diff --git a/LeanPool/AxQM.lean b/LeanPool/AxQM.lean new file mode 100644 index 0000000000..74937c8772 --- /dev/null +++ b/LeanPool/AxQM.lean @@ -0,0 +1,63 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +/- +AxQM — a Lean 4 formalization of Nielsen & Chuang grounded in the +postulates of quantum mechanics +Copyright (c) 2026 Axiomatic AI + +Licensed under the Apache License, Version 2.0. The full terms are in the file +LICENSE. SPDX-License-Identifier: Apache-2.0 + +Original to Axiomatic AI: AxQM/ and ToMathlib/. + + +THIRD-PARTY MATERIAL + +The library depends on Mathlib (https://github.com/leanprover-community/mathlib4), +Copyright (c) the mathlib4 authors, licensed under the Apache License, Version +2.0. Lake fetches it at build time, at the revision recorded in +lake-manifest.json; no Mathlib file is included in this repository. + +ToMathlib/ holds general mathematics written for this library. Where a file +there extends a Mathlib file, it has the same relative path and contains only +the additions. + + +NIELSEN AND CHUANG + +The library formalizes results and exercises from Quantum Computation and +Quantum Information by Michael A. Nielsen and Isaac L. Chuang (Cambridge +University Press), each cited by item number and page. The book is not +reproduced: each item is stated in Lean and summarised in a sentence of our +own, and comments quote short phrases of the book only where its wording bears +on how a statement should be read. Rights in the book remain with its rights +holders, and nothing granted above extends to them. +-/ + +module + +public import LeanPool.AxQM.Core.UniversalityReduction +public import LeanPool.AxQM.NC.Ch9.Theorem4 +public import LeanPool.AxQM.NC.Ch12.Theorem1 +public import LeanPool.AxQM.NC.Ch12.Theorem6 +public import LeanPool.AxQM.NC.Ch12.Theorem8 +public import LeanPool.AxQM.NC.Ch12.Theorem15 + +/-! +# Finite-dimensional quantum information + +Source: arxiv:2612.02353, url:https://github.com/Axiomatic-AI/AxQMLib/tree/1bc3602193961227cad4f5fd3ae794fb584c05b6 +Authors: Weichen Winston Yin, Frank H. L. Koppens +Status: verified +Main declarations: `AxQM.State.isGreatest_norm_overlap_purification`, `AxQM.holevo_bound`, + `AxQM.State.reliablyCompressible_iff_vonNeumannEntropy_lt`, + `AxQM.channelHolevoChi_eq_productStateCapacity` +Tags: quantum-information, quantum-channels, quantum-entropy, coding-theory +MSC: 81P45, 81P68, 94A17 +-/ diff --git a/LeanPool/AxQM/Concrete/ABCDecomposition.lean b/LeanPool/AxQM/Concrete/ABCDecomposition.lean new file mode 100644 index 0000000000..effdabe284 --- /dev/null +++ b/LeanPool/AxQM/Concrete/ABCDecomposition.lean @@ -0,0 +1,138 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.RotationDecomposition +public import LeanPool.AxQM.Concrete.RotationConjugation + +/-! +# Concrete: the ABC decomposition of a single-qubit unitary (Nielsen & Chuang, Corollary 4.2) + +Building on the Z–Y decomposition `exists_zy_decomposition` (N&C Theorem 4.1, +`Concrete/RotationDecomposition.lean`) and the `X`-conjugation identities +`pauliX_mul_rotY_mul_pauliX`/`pauliX_mul_rotZ_mul_pauliX` (N&C Exercise 4.7, +`Concrete/RotationConjugation.lean`), it proves the **ABC decomposition** — **Nielsen & Chuang, +Corollary 4.2**: every single-qubit unitary `U` can be written + +`U = e^{iα} A X B X C` with `A B C = I`, + +for unitary `A, B, C` and a global phase `α`. This is the algebraic key to implementing controlled +single-qubit operations (N&C §4.3): a controlled-`U` is realised by the `X`-gates being the +control-conditioned pieces while `A, B, C` are applied unconditionally. + +## What is formalised + +* `rotY_mul_rotY`, `rotZ_mul_rotZ`, `rotY_zero`, `rotZ_zero` — the coordinate specialisations of + the one-parameter group law `rotAxis_mul_same`/`rotAxis_zero` (`Concrete/Rotation.lean`), used to + collapse the products of `R_y`/`R_z` rotations that appear in `A B C` and `A X B X C`. +* `exists_abc_decomposition` — **Corollary 4.2 itself**: for `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` + there exist a real `α` and matrices `A, B, C ∈ Matrix.unitaryGroup (Fin 2) ℂ` with `A B C = 1` + and `U = e^{iα} • (A X B X C)`, where `X = pauliX`. + +## Design notes + +* **Statement shape.** "Unitary" is `Matrix.unitaryGroup (Fin 2) ℂ` (`Uᴴ U = I`), matching + `exists_zy_decomposition` and N&C's own definition of a single-qubit gate; no dimension or + determinant is fixed, so the statement is Corollary 4.2 in full generality (all of `U(2)`). The + three matrices `A, B, C`, their unitarity, the relation `A B C = 1`, and the phase-factored + identity `U = e^{iα} A X B X C` are all recorded (no weakening): the corollary's content is + exactly this bundle, so it is one existential theorem rather than a monolithic conjunction bolted + onto an unrelated headline. +* **The witnesses (N&C's proof, eq. 4.14–4.17).** From `exists_zy_decomposition`, + `U = e^{iα} R_z(β) R_y(γ) R_z(δ)`. Set (N&C's choice) + `A = R_z(β) R_y(γ/2)`, `B = R_y(-γ/2) R_z(-(δ+β)/2)`, `C = R_z((δ-β)/2)`. + - `A B C = I`: the two inner `R_y` collapse (`R_y(γ/2) R_y(-γ/2) = R_y(0) = I`) and the `R_z` + telescope to `R_z(β) R_z(-β) = R_z(0) = I` (eq. 4.14). + - `X B X = R_y(γ/2) R_z((δ+β)/2)`: insert `X X = I` between `B`'s two factors and apply the + `X`-conjugation identities `X R_a(θ) X = R_a(-θ)` (eq. 4.15). + - hence `A X B X C = R_z(β) R_y(γ) R_z(δ)` (eq. 4.16–4.17), giving `U = e^{iα} A X B X C`. +* **Associativity handling.** Matrix multiplication is non-commutative, so the regroupings (moving + `X X` together, telescoping the rotations) are pure re-associations discharged by `noncomm_ring` + (which normalises a non-commutative ring expression without reordering factors); the actual + cancellations are the rotation group law and `pauliX_mul_self` (`X X = I`). + +The statement of Corollary 4.2 in `AxQM/NC/Ch4/Corollary4_2.lean` refers to +`exists_abc_decomposition`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The one-parameter group law for `R_y`: `R_y(a) R_y(b) = R_y(a+b)` (the coordinate case of +`rotAxis_mul_same`). -/ +theorem rotY_mul_rotY (a b : ℝ) : rotY a * rotY b = rotY (a + b) := rotAxis_mul_same _ a b + +/-- The one-parameter group law for `R_z`: `R_z(a) R_z(b) = R_z(a+b)` (the coordinate case of +`rotAxis_mul_same`). -/ +theorem rotZ_mul_rotZ (a b : ℝ) : rotZ a * rotZ b = rotZ (a + b) := rotAxis_mul_same _ a b + +/-- `R_y(0) = I` (the coordinate case of `rotAxis_zero`). -/ +theorem rotY_zero : rotY 0 = 1 := rotAxis_zero _ + +/-- `R_z(0) = I` (the coordinate case of `rotAxis_zero`). -/ +theorem rotZ_zero : rotZ 0 = 1 := rotAxis_zero _ + +/-- **Nielsen & Chuang, Corollary 4.2 (ABC decomposition of a single-qubit unitary).** Every +`2 × 2` unitary `U` (a single-qubit gate, `Uᴴ U = I`) can be written `U = e^{iα} A X B X C` with +`A B C = I`, for a real phase `α`, unitary matrices `A, B, C`, and `X = pauliX`. The witnesses come +from the Z–Y decomposition `U = e^{iα} R_z(β) R_y(γ) R_z(δ)` (Theorem 4.1) via N&C's choice +`A = R_z(β) R_y(γ/2)`, `B = R_y(-γ/2) R_z(-(δ+β)/2)`, `C = R_z((δ-β)/2)` (eq. 4.14–4.17): `A B C` +telescopes to `I`, and conjugating `B` by the two `X` gates (`X R_a(θ) X = R_a(-θ)`, Exercise 4.7) +turns `A X B X C` back into `R_z(β) R_y(γ) R_z(δ)`. -/ +theorem exists_abc_decomposition (U : Matrix (Fin 2) (Fin 2) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ (α : ℝ) (A B C : Matrix (Fin 2) (Fin 2) ℂ), + A ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ B ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ + C ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ A * B * C = 1 ∧ + U = Complex.exp ((α : ℂ) * Complex.I) • (A * pauliX * B * pauliX * C) := by + obtain ⟨α, β, γ, δ, hU_eq⟩ := exists_zy_decomposition U hU + refine ⟨α, rotZ β * rotY (γ / 2), rotY (-(γ / 2)) * rotZ (-((δ + β) / 2)), + rotZ ((δ - β) / 2), mul_mem (rotZ_mem_unitaryGroup β) (rotY_mem_unitaryGroup (γ / 2)), + mul_mem (rotY_mem_unitaryGroup (-(γ / 2))) (rotZ_mem_unitaryGroup (-((δ + β) / 2))), + rotZ_mem_unitaryGroup ((δ - β) / 2), ?_, ?_⟩ + · -- `A B C = 1` (N&C eq. 4.14): the inner `R_y` collapse and the `R_z` telescope. + calc rotZ β * rotY (γ / 2) * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) * rotZ ((δ - β) / 2) + = rotZ β * (rotY (γ / 2) * rotY (-(γ / 2))) + * (rotZ (-((δ + β) / 2)) * rotZ ((δ - β) / 2)) := by noncomm_ring + _ = 1 := by + rw [rotY_mul_rotY, rotZ_mul_rotZ, show γ / 2 + -(γ / 2) = 0 by ring, + show -((δ + β) / 2) + (δ - β) / 2 = -β by ring, rotY_zero, mul_one, rotZ_mul_rotZ, + show β + -β = 0 by ring, rotZ_zero] + · -- `U = e^{iα} • (A X B X C)` (N&C eq. 4.15–4.17). + -- Conjugate `B` by the two `X` gates: `X B X = R_y(γ/2) R_z((δ+β)/2)`. + have hXBX : pauliX * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) * pauliX + = rotY (γ / 2) * rotZ ((δ + β) / 2) := by + calc pauliX * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) * pauliX + = pauliX * rotY (-(γ / 2)) * (pauliX * pauliX) + * rotZ (-((δ + β) / 2)) * pauliX := by rw [pauliX_mul_self]; noncomm_ring + _ = (pauliX * rotY (-(γ / 2)) * pauliX) + * (pauliX * rotZ (-((δ + β) / 2)) * pauliX) := by noncomm_ring + _ = rotY (γ / 2) * rotZ ((δ + β) / 2) := by + rw [pauliX_mul_rotY_mul_pauliX, pauliX_mul_rotZ_mul_pauliX, neg_neg, neg_neg] + -- Reassemble `A X B X C` into `R_z(β) R_y(γ) R_z(δ)`. + have hprod : rotZ β * rotY (γ / 2) * pauliX * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) + * pauliX * rotZ ((δ - β) / 2) = rotZ β * rotY γ * rotZ δ := by + calc rotZ β * rotY (γ / 2) * pauliX * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) + * pauliX * rotZ ((δ - β) / 2) + = rotZ β * rotY (γ / 2) + * (pauliX * (rotY (-(γ / 2)) * rotZ (-((δ + β) / 2))) * pauliX) + * rotZ ((δ - β) / 2) := by noncomm_ring + _ = rotZ β * rotY (γ / 2) * (rotY (γ / 2) * rotZ ((δ + β) / 2)) + * rotZ ((δ - β) / 2) := by rw [hXBX] + _ = rotZ β * (rotY (γ / 2) * rotY (γ / 2)) + * (rotZ ((δ + β) / 2) * rotZ ((δ - β) / 2)) := by noncomm_ring + _ = rotZ β * rotY γ * rotZ δ := by + rw [rotY_mul_rotY, rotZ_mul_rotZ, show γ / 2 + γ / 2 = γ by ring, + show (δ + β) / 2 + (δ - β) / 2 = δ by ring] + rw [hU_eq, hprod] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/AxisAngleDecomposition.lean b/LeanPool/AxQM/Concrete/AxisAngleDecomposition.lean new file mode 100644 index 0000000000..92c91c090b --- /dev/null +++ b/LeanPool/AxQM/Concrete/AxisAngleDecomposition.lean @@ -0,0 +1,206 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation +public import Mathlib.LinearAlgebra.Matrix.NonsingularInverse +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse + +/-! +# Concrete: the axis-angle decomposition of a single-qubit unitary (Nielsen & Chuang, Ex. 4.8(1)) + +Building on the rotation operator `rotAxis` of `Concrete/Rotation.lean` (N&C eq. 4.8), it proves +the **axis-angle decomposition** — the first part of **Nielsen & Chuang, Exercise 4.8** (eq. 4.9): +every single-qubit unitary `U` factors as + +`U = e^{iα} R_n̂(θ)` + +for some real numbers `α, θ` and a real *unit* three-vector `n̂`. +This is the `SU(2) = unit quaternions` fact behind the Bloch-sphere picture: modulo an overall +phase, a single-qubit gate is a rotation of the Bloch sphere. + +"Unitary" is membership in `Matrix.unitaryGroup (Fin 2) ℂ` (`Uᴴ U = I`) — N&C's own definition; no +dimension or determinant is fixed, so this is Exercise 4.8(1) in full generality (all of `U(2)`), +the axis-angle analogue of Theorem 4.1's Z-Y decomposition (`exists_zy_decomposition`). + +## Proof (the quaternion route) + +Pull out the phase `α = arg(det U)/2`; then `V := e^{-iα} • U` has `det V = 1` (since +`|det U| = 1`), so `V ∈ SU(2)`. Unitarity with unit determinant forces (via `adjugate_fin_two`) the +`SU(2)` shape `V₁₁ = conj V₀₀`, `V₁₀ = -conj V₀₁`; expanding into real and imaginary parts gives the +*quaternion* identity `V = a • I + i (w₀ X + w₁ Y + w₂ Z)` with `a = Re V₀₀` and +`w = (Im V₀₁, Re V₀₁, Im V₀₀)`, and row-`0` orthonormality `‖V₀₀‖² + ‖V₀₁‖² = 1` gives +`‖w‖² = 1 - a²`. Choosing `θ = 2 arccos a` (so `cos(θ/2) = a`, `sin(θ/2) = ‖w‖`) and the unit axis +`n̂ = -w/‖w‖` (or `e_z` when `w = 0`, `V = ±I`, keeping `n̂` genuinely unit) matches the closed form +`rotAxis_eq_of_unit` `cos(θ/2) I - i sin(θ/2) (n̂·σ)`, since `sin(θ/2) (n̂·σ) = -(w·σ)`. Finally +`U = e^{iα} V`. The grounded physics reading is in +[upstream `AxQM/NC/Ch4/Exercise4_8.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_8.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +private theorem axisAngle_of_quaternion (V : Matrix (Fin 2) (Fin 2) ℂ) (a : ℝ) + (w : Fin 3 → ℝ) + (hquat : V = (a : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) + Complex.I • pauliDot w) + (hnrm : w 0 ^ 2 + w 1 ^ 2 + w 2 ^ 2 = 1 - a ^ 2) : + ∃ (θ : ℝ) (n : Fin 3 → ℝ), (n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) ∧ rotAxis n θ = V := by + let nrm := w 0 ^ 2 + w 1 ^ 2 + w 2 ^ 2 + have hnrmdef : nrm = w 0 ^ 2 + w 1 ^ 2 + w 2 ^ 2 := rfl + have hnrm_nonneg : 0 ≤ nrm := by dsimp only [nrm]; positivity + have ha_sq : a ^ 2 ≤ 1 := by linarith only [hnrm, hnrm_nonneg] + have ha1 : a ≤ 1 := by nlinarith [ha_sq] + have ha_ge : (-1 : ℝ) ≤ a := by nlinarith [ha_sq] + set θ : ℝ := 2 * Real.arccos a with hθ + set s : ℝ := Real.sqrt nrm with hs + have hcos : Real.cos (θ / 2) = a := by + rw [show θ / 2 = Real.arccos a by rw [hθ]; ring, Real.cos_arccos ha_ge ha1] + have hsin : Real.sin (θ / 2) = s := by + rw [show θ / 2 = Real.arccos a by rw [hθ]; ring, Real.sin_arccos, ← hnrm, hs] + -- The unit axis: `-w/‖w‖ = (-1/s) • w`, or `e_z` in the degenerate case `w = 0`. + set n : Fin 3 → ℝ := if s = 0 then ![0, 0, 1] else (-1 / s : ℝ) • w with hn_def + have hs2 : s ^ 2 = nrm := Real.sq_sqrt hnrm_nonneg + have hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1 := by + by_cases hs0 : s = 0 + · simp [hn_def, hs0] + · simp only [hn_def, ite_eq_right hs0, Pi.smul_apply, smul_eq_mul] + have hsne : s ≠ 0 := hs0 + have hs2' : s ^ 2 = w 0 ^ 2 + w 1 ^ 2 + w 2 ^ 2 := by rw [hs2, hnrmdef] + field_simp + nlinarith [hs2'] + -- `(s : ℂ) • (w · σ)` collapses to `-(w · σ)` on the chosen axis `n`. + have hstep : (s : ℂ) • pauliDot n = -pauliDot w := by + by_cases hs0 : s = 0 + · have hnrm0 : nrm = 0 := by + have : s ^ 2 = 0 := by rw [hs0]; ring + rw [hs2] at this; exact this + have hw0 : w 0 = 0 ∧ w 1 = 0 ∧ w 2 = 0 := by + rw [hnrmdef] at hnrm0 + refine ⟨?_, ?_, ?_⟩ <;> + nlinarith only [hnrm0, sq_nonneg (w 0), sq_nonneg (w 1), sq_nonneg (w 2)] + rw [hs0, Complex.ofReal_zero, zero_smul, eq_comm, neg_eq_zero, pauliDot, hw0.1, hw0.2.1, + hw0.2.2] + simp + · have hsne : s ≠ 0 := hs0 + have hn_eq : n = (-1 / s : ℝ) • w := by rw [hn_def, ite_eq_right hs0] + rw [hn_eq, pauliDot_smul, smul_smul] + rw [show (s : ℂ) * ((-1 / s : ℝ) : ℂ) = ((s * (-1 / s) : ℝ) : ℂ) by push_cast; ring, + show s * (-1 / s) = -1 by field_simp] + simp + -- `rotAxis n θ = V`. + have hgoalV : rotAxis n θ = V := by + have hpw : pauliDot w = -((s : ℂ) • pauliDot n) := by rw [hstep]; exact (neg_neg _).symm + rw [rotAxis_eq_of_unit hn θ, hcos, hsin, hquat, hpw] + module + exact ⟨θ, n, hn, hgoalV⟩ + +/-- **Nielsen & Chuang, Exercise 4.8(1) (axis-angle decomposition of a single-qubit unitary).** +Every `2 × 2` unitary `U` (a single-qubit gate, `Uᴴ U = I`) factors as `U = e^{iα} R_n̂(θ)` +(eq. 4.9) for some real numbers `α, θ` and a real *unit* three-vector `n̂` +(`n₀² + n₁² + n₂² = 1`). The phase is `α = arg(det U)/2`; writing `V = e^{-iα} U ∈ SU(2)` in +quaternion form `V = a·I + i(w·σ)` with `a = Re V₀₀`, `w = (Im V₀₁, Re V₀₁, Im V₀₀)`, the angle is +`θ = 2 arccos a` and the axis `n̂ = -w/‖w‖` (or `e_z` if `w = 0`). -/ +theorem exists_axis_angle_decomposition (U : Matrix (Fin 2) (Fin 2) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ (α θ : ℝ) (n : Fin 3 → ℝ), (n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) ∧ + U = Complex.exp ((α : ℂ) * Complex.I) • rotAxis n θ := by + -- Unitarity as the two products. + have hUsU : U * star U = 1 := (Matrix.mem_unitaryGroup_iff).1 hU + have hsUU : star U * U = 1 := (Matrix.mem_unitaryGroup_iff').1 hU + -- `|det U| = 1`: `det U` is a unitary of the C⋆-ring `ℂ` (`Matrix.det_of_mem_unitary`). + have hdetnorm : ‖U.det‖ = 1 := + CStarRing.norm_of_mem_unitary (Matrix.det_of_mem_unitary hU) + -- The phase `α = arg(det U)/2` and the unit-modulus scalar `c = e^{-iα}`. + set α : ℝ := U.det.arg / 2 with hα + set c : ℂ := Complex.exp (((-α : ℝ) : ℂ) * Complex.I) with hc + have hcnorm : ‖c‖ = 1 := Complex.norm_exp_ofReal_mul_I (-α) + -- The `SU(2)` matrix `V = c • U`. + set V : Matrix (Fin 2) (Fin 2) ℂ := c • U with hV + -- `V` is unitary (unit scalar times unitary). + have hcc : star c * c = 1 := by + rw [← starRingEnd_apply, Complex.conj_mul', hcnorm]; norm_num + have hcc' : c * star c = 1 := by rw [mul_comm]; exact hcc + have hVsV : star V * V = 1 := by + rw [hV, star_smul, smul_mul_smul_comm, hsUU, hcc, one_smul] + have hVVs : V * star V = 1 := by + rw [hV, star_smul, smul_mul_smul_comm, hUsU, hcc', one_smul] + -- `det V = 1`. + have hdetV : V.det = 1 := by + have hd : U.det = Complex.exp ((↑U.det.arg : ℂ) * Complex.I) := by + conv_lhs => rw [← Complex.norm_mul_exp_arg_mul_I U.det] + rw [hdetnorm]; simp + rw [hV, Matrix.det_smul, Fintype.card_fin, hc, hd, ← Complex.exp_nsmul, ← Complex.exp_add] + rw [show (2 : ℕ) • (((-α : ℝ) : ℂ) * Complex.I) + (↑U.det.arg : ℂ) * Complex.I + = ((2 * (-α) + U.det.arg : ℝ) : ℂ) * Complex.I by rw [hα]; push_cast; ring] + rw [show (2 * (-α) + U.det.arg : ℝ) = 0 by rw [hα]; ring] + simp + -- The `SU(2)` entry constraints from `star V = V⁻¹ = adjugate V` (det V = 1). + have hstarV : star V = !![V 1 1, -(V 0 1); -(V 1 0), V 0 0] := by + rw [(Matrix.inv_eq_left_inv hVsV).symm, Matrix.inv_def, Matrix.adjugate_fin_two, hdetV, + Ring.inverse_one, one_smul] + have hF1 : V 1 1 = star (V 0 0) := by + have h := congrFun (congrFun hstarV 0) 0 + simp only [Matrix.star_eq_conjTranspose, Matrix.conjTranspose_apply, Matrix.of_apply, + Matrix.cons_val', Matrix.cons_val_zero, Matrix.empty_val', Matrix.cons_val_fin_one] at h + exact h.symm + have hF2 : V 1 0 = -star (V 0 1) := by + have h := congrFun (congrFun hstarV 1) 0 + simp only [Matrix.star_eq_conjTranspose, Matrix.conjTranspose_apply, Matrix.of_apply, + Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.empty_val', + Matrix.cons_val_fin_one] at h + rw [h, neg_neg] + -- Row-`0` orthonormality `‖V₀₀‖² + ‖V₀₁‖² = 1`. + have hF3 : Complex.normSq (V 0 0) + Complex.normSq (V 0 1) = 1 := by + have h := congrFun (congrFun hVVs 0) 0 + simp only [Matrix.mul_apply, Fin.sum_univ_two, Matrix.star_eq_conjTranspose, + Matrix.conjTranspose_apply, Matrix.one_apply_eq, ← starRingEnd_apply, Complex.mul_conj] at h + exact_mod_cast h + -- The quaternion coefficients. + set a : ℝ := (V 0 0).re with ha + set w : Fin 3 → ℝ := ![(V 0 1).im, (V 0 1).re, (V 0 0).im] with hw + set nrm : ℝ := w 0 ^ 2 + w 1 ^ 2 + w 2 ^ 2 with hnrmdef + have hnrm : nrm = 1 - a ^ 2 := by + simp only [hnrmdef, hw, ha, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons] + have := hF3 + simp only [Complex.normSq_apply] at this + nlinarith [this] + -- `V = a • I + i (w · σ)` (the quaternion identity). + have hVform : V = !![V 0 0, V 0 1; -star (V 0 1), star (V 0 0)] := by + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Fin.isValue, Fin.zero_eta, Fin.mk_one] + · exact hF2 + · exact hF1 + have hquat : V = (a : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) + Complex.I • pauliDot w := by + rw [hVform, pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [hw, ha, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.cons_val_two, + Matrix.tail_cons, Matrix.head_cons, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, + smul_eq_mul, mul_one, Fin.isValue, Fin.zero_eta, Fin.mk_one, ite_true] <;> + apply Complex.ext <;> + simp [Complex.add_re, Complex.add_im, Complex.mul_re, Complex.mul_im, Complex.conj_re, + Complex.conj_im] + obtain ⟨θ, n, hn, hgoalV⟩ := axisAngle_of_quaternion V a w hquat (hnrmdef.symm.trans hnrm) + -- Reassemble `U = e^{iα} • rotAxis n θ`. + refine ⟨α, θ, n, hn, ?_⟩ + have hac : Complex.exp ((α : ℂ) * Complex.I) * c = 1 := by + rw [hc, ← Complex.exp_add, + show (α : ℂ) * Complex.I + ((-α : ℝ) : ℂ) * Complex.I = 0 by push_cast; ring, + Complex.exp_zero] + rw [hgoalV, hV, smul_smul, hac, one_smul] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/AxisAngleGateValues.lean b/LeanPool/AxQM/Concrete/AxisAngleGateValues.lean new file mode 100644 index 0000000000..52f217a338 --- /dev/null +++ b/LeanPool/AxQM/Concrete/AxisAngleGateValues.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.Concrete.Hadamard +public import LeanPool.AxQM.Concrete.Pauli +public import LeanPool.AxQM.Concrete.PauliEigenvectors + +/-! +# Concrete: axis-angle parameters for the Hadamard and phase gates (Nielsen & Chuang, Ex. 4.8(2,3)) + +Parts 2 and 3 of **Nielsen & Chuang, Exercise 4.8** ask for the explicit values of `α, θ, n̂` in the +axis-angle decomposition `U = e^{iα} R_n̂(θ)` (eq. 4.9) for two named gates. This file, +building on the rotation matrices `rotAxis`/`rotZ` of +`Concrete/Rotation.lean` and the complex Hadamard matrix `hadamardC` of `Concrete/Hadamard.lean`, it +proves the two `2 × 2` matrix identities that pin those values. + +* **Part 2 — the Hadamard gate `H`:** `α = π/2`, `θ = π`, `n̂ = (1/√2, 0, 1/√2)` (the `x̂ + e_z` + axis). `hadamardC_eq_expPiDivTwo_smul_rotAxis`: + `H = e^{iπ/2} • R_{(1/√2, 0, 1/√2)}(π)`. + At `θ = π` the closed form (`rotAxis_eq_of_unit`) collapses to `-i (n̂·σ)` (since `cos(π/2) = 0`, + `sin(π/2) = 1`); with this axis `n̂·σ = (1/√2)(X + Z) = H`, and the phase `e^{iπ/2} = i` cancels + the `-i`, giving `H` exactly. +* **Part 3 — the phase gate `S = diag(1, i)`:** `α = π/4`, `θ = π/2`, `n̂ = e_z`. + `sMatrix_eq_expPiDivFour_smul_rotZ`: + `S = e^{iπ/4} • R_z(π/2)`. + This is the exact analogue of the π/8 gate identity `T = e^{iπ/8} R_z(π/4)` (`tMatrix`, + Exercise 4.3): both `S` and `R_z(π/2) = diag(e^{-iπ/4}, e^{iπ/4})` are diagonal, and pulling the + scalar `e^{iπ/4}` through gives `diag(1, e^{iπ/2}) = diag(1, i) = S`. + +The corresponding operator identities are in +`AxQM/Postulates/API/AxisAngleGateValues.lean`, and the grounded physics reading — that `H` and `S`, +as quantum operations, *are* these rotations (the global phase being unobservable) — is in +[upstream `AxQM/NC/Ch4/Exercise4_8.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_8.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **Nielsen & Chuang, Exercise 4.8(2) (Hadamard gate as an axis rotation).** The Hadamard matrix +is `e^{iπ/2}` times the rotation by `θ = π` about the `x̂ + e_z` axis `n̂ = (1/√2, 0, 1/√2)`: +`H = e^{iπ/2} • R_{(1/√2, 0, 1/√2)}(π)`. At `θ = π` the closed form `R_n̂(π) = cos(π/2) I - +i sin(π/2) (n̂·σ) = -i (n̂·σ)`; for this axis `n̂·σ = (1/√2)(X + Z) = H`, and `e^{iπ/2} = i` cancels +the `-i`. -/ +theorem hadamardC_eq_expPiDivTwo_smul_rotAxis : + hadamardC = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) • + rotAxis ![(Real.sqrt 2)⁻¹, 0, (Real.sqrt 2)⁻¹] Real.pi := by + have hhalf : ((Real.sqrt 2)⁻¹ : ℝ) ^ 2 = 2⁻¹ := by + rw [inv_pow, Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + have hn : (![(Real.sqrt 2)⁻¹, 0, (Real.sqrt 2)⁻¹] : Fin 3 → ℝ) 0 ^ 2 + + (![(Real.sqrt 2)⁻¹, 0, (Real.sqrt 2)⁻¹] : Fin 3 → ℝ) 1 ^ 2 + + (![(Real.sqrt 2)⁻¹, 0, (Real.sqrt 2)⁻¹] : Fin 3 → ℝ) 2 ^ 2 = 1 := by + simp only [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, Matrix.cons_val_two, + Matrix.tail_cons, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow] + rw [hhalf]; norm_num + have hphase : Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) = Complex.I := by + exact_mod_cast Complex.exp_pi_div_two_mul_I + -- At `θ = π`: `cos(π/2) = 0`, `sin(π/2) = 1`, so `R_n̂(π) = -(i (n̂·σ))`, and the outer phase + -- `e^{iπ/2} = i` gives `i · (-(i (n̂·σ))) = -(i² (n̂·σ)) = n̂·σ`. The RHS collapses to `n̂·σ`. + rw [hphase, rotAxis_eq_of_unit hn Real.pi] + simp only [Real.cos_pi_div_two, Real.sin_pi_div_two, Complex.ofReal_zero, Complex.ofReal_one, + one_mul, zero_smul, zero_sub, smul_neg, smul_smul, Complex.I_mul_I, neg_smul, one_smul] + rw [pauliDot_eq, hadamardC] + ext i j + fin_cases i <;> fin_cases j <;> simp [Matrix.smul_apply, Complex.ofReal_inv] + +/-- The **phase gate** `S = diag(1, i)` (Nielsen & Chuang, §4.2), the diagonal single-qubit gate +`!![1, 0; 0, i]`. Written `S = e^{iπ/4} R_z(π/2)` up to a global phase +(`sMatrix_eq_expPiDivFour_smul_rotZ`), the phase-gate analogue of the π/8 gate `tMatrix`. -/ +def sMatrix : Matrix (Fin 2) (Fin 2) ℂ := + !![1, 0; 0, Complex.I] + +/-- **Nielsen & Chuang, Exercise 4.8(3) (phase gate as an axis rotation).** The phase gate equals +`R_z(π/2)` up to the global phase `e^{iπ/4}`: `S = e^{iπ/4} • R_z(π/2)` (so `α = π/4`, `θ = π/2`, +`n̂ = e_z`). Both are diagonal, and pulling the scalar `e^{iπ/4}` through +`R_z(π/2) = diag(e^{-iπ/4}, e^{iπ/4})` gives `diag(1, e^{iπ/2}) = diag(1, i) = S`, via +`e^{iπ/4}·e^{-iπ/4} = 1` and `e^{iπ/4}·e^{iπ/4} = e^{iπ/2} = i`. -/ +theorem sMatrix_eq_expPiDivFour_smul_rotZ : + sMatrix = Complex.exp ((Real.pi / 4 : ℝ) * Complex.I) • rotZ (Real.pi / 2) := by + have hI : Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) = Complex.I := by + exact_mod_cast Complex.exp_pi_div_two_mul_I + rw [rotZ_eq] + unfold sMatrix + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, Matrix.of_apply, Matrix.cons_val', + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_fin_one, Matrix.smul_apply, + smul_eq_mul, neg_mul, mul_zero, Complex.ofReal_div, Complex.ofReal_ofNat] + · -- (0,0): `1 = exp(iπ/4) · exp(-i(π/2)/2)` + rw [← Complex.exp_add, ← Complex.exp_zero] + congr 1 + ring + · -- (1,1): `i = exp(iπ/4) · exp(i(π/2)/2)`, i.e. `exp(iπ/2) = i` + rw [← Complex.exp_add, + show (Real.pi : ℂ) / 4 * Complex.I + (Real.pi : ℂ) / 2 / 2 * Complex.I + = ((Real.pi / 2 : ℝ) : ℂ) * Complex.I by push_cast; ring] + exact hI.symm + +/-- The phase gate `S = diag(1, i)` is unitary: it lies in the `2 × 2` unitary group. Immediate from +`S = e^{iπ/4} • R_z(π/2)` (`sMatrix_eq_expPiDivFour_smul_rotZ`), the unitarity of `R_z(π/2)` +(`rotZ_mem_unitaryGroup`), and the fact that scaling a unitary by the unit-modulus phase `e^{iπ/4}` +keeps it unitary. -/ +theorem sMatrix_mem_unitaryGroup : sMatrix ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + have hc : Complex.exp ((Real.pi / 4 : ℝ) * Complex.I) * + star (Complex.exp ((Real.pi / 4 : ℝ) * Complex.I)) = 1 := by + rw [← starRingEnd_apply, Complex.mul_conj', Complex.norm_exp_ofReal_mul_I]; norm_num + rw [sMatrix_eq_expPiDivFour_smul_rotZ, Matrix.mem_unitaryGroup_iff, star_smul, + smul_mul_smul_comm, Matrix.mem_unitaryGroup_iff.mp (rotZ_mem_unitaryGroup _), hc, one_smul] + +/-- **`S² = Z`.** The phase-gate matrix `S = diag(1, i)` squares to the Pauli-`Z` matrix +`diag(1, -1)`, since `i² = -1`. -/ +theorem sMatrix_mul_self_eq_pauliZ : sMatrix * sMatrix = pauliZ := by + rw [sMatrix, pauliZ, Matrix.mul_fin_two] + norm_num [Complex.I_mul_I] + +/-- **Spectral form of the phase gate `S = diag(1, i)`:** `S = |0⟩⟨0| + i · |1⟩⟨1|`, the eigenbasis +expansion with eigenvalues `1, i` on the computational-basis kets `|0⟩, |1⟩` (`ket 0`, `ket 1`). +Transported to the operator level by `sGate_op_eq_rankOne_add`, it identifies the once-controlled +`i · I` gate with `S ⊗ I` in the Deutsch-gate universality argument (Nielsen & Chuang, +Exercise 4.44). Verified by the `2 × 2` entrywise computation. -/ +theorem sMatrix_eq_outerSelf_add : + sMatrix = outerSelf (ket 0) + Complex.I • outerSelf (ket 1) := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sMatrix, outerSelf, ket, Matrix.vecMulVec, Matrix.add_apply] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlochMatrix.lean b/LeanPool/AxQM/Concrete/BlochMatrix.lean new file mode 100644 index 0000000000..48ac85d711 --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlochMatrix.lean @@ -0,0 +1,282 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Pauli +public import Mathlib.Analysis.Matrix.PosDef +public import Mathlib.Analysis.Complex.Order + +/-! +# Concrete: the Bloch matrix `ρ = (I + r·σ)/2` + +For a real three-vector +`r` this file defines the `2 × 2` complex matrix + +`blochMatrix r = ½ (I + r·σ) = ½ (I + r₀ X + r₁ Y + r₂ Z)`, + +the **Bloch representation of a single-qubit density matrix** (Nielsen & Chuang, Exercise +2.72, eq. 2.175), built on the concrete combination `Concrete.pauliDot` (`r·σ`). It records the +matrix-level facts of the exercise that need no positivity/spectral analysis — the statement that +the family `½(I + r·σ)` is exactly the family of Hermitian trace-one `2 × 2` matrices: + +* `blochMatrix_eq` — the collapsed explicit `2 × 2` form + `½ !![1 + r₂, r₀ − i r₁; r₀ + i r₁, 1 − r₂]`. +* `blochMatrix_isHermitian` — `blochMatrix r` is Hermitian (`r` real). +* `blochMatrix_trace` — `tr (blochMatrix r) = 1` (the `±r₂` on the diagonal cancels). +* `blochMatrix_zero` — `blochMatrix 0 = ½ I`, the matrix underlying the maximally mixed state + (Nielsen & Chuang, Exercise 2.72(2): the state `ρ = I/2` has Bloch vector `r_vec = 0`). +* `blochVector` / `blochVector_blochMatrix` — the map reading the Bloch vector off a matrix's + entries (`r₀ = 2 Re M₁₀`, `r₁ = 2 Im M₁₀`, `r₂ = 2 Re M₀₀ − 1`), a **left inverse** of + `blochMatrix`; the citable "Bloch vector for `ρ`" the exercise names. +* `blochMatrix_injective` — `r ↦ blochMatrix r` is injective, so the Bloch vector of a matrix is + **unique** ("the Bloch vector for `ρ`" of the exercise is well defined), immediate from the + left inverse `blochVector`. +* `exists_blochMatrix_of_isHermitian_trace_one` — **every** Hermitian trace-one `2 × 2` matrix + is `blochMatrix r` for some real `r` (the decomposition half of Exercise 2.72(1): the family + `½(I + r·σ)` exhausts the Hermitian trace-one matrices). +* `blochMatrix_det` — `det (blochMatrix r) = (1 − ‖r‖²)/4`, the eigenvalue product `λ₊ λ₋` for the + eigenvalues `(1 ± ‖r‖)/2`. +* `blochMatrix_posSemidef_iff` — the **positivity constraint** of Exercise 2.72(1): `blochMatrix r` + is positive semidefinite iff `‖r‖² = r₀² + r₁² + r₂² ≤ 1`. Together with the Hermitian/trace-one + facts this identifies the Bloch matrices that are genuine density matrices as exactly the closed + unit ball `‖r‖ ≤ 1` — the **Bloch ball**. + +The remaining halves of Exercise 2.72 — the purity characterization `pure ↔ ‖r‖ = 1` (part 3), +and the promotion of the `‖r‖ ≤ 1` family to states of a qubit `State qubit` (parts 1, 2, 4) — +are not treated here. + +## Design notes + +* The Bloch vector `r` is modelled as a bare `Fin 3 → ℝ` and `‖r‖²` as the scalar + `r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2`, matching `Concrete.pauliDot` (and N&C's `r_vec · σ_vec ≡ Σᵢ rᵢ + σᵢ`). +* Facts are proved by collapsing to the closed `2 × 2` form `blochMatrix_eq` and computing + entrywise, the same idiom as `Concrete.Pauli`. +* `exists_blochMatrix_of_isHermitian_trace_one` recovers the components from the matrix entries: + `r₀ = 2 Re M₁₀`, `r₁ = 2 Im M₁₀`, `r₂ = 2 Re M₀₀ − 1` (using that `M` is Hermitian — diagonal + real, `M₀₁ = M₁₀*` — and has trace one — `M₁₁ = 1 − M₀₀`). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex +open scoped ComplexOrder + +/-- The **Bloch matrix** `½ (I + r·σ)` for a real three-vector `r`: the `2 × 2` complex matrix +representing a single-qubit density matrix with Bloch vector `r` (Nielsen & Chuang, Exercise +2.72, eq. 2.175). Built from the identity and the Pauli combination `Concrete.pauliDot r`. -/ +noncomputable def blochMatrix (r : Fin 3 → ℝ) : Matrix (Fin 2) (Fin 2) ℂ := + (2⁻¹ : ℂ) • (1 + pauliDot r) + +/-- The **Bloch vector** read off a `2 × 2` matrix's entries: `r₀ = 2 Re M₁₀`, `r₁ = 2 Im M₁₀`, +`r₂ = 2 Re M₀₀ − 1`. This is the left inverse of `blochMatrix` (`blochVector_blochMatrix`), so it +recovers the Bloch vector of a Bloch matrix — the extraction "the Bloch vector for `ρ`" that +Nielsen & Chuang, Exercise 2.72 names. -/ +noncomputable def blochVector (M : Matrix (Fin 2) (Fin 2) ℂ) : Fin 3 → ℝ := + ![2 * (M 1 0).re, 2 * (M 1 0).im, 2 * (M 0 0).re - 1] + +/-- `blochMatrix r` as a single explicit `2 × 2` matrix +`½ !![1 + r₂, r₀ − i r₁; r₀ + i r₁, 1 − r₂]`. -/ +theorem blochMatrix_eq (r : Fin 3 → ℝ) : + blochMatrix r = + !![(2⁻¹ : ℂ) * (1 + (r 2 : ℂ)), (2⁻¹ : ℂ) * ((r 0 : ℂ) - (r 1 : ℂ) * I); + (2⁻¹ : ℂ) * ((r 0 : ℂ) + (r 1 : ℂ) * I), (2⁻¹ : ℂ) * (1 - (r 2 : ℂ))] := by + rw [blochMatrix, pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.smul_apply, Matrix.add_apply, mul_add, sub_eq_add_neg] + +/-- **`blochVector (blochMatrix r) = r`**: recovering the Bloch vector off the entries inverts +`blochMatrix`. Reading `r₀ = 2 Re M₁₀` etc. back from `½(I + r·σ)`'s entries returns `r`. -/ +theorem blochVector_blochMatrix (r : Fin 3 → ℝ) : blochVector (blochMatrix r) = r := by + funext i + rw [blochMatrix_eq] + fin_cases i <;> + simp [blochVector, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply, Complex.add_re, Complex.mul_re, + Complex.ofReal_re, Complex.ofReal_im, Complex.mul_im, Complex.I_re, Complex.I_im] + +/-- `(blochMatrix r)ᴴ = blochMatrix r`: the Bloch matrix is self-adjoint (its diagonal entries are +real and its off-diagonal entries are complex conjugates). -/ +theorem blochMatrix_conjTranspose (r : Fin 3 → ℝ) : (blochMatrix r)ᴴ = blochMatrix r := by + rw [blochMatrix_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Matrix.conjTranspose_apply, Complex.ext_iff] + +/-- `blochMatrix r` is Hermitian for any real three-vector `r` (Nielsen & Chuang, Exercise 2.72: +the density matrix `ρ = ½(I + r·σ)` is Hermitian). -/ +theorem blochMatrix_isHermitian (r : Fin 3 → ℝ) : (blochMatrix r).IsHermitian := + blochMatrix_conjTranspose r + +/-- **`tr (blochMatrix r) = 1`**: the trace of the Bloch matrix is one, since the `±r₂` on the +diagonal cancels and the two `½`'s add. This is the trace-one half of "`blochMatrix r` is a +density matrix" (Nielsen & Chuang, Exercise 2.72). -/ +theorem blochMatrix_trace (r : Fin 3 → ℝ) : (blochMatrix r).trace = 1 := by + rw [blochMatrix_eq, Matrix.trace_fin_two] + simp only [Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply] + ring + +/-- **`blochMatrix 0 = ½ I`**: the Bloch matrix of the zero vector is half the identity, the +matrix underlying the maximally mixed state `I/2` (Nielsen & Chuang, Exercise 2.72(2): the state +`ρ = I/2` has Bloch vector `r_vec = 0`). -/ +theorem blochMatrix_zero : + blochMatrix (0 : Fin 3 → ℝ) = (2⁻¹ : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + rw [blochMatrix] + simp [pauliDot] + +/-- **`r ↦ blochMatrix r` is injective**: a Bloch matrix determines its Bloch vector, so the +"Bloch vector for `ρ`" of Nielsen & Chuang, Exercise 2.72 is unique. The three real components are +recovered from the `(0,0)` and `(1,0)` entries. -/ +theorem blochMatrix_injective : Function.Injective blochMatrix := + Function.LeftInverse.injective blochVector_blochMatrix + +/-- **Bloch decomposition (Nielsen & Chuang, Exercise 2.72(1), the "form" half).** Every Hermitian +`2 × 2` matrix of trace one is a Bloch matrix: there is a real three-vector `r` with +`M = ½(I + r·σ)`. The components are read off `M`'s entries — `r₀ = 2 Re M₁₀`, `r₁ = 2 Im M₁₀`, +`r₂ = 2 Re M₀₀ − 1` — using Hermiticity (diagonal real, `M₀₁ = M₁₀*`) and trace one +(`M₁₁ = 1 − M₀₀`). Together with `blochMatrix_isHermitian`/`blochMatrix_trace` this shows the +family `½(I + r·σ)` is *exactly* the Hermitian trace-one matrices. -/ +theorem exists_blochMatrix_of_isHermitian_trace_one {M : Matrix (Fin 2) (Fin 2) ℂ} + (hM : M.IsHermitian) (htr : M.trace = 1) : + ∃ r : Fin 3 → ℝ, M = blochMatrix r := by + refine ⟨blochVector M, ?_⟩ + -- Hermiticity: diagonal entries real, and `M₀₁ = conj M₁₀`. + have h00 : (M 0 0).im = 0 := Complex.conj_eq_iff_im.mp (hM.apply 0 0) + have h11 : (M 1 1).im = 0 := Complex.conj_eq_iff_im.mp (hM.apply 1 1) + have h01re : (M 0 1).re = (M 1 0).re := by + have := hM.apply 0 1; rw [Complex.ext_iff] at this; simpa using this.1.symm + have h01im : (M 0 1).im = -(M 1 0).im := by + have := hM.apply 0 1; rw [Complex.ext_iff] at this; simpa using this.2.symm + -- Trace one: `M₀₀ + M₁₁ = 1`, hence on real parts `Re M₀₀ + Re M₁₁ = 1`. + have htrre : (M 0 0).re + (M 1 1).re = 1 := by + rw [Matrix.trace_fin_two] at htr + have := congrArg Complex.re htr; simpa [Complex.add_re] using this + rw [blochMatrix_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [blochVector, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.head_cons, Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply, + Matrix.cons_val_two, Matrix.tail_cons] <;> + rw [Complex.ext_iff] <;> + refine ⟨?_, ?_⟩ <;> + simp [Complex.mul_re, Complex.mul_im, Complex.add_re, Complex.add_im, Complex.sub_re, + Complex.sub_im, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im] <;> + linarith [h00, h11, h01re, h01im, htrre] + +/-- **`det (blochMatrix r) = (1 − ‖r‖²)/4`** (with `‖r‖² = r₀² + r₁² + r₂²`). Computing the +`2 × 2` determinant of `½ !![1+r₂, r₀−i r₁; r₀+i r₁, 1−r₂]`, the diagonal product contributes +`¼(1 − r₂²)` and the off-diagonal product `¼(r₀² + r₁²)`, whose difference is `¼(1 − ‖r‖²)`. This +is the product `λ₊ λ₋` of the eigenvalues `(1 ± ‖r‖)/2` of the Bloch matrix, and it drives the +positivity criterion `blochMatrix_posSemidef_iff`. -/ +theorem blochMatrix_det (r : Fin 3 → ℝ) : + (blochMatrix r).det = ((1 - (r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2)) / 4 : ℝ) := by + rw [blochMatrix_eq, Matrix.det_fin_two] + simp only [Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply] + rw [Complex.ext_iff] + refine ⟨?_, ?_⟩ <;> + simp [Complex.mul_re, Complex.mul_im, Complex.add_re, Complex.add_im, Complex.sub_re, + Complex.sub_im, Complex.ofReal_re, Complex.ofReal_im, -Complex.ofReal_pow, Complex.I_re, + Complex.I_im] <;> + ring + +/-- **`tr ((blochMatrix r)²) = (1 + ‖r‖²)/2`** (with `‖r‖² = r₀² + r₁² + r₂²`). Squaring the Bloch +matrix `½(I + r·σ)` and taking the trace: the diagonal entries square to give +`¼(1+r₂)² + ¼(1−r₂)² = ½(1 + r₂²)`, and the two off-diagonal cross terms contribute +`2·¼(r₀ − i r₁)(r₀ + i r₁) = ½(r₀² + r₁²)`, summing to `½(1 + ‖r‖²)`. Equivalently +`tr ((blochMatrix r)²) = ½(1 + ‖r‖²)`, matching the eigenvalues `(1 ± ‖r‖)/2` (their squares sum to +`½(1 + ‖r‖²)`). This is the **purity** `tr ρ²` of the Bloch matrix; combined with the equivalence +`tr ρ² = 1 ↔ ρ` pure it drives the purity characterization `pure ↔ ‖r‖ = 1` (Nielsen & Chuang, +Exercise 2.72(3)). -/ +theorem blochMatrix_sq_trace (r : Fin 3 → ℝ) : + (blochMatrix r * blochMatrix r).trace + = (((1 + (r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2)) / 2 : ℝ) : ℂ) := by + rw [blochMatrix_eq, Matrix.mul_fin_two, Matrix.trace_fin_two] + simp only [Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply] + rw [Complex.ext_iff] + refine ⟨?_, ?_⟩ <;> + simp [Complex.mul_re, Complex.mul_im, Complex.add_re, Complex.add_im, Complex.sub_re, + Complex.sub_im, Complex.ofReal_re, Complex.ofReal_im, -Complex.ofReal_pow, Complex.I_re, + Complex.I_im] <;> + ring + +/-- **Positivity criterion for the Bloch matrix (Nielsen & Chuang, Exercise 2.72(1), positivity +half).** `blochMatrix r` is positive semidefinite iff `‖r‖² = r₀² + r₁² + r₂² ≤ 1` — equivalently +`‖r‖ ≤ 1`, since `‖r‖ ≥ 0`. Combined with `blochMatrix_isHermitian`, `blochMatrix_trace` and +`exists_blochMatrix_of_isHermitian_trace_one`, this identifies the Bloch matrices that are genuine +density matrices (Hermitian, trace one, positive semidefinite) as exactly the closed unit ball +`‖r‖ ≤ 1` — the **Bloch ball**. + +*Forward* (`PosSemidef ⇒ ‖r‖² ≤ 1`): a positive semidefinite matrix has nonnegative determinant +(`Matrix.PosSemidef.det_nonneg`), and `det (blochMatrix r) = (1 − ‖r‖²)/4` (`blochMatrix_det`), so +`0 ≤ (1 − ‖r‖²)/4`. + +*Reverse* (`‖r‖² ≤ 1 ⇒ PosSemidef`): writing `A := r·σ`, which is Hermitian +(`pauliDot_conjTranspose`) with `A² = ‖r‖²·I` (`pauliDot_mul_self`), one has the algebraic identity + +`blochMatrix r = ¼·(I+A)ᴴ(I+A) + ¼(1 − ‖r‖²)·I`, + +exhibiting `blochMatrix r` as a nonnegative combination of the positive semidefinite matrices +`(I+A)ᴴ(I+A)` (a Gram matrix, `Matrix.posSemidef_conjTranspose_mul_self`) and `I` +(`Matrix.PosSemidef.one`); the second coefficient `¼(1 − ‖r‖²)` is `≥ 0` exactly when `‖r‖² ≤ 1`. +This route sidesteps any normalisation of `r` (no `r/‖r‖`, no case split on `r = 0`). -/ +theorem blochMatrix_posSemidef_iff (r : Fin 3 → ℝ) : + (blochMatrix r).PosSemidef ↔ r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1 := by + constructor + · -- Forward: positive semidefinite ⇒ nonnegative determinant ⇒ ‖r‖² ≤ 1. + intro h + have hdet := h.det_nonneg + rw [blochMatrix_det, Complex.zero_le_real] at hdet + linarith + · -- Reverse: the Gram + scaled-identity decomposition. + intro hr + have hAh : (1 + pauliDot r)ᴴ = 1 + pauliDot r := by + rw [Matrix.conjTranspose_add, Matrix.conjTranspose_one, pauliDot_conjTranspose] + -- (I+A)ᴴ(I+A) = I + 2A + A² = I + 2A + ‖r‖²·I. + have hgram : (1 + pauliDot r)ᴴ * (1 + pauliDot r) + = 1 + pauliDot r + pauliDot r + + ((r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 : ℝ) : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + rw [hAh, + show (1 + pauliDot r) * (1 + pauliDot r) + = 1 + pauliDot r + pauliDot r + pauliDot r * pauliDot r from by noncomm_ring, + pauliDot_mul_self] + -- The scalar-level identity blochMatrix r = ¼(I+A)ᴴ(I+A) + ¼(1-‖r‖²)·I. The two coefficients + -- are written as coerced reals so the nonnegativity goals reduce via `Complex.zero_le_real`. + have heq : blochMatrix r + = (((4⁻¹ : ℝ) : ℂ)) • ((1 + pauliDot r)ᴴ * (1 + pauliDot r)) + + (((1 - (r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2)) / 4 : ℝ) : ℂ) + • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + rw [hgram, blochMatrix, pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, Matrix.of_apply, + Matrix.cons_val', Matrix.empty_val', Matrix.cons_val_fin_one, smul_eq_mul] <;> + push_cast <;> ring + rw [heq] + refine (Matrix.posSemidef_conjTranspose_mul_self _).smul ?_ |>.add + (Matrix.PosSemidef.one.smul ?_) + · rw [Complex.zero_le_real]; norm_num + · rw [Complex.zero_le_real]; linarith + +/-- **The Bloch ball is closed under a `[0,1]` shrink.** If `r` lies in the closed unit ball +`r₀² + r₁² + r₂² ≤ 1` and `0 ≤ c ≤ 1`, then so does the scaled vector `c r`: +`‖c r‖² = c² ‖r‖² ≤ c² ≤ 1`. A pure `Fin 3 → ℝ` companion to `blochMatrix_posSemidef_iff`'s ball +constraint, used to certify that the shrunk Bloch state stays a genuine density matrix (e.g. under +the depolarizing channel `r ↦ (1 − p) r`, Nielsen & Chuang Exercise 9.12). -/ +theorem sq_sum_smul_le_one {r : Fin 3 → ℝ} (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) {c : ℝ} + (hc0 : 0 ≤ c) (hc1 : c ≤ 1) : + (c • r) 0 ^ 2 + (c • r) 1 ^ 2 + (c • r) 2 ^ 2 ≤ 1 := by + simp only [Pi.smul_apply, smul_eq_mul] + nlinarith [h, sq_nonneg (r 0), sq_nonneg (r 1), sq_nonneg (r 2), hc0, hc1, mul_nonneg hc0 hc0] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlochPureState.lean b/LeanPool/AxQM/Concrete/BlochPureState.lean new file mode 100644 index 0000000000..2b2e27690b --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlochPureState.lean @@ -0,0 +1,143 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.BlochMatrix +public import LeanPool.AxQM.Concrete.PauliEigenvectors +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle + +/-! +# Concrete: the §1.2 single-qubit pure state and its Bloch vector (N&C, Exercise 2.72(4)) + +This file records, at the matrix level, the +**§1.2 Bloch-sphere parametrization of a single-qubit pure state** and its agreement with the +mixed-state Bloch representation `Concrete.blochMatrix` (eq. 2.175) of +`AxQM/Concrete/BlochMatrix.lean`. + +Nielsen & Chuang §1.2, eq. (1.4) writes a single-qubit pure state, up to global phase, as + +`|ψ(θ,φ)⟩ = cos(θ/2) |0⟩ + e^{iφ} sin(θ/2) |1⟩`, + +the point `(θ, φ)` lying on the Bloch sphere with Cartesian coordinates +`r_vec = (sin θ cos φ, sin θ sin φ, cos θ)`. Exercise 2.72(4) asks to show that for pure states this +Bloch vector **coincides** with the mixed-state Bloch vector of part (1): the density matrix +`|ψ(θ,φ)⟩⟨ψ(θ,φ)|` equals `½(I + r_vec·σ_vec)` for that `r_vec`. + +## Contents + +* `blochKet θ φ` — the column vector `cos(θ/2) |0⟩ + e^{iφ} sin(θ/2) |1⟩` of `ℂ²` (§1.2 eq. 1.4). +* `blochSphereVector θ φ` — the §1.2 Cartesian Bloch vector `(sin θ cos φ, sin θ sin φ, cos θ)`. +* `blochSphereVector_normSq` — it is a **unit vector**, `r₀² + r₁² + r₂² = 1` (so a pure state lies + on the *surface* of the Bloch ball, matching Exercise 2.72(3)). +* `outerSelf_blochKet_eq_blochMatrix` — **the coincidence at the matrix level:** the outer product + `|ψ(θ,φ)⟩⟨ψ(θ,φ)| = Concrete.outerSelf (blochKet θ φ)` equals `Concrete.blochMatrix + (blochSphereVector θ φ)`, i.e. `½(I + r_vec·σ_vec)` with `r_vec` the §1.2 vector. + +The state-level coincidence `|ψ⟩ = blochState r` for the pure state `PureState qubit` is in +`AxQM/Postulates/API/BlochState.lean` and [upstream `AxQM/NC/Ch2/Exercise2_72.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_72.lean). + +## Design notes + +* The amplitudes are kept as `↑(Real.cos (θ/2))` and `Complex.exp (↑φ * I) · ↑(Real.sin (θ/2))`, + faithful to N&C's `e^{iφ}`; the outer product `|ψ⟩⟨ψ|` reuses `Concrete.outerSelf v = vecMulVec v + (star v)` from `Concrete.PauliEigenvectors`, so `star` supplies the bra automatically (eq. 2.20). +* The matrix identity is proved entrywise from `blochMatrix_eq` (the explicit `2 × 2` form) and the + half-angle identities `cos²(θ/2) = (1+cos θ)/2`, `sin²(θ/2) = (1−cos θ)/2`, + `2 sin(θ/2) cos(θ/2) = sin θ` (from `Real.cos_sq` / `Real.sin_two_mul`), with `e^{iφ}` expanded + through `Complex.exp_mul_I`. This matches the entrywise idiom of `Concrete.BlochMatrix`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The **§1.2 single-qubit pure-state vector** `|ψ(θ,φ)⟩ = cos(θ/2) |0⟩ + e^{iφ} sin(θ/2) |1⟩` +(Nielsen & Chuang eq. 1.4), as a column vector `Fin 2 → ℂ`. Its polar angle `θ` and azimuth `φ` +locate the state on the Bloch sphere. -/ +noncomputable def blochKet (θ φ : ℝ) : Fin 2 → ℂ := + ![(Real.cos (θ / 2) : ℂ), Complex.exp ((φ : ℂ) * Complex.I) * (Real.sin (θ / 2) : ℂ)] + +/-- The **§1.2 Cartesian Bloch vector** `r_vec = (sin θ cos φ, sin θ sin φ, cos θ)` of the pure +state +`blochKet θ φ`: the spherical-to-Cartesian coordinates of the point `(θ, φ)` on the Bloch sphere +(Nielsen & Chuang §1.2, Figure 1.3), with the `z`-axis along `|0⟩`. -/ +noncomputable def blochSphereVector (θ φ : ℝ) : Fin 3 → ℝ := + ![Real.sin θ * Real.cos φ, Real.sin θ * Real.sin φ, Real.cos θ] + +/-- **The §1.2 Bloch vector is a unit vector:** `r₀² + r₁² + r₂² = 1` for `r_vec = +blochSphereVector θ +φ`. Indeed `sin²θ(cos²φ + sin²φ) + cos²θ = sin²θ + cos²θ = 1`. Consequently a pure state lies on the +*surface* `‖r_vec‖ = 1` of the Bloch ball (Nielsen & Chuang, Exercise 2.72(3)), and the vector is a +legitimate Bloch vector (`‖r_vec‖ ≤ 1`) for `Concrete.blochMatrix` / `blochState`. -/ +theorem blochSphereVector_normSq (θ φ : ℝ) : + blochSphereVector θ φ 0 ^ 2 + blochSphereVector θ φ 1 ^ 2 + + blochSphereVector θ φ 2 ^ 2 = 1 := by + simp only [blochSphereVector, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons] + nlinarith [Real.sin_sq_add_cos_sq θ, Real.sin_sq_add_cos_sq φ] + +/-- **Nielsen & Chuang, Exercise 2.72(4), matrix level: the Bloch vector of the §1.2 pure state is +the §1.2 Cartesian vector.** The density matrix `|ψ(θ,φ)⟩⟨ψ(θ,φ)| = Concrete.outerSelf (blochKet θ +φ)` equals `Concrete.blochMatrix (blochSphereVector θ φ) = ½(I + r_vec·σ_vec)` with `r_vec = (sin +θ cos φ, +sin θ sin φ, cos θ)`. So the mixed-state Bloch vector of part (1), read off `½(I + r_vec·σ_vec)`, +coincides with the §1.2 parametrization for this pure state. + +Proof: expand `e^{iφ} = cos φ + i sin φ` (`Complex.exp_mul_I`) and compare entries with the explicit +form `blochMatrix_eq`, using the half-angle identities `cos²(θ/2) = (1 + cos θ)/2`, +`sin²(θ/2) = (1 − cos θ)/2`, and `2 sin(θ/2) cos(θ/2) = sin θ`. E.g. the `(0,0)` entry is +`cos²(θ/2) = ½(1 + cos θ)`, the `(1,1)` entry `sin²(θ/2)(cos²φ + sin²φ) = ½(1 − cos θ)`, and the +off-diagonals `cos(θ/2) sin(θ/2) e^{∓iφ} = ½ sin θ · e^{∓iφ}`. -/ +theorem outerSelf_blochKet_eq_blochMatrix (θ φ : ℝ) : + outerSelf (blochKet θ φ) = blochMatrix (blochSphereVector θ φ) := by + have hc : Real.cos (θ / 2) ^ 2 = (1 + Real.cos θ) / 2 := by + have := Real.cos_sq (θ / 2); rw [show 2 * (θ / 2) = θ by ring] at this; rw [this]; ring + have hs : Real.sin (θ / 2) ^ 2 = (1 - Real.cos θ) / 2 := by + have h1 := Real.sin_sq_add_cos_sq (θ / 2) + have h2 := Real.cos_sq (θ / 2); rw [show 2 * (θ / 2) = θ by ring] at h2; nlinarith [h1, h2] + have hsc : 2 * Real.sin (θ / 2) * Real.cos (θ / 2) = Real.sin θ := by + have := Real.sin_two_mul (θ / 2); rw [show 2 * (θ / 2) = θ by ring] at this; linarith [this] + have hpyth : Real.sin φ ^ 2 + Real.cos φ ^ 2 = 1 := Real.sin_sq_add_cos_sq φ + -- the two off-diagonal entries need `hsc` scaled by `cos φ` / `sin φ`. + have hsc_c : 2 * Real.sin (θ / 2) * Real.cos (θ / 2) * Real.cos φ = Real.sin θ * Real.cos φ := by + rw [hsc] + have hsc_s : 2 * Real.sin (θ / 2) * Real.cos (θ / 2) * Real.sin φ = Real.sin θ * Real.sin φ := by + rw [hsc] + have hexp : Complex.exp ((φ : ℂ) * Complex.I) + = (Real.cos φ : ℂ) + (Real.sin φ : ℂ) * Complex.I := by + rw [Complex.exp_mul_I, Complex.ofReal_cos, Complex.ofReal_sin] + have h2 : (2⁻¹ : ℂ) = ((2⁻¹ : ℝ) : ℂ) := by norm_num + rw [blochMatrix_eq] + ext a b + fin_cases a <;> fin_cases b <;> + simp only [Fin.isValue, Fin.mk_zero, Fin.mk_one, outerSelf_apply, blochKet, blochSphereVector, + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, Matrix.of_apply, + Matrix.cons_val', Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.cons_val_two, + Matrix.tail_cons, hexp, h2, Complex.ext_iff, Complex.mul_re, Complex.mul_im, + Complex.add_re, Complex.add_im, Complex.sub_re, Complex.sub_im, Complex.ofReal_re, + Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.one_re, Complex.one_im, + Complex.neg_re, Complex.neg_im, + RCLike.star_def, map_add, map_mul, Complex.conj_ofReal, Complex.conj_I] <;> + constructor <;> nlinarith [hc, hs, hsc, hpyth, hsc_c, hsc_s] + +/-- The Bloch direction `blochSphereVector` is jointly continuous in `(θ, φ)`. -/ +theorem continuous_blochSphereVector : + Continuous (fun p : ℝ × ℝ => blochSphereVector p.1 p.2) := by + apply continuous_pi; intro i + fin_cases i <;> · simp only [blochSphereVector]; fun_prop + +/-- For a fixed polar angle `θ`, the Bloch direction is continuous in the azimuth `φ`. -/ +theorem continuous_blochSphereVector_snd (θ : ℝ) : + Continuous (fun φ : ℝ => blochSphereVector θ φ) := by + apply continuous_pi; intro i + fin_cases i <;> · simp only [blochSphereVector]; fun_prop + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlochRotation.lean b/LeanPool/AxQM/Concrete/BlochRotation.lean new file mode 100644 index 0000000000..aa61b20b96 --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlochRotation.lean @@ -0,0 +1,242 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.Concrete.BlochMatrix +public import Mathlib.LinearAlgebra.CrossProduct + +/-! +# Concrete: the rotation `R_n̂(θ)` rotates the Bloch vector (Nielsen & Chuang, Exercise 4.6) + +Nielsen & Chuang, Exercise 4.6 ("Bloch sphere interpretation of rotations") asks to show that the +qubit rotation `R_n̂(θ) = exp(−iθ n̂·σ/2)` (eq. 4.8) acts on a state with Bloch vector `_vecλ` by +rotating `_vecλ` through the angle `θ` about the `n̂` axis. This file develops the pure `2 × 2` +complex-matrix core of that fact — a statement about the conjugation +`ρ ↦ R_n̂(θ) ρ R_n̂(θ)ᴴ` acting on Bloch matrices. The statement for states and evolutions +is elsewhere. + +## The 3D rotation and the conjugation identity + +* `rot3D n θ` — the **3D rotation** of a vector about the unit axis `n` by angle `θ`, in Rodrigues + form `R(θ)v = cos θ · v + sin θ · (n × v) + (1 − cos θ)(n·v) · n`. This is the map the qubit + rotation induces on Bloch vectors. +* `pauliDot_conj_rotAxis` — the **conjugation identity** and heart of the exercise: for a unit axis + `n`, `R_n̂(θ) · (v·σ) · R_n̂(θ)ᴴ = (R(θ)v)·σ`. Conjugating the Pauli combination `v·σ` by the + spin-½ rotation is the Pauli combination of the *rotated* vector. The proof reduces `R_n̂(θ)` to + its closed form `cos(θ/2) I − i sin(θ/2)(n·σ)`, expands the triple product using the two Pauli + identities below, and matches coefficients with the half-angle formulae + `cos θ = cos²(θ/2) − sin²(θ/2)`, `sin θ = 2 sin(θ/2)cos(θ/2)`, `1 − cos θ = 2 sin²(θ/2)`. +* `blochMatrix_conj_rotAxis` — the **Bloch-matrix form**: `R_n̂(θ) · ½(I + v·σ) · R_n̂(θ)ᴴ = + ½(I + (R(θ)v)·σ)`, i.e. `R_n̂(θ) · blochMatrix v · R_n̂(θ)ᴴ = blochMatrix (rot3D n θ v)`. The + identity part is fixed by unitarity (`R R† = I`) and the traceless part rotates; this is the + matrix identity the theorem of Exercise 4.6 ([upstream `AxQM/NC/Ch4/Exercise4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_6.lean)) transports to states. +* `rot3D_sq_sum` — a rotation **preserves the squared length** of the Bloch vector, proved + algebraically from the conjugation identity (`(w·σ)² = ‖w‖² I` plus `R R† = R† R = I`), with no + expansion of the Rodrigues formula. This keeps `rot3D n θ v` in the Bloch ball. + +## Supporting Pauli identities + +* `pauliDot_mul` — the **Pauli product rule** (vector form): `(a·σ)(b·σ) = (a·b) I + i (a×b)·σ`, the + vector-calculus form of the multiplication table `σⱼσₖ = δⱼₖ I + i εⱼₖₗ σₗ`. +* `pauliDot_reflect` — the **reflection identity**: for a unit axis `n`, + `(n·σ)(v·σ)(n·σ) = 2(n·v)(n·σ) − (v·σ)`, i.e. conjugation by the involution `n·σ` reflects `v` in + the `n` axis. It supplies the triple-product `(n·σ)(v·σ)(n·σ)` term of the conjugation. + +(The linearity family `pauliDot_add` / `pauliDot_smul` / `pauliDot_sub` / `pauliDot_neg` of +`n ↦ n·σ`, used throughout, lives with `pauliDot`'s other basic lemmas in +`AxQM/Concrete/Pauli.lean`.) + +The physical statement of Exercise 4.6 — that `R_n̂(θ)` acting on the Bloch +*state* rotates its Bloch vector — is in [upstream `AxQM/NC/Ch4/Exercise4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_6.lean), built on +`blochMatrix_conj_rotAxis` and `rot3D_sq_sum`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **The Pauli product rule** (vector form): for real three-vectors `a`, `b`, +`(a·σ)(b·σ) = (a·b) I + i (a×b)·σ`, where `a·b` is the dot product and `a×b` the cross product. +This is the vector form of the multiplication table `σⱼσₖ = δⱼₖ I + i εⱼₖₗ σₗ`. -/ +theorem pauliDot_mul (a b : Fin 3 → ℝ) : + pauliDot a * pauliDot b + = ((a ⬝ᵥ b : ℝ) : ℂ) • 1 + Complex.I • pauliDot (crossProduct a b) := by + rw [pauliDot_eq, pauliDot_eq, pauliDot_eq] + rw [cross_apply, dotProduct] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.mul_apply, Fin.sum_univ_two, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.head_cons, Matrix.empty_val', Matrix.cons_val_fin_one, + Matrix.of_apply, Matrix.add_apply, Matrix.smul_apply, Matrix.one_apply, Fin.sum_univ_three, + Matrix.cons_val_two, Matrix.tail_cons, smul_eq_mul] <;> + rw [Complex.ext_iff] <;> + constructor <;> + simp [Complex.add_re, Complex.add_im, Complex.mul_re, Complex.mul_im, Complex.sub_re, + Complex.sub_im, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im] <;> + ring + +/-- The **conjugate transpose of the rotation operator** for a unit axis: +`R_n̂(θ)ᴴ = cos(θ/2) I + sin(θ/2) i (n·σ)` — the same closed form as `rotAxis_eq_of_unit` with the +sign of the `(n·σ)` term flipped (since `(n·σ)ᴴ = n·σ` and `star(sin(θ/2)·i) = -sin(θ/2)·i`). -/ +theorem rotAxis_conjTranspose_eq_of_unit {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) : + (rotAxis n θ)ᴴ = (Real.cos (θ / 2) : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) + + ((Real.sin (θ / 2) : ℂ) * Complex.I) • pauliDot n := by + rw [rotAxis_eq_of_unit hn, conjTranspose_sub, conjTranspose_smul, conjTranspose_smul, + conjTranspose_one, pauliDot_conjTranspose] + have h1 : star ((Real.cos (θ / 2) : ℂ)) = (Real.cos (θ / 2) : ℂ) := Complex.conj_ofReal _ + have h2 : star ((Real.sin (θ / 2) : ℂ) * Complex.I) = -((Real.sin (θ / 2) : ℂ) * Complex.I) := by + rw [star_mul', ← starRingEnd_apply, ← starRingEnd_apply, Complex.conj_ofReal, Complex.conj_I, + mul_neg] + rw [h1, h2, neg_smul, sub_neg_eq_add] + +/-- The **3D rotation** of a vector `v` by angle `θ` about the unit axis `n`, in Rodrigues form +`R(θ)v = cos θ · v + sin θ · (n × v) + (1 − cos θ)(n·v) · n`. This is the map on Bloch vectors that +the qubit rotation `R_n̂(θ)` induces (Nielsen & Chuang, Exercise 4.6). -/ +noncomputable def rot3D (n : Fin 3 → ℝ) (θ : ℝ) (v : Fin 3 → ℝ) : Fin 3 → ℝ := + Real.cos θ • v + Real.sin θ • crossProduct n v + ((1 - Real.cos θ) * (n ⬝ᵥ v)) • n + +/-- `n ⬝ᵥ n = ‖n‖²` for the scalar norm, `= 1` for a unit vector. -/ +theorem dotProduct_self_of_unit {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) : n ⬝ᵥ n = 1 := by + simp only [dotProduct, Fin.sum_univ_three] + nlinarith [hn] + +/-- A rotation **fixes its own axis**: `R(θ) n̂ = n̂` for a unit vector `n̂`. In the Rodrigues form +`rot3D n θ n = cos θ • n + sin θ • (n × n) + (1 − cos θ)(n·n) • n` the cross term vanishes +(`n × n = 0`) and `n·n = 1`, leaving `(cos θ + (1 − cos θ)) • n = n`. -/ +theorem rot3D_self {n : Fin 3 → ℝ} (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) : + rot3D n θ n = n := by + have hnn : n ⬝ᵥ n = 1 := dotProduct_self_of_unit hn + rw [rot3D, cross_self, smul_zero, add_zero, hnn, mul_one] + funext i + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] + ring + +/-- A rotation **about `e_z`** preserves the `z`-component of any vector: `(rot3D e_z θ u)₂ = u₂`. +The +Rodrigues terms contribute `cos θ · u₂`, `sin θ · (e_z × u)₂ = 0`, and `(1 − cos θ)(e_z·u)·e_z₂ = +(1 − cos θ) u₂`, summing to `u₂`. -/ +theorem rot3D_axisZ_apply_two (θ : ℝ) (u : Fin 3 → ℝ) : + (rot3D ![0, 0, 1] θ u) 2 = u 2 := by + simp only [rot3D, Pi.add_apply, Pi.smul_apply, smul_eq_mul, cross_apply, dotProduct, + Fin.sum_univ_three, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons] + ring + +/-- The **anti-commutator/reflection identity** for the Pauli combination: for a unit axis `n`, +`(n·σ)(v·σ)(n·σ) = 2(n·v)(n·σ) − (v·σ)`. Geometrically, conjugating `v·σ` by the involution `n·σ` +reflects the vector `v` in the `n` axis (`v ↦ 2(n·v)n − v`). Proved from the Pauli product rule +`pauliDot_mul` and the vector triple product `(n×v)×n = v − (n·v)n`. -/ +theorem pauliDot_reflect {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (v : Fin 3 → ℝ) : + pauliDot n * pauliDot v * pauliDot n + = (2 * (n ⬝ᵥ v : ℝ) : ℂ) • pauliDot n - pauliDot v := by + have hnn : n ⬝ᵥ n = 1 := dotProduct_self_of_unit hn + -- (n×v)·n = 0 + have hdot : (crossProduct n v) ⬝ᵥ n = 0 := by + rw [dotProduct_comm]; exact dot_self_cross n v + -- (n×v)×n = v − (n·v) n + have hcc : crossProduct (crossProduct n v) n = v - (n ⬝ᵥ v) • n := by + rw [← cross_anticomm, cross_cross_eq_smul_sub_smul', hnn, one_smul, neg_sub] + -- (n×v)·σ · n·σ = i (v − (n·v)n)·σ + have hPN : pauliDot (crossProduct n v) * pauliDot n + = Complex.I • (pauliDot v - ((n ⬝ᵥ v : ℝ) : ℂ) • pauliDot n) := by + rw [pauliDot_mul, hdot, hcc, pauliDot_sub, pauliDot_smul] + push_cast + module + rw [pauliDot_mul, add_mul, smul_mul_assoc, smul_mul_assoc, one_mul, hPN, smul_smul, + Complex.I_mul_I] + module + +/-- **The conjugation identity — the heart of Nielsen & Chuang, Exercise 4.6.** For a unit axis +`n`, conjugating the Pauli combination `v·σ` by the qubit rotation `R_n̂(θ)` is the Pauli +combination of the *rotated* vector: `R_n̂(θ) · (v·σ) · R_n̂(θ)ᴴ = (R(θ)v)·σ`, i.e. +`rotAxis n θ * pauliDot v * (rotAxis n θ)ᴴ = pauliDot (rot3D n θ v)`. Proof: reduce `R_n̂(θ)` to +its closed form `cos(θ/2) I − i sin(θ/2)(n·σ)`, expand the triple product using the Pauli product +rule `pauliDot_mul` and the reflection identity `pauliDot_reflect`, and match coefficients over the +basis `{I, n·σ, v·σ, (n×v)·σ}` with the half-angle formulae `cos θ = cos²(θ/2) − sin²(θ/2)`, +`sin θ = 2 sin(θ/2)cos(θ/2)`, `1 − cos θ = 2 sin²(θ/2)`. The unit-axis hypothesis is load-bearing +(it makes `(n·σ)² = I`); `θ` and `v` are fully general. -/ +theorem pauliDot_conj_rotAxis {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) (v : Fin 3 → ℝ) : + rotAxis n θ * pauliDot v * (rotAxis n θ)ᴴ = pauliDot (rot3D n θ v) := by + have hVN : pauliDot v * pauliDot n + = ((n ⬝ᵥ v : ℝ) : ℂ) • 1 - Complex.I • pauliDot (crossProduct n v) := by + rw [pauliDot_mul v n, dotProduct_comm v n, + show crossProduct v n = -crossProduct n v from (cross_anticomm n v).symm, pauliDot_neg, + smul_neg, sub_eq_add_neg] + have hcosR : Real.cos θ = Real.cos (θ / 2) ^ 2 - Real.sin (θ / 2) ^ 2 := by + have h2 := Real.cos_two_mul (θ / 2) + have hs := Real.sin_sq_add_cos_sq (θ / 2) + rw [show (2 : ℝ) * (θ / 2) = θ from by ring] at h2 + linear_combination h2 + hs + have hsinR : Real.sin θ = 2 * Real.sin (θ / 2) * Real.cos (θ / 2) := by + rw [← Real.sin_two_mul]; congr 1; ring + rw [rotAxis_conjTranspose_eq_of_unit hn, rotAxis_eq_of_unit hn] + simp only [sub_mul, mul_add, smul_mul_assoc, mul_smul_comm, one_mul, mul_one] + rw [pauliDot_reflect hn, pauliDot_mul n v, hVN, rot3D, pauliDot_add, pauliDot_add, pauliDot_smul, + pauliDot_smul, pauliDot_smul, hcosR, hsinR] + simp only [Complex.ofReal_mul, Complex.ofReal_sub, Complex.ofReal_one, Complex.ofReal_pow] + match_scalars + · -- coefficient of `v·σ`: `cos²(θ/2) − sin²(θ/2) = cos θ` + linear_combination (Complex.sin ((θ : ℂ) / 2)) ^ 2 * Complex.I_mul_I + · -- coefficient of `1`: the two `cos(θ/2)sin(θ/2)(n·v)` terms cancel + ring + · -- coefficient of `(n×v)·σ`: `2 sin(θ/2)cos(θ/2) = sin θ` + linear_combination + (-2 * Complex.sin ((θ : ℂ) / 2) * Complex.cos ((θ : ℂ) / 2)) * Complex.I_mul_I + · -- coefficient of `n·σ`: `2 sin²(θ/2)(n·v) = (1 − cos θ)(n·v)`, using `cos²+sin²=1` + linear_combination + (-2 * (Complex.sin ((θ : ℂ) / 2)) ^ 2 * ((n ⬝ᵥ v : ℝ) : ℂ)) * Complex.I_mul_I + + ((n ⬝ᵥ v : ℝ) : ℂ) * Complex.sin_sq_add_cos_sq ((θ : ℂ) / 2) + +/-- **The rotation operator conjugates the Bloch matrix by rotating its Bloch vector**: for a unit +axis `n`, `R_n̂(θ) · ½(I + v·σ) · R_n̂(θ)ᴴ = ½(I + (R(θ)v)·σ)`, i.e. +`R_n̂(θ) · blochMatrix v · R_n̂(θ)ᴴ = blochMatrix (rot3D n θ v)`. The identity part is fixed +(`R R† = I`) and the `v·σ` part rotates (`pauliDot_conj_rotAxis`). This is the matrix core of the +Bloch-sphere interpretation of the rotation `R_n̂(θ)` (Nielsen & Chuang, Exercise 4.6). -/ +theorem blochMatrix_conj_rotAxis {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) (v : Fin 3 → ℝ) : + rotAxis n θ * blochMatrix v * (rotAxis n θ)ᴴ = blochMatrix (rot3D n θ v) := by + simp only [blochMatrix, mul_smul_comm, smul_mul_assoc] + congr 1 + rw [mul_add, mul_one, add_mul, rotAxis_mul_conjTranspose_self, pauliDot_conj_rotAxis hn] + +/-- **A rotation preserves the squared length of the Bloch vector**: for a unit axis `n`, +`‖R(θ)v‖² = ‖v‖²` (with `‖·‖²` the scalar `·₀² + ·₁² + ·₂²`). Proved *algebraically* from the +conjugation identity, avoiding any expansion of the Rodrigues formula: `(R(θ)v)·σ = R(v·σ)R†`, so +`((R(θ)v)·σ)² = R(v·σ)²R† = ‖v‖² R R† = ‖v‖² I` using `R†R = R R† = I` and `(w·σ)² = ‖w‖² I`; +comparing with `((R(θ)v)·σ)² = ‖R(θ)v‖² I` gives `‖R(θ)v‖² = ‖v‖²`. Ensures the rotated Bloch +vector stays in the Bloch ball, so `blochState (rot3D n θ v)` is well defined. -/ +theorem rot3D_sq_sum {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) (v : Fin 3 → ℝ) : + (rot3D n θ v) 0 ^ 2 + (rot3D n θ v) 1 ^ 2 + (rot3D n θ v) 2 ^ 2 + = v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2 := by + have key : pauliDot (rot3D n θ v) * pauliDot (rot3D n θ v) + = ((v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2 : ℝ) : ℂ) • 1 := by + rw [← pauliDot_conj_rotAxis hn] + calc rotAxis n θ * pauliDot v * (rotAxis n θ)ᴴ + * (rotAxis n θ * pauliDot v * (rotAxis n θ)ᴴ) + = rotAxis n θ * pauliDot v * ((rotAxis n θ)ᴴ * rotAxis n θ) * pauliDot v + * (rotAxis n θ)ᴴ := by noncomm_ring + _ = rotAxis n θ * (pauliDot v * pauliDot v) * (rotAxis n θ)ᴴ := by + rw [rotAxis_conjTranspose_mul_self]; noncomm_ring + _ = ((v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2 : ℝ) : ℂ) • 1 := by + rw [pauliDot_mul_self, mul_smul_comm, smul_mul_assoc, mul_one, + rotAxis_mul_conjTranspose_self] + rw [pauliDot_mul_self] at key + have h00 := congrArg (fun M : Matrix (Fin 2) (Fin 2) ℂ => M 0 0) key + simp only [Matrix.smul_apply, Matrix.one_apply_eq, smul_eq_mul, mul_one] at h00 + exact_mod_cast h00 + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlochUnitaryRotation.lean b/LeanPool/AxQM/Concrete/BlochUnitaryRotation.lean new file mode 100644 index 0000000000..c5890aa277 --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlochUnitaryRotation.lean @@ -0,0 +1,343 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.BlochRotation +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup + +/-! +# Concrete: unitary conjugation of the Bloch matrix is an SO(3) rotation (N&C Exercise 8.13) + +Nielsen & Chuang, Exercise 8.13 asks to show that *unitary transformations correspond to rotations +of the Bloch sphere*. In the Bloch representation `ρ = ½(I + r·σ)` (N&C eq. 8.87, here +`Concrete.blochMatrix r`), the state conjugation `ρ ↦ U ρ U†` induced by a `2 × 2` unitary `U` +sends the Bloch vector `r` to `R r`, where `R` is a **proper rotation** `R ∈ SO(3)`. This is the +`SU(2) → SO(3)` homomorphism: the group of single-qubit unitaries (modulo the global phase, which +cancels in the conjugation) double-covers the rotation group of the Bloch ball. + +This file develops the pure `2 × 2`/`3 × 3` matrix core; the statement for evolutions and states +is in [upstream `AxQM/NC/Ch8/Exercise8_13.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_13.lean). + +## What is formalized + +* `blochRotationOfUnitary U` — the **induced 3D rotation matrix** `R(U) : Matrix (Fin 3) (Fin 3) ℝ`, + whose `k`-th column is the Pauli coordinate vector of `U σₖ U†`. +* `blochRotationOfUnitary_conj_pauliDot` — the **homomorphism at the Pauli level**: for a unitary + `U`, `U (v·σ) U† = (R(U) v)·σ`. Its heart is the reconstruction that a Hermitian traceless + `2 × 2` matrix `M` equals `(pauliCoords M)·σ` (`pauliDot_pauliCoords_of_isHermitian_trace_zero`), + applied to `U σₖ U†` (Hermitian since `σₖ` is, traceless since `tr(U σₖ U†) = tr σₖ = 0`). +* `blochRotationOfUnitary_mem_orthogonalGroup` — `R(U)ᵀ R(U) = I`, from the Hilbert–Schmidt + orthonormality of the columns: `2 (wₖ · wₗ) = tr((wₖ·σ)(wₗ·σ)) = tr(U σₖ σₗ U†) = 2δₖₗ`. +* `blochRotationOfUnitary_det` — `det R(U) = 1`, from the orientation identity `X Y Z = i I`: + `2i (w₀×w₁)·w₂ = tr((w₀·σ)(w₁·σ)(w₂·σ)) = tr(U (XYZ) U†) = tr(i I) = 2i`, and + `det R = (w₀×w₁)·w₂` (the scalar triple product of the columns). +* `exists_mem_specialOrthogonalGroup_blochMatrix_conj_unitary` — **Exercise 8.13 (Concrete + headline)**: for any unitary `U`, there is `R ∈ SO(3)` with `U (blochMatrix r) U† = blochMatrix + (R r)` for every Bloch vector `r`. + +The physical statement — that unitary *evolution* rotates +the Bloch *state*'s vector — is in [upstream `AxQM/NC/Ch8/Exercise8_13.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_13.lean). + +## Design notes + +* The Pauli coordinates are `pauliCoords M = (Re M₁₀, Im M₁₀, Re M₀₀)`, the inverse of + `pauliDot` on the space of Hermitian traceless matrices (compare `Concrete.blochVector`, which + carries the affine `−1` shift for the trace-one Bloch matrices). No factor of two appears. +* The whole `SU(2) → SO(3)` construction is *uniform* in `U`: orthogonality and `det = 1` are read + off two Pauli-trace identities (`pauliDot_trace_mul`, `pauliDot_trace_mul3`) with the unitary's + role reduced to the cyclicity `tr(U A U†) = tr A`. In particular the axis-angle decomposition + (`Concrete.exists_axis_angle_decomposition`) is *not* used — the proof holds for any unitary. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- `tr(v·σ) = 0`: the Pauli combination is traceless (its diagonal is `(v₂, −v₂)`). -/ +theorem pauliDot_trace (v : Fin 3 → ℝ) : (pauliDot v).trace = 0 := by + rw [pauliDot_eq, Matrix.trace_fin_two] + simp + +/-- **Hilbert–Schmidt pairing of Pauli combinations**: `tr((a·σ)(b·σ)) = 2 (a · b)`. The `(a·b) I` +part of the Pauli product rule contributes `2 (a·b)`; the `i (a×b)·σ` part is traceless. -/ +theorem pauliDot_trace_mul (a b : Fin 3 → ℝ) : + (pauliDot a * pauliDot b).trace = 2 * ((a ⬝ᵥ b : ℝ) : ℂ) := by + rw [pauliDot_mul, Matrix.trace_add, Matrix.trace_smul, Matrix.trace_smul, trace_one_fin_two, + pauliDot_trace, smul_eq_mul, smul_eq_mul, mul_zero, add_zero, mul_comm] + +/-- **Triple Pauli trace** (the orientation pairing): `tr((a·σ)(b·σ)(c·σ)) = 2i ((a×b) · c)`. From +the Pauli product rule `(a·σ)(b·σ) = (a·b) I + i (a×b)·σ` and `pauliDot_trace`/`pauliDot_trace_mul`: +the `(a·b) I` term multiplies a traceless `c·σ`, and the `i (a×b)·σ` term pairs with `c·σ` to give +`i · 2((a×b)·c)`. This is the scalar triple product that drives `det R = 1`. -/ +theorem pauliDot_trace_mul3 (a b c : Fin 3 → ℝ) : + (pauliDot a * pauliDot b * pauliDot c).trace + = 2 * Complex.I * (((crossProduct a) b ⬝ᵥ c : ℝ) : ℂ) := by + rw [pauliDot_mul, add_mul, Matrix.trace_add, Matrix.smul_mul, Matrix.smul_mul, + Matrix.trace_smul, Matrix.trace_smul, one_mul, pauliDot_trace, pauliDot_trace_mul, + smul_eq_mul, smul_eq_mul, mul_zero, zero_add] + ring + +/-- `pauliDot (Pi.single 0 1) = X`. -/ +theorem pauliDot_single_zero : pauliDot (Pi.single 0 (1 : ℝ)) = pauliX := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX] + +/-- `pauliDot (Pi.single 1 1) = Y`. -/ +theorem pauliDot_single_one : pauliDot (Pi.single 1 (1 : ℝ)) = pauliY := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliY] + +/-- `pauliDot (Pi.single 2 1) = Z`. -/ +theorem pauliDot_single_two : pauliDot (Pi.single 2 (1 : ℝ)) = pauliZ := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliZ] + +/-- The orientation identity `X Y Z = i I` (positive handedness of the Pauli vector). -/ +theorem pauliX_mul_pauliY_mul_pauliZ : + pauliX * pauliY * pauliZ = Complex.I • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, pauliY, pauliZ, Matrix.mul_apply, Fin.sum_univ_two] + +/-- The **Pauli coordinates** of a `2 × 2` matrix: `(Re M₁₀, Im M₁₀, Re M₀₀)`. On the Hermitian +traceless matrices this inverts `pauliDot` (`pauliDot_pauliCoords_of_isHermitian_trace_zero`). -/ +noncomputable def pauliCoords (M : Matrix (Fin 2) (Fin 2) ℂ) : Fin 3 → ℝ := + ![(M 1 0).re, (M 1 0).im, (M 0 0).re] + +/-- **Reconstruction**: a Hermitian, traceless `2 × 2` matrix `M` is `(pauliCoords M)·σ`. Reading +`(Re M₁₀, Im M₁₀, Re M₀₀)` back through `pauliDot` returns `M`, using Hermiticity (diagonal real, +`M₀₁ = M₁₀*`) and tracelessness (`M₁₁ = −M₀₀`). This is the `pauliDot`-inverse that turns each +conjugate `U σₖ U†` into a real three-vector. -/ +theorem pauliDot_pauliCoords_of_isHermitian_trace_zero {M : Matrix (Fin 2) (Fin 2) ℂ} + (hH : M.IsHermitian) (h0 : M.trace = 0) : pauliDot (pauliCoords M) = M := by + have h00 : (M 0 0).im = 0 := Complex.conj_eq_iff_im.mp (hH.apply 0 0) + have h11 : (M 1 1).im = 0 := Complex.conj_eq_iff_im.mp (hH.apply 1 1) + have h01re : (M 0 1).re = (M 1 0).re := by + have := hH.apply 0 1; rw [Complex.ext_iff] at this; simpa using this.1.symm + have h01im : (M 0 1).im = -(M 1 0).im := by + have := hH.apply 0 1; rw [Complex.ext_iff] at this; simpa using this.2.symm + have htr : (M 0 0).re + (M 1 1).re = 0 := by + rw [Matrix.trace_fin_two] at h0 + have := congrArg Complex.re h0; simpa [Complex.add_re] using this + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [pauliCoords, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.head_cons, Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply, + Matrix.cons_val_two, Matrix.tail_cons] <;> + rw [Complex.ext_iff] <;> + refine ⟨?_, ?_⟩ <;> + simp [Complex.sub_re, Complex.sub_im, Complex.mul_re, + Complex.mul_im, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im] <;> + linarith [h00, h11, h01re, h01im, htr] + +/-- `tr(U A U†) = tr A` for a unitary `U` (`U† U = 1`): cyclicity of the trace. -/ +theorem trace_conjUnitary {U : Matrix (Fin 2) (Fin 2) ℂ} (hUU' : Uᴴ * U = 1) + (A : Matrix (Fin 2) (Fin 2) ℂ) : (U * A * Uᴴ).trace = A.trace := by + rw [Matrix.trace_mul_cycle, hUU', one_mul] + +/-- Conjugation by a unitary is multiplicative: `(U A U†)(U B U†) = U (A B) U†` (using `U† U = 1`). +The engine of both SO(3)-membership proofs: it collapses a product of conjugates to a single +conjugate whose trace is `tr(A B)` via `trace_conjUnitary`. -/ +theorem conjUnitary_mul {U : Matrix (Fin 2) (Fin 2) ℂ} (hUU' : Uᴴ * U = 1) + (A B : Matrix (Fin 2) (Fin 2) ℂ) : + U * A * Uᴴ * (U * B * Uᴴ) = U * (A * B) * Uᴴ := by + simp only [mul_assoc] + rw [← mul_assoc Uᴴ U, hUU', one_mul] + +/-- `U A U†` is Hermitian when `A` is a Pauli combination (`(v·σ)† = v·σ`). -/ +theorem conjUnitary_pauliDot_isHermitian (U : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin 3 → ℝ) : + (U * pauliDot v * Uᴴ).IsHermitian := by + unfold Matrix.IsHermitian + rw [Matrix.conjTranspose_mul, Matrix.conjTranspose_mul, Matrix.conjTranspose_conjTranspose, + pauliDot_conjTranspose, ← mul_assoc] + +/-- The **induced 3D rotation matrix** `R(U)` of a `2 × 2` unitary: its `k`-th column is the Pauli +coordinate vector of `U σₖ U†`, where `σₖ = pauliDot (Pi.single k 1)` (so `σ₀ = X`, `σ₁ = Y`, +`σ₂ = Z`). By `blochRotationOfUnitary_conj_pauliDot` it satisfies `U (v·σ) U† = (R(U) v)·σ`. -/ +noncomputable def blochRotationOfUnitary (U : Matrix (Fin 2) (Fin 2) ℂ) : + Matrix (Fin 3) (Fin 3) ℝ := + Matrix.of fun j k => pauliCoords (U * pauliDot (Pi.single k 1) * Uᴴ) j + +/-- Each conjugated basis Pauli reconstructs to the corresponding column of `R(U)`: +`U σₖ U† = (colₖ R(U))·σ`. Immediate from the reconstruction lemma, since `U σₖ U†` is Hermitian +and traceless and `colₖ R(U)` is by definition its Pauli coordinates. -/ +theorem conjUnitary_pauliDot_eq_col {U : Matrix (Fin 2) (Fin 2) ℂ} (hUU' : Uᴴ * U = 1) + (k : Fin 3) : + U * pauliDot (Pi.single k 1) * Uᴴ = pauliDot (fun j => blochRotationOfUnitary U j k) := by + rw [← pauliDot_pauliCoords_of_isHermitian_trace_zero (conjUnitary_pauliDot_isHermitian U _) + (by rw [trace_conjUnitary hUU', pauliDot_trace])] + rfl + +/-- `pauliDot` distributes over a real-scalar `Fin 3` sum. -/ +theorem pauliDot_sum3 (c : Fin 3 → ℝ) (w : Fin 3 → (Fin 3 → ℝ)) : + pauliDot (∑ k, c k • w k) = ∑ k, (c k : ℂ) • pauliDot (w k) := by + rw [Fin.sum_univ_three, Fin.sum_univ_three, pauliDot_add, pauliDot_add, pauliDot_smul, + pauliDot_smul, pauliDot_smul] + +/-- The standard-basis expansion `∑ k, v k • Pi.single k 1 = v`. -/ +theorem sum_smul_single (v : Fin 3 → ℝ) : + (∑ k, v k • (Pi.single k 1 : Fin 3 → ℝ)) = v := by + funext i + rw [Finset.sum_apply] + simp [Pi.single_apply, Finset.sum_ite_eq] + +/-- `v·σ = ∑ k, vₖ (Pi.single k 1)·σ`: the Pauli combination as a basis sum, used to reduce the +homomorphism to its action on the basis conjugates. -/ +theorem pauliDot_eq_sum (v : Fin 3 → ℝ) : + pauliDot v = ∑ k, (v k : ℂ) • pauliDot (Pi.single k (1 : ℝ)) := by + conv_lhs => rw [← sum_smul_single v] + rw [pauliDot_sum3] + +/-- `R.mulVec v` as the scaled sum of the columns of `R`. -/ +theorem mulVec_eq_sum_col (R : Matrix (Fin 3) (Fin 3) ℝ) (v : Fin 3 → ℝ) : + R.mulVec v = ∑ k, v k • (fun j => R j k) := by + funext j + simp only [Matrix.mulVec, dotProduct, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + exact Finset.sum_congr rfl fun k _ => mul_comm _ _ + +/-- **The `SU(2) → SO(3)` homomorphism at the Pauli level.** For a unitary `U`, conjugating the +Pauli combination `v·σ` gives that of the rotated vector: `U (v·σ) U† = (R(U) v)·σ`. +The proof expands `v·σ = ∑ vₖ σₖ`, distributes the conjugation over the sum, reconstructs each +`U σₖ U†` as `(colₖ R(U))·σ`, and reassembles `∑ vₖ colₖ = R(U) v`. -/ +theorem blochRotationOfUnitary_conj_pauliDot {U : Matrix (Fin 2) (Fin 2) ℂ} + (hUU' : Uᴴ * U = 1) (v : Fin 3 → ℝ) : + U * pauliDot v * Uᴴ = pauliDot ((blochRotationOfUnitary U).mulVec v) := by + rw [pauliDot_eq_sum v, Finset.mul_sum, Finset.sum_mul] + simp_rw [Matrix.mul_smul, Matrix.smul_mul, conjUnitary_pauliDot_eq_col hUU'] + rw [mulVec_eq_sum_col, pauliDot_sum3] + +/-- **`R(U)ᵀ R(U) = I`**: `R(U)` is orthogonal. The `(k, l)` entry of `R(U)ᵀ R(U)` is +`colₖ · colₗ`, and `2 (colₖ · colₗ) = tr((colₖ·σ)(colₗ·σ)) = tr(U σₖ σₗ U†) = tr(σₖ σₗ) += 2 (σₖ-vector · σₗ-vector) = 2 δₖₗ`, using the Pauli trace pairing and trace cyclicity. -/ +theorem blochRotationOfUnitary_mem_orthogonalGroup {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + blochRotationOfUnitary U ∈ Matrix.orthogonalGroup (Fin 3) ℝ := by + have hUU' : Uᴴ * U = 1 := (Matrix.mem_unitaryGroup_iff' (n := Fin 2) (α := ℂ)).mp hU + -- the columns are orthonormal: `colₚ · col_q = δₚ_q`, via the Pauli-trace pairing. + have hcol : ∀ p q : Fin 3, + (∑ j, blochRotationOfUnitary U j p * blochRotationOfUnitary U j q) + = if p = q then (1 : ℝ) else 0 := by + intro p q + have key : (pauliDot (fun j => blochRotationOfUnitary U j p) + * pauliDot (fun j => blochRotationOfUnitary U j q)).trace + = (pauliDot (Pi.single p 1) * pauliDot (Pi.single q 1)).trace := by + rw [← conjUnitary_pauliDot_eq_col hUU' p, ← conjUnitary_pauliDot_eq_col hUU' q, + conjUnitary_mul hUU', trace_conjUnitary hUU'] + rw [pauliDot_trace_mul, pauliDot_trace_mul] at key + have hreal : ((fun j => blochRotationOfUnitary U j p) ⬝ᵥ + (fun j => blochRotationOfUnitary U j q)) = (Pi.single p (1 : ℝ) ⬝ᵥ Pi.single q 1) := by + exact_mod_cast mul_left_cancel₀ (by norm_num : (2 : ℂ) ≠ 0) key + rw [show (∑ j, blochRotationOfUnitary U j p * blochRotationOfUnitary U j q) + = (fun j => blochRotationOfUnitary U j p) ⬝ᵥ (fun j => blochRotationOfUnitary U j q) + from rfl, hreal, single_dotProduct, one_mul, Pi.single_apply] + rw [Matrix.mem_orthogonalGroup_iff'] + ext k l + rw [Matrix.mul_apply, Matrix.one_apply] + simp only [Matrix.transpose_apply] + exact hcol k l + +/-- **`det R(U) = 1`**: `R(U)` is a *proper* rotation. Its determinant equals the scalar triple +product `(col₀ × col₁) · col₂` of the columns, and `2i ((col₀×col₁)·col₂) = tr((col₀·σ)(col₁·σ) +(col₂·σ)) = tr(U (X Y Z) U†) = tr(i I) = 2i` (using `X Y Z = i I` and trace cyclicity), so the +triple product is `1`. -/ +theorem blochRotationOfUnitary_det {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : (blochRotationOfUnitary U).det = 1 := by + have hUU' : Uᴴ * U = 1 := (Matrix.mem_unitaryGroup_iff' (n := Fin 2) (α := ℂ)).mp hU + set c0 : Fin 3 → ℝ := fun j => blochRotationOfUnitary U j 0 with hc0 + set c1 : Fin 3 → ℝ := fun j => blochRotationOfUnitary U j 1 with hc1 + set c2 : Fin 3 → ℝ := fun j => blochRotationOfUnitary U j 2 with hc2 + -- the triple product is 1 + have htriple : (crossProduct c0) c1 ⬝ᵥ c2 = 1 := by + have hkey : (pauliDot c0 * pauliDot c1 * pauliDot c2).trace = 2 * Complex.I := by + rw [hc0, hc1, hc2, ← conjUnitary_pauliDot_eq_col hUU', ← conjUnitary_pauliDot_eq_col hUU', + ← conjUnitary_pauliDot_eq_col hUU'] + rw [conjUnitary_mul hUU', conjUnitary_mul hUU', trace_conjUnitary hUU', + pauliDot_single_zero, pauliDot_single_one, pauliDot_single_two, + pauliX_mul_pauliY_mul_pauliZ, Matrix.trace_smul, trace_one_fin_two, smul_eq_mul] + ring + have heq := hkey.symm.trans (pauliDot_trace_mul3 c0 c1 c2) + -- 2i = 2i * triple ⟹ triple = 1 + have : (((crossProduct c0) c1 ⬝ᵥ c2 : ℝ) : ℂ) = 1 := + mul_left_cancel₀ (by simp [Complex.ext_iff] : (2 * Complex.I : ℂ) ≠ 0) + (by rw [mul_one]; exact heq.symm) + exact_mod_cast this + -- det = scalar triple product of the columns + rw [Matrix.det_fin_three] + simp only [cross_apply, dotProduct, Fin.sum_univ_three, Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.head_cons, Matrix.cons_val_two, Matrix.tail_cons] at htriple + simp only [hc0, hc1, hc2] at htriple + linarith [htriple] + +/-- `R(U) ∈ SO(3)`: combining orthogonality and `det = 1`. -/ +theorem blochRotationOfUnitary_mem_specialOrthogonalGroup {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + blochRotationOfUnitary U ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ := + Matrix.mem_specialOrthogonalGroup_iff.mpr + ⟨blochRotationOfUnitary_mem_orthogonalGroup hU, blochRotationOfUnitary_det hU⟩ + +/-- **`R(U)` preserves the squared Bloch-vector length**: `‖R(U) r‖² = ‖r‖²` (with `‖·‖²` the +scalar `·₀² + ·₁² + ·₂²`). Proved *algebraically* from the homomorphism identity, mirroring +`rot3D_sq_sum`: `(R(U) r)·σ = U (r·σ) U†`, so `((R(U) r)·σ)² = U (r·σ)² U† = ‖r‖² U U† = ‖r‖² I` +using `U† U = U U† = I` and `(w·σ)² = ‖w‖² I` (`pauliDot_mul_self`); comparing with +`((R(U) r)·σ)² = ‖R(U) r‖² I` gives `‖R(U) r‖² = ‖r‖²`. Since `R(U)` is an SO(3) rotation this is +just orthogonality, but the Pauli-square route needs no orthogonal-group API. It keeps the rotated +Bloch vector in the ball, so `blochState (R(U) r)` is well defined (Exercise 8.13). -/ +theorem blochRotationOfUnitary_mulVec_sq_sum {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) (r : Fin 3 → ℝ) : + ((blochRotationOfUnitary U).mulVec r) 0 ^ 2 + ((blochRotationOfUnitary U).mulVec r) 1 ^ 2 + + ((blochRotationOfUnitary U).mulVec r) 2 ^ 2 + = r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 := by + have hUU : U * Uᴴ = 1 := (Matrix.mem_unitaryGroup_iff (n := Fin 2) (α := ℂ)).mp hU + have hUU' : Uᴴ * U = 1 := (Matrix.mem_unitaryGroup_iff' (n := Fin 2) (α := ℂ)).mp hU + have key : pauliDot ((blochRotationOfUnitary U).mulVec r) + * pauliDot ((blochRotationOfUnitary U).mulVec r) + = ((r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 : ℝ) : ℂ) • 1 := by + rw [← blochRotationOfUnitary_conj_pauliDot hUU'] + calc U * pauliDot r * Uᴴ * (U * pauliDot r * Uᴴ) + = U * pauliDot r * (Uᴴ * U) * pauliDot r * Uᴴ := by noncomm_ring + _ = U * (pauliDot r * pauliDot r) * Uᴴ := by rw [hUU']; noncomm_ring + _ = ((r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 : ℝ) : ℂ) • 1 := by + rw [pauliDot_mul_self, mul_smul_comm, smul_mul_assoc, mul_one, hUU] + rw [pauliDot_mul_self] at key + have h00 := congrArg (fun M : Matrix (Fin 2) (Fin 2) ℂ => M 0 0) key + simp only [Matrix.smul_apply, Matrix.one_apply_eq, smul_eq_mul, mul_one] at h00 + exact_mod_cast h00 + +/-- **Unitary conjugation of the Bloch matrix rotates its Bloch vector.** For a unitary `U`, +`U (blochMatrix r) U† = blochMatrix (R(U) r)`: the identity part is fixed (`U U† = I`) and the +traceless part rotates (`blochRotationOfUnitary_conj_pauliDot`). -/ +theorem blochMatrix_conj_unitary {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) (r : Fin 3 → ℝ) : + U * blochMatrix r * Uᴴ = blochMatrix ((blochRotationOfUnitary U).mulVec r) := by + have hUU : U * Uᴴ = 1 := (Matrix.mem_unitaryGroup_iff (n := Fin 2) (α := ℂ)).mp hU + have hUU' : Uᴴ * U = 1 := (Matrix.mem_unitaryGroup_iff' (n := Fin 2) (α := ℂ)).mp hU + simp only [blochMatrix, Matrix.mul_smul, Matrix.smul_mul] + congr 1 + rw [mul_add, mul_one, add_mul, hUU, blochRotationOfUnitary_conj_pauliDot hUU'] + +/-- **Nielsen & Chuang, Exercise 8.13 (Concrete headline) — unitary transformations correspond to +rotations of the Bloch sphere.** For any `2 × 2` unitary `U`, the state conjugation +`ρ ↦ U ρ U†` on the Bloch matrix `ρ = ½(I + r·σ)` acts on the Bloch vector `r` as a *proper +rotation* `R ∈ SO(3)`: there exists `R ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ` with +`U (blochMatrix r) U† = blochMatrix (R r)` for every `r`. The witness is +`blochRotationOfUnitary U`, the `SU(2) → SO(3)` image of `U`. -/ +theorem exists_mem_specialOrthogonalGroup_blochMatrix_conj_unitary + {U : Matrix (Fin 2) (Fin 2) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ R ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ, + ∀ r : Fin 3 → ℝ, U * blochMatrix r * Uᴴ = blochMatrix (R.mulVec r) := + ⟨blochRotationOfUnitary U, blochRotationOfUnitary_mem_specialOrthogonalGroup hU, + fun r => blochMatrix_conj_unitary hU r⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlockDiagonalPeel.lean b/LeanPool/AxQM/Concrete/BlockDiagonalPeel.lean new file mode 100644 index 0000000000..138bd70674 --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlockDiagonalPeel.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.BlockOneEmbedding + +/-! +# Concrete: the block-diagonal peel of §4.5.1 (`phase ⊕ corner` from a cleared first column) + +The two-level decomposition of an arbitrary `d × d` unitary (Nielsen & Chuang §4.5.1, p. 189–191) +proceeds by an induction on the dimension. Column-clearing +(`AxQM.Concrete.exists_twoLevelUnitaryList_clear_first_column`) reduces a `(d+1) × (d+1)` +unitary, after left-multiplication by two-level unitaries, to a matrix `W` whose first column is a +multiple of `e₀` (`W i 0 = 0` for `i ≠ 0`). N&C eq. (4.51) then reads off that such a `W`, *being +unitary*, is **block-diagonal**: its first row is also a multiple of `e₀`, so `W = 1 ⊕ V'` up to a +phase on coordinate `0`, with `V'` a `d × d` unitary on the remaining coordinates. The inductive +step then decomposes `V'`. + +This file supplies that **peel** as reusable mathematics, independently of the induction +itself (`AxQM/Concrete/TwoLevelDecomposition.lean`): + +* `phaseShift c` — the single-coordinate phase `diag(c, 1, …, 1)`, unitary for `|c| = 1` + (`phaseShift_mem_unitaryGroup`) and a two-level unitary (`isTwoLevelUnitary_phaseShift`), acting + nontrivially only on coordinate `0`. +* `apply_zero_of_clearFirstColumn` — the unitarity input: a unitary whose first column is a multiple + of `e₀` has its **first row** a multiple of `e₀` too (`W 0 j = 0` for `j ≠ 0`), and `|W 0 0| = 1`. +* `exists_phaseShift_mul_blockOne_of_clearFirstColumn` — the peel: for such a `W` there is a + phase `c` (with `|c| = 1`) and a `d × d` unitary `C` (the lower-right corner + `W.submatrix Fin.succ Fin.succ`) with `W = phaseShift c * blockOne C`. Both factors are two-level + unitaries (`phaseShift` directly, `blockOne` of a product of two-level factors via + `isTwoLevelUnitary_blockOne`), which is what lets the §4.5.1 induction reassemble the corner's + decomposition into two-level factors on the full space. + +## Use + +This is a shared building block for the §4.5.1 development (Exercise 4.43's `n`-qubit lift, +reusable by Exercises 4.37/4.38). The statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **The single-coordinate phase** `diag(c, 1, …, 1)`: the `(d+1) × (d+1)` diagonal matrix with `c` +in the top-left corner and `1` on the rest of the diagonal. It fixes every coordinate except `0`, +where it multiplies by `c`; for `|c| = 1` it is a (one-level, hence two-level) unitary. This is the +phase factor of the §4.5.1 block-diagonal peel `W = phaseShift (W 0 0) * blockOne C`. -/ +def phaseShift (c : ℂ) : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ := + Matrix.diagonal (Fin.cons c (1 : Fin d → ℂ)) + +@[simp] theorem phaseShift_zero_zero (c : ℂ) : + (phaseShift c : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) 0 0 = c := by + simp [phaseShift, Matrix.diagonal_apply_eq] + +/-- `phaseShift c` acts as the identity on the tail: its `(i.succ, i.succ)` entry is `1`. -/ +@[simp] theorem phaseShift_succ_succ (c : ℂ) (i : Fin d) : + (phaseShift c : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) i.succ i.succ = 1 := by + simp [phaseShift, Matrix.diagonal_apply_eq] + +/-- `phaseShift c` is diagonal: off-diagonal entries vanish. -/ +theorem phaseShift_apply_of_ne (c : ℂ) {i j : Fin (d + 1)} (h : i ≠ j) : + phaseShift c i j = 0 := + Matrix.diagonal_apply_ne _ h + +/-- **`phaseShift c` is unitary** when `|c| = 1` (equivalently `Complex.normSq c = 1`): a diagonal +matrix is unitary iff each diagonal entry has unit modulus, and here they are `c` and `1`. -/ +theorem phaseShift_mem_unitaryGroup {c : ℂ} (hc : Complex.normSq c = 1) : + (phaseShift c : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) ∈ + Matrix.unitaryGroup (Fin (d + 1)) ℂ := by + rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose, phaseShift, + Matrix.diagonal_conjTranspose, Matrix.diagonal_mul_diagonal, ← Matrix.diagonal_one] + congr 1 + funext i + simp only [Pi.star_apply] + induction i using Fin.cases with + | zero => rw [Fin.cons_zero]; simp [mul_comm, Complex.mul_conj, hc] + | succ i => rw [Fin.cons_succ]; simp + +/-- **`phaseShift c` is a two-level unitary** when `|c| = 1`: it is unitary and agrees with the +identity outside the single coordinate `0` (take `p = q = 0` in `IsTwoLevelUnitary`). -/ +theorem isTwoLevelUnitary_phaseShift {c : ℂ} (hc : Complex.normSq c = 1) : + IsTwoLevelUnitary (phaseShift c : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) := by + refine ⟨phaseShift_mem_unitaryGroup hc, 0, 0, ?_⟩ + rintro i j hij' + rcases eq_or_ne i j with rfl | hij + · induction i using Fin.cases with + | zero => rcases hij' with ⟨h, -⟩ | ⟨h, -⟩ <;> exact absurd rfl h + | succ i => simp + · rw [phaseShift_apply_of_ne c hij, Matrix.one_apply_ne hij] + +/-- **A unitary with cleared first column has a cleared first row too.** If `W` is unitary and its +first column is a multiple of `e₀` (`W i 0 = 0` for `i ≠ 0`), then `Wᴴ W = 1` forces +`conj (W 0 0) · W 0 j = (1) 0 j` for every `j`; taking `j = 0` gives `|W 0 0|² = 1`, and for `j ≠ 0` +the right side is `0` and `conj (W 0 0) ≠ 0`, so `W 0 j = 0`. -/ +theorem apply_zero_of_clearFirstColumn {W : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ} + (hW : W ∈ Matrix.unitaryGroup (Fin (d + 1)) ℂ) (hcol : ∀ i, i ≠ 0 → W i 0 = 0) : + Complex.normSq (W 0 0) = 1 ∧ ∀ j, j ≠ 0 → W 0 j = 0 := by + have h1 : Wᴴ * W = 1 := by + rw [← Matrix.star_eq_conjTranspose]; exact Matrix.mem_unitaryGroup_iff'.mp hW + -- the collapsed `(0, j)` entry of `Wᴴ W = 1` + have key : ∀ j, (starRingEnd ℂ) (W 0 0) * W 0 j = + (1 : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) 0 j := by + intro j + have hj := congrFun (congrFun h1 0) j + rw [Matrix.mul_apply, Finset.sum_eq_single_of_mem 0 (Finset.mem_univ 0) + (fun k _ hk => by rw [Matrix.conjTranspose_apply, hcol k hk, star_zero, zero_mul])] at hj + rwa [Matrix.conjTranspose_apply] at hj + have hnorm : Complex.normSq (W 0 0) = 1 := by + have h0 := key 0 + rw [Matrix.one_apply_eq, ← Complex.normSq_eq_conj_mul_self] at h0 + exact_mod_cast h0 + refine ⟨hnorm, fun j hj => ?_⟩ + have hne : (starRingEnd ℂ) (W 0 0) ≠ 0 := by + simp only [ne_eq, map_eq_zero] + intro h; rw [h] at hnorm; simp at hnorm + have hkj := key j + rw [Matrix.one_apply_ne (Ne.symm hj)] at hkj + exact (mul_eq_zero.mp hkj).resolve_left hne + +/-- **The block-diagonal peel (N&C eq. 4.51).** A `(d+1) × (d+1)` unitary `W` whose first column is +a multiple of `e₀` factors as `W = phaseShift c * blockOne C`, where the phase `c = W 0 0` has unit +modulus and the corner `C = W.submatrix Fin.succ Fin.succ` (the lower-right `d × d` block) is +unitary. Both factors are two-level-unitary building blocks: `phaseShift c` directly +(`isTwoLevelUnitary_phaseShift`), and `blockOne` sends a decomposition of `C` into two-level factors +back to two-level factors on the full space (`isTwoLevelUnitary_blockOne`). This is the step +of the §4.5.1 induction that peels off one dimension. -/ +theorem exists_phaseShift_mul_blockOne_of_clearFirstColumn + {W : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ} (hW : W ∈ Matrix.unitaryGroup (Fin (d + 1)) ℂ) + (hcol : ∀ i, i ≠ 0 → W i 0 = 0) : + ∃ (c : ℂ) (C : Matrix (Fin d) (Fin d) ℂ), + Complex.normSq c = 1 ∧ C ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + W = phaseShift c * blockOne C := by + obtain ⟨hnorm, hrow⟩ := apply_zero_of_clearFirstColumn hW hcol + set C : Matrix (Fin d) (Fin d) ℂ := W.submatrix Fin.succ Fin.succ with hC + have h1 : Wᴴ * W = 1 := by + rw [← Matrix.star_eq_conjTranspose]; exact Matrix.mem_unitaryGroup_iff'.mp hW + -- the corner `C` is unitary: `Cᴴ C = 1` from the `(i.succ, j.succ)` entries of `Wᴴ W = 1` + have hCunit : C ∈ Matrix.unitaryGroup (Fin d) ℂ := by + rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose] + ext i j + have hij := congrFun (congrFun h1 i.succ) j.succ + rw [Matrix.mul_apply, Fin.sum_univ_succ] at hij + have hz : Wᴴ i.succ 0 * W 0 j.succ = 0 := by + rw [Matrix.conjTranspose_apply, hrow i.succ (Fin.succ_ne_zero i), star_zero, zero_mul] + rw [hz, zero_add] at hij + have hsum : (∑ k : Fin d, Cᴴ i k * C k j) + = ∑ k : Fin d, Wᴴ i.succ k.succ * W k.succ j.succ := + Finset.sum_congr rfl fun k _ => by + simp only [hC, Matrix.conjTranspose_apply, Matrix.submatrix_apply] + rw [Matrix.mul_apply, hsum, hij] + simp [Matrix.one_apply, Fin.succ_inj] + refine ⟨W 0 0, C, hnorm, hCunit, ?_⟩ + ext i j + rw [phaseShift, Matrix.diagonal_mul] + induction i using Fin.cases with + | zero => + rw [Fin.cons_zero] + induction j using Fin.cases with + | zero => rw [blockOne_zero_zero, mul_one] + | succ j => rw [blockOne_zero_succ, mul_zero]; exact hrow j.succ (Fin.succ_ne_zero j) + | succ i => + rw [Fin.cons_succ, Pi.one_apply, one_mul] + induction j using Fin.cases with + | zero => rw [blockOne_succ_zero]; exact hcol i.succ (Fin.succ_ne_zero i) + | succ j => rw [blockOne_succ_succ, hC, Matrix.submatrix_apply] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/BlockOneEmbedding.lean b/LeanPool/AxQM/Concrete/BlockOneEmbedding.lean new file mode 100644 index 0000000000..69b7da5135 --- /dev/null +++ b/LeanPool/AxQM/Concrete/BlockOneEmbedding.lean @@ -0,0 +1,131 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QFTTwoLevel +public import Mathlib.Data.Matrix.Mul + +/-! +# Concrete: the `1 ⊕ M` block embedding fixing the first coordinate (N&C §4.5.1 block peel) + +The two-level decomposition of an arbitrary `d × d` unitary (Nielsen & Chuang §4.5.1, p. 189–191) +proceeds by an induction on the dimension. Column-clearing +(`AxQM.Concrete.exists_twoLevelUnitaryList_clear_first_column`) reduces a `(d+1) × (d+1)` +unitary `U`, after left-multiplication by two-level unitaries, to a matrix whose first row and +column are those of the identity — a **block-diagonal** matrix `1 ⊕ V'` with `V'` a `d × d` unitary +on the remaining coordinates `1, …, d` (N&C eq. (4.51): "repeat this procedure for the `d − 1` by +`d − 1` unitary submatrix in the lower right hand corner"). The inductive step then decomposes `V'`. + +This file provides the **embedding** underlying that peel, `blockOne`, independently of the peel and +induction themselves: `blockOne M` places a `d × d` matrix `M` into the lower-right +`{1, …, d}` block of a `(d+1) × (d+1)` matrix, fixing the first coordinate `0`. + +## The construction and its algebra + +`blockOne M` fixes coordinate `0` and acts as `M` on the tail (`i ↦ i.succ`): its `(0,0)` entry is +`1`, the rest of its first row and column are `0`, and `blockOne M i.succ j.succ = M i j`. Exactly +as for `twoLevelEmbed`, `blockOne` is a **`*`-homomorphism**: + +* `blockOne_one` — it sends `1 ↦ 1`; +* `blockOne_mul` — it is multiplicative, `blockOne A * blockOne B = blockOne (A * B)`; +* `blockOne_conjTranspose` — it commutes with `ᴴ`, `(blockOne M)ᴴ = blockOne Mᴴ`. + +Unitarity then needs no block manipulation: `(blockOne M)ᴴ * blockOne M = blockOne (Mᴴ * M) = +blockOne 1 = 1`, so `blockOne` sends a unitary to a unitary (`blockOne_mem_unitaryGroup`). A +two-level unitary maps to a two-level unitary (`isTwoLevelUnitary_blockOne`), its distinguished +block `{p, q}` shifted to `{p.succ, q.succ}` — this is what lets the inductive step re-assemble the +smaller decomposition into two-level factors on the full space. + +## Use + +This is a shared building block for the §4.5.1 development (Exercise 4.43's `n`-qubit lift). The +statement of Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **The `1 ⊕ M` block embedding.** `blockOne M` is the `(d+1) × (d+1)` matrix that fixes the first +coordinate `0` and acts as the `d × d` matrix `M` on the remaining coordinates `1, …, d` (identified +with `Fin d` via `Fin.succ`): its `(0,0)` entry is `1`, it agrees with the identity elsewhere in the +first row and column, and `blockOne M i.succ j.succ = M i j`. This is the block-diagonal form +`1 ⊕ V'` of the §4.5.1 two-level-decomposition induction. -/ +def blockOne (M : Matrix (Fin d) (Fin d) ℂ) : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ := + Matrix.of (Fin.cons (Fin.cons 1 0) fun i => Fin.cons 0 (M i)) + +@[simp] theorem blockOne_zero_zero (M : Matrix (Fin d) (Fin d) ℂ) : blockOne M 0 0 = 1 := rfl + +@[simp] theorem blockOne_zero_succ (M : Matrix (Fin d) (Fin d) ℂ) (j : Fin d) : + blockOne M 0 j.succ = 0 := rfl + +@[simp] theorem blockOne_succ_zero (M : Matrix (Fin d) (Fin d) ℂ) (i : Fin d) : + blockOne M i.succ 0 = 0 := rfl + +@[simp] theorem blockOne_succ_succ (M : Matrix (Fin d) (Fin d) ℂ) (i j : Fin d) : + blockOne M i.succ j.succ = M i j := rfl + +/-- The embedding of the `d × d` identity is the `(d+1) × (d+1)` identity. -/ +theorem blockOne_one : blockOne (1 : Matrix (Fin d) (Fin d) ℂ) = 1 := by + ext i j + induction i using Fin.cases <;> induction j using Fin.cases <;> + simp [Matrix.one_apply, Fin.succ_ne_zero, eq_comm, Fin.succ_inj] + +/-- **`blockOne` is multiplicative**: embedding respects matrix products, +`blockOne A * blockOne B = blockOne (A * B)`. The structural core making an embedded unitary +unitary. -/ +theorem blockOne_mul (A B : Matrix (Fin d) (Fin d) ℂ) : + blockOne A * blockOne B = blockOne (A * B) := by + ext i j + rw [Matrix.mul_apply, Fin.sum_univ_succ] + induction i using Fin.cases <;> induction j using Fin.cases <;> + simp [Matrix.mul_apply] + +/-- **`blockOne` commutes with the conjugate transpose**: `(blockOne M)ᴴ = blockOne Mᴴ`. The block +`ᴴ` is `M`'s; the fixed coordinate and the zeros are real. -/ +theorem blockOne_conjTranspose (M : Matrix (Fin d) (Fin d) ℂ) : + (blockOne M)ᴴ = blockOne Mᴴ := by + ext i j + induction i using Fin.cases <;> induction j using Fin.cases <;> + simp [Matrix.conjTranspose_apply] + +/-- **`blockOne` sends unitaries to unitaries.** From the `*`-homomorphism laws: +`(blockOne M)ᴴ · blockOne M = blockOne (Mᴴ · M) = blockOne 1 = 1`. -/ +theorem blockOne_mem_unitaryGroup {M : Matrix (Fin d) (Fin d) ℂ} + (hM : M ∈ Matrix.unitaryGroup (Fin d) ℂ) : + blockOne M ∈ Matrix.unitaryGroup (Fin (d + 1)) ℂ := by + rw [Matrix.mem_unitaryGroup_iff'] at hM ⊢ + rw [Matrix.star_eq_conjTranspose] at hM ⊢ + rw [blockOne_conjTranspose, blockOne_mul, hM, blockOne_one] + +/-- **`blockOne` sends two-level unitaries to two-level unitaries**, with the distinguished block +`{p, q}` shifted to `{p.succ, q.succ}`. This is what lets the §4.5.1 inductive step re-assemble the +`d`-dimensional decomposition into two-level factors on the `(d+1)`-dimensional space. -/ +theorem isTwoLevelUnitary_blockOne {M : Matrix (Fin d) (Fin d) ℂ} + (hM : IsTwoLevelUnitary M) : IsTwoLevelUnitary (blockOne M) := by + obtain ⟨hunit, p, q, hpq⟩ := hM + refine ⟨blockOne_mem_unitaryGroup hunit, p.succ, q.succ, ?_⟩ + intro i j hij + induction i using Fin.cases with + | zero => + induction j using Fin.cases with + | zero => simp + | succ j => simp [(Fin.succ_ne_zero j).symm] + | succ i => + induction j using Fin.cases with + | zero => simp [Fin.succ_ne_zero i] + | succ j => + rw [blockOne_succ_succ, hpq i j (by simpa only [ne_eq, Fin.succ_inj] using hij)] + simp [Matrix.one_apply, Fin.succ_inj] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/CheckMatrix.lean b/LeanPool/AxQM/Concrete/CheckMatrix.lean new file mode 100644 index 0000000000..b1df7c4b9a --- /dev/null +++ b/LeanPool/AxQM/Concrete/CheckMatrix.lean @@ -0,0 +1,193 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCommutation +public import Mathlib.Data.ZMod.Basic + +/-! +# Concrete: the check-matrix row of a Pauli string is an additive homomorphism + +This file formalizes the algebraic core of +Nielsen & Chuang's **check-matrix representation** of the Pauli group (N&C §10.5.1, the paragraph +preceding eq. (10.83) and the proof of Proposition 10.3). The check matrix records, for a Pauli +operator `g`, its `2n`-bit **row** `r(g) = (x_g | z_g)` — a `1` in the `k`-th `X`-slot when `g` has +an `X` (or `Y`) on qubit `k`, a `1` in the `k`-th `Z`-slot when `g` has a `Z` (or `Y`). The central +fact N&C uses is that this row map is a **homomorphism modulo phase**: + + `r(g) + r(g′) = r(g g′)` (the row of a product is the sum of the rows), + +together with its **trivial kernel** — a Pauli string is the identity exactly when its row vanishes. +These are exactly the two ingredients of the Proposition 10.3 proof ("independent generators iff the +check-matrix rows are linearly independent"); they are also shared infrastructure for Propositions +10.4 and 10.5. + +## The Pauli-index product and its phase + +Two single-qubit Pauli matrices multiply to a third **up to a phase** `±1, ±i`: `σ_a σ_b = ζ(a,b) +σ_{a⊙b}`. The **product index** `a ⊙ b` (`pauliMul`) is the bitwise XOR of the `(x, z)` bit +representations (`I = (0,0)`, `X = (1,0)`, `Y = (1,1)`, `Z = (0,1)`), and `ζ(a,b)` (`pauliMulPhase`) +is the fourth-root-of-unity phase. Lifting factor-by-factor over the `n`-fold tensor product +(`kronFamily`) gives the `n`-qubit product law `P_g P_h = (∏_k ζ(g_k, h_k)) · P_{g ⊙ h}` +(`pauliString_mul_eq_smul`), so the product of two Pauli strings is again a phase times a Pauli +string — the closure fact behind the Pauli group. + +## What is proved + +* `pauliMul` / `pauliMulPhase` — the Pauli-index product table and its phase table. +* `pauli_mul_eq_smul_pauliMul` — the single-qubit product law `σ_a σ_b = ζ(a,b) σ_{a⊙b}` (a finite + `4 × 4` case check). +* `pauliMulIndex` / `pauliString_mul_eq_smul` — the `n`-qubit product law `P_g P_h = + (∏_k ζ(g_k, h_k)) · P_{g ⊙ h}`, obtained factor-by-factor via `kronFamily_mul` and + `kronFamily_smul_family`. +* `pauliBit` / `checkRow` — the single-qubit `(x, z)` bit pair and the `n`-qubit check-matrix row + `r(g) = (x_g | z_g) : (Fin n → ZMod 2) × (Fin n → ZMod 2)`. +* `checkRow_pauliMulIndex` — **the homomorphism law** `r(g ⊙ h) = r(g) + r(h)` (mod 2); since + `P_g P_h` is a phase times `P_{g ⊙ h}`, this is N&C's `r(g g′) = r(g) + r(g′)`. +* `checkRow_eq_zero_iff` — **the trivial kernel** `r(g) = 0 ↔ g = 0` (all-identity string). + +The general facts `pauliString_injective` (distinct indices give distinct operators) and +`pauliString_eq_one_iff` (`P_g = I ↔ g = 0`), which the trivial kernel combines with to give +`P_g = I ↔ r(g) = 0`, live with the `pauliString` family in `Concrete/PauliString.lean`. + +## Design notes + +* The check row is valued in `(Fin n → ZMod 2) × (Fin n → ZMod 2)` (the `X`-part and `Z`-part), an + `F₂`-vector space, so "the rows are linearly independent" (Proposition 10.3) is + `LinearIndependent (ZMod 2)` of the family of rows. The single-qubit bit pair `pauliBit` reuses + the natural-number bits `pauliXBit`, `pauliZBit` (`Concrete/PauliStringCommutation.lean`) reduced + mod 2 — one source of truth for the `(x | z)` convention. Since `pauliMul` is exactly their XOR, + the homomorphism law `pauliBit (pauliMul a b) = pauliBit a + pauliBit b` is a `16`-case `decide`. +* The phase `pauliMulPhase` is recorded explicitly (a fourth root of unity) even though Proposition + 10.3 only needs it to be a nonzero scalar; the exact table is what makes `P_g P_h` land back in + the Pauli group and is reused by the Pauli-group closure development. +-/ + +@[expose] public section + +open Matrix Complex + +open scoped BigOperators + +namespace AxQM.Concrete + +/-! ### The single-qubit Pauli-index product and its phase -/ + +/-- The **Pauli-index product** `a ⊙ b`: the index of the Pauli matrix `σ_a σ_b` up to phase. It is +the bitwise XOR of the `(x, z)` bit representations `I = (0,0)`, `X = (1,0)`, `Y = (1,1)`, +`Z = (0,1)` (e.g. `X ⊙ Y = Z`, `Y ⊙ Z = X`). -/ +def pauliMul : Fin 4 → Fin 4 → Fin 4 := + ![![0, 1, 2, 3], ![1, 0, 3, 2], ![2, 3, 0, 1], ![3, 2, 1, 0]] + +/-- The **phase** `ζ(a, b)` in the single-qubit product `σ_a σ_b = ζ(a,b) σ_{a⊙b}`, a fourth root of +unity: `1` when the two Paulis commute in the naive sense (equal, or one is `I`), `±i` otherwise +(e.g. `X Y = i Z`, `Y X = -i Z`). -/ +def pauliMulPhase : Fin 4 → Fin 4 → ℂ := + ![![1, 1, 1, 1], ![1, 1, I, -I], ![1, -I, 1, I], ![1, I, -I, 1]] + +/-- **Single-qubit Pauli product law**: `σ_a σ_b = ζ(a,b) · σ_{a⊙b}`. Two single-qubit Paulis +multiply to a third up to a fourth-root-of-unity phase; the product index is `pauliMul` and the +phase is `pauliMulPhase`. Proved by the finite `4 × 4` case check on `a, b`. -/ +theorem pauli_mul_eq_smul_pauliMul (a b : Fin 4) : + pauli a * pauli b = pauliMulPhase a b • pauli (pauliMul a b) := by + fin_cases a <;> fin_cases b <;> + (ext i j; fin_cases i <;> fin_cases j <;> + simp [pauliMul, pauliMulPhase, pauli, pauliX, pauliY, pauliZ, Matrix.mul_apply, + Fin.sum_univ_two]) + +/-! ### The `n`-qubit Pauli-string product law -/ + +variable {n : ℕ} + +/-- The **`n`-qubit product index** `g ⊙ h`, the componentwise Pauli-index product `k ↦ (g k) ⊙ +(h k)`. It is the index of the Pauli string `P_g P_h` up to phase (`pauliString_mul_eq_smul`). -/ +def pauliMulIndex (g h : Fin n → Fin 4) : Fin n → Fin 4 := fun k => pauliMul (g k) (h k) + +/-- **The `n`-qubit Pauli-string product law**: `P_g P_h = (∏_k ζ(g_k, h_k)) · P_{g ⊙ h}`. The +product of two Pauli strings is a phase times the Pauli string of the product index. Obtained +factor-by-factor from the single-qubit law (`pauli_mul_eq_smul_pauliMul`) via the tensor +mixed-product property (`kronFamily_mul`) and the per-qubit scalar pull-out +(`kronFamily_smul_family`): each qubit contributes its phase `ζ(g_k, h_k)`, and the phases multiply +to `∏_k ζ(g_k, h_k)`. This is the closure fact behind the Pauli group. -/ +theorem pauliString_mul_eq_smul (g h : Fin n → Fin 4) : + pauliString g * pauliString h = + (∏ k, pauliMulPhase (g k) (h k)) • pauliString (pauliMulIndex g h) := by + rw [pauliString_eq_kronFamily g, pauliString_eq_kronFamily h, kronFamily_mul] + simp only [pauli_mul_eq_smul_pauliMul] + rw [kronFamily_smul_family, pauliString_eq_kronFamily] + rfl + +/-- **Pauli-string product with a trivial phase**: if the combined index is `k` and the total phase +`∏_i ζ(g_i, h_i)` is `1`, then `P_g P_h = P_k`. The common specialisation of +`pauliString_mul_eq_smul` for a product of Pauli strings with no `Y`-recombination phase — it turns +a concrete Pauli-string product into a `by decide` (index) plus `by simp` (phase) obligation. -/ +theorem pauliString_mul_of {g h k : Fin n → Fin 4} (hidx : pauliMulIndex g h = k) + (hph : (∏ i, pauliMulPhase (g i) (h i)) = 1) : + pauliString g * pauliString h = pauliString k := by + rw [pauliString_mul_eq_smul, hph, one_smul, hidx] + +/-! ### The check-matrix row and its homomorphism law -/ + +/-- The **single-qubit check bits** `(x_a, z_a)` of a Pauli index: `I = (0,0)`, `X = (1,0)`, +`Y = (1,1)`, `Z = (0,1)`. This is the `(x | z)` symplectic representation over `ZMod 2`; it reuses +the single source of truth for the bit assignment, the natural-number bits `pauliXBit`, `pauliZBit` +of `Concrete/PauliStringCommutation.lean` (`x`-bit `1` for the Paulis containing an `X` factor +`X`, `Y`; `z`-bit `1` for those containing a `Z` factor `Y`, `Z`), reduced mod 2. -/ +def pauliBit : Fin 4 → ZMod 2 × ZMod 2 := fun a => ((pauliXBit a : ZMod 2), (pauliZBit a : ZMod 2)) + +/-- The check bits vanish exactly for the identity Pauli: `pauliBit a = 0 ↔ a = 0`. Only `σ₀ = I` +has both `x`- and `z`-bit `0`. -/ +theorem pauliBit_eq_zero_iff (a : Fin 4) : pauliBit a = 0 ↔ a = 0 := by + fin_cases a <;> decide + +/-- The check bits are **additive under the Pauli-index product**: `pauliBit (a ⊙ b) = pauliBit a + +pauliBit b` (mod 2). This is the single-qubit homomorphism law; it holds because `pauliMul` is the +XOR of the bit representations. A finite `4 × 4` case check. -/ +theorem pauliBit_pauliMul (a b : Fin 4) : pauliBit (pauliMul a b) = pauliBit a + pauliBit b := by + fin_cases a <;> fin_cases b <;> decide + +/-- The **`n`-qubit check-matrix row** `r(g) = (x_g | z_g)` of a Pauli string, its `X`-part and +`Z`-part over `ZMod 2`: `x_g k`, `z_g k` are the check bits of the `k`-th single-qubit Pauli `g k`. +This is the `2n`-bit row that Nielsen & Chuang assigns to a stabilizer generator; the family of rows +of a generating set is the check matrix. -/ +def checkRow (g : Fin n → Fin 4) : (Fin n → ZMod 2) × (Fin n → ZMod 2) := + (fun k => (pauliBit (g k)).1, fun k => (pauliBit (g k)).2) + +/-- **The check-matrix homomorphism law** (Nielsen & Chuang §10.5.1): `r(g ⊙ h) = r(g) + r(h)` +(mod 2). Since `P_g P_h = (phase) · P_{g ⊙ h}` (`pauliString_mul_eq_smul`), this is N&C's +`r(g g′) = r(g) + r(g′)` — "addition in the row representation corresponds to multiplication of +group elements". Componentwise it is the single-qubit additivity `pauliBit_pauliMul`. -/ +theorem checkRow_pauliMulIndex (g h : Fin n → Fin 4) : + checkRow (pauliMulIndex g h) = checkRow g + checkRow h := by + ext k <;> + simp only [checkRow, pauliMulIndex, Prod.fst_add, Prod.snd_add, Pi.add_apply, pauliBit_pauliMul] + +/-- **The check row has trivial kernel**: `r(g) = 0 ↔ g = 0`, i.e. a Pauli string's row vanishes +exactly when it is the all-identity string. Componentwise, both check bits vanish iff each +single-qubit Pauli is `I` (`pauliBit_eq_zero_iff`). -/ +theorem checkRow_eq_zero_iff (g : Fin n → Fin 4) : checkRow g = 0 ↔ g = 0 := by + simp [checkRow, Prod.ext_iff, funext_iff, ← pauliBit_eq_zero_iff, forall_and] + +/-- The single-qubit check bits **determine the Pauli**: `pauliBit` is injective. Each of the four +Pauli indices `I, X, Y, Z` has a distinct `(x, z)` bit pattern (`(0,0), (1,0), (1,1), (0,1)`), a +finite `4 × 4` check. This is the injectivity that makes the whole check row `r(g)` determine the +Pauli string `g` (`checkRow_injective`). -/ +theorem pauliBit_injective : Function.Injective pauliBit := by decide + +/-- **The check row determines the Pauli string**: `checkRow` is injective. Two Pauli strings with +the same `(x | z)` row are equal, since at each qubit the single-qubit check bits determine the +Pauli (`pauliBit_injective`). This is the faithfulness of the symplectic representation on strings +(ignoring the overall phase). -/ +theorem checkRow_injective : Function.Injective (checkRow (n := n)) := by + intro g h hgh + funext k + exact pauliBit_injective (Prod.ext (congrFun (congrArg Prod.fst hgh) k) + (congrFun (congrArg Prod.snd hgh) k)) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ClassicalTraceDistance.lean b/LeanPool/AxQM/Concrete/ClassicalTraceDistance.lean new file mode 100644 index 0000000000..1cd1c833fd --- /dev/null +++ b/LeanPool/AxQM/Concrete/ClassicalTraceDistance.lean @@ -0,0 +1,253 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Data.Fin.VecNotation +public import Mathlib.Tactic + +/-! +# Classical trace distance between probability distributions (Nielsen & Chuang §9.1) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, §9.1 (p. 400) +introduce the **trace distance** (a.k.a. the `L¹` or Kolmogorov distance) +between two probability distributions `{pₓ}` and `{qₓ}` over a common finite +index set, N&C equation `(9.1)`: +``` +D(pₓ, qₓ) ≡ ½ ∑ₓ |pₓ − qₓ|. +``` +It is the classical quantity that the quantum trace +distance `½ tr|ρ − σ|` (N&C `(9.11)`) generalizes, and it is reused by several +Chapter 9 items (Exercises 9.1, 9.2, 9.4). + +A distribution is modelled by a real-valued family `p : ι → ℝ` on a `Fintype ι`; +the definition and its basic properties do not need the normalization `∑ₓ pₓ = 1`, +so we do not impose it here (the concrete instances of interest are, of course, +normalized). + +## Main definitions + +* `classicalTraceDist` — the trace distance `½ ∑ₓ |pₓ − qₓ|` of `(9.1)`. + +## Main statements + +* `classicalTraceDist_self`, `classicalTraceDist_comm`, `classicalTraceDist_nonneg` + — the basic "distance" properties N&C invoke in justifying the term *distance* + (`D(x, x) = 0`, symmetry `D(x, y) = D(y, x)`, and nonnegativity). +* `classicalTraceDist_deterministic_uniform` — **Exercise 9.1, part 1**: the + trace distance between the deterministic distribution `(1, 0)` and the uniform + distribution `(1/2, 1/2)` is `1/2`. +* `classicalTraceDist_ternary_example` — **Exercise 9.1, part 2**: the trace + distance between `(1/2, 1/3, 1/6)` and `(3/4, 1/8, 1/8)` is `1/4`. +* `classicalTraceDist_binary` — **Exercise 9.2**: the trace distance between the + two-outcome distributions `(p, 1 − p)` and `(q, 1 − q)` is `|p − q|`, for + arbitrary real parameters `p` and `q`. +* `classicalTraceDist_eq_sum_posPart` — for equal-total-mass `p, q`, the trace + distance equals `∑ₓ (pₓ − qₓ)⁺` (the algebraic core of Exercise 9.4). +* `sum_sub_sum_le_classicalTraceDist`, `abs_sum_sub_sum_le_classicalTraceDist`, + `exists_finset_sum_sub_eq_classicalTraceDist` — the one-sided / two-sided bound + and the attainment that assemble Exercise 9.4. +* `classicalTraceDist_isGreatest` (and its probability-distribution corollary + `classicalTraceDist_isGreatest_of_sum_eq_one`) — **Exercise 9.4**, N&C `(9.3)`: + `D(p, q) = max_S |p(S) − q(S)|`, the maximum over all events `S` of the gap in + the probability assigned to `S`. +* `classicalTraceDist_isGreatest_sub` (and its probability-distribution corollary + `classicalTraceDist_isGreatest_sub_of_sum_eq_one`) — **Exercise 9.5**, N&C + `(9.4)`: the absolute value signs may be removed, `D(p, q) = max_S (p(S) − q(S))`, + because the optimal event `S⁺ = {x | pₓ ≥ qₓ}` already makes the gap nonnegative. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open scoped BigOperators + +/-- The **classical trace distance** between two probability distributions +`p, q : ι → ℝ` over a finite index set, Nielsen & Chuang `(9.1)`: +`D(pₓ, qₓ) ≡ ½ ∑ₓ |pₓ − qₓ|`. Also known as the `L¹` or Kolmogorov distance. -/ +noncomputable def classicalTraceDist {ι : Type*} [Fintype ι] (p q : ι → ℝ) : ℝ := + (∑ x, |p x - q x|) / 2 + +/-- The classical trace distance of a distribution from itself is `0` +(N&C: a metric satisfies `D(x, x) = 0`). -/ +theorem classicalTraceDist_self {ι : Type*} [Fintype ι] (p : ι → ℝ) : + classicalTraceDist p p = 0 := by + simp [classicalTraceDist] + +/-- The classical trace distance is symmetric, `D(p, q) = D(q, p)` +(N&C: a metric must be symmetric). -/ +theorem classicalTraceDist_comm {ι : Type*} [Fintype ι] (p q : ι → ℝ) : + classicalTraceDist p q = classicalTraceDist q p := by + simp only [classicalTraceDist, abs_sub_comm] + +/-- The classical trace distance is nonnegative, `0 ≤ D(p, q)`. -/ +theorem classicalTraceDist_nonneg {ι : Type*} [Fintype ι] (p q : ι → ℝ) : + 0 ≤ classicalTraceDist p q := + div_nonneg (Finset.sum_nonneg fun _ _ => abs_nonneg _) (by norm_num) + +/-- **Nielsen & Chuang, Exercise 9.1 (part 1).** The trace distance between the +deterministic distribution `(1, 0)` and the uniform distribution `(1/2, 1/2)` is +`1/2`: `½(|1 − 1/2| + |0 − 1/2|) = ½(1/2 + 1/2) = 1/2`. -/ +theorem classicalTraceDist_deterministic_uniform : + classicalTraceDist ![1, 0] ![1 / 2, 1 / 2] = 1 / 2 := by + simp [classicalTraceDist, Fin.sum_univ_two] + norm_num + +/-- **Nielsen & Chuang, Exercise 9.1 (part 2).** The trace distance between +`(1/2, 1/3, 1/6)` and `(3/4, 1/8, 1/8)` is `1/4`: +`½(|1/2 − 3/4| + |1/3 − 1/8| + |1/6 − 1/8|) = ½(1/4 + 5/24 + 1/24) = ½·(1/2) = 1/4`. -/ +theorem classicalTraceDist_ternary_example : + classicalTraceDist ![1 / 2, 1 / 3, 1 / 6] ![3 / 4, 1 / 8, 1 / 8] = 1 / 4 := by + simp [classicalTraceDist, Fin.sum_univ_three] + norm_num + +/-- **Nielsen & Chuang, Exercise 9.2.** The trace distance between the two-outcome +distributions `(p, 1 − p)` and `(q, 1 − q)` is `|p − q|`, for arbitrary real +parameters `p q : ℝ`. The second summand collapses onto the first because the two +outcomes' deviations are equal and opposite: +`½(|p − q| + |(1 − p) − (1 − q)|) = ½(|p − q| + |q − p|) = ½(2|p − q|) = |p − q|`. -/ +theorem classicalTraceDist_binary (p q : ℝ) : + classicalTraceDist ![p, 1 - p] ![q, 1 - q] = |p - q| := by + have h : (1 - p) - (1 - q) = -(p - q) := by ring + simp only [classicalTraceDist, Fin.sum_univ_two, Matrix.cons_val_zero, + Matrix.cons_val_one, h, abs_neg] + ring + +/-- **Positive-part form of the trace distance** (the algebraic core of +Exercise 9.4). When `p` and `q` have equal total mass — in particular when both +are probability distributions, `∑ₓ pₓ = ∑ₓ qₓ = 1` — the trace distance equals +the sum of the positive parts of the pointwise differences: +`D(p, q) = ½ ∑ₓ |pₓ − qₓ| = ∑ₓ (pₓ − qₓ)⁺`. +Since the differences sum to zero, the positive and negative parts have equal +total, so each is half of `∑ₓ |pₓ − qₓ|`. -/ +theorem classicalTraceDist_eq_sum_posPart {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) : + classicalTraceDist p q = ∑ x, (p x - q x)⁺ := by + have hsum : ∑ x, (p x - q x) = 0 := by rw [Finset.sum_sub_distrib, h, sub_self] + have e1 : ∑ x, |p x - q x| = (∑ x, (p x - q x)⁺) + ∑ x, (p x - q x)⁻ := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun x _ => by rw [add_comm]; exact (negPart_add_posPart _).symm + have e2 : (0 : ℝ) = (∑ x, (p x - q x)⁺) - ∑ x, (p x - q x)⁻ := by + rw [← Finset.sum_sub_distrib, ← hsum] + exact Finset.sum_congr rfl fun x _ => (posPart_sub_negPart _).symm + have key : ∑ x, (p x - q x)⁺ = ∑ x, (p x - q x)⁻ := by linarith + unfold classicalTraceDist + rw [e1, key]; ring + +/-- **One-sided distinguishability bound** (Exercise 9.4). For any event +`S ⊆ {x}` and distributions of equal total mass, the excess probability that `S` +receives under `p` over `q`, `p(S) − q(S) = ∑_{x∈S} pₓ − ∑_{x∈S} qₓ`, is at most +the trace distance `D(p, q)`. The bound is saturated by the event where `p ≥ q`; +see `exists_finset_sum_sub_eq_classicalTraceDist`. -/ +theorem sum_sub_sum_le_classicalTraceDist {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) (S : Finset ι) : + (∑ x ∈ S, p x) - (∑ x ∈ S, q x) ≤ classicalTraceDist p q := by + rw [classicalTraceDist_eq_sum_posPart h, ← Finset.sum_sub_distrib] + calc ∑ x ∈ S, (p x - q x) ≤ ∑ x ∈ S, (p x - q x)⁺ := + Finset.sum_le_sum fun x _ => le_posPart _ + _ ≤ ∑ x, (p x - q x)⁺ := Finset.sum_le_univ_sum_of_nonneg fun x => posPart_nonneg _ + +/-- **Two-sided distinguishability bound** (Exercise 9.4). For any event +`S ⊆ {x}`, the absolute gap `|p(S) − q(S)|` between the probabilities `S` +receives under `p` and `q` is at most the trace distance `D(p, q)`. The lower +direction follows from the one-sided bound applied to the swapped pair, using +symmetry of the trace distance (`classicalTraceDist_comm`). -/ +theorem abs_sum_sub_sum_le_classicalTraceDist {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) (S : Finset ι) : + |(∑ x ∈ S, p x) - (∑ x ∈ S, q x)| ≤ classicalTraceDist p q := by + rw [abs_le] + refine ⟨?_, sum_sub_sum_le_classicalTraceDist h S⟩ + have hswap := sum_sub_sum_le_classicalTraceDist h.symm S + rw [classicalTraceDist_comm q p] at hswap + linarith + +/-- **Attainment of the trace distance by an optimal event** (Exercise 9.4). For +distributions of equal total mass there is a subset `S` — the set of indices +where `p ≥ q` — whose signed probability excess equals the trace distance +exactly, `p(S) − q(S) = D(p, q)`. Combined with the two-sided bound this exhibits +`D(p, q)` as the maximum of `|p(S) − q(S)|`. (This absolute-value-free attainment +is also the content of Exercise 9.5.) -/ +theorem exists_finset_sum_sub_eq_classicalTraceDist {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) : + ∃ S : Finset ι, (∑ x ∈ S, p x) - (∑ x ∈ S, q x) = classicalTraceDist p q := by + classical + refine ⟨Finset.univ.filter fun x => q x ≤ p x, ?_⟩ + rw [classicalTraceDist_eq_sum_posPart h, ← Finset.sum_sub_distrib, + ← Finset.sum_filter_add_sum_filter_not Finset.univ (fun x => q x ≤ p x) + fun x => (p x - q x)⁺] + have hpos : ∑ x ∈ Finset.univ.filter (fun x => q x ≤ p x), (p x - q x) = + ∑ x ∈ Finset.univ.filter (fun x => q x ≤ p x), (p x - q x)⁺ := + Finset.sum_congr rfl fun x hx => by + simp only [Finset.mem_filter] at hx; rw [posPart_eq_self.2 (by linarith [hx.2])] + have hneg : ∑ x ∈ Finset.univ.filter (fun x => ¬ q x ≤ p x), (p x - q x)⁺ = 0 := + Finset.sum_eq_zero fun x hx => by + simp only [Finset.mem_filter, not_le] at hx; rw [posPart_eq_zero.2 (by linarith [hx.2])] + rw [hpos, hneg, add_zero] + +/-- **Nielsen & Chuang, Exercise 9.4** — equation `(9.3)`. For two distributions +`p, q : ι → ℝ` of equal total mass (probability distributions in particular), the +trace distance is the greatest value of `|p(S) − q(S)|` over all events +`S ⊆ {x}`: +`D(p, q) = max_S |p(S) − q(S)| = max_S |∑_{x∈S} pₓ − ∑_{x∈S} qₓ|`. +The event `S` is the optimal test for distinguishing `p` from `q`, with the trace +distance governing how well the distinction can be made. `IsGreatest` packages +both halves of `(9.3)`: `D(p, q)` is attained (by the event where `p ≥ q`) and is +an upper bound over all events. -/ +theorem classicalTraceDist_isGreatest {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) : + IsGreatest (Set.range fun S : Finset ι => |(∑ x ∈ S, p x) - (∑ x ∈ S, q x)|) + (classicalTraceDist p q) := by + refine ⟨?_, ?_⟩ + · obtain ⟨S, hS⟩ := exists_finset_sum_sub_eq_classicalTraceDist h + exact ⟨S, by simp only [hS, abs_of_nonneg (classicalTraceDist_nonneg p q)]⟩ + · rintro _ ⟨S, rfl⟩ + exact abs_sum_sub_sum_le_classicalTraceDist h S + +/-- **Nielsen & Chuang, Exercise 9.4** for probability distributions. Specializing +`classicalTraceDist_isGreatest` to genuine probability distributions `p, q` (each +summing to `1`), the trace distance is the maximum over events `S` of the gap +`|p(S) − q(S)|` in the probability assigned to `S`, N&C `(9.3)`. -/ +theorem classicalTraceDist_isGreatest_of_sum_eq_one {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (hp : ∑ x, p x = 1) (hq : ∑ x, q x = 1) : + IsGreatest (Set.range fun S : Finset ι => |(∑ x ∈ S, p x) - (∑ x ∈ S, q x)|) + (classicalTraceDist p q) := + classicalTraceDist_isGreatest (hp.trans hq.symm) + +/-- **Nielsen & Chuang, Exercise 9.5** — equation `(9.4)`. The absolute value +signs may be removed from `(9.3)`: for two distributions `p, q : ι → ℝ` of equal +total mass, the trace distance is the greatest value of the *signed* gap +`p(S) − q(S)` over all events `S ⊆ {x}`: +`D(p, q) = max_S (p(S) − q(S)) = max_S (∑_{x∈S} pₓ − ∑_{x∈S} qₓ)`. +Removing the absolute value cannot lower the maximum (the signed gap is bounded +above by `|p(S) − q(S)| ≤ D(p, q)`), and the bound is still attained — by the very +same optimal event `S⁺ = {x | pₓ ≥ qₓ}`, whose signed gap is already the +nonnegative value `D(p, q)` (`exists_finset_sum_sub_eq_classicalTraceDist`). So +the two maxima coincide. `IsGreatest` packages both halves: `D(p, q)` is attained +and is an upper bound, now over the signed gaps rather than their absolute +values. -/ +theorem classicalTraceDist_isGreatest_sub {ι : Type*} [Fintype ι] {p q : ι → ℝ} + (h : ∑ x, p x = ∑ x, q x) : + IsGreatest (Set.range fun S : Finset ι => (∑ x ∈ S, p x) - (∑ x ∈ S, q x)) + (classicalTraceDist p q) := by + refine ⟨exists_finset_sum_sub_eq_classicalTraceDist h, ?_⟩ + rintro _ ⟨S, rfl⟩ + exact sum_sub_sum_le_classicalTraceDist h S + +/-- **Nielsen & Chuang, Exercise 9.5** for probability distributions. Specializing +`classicalTraceDist_isGreatest_sub` to genuine probability distributions `p, q` +(each summing to `1`), the trace distance is the maximum over events `S` of the +signed gap `p(S) − q(S)` in the probability assigned to `S`, N&C `(9.4)`. -/ +theorem classicalTraceDist_isGreatest_sub_of_sum_eq_one {ι : Type*} [Fintype ι] + {p q : ι → ℝ} (hp : ∑ x, p x = 1) (hq : ∑ x, q x = 1) : + IsGreatest (Set.range fun S : Finset ι => (∑ x ∈ S, p x) - (∑ x ∈ S, q x)) + (classicalTraceDist p q) := + classicalTraceDist_isGreatest_sub (hp.trans hq.symm) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/CliffordCircuitInverse.lean b/LeanPool/AxQM/Concrete/CliffordCircuitInverse.lean new file mode 100644 index 0000000000..9eea2795fb --- /dev/null +++ b/LeanPool/AxQM/Concrete/CliffordCircuitInverse.lean @@ -0,0 +1,152 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit + +/-! +# Concrete: the Clifford-circuit inverse + +This file continues the formalisation of Nielsen & Chuang **Theorem 10.6** (the converse — the +normalizer `N(Gₙ)` is generated by Hadamard/phase/CNOT gates, Exercise 10.40) by supplying the +inverse of a Clifford circuit that the multi-qubit inductive synthesis needs. + +The induction of Figure 10.9 reduces an `(n+1)`-qubit normalizer `U` by left-composing it with a +Clifford circuit `B` (`M := B.toMatrix * U` fixes the first-wire generators), recurses on the last +`n` wires to obtain a Clifford circuit `B'`, and must then re-assemble `U` itself. Since +`M = phase • B'.toMatrix`, we get `U = B.toMatrixᴴ • (phase • B'.toMatrix)`, so to express `U` as a +*global phase times a Clifford circuit* we need `B.toMatrixᴴ` realised as the matrix of an actual +Clifford circuit. That is exactly what this file provides. + +## The construction + +Every elementary Clifford gate is invertible by a *word in the same gate set*: + +* `H⁻¹ = H` and `CNOT⁻¹ = CNOT` (both are Hermitian involutions), and +* `S⁻¹ = S³` (the phase gate has order `4`, so `Sᴴ = S⁻¹ = S³`). + +`CliffordGate.invList γ` records this word (`[H]`, `[CNOT]`, or `[S, S, S]`), with the defining +property `(invList γ).toMatrix = γ.toMatrixᴴ` (`toMatrix_invList`). Reversing the gate list of a +circuit and replacing each gate by its inverse word gives `CliffordCircuit.inverse`, whose matrix is +the conjugate transpose of the original (`toMatrix_inverse`): `(inverse C).toMatrix = C.toMatrixᴴ`. +Because a Clifford circuit is unitary, `inverse` is a genuine two-sided inverse +(`toMatrix_mul_inverse`, `toMatrix_inverse_mul`). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {n : ℕ} + +/-! ### Two general facts about single-wire gates -/ + +/-- **`kronWireGate` is multiplicative on a fixed wire**: placing `G · H` on wire `j` is the same as +placing `G` and then `H` there. From the factor-by-factor product law `kronFamily_mul`, since the +per-wire families agree everywhere (`1 · 1 = 1` off wire `j`, `G · H` on it). -/ +theorem kronWireGate_mul (j : Fin n) (G H : Matrix (Fin 2) (Fin 2) ℂ) : + kronWireGate j G * kronWireGate j H = kronWireGate j (G * H) := by + unfold kronWireGate + rw [kronFamily_mul] + congr 1 + funext k + by_cases hk : k = j + · subst hk; simp + · simp [Function.update_of_ne hk] + +/-- **The conjugate transpose passes through `kronWireGate`**: `(kronWireGate j G)ᴴ = +kronWireGate j Gᴴ`. From the entrywise `kronFamily_conjTranspose`, since `1ᴴ = 1` off wire `j`. -/ +theorem kronWireGate_conjTranspose (j : Fin n) (G : Matrix (Fin 2) (Fin 2) ℂ) : + (kronWireGate j G)ᴴ = kronWireGate j Gᴴ := by + unfold kronWireGate + rw [kronFamily_conjTranspose] + congr 1 + funext k + by_cases hk : k = j + · subst hk; simp + · simp [Function.update_of_ne hk] + +/-- **The phase gate is a fourth root of unity, so `S³ = Sᴴ`**: `sMatrix · sMatrix · sMatrix = +sMatrixᴴ`. Both sides are `diag(1, -i)` (`S = diag(1, i)`, `i³ = -i = conj i`); a `2×2` entrywise +computation. This is what makes `[S, S, S]` an inverse word for the phase gate. -/ +theorem sMatrix_mul_self_mul_self_eq_conjTranspose : + sMatrix * sMatrix * sMatrix = sMatrixᴴ := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sMatrix, Matrix.mul_apply, Fin.sum_univ_two, Matrix.conjTranspose_apply, + Complex.I_mul_I] + +/-! ### The inverse word of a gate, and of a circuit -/ + +/-- The **inverse word** of an elementary Clifford gate: a Clifford circuit whose matrix is the +gate's conjugate transpose (`toMatrix_invList`). Hadamard and CNOT are Hermitian involutions, so +each is its own inverse (`[had j]`, `[cnot c t h]`); the phase gate has order `4`, so `S⁻¹ = S³` +(`[phase j, phase j, phase j]`). -/ +def CliffordGate.invList : CliffordGate n → CliffordCircuit n + | .had j => [.had j] + | .phase j => [.phase j, .phase j, .phase j] + | .cnot c t h => [.cnot c t h] + +namespace CliffordCircuit + +/-- **The inverse word realises the gate's adjoint**: `(CliffordGate.invList γ).toMatrix = +γ.toMatrixᴴ`. By cases on `γ`: `H`/`CNOT` are self-adjoint (`hadamardC_isHermitian`, +`cnotWireGate_conjTranspose`), and `[S, S, S].toMatrix = kronWireGate j (S · S · S) = +kronWireGate j Sᴴ = (kronWireGate j S)ᴴ` via `kronWireGate_mul`, +`sMatrix_mul_self_mul_self_eq_conjTranspose` and `kronWireGate_conjTranspose`. -/ +theorem toMatrix_invList (γ : CliffordGate n) : + toMatrix γ.invList = (γ.toMatrix)ᴴ := by + cases γ with + | had j => + simp only [CliffordGate.invList, toMatrix, CliffordGate.toMatrix, mul_one] + rw [kronWireGate_conjTranspose, hadamardC_isHermitian.eq] + | phase j => + simp only [CliffordGate.invList, toMatrix, CliffordGate.toMatrix, mul_one] + rw [← Matrix.mul_assoc, kronWireGate_mul, kronWireGate_mul, + sMatrix_mul_self_mul_self_eq_conjTranspose, kronWireGate_conjTranspose] + | cnot c t h => + simp only [CliffordGate.invList, toMatrix, CliffordGate.toMatrix, mul_one] + rw [cnotWireGate_conjTranspose c t h] + +/-- The **inverse** of a Clifford circuit: reverse the gate list and replace each gate by its +inverse word (`CliffordGate.invList`). Read right-to-left, reversing the order and adjointing each +gate is precisely the conjugate transpose of the product (`toMatrix_inverse`). -/ +def inverse : CliffordCircuit n → CliffordCircuit n + | [] => [] + | γ :: U => inverse U ++ γ.invList + +/-- **The inverse circuit realises the adjoint**: `(inverse C).toMatrix = C.toMatrixᴴ`. By induction +on the gate list, using `toMatrix_append`, the per-gate `toMatrix_invList`, and +`conjTranspose_mul` (which reverses the product order, matching the reversal in `inverse`). This is +the assembly keystone: it lets the Figure 10.9 induction re-express a reduced normalizer +`U = Bᴴ • (phase • B'.toMatrix)` as a global phase times the Clifford circuit `inverse B ++ B'`. -/ +theorem toMatrix_inverse (C : CliffordCircuit n) : + toMatrix (inverse C) = (toMatrix C)ᴴ := by + induction C with + | nil => simp [inverse, toMatrix] + | cons γ U ih => + rw [inverse, toMatrix_append, ih, toMatrix_invList, toMatrix, Matrix.conjTranspose_mul] + +/-- **`inverse` is a right inverse**: `C.toMatrix · (inverse C).toMatrix = 1`, since a Clifford +circuit is unitary (`mul_conjTranspose`) and `(inverse C).toMatrix = C.toMatrixᴴ`. -/ +theorem toMatrix_mul_inverse (C : CliffordCircuit n) : + toMatrix C * toMatrix (inverse C) = 1 := by + rw [toMatrix_inverse]; exact mul_conjTranspose C + +/-- **`inverse` is a left inverse**: `(inverse C).toMatrix · C.toMatrix = 1`. From the right-inverse +identity via `mul_eq_one_comm` (a right inverse of a square matrix is a two-sided inverse). -/ +theorem toMatrix_inverse_mul (C : CliffordCircuit n) : + toMatrix (inverse C) * toMatrix C = 1 := by + rw [toMatrix_inverse]; exact mul_eq_one_comm.mp (mul_conjTranspose C) + +end CliffordCircuit + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/CliffordStabilizerTracking.lean b/LeanPool/AxQM/Concrete/CliffordStabilizerTracking.lean new file mode 100644 index 0000000000..e635204c39 --- /dev/null +++ b/LeanPool/AxQM/Concrete/CliffordStabilizerTracking.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit +public import LeanPool.AxQM.Concrete.StabilizerCodeDimension + +/-! +# Concrete: Clifford stabilizer tracking — N&C §10.5.2, Eq. (10.87) for Clifford circuits + +The **correctness of the "keep track of the generators" simulation** for the unitary part of the +Gottesman–Knill theorem (Nielsen & Chuang Theorem 10.7, §10.5.2, p. 459). + +N&C's Eq. (10.87) observes that if `|ψ⟩` lies in the stabilized subspace `V_S` (`g|ψ⟩ = |ψ⟩` for a +generator `g`) and a unitary `U` is applied, then `U|ψ⟩` is stabilized by `U g U†`: "so to compute +the change in the stabilizer we need only compute how it affects the generators". For a **Clifford +circuit** `U`, the backbone `CliffordCircuit.conj_pauliString` computes that conjugate +*classically*, `U · P_g · U† = U.sign g • P_{U.act g}` — the updated generator is again a (signed) +Pauli string, whose check-matrix row `U.act g` and `±1` sign `U.sign g` are read off by the composed +column operations. That is an identity of **operators**; this file closes the loop to the **state**, +proving the classically-updated generator really does fix the evolved vector `U ·ᵥ v`. + +* `conj_mulVec_toMatrix_mulVec` — the general unitary step (Eq. 10.87, matrix form): for any unitary + `U` (`U · Uᴴ = 1`) and any `P` fixing `v`, the conjugate `U · P · Uᴴ` fixes `U ·ᵥ v`. +* `CliffordCircuit.updatedGenerator_mulVec_toMatrix_mulVec` — the Clifford instance for a single + generator: `P_g ·ᵥ v = v ⟹ (U.sign g • P_{U.act g}) ·ᵥ (U ·ᵥ v) = U ·ᵥ v`. +* `CliffordCircuit.updatedGenerator_mulVec_toMatrix_mulVec_of_mem` — the whole generator family of a + stabilized subspace `V_S` is carried through: every classically-updated signed generator + `U.sign (g i) • P_{U.act (g i)}` fixes the evolved vector `U ·ᵥ v`. + +This is the precise sense in which "the classical computer performs the simulation … simply to keep +track of the generators of the stabilizer" (N&C §10.5.4) is **correct** for the Clifford operations: +the tracked list of check-matrix rows and signs `(U.act (g i), U.sign (g i))ᵢ` is a genuine +stabilizer description of the evolved state. +-/ + +@[expose] public section + +open scoped Matrix + +namespace AxQM.Concrete + +variable {n m : ℕ} + +/-- **N&C Eq. (10.87), matrix form — the general unitary step.** If `P` fixes `v` (`P ·ᵥ v = v`) and +`U` is unitary (`U · Uᴴ = 1`), then the conjugate `U · P · Uᴴ` fixes the evolved vector `U ·ᵥ v`: +`(U · P · Uᴴ) ·ᵥ (U ·ᵥ v) = U ·ᵥ v`. This is the linear-algebra content of "the state `U|ψ⟩` is +stabilized by `U g U†`". Proof: slide the outer `Uᴴ` against the `U` in `U ·ᵥ v` using `Uᴴ · U = 1` +(the two-sided inverse of a square unitary, `Matrix.mul_eq_one_comm`), then apply `P ·ᵥ v = v`. -/ +theorem conj_mulVec_toMatrix_mulVec + {U P : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : U * Uᴴ = 1) + {v : (Fin n → Fin 2) → ℂ} (hv : P.mulVec v = v) : + (U * P * Uᴴ).mulVec (U.mulVec v) = U.mulVec v := by + have hUadjU : Uᴴ * U = 1 := mul_eq_one_comm.mp hU + rw [Matrix.mulVec_mulVec, Matrix.mul_assoc, hUadjU, Matrix.mul_one, + ← Matrix.mulVec_mulVec, hv] + +namespace CliffordCircuit + +/-- **Gottesman–Knill, Clifford tracking (single generator).** If the phase-free Pauli string `P_g` +fixes `v` (`P_g ·ᵥ v = v` — `g` is a stabilizer generator of `v`), then the **classically-updated** +generator `U.sign g • P_{U.act g}` — the check-matrix row `U.act g` with sign `U.sign g` produced by +the Clifford circuit `U` — fixes the evolved vector `U ·ᵥ v`. Immediate from +`CliffordCircuit.conj_pauliString` (which identifies `U.sign g • P_{U.act g}` with `U · P_g · Uᴴ`) +and `conj_mulVec_toMatrix_mulVec` (Eq. 10.87, using unitarity `U · Uᴴ = 1`). -/ +theorem updatedGenerator_mulVec_toMatrix_mulVec (U : CliffordCircuit n) (g : Fin n → Fin 4) + {v : (Fin n → Fin 2) → ℂ} (hv : (pauliString g).mulVec v = v) : + (U.sign g • pauliString (U.act g)).mulVec (U.toMatrix.mulVec v) = U.toMatrix.mulVec v := by + rw [← U.conj_pauliString g] + exact conj_mulVec_toMatrix_mulVec U.mul_conjTranspose hv + +/-- **Gottesman–Knill, Clifford tracking (the whole stabilizer).** If `v` lies in the stabilized +subspace `V_S = ⟨g₀, …, g_{m-1}⟩`, then for every generator index `i` the classically-updated signed +generator `U.sign (g i) • P_{U.act (g i)}` fixes the evolved vector `U ·ᵥ v`. So the tracked +description `(U.act (g i), U.sign (g i))ᵢ` is a genuine stabilizer of `U ·ᵥ v`: the Clifford circuit +`U` maps `V_S` into the subspace stabilized by the updated generators. Per-generator instance of +`updatedGenerator_mulVec_toMatrix_mulVec` via `mem_stabilizedSubspace`. -/ +theorem updatedGenerator_mulVec_toMatrix_mulVec_of_mem (U : CliffordCircuit n) + {g : Fin m → Fin n → Fin 4} {v : (Fin n → Fin 2) → ℂ} + (hv : v ∈ stabilizedSubspace g) (i : Fin m) : + (U.sign (g i) • pauliString (U.act (g i))).mulVec (U.toMatrix.mulVec v) = U.toMatrix.mulVec v := + updatedGenerator_mulVec_toMatrix_mulVec U (g i) (mem_stabilizedSubspace.mp hv i) + +end CliffordCircuit + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/CnotWirePermGate.lean b/LeanPool/AxQM/Concrete/CnotWirePermGate.lean new file mode 100644 index 0000000000..bbc2b3940a --- /dev/null +++ b/LeanPool/AxQM/Concrete/CnotWirePermGate.lean @@ -0,0 +1,86 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerZClear +public import LeanPool.AxQM.Concrete.PermutationGate +public import LeanPool.AxQM.Concrete.MultiControlledNot + +/-! +# Concrete: the single `CNOT` matrix bridge — `permGate` of a one-control `mcNotPerm` is the +reindexed `cnotWireGate` + +This file bridges the **two matrix incarnations of a single `CNOT`** that Nielsen & Chuang +**Problem 4.3(3)** puts side by side: + +* the reversible-register gate `permGate enc (mcNotPerm {a} b hb)` — the permutation matrix on the + flat register `Fin d` (`enc : (Fin m → Fin 2) ≃ Fin d`) of the one-control multiply-controlled + `NOT` with control `a`, target `b`, the matrix underlying the register `Evolution` + `AxQM.mcNotWireEvolution` (`Postulates/API/FourGateReversibleWire`); and +* the Clifford gate matrix `cnotWireGate a b` — the `CNOT`-fan building block of the Figure-4.19 + parity circuit (`Concrete/PauliStringParityCascade`), indexed by the bit strings `Fin m → Fin 2`. + +The two are the same permutation (`mcNot {a} b = cnotPerm a b`, since a single control's control bit +is just that wire's value, `ctrlBit_singleton`), so the flat gate is exactly the bit-string gate +reindexed along `enc`: + +`permGate enc (mcNotPerm {a} b hb) = (cnotWireGate a b).submatrix enc.symm enc.symm`. + +This is the factor-level identity that lets the register `CNOT` fan `cnotFanIntoEvolution` +(`Postulates/API/CnotFanEvolution`) be identified — through `Matrix.toEuclideanCLM` — with the +reindexed matrix fan `Concrete.cnotFanInto` of Figure 4.19, chaining the Evolution-level Figure-4.19 +circuit to the matrix-level parity collapse `pauliString_exp_smul_conj_cnotFanInto`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-- **A one-control multiply-controlled `NOT` permutation is the `CNOT` bit-permutation.** For +control `a`, target `b` (`hb : b ∉ {a}`), the classical gate `mcNot {a} b` equals `cnotPerm a b`: +both flip the target bit `x b` by the single control bit `x a` (`ctrlBit {a} x = x a`, +`ctrlBit_singleton`) and leave every other wire unchanged. The pointwise identity behind the matrix +bridge `permGate_mcNotPerm_singleton_eq_submatrix_cnotWireGate`. -/ +theorem mcNot_singleton_eq_cnotPerm (a b : Fin m) (x : Fin m → Fin 2) : + mcNot {a} b x = cnotPerm a b x := by + rw [mcNot, cnotPerm, ctrlBit_singleton] + +/-- **The single-`CNOT` matrix bridge.** For control `a`, target `b` (`hb : b ∉ {a}`) and any +encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the bit strings as the flat register `Fin d`, the +reversible-register gate matrix `permGate enc (mcNotPerm {a} b hb)` is exactly the Clifford `CNOT` +matrix `cnotWireGate a b` reindexed from bit strings to `Fin d` along `enc`: + +`permGate enc (mcNotPerm {a} b hb) = (cnotWireGate a b).submatrix enc.symm enc.symm`. + +Proved entrywise: both `(I, J)`-entries are the indicator of the same event, since the two gates +realise the same bit-string permutation (`mcNot_singleton_eq_cnotPerm`) and `enc` intertwines the +flat and bit-string index conventions (`I = enc y ↔ enc.symm I = y`, `Equiv.symm_apply_eq`). -/ +theorem permGate_mcNotPerm_singleton_eq_submatrix_cnotWireGate {d : ℕ} + (enc : (Fin m → Fin 2) ≃ Fin d) (a b : Fin m) (hb : b ∉ ({a} : Finset (Fin m))) : + permGate enc (mcNotPerm {a} hb) + = (cnotWireGate a b).submatrix enc.symm enc.symm := by + ext I J + rw [permGate_apply, Matrix.submatrix_apply, cnotWireGate, Matrix.of_apply, mcNotPerm_apply, + mcNot_singleton_eq_cnotPerm] + exact if_congr (Equiv.symm_apply_eq enc).symm rfl rfl + +/-- **The matrix of a single `CNOT` step.** For distinct wires `a ≠ b`, the one-gate circuit +`cnotStep a b = [CNOT_{a→b}]` has matrix `cnotWireGate a b`. The reduction feeding the register +faithfulness `cnotWireEvolution_op` (`Postulates/API/CnotFanEvolution`) in its genuine-`CNOT` +branch. -/ +theorem cnotStep_toMatrix_of_ne {n : ℕ} {a b : Fin n} (hab : a ≠ b) : + CliffordCircuit.toMatrix (cnotStep a b) = cnotWireGate a b := by + rw [cnotStep, dite_eq_right hab] + simp only [CliffordCircuit.toMatrix, CliffordGate.toMatrix, mul_one] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/CollectorZRotation.lean b/LeanPool/AxQM/Concrete/CollectorZRotation.lean new file mode 100644 index 0000000000..3cd5a71dad --- /dev/null +++ b/LeanPool/AxQM/Concrete/CollectorZRotation.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringParityCascade +public import LeanPool.AxQM.Concrete.SingleQubitWire +public import LeanPool.AxQM.Concrete.Rotation + +/-! +# Concrete: the Figure-4.19 collector `Z`-rotation as a single-wire gate + +This is the **third step** of Nielsen & Chuang +**Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit gates" — closing +the gap between the *matrix-level* collector rotation of the Figure-4.19 parity cascade and the +*single-qubit `z`-rotation gate* that circuit actually applies to the collector wire. + +## The construction (N&C §4.7.3, Figure 4.19) + +`Concrete/PauliStringParityCascade.lean` reduces the diagonalised (all-`Z`-on-support) exponential +to `exp(s · P_a) = V† · exp(s · P_{Z_c}) · V`, where the middle factor `exp(s · P_{Z_c})` — +`exp(s • pauliString (zGenPauli c))` — is the collector rotation, a phase depending only on the +collector's bit. Physically `s = -i h_g Δ`, so this factor is a single-qubit `z`-rotation +`R_z(2 h_g Δ)` on wire `c`. This file makes that identification precise. + +## What is proved + +* `exp_smul_diagonal` — a general helper: `exp(s • diagonal v) = diagonal (fun i ↦ exp(s · vᵢ))` for + a complex diagonal matrix (`Matrix.exp_diagonal` composed with `Pi.coe_exp`). +* `pauliString_zGenPauli_eq_diagonal` — the single-`Z` string `P_{Z_c}` is diagonal, `+1` where the + collector bit is `0` and `−1` where it is `1` (the general-wire form of the wire-`0` + `pauliString_zGenPauli_zero_eq_diagonal`). +* `pauliZ_eq_diagonal` / `rotZ_eq_exp_smul_pauliZ` — the `2 × 2` facts `Z = diagonal ![1, −1]` and + `R_z(θ) = exp((−θ/2) i • Z)` (the latter is the definition `rotZ = rotAxis ![0,0,1]` unfolded + through `pauliDot_axisZ`). +* `exp_smul_pauliString_zGenPauli_submatrix_eq_singleQubitOnWire` — **the bridge**: reindexed to the + flat `2ⁿ`-level register along `finFunctionFinEquiv`, the collector exponential is exactly the + `2 × 2` gate `exp(s • Z)` placed on wire `c` (`e := finFunctionFinEquiv`), + `(exp(s • P_{Z_c})).submatrix e⁻¹ e⁻¹ = singleQubitOnWire e c (exp(s • Z))`. + Both sides are diagonal (`P_{Z_c}` and `Z` are), so the proof is a diagonal-vector comparison via + `singleQubitOnWire_diagonal` and `Matrix.submatrix_diagonal_equiv`. + +Chaining this with `rotZ_eq_exp_smul_pauliZ` (at `s = (−θ/2) i`) exhibits the register `z`-rotation +`singleQubitOnWire e c (rotZ θ)` — the one single-qubit gate the collector carries — as the +reindexed Figure-4.19 collector rotation; the `Evolution`-level faithfulness of that identification +is `rotZWireEvolution_op_eq_exp_smul_zGenPauli` (`Postulates/API/CollectorZRotationEvolution.lean`). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **Exponential of a scalar-multiplied complex diagonal matrix.** `exp(s • diagonal v)` is the +diagonal matrix of pointwise complex exponentials `fun i ↦ exp(s · vᵢ)`. Pushes the scalar into the +diagonal (`Matrix.diagonal_smul`), applies `Matrix.exp_diagonal`, and evaluates the resulting +`Pi`-exponential pointwise (`Pi.coe_exp`, `Complex.exp_eq_exp_ℂ`). -/ +theorem exp_smul_diagonal {m : Type*} [Fintype m] [DecidableEq m] (s : ℂ) (v : m → ℂ) : + NormedSpace.exp (s • Matrix.diagonal v) + = Matrix.diagonal (fun i => Complex.exp (s * v i)) := by + rw [← Matrix.diagonal_smul, Matrix.exp_diagonal] + congr 1 + funext i + rw [Complex.exp_eq_exp_ℂ, Pi.coe_exp, Pi.smul_apply, smul_eq_mul] + +/-- **The single-`Z` Pauli string `Z_c` is diagonal.** `pauliString (zGenPauli c)` — `Z` on the +collector wire `c`, identity elsewhere — is the diagonal matrix whose entry at a bit string `i` is +`+1` when the collector bit `i c` is `0` and `−1` when it is `1`. The general-wire form of +`pauliString_zGenPauli_zero_eq_diagonal` (wire `0`): every off-support factor `pauli 0 = I` is +diagonal and the collector factor `pauli 3 = Z` is diagonal, so the whole product vanishes off the +diagonal and equals the collector's `Z` entry on it. -/ +theorem pauliString_zGenPauli_eq_diagonal (c : Fin n) : + pauliString (zGenPauli c) = Matrix.diagonal (fun i => if i c = 0 then (1 : ℂ) else -1) := by + ext i j + rw [pauliString_apply, Matrix.diagonal_apply] + by_cases hij : i = j + · subst hij + rw [ite_eq_left rfl, ← Finset.mul_prod_erase _ _ (Finset.mem_univ c)] + have hrest : ∀ k ∈ Finset.univ.erase c, pauli (zGenPauli c k) (i k) (i k) = 1 := by + intro k hk + rw [zGenPauli_apply, ite_eq_right (Finset.ne_of_mem_erase hk)]; simp [pauli] + rw [Finset.prod_congr rfl hrest, Finset.prod_const_one, mul_one, zGenPauli_apply, + ite_eq_left rfl] + rcases (show i c = 0 ∨ i c = 1 by omega) with h | h <;> rw [h] <;> simp [pauli, pauliZ] + · rw [ite_eq_right hij] + obtain ⟨k, hk⟩ := Function.ne_iff.mp hij + refine Finset.prod_eq_zero (Finset.mem_univ k) ?_ + by_cases hkc : k = c + · subst hkc + rw [zGenPauli_apply, ite_eq_left rfl] + rcases (show i k = 0 ∨ i k = 1 by omega) with h1 | h1 <;> + rcases (show j k = 0 ∨ j k = 1 by omega) with h2 | h2 <;> simp_all [pauli, pauliZ] + · rw [zGenPauli_apply, ite_eq_right hkc]; simp [pauli, hk] + +/-- **The Pauli `Z` matrix as a diagonal.** `Z = diagonal ![1, −1]`, entry `+1` at bit `0` and `−1` +at bit `1`. The `2 × 2` companion of `pauliString_zGenPauli_eq_diagonal`. -/ +theorem pauliZ_eq_diagonal : + pauliZ = Matrix.diagonal (fun z => if z = 0 then (1 : ℂ) else -1) := by + ext a b; fin_cases a <;> fin_cases b <;> simp [pauliZ] + +/-- **The `z`-rotation is the exponential of `−(θ/2) i • Z`.** `R_z(θ) = exp((−θ/2) i • Z)`, +Nielsen & Chuang eq. 4.6 read as the definition `rotZ = rotAxis ![0,0,1]` (an exponential of +`(−θ/2) i • (e_z·σ)`) with `e_z·σ = Z` (`pauliDot_axisZ`). The scalar `s = (−θ/2) i` is exactly the +`s = -i h_g Δ` of the Figure-4.19 collector rotation at `θ = 2 h_g Δ`. -/ +theorem rotZ_eq_exp_smul_pauliZ (θ : ℝ) : + rotZ θ = NormedSpace.exp ((((-(θ / 2) : ℝ) : ℂ) * Complex.I) • pauliZ) := by + rw [rotZ, rotAxis, pauliDot_axisZ] + +/-- **The Figure-4.19 collector rotation is a single-wire `Z`-exponential.** Reindexed to the flat +`2ⁿ`-level register along `e = finFunctionFinEquiv`, the collector exponential +`exp(s • pauliString (zGenPauli c))` — the middle factor `exp(s · P_{Z_c})` of the parity collapse +`pauliString_exp_smul_conj_cnotFanInto` — is exactly the `2 × 2` gate `exp(s • Z)` placed on wire +`c`: +`(exp(s • P_{Z_c})).submatrix e⁻¹ e⁻¹ = singleQubitOnWire e c (exp(s • Z))`. + +Both sides are diagonal: `pauliString (zGenPauli c)` and `pauliZ` are diagonal +(`pauliString_zGenPauli_eq_diagonal`, `pauliZ_eq_diagonal`), so `exp_smul_diagonal` turns each +exponential into a diagonal of pointwise complex exponentials; `Matrix.submatrix_diagonal_equiv` and +`singleQubitOnWire_diagonal` then reindex both to `diagonal (fun i ↦ exp(s · (Z-value of bit c of +e⁻¹ i)))`. The reindex `.submatrix e⁻¹ e⁻¹` is the same `finFunctionFinEquiv.symm` reindex that +`pauliStringStd` / `kronFamilyStd` / `cnotFanIntoEvolution_op` use, so this chains directly into the +register faithfulness of the parity fan. -/ +theorem exp_smul_pauliString_zGenPauli_submatrix_eq_singleQubitOnWire (c : Fin n) (s : ℂ) : + (NormedSpace.exp (s • pauliString (zGenPauli c))).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm + = singleQubitOnWire finFunctionFinEquiv c (NormedSpace.exp (s • pauliZ)) := by + rw [pauliString_zGenPauli_eq_diagonal, exp_smul_diagonal, Matrix.submatrix_diagonal_equiv, + pauliZ_eq_diagonal, exp_smul_diagonal, singleQubitOnWire_diagonal] + rfl + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ComplexExpUnit.lean b/LeanPool/AxQM/Concrete/ComplexExpUnit.lean new file mode 100644 index 0000000000..17d91afbad --- /dev/null +++ b/LeanPool/AxQM/Concrete/ComplexExpUnit.lean @@ -0,0 +1,40 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Complex.Circle + +/-! +# Concrete: unit-modulus arithmetic for `e^{iφ}` + +A single shared home for the `star (e^{iφ}) · e^{iφ} = 1` form of the unit-modulus fact — the shape +consumed when proving a *diagonal* matrix with `e^{iφ}` entries is unitary +(`Matrix.mem_unitaryGroup` reduces to `star · = 1` on each diagonal entry). Mathlib packages the +**norm** form +(`Complex.nnnorm_exp_ofReal_mul_I : ‖e^{iφ}‖₊ = 1`) but not this `star`-product form, so this file +provides it once here rather than re-deriving it per consumer. + +It is used by `LinearOpticalElement` and the multiply-controlled single-qubit reductions of +Exercise 4.43. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +/-- The phase `e^{iφ}` has unit modulus, in the `star`-product form used for diagonal unitarity: +`conj(e^{iφ}) · e^{iφ} = 1`. Proved via `Complex.exp_conj` (`conj (e^{iφ}) = e^{-iφ}`) and +`e^{-iφ} · e^{iφ} = e^{0} = 1`. -/ +theorem star_exp_ofReal_mul_I_mul_self (φ : ℝ) : + star (Complex.exp ((φ : ℂ) * Complex.I)) * Complex.exp ((φ : ℂ) * Complex.I) = 1 := by + rw [Complex.star_def, ← Complex.exp_conj, map_mul, Complex.conj_ofReal, Complex.conj_I, + ← Complex.exp_add, + show (φ : ℂ) * (-Complex.I) + (φ : ℂ) * Complex.I = 0 by ring, Complex.exp_zero] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ControlledSingleQubit.lean b/LeanPool/AxQM/Concrete/ControlledSingleQubit.lean new file mode 100644 index 0000000000..f4d2e37f5c --- /dev/null +++ b/LeanPool/AxQM/Concrete/ControlledSingleQubit.lean @@ -0,0 +1,356 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelEmbedding +public import LeanPool.AxQM.Concrete.GrayCode + +/-! +# Concrete: the controlled single-qubit gate (N&C §4.5.2, the controlled-`U₀` step) + +(Nielsen & Chuang §4.5.2, p. 191–193.) + +The §4.5.2 realisation of a two-level unitary `U` (acting non-trivially only on two computational +basis states `|s⟩`, `|t⟩`) as a circuit of single-qubit and `CNOT` gates walks a Gray code to bring +the two active states onto a pair `|g_{m-1}⟩`, `|g_m⟩ = |t⟩` **differing in exactly one bit** `j`, +then applies a *controlled-`U₀`* operation — apply the `2 × 2` unitary `U₀` to qubit `j`, +conditional +on the other qubits matching the values shared by the two active states. The Gray-code relocation is +already in the library (`swapConj_swapChain_grayCode_support`, the first stage); this file provides +that controlled-`U₀` object as an explicit matrix and identifies it with a bit-adjacent two-level +unitary. + +## The construction + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the `m`-bit strings as the `d = 2 ^ m` +computational basis indices. For a target bit `j`, a control pattern `c : Fin m → Fin 2` (its `j`-th +entry is ignored — the two active states are `c` with bit `j` set to `0` and to `1`), and a `2 × 2` +matrix `U₀`: + +* `AxQM.Concrete.ctrlSingleQubit enc j c U₀` — on the basis state `|enc x⟩` it applies `U₀` + to bit `j` of `x` when the other bits of `x` agree with `c`, and fixes `|enc x⟩` otherwise. + +The key identity is that this **is** a two-level embedding at the bit-adjacent pair: + +* `AxQM.Concrete.ctrlSingleQubit_eq_twoLevelEmbed` — + `ctrlSingleQubit enc j c U₀ = twoLevelEmbed (enc (c[j↦0])) (enc (c[j↦1])) U₀`, an entrywise + identification. Via `isTwoLevelUnitary_twoLevelEmbed` it follows that a controlled single-qubit + gate with unitary `U₀` is a two-level unitary (`isTwoLevelUnitary_ctrlSingleQubit`) whose + distinguished pair `{c[j↦0], c[j↦1]}` differs in a single bit (`differsInOneBit_update_zero_one`) + — the §4.5.2 controlled-`U₀` gate. Its action is read off from `twoLevelEmbed_mulVec`: + `ctrlSingleQubit_mulVec` mixes only the two active components through `U₀`, and + `ctrlSingleQubit_mulVec_of_not_ctrl` fixes every basis state outside the controlled subspace. + +Used by the §4.5.2 development of Exercise 4.43's `n`-qubit lift; the statement of Exercise 4.43 +is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- If a bit-string does not match the control pattern `c` off bit `j`, it is neither of the two +active states `c[j↦0]`, `c[j↦1]` — a thin wrapper reading off `Function.eq_update_iff`. -/ +theorem ne_update_of_not_ctrl {j : Fin m} {v : Fin 2} {c y : Fin m → Fin 2} + (h : ¬ ∀ k, k ≠ j → y k = c k) : y ≠ Function.update c j v := + fun he => h (Function.eq_update_iff.mp he).2 + +/-- If `z` matches the control pattern `c` off bit `j`, then `z = c[j↦v]` iff `z j = v`. -/ +theorem eq_update_iff_of_off {j : Fin m} {c z : Fin m → Fin 2} + (h : ∀ k, k ≠ j → z k = c k) (v : Fin 2) : + (z = Function.update c j v) ↔ z j = v := + Function.eq_update_iff.trans (and_iff_left h) + +/-- The two active states `c[j↦0]` and `c[j↦1]` differ (at bit `j`), hence are distinct. -/ +theorem update_zero_ne_update_one {j : Fin m} (c : Fin m → Fin 2) : + Function.update c j 0 ≠ Function.update c j 1 := by + intro h + have := congrFun h j + simp only [Function.update_self] at this + exact absurd this (by decide) + +/-- The two active states of a controlled single-qubit gate differ in exactly one bit (bit `j`) — +the adjacency the Gray-code relocation produces. -/ +theorem differsInOneBit_update_zero_one {j : Fin m} (c : Fin m → Fin 2) : + differsInOneBit (Function.update c j 0) (Function.update c j 1) := by + refine ⟨j, ?_, fun k hk => ?_⟩ + · simp only [Function.update_self]; decide + · simp [Function.update_of_ne hk] + +/-- **The controlled single-qubit gate** (N&C §4.5.2's controlled-`U₀`). Relative to an encoding +`enc : (Fin m → Fin 2) ≃ Fin d`, target bit `j`, control pattern `c`, and `2 × 2` matrix `U₀`, it +applies `U₀` to bit `j` of `x` on the basis state `|enc x⟩` when the other bits of `x` match `c`, +and +acts as the identity otherwise. -/ +def ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) (c : Fin m → Fin 2) + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : Matrix (Fin d) (Fin d) ℂ := + Matrix.of fun i i' => + if ∀ k, k ≠ j → enc.symm i k = enc.symm i' k then + (if ∀ k, k ≠ j → enc.symm i k = c k then U₀ (enc.symm i j) (enc.symm i' j) + else if enc.symm i j = enc.symm i' j then 1 else 0) + else 0 + +/-- The entrywise heart of `ctrlSingleQubit_eq_twoLevelEmbed`, phrased on bare bit-strings `x`, `y`: +the controlled-gate entry (LHS) equals the two-level-embedding entry at the pair +`{c[j↦0], c[j↦1]}` (RHS). -/ +theorem ctrlSingleQubit_entry_eq {j : Fin m} {c : Fin m → Fin 2} + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) (x y : Fin m → Fin 2) : + (if ∀ k, k ≠ j → x k = y k then + (if ∀ k, k ≠ j → x k = c k then U₀ (x j) (y j) else if x j = y j then 1 else 0) + else 0) + = (if x = Function.update c j 0 then + (if y = Function.update c j 0 then U₀ 0 0 else if y = Function.update c j 1 then U₀ 0 1 + else 0) + else if x = Function.update c j 1 then + (if y = Function.update c j 0 then U₀ 1 0 else if y = Function.update c j 1 then U₀ 1 1 + else 0) + else if x = y then 1 else 0) := by + by_cases hcx : ∀ k, k ≠ j → x k = c k + · -- `x` matches the control pattern off bit `j`. + have hxa := eq_update_iff_of_off hcx 0 + have hxb := eq_update_iff_of_off hcx 1 + by_cases hcy : ∀ k, k ≠ j → y k = c k + · -- both `x, y` match: the gate acts through `U₀ (x j) (y j)`. + have hPi : ∀ k, k ≠ j → x k = y k := fun k hk => (hcx k hk).trans (hcy k hk).symm + have hya := eq_update_iff_of_off hcy 0 + have hyb := eq_update_iff_of_off hcy 1 + rw [ite_eq_left hPi, ite_eq_left hcx] + rcases (by omega : x j = 0 ∨ x j = 1) with hx | hx <;> + rcases (by omega : y j = 0 ∨ y j = 1) with hy | hy + · rw [ite_eq_left (hxa.2 hx), ite_eq_left (hya.2 hy), hx, hy] + · rw [ite_eq_left (hxa.2 hx), ite_eq_right (by rw [hya]; omega), ite_eq_left (hyb.2 hy), hx, + hy] + · rw [ite_eq_right (by rw [hxa]; omega), ite_eq_left (hxb.2 hx), ite_eq_left (hya.2 hy), hx, + hy] + · rw [ite_eq_right (by rw [hxa]; omega), ite_eq_left (hxb.2 hx), + ite_eq_right (by rw [hya]; omega), + ite_eq_left (hyb.2 hy), hx, hy] + · -- `y` does not match: both sides are `0` at the `y`-column. + have hPi : ¬ ∀ k, k ≠ j → x k = y k := + fun hPi => hcy fun k hk => (hPi k hk).symm.trans (hcx k hk) + have hy0 : ¬ (y = Function.update c j 0) := ne_update_of_not_ctrl hcy + have hy1 : ¬ (y = Function.update c j 1) := ne_update_of_not_ctrl hcy + rw [ite_eq_right hPi] + rcases (by omega : x j = 0 ∨ x j = 1) with hx | hx + · rw [ite_eq_left (hxa.2 hx), ite_eq_right hy0, ite_eq_right hy1] + · rw [ite_eq_right (by rw [hxa]; omega), ite_eq_left (hxb.2 hx), ite_eq_right hy0, + ite_eq_right hy1] + · -- `x` does not match: the gate is the identity at the `x`-row. + have hx0 : ¬ (x = Function.update c j 0) := ne_update_of_not_ctrl hcx + have hx1 : ¬ (x = Function.update c j 1) := ne_update_of_not_ctrl hcx + rw [ite_eq_right hcx, ite_eq_right hx0, ite_eq_right hx1] + by_cases hxy : x = y + · subst hxy + rw [ite_eq_left (fun _ _ => rfl), ite_eq_left rfl, ite_eq_left rfl] + · rw [ite_eq_right hxy] + by_cases hoff : ∀ k, k ≠ j → x k = y k + · have hne : x j ≠ y j := fun hj => hxy (funext fun k => by + rcases eq_or_ne k j with rfl | hk + · exact hj + · exact hoff k hk) + rw [ite_eq_left hoff, ite_eq_right hne] + · rw [ite_eq_right hoff] + +/-- **A controlled single-qubit gate is a two-level embedding at a bit-adjacent pair.** +`ctrlSingleQubit enc j c U₀` places `U₀` into the `{enc (c[j↦0]), enc (c[j↦1])}` block, an entrywise +identity. This routes the controlled-`U₀` gate through the §4.5.1 embedding machinery. -/ +theorem ctrlSingleQubit_eq_twoLevelEmbed (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + ctrlSingleQubit enc j c U₀ + = twoLevelEmbed (enc (Function.update c j 0)) (enc (Function.update c j 1)) U₀ := by + ext i i' + have hi0 : (i = enc (Function.update c j 0)) ↔ (enc.symm i = Function.update c j 0) := by + rw [Equiv.symm_apply_eq] + have hi1 : (i = enc (Function.update c j 1)) ↔ (enc.symm i = Function.update c j 1) := by + rw [Equiv.symm_apply_eq] + have hi'0 : (i' = enc (Function.update c j 0)) ↔ (enc.symm i' = Function.update c j 0) := by + rw [Equiv.symm_apply_eq] + have hi'1 : (i' = enc (Function.update c j 1)) ↔ (enc.symm i' = Function.update c j 1) := by + rw [Equiv.symm_apply_eq] + have hii' : (i = i') ↔ (enc.symm i = enc.symm i') := enc.symm.injective.eq_iff.symm + simp only [ctrlSingleQubit, Matrix.of_apply, twoLevelEmbed_apply, hi0, hi1, hi'0, hi'1, hii'] + exact ctrlSingleQubit_entry_eq U₀ (enc.symm i) (enc.symm i') + +/-- **A controlled single-qubit gate with unitary `U₀` is a two-level unitary.** -/ +theorem isTwoLevelUnitary_ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) {U₀ : Matrix (Fin 2) (Fin 2) ℂ} (hU₀ : U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + IsTwoLevelUnitary (ctrlSingleQubit enc j c U₀) := by + rw [ctrlSingleQubit_eq_twoLevelEmbed] + exact isTwoLevelUnitary_twoLevelEmbed (enc.injective.ne (update_zero_ne_update_one c)) hU₀ + +/-- **The action of a controlled single-qubit gate on a vector.** It mixes only the two active +components `enc (c[j↦0])`, `enc (c[j↦1])` through `U₀`, fixing every other component — the +controlled-`U₀` action. -/ +theorem ctrlSingleQubit_mulVec (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) (c : Fin m → Fin 2) + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) : + (ctrlSingleQubit enc j c U₀ *ᵥ v) i = + if enc.symm i = Function.update c j 0 then + U₀ 0 0 * v (enc (Function.update c j 0)) + U₀ 0 1 * v (enc (Function.update c j 1)) + else if enc.symm i = Function.update c j 1 then + U₀ 1 0 * v (enc (Function.update c j 0)) + U₀ 1 1 * v (enc (Function.update c j 1)) + else v i := by + rw [ctrlSingleQubit_eq_twoLevelEmbed, + twoLevelEmbed_mulVec (enc.injective.ne (update_zero_ne_update_one c))] + simp only [← Equiv.symm_apply_eq] + +/-- Outside the controlled subspace — when the other bits of `x = enc.symm i` do not match the +control pattern `c` — the controlled single-qubit gate fixes `|enc x⟩`. -/ +theorem ctrlSingleQubit_mulVec_of_not_ctrl (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) + (h : ¬ ∀ k, k ≠ j → enc.symm i k = c k) : + (ctrlSingleQubit enc j c U₀ *ᵥ v) i = v i := by + rw [ctrlSingleQubit_mulVec, ite_eq_right (ne_update_of_not_ctrl h), + ite_eq_right (ne_update_of_not_ctrl h)] + +/-! ## The fibrewise-gate abstraction + +Both `ctrlSingleQubit enc j c` (above) and `singleQubitOnWire enc j` (`SingleQubitWire.lean`) +are **fibrewise**: they preserve each two-dimensional `j`-bit fibre +`{x[j↦0], x[j↦1]}` and act on it by a `2 × 2` block determined by the *other* bits. `wireGate` +captures that common shape here, at the common ancestor of both gates, so each gate's action / +multiplicativity lemmas are one-line consequences of the general `wireGate_*` lemmas (rather than +parallel hand-proofs). -/ + +/-- **A fibrewise gate on wire `j`.** For an encoding `enc : (Fin m → Fin 2) ≃ Fin d`, a wire `j`, +and a family `f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ` of `2 × 2` blocks indexed by the +off-`j` bit-pattern, `wireGate enc j f` is the `d × d` matrix that, on the basis state `|enc x⟩`, +acts on the `j`-th bit's two-dimensional fibre by the block `f x` (read at the pattern with bit `j` +normalised to `0`), fixing the other bits. It is the common shape of `singleQubitOnWire` (a constant +block) and `ctrlSingleQubit` (a block that is `U₀` on the controlled fibres and `1` elsewhere). -/ +def wireGate (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) : Matrix (Fin d) (Fin d) ℂ := + Matrix.of fun i i' => + if ∀ k, k ≠ j → enc.symm i k = enc.symm i' k then + f (Function.update (enc.symm i) j 0) (enc.symm i j) (enc.symm i' j) + else 0 + +/-- Unfolding lemma for `wireGate` entries. -/ +theorem wireGate_apply (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) (i i' : Fin d) : + wireGate enc j f i i' = + if ∀ k, k ≠ j → enc.symm i k = enc.symm i' k then + f (Function.update (enc.symm i) j 0) (enc.symm i j) (enc.symm i' j) + else 0 := rfl + +/-- **The action of a fibrewise gate on a vector.** It mixes only the two components whose +bit-strings agree off wire `j`, through the block `f` (read at the fibre representative). -/ +theorem wireGate_mulVec (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) : + (wireGate enc j f *ᵥ v) i = + f (Function.update (enc.symm i) j 0) (enc.symm i j) 0 + * v (enc (Function.update (enc.symm i) j 0)) + + f (Function.update (enc.symm i) j 0) (enc.symm i j) 1 + * v (enc (Function.update (enc.symm i) j 1)) := by + classical + simp only [Matrix.mulVec, dotProduct, wireGate, Matrix.of_apply] + set X := enc.symm i with hX + set p := enc (Function.update X j 0) with hp + set q := enc (Function.update X j 1) with hq + have hpq : p ≠ q := enc.injective.ne (update_zero_ne_update_one X) + have hp' : enc.symm p = Function.update X j 0 := by rw [hp, Equiv.symm_apply_apply] + have hq' : enc.symm q = Function.update X j 1 := by rw [hq, Equiv.symm_apply_apply] + rw [Finset.sum_eq_add p q hpq (fun c _ hc => ?_) (by simp) (by simp)] + · -- the two surviving terms `p`, `q` + have hcondp : ∀ k, k ≠ j → X k = enc.symm p k := by + intro k hk; rw [hp', Function.update_of_ne hk] + have hcondq : ∀ k, k ≠ j → X k = enc.symm q k := by + intro k hk; rw [hq', Function.update_of_ne hk] + rw [ite_eq_left hcondp, ite_eq_left hcondq, hp', hq', Function.update_self, + Function.update_self] + · -- every other index contributes `0` + have hcond : ¬ ∀ k, k ≠ j → X k = enc.symm c k := by + intro hcond + have hupd : enc.symm c = Function.update X j (enc.symm c j) := by + funext k + rcases eq_or_ne k j with rfl | hk + · rw [Function.update_self] + · rw [Function.update_of_ne hk, ← hcond k hk] + rcases (show enc.symm c j = 0 ∨ enc.symm c j = 1 from by omega) with h0 | h1 + · exact hc.1 (by rw [← Equiv.symm_apply_eq, hupd, h0]) + · exact hc.2 (by rw [← Equiv.symm_apply_eq, hupd, h1]) + rw [ite_eq_right hcond, zero_mul] + +/-- **Fibrewise gates multiply blockwise.** Since a fibrewise gate preserves each `j`-bit fibre, +different fibres never mix, so a matrix product of two of them multiplies their `2 × 2` blocks +fibre-by-fibre: `wireGate enc j f * wireGate enc j g = wireGate enc j (fun y => f y * g y)`. -/ +theorem wireGate_mul (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (f g : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) : + wireGate enc j f * wireGate enc j g = wireGate enc j (fun y => f y * g y) := by + have key : ∀ (v : Fin d → ℂ) (i : Fin d), + ((wireGate enc j f * wireGate enc j g) *ᵥ v) i + = (wireGate enc j (fun y => f y * g y) *ᵥ v) i := by + intro v i + rw [← Matrix.mulVec_mulVec] + simp only [wireGate_mulVec, Equiv.symm_apply_apply, Function.update_self, + Function.update_idem, Matrix.mul_apply, Fin.sum_univ_two] + ring + ext i i' + have h1 := key (fun x => if x = i' then (1 : ℂ) else 0) i + simpa only [Matrix.mulVec, dotProduct, mul_ite, mul_one, mul_zero, + Finset.sum_ite_eq', Finset.mem_univ, ite_true] using h1 + +/-- **The fibrewise gate with the constant identity block is the identity.** -/ +theorem wireGate_one (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) : + wireGate enc j (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) = 1 := by + ext i i' + simp only [wireGate_apply, Matrix.one_apply] + by_cases h : i = i' + · subst h; simp + · rw [ite_eq_right h] + by_cases hoff : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hoff, ite_eq_right] + intro hj + exact h (enc.symm.injective (funext fun k => by + rcases eq_or_ne k j with rfl | hk + · exact hj + · exact hoff k hk)) + · rw [ite_eq_right hoff] + +/-- **A fibrewise gate commutes with the conjugate transpose**: +`(wireGate enc j f)ᴴ = wireGate enc j (fun y => (f y)ᴴ)`. Each fibre's `2 × 2` block is transposed; +the fibre representative is unaffected because the two indices agree off wire `j` exactly when the +entry is non-zero. The adjoint counterpart of `wireGate_mul`. -/ +theorem wireGate_conjTranspose (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) : + (wireGate enc j f)ᴴ = wireGate enc j (fun y => (f y)ᴴ) := by + ext i i' + rw [Matrix.conjTranspose_apply, wireGate_apply, wireGate_apply] + by_cases hoff : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hoff, ite_eq_left (fun k hk => (hoff k hk).symm)] + have hrep : Function.update (enc.symm i') j 0 = Function.update (enc.symm i) j 0 := by + funext k + rcases eq_or_ne k j with rfl | hk + · rw [Function.update_self, Function.update_self] + · rw [Function.update_of_ne hk, Function.update_of_ne hk, hoff k hk] + rw [hrep, Matrix.conjTranspose_apply] + · rw [ite_eq_right hoff, ite_eq_right (fun h => hoff (fun k hk => (h k hk).symm)), star_zero] + +/-- **`ctrlSingleQubit` is the fibrewise gate whose block is `U₀` on the controlled fibres and `1` +elsewhere.** -/ +theorem ctrlSingleQubit_eq_wireGate (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + ctrlSingleQubit enc j c U₀ + = wireGate enc j (fun y => if ∀ k, k ≠ j → y k = c k then U₀ else 1) := by + ext i i' + simp only [ctrlSingleQubit, wireGate, Matrix.of_apply] + by_cases hfib : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hfib, ite_eq_left hfib] + have hcond : (∀ k, k ≠ j → Function.update (enc.symm i) j 0 k = c k) + ↔ (∀ k, k ≠ j → enc.symm i k = c k) := + forall_congr' fun k => imp_congr_right fun hk => by rw [Function.update_of_ne hk] + by_cases hc : ∀ k, k ≠ j → enc.symm i k = c k + · rw [ite_eq_left hc, ite_eq_left (hcond.mpr hc)] + · rw [ite_eq_right hc, ite_eq_right (fun h => hc (hcond.mp h)), Matrix.one_apply] + · rw [ite_eq_right hfib, ite_eq_right hfib] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ControlledSingleQubitConjugation.lean b/LeanPool/AxQM/Concrete/ControlledSingleQubitConjugation.lean new file mode 100644 index 0000000000..0075c3b777 --- /dev/null +++ b/LeanPool/AxQM/Concrete/ControlledSingleQubitConjugation.lean @@ -0,0 +1,208 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.SingleQubitWire +public import LeanPool.AxQM.Concrete.TwoLevelControlledDecomposition + +/-! +# Concrete: control-pattern normalisation of a controlled single-qubit gate (N&C §4.3) + +(Nielsen & Chuang §4.3, §4.5.2, p. 182–193 — the reduction of a controlled gate to single-qubit and +`CNOT` gates.) + +The §4.5 decomposition (`Concrete/UnitaryControlledProduct.lean`) writes any register unitary as a +product of **controlled single-qubit gates** `ctrlSingleQubit enc j c U₀` — apply `U₀` to bit `j` +when +the *other* bits match a control pattern `c`. Nielsen & Chuang's §4.3 reduces such a multiply- +controlled gate to a circuit of uncontrolled single-qubit gates on wires and `CNOT`s. The very first +move of that reduction is **control-pattern normalisation**: by conjugating a control wire with a +`NOT` gate, the value the control is conditioned on flips, so an arbitrary control pattern can be +brought to a canonical one (e.g. all controls conditioned on `1`). This file supplies that step at +the matrix level. + +## The construction + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the `m`-bit strings as the `d = 2 ^ m` basis +indices. The `NOT` (`X`) gate on wire `k` is the uncontrolled single-qubit gate +`singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` — already in the target gate family, unitary +(`singleQubitOnWire_mem_unitaryGroup` with `swapTwo_mem_unitaryGroup`), and an involution +(`singleQubitOnWire_swap_mul_self`). + +* `AxQM.Concrete.flipWire enc k` — the basis-index involution that flips bit `k` of the + encoded bit-string (`|enc x⟩ ↦ |enc x'⟩` with `x'` equal to `x` with bit `k` negated). The `X`-on- + wire gate is exactly its permutation matrix (`singleQubitOnWire_swap_apply`). +* `AxQM.Concrete.singleQubitOnWire_swap_conj` — **conjugation by the `X`-on-wire gate is a + reindexing.** `Wₖ * M * Wₖ = M.submatrix (flipWire enc k) (flipWire enc k)` for any `d × d` matrix + `M`: sandwiching `M` between two `X`-on-wire gates permutes both indices by the wire-`k` flip. A + reusable matrix identity (the analogue of `swap_conj_apply` for the wire-flip permutation). +* `AxQM.Concrete.ctrlSingleQubit_conj_singleQubitOnWire_swap` — **the headline: conjugating + by the `X`-on-wire gate flips the control bit.** For `k ≠ j`, + `Wₖ * ctrlSingleQubit enc j c U₀ * Wₖ = ctrlSingleQubit enc j (c[k ↦ ¬c k]) U₀`: the controlled + gate + is unchanged except that the value control wire `k` is conditioned on is negated. Iterating this + over the wires where `c` is `0` normalises any control pattern to all-`1` controls — the §4.3 + reduction's first step. + +Used by the §4.3 reduction of Exercise 4.43's `n`-qubit lift; the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The basis-index involution flipping bit `k`.** Relative to an encoding +`enc : (Fin m → Fin 2) ≃ Fin d`, it sends `|enc x⟩` to `|enc x'⟩` where `x'` is `x` with bit `k` +negated (`Equiv.swap 0 1`). It is exactly the permutation the `X`-on-wire gate +`singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` realises (`singleQubitOnWire_swap_apply`). -/ +def flipWire (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) (i : Fin d) : Fin d := + enc (Function.update (enc.symm i) k (Equiv.swap 0 1 (enc.symm i k))) + +/-- The bit-string underlying `flipWire enc k i` is `enc.symm i` with bit `k` negated. -/ +theorem enc_symm_flipWire (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) (i : Fin d) : + enc.symm (flipWire enc k i) + = Function.update (enc.symm i) k (Equiv.swap 0 1 (enc.symm i k)) := by + rw [flipWire, Equiv.symm_apply_apply] + +/-- **`flipWire enc k` is an involution.** Flipping bit `k` twice restores the original bit-string +(`Equiv.swap 0 1` is an involution), hence the original basis index. -/ +theorem flipWire_involutive (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) : + Function.Involutive (flipWire enc k) := by + intro i + rw [flipWire, enc_symm_flipWire, Function.update_self, Equiv.swap_apply_self, + Function.update_idem, Function.update_eq_self, Equiv.apply_symm_apply] + +/-- **The `X`-on-wire gate is the wire-`k`-flip permutation matrix.** The entry of +`singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` at `(i, a)` is `1` exactly when `a = flipWire enc k i` +(and `0` otherwise): it is the `0/1` permutation matrix of `flipWire enc k`. -/ +theorem singleQubitOnWire_swap_apply (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) (i a : Fin d) : + singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) i a + = if a = flipWire enc k i then 1 else 0 := by + rw [singleQubitOnWire_apply] + by_cases hoff : ∀ l, l ≠ k → enc.symm i l = enc.symm a l + · rw [ite_eq_left hoff, swap_apply_eq_one_row, Matrix.one_apply] + have hkey : (a = flipWire enc k i) + ↔ (Equiv.swap 0 1 (enc.symm i k) = enc.symm a k) := by + constructor + · intro ha; rw [ha, enc_symm_flipWire, Function.update_self] + · intro hP + apply enc.symm.injective + rw [enc_symm_flipWire] + funext l + rcases eq_or_ne l k with rfl | hl + · rw [Function.update_self, hP] + · rw [Function.update_of_ne hl, hoff l hl] + by_cases hP : Equiv.swap 0 1 (enc.symm i k) = enc.symm a k + · rw [ite_eq_left hP, ite_eq_left (hkey.mpr hP)] + · rw [ite_eq_right hP, ite_eq_right (fun h => hP (hkey.mp h))] + · rw [ite_eq_right hoff] + have hne : ¬ (a = flipWire enc k i) := by + intro ha + apply hoff + intro l hl + rw [ha, enc_symm_flipWire, Function.update_of_ne hl] + rw [ite_eq_right hne] + +/-- **The `X`-on-wire gate is an involution**: `Wₖ * Wₖ = 1`. It is `singleQubitOnWire enc k` +applied to the involution `Matrix.swap ℂ 0 1`, and `singleQubitOnWire enc k` is a `*`-homomorphism +on the block. -/ +theorem singleQubitOnWire_swap_mul_self (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) : + singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) = 1 := by + rw [singleQubitOnWire_mul, Matrix.swap_mul_self, singleQubitOnWire_one] + +/-- **Conjugation by the `X`-on-wire gate reindexes both matrix indices by the wire-`k` flip.** For +any `d × d` matrix `M`, `Wₖ * M * Wₖ = M.submatrix (flipWire enc k) (flipWire enc k)`, where +`Wₖ = singleQubitOnWire enc k (Matrix.swap ℂ 0 1)`. Since `Wₖ` is a `0/1` permutation matrix +(`singleQubitOnWire_swap_apply`) of the involution `flipWire enc k` (`flipWire_involutive`), +sandwiching `M` between two copies permutes its rows and columns by that flip. This is the analogue +of `swap_conj_apply` for the wire-flip permutation, and the engine behind the control-bit flip. -/ +theorem singleQubitOnWire_swap_conj (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) + (M : Matrix (Fin d) (Fin d) ℂ) : + singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) * M + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) + = M.submatrix (flipWire enc k) (flipWire enc k) := by + ext i i' + rw [Matrix.submatrix_apply, Matrix.mul_apply] + have hb0 : ∀ b ∈ (Finset.univ : Finset (Fin d)), b ≠ flipWire enc k i' → + (singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) * M) i b + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) b i' = 0 := by + intro b _ hb + have hbne : ¬ (i' = flipWire enc k b) := by + intro h; exact hb (by rw [h, flipWire_involutive]) + rw [singleQubitOnWire_swap_apply, ite_eq_right hbne, mul_zero] + rw [Finset.sum_eq_single (flipWire enc k i') hb0 (fun h => absurd (Finset.mem_univ _) h), + singleQubitOnWire_swap_apply, flipWire_involutive, ite_eq_left rfl, mul_one, Matrix.mul_apply] + have ha0 : ∀ a ∈ (Finset.univ : Finset (Fin d)), a ≠ flipWire enc k i → + singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) i a * M a (flipWire enc k i') = 0 := by + intro a _ ha + rw [singleQubitOnWire_swap_apply, ite_eq_right ha, zero_mul] + rw [Finset.sum_eq_single (flipWire enc k i) ha0 (fun h => absurd (Finset.mem_univ _) h), + singleQubitOnWire_swap_apply, ite_eq_left rfl, one_mul] + +/-- **Conjugating a controlled single-qubit gate by the `X`-on-wire gate flips its control bit.** +For a control wire `k ≠ j` (the target), +`Wₖ * ctrlSingleQubit enc j c U₀ * Wₖ = ctrlSingleQubit enc j (c[k ↦ ¬c k]) U₀`, where +`Wₖ = singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` and `c[k ↦ ¬c k]` is `c` with the value at bit +`k` negated (`Equiv.swap 0 1`). The controlled gate is unchanged except that the value control wire +`k` is conditioned on is flipped — N&C §4.3's control-pattern normalisation, one wire at a time. +Iterating over the wires where `c` is `0` brings any control pattern to all-`1` controls. -/ +theorem ctrlSingleQubit_conj_singleQubitOnWire_swap (enc : (Fin m → Fin 2) ≃ Fin d) + {j k : Fin m} (hkj : k ≠ j) (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) * ctrlSingleQubit enc j c U₀ + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) + = ctrlSingleQubit enc j (Function.update c k (Equiv.swap 0 1 (c k))) U₀ := by + rw [singleQubitOnWire_swap_conj] + ext i i' + rw [Matrix.submatrix_apply] + simp only [ctrlSingleQubit, Matrix.of_apply, enc_symm_flipWire] + have hjx : Function.update (enc.symm i) k (Equiv.swap 0 1 (enc.symm i k)) j = enc.symm i j := + Function.update_of_ne (Ne.symm hkj) _ _ + have hjx' : Function.update (enc.symm i') k (Equiv.swap 0 1 (enc.symm i' k)) j = enc.symm i' j := + Function.update_of_ne (Ne.symm hkj) _ _ + have hiff1 : (∀ l, l ≠ j → Function.update (enc.symm i) k (Equiv.swap 0 1 (enc.symm i k)) l + = Function.update (enc.symm i') k (Equiv.swap 0 1 (enc.symm i' k)) l) + ↔ (∀ l, l ≠ j → enc.symm i l = enc.symm i' l) := by + constructor + · intro h l hl + have hl' := h l hl + rcases eq_or_ne l k with rfl | hlk + · rwa [Function.update_self, Function.update_self, + (Equiv.swap (0 : Fin 2) 1).injective.eq_iff] at hl' + · rwa [Function.update_of_ne hlk, Function.update_of_ne hlk] at hl' + · intro h l hl + rcases eq_or_ne l k with rfl | hlk + · rw [Function.update_self, Function.update_self, h l hl] + · rw [Function.update_of_ne hlk, Function.update_of_ne hlk]; exact h l hl + have hiff2 : (∀ l, l ≠ j → Function.update (enc.symm i) k (Equiv.swap 0 1 (enc.symm i k)) l = c l) + ↔ (∀ l, l ≠ j → enc.symm i l = Function.update c k (Equiv.swap 0 1 (c k)) l) := by + constructor + · intro h l hl + have hl' := h l hl + rcases eq_or_ne l k with rfl | hlk + · rw [Function.update_self] at hl' + rw [Function.update_self, ← hl', Equiv.swap_apply_self] + · rw [Function.update_of_ne hlk] at hl' + rw [Function.update_of_ne hlk]; exact hl' + · intro h l hl + have hl' := h l hl + rcases eq_or_ne l k with rfl | hlk + · rw [Function.update_self] at hl' ⊢ + rw [hl', Equiv.swap_apply_self] + · rw [Function.update_of_ne hlk] at hl' ⊢ + exact hl' + rw [hjx, hjx'] + exact if_congr hiff1 (if_congr hiff2 rfl rfl) rfl + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ControlledSingleQubitNormalisation.lean b/LeanPool/AxQM/Concrete/ControlledSingleQubitNormalisation.lean new file mode 100644 index 0000000000..3141551caf --- /dev/null +++ b/LeanPool/AxQM/Concrete/ControlledSingleQubitNormalisation.lean @@ -0,0 +1,232 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.ControlledSingleQubitConjugation + +/-! +# Concrete: control-pattern normalisation, folded to all-`1` controls (N&C §4.3) + +(Nielsen & Chuang §4.3, p. 182 — the reduction of a controlled gate to single-qubit and `CNOT` +gates.) + +`Concrete/ControlledSingleQubitConjugation.lean` supplied the **one-wire** step of Nielsen & +Chuang's §4.3 control-pattern normalisation: conjugating a controlled single-qubit gate +`ctrlSingleQubit enc j c U₀` by the `X`-on-wire gate +`Wₖ = singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` (for a control wire `k ≠ j`) flips the value the +control is conditioned on, +`Wₖ * ctrlSingleQubit enc j c U₀ * Wₖ = ctrlSingleQubit enc j (c[k ↦ ¬c k]) U₀` +(`ctrlSingleQubit_conj_singleQubitOnWire_swap`). This file **folds that step over a list of wires**, +so an *arbitrary* control pattern is normalised to the all-`1` pattern by conjugation with a product +of `X`-on-wire gates — the state N&C's §4.3 reduction starts from before realising the resulting +`Cⁿ(U₀)` over `H, S, CNOT, Toffoli`. + +## The construction + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the `m`-bit strings as the `d = 2 ^ m` basis +indices. + +* `AxQM.Concrete.wireFlipProd enc L` — the product `∏ₖ Wₖ` of `X`-on-wire gates over a list + `L` of wires (head outermost). It is a product of uncontrolled single-qubit gates, hence unitary + (`wireFlipProd_mem_unitaryGroup`), and `wireFlipProd enc L * wireFlipProd enc L.reverse = 1` + (`wireFlipProd_mul_reverse`), so the reversed list gives its inverse (each `Wₖ` is an involution, + telescoping from the inside out with no need for the `Wₖ` to commute). +* `AxQM.Concrete.flipPattern L c` — the control pattern `c` with every bit listed in `L` + negated in turn. For a duplicate-free `L`, `flipPattern L c l = ¬c l` on `l ∈ L` and `c l` + elsewhere (`flipPattern_apply_of_nodup`). +* `AxQM.Concrete.wireFlipProd_conj_ctrlSingleQubit` — **the fold**: for a list `L` of wires + all distinct from the target `j`, + `wireFlipProd enc L * ctrlSingleQubit enc j c U₀ * wireFlipProd enc L.reverse + = ctrlSingleQubit enc j (flipPattern L c) U₀`, iterating the one-wire step along `L`. No + commutativity of the `Wₖ` is used — each induction step peels one `Wₖ` off each side and applies + the single-wire lemma to the conjugated remainder. +* `AxQM.Concrete.exists_wireFlipProd_conj_ctrlSingleQubit_one` — **the headline**: for any + control pattern `c`, there is a list `L` of control wires with + `ctrlSingleQubit enc j c U₀ + = wireFlipProd enc L.reverse * ctrlSingleQubit enc j 1 U₀ * wireFlipProd enc L` + — every controlled single-qubit gate is, up to conjugation by a product of `X`-on-wire gates, the + gate with **all controls conditioned on `1`** (the constant pattern `1`). `L` is taken to be the + wires `≠ j` on which `c` is `0`; folding the one-wire flip over them turns those `0`-controls into + `1`-controls, and the wires already carrying a `1`-control are left untouched. + +It is used in the §4.3 reduction of Exercise 4.43's `n`-qubit lift; the statement of +Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The product of `X`-on-wire gates over a list of wires** (head outermost): +`wireFlipProd enc [k₁, …, kₙ] = W_{k₁} ⋯ W_{kₙ}` with +`Wₖ = singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` +the `NOT` gate on wire `k`. It is the operator that conjugates a control pattern into its +normalised form. -/ +noncomputable def wireFlipProd (enc : (Fin m → Fin 2) ≃ Fin d) (L : List (Fin m)) : + Matrix (Fin d) (Fin d) ℂ := + (L.map fun k => singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1)).prod + +@[simp] theorem wireFlipProd_nil (enc : (Fin m → Fin 2) ≃ Fin d) : + wireFlipProd enc [] = 1 := rfl + +/-- `wireFlipProd` peels its first wire off the outside. -/ +theorem wireFlipProd_cons (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) (L : List (Fin m)) : + wireFlipProd enc (k :: L) + = singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) * wireFlipProd enc L := by + simp [wireFlipProd] + +/-- `wireFlipProd` on a singleton is the single `X`-on-wire gate. -/ +@[simp] theorem wireFlipProd_singleton (enc : (Fin m → Fin 2) ≃ Fin d) (k : Fin m) : + wireFlipProd enc [k] = singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) := by + simp [wireFlipProd] + +/-- `wireFlipProd` turns list concatenation into matrix multiplication. -/ +theorem wireFlipProd_append (enc : (Fin m → Fin 2) ≃ Fin d) (L₁ L₂ : List (Fin m)) : + wireFlipProd enc (L₁ ++ L₂) = wireFlipProd enc L₁ * wireFlipProd enc L₂ := by + simp [wireFlipProd, List.map_append, List.prod_append] + +/-- **The reversed list gives the inverse product**: +`wireFlipProd enc L * wireFlipProd enc L.reverse = 1`. +Proved by peeling one wire off each end and cancelling the two innermost copies of `Wₖ` +(an involution, `singleQubitOnWire_swap_mul_self`); the cancellation telescopes from the inside out, +so the `Wₖ` need not commute. -/ +theorem wireFlipProd_mul_reverse (enc : (Fin m → Fin 2) ≃ Fin d) (L : List (Fin m)) : + wireFlipProd enc L * wireFlipProd enc L.reverse = 1 := by + induction L with + | nil => simp + | cons k L ih => + rw [wireFlipProd_cons, List.reverse_cons, wireFlipProd_append, wireFlipProd_singleton, + mul_assoc, ← mul_assoc (wireFlipProd enc L), ih, one_mul, singleQubitOnWire_swap_mul_self] + +/-- **`wireFlipProd enc L` is unitary** — it is a product of the uncontrolled single-qubit gates +`Wₖ = singleQubitOnWire enc k (Matrix.swap ℂ 0 1)`, each unitary (`swapTwo_mem_unitaryGroup`). -/ +theorem wireFlipProd_mem_unitaryGroup (enc : (Fin m → Fin 2) ≃ Fin d) (L : List (Fin m)) : + wireFlipProd enc L ∈ Matrix.unitaryGroup (Fin d) ℂ := by + refine list_prod_mem ?_ + intro M hM + rw [List.mem_map] at hM + obtain ⟨k, _, rfl⟩ := hM + exact singleQubitOnWire_mem_unitaryGroup enc k swapTwo_mem_unitaryGroup + +/-- **The control pattern `c` with every bit listed in `L` negated in turn** +(`Equiv.swap 0 1`, applied one wire at a time, head first). It is the pattern +`wireFlipProd enc L` conjugates `c` into (`wireFlipProd_conj_ctrlSingleQubit`). -/ +def flipPattern (L : List (Fin m)) (c : Fin m → Fin 2) : Fin m → Fin 2 := + L.foldr (fun k c' => Function.update c' k (Equiv.swap (0 : Fin 2) 1 (c' k))) c + +@[simp] theorem flipPattern_nil (c : Fin m → Fin 2) : flipPattern [] c = c := rfl + +/-- `flipPattern` on a cons negates the head wire on top of the tail's fold. -/ +theorem flipPattern_cons (k : Fin m) (L : List (Fin m)) (c : Fin m → Fin 2) : + flipPattern (k :: L) c + = Function.update (flipPattern L c) k (Equiv.swap (0 : Fin 2) 1 (flipPattern L c k)) := rfl + +/-- **On a duplicate-free list, `flipPattern` negates exactly the listed wires.** +`flipPattern L c l = ¬c l` (i.e. `Equiv.swap 0 1 (c l)`) for `l ∈ L`, and `c l` otherwise — each +listed wire is flipped exactly once. -/ +theorem flipPattern_apply_of_nodup {L : List (Fin m)} (hL : L.Nodup) (c : Fin m → Fin 2) + (l : Fin m) : + flipPattern L c l = if l ∈ L then Equiv.swap (0 : Fin 2) 1 (c l) else c l := by + induction L with + | nil => simp + | cons k L ih => + rw [List.nodup_cons] at hL + rw [flipPattern_cons] + rcases eq_or_ne l k with rfl | hlk + · rw [Function.update_self, ih hL.2, ite_eq_right hL.1, ite_eq_left (List.mem_cons_self ..)] + · rw [Function.update_of_ne hlk, ih hL.2] + by_cases hlL : l ∈ L + · rw [ite_eq_left hlL, ite_eq_left (List.mem_cons_of_mem k hlL)] + · rw [ite_eq_right hlL, ite_eq_right (by simp [List.mem_cons, hlk, hlL])] + +/-- **`ctrlSingleQubit` depends on the control pattern only off the target wire.** If `c` and `c'` +agree on every wire `≠ j`, they give the same controlled single-qubit gate: the control condition +`∀ k ≠ j, x k = c k` reads `c` only away from `j`. -/ +theorem ctrlSingleQubit_congr (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) {c c' : Fin m → Fin 2} + (h : ∀ l, l ≠ j → c l = c' l) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + ctrlSingleQubit enc j c U₀ = ctrlSingleQubit enc j c' U₀ := by + ext i i' + simp only [ctrlSingleQubit, Matrix.of_apply] + have hc : (∀ k, k ≠ j → enc.symm i k = c k) ↔ (∀ k, k ≠ j → enc.symm i k = c' k) := + forall_congr' fun k => imp_congr_right fun hk => by rw [h k hk] + exact if_congr Iff.rfl (if_congr hc rfl rfl) rfl + +/-- **The fold of the one-wire control-bit flip along a list of control wires.** For a list `L` of +wires all distinct from the target `j`, +`wireFlipProd enc L * ctrlSingleQubit enc j c U₀ * wireFlipProd enc L.reverse + = ctrlSingleQubit enc j (flipPattern L c) U₀`: conjugating by the product of `X`-on-wire gates +negates the control values on exactly the wires of `L`. Each induction step peels one `Wₖ` off each +side and applies `ctrlSingleQubit_conj_singleQubitOnWire_swap` to the conjugated remainder, so no +commutativity of the wire gates is needed. -/ +theorem wireFlipProd_conj_ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + ∀ (L : List (Fin m)), (∀ k ∈ L, k ≠ j) → + wireFlipProd enc L * ctrlSingleQubit enc j c U₀ * wireFlipProd enc L.reverse + = ctrlSingleQubit enc j (flipPattern L c) U₀ := by + intro L + induction L with + | nil => intro _; simp + | cons k L ih => + intro hL + have hk : k ≠ j := hL k (List.mem_cons_self ..) + have hL' : ∀ k' ∈ L, k' ≠ j := fun k' hk' => hL k' (List.mem_cons_of_mem k hk') + calc wireFlipProd enc (k :: L) * ctrlSingleQubit enc j c U₀ * wireFlipProd enc (k :: L).reverse + = singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) + * (wireFlipProd enc L * ctrlSingleQubit enc j c U₀ * wireFlipProd enc L.reverse) + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) := by + rw [wireFlipProd_cons, List.reverse_cons, wireFlipProd_append, wireFlipProd_singleton] + simp only [mul_assoc] + _ = singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) + * ctrlSingleQubit enc j (flipPattern L c) U₀ + * singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1) := by rw [ih hL'] + _ = ctrlSingleQubit enc j (flipPattern (k :: L) c) U₀ := by + rw [ctrlSingleQubit_conj_singleQubitOnWire_swap enc hk, flipPattern_cons] + +/-- **Every controlled single-qubit gate normalises, up to conjugation by `X`-on-wire gates, to the +all-`1`-controlled gate** (N&C §4.3, control-pattern normalisation). For any control pattern `c` +there is a list `L` of control wires (all `≠ j`) with +`ctrlSingleQubit enc j c U₀ + = wireFlipProd enc L.reverse * ctrlSingleQubit enc j 1 U₀ * wireFlipProd enc L`, +where `1` is the constant pattern that conditions every control wire on `1`. `L` is the set of wires +`≠ j` on which `c` is `0`; folding the one-wire flip over them turns those `0`-controls into +`1`-controls while leaving the wires already carrying `1` untouched. This is the state from which +the resulting `Cⁿ(U₀)` is realised over `H, S, CNOT, Toffoli`. -/ +theorem exists_wireFlipProd_conj_ctrlSingleQubit_one (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + ∃ L : List (Fin m), (∀ k ∈ L, k ≠ j) ∧ + ctrlSingleQubit enc j c U₀ + = wireFlipProd enc L.reverse * ctrlSingleQubit enc j 1 U₀ * wireFlipProd enc L := by + set L : List (Fin m) := + (Finset.univ.filter fun l => l ≠ j ∧ c l = 0).toList with hLdef + have hmem : ∀ l, l ∈ L ↔ (l ≠ j ∧ c l = 0) := by + intro l; rw [hLdef, Finset.mem_toList, Finset.mem_filter] + exact and_iff_right (Finset.mem_univ l) + have hLne : ∀ k ∈ L, k ≠ j := fun k hk => ((hmem k).1 hk).1 + have hLnodup : L.Nodup := Finset.nodup_toList _ + have hflip : ∀ l, l ≠ j → flipPattern L c l = (1 : Fin m → Fin 2) l := by + intro l hlj + rw [flipPattern_apply_of_nodup hLnodup, Pi.one_apply] + by_cases h0 : c l = 0 + · rw [ite_eq_left ((hmem l).2 ⟨hlj, h0⟩), h0, Equiv.swap_apply_left] + · rw [ite_eq_right (fun hl => h0 ((hmem l).1 hl).2)] + omega + have key : wireFlipProd enc L * ctrlSingleQubit enc j c U₀ * wireFlipProd enc L.reverse + = ctrlSingleQubit enc j 1 U₀ := by + rw [wireFlipProd_conj_ctrlSingleQubit enc j c U₀ L hLne, ctrlSingleQubit_congr enc j hflip U₀] + have hBA : wireFlipProd enc L.reverse * wireFlipProd enc L = 1 := by + have h := wireFlipProd_mul_reverse enc L.reverse + rwa [List.reverse_reverse] at h + refine ⟨L, hLne, ?_⟩ + rw [← key]; simp only [mul_assoc]; rw [hBA, mul_one, ← mul_assoc, hBA, one_mul] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/DensityMatrixRealDimension.lean b/LeanPool/AxQM/Concrete/DensityMatrixRealDimension.lean new file mode 100644 index 0000000000..de062d258b --- /dev/null +++ b/LeanPool/AxQM/Concrete/DensityMatrixRealDimension.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Algebra.Star.Module +public import Mathlib.LinearAlgebra.Complex.Module +public import Mathlib.LinearAlgebra.Complex.FiniteDimensional +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SelfAdjointFinrank +public import LeanPool.AxQM.ToMathlib.Analysis.Matrix.HilbertSchmidt +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Trace +public import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas +public import Mathlib.LinearAlgebra.Dimension.Constructions + +/-! +# Concrete: real-parameter count of an `n`-qubit density matrix (N&C Ex 4.46) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 4.46 (p. 205): + +An n-qubit density matrix is described by 4ⁿ − 1 independent real parameters. + +This is a **linear-algebra parameter count**. The statement of Exercise 4.46 is in +[upstream `AxQM/NC/Ch4/Exercise4_46.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_46.lean). + +## The argument + +A density matrix on the `d`-dimensional space `ℂ^d` (`d = 2ⁿ` for `n` qubits) is a `d × d` +**Hermitian** matrix that is additionally positive semidefinite and has unit trace. Counting +the *real* degrees of freedom: + +* The real vector space of Hermitian `d × d` complex matrices, + `selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ)`, has real dimension `d²` + (`finrank_selfAdjoint_matrix`) — the matrix special case of the general lemma + `finrank_real_selfAdjoint`, that the self-adjoint elements of a finite-dimensional complex + star module have real dimension equal to its complex dimension. +* Unit trace is **one** real linear constraint: the trace of a Hermitian matrix is real, giving + a surjective real-linear functional `realTraceOnSelfAdjoint` onto `ℝ`. Its kernel — the + *traceless* Hermitian matrices, i.e. the "generalized Bloch vector" space + `tracelessSelfAdjoint` — therefore has real dimension `d² − 1` + (`finrank_tracelessSelfAdjoint_matrix`, via rank–nullity). Positive semidefiniteness is an + open (inequality) condition and does not lower the count; a density matrix is `ρ = I/d + T` + with `T` a free traceless Hermitian matrix. + +Specialising to `d = 2ⁿ` gives `d² = 4ⁿ` and the exercise's `4ⁿ − 1` +(`finrank_tracelessSelfAdjoint_matrix_two_pow`). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +noncomputable section + +/-- **The real dimension of the Hermitian `d × d` matrices is `d²`.** + +The matrix special case of `finrank_real_selfAdjoint` — the real dimension of the self-adjoint +elements of a finite-dimensional complex star module equals its complex dimension — applied to +`A = Matrix (Fin d) (Fin d) ℂ`, whose complex dimension is `d²` (`Matrix.finrank_eq_card_sq`). For +`n` qubits (`d = 2ⁿ`) this is the `4ⁿ` real parameters of a general Hermitian matrix; the unit-trace +constraint removes one (see `finrank_tracelessSelfAdjoint_matrix`). -/ +theorem finrank_selfAdjoint_matrix (d : ℕ) : + Module.finrank ℝ (selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ)) = d ^ 2 := by + -- `selfAdjoint.submodule ℝ A` and `selfAdjoint A` share a defeq carrier, so the general lemma + -- closes it once the complex dimension `finrank ℂ (Matrix (Fin d) (Fin d) ℂ) = d²` is rewritten + have h := finrank_real_selfAdjoint (Matrix (Fin d) (Fin d) ℂ) + rw [Matrix.finrank_eq_card_sq, Fintype.card_fin] at h + exact h + +/-- The (real) trace as a real-linear functional on the Hermitian matrices, `s ↦ Re (tr s)`. +Since a Hermitian matrix has real trace this records the full trace, and unit trace is the single +linear constraint `realTraceOnSelfAdjoint = 1` cutting density matrices out of the Hermitian +matrices. -/ +def realTraceOnSelfAdjoint (d : ℕ) : + selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ) →ₗ[ℝ] ℝ := + Complex.reLm ∘ₗ (Matrix.traceLinearMap (Fin d) ℝ ℂ) ∘ₗ + (selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ)).subtype + +/-- The **traceless Hermitian** `d × d` matrices: the kernel of the real trace functional on the +Hermitian matrices. This is the "generalized Bloch vector" space — a density matrix is +`ρ = I/d + T` for a unique `T` in this space, so it parametrizes the density matrices. -/ +def tracelessSelfAdjoint (d : ℕ) : + Submodule ℝ (selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ)) := + LinearMap.ker (realTraceOnSelfAdjoint d) + +/-- The real trace functional on the Hermitian matrices is surjective (for `d ≠ 0`): the identity +is Hermitian with trace `d ≠ 0`, and scaling it hits every real value. -/ +theorem realTraceOnSelfAdjoint_surjective (d : ℕ) [NeZero d] : + Function.Surjective (realTraceOnSelfAdjoint d) := by + have hone : (1 : Matrix (Fin d) (Fin d) ℂ) ∈ + selfAdjoint.submodule ℝ (Matrix (Fin d) (Fin d) ℂ) := + selfAdjoint.mem_iff.mpr (star_one _) + have hval : realTraceOnSelfAdjoint d ⟨1, hone⟩ = (d : ℝ) := by + simp [realTraceOnSelfAdjoint, Matrix.trace_one, Fintype.card_fin] + have hd : (d : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne d) + intro t + exact ⟨(t / (d : ℝ)) • ⟨1, hone⟩, by rw [map_smul, hval, smul_eq_mul, div_mul_cancel₀ t hd]⟩ + +/-- **The real dimension of the traceless Hermitian `d × d` matrices is `d² − 1`** (for `d ≠ 0`). +By rank–nullity applied to the surjective real trace functional on the `d²`-dimensional Hermitian +matrices: one real constraint removes one dimension. -/ +theorem finrank_tracelessSelfAdjoint_matrix (d : ℕ) [NeZero d] : + Module.finrank ℝ (tracelessSelfAdjoint d) = d ^ 2 - 1 := by + have : Module.Finite ℝ (Matrix (Fin d) (Fin d) ℂ) := + Module.Finite.trans ℂ (Matrix (Fin d) (Fin d) ℂ) + have hrn := (realTraceOnSelfAdjoint d).finrank_range_add_finrank_ker + rw [LinearMap.range_eq_top.mpr (realTraceOnSelfAdjoint_surjective d), finrank_top, + Module.finrank_self, finrank_selfAdjoint_matrix] at hrn + rw [tracelessSelfAdjoint] + omega + +/-- `(2ⁿ)² = 4ⁿ`. -/ +theorem two_pow_sq (n : ℕ) : (2 ^ n) ^ 2 = 4 ^ n := by + rw [← pow_mul, mul_comm, pow_mul]; norm_num + +/-- **`n`-qubit specialization: the Hermitian `2ⁿ × 2ⁿ` matrices have real dimension `4ⁿ`.** -/ +theorem finrank_selfAdjoint_matrix_two_pow (n : ℕ) : + Module.finrank ℝ (selfAdjoint.submodule ℝ (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ)) = 4 ^ n := by + rw [finrank_selfAdjoint_matrix, two_pow_sq] + +/-- **Nielsen & Chuang, Exercise 4.46.** Describing an `n`-qubit density matrix requires `4ⁿ − 1` +independent real numbers: the traceless Hermitian `2ⁿ × 2ⁿ` matrices — the parameter space of +`n`-qubit density matrices — have real dimension `4ⁿ − 1`. -/ +theorem finrank_tracelessSelfAdjoint_matrix_two_pow (n : ℕ) : + Module.finrank ℝ (tracelessSelfAdjoint (2 ^ n)) = 4 ^ n - 1 := by + rw [finrank_tracelessSelfAdjoint_matrix, two_pow_sq] + +end + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/FourGateUniversality.lean b/LeanPool/AxQM/Concrete/FourGateUniversality.lean new file mode 100644 index 0000000000..ba0e425c61 --- /dev/null +++ b/LeanPool/AxQM/Concrete/FourGateUniversality.lean @@ -0,0 +1,135 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.ReachableCircuits + +/-! +# `H, S, CNOT, Toffoli` are universal: every unitary is a limit of reachable circuits (up to phase) + +*(N&C Exercise 4.43 — the universality conclusion.)* + +This file assembles the §4.5/§4.3 development into Nielsen & Chuang's Exercise 4.43 +conclusion: the Hadamard, phase, controlled-`NOT` and Toffoli gates are **universal for quantum +computation** — every unitary on an `m`-qubit register is approximated, to arbitrary accuracy and up +to an (unobservable) global phase, by a circuit built from those four gates. + +## The reachable circuit set + +The elementary gates the §4.5/§4.3 decomposition bottoms out in — and which the four-gate set +realises — are collected into the **reachable gate set** `reachableGateSet enc θ`: + +* the `≤ 2`-control reversible gates `IsToffoliPermGate enc G` (`Toffoli`/`CNOT`/`NOT`), realised + *exactly* by the four-gate set (`CNOT`, `Toffoli` are members; `NOT = H S² H`); +* the uncontrolled single-qubit gates on a wire `singleQubitOnWire enc j g` whose `2 × 2` block `g` + is a **reachable rotation** (`g ∈ reachableRotations θ` — a finite product of `R_z(±θ), R_x(±θ)`), + realised by the Exercise 4.41 circuit for `R_z(θ)` (`cos θ = 3/5`) and Hadamard conjugation for + `R_x(θ)`. + +`reachableCircuits enc θ` is the submonoid these generate — the exact matrix incarnation of "the +circuits assembled from the four gates" (their finite products). + +## The universality theorem + +* `exists_phase_smul_mem_closure_reachableCircuits` — **the headline**: for the reachability angle + `θ` (`cos θ = 3/5`), an encoding `enc : (Fin m → Fin 2) ≃ Fin d` with at least one qubit + (`Nontrivial (Fin m → Fin 2)`), and *any* `U ∈ U(d)`, some global phase `e^{iα}` makes + `e^{iα} • U` lie in the topological closure of `reachableCircuits enc θ`. Because the ambient + topology on `Matrix (Fin d) (Fin d) ℂ` is the (finite-dimensional) product topology — where + closure means entrywise, equivalently operator-norm, approximation — this says exactly that the + reachable circuits are **dense in `U(d)` up to a global phase**: the universality of + `H, S, CNOT, Toffoli`. (States are rays, so the residual global phase is physically irrelevant; it + is genuinely global — not a relative phase — precisely because the §4.3 reduction placed the + single-qubit gates on *uncontrolled* wires, `singleQubitOnWire_smul`.) + +The headline is a one-line instantiation of the **generic** reachable-circuit density +`exists_phase_smul_mem_closure_reachableCircuitsOf` (`Concrete/ReachableCircuits.lean`), which is +the shared §4.5/§4.3 assembly parameterised over an abstract single-qubit gate set `S` (here +`S = reachableRotations θ`, so `reachableCircuits enc θ` is +`reachableCircuitsOf enc ↑(reachableRotations θ)` definitionally). The four-gate-specific input is +just the per-wire single-qubit density +`exists_phase_smul_singleQubitOnWire_mem_closure` (N&C's single-qubit density, eq. 4.81, +`cos θ = 3/5`). The generic assembly chains three pieces: + +1. the *exact* decomposition `exists_isToffoliOrSingleQubit_list_prod_eq` writes `U = gates.prod` + with every factor an `IsToffoliOrSingleQubitGate` (a terminal gate); +2. each terminal gate is, up to a phase, a limit of reachable circuits: a `Toffoli`/`CNOT`/`NOT` is + *exactly* a generator (phase `0`); a single-qubit wire gate is a limit of `singleQubitOnWire` + applied to `S`, up to a global phase (the supplied density hypothesis); +3. the per-gate approximations multiply up: the closure of a submonoid is again a submonoid + (`Submonoid.topologicalClosure`, matrix multiplication being continuous), so a product of + limits-of-circuits is a limit of circuits, and the individual phases combine into one global + phase `e^{iΣαⱼ}` (`smul_mul_smul_comm`, `Complex.exp_add`). + +## Design: density, not a re-derived error budget + +The statement is the topological density `∈ closure` rather than an explicit `∀ ε, ∃ V, ‖·‖ < ε` +bound. In the fixed finite dimension the two are equivalent (`Matrix` carries the product topology +and no ambient norm), and `∈ closure` is the Mathlib-idiomatic way to state density. N&C's +quantitative §4.5.3 error budget (eq. 4.63, "total error ≤ sum of per-gate errors") is formalised +independently as the general chaining inequality `norm_listProd_sub_listProd_le`; it is the accuracy +calculus behind step 3's convergence but is not re-invoked here, since the submonoid-closure route +delivers the density conclusion directly. + +The link "`reachableGateSet enc θ` is exactly what `H, S, CNOT, Toffoli` realise" is carried by the +description of the reachable gate set above and the already-grounded circuit +`rzThreeFifthsCircuit` (Exercise 4.41); +this file, like the rest of the matrix-level §4.5/§4.3 development, stays a faithful *reformulation* +over the encoded-basis matrix gates rather than re-bridging each gate to its `Evolution`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The reachable gate set.** The elementary matrix gates the §4.5/§4.3 universality reduction +bottoms out in, which the `H, S, CNOT, Toffoli` set realises: the `≤ 2`-control reversible gates +(`IsToffoliPermGate` — `Toffoli`/`CNOT`/`NOT`) together with, on every wire `j`, the uncontrolled +single-qubit gates `singleQubitOnWire enc j g` whose block `g` is a reachable rotation +(`g ∈ reachableRotations θ`). -/ +noncomputable def reachableGateSet (enc : (Fin m → Fin 2) ≃ Fin d) (θ : ℝ) : + Set (Matrix (Fin d) (Fin d) ℂ) := + {G | IsToffoliPermGate enc G} ∪ + ⋃ j : Fin m, + singleQubitOnWire enc j '' (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) + +/-- **The reachable circuits.** The submonoid of `Matrix (Fin d) (Fin d) ℂ` generated by the +reachable gate set — the finite products of reachable gates, i.e. the matrix incarnation of the +circuits assembled from `H, S, CNOT, Toffoli`. Universality is the statement that its topological +closure fills `U(d)` up to a global phase (`exists_phase_smul_mem_closure_reachableCircuits`). -/ +noncomputable def reachableCircuits (enc : (Fin m → Fin 2) ≃ Fin d) (θ : ℝ) : + Submonoid (Matrix (Fin d) (Fin d) ℂ) := + Submonoid.closure (reachableGateSet enc θ) + +/-- **Universality of `H, S, CNOT, Toffoli`** (N&C Exercise 4.43). For the reachability angle `θ` +(`cos θ = 3/5`), an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of an `m`-qubit register with at least +one qubit, and *any* unitary `U ∈ U(d)`, some global phase `e^{iα}` makes `e^{iα} • U` a limit of +reachable circuits: `e^{iα} • U ∈ closure ↑(reachableCircuits enc θ)`. + +In the finite-dimensional product topology on `Matrix (Fin d) (Fin d) ℂ`, closure is approximation +to arbitrary accuracy, so this is exactly: **the circuits built from `H, S, CNOT, Toffoli` are dense +in `U(d)` up to an (unobservable) global phase**. A one-line instantiation of the generic +reachable-circuit density `exists_phase_smul_mem_closure_reachableCircuitsOf` +(`Concrete/ReachableCircuits.lean`) — the shared §4.5/§4.3 assembly (decompose into terminal gates +via `exists_isToffoliOrSingleQubit_list_prod_eq`, approximate each up to a phase, combine the +phases) — at the four-gate-specific single-qubit density +`exists_phase_smul_singleQubitOnWire_mem_closure` (N&C eq. 4.81, `cos θ = 3/5`). -/ +theorem exists_phase_smul_mem_closure_reachableCircuits [Nontrivial (Fin m → Fin 2)] + {θ : ℝ} (hθ : Real.cos θ = 3 / 5) (enc : (Fin m → Fin 2) ≃ Fin d) + {U : Matrix (Fin d) (Fin d) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + ∃ α : ℝ, Complex.exp ((α : ℂ) * Complex.I) • U + ∈ closure (↑(reachableCircuits enc θ) : Set (Matrix (Fin d) (Fin d) ℂ)) := + exists_phase_smul_mem_closure_reachableCircuitsOf enc + (exists_phase_smul_singleQubitOnWire_mem_closure hθ enc) hU + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/GivensRotation.lean b/LeanPool/AxQM/Concrete/GivensRotation.lean new file mode 100644 index 0000000000..262a425c72 --- /dev/null +++ b/LeanPool/AxQM/Concrete/GivensRotation.lean @@ -0,0 +1,152 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Notation +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import Mathlib.Basic.Complex.Basic +public import LeanPool.AxQM.ToMathlib.Data.Real.Sqrt +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Data.Matrix.Mul + +/-! +# Concrete: the 2×2 Givens rotation clearing a column entry (N&C eq. 4.45) + +The two-level decomposition of an arbitrary `d × d` unitary (Nielsen & Chuang §4.5.1, p. 189) is +built from a sequence of *two-level* unitaries `U₁, U₂, …` chosen so that `Uₖ ⋯ U₁ U` has its first +column equal to `e₀`. Each `Uₖ` is obtained by embedding, into a chosen `{p, q}` coordinate pair, a +single `2 × 2` unitary — the **Givens rotation** of N&C eq. (4.45) — that zeros the second entry of +the length-two column `(a, b)` it acts on. This file provides that atomic `2 × 2` building block, +independently of the `d × d` embedding and the column-clearing induction. + +## The construction + +For a column `(a, b) : ℂ²` write `r = givensNorm a b = √(|a|² + |b|²)` for its Euclidean length. +Following N&C eq. (4.45), when `(a, b) ≠ 0` set + +``` + givensRotation a b = r⁻¹ • !![conj a, conj b; b, -a], +``` + +and `givensRotation a b = 1` when `a = b = 0` (the degenerate case, where there is nothing to +clear; N&C's own `U₁ = I` branch of eq. (4.44)). Two facts make it the required clearing step: + +* `givensRotation_mem_unitaryGroup` — it is unitary. In the non-degenerate branch + `Gᴴ G = r⁻² • (Mᴴ M) = r⁻² • (r² • 1) = 1`, since `Mᴴ M = (|a|² + |b|²) • 1 = r² • 1`. +* `givensRotation_mulVec` — it clears the column: `G *ᵥ ![a, b] = ![r, 0]`. The first entry is + `r⁻¹ · (conj a · a + conj b · b) = r⁻¹ · (|a|² + |b|²) = r⁻¹ · r² = r`; the second is + `r⁻¹ · (b · a − a · b) = 0`. This holds in *all* cases, including `a = b = 0` (both sides are + `![0, 0]`, as `r = 0` there). + +## Use + +This is a shared building block for the §4.5.1 development (used by Exercise 4.43's `n`-qubit lift +and reusable by Exercises 4.37 and 4.38). The statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- The Euclidean length `√(|a|² + |b|²)` of the column `(a, b) : ℂ²`; the normalising scalar of the +Givens rotation `givensRotation a b`. -/ +noncomputable def givensNorm (a b : ℂ) : ℝ := + Real.sqrt (Complex.normSq a + Complex.normSq b) + +/-- `givensNorm` is nonnegative (a square root). -/ +theorem givensNorm_nonneg (a b : ℂ) : 0 ≤ givensNorm a b := Real.sqrt_nonneg _ + +/-- The square of `givensNorm` recovers the sum of squared moduli: `r² = |a|² + |b|²`. -/ +theorem givensNorm_sq (a b : ℂ) : + givensNorm a b ^ 2 = Complex.normSq a + Complex.normSq b := + Real.sq_sqrt (add_nonneg (Complex.normSq_nonneg a) (Complex.normSq_nonneg b)) + +/-- `givensNorm` vanishes only in the degenerate case: if `(a, b) ≠ 0` then `r ≠ 0`. -/ +theorem givensNorm_ne_zero {a b : ℂ} (h : ¬(a = 0 ∧ b = 0)) : givensNorm a b ≠ 0 := by + rw [givensNorm, Real.sqrt_ne_zero'] + rcases not_and_or.mp h with ha | hb + · have h1 := Complex.normSq_pos.mpr ha + have h2 := Complex.normSq_nonneg b + linarith + · have h1 := Complex.normSq_pos.mpr hb + have h2 := Complex.normSq_nonneg a + linarith + +/-- The complex-cast form of `givensNorm_sq`: `(r : ℂ)² = |a|² + |b|²`. -/ +theorem givensNorm_sq_complex (a b : ℂ) : + (givensNorm a b : ℂ) ^ 2 = (Complex.normSq a : ℂ) + (Complex.normSq b : ℂ) := by + rw [← Complex.ofReal_pow, givensNorm_sq]; push_cast; ring + +/-- **The Givens rotation of Nielsen & Chuang eq. (4.45).** The `2 × 2` unitary that clears the +second entry of the column `(a, b)`: for `(a, b) ≠ 0` it is `r⁻¹ • !![conj a, conj b; b, -a]` (with +`r = givensNorm a b`), and the identity in the degenerate case `a = b = 0`. -/ +noncomputable def givensRotation (a b : ℂ) : Matrix (Fin 2) (Fin 2) ℂ := + if a = 0 ∧ b = 0 then 1 + else (givensNorm a b : ℂ)⁻¹ • !![starRingEnd ℂ a, starRingEnd ℂ b; b, -a] + +/-- The core `2 × 2` product identity behind unitarity: `Mᴴ M = (|a|² + |b|²) • 1`, where +`M = !![conj a, conj b; b, -a]` is the unnormalised Givens block. -/ +theorem givensBlock_conjTranspose_mul_self (a b : ℂ) : + (!![starRingEnd ℂ a, starRingEnd ℂ b; b, -a] : Matrix (Fin 2) (Fin 2) ℂ)ᴴ * + !![starRingEnd ℂ a, starRingEnd ℂ b; b, -a] + = ((Complex.normSq a : ℂ) + Complex.normSq b) • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_two, Matrix.conjTranspose_apply, Matrix.smul_apply, + ← Complex.normSq_eq_conj_mul_self] <;> ring + +/-- **The Givens rotation is unitary.** In the non-degenerate branch, +`Gᴴ G = r⁻² • (Mᴴ M) = r⁻² • (r² • 1) = 1`. -/ +theorem givensRotation_mem_unitaryGroup (a b : ℂ) : + givensRotation a b ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + rw [Matrix.mem_unitaryGroup_iff'] + by_cases h : a = 0 ∧ b = 0 + · rw [givensRotation, ite_eq_left h]; simp + · have hr : (givensNorm a b : ℂ) ≠ 0 := by exact_mod_cast givensNorm_ne_zero h + have key : (givensNorm a b : ℂ)⁻¹ * (givensNorm a b : ℂ)⁻¹ * + ((Complex.normSq a : ℂ) + Complex.normSq b) = 1 := by + rw [← givensNorm_sq_complex]; field_simp + have hstar : star ((givensNorm a b : ℂ)⁻¹) = (givensNorm a b : ℂ)⁻¹ := by simp + rw [givensRotation, ite_eq_right h, Matrix.star_eq_conjTranspose, Matrix.conjTranspose_smul, + Matrix.smul_mul, Matrix.mul_smul, givensBlock_conjTranspose_mul_self, smul_smul, smul_smul, + hstar, key, one_smul] + +/-- **The Givens rotation clears the column.** `givensRotation a b *ᵥ ![a, b] = ![r, 0]` with +`r = givensNorm a b`: the second component is zeroed and the first becomes the column's length. This +holds in all cases (in the degenerate `a = b = 0` case both sides are `![0, 0]`). -/ +theorem givensRotation_mulVec (a b : ℂ) : + givensRotation a b *ᵥ ![a, b] = ![(givensNorm a b : ℂ), 0] := by + by_cases h : a = 0 ∧ b = 0 + · obtain ⟨ha, hb⟩ := h + subst ha; subst hb + funext i; fin_cases i <;> simp [givensRotation, givensNorm] + · have hr : (givensNorm a b : ℂ) ≠ 0 := by exact_mod_cast givensNorm_ne_zero h + have hMv : (!![starRingEnd ℂ a, starRingEnd ℂ b; b, -a] : Matrix (Fin 2) (Fin 2) ℂ) *ᵥ ![a, b] + = ![(Complex.normSq a : ℂ) + Complex.normSq b, 0] := by + funext i + fin_cases i <;> + simp [Matrix.mulVec, dotProduct, Fin.sum_univ_two, ← Complex.normSq_eq_conj_mul_self] + ring + rw [givensRotation, ite_eq_right h, Matrix.smul_mulVec, hMv, ← givensNorm_sq_complex] + funext i + fin_cases i <;> simp [pow_two, inv_mul_cancel_left₀ hr] + +/-- **The Givens clearing identity as a scalar equation.** Applying `givensRotation a b` to the +column `(a, b)` zeroes the second component: `givensRotation a b 1 0 * a + givensRotation a b 1 1 * +b = 0`. Extracted from `givensRotation_mulVec` (its second output component), this is the arithmetic +behind zeroing one entry in the column-clearing step of §4.5.1. -/ +theorem givensRotation_row_one_dotProduct (a b : ℂ) : + givensRotation a b 1 0 * a + givensRotation a b 1 1 * b = 0 := by + have h := congrFun (givensRotation_mulVec a b) 1 + simpa [Matrix.mulVec, dotProduct, Fin.sum_univ_two] using h + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/GrayCode.lean b/LeanPool/AxQM/Concrete/GrayCode.lean new file mode 100644 index 0000000000..ab7ee45f4d --- /dev/null +++ b/LeanPool/AxQM/Concrete/GrayCode.lean @@ -0,0 +1,341 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Data.List.Chain +public import Mathlib.Data.Finset.Card +public import Mathlib.Data.Fintype.Card +public import Mathlib.Logic.Function.Basic + +/-! +# Concrete: a Gray code connecting two bit-strings (N&C §4.5.2) + +Nielsen & Chuang §4.5.2 (p. 191) reduces an arbitrary two-level unitary on `n` qubits — one acting +non-trivially only on the two computational basis states `|s⟩` and `|t⟩` — to single-qubit and +`CNOT` gates using a **Gray code** connecting `s` and `t`: a sequence of bit-strings starting at `s` +and ending at `t` in which *adjacent members differ in exactly one bit*. Each one-bit step is then a +controlled bit-flip (a multiply-controlled `NOT`, conditional on the other wires), so the code +prescribes the swap circuit that shuffles `|s⟩` adjacent to `|t⟩`, after which a single +controlled-`U₀` acts and the swaps are undone. + +This file provides that purely combinatorial ingredient, independently of the circuit realisation. +For two bit-strings `s t : Fin m → Fin 2` it builds `grayCode s t`, the path that +flips, one at a time, exactly the coordinates on which `s` and `t` disagree. + +## The construction + +`grayPath t s L` walks from `s`, rewriting the coordinates listed in `L` to their `t`-values one at +a time (`List.scanl`-style, but by explicit recursion so the induction unfolds cleanly): + +``` + grayPath t s [] = [s] + grayPath t s (i :: L) = s :: grayPath t (Function.update s i (t i)) L. +``` + +The two facts that make it a Gray code, when `L` is duplicate-free and lists coordinates on which +`s` and `t` genuinely differ: + +* `grayPath_isChain_differsInOneBit` — consecutive entries differ in exactly one coordinate + (`differsInOneBit`), namely the one flipped at that step. `L.Nodup` and `s i ≠ t i` are needed: a + coordinate is still at its `s`-value when its step happens (so the value really changes there), + and only that coordinate is touched. +* `grayPath_getLast?` — the last entry equals `t` on the coordinates in `L` and `s` elsewhere. + +`grayCode s t := grayPath t s (differing coordinates)` then starts at `s` (`grayCode_head?`), ends +at `t` (`grayCode_getLast?`), has consecutive entries differing in one bit (`grayCode_isChain`), and +length `≤ m + 1` (`grayCode_length_le`, since `s` and `t` differ in at most `m` of `m` coordinates — +N&C's "`m ≤ n + 1`"). It is moreover a **simple** path — duplicate-free (`grayCode_nodup`, via the +invariant `grayPath_apply_eq_of_not_mem` feeding `grayPath_nodup`) — so its endpoint `t` occurs +only as the last entry: `t ∉ (grayCode s t).dropLast` (`grayCode_getLast_not_mem_dropLast`). That +"`t` off the initial segment" fact is precisely the hypothesis the §4.5.2 swap chain consumes to +keep `|t⟩` fixed while it relocates the active pair `{s, t}` onto two adjacent Gray-code words. + +## Use + +Everything here is decidable `Fin 2` / `Finset` / `List` combinatorics on bit-strings +`Fin m → Fin 2`. It is the shared foundation of the §4.5.2 two-level → single-qubit + `CNOT` +reduction used by Exercise 4.43's `n`-qubit lift. The statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-- Two bit-strings `a`, `b : Fin m → Fin 2` **differ in exactly one bit**: there is a single +coordinate `i` at which they disagree, and they agree everywhere else. This is the adjacency +relation of a Gray code; the distinguished coordinate `i` is where the corresponding controlled +bit-flip acts. -/ +def differsInOneBit (a b : Fin m → Fin 2) : Prop := + ∃ i : Fin m, a i ≠ b i ∧ ∀ j : Fin m, j ≠ i → a j = b j + +/-- The Gray-code path from `s`, flipping each coordinate listed in `L` to its `t`-value in turn. +Built by explicit recursion so its induction unfolds definitionally. See the module docstring. -/ +def grayPath (t : Fin m → Fin 2) : (Fin m → Fin 2) → List (Fin m) → List (Fin m → Fin 2) + | s, [] => [s] + | s, i :: L => s :: grayPath t (Function.update s i (t i)) L + +@[simp] theorem grayPath_nil (t s : Fin m → Fin 2) : grayPath t s [] = [s] := rfl + +theorem grayPath_cons (t s : Fin m → Fin 2) (i : Fin m) (L : List (Fin m)) : + grayPath t s (i :: L) = s :: grayPath t (Function.update s i (t i)) L := rfl + +/-- A Gray-code path is never empty (it always begins with its start point). -/ +theorem grayPath_ne_nil (t s : Fin m → Fin 2) (L : List (Fin m)) : grayPath t s L ≠ [] := by + cases L with + | nil => simp + | cons i L => simp [grayPath_cons] + +/-- A Gray-code path begins at its start point `s`. -/ +@[simp] theorem grayPath_head? (t s : Fin m → Fin 2) (L : List (Fin m)) : + (grayPath t s L).head? = some s := by + cases L with + | nil => rfl + | cons i L => rfl + +/-- A Gray-code path over `L` has `L.length + 1` entries. -/ +@[simp] theorem grayPath_length (t s : Fin m → Fin 2) (L : List (Fin m)) : + (grayPath t s L).length = L.length + 1 := by + induction L generalizing s with + | nil => rfl + | cons i L ih => simp [grayPath_cons, ih] + +/-- The final entry of a Gray-code path equals `t` on the flipped coordinates `L` and `s` +elsewhere. Stated via `getLast?` to avoid a nonemptiness side condition. -/ +theorem grayPath_getLast? (t : Fin m → Fin 2) : + ∀ (s : Fin m → Fin 2) (L : List (Fin m)), + (grayPath t s L).getLast? = some (fun x => if x ∈ L then t x else s x) := by + intro s L + induction L generalizing s with + | nil => simp + | cons i L ih => + rw [grayPath_cons, List.getLast?_cons_of_ne_nil (grayPath_ne_nil _ _ _), ih] + congr 1 + funext x + by_cases hxi : x = i <;> by_cases hxL : x ∈ L <;> + simp [List.mem_cons, hxi, hxL] + +/-- **Adjacent Gray-code words differ in exactly one bit.** When `L` is duplicate-free and lists +coordinates on which `s` and `t` disagree, consecutive entries of `grayPath t s L` differ in exactly +one coordinate — the one flipped at that step. -/ +theorem grayPath_isChain_differsInOneBit (t : Fin m → Fin 2) : + ∀ (s : Fin m → Fin 2) (L : List (Fin m)), L.Nodup → (∀ i ∈ L, s i ≠ t i) → + List.IsChain differsInOneBit (grayPath t s L) := by + intro s L + induction L generalizing s with + | nil => intro _ _; exact List.isChain_singleton s + | cons i L ih => + intro hnd hdiff + have hiL : i ∉ L := (List.nodup_cons.mp hnd).1 + rw [grayPath_cons, List.isChain_cons] + refine ⟨?_, ?_⟩ + · -- the first step `s → Function.update s i (t i)` differs exactly at `i` + intro y hy + rw [grayPath_head?, Option.mem_some_iff] at hy + subst hy + refine ⟨i, ?_, ?_⟩ + · simpa using hdiff i (by simp) + · intro j hj + rw [Function.update_apply, ite_eq_right hj] + · -- the remaining steps, by the induction hypothesis on the updated start point + apply ih + · exact (List.nodup_cons.mp hnd).2 + · intro k hk + have hki : k ≠ i := fun h => hiL (h ▸ hk) + rw [Function.update_apply, ite_eq_right hki] + exact hdiff k (by simp [hk]) + +/-- **Every entry of a Gray-code path agrees with the start point off the flipped coordinates.** For +`x ∈ grayPath t s L` and a coordinate `j ∉ L`, `x j = s j` — only the coordinates listed in `L` are +ever touched. The key invariant behind `grayPath_nodup`: a coordinate not yet (or never) flipped +still holds its `s`-value. -/ +theorem grayPath_apply_eq_of_not_mem (t : Fin m → Fin 2) : + ∀ {s : Fin m → Fin 2} {L : List (Fin m)} {x : Fin m → Fin 2}, x ∈ grayPath t s L → + ∀ {j : Fin m}, j ∉ L → x j = s j := by + intro s L + induction L generalizing s with + | nil => intro x hx j _; rw [grayPath_nil, List.mem_singleton] at hx; rw [hx] + | cons i L ih => + intro x hx j hj + rw [grayPath_cons, List.mem_cons] at hx + rw [List.mem_cons, not_or] at hj + obtain ⟨hji, hjL⟩ := hj + rcases hx with h | h + · rw [h] + · rw [ih h hjL, Function.update_apply, ite_eq_right hji] + +/-- **A Gray-code path has no repeated entries** when `L` is duplicate-free and lists coordinates on +which `s` and `t` genuinely differ. Two entries differ on the coordinates flipped between them, a +nonempty set (each listed coordinate really changes value, by `s i ≠ t i`), so no entry recurs. +Proved by induction: the head `s` differs from every tail entry at the just-flipped coordinate `i` +(which the tail leaves at its `t`-value, via `grayPath_apply_eq_of_not_mem` since `i ∉ L`), and the +tail is duplicate-free by the inductive hypothesis. -/ +theorem grayPath_nodup (t : Fin m → Fin 2) : + ∀ {s : Fin m → Fin 2} {L : List (Fin m)}, L.Nodup → (∀ i ∈ L, s i ≠ t i) → + (grayPath t s L).Nodup := by + intro s L + induction L generalizing s with + | nil => intro _ _; rw [grayPath_nil]; exact List.nodup_singleton s + | cons i L ih => + intro hnd hdiff + have hiL : i ∉ L := (List.nodup_cons.mp hnd).1 + rw [grayPath_cons, List.nodup_cons] + refine ⟨?_, ?_⟩ + · -- the head `s` is not among the tail entries: they all hold `t i` at coordinate `i`, + -- while `s i ≠ t i` + intro hs + have hval : s i = (Function.update s i (t i)) i := + grayPath_apply_eq_of_not_mem t hs (j := i) hiL + rw [Function.update_apply, ite_eq_left rfl] at hval + exact hdiff i (by simp) hval + · -- the tail is duplicate-free by the induction hypothesis on the updated start point + apply ih + · exact (List.nodup_cons.mp hnd).2 + · intro k hk + have hki : k ≠ i := fun h => hiL (h ▸ hk) + rw [Function.update_apply, ite_eq_right hki] + exact hdiff k (by simp [hk]) + +/-- The Gray code connecting two bit-strings `s`, `t : Fin m → Fin 2`: the path flipping, one bit at +a time, exactly the coordinates on which they differ. It starts at `s`, ends at `t`, and has +consecutive entries differing in exactly one bit. -/ +noncomputable def grayCode (s t : Fin m → Fin 2) : List (Fin m → Fin 2) := + grayPath t s (Finset.univ.filter (fun i => s i ≠ t i)).toList + +/-- The Gray code begins at `s`. -/ +@[simp] theorem grayCode_head? (s t : Fin m → Fin 2) : (grayCode s t).head? = some s := + grayPath_head? t s _ + +/-- The Gray code is nonempty. -/ +theorem grayCode_ne_nil (s t : Fin m → Fin 2) : grayCode s t ≠ [] := + grayPath_ne_nil _ _ _ + +/-- The Gray code has at most `m + 1` entries: `s` and `t` differ in at most `m` of `m` +coordinates (N&C's "`m ≤ n + 1`"). -/ +theorem grayCode_length_le (s t : Fin m → Fin 2) : (grayCode s t).length ≤ m + 1 := by + have hlen : (grayCode s t).length + = (Finset.univ.filter (fun i => s i ≠ t i)).toList.length + 1 := grayPath_length t s _ + rw [hlen, Finset.length_toList] + have h : (Finset.univ.filter (fun i => s i ≠ t i)).card ≤ m := by + calc (Finset.univ.filter (fun i => s i ≠ t i)).card + ≤ (Finset.univ : Finset (Fin m)).card := Finset.card_filter_le _ _ + _ = m := by simp + omega + +/-- **The Gray code ends at `t`.** -/ +theorem grayCode_getLast? (s t : Fin m → Fin 2) : (grayCode s t).getLast? = some t := by + unfold grayCode + rw [grayPath_getLast?] + congr 1 + funext x + split_ifs with h + · rfl + · rw [Finset.mem_toList, Finset.mem_filter] at h + simp only [Finset.mem_univ, true_and, not_not] at h + exact h + +/-- **Adjacent Gray-code words differ in exactly one bit** — the defining Gray-code property, at the +level of `grayCode s t`. -/ +theorem grayCode_isChain (s t : Fin m → Fin 2) : + List.IsChain differsInOneBit (grayCode s t) := by + apply grayPath_isChain_differsInOneBit + · exact Finset.nodup_toList _ + · intro i hi + rw [Finset.mem_toList, Finset.mem_filter] at hi + exact hi.2 + +/-- **The Gray code has no repeated entries.** The path visits each intermediate bit-string once, so +it is a *simple* path from `s` to `t`. Instance of `grayPath_nodup` (the filtered coordinate list is +duplicate-free and, by construction, lists exactly the coordinates on which `s` and `t` differ). -/ +theorem grayCode_nodup (s t : Fin m → Fin 2) : (grayCode s t).Nodup := by + apply grayPath_nodup + · exact Finset.nodup_toList _ + · intro i hi + rw [Finset.mem_toList, Finset.mem_filter] at hi + exact hi.2 + +/-- **`t` lies off the Gray code's initial segment `(grayCode s t).dropLast`** — its only occurrence +in the (duplicate-free) code is the final entry, which `dropLast` removes. This is the "`t` off the +path `[g₁, …, g_{m-1}]`" hypothesis that the §4.5.2 swap chain (`swapConj_swapChain_support`) +consumes to keep `|t⟩` fixed while the active pair is relocated. Follows from `grayCode_nodup` and +`grayCode_getLast?` via `l = l.dropLast ++ [l.getLast]`. -/ +theorem grayCode_getLast_not_mem_dropLast (s t : Fin m → Fin 2) : + t ∉ (grayCode s t).dropLast := by + have hne : grayCode s t ≠ [] := grayCode_ne_nil s t + have hlast : (grayCode s t).getLast hne = t := by + have h := grayCode_getLast? s t + rw [List.getLast?_eq_some_getLast hne] at h + exact Option.some_inj.mp h + have hnd : (grayCode s t).Nodup := grayCode_nodup s t + have hsplit : (grayCode s t).dropLast ++ [(grayCode s t).getLast hne] = grayCode s t := + List.dropLast_append_getLast hne + have hnd' : ((grayCode s t).dropLast ++ [(grayCode s t).getLast hne]).Nodup := by + rw [hsplit]; exact hnd + have hpair := (List.nodup_append.mp hnd').2.2 + have hnotmem : (grayCode s t).getLast hne ∉ (grayCode s t).dropLast := fun hmem => + hpair _ hmem _ (List.mem_singleton_self _) rfl + rwa [hlast] at hnotmem + +/-! +## The swap-chain path `(grayCode s t).dropLast` + +N&C §4.5.2 relocates the active pair of a two-level unitary by conjugating with the swap chain read +off the Gray-code path with its **final** entry `t = g_m` dropped, `(grayCode s t).dropLast = +[g₁, …, g_{m-1}]`. The three facts `swapConj_swapChain_support` consumes about that path are: its +head is `s` (`grayCode_dropLast_head?`), its last entry is bit-adjacent to `t` +(`grayCode_dropLast_getLast?_differsInOneBit` — so the relocated pair `{g_{m-1}, t}` is a +single-bit-differing pair, i.e. a controlled single-qubit gate), and `t` lies off it +(`grayCode_getLast_not_mem_dropLast`, above). All three need `s ≠ t` (else `grayCode s t = [s]` and +the path is empty — no relocation is required, the unitary already acts on a single basis state). +-/ + +/-- For distinct `s ≠ t` the swap-chain path `(grayCode s t).dropLast` is nonempty: the Gray code +has at least two entries (it starts at `s ≠ t` and ends at `t`), so dropping its last entry leaves +a nonempty list. -/ +theorem grayCode_dropLast_ne_nil (s t : Fin m → Fin 2) (hst : s ≠ t) : + (grayCode s t).dropLast ≠ [] := by + intro h + have hsplit : (grayCode s t).dropLast ++ [t] = grayCode s t := + List.dropLast_append_getLast? _ (Option.mem_def.mpr (grayCode_getLast? s t)) + rw [h, List.nil_append] at hsplit + have hhd := grayCode_head? s t + rw [← hsplit, List.head?_cons, Option.some_inj] at hhd + exact hst hhd.symm + +/-- **The swap-chain path `(grayCode s t).dropLast` begins at `s`** — the `path.head? = some s` +hypothesis of `swapConj_swapChain_support`, with `s = g₁` the Gray code's start (N&C §4.5.2). +Dropping the last entry `t` of the Gray code leaves a nonempty path (`s ≠ t`) still headed by +`s`. -/ +theorem grayCode_dropLast_head? (s t : Fin m → Fin 2) (hst : s ≠ t) : + (grayCode s t).dropLast.head? = some s := by + have hsplit : (grayCode s t).dropLast ++ [t] = grayCode s t := + List.dropLast_append_getLast? _ (Option.mem_def.mpr (grayCode_getLast? s t)) + have hhd := grayCode_head? s t + rw [← hsplit, List.head?_append_of_ne_nil _ (grayCode_dropLast_ne_nil s t hst)] at hhd + exact hhd + +/-- **The last entry of the swap-chain path `(grayCode s t).dropLast` is bit-adjacent to `t`.** That +entry is the penultimate Gray-code word `g_{m-1}`, and `g_{m-1}`, `t = g_m` are consecutive +Gray-code words (`grayCode_isChain`), hence `differsInOneBit`. This is what makes the relocated pair +`{g_{m-1}, t}` produced by `swapConj_swapChain_support` a pair of basis states differing in exactly +one bit — the point where the two-level unitary is a *controlled single-qubit gate* (N&C §4.5.2). -/ +theorem grayCode_dropLast_getLast?_differsInOneBit (s t : Fin m → Fin 2) (hst : s ≠ t) : + ∃ e, (grayCode s t).dropLast.getLast? = some e ∧ differsInOneBit e t := by + have hne := grayCode_dropLast_ne_nil s t hst + have hsplit : (grayCode s t).dropLast ++ [t] = grayCode s t := + List.dropLast_append_getLast? _ (Option.mem_def.mpr (grayCode_getLast? s t)) + refine ⟨(grayCode s t).dropLast.getLast hne, List.getLast?_eq_some_getLast hne, ?_⟩ + have hchain : List.IsChain differsInOneBit (grayCode s t) := grayCode_isChain s t + rw [← hsplit] at hchain + obtain ⟨-, -, hcross⟩ := List.isChain_append.1 hchain + exact hcross _ (Option.mem_def.mpr (List.getLast?_eq_some_getLast hne)) t (Option.mem_def.mpr rfl) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/Hadamard.lean b/LeanPool/AxQM/Concrete/Hadamard.lean new file mode 100644 index 0000000000..d3e08d869c --- /dev/null +++ b/LeanPool/AxQM/Concrete/Hadamard.lean @@ -0,0 +1,254 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Notation +public import LeanPool.AxQM.ToMathlib.Data.Real.Sqrt +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Basic.Complex.Basic +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Hermitian +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.HermitianUnitary +public import Mathlib.Tactic.LinearCombination + +/-! +# Concrete: the Hadamard matrix and its `n`-fold tensor (Kronecker) power + +This file defines the single-qubit Hadamard matrix `H` and its `n`-fold tensor power `H^{⊗n}` over +`ℝ`, proves the closed entry formula of Nielsen & Chuang, Exercise 2.33 (p. 74), and — for the qubit +*operator* work of Chapter 2 — the complex-entried Hadamard `H` together with its Hermiticity, +involution `H² = I`, and unitarity (membership in `Matrix.unitaryGroup`). + +## The exercise + +N&C write the one-qubit Hadamard operator (eq. 2.54) as +`H = (1/√2) [(|0⟩ + |1⟩)⟨0| + (|0⟩ − |1⟩)⟨1|]`, i.e. the real `2 × 2` matrix +`(1/√2) !![1, 1; 1, -1]`, and ask to show that the Hadamard transform on `n` qubits +`H^{⊗n}` may be written (eq. 2.55) as +`H^{⊗n} = (1/√(2ⁿ)) ∑_{x,y} (-1)^{x·y} |x⟩⟨y|`, +where `x, y` range over `n`-bit strings and `x·y = ∑ᵢ xᵢ yᵢ` is the bitwise dot product. +Finally it asks for an explicit matrix for `H^{⊗2}`. + +## What is formalised + +* `hadamard` — the `2 × 2` real matrix `(√2)⁻¹ • !![1, 1; 1, -1]` of eq. (2.54), and + `hadamard_apply` — its entrywise closed form `H a b = (√2)⁻¹ (-1)^{a b}`. +* `hadamardPow n` — the `n`-fold tensor power, indexed by `n`-bit strings `Fin n → Fin 2`, + defined by the honest block (Kronecker) recursion + `H^{⊗(n+1)} x y = H (x 0) (y 0) · H^{⊗n} (tail x) (tail y)`. Its faithfulness as *the* + tensor power is certified by `hadamardPow_apply`, the standard characterisation that a + Kronecker-power entry is the product of the factor entries: `H^{⊗n} x y = ∏ᵢ H (xᵢ) (yᵢ)`. +* `hadamardPow_apply_eq` — **eq. (2.55)**: `H^{⊗n} x y = (√(2ⁿ))⁻¹ (-1)^{∑ᵢ xᵢ yᵢ}`. This is + the exercise's main claim, proved (not assumed): the entry is the *product* `∏ᵢ H(xᵢ,yᵢ)`, + and the closed form drops out of the single-qubit formula by distributing the product. +* `hadamardPow_two_submatrix` — the explicit `4 × 4` matrix for `H^{⊗2}`, in N&C's + big-endian basis order `00, 01, 10, 11` (given by `bitPair2`). +* `hadamardC` — the same Hadamard `(√2)⁻¹ • !![1, 1; 1, -1]` but with **complex** entries + (eq. 2.85), the form needed as an *operator* on the qubit's state space `ℂ²`. Its structural + facts, matching the per-matrix facts of the Pauli file: `hadamardC_isHermitian` (`Hᴴ = H`), + `hadamardC_mul_self` (`H² = I`, the involution), and `hadamardC_mem_unitaryGroup` — the + formalisation of **Nielsen & Chuang, Exercise 2.51** (`H` is unitary, `Hᴴ H = I`), a one-line + consequence of Hermiticity and the involution via `Matrix.IsHermitian.mem_unitaryGroup`. + +These are the statements of N&C Exercises 2.33 and 2.51 ([upstream `AxQM/NC/Ch2/Exercise2_33.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_33.lean) and +[upstream `AxQM/NC/Ch2/Exercise2_51.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_51.lean)). The Hadamard gate `hadamardGate : Evolution qubit`, built on +`hadamardC_mem_unitaryGroup`, is in `AxQM/Postulates/API/HadamardGate.lean`. + +## Design notes + +* **Index type.** `n`-bit strings are `Fin n → Fin 2`, so an entry of `H^{⊗n}` is indexed by + a pair of strings and the tensor power is a `Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℝ`. + This makes the product-of-entries characterisation `∏ᵢ H(xᵢ,yᵢ)` a clean `Finset.prod` + over `Fin n`, and the dot product `x·y` the natural `∑ᵢ (xᵢ).val (yᵢ).val : ℕ`. +* **Real vs. complex.** N&C's Hadamard has real entries. For the tensor-power identity (2.33) — + a pure matrix identity with no physical content — `hadamard : Matrix (Fin 2) (Fin 2) ℝ` is + faithful and keeps the `√2` bookkeeping (`sqrt_two_pow`) on `ℝ` where it is cleanest. The + qubit gate operators of Chapter 2 act on `EuclideanSpace ℂ (Fin 2)`, so unitarity (2.51) is + stated for the complex-entried `hadamardC : Matrix (Fin 2) (Fin 2) ℂ`; the two are the same + matrix over their respective scalar rings (mirroring how the Pauli matrices are kept complex). +* **Unitarity via Hermitian ∧ involution.** `H` is real-symmetric, hence Hermitian, and squares + to `I`; so `Hᴴ H = H H = I`, exactly the input shape of `Matrix.IsHermitian.mem_unitaryGroup`. + This mirrors `pauliX_mem_unitaryGroup` etc. in `Concrete/Pauli.lean`, and reuses + `hadamardC_isHermitian` / `hadamardC_mul_self` — the latter is also N&C Exercise 2.52 (`H² = I`). +* **`(-1)^{x·y}` as an integer power.** The exponent `∑ᵢ (xᵢ).val (yᵢ).val` is a genuine `ℕ` + (not a residue mod 2); since `(-1 : ℝ)` has order `2`, `(-1)^k` depends only on parity, so + this matches N&C's `(-1)^{x·y}` exactly. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- The single-qubit Hadamard matrix `H = (1/√2) !![1, 1; 1, -1]` (Nielsen & Chuang, +eq. 2.54). Its columns are `(|0⟩ + |1⟩)/√2` and `(|0⟩ − |1⟩)/√2`. -/ +noncomputable def hadamard : Matrix (Fin 2) (Fin 2) ℝ := + (Real.sqrt 2)⁻¹ • !![1, 1; 1, -1] + +/-- The single-qubit Hadamard entries in closed form: `H a b = (√2)⁻¹ (-1)^{a b}`. This is +the `n = 1` case of eq. (2.55): `H(0,0) = H(0,1) = H(1,0) = 1/√2` and `H(1,1) = -1/√2`. -/ +theorem hadamard_apply (a b : Fin 2) : + hadamard a b = (Real.sqrt 2)⁻¹ * (-1) ^ (a.val * b.val) := by + fin_cases a <;> fin_cases b <;> simp [hadamard] + +/-- The `n`-fold tensor (Kronecker) power `H^{⊗n}` of the Hadamard matrix, indexed by the +`n`-bit strings `Fin n → Fin 2`. Defined by the block recursion of the Kronecker product: +`H^{⊗0} = I` (a `1 × 1` matrix on the singleton index) and +`H^{⊗(n+1)} x y = H (x 0) (y 0) · H^{⊗n} (tail x) (tail y)`, i.e. the first qubit contributes +the Hadamard factor `H (x 0) (y 0)` and the remaining `n` qubits contribute `H^{⊗n}`. -/ +noncomputable def hadamardPow : (n : ℕ) → Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℝ + | 0 => 1 + | n + 1 => fun x y => hadamard (x 0) (y 0) * hadamardPow n (Fin.tail x) (Fin.tail y) + +/-- A Kronecker-power entry is the product of the factor entries: +`H^{⊗n} x y = ∏ᵢ H (xᵢ) (yᵢ)`. This is the textbook characterisation of the tensor power, +so it certifies that `hadamardPow` really is `H^{⊗n}` (rather than a definition rigged to the +answer). -/ +theorem hadamardPow_apply (n : ℕ) (x y : Fin n → Fin 2) : + hadamardPow n x y = ∏ i, hadamard (x i) (y i) := by + induction n with + | zero => + have hxy : x = y := Subsingleton.elim x y + subst hxy + simp [hadamardPow] + | succ n ih => + simp only [hadamardPow] + rw [ih (Fin.tail x) (Fin.tail y), Fin.prod_univ_succ] + rfl + +/-- `√2 ^ n = √(2ⁿ)`: pulling the square root through a power, on `ℝ`. -/ +theorem sqrt_two_pow (n : ℕ) : Real.sqrt 2 ^ n = Real.sqrt (2 ^ n) := by + have h : (2 : ℝ) ^ n = (Real.sqrt 2 ^ n) ^ 2 := by + rw [← pow_mul, mul_comm n 2, pow_mul, Real.sq_sqrt] + norm_num + rw [h, Real.sqrt_sq (by positivity)] + +/-- **Nielsen & Chuang, Exercise 2.33 (eq. 2.55).** The Hadamard transform on `n` qubits has +the closed form `H^{⊗n} x y = (√(2ⁿ))⁻¹ (-1)^{x·y}`, where `x·y = ∑ᵢ xᵢ yᵢ` is the bitwise +dot product of the `n`-bit strings `x, y`. Proved from the product-of-entries formula +`hadamardPow_apply` by distributing the single-qubit closed form over the product. -/ +theorem hadamardPow_apply_eq (n : ℕ) (x y : Fin n → Fin 2) : + hadamardPow n x y + = (Real.sqrt (2 ^ n))⁻¹ * (-1) ^ (∑ i, (x i).val * (y i).val) := by + rw [hadamardPow_apply] + simp_rw [hadamard_apply] + rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.prod_pow_eq_pow_sum, + Finset.card_univ, Fintype.card_fin] + congr 1 + rw [inv_pow, sqrt_two_pow] + +/-- The four `2`-bit strings listed in Nielsen & Chuang's big-endian order `00, 01, 10, 11` +(the first component is the most significant bit). Used to reindex `H^{⊗2}` as an explicit +`4 × 4` matrix. -/ +def bitPair2 : Fin 4 → (Fin 2 → Fin 2) := ![![0, 0], ![0, 1], ![1, 0], ![1, 1]] + +/-- **Nielsen & Chuang, Exercise 2.33 (explicit `H^{⊗2}`).** In the big-endian basis order +`00, 01, 10, 11` (via `bitPair2`), the two-qubit Hadamard transform is the `4 × 4` matrix +`(1/2) !![1,1,1,1; 1,-1,1,-1; 1,1,-1,-1; 1,-1,-1,1]`. Each entry is `(1/2)(-1)^{x·y}` by the +`n = 2` case of eq. (2.55). -/ +theorem hadamardPow_two_submatrix : + (hadamardPow 2).submatrix bitPair2 bitPair2 + = (2⁻¹ : ℝ) • !![1, 1, 1, 1; 1, -1, 1, -1; 1, 1, -1, -1; 1, -1, -1, 1] := by + have hc : (Real.sqrt ((2 : ℝ) ^ 2))⁻¹ = 2⁻¹ := by + rw [Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 2)] + ext i j + simp only [Matrix.submatrix_apply, hadamardPow_apply_eq, hc] + fin_cases i <;> fin_cases j <;> norm_num [bitPair2, Fin.sum_univ_two] + +/-! ### The complex Hadamard matrix and its unitarity (Nielsen & Chuang, Exercise 2.51) + +The Hadamard `H = (1/√2) !![1, 1; 1, -1]` again, now over `ℂ` — the entry ring in which it is +an operator on the qubit's state space `EuclideanSpace ℂ (Fin 2)`. Like each Pauli matrix it is +Hermitian and an involution, and unitarity is the one-line consequence +`Hᴴ H = H H = I` via `Matrix.IsHermitian.mem_unitaryGroup`. -/ + +open Matrix Complex in +/-- The single-qubit Hadamard matrix `H = (1/√2) !![1, 1; 1, -1]` with **complex** entries +(Nielsen & Chuang, eq. 2.85). This is the operator form of `hadamard`, used to build the qubit +Hadamard gate; the two are the same matrix over `ℝ` resp. `ℂ`. -/ +noncomputable def hadamardC : Matrix (Fin 2) (Fin 2) ℂ := + ((Real.sqrt 2 : ℂ))⁻¹ • !![1, 1; 1, -1] + +/-- Entry formula for the complex Hadamard matrix (the `ℂ` twin of `hadamard_apply`): +`hadamardC a b = (√2)⁻¹ * (-1) ^ (a * b)`. -/ +theorem hadamardC_apply (a b : Fin 2) : + hadamardC a b = (Real.sqrt 2 : ℂ)⁻¹ * (-1) ^ ((a : ℕ) * (b : ℕ)) := by + fin_cases a <;> fin_cases b <;> simp [hadamardC, Matrix.smul_apply] + +/-- The complex Hadamard matrix is Hermitian (`Hᴴ = H`): its entries `±1/√2` are real, and the +matrix is symmetric. -/ +theorem hadamardC_isHermitian : hadamardC.IsHermitian := by + ext i j + fin_cases i <;> fin_cases j <;> simp [hadamardC, Matrix.conjTranspose_apply] + +/-- The Hadamard normalisation scalar squares to `½`: `(√2)⁻¹ * (√2)⁻¹ = 2⁻¹` over `ℂ`. Shared by +the Hadamard involution and the Hadamard-conjugation lemmas, where the two `(√2)⁻¹` factors of +`H = (√2)⁻¹ !![1,1;1,-1]` combine. -/ +theorem inv_sqrt_two_mul_self : (Real.sqrt 2 : ℂ)⁻¹ * (Real.sqrt 2 : ℂ)⁻¹ = 2⁻¹ := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num)]; norm_num + +/-- The Hadamard matrix is an involution: `H² = I`. The scalar `((√2)⁻¹)² = 2⁻¹` combines with +`!![1,1;1,-1]² = 2 • I` to give the identity. (This is also Nielsen & Chuang, Exercise 2.52.) -/ +theorem hadamardC_mul_self : hadamardC * hadamardC = 1 := by + have hc : ((Real.sqrt 2 : ℂ))⁻¹ * ((Real.sqrt 2 : ℂ))⁻¹ * 2 = 1 := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + norm_num + have hBB : (!![1, 1; 1, -1] : Matrix (Fin 2) (Fin 2) ℂ) * !![1, 1; 1, -1] + = (2 : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_two] <;> norm_num + rw [hadamardC, Matrix.smul_mul, Matrix.mul_smul, smul_smul, hBB, smul_smul, hc, one_smul] + +/-- **Nielsen & Chuang, Exercise 2.51: the Hadamard gate `H` is unitary.** `H ∈ unitaryGroup`, +i.e. `Hᴴ H = I` (N&C's definition of unitary), from `hadamardC_isHermitian` and the involution +`hadamardC_mul_self` via `Matrix.IsHermitian.mem_unitaryGroup`. -/ +theorem hadamardC_mem_unitaryGroup : hadamardC ∈ Matrix.unitaryGroup (Fin 2) ℂ := + hadamardC_isHermitian.mem_unitaryGroup hadamardC_mul_self + +/-- Conjugation by the Hadamard gate is **multiplicative** (because `H² = I`): +`H (A B) H = (H A H) (H B H)`. Inserting `H H = 1` between `A` and `B` splits the conjugation over +the product; the reusable step for pushing a pair of Hadamards through a product of gates. -/ +theorem hadamardC_conj_mul (A B : Matrix (Fin 2) (Fin 2) ℂ) : + hadamardC * (A * B) * hadamardC + = (hadamardC * A * hadamardC) * (hadamardC * B * hadamardC) := by + rw [show (hadamardC * A * hadamardC) * (hadamardC * B * hadamardC) + = hadamardC * A * (hadamardC * hadamardC) * B * hadamardC by noncomm_ring, + hadamardC_mul_self] + noncomm_ring + +/-- Double-conjugation by the Hadamard gate is the **identity** (because `H² = I`): +`H (H A H) H = A`. The two `H H = 1` cancellations recover `A`; used to write `U = H (H U H) H` +before decomposing `H U H`. -/ +theorem hadamardC_conj_conj (A : Matrix (Fin 2) (Fin 2) ℂ) : + hadamardC * (hadamardC * A * hadamardC) * hadamardC = A := by + rw [show hadamardC * (hadamardC * A * hadamardC) * hadamardC + = (hadamardC * hadamardC) * A * (hadamardC * hadamardC) by noncomm_ring, + hadamardC_mul_self, one_mul, mul_one] + +/-- The Hadamard matrix is the phase `i` times the shared rotation-product core +`(√2)⁻¹ !![-i, -i; -i, i]` (` = -i H`): `H = i • ((√2)⁻¹ • !![-i, -i; -i, i])`. This is the common +final step of the Hadamard rotation-decomposition identities — the `R_x`–`R_z`–`R_x` product of +Exercise 4.4 (`HadamardRotation.lean`) and the `R_x`–`R_y` product of Exercise 7.31 +(`HadamardRyRx.lean`) both evaluate to this matrix `-i H`, so multiplying by `e^{iπ/2} = i` recovers +`H` identically. Proved entrywise, closing each entry with `i² = -1` (`Complex.I_sq`). -/ +theorem hadamardC_eq_I_smul_negIH : + hadamardC = Complex.I • ((Real.sqrt 2 : ℂ)⁻¹ • + !![-Complex.I, -Complex.I; -Complex.I, Complex.I]) := by + rw [smul_smul, hadamardC] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, + smul_eq_mul] <;> + first + | linear_combination (Real.sqrt 2 : ℂ)⁻¹ * Complex.I_sq + | linear_combination (-(Real.sqrt 2 : ℂ)⁻¹) * Complex.I_sq + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/HadamardABC.lean b/LeanPool/AxQM/Concrete/HadamardABC.lean new file mode 100644 index 0000000000..2f8637e492 --- /dev/null +++ b/LeanPool/AxQM/Concrete/HadamardABC.lean @@ -0,0 +1,174 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.ABCDecomposition +public import LeanPool.AxQM.Concrete.HadamardRotation + +/-! +# Concrete: the ABC decomposition of the Hadamard gate (Nielsen & Chuang, Exercise 4.12) + +Nielsen & Chuang, Exercise 4.12 asks to **give `A`, `B`, `C` and `α` for the Hadamard gate** in the +ABC decomposition of Corollary 4.2 (`U = e^{iα} A X B X C` with `A B C = I`). This file supplies the +explicit witnesses and verifies both defining relations at the matrix level. + +The Z–Y decomposition of the Hadamard matrix (N&C eq. 4.12 with `cos(γ/2) = sin(γ/2) = (√2)⁻¹` and +the phases forcing `β = 0`, `γ = π/2`, `δ = π`, `α = π/2`) is `H = e^{iπ/2} R_z(0) R_y(π/2) R_z(π)`. +Feeding these angles into Corollary 4.2's witnesses `A = R_z(β) R_y(γ/2)`, `B = R_y(-γ/2) +R_z(-(δ+β)/2)`, `C = R_z((δ-β)/2)` and simplifying `R_z(0) = I` gives + +`α = π/2`, `A = R_y(π/4)`, `B = R_y(-π/4) R_z(-π/2)`, `C = R_z(π/2)`. + +## What is formalised + +* `hadamardWitnessA`, `hadamardWitnessB`, `hadamardWitnessC` — the explicit witnesses (the answer to + "give `A`, `B`, `C`"), each a product of `§4.2` rotation matrices. +* `hadamardWitnessA_mul_B_mul_C_eq_one` — `A B C = I` (Corollary 4.2's first relation). +* `hadamardC_eq_expPiDivTwo_smul_rotY_mul_rotZ` — the Hadamard Z–Y decomposition + `H = e^{iπ/2} • (R_y(π/2) R_z(π))` (the `β = 0` case). +* `hadamardABC_reassembly` — `A X B X C = R_y(π/2) R_z(π)` (Corollary 4.2's `X`-conjugation step, + specialised). +* `hadamardC_eq_expPiDivTwo_smul_hadamardABC` — **Exercise 4.12 as a matrix identity**: + `H = e^{iπ/2} • (A X B X C)`, the answer to "give `α`" (`α = π/2`) assembled with the witnesses. + +## Design notes + +* **These are the standard witnesses, not asserted.** Both relations are *proved*: `A B C = I` by + the same `R_y`/`R_z` telescope as Corollary 4.2 (`rotY_mul_rotY`/`rotZ_mul_rotZ` and the zero + angles collapse), and `A X B X C = R_y(π/2) R_z(π)` by the `X`-conjugation identities + `pauliX_mul_rotY_mul_pauliX`/`pauliX_mul_rotZ_mul_pauliX` (Exercise 4.7) with `pauliX_mul_self` + (`X² = I`). The exercise permits any correct answer; these are N&C's own witnesses (Corollary 4.2) + for the Hadamard's Z–Y parameters. +* **The Z–Y decomposition of `H` is routed through Exercise 4.4.** Rather than recomputing an + entrywise angle extraction, `hadamardC_eq_expPiDivTwo_smul_rotY_mul_rotZ` uses the already-proved + `hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX` (`H = e^{iπ/2} R_x(π/2) R_z(π/2) R_x(π/2)`, + Exercise 4.4) together with the shared closed form `(√2)⁻¹ • !![-i,-i;-i,i]`, which + `R_y(π/2) R_z(π)` also realises (`rotY_mul_rotZ_piHalf_pi`). +* **Gate-level statement.** The operator identity for gates is in + `AxQM/Postulates/API/HadamardABC.lean`, and the physics reading — that the Hadamard *gate* and + the ABC gate product induce the same state channel — is in [upstream `AxQM/NC/Ch4/Exercise4_12.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_12.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The Hadamard ABC witness `A = R_y(π/4)` (Nielsen & Chuang, Exercise 4.12). Corollary 4.2's +`A = R_z(β) R_y(γ/2)` with the Hadamard's Z–Y angles `β = 0`, `γ = π/2` (so `R_z(0) = I`). -/ +noncomputable def hadamardWitnessA : Matrix (Fin 2) (Fin 2) ℂ := rotY (Real.pi / 4) + +/-- The Hadamard ABC witness `B = R_y(-π/4) R_z(-π/2)` (Nielsen & Chuang, Exercise 4.12). +Corollary 4.2's `B = R_y(-γ/2) R_z(-(δ+β)/2)` with `β = 0`, `γ = π/2`, `δ = π`. -/ +noncomputable def hadamardWitnessB : Matrix (Fin 2) (Fin 2) ℂ := + rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2)) + +/-- The Hadamard ABC witness `C = R_z(π/2)` (Nielsen & Chuang, Exercise 4.12). Corollary 4.2's +`C = R_z((δ-β)/2)` with `β = 0`, `δ = π`. -/ +noncomputable def hadamardWitnessC : Matrix (Fin 2) (Fin 2) ℂ := rotZ (Real.pi / 2) + +/-- **Corollary 4.2's first relation for the Hadamard witnesses:** `A B C = I`. The inner `R_y` +collapse (`R_y(π/4) R_y(-π/4) = R_y(0) = I`) and the outer `R_z` telescope +(`R_z(-π/2) R_z(π/2) = R_z(0) = I`). -/ +theorem hadamardWitnessA_mul_B_mul_C_eq_one : + hadamardWitnessA * hadamardWitnessB * hadamardWitnessC = 1 := by + unfold hadamardWitnessA hadamardWitnessB hadamardWitnessC + calc rotY (Real.pi / 4) * (rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2))) * rotZ (Real.pi / 2) + = (rotY (Real.pi / 4) * rotY (-(Real.pi / 4))) + * (rotZ (-(Real.pi / 2)) * rotZ (Real.pi / 2)) := by noncomm_ring + _ = 1 := by + rw [rotY_mul_rotY, rotZ_mul_rotZ, show Real.pi / 4 + -(Real.pi / 4) = 0 by ring, + show -(Real.pi / 2) + Real.pi / 2 = 0 by ring, rotY_zero, rotZ_zero, mul_one] + +/-- The closed form of the product `R_y(π/2) R_z(π) = (√2)⁻¹ • !![-i, -i; -i, i]` (` = -i H`), the +same matrix realised by the `X`–`Z`–`X` product of Exercise 4.4. Computed entrywise from +`rotY_eq`/`rotZ_eq` (`cos(π/4) = sin(π/4) = (√2)⁻¹`, `e^{∓iπ/2} = ∓i`). -/ +theorem rotY_mul_rotZ_piHalf_pi : + rotY (Real.pi / 2) * rotZ Real.pi + = (Real.sqrt 2 : ℂ)⁻¹ • !![-Complex.I, -Complex.I; -Complex.I, Complex.I] := by + have hs : (Real.sqrt 2 / 2 : ℝ) = (Real.sqrt 2)⁻¹ := by + rw [div_eq_iff (by positivity), inv_mul_eq_div, eq_div_iff (by positivity), + Real.mul_self_sqrt (by norm_num)] + have hc : Real.cos (Real.pi / 2 / 2) = (Real.sqrt 2)⁻¹ := by + rw [show Real.pi / 2 / 2 = Real.pi / 4 by ring, Real.cos_pi_div_four, hs] + have hsin : Real.sin (Real.pi / 2 / 2) = (Real.sqrt 2)⁻¹ := by + rw [show Real.pi / 2 / 2 = Real.pi / 4 by ring, Real.sin_pi_div_four, hs] + have hz1 : Complex.exp (-((Real.pi : ℂ) / 2) * Complex.I) = -Complex.I := by + rw [show -((Real.pi : ℂ) / 2) * Complex.I = ((-(Real.pi / 2) : ℝ) : ℂ) * Complex.I by + push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, Real.cos_neg, Real.sin_neg, + Real.cos_pi_div_two, Real.sin_pi_div_two] + push_cast; ring + have hz2 : Complex.exp ((Real.pi : ℂ) / 2 * Complex.I) = Complex.I := by + rw [show ((Real.pi : ℂ) / 2) * Complex.I = ((Real.pi / 2 : ℝ) : ℂ) * Complex.I by + push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, + Real.cos_pi_div_two, Real.sin_pi_div_two] + push_cast; ring + rw [rotY_eq, rotZ_eq] + simp only [Matrix.mul_fin_two, hc, hsin, hz1, hz2] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, + smul_eq_mul, Complex.ofReal_inv] <;> ring + +/-- The **Z–Y decomposition of the Hadamard matrix** (the `β = 0` case, N&C eq. 4.12): +`H = e^{iπ/2} • (R_y(π/2) R_z(π))`. Both `R_y(π/2) R_z(π)` (`rotY_mul_rotZ_piHalf_pi`) and the +`X`–`Z`–`X` product of Exercise 4.4 equal the shared closed form `(√2)⁻¹ • !![-i,-i;-i,i]`, so this +reduces to `hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX`. -/ +theorem hadamardC_eq_expPiDivTwo_smul_rotY_mul_rotZ : + hadamardC = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) + • (rotY (Real.pi / 2) * rotZ Real.pi) := by + rw [hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX, rotX_mul_rotZ_mul_rotX_pi_div_two, + rotY_mul_rotZ_piHalf_pi] + +/-- **Corollary 4.2's `X`-conjugation step for the Hadamard witnesses:** +`A X B X C = R_y(π/2) R_z(π)`. +Inserting `X X = I` inside `B` and applying `X R_a(θ) X = R_a(-θ)` (Exercise 4.7) turns `X B X` into +`R_y(π/4) R_z(π/2)`, after which the `R_y` and `R_z` factors combine via the group law. -/ +theorem hadamardABC_reassembly : + hadamardWitnessA * pauliX * hadamardWitnessB * pauliX * hadamardWitnessC + = rotY (Real.pi / 2) * rotZ Real.pi := by + have hXBX : pauliX * (rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2))) * pauliX + = rotY (Real.pi / 4) * rotZ (Real.pi / 2) := by + calc pauliX * (rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2))) * pauliX + = pauliX * rotY (-(Real.pi / 4)) * (pauliX * pauliX) + * rotZ (-(Real.pi / 2)) * pauliX := by rw [pauliX_mul_self]; noncomm_ring + _ = (pauliX * rotY (-(Real.pi / 4)) * pauliX) + * (pauliX * rotZ (-(Real.pi / 2)) * pauliX) := by noncomm_ring + _ = rotY (Real.pi / 4) * rotZ (Real.pi / 2) := by + rw [pauliX_mul_rotY_mul_pauliX, pauliX_mul_rotZ_mul_pauliX, neg_neg, neg_neg] + unfold hadamardWitnessA hadamardWitnessB hadamardWitnessC + calc rotY (Real.pi / 4) * pauliX * (rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2))) + * pauliX * rotZ (Real.pi / 2) + = rotY (Real.pi / 4) + * (pauliX * (rotY (-(Real.pi / 4)) * rotZ (-(Real.pi / 2))) * pauliX) + * rotZ (Real.pi / 2) := by noncomm_ring + _ = rotY (Real.pi / 4) * (rotY (Real.pi / 4) * rotZ (Real.pi / 2)) * rotZ (Real.pi / 2) := by + rw [hXBX] + _ = (rotY (Real.pi / 4) * rotY (Real.pi / 4)) * (rotZ (Real.pi / 2) * rotZ (Real.pi / 2)) := by + noncomm_ring + _ = rotY (Real.pi / 2) * rotZ Real.pi := by + rw [rotY_mul_rotY, rotZ_mul_rotZ, show Real.pi / 4 + Real.pi / 4 = Real.pi / 2 by ring, + show Real.pi / 2 + Real.pi / 2 = Real.pi by ring] + +/-- **Nielsen & Chuang, Exercise 4.12 (matrix form).** The ABC decomposition of the Hadamard gate: +with `α = π/2`, `A = R_y(π/4)`, `B = R_y(-π/4) R_z(-π/2)`, `C = R_z(π/2)`, +`H = e^{iπ/2} • (A X B X C)` (and `A B C = I`, `hadamardWitnessA_mul_B_mul_C_eq_one`). Assembled +from +the Hadamard Z–Y decomposition `hadamardC_eq_expPiDivTwo_smul_rotY_mul_rotZ` and the reassembly +`hadamardABC_reassembly` (`A X B X C = R_y(π/2) R_z(π)`). -/ +theorem hadamardC_eq_expPiDivTwo_smul_hadamardABC : + hadamardC = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) + • (hadamardWitnessA * pauliX * hadamardWitnessB * pauliX * hadamardWitnessC) := by + rw [hadamardABC_reassembly, hadamardC_eq_expPiDivTwo_smul_rotY_mul_rotZ] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/HadamardPauliConjugation.lean b/LeanPool/AxQM/Concrete/HadamardPauliConjugation.lean new file mode 100644 index 0000000000..a4765c948c --- /dev/null +++ b/LeanPool/AxQM/Concrete/HadamardPauliConjugation.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Hadamard +public import LeanPool.AxQM.Concrete.Pauli + +/-! +# Concrete: conjugating the Pauli matrices by the Hadamard gate (Nielsen & Chuang, Exercise 4.13) + +Nielsen & Chuang, Exercise 4.13 (*Circuit identities*, p. 177) asks to prove the three +Hadamard-conjugation identities (eq. 4.18) + +`H X H = Z`, `H Y H = -Y`, `H Z H = X`. + +Each is a pure `2 × 2` complex-matrix identity about the Hadamard matrix `hadamardC` +(`AxQM/Concrete/Hadamard.lean`) and the Pauli matrices `pauliX`/`pauliY`/`pauliZ` +(`AxQM/Concrete/Pauli.lean`). The statement of Exercise 4.13 is in +[upstream `AxQM/NC/Ch4/Exercise4_13.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_13.lean). + +## What is formalised + +* `hadamardC_mul_pauliX_mul_hadamardC` — `H X H = Z`. +* `hadamardC_mul_pauliY_mul_hadamardC` — `H Y H = -Y`. +* `hadamardC_mul_pauliZ_mul_hadamardC` — `H Z H = X`. + +Geometrically the Hadamard gate is the reflection of the Bloch sphere that exchanges the `x̂` and +`e_z` axes and flips `y_hat`; the three identities record exactly that action on the Pauli +operators. + +## Related results + +The X–Y decomposition (Exercise 4.10) already relies +on Hadamard conjugation exchanging the `x̂`/`e_z` axes — its `hadamardC_mul_rotZ_mul_hadamardC` +(`H R_z(θ) H = R_x(θ)`) is precisely the rotation-level shadow of `H Z H = X` here. Stating the +three Pauli identities on their own makes that geometric fact citable directly (and matches the +naming convention `hadamardC_mul_<σ>_mul_hadamardC` of the rotation conjugation lemmas). + +## Design notes + +* **Proof idiom: factor the normalisation, then compute entrywise.** Writing + `H = (√2)⁻¹ • !![1,1;1,-1]`, the two `H` factors of a conjugation contribute + `(√2)⁻¹ · (√2)⁻¹ = 2⁻¹` (`inv_sqrt_two_mul_self`), collapsing the Hadamard normalisation to a + single `2⁻¹ •` in front of `!![1,1;1,-1] * σ * !![1,1;1,-1]`. The remaining `2 × 2` matrix + equality is checked entry by entry (`fin_cases` on both indices, `Matrix.mul_apply` + + `Fin.sum_univ_two`, closed by `ring`). This is the same reduce-and-compute idiom as + `hadamardC_mul_rotZ_mul_hadamardC` / `hadamardC_mul_rotY_mul_hadamardC` in + `Concrete/RotationDecompositionXY.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **Nielsen & Chuang, Exercise 4.13 (eq. 4.18)**: conjugating `X` by the Hadamard gate gives `Z`, +`H X H = Z`. The Hadamard reflection exchanges the `x̂` and `e_z` Bloch axes. -/ +theorem hadamardC_mul_pauliX_mul_hadamardC : hadamardC * pauliX * hadamardC = pauliZ := by + rw [hadamardC, Matrix.smul_mul, Matrix.smul_mul, Matrix.mul_smul, smul_smul, + inv_sqrt_two_mul_self] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX, pauliZ] <;> ring + +/-- **Nielsen & Chuang, Exercise 4.13 (eq. 4.18)**: conjugating `Y` by the Hadamard gate negates it, +`H Y H = -Y`. The Hadamard reflection flips the `y_hat` Bloch axis. -/ +theorem hadamardC_mul_pauliY_mul_hadamardC : hadamardC * pauliY * hadamardC = -pauliY := by + rw [hadamardC, Matrix.smul_mul, Matrix.smul_mul, Matrix.mul_smul, smul_smul, + inv_sqrt_two_mul_self] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliY, Matrix.neg_apply] <;> ring + +/-- **Nielsen & Chuang, Exercise 4.13 (eq. 4.18)**: conjugating `Z` by the Hadamard gate gives `X`, +`H Z H = X`. The Hadamard reflection exchanges the `e_z` and `x̂` Bloch axes; this is the +Pauli-level +form of `hadamardC_mul_rotZ_mul_hadamardC` (`H R_z(θ) H = R_x(θ)`). -/ +theorem hadamardC_mul_pauliZ_mul_hadamardC : hadamardC * pauliZ * hadamardC = pauliX := by + rw [hadamardC, Matrix.smul_mul, Matrix.smul_mul, Matrix.mul_smul, smul_smul, + inv_sqrt_two_mul_self] + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX, pauliZ] <;> ring + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/HadamardRotation.lean b/LeanPool/AxQM/Concrete/HadamardRotation.lean new file mode 100644 index 0000000000..1f740b1bcf --- /dev/null +++ b/LeanPool/AxQM/Concrete/HadamardRotation.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.Concrete.Hadamard + +/-! +# Concrete: the Hadamard matrix as a product of `R_x`, `R_z` rotations (Nielsen & Chuang, Ex. 4.4) + +Nielsen & Chuang, Exercise 4.4 asks to express the Hadamard gate `H` as a product of `R_x` and `R_z` +rotations together with a global phase `e^{iϕ}`. The closed-form answer is + +`H = e^{iπ/2} R_x(π/2) R_z(π/2) R_x(π/2)`. (with `ϕ = π/2`, i.e. `e^{iϕ} = i`) + +Building on the rotation matrices `rotX`, `rotZ` of `AxQM/Concrete/Rotation.lean` (N&C eqs. 4.4, +4.6) and the complex Hadamard matrix `hadamardC` of `AxQM/Concrete/Hadamard.lean` (eq. 2.85), this +file proves the above `2 × 2` matrix identity. The *physics* reading of Exercise 4.4 — that `H` and +the rotation product are the **same quantum operation** (the global phase being unobservable) — is +the statement in [upstream `AxQM/NC/Ch4/Exercise4_4.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_4.lean), built on this identity and the gates of +`AxQM/Postulates/API/HadamardRotation.lean`. + +## What is formalised + +* `rotX_mul_rotZ_mul_rotX_pi_div_two` — the reusable computational core: the product + `R_x(π/2) R_z(π/2) R_x(π/2)` in closed form, + `(√2)⁻¹ • !![-i, -i; -i, i]` (` = -i H`). +* `hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX` — **Exercise 4.4 as a matrix identity**: + `H = e^{iπ/2} • (R_x(π/2) R_z(π/2) R_x(π/2))`, obtained by multiplying the product core by the + phase `e^{iπ/2} = i`. + +## Design notes + +* **The decomposition is verified, not asserted.** `rotX`/`rotZ` are consumed through their + explicit-matrix forms `rotX_eq`/`rotZ_eq` (the closed forms of eqs. 4.4/4.6), and the product is + computed entrywise, so the identity is a *theorem* about the rotation operators of `§4.2`, not a + restatement. +* **The phase `ϕ = π/2`.** The product `R_x(π/2) R_z(π/2) R_x(π/2)` evaluates to `-i H`; multiplying + by `e^{iπ/2} = i` recovers `H`. The exercise permits any correct `(ϕ, sequence)`; this is the + standard `X`–`Z`–`X` sandwich (the reflection `H` exchanges the `x̂` and `e_z` axes, so it is a + rotation built symmetrically from `R_x` and `R_z`). +* **Entry arithmetic.** At `θ = π/2` the rotation entries are `cos(π/4) = sin(π/4) = (√2)⁻¹` and the + `R_z` phases `e^{∓iπ/4} = (√2)⁻¹(1 ∓ i)`; each product entry then reduces to a Gaussian-integer + multiple of `(√2)⁻¹` using `(√2)⁻¹·(√2)⁻¹ = 1/2` and `i² = -1`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The product `R_x(π/2) R_z(π/2) R_x(π/2)` in closed form: `(√2)⁻¹ • !![-i, -i; -i, i]`, i.e. +`-i H`. This is the reusable computational core of the Hadamard `X`–`Z`–`X` decomposition +(Nielsen & Chuang, Exercise 4.4), obtained from the explicit forms `rotX_eq`/`rotZ_eq` by an +entrywise computation. -/ +theorem rotX_mul_rotZ_mul_rotX_pi_div_two : + rotX (Real.pi / 2) * rotZ (Real.pi / 2) * rotX (Real.pi / 2) + = (Real.sqrt 2 : ℂ)⁻¹ • !![-Complex.I, -Complex.I; -Complex.I, Complex.I] := by + have hs : (Real.sqrt 2 / 2 : ℝ) = (Real.sqrt 2)⁻¹ := Real.sqrt_div_self + have hc : Real.cos (Real.pi / 2 / 2) = (Real.sqrt 2)⁻¹ := by + rw [show Real.pi / 2 / 2 = Real.pi / 4 by ring, Real.cos_pi_div_four, hs] + have hsin : Real.sin (Real.pi / 2 / 2) = (Real.sqrt 2)⁻¹ := by + rw [show Real.pi / 2 / 2 = Real.pi / 4 by ring, Real.sin_pi_div_four, hs] + have he1 : Complex.exp (-(((Real.pi / 2 : ℝ) : ℂ) / 2) * Complex.I) + = (Real.sqrt 2 : ℂ)⁻¹ - (Real.sqrt 2 : ℂ)⁻¹ * Complex.I := by + rw [show -(((Real.pi / 2 : ℝ) : ℂ) / 2) * Complex.I = ((-(Real.pi / 4) : ℝ) : ℂ) * Complex.I by + push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, Real.cos_neg, Real.sin_neg, + Real.cos_pi_div_four, Real.sin_pi_div_four, hs] + push_cast; ring + have he2 : Complex.exp (((Real.pi / 2 : ℝ) : ℂ) / 2 * Complex.I) + = (Real.sqrt 2 : ℂ)⁻¹ + (Real.sqrt 2 : ℂ)⁻¹ * Complex.I := by + rw [show ((Real.pi / 2 : ℝ) : ℂ) / 2 * Complex.I = ((Real.pi / 4 : ℝ) : ℂ) * Complex.I by + push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, + Real.cos_pi_div_four, Real.sin_pi_div_four, hs] + push_cast; ring + have hsqrt : (Real.sqrt 2 : ℂ)⁻¹ * (Real.sqrt 2 : ℂ)⁻¹ = 2⁻¹ := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num)]; norm_num + rw [rotX_eq, rotZ_eq] + simp only [Matrix.mul_fin_two, hc, hsin, he1, he2] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, + smul_eq_mul, Complex.ofReal_inv] <;> + first + | linear_combination (-2 * (Real.sqrt 2 : ℂ)⁻¹ * Complex.I) * hsqrt + | linear_combination ((Real.sqrt 2 : ℂ)⁻¹ ^ 3 * (1 + Complex.I)) * Complex.I_sq + + (-2 * (Real.sqrt 2 : ℂ)⁻¹ * Complex.I) * hsqrt + | linear_combination ((Real.sqrt 2 : ℂ)⁻¹ ^ 3 * (1 - Complex.I)) * Complex.I_sq + + (2 * (Real.sqrt 2 : ℂ)⁻¹ * Complex.I) * hsqrt + +/-- **Nielsen & Chuang, Exercise 4.4 (matrix form).** The Hadamard matrix is the `X`–`Z`–`X` +rotation product up to the global phase `e^{iπ/2}`: +`H = e^{iπ/2} • (R_x(π/2) R_z(π/2) R_x(π/2))`. +Since `R_x(π/2) R_z(π/2) R_x(π/2) = -i H` (`rotX_mul_rotZ_mul_rotX_pi_div_two`) and +`e^{iπ/2} = i`, multiplying by the phase recovers `H`. -/ +theorem hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX : + hadamardC = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) • + (rotX (Real.pi / 2) * rotZ (Real.pi / 2) * rotX (Real.pi / 2)) := by + have hphase : Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) = Complex.I := by + push_cast; exact Complex.exp_pi_div_two_mul_I + rw [hphase, rotX_mul_rotZ_mul_rotX_pi_div_two] + exact hadamardC_eq_I_smul_negIH + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/KronFamilyWireProduct.lean b/LeanPool/AxQM/Concrete/KronFamilyWireProduct.lean new file mode 100644 index 0000000000..9ef5ed7e9f --- /dev/null +++ b/LeanPool/AxQM/Concrete/KronFamilyWireProduct.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringDiagonalize +public import LeanPool.AxQM.Concrete.PauliStringCliffordConjugation +public import LeanPool.AxQM.Concrete.SingleQubitWire + +/-! +# Concrete: a tensor product of per-qubit gates is the ordered product of single-wire gates + +This file proves the **flat-register +factorisation** of an `n`-fold tensor product `⨂ₖ Aₖ` into the ordered matrix product of its +single-wire embeddings — the elementary identity behind every *wire-by-wire* circuit decomposition +(each `Aₖ` is a separate one-qubit gate on wire `k`). + +## Why this is needed (Nielsen & Chuang, Problem 4.3(3)) + +The `O(n)`-gate circuit implementing `exp(-i h_g g Δ)` opens with a **layer** `B = ⨂ₖ B_{gₖ}` of +single-qubit basis-change gates (`Concrete/PauliStringDiagonalize.lean`). To count that layer's +gates through the elementary-gate accountant `CircuitBudget` — which folds a *product* of +single-wire `Evolution`s one gate at a time — the tensor product `B` must first be exhibited as +such a product: `B = ∏ₜ Bₜ` with `Bₜ` acting only on wire `t`. This file supplies that identity; the +`Evolution`/`CircuitBudget` promotion of `B` is a separate physics-level step. + +## What is proved + +* `kronFamily_eq_prod_kronWireGate` — on the bit-string indexing `Fin n → Fin 2`, the tensor product + is the ordered product of its one-wire embeddings: + `kronFamily A = ∏_{j < n} kronWireGate j (A j)` (a `List.prod` over `List.finRange n`). The + factors act on disjoint wires and commute, but the statement fixes the wire order for later use. +* `singleQubitOnWire_eq_submatrix_kronWireGate` — under any register encoding + `enc : (Fin n → Fin 2) ≃ Fin d`, the wire gate `singleQubitOnWire enc j g` is the reindexing + of the bit-string one-wire embedding `kronWireGate j g`. +* `kronFamilyStd_eq_prod_singleQubitOnWire` — combining the two, on the flat register `Fin (2ⁿ)`: + `kronFamilyStd A = ∏_{t < n} singleQubitOnWire finFunctionFinEquiv t (A t)`. +* `kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire` — the Problem 4.3(3) instance: the + basis-change `B = ⨂ₖ B_{gₖ}` (`kronFamilyStd (pauliDiagGate ∘ g)`) is the ordered product of the + per-wire diagonalising gates `singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate (g t))`. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **A tensor product is the ordered product of its one-wire embeddings.** On the bit-string +register `Fin n → Fin 2`, `⨂ₖ Aₖ = ∏_{j kronWireGate j (A j))).prod := by + -- `kronFamily` as a monoid homomorphism from the pointwise-product monoid of qubit gates. + let φ : (Fin n → Matrix (Fin 2) (Fin 2) ℂ) →* Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + { toFun := kronFamily + map_one' := by simpa [Pi.one_def] using (kronFamily_one (n := n)) + map_mul' := fun A B => (kronFamily_mul A B).symm } + -- The one-hot families multiply to `A` (pointwise: one non-identity factor per coordinate). + have hprod : ((List.finRange n).map + (fun j => Function.update (1 : Fin n → Matrix (Fin 2) (Fin 2) ℂ) j (A j))).prod = A := by + funext k + have h := map_list_prod (Pi.evalMonoidHom (fun _ : Fin n => Matrix (Fin 2) (Fin 2) ℂ) k) + ((List.finRange n).map + (fun j => Function.update (1 : Fin n → Matrix (Fin 2) (Fin 2) ℂ) j (A j))) + simp only [List.map_map] at h + rw [Pi.evalMonoidHom] at h + simp only [MonoidHom.coe_mk, OneHom.coe_mk] at h + rw [h, List.prod_map_eq_pow_single (a := k)] + · simp [Function.update_self] + · intro j hjk _ + simp [Function.update_of_ne (Ne.symm hjk)] + calc kronFamily A = φ A := rfl + _ = φ (((List.finRange n).map + (fun j => Function.update (1 : Fin n → Matrix (Fin 2) (Fin 2) ℂ) j (A j))).prod) := by + rw [hprod] + _ = ((List.finRange n).map (fun j => kronWireGate j (A j))).prod := by + rw [map_list_prod, List.map_map]; rfl + +/-- **The wire gate is the reindexed one-wire embedding.** Under any register encoding +`enc : (Fin n → Fin 2) ≃ Fin d`, the single-qubit gate on wire `j` is the bit-string one-wire +embedding `kronWireGate j g` reindexed along `enc`: +`singleQubitOnWire enc j g = (kronWireGate j g).submatrix enc.symm enc.symm`. Proof: entrywise, the +`kronFamily` entry `∏ₖ (1 update j ↦ g)ₖ` splits off the `k = j` factor `g (x j) (x' j)`; the +remaining `k ≠ j` factors are the identity entries `[xₖ = x'ₖ]`, whose product +(`Finset.prod_boole`) is `[∀ k ≠ j, xₖ = x'ₖ]` — exactly the `singleQubitOnWire` conditional. -/ +theorem singleQubitOnWire_eq_submatrix_kronWireGate {d : ℕ} (enc : (Fin n → Fin 2) ≃ Fin d) + (j : Fin n) (g : Matrix (Fin 2) (Fin 2) ℂ) : + singleQubitOnWire enc j g = (kronWireGate j g).submatrix enc.symm enc.symm := by + ext i i' + simp only [singleQubitOnWire_apply, submatrix_apply, kronWireGate, kronFamily_apply] + rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ j), Function.update_self] + have hentry : ∀ k ∈ Finset.univ.erase j, + Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j g k + (enc.symm i k) (enc.symm i' k) + = (if enc.symm i k = enc.symm i' k then (1 : ℂ) else 0) := by + intro k hk + rw [Function.update_of_ne (Finset.ne_of_mem_erase hk), Matrix.one_apply] + rw [Finset.prod_congr rfl hentry, Finset.prod_boole] + have hcond : (∀ k ∈ Finset.univ.erase j, enc.symm i k = enc.symm i' k) + ↔ (∀ k, k ≠ j → enc.symm i k = enc.symm i' k) := by + simp [Finset.mem_erase] + by_cases h : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left h, ite_eq_left (hcond.mpr h), mul_one] + · rw [ite_eq_right h, ite_eq_right (mt hcond.mp h), mul_zero] + +/-- **The flat-register tensor factorisation.** On the computational-basis register `Fin (2ⁿ)`, +`⨂ₖ Aₖ = ∏_{t singleQubitOnWire finFunctionFinEquiv t (A t))).prod := by + -- The `finFunctionFinEquiv`-reindexing as a monoid homomorphism on `Fin (2ⁿ)`-matrices. + let ψ : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ →* Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + { toFun := fun M => M.submatrix finFunctionFinEquiv.symm finFunctionFinEquiv.symm + map_one' := Matrix.submatrix_one_equiv finFunctionFinEquiv.symm + map_mul' := fun M N => (Matrix.submatrix_mul_equiv M N _ finFunctionFinEquiv.symm _).symm } + have hstd : kronFamilyStd A = ψ (kronFamily A) := rfl + rw [hstd, kronFamily_eq_prod_kronWireGate, map_list_prod, List.map_map] + refine congrArg List.prod (List.map_congr_left fun j _ => ?_) + exact (singleQubitOnWire_eq_submatrix_kronWireGate finFunctionFinEquiv j (A j)).symm + +/-- **Problem 4.3(3): the basis-change layer `B` factors into single-wire gates.** The single-qubit +basis change `B = ⨂ₖ B_{gₖ}` diagonalising the Pauli string `g` +(`kronFamilyStd (pauliDiagGate ∘ g)`, `Concrete/PauliStringDiagonalize.lean`) is the ordered matrix +product of the per-wire diagonalising +gates `B_{gₜ}` on wire `t`: +`kronFamilyStd (fun k => pauliDiagGate (g k)) + = ∏_{t < n} singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate (g t))`. The instance of +`kronFamilyStd_eq_prod_singleQubitOnWire` at `A = pauliDiagGate ∘ g`; it exhibits the layer `B` as +literally `n` one-qubit gates, one per wire, the shape the elementary-gate budget of Problem 4.3(3) +folds over. -/ +theorem kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire (g : Fin n → Fin 4) : + kronFamilyStd (fun k => pauliDiagGate (g k)) + = ((List.finRange n).map + (fun t => singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate (g t)))).prod := + kronFamilyStd_eq_prod_singleQubitOnWire (fun k => pauliDiagGate (g k)) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNot.lean b/LeanPool/AxQM/Concrete/MultiControlledNot.lean new file mode 100644 index 0000000000..8be55f78e1 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNot.lean @@ -0,0 +1,242 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Data.Finset.Insert +public import Mathlib.Data.Finset.Image +public import Mathlib.Data.Finset.Lattice.Basic +public import Mathlib.Logic.Equiv.Basic + +/-! +# Concrete: the multiply-controlled NOT as a reversible bit-string permutation (N&C §4.3) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a circuit of `O(n²)` Toffoli, `CNOT` and +single-qubit gates that implements a `Cⁿ(X)` gate — the `n`-controlled `NOT` — **using no work +qubits** (the whole register is the `n` controls and the one target, `n + 1` qubits). + +Every gate in such a circuit (`X`, `CNOT`, Toffoli, and any multiply-controlled `NOT`) is a +*permutation of the computational basis*, so the entire construction — its correctness **and** its +gate count — is a statement about reversible classical circuits on bit-strings, decidable +`Fin 2`/`Finset` combinatorics. This file sets up that classical model: bit-strings `Fin m → Fin 2` +and the **multiply-controlled `NOT`** `mcNot S t`, which flips wire `t` exactly when every control +wire in the finite set `S` is set. It is an involution, hence a permutation (`mcNotPerm`). + +The mathematical heart of the `O(n²)` no-work-qubit construction is the **dirty borrowed-wire +reduction** `mcNot_union_borrow`: for disjoint control sets `A`, `B`, a target `t`, and *any* wire +`a` outside the gate's support, splitting the controls as `A ∪ B` and using `a` as a **borrowed** +work wire, +`mcNot (A ∪ B) t = mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a`, +and — crucially — `a` starts in an *arbitrary* ("dirty") state yet is restored, so no clean work +qubit is needed. The middle wire `a` is toggled by the two `mcNot A a` iff every control in `A` is +set; the two `mcNot (insert a B) t` flip `t` iff every control in `B` **and** `a` are set, and the +even number of `a`-toggles between them makes the net effect flip `t` iff every control in +`A ∪ B` is set (a group-commutator / parity cancellation). Iterating this reduction with +`|A|, |B| ≈ n/2` bottoms out in Toffoli/`CNOT` gates and yields the `O(n²)` gate count of the +exercise (the recursion `T(n) = 2T(⌈n/2⌉) + 2T(⌊n/2⌋+1)` is `Θ(n²)`). + +This is pure combinatorics. Each `mcNot` gate is realised as a genuine `Evolution` (a +Toffoli/`CNOT`/single-qubit gate placed on the register), and the whole circuit as +`mcCtrl n pauliXGate`, in [upstream `AxQM/NC/Ch4/Exercise4_29.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_29.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-- A `Fin 2` bit added to itself cancels: `b + c + c = b` (the target wire, flipped by the same +control bit an even number of times, is restored). -/ +theorem add_add_self_right (b c : Fin 2) : b + c + c = b := by revert b c; decide + +/-- Bit-strings agreeing on every wire of `B` satisfy the "all controls set" predicate together. -/ +theorem forall_mem_eq_one_congr {B : Finset (Fin m)} {x y : Fin m → Fin 2} + (h : ∀ i ∈ B, x i = y i) : (∀ i ∈ B, x i = 1) ↔ (∀ i ∈ B, y i = 1) := + ⟨fun H i hi => h i hi ▸ H i hi, fun H i hi => (h i hi).symm ▸ H i hi⟩ + +/-- **The control bit of a multiply-controlled `NOT`**: `1` when every control wire in the finite +set `S` is set to `1` in the bit-string `x`, and `0` otherwise. This is the amount by which the +target wire is flipped. -/ +def ctrlBit (S : Finset (Fin m)) (x : Fin m → Fin 2) : Fin 2 := + if ∀ i ∈ S, x i = 1 then 1 else 0 + +/-- **The classical multiply-controlled `NOT`** `mcNot S t`: the reversible map on bit-strings +`Fin m → Fin 2` that adds the control bit `ctrlBit S x` (XOR, since we are in `Fin 2`) to wire `t`, +leaving every other wire unchanged. For `|S| = 0, 1, 2` this is the `NOT`, `CNOT`, Toffoli gate +respectively; in general it is the classical `C^{|S|}(X)` gate with controls `S` and target `t`. -/ +def mcNot (S : Finset (Fin m)) (t : Fin m) (x : Fin m → Fin 2) : Fin m → Fin 2 := + Function.update x t (x t + ctrlBit S x) + +/-! ### Pointwise behaviour -/ + +/-- The value of `mcNot S t x` on the target wire `t` is `x t` flipped by the control bit. -/ +@[simp] theorem mcNot_apply_self (S : Finset (Fin m)) (t : Fin m) (x : Fin m → Fin 2) : + mcNot S t x t = x t + ctrlBit S x := by + simp [mcNot] + +/-- The value of `mcNot S t x` on any wire other than the target `t` is unchanged. -/ +theorem mcNot_apply_of_ne (S : Finset (Fin m)) (t : Fin m) (x : Fin m → Fin 2) {j : Fin m} + (h : j ≠ t) : mcNot S t x j = x j := by + simp only [mcNot, Function.update_of_ne h] + +/-- When no control condition is met (`ctrlBit S x = 0`), `mcNot S t` fixes the bit-string. -/ +theorem mcNot_of_ctrlBit_eq_zero (S : Finset (Fin m)) (t : Fin m) (x : Fin m → Fin 2) + (h : ctrlBit S x = 0) : mcNot S t x = x := by + rw [mcNot, h]; simp + +/-- `ctrlBit S` only reads the wires in `S`, so updating a wire outside `S` leaves it unchanged. -/ +theorem ctrlBit_update_of_notMem (S : Finset (Fin m)) {j : Fin m} (hj : j ∉ S) + (x : Fin m → Fin 2) (v : Fin 2) : + ctrlBit S (Function.update x j v) = ctrlBit S x := by + simp only [ctrlBit, forall_mem_eq_one_congr + fun i hi => Function.update_of_ne (fun (h : i = j) => hj (h ▸ hi)) v x] + +/-- `ctrlBit` of an `insert`: every control in `insert a B` is set iff `a` is set and every control +in `B` is set. -/ +theorem ctrlBit_insert (a : Fin m) (B : Finset (Fin m)) (x : Fin m → Fin 2) : + ctrlBit (insert a B) x = if x a = 1 ∧ ∀ i ∈ B, x i = 1 then 1 else 0 := by + simp only [ctrlBit, Finset.forall_mem_insert] + +/-- `ctrlBit` of a `union`: every control in `A ∪ B` is set iff every control in `A` is set and +every control in `B` is set. -/ +theorem ctrlBit_union (A B : Finset (Fin m)) (x : Fin m → Fin 2) : + ctrlBit (A ∪ B) x = if (∀ i ∈ A, x i = 1) ∧ ∀ i ∈ B, x i = 1 then 1 else 0 := by + simp only [ctrlBit, Finset.forall_mem_union] + +/-- `ctrlBit` under a `Finset.image`: the control bit of the relabelled control set `S.image f` +read on `x` equals the control bit of `S` read on the pulled-back bit-string `x ∘ f`. (Used to +transport a placed multiply-controlled gate's control condition back through the wire relabelling.) +No injectivity of `f` is needed: `∀ y ∈ S.image f, x y = 1 ↔ ∀ i ∈ S, x (f i) = 1`. -/ +theorem ctrlBit_image {n : ℕ} (S : Finset (Fin m)) (f : Fin m → Fin n) (x : Fin n → Fin 2) : + ctrlBit (S.image f) x = ctrlBit S (fun i => x (f i)) := by + simp only [ctrlBit, Finset.forall_mem_image] + +/-- The multiply-controlled `NOT` control bit of a **single** control wire `a` is just that wire's +value: `ctrlBit {a} c = c a` (the `CNOT` control bit). -/ +theorem ctrlBit_singleton (a : Fin m) (c : Fin m → Fin 2) : ctrlBit {a} c = c a := by + unfold ctrlBit + simp only [Finset.mem_singleton, forall_eq] + generalize c a = b + revert b + decide + +/-! ### Reversibility -/ + +/-- **`mcNot S t` is an involution** when the target `t` is not one of the controls: applying it +twice restores the bit-string, because the target is flipped by the same control bit twice +(`c + c = 0` in `Fin 2`) and the flip does not affect the control wires. -/ +theorem mcNot_involutive (S : Finset (Fin m)) {t : Fin m} (ht : t ∉ S) : + Function.Involutive (mcNot S t) := by + intro x + have hc : ctrlBit S (mcNot S t x) = ctrlBit S x := + ctrlBit_update_of_notMem S ht x _ + funext j + by_cases hj : j = t + · subst hj + rw [mcNot_apply_self, hc, mcNot_apply_self] + exact add_add_self_right _ _ + · rw [mcNot_apply_of_ne _ _ _ hj, mcNot_apply_of_ne _ _ _ hj] + +/-- **The multiply-controlled `NOT` as a permutation** of the computational basis (when the target +is not a control): the reversible-gate incarnation, ready to be realised as a unitary. -/ +def mcNotPerm (S : Finset (Fin m)) {t : Fin m} (ht : t ∉ S) : Equiv.Perm (Fin m → Fin 2) := + (mcNot_involutive S ht).toPerm _ + +@[simp] theorem mcNotPerm_apply (S : Finset (Fin m)) {t : Fin m} (ht : t ∉ S) (x : Fin m → Fin 2) : + mcNotPerm S ht x = mcNot S t x := rfl + +/-! ### Naturality under wire relabelling -/ + +/-- **`mcNot` is natural under a bijective relabelling of the wires.** Relabelling the wires by an +equivalence `σ : Fin m ≃ Fin p` — sending the control set `S` to `S.map σ.toEmbedding` and the +target `t` to `σ t` — turns the gate `mcNot S t` into `mcNot (S.map σ.toEmbedding) (σ t)`, read on +the relabelled bit-string: `mcNot (S.map σ.toEmbedding) (σ t) x j = mcNot S t (x ∘ σ) (σ.symm j)`. +The control condition transports because `ctrlBit` of a `Finset.map` is `ctrlBit` of the pulled-back +bit-string (`ctrlBit_image`, no injectivity needed); the target flip transports because +`σ.symm j = t ↔ j = σ t`. This is the equivariance a **register cast** uses to place a +wire-addressed `mcNot` gate on a propositionally-resized register (`Fin (k + 1 + b) ≃ Fin m`), so +the classical truth table survives the relabelling. -/ +theorem mcNot_map_equiv {p : ℕ} (σ : Fin m ≃ Fin p) (S : Finset (Fin m)) (t : Fin m) + (x : Fin p → Fin 2) (j : Fin p) : + mcNot (S.map σ.toEmbedding) (σ t) x j = mcNot S t (fun i => x (σ i)) (σ.symm j) := by + have hctrl : ctrlBit (S.map σ.toEmbedding) x = ctrlBit S (fun i => x (σ i)) := by + rw [Finset.map_eq_image, Equiv.coe_toEmbedding, ctrlBit_image] + by_cases hj : j = σ t + · subst hj + rw [Equiv.symm_apply_apply, mcNot_apply_self, mcNot_apply_self, hctrl] + · have hj' : σ.symm j ≠ t := fun h => hj ((Equiv.symm_apply_eq σ).mp h) + rw [mcNot_apply_of_ne _ _ _ hj, mcNot_apply_of_ne _ _ _ hj', Equiv.apply_symm_apply] + +/-! ### The dirty borrowed-wire reduction -/ + +/-- **The Barenco dirty borrowed-wire reduction (the heart of Exercise 4.29).** Split the controls +of a multiply-controlled `NOT` into two disjoint sets `A`, `B`, and let `a` be *any* wire outside +the gate's support (`a ∉ A`, `a ∉ B`, `a ≠ t`) — used as a **borrowed** work wire in an arbitrary +("dirty") state. Then +`mcNot (A ∪ B) t = mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a`, +where the composition reads right to left (the rightmost `mcNot A a` acts first). The borrowed wire +`a` is toggled iff every control in `A` is set, and is **restored** by the two `mcNot A a`; the two +`mcNot (insert a B) t` flip the target `t` iff every control in `B` and `a` are set, and the even +number of `a`-toggles between them nets out to: `t` flips iff every control in `A ∪ B` is set. This +is the identity iterated (with `|A|, |B| ≈ n/2`) to reach the `O(n²)` no-work-qubit circuit. -/ +theorem mcNot_union_borrow (A B : Finset (Fin m)) {a t : Fin m} + (haA : a ∉ A) (haB : a ∉ B) (hat : a ≠ t) (htA : t ∉ A) (htB : t ∉ B) : + mcNot (A ∪ B) t + = mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a := by + -- A decidable `Fin 2` identity capturing the parity cancellation of the borrowed wire `a`. + have master : ∀ w y α : Fin 2, + w + α = w + (if y + α = 1 then (1 : Fin 2) else 0) + (if y = 1 then (1 : Fin 2) else 0) := by + decide + funext x + simp only [Function.comp_apply] + set x1 := mcNot A a x with hx1 + set x2 := mcNot (insert a B) t x1 with hx2 + set x3 := mcNot A a x2 with hx3 + -- The control bit of `A` is unaffected by the two updates (both hit wires outside `A`). + have hAx2 : ctrlBit A x2 = ctrlBit A x := by + rw [hx2, mcNot, ctrlBit_update_of_notMem A htA, hx1, mcNot, ctrlBit_update_of_notMem A haA] + -- Values of the intermediate states on the relevant wires. + have hx1a : x1 a = x a + ctrlBit A x := by rw [hx1, mcNot_apply_self] + have hx1B : ∀ i ∈ B, x1 i = x i := by + intro i hi; rw [hx1]; exact mcNot_apply_of_ne A a x (by rintro rfl; exact haB hi) + have hx3a : x3 a = x a := by + rw [hx3, mcNot_apply_self, hAx2, hx2, mcNot_apply_of_ne _ _ _ hat, hx1a] + exact add_add_self_right _ _ + have hx3B : ∀ i ∈ B, x3 i = x i := by + intro i hi + have hia : i ≠ a := by rintro rfl; exact haB hi + have hit : i ≠ t := by rintro rfl; exact htB hi + rw [hx3, mcNot_apply_of_ne _ _ _ hia, hx2, mcNot_apply_of_ne _ _ _ hit, hx1B i hi] + have hx3t : x3 t = x t + ctrlBit (insert a B) x1 := by + rw [hx3, mcNot_apply_of_ne _ _ _ (Ne.symm hat), hx2, mcNot_apply_self, hx1, + mcNot_apply_of_ne _ _ _ (Ne.symm hat)] + funext j + by_cases hjt : j = t + · -- Target wire: the parity cancellation. + subst hjt + rw [mcNot_apply_self, ctrlBit_union, mcNot_apply_self, hx3t] + have hB3 := forall_mem_eq_one_congr hx3B + have hB1 := forall_mem_eq_one_congr hx1B + rw [ctrlBit_insert, ctrlBit_insert, hx3a, hx1a] + simp only [hB3, hB1] + by_cases hPB : ∀ i ∈ B, x i = 1 + · simp only [and_iff_left hPB] + exact master (x j) (x a) (ctrlBit A x) + · rw [ite_eq_right fun h => hPB h.2, ite_eq_right fun h => hPB h.2, + ite_eq_right fun h => hPB h.2] + have h0 : ∀ w : Fin 2, w + 0 = w + 0 + 0 := by decide + exact h0 (x j) + · -- Non-target wire: passes through unchanged (borrowed wire `a` restored). + rw [mcNot_apply_of_ne _ _ _ hjt, mcNot_apply_of_ne _ _ _ hjt] + by_cases hja : j = a + · subst hja; rw [hx3a] + · rw [hx3, mcNot_apply_of_ne _ _ _ hja, hx2, mcNot_apply_of_ne _ _ _ hjt, + hx1, mcNot_apply_of_ne _ _ _ hja] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean b/LeanPool/AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean new file mode 100644 index 0000000000..fd77ab339f --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean @@ -0,0 +1,275 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledNotDirtyCascade + +/-! +# Concrete: the genuine dirty-ancilla `Cᵏ(X)` from a double borrowed-wire AND cascade + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for an `O(n²)` no-work-qubit circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. The linear-cascade +sub-project reaches the `O(n²)` count — which the `Θ(k²)` halving recursion +`exists_mcNotCircuit` misses (it sums to `Θ(n³)` over `barencoNCircuit`'s `O(n)` blocks) — +by bottoming each internal `Cᵏ(X)` block in a **linear** +`O(k)` number of `Toffoli`s, using the register's idle wires as **dirty** borrowed ancillas +(Barenco *Elementary gates*, Lemma 7.2/7.3). + +`AxQM/Concrete/MultiControlledNotDirtyCascade.lean` builds the **borrowed-wire AND +cascade** `borrowedAndCascade as cs tgt`: it flips the target by the exact control AND +`ctrlBit cs.toFinset x`, **independently of the dirty borrowed wires** +(`borrowedAndCascade_apply_tgt`), in a linear number of `≤ 2`-control gates — but it *corrupts* the +borrowed wires (each is flipped by a partial AND), so it is **not** itself a `Cᵏ(X)`. It is however +an involution (`borrowedAndCascade_involutive`). + +This file assembles the genuine dirty `Cᵏ(X)` from it. Write + +* `C := borrowedAndCascade (a :: as) (c :: cs) tgt` — the full cascade: flips `tgt` by + `⋀ (c :: cs)`, corrupts the ancillas `a :: as`; +* `R := borrowedAndCascade as cs a` — the *sub*-cascade one layer down (target the head ancilla + `a`). + +The key structural fact (`borrowedAndCascade_agree_off_tgt`) is that `C` and `R` **act identically +on every wire except `tgt`** — because `C = T · R · T` sandwiches `R` between two copies of the +single `Toffoli` `T = ({a, c}, tgt)`, and `T` touches only `tgt`, which lies outside `R`'s support. +Hence + +`borrowedMcNot (a :: as) (c :: cs) tgt := C ++ R` + +is a genuine `Cᵏ(X)`: applied as `x ↦ C (R x)`, on the target it flips by `⋀ (c :: cs)` (the two +target-flips of `R` are killed since `R` fixes `tgt`, and `C` supplies the one correct flip), and on +every other wire `C` acts as `R`, so the net effect is `R (R x) = x` — every borrowed wire is +**restored** (`mcNotDenote_borrowedMcNot`). Its gates are all `Toffoli`/`CNOT`/`NOT` +(`borrowedMcNot_gate_mem`) and its length is linear, `≤ 4 |as| + 1` (`borrowedMcNot_length_le`) — +the `O(k)` per-block count the `O(n²)` assembly needs, requiring `|cs| - 2` **arbitrary** (dirty) +borrowed wires and **no** clean work qubit. + +Everything here is `Fin 2`/`Finset`/`List` combinatorics. Compare the other `MultiControlledNot*` +files. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-! ### Two reusable frame lemmas for `mcNot` circuits -/ + +/-- **`ctrlBit` depends only on the control wires.** Two bit-strings agreeing on every wire of the +control set `S` have the same control bit. -/ +theorem ctrlBit_congr {S : Finset (Fin m)} {x y : Fin m → Fin 2} (h : ∀ i ∈ S, y i = x i) : + ctrlBit S y = ctrlBit S x := by + simp only [ctrlBit, forall_mem_eq_one_congr h] + +/-- **Per-gate frame lemma.** Updating a wire `w` that is neither a control (`w ∉ S`) nor the target +(`w ≠ t`) of a gate commutes with the gate: `mcNot S t (x[w ↦ v]) = (mcNot S t x)[w ↦ v]`. The gate +neither reads nor writes `w`, so the update passes straight through. -/ +theorem mcNot_update_comm (S : Finset (Fin m)) (t : Fin m) {w : Fin m} (hwS : w ∉ S) (hwt : w ≠ t) + (x : Fin m → Fin 2) (v : Fin 2) : + mcNot S t (Function.update x w v) = Function.update (mcNot S t x) w v := by + unfold mcNot + rw [ctrlBit_update_of_notMem S hwS, Function.update_of_ne (Ne.symm hwt), + Function.update_comm hwt] + +/-- **Circuit frame lemma.** If a wire `w` is outside the support of every gate of a circuit `gs` +(never a control, `w ∉ g.1`, and never a target, `w ≠ g.2`), then updating `w` commutes with running +the whole circuit: `mcNotDenote gs (x[w ↦ v]) = (mcNotDenote gs x)[w ↦ v]`. Proved by structural +recursion over the gate list, iterating `mcNot_update_comm`. -/ +theorem mcNotDenote_update_comm {w : Fin m} : + ∀ (gs : List (McNotGate m)), (∀ g ∈ gs, w ∉ g.1 ∧ w ≠ g.2) → + ∀ (x : Fin m → Fin 2) (v : Fin 2), + mcNotDenote gs (Function.update x w v) = Function.update (mcNotDenote gs x) w v + | [], _, _, _ => rfl + | g :: gs, h, x, v => by + rw [mcNotDenote_cons, mcNotDenote_cons, + mcNotDenote_update_comm gs (fun g' hg' => h g' (List.mem_cons_of_mem _ hg')) x v, + mcNot_update_comm _ _ (h g List.mem_cons_self).1 (h g List.mem_cons_self).2] + +/-! ### The target lies outside the sub-cascade's support -/ + +/-- **The borrowed-wire AND cascade has no external wire as a control or target.** Any wire `w` +distinct from every control (`w ∉ cs`), every ancilla (`w ∉ as`), and the target (`w ≠ t`) occurs +neither as a control nor as a target of any gate of `borrowedAndCascade as cs t`. Used to feed +`mcNotDenote_update_comm`: the outer register wire `tgt` of the enclosing cascade lies outside the +sub-cascade's support. -/ +theorem borrowedAndCascade_notMem_support : + ∀ (as cs : List (Fin m)) (t : Fin m) {w : Fin m}, w ∉ cs → w ∉ as → w ≠ t → + ∀ g ∈ borrowedAndCascade as cs t, w ∉ g.1 ∧ w ≠ g.2 + | [], cs, t, w => by + intro hwc _ hwt g hg + rw [borrowedAndCascade_nil, List.mem_singleton] at hg + subst hg + exact ⟨by rwa [List.mem_toFinset], hwt⟩ + | a :: as, cs, t, w => by + intro hwc hwa hwt g hg + obtain _ | ⟨c, cs⟩ := cs + · rw [borrowedAndCascade_cons_nil, List.mem_singleton] at hg + subst hg + exact ⟨by simp, hwt⟩ + · have hwa' : w ∉ as := fun h => hwa (List.mem_cons_of_mem _ h) + have hwa_ne : w ≠ a := fun h => hwa (h ▸ List.mem_cons_self) + have hwc' : w ∉ cs := fun h => hwc (List.mem_cons_of_mem _ h) + have hwc_ne : w ≠ c := fun h => hwc (h ▸ List.mem_cons_self) + have hpeel : w ∉ ({a, c} : Finset (Fin m)) ∧ w ≠ t := by + refine ⟨?_, hwt⟩ + simp only [Finset.mem_insert, Finset.mem_singleton, not_or] + exact ⟨hwa_ne, hwc_ne⟩ + rw [borrowedAndCascade_cons] at hg + rcases List.mem_cons.mp hg with hg | hg + · subst hg; exact hpeel + rcases List.mem_append.mp hg with hg | hg + · exact borrowedAndCascade_notMem_support as cs a hwc' hwa' hwa_ne g hg + · rw [List.mem_singleton] at hg; subst hg; exact hpeel + +/-- **The full cascade and its sub-cascade agree off the target.** For any wire `w ≠ tgt`, +`borrowedAndCascade (a :: as) (c :: cs) tgt` acts on `w` exactly as its one-layer-down sub-cascade +`borrowedAndCascade as cs a` (target the head ancilla `a`). Reason: the full cascade is `T · R · T` +with `R = borrowedAndCascade as cs a` and `T = ({a, c}, tgt)` a single `Toffoli` touching only +`tgt`; +since `tgt` lies outside `R`'s support, `R`'s obliviousness to `tgt` (`mcNotDenote_update_comm` + +`borrowedAndCascade_notMem_support`) and the two `T`s leave `R`'s action on every other wire +unchanged. This is what lets the double cascade restore the borrowed wires. -/ +theorem borrowedAndCascade_agree_off_tgt {a : Fin m} {as : List (Fin m)} (c : Fin m) + {cs : List (Fin m)} {tgt : Fin m} (htcs : tgt ∉ cs) (htas : tgt ∉ as) (hta : tgt ≠ a) + (x : Fin m → Fin 2) {w : Fin m} (hwt : w ≠ tgt) : + mcNotDenote (borrowedAndCascade (a :: as) (c :: cs) tgt) x w + = mcNotDenote (borrowedAndCascade as cs a) x w := by + rw [borrowedAndCascade_cons, mcNotDenote_cons, mcNot_apply_of_ne _ _ _ hwt, mcNotDenote_append] + simp only [mcNotDenote_cons, mcNotDenote_nil] + rw [mcNot, mcNotDenote_update_comm (borrowedAndCascade as cs a) + (borrowedAndCascade_notMem_support as cs a htcs htas hta) x _, + Function.update_of_ne hwt] + +/-! ### The genuine dirty `Cᵏ(X)` circuit -/ + +/-- **The dirty-ancilla `Cᵏ(X)` circuit** (Barenco *Elementary gates*, Lemma 7.2/7.3). Given +borrowed ancilla wires `as`, controls `cs`, and target `tgt`, `borrowedMcNot as cs tgt` runs the +borrowed-wire AND cascade `borrowedAndCascade (a :: as) (c :: cs) tgt` (which flips `tgt` by the +exact control AND +but corrupts the ancillas) followed by the one-layer-down sub-cascade `borrowedAndCascade as cs a` +(which un-corrupts the ancillas without touching `tgt`, since it is an involution and the two agree +off `tgt`). It bottoms out (ancillas exhausted, `|cs| ≤ 2`) at a single `≤ 2`-control gate. With +`|cs| - 2` **arbitrary** (dirty) borrowed ancillas it is a genuine `C^{|cs|}(X)` restoring every +wire (`mcNotDenote_borrowedMcNot`), in a **linear** `O(|cs|)` number of `Toffoli`/`CNOT`/`NOT` gates +and no clean work qubit. -/ +def borrowedMcNot : List (Fin m) → List (Fin m) → Fin m → List (McNotGate m) + | a :: as, c :: cs, tgt => + borrowedAndCascade (a :: as) (c :: cs) tgt ++ borrowedAndCascade as cs a + | _, cs, tgt => [(cs.toFinset, tgt)] + +/-- Base unfolding of `borrowedMcNot` when the ancillas run out (`|cs| ≤ 2`: a single base gate). -/ +theorem borrowedMcNot_nil (cs : List (Fin m)) (tgt : Fin m) : + borrowedMcNot [] cs tgt = [(cs.toFinset, tgt)] := rfl + +/-- Base unfolding of `borrowedMcNot` when the controls run out (unreached under the invariant +`|cs| = |as| + 2`). -/ +theorem borrowedMcNot_cons_nil (a : Fin m) (as : List (Fin m)) (tgt : Fin m) : + borrowedMcNot (a :: as) [] tgt = [(([] : List (Fin m)).toFinset, tgt)] := rfl + +/-- Recursive unfolding of `borrowedMcNot` (≥ 1 ancilla, ≥ 1 control): the full cascade followed by +its one-layer-down sub-cascade. -/ +theorem borrowedMcNot_cons (a : Fin m) (as : List (Fin m)) (c : Fin m) (cs : List (Fin m)) + (tgt : Fin m) : + borrowedMcNot (a :: as) (c :: cs) tgt + = borrowedAndCascade (a :: as) (c :: cs) tgt ++ borrowedAndCascade as cs a := rfl + +/-- **The dirty `Cᵏ(X)` is linear.** `borrowedMcNot as cs tgt` has at most `4 |as| + 1` gates — +twice the borrowed-wire cascade's `≤ 2|as| + 1` plus its one-layer sub-cascade, `O(|as|) = O(|cs|)` +(the linear per-block count the `O(n²)` assembly needs). -/ +theorem borrowedMcNot_length_le (as cs : List (Fin m)) (tgt : Fin m) : + (borrowedMcNot as cs tgt).length ≤ 4 * as.length + 1 := by + obtain _ | ⟨a, as⟩ := as + · rw [borrowedMcNot_nil]; simp + · obtain _ | ⟨c, cs⟩ := cs + · rw [borrowedMcNot_cons_nil]; simp only [List.length_cons, List.length_nil]; omega + · rw [borrowedMcNot_cons, List.length_append] + have h1 := borrowedAndCascade_length_le (a :: as) (c :: cs) tgt + have h2 := borrowedAndCascade_length_le as cs a + simp only [List.length_cons] at h1 ⊢ + omega + +/-- **Every gate of the dirty `Cᵏ(X)` is a `Toffoli`/`CNOT`/`NOT`** (`≤ 2` controls, target not a +control), under the matching invariant `|cs| = |as| + 2` with all wires distinct — inherited from +the two borrowed-wire cascades it concatenates. -/ +theorem borrowedMcNot_gate_mem (as cs : List (Fin m)) (tgt : Fin m) + (hlen : cs.length = as.length + 2) (hcs : cs.Nodup) (has : as.Nodup) (hdisj : cs.Disjoint as) + (htcs : tgt ∉ cs) (htas : tgt ∉ as) : + ∀ g ∈ borrowedMcNot as cs tgt, g.1.card ≤ 2 ∧ g.2 ∉ g.1 := by + obtain _ | ⟨a, as⟩ := as + · rw [borrowedMcNot_nil] + intro g hg + simp only [List.mem_singleton] at hg + subst hg + refine ⟨?_, ?_⟩ + · calc cs.toFinset.card ≤ cs.length := List.toFinset_card_le cs + _ = 2 := by simp only [List.length_nil] at hlen; omega + · simpa [List.mem_toFinset] using htcs + · obtain _ | ⟨c, cs⟩ := cs + · simp only [List.length_nil, List.length_cons] at hlen; omega + · rw [borrowedMcNot_cons] + obtain ⟨hlen', hcs', has', hdisj', hacs', haas'⟩ := + borrowedAndCascade_step_hyps hlen hcs has hdisj + intro g hg + rcases List.mem_append.mp hg with hg | hg + · exact borrowedAndCascade_gate_mem (a :: as) (c :: cs) tgt hlen hcs has hdisj htcs htas g hg + · exact borrowedAndCascade_gate_mem as cs a hlen' hcs' has' hdisj' hacs' haas' g hg + +/-- **N&C Exercise 4.29 / Barenco Lemma 7.2/7.3 — the double borrowed-wire cascade is a genuine +dirty `Cᵏ(X)`.** With `|cs|` controls, `|cs| - 2` **arbitrary** (dirty) borrowed ancillas `as`, and +every +wire distinct, `borrowedMcNot as cs tgt` acts on the bit-string `x` exactly as the multiply- +controlled `NOT` `mcNot cs.toFinset tgt` — flipping only the target by the true control AND +`ctrlBit cs.toFinset x` and **restoring every borrowed wire**, with no dependence on the ancillas' +initial values. + +Applied as `x ↦ C (R x)` with `C = borrowedAndCascade (a :: as) (c :: cs) tgt` and +`R = borrowedAndCascade as cs a`: + +* on the target `tgt`, `C` supplies the one correct flip `⋀ (c :: cs)` + (`borrowedAndCascade_apply_tgt`) while `R` fixes `tgt` and every control + (`borrowedAndCascade_apply_of_ne`, `ctrlBit_congr`); +* on every other wire `C` acts as `R` (`borrowedAndCascade_agree_off_tgt`), so the net effect is + `R (R x) = x` (`borrowedAndCascade_involutive`) — the corruption cancels. -/ +theorem mcNotDenote_borrowedMcNot (as cs : List (Fin m)) (tgt : Fin m) + (hlen : cs.length = as.length + 2) (hcs : cs.Nodup) (has : as.Nodup) (hdisj : cs.Disjoint as) + (htcs : tgt ∉ cs) (htas : tgt ∉ as) (x : Fin m → Fin 2) : + mcNotDenote (borrowedMcNot as cs tgt) x = mcNot cs.toFinset tgt x := by + obtain _ | ⟨a, as⟩ := as + · rw [borrowedMcNot_nil] + simp [mcNotDenote_cons, mcNotDenote_nil] + · obtain _ | ⟨c, cs⟩ := cs + · simp only [List.length_nil, List.length_cons] at hlen; omega + · rw [borrowedMcNot_cons, mcNotDenote_append] + -- Distinctness facts for the sub-cascade `R = borrowedAndCascade as cs a`. + have hta : tgt ≠ a := fun h => htas (h ▸ List.mem_cons_self) + have htas' : tgt ∉ as := fun h => htas (List.mem_cons_of_mem _ h) + have htcs' : tgt ∉ cs := fun h => htcs (List.mem_cons_of_mem _ h) + have hca : c ≠ a := by rintro rfl; exact hdisj List.mem_cons_self List.mem_cons_self + have hcas : c ∉ as := fun h => hdisj List.mem_cons_self (List.mem_cons_of_mem _ h) + obtain ⟨hlen', hcs', has', hdisj', hacs', haas'⟩ := + borrowedAndCascade_step_hyps hlen hcs has hdisj + funext w + by_cases hwt : w = tgt + · subst hwt + rw [borrowedAndCascade_apply_tgt (a :: as) (c :: cs) w hlen hcs has hdisj htcs htas + (mcNotDenote (borrowedAndCascade as cs a) x), + borrowedAndCascade_apply_of_ne as cs a x hta htas', mcNot_apply_self] + congr 1 + refine ctrlBit_congr fun i hi => ?_ + rw [List.mem_toFinset] at hi + rcases List.mem_cons.mp hi with rfl | hics + · exact borrowedAndCascade_apply_of_ne as cs a x hca hcas + · exact borrowedAndCascade_apply_of_ne as cs a x (fun h => hacs' (h ▸ hics)) (hdisj' hics) + · rw [borrowedAndCascade_agree_off_tgt c htcs' htas' hta + (mcNotDenote (borrowedAndCascade as cs a) x) hwt, + borrowedAndCascade_involutive as cs a hlen' hcs' has' hdisj' hacs' haas' x, + mcNot_apply_of_ne _ _ _ hwt] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotCircuit.lean b/LeanPool/AxQM/Concrete/MultiControlledNotCircuit.lean new file mode 100644 index 0000000000..abe4717705 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotCircuit.lean @@ -0,0 +1,261 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledNot +public import Mathlib.Data.Finset.Card +public import Mathlib.Data.Fintype.Card +public import Mathlib.Data.List.Basic + +/-! +# Concrete: the recursive `O(n²)` no-work-qubit `Cⁿ(X)` circuit (N&C Exercise 4.29) + +Building on `AxQM/Concrete/MultiControlledNot.lean`, this file assembles the +**recursive halving construction** that Nielsen & Chuang, Exercise 4.29 (p. 184), asks for: a +circuit of `Toffoli`, `CNOT` and single-qubit (`NOT`) gates that implements the `n`-controlled +`NOT` `Cⁿ(X)`, using each gate at most twice-controlled and using no *clean* work qubit — the only +scratch is a **dirty borrowed wire** drawn from the register, restored after use. + +A *gate* is a pair `(S, t) : Finset (Fin m) × Fin m` denoting `mcNot S t`; a *circuit* is a +`List` of gates, denoted (`mcNotDenote`) by composing the gates' actions. The construction +(`exists_mcNotCircuit`) is: to build `mcNot S t` with `|S| ≥ 3` controls, split the controls into +two near-equal halves `A ⊔ B` (`|A| = ⌈|S|/2⌉`, `|B| = ⌊|S|/2⌋`), pick a borrowed wire `a` outside +the gate's support, and apply the dirty-borrow reduction `mcNot_union_borrow`: +`mcNot (A ∪ B) t = mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a`, +recursing on the two smaller gates `mcNot (insert a B) t` (with `⌊|S|/2⌋ + 1` controls) and +`mcNot A a` (with `⌈|S|/2⌉` controls). The recursion bottoms out at `|S| ≤ 2` — a single `Toffoli`, +`CNOT`, or `NOT`. + +The **borrowed wire is always available in the recursive calls** because after the first split each +sub-gate touches only a proper part of the register, leaving the other half (and the target) free +to borrow; the sole hypothesis is that the *top* call has at least one wire outside its support +(`(insert t S).card < m`), and this invariant is preserved downward. The gate count is bounded by +the explicit recurrence `mcNotGateBound |S|` satisfying `T(k) = 2 T(⌈k/2⌉) + 2 T(⌊k/2⌋+1)`, which +is `Θ(k²)`; the asymptotic `O(n²)` reading of this bound (an `Asymptotics.IsBigO`), and the +tight-register bootstrap that manufactures the first borrowed wire on exactly `n + 1` qubits +(Barenco's `n ≥ 4` step), are separate developments built on this one. + +Everything here is `Fin 2`/`Finset` combinatorics; each gate is realised as a genuine `Evolution`, +and the circuit as `mcCtrl n pauliXGate`, elsewhere. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-- A single reversible gate of a multiply-controlled-`NOT` circuit: the control set together with +the target wire, denoting the classical gate `mcNot S t`. With `|S| ≤ 2` this is a `Toffoli` +(`|S| = 2`), `CNOT` (`|S| = 1`), or `NOT` (`|S| = 0`). -/ +abbrev McNotGate (m : ℕ) : Type := Finset (Fin m) × Fin m + +/-- **Denotation of a gate circuit**: the reversible map on bit-strings obtained by applying each +gate's `mcNot` action in turn, the head gate acting last (leftmost in the composition). -/ +def mcNotDenote (gs : List (McNotGate m)) (x : Fin m → Fin 2) : Fin m → Fin 2 := + gs.foldr (fun g y => mcNot g.1 g.2 y) x + +@[simp] theorem mcNotDenote_nil (x : Fin m → Fin 2) : mcNotDenote [] x = x := rfl + +@[simp] theorem mcNotDenote_cons (g : McNotGate m) (gs : List (McNotGate m)) (x : Fin m → Fin 2) : + mcNotDenote (g :: gs) x = mcNot g.1 g.2 (mcNotDenote gs x) := rfl + +/-- Concatenating circuits composes their denotations (the second list acts first). -/ +@[simp] theorem mcNotDenote_append (gs hs : List (McNotGate m)) (x : Fin m → Fin 2) : + mcNotDenote (gs ++ hs) x = mcNotDenote gs (mcNotDenote hs x) := + List.foldr_append + +/-- **A reversed gate circuit inverts the original.** For a valid circuit `gs` (every gate's target +not among its controls, so each gate `mcNot g.1 g.2` is an involution, `mcNot_involutive`), running +the reversed circuit `gs.reverse` and then `gs` returns every bit-string unchanged: +`mcNotDenote gs (mcNotDenote gs.reverse x) = x`. Equivalently `gs.reverse` denotes the inverse +permutation of `gs`. Proved by induction on `gs`, folding `List.reverse_cons` through +`mcNotDenote_append`/`mcNotDenote_cons` and closing each layer with the per-gate involutivity. -/ +theorem mcNotDenote_mcNotDenote_reverse : + ∀ (gs : List (McNotGate m)), (∀ g ∈ gs, g.2 ∉ g.1) → + ∀ (x : Fin m → Fin 2), mcNotDenote gs (mcNotDenote gs.reverse x) = x + | [], _, x => by simp + | g :: gs, hgs, x => by + rw [List.reverse_cons, mcNotDenote_cons, mcNotDenote_append, mcNotDenote_cons, + mcNotDenote_nil, + mcNotDenote_mcNotDenote_reverse gs + (fun g' hg' => hgs g' (List.mem_cons_of_mem g hg')) (mcNot g.1 g.2 x)] + exact mcNot_involutive g.1 (hgs g (by simp)) x + +/-- **The gate-count bound of the halving construction**: an explicit `ℕ → ℕ` recurrence with +`T(k) = 1` for `k ≤ 2` (one base gate) and `T(k) = 2 T(⌈k/2⌉) + 2 T(⌊k/2⌋+1)` for `k ≥ 3` (two +copies each of the two sub-gates produced by `mcNot_union_borrow`). This is `Θ(k²)`; the `O(n²)` +statement of the exercise is `mcNotGateBound n = O[atTop] n²`. -/ +def mcNotGateBound : ℕ → ℕ + | k => + if 3 ≤ k then + 2 * mcNotGateBound ((k + 1) / 2) + 2 * mcNotGateBound (k / 2 + 1) + else 1 +decreasing_by + · omega + · omega + +/-- Unfolding of `mcNotGateBound` at the base cases `k ≤ 2`. -/ +theorem mcNotGateBound_of_le {k : ℕ} (hk : k ≤ 2) : mcNotGateBound k = 1 := by + rw [mcNotGateBound]; exact ite_eq_right (by omega) + +/-- Unfolding of `mcNotGateBound` at the recursive cases `k ≥ 3`. -/ +theorem mcNotGateBound_of_ge {k : ℕ} (hk : 3 ≤ k) : + mcNotGateBound k = 2 * mcNotGateBound ((k + 1) / 2) + 2 * mcNotGateBound (k / 2 + 1) := by + rw [mcNotGateBound]; exact ite_eq_left hk + +/-- **The recursive `O(n²)` `Cⁿ(X)` circuit (N&C Exercise 4.29).** For any control set `S` and +target `t ∉ S` on a register `Fin m` that has at least one wire outside the gate's support +(`(insert t S).card < m` — the borrowed wire needed to start the recursion), there is a circuit of +gates each with at most two controls (a `Toffoli`/`CNOT`/`NOT`, target never a control) whose +denotation is exactly `mcNot S t = C^{|S|}(X)`, and whose length is bounded by `mcNotGateBound |S|` +(a `Θ(|S|²)` recurrence). The construction uses the dirty borrowed-wire reduction +`mcNot_union_borrow` recursively, halving the control set; no clean work qubit is introduced. -/ +theorem exists_mcNotCircuit (S : Finset (Fin m)) (t : Fin m) + (hst : t ∉ S) (hspare : (insert t S).card < m) : + ∃ gs : List (McNotGate m), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + mcNotDenote gs = mcNot S t ∧ + gs.length ≤ mcNotGateBound S.card := by + suffices H : ∀ n : ℕ, ∀ (S : Finset (Fin m)) (t : Fin m), + S.card = n → t ∉ S → (insert t S).card < m → + ∃ gs : List (McNotGate m), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + mcNotDenote gs = mcNot S t ∧ gs.length ≤ mcNotGateBound S.card by + exact H S.card S t rfl hst hspare + intro n + induction n using Nat.strong_induction_on with + | _ n IH => + intro S t hcard hst hspare + by_cases hn : n ≤ 2 + · -- Base case: a single ≤2-control gate. + refine ⟨[(S, t)], ?_, ?_, ?_⟩ + · intro g hg + simp only [List.mem_singleton] at hg + subst hg + exact ⟨by simpa [hcard] using hn, hst⟩ + · funext x; simp [mcNotDenote] + · simp only [List.length_singleton] + rw [mcNotGateBound_of_le (hcard ▸ hn)] + · -- Recursive case: `n ≥ 3`. Split `S = A ⊔ B` and borrow a wire `a`. + have hn3 : 3 ≤ n := by omega + -- A borrowed wire `a` outside the gate's support. + have hcompl : (insert t S)ᶜ.Nonempty := by + rw [← Finset.card_pos, Finset.card_compl, Fintype.card_fin]; omega + obtain ⟨a, ha⟩ := hcompl + rw [Finset.mem_compl, Finset.mem_insert, not_or] at ha + obtain ⟨hat, haS⟩ := ha + -- The first half `A ⊆ S` of size `⌈n/2⌉`, and `B = S \ A` of size `⌊n/2⌋`. + obtain ⟨A, hAS, hAcard⟩ := Finset.exists_subset_card_eq (n := (n + 1) / 2) (s := S) + (by rw [hcard]; omega) + set B := S \ A with hB + have hAB : A ∪ B = S := Finset.union_sdiff_of_subset hAS + have hBcard : B.card = n / 2 := by + rw [hB, Finset.card_sdiff_of_subset hAS, hcard, hAcard]; omega + have haA : a ∉ A := fun h => haS (hAS h) + have haB : a ∉ B := fun h => haS (Finset.sdiff_subset h) + have htA : t ∉ A := fun h => hst (hAS h) + have htB : t ∉ B := fun h => hst (Finset.sdiff_subset h) + have htaB : t ∉ insert a B := by + rw [Finset.mem_insert, not_or]; exact ⟨fun h => hat h.symm, htB⟩ + -- Cardinalities of the two sub-gates' control sets. + have hS1card : (insert a B).card = n / 2 + 1 := by + rw [Finset.card_insert_of_notMem haB, hBcard] + have htSn : (insert t S).card = n + 1 := by rw [Finset.card_insert_of_notMem hst, hcard] + -- Spare-wire invariant is preserved for both sub-gates (their supports are smaller). + have hspare1 : (insert t (insert a B)).card < m := by + rw [Finset.card_insert_of_notMem htaB, hS1card]; omega + have hspare2 : (insert a A).card < m := by + rw [Finset.card_insert_of_notMem haA, hAcard]; omega + -- Recurse on the two sub-gates. + obtain ⟨gs₁, hgate₁, hden₁, hlen₁⟩ := + IH (n / 2 + 1) (by omega) (insert a B) t hS1card htaB hspare1 + obtain ⟨gs₂, hgate₂, hden₂, hlen₂⟩ := + IH ((n + 1) / 2) (by omega) A a hAcard haA hspare2 + -- Assemble: two copies each, matching `mcNot_union_borrow`. + refine ⟨gs₁ ++ gs₂ ++ gs₁ ++ gs₂, ?_, ?_, ?_⟩ + · simp only [List.forall_mem_append] + exact ⟨⟨⟨hgate₁, hgate₂⟩, hgate₁⟩, hgate₂⟩ + · funext x + have e := congrFun (mcNot_union_borrow A B haA haB hat htA htB) x + simp only [Function.comp_apply] at e + simp only [mcNotDenote_append, hden₁, hden₂] + rw [← hAB, e] + · simp only [List.length_append] + have hb := mcNotGateBound_of_ge hn3 + rw [hS1card] at hlen₁ + rw [hAcard] at hlen₂ + rw [hcard] + omega + +/-! ### Prepending an idle head wire to a gate circuit + +Placing a whole `≤ 2`-control gate circuit `gs` on the *tail* wires `1, …, m` of an `(m+1)`-wire +register — the head wire `0` left untouched — is, at the classical bit-string level, shifting every +gate's control set and target up by `Fin.succ`. This section supplies that reindexing and its +passthrough law, the combinatorial core of the register-level "add an idle head wire" closure of the +`Evolution` gate-count budget (`Core/CircuitBudgetOnRight`). -/ + +/-- **Prepend an idle head wire to a gate.** Shift a gate's control set and target up by `Fin.succ`, +so it acts on wires `1, …, m` of the `(m+1)`-wire register and leaves the new head wire `0` +untouched: `(S, t) ↦ (Fin.succ '' S, t.succ)`. -/ +def mcNotConsWire (g : McNotGate m) : McNotGate (m + 1) := + (g.1.map ⟨Fin.succ, Fin.succ_injective m⟩, g.2.succ) + +/-- Prepending an idle head wire preserves a gate's control count (`Fin.succ` is injective). -/ +theorem mcNotConsWire_card (g : McNotGate m) : (mcNotConsWire g).1.card = g.1.card := by + simp [mcNotConsWire] + +/-- Prepending an idle head wire preserves "the target is not a control": if `t ∉ S` then +`t.succ ∉ Fin.succ '' S`. -/ +theorem mcNotConsWire_target_not_mem {g : McNotGate m} (h : g.2 ∉ g.1) : + (mcNotConsWire g).2 ∉ (mcNotConsWire g).1 := by + simp only [mcNotConsWire, Finset.mem_map, Function.Embedding.coeFn_mk, not_exists, not_and] + intro a ha hcontra + exact h (Fin.succ_injective m hcontra ▸ ha) + +/-- The control bit of a shifted gate on `Fin.cons b x` reads the same controls as the original gate +on `x`: the new head wire `0` is not in the shifted control set, so `b` is ignored. -/ +theorem ctrlBit_map_succ_cons (S : Finset (Fin m)) (b : Fin 2) (x : Fin m → Fin 2) : + ctrlBit (S.map ⟨Fin.succ, Fin.succ_injective m⟩) (Fin.cons b x) = ctrlBit S x := by + unfold ctrlBit + have hiff : (∀ i ∈ S.map ⟨Fin.succ, Fin.succ_injective m⟩, + (Fin.cons b x : Fin (m + 1) → Fin 2) i = 1) ↔ (∀ a ∈ S, x a = 1) := by + constructor + · intro h a ha + have h2 := h a.succ (Finset.mem_map.mpr ⟨a, ha, rfl⟩) + rwa [Fin.cons_succ] at h2 + · intro h i hi + obtain ⟨a, ha, rfl⟩ := Finset.mem_map.mp hi + rw [Function.Embedding.coeFn_mk, Fin.cons_succ] + exact h a ha + exact if_congr hiff rfl rfl + +/-- **Per-gate passthrough.** A gate shifted up by `Fin.succ`, acting on `Fin.cons b x`, leaves the +head wire `b` untouched and acts as the original gate on the tail `x`: +`mcNot (Fin.succ '' S) t.succ (Fin.cons b x) = Fin.cons b (mcNot S t x)`. -/ +theorem mcNot_map_succ_cons (S : Finset (Fin m)) (t : Fin m) (b : Fin 2) (x : Fin m → Fin 2) : + mcNot (S.map ⟨Fin.succ, Fin.succ_injective m⟩) t.succ (Fin.cons b x) + = Fin.cons b (mcNot S t x) := by + unfold mcNot + rw [ctrlBit_map_succ_cons, Fin.cons_succ, Fin.cons_update] + +/-- **Circuit passthrough.** The whole shifted circuit `gs.map mcNotConsWire`, acting on +`Fin.cons b x`, passes the head wire `b` through and denotes as the original circuit `gs` on the +tail `x`: `mcNotDenote (gs.map mcNotConsWire) (Fin.cons b x) = Fin.cons b (mcNotDenote gs x)`. By +induction on `gs` from the per-gate passthrough `mcNot_map_succ_cons`. -/ +theorem mcNotDenote_map_mcNotConsWire (gs : List (McNotGate m)) (b : Fin 2) (x : Fin m → Fin 2) : + mcNotDenote (gs.map mcNotConsWire) (Fin.cons b x) = Fin.cons b (mcNotDenote gs x) := by + induction gs with + | nil => simp + | cons g gs ih => + rw [List.map_cons, mcNotDenote_cons, ih, mcNotDenote_cons] + exact mcNot_map_succ_cons g.1 g.2 b (mcNotDenote gs x) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotDirtyCascade.lean b/LeanPool/AxQM/Concrete/MultiControlledNotDirtyCascade.lean new file mode 100644 index 0000000000..1dff801f46 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotDirtyCascade.lean @@ -0,0 +1,294 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledNotCircuit + +/-! +# Concrete: the borrowed-wire AND cascade for `Cⁿ(X)` (Barenco's dirty-ancilla conditioning) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for an `O(n²)` no-work-qubit circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. The linear-cascade +sub-project reaches the `O(n²)` count (which the `Θ(k²)` halving recursion +`exists_mcNotCircuit` misses — it sums to `Θ(n³)` over `barencoNCircuit`'s `O(n)` blocks) +by bottoming each internal `Cᵏ(X)` block in a **linear** `O(k)` +number of `Toffoli`s (Barenco *Elementary gates*, Lemma 7.2/7.3). The file +`Concrete/MultiControlledNotLinearCircuit.lean` gave the **clean-ancilla** staircase (Figure 4.10); +this file supplies the **dirty-ancilla** building block, whose borrowed wires may start in an +*arbitrary* state (the wires borrowed from `barencoNCircuit`'s idle register are not clean). + +## The borrowed-wire AND cascade + +`borrowedAndCascade as cs tgt` (`as` the borrowed ancilla wires, `cs` the controls, `tgt` the +target) fuses the first control `c` **together with the first borrowed wire `a`** into `tgt` +(a `Toffoli` `({a, c}, tgt)`), recurses to flip `a` by the AND of the remaining controls `cs`, and +repeats the **same** `Toffoli` — a palindrome sandwich `T · (flip a by ⋀cs) · T`. It bottoms out +(ancillas exhausted) at a single `≤ 2`-control gate `(cs.toFinset, tgt)` fusing the last two +controls into `tgt`. + +Its decisive property (`borrowedAndCascade_apply_tgt`) is that it flips the target by the **exact** +control AND `ctrlBit cs.toFinset x`, **independently of the borrowed wires' dirty values**: the two +copies of the `Toffoli` `({a, c}, tgt)` flip `tgt` before and after `a` is transformed by +`⋀ cs`, and in `Fin 2` the dirty part of `a` cancels between them (`x a` cancels: `x a · c + (x a ⊕ +⋀cs) · c = ⋀cs · c`). This is exactly Barenco's group-commutator cancellation of a borrowed dirty +wire, here iterated down a linear cascade rather than the halving `mcNot_union_borrow`. + +The cascade is **not** itself a `Cᵏ(X)`: it flips `tgt` correctly but **corrupts** the borrowed +wires (each `aᵢ` is flipped by a partial AND). It *is* an involution +(`borrowedAndCascade_involutive`, since every wire is flipped by a control-AND independent of that +wire's own value). The genuine dirty +`Cᵏ(X)` — this cascade run **twice** with a leading `Toffoli`, so the borrowed-wire corruption +cancels and every wire is restored — is built from the involution and target-action proved here +in `AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean`. + +Everything here is `Fin 2`/`Finset`/`List` combinatorics. Compare `MultiControlledNot` and +`MultiControlledNotCircuit`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-! ### Two `ctrlBit` reformulations -/ + +/-- The control bit is set exactly when every control wire is set. -/ +theorem ctrlBit_eq_one {S : Finset (Fin m)} {x : Fin m → Fin 2} : + ctrlBit S x = 1 ↔ ∀ i ∈ S, x i = 1 := by + rw [ctrlBit] + split + · exact iff_of_true rfl ‹_› + · exact iff_of_false (by decide) ‹_› + +/-- `ctrlBit` of a two-element control set `{a, c}` in boolean-`if` form. -/ +theorem ctrlBit_pair (a c : Fin m) (x : Fin m → Fin 2) : + ctrlBit ({a, c} : Finset (Fin m)) x = if x a = 1 ∧ x c = 1 then 1 else 0 := by + rw [ctrlBit_insert]; simp only [Finset.mem_singleton, forall_eq] + +/-- `ctrlBit` of a `List`-`cons` control set factors through the head control and the tail's +`ctrlBit`: `⋀ (c :: cs) = (x c = 1) ∧ (⋀ cs = 1)`. -/ +theorem ctrlBit_cons_toFinset (c : Fin m) (cs : List (Fin m)) (x : Fin m → Fin 2) : + ctrlBit (c :: cs).toFinset x = if x c = 1 ∧ ctrlBit cs.toFinset x = 1 then 1 else 0 := by + rw [List.toFinset_cons, ctrlBit_insert] + simp only [ctrlBit_eq_one] + +/-! ### The borrowed-wire AND cascade -/ + +/-- **The borrowed-wire AND cascade** (Barenco's dirty-ancilla conditioning cascade). Given borrowed +ancilla wires `as`, controls `cs`, and target `tgt`, it fuses the first control `c` with the first +borrowed wire `a` into `tgt` (a `Toffoli` `({a, c}, tgt)`), recurses to flip `a` by the AND of the +remaining controls `cs`, and repeats the same `Toffoli`; it bottoms out (ancillas exhausted) at a +single `≤ 2`-control gate fusing the remaining controls into `tgt`. See the file docstring for its +dirty-robust target action. -/ +def borrowedAndCascade : List (Fin m) → List (Fin m) → Fin m → List (McNotGate m) + | a :: as, c :: cs, tgt => ({a, c}, tgt) :: (borrowedAndCascade as cs a ++ [({a, c}, tgt)]) + | _, cs, tgt => [(cs.toFinset, tgt)] + +/-- Base unfolding of `borrowedAndCascade` when the ancillas run out. -/ +theorem borrowedAndCascade_nil (cs : List (Fin m)) (tgt : Fin m) : + borrowedAndCascade [] cs tgt = [(cs.toFinset, tgt)] := rfl + +/-- Recursive unfolding of `borrowedAndCascade` (≥ 1 ancilla, ≥ 1 control). -/ +theorem borrowedAndCascade_cons (a : Fin m) (as : List (Fin m)) (c : Fin m) (cs : List (Fin m)) + (tgt : Fin m) : + borrowedAndCascade (a :: as) (c :: cs) tgt + = ({a, c}, tgt) :: (borrowedAndCascade as cs a ++ [({a, c}, tgt)]) := rfl + +/-- Base unfolding of `borrowedAndCascade` when the controls run out (unreached under the length +invariant `|cs| = |as| + 2`). -/ +theorem borrowedAndCascade_cons_nil (a : Fin m) (as : List (Fin m)) (tgt : Fin m) : + borrowedAndCascade (a :: as) [] tgt = [(([] : List (Fin m)).toFinset, tgt)] := rfl + +/-- **The cascade is linear.** `borrowedAndCascade as cs tgt` has at most `2 |as| + 1` gates — under +the matching invariant `|cs| = |as| + 2`, exactly `2|cs| - 3`, the linear `O(k)` `Toffoli` count of +Barenco's cascade (contrast the halving `exists_mcNotCircuit`'s `Θ(k²)`). -/ +theorem borrowedAndCascade_length_le : + ∀ (as cs : List (Fin m)) (tgt : Fin m), + (borrowedAndCascade as cs tgt).length ≤ 2 * as.length + 1 + | [], cs, tgt => by rw [borrowedAndCascade_nil]; simp + | a :: as, cs, tgt => by + obtain _ | ⟨c, cs⟩ := cs + · rw [borrowedAndCascade_cons_nil]; simp only [List.length_singleton]; omega + · rw [borrowedAndCascade_cons] + have ih := borrowedAndCascade_length_le as cs a + simp only [List.length_cons, List.length_append, List.length_nil] at ih ⊢ + omega + +/-- **The cascade fixes every non-target, non-ancilla wire.** Every gate's target is `tgt` or one of +the borrowed wires `as`, so a wire `w` outside them passes through unchanged — in particular the +controls and the ambient register are untouched. -/ +theorem borrowedAndCascade_apply_of_ne : + ∀ (as cs : List (Fin m)) (tgt : Fin m) (x : Fin m → Fin 2) {w : Fin m}, + w ≠ tgt → w ∉ as → mcNotDenote (borrowedAndCascade as cs tgt) x w = x w + | [], cs, tgt, x, w => by + intro hwt _ + rw [borrowedAndCascade_nil] + simp only [mcNotDenote_cons, mcNotDenote_nil] + exact mcNot_apply_of_ne _ _ _ hwt + | a :: as, cs, tgt, x, w => by + intro hwt hwas + obtain _ | ⟨c, cs⟩ := cs + · rw [borrowedAndCascade_cons_nil] + simp only [mcNotDenote_cons, mcNotDenote_nil] + exact mcNot_apply_of_ne _ _ _ hwt + · have hwa : w ≠ a := fun h => hwas (h ▸ List.mem_cons_self) + have hwas' : w ∉ as := fun h => hwas (List.mem_cons_of_mem _ h) + rw [borrowedAndCascade_cons, mcNotDenote_cons, mcNot_apply_of_ne _ _ _ hwt, + mcNotDenote_append, borrowedAndCascade_apply_of_ne as cs a _ hwa hwas'] + simp only [mcNotDenote_cons, mcNotDenote_nil] + exact mcNot_apply_of_ne _ _ _ hwt + +/-- **The induction-step distinctness bundle for `borrowedAndCascade`.** In the recursive layer — +controls `c :: cs`, ancillas `a :: as` — the recursive call runs on controls `cs`, ancillas `as`, +and target the peeled ancilla `a`. This packages the six invariants that call needs: the matching +length `|cs| = |as| + 2`, both `Nodup`s, disjointness, and the new target `a`'s absence from the +sub-controls and sub-ancillas. -/ +theorem borrowedAndCascade_step_hyps {a : Fin m} {as : List (Fin m)} {c : Fin m} + {cs : List (Fin m)} + (hlen : (c :: cs).length = (a :: as).length + 2) + (hcs : (c :: cs).Nodup) (has : (a :: as).Nodup) + (hdisj : (c :: cs).Disjoint (a :: as)) : + cs.length = as.length + 2 ∧ cs.Nodup ∧ as.Nodup ∧ cs.Disjoint as ∧ a ∉ cs ∧ a ∉ as := by + refine ⟨?_, (List.nodup_cons.mp hcs).2, (List.nodup_cons.mp has).2, ?_, ?_, + (List.nodup_cons.mp has).1⟩ + · simp only [List.length_cons] at hlen ⊢; omega + · exact fun w hw hwas => hdisj (List.mem_cons_of_mem _ hw) (List.mem_cons_of_mem _ hwas) + · exact fun h => hdisj (List.mem_cons_of_mem _ h) List.mem_cons_self + +/-- **Every cascade gate is a `Toffoli`/`CNOT`/`NOT`** (`≤ 2` controls, target not a control), under +the matching invariant `|cs| = |as| + 2` with all wires distinct. -/ +theorem borrowedAndCascade_gate_mem : + ∀ (as cs : List (Fin m)) (tgt : Fin m), cs.length = as.length + 2 → + cs.Nodup → as.Nodup → cs.Disjoint as → tgt ∉ cs → tgt ∉ as → + ∀ g ∈ borrowedAndCascade as cs tgt, g.1.card ≤ 2 ∧ g.2 ∉ g.1 + | [], cs, tgt => by + intro hlen _ _ _ htcs _ g hg + rw [borrowedAndCascade_nil] at hg + simp only [List.mem_singleton] at hg + obtain rfl := hg + refine ⟨?_, ?_⟩ + · calc cs.toFinset.card ≤ cs.length := List.toFinset_card_le cs + _ = 2 := by simp only [List.length_nil] at hlen; omega + · simpa using htcs + | a :: as, cs, tgt => by + intro hlen hcs has hdisj htcs htas + obtain _ | ⟨c, cs⟩ := cs + · simp only [List.length_nil, List.length_cons] at hlen; omega + · rw [borrowedAndCascade_cons] + have htc : tgt ≠ c := fun h => htcs (h ▸ List.mem_cons_self) + have hta : tgt ≠ a := fun h => htas (h ▸ List.mem_cons_self) + have hpeel : (({a, c} : Finset (Fin m))).card ≤ 2 ∧ tgt ∉ ({a, c} : Finset (Fin m)) := by + refine ⟨Finset.card_insert_le _ _ |>.trans (by simp), ?_⟩ + simp only [Finset.mem_insert, Finset.mem_singleton, not_or] + exact ⟨hta, htc⟩ + obtain ⟨hlen', hcs', has', hdisj', hacs', haas'⟩ := + borrowedAndCascade_step_hyps hlen hcs has hdisj + have ih := borrowedAndCascade_gate_mem as cs a hlen' hcs' has' hdisj' hacs' haas' + intro g hg + rcases List.mem_cons.mp hg with hg | hg + · rw [hg]; exact hpeel + rcases List.mem_append.mp hg with hg | hg + · exact ih g hg + · rw [List.mem_singleton.mp hg]; exact hpeel + +/-- **N&C Exercise 4.29 / Barenco Lemma 7.2 — the cascade flips the target by the exact control AND, +independently of the dirty borrowed wires.** With `|cs|` controls, `|cs| - 2` **arbitrary** (dirty) +borrowed ancillas `as`, and every wire distinct, `borrowedAndCascade as cs tgt` acts on the target +`tgt` exactly as `mcNot cs.toFinset tgt` — it adds the true control bit `ctrlBit cs.toFinset x`, +with **no** dependence on the ancillas' initial values. + +Proved by structural induction on `as`. In the recursive layer the two copies of the `Toffoli` +`({a, c}, tgt)` sandwich the sub-cascade that flips `a` by `⋀ cs`; the target is flipped by +`x a · x c` first and by `(x a ⊕ ⋀cs) · x c` second, and in `Fin 2` the dirty `x a` cancels, leaving +`⋀cs · x c = ⋀(c :: cs)` — Barenco's borrowed-wire group-commutator cancellation. -/ +theorem borrowedAndCascade_apply_tgt : + ∀ (as cs : List (Fin m)) (tgt : Fin m), + cs.length = as.length + 2 → cs.Nodup → as.Nodup → cs.Disjoint as → + tgt ∉ cs → tgt ∉ as → ∀ x : Fin m → Fin 2, + mcNotDenote (borrowedAndCascade as cs tgt) x tgt = x tgt + ctrlBit cs.toFinset x + | [], cs, tgt => by + intro _ _ _ _ _ _ x + rw [borrowedAndCascade_nil] + simp only [mcNotDenote_cons, mcNotDenote_nil, mcNot_apply_self] + | a :: as, cs, tgt => by + intro hlen hcs has hdisj htcs htas x + obtain _ | ⟨c, cs⟩ := cs + · simp only [List.length_nil, List.length_cons] at hlen; omega + · -- A decidable `Fin 2` identity: the dirty `x a` cancels between the two target flips. + have master : ∀ w α p g : Fin 2, + (w + (if α = 1 ∧ p = 1 then (1 : Fin 2) else 0)) + + (if (α + g) = 1 ∧ p = 1 then (1 : Fin 2) else 0) + = w + (if p = 1 ∧ g = 1 then (1 : Fin 2) else 0) := by decide + rw [borrowedAndCascade_cons] + -- Distinctness facts. + have htc : tgt ≠ c := fun h => htcs (h ▸ List.mem_cons_self) + have htcs' : tgt ∉ cs := fun h => htcs (List.mem_cons_of_mem _ h) + have hta : tgt ≠ a := fun h => htas (h ▸ List.mem_cons_self) + have htas' : tgt ∉ as := fun h => htas (List.mem_cons_of_mem _ h) + have hca : c ≠ a := by rintro rfl; exact hdisj List.mem_cons_self List.mem_cons_self + have hcas : c ∉ as := fun h => + hdisj List.mem_cons_self (List.mem_cons_of_mem _ h) + obtain ⟨hlen', hcs', has', hdisj', hacs', haas'⟩ := + borrowedAndCascade_step_hyps hlen hcs has hdisj + -- Unfold to the sub-cascade acting on the state after the tail `Toffoli`. + rw [mcNotDenote_cons, mcNotDenote_append] + simp only [mcNotDenote_cons, mcNotDenote_nil] + set x' := mcNot ({a, c} : Finset (Fin m)) tgt x with hx' + set y := mcNotDenote (borrowedAndCascade as cs a) x' with hy + -- The head `Toffoli` reads `y a`, `y c`; and `y tgt` after the sandwich. + have hx'cs : ctrlBit cs.toFinset x' = ctrlBit cs.toFinset x := by + rw [hx', mcNot] + exact ctrlBit_update_of_notMem cs.toFinset (by rwa [List.mem_toFinset]) x _ + have hya : y a = x a + ctrlBit cs.toFinset x := by + rw [hy, borrowedAndCascade_apply_tgt as cs a hlen' hcs' has' hdisj' hacs' haas' x', + hx', mcNot_apply_of_ne _ _ _ (Ne.symm hta), ← hx', hx'cs] + have hyc : y c = x c := by + rw [hy, borrowedAndCascade_apply_of_ne as cs a x' hca hcas, hx', + mcNot_apply_of_ne _ _ _ (Ne.symm htc)] + have hytgt : y tgt = x tgt + ctrlBit ({a, c} : Finset (Fin m)) x := by + rw [hy, borrowedAndCascade_apply_of_ne as cs a x' hta htas', hx', mcNot_apply_self] + rw [mcNot_apply_self, hytgt, ctrlBit_pair a c y, hya, hyc, ctrlBit_pair a c x, + ctrlBit_cons_toFinset] + exact master (x tgt) (x a) (x c) (ctrlBit cs.toFinset x) + +/-- **The cascade is an involution.** Applying `borrowedAndCascade as cs tgt` twice restores the +bit-string: every wire is flipped by a control AND independent of that wire's own value, so the +flips cancel. Proved by induction — the two outer `Toffoli`s and the sub-cascade each cancel with +their copy. This is what the follow-on dirty `Cᵏ(X)` assembly consumes to restore the borrowed wires +(running the cascade twice). -/ +theorem borrowedAndCascade_involutive : + ∀ (as cs : List (Fin m)) (tgt : Fin m), + cs.length = as.length + 2 → cs.Nodup → as.Nodup → cs.Disjoint as → + tgt ∉ cs → tgt ∉ as → ∀ x : Fin m → Fin 2, + mcNotDenote (borrowedAndCascade as cs tgt) (mcNotDenote (borrowedAndCascade as cs tgt) x) = x + | [], cs, tgt => by + intro _ _ _ _ htcs _ x + rw [borrowedAndCascade_nil] + simp only [mcNotDenote_cons, mcNotDenote_nil] + exact mcNot_involutive cs.toFinset (by rwa [List.mem_toFinset]) x + | a :: as, cs, tgt => by + intro hlen hcs has hdisj htcs htas x + obtain _ | ⟨c, cs⟩ := cs + · simp only [List.length_nil, List.length_cons] at hlen; omega + · rw [borrowedAndCascade_cons] + have htc : tgt ≠ c := fun h => htcs (h ▸ List.mem_cons_self) + have hta : tgt ≠ a := fun h => htas (h ▸ List.mem_cons_self) + have htac : tgt ∉ ({a, c} : Finset (Fin m)) := by + simp only [Finset.mem_insert, Finset.mem_singleton, not_or]; exact ⟨hta, htc⟩ + obtain ⟨hlen', hcs', has', hdisj', hacs', haas'⟩ := + borrowedAndCascade_step_hyps hlen hcs has hdisj + have ih := borrowedAndCascade_involutive as cs a hlen' hcs' has' hdisj' hacs' haas' + simp only [mcNotDenote_cons, mcNotDenote_append, mcNotDenote_nil] + rw [mcNot_involutive ({a, c} : Finset (Fin m)) htac + (mcNotDenote (borrowedAndCascade as cs a) (mcNot ({a, c} : Finset (Fin m)) tgt x)), + ih (mcNot ({a, c} : Finset (Fin m)) tgt x), + mcNot_involutive ({a, c} : Finset (Fin m)) htac x] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotGate.lean b/LeanPool/AxQM/Concrete/MultiControlledNotGate.lean new file mode 100644 index 0000000000..162feeb5e6 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotGate.lean @@ -0,0 +1,123 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PermutationGate +public import LeanPool.AxQM.Concrete.ControlledSingleQubit +public import LeanPool.AxQM.Concrete.MultiControlledNot +public import LeanPool.AxQM.Concrete.Pauli + +/-! +# Concrete: the matrix multiply-controlled `NOT` is the permutation gate of the classical `mcNot` + +The §4.3 reduction of a controlled single-qubit gate to `H, S, CNOT, Toffoli` +(`Concrete/ControlledSingleQubitABCReduction.lean`) writes an all-`1`-controlled single-qubit gate +in terms of a **multiply-controlled `NOT`** `N = ctrlSingleQubit enc j 1 pauliX` (the matrix that +flips the target bit `j` of `|enc x⟩` exactly when every other bit of `x` is `1`). That gate is a +*classical reversible* gate — a permutation of the computational basis — and this file identifies it +with the `Concrete/MultiControlledNot.lean` combinatorial multiply-controlled `NOT` +`mcNot (univ \ {j}) j` (controls = all wires but `j`, target `j`), lifted to a matrix by the +permutation gate `permGate`: + +* `AxQM.Concrete.ctrlSingleQubit_one_pauliX_eq_permGate` — **the bridge**: + `ctrlSingleQubit enc j 1 pauliX = permGate enc (mcNotPerm (univ \ {j}) j)`. The two objects agree + entrywise: the controlled-`X` gate's action on `|enc x⟩` — flip bit `j` iff all other bits are `1` + — *is* the classical `mcNot (univ \ {j}) j` truth table `x ↦ update x j (x j + ctrlBit x)` + (`ctrlBit` is `1` exactly on the all-`1`-elsewhere condition), transported through the encoding. + +This is the link that lets the whole reversible-circuit development of +`Concrete/MultiControlledNot*` (the `O(n²)` no-work-qubit `Cⁿ(X)` circuit and the Gray-code/Barenco +machinery, all phrased on bit-string permutations) be transported to the matrix multiply-controlled +`NOT` the §4.3 reduction produces, via `permGate`'s `*`-homomorphism algebra. + +Everything is stated for raw complex matrices, the encoding equivalence, the concrete gate +`ctrlSingleQubit`, `pauliX`, and the classical `mcNot`/`ctrlBit`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m d : ℕ} + +/-- **The `pauliX` block reads off bit inequality.** For `a, b : Fin 2`, +`pauliX a b = 1` when `a = b + 1` (`a ≠ b`, i.e. `X` flips the bit) and `0` otherwise. -/ +theorem pauliX_apply_eq (a b : Fin 2) : pauliX a b = if a = b + 1 then (1 : ℂ) else 0 := by + fin_cases a <;> fin_cases b <;> rfl + +/-- **The entrywise heart of the identification**, on bare bit-strings `x`, `y`, for an arbitrary +control set `S` (with `j ∉ S`): the `S`-controlled `X` gate's `(x, y)` entry — apply `pauliX` to +bit `j` when every control wire in `S` is `1`, else act as the identity — equals `1` exactly when +`x` is the classical `mcNot`-image of `y` (controls `S`, target `j`), and `0` otherwise. The +all-`1`-controlled special case is `ctrlOne_pauliX_entry` below (`S = univ \ {j}`); the subset form +is what the multiply-controlled-gate bridge `mcCtrlSingleQubit_pauliX_eq_permGate` +(`Concrete/MultiControlledSingleQubit.lean`) consumes. -/ +theorem ctrlSet_pauliX_entry (S : Finset (Fin m)) {j : Fin m} (hj : j ∉ S) (x y : Fin m → Fin 2) : + (if ∀ k, k ≠ j → x k = y k then + (if ∀ k ∈ S, x k = 1 then pauliX (x j) (y j) else if x j = y j then 1 else 0) + else 0) + = if x = mcNot S j y then (1 : ℂ) else 0 := by + by_cases hoff : ∀ k, k ≠ j → x k = y k + · rw [ite_eq_left hoff] + have hupd : (x = mcNot S j y) ↔ (x j = y j + ctrlBit S y) := by + rw [mcNot, Function.eq_update_iff] + exact ⟨fun h => h.1, fun h => ⟨h, fun k hk => hoff k hk⟩⟩ + simp only [hupd] + by_cases hctrl : ∀ k ∈ S, x k = 1 + · rw [ite_eq_left hctrl] + have hcb : ctrlBit S y = 1 := by + rw [ctrlBit, ite_eq_left] + intro k hk + rw [← hoff k (fun h => hj (h ▸ hk)), hctrl k hk] + simp only [hcb] + exact pauliX_apply_eq (x j) (y j) + · rw [ite_eq_right hctrl] + have hcb : ctrlBit S y = 0 := by + rw [ctrlBit, ite_eq_right] + intro hall + exact hctrl fun k hk => (hoff k (fun h => hj (h ▸ hk))).trans (hall k hk) + simp only [hcb, add_zero] + · rw [ite_eq_right hoff, eq_comm, ite_eq_right] + intro heq + exact hoff fun k hk => by rw [heq, mcNot_apply_of_ne _ _ _ hk] + +/-- **The all-`1`-controlled special case of `ctrlSet_pauliX_entry`** (`S = univ \ {j}`): the +all-`1`-controlled `X` gate's `(x, y)` entry equals `1` exactly when `x = mcNot (univ \ {j}) j y`. +A one-line corollary — the control condition `∀ k, k ≠ j → x k = 1` is the `S = univ \ {j}` form of +`∀ k ∈ S, x k = 1`. -/ +theorem ctrlOne_pauliX_entry (j : Fin m) (x y : Fin m → Fin 2) : + (if ∀ k, k ≠ j → x k = y k then + (if ∀ k, k ≠ j → x k = 1 then pauliX (x j) (y j) else if x j = y j then 1 else 0) + else 0) + = if x = mcNot (Finset.univ \ {j}) j y then (1 : ℂ) else 0 := by + have hiff : (∀ k, k ≠ j → x k = 1) ↔ (∀ k ∈ Finset.univ \ {j}, x k = 1) := by + constructor + · intro h k hk; rw [Finset.mem_sdiff, Finset.mem_singleton] at hk; exact h k hk.2 + · intro h k hk; exact h k (by simp [hk]) + simp only [hiff] + exact ctrlSet_pauliX_entry (Finset.univ \ {j}) (by simp) x y + +/-- **The matrix multiply-controlled `NOT` is the permutation gate of the classical `mcNot`.** +`ctrlSingleQubit enc j 1 pauliX = permGate enc (mcNotPerm (univ \ {j}) j)`: the all-`1`-controlled +`X` gate (flip target wire `j` of `|enc x⟩` iff every other wire is `1`) realises, through the +encoding `enc`, the bit-string permutation `mcNot (univ \ {j}) j`. This is the bridge that carries +the combinatorial `Cⁿ(X)` circuit development (`Concrete/MultiControlledNot*`) over to the matrix +gate. -/ +theorem ctrlSingleQubit_one_pauliX_eq_permGate (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) : + ctrlSingleQubit enc j 1 pauliX + = permGate enc (mcNotPerm (Finset.univ \ {j}) (show j ∉ Finset.univ \ {j} by simp)) := by + ext i i' + have hcond : (i = enc (mcNot (Finset.univ \ {j}) j (enc.symm i'))) + ↔ (enc.symm i = mcNot (Finset.univ \ {j}) j (enc.symm i')) := by rw [Equiv.symm_apply_eq] + simp only [ctrlSingleQubit, Matrix.of_apply, permGate_apply, mcNotPerm_apply, Pi.one_apply, hcond] + exact ctrlOne_pauliX_entry j (enc.symm i) (enc.symm i') + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotPermProduct.lean b/LeanPool/AxQM/Concrete/MultiControlledNotPermProduct.lean new file mode 100644 index 0000000000..a72d13f265 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotPermProduct.lean @@ -0,0 +1,140 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledNotGate +public import LeanPool.AxQM.Concrete.MultiControlledNotCircuit + +/-! +# Concrete: a combinatorial `mcNot` circuit lifts to a product of Toffoli/CNOT/NOT permutation gates + +The §4.3 reduction of a controlled single-qubit gate +(`Concrete/ControlledSingleQubitABCReduction.lean`) +leaves the multiply-controlled `NOT` `N = ctrlSingleQubit enc j 1 pauliX` as its only *controlled* +residue, and `Concrete/MultiControlledNotGate.lean` identifies that matrix with the permutation gate +of the classical `mcNot`: `N = permGate enc (mcNotPerm (univ \ {j}) j)`. Nielsen & Chuang, Exercise +4.29, decomposes that classical `Cⁿ(X)` into a **circuit** of `Toffoli`, `CNOT` and `NOT` gates — a +`List (McNotGate m)` of `≤ 2`-control `mcNot`s whose denotation (`mcNotDenote`) is the whole gate +(`Concrete/MultiControlledNotCircuit.lean`, `exists_mcNotCircuit`). + +This file carries that combinatorial decomposition over to the **matrix** level: a valid gate +circuit `gs` — every gate `(S, t)` with `t ∉ S`, so a genuine reversible permutation — realises the +`permGate enc (mcNotPerm S t)` as an *exact product* `Gs.prod` of the individual gates' +permutation-gate matrices, using only `permGate`'s `*`-homomorphism algebra (`permGate_one`, +`permGate_mul`). When moreover each gate has at most two controls (`S.card ≤ 2`) — the shape +`exists_mcNotCircuit` guarantees — every factor is a `Toffoli` (2 controls), `CNOT` (1) or `NOT` (0) +permutation gate, captured by the predicate `IsToffoliPermGate`; each such factor is unitary. + +## Contents + +* `IsToffoliPermGate enc G` — `G` is the permutation gate of an `mcNot` with `≤ 2` controls (a + `Toffoli`/`CNOT`/`NOT`); `IsToffoliPermGate.mem_unitaryGroup` — each is unitary. +* `exists_isToffoliPermGate_list_prod_permGate` — the inductive core: a valid gate circuit `gs` + yields a permutation `σ` with `⇑σ = mcNotDenote gs` and a matching list `Gs` of + `IsToffoliPermGate` factors with `permGate enc σ = Gs.prod`. +* `exists_isToffoliPermGate_prod_eq_mcNotPermGate` — **the bridge**: if `mcNotDenote gs = mcNot S t` + then `permGate enc (mcNotPerm S ht) = Gs.prod` for such a `Gs`. +* `exists_isToffoliPermGate_prod_eq_mcNotPermGate_of_spare` — the corollary that feeds + `exists_mcNotCircuit`'s circuit (whenever a spare wire exists) straight into the bridge. + +The all-controls case `mcNot (univ \ {j}) j` that `N` needs uses the *whole* register (no spare +wire), so its circuit is the Barenco tight-register construction — a separate (Exercise 4.29) +development — plugged into `exists_isToffoliPermGate_prod_eq_mcNotPermGate` once available. The +bridge here is exactly the reusable transport step, independent of which circuit supplies `gs`. + +Everything is stated for raw complex matrices, the encoding equivalence, `permGate`, and the +classical `mcNot`/`mcNotDenote`/`McNotGate`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m d : ℕ} + +/-- **A `≤ 2`-control reversible gate on the encoded register.** `IsToffoliPermGate enc G` holds +when `G` is the permutation gate `permGate enc (mcNotPerm S t)` of a multiply-controlled `NOT` with +at most two controls — a `Toffoli` (`|S| = 2`), `CNOT` (`|S| = 1`), or `NOT` (`|S| = 0`), the +elementary reversible gates N&C's universality reduction bottoms out in. -/ +def IsToffoliPermGate (enc : (Fin m → Fin 2) ≃ Fin d) (G : Matrix (Fin d) (Fin d) ℂ) : Prop := + ∃ (S : Finset (Fin m)) (t : Fin m) (ht : t ∉ S), S.card ≤ 2 ∧ G = permGate enc (mcNotPerm S ht) + +/-- **Every `≤ 2`-control reversible gate is unitary** — it is a permutation gate +(`permGate_mem_unitaryGroup`). This is the per-gate unitarity the §4.5.3 error-chaining calculus +consumes. -/ +theorem IsToffoliPermGate.mem_unitaryGroup {enc : (Fin m → Fin 2) ≃ Fin d} + {G : Matrix (Fin d) (Fin d) ℂ} (h : IsToffoliPermGate enc G) : + G ∈ Matrix.unitaryGroup (Fin d) ℂ := by + obtain ⟨S, t, ht, _, rfl⟩ := h + exact permGate_mem_unitaryGroup enc _ + +/-- **The inductive core of the circuit-to-matrix bridge.** A gate circuit `gs`, every gate `(S, t)` +of which has `≤ 2` controls and target `t ∉ S` (so a genuine permutation), yields a permutation `σ` +of the bit-strings whose action *is* the circuit denotation (`⇑σ = mcNotDenote gs`), together with a +list `Gs` of matrices — one per gate — every one a `Toffoli`/`CNOT`/`NOT` permutation gate +(`IsToffoliPermGate`), whose product is `permGate enc σ`. Proved by list induction: each gate +contributes its `mcNotPerm` to `σ` (composition of permutations = circuit denotation, head acting +last) and its `permGate` to `Gs`, the product identity following from `permGate`'s multiplicativity +(`permGate_mul`). -/ +theorem exists_isToffoliPermGate_list_prod_permGate (enc : (Fin m → Fin 2) ≃ Fin d) + (gs : List (McNotGate m)) (hgate : ∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) : + ∃ (σ : Equiv.Perm (Fin m → Fin 2)) (Gs : List (Matrix (Fin d) (Fin d) ℂ)), + ⇑σ = mcNotDenote gs ∧ (∀ G ∈ Gs, IsToffoliPermGate enc G) ∧ + permGate enc σ = Gs.prod := by + revert hgate + induction gs with + | nil => exact fun _ => ⟨1, [], by funext x; simp [mcNotDenote], by simp, by simp⟩ + | cons g gs ih => + intro hgate + obtain ⟨hc, hne⟩ := hgate g List.mem_cons_self + obtain ⟨σ, Gs, hσ, hGs, hprod⟩ := + ih (fun g' hg' => hgate g' (List.mem_cons_of_mem _ hg')) + refine ⟨mcNotPerm g.1 hne * σ, permGate enc (mcNotPerm g.1 hne) :: Gs, ?_, ?_, ?_⟩ + · funext x + rw [mcNotDenote_cons, Equiv.Perm.mul_apply, mcNotPerm_apply, congrFun hσ x] + · intro G hG + rcases List.mem_cons.mp hG with rfl | hG + · exact ⟨g.1, g.2, hne, hc, rfl⟩ + · exact hGs G hG + · rw [List.prod_cons, ← hprod, permGate_mul] + +/-- **The circuit-to-matrix bridge.** If a valid gate circuit `gs` (each gate `≤ 2`-controlled with +target off its controls) denotes the classical multiply-controlled `NOT` `mcNot S t` +(`mcNotDenote gs = mcNot S t`), then the matrix multiply-controlled `NOT` `permGate enc (mcNotPerm S +ht)` is an *exact product* `Gs.prod` of `Toffoli`/`CNOT`/`NOT` permutation gates. The circuit's +denotation and `mcNotPerm S ht` agree as functions, hence as permutations (`Equiv.ext`), so the +inductive core's product identity transports across. This is the reusable transport step: whichever +Exercise 4.29 circuit realises `mcNot S t` feeds straight in. -/ +theorem exists_isToffoliPermGate_prod_eq_mcNotPermGate (enc : (Fin m → Fin 2) ≃ Fin d) + {S : Finset (Fin m)} {t : Fin m} (ht : t ∉ S) (gs : List (McNotGate m)) + (hgate : ∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) (hden : mcNotDenote gs = mcNot S t) : + ∃ Gs : List (Matrix (Fin d) (Fin d) ℂ), + (∀ G ∈ Gs, IsToffoliPermGate enc G) ∧ permGate enc (mcNotPerm S ht) = Gs.prod := by + obtain ⟨σ, Gs, hσ, hGs, hprod⟩ := exists_isToffoliPermGate_list_prod_permGate enc gs hgate + refine ⟨Gs, hGs, ?_⟩ + have heq : σ = mcNotPerm S ht := + Equiv.ext fun x => by rw [mcNotPerm_apply, ← congrFun hden x, ← congrFun hσ x] + rw [← heq, hprod] + +/-- **The bridge fed by the halving `Cⁿ(X)` circuit.** For any target `t ∉ S` on a register with at +least one spare wire (`(insert t S).card < m`), the matrix multiply-controlled `NOT` +`permGate enc (mcNotPerm S ht)` is an exact product of `Toffoli`/`CNOT`/`NOT` permutation gates — +`exists_mcNotCircuit`'s combinatorial circuit fed straight into +`exists_isToffoliPermGate_prod_eq_mcNotPermGate`. (The all-controls case `mcNot (univ \ {j}) j` uses +the whole register, so is *not* covered here — it needs the Barenco tight-register circuit.) -/ +theorem exists_isToffoliPermGate_prod_eq_mcNotPermGate_of_spare (enc : (Fin m → Fin 2) ≃ Fin d) + {S : Finset (Fin m)} {t : Fin m} (ht : t ∉ S) (hspare : (insert t S).card < m) : + ∃ Gs : List (Matrix (Fin d) (Fin d) ℂ), + (∀ G ∈ Gs, IsToffoliPermGate enc G) ∧ permGate enc (mcNotPerm S ht) = Gs.prod := by + obtain ⟨gs, hgate, hden, _⟩ := exists_mcNotCircuit S t ht hspare + exact exists_isToffoliPermGate_prod_eq_mcNotPermGate enc ht gs hgate hden + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledNotSplit.lean b/LeanPool/AxQM/Concrete/MultiControlledNotSplit.lean new file mode 100644 index 0000000000..c5314dbd6f --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledNotSplit.lean @@ -0,0 +1,177 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledNotBorrowedMcNot + +/-! +# Concrete: the one-dirty-ancilla `Cᵐ(X)` split (Barenco *Elementary gates*, Lemma 7.3) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for an `O(n²)` no-work-qubit circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. The linear-cascade +sub-project reaches the `O(n²)` count by bottoming each internal `Cᵏ(X)` block of `barencoNCircuit` +in a **linear** `O(k)` number of `Toffoli`s, borrowing the register's idle wires as **dirty** +ancillas. + +`AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean` builds the dirty `Cᵏ(X)` +`borrowedMcNot as cs tgt` (Barenco Lemma 7.2): a linear circuit for the `|cs|`-controlled `NOT`, +but requiring `|cs| - 2` borrowed dirty ancillas `as`. That is exactly enough for the **small** +blocks of `barencoNCircuit V (n-1) 0`: a `Cʲ(X)` block sits with `n - j` idle module wires, so the +`j - 2` needed ancillas fit iff `j ≤ n/2 + 1`. The **large** blocks — up to the top `C^{n-1}(X)` +with a *single* idle module wire — carry too few ancillas for Lemma 7.2 directly. + +## Barenco Lemma 7.3 — the one-borrowed-wire split + +This file closes that gap with Barenco's **Lemma 7.3**: a `Cᵐ(X)` needing only **one** borrowed +dirty wire `a`, by splitting the controls into two halves `A`, `B` (`|A|, |B| ≈ m/2`) and running + +`splitMcNot asA A asB B a t = W · V · W · V`, where (reading right to left) + +* `V := borrowedMcNot asA A a` is a `C^{|A|}(X)` on the borrowed wire `a`, using `|A| - 2` wires + `asA` **taken from the other half `B`** as its dirty ancillas (idle while `V` runs); +* `W := borrowedMcNot asB (B ++ [a]) t` is a `C^{|B|+1}(X)` on the target `t`, controls + `B ∪ {a}`, using `|B| - 1` wires `asB` **taken from `A`** as its dirty ancillas. + +Because each `borrowedMcNot` restores its own borrowed ancillas +(`mcNotDenote_borrowedMcNot`), at the bit-string level the four sub-blocks collapse to the four +gates of the Barenco halving identity `mcNot_union_borrow`: +`mcNot (A ∪ B) t = mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a` +— the borrowed wire `a` is toggled by the two `mcNot A a` (restored) and its dirty part cancels +between the two `mcNot (insert a B) t`, netting `t` flipped iff every control in `A ∪ B` is set +(`mcNotDenote_splitMcNot`). Every gate is a `Toffoli`/`CNOT`/`NOT` (`splitMcNot_gate_mem`, inherited +from the four cascades) and the length is **linear**, `≤ 8|asA| + 8|asB| + 4 = O(m)` +(`splitMcNot_length_le`) — four cascades of half-size each, so `4 · O(m/2) = O(m)`. + +The one wire it must borrow (`a`) is the single idle module wire the big `barencoNCircuit` blocks +still have, so `splitMcNot` is the per-block reduction those blocks need; the two control halves +supply each other's Lemma-7.2 ancillas, so **no clean work qubit** and no extra register wire is +required. + +Everything here is `Fin 2`/`Finset`/`List` combinatorics. Compare the other `MultiControlledNot*` +files. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m : ℕ} + +/-- **The one-borrowed-wire `Cᵐ(X)` split** (Barenco *Elementary gates*, Lemma 7.3). With controls +split into two halves `A`, `B`, target `t`, and a **single** borrowed dirty wire `a`, +`splitMcNot asA A asB B a t` is the four-block circuit `W · V · W · V` (right to left): +`V := borrowedMcNot asA A a` (a `C^{|A|}(X)` on `a`, dirty ancillas `asA ⊆ B`) alternated with +`W := borrowedMcNot asB (B ++ [a]) t` (a `C^{|B|+1}(X)` on `t`, controls `B ∪ {a}`, dirty ancillas +`asB ⊆ A`). With `|A| = |asA| + 2` and `|B| = |asB| + 1` it is a genuine `C^{|A|+|B|}(X)` restoring +every wire (`mcNotDenote_splitMcNot`), in a linear number of `Toffoli`/`CNOT`/`NOT` gates using just +one borrowed dirty wire. -/ +def splitMcNot (asA A asB B : List (Fin m)) (a t : Fin m) : List (McNotGate m) := + borrowedMcNot asB (B ++ [a]) t ++ borrowedMcNot asA A a + ++ borrowedMcNot asB (B ++ [a]) t ++ borrowedMcNot asA A a + +/-- Unfolding of `splitMcNot` into its four `borrowedMcNot` blocks `W · V · W · V`. -/ +theorem splitMcNot_eq (asA A asB B : List (Fin m)) (a t : Fin m) : + splitMcNot asA A asB B a t + = borrowedMcNot asB (B ++ [a]) t ++ borrowedMcNot asA A a + ++ borrowedMcNot asB (B ++ [a]) t ++ borrowedMcNot asA A a := rfl + +/-- **The `borrowedMcNot` preconditions for the `W`-block `B ++ [a]`.** From the atomic +hypotheses on the second control half `B`, its dirty ancillas `asB`, the borrowed wire `a` +(with `|B| = |asB| + 1`), and the target `t`, the snoc control list `B ++ [a]` (controls `B ∪ {a}`) +satisfies the four `borrowedMcNot` preconditions: `|B ++ [a]| = |asB| + 2`, `Nodup`, disjointness +from `asB`, and `t` outside it. Consumed by both `mcNotDenote_splitMcNot` and `splitMcNot_gate_mem` +(and by the assembly and `Evolution` lift, which re-derive the same `B ++ [a]` +facts). -/ +theorem borrowedMcNot_snoc_hyps {asB B : List (Fin m)} {a t : Fin m} + (hBlen : B.length = asB.length + 1) (hB : B.Nodup) (hBasB : B.Disjoint asB) + (haB : a ∉ B) (haasB : a ∉ asB) (htB : t ∉ B) (hat : a ≠ t) : + (B ++ [a]).length = asB.length + 2 ∧ (B ++ [a]).Nodup ∧ + (B ++ [a]).Disjoint asB ∧ t ∉ (B ++ [a]) := by + refine ⟨?_, hB.append (List.nodup_singleton a) (List.disjoint_singleton.mpr haB), ?_, ?_⟩ + · rw [List.length_append, List.length_singleton]; omega + · rw [List.disjoint_append_left] + exact ⟨hBasB, List.singleton_disjoint.mpr haasB⟩ + · rw [List.mem_append, List.mem_singleton] + exact fun h => h.elim htB fun h' => hat h'.symm + +/-- **The one-borrowed-wire split is a genuine `Cᵐ(X)`** (Barenco Lemma 7.3). With `A` the first +control half (`|A| = |asA| + 2`, dirty ancillas `asA`), `B` the second (`|B| = |asB| + 1`, dirty +ancillas `asB`), target `t`, and one borrowed dirty wire `a` (outside `A`, `B`, `asB`, distinct +from `t`), the circuit `splitMcNot asA A asB B a t` acts on the bit-string `x` exactly as the +multiply-controlled `NOT` `mcNot (A.toFinset ∪ B.toFinset) t` — flipping only the target by the +full control AND and restoring every borrowed wire, with no dependence on any wire's dirty value. + +Proof: each of the four `borrowedMcNot` blocks restores its own dirty ancillas +(`mcNotDenote_borrowedMcNot`), so the circuit denotes as the four-gate composition +`mcNot (insert a B) t ∘ mcNot A a ∘ mcNot (insert a B) t ∘ mcNot A a`, which is Barenco's halving +identity `mcNot_union_borrow` for the single borrowed wire `a`. -/ +theorem mcNotDenote_splitMcNot (asA A asB B : List (Fin m)) (a t : Fin m) + (hAlen : A.length = asA.length + 2) (hBlen : B.length = asB.length + 1) + (hA : A.Nodup) (hasA : asA.Nodup) (hB : B.Nodup) (hasB : asB.Nodup) + (hAasA : A.Disjoint asA) (hBasB : B.Disjoint asB) + (haA : a ∉ A) (haasA : a ∉ asA) (haB : a ∉ B) (haasB : a ∉ asB) + (htA : t ∉ A) (htB : t ∉ B) (htasB : t ∉ asB) (hat : a ≠ t) + (x : Fin m → Fin 2) : + mcNotDenote (splitMcNot asA A asB B a t) x = mcNot (A.toFinset ∪ B.toFinset) t x := by + -- The `W`-block `borrowedMcNot asB (B ++ [a]) t` obligations, derived from the atomic hypotheses. + obtain ⟨hWlen, hWnd, hWdisj, hWt⟩ := borrowedMcNot_snoc_hyps hBlen hB hBasB haB haasB htB hat + -- The four blocks, each replaced by its net `mcNot` (dirty ancillas restored). + have hV : ∀ y : Fin m → Fin 2, mcNotDenote (borrowedMcNot asA A a) y = mcNot A.toFinset a y := + fun y => mcNotDenote_borrowedMcNot asA A a hAlen hA hasA hAasA haA haasA y + have hW : ∀ y : Fin m → Fin 2, + mcNotDenote (borrowedMcNot asB (B ++ [a]) t) y = mcNot (B ++ [a]).toFinset t y := + fun y => mcNotDenote_borrowedMcNot asB (B ++ [a]) t hWlen hWnd hasB hWdisj hWt htasB y + -- `(B ++ [a]).toFinset = insert a B.toFinset`. + have hBa : (B ++ [a]).toFinset = insert a B.toFinset := by + rw [List.toFinset_append, List.toFinset_cons, List.toFinset_nil, + Finset.insert_eq, Finset.union_comm] + simp + -- The `mcNot_union_borrow` hypotheses, as `Finset` membership. + have haA' : a ∉ A.toFinset := by rwa [List.mem_toFinset] + have haB' : a ∉ B.toFinset := by rwa [List.mem_toFinset] + have htA' : t ∉ A.toFinset := by rwa [List.mem_toFinset] + have htB' : t ∉ B.toFinset := by rwa [List.mem_toFinset] + rw [splitMcNot_eq] + simp only [mcNotDenote_append, hV, hW, hBa] + rw [mcNot_union_borrow A.toFinset B.toFinset haA' haB' hat htA' htB'] + simp only [Function.comp_apply] + +/-- **Every gate of the one-borrowed-wire split is a `Toffoli`/`CNOT`/`NOT`** (`≤ 2` controls, +target not a control), inherited from the four `borrowedMcNot` cascades it concatenates. -/ +theorem splitMcNot_gate_mem (asA A asB B : List (Fin m)) (a t : Fin m) + (hAlen : A.length = asA.length + 2) (hBlen : B.length = asB.length + 1) + (hA : A.Nodup) (hasA : asA.Nodup) (hB : B.Nodup) (hasB : asB.Nodup) + (hAasA : A.Disjoint asA) (hBasB : B.Disjoint asB) + (haA : a ∉ A) (haasA : a ∉ asA) (haB : a ∉ B) (haasB : a ∉ asB) + (htB : t ∉ B) (htasB : t ∉ asB) (hat : a ≠ t) : + ∀ g ∈ splitMcNot asA A asB B a t, g.1.card ≤ 2 ∧ g.2 ∉ g.1 := by + obtain ⟨hWlen, hWnd, hWdisj, hWt⟩ := borrowedMcNot_snoc_hyps hBlen hB hBasB haB haasB htB hat + have hVmem := borrowedMcNot_gate_mem asA A a hAlen hA hasA hAasA haA haasA + have hWmem := borrowedMcNot_gate_mem asB (B ++ [a]) t hWlen hWnd hasB hWdisj hWt htasB + intro g hg + rw [splitMcNot_eq, List.mem_append, List.mem_append, List.mem_append] at hg + rcases hg with (((h | h) | h) | h) + · exact hWmem g h + · exact hVmem g h + · exact hWmem g h + · exact hVmem g h + +/-- **The one-borrowed-wire split is linear.** `splitMcNot asA A asB B a t` has at most +`8|asA| + 8|asB| + 4` gates — two copies each of the two `borrowedMcNot` cascades +(`≤ 4|asA| + 1` and `≤ 4|asB| + 1`). With `|asA| = |A| - 2` and `|asB| = |B| - 1` this is +`O(|A| + |B|) = O(m)` for `m = |A| + |B|` controls: four half-size cascades, `4 · O(m/2) = O(m)`. -/ +theorem splitMcNot_length_le (asA A asB B : List (Fin m)) (a t : Fin m) : + (splitMcNot asA A asB B a t).length ≤ 8 * asA.length + 8 * asB.length + 4 := by + rw [splitMcNot_eq] + simp only [List.length_append] + have hV := borrowedMcNot_length_le asA A a + have hW := borrowedMcNot_length_le asB (B ++ [a]) t + omega + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledSingleQubit.lean b/LeanPool/AxQM/Concrete/MultiControlledSingleQubit.lean new file mode 100644 index 0000000000..656a63cb16 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledSingleQubit.lean @@ -0,0 +1,282 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.SingleQubitWire +public import LeanPool.AxQM.Concrete.MultiControlledNotGate + +/-! +# Concrete: the multiply-controlled single-qubit gate `Cᵏ(U₀)` (N&C §4.3 / Barenco) + +The §4.3 reduction of a controlled single-qubit gate to `H, S, CNOT, Toffoli`, and in particular the +Barenco *no-work-qubit* `Cⁿ(X)` construction (Exercise 4.30 / Barenco *et al.* Lemma 7.5), express a +multiply-controlled gate as a product of *smaller* multiply-controlled gates whose controls are +proper **subsets** of the wires — for `Cⁿ(X) = Cⁿ(V²)` (with `V = √X`), + +`Cⁿ(X) = C(V)·Cⁿ⁻¹(X)·C(V†)·Cⁿ⁻¹(X)·Cⁿ⁻¹(V)`, + +whose factors are gates controlled on one wire (`C(V)`, `C(V†)`) and on `n − 1` wires +(`Cⁿ⁻¹(X)`, `Cⁿ⁻¹(V)`). The two existing matrix objects are the extremes of the control range: +`ctrlSingleQubit enc j 1 U₀` is controlled on **every** wire but `j`, and `singleQubitOnWire enc j +g` +is controlled on **no** wire. This file supplies the object that interpolates them — the +**subset-controlled single-qubit gate** every Barenco factor is an instance of. + +## The construction + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d`, a control set `S : Finset (Fin m)`, a target wire +`j`, and a `2 × 2` matrix `U₀`: + +* `AxQM.Concrete.mcCtrlSingleQubit enc S j U₀` — on the basis state `|enc x⟩` it applies `U₀` + to bit `j` of `x` when **every control wire in `S` is `1`**, and fixes `|enc x⟩` otherwise. It is + the fibrewise gate (`wireGate`) whose `2 × 2` block is `U₀` on the fibres passing the control + condition and the identity elsewhere. + +## The algebra + +Through the general fibrewise-gate lemmas (`wireGate_*`, incl. `wireGate_conjTranspose`, all in +`ControlledSingleQubit.lean`) it is a `*`-homomorphism in the block on a *fixed* control set `S`: + +* `mcCtrlSingleQubit_one`, `mcCtrlSingleQubit_mul`, `mcCtrlSingleQubit_conjTranspose` + — identity/product/adjoint respect the block, so a unitary block gives a unitary gate + (`mcCtrlSingleQubit_mem_unitaryGroup`). +* `mcCtrlSingleQubit_mulVec_of_ctrl` / `mcCtrlSingleQubit_mulVec_of_not_ctrl` (for `j ∉ S`) — the + controlled action: `U₀`-mix the two active components when the controls are satisfied, fix the + basis state otherwise. + +It **interpolates** the two extreme gates: + +* `mcCtrlSingleQubit_empty` — with no controls it is `singleQubitOnWire enc j U₀`. +* `mcCtrlSingleQubit_univ_sdiff` — controlled on all wires but `j` it is the all-`1`-controlled gate + `ctrlSingleQubit enc j 1 U₀`. + +## The permutation bridge for the `NOT` block + +Its Pauli-`X` instance is a *classical reversible* gate — the permutation gate of the combinatorial +multiply-controlled `NOT`: + +* `mcCtrlSingleQubit_pauliX_eq_permGate` (for `j ∉ S`) — + `mcCtrlSingleQubit enc S j pauliX = permGate enc (mcNotPerm S j)`, generalising + `ctrlSingleQubit_one_pauliX_eq_permGate` (its `S = univ \ {j}` case) to an arbitrary control set. + This is exactly the bridge that carries every spare-wire `Cⁿ⁻¹(X)` sub-gate of the Barenco + reduction into the combinatorial `Cⁿ(X)` circuit development (`Concrete/MultiControlledNot*`) — + through `permGate`'s `*`-homomorphism — hence into a product of `Toffoli`/`CNOT`/`NOT` gates. Its + entrywise heart is `ctrlSet_pauliX_entry` (in `Concrete/MultiControlledNotGate.lean`), the + `S`-general form of `ctrlOne_pauliX_entry` — which the all-`1`-controlled special case now + derives from, so the case analysis is written once. + +## Use + +These results are reused by the tight-register `Cⁿ(X)` reduction of Exercise 4.43 +([upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean)). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m d : ℕ} + +/-- **The multiply-controlled single-qubit gate** `Cᵏ(U₀)` (`k = |S|`). Relative to an encoding +`enc : (Fin m → Fin 2) ≃ Fin d`, a control set `S`, a target wire `j`, and a `2 × 2` matrix `U₀`, on +the basis state `|enc x⟩` it applies `U₀` to bit `j` of `x` when every control wire in `S` is set to +`1`, and acts as the identity otherwise. It is the fibrewise gate whose block is `U₀` on the +controlled fibres and `1` elsewhere — the object every factor of the Barenco `Cⁿ(X)` reduction is an +instance of. -/ +def mcCtrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (j : Fin m) + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : Matrix (Fin d) (Fin d) ℂ := + wireGate enc j (fun y => if ∀ k ∈ S, y k = 1 then U₀ else 1) + +/-- On a control set `S` with `j ∉ S`, evaluating the control condition at the fibre representative +`(enc.symm i)[j ↦ v]` is the same as evaluating it at `enc.symm i`: bit `j` is not a control. -/ +theorem ctrl_update_iff {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) (x : Fin m → Fin 2) + (v : Fin 2) : (∀ k ∈ S, Function.update x j v k = 1) ↔ (∀ k ∈ S, x k = 1) := + forall_congr' fun k => imp_congr_right fun hk => by + have hkj : k ≠ j := fun h => hj (h ▸ hk) + rw [Function.update_of_ne hkj] + +/-- **The block algebra is multiplicative on a fixed control set**: +`mcCtrlSingleQubit enc S j P * mcCtrlSingleQubit enc S j Q = mcCtrlSingleQubit enc S j (P * Q)`. On +each fibre the control condition is fixed, so the two blocks (`if · then P else 1` and its `Q` +analogue) multiply to `if · then P*Q else 1`. -/ +theorem mcCtrlSingleQubit_mul (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (j : Fin m) + (P Q : Matrix (Fin 2) (Fin 2) ℂ) : + mcCtrlSingleQubit enc S j P * mcCtrlSingleQubit enc S j Q + = mcCtrlSingleQubit enc S j (P * Q) := by + rw [mcCtrlSingleQubit, mcCtrlSingleQubit, mcCtrlSingleQubit, wireGate_mul] + congr 1 + funext y + by_cases h : ∀ k ∈ S, y k = 1 + · rw [ite_eq_left h, ite_eq_left h, ite_eq_left h] + · rw [ite_eq_right h, ite_eq_right h, ite_eq_right h, mul_one] + +/-- **The multiply-controlled gate of the identity block is the identity.** -/ +theorem mcCtrlSingleQubit_one (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (j : Fin m) : + mcCtrlSingleQubit enc S j (1 : Matrix (Fin 2) (Fin 2) ℂ) = 1 := by + rw [mcCtrlSingleQubit] + simp only [ite_self, wireGate_one] + +/-- **The multiply-controlled gate commutes with the conjugate transpose**: +`(mcCtrlSingleQubit enc S j U₀)ᴴ = mcCtrlSingleQubit enc S j U₀ᴴ` (via `wireGate_conjTranspose`, +using +`1ᴴ = 1`). -/ +theorem mcCtrlSingleQubit_conjTranspose (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) + (j : Fin m) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + (mcCtrlSingleQubit enc S j U₀)ᴴ = mcCtrlSingleQubit enc S j U₀ᴴ := by + rw [mcCtrlSingleQubit, mcCtrlSingleQubit, wireGate_conjTranspose] + congr 1 + funext y + simp only [apply_ite Matrix.conjTranspose, Matrix.conjTranspose_one] + +/-- **A multiply-controlled single-qubit gate with unitary block is unitary.** Follows from the +`*`-homomorphism laws: `(C(U₀))ᴴ · C(U₀) = C(U₀ᴴ · U₀) = C(1) = 1`. -/ +theorem mcCtrlSingleQubit_mem_unitaryGroup (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) + (j : Fin m) {U₀ : Matrix (Fin 2) (Fin 2) ℂ} (hU₀ : U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + mcCtrlSingleQubit enc S j U₀ ∈ Matrix.unitaryGroup (Fin d) ℂ := by + rw [Matrix.mem_unitaryGroup_iff'] at hU₀ ⊢ + rw [Matrix.star_eq_conjTranspose] at hU₀ ⊢ + rw [mcCtrlSingleQubit_conjTranspose, mcCtrlSingleQubit_mul, hU₀, mcCtrlSingleQubit_one] + +/-- **`mcCtrlSingleQubit enc S j` is continuous** in its `2 × 2` block: each matrix entry is either +the constant `0`, a constant entry of the identity, or a single continuous entry of `U₀` (the +control +condition and the fibre condition do not depend on `U₀`). The continuity lemma for the whole +fibrewise family — every consumer that transports a closure/limit of `2 × 2` blocks through the +placement (e.g. the Deutsch-gate density transports, `Concrete/DeutschWirePlacement.lean`) cites +it. -/ +theorem continuous_mcCtrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) + (j : Fin m) : + Continuous (fun U₀ : Matrix (Fin 2) (Fin 2) ℂ => mcCtrlSingleQubit enc S j U₀) := by + apply continuous_matrix + intro i i' + simp only [mcCtrlSingleQubit, wireGate, Matrix.of_apply] + split_ifs + · exact (continuous_apply _).comp (continuous_apply _) + · exact continuous_const + · exact continuous_const + +/-- **No controls: the multiply-controlled gate is the uncontrolled single-qubit wire gate.** +`mcCtrlSingleQubit enc ∅ j U₀ = singleQubitOnWire enc j U₀` — one endpoint of the control range. -/ +theorem mcCtrlSingleQubit_empty (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + mcCtrlSingleQubit enc (∅ : Finset (Fin m)) j U₀ = singleQubitOnWire enc j U₀ := by + rw [singleQubitOnWire_eq_wireGate, mcCtrlSingleQubit] + congr 1 + funext y + rw [ite_eq_left (by simp)] + +/-- **Every wire but `j` a control: the multiply-controlled gate is the all-`1`-controlled gate.** +`mcCtrlSingleQubit enc (univ \ {j}) j U₀ = ctrlSingleQubit enc j 1 U₀` — the other endpoint of the +control range. -/ +theorem mcCtrlSingleQubit_univ_sdiff (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (U₀ : Matrix (Fin 2) (Fin 2) ℂ) : + mcCtrlSingleQubit enc (Finset.univ \ {j}) j U₀ = ctrlSingleQubit enc j 1 U₀ := by + rw [ctrlSingleQubit_eq_wireGate, mcCtrlSingleQubit] + congr 1 + funext y + by_cases h : ∀ k ∈ Finset.univ \ {j}, y k = 1 + · rw [ite_eq_left h, ite_eq_left] + intro k hk + rw [Pi.one_apply] + exact h k (by simp [hk]) + · rw [ite_eq_right h, ite_eq_right] + intro hc + exact h fun k hk => by + rw [Finset.mem_sdiff, Finset.mem_singleton] at hk + simpa using hc k hk.2 + +/-- **The controlled action, controls satisfied.** When every control wire in `S` is `1` +(`j ∉ S`), the gate mixes only the two components differing in bit `j` through `U₀`. -/ +theorem mcCtrlSingleQubit_mulVec_of_ctrl (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} + {j : Fin m} (hj : j ∉ S) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) + (h : ∀ k ∈ S, enc.symm i k = 1) : + (mcCtrlSingleQubit enc S j U₀ *ᵥ v) i = + U₀ (enc.symm i j) 0 * v (enc (Function.update (enc.symm i) j 0)) + + U₀ (enc.symm i j) 1 * v (enc (Function.update (enc.symm i) j 1)) := by + rw [mcCtrlSingleQubit, wireGate_mulVec, ite_eq_left ((ctrl_update_iff hj _ 0).mpr h)] + +/-- **The controlled action, controls not satisfied.** When some control wire in `S` is `0` +(`j ∉ S`), the gate fixes the basis state `|enc x⟩` at `i`. -/ +theorem mcCtrlSingleQubit_mulVec_of_not_ctrl (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} + {j : Fin m} (hj : j ∉ S) (U₀ : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) + (h : ¬ ∀ k ∈ S, enc.symm i k = 1) : + (mcCtrlSingleQubit enc S j U₀ *ᵥ v) i = v i := by + rw [mcCtrlSingleQubit, wireGate_mulVec, + ite_eq_right (fun hup => h ((ctrl_update_iff hj _ 0).mp hup))] + rcases (by omega : enc.symm i j = 0 ∨ enc.symm i j = 1) with ha | ha + · have hself : Function.update (enc.symm i) j 0 = enc.symm i := by + rw [← ha, Function.update_eq_self] + rw [ha, Matrix.one_apply_eq, Matrix.one_apply_ne (by decide), hself, Equiv.apply_symm_apply] + ring + · have hself : Function.update (enc.symm i) j 1 = enc.symm i := by + rw [← ha, Function.update_eq_self] + rw [ha, Matrix.one_apply_ne (by decide), Matrix.one_apply_eq, hself, Equiv.apply_symm_apply] + ring + +/-- Two distinct basis indices agreeing off wire `w` disagree at `w` — from injectivity of the +encoding equivalence `enc`. The single fact the diagonal/fibrewise gate lemmas use to discharge +their off-diagonal (`i ≠ i'`) entry. -/ +theorem enc_symm_ne_of_off (enc : (Fin m → Fin 2) ≃ Fin d) {i i' : Fin d} {w : Fin m} + (hii : i ≠ i') (hoff : ∀ k, k ≠ w → enc.symm i k = enc.symm i' k) : + enc.symm i w ≠ enc.symm i' w := fun hw => + hii (enc.symm.injective (funext fun k => by + rcases eq_or_ne k w with rfl | hk + · exact hw + · exact hoff k hk)) + +/-- **A subset-controlled diagonal single-qubit gate is diagonal.** For `j ∉ S`, +`mcCtrlSingleQubit enc S j (diagonal w)` multiplies `|enc x⟩` by `w (x_j)` when every control wire +in `S` is set and by `1` otherwise — the diagonal matrix +`diagonal (fun i => if ∀ k ∈ S, x_k = 1 then w (x_j) else 1)`. The general form of the diagonal +block; its global-phase special case is `mcCtrlSingleQubit_smul_one_eq_diagonal` (`z • 1`), and its +`Rₖ` instance makes the quantum-Fourier-transform circuit's conditional rotations simultaneously +diagonal (`Concrete/QftGateCircuitCorrectness.lean`). -/ +theorem mcCtrlSingleQubit_diagonal (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {j : Fin m} + (hj : j ∉ S) (w : Fin 2 → ℂ) : + mcCtrlSingleQubit enc S j (Matrix.diagonal w) + = Matrix.diagonal fun i => if ∀ k ∈ S, enc.symm i k = 1 then w (enc.symm i j) else 1 := by + ext i i' + rw [mcCtrlSingleQubit, wireGate_apply, Matrix.diagonal_apply] + simp only [ctrl_update_iff hj] + by_cases hii : i = i' + · subst hii + rw [ite_eq_left (fun k _ => rfl), ite_eq_left rfl] + by_cases hC : ∀ k ∈ S, enc.symm i k = 1 + · rw [ite_eq_left hC, ite_eq_left hC, Matrix.diagonal_apply_eq] + · rw [ite_eq_right hC, ite_eq_right hC, Matrix.one_apply_eq] + · rw [ite_eq_right hii] + by_cases hbits : ∀ k : Fin m, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hbits] + have hjne : enc.symm i j ≠ enc.symm i' j := enc_symm_ne_of_off enc hii hbits + rw [apply_ite (fun M : Matrix (Fin 2) (Fin 2) ℂ => M (enc.symm i j) (enc.symm i' j)), + Matrix.diagonal_apply_ne _ hjne, Matrix.one_apply_ne hjne, ite_self] + · rw [ite_eq_right hbits] + +/-- **The multiply-controlled `NOT` matrix is the permutation gate of the classical `mcNot`.** +For `j ∉ S`, `mcCtrlSingleQubit enc S j pauliX = permGate enc (mcNotPerm S j)`: the `S`-controlled +`X` gate (flip target wire `j` of `|enc x⟩` iff every control wire in `S` is `1`) realises, through +the encoding, the bit-string permutation `mcNot S j`. This generalises +`ctrlSingleQubit_one_pauliX_eq_permGate` (the `S = univ \ {j}` case) and is the bridge carrying a +spare-wire `Cⁿ⁻¹(X)` sub-gate of the Barenco reduction into the combinatorial `Cⁿ(X)` circuit +development. -/ +theorem mcCtrlSingleQubit_pauliX_eq_permGate (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) + {j : Fin m} (hj : j ∉ S) : + mcCtrlSingleQubit enc S j pauliX = permGate enc (mcNotPerm S hj) := by + ext i i' + have hcond : (i = enc (mcNot S j (enc.symm i'))) ↔ (enc.symm i = mcNot S j (enc.symm i')) := by + rw [Equiv.symm_apply_eq] + rw [mcCtrlSingleQubit, wireGate_apply, permGate_apply, mcNotPerm_apply] + simp only [hcond, ctrl_update_iff hj (enc.symm i) 0, + apply_ite (fun M : Matrix (Fin 2) (Fin 2) ℂ => M (enc.symm i j) (enc.symm i' j)), + Matrix.one_apply] + exact ctrlSet_pauliX_entry S hj (enc.symm i) (enc.symm i') + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledSingleQubitABCReduction.lean b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitABCReduction.lean new file mode 100644 index 0000000000..652234cc4c --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitABCReduction.lean @@ -0,0 +1,223 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubit +public import LeanPool.AxQM.Concrete.ABCDecomposition + +/-! +# Concrete: the controlled-`ABC` reduction of a *subset*-controlled single-qubit gate (N&C §4.3) + +(Nielsen & Chuang §4.3, p. 176–182 — Corollary 4.2, for an arbitrary control set.) + +The Barenco tight-register recursion (`Concrete/MultiControlledSingleQubitBarenco.lean`) factors +`Cⁿ(X)` into *subset*-controlled single-qubit gates `mcCtrlSingleQubit enc S j U₀` — a `2 × 2` gate +`U₀` on wire `j`, controlled on the wires in `S`. To bottom the recursion out over +`H, S, CNOT, Toffoli`, each such factor must in turn be reduced to uncontrolled single-qubit gates +and multiply-controlled `NOT`s. This file supplies that reduction — the subset-controlled +generalisation of the all-`1`-controlled `ctrlSingleQubit_one_eq_abc` / +`exists_abc_reduction_ctrlSingleQubit_one` (`Concrete/ControlledSingleQubitABCReduction.lean`, its +`S = univ \ {j}` case) — together with the *peel* that discharges the ABC phase residual. + +## The ABC reduction + +* `AxQM.Concrete.mcCtrlSingleQubit_eq_abc` — **the controlled-`ABC` identity** (N&C + Corollary 4.2, subset-controlled): for any `2 × 2` matrices `A, B, C, X` with `A B C = I`, + `mcCtrlSingleQubit enc S j (A X B X C) + = singleQubitOnWire enc j A · N · singleQubitOnWire enc j B · N · singleQubitOnWire enc j C`, + where `N = mcCtrlSingleQubit enc S j X` is the subset-controlled gate with block `X`. On the + `S`-controlled fibres both `N`s fire (as `X`), so wire `j` sees `A X B X C`; off them both `N`s + are the identity, so wire `j` sees `A B C = I` and the gate is trivial — the mechanism by which + two subset-controlled-`NOT`s and three *uncontrolled* single-qubit gates realise a controlled + gate. +* `AxQM.Concrete.exists_abc_reduction_mcCtrlSingleQubit` — **the reduction of a general + subset-controlled single-qubit gate**: for any `U₀ ∈ U(2)`, the ABC decomposition + (`exists_abc_decomposition`, `U₀ = e^{iα} A X B X C`, `A B C = I`) gives + `mcCtrlSingleQubit enc S j U₀ = mcCtrlSingleQubit enc S j (e^{iα} • 1) · + (singleQubitOnWire enc j A · N · singleQubitOnWire enc j B · N · singleQubitOnWire enc j C)` with + `N = mcCtrlSingleQubit enc S j pauliX`. This exhibits the gate as three uncontrolled single-qubit + gates on wire `j`, two subset-controlled-`NOT`s, and one subset-controlled *phase* gate. + +## The phase-residual peel + +The residual `mcCtrlSingleQubit enc S j (e^{iα} • 1)` applies the global phase `e^{iα}` to the +target fibre exactly when every control in `S` is set — a phase applied to the whole `S`-controlled +subspace, *independent of the target value*. N&C realises it by peeling one control: the same +diagonal gate is a controlled **phase-block** gate `diag(1, e^{iα})` on one of the former control +wires, with one fewer control. + +* `AxQM.Concrete.phaseGate z` — the `2 × 2` phase-block gate `diag(1, z)`; unitary for + `z_bar z = 1` (`phaseGate_mem_unitaryGroup`), so `phaseGate (e^{iα})` is a legitimate single-qubit + gate. +* `AxQM.Concrete.mcCtrlSingleQubit_phase_peel` — **the phase peel**: for `c ∈ S`, `j ∉ S`, + `mcCtrlSingleQubit enc S j (z • 1) = mcCtrlSingleQubit enc (S.erase c) c (phaseGate z)`. The + target moves from `j` to the former control wire `c`, and the control set shrinks by one. + Iterating bottoms the phase out at the uncontrolled `singleQubitOnWire enc c (phaseGate z)` (via + `mcCtrlSingleQubit_empty`), and the phase-block gate itself, being a single-qubit unitary, + recurses through the ABC reduction above — so the ABC reduction and this peel together are the + "recurse into smaller multiply-controlled gates" step of the §4.3 reduction. Both sides are proved + equal to the common diagonal matrix `diag(fun i => if all of S set then z else 1)` + (`mcCtrlSingleQubit_smul_one_eq_diagonal`, `mcCtrlSingleQubit_phaseGate_eq_diagonal`). + +## Use + +These results are reused by the tight-register `Cⁿ(X)` reduction of Exercise 4.43 +([upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean)). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The controlled-`ABC` identity for a subset-controlled single-qubit gate** (Nielsen & Chuang, +Corollary 4.2, for an arbitrary control set `S`). For any `2 × 2` matrices `A, B, C, X` with +`A B C = I`, `mcCtrlSingleQubit enc S j (A X B X C) = singleQubitOnWire enc j A · N · +singleQubitOnWire enc j B · N · singleQubitOnWire enc j C`, where `N = mcCtrlSingleQubit enc S j X`. +On the `S`-controlled fibres both `N`s fire (as `X`), so wire `j` sees `A X B X C`; off them both +`N`s are the identity, so wire `j` sees `A B C = I` and nothing happens. The all-`1`-controlled +`ctrlSingleQubit_one_eq_abc` is the `S = univ \ {j}` case. -/ +theorem mcCtrlSingleQubit_eq_abc (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (j : Fin m) + (A B C X : Matrix (Fin 2) (Fin 2) ℂ) (hABC : A * B * C = 1) : + mcCtrlSingleQubit enc S j (A * X * B * X * C) + = singleQubitOnWire enc j A * mcCtrlSingleQubit enc S j X + * singleQubitOnWire enc j B * mcCtrlSingleQubit enc S j X + * singleQubitOnWire enc j C := by + simp only [singleQubitOnWire_eq_wireGate, mcCtrlSingleQubit, wireGate_mul] + congr 1 + funext y + by_cases h : ∀ k ∈ S, y k = 1 + · simp only [ite_eq_left h] + · simp only [ite_eq_right h, mul_one, hABC] + +/-- **The reduction of a general subset-controlled single-qubit gate** (Nielsen & Chuang §4.3). For +any single-qubit unitary `U₀`, the ABC decomposition (`exists_abc_decomposition`) yields real phase +`α` and unitaries `A, B, C` with `A B C = I` such that `mcCtrlSingleQubit enc S j U₀ = +mcCtrlSingleQubit enc S j (e^{iα} • 1) · (singleQubitOnWire enc j A · N · singleQubitOnWire enc j B +· N · singleQubitOnWire enc j C)`, with `N = mcCtrlSingleQubit enc S j pauliX`. This exhibits the +gate as three uncontrolled single-qubit gates on wire `j`, two subset-controlled-`NOT`s, and one +subset-controlled phase gate — the §4.3 reduction step the Barenco recursion factors feed into. -/ +theorem exists_abc_reduction_mcCtrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) + (j : Fin m) {U₀ : Matrix (Fin 2) (Fin 2) ℂ} (hU₀ : U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ (α : ℝ) (A B C : Matrix (Fin 2) (Fin 2) ℂ), + A ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ B ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ + C ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ + mcCtrlSingleQubit enc S j U₀ + = mcCtrlSingleQubit enc S j (Complex.exp ((α : ℂ) * Complex.I) • 1) + * (singleQubitOnWire enc j A * mcCtrlSingleQubit enc S j pauliX + * singleQubitOnWire enc j B * mcCtrlSingleQubit enc S j pauliX + * singleQubitOnWire enc j C) := by + obtain ⟨α, A, B, C, hA, hB, hC, hABC, hU⟩ := exists_abc_decomposition U₀ hU₀ + refine ⟨α, A, B, C, hA, hB, hC, ?_⟩ + rw [hU, ← smul_one_mul, ← mcCtrlSingleQubit_mul, + mcCtrlSingleQubit_eq_abc enc S j A B C pauliX hABC] + +/-- **The `2 × 2` phase-block gate** `diag(1, z)`. For `z = e^{iα}` (`z_bar z = 1`) it is a unitary +single-qubit gate (`phaseGate_mem_unitaryGroup`); it is the block the subset-controlled *phase* +residual of the ABC reduction peels one control off into (`mcCtrlSingleQubit_phase_peel`). -/ +def phaseGate (z : ℂ) : Matrix (Fin 2) (Fin 2) ℂ := !![1, 0; 0, z] + +/-- The phase-block gate as a diagonal matrix, `diag(1, z) = Matrix.diagonal ![1, z]`. -/ +theorem phaseGate_eq_diagonal (z : ℂ) : phaseGate z = Matrix.diagonal ![1, z] := by + ext a b + fin_cases a <;> fin_cases b <;> simp [phaseGate, Matrix.diagonal] + +/-- The diagonal entries of the phase-block gate: `diag(1, z) 0 0 = 1`, `diag(1, z) 1 1 = z`. -/ +theorem phaseGate_apply_diag (z : ℂ) (a : Fin 2) : phaseGate z a a = if a = 0 then 1 else z := by + fin_cases a <;> simp [phaseGate] + +/-- The phase-block gate is diagonal: off-diagonal entries vanish. -/ +theorem phaseGate_apply_of_ne (z : ℂ) {a b : Fin 2} (h : a ≠ b) : phaseGate z a b = 0 := by + fin_cases a <;> fin_cases b <;> simp_all [phaseGate] + +/-- **The phase-block gate is unitary when `z_bar z = 1`** (e.g. `z = e^{iα}`): `(diag(1, z))ᴴ +diag(1, z) = diag(1, z_bar z) = I`. -/ +theorem phaseGate_mem_unitaryGroup {z : ℂ} (hz : star z * z = 1) : + phaseGate z ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose, phaseGate_eq_diagonal, + Matrix.diagonal_conjTranspose, Matrix.diagonal_mul_diagonal, ← Matrix.diagonal_one] + congr 1 + funext a + fin_cases a + · simp + · simpa using hz + +/-- **The subset-controlled global-phase gate is diagonal.** `mcCtrlSingleQubit enc S j (z • 1)` +(with `j ∉ S`) multiplies `|enc x⟩` by `z` exactly when every control in `S` is set — the diagonal +matrix `diag(fun i => if all of S set then z else 1)`, independent of the target value at `j`. The +`w = fun _ => z` case of the general diagonal-block lemma `mcCtrlSingleQubit_diagonal`, via +`Matrix.smul_one_eq_diagonal` (`z • 1 = diagonal (fun _ => z)`). -/ +theorem mcCtrlSingleQubit_smul_one_eq_diagonal (enc : (Fin m → Fin 2) ≃ Fin d) + {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) (z : ℂ) : + mcCtrlSingleQubit enc S j (z • (1 : Matrix (Fin 2) (Fin 2) ℂ)) + = Matrix.diagonal (fun i => if ∀ k ∈ S, enc.symm i k = 1 then z else 1) := by + rw [Matrix.smul_one_eq_diagonal, mcCtrlSingleQubit_diagonal enc hj] + +/-- **The subset-controlled phase-block gate is the same diagonal.** For `c ∈ S`, +`mcCtrlSingleQubit enc (S.erase c) c (phaseGate z)` multiplies `|enc x⟩` by `z` exactly when wire +`c` and every control in `S.erase c` are set — i.e. when every control in `S` is set (`c ∈ S`) — +the same `diag(fun i => if all of S set then z else 1)` as +`mcCtrlSingleQubit_smul_one_eq_diagonal`. -/ +theorem mcCtrlSingleQubit_phaseGate_eq_diagonal (enc : (Fin m → Fin 2) ≃ Fin d) + {S : Finset (Fin m)} {c : Fin m} (hc : c ∈ S) (z : ℂ) : + mcCtrlSingleQubit enc (S.erase c) c (phaseGate z) + = Matrix.diagonal (fun i => if ∀ k ∈ S, enc.symm i k = 1 then z else 1) := by + have hsplit : ∀ i : Fin d, (∀ k ∈ S, enc.symm i k = 1) + ↔ (enc.symm i c = 1 ∧ ∀ k ∈ S.erase c, enc.symm i k = 1) := fun i => + ⟨fun h => ⟨h c hc, fun k hk => h k (Finset.mem_of_mem_erase hk)⟩, + fun ⟨hc1, h⟩ k hk => by + rcases eq_or_ne k c with rfl | hkc + · exact hc1 + · exact h k (Finset.mem_erase.mpr ⟨hkc, hk⟩)⟩ + ext i i' + rw [mcCtrlSingleQubit, wireGate_apply] + simp only [Matrix.diagonal_apply, ctrl_update_iff (Finset.notMem_erase c S)] + by_cases hii : i = i' + · subst hii + rw [ite_eq_left rfl, ite_eq_left (fun _ _ => rfl)] + by_cases hall : ∀ k ∈ S, enc.symm i k = 1 + · rw [ite_eq_left hall, ite_eq_left (fun k hk => hall k (Finset.mem_of_mem_erase hk)), + hall c hc, phaseGate_apply_diag, ite_eq_right (by decide)] + · rw [ite_eq_right hall] + by_cases he : ∀ k ∈ S.erase c, enc.symm i k = 1 + · have hc0 : enc.symm i c = 0 := by + rcases (by omega : enc.symm i c = 0 ∨ enc.symm i c = 1) with h0 | h1 + · exact h0 + · exact absurd ((hsplit i).mpr ⟨h1, he⟩) hall + rw [ite_eq_left he, hc0, phaseGate_apply_diag, ite_eq_left rfl] + · rw [ite_eq_right he, Matrix.one_apply_eq] + · rw [ite_eq_right hii] + by_cases hoff : ∀ k, k ≠ c → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hoff] + have hne : enc.symm i c ≠ enc.symm i' c := enc_symm_ne_of_off enc hii hoff + split_ifs with h + · rw [phaseGate_apply_of_ne z hne] + · rw [Matrix.one_apply_ne hne] + · rw [ite_eq_right hoff] + +/-- **The phase peel** (Nielsen & Chuang §4.3): the subset-controlled global-phase residual of the +ABC reduction is a controlled *phase-block* gate on **one fewer control**. For `c ∈ S`, `j ∉ S`, +`mcCtrlSingleQubit enc S j (z • 1) = mcCtrlSingleQubit enc (S.erase c) c (phaseGate z)`: the target +moves from `j` to the former control wire `c`, and the control set shrinks by one. Iterating bottoms +the phase out at the uncontrolled `singleQubitOnWire enc c (phaseGate z)` (via +`mcCtrlSingleQubit_empty`), and the phase-block gate, being a single-qubit unitary, recurses through +`exists_abc_reduction_mcCtrlSingleQubit` — so the ABC reduction and this peel are the "recurse into +smaller multiply-controlled gates" step of the §4.3 reduction. Proved by writing both sides as the +common diagonal matrix. -/ +theorem mcCtrlSingleQubit_phase_peel (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} + {c j : Fin m} (hc : c ∈ S) (hj : j ∉ S) (z : ℂ) : + mcCtrlSingleQubit enc S j (z • (1 : Matrix (Fin 2) (Fin 2) ℂ)) + = mcCtrlSingleQubit enc (S.erase c) c (phaseGate z) := by + rw [mcCtrlSingleQubit_smul_one_eq_diagonal enc hj, + mcCtrlSingleQubit_phaseGate_eq_diagonal enc hc] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledSingleQubitBarenco.lean b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitBarenco.lean new file mode 100644 index 0000000000..5c2fe1a91b --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitBarenco.lean @@ -0,0 +1,240 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubit +public import LeanPool.AxQM.Concrete.SqrtNot + +/-! +# Concrete: the Barenco tight-register `Cⁿ(X)` recursion (N&C §4.3 / Barenco Lemma 7.5) + +The §4.3 reduction of a controlled single-qubit gate to `H, S, CNOT, Toffoli` bottoms out at the +**tight-register** multiply-controlled `NOT` `Cⁿ(X)` — controls *all* `n` wires but the target, no +spare/work wire. By a parity obstruction (`Concrete/SqrtNot.lean`) that gate is **not** a product of +`Toffoli`/`CNOT`/`NOT` permutation gates; Nielsen & Chuang's *no-work-qubit* construction (Exercise +4.30 / Barenco *et al.* Lemma 7.5) resolves it with a genuine single-qubit gate `V = √X` +(`sqrtNot`). Writing `Cⁿ(X) = Cⁿ(V²)`, the construction peels one control: + +`Cⁿ(V²) = C(V) · Cⁿ⁻¹(X) · C(V†) · Cⁿ⁻¹(X) · Cⁿ⁻¹(V)`, + +where — distinguishing one control wire `c` from the other `n − 1` controls `S'` and the target `j` +— the factors are + +* `C(V)`, `C(V†)` — single-qubit `V`, `V†` on wire `j`, controlled on the *one* wire `c`; +* `Cⁿ⁻¹(X)` (twice) — a `NOT` on wire `c`, controlled on the `n − 1` wires `S'`; +* `Cⁿ⁻¹(V)` — single-qubit `V` on wire `j`, controlled on the `n − 1` wires `S'`. + +Each factor lives in the interpolating gate `mcCtrlSingleQubit` +(`Concrete/MultiControlledSingleQubit.lean`). This file proves the identity at the matrix level. + +## The proof shape + +All five factors are fibrewise (`wireGate`) — three on wire `j` (`C(V)`, `C(V†)`, `Cⁿ⁻¹(V)`) and two +on wire `c` (the `Cⁿ⁻¹(X)`s). The two `Cⁿ⁻¹(X) = P` factors are the *same* permutation gate, +sandwiching `C(V†)`; conjugating collapses that sandwich back to a **single wire-`j` gate**, so the +whole right-hand side becomes a product of three wire-`j` `wireGate`s, which multiply blockwise +(`wireGate_mul`). The identity then reduces to a per-off-`j`-pattern `2 × 2` check: on the four +cases of `(c-bit, all-S'-controls-set)` the block products are `1`, `V†V = 1`, `VV† = 1`, `V·V` — +the +Barenco truth table. + +The conjugation collapse is `mcNotGate_conj_wireGate`: conjugating a wire-`j` `wireGate enc j f` by +`P = mcCtrlSingleQubit enc S' c pauliX` reindexes the block family by the classical `mcNot S' c`, +`P · wireGate enc j f · P = wireGate enc j (fun y => f (mcNot S' c y))`. It is proved from the +general **conjugation-is-reindexing** fact `mcNotGate_conj` +(`P · M · P = M.submatrix (flipCtrl …) (flipCtrl …)`, the analogue of +`singleQubitOnWire_swap_conj`), since `P` is the `0/1` permutation matrix of the involution +`flipCtrl` (the basis-index incarnation of `mcNot S' c`). + +## Use + +These results are reused by the tight-register `Cⁿ(X)` reduction of Exercise 4.43 +([upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean)). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m d : ℕ} + +/-- **The basis-index incarnation of the classical `mcNot S t`.** Relative to an encoding +`enc : (Fin m → Fin 2) ≃ Fin d`, `flipCtrl enc S t` sends `|enc x⟩` to `|enc (mcNot S t x)⟩`: it +flips bit `t` of the encoded bit-string exactly when every control wire in `S` is set. It is the +permutation the multiply-controlled `NOT` gate `mcCtrlSingleQubit enc S t pauliX` realises. -/ +def flipCtrl (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (t : Fin m) (i : Fin d) : Fin d := + enc (mcNot S t (enc.symm i)) + +/-- The bit-string underlying `flipCtrl enc S t i` is `mcNot S t (enc.symm i)`. -/ +theorem enc_symm_flipCtrl (enc : (Fin m → Fin 2) ≃ Fin d) (S : Finset (Fin m)) (t : Fin m) + (i : Fin d) : enc.symm (flipCtrl enc S t i) = mcNot S t (enc.symm i) := by + rw [flipCtrl, Equiv.symm_apply_apply] + +/-- **`flipCtrl enc S t` is an involution** (when the target `t` is not a control): applying +`mcNot S t` twice restores the bit-string (`mcNot_involutive`), hence the basis index. -/ +theorem flipCtrl_involutive (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {t : Fin m} + (ht : t ∉ S) : Function.Involutive (flipCtrl enc S t) := by + intro i + rw [flipCtrl, enc_symm_flipCtrl, mcNot_involutive S ht, Equiv.apply_symm_apply] + +/-- **The multiply-controlled `NOT` gate is the `0/1` permutation matrix of `flipCtrl`.** Its entry +at `(i, a)` is `1` exactly when `a = flipCtrl enc S t i` (and `0` otherwise). This is the +column-indexed form of `mcCtrlSingleQubit_pauliX_eq_permGate`, the analogue of +`singleQubitOnWire_swap_apply`, and the engine behind the conjugation-is-reindexing lemma. -/ +theorem mcNotGate_apply (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {t : Fin m} + (ht : t ∉ S) (i a : Fin d) : + mcCtrlSingleQubit enc S t pauliX i a = if a = flipCtrl enc S t i then 1 else 0 := by + rw [mcCtrlSingleQubit_pauliX_eq_permGate enc S ht, permGate_apply, mcNotPerm_apply] + exact if_congr (eq_comm.trans (flipCtrl_involutive enc ht).eq_iff) rfl rfl + +/-- **Conjugation by the multiply-controlled `NOT` reindexes both matrix indices by `flipCtrl`.** +For any `d × d` matrix `M`, `P · M · P = M.submatrix (flipCtrl enc S t) (flipCtrl enc S t)`, +where +`P = mcCtrlSingleQubit enc S t pauliX`. Since `P` is the `0/1` permutation matrix +(`mcNotGate_apply`) of the involution `flipCtrl enc S t` (`flipCtrl_involutive`), sandwiching `M` +between two copies permutes rows and columns by that flip — the analogue of +`singleQubitOnWire_swap_conj`. -/ +theorem mcNotGate_conj (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {t : Fin m} + (ht : t ∉ S) (M : Matrix (Fin d) (Fin d) ℂ) : + mcCtrlSingleQubit enc S t pauliX * M * mcCtrlSingleQubit enc S t pauliX + = M.submatrix (flipCtrl enc S t) (flipCtrl enc S t) := by + ext i i' + rw [Matrix.submatrix_apply, Matrix.mul_apply] + have hb0 : ∀ b ∈ (Finset.univ : Finset (Fin d)), b ≠ flipCtrl enc S t i' → + (mcCtrlSingleQubit enc S t pauliX * M) i b + * mcCtrlSingleQubit enc S t pauliX b i' = 0 := by + intro b _ hb + have hbne : ¬ (i' = flipCtrl enc S t b) := by + intro h; exact hb (by rw [h, flipCtrl_involutive enc ht]) + rw [mcNotGate_apply enc ht, ite_eq_right hbne, mul_zero] + rw [Finset.sum_eq_single (flipCtrl enc S t i') hb0 (fun h => absurd (Finset.mem_univ _) h), + mcNotGate_apply enc ht, flipCtrl_involutive enc ht, ite_eq_left rfl, mul_one, Matrix.mul_apply] + have ha0 : ∀ a ∈ (Finset.univ : Finset (Fin d)), a ≠ flipCtrl enc S t i → + mcCtrlSingleQubit enc S t pauliX i a * M a (flipCtrl enc S t i') = 0 := by + intro a _ ha + rw [mcNotGate_apply enc ht, ite_eq_right ha, zero_mul] + rw [Finset.sum_eq_single (flipCtrl enc S t i) ha0 (fun h => absurd (Finset.mem_univ _) h), + mcNotGate_apply enc ht, ite_eq_left rfl, one_mul] + +/-- Updating bit `j` of `mcNot S c x` (with `j ≠ c` and `j ∉ S`) commutes past the gate: bit `j` is +neither the target nor a control, so `(mcNot S c x)[j ↦ v] = mcNot S c (x[j ↦ v])`. -/ +theorem update_mcNot_comm {S : Finset (Fin m)} {c j : Fin m} (hjc : j ≠ c) (hjS : j ∉ S) + (x : Fin m → Fin 2) (v : Fin 2) : + Function.update (mcNot S c x) j v = mcNot S c (Function.update x j v) := by + rw [mcNot, mcNot, ctrlBit_update_of_notMem S hjS x v, Function.update_of_ne (Ne.symm hjc), + Function.update_comm hjc] + +/-- Two bit-strings agree off wire `j` iff their `mcNot S c`-images do (for `j ≠ c`, `j ∉ S`): +`mcNot S c` preserves each `j`-fibre. The `→` direction propagates agreement (`mcNot` reads only +the off-`j` control and `c` bits); the `←` direction is the same run through the involution. -/ +theorem forall_ne_mcNot_iff {S : Finset (Fin m)} {c j : Fin m} (hc : c ∉ S) (hjc : j ≠ c) + (hjS : j ∉ S) (x x' : Fin m → Fin 2) : + (∀ l, l ≠ j → mcNot S c x l = mcNot S c x' l) ↔ (∀ l, l ≠ j → x l = x' l) := by + have key : ∀ u v : Fin m → Fin 2, (∀ l, l ≠ j → u l = v l) → + (∀ l, l ≠ j → mcNot S c u l = mcNot S c v l) := by + intro u v h l hl + rcases eq_or_ne l c with rfl | hlc + · rw [mcNot_apply_self, mcNot_apply_self, h l hl] + congr 1 + simp only [ctrlBit, forall_mem_eq_one_congr fun k hk => h k fun e => hjS (e ▸ hk)] + · rw [mcNot_apply_of_ne S c u hlc, mcNot_apply_of_ne S c v hlc] + exact h l hl + refine ⟨fun h l hl => ?_, key x x'⟩ + have h2 := key _ _ h l hl + rwa [mcNot_involutive S hc, mcNot_involutive S hc] at h2 + +/-- **Conjugating a wire-`j` gate by the multiply-controlled `NOT` reindexes its block by `mcNot`.** +For `c ∉ S`, `j ≠ c`, `j ∉ S`, +`P · wireGate enc j f · P = wireGate enc j (fun y => f (mcNot S c y))`, where +`P = mcCtrlSingleQubit enc S c pauliX`. Combined with the two extreme `Cⁿ⁻¹(X)` factors of the +Barenco recursion sandwiching `C(V†)`, this collapses the sandwich to a single wire-`j` gate. -/ +theorem mcNotGate_conj_wireGate (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {c j : Fin m} + (hc : c ∉ S) (hjc : j ≠ c) (hjS : j ∉ S) + (f : (Fin m → Fin 2) → Matrix (Fin 2) (Fin 2) ℂ) : + mcCtrlSingleQubit enc S c pauliX * wireGate enc j f * mcCtrlSingleQubit enc S c pauliX + = wireGate enc j (fun y => f (mcNot S c y)) := by + rw [mcNotGate_conj enc hc] + ext i i' + rw [Matrix.submatrix_apply, wireGate_apply, wireGate_apply, enc_symm_flipCtrl, enc_symm_flipCtrl, + mcNot_apply_of_ne S c (enc.symm i) hjc, mcNot_apply_of_ne S c (enc.symm i') hjc, + update_mcNot_comm hjc hjS (enc.symm i) 0] + exact if_congr (forall_ne_mcNot_iff hc hjc hjS _ _) rfl rfl + +/-- **The Barenco tight-register recursion** (N&C §4.3 / Barenco Lemma 7.5), at the matrix level. +For a distinguished control wire `c`, the remaining controls `S` (`c ∉ S`), and a target `j` +(`j ≠ c`, `j ∉ S`), and any single-qubit unitary `V`, the multiply-controlled gate `Cⁿ(V²)` on the +control set `insert c S` factors as +`C(V) · Cⁿ⁻¹(X) · C(V†) · Cⁿ⁻¹(X) · Cⁿ⁻¹(V)`: +one control is peeled by inserting two `NOT`s on wire `c` (controlled on `S`) around a +controlled-`V†`, plus a controlled-`V` on `c` and a controlled-`V` on the remaining controls `S`. +On the four cases of `(c-bit, all-of-S-set)` the wire-`j` block products are `1`, `V†V`, `VV†`, and +`V²`, matching `mcCtrlSingleQubit enc (insert c S) j (V * V)` since `V` is unitary. -/ +theorem mcCtrlSingleQubit_barenco_recursion (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} + {c j : Fin m} (hc : c ∉ S) (hjc : j ≠ c) (hjS : j ∉ S) {V : Matrix (Fin 2) (Fin 2) ℂ} + (hV : V ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + mcCtrlSingleQubit enc (insert c S) j (V * V) + = mcCtrlSingleQubit enc {c} j V * mcCtrlSingleQubit enc S c pauliX + * mcCtrlSingleQubit enc {c} j Vᴴ * mcCtrlSingleQubit enc S c pauliX + * mcCtrlSingleQubit enc S j V := by + have hVdV : Vᴴ * V = 1 := by + rw [← Matrix.star_eq_conjTranspose]; exact Matrix.mem_unitaryGroup_iff'.mp hV + have hVVd : V * Vᴴ = 1 := by + rw [← Matrix.star_eq_conjTranspose]; exact Matrix.mem_unitaryGroup_iff.mp hV + -- collapse the `Cⁿ⁻¹(X) · C(V†) · Cⁿ⁻¹(X)` sandwich to a single wire-`j` gate + have hconj : mcCtrlSingleQubit enc S c pauliX * mcCtrlSingleQubit enc {c} j Vᴴ + * mcCtrlSingleQubit enc S c pauliX + = wireGate enc j + (fun y => if ∀ k ∈ ({c} : Finset (Fin m)), mcNot S c y k = 1 then Vᴴ else 1) := + mcNotGate_conj_wireGate enc hc hjc hjS _ + -- reassociate `A * B * C * B * E` to `A * (B * C * B) * E` and rewrite the sandwich + rw [mul_assoc (mcCtrlSingleQubit enc {c} j V) (mcCtrlSingleQubit enc S c pauliX) + (mcCtrlSingleQubit enc {c} j Vᴴ), + mul_assoc (mcCtrlSingleQubit enc {c} j V) _ (mcCtrlSingleQubit enc S c pauliX), hconj, + mcCtrlSingleQubit, mcCtrlSingleQubit, mcCtrlSingleQubit, wireGate_mul, wireGate_mul] + congr 1 + funext y + simp only [Finset.mem_singleton, Finset.mem_insert, forall_eq, forall_eq_or_imp, + mcNot_apply_self] + by_cases hcS : ∀ k ∈ S, y k = 1 + · have hcb : ctrlBit S y = 1 := ite_eq_left hcS + rw [hcb] + rcases (by omega : y c = 0 ∨ y c = 1) with hyc | hyc <;> rw [hyc] + · rw [ite_eq_right (fun h => absurd h.1 (by decide)), ite_eq_right (by decide), + ite_eq_left (by decide), + ite_eq_left hcS, one_mul, hVdV] + · rw [ite_eq_left ⟨rfl, hcS⟩, ite_eq_left rfl, ite_eq_right (by decide), ite_eq_left hcS, + mul_one] + · have hcb : ctrlBit S y = 0 := ite_eq_right hcS + rw [hcb] + rcases (by omega : y c = 0 ∨ y c = 1) with hyc | hyc <;> rw [hyc] + · rw [ite_eq_right (fun h => absurd h.1 (by decide)), ite_eq_right (by decide), + ite_eq_right (by decide), + ite_eq_right hcS, mul_one, mul_one] + · rw [ite_eq_right (fun h => hcS h.2), ite_eq_left rfl, ite_eq_left (by decide), + ite_eq_right hcS, mul_one, hVVd] + +/-- **The Barenco tight-register `Cⁿ(X)` recursion** — the `V = √X` specialisation of +`mcCtrlSingleQubit_barenco_recursion`. Since `sqrtNot² = X` (`sqrtNot_mul_self`) and `sqrtNot` is +unitary (`sqrtNot_mem_unitaryGroup`), the tight multiply-controlled `NOT` `Cⁿ(X)` on control set +`insert c S` factors as `C(√X) · Cⁿ⁻¹(X) · C(√X†) · Cⁿ⁻¹(X) · Cⁿ⁻¹(√X)`, peeling one control at the +cost of a genuine single-qubit `√X` gate — the no-work-qubit reduction of Exercise 4.30. Each +`Cⁿ⁻¹(X)`/`Cⁿ⁻¹(√X)` factor uses `n − 1` controls, so on the tight `n + 1`-wire register it now has +a spare wire, feeding the permutation-gate / controlled-`ABC` machinery. -/ +theorem mcCtrlSingleQubit_pauliX_barenco_recursion (enc : (Fin m → Fin 2) ≃ Fin d) + {S : Finset (Fin m)} {c j : Fin m} (hc : c ∉ S) (hjc : j ≠ c) (hjS : j ∉ S) : + mcCtrlSingleQubit enc (insert c S) j pauliX + = mcCtrlSingleQubit enc {c} j sqrtNot * mcCtrlSingleQubit enc S c pauliX + * mcCtrlSingleQubit enc {c} j sqrtNotᴴ * mcCtrlSingleQubit enc S c pauliX + * mcCtrlSingleQubit enc S j sqrtNot := by + nth_rewrite 1 [← sqrtNot_mul_self] + exact mcCtrlSingleQubit_barenco_recursion enc hc hjc hjS sqrtNot_mem_unitaryGroup + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledSingleQubitSpareReduction.lean b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitSpareReduction.lean new file mode 100644 index 0000000000..aa8f26d9a1 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitSpareReduction.lean @@ -0,0 +1,183 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitABCReduction +public import LeanPool.AxQM.Concrete.MultiControlledNotPermProduct +public import LeanPool.AxQM.Concrete.ComplexExpUnit + +/-! +# Concrete: the work-qubit-assisted reduction of a subset-controlled single-qubit gate (N&C §4.3) + +(Nielsen & Chuang §4.3, p. 182 — the "with work qubits" reduction of `Cᵏ(U)`; Barenco *et al.*, +Lemma 7.2/7.5.) + +The Barenco tight-register recursion (`Concrete/MultiControlledSingleQubitBarenco.lean`) factors the +tight `Cⁿ(X)` into *subset*-controlled single-qubit gates `mcCtrlSingleQubit enc S j U₀` **each of +which now has a spare wire** (uses at most `n − 1` of the `n + 1` register wires). This file bottoms +those factors out: **a subset-controlled single-qubit gate with a spare wire is an exact product of +`Toffoli`/`CNOT`/`NOT` gates and uncontrolled single-qubit gates** — the elementary gates the whole +universality reduction terminates in. + +## The terminal gate class + +* `AxQM.Concrete.IsToffoliOrSingleQubitGate enc G` — `G` is either a `≤ 2`-control + reversible gate (`IsToffoliPermGate`: a `Toffoli`/`CNOT`/`NOT`) or an uncontrolled single-qubit + unitary on a wire (`singleQubitOnWire enc j U`, `U ∈ U(2)`). These are exactly the gates the §4.3 + reduction bottoms out in — each directly a `CNOT`/`Toffoli` or an arbitrary single-qubit gate. + `IsToffoliOrSingleQubitGate.mem_unitaryGroup` — each is unitary (the per-gate norm bound the + §4.5.3 error-chaining calculus consumes). + +## The reduction + +* `AxQM.Concrete.exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX` — the + **spare-wire subset-controlled `NOT`** is a product of terminal gates: for `j ∉ S` with a spare + wire (`(insert j S).card < m`), `mcCtrlSingleQubit enc S j pauliX = gates.prod` with every factor + a `Toffoli`/`CNOT`/`NOT`. Composes the permutation bridge + `mcCtrlSingleQubit_pauliX_eq_permGate` with the combinatorial `Cⁿ(X)` circuit + (`exists_isToffoliPermGate_prod_eq_mcNotPermGate_of_spare`). +* `AxQM.Concrete.exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit` — **the + headline**: for any `U₀ ∈ U(2)`, `j ∉ S`, and a spare wire (`(insert j S).card < m`), + `mcCtrlSingleQubit enc S j U₀ = gates.prod` with **every** factor an `IsToffoliOrSingleQubitGate`. + Proved by strong induction on the control set `S` (`Finset.strongInductionOn`): + - `S = ∅` — the gate is the uncontrolled `singleQubitOnWire enc j U₀` (`mcCtrlSingleQubit_empty`), + a single terminal factor. + - `S ≠ ∅` — the subset-controlled ABC reduction + (`exists_abc_reduction_mcCtrlSingleQubit`) rewrites the gate as a subset-controlled *phase* + residual times `singleQubitOnWire A · N · singleQubitOnWire B · N · singleQubitOnWire C`, with + `N = mcCtrlSingleQubit enc S j pauliX`. The three wire gates are terminal; each `N` reduces by + the spare-wire `NOT` lemma above; and the phase residual **peels one control** + (`mcCtrlSingleQubit_phase_peel`) into `mcCtrlSingleQubit enc (S.erase c) c (phaseGate _)` — a + subset-controlled single-qubit gate on the strictly smaller control set `S.erase c ⊂ S`, handled + by the induction hypothesis (its own spare wire persists since `insert c (S.erase c) = S`). + +The spare-wire hypothesis `(insert j S).card < m` is preserved down the recursion: the only +recursive call is on `S.erase c`, whose gate uses `insert c (S.erase c) = S` (`≤ m − 1` wires), so a +spare wire remains. The **tight** case `(insert j S).card = m` (the top `Cⁿ(X)` controlling every +other wire) is *not* covered here — it needs the Barenco `√X` construction first, whose factors then +feed this lemma. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The terminal gate class of the §4.3 reduction.** `IsToffoliOrSingleQubitGate enc G` holds when +`G` is either a `≤ 2`-control reversible gate (`IsToffoliPermGate` — a `Toffoli`/`CNOT`/`NOT`) or an +uncontrolled single-qubit unitary on a wire (`singleQubitOnWire enc j U` with `U ∈ U(2)`). Every +subset-controlled single-qubit gate with a spare wire reduces to a product of these +(`exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit`). -/ +def IsToffoliOrSingleQubitGate (enc : (Fin m → Fin 2) ≃ Fin d) (G : Matrix (Fin d) (Fin d) ℂ) : + Prop := + IsToffoliPermGate enc G ∨ + ∃ (j : Fin m) (U : Matrix (Fin 2) (Fin 2) ℂ), + U ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ G = singleQubitOnWire enc j U + +/-- **Every terminal gate is unitary** — a `≤ 2`-control reversible gate is a permutation gate +(`IsToffoliPermGate.mem_unitaryGroup`), and a single-qubit unitary on a wire is unitary +(`singleQubitOnWire_mem_unitaryGroup`). This is the per-gate norm bound the §4.5.3 error-chaining +calculus consumes. -/ +theorem IsToffoliOrSingleQubitGate.mem_unitaryGroup {enc : (Fin m → Fin 2) ≃ Fin d} + {G : Matrix (Fin d) (Fin d) ℂ} (h : IsToffoliOrSingleQubitGate enc G) : + G ∈ Matrix.unitaryGroup (Fin d) ℂ := by + rcases h with h | ⟨j, U, hU, rfl⟩ + · exact h.mem_unitaryGroup + · exact singleQubitOnWire_mem_unitaryGroup enc j hU + +/-- **The phase-block gate of a global phase `e^{iα}` is unitary** — `star (e^{iα}) · e^{iα} = 1` +(the shared unit-modulus fact `star_exp_ofReal_mul_I_mul_self`), so `phaseGate (e^{iα}) ∈ U(2)`. The +residual of the subset-controlled ABC reduction peels into this gate. -/ +theorem phaseGate_exp_mem_unitaryGroup (α : ℝ) : + phaseGate (Complex.exp ((α : ℂ) * Complex.I)) ∈ Matrix.unitaryGroup (Fin 2) ℂ := + phaseGate_mem_unitaryGroup (star_exp_ofReal_mul_I_mul_self α) + +/-- **The spare-wire subset-controlled `NOT` is a product of `Toffoli`/`CNOT`/`NOT` gates.** For +`j ∉ S` on a register with a spare wire (`(insert j S).card < m`), +`mcCtrlSingleQubit enc S j pauliX` is an exact product `gates.prod` of terminal gates, every factor +a `≤ 2`-control reversible gate. +Composes the permutation bridge `mcCtrlSingleQubit_pauliX_eq_permGate` with the combinatorial +`Cⁿ(X)` circuit `exists_isToffoliPermGate_prod_eq_mcNotPermGate_of_spare`. -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) + (hspare : (insert j S).card < m) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ + mcCtrlSingleQubit enc S j pauliX = gates.prod := by + obtain ⟨Gs, hGs, hprod⟩ := exists_isToffoliPermGate_prod_eq_mcNotPermGate_of_spare enc hj hspare + refine ⟨Gs, fun G hG => Or.inl (hGs G hG), ?_⟩ + rw [mcCtrlSingleQubit_pauliX_eq_permGate enc S hj, hprod] + +/-- **The work-qubit-assisted reduction of a subset-controlled single-qubit gate** (Nielsen & Chuang +§4.3, the reduction of `Cᵏ(U)` with work qubits available). For any single-qubit unitary `U₀`, +target +`j ∉ S`, and a register with a spare wire (`(insert j S).card < m`), the subset-controlled gate +`mcCtrlSingleQubit enc S j U₀` is an exact product `gates.prod` of terminal gates — every factor an +`IsToffoliOrSingleQubitGate` (a `Toffoli`/`CNOT`/`NOT` or an uncontrolled single-qubit unitary on a +wire). Proved by strong induction on the control set `S`: the subset-controlled ABC reduction plus +the phase-residual peel express the gate as three uncontrolled wire gates, two spare-wire +subset-controlled `NOT`s (each a `Toffoli`/`CNOT`/`NOT` product), and one subset-controlled gate on +the strictly smaller control set `S.erase c` (the induction hypothesis). This is the machine that +discharges every Barenco recursion factor — the "recurse until every gate is a +`Toffoli`/`CNOT`/single-qubit gate" step of Exercise 4.43 +([upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean)). -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) + (hspare : (insert j S).card < m) {U₀ : Matrix (Fin 2) (Fin 2) ℂ} + (hU₀ : U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ + mcCtrlSingleQubit enc S j U₀ = gates.prod := by + suffices H : ∀ (S : Finset (Fin m)) (j : Fin m), j ∉ S → (insert j S).card < m → + ∀ (U : Matrix (Fin 2) (Fin 2) ℂ), U ∈ Matrix.unitaryGroup (Fin 2) ℂ → + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ + mcCtrlSingleQubit enc S j U = gates.prod by + exact H S j hj hspare U₀ hU₀ + intro S + induction S using Finset.strongInductionOn with + | _ S ih => + intro j hj hspare U hU + rcases Finset.eq_empty_or_nonempty S with rfl | ⟨c, hc⟩ + · -- Base case: no controls — the gate is the uncontrolled single-qubit wire gate. + refine ⟨[singleQubitOnWire enc j U], ?_, ?_⟩ + · intro g hg + rw [List.mem_singleton] at hg + subst hg + exact Or.inr ⟨j, U, hU, rfl⟩ + · rw [mcCtrlSingleQubit_empty, List.prod_singleton] + · -- Step: ABC reduction + phase-residual peel + spare-wire `NOT`s. + obtain ⟨α, A, B, C, hA, hB, hC, habc⟩ := exists_abc_reduction_mcCtrlSingleQubit enc S j hU + obtain ⟨Gn, hGn, hNprod⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX enc hj hspare + have hspare' : (insert c (S.erase c)).card < m := by + rw [Finset.insert_erase hc] + have hins : (insert j S).card = S.card + 1 := Finset.card_insert_of_notMem hj + omega + obtain ⟨Gp, hGp, hPprod⟩ := + ih (S.erase c) (Finset.erase_ssubset hc) c (Finset.notMem_erase c S) hspare' + (phaseGate (Complex.exp ((α : ℂ) * Complex.I))) (phaseGate_exp_mem_unitaryGroup α) + refine ⟨Gp ++ [singleQubitOnWire enc j A] ++ Gn ++ [singleQubitOnWire enc j B] ++ Gn + ++ [singleQubitOnWire enc j C], ?_, ?_⟩ + · intro g hg + simp only [List.mem_append, List.mem_singleton] at hg + rcases hg with (((((hg | hg) | hg) | hg) | hg) | hg) + · exact hGp g hg + · subst hg; exact Or.inr ⟨j, A, hA, rfl⟩ + · exact hGn g hg + · subst hg; exact Or.inr ⟨j, B, hB, rfl⟩ + · exact hGn g hg + · subst hg; exact Or.inr ⟨j, C, hC, rfl⟩ + · rw [habc, mcCtrlSingleQubit_phase_peel enc hc hj, hPprod, hNprod] + simp only [List.prod_append, List.prod_singleton, mul_assoc] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/MultiControlledSingleQubitTightReduction.lean b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitTightReduction.lean new file mode 100644 index 0000000000..4a6dd29e19 --- /dev/null +++ b/LeanPool/AxQM/Concrete/MultiControlledSingleQubitTightReduction.lean @@ -0,0 +1,207 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitSpareReduction +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitBarenco + +/-! +# Concrete: the tight-register `Cⁿ(X)` bottoms out — no spare-wire hypothesis (N&C §4.3) + +(Nielsen & Chuang §4.3, p. 182 — the multiply-controlled-`NOT`/`Cⁿ(U)` reduction; Barenco *et al.*, +Lemma 7.5.) + +The spare-wire reduction (`Concrete/MultiControlledSingleQubitSpareReduction.lean`) reduces a +*subset*-controlled single-qubit gate `mcCtrlSingleQubit enc S j U₀` to a product of the terminal +gates `IsToffoliOrSingleQubitGate` **only when the register offers a spare wire** +(`(insert j S).card < m`). The **tight** case — the top `Cⁿ(X)` that controls *every* other wire +(`S = univ \ {j}`, so `(insert j S).card = m`) — is deliberately excluded there: as a permutation of +the `2^m` basis states it is a single transposition, hence **odd**, whereas every product of +`≤ 2`-control permutation gates on `≥ 4` wires is **even**, so it is provably *not* a product of +`Toffoli`/`CNOT`/`NOT` permutation gates (`Concrete/SqrtNot.lean`, the parity obstruction). + +This file closes that last gap. The Barenco tight-register recursion +(`mcCtrlSingleQubit_pauliX_barenco_recursion`) peels one control off the tight `Cⁿ(X)` at the cost +of a genuine single-qubit `√X = sqrtNot` gate, + +`Cⁿ(X) = C(√X) · Cⁿ⁻¹(X) · C(√X†) · Cⁿ⁻¹(X) · Cⁿ⁻¹(√X)`, + +and **each of the five factors now has a spare wire**, so each bottoms out by the spare-wire +reduction. Chaining the two removes the spare-wire hypothesis entirely. + +## The results + +* `AxQM.Concrete.exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX'` — **the + crux**: for *any* target `j ∉ S` (**no** spare-wire hypothesis) the multiply-controlled `NOT` + `mcCtrlSingleQubit enc S j pauliX` is an exact product of terminal gates + (`IsToffoliOrSingleQubitGate`). Removes the `(insert j S).card < m` hypothesis from + `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX`, so it covers the tight top + `Cⁿ(X)`. Case split: a spare wire → the spare-wire lemma; `≤ 2` controls → directly a single + `Toffoli`/`CNOT`/`NOT` (`mcCtrlSingleQubit_pauliX_eq_permGate`); otherwise (`≥ 3` controls, no + spare wire) → the Barenco `√X` recursion, whose five factors are each spare-wire. +* `AxQM.Concrete.exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit'` — **the + headline**: for any single-qubit unitary `U₀` and *any* target `j ∉ S` (no spare-wire hypothesis), + `mcCtrlSingleQubit enc S j U₀` is an exact product of terminal gates. Removes the spare-wire + hypothesis from `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit`. For the tight case the + subset-controlled ABC reduction rewrites the gate as three uncontrolled wire gates, two tight + `Cⁿ(X)`s (bottomed out by the crux above), and a phase residual that **peels one control** + (`mcCtrlSingleQubit_phase_peel`) into a *spare-wire* controlled phase-block gate. + +So **every subset-controlled single-qubit gate on an encoded register bottoms out to +`Toffoli`/`CNOT`/single-qubit gates**, with no constraint on the control set — the §4.3 reduction of +`Cᵏ(U)` in full, the form the §4.5.2 controlled single-qubit gates of the universality argument feed +into. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The multiply-controlled `NOT` bottoms out — with no spare-wire hypothesis.** For any target +`j ∉ S` (in particular the tight top `Cⁿ(X)` controlling every other wire), the multiply-controlled +`NOT` `mcCtrlSingleQubit enc S j pauliX` is an exact product `gates.prod` of terminal gates +(`IsToffoliOrSingleQubitGate` — each a `Toffoli`/`CNOT`/`NOT` or an uncontrolled single-qubit +unitary on a wire). + +This is the tight-register counterpart of +`exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX`, which requires a spare wire +(`(insert j S).card < m`). Three cases: +* a spare wire (`(insert j S).card < m`) — the spare-wire lemma; +* `S.card ≤ 2` — the gate is directly a `Toffoli`/`CNOT`/`NOT` permutation gate + (`mcCtrlSingleQubit_pauliX_eq_permGate`), a single terminal factor; +* `S.card ≥ 3` and no spare wire (the genuinely tight case, `m = S.card + 1 ≥ 4`) — the Barenco + `√X` recursion (`mcCtrlSingleQubit_pauliX_barenco_recursion`) peels one control `c`, and each of + its five factors (`C(√X)`, `Cⁿ⁻¹(X)`, `C(√X†)`, `Cⁿ⁻¹(X)`, `Cⁿ⁻¹(√X)`) uses at most `m − 1` wires, + hence has a spare wire and bottoms out by + `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit`(`_pauliX`). -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX' + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ + mcCtrlSingleQubit enc S j pauliX = gates.prod := by + by_cases hspare : (insert j S).card < m + · -- A spare wire is available: the spare-wire `NOT` reduction applies verbatim. + exact exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX enc hj hspare + · by_cases hcard : S.card ≤ 2 + · -- `≤ 2` controls: the gate is a single `Toffoli`/`CNOT`/`NOT` permutation gate. + refine ⟨[mcCtrlSingleQubit enc S j pauliX], ?_, (List.prod_singleton).symm⟩ + intro g hg + rw [List.mem_singleton] at hg + subst hg + exact Or.inl ⟨S, j, hj, hcard, mcCtrlSingleQubit_pauliX_eq_permGate enc S hj⟩ + · -- `≥ 3` controls and no spare wire (`m = S.card + 1 ≥ 4`): the Barenco `√X` recursion. + have hScard : 3 ≤ S.card := by omega + have hcard_ins : (insert j S).card = S.card + 1 := Finset.card_insert_of_notMem hj + have hle : (insert j S).card ≤ m := + (Finset.card_le_univ _).trans_eq (Fintype.card_fin m) + have htight : (insert j S).card = m := le_antisymm hle (not_lt.mp hspare) + have hm : m = S.card + 1 := by omega + -- Distinguish one control wire `c`. + obtain ⟨c, hc⟩ : S.Nonempty := Finset.card_pos.mp (by omega) + have hjc : j ≠ c := by rintro rfl; exact hj hc + have hcS' : c ∉ S.erase c := Finset.notMem_erase c S + have hjS' : j ∉ S.erase c := fun h => hj (Finset.mem_of_mem_erase h) + -- `C(√X)` / `C(√X†)`: single control `{c}` on wire `j`; spare since `m ≥ 4`. + have hj1 : j ∉ ({c} : Finset (Fin m)) := Finset.notMem_singleton.mpr hjc + have hs1 : (insert j ({c} : Finset (Fin m))).card < m := by + rw [Finset.card_insert_of_notMem hj1, Finset.card_singleton]; omega + obtain ⟨G1, hG1, hp1⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit enc hj1 hs1 sqrtNot_mem_unitaryGroup + obtain ⟨G3, hG3, hp3⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit enc hj1 hs1 + sqrtNot_conjTranspose_mem_unitaryGroup + -- `Cⁿ⁻¹(X)` (twice): control `S.erase c` on wire `c`; spare wire `j`. + have hs2 : (insert c (S.erase c)).card < m := by rw [Finset.insert_erase hc]; omega + obtain ⟨G2, hG2, hp2⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX enc hcS' hs2 + -- `Cⁿ⁻¹(√X)`: control `S.erase c` on wire `j`; spare wire `c`. + have hs5 : (insert j (S.erase c)).card < m := by + rw [Finset.card_insert_of_notMem hjS', Finset.card_erase_of_mem hc]; omega + obtain ⟨G5, hG5, hp5⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit enc hjS' hs5 + sqrtNot_mem_unitaryGroup + refine ⟨G1 ++ G2 ++ G3 ++ G2 ++ G5, ?_, ?_⟩ + · intro g hg + simp only [List.mem_append] at hg + rcases hg with ((((hg | hg) | hg) | hg) | hg) + · exact hG1 g hg + · exact hG2 g hg + · exact hG3 g hg + · exact hG2 g hg + · exact hG5 g hg + · rw [← Finset.insert_erase hc, + mcCtrlSingleQubit_pauliX_barenco_recursion enc hcS' hjc hjS', hp1, hp2, hp3, hp5] + simp only [List.prod_append] + +/-- **The work-qubit-free reduction of a subset-controlled single-qubit gate** (Nielsen & Chuang +§4.3), with **no spare-wire hypothesis**. For any single-qubit unitary `U₀` and any target `j ∉ S`, +`mcCtrlSingleQubit enc S j U₀` is an exact product `gates.prod` of terminal gates +(`IsToffoliOrSingleQubitGate`). + +Removes the spare-wire hypothesis `(insert j S).card < m` from +`exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit`. Case split: +* a spare wire → the spare-wire reduction; +* no controls (`S = ∅`) → the uncontrolled single-qubit wire gate, one terminal factor; +* controlled, no spare wire → the subset-controlled ABC reduction + (`exists_abc_reduction_mcCtrlSingleQubit`) rewrites the gate as three uncontrolled wire gates, two + tight `Cⁿ(X)`s (bottomed out by + `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX'`), and a phase residual that + **peels one control** (`mcCtrlSingleQubit_phase_peel`) into + `mcCtrlSingleQubit enc (S.erase c) c (phaseGate _)`, which now *has* a spare wire + (`insert c (S.erase c) = S`, of card `m − 1 < m`) so bottoms out by the general spare-wire + reduction. -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit' + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Finset (Fin m)} {j : Fin m} (hj : j ∉ S) + {U₀ : Matrix (Fin 2) (Fin 2) ℂ} (hU₀ : U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ + mcCtrlSingleQubit enc S j U₀ = gates.prod := by + by_cases hspare : (insert j S).card < m + · -- A spare wire is available: the general spare-wire reduction applies verbatim. + exact exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit enc hj hspare hU₀ + · rcases Finset.eq_empty_or_nonempty S with rfl | ⟨c, hc⟩ + · -- No controls: the uncontrolled single-qubit wire gate is itself terminal. + refine ⟨[singleQubitOnWire enc j U₀], ?_, ?_⟩ + · intro g hg + rw [List.mem_singleton] at hg + subst hg + exact Or.inr ⟨j, U₀, hU₀, rfl⟩ + · rw [mcCtrlSingleQubit_empty, List.prod_singleton] + · -- Controlled, no spare wire: ABC reduction + phase-residual peel + the tight `NOT` crux. + obtain ⟨α, A, B, C, hA, hB, hC, habc⟩ := exists_abc_reduction_mcCtrlSingleQubit enc S j hU₀ + obtain ⟨Gn, hGn, hNprod⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit_pauliX' enc hj + -- The phase residual peels the control `c ∈ S`, gaining wire `j` as a spare wire. + have hcard_ins : (insert j S).card = S.card + 1 := Finset.card_insert_of_notMem hj + have hle : (insert j S).card ≤ m := + (Finset.card_le_univ _).trans_eq (Fintype.card_fin m) + have htight : (insert j S).card = m := le_antisymm hle (not_lt.mp hspare) + have hspare_peel : (insert c (S.erase c)).card < m := by rw [Finset.insert_erase hc]; omega + obtain ⟨Gp, hGp, hPprod⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit enc (Finset.notMem_erase c S) + hspare_peel (phaseGate_exp_mem_unitaryGroup α) + refine ⟨Gp ++ [singleQubitOnWire enc j A] ++ Gn ++ [singleQubitOnWire enc j B] ++ Gn + ++ [singleQubitOnWire enc j C], ?_, ?_⟩ + · intro g hg + simp only [List.mem_append, List.mem_singleton] at hg + rcases hg with (((((hg | hg) | hg) | hg) | hg) | hg) + · exact hGp g hg + · subst hg; exact Or.inr ⟨j, A, hA, rfl⟩ + · exact hGn g hg + · subst hg; exact Or.inr ⟨j, B, hB, rfl⟩ + · exact hGn g hg + · subst hg; exact Or.inr ⟨j, C, hC, rfl⟩ + · rw [habc, mcCtrlSingleQubit_phase_peel enc hc hj, hPprod, hNprod] + simp only [List.prod_append, List.prod_singleton, mul_assoc] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/NmrTomographyExperimentCount.lean b/LeanPool/AxQM/Concrete/NmrTomographyExperimentCount.lean new file mode 100644 index 0000000000..a82e0938ed --- /dev/null +++ b/LeanPool/AxQM/Concrete/NmrTomographyExperimentCount.lean @@ -0,0 +1,238 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliString +public import LeanPool.AxQM.Concrete.DensityMatrixRealDimension + +/-! +# Concrete: how many NMR tomography experiments for `n` spins (Nielsen & Chuang, Exercise 7.46) + +This file supplies the combinatorial core answering **Nielsen & Chuang, Exercise 7.46** (p. 337, +§7.7.4) — *"How many [tomography] experiments are sufficient for three spins? Necessary?"* — the +direct sequel to Exercise 7.45, whose answer for **two** spins is *nine*. Everything here is stated +in terms of index/combinatorial data (`Fin n → Fin 3`, `Fin n → Fin 4`, `Finset`, +`Concrete.pauliString`/`pauliBasis`). The statement of Exercise 7.46 is in +[upstream `AxQM/NC/Ch7/Exercise7_46.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch7/Exercise7_46.lean); compare the NMR exercises 7.44 (logical labeling) and 4.46 (the `4ⁿ +− 1` parameter count this exercise reuses). + +## The physics of NMR state tomography (N&C §7.7.4, eqs. 7.166–7.168) + +An `n`-spin density matrix expands in the `4ⁿ` Pauli strings `P_g = σ_{g₁} ⊗ ⋯ ⊗ σ_{gₙ}` +(`Concrete.pauliString`, `g : Fin n → Fin 4` choosing `{I, X, Y, Z}` per spin), and by the trace +orthogonality `tr(P_g P_h) = 2ⁿ δ_{gh}` (N&C eq. 7.167, generalized; `pauliString_trace_mul`) is +reconstructed from the `4ⁿ` coefficients `tr(ρ P_g)` — of which one, `tr(ρ P_0) = tr ρ = 1`, is +fixed by normalization, leaving `4ⁿ − 1` free real numbers (`Exercise4_46`; +`finrank_tracelessSelfAdjoint_matrix_two_pow`). Measurement of the NMR observable (N&C eq. 7.143), +*preceded by single-qubit pulses*, reads out these coefficients (eq. 7.168). + +The scheme of Exercise 7.45 applies, to each spin independently, one of three pre-rotations +`{I, R_x, R_y}` — equivalently, it **measures each spin in one of three bases** `{Z, Y, X}`. We +model a measurement configuration as a **setting** `s : Fin n → Fin 3` (a basis per spin). Under +setting `s`, a Pauli string `P_g` is read out exactly when each of its non-identity factors matches +that spin's measured basis: `SettingObserves s g`, i.e. `∀ i, g i = 0 ∨ g i = (s i).succ` (the +three non-identity Pauli indices `1, 2, 3 : Fin 4` are `(·).succ` of the three bases `0, 1, 2 : +Fin 3`). A finite family of settings `T` is **tomographically complete** when *every* non-identity +Pauli string is observed by some setting in `T` (`TomographyComplete T`) — then all `4ⁿ − 1` +informative coefficients are measured, and with the normalization-fixed identity coefficient the +whole state is determined (`TomographyComplete.matrix_ext`). + +## The answer + +* **Sufficient.** The full family of all `3ⁿ` settings is complete (`tomographyComplete_univ`): for + three spins, `3³ = 27` experiments suffice (`nmrTomographyExperiments_three`), extending the + `3² = 9` of Exercise 7.45 (`nmrTomographyExperiments_two`). +* **Necessary.** `3ⁿ` is also necessary — indeed the complete family is *unique* + (`TomographyComplete.eq_univ`): a *full-weight* Pauli string `P_{s.succ}` (every factor + non-identity) is observed by the **single** setting `s`, so completeness forces every setting into + `T`. Hence any complete family has exactly `3ⁿ` settings (`TomographyComplete.card_eq`): for three + spins, **27** experiments are both sufficient and necessary. +* **Information count.** Independently, reconstructing an `n`-spin state requires determining + `4ⁿ − 1` real parameters (`Exercise4_46`); for three spins, `4³ − 1 = 63` + (`nmrTomographyParams_three`). Each of the `3ⁿ` settings reads out `2ⁿ` coefficients + (`card_settingObserves`), so the `27` experiments over-determine the `63` parameters — the two + numbers answer *"how many experiments"* vs *"how many real parameters"*, the two halves of the + exercise's question. + +## Fidelity + +The three-basis-per-spin scheme is exactly Exercise 7.45's `{I, R_x, R_y}` construction (whose +two-spin count `9` is reproduced here), read as a product-basis measurement. Both directions are +proved: `3ⁿ` settings suffice **and** are necessary (with the completeness family pinned uniquely to +`univ`), and completeness genuinely determines the density matrix (`matrix_ext`), not merely covers +an abstract index set. No dimension is specialized and no hypothesis is added beyond `0 < n` (needed +only for necessity; `n = 0` has no spins to measure). The answer is neither weakened nor overstated. +-/ + +@[expose] public section + +open Matrix +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The tomography scheme: settings and observability -/ + +/-- A **measurement setting** `s : Fin n → Fin 3` (one of three bases `{Z, Y, X}` per spin, realized +by the pre-pulses `{I, R_x, R_y}`) **observes** the Pauli string `g : Fin n → Fin 4` when each of +`g`'s non-identity factors matches that spin's measured basis: `∀ i, g i = 0 ∨ g i = (s i).succ`. +The three non-identity Pauli indices `1, 2, 3 : Fin 4` are the images `(·).succ` of the three +bases `0, 1, 2 : Fin 3`; a factor `g i = 0` (identity) is observed under any basis. -/ +def SettingObserves (s : Fin n → Fin 3) (g : Fin n → Fin 4) : Prop := + ∀ i, g i = 0 ∨ g i = (s i).succ + +instance (s : Fin n → Fin 3) : DecidablePred (SettingObserves s) := fun g => + inferInstanceAs (Decidable (∀ i, g i = 0 ∨ g i = (s i).succ)) + +/-- A finite family of settings `T` is **tomographically complete** when every non-identity Pauli +string `g` is observed by some setting in `T`. Then the measurements determine all `4ⁿ − 1` +informative Pauli coefficients of the state, and — with the normalization-fixed identity coefficient +`tr ρ = 1` — the whole density matrix (`TomographyComplete.matrix_ext`). This is the precise reading +of "`T` provides sufficient data from which `ρ` can be reconstructed" (Exercise 7.45). -/ +def TomographyComplete (T : Finset (Fin n → Fin 3)) : Prop := + ∀ g : Fin n → Fin 4, g ≠ 0 → ∃ s ∈ T, SettingObserves s g + +/-- Each setting `s` observes its own **full-weight** Pauli string `P_{s.succ}` (the one with every +factor non-identity, `g i = (s i).succ`): trivially, each factor matches. -/ +theorem settingObserves_succ (s : Fin n → Fin 3) : + SettingObserves s (fun i => (s i).succ) := fun _ => Or.inr rfl + +/-- A full-weight Pauli string `P_{s.succ}` is observed **only** by its own setting `s`: since every +factor `(s i).succ ≠ 0`, the observability disjunct forces `(s i).succ = (s' i).succ`, hence +`s = s'` by injectivity of `Fin.succ`. This uniqueness is the engine of necessity. -/ +theorem eq_of_settingObserves_succ {s s' : Fin n → Fin 3} + (h : SettingObserves s' (fun i => (s i).succ)) : s' = s := by + funext i + rcases h i with h0 | hmatch + · exact absurd h0 (Fin.succ_ne_zero (s i)) + · exact (Fin.succ_injective 3 hmatch).symm + +/-! ### Sufficiency: all `3ⁿ` settings are complete -/ + +/-- **Sufficiency.** The full family of all `3ⁿ` settings is tomographically complete: any Pauli +string `g` is observed by the setting matching `g`'s non-identity factors (`s i = (g i).pred` where +`g i ≠ 0`, arbitrary elsewhere). For three spins this is the `27`-experiment scheme; for two spins +the `9` of Exercise 7.45. -/ +theorem tomographyComplete_univ : + TomographyComplete (Finset.univ : Finset (Fin n → Fin 3)) := by + intro g _ + refine ⟨fun i => if h : g i = 0 then 0 else (g i).pred h, Finset.mem_univ _, fun i => ?_⟩ + by_cases h : g i = 0 + · exact Or.inl h + · refine Or.inr ?_ + simp only [dite_eq_right h] + exact (Fin.succ_pred (g i) h).symm + +/-! ### Necessity: `3ⁿ` settings are necessary, and the complete family is unique -/ + +/-- **Necessity (uniqueness).** The *only* tomographically complete family is the full one: for each +setting `s`, its full-weight string `P_{s.succ}` (which is `≠ 0` when there is at least one spin) is +observed **only** by `s` (`eq_of_settingObserves_succ`), so completeness forces `s ∈ T`. Hence +`T = univ`. Requires `0 < n` — with no spins every family, even the empty one, is vacuously +complete. -/ +theorem TomographyComplete.eq_univ (hn : 0 < n) {T : Finset (Fin n → Fin 3)} + (hT : TomographyComplete T) : T = Finset.univ := by + refine Finset.eq_univ_of_forall fun s => ?_ + have hne : (fun i => (s i).succ) ≠ (0 : Fin n → Fin 4) := by + obtain ⟨i⟩ := Fin.pos_iff_nonempty.mp hn + intro hcontra + have hi := congrFun hcontra i + simp only [Pi.zero_apply] at hi + exact Fin.succ_ne_zero (s i) hi + obtain ⟨s', hs'T, hobs⟩ := hT _ hne + exact (eq_of_settingObserves_succ hobs) ▸ hs'T + +/-- **The number of NMR tomography experiments for `n` spins**: `3ⁿ`, both sufficient +(`tomographyComplete_univ`) and necessary (`TomographyComplete.card_eq`). -/ +def nmrTomographyExperiments (n : ℕ) : ℕ := 3 ^ n + +/-- The number of settings for `n` spins is `nmrTomographyExperiments n = 3ⁿ`, i.e. +`Fintype.card (Fin n → Fin 3)`. -/ +theorem card_univ_setting : + (Finset.univ : Finset (Fin n → Fin 3)).card = nmrTomographyExperiments n := by + change (Finset.univ : Finset (Fin n → Fin 3)).card = 3 ^ n + rw [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_fin] + +/-- **The count.** For `0 < n` spins, any tomographically complete family has exactly +`nmrTomographyExperiments n = 3ⁿ` settings (it is `univ`, `TomographyComplete.eq_univ`): `3ⁿ` +experiments are both sufficient (`tomographyComplete_univ`) and necessary. -/ +theorem TomographyComplete.card_eq (hn : 0 < n) {T : Finset (Fin n → Fin 3)} + (hT : TomographyComplete T) : T.card = nmrTomographyExperiments n := by + rw [hT.eq_univ hn, card_univ_setting] + +/-- Each experiment (setting `s`) reads out exactly `2ⁿ` Pauli coefficients: the strings it observes +are those choosing, per spin, either the identity factor `0` or the matched basis `(s i).succ` — two +options each. Via the bijection `(Fin n → Fin 2) ≃ {g | SettingObserves s g}` sending a per-spin bit +`b` to `if b i = 0 then 0 else (s i).succ`. -/ +theorem card_settingObserves (s : Fin n → Fin 3) : + (Finset.univ.filter (fun g : Fin n → Fin 4 => SettingObserves s g)).card = 2 ^ n := by + have hset : (Finset.univ.filter (fun g : Fin n → Fin 4 => SettingObserves s g)) + = Fintype.piFinset (fun i => ({0, (s i).succ} : Finset (Fin 4))) := by + ext g + rw [Finset.mem_filter, Fintype.mem_piFinset] + unfold SettingObserves + simp only [Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_singleton] + rw [hset, Fintype.card_piFinset, + Finset.prod_congr rfl (fun i _ => Finset.card_pair (Fin.succ_ne_zero (s i)).symm), + Finset.prod_const, Finset.card_univ, Fintype.card_fin] + +/-! ### The reconstruction is genuine: completeness determines the density matrix + +The identity coefficient is pinned by the trace via the general Pauli-basis facts +`Concrete.pauliString_const_zero` (`P_0 = I`) and `Concrete.trace_pauliString_mul_eq_repr` +(`tr(P_m · M) = (pauliBasis.repr M m) · 2ⁿ`, the tomography readout functional, N&C eq. 7.168), +both living with the Pauli API in `Concrete/PauliString.lean`. -/ + +/-- **Genuine reconstruction.** If a family `T` is tomographically complete, then two density +matrices `M₁, M₂` agreeing on the trace (`tr M₁ = tr M₂`, the fixed normalization) and on every +observed Pauli coefficient are equal. In words: the measured data of a complete tomography scheme +determine the state — "sufficient data from which `ρ` can be reconstructed" (Exercise 7.45), now +proved for the `n`-spin scheme. The coefficient at `g = 0` is pinned by the trace +(`trace_pauliString_mul_eq_repr`, `pauliString_const_zero`); every other coefficient by +completeness; and equal Pauli coordinates force `M₁ = M₂` (`pauliBasis`). -/ +theorem TomographyComplete.matrix_ext {T : Finset (Fin n → Fin 3)} + (hT : TomographyComplete T) + {M₁ M₂ : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (htr : M₁.trace = M₂.trace) + (hobs : ∀ g : Fin n → Fin 4, (∃ s ∈ T, SettingObserves s g) → + pauliBasis.repr M₁ g = pauliBasis.repr M₂ g) : + M₁ = M₂ := by + have hrepr : ∀ g, pauliBasis.repr M₁ g = pauliBasis.repr M₂ g := by + intro g + by_cases hg : g = 0 + · subst hg + have hP0 : pauliString (0 : Fin n → Fin 4) = 1 := pauliString_const_zero + have e1 := trace_pauliString_mul_eq_repr M₁ (0 : Fin n → Fin 4) + have e2 := trace_pauliString_mul_eq_repr M₂ (0 : Fin n → Fin 4) + rw [hP0, Matrix.one_mul] at e1 e2 + have hcancel : pauliBasis.repr M₁ 0 * (2 : ℂ) ^ n = pauliBasis.repr M₂ 0 * (2 : ℂ) ^ n := by + rw [← e1, ← e2, htr] + exact mul_right_cancel₀ (pow_ne_zero n two_ne_zero) hcancel + · exact hobs g (hT g hg) + exact pauliBasis.repr.injective (Finsupp.ext hrepr) + +/-! ### The numeric answers -/ + +/-- Two spins: `3² = 9` experiments — Exercise 7.45's "nine experiments". -/ +theorem nmrTomographyExperiments_two : nmrTomographyExperiments 2 = 9 := by + norm_num [nmrTomographyExperiments] + +/-- **Exercise 7.46, sufficient & necessary count.** Three spins: `3³ = 27` experiments. -/ +theorem nmrTomographyExperiments_three : nmrTomographyExperiments 3 = 27 := by + norm_num [nmrTomographyExperiments] + +/-- **Exercise 7.46, real-parameter count.** Reconstructing a three-spin state requires determining +`4³ − 1 = 63` real numbers (`Exercise4_46`, specialized to `n = 3`). -/ +theorem nmrTomographyParams_three : + Module.finrank ℝ (tracelessSelfAdjoint (2 ^ 3)) = 63 := by + rw [finrank_tracelessSelfAdjoint_matrix_two_pow]; norm_num + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/Pauli.lean b/LeanPool/AxQM/Concrete/Pauli.lean new file mode 100644 index 0000000000..4e240c572f --- /dev/null +++ b/LeanPool/AxQM/Concrete/Pauli.lean @@ -0,0 +1,359 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Notation +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Hermitian +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.HermitianUnitary +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Trace +public import Mathlib.Basic.Complex.Basic +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Tactic.Module + +/-! +# Concrete: the Pauli matrices and the combination `n · σ` + +This file defines the three `2 × 2` Pauli matrices `X`, `Y`, `Z` over `ℂ` and, for a real +three-vector `n`, the Hermitian combination + +`pauliDot n = n₀ • X + n₁ • Y + n₂ • Z` ("`n · σ`"), + +together with its two structural facts: + +* `pauliDot_isHermitian` — `n · σ` is Hermitian (this is the combination used throughout + Chapter 2). +* `pauliDot_mul_self` — `(n · σ)² = ‖n‖² • I` (with `‖n‖² = n₀² + n₁² + n₂²`), and its + corollary `pauliDot_mul_self_of_unit` giving `(n · σ)² = I` for a unit vector. + +The **per-matrix** facts of Nielsen & Chuang, Exercise 2.19 ("the Pauli matrices are +Hermitian and unitary") are formalized here too: + +* `pauliX_mul_self`, `pauliY_mul_self`, `pauliZ_mul_self` — each Pauli matrix is an + involution (`σ² = I`), the anticommutation-free diagonal case of `pauliDot_mul_self`. +* `pauliX_isHermitian`, `pauliY_isHermitian`, `pauliZ_isHermitian` — `σᴴ = σ`. +* `pauliX_mem_unitaryGroup`, `pauliY_mem_unitaryGroup`, `pauliZ_mem_unitaryGroup` — each + `σ` is unitary in the sense of N&C (`σᴴ σ = I`, i.e. membership in `Matrix.unitaryGroup`), + immediate from being Hermitian and an involution. (`σ₀ = I` is trivially both, via + Mathlib's `Matrix.isHermitian_one` / `unitary` structure on `1`.) + +The trace facts of Nielsen & Chuang, Exercise 2.36 ("the Pauli matrices except `I` have trace +zero") are formalized here too: + +* `pauliX_trace`, `pauliY_trace`, `pauliZ_trace` — each non-identity Pauli matrix is traceless + (`tr σ = 0`), by summing its diagonal entries (`0 + 0`, `0 + 0`, and `1 + (-1)`). +* `trace_one_fin_two` — the exception `σ₀ = I` has trace `2 ≠ 0`, so `I` is genuinely the one + Pauli matrix that is *not* traceless. + +The anticommutation relations of Nielsen & Chuang, Exercise 2.41 are formalized here too, along +with an indexed Pauli family `pauli : Fin 4 → M₂(ℂ)` (`σ₀ = I`, `σ₁ = X`, `σ₂ = Y`, `σ₃ = Z`): + +* `pauliX_anticomm_pauliY`, `pauliY_anticomm_pauliZ`, `pauliX_anticomm_pauliZ` — the three + anticommutators `{σᵢ, σⱼ} = σᵢ σⱼ + σⱼ σᵢ = 0` for the distinct pairs from `{X, Y, Z}` (eq. 2.75). +* `pauli_mul_self` — `σᵢ² = I` for every `i = 0, 1, 2, 3` (eq. 2.76), and `pauli_anticomm` — the + anticommutation relations in indexed form (`{σᵢ, σⱼ} = 0` for distinct `i, j ∈ {1, 2, 3}`). + +These are the shared foundation for the many Chapter 2 items about `n · σ` — the rotation +and exponential formulas (Ex 2.35, Ex 4.5), the eigenprojectors `P± = (I ± n·σ)/2` +(Ex 2.60), Tsirelson's inequality (Prob 2.3), and the functional-calculus decomposition +`f(θ n·σ) = …` (Prob 2.1). + +## Design notes + +* The direction `n` is modelled as a bare `Fin 3 → ℝ` and normalization as the scalar + hypothesis `n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1`, rather than as `EuclideanSpace ℝ (Fin 3)` + with `‖n‖ = 1`. This keeps the statements self-contained and the `n · σ` algebra a + direct `2 × 2` computation, and matches how N&C writes `n̂ · σ ≡ Σᵢ nᵢ σᵢ`. +* `pauliDot_eq` collapses the definitional sum into a single explicit `2 × 2` matrix; every + later fact is proved by reducing to this closed form and computing entrywise. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The Pauli `X` matrix `!![0, 1; 1, 0]`. -/ +def pauliX : Matrix (Fin 2) (Fin 2) ℂ := !![0, 1; 1, 0] + +/-- The Pauli `Y` matrix `!![0, -i; i, 0]`. -/ +def pauliY : Matrix (Fin 2) (Fin 2) ℂ := !![0, -I; I, 0] + +/-- The Pauli `Z` matrix `!![1, 0; 0, -1]`. -/ +def pauliZ : Matrix (Fin 2) (Fin 2) ℂ := !![1, 0; 0, -1] + +/-- The combination `n · σ = n₀ • X + n₁ • Y + n₂ • Z` for a real three-vector `n`. This is +Nielsen & Chuang's `n̂ · σ ≡ Σᵢ nᵢ σᵢ`. -/ +def pauliDot (n : Fin 3 → ℝ) : Matrix (Fin 2) (Fin 2) ℂ := + (n 0 : ℂ) • pauliX + (n 1 : ℂ) • pauliY + (n 2 : ℂ) • pauliZ + +/-- `n · σ` as a single explicit `2 × 2` matrix. -/ +theorem pauliDot_eq (n : Fin 3 → ℝ) : + pauliDot n = + !![(n 2 : ℂ), (n 0 : ℂ) - (n 1 : ℂ) * I; + (n 0 : ℂ) + (n 1 : ℂ) * I, -(n 2 : ℂ)] := by + simp only [pauliDot, pauliX, pauliY, pauliZ] + ext i j + fin_cases i <;> fin_cases j <;> simp [Complex.ext_iff] + +/-- The `e_z`-axis combination `e_z · σ` is the Pauli `Z` matrix: `pauliDot ![0, 0, 1] = Z`. -/ +theorem pauliDot_axisZ : pauliDot (![0, 0, 1] : Fin 3 → ℝ) = pauliZ := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliZ, Matrix.cons_val_two, Matrix.tail_cons, Matrix.head_cons] + +/-- `pauliDot` is additive in its vector argument. -/ +theorem pauliDot_add (u w : Fin 3 → ℝ) : pauliDot (u + w) = pauliDot u + pauliDot w := by + simp only [pauliDot, Pi.add_apply, Complex.ofReal_add] + module + +/-- `pauliDot` is ℝ-homogeneous in its vector argument (as a `ℂ`-scalar multiple). -/ +theorem pauliDot_smul (a : ℝ) (u : Fin 3 → ℝ) : + pauliDot (a • u) = (a : ℂ) • pauliDot u := by + simp only [pauliDot, Pi.smul_apply, smul_eq_mul, Complex.ofReal_mul] + module + +/-- `pauliDot` subtracts. -/ +theorem pauliDot_sub (u w : Fin 3 → ℝ) : pauliDot (u - w) = pauliDot u - pauliDot w := by + simp only [pauliDot, Pi.sub_apply, Complex.ofReal_sub] + module + +/-- `pauliDot` negates. -/ +theorem pauliDot_neg (u : Fin 3 → ℝ) : pauliDot (-u) = -pauliDot u := by + simp only [pauliDot, Pi.neg_apply, Complex.ofReal_neg] + module + +/-- `n · σ` is never the identity matrix: its diagonal `(n₂, −n₂)` cannot be `(1, 1)` +(`n₂ = 1` and `−n₂ = 1` are incompatible). A pure-matrix fact used to show the eigenprojectors +`½(1 ± n·σ)` are nonzero (Exercise 2.60). -/ +theorem pauliDot_ne_one (n : Fin 3 → ℝ) : pauliDot n ≠ 1 := by + intro hmat + have e00 := congrFun (congrFun hmat 0) 0 + have e11 := congrFun (congrFun hmat 1) 1 + rw [pauliDot_eq] at e00 e11 + simp only [Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.empty_val', + Matrix.cons_val_fin_one, Matrix.one_apply_eq, Matrix.of_apply] at e00 e11 + rw [e00] at e11 + norm_num at e11 + +/-- `n · σ` is never `−1`: its diagonal `(n₂, −n₂)` cannot be `(−1, −1)` (`n₂ = −1` and `−n₂ = −1` +are incompatible). A pure-matrix fact used to show the eigenprojectors `½(1 ± n·σ)` are nonzero +(Exercise 2.60). -/ +theorem pauliDot_ne_neg_one (n : Fin 3 → ℝ) : pauliDot n ≠ -1 := by + intro hmat + have e00 := congrFun (congrFun hmat 0) 0 + have e11 := congrFun (congrFun hmat 1) 1 + rw [pauliDot_eq] at e00 e11 + simp only [Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.empty_val', + Matrix.cons_val_fin_one, Matrix.neg_apply, Matrix.one_apply_eq, Matrix.of_apply] at e00 e11 + rw [e00] at e11 + norm_num at e11 + +/-- `n · σ` equals its own conjugate transpose (its entries are `n₂`, `n₀ ∓ i n₁`, `-n₂`, +each fixed by conjugation because `n` is real). -/ +theorem pauliDot_conjTranspose (n : Fin 3 → ℝ) : (pauliDot n)ᴴ = pauliDot n := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Matrix.conjTranspose_apply, Complex.ext_iff] + +/-- `n · σ` is Hermitian, for any real three-vector `n` (Nielsen & Chuang, Exercise 2.19). -/ +theorem pauliDot_isHermitian (n : Fin 3 → ℝ) : (pauliDot n).IsHermitian := + pauliDot_conjTranspose n + +/-- `(n · σ)² = ‖n‖² • I`, where `‖n‖² = n₀² + n₁² + n₂²`. The cross terms cancel because the +Pauli matrices anticommute; the diagonal terms sum the squared components. -/ +theorem pauliDot_mul_self (n : Fin 3 → ℝ) : + pauliDot n * pauliDot n = + (((n 0) ^ 2 + (n 1) ^ 2 + (n 2) ^ 2 : ℝ) : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + rw [pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.mul_apply, Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.smul_apply, smul_eq_mul, Matrix.one_apply, Matrix.of_apply, Matrix.cons_val', + Matrix.empty_val', Matrix.cons_val_fin_one] <;> + push_cast <;> ring_nf <;> simp only [Complex.I_sq] <;> ring + +/-- For a unit vector `n` (`n₀² + n₁² + n₂² = 1`), `(n · σ)² = I`. This is the involution +property underlying the eigenprojectors `P± = (I ± n·σ)/2` and the functional calculus of +`θ n·σ`. -/ +theorem pauliDot_mul_self_of_unit {n : Fin 3 → ℝ} + (h : (n 0) ^ 2 + (n 1) ^ 2 + (n 2) ^ 2 = 1) : + pauliDot n * pauliDot n = 1 := by + rw [pauliDot_mul_self, h]; simp + +/-! ### Each Pauli matrix is Hermitian and unitary (Nielsen & Chuang, Exercise 2.19) + +N&C define an operator to be *Hermitian* when it equals its own adjoint (`σᴴ = σ`, here +`Matrix.IsHermitian`) and *unitary* when `σᴴ σ = I` (here membership in +`Matrix.unitaryGroup`). For each Pauli matrix both hold, and unitarity is a one-line +consequence of Hermiticity together with the involution `σ² = I`. -/ + +/-- Pauli `X` is an involution: `X² = I`. -/ +theorem pauliX_mul_self : pauliX * pauliX = 1 := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, Matrix.mul_apply, Fin.sum_univ_two] + +/-- Pauli `Y` is an involution: `Y² = I`. The off-diagonal product `(-i)(i) = 1` fills the +diagonal, and the cross terms vanish. -/ +theorem pauliY_mul_self : pauliY * pauliY = 1 := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliY, Matrix.mul_apply, Fin.sum_univ_two] + +/-- Pauli `Z` is an involution: `Z² = I`. -/ +theorem pauliZ_mul_self : pauliZ * pauliZ = 1 := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliZ, Matrix.mul_apply, Fin.sum_univ_two] + +/-- Pauli `X` is Hermitian (`Xᴴ = X`); its entries `0, 1, 1, 0` are real. -/ +theorem pauliX_isHermitian : pauliX.IsHermitian := by + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX, Matrix.conjTranspose_apply] + +/-- Pauli `Y` is Hermitian (`Yᴴ = Y`); conjugating and transposing swaps `∓i` back to +themselves (`conj (∓i) = ±i`). -/ +theorem pauliY_isHermitian : pauliY.IsHermitian := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliY, Matrix.conjTranspose_apply] + +/-- Pauli `Z` is Hermitian (`Zᴴ = Z`); its entries `1, 0, 0, -1` are real. -/ +theorem pauliZ_isHermitian : pauliZ.IsHermitian := by + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliZ, Matrix.conjTranspose_apply] + +/-- Pauli `X` is unitary (`Xᴴ X = I`, i.e. `X ∈ unitaryGroup`), from Hermiticity and +`X² = I`. -/ +theorem pauliX_mem_unitaryGroup : pauliX ∈ Matrix.unitaryGroup (Fin 2) ℂ := + pauliX_isHermitian.mem_unitaryGroup pauliX_mul_self + +/-- Pauli `Y` is unitary (`Yᴴ Y = I`, i.e. `Y ∈ unitaryGroup`), from Hermiticity and +`Y² = I`. -/ +theorem pauliY_mem_unitaryGroup : pauliY ∈ Matrix.unitaryGroup (Fin 2) ℂ := + pauliY_isHermitian.mem_unitaryGroup pauliY_mul_self + +/-- Pauli `Z` is unitary (`Zᴴ Z = I`, i.e. `Z ∈ unitaryGroup`), from Hermiticity and +`Z² = I`. -/ +theorem pauliZ_mem_unitaryGroup : pauliZ ∈ Matrix.unitaryGroup (Fin 2) ℂ := + pauliZ_isHermitian.mem_unitaryGroup pauliZ_mul_self + +/-! ### The Pauli matrices except `I` have trace zero (Nielsen & Chuang, Exercise 2.36) + +The trace of a `2 × 2` matrix is the sum of its two diagonal entries. For `X` and `Y` both +diagonal entries are `0`; for `Z` they are `1` and `-1`, which cancel. Hence all three +non-identity Pauli matrices are traceless. The identity `σ₀ = I` is the sole exception: its +trace is `2` (`trace_one_fin_two`). -/ + +/-- Pauli `X` is traceless: `tr X = 0` (its diagonal entries are both `0`). -/ +theorem pauliX_trace : pauliX.trace = 0 := by + simp [pauliX, Matrix.trace, Matrix.diag, Fin.sum_univ_two] + +/-- Pauli `Y` is traceless: `tr Y = 0` (its diagonal entries are both `0`). -/ +theorem pauliY_trace : pauliY.trace = 0 := by + simp [pauliY, Matrix.trace, Matrix.diag, Fin.sum_univ_two] + +/-- Pauli `Z` is traceless: `tr Z = 0` (its diagonal entries `1` and `-1` cancel). -/ +theorem pauliZ_trace : pauliZ.trace = 0 := by + simp [pauliZ, Matrix.trace, Matrix.diag, Fin.sum_univ_two] + +/-- The identity `σ₀ = I` is the exception in Nielsen & Chuang, Exercise 2.36: the `2 × 2` +identity matrix has trace `2`, hence is *not* traceless, unlike `X`, `Y`, `Z`. -/ +theorem trace_one_fin_two : (1 : Matrix (Fin 2) (Fin 2) ℂ).trace = 2 := by + simp [Matrix.trace_one] + +/-! ### Anticommutation relations and the indexed Pauli family (Nielsen & Chuang, Exercise 2.41) + +Exercise 2.41 asks to verify two relations. First the **anticommutation relations** (eq. 2.75) + +`{σᵢ, σⱼ} = σᵢ σⱼ + σⱼ σᵢ = 0` for `i ≠ j`, both drawn from `{1, 2, 3}` (i.e. `X`, `Y`, `Z`), + +stated below as the three distinct unordered pairs; each product is `±i` times the remaining +Pauli matrix, and the two orders differ by a sign, so their sum vanishes. (`{·,·}` denotes the +anticommutator; we write it out as `A * B + B * A = 0` to match the textbook literally.) + +Second, `σᵢ² = I` (eq. 2.76) for **all four** `i = 0, 1, 2, 3`. To capture N&C's indexed +statement uniformly — including `σ₀ = I` — we introduce the family `pauli : Fin 4 → M₂(ℂ)` with +`pauli 0 = I` and `pauli 1, 2, 3 = X, Y, Z`, and prove `pauli_mul_self` (`σᵢ² = I` for every `i`) +and `pauli_anticomm` (`{σᵢ, σⱼ} = 0` for distinct `i, j ≠ 0`, i.e. both in `{1, 2, 3}`, the +non-zero indices being exactly N&C's set). The per-matrix involutions `pauliX_mul_self`, +`pauliY_mul_self`, `pauliZ_mul_self` above supply the `i = 1, 2, 3` cases, and `1 * 1 = 1` the +`i = 0` case. -/ + +/-- Anticommutation of `X` and `Y` (Nielsen & Chuang, eq. 2.75): `{X, Y} = X Y + Y X = 0`. +`X Y = diag(i, -i)` and `Y X = diag(-i, i)`, so the sum is the zero matrix. -/ +theorem pauliX_anticomm_pauliY : pauliX * pauliY + pauliY * pauliX = 0 := by + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX, pauliY] + +/-- Anticommutation of `Y` and `Z` (Nielsen & Chuang, eq. 2.75): `{Y, Z} = Y Z + Z Y = 0`. -/ +theorem pauliY_anticomm_pauliZ : pauliY * pauliZ + pauliZ * pauliY = 0 := by + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliY, pauliZ] + +/-- Anticommutation of `X` and `Z` (Nielsen & Chuang, eq. 2.75): `{X, Z} = X Z + Z X = 0`. -/ +theorem pauliX_anticomm_pauliZ : pauliX * pauliZ + pauliZ * pauliX = 0 := by + ext i j + fin_cases i <;> fin_cases j <;> simp [pauliX, pauliZ] + +/-- The Pauli matrices indexed by `Fin 4` in Nielsen & Chuang's convention: `σ₀ = I`, `σ₁ = X`, +`σ₂ = Y`, `σ₃ = Z`. This packages the four matrices as a single family so the exercise's +statements (`σᵢ² = I` for `i = 0, 1, 2, 3`; `{σᵢ, σⱼ} = 0` for `i ≠ j` from `{1, 2, 3}`) can be +expressed uniformly over the index. -/ +def pauli : Fin 4 → Matrix (Fin 2) (Fin 2) ℂ := ![1, pauliX, pauliY, pauliZ] + +/-- Every Pauli matrix is an involution (Nielsen & Chuang, eq. 2.76): `σᵢ² = I` for +`i = 0, 1, 2, 3`. For `i = 0` this is `I² = I`; for `i = 1, 2, 3` it is the per-matrix involution +of `X`, `Y`, `Z`. -/ +theorem pauli_mul_self (i : Fin 4) : pauli i * pauli i = 1 := by + fin_cases i <;> + simp [pauli, pauliX_mul_self, pauliY_mul_self, pauliZ_mul_self] + +/-- The anticommutation relations in indexed form (Nielsen & Chuang, eq. 2.75): for distinct +non-identity indices `i, j` — i.e. `i ≠ j`, both in `{1, 2, 3}`, expressed as `i, j ≠ 0` since +`0` is the sole excluded index of `Fin 4` — the anticommutator vanishes, `σᵢ σⱼ + σⱼ σᵢ = 0`. +The identity `σ₀ = I` is excluded because `{I, σ} = 2σ ≠ 0`, and the equal-index diagonal because +`{σ, σ} = 2σ² = 2I ≠ 0`. -/ +theorem pauli_anticomm {i j : Fin 4} (hi : i ≠ 0) (hj : j ≠ 0) (hij : i ≠ j) : + pauli i * pauli j + pauli j * pauli i = 0 := by + fin_cases i <;> fin_cases j <;> + first + | exact absurd rfl hi + | exact absurd rfl hj + | exact absurd rfl hij + | (ext a b; fin_cases a <;> fin_cases b <;> simp [pauli, pauliX, pauliY, pauliZ]) + +/-- Each indexed Pauli matrix is Hermitian: `σᵢᴴ = σᵢ` for `i = 0, 1, 2, 3`. For `i = 0` this is +`Iᴴ = I` (`Matrix.isHermitian_one`); for `i = 1, 2, 3` it is `pauliX/Y/Z_isHermitian`. -/ +theorem pauli_isHermitian (m : Fin 4) : (pauli m).IsHermitian := by + fin_cases m + · exact Matrix.isHermitian_one + · exact pauliX_isHermitian + · exact pauliY_isHermitian + · exact pauliZ_isHermitian + +/-- Entrywise Hermiticity of a Pauli matrix: `conj (σₘ a b) = σₘ b a`, read off `pauli_isHermitian` +via `Matrix.conjTranspose_apply`. -/ +theorem pauli_conj_apply (m : Fin 4) (a b : Fin 2) : star (pauli m a b) = pauli m b a := by + have h := congrFun (congrFun (pauli_isHermitian m) b) a + rwa [Matrix.conjTranspose_apply] at h + +/-- **Single-qubit trace orthogonality** (the `d = 2` case of Nielsen & Chuang, Exercise 2.39): +`tr(σᵢ σⱼ) = 2 δᵢⱼ`. Since each `σ` is an involution (`σ² = I`), the diagonal case gives `tr I = 2`; +the off-diagonal products are traceless. This is the `n = 1` case of the Hilbert–Schmidt +orthogonality of the `n`-fold Pauli strings (`Concrete.pauliString_trace_mul`). -/ +theorem pauli_trace_mul (i j : Fin 4) : + (pauli i * pauli j).trace = if i = j then (2 : ℂ) else 0 := by + fin_cases i <;> fin_cases j <;> + simp [pauli, pauliX, pauliY, pauliZ, Matrix.trace_fin_two, Complex.ext_iff] <;> norm_num + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliEigenstateBloch.lean b/LeanPool/AxQM/Concrete/PauliEigenstateBloch.lean new file mode 100644 index 0000000000..0513bc2d9b --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliEigenstateBloch.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.BlochPureState + +/-! +# Concrete: the Pauli eigenvectors as §1.2 Bloch kets, and their Cartesian Bloch points + +Supporting Nielsen & Chuang, Exercise 4.1 ("find the +points on the Bloch sphere for the normalized eigenvectors of the Pauli matrices", p. 174). At the +matrix/vector level it records two families of identities, at the six equator/pole points +`(θ,φ) ∈ {(π/2,0), (π/2,π), (π/2,π/2), (π/2,3π/2), (0,0), (π,0)}`: + +* each normalized Pauli eigenvector of Exercise 2.11 (`|±⟩`, `|±i⟩`, `|0⟩`, `|1⟩`) *is* the §1.2 + Bloch ket `blochKet θ φ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩` (eq. 1.4) at that point; and +* the §1.2 Cartesian Bloch vector `blochSphereVector θ φ = (sin θ cos φ, sin θ sin φ, cos θ)` there + evaluates to the corresponding coordinate axis `±x̂ / ±y_hat / ±e_z`. + +Everything is stated for raw matrix/vector data (`Fin 2 → ℂ`, `Fin 3 → ℝ`, `Concrete.blochKet`, +`Concrete.blochSphereVector`, the eigenvectors `xPlus`/`…`). Exercise 4.1 +(`LeanPool/AxQM/NC/Ch4/Exercise1.lean`) builds on these identities. + +## Design notes + +* The amplitude `1/√2` shared by the `X`/`Y` eigenvectors is `Concrete.invSqrt2 = (√2)⁻¹`; it equals + `cos(π/4) = sin(π/4) = √2/2` (`ofReal_cos_pi_div_four`, `ofReal_sin_pi_div_four`), the bridge to + the half-angle values at `θ/2 = π/4`. +* The `e^{iφ}` factor is expanded via `Complex.exp_mul_I` to `cos φ + i sin φ` and the real trig + evaluated at `φ ∈ {0, π/2, π, 3π/2}` (`3π/2 = π + π/2` via the addition formulas). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-! ### `1/√2 = cos(π/4) = sin(π/4)` -/ + +/-- `√2/2 = (√2)⁻¹` in `ℝ` (the two spellings of `1/√2`). -/ +private theorem sqrt2_div_two : Real.sqrt 2 / 2 = (Real.sqrt 2)⁻¹ := by + have h2 : Real.sqrt 2 ≠ 0 := (Real.sqrt_pos.mpr (by norm_num)).ne' + rw [div_eq_iff (two_ne_zero), inv_mul_eq_div, eq_div_iff h2] + exact Real.mul_self_sqrt (by norm_num) + +/-- `cos(π/4) = 1/√2` (as a complex number): the `(θ = π/2)` half-angle value is the shared +`X`/`Y`-eigenvector amplitude `invSqrt2`. -/ +theorem ofReal_cos_pi_div_four : ((Real.cos (Real.pi / 4) : ℝ) : ℂ) = invSqrt2 := by + rw [Real.cos_pi_div_four, sqrt2_div_two, Complex.ofReal_inv, invSqrt2] + +/-- `sin(π/4) = 1/√2` (as a complex number). -/ +theorem ofReal_sin_pi_div_four : ((Real.sin (Real.pi / 4) : ℝ) : ℂ) = invSqrt2 := by + rw [Real.sin_pi_div_four, sqrt2_div_two, Complex.ofReal_inv, invSqrt2] + +/-! ### Trig values at `3π/2`, and the `e^{iφ}` phase factors -/ + +/-- `cos(3π/2) = 0` (`3π/2 = π + π/2`, addition formula). Not available upstream, +so a shared private fact reused by both `|-i⟩` identities. -/ +private theorem cos_three_pi_div_two : Real.cos (3 * Real.pi / 2) = 0 := by + rw [show (3 * Real.pi / 2) = Real.pi + Real.pi / 2 by ring, Real.cos_add, + Real.cos_pi, Real.sin_pi, Real.cos_pi_div_two, Real.sin_pi_div_two]; ring + +/-- `sin(3π/2) = -1` (`3π/2 = π + π/2`, addition formula). Not available upstream, so a shared +private fact reused by both `|-i⟩` identities. -/ +private theorem sin_three_pi_div_two : Real.sin (3 * Real.pi / 2) = -1 := by + rw [show (3 * Real.pi / 2) = Real.pi + Real.pi / 2 by ring, Real.sin_add, + Real.cos_pi, Real.sin_pi, Real.cos_pi_div_two, Real.sin_pi_div_two]; ring + +/-- `e^{i π/2} = i` (the §1.2 phase at `φ = π/2`): Mathlib's `Complex.exp_pi_div_two_mul_I` after +matching the coercion `↑(π/2) = ↑π/2`. -/ +private theorem exp_pi_div_two_mul_I : + Complex.exp (((Real.pi / 2 : ℝ) : ℂ) * Complex.I) = Complex.I := by + rw [show ((Real.pi / 2 : ℝ) : ℂ) = (Real.pi : ℂ) / 2 by push_cast; ring, + Complex.exp_pi_div_two_mul_I] + +/-- `e^{i 3π/2} = -i` (the §1.2 phase at `φ = 3π/2`): `Complex.exp_mul_I` with the shared `3π/2` +trig values `cos_three_pi_div_two` / `sin_three_pi_div_two`. -/ +private theorem exp_three_pi_div_two_mul_I : + Complex.exp (((3 * Real.pi / 2 : ℝ) : ℂ) * Complex.I) = -Complex.I := by + rw [Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, + cos_three_pi_div_two, sin_three_pi_div_two] + push_cast; ring + +/-! ### The Pauli eigenvectors as §1.2 Bloch kets + +At `θ = π/2` the two half-angle amplitudes are both `1/√2`, so `blochKet (π/2) φ = (1/√2)(|0⟩ + +e^{iφ}|1⟩)`; the four equatorial eigenvectors are read off by evaluating `e^{iφ}`. -/ + +/-- **`blochKet (π/2) φ = (1/√2, e^{iφ}/√2)`** — the §1.2 pure state on the equator, in terms of its +phase `e^{iφ}`. The shared reduction behind the four `X`/`Y` eigenvector identities. -/ +theorem blochKet_pi_div_two (φ : ℝ) : + blochKet (Real.pi / 2) φ = ![invSqrt2, Complex.exp ((φ : ℂ) * Complex.I) * invSqrt2] := by + funext i + fin_cases i <;> + simp only [blochKet, show (Real.pi / 2 / 2) = Real.pi / 4 by ring, + ofReal_cos_pi_div_four, ofReal_sin_pi_div_four] + +/-- **`|+⟩ = blochKet (π/2) 0`** — the `+1` eigenvector of `X` at equator azimuth `φ = 0`. -/ +theorem blochKet_pi_div_two_zero : blochKet (Real.pi / 2) 0 = xPlus := by + rw [blochKet_pi_div_two] + funext i; fin_cases i <;> simp [xPlus] + +/-- **`|-⟩ = blochKet (π/2) π`** — the `-1` eigenvector of `X` (`e^{iπ} = -1`). -/ +theorem blochKet_pi_div_two_pi : blochKet (Real.pi / 2) Real.pi = xMinus := by + rw [blochKet_pi_div_two, Complex.exp_pi_mul_I] + funext i; fin_cases i <;> simp [xMinus] + +/-- **`|+i⟩ = blochKet (π/2) (π/2)`** — the `+1` eigenvector of `Y` (`e^{iπ/2} = i`). -/ +theorem blochKet_pi_div_two_pi_div_two : blochKet (Real.pi / 2) (Real.pi / 2) = yPlus := by + unfold yPlus + rw [blochKet_pi_div_two, exp_pi_div_two_mul_I, mul_comm] + +/-- **`|-i⟩ = blochKet (π/2) (3π/2)`** — the `-1` eigenvector of `Y` (`e^{i3π/2} = -i`). -/ +theorem blochKet_pi_div_two_three_pi_div_two : + blochKet (Real.pi / 2) (3 * Real.pi / 2) = yMinus := by + unfold yMinus + rw [blochKet_pi_div_two, exp_three_pi_div_two_mul_I, neg_mul, mul_comm] + +/-- **`|0⟩ = blochKet 0 0`** — the `+1` eigenvector of `Z` is the north pole `θ = 0`. -/ +theorem blochKet_zero_zero : blochKet 0 0 = ket 0 := by + funext i + fin_cases i <;> simp [blochKet, ket] + +/-- **`|1⟩ = blochKet π 0`** — the `-1` eigenvector of `Z` is the south pole `θ = π`. -/ +theorem blochKet_pi_zero : blochKet Real.pi 0 = ket 1 := by + funext i + fin_cases i <;> simp [blochKet, ket, Real.cos_pi_div_two, Real.sin_pi_div_two] + +/-! ### The Cartesian Bloch points of the eigenvectors + +`blochSphereVector θ φ = (sin θ cos φ, sin θ sin φ, cos θ)` evaluated at the six points. -/ + +/-- The Bloch point of `|+⟩` is `+x̂ = (1, 0, 0)`. -/ +theorem blochSphereVector_pi_div_two_zero : + blochSphereVector (Real.pi / 2) 0 = ![1, 0, 0] := by + funext i + fin_cases i <;> simp [blochSphereVector, Real.sin_pi_div_two, Real.cos_pi_div_two] + +/-- The Bloch point of `|-⟩` is `-x̂ = (-1, 0, 0)`. -/ +theorem blochSphereVector_pi_div_two_pi : + blochSphereVector (Real.pi / 2) Real.pi = ![-1, 0, 0] := by + funext i + fin_cases i <;> + simp [blochSphereVector, Real.sin_pi_div_two, Real.cos_pi_div_two, Real.sin_pi, Real.cos_pi] + +/-- The Bloch point of `|+i⟩` is `+y_hat = (0, 1, 0)`. -/ +theorem blochSphereVector_pi_div_two_pi_div_two : + blochSphereVector (Real.pi / 2) (Real.pi / 2) = ![0, 1, 0] := by + funext i + fin_cases i <;> simp [blochSphereVector, Real.sin_pi_div_two, Real.cos_pi_div_two] + +/-- The Bloch point of `|-i⟩` is `-y_hat = (0, -1, 0)`. -/ +theorem blochSphereVector_pi_div_two_three_pi_div_two : + blochSphereVector (Real.pi / 2) (3 * Real.pi / 2) = ![0, -1, 0] := by + funext i + fin_cases i <;> simp [blochSphereVector, Real.sin_pi_div_two, Real.cos_pi_div_two, + cos_three_pi_div_two, sin_three_pi_div_two] + +/-- The Bloch point of `|0⟩` is `+e_z = (0, 0, 1)`. -/ +theorem blochSphereVector_zero_zero : + blochSphereVector 0 0 = ![0, 0, 1] := by + funext i + fin_cases i <;> simp [blochSphereVector] + +/-- The Bloch point of `|1⟩` is `-e_z = (0, 0, -1)`. -/ +theorem blochSphereVector_pi_zero : + blochSphereVector Real.pi 0 = ![0, 0, -1] := by + funext i + fin_cases i <;> simp [blochSphereVector, Real.sin_pi, Real.cos_pi] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliEigenvectors.lean b/LeanPool/AxQM/Concrete/PauliEigenvectors.lean new file mode 100644 index 0000000000..74cee071aa --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliEigenvectors.lean @@ -0,0 +1,297 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliOuterProduct +public import LeanPool.AxQM.ToMathlib.Data.Real.Sqrt +public import Mathlib.Analysis.Complex.Norm + +/-! +# Concrete: eigendecomposition of the Pauli matrices (Nielsen & Chuang, Exercise 2.11) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 2.11 +("Eigendecomposition of the Pauli matrices", p. 69) asks to find the **eigenvectors**, +**eigenvalues**, and **diagonal representations** of the Pauli matrices `X`, `Y`, `Z`. + +Each Pauli matrix is Hermitian with eigenvalues `+1` and `-1`, and its two normalized +eigenvectors form an orthonormal basis of `ℂ²`; N&C's *diagonal representation* +(eq. (2.29), also called an *orthonormal decomposition*) writes the operator as +`A = (+1)|ψ₊⟩⟨ψ₊| + (-1)|ψ₋⟩⟨ψ₋|` over that eigenbasis. Concretely: + +* `Z`: eigenvectors `|0⟩, |1⟩` (eigenvalues `+1, -1`); `Z = |0⟩⟨0| - |1⟩⟨1|`. +* `X`: eigenvectors `|+⟩ = (|0⟩+|1⟩)/√2`, `|-⟩ = (|0⟩-|1⟩)/√2` (eigenvalues `+1, -1`); + `X = |+⟩⟨+| - |-⟩⟨-|`. +* `Y`: eigenvectors `|+i⟩ = (|0⟩+i|1⟩)/√2`, `|-i⟩ = (|0⟩-i|1⟩)/√2` (eigenvalues `+1, -1`); + `Y = |+i⟩⟨+i| - |-i⟩⟨-i|`. + +This is pure linear algebra over `ℂ²`. It builds directly on +`AxQM.Concrete.PauliOuterProduct`: the Pauli matrices `pauliX/pauliY/pauliZ`, the +computational-basis kets `ket 0 = |0⟩`, `ket 1 = |1⟩`, and the outer-product decomposition +`pauliZ_eq_ketBra : Z = |0⟩⟨0| - |1⟩⟨1|` — which, because `|0⟩, |1⟩` *are* the eigenvectors +of `Z`, is already its diagonal representation, so `Z` is handled entirely by reuse. + +## Design notes + +* Everything stays at the matrix level, matching `Concrete.Pauli`/`Concrete.PauliOuterProduct`: + the eigenvectors are plain column vectors `Fin 2 → ℂ`, the matrix acts by `Matrix.mulVec` + (`M *ᵥ v`), and an outer product `|v⟩⟨v|` is `Matrix.vecMulVec v (star v)` (the bra `⟨v|` + being the conjugate of `|v⟩`, faithful to N&C eq. (2.20)). No `EuclideanSpace`/`LinearMap` + machinery is needed. Each eigenvalue equation is stated as `M *ᵥ v = μ • v` with the + eigenvalue `μ ∈ {1, -1}` explicit, and each diagonal representation as a `2 × 2` matrix + identity, so every fact reduces to an entrywise computation. +* The normalization constant `1/√2` is packaged as `invSqrt2`, with `invSqrt2_mul_self` + (`(1/√2)² = 1/2`) the one arithmetic fact the `X`/`Y` outer products need; the eigenvalue + equations, being linear, do not use it. `invSqrt2` is real, so it is fixed by conjugation + (`invSqrt2_star`). +* Orthonormality of each eigenpair is recorded via the Hermitian inner product `⟨u|v⟩ = + star u ⬝ᵥ v` of N&C eq. (2.14) (`Matrix.dotProduct` of the conjugate): the `_dotProduct_self` + facts give `‖·‖² = 1` and the `_dotProduct_` cross facts give orthogonality — together + certifying "an orthonormal set of eigenvectors", which is what makes the outer-product + sums genuine *diagonal representations* in N&C's sense. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-! ### The normalization constant `1/√2` and the self outer product `|v⟩⟨v|` -/ + +/-- The normalization constant `1/√2`, as a complex number. It is the shared coefficient of +the `X`- and `Y`-eigenvectors `|±⟩`, `|±i⟩`. -/ +noncomputable def invSqrt2 : ℂ := (Real.sqrt 2 : ℂ)⁻¹ + +/-- `(1/√2)·(1/√2) = 1/2`: the single arithmetic fact behind the `X`/`Y` diagonal +representations and normalizations (each outer-product entry is a product of two `1/√2`s). -/ +theorem invSqrt2_mul_self : invSqrt2 * invSqrt2 = 2⁻¹ := by + rw [invSqrt2, ← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num)] + norm_num + +/-- `(1/√2)² = 1/2`, the squared form of `invSqrt2_mul_self`. -/ +theorem invSqrt2_sq : invSqrt2 ^ 2 = 2⁻¹ := by rw [sq, invSqrt2_mul_self] + +/-- `‖(1/√2 : ℂ)‖² = 1/2`: the squared magnitude of the shared amplitude of `|±⟩`, used when +normalizing the `X`-eigenstates. -/ +theorem norm_invSqrt2_sq : ‖(invSqrt2 : ℂ)‖ ^ 2 = 2⁻¹ := by + rw [invSqrt2, ← Complex.ofReal_inv, Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg 2)), inv_pow, + Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + +/-- `1/√2` is real, hence fixed by complex conjugation: `conj (1/√2) = 1/√2`. -/ +theorem invSqrt2_star : star invSqrt2 = invSqrt2 := by simp [invSqrt2] + +/-- `1/√2 ≠ 0`. -/ +theorem invSqrt2_ne_zero : invSqrt2 ≠ 0 := by rw [invSqrt2]; simp + +/-- The self outer product `|v⟩⟨v|` of a column vector `v : Fin 2 → ℂ`, as the `2 × 2` +matrix `vecMulVec v (star v)` with `(a, b)` entry `vₐ · conj v_b` (the bra `⟨v|` is the +conjugate of the ket `|v⟩`). When `v` is a unit vector this is the rank-one orthogonal +projector onto `v`; a diagonal representation is a signed sum of such projectors. -/ +def outerSelf (v : Fin 2 → ℂ) : Matrix (Fin 2) (Fin 2) ℂ := vecMulVec v (star v) + +/-- The `(a, b)` entry of `|v⟩⟨v|` is `vₐ · conj v_b`. -/ +theorem outerSelf_apply (v : Fin 2 → ℂ) (a b : Fin 2) : + outerSelf v a b = v a * star (v b) := rfl + +/-! ### Eigendecomposition of `Z` + +The eigenvectors of `Z` are the computational-basis kets `|0⟩, |1⟩` (`ket 0`, `ket 1` from +`PauliOuterProduct`), with eigenvalues `+1, -1`. Its diagonal representation +`Z = |0⟩⟨0| - |1⟩⟨1|` coincides with the outer-product expansion `pauliZ_eq_ketBra`. -/ + +/-- `|0⟩` is an eigenvector of `Z` with eigenvalue `+1`: `Z|0⟩ = |0⟩`. -/ +theorem pauliZ_mulVec_ket_zero : pauliZ *ᵥ ket 0 = (1 : ℂ) • ket 0 := by + ext i; fin_cases i <;> simp [pauliZ, ket, Matrix.mulVec] + +/-- `|1⟩` is an eigenvector of `Z` with eigenvalue `-1`: `Z|1⟩ = -|1⟩`. -/ +theorem pauliZ_mulVec_ket_one : pauliZ *ᵥ ket 1 = (-1 : ℂ) • ket 1 := by + ext i; fin_cases i <;> simp [pauliZ, ket, Matrix.mulVec] + +/-- The diagonal representation of `Z`: `Z = |0⟩⟨0| - |1⟩⟨1|`. This is exactly the +outer-product expansion `pauliZ_eq_ketBra`, since `|0⟩, |1⟩` are the eigenvectors of `Z` +(`outerSelf (ket i) = ketBra i i` by definition). -/ +theorem pauliZ_eq_outerSelf_sub : pauliZ = outerSelf (ket 0) - outerSelf (ket 1) := + pauliZ_eq_ketBra + +/-! ### Eigendecomposition of `X` + +The eigenvectors of `X` are `|+⟩ = (|0⟩+|1⟩)/√2` and `|-⟩ = (|0⟩-|1⟩)/√2`, with eigenvalues +`+1, -1`; the diagonal representation is `X = |+⟩⟨+| - |-⟩⟨-|`. -/ + +/-- The `X`-eigenvector `|+⟩ = (|0⟩ + |1⟩)/√2 = (1/√2, 1/√2)`, eigenvalue `+1`. -/ +noncomputable def xPlus : Fin 2 → ℂ := ![invSqrt2, invSqrt2] + +/-- The `X`-eigenvector `|-⟩ = (|0⟩ - |1⟩)/√2 = (1/√2, -1/√2)`, eigenvalue `-1`. -/ +noncomputable def xMinus : Fin 2 → ℂ := ![invSqrt2, -invSqrt2] + +/-- Both components of `|+⟩ = (1/√2, 1/√2)` equal `1/√2`: the definitional unfold of +`xPlus`, provided at its definition site so every consumer inherits it. -/ +@[simp] theorem xPlus_apply (i : Fin 2) : xPlus i = invSqrt2 := by fin_cases i <;> rfl + +/-- `|+⟩` is an eigenvector of `X` with eigenvalue `+1`: `X|+⟩ = |+⟩`. -/ +theorem pauliX_mulVec_xPlus : pauliX *ᵥ xPlus = (1 : ℂ) • xPlus := by + ext i; fin_cases i <;> simp [pauliX, xPlus, Matrix.mulVec] + +/-- `|-⟩` is an eigenvector of `X` with eigenvalue `-1`: `X|-⟩ = -|-⟩`. -/ +theorem pauliX_mulVec_xMinus : pauliX *ᵥ xMinus = (-1 : ℂ) • xMinus := by + ext i; fin_cases i <;> simp [pauliX, xMinus, Matrix.mulVec] + +/-- `X` flips the computational-basis ket: `X|i⟩ = |i ⊕ 1⟩`. The matrix-action companion of the +`Z`-ket eigenvalue lemmas `pauliZ_mulVec_ket_zero`/`_one`, on the standard basis vector +`ket i = Pi.single i 1`. -/ +theorem pauliX_mulVec_ket (i : Fin 2) : pauliX *ᵥ ket i = ket (i + 1) := by + ext j; fin_cases i <;> fin_cases j <;> simp [pauliX, ket, Matrix.mulVec] + +/-- `Y` flips the computational-basis ket with a phase: `Y|i⟩ = i · (-1)ⁱ · |i ⊕ 1⟩` +(`Y|0⟩ = i|1⟩`, `Y|1⟩ = -i|0⟩`). The `Y` companion of `pauliX_mulVec_ket` / `pauliZ_mulVec_ket_*`, +on the standard basis vector `ket i = Pi.single i 1`, read off from `pauliY = !![0, -I; I, 0]`. -/ +theorem pauliY_mulVec_ket (i : Fin 2) : + pauliY *ᵥ ket i = (Complex.I * (-1) ^ (i : ℕ)) • ket (i + 1) := by + ext j; fin_cases i <;> fin_cases j <;> simp [pauliY, ket, Matrix.mulVec] + +/-- `|+⟩` is a unit vector: `⟨+|+⟩ = 1`. -/ +theorem xPlus_dotProduct_self : star xPlus ⬝ᵥ xPlus = 1 := by + simp only [xPlus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, invSqrt2_star, invSqrt2_mul_self] + norm_num + +/-- `|-⟩` is a unit vector: `⟨-|-⟩ = 1`. -/ +theorem xMinus_dotProduct_self : star xMinus ⬝ᵥ xMinus = 1 := by + simp only [xMinus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, star_neg, invSqrt2_star, neg_mul, mul_neg, neg_neg, invSqrt2_mul_self] + norm_num + +/-- `|+⟩` and `|-⟩` are orthogonal: `⟨+|-⟩ = 0`. -/ +theorem xPlus_dotProduct_xMinus : star xPlus ⬝ᵥ xMinus = 0 := by + simp only [xPlus, xMinus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, invSqrt2_star, mul_neg] + ring + +/-- `|+⟩` is nonzero (so it is a genuine eigenvector). -/ +theorem xPlus_ne_zero : xPlus ≠ 0 := by + intro h; have := xPlus_dotProduct_self; rw [h] at this; simp at this + +/-- `|-⟩` is nonzero (so it is a genuine eigenvector). -/ +theorem xMinus_ne_zero : xMinus ≠ 0 := by + intro h; have := xMinus_dotProduct_self; rw [h] at this; simp at this + +/-- The diagonal representation of `X`: `X = |+⟩⟨+| - |-⟩⟨-|`. -/ +theorem pauliX_eq_outerSelf_sub : pauliX = outerSelf xPlus - outerSelf xMinus := by + ext a b + fin_cases a <;> fin_cases b <;> + simp only [pauliX, outerSelf, vecMulVec_apply, Pi.star_apply, Matrix.sub_apply, + ] <;> + simp [xPlus, xMinus, invSqrt2_star] <;> + ring_nf <;> simp [invSqrt2_sq] + +/-! ### Eigendecomposition of `Y` + +The eigenvectors of `Y` are `|+i⟩ = (|0⟩+i|1⟩)/√2` and `|-i⟩ = (|0⟩-i|1⟩)/√2`, with +eigenvalues `+1, -1`; the diagonal representation is `Y = |+i⟩⟨+i| - |-i⟩⟨-i|`. -/ + +/-- The `Y`-eigenvector `|+i⟩ = (|0⟩ + i|1⟩)/√2 = (1/√2, i/√2)`, eigenvalue `+1`. -/ +noncomputable def yPlus : Fin 2 → ℂ := ![invSqrt2, invSqrt2 * I] + +/-- The `Y`-eigenvector `|-i⟩ = (|0⟩ - i|1⟩)/√2 = (1/√2, -i/√2)`, eigenvalue `-1`. -/ +noncomputable def yMinus : Fin 2 → ℂ := ![invSqrt2, -(invSqrt2 * I)] + +/-- `|+i⟩` is an eigenvector of `Y` with eigenvalue `+1`: `Y|+i⟩ = |+i⟩`. -/ +theorem pauliY_mulVec_yPlus : pauliY *ᵥ yPlus = (1 : ℂ) • yPlus := by + ext i + fin_cases i + all_goals simp [pauliY, yPlus, Matrix.mulVec, mul_comm] + ring_nf + rw [Complex.I_sq]; ring + +/-- `|-i⟩` is an eigenvector of `Y` with eigenvalue `-1`: `Y|-i⟩ = -|-i⟩`. -/ +theorem pauliY_mulVec_yMinus : pauliY *ᵥ yMinus = (-1 : ℂ) • yMinus := by + ext i + fin_cases i + all_goals simp [pauliY, yMinus, Matrix.mulVec, mul_comm] + ring_nf + rw [Complex.I_sq]; ring + +/-- `|+i⟩` is a unit vector: `⟨+i|+i⟩ = 1`. -/ +theorem yPlus_dotProduct_self : star yPlus ⬝ᵥ yPlus = 1 := by + simp only [yPlus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, star_mul', invSqrt2_star] + ring_nf + rw [show star I = -I from Complex.conj_I, invSqrt2_sq]; ring_nf; rw [Complex.I_sq]; norm_num + +/-- `|-i⟩` is a unit vector: `⟨-i|-i⟩ = 1`. -/ +theorem yMinus_dotProduct_self : star yMinus ⬝ᵥ yMinus = 1 := by + simp only [yMinus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, star_neg, star_mul', invSqrt2_star] + ring_nf + rw [show star I = -I from Complex.conj_I, invSqrt2_sq]; ring_nf; rw [Complex.I_sq]; norm_num + +/-- `|+i⟩` and `|-i⟩` are orthogonal: `⟨+i|-i⟩ = 0`. -/ +theorem yPlus_dotProduct_yMinus : star yPlus ⬝ᵥ yMinus = 0 := by + simp only [yPlus, yMinus, dotProduct, Fin.sum_univ_two, Pi.star_apply, Matrix.cons_val_zero, + Matrix.cons_val_one, star_mul', invSqrt2_star] + ring_nf + rw [show star I = -I from Complex.conj_I, invSqrt2_sq]; ring_nf; rw [Complex.I_sq]; norm_num + +/-- `|+i⟩` is nonzero (so it is a genuine eigenvector). -/ +theorem yPlus_ne_zero : yPlus ≠ 0 := by + intro h; have := yPlus_dotProduct_self; rw [h] at this; simp at this + +/-- `|-i⟩` is nonzero (so it is a genuine eigenvector). -/ +theorem yMinus_ne_zero : yMinus ≠ 0 := by + intro h; have := yMinus_dotProduct_self; rw [h] at this; simp at this + +/-- The diagonal representation of `Y`: `Y = |+i⟩⟨+i| - |-i⟩⟨-i|`. -/ +theorem pauliY_eq_outerSelf_sub : pauliY = outerSelf yPlus - outerSelf yMinus := by + ext a b + fin_cases a <;> fin_cases b <;> + simp only [pauliY, outerSelf, vecMulVec_apply, Pi.star_apply, Matrix.sub_apply, + ] <;> + simp [yPlus, yMinus, invSqrt2_star, Complex.conj_I] <;> + ring_nf <;> simp only [invSqrt2_sq] <;> ring + +/-! ### Reflections about the `-1`-eigenvectors are the Pauli matrices + +For each Pauli `P ∈ {X, Y, Z}` with `-1`-eigenvector `|ψ₋⟩`, the reflection `I - 2|ψ₋⟩⟨ψ₋|` +equals `P` itself. Indeed `|ψ₋⟩` is fixed (with sign flip) by `P`, so `P = |ψ₊⟩⟨ψ₊| - |ψ₋⟩⟨ψ₋|` +and `I = |ψ₊⟩⟨ψ₊| + |ψ₋⟩⟨ψ₋|` give `I - 2|ψ₋⟩⟨ψ₋| = P`. These are the concrete matrix core of +Nielsen & Chuang Problem 6.2(2): the three oracles `U_{|ψᵢ⟩} = I - 2|ψᵢ⟩⟨ψᵢ|` for +`|ψ₁⟩ = |1⟩`, `|ψ₂⟩ = |-⟩`, `|ψ₃⟩ = |-i⟩` are exactly the Pauli matrices `Z`, `X`, `Y`. -/ + +/-- **N&C Problem 6.2(2), `Z` case.** The reflection about `|1⟩` is `Z`: +`I - 2|1⟩⟨1| = Z` (since `Z = |0⟩⟨0| - |1⟩⟨1|` and `I = |0⟩⟨0| + |1⟩⟨1|`). -/ +theorem one_sub_two_smul_outerSelf_ket_one : + (1 : Matrix (Fin 2) (Fin 2) ℂ) - (2 : ℂ) • outerSelf (ket 1) = pauliZ := by + ext a b + fin_cases a <;> fin_cases b <;> + norm_num [pauliZ, outerSelf, ket, Matrix.vecMulVec_apply, Pi.single_apply] + +/-- **N&C Problem 6.2(2), `X` case.** The reflection about `|-⟩ = (|0⟩ - |1⟩)/√2` is `X`: +`I - 2|-⟩⟨-| = X`. -/ +theorem one_sub_two_smul_outerSelf_xMinus : + (1 : Matrix (Fin 2) (Fin 2) ℂ) - (2 : ℂ) • outerSelf xMinus = pauliX := by + ext a b + fin_cases a <;> fin_cases b <;> + simp only [pauliX, outerSelf, Matrix.one_apply, Matrix.smul_apply, Matrix.sub_apply, + vecMulVec_apply, Pi.star_apply] <;> + simp [xMinus, invSqrt2_star] <;> + ring_nf <;> simp only [invSqrt2_sq] <;> ring + +/-- **N&C Problem 6.2(2), `Y` case.** The reflection about `|-i⟩ = (|0⟩ - i|1⟩)/√2` is `Y`: +`I - 2|-i⟩⟨-i| = Y`. -/ +theorem one_sub_two_smul_outerSelf_yMinus : + (1 : Matrix (Fin 2) (Fin 2) ℂ) - (2 : ℂ) • outerSelf yMinus = pauliY := by + ext a b + fin_cases a <;> fin_cases b <;> + simp only [pauliY, outerSelf, Matrix.one_apply, Matrix.smul_apply, Matrix.sub_apply, + vecMulVec_apply, Pi.star_apply] <;> + simp [yMinus, invSqrt2_star, Complex.conj_I] <;> + ring_nf <;> simp only [invSqrt2_sq, Complex.I_sq] <;> ring + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliExponential.lean b/LeanPool/AxQM/Concrete/PauliExponential.lean new file mode 100644 index 0000000000..5b68aacc3b --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliExponential.lean @@ -0,0 +1,66 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Pauli +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.MatrixExponential +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.ExponentialInvolution +public import Mathlib.Analysis.Complex.Trigonometric +public import Mathlib.Analysis.Matrix.Normed + +/-! +# Concrete: the exponential of `i θ (n · σ)` (Nielsen & Chuang, Exercise 2.35) + +For a real *unit* three-vector `n` and a real angle `θ`, the exponential of `i θ (n · σ)` has the +closed form + +`exp (i θ (n · σ)) = cos θ • I + i sin θ • (n · σ)`. + +This is pure `2 × 2` complex-matrix mathematics: the matrix exponential is Mathlib's +`NormedSpace.exp`, and the statement names only the combination `pauliDot n = n · σ`, +raw matrices, and the real trigonometric functions. + +## Proof + +The whole content is the involution `(n · σ)² = I` for a unit vector +(`pauliDot_mul_self_of_unit`): writing the exponent as `z • (n · σ)` with `z = θ * i`, the general +`NormedSpace.exp_smul_of_mul_self_eq_one` gives `cosh z • I + sinh z • (n · σ)`, and +`Complex.cosh_mul_I` / `Complex.sinh_mul_I` turn `cosh (θ i) = cos θ` and `sinh (θ i) = (sin θ) i` +into the trigonometric form. The matrix exponential needs a norm to name its series; we supply the +`ℓ^∞`-operator norm locally via `open scoped Matrix.Norms.Operator`, exactly as Mathlib's own +`Matrix.exp_*` lemmas do (the norm choice does not affect the value of `exp`). + +## Main results + +* `pauliDot_exp_of_unit`: `exp (i θ (n · σ)) = cos θ • I + i sin θ • (n · σ)` for a unit vector `n`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open NormedSpace + +/-- **Nielsen & Chuang, Exercise 2.35** (exponential of the Pauli matrices). For a real unit vector +`n` (`n₀² + n₁² + n₂² = 1`) and a real angle `θ`, +`exp (i θ (n · σ)) = cos θ • I + i sin θ • (n · σ)`, +where `n · σ = pauliDot n`. + +The exponent `i θ (n · σ)` is written as `(θ * i) • pauliDot n`. Since `(n · σ)² = I` for a unit +vector (`pauliDot_mul_self_of_unit`), this is the case `a = pauliDot n`, `x = θ` of the general +Euler formula for an involution `NormedSpace.exp_smul_mul_I_of_mul_self_eq_one`. -/ +theorem pauliDot_exp_of_unit {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) : + exp (((θ : ℂ) * Complex.I) • pauliDot n) + = (Real.cos θ : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) + + ((Real.sin θ : ℂ) * Complex.I) • pauliDot n := by + open scoped Matrix.Norms.Operator in + exact exp_smul_mul_I_of_mul_self_eq_one (pauliDot_mul_self_of_unit hn) θ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliGroup.lean b/LeanPool/AxQM/Concrete/PauliGroup.lean new file mode 100644 index 0000000000..55b5987a5e --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliGroup.lean @@ -0,0 +1,433 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.CheckMatrix + +/-! +# Concrete: the `n`-qubit Pauli group and its faithful check-row representation + +This file builds the **`n`-qubit Pauli +group** `Gₙ` (Nielsen & Chuang §10.5, the group whose elements are the `n`-fold tensor products of +`{I, X, Y, Z}` together with an overall multiplicative factor `±1, ±i`) as an honest group, and the +**total check-row homomorphism** `r : Gₙ → 𝔽₂^{2n}` that N&C uses in the proof of Proposition 10.3. +Everything here is stated for raw matrix / index data (`Matrix`, `Concrete.pauliString`, +`Concrete.checkRow`, `ZMod`, `Fin n → Fin 4`). + +## The group + +An element of `Gₙ` is `iˢ · P_a`, a Pauli string `P_a` (`a : Fin n → Fin 4`) scaled by a +fourth-root-of-unity phase `iˢ` (`s : ZMod 4`). We model this **abstractly** by the data pair + +`PauliGroup n := { phase : ZMod 4, idx : Fin n → Fin 4 }`, + +with the twisted product `(s, a) · (t, b) = (s + t + phasePow a b, a ⊙ b)`, where `a ⊙ b` +(`pauliMulIndex`) is the componentwise Pauli-index product and `phasePow a b : ZMod 4` collects the +per-qubit product phases (`pauliMulPhase`) written as powers of `i`. This is the abstract structure +of `Gₙ`; it is identified with the actual operators by the **faithful representation** + +`pauliRep : PauliGroup n →* Matrix …, (s, a) ↦ iˢ • P_a`, + +an **injective** monoid homomorphism (`pauliRep_injective`). Modelling the group abstractly (rather +than as a `Subgroup` of matrix units) makes the check-row map the trivial second-projection map +below; faithfulness is recorded once, by the injective representation. + +The `Group` instance is derived *through* the representation: since `pauliRep` is injective and +multiplicative and lands in the (associative) matrix ring, the group axioms for `PauliGroup n` +reduce to matrix identities (associativity from `mul_assoc`, the inverse law from the involution +`pauliString_mul_self`). No group-cocycle case check is needed. + +## The check-row homomorphism + +The check row of a Pauli-group element is the check row of its index — the phase is discarded, as in +N&C ("the check matrix doesn't contain any information about the multiplicative factors"): + +`checkRowHom (s, a) := checkRow a`. + +It is a homomorphism `(Gₙ, ·) → (𝔽₂^{2n}, +)` — `checkRowHom (p q) = checkRowHom p + checkRowHom q` +(`checkRowHom_mul`, from `checkRow_pauliMulIndex`) — with *bare* kernel `checkRowHom p = 0 ↔ +p.idx = 0` (`checkRowHom_eq_zero_iff`, from `checkRow_eq_zero_iff`): the row vanishes exactly on the +phase-only elements `iˢ · I`. This is the "addition in the row representation corresponds to +multiplication of group elements" of the Proposition 10.3 proof, now for the *full* group (phases +included), not just the phase-free strings of `Concrete/CheckMatrix.lean`. + +The element `negOne : PauliGroup n := (2, 0)` represents `-I` (`pauliRep_negOne`); the hypothesis +`-I ∉ S` of Proposition 10.3 is `negOne ∉ S`. Turning the bare kernel into a *trivial* kernel on a +subgroup `S` with `negOne ∉ S` is the subject of Exercises 10.34 and 10.35 +([upstream `AxQM/NC/Ch10/Exercise10_34.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Exercise10_34.lean), [upstream `AxQM/NC/Ch10/Exercise10_35.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Exercise10_35.lean)). + +## Design notes + +* The phase group is `ZMod 4` with `iˢ` realised by `zmod4Pow s = Iˢ·ᵛᵃˡ`, a monoid homomorphism + from `(ZMod 4, +)` to `(ℂ, ·)` (`zmod4Pow_add`, using `I⁴ = 1`), injective and nonzero on the four + values `1, i, -1, -i`. The `n`-qubit phase exponent `phasePow a b = ∑ₖ singlePhasePow (aₖ) (bₖ)` + sums the single-qubit `i`-power table `singlePhasePow`, chosen so that `zmod4Pow (singlePhasePow + a b) = pauliMulPhase a b`; hence `zmod4Pow (phasePow a b) = ∏ₖ pauliMulPhase (aₖ) (bₖ)`, exactly + the scalar in the Pauli-string product law `pauliString_mul_eq_smul` — this is what makes + `pauliRep` multiplicative. +* Injectivity of `pauliRep` comes from the Hilbert–Schmidt orthogonality of the Pauli strings: + pairing `iˢ • P_a = iᵗ • P_b` against `P_a` and `P_b` under the trace (`pauliString_trace_mul`) + forces `a = b` (else a nonzero scalar would vanish) and then `iˢ = iᵗ`, hence `s = t`. +-/ + +@[expose] public section + +open Matrix Complex + +open scoped BigOperators + +namespace AxQM.Concrete + +/-! ### The fourth-root-of-unity phase `iˢ` -/ + +/-- The **fourth-root-of-unity phase** `iˢ` for `s : ZMod 4`, defined as `Complex.I ^ s.val`. Since +`I⁴ = 1`, this descends from `ℤ`/`ℕ` to `ZMod 4` and is a homomorphism `(ZMod 4, +) → (ℂ, ·)` +(`zmod4Pow_add`), taking the four values `1, i, -1, -i`. It supplies the `±1, ±i` overall factor of +a Pauli-group element. -/ +noncomputable def zmod4Pow (s : ZMod 4) : ℂ := Complex.I ^ s.val + +@[simp] theorem zmod4Pow_zero : zmod4Pow 0 = 1 := by rw [zmod4Pow]; norm_num + +@[simp] theorem zmod4Pow_one : zmod4Pow 1 = Complex.I := by + rw [zmod4Pow, show (1 : ZMod 4).val = 1 from rfl, pow_one] + +@[simp] theorem zmod4Pow_two : zmod4Pow 2 = -1 := by + rw [zmod4Pow, show (2 : ZMod 4).val = 2 from rfl]; norm_num [pow_succ, Complex.I_mul_I] + +@[simp] theorem zmod4Pow_three : zmod4Pow 3 = -Complex.I := by + rw [zmod4Pow, show (3 : ZMod 4).val = 3 from rfl]; norm_num [pow_succ, Complex.I_mul_I] + +/-- `iˢ ≠ 0`: a power of the nonzero number `i` is nonzero. -/ +theorem zmod4Pow_ne_zero (s : ZMod 4) : zmod4Pow s ≠ 0 := by + rw [zmod4Pow]; exact pow_ne_zero _ Complex.I_ne_zero + +/-- **The phase is a homomorphism** `(ZMod 4, +) → (ℂ, ·)`: `i^(x+y) = iˣ · iʸ`. Because `I⁴ = 1`, +the power `Iᵏ` depends only on `k mod 4`, and `(x + y).val ≡ x.val + y.val (mod 4)` +(`ZMod.val_add`). -/ +theorem zmod4Pow_add (x y : ZMod 4) : zmod4Pow (x + y) = zmod4Pow x * zmod4Pow y := by + have hI4 : ∀ a : ℕ, Complex.I ^ (a % 4) = Complex.I ^ a := by + intro a + conv_rhs => rw [← Nat.div_add_mod a 4, pow_add, pow_mul] + norm_num [pow_succ, Complex.I_mul_I] + rw [zmod4Pow, zmod4Pow, zmod4Pow, ZMod.val_add, hI4, pow_add] + +/-- The phase `iˢ` is **injective** in `s`: the four values `1, i, -1, -i` are distinct. -/ +theorem zmod4Pow_injective : Function.Injective zmod4Pow := by + intro x y h + simp only [zmod4Pow] at h + fin_cases x <;> fin_cases y <;> revert h <;> + simp only [ZMod.val] <;> norm_num [Complex.ext_iff, pow_succ, Complex.I_mul_I] <;> rfl + +/-- **The phase conjugates as its negation**: `zmod4Pow (-s) = star (zmod4Pow s)` (i.e. +`star (iˢ) = i⁻ˢ`). Both `zmod4Pow (-s)` and `star (zmod4Pow s)` are the inverse of the nonzero +unit-modulus number `zmod4Pow s` — `zmod4Pow s · zmod4Pow (-s) = 1` by `zmod4Pow_add`, and +`zmod4Pow s · star (zmod4Pow s) = 1` by a finite `ZMod 4` case check — so they agree by left +cancellation. This is what makes each `PauliGroup.toMat` unitary (`PauliGroup.toMat_inv`). -/ +theorem zmod4Pow_neg (s : ZMod 4) : zmod4Pow (-s) = star (zmod4Pow s) := by + have hz : zmod4Pow s ≠ 0 := zmod4Pow_ne_zero s + have h1 : zmod4Pow s * zmod4Pow (-s) = 1 := by + rw [← zmod4Pow_add, add_neg_cancel, zmod4Pow_zero] + have h2 : zmod4Pow s * star (zmod4Pow s) = 1 := by + fin_cases s <;> + simp only [zmod4Pow, ZMod.val] <;> + norm_num [Complex.ext_iff, pow_succ, Complex.I_mul_I, Complex.star_def] + exact mul_left_cancel₀ hz (h1.trans h2.symm) + +/-- **The phase has unit modulus**: `‖zmod4Pow s‖ = 1`. Directly from the definition +`zmod4Pow s = Iˢ`: `‖Iˢ‖ = ‖I‖ˢ = 1ˢ = 1`. This certifies that multiplying by a Pauli phase neither +scales nor annihilates (used, e.g., to keep the code projector a *unit* multiple of itself under +below-distance conjugation in the N&C Ex 12.34(b) recovery). -/ +theorem zmod4Pow_norm (s : ZMod 4) : ‖zmod4Pow s‖ = 1 := by + rw [zmod4Pow, norm_pow, Complex.norm_I, one_pow] + +/-- The phase carries finite sums to finite products: `i^(∑ᵢ fᵢ) = ∏ᵢ i^(fᵢ)`. Finset induction on +`zmod4Pow_zero` and `zmod4Pow_add`. -/ +theorem zmod4Pow_sum {ι : Type*} (s : Finset ι) (f : ι → ZMod 4) : + zmod4Pow (∑ i ∈ s, f i) = ∏ i ∈ s, zmod4Pow (f i) := by + classical + induction s using Finset.induction with + | empty => simp + | @insert a s ha ih => rw [Finset.sum_insert ha, Finset.prod_insert ha, zmod4Pow_add, ih] + +/-! ### The Pauli-string product phase as an exponent of `i` -/ + +/-- The **single-qubit product-phase exponent** `singlePhasePow a b : ZMod 4`, the power `s` with +`iˢ = ζ(a, b)` (`pauliMulPhase`) in the single-qubit product `σ_a σ_b = ζ(a,b) σ_{a⊙b}`. Read off +`pauliMulPhase` (`1 = i⁰`, `i = i¹`, `-1 = i²`, `-i = i³`). -/ +def singlePhasePow : Fin 4 → Fin 4 → ZMod 4 := + ![![0, 0, 0, 0], ![0, 0, 1, 3], ![0, 3, 0, 1], ![0, 1, 3, 0]] + +/-- `singlePhasePow` is the `i`-exponent of the single-qubit product phase: `i^(singlePhasePow a b) += pauliMulPhase a b`. A finite `4 × 4` case check. -/ +theorem zmod4Pow_singlePhasePow (a b : Fin 4) : + zmod4Pow (singlePhasePow a b) = pauliMulPhase a b := by + fin_cases a <;> fin_cases b <;> simp [singlePhasePow, pauliMulPhase] + +/-- The **`n`-qubit product-phase exponent** `phasePow a b : ZMod 4`, the power `s` with `iˢ = +∏ₖ ζ(aₖ, bₖ)` the total phase in the Pauli-string product law. It is the sum of the per-qubit +exponents `∑ₖ singlePhasePow (aₖ) (bₖ)`. -/ +def phasePow {n : ℕ} (a b : Fin n → Fin 4) : ZMod 4 := ∑ k, singlePhasePow (a k) (b k) + +/-- `i^(phasePow a b) = ∏ₖ pauliMulPhase (aₖ) (bₖ)`: the phase exponent exponentiates to the total +scalar in the Pauli-string product law `pauliString_mul_eq_smul`. Combines `zmod4Pow_sum` with the +single-qubit `zmod4Pow_singlePhasePow`. -/ +theorem zmod4Pow_phasePow {n : ℕ} (a b : Fin n → Fin 4) : + zmod4Pow (phasePow a b) = ∏ k, pauliMulPhase (a k) (b k) := by + rw [phasePow, zmod4Pow_sum] + exact Finset.prod_congr rfl fun k _ => zmod4Pow_singlePhasePow (a k) (b k) + +/-! ### The `n`-qubit Pauli group -/ + +/-- The **`n`-qubit Pauli group** `Gₙ` (Nielsen & Chuang §10.5), modelled abstractly by its data: a +fourth-root-of-unity phase `phase : ZMod 4` (the `iˢ` factor) and a Pauli-string index `idx : Fin n +→ Fin 4`. The element it represents is `iᵖʰᵃˢᵉ · P_idx` (`pauliRep`). -/ +@[ext] +structure PauliGroup (n : ℕ) where + /-- The fourth-root-of-unity phase power `s` (the overall factor `iˢ`). -/ + phase : ZMod 4 + /-- The Pauli-string index `a : Fin n → Fin 4` (one of `I, X, Y, Z` per qubit). -/ + idx : Fin n → Fin 4 + +namespace PauliGroup + +variable {n : ℕ} + +/-- Group multiplication `(s, a) · (t, b) = (s + t + phasePow a b, a ⊙ b)`: indices multiply +componentwise (`pauliMulIndex`) and the phases add, with the extra `phasePow a b` from the +Pauli-string product phase. -/ +instance : Mul (PauliGroup n) := + ⟨fun p q => ⟨p.phase + q.phase + phasePow p.idx q.idx, pauliMulIndex p.idx q.idx⟩⟩ + +/-- The identity `(0, 0)`: phase `i⁰ = 1` and the all-identity index (`P₀ = I`). -/ +instance : One (PauliGroup n) := ⟨⟨0, 0⟩⟩ + +/-- Inversion `(s, a)⁻¹ = (-s, a)`: a Pauli string is an involution, so only the phase inverts. -/ +instance : Inv (PauliGroup n) := ⟨fun p => ⟨-p.phase, p.idx⟩⟩ + +@[simp] theorem mul_phase (p q : PauliGroup n) : + (p * q).phase = p.phase + q.phase + phasePow p.idx q.idx := rfl + +@[simp] theorem mul_idx (p q : PauliGroup n) : (p * q).idx = pauliMulIndex p.idx q.idx := rfl + +@[simp] theorem one_phase : (1 : PauliGroup n).phase = 0 := rfl + +@[simp] theorem one_idx : (1 : PauliGroup n).idx = 0 := rfl + +@[simp] theorem inv_phase (p : PauliGroup n) : p⁻¹.phase = -p.phase := rfl + +@[simp] theorem inv_idx (p : PauliGroup n) : p⁻¹.idx = p.idx := rfl + +/-- The **faithful matrix representation** of a Pauli-group element: `(s, a) ↦ iˢ • P_a`, the +operator `iˢ · pauliString a`. This is the actual Pauli operator the abstract pair encodes; it is a +monoid homomorphism (`pauliRep`) and injective (`toMat_injective`). -/ +noncomputable def toMat (p : PauliGroup n) : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + zmod4Pow p.phase • pauliString p.idx + +/-- `toMat` is **multiplicative**: `toMat (p q) = toMat p · toMat q`. The phases combine via +`zmod4Pow_add` and `zmod4Pow_phasePow` into exactly the scalar of the Pauli-string product law +`pauliString_mul_eq_smul`. -/ +theorem toMat_mul (p q : PauliGroup n) : toMat (p * q) = toMat p * toMat q := by + simp only [toMat, mul_phase, mul_idx] + rw [smul_mul_smul_comm, pauliString_mul_eq_smul, smul_smul, zmod4Pow_add, zmod4Pow_add, + zmod4Pow_phasePow] + +/-- `toMat` sends the identity to `1`: `i⁰ • P₀ = 1 • I = I`. -/ +theorem toMat_one : toMat (1 : PauliGroup n) = 1 := by + simp only [toMat, one_phase, one_idx, zmod4Pow_zero, one_smul, pauliString_eq_one_iff] + +/-- **Faithfulness**: the representation `toMat` is injective — distinct abstract Pauli-group +elements give distinct operators. Pairing `iˢ • P_a = iᵗ • P_b` against `P_a` (resp. `P_b`) under +the trace and using the Hilbert–Schmidt orthogonality `pauliString_trace_mul` forces `a = b` (else a +nonzero scalar would vanish), and then `iˢ = iᵗ`, so `s = t` (`zmod4Pow_injective`). -/ +theorem toMat_injective : Function.Injective (toMat (n := n)) := by + rintro ⟨s, a⟩ ⟨t, b⟩ h + simp only [toMat] at h + have h2 : (2 : ℂ) ^ n ≠ 0 := pow_ne_zero _ two_ne_zero + have key : ∀ m, zmod4Pow s * (if m = a then (2 : ℂ) ^ n else 0) + = zmod4Pow t * (if m = b then (2 : ℂ) ^ n else 0) := by + intro m + have hh := congrArg (fun M => (pauliString m * M).trace) h + simpa only [Matrix.mul_smul, Matrix.trace_smul, pauliString_trace_mul, smul_eq_mul] using hh + have hab : a = b := by + by_contra hab + have ea := key a + rw [ite_eq_left rfl, ite_eq_right hab, mul_zero] at ea + exact zmod4Pow_ne_zero s ((mul_eq_zero.mp ea).resolve_right h2) + subst hab + have ea := key a + rw [ite_eq_left rfl] at ea + have hst : s = t := zmod4Pow_injective (mul_right_cancel₀ h2 ea) + subst hst; rfl + +/-- **The adjoint of a Pauli-group element is its inverse**: `toMat p⁻¹ = (toMat p)†`. Since +`toMat p = iˢ • P_a` with `P_a` Hermitian (`pauliString_isHermitian`) and `star (iˢ) = i⁻ˢ` +(`zmod4Pow_neg`), the conjugate transpose is `i⁻ˢ • P_a = toMat (−s, a) = toMat p⁻¹`. In particular +every `toMat p` is unitary (`toMat p · (toMat p)† = toMat (p · p⁻¹) = toMat 1 = 1`). -/ +theorem toMat_inv (p : PauliGroup n) : (p⁻¹).toMat = (p.toMat)ᴴ := by + rw [toMat, toMat, inv_phase, inv_idx, Matrix.conjTranspose_smul, (pauliString_isHermitian p.idx)] + congr 1 + exact zmod4Pow_neg p.phase + +/-- **The Pauli commutation sign law at the operator level.** For Pauli-group elements `p, q`, +`toMat p · toMat q = (-1)^(pauliAnticommCount p.idx q.idx) • (toMat q · toMat p)`: the phases +`iˢ` are central scalars, so the sign is the phase-free symplectic pairing of the underlying +strings (`pauliString_mul_comm_sign`). -/ +theorem toMat_mul_eq_neg_one_pow_smul (p q : PauliGroup n) : + p.toMat * q.toMat + = (-1 : ℂ) ^ pauliAnticommCount p.idx q.idx • (q.toMat * p.toMat) := by + have hpq : p.toMat * q.toMat + = (zmod4Pow p.phase * zmod4Pow q.phase) • (pauliString p.idx * pauliString q.idx) := by + simp only [toMat, smul_mul_smul_comm] + have hqp : q.toMat * p.toMat + = (zmod4Pow q.phase * zmod4Pow p.phase) • (pauliString q.idx * pauliString p.idx) := by + simp only [toMat, smul_mul_smul_comm] + rw [hpq, hqp, pauliString_mul_comm_sign p.idx q.idx, smul_smul, smul_smul] + congr 1 + ring + +/-- **Pauli operators commute or anticommute.** For any two Pauli-group elements `p, q` either +`toMat p · toMat q = toMat q · toMat p` (they commute) or `toMat p · toMat q = -(toMat q · toMat p)` +(they anticommute), according to the parity of the symplectic pairing +(`toMat_mul_eq_neg_one_pow_smul`). -/ +theorem toMat_commute_or_anticomm (p q : PauliGroup n) : + Commute p.toMat q.toMat ∨ p.toMat * q.toMat = -(q.toMat * p.toMat) := by + rcases Nat.even_or_odd (pauliAnticommCount p.idx q.idx) with he | ho + · left + rw [commute_iff_eq, toMat_mul_eq_neg_one_pow_smul, he.neg_one_pow, one_smul] + · right + rw [toMat_mul_eq_neg_one_pow_smul, ho.neg_one_pow, neg_one_smul] + +/-- **Non-commuting Pauli-group elements have anticommuting operators.** If `p * q ≠ q * p` as group +elements, then their operators anticommute: `toMat p · toMat q = -(toMat q · toMat p)`. (If they +commuted as operators, faithfulness `toMat_injective` would force `p * q = q * p`.) -/ +theorem toMat_anticomm_of_ne_mul_comm (p q : PauliGroup n) (h : p * q ≠ q * p) : + p.toMat * q.toMat = -(q.toMat * p.toMat) := by + rcases toMat_commute_or_anticomm p q with hc | ha + · exact absurd (toMat_injective (by rw [toMat_mul, toMat_mul]; exact hc.eq)) h + · exact ha + +/-- The **`n`-qubit Pauli group** structure on `PauliGroup n`. The group axioms are pulled back +through the faithful, multiplicative representation `toMat` into the associative matrix ring: +associativity is `mul_assoc` there, and the inverse law is the involution `pauliString_mul_self` +(`(i⁻ˢ • P_a)(iˢ • P_a) = 1 • I`). -/ +instance : Group (PauliGroup n) where + mul_assoc a b c := + toMat_injective (by rw [toMat_mul, toMat_mul, toMat_mul, toMat_mul, mul_assoc]) + one_mul a := toMat_injective (by rw [toMat_mul, toMat_one, one_mul]) + mul_one a := toMat_injective (by rw [toMat_mul, toMat_one, mul_one]) + inv_mul_cancel a := toMat_injective (by + rw [toMat_mul, toMat_one] + simp only [toMat, inv_phase, inv_idx] + rw [smul_mul_smul_comm, pauliString_mul_self, ← zmod4Pow_add, neg_add_cancel, zmod4Pow_zero, + one_smul]) + +/-- **The operator of a Pauli-group element is unitary**: `(toMat p)(toMat p)ᴴ = 1`. Since the +adjoint is the inverse (`toMat_inv`), this is `toMat (p · p⁻¹) = toMat 1 = 1`. The `toMat`-interface +form of unitarity, alongside `toMat_mul`/`toMat_one`/`toMat_inv`. -/ +theorem toMat_mul_conjTranspose (p : PauliGroup n) : p.toMat * p.toMat.conjTranspose = 1 := by + rw [← toMat_inv, ← toMat_mul, mul_inv_cancel, toMat_one] + +/-- **Odd symplectic pairing ⟹ the Pauli-group elements do not commute.** If +`pauliAnticommCount g.idx p.idx` is odd then `g * p ≠ p * g` as group elements. Their operators +anticommute (`toMat_mul_eq_neg_one_pow_smul`, since `(-1)^odd = -1`), and a nonzero operator cannot +equal its own negation — so were `g, p` to commute as group elements, faithfulness (`toMat_mul`) +would force the unitary `toMat (p * g)` to vanish. This is the parity-indexed group-level converse +of `toMat_anticomm_of_ne_mul_comm`. -/ +theorem mul_ne_mul_of_odd_anticommCount {g p : PauliGroup n} + (hodd : Odd (pauliAnticommCount g.idx p.idx)) : g * p ≠ p * g := by + intro heq + have hcomm : g.toMat * p.toMat = p.toMat * g.toMat := by + rw [← toMat_mul, ← toMat_mul, heq] + have hanti : g.toMat * p.toMat = -(p.toMat * g.toMat) := by + rw [toMat_mul_eq_neg_one_pow_smul, hodd.neg_one_pow, neg_one_smul] + rw [hcomm] at hanti + have hzero : p.toMat * g.toMat = 0 := by + have h2 : (2 : ℂ) • (p.toMat * g.toMat) = 0 := by + rw [two_smul]; nth_rewrite 2 [hanti]; rw [add_neg_cancel] + exact (smul_eq_zero.mp h2).resolve_left two_ne_zero + have hunit : (p * g).toMat * ((p * g).toMat)ᴴ = 1 := toMat_mul_conjTranspose (p * g) + rw [toMat_mul, hzero, Matrix.zero_mul] at hunit + exact zero_ne_one hunit + +/-! ### Finiteness of the Pauli group -/ + +/-- `PauliGroup n` as the plain product type `ZMod 4 × (Fin n → Fin 4)`, used to transport the +`DecidableEq`/`Fintype` instances (each field of `PauliGroup n` is a finite type with decidable +equality). -/ +def equivProd (n : ℕ) : PauliGroup n ≃ ZMod 4 × (Fin n → Fin 4) where + toFun p := (p.phase, p.idx) + invFun q := ⟨q.1, q.2⟩ + left_inv _ := rfl + right_inv _ := rfl + +instance : DecidableEq (PauliGroup n) := (equivProd n).decidableEq + +instance : Fintype (PauliGroup n) := Fintype.ofEquiv _ (equivProd n).symm + +/-- The faithful matrix representation **as a monoid homomorphism** `pauliRep : PauliGroup n →* +Matrix …`, `(s, a) ↦ iˢ • P_a`. Being an *injective* monoid hom into the operators, it exhibits +`PauliGroup n` as the actual `n`-qubit Pauli group `Gₙ` of Nielsen & Chuang. -/ +noncomputable def pauliRep : PauliGroup n →* Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ where + toFun := toMat + map_one' := toMat_one + map_mul' := toMat_mul + +@[simp] theorem pauliRep_apply (p : PauliGroup n) : + pauliRep p = zmod4Pow p.phase • pauliString p.idx := rfl + +/-- `pauliRep` is injective (faithfulness), the bundled form of `toMat_injective`. -/ +theorem pauliRep_injective : Function.Injective (pauliRep (n := n)) := toMat_injective + +/-! ### The total check-row homomorphism -/ + +/-- The **check row of a Pauli-group element**, the check row of its index (the overall phase `iˢ` +is discarded, as the check matrix records no phase information): `checkRowHom (s, a) = checkRow a`. +Valued in the symplectic space `𝔽₂^{2n} = (Fin n → ZMod 2) × (Fin n → ZMod 2)`. -/ +def checkRowHom (p : PauliGroup n) : (Fin n → ZMod 2) × (Fin n → ZMod 2) := checkRow p.idx + +@[simp] theorem checkRowHom_apply (p : PauliGroup n) : checkRowHom p = checkRow p.idx := rfl + +/-- The check row of the identity is `0` (the all-identity index has vanishing row). -/ +theorem checkRowHom_one : checkRowHom (1 : PauliGroup n) = 0 := + (checkRow_eq_zero_iff (0 : Fin n → Fin 4)).mpr rfl + +/-- **The total check-row homomorphism law** (Nielsen & Chuang §10.5.1, for the full Pauli group): +`r(p q) = r(p) + r(q)`, i.e. "addition in the row representation corresponds to multiplication of +group elements". The phase is irrelevant to the row, so this is the index-level additivity +`checkRow_pauliMulIndex`. -/ +theorem checkRowHom_mul (p q : PauliGroup n) : + checkRowHom (p * q) = checkRowHom p + checkRowHom q := by + simp only [checkRowHom, mul_idx, checkRow_pauliMulIndex] + +/-- **The bare kernel of the check row**: `r(p) = 0 ↔ p.idx = 0`, i.e. `checkRowHom p` vanishes +exactly when `p` is a phase-only element `iˢ · I`. From the trivial kernel of `checkRow` +(`checkRow_eq_zero_iff`). (Restricting to a subgroup `S` with `-I ∉ S` upgrades this to a *trivial* +kernel `r(p) = 0 → p = 1`.) -/ +theorem checkRowHom_eq_zero_iff (p : PauliGroup n) : checkRowHom p = 0 ↔ p.idx = 0 := + checkRow_eq_zero_iff p.idx + +/-! ### The element `-I` -/ + +/-- The Pauli-group element **`-I`**, i.e. `(2, 0)` (`i² · I = -I`). Its non-membership `negOne ∉ S` +in a subgroup `S` is the standing hypothesis `-I ∉ S` of Nielsen & Chuang Proposition 10.3. -/ +def negOne (n : ℕ) : PauliGroup n := ⟨2, 0⟩ + +/-- The representation of `negOne` is the operator `-I` (`-1` in the matrix ring): `i² • P₀ = +(-1) • I = -I`. -/ +theorem pauliRep_negOne : pauliRep (negOne n) = -1 := by + simp only [pauliRep_apply, negOne] + rw [zmod4Pow_two, neg_one_smul, (pauliString_eq_one_iff (0 : Fin n → Fin 4)).mpr rfl] + +/-- `negOne` has vanishing check row (it is a phase-only element). -/ +theorem checkRowHom_negOne : checkRowHom (negOne n) = 0 := + checkRow_eq_zero_iff (0 : Fin n → Fin 4) |>.mpr rfl + +end PauliGroup + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliGroupNegOne.lean b/LeanPool/AxQM/Concrete/PauliGroupNegOne.lean new file mode 100644 index 0000000000..2e2be6a816 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliGroupNegOne.lean @@ -0,0 +1,519 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliGroup +public import Mathlib.Algebra.Group.Subgroup.Basic +public import LeanPool.AxQM.ToMathlib.Algebra.Group.Subgroup.InvolutionClosure +public import LeanPool.AxQM.ToMathlib.GroupTheory.Subgroup.Centralizer +public import Mathlib.LinearAlgebra.LinearIndependent.Defs + +/-! +# Concrete: the structure of a Pauli subgroup `S` with `-I ∉ S` + +This file develops the +elementary group theory Nielsen & Chuang use in the proof of **Proposition 10.3** +for a subgroup `S` of the `n`-qubit Pauli group `Gₙ` (`Concrete.PauliGroup`) +satisfying `-I ∉ S` (`negOne n ∉ S`). Everything here names only the abstract group +`PauliGroup n`, its subgroups, and the check row (`ZMod`, `Fin n → Fin 4`). + +## Squares in the Pauli group + +Every Pauli-group element is an involution up to phase: since each single-qubit +Pauli squares to `I` (`pauliMul a a = 0`) with trivial phase +(`singlePhasePow a a = 0`), a group element `p = (s, a)` squares to `p * p = (2s, 0)` +(`mul_self`), a *phase-only* element. Hence `p * p` is always `I` or `-I` +(`mul_self_eq_one_or_negOne`). + +## The `-I ∉ S` structure (N&C Exercises 10.30, 10.35) + +For a subgroup `S` with `negOne n ∉ S`, `p * p ∈ S` for `p ∈ S`, and `p * p ≠ -I`, +so: + +* `imOne_notMem_of_negOne_notMem`, `negImOne_notMem_of_negOne_notMem` — **N&C Exercise 10.30** + (`-I ∉ S ⟹ ±iI ∉ S`): the phase-only elements `iI` (`imOne := (1, 0)`) and `-iI` + (`negImOne := (3, 0)`) both square to `-I` (`imOne_mul_self`, `negImOne_mul_self`), so a subgroup + `S` that is closed under products and has `-I ∉ S` can contain neither. (`pauliRep_imOne`, + `pauliRep_negImOne` confirm these two elements really represent the operators `iI` and `-iI`.) +* `sq_eq_one_of_negOne_notMem` — **`g² = I` for all `g ∈ S`** (N&C Exercise 10.35): + `S` is an *elementary abelian* `2`-group. Equivalently every `g ∈ S` is its own + inverse (`inv_eq_self_of_negOne_notMem`, N&C's `g† = g`). +* `mul_comm_of_negOne_notMem` — **`S` is abelian**: any group in which every element + squares to `1` is commutative (`gh = (gh)⁻¹ = h⁻¹g⁻¹ = hg`). This is N&C's + necessary condition (a) (commuting elements), here derived from `-I ∉ S` alone. +* `eq_one_of_checkRowHom_eq_zero_of_negOne_notMem` — **the check row is injective on + `S`**: from `r(g) = 0` and `g ∈ S` we get `g = I`. The bare kernel of `r` is the + phase-only elements `iˢ · I` (`checkRowHom_eq_zero_iff`); of those, `iI` and `-iI` + square to `-I ∉ S`, while `-I` itself is excluded directly as `-I ∉ S`, so only + `g = I` remains (the phase argument of Exercise 10.30, here inlined at the level of + the phase `s ∈ {0, 2}` rather than routed through `imOne_notMem_of_negOne_notMem`). + +Together these are the ingredients Proposition 10.3's proof invokes ("note first +that `gᵢ² = I` for all `i`") and turn the *bare* kernel of `Concrete/PauliGroup.lean` +into a *trivial* kernel on `S` — exactly what identifies `S` with its check-matrix +rows as an `𝔽₂`-vector space (the Proposition 10.3 equivalence). + +## N&C Exercise 10.34 (`-I ∉ S ↔ gⱼ² = I ∧ gⱼ ≠ -I`) — false as literally stated + +Exercise 10.34 asks to show, for `S = ⟨g₁,…,g_l⟩`, that `-I ∉ S` iff `gⱼ² = I` and +`gⱼ ≠ -I` for every generator `gⱼ`. + +* The **forward** implication is true and is + `sq_eq_one_and_ne_negOne_of_negOne_notMem_closure`: every generator lies in `S`, so + this is `sq_eq_one_of_negOne_notMem` (Exercise 10.35) together with the fact that a + member of `S` cannot equal the non-member `-I`. +* The **reverse** implication is **false** as the exercise states it: the two + per-generator conditions `gⱼ² = I` and `gⱼ ≠ -I` do not imply `-I ∉ S`. Two + hypotheses are omitted from the wording, and **neither alone suffices**: + - *Commutativity alone is insufficient.* `⟨X, -X⟩` in `PauliGroup 1`: `X` and `-X` + **commute**, both square to `I`, neither is `-I`, yet `X·(-X) = -I ∈ ⟨X, -X⟩` + (`pauliXOne_mul_negPauliXOne`, + `exists_commuting_gens_sq_one_ne_negOne_with_negOne_mem`). Here `X` and `-X` have + equal check rows, i.e. are `𝔽₂`-**dependent**. + - *Independence alone is insufficient.* `⟨X, Z⟩` in `PauliGroup 1`: `X` and `Z` are + `𝔽₂`-independent (check rows `(1,0)`, `(0,1)`) but **anticommute**, so + `(XZ)² = -I ∈ ⟨X, Z⟩` (`pauliXZ_sq_eq_negOne`, `negOne_mem_closure_pauliXZ`, + `exists_gens_sq_one_ne_negOne_with_negOne_mem`). + +The genuinely missing ingredient is `𝔽₂`-**independence** of the generators (N&C +Proposition 10.3), *together with* commutativity. Commutativity is **not** an +independent discriminator once `-I ∉ S` is known (any such subgroup is automatically +abelian, `mul_comm_of_negOne_notMem`); but for the *reverse* implication `-I ∉ S` is the +conclusion, not a hypothesis, so commutativity must be assumed alongside independence, +and neither alone suffices (the two counterexamples above). + +**The intended correct statement** — the result the book evidently means — restores +exactly these two hypotheses. Under them the biconditional holds with the exercise's own +right-hand side: `negOne_notMem_closure_iff_forall_sq_eq_one_and_ne_negOne` proves, for a +family `g` that pairwise commutes and whose check rows are `𝔽₂`-linearly independent, +`-I ∉ ⟨g₁,…,g_l⟩ ↔ (∀ j, gⱼ² = I ∧ gⱼ ≠ -I)`. Its reverse half +(`negOne_notMem_closure_of_commute_of_checkRowHom_linearIndependent`) is Proposition +10.3's check-matrix argument run in reverse: the commuting involutions generate an +elementary abelian `2`-group whose elements are the subset products +`∏ⱼ gⱼ ^ (cⱼ).val` (the general `ToMathlib` lemma +`Subgroup.exists_zmod2_prod_of_mem_closure`), and applying the check-row homomorphism +to a putative `-I = ∏ⱼ gⱼ ^ (cⱼ).val` gives `∑ⱼ cⱼ · r(gⱼ) = r(-I) = 0`, which +independence forces to the empty product `I ≠ -I`. + +So this item is formalised in full: the true forward implication, the **refutation** of +the false reverse implication by two explicit counterexamples (one commuting, one +independent — each isolating a necessary hypothesis the wording omits), **and** the +intended correct biconditional, proved. We never patch the false `↔` silently; we exhibit +its failure and separately state and prove the corrected form. +-/ + +@[expose] public section + +open scoped BigOperators +open scoped IsMulCommutative + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Diagonal identities of the Pauli-index product tables -/ + +/-- Each single-qubit Pauli squares to the identity: `a ⊙ a = 0` (i.e. `σ_a σ_a = I`). +The diagonal of the `pauliMul` table is `0`. -/ +theorem pauliMul_self (a : Fin 4) : pauliMul a a = 0 := by fin_cases a <;> decide + +/-- Squaring a single-qubit Pauli has trivial phase: `singlePhasePow a a = 0` +(`σ_a σ_a = I`, no `i`-factor). The diagonal of the `singlePhasePow` table is `0`. -/ +theorem singlePhasePow_self (a : Fin 4) : singlePhasePow a a = 0 := by fin_cases a <;> decide + +/-- The `n`-qubit product index of a string with itself is the identity index: +`a ⊙ a = 0` (componentwise `pauliMul_self`). -/ +theorem pauliMulIndex_self (a : Fin n → Fin 4) : pauliMulIndex a a = 0 := by + funext k; exact pauliMul_self (a k) + +/-- The `n`-qubit product-phase exponent of a string with itself vanishes: +`phasePow a a = 0` (the sum of the per-qubit zeros `singlePhasePow_self`). -/ +theorem phasePow_self (a : Fin n → Fin 4) : phasePow a a = 0 := by + simp only [phasePow, singlePhasePow_self, Finset.sum_const_zero] + +namespace PauliGroup + +/-! ### Squares of Pauli-group elements -/ + +/-- The phase of a square doubles: `(p * p).phase = 2 · p.phase` (the twist +`phasePow p.idx p.idx` vanishes by `phasePow_self`). -/ +theorem mul_self_phase (p : PauliGroup n) : (p * p).phase = 2 * p.phase := by + rw [mul_phase, phasePow_self, add_zero, two_mul] + +/-- The index of a square is the identity index: `(p * p).idx = 0` +(`pauliMulIndex_self`). -/ +theorem mul_self_idx (p : PauliGroup n) : (p * p).idx = 0 := by + rw [mul_idx, pauliMulIndex_self] + +/-- **A Pauli-group element squares to a phase-only element**: `p * p = (2 · p.phase, 0)`, +i.e. `(iˢ P_a)² = i²ˢ · I`. The index cancels (`mul_self_idx`), the phase doubles +(`mul_self_phase`). -/ +theorem mul_self (p : PauliGroup n) : p * p = ⟨2 * p.phase, 0⟩ := + PauliGroup.ext (mul_self_phase p) (mul_self_idx p) + +/-- **Every Pauli-group element squares to `±I`**: `p * p = I` or `p * p = -I`. Since +`p * p = (2 · p.phase, 0)` is phase-only and `2s ∈ {0, 2}` in `ZMod 4`, the square is +`(0,0) = I` or `(2,0) = -I` (`negOne`). -/ +theorem mul_self_eq_one_or_negOne (p : PauliGroup n) : p * p = 1 ∨ p * p = negOne n := by + rw [mul_self p] + rcases (by decide : ∀ s : ZMod 4, 2 * s = 0 ∨ 2 * s = 2) p.phase with h | h + · rw [h]; left; rfl + · rw [h]; right; rfl + +/-! ### The structure of a subgroup with `-I ∉ S` -/ + +/-- **N&C Exercise 10.35**: for a subgroup `S` of the Pauli group with `-I ∉ S`, every +`g ∈ S` satisfies `g² = I`. Indeed `g² = I` or `g² = -I` (`mul_self_eq_one_or_negOne`), +and `g² ∈ S` (closure under multiplication) while `-I ∉ S`, so `g² = I`. This makes `S` +an elementary abelian `2`-group. -/ +theorem sq_eq_one_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) + {p : PauliGroup n} (hp : p ∈ S) : p ^ 2 = 1 := by + rw [pow_two] + rcases mul_self_eq_one_or_negOne p with h | h + · exact h + · exact absurd (h ▸ S.mul_mem hp hp) hS + +/-- **N&C Exercise 10.35** (the group form of `g† = g`): for a subgroup `S` with `-I ∉ S`, +every `g ∈ S` is its own inverse, `g⁻¹ = g`. Immediate from `g² = I` +(`sq_eq_one_of_negOne_notMem`). Because the Pauli-group representation `toMat` is unitary, +this is the operator statement `g† = g`, recorded at the matrix level as +`toMat_isHermitian_of_negOne_notMem`. -/ +theorem inv_eq_self_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) + {p : PauliGroup n} (hp : p ∈ S) : p⁻¹ = p := by + exact inv_eq_of_mul_eq_one_right (pow_two p ▸ sq_eq_one_of_negOne_notMem hS hp) + +/-- **N&C Exercise 10.35** (`g† = g`, the operator form): for a subgroup `S` of the +`n`-qubit Pauli group with `-I ∉ S`, the operator `toMat g` of every `g ∈ S` is **Hermitian**, +`(toMat g)ᴴ = toMat g`. This is N&C's `g† = g` at the level of the actual matrix (`†` = the +conjugate transpose): the adjoint of a Pauli-group element is its inverse +(`toMat_inv : (toMat p)ᴴ = toMat p⁻¹`, i.e. the representation is unitary), and `g⁻¹ = g` on `S` +(`inv_eq_self_of_negOne_notMem`), so the adjoint equals `g` itself. Physically the stabilizer +generators are therefore genuine observables (Hermitian, with `±1` eigenvalues by `g² = I`). -/ +theorem toMat_isHermitian_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) + {p : PauliGroup n} (hp : p ∈ S) : (p.toMat).IsHermitian := by + rw [Matrix.IsHermitian, ← toMat_inv, inv_eq_self_of_negOne_notMem hS hp] + +/-- **The subgroup `S` is abelian** (N&C's necessary condition (a), derived from +`-I ∉ S`): for `g, h ∈ S`, `g h = h g`. A group in which every element squares to `1` +is commutative — `g`, `h` and `gh` are all their own inverses +(`inv_eq_self_of_negOne_notMem`), so `gh = (gh)⁻¹ = h⁻¹ g⁻¹ = h g`. -/ +theorem mul_comm_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) + {p q : PauliGroup n} (hp : p ∈ S) (hq : q ∈ S) : p * q = q * p := by + have hpq : (p * q)⁻¹ = p * q := inv_eq_self_of_negOne_notMem hS (S.mul_mem hp hq) + rw [mul_inv_rev, inv_eq_self_of_negOne_notMem hS hq, + inv_eq_self_of_negOne_notMem hS hp] at hpq + exact hpq.symm + +/-- **The check row is injective on a subgroup with `-I ∉ S`** (the *trivial* kernel, +packaging N&C Exercise 10.30): if `g ∈ S`, `-I ∉ S`, and `r(g) = 0`, then `g = I`. The +bare kernel of `r` is the phase-only elements `p = (s, 0)` (`checkRowHom_eq_zero_iff`); +such a `p` has `p² = (2s, 0)`, forced to `I` by `-I ∉ S` +(`sq_eq_one_of_negOne_notMem`), so `2s = 0`, i.e. `s ∈ {0, 2}`. `s = 2` gives +`p = -I ∈ S`, impossible; hence `s = 0` and `p = I`. -/ +theorem eq_one_of_checkRowHom_eq_zero_of_negOne_notMem {S : Subgroup (PauliGroup n)} + (hS : negOne n ∉ S) {p : PauliGroup n} (hp : p ∈ S) (h : checkRowHom p = 0) : + p = 1 := by + have hidx : p.idx = 0 := (checkRowHom_eq_zero_iff p).mp h + have hsq : p * p = 1 := by rw [← pow_two]; exact sq_eq_one_of_negOne_notMem hS hp + have hphase : 2 * p.phase = 0 := by rw [← mul_self_phase p, hsq]; rfl + rcases (by decide : ∀ s : ZMod 4, 2 * s = 0 → s = 0 ∨ s = 2) p.phase hphase with hph | hph + · exact PauliGroup.ext hph hidx + · refine absurd ?_ hS + have hp' : p = negOne n := PauliGroup.ext hph hidx + rwa [hp'] at hp + +/-! ### The phase-only elements `iI`, `-iI`, and N&C Exercise 10.30 -/ + +/-- The Pauli-group element **`iI`**, i.e. `(1, 0)` (`i¹ · I = iI`). With `-iI` (`negImOne`) these +are the two phase-only elements N&C Exercise 10.30 excludes from a subgroup `S` with `-I ∉ S`: +both square to `-I`. -/ +def imOne (n : ℕ) : PauliGroup n := ⟨1, 0⟩ + +/-- The Pauli-group element **`-iI`**, i.e. `(3, 0)` (`i³ · I = -iI`). -/ +def negImOne (n : ℕ) : PauliGroup n := ⟨3, 0⟩ + +/-- The representation of `imOne` is the operator `iI` (`Complex.I` times the identity matrix): +`i¹ • P₀ = i • I`. Mirrors `pauliRep_negOne`; confirms `imOne` really is `iI`. -/ +theorem pauliRep_imOne : pauliRep (imOne n) = Complex.I • 1 := by + simp only [pauliRep_apply, imOne] + rw [zmod4Pow_one, (pauliString_eq_one_iff (0 : Fin n → Fin 4)).mpr rfl] + +/-- The representation of `negImOne` is the operator `-iI`: `i³ • P₀ = -i • I`. Mirrors +`pauliRep_negOne`; confirms `negImOne` really is `-iI`. -/ +theorem pauliRep_negImOne : pauliRep (negImOne n) = -Complex.I • 1 := by + simp only [pauliRep_apply, negImOne] + rw [zmod4Pow_three, (pauliString_eq_one_iff (0 : Fin n → Fin 4)).mpr rfl] + +/-- **`(iI)² = -I`**: `imOne² = negOne`. The index cancels and the phase doubles to `2 · 1 = 2` +in `ZMod 4` (`mul_self`), giving the phase-only element `(2, 0) = -I`. -/ +theorem imOne_mul_self : imOne n * imOne n = negOne n := + PauliGroup.ext (by simp only [mul_self_phase, imOne, negOne]; decide) (mul_self_idx _) + +/-- **`(-iI)² = -I`**: `negImOne² = negOne`. The phase doubles to `2 · 3 = 6 = 2` in `ZMod 4`. -/ +theorem negImOne_mul_self : negImOne n * negImOne n = negOne n := + PauliGroup.ext (by simp only [mul_self_phase, negImOne, negOne]; decide) (mul_self_idx _) + +/-- **N&C Exercise 10.30** (the `iI` half): for a subgroup `S` of the `n`-qubit Pauli group with +`-I ∉ S`, the element `iI` is not in `S`. If `iI ∈ S` then `(iI)² = -I ∈ S` by closure +(`imOne_mul_self`), contradicting `-I ∉ S`. -/ +theorem imOne_notMem_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) : + imOne n ∉ S := fun h => hS (imOne_mul_self ▸ S.mul_mem h h) + +/-- **N&C Exercise 10.30** (the `-iI` half): for a subgroup `S` of the `n`-qubit Pauli group with +`-I ∉ S`, the element `-iI` is not in `S`. If `-iI ∈ S` then `(-iI)² = -I ∈ S` by closure +(`negImOne_mul_self`), contradicting `-I ∉ S`. -/ +theorem negImOne_notMem_of_negOne_notMem {S : Subgroup (PauliGroup n)} (hS : negOne n ∉ S) : + negImOne n ∉ S := fun h => hS (negImOne_mul_self ▸ S.mul_mem h h) + +/-! ### N&C Exercise 10.34: `-I ∉ S ↔ gⱼ² = I ∧ gⱼ ≠ -I` (forward true, reverse false) -/ + +/-- **N&C Exercise 10.34, forward implication** (the true half). Let `S = ⟨g₁,…,g_l⟩ = closure T` be +the subgroup generated by a set `T` of Pauli-group elements. If `-I ∉ S` then every generator +`g ∈ T` satisfies `g² = I` and `g ≠ -I`. Both follow from `g ∈ S` (`Subgroup.subset_closure`): the +square is `I` by `sq_eq_one_of_negOne_notMem` (Exercise 10.35), and `g ≠ -I` because `g ∈ S` while +`-I ∉ S`. (The converse is **false**: the two per-generator conditions do not imply `-I ∉ S` +without `𝔽₂`-independence of the generators — see `exists_gens_sq_one_ne_negOne_with_negOne_mem` +and `exists_commuting_gens_sq_one_ne_negOne_with_negOne_mem`.) -/ +theorem sq_eq_one_and_ne_negOne_of_negOne_notMem_closure {T : Set (PauliGroup n)} + (hS : negOne n ∉ Subgroup.closure T) {g : PauliGroup n} (hg : g ∈ T) : + g ^ 2 = 1 ∧ g ≠ negOne n := by + have hmem : g ∈ Subgroup.closure T := Subgroup.subset_closure hg + exact ⟨sq_eq_one_of_negOne_notMem hS hmem, fun h => hS (h ▸ hmem)⟩ + +/-- The single-qubit Pauli `X` as an element of the Pauli group `PauliGroup 1`: phase `0`, index +`X = 1` (so `pauliRep` sends it to the operator `X`). One of the two generators of the Exercise +10.34 counterexample `⟨X, Z⟩ ∋ -I`. -/ +def pauliXOne : PauliGroup 1 := ⟨0, ![1]⟩ + +/-- The single-qubit Pauli `Z` as an element of the Pauli group `PauliGroup 1`: phase `0`, index +`Z = 3`. The second generator of the Exercise 10.34 counterexample. -/ +def pauliZOne : PauliGroup 1 := ⟨0, ![3]⟩ + +/-- `X² = I` in `PauliGroup 1`: the index cancels and the phase doubles to `2·0 = 0` +(`mul_self`). -/ +theorem pauliXOne_sq : pauliXOne ^ 2 = 1 := by decide + +/-- `Z² = I` in `PauliGroup 1`, exactly as for `X` (`mul_self`, phase `2·0 = 0`). -/ +theorem pauliZOne_sq : pauliZOne ^ 2 = 1 := by decide + +/-- `X ≠ -I` in `PauliGroup 1` (they differ in their Pauli index: `X` has index `1`, `-I` index +`0`). -/ +theorem pauliXOne_ne_negOne : pauliXOne ≠ negOne 1 := by decide + +/-- `Z ≠ -I` in `PauliGroup 1` (index `3` versus `0`). -/ +theorem pauliZOne_ne_negOne : pauliZOne ≠ negOne 1 := by decide + +/-- The phase of the product `X·Z` in `PauliGroup 1` is `3`: `0 + 0 + phasePow ![1] ![3] = +singlePhasePow 1 3 = 3`. (Equivalently `XZ = -iY = i³·Y`.) -/ +theorem pauliXOne_mul_pauliZOne_phase : (pauliXOne * pauliZOne).phase = 3 := by decide + +/-- **`(XZ)² = -I`** in `PauliGroup 1`: `X` and `Z` anticommute, so their product `XZ = -iY` squares +to `-I`. Concretely `(XZ)²` is phase-only with phase `2·(XZ).phase = 2·3 = 2` (`mul_self`, +`pauliXOne_mul_pauliZOne_phase`), i.e. `⟨2, 0⟩ = -I`. This is the crux of the Exercise 10.34 +counterexample. -/ +theorem pauliXZ_sq_eq_negOne : + pauliXOne * pauliZOne * (pauliXOne * pauliZOne) = negOne 1 := by decide + +/-- **`-I ∈ ⟨X, Z⟩`** in `PauliGroup 1`: since `X, Z ∈ ⟨X, Z⟩` and the subgroup is closed under +products, `(XZ)² ∈ ⟨X, Z⟩`, and `(XZ)² = -I` (`pauliXZ_sq_eq_negOne`). So `-I` lies in the group +generated by `X` and `Z` even though `X² = Z² = I` and `X, Z ≠ -I` — the failure of the reverse +implication of Exercise 10.34. -/ +theorem negOne_mem_closure_pauliXZ : + negOne 1 ∈ Subgroup.closure ({pauliXOne, pauliZOne} : Set (PauliGroup 1)) := by + have hX : pauliXOne ∈ Subgroup.closure ({pauliXOne, pauliZOne} : Set (PauliGroup 1)) := + Subgroup.subset_closure (by simp) + have hZ : pauliZOne ∈ Subgroup.closure ({pauliXOne, pauliZOne} : Set (PauliGroup 1)) := + Subgroup.subset_closure (by simp) + have hmem := Subgroup.mul_mem _ (Subgroup.mul_mem _ hX hZ) (Subgroup.mul_mem _ hX hZ) + rwa [pauliXZ_sq_eq_negOne] at hmem + +/-- **N&C Exercise 10.34, reverse implication is false.** There is a set `T` of Pauli-group elements +each satisfying `g² = I` and `g ≠ -I`, whose generated subgroup `⟨T⟩` nevertheless contains `-I`. +The witness is `T = {X, Z}` in `PauliGroup 1`: `X² = Z² = I` and `X, Z ≠ -I` +(`pauliXOne_sq`, `pauliZOne_sq`, `pauliXOne_ne_negOne`, `pauliZOne_ne_negOne`), yet `-I ∈ ⟨X, Z⟩` +(`negOne_mem_closure_pauliXZ`), because `X` and `Z` anticommute. This refutes the `⇐` direction of +the exercise's `↔`. (Here `X, Z` are `𝔽₂`-independent but non-commuting; for a *commuting* +counterexample, isolating independence as the missing hypothesis, see +`exists_commuting_gens_sq_one_ne_negOne_with_negOne_mem`.) -/ +theorem exists_gens_sq_one_ne_negOne_with_negOne_mem : + ∃ T : Set (PauliGroup 1), + (∀ g ∈ T, g ^ 2 = 1 ∧ g ≠ negOne 1) ∧ negOne 1 ∈ Subgroup.closure T := by + refine ⟨{pauliXOne, pauliZOne}, ?_, negOne_mem_closure_pauliXZ⟩ + intro g hg + simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hg + rcases hg with rfl | rfl + · exact ⟨pauliXOne_sq, pauliXOne_ne_negOne⟩ + · exact ⟨pauliZOne_sq, pauliZOne_ne_negOne⟩ + +/-- The single-qubit Pauli `-X` as an element of `PauliGroup 1`: phase `2` (`i² = -1`), index +`X = 1`. With `X` it forms a *commuting* Exercise 10.34 counterexample witnessing that commutativity +of the generators is **not** enough to rescue the reverse implication. -/ +def negPauliXOne : PauliGroup 1 := ⟨2, ![1]⟩ + +/-- `(-X)² = I` in `PauliGroup 1`: the index cancels and the phase doubles to `2·2 = 0` in `ZMod 4` +(`mul_self`). -/ +theorem negPauliXOne_sq : negPauliXOne ^ 2 = 1 := by decide + +/-- `-X ≠ -I` in `PauliGroup 1` (they differ in their Pauli index: `-X` has index `1`, `-I` index +`0`). -/ +theorem negPauliXOne_ne_negOne : negPauliXOne ≠ negOne 1 := by decide + +/-- **`X·(-X) = -I`** in `PauliGroup 1`: the phases add to `0 + 2 = 2` and the indices cancel +(`X·X = I`, `pauliMulIndex_self`), giving `⟨2, 0⟩ = -I`. This puts `-I` in `⟨X, -X⟩` in a single +product — no anticommutation needed. -/ +theorem pauliXOne_mul_negPauliXOne : pauliXOne * negPauliXOne = negOne 1 := by decide + +/-- **`(-X)·X = -I`** in `PauliGroup 1`, symmetric to `pauliXOne_mul_negPauliXOne`. -/ +theorem negPauliXOne_mul_pauliXOne : negPauliXOne * pauliXOne = negOne 1 := by decide + +/-- **`X` and `-X` commute** in `PauliGroup 1`: both products equal `-I` +(`pauliXOne_mul_negPauliXOne`, `negPauliXOne_mul_pauliXOne`). They differ only by the central phase +`i²`, so of course they commute — the point of the commuting counterexample. -/ +theorem pauliXOne_mul_negPauliXOne_comm : + pauliXOne * negPauliXOne = negPauliXOne * pauliXOne := + pauliXOne_mul_negPauliXOne.trans negPauliXOne_mul_pauliXOne.symm + +/-- **N&C Exercise 10.34, reverse implication is false even for COMMUTING generators.** The +generating set `T = {X, -X}` in `PauliGroup 1` consists of two *commuting* elements (obligation on +the pairwise product below), each squaring to `I` and different from `-I`, yet `X·(-X) = -I ∈ +⟨X, -X⟩` (`pauliXOne_mul_negPauliXOne`). Hence the `⇐` direction of the exercise's `↔` fails **even +under §10.5's standing abelian convention**: commutativity of the generators is not the missing +hypothesis (indeed any subgroup with `-I ∉ S` is automatically abelian, +`mul_comm_of_negOne_notMem`). The genuinely omitted hypothesis is `𝔽₂`-**independence** of the +generators (N&C Proposition 10.3, `IndependentGenerators`): `X` and `-X` have equal check rows +(`r(X) = r(-X)`), so they are dependent. -/ +theorem exists_commuting_gens_sq_one_ne_negOne_with_negOne_mem : + ∃ T : Set (PauliGroup 1), + (∀ g ∈ T, g ^ 2 = 1 ∧ g ≠ negOne 1) ∧ + (∀ g ∈ T, ∀ h ∈ T, g * h = h * g) ∧ + negOne 1 ∈ Subgroup.closure T := by + refine ⟨{pauliXOne, negPauliXOne}, ?_, ?_, ?_⟩ + · intro g hg + simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hg + rcases hg with rfl | rfl + · exact ⟨pauliXOne_sq, pauliXOne_ne_negOne⟩ + · exact ⟨negPauliXOne_sq, negPauliXOne_ne_negOne⟩ + · intro g hg h hh + simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hg hh + rcases hg with rfl | rfl <;> rcases hh with rfl | rfl + · rfl + · exact pauliXOne_mul_negPauliXOne_comm + · exact pauliXOne_mul_negPauliXOne_comm.symm + · rfl + · have hX : pauliXOne ∈ Subgroup.closure ({pauliXOne, negPauliXOne} : Set (PauliGroup 1)) := + Subgroup.subset_closure (by simp) + have hnX : negPauliXOne ∈ Subgroup.closure ({pauliXOne, negPauliXOne} : Set (PauliGroup 1)) := + Subgroup.subset_closure (by simp) + have hmem := Subgroup.mul_mem _ hX hnX + rwa [pauliXOne_mul_negPauliXOne] at hmem + +/-! ### N&C Exercise 10.34, the intended correct statement: the `↔` for independent commuting +generators -/ + +/-- The check row of a power: `checkRowHom (p ^ k) = k • checkRowHom p`. `checkRowHom` is a +homomorphism to the additive group `𝔽₂^{2n}` (`checkRowHom_mul`), so it carries a power to the +`ℕ`-scalar multiple of the row. -/ +theorem checkRowHom_pow (p : PauliGroup n) (k : ℕ) : + checkRowHom (p ^ k) = k • checkRowHom p := by + induction k with + | zero => rw [pow_zero, checkRowHom_one, zero_smul] + | succ k ih => rw [pow_succ, checkRowHom_mul, ih, succ_nsmul] + +/-- `-I ≠ I` in the Pauli group: they differ in their phase (`2 ≠ 0` in `ZMod 4`). -/ +theorem negOne_ne_one : negOne n ≠ 1 := by + intro h + have hp : (negOne n).phase = (1 : PauliGroup n).phase := congrArg PauliGroup.phase h + simp only [negOne, one_phase] at hp + exact absurd hp (by decide) + +/-- **N&C Exercise 10.34, the intended correct statement (reverse implication).** The exercise's +`⇐` (`gⱼ² = I ∧ gⱼ ≠ -I ⟹ -I ∉ S`) is false as literally stated +(`exists_gens_sq_one_ne_negOne_with_negOne_mem`): it omits `𝔽₂`-**independence** of the generators +(N&C Proposition 10.3) *and* their commutativity, and neither alone suffices. Restoring both +hypotheses makes it true — this is the result the book evidently means. If `g₁, …, g_l` pairwise +commute, each squares to `I`, and their check rows `r(gⱼ)` are `𝔽₂`-linearly independent, then +`-I ∉ ⟨g₁, …, g_l⟩`. + +The proof is Proposition 10.3's check-matrix argument, run in reverse. As the generators commute and +are involutions, `⟨g₁, …, g_l⟩` is an elementary abelian `2`-group in which every element is a +subset product `∏ⱼ gⱼ ^ (cⱼ).val`, `c : Fin l → 𝔽₂` (`exists_zmod2_prod_of_mem_closure`). If `-I` +were such a product then, pushing the check-row homomorphism through it (`checkRowHom_pow`, +`checkRowHom_mul`), +`0 = r(-I) = ∑ⱼ cⱼ · r(gⱼ)`; `𝔽₂`-independence forces `c = 0`, so the product is the empty product +`I ≠ -I`. -/ +theorem negOne_notMem_closure_of_commute_of_checkRowHom_linearIndependent {l : ℕ} + {g : Fin l → PauliGroup n} (hcomm : ∀ i j, g i * g j = g j * g i) + (hsq : ∀ i, g i ^ 2 = 1) + (hindep : LinearIndependent (ZMod 2) fun i => (g i).checkRowHom) : + negOne n ∉ Subgroup.closure (Set.range g) := by + intro hmem + set S := Subgroup.closure (Set.range g) with hSdef + -- the closure of pairwise-commuting generators is a commutative group + have hcs : ∀ x ∈ Set.range g, ∀ y ∈ Set.range g, x * y = y * x := by + rintro _ ⟨i, rfl⟩ _ ⟨j, rfl⟩; exact hcomm i j + have hic : IsMulCommutative ↥S := + Subgroup.isMulCommutative_closure fun x hx y hy _ => hcs x hx y hy + -- the generators, lifted into the subgroup, are commuting involutions generating all of `↥S` + have hmemg : ∀ i, g i ∈ S := fun i => Subgroup.subset_closure ⟨i, rfl⟩ + let g' : Fin l → ↥S := fun i => ⟨g i, hmemg i⟩ + have hg'sq : ∀ i, g' i ^ 2 = 1 := fun i => + Subtype.ext (by simpa [SubmonoidClass.coe_pow] using hsq i) + have hgen : Subgroup.closure (Set.range g') = ⊤ := by + apply Subgroup.map_injective S.subtype_injective + rw [MonoidHom.map_closure, ← MonoidHom.range_eq_map, Subgroup.range_subtype, + show S.subtype '' Set.range g' = Set.range g from by rw [← Set.range_comp]; rfl, ← hSdef] + -- normal form: `-I` is a subset product of the generators (`↥S` is a `CommGroup` via the + -- scoped `IsMulCommutative → CommGroup` instance) + obtain ⟨c, hc⟩ := Subgroup.exists_zmod2_prod_of_mem_closure g' hg'sq + (hgen ▸ Subgroup.mem_top (⟨negOne n, hmem⟩ : ↥S)) + -- push the check-row homomorphism through the product: `r(-I) = ∑ⱼ (cⱼ).val • r(gⱼ)` + have hcheck : ∀ s : Finset (Fin l), + checkRowHom ((∏ i ∈ s, g' i ^ (c i).val : ↥S) : PauliGroup n) + = ∑ i ∈ s, (c i).val • checkRowHom (g i) := by + intro s + induction s using Finset.induction with + | empty => + simp only [Finset.prod_empty, Finset.sum_empty, OneMemClass.coe_one, checkRowHom_one] + | insert a s ha ih => + rw [Finset.prod_insert ha, Finset.sum_insert ha, Subgroup.coe_mul, checkRowHom_mul, ih, + SubmonoidClass.coe_pow, checkRowHom_pow] + have hval : ((∏ i, g' i ^ (c i).val : ↥S) : PauliGroup n) = negOne n := by rw [← hc] + have hsum : ∑ i, (c i).val • checkRowHom (g i) = 0 := by + rw [← hcheck Finset.univ, hval] + exact checkRowHom_negOne + -- rewrite the `ℕ`-scalars as `𝔽₂`-scalars and apply linear independence + have hsum' : ∑ i, c i • checkRowHom (g i) = 0 := by + rw [← hsum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← Nat.cast_smul_eq_nsmul (ZMod 2) (c i).val (checkRowHom (g i)), + ZMod.natCast_rightInverse (c i)] + have hc0 : ∀ i, c i = 0 := Fintype.linearIndependent_iff.mp hindep c hsum' + -- with `c = 0` the product is the identity, contradicting `-I = ∏ⱼ gⱼ ^ (cⱼ).val` + have hone : (⟨negOne n, hmem⟩ : ↥S) = 1 := + hc.trans (Finset.prod_eq_one fun i _ => by rw [hc0 i]; simp) + exact negOne_ne_one (by simpa using Subtype.ext_iff.mp hone) + +/-- **N&C Exercise 10.34, the intended correct statement (the `↔`).** The book's biconditional +`-I ∉ ⟨g₁, …, g_l⟩ ↔ (gⱼ² = I ∧ gⱼ ≠ -I ∀j)` is false as literally stated; it becomes true once the +two hypotheses N&C's context supplies are restored — the generators **commute** and their check rows +are `𝔽₂`-**independent** (equivalently, by Proposition 10.3, the generators are independent). Under +these standing hypotheses the biconditional holds with exactly the exercise's right-hand side. Its +forward direction is `sq_eq_one_and_ne_negOne_of_negOne_notMem_closure` (needing neither +hypothesis); the reverse is `negOne_notMem_closure_of_commute_of_checkRowHom_linearIndependent`. -/ +theorem negOne_notMem_closure_iff_forall_sq_eq_one_and_ne_negOne {l : ℕ} + {g : Fin l → PauliGroup n} (hcomm : ∀ i j, g i * g j = g j * g i) + (hindep : LinearIndependent (ZMod 2) fun i => (g i).checkRowHom) : + negOne n ∉ Subgroup.closure (Set.range g) ↔ ∀ i, g i ^ 2 = 1 ∧ g i ≠ negOne n := + ⟨fun hS i => sq_eq_one_and_ne_negOne_of_negOne_notMem_closure hS ⟨i, rfl⟩, + fun h => negOne_notMem_closure_of_commute_of_checkRowHom_linearIndependent hcomm + (fun i => (h i).1) hindep⟩ + +end PauliGroup + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliNormalizer.lean b/LeanPool/AxQM/Concrete/PauliNormalizer.lean new file mode 100644 index 0000000000..92cff9c695 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizer.lean @@ -0,0 +1,675 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit +public import LeanPool.AxQM.Concrete.PauliGroup + +/-! +# Concrete: the Pauli normalizer, and uniqueness up to global phase (Theorem 10.6, part 1) + +This file opens the formalisation of +Nielsen & Chuang **Theorem 10.6** — *any unitary `U` on `n` qubits with `U Gₙ U† ⊆ Gₙ` is, up to a +global phase, a product of `O(n²)` Hadamard/phase/CNOT gates*. It supplies the **framework** (the +matrix-level normalizer predicate), the **easy direction** (every Clifford circuit is a Pauli +normalizer), and the **reduction that gives the theorem its "up to a global phase" shape**: two +unitaries with the *same conjugation action* on the Pauli group agree up to a unit scalar. Every +statement is about raw matrix / index data (`Matrix`, `Concrete.pauliString`, +`Concrete.PauliGroup`, `Matrix.unitaryGroup`, `Fin n → Fin 4`). + +## What is proved + +* `exists_smul_one_of_commute_pauliString` — **the Pauli commutant is the scalars.** A matrix `W` + commuting with every Pauli string `P_g` is a scalar `c • 1`. This is *Schur's lemma for the Pauli + group*: since the `4ⁿ` Pauli strings are a basis of the `2ⁿ×2ⁿ` matrices (`pauliBasis`), `W` + commutes with every matrix, hence lies in the centre of the matrix ring, which is the scalars + (`Matrix.center_eq_scalar_image`). It is the linear-algebraic engine of the whole reduction. + +* `IsPauliNormalizer U` — **the normalizer predicate.** `U` is unitary and conjugates every element + of the Pauli group `Gₙ` (via its faithful representation `PauliGroup.toMat`) back into `Gₙ`. This + is exactly N&C's hypothesis "if `g ∈ Gₙ` then `U g U† ∈ Gₙ`", i.e. membership in the normalizer + `N(Gₙ)`. + +* `unitary_eq_smul_of_conj_pauliString_eq` — **uniqueness up to global phase (the reduction).** If + two unitaries `U, V` conjugate every Pauli string identically (`U P_g U† = V P_g V†` for all `g`), + then `U = c • V` for a unit scalar `c` (`‖c‖ = 1`). Hence a normalizer unitary is determined, up + to a global phase, by its conjugation action on `Gₙ` — the precise sense of Theorem 10.6's "up to + a global phase", and what reduces the theorem to realising that action by a Clifford circuit. + +* `unitary_isGlobalPhase_of_conj_pauliString_eq_self` — **Nielsen & Chuang Exercise 10.38 (core).** + A unitary that fixes every Pauli string under conjugation (`U P_g U† = P_g`) is a global phase + `c • 1`, `‖c‖ = 1`. The `V = 1` special case of the reduction; the physical statement that only + scalars commute with the whole Pauli group. + +* `CliffordCircuit.sign_eq_one_or_neg_one` / `cliffordCircuit_isPauliNormalizer` — **the easy + direction of Theorem 10.6.** The conjugation phase of a Clifford circuit is `±1`, and therefore + every Clifford circuit is a Pauli normalizer: `U P_a U† = ±P_{U.act a}`, so `U (iˢ P_a) U† = + i^{s'} P_{U.act a} ∈ Gₙ` (`CliffordCircuit.conj_pauliString`). This is the containment + `⟨H, S, CNOT⟩ ⊆ N(Gₙ)`; Theorem 10.6 is the converse. + +* `IsPauliNormalizer.exists_sign_conj_pauliString` — **the sign is `±1`.** A normalizer conjugates + each phase-free Pauli string to a `±1` multiple of a Pauli string, `U P_a U† = z • P_b` with + `z ∈ {1, -1}`. The phase is real because `P_a` is an involution, so `(U P_a U†)² = 1` forces + `z² = 1`; this is the shape (signs `±1`, never `±i`) the synthesis of Exercise 10.40 uses. + +* `IsPauliNormalizer.exists_signedPerm` — **a normalizer is a `±1`-signed permutation of the Pauli + strings.** Bundles the per-string data into a permutation `σ : Equiv.Perm (Fin n → Fin 4)` and a + sign function `ε` valued in `{1, -1}` with `U P_a U† = ε a • P_{σ a}`. Injectivity of the action + (hence bijectivity, on the finite index set) comes from conjugating back by `U` and + Hilbert–Schmidt orthogonality. It is the combinatorial object Exercise 10.40 synthesises. + +* `unitary_eq_smul_cliffordCircuit_of_conj_eq` — **the converse reduces to synthesis.** If a unitary + conjugates the Pauli strings exactly as a Clifford circuit `C` does, it equals `C` up to a global + phase. With `exists_signedPerm` this reduces the converse of Theorem 10.6 to a combinatorial + problem: synthesise a Clifford circuit realising the normalizer's signed permutation. + +* `unitaryConj_commute_iff` / `IsPauliNormalizer.exists_signedPerm_symplectic` — **a normalizer's + signed permutation is symplectic.** Conjugation by a unitary preserves commutation (it is an + algebra automorphism), so a normalizer's induced permutation `σ` of the Pauli-string indices + preserves the binary symplectic form (`pauliAnticommCount`, mod 2) of Exercise 10.33 — in + particular it maps anticommuting Pauli strings to anticommuting ones. This is the structural + invariant the multi-qubit inductive synthesis of Exercise 10.40 (parts 2–3) rests on (N&C part 2 + opens by noting the images of the anticommuting `Z₁, X₁` anticommute). + +## Design notes + +* The reduction is stated over `pauliString` (the phase-free Pauli operators) because that is where + `pauliBasis`/`CliffordCircuit.conj_pauliString` live; the normalizer *predicate* is stated over + the full group `PauliGroup.toMat = iˢ • P_a` (phases included) to be faithful to N&C's `Gₙ`. The + two match because conjugation is `ℂ`-linear, so acting on `iˢ P_a` is acting on `P_a` scaled. +* `unitary_eq_smul_of_conj_pauliString_eq` needs no normalizer hypothesis: it holds for *any* two + unitaries with equal conjugation action. The normalizer only enters when one shows the action is + realised by a Clifford circuit (the converse, developed later — the inductive synthesis of + N&C Exercise 10.40 and its `O(n²)` gate count). +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Schur's lemma for the Pauli group: the commutant is the scalars -/ + +/-- **The Pauli commutant is the scalars.** If `W` commutes with every Pauli string `P_g`, then +`W = c • 1` for some scalar `c`. Because the `4ⁿ` Pauli strings form a basis of the `2ⁿ×2ⁿ` +matrices (`sum_repr_smul_pauliString`), `W` commutes with *every* matrix, so it lies in the centre +of the matrix ring, which is the scalar matrices (`Matrix.center_eq_scalar_image`). -/ +theorem exists_smul_one_of_commute_pauliString + (W : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + (h : ∀ g, Commute (pauliString g) W) : ∃ c : ℂ, W = c • 1 := by + have hz : W ∈ Set.center (Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) := by + rw [Semigroup.mem_center_iff] + intro M + rw [← sum_repr_smul_pauliString M, Finset.sum_mul, Matrix.mul_sum] + exact Finset.sum_congr rfl fun g _ => by + rw [smul_mul_assoc, mul_smul_comm, (h g).eq] + rw [Matrix.center_eq_scalar_image, Set.center_eq_univ] at hz + obtain ⟨c, -, rfl⟩ := hz + exact ⟨c, Algebra.algebraMap_eq_smul_one c⟩ + +/-! ### The normalizer predicate -/ + +/-- **The Pauli normalizer** `N(Gₙ)`. `U` is unitary and conjugates every element of the `n`-qubit +Pauli group `Gₙ` (through its faithful matrix representation `PauliGroup.toMat`, `p ↦ iˢ • P_a`) +back into `Gₙ`. This is exactly Nielsen & Chuang's hypothesis in Theorem 10.6: "if `g ∈ Gₙ` then +`U g U† ∈ Gₙ`". -/ +def IsPauliNormalizer (U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : Prop := + U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ ∧ + ∀ p : PauliGroup n, ∃ q : PauliGroup n, U * p.toMat * Uᴴ = q.toMat + +/-! ### Uniqueness up to global phase (the reduction) -/ + +/-- **Uniqueness up to a global phase.** If two unitaries `U, V` conjugate every Pauli string +identically — `U P_g U† = V P_g V†` for all `g` — then they differ by a unit global phase: +`∃ c, ‖c‖ = 1 ∧ U = c • V`. Setting `W = V† U`, the hypothesis says `W` commutes with every `P_g` +(cancelling `V†V = U†U = 1`), so `W = c • 1` by `exists_smul_one_of_commute_pauliString`; unitarity +forces `‖c‖ = 1`, and `U = V W = c • V`. This is the precise content of Theorem 10.6's "up to a +global phase": a normalizer unitary is determined, up to a scalar, by its conjugation action. -/ +theorem unitary_eq_smul_of_conj_pauliString_eq + {U V : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) + (hV : V ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) + (h : ∀ g, U * pauliString g * Uᴴ = V * pauliString g * Vᴴ) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • V := by + -- basic unitarity facts (`star = ᴴ`) + have hVV : V * Vᴴ = 1 := by simpa [star_eq_conjTranspose] using (mem_unitaryGroup_iff).mp hV + have hVV' : Vᴴ * V = 1 := by simpa [star_eq_conjTranspose] using (mem_unitaryGroup_iff').mp hV + set W := Vᴴ * U with hW + have hWH : Wᴴ = Uᴴ * V := by rw [hW, conjTranspose_mul, conjTranspose_conjTranspose] + -- W is a product of unitaries, hence unitary (submonoid closure) + have hWmem : W ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ := by + rw [hW]; exact mul_mem (by rw [← star_eq_conjTranspose]; exact Unitary.star_mem hV) hU + have hWW : W * Wᴴ = 1 := by simpa [star_eq_conjTranspose] using (mem_unitaryGroup_iff).mp hWmem + have hWW' : Wᴴ * W = 1 := by simpa [star_eq_conjTranspose] using (mem_unitaryGroup_iff').mp hWmem + -- W commutes with every Pauli string + have hcomm : ∀ g, Commute (pauliString g) W := by + intro g + have hconj : W * pauliString g * Wᴴ = pauliString g := by + rw [hW, hWH] + calc Vᴴ * U * pauliString g * (Uᴴ * V) + = Vᴴ * (U * pauliString g * Uᴴ) * V := by simp [Matrix.mul_assoc] + _ = Vᴴ * (V * pauliString g * Vᴴ) * V := by rw [h g] + _ = (Vᴴ * V) * pauliString g * (Vᴴ * V) := by simp [Matrix.mul_assoc] + _ = pauliString g := by rw [hVV', Matrix.one_mul, Matrix.mul_one] + -- multiply `hconj` on the right by `W` and cancel `Wᴴ W = 1` + have key : W * pauliString g = pauliString g * W := by + have hmulW := congrArg (· * W) hconj + simpa [Matrix.mul_assoc, hWW'] using hmulW + exact key.symm + -- so W is a scalar, and unitarity pins its modulus to 1 + obtain ⟨c, hc⟩ := exists_smul_one_of_commute_pauliString W hcomm + -- unitarity of `W = c • 1` pins the modulus of `c` to `1` + have hWform : W * Wᴴ = (c * star c) • 1 := by + rw [hc, conjTranspose_smul, conjTranspose_one, smul_mul_smul_comm, Matrix.mul_one] + have hcc : c * star c = 1 := by + have he : ((c * star c) • (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ)) = 1 := by + rw [← hWform]; exact hWW + have h11 := congrFun (congrFun he (fun _ => (0 : Fin 2))) (fun _ => (0 : Fin 2)) + simpa [Matrix.smul_apply, Matrix.one_apply] using h11 + have hmod : ‖c‖ = 1 := by + have hnorm : ‖c‖ * ‖c‖ = 1 := by + have hn : ‖c * star c‖ = ‖(1 : ℂ)‖ := by rw [hcc] + rwa [norm_mul, norm_star, norm_one] at hn + rcases mul_self_eq_one_iff.mp hnorm with h1 | h1 + · exact h1 + · linarith [norm_nonneg c] + refine ⟨c, hmod, ?_⟩ + -- U = V W = c • V + have hVWU : V * W = U := by rw [hW, ← Matrix.mul_assoc, hVV, Matrix.one_mul] + rw [← hVWU, hc, mul_smul_comm, Matrix.mul_one] + +/-- **Nielsen & Chuang Exercise 10.38 (core).** A unitary `U` that *fixes* every Pauli string under +conjugation (`U P_g U† = P_g` for all `g`) is a global phase: `∃ c, ‖c‖ = 1 ∧ U = c • 1`. The +`V = 1` special case of `unitary_eq_smul_of_conj_pauliString_eq`. -/ +theorem unitary_isGlobalPhase_of_conj_pauliString_eq_self + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) + (h : ∀ g, U * pauliString g * Uᴴ = pauliString g) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • 1 := + unitary_eq_smul_of_conj_pauliString_eq hU (Submonoid.one_mem _) + (fun g => by rw [h g, conjTranspose_one, Matrix.one_mul, Matrix.mul_one]) + +/-! ### The easy direction: every Clifford circuit is a Pauli normalizer -/ + +/-- The single-gate Hadamard conjugation phase is `±1`: `hadamardPauliSign a ∈ {1, -1}`. -/ +private theorem hadamardPauliSign_eq_one_or_neg_one (a : Fin 4) : + hadamardPauliSign a = 1 ∨ hadamardPauliSign a = -1 := by + fin_cases a <;> simp [hadamardPauliSign] + +/-- The single-gate phase-gate conjugation phase is `±1`: `phasePauliSign a ∈ {1, -1}`. -/ +private theorem phasePauliSign_eq_one_or_neg_one (a : Fin 4) : + phasePauliSign a = 1 ∨ phasePauliSign a = -1 := by + fin_cases a <;> simp [phasePauliSign] + +/-- The single-gate CNOT conjugation phase is `±1`: `cnotPauliSign a b ∈ {1, -1}`. -/ +private theorem cnotPauliSign_eq_one_or_neg_one (a b : Fin 4) : + cnotPauliSign a b = 1 ∨ cnotPauliSign a b = -1 := by + fin_cases a <;> fin_cases b <;> simp [cnotPauliSign] + +/-- An elementary Clifford gate conjugates a Pauli string with a `±1` phase. -/ +theorem CliffordGate.sign_eq_one_or_neg_one (γ : CliffordGate n) (g : Fin n → Fin 4) : + γ.sign g = 1 ∨ γ.sign g = -1 := by + cases γ with + | had j => simpa [CliffordGate.sign] using hadamardPauliSign_eq_one_or_neg_one (g j) + | phase j => simpa [CliffordGate.sign] using phasePauliSign_eq_one_or_neg_one (g j) + | cnot c t _ => simpa [CliffordGate.sign] using cnotPauliSign_eq_one_or_neg_one (g c) (g t) + +/-- **A Clifford circuit conjugates a Pauli string with a `±1` phase**: `U.sign g ∈ {1, -1}`, since +it is a product of the per-gate `±1` phases (`CliffordGate.sign_eq_one_or_neg_one`). -/ +theorem CliffordCircuit.sign_eq_one_or_neg_one (U : CliffordCircuit n) (g : Fin n → Fin 4) : + CliffordCircuit.sign U g = 1 ∨ CliffordCircuit.sign U g = -1 := by + induction U with + | nil => left; rfl + | cons γ U ih => + rw [CliffordCircuit.sign] + rcases ih with hU | hU <;> + rcases γ.sign_eq_one_or_neg_one (CliffordCircuit.act U g) with hγ | hγ <;> + simp [hU, hγ] + +/-- The Clifford-circuit conjugation phase is a fourth root of unity: `U.sign g = iᵏ` for some +`k : ZMod 4` (indeed `k ∈ {0, 2}`, i.e. `±1`). Packaging `sign_eq_one_or_neg_one` in the phase +form `zmod4Pow` needed to land the conjugate back in the Pauli group `Gₙ`. -/ +theorem CliffordCircuit.sign_eq_zmod4Pow (U : CliffordCircuit n) (g : Fin n → Fin 4) : + ∃ k : ZMod 4, CliffordCircuit.sign U g = zmod4Pow k := by + rcases CliffordCircuit.sign_eq_one_or_neg_one U g with h | h + · exact ⟨0, by rw [h, zmod4Pow_zero]⟩ + · exact ⟨2, by rw [h, zmod4Pow_two]⟩ + +/-- **The easy direction of Nielsen & Chuang Theorem 10.6**: every Clifford circuit `U` (a sequence +of Hadamard/phase/CNOT gates) is a Pauli normalizer. It is unitary (`CliffordCircuit. +mul_conjTranspose`), and for a group element `iˢ • P_a` its conjugate is `iˢ • (±P_{U.act a}) = +i^{s'} • P_{U.act a} ∈ Gₙ`, the `±1` phase folded into the fourth-root-of-unity factor +(`CliffordCircuit.conj_pauliString` + `CliffordCircuit.sign_eq_zmod4Pow`). This is the containment +`⟨H, S, CNOT⟩ ⊆ N(Gₙ)`; Theorem 10.6 asserts the converse. -/ +theorem cliffordCircuit_isPauliNormalizer (U : CliffordCircuit n) : + IsPauliNormalizer (CliffordCircuit.toMatrix U) := by + refine ⟨?_, fun p => ?_⟩ + · rw [mem_unitaryGroup_iff, star_eq_conjTranspose] + exact CliffordCircuit.mul_conjTranspose U + · obtain ⟨k, hk⟩ := CliffordCircuit.sign_eq_zmod4Pow U p.idx + refine ⟨⟨p.phase + k, CliffordCircuit.act U p.idx⟩, ?_⟩ + simp only [PauliGroup.toMat] + rw [mul_smul_comm, smul_mul_assoc, CliffordCircuit.conj_pauliString, smul_smul, hk, + ← zmod4Pow_add] + +/-! ### The induced signed permutation of a normalizer, and the reduction to Clifford synthesis -/ + +/-- **A Pauli normalizer conjugates each phase-free Pauli string to a `±1` multiple of a Pauli +string.** For `U ∈ N(Gₙ)` and any index `a`, there are an index `b` and a sign `z ∈ {1, -1}` with +`U P_a U† = z • P_b`. Two facts combine: the normalizer hypothesis applied to the group element +`⟨0, a⟩ = P_a` gives `U P_a U† = iˢ • P_b` for a Pauli-group element `⟨s, b⟩`; and `P_a` is an +involution (`pauliString_mul_self`), so `(U P_a U†)² = 1` (unitarity cancels the inner `U† U`), +forcing `(iˢ)² = 1`, i.e. `iˢ = ±1` (`mul_self_eq_one_iff`). This `±1`-signed shape of the +conjugation action is what the inductive synthesis of Nielsen & Chuang Exercise 10.40 relies on +(the encoded generators pick up `±1` signs, never `±i`). -/ +theorem IsPauliNormalizer.exists_sign_conj_pauliString + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : IsPauliNormalizer U) (a : Fin n → Fin 4) : + ∃ (b : Fin n → Fin 4) (z : ℂ), (z = 1 ∨ z = -1) ∧ + U * pauliString a * Uᴴ = z • pauliString b := by + obtain ⟨hUmem, hUnorm⟩ := hU + obtain ⟨q, hq⟩ := hUnorm ⟨0, a⟩ + have hpa : (⟨0, a⟩ : PauliGroup n).toMat = pauliString a := by simp [PauliGroup.toMat] + rw [hpa] at hq + refine ⟨q.idx, zmod4Pow q.phase, ?_, hq⟩ + -- unitarity of `U`, both handed + have hUUH : U * Uᴴ = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff.mp hUmem + have hUHU : Uᴴ * U = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hUmem + -- `(U P_a U†)² = 1` because `P_a` is an involution and `U† U = 1` + have hsq : (U * pauliString a * Uᴴ) * (U * pauliString a * Uᴴ) = 1 := + calc U * pauliString a * Uᴴ * (U * pauliString a * Uᴴ) + = U * pauliString a * (Uᴴ * U) * pauliString a * Uᴴ := by simp only [Matrix.mul_assoc] + _ = 1 := by + rw [hUHU, Matrix.mul_one, Matrix.mul_assoc U (pauliString a) (pauliString a), + pauliString_mul_self, Matrix.mul_one, hUUH] + -- rewrite the square as `(iˢ)² • 1 = 1` and read off `(iˢ)² = 1` + rw [hq] at hsq + simp only [PauliGroup.toMat] at hsq + rw [smul_mul_smul_comm, pauliString_mul_self] at hsq + have hz2 : zmod4Pow q.phase * zmod4Pow q.phase = 1 := by + have h00 := congrFun (congrFun hsq (fun _ => 0)) (fun _ => 0) + simpa [Matrix.smul_apply, Matrix.one_apply, smul_eq_mul] using h00 + exact mul_self_eq_one_iff.mp hz2 + +/-- **A Pauli normalizer induces a `±1`-signed permutation of the Pauli-string indices.** For +`U ∈ N(Gₙ)` there are a permutation `σ` of the index set `Fin n → Fin 4` and a sign function `ε` +valued in `{1, -1}` with `U P_a U† = ε a • P_{σ a}` for every `a`. The per-index datum comes from +`exists_sign_conj_pauliString`; the induced map is *injective* — conjugating back by `U` +(`Uᴴ · U = 1`) expresses `P_a` and `P_{a'}` as the *same* operator scaled by `ε a`, `ε a'`, so +`P_a = ±P_{a'}`, and Hilbert–Schmidt orthogonality (`pauliString_trace_mul`) forces `a = a'` — hence +a bijection on the finite index set `Fin n → Fin 4` (`Finite.injective_iff_bijective`). This is the +combinatorial object that Nielsen & Chuang Exercise 10.40 synthesises by a Clifford circuit: a +signed permutation of the `4ⁿ` Pauli strings. -/ +theorem IsPauliNormalizer.exists_signedPerm + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ (σ : Equiv.Perm (Fin n → Fin 4)) (ε : (Fin n → Fin 4) → ℂ), + (∀ a, ε a = 1 ∨ ε a = -1) ∧ ∀ a, U * pauliString a * Uᴴ = ε a • pauliString (σ a) := by + have hUmem : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ := hU.1 + choose f ε hcond using hU.exists_sign_conj_pauliString + have hε : ∀ a, ε a = 1 ∨ ε a = -1 := fun a => (hcond a).1 + have hconj : ∀ a, U * pauliString a * Uᴴ = ε a • pauliString (f a) := fun a => (hcond a).2 + have hUHU : Uᴴ * U = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hUmem + -- conjugating back by `U` recovers a matrix from its `U`-conjugate + have hback : ∀ M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ, Uᴴ * (U * M * Uᴴ) * U = M := by + intro M + calc Uᴴ * (U * M * Uᴴ) * U = (Uᴴ * U) * M * (Uᴴ * U) := by simp only [Matrix.mul_assoc] + _ = M := by rw [hUHU, Matrix.one_mul, Matrix.mul_one] + have hinj : Function.Injective f := by + intro a a' hff + have ha : pauliString a = ε a • (Uᴴ * pauliString (f a) * U) := by + have hb := hback (pauliString a) + rw [hconj a, mul_smul_comm, smul_mul_assoc] at hb + exact hb.symm + have ha' : pauliString a' = ε a' • (Uᴴ * pauliString (f a) * U) := by + have hb := hback (pauliString a') + rw [hconj a', ← hff, mul_smul_comm, smul_mul_assoc] at hb + exact hb.symm + have hεsq : ε a' * ε a' = 1 := by rcases hε a' with h | h <;> rw [h] <;> ring + have hcoef : ε a * ε a' * ε a' = ε a := by rw [mul_assoc, hεsq, mul_one] + have hrel : pauliString a = (ε a * ε a') • pauliString a' := by + rw [ha, ha', smul_smul, hcoef] + by_contra hne + have t1 : (pauliString a * pauliString a).trace = (2 : ℂ) ^ n := by + rw [pauliString_trace_mul, ite_eq_left rfl] + have t2 : (pauliString a * pauliString a').trace = 0 := by + rw [pauliString_trace_mul, ite_eq_right hne] + have hcong := congrArg (fun M => (pauliString a * M).trace) hrel + rw [mul_smul_comm, Matrix.trace_smul, smul_eq_mul, t1, t2, mul_zero] at hcong + exact absurd hcong (pow_ne_zero n (by norm_num)) + exact ⟨Equiv.ofBijective f (Finite.injective_iff_bijective.mp hinj), ε, hε, fun a => hconj a⟩ + +/-- **The converse of Theorem 10.6 reduces to Clifford synthesis.** If a unitary `U` conjugates the +Pauli strings exactly as a Clifford circuit `C` does — `U P_g U† = C.sign g • P_{C.act g}` for all +`g`, i.e. `U` realises `C`'s signed permutation — then `U` equals `C` up to a unit global phase: +`∃ c, ‖c‖ = 1 ∧ U = c • C.toMatrix`. Immediate from the uniqueness reduction +`unitary_eq_smul_of_conj_pauliString_eq` once `C`'s conjugation is folded back through +`CliffordCircuit.conj_pauliString`. Combined with `IsPauliNormalizer.exists_signedPerm`, it turns +the converse of Theorem 10.6 into a purely combinatorial task: *synthesise a Clifford circuit whose +signed permutation matches the normalizer's* — the content of Nielsen & Chuang Exercise 10.40. -/ +theorem unitary_eq_smul_cliffordCircuit_of_conj_eq + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) (C : CliffordCircuit n) + (h : ∀ g, U * pauliString g * Uᴴ + = CliffordCircuit.sign C g • pauliString (CliffordCircuit.act C g)) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C := by + refine unitary_eq_smul_of_conj_pauliString_eq hU ?_ (fun g => ?_) + · rw [mem_unitaryGroup_iff, star_eq_conjTranspose] + exact CliffordCircuit.mul_conjTranspose C + · rw [h g, ← CliffordCircuit.conj_pauliString C g] + +/-! ### Multiplicativity of conjugation by an isometry -/ + +/-- **Conjugation by an isometry is multiplicative.** If `Mᴴ * M = 1`, then +`(M * P * Mᴴ) * (M * Q * Mᴴ) = M * (P * Q) * Mᴴ`: the middle `Mᴴ * M` collapses to `1`. This is the +homomorphism property behind a Pauli normalizer's conjugation action — reused wherever a synthesised +circuit's `Y`-image is forced by its `X`- and `Z`-images (Exercise 10.40). -/ +theorem conj_mul_conj_of_conjTranspose_mul_self + {N : Type*} [Fintype N] [DecidableEq N] {M : Matrix N N ℂ} (hM : Mᴴ * M = 1) + (P Q : Matrix N N ℂ) : + (M * P * Mᴴ) * (M * Q * Mᴴ) = M * (P * Q) * Mᴴ := by + calc (M * P * Mᴴ) * (M * Q * Mᴴ) + = M * P * (Mᴴ * M) * Q * Mᴴ := by simp only [Matrix.mul_assoc] + _ = M * (P * Q) * Mᴴ := by rw [hM, Matrix.mul_one]; simp only [Matrix.mul_assoc] + +/-! ### Single-qubit case: `X` and `Z` determine the conjugation action (Exercise 10.40 part 1) -/ + +/-- **On a single qubit, `Y = i · X Z`**: `pauliString (fun _ => 2) = i • (pauliString (fun _ => 1) +· pauliString (fun _ => 3))`. From the Pauli-string product law `pauliString_mul_eq_smul` the single +factor is `P_X P_Z = (-i) • P_Y` (`pauliMulPhase 1 3 = -i`, product index `pauliMul 1 3 = 2`), and +`i · (-i) = 1`. This writes the third single-qubit Pauli through the two generators `X, Z`, so a +conjugation action is fixed by its values on `X` and `Z` alone. -/ +theorem pauliString_two_eq_smul_mul : + pauliString (fun _ : Fin 1 => (2 : Fin 4)) + = Complex.I • (pauliString (fun _ : Fin 1 => (1 : Fin 4)) * pauliString (fun _ => 3)) := by + rw [pauliString_mul_eq_smul, smul_smul] + have hidx : pauliMulIndex (fun _ : Fin 1 => (1 : Fin 4)) (fun _ => 3) = fun _ => 2 := by + funext k; fin_cases k; rfl + rw [hidx] + have hph : Complex.I * ∏ k : Fin 1, pauliMulPhase ((fun _ : Fin 1 => (1 : Fin 4)) k) + ((fun _ : Fin 1 => (3 : Fin 4)) k) = 1 := by + simp [pauliMulPhase, Complex.I_mul_I] + rw [hph, one_smul] + +/-- **A single-qubit unitary is determined, up to a global phase, by how it conjugates `X` and +`Z`.** If two unitaries `U, V` on one qubit agree on conjugating the Pauli `X` (`P_{fun _ => 1}`) +and the Pauli `Z` (`P_{fun _ => 3}`), then `U = c • V` for a unit scalar `c` (`‖c‖ = 1`). The +generators `X, Z` fix the whole conjugation action: `I ↦ I` (unitarity) and `Y = i X Z ↦ +i (U X U†)(U Z U†)` by multiplicativity of conjugation (`Uᴴ U = 1` cancels in the middle, +`pauliString_two_eq_smul_mul`), so agreement on `X, Z` forces agreement on every single-qubit Pauli; +`unitary_eq_smul_of_conj_pauliString_eq` then concludes. This reduces the single-qubit case of +Nielsen & Chuang Theorem 10.6 (Exercise 10.40 part 1) from *matching the full signed permutation* to +*matching the images of `X` and `Z`* — the two generators an `H/S`-word Clifford synthesis must +hit. -/ +theorem unitary_eq_smul_of_conj_singleQubit_XZ + {U V : Matrix (Fin 1 → Fin 2) (Fin 1 → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 1 → Fin 2) ℂ) + (hV : V ∈ Matrix.unitaryGroup (Fin 1 → Fin 2) ℂ) + (hX : U * pauliString (fun _ => 1) * Uᴴ = V * pauliString (fun _ => 1) * Vᴴ) + (hZ : U * pauliString (fun _ => 3) * Uᴴ = V * pauliString (fun _ => 3) * Vᴴ) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • V := by + have hUUH : U * Uᴴ = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff.mp hU + have hVVH : V * Vᴴ = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff.mp hV + have hUHU : Uᴴ * U = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hU + have hVHV : Vᴴ * V = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hV + refine unitary_eq_smul_of_conj_pauliString_eq hU hV (fun g => ?_) + obtain ⟨a, rfl⟩ : ∃ a : Fin 4, g = fun _ => a := ⟨g 0, by funext i; fin_cases i; rfl⟩ + fin_cases a + · -- `a = 0` : the identity Pauli, both conjugates equal `1` + change U * pauliString (fun _ : Fin 1 => (0 : Fin 4)) * Uᴴ + = V * pauliString (fun _ : Fin 1 => (0 : Fin 4)) * Vᴴ + rw [pauliString_const_zero, Matrix.mul_one, Matrix.mul_one, hUUH, hVVH] + · -- `a = 1` : `X` + exact hX + · -- `a = 2` : `Y`, through `Y = i X Z` and multiplicativity + change U * pauliString (fun _ : Fin 1 => (2 : Fin 4)) * Uᴴ + = V * pauliString (fun _ : Fin 1 => (2 : Fin 4)) * Vᴴ + rw [pauliString_two_eq_smul_mul, mul_smul_comm, smul_mul_assoc, mul_smul_comm, smul_mul_assoc] + refine congrArg (_ • ·) ?_ + rw [← conj_mul_conj_of_conjTranspose_mul_self hUHU, + ← conj_mul_conj_of_conjTranspose_mul_self hVHV, hX, hZ] + · -- `a = 3` : `Z` + exact hZ + +/-! ### Single-qubit synthesis: `H`/`S` generate the normalizer up to phase (Exercise 10.40 part 1) + +The base case of the converse of Theorem 10.6. A single-qubit normalizer `U` induces a `±1`-signed +permutation of the four Pauli-string indices `{I, X, Y, Z}` (`exists_signedPerm`); it fixes `I`, so +it sends `X` and `Z` to a *distinct* pair of non-identity strings with `±1` signs. By the +`X, Z`-determinacy reduction `unitary_eq_smul_of_conj_singleQubit_XZ` it suffices to realise those +two images by a Clifford circuit — and the single-qubit `H`, `S` gates already do: their phase-free +action is a transposition of the index set (`H : X ↔ Z`, `S : X ↔ Y`), so their words realise every +permutation of `{X, Y, Z}` (`⟨(X Z), (X Y)⟩ = S₃`, `exists_cliffordCircuit_singleQubit_act`), and +the trivial-action Pauli-conjugation words (`Z = S²`, `X = H S² H`, `Y = X · Z`) realise every +`±1` sign pattern on `X, Z` (`exists_cliffordCircuit_singleQubit_signFix`). Gluing a permutation +word to a sign-fix word (`act_append` / `sign_append`) hits an arbitrary valid `(X, Z)` image, and +the determinacy reduction upgrades that to `U = c • C.toMatrix` for an `H`/`S`-word `C`, `‖c‖ = 1` +— Theorem 10.6 for `n = 1`. (The `n + 1` inductive step and the `O(n²)` gate count are the remaining +parts of Exercise 10.40.) -/ + +/-- **A unitary conjugates a non-identity Pauli string to a non-identity one.** If `U` is an +isometry (`Uᴴ U = 1`) and `U P_a U† = z • P_b` with `z ≠ 0` and `a` not the all-identity index +(`a ≠ 0`), then the image index is non-identity too (`b ≠ 0`). Trace argument: an isometry preserves +the trace, so `tr (U P_a U†) = tr P_a = 0` because a non-identity Pauli string is traceless +(`pauliString_trace`); but were `b = 0`, then `tr (z • P_b) = z · 2ⁿ ≠ 0`. This is what forces a +single-qubit normalizer to send `X` and `Z` to genuine (non-identity) Pauli strings. -/ +theorem conj_pauliString_index_ne_zero + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hUHU : Uᴴ * U = 1) + {a b : Fin n → Fin 4} {z : ℂ} + (h : U * pauliString a * Uᴴ = z • pauliString b) (hz : z ≠ 0) (ha : a ≠ 0) : b ≠ 0 := by + intro hb + have e1 : (U * pauliString a * Uᴴ).trace = 0 := by + rw [Matrix.trace_mul_comm, ← Matrix.mul_assoc, hUHU, Matrix.one_mul, pauliString_trace, + ite_eq_right ha] + have e2 : (U * pauliString a * Uᴴ).trace = z * 2 ^ n := by + rw [h, Matrix.trace_smul, hb, pauliString_trace, ite_eq_left rfl, smul_eq_mul] + rw [e1] at e2 + exact mul_ne_zero hz (pow_ne_zero n two_ne_zero) e2.symm + +/-- **`H` and `S` realise every permutation of the single-qubit Pauli indices.** For distinct +non-identity targets `aX, aZ` (i.e. `aX, aZ ∈ {X, Y, Z}`, `aX ≠ aZ`), there is an `H`/`S` Clifford +circuit `p` whose phase-free action sends `X ↦ aX` and `Z ↦ aZ`. Since `H`'s action is the +transposition `X ↔ Z` and `S`'s is `X ↔ Y`, their words generate all of `S₃` on `{X, Y, Z}`; the six +permutations are the six explicit words below (`[]`, `[H]`, `[S]`, `[H,S,H]`, `[H,S]`, `[S,H]`), +selected by `fin_cases` and verified by `decide` on the computable action, the invalid index +combinations being ruled out by the distinctness/non-identity hypotheses. -/ +theorem exists_cliffordCircuit_singleQubit_act {aX aZ : Fin 4} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) : + ∃ p : CliffordCircuit 1, CliffordCircuit.act p (fun _ => 1) = (fun _ => aX) ∧ + CliffordCircuit.act p (fun _ => 3) = (fun _ => aZ) := by + fin_cases aX <;> fin_cases aZ <;> + first + | exact absurd rfl h0X + | exact absurd rfl h0Z + | exact absurd rfl hne + | exact ⟨[], by decide, by decide⟩ + | exact ⟨[.had 0], by decide, by decide⟩ + | exact ⟨[.phase 0], by decide, by decide⟩ + | exact ⟨[.had 0, .phase 0, .had 0], by decide, by decide⟩ + | exact ⟨[.had 0, .phase 0], by decide, by decide⟩ + | exact ⟨[.phase 0, .had 0], by decide, by decide⟩ + +/-- **Every `±1` sign pattern on `X, Z` is realised by a trivial-action `H`/`S` word.** For target +signs `sX, sZ ∈ {1, -1}` there is a Clifford circuit `f` that fixes the `X` and `Z` indices under +conjugation (`f.act X = X`, `f.act Z = Z`) with `f.sign X = sX`, `f.sign Z = sZ`. These are the +Pauli-conjugation words: `[]` (no flip); `X = H S² H` conjugation flips the sign of `Z` only; +`Z = S²` conjugation flips `X` only; and their composite `Y`-type word flips both. The four cases +are verified by `decide` (action) and `simp` (the `±1` sign, a product of the per-gate phases). -/ +theorem exists_cliffordCircuit_singleQubit_signFix {sX sZ : ℂ} + (hsX : sX = 1 ∨ sX = -1) (hsZ : sZ = 1 ∨ sZ = -1) : + ∃ f : CliffordCircuit 1, CliffordCircuit.act f (fun _ => 1) = (fun _ => 1) ∧ + CliffordCircuit.act f (fun _ => 3) = (fun _ => 3) ∧ + CliffordCircuit.sign f (fun _ => 1) = sX ∧ CliffordCircuit.sign f (fun _ => 3) = sZ := by + rcases hsX with rfl | rfl <;> rcases hsZ with rfl | rfl + · exact ⟨[], by decide, by decide, by simp [CliffordCircuit.sign], by simp [CliffordCircuit.sign]⟩ + · exact ⟨[.had 0, .phase 0, .phase 0, .had 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update]⟩ + · exact ⟨[.phase 0, .phase 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + phasePauli, phasePauliSign, Function.update]⟩ + · exact ⟨[.had 0, .phase 0, .phase 0, .had 0, .phase 0, .phase 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update]⟩ + +/-- **Single-qubit synthesis (the combinatorial core of Exercise 10.40 part 1).** For any valid +single-qubit signed permutation — distinct non-identity targets `aX, aZ` and signs `zX, zZ` in +`{1, -1}` — there is an `H`/`S` Clifford circuit `C` realising it exactly: `C.act X = aX`, +`C.act Z = aZ`, +`C.sign X = zX`, `C.sign Z = zZ`. Take a permutation word `p` hitting the target *indices* +(`exists_cliffordCircuit_singleQubit_act`); its `X, Z` signs are some `pX, pZ ∈ {±1}` +(`CliffordCircuit.sign_eq_one_or_neg_one`). Append a sign-fix word `f` for the signs `zX · pX`, +`zZ · pZ` (`exists_cliffordCircuit_singleQubit_signFix`): since `f` fixes the indices, +`(p ++ f).act = p.act` (`act_append`) and `(p ++ f).sign X = f.sign X · p.sign X = (zX · pX) · pX = +zX` (`sign_append`, using `pX² = 1`). All 24 valid signed permutations are covered, matching the +order of the single-qubit Clifford group modulo global phase. -/ +theorem exists_cliffordCircuit_singleQubit_act_sign {aX aZ : Fin 4} {zX zZ : ℂ} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) + (hzX : zX = 1 ∨ zX = -1) (hzZ : zZ = 1 ∨ zZ = -1) : + ∃ C : CliffordCircuit 1, + CliffordCircuit.act C (fun _ => 1) = (fun _ => aX) ∧ + CliffordCircuit.sign C (fun _ => 1) = zX ∧ + CliffordCircuit.act C (fun _ => 3) = (fun _ => aZ) ∧ + CliffordCircuit.sign C (fun _ => 3) = zZ := by + obtain ⟨p, hpX, hpZ⟩ := exists_cliffordCircuit_singleQubit_act h0X h0Z hne + have hpXpm := CliffordCircuit.sign_eq_one_or_neg_one p (fun _ => 1) + have hpZpm := CliffordCircuit.sign_eq_one_or_neg_one p (fun _ => 3) + obtain ⟨f, hfaX, hfaZ, hfsX, hfsZ⟩ := + exists_cliffordCircuit_singleQubit_signFix (sX := zX * CliffordCircuit.sign p (fun _ => 1)) + (sZ := zZ * CliffordCircuit.sign p (fun _ => 3)) + (by rcases hzX with h | h <;> rcases hpXpm with h' | h' <;> rw [h, h'] <;> norm_num) + (by rcases hzZ with h | h <;> rcases hpZpm with h' | h' <;> rw [h, h'] <;> norm_num) + refine ⟨p ++ f, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hfaX, hpX] + · rw [CliffordCircuit.sign_append, hfaX, hfsX]; rcases hpXpm with h | h <;> rw [h] <;> ring + · rw [CliffordCircuit.act_append, hfaZ, hpZ] + · rw [CliffordCircuit.sign_append, hfaZ, hfsZ]; rcases hpZpm with h | h <;> rw [h] <;> ring + +/-- **Nielsen & Chuang Theorem 10.6 for a single qubit.** Every single-qubit Pauli normalizer `U` +equals a global phase times an `H`/`S` Clifford circuit: `∃ C, c, ‖c‖ = 1 ∧ U = c • C.toMatrix`. +`U`'s conjugation action is a `±1`-signed permutation of the Pauli indices (`exists_signedPerm`) +that fixes the identity; its `X` and `Z` images are therefore distinct non-identity Pauli strings +(`conj_pauliString_index_ne_zero` for non-identity, `σ` injective for distinctness) carrying `±1` +signs. Synthesise a Clifford circuit `C` realising exactly those images +(`exists_cliffordCircuit_singleQubit_act_sign`); then `U` and `C.toMatrix` conjugate `X` and `Z` +identically, so `unitary_eq_smul_of_conj_singleQubit_XZ` gives `U = c • C.toMatrix` with `‖c‖ = 1`. +This is the base case (`n = 1`) of the converse of Theorem 10.6; the `n + 1` inductive step and the +`O(n²)` gate-count bound (the rest of Exercise 10.40) remain. -/ +theorem isPauliNormalizer_singleQubit_eq_smul_cliffordCircuit + {U : Matrix (Fin 1 → Fin 2) (Fin 1 → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ (C : CliffordCircuit 1) (c : ℂ), ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C := by + obtain ⟨σ, ε, hε, hconj⟩ := hU.exists_signedPerm + have hUmem : U ∈ Matrix.unitaryGroup (Fin 1 → Fin 2) ℂ := hU.1 + have hUHU : Uᴴ * U = 1 := by + simpa [star_eq_conjTranspose] using (mem_unitaryGroup_iff').mp hUmem + have hzX0 : ε (fun _ => 1) ≠ 0 := by rcases hε (fun _ => 1) with h | h <;> rw [h] <;> norm_num + have hzZ0 : ε (fun _ => 3) ≠ 0 := by rcases hε (fun _ => 3) with h | h <;> rw [h] <;> norm_num + have hbX0 : σ (fun _ => 1) ≠ 0 := + conj_pauliString_index_ne_zero hUHU (hconj (fun _ => 1)) hzX0 (by decide) + have hbZ0 : σ (fun _ => 3) ≠ 0 := + conj_pauliString_index_ne_zero hUHU (hconj (fun _ => 3)) hzZ0 (by decide) + obtain ⟨aX, haX⟩ : ∃ a, σ (fun _ => 1) = fun _ => a := + ⟨σ (fun _ => 1) 0, by funext i; fin_cases i; rfl⟩ + obtain ⟨aZ, haZ⟩ : ∃ a, σ (fun _ => 3) = fun _ => a := + ⟨σ (fun _ => 3) 0, by funext i; fin_cases i; rfl⟩ + have h0X : aX ≠ 0 := by intro h; exact hbX0 (by rw [haX, h]; rfl) + have h0Z : aZ ≠ 0 := by intro h; exact hbZ0 (by rw [haZ, h]; rfl) + have hbne : σ (fun _ => 1) ≠ σ (fun _ => 3) := fun h => + (by decide : (fun _ : Fin 1 => (1 : Fin 4)) ≠ fun _ => 3) (σ.injective h) + have hne : aX ≠ aZ := by intro h; exact hbne (by rw [haX, haZ, h]) + obtain ⟨C, hCaX, hCsX, hCaZ, hCsZ⟩ := + exists_cliffordCircuit_singleQubit_act_sign h0X h0Z hne (hε (fun _ => 1)) (hε (fun _ => 3)) + have hCmem : CliffordCircuit.toMatrix C ∈ Matrix.unitaryGroup (Fin 1 → Fin 2) ℂ := by + rw [mem_unitaryGroup_iff, star_eq_conjTranspose]; exact CliffordCircuit.mul_conjTranspose C + have hXeq : U * pauliString (fun _ => 1) * Uᴴ + = CliffordCircuit.toMatrix C * pauliString (fun _ => 1) * (CliffordCircuit.toMatrix C)ᴴ := by + rw [hconj (fun _ => 1), CliffordCircuit.conj_pauliString, hCsX, hCaX, haX] + have hZeq : U * pauliString (fun _ => 3) * Uᴴ + = CliffordCircuit.toMatrix C * pauliString (fun _ => 3) * (CliffordCircuit.toMatrix C)ᴴ := by + rw [hconj (fun _ => 3), CliffordCircuit.conj_pauliString, hCsZ, hCaZ, haZ] + obtain ⟨c, hc, hUc⟩ := unitary_eq_smul_of_conj_singleQubit_XZ hUmem hCmem hXeq hZeq + exact ⟨C, c, hc, hUc⟩ + +/-! ### A normalizer preserves the commutation (symplectic) structure of the Pauli strings + +The structural invariant driving the multi-qubit inductive synthesis (Nielsen & Chuang Exercise +10.40 parts 2–3): conjugation by a unitary is a `*`-algebra automorphism, hence preserves +commutation and anticommutation. A Pauli normalizer therefore acts on the Pauli strings by a +transformation that respects the **binary symplectic form** (`pauliAnticommCount`, mod 2) of +Exercise 10.33 — its induced `±1`-signed permutation `σ` of the Pauli-string indices is a +*symplectic* permutation. In particular it sends anticommuting Pauli strings to anticommuting ones, +which is precisely how Nielsen & Chuang open part 2: "since `Z₁` and `X₁` anticommute, `U Z₁ U†` and +`U X₁ U†` anticommute". -/ + +/-- **Conjugation by a unitary preserves commutation.** For a unitary `U` and any matrices `P, Q`, +the conjugates `U P U†` and `U Q U†` commute iff `P` and `Q` do. Conjugation `M ↦ U M U†` is the +`*`-algebra automorphism `Unitary.conjStarAlgAut ℂ _ ⟨U, hU⟩` (a `StarAlgEquiv`, so a bijective +ring homomorphism), and commutation is transported along any multiplicative map both ways +(`Commute.map`, using the inverse `f.symm` for the reverse direction). This is the algebraic reason +a Pauli normalizer preserves the commutation structure of `Gₙ`. -/ +theorem unitaryConj_commute_iff {N : Type*} [Fintype N] [DecidableEq N] + {U : Matrix N N ℂ} (hU : U ∈ Matrix.unitaryGroup N ℂ) (P Q : Matrix N N ℂ) : + Commute (U * P * Uᴴ) (U * Q * Uᴴ) ↔ Commute P Q := by + set f := Unitary.conjStarAlgAut ℂ (Matrix N N ℂ) ⟨U, hU⟩ with hf_def + have hf : ∀ M : Matrix N N ℂ, f M = U * M * Uᴴ := fun M => by + rw [hf_def, Unitary.conjStarAlgAut_apply] + simp only [star_eq_conjTranspose, Matrix.mul_assoc] + rw [← hf P, ← hf Q] + exact ⟨fun h => by simpa using h.map (f.symm : _ ≃⋆ₐ[ℂ] _), fun h => h.map f⟩ + +/-- **A Pauli normalizer's signed permutation preserves the binary symplectic form.** Strengthening +`exists_signedPerm`: for `U ∈ N(Gₙ)` the induced permutation `σ` of the Pauli-string indices +preserves the mod-2 symplectic pairing of Nielsen & Chuang Exercise 10.33 — +`Even (pauliAnticommCount (σ a) (σ b)) ↔ Even (pauliAnticommCount a b)` for all `a, b`. Conjugation +by `U` preserves commutation (`unitaryConj_commute_iff`), and `U P_a U† = ε a • P_{σ a}` with +`ε a ∈ {±1}` nonzero, so the ±1 scalars cancel and `P_{σ a}, P_{σ b}` commute iff `P_a, P_b` do; the +symplectic commutation criterion `pauliString_commute_iff` then translates this into the parity +statement. This is the *symplectic-transformation* structure of a normalizer's action — the +invariant that the inductive Clifford synthesis of Exercise 10.40 (parts 2–3) must reproduce, and +the reason a normalizer maps anticommuting generators to anticommuting Pauli strings. -/ +theorem IsPauliNormalizer.exists_signedPerm_symplectic + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ (σ : Equiv.Perm (Fin n → Fin 4)) (ε : (Fin n → Fin 4) → ℂ), + (∀ a, ε a = 1 ∨ ε a = -1) ∧ + (∀ a, U * pauliString a * Uᴴ = ε a • pauliString (σ a)) ∧ + (∀ a b, Even (pauliAnticommCount (σ a) (σ b)) ↔ Even (pauliAnticommCount a b)) := by + obtain ⟨σ, ε, hε, hconj⟩ := hU.exists_signedPerm + refine ⟨σ, ε, hε, hconj, fun a b => ?_⟩ + have hne : ε a * ε b ≠ 0 := + mul_ne_zero (by rcases hε a with h | h <;> rw [h] <;> norm_num) + (by rcases hε b with h | h <;> rw [h] <;> norm_num) + -- conjugation by `U` preserves the commutation of `P_a, P_b`; the `±1` scalars cancel + have hstep : Commute (U * pauliString a * Uᴴ) (U * pauliString b * Uᴴ) + ↔ Commute (pauliString (σ a)) (pauliString (σ b)) := by + rw [hconj a, hconj b] + constructor + · intro h + have he := h.eq + rw [smul_mul_smul_comm, smul_mul_smul_comm, mul_comm (ε b) (ε a)] at he + exact smul_right_injective _ hne he + · intro h + exact (h.smul_left (ε a)).smul_right (ε b) + have hcomm : Commute (pauliString (σ a)) (pauliString (σ b)) + ↔ Commute (pauliString a) (pauliString b) := + hstep.symm.trans (unitaryConj_commute_iff hU.1 (pauliString a) (pauliString b)) + rw [pauliString_commute_iff, pauliString_commute_iff] at hcomm + exact hcomm + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerCnotClear.lean b/LeanPool/AxQM/Concrete/PauliNormalizerCnotClear.lean new file mode 100644 index 0000000000..8e1c495cea --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerCnotClear.lean @@ -0,0 +1,189 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerLayer + +/-! +# Concrete: CNOT clearing — collapse an all-`X` Pauli string to a single `X` generator + +This file continues the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The Gottesman tableau sweep synthesising a Clifford circuit for a normalizer's signed permutation +proceeds, on the first generator's image `U X₁ U†`, in two moves: + +1. **Diagonalise to all-`X`** (`exists_singleQubitLayer_act_diagX`): a single-qubit + layer rotates the image to a string carrying `X` on its support and `I` elsewhere. +2. **Collapse to a single generator** (*this file*): a **fan of CNOTs** from one support wire + `c` clears the `X` off every other support wire, leaving `X` on wire `c` alone (`xGenPauli c`). + +The clearing move is the *inverse reading* of the CNOT `X`-spread of Problem 10.3 +(`act_cnotFan_xGenPauli`): a single `CNOT_{c→t}` with `X` on both control and target sends +`X_c X_t ↦ X_c` (the target's `X` is copied onto the — already `X` — control, cancelling `mod 2`; +`x_t += x_c`, Figure 10.7), so a fan controlled on `c` and targeting the other support wires +collapses an all-`X` string to `X_c`. We reuse the existing `cnotFan` combinator and its cons law +`act_cnotFan_cons_of_ne` rather than reconstructing the circuit. + +Every statement is about raw matrix / index data (`Concrete.CliffordCircuit`, +`Concrete.pauliString` indices `Fin n → Fin 4`, `Concrete.xGenPauli`). + +## What is proved + +* `act_cnotFan_collapse` — **the clearing action.** For an all-`X` string `a` with pivot `c` + (`a c = 1`) and distinct target wires `ts` (`c ∉ ts`, `ts.Nodup`) all in `a`'s support + (`∀ t ∈ ts, a t = 1`), the fan `cnotFan c ts` sends `a` to `X` on `c`, `I` on each target, and + `a` unchanged elsewhere + (`act (cnotFan c ts) a k = if k = c then 1 else if k ∈ ts then 0 else a k`). + The control wire keeps its `X` throughout (`cnotCtrlPauli 1 1 = 1`) and each target's `X` is + cleared (`cnotTgtPauli 1 1 = 0`); an induction on `ts` on top of `act_cnotFan_cons_of_ne`. + +* `sign_cnotStep_of_ne` — the `±1` phase of one CNOT step `CNOT_{c→t}` (`c ≠ t`) is + `cnotPauliSign (g c) (g t)`. + +* `sign_cnotFan_collapse` — **the clearing introduces no sign.** Under the same hypotheses, + `sign (cnotFan c ts) a = 1`: every step conjugates an `(X_c, X_t)` pair, whose tableau sign is + `cnotPauliSign 1 1 = 1`. + +* `exists_cliffordCircuit_cnotClear_toSingleX` — **sweep step 2.** For any all-`X` + string `a` (`∀ k, a k = 0 ∨ a k = 1`) with a pivot `c` in its support (`a c = 1`), there is a + Clifford circuit realising `a ↦ xGenPauli c` exactly, with phase `1`. Taking the targets to be + the support minus `c` (a `Finset.filter … |>.toList`), the fan clears every other `X`. This + reduces a diagonalised generator image `U X₁ U†` to the standard `X₁`, the second move of the + Exercise 10.40 inductive synthesis. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Collapsing an all-`X` string with a CNOT fan -/ + +/-- **A CNOT fan collapses an all-`X` string to its pivot.** For a string `a` with `X` (letter `1`) +on wire `c` and on every wire of a distinct list `ts` (`c ∉ ts`, `ts.Nodup`, `∀ t ∈ ts, a t = 1`), +the fan `cnotFan c ts` (control `c`, targets `ts`) transforms `a` to: +`act (cnotFan c ts) a k = if k = c then 1 else if k ∈ ts then 0 else a k` — `X` kept on the control +`c`, `I` on every target, and every other wire unchanged. + +This is the *inverse reading* of the `X`-spread `act_cnotFan_xGenPauli`: `CNOT_{c→t}` copies the +control's `X` onto the target (`x_t += x_c`, Figure 10.7), so a target that already carries an `X` +is cleared (`cnotTgtPauli 1 1 = 0`) while the control keeps its `X` (`cnotCtrlPauli 1 1 = 1`). +Proved by induction on `ts` via `act_cnotFan_cons_of_ne`: the tail collapses all but the head +target, whose `X` the head `CNOT_{c→t}` then clears. -/ +theorem act_cnotFan_collapse (c : Fin n) : + ∀ (ts : List (Fin n)), c ∉ ts → ts.Nodup → ∀ (a : Fin n → Fin 4), a c = 1 → + (∀ t ∈ ts, a t = 1) → ∀ k, + CliffordCircuit.act (cnotFan c ts) a k = if k = c then 1 else if k ∈ ts then 0 else a k + | [], _, _, a, hac, _, k => by + simp only [cnotFan_nil, CliffordCircuit.act, List.not_mem_nil, ite_false] + rcases eq_or_ne k c with rfl | hk + · rw [ite_eq_left rfl]; exact hac + · rw [ite_eq_right hk] + | t :: ts, hct, hnd, a, hac, hall, k => by + rw [List.mem_cons, not_or] at hct + obtain ⟨hct_t, hct_ts⟩ := hct + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + have hit : c ≠ t := hct_t + have hall' : ∀ t' ∈ ts, a t' = 1 := fun t' ht' => hall t' (List.mem_cons_of_mem t ht') + have hIH := act_cnotFan_collapse c ts hct_ts hnd' a hac hall' + have hac' : CliffordCircuit.act (cnotFan c ts) a c = 1 := by rw [hIH c]; simp + have hat' : CliffordCircuit.act (cnotFan c ts) a t = 1 := by + rw [hIH t, ite_eq_right (Ne.symm hit), ite_eq_right htnotin] + exact hall t List.mem_cons_self + rw [act_cnotFan_cons_of_ne hit ts a] + rcases eq_or_ne k c with rfl | hkc + · rw [cnotPauliString_ctrl, hac', hat', ite_eq_left rfl]; decide + · rcases eq_or_ne k t with rfl | hkt + · rw [cnotPauliString_tgt _ hit, hac', hat', ite_eq_right hkc, + ite_eq_left List.mem_cons_self] + decide + · rw [cnotPauliString_of_ne _ c t hkc hkt, hIH k] + have hmem2 : (k ∈ t :: ts) ↔ (k ∈ ts) := by simp [List.mem_cons, hkt] + simp only [hmem2] + +/-- **The `±1` phase of a single CNOT step.** For `c ≠ t`, `sign (cnotStep c t) g` is the CNOT +tableau sign `cnotPauliSign (g c) (g t)` (`cnotStep c t = [CNOT_{c→t}]`, and a one-gate circuit's +sign is the gate's). -/ +theorem sign_cnotStep_of_ne {c t : Fin n} (hct : c ≠ t) (g : Fin n → Fin 4) : + CliffordCircuit.sign (cnotStep c t) g = cnotPauliSign (g c) (g t) := by + rw [cnotStep, dite_eq_right hct] + simp [CliffordCircuit.sign, CliffordGate.sign, CliffordCircuit.act] + +/-- **The CNOT clearing introduces no sign.** Under the hypotheses of `act_cnotFan_collapse`, +`sign (cnotFan c ts) a = 1`: each `CNOT_{c→t}` in the fan conjugates a pair `(X_c, X_t)` (control +and current target both `X`, by the collapse action of the tail), whose CNOT tableau sign is +`cnotPauliSign 1 1 = 1`. Proved by induction on `ts` via `sign_append` and the tail's `act` values +from `act_cnotFan_collapse`. -/ +theorem sign_cnotFan_collapse (c : Fin n) : + ∀ (ts : List (Fin n)), c ∉ ts → ts.Nodup → ∀ (a : Fin n → Fin 4), a c = 1 → + (∀ t ∈ ts, a t = 1) → CliffordCircuit.sign (cnotFan c ts) a = 1 + | [], _, _, _, _, _ => by simp [cnotFan_nil, CliffordCircuit.sign] + | t :: ts, hct, hnd, a, hac, hall => by + rw [List.mem_cons, not_or] at hct + obtain ⟨hct_t, hct_ts⟩ := hct + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + have hit : c ≠ t := hct_t + have hall' : ∀ t' ∈ ts, a t' = 1 := fun t' ht' => hall t' (List.mem_cons_of_mem t ht') + have hac' : CliffordCircuit.act (cnotFan c ts) a c = 1 := by + rw [act_cnotFan_collapse c ts hct_ts hnd' a hac hall' c]; simp + have hat' : CliffordCircuit.act (cnotFan c ts) a t = 1 := by + rw [act_cnotFan_collapse c ts hct_ts hnd' a hac hall' t, ite_eq_right (Ne.symm hit), + ite_eq_right htnotin] + exact hall t List.mem_cons_self + rw [cnotFan_cons, CliffordCircuit.sign_append, + sign_cnotFan_collapse c ts hct_ts hnd' a hac hall', one_mul, + sign_cnotStep_of_ne hit, hac', hat'] + rfl + +/-! ### Sweep step 2: collapse an all-`X` image to a single `X` generator -/ + +/-- **CNOT clearing (N&C Exercise 10.40 sweep step 2).** For any all-`X` Pauli string `a` +(`∀ k, a k = 0 ∨ a k = 1`) with a pivot wire `c` in its support (`a c = 1`), there is a Clifford +circuit `C` collapsing `a` to the single `X` generator on wire `c` exactly, with phase `1`: +`act C a = xGenPauli c` and `sign C a = 1`. + +The witness is the CNOT fan `cnotFan c ts` controlled on `c` with targets the rest of `a`'s support +`ts = {k | a k = 1, k ≠ c}` (as a `Finset.filter … |>.toList`, so `Nodup` and `c ∉ ts`); +`act_cnotFan_collapse` clears every target's `X`, and `sign_cnotFan_collapse` gives the trivial +phase. Together with the diagonalisation step (`exists_singleQubitLayer_act_diagX`), this +reduces a normalizer's diagonalised generator image `U X₁ U†` to the standard `X₁` — the second +move of the multi-qubit inductive synthesis of Theorem 10.6. -/ +theorem exists_cliffordCircuit_cnotClear_toSingleX (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 1) (hX : ∀ k, a k = 0 ∨ a k = 1) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = xGenPauli c ∧ CliffordCircuit.sign C a = 1 := by + set ts := (Finset.univ.filter (fun k => a k = 1 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 1 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 1 := fun t ht => ((hmem t).mp ht).1 + refine ⟨cnotFan c ts, ?_, sign_cnotFan_collapse c ts hcnotin hnd a hc hall⟩ + funext k + rw [act_cnotFan_collapse c ts hcnotin hnd a hc hall k, xGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk1 : a k = 1 + · rw [ite_eq_left ((hmem k).mpr ⟨hk1, hkc⟩)] + · rw [ite_eq_right (fun h => hk1 ((hmem k).mp h).1)] + exact (hX k).resolve_right hk1 + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerDecouple.lean b/LeanPool/AxQM/Concrete/PauliNormalizerDecouple.lean new file mode 100644 index 0000000000..312391082e --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerDecouple.lean @@ -0,0 +1,149 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerFirstPair + +/-! +# Concrete: pivot-wire decoupling of a Pauli normalizer (Figure 10.9, part 2) + +This file continues the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3, +Figure 10.9). + +After the first-wire reduction (`IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair`), the +composite `M := B U` is again a Pauli normalizer that **fixes the first-wire generators** +`X₀` and `Z₀` exactly under conjugation. The inductive step now needs to *decouple* wire `0`: to +recurse onto the last `n` wires, one must know that `M` maps every generator supported away from +wire `0` back to a Pauli again trivial on wire `0`. This file proves exactly that decoupling. + +The mechanism is the symplectic (commutation) structure of Exercise 10.33. A Pauli string `a` that +is the identity on wire `0` commutes with both `X₀` and `Z₀`; conjugation by a unitary preserves +commutation (`unitaryConj_commute_iff`); and `M` fixes `X₀, Z₀`; so the (signed) image +`M P_a M† = z • P_b` again commutes with `X₀` and `Z₀`. Finally, the only single-qubit Pauli +commuting with both `X` and `Z` is the identity, so `b` is the identity letter on wire `0`. + +Everything is about raw matrix / index data (`Matrix`, `Concrete.pauliString`, +`Concrete.xGenPauli`/`zGenPauli`, `Concrete.IsPauliNormalizer`). + +## What is proved + +* `pauliString_index_eq_zero_of_commute_gen` — **a Pauli string commuting with both `X_c` and `Z_c` + is the identity on wire `c`.** The single-qubit fact that only `I` commutes with both `X` and `Z`, + read off the symplectic criterion (Exercise 10.33): commuting with `X_c` forces `b c ∉ {Y, Z}` and + commuting with `Z_c` forces `b c ∉ {X, Y}`, leaving `b c = I`. + +* `IsPauliNormalizer.conj_apply_zero_eq_zero` — **wire-`0` decoupling.** A Pauli normalizer `M` that + fixes `X₀` and `Z₀` under conjugation sends every Pauli string trivial on wire `0` (`a 0 = 0`) to + a signed Pauli string `z • P_b` (`z = ±1`) that is again trivial on wire `0` (`b 0 = 0`). This is + Figure 10.9, part 2: after `M` fixes the first-wire generators, the remaining generators + `Xᵢ, Zᵢ` (`i ≠ 0`) — each identity on wire `0` — are mapped to Paulis supported on the last `n` + wires, so `M`'s action restricts to an `n`-qubit normalizer on the sub-register `{1, …, n}` (the + inductive hypothesis of `isPauliNormalizer_eq_smul_cliffordCircuit`). + +* `IsPauliNormalizer.exists_conj_xGenPauli_supportedOffZero` / + `…_exists_conj_zGenPauli_supportedOffZero` — **the generator specialisation.** The decoupling read + directly off the remaining generators: for `i ≠ 0`, `M Xᵢ M†` and `M Zᵢ M†` are `±1` multiples of + Pauli strings supported on the last `n` wires (`b 0 = 0`). This is the exact form the multi-qubit + inductive step consumes as an `n`-qubit normalizer's generator action. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **Only the identity commutes with both `X_c` and `Z_c`.** A Pauli string index `b` whose Pauli +`pauliString b` commutes with both standard generators `X_c` and `Z_c` has the identity letter on +wire `c` (`b c = 0`). Reading the symplectic commutation criterion (`pauliString_commute_iff`, +Exercise 10.33): commuting with `X_c` means `Even (pauliAnticommCount b (xGenPauli c))`, i.e. +`b c ∉ {Y, Z}` (`odd_pauliAnticommCount_xGenPauli_iff`); commuting with `Z_c` means `b c ∉ {X, Y}` +(`odd_pauliAnticommCount_zGenPauli_iff`); together these leave only `b c = I`. -/ +theorem pauliString_index_eq_zero_of_commute_gen (b : Fin n → Fin 4) (c : Fin n) + (hx : Commute (pauliString b) (pauliString (xGenPauli c))) + (hz : Commute (pauliString b) (pauliString (zGenPauli c))) : b c = 0 := by + rw [pauliString_commute_iff] at hx hz + have hxx : ¬ (b c = 2 ∨ b c = 3) := fun h => + (Nat.not_even_iff_odd.mpr ((odd_pauliAnticommCount_xGenPauli_iff b c).mpr h)) hx + have hzz : ¬ (b c = 1 ∨ b c = 2) := fun h => + (Nat.not_even_iff_odd.mpr ((odd_pauliAnticommCount_zGenPauli_iff b c).mpr h)) hz + omega + +/-- **Pivot-wire decoupling (Nielsen & Chuang Exercise 10.40, Figure 10.9, part 2).** Let `M` be an +`(n+1)`-qubit Pauli normalizer that **fixes the first-wire generators** `X₀` and `Z₀` under +conjugation (the output of the first-wire reduction). Then `M` maps every Pauli string trivial on +wire `0` to a signed Pauli again trivial on wire `0`: for `a` with `a 0 = 0` there are an index `b` +and a sign `z ∈ {1, -1}` with `M P_a M† = z • P_b` and `b 0 = 0`. + +Since `a` is the identity on wire `0`, it commutes with both `X₀` and `Z₀` +(`pauliAnticommCount_xGenPauli`/`…_zGenPauli` vanish at `a 0 = I`). Conjugation by the unitary `M` +preserves commutation (`unitaryConj_commute_iff`) and `M` fixes `X₀, Z₀`, so the image `z • P_b` +commutes with `X₀` and `Z₀`; stripping the nonzero sign (`Commute.smul_left_iff₀`), `P_b` does too, +whence `b 0 = 0` (`pauliString_index_eq_zero_of_commute_gen`). + +Applied to the generators `Xᵢ, Zᵢ` (`i ≠ 0`, each identity on wire `0`), this forces their images +onto the last `n` wires — the decoupling that lets the multi-qubit induction recurse onto the +sub-register `{1, …, n}`. -/ +theorem IsPauliNormalizer.conj_apply_zero_eq_zero + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) + {a : Fin (n + 1) → Fin 4} (ha : a 0 = 0) : + ∃ b, ∃ z : ℂ, (z = 1 ∨ z = -1) ∧ M * pauliString a * Mᴴ = z • pauliString b ∧ b 0 = 0 := by + obtain ⟨b, z, hz, hconj⟩ := hM.exists_sign_conj_pauliString a + refine ⟨b, z, hz, hconj, ?_⟩ + have hz0 : z ≠ 0 := by rcases hz with h | h <;> rw [h] <;> norm_num + -- transport commutation with a fixed generator through conjugation by `M`. + have transport : ∀ g : Fin (n + 1) → Fin 4, + M * pauliString g * Mᴴ = pauliString g → + Commute (pauliString a) (pauliString g) → Commute (pauliString b) (pauliString g) := by + intro g hg hag + have h := (unitaryConj_commute_iff hM.1 (pauliString a) (pauliString g)).mpr hag + rw [hconj, hg] at h + exact (Commute.smul_left_iff₀ hz0).mp h + -- `a` is the identity letter on wire `0`, hence commutes with `X₀` and `Z₀`. + refine pauliString_index_eq_zero_of_commute_gen b 0 (transport _ hX ?_) (transport _ hZ ?_) + · rw [pauliString_commute_iff, pauliAnticommCount_xGenPauli, ha]; decide + · rw [pauliString_commute_iff, pauliAnticommCount_zGenPauli, ha]; decide + +/-- **Decoupling of a remaining `X` generator.** For a normalizer `M` fixing `X₀, Z₀` under +conjugation and a wire `i ≠ 0`, the image `M Xᵢ M† = z • P_b` (`z = ±1`) has `b` supported off wire +`0` (`b 0 = 0`) — i.e. `Xᵢ` maps to a Pauli string on the last `n` wires. The generator +specialisation of `conj_apply_zero_eq_zero` (via `xGenPauli i 0 = 0` for `i ≠ 0`), the form the +inductive step of Exercise 10.40 consumes. -/ +theorem IsPauliNormalizer.exists_conj_xGenPauli_supportedOffZero + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) + {i : Fin (n + 1)} (hi : i ≠ 0) : + ∃ b, ∃ z : ℂ, (z = 1 ∨ z = -1) ∧ + M * pauliString (xGenPauli i) * Mᴴ = z • pauliString b ∧ b 0 = 0 := + hM.conj_apply_zero_eq_zero hX hZ (by rw [xGenPauli_apply, ite_eq_right hi.symm]) + +/-- **Decoupling of a remaining `Z` generator.** The `Z`-basis mirror of +`exists_conj_xGenPauli_supportedOffZero`: for a normalizer `M` fixing `X₀, Z₀` and a wire `i ≠ 0`, +the image `M Zᵢ M† = z • P_b` (`z = ±1`) has `b 0 = 0`. -/ +theorem IsPauliNormalizer.exists_conj_zGenPauli_supportedOffZero + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) + {i : Fin (n + 1)} (hi : i ≠ 0) : + ∃ b, ∃ z : ℂ, (z = 1 ∨ z = -1) ∧ + M * pauliString (zGenPauli i) * Mᴴ = z • pauliString b ∧ b 0 = 0 := + hM.conj_apply_zero_eq_zero hX hZ (by rw [zGenPauli_apply, ite_eq_right hi.symm]) + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerFirstPair.lean b/LeanPool/AxQM/Concrete/PauliNormalizerFirstPair.lean new file mode 100644 index 0000000000..44aae226e2 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerFirstPair.lean @@ -0,0 +1,188 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerPairReduce +public import LeanPool.AxQM.Concrete.PauliNormalizerSwap + +/-! +# Concrete: the first-wire reduction of a Pauli normalizer (Figure 10.9 setup) + +This file continues the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3, +Figure 10.9). + +The inductive step of Exercise 10.40 reduces an `(n+1)`-qubit normalizer to an `n`-qubit one by +**decoupling the first wire**: one composes `U` on the left with a Clifford circuit so that the +composite fixes the first-wire generators `X₀` and `Z₀` under conjugation, after which +the remaining generators are forced to be supported on the last `n` wires and the inductive +hypothesis applies. This file builds that composite from the following pieces: + +* `exists_cliffordCircuit_reducePair` — reduce the anticommuting image pair + `(U X₀ U†, U Z₀ U†)` to the canonical `(X_c, Z_c)` on some pivot wire `c`, exactly (`±1` phases + pinned to `+1`); +* `swapWires` — swap the pivot wire `c` to the designated first wire `0`; +* `exists_cliffordCircuit_onWire_act_sign` — a single-wire sign gadget on wire `0` correcting + the two residual `±1` phases `ε(X₀), ε(Z₀)` the normalizer contributes. + +Everything is about raw matrix / index data (`Matrix`, `Concrete.pauliString`, +`Concrete.xGenPauli`/`zGenPauli`, `Concrete.CliffordCircuit`, `Concrete.IsPauliNormalizer`). + +## What is proved + +* `IsPauliNormalizer.mul` — **the normalizer `N(Gₙ)` is closed under matrix multiplication.** If `A` + and `B` are Pauli normalizers then so is `A * B`: the product is unitary (submonoid closure) and + conjugation composes — `(A B) p (A B)† = A (B p B†) A† ∈ Gₙ`. This is what makes the composite + `B.toMatrix * U` of the reduction below itself a normalizer, so the induction can recurse on it. + +* `IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair` — **the first-wire reduction.** For any + `(n+1)`-qubit Pauli normalizer `U`, there is a Clifford circuit `B` such that `B.toMatrix * U` is + again a normalizer and **fixes the first-wire generators exactly**: + + * `(B U) P_{X₀} (B U)† = P_{X₀}` and `(B U) P_{Z₀} (B U)† = P_{Z₀}`. + + Construction. From `IsPauliNormalizer.exists_signedPerm_symplectic`, `U P_a U† = ε a • P_{σ a}` + with `σ` symplectic; since `X₀` and `Z₀` anticommute and `σ` preserves the mod-2 symplectic form, + their images `p = σ X₀`, `q = σ Z₀` anticommute. `exists_cliffordCircuit_reducePair` gives a + Clifford `E` and pivot `c` reducing `(p, q)` to `(X_c, Z_c)` exactly; `swapWires c 0` prepended to + `E` relocates the pivot to wire `0` (phase-free), so `A := swapWires c 0 ++ E` maps `p ↦ X₀`, + `q ↦ Z₀` with `+1` phase. Then `A.toMatrix * U` fixes `X₀, Z₀` up to the residual signs + `ε(X₀), ε(Z₀)`, which a single-wire sign gadget `G` on wire `0` cancels (each sign squares to + `1`). `B := G ++ A`. + + This is the setup of Figure 10.9 — the first move of the `n+1` inductive step, after + which the decoupling of the remaining generators reduces the problem to `n` wires. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The normalizer is closed under multiplication -/ + +/-- **The Pauli normalizer `N(Gₙ)` is closed under matrix multiplication.** If `A` and `B` are Pauli +normalizers then `A * B` is: the product of two unitaries is unitary (submonoid closure of +`Matrix.unitaryGroup`), and conjugation composes — for a group element `p`, `B p B† = q ∈ Gₙ` +(`B` normalizer) and then `A q A† = r ∈ Gₙ` (`A` normalizer), so `(A B) p (A B)† = r ∈ Gₙ`. This +lets the inductive synthesis of Nielsen & Chuang Exercise 10.40 recurse on the composite +`B.toMatrix * U` +of a Clifford reduction circuit and a normalizer. -/ +theorem IsPauliNormalizer.mul {A B : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hA : IsPauliNormalizer A) (hB : IsPauliNormalizer B) : IsPauliNormalizer (A * B) := by + refine ⟨mul_mem hA.1 hB.1, fun p => ?_⟩ + obtain ⟨q, hq⟩ := hB.2 p + obtain ⟨r, hr⟩ := hA.2 q + refine ⟨r, ?_⟩ + rw [conjTranspose_mul] + calc A * B * p.toMat * (Bᴴ * Aᴴ) + = A * (B * p.toMat * Bᴴ) * Aᴴ := by simp only [Matrix.mul_assoc] + _ = A * q.toMat * Aᴴ := by rw [hq] + _ = r.toMat := hr + +/-! ### Conjugation plumbing -/ + +/-- Split a conjugation by a product: `(X Y) P (X Y)† = X (Y P Y†) X†`. Pure matrix associativity +(`conjTranspose_mul` + `mul_assoc`); lets the composite `B.toMatrix * U` be peeled one factor at a +time. Reused by the gate-count companion `exists_cliffordCircuit_fixFirstPair_length_le`. -/ +theorem conj_split {N : Type*} [Fintype N] + (X Y P : Matrix N N ℂ) : (X * Y) * P * (X * Y)ᴴ = X * (Y * P * Yᴴ) * Xᴴ := by + rw [Matrix.conjTranspose_mul]; simp only [Matrix.mul_assoc] + +/-- Conjugating a scaled Pauli string by a Clifford circuit: +`C (z • P_a) C† = z • (sign • P_{act})`, folding `CliffordCircuit.conj_pauliString` through the +scalar. Reused by the gate-count companion `exists_cliffordCircuit_fixFirstPair_length_le`. -/ +theorem conj_circuit_smul {m : ℕ} (C : CliffordCircuit m) (z : ℂ) (a : Fin m → Fin 4) : + C.toMatrix * (z • pauliString a) * C.toMatrixᴴ + = z • (C.sign a • pauliString (C.act a)) := by + rw [mul_smul_comm, smul_mul_assoc, CliffordCircuit.conj_pauliString] + +/-- The core of the first-wire reduction, applied once for `X₀` and once for `Z₀`. Given a Clifford +circuit `A` reducing the normalizer's generator image `imag` to the generator `gen` exactly +(`A.act imag = gen`, `A.sign imag = 1`), a single-wire sign gadget `G` fixing `gen` with sign `z` +(`G.act gen = gen`, `G.sign gen = z`), the normalizer's conjugation `U P_gen U† = z • P_imag`, and +`z² = 1`, the composite `(G ++ A).toMatrix * U` fixes `gen` under conjugation. The two `z` factors +(one from the normalizer, one from `G`) multiply to `z² = 1`. Reused verbatim by the gate-count +companion `exists_cliffordCircuit_fixFirstPair_length_le`, whose reconstructed `B` fixes `X₀, Z₀` +by the same identity. -/ +theorem normalizer_first_fix + (G A : CliffordCircuit (n + 1)) (U : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ) + (gen imag : Fin (n + 1) → Fin 4) (z : ℂ) (hz : z * z = 1) + (hUconj : U * pauliString gen * Uᴴ = z • pauliString imag) + (hAact : A.act imag = gen) (hAsign : A.sign imag = 1) + (hGact : G.act gen = gen) (hGsign : G.sign gen = z) : + ((G ++ A).toMatrix * U) * pauliString gen * ((G ++ A).toMatrix * U)ᴴ = pauliString gen := by + rw [CliffordCircuit.toMatrix_append, Matrix.mul_assoc G.toMatrix A.toMatrix U, + conj_split, conj_split, hUconj, conj_circuit_smul, hAsign, one_smul, hAact, + conj_circuit_smul, hGsign, hGact, smul_smul, hz, one_smul] + +/-! ### The first-wire reduction -/ + +/-- **The first-wire reduction of a Pauli normalizer (Nielsen & Chuang Exercise 10.40, Figure 10.9 +setup).** For any `(n+1)`-qubit Pauli normalizer `U`, there is a Clifford circuit `B` such that +`B.toMatrix * U` is again a Pauli normalizer and **fixes the first-wire generators exactly** under +conjugation: + +* `(B U) P_{X₀} (B U)† = P_{X₀}` and `(B U) P_{Z₀} (B U)† = P_{Z₀}`. + +The images `p = σ X₀`, `q = σ Z₀` of the first-wire generators under the normalizer's signed +permutation `σ` anticommute (`X₀`, `Z₀` anticommute and `σ` preserves the mod-2 symplectic form, +`exists_signedPerm_symplectic`), so `exists_cliffordCircuit_reducePair` reduces the pair to +`(X_c, Z_c)` on a pivot wire `c` exactly; `swapWires c 0` relocates the pivot to wire `0`. The +composite then fixes `X₀, Z₀` up to the residual `±1` signs `ε(X₀), ε(Z₀)`, cancelled by a +single-wire sign gadget on wire `0` (`exists_cliffordCircuit_onWire_act_sign`, each sign squaring to +`1`). This is the first move of the multi-qubit induction: after it, the remaining generators are +supported on the last `n` wires and the inductive hypothesis applies. -/ +theorem IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair + {U : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ B : CliffordCircuit (n + 1), + IsPauliNormalizer (B.toMatrix * U) ∧ + ((B.toMatrix * U) * pauliString (xGenPauli 0) * (B.toMatrix * U)ᴴ + = pauliString (xGenPauli 0)) ∧ + (B.toMatrix * U) * pauliString (zGenPauli 0) * (B.toMatrix * U)ᴴ + = pauliString (zGenPauli 0) := by + obtain ⟨σ, ε, hε, hconj, hsymp⟩ := hU.exists_signedPerm_symplectic + -- `X₀` and `Z₀` anticommute, hence so do their images `p = σ X₀`, `q = σ Z₀`. + have hXZ : Odd (pauliAnticommCount (xGenPauli (0 : Fin (n + 1))) (zGenPauli 0)) := by + rw [odd_pauliAnticommCount_zGenPauli_iff]; left; simp [xGenPauli] + have hpq : Odd (pauliAnticommCount (σ (xGenPauli 0)) (σ (zGenPauli 0))) := by + rw [← Nat.not_even_iff_odd]; rw [← Nat.not_even_iff_odd] at hXZ + exact fun h => hXZ ((hsymp (xGenPauli 0) (zGenPauli 0)).mp h) + -- Reduce the pair `(p, q)` to `(X_c, Z_c)`, then swap the pivot `c` to wire `0`. + obtain ⟨E, c, hEp, hEsp, hEq, hEsq⟩ := + exists_cliffordCircuit_reducePair (σ (xGenPauli 0)) (σ (zGenPauli 0)) hpq + set A := swapWires c 0 ++ E with hA + have hAp : A.act (σ (xGenPauli 0)) = xGenPauli 0 := by + rw [hA, CliffordCircuit.act_append, hEp, act_swapWires_xGenPauli] + have hAq : A.act (σ (zGenPauli 0)) = zGenPauli 0 := by + rw [hA, CliffordCircuit.act_append, hEq, act_swapWires_zGenPauli] + have hAsp : A.sign (σ (xGenPauli 0)) = 1 := by + rw [hA, CliffordCircuit.sign_append, hEsp, sign_swapWires, mul_one] + have hAsq : A.sign (σ (zGenPauli 0)) = 1 := by + rw [hA, CliffordCircuit.sign_append, hEsq, sign_swapWires, mul_one] + -- A single-wire sign gadget on wire `0` correcting the residual signs `ε(X₀), ε(Z₀)`. + obtain ⟨G, hGaX, hGsX, hGaZ, hGsZ, -⟩ := + exists_cliffordCircuit_onWire_act_sign (0 : Fin (n + 1)) (aX := 1) (aZ := 3) + (by decide) (by decide) (by decide) (hε (xGenPauli 0)) (hε (zGenPauli 0)) + have hsq : ∀ a, ε a * ε a = 1 := fun a => by rcases hε a with h | h <;> rw [h] <;> ring + refine ⟨G ++ A, (cliffordCircuit_isPauliNormalizer (G ++ A)).mul hU, ?_, ?_⟩ + · exact normalizer_first_fix G A U (xGenPauli 0) (σ (xGenPauli 0)) (ε (xGenPauli 0)) + (hsq (xGenPauli 0)) (hconj (xGenPauli 0)) hAp hAsp hGaX hGsX + · exact normalizer_first_fix G A U (zGenPauli 0) (σ (zGenPauli 0)) (ε (zGenPauli 0)) + (hsq (zGenPauli 0)) (hconj (zGenPauli 0)) hAq hAsq hGaZ hGsZ + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCount.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCount.lean new file mode 100644 index 0000000000..0c0cd1ab01 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCount.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerInduction + +/-! +# Concrete: gate-count (circuit-length) foundation for Nielsen & Chuang Theorem 10.6 + +*(Theorem 10.6, N&C §10.5.2, p. 461.)* + +Nielsen & Chuang **Theorem 10.6** asserts that a Pauli normalizer `U ∈ N(Gₙ)` may be composed, up to +a global phase, from **`O(n²)`** Hadamard/phase/CNOT gates. The structural converse — that *some* +Clifford circuit realises `U` up to a global phase — is +`isPauliNormalizer_eq_smul_cliffordCircuit`; the quantitative part of the boxed theorem is the +**`O(n²)` gate-count** bound. + +A `CliffordCircuit n` is a `List (CliffordGate n)`, so *its gate count is its `List.length`*. This +file collects the **length arithmetic of the circuit-building blocks** of the Figure 10.9 inductive +synthesis; these bounds compose to bound the synthesised circuit's length. + +Contents: + +* `CliffordCircuit.length_relabel`, `CliffordCircuit.length_onWire` — wire relabeling preserves the + gate count (it is `List.map`). +* `CliffordCircuit.length_layerOn_le`, `CliffordCircuit.length_singleQubitLayer_le` — a single-qubit + layer costs at most `n · m₀` gates when each per-wire word has `≤ m₀` gates (one bounded word on + each of the `n` wires). +* `CliffordCircuit.length_rotateToX_le`, `…_rotateToZ_le`, `…_rotateToZFixingX_le` — the single-wire + rotation words are bounded by a *constant* (`≤ 1`, `≤ 2`, `≤ 3` gates), the `m₀` a layer plugs in. +* `length_cnotStep_le`, `length_cnotFan_le`, `length_cnotFanInto_le` — a CNOT fan costs at most one + gate per target (`≤ |ts|`). +* `length_swapWires_le` — a wire swap costs at most `3` gates (the three-CNOT `SWAP`). +* `CliffordGate.length_invList_le`, `CliffordCircuit.length_inverse_le` — inverting a circuit at + most *triples* its gate count (`S⁻¹ = S³` is the longest per-gate inverse word). +* `CliffordCircuit.length_inverse_append_relabel_le` — the per-level overhead of the Figure 10.9 + recurrence `C_{n+1} = inverse B ++ relabel C'`: at most `3·|B| + |C'|` gates. With a linear bound + `|B| ≤ O(n)` on the per-level first-wire-reduction circuit + (`AxQM/Concrete/PauliNormalizerGateCountFirstPair.lean`), this recurrence unrolls to the `O(n²)` + total gate count of Theorem 10.6. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {m n : ℕ} + +/-- **A gate's inverse word has at most `3` gates**: `(γ.invList).length ≤ 3`. The Hadamard and CNOT +gates are self-inverse (`[H]`, `[CNOT]`, one gate each); the phase gate needs `S⁻¹ = S³` +(`[S, S, S]`, three gates), which is the longest inverse word. -/ +theorem CliffordGate.length_invList_le (γ : CliffordGate n) : γ.invList.length ≤ 3 := by + cases γ <;> simp [CliffordGate.invList] + +namespace CliffordCircuit + +/-! ### Relabeling and single-wire placement preserve the gate count -/ + +/-- **Wire relabeling preserves the gate count**: `(C.relabel f).length = C.length`. Relabeling is +`List.map (CliffordGate.relabel f)`, which keeps the list length. -/ +theorem length_relabel (f : Fin m ↪ Fin n) (C : CliffordCircuit m) : + (C.relabel f).length = C.length := by + simp [relabel] + +/-- **Running a single-wire circuit on one wire preserves the gate count**: +`(onWire j C₀).length = C₀.length`. `onWire j` is the relabeling along the wire-`j` embedding. -/ +theorem length_onWire (j : Fin n) (C₀ : CliffordCircuit 1) : + (onWire j C₀).length = C₀.length := by + rw [onWire, length_relabel] + +/-! ### The single-qubit layer costs one bounded word per wire -/ + +/-- **A per-wire layer over a wire list costs at most one bounded word per wire**: if every +single-wire word `f i` has at most `m₀` gates, then `layerOn f L` has at most `|L| · m₀` gates. +Induction on `L`; each `onWire i (f i)` factor contributes `(f i).length ≤ m₀` +(`length_onWire`, `hf`). -/ +theorem length_layerOn_le (f : Fin n → CliffordCircuit 1) {m₀ : ℕ} + (hf : ∀ i, (f i).length ≤ m₀) (L : List (Fin n)) : + (layerOn f L).length ≤ L.length * m₀ := by + induction L with + | nil => simp + | cons i L ih => + rw [layerOn_cons, List.length_append, length_onWire, List.length_cons, Nat.add_one_mul] + have := hf i + omega + +/-- **The single-qubit layer costs at most `n · m₀` gates**: if each per-wire word `f i` has at most +`m₀` gates, then `(singleQubitLayer f).length ≤ n · m₀`. The layer runs one word on each of the `n` +wires (`layerOn f (List.finRange n)`), so `length_layerOn_le` gives the bound. -/ +theorem length_singleQubitLayer_le (f : Fin n → CliffordCircuit 1) {m₀ : ℕ} + (hf : ∀ i, (f i).length ≤ m₀) : (singleQubitLayer f).length ≤ n * m₀ := by + rw [singleQubitLayer] + calc (layerOn f (List.finRange n)).length + ≤ (List.finRange n).length * m₀ := length_layerOn_le f hf _ + _ = n * m₀ := by simp + +/-! ### The single-wire rotation words are constant-length -/ + +/-- **`rotateToX c` has at most one gate**: it is `[S]` (`Y ↦ X`), `[H]` (`Z ↦ X`), or `[]` +(`I`/`X`). -/ +theorem length_rotateToX_le (c : Fin 4) : (rotateToX c).length ≤ 1 := by + fin_cases c <;> simp [rotateToX] + +/-- **`rotateToZ c` has at most two gates**: it is `[H]` (`X ↦ Z`), `[H, S]` (`Y ↦ Z`), or `[]` +(`I`/`Z`). -/ +theorem length_rotateToZ_le (c : Fin 4) : (rotateToZ c).length ≤ 2 := by + fin_cases c <;> simp [rotateToZ] + +/-- **`rotateToZFixingX c` has at most three gates**: it is `[H, S, H]` (`Y ↦ Z` while fixing `X`), +or `[]` (`Z`). -/ +theorem length_rotateToZFixingX_le (c : Fin 4) : (rotateToZFixingX c).length ≤ 3 := by + fin_cases c <;> simp [rotateToZFixingX] + +/-! ### Inverting a circuit at most triples the gate count -/ + +/-- **Inverting a circuit at most triples its gate count**: `(inverse C).length ≤ 3 · C.length`. +Induction on the gate list: `inverse (γ :: U) = inverse U ++ γ.invList`, and each inverse word adds +at most `3` gates (`CliffordGate.length_invList_le`). -/ +theorem length_inverse_le (C : CliffordCircuit n) : (inverse C).length ≤ 3 * C.length := by + induction C with + | nil => simp [inverse] + | cons γ U ih => + rw [inverse, List.length_append, List.length_cons] + have := CliffordGate.length_invList_le γ + omega + +/-- **The per-level gate overhead of the Figure 10.9 recurrence.** Prefixing the inverse of the +first-wire-reduction circuit `B` and appending the sub-register circuit `C'` (embedded onto the last +`n` wires via `relabel f`) adds at most `3 · |B|` gates to `C'`: +`(B.inverse ++ C'.relabel f).length ≤ 3 · B.length + C'.length`. This is the arithmetic of the +inductive step `C_{n+1} = inverse B ++ relabel C'`; with a linear bound `|B| ≤ O(n)` it +unrolls to the `O(n²)` gate count of Theorem 10.6. -/ +theorem length_inverse_append_relabel_le (B : CliffordCircuit n) (C' : CliffordCircuit m) + (f : Fin m ↪ Fin n) : + (inverse B ++ C'.relabel f).length ≤ 3 * B.length + C'.length := by + rw [List.length_append, length_relabel] + have := length_inverse_le B + omega + +end CliffordCircuit + +/-! ### CNOT fans and wire swaps -/ + +/-- **A single CNOT step has at most one gate**: `(cnotStep i t).length ≤ 1` (it is `[CNOT_{i→t}]`, +or `[]` on a self-target). -/ +theorem length_cnotStep_le (i t : Fin n) : (cnotStep i t).length ≤ 1 := by + unfold cnotStep + split <;> simp + +/-- **A CNOT fan costs at most one gate per target**: `(cnotFan i ts).length ≤ ts.length`. Induction +on `ts` via `cnotFan_cons`, each step a single `cnotStep` (`length_cnotStep_le`). -/ +theorem length_cnotFan_le (i : Fin n) (ts : List (Fin n)) : + (cnotFan i ts).length ≤ ts.length := by + induction ts with + | nil => simp + | cons t ts ih => + rw [cnotFan_cons, List.length_append, List.length_cons] + have := length_cnotStep_le i t + omega + +/-- **A reverse CNOT fan costs at most one gate per control**: `(cnotFanInto c ts).length ≤ +ts.length`. Induction on `ts` via `cnotFanInto_cons`, each step a single `cnotStep`. -/ +theorem length_cnotFanInto_le (c : Fin n) (ts : List (Fin n)) : + (cnotFanInto c ts).length ≤ ts.length := by + induction ts with + | nil => simp + | cons t ts ih => + rw [cnotFanInto_cons, List.length_append, List.length_cons] + have := length_cnotStep_le t c + omega + +/-- **A wire swap has at most three gates**: `(swapWires a b).length ≤ 3` (the three-CNOT `SWAP`, or +`[]` when `a = b`). -/ +theorem length_swapWires_le (a b : Fin n) : (swapWires a b).length ≤ 3 := by + unfold swapWires + split <;> simp + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCountFirstPair.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountFirstPair.lean new file mode 100644 index 0000000000..978f9b0604 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountFirstPair.lean @@ -0,0 +1,135 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountPair +public import LeanPool.AxQM.Concrete.PauliNormalizerFirstPair + +/-! +# Concrete: the `O(n)` gate-count of the first-wire reduction (N&C Theorem 10.6) + +*(Theorem 10.6, N&C §10.5.2, p. 461.)* + +Nielsen & Chuang **Theorem 10.6** asserts that a Pauli normalizer `U ∈ N(Gₙ)` may be composed, up to +a global phase, from **`O(n²)`** Hadamard/phase/CNOT gates. The structural converse +(`isPauliNormalizer_eq_smul_cliffordCircuit`) gives the circuit; the quantitative part is the gate +count, bounded through the Figure 10.9 synthesis, using the length calculus of the definitions +(`AxQM/Concrete/PauliNormalizerGateCount.lean`), the constant gadget bounds +(`AxQM/Concrete/PauliNormalizerGateCountGadgets.lean`), the single-generator reduction bound +(`AxQM/Concrete/PauliNormalizerGateCountReduce.lean`, `≤ 2·n + 2`) and the anticommuting-pair +reduction bound (`AxQM/Concrete/PauliNormalizerGateCountPair.lean`, +`exists_cliffordCircuit_reducePair_length_le ≤ 6·n + 20`). + +This file proves the **per-level linear bound** on the first-wire reduction +circuit `B` of `IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair` (the opening move of +the Figure 10.9 inductive step, which left-composes an `(n+1)`-qubit normalizer `U` with a Clifford +circuit `B` so that `B·U` fixes the first-wire generators `X₀, Z₀` under conjugation). That circuit +is `B = G ++ (swapWires c 0 ++ E)`: + +* `E` reduces the anticommuting image pair `(σ X₀, σ Z₀)` to the canonical `(X_c, Z_c)` on a pivot + wire `c` (`exists_cliffordCircuit_reducePair_length_le`, `≤ 6·(n+1) + 20` here, as the pair lives + on `Fin (n+1)`); +* `swapWires c 0` relocates the pivot to wire `0` (`length_swapWires_le`, `≤ 3`); +* `G` is one single-wire `onWire` sign gadget on wire `0` cancelling the residual `±1` signs + `ε(X₀), ε(Z₀)` (`exists_cliffordCircuit_onWire_act_sign_length_le`, `≤ 9`). + +So `|B| ≤ 9 + 3 + (6·(n+1) + 20) = 6·(n+1) + 32` — the per-level `O(n)` overhead in the `O(n²)` +unrolling of the Figure 10.9 recurrence. + +The lemma `exists_cliffordCircuit_fixFirstPair` gives its circuit only existentially, so the length +bound reconstructs the reduction, using the length-annotated +`exists_cliffordCircuit_reducePair_length_le` for the pair reduction, and re-proves the two +conjugation-fixing facts. These follow from the plumbing lemma `normalizer_first_fix` (with its +helpers `conj_split`, `conj_circuit_smul`) of `AxQM/Concrete/PauliNormalizerFirstPair.lean`, which +is stated for an *arbitrary* reduction circuit `A` and sign gadget `G`, so the reconstructed +`B = G ++ A` fixes `X₀, Z₀` by the same matrix identity as the original lemma. The action/sign +content is identical to the original lemma; the length is additionally bounded. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The first-wire reduction costs `O(n)` gates -/ + +/-- **The first-wire reduction of a Pauli normalizer costs `≤ 6·(n+1) + 32` gates.** The +length-annotated companion of `IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair` (N&C Exercise +10.40, Figure 10.9 setup): for any `(n+1)`-qubit Pauli normalizer `U`, there is a Clifford circuit +`B` such that `B.toMatrix * U` is again a Pauli normalizer, **fixes the first-wire generators +`X₀, Z₀` exactly** under conjugation, and has `B.length ≤ 6·(n+1) + 32`. + +The circuit is `B = G ++ (swapWires c 0 ++ E)`, reconstructed with the length-annotated pair +reduction: + +* the anticommuting image pair `p = σ X₀`, `q = σ Z₀` (anticommuting because `X₀, Z₀` do and the + normalizer's signed permutation is symplectic, `exists_signedPerm_symplectic`) is reduced to + `(X_c, Z_c)` by `exists_cliffordCircuit_reducePair_length_le`, whose `E : CliffordCircuit (n+1)` + has `≤ 6·(n+1) + 20` gates; +* `swapWires c 0` relocates the pivot to wire `0` (`length_swapWires_le`, `≤ 3`, phase-free); +* one single-wire `onWire` sign gadget `G` on wire `0` cancels the residual `±1` signs + `ε(X₀), ε(Z₀)` (`exists_cliffordCircuit_onWire_act_sign_length_le`, `≤ 9`; each sign squares to + `1`). + +so `|B| = |G| + |swapWires c 0| + |E| ≤ 9 + 3 + (6·(n+1) + 20) = 6·(n+1) + 32`. The action/sign +content (normalizer closure and the two fixing facts) is proved exactly as in +`exists_cliffordCircuit_fixFirstPair`; only the length is newly tracked. This is the per-level +`O(n)` overhead of the Figure 10.9 recurrence toward the `O(n²)` gate-count headline. -/ +theorem IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair_length_le + {U : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ B : CliffordCircuit (n + 1), + IsPauliNormalizer (B.toMatrix * U) ∧ + ((B.toMatrix * U) * pauliString (xGenPauli 0) * (B.toMatrix * U)ᴴ + = pauliString (xGenPauli 0)) ∧ + ((B.toMatrix * U) * pauliString (zGenPauli 0) * (B.toMatrix * U)ᴴ + = pauliString (zGenPauli 0)) ∧ + B.length ≤ 6 * (n + 1) + 32 := by + obtain ⟨σ, ε, hε, hconj, hsymp⟩ := hU.exists_signedPerm_symplectic + -- `X₀` and `Z₀` anticommute, hence so do their images `p = σ X₀`, `q = σ Z₀`. + have hXZ : Odd (pauliAnticommCount (xGenPauli (0 : Fin (n + 1))) (zGenPauli 0)) := by + rw [odd_pauliAnticommCount_zGenPauli_iff]; left; simp [xGenPauli] + have hpq : Odd (pauliAnticommCount (σ (xGenPauli 0)) (σ (zGenPauli 0))) := by + rw [← Nat.not_even_iff_odd]; rw [← Nat.not_even_iff_odd] at hXZ + exact fun h => hXZ ((hsymp (xGenPauli 0) (zGenPauli 0)).mp h) + -- Reduce the pair `(p, q)` to `(X_c, Z_c)` with a length-bounded circuit, then swap the pivot. + obtain ⟨E, c, hEp, hEsp, hEq, hEsq, hElen⟩ := + exists_cliffordCircuit_reducePair_length_le (σ (xGenPauli 0)) (σ (zGenPauli 0)) hpq + set A := swapWires c 0 ++ E with hA + have hAp : A.act (σ (xGenPauli 0)) = xGenPauli 0 := by + rw [hA, CliffordCircuit.act_append, hEp, act_swapWires_xGenPauli] + have hAq : A.act (σ (zGenPauli 0)) = zGenPauli 0 := by + rw [hA, CliffordCircuit.act_append, hEq, act_swapWires_zGenPauli] + have hAsp : A.sign (σ (xGenPauli 0)) = 1 := by + rw [hA, CliffordCircuit.sign_append, hEsp, sign_swapWires, mul_one] + have hAsq : A.sign (σ (zGenPauli 0)) = 1 := by + rw [hA, CliffordCircuit.sign_append, hEsq, sign_swapWires, mul_one] + -- A single-wire sign gadget on wire `0` correcting the residual signs `ε(X₀), ε(Z₀)` (`≤ 9`). + obtain ⟨G, hGaX, hGsX, hGaZ, hGsZ, -, hGlen⟩ := + exists_cliffordCircuit_onWire_act_sign_length_le (0 : Fin (n + 1)) (aX := 1) (aZ := 3) + (by decide) (by decide) (by decide) (hε (xGenPauli 0)) (hε (zGenPauli 0)) + have hsq : ∀ a, ε a * ε a = 1 := fun a => by rcases hε a with h | h <;> rw [h] <;> ring + refine ⟨G ++ A, (cliffordCircuit_isPauliNormalizer (G ++ A)).mul hU, ?_, ?_, ?_⟩ + · exact normalizer_first_fix G A U (xGenPauli 0) (σ (xGenPauli 0)) (ε (xGenPauli 0)) + (hsq (xGenPauli 0)) (hconj (xGenPauli 0)) hAp hAsp hGaX hGsX + · exact normalizer_first_fix G A U (zGenPauli 0) (σ (zGenPauli 0)) (ε (zGenPauli 0)) + (hsq (zGenPauli 0)) (hconj (zGenPauli 0)) hAq hAsq hGaZ hGsZ + · -- `|G ++ (swapWires c 0 ++ E)| = |G| + |swapWires c 0| + |E| ≤ 9 + 3 + (6·(n+1) + 20)` + have hsw : (swapWires c (0 : Fin (n + 1))).length ≤ 3 := length_swapWires_le c 0 + rw [hA] + simp only [List.length_append] + omega + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCountGadgets.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountGadgets.lean new file mode 100644 index 0000000000..8740e5cae1 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountGadgets.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCount + +/-! +# Concrete: constant gate-count bounds for the single-qubit / single-wire synthesis gadgets + +*(The `O(n²)` gate-count clause of Nielsen & Chuang Theorem 10.6 / Exercise 10.40, N&C §10.5.2, +pp. 461–462.)* + +The `O(n²)` gate-count bound of Theorem 10.6 is proved by bounding the `CliffordCircuit` length +(`= List.length`, its gate count) through the Figure 10.9 reduction. The circuit arithmetic of the +building **definitions** is in `AxQM/Concrete/PauliNormalizerGateCount.lean`; this file gives the +base case: the *existence* lemmas for single-qubit and single-wire gadgets, strengthened to also +bound the gadget's length by a **constant**. + +Each lemma here repeats the construction of its `PauliNormalizer*.lean` counterpart while also +tracking the gate count. The bounds are the small explicit constants read off the finite word +lists: + +* `exists_cliffordCircuit_singleQubit_act_length_le` — a single-qubit permutation word (one of the + six words of `S₃` on `{X, Y, Z}`) has `≤ 3` gates. +* `exists_cliffordCircuit_singleQubit_signFix_length_le` — a single-qubit sign-fix word (`I`, `X`, + `Z`, `Y`-type Pauli-conjugation words) has `≤ 6` gates. +* `exists_cliffordCircuit_singleQubit_act_sign_length_le` — the glued single-qubit synthesis + `permutation ++ sign-fix` has `≤ 9` gates. +* `exists_cliffordCircuit_onWire_act_sign_length_le` — running that gadget on one wire `j` of an + `n`-qubit register (a wire relabeling, which preserves the gate count, `length_onWire`) still has + `≤ 9` gates. + +The last is the per-wire "sign gadget" the pair reduction and the first-wire reduction invoke a +bounded number of times; its constant length keeps their contribution to the level-cost `O(1)`. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **A single-qubit permutation word has at most three gates.** Strengthens +`exists_cliffordCircuit_singleQubit_act` with a gate-count bound: each of the six explicit words +realising a permutation of `{X, Y, Z}` (`[]`, `[H]`, `[S]`, `[H, S, H]`, `[H, S]`, `[S, H]`) has at +most three gates. Same `fin_cases` case split as the base lemma, with the length checked by +`decide`. -/ +theorem exists_cliffordCircuit_singleQubit_act_length_le {aX aZ : Fin 4} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) : + ∃ p : CliffordCircuit 1, CliffordCircuit.act p (fun _ => 1) = (fun _ => aX) ∧ + CliffordCircuit.act p (fun _ => 3) = (fun _ => aZ) ∧ p.length ≤ 3 := by + fin_cases aX <;> fin_cases aZ <;> + first + | exact absurd rfl h0X + | exact absurd rfl h0Z + | exact absurd rfl hne + | exact ⟨[], by decide, by decide, by decide⟩ + | exact ⟨[.had 0], by decide, by decide, by decide⟩ + | exact ⟨[.phase 0], by decide, by decide, by decide⟩ + | exact ⟨[.had 0, .phase 0, .had 0], by decide, by decide, by decide⟩ + | exact ⟨[.had 0, .phase 0], by decide, by decide, by decide⟩ + | exact ⟨[.phase 0, .had 0], by decide, by decide, by decide⟩ + +/-- **A single-qubit sign-fix word has at most six gates.** Strengthens +`exists_cliffordCircuit_singleQubit_signFix` with a gate-count bound: the four trivial-action +sign-correction words (`[]`; the `Z`-flip `H S² H`; the `X`-flip `S²`; and their both-flip +composite) have at most six gates. Same split on the target signs, length checked by `decide`. -/ +theorem exists_cliffordCircuit_singleQubit_signFix_length_le {sX sZ : ℂ} + (hsX : sX = 1 ∨ sX = -1) (hsZ : sZ = 1 ∨ sZ = -1) : + ∃ f : CliffordCircuit 1, CliffordCircuit.act f (fun _ => 1) = (fun _ => 1) ∧ + CliffordCircuit.act f (fun _ => 3) = (fun _ => 3) ∧ + CliffordCircuit.sign f (fun _ => 1) = sX ∧ CliffordCircuit.sign f (fun _ => 3) = sZ ∧ + f.length ≤ 6 := by + rcases hsX with rfl | rfl <;> rcases hsZ with rfl | rfl + · exact ⟨[], by decide, by decide, by simp [CliffordCircuit.sign], + by simp [CliffordCircuit.sign], by decide⟩ + · exact ⟨[.had 0, .phase 0, .phase 0, .had 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by decide⟩ + · exact ⟨[.phase 0, .phase 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + phasePauli, phasePauliSign, Function.update], + by decide⟩ + · exact ⟨[.had 0, .phase 0, .phase 0, .had 0, .phase 0, .phase 0], by decide, by decide, + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update], + by decide⟩ + +/-- **The single-qubit synthesis has at most nine gates.** Strengthens +`exists_cliffordCircuit_singleQubit_act_sign` with a gate-count bound. The synthesised circuit is a +permutation word (`≤ 3` gates, `exists_cliffordCircuit_singleQubit_act_length_le`) appended with a +sign-fix word (`≤ 6` gates, `exists_cliffordCircuit_singleQubit_signFix_length_le`), so appending +gives `≤ 3 + 6 = 9` gates. The action/sign facts are proved exactly as in the base lemma. -/ +theorem exists_cliffordCircuit_singleQubit_act_sign_length_le {aX aZ : Fin 4} {zX zZ : ℂ} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) + (hzX : zX = 1 ∨ zX = -1) (hzZ : zZ = 1 ∨ zZ = -1) : + ∃ C : CliffordCircuit 1, + CliffordCircuit.act C (fun _ => 1) = (fun _ => aX) ∧ + CliffordCircuit.sign C (fun _ => 1) = zX ∧ + CliffordCircuit.act C (fun _ => 3) = (fun _ => aZ) ∧ + CliffordCircuit.sign C (fun _ => 3) = zZ ∧ + C.length ≤ 9 := by + obtain ⟨p, hpX, hpZ, hplen⟩ := exists_cliffordCircuit_singleQubit_act_length_le h0X h0Z hne + have hpXpm := CliffordCircuit.sign_eq_one_or_neg_one p (fun _ => 1) + have hpZpm := CliffordCircuit.sign_eq_one_or_neg_one p (fun _ => 3) + obtain ⟨f, hfaX, hfaZ, hfsX, hfsZ, hflen⟩ := + exists_cliffordCircuit_singleQubit_signFix_length_le + (sX := zX * CliffordCircuit.sign p (fun _ => 1)) + (sZ := zZ * CliffordCircuit.sign p (fun _ => 3)) + (by rcases hzX with h | h <;> rcases hpXpm with h' | h' <;> rw [h, h'] <;> norm_num) + (by rcases hzZ with h | h <;> rcases hpZpm with h' | h' <;> rw [h, h'] <;> norm_num) + refine ⟨p ++ f, ?_, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hfaX, hpX] + · rw [CliffordCircuit.sign_append, hfaX, hfsX]; rcases hpXpm with h | h <;> rw [h] <;> ring + · rw [CliffordCircuit.act_append, hfaZ, hpZ] + · rw [CliffordCircuit.sign_append, hfaZ, hfsZ]; rcases hpZpm with h | h <;> rw [h] <;> ring + · rw [List.length_append]; omega + +/-- **The single-wire sign gadget on wire `j` has at most nine gates.** Strengthens +`exists_cliffordCircuit_onWire_act_sign` with a gate-count bound. The gadget runs the single-qubit +synthesis (`≤ 9` gates, `exists_cliffordCircuit_singleQubit_act_sign_length_le`) on wire `j` via +`CliffordCircuit.onWire`, a wire relabeling that preserves the gate count +(`CliffordCircuit.length_onWire`), so the bound is unchanged. This is the per-wire sign gadget the +pair reduction and the first-wire reduction invoke a bounded number of times per induction level. -/ +theorem exists_cliffordCircuit_onWire_act_sign_length_le (j : Fin n) {aX aZ : Fin 4} {zX zZ : ℂ} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) + (hzX : zX = 1 ∨ zX = -1) (hzZ : zZ = 1 ∨ zZ = -1) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (xGenPauli j) = Function.update (0 : Fin n → Fin 4) j aX ∧ + CliffordCircuit.sign C (xGenPauli j) = zX ∧ + CliffordCircuit.act C (zGenPauli j) = Function.update (0 : Fin n → Fin 4) j aZ ∧ + CliffordCircuit.sign C (zGenPauli j) = zZ ∧ + (∀ (g : Fin n → Fin 4) (k : Fin n), k ≠ j → CliffordCircuit.act C g k = g k) ∧ + C.length ≤ 9 := by + obtain ⟨C₀, hCaX, hCsX, hCaZ, hCsZ, hC0len⟩ := + exists_cliffordCircuit_singleQubit_act_sign_length_le h0X h0Z hne hzX hzZ + have hXj : (fun _ : Fin 1 => xGenPauli j j) = (fun _ => (1 : Fin 4)) := by + funext _; simp [xGenPauli] + have hZj : (fun _ : Fin 1 => zGenPauli j j) = (fun _ => (3 : Fin 4)) := by + funext _; simp [zGenPauli] + refine ⟨CliffordCircuit.onWire j C₀, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · rw [show xGenPauli j = Function.update (0 : Fin n → Fin 4) j 1 from rfl, + CliffordCircuit.onWire_act_update, hCaX] + · rw [CliffordCircuit.onWire_sign, hXj, hCsX] + · rw [show zGenPauli j = Function.update (0 : Fin n → Fin 4) j 3 from rfl, + CliffordCircuit.onWire_act_update, hCaZ] + · rw [CliffordCircuit.onWire_sign, hZj, hCsZ] + · intro g k hk + exact CliffordCircuit.onWire_act_of_ne _ _ _ hk + · rw [CliffordCircuit.length_onWire]; exact hC0len + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCountPair.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountPair.lean new file mode 100644 index 0000000000..a733d045af --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountPair.lean @@ -0,0 +1,270 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountGadgets +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountReduce + +/-! +# Concrete: the `O(n)` gate-count of the anticommuting-pair reduction (N&C Theorem 10.6) + +*(Theorem 10.6, N&C §10.5.2, p. 461.)* + +Nielsen & Chuang **Theorem 10.6** asserts that a Pauli normalizer `U ∈ N(Gₙ)` may be composed, up to +a global phase, from **`O(n²)`** Hadamard/phase/CNOT gates. The structural converse +(`isPauliNormalizer_eq_smul_cliffordCircuit`) gives the circuit; the quantitative part is the gate +count, bounded through the Figure 10.9 synthesis. This file bounds the length of the first-qubit +reduction `exists_cliffordCircuit_reducePair` — the move that carries a normalizer's +anticommuting generator image pair `(U X₁ U†, U Z₁ U†)` to the canonical `(X_c, Z_c)` on a common +pivot wire — by `O(n)` gates. It composes three sub-moves, each `O(n)`: + +* the symplectic first move (reduce `p` to `X_c` via `reduceToXGen`, `≤ 2·n + 2` — reused + inline here); +* the `X_c`-preserving `Z`-reduction of the partner image (`reduceSecondFixingX`: a diagonalising + single-qubit layer, `≤ 3·n`, then a reverse CNOT fan, `≤ n`, so `≤ 4·n`); +* the two `±1` sign corrections (`fixPairSigns`: at most two constant-length `onWire` gadgets, `≤ 9` + each, so `+ 18`). + +So the pair reduction costs `≤ (2·n + 2) + 4·n + 18 = 6·n + 20` gates — the per-pair `O(n)` atom of +the first-wire-reduction bound `|B| ≤ O(n)` the Figure 10.9 induction needs. + + +Contents: + +* `exists_cnotFanInto_toSingleZ_fixingX_length_le` (`≤ n`) — the reverse CNOT-clearing fan that + collapses an all-`Z` string to `Z_c` while fixing `X_c` costs at most one CNOT per support wire. +* `exists_cliffordCircuit_reduceSecondFixingX_length_le` (`≤ 4·n`) — the `X_c`-preserving + `Z`-reduction of the partner image: a diagonalising layer (`≤ 3·n`, per-wire words `rotateToZ ≤ 2` + and the pivot `rotateToZFixingX ≤ 3`) then the fan above (`≤ n`). +* `exists_cliffordCircuit_fixPairSigns_length_le` (`≤ input + 18`) — sign normalisation with at most + two constant-length `onWire` sign gadgets (`≤ 9` each). +* `exists_cliffordCircuit_reducePair_length_le` (`≤ 6·n + 20`) — the + first-qubit reduction of an anticommuting pair costs `O(n)` gates. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The `X_c`-preserving reverse CNOT-clearing fan costs `O(n)` gates -/ + +/-- **The reverse CNOT-clearing fan collapsing an all-`Z` string to `Z_c` while fixing `X_c` costs +`≤ n` gates.** The length-annotated companion of `exists_cnotFanInto_toSingleZ_fixingX` +(the `X_c`-preserving strengthening of `exists_cliffordCircuit_cnotClear_toSingleZ`): the witness is +the reverse fan `cnotFanInto c ts` over the support `ts = {k | a k = 3, k ≠ c}`, which has at most +one gate per control (`length_cnotFanInto_le`, `≤ |ts|`), and `ts` is a `Finset.filter` of `Fin n` +so `|ts| ≤ n` (`card_filter_le`). The collapse and `X_c`-preservation are those of the original +(`act_cnotFanInto_collapse`, `act_cnotFanInto_xGenPauli`); signs are not tracked (they are corrected +by the pair reduction). -/ +theorem exists_cnotFanInto_toSingleZ_fixingX_length_le (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 3) (hZ : ∀ k, a k = 0 ∨ a k = 3) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ + CliffordCircuit.act C (xGenPauli c) = xGenPauli c ∧ C.length ≤ n := by + set ts := (Finset.univ.filter (fun k => a k = 3 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 3 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 3 := fun t ht => ((hmem t).mp ht).1 + have hlen : ts.length ≤ n := by + rw [hts, Finset.length_toList] + calc (Finset.univ.filter fun k => a k = 3 ∧ k ≠ c).card + ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_filter_le _ _ + _ = n := by simp + refine ⟨cnotFanInto c ts, ?_, act_cnotFanInto_xGenPauli c ts hcnotin, + le_trans (length_cnotFanInto_le c ts) hlen⟩ + funext k + rw [act_cnotFanInto_collapse c ts hcnotin hnd a hc hall k, zGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk3 : a k = 3 + · rw [ite_eq_left ((hmem k).mpr ⟨hk3, hkc⟩)] + · rw [ite_eq_right (fun h => hk3 ((hmem k).mp h).1)] + exact (hZ k).resolve_right hk3 + +/-! ### The `X_c`-preserving `Z`-reduction of the partner image costs `O(n)` gates -/ + +/-- **The `X_c`-preserving `Z`-reduction of a Pauli string costs `≤ 4·n` gates.** The +length-annotated companion of `exists_cliffordCircuit_reduceSecondFixingX`: for a string `q` with a +`Z` factor on wire `c` (`q c ∈ {Y, Z}`), a Clifford circuit `D` collapsing `q` to `Z_c` while fixing +`X_c` (index level), with `≤ 4·n` gates. The reducing circuit is `cnotFanInto ++ layer`, whose +`X_c`-preserving diagonalising layer costs `≤ 3·n` (each per-wire word is `rotateToZ ≤ 2`, except +the pivot's `rotateToZFixingX ≤ 3`, so `≤ n·3`; `length_singleQubitLayer_le`) and whose reverse CNOT +fan +costs `≤ n` (`exists_cnotFanInto_toSingleZ_fixingX_length_le`). The action/phase content is that of +the original (diagonalise-to-all-`Z`-fixing-`X_c`, then `X_c`-preserving CNOT collapse). -/ +theorem exists_cliffordCircuit_reduceSecondFixingX_length_le (q : Fin n → Fin 4) (c : Fin n) + (hq : q c = 2 ∨ q c = 3) : + ∃ D : CliffordCircuit n, + CliffordCircuit.act D q = zGenPauli c ∧ + CliffordCircuit.act D (xGenPauli c) = xGenPauli c ∧ D.length ≤ 4 * n := by + set f : Fin n → CliffordCircuit 1 := + Function.update (fun k => CliffordCircuit.rotateToZ (q k)) c + (CliffordCircuit.rotateToZFixingX (q c)) with hf + set L := CliffordCircuit.singleQubitLayer f with hL + -- the layer diagonalises `q` to an all-`Z` string with pivot `c`, fixing `X_c` + have hLqc : CliffordCircuit.act L q c = 3 := by + rw [hL, CliffordCircuit.singleQubitLayer_act, hf, Function.update_self] + exact CliffordCircuit.rotateToZFixingX_act_self hq + have hLqZ : ∀ k, CliffordCircuit.act L q k = 0 ∨ CliffordCircuit.act L q k = 3 := by + intro k + rw [hL, CliffordCircuit.singleQubitLayer_act, hf] + by_cases hkc : k = c + · rw [hkc, Function.update_self] + exact Or.inr (CliffordCircuit.rotateToZFixingX_act_self hq) + · simp only [Function.update_of_ne hkc, CliffordCircuit.rotateToZ_act] + split + · exact Or.inl rfl + · exact Or.inr rfl + have hLx : CliffordCircuit.act L (xGenPauli c) = xGenPauli c := by + funext k + rw [hL, CliffordCircuit.singleQubitLayer_act, hf] + by_cases hkc : k = c + · rw [hkc, Function.update_self, xGenPauli_apply, ite_eq_left rfl] + exact CliffordCircuit.rotateToZFixingX_act_one _ + · simp only [Function.update_of_ne hkc, xGenPauli_apply, ite_eq_right hkc] + exact CliffordCircuit.rotateToZ_act_zero _ + -- the layer costs `≤ 3·n` gates: each per-wire word has `≤ 3` gates + have hLlen : L.length ≤ 3 * n := by + have hb : L.length ≤ n * 3 := + CliffordCircuit.length_singleQubitLayer_le f fun i => by + by_cases hic : i = c + · rw [hf, hic, Function.update_self] + exact CliffordCircuit.length_rotateToZFixingX_le _ + · rw [hf, Function.update_of_ne hic] + exact le_trans (CliffordCircuit.length_rotateToZ_le _) (by norm_num) + omega + -- collapse the all-`Z` image to `Z_c`, keeping `X_c` fixed, in `≤ n` gates + obtain ⟨K, hKq, hKx, hKlen⟩ := + exists_cnotFanInto_toSingleZ_fixingX_length_le (CliffordCircuit.act L q) c hLqc hLqZ + refine ⟨K ++ L, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append]; exact hKq + · rw [CliffordCircuit.act_append, hLx]; exact hKx + · rw [List.length_append]; omega + +/-! ### Sign normalisation of a reduced pair is constant overhead -/ + +/-- **Normalising the signs of a reduced pair costs `≤ input + 18` gates.** The length-annotated +companion of `exists_cliffordCircuit_fixPairSigns`: given a Clifford circuit `E` already sending +`p ↦ X_c` and `q ↦ Z_c` at the index level, two single-wire `onWire` sign gadgets pin the two +independent residual `±1` phases to `+1`, each with `≤ 9` gates +(`exists_cliffordCircuit_onWire_act_sign_length_le`), so at most `18` gates are prepended. In every +branch (zero, one or two corrections) the total is `≤ E.length + 18`. -/ +theorem exists_cliffordCircuit_fixPairSigns_length_le (E : CliffordCircuit n) (c : Fin n) + {p q : Fin n → Fin 4} (hp : CliffordCircuit.act E p = xGenPauli c) + (hq : CliffordCircuit.act E q = zGenPauli c) : + ∃ E' : CliffordCircuit n, CliffordCircuit.act E' p = xGenPauli c ∧ + CliffordCircuit.sign E' p = 1 ∧ CliffordCircuit.act E' q = zGenPauli c ∧ + CliffordCircuit.sign E' q = 1 ∧ E'.length ≤ E.length + 18 := by + -- correct `p`'s sign with an `X_c`-sign-flip gadget (fixing `Z_c`) if needed + obtain ⟨E1, hE1p, hE1q, hE1ps, hE1qs, hE1len⟩ : + ∃ E1 : CliffordCircuit n, CliffordCircuit.act E1 p = xGenPauli c ∧ + CliffordCircuit.act E1 q = zGenPauli c ∧ + CliffordCircuit.sign E1 p = 1 ∧ CliffordCircuit.sign E1 q = CliffordCircuit.sign E q ∧ + E1.length ≤ E.length + 9 := by + rcases CliffordCircuit.sign_eq_one_or_neg_one E p with hs | hs + · exact ⟨E, hp, hq, hs, rfl, by omega⟩ + · obtain ⟨A, hAx, hAxs, hAz, hAzs, -, hAlen⟩ := + exists_cliffordCircuit_onWire_act_sign_length_le c (aX := 1) (aZ := 3) (zX := -1) (zZ := 1) + (by decide) (by decide) (by decide) (Or.inr rfl) (Or.inl rfl) + refine ⟨A ++ E, ?_, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hp]; exact hAx + · rw [CliffordCircuit.act_append, hq]; exact hAz + · rw [CliffordCircuit.sign_append, hp, hs, hAxs]; norm_num + · rw [CliffordCircuit.sign_append, hq, hAzs, mul_one] + · rw [List.length_append]; omega + -- correct `q`'s sign with a `Z_c`-sign-flip gadget (fixing `X_c`) if needed + rcases CliffordCircuit.sign_eq_one_or_neg_one E1 q with hs | hs + · exact ⟨E1, hE1p, hE1ps, hE1q, hs, by omega⟩ + · obtain ⟨B, hBx, hBxs, hBz, hBzs, -, hBlen⟩ := + exists_cliffordCircuit_onWire_act_sign_length_le c (aX := 1) (aZ := 3) (zX := 1) (zZ := -1) + (by decide) (by decide) (by decide) (Or.inl rfl) (Or.inr rfl) + refine ⟨B ++ E1, ?_, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hE1p]; exact hBx + · rw [CliffordCircuit.sign_append, hE1p, hE1ps, hBxs]; norm_num + · rw [CliffordCircuit.act_append, hE1q]; exact hBz + · rw [CliffordCircuit.sign_append, hE1q, hs, hBzs]; norm_num + · rw [List.length_append]; omega + +/-! ### The first-qubit reduction of an anticommuting pair costs `O(n)` gates -/ + +/-- **The first-qubit reduction of an anticommuting pair costs `≤ 6·n + 20` gates.** The +length-annotated companion of `exists_cliffordCircuit_reducePair` (N&C Exercise 10.40, first-qubit +reduction): for an anticommuting pair `p, q` (`Odd (pauliAnticommCount p q)`), a Clifford circuit +`E` and pivot wire `c` reducing the pair to the canonical generators exactly — `act E p = +xGenPauli c`, +`sign E p = 1`, `act E q = zGenPauli c`, `sign E q = 1` — with `E.length ≤ 6·n + 20`. + +A three-move composition, each `O(n)`: + +1. the symplectic first move — `p` is non-identity (an anticommuting partner), so it has a support + wire `c`, and `exists_cliffordCircuit_reduceToXGen_length_le` reduces `p` to `X_c` with + `≤ 2·n + 2` gates; the Clifford action is symplectic + (`act_pauliAnticommCount_even_iff`), so the partner image `act C q` still anticommutes with `X_c` + (`act C q c ∈ {Y, Z}`). (Reconstructed inline from `reduceToXGen_length_le`.) +2. the `X_c`-preserving `Z`-reduction `D` of `act C q` + (`exists_cliffordCircuit_reduceSecondFixingX_length_le`, `≤ 4·n`), so `D ++ C` realises + `p ↦ X_c`, `q ↦ Z_c` on the index level in `≤ 6·n + 2` gates; +3. `exists_cliffordCircuit_fixPairSigns_length_le` pins the two residual `±1` phases to `+1` with at + most `18` further gates. + +Total `≤ (2·n + 2) + 4·n + 18 = 6·n + 20`. This is the per-pair `O(n)` bound used once per induction +level of the first-wire reduction (`fixFirstPair`) in the `O(n²)` bound. -/ +theorem exists_cliffordCircuit_reducePair_length_le (p q : Fin n → Fin 4) + (hpq : Odd (pauliAnticommCount p q)) : + ∃ (E : CliffordCircuit n) (c : Fin n), + CliffordCircuit.act E p = xGenPauli c ∧ CliffordCircuit.sign E p = 1 ∧ + CliffordCircuit.act E q = zGenPauli c ∧ CliffordCircuit.sign E q = 1 ∧ + E.length ≤ 6 * n + 20 := by + -- the symplectic first move, inlined: reduce `p` to `X_c` with `≤ 2·n + 2` gates + obtain ⟨c, hc⟩ : ∃ c, p c ≠ 0 := by + by_contra hall + have hp0 : ∀ k, p k = 0 := fun k => by + by_contra hk; exact hall ⟨k, hk⟩ + have hz : pauliAnticommCount p q = 0 := by + refine Finset.sum_eq_zero fun k _ => ?_ + rw [hp0 k] + simp [singlePauliAnticomm, pauliXBit, pauliZBit] + rw [hz] at hpq + exact absurd hpq (by decide) + obtain ⟨C, hCp, hCsp, hClen⟩ := exists_cliffordCircuit_reduceToXGen_length_le p c hc + have hCqc : CliffordCircuit.act C q c = 2 ∨ CliffordCircuit.act C q c = 3 := by + have hpreserve : Odd (pauliAnticommCount (C.act p) (C.act q)) := by + rw [← Nat.not_even_iff_odd] at hpq ⊢ + rwa [CliffordCircuit.act_pauliAnticommCount_even_iff] + rw [← odd_pauliAnticommCount_xGenPauli_iff, pauliAnticommCount_symm, ← hCp] + exact hpreserve + -- the `X_c`-preserving `Z`-reduction of the partner image, `≤ 4·n` gates + obtain ⟨D, hDq, hDx, hDlen⟩ := + exists_cliffordCircuit_reduceSecondFixingX_length_le (CliffordCircuit.act C q) c hCqc + set E0 := D ++ C with hE0 + have hE0p : CliffordCircuit.act E0 p = xGenPauli c := by + rw [hE0, CliffordCircuit.act_append, hCp]; exact hDx + have hE0q : CliffordCircuit.act E0 q = zGenPauli c := by + rw [hE0, CliffordCircuit.act_append]; exact hDq + have hE0len : E0.length ≤ 6 * n + 2 := by + rw [hE0, List.length_append]; omega + -- pin the two residual ±1 phases to +1, `≤ 18` further gates + obtain ⟨E, hEp, hEps, hEq, hEqs, hElen⟩ := + exists_cliffordCircuit_fixPairSigns_length_le E0 c hE0p hE0q + exact ⟨E, c, hEp, hEps, hEq, hEqs, by omega⟩ + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCountReduce.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountReduce.lean new file mode 100644 index 0000000000..77d6cfa85a --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountReduce.lean @@ -0,0 +1,324 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCount + +/-! +# Concrete: the `O(n)` gate-count of the single-generator reduction (N&C Theorem 10.6) + +*(Supporting material for Theorem 10.6, N&C §10.5.2, p. 461.)* + +Nielsen & Chuang **Theorem 10.6** asserts a normalizer `U ∈ N(Gₙ)` may be composed, up to a global +phase, from **`O(n²)`** Hadamard/phase/CNOT gates. The structural converse +(`isPauliNormalizer_eq_smul_cliffordCircuit`) is discharged; what remains is the quantitative gate +count, which is threaded bottom-up through the Figure 10.9 +synthesis: the **length calculus of the circuit-building *definitions*** +(`PauliNormalizerGateCount.lean`), then a **per-level linear bound** `|B| ≤ O(n)` on the first-wire +reduction circuit (this cascade), then the `O(n²)` headline. + +This file is the **first step**: it bounds the length of the **single-generator +reduction** — the sweep that collapses a normalizer's generator image `U X₁ U†` to a standard +`X_c`/`Z_c` (`exists_cliffordCircuit_reduceToXGen`/`…ZGen`). Each such reduction is a +diagonalising single-qubit *layer* (`O(n)` gates: one bounded word on each of `n` wires), then a +CNOT *fan* (`O(n)` gates: at most one gate per support wire), then a constant-size sign gadget, so +it costs `O(n)` gates in total. + +## Length-annotated companions + +The length-of-definition lemmas (`length_singleQubitLayer_le`, `length_cnotFan_le`, …) are in +`AxQM/Concrete/PauliNormalizerGateCount.lean`. The quantitative refinement is stated here as +length-annotated **companions** `…_length_le` of the existence lemmas, which re-exhibit each +circuit and additionally bound its `List.length`. The action/phase content is carried entirely by +the shared building-block lemmas (`singleQubitLayer_act`, `act_cnotFan_collapse`, +`onWire_act_update`, …), so each companion is a thin assembly that pairs the original construction +with a length bound, not a re-proof of the tableau algebra. + +Contents: + +* `exists_singleQubitLayer_act_diagX_length_le` / `…diagZ_length_le` — the diagonalising layers + cost `≤ n` (resp. `≤ 2·n`) gates: one `rotateToX` (`≤ 1`) resp. `rotateToZ` (`≤ 2`) word on each + of the `n` wires (`length_singleQubitLayer_le`). +* `exists_cliffordCircuit_cnotClear_toSingleX_length_le` / `…toSingleZ_length_le` — the CNOT + clearing fans cost `≤ n` gates: at most one CNOT per support wire + (`length_cnotFan_le`/`…FanInto_le`), and the support is a `Finset.filter` of `Fin n`, so its + size is `≤ n`. +* `exists_cliffordCircuit_xGen_signFlip_length_le` (`≤ 2`) / `…zGen_signFlip_length_le` (`≤ 4`) — + the sign-flip gadgets are single-wire Pauli conjugations (`Z = S²`, `X = H S² H`) on one wire. +* `exists_cliffordCircuit_reduceToXGen_length_le` (`≤ 2·n + 2`) / `…reduceToZGen_length_le` + (`≤ 3·n + 4`) — the exact single-generator reduction costs `O(n)` gates, the per-generator atom + of the linear per-level bound `|B| ≤ O(n)`. +* `exists_cliffordCircuit_reduceFirstOfPair_length_le` (`≤ 2·n + 2`) — the + symplectic first move of the anticommuting-pair reduction (reduce `p` to `X_c` while its partner + `q` keeps a `Z` factor on the pivot `c`) is exactly `reduceToXGen` applied to `p`, so it inherits + the `≤ 2·n + 2` bound. This is the `O(n)` entry point of the pair-reduction cascade toward the + first-wire reduction `fixFirstPair`. + +-/ + +@[expose] public section +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The diagonalising single-qubit layers cost `O(n)` gates -/ + +/-- **The all-`X` diagonalising layer costs `≤ n` gates.** The length-annotated companion of +`exists_singleQubitLayer_act_diagX`: for any Pauli string `a` there is a per-wire family `f` whose +layer sends `a` to its all-`X`-on-support form *and* whose gate count is `≤ n`. Take +`f k = rotateToX (a k)`; each per-wire word has `≤ 1` gate (`length_rotateToX_le`), so the layer — +one word on each of the `n` wires — has `≤ n · 1 = n` gates (`length_singleQubitLayer_le`). -/ +theorem exists_singleQubitLayer_act_diagX_length_le (a : Fin n → Fin 4) : + ∃ f : Fin n → CliffordCircuit 1, + (∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k + = if a k = 0 then 0 else 1) ∧ + (CliffordCircuit.singleQubitLayer f).length ≤ n := by + refine ⟨fun k => CliffordCircuit.rotateToX (a k), fun k => ?_, ?_⟩ + · rw [CliffordCircuit.singleQubitLayer_act]; exact CliffordCircuit.rotateToX_act (a k) + · calc (CliffordCircuit.singleQubitLayer fun k => CliffordCircuit.rotateToX (a k)).length + ≤ n * 1 := + CliffordCircuit.length_singleQubitLayer_le _ + fun i => CliffordCircuit.length_rotateToX_le _ + _ = n := Nat.mul_one n + +/-- **The all-`Z` diagonalising layer costs `≤ 2·n` gates.** The `Z`-basis mirror of +`exists_singleQubitLayer_act_diagX_length_le`: `f k = rotateToZ (a k)`, each per-wire word `≤ 2` +gates (`H` for `X`, `H S` for `Y`; `length_rotateToZ_le`), so the layer has `≤ n · 2 = 2·n` gates. +-/ +theorem exists_singleQubitLayer_act_diagZ_length_le (a : Fin n → Fin 4) : + ∃ f : Fin n → CliffordCircuit 1, + (∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k + = if a k = 0 then 0 else 3) ∧ + (CliffordCircuit.singleQubitLayer f).length ≤ 2 * n := by + refine ⟨fun k => CliffordCircuit.rotateToZ (a k), fun k => ?_, ?_⟩ + · rw [CliffordCircuit.singleQubitLayer_act]; exact CliffordCircuit.rotateToZ_act (a k) + · calc (CliffordCircuit.singleQubitLayer fun k => CliffordCircuit.rotateToZ (a k)).length + ≤ n * 2 := + CliffordCircuit.length_singleQubitLayer_le _ + fun i => CliffordCircuit.length_rotateToZ_le _ + _ = 2 * n := Nat.mul_comm n 2 + +/-! ### The CNOT-clearing fans cost `O(n)` gates -/ + +/-- **The all-`X` CNOT-clearing fan costs `≤ n` gates.** The length-annotated companion of +`exists_cliffordCircuit_cnotClear_toSingleX`: the witness is the CNOT fan `cnotFan c ts` over the +support `ts = {k | a k = 1, k ≠ c}`, which has at most one gate per target +(`length_cnotFan_le`, `≤ |ts|`), and `ts` is a `Finset.filter` of `Fin n` so `|ts| ≤ n` +(`card_filter_le`). The action/phase proof is that of the original (`act_cnotFan_collapse`, +`sign_cnotFan_collapse`). -/ +theorem exists_cliffordCircuit_cnotClear_toSingleX_length_le (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 1) (hX : ∀ k, a k = 0 ∨ a k = 1) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = xGenPauli c ∧ CliffordCircuit.sign C a = 1 ∧ C.length ≤ n := by + set ts := (Finset.univ.filter (fun k => a k = 1 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 1 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 1 := fun t ht => ((hmem t).mp ht).1 + have hlen : ts.length ≤ n := by + rw [hts, Finset.length_toList] + calc (Finset.univ.filter fun k => a k = 1 ∧ k ≠ c).card + ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_filter_le _ _ + _ = n := by simp + refine ⟨cnotFan c ts, ?_, sign_cnotFan_collapse c ts hcnotin hnd a hc hall, + le_trans (length_cnotFan_le c ts) hlen⟩ + funext k + rw [act_cnotFan_collapse c ts hcnotin hnd a hc hall k, xGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk1 : a k = 1 + · rw [ite_eq_left ((hmem k).mpr ⟨hk1, hkc⟩)] + · rw [ite_eq_right (fun h => hk1 ((hmem k).mp h).1)] + exact (hX k).resolve_right hk1 + +/-- **The all-`Z` reverse CNOT-clearing fan costs `≤ n` gates.** The `Z`-basis mirror of +`exists_cliffordCircuit_cnotClear_toSingleX_length_le`: the witness is the reverse fan +`cnotFanInto c ts` over the support `ts = {k | a k = 3, k ≠ c}` (`length_cnotFanInto_le`, `≤ |ts|`), +again `|ts| ≤ n`. Action/phase from `act_cnotFanInto_collapse`, `sign_cnotFanInto_collapse`. -/ +theorem exists_cliffordCircuit_cnotClear_toSingleZ_length_le (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 3) (hZ : ∀ k, a k = 0 ∨ a k = 3) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ CliffordCircuit.sign C a = 1 ∧ C.length ≤ n := by + set ts := (Finset.univ.filter (fun k => a k = 3 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 3 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 3 := fun t ht => ((hmem t).mp ht).1 + have hlen : ts.length ≤ n := by + rw [hts, Finset.length_toList] + calc (Finset.univ.filter fun k => a k = 3 ∧ k ≠ c).card + ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_filter_le _ _ + _ = n := by simp + refine ⟨cnotFanInto c ts, ?_, sign_cnotFanInto_collapse c ts hcnotin hnd a hc hall, + le_trans (length_cnotFanInto_le c ts) hlen⟩ + funext k + rw [act_cnotFanInto_collapse c ts hcnotin hnd a hc hall k, zGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk3 : a k = 3 + · rw [ite_eq_left ((hmem k).mpr ⟨hk3, hkc⟩)] + · rw [ite_eq_right (fun h => hk3 ((hmem k).mp h).1)] + exact (hZ k).resolve_right hk3 + +/-! ### The single-wire sign-flip gadgets are constant-length -/ + +/-- **The `X_c` sign-flip gadget costs `≤ 2` gates.** The length-annotated companion of +`exists_cliffordCircuit_xGen_signFlip`, with the explicit construction `onWire c [S, S]`: a `Z_c` +conjugation (`Z = S²`, `Z X Z = -X`, `Z Z Z = Z`) placed on wire `c`. It fixes `X_c`'s index while +negating its phase (`act = X_c`, `sign = -1`), and has `2` gates (`length_onWire`). -/ +theorem exists_cliffordCircuit_xGen_signFlip_length_le (c : Fin n) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (xGenPauli c) = xGenPauli c ∧ + CliffordCircuit.sign C (xGenPauli c) = -1 ∧ C.length ≤ 2 := by + refine ⟨CliffordCircuit.onWire c [CliffordGate.phase 0, CliffordGate.phase 0], ?_, ?_, ?_⟩ + · rw [show xGenPauli c = Function.update (0 : Fin n → Fin 4) c 1 from rfl, + CliffordCircuit.onWire_act_update, + show CliffordCircuit.act [CliffordGate.phase 0, CliffordGate.phase 0] + (fun _ => (1 : Fin 4)) 0 = 1 from by decide] + · have hcc : xGenPauli c c = 1 := by rw [xGenPauli_apply, ite_eq_left rfl] + rw [CliffordCircuit.onWire_sign, hcc] + simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + phasePauli, phasePauliSign, Function.update] + · simp [CliffordCircuit.length_onWire] + +/-- **The `Z_c` sign-flip gadget costs `≤ 4` gates.** The length-annotated companion of +`exists_cliffordCircuit_zGen_signFlip`, with the explicit construction `onWire c [H, S, S, H]`: an +`X_c` conjugation (`X = H S² H`, `X Z X = -Z`, `X X X = X`) placed on wire `c`. It fixes `Z_c`'s +index while negating its phase (`act = Z_c`, `sign = -1`), and has `4` gates (`length_onWire`). -/ +theorem exists_cliffordCircuit_zGen_signFlip_length_le (c : Fin n) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (zGenPauli c) = zGenPauli c ∧ + CliffordCircuit.sign C (zGenPauli c) = -1 ∧ C.length ≤ 4 := by + refine ⟨CliffordCircuit.onWire c + [CliffordGate.had 0, CliffordGate.phase 0, CliffordGate.phase 0, CliffordGate.had 0], + ?_, ?_, ?_⟩ + · rw [show zGenPauli c = Function.update (0 : Fin n → Fin 4) c 3 from rfl, + CliffordCircuit.onWire_act_update, + show CliffordCircuit.act [CliffordGate.had 0, CliffordGate.phase 0, CliffordGate.phase 0, + CliffordGate.had 0] (fun _ => (3 : Fin 4)) 0 = 3 from by decide] + · have hcc : zGenPauli c c = 3 := by rw [zGenPauli_apply, ite_eq_left rfl] + rw [CliffordCircuit.onWire_sign, hcc] + simp [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act, + hadamardPauli, hadamardPauliSign, phasePauli, phasePauliSign, Function.update] + · simp [CliffordCircuit.length_onWire] + +/-! ### The single-generator reduction costs `O(n)` gates -/ + +/-- **Exact reduction to a standard `X` generator costs `≤ 2·n + 2` gates.** The length-annotated +companion of `exists_cliffordCircuit_reduceToXGen`: the reducing circuit is +`[sign gadget] ++ cnotClear ++ layer`, whose diagonalising layer costs `≤ n` +(`…diagX_length_le`), CNOT clear `≤ n` (`…cnotClear_toSingleX_length_le`) and sign gadget `≤ 2` +(`…xGen_signFlip_length_le`), so `≤ 2·n + 2` gates. This is the per-generator `O(n)` atom of the +linear per-level bound the Figure 10.9 induction needs. -/ +theorem exists_cliffordCircuit_reduceToXGen_length_le (a : Fin n → Fin 4) (c : Fin n) + (hc : a c ≠ 0) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = xGenPauli c ∧ CliffordCircuit.sign C a = 1 ∧ + C.length ≤ 2 * n + 2 := by + obtain ⟨f, hf, hLlen⟩ := exists_singleQubitLayer_act_diagX_length_le a + have ha'c : CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a c = 1 := by + rw [hf c, ite_eq_right hc] + have ha'X : ∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 0 ∨ + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 1 := by + intro k; rw [hf k]; split + · exact Or.inl rfl + · exact Or.inr rfl + obtain ⟨K, hKact, hKsign, hKlen⟩ := + exists_cliffordCircuit_cnotClear_toSingleX_length_le + (CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a) c ha'c ha'X + set L := CliffordCircuit.singleQubitLayer f with hLdef + have hrest_act : CliffordCircuit.act (K ++ L) a = xGenPauli c := by + rw [CliffordCircuit.act_append]; exact hKact + have hrest_sign : CliffordCircuit.sign (K ++ L) a = CliffordCircuit.sign L a := by + rw [CliffordCircuit.sign_append, hKsign, mul_one] + have hrest_len : (K ++ L).length ≤ 2 * n := by + rw [List.length_append]; omega + rcases CliffordCircuit.sign_eq_one_or_neg_one L a with hs | hs + · exact ⟨K ++ L, hrest_act, by rw [hrest_sign]; exact hs, by omega⟩ + · obtain ⟨D, hDact, hDsign, hDlen⟩ := exists_cliffordCircuit_xGen_signFlip_length_le c + refine ⟨D ++ (K ++ L), ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hrest_act, hDact] + · rw [CliffordCircuit.sign_append, hrest_sign, hs, hrest_act, hDsign]; norm_num + · rw [List.length_append]; omega + +/-- **Exact reduction to a standard `Z` generator costs `≤ 3·n + 4` gates.** The `Z`-basis mirror of +`exists_cliffordCircuit_reduceToXGen_length_le`: the diagonalising layer costs `≤ 2·n` +(`…diagZ_length_le`), CNOT clear `≤ n` (`…cnotClear_toSingleZ_length_le`) and sign gadget `≤ 4` +(`…zGen_signFlip_length_le`), so `≤ 3·n + 4` gates. -/ +theorem exists_cliffordCircuit_reduceToZGen_length_le (a : Fin n → Fin 4) (c : Fin n) + (hc : a c ≠ 0) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ CliffordCircuit.sign C a = 1 ∧ + C.length ≤ 3 * n + 4 := by + obtain ⟨f, hf, hLlen⟩ := exists_singleQubitLayer_act_diagZ_length_le a + have ha'c : CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a c = 3 := by + rw [hf c, ite_eq_right hc] + have ha'Z : ∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 0 ∨ + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 3 := by + intro k; rw [hf k]; split + · exact Or.inl rfl + · exact Or.inr rfl + obtain ⟨K, hKact, hKsign, hKlen⟩ := + exists_cliffordCircuit_cnotClear_toSingleZ_length_le + (CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a) c ha'c ha'Z + set L := CliffordCircuit.singleQubitLayer f with hLdef + have hrest_act : CliffordCircuit.act (K ++ L) a = zGenPauli c := by + rw [CliffordCircuit.act_append]; exact hKact + have hrest_sign : CliffordCircuit.sign (K ++ L) a = CliffordCircuit.sign L a := by + rw [CliffordCircuit.sign_append, hKsign, mul_one] + have hrest_len : (K ++ L).length ≤ 3 * n := by + rw [List.length_append]; omega + rcases CliffordCircuit.sign_eq_one_or_neg_one L a with hs | hs + · exact ⟨K ++ L, hrest_act, by rw [hrest_sign]; exact hs, by omega⟩ + · obtain ⟨D, hDact, hDsign, hDlen⟩ := exists_cliffordCircuit_zGen_signFlip_length_le c + refine ⟨D ++ (K ++ L), ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hrest_act, hDact] + · rw [CliffordCircuit.sign_append, hrest_sign, hs, hrest_act, hDsign]; norm_num + · rw [List.length_append]; omega + +/-! ### The symplectic first move of the pair reduction costs `O(n)` gates -/ + +/-- **The symplectic first move of the pair reduction costs `≤ 2·n + 2` gates.** The +length-annotated companion of `exists_cliffordCircuit_reduceFirstOfPair`: for an anticommuting pair +`p, q`, the +reducing circuit `C` is exactly an `exists_cliffordCircuit_reduceToXGen_length_le` applied to `p` +(reducing `p` to `X_c`), so it inherits that reduction's `≤ 2·n + 2` gate count. The pivot wire `c`, +the exact reduction of `p`, and the `Y`/`Z` factor of `act C q` on `c` are established exactly as in +the base lemma (via the symplectic invariance `act_pauliAnticommCount_even_iff`). This is the first +move whose `O(n)` cost feeds the per-level overhead of the Figure 10.9 recurrence. -/ +theorem exists_cliffordCircuit_reduceFirstOfPair_length_le (p q : Fin n → Fin 4) + (hpq : Odd (pauliAnticommCount p q)) : + ∃ (C : CliffordCircuit n) (c : Fin n), + CliffordCircuit.act C p = xGenPauli c ∧ CliffordCircuit.sign C p = 1 ∧ + (CliffordCircuit.act C q c = 2 ∨ CliffordCircuit.act C q c = 3) ∧ + C.length ≤ 2 * n + 2 := by + obtain ⟨c, hc⟩ := exists_support_of_odd_pauliAnticommCount p q hpq + obtain ⟨C, hCact, hCsign, hClen⟩ := exists_cliffordCircuit_reduceToXGen_length_le p c hc + refine ⟨C, c, hCact, hCsign, ?_, hClen⟩ + have hpreserve : Odd (pauliAnticommCount (C.act p) (C.act q)) := by + rw [← Nat.not_even_iff_odd] at hpq ⊢ + rwa [CliffordCircuit.act_pauliAnticommCount_even_iff] + rw [← odd_pauliAnticommCount_xGenPauli_iff, pauliAnticommCount_symm, ← hCact] + exact hpreserve + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGateCountSynthesis.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountSynthesis.lean new file mode 100644 index 0000000000..680fb70661 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGateCountSynthesis.lean @@ -0,0 +1,229 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountFirstPair + +/-! +# Concrete: the `O(n²)` gate-count headline of the normalizer synthesis (N&C Theorem 10.6 / +Exercise 10.40, Fig 10.9) + +*(Supporting material for Theorem 10.6 and Exercise 10.40, N&C +§10.5.2, pp. 461–462.)* + +Nielsen & Chuang **Theorem 10.6** (and its worked proof, **Exercise 10.40**) asserts that a Pauli +normalizer `U ∈ N(Gₙ)` may be composed, up to a global phase, from **`O(n²)`** Hadamard/phase/CNOT +gates. The structural *existence* content — that H/S/CNOT generate `N(Gₙ)` — is +`isPauliNormalizer_eq_smul_cliffordCircuit` (`PauliNormalizerInduction.lean`), which gives a +Clifford circuit `C` with `U = c • C.toMatrix` (`‖c‖ = 1`) but **no** bound on `C.length`. This file +supplies the missing **quantitative** clause: the *same* Figure 10.9 synthesis, re-run with a +length-tracking invariant, produces a circuit of length `≤ 9·n² + 105·n`. + +## The recurrence + +Threading the per-move `O(n)` bounds of the gate-count cascade +(`PauliNormalizerGateCount*.lean`) through the two structural steps of the induction: + +* **First-wire reduction** (`exists_cliffordCircuit_fixFirstPair_length_le`, in + `PauliNormalizerGateCountFirstPair.lean`). The circuit `B` that brings `U` to a normalizer fixing + `X₀, Z₀` is `G ++ (swapWires c 0 ++ E)` with `E` the anticommuting-pair reduction + (`≤ 6·(n+1)+20`), a wire swap (`≤ 3`) and a single-wire sign gadget `G` (`≤ 9`), so + `|B| ≤ 6·(n+1) + 32` — linear in the wire count. +* **Inductive step.** At level `n + 1` the synthesised circuit is `inverse B ++ C'.relabel succ`, + where `C'` is the sub-register circuit from the inductive hypothesis. By + `length_inverse_append_relabel_le` this costs `≤ 3·|B| + |C'|`. With `|B| ≤ 6·(n+1) + 32` and the + inductive bound `|C'| ≤ 9·n² + 105·n`, the recurrence is + `L(n+1) ≤ 3·(6·(n+1) + 32) + (9·n² + 105·n) = 9·(n+1)² + 105·(n+1)`, + an *equality* in the arithmetic, so the quadratic closed form + `L(n) ≤ 9·n² + 105·n` (`= O(n²)`) propagates exactly. The base `L(0) = 0` is the empty circuit. + +`9·n² + 105·n` is a concrete quadratic bound; it is manifestly `O(n²)`, matching the textbook claim. + +## Relation to the existence statement + +`isPauliNormalizer_eq_smul_cliffordCircuit` is an `∃`-statement, so its witness circuit is opaque: a +length bound cannot be recovered *post hoc*. The length-tracking statement is therefore proved as a +**companion** — the existence proof is repeated and +augmented with the length conjunct. The action / phase / normalizer content is unchanged; +only the `List.length` arithmetic is new. The per-level `O(n)` first-wire atom +(`exists_cliffordCircuit_fixFirstPair_length_le`) is the analogous companion of +`exists_cliffordCircuit_fixFirstPair`; it is proved separately +in `AxQM/Concrete/PauliNormalizerGateCountFirstPair.lean`. + +## The `O(n²)` headline and the qualitative characterization + +`isPauliNormalizer_eq_smul_cliffordCircuit_bigO` restates the bound in the textbook `O(n²)` form: a +*single universal* constant `K` (here `114`) with `C.length ≤ K·n²` for every `n` and every +`n`-qubit normalizer — the constant is uniform in `n` (a per-`n` `∃ K` would be vacuous), so this is +the faithful reading of "composed from `O(n²)` gates". Immediate from the polynomial bound via +`9·n² + 105·n ≤ 114·n²`. + +With both inclusions available — the synthesis (converse) and the easy direction +(`cliffordCircuit_isPauliNormalizer`, every Clifford circuit is a normalizer) — +`isPauliNormalizer_iff_eq_smul_cliffordCircuit` records the biconditional +`IsPauliNormalizer U ↔ ∃ C c, ‖c‖ = 1 ∧ U = c • C.toMatrix`: the normalizer `N(Gₙ)` is *exactly* +the Clifford circuits up to a global phase. The reverse implication uses `IsPauliNormalizer.smul` +— a unit global phase times a normalizer is again a normalizer (`|c|² = 1` cancels in the +conjugation, and `c • V` stays unitary). + +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +/-- **Nielsen & Chuang, Theorem 10.6 (converse), with the `O(n²)` gate count.** Every `n`-qubit +Pauli normalizer `U` equals a global phase times a Clifford (`H`/`S`/`CNOT`) circuit `C` of length +**at most `9·n² + 105·n`**: `∃ C c, ‖c‖ = 1 ∧ U = c • C.toMatrix ∧ C.length ≤ 9·n² + 105·n`. This is +the length-tracking companion of `isPauliNormalizer_eq_smul_cliffordCircuit`, and completes the +quantitative clause of Exercise 10.40 (parts 2–3): the concrete quadratic bound is `O(n²)`, exactly +the textbook count. Proved by `Nat.rec` on the wire count; the base `n = 0` is the empty circuit +(`0 ≤ 0`), and the step threads `exists_cliffordCircuit_fixFirstPair_length_le` +(`|B| ≤ 6·(n+1) + 32`) and `length_inverse_append_relabel_le` +(`|inverse B ++ relabel C'| ≤ 3·|B| + |C'|`) into the exact +recurrence `L(n+1) ≤ 3·(6·(n+1)+32) + L(n) = 9·(n+1)² + 105·(n+1)`. -/ +theorem isPauliNormalizer_eq_smul_cliffordCircuit_length_le {n : ℕ} + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ (C : CliffordCircuit n) (c : ℂ), + ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C ∧ C.length ≤ 9 * n ^ 2 + 105 * n := by + induction n with + | zero => + -- `Fin 0 → Fin 2` is a singleton: `U` is a `1×1` unitary, the empty circuit's matrix is `1`. + refine ⟨[], U default default, ?_, ?_, ?_⟩ + · have hUU : Uᴴ * U = 1 := by + have h := mem_unitaryGroup_iff'.mp hU.1 + rwa [star_eq_conjTranspose] at h + have h1 := congrFun (congrFun hUU default) default + simp only [Matrix.mul_apply, Matrix.one_apply_eq] at h1 + rw [Finset.sum_eq_single default] at h1 + · rw [Matrix.conjTranspose_apply] at h1 + have hnn : ‖U default default‖ * ‖U default default‖ = 1 := by + have := congrArg norm h1 + rwa [norm_mul, norm_star, norm_one] at this + nlinarith [norm_nonneg (U default default), hnn] + · intro b _ hb; exact absurd (Subsingleton.elim b default) hb + · intro h; exact absurd (Finset.mem_univ default) h + · funext i j + rw [Subsingleton.elim i default, Subsingleton.elim j default] + simp [CliffordCircuit.toMatrix, Matrix.one_apply_eq] + · simp + | succ n ih => + -- Step 1: reduce `U` to a normalizer `M = B U` fixing `X₀, Z₀`, with `|B| ≤ 6·(n+1) + 32`. + obtain ⟨B, hM, hMX, hMZ, hBlen⟩ := hU.exists_cliffordCircuit_fixFirstPair_length_le + set M := B.toMatrix * U with hMdef + -- Step 2: the restriction `M' = firstWireRestrict M` is an `n`-qubit normalizer. + have hM' : IsPauliNormalizer (firstWireRestrict M) := + firstWireRestrict_isPauliNormalizer hM hMX hMZ + set M' := firstWireRestrict M with hM'def + -- Step 3: apply the IH to `M'` (carrying its length bound `|C'| ≤ 9n²+105n`). + obtain ⟨C', c', hc', hC'eq, hC'len⟩ := ih hM' + -- Step 4: embed `C'` onto the last `n` wires. + set B' := C'.relabel ⟨Fin.succ, Fin.succ_injective n⟩ with hB'def + -- Step 5: `M` matches `B'` on every generator, so `M = c • B'.toMatrix`. + have hM'conj : ∀ g : Fin n → Fin 4, + M' * pauliString g * M'ᴴ + = CliffordCircuit.sign C' g • pauliString (CliffordCircuit.act C' g) := by + intro g + rw [hC'eq, smul_conjTranspose_conj_cancel hc', CliffordCircuit.conj_pauliString] + have hgenX : ∀ i, M * pauliString (xGenPauli i) * Mᴴ + = CliffordCircuit.sign B' (xGenPauli i) + • pauliString (CliffordCircuit.act B' (xGenPauli i)) := by + intro i + refine Fin.cases ?_ ?_ i + · rw [hMX, xGenPauli_zero_eq_cons, hB'def, CliffordCircuit.relabelSucc_act_cons, + CliffordCircuit.relabelSucc_sign_cons, CliffordCircuit.act_const_zero, + CliffordCircuit.sign_const_zero, one_smul, ← xGenPauli_zero_eq_cons] + · intro j + rw [xGenPauli_succ_eq_cons, hM.conj_pauliString_cons hMX hMZ, hM'conj, + embedLast_smul, ← pauliString_cons_zero, hB'def, + CliffordCircuit.relabelSucc_act_cons, CliffordCircuit.relabelSucc_sign_cons] + have hgenZ : ∀ i, M * pauliString (zGenPauli i) * Mᴴ + = CliffordCircuit.sign B' (zGenPauli i) + • pauliString (CliffordCircuit.act B' (zGenPauli i)) := by + intro i + refine Fin.cases ?_ ?_ i + · rw [hMZ, zGenPauli_zero_eq_cons, hB'def, CliffordCircuit.relabelSucc_act_cons, + CliffordCircuit.relabelSucc_sign_cons, CliffordCircuit.act_const_zero, + CliffordCircuit.sign_const_zero, one_smul, ← zGenPauli_zero_eq_cons] + · intro j + rw [zGenPauli_succ_eq_cons, hM.conj_pauliString_cons hMX hMZ, hM'conj, + embedLast_smul, ← pauliString_cons_zero, hB'def, + CliffordCircuit.relabelSucc_act_cons, CliffordCircuit.relabelSucc_sign_cons] + obtain ⟨c, hc, hMeq⟩ := + unitary_eq_smul_cliffordCircuit_of_conj_generators hM.1 B' hgenX hgenZ + -- Step 6: left-cancel `B` with its inverse; the length is `|inverse B ++ B'| ≤ 3|B| + |C'|`. + refine ⟨B.inverse ++ B', c, hc, ?_, ?_⟩ + · have hUeq : U = B.inverse.toMatrix * M := by + rw [hMdef, ← Matrix.mul_assoc, CliffordCircuit.toMatrix_inverse_mul, Matrix.one_mul] + rw [hUeq, hMeq, CliffordCircuit.toMatrix_append, Matrix.mul_smul] + · -- `L(n+1) ≤ 3·|B| + |C'| ≤ 3·(6·(n+1)+32) + (9n²+105n) = 9·(n+1)² + 105·(n+1)`. + rw [hB'def] + have hrec := CliffordCircuit.length_inverse_append_relabel_le B C' + ⟨Fin.succ, Fin.succ_injective n⟩ + nlinarith [hrec, hBlen, hC'len] + +/-! ### A unit global phase times a normalizer is a normalizer -/ + +/-- **A unit global phase times a Pauli normalizer is a Pauli normalizer**: if `V ∈ N(Gₙ)` and +`‖c‖ = 1` then `c • V ∈ N(Gₙ)`. Unitarity is preserved (`(c • V)(c • V)† = |c|²·VV† = 1`), and the +global phase cancels in every conjugation (`(c • V) p (c • V)† = |c|²·V p V† = V p V†`), so `c • V` +sends the Pauli group into itself exactly as `V` does. -/ +theorem IsPauliNormalizer.smul {n : ℕ} {V : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hV : IsPauliNormalizer V) {c : ℂ} (hc : ‖c‖ = 1) : IsPauliNormalizer (c • V) := by + have hcc : c * star c = 1 := by simp [RCLike.mul_conj, hc] + refine ⟨?_, fun p => ?_⟩ + · -- `c • V` is unitary: `(c • V) * (c • V)⋆ = (c * star c) • (V * V⋆) = 1 • 1 = 1`. + rw [Matrix.mem_unitaryGroup_iff, star_smul, smul_mul_smul_comm, + Matrix.mem_unitaryGroup_iff.mp hV.1, hcc, one_smul] + · -- The conjugation is `V`'s, since the unit phase cancels. + rw [smul_conjTranspose_conj_cancel hc]; exact hV.2 p + +/-! ### The `O(n²)` headline (Theorem 10.6 proper) -/ + +/-- **Nielsen & Chuang, Theorem 10.6.** There is a *universal* constant `K` (here `114`) such that +every `n`-qubit Pauli normalizer `U` is a global phase times a Clifford circuit of `O(n²)` gates: +`∃ K, ∀ n U, IsPauliNormalizer U → ∃ C c, ‖c‖ = 1 ∧ U = c • C.toMatrix ∧ C.length ≤ K · n²`. This is +the faithful formalisation of N&C's "up to a global phase `U` may be composed from `O(n²)` +Hadamard/phase/CNOT gates" — the constant `K` is uniform in `n`. It follows from the explicit +polynomial bound `isPauliNormalizer_eq_smul_cliffordCircuit_length_le` (`≤ 9·n² + 105·n`) via +`9·n² + 105·n ≤ 114·n²` (using `n ≤ n²`). -/ +theorem isPauliNormalizer_eq_smul_cliffordCircuit_bigO : + ∃ K : ℕ, ∀ (n : ℕ) (U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ), + IsPauliNormalizer U → + ∃ (C : CliffordCircuit n) (c : ℂ), + ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C ∧ C.length ≤ K * n ^ 2 := by + refine ⟨114, fun n U hU => ?_⟩ + obtain ⟨C, c, hc, hUeq, hlen⟩ := isPauliNormalizer_eq_smul_cliffordCircuit_length_le hU + have hnn : n ≤ n ^ 2 := Nat.le_self_pow (by norm_num) n + exact ⟨C, c, hc, hUeq, hlen.trans (by nlinarith [hnn])⟩ + +/-! ### The qualitative characterization: `N(Gₙ)` is exactly the Clifford circuits up to phase -/ + +/-- **`N(Gₙ)` is exactly the Clifford circuits, up to a global phase.** A matrix `U` is a Pauli +normalizer iff it equals a unit global phase times a Clifford (`H`/`S`/`CNOT`) circuit: +`IsPauliNormalizer U ↔ ∃ C c, ‖c‖ = 1 ∧ U = c • C.toMatrix`. The forward direction is the inductive +synthesis (Theorem 10.6's converse, `isPauliNormalizer_eq_smul_cliffordCircuit`); the reverse is the +easy direction — every Clifford circuit is a normalizer (`cliffordCircuit_isPauliNormalizer`) and a +unit global phase preserves the normalizer property (`IsPauliNormalizer.smul`). This packages the +two inclusions of Theorem 10.6 as a single characterization of the normalizer group. -/ +theorem isPauliNormalizer_iff_eq_smul_cliffordCircuit {n : ℕ} + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} : + IsPauliNormalizer U ↔ + ∃ (C : CliffordCircuit n) (c : ℂ), ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C := by + refine ⟨isPauliNormalizer_eq_smul_cliffordCircuit, ?_⟩ + rintro ⟨C, c, hc, rfl⟩ + exact (cliffordCircuit_isPauliNormalizer C).smul hc + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerGenerators.lean b/LeanPool/AxQM/Concrete/PauliNormalizerGenerators.lean new file mode 100644 index 0000000000..976bdad0aa --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerGenerators.lean @@ -0,0 +1,307 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizer +public import LeanPool.AxQM.Concrete.PauliStringEncodingPhaseCZLayer + +/-! +# Concrete: a unitary is fixed up to a global phase by its conjugation of the generators + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40). It proves the **multi-qubit generator-determinacy +lemma**: a unitary on `n` qubits is determined, up to a global phase, by how it conjugates the `2n` +single-qubit generators `Xᵢ = xGenPauli i` and `Zᵢ = zGenPauli i`. + +This is the multi-qubit generalisation of the single-qubit +`unitary_eq_smul_of_conj_singleQubit_XZ`, and it is exactly the reduction that turns the *inductive +synthesis* of Exercise 10.40 (parts 2–3) from *matching a normalizer's full signed permutation on +all `4ⁿ` Pauli strings* into the finite, combinatorial task of *matching it on the `2n` generators* +— the datum a Clifford circuit is actually built to reproduce. Its Clifford-circuit corollary +`unitary_eq_smul_cliffordCircuit_of_conj_generators` is the direct handle for the synthesis: build a +Clifford circuit whose phase-free action and `±1` sign agree with `U`'s conjugation on every `Xᵢ` +and `Zᵢ`, and `U` equals that circuit up to a unit global phase. + +## What is proved + +* `pauliString_peel_wire` — **peel one wire off a Pauli string.** `P_a = P_{a'} · P_{b}` where + `a' = Function.update a i 0` zeroes wire `i` and `b = Function.update 0 i (a i)` is the + single-wire Pauli on wire `i`. The two factors overlap on no wire, so the Pauli-string product law + (`pauliString_mul_eq_smul`) contributes index `a` and phase `1`. This is the recursion that + expresses any Pauli string as a product of single-wire generators. + +* `pauliString_yGenPauli_eq_smul_mul` — **`Yᵢ = i · Xᵢ Zᵢ`** on any wire: `P_{Yᵢ} = i • (P_{Xᵢ} · + P_{Zᵢ})`. The multi-qubit analogue of `pauliString_two_eq_smul_mul`; it writes the third + single-wire Pauli through the two generators `Xᵢ, Zᵢ`, so agreement on `X` and `Z` forces + agreement on `Y`. + +* `unitary_eq_smul_of_conj_generators` — **generator-determinacy.** If two unitaries `U, V` + conjugate every `Xᵢ` and every `Zᵢ` identically, then `U = c • V` with `‖c‖ = 1`. The agreement is + closed under products (multiplicativity of conjugation by an isometry, + `conj_mul_conj_of_conjTranspose_mul_self`) and scalars, contains `Xᵢ, Zᵢ`, hence `Yᵢ` and the + identity; a `Finset.induction` on the support peels the string wire by wire + (`pauliString_peel_wire`) down to generators, giving agreement on every Pauli string, and + `unitary_eq_smul_of_conj_pauliString_eq` concludes. + +* `unitary_eq_smul_cliffordCircuit_of_conj_generators` — **synthesis reduces to matching on + generators.** If a unitary `U` conjugates every `Xᵢ` and `Zᵢ` exactly as a Clifford circuit `C` + does (`U P_{Xᵢ} U† = C.sign (Xᵢ) • P_{C.act (Xᵢ)}`, and likewise for `Zᵢ`), then `U = c • + C.toMatrix`, `‖c‖ = 1`. Immediate from generator-determinacy once `C`'s conjugation is folded + through `CliffordCircuit.conj_pauliString`. This is the multi-qubit refinement of + `unitary_eq_smul_cliffordCircuit_of_conj_eq` (which required matching on *all* Pauli strings): the + inductive synthesis of Exercise 10.40 need only reproduce the normalizer's action on the `2n` + generators. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Zero cases of the single-qubit Pauli product tables -/ + +/-- The identity Pauli is a left unit for the index product: `pauliMul 0 b = b`. -/ +private theorem pauliMul_zero_left (b : Fin 4) : pauliMul 0 b = b := by fin_cases b <;> rfl + +/-- The identity Pauli is a right unit for the index product: `pauliMul a 0 = a`. -/ +private theorem pauliMul_zero_right (a : Fin 4) : pauliMul a 0 = a := by fin_cases a <;> rfl + +/-- The identity Pauli contributes trivial phase on the left: `pauliMulPhase 0 b = 1`. -/ +private theorem pauliMulPhase_zero_left (b : Fin 4) : pauliMulPhase 0 b = 1 := by + fin_cases b <;> rfl + +/-- The identity Pauli contributes trivial phase on the right: `pauliMulPhase a 0 = 1`. -/ +private theorem pauliMulPhase_zero_right (a : Fin 4) : pauliMulPhase a 0 = 1 := by + fin_cases a <;> rfl + +/-! ### Peeling a wire off a Pauli string, and `Y = i X Z` on a wire -/ + +/-- **Peel one wire off a Pauli string.** For any Pauli string `a : Fin n → Fin 4` and wire `i`, +`P_a = P_{a'} · P_{b}` where `a' = Function.update a i 0` zeroes wire `i` and `b = Function.update 0 +i (a i)` is the single-wire Pauli carrying `a`'s letter on wire `i`. The two factors are supported +on disjoint wires (`a'` is `I` on wire `i`; `b` is `I` off wire `i`), so in the Pauli-string product +law (`pauliString_mul_eq_smul`) every per-wire product is with an identity — the product index is +`a` (`pauliMul` has `0` as a unit) and the total phase is `1`. This is the recursion expressing any +Pauli string as a product of single-wire generators. -/ +theorem pauliString_peel_wire (a : Fin n → Fin 4) (i : Fin n) : + pauliString a + = pauliString (Function.update a i 0) + * pauliString (Function.update (0 : Fin n → Fin 4) i (a i)) := by + rw [pauliString_mul_eq_smul] + have hidx : + pauliMulIndex (Function.update a i 0) (Function.update (0 : Fin n → Fin 4) i (a i)) = a := by + funext k + rcases eq_or_ne k i with hk | hk + · subst hk + simp only [pauliMulIndex, Function.update_self, pauliMul_zero_left] + · simp only [pauliMulIndex, Function.update_of_ne hk, Pi.zero_apply, pauliMul_zero_right] + have hph : + (∏ k, pauliMulPhase (Function.update a i 0 k) + (Function.update (0 : Fin n → Fin 4) i (a i) k)) = 1 := by + refine Finset.prod_eq_one (fun k _ => ?_) + rcases eq_or_ne k i with hk | hk + · subst hk + simp only [Function.update_self, pauliMulPhase_zero_left] + · simp only [Function.update_of_ne hk, Pi.zero_apply, pauliMulPhase_zero_right] + rw [hidx, hph, one_smul] + +/-- **`Yᵢ = i · Xᵢ Zᵢ` on any wire.** `P_{yGenPauli i} = i • (P_{xGenPauli i} · P_{zGenPauli i})`. +From the Pauli-string product law, `Xᵢ Zᵢ = (∏ₖ ζ) • P_{idx}` where the only non-trivial factor is +on wire `i` (`ζ(X, Z) = -i`) and the product index is `Yᵢ`; `i · (-i) = 1`. The multi-qubit +analogue of `pauliString_two_eq_smul_mul`, expressing the single-wire `Y` generator through the two +generators `X, Z`. -/ +theorem pauliString_yGenPauli_eq_smul_mul (i : Fin n) : + pauliString (yGenPauli i) + = Complex.I • (pauliString (xGenPauli i) * pauliString (zGenPauli i)) := by + rw [pauliString_mul_eq_smul, smul_smul] + have hidx : pauliMulIndex (xGenPauli i) (zGenPauli i) = yGenPauli i := by + funext k + rcases eq_or_ne k i with hk | hk + · subst hk + simp only [pauliMulIndex, xGenPauli, zGenPauli, yGenPauli, Function.update_self] + rfl + · simp only [pauliMulIndex, xGenPauli, zGenPauli, yGenPauli, Function.update_of_ne hk, + Pi.zero_apply] + rfl + rw [hidx] + have hprod : (∏ k, pauliMulPhase (xGenPauli i k) (zGenPauli i k)) = -Complex.I := by + rw [Finset.prod_eq_single i] + · simp only [xGenPauli, zGenPauli, Function.update_self]; rfl + · intro k _ hki + simp only [xGenPauli, zGenPauli, Function.update_of_ne hki, Pi.zero_apply, + pauliMulPhase_zero_left] + · intro hi; exact absurd (Finset.mem_univ i) hi + rw [hprod, mul_neg, Complex.I_mul_I, neg_neg, one_smul] + +/-! ### Generator-determinacy up to a global phase -/ + +/-- **A unitary is determined up to a global phase by how it conjugates the generators `Xᵢ, Zᵢ`.** +If two unitaries `U, V` on `n` qubits agree on conjugating every single-qubit `X` generator +(`U P_{Xᵢ} U† = V P_{Xᵢ} V†`) and every `Z` generator (likewise `Zᵢ`), then `U = c • V` for a unit +scalar `c` (`‖c‖ = 1`). The `2n` generators fix the whole conjugation action: the identity goes to +the identity (unitarity), each `Yᵢ = i Xᵢ Zᵢ` is forced by multiplicativity of conjugation +(`conj_mul_conj_of_conjTranspose_mul_self`, `pauliString_yGenPauli_eq_smul_mul`), and any Pauli +string is peeled wire by wire into single-wire generators (`pauliString_peel_wire`, by +`Finset.induction` on the support); `unitary_eq_smul_of_conj_pauliString_eq` then concludes. This is +the multi-qubit generalisation of `unitary_eq_smul_of_conj_singleQubit_XZ`, and it reduces the +inductive synthesis of Nielsen & Chuang Exercise 10.40 (parts 2–3) from matching the normalizer's +full signed permutation to matching it on the `2n` generators. -/ +theorem unitary_eq_smul_of_conj_generators + {U V : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) + (hV : V ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) + (hX : ∀ i, U * pauliString (xGenPauli i) * Uᴴ = V * pauliString (xGenPauli i) * Vᴴ) + (hZ : ∀ i, U * pauliString (zGenPauli i) * Uᴴ = V * pauliString (zGenPauli i) * Vᴴ) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • V := by + have hUUH : U * Uᴴ = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff.mp hU + have hVVH : V * Vᴴ = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff.mp hV + have hUHU : Uᴴ * U = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hU + have hVHV : Vᴴ * V = 1 := by simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hV + -- agreement on any single-wire Pauli, by cases on the wire's letter + have hsingle : ∀ (i : Fin n) (c : Fin 4), + U * pauliString (Function.update 0 i c) * Uᴴ + = V * pauliString (Function.update 0 i c) * Vᴴ := by + intro i c + -- `I` on wire `i` : the whole string is the identity + have hI : U * pauliString (Function.update (0 : Fin n → Fin 4) i (0 : Fin 4)) * Uᴴ + = V * pauliString (Function.update (0 : Fin n → Fin 4) i (0 : Fin 4)) * Vᴴ := by + have hs0 : pauliString (Function.update (0 : Fin n → Fin 4) i (0 : Fin 4)) = 1 := by + rw [pauliString_eq_one_iff] + funext k + rcases eq_or_ne k i with hk | hk + · subst hk; simp + · rw [Function.update_of_ne hk] + rw [hs0, Matrix.mul_one, Matrix.mul_one, hUUH, hVVH] + -- `Y` on wire `i`, through `Y = i X Z` and multiplicativity of conjugation + have hY : U * pauliString (yGenPauli i) * Uᴴ = V * pauliString (yGenPauli i) * Vᴴ := by + rw [pauliString_yGenPauli_eq_smul_mul, mul_smul_comm, smul_mul_assoc, mul_smul_comm, + smul_mul_assoc] + refine congrArg (_ • ·) ?_ + rw [← conj_mul_conj_of_conjTranspose_mul_self hUHU, + ← conj_mul_conj_of_conjTranspose_mul_self hVHV, hX i, hZ i] + fin_cases c + · exact hI + · exact hX i + · exact hY + · exact hZ i + -- agreement on every Pauli string, by induction on the support + have hall : ∀ a : Fin n → Fin 4, U * pauliString a * Uᴴ = V * pauliString a * Vᴴ := by + have hind : ∀ (s : Finset (Fin n)) (a : Fin n → Fin 4), + (∀ k, k ∉ s → a k = 0) → U * pauliString a * Uᴴ = V * pauliString a * Vᴴ := by + intro s + induction s using Finset.induction with + | empty => + intro a ha + have ha0 : a = 0 := by funext k; exact ha k (by simp) + subst ha0 + rw [(pauliString_eq_one_iff (0 : Fin n → Fin 4)).mpr rfl, Matrix.mul_one, Matrix.mul_one, + hUUH, hVVH] + | @insert i s' hi ih => + intro a ha + have ha' : ∀ k, k ∉ s' → Function.update a i 0 k = 0 := by + intro k hk + rcases eq_or_ne k i with hki | hki + · subst hki; simp + · rw [Function.update_of_ne hki] + exact ha k (by simp [Finset.mem_insert, hki, hk]) + have hIH := ih (Function.update a i 0) ha' + rw [pauliString_peel_wire a i, ← conj_mul_conj_of_conjTranspose_mul_self hUHU, hIH, + hsingle i (a i), conj_mul_conj_of_conjTranspose_mul_self hVHV] + intro a + exact hind Finset.univ a (fun k hk => absurd (Finset.mem_univ k) hk) + exact unitary_eq_smul_of_conj_pauliString_eq hU hV hall + +/-- **The converse of Theorem 10.6 reduces to matching a Clifford circuit on the generators.** If a +unitary `U` conjugates every generator `Xᵢ` and `Zᵢ` exactly as a Clifford circuit `C` does — +`U P_{Xᵢ} U† = C.sign (Xᵢ) • P_{C.act (Xᵢ)}` and likewise for `Zᵢ` — then `U` equals `C` up to a +unit global phase: `∃ c, ‖c‖ = 1 ∧ U = c • C.toMatrix`. Immediate from +`unitary_eq_smul_of_conj_generators` once `C`'s conjugation is folded back through +`CliffordCircuit.conj_pauliString`. This is the multi-qubit refinement of +`unitary_eq_smul_cliffordCircuit_of_conj_eq` (which matched on *all* Pauli strings): the inductive +synthesis of Nielsen & Chuang Exercise 10.40 (parts 2–3) need only reproduce the normalizer's action +on the `2n` generators. -/ +theorem unitary_eq_smul_cliffordCircuit_of_conj_generators + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ) (C : CliffordCircuit n) + (hX : ∀ i, U * pauliString (xGenPauli i) * Uᴴ + = CliffordCircuit.sign C (xGenPauli i) • pauliString (CliffordCircuit.act C (xGenPauli i))) + (hZ : ∀ i, U * pauliString (zGenPauli i) * Uᴴ + = CliffordCircuit.sign C (zGenPauli i) + • pauliString (CliffordCircuit.act C (zGenPauli i))) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C := by + have hCmem : CliffordCircuit.toMatrix C ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ := by + rw [mem_unitaryGroup_iff, star_eq_conjTranspose]; exact CliffordCircuit.mul_conjTranspose C + refine unitary_eq_smul_of_conj_generators hU hCmem (fun i => ?_) (fun i => ?_) + · rw [hX i, ← CliffordCircuit.conj_pauliString C (xGenPauli i)] + · rw [hZ i, ← CliffordCircuit.conj_pauliString C (zGenPauli i)] + +/-! ### Nielsen & Chuang Exercise 10.38 — the two-qubit specialisation + +Exercise 10.38 is the two-qubit (`n = 2`) case of `unitary_eq_smul_of_conj_generators`: the four +generators are `X₁ = xGenPauli 0`, `X₂ = xGenPauli 1` (Pauli `X` on wire `0`, resp. `1`) and +`Z₁ = zGenPauli 0`, `Z₂ = zGenPauli 1`. N&C phrase the conclusion as "`U = V`"; taken literally +this is *false* — conjugation is insensitive to a global phase, so `U` and `c • U` (`‖c‖ = 1`) +always act identically — and the honest statement is equality *up to a global phase*, exactly as +N&C's own Theorem 10.6 states one line later on the same page. +`exists_ne_unitary_conj_twoQubitGenerators_eq` records that the phase genuinely cannot be +dropped. -/ + +/-- **Nielsen & Chuang, Exercise 10.38.** Two unitaries `U, V` on two qubits that conjugate the four +generators `X₁ = X ⊗ I`, `X₂ = I ⊗ X`, `Z₁ = Z ⊗ I`, `Z₂ = I ⊗ Z` — i.e. `pauliString (xGenPauli i)` +and `pauliString (zGenPauli i)` for `i ∈ {0, 1}` — in the same way agree up to a global phase: +`U = c • V` for a unit scalar `c` (`‖c‖ = 1`). N&C write "`U = V`", but the global phase is +unavoidable (see `exists_ne_unitary_conj_twoQubitGenerators_eq`). This is the `n = 2` case of the +multi-qubit generator-determinacy lemma `unitary_eq_smul_of_conj_generators`: the four generators +`Z₁, Z₂, X₁, X₂` fix the whole conjugation action, because the `16` Pauli strings on two qubits are +products of them up to phase. -/ +theorem unitary_eq_smul_of_conj_twoQubitGenerators + {U V : Matrix (Fin 2 → Fin 2) (Fin 2 → Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2 → Fin 2) ℂ) + (hV : V ∈ Matrix.unitaryGroup (Fin 2 → Fin 2) ℂ) + (hX₁ : U * pauliString (xGenPauli 0) * Uᴴ = V * pauliString (xGenPauli 0) * Vᴴ) + (hX₂ : U * pauliString (xGenPauli 1) * Uᴴ = V * pauliString (xGenPauli 1) * Vᴴ) + (hZ₁ : U * pauliString (zGenPauli 0) * Uᴴ = V * pauliString (zGenPauli 0) * Vᴴ) + (hZ₂ : U * pauliString (zGenPauli 1) * Uᴴ = V * pauliString (zGenPauli 1) * Vᴴ) : + ∃ c : ℂ, ‖c‖ = 1 ∧ U = c • V := + unitary_eq_smul_of_conj_generators hU hV + (Fin.forall_fin_two.mpr ⟨hX₁, hX₂⟩) (Fin.forall_fin_two.mpr ⟨hZ₁, hZ₂⟩) + +/-- **The global phase in Exercise 10.38 is necessary.** N&C's literal "`U = V`" fails: the identity +`1` and its negation `-1` are two *distinct* two-qubit unitaries that conjugate every generator +(indeed every operator) identically, since conjugation by a global phase acts trivially. Hence the +conclusion of `unitary_eq_smul_of_conj_twoQubitGenerators` cannot be strengthened from `U = c • V` +to `U = V`. -/ +theorem exists_ne_unitary_conj_twoQubitGenerators_eq : + ∃ U V : Matrix (Fin 2 → Fin 2) (Fin 2 → Fin 2) ℂ, + U ∈ Matrix.unitaryGroup (Fin 2 → Fin 2) ℂ ∧ + V ∈ Matrix.unitaryGroup (Fin 2 → Fin 2) ℂ ∧ + U * pauliString (xGenPauli 0) * Uᴴ = V * pauliString (xGenPauli 0) * Vᴴ ∧ + U * pauliString (xGenPauli 1) * Uᴴ = V * pauliString (xGenPauli 1) * Vᴴ ∧ + U * pauliString (zGenPauli 0) * Uᴴ = V * pauliString (zGenPauli 0) * Vᴴ ∧ + U * pauliString (zGenPauli 1) * Uᴴ = V * pauliString (zGenPauli 1) * Vᴴ ∧ + U ≠ V := by + refine ⟨1, -1, Submonoid.one_mem _, ?mem, ?_, ?_, ?_, ?_, ?ne⟩ + case mem => rw [mem_unitaryGroup_iff, star_neg, star_one]; noncomm_ring + case ne => + intro h + have h00 := congrFun (congrFun h (fun _ => 0)) (fun _ => 0) + simp only [Matrix.one_apply_eq, Matrix.neg_apply] at h00 + norm_num at h00 + -- the four generator-conjugation goals are all `1 · P · 1ᴴ = -1 · P · (-1)ᴴ`, i.e. `P = P` + all_goals (rw [conjTranspose_one, conjTranspose_neg, conjTranspose_one]; noncomm_ring) + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerInduction.lean b/LeanPool/AxQM/Concrete/PauliNormalizerInduction.lean new file mode 100644 index 0000000000..90452d2530 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerInduction.lean @@ -0,0 +1,284 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerRestrictNormalizer +public import LeanPool.AxQM.Concrete.PauliNormalizerFirstPair +public import LeanPool.AxQM.Concrete.PauliNormalizerGenerators +public import LeanPool.AxQM.Concrete.CliffordCircuitInverse + +/-! +# Concrete: the multi-qubit inductive synthesis — every normalizer is a phase times a Clifford +circuit (N&C Theorem 10.6, converse; Exercise 10.40, Fig 10.9) + +This file completes the *existence* content of Nielsen & Chuang **Theorem 10.6** (the converse — +the normalizer `N(Gₙ)` is generated by Hadamard/phase/CNOT gates), stated over `2ⁿ × 2ⁿ` unitary +matrices. + +`isPauliNormalizer_eq_smul_cliffordCircuit` proves: *every* `n`-qubit Pauli normalizer `U` equals a +global phase times a Clifford circuit, `U = c • C.toMatrix` with `‖c‖ = 1`. This is the inductive +synthesis of Exercise 10.40, assembling the machinery of the earlier files. The `O(n²)` gate-count +bound of Theorem 10.6 is in `AxQM/Concrete/PauliNormalizerGateCountSynthesis.lean`. + +## The induction (Figure 10.9) + +Induction on the qubit count `n`, peeling the sub-register `{1, …, n}` off wire `0` at each step. + +* **Base `n = 0`.** The register `Fin 0 → Fin 2` is a singleton, so `U` is a `1×1` unitary — a + scalar `c` of modulus `1` — and the empty circuit has matrix `1`, giving `U = c • 1`. +* **Step `n + 1`.** Given the inductive hypothesis on `n`-qubit normalizers: + 1. `IsPauliNormalizer.exists_cliffordCircuit_fixFirstPair` produces a Clifford circuit `B` + with `M := B.toMatrix * U` again a normalizer that **fixes** `X₀` and `Z₀` under conjugation. + 2. `firstWireRestrict_isPauliNormalizer` packages the restriction + `M' := firstWireRestrict M` as a bona fide `n`-qubit normalizer. + 3. The inductive hypothesis gives an `n`-wire Clifford circuit `C'` and phase `c'` with + `M' = c' • C'.toMatrix`. + 4. `B' := C'.relabel ⟨Fin.succ, …⟩` embeds `C'` onto the last `n` wires. + 5. `M` and `B'` conjugate **every** generator identically + (`unitary_eq_smul_cliffordCircuit_of_conj_generators`): `X₀, Z₀` are fixed by both (`B'` never + touches wire `0`), and for `i = succ j` the + block-diagonal correspondence `M P_{cons 0 a} M† = I₂ ⊗ (M' P_a M'†)` matches `M`'s + action on the last-`n`-wire generators to `B'`'s. Hence `M = c • B'.toMatrix`, `‖c‖ = 1`. + 6. Left-cancelling `B` with its inverse (`CliffordCircuit.inverse`) gives + `U = c • (inverse B ++ B').toMatrix`. + +## What is proved + +Alongside the headline `isPauliNormalizer_eq_smul_cliffordCircuit`, the file records the small +reusable bridges the step needs: + +* `CliffordCircuit.act_const_zero` / `sign_const_zero` — a Clifford circuit fixes the identity Pauli + string (`act C 0 = 0`, `sign C 0 = 1`): conjugating `1 = P_0` gives `1` with phase `1`. +* `xGenPauli_zero_eq_cons` / `zGenPauli_zero_eq_cons` / `xGenPauli_succ_eq_cons` / + `zGenPauli_succ_eq_cons` — the standard generators as `Fin.cons` strings (`X₀ = cons 1 0`, + `Xᵢ₊₁ = cons 0 Xᵢ`, and the `Z` mirrors), so the wire-`0` head is exposed. +* `CliffordCircuit.relabelSucc_act_cons` / `relabelSucc_sign_cons` — the action and `±1` phase of a + circuit relabeled onto the last `n` wires, on a `Fin.cons` string: `(relabel succ C).act (cons a₀ + h) = cons a₀ (C.act h)` and `(relabel succ C).sign (cons a₀ h) = C.sign h`. Wire `0` is untouched; + the last `n` wires transform by `C` on the tail. +* `smul_conjTranspose_conj_cancel` — a unit global phase cancels in a conjugation: + `(c • V) P (c • V)† = V P V†` when `‖c‖ = 1`. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### A Clifford circuit fixes the identity Pauli string -/ + +/-- **A Clifford circuit fixes the identity string's index**: `act C 0 = 0`. Each elementary gate +sends the identity letter to itself (`hadamardPauli 0 = phasePauli 0 = 0`, and `cnotPauliString` +leaves an all-identity string fixed), so the fold does nothing. By induction on the gate list. -/ +theorem CliffordCircuit.act_const_zero (C : CliffordCircuit n) : + CliffordCircuit.act C (0 : Fin n → Fin 4) = 0 := by + induction C with + | nil => rfl + | cons γ C ih => + change γ.act (CliffordCircuit.act C (0 : Fin n → Fin 4)) = 0 + rw [ih] + cases γ with + | had j => simp [CliffordGate.act, hadamardPauli] + | phase j => simp [CliffordGate.act, phasePauli] + | cnot c t h => + change cnotPauliString (0 : Fin n → Fin 4) c t = 0 + funext k + by_cases hkc : k = c + · subst hkc; rw [cnotPauliString_ctrl]; rfl + · by_cases hkt : k = t + · subst hkt; rw [cnotPauliString_tgt _ h]; rfl + · rw [cnotPauliString_of_ne _ c t hkc hkt] + +/-- **A Clifford circuit acquires no phase conjugating the identity string**: `sign C 0 = 1`. Each +elementary gate's phase on the identity letter is `1` (`hadamardPauliSign 0 = phasePauliSign 0 = +cnotPauliSign 0 0 = 1`); the intermediate strings stay all-identity by `act_const_zero`. By +induction on the gate list. -/ +theorem CliffordCircuit.sign_const_zero (C : CliffordCircuit n) : + CliffordCircuit.sign C (0 : Fin n → Fin 4) = 1 := by + induction C with + | nil => rfl + | cons γ C ih => + change CliffordCircuit.sign C (0 : Fin n → Fin 4) + * γ.sign (CliffordCircuit.act C (0 : Fin n → Fin 4)) = 1 + rw [ih, CliffordCircuit.act_const_zero, one_mul] + cases γ with + | had j => simp [CliffordGate.sign, hadamardPauliSign] + | phase j => simp [CliffordGate.sign, phasePauliSign] + | cnot c t h => rfl + +/-! ### The standard generators as `Fin.cons` strings -/ + +/-- **`X₀ = cons 1 0`**: the first-wire `X` generator on `n+1` wires is `X` on wire `0` and identity +elsewhere. -/ +theorem xGenPauli_zero_eq_cons : + xGenPauli (0 : Fin (n + 1)) = Fin.cons (1 : Fin 4) (0 : Fin n → Fin 4) := by + funext k + refine Fin.cases ?_ ?_ k + · simp [xGenPauli] + · intro i; simp [xGenPauli, Fin.succ_ne_zero] + +/-- **`Z₀ = cons 3 0`**: the first-wire `Z` generator on `n+1` wires is `Z` on wire `0` and identity +elsewhere. -/ +theorem zGenPauli_zero_eq_cons : + zGenPauli (0 : Fin (n + 1)) = Fin.cons (3 : Fin 4) (0 : Fin n → Fin 4) := by + funext k + refine Fin.cases ?_ ?_ k + · simp [zGenPauli] + · intro i; simp [zGenPauli, Fin.succ_ne_zero] + +/-- **`Xᵢ₊₁ = cons 0 Xᵢ`**: the `X` generator on wire `succ i` is identity on wire `0` and the +`n`-wire `X` generator `Xᵢ` on the last `n` wires. -/ +theorem xGenPauli_succ_eq_cons (i : Fin n) : + xGenPauli (Fin.succ i) = Fin.cons (0 : Fin 4) (xGenPauli i) := by + funext k + refine Fin.cases ?_ ?_ k + · simp [xGenPauli, (Fin.succ_ne_zero i).symm] + · intro j; simp [xGenPauli_apply, Fin.cons_succ, (Fin.succ_injective n).eq_iff] + +/-- **`Zᵢ₊₁ = cons 0 Zᵢ`**: the `Z` generator on wire `succ i` is identity on wire `0` and the +`n`-wire `Z` generator `Zᵢ` on the last `n` wires. -/ +theorem zGenPauli_succ_eq_cons (i : Fin n) : + zGenPauli (Fin.succ i) = Fin.cons (0 : Fin 4) (zGenPauli i) := by + funext k + refine Fin.cases ?_ ?_ k + · simp [zGenPauli, (Fin.succ_ne_zero i).symm] + · intro j; simp [zGenPauli_apply, Fin.cons_succ, (Fin.succ_injective n).eq_iff] + +/-! ### A circuit relabeled onto the last `n` wires, on a `Fin.cons` string -/ + +/-- **The action of a circuit relabeled onto the last `n` wires, on a `Fin.cons` string**: +`(relabel ⟨Fin.succ,·⟩ C).act (cons a₀ h) = cons a₀ (C.act h)`. Wire `0` is outside the range of +`Fin.succ`, so it is left untouched (`act_relabel_of_forall_ne`); on the last `n` wires the +relabeled circuit acts as `C` on the tail `h` (`act_relabel_embed`, `Fin.cons_succ`). -/ +theorem CliffordCircuit.relabelSucc_act_cons (C : CliffordCircuit n) (a₀ : Fin 4) + (h : Fin n → Fin 4) : + CliffordCircuit.act (C.relabel ⟨Fin.succ, Fin.succ_injective n⟩) (Fin.cons a₀ h) + = Fin.cons a₀ (CliffordCircuit.act C h) := by + funext k + refine Fin.cases ?_ ?_ k + · rw [CliffordCircuit.act_relabel_of_forall_ne _ _ _ (fun i => Fin.succ_ne_zero i), + Fin.cons_zero, Fin.cons_zero] + · intro i + rw [Fin.cons_succ] + have h1 := CliffordCircuit.act_relabel_embed ⟨Fin.succ, Fin.succ_injective n⟩ C + (Fin.cons a₀ h) i + simp only [Function.Embedding.coeFn_mk, Fin.cons_succ] at h1 + exact h1 + +/-- **The `±1` phase of a circuit relabeled onto the last `n` wires, on a `Fin.cons` string**: +`(relabel ⟨Fin.succ,·⟩ C).sign (cons a₀ h) = C.sign h`. The phase pulls back along `Fin.succ` +(`sign_relabel`) to the tail `h` (`Fin.cons_succ`). -/ +theorem CliffordCircuit.relabelSucc_sign_cons (C : CliffordCircuit n) (a₀ : Fin 4) + (h : Fin n → Fin 4) : + CliffordCircuit.sign (C.relabel ⟨Fin.succ, Fin.succ_injective n⟩) (Fin.cons a₀ h) + = CliffordCircuit.sign C h := by + simp only [CliffordCircuit.sign_relabel, Function.Embedding.coeFn_mk, Fin.cons_succ] + +/-! ### A unit global phase cancels in a conjugation -/ + +/-- **A unit global phase cancels in a conjugation**: for `‖c‖ = 1`, `(c • V) P (c • V)† = V P V†`. +The scalars collect to `c * star c = ‖c‖² = 1`. -/ +theorem smul_conjTranspose_conj_cancel {c : ℂ} (hc : ‖c‖ = 1) + (V P : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + (c • V) * P * (c • V)ᴴ = V * P * Vᴴ := by + have hcc : c * star c = 1 := by simp [RCLike.mul_conj, hc] + rw [conjTranspose_smul, smul_mul_assoc, smul_mul_smul_comm, hcc, one_smul] + +/-! ### The inductive synthesis -/ + +/-- **Nielsen & Chuang, Theorem 10.6 (converse), the existence content.** Every `n`-qubit Pauli +normalizer `U` equals a global phase times a Clifford (`H`/`S`/`CNOT`) circuit: +`∃ C c, ‖c‖ = 1 ∧ U = c • C.toMatrix`. This is the multi-qubit inductive synthesis of Exercise +10.40 (Figure 10.9), assembled from the earlier files; the `O(n²)` gate-count bound and the headline +packaging are in `PauliNormalizerGateCountSynthesis.lean`. See the module docstring for the step +structure. -/ +theorem isPauliNormalizer_eq_smul_cliffordCircuit {n : ℕ} + {U : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hU : IsPauliNormalizer U) : + ∃ (C : CliffordCircuit n) (c : ℂ), ‖c‖ = 1 ∧ U = c • CliffordCircuit.toMatrix C := by + induction n with + | zero => + -- `Fin 0 → Fin 2` is a singleton: `U` is a `1×1` unitary, the empty circuit's matrix is `1`. + refine ⟨[], U default default, ?_, ?_⟩ + · have hUU : Uᴴ * U = 1 := by + have h := mem_unitaryGroup_iff'.mp hU.1 + rwa [star_eq_conjTranspose] at h + have h1 := congrFun (congrFun hUU default) default + simp only [Matrix.mul_apply, Matrix.one_apply_eq] at h1 + rw [Finset.sum_eq_single default] at h1 + · rw [Matrix.conjTranspose_apply] at h1 + have hnn : ‖U default default‖ * ‖U default default‖ = 1 := by + have := congrArg norm h1 + rwa [norm_mul, norm_star, norm_one] at this + nlinarith [norm_nonneg (U default default), hnn] + · intro b _ hb; exact absurd (Subsingleton.elim b default) hb + · intro h; exact absurd (Finset.mem_univ default) h + · funext i j + rw [Subsingleton.elim i default, Subsingleton.elim j default] + simp [CliffordCircuit.toMatrix, Matrix.one_apply_eq] + | succ n ih => + -- Step 1: reduce `U` to a normalizer `M = B U` fixing `X₀, Z₀`. + obtain ⟨B, hM, hMX, hMZ⟩ := hU.exists_cliffordCircuit_fixFirstPair + set M := B.toMatrix * U with hMdef + -- Step 2: the restriction `M' = firstWireRestrict M` is an `n`-qubit normalizer. + have hM' : IsPauliNormalizer (firstWireRestrict M) := + firstWireRestrict_isPauliNormalizer hM hMX hMZ + set M' := firstWireRestrict M with hM'def + -- Step 3: apply the inductive hypothesis to `M'`. + obtain ⟨C', c', hc', hC'eq⟩ := ih hM' + -- Step 4: embed `C'` onto the last `n` wires. + set B' := C'.relabel ⟨Fin.succ, Fin.succ_injective n⟩ with hB'def + -- Step 5: `M` matches `B'` on every generator, so `M = c • B'.toMatrix`. + -- The conjugation of `M'` on a phase-free string is exactly `C'`'s (phase cancels). + have hM'conj : ∀ g : Fin n → Fin 4, + M' * pauliString g * M'ᴴ + = CliffordCircuit.sign C' g • pauliString (CliffordCircuit.act C' g) := by + intro g + rw [hC'eq, smul_conjTranspose_conj_cancel hc', CliffordCircuit.conj_pauliString] + have hgenX : ∀ i, M * pauliString (xGenPauli i) * Mᴴ + = CliffordCircuit.sign B' (xGenPauli i) + • pauliString (CliffordCircuit.act B' (xGenPauli i)) := by + intro i + refine Fin.cases ?_ ?_ i + · -- `i = 0`: both fix `X₀`. + rw [hMX, xGenPauli_zero_eq_cons, hB'def, CliffordCircuit.relabelSucc_act_cons, + CliffordCircuit.relabelSucc_sign_cons, CliffordCircuit.act_const_zero, + CliffordCircuit.sign_const_zero, one_smul, ← xGenPauli_zero_eq_cons] + · -- `i = succ j`: match via the block-diagonal correspondence. + intro j + rw [xGenPauli_succ_eq_cons, hM.conj_pauliString_cons hMX hMZ, hM'conj, + embedLast_smul, ← pauliString_cons_zero, hB'def, + CliffordCircuit.relabelSucc_act_cons, CliffordCircuit.relabelSucc_sign_cons] + have hgenZ : ∀ i, M * pauliString (zGenPauli i) * Mᴴ + = CliffordCircuit.sign B' (zGenPauli i) + • pauliString (CliffordCircuit.act B' (zGenPauli i)) := by + intro i + refine Fin.cases ?_ ?_ i + · rw [hMZ, zGenPauli_zero_eq_cons, hB'def, CliffordCircuit.relabelSucc_act_cons, + CliffordCircuit.relabelSucc_sign_cons, CliffordCircuit.act_const_zero, + CliffordCircuit.sign_const_zero, one_smul, ← zGenPauli_zero_eq_cons] + · intro j + rw [zGenPauli_succ_eq_cons, hM.conj_pauliString_cons hMX hMZ, hM'conj, + embedLast_smul, ← pauliString_cons_zero, hB'def, + CliffordCircuit.relabelSucc_act_cons, CliffordCircuit.relabelSucc_sign_cons] + obtain ⟨c, hc, hMeq⟩ := + unitary_eq_smul_cliffordCircuit_of_conj_generators hM.1 B' hgenX hgenZ + -- Step 6: left-cancel `B` with its inverse. + refine ⟨B.inverse ++ B', c, hc, ?_⟩ + have hUeq : U = B.inverse.toMatrix * M := by + rw [hMdef, ← Matrix.mul_assoc, CliffordCircuit.toMatrix_inverse_mul, Matrix.one_mul] + rw [hUeq, hMeq, CliffordCircuit.toMatrix_append, Matrix.mul_smul] + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerLayer.lean b/LeanPool/AxQM/Concrete/PauliNormalizerLayer.lean new file mode 100644 index 0000000000..b52d08b73a --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerLayer.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerSweep + +/-! +# Concrete: the single-qubit Clifford layer on an `n`-qubit register + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The per-wire atom `CliffordCircuit.onWire j C₀` runs one single-wire Clifford on a +single chosen wire. The Gottesman tableau sweep that synthesises a Clifford circuit realising a +normalizer's signed permutation begins by rotating *every* wire's Pauli letter simultaneously — a +**single-qubit layer**: one (independently chosen) single-wire Clifford applied to each wire at +once. This file provides that combinator and its clean characterisation, by concatenating the +per-wire `onWire` circuits over `List.finRange n`. + +## What is proved + +* `CliffordCircuit.layerOn f L` — run the single-wire circuit `f i` on wire `i` for each `i` in a + wire list `L` (folding the per-wire `onWire i (f i)` circuits). `CliffordCircuit.singleQubitLayer` + is the whole-register instance `layerOn f (List.finRange n)`. + +* `CliffordCircuit.singleQubitLayer_act` — **the layer acts wire-by-wire independently**: + `(singleQubitLayer f).act g i = (f i).act (fun _ => g i) 0`. Each wire `i`'s output letter is + `f i`'s single-wire action on `g`'s letter at wire `i`, unaffected by the other wires. + +* `CliffordCircuit.singleQubitLayer_sign` — **its `±1` phase is the product of the per-wire + phases**: `(singleQubitLayer f).sign g = ∏ i, (f i).sign (fun _ => g i)`. + +* `exists_singleQubitLayer_act_diagX` — **step 1 of the sweep: rotate a Pauli string to all-`X`**. + For any Pauli string `a`, a single-qubit layer sends it to the string carrying `X` on every wire + of `a`'s support and `I` elsewhere (`act (singleQubitLayer f) a k = if a k = 0 then 0 else 1`). + Because the witness is returned as the per-wire family `f`, the layer's effect on *every other* + string is simultaneously available through `singleQubitLayer_act` — exactly what the multi-qubit + induction needs to track a second generator's image while diagonalising the first. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +namespace CliffordCircuit + +/-! ### Running one single-qubit circuit per wire -/ + +/-- **Run the single-wire circuit `f i` on wire `i`, for every `i` in the wire list `L`.** +Concatenation (`++`) of the per-wire circuits `onWire i (f i)`; the whole-register layer is the +`L = List.finRange n` instance (`singleQubitLayer`). -/ +def layerOn (f : Fin n → CliffordCircuit 1) : List (Fin n) → CliffordCircuit n + | [] => [] + | i :: L => onWire i (f i) ++ layerOn f L + +@[simp] +theorem layerOn_nil (f : Fin n → CliffordCircuit 1) : layerOn f [] = [] := rfl + +theorem layerOn_cons (f : Fin n → CliffordCircuit 1) (i : Fin n) (L : List (Fin n)) : + layerOn f (i :: L) = onWire i (f i) ++ layerOn f L := rfl + +/-- **`layerOn f L` leaves every wire outside `L` untouched**: for `k ∉ L`, +`(layerOn f L).act g k = g k`. Each `onWire i (f i)` in the fold touches only wire `i ∈ L`. -/ +theorem layerOn_act_of_not_mem (f : Fin n → CliffordCircuit 1) (g : Fin n → Fin 4) {k : Fin n} : + ∀ {L : List (Fin n)}, k ∉ L → act (layerOn f L) g k = g k := by + intro L hk + induction L with + | nil => rfl + | cons i L ih => + rw [List.mem_cons, not_or] at hk + rw [layerOn_cons, act_append, onWire_act_of_ne _ _ _ hk.1, ih hk.2] + +/-- **On a wire `k ∈ L` (with `L` duplicate-free) the layer acts as `f k` on that wire's letter**: +`(layerOn f L).act g k = (f k).act (fun _ => g k) 0`. The `onWire k (f k)` factor supplies wire +`k`'s transformation, and every other factor (a distinct wire) leaves wire `k` fixed. -/ +theorem layerOn_act_of_mem (f : Fin n → CliffordCircuit 1) (g : Fin n → Fin 4) {k : Fin n} + {L : List (Fin n)} (hk : k ∈ L) (hL : L.Nodup) : + act (layerOn f L) g k = act (f k) (fun _ => g k) 0 := by + induction L with + | nil => simp at hk + | cons i L ih => + rw [List.nodup_cons] at hL + rw [layerOn_cons, act_append] + rcases List.mem_cons.1 hk with h | h + · subst h + rw [onWire_act, layerOn_act_of_not_mem f g hL.1] + · rw [onWire_act_of_ne _ _ _ (by rintro rfl; exact hL.1 h), ih h hL.2] + +/-- **The layer's `±1` phase is the product of the per-wire phases** (for a duplicate-free `L`): +`(layerOn f L).sign g = (L.map fun i => (f i).sign (fun _ => g i)).prod`. Each `onWire i (f i)` +contributes `(f i).sign` read at wire `i`'s letter (`onWire_sign`), and — the earlier factors acting +on distinct wires — that letter is still `g i` (`layerOn_act_of_not_mem`). -/ +theorem layerOn_sign (f : Fin n → CliffordCircuit 1) (g : Fin n → Fin 4) {L : List (Fin n)} + (hL : L.Nodup) : sign (layerOn f L) g = (L.map fun i => sign (f i) (fun _ => g i)).prod := by + induction L with + | nil => rfl + | cons i L ih => + rw [List.nodup_cons] at hL + rw [layerOn_cons, sign_append, onWire_sign, layerOn_act_of_not_mem f g hL.1, ih hL.2, + List.map_cons, List.prod_cons] + ring + +/-! ### The whole-register single-qubit layer -/ + +/-- **The single-qubit layer**: apply the single-wire circuit `f i` to wire `i`, for every wire `i` +of the `n`-qubit register (`layerOn f (List.finRange n)`). The first move of the Exercise 10.40 +tableau sweep — rotating each wire's Pauli letter independently. -/ +def singleQubitLayer (f : Fin n → CliffordCircuit 1) : CliffordCircuit n := + layerOn f (List.finRange n) + +/-- **The single-qubit layer acts wire-by-wire independently**: +`(singleQubitLayer f).act g i = (f i).act (fun _ => g i) 0`. Wire `i`'s output letter depends only +on `f i` and `g`'s letter at wire `i`. -/ +theorem singleQubitLayer_act (f : Fin n → CliffordCircuit 1) (g : Fin n → Fin 4) (i : Fin n) : + act (singleQubitLayer f) g i = act (f i) (fun _ => g i) 0 := + layerOn_act_of_mem f g (by simp) (List.nodup_finRange n) + +/-- **The single-qubit layer's `±1` phase is the product of the per-wire phases**: +`(singleQubitLayer f).sign g = ∏ i, (f i).sign (fun _ => g i)`. -/ +theorem singleQubitLayer_sign (f : Fin n → CliffordCircuit 1) (g : Fin n → Fin 4) : + sign (singleQubitLayer f) g = ∏ i, sign (f i) (fun _ => g i) := by + rw [singleQubitLayer, layerOn_sign f g (List.nodup_finRange n), ← List.ofFn_eq_map, + List.prod_ofFn] + +/-! ### Rotating a single Pauli letter to `X` -/ + +/-- **A single-wire Clifford rotating the letter `c` to `X`.** `X` needs no gate; `S` sends `Y ↦ X` +(`phasePauli`); `H` sends `Z ↦ X` (`hadamardPauli`). The identity `I` (`c = 0`) is left as `I`. -/ +def rotateToX (c : Fin 4) : CliffordCircuit 1 := + if c = 2 then [CliffordGate.phase 0] else if c = 3 then [CliffordGate.had 0] else [] + +/-- **`rotateToX c` sends the letter `c` to `X`** (and fixes `I`): `(rotateToX c).act (fun _ => c) 0 += if c = 0 then 0 else 1`. Verified by cases on `c` (`decide` on the computable single-wire +action). -/ +theorem rotateToX_act (c : Fin 4) : + act (rotateToX c) (fun _ => c) 0 = if c = 0 then 0 else 1 := by + fin_cases c <;> decide + +end CliffordCircuit + +/-! ### Step 1 of the sweep: diagonalise a Pauli string to all-`X` -/ + +/-- **First move of the Exercise 10.40 tableau sweep: rotate a Pauli string to all-`X`.** For any +Pauli string `a : Fin n → Fin 4` there is a single-qubit family `f` whose layer sends `a` to the +string carrying `X` on every wire of `a`'s support and `I` elsewhere: +`(singleQubitLayer f).act a k = if a k = 0 then 0 else 1`. Take `f k = rotateToX (a k)` on each +wire and apply `singleQubitLayer_act` and `rotateToX_act`. + +The witness is returned as the *per-wire family* `f` rather than the assembled circuit, so a caller +can read off the same layer's effect on any *other* Pauli string through +`CliffordCircuit.singleQubitLayer_act` — precisely what the multi-qubit induction needs to follow a +second generator's image (`U Z₁ U†`) while this step diagonalises the first (`U X₁ U†`). -/ +theorem exists_singleQubitLayer_act_diagX (a : Fin n → Fin 4) : + ∃ f : Fin n → CliffordCircuit 1, ∀ k, + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = if a k = 0 then 0 else 1 := by + refine ⟨fun k => CliffordCircuit.rotateToX (a k), fun k => ?_⟩ + rw [CliffordCircuit.singleQubitLayer_act] + exact CliffordCircuit.rotateToX_act (a k) + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerPairReduce.lean b/LeanPool/AxQM/Concrete/PauliNormalizerPairReduce.lean new file mode 100644 index 0000000000..649a859140 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerPairReduce.lean @@ -0,0 +1,317 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerSymplectic + +/-! +# Concrete: the first-qubit reduction — bring an anticommuting pair to standard `(X_c, Z_c)` + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The symplectic *first move* (`exists_cliffordCircuit_reduceFirstOfPair`) takes an +anticommuting pair of Pauli strings `p, q` (the images `U X₁ U†`, `U Z₁ U†` of a normalizer) and +reduces `p` to a standard `X_c` while leaving the partner image `q' = act C q` still anticommuting +with `X_c` (`q'_c ∈ {Y, Z}`). *This file completes the first-qubit reduction*: a second Clifford +circuit reduces `q'` to the standard `Z_c` **while fixing `X_c`**, bringing the pair to the +canonical `(X_c, Z_c)` on a common pivot wire — precisely N&C's Exercise 10.40 part-2 opening +("since `Z₁` and `X₁` anticommute, `U Z₁ U†` and `U X₁ U†` anticommute", then reduce them together). + +## The `X_c`-preserving `Z`-sweep + +The generic `Z`-reduction `exists_cliffordCircuit_reduceToZGen` does **not** preserve `X_c`: +its diagonalising layer touches wire `c` when `q'_c = Y` (via `rotateToZ Y = H S`), and its sign +correction is a `Z_c`-conjugation (`X ↦ -X`). Both disturb `X_c`. So the sweep is rebuilt to fix +`X_c`: + +* **Diagonalise (`X_c`-preserving).** A custom single-qubit layer rotates every wire's letter of + `q'` to `Z`, but on the pivot wire `c` it uses `rotateToZFixingX` — the identity when `q'_c = Z`, + and `H S H` (which fixes `X` and swaps `Y ↔ Z`) when `q'_c = Y`. The pivot gate therefore fixes + `X` on wire `c`; every other wire's gate touches only that wire, so `X_c` (identity off `c`) is + untouched. +* **CNOT-clear (`X_c`-preserving).** The reverse CNOT fan `cnotFanInto c ts` (controls `ts`, target + `c`) collapses the all-`Z` image to `Z_c`. Each `CNOT_{t→c}` (`t ≠ c`) leaves `X_c` fixed: an `X` + on the *target* wire `c` is preserved by CNOT (`cnotTgtPauli 0 1 = 1`, `cnotCtrlPauli 0 1 = 0`), + since only an `X` on the *control* spreads (`act_cnotFanInto_xGenPauli`). + +Both moves are proved **at the index level only** — no `±1` sign is tracked for the `Z`-sweep. The +overall `±1` phases are corrected at the very end of the pair reduction by two single-wire `onWire` +gadgets, chosen from `exists_cliffordCircuit_onWire_act_sign`: one flips the sign of `X_c` +while fixing `Z_c` (correcting `p`'s phase), the other flips the sign of `Z_c` while fixing `X_c` +(correcting `q`'s phase). Deferring all sign bookkeeping to these two independent gadgets keeps the +sweep purely combinatorial. + +## Results + +* `CliffordCircuit.rotateToZFixingX` (+ `_act_self`, `_act_one`) and + `CliffordCircuit.rotateToZ_act_zero` — the single-wire pieces of the `X_c`-preserving + diagonalisation. +* `act_cnotFanInto_xGenPauli` — the reverse CNOT fan fixes `X_c` (`c ∉ ts`). +* `exists_cnotFanInto_toSingleZ_fixingX` — the CNOT-clear collapsing an all-`Z` string to `Z_c` + while fixing `X_c`. +* `exists_cliffordCircuit_reduceSecondFixingX` — **the `X_c`-preserving `Z`-reduction**: for `q` + with `q c ∈ {Y, Z}`, a Clifford circuit `D` with `act D q = zGenPauli c` and + `act D (xGenPauli c) = xGenPauli c` (letters only; signs unconstrained). +* `exists_cliffordCircuit_reducePair` — **the first-qubit reduction (the main result).** For an + anticommuting pair `p, q` (`Odd (pauliAnticommCount p q)`), a Clifford circuit `E` and a pivot + wire `c` reducing the pair to the canonical generators *exactly*: `act E p = xGenPauli c`, + `sign E p = 1`, `act E q = zGenPauli c`, `sign E q = 1`. + +Fed the `2n` generator images of a normalizer, `reducePair` handles the first anticommuting pair; +the `n+1`-qubit inductive step of Figure 10.9 then completes the converse via +`unitary_eq_smul_cliffordCircuit_of_conj_generators`. + +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +namespace CliffordCircuit + +/-! ### A single-wire Clifford rotating a letter to `Z` while fixing `X` -/ + +/-- **A single-wire Clifford rotating the letter `a` to `Z` while fixing `X`.** For `a = Z` no gate +is needed (`Z ↦ Z`, `X ↦ X`); for `a = Y` the word `H S H` fixes `X` (`X ↦ Z ↦ Z ↦ X`) and swaps +`Y ↔ Z` (`Y ↦ Y ↦ X ↦ Z`), so it sends `Y ↦ Z` while preserving `X`. (The `a ∈ {I, X}` cases are +unused: this gate is applied only on the pivot wire, whose letter is `Y` or `Z`.) Unlike +`rotateToZ`, which sends `Y` to `Z` via `H S` and therefore moves `X`, this variant keeps `X` fixed +— the pivot gate of the `X_c`-preserving diagonalisation. -/ +def rotateToZFixingX (a : Fin 4) : CliffordCircuit 1 := + if a = 2 then [CliffordGate.had 0, CliffordGate.phase 0, CliffordGate.had 0] else [] + +/-- `rotateToZFixingX a` sends its own letter `a ∈ {Y, Z}` to `Z`: +`act (rotateToZFixingX a) (fun _ => a) 0 = 3`. (`Z`: identity; `Y`: `H S H` swaps `Y ↔ Z`.) -/ +theorem rotateToZFixingX_act_self {a : Fin 4} (ha : a = 2 ∨ a = 3) : + act (rotateToZFixingX a) (fun _ => a) 0 = 3 := by + rcases ha with rfl | rfl <;> decide + +/-- `rotateToZFixingX a` fixes the letter `X`: `act (rotateToZFixingX a) (fun _ => 1) 0 = 1`. Both +the identity (`a ≠ Y`) and `H S H` (`a = Y`) fix `X`. -/ +theorem rotateToZFixingX_act_one (a : Fin 4) : + act (rotateToZFixingX a) (fun _ => (1 : Fin 4)) 0 = 1 := by + rw [rotateToZFixingX]; split <;> decide + +/-- Any `rotateToZ` gate fixes the identity letter: `act (rotateToZ a) (fun _ => 0) 0 = 0`. Used off +the pivot wire, where `X_c` carries the identity and the diagonalising layer must leave it fixed. -/ +theorem rotateToZ_act_zero (a : Fin 4) : + act (rotateToZ a) (fun _ => (0 : Fin 4)) 0 = 0 := by + fin_cases a <;> decide + +end CliffordCircuit + +/-! ### The reverse CNOT fan fixes a standard `X` generator on its collector wire -/ + +/-- **The reverse CNOT fan into `c` fixes `X_c`** (for `c ∉ ts`): +`act (cnotFanInto c ts) (xGenPauli c) = xGenPauli c`. Each `CNOT_{t→c}` in the fan (control +`t ≠ c`, target `c`) sees the identity on its control (`X_c` is `I` off `c`) and `X` on its target +`c`; an `X` on a CNOT *target* is preserved (`cnotTgtPauli 0 1 = 1`, `cnotCtrlPauli 0 1 = 0`) — only +an `X` on the control spreads. An induction on `ts` via `act_cnotFanInto_cons_of_ne`. This is why +the `Z`-collapse fan, whose CNOTs all target the pivot `c`, leaves `X_c` untouched. -/ +theorem act_cnotFanInto_xGenPauli (c : Fin n) : + ∀ (ts : List (Fin n)), c ∉ ts → + CliffordCircuit.act (cnotFanInto c ts) (xGenPauli c) = xGenPauli c + | [], _ => by rw [cnotFanInto_nil]; rfl + | t :: ts, hc => by + rw [List.mem_cons, not_or] at hc + obtain ⟨hct, hcts⟩ := hc + have htc : t ≠ c := Ne.symm hct + rw [act_cnotFanInto_cons_of_ne htc ts (xGenPauli c), + act_cnotFanInto_xGenPauli c ts hcts] + have ht0 : xGenPauli c t = 0 := by rw [xGenPauli_apply, ite_eq_right htc] + have hc1 : xGenPauli c c = 1 := by rw [xGenPauli_apply, ite_eq_left rfl] + funext k + by_cases hkt : k = t + · rw [hkt, cnotPauliString_ctrl, ht0, hc1]; decide + · by_cases hkc : k = c + · rw [hkc, cnotPauliString_tgt _ htc, ht0, hc1]; decide + · rw [cnotPauliString_of_ne _ t c hkt hkc] + +/-- **CNOT-clear to a single `Z` generator, fixing `X_c`.** For an all-`Z` Pauli string `a` +(`∀ k, a k = 0 ∨ a k = 3`) with a pivot wire `c` in its support (`a c = 3`), the reverse CNOT fan +`cnotFanInto c ts` (controls the rest of `a`'s support) collapses `a` to `zGenPauli c` *and* fixes +`X_c`: `act C a = zGenPauli c` and `act C (xGenPauli c) = xGenPauli c`. The collapse is +`act_cnotFanInto_collapse`; the `X_c`-preservation is `act_cnotFanInto_xGenPauli`. This strengthens +`exists_cliffordCircuit_cnotClear_toSingleZ` with the `X_c`-fixing property the pair reduction +needs; signs are not tracked (corrected later in the construction). -/ +theorem exists_cnotFanInto_toSingleZ_fixingX (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 3) (hZ : ∀ k, a k = 0 ∨ a k = 3) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ + CliffordCircuit.act C (xGenPauli c) = xGenPauli c := by + set ts := (Finset.univ.filter (fun k => a k = 3 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 3 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 3 := fun t ht => ((hmem t).mp ht).1 + refine ⟨cnotFanInto c ts, ?_, act_cnotFanInto_xGenPauli c ts hcnotin⟩ + funext k + rw [act_cnotFanInto_collapse c ts hcnotin hnd a hc hall k, zGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk3 : a k = 3 + · rw [ite_eq_left ((hmem k).mpr ⟨hk3, hkc⟩)] + · rw [ite_eq_right (fun h => hk3 ((hmem k).mp h).1)] + exact (hZ k).resolve_right hk3 + +/-! ### The `X_c`-preserving `Z`-reduction of the partner image -/ + +/-- **Reduce a Pauli string to a standard `Z` generator while fixing `X_c`.** For a Pauli string `q` +with a `Z` factor on wire `c` (`q c ∈ {Y, Z}`, i.e. `q` anticommutes with `X_c`), there is a +Clifford circuit `D` collapsing `q` to the standard `Z_c` *and* fixing `X_c` on the index level: +`act D q = zGenPauli c` and `act D (xGenPauli c) = xGenPauli c`. (Signs are not tracked — they are +corrected by the final gadgets of `exists_cliffordCircuit_reducePair`.) + +Construction: an `X_c`-preserving diagonalising layer `L` (the pivot gate `rotateToZFixingX (q c)` +fixes `X` and sends `q c ↦ Z`; every other wire's `rotateToZ (q k)` fixes the identity of `X_c`) +sends `q` to an all-`Z` string with pivot `c`, and fixes `X_c`; then +`exists_cnotFanInto_toSingleZ_fixingX` collapses that all-`Z` image to `Z_c` while again fixing +`X_c`. This is the second, `X_c`-preserving move of the Exercise 10.40 first-qubit reduction (the +partner of the `X`-reduction move `exists_cliffordCircuit_reduceToXGen`). -/ +theorem exists_cliffordCircuit_reduceSecondFixingX (q : Fin n → Fin 4) (c : Fin n) + (hq : q c = 2 ∨ q c = 3) : + ∃ D : CliffordCircuit n, + CliffordCircuit.act D q = zGenPauli c ∧ + CliffordCircuit.act D (xGenPauli c) = xGenPauli c := by + -- the `X_c`-preserving diagonalising family: on the pivot wire `c` a gate fixing `X` and + -- sending `q c ↦ Z`; on every other wire the plain `rotateToZ` + set f : Fin n → CliffordCircuit 1 := + Function.update (fun k => CliffordCircuit.rotateToZ (q k)) c + (CliffordCircuit.rotateToZFixingX (q c)) with hf + set L := CliffordCircuit.singleQubitLayer f with hL + -- the layer diagonalises `q` to an all-`Z` string with pivot `c` + have hLqc : CliffordCircuit.act L q c = 3 := by + rw [hL, CliffordCircuit.singleQubitLayer_act, hf, Function.update_self] + exact CliffordCircuit.rotateToZFixingX_act_self hq + have hLqZ : ∀ k, CliffordCircuit.act L q k = 0 ∨ CliffordCircuit.act L q k = 3 := by + intro k + rw [hL, CliffordCircuit.singleQubitLayer_act, hf] + by_cases hkc : k = c + · rw [hkc, Function.update_self] + exact Or.inr (CliffordCircuit.rotateToZFixingX_act_self hq) + · simp only [Function.update_of_ne hkc, CliffordCircuit.rotateToZ_act] + split + · exact Or.inl rfl + · exact Or.inr rfl + -- the layer fixes `X_c` (letters) + have hLx : CliffordCircuit.act L (xGenPauli c) = xGenPauli c := by + funext k + rw [hL, CliffordCircuit.singleQubitLayer_act, hf] + by_cases hkc : k = c + · rw [hkc, Function.update_self, xGenPauli_apply, ite_eq_left rfl] + exact CliffordCircuit.rotateToZFixingX_act_one _ + · simp only [Function.update_of_ne hkc, xGenPauli_apply, ite_eq_right hkc] + exact CliffordCircuit.rotateToZ_act_zero _ + -- collapse the all-`Z` image to `Z_c`, keeping `X_c` fixed + obtain ⟨K, hKq, hKx⟩ := + exists_cnotFanInto_toSingleZ_fixingX (CliffordCircuit.act L q) c hLqc hLqZ + refine ⟨K ++ L, ?_, ?_⟩ + · rw [CliffordCircuit.act_append]; exact hKq + · rw [CliffordCircuit.act_append, hLx]; exact hKx + +/-! ### Sign normalisation of a reduced pair -/ + +/-- **Normalise the signs of a reduced pair to `+1`.** Given a Clifford circuit `E` already sending +`p ↦ X_c` and `q ↦ Z_c` at the index level (`act E p = xGenPauli c`, `act E q = zGenPauli c`), two +single-wire `onWire` gadgets pin the two independent residual `±1` phases to `+1`: one flips +`X_c`'s sign while fixing `Z_c`, the other flips `Z_c`'s sign while fixing `X_c`. Acting on disjoint +generators, each correction leaves the other pair member's exact reduction intact. The input signs +are unconstrained — the lemma works for any circuit that reduces the pair on the index level — so it +is reused per pair by the `n+1`-qubit inductive step (Figure 10.9). -/ +theorem exists_cliffordCircuit_fixPairSigns (E : CliffordCircuit n) (c : Fin n) + {p q : Fin n → Fin 4} (hp : CliffordCircuit.act E p = xGenPauli c) + (hq : CliffordCircuit.act E q = zGenPauli c) : + ∃ E' : CliffordCircuit n, CliffordCircuit.act E' p = xGenPauli c ∧ + CliffordCircuit.sign E' p = 1 ∧ CliffordCircuit.act E' q = zGenPauli c ∧ + CliffordCircuit.sign E' q = 1 := by + -- correct `p`'s sign with an `X_c`-sign-flip gadget (fixing `Z_c`) if needed + obtain ⟨E1, hE1p, hE1q, hE1ps, hE1qs⟩ : + ∃ E1 : CliffordCircuit n, CliffordCircuit.act E1 p = xGenPauli c ∧ + CliffordCircuit.act E1 q = zGenPauli c ∧ + CliffordCircuit.sign E1 p = 1 ∧ CliffordCircuit.sign E1 q = CliffordCircuit.sign E q := by + rcases CliffordCircuit.sign_eq_one_or_neg_one E p with hs | hs + · exact ⟨E, hp, hq, hs, rfl⟩ + · obtain ⟨A, hAx, hAxs, hAz, hAzs, -⟩ := + exists_cliffordCircuit_onWire_act_sign c (aX := 1) (aZ := 3) (zX := -1) (zZ := 1) + (by decide) (by decide) (by decide) (Or.inr rfl) (Or.inl rfl) + refine ⟨A ++ E, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hp]; exact hAx + · rw [CliffordCircuit.act_append, hq]; exact hAz + · rw [CliffordCircuit.sign_append, hp, hs, hAxs]; norm_num + · rw [CliffordCircuit.sign_append, hq, hAzs, mul_one] + -- correct `q`'s sign with a `Z_c`-sign-flip gadget (fixing `X_c`) if needed + rcases CliffordCircuit.sign_eq_one_or_neg_one E1 q with hs | hs + · exact ⟨E1, hE1p, hE1ps, hE1q, hs⟩ + · obtain ⟨B, hBx, hBxs, hBz, hBzs, -⟩ := + exists_cliffordCircuit_onWire_act_sign c (aX := 1) (aZ := 3) (zX := 1) (zZ := -1) + (by decide) (by decide) (by decide) (Or.inl rfl) (Or.inr rfl) + refine ⟨B ++ E1, ?_, ?_, ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hE1p]; exact hBx + · rw [CliffordCircuit.sign_append, hE1p, hE1ps, hBxs]; norm_num + · rw [CliffordCircuit.act_append, hE1q]; exact hBz + · rw [CliffordCircuit.sign_append, hE1q, hs, hBzs]; norm_num + +/-! ### The first-qubit reduction: an anticommuting pair to standard `(X_c, Z_c)` -/ + +/-- **The first-qubit reduction of an anticommuting pair (Nielsen & Chuang Exercise 10.40).** For an +anticommuting pair of Pauli strings `p, q` (`Odd (pauliAnticommCount p q)` — the images `U X₁ U†`, +`U Z₁ U†` of a normalizer), there is a Clifford circuit `E` and a pivot wire `c` reducing the pair +to the canonical single-qubit generators on `c` *exactly*: + +* `act E p = xGenPauli c` and `sign E p = 1`; +* `act E q = zGenPauli c` and `sign E q = 1`. + +Construction, a three-move composition: + +1. The symplectic first move (`exists_cliffordCircuit_reduceFirstOfPair`) gives a circuit `C` + with `act C p = X_c`, `sign C p = 1`, and `act C q` still anticommuting with `X_c` + (`(act C q) c ∈ {Y, Z}`). +2. The `X_c`-preserving `Z`-reduction (`exists_cliffordCircuit_reduceSecondFixingX`) gives `D` + collapsing `act C q` to `Z_c` while fixing `X_c` on the index level; so the composite `D ++ C` + realises `p ↦ X_c`, `q ↦ Z_c` on the index level, up to two independent `±1` phases. +3. `exists_cliffordCircuit_fixPairSigns` pins those two phases to `+1` with a pair of disjoint + `onWire` sign gadgets. + +This is the first-qubit reduction that opens N&C's Exercise 10.40 parts 2–3: it brings a +normalizer's first anticommuting generator pair to the standard `(X_c, Z_c)`, the base of the +multi-qubit induction (Figure 10.9). -/ +theorem exists_cliffordCircuit_reducePair (p q : Fin n → Fin 4) + (hpq : Odd (pauliAnticommCount p q)) : + ∃ (E : CliffordCircuit n) (c : Fin n), + CliffordCircuit.act E p = xGenPauli c ∧ CliffordCircuit.sign E p = 1 ∧ + CliffordCircuit.act E q = zGenPauli c ∧ CliffordCircuit.sign E q = 1 := by + obtain ⟨C, c, hCp, _hCps, hCqc⟩ := exists_cliffordCircuit_reduceFirstOfPair p q hpq + obtain ⟨D, hDq, hDx⟩ := + exists_cliffordCircuit_reduceSecondFixingX (CliffordCircuit.act C q) c hCqc + -- the base composite reduces the pair to `(X_c, Z_c)` on the index level, + -- up to unknown `±1` signs + set E0 := D ++ C with hE0 + have hE0p : CliffordCircuit.act E0 p = xGenPauli c := by + rw [hE0, CliffordCircuit.act_append, hCp]; exact hDx + have hE0q : CliffordCircuit.act E0 q = zGenPauli c := by + rw [hE0, CliffordCircuit.act_append]; exact hDq + -- pin the two residual ±1 phases to +1 + obtain ⟨E, hEp, hEps, hEq, hEqs⟩ := exists_cliffordCircuit_fixPairSigns E0 c hE0p hE0q + exact ⟨E, c, hEp, hEps, hEq, hEqs⟩ + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerReduceGenerator.lean b/LeanPool/AxQM/Concrete/PauliNormalizerReduceGenerator.lean new file mode 100644 index 0000000000..eca21c25fe --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerReduceGenerator.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerZClear + +/-! +# Concrete: exact single-generator reduction — collapse any Pauli string to a standard `X_c`/`Z_c` + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The Gottesman tableau sweep reduces a normalizer's image of a generator, `U X₁ U†` (a signed Pauli +string), to a *standard single-qubit generator*. The two component moves are: + +* **diagonalise** to an all-`X` (resp. all-`Z`) string — a single-qubit layer + (`exists_singleQubitLayer_act_diagX` / `…diagZ`); +* **CNOT-clear** that all-`X`/`Z` string down to a single generator on a chosen pivot wire `c` + (`exists_cliffordCircuit_cnotClear_toSingleX` / `…toSingleZ`). + +*This file assembles the two into an exact reduction, with the residual `±1` phase corrected.* The +diagonalisation move is phase-free on the *index* level but the assembled circuit carries some `±1` +sign; a single sign-flip gadget on the pivot wire pins it to `+1`. The results: + +* `exists_cliffordCircuit_reduceToXGen` — for any Pauli string `a` and any pivot `c` in its support + (`a c ≠ 0`), a Clifford circuit `C` with `C a C† = X_c` **exactly** (`act C a = xGenPauli c`, + `sign C a = 1`). +* `exists_cliffordCircuit_reduceToZGen` — the `Z`-basis mirror (`act C a = zGenPauli c`, + `sign C a = 1`). + +## Design notes + +*The pivot is a parameter.* A caller reducing a non-identity image `U X₁ U†` picks any wire in its +support as the pivot; the pivot is then moved (with a wire swap if needed) to be wire `1`, the first +move of Exercise 10.40's first-qubit reduction. + +*Sign correction without computing the layer's phase.* Rather than track the diagonalising layer's +`±1` phase through `rotateToX`/`rotateToZ` (a per-wire computation), we assemble +`cnotClear ++ layer`, observe that its overall phase on `a` is `±1` +(`CliffordCircuit.sign_eq_one_or_neg_one`), and, in the `-1` case, prepend a sign-flip gadget on the +pivot wire. The gadget (`exists_cliffordCircuit_xGen_signFlip` / `…zGen_signFlip`) is the +specialised `onWire` synthesis: a single-wire Clifford that fixes the generator's index but +negates its phase (`Z_c` conjugation negates `X_c`; `X_c` conjugation negates `Z_c`). + +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Sign-flip gadgets on a single wire -/ + +/-- **A Clifford circuit negating the phase of `X_c` while fixing its index** (and fixing `Z_c`): +`act C (xGenPauli c) = xGenPauli c` and `sign C (xGenPauli c) = -1`. It is the single-wire +`onWire` synthesis (`exists_cliffordCircuit_onWire_act_sign`) on wire `c` sending `X ↦ -X`, +`Z ↦ +Z` — concretely a `Z_c` conjugation (`Z X Z = -X`). Used to correct the residual `-1` phase +after the diagonalise-then-clear reduction to `X_c`. -/ +theorem exists_cliffordCircuit_xGen_signFlip (c : Fin n) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (xGenPauli c) = xGenPauli c ∧ + CliffordCircuit.sign C (xGenPauli c) = -1 := by + obtain ⟨C, hact, hsign, -, -, -⟩ := + exists_cliffordCircuit_onWire_act_sign c (aX := 1) (aZ := 3) (zX := -1) (zZ := 1) + (by decide) (by decide) (by decide) (Or.inr rfl) (Or.inl rfl) + exact ⟨C, hact, hsign⟩ + +/-- **A Clifford circuit negating the phase of `Z_c` while fixing its index** (and fixing `X_c`): +`act C (zGenPauli c) = zGenPauli c` and `sign C (zGenPauli c) = -1`. The `Z`-basis mirror of +`exists_cliffordCircuit_xGen_signFlip`: the `onWire` synthesis on wire `c` sending `X ↦ +X`, +`Z ↦ -Z` — concretely an `X_c` conjugation (`X Z X = -Z`). -/ +theorem exists_cliffordCircuit_zGen_signFlip (c : Fin n) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (zGenPauli c) = zGenPauli c ∧ + CliffordCircuit.sign C (zGenPauli c) = -1 := by + obtain ⟨C, -, -, hact, hsign, -⟩ := + exists_cliffordCircuit_onWire_act_sign c (aX := 1) (aZ := 3) (zX := 1) (zZ := -1) + (by decide) (by decide) (by decide) (Or.inl rfl) (Or.inr rfl) + exact ⟨C, hact, hsign⟩ + +/-! ### Exact reduction to a standard `X` generator -/ + +/-- **Exact reduction to a standard `X` generator (assembling the `X`-sweep).** For any Pauli string +`a : Fin n → Fin 4` and any pivot wire `c` in its support (`a c ≠ 0`), there is a Clifford circuit +`C` collapsing `a` to the single `X` generator on wire `c` *exactly*: `act C a = xGenPauli c` and +`sign C a = 1`. + +Construction: diagonalise `a` to its all-`X`-on-support form via a single-qubit layer `L` +(`exists_singleQubitLayer_act_diagX`) — the pivot `c` survives (`act L a c = 1`, from `a c ≠ 0`) — +then CNOT-clear that all-`X` string to `X_c` with trivial phase +(`exists_cliffordCircuit_cnotClear_toSingleX`). +The composite `K ++ L` already realises `a ↦ X_c` on the index; its overall phase on `a` equals the +layer's phase (the clearing is phase-free), which is `±1`. Prepending the sign-flip gadget +`exists_cliffordCircuit_xGen_signFlip` in the `-1` case corrects the phase to `+1`. This reduces a +normalizer's generator image `U X₁ U†` to the standard `X_c`, the first move of the Exercise 10.40 +first-qubit reduction. -/ +theorem exists_cliffordCircuit_reduceToXGen (a : Fin n → Fin 4) (c : Fin n) (hc : a c ≠ 0) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = xGenPauli c ∧ CliffordCircuit.sign C a = 1 := by + obtain ⟨f, hf⟩ := exists_singleQubitLayer_act_diagX a + have ha'c : CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a c = 1 := by + rw [hf c, ite_eq_right hc] + have ha'X : ∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 0 ∨ + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 1 := by + intro k; rw [hf k]; split + · exact Or.inl rfl + · exact Or.inr rfl + obtain ⟨K, hKact, hKsign⟩ := + exists_cliffordCircuit_cnotClear_toSingleX + (CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a) c ha'c ha'X + set L := CliffordCircuit.singleQubitLayer f with hLdef + have hrest_act : CliffordCircuit.act (K ++ L) a = xGenPauli c := by + rw [CliffordCircuit.act_append]; exact hKact + have hrest_sign : CliffordCircuit.sign (K ++ L) a = CliffordCircuit.sign L a := by + rw [CliffordCircuit.sign_append, hKsign, mul_one] + rcases CliffordCircuit.sign_eq_one_or_neg_one L a with hs | hs + · exact ⟨K ++ L, hrest_act, by rw [hrest_sign]; exact hs⟩ + · obtain ⟨D, hDact, hDsign⟩ := exists_cliffordCircuit_xGen_signFlip c + refine ⟨D ++ (K ++ L), ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hrest_act, hDact] + · rw [CliffordCircuit.sign_append, hrest_sign, hs, hrest_act, hDsign]; norm_num + +/-! ### Exact reduction to a standard `Z` generator -/ + +/-- **Exact reduction to a standard `Z` generator (assembling the `Z`-sweep).** For any Pauli string +`a : Fin n → Fin 4` and any pivot wire `c` in its support (`a c ≠ 0`), there is a Clifford circuit +`C` collapsing `a` to the single `Z` generator on wire `c` *exactly*: `act C a = zGenPauli c` and +`sign C a = 1`. The `Z`-basis mirror of `exists_cliffordCircuit_reduceToXGen`: diagonalise to +all-`Z` (`exists_singleQubitLayer_act_diagZ`), reverse-CNOT-clear to `Z_c` +(`exists_cliffordCircuit_cnotClear_toSingleZ`), and correct the residual phase with +`exists_cliffordCircuit_zGen_signFlip`. This reduces a normalizer's second generator image +`U Z₁ U†` to the standard `Z_c`. -/ +theorem exists_cliffordCircuit_reduceToZGen (a : Fin n → Fin 4) (c : Fin n) (hc : a c ≠ 0) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ CliffordCircuit.sign C a = 1 := by + obtain ⟨f, hf⟩ := exists_singleQubitLayer_act_diagZ a + have ha'c : CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a c = 3 := by + rw [hf c, ite_eq_right hc] + have ha'Z : ∀ k, CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 0 ∨ + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = 3 := by + intro k; rw [hf k]; split + · exact Or.inl rfl + · exact Or.inr rfl + obtain ⟨K, hKact, hKsign⟩ := + exists_cliffordCircuit_cnotClear_toSingleZ + (CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a) c ha'c ha'Z + set L := CliffordCircuit.singleQubitLayer f with hLdef + have hrest_act : CliffordCircuit.act (K ++ L) a = zGenPauli c := by + rw [CliffordCircuit.act_append]; exact hKact + have hrest_sign : CliffordCircuit.sign (K ++ L) a = CliffordCircuit.sign L a := by + rw [CliffordCircuit.sign_append, hKsign, mul_one] + rcases CliffordCircuit.sign_eq_one_or_neg_one L a with hs | hs + · exact ⟨K ++ L, hrest_act, by rw [hrest_sign]; exact hs⟩ + · obtain ⟨D, hDact, hDsign⟩ := exists_cliffordCircuit_zGen_signFlip c + refine ⟨D ++ (K ++ L), ?_, ?_⟩ + · rw [CliffordCircuit.act_append, hrest_act, hDact] + · rw [CliffordCircuit.sign_append, hrest_sign, hs, hrest_act, hDsign]; norm_num + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerRestrict.lean b/LeanPool/AxQM/Concrete/PauliNormalizerRestrict.lean new file mode 100644 index 0000000000..3fd8178867 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerRestrict.lean @@ -0,0 +1,380 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGenerators + +/-! +# Concrete: restricting a wire-`0`-fixing Pauli normalizer to the last `n` wires (Fig 10.9, part 2) + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, **Exercise 10.40**) toward the multi-qubit inductive synthesis (parts +2–3, Figure 10.9). + +After the first-wire reduction and pivot-wire decoupling, the inductive step needs +to *recurse* onto the last `n` wires. The datum it recurses on is an `n`-qubit unitary obtained by +**restricting** the `(n+1)`-qubit normalizer to the sub-register `{1, …, n}`. This file supplies +that restriction and the linear-algebraic fact that makes it well-behaved: a unitary that **fixes +the first-wire generators** `X₀` and `Z₀` under conjugation is a genuine *tensor product* +`I₂ ⊗ M'` — it acts as the identity on wire `0` and as an `n`-qubit unitary `M'` on the rest. + +The mechanism is elementary matrix algebra with the sparse structure of `X₀` and `Z₀`. Fixing `X₀` +and `Z₀` up to conjugation is, for a unitary, the same as *commuting* with `X₀` and `Z₀`. `Z₀` is +diagonal with a `±1` split according to the wire-`0` bit, so commuting with it kills every matrix +entry mixing the two wire-`0` sectors (`i₀ ≠ j₀`). `X₀` is the wire-`0` bit-flip permutation, so +commuting with it identifies the two diagonal sectors. Together these say the matrix is +block-scalar, `I₂ ⊗ M'`. + +## What is proved + +* `embedLast` — the **block-scalar embedding** `I₂ ⊗ X` of an `n`-qubit matrix `X` onto the last + `n` of `n+1` wires (identity on wire `0`), with its algebra: `embedLast_mul`, `embedLast_one`, + `embedLast_conjTranspose`, and injectivity. This is the tensor-with-identity functor whose image + is exactly the operators fixing wire `0`. +* `firstWireRestrict` — the **restriction** `M'` of an `(n+1)`-qubit matrix to the last `n` wires, + the `M'` of a factorisation `M = I₂ ⊗ M'`. +* `pauliString_zGenPauli_zero_eq_diagonal` / `pauliString_xGenPauli_zero_apply` — the sparse entry + structure of `Z₀` (diagonal, `±1` by the wire-`0` bit) and `X₀` (the wire-`0` bit-flip + permutation matrix), the two facts the factorisation reads off. +* `eq_embedLast_firstWireRestrict` — **the factorisation.** A unitary `M` fixing `X₀` and `Z₀` + under conjugation equals `embedLast (firstWireRestrict M) = I₂ ⊗ M'`. This is Figure 10.9's + "restrict to the last `n` wires": the inductive step's recursion target. +* `firstWireRestrict_mem_unitaryGroup` — the restriction `M'` is again **unitary**, so it is a + bona fide `n`-qubit operator the inductive hypothesis can consume. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The block-scalar embedding `I₂ ⊗ X` -/ + +/-- **Block-scalar embedding `I₂ ⊗ X`.** Given an `n`-qubit matrix `X` (index type +`Fin n → Fin 2`), `embedLast X` is the `(n+1)`-qubit matrix acting as the identity on wire `0` and +as `X` on the last `n` wires: its `(i, j)` entry is `X (Fin.tail i) (Fin.tail j)` when the wire-`0` +bits agree (`i 0 = j 0`) and `0` otherwise. This is the tensor product `I₂ ⊗ X`. -/ +def embedLast (X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ := + fun i j => if i 0 = j 0 then X (Fin.tail i) (Fin.tail j) else 0 + +@[simp] theorem embedLast_apply (X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + (i j : Fin (n + 1) → Fin 2) : + embedLast X i j = if i 0 = j 0 then X (Fin.tail i) (Fin.tail j) else 0 := rfl + +/-- The `embedLast` entry on `Fin.cons`-form indices: `embedLast X (cons s a) (cons t b)` is +`X a b` when `s = t` and `0` otherwise. -/ +theorem embedLast_cons (X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) (s t : Fin 2) + (a b : Fin n → Fin 2) : + embedLast X (Fin.cons s a) (Fin.cons t b) = if s = t then X a b else 0 := by + simp only [embedLast_apply, Fin.cons_zero, Fin.tail_cons] + +/-- **`embedLast` is injective.** Reading off the wire-`0`-trivial block recovers `X`. -/ +theorem embedLast_injective : + Function.Injective (embedLast : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ → _) := by + intro X Y h + ext a b + have hcons := congrFun (congrFun h (Fin.cons 0 a)) (Fin.cons 0 b) + rwa [embedLast_cons, embedLast_cons, ite_eq_left rfl, ite_eq_left rfl] at hcons + +/-- **`embedLast 1 = 1`.** `I₂ ⊗ I = I`. -/ +@[simp] theorem embedLast_one : + embedLast (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) = 1 := by + ext i j + simp only [embedLast_apply, Matrix.one_apply] + by_cases hij : i = j + · subst hij; simp + · rw [ite_eq_right hij] + split_ifs with h0 htail + · exact absurd (by rw [← Fin.cons_self_tail i, ← Fin.cons_self_tail j, h0, htail]) hij + · rfl + · rfl + +/-- **`embedLast` respects the conjugate transpose**: `(I₂ ⊗ X)ᴴ = I₂ ⊗ Xᴴ`. -/ +@[simp] theorem embedLast_conjTranspose (X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + (embedLast X)ᴴ = embedLast Xᴴ := by + ext i j + rw [Matrix.conjTranspose_apply, embedLast_apply, embedLast_apply, Matrix.conjTranspose_apply] + by_cases h0 : i 0 = j 0 + · rw [ite_eq_left h0, ite_eq_left h0.symm] + · rw [ite_eq_right h0, ite_eq_right (fun h => h0 h.symm), star_zero] + +/-- **Split a sum over `(n+1)`-bit strings into wire `0` and the tail.** -/ +theorem sum_consFirst_split (f : (Fin (n + 1) → Fin 2) → ℂ) : + ∑ k, f k = ∑ s : Fin 2, ∑ c : Fin n → Fin 2, f (Fin.cons s c) := by + have h1 : ∑ k, f k = ∑ p : Fin 2 × (Fin n → Fin 2), f (Fin.cons p.1 p.2) := + (Equiv.sum_comp (Fin.consEquiv (fun _ => Fin 2)) f).symm + rw [h1, Fintype.sum_prod_type] + +/-- **`embedLast` is multiplicative**: `(I₂ ⊗ X)(I₂ ⊗ Y) = I₂ ⊗ (XY)`. -/ +theorem embedLast_mul (X Y : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + embedLast X * embedLast Y = embedLast (X * Y) := by + ext i j + rw [embedLast_apply, Matrix.mul_apply, sum_consFirst_split] + simp only [embedLast_apply, Fin.cons_zero, Fin.tail_cons] + by_cases h0 : i 0 = j 0 + · rw [ite_eq_left h0, Matrix.mul_apply, Finset.sum_eq_single (i 0)] + · simp [h0] + · intro s _ hs + exact Finset.sum_eq_zero fun c _ => by rw [ite_eq_right (Ne.symm hs), zero_mul] + · intro h; exact absurd (Finset.mem_univ _) h + · rw [ite_eq_right h0] + refine Finset.sum_eq_zero fun s _ => Finset.sum_eq_zero fun c _ => ?_ + by_cases hs1 : i 0 = s + · rw [ite_eq_right (fun h : s = j 0 => h0 (hs1.trans h)), mul_zero] + · rw [ite_eq_right hs1, zero_mul] + +/-! ### The restriction `M'` -/ + +/-- **Restriction to the last `n` wires.** For an `(n+1)`-qubit matrix `M`, `firstWireRestrict M` is +the `n`-qubit matrix whose `(a, b)` entry is `M (cons 0 a) (cons 0 b)` — the wire-`0`-trivial block +of `M`. When `M = I₂ ⊗ M'`, this recovers `M'`. -/ +def firstWireRestrict (M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + fun a b => M (Fin.cons 0 a) (Fin.cons 0 b) + +@[simp] theorem firstWireRestrict_apply + (M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ) (a b : Fin n → Fin 2) : + firstWireRestrict M a b = M (Fin.cons 0 a) (Fin.cons 0 b) := rfl + +/-! ### Helper facts on `Fin 2`, single Pauli entries, and the wire-`0` split -/ + +/-- In `Fin 2`, every element is `0` or `1`. -/ +theorem fin2_zero_or_one (x : Fin 2) : x = 0 ∨ x = 1 := by fin_cases x <;> decide + +/-- In `Fin 2`, `x + 1 ≠ x`. -/ +theorem fin2_add_one_ne (x : Fin 2) : x + 1 ≠ x := by fin_cases x <;> decide + +/-- In `Fin 2`, `x + 1 + 1 = x`. -/ +theorem fin2_add_one_add_one (x : Fin 2) : x + 1 + 1 = x := by fin_cases x <;> rfl + +/-- In `Fin 2`, `a ≠ b` forces `a = b + 1`. -/ +theorem fin2_eq_add_one_of_ne {a b : Fin 2} (h : a ≠ b) : a = b + 1 := by + fin_cases a <;> fin_cases b <;> revert h <;> decide + +/-- Entry form of `pauliZ`: diagonal, `+1`/`-1` by the bit. -/ +theorem pauliZ_apply' (a b : Fin 2) : + pauliZ a b = if a = b then (if a = 0 then (1 : ℂ) else -1) else 0 := by + fin_cases a <;> fin_cases b <;> simp [pauliZ] + +/-- Entry form of `pauliX`: the bit-flip permutation, `1` off the diagonal. -/ +theorem pauliX_apply' (a b : Fin 2) : pauliX a b = if a = b then (0 : ℂ) else 1 := by + fin_cases a <;> fin_cases b <;> simp [pauliX] + +/-- **Two `(n+1)`-bit strings agree iff their wire-`0` bits and tails agree.** -/ +theorem funMap_eq_iff (i j : Fin (n + 1) → Fin 2) : + i = j ↔ i 0 = j 0 ∧ Fin.tail i = Fin.tail j := by + constructor + · rintro rfl; exact ⟨rfl, rfl⟩ + · rintro ⟨h0, ht⟩; rw [← Fin.cons_self_tail i, ← Fin.cons_self_tail j, h0, ht] + +/-- **The tail product of identity factors** is `1` when the tails agree, `0` otherwise. -/ +theorem prod_pauli_zero_tail (i j : Fin (n + 1) → Fin 2) (g : Fin (n + 1) → Fin 4) + (hg : ∀ k : Fin n, g k.succ = 0) : + (∏ k : Fin n, pauli (g k.succ) (i k.succ) (j k.succ)) + = if Fin.tail i = Fin.tail j then (1 : ℂ) else 0 := by + have hstep : ∀ k : Fin n, pauli (g k.succ) (i k.succ) (j k.succ) + = if i k.succ = j k.succ then (1 : ℂ) else 0 := by + intro k; rw [hg k, show pauli (0 : Fin 4) = 1 from rfl, Matrix.one_apply] + by_cases ht : Fin.tail i = Fin.tail j + · rw [ite_eq_left ht] + exact Finset.prod_eq_one fun k _ => by + rw [hstep k, ite_eq_left (show i k.succ = j k.succ from congrFun ht k)] + · rw [ite_eq_right ht] + obtain ⟨k, hk⟩ : ∃ k : Fin n, i k.succ ≠ j k.succ := by + by_contra hc + simp only [not_exists, not_ne_iff] at hc + exact ht (funext hc) + exact Finset.prod_eq_zero (Finset.mem_univ k) (by rw [hstep k, ite_eq_right hk]) + +/-- The wire-`0` **bit-flip** on an `(n+1)`-bit string: flips wire `0`, keeps the rest. It is the +permutation `X₀` acts by, and an involution. -/ +def flipFirst (i : Fin (n + 1) → Fin 2) : Fin (n + 1) → Fin 2 := + Fin.cons (i 0 + 1) (Fin.tail i) + +@[simp] theorem flipFirst_apply_zero (i : Fin (n + 1) → Fin 2) : flipFirst i 0 = i 0 + 1 := by + rw [flipFirst, Fin.cons_zero] + +@[simp] theorem tail_flipFirst (i : Fin (n + 1) → Fin 2) : Fin.tail (flipFirst i) = Fin.tail i := by + rw [flipFirst, Fin.tail_cons] + +@[simp] theorem flipFirst_flipFirst (i : Fin (n + 1) → Fin 2) : flipFirst (flipFirst i) = i := by + rw [funMap_eq_iff, flipFirst_apply_zero, tail_flipFirst, tail_flipFirst, flipFirst_apply_zero] + exact ⟨fin2_add_one_add_one (i 0), rfl⟩ + +/-- `a = flipFirst b` is symmetric under swapping `a, b` (the flip is an involution). -/ +theorem eq_flipFirst_comm (a b : Fin (n + 1) → Fin 2) : (a = flipFirst b) ↔ (b = flipFirst a) := by + constructor <;> intro h <;> rw [h, flipFirst_flipFirst] + +/-- `i = flipFirst j` exactly when the wire-`0` bit flips and the tails agree. -/ +theorem eq_flipFirst_iff (i j : Fin (n + 1) → Fin 2) : + i = flipFirst j ↔ i 0 = j 0 + 1 ∧ Fin.tail i = Fin.tail j := by + rw [funMap_eq_iff, flipFirst_apply_zero, tail_flipFirst] + +/-- When the wire-`0` bit is `0`, `cons 0 (tail x)` reconstructs `x`. -/ +theorem cons_zero_tail_of_apply_zero {x : Fin (n + 1) → Fin 2} (hx : x 0 = 0) : + Fin.cons (0 : Fin 2) (Fin.tail x) = x := by rw [← hx]; exact Fin.cons_self_tail x + +/-- When the wire-`0` bit is `1`, `cons 0 (tail x)` is the bit-flip `flipFirst x`. -/ +theorem cons_zero_tail_of_apply_one {x : Fin (n + 1) → Fin 2} (hx : x 0 = 1) : + Fin.cons (0 : Fin 2) (Fin.tail x) = flipFirst x := by + have hxx : x 0 + 1 = 0 := by simp [hx] + unfold flipFirst + rw [hxx] + +/-! ### Sparse entry structure of `Z₀` and `X₀` -/ + +/-- **`Z₀` is diagonal.** The Pauli string `Z` on wire `0` (identity elsewhere) is the diagonal +matrix whose `i`-th entry is `+1` when the wire-`0` bit is `0` and `-1` when it is `1`. -/ +theorem pauliString_zGenPauli_zero_eq_diagonal : + pauliString (zGenPauli (0 : Fin (n + 1))) + = Matrix.diagonal (fun i => if i 0 = 0 then (1 : ℂ) else -1) := by + ext i j + rw [pauliString_apply, Fin.prod_univ_succ, Matrix.diagonal_apply, + prod_pauli_zero_tail i j (zGenPauli 0) + (fun k => by rw [zGenPauli_apply, ite_eq_right (Fin.succ_ne_zero k)]), + zGenPauli_apply, ite_eq_left rfl, show pauli (3 : Fin 4) = pauliZ from rfl, pauliZ_apply'] + by_cases hij : i = j + · rw [ite_eq_left hij] + obtain ⟨h0, ht⟩ := (funMap_eq_iff i j).mp hij + rw [ite_eq_left h0, ite_eq_left ht, mul_one] + · rw [ite_eq_right hij] + by_cases ht : Fin.tail i = Fin.tail j + · rw [ite_eq_left ht, mul_one] + by_cases h0 : i 0 = j 0 + · exact absurd ((funMap_eq_iff i j).mpr ⟨h0, ht⟩) hij + · rw [ite_eq_right h0] + · rw [ite_eq_right ht, mul_zero] + +/-- **`X₀` is the wire-`0` bit-flip permutation matrix.** The Pauli string `X` on wire `0` (identity +elsewhere) has `(i, j)` entry `1` exactly when `i` is `j` with its wire-`0` bit flipped. -/ +theorem pauliString_xGenPauli_zero_apply (i j : Fin (n + 1) → Fin 2) : + pauliString (xGenPauli (0 : Fin (n + 1))) i j = if i = flipFirst j then (1 : ℂ) else 0 := by + rw [pauliString_apply, Fin.prod_univ_succ, + prod_pauli_zero_tail i j (xGenPauli 0) + (fun k => by rw [xGenPauli_apply, ite_eq_right (Fin.succ_ne_zero k)]), + xGenPauli_apply, ite_eq_left rfl, show pauli (1 : Fin 4) = pauliX from rfl, pauliX_apply'] + by_cases hf : i = flipFirst j + · obtain ⟨h0, ht⟩ := (eq_flipFirst_iff i j).mp hf + rw [ite_eq_left hf, ite_eq_left ht, mul_one, + ite_eq_right (fun he => fin2_add_one_ne (j 0) (h0 ▸ he))] + · rw [ite_eq_right hf] + by_cases ht : Fin.tail i = Fin.tail j + · rw [ite_eq_left ht, mul_one] + by_cases h0 : i 0 = j 0 + · rw [ite_eq_left h0] + · exact absurd ((eq_flipFirst_iff i j).mpr ⟨fin2_eq_add_one_of_ne h0, ht⟩) hf + · rw [ite_eq_right ht, mul_zero] + +/-! ### The factorisation -/ + +/-- **The tensor factorisation `M = I₂ ⊗ M'` (Figure 10.9, restriction to the last `n` wires).** +A unitary `M` on `n+1` qubits that **fixes the first-wire generators** `X₀` and `Z₀` under +conjugation (`M X₀ M† = X₀`, `M Z₀ M† = Z₀` — the output of the first-wire reduction) equals +`embedLast (firstWireRestrict M) = I₂ ⊗ M'`: it acts as the identity on wire `0` and as the +`n`-qubit restriction `M'` on the rest. + +Fixing `X₀`, `Z₀` up to conjugation is, for a unitary (`Mᴴ M = 1`), the same as commuting with +`X₀`, `Z₀`. `Z₀` is diagonal with a `±1` split by the wire-`0` bit +(`pauliString_zGenPauli_zero_eq_diagonal`), so commuting with it forces every entry with `i 0 ≠ j 0` +to vanish. `X₀` is the wire-`0` bit-flip permutation +(`pauliString_xGenPauli_zero_apply`), so commuting with it gives `M i j = M (flipFirst i) +(flipFirst j)`, identifying the two diagonal sectors. Together these are exactly the block-scalar +form `I₂ ⊗ M'`. -/ +theorem eq_embedLast_firstWireRestrict + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} + (hM : M ∈ Matrix.unitaryGroup (Fin (n + 1) → Fin 2) ℂ) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) : + M = embedLast (firstWireRestrict M) := by + have hMHM : Mᴴ * M = 1 := by + simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hM + -- fixing up to conjugation ↔ commuting, for a unitary + have hcomm : ∀ g : Fin (n + 1) → Fin 4, + M * pauliString g * Mᴴ = pauliString g → M * pauliString g = pauliString g * M := by + intro g hg + have h2 : M * pauliString g * Mᴴ * M = pauliString g * M := by rw [hg] + rwa [Matrix.mul_assoc (M * pauliString g) Mᴴ M, hMHM, Matrix.mul_one] at h2 + have hcommZ := hcomm _ hZ + have hcommX := hcomm _ hX + -- Z₀-consequence: entries mixing the two wire-0 sectors vanish + have hzero : ∀ i j : Fin (n + 1) → Fin 2, i 0 ≠ j 0 → M i j = 0 := by + intro i j hij + have h := congrFun (congrFun hcommZ i) j + rw [pauliString_zGenPauli_zero_eq_diagonal, Matrix.mul_diagonal, Matrix.diagonal_mul] at h + have hdine : + (if j 0 = 0 then (1 : ℂ) else -1) - (if i 0 = 0 then (1 : ℂ) else -1) ≠ 0 := by + rcases fin2_zero_or_one (i 0) with hi | hi <;> rcases fin2_zero_or_one (j 0) with hj | hj + · exact absurd (hi.trans hj.symm) hij + · rw [hi, hj]; norm_num + · rw [hi, hj]; norm_num + · exact absurd (hi.trans hj.symm) hij + have hz2 : M i j * + ((if j 0 = 0 then (1 : ℂ) else -1) - (if i 0 = 0 then (1 : ℂ) else -1)) = 0 := by + linear_combination h + rcases mul_eq_zero.mp hz2 with h1 | h1 + · exact h1 + · exact absurd h1 hdine + -- X₀-consequence: the two diagonal sectors are identified + have hswap : ∀ a b : Fin (n + 1) → Fin 2, M a (flipFirst b) = M (flipFirst a) b := by + intro a b + have h := congrFun (congrFun hcommX a) b + rw [Matrix.mul_apply, Matrix.mul_apply] at h + simp only [pauliString_xGenPauli_zero_apply, mul_ite, mul_one, mul_zero, ite_mul, + one_mul, zero_mul] at h + have hcongr : (∑ k, if a = flipFirst k then M k b else 0) + = ∑ k, if k = flipFirst a then M k b else 0 := + Finset.sum_congr rfl fun k _ => if_congr (eq_flipFirst_comm a k) rfl rfl + rw [Finset.sum_ite_eq' Finset.univ (flipFirst b) (fun k => M a k), hcongr, + Finset.sum_ite_eq' Finset.univ (flipFirst a) (fun k => M k b)] at h + simpa using h + have hflip : ∀ i j : Fin (n + 1) → Fin 2, M i j = M (flipFirst i) (flipFirst j) := by + intro i j + have h := hswap i (flipFirst j) + rwa [flipFirst_flipFirst] at h + -- assemble the block-scalar form + ext i j + rw [embedLast_apply] + simp only [firstWireRestrict_apply] + by_cases h0 : i 0 = j 0 + · rw [ite_eq_left h0] + rcases eq_or_ne (i 0) 0 with hi0 | hi0 + · rw [cons_zero_tail_of_apply_zero hi0, cons_zero_tail_of_apply_zero (h0 ▸ hi0)] + · have hi1 : i 0 = 1 := (fin2_eq_add_one_of_ne hi0).trans (by decide) + rw [cons_zero_tail_of_apply_one hi1, cons_zero_tail_of_apply_one (h0 ▸ hi1), ← hflip] + · rw [ite_eq_right h0, hzero i j h0] + +/-- **The restriction is unitary.** The `M'` of the factorisation `M = I₂ ⊗ M'` (for `M` a unitary +fixing `X₀, Z₀`) is again a unitary, so it is a bona fide `n`-qubit operator the inductive +hypothesis can consume. From `M = embedLast M'` and `Mᴴ M = 1`: `embedLast (M'ᴴ M') = Mᴴ M = 1 = +embedLast 1`, and `embedLast` is injective. -/ +theorem firstWireRestrict_mem_unitaryGroup + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} + (hM : M ∈ Matrix.unitaryGroup (Fin (n + 1) → Fin 2) ℂ) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) : + firstWireRestrict M ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ := by + have hfac := eq_embedLast_firstWireRestrict hM hX hZ + have hMHM : Mᴴ * M = 1 := by + simpa [star_eq_conjTranspose] using mem_unitaryGroup_iff'.mp hM + have key : embedLast ((firstWireRestrict M)ᴴ * firstWireRestrict M) = embedLast 1 := by + rw [← embedLast_mul, ← embedLast_conjTranspose, ← hfac, embedLast_one, hMHM] + have h1 : (firstWireRestrict M)ᴴ * firstWireRestrict M = 1 := embedLast_injective key + rw [mem_unitaryGroup_iff', star_eq_conjTranspose] + exact h1 + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerRestrictNormalizer.lean b/LeanPool/AxQM/Concrete/PauliNormalizerRestrictNormalizer.lean new file mode 100644 index 0000000000..56339314a3 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerRestrictNormalizer.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerRestrict +public import LeanPool.AxQM.Concrete.PauliNormalizerDecouple + +/-! +# Concrete: the wire-`0` restriction of a normalizer is an `n`-qubit normalizer (Fig 10.9, part 2) + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, **Exercise 10.40**) toward the multi-qubit inductive synthesis (Figure +10.9, part 2). + +`AxQM/Concrete/PauliNormalizerRestrict.lean` showed that a unitary `M` on `n+1` +qubits fixing the first-wire generators `X₀` and `Z₀` under conjugation is a genuine tensor product +`M = I₂ ⊗ M'`, with `M' = firstWireRestrict M` an `n`-qubit unitary. The inductive step now needs +`M'` to be a bona fide **`n`-qubit Pauli normalizer**, so the induction can recurse onto the +sub-register `{1, …, n}` and apply the inductive hypothesis to `M'`. + +That is what this file supplies. The key algebraic fact is that `M`'s conjugation action on a Pauli +string trivial on wire `0` **block-diagonalises**: `M · P_{cons 0 a} · M† = I₂ ⊗ (M' · P_a · M'†)`. +Combined with the pivot-wire decoupling (the image is again trivial on wire `0`) +and injectivity of `I₂ ⊗ ·`, this pins down `M'`'s conjugation action on every phase-free `n`-qubit +Pauli string to a `±1` multiple of a Pauli string, from which the normalizer property of `M'` +follows by rebuilding the fourth-root-of-unity phase. + +## What is proved + +* `pauliString_cons_zero` — the identity-on-wire-`0` Pauli string is the block-scalar embedding of + the tail string: `P_{cons 0 a} = I₂ ⊗ P_a` (`embedLast (pauliString a)`). +* `embedLast_smul` — the embedding `I₂ ⊗ ·` is `ℂ`-linear in the scalar: `I₂ ⊗ (c • X) = c • (I₂ ⊗ + X)`. +* `IsPauliNormalizer.conj_pauliString_cons` — the **block-diagonal intertwining**: for a normalizer + `M` fixing `X₀, Z₀`, `M · P_{cons 0 a} · M† = I₂ ⊗ (M' · P_a · M'†)` with `M' = firstWireRestrict + M`. This is the recursion step: `M`'s action on the last-`n`-wire Pauli strings is exactly `M'`'s + action, wrapped in `I₂ ⊗ ·`. +* `firstWireRestrict_conj_pauliString` — the **`±1` signed action of `M'`**: for every `n`-qubit + index `a`, `M' · P_a · M'† = z • P_b` with `z ∈ {1, -1}`. From the intertwining, the pivot-wire + decoupling (`conj_apply_zero_eq_zero`, giving `b 0 = 0` so the image re-embeds), and injectivity + of `embedLast`. +* `firstWireRestrict_isPauliNormalizer` — **the main result**: `firstWireRestrict M` is an + `n`-qubit Pauli normalizer. Unitary by `firstWireRestrict_mem_unitaryGroup`; the group condition + rebuilds the phase — + a Pauli-group element `⟨s, a⟩` conjugates to `iˢ • (z • P_b) = i^{s + t} • P_b` where `z = iᵗ` + (`t = 0` for `z = 1`, `t = 2` for `z = -1`), which is again a Pauli-group element `⟨s + t, b⟩`. + This is the `n`-qubit normalizer the inductive hypothesis of Exercise 10.40 consumes. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The identity-on-wire-`0` Pauli string as a block-scalar embedding -/ + +/-- **`P_{cons 0 a} = I₂ ⊗ P_a`.** The `(n+1)`-qubit Pauli string that is the identity on wire `0` +and `P_a` on the last `n` wires is exactly the block-scalar embedding `embedLast (pauliString a)`. +Peeling the wire-`0` factor (`Fin.prod_univ_succ`) gives `pauli 0 (i 0) (j 0) = [i 0 = j 0]` +(the identity matrix entry) times the tail product `pauliString a (tail i) (tail j)`, which is the +defining entry of `embedLast (pauliString a)`. -/ +theorem pauliString_cons_zero (a : Fin n → Fin 4) : + pauliString (Fin.cons (0 : Fin 4) a) = embedLast (pauliString a) := by + ext i j + rw [embedLast_apply, pauliString_apply, Fin.prod_univ_succ, Fin.cons_zero, + show pauli (0 : Fin 4) = 1 from rfl, Matrix.one_apply, pauliString_apply] + simp only [Fin.cons_succ] + split_ifs with h <;> simp [Fin.tail] + +/-- **The embedding `I₂ ⊗ ·` is linear in the scalar**: `I₂ ⊗ (c • X) = c • (I₂ ⊗ X)`. -/ +theorem embedLast_smul (c : ℂ) (X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + embedLast (c • X) = c • embedLast X := by + ext i j + simp only [Matrix.smul_apply, embedLast_apply, smul_eq_mul, mul_ite, mul_zero] + +/-! ### The block-diagonal intertwining and the signed action of `M'` -/ + +/-- **Block-diagonal intertwining.** For an `(n+1)`-qubit Pauli normalizer `M` fixing the first-wire +generators `X₀` and `Z₀` under conjugation, conjugation of a Pauli string trivial on wire `0` +block-diagonalises: `M · P_{cons 0 a} · M† = I₂ ⊗ (M' · P_a · M'†)`, where `M' = firstWireRestrict +M`. Because `M = I₂ ⊗ M'` (`eq_embedLast_firstWireRestrict`), this is just multiplicativity of +`I₂ ⊗ ·` (`embedLast_mul`) together with `P_{cons 0 a} = I₂ ⊗ P_a` (`pauliString_cons_zero`). -/ +theorem IsPauliNormalizer.conj_pauliString_cons + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) (a : Fin n → Fin 4) : + M * pauliString (Fin.cons 0 a) * Mᴴ + = embedLast (firstWireRestrict M * pauliString a * (firstWireRestrict M)ᴴ) := by + have hfac : M = embedLast (firstWireRestrict M) := eq_embedLast_firstWireRestrict hM.1 hX hZ + set M' := firstWireRestrict M with hM' + rw [pauliString_cons_zero, hfac, embedLast_conjTranspose, embedLast_mul, embedLast_mul] + +/-- **The `±1` signed action of the restriction `M'`.** For an `(n+1)`-qubit normalizer `M` fixing +`X₀, Z₀`, the restriction `M' = firstWireRestrict M` conjugates every phase-free `n`-qubit Pauli +string to a `±1` multiple of a Pauli string: `M' · P_a · M'† = z • P_b`, `z ∈ {1, -1}`. + +The pivot-wire decoupling (`conj_apply_zero_eq_zero`) applied to `cons 0 a` (trivial on wire `0`) +gives `M · P_{cons 0 a} · M† = z • P_{b₀}` with `b₀ 0 = 0` and `z = ±1`. Rewriting the left side by +the block-diagonal intertwining and the right side as `I₂ ⊗ (z • P_{tail b₀})` (using `b₀ 0 = 0`), +injectivity of `I₂ ⊗ ·` strips the embedding, leaving the signed action with `b = tail b₀`. -/ +theorem firstWireRestrict_conj_pauliString + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) (a : Fin n → Fin 4) : + ∃ (b : Fin n → Fin 4) (z : ℂ), (z = 1 ∨ z = -1) ∧ + firstWireRestrict M * pauliString a * (firstWireRestrict M)ᴴ = z • pauliString b := by + obtain ⟨b0, z, hz, hconj0, hb0⟩ := + hM.conj_apply_zero_eq_zero hX hZ (a := Fin.cons 0 a) (Fin.cons_zero _ _) + rw [hM.conj_pauliString_cons hX hZ] at hconj0 + refine ⟨Fin.tail b0, z, hz, ?_⟩ + have hcons : Fin.cons (0 : Fin 4) (Fin.tail b0) = b0 := by rw [← hb0]; exact Fin.cons_self_tail b0 + have hb0eq : pauliString b0 = embedLast (pauliString (Fin.tail b0)) := by + conv_lhs => rw [← hcons] + rw [pauliString_cons_zero] + rw [hb0eq, ← embedLast_smul] at hconj0 + exact embedLast_injective hconj0 + +/-! ### The restriction is an `n`-qubit normalizer -/ + +/-- **The restriction of a normalizer is a normalizer.** For an `(n+1)`-qubit Pauli normalizer `M` +fixing the first-wire generators `X₀` and `Z₀` under conjugation, the `n`-qubit restriction +`firstWireRestrict M` is again a Pauli normalizer. This is the datum the multi-qubit induction of +Nielsen & Chuang Exercise 10.40 recurses on. + +Unitarity is `firstWireRestrict_mem_unitaryGroup`. For the group condition, a Pauli-group element +`p = ⟨s, a⟩` has `p.toMat = iˢ • P_a`; the signed action gives `M' · P_a · M'† = z • P_b` with +`z = ±1`, so `M' · p.toMat · M'† = iˢ • (z • P_b) = i^{s + t} • P_b`, where `z = iᵗ` (`t = 0` if +`z = 1`, `t = 2` if `z = -1`). That is `⟨s + t, b⟩.toMat`, again a Pauli-group element. -/ +theorem firstWireRestrict_isPauliNormalizer + {M : Matrix (Fin (n + 1) → Fin 2) (Fin (n + 1) → Fin 2) ℂ} (hM : IsPauliNormalizer M) + (hX : M * pauliString (xGenPauli 0) * Mᴴ = pauliString (xGenPauli 0)) + (hZ : M * pauliString (zGenPauli 0) * Mᴴ = pauliString (zGenPauli 0)) : + IsPauliNormalizer (firstWireRestrict M) := by + refine ⟨firstWireRestrict_mem_unitaryGroup hM.1 hX hZ, ?_⟩ + intro p + obtain ⟨b, z, hz, hconj⟩ := firstWireRestrict_conj_pauliString hM hX hZ p.idx + -- `z = iᵗ` with `t = 0` (for `z = 1`) or `t = 2` (for `z = -1`); rebuild the Pauli-group element + -- `⟨p.phase + t, b⟩`. + obtain ⟨t, ht⟩ : ∃ t : ZMod 4, z = zmod4Pow t := by + rcases hz with h | h + · exact ⟨0, by rw [h, zmod4Pow_zero]⟩ + · exact ⟨2, by rw [h, zmod4Pow_two]⟩ + refine ⟨⟨p.phase + t, b⟩, ?_⟩ + simp only [PauliGroup.toMat] + rw [Matrix.mul_smul, Matrix.smul_mul, hconj, ht, smul_smul, ← zmod4Pow_add] + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerSwap.lean b/LeanPool/AxQM/Concrete/PauliNormalizerSwap.lean new file mode 100644 index 0000000000..b36a8c2ee6 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerSwap.lean @@ -0,0 +1,149 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringEncodingLayers + +/-! +# Concrete: the wire-swap Clifford circuit — transpose two wires' Pauli letters + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The inductive step of Exercise 10.40 (Figure 10.9) reduces a normalizer's first anticommuting +generator pair to the standard `(X_c, Z_c)` on some pivot wire `c` +(`exists_cliffordCircuit_reducePair`) and then **swaps the pivot to a designated first wire** so +the remaining `n` wires form a clean sub-register on which the inductive hypothesis runs. A wire +transposition is itself a Clifford operation — the standard three-`CNOT` identity `SWAP_{a,b} = +CNOT_{a→b} CNOT_{b→a} CNOT_{a→b}` — so this file builds it as a `CliffordCircuit` and proves the +two facts the induction needs: its phase-free action **transposes the two wires' Pauli letters** +and it acquires **no `±1` phase**. + +## What is proved + +* `swapWires a b` — the wire-swap circuit: `[CNOT_{a→b}, CNOT_{b→a}, CNOT_{a→b}]` for `a ≠ b`, and + the empty circuit for `a = b` (swapping a wire with itself is the identity). + +* `act_swapWires` / `act_swapWires_eq` — **the swap transposes the two wires' letters.** Its + phase-free action precomposes the Pauli string with the transposition of wires `a` and `b`: + `(swapWires a b).act g k = g (Equiv.swap a b k)`. On the two swapped wires this is a finite + `Fin 4 × Fin 4` tableau computation (three `CNOT` tableau steps `cnotPauliString`); off them every + gate leaves the wire untouched. + +* `sign_swapWires` — **the swap acquires no phase**: `(swapWires a b).sign g = 1`. `SWAP` is a real + permutation matrix and only permutes the tensor factors of a Pauli string, so the three `CNOT` + tableau signs multiply to `+1` on every letter pair. + +* `act_swapWires_xGenPauli` / `act_swapWires_zGenPauli` — **the swap moves a standard generator + between the two wires**: `(swapWires a b).act (xGenPauli a) = xGenPauli b` (and the `Z` mirror), + the exact use the induction makes of it — relocating the reduced pivot `(X_c, Z_c)` to a chosen + first wire. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **The wire-swap Clifford circuit.** For `a ≠ b`, the standard three-`CNOT` swap +`SWAP_{a,b} = CNOT_{a→b} CNOT_{b→a} CNOT_{a→b}` (read right-to-left, so `CNOT_{a→b}` is applied +first); for `a = b` the empty circuit, since swapping a wire with itself is the identity. Used by +the multi-qubit synthesis of Nielsen & Chuang Exercise 10.40 to swap the reduced pivot wire to a +designated first wire (Figure 10.9). -/ +def swapWires (a b : Fin n) : CliffordCircuit n := + if h : a = b then [] + else [CliffordGate.cnot a b h, CliffordGate.cnot b a (Ne.symm h), CliffordGate.cnot a b h] + +/-- The `Fin 4` tableau values of `swapWires a b` at the two swapped wires depend only on `g a` and +`g b`; these four abbreviations name the intermediate string values so `act_swapWires` and +`sign_swapWires` share the reduction. -/ +private theorem swapWires_reduce (a b : Fin n) (hab : a ≠ b) (g : Fin n → Fin 4) : + (cnotPauliString g a b) a = cnotCtrlPauli (g a) (g b) ∧ + (cnotPauliString g a b) b = cnotTgtPauli (g a) (g b) ∧ + (cnotPauliString (cnotPauliString g a b) b a) a + = cnotTgtPauli ((cnotPauliString g a b) b) ((cnotPauliString g a b) a) ∧ + (cnotPauliString (cnotPauliString g a b) b a) b + = cnotCtrlPauli ((cnotPauliString g a b) b) ((cnotPauliString g a b) a) := + ⟨cnotPauliString_ctrl g a b, cnotPauliString_tgt g hab, + cnotPauliString_tgt (cnotPauliString g a b) hab.symm, + cnotPauliString_ctrl (cnotPauliString g a b) b a⟩ + +/-- **The wire-swap transposes the two wires' Pauli letters (pointwise).** For every wire `k`, +`(swapWires a b).act g k = g (Equiv.swap a b k)`: the phase-free action of the swap circuit reads +the letter of `g` at the swapped wire. On the two swapped wires this is the composition of the three +`CNOT` tableau steps, a finite `Fin 4 × Fin 4` computation; off them each `CNOT` leaves the wire +fixed (`cnotPauliString_of_ne`). -/ +theorem act_swapWires (a b : Fin n) (g : Fin n → Fin 4) (k : Fin n) : + (swapWires a b).act g k = g (Equiv.swap a b k) := by + rcases eq_or_ne a b with rfl | hab + · simp [swapWires, Equiv.swap_self, CliffordCircuit.act] + · rw [swapWires, dite_eq_right hab] + simp only [CliffordCircuit.act, CliffordGate.act] + obtain ⟨hNa, hNb, hMa, hMb⟩ := swapWires_reduce a b hab g + rcases eq_or_ne k a with hka | hka + · rw [hka, Equiv.swap_apply_left, cnotPauliString_ctrl, hMa, hMb, hNa, hNb] + generalize g a = α + generalize g b = β + fin_cases α <;> fin_cases β <;> decide + · rcases eq_or_ne k b with hkb | hkb + · rw [hkb, Equiv.swap_apply_right, cnotPauliString_tgt _ hab, hMa, hMb, hNa, hNb] + generalize g a = α + generalize g b = β + fin_cases α <;> fin_cases β <;> decide + · rw [Equiv.swap_apply_of_ne_of_ne hka hkb, + cnotPauliString_of_ne _ a b hka hkb, + cnotPauliString_of_ne _ b a hkb hka, + cnotPauliString_of_ne _ a b hka hkb] + +/-- **The wire-swap transposes the two wires' Pauli letters (functional form)**: +`(swapWires a b).act g = fun k => g (Equiv.swap a b k)`. The `funext` packaging of `act_swapWires`, +convenient for composing the swap into a larger circuit. -/ +theorem act_swapWires_eq (a b : Fin n) (g : Fin n → Fin 4) : + (swapWires a b).act g = fun k => g (Equiv.swap a b k) := + funext (act_swapWires a b g) + +/-- **The wire-swap acquires no `±1` phase**: `(swapWires a b).sign g = 1`. `SWAP` is a real +permutation matrix and merely permutes the tensor factors of a Pauli string, so the three `CNOT` +tableau signs multiply to `+1` on every letter pair — a finite `Fin 4 × Fin 4` check. -/ +theorem sign_swapWires (a b : Fin n) (g : Fin n → Fin 4) : + (swapWires a b).sign g = 1 := by + rcases eq_or_ne a b with rfl | hab + · simp [swapWires, CliffordCircuit.sign] + · rw [swapWires, dite_eq_right hab] + simp only [CliffordCircuit.sign, CliffordCircuit.act, CliffordGate.sign, CliffordGate.act] + obtain ⟨hNa, hNb, hMa, hMb⟩ := swapWires_reduce a b hab g + rw [hMa, hMb, hNa, hNb] + generalize g a = α + generalize g b = β + fin_cases α <;> fin_cases β <;> simp [cnotPauliSign, cnotTgtPauli, cnotCtrlPauli] + +/-- **The wire-swap moves the standard `X` generator between the two wires**: +`(swapWires a b).act (xGenPauli a) = xGenPauli b`. Immediate from `act_swapWires` and the definition +`xGenPauli x = Function.update 0 x 1`: precomposing with the transposition sends the `X` on wire `a` +to wire `b`. The induction uses it to relocate a reduced pivot generator to a chosen first wire. -/ +theorem act_swapWires_xGenPauli (a b : Fin n) : + (swapWires a b).act (xGenPauli a) = xGenPauli b := by + funext k; simp [act_swapWires, xGenPauli_apply, Equiv.swap_apply_eq_iff, Equiv.swap_apply_left] + +/-- **The wire-swap moves the standard `Z` generator between the two wires**: +`(swapWires a b).act (zGenPauli a) = zGenPauli b`. The `Z` mirror of `act_swapWires_xGenPauli` +(`zGenPauli x = Function.update 0 x 3`). -/ +theorem act_swapWires_zGenPauli (a b : Fin n) : + (swapWires a b).act (zGenPauli a) = zGenPauli b := by + funext k; simp [act_swapWires, zGenPauli_apply, Equiv.swap_apply_eq_iff, Equiv.swap_apply_left] + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerSweep.lean b/LeanPool/AxQM/Concrete/PauliNormalizerSweep.lean new file mode 100644 index 0000000000..772f724e09 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerSweep.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerGenerators + +/-! +# Concrete: single-wire Clifford synthesis on any wire of an `n`-qubit register + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +The base case (`isPauliNormalizer_singleQubit_eq_smul_cliffordCircuit`) synthesises a +Clifford circuit realising an arbitrary valid single-qubit signed permutation — but only on the +*single-wire* +register `Fin 1`. The multi-qubit induction sweeps qubit by qubit, and to do so needs to run *any* +single-qubit Clifford on *any chosen wire* of the full register while leaving every other wire +undisturbed. This file provides exactly that atom, by transporting the `Fin 1` synthesis onto a +chosen wire through the wire-relabeling machinery of +`AxQM/Concrete/PauliStringCliffordCircuit.lean`. + +## What is proved + +* `wireEmbedding` — the wire-selecting embedding `Fin 1 ↪ Fin n` picking out a single wire `j` + (injective vacuously, as `Fin 1` is a subsingleton). This is the `f = fun _ => j` instance of the + embedding that `CliffordCircuit.relabel` transports a circuit along. + +* `CliffordCircuit.onWire j C₀` — the `n`-wire circuit that runs the single-wire circuit `C₀` on + wire `j` (`relabel (wireEmbedding j) C₀`). + +* `CliffordCircuit.onWire_act` / `onWire_act_of_ne` / `onWire_sign` — the **characterisation of + `onWire`'s action and phase on the whole register**: on wire `j` the phase-free action is `C₀`'s + single-wire action read off wire `j`'s letter (`onWire_act`), every wire `k ≠ j` is left untouched + (`onWire_act_of_ne`), and the `±1` phase is `C₀`'s phase at wire `j`'s letter (`onWire_sign`). + These are the direct specialisations of `act_relabel_embed`, `act_relabel_of_forall_ne` and + `sign_relabel` to the single-wire embedding. + +* `exists_cliffordCircuit_onWire_act_sign` — **single-wire signed-permutation synthesis on an + arbitrary wire.** For any wire `j`, distinct non-identity target letters `aX, aZ` and signs + `zX, zZ ∈ {±1}`, there is an `n`-wire Clifford circuit realising, on wire `j`, the signed + permutation `Xⱼ ↦ zX · (aX on wire j)`, `Zⱼ ↦ zZ · (aZ on wire j)` exactly, while fixing every + other wire. This is the multi-qubit lift of `exists_cliffordCircuit_singleQubit_act_sign`, the + per-wire building block of the Exercise 10.40 sweep. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The single-wire embedding -/ + +/-- **The wire-selecting embedding `Fin 1 ↪ Fin n`** picking out a single wire `j`: the constant map +`fun _ => j`, injective because `Fin 1` is a subsingleton. `CliffordCircuit.relabel` transports a +single-wire circuit onto wire `j` of the `n`-wire register along this embedding. -/ +def wireEmbedding (j : Fin n) : Fin 1 ↪ Fin n := + ⟨fun _ => j, fun _ _ _ => Subsingleton.elim _ _⟩ + +@[simp] +theorem wireEmbedding_apply (j : Fin n) (i : Fin 1) : wireEmbedding j i = j := rfl + +namespace CliffordCircuit + +/-! ### Running a single-wire circuit on a chosen wire -/ + +/-- **Run the single-wire circuit `C₀` on wire `j`** of the `n`-wire register: relabel each gate's +wire to `j` (`relabel (wireEmbedding j) C₀`). The result is a genuine `n`-wire Clifford circuit +touching only wire `j`. -/ +def onWire (j : Fin n) (C₀ : CliffordCircuit 1) : CliffordCircuit n := + relabel (wireEmbedding j) C₀ + +/-- **On wire `j`, `onWire j C₀` acts as `C₀` on wire `j`'s letter**: +`(onWire j C₀).act g j = C₀.act (fun _ => g j) 0`. Immediate from `act_relabel_embed` at index `0` +of the single-wire embedding. -/ +theorem onWire_act (j : Fin n) (C₀ : CliffordCircuit 1) (g : Fin n → Fin 4) : + act (onWire j C₀) g j = act C₀ (fun _ => g j) 0 := by + have h := act_relabel_embed (wireEmbedding j) C₀ g 0 + simpa only [onWire, wireEmbedding_apply] using h + +/-- **`onWire j C₀` leaves every wire `k ≠ j` untouched**: `(onWire j C₀).act g k = g k`. Immediate +from `act_relabel_of_forall_ne` (every embedded wire is `j ≠ k`). -/ +theorem onWire_act_of_ne (j : Fin n) (C₀ : CliffordCircuit 1) (g : Fin n → Fin 4) {k : Fin n} + (hk : k ≠ j) : act (onWire j C₀) g k = g k := + act_relabel_of_forall_ne (wireEmbedding j) C₀ g (fun i => by simpa using hk.symm) + +/-- **The `±1` phase of `onWire j C₀` is `C₀`'s phase at wire `j`'s letter**: +`(onWire j C₀).sign g = C₀.sign (fun _ => g j)`. Immediate from `sign_relabel`. -/ +theorem onWire_sign (j : Fin n) (C₀ : CliffordCircuit 1) (g : Fin n → Fin 4) : + sign (onWire j C₀) g = sign C₀ (fun _ => g j) := by + have h := sign_relabel (wireEmbedding j) C₀ g + simpa only [onWire, wireEmbedding_apply] using h + +/-- **`onWire j C₀` runs `C₀`'s single-qubit action on a single-wire Pauli.** For a string carrying +letter `c` on wire `j` and identity elsewhere (`Function.update 0 j c`), +`(onWire j C₀).act (Function.update 0 j c) = Function.update 0 j (C₀.act (fun _ => c) 0)` — the +image is again supported on wire `j`, carrying the letter `C₀` sends `c` to. From `onWire_act` on +wire `j` and `onWire_act_of_ne` off it — the form the multi-qubit synthesis applies to the +generators `Xⱼ = update 0 j 1` and `Zⱼ = update 0 j 3`. -/ +theorem onWire_act_update (j : Fin n) (C₀ : CliffordCircuit 1) (c : Fin 4) : + act (onWire j C₀) (Function.update (0 : Fin n → Fin 4) j c) + = Function.update (0 : Fin n → Fin 4) j (act C₀ (fun _ => c) 0) := by + funext k + rcases eq_or_ne k j with hk | hk + · subst hk + rw [onWire_act, Function.update_self, Function.update_self] + · rw [onWire_act_of_ne _ _ _ hk, Function.update_of_ne hk, Function.update_of_ne hk] + +end CliffordCircuit + +/-! ### Single-wire signed-permutation synthesis on an arbitrary wire -/ + +/-- **Single-wire signed-permutation synthesis on an arbitrary wire (the sweep atom of Exercise +10.40).** For any wire `j`, distinct non-identity target letters `aX, aZ` (`aX, aZ ∈ {X, Y, Z}`, +`aX ≠ aZ`) and signs `zX, zZ ∈ {1, -1}`, there is an `n`-wire Clifford circuit `C` realising, on +wire `j`, the signed permutation exactly: + +* `C.act (Xⱼ) = (aX on wire j)` with `C.sign (Xⱼ) = zX`, +* `C.act (Zⱼ) = (aZ on wire j)` with `C.sign (Zⱼ) = zZ`, + +and leaving every other wire fixed (`C.act g k = g k` for `k ≠ j`, all `g`). The multi-qubit lift of +`exists_cliffordCircuit_singleQubit_act_sign`: synthesise the required single-qubit signed +permutation on `Fin 1`, then run it on wire `j` via `CliffordCircuit.onWire`, whose action/phase +characterisation transports the base circuit's images to `Function.update 0 j aX` / `…aZ`. This is +the per-wire building block the multi-qubit induction runs on each wire in turn. -/ +theorem exists_cliffordCircuit_onWire_act_sign (j : Fin n) {aX aZ : Fin 4} {zX zZ : ℂ} + (h0X : aX ≠ 0) (h0Z : aZ ≠ 0) (hne : aX ≠ aZ) + (hzX : zX = 1 ∨ zX = -1) (hzZ : zZ = 1 ∨ zZ = -1) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C (xGenPauli j) = Function.update (0 : Fin n → Fin 4) j aX ∧ + CliffordCircuit.sign C (xGenPauli j) = zX ∧ + CliffordCircuit.act C (zGenPauli j) = Function.update (0 : Fin n → Fin 4) j aZ ∧ + CliffordCircuit.sign C (zGenPauli j) = zZ ∧ + (∀ (g : Fin n → Fin 4) (k : Fin n), k ≠ j → CliffordCircuit.act C g k = g k) := by + obtain ⟨C₀, hCaX, hCsX, hCaZ, hCsZ⟩ := + exists_cliffordCircuit_singleQubit_act_sign h0X h0Z hne hzX hzZ + -- the generator's own letter on wire `j` is its Pauli letter (`X = 1`, `Z = 3`) + have hXj : (fun _ : Fin 1 => xGenPauli j j) = (fun _ => (1 : Fin 4)) := by + funext _; simp [xGenPauli] + have hZj : (fun _ : Fin 1 => zGenPauli j j) = (fun _ => (3 : Fin 4)) := by + funext _; simp [zGenPauli] + refine ⟨CliffordCircuit.onWire j C₀, ?_, ?_, ?_, ?_, ?_⟩ + · -- action on Xⱼ = `update 0 j 1` + rw [show xGenPauli j = Function.update (0 : Fin n → Fin 4) j 1 from rfl, + CliffordCircuit.onWire_act_update, hCaX] + · rw [CliffordCircuit.onWire_sign, hXj, hCsX] + · -- action on Zⱼ = `update 0 j 3` + rw [show zGenPauli j = Function.update (0 : Fin n → Fin 4) j 3 from rfl, + CliffordCircuit.onWire_act_update, hCaZ] + · rw [CliffordCircuit.onWire_sign, hZj, hCsZ] + · intro g k hk + exact CliffordCircuit.onWire_act_of_ne _ _ _ hk + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerSymplectic.lean b/LeanPool/AxQM/Concrete/PauliNormalizerSymplectic.lean new file mode 100644 index 0000000000..32266de659 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerSymplectic.lean @@ -0,0 +1,189 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerReduceGenerator + +/-! +# Concrete: the Clifford action is symplectic — the first move of the pair reduction + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3), +by establishing the *symplectic structure* of a Clifford circuit's action on Pauli strings. + +The single-generator reduction `exists_cliffordCircuit_reduceToXGen`/`…ToZGen` collapses one +generator image `U X₁ U†` to a standard `X_c`/`Z_c`. The Exercise 10.40 first-qubit reduction must +reduce the *anticommuting pair* `U X₁ U†`, `U Z₁ U†` *simultaneously*, to `X_c` and `Z_c` on a +**common** wire. The key structural fact making this possible is that a Clifford circuit's action +preserves commutation — precisely how N&C open part 2: "since `Z₁` and `X₁` anticommute, `U Z₁ U†` +and `U X₁ U†` anticommute". This file records that invariant at the circuit level and derives the +symplectic *first move* of the pair reduction. + +## Main results + +* `CliffordCircuit.act_pauliAnticommCount_even_iff` — **the Clifford action is symplectic**: for any + circuit `C`, `Even (pauliAnticommCount (act C g) (act C h)) ↔ Even (pauliAnticommCount g h)`. A + Clifford circuit's phase-free action on the check matrix preserves the mod-2 symplectic form of + Exercise 10.33. The circuit-level counterpart of the normalizer-level + `IsPauliNormalizer.exists_signedPerm_symplectic`, proved the same way: `act C` corresponds + to conjugation by the unitary `toMatrix C` (`conj_pauliString`), conjugation preserves commutation + (`unitaryConj_commute_iff`), and `pauliString_commute_iff` (Ex 10.33) turns commutation into the + parity statement. +* `pauliAnticommCount_xGenPauli` / `…_zGenPauli` — **single-generator positions**: the symplectic + pairing of a string `h` against a standard generator is a single check bit, + `pauliAnticommCount h (xGenPauli c) = pauliZBit (h c)` and + `pauliAnticommCount h (zGenPauli c) = pauliXBit (h c)`. +* `odd_pauliAnticommCount_xGenPauli_iff` / `…_zGenPauli_iff` — the parity reading: `h` anticommutes + with `X_c` iff its `c`-letter has a `Z` factor (`h c ∈ {Y, Z}`), and with `Z_c` iff it has an `X` + factor (`h c ∈ {X, Y}`). +* `exists_cliffordCircuit_reduceFirstOfPair` — **the symplectic first move of the pair reduction**: + for anticommuting `p, q` (`Odd (pauliAnticommCount p q)`) there is a Clifford circuit `C` and a + pivot wire `c` reducing `p` to the standard `X_c` exactly (`act C p = xGenPauli c`, + `sign C p = 1`) such that the partner image `act C q` *still anticommutes with `X_c`* — concretely + `act C q c ∈ {Y, Z}`. This is the starting configuration completed by reducing + `act C q` to `Z_c` while fixing `X_c`. + +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +namespace CliffordCircuit + +/-- **The Clifford action is symplectic.** A Clifford circuit's phase-free action on Pauli strings +preserves the mod-2 symplectic form of Nielsen & Chuang Exercise 10.33: for any circuit `C` and +Pauli strings `g, h`, `Even (pauliAnticommCount (act C g) (act C h)) ↔ Even (pauliAnticommCount g +h)`. + +This is the circuit-level counterpart of the normalizer-level +`IsPauliNormalizer.exists_signedPerm_symplectic`, and is proved the same way: `act C` +corresponds to conjugation by the unitary `toMatrix C` +(`conj_pauliString`: `toMatrix C · P_g · (toMatrix C)ᴴ = sign C g • P_{act C g}`), conjugation by a +unitary preserves commutation (`unitaryConj_commute_iff`) — the `±1` phases `sign C g` cancel — and +`pauliString_commute_iff` translates commutation into the parity statement both ways. It is the +structural invariant the inductive synthesis of Exercise 10.40 must reproduce: a Clifford circuit +maps anticommuting Pauli strings to anticommuting ones. -/ +theorem act_pauliAnticommCount_even_iff (C : CliffordCircuit n) (g h : Fin n → Fin 4) : + Even (pauliAnticommCount (act C g) (act C h)) ↔ Even (pauliAnticommCount g h) := by + rw [← pauliString_commute_iff, ← pauliString_commute_iff] + have hUmem : toMatrix C ∈ Matrix.unitaryGroup (Fin n → Fin 2) ℂ := by + rw [mem_unitaryGroup_iff, star_eq_conjTranspose]; exact mul_conjTranspose C + -- the `±1` conjugation phases cancel, so the images commute iff the raw conjugates do + have hstep : Commute (toMatrix C * pauliString g * (toMatrix C)ᴴ) + (toMatrix C * pauliString h * (toMatrix C)ᴴ) + ↔ Commute (pauliString (act C g)) (pauliString (act C h)) := by + rw [conj_pauliString C g, conj_pauliString C h, + Commute.smul_left_iff₀ (sign_ne_zero C g), Commute.smul_right_iff₀ (sign_ne_zero C h)] + exact hstep.symm.trans (unitaryConj_commute_iff hUmem (pauliString g) (pauliString h)) + +end CliffordCircuit + +/-! ### Single-generator positions: the symplectic pairing against a standard generator -/ + +/-- **The symplectic pairing against a standard `X` generator is a single `Z` bit**: +`pauliAnticommCount h (xGenPauli c) = pauliZBit (h c)`. Only wire `c` contributes (`xGenPauli c` is +`I` elsewhere), and against a single `X` the per-qubit symplectic pairing +`singlePauliAnticomm (h c) 1` is exactly the `Z`-bit of `h c`. Hence `h` anticommutes with `X_c` +precisely when its `c`-letter contains a `Z` factor. -/ +theorem pauliAnticommCount_xGenPauli (h : Fin n → Fin 4) (c : Fin n) : + pauliAnticommCount h (xGenPauli c) = pauliZBit (h c) := by + rw [pauliAnticommCount, Finset.sum_eq_single_of_mem c (Finset.mem_univ c)] + · simp [singlePauliAnticomm, xGenPauli_apply, pauliXBit, pauliZBit] + · intro k _ hk + simp [singlePauliAnticomm, xGenPauli_apply, ite_eq_right hk, pauliXBit, pauliZBit] + +/-- **The symplectic pairing against a standard `Z` generator is a single `X` bit**: +`pauliAnticommCount h (zGenPauli c) = pauliXBit (h c)`. The `Z`-basis mirror of +`pauliAnticommCount_xGenPauli`: against a single `Z` the per-qubit symplectic pairing +`singlePauliAnticomm (h c) 3` is the `X`-bit of `h c`, so `h` anticommutes with `Z_c` precisely when +its `c`-letter contains an `X` factor. -/ +theorem pauliAnticommCount_zGenPauli (h : Fin n → Fin 4) (c : Fin n) : + pauliAnticommCount h (zGenPauli c) = pauliXBit (h c) := by + rw [pauliAnticommCount, Finset.sum_eq_single_of_mem c (Finset.mem_univ c)] + · simp [singlePauliAnticomm, zGenPauli_apply, pauliXBit, pauliZBit] + · intro k _ hk + simp [singlePauliAnticomm, zGenPauli_apply, ite_eq_right hk, pauliXBit, pauliZBit] + +/-- **Anticommuting with `X_c` means a `Z` factor on wire `c`.** `h` anticommutes with the standard +generator `X_c` (`Odd (pauliAnticommCount h (xGenPauli c))`) iff its `c`-letter is `Y` or `Z` +(`h c = 2 ∨ h c = 3`), the Paulis carrying a `Z` factor. -/ +theorem odd_pauliAnticommCount_xGenPauli_iff (h : Fin n → Fin 4) (c : Fin n) : + Odd (pauliAnticommCount h (xGenPauli c)) ↔ h c = 2 ∨ h c = 3 := by + rw [pauliAnticommCount_xGenPauli] + generalize h c = a + revert a + decide + +/-- **Anticommuting with `Z_c` means an `X` factor on wire `c`.** `h` anticommutes with the standard +generator `Z_c` (`Odd (pauliAnticommCount h (zGenPauli c))`) iff its `c`-letter is `X` or `Y` +(`h c = 1 ∨ h c = 2`), the Paulis carrying an `X` factor. The mirror of +`odd_pauliAnticommCount_xGenPauli_iff`. -/ +theorem odd_pauliAnticommCount_zGenPauli_iff (h : Fin n → Fin 4) (c : Fin n) : + Odd (pauliAnticommCount h (zGenPauli c)) ↔ h c = 1 ∨ h c = 2 := by + rw [pauliAnticommCount_zGenPauli] + generalize h c = a + revert a + decide + +/-! ### The symplectic first move of the pair reduction -/ + +/-- **The symplectic first move of the pair reduction (Exercise 10.40, first-qubit reduction).** For +an anticommuting pair of Pauli strings `p, q` (`Odd (pauliAnticommCount p q)`), there is a Clifford +circuit `C` and a pivot wire `c` such that: + +* `C` reduces `p` to the standard `X` generator on `c` *exactly* — `act C p = xGenPauli c` and + `sign C p = 1`; and +* the partner image `act C q` **still anticommutes with `X_c`** — concretely `act C q c = 2 ∨ + act C q c = 3` (a `Y`/`Z` factor on the pivot wire). + +Construction: `p` is non-identity (an anticommuting partner cannot be the identity, whose symplectic +form is even), so it has a support wire `c`; `exists_cliffordCircuit_reduceToXGen` reduces +`p` to `X_c`. The Clifford action is symplectic (`act_pauliAnticommCount_even_iff`), so `act C p` +and `act C q` still anticommute; rewriting `act C p = X_c` and reading the position lemma +(`odd_pauliAnticommCount_xGenPauli_iff`) gives the `Y`/`Z` factor of `act C q` on `c`. + +This is the starting configuration for the rest of the first-qubit reduction: `act C q` shares the +pivot wire `c` with `X_c` (it has a `Z` factor there), so a subsequent circuit can reduce it to +`Z_c` while fixing `X_c`, bringing the pair to the standard `(X_c, Z_c)`. -/ +theorem exists_cliffordCircuit_reduceFirstOfPair (p q : Fin n → Fin 4) + (hpq : Odd (pauliAnticommCount p q)) : + ∃ (C : CliffordCircuit n) (c : Fin n), + CliffordCircuit.act C p = xGenPauli c ∧ CliffordCircuit.sign C p = 1 ∧ + (CliffordCircuit.act C q c = 2 ∨ CliffordCircuit.act C q c = 3) := by + -- an anticommuting partner is non-identity, hence has a support wire `c` + obtain ⟨c, hc⟩ : ∃ c, p c ≠ 0 := by + by_contra hall + have hp0 : ∀ k, p k = 0 := fun k => by + by_contra hk; exact hall ⟨k, hk⟩ + have hz : pauliAnticommCount p q = 0 := by + refine Finset.sum_eq_zero fun k _ => ?_ + rw [hp0 k] + simp [singlePauliAnticomm, pauliXBit, pauliZBit] + rw [hz] at hpq + exact absurd hpq (by decide) + obtain ⟨C, hCact, hCsign⟩ := exists_cliffordCircuit_reduceToXGen p c hc + refine ⟨C, c, hCact, hCsign, ?_⟩ + -- the images still anticommute, and `act C p = X_c`, so `act C q` anticommutes with `X_c` + have hpreserve : Odd (pauliAnticommCount (C.act p) (C.act q)) := by + rw [← Nat.not_even_iff_odd] at hpq ⊢ + rwa [CliffordCircuit.act_pauliAnticommCount_even_iff] + rw [← odd_pauliAnticommCount_xGenPauli_iff, pauliAnticommCount_symm, ← hCact] + exact hpreserve + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliNormalizerZClear.lean b/LeanPool/AxQM/Concrete/PauliNormalizerZClear.lean new file mode 100644 index 0000000000..949c4083f6 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliNormalizerZClear.lean @@ -0,0 +1,243 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerCnotClear + +/-! +# Concrete: the `Z`-generator sweep — diagonalise to all-`Z` and collapse to a single `Z` + +This file is part of the formalisation of +Nielsen & Chuang **Theorem 10.6** (the converse — the normalizer `N(Gₙ)` is generated by +Hadamard/phase/CNOT gates, Exercise 10.40) toward the multi-qubit inductive synthesis (parts 2–3). + +It is the **`Z`-generator companion** of the `X`-generator sweep: + +* diagonalise-to-all-`X` (`exists_singleQubitLayer_act_diagX`) and +* CNOT-clear-to-single-`X` (`exists_cliffordCircuit_cnotClear_toSingleX`). + +The Gottesman tableau sweep reduces a normalizer's action on the second generator `U Z₁ U†` by the +mirror-image of the first-generator moves, working in the `Z` (rather than `X`) basis: + +1. **Diagonalise to all-`Z`** (*this file*, `exists_singleQubitLayer_act_diagZ`): a single-qubit + layer rotates the image to a string carrying `Z` on its support and `I` elsewhere. The per-wire + rotation `rotateToZ` uses `H` (`X ↦ Z`) and `H S` (`Y ↦ X ↦ Z`); `Z` and `I` need no gate. +2. **Collapse to a single generator** (*this file*, `exists_cliffordCircuit_cnotClear_toSingleZ`): a + **fan of CNOTs into** one support wire `c` (that wire the common *target*, every other support + wire a *control*) clears the `Z` off every other support wire, leaving `Z` on wire `c` alone + (`zGenPauli c`). + +The clearing move is the `Z`-basis mirror of the `X`-clearing. For `X` a single +`CNOT_{c→t}` (control `c`, target `t`) copies the control's `X` onto the target (`x_t += x_c`, +Figure 10.7), so a fan *out of* `c` clears an all-`X` string down to `X_c`. For `Z` the propagation +runs the other way — `CNOT_{t→c}` sends the target's `Z` onto the control (`z_c += z_t`), i.e. a +`CNOT` whose **control** is `t` and **target** is `c` clears `Z` off `t` (`cnotCtrlPauli 3 3 = 0`) +while keeping `Z` on `c` (`cnotTgtPauli 3 3 = 3`). So the `Z`-collapse fan reverses the control/ +target roles of the `X`-collapse fan: `cnotFanInto c ts` runs `CNOT_{t→c}` for each `t ∈ ts`. + +## What is proved + +* `CliffordCircuit.rotateToZ` / `rotateToZ_act` — a single-wire Clifford rotating a Pauli letter to + `Z` (fixing `I`): `H` for `X`, `H S` for `Y`. +* `exists_singleQubitLayer_act_diagZ` — **sweep step 1 (`Z` basis)**: a single-qubit layer sends any + Pauli string to its all-`Z`-on-support form, returned as the per-wire family so the layer's action + on any other string stays available through `CliffordCircuit.singleQubitLayer_act`. +* `cnotFanInto` — the **reverse CNOT fan**: `CNOT_{t→c}` for every `t ∈ ts` (targets folded into the + single control-collector wire `c`). `act_cnotFanInto_collapse` gives its clearing action on an + all-`Z` string and `sign_cnotFanInto_collapse` its trivial `±1` phase. +* `exists_cliffordCircuit_cnotClear_toSingleZ` — **sweep step 2 (`Z` basis)**: for + any all-`Z` string `a` with a pivot `c` in its support, a Clifford circuit realising + `a ↦ zGenPauli c` exactly, with phase `1`. Together with the diagonalisation step this reduces a + normalizer's second generator image `U Z₁ U†` to the standard `Z₁`, the `Z`-basis mirror of the + `X`-generator reduction. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +namespace CliffordCircuit + +/-! ### Rotating a single Pauli letter to `Z` -/ + +/-- **A single-wire Clifford rotating the letter `c` to `Z`.** `Z` needs no gate; `H` sends +`X ↦ Z` (`hadamardPauli`); `H S` sends `Y ↦ X ↦ Z` (`S` first, `phasePauli 2 = 1`; then `H`, +`hadamardPauli 1 = 3`). The identity `I` (`c = 0`) is left as `I`. -/ +def rotateToZ (c : Fin 4) : CliffordCircuit 1 := + if c = 1 then [CliffordGate.had 0] + else if c = 2 then [CliffordGate.had 0, CliffordGate.phase 0] else [] + +/-- **`rotateToZ c` sends the letter `c` to `Z`** (and fixes `I`): `(rotateToZ c).act (fun _ => c) 0 += if c = 0 then 0 else 3`. Verified by cases on `c` (`decide` on the computable single-wire +action; the two-gate `Y` case composes right-to-left, `S` then `H`). -/ +theorem rotateToZ_act (c : Fin 4) : + act (rotateToZ c) (fun _ => c) 0 = if c = 0 then 0 else 3 := by + fin_cases c <;> decide + +end CliffordCircuit + +/-! ### Sweep step 1 (`Z` basis): diagonalise a Pauli string to all-`Z` -/ + +/-- **First move of the `Z`-generator sweep: rotate a Pauli string to all-`Z`.** For any Pauli +string `a : Fin n → Fin 4` there is a single-qubit family `f` whose layer sends `a` to the string +carrying `Z` on every wire of `a`'s support and `I` elsewhere: +`(singleQubitLayer f).act a k = if a k = 0 then 0 else 3`. Take `f k = rotateToZ (a k)` on each wire +and apply `singleQubitLayer_act` and `rotateToZ_act`. + +The witness is returned as the *per-wire family* `f` rather than the assembled circuit, so a caller +can read off the same layer's effect on any *other* Pauli string through +`CliffordCircuit.singleQubitLayer_act` — the `Z`-basis mirror of +`exists_singleQubitLayer_act_diagX`, +and what the multi-qubit induction needs while diagonalising the second generator's image +`U Z₁ U†`. -/ +theorem exists_singleQubitLayer_act_diagZ (a : Fin n → Fin 4) : + ∃ f : Fin n → CliffordCircuit 1, ∀ k, + CliffordCircuit.act (CliffordCircuit.singleQubitLayer f) a k = if a k = 0 then 0 else 3 := by + refine ⟨fun k => CliffordCircuit.rotateToZ (a k), fun k => ?_⟩ + rw [CliffordCircuit.singleQubitLayer_act] + exact CliffordCircuit.rotateToZ_act (a k) + +/-! ### The reverse CNOT fan: collapsing an all-`Z` string -/ + +/-- **The reverse CNOT fan into a collector wire `c`.** Runs `CNOT_{t→c}` (control `t`, target `c`) +for each `t ∈ ts` (`ts.flatMap (fun t => cnotStep t c)`). This is the control/target mirror of +`cnotFan` (which fixes a single control and fans onto many targets): here a single target `c` +collects from many controls, so that a fan of `Z`-carrying controls collapses onto the single +target `c` (`z_c += z_t` clears the control's `Z`, keeps the target's). -/ +def cnotFanInto (c : Fin n) (ts : List (Fin n)) : CliffordCircuit n := + ts.flatMap (fun t => cnotStep t c) + +@[simp] +theorem cnotFanInto_nil (c : Fin n) : cnotFanInto c [] = [] := rfl + +theorem cnotFanInto_cons (c t : Fin n) (ts : List (Fin n)) : + cnotFanInto c (t :: ts) = cnotStep t c ++ cnotFanInto c ts := by + simp [cnotFanInto, List.flatMap_cons] + +/-- Peeling the head of a reverse CNOT fan (with `t ≠ c`): the head CNOT `t → c` acts last, on the +result of the rest of the fan. -/ +theorem act_cnotFanInto_cons_of_ne {c t : Fin n} (htc : t ≠ c) (ts : List (Fin n)) + (g : Fin n → Fin 4) : + CliffordCircuit.act (cnotFanInto c (t :: ts)) g + = cnotPauliString (CliffordCircuit.act (cnotFanInto c ts) g) t c := by + rw [cnotFanInto_cons, CliffordCircuit.act_append, act_cnotStep_of_ne htc] + +/-- **A reverse CNOT fan collapses an all-`Z` string to its collector.** For a string `a` with `Z` +(letter `3`) on wire `c` and on every wire of a distinct list `ts` (`c ∉ ts`, `ts.Nodup`, +`∀ t ∈ ts, a t = 3`), the fan `cnotFanInto c ts` (controls `ts`, target `c`) transforms `a` to: +`act (cnotFanInto c ts) a k = if k = c then 3 else if k ∈ ts then 0 else a k` — `Z` kept on the +collector `c`, `I` on every control, and every other wire unchanged. + +This is the `Z`-basis mirror of `act_cnotFan_collapse`: `CNOT_{t→c}` copies the control's `Z` onto +the target (`z_c += z_t`, Figure 10.7), so a control that already carries a `Z` is cleared +(`cnotCtrlPauli 3 3 = 0`) while the target keeps its `Z` (`cnotTgtPauli 3 3 = 3`). Proved by +induction on `ts` via `act_cnotFanInto_cons_of_ne`. -/ +theorem act_cnotFanInto_collapse (c : Fin n) : + ∀ (ts : List (Fin n)), c ∉ ts → ts.Nodup → ∀ (a : Fin n → Fin 4), a c = 3 → + (∀ t ∈ ts, a t = 3) → ∀ k, + CliffordCircuit.act (cnotFanInto c ts) a k = if k = c then 3 else if k ∈ ts then 0 else a k + | [], _, _, a, hac, _, k => by + simp only [cnotFanInto_nil, CliffordCircuit.act, List.not_mem_nil, ite_false] + rcases eq_or_ne k c with rfl | hk + · rw [ite_eq_left rfl]; exact hac + · rw [ite_eq_right hk] + | t :: ts, hct, hnd, a, hac, hall, k => by + rw [List.mem_cons, not_or] at hct + obtain ⟨hct_t, hct_ts⟩ := hct + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + have htc : t ≠ c := Ne.symm hct_t + have hall' : ∀ t' ∈ ts, a t' = 3 := fun t' ht' => hall t' (List.mem_cons_of_mem t ht') + have hIH := act_cnotFanInto_collapse c ts hct_ts hnd' a hac hall' + have hac' : CliffordCircuit.act (cnotFanInto c ts) a c = 3 := by rw [hIH c]; simp + have hat' : CliffordCircuit.act (cnotFanInto c ts) a t = 3 := by + rw [hIH t, ite_eq_right htc, ite_eq_right htnotin] + exact hall t List.mem_cons_self + rw [act_cnotFanInto_cons_of_ne htc ts a] + rcases eq_or_ne k t with rfl | hkt + · rw [cnotPauliString_ctrl, hat', hac', ite_eq_right htc, ite_eq_left List.mem_cons_self] + decide + · rcases eq_or_ne k c with rfl | hkc + · rw [cnotPauliString_tgt _ htc, hat', hac', ite_eq_left rfl] + decide + · rw [cnotPauliString_of_ne _ t c hkt hkc, hIH k] + have hmem2 : (k ∈ t :: ts) ↔ (k ∈ ts) := by simp [List.mem_cons, hkt] + simp only [hmem2] + +/-- **The reverse CNOT clearing introduces no sign.** Under the hypotheses of +`act_cnotFanInto_collapse`, `sign (cnotFanInto c ts) a = 1`: each `CNOT_{t→c}` in the fan conjugates +a pair `(Z_t, Z_c)` (control and target both `Z`, by the collapse action of the tail), whose CNOT +tableau sign is `cnotPauliSign 3 3 = 1`. Proved by induction on `ts` via `sign_append` and the +tail's `act` values from `act_cnotFanInto_collapse`. -/ +theorem sign_cnotFanInto_collapse (c : Fin n) : + ∀ (ts : List (Fin n)), c ∉ ts → ts.Nodup → ∀ (a : Fin n → Fin 4), a c = 3 → + (∀ t ∈ ts, a t = 3) → CliffordCircuit.sign (cnotFanInto c ts) a = 1 + | [], _, _, _, _, _ => by simp [cnotFanInto_nil, CliffordCircuit.sign] + | t :: ts, hct, hnd, a, hac, hall => by + rw [List.mem_cons, not_or] at hct + obtain ⟨hct_t, hct_ts⟩ := hct + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + have htc : t ≠ c := Ne.symm hct_t + have hall' : ∀ t' ∈ ts, a t' = 3 := fun t' ht' => hall t' (List.mem_cons_of_mem t ht') + have hac' : CliffordCircuit.act (cnotFanInto c ts) a c = 3 := by + rw [act_cnotFanInto_collapse c ts hct_ts hnd' a hac hall' c]; simp + have hat' : CliffordCircuit.act (cnotFanInto c ts) a t = 3 := by + rw [act_cnotFanInto_collapse c ts hct_ts hnd' a hac hall' t, ite_eq_right htc, + ite_eq_right htnotin] + exact hall t List.mem_cons_self + rw [cnotFanInto_cons, CliffordCircuit.sign_append, + sign_cnotFanInto_collapse c ts hct_ts hnd' a hac hall', one_mul, + sign_cnotStep_of_ne htc, hat', hac'] + rfl + +/-! ### Sweep step 2 (`Z` basis): collapse an all-`Z` image to a single `Z` generator -/ + +/-- **Reverse CNOT clearing (N&C Exercise 10.40 sweep step 2, `Z` basis).** For any all-`Z` Pauli +string `a` (`∀ k, a k = 0 ∨ a k = 3`) with a pivot wire `c` in its support (`a c = 3`), there is a +Clifford circuit `C` collapsing `a` to the single `Z` generator on wire `c` exactly, with phase `1`: +`act C a = zGenPauli c` and `sign C a = 1`. + +The witness is the reverse CNOT fan `cnotFanInto c ts` with collector `c` and controls the rest of +`a`'s support `ts = {k | a k = 3, k ≠ c}` (as a `Finset.filter … |>.toList`, so `Nodup` and +`c ∉ ts`); `act_cnotFanInto_collapse` clears every control's `Z`, and `sign_cnotFanInto_collapse` +gives the trivial phase. Together with the diagonalisation step +(`exists_singleQubitLayer_act_diagZ`) this reduces a normalizer's second generator image `U Z₁ U†` +to the standard `Z₁`, the `Z`-basis +mirror of `exists_cliffordCircuit_cnotClear_toSingleX`. -/ +theorem exists_cliffordCircuit_cnotClear_toSingleZ (a : Fin n → Fin 4) (c : Fin n) + (hc : a c = 3) (hZ : ∀ k, a k = 0 ∨ a k = 3) : + ∃ C : CliffordCircuit n, + CliffordCircuit.act C a = zGenPauli c ∧ CliffordCircuit.sign C a = 1 := by + set ts := (Finset.univ.filter (fun k => a k = 3 ∧ k ≠ c)).toList with hts + have hmem : ∀ k, k ∈ ts ↔ (a k = 3 ∧ k ≠ c) := by + intro k + rw [hts, Finset.mem_toList, Finset.mem_filter] + simp + have hnd : ts.Nodup := Finset.nodup_toList _ + have hcnotin : c ∉ ts := fun h => ((hmem c).mp h).2 rfl + have hall : ∀ t ∈ ts, a t = 3 := fun t ht => ((hmem t).mp ht).1 + refine ⟨cnotFanInto c ts, ?_, sign_cnotFanInto_collapse c ts hcnotin hnd a hc hall⟩ + funext k + rw [act_cnotFanInto_collapse c ts hcnotin hnd a hc hall k, zGenPauli_apply] + rcases eq_or_ne k c with rfl | hkc + · simp + · simp only [ite_eq_right hkc] + by_cases hk3 : a k = 3 + · rw [ite_eq_left ((hmem k).mpr ⟨hk3, hkc⟩)] + · rw [ite_eq_right (fun h => hk3 ((hmem k).mp h).1)] + exact (hZ k).resolve_right hk3 + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliOuterProduct.lean b/LeanPool/AxQM/Concrete/PauliOuterProduct.lean new file mode 100644 index 0000000000..73f8ba7b31 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliOuterProduct.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Data.Matrix.Mul +public import LeanPool.AxQM.Concrete.Pauli + +/-! +# Concrete: the Pauli matrices in the outer-product notation (Nielsen & Chuang, Exercise 2.9) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 2.9 +("Pauli operators and the outer product", p. 68) asks to express each of the Pauli +operators — considered as operators with respect to the orthonormal computational +basis `|0⟩, |1⟩` of a two-dimensional Hilbert space — in the outer-product notation. + +This is pure linear algebra over `ℂ²`. The Pauli matrices +themselves are the `Matrix (Fin 2) (Fin 2) ℂ` objects `pauliX`, `pauliY`, `pauliZ` +from `AxQM.Concrete.Pauli`; here we add the fourth, `pauliI` (`σ₀ = I`, per +Figure 2.2), and the outer-product vocabulary needed to state the exercise. + +## Contents + +* `ket i` — the computational-basis column vector `|i⟩` of `ℂ²`, i.e. `Pi.single i 1` + (`|0⟩ = (1, 0)`, `|1⟩ = (0, 1)`). +* `ketBra i j` — the outer product `|i⟩⟨j|` as a `2 × 2` matrix. Following N&C + eq. (2.20) the bra `⟨j|` is the conjugate transpose of `|j⟩`, so `ketBra i j` is + `vecMulVec |i⟩ (star |j⟩)`; its `(a, b)` entry is `⟨a|i⟩ · conj⟨b|j⟩ = δ_{ai} δ_{jb}`. +* `ketBra_apply` / `ketBra_eq_single` — the entrywise value and the identification + `|i⟩⟨j| = single i j 1` with the matrix unit (this is the completeness-relation + fact that outer products of an orthonormal basis are the standard basis matrices). +* `pauliI_eq_ketBra`, `pauliX_eq_ketBra`, `pauliY_eq_ketBra`, `pauliZ_eq_ketBra` — + the four decompositions the exercise asks for: + `I = |0⟩⟨0| + |1⟩⟨1|`, `X = |0⟩⟨1| + |1⟩⟨0|`, + `Y = -i|0⟩⟨1| + i|1⟩⟨0|`, `Z = |0⟩⟨0| - |1⟩⟨1|`. + +## Design notes + +* The Pauli matrices are already modelled as raw `2 × 2` matrices in + `Concrete.Pauli`, and Mathlib's outer product `Matrix.vecMulVec` takes plain + `Fin 2 → ℂ` column vectors, so the whole exercise stays at the matrix level: no + `EuclideanSpace`/`LinearMap` machinery is needed to say "express the matrix as a + sum of outer products". The `star` in `ketBra` makes the bra a genuine conjugate + dual (faithful to N&C's `|i⟩⟨j|`); on the real basis vectors it is inert, which is + why the decompositions reduce to entrywise `2 × 2` computations. +* Each decomposition is its own named theorem (not one monolithic conjunction), and + the coefficients are read directly off the matrix: the coefficient of `|a⟩⟨b|` is + the `(a, b)` entry of the Pauli matrix. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The Pauli `I` matrix (`σ₀` in Nielsen & Chuang's Figure 2.2): the `2 × 2` identity +`!![1, 0; 0, 1]`. -/ +def pauliI : Matrix (Fin 2) (Fin 2) ℂ := 1 + +/-- The computational-basis ket `|i⟩` of `ℂ²`, as a column vector `Fin 2 → ℂ`: +`|0⟩ = (1, 0)` and `|1⟩ = (0, 1)`. Concretely the standard basis vector `Pi.single i 1`. -/ +def ket (i : Fin 2) : Fin 2 → ℂ := Pi.single i 1 + +/-- The outer product `|i⟩⟨j|` of two computational-basis vectors, as a `2 × 2` matrix. +Following Nielsen & Chuang eq. (2.20) the bra `⟨j|` is the conjugate transpose of `|j⟩`, +so `ketBra i j = vecMulVec |i⟩ (star |j⟩)` has `(a, b)` entry `|i⟩ₐ · conj(|j⟩_b)`. -/ +def ketBra (i j : Fin 2) : Matrix (Fin 2) (Fin 2) ℂ := vecMulVec (ket i) (star (ket j)) + +/-- The `(a, b)` entry of `|i⟩⟨j|` is `1` when `a = i` and `b = j`, and `0` otherwise. -/ +theorem ketBra_apply (i j a b : Fin 2) : + ketBra i j a b = if a = i ∧ b = j then 1 else 0 := by + simp only [ketBra, ket, vecMulVec_apply, Pi.single_apply] + by_cases ha : a = i <;> by_cases hb : b = j <;> simp [ha, hb] + +/-- The outer product `|i⟩⟨j|` of two computational-basis vectors is the matrix unit +`single i j 1` (a single `1` in row `i`, column `j`): outer products of an orthonormal +basis are the standard basis matrices. -/ +theorem ketBra_eq_single (i j : Fin 2) : ketBra i j = Matrix.single i j 1 := by + ext a b + rw [ketBra_apply, Matrix.single_apply] + simp [eq_comm] + +/-- **Nielsen & Chuang, Exercise 2.9** for `σ₀`: `I = |0⟩⟨0| + |1⟩⟨1|` (the +completeness relation for the computational basis). -/ +theorem pauliI_eq_ketBra : pauliI = ketBra 0 0 + ketBra 1 1 := by + ext a b + fin_cases a <;> fin_cases b <;> simp [pauliI, ketBra_apply] + +/-- **Nielsen & Chuang, Exercise 2.9** for `σ₁ = X`: `X = |0⟩⟨1| + |1⟩⟨0|`. -/ +theorem pauliX_eq_ketBra : pauliX = ketBra 0 1 + ketBra 1 0 := by + ext a b + fin_cases a <;> fin_cases b <;> simp [pauliX, ketBra_apply] + +/-- **Nielsen & Chuang, Exercise 2.9** for `σ₂ = Y`: `Y = -i|0⟩⟨1| + i|1⟩⟨0|`. -/ +theorem pauliY_eq_ketBra : pauliY = (-I) • ketBra 0 1 + I • ketBra 1 0 := by + ext a b + fin_cases a <;> fin_cases b <;> simp [pauliY, ketBra_apply] + +/-- **Nielsen & Chuang, Exercise 2.9** for `σ₃ = Z`: `Z = |0⟩⟨0| - |1⟩⟨1|`. -/ +theorem pauliZ_eq_ketBra : pauliZ = ketBra 0 0 - ketBra 1 1 := by + ext a b + fin_cases a <;> fin_cases b <;> simp [pauliZ, ketBra_apply] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliString.lean b/LeanPool/AxQM/Concrete/PauliString.lean new file mode 100644 index 0000000000..3ab5ff8e14 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliString.lean @@ -0,0 +1,307 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Pauli +public import LeanPool.AxQM.ToMathlib.Analysis.Matrix.HilbertSchmidt +public import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas +public import Mathlib.Algebra.BigOperators.Ring.Finset +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin + +/-! +# Concrete: the `n`-fold Pauli strings and the Pauli basis of `M₂ₙ(ℂ)` + +This file builds, for each `n`, the family of **`n`-fold Pauli tensor products** ("Pauli strings") +and proves that they form a basis of the `2ⁿ × 2ⁿ` complex matrices, with a **real-coefficient** +expansion for every Hermitian matrix. This is the mathematical content underlying part (2) of +Nielsen & Chuang, Problem 4.3 (`H = Σ_g h_g g` with real `h_g`, the sum over all `n`-fold tensor +products `g` of `{I, X, Y, Z}`) — see [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean). + +## The construction + +An `n`-qubit register carries the index type `Fin n → Fin 2` (a bit-string of length `n`), of +cardinality `2ⁿ`, so its operators are `Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ`. A Pauli +string is indexed by `g : Fin n → Fin 4` (a choice of one of `σ₀ = I, σ₁ = X, σ₂ = Y, σ₃ = Z` +per qubit) and defined **entrywise** as the product of the per-qubit Pauli entries: + +`pauliString g i j = ∏ k, pauli (g k) (i k) (j k)`. + +Working with the entrywise product (rather than an iterated Kronecker product) keeps the trace +algebra a single `Finset.prod_univ_sum` factorisation. + +The single-qubit trace orthogonality `tr(σᵢ σⱼ) = 2 δᵢⱼ` it rests on (`Concrete.pauli_trace_mul`) +lives with the `pauli` family in `Concrete/Pauli.lean`. + +## What is proved + +* `pauliString` / `pauliString_apply` — the Pauli string and its defining entry formula. +* `pauliString_isHermitian` — each Pauli string is Hermitian (a product of Hermitian factors). +* `pauliString_trace_mul` — the **trace orthogonality** `tr(P_g P_h) = 2ⁿ δ_{g h}`, the + `n`-fold Hilbert–Schmidt orthogonality of the Pauli strings. +* `pauliString_linearIndependent` — the `4ⁿ` Pauli strings are `ℂ`-linearly independent + (immediate from trace orthogonality). +* `pauliBasis` — hence they form a **basis** of `M₂ₙ(ℂ)` (a linearly independent family of + `finrank = 4ⁿ` vectors). +* `exists_real_pauliString_expansion` — every **Hermitian** matrix is a **real**-coefficient + linear combination of Pauli strings, `M = Σ_g (h_g : ℂ) • P_g` with `h_g : ℝ`. This is the + faithful matrix-level statement of Problem 4.3(2). +* `pauliStringStd` / `pauliStringStd_isHermitian` — the same Pauli string reindexed to the flat + `Fin (2ⁿ)` computational-basis ordering (via `finFunctionFinEquiv`), still Hermitian; the form + ready to be promoted to an operator on the standard register `EuclideanSpace ℂ (Fin (2ⁿ))`. + +## Design notes + +* The index type is `Fin n → Fin 2` rather than `Fin (2ⁿ)`; this makes the per-qubit product + structure literal and lets `Finset.prod_univ_sum` collapse the double trace sum + `∑ᵢ ∑ⱼ ∏ₖ (…)` into `∏ₖ ∑ₐ ∑_b (…) = ∏ₖ tr(σ_{gₖ} σ_{hₖ})`. +* The coefficients are real because, for Hermitian `A`, `B`, the trace `tr(A B)` is real + (`Matrix.IsHermitian.im_trace_mul`, in `ToMathlib`): `conj tr(AB) = tr((AB)ᴴ) = tr(BA) + = tr(AB)`. +-/ + +@[expose] public section + +open Matrix Complex + +open scoped BigOperators + +namespace AxQM.Concrete + +/-! ### The `n`-fold Pauli strings + +The single-qubit facts `pauli_isHermitian`, `pauli_conj_apply` and the trace orthogonality +`pauli_trace_mul` (`tr(σᵢ σⱼ) = 2 δᵢⱼ`) live with the `pauli` family in `Concrete/Pauli.lean`. -/ + +variable {n : ℕ} + +/-- The `n`-fold **Pauli string** for `g : Fin n → Fin 4`, the operator on the `n`-qubit +register (index type `Fin n → Fin 2`) whose `(i, j)` entry is the product of the per-qubit Pauli +entries `∏ₖ σ_{gₖ} (iₖ) (jₖ)`. Entrywise, this is the tensor product `σ_{g₀} ⊗ ⋯ ⊗ σ_{g_{n-1}}`. -/ +def pauliString (g : Fin n → Fin 4) : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + fun i j => ∏ k, pauli (g k) (i k) (j k) + +@[simp] +theorem pauliString_apply (g : Fin n → Fin 4) (i j : Fin n → Fin 2) : + pauliString g i j = ∏ k, pauli (g k) (i k) (j k) := rfl + +/-- Each Pauli string is Hermitian: its `(i, j)` entry is a product of factors each Hermitian, +so conjugating and transposing returns the same product (`pauli_conj_apply` per factor). -/ +theorem pauliString_isHermitian (g : Fin n → Fin 4) : (pauliString g).IsHermitian := by + ext i j + rw [Matrix.conjTranspose_apply, pauliString_apply, pauliString_apply, ← starRingEnd_apply, + map_prod] + refine Finset.prod_congr rfl fun k _ => ?_ + rw [starRingEnd_apply, pauli_conj_apply] + +/-- The **all-identity Pauli string** `σ₀ ⊗ ⋯ ⊗ σ₀ = I ⊗ ⋯ ⊗ I` is the identity matrix. Its +`(i, j)` entry is `∏ₖ σ₀ (iₖ) (jₖ) = ∏ₖ (1 : M₂(ℂ)) (iₖ) (jₖ) = ∏ₖ [iₖ = jₖ]`, which is `1` +exactly when `i = j`. (A structural fact about `pauliString`; it isolates the string whose trace +pairing is `tr M` itself, used by the tomographic trace-normalisation refinement.) -/ +theorem pauliString_const_zero : pauliString (n := n) (fun _ => 0) = 1 := by + ext i j + rw [pauliString_apply, Matrix.one_apply] + have h0 : (pauli 0) = (1 : Matrix (Fin 2) (Fin 2) ℂ) := rfl + simp only [h0, Matrix.one_apply] + by_cases hij : i = j + · subst hij; simp + · rw [ite_eq_right hij] + obtain ⟨k, hk⟩ := Function.ne_iff.mp hij + exact Finset.prod_eq_zero (Finset.mem_univ k) (ite_eq_right hk) + +/-- The trace of a product of two matrices given by per-qubit entry products factors over the +qubits: `tr((∏ₖ Aₖ) (∏ₖ Bₖ)) = ∏ₖ tr(Aₖ Bₖ)`, where the two matrices have `(i,j)` entries +`∏ₖ Aₖ(iₖ)(jₖ)` and `∏ₖ Bₖ(iₖ)(jₖ)`. This is the algebraic heart of the Hilbert–Schmidt +orthogonality of the Pauli strings; it collapses the double sum `∑ᵢ ∑ⱼ` via +`Finset.prod_univ_sum`. -/ +private theorem trace_mul_prodMatrix (A B : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + ((Matrix.of fun i j : Fin n → Fin 2 => ∏ k, A k (i k) (j k)) * + (Matrix.of fun i j : Fin n → Fin 2 => ∏ k, B k (i k) (j k))).trace + = ∏ k, (A k * B k).trace := by + -- RHS: expand each factor `tr(Aₖ Bₖ) = ∑ a, ∑ b, Aₖ a b * Bₖ b a`, then two `prod_univ_sum` + -- collapse `∏ₖ ∑ₐ ∑_b` into the double sum `∑ᵢ ∑ⱼ ∏ₖ`. + have hRHS : (∏ k, (A k * B k).trace) + = ∑ i : Fin n → Fin 2, ∑ j : Fin n → Fin 2, + ∏ k, A k (i k) (j k) * B k (j k) (i k) := by + simp only [Matrix.trace, Matrix.diag_apply, Matrix.mul_apply] + rw [Finset.prod_univ_sum, Fintype.piFinset_univ] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Finset.prod_univ_sum, Fintype.piFinset_univ] + rw [hRHS] + simp only [Matrix.trace, Matrix.diag_apply, Matrix.mul_apply, Matrix.of_apply, + ← Finset.prod_mul_distrib] + +/-- **Trace orthogonality of the Pauli strings**: `tr(P_g P_h) = 2ⁿ δ_{g h}`. Since each Pauli +string is Hermitian, this is the `n`-fold Hilbert–Schmidt orthogonality of the family — the +crucial fact making them a basis. It factors over qubits (`trace_mul_prodMatrix`) into a product +of single-qubit traces `tr(σ_{gₖ} σ_{hₖ}) = 2 δ_{gₖ hₖ}` (`pauli_trace_mul`); the product is `2ⁿ` +when `g = h` and vanishes as soon as one factor differs. -/ +theorem pauliString_trace_mul (g h : Fin n → Fin 4) : + (pauliString g * pauliString h).trace = if g = h then (2 : ℂ) ^ n else 0 := by + have hfac : (pauliString g * pauliString h).trace + = ∏ k, (pauli (g k) * pauli (h k)).trace := + trace_mul_prodMatrix (fun k => pauli (g k)) (fun k => pauli (h k)) + rw [hfac] + simp_rw [pauli_trace_mul] + by_cases hgh : g = h + · subst hgh; simp + · rw [ite_eq_right hgh] + obtain ⟨k, hk⟩ := Function.ne_iff.mp hgh + exact Finset.prod_eq_zero (Finset.mem_univ k) (ite_eq_right hk) + +/-- **Trace of a single Pauli string**: `tr(P_h) = 2ⁿ` when `h` is the identity index and `0` +otherwise. Immediate from the Hilbert–Schmidt orthogonality `pauliString_trace_mul` (with the +identity `pauliString 0 = 1`, `pauliString_const_zero`). -/ +theorem pauliString_trace (h : Fin n → Fin 4) : + (pauliString h).trace = if h = 0 then (2 : ℂ) ^ n else 0 := by + have hz : pauliString (0 : Fin n → Fin 4) = 1 := pauliString_const_zero + have hmul := pauliString_trace_mul h (0 : Fin n → Fin 4) + rw [hz, mul_one] at hmul + rw [hmul] + +/-- **Trace pairing extracts a coefficient**: `tr(P_m * ∑_g c_g • P_g) = c_m · 2ⁿ`. Only the +`g = m` term survives the Hilbert–Schmidt orthogonality `pauliString_trace_mul`, contributing +`c_m · 2ⁿ`. This coefficient-extraction identity underlies both `pauliString_linearIndependent` +and `exists_real_pauliString_expansion`. -/ +theorem pauliString_trace_mul_sum_smul (c : (Fin n → Fin 4) → ℂ) (m : Fin n → Fin 4) : + (pauliString m * ∑ g, c g • pauliString g).trace = c m * (2 : ℂ) ^ n := by + rw [Finset.mul_sum, Matrix.trace_sum, Finset.sum_eq_single m] + · rw [mul_smul_comm, Matrix.trace_smul, pauliString_trace_mul, ite_eq_left rfl, smul_eq_mul] + · intro b _ hb + rw [mul_smul_comm, Matrix.trace_smul, pauliString_trace_mul, ite_eq_right (Ne.symm hb), + smul_zero] + · intro hm; exact absurd (Finset.mem_univ m) hm + +/-! ### The Pauli basis and the real Hermitian expansion -/ + +/-- The `4ⁿ` Pauli strings are `ℂ`-linearly independent. If `∑_g c_g P_g = 0`, testing against +`P_m` under the trace pairing gives `0 = tr(P_m ∑_g c_g P_g) = ∑_g c_g tr(P_m P_g) = c_m 2ⁿ`, +so every `c_m = 0` (using `pauliString_trace_mul` and `2ⁿ ≠ 0`). -/ +theorem pauliString_linearIndependent : LinearIndependent ℂ (pauliString (n := n)) := by + rw [Fintype.linearIndependent_iff] + intro c hc m + have key := pauliString_trace_mul_sum_smul c m + rw [hc, Matrix.mul_zero, Matrix.trace_zero] at key + exact (mul_eq_zero.mp key.symm).resolve_right (pow_ne_zero n two_ne_zero) + +/-- The `n`-fold Pauli strings form a **basis** of the `2ⁿ × 2ⁿ` complex matrices: a linearly +independent family whose cardinality `4ⁿ` equals `finrank ℂ M₂ₙ(ℂ) = (2ⁿ)²` (N&C Ex 2.39(2), +`Matrix.finrank_eq_card_sq`). This is the "the Pauli strings span the operators" half of +Problem 4.3(2). -/ +noncomputable def pauliBasis : + Module.Basis (Fin n → Fin 4) ℂ (Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) := by + haveI : Nonempty (Fin n → Fin 4) := ⟨fun _ => 0⟩ + refine basisOfLinearIndependentOfCardEqFinrank pauliString_linearIndependent ?_ + rw [Matrix.finrank_eq_card_sq] + simp only [Fintype.card_fun, Fintype.card_fin] + rw [pow_two, ← mul_pow] + norm_num + +@[simp] +theorem pauliBasis_apply (g : Fin n → Fin 4) : pauliBasis g = pauliString g := by + rw [pauliBasis] + exact congrFun (coe_basisOfLinearIndependentOfCardEqFinrank _ _) g + +/-- **The Pauli-basis expansion of a matrix**: `∑_g (pauliBasis.repr M g) • P_g = M`. This is just +`pauliBasis.sum_repr` with the basis vectors rewritten to Pauli strings (`pauliBasis_apply`); it is +the foundational identity underlying every trace-pairing extraction. -/ +theorem sum_repr_smul_pauliString (M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + ∑ g, pauliBasis.repr M g • pauliString g = M := by + conv_rhs => rw [← pauliBasis.sum_repr M] + exact Finset.sum_congr rfl fun g _ => by rw [pauliBasis_apply] + +/-- **Trace pairing recovers the Pauli coordinate**: `tr(P_g M) = (pauliBasis.repr M g) · 2ⁿ`. +Writing `M = Σ_h (repr M h) • P_h` in the Pauli basis (`sum_repr_smul_pauliString`) and pairing +against `P_g`, only the `h = g` term survives the Hilbert–Schmidt orthogonality +(`pauliString_trace_mul_sum_smul`). The name is kept distinct from the orthogonality lemma +`pauliString_trace_mul` (`tr(P_g P_h) = 2ⁿ δ_{gh}`). -/ +theorem trace_pauliString_mul_eq_repr (M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + (g : Fin n → Fin 4) : + (pauliString g * M).trace = pauliBasis.repr M g * (2 : ℂ) ^ n := by + have h := pauliString_trace_mul_sum_smul (fun h => pauliBasis.repr M h) g + rwa [sum_repr_smul_pauliString] at h + +/-- **Trace pairing with a Hermitian matrix is real**: `im tr(P_g M) = 0`. Both `P_g` and `M` are +Hermitian, and `tr(A B)` is real for Hermitian `A, B` (`Matrix.IsHermitian.im_trace_mul`). For a +density matrix `M` these are the real Pauli expectation values `⟨P_g⟩` used by state tomography +(`Concrete/PauliTomography.lean`). -/ +theorem trace_pauliString_mul_im {M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (hM : M.IsHermitian) (g : Fin n → Fin 4) : ((pauliString g * M).trace).im = 0 := by + simpa [RCLike.im_to_complex] using (pauliString_isHermitian g).im_trace_mul hM + +/-- **Real-coefficient Pauli expansion of a Hermitian matrix** (Nielsen & Chuang, Problem 4.3(2), +matrix form). Every Hermitian `2ⁿ × 2ⁿ` matrix `M` is a **real** linear combination of the Pauli +strings, `M = Σ_g (h_g : ℂ) • P_g` with `h_g : ℝ`. The complex coefficients are `pauliBasis.repr M`; +each is real because `pauliBasis.repr M g · 2ⁿ = tr(P_g M)` is real (both `P_g` and `M` Hermitian, +`Matrix.IsHermitian.im_trace_mul`), so its imaginary part vanishes. -/ +theorem exists_real_pauliString_expansion + {M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (hM : M.IsHermitian) : + ∃ h : (Fin n → Fin 4) → ℝ, M = ∑ g, (h g : ℂ) • pauliString g := by + have hsum : M = ∑ g, (pauliBasis.repr M g) • pauliString g := + (sum_repr_smul_pauliString M).symm + have hreal : ∀ g, (pauliBasis.repr M g).im = 0 := by + intro g + have htr : (pauliString g * M).trace = pauliBasis.repr M g * (2 : ℂ) ^ n := + trace_pauliString_mul_eq_repr M g + have hreal_tr : ((pauliString g * M).trace).im = 0 := trace_pauliString_mul_im hM g + have h2 : ((2 : ℂ) ^ n) = (((2 : ℝ) ^ n : ℝ) : ℂ) := by push_cast; ring + rw [htr, h2, Complex.mul_im, Complex.ofReal_im, Complex.ofReal_re, mul_zero, zero_add] + at hreal_tr + exact (mul_eq_zero.mp hreal_tr).resolve_right (pow_ne_zero n two_ne_zero) + refine ⟨fun g => (pauliBasis.repr M g).re, ?_⟩ + conv_lhs => rw [hsum] + refine Finset.sum_congr rfl fun g _ => ?_ + have hcoe : ((pauliBasis.repr M g).re : ℂ) = pauliBasis.repr M g := + Complex.ext (by simp) (by simp [hreal g]) + simp only [hcoe] + +/-! ### The Pauli string on the standard `Fin (2ⁿ)` register indexing + +The `n`-qubit register carries two interchangeable index types: the bit strings `Fin n → Fin 2` +used above (which make the per-qubit product structure literal), and the flat `Fin (2ⁿ)` used by +the computational-basis register `EuclideanSpace ℂ (Fin (2ⁿ))`. The two are identified by +`finFunctionFinEquiv : (Fin n → Fin 2) ≃ Fin (2ⁿ)`. This section transports a Pauli string to the +flat indexing, so it can be promoted to an operator on the standard register. -/ + +/-- The `n`-fold **Pauli string on the standard register indexing** `Fin (2ⁿ)`: the matrix +`pauliString g`, reindexed from bit strings `Fin n → Fin 2` to `Fin (2ⁿ)` along +`finFunctionFinEquiv`. Its `(I, J)` entry is `pauliString g (e⁻¹ I) (e⁻¹ J)` for +`e = finFunctionFinEquiv`. This is the same operator as `pauliString g`, expressed on the flat +`Fin (2ⁿ)` computational-basis ordering that the register `EuclideanSpace ℂ (Fin (2ⁿ))` uses. -/ +def pauliStringStd (g : Fin n → Fin 4) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + (pauliString g).submatrix finFunctionFinEquiv.symm finFunctionFinEquiv.symm + +/-- The standard-indexed Pauli string is **Hermitian**: reindexing a Hermitian matrix by the same +map on rows and columns preserves Hermitianness (`Matrix.IsHermitian.submatrix`), and each Pauli +string is Hermitian (`pauliString_isHermitian`). -/ +theorem pauliStringStd_isHermitian (g : Fin n → Fin 4) : (pauliStringStd g).IsHermitian := + (pauliString_isHermitian g).submatrix finFunctionFinEquiv.symm + +/-! ### Injectivity of the Pauli strings -/ + +/-- The Pauli strings are **injective** in their index: distinct `g` give distinct operators `P_g`. +Immediate from their `ℂ`-linear independence (`pauliString_linearIndependent`). -/ +theorem pauliString_injective : Function.Injective (pauliString (n := n)) := + pauliString_linearIndependent.injective + +/-- A Pauli string is the **identity operator** exactly when its index is all-identity: +`P_g = I ↔ g = 0`. The `⇐` direction is `pauliString_const_zero`; the `⇒` direction is injectivity +(`pauliString_injective`). -/ +theorem pauliString_eq_one_iff (g : Fin n → Fin 4) : pauliString g = 1 ↔ g = 0 := by + rw [← pauliString_const_zero, pauliString_injective.eq_iff, Pi.zero_def] + +/-- The **standard-indexed all-identity Pauli string is the identity matrix**: +`pauliStringStd 0 = 1`. Reindexing the identity matrix along an equivalence on both rows and columns +leaves it fixed (`Matrix.submatrix_one_equiv`), and the underlying string is already the identity +(`pauliString_const_zero`). This is the standard-register form of `pauliString_const_zero`, the +`(I, J)`-flat-indexing companion used wherever the identity Pauli string appears (e.g. the +global-phase Trotter summand of the all-identity string). -/ +@[simp] theorem pauliStringStd_zero : pauliStringStd (0 : Fin n → Fin 4) = 1 := by + simp only [pauliStringStd, Pi.zero_def, pauliString_const_zero, Matrix.submatrix_one_equiv] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringBasisChange.lean b/LeanPool/AxQM/Concrete/PauliStringBasisChange.lean new file mode 100644 index 0000000000..27ef267378 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringBasisChange.lean @@ -0,0 +1,331 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliString +public import LeanPool.AxQM.Concrete.HadamardPauliConjugation +public import LeanPool.AxQM.Concrete.AxisAngleGateValues +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.MatrixExponential + +/-! +# Concrete: local single-qubit basis change reducing `X ⊗ Y ⊗ Z` to `Z ⊗ Z ⊗ Z` + +This file supplies the matrix core of Nielsen & Chuang, **Exercise 4.51** — "construct a quantum +circuit to simulate the Hamiltonian `H = X₁ ⊗ Y₂ ⊗ Z₃`, performing `e^{-iΔt H}` for any `Δt`". +The exercise statement is in [upstream `AxQM/NC/Ch4/Exercise4_51.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_51.lean). + +## The construction (N&C §4.7.3) + +N&C's simulation algorithm reduces any tensor-product Pauli Hamiltonian `⊗ₖ σ_{c(k)}` to the +all-`Z` case `Z ⊗ ⋯ ⊗ Z` (whose `e^{-iΔt}` circuit is Figure 4.19, a parity computation into an +ancilla, a conditional phase, and an uncompute) by **single-qubit basis changes**: an `X` or `Y` +factor is conjugated to a `Z` factor by a local unitary. Concretely, with + +* `B₁ = H` (Hadamard): `H · Z · Hᴴ = X` (`hadamardC_mul_pauliZ_mul_hadamardC`); +* `B₂ = S·H` (`basisChangeY`): `(SH) · Z · (SH)ᴴ = Y` (`basisChangeY_conj_pauliZ`); +* `B₃ = I`: `I · Z · Iᴴ = Z`, + +the local tensor unitary `B = B₁ ⊗ B₂ ⊗ B₃` satisfies `B · (Z ⊗ Z ⊗ Z) · Bᴴ = X ⊗ Y ⊗ Z`, and +hence, for any complex scalar `s` (in the exercise `s = -iΔt`), +`exp(s · (X ⊗ Y ⊗ Z)) = B · exp(s · (Z ⊗ Z ⊗ Z)) · Bᴴ`. Applying `B` locally, running the `Z⊗Z⊗Z` +simulation, and undoing `B` is the circuit for `e^{-iΔt H}`. + +## What is proved + +* `kronFamily` — the `n`-fold tensor product `⨂ₖ Aₖ` of a family of single-qubit operators, + defined entrywise `(⨂ₖ Aₖ)(i,j) = ∏ₖ Aₖ(iₖ)(jₖ)` on the register index `Fin n → Fin 2`, + matching the entrywise form of `pauliString` (so `pauliString g = ⨂ₖ σ_{gₖ}`, + `pauliString_eq_kronFamily`). +* `kronFamily_mul` — the **mixed-product property** `(⨂ₖ Aₖ)(⨂ₖ Bₖ) = ⨂ₖ (Aₖ Bₖ)`, the + algebraic engine of the reduction; `kronFamily_conjTranspose` (`(⨂ₖ Aₖ)ᴴ = ⨂ₖ Aₖᴴ`), + `kronFamily_one` (`⨂ₖ 1 = 1`) and `kronFamily_smul_family` (`⨂ₖ (cₖ • Aₖ) = (∏ₖ cₖ) • ⨂ₖ Aₖ`) + are its unit/adjoint/scalar companions. +* `basisChangeY` / `sMatrix_conj_pauliX` / `sMatrix_conj_pauliY` / `sMatrix_conj_pauliZ` / + `basisChangeY_conj_pauliZ` — the `Y` basis-change gate `S·H`, the single-qubit phase-gate tableau + `S·X·Sᴴ = Y`, `S·Y·Sᴴ = -X`, `S·Z·Sᴴ = Z` (N&C Ex 10.39), and `(SH)·Z·(SH)ᴴ = Y`. +* `pauliString_conj_kronFamily` — the operator identity `B · (Z⊗Z⊗Z) · Bᴴ = X⊗Y⊗Z`, and +* `pauliString_exp_smul_conj_kronFamily` — its exponentiated form `exp(s·(X⊗Y⊗Z)) = + B · exp(s·(Z⊗Z⊗Z)) · Bᴴ` for any `s : ℂ` (via `Matrix.exp_units_conj`, `B` unitary). +-/ + +@[expose] public section + +open Matrix Complex + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The `n`-fold tensor product of single-qubit operators -/ + +/-- The **`n`-fold tensor product** `A₀ ⊗ A₁ ⊗ ⋯ ⊗ A_{n-1}` of a family of single-qubit operators +`A : Fin n → M₂(ℂ)`, as an operator on the `n`-qubit register `Fin n → Fin 2`, defined entrywise by +the product of the per-qubit entries `(⨂ₖ Aₖ)(i,j) = ∏ₖ Aₖ(iₖ)(jₖ)`. This matches the entrywise +form of `pauliString` (`pauliString g = kronFamily (σ_{g·})`, `pauliString_eq_kronFamily`), so the +mixed-product property `kronFamily_mul` conjugates a Pauli string factor-by-factor. -/ +def kronFamily (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + fun i j => ∏ k, A k (i k) (j k) + +@[simp] +theorem kronFamily_apply (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) (i j : Fin n → Fin 2) : + kronFamily A i j = ∏ k, A k (i k) (j k) := rfl + +/-- A Pauli string is the tensor product of its per-qubit Pauli factors: +`pauliString g = kronFamily (fun k => pauli (g k))`. Definitional, since both are the entrywise +product `∏ₖ σ_{gₖ}(iₖ)(jₖ)`. -/ +theorem pauliString_eq_kronFamily (g : Fin n → Fin 4) : + pauliString g = kronFamily (fun k => pauli (g k)) := rfl + +/-- **Mixed-product property of the tensor product** `(⨂ₖ Aₖ)(⨂ₖ Bₖ) = ⨂ₖ (Aₖ Bₖ)`. The `(i,j)` +entry of the product, `∑_l (∏ₖ Aₖ(iₖ)(lₖ))(∏ₖ Bₖ(lₖ)(jₖ))`, collapses under `Finset.prod_univ_sum` +into `∏ₖ ∑ₐ Aₖ(iₖ)(a) Bₖ(a)(jₖ) = ∏ₖ (Aₖ Bₖ)(iₖ)(jₖ)`: summing over intermediate register states +`l` is choosing an intermediate index per qubit. This is the algebraic engine of the basis-change +reduction (conjugation acts factor-by-factor). -/ +theorem kronFamily_mul (A B : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + kronFamily A * kronFamily B = kronFamily (fun k => A k * B k) := by + ext i j + simp only [kronFamily, Matrix.mul_apply] + rw [Finset.prod_univ_sum, Fintype.piFinset_univ] + exact Finset.sum_congr rfl fun l _ => Finset.prod_mul_distrib.symm + +/-- The conjugate transpose of a tensor product is the tensor product of the conjugate transposes, +`(⨂ₖ Aₖ)ᴴ = ⨂ₖ Aₖᴴ`. Entrywise, `star (∏ₖ Aₖ(jₖ)(iₖ)) = ∏ₖ star (Aₖ(jₖ)(iₖ)) = ∏ₖ Aₖᴴ(iₖ)(jₖ)` +(`map_prod` of the ring conjugation). -/ +theorem kronFamily_conjTranspose (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + (kronFamily A)ᴴ = kronFamily (fun k => (A k)ᴴ) := by + ext i j + rw [Matrix.conjTranspose_apply, kronFamily_apply, kronFamily_apply, ← starRingEnd_apply, + map_prod] + exact Finset.prod_congr rfl fun k _ => by rw [starRingEnd_apply, Matrix.conjTranspose_apply] + +/-- The tensor product of identities is the identity, `⨂ₖ 1 = 1`. Entrywise +`∏ₖ (if iₖ = jₖ then 1 else 0)` is `1` when `i = j` (every factor `1`) and `0` otherwise (some +qubit factor vanishes). -/ +theorem kronFamily_one : kronFamily (fun _ : Fin n => (1 : Matrix (Fin 2) (Fin 2) ℂ)) = 1 := by + ext i j + simp only [kronFamily_apply, Matrix.one_apply] + by_cases h : i = j + · subst h; simp + · rw [ite_eq_right h] + obtain ⟨k, hk⟩ := Function.ne_iff.mp h + exact Finset.prod_eq_zero (Finset.mem_univ k) (ite_eq_right hk) + +/-- Pulling per-qubit scalars out of a tensor product: `⨂ₖ (cₖ • Aₖ) = (∏ₖ cₖ) • ⨂ₖ Aₖ`. Entrywise +the `(i, j)` entry is `∏ₖ cₖ Aₖ(iₖ)(jₖ) = (∏ₖ cₖ)(∏ₖ Aₖ(iₖ)(jₖ))` by `Finset.prod_mul_distrib`. -/ +theorem kronFamily_smul_family (c : Fin n → ℂ) (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + kronFamily (fun k => c k • A k) = (∏ k, c k) • kronFamily A := by + ext i j + simp only [kronFamily_apply, Matrix.smul_apply, smul_eq_mul] + rw [Finset.prod_mul_distrib] + +/-! ### The single-qubit basis-change gates -/ + +/-- The **`Y` basis-change gate** `S·H` (phase gate after Hadamard): the single-qubit unitary that +conjugates `Z` to `Y` (`basisChangeY_conj_pauliZ`). It is the composite reducing a `Y` factor of a +Pauli Hamiltonian to a `Z` factor (N&C §4.7.3); `H` alone reduces an `X` factor. -/ +noncomputable def basisChangeY : Matrix (Fin 2) (Fin 2) ℂ := sMatrix * hadamardC + +/-- **Phase-gate conjugation** `S·X·Sᴴ = Y` (N&C Exercise 10.39): the phase gate `S = diag(1, i)` +rotates `X` into `Y`. A direct `2 × 2` computation. -/ +theorem sMatrix_conj_pauliX : sMatrix * pauliX * sMatrixᴴ = pauliY := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sMatrix, pauliX, pauliY, Matrix.mul_apply, Fin.sum_univ_two, + Matrix.conjTranspose_apply] + +/-- **Phase-gate conjugation** `S·Y·Sᴴ = -X` (N&C Exercise 10.39): the phase gate `S = diag(1, i)` +rotates `Y` into `-X`. A direct `2 × 2` computation. -/ +theorem sMatrix_conj_pauliY : sMatrix * pauliY * sMatrixᴴ = -pauliX := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sMatrix, pauliX, pauliY, Matrix.mul_apply, Fin.sum_univ_two, + Matrix.conjTranspose_apply] + +/-- **Phase-gate conjugation** `S·Z·Sᴴ = Z` (N&C Exercise 10.39): the phase gate `S = diag(1, i)` +fixes `Z`. A direct `2 × 2` computation. -/ +theorem sMatrix_conj_pauliZ : sMatrix * pauliZ * sMatrixᴴ = pauliZ := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sMatrix, pauliZ, Matrix.mul_apply, Fin.sum_univ_two, Matrix.conjTranspose_apply] + +/-- The `Y` basis-change gate conjugates `Z` to `Y`: `(SH) · Z · (SH)ᴴ = Y`. Splitting the +adjoint `(SH)ᴴ = H·Sᴴ` (Hadamard Hermitian) and regrouping, this is `S·(H·Z·H)·Sᴴ = S·X·Sᴴ = Y` +via `hadamardC_mul_pauliZ_mul_hadamardC` and `sMatrix_conj_pauliX`. -/ +theorem basisChangeY_conj_pauliZ : basisChangeY * pauliZ * basisChangeYᴴ = pauliY := by + have hHadj : hadamardCᴴ = hadamardC := hadamardC_isHermitian + rw [basisChangeY, Matrix.conjTranspose_mul, hHadj, ← sMatrix_conj_pauliX, + ← hadamardC_mul_pauliZ_mul_hadamardC] + simp only [Matrix.mul_assoc] + +/-- The `Y` basis-change gate is unitary: `(SH)(SH)ᴴ = 1`. Both `S` and `H` are unitary, so +`SH·(SH)ᴴ = S·(H·Hᴴ)·Sᴴ = S·Sᴴ = 1` (`hadamardC_mul_self`, `sMatrix_mem_unitaryGroup`). -/ +theorem basisChangeY_mul_conjTranspose : basisChangeY * basisChangeYᴴ = 1 := by + have hHadj : hadamardCᴴ = hadamardC := hadamardC_isHermitian + have hS : sMatrix * sMatrixᴴ = 1 := Matrix.mem_unitaryGroup_iff.mp sMatrix_mem_unitaryGroup + rw [basisChangeY, Matrix.conjTranspose_mul, hHadj] + rw [Matrix.mul_assoc, ← Matrix.mul_assoc hadamardC, hadamardC_mul_self, Matrix.one_mul, hS] + +/-- The `Y` basis-change gate is unitary: `(SH)ᴴ(SH) = 1`. As `basisChangeY_mul_conjTranspose` +with the factors reversed (`Sᴴ·(Hᴴ·H)·... `). -/ +theorem basisChangeY_conjTranspose_mul : basisChangeYᴴ * basisChangeY = 1 := by + have hHadj : hadamardCᴴ = hadamardC := hadamardC_isHermitian + have hS : sMatrixᴴ * sMatrix = 1 := Matrix.mem_unitaryGroup_iff'.mp sMatrix_mem_unitaryGroup + rw [basisChangeY, Matrix.conjTranspose_mul, hHadj] + rw [Matrix.mul_assoc, ← Matrix.mul_assoc sMatrixᴴ, hS, Matrix.one_mul, hadamardC_mul_self] + +/-! ### The three-qubit basis-change reduction `X ⊗ Y ⊗ Z = B (Z ⊗ Z ⊗ Z) Bᴴ` -/ + +/-- The **local basis-change family** `B = (B₁, B₂, B₃) = (H, SH, I)` for Exercise 4.51: the three +single-qubit gates whose tensor product `kronFamily basisChangeFamily` conjugates `Z ⊗ Z ⊗ Z` to +`X ⊗ Y ⊗ Z`. Qubit 1 (`X`) is reduced by Hadamard, qubit 2 (`Y`) by `S·H`, qubit 3 (`Z`) is left +alone. -/ +noncomputable def basisChangeFamily : Fin 3 → Matrix (Fin 2) (Fin 2) ℂ := + ![hadamardC, basisChangeY, 1] + +/-- Each local gate `Bₖ` conjugates `Z` to the target Pauli `σ_{c(k)}` of `X ⊗ Y ⊗ Z`: +`Bₖ · Z · Bₖᴴ = pauli (![1,2,3] k)` (i.e. `X`, `Y`, `Z` for `k = 0, 1, 2`). The per-qubit inputs to +`pauliString_conj_kronFamily`. -/ +theorem basisChangeFamily_conj_pauliZ (k : Fin 3) : + basisChangeFamily k * pauliZ * (basisChangeFamily k)ᴴ = pauli (![1, 2, 3] k) := by + fin_cases k + · simpa [basisChangeFamily, pauli] using + (by rw [hadamardC_isHermitian]; exact hadamardC_mul_pauliZ_mul_hadamardC : + hadamardC * pauliZ * hadamardCᴴ = pauliX) + · simpa [basisChangeFamily, pauli] using basisChangeY_conj_pauliZ + · simp [basisChangeFamily, pauli] + +/-- Each local gate `Bₖ` is unitary: `Bₖ · Bₖᴴ = 1`. The per-qubit inputs to the unitarity of +`kronFamily basisChangeFamily`. -/ +theorem basisChangeFamily_mul_conjTranspose (k : Fin 3) : + basisChangeFamily k * (basisChangeFamily k)ᴴ = 1 := by + fin_cases k + · simpa [basisChangeFamily] using + (by rw [hadamardC_isHermitian]; exact hadamardC_mul_self : + hadamardC * hadamardCᴴ = 1) + · simpa [basisChangeFamily] using basisChangeY_mul_conjTranspose + · simp [basisChangeFamily] + +/-- Each local gate `Bₖ` is unitary: `Bₖᴴ · Bₖ = 1`. -/ +theorem basisChangeFamily_conjTranspose_mul (k : Fin 3) : + (basisChangeFamily k)ᴴ * basisChangeFamily k = 1 := by + fin_cases k + · simpa [basisChangeFamily] using + (by rw [hadamardC_isHermitian]; exact hadamardC_mul_self : + hadamardCᴴ * hadamardC = 1) + · simpa [basisChangeFamily] using basisChangeY_conjTranspose_mul + · simp [basisChangeFamily] + +/-- **Exercise 4.51, matrix form: the basis-change reduction of the tensor Pauli Hamiltonian.** +The local tensor unitary `B = H ⊗ SH ⊗ I` conjugates the all-`Z` Hamiltonian to the target: +`B · (Z ⊗ Z ⊗ Z) · Bᴴ = X ⊗ Y ⊗ Z`. Reducing both Pauli strings to `kronFamily` and applying the +mixed-product property twice (`kronFamily_mul`, `kronFamily_conjTranspose`) turns the left side into +`⨂ₖ (Bₖ · Z · Bₖᴴ)`, which is `⨂ₖ σ_{c(k)} = X ⊗ Y ⊗ Z` factor-by-factor +(`basisChangeFamily_conj_pauliZ`). -/ +theorem pauliString_conj_kronFamily : + kronFamily basisChangeFamily * pauliString ![3, 3, 3] * (kronFamily basisChangeFamily)ᴴ + = pauliString ![1, 2, 3] := by + have hZ : pauliString (![3, 3, 3] : Fin 3 → Fin 4) = kronFamily (fun _ => pauliZ) := by + rw [pauliString_eq_kronFamily] + congr 1 + funext k + fin_cases k <;> simp [pauli] + rw [hZ, kronFamily_conjTranspose, kronFamily_mul, kronFamily_mul, pauliString_eq_kronFamily] + congr 1 + funext k + exact basisChangeFamily_conj_pauliZ k + +/-- The tensor unitary `B = H ⊗ SH ⊗ I` is unitary: `B · Bᴴ = 1`. Factor-by-factor from the +per-qubit unitarity (`basisChangeFamily_mul_conjTranspose`), via `kronFamily_mul`, `kronFamily_one`. +-/ +theorem kronFamily_basisChangeFamily_mul_conjTranspose : + kronFamily basisChangeFamily * (kronFamily basisChangeFamily)ᴴ = 1 := by + rw [kronFamily_conjTranspose, kronFamily_mul] + simp only [basisChangeFamily_mul_conjTranspose, kronFamily_one] + +/-- The tensor unitary `B = H ⊗ SH ⊗ I` is unitary: `Bᴴ · B = 1`. -/ +theorem kronFamily_basisChangeFamily_conjTranspose_mul : + (kronFamily basisChangeFamily)ᴴ * kronFamily basisChangeFamily = 1 := by + rw [kronFamily_conjTranspose, kronFamily_mul] + simp only [basisChangeFamily_conjTranspose_mul, kronFamily_one] + +/-- **Exercise 4.51, exponentiated form: the circuit for `e^{-iΔt H}`.** For any complex scalar +`s` (physically `s = -iΔt`), the propagator of the target Hamiltonian is the local conjugation of +the all-`Z` propagator: `exp(s · (X ⊗ Y ⊗ Z)) = B · exp(s · (Z ⊗ Z ⊗ Z)) · Bᴴ`. Since `s • H` is +conjugated by `B` exactly as `H` is (`pauliString_conj_kronFamily`), and `B` is unitary — hence a +unit with inverse `Bᴴ` — `Matrix.exp_units_conj` pushes the conjugation through the exponential. +This is the algebraic content of "apply the local basis changes `B`, run the `Z ⊗ Z ⊗ Z` +simulation of Figure 4.19, undo `B`". -/ +theorem pauliString_exp_smul_conj_kronFamily (s : ℂ) : + NormedSpace.exp (s • pauliString ![1, 2, 3]) + = kronFamily basisChangeFamily * NormedSpace.exp (s • pauliString ![3, 3, 3]) + * (kronFamily basisChangeFamily)ᴴ := by + let u : (Matrix (Fin 3 → Fin 2) (Fin 3 → Fin 2) ℂ)ˣ := + ⟨kronFamily basisChangeFamily, (kronFamily basisChangeFamily)ᴴ, + kronFamily_basisChangeFamily_mul_conjTranspose, + kronFamily_basisChangeFamily_conjTranspose_mul⟩ + have hconj : s • pauliString ![1, 2, 3] + = kronFamily basisChangeFamily * (s • pauliString ![3, 3, 3]) + * (kronFamily basisChangeFamily)ᴴ := by + rw [← pauliString_conj_kronFamily, Matrix.mul_smul, Matrix.smul_mul] + rw [hconj] + exact Matrix.exp_units_conj u (s • pauliString ![3, 3, 3]) + +/-! ### The flat computational-basis (register) indexing `Fin (2ⁿ)` -/ + +/-- Reindexing a register-conjugation `W A Wᴴ` by a bijection `e` distributes over the three +factors: `(W A Wᴴ).submatrix e e = (W.submatrix e e)(A.submatrix e e)(W.submatrix e e)ᴴ`. This is +the transport carrying the bit-string statements (`kronFamily`, `pauliString`) to the flat +`Fin (2ⁿ)` indexing of `pauliStringStd`, since `submatrix` by an equiv on both indices is a +`⋆`-algebra map (`Matrix.submatrix_mul_equiv`, `Matrix.conjTranspose_submatrix`). -/ +theorem submatrix_conj_equiv {m l : Type*} [Fintype m] [Fintype l] + (e : l ≃ m) (W A : Matrix m m ℂ) : + (W * A * Wᴴ).submatrix e e + = W.submatrix e e * A.submatrix e e * (W.submatrix e e)ᴴ := by + rw [Matrix.conjTranspose_submatrix, Matrix.submatrix_mul_equiv, Matrix.submatrix_mul_equiv] + +/-- The **Std-indexed tensor product** `⨂ₖ Aₖ` on the flat register `Fin (2ⁿ)`: `kronFamily A` +reindexed from bit strings `Fin n → Fin 2` to `Fin (2ⁿ)` along `finFunctionFinEquiv`, exactly as +`pauliStringStd` reindexes `pauliString`. This is the operator `B = ⨂ₖ Aₖ` in the flat +computational-basis ordering that the `n`-qubit register `qudit (2ⁿ)` uses; the physics wrapper +(`Postulates/API/PauliStringSimulation.lean`) promotes `kronFamilyStd basisChangeFamily` to a +unitary `Evolution`. -/ +noncomputable def kronFamilyStd (A : Fin n → Matrix (Fin 2) (Fin 2) ℂ) : + Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + (kronFamily A).submatrix finFunctionFinEquiv.symm finFunctionFinEquiv.symm + +/-- **Exercise 4.51, the reduction on the flat register `Fin (2³)`.** The Std-indexed basis change +`B = H ⊗ SH ⊗ I` conjugates the all-`Z` string to the target: `B · (Z⊗Z⊗Z) · Bᴴ = X⊗Y⊗Z`, on the +`Fin (2³)` computational basis that `pauliStringStd` (and the register `qudit (2³)`) use. The flat +image of `pauliString_conj_kronFamily`, obtained by `submatrix_conj_equiv`. -/ +theorem kronFamilyStd_basisChangeFamily_conj_pauliStringStd : + kronFamilyStd basisChangeFamily * pauliStringStd ![3, 3, 3] + * (kronFamilyStd basisChangeFamily)ᴴ + = pauliStringStd ![1, 2, 3] := by + simp only [kronFamilyStd, pauliStringStd] + rw [← submatrix_conj_equiv, pauliString_conj_kronFamily] + +/-- The Std basis change is unitary: `B · Bᴴ = 1` on `Fin (2³)`. The flat image of +`kronFamily_basisChangeFamily_mul_conjTranspose` (`submatrix` of `1` by an equiv is `1`). -/ +theorem kronFamilyStd_basisChangeFamily_mul_conjTranspose : + kronFamilyStd basisChangeFamily * (kronFamilyStd basisChangeFamily)ᴴ = 1 := by + simp only [kronFamilyStd, Matrix.conjTranspose_submatrix] + rw [Matrix.submatrix_mul_equiv, kronFamily_basisChangeFamily_mul_conjTranspose, + Matrix.submatrix_one_equiv] + +/-- The Std basis change is unitary: `Bᴴ · B = 1` on `Fin (2³)`. -/ +theorem kronFamilyStd_basisChangeFamily_conjTranspose_mul : + (kronFamilyStd basisChangeFamily)ᴴ * kronFamilyStd basisChangeFamily = 1 := by + simp only [kronFamilyStd, Matrix.conjTranspose_submatrix] + rw [Matrix.submatrix_mul_equiv, kronFamily_basisChangeFamily_conjTranspose_mul, + Matrix.submatrix_one_equiv] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringCliffordCircuit.lean b/LeanPool/AxQM/Concrete/PauliStringCliffordCircuit.lean new file mode 100644 index 0000000000..be6dff8e38 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringCliffordCircuit.lean @@ -0,0 +1,418 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCnotConjugation + +/-! +# Concrete: a Clifford circuit conjugates a Pauli string to a Pauli string (encoding backbone) + +This file packages the single-wire Hadamard/phase gates of +`Concrete/PauliStringCliffordConjugation.lean` and the two-wire `CNOT` gate of +`Concrete/PauliStringCnotConjugation.lean` into a **Clifford circuit** — a finite sequence of these +gates — and proves the fact those files were built for: conjugating an `n`-qubit Pauli string +(`Concrete.pauliString`, `g : Fin n → Fin 4`) by a Clifford circuit returns another Pauli string, +up to a nonzero (`±1`) phase, whose **check matrix** is obtained from `g`'s by applying, in order, +each gate's elementary symplectic column operation. This is the operator-level statement of Nielsen +& Chuang **Problem 10.3**: *a circuit acts on the check matrix by column operations*, and the +encoding circuit of Eqs (10.124)→(10.125) is exactly such a sequence. + +## The gate and circuit + +`CliffordGate n` is the elementary gate set: `had j` and `phase j` (the single-wire Hadamard/phase +gates on wire `j`) and `cnot c t (h : c ≠ t)` (the two-wire controlled-NOT with control `c`, target +`t`). Three data are read off a gate: + +* `CliffordGate.toMatrix` — its unitary matrix (`kronWireGate j hadamardC` / + `kronWireGate j sMatrix` / `cnotWireGate c t`); +* `CliffordGate.act` — its **phase-free action** on a Pauli string, i.e. how it transforms the + check-matrix row (`Function.update` via `hadamardPauli` / `phasePauli`, or `cnotPauliString`); +* `CliffordGate.sign` — the `±1` phase acquired under conjugation (`hadamardPauliSign` / + `phasePauliSign` / `cnotPauliSign`), discarded by the check matrix but tracked here for the exact + operator identity. + +A `CliffordCircuit n` is a `List (CliffordGate n)`, read right-to-left: `(γ :: U).toMatrix = +γ.toMatrix * U.toMatrix` applies `U` first then `γ`, with `act`/`sign` the matching folds. + +## What is proved + +* `CliffordGate.conj` / `CliffordGate.mul_conjTranspose` — the single-gate conjugation + `γ.toMatrix · P_g · γ.toMatrixᴴ = γ.sign g • P_{γ.act g}` (unifying the three per-gate theorems) + and gate unitarity `γ.toMatrix · γ.toMatrixᴴ = 1`. +* `CliffordCircuit.conj_pauliString` — **the backbone**: for any circuit `U`, + `U.toMatrix · P_g · U.toMatrixᴴ = U.sign g • P_{U.act g}`. By induction on the gate list: the cons + case is `(γ M) P (γ M)ᴴ = γ (M P Mᴴ) γᴴ` (associativity + `conjTranspose_mul`), the inductive + hypothesis on the inner conjugation, and one application of `CliffordGate.conj`, collecting + the two `±1` scalars. +* `CliffordCircuit.mul_conjTranspose` — a Clifford circuit is **unitary** (`U.toMatrix · U.toMatrixᴴ + = 1`), from gate unitarity by the same induction. +* `CliffordGate.sign_ne_zero` / `CliffordCircuit.sign_ne_zero` — the conjugation phase is nonzero + (each gate phase is `±1`, a circuit's is a product of them), so `U` conjugates `P_g` to a genuine + scalar multiple of `P_{U.act g}` — it is never annihilated. + +## Design notes + +* We work with the **phase-free** `pauliString`, as throughout the Chapter-10 stabilizer material: + the check matrix records a Pauli only up to phase, so the `±1` signs live in `sign`, never in + `act`. Nielsen & Chuang fix the signs of the encoded generators separately (Proposition 10.4), so + the phase-free `act` is the right notion of "the circuit's action on the check matrix". +* `CliffordCircuit.sign (γ :: U) g` is defined as `U.sign g * γ.sign (U.act g)` — the order in which + `smul_smul` collects the scalars in the `conj_pauliString` induction — so no `mul_comm` is needed; + conceptually the order is immaterial (`ℂ` is commutative). +* No unitarity is used in `conj_pauliString`: conjugation composes for *any* matrices. Unitarity + of a Clifford circuit (a genuine gate of a quantum circuit) is not needed there. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### `±1`-valued gate signs are nonzero -/ + +/-- The Hadamard conjugation sign is nonzero (`±1`): `hadamardPauliSign a ≠ 0` for every `a`. -/ +private theorem hadamardPauliSign_ne_zero (a : Fin 4) : hadamardPauliSign a ≠ 0 := by + fin_cases a <;> simp [hadamardPauliSign] + +/-- The phase-gate conjugation sign is nonzero (`±1`): `phasePauliSign a ≠ 0` for every `a`. -/ +private theorem phasePauliSign_ne_zero (a : Fin 4) : phasePauliSign a ≠ 0 := by + fin_cases a <;> simp [phasePauliSign] + +/-- The CNOT conjugation sign is nonzero (`±1`): `cnotPauliSign a b ≠ 0` for every pair `a, b`. -/ +private theorem cnotPauliSign_ne_zero (a b : Fin 4) : cnotPauliSign a b ≠ 0 := by + fin_cases a <;> fin_cases b <;> simp [cnotPauliSign] + +/-! ### Clifford gates -/ + +/-- An **elementary Clifford gate** on the `n`-qubit register: the single-wire Hadamard (`had j`) +and phase (`phase j`) gates on wire `j`, and the two-wire controlled-NOT (`cnot c t h`) with control +`c`, target `t` (`h : c ≠ t`). These are the generators of the check-matrix column operations behind +the encoding circuit of Nielsen & Chuang Problem 10.3. -/ +inductive CliffordGate (n : ℕ) where + /-- The Hadamard gate on wire `j`. -/ + | had (j : Fin n) + /-- The phase gate `S` on wire `j`. -/ + | phase (j : Fin n) + /-- The controlled-NOT gate with control wire `c` and target wire `t` (`c ≠ t`). -/ + | cnot (c t : Fin n) (h : c ≠ t) + +namespace CliffordGate + +/-- The **unitary matrix** of an elementary Clifford gate: `kronWireGate j hadamardC` for `had j`, +`kronWireGate j sMatrix` for `phase j`, and `cnotWireGate c t` for `cnot c t`. -/ +def toMatrix : CliffordGate n → Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ + | .had j => kronWireGate j hadamardC + | .phase j => kronWireGate j sMatrix + | .cnot c t _ => cnotWireGate c t + +/-- The **phase-free action** of an elementary Clifford gate on a Pauli string `g : Fin n → Fin 4`, +i.e. how it transforms the check-matrix row: the Hadamard/phase gates update wire `j` by +`hadamardPauli` / `phasePauli`, and `cnot c t` applies `cnotPauliString`. -/ +def act : CliffordGate n → (Fin n → Fin 4) → (Fin n → Fin 4) + | .had j, g => Function.update g j (hadamardPauli (g j)) + | .phase j, g => Function.update g j (phasePauli (g j)) + | .cnot c t _, g => cnotPauliString g c t + +/-- The **`±1` phase** an elementary Clifford gate acquires when conjugating the Pauli string `g`: +`hadamardPauliSign (g j)` / `phasePauliSign (g j)` for the single-wire gates and +`cnotPauliSign (g c) (g t)` for `cnot c t`. Discarded by the check matrix but tracked here for +the exact operator identity `CliffordGate.conj`. -/ +def sign : CliffordGate n → (Fin n → Fin 4) → ℂ + | .had j, g => hadamardPauliSign (g j) + | .phase j, g => phasePauliSign (g j) + | .cnot c t _, g => cnotPauliSign (g c) (g t) + +/-- **Single-gate conjugation.** Conjugating a Pauli string `P_g` by an elementary Clifford gate +returns the Pauli string `P_{γ.act g}` up to the `±1` phase `γ.sign g`: +`γ.toMatrix · P_g · γ.toMatrixᴴ = γ.sign g • P_{γ.act g}`. This unifies the three per-gate theorems +`hadamardWire_conj_pauliString`, `phaseWire_conj_pauliString`, `cnotWireGate_conj_pauliString`. -/ +theorem conj (γ : CliffordGate n) (g : Fin n → Fin 4) : + γ.toMatrix * pauliString g * γ.toMatrixᴴ = γ.sign g • pauliString (γ.act g) := by + cases γ with + | had j => exact hadamardWire_conj_pauliString j g + | phase j => exact phaseWire_conj_pauliString j g + | cnot c t h => exact cnotWireGate_conj_pauliString c t h g + +/-- An elementary Clifford gate is **unitary**: `γ.toMatrix · γ.toMatrixᴴ = 1`. For the single-wire +gates via `kronWireGate_mul_conjTranspose` (`hadamardC` Hermitian involution; `sMatrix` in the +unitary group); for `cnot` via `cnotWireGate_mul_conjTranspose`. -/ +theorem mul_conjTranspose (γ : CliffordGate n) : γ.toMatrix * γ.toMatrixᴴ = 1 := by + cases γ with + | had j => + exact kronWireGate_mul_conjTranspose + (by rw [hadamardC_isHermitian]; exact hadamardC_mul_self) j + | phase j => + exact kronWireGate_mul_conjTranspose + (Matrix.mem_unitaryGroup_iff.mp sMatrix_mem_unitaryGroup) j + | cnot c t h => exact cnotWireGate_mul_conjTranspose c t h + +/-- The single-gate conjugation phase is **nonzero** (`±1`): `γ.sign g ≠ 0`. -/ +theorem sign_ne_zero (γ : CliffordGate n) (g : Fin n → Fin 4) : γ.sign g ≠ 0 := by + cases γ with + | had j => exact hadamardPauliSign_ne_zero (g j) + | phase j => exact phasePauliSign_ne_zero (g j) + | cnot c t _ => exact cnotPauliSign_ne_zero (g c) (g t) + +end CliffordGate + +/-! ### Clifford circuits -/ + +/-- A **Clifford circuit** on the `n`-qubit register: a finite sequence of elementary Clifford gates +(`CliffordGate n`). Read right-to-left: the head gate is applied last (see `toMatrix`). -/ +abbrev CliffordCircuit (n : ℕ) := List (CliffordGate n) + +namespace CliffordCircuit + +/-- The **unitary matrix** of a Clifford circuit: the product of its gate matrices, with the head +applied last — `[].toMatrix = 1`, `(γ :: U).toMatrix = γ.toMatrix * U.toMatrix`. -/ +def toMatrix : CliffordCircuit n → Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ + | [] => 1 + | γ :: U => γ.toMatrix * toMatrix U + +/-- The **phase-free action** of a Clifford circuit on a Pauli string (its transformation of the +check-matrix row): apply the gates right-to-left — `[].act g = g`, `(γ :: U).act g = γ.act (U.act +g)`. This is the composed sequence of elementary symplectic column operations. -/ +def act : CliffordCircuit n → (Fin n → Fin 4) → (Fin n → Fin 4) + | [], g => g + | γ :: U, g => γ.act (act U g) + +/-- The **`±1` phase** a Clifford circuit acquires conjugating `P_g`: the product of the per-gate +phases along the fold — `[].sign g = 1`, `(γ :: U).sign g = U.sign g * γ.sign (U.act g)` (the inner +circuit `U` acts first, so its phase multiplies the head gate's phase at the intermediate string +`U.act g`). -/ +def sign : CliffordCircuit n → (Fin n → Fin 4) → ℂ + | [], _ => 1 + | γ :: U, g => sign U g * γ.sign (act U g) + +/-- **The backbone (Nielsen & Chuang Problem 10.3): a Clifford circuit conjugates a Pauli string to +a Pauli string.** For any circuit `U` and Pauli string `g`, +`U.toMatrix · P_g · U.toMatrixᴴ = U.sign g • P_{U.act g}`: `U` maps `P_g` to the Pauli string +`P_{U.act g}` — whose check matrix is `g`'s after the composed column operations — up to the `±1` +phase `U.sign g`. This is the precise sense in which *a Clifford circuit acts on the check matrix by +column operations*. + +By induction on the gate list. The cons case rewrites `(γ.toMatrix * U.toMatrix) · P_g · +(γ.toMatrix * U.toMatrix)ᴴ` to `γ.toMatrix · (U.toMatrix · P_g · U.toMatrixᴴ) · γ.toMatrixᴴ` +(`conjTranspose_mul` + associativity), applies the inductive hypothesis to the inner conjugation, +then `CliffordGate.conj` to the outer gate, collecting the two `±1` scalars via `smul_smul`. -/ +theorem conj_pauliString (U : CliffordCircuit n) (g : Fin n → Fin 4) : + toMatrix U * pauliString g * (toMatrix U)ᴴ = sign U g • pauliString (act U g) := by + induction U with + | nil => simp [toMatrix, act, sign] + | cons γ U ih => + change (γ.toMatrix * toMatrix U) * pauliString g * (γ.toMatrix * toMatrix U)ᴴ + = sign (γ :: U) g • pauliString (act (γ :: U) g) + rw [Matrix.conjTranspose_mul, + show (γ.toMatrix * toMatrix U) * pauliString g * ((toMatrix U)ᴴ * γ.toMatrixᴴ) + = γ.toMatrix * (toMatrix U * pauliString g * (toMatrix U)ᴴ) * γ.toMatrixᴴ from by + simp only [Matrix.mul_assoc], + ih, mul_smul_comm, smul_mul_assoc, γ.conj, smul_smul] + simp only [sign, act] + +/-- A Clifford circuit is **unitary**: `U.toMatrix · U.toMatrixᴴ = 1`. By induction on the gate list +from single-gate unitarity `CliffordGate.mul_conjTranspose`: the cons case reassociates +`(γ M) (γ M)ᴴ = γ (M Mᴴ) γᴴ`, uses the inductive hypothesis `M Mᴴ = 1`, then the head gate's +unitarity. -/ +theorem mul_conjTranspose (U : CliffordCircuit n) : toMatrix U * (toMatrix U)ᴴ = 1 := by + induction U with + | nil => simp [toMatrix] + | cons γ U ih => + change (γ.toMatrix * toMatrix U) * (γ.toMatrix * toMatrix U)ᴴ = 1 + rw [Matrix.conjTranspose_mul, Matrix.mul_assoc, ← Matrix.mul_assoc (toMatrix U), ih, + Matrix.one_mul] + exact γ.mul_conjTranspose + +/-- The Clifford-circuit conjugation phase is **nonzero**: `U.sign g ≠ 0`, since it is a product of +the `±1` per-gate phases (`CliffordGate.sign_ne_zero`). Hence `U` conjugates `P_g` to a genuine +scalar multiple of `P_{U.act g}` — never to `0`. -/ +theorem sign_ne_zero (U : CliffordCircuit n) (g : Fin n → Fin 4) : sign U g ≠ 0 := by + induction U with + | nil => simp [sign] + | cons γ U ih => exact mul_ne_zero ih (γ.sign_ne_zero (act U g)) + +/-! ### Composition of Clifford circuits (list append) + +Since a `CliffordCircuit` is a gate list, `U ++ V` is the circuit that runs `V` first then `U` +(matching `toMatrix`'s right-to-left reading). These three lemmas record how the matrix, the +phase-free action, and the `±1` phase compose across an append — the algebra any *synthesis* of a +circuit from smaller pieces relies on (e.g. the inductive construction of Nielsen & Chuang +Exercise 10.40, which glues a permutation-fixing sub-circuit to a sign-fixing one). -/ + +/-- **The matrix of an appended circuit is the product of the matrices**: `(U ++ V).toMatrix = +U.toMatrix · V.toMatrix`, so `V` acts first (rightmost). By induction on the gate list `U`. -/ +theorem toMatrix_append (U V : CliffordCircuit n) : + toMatrix (U ++ V) = toMatrix U * toMatrix V := by + induction U with + | nil => simp [toMatrix] + | cons γ U ih => simp only [List.cons_append, toMatrix, ih, Matrix.mul_assoc] + +/-- **The action of an appended circuit is the composed action**: `(U ++ V).act g = U.act (V.act +g)`, `V` acting first. By induction on the gate list `U`. -/ +theorem act_append (U V : CliffordCircuit n) (g : Fin n → Fin 4) : + act (U ++ V) g = act U (act V g) := by + induction U with + | nil => rfl + | cons γ U ih => simp only [List.cons_append, act, ih] + +/-- **The phase of an appended circuit multiplies across the join**: `(U ++ V).sign g = V.sign g · +U.sign (V.act g)` — `V`'s phase at `g`, times `U`'s phase at the intermediate string `V.act g`. +By induction on the gate list `U`, using `act_append` for the intermediate string. -/ +theorem sign_append (U V : CliffordCircuit n) (g : Fin n → Fin 4) : + sign (U ++ V) g = sign V g * sign U (act V g) := by + induction U with + | nil => simp [sign] + | cons γ U ih => + simp only [List.cons_append, sign, act_append, ih] + ring + +end CliffordCircuit + +/-! ### Relabeling a Clifford circuit along a wire embedding + +A Clifford circuit on `m` wires transports onto `n` wires along an **injection of wires** +`f : Fin m ↪ Fin n`, relabeling each gate's wires by `f` (`had j ↦ had (f j)`, `cnot c t ↦ +cnot (f c) (f t)`, …). On the embedded wires the transported circuit acts exactly as the original: +its phase-free action and `±1` phase **pull back** along `f` +(`CliffordCircuit.act_relabel_comp`, `CliffordCircuit.sign_relabel`), and every wire *outside* the +range of `f` is left untouched (`CliffordCircuit.act_relabel_of_forall_ne`). Concretely, writing +`g ∘ f` for the string `k ↦ g (f k)` read off the embedded wires, +`(C.relabel f).act g (f i) = C.act (g ∘ f) i` and `(C.relabel f).sign g = C.sign (g ∘ f)`. + +This is the mechanism by which the inductive Clifford synthesis of Nielsen & Chuang Exercise 10.40 +embeds the `n`-qubit inductive hypothesis into a sub-register of an `(n+1)`-qubit register (the +embedding `f` picking out the sub-register's wires), and runs the single-qubit base case on any +chosen wire (`f = fun _ => j` on `Fin 1 ↪ Fin n`). Because a relabeled circuit is a genuine +Clifford circuit, its conjugation of Pauli strings is again governed by `conj_pauliString`, now with +the pulled-back action/sign. -/ + +variable {m : ℕ} + +/-- **Relabel an elementary Clifford gate's wires along `f : Fin m ↪ Fin n`.** `had j ↦ had (f j)`, +`phase j ↦ phase (f j)`, and `cnot c t ↦ cnot (f c) (f t)` — the target/control distinctness `c ≠ t` +is preserved because `f` is injective. -/ +def CliffordGate.relabel (f : Fin m ↪ Fin n) : CliffordGate m → CliffordGate n + | .had j => .had (f j) + | .phase j => .phase (f j) + | .cnot c t h => .cnot (f c) (f t) fun he => h (f.injective he) + +/-- **On an embedded wire `f i`, a relabeled gate acts as the original gate on the pulled-back +string** `k ↦ g (f k)`: `(γ.relabel f).act g (f i) = γ.act (fun k => g (f k)) i`. The single-wire +gates update only their (relabeled) wire; injectivity of `f` matches the off-wire indices, and for +`cnot` the control/target/rest split of `cnotPauliString` transports through `f`. -/ +theorem CliffordGate.act_relabel_embed (f : Fin m ↪ Fin n) (γ : CliffordGate m) + (g : Fin n → Fin 4) (i : Fin m) : + (γ.relabel f).act g (f i) = γ.act (fun k => g (f k)) i := by + cases γ with + | had j => + simp only [CliffordGate.relabel, CliffordGate.act] + by_cases hij : i = j + · subst hij; simp + · rw [Function.update_of_ne (f.injective.ne hij), Function.update_of_ne hij] + | phase j => + simp only [CliffordGate.relabel, CliffordGate.act] + by_cases hij : i = j + · subst hij; simp + · rw [Function.update_of_ne (f.injective.ne hij), Function.update_of_ne hij] + | cnot c t h => + simp only [CliffordGate.relabel, CliffordGate.act] + by_cases hic : i = c + · subst hic; rw [cnotPauliString_ctrl, cnotPauliString_ctrl] + · by_cases hit : i = t + · subst hit + rw [cnotPauliString_tgt g (f.injective.ne h), cnotPauliString_tgt _ h] + · rw [cnotPauliString_of_ne g (f c) (f t) (f.injective.ne hic) (f.injective.ne hit), + cnotPauliString_of_ne _ c t hic hit] + +/-- **A relabeled gate leaves every wire outside the range of `f` untouched**: if `f i ≠ k` for all +`i`, then `(γ.relabel f).act g k = g k`. A relabeled gate only ever touches wires in `f`'s range. -/ +theorem CliffordGate.act_relabel_of_forall_ne (f : Fin m ↪ Fin n) (γ : CliffordGate m) + (g : Fin n → Fin 4) {k : Fin n} (hk : ∀ i, f i ≠ k) : + (γ.relabel f).act g k = g k := by + cases γ with + | had j => + simp only [CliffordGate.relabel, CliffordGate.act, Function.update_of_ne (hk j).symm] + | phase j => + simp only [CliffordGate.relabel, CliffordGate.act, Function.update_of_ne (hk j).symm] + | cnot c t h => + simp only [CliffordGate.relabel, CliffordGate.act] + rw [cnotPauliString_of_ne g (f c) (f t) (hk c).symm (hk t).symm] + +/-- **A relabeled gate's `±1` phase pulls back along `f`**: `(γ.relabel f).sign g = +γ.sign (fun k => g (f k))`. Each gate's phase depends only on the (relabeled) wire values, so it is +unchanged by reading the string through `f`. -/ +theorem CliffordGate.sign_relabel (f : Fin m ↪ Fin n) (γ : CliffordGate m) (g : Fin n → Fin 4) : + (γ.relabel f).sign g = γ.sign (fun k => g (f k)) := by + cases γ <;> rfl + +namespace CliffordCircuit + +/-- **Relabel a Clifford circuit's wires along `f : Fin m ↪ Fin n`**, gate by gate +(`CliffordGate.relabel`). -/ +def relabel (f : Fin m ↪ Fin n) (C : CliffordCircuit m) : CliffordCircuit n := + C.map (CliffordGate.relabel f) + +/-- **A relabeled Clifford circuit acts, on the embedded wires, as the original on the pulled-back +string** — as a full function equality: `(fun i => (relabel f C).act g (f i)) = C.act (fun k => +g (f k))`. By induction on the gate list from the single-gate pullback +`CliffordGate.act_relabel_embed`. This is the key identity letting the inductive synthesis of +Exercise 10.40 reuse a sub-register circuit on a chosen set of wires. -/ +theorem act_relabel_comp (f : Fin m ↪ Fin n) (C : CliffordCircuit m) (g : Fin n → Fin 4) : + (fun i => act (relabel f C) g (f i)) = act C (fun k => g (f k)) := by + induction C generalizing g with + | nil => rfl + | cons γ C ih => + funext i + change (γ.relabel f).act (act (relabel f C) g) (f i) = γ.act (act C (fun k => g (f k))) i + rw [CliffordGate.act_relabel_embed, ih g] + +/-- **The embedded-wire action, pointwise**: `(relabel f C).act g (f i) = C.act (fun k => g (f k)) +i` for every `i`. The pointwise form of `act_relabel_comp`. -/ +theorem act_relabel_embed (f : Fin m ↪ Fin n) (C : CliffordCircuit m) + (g : Fin n → Fin 4) (i : Fin m) : + act (relabel f C) g (f i) = act C (fun k => g (f k)) i := + congrFun (act_relabel_comp f C g) i + +/-- **A relabeled Clifford circuit leaves every wire outside the range of `f` untouched**: if +`f i ≠ k` for all `i`, then `(relabel f C).act g k = g k`. By induction from the single-gate +version `CliffordGate.act_relabel_of_forall_ne`; this lets the induction embed a sub-register +circuit without disturbing the qubits it peels off. -/ +theorem act_relabel_of_forall_ne (f : Fin m ↪ Fin n) (C : CliffordCircuit m) + (g : Fin n → Fin 4) {k : Fin n} (hk : ∀ i, f i ≠ k) : + act (relabel f C) g k = g k := by + induction C generalizing g with + | nil => rfl + | cons γ C ih => + change (γ.relabel f).act (act (relabel f C) g) k = g k + rw [CliffordGate.act_relabel_of_forall_ne f γ _ hk, ih g] + +/-- **A relabeled Clifford circuit's `±1` phase pulls back along `f`**: `(relabel f C).sign g = +C.sign (fun k => g (f k))`. By induction on the gate list, using the single-gate phase pullback +`CliffordGate.sign_relabel` and the action pullback `act_relabel_comp` for the intermediate string. +Together with `act_relabel_embed`, a relabeled circuit realises on the embedded wires exactly the +signed permutation of the original — the transport of a sub-register synthesis into the full +register. -/ +theorem sign_relabel (f : Fin m ↪ Fin n) (C : CliffordCircuit m) (g : Fin n → Fin 4) : + sign (relabel f C) g = sign C (fun k => g (f k)) := by + induction C generalizing g with + | nil => rfl + | cons γ C ih => + change sign (relabel f C) g * (γ.relabel f).sign (act (relabel f C) g) + = sign C (fun k => g (f k)) * γ.sign (act C (fun k => g (f k))) + rw [ih g, CliffordGate.sign_relabel, act_relabel_comp] + +end CliffordCircuit + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliStringCliffordConjugation.lean b/LeanPool/AxQM/Concrete/PauliStringCliffordConjugation.lean new file mode 100644 index 0000000000..45dc84017f --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringCliffordConjugation.lean @@ -0,0 +1,253 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCommutation + +/-! +# Concrete: single-wire Clifford conjugation of Pauli strings and check-matrix column operations + +This file establishes how the **single-wire +Clifford generators** — the Hadamard gate `H` and the phase gate `S` placed on one qubit of an +`n`-qubit register — act on a Pauli string (`Concrete.pauliString`, `g : Fin n → Fin 4`) by +**conjugation**, and how that conjugation acts on the string's **binary symplectic check-matrix** +row (the `(x | z)` bits `pauliXBit`, `pauliZBit` of `Concrete/PauliStringCommutation.lean`). +Conjugating a Pauli string by a Clifford gate returns another Pauli string (up to a `±1` phase), and +on the check matrix this is exactly an **elementary symplectic column operation**: + +* **Hadamard on wire `j`** swaps the `X`-bit and `Z`-bit of column `j` (`H` exchanges the `x̂`/`e_z` + Bloch axes): `x_j ↔ z_j`. +* **Phase `S` on wire `j`** adds the `X`-bit into the `Z`-bit of column `j` (mod 2): + `z_j ↦ z_j + x_j`. + +This is the algebraic engine of the *encoding circuit* of Nielsen & Chuang **Problem 10.3**: a +Clifford circuit acts on the `n × 2n` check matrix of a stabilizer code by column operations, and +the encoding circuit is a sequence of such operations taking the trivial check matrix `[0 | I]` +(Eq. 10.124) to the standard form (Eq. 10.125). The single-wire generators formalised here are the +`H`/`S` half of that gate set (the two-wire gate `CNOT` is treated in +`AxQM/Concrete/PauliStringCnotConjugation.lean`); more broadly they are used throughout the +Chapter-10 stabilizer material (Gottesman–Knill Thm 10.7, the Clifford normalizer Thm 10.6, +Ex 10.39). + +## The gate on a wire + +`kronWireGate j G = kronFamily (Function.update (fun _ => 1) j G)` places the single-qubit gate `G` +on wire `j` of the register `Fin n → Fin 2` (identity on every other wire), `I ⊗ ⋯ ⊗ G ⊗ ⋯ ⊗ I`. +When `G` is unitary so is `kronWireGate j G` (`kronWireGate_mul_conjTranspose`, +`kronWireGate_conjTranspose_mul`), so it is a genuine one-qubit gate of a circuit. + +## What is proved + +* `hadamardC_conj_pauli` / `sMatrix_conj_pauli` — the **single-qubit tableaux** + `H σ_a H† = ε_H(a) • σ_{H·a}` and `S σ_a S† = ε_S(a) • σ_{S·a}`, where the index maps + `hadamardPauli` (`I,X,Y,Z ↦ I,Z,Y,X`) / `phasePauli` (`I,X,Y,Z ↦ I,Y,X,Z`) and the signs + `hadamardPauliSign` / `phasePauliSign` record the Clifford action `H X H=Z`, `H Y H=-Y`, `H Z H=X` + and `S X S†=Y`, `S Y S†=-X`, `S Z S†=Z` on the single qubit. (`S X S† = Y` is N&C Exercise 10.39.) +* `kronWireGate_conj_pauliString` — the **`n`-qubit lift**: for any single-qubit gate `G` with + tableau `G σ_a G† = ε a • σ_{τ a}`, conjugating a Pauli string by `kronWireGate j G` rewrites only + wire `j`: + `kronWireGate j G · P_g · (kronWireGate j G)† = ε (g j) • P_{update g j (τ (g j))}`. Proved + factor-by-factor by the mixed-product property `kronFamily_mul` (only the `j`-th factor is not + `1 · σ · 1 = σ`), with the single non-trivial sign pulled out by `kronFamily_smul_family` (all + other wires contribute the scalar `1`, `Finset.prod_update_of_mem`). +* `hadamardWire_conj_pauliString` / `phaseWire_conj_pauliString` — the two instances (`G = H`, `S`). +* `pauliXBit_hadamardPauli` / `pauliZBit_hadamardPauli` (the `H` column op `x_j ↔ z_j`) and + `pauliXBit_phasePauli` / `pauliZBit_phasePauli` (the `S` column op `z_j ↦ z_j + x_j (mod 2)`) — + the symplectic **check-matrix column operations** these gates induce. + +## Design notes + +* We work with the **phase-free** `pauliString`; the `±1` acquired under conjugation is tracked + explicitly as the scalar `ε`, matching the sign law `pauliString_mul_comm_sign` of the commutation + file. The check-matrix bit maps `hadamardPauli`/`phasePauli` discard the sign (the check matrix is + a phase-free `(x | z)` record), which is why the encoding-circuit column operations are stated on + the bits alone. +* Both single-qubit tableaux are finite `Fin 4` case checks citing the per-Pauli conjugation + lemmas: the Hadamard tableau cites `hadamardC_mul_pauli{X,Y,Z}_mul_hadamardC`, the phase tableau + cites `sMatrix_conj_pauli{X,Y,Z}` (all in `Concrete/PauliStringBasisChange.lean`, the `Y`/`Z` + siblings extracted next to the pre-existing `sMatrix_conj_pauliX`), plus `S S† = 1` for the `I` + case. +* The lift `kronWireGate_conj_pauliString` is the same `kronFamily` factor-by-factor idiom as + `pauliString_conj_kronFamily` (Exercise 4.51), specialised to a gate supported on a single wire + via `Function.update`. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The single-qubit Clifford tableaux -/ + +/-- The **Hadamard tableau** on a Pauli index: `I, X, Y, Z ↦ I, Z, Y, X` (`0,1,2,3 ↦ 0,3,2,1`). It +records the Pauli that `H σ_a H` produces, up to sign (`hadamardPauliSign`): `H` exchanges the `x̂` +and `e_z` Bloch axes and fixes `y_hat`. On the binary symplectic bits this is the swap `(x, z) ↦ +(z, x)` +(`pauliXBit_hadamardPauli`, `pauliZBit_hadamardPauli`). -/ +def hadamardPauli : Fin 4 → Fin 4 := ![0, 3, 2, 1] + +/-- The **sign** in the Hadamard tableau `H σ_a H = hadamardPauliSign a • σ_{hadamardPauli a}`: `-1` +for `a = Y` (since `H Y H = -Y`) and `+1` otherwise. -/ +def hadamardPauliSign : Fin 4 → ℂ := ![1, 1, -1, 1] + +/-- The **phase-gate tableau** on a Pauli index: `I, X, Y, Z ↦ I, Y, X, Z` (`0,1,2,3 ↦ 0,2,1,3`). It +records the Pauli that `S σ_a S†` produces, up to sign (`phasePauliSign`): the phase gate +`S = diag(1, i)` rotates `X ↦ Y` and `Y ↦ X` and fixes `Z`. On the binary symplectic bits this is +`(x, z) ↦ (x, z + x mod 2)` (`pauliXBit_phasePauli`, `pauliZBit_phasePauli`). -/ +def phasePauli : Fin 4 → Fin 4 := ![0, 2, 1, 3] + +/-- The **sign** in the phase-gate tableau `S σ_a S† = phasePauliSign a • σ_{phasePauli a}`: `-1` +for `a = Y` (since `S Y S† = -X`) and `+1` otherwise. -/ +def phasePauliSign : Fin 4 → ℂ := ![1, 1, -1, 1] + +/-- **Single-qubit Hadamard tableau**: `H σ_a H† = hadamardPauliSign a • σ_{hadamardPauli a}`. +Conjugating a single-qubit Pauli by the Hadamard gate returns a Pauli (up to `±1`): `H X H = Z`, +`H Y H = -Y`, `H Z H = X`, `H I H = I`. A finite `Fin 4` case check reusing the existing conjugation +lemmas (`H` Hermitian, so `H† = H`). -/ +theorem hadamardC_conj_pauli (a : Fin 4) : + hadamardC * pauli a * hadamardCᴴ = hadamardPauliSign a • pauli (hadamardPauli a) := by + have hH : hadamardCᴴ = hadamardC := hadamardC_isHermitian + rw [hH] + fin_cases a <;> + simp [hadamardPauli, hadamardPauliSign, pauli, hadamardC_mul_pauliX_mul_hadamardC, + hadamardC_mul_pauliY_mul_hadamardC, hadamardC_mul_pauliZ_mul_hadamardC, hadamardC_mul_self] + +/-- **Single-qubit phase-gate tableau**: `S σ_a S† = phasePauliSign a • σ_{phasePauli a}`. +Conjugating a single-qubit Pauli by the phase gate `S = diag(1, i)` returns a Pauli (up to `±1`): +`S X S† = Y`, `S Y S† = -X`, `S Z S† = Z`, `S I S† = I` (N&C Exercise 10.39). A finite `Fin 4` case +check citing the three conjugation facts `sMatrix_conj_pauli{X,Y,Z}` and the unitarity `S S† = 1` +(the `I` case), mirroring its sibling `hadamardC_conj_pauli`. -/ +theorem sMatrix_conj_pauli (a : Fin 4) : + sMatrix * pauli a * sMatrixᴴ = phasePauliSign a • pauli (phasePauli a) := by + have hI : sMatrix * sMatrixᴴ = 1 := Matrix.mem_unitaryGroup_iff.mp sMatrix_mem_unitaryGroup + fin_cases a <;> + simp [phasePauli, phasePauliSign, pauli, sMatrix_conj_pauliX, sMatrix_conj_pauliY, + sMatrix_conj_pauliZ, hI] + +/-! ### The gate on a single wire and its conjugation action -/ + +/-- The single-qubit gate `G` placed on **wire `j`** of the `n`-qubit register `Fin n → Fin 2` +(identity on every other wire): `I ⊗ ⋯ ⊗ G ⊗ ⋯ ⊗ I`, i.e. the tensor product with `G` at position +`j` and `1` elsewhere. This is the one-qubit gate of a circuit acting only on qubit `j`; when `G` is +unitary so is `kronWireGate j G` (`kronWireGate_mul_conjTranspose`). -/ +def kronWireGate (j : Fin n) (G : Matrix (Fin 2) (Fin 2) ℂ) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + kronFamily (Function.update (fun _ => 1) j G) + +/-- **Single-wire Clifford conjugation of a Pauli string.** For a single-qubit gate `G` with tableau +`G σ_a G† = ε a • σ_{τ a}`, conjugating the Pauli string `P_g` by `G` on wire `j` changes only wire +`j`: `kronWireGate j G · P_g · (kronWireGate j G)† = ε (g j) • P_{update g j (τ (g j))}`. This is +the sense in which a circuit built from single-wire Clifford gates acts on a Pauli string — hence on +the check matrix — one column at a time. + +Proof: reducing `P_g` and the gate to `kronFamily` and applying the mixed-product property twice +(`kronFamily_mul`, `kronFamily_conjTranspose`), the `k`-th tensor factor becomes +`(update 1 j G) k · σ_{g k} · ((update 1 j G) k)†`, which is `σ_{g k}` for `k ≠ j` and +`ε (g j) • σ_{τ (g j)}` for `k = j` (the tableau `hG`). Pulling the single non-trivial scalar out +with `kronFamily_smul_family` gives the product of scalars `∏ (update 1 j (ε (g j))) = ε (g j)` +(`Finset.prod_update_of_mem`, all other factors `1`). -/ +theorem kronWireGate_conj_pauliString + {G : Matrix (Fin 2) (Fin 2) ℂ} {τ : Fin 4 → Fin 4} {ε : Fin 4 → ℂ} + (hG : ∀ a : Fin 4, G * pauli a * Gᴴ = ε a • pauli (τ a)) + (j : Fin n) (g : Fin n → Fin 4) : + kronWireGate j G * pauliString g * (kronWireGate j G)ᴴ + = ε (g j) • pauliString (Function.update g j (τ (g j))) := by + have hA : ∀ k, (Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k + * pauli (g k) * ((Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k)ᴴ + = (Function.update (fun _ => (1 : ℂ)) j (ε (g j))) k + • pauli ((Function.update g j (τ (g j))) k) := by + intro k + rcases eq_or_ne k j with rfl | hk + · simp only [Function.update_self]; exact hG (g k) + · simp only [Function.update_of_ne hk, Matrix.conjTranspose_one, Matrix.one_mul, + Matrix.mul_one, one_smul] + rw [kronWireGate, pauliString_eq_kronFamily, kronFamily_conjTranspose, kronFamily_mul, + kronFamily_mul, congrArg kronFamily (funext hA), kronFamily_smul_family, + Finset.prod_update_of_mem (Finset.mem_univ j), pauliString_eq_kronFamily] + simp + +/-- A single-wire gate is unitary when its single-qubit gate is: +`G G† = 1 ⟹ (kronWireGate j G)(kronWireGate j G)† = 1`. Factor-by-factor from `kronFamily_mul` +(`kronFamily_conjTranspose`): wire `j` contributes `G G† = 1`, every other wire `1 · 1† = 1`, so the +tensor product is `⨂ 1 = 1` (`kronFamily_one`). -/ +theorem kronWireGate_mul_conjTranspose {G : Matrix (Fin 2) (Fin 2) ℂ} (hG : G * Gᴴ = 1) + (j : Fin n) : kronWireGate j G * (kronWireGate j G)ᴴ = 1 := by + have h : (fun k => (Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k + * ((Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k)ᴴ) + = fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + funext k + rcases eq_or_ne k j with rfl | hk + · simp only [Function.update_self]; exact hG + · simp only [Function.update_of_ne hk, Matrix.conjTranspose_one, Matrix.mul_one] + rw [kronWireGate, kronFamily_conjTranspose, kronFamily_mul, h, kronFamily_one] + +/-- A single-wire gate is unitary when its single-qubit gate is: +`G† G = 1 ⟹ (kronWireGate j G)†(kronWireGate j G) = 1`. The mirror of +`kronWireGate_mul_conjTranspose`. -/ +theorem kronWireGate_conjTranspose_mul {G : Matrix (Fin 2) (Fin 2) ℂ} (hG : Gᴴ * G = 1) + (j : Fin n) : (kronWireGate j G)ᴴ * kronWireGate j G = 1 := by + have h : (fun k => ((Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k)ᴴ + * (Function.update (fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ)) j G) k) + = fun _ => (1 : Matrix (Fin 2) (Fin 2) ℂ) := by + funext k + rcases eq_or_ne k j with rfl | hk + · simp only [Function.update_self]; exact hG + · simp only [Function.update_of_ne hk, Matrix.conjTranspose_one, Matrix.mul_one] + rw [kronWireGate, kronFamily_conjTranspose, kronFamily_mul, h, kronFamily_one] + +/-- **Hadamard on wire `j` conjugates a Pauli string, changing only wire `j`.** The `G = H` instance +of `kronWireGate_conj_pauliString`: `kronWireGate j H · P_g · (kronWireGate j H)† = +hadamardPauliSign (g j) • P_{update g j (hadamardPauli (g j))}`. Its check-matrix effect is the +column swap `x_j ↔ z_j` +(`pauliXBit_hadamardPauli`, `pauliZBit_hadamardPauli`). -/ +theorem hadamardWire_conj_pauliString (j : Fin n) (g : Fin n → Fin 4) : + kronWireGate j hadamardC * pauliString g * (kronWireGate j hadamardC)ᴴ + = hadamardPauliSign (g j) • pauliString (Function.update g j (hadamardPauli (g j))) := + kronWireGate_conj_pauliString hadamardC_conj_pauli j g + +/-- **Phase gate on wire `j` conjugates a Pauli string, changing only wire `j`.** The `G = S` +instance of `kronWireGate_conj_pauliString`: `kronWireGate j S · P_g · (kronWireGate j S)† = +phasePauliSign (g j) • P_{update g j (phasePauli (g j))}`. Its check-matrix effect is the column +operation `z_j ↦ z_j + x_j` (`pauliXBit_phasePauli`, `pauliZBit_phasePauli`). -/ +theorem phaseWire_conj_pauliString (j : Fin n) (g : Fin n → Fin 4) : + kronWireGate j sMatrix * pauliString g * (kronWireGate j sMatrix)ᴴ + = phasePauliSign (g j) • pauliString (Function.update g j (phasePauli (g j))) := + kronWireGate_conj_pauliString sMatrix_conj_pauli j g + +/-! ### The induced symplectic check-matrix column operations -/ + +/-- The Hadamard column operation on the check matrix, `X`-bit half: the `x`-bit of `H·a` is the +`z`-bit of `a`. Together with `pauliZBit_hadamardPauli` this is the swap `(x_j, z_j) ↦ (z_j, x_j)` +that a Hadamard on wire `j` performs on column `j` of the check matrix. -/ +theorem pauliXBit_hadamardPauli (a : Fin 4) : pauliXBit (hadamardPauli a) = pauliZBit a := by + fin_cases a <;> rfl + +/-- The Hadamard column operation on the check matrix, `Z`-bit half: the `z`-bit of `H·a` is the +`x`-bit of `a`. -/ +theorem pauliZBit_hadamardPauli (a : Fin 4) : pauliZBit (hadamardPauli a) = pauliXBit a := by + fin_cases a <;> rfl + +/-- The phase-gate column operation on the check matrix, `X`-bit half: the `x`-bit of `S·a` is +unchanged, the `x`-bit of `a`. Together with `pauliZBit_phasePauli` this is the operation +`(x_j, z_j) ↦ (x_j, z_j + x_j)` that a phase gate on wire `j` performs on column `j`. -/ +theorem pauliXBit_phasePauli (a : Fin 4) : pauliXBit (phasePauli a) = pauliXBit a := by + fin_cases a <;> rfl + +/-- The phase-gate column operation on the check matrix, `Z`-bit half: the `z`-bit of `S·a` is +`z_a + x_a` mod 2 (the phase gate adds the `X`-bit into the `Z`-bit). -/ +theorem pauliZBit_phasePauli (a : Fin 4) : + pauliZBit (phasePauli a) = (pauliXBit a + pauliZBit a) % 2 := by + fin_cases a <;> rfl + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringCnotConjugation.lean b/LeanPool/AxQM/Concrete/PauliStringCnotConjugation.lean new file mode 100644 index 0000000000..2171bb84e2 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringCnotConjugation.lean @@ -0,0 +1,326 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordConjugation +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Permutation + +/-! +# Concrete: two-wire CNOT conjugation of Pauli strings and its check-matrix column operation + +This file establishes how the **two-wire +Clifford generator** — the controlled-NOT gate `CNOT` with control wire `c` and target wire `t` of +an `n`-qubit register — acts on a Pauli string (`Concrete.pauliString`, `g : Fin n → Fin 4`) by +**conjugation**, and the elementary symplectic **check-matrix column operation** it induces. This is +the two-wire companion of the single-wire Hadamard/phase gates of +`Concrete/PauliStringCliffordConjugation.lean`; together `{H, S, CNOT}` is the full column-operation +gate set behind the encoding circuit of Nielsen & Chuang **Problem 10.3** (the sequence of column +operations carrying the trivial check matrix `[0 | I]` of Eq. 10.124 to the standard/encoded form of +Eq. 10.125). + +Conjugating a Pauli string by `CNOT` returns another Pauli string up to a `±1` phase, and on the +binary symplectic check matrix (the `(x | z)` bits `pauliXBit`, `pauliZBit` of +`Concrete/PauliStringCommutation.lean`) this is exactly the column operation of Nielsen & Chuang +**Figure 10.7** (control `c`, target `t`): + +* the target's `X`-bit picks up the control's: `x_t ↦ x_t + x_c` (`X_c ↦ X_c X_t`); +* the control's `Z`-bit picks up the target's: `z_c ↦ z_c + z_t` (`Z_t ↦ Z_c Z_t`); +* `x_c` and `z_t` are unchanged (`X_t ↦ X_t`, `Z_c ↦ Z_c`). + +## The gate + +Unlike the single-wire gates, `CNOT` is **entangling** and does *not* factor as a tensor product of +single-qubit gates, so the `kronFamily` factor-by-factor idiom of the `H`/`S` file does not apply +directly. Instead `CNOT` is a **permutation** of the computational basis: on the register +`Fin n → Fin 2`, `|x⟩ ↦ |x with wire t flipped by wire c⟩`, i.e. the involution +`cnotPerm c t x = update x t (x t + x c)` (mod 2). `cnotWireGate c t` is its permutation matrix. +Under `c ≠ t` it is exactly Mathlib's `Equiv.Perm.permMatrix` of the corresponding permutation +(`cnotWireGate_eq_permMatrix`), so its symmetry, self-inverse, unitarity and conjugation action are +all applications of the existing permutation-matrix API rather than hand-rolled — a genuine gate. + +## What is proved + +* `cnotPerm` / `cnotPerm_involutive` — the CNOT bit-permutation and that it is an involution. +* `cnotWireGate` / `cnotWireGate_eq_permMatrix` (the bridge to `Equiv.Perm.permMatrix`) / + `cnotWireGate_conjTranspose` (symmetric) / `cnotWireGate_mul_self` (self-inverse) / + `cnotWireGate_mul_conjTranspose`, `cnotWireGate_conjTranspose_mul` (unitarity). +* `cnotWireGate_conj_apply` — the conjugation of any matrix by the permutation reindexes both sides: + `(P · M · Pᴴ)(i, j) = M (cnotPerm i) (cnotPerm j)`. +* `cnotCtrlPauli` / `cnotTgtPauli` / `cnotPauliSign` — the CNOT single-pair tableau: the new + control- and target-wire Paulis and the `±1` sign in `CNOT (σ_a ⊗ σ_b) CNOT†`. Because `CNOT` + entangles, the *new* control Pauli depends on *both* input Paulis (its `Z`-bit gains the + target's), and likewise the new target Pauli (its `X`-bit gains the control's). +* `cnot_conj_pauliEntry` — the two-wire entry factorisation + `σ_a(i_c,j_c) · σ_b(i_t+i_c, j_t+j_c) = ε • σ_{a'}(i_c,j_c) · σ_{b'}(i_t,j_t)` (a finite `Fin 4²` + by `Fin 2⁴` case check), the heart of the conjugation. +* `cnotPauliString` / `cnotWireGate_conj_pauliString` — the **`n`-qubit theorem**: + `CNOT_{c→t} · P_g · CNOT_{c→t}† = ε (g c) (g t) • P_{g'}`, where `g'` updates only wires `c`, `t`. + Proved by the conjugation entry formula plus splitting the entrywise product off wires `t` and `c` + (`Finset.prod_erase_mul`, `Finset.mul_prod_erase`) and the pair factorisation; the middle "rest" + product is unchanged, and matrix entries are `ℂ` (commutative), so the two `{c,t}` factors combine + by `cnot_conj_pauliEntry`. +* `pauliXBit_cnotTgtPauli` (`x_t ↦ x_t + x_c`), `pauliZBit_cnotTgtPauli` (`z_t` unchanged), + `pauliXBit_cnotCtrlPauli` (`x_c` unchanged), `pauliZBit_cnotCtrlPauli` (`z_c ↦ z_c + z_t`) — the + induced symplectic **check-matrix column operation** of Figure 10.7. + +## Design notes + +* The gate is defined entrywise but immediately bridged to `Equiv.Perm.permMatrix` + (`cnotWireGate_eq_permMatrix`), so its symmetry, self-inverse, unitarity and conjugation-by- + reindexing come from the existing Mathlib API (`Matrix.conjTranspose_permMatrix`, + `Matrix.permMatrix_mul`/`_one`, `PEquiv.toMatrix_toPEquiv_mul`/`mul_toMatrix_toPEquiv`) rather + than hand-rolled `Finset` sums. The `def` keeps its `c ≠ t`-free signature; the hypothesis is + carried only in the bridge. +* We work with the **phase-free** `pauliString`; the `±1` acquired under conjugation is tracked as + the explicit scalar `cnotPauliSign` (nonzero only for the pairs `X_c Z_t` and `Y_c Y_t`, where + the two `i`-factors from `Y = iXZ` recombine to `-1`), matching the sign convention of the + `H`/`S` file and of `pauliString_mul_comm_sign`. The check-matrix column-op lemmas are stated on + the bits alone, discarding the sign (the check matrix is a phase-free `(x | z)` record). +* Specialising `cnotWireGate_conj_pauliString` to single-generator strings reproduces the + Figure 10.7 / N&C Ex. 10.36 rules `CNOT X_c CNOT = X_c X_t`, `CNOT X_t CNOT = X_t`, + `CNOT Z_c CNOT = Z_c`, `CNOT Z_t CNOT = Z_c Z_t`. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The CNOT bit-permutation and gate -/ + +/-- The **CNOT bit-permutation** with control wire `c` and target wire `t`: flip the target bit +`x t` by the control bit `x c`, `x ↦ update x t (x t + x c)` (in `Fin 2`, i.e. mod 2). This is +the action of `CNOT_{c→t}` on the computational-basis register `Fin n → Fin 2`, +`|x⟩ ↦ |x_t ⊕ x_c on wire t⟩`. It is an involution (`cnotPerm_involutive`). -/ +def cnotPerm (c t : Fin n) (x : Fin n → Fin 2) : Fin n → Fin 2 := + Function.update x t (x t + x c) + +/-- The CNOT bit-permutation is an **involution**: flipping the target by the control twice restores +the state (`(x t + x c) + x c = x t` in `Fin 2`). Requires `c ≠ t` (else the control bit is itself +altered). -/ +theorem cnotPerm_involutive (c t : Fin n) (h : c ≠ t) : Function.Involutive (cnotPerm c t) := by + intro x + funext k + rcases eq_or_ne k t with rfl | hk + · simp only [cnotPerm, Function.update_self, Function.update_of_ne h] + generalize x k = a; generalize x c = b + fin_cases a <;> fin_cases b <;> rfl + · simp only [cnotPerm, Function.update_of_ne hk] + +/-- The **CNOT gate** `CNOT_{c→t}` (control wire `c`, target wire `t`) on the `n`-qubit register, as +the **permutation matrix** of the bit-permutation `cnotPerm c t`: `(i, j)` entry is `1` iff +`i = cnotPerm c t j`, else `0`. Under `c ≠ t` this is exactly Mathlib's `Equiv.Perm.permMatrix` of +the involution's permutation (`cnotWireGate_eq_permMatrix`), which supplies its symmetry, being its +own inverse, unitarity, and conjugation action; so it is a genuine two-qubit gate of a circuit. +The `def` is kept proof-free (no `c ≠ t` in its signature); `c ≠ t` enters only in the bridge. -/ +def cnotWireGate (c t : Fin n) : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + Matrix.of fun i j => if i = cnotPerm c t j then (1 : ℂ) else 0 + +/-- **Bridge to Mathlib's permutation matrix.** For `c ≠ t`, `cnotWireGate c t` is the +`Equiv.Perm.permMatrix` of the permutation obtained from the involution `cnotPerm c t` +(`Function.Involutive.toPerm`). The entry conventions match up to `cnotPerm`'s involutivity: +`cnotWireGate i j = [i = cnotPerm j]` and `permMatrix σ i j = [σ i = j]`, and +`i = cnotPerm j ↔ cnotPerm i = j`. This reduces every gate lemma below to the existing Mathlib +permutation-matrix API. -/ +theorem cnotWireGate_eq_permMatrix (c t : Fin n) (h : c ≠ t) : + cnotWireGate c t + = Equiv.Perm.permMatrix ℂ + (Function.Involutive.toPerm (cnotPerm c t) (cnotPerm_involutive c t h)) := by + have hinv := cnotPerm_involutive c t h + ext i j + simp only [cnotWireGate, Matrix.of_apply, Equiv.Perm.permMatrix, PEquiv.toMatrix_apply, + Equiv.toPEquiv_apply, Function.Involutive.coe_toPerm, Option.mem_def, Option.some.injEq] + by_cases hij : i = cnotPerm c t j + · rw [ite_eq_left hij, ite_eq_left (by rw [hij, hinv])] + · rw [ite_eq_right hij, ite_eq_right (fun heq => hij (by rw [← heq, hinv]))] + +/-- The inverse of the CNOT permutation equals itself (`cnotPerm` is an involution). A helper for +the gate lemmas: `permMatrix` of this permutation is symmetric and self-inverse. -/ +private theorem cnotToPerm_inv (c t : Fin n) (h : c ≠ t) : + (Function.Involutive.toPerm (cnotPerm c t) (cnotPerm_involutive c t h))⁻¹ + = Function.Involutive.toPerm (cnotPerm c t) (cnotPerm_involutive c t h) := + Function.Involutive.toPerm_symm (cnotPerm_involutive c t h) + +/-- The CNOT gate is **symmetric** (real permutation matrix of an involution): +`(cnotWireGate c t)ᴴ = cnotWireGate c t`. Via the bridge, `Matrix.conjTranspose_permMatrix` turns +the adjoint into `permMatrix σ⁻¹`, and `σ⁻¹ = σ` (`cnotToPerm_inv`). -/ +theorem cnotWireGate_conjTranspose (c t : Fin n) (h : c ≠ t) : + (cnotWireGate c t)ᴴ = cnotWireGate c t := by + rw [cnotWireGate_eq_permMatrix c t h, Matrix.conjTranspose_permMatrix, cnotToPerm_inv c t h] + +/-- The CNOT gate is its **own inverse**: `cnotWireGate c t * cnotWireGate c t = 1`. Via the bridge, +`Matrix.permMatrix_mul` folds the product to `permMatrix (σ * σ)`, and `σ * σ = 1` (involution, +`cnotToPerm_inv`), then `Matrix.permMatrix_one`. -/ +theorem cnotWireGate_mul_self (c t : Fin n) (h : c ≠ t) : + cnotWireGate c t * cnotWireGate c t = 1 := by + rw [cnotWireGate_eq_permMatrix c t h, ← Matrix.permMatrix_mul] + have hone : (Function.Involutive.toPerm (cnotPerm c t) (cnotPerm_involutive c t h)) + * (Function.Involutive.toPerm (cnotPerm c t) (cnotPerm_involutive c t h)) = 1 := by + rw [mul_eq_one_iff_eq_inv, cnotToPerm_inv c t h] + rw [hone, Matrix.permMatrix_one] + +/-- The CNOT gate is **unitary**: `cnotWireGate c t * (cnotWireGate c t)ᴴ = 1` (real symmetric +involution). -/ +theorem cnotWireGate_mul_conjTranspose (c t : Fin n) (h : c ≠ t) : + cnotWireGate c t * (cnotWireGate c t)ᴴ = 1 := by + rw [cnotWireGate_conjTranspose c t h, cnotWireGate_mul_self c t h] + +/-- The CNOT gate is **unitary**: `(cnotWireGate c t)ᴴ * cnotWireGate c t = 1`. -/ +theorem cnotWireGate_conjTranspose_mul (c t : Fin n) (h : c ≠ t) : + (cnotWireGate c t)ᴴ * cnotWireGate c t = 1 := by + rw [cnotWireGate_conjTranspose c t h, cnotWireGate_mul_self c t h] + +/-- **Conjugation by the CNOT permutation matrix reindexes both indices.** For any matrix `M`, +`(cnotWireGate c t · M · (cnotWireGate c t)ᴴ)(i, j) = M (cnotPerm c t i) (cnotPerm c t j)`. +Permutation-matrix conjugation is submatrix reindexing by the permutation: via the bridge and +`cnotToPerm_inv`, the two multiplications collapse to `M.submatrix σ σ.symm` by Mathlib's +`PEquiv.toMatrix_toPEquiv_mul` / `PEquiv.mul_toMatrix_toPEquiv`, and `σ = σ.symm = cnotPerm c t`. -/ +theorem cnotWireGate_conj_apply (c t : Fin n) (h : c ≠ t) + (M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) (i j : Fin n → Fin 2) : + (cnotWireGate c t * M * (cnotWireGate c t)ᴴ) i j = M (cnotPerm c t i) (cnotPerm c t j) := by + rw [cnotWireGate_eq_permMatrix c t h, Matrix.conjTranspose_permMatrix, cnotToPerm_inv c t h] + simp only [Equiv.Perm.permMatrix, PEquiv.toMatrix_toPEquiv_mul, PEquiv.mul_toMatrix_toPEquiv, + Matrix.submatrix_apply, id_eq, Function.Involutive.toPerm_symm, Function.Involutive.coe_toPerm] + +/-! ### The CNOT single-pair tableau -/ + +/-- The **new control Pauli** in `CNOT (σ_a^c ⊗ σ_b^t) CNOT†`, as a function of the control index +`a` and target index `b` (`0 = I, 1 = X, 2 = Y, 3 = Z`). The control's `X`-bit is unchanged and its +`Z`-bit gains the target's (`z_c ↦ z_c + z_t`, since `Z_t ↦ Z_c Z_t` puts a `Z` on the control), so +it depends on both `a` and `b` (`CNOT` is entangling). -/ +def cnotCtrlPauli : Fin 4 → Fin 4 → Fin 4 := + ![![0, 0, 3, 3], ![1, 1, 2, 2], ![2, 2, 1, 1], ![3, 3, 0, 0]] + +/-- The **new target Pauli** in `CNOT (σ_a^c ⊗ σ_b^t) CNOT†`. The target's `Z`-bit is unchanged and +its `X`-bit gains the control's (`x_t ↦ x_t + x_c`, since `X_c ↦ X_c X_t` puts an `X` on the +target), so it depends on both `a` and `b`. -/ +def cnotTgtPauli : Fin 4 → Fin 4 → Fin 4 := + ![![0, 1, 2, 3], ![1, 0, 3, 2], ![1, 0, 3, 2], ![0, 1, 2, 3]] + +/-- The **sign** `ε` in the CNOT pair tableau +`CNOT (σ_a^c ⊗ σ_b^t) CNOT† = ε • (σ_{a'}^c ⊗ σ_{b'}^t)`. It is `-1` exactly for the pairs +`(X_c, Z_t)` and `(Y_c, Y_t)`, where the two `i`-factors produced by recombining the `Y = iXZ` +factors on the two wires multiply to `-1`; otherwise `+1`. -/ +def cnotPauliSign : Fin 4 → Fin 4 → ℂ := + ![![1, 1, 1, 1], ![1, 1, 1, -1], ![1, 1, -1, 1], ![1, 1, 1, 1]] + +/-- **The CNOT two-wire entry factorisation.** For the control index `a` and target index `b`, the +product of a control entry and a *shifted* target entry factorises into the transformed Paulis with +the tableau sign: +`σ_a(i_c, j_c) · σ_b(i_t+i_c, j_t+j_c) = cnotPauliSign a b • (σ_{a'}(i_c, j_c) · σ_{b'}(i_t, j_t))` +where `a' = cnotCtrlPauli a b`, `b' = cnotTgtPauli a b`. The index shift `i_t + i_c` is exactly the +CNOT bit-permutation on the target wire; this identity captures how the control couples into the +target under conjugation. A finite `Fin 4 × Fin 4` (Paulis) by `Fin 2⁴` (register bits) case check +against the explicit `pauli` entries. -/ +theorem cnot_conj_pauliEntry (a b : Fin 4) (ic it jc jt : Fin 2) : + pauli a ic jc * pauli b (it + ic) (jt + jc) + = cnotPauliSign a b • (pauli (cnotCtrlPauli a b) ic jc * pauli (cnotTgtPauli a b) it jt) := by + fin_cases a <;> fin_cases b <;> + simp only [cnotCtrlPauli, cnotTgtPauli, cnotPauliSign, Matrix.cons_val', + Matrix.cons_val_fin_one] <;> + (fin_cases ic <;> fin_cases it <;> fin_cases jc <;> fin_cases jt <;> + simp [pauli, pauliX, pauliY, pauliZ, Fin.add_def]) + +/-! ### The `n`-qubit CNOT conjugation of a Pauli string -/ + +/-- The **CNOT-transformed Pauli string**: `CNOT_{c→t}` conjugation changes only wire `c` (to +`cnotCtrlPauli (g c) (g t)`) and wire `t` (to `cnotTgtPauli (g c) (g t)`), leaving every other wire +fixed. The new wire-`c` and wire-`t` Paulis both depend on the *original* pair `(g c, g t)` +(`cnotWireGate_conj_pauliString`). -/ +def cnotPauliString (g : Fin n → Fin 4) (c t : Fin n) : Fin n → Fin 4 := + Function.update (Function.update g t (cnotTgtPauli (g c) (g t))) c (cnotCtrlPauli (g c) (g t)) + +/-- The transformed string on the control wire: +`cnotPauliString g c t c = cnotCtrlPauli (g c) (g t)`. -/ +@[simp] +theorem cnotPauliString_ctrl (g : Fin n → Fin 4) (c t : Fin n) : + cnotPauliString g c t c = cnotCtrlPauli (g c) (g t) := + Function.update_self .. + +/-- The transformed string on the target wire: `cnotPauliString g c t t = cnotTgtPauli (g c) (g t)` +(needs `c ≠ t`). -/ +theorem cnotPauliString_tgt (g : Fin n → Fin 4) {c t : Fin n} (h : c ≠ t) : + cnotPauliString g c t t = cnotTgtPauli (g c) (g t) := by + simp only [cnotPauliString, Function.update_of_ne h.symm, Function.update_self] + +/-- The transformed string off wires `c` and `t` is unchanged: `cnotPauliString g c t k = g k` for +`k ≠ c`, `k ≠ t`. -/ +theorem cnotPauliString_of_ne (g : Fin n → Fin 4) (c t : Fin n) {k : Fin n} (hkc : k ≠ c) + (hkt : k ≠ t) : cnotPauliString g c t k = g k := by + simp only [cnotPauliString, Function.update_of_ne hkc, Function.update_of_ne hkt] + +/-- **CNOT conjugation of a Pauli string** (control wire `c`, target wire `t`, `c ≠ t`): +`CNOT_{c→t} · P_g · CNOT_{c→t}† = cnotPauliSign (g c) (g t) • P_{cnotPauliString g c t}`. +Conjugating by `CNOT` returns a Pauli string (up to `±1`) differing from `g` only on wires `c`, `t`. + +Proof: the conjugation reindexes each entry by the bit-permutation (`cnotWireGate_conj_apply`), +`P_g(cnotPerm i, cnotPerm j) = ∏ₖ σ_{gₖ}((cnotPerm i)ₖ)((cnotPerm j)ₖ)`. Splitting the entrywise +product off wire `t` and then wire `c` (`Finset.prod_erase_mul`, `Finset.mul_prod_erase`; `c ≠ t`), +only the target factor carries the coupled shift `(i_t + i_c, j_t + j_c)`; the "rest" product over +the other wires is literally unchanged (`cnotPauliString_of_ne`), and — matrix entries being `ℂ`, +commutative — the `{c, t}` factors recombine by the pair factorisation `cnot_conj_pauliEntry`. -/ +theorem cnotWireGate_conj_pauliString (c t : Fin n) (h : c ≠ t) (g : Fin n → Fin 4) : + cnotWireGate c t * pauliString g * (cnotWireGate c t)ᴴ + = cnotPauliSign (g c) (g t) • pauliString (cnotPauliString g c t) := by + ext i j + rw [cnotWireGate_conj_apply c t h, Matrix.smul_apply, pauliString_apply, pauliString_apply, + smul_eq_mul] + have hc_mem : c ∈ Finset.univ.erase t := Finset.mem_erase.mpr ⟨h, Finset.mem_univ c⟩ + have hrest : ∀ k ∈ (Finset.univ.erase t).erase c, + pauli (g k) ((cnotPerm c t i) k) ((cnotPerm c t j) k) + = pauli (cnotPauliString g c t k) (i k) (j k) := by + intro k hk + have hkt : k ≠ t := Finset.ne_of_mem_erase (Finset.mem_of_mem_erase hk) + have hkc : k ≠ c := Finset.ne_of_mem_erase hk + simp only [cnotPerm, Function.update_of_ne hkt, cnotPauliString_of_ne g c t hkc hkt] + rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ t), ← Finset.mul_prod_erase _ _ hc_mem] + rw [← Finset.prod_erase_mul (a := t) + (f := fun k => pauli (cnotPauliString g c t k) (i k) (j k)) _ (Finset.mem_univ t), + ← Finset.mul_prod_erase _ + (f := fun k => pauli (cnotPauliString g c t k) (i k) (j k)) hc_mem] + rw [Finset.prod_congr rfl hrest, cnotPauliString_ctrl, cnotPauliString_tgt g h] + simp only [cnotPerm, Function.update_self, Function.update_of_ne h] + have key := cnot_conj_pauliEntry (g c) (g t) (i c) (i t) (j c) (j t) + rw [smul_eq_mul] at key + set R := ∏ x ∈ (Finset.univ.erase t).erase c, + pauli (cnotPauliString g c t x) (i x) (j x) with hR + linear_combination R * key + +/-! ### The induced symplectic check-matrix column operation (Figure 10.7) -/ + +/-- CNOT column operation, target `X`-bit: `x_t ↦ x_t + x_c` (mod 2). The `X`-bit of the new target +Pauli `cnotTgtPauli a b` is the sum of the target's and control's `X`-bits — a `CNOT` from control +`c` to target `t` adds column `x_c` into column `x_t` of the check matrix (`X_c ↦ X_c X_t`). -/ +theorem pauliXBit_cnotTgtPauli (a b : Fin 4) : + pauliXBit (cnotTgtPauli a b) = (pauliXBit b + pauliXBit a) % 2 := by + fin_cases a <;> fin_cases b <;> rfl + +/-- CNOT column operation, target `Z`-bit: `z_t` unchanged. The `Z`-bit of the new target Pauli is +the target's own `Z`-bit. -/ +theorem pauliZBit_cnotTgtPauli (a b : Fin 4) : pauliZBit (cnotTgtPauli a b) = pauliZBit b := by + fin_cases a <;> fin_cases b <;> rfl + +/-- CNOT column operation, control `X`-bit: `x_c` unchanged. The `X`-bit of the new control Pauli is +the control's own `X`-bit. -/ +theorem pauliXBit_cnotCtrlPauli (a b : Fin 4) : pauliXBit (cnotCtrlPauli a b) = pauliXBit a := by + fin_cases a <;> fin_cases b <;> rfl + +/-- CNOT column operation, control `Z`-bit: `z_c ↦ z_c + z_t` (mod 2). The `Z`-bit of the new +control Pauli is the sum of the control's and target's `Z`-bits — a `CNOT` from control `c` to +target `t` adds column `z_t` into column `z_c` of the check matrix (`Z_t ↦ Z_c Z_t`). -/ +theorem pauliZBit_cnotCtrlPauli (a b : Fin 4) : + pauliZBit (cnotCtrlPauli a b) = (pauliZBit a + pauliZBit b) % 2 := by + fin_cases a <;> fin_cases b <;> rfl + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringCommutation.lean b/LeanPool/AxQM/Concrete/PauliStringCommutation.lean new file mode 100644 index 0000000000..9f70c39d2e --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringCommutation.lean @@ -0,0 +1,192 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringBasisChange + +/-! +# Concrete: commutation of Pauli strings and the symplectic form (Nielsen & Chuang, Ex. 10.33) + +This file proves that any two `n`-fold Pauli strings (`Concrete.pauliString`, indexed by `g : Fin n +→ Fin 4`) either **commute** or **anticommute**, with the dichotomy governed entirely by the +**binary symplectic form** of their check-matrix rows. This is the algebraic heart of the stabilizer +formalism — Nielsen & Chuang, Exercise 10.33: two elements of the Pauli group commute iff `r(g) Λ +r(g')ᵀ = 0 (mod 2)`, where `r(·)` is the `(x | z)` check-matrix row and `Λ = [[0, I], [I, 0]]` is +the symplectic form. Because commutation is unchanged by the overall phase, the phase-free +`pauliString` (which carries no `±1, ±i` prefactor) is the right object for this fact. + +It is used throughout the Chapter 10 stabilizer-code material (Propositions 10.3–10.5, +Theorems 10.6–10.8, and the encoding circuit of Problem 10.3), each of which needs to know when +Pauli-group generators commute. + +## The binary symplectic representation + +Each single-qubit Pauli index `a : Fin 4` (`0 = I, 1 = X, 2 = Y, 3 = Z`) has an **X-bit** and a +**Z-bit** (`pauliXBit`, `pauliZBit`): `I ↦ (0,0)`, `X ↦ (1,0)`, `Y ↦ (1,1)`, `Z ↦ (0,1)`. A Pauli +string `g : Fin n → Fin 4` thus has check-matrix row `r(g) = (x_g | z_g)` with `x_g k = pauliXBit +(g k)`, `z_g k = pauliZBit (g k)`. The **symplectic pairing** of `a, b` is `singlePauliAnticomm a b += x_a z_b + z_a x_b`, and the total pairing of two strings is `pauliAnticommCount g h = Σ_k +(x_{g,k} z_{h,k} + z_{g,k} x_{h,k})` — exactly `r(g) Λ r(g')ᵀ`. Its **parity** (`Even`) is the +mod-2 symplectic condition of Exercise 10.33. + +## What is proved + +* `pauli_mul_comm_sign` — the single-qubit sign law `σ_a σ_b = (-1)^{singlePauliAnticomm a b} σ_b + σ_a`: two single-qubit Paulis commute or anticommute, and the symplectic pairing says which. +* `pauliString_mul_self` — each Pauli string is an **involution**, `P_g P_g = I` (so `P_g` is + unitary / its own inverse). +* `pauliString_mul_comm_sign` — the `n`-qubit sign law `P_g P_h = (-1)^{pauliAnticommCount g h} P_h + P_g`, obtained factor-by-factor from the single-qubit law via the tensor mixed-product property + (`kronFamily_mul`) and the scalar pull-out `kronFamily_smul_family`. +* `pauliAnticommCount_symm` — the symplectic form is symmetric, `pauliAnticommCount g h = + pauliAnticommCount h g` (so commutation is a symmetric relation). +* `pauliString_commute_iff` — **Nielsen & Chuang, Exercise 10.33**: `Commute P_g P_h ↔ Even + (pauliAnticommCount g h)`. The `⇐` direction reads the sign as `+1`; the `⇒` direction uses that + an odd pairing forces `P_g P_h = -P_g P_h`, hence `P_g P_h = 0`, contradicting `(P_g P_h)(P_h P_g) + = I` (the involution `pauliString_mul_self`). + +## Design notes + +* The pairing `singlePauliAnticomm` / `pauliAnticommCount` is a **natural-number count** (it equals + `2` on the diagonal `Y, Y` pair, not `1`), and it is only its **parity** that is the symplectic + invariant — `(-1)^{count}` and `Even count` are parity-invariant, so this faithfully realizes the + `(mod 2)` symplectic form while keeping a clean `ℕ` exponent for the sign. +* The proofs reduce everything to the per-qubit tensor-factorisation lemmas `kronFamily_mul` / + `kronFamily_one` of `Concrete/PauliStringBasisChange.lean`; the single-qubit base case + `pauli_mul_comm_sign` is a finite `4 × 4` case check. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +/-! ### Single-qubit symplectic data -/ + +/-- The **X-bit** of a single-qubit Pauli index: `I, X, Y, Z ↦ 0, 1, 1, 0`. It is `1` exactly for +the Paulis (`X`, `Y`) that contain an `X` factor, i.e. the X-part of the binary symplectic +representation of a single-qubit Pauli. -/ +def pauliXBit : Fin 4 → ℕ := ![0, 1, 1, 0] + +/-- The **Z-bit** of a single-qubit Pauli index: `I, X, Y, Z ↦ 0, 0, 1, 1`. It is `1` exactly for +the Paulis (`Y`, `Z`) that contain a `Z` factor, i.e. the Z-part of the binary symplectic +representation of a single-qubit Pauli. -/ +def pauliZBit : Fin 4 → ℕ := ![0, 0, 1, 1] + +/-- The **single-qubit symplectic pairing** of two Pauli indices, `x_a z_b + z_a x_b`. It is the +per-qubit contribution to the symplectic form `r(g) Λ r(g')ᵀ`, and its parity is the single-qubit +commutation indicator: `0 (mod 2)` when `σ_a`, `σ_b` commute, `1` when they anticommute. -/ +def singlePauliAnticomm (a b : Fin 4) : ℕ := + pauliXBit a * pauliZBit b + pauliZBit a * pauliXBit b + +/-- **Single-qubit commutation/anticommutation sign law**: `σ_a σ_b = (-1)^{singlePauliAnticomm a +b} · σ_b σ_a`. Any two single-qubit Paulis either commute (sign `+1`, symplectic pairing even) or +anticommute (sign `-1`, pairing odd); the symplectic pairing `singlePauliAnticomm` decides which. +Proved by the finite `4 × 4` case check on `a, b`. -/ +theorem pauli_mul_comm_sign (a b : Fin 4) : + pauli a * pauli b = (-1 : ℂ) ^ singlePauliAnticomm a b • (pauli b * pauli a) := by + fin_cases a <;> fin_cases b <;> + simp only [singlePauliAnticomm, pauliXBit, pauliZBit] <;> + norm_num [pauli] <;> + (ext i j; fin_cases i <;> fin_cases j <;> simp [pauliX, pauliY, pauliZ]) + +/-! ### Commutation of `n`-qubit Pauli strings -/ + +variable {n : ℕ} + +/-- The **symplectic form** (total anticommutation pairing) of two Pauli strings, `Σ_k +singlePauliAnticomm (g k) (h k)`. This is `r(g) Λ r(g')ᵀ` for the check-matrix rows `r(g) = (x_g | +z_g)` and symplectic form `Λ = [[0, I], [I, 0]]`; its parity is the mod-2 quantity of Nielsen & +Chuang, Exercise 10.33. -/ +def pauliAnticommCount (g h : Fin n → Fin 4) : ℕ := ∑ k, singlePauliAnticomm (g k) (h k) + +/-- The symplectic form is **symmetric**: `pauliAnticommCount g h = pauliAnticommCount h g` +(equivalently `Λ` is symmetric), so the commutation relation it governs is symmetric. -/ +theorem pauliAnticommCount_symm (g h : Fin n → Fin 4) : + pauliAnticommCount g h = pauliAnticommCount h g := by + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [singlePauliAnticomm] + ring + +/-- Each Pauli string is an **involution**: `P_g P_g = I`. Factor-by-factor `σ_{gₖ}² = I` +(`pauli_mul_self`), so the tensor product is `⨂ₖ I = I` (`kronFamily_one`). In particular `P_g` is +its own inverse, hence unitary. -/ +theorem pauliString_mul_self (g : Fin n → Fin 4) : pauliString g * pauliString g = 1 := by + rw [pauliString_eq_kronFamily, kronFamily_mul] + simp only [pauli_mul_self] + exact kronFamily_one + +/-- **The `n`-qubit commutation/anticommutation sign law**: `P_g P_h = (-1)^{pauliAnticommCount g h} +· P_h P_g`. The Pauli strings commute or anticommute as a whole, and the total symplectic pairing +decides which. Obtained factor-by-factor from the single-qubit law (`pauli_mul_comm_sign`) via the +tensor mixed-product property (`kronFamily_mul`): each qubit contributes its sign `(-1)^{…}`, and +the product of signs is `(-1)` to the sum of the pairings (`Finset.prod_pow_eq_pow_sum`). -/ +theorem pauliString_mul_comm_sign (g h : Fin n → Fin 4) : + pauliString g * pauliString h = + (-1 : ℂ) ^ pauliAnticommCount g h • (pauliString h * pauliString g) := by + rw [pauliString_eq_kronFamily g, pauliString_eq_kronFamily h, kronFamily_mul] + have hfac : (fun k => pauli (g k) * pauli (h k)) + = (fun k => (-1 : ℂ) ^ singlePauliAnticomm (g k) (h k) • (pauli (h k) * pauli (g k))) := by + funext k; exact pauli_mul_comm_sign (g k) (h k) + rw [hfac, kronFamily_smul_family, Finset.prod_pow_eq_pow_sum, ← kronFamily_mul, + ← pauliString_eq_kronFamily, ← pauliString_eq_kronFamily] + rfl + +/-- **Nielsen & Chuang, Exercise 10.33** (the symplectic check-matrix commutation condition): two +Pauli strings commute iff their symplectic form vanishes mod 2, +`Commute P_g P_h ↔ Even (pauliAnticommCount g h)`. The `⇐` direction reads the sign law +(`pauliString_mul_comm_sign`) with sign `+1`. For `⇒`, an odd pairing would give sign `-1`, so +`P_g P_h = -(P_h P_g) = -(P_g P_h)` (using commutation), forcing `P_g P_h = 0`; but the involution +property (`pauliString_mul_self`) gives `(P_g P_h)(P_h P_g) = I`, contradicting `0 = I`. -/ +theorem pauliString_commute_iff (g h : Fin n → Fin 4) : + Commute (pauliString g) (pauliString h) ↔ Even (pauliAnticommCount g h) := by + have hinv : (pauliString g * pauliString h) * (pauliString h * pauliString g) = 1 := by + rw [mul_assoc, ← mul_assoc (pauliString h), pauliString_mul_self, one_mul, + pauliString_mul_self] + constructor + · intro hcomm + by_contra hodd + rw [Nat.not_even_iff_odd] at hodd + have hsign : (-1 : ℂ) ^ pauliAnticommCount g h = -1 := hodd.neg_one_pow + have key := pauliString_mul_comm_sign g h + rw [hsign, neg_one_smul, hcomm.eq] at key + have hz : pauliString h * pauliString g = 0 := by + have h2 : (2 : ℂ) • (pauliString h * pauliString g) = 0 := by + rw [two_smul]; nth_rewrite 2 [key]; rw [add_neg_cancel] + exact (smul_eq_zero.mp h2).resolve_left two_ne_zero + rw [hcomm.eq, hz, zero_mul] at hinv + exact zero_ne_one hinv + · intro heven + have hsign : (-1 : ℂ) ^ pauliAnticommCount g h = 1 := heven.neg_one_pow + have key := pauliString_mul_comm_sign g h + rw [hsign, one_smul] at key + exact key + +/-- **An anticommuting Pauli partner is non-identity.** If `p` anticommutes with `q` — the +symplectic pairing `pauliAnticommCount p q` is odd — then `p` has a support wire (`∃ c, p c ≠ 0`). +Contrapositive: if `p` were the identity string (`∀ k, p k = 0`) then every per-wire pairing +`singlePauliAnticomm 0 _` vanishes, so `pauliAnticommCount p q = 0`, which is even. Shared +structural fact used to pick a pivot wire when reducing an anticommuting generator pair to standard +form (Nielsen & Chuang Ex. 10.40). -/ +theorem exists_support_of_odd_pauliAnticommCount (p q : Fin n → Fin 4) + (hpq : Odd (pauliAnticommCount p q)) : ∃ c, p c ≠ 0 := by + by_contra hall + have hp0 : ∀ k, p k = 0 := fun k => by + by_contra hk; exact hall ⟨k, hk⟩ + have hz : pauliAnticommCount p q = 0 := by + refine Finset.sum_eq_zero fun k _ => ?_ + rw [hp0 k] + simp [singlePauliAnticomm, pauliXBit, pauliZBit] + rw [hz] at hpq + exact absurd hpq (by decide) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringDiagonalize.lean b/LeanPool/AxQM/Concrete/PauliStringDiagonalize.lean new file mode 100644 index 0000000000..3ed8f197af --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringDiagonalize.lean @@ -0,0 +1,247 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringBasisChange + +/-! +# Concrete: single-qubit basis change diagonalising an arbitrary Pauli string to all-`Z` + +This file generalises the matrix core of Nielsen & Chuang **Exercise 4.51** (the specific `X ⊗ Y ⊗ +Z` reduction of +`Concrete/PauliStringBasisChange.lean`) to an **arbitrary** `n`-qubit Pauli string, the first step +of **Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit gates". + +## The construction (N&C §4.7.3) + +N&C's simulation algorithm reduces the exponential of any tensor-product Pauli Hamiltonian +`g = ⨂ₖ σ_{gₖ}` to the exponential of an operator that is `Z` on the string's support and `I` +elsewhere — whose `e^{-iΔt}` circuit is the Figure-4.19 parity computation — by **single-qubit basis +changes**: an `X` factor is conjugated to `Z` by Hadamard (`H · Z · H = X`), a `Y` factor by `S·H` +(`(SH) · Z · (SH)† = Y`), a `Z` or `I` factor is left alone. Collecting these per-qubit gates into a +single-qubit family `B = ⨂ₖ Bₖ`, the string factorises as `g = B · d(g) · B†`, where `d(g)` is the +**diagonalised string** (`I ↦ I`, every `X`/`Y`/`Z` factor `↦ Z`); hence +`exp(s · g) = B · exp(s · d(g)) · B†` for any scalar `s` (physically `s = -i h_g Δ`). + +## What is proved + +* `pauliDiagGate a` — the single-qubit basis-change gate for Pauli `σ_a` + (`![1, H, SH, 1]`: identity for `I`/`Z`, Hadamard for `X`, `S·H` for `Y`); + `pauliToZ a` — the diagonalised Pauli index (`![0, 3, 3, 3]`: `I ↦ I`, else `↦ Z`). +* `pauliDiagGate_conj_pauli` — the per-qubit conjugation `Bₐ · σ_{d(a)} · Bₐ† = σₐ`, and + `pauliDiagGate_mul_conjTranspose` / `pauliDiagGate_conjTranspose_mul` — each `Bₐ` unitary. +* `pauliString_conj_kronFamily_pauliDiagGate` — the string identity + `B · d(g) · B† = g` (`B = kronFamily (Bₐ ∘ g)`, `d(g) = pauliString (pauliToZ ∘ g)`), with + `kronFamily_pauliDiagGate_mul_conjTranspose` / `..._conjTranspose_mul` its unitarity. +* `pauliStringStd_conj_kronFamilyStd_pauliDiagGate` and its unitarity — the same on the flat + computational-basis indexing `Fin (2ⁿ)` that `pauliStringStd` (and the register `qudit (2ⁿ)`) use. +* `pauliStringStd_exp_smul_conj_kronFamilyStd_pauliDiagGate` — the exponentiated form + `exp(s · g) = B · exp(s · d(g)) · B†` on `Fin (2ⁿ)`, the matrix content of "apply `B`, run the + diagonal (Figure-4.19) simulation, undo `B`" for a general Pauli string. +-/ + +@[expose] public section + +open Matrix Complex + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The per-qubit diagonalising gate -/ + +/-- The **single-qubit basis-change gate** `Bₐ` diagonalising Pauli `σ_a` to `Z`: `![1, H, SH, 1]`, +i.e. the identity for `I` (`a = 0`) and `Z` (`a = 3`), Hadamard `H` for `X` (`a = 1`), and the `Y` +basis change `S·H` (`basisChangeY`) for `Y` (`a = 2`). It satisfies `Bₐ · σ_{pauliToZ a} · Bₐ† = σₐ` +(`pauliDiagGate_conj_pauli`): conjugating the diagonalised factor recovers the original Pauli. -/ +noncomputable def pauliDiagGate : Fin 4 → Matrix (Fin 2) (Fin 2) ℂ := + ![1, hadamardC, basisChangeY, 1] + +/-- The **diagonalised Pauli index** `d(a)` sending every non-identity Pauli to `Z`: `![0, 3, 3, 3]` +(`I ↦ I`, `X ↦ Z`, `Y ↦ Z`, `Z ↦ Z`). For a Pauli string `g`, `pauliString (pauliToZ ∘ g)` is `Z` +on the string's support and `I` elsewhere — the operator whose exponential the Figure-4.19 parity +circuit implements. -/ +def pauliToZ : Fin 4 → Fin 4 := ![0, 3, 3, 3] + +/-- `pauliToZ` sends every **non-identity** Pauli index to `Z` (`3`): the diagonalisation puts a `Z` +on each support wire of a Pauli string. -/ +theorem pauliToZ_eq_three_of_ne_zero (m : Fin 4) (hm : m ≠ 0) : pauliToZ m = 3 := by + fin_cases m <;> simp_all [pauliToZ] + +/-- `pauliToZ` vanishes **exactly** on the identity index `I` (`0`): `pauliToZ m = 0 ↔ m = 0`. +Together with `pauliToZ_eq_three_of_ne_zero` this pins the diagonalised string `d(g) = pauliToZ ∘ g` +— `I` off the support of `g`, `Z` on it. -/ +theorem pauliToZ_eq_zero_iff {m : Fin 4} : pauliToZ m = 0 ↔ m = 0 := by + fin_cases m <;> decide + +/-- **Per-qubit diagonalisation** `Bₐ · σ_{d(a)} · Bₐ† = σₐ`. For `a = 0` (`I`) and `a = 3` (`Z`) +the gate is the identity and `d(a)` leaves the factor unchanged; for `a = 1` (`X`) this is +`H · Z · H = X` (`hadamardC_mul_pauliZ_mul_hadamardC`) and for `a = 2` (`Y`) it is +`(SH) · Z · (SH)† = Y` (`basisChangeY_conj_pauliZ`). -/ +theorem pauliDiagGate_conj_pauli (a : Fin 4) : + pauliDiagGate a * pauli (pauliToZ a) * (pauliDiagGate a)ᴴ = pauli a := by + fin_cases a + · simp [pauliDiagGate, pauliToZ, pauli] + · simpa [pauliDiagGate, pauliToZ, pauli, hadamardC_isHermitian.eq] using + hadamardC_mul_pauliZ_mul_hadamardC + · simpa [pauliDiagGate, pauliToZ, pauli] using basisChangeY_conj_pauliZ + · simp [pauliDiagGate, pauliToZ, pauli] + +/-- Each diagonalising gate `Bₐ` is unitary: `Bₐ · Bₐ† = 1`. The identity and `Z` gates are `1`, the +`X` gate is `H` (`hadamardC_mul_self`), the `Y` gate is `S·H` (`basisChangeY_mul_conjTranspose`). -/ +theorem pauliDiagGate_mul_conjTranspose (a : Fin 4) : + pauliDiagGate a * (pauliDiagGate a)ᴴ = 1 := by + fin_cases a + · simp [pauliDiagGate] + · simpa [pauliDiagGate, hadamardC_isHermitian.eq] using hadamardC_mul_self + · simpa [pauliDiagGate] using basisChangeY_mul_conjTranspose + · simp [pauliDiagGate] + +/-- Each diagonalising gate `Bₐ` is unitary: `Bₐ† · Bₐ = 1`. As `pauliDiagGate_mul_conjTranspose` +with the factors reversed. -/ +theorem pauliDiagGate_conjTranspose_mul (a : Fin 4) : + (pauliDiagGate a)ᴴ * pauliDiagGate a = 1 := by + fin_cases a + · simp [pauliDiagGate] + · simpa [pauliDiagGate, hadamardC_isHermitian.eq] using hadamardC_mul_self + · simpa [pauliDiagGate] using basisChangeY_conjTranspose_mul + · simp [pauliDiagGate] + +/-- Each diagonalising gate `Bₐ` lies in the unitary group `U(2)`, since `Bₐ† · Bₐ = 1` +(`pauliDiagGate_conjTranspose_mul`). The membership form, letting each `Bₐ` be promoted to a gate +`Evolution` (`quditGate` / `unitaryGate`) for the basis-change layer of Problem 4.3(3). -/ +theorem pauliDiagGate_mem_unitaryGroup (a : Fin 4) : + pauliDiagGate a ∈ Matrix.unitaryGroup (Fin 2) ℂ := + Matrix.mem_unitaryGroup_iff'.2 <| by + rw [Matrix.star_eq_conjTranspose]; exact pauliDiagGate_conjTranspose_mul a + +/-! ### The `n`-qubit basis-change reduction `g = B · d(g) · B†` -/ + +/-- **Problem 4.3(3), matrix form: the basis-change reduction of an arbitrary Pauli string.** +The single-qubit family `B = ⨂ₖ B_{gₖ}` conjugates the diagonalised string +`d(g) = ⨂ₖ σ_{pauliToZ (gₖ)}` (`Z` on the support, `I` elsewhere) back to the original Pauli string: +`B · d(g) · B† = g`. Reducing both strings to `kronFamily` and applying the mixed-product property +twice (`kronFamily_mul`, `kronFamily_conjTranspose`) turns the left side into +`⨂ₖ (B_{gₖ} · σ_{pauliToZ (gₖ)} · B_{gₖ}†)`, which is `⨂ₖ σ_{gₖ} = g` factor-by-factor +(`pauliDiagGate_conj_pauli`). Generalises `pauliString_conj_kronFamily` (the `X ⊗ Y ⊗ Z` case). -/ +theorem pauliString_conj_kronFamily_pauliDiagGate (g : Fin n → Fin 4) : + kronFamily (fun k => pauliDiagGate (g k)) * pauliString (fun k => pauliToZ (g k)) + * (kronFamily (fun k => pauliDiagGate (g k)))ᴴ + = pauliString g := by + rw [pauliString_eq_kronFamily (fun k => pauliToZ (g k)), kronFamily_conjTranspose, + kronFamily_mul, kronFamily_mul, pauliString_eq_kronFamily g] + congr 1 + funext k + exact pauliDiagGate_conj_pauli (g k) + +/-- The tensor basis change `B = ⨂ₖ B_{gₖ}` is unitary: `B · B† = 1`. Factor-by-factor from the +per-qubit unitarity (`pauliDiagGate_mul_conjTranspose`) via `kronFamily_mul`, `kronFamily_one`. -/ +theorem kronFamily_pauliDiagGate_mul_conjTranspose (g : Fin n → Fin 4) : + kronFamily (fun k => pauliDiagGate (g k)) * (kronFamily (fun k => pauliDiagGate (g k)))ᴴ + = 1 := by + rw [kronFamily_conjTranspose, kronFamily_mul] + simp only [pauliDiagGate_mul_conjTranspose, kronFamily_one] + +/-- The tensor basis change `B = ⨂ₖ B_{gₖ}` is unitary: `B† · B = 1`. -/ +theorem kronFamily_pauliDiagGate_conjTranspose_mul (g : Fin n → Fin 4) : + (kronFamily (fun k => pauliDiagGate (g k)))ᴴ * kronFamily (fun k => pauliDiagGate (g k)) + = 1 := by + rw [kronFamily_conjTranspose, kronFamily_mul] + simp only [pauliDiagGate_conjTranspose_mul, kronFamily_one] + +/-- **Problem 4.3(3), exponentiated form on bit strings: the circuit for `exp(s · g)`.** For any +complex scalar `s` (physically `s = -i h_g Δ`), the exponential of a general Pauli string factors as +the local conjugation of the diagonalised (all-`Z`-on-support) exponential: +`exp(s · g) = B · exp(s · d(g)) · B†` on the bit-string register `Fin n → Fin 2`, where +`B = ⨂ₖ B_{gₖ}` (`kronFamily (pauliDiagGate ∘ g)`) and `d(g) = pauliToZ ∘ g` (the diagonalised +string). Since `s • g` is conjugated by `B` exactly as `g` is +(`pauliString_conj_kronFamily_pauliDiagGate`), and `B` is unitary — hence a unit with inverse `B†` — +`Matrix.exp_units_conj` pushes the conjugation through the exponential. + +This is the **bit-string companion** of the flat-register +`pauliStringStd_exp_smul_conj_kronFamilyStd_pauliDiagGate`; it is the form Problem 4.3(3)'s +Figure-4.19 circuit assembly composes with the parity-cascade collapse +`pauliString_exp_smul_conj_cnotFanInto` (which is stated over bit strings), keeping the entire +exponential reduction on `Fin n → Fin 2` and reindexing to the register only once, at the end. -/ +theorem pauliString_exp_smul_conj_kronFamily_pauliDiagGate (g : Fin n → Fin 4) (s : ℂ) : + NormedSpace.exp (s • pauliString g) + = kronFamily (fun k => pauliDiagGate (g k)) + * NormedSpace.exp (s • pauliString (fun k => pauliToZ (g k))) + * (kronFamily (fun k => pauliDiagGate (g k)))ᴴ := by + let u : (Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ)ˣ := + ⟨kronFamily (fun k => pauliDiagGate (g k)), (kronFamily (fun k => pauliDiagGate (g k)))ᴴ, + kronFamily_pauliDiagGate_mul_conjTranspose g, kronFamily_pauliDiagGate_conjTranspose_mul g⟩ + have hconj : s • pauliString g + = kronFamily (fun k => pauliDiagGate (g k)) + * (s • pauliString (fun k => pauliToZ (g k))) + * (kronFamily (fun k => pauliDiagGate (g k)))ᴴ := by + rw [← pauliString_conj_kronFamily_pauliDiagGate g, Matrix.mul_smul, Matrix.smul_mul] + rw [hconj] + exact Matrix.exp_units_conj u (s • pauliString (fun k => pauliToZ (g k))) + +/-! ### The flat computational-basis (register) indexing `Fin (2ⁿ)` -/ + +/-- **Problem 4.3(3), the reduction on the flat register `Fin (2ⁿ)`.** The Std-indexed basis change +`B = ⨂ₖ B_{gₖ}` conjugates the diagonalised string to the original: `B · d(g) · B† = g`, on the +`Fin (2ⁿ)` computational basis that `pauliStringStd` (and the register `qudit (2ⁿ)`) use. The flat +image of `pauliString_conj_kronFamily_pauliDiagGate`, obtained by `submatrix_conj_equiv`. -/ +theorem pauliStringStd_conj_kronFamilyStd_pauliDiagGate (g : Fin n → Fin 4) : + kronFamilyStd (fun k => pauliDiagGate (g k)) * pauliStringStd (fun k => pauliToZ (g k)) + * (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ + = pauliStringStd g := by + simp only [kronFamilyStd, pauliStringStd] + rw [← submatrix_conj_equiv, pauliString_conj_kronFamily_pauliDiagGate] + +/-- The Std basis change is unitary: `B · B† = 1` on `Fin (2ⁿ)`. The flat image of +`kronFamily_pauliDiagGate_mul_conjTranspose`. -/ +theorem kronFamilyStd_pauliDiagGate_mul_conjTranspose (g : Fin n → Fin 4) : + kronFamilyStd (fun k => pauliDiagGate (g k)) * (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ + = 1 := by + simp only [kronFamilyStd, Matrix.conjTranspose_submatrix] + rw [Matrix.submatrix_mul_equiv, kronFamily_pauliDiagGate_mul_conjTranspose, + Matrix.submatrix_one_equiv] + +/-- The Std basis change is unitary: `B† · B = 1` on `Fin (2ⁿ)`. -/ +theorem kronFamilyStd_pauliDiagGate_conjTranspose_mul (g : Fin n → Fin 4) : + (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ * kronFamilyStd (fun k => pauliDiagGate (g k)) + = 1 := by + simp only [kronFamilyStd, Matrix.conjTranspose_submatrix] + rw [Matrix.submatrix_mul_equiv, kronFamily_pauliDiagGate_conjTranspose_mul, + Matrix.submatrix_one_equiv] + +/-- **Problem 4.3(3), exponentiated form: the circuit for `exp(s · g)`.** For any complex scalar `s` +(physically `s = -i h_g Δ`), the exponential of a general Pauli string factors as the local +conjugation of the diagonalised (all-`Z`-on-support) exponential: +`exp(s · g) = B · exp(s · d(g)) · B†` on the flat register `Fin (2ⁿ)`. Since `s • g` is conjugated +by `B` exactly as `g` is (`pauliStringStd_conj_kronFamilyStd_pauliDiagGate`), and `B` is unitary — +hence a unit with inverse `B†` — `Matrix.exp_units_conj` pushes the conjugation through the +exponential. +This is the algebraic content of "apply the local basis change `B`, run the Figure-4.19 diagonal +simulation, undo `B`" for an arbitrary Pauli string; it generalises +`pauliString_exp_smul_conj_kronFamily` (the `X ⊗ Y ⊗ Z` case). -/ +theorem pauliStringStd_exp_smul_conj_kronFamilyStd_pauliDiagGate (g : Fin n → Fin 4) (s : ℂ) : + NormedSpace.exp (s • pauliStringStd g) + = kronFamilyStd (fun k => pauliDiagGate (g k)) + * NormedSpace.exp (s • pauliStringStd (fun k => pauliToZ (g k))) + * (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ := by + let u : (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ)ˣ := + ⟨kronFamilyStd (fun k => pauliDiagGate (g k)), (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ, + kronFamilyStd_pauliDiagGate_mul_conjTranspose g, + kronFamilyStd_pauliDiagGate_conjTranspose_mul g⟩ + have hconj : s • pauliStringStd g + = kronFamilyStd (fun k => pauliDiagGate (g k)) + * (s • pauliStringStd (fun k => pauliToZ (g k))) + * (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ := by + rw [← pauliStringStd_conj_kronFamilyStd_pauliDiagGate g, Matrix.mul_smul, Matrix.smul_mul] + rw [hconj] + exact Matrix.exp_units_conj u (s • pauliStringStd (fun k => pauliToZ (g k))) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringEncodingCnotLayer.lean b/LeanPool/AxQM/Concrete/PauliStringEncodingCnotLayer.lean new file mode 100644 index 0000000000..1c78fc0fe9 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringEncodingCnotLayer.lean @@ -0,0 +1,323 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringEncodingLayers + +/-! +# Concrete: the CNOT layer of the stabilizer encoding circuit (Nielsen & Chuang, Problem 10.3) + +This file continues the **synthesis** half of Nielsen & Chuang **Problem 10.3** ("encoding +stabilizer codes"): after the Hadamard layer (`Concrete/PauliStringEncodingLayers.lean`) has turned +the top `r` rows of the trivial check matrix `G` of Eq. (10.124) from `Z`-type (`Zᵢ`) into `X`-type +(`Xᵢ`), the second layer is a **network of CNOT gates**, all controlled on those top `X`-rows, that +builds the `X`-blocks `A₁, A₂` of the standard form (10.125) — and, by the coupled column +operations of a CNOT, simultaneously builds the transposed `Z`-blocks `A₁ᵀ` (into the middle +generator rows) and `A₂ᵀ` (into the bottom encoded-`Z` rows). This file delivers the reusable unit +of that network: the **fan of CNOTs from one control**. + +## The CNOT fan + +`cnotFan i ts` is the circuit applying a CNOT from control wire `i` to each target `t` in a list +`ts` (a self-target `t = i` is dropped, so the fan is total: `cnotStep i t`). With `ts` the +support of row `i` of `[A₁ | A₂]`, `cnotFan i ts` is exactly the CNOT network attached to the +`i`-th top generator. The two column operations of `CNOT_{i→t}` (`x_t += x_c`, `z_c += z_t`; +Figure 10.7) drive the two effects: + +* `act_cnotFan_xGenPauli` — the **X-spread** (building row `i` of `A₁, A₂`): applied to the + `X`-seed `Xᵢ`, the fan produces the Pauli string with an `X` on wire `i` and on every wire in + `ts` (`xSetPauli (i :: ts)`). Each `CNOT_{i→t}` copies the control's `X` onto the target + (`x_t += x_c`), so the seed's single `X` fans out to the whole target set. On the check matrix + this is row `i` becoming `(eᵢ + Σ_{t∈ts} e_t | 0)` — the `I` diagonal entry plus the row's + `A₁, A₂` entries. +* `act_cnotFan_zGenPauli_of_mem` — the **coupled transpose** (building `A₂ᵀ` / `A₁ᵀ`): applied + to a pure-`Z` generator `Z_m` with `m ∈ ts`, the fan produces `Z_i Z_m` (`zPairPauli i m`). + The single gate `CNOT_{i→m}` copies the target's `Z` back onto the control (`z_i += z_m`), so + a `Z` on a target wire `m` deposits a `Z` on the control wire `i`. Iterated over the top + controls `i`, this is precisely how a `Z` in the identity block of a bottom (encoded-`Z`) or + middle row is transposed into column `i` — the blocks `A₂ᵀ` (bottom) and `A₁ᵀ` (middle) of + (10.125). +* `act_cnotFan_zGenPauli_of_not_mem` — the fan leaves a pure-`Z` generator `Z_m` **unchanged** + when `m ∉ ts`: a `Z` on a wire the fan neither controls nor targets is untouched, and a `Z` on + the control itself is preserved (no target carries a `Z` to add). This is what keeps the layer + from disturbing rows outside its support. + +The check-matrix readings (`checkRow_act_cnotFan_xGenPauli`, +`checkRow_act_cnotFan_zGenPauli_of_mem`) and the operator-level readings through the backbone +`CliffordCircuit.conj_pauliString` (`cnotFan_conj_xGenPauli`, `cnotFan_conj_zGenPauli_of_mem`) +record the same facts as check-matrix column operations and as unitary conjugations up to a +nonzero `±1` phase. + +## Design notes + +* `cnotFan i ts = ts.flatMap (cnotStep i)`, so it composes with the other layers as list + concatenation and its `act`/`sign`/`toMatrix` are the existing `CliffordCircuit` folds — + nothing new about circuits is introduced, only the specific gate list. The helper + `cnotStep i t` (`if i = t then [] else [CNOT_{i→t}]`) makes the fan **total** — a self-target + is simply skipped — which sidesteps carrying a `i ∉ ts` proof through the gate list; the + action lemmas re-supply `i ∉ ts` and `ts.Nodup` as hypotheses where they are actually needed + (freshness of each target). +* Both action lemmas need `ts.Nodup`: a target hit twice would have its column operation applied + twice and, `X`/`Z` bits living in `ZMod 2`, cancel — the clean "spread over exactly the wires + in `ts`" statement is the one the encoding circuit uses (each `1` of `A` gives one CNOT). +* The single-gate facts `cnotPauliString_fixed` (a fan leaves a control/target pair fixed when + the control is `I`/`Z` and the target is `I`) and `cnotPauliString_zGenPauli_couple` + (`CNOT_{i→m} : Z_m ↦ Z_i Z_m`) are read off the tableau of + `Concrete/PauliStringCnotConjugation.lean`; the layer lemmas are inductions over `ts` on top + of them. +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Multi-wire generators (rows of the check matrix) -/ + +/-- The **multi-`X` Pauli string** on a wire list `S`: `X` on every wire in `S`, `I` elsewhere. +The image of the `X`-seed `Xᵢ` under a CNOT fan (`act_cnotFan_xGenPauli`); its check row is +`(1_S | 0)` — a `1` in each `X`-column of `S`. -/ +def xSetPauli (S : List (Fin n)) : Fin n → Fin 4 := fun k => if k ∈ S then 1 else 0 + +/-- The **two-wire `Z` Pauli string** `Z_i Z_m`: `Z` on wires `i` and `m`, `I` elsewhere. The +image of the pure-`Z` generator `Z_m` under a CNOT fan controlled on `i` with `m` a target +(`act_cnotFan_zGenPauli_of_mem`); its check row is `(0 | e_i + e_m)`. -/ +def zPairPauli (i m : Fin n) : Fin n → Fin 4 := fun k => if k = i ∨ k = m then 3 else 0 + +@[simp] theorem xSetPauli_apply (S : List (Fin n)) (k : Fin n) : + xSetPauli S k = if k ∈ S then 1 else 0 := rfl + +@[simp] theorem zPairPauli_apply (i m k : Fin n) : + zPairPauli i m k = if k = i ∨ k = m then 3 else 0 := rfl + +/-! ### The CNOT fan -/ + +/-- A **single CNOT step** from control `i` to target `t`: the one-gate circuit `[CNOT_{i→t}]`, +or the empty circuit if `t = i` (a self-target is skipped). This keeps the CNOT fan total. -/ +def cnotStep (i t : Fin n) : CliffordCircuit n := + if h : i = t then [] else [CliffordGate.cnot i t h] + +/-- The **CNOT fan** from control wire `i` onto the target wires `ts`: apply a CNOT from `i` to +each `t ∈ ts` (`ts.flatMap (cnotStep i)`). With `ts` the support of row `i` of the `X`-block +`[A₁ | A₂]`, this is the CNOT network attached to the `i`-th top generator in the encoding +circuit of Nielsen & Chuang Problem 10.3. -/ +def cnotFan (i : Fin n) (ts : List (Fin n)) : CliffordCircuit n := ts.flatMap (cnotStep i) + +/-- The fan on no targets is the empty circuit. -/ +@[simp] theorem cnotFan_nil (i : Fin n) : cnotFan i [] = [] := rfl + +/-- The fan is built one target at a time: `cnotFan i (t :: ts) = cnotStep i t ++ cnotFan i ts`. -/ +theorem cnotFan_cons (i t : Fin n) (ts : List (Fin n)) : + cnotFan i (t :: ts) = cnotStep i t ++ cnotFan i ts := by + simp only [cnotFan, List.flatMap_cons] + +/-- **The row action factors over `++`**: conjugating by `U ++ V` applies `V` first, then `U` +(`act (U ++ V) g = act U (act V g)`), since `act` composes gates right-to-left. -/ +theorem act_append (U V : CliffordCircuit n) (g : Fin n → Fin 4) : + CliffordCircuit.act (U ++ V) g = CliffordCircuit.act U (CliffordCircuit.act V g) := by + induction U with + | nil => rfl + | cons γ U ih => simp only [List.cons_append, CliffordCircuit.act, ih] + +/-- The row action of a single CNOT step with `i ≠ t` is the CNOT column operation +`cnotPauliString g i t`. -/ +theorem act_cnotStep_of_ne {i t : Fin n} (hit : i ≠ t) (g : Fin n → Fin 4) : + CliffordCircuit.act (cnotStep i t) g = cnotPauliString g i t := by + rw [cnotStep, dite_eq_right hit] + simp only [CliffordCircuit.act, CliffordGate.act] + +/-- Peeling the head of a CNOT fan (with `i ≠ t`): the head CNOT `i → t` acts last, on the result +of the rest of the fan. -/ +theorem act_cnotFan_cons_of_ne {i t : Fin n} (hit : i ≠ t) (ts : List (Fin n)) + (g : Fin n → Fin 4) : + CliffordCircuit.act (cnotFan i (t :: ts)) g + = cnotPauliString (CliffordCircuit.act (cnotFan i ts) g) i t := by + rw [cnotFan_cons, act_append, act_cnotStep_of_ne hit] + +/-! ### Single-CNOT tableau facts -/ + +/-- With an identity target, the control Pauli is unchanged: `cnotCtrlPauli a 0 = a` (a `CNOT` +whose target carries no `Z` does not touch the control's `Z`-bit). -/ +theorem cnotCtrlPauli_zero_right (a : Fin 4) : cnotCtrlPauli a 0 = a := by fin_cases a <;> rfl + +/-- **A CNOT `i → t` fixes a string whose target wire is `I` and whose control wire is `I` or +`Z`.** Since `x_c ∈ {0}` (control is `I` or `Z`), the target keeps its `I` (`x_t += x_c` adds +nothing), and since `z_t = 0` (target is `I`) the control keeps its `Z`-bit (`z_c += z_t` adds +nothing). This is why the fan leaves untouched every row on which the control and the current +target are inactive. -/ +theorem cnotPauliString_fixed {g : Fin n → Fin 4} {i t : Fin n} (hit : i ≠ t) + (ht0 : g t = 0) (hi : g i = 0 ∨ g i = 3) : cnotPauliString g i t = g := by + funext k + rcases eq_or_ne k i with rfl | hki + · rw [cnotPauliString_ctrl, ht0, cnotCtrlPauli_zero_right] + · rcases eq_or_ne k t with rfl | hkt + · rw [cnotPauliString_tgt g hit, ht0] + rcases hi with h | h <;> rw [h] <;> decide + · rw [cnotPauliString_of_ne g i t hki hkt] + +/-- **The coupling of a single CNOT** `CNOT_{i→m} : Z_m ↦ Z_i Z_m` (`i ≠ m`). The target's `Z` +is copied back onto the control (`z_i += z_m`), depositing a `Z` on the control wire while +leaving the `Z` on `m`. This is the elementary transpose operation building the `A₂ᵀ` / `A₁ᵀ` +blocks. -/ +theorem cnotPauliString_zGenPauli_couple {i m : Fin n} (him : i ≠ m) : + cnotPauliString (zGenPauli m) i m = zPairPauli i m := by + have hi : zGenPauli m i = 0 := by simp [zGenPauli_apply, him] + have hm : zGenPauli m m = 3 := by simp [zGenPauli_apply] + funext k + rcases eq_or_ne k i with rfl | hki + · rw [cnotPauliString_ctrl, hi, hm, zPairPauli_apply, ite_eq_left (Or.inl rfl)]; decide + · rcases eq_or_ne k m with rfl | hkm + · rw [cnotPauliString_tgt _ him, hi, hm, zPairPauli_apply, ite_eq_left (Or.inr rfl)]; decide + · rw [cnotPauliString_of_ne _ i m hki hkm, zGenPauli_apply, ite_eq_right hkm, zPairPauli_apply, + ite_eq_right (not_or.mpr ⟨hki, hkm⟩)] + +/-! ### The CNOT layer acting on the seed generators -/ + +/-- **The X-spread of the CNOT layer** (Nielsen & Chuang Problem 10.3, building `A₁, A₂`): +applying the fan `cnotFan i ts` (distinct targets `ts`, none equal to `i`) to the `X`-seed `Xᵢ` +returns the multi-`X` string with an `X` on wire `i` and on every target — `xSetPauli (i :: ts)`. +Each `CNOT_{i→t}` copies the control's `X` onto the target (`x_t += x_c`), so the seed's single +`X` fans out; on the check matrix this makes row `i` equal to `(eᵢ + Σ_{t∈ts} e_t | 0)`, the `I` +diagonal entry plus row `i` of the `X`-blocks. Proved by induction on `ts`. -/ +theorem act_cnotFan_xGenPauli (i : Fin n) : ∀ (ts : List (Fin n)), i ∉ ts → ts.Nodup → + CliffordCircuit.act (cnotFan i ts) (xGenPauli i) = xSetPauli (i :: ts) + | [], _, _ => by + funext k + simp only [cnotFan_nil, CliffordCircuit.act, xGenPauli_apply, xSetPauli_apply, + List.mem_singleton] + | t :: ts, h, hnd => by + rw [List.mem_cons, not_or] at h + obtain ⟨hit, hts⟩ := h + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + rw [act_cnotFan_cons_of_ne hit, act_cnotFan_xGenPauli i ts hts hnd'] + have hgi : xSetPauli (i :: ts) i = 1 := by simp [xSetPauli_apply] + have htmem : t ∉ i :: ts := by + simp only [List.mem_cons, not_or]; exact ⟨Ne.symm hit, htnotin⟩ + have hgt : xSetPauli (i :: ts) t = 0 := by simp [xSetPauli_apply, htmem] + funext k + rcases eq_or_ne k i with rfl | hki + · rw [cnotPauliString_ctrl, hgi, hgt, xSetPauli_apply, ite_eq_left (by simp)]; decide + · rcases eq_or_ne k t with rfl | hkt + · rw [cnotPauliString_tgt _ hit, hgi, hgt, xSetPauli_apply, ite_eq_left (by simp)]; decide + · rw [cnotPauliString_of_ne _ i t hki hkt, xSetPauli_apply, xSetPauli_apply] + have hmem : (k ∈ i :: t :: ts) ↔ (k ∈ i :: ts) := by simp [List.mem_cons, hkt] + simp only [hmem] + +/-- **The CNOT layer fixes a pure-`Z` generator off its target set** (`m ∉ ts`): a `Z` on a wire +the fan neither controls (`m` may be `i`) nor targets is left unchanged. Every target of the fan +is `I` in `Z_m`, so no `Z` is ever copied onto the control, and the control's `Z`-bit is likewise +undisturbed. Proved by induction on `ts` via `cnotPauliString_fixed`. -/ +theorem act_cnotFan_zGenPauli_of_not_mem (i : Fin n) : + ∀ (ts : List (Fin n)), i ∉ ts → ts.Nodup → + ∀ (m : Fin n), m ∉ ts → CliffordCircuit.act (cnotFan i ts) (zGenPauli m) = zGenPauli m + | [], _, _, _, _ => rfl + | t :: ts, h, hnd, m, hm => by + rw [List.mem_cons, not_or] at h hm + obtain ⟨hit, hts⟩ := h + obtain ⟨hmt, hmts⟩ := hm + obtain ⟨_, hnd'⟩ := List.nodup_cons.mp hnd + rw [act_cnotFan_cons_of_ne hit, act_cnotFan_zGenPauli_of_not_mem i ts hts hnd' m hmts] + apply cnotPauliString_fixed hit + · rw [zGenPauli_apply, ite_eq_right (Ne.symm hmt)] + · rcases eq_or_ne i m with rfl | hh + · exact Or.inr (by simp [zGenPauli_apply]) + · exact Or.inl (by simp [zGenPauli_apply, hh]) + +/-- **The coupled transpose of the CNOT layer** (Nielsen & Chuang Problem 10.3, building `A₂ᵀ` / +`A₁ᵀ`): applying the fan `cnotFan i ts` (distinct targets, none equal to `i`) to a pure-`Z` +generator `Z_m` with `m ∈ ts` returns `Z_i Z_m` (`zPairPauli i m`). The one gate `CNOT_{i→m}` +copies the target's `Z` back onto the control (`z_i += z_m`), depositing a `Z` on wire `i`; the +other gates of the fan leave it fixed. On the check matrix this puts a `1` in column `i` of row +`m`'s `Z`-part — the transposed entry. Iterated over the top controls `i`, this builds the whole +`A₂ᵀ` block of the bottom encoded-`Z` rows (and `A₁ᵀ` of the middle rows). Proved by induction on +`ts` via the single-gate coupling and `act_cnotFan_zGenPauli_of_not_mem`. -/ +theorem act_cnotFan_zGenPauli_of_mem (i : Fin n) : + ∀ (ts : List (Fin n)), i ∉ ts → ts.Nodup → + ∀ (m : Fin n), m ∈ ts → + CliffordCircuit.act (cnotFan i ts) (zGenPauli m) = zPairPauli i m + | [], _, _, m, hm => by simp at hm + | t :: ts, h, hnd, m, hm => by + rw [List.mem_cons, not_or] at h + obtain ⟨hit, hts⟩ := h + obtain ⟨htnotin, hnd'⟩ := List.nodup_cons.mp hnd + rw [act_cnotFan_cons_of_ne hit] + rcases List.mem_cons.mp hm with rfl | hmts + · rw [act_cnotFan_zGenPauli_of_not_mem i ts hts hnd' m htnotin] + exact cnotPauliString_zGenPauli_couple hit + · have hmt : m ≠ t := fun e => htnotin (e ▸ hmts) + rw [act_cnotFan_zGenPauli_of_mem i ts hts hnd' m hmts] + apply cnotPauliString_fixed hit + · rw [zPairPauli_apply, ite_eq_right (not_or.mpr ⟨Ne.symm hit, Ne.symm hmt⟩)] + · exact Or.inr (by rw [zPairPauli_apply, ite_eq_left (Or.inl rfl)]) + +/-! ### Check-matrix readings -/ + +/-- The check row of a multi-`X` string is `(1_S | 0)`: a `1` in each `X`-column of `S`, no +`Z`-part. -/ +theorem checkRow_xSetPauli (S : List (Fin n)) : + checkRow (xSetPauli S) = (fun k => if k ∈ S then (1 : ZMod 2) else 0, 0) := by + ext k <;> by_cases hk : k ∈ S <;> + simp [checkRow, xSetPauli, pauliBit, pauliXBit, pauliZBit, hk] + +/-- The check row of `Z_i Z_m` is `(0 | 1_{i} + 1_{m})`: no `X`-part, a `1` in `Z`-columns `i` +and `m`. -/ +theorem checkRow_zPairPauli (i m : Fin n) : + checkRow (zPairPauli i m) = (0, fun k => if k = i ∨ k = m then (1 : ZMod 2) else 0) := by + ext k <;> by_cases hk : k = i ∨ k = m <;> + simp [checkRow, zPairPauli, pauliBit, pauliXBit, pauliZBit, hk] + +/-- **The X-spread in check-matrix terms.** After the CNOT fan, row `i` of the check matrix is +`(1_{i :: ts} | 0)` — the `X`-part carries a `1` in column `i` (the `I` diagonal) and in each +column of the target set (the `A₁, A₂` entries of row `i`), and there is no `Z`-part. -/ +theorem checkRow_act_cnotFan_xGenPauli (i : Fin n) (ts : List (Fin n)) (h : i ∉ ts) + (hnd : ts.Nodup) : + checkRow (CliffordCircuit.act (cnotFan i ts) (xGenPauli i)) + = (fun k => if k ∈ i :: ts then (1 : ZMod 2) else 0, 0) := by + rw [act_cnotFan_xGenPauli i ts h hnd, checkRow_xSetPauli] + +/-- **The coupled transpose in check-matrix terms.** After the CNOT fan, the row of the +encoded-`Z` generator `Z_m` (`m ∈ ts`) is `(0 | 1_i + 1_m)` — the identity-block `1` in +`Z`-column `m` plus the transposed `1` deposited in `Z`-column `i` (an entry of `A₂ᵀ` / `A₁ᵀ`). -/ +theorem checkRow_act_cnotFan_zGenPauli_of_mem (i : Fin n) (ts : List (Fin n)) (h : i ∉ ts) + (hnd : ts.Nodup) (m : Fin n) (hm : m ∈ ts) : + checkRow (CliffordCircuit.act (cnotFan i ts) (zGenPauli m)) + = (0, fun k => if k = i ∨ k = m then (1 : ZMod 2) else 0) := by + rw [act_cnotFan_zGenPauli_of_mem i ts h hnd m hm, checkRow_zPairPauli] + +/-! ### Operator-level readings (through the backbone) -/ + +/-- **Operator-level X-spread**, through `CliffordCircuit.conj_pauliString`: the CNOT fan is a +unitary Clifford circuit conjugating the Pauli operator `P_{Xᵢ}` to a nonzero (`±1`, +`CliffordCircuit.sign_ne_zero`) scalar multiple of the multi-`X` operator +`P_{xSetPauli (i :: ts)}` — the physical content of `act_cnotFan_xGenPauli`. -/ +theorem cnotFan_conj_xGenPauli (i : Fin n) (ts : List (Fin n)) (h : i ∉ ts) (hnd : ts.Nodup) : + CliffordCircuit.toMatrix (cnotFan i ts) * pauliString (xGenPauli i) + * (CliffordCircuit.toMatrix (cnotFan i ts))ᴴ + = CliffordCircuit.sign (cnotFan i ts) (xGenPauli i) + • pauliString (xSetPauli (i :: ts)) := by + rw [CliffordCircuit.conj_pauliString, act_cnotFan_xGenPauli i ts h hnd] + +/-- **Operator-level coupled transpose**, through `CliffordCircuit.conj_pauliString`: for +`m ∈ ts` the CNOT fan conjugates `P_{Z_m}` to a nonzero (`±1`) scalar multiple of `P_{Z_i Z_m}` — +the physical content of `act_cnotFan_zGenPauli_of_mem`. -/ +theorem cnotFan_conj_zGenPauli_of_mem (i : Fin n) (ts : List (Fin n)) (h : i ∉ ts) + (hnd : ts.Nodup) (m : Fin n) (hm : m ∈ ts) : + CliffordCircuit.toMatrix (cnotFan i ts) * pauliString (zGenPauli m) + * (CliffordCircuit.toMatrix (cnotFan i ts))ᴴ + = CliffordCircuit.sign (cnotFan i ts) (zGenPauli m) • pauliString (zPairPauli i m) := by + rw [CliffordCircuit.conj_pauliString, act_cnotFan_zGenPauli_of_mem i ts h hnd m hm] + +end AxQM.Concrete + +end diff --git a/LeanPool/AxQM/Concrete/PauliStringEncodingLayers.lean b/LeanPool/AxQM/Concrete/PauliStringEncodingLayers.lean new file mode 100644 index 0000000000..ff90606bdb --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringEncodingLayers.lean @@ -0,0 +1,193 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit +public import LeanPool.AxQM.Concrete.CheckMatrix + +/-! +# Concrete: the Hadamard layer of the stabilizer encoding circuit (Nielsen & Chuang, Problem 10.3) + +This file begins the **synthesis** half of Nielsen & Chuang **Problem 10.3** ("encoding stabilizer +codes"): having established (in +`Concrete/PauliStringCliffordCircuit.lean`) that a `CliffordCircuit` conjugates a Pauli string to a +Pauli string and acts on the `n × 2n` **check matrix** by the composed elementary column operations, +we now build the specific circuit carrying the *trivial* check matrix `G` of Eq. (10.124) — a +listing of the single-qubit generators `Z₁, …, Zₙ` (X-part `0`, Z-part the identity) — to the +standard/encoded form of Eq. (10.125), one **layer** at a time. This file delivers the first layer. + +The rows of the check matrix are individual Pauli strings (`Concrete.pauliString`, +`g : Fin n → Fin 4`); a circuit `U` acts on the whole matrix by applying its row action +`CliffordCircuit.act U` to each row. Two single-generator objects name the rows we start from and +pass through: + +* `zGenPauli i` — the pure-`Z` generator `Zᵢ` (`Z` on wire `i`, `I` elsewhere): row `i` of the + trivial matrix `G` (10.124), with check row `(0 | eᵢ)` (`checkRow_zGenPauli`). +* `xGenPauli i` — the pure-`X` generator `Xᵢ`, with check row `(eᵢ | 0)` (`checkRow_xGenPauli`). + +## The Hadamard layer + +`hadLayer ws` is the circuit applying a Hadamard to each wire in a list `ws : List (Fin n)`. Because +`H` swaps the `X`- and `Z`-bits of its wire (`pauliXBit_hadamardPauli` / `pauliZBit_hadamardPauli`), +this layer is exactly the **Hadamards on the first `r` qubits** that open the encoding circuit: on +the trivial matrix `G` it turns row `i` from `Zᵢ` into `Xᵢ` for every `i ∈ ws`, leaving the rest +untouched. Concretely, for a list of **distinct** wires (`ws.Nodup` — each chosen wire is +Hadamard'd once): + +* `act_hadLayer` — its row action, `act (hadLayer ws) g k = hadamardPauli (g k)` for `k ∈ ws`, else + `g k` (only the chosen wires are transformed); +* `act_hadLayer_zGenPauli` — the **first encoding-circuit layer**: `act (hadLayer ws) Zᵢ = Xᵢ` when + `i ∈ ws`, else `Zᵢ`; +* `checkRow_act_hadLayer_zGenPauli` — the same in check-matrix terms: row `i` becomes `(eᵢ | 0)` for + `i ∈ ws`, else `(0 | eᵢ)`. With `ws` the first `r` wires this is the transition from `G` + (10.124, all rows `(0 | eᵢ)`) to the intermediate matrix with an `X`-identity block on top; +* `hadLayer_conj_zGenPauli` — the operator-level reading through the backbone + `CliffordCircuit.conj_pauliString`: the layer is a unitary circuit conjugating `P_{Zᵢ}` to a + nonzero (`±1`) multiple of `P_{Xᵢ}` / `P_{Zᵢ}` (`CliffordCircuit.sign_ne_zero`). + +## Design notes + +* `hadLayer ws = ws.map CliffordGate.had`, so `hadLayer` composes as list concatenation with the + other layers and its `act`/`sign`/`toMatrix` are the existing `CliffordCircuit` folds — nothing + new about circuits is introduced, only the specific gate list. +* `act_hadLayer` needs `ws.Nodup`: a wire appearing twice would be Hadamard'd twice, and although + `hadamardPauli` is an involution the clean "transform exactly the wires in `ws`" statement is the + one the encoding circuit uses (each of the first `r` qubits appears once). The `Nodup` is consumed + only through the cons step `w ∉ ws`, which lets the final `Function.update` on wire `w` see the + untouched value `g w`. +* The generators are `Function.update 0 i · ` on `Fin n → Fin 4` (`0 = I`, `1 = X`, `3 = Z`); their + check rows are read off the single source of truth `pauliBit` of `Concrete/CheckMatrix.lean`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Single-generator Pauli strings (rows of the check matrix) -/ + +/-- The **pure-`Z` generator** `Zᵢ`: the Pauli string with `Z` on wire `i` and `I` on every other +wire (`Function.update 0 i 3`, using `0 = I`, `3 = Z`). Row `i` of the trivial check matrix `G` of +Nielsen & Chuang Eq. (10.124); its check row is `(0 | eᵢ)` (`checkRow_zGenPauli`). -/ +def zGenPauli (i : Fin n) : Fin n → Fin 4 := Function.update 0 i 3 + +/-- The **pure-`X` generator** `Xᵢ`: the Pauli string with `X` on wire `i` and `I` on every other +wire (`Function.update 0 i 1`, using `0 = I`, `1 = X`). Its check row is `(eᵢ | 0)` +(`checkRow_xGenPauli`); it is the image of `Zᵢ` under a Hadamard on wire `i`. -/ +def xGenPauli (i : Fin n) : Fin n → Fin 4 := Function.update 0 i 1 + +@[simp] theorem zGenPauli_apply (i k : Fin n) : zGenPauli i k = if k = i then 3 else 0 := by + simp only [zGenPauli, Function.update_apply, Pi.zero_apply] + +@[simp] theorem xGenPauli_apply (i k : Fin n) : xGenPauli i k = if k = i then 1 else 0 := by + simp only [xGenPauli, Function.update_apply, Pi.zero_apply] + +/-- The check row of the pure-`Z` generator is `(0 | eᵢ)`: no `X`-part, and a single `1` in column +`i` of the `Z`-part. This is row `i` of the trivial check matrix `G` of Eq. (10.124). -/ +theorem checkRow_zGenPauli (i : Fin n) : + checkRow (zGenPauli i) = (0, Pi.single i (1 : ZMod 2)) := by + ext k <;> rcases eq_or_ne k i with rfl | hk <;> + simp [checkRow, pauliBit, pauliXBit, pauliZBit, *] + +/-- The check row of the pure-`X` generator is `(eᵢ | 0)`: a single `1` in column `i` of the +`X`-part, and no `Z`-part. -/ +theorem checkRow_xGenPauli (i : Fin n) : + checkRow (xGenPauli i) = (Pi.single i (1 : ZMod 2), 0) := by + ext k <;> rcases eq_or_ne k i with rfl | hk <;> + simp [checkRow, pauliBit, pauliXBit, pauliZBit, *] + +/-! ### The Hadamard layer -/ + +/-- The **Hadamard layer** on the wires `ws`: the Clifford circuit applying a Hadamard gate to each +wire in the list `ws` (`ws.map CliffordGate.had`). Taking `ws` to be the first `r` qubits, this is +the opening layer of the stabilizer encoding circuit of Nielsen & Chuang Problem 10.3. -/ +def hadLayer (ws : List (Fin n)) : CliffordCircuit n := ws.map CliffordGate.had + +/-- The Hadamard layer is built one wire at a time: `hadLayer (w :: ws) = had w :: hadLayer ws` +(definitionally, `List.map` on a cons). -/ +theorem hadLayer_cons (w : Fin n) (ws : List (Fin n)) : + hadLayer (w :: ws) = CliffordGate.had w :: hadLayer ws := rfl + +/-- **Row action of the Hadamard layer.** For a list of **distinct** wires `ws`, conjugating a Pauli +string by `hadLayer ws` applies the single-wire Hadamard tableau `hadamardPauli` to exactly the +wires in `ws`, leaving the others fixed: `act (hadLayer ws) g k = hadamardPauli (g k)` if `k ∈ ws`, +else `g k`. Proved by induction on `ws`; the cons step uses `w ∉ ws` (from `Nodup`) so the outer +`Function.update` on wire `w` reads the still-untouched value `g w`. -/ +theorem act_hadLayer (ws : List (Fin n)) (g : Fin n → Fin 4) (hnd : ws.Nodup) : + CliffordCircuit.act (hadLayer ws) g = fun k => if k ∈ ws then hadamardPauli (g k) else g k := by + revert hnd + induction ws with + | nil => intro _; funext k; simp [hadLayer, CliffordCircuit.act] + | cons w ws ih => + intro hnd + obtain ⟨hw, hnd'⟩ := List.nodup_cons.mp hnd + have hrec := ih hnd' + funext k + rw [hadLayer_cons] + simp only [CliffordCircuit.act, CliffordGate.act] + rw [hrec, Function.update_apply] + rcases eq_or_ne k w with rfl | hk + · simp [hw, List.mem_cons] + · simp [hk, List.mem_cons] + +/-! ### The Hadamard layer as the first layer of the encoding circuit -/ + +/-- The Hadamard tableau sends `I ↦ I` (`hadamardPauli 0 = 0`). -/ +theorem hadamardPauli_zero : hadamardPauli (0 : Fin 4) = 0 := by decide + +/-- The Hadamard tableau sends `Z ↦ X` (`hadamardPauli 3 = 1`). -/ +theorem hadamardPauli_three : hadamardPauli (3 : Fin 4) = 1 := by decide + +/-- **The first layer of the encoding circuit** (Nielsen & Chuang Problem 10.3): applying the +Hadamard layer on distinct wires `ws` to the pure-`Z` generator `Zᵢ` returns `Xᵢ` when `i ∈ ws` +and leaves `Zᵢ` unchanged otherwise. On the trivial check matrix `G` (10.124), whose rows are the +`Zᵢ`, Hadamarding the first `r` wires converts exactly the first `r` rows from `Z`-type to `X`-type. +The Hadamard swaps the wire's `X`/`Z` bits (`hadamardPauli 3 = 1`, i.e. `Z ↦ X`), and only wire `i` +of `Zᵢ` is non-identity, so only `i ∈ ws` matters. -/ +theorem act_hadLayer_zGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + CliffordCircuit.act (hadLayer ws) (zGenPauli i) + = if i ∈ ws then xGenPauli i else zGenPauli i := by + rw [act_hadLayer ws _ hnd] + by_cases hiws : i ∈ ws + · rw [ite_eq_left hiws] + funext k + rcases eq_or_ne k i with rfl | hk <;> + simp [hadamardPauli_three, hadamardPauli_zero, *] + · rw [ite_eq_right hiws] + funext k + rcases eq_or_ne k i with rfl | hk <;> + simp [hadamardPauli_zero, *] + +/-- **The first encoding layer in check-matrix terms.** After the Hadamard layer on `ws`, row `i` of +the check matrix is `(eᵢ | 0)` (pure `X`) when `i ∈ ws` and `(0 | eᵢ)` (pure `Z`) otherwise. With +`ws` the first `r` wires this is precisely the transition from the trivial matrix `G` (10.124), all +rows `(0 | eᵢ)`, to the intermediate matrix with an `X`-part identity block on the first `r` rows — +the starting point for the CNOT and phase layers that build the standard form (10.125). -/ +theorem checkRow_act_hadLayer_zGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + checkRow (CliffordCircuit.act (hadLayer ws) (zGenPauli i)) + = if i ∈ ws then (Pi.single i (1 : ZMod 2), 0) else (0, Pi.single i (1 : ZMod 2)) := by + rw [act_hadLayer_zGenPauli ws hnd] + by_cases h : i ∈ ws <;> simp [h, checkRow_xGenPauli, checkRow_zGenPauli] + +/-- **Operator-level first encoding layer**, through the backbone +`CliffordCircuit.conj_pauliString`. The Hadamard layer is a unitary Clifford circuit conjugating +the Pauli operator `P_{Zᵢ}` to a +nonzero (`±1`, `CliffordCircuit.sign_ne_zero`) scalar multiple of `P_{Xᵢ}` when `i ∈ ws`, else +`P_{Zᵢ}` — the physical content of the check-matrix layer `act_hadLayer_zGenPauli`. -/ +theorem hadLayer_conj_zGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + CliffordCircuit.toMatrix (hadLayer ws) * pauliString (zGenPauli i) + * (CliffordCircuit.toMatrix (hadLayer ws))ᴴ + = CliffordCircuit.sign (hadLayer ws) (zGenPauli i) + • pauliString (if i ∈ ws then xGenPauli i else zGenPauli i) := by + rw [CliffordCircuit.conj_pauliString, act_hadLayer_zGenPauli ws hnd] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringEncodingPhaseCZLayer.lean b/LeanPool/AxQM/Concrete/PauliStringEncodingPhaseCZLayer.lean new file mode 100644 index 0000000000..9ba8ecbc71 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringEncodingPhaseCZLayer.lean @@ -0,0 +1,293 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringEncodingCnotLayer + +/-! +# Concrete: the phase / controlled-`Z` gates of the stabilizer encoding circuit (N&C, Problem 10.3) + +This file continues the **synthesis** half +of Nielsen & Chuang **Problem 10.3** ("encoding stabilizer codes"): after the Hadamard layer +(`Concrete/PauliStringEncodingLayers.lean`) turns the top `r` rows of the trivial check matrix `G` +of Eq. (10.124) from `Z`-type to `X`-type, and the CNOT layer +(`Concrete/PauliStringEncodingCnotLayer.lean`) builds the `X`-blocks `A₁, A₂` (and, coupled, the +transposed `Z`-blocks `A₁ᵀ, A₂ᵀ`), the last synthesis step is a **network of phase (`S`) and +controlled-`Z` gates** that deposits the remaining `Z`-blocks of the standard form (10.125): the +`r × r` block `B` in the top rows and the `r × k` block `C₂`. This file delivers the two +`Z`-depositing gates that network is built from. + +The two column operations these gates induce on the check matrix (`0 = I, 1 = X, 2 = Y, 3 = Z`; +symplectic bits `pauliXBit`/`pauliZBit` of `Concrete/CheckMatrix.lean`) are the two ways to add a +`Z` without touching an `X`: + +* **Phase gate `S` on wire `j`** — the column operation `z_j += x_j`: it sends `X ↦ Y` (`Y = XZ` + adds a `Z`) and fixes `I, Z` (`phasePauli`, `Concrete/PauliStringCliffordConjugation.lean`). On a + row whose only `X` among the first `r` wires is on wire `j` (the `X`-identity block of (10.125)), + `S_j` deposits a single `Z` on wire `j` — the **diagonal of `B`**. +* **Controlled-`Z` between wires `c, t`** — the symmetric column operation `z_c += x_t`, + `z_t += x_c` (`X`-bits fixed). There is no elementary `CZ` gate in the elementary set + `{H, S, CNOT}`, so it is realized as the three-gate circuit `CZ_{c,t} = H_t · CNOT_{c→t} · H_t` + (`czGate`); its action is read off the existing Hadamard / CNOT tableaux. Between two top wires it + builds the **off-diagonal of `B`**; between a top wire and an encoded wire it builds the block + `C₂` (and, coupled through the top rows' `A₂`-block `X`-entries, the cross term of `B`). + +## The phase layer + +`sLayer ws` applies a phase gate to each wire in a list `ws` (`ws.map CliffordGate.phase`); the +gates commute and act on distinct wires, so it is a genuine *layer*. For distinct wires +(`ws.Nodup`): + +* `act_sLayer` — its row action, `act (sLayer ws) g k = phasePauli (g k)` for `k ∈ ws`, else `g k` + (only the chosen wires are transformed), mirroring `act_hadLayer`; +* `act_sLayer_xGenPauli` — the **diagonal-building layer**: on the pure-`X` generator `Xᵢ`, + `act (sLayer ws) Xᵢ = Yᵢ` when `i ∈ ws`, else `Xᵢ` — the phase gate deposits a `Z` on wire `i` + (`X ↦ Y`); +* `checkRow_act_sLayer_xGenPauli` — the same in check-matrix terms: row `i` becomes `(eᵢ | eᵢ)` + (`X`- and `Z`-bit on wire `i`) for `i ∈ ws`, else `(eᵢ | 0)`; +* `sLayer_conj_xGenPauli` — the operator-level reading through the backbone + `CliffordCircuit.conj_pauliString`: a unitary circuit conjugating `P_{Xᵢ}` to a nonzero (`±1`) + multiple of `P_{Yᵢ}` / `P_{Xᵢ}`. + +## The controlled-`Z` gate + +`czGate c t h = [H_t, CNOT_{c→t}, H_t]` (with `h : c ≠ t`). Its check-matrix action is the pair +tableau `czCtrlPauli` / `czTgtPauli`, packaged as the string transformation `czPauliString` +(`act_czGate`), and its symplectic content is the CZ column operation: + +* `pauliXBit_czCtrlPauli` / `pauliXBit_czTgtPauli` — the `X`-bits are unchanged; +* `pauliZBit_czCtrlPauli` (`z_c ↦ z_c + x_t`) / `pauliZBit_czTgtPauli` (`z_t ↦ z_t + x_c`) — each + wire's `Z`-bit gains the *other* wire's `X`-bit, the symmetric hallmark of `CZ`; +* `czGate_conj_pauliString` — the operator-level reading through the backbone: a unitary circuit + conjugating `P_g` to a nonzero (`±1`) multiple of `P_{czPauliString g c t}`. + +Everything is stated for raw index / matrix data (`Concrete.pauliString`, `CliffordCircuit`, +`Fin n → Fin 4`, `ZMod 2`). Assembling these layers with the Hadamard and CNOT layers gives the +circuit carrying `G` (10.124) to the standard form (10.125). + +## Design notes + +* `czGate` introduces **no new `CliffordGate` constructor**: `CZ = H·CNOT·H` is a three-gate + `CliffordCircuit`, so its `toMatrix`/`act`/`sign` are the existing folds and its conjugation is an + instance of the backbone `CliffordCircuit.conj_pauliString` — the same discipline as the CNOT and + Hadamard layers. `act_czGate` is proved by unfolding the three `Function.update`s of the + composition (`had_t` acts, then `cnot`, then `had_t`), and the symplectic bit laws are a finite + `Fin 4 × Fin 4` check (`decide`) against the composed Hadamard/CNOT tableaux. +* `act_sLayer` needs `ws.Nodup` for the same reason as `act_hadLayer`: although the clean statement + is "transform exactly the wires in `ws`", the encoding circuit phases each chosen wire once. The + `Nodup` is consumed only through the cons step `w ∉ ws`, so the outer `Function.update` reads the + untouched value `g w`. +* `yGenPauli i` (`Y` on wire `i`) names the image of `Xᵢ` under `S_i`; its check row `(eᵢ | eᵢ)` + (`checkRow_yGenPauli`) is the single diagonal entry of `B` that a phase gate deposits. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The `Y` generator (image of `Xᵢ` under a phase gate) -/ + +/-- The **pure-`Y` generator** `Yᵢ`: the Pauli string with `Y` on wire `i` and `I` on every other +wire (`Function.update 0 i 2`, using `0 = I`, `2 = Y`). It is the image of `Xᵢ` under a phase gate +on wire `i` (`act_sLayer_xGenPauli`); its check row is `(eᵢ | eᵢ)` (`checkRow_yGenPauli`), the +single diagonal `Z`-entry that a phase gate deposits on the `X`-identity block. -/ +def yGenPauli (i : Fin n) : Fin n → Fin 4 := Function.update 0 i 2 + +@[simp] theorem yGenPauli_apply (i k : Fin n) : yGenPauli i k = if k = i then 2 else 0 := by + simp only [yGenPauli, Function.update_apply, Pi.zero_apply] + +/-- The check row of the pure-`Y` generator is `(eᵢ | eᵢ)`: a single `1` in column `i` of both the +`X`-part and the `Z`-part (`Y` carries both an `X`- and a `Z`-bit). -/ +theorem checkRow_yGenPauli (i : Fin n) : + checkRow (yGenPauli i) = (Pi.single i (1 : ZMod 2), Pi.single i (1 : ZMod 2)) := by + ext k <;> rcases eq_or_ne k i with rfl | hk <;> + simp [checkRow, pauliBit, pauliXBit, pauliZBit, yGenPauli, *] + +/-! ### The phase (`S`) layer -/ + +/-- The **phase layer** on the wires `ws`: the Clifford circuit applying a phase gate `S` to each +wire in the list `ws` (`ws.map CliffordGate.phase`). With `ws` a set of top wires, this deposits the +diagonal `Z`-entries of the block `B` in the stabilizer encoding circuit of N&C Problem 10.3. -/ +def sLayer (ws : List (Fin n)) : CliffordCircuit n := ws.map CliffordGate.phase + +/-- The phase layer is built one wire at a time: `sLayer (w :: ws) = phase w :: sLayer ws` +(definitionally, `List.map` on a cons). -/ +theorem sLayer_cons (w : Fin n) (ws : List (Fin n)) : + sLayer (w :: ws) = CliffordGate.phase w :: sLayer ws := rfl + +/-- **Row action of the phase layer.** For a list of **distinct** wires `ws`, conjugating a Pauli +string by `sLayer ws` applies the single-wire phase tableau `phasePauli` to exactly the wires in +`ws`, leaving the others fixed: `act (sLayer ws) g k = phasePauli (g k)` if `k ∈ ws`, else `g k`. +Proved by induction on `ws`; the cons step uses `w ∉ ws` (from `Nodup`) so the outer +`Function.update` on wire `w` reads the still-untouched value `g w`. -/ +theorem act_sLayer (ws : List (Fin n)) (g : Fin n → Fin 4) (hnd : ws.Nodup) : + CliffordCircuit.act (sLayer ws) g = fun k => if k ∈ ws then phasePauli (g k) else g k := by + revert hnd + induction ws with + | nil => intro _; funext k; simp [sLayer, CliffordCircuit.act] + | cons w ws ih => + intro hnd + obtain ⟨hw, hnd'⟩ := List.nodup_cons.mp hnd + have hrec := ih hnd' + funext k + rw [sLayer_cons] + simp only [CliffordCircuit.act, CliffordGate.act] + rw [hrec, Function.update_apply] + rcases eq_or_ne k w with rfl | hk + · simp [hw, List.mem_cons] + · simp [hk, List.mem_cons] + +/-! ### The phase layer as the diagonal-building layer of the encoding circuit -/ + +/-- **The diagonal-building layer of the encoding circuit** (N&C Problem 10.3): applying the phase +layer on distinct wires `ws` to the pure-`X` generator `Xᵢ` returns `Yᵢ` when `i ∈ ws` and leaves +`Xᵢ` unchanged otherwise. The phase gate sends `X ↦ Y` (`phasePauli 1 = 2`, i.e. it adds a `Z` on +the wire) and fixes `I`; only wire `i` of `Xᵢ` is non-identity, so only `i ∈ ws` matters. Applied to +the `X`-identity block of (10.125) this deposits the diagonal entries of the `Z`-block `B`. -/ +theorem act_sLayer_xGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + CliffordCircuit.act (sLayer ws) (xGenPauli i) + = if i ∈ ws then yGenPauli i else xGenPauli i := by + rw [act_sLayer ws _ hnd] + by_cases hiws : i ∈ ws + · rw [ite_eq_left hiws] + funext k + rcases eq_or_ne k i with rfl | hk <;> simp [yGenPauli, xGenPauli_apply, phasePauli, *] + · rw [ite_eq_right hiws] + funext k + rcases eq_or_ne k i with rfl | hk <;> simp [xGenPauli_apply, phasePauli, *] + +/-- **The diagonal-building layer in check-matrix terms.** After the phase layer on `ws`, row `i` +(the pure-`X` generator `Xᵢ`) becomes `(eᵢ | eᵢ)` — an `X`- and a `Z`-bit on wire `i` — when +`i ∈ ws`, and stays `(eᵢ | 0)` otherwise. This is how the phase gates deposit the diagonal of the +`Z`-block `B` of the standard form (10.125) onto the top rows' `X`-identity block. -/ +theorem checkRow_act_sLayer_xGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + checkRow (CliffordCircuit.act (sLayer ws) (xGenPauli i)) + = if i ∈ ws then (Pi.single i (1 : ZMod 2), Pi.single i (1 : ZMod 2)) + else (Pi.single i (1 : ZMod 2), 0) := by + rw [act_sLayer_xGenPauli ws hnd] + by_cases h : i ∈ ws <;> simp [h, checkRow_yGenPauli, checkRow_xGenPauli] + +/-- **Operator-level diagonal-building layer**, through the backbone +`CliffordCircuit.conj_pauliString`. The phase layer is a unitary Clifford circuit conjugating the +Pauli operator `P_{Xᵢ}` to a nonzero (`±1`, `CliffordCircuit.sign_ne_zero`) scalar multiple of +`P_{Yᵢ}` when `i ∈ ws`, else `P_{Xᵢ}` — the physical content of the check-matrix layer +`act_sLayer_xGenPauli`. -/ +theorem sLayer_conj_xGenPauli (ws : List (Fin n)) (hnd : ws.Nodup) (i : Fin n) : + CliffordCircuit.toMatrix (sLayer ws) * pauliString (xGenPauli i) + * (CliffordCircuit.toMatrix (sLayer ws))ᴴ + = CliffordCircuit.sign (sLayer ws) (xGenPauli i) + • pauliString (if i ∈ ws then yGenPauli i else xGenPauli i) := by + rw [CliffordCircuit.conj_pauliString, act_sLayer_xGenPauli ws hnd] + +/-! ### The controlled-`Z` gate tableau -/ + +/-- The **new control Pauli** in `CZ_{c,t} (σ_a^c ⊗ σ_b^t) CZ_{c,t}†`, as a function of the control +index `a` and target index `b`. Since `CZ = H_t · CNOT_{c→t} · H_t`, it is the CNOT control Pauli +against the Hadamard-conjugated target: `czCtrlPauli a b = cnotCtrlPauli a (hadamardPauli b)`. Its +`X`-bit is unchanged and its `Z`-bit gains the target's `X`-bit (`pauliZBit_czCtrlPauli`). -/ +def czCtrlPauli (a b : Fin 4) : Fin 4 := cnotCtrlPauli a (hadamardPauli b) + +/-- The **new target Pauli** in `CZ_{c,t} (σ_a^c ⊗ σ_b^t) CZ_{c,t}†`. Conjugating the middle CNOT +target between two Hadamards on the target wire: +`czTgtPauli a b = hadamardPauli (cnotTgtPauli a (hadamardPauli b))`. Its `X`-bit is unchanged and +its `Z`-bit gains the control's `X`-bit (`pauliZBit_czTgtPauli`) — symmetric with the control, as +`CZ` is symmetric in its two wires. -/ +def czTgtPauli (a b : Fin 4) : Fin 4 := hadamardPauli (cnotTgtPauli a (hadamardPauli b)) + +/-- The controlled-`Z` fixes the control's `X`-bit: `pauliXBit (czCtrlPauli a b) = pauliXBit a`. -/ +theorem pauliXBit_czCtrlPauli (a b : Fin 4) : pauliXBit (czCtrlPauli a b) = pauliXBit a := by + revert a b; decide + +/-- The controlled-`Z` column operation on the control's `Z`-bit: `z_c ↦ z_c + x_t`, i.e. +`pauliZBit (czCtrlPauli a b) = (pauliZBit a + pauliXBit b) % 2` — the control gains the target's +`X`-bit. -/ +theorem pauliZBit_czCtrlPauli (a b : Fin 4) : + pauliZBit (czCtrlPauli a b) = (pauliZBit a + pauliXBit b) % 2 := by + revert a b; decide + +/-- The controlled-`Z` fixes the target's `X`-bit: `pauliXBit (czTgtPauli a b) = pauliXBit b`. -/ +theorem pauliXBit_czTgtPauli (a b : Fin 4) : pauliXBit (czTgtPauli a b) = pauliXBit b := by + revert a b; decide + +/-- The controlled-`Z` column operation on the target's `Z`-bit: `z_t ↦ z_t + x_c`, i.e. +`pauliZBit (czTgtPauli a b) = (pauliZBit b + pauliXBit a) % 2` — the target gains the control's +`X`-bit (symmetric with `pauliZBit_czCtrlPauli`). -/ +theorem pauliZBit_czTgtPauli (a b : Fin 4) : + pauliZBit (czTgtPauli a b) = (pauliZBit b + pauliXBit a) % 2 := by + revert a b; decide + +/-! ### The controlled-`Z` gate -/ + +/-- The **controlled-`Z` gate** between control wire `c` and target wire `t` (`h : c ≠ t`), +realized in the elementary gate set `{H, S, CNOT}` as `CZ_{c,t} = H_t · CNOT_{c→t} · H_t` — the +three-gate Clifford circuit `[had t, cnot c t, had t]` (the head `had t` is applied last). Its +check-matrix action is the symmetric column operation `z_c += x_t`, `z_t += x_c` (`act_czGate`, +the bit laws `pauliZBit_cz…`). -/ +def czGate (c t : Fin n) (h : c ≠ t) : CliffordCircuit n := + [CliffordGate.had t, CliffordGate.cnot c t h, CliffordGate.had t] + +/-- The **controlled-`Z`-transformed Pauli string**: `CZ_{c,t}` conjugation changes only wire `c` +(to `czCtrlPauli (g c) (g t)`) and wire `t` (to `czTgtPauli (g c) (g t)`), leaving every other wire +fixed. Both new Paulis depend on the *original* pair `(g c, g t)`. -/ +def czPauliString (g : Fin n → Fin 4) (c t : Fin n) : Fin n → Fin 4 := + Function.update (Function.update g t (czTgtPauli (g c) (g t))) c (czCtrlPauli (g c) (g t)) + +/-- The `CZ`-transformed string on the control wire: +`czPauliString g c t c = czCtrlPauli (g c) (g t)`. -/ +@[simp] theorem czPauliString_ctrl (g : Fin n → Fin 4) (c t : Fin n) : + czPauliString g c t c = czCtrlPauli (g c) (g t) := + Function.update_self .. + +/-- The `CZ`-transformed string on the target wire: `czPauliString g c t t = czTgtPauli (g c) (g t)` +(needs `c ≠ t`). -/ +theorem czPauliString_tgt (g : Fin n → Fin 4) {c t : Fin n} (h : c ≠ t) : + czPauliString g c t t = czTgtPauli (g c) (g t) := by + simp only [czPauliString, Function.update_of_ne h.symm, Function.update_self] + +/-- The `CZ`-transformed string off wires `c` and `t` is unchanged: `czPauliString g c t k = g k` +for `k ≠ c`, `k ≠ t`. -/ +theorem czPauliString_of_ne (g : Fin n → Fin 4) (c t : Fin n) {k : Fin n} (hkc : k ≠ c) + (hkt : k ≠ t) : czPauliString g c t k = g k := by + simp only [czPauliString, Function.update_of_ne hkc, Function.update_of_ne hkt] + +/-- **Row action of the controlled-`Z` gate.** Conjugating a Pauli string by `czGate c t h` applies +the pair tableau `czCtrlPauli` / `czTgtPauli` to wires `c, t` and fixes the rest: +`act (czGate c t h) g = czPauliString g c t`. Proved by unfolding the three `Function.update`s of +the composition `H_t · CNOT_{c→t} · H_t` (the inner Hadamard acts first, then the CNOT column +operation, then the outer Hadamard) and reading the resulting wire values. -/ +theorem act_czGate (c t : Fin n) (h : c ≠ t) (g : Fin n → Fin 4) : + CliffordCircuit.act (czGate c t h) g = czPauliString g c t := by + funext k + simp only [czGate, CliffordCircuit.act, CliffordGate.act, czPauliString, czTgtPauli, czCtrlPauli] + rcases eq_or_ne k c with rfl | hkc + · rw [Function.update_self, Function.update_of_ne h, cnotPauliString_ctrl, + Function.update_of_ne h, Function.update_self] + · rw [Function.update_of_ne hkc] + rcases eq_or_ne k t with rfl | hkt + · rw [Function.update_self, Function.update_self, cnotPauliString_tgt _ h, + Function.update_self, Function.update_of_ne h] + · rw [Function.update_of_ne hkt, Function.update_of_ne hkt, + cnotPauliString_of_ne _ _ _ hkc hkt, Function.update_of_ne hkt] + +/-- **Operator-level controlled-`Z` conjugation**, through the backbone +`CliffordCircuit.conj_pauliString`. The `CZ` gate is a unitary Clifford circuit conjugating the +Pauli operator `P_g` to a nonzero (`±1`, `CliffordCircuit.sign_ne_zero`) scalar multiple of +`P_{czPauliString g c t}` — the physical content of the check-matrix column operation `act_czGate` +(the symmetric `z_c += x_t`, `z_t += x_c`). -/ +theorem czGate_conj_pauliString (c t : Fin n) (h : c ≠ t) (g : Fin n → Fin 4) : + CliffordCircuit.toMatrix (czGate c t h) * pauliString g + * (CliffordCircuit.toMatrix (czGate c t h))ᴴ + = CliffordCircuit.sign (czGate c t h) g • pauliString (czPauliString g c t) := by + rw [CliffordCircuit.conj_pauliString, act_czGate] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringLocality.lean b/LeanPool/AxQM/Concrete/PauliStringLocality.lean new file mode 100644 index 0000000000..053301d045 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringLocality.lean @@ -0,0 +1,335 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliString +public import Mathlib.Data.Finset.Powerset +public import Mathlib.Data.Fintype.Powerset +public import Mathlib.Data.Fintype.BigOperators +public import Mathlib.Data.Nat.Choose.Bounds +public import Mathlib.Algebra.Polynomial.Eval.Defs + +/-! +# Concrete: locality of Pauli strings and the polynomial count of local terms + +It supplies the combinatorial +core behind **Nielsen & Chuang, Exercise 4.48**: *the restriction of each term `Hₖ` in a +Hamiltonian `H = Σₖ Hₖ` (eq. 4.97) to involve at most a constant `c` particles implies that the +number of terms `L` is upper bounded by a polynomial in the particle count `n`.* + +N&C's own examples of local terms are Pauli strings — "two-body interactions such as `XᵢXⱼ` and +one-body Hamiltonians such as `Xᵢ`" (§4.7.2). In this library a Pauli string on `n` qubits is the +index `g : Fin n → Fin 4` (a choice of `{I, X, Y, Z}` per qubit, `Concrete.pauliString`). The set +of qubits it acts on non-trivially — its **support** — is `{i | g i ≠ 0}`, and "the term acts on +at most `c` particles" is exactly `(support g).card ≤ c`. + +The heart of N&C's argument is a *counting* fact: there are only polynomially many ways to choose +which `≤ c` of the `n` particles a term acts on. This file makes that precise and proves the +polynomial bound; the statement that these `g` index genuine Hamiltonian terms +`pauliStringHamiltonian g (h g)` (`Observable`s on the register `qudit (2ⁿ)`) is in +[upstream `AxQM/NC/Ch4/Exercise4_48.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_48.lean). + +Everything here is stated for raw index/combinatorial data (`Fin n → Fin 4`, `Finset`, +`Concrete.pauliString`). + +## Main definitions + +* `Concrete.pauliStringSupport g` — the support `{i | g i ≠ 0}` of the Pauli string `g`, the set + of qubits it acts on non-trivially. +* `Concrete.localPauliStrings c n` — the Pauli strings on `n` qubits acting on at most `c` + particles (support of size `≤ c`): the "menu" of `c`-local Hamiltonian terms. + +## Main results + +* `Concrete.pauliString_apply_eq_zero_of_notMem_support` — a Pauli string acts as the identity off + its support: its `(i, j)` entry vanishes whenever some non-support qubit `k` has `i k ≠ j k`. + This justifies the name "support". +* `Concrete.card_finset_card_le_le` — **the counting core**: the number of subsets of an + `n`-element set of size `≤ c` is at most `(n + 1) ^ c`. This is N&C's "polynomially many ways to + pick `≤ c` particles". +* `Concrete.card_localPauliStrings_le` — the number of `c`-local Pauli strings on `n` qubits is at + most `4 ^ c * (n + 1) ^ c`, a polynomial in `n` of degree `c`. +* `Concrete.exists_polynomial_card_localPauliStrings_le` — the same as a literal + `Polynomial ℕ` bound: a single polynomial `p` (independent of `n`) with + `(localPauliStrings c n).card ≤ p.eval n` for all `n`. +* `Concrete.card_filter_pauliStringSupport_eq` / `Concrete.card_filter_pauliStringSupport_card_eq` / + `Concrete.card_localPauliStrings_eq` — the **exact** counts sharpening the `≤` bounds: the fibre + of fixed support `S` has `3 ^ |S|` strings, there are `C(n, j) · 3ʲ` strings of weight exactly + `j`, and `(localPauliStrings t n).card = ∑_{j=0}^{t} C(n, j) · 3ʲ` (N&C eq. (10.50), the + left-hand multiplicand of the quantum Hamming bound (10.51), Exercise 10.50). +-/ + +@[expose] public section + +open Matrix +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The support of a Pauli string -/ + +/-- The **support** of the Pauli string `g : Fin n → Fin 4`: the set of qubits `{i | g i ≠ 0}` on +which it acts non-trivially (`g i ≠ 0` means the `i`-th factor is one of `X, Y, Z`, not `I`). The +number of particles the corresponding local term acts on is `(pauliStringSupport g).card`. -/ +def pauliStringSupport (g : Fin n → Fin 4) : Finset (Fin n) := + Finset.univ.filter (fun i => g i ≠ 0) + +@[simp] theorem mem_pauliStringSupport {g : Fin n → Fin 4} {i : Fin n} : + i ∈ pauliStringSupport g ↔ g i ≠ 0 := by + simp [pauliStringSupport] + +/-- The dual of `mem_pauliStringSupport`: a qubit `i` is **outside** the support of the Pauli +string `g` exactly when its factor is the identity, `g i = 0`. (Not a `simp` lemma: it is already +provable by `simp` via the `@[simp] mem_pauliStringSupport` above, so tagging it `@[simp]` would be +flagged as redundant; it is kept as a citable form for the local-term proofs.) -/ +theorem notMem_pauliStringSupport {g : Fin n → Fin 4} {i : Fin n} : + i ∉ pauliStringSupport g ↔ g i = 0 := by + simp [pauliStringSupport] + +/-- A Pauli string acts as the **identity off its support**: if `k` is not in the support +(`g k = 0`, so the `k`-th factor is `I`) and `i k ≠ j k`, then the `(i, j)` entry of `pauliString g` +is `0`. Hence `pauliString g` is diagonal in every non-support qubit, i.e. acts only on the +`(pauliStringSupport g)` qubits — justifying the name "support". -/ +theorem pauliString_apply_eq_zero_of_notMem_support (g : Fin n → Fin 4) {i j : Fin n → Fin 2} + {k : Fin n} (hk : k ∉ pauliStringSupport g) (hij : i k ≠ j k) : + pauliString g i j = 0 := by + rw [pauliString_apply] + refine Finset.prod_eq_zero (Finset.mem_univ k) ?_ + simp [notMem_pauliStringSupport.mp hk, pauli, hij] + +/-! ### The counting core: polynomially many subsets of bounded size -/ + +/-- **The counting core of Exercise 4.48.** The number of subsets of an `n`-element set of +cardinality at most `c` is bounded by the polynomial `(n + 1) ^ c`. This is the precise form of +N&C's "there are only polynomially many ways to choose which `≤ c` of the `n` particles a term acts +on": grouping the terms `Hₖ` by the set of particles they couple, `L` is at most this count. + +Proof: fibring over the cardinality `k ≤ c`, the count is `Σ_{k=0}^{c} C(n, k)`; bounding each +binomial `C(n, k) ≤ nᵏ` (`Nat.choose_le_pow`) and then `nᵏ ≤ nᵏ · C(c, k)` (as `C(c, k) ≥ 1` for +`k ≤ c`), the sum is `Σ_{k=0}^{c} nᵏ C(c, k) = (n + 1)ᶜ` by the binomial theorem. -/ +theorem card_finset_card_le_le (n c : ℕ) : + (Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c)).card ≤ (n + 1) ^ c := by + classical + have hmaps : ∀ S ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c), + S.card ∈ Finset.range (c + 1) := by + intro S hS + rw [Finset.mem_range, Nat.lt_succ_iff] + exact (Finset.mem_filter.mp hS).2 + have key : (n + 1) ^ c = ∑ k ∈ Finset.range (c + 1), n ^ k * c.choose k := by + rw [add_pow] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [one_pow, mul_one, Nat.cast_id] + rw [Finset.card_eq_sum_card_fiberwise hmaps] + calc ∑ k ∈ Finset.range (c + 1), + ((Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c)).filter + (fun S => S.card = k)).card + ≤ ∑ k ∈ Finset.range (c + 1), n.choose k := by + refine Finset.sum_le_sum fun k _ => ?_ + have hsub : + (Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c)).filter + (fun S => S.card = k) + ⊆ Finset.univ.filter (fun S : Finset (Fin n) => S.card = k) := by + intro S hS + rw [Finset.mem_filter] at hS ⊢ + exact ⟨Finset.mem_univ S, hS.2⟩ + have heq : (Finset.univ.filter (fun S : Finset (Fin n) => S.card = k)).card + = n.choose k := by + rw [Finset.univ_filter_card_eq, Finset.card_powersetCard, Finset.card_univ, + Fintype.card_fin] + exact le_trans (Finset.card_le_card hsub) (le_of_eq heq) + _ ≤ ∑ k ∈ Finset.range (c + 1), n ^ k := Finset.sum_le_sum fun k _ => Nat.choose_le_pow n k + _ ≤ ∑ k ∈ Finset.range (c + 1), n ^ k * c.choose k := by + refine Finset.sum_le_sum fun k hk => ?_ + rw [Finset.mem_range, Nat.lt_succ_iff] at hk + exact Nat.le_mul_of_pos_right _ (Nat.choose_pos hk) + _ = (n + 1) ^ c := key.symm + +/-! ### The `c`-local Pauli strings and their polynomial count -/ + +/-- The **`c`-local Pauli strings** on `n` qubits: those acting on at most `c` particles +(`(pauliStringSupport g).card ≤ c`). This is the menu of possible `c`-local Hamiltonian terms in +the Pauli picture — each `g` names a term `h_g · g` of a Hamiltonian `H = Σ_g h_g g`. -/ +def localPauliStrings (c n : ℕ) : Finset (Fin n → Fin 4) := + Finset.univ.filter (fun g => (pauliStringSupport g).card ≤ c) + +@[simp] theorem mem_localPauliStrings {c : ℕ} {g : Fin n → Fin 4} : + g ∈ localPauliStrings c n ↔ (pauliStringSupport g).card ≤ c := by + simp [localPauliStrings] + +/-- **The number of Pauli strings on `n` qubits with a fixed support `S` is at most `4 ^ |S|`.** A +Pauli string with support exactly `S` is determined by its values on `S` (it is `0` off `S`), and +those values lie in `Fin 4`; restriction to `S` is therefore injective on the fibre, bounding its +cardinality by `Fintype.card (S → Fin 4) = 4 ^ |S|`. -/ +theorem card_filter_pauliStringSupport_eq_le (S : Finset (Fin n)) : + (Finset.univ.filter (fun g : Fin n → Fin 4 => pauliStringSupport g = S)).card ≤ 4 ^ S.card := by + classical + calc (Finset.univ.filter (fun g : Fin n → Fin 4 => pauliStringSupport g = S)).card + ≤ (Finset.univ : Finset (S → Fin 4)).card := by + refine Finset.card_le_card_of_injOn (fun g => fun i : S => g i.1) + (fun g _ => Finset.mem_univ _) ?_ + intro g₁ hg₁ g₂ hg₂ heq + simp only [Finset.coe_filter, Finset.mem_univ, true_and, Set.mem_ofPred_eq] at hg₁ hg₂ + funext i + by_cases hi : i ∈ S + · exact congrFun heq ⟨i, hi⟩ + · have h1 : g₁ i = 0 := notMem_pauliStringSupport.mp (by rw [hg₁]; exact hi) + have h2 : g₂ i = 0 := notMem_pauliStringSupport.mp (by rw [hg₂]; exact hi) + rw [h1, h2] + _ = 4 ^ S.card := by + rw [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_coe] + +/-- **Exercise 4.48, combinatorial form.** The number of `c`-local Pauli strings on `n` qubits is +at most `4 ^ c * (n + 1) ^ c`, a polynomial in the particle count `n` (of degree `c`). Any +Hamiltonian `H = Σ_g h_g g` whose terms are each `c`-local therefore has at most polynomially many +terms `L`. + +Proof: fibring over the support `S = pauliStringSupport g` (which ranges over the subsets of size +`≤ c`), each fibre has at most `4 ^ |S| ≤ 4 ^ c` members +(`card_filter_pauliStringSupport_eq_le`), and there are at most `(n + 1) ^ c` supports +(`card_finset_card_le_le`), giving `4 ^ c * (n + 1) ^ c`. -/ +theorem card_localPauliStrings_le (c n : ℕ) : + (localPauliStrings c n).card ≤ 4 ^ c * (n + 1) ^ c := by + classical + have hmaps : ∀ g ∈ localPauliStrings c n, + pauliStringSupport g ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c) := by + intro g hg + rw [Finset.mem_filter] + exact ⟨Finset.mem_univ _, (mem_localPauliStrings).mp hg⟩ + rw [Finset.card_eq_sum_card_fiberwise hmaps] + calc ∑ S ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c), + ((localPauliStrings c n).filter (fun g => pauliStringSupport g = S)).card + ≤ ∑ _S ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c), 4 ^ c := by + refine Finset.sum_le_sum fun S hS => ?_ + have hSc : S.card ≤ c := (Finset.mem_filter.mp hS).2 + refine le_trans (Finset.card_le_card ?_) + (le_trans (card_filter_pauliStringSupport_eq_le S) + (Nat.pow_le_pow_right (by norm_num) hSc)) + intro g hg + rw [Finset.mem_filter] at hg ⊢ + exact ⟨Finset.mem_univ g, hg.2⟩ + _ = (Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ c)).card * 4 ^ c := by + rw [Finset.sum_const, smul_eq_mul] + _ ≤ (n + 1) ^ c * 4 ^ c := Nat.mul_le_mul (card_finset_card_le_le n c) le_rfl + _ = 4 ^ c * (n + 1) ^ c := by ring + +/-- **Exercise 4.48, "`L` is bounded by a polynomial in `n`".** For a fixed locality bound `c` +there is a single polynomial `p : Polynomial ℕ` (namely `4ᶜ · (X + 1)ᶜ`, of degree `c` and +independent of `n`) such that the number of `c`-local Pauli strings on `n` qubits is at most +`p.eval n` for every `n`. This is the literal reading of "`L` is upper bounded by a polynomial in +`n`". -/ +theorem exists_polynomial_card_localPauliStrings_le (c : ℕ) : + ∃ p : Polynomial ℕ, ∀ n, (localPauliStrings c n).card ≤ p.eval n := by + refine ⟨Polynomial.C (4 ^ c) * (Polynomial.X + 1) ^ c, fun n => ?_⟩ + simpa using card_localPauliStrings_le c n + +/-! ### Exact counts of Pauli strings by weight (the quantum Hamming bound, N&C §10.3.4) + +The `≤` bounds above suffice for the polynomial-locality statement of Exercise 4.48, but the +**quantum Hamming bound** (N&C eqs. (10.50)–(10.51), Exercise 10.50) needs the *exact* count of +Pauli strings of a given weight. A string with support exactly `S` carries one of the three +non-identity Paulis `X, Y, Z` on each of the `|S|` sites of `S` (and `I` off `S`), so its fibre has +cardinality exactly `3 ^ |S|`. Summing over the `C(n, j)` supports of each size `j ≤ t` gives the +number of Pauli strings of weight `≤ t` on `n` qubits as `∑_{j=0}^{t} C(n, j) · 3ʲ` (N&C +eq. (10.50)) — sharpening `card_localPauliStrings_le` from a `≤` bound to an equality. -/ + +/-- **The number of Pauli strings on `n` qubits with a fixed support `S` is exactly `3 ^ |S|`.** A +string with support exactly `S` is `0` off `S` and one of the three non-identity Paulis `X, Y, Z` +(the nonzero elements of `Fin 4`) on each of the `|S|` sites of `S`; the choices are independent, +so the fibre is `Fintype.piFinset (fun i => if i ∈ S then {1,2,3} else {0})`, of cardinality +`∏ᵢ (if i ∈ S then 3 else 1) = 3 ^ |S|`. This is the exact form of +`card_filter_pauliStringSupport_eq_le` (which only bounds the fibre by `4 ^ |S|`). -/ +theorem card_filter_pauliStringSupport_eq (S : Finset (Fin n)) : + (Finset.univ.filter (fun g : Fin n → Fin 4 => pauliStringSupport g = S)).card = 3 ^ S.card := by + classical + have hmem : ∀ x : Fin 4, x ∈ ({1, 2, 3} : Finset (Fin 4)) ↔ x ≠ 0 := by decide + have hset : (Finset.univ.filter (fun g : Fin n → Fin 4 => pauliStringSupport g = S)) + = Fintype.piFinset (fun i => if i ∈ S then ({1, 2, 3} : Finset (Fin 4)) else {0}) := by + ext g + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset] + constructor + · intro hg i + by_cases hi : i ∈ S + · simp only [hi, ite_true]; rw [hmem, ← mem_pauliStringSupport, hg]; exact hi + · simp only [hi, ite_false, Finset.mem_singleton] + rw [← notMem_pauliStringSupport, hg]; exact hi + · intro hg + ext i + rw [mem_pauliStringSupport] + by_cases hi : i ∈ S + · have hgi := hg i; simp only [hi, ite_true, hmem] at hgi; exact iff_of_true hgi hi + · have hgi := hg i; simp only [hi, ite_false, Finset.mem_singleton] at hgi + exact iff_of_false (by rw [hgi]; simp) hi + rw [hset, Fintype.card_piFinset] + have hcard : ∀ i : Fin n, + (if i ∈ S then ({1, 2, 3} : Finset (Fin 4)) else {0}).card = if i ∈ S then 3 else 1 := by + intro i; by_cases hi : i ∈ S <;> simp [hi] + simp_rw [hcard] + rw [Finset.prod_ite_mem Finset.univ S (fun _ => 3), Finset.univ_inter, Finset.prod_const] + +/-- **The number of Pauli strings on `n` qubits of weight exactly `j` is `C(n, j) · 3ʲ`.** Fibring +over the support `S` (which ranges over the `C(n, j)` subsets of `Fin n` of size `j`), each fibre +has exactly `3 ^ j` members by `card_filter_pauliStringSupport_eq`. This is the `j`-th summand of +N&C's error count (10.50). -/ +theorem card_filter_pauliStringSupport_card_eq (j : ℕ) : + (Finset.univ.filter (fun g : Fin n → Fin 4 => (pauliStringSupport g).card = j)).card + = n.choose j * 3 ^ j := by + classical + have hmaps : ∀ g ∈ Finset.univ.filter (fun g : Fin n → Fin 4 => (pauliStringSupport g).card = j), + pauliStringSupport g ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card = j) := by + intro g hg + rw [Finset.mem_filter] at hg ⊢ + exact ⟨Finset.mem_univ _, hg.2⟩ + rw [Finset.card_eq_sum_card_fiberwise hmaps] + have hval : ∀ S ∈ Finset.univ.filter (fun S : Finset (Fin n) => S.card = j), + ((Finset.univ.filter (fun g : Fin n → Fin 4 => (pauliStringSupport g).card = j)).filter + (fun g => pauliStringSupport g = S)).card = 3 ^ j := by + intro S hS + have hSj : S.card = j := (Finset.mem_filter.mp hS).2 + have hrw : (Finset.univ.filter (fun g : Fin n → Fin 4 => + (pauliStringSupport g).card = j)).filter (fun g => pauliStringSupport g = S) + = Finset.univ.filter (fun g : Fin n → Fin 4 => pauliStringSupport g = S) := by + ext g + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · rintro ⟨_, h⟩; exact h + · intro h; exact ⟨by rw [h, hSj], h⟩ + rw [hrw, card_filter_pauliStringSupport_eq, hSj] + rw [Finset.sum_congr rfl hval, Finset.sum_const, smul_eq_mul] + congr 1 + rw [Finset.univ_filter_card_eq, Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] + +/-- **Nielsen & Chuang eq. (10.50): the number of Pauli strings on `n` qubits of weight `≤ t` is +`∑_{j=0}^{t} C(n, j) · 3ʲ`.** These are exactly the errors correctable by a `t`-error-correcting +code (the identity on all but `≤ t` qubits, each of those carrying one of `X, Y, Z`); the count is +the left-hand multiplicand of the quantum Hamming bound (10.51). Fibring `localPauliStrings t n` +over the weight `j ∈ {0, …, t}` and applying `card_filter_pauliStringSupport_card_eq` on each fibre +gives the sum. This is the exact form of `card_localPauliStrings_le`. -/ +theorem card_localPauliStrings_eq (t n : ℕ) : + (localPauliStrings t n).card = ∑ j ∈ Finset.range (t + 1), n.choose j * 3 ^ j := by + classical + have hmaps : ∀ g ∈ localPauliStrings t n, + (pauliStringSupport g).card ∈ Finset.range (t + 1) := by + intro g hg + rw [Finset.mem_range, Nat.lt_succ_iff] + exact (mem_localPauliStrings).mp hg + rw [Finset.card_eq_sum_card_fiberwise hmaps] + refine Finset.sum_congr rfl fun j hj => ?_ + rw [Finset.mem_range, Nat.lt_succ_iff] at hj + have hrw : (localPauliStrings t n).filter (fun g => (pauliStringSupport g).card = j) + = Finset.univ.filter (fun g : Fin n → Fin 4 => (pauliStringSupport g).card = j) := by + ext g + simp only [Finset.mem_filter, mem_localPauliStrings, Finset.mem_univ, true_and] + constructor + · rintro ⟨_, h⟩; exact h + · intro h; refine ⟨?_, h⟩; rw [h]; exact hj + rw [hrw, card_filter_pauliStringSupport_card_eq] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringParityCascade.lean b/LeanPool/AxQM/Concrete/PauliStringParityCascade.lean new file mode 100644 index 0000000000..353670242f --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringParityCascade.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliNormalizerZClear +public import LeanPool.AxQM.Concrete.PauliStringDiagonalize + +/-! +# Concrete: the Figure-4.19 parity circuit — collapse `exp(s · Z^{⊗S})` to a single `Z`-rotation + +This file is the **second step** of Nielsen & Chuang **Problem 4.3(3)** — "implement +`exp(-i h_g g Δ)` using `O(n)` one- and two-qubit gates" — the *parity computation* that follows +the single-qubit basis change of `Concrete/PauliStringDiagonalize.lean`. + +## The construction (N&C §4.7.3, Figure 4.19) + +After the local basis change diagonalises a Pauli string to an operator that is `Z` on its support +`S` and `I` elsewhere (`d(g) = pauliToZ ∘ g`), the remaining task is to implement +`exp(s · Z^{⊗S})` — a diagonal unitary applying a phase that depends on the **parity** +`⊕_{i∈S} xᵢ` of the support bits. Nielsen & Chuang's Figure 4.19 computes this parity into a single +*collector* wire `c ∈ S` with a fan of `CNOT`s, applies one single-qubit `Z`-rotation +`exp(s · Z_c)` on the collector, then uncomputes the fan: +`exp(s · Z^{⊗S}) = V† · exp(s · Z_c) · V`, where `V` is the `CNOT` fan and `V†` its uncomputation. +Only `2·(|S|−1)` `CNOT`s and one rotation are used — `O(n)` elementary gates. + +## Reuse: the Gottesman `CNOT`-fan already in the library + +The `CNOT` fan `V = cnotFanInto c ts` (controls `ts`, target `c`), built for the Clifford-normalizer +synthesis of Theorem 10.6, already carries the Pauli-conjugation facts we need +(`Concrete/PauliNormalizerZClear.lean`): `act_cnotFanInto_collapse` proves the fan conjugates the +all-`Z` string on `insert c ts` back to the single generator `zGenPauli c` (`Z` on the collector, +`I` on every control), and `sign_cnotFanInto_collapse` proves this acquires no `±1` phase. The +`z_c += z_t` propagation of `CNOT_{t→c}` (Figure 10.7) *is* the parity accumulation of Figure 4.19. +So this file needs only to push those facts through the exponential; the `O(n)` gate count is +`length_cnotFanInto_le`. + +## What is proved + +For a collector `c ∉ ts` with a duplicate-free control list `ts`, and any Pauli string `a` that is +`Z` (letter `3`) exactly on `insert c ts` and `I` elsewhere: + +* `cnotFanInto_act_eq_zGenPauli` — the fan's symplectic action collapses `a` to `zGenPauli c`. +* `cnotFanInto_toMatrix_conj_pauliString_eq_zGenPauli` — the operator collapse + `V · P_a · V† = P_{Z_c}` (no sign). +* `pauliString_exp_smul_conj_cnotFanInto` — the exponentiated **Figure-4.19 identity** + `exp(s · P_a) = V† · exp(s · P_{Z_c}) · V` for any scalar `s` (physically `s = -i h_g Δ`): the + exponential of the diagonalised (all-`Z`-on-support) Hamiltonian is the collector `Z`-rotation + conjugated by the `CNOT` parity fan. Reading right-to-left, this is exactly "compute the parity + (`V`), rotate the collector (`exp(s · Z_c)`), uncompute (`V†`)". + +The string `a` is the output `pauliToZ ∘ g` of `Concrete/PauliStringDiagonalize.lean` (`Z` on the +support of `g`), so chaining the two files reduces `exp(s · g)` for an arbitrary Pauli string `g` to +a single single-qubit `Z`-rotation conjugated by an `O(n)`-gate circuit. Every statement is about +raw matrix / index data (`Concrete.CliffordCircuit`, `Concrete.pauliString`, `Concrete.zGenPauli`, +`NormedSpace.exp`). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **Figure-4.19 parity collapse (symplectic form).** For a collector `c ∉ ts` (`ts.Nodup`) and a +Pauli string `a` that is `Z` (`3`) on `c` and on every wire of `ts` and `I` (`0`) on every other +wire, the reverse `CNOT` fan `cnotFanInto c ts` conjugates `a` to the single `Z` generator +`zGenPauli c`. Packages the pointwise `act_cnotFanInto_collapse` (which clears the `Z` off each +control and keeps it on the collector) into the equality of Pauli strings, using the support +hypothesis `hrest` to kill the `else a k` branch off the support. -/ +theorem cnotFanInto_act_eq_zGenPauli (c : Fin n) (ts : List (Fin n)) (hc : c ∉ ts) + (hnd : ts.Nodup) (a : Fin n → Fin 4) (hac : a c = 3) (hts : ∀ t ∈ ts, a t = 3) + (hrest : ∀ k, k ≠ c → k ∉ ts → a k = 0) : + (cnotFanInto c ts).act a = zGenPauli c := by + funext k + rw [act_cnotFanInto_collapse c ts hc hnd a hac hts k] + simp only [zGenPauli, Function.update_apply, Pi.zero_apply] + by_cases hkc : k = c + · simp [hkc] + · rw [ite_eq_right hkc, ite_eq_right hkc] + by_cases hkt : k ∈ ts + · rw [ite_eq_left hkt] + · rw [ite_eq_right hkt]; exact hrest k hkc hkt + +/-- **Figure-4.19 parity collapse (operator form).** Under the same hypotheses, the `CNOT` fan +conjugates the operator `P_a` (`Z` on `insert c ts`) to the collector generator `P_{Z_c}` with no +sign: `V · P_a · V† = P_{Z_c}`. Immediate from `CliffordCircuit.conj_pauliString` together with the +trivial sign (`sign_cnotFanInto_collapse`) and the symplectic collapse +(`cnotFanInto_act_eq_zGenPauli`). -/ +theorem cnotFanInto_toMatrix_conj_pauliString_eq_zGenPauli (c : Fin n) (ts : List (Fin n)) + (hc : c ∉ ts) (hnd : ts.Nodup) (a : Fin n → Fin 4) (hac : a c = 3) (hts : ∀ t ∈ ts, a t = 3) + (hrest : ∀ k, k ≠ c → k ∉ ts → a k = 0) : + (cnotFanInto c ts).toMatrix * pauliString a * (cnotFanInto c ts).toMatrixᴴ + = pauliString (zGenPauli c) := by + rw [CliffordCircuit.conj_pauliString, sign_cnotFanInto_collapse c ts hc hnd a hac hts, + cnotFanInto_act_eq_zGenPauli c ts hc hnd a hac hts hrest, one_smul] + +/-- **Problem 4.3(3), exponentiated form: the Figure-4.19 parity circuit for `exp(s · Z^{⊗S})`.** +For any complex scalar `s` (physically `s = -i h_g Δ`), the exponential of the diagonalised +(all-`Z`-on-support) Hamiltonian `a` is the single collector `Z`-rotation conjugated by the `CNOT` +parity fan: +`exp(s · P_a) = V† · exp(s · P_{Z_c}) · V`, `V = cnotFanInto c ts`. +Reading the right side right-to-left: apply the fan `V` (compute the parity of the support onto the +collector `c`), apply the single-qubit rotation `exp(s · Z_c)` on the collector, then apply `V†` +(uncompute the parity) — Nielsen & Chuang's Figure 4.19. + +The proof mirrors `pauliStringStd_exp_smul_conj_kronFamilyStd_pauliDiagGate`: the operator collapse +`V · P_a · V† = P_{Z_c}` (`cnotFanInto_toMatrix_conj_pauliString_eq_zGenPauli`) together with the +unitarity of the Clifford circuit `V` feeds the reusable matrix-exponential lemma +`Matrix.exp_smul_conj_of_conj_eq` (which packages `Matrix.exp_units_conj` with the `s • ` scalar +and the equational conjugation hypothesis), carrying the conjugation through the exponential in one +step. The fan uses `O(n)` `CNOT`s (`length_cnotFanInto_le`). -/ +theorem pauliString_exp_smul_conj_cnotFanInto (c : Fin n) (ts : List (Fin n)) (hc : c ∉ ts) + (hnd : ts.Nodup) (a : Fin n → Fin 4) (hac : a c = 3) (hts : ∀ t ∈ ts, a t = 3) + (hrest : ∀ k, k ≠ c → k ∉ ts → a k = 0) (s : ℂ) : + NormedSpace.exp (s • pauliString a) + = (cnotFanInto c ts).toMatrixᴴ + * NormedSpace.exp (s • pauliString (zGenPauli c)) + * (cnotFanInto c ts).toMatrix := by + have hmul_CH : (cnotFanInto c ts).toMatrix * (cnotFanInto c ts).toMatrixᴴ = 1 := + CliffordCircuit.mul_conjTranspose _ + exact Matrix.exp_smul_conj_of_conj_eq _ _ _ _ hmul_CH (mul_eq_one_comm.mp hmul_CH) + (cnotFanInto_toMatrix_conj_pauliString_eq_zGenPauli c ts hc hnd a hac hts hrest) s + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliStringStdInvolution.lean b/LeanPool/AxQM/Concrete/PauliStringStdInvolution.lean new file mode 100644 index 0000000000..e931b192c8 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliStringStdInvolution.lean @@ -0,0 +1,51 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCommutation + +/-! +# Concrete: a standard-register Pauli string is an involution (`P_g² = I`) + +The Pauli string `pauliStringStd g` on the flat computational-basis register `Fin (2ⁿ)` squares to +the identity. This is the standard-indexed analogue of `pauliString_mul_self` (`P_g · P_g = I` on +the bit-string indexing `Fin n → Fin 2`), transported along the reindexing equivalence +`finFunctionFinEquiv`. + +It is the matrix half of the observation that **every honest (phase `+1`) `n`-qubit Pauli operator +is a self-adjoint involution** — Hermitian (`pauliStringStd_isHermitian`) and squaring to `I` — +hence a unitary with eigenvalues `±1`. Nielsen & Chuang use exactly this to feed a product of Pauli +operators to the operator-measurement circuit of Figure 10.13 ("`M` is an arbitrary Hermitian +operator with eigenvalues `±1`"); on the physics side it lets a Pauli-string observable be promoted +to an `Evolution` (a controllable unitary), which the stabilizer syndrome circuits of §10.5.8 need. + +Everything is stated for raw matrix / index data (`Matrix`, `Concrete.pauliStringStd`, +`Fin n → Fin 4`). +-/ + +@[expose] public section + +open scoped Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **A standard-register Pauli string is an involution**: `pauliStringStd g · pauliStringStd g = +I`. Since `pauliStringStd g = (pauliString g).submatrix e⁻¹ e⁻¹` for the reindexing equivalence +`e = finFunctionFinEquiv`, and reindexing by an equivalence is multiplicative +(`Matrix.submatrix_mul_equiv`) and sends `I` to `I` (`Matrix.submatrix_one_equiv`), this follows +from the bit-string form `pauliString_mul_self` (`P_g · P_g = I`). Each single-qubit Pauli squares +to `I` with trivial phase, so their tensor product does too. -/ +theorem pauliStringStd_mul_self (g : Fin n → Fin 4) : + pauliStringStd g * pauliStringStd g = 1 := by + unfold pauliStringStd + rw [Matrix.submatrix_mul_equiv, pauliString_mul_self, Matrix.submatrix_one_equiv] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PauliTomography.lean b/LeanPool/AxQM/Concrete/PauliTomography.lean new file mode 100644 index 0000000000..b7e937b6f6 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PauliTomography.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliString + +/-! +# Concrete: tomographic reconstruction of a matrix from its Pauli trace pairings + +This file turns the Pauli **basis** +of `M₂ₙ(ℂ)` (`Concrete/PauliString.lean`) into the explicit **reconstruction** and +**uniqueness** statements underlying *state tomography* — Nielsen & Chuang, §7.7.4, equations +(7.166)–(7.168) and their multi-spin generalisation ("Similar results hold for larger numbers of +spins"). Everything here is stated for raw matrix data (`Matrix`, `Concrete.pauliString`, `trace`). + +## The tomography backbone + +For a single qubit N&C writes `ρ = ½(I + Σₖ rₖ σₖ)` (7.166) with real coordinates +`rₖ = tr(ρ σₖ)` (7.168), recoverable because of the trace orthogonality `tr(σₖ σⱼ) = 2 δₖⱼ` +(7.167). The `n`-fold generalisation, over the Pauli strings `P_g = σ_{g₀} ⊗ ⋯ ⊗ σ_{g_{n-1}}`, is: + +* every coordinate is a trace pairing — `pauliBasis.repr M g = (2ⁿ)⁻¹ tr(P_g M)` + (`pauliBasis_repr_apply`), the (7.168) formula `rₖ = tr(ρ σₖ)`; +* the **reconstruction formula** `M = (2ⁿ)⁻¹ Σ_g tr(P_g M) • P_g` + (`eq_smul_sum_trace_pauliString`), the (7.166) expansion; +* the **uniqueness / injectivity** principle `(∀ g, tr(P_g M) = tr(P_g N)) → M = N` + (`eq_of_trace_pauliString_eq`) — *this* is what "the measurements suffice to reconstruct `M`" + means: a matrix is determined by its `4ⁿ` Pauli trace pairings; +* the **deviation-density-matrix** refinement `eq_of_trace_eq_of_trace_pauliString_eq`: once the + trace is fixed (density matrices have `tr ρ = 1`), the `4ⁿ − 1` **non-identity** pairings + already determine `M`, matching N&C's "traceless deviation" bookkeeping and the counting + `4ⁿ − 1` of independent real parameters. + +For a Hermitian `M` (a density matrix) every pairing `tr(P_g M)` is real, so the recovered +coordinates are the real `⟨σ_g⟩` of (7.168). The underlying trace-pairing facts +`trace_pauliString_mul_eq_repr` (`tr(P_g M) = repr M g · 2ⁿ`) and `trace_pauliString_mul_im` (that +pairing is real for Hermitian `M`) live upstream in `Concrete/PauliString.lean`, beside the Pauli +basis and the existence result `exists_real_pauliString_expansion` that consumes them; this file +adds the *reconstruction* / *uniqueness* statements built on top — the reusable half of state +tomography applied by N&C Exercise 7.45 (two spins) and 7.46 (three spins). +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- **The (7.168) coordinate formula**: `pauliBasis.repr M g = (2ⁿ)⁻¹ tr(P_g M)`. The single-qubit +case `rₖ = tr(ρ σₖ)` (`n = 1`, `2ⁿ = 2`, so `rₖ = ½ tr(ρ σₖ)` in N&C's `½`-normalised form). -/ +theorem pauliBasis_repr_apply (M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + (g : Fin n → Fin 4) : + pauliBasis.repr M g = ((2 : ℂ) ^ n)⁻¹ * (pauliString g * M).trace := by + have h2 : (2 : ℂ) ^ n ≠ 0 := pow_ne_zero n two_ne_zero + rw [trace_pauliString_mul_eq_repr] + field_simp + +/-- **The reconstruction formula (7.166), `n`-fold form**: every `2ⁿ × 2ⁿ` complex matrix is the +Pauli sum of its own trace pairings, `M = (2ⁿ)⁻¹ Σ_g tr(P_g M) • P_g`. This is the operational +content of tomography — the matrix is *rebuilt* from the numbers `tr(P_g M)`, which the +measurements provide. (No Hermitian hypothesis: it holds for every matrix, `ρ` being one case.) -/ +theorem eq_smul_sum_trace_pauliString (M : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) : + M = ((2 : ℂ) ^ n)⁻¹ • ∑ g, (pauliString g * M).trace • pauliString g := by + conv_lhs => rw [← pauliBasis.sum_repr M] + rw [Finset.smul_sum] + refine Finset.sum_congr rfl fun g _ => ?_ + rw [pauliBasis_apply, pauliBasis_repr_apply, smul_smul] + +/-- **Tomographic uniqueness / injectivity**: a matrix is determined by its `4ⁿ` Pauli trace +pairings — if `tr(P_g M) = tr(P_g N)` for every Pauli string `P_g`, then `M = N`. This is the +precise sense in which "the measured expectation values suffice to reconstruct the state": two +states with identical Pauli measurement statistics are equal. Both sides are rebuilt by the +reconstruction formula from data that agree termwise. -/ +theorem eq_of_trace_pauliString_eq {M N : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} + (h : ∀ g, (pauliString g * M).trace = (pauliString g * N).trace) : M = N := by + rw [eq_smul_sum_trace_pauliString M, eq_smul_sum_trace_pauliString N] + simp only [h] + +/-- **Deviation-density-matrix uniqueness**: once the trace is fixed, the **non-identity** Pauli +pairings already determine the matrix. If `tr M = tr N` and `tr(P_g M) = tr(P_g N)` for every +`g ≠ (0, …, 0)` (every Pauli string other than `I ⊗ ⋯ ⊗ I`), then `M = N`. Density matrices carry +`tr ρ = 1`, so this is the statement that the `4ⁿ − 1` non-identity expectation values +`⟨P_g⟩ = tr(ρ P_g)` reconstruct `ρ` — N&C's traceless "deviation density matrix" bookkeeping and +the `4ⁿ − 1` real-parameter count. -/ +theorem eq_of_trace_eq_of_trace_pauliString_eq + {M N : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ} (htr : M.trace = N.trace) + (h : ∀ g, g ≠ (fun _ => 0) → (pauliString g * M).trace = (pauliString g * N).trace) : + M = N := by + refine eq_of_trace_pauliString_eq fun g => ?_ + by_cases hg : g = (fun _ => 0) + · subst hg + rw [pauliString_const_zero, Matrix.one_mul, Matrix.one_mul, htr] + · exact h g hg + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PermutationGate.lean b/LeanPool/AxQM/Concrete/PermutationGate.lean new file mode 100644 index 0000000000..d545aa598f --- /dev/null +++ b/LeanPool/AxQM/Concrete/PermutationGate.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Permutation +public import Mathlib.Algebra.Group.End +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup + +/-! +# Concrete: the encoding-carried permutation gate `permGate` + +The `n`-qubit universality argument (Nielsen & Chuang §4.3/§4.5.2) realises a two-level unitary as a +circuit whose backbone is a family of **classical reversible gates** — the multiply-controlled +`NOT`, the single-wire `NOT`, the basis transpositions of the Gray-code walk, `CNOT`, `Toffoli`. +Each of these acts on the computational basis `|enc x⟩` (`enc : (Fin m → Fin 2) ≃ Fin d` an encoding +of the `m`-bit strings as the `d`-dimensional register) by a *permutation of the bit-strings* +`σ : Equiv.Perm (Fin m → Fin 2)`: `|enc x⟩ ↦ |enc (σ x)⟩`. This file provides the matrix realising +that action, `permGate enc σ`, and its algebra. + +`permGate enc σ` is defined as **Mathlib's permutation matrix** `Equiv.Perm.permMatrix` of the +conjugated permutation `(enc.permCongr σ)⁻¹` of `Fin d`; carrying `enc` and `σ` explicitly (and +using the inverse of `enc.permCongr σ`) fixes the **forward** convention +`permGate enc σ *ᵥ |enc x⟩ = |enc (σ x)⟩`, so `permGate enc` is a genuine `*`-homomorphism (not the +anti-homomorphism `permMatrix` is directly). Defining it *as* a `permMatrix` — rather than by hand +from `0/1` entries — reuses the whole `Equiv.Perm.permMatrix` API: the algebra below is derived from +`Matrix.permMatrix_one`/`_mul`/`conjTranspose_permMatrix` and `Equiv.permCongr_mul` in a few +rewrites, and the operator-norm bounds `Matrix.permMatrix_l2_opNorm_le`/`_eq` (each `‖·‖ = 1`) come +for free — exactly the per-gate norm bound the §4.5.3 error-chaining calculus will need. + +## Contents + +* `permGate enc σ` — `(enc.permCongr σ)⁻¹.permMatrix ℂ`; `permGate_apply` is its entry form, + `(permGate enc σ) i i' = 1` iff `i = enc (σ (enc.symm i'))`, so its forward action on a basis + vector is `permGate enc σ *ᵥ |enc x⟩ = |enc (σ x)⟩`. +* `permGate_one` / `permGate_mul` — `permGate enc` is a `*`-homomorphism + (`permGate enc 1 = 1`, `permGate enc σ * permGate enc τ = permGate enc (σ * τ)`). +* `permGate_conjTranspose` / `permGate_mem_unitaryGroup` — the adjoint is the gate of the inverse + permutation, so every `permGate` is unitary. + +Everything is stated for raw complex matrices and an `Equiv.Perm`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {m d : ℕ} + +/-- **The encoding-carried permutation gate.** For an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of +the `m`-bit strings as the `d`-dimensional register and a permutation `σ` of the bit-strings, +`permGate enc σ` is Mathlib's permutation matrix of the conjugated permutation `(enc.permCongr σ)⁻¹` +of `Fin d`: the `d × d` matrix sending the basis state `|enc x⟩` to `|enc (σ x)⟩`. It is the matrix +realising a classical reversible gate (`NOT`, `CNOT`, `Toffoli`, multiply-controlled `NOT`, basis +transposition) whose action on bit-strings is `σ`. -/ +def permGate (enc : (Fin m → Fin 2) ≃ Fin d) (σ : Equiv.Perm (Fin m → Fin 2)) : + Matrix (Fin d) (Fin d) ℂ := + (enc.permCongr σ)⁻¹.permMatrix ℂ + +/-- `enc.permCongr` sends the identity permutation to the identity (it is a monoid homomorphism, +`Equiv.permCongrHom`). -/ +theorem permCongr_one (enc : (Fin m → Fin 2) ≃ Fin d) : + enc.permCongr (1 : Equiv.Perm (Fin m → Fin 2)) = 1 := + map_one (Equiv.permCongrHom enc) + +/-- `enc.permCongr` commutes with taking inverses (it is a monoid homomorphism, +`Equiv.permCongrHom`). -/ +theorem permCongr_inv (enc : (Fin m → Fin 2) ≃ Fin d) (σ : Equiv.Perm (Fin m → Fin 2)) : + enc.permCongr σ⁻¹ = (enc.permCongr σ)⁻¹ := + map_inv (Equiv.permCongrHom enc) σ + +/-- **The entry form of the permutation gate.** `(permGate enc σ) i i' = 1` exactly when +`i = enc (σ (enc.symm i'))` (and `0` otherwise); equivalently its forward action on the basis is +`permGate enc σ *ᵥ |enc x⟩ = |enc (σ x)⟩`. -/ +@[simp] theorem permGate_apply (enc : (Fin m → Fin 2) ≃ Fin d) (σ : Equiv.Perm (Fin m → Fin 2)) + (i i' : Fin d) : + permGate enc σ i i' = if i = enc (σ (enc.symm i')) then 1 else 0 := by + simp only [permGate, Equiv.Perm.permMatrix, PEquiv.toMatrix_apply, Equiv.toPEquiv_apply, + Option.mem_some_iff] + refine if_congr ?_ rfl rfl + rw [Equiv.Perm.inv_def, Equiv.symm_apply_eq, Equiv.permCongr_apply] + +/-- `permGate enc 1 = 1`: the identity permutation gives the identity matrix. -/ +@[simp] theorem permGate_one (enc : (Fin m → Fin 2) ≃ Fin d) : + permGate enc (1 : Equiv.Perm (Fin m → Fin 2)) = 1 := by + simp only [permGate, permCongr_one, inv_one, Matrix.permMatrix_one] + +/-- **`permGate enc` is multiplicative**: `permGate enc σ * permGate enc τ = permGate enc (σ * τ)`. +Composing the gates (rightmost first) composes the bit-string permutations, +`(σ * τ) x = σ (τ x)`. Derived from `Matrix.permMatrix_mul` (an anti-homomorphism) and +`Equiv.permCongr_mul`, with `mul_inv_rev` absorbing the order reversal. -/ +theorem permGate_mul (enc : (Fin m → Fin 2) ≃ Fin d) (σ τ : Equiv.Perm (Fin m → Fin 2)) : + permGate enc σ * permGate enc τ = permGate enc (σ * τ) := by + simp only [permGate] + rw [← Matrix.permMatrix_mul, ← _root_.mul_inv_rev, ← Equiv.permCongr_mul] + +/-- **The adjoint of a permutation gate is the gate of the inverse permutation.** +`(permGate enc σ)ᴴ = permGate enc σ⁻¹`, from `Matrix.conjTranspose_permMatrix`. -/ +@[simp] theorem permGate_conjTranspose (enc : (Fin m → Fin 2) ≃ Fin d) + (σ : Equiv.Perm (Fin m → Fin 2)) : + (permGate enc σ)ᴴ = permGate enc σ⁻¹ := by + simp only [permGate] + rw [Matrix.conjTranspose_permMatrix, permCongr_inv] + +/-- **Every permutation gate is unitary.** A permutation matrix is unitary +(`star (permMatrix ρ) = permMatrix ρ⁻¹` and `permMatrix ρ * permMatrix ρ⁻¹ = permMatrix 1 = 1`). -/ +theorem permGate_mem_unitaryGroup (enc : (Fin m → Fin 2) ≃ Fin d) + (σ : Equiv.Perm (Fin m → Fin 2)) : + permGate enc σ ∈ Matrix.unitaryGroup (Fin d) ℂ := by + simp only [permGate] + rw [Matrix.mem_unitaryGroup_iff, Matrix.star_eq_conjTranspose, Matrix.conjTranspose_permMatrix, + ← Matrix.permMatrix_mul, inv_mul_cancel, Matrix.permMatrix_one] + +/-- **A permutation gate sends a basis state to a basis state:** +`permGate enc σ *ᵥ |enc x⟩ = |enc (σ x)⟩` — the forward action recorded in `permGate`'s definition, +on the standard basis vectors. This is the column form of `permGate_apply`: the `j = enc x` column +of `permGate enc σ` is the indicator of `enc (σ x)`. -/ +theorem permGate_mulVec_single (enc : (Fin m → Fin 2) ≃ Fin d) + (σ : Equiv.Perm (Fin m → Fin 2)) (x : Fin m → Fin 2) : + permGate enc σ *ᵥ Pi.single (enc x) 1 = Pi.single (enc (σ x)) 1 := by + funext i + rw [Matrix.mulVec_single_one, Matrix.col_apply, permGate_apply, Equiv.symm_apply_apply, + Pi.single_apply] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PiEighthGate.lean b/LeanPool/AxQM/Concrete/PiEighthGate.lean new file mode 100644 index 0000000000..40cf738b75 --- /dev/null +++ b/LeanPool/AxQM/Concrete/PiEighthGate.lean @@ -0,0 +1,83 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation + +/-! +# Concrete: the π/8 (T) gate and its relation to `R_z(π/4)` (Nielsen & Chuang, §4.2) + +Nielsen & Chuang's **π/8 gate** (denoted `T`) is the diagonal single-qubit gate +`T = !![1, 0; 0, exp(iπ/4)]` (eq. 4.2). +It is called the "π/8 gate" because, pulling out a global phase `exp(iπ/8)`, it equals a gate with +`exp(±iπ/8)` on the diagonal (eq. 4.3): +`T = exp(iπ/8) !![exp(-iπ/8), 0; 0, exp(iπ/8)] = exp(iπ/8) R_z(π/4)`, +since `R_z(θ) = !![exp(-iθ/2), 0; 0, exp(iθ/2)]` (eq. 4.6, `Concrete.rotZ_eq`) evaluated at +`θ = π/4` has `θ/2 = π/8`. + +This is the pure `2 × 2` complex-matrix content of **Exercise 4.3** (`T = R_z(π/4)` up to a global +phase). The physics reading — that `T` and `R_z(π/4)` are the *same qubit gate* up to the +unobservable global phase — is in `AxQM/Postulates/API/PiEighthGate.lean`. + +## What is formalized + +* `tMatrix` — the T gate matrix `!![1, 0; 0, exp(iπ/4)]` (eq. 4.2). +* `tMatrix_eq_expPiDivEight_smul_rotZ` — **the identity of Exercise 4.3**: + `T = exp(iπ/8) • R_z(π/4)` (eq. 4.3). +* `tMatrix_mem_unitaryGroup` — `T` is unitary. +-/ + +@[expose] public section + +open scoped Matrix + +noncomputable section + +namespace AxQM.Concrete + +/-- The **π/8 (T) gate** `T = !![1, 0; 0, exp(iπ/4)]` (Nielsen & Chuang, eq. 4.2), a diagonal +single-qubit gate. Historically called the "π/8 gate" because of the global-phase form +`T = exp(iπ/8) R_z(π/4)` (`tMatrix_eq_expPiDivEight_smul_rotZ`). -/ +def tMatrix : Matrix (Fin 2) (Fin 2) ℂ := + !![1, 0; 0, Complex.exp ((Real.pi / 4 : ℝ) * Complex.I)] + +/-- **The identity of Nielsen & Chuang Exercise 4.3** (eq. 4.3): the π/8 gate equals `R_z(π/4)` up +to the global phase `exp(iπ/8)`, i.e. `T = exp(iπ/8) • R_z(π/4)`. Both are diagonal, and pulling the +scalar `exp(iπ/8)` through `R_z(π/4) = diag(exp(-iπ/8), exp(iπ/8))` gives `diag(1, exp(iπ/4)) = T` +via `exp(iπ/8)·exp(-iπ/8) = 1` and `exp(iπ/8)·exp(iπ/8) = exp(iπ/4)`. -/ +theorem tMatrix_eq_expPiDivEight_smul_rotZ : + tMatrix = Complex.exp ((Real.pi / 8 : ℝ) * Complex.I) • rotZ (Real.pi / 4) := by + rw [rotZ_eq] + unfold tMatrix + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, Matrix.of_apply, Matrix.cons_val', + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_fin_one, Matrix.smul_apply, + smul_eq_mul, neg_mul, mul_zero, Complex.ofReal_div, Complex.ofReal_ofNat] + · -- (0,0): `1 = exp(iπ/8) · exp(-i(π/4)/2)` + rw [← Complex.exp_add, ← Complex.exp_zero] + congr 1 + ring + · -- (1,1): `exp(iπ/4) = exp(iπ/8) · exp(i(π/4)/2)` + rw [← Complex.exp_add] + congr 1 + ring + +/-- The π/8 gate `T` is unitary: it lies in the `2 × 2` unitary group. Immediate from the global +phase identity `T = exp(iπ/8) • R_z(π/4)` (`tMatrix_eq_expPiDivEight_smul_rotZ`), the unitarity of +`R_z(π/4)` (`rotZ_mem_unitaryGroup`), and the fact that scaling a unitary by the unit-modulus phase +`exp(iπ/8)` keeps it unitary (`exp(iπ/8) · conj(exp(iπ/8)) = 1`). -/ +theorem tMatrix_mem_unitaryGroup : tMatrix ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + have hc : Complex.exp ((Real.pi / 8 : ℝ) * Complex.I) * + star (Complex.exp ((Real.pi / 8 : ℝ) * Complex.I)) = 1 := by + rw [← starRingEnd_apply, Complex.mul_conj', Complex.norm_exp_ofReal_mul_I]; norm_num + rw [tMatrix_eq_expPiDivEight_smul_rotZ, Matrix.mem_unitaryGroup_iff, star_smul, + smul_mul_smul_comm, Matrix.mem_unitaryGroup_iff.mp (rotZ_mem_unitaryGroup _), hc, one_smul] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/PlusStateTensorPower.lean b/LeanPool/AxQM/Concrete/PlusStateTensorPower.lean new file mode 100644 index 0000000000..774cc45adc --- /dev/null +++ b/LeanPool/AxQM/Concrete/PlusStateTensorPower.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliEigenvectors + +/-! +# Concrete: tensor powers of the plus state (Nielsen & Chuang, Exercise 2.26) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 2.26 (p. 74) +asks: for `|ψ⟩ = (|0⟩ + |1⟩)/√2`, write out `|ψ⟩^⊗2` and `|ψ⟩^⊗3` explicitly, **both** +in terms of tensor products like `|0⟩|1⟩` and **using the Kronecker product**. + +The state `|ψ⟩` is exactly the `X`-eigenvector `|+⟩` (`xPlus` from +`Concrete.PauliEigenvectors`); `xPlus_eq_smul_add` records this identification +`|+⟩ = (|0⟩ + |1⟩)/√2`. This is pure linear algebra over `ℂ²`. + +## The Kronecker product of vectors + +`vecKron u v` is the Kronecker (tensor) product of two finite complex column vectors, +indexed by the product index type: `(u ⊗ v) (i, j) = uᵢ · vⱼ`. Viewing `u, v` as +column vectors, this is their Kronecker product, with the row index of the result the +pair `(i, j)` — the row-major ordering that `finProdFinEquiv` flattens to `n·i + j`, +so `vecKron` *is* N&C's Kronecker product up to that reindexing. A basis ket `|i⟩|j⟩` +of the tensor-product space is `vecKron (ket i) (ket j)`, which is the standard basis +vector supported at `(i, j)`; that identification is what makes the two requested +representations — a sum of basis kets, and an explicit (uniform) column vector — the +same object. + +## Contents + +* `vecKron`, `vecKron_apply` — the vector Kronecker product and its entrywise value. +* `xPlus_eq_smul_add` — `|+⟩` equals `(|0⟩ + |1⟩)/√2` (the exercise's `|ψ⟩`). The + component formula `xPlus_apply` (`|+⟩ᵢ = 1/√2`) lives with `xPlus` in + `Concrete.PauliEigenvectors` and is used here via the import. +* `vecKron_xPlus_xPlus` — the Kronecker-product form of `|ψ⟩^⊗2`: the explicit + 4-component column vector with every entry `1/2`, i.e. `½(1, 1, 1, 1)ᵀ`. +* `vecKron_xPlus_xPlus_eq_sum` — the tensor-product form of `|ψ⟩^⊗2`: + `½(|00⟩ + |01⟩ + |10⟩ + |11⟩)`. +* `vecKron_xPlus_vecKron_xPlus_xPlus` — the Kronecker-product form of `|ψ⟩^⊗3`: the + explicit 8-component column vector with every entry `1/(2√2) = (1/√2)/2`. +* `vecKron_xPlus_vecKron_xPlus_xPlus_eq_sum` — the tensor-product form of `|ψ⟩^⊗3`: + `1/(2√2) · (|000⟩ + |001⟩ + ⋯ + |111⟩)`, all eight computational-basis kets. + +## Design notes + +* `|ψ⟩^⊗3` is right-nested, `|ψ⟩ ⊗ (|ψ⟩ ⊗ |ψ⟩)`, so it is indexed by + `Fin 2 × Fin 2 × Fin 2 = Fin 2 × (Fin 2 × Fin 2)`; Kronecker association is a mere + reindexing, so the grouping is immaterial to the "written-out" content. +* The two forms are stated as separate named theorems (not a monolithic conjunction), + one per representation the exercise requests. The uniform-vector forms use the shared + arithmetic fact `invSqrt2_mul_self : (1/√2)·(1/√2) = 1/2`; the sum-of-kets forms hold + because at each index exactly one of the enumerated basis kets is supported. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- The Kronecker (tensor) product of two finite complex column vectors, indexed by the +product index type: `(u ⊗ v) (i, j) = uᵢ · vⱼ`. This is the Kronecker product of `u` +and `v` viewed as column vectors, with the row index of the result the pair `(i, j)` +(row-major order flattens `(i, j)` to `n·i + j` via `finProdFinEquiv`). The tensor-product +basis ket `|i⟩|j⟩` is `vecKron (ket i) (ket j)`. -/ +def vecKron {m n : Type*} (u : m → ℂ) (v : n → ℂ) : m × n → ℂ := fun p => u p.1 * v p.2 + +/-- The `(i, j)` entry of the Kronecker product `u ⊗ v` is `uᵢ · vⱼ`. -/ +@[simp] theorem vecKron_apply {m n : Type*} (u : m → ℂ) (v : n → ℂ) (i : m) (j : n) : + vecKron u v (i, j) = u i * v j := rfl + +/-- The plus state written in N&C's Exercise 2.26 form `|ψ⟩ = (|0⟩ + |1⟩)/√2`, i.e. +`|+⟩ = (1/√2) · (|0⟩ + |1⟩)`. -/ +theorem xPlus_eq_smul_add : xPlus = invSqrt2 • (ket 0 + ket 1) := by + funext i + fin_cases i <;> + simp [xPlus, ket] + +/-- The minus state in the analogous form `|-⟩ = (|0⟩ - |1⟩)/√2`, i.e. +`|-⟩ = (1/√2) · (|0⟩ - |1⟩)`. The sign-flipped companion of `xPlus_eq_smul_add`. -/ +theorem xMinus_eq_smul_sub : xMinus = invSqrt2 • (ket 0 - ket 1) := by + funext i + fin_cases i <;> + simp [xMinus, ket] + +/-! ### `|ψ⟩^⊗2` -/ + +/-- **`|ψ⟩^⊗2` via the Kronecker product.** For `|ψ⟩ = (|0⟩ + |1⟩)/√2`, the Kronecker +product `|ψ⟩ ⊗ |ψ⟩` is the explicit 4-component column vector with every entry `1/2`: +`|ψ⟩^⊗2 = ½(1, 1, 1, 1)ᵀ`. -/ +theorem vecKron_xPlus_xPlus : vecKron xPlus xPlus = fun _ => (1 / 2 : ℂ) := by + funext p + simp only [vecKron, xPlus_apply, invSqrt2_mul_self] + norm_num + +/-- **`|ψ⟩^⊗2` in terms of tensor products.** For `|ψ⟩ = (|0⟩ + |1⟩)/√2`, +`|ψ⟩^⊗2 = ½(|00⟩ + |01⟩ + |10⟩ + |11⟩)`, where `|ij⟩ = vecKron (ket i) (ket j)`. -/ +theorem vecKron_xPlus_xPlus_eq_sum : + vecKron xPlus xPlus = + (1 / 2 : ℂ) • (vecKron (ket 0) (ket 0) + vecKron (ket 0) (ket 1) + + vecKron (ket 1) (ket 0) + vecKron (ket 1) (ket 1)) := by + funext p + obtain ⟨i, j⟩ := p + fin_cases i <;> fin_cases j <;> + simp [vecKron, ket, Pi.add_apply, Pi.smul_apply, invSqrt2_mul_self] + +/-! ### `|ψ⟩^⊗3` -/ + +/-- **`|ψ⟩^⊗3` via the Kronecker product.** For `|ψ⟩ = (|0⟩ + |1⟩)/√2`, the Kronecker +product `|ψ⟩ ⊗ (|ψ⟩ ⊗ |ψ⟩)` is the explicit 8-component column vector with every entry +`1/(2√2) = (1/√2)/2`. -/ +theorem vecKron_xPlus_vecKron_xPlus_xPlus : + vecKron xPlus (vecKron xPlus xPlus) = fun _ => invSqrt2 / 2 := by + funext p + obtain ⟨i, j, k⟩ := p + simp only [vecKron, xPlus_apply, invSqrt2_mul_self] + ring + +/-- **`|ψ⟩^⊗3` in terms of tensor products.** For `|ψ⟩ = (|0⟩ + |1⟩)/√2`, +`|ψ⟩^⊗3 = 1/(2√2) · (|000⟩ + |001⟩ + |010⟩ + |011⟩ + |100⟩ + |101⟩ + |110⟩ + |111⟩)`, +the equal superposition of all eight computational-basis kets +`|ijk⟩ = vecKron (ket i) (vecKron (ket j) (ket k))`. -/ +theorem vecKron_xPlus_vecKron_xPlus_xPlus_eq_sum : + vecKron xPlus (vecKron xPlus xPlus) = + (invSqrt2 / 2) • (vecKron (ket 0) (vecKron (ket 0) (ket 0)) + + vecKron (ket 0) (vecKron (ket 0) (ket 1)) + + vecKron (ket 0) (vecKron (ket 1) (ket 0)) + + vecKron (ket 0) (vecKron (ket 1) (ket 1)) + + vecKron (ket 1) (vecKron (ket 0) (ket 0)) + + vecKron (ket 1) (vecKron (ket 0) (ket 1)) + + vecKron (ket 1) (vecKron (ket 1) (ket 0)) + + vecKron (ket 1) (vecKron (ket 1) (ket 1))) := by + funext p + obtain ⟨i, j, k⟩ := p + fin_cases i <;> fin_cases j <;> fin_cases k <;> + simp [vecKron, ket, Pi.add_apply, Pi.smul_apply, invSqrt2_mul_self] <;> + ring + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QFTTwoLevel.lean b/LeanPool/AxQM/Concrete/QFTTwoLevel.lean new file mode 100644 index 0000000000..2a20f76771 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QFTTwoLevel.lean @@ -0,0 +1,220 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Notation +public import LeanPool.AxQM.ToMathlib.Data.Real.Sqrt +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Basic.Complex.Basic +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup + +/-! +# Concrete: two-level decomposition of the 4×4 quantum Fourier transform (N&C Ex 4.37) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 4.37 (p. 191) asks +for a decomposition of the transform (eq. 4.52) + +``` + [ 1 1 1 1 ] + F = ½ [ 1 i -1 -i ] (Fⱼₖ = ½ · iʲᵏ, j,k ∈ {0,1,2,3}) + [ 1 -1 1 -1 ] + [ 1 -i -1 i ] +``` + +— the two-qubit quantum Fourier transform (the `N = 4` discrete Fourier transform matrix) — into +a product of **two-level unitaries**: unitary matrices that act non-trivially on at most two of +the four computational basis vectors (i.e. agree with the identity outside a single 2×2 principal +submatrix). + +## The decomposition + +We use the radix-2 (Cooley–Tukey) factorisation of the DFT, `F = B · (H ⊕ H) · P`, in which every +sparse factor splits into a pair of *disjoint* 2×2 blocks — and disjoint blocks each embed as a +genuine two-level unitary. Concretely + +``` + F = qftFactorH02 · qftFactorG13 · qftFactorH01 · qftFactorH23 · qftFactorSwap +``` + +where, writing `H = (√2)⁻¹ !![1,1; 1,-1]` for the Hadamard block and +`G = (√2)⁻¹ !![1,i; 1,-i]` for the "twiddled" Hadamard block, + +* `qftFactorH02` — `H` on the coordinate pair `{0,2}` (identity on `{1,3}`); +* `qftFactorG13` — `G` on `{1,3}` (identity on `{0,2}`); +* `qftFactorH01` — `H` on `{0,1}`; +* `qftFactorH23` — `H` on `{2,3}`; +* `qftFactorSwap` — the transposition (bit-reversal swap) of `{1,2}`. + +The five factors compose to `F` exactly: the two Hadamard-magnitude layers each contribute a +`(√2)⁻¹` per block, and the two `(√2)⁻¹` factors that meet on each basis vector multiply to the +overall `½` prefactor of (4.52) (`qftFour_eq_prod`). Each factor is a two-level unitary +(`qftFactor…_isTwoLevelUnitary`), and — as a product of unitaries — `F` is itself unitary +(`qftFour_mem_unitaryGroup`). + +## Design notes + +* **A concrete existence result.** The exercise asks only to *provide* a decomposition, so this is + an explicit construction, not an appeal to the general §4.5.1 algorithm (N&C's Gaussian-style + procedure, which would produce up to `d(d-1)/2 = 6` factors with irrational Givens entries). The + FFT route gives a cleaner five-factor product whose blocks are Hadamard/twiddle gates and a + permutation, and it never needs the general theorem. +* **Genuine two-level factors.** Each factor equals the identity outside one 2×2 block, so scalars + cannot be pulled through the whole matrix; the definitions carry the `(√2)⁻¹` entries inline. + The product proof instead groups the two disjoint-block layers (`H02·G13` and `H01·H23`), each of + which *does* factor as `(√2)⁻¹ • (Gaussian-integer matrix)`, so the only irrational arithmetic is + the single scalar identity `(√2)⁻¹ · (√2)⁻¹ = ½`. +* **Generality.** The statement of Exercise 4.37 is in [upstream `AxQM/NC/Ch4/Exercise4_37.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_37.lean). + `IsTwoLevelUnitary` is stated here in general `d` dimensions so it can be reused for the + neighbouring two-level items (Ex 4.38, Ex 4.39, §4.5.1). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- A `d × d` complex matrix `U` is a **two-level unitary** (Nielsen & Chuang §4.5.1) when it is +unitary and acts non-trivially on at most two computational basis vectors: there are indices +`p, q` such that `U` agrees with the identity on every entry lying outside the `{p,q} × {p,q}` +principal submatrix. Allowing `p = q` includes the one-level (single-phase) case, so this captures +"acts non-trivially on two-or-fewer components". -/ +def IsTwoLevelUnitary {d : ℕ} (U : Matrix (Fin d) (Fin d) ℂ) : Prop := + U ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + ∃ p q : Fin d, ∀ i j : Fin d, + (i ≠ p ∧ i ≠ q) ∨ (j ≠ p ∧ j ≠ q) → U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j + +/-- The normalisation scalar squares to `½`: `(√2)⁻¹ · (√2)⁻¹ = 2⁻¹` over `ℂ`. Used in the product +identity, where the two Hadamard-layer factors of `(√2)⁻¹` combine into the `½` of (4.52). -/ +theorem invSqrtTwo_mul_self : (Real.sqrt 2 : ℂ)⁻¹ * (Real.sqrt 2 : ℂ)⁻¹ = 2⁻¹ := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num)]; norm_num + +/-- `(√2)² = 2` over `ℂ`. Used to close the diagonal entries of the `star U · U = I` unitarity +checks, where two `(√2)⁻¹` factors combine as `(√2²)⁻¹ = 2⁻¹`. -/ +theorem sqrtTwo_sq : (Real.sqrt 2 : ℂ) ^ 2 = 2 := by + rw [← Complex.ofReal_pow, Real.sq_sqrt (by norm_num)]; norm_num + +/-- The 4×4 quantum Fourier transform `F` of Nielsen & Chuang eq. (4.52), `Fⱼₖ = ½ · iʲᵏ`: +`½ !![1,1,1,1; 1,i,-1,-i; 1,-1,1,-1; 1,-i,-1,i]`. This is the `N = 4` discrete Fourier transform +matrix, i.e. the two-qubit QFT. -/ +noncomputable def qftFour : Matrix (Fin 4) (Fin 4) ℂ := + (2⁻¹ : ℂ) • !![1, 1, 1, 1; 1, Complex.I, -1, -Complex.I; + 1, -1, 1, -1; 1, -Complex.I, -1, Complex.I] + +/-- First factor: the Hadamard block `H = (√2)⁻¹ !![1,1; 1,-1]` acting on the coordinate pair +`{0,2}`, identity on `{1,3}`. A two-level unitary. -/ +noncomputable def qftFactorH02 : Matrix (Fin 4) (Fin 4) ℂ := + !![(Real.sqrt 2 : ℂ)⁻¹, 0, (Real.sqrt 2 : ℂ)⁻¹, 0; 0, 1, 0, 0; + (Real.sqrt 2 : ℂ)⁻¹, 0, -(Real.sqrt 2 : ℂ)⁻¹, 0; 0, 0, 0, 1] + +/-- Second factor: the twiddled Hadamard block `G = (√2)⁻¹ !![1,i; 1,-i]` acting on the coordinate +pair `{1,3}`, identity on `{0,2}`. A two-level unitary. -/ +noncomputable def qftFactorG13 : Matrix (Fin 4) (Fin 4) ℂ := + !![1, 0, 0, 0; 0, (Real.sqrt 2 : ℂ)⁻¹, 0, Complex.I * (Real.sqrt 2 : ℂ)⁻¹; + 0, 0, 1, 0; 0, (Real.sqrt 2 : ℂ)⁻¹, 0, -(Complex.I * (Real.sqrt 2 : ℂ)⁻¹)] + +/-- Third factor: the Hadamard block `H = (√2)⁻¹ !![1,1; 1,-1]` acting on the coordinate pair +`{0,1}`, identity on `{2,3}`. A two-level unitary. -/ +noncomputable def qftFactorH01 : Matrix (Fin 4) (Fin 4) ℂ := + !![(Real.sqrt 2 : ℂ)⁻¹, (Real.sqrt 2 : ℂ)⁻¹, 0, 0; + (Real.sqrt 2 : ℂ)⁻¹, -(Real.sqrt 2 : ℂ)⁻¹, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1] + +/-- Fourth factor: the Hadamard block `H = (√2)⁻¹ !![1,1; 1,-1]` acting on the coordinate pair +`{2,3}`, identity on `{0,1}`. A two-level unitary. -/ +noncomputable def qftFactorH23 : Matrix (Fin 4) (Fin 4) ℂ := + !![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, (Real.sqrt 2 : ℂ)⁻¹, (Real.sqrt 2 : ℂ)⁻¹; + 0, 0, (Real.sqrt 2 : ℂ)⁻¹, -(Real.sqrt 2 : ℂ)⁻¹] + +/-- Fifth factor: the transposition (bit-reversal swap) of the coordinate pair `{1,2}`, identity on +`{0,3}`. A two-level unitary (a permutation matrix). -/ +def qftFactorSwap : Matrix (Fin 4) (Fin 4) ℂ := + !![1, 0, 0, 0; 0, 0, 1, 0; 0, 1, 0, 0; 0, 0, 0, 1] + +/-- **Nielsen & Chuang, Exercise 4.37.** The 4×4 quantum Fourier transform factors as a product of +five two-level unitaries, `F = qftFactorH02 · qftFactorG13 · qftFactorH01 · qftFactorH23 · +qftFactorSwap`. Proved by grouping the two disjoint-block layers `H02·G13 = (√2)⁻¹ • B` and +`H01·H23 = (√2)⁻¹ • C` (both Gaussian-integer matrices), so that `(√2)⁻¹ · (√2)⁻¹ = ½` supplies the +prefactor and the remaining product `B · C · Swap` is the integer matrix `!![…] = 2·F`. -/ +theorem qftFour_eq_prod : + qftFour = qftFactorH02 * qftFactorG13 * qftFactorH01 * qftFactorH23 * qftFactorSwap := by + have hA : qftFactorH02 * qftFactorG13 + = (Real.sqrt 2 : ℂ)⁻¹ • !![1, 0, 1, 0; 0, 1, 0, Complex.I; + 1, 0, -1, 0; 0, 1, 0, -Complex.I] := by + ext i j; fin_cases i <;> fin_cases j <;> + simp [qftFactorH02, qftFactorG13, Matrix.mul_apply, Fin.sum_univ_four, + Matrix.smul_apply] <;> ring + have hB : qftFactorH01 * qftFactorH23 + = (Real.sqrt 2 : ℂ)⁻¹ • !![1, 1, 0, 0; 1, -1, 0, 0; 0, 0, 1, 1; 0, 0, 1, -1] := by + ext i j; fin_cases i <;> fin_cases j <;> + simp [qftFactorH01, qftFactorH23, Matrix.mul_apply, Fin.sum_univ_four, Matrix.smul_apply] + rw [mul_assoc (qftFactorH02 * qftFactorG13) qftFactorH01 qftFactorH23, hA, hB] + simp only [Matrix.smul_mul, Matrix.mul_smul, smul_smul, invSqrtTwo_mul_self] + rw [qftFour] + congr 1 + ext i j; fin_cases i <;> fin_cases j <;> + simp [qftFactorSwap, Matrix.mul_apply, Fin.sum_univ_four] + +/-- The first factor is a two-level unitary, acting only on `{0,2}`. -/ +theorem qftFactorH02_isTwoLevelUnitary : IsTwoLevelUnitary qftFactorH02 := by + refine ⟨?_, 0, 2, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff']; ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_four, Matrix.star_apply, qftFactorH02] <;> + ring_nf <;> norm_num [Complex.I_sq, sqrtTwo_sq] + · intro i j h + fin_cases i <;> fin_cases j <;> simp_all [qftFactorH02] + +/-- The second factor is a two-level unitary, acting only on `{1,3}`. -/ +theorem qftFactorG13_isTwoLevelUnitary : IsTwoLevelUnitary qftFactorG13 := by + refine ⟨?_, 1, 3, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff']; ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_four, Matrix.star_apply, qftFactorG13] <;> + ring_nf <;> norm_num [Complex.I_sq, sqrtTwo_sq] + · intro i j h + fin_cases i <;> fin_cases j <;> simp_all [qftFactorG13] + +/-- The third factor is a two-level unitary, acting only on `{0,1}`. -/ +theorem qftFactorH01_isTwoLevelUnitary : IsTwoLevelUnitary qftFactorH01 := by + refine ⟨?_, 0, 1, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff']; ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_four, Matrix.star_apply, qftFactorH01] <;> + ring_nf <;> norm_num [Complex.I_sq, sqrtTwo_sq] + · intro i j h + fin_cases i <;> fin_cases j <;> simp_all [qftFactorH01] + +/-- The fourth factor is a two-level unitary, acting only on `{2,3}`. -/ +theorem qftFactorH23_isTwoLevelUnitary : IsTwoLevelUnitary qftFactorH23 := by + refine ⟨?_, 2, 3, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff']; ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_four, Matrix.star_apply, qftFactorH23] <;> + ring_nf <;> norm_num [Complex.I_sq, sqrtTwo_sq] + · intro i j h + fin_cases i <;> fin_cases j <;> simp_all [qftFactorH23] + +/-- The fifth factor is a two-level unitary, acting only on `{1,2}` (a transposition). -/ +theorem qftFactorSwap_isTwoLevelUnitary : IsTwoLevelUnitary qftFactorSwap := by + refine ⟨?_, 1, 2, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff']; ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.mul_apply, Fin.sum_univ_four, Matrix.star_apply, qftFactorSwap] + · intro i j h + fin_cases i <;> fin_cases j <;> simp_all [qftFactorSwap] + +/-- The 4×4 quantum Fourier transform is unitary: being a product of the five two-level unitaries of +`qftFour_eq_prod`, it lies in the unitary group. -/ +theorem qftFour_mem_unitaryGroup : qftFour ∈ Matrix.unitaryGroup (Fin 4) ℂ := by + rw [qftFour_eq_prod] + exact mul_mem (mul_mem (mul_mem (mul_mem qftFactorH02_isTwoLevelUnitary.1 + qftFactorG13_isTwoLevelUnitary.1) qftFactorH01_isTwoLevelUnitary.1) + qftFactorH23_isTwoLevelUnitary.1) qftFactorSwap_isTwoLevelUnitary.1 + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftGateCircuit.lean b/LeanPool/AxQM/Concrete/QftGateCircuit.lean new file mode 100644 index 0000000000..7b4e1b1619 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftGateCircuit.lean @@ -0,0 +1,232 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubit +public import LeanPool.AxQM.Concrete.SingleQubitWire +public import LeanPool.AxQM.Concrete.Hadamard +public import LeanPool.AxQM.Concrete.PermutationGate +public import LeanPool.AxQM.Concrete.QftGateCount +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin + +/-! +# Concrete: the gate-level Figure 5.1 quantum-Fourier-transform circuit + +Nielsen & Chuang, §5.1, p. 219, Figure 5.1, give the **efficient circuit for the quantum Fourier +transform** on `n` qubits: process the wires in turn, applying to wire `t` one Hadamard followed by +a cascade of *controlled-`Rₖ`* phase rotations from the later wires, and finish with swap gates that +reverse the wire order. The gate + +``` + Rₖ = diag(1, e^{2πi/2^k}) (5.11) +``` + +is a one-qubit phase rotation, and the controlled-`Rₖ` acting between two wires is the diagonal +controlled phase `|0⟩⟨0|⊗I + |1⟩⟨1|⊗Rₖ`. + +This file assembles that circuit as an explicit **matrix product** over the raw `2ⁿ`-dimensional +register `Fin (2ⁿ)`, reusing the wire-gate framework already in `Concrete/` — `singleQubitOnWire` +(uncontrolled one-qubit gate, `AxQM/Concrete/SingleQubitWire.lean`), `mcCtrlSingleQubit` (controlled +one-qubit gate, `AxQM/Concrete/MultiControlledSingleQubit.lean`), and `permGate` (the swap +permutation, `AxQM/Concrete/PermutationGate.lean`) — under the little-endian bit encoding +`finFunctionFinEquiv : (Fin n → Fin 2) ≃ Fin (2ⁿ)` +(`k = ∑ₗ kₗ 2ˡ`), the same encoding as the product representation `Concrete.qftMatrix_apply_prod`. + +## What is formalised + +* `qftRk k` — the phase matrix `Rₖ = diag(1, e^{2πi/2^k})` (eq. 5.11), and + `qftRk_mem_unitaryGroup` — it is unitary (its lone off-`1` entry is a unit-modulus phase). +* `qftHadamardGate n t`, `qftControlledGate n t c` — the two elementary gates on the `n`-qubit + register: the Hadamard on wire `t`, and the controlled-`R_{(c-t)+1}` from control wire `c` onto + target wire `t` (a control at distance `d = c - t` carries `R_{d+1}`, so the nearest control + `c = t+1` carries `R₂`, matching Figure 5.1's `R₂ … R_{n-t}` cascade). +* `qftTargetControls n t` — the later wires `t+1, …, n-1` that control target `t` + (`length_qftTargetControls`: there are `n-1-t` of them); `qftBlock n t` — target `t`'s block + (Hadamard, then its controlled gates); `qftBitReversal n` — the wire-reversing permutation of the + swap layer. +* `qftGateSequence n` — the full ordered gate list of Figure 5.1: the wire-reversal (swap) layer, + then every target's block in order `t = 0, 1, …, n-1`; and + `qftGateCircuit n = (qftGateSequence n).reverse.prod` — the circuit as a `2ⁿ × 2ⁿ` matrix. The + list is in **circuit/time order** (the gate applied first is written first); the matrix is the + product of the *reversed* list so that, read as an operator, the first-listed gate acts first + (`(g₁ :: … :: gₘ).reverse.prod = gₘ * … * g₁`). **Endianness — why the swap layer comes first.** + Under the little-endian encoding `finFunctionFinEquiv` (`k = ∑ₗ kₗ 2ˡ`, wire `0` the *least* + significant), the blocks process wire `0` first with its controls drawn from the *higher* wires, + so wire `0` plays the most-significant role and the block cascade builds the QFT's phases in + reverse-bit order. Placing the wire-reversal **before** the blocks (rather than after, as in a + big-endian drawing of Figure 5.1) is exactly what makes the resulting matrix equal to the + little-endian `qftMatrix 2ⁿ` — the identity `qftGateCircuit 2 = qftMatrix 4` is certified in + `AxQM/Concrete/QftGateCircuitCorrectness.lean` (general `n` in + `AxQM/Concrete/QftGateCircuitEqMatrix.lean`). The swap layer's *position* is + immaterial to Exercise 5.6: the perturbable controlled-`Rₖ` gates (`qftControlledGates`) and their + count are unchanged; only the parameter-free swap moves to the input end. +* `qftGateCircuit_mem_unitaryGroup` — the circuit is **unitary**: every factor (Hadamard, controlled + phase, swap permutation) is unitary, so their product is (`Submonoid.list_prod_mem`). This is + N&C's remark that the circuit "proves that the quantum Fourier transform is unitary, since each + gate in the circuit is unitary." +* `qftControlledGates n` — the controlled-`Rₖ` gates of the circuit (the `qftBlock` cascades, + concatenated), and `length_qftControlledGates` — there are exactly `qftControlledRkCount n = + n(n-1)/2` of them. These are the only gates carrying a continuous phase parameter, hence the ones + implemented to finite precision in Exercise 5.6; the Hadamards and swaps are parameter-free. + +## Why this file exists (Exercise 5.6) + +The faithful `Ω(n²/p(n))` lower bound of Exercise 5.6 (perturbing the controlled-`Rₖ` gates to +precision `Δ = 1/p(n)` costs error `Θ(n²/p(n))`) requires the Figure 5.1 circuit as a *formal* +object whose `Rₖ` gates one can individually perturb — the postulate-level `qftEvolution` is the +matrix-derived transform, monolithic, with no exposed gate structure. This file supplies that +object: the gate product `qftGateCircuit`, its unitarity, and the identification of its `n(n-1)/2` +perturbable controlled gates (`qftControlledGates`). That `qftGateCircuit n = qftMatrix 2ⁿ` (the +circuit computes the transform, N&C eqs. 5.12–5.18, via the product representation +`qftMatrix_apply_eq_prod_wirePhase`) is proved in `AxQM/Concrete/QftGateCircuitEqMatrix.lean`; the +perturbation and the coherent lower bound build on that. This is the general-`n` gate-level +counterpart of the two-qubit `qftFour_eq_prod`. + +## Setting + +Every statement is about complex matrices (`Matrix`, `Matrix.unitaryGroup`), the encoding +equivalence `finFunctionFinEquiv`, permutations, and the gate-count function +`qftControlledRkCount`, alongside the matrix `qftMatrix` and the gate count it consumes. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **The `Rₖ` phase gate** `Rₖ = diag(1, e^{2πi/2^k})` (Nielsen & Chuang eq. 5.11): the one-qubit +phase rotation whose controlled version is the QFT circuit's conditional rotation. -/ +noncomputable def qftRk (k : ℕ) : Matrix (Fin 2) (Fin 2) ℂ := + !![1, 0; 0, Complex.exp (2 * Real.pi * Complex.I / 2 ^ k)] + +/-- **`Rₖ` is unitary.** It is diagonal with entries `1` and the unit-modulus phase `e^{2πi/2^k}`; +concretely `conj(e^{2πi/2^k})·e^{2πi/2^k} = e^{-z}·e^{z} = 1` because the exponent `z = 2πi/2^k` is +purely imaginary (`conj z = -z`). -/ +theorem qftRk_mem_unitaryGroup (k : ℕ) : qftRk k ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + rw [Matrix.mem_unitaryGroup_iff'] + have hz : (starRingEnd ℂ) (2 * (Real.pi : ℂ) * Complex.I / 2 ^ k) + = -(2 * Real.pi * Complex.I / 2 ^ k) := by + simp only [map_div₀, map_mul, Complex.conj_I, map_ofNat, Complex.conj_ofReal, map_pow]; ring + have hφ : (starRingEnd ℂ) (Complex.exp (2 * Real.pi * Complex.I / 2 ^ k)) + * Complex.exp (2 * Real.pi * Complex.I / 2 ^ k) = 1 := by + rw [← Complex.exp_conj, ← Complex.exp_add, hz, neg_add_cancel, Complex.exp_zero] + ext i j + fin_cases i <;> fin_cases j <;> + simp [qftRk, Matrix.mul_apply, Fin.sum_univ_two, Matrix.star_apply, hφ] + +/-- **The Hadamard gate on wire `t`** of the `n`-qubit register — the parameter-free gate that +opens each block of Figure 5.1 (`singleQubitOnWire` with the complex Hadamard `hadamardC`). -/ +noncomputable def qftHadamardGate (n : ℕ) (t : Fin n) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + singleQubitOnWire finFunctionFinEquiv t hadamardC + +/-- **The controlled-`Rₖ` gate from control wire `c` onto target wire `t`** (Figure 5.1's +conditional rotation): apply `R_{(c-t)+1}` to wire `t` when wire `c` is `1`. A control at distance +`d = c - t` carries `R_{d+1}`, so the nearest control `c = t+1` carries `R₂`, and the cascade over +`c = t+1, …, n-1` reproduces the `R₂ … R_{n-t}` rotations N&C apply to wire `t`. -/ +noncomputable def qftControlledGate (n : ℕ) (t c : Fin n) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + mcCtrlSingleQubit finFunctionFinEquiv {c} t (qftRk ((c : ℕ) - (t : ℕ) + 1)) + +/-- **The control wires of target `t`:** the later wires `t+1, …, n-1`, obtained by dropping the +first `t+1` wires of `List.finRange n`. -/ +def qftTargetControls (n : ℕ) (t : Fin n) : List (Fin n) := + (List.finRange n).drop ((t : ℕ) + 1) + +/-- Target `t` has `n - 1 - t` control wires — the `n - t` wires above `t` less the wire `t` itself +(`List.length_drop` on `List.finRange`). -/ +theorem length_qftTargetControls (n : ℕ) (t : Fin n) : + (qftTargetControls n t).length = n - 1 - (t : ℕ) := by + rw [qftTargetControls, List.length_drop, List.length_finRange]; omega + +/-- **The controlled-`Rₖ` cascade of target `t`'s block:** the controlled gates from each of `t`'s +control wires, in order. Concatenated over all targets, these are the circuit's `qftControlledGates` +(the perturbable gates of Exercise 5.6). -/ +noncomputable def qftBlockControlledGates (n : ℕ) (t : Fin n) : + List (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ) := + (qftTargetControls n t).map (qftControlledGate n t) + +/-- **Target `t`'s Figure-5.1 block:** the Hadamard on wire `t`, followed by its controlled-`Rₖ` +cascade. -/ +noncomputable def qftBlock (n : ℕ) (t : Fin n) : List (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ) := + qftHadamardGate n t :: qftBlockControlledGates n t + +/-- **The wire-reversal permutation** realised by the swap layer at the end of Figure 5.1: it +reverses the order of the `n` wires (`f ↦ f ∘ Fin.rev`). -/ +def qftBitReversal (n : ℕ) : Equiv.Perm (Fin n → Fin 2) := + Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin 2)) + +/-- **The full ordered gate list of the Figure 5.1 QFT circuit:** the wire-reversal (swap) gate, +then each target's block in order `t = 0, 1, …, n-1`. The list is in **circuit/time order** — the +gate applied first appears first, so the swap layer acts first. Under the little-endian encoding +(`finFunctionFinEquiv`, wire `0` least significant) the blocks process wire `0` first with controls +from the higher wires; applying the wire reversal at the *input* (rather than the output, as a +big-endian drawing of Figure 5.1 would) is what lands the circuit on the little-endian +`qftMatrix 2ⁿ` (the module docstring's endianness note; certified `qftGateCircuit 2 = qftMatrix 4` +in `AxQM/Concrete/QftGateCircuitCorrectness.lean`). The controlled-`Rₖ` gates — Exercise 5.6's +entire content — are unaffected by the swap's position. -/ +noncomputable def qftGateSequence (n : ℕ) : List (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ) := + permGate finFunctionFinEquiv (qftBitReversal n) :: (List.finRange n).flatMap (qftBlock n) + +/-- **The gate-level Figure 5.1 QFT circuit** as a `2ⁿ × 2ⁿ` matrix: the product of +`qftGateSequence` in reverse, so that as an operator the first-listed gate acts first +(`(g₁ :: … :: gₘ).reverse.prod = gₘ * … * g₁`). Reusing the wire-gate framework, this is a fully +explicit unitary computing the quantum Fourier transform (its equality to `qftMatrix 2ⁿ` is the +next step of the Exercise 5.6 arc). -/ +noncomputable def qftGateCircuit (n : ℕ) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ := + (qftGateSequence n).reverse.prod + +/-- **Every gate of the Figure 5.1 QFT circuit is unitary** (Nielsen & Chuang, p. 219: "each gate in +the circuit is unitary"): the swap permutation (`permGate_mem_unitaryGroup`), the Hadamards +(`singleQubitOnWire_mem_unitaryGroup`, `hadamardC_mem_unitaryGroup`), and the controlled rotations +(`mcCtrlSingleQubit_mem_unitaryGroup`, `qftRk_mem_unitaryGroup`). This is the reusable per-factor +obligation: the circuit's own unitarity (`qftGateCircuit_mem_unitaryGroup`) and the chaining bound +of Exercise 5.6 (`qftGateCircuit_sub_qftGateCircuitPerturbed_norm_le`) both consume it. -/ +theorem qftGateSequence_forall_mem_unitaryGroup (n : ℕ) : + ∀ g ∈ qftGateSequence n, g ∈ Matrix.unitaryGroup (Fin (2 ^ n)) ℂ := by + intro g hg + rw [qftGateSequence, List.mem_cons] at hg + rcases hg with rfl | hg + · exact permGate_mem_unitaryGroup _ _ + · rw [List.mem_flatMap] at hg + obtain ⟨t, _, hgt⟩ := hg + rw [qftBlock, List.mem_cons] at hgt + rcases hgt with rfl | hmap + · exact singleQubitOnWire_mem_unitaryGroup _ _ hadamardC_mem_unitaryGroup + · rw [qftBlockControlledGates, List.mem_map] at hmap + obtain ⟨c, _, rfl⟩ := hmap + exact mcCtrlSingleQubit_mem_unitaryGroup _ _ _ (qftRk_mem_unitaryGroup _) + +/-- **The QFT circuit is unitary** (Nielsen & Chuang, p. 219): the reverse product of the gate list +`qftGateSequence`, whose every factor is unitary (`qftGateSequence_forall_mem_unitaryGroup`), lies +in the unitary group (`Submonoid.list_prod_mem`). -/ +theorem qftGateCircuit_mem_unitaryGroup (n : ℕ) : + qftGateCircuit n ∈ Matrix.unitaryGroup (Fin (2 ^ n)) ℂ := + Submonoid.list_prod_mem _ fun g hg => + qftGateSequence_forall_mem_unitaryGroup n g (List.mem_reverse.mp hg) + +/-- **The controlled-`Rₖ` gates of the QFT circuit:** every block's controlled cascade, concatenated +over the targets `t = 0, …, n-1`. These are exactly the gates carrying a continuous phase parameter +(the Hadamards and the swap are parameter-free), hence the ones Exercise 5.6 implements to finite +precision `Δ`. -/ +noncomputable def qftControlledGates (n : ℕ) : List (Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ) := + (List.finRange n).flatMap (qftBlockControlledGates n) + +/-- **The QFT circuit has `n(n-1)/2` controlled-`Rₖ` gates** (Nielsen & Chuang, Figure 5.1 count): +`(qftControlledGates n).length = qftControlledRkCount n`. Target `t` contributes its `n-1-t` +controls (`length_qftTargetControls`), and `∑_{t n - 1 - i) n, + Finset.sum_range_reflect (fun i => i) n] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftGateCircuitCorrectness.lean b/LeanPool/AxQM/Concrete/QftGateCircuitCorrectness.lean new file mode 100644 index 0000000000..d9f27341a8 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftGateCircuitCorrectness.lean @@ -0,0 +1,264 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QftGateCircuit +public import LeanPool.AxQM.Concrete.QuantumFourierTransform + +/-! +# Concrete: the QFT circuit's controlled-`Rₖ` cascade is a diagonal phase gate (N&C eqs. 5.5–5.6) + +Building toward the correctness of the gate-level Figure 5.1 circuit +(`Concrete.qftGateCircuit n = qftMatrix 2ⁿ`, N&C eqs. 5.12–5.18), this file establishes the first +structural step: **the controlled-`Rₖ` rotations acting on a wire are simultaneously diagonal in the +computational basis, so a whole block's cascade collapses to a single diagonal phase gate** — the +map (N&C eqs. 5.5–5.6) that appends the binary-fraction tail `0.j_{t+1}…j_{n-1}` to the phase of +wire `t`. + +Each Figure 5.1 conditional rotation `qftControlledGate n t c` applies `Rₖ = diag(1, e^{2πi/2ᵏ})` +(itself diagonal) to target wire `t` conditioned on control wire `c`, so it is *control-diagonal*: +it multiplies the basis state `|enc x⟩` by the phase `e^{2πi/2^{c-t+1}}` exactly when both `x_c = 1` +and `x_t = 1`, and by `1` otherwise. Because diagonal matrices commute and their product is the +pointwise product of their diagonals, the target-`t` cascade `qftBlockControlledGates n t` — the +rotations from all of `t`'s control wires — is again a single diagonal gate, whose phase on +`|enc x⟩` is the product over the active controls, `∏_{c > t, x_c = 1} e^{2πi/2^{c-t+1}}` (present +only when `x_t = 1`). + +The general fact that a subset-controlled *diagonal* single-qubit gate is diagonal +(`mcCtrlSingleQubit_diagonal`, generalising `mcCtrlSingleQubit_smul_one_eq_diagonal` from a global +phase `z • 1` to an arbitrary diagonal block) lives with the rest of the `mcCtrlSingleQubit` family +in `AxQM/Concrete/MultiControlledSingleQubit.lean`; this file consumes it. + +## What is formalised + +* `diagonal_map_prod` — a list-indexed family of diagonal matrices multiplies to the diagonal of the + entrywise list product of the diagonals (general `Matrix` algebra). +* `qftRk_eq_diagonal` — `Rₖ = diagonal ![1, e^{2πi/2ᵏ}]`. +* `qftTargetControls_lt` — a target's control wires all lie strictly above it. +* `qftControlledGate_eq_diagonal` — the Figure 5.1 controlled rotation from `c` onto `t` (`t ≠ c`) + is the diagonal gate `diag(fun i => if x_c = 1 then ![1, e^{2πi/2^{c-t+1}}] (x_t) else 1)`. +* `qftBlockControlledGates_prod_eq_diagonal` — target `t`'s whole controlled cascade is the single + diagonal phase gate `diag(fun i => if x_t = 1 then ∏_{c ∈ controls, x_c = 1} e^{2πi/2^{c-t+1}} + else 1)`. + +Composing this cascade with the block-opening Hadamard, then the +inter-block interleave and the final bit reversal, identifies the circuit with `qftMatrix 2ⁿ`. + +## Setting + +Every statement is about complex matrices (`Matrix`, `Matrix.diagonal`), the encoding +equivalence `finFunctionFinEquiv`, and the circuit objects of `AxQM/Concrete/QftGateCircuit.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **A product of diagonal matrices built from a list is diagonal**, with the entrywise list +product of their diagonals: `∏_{c ∈ l} diagonal (g c) = diagonal (fun i => ∏_{c ∈ l} g c i)` — the +list-product form of the fact that `Matrix.diagonal` is a multiplicative homomorphism. -/ +theorem diagonal_map_prod {ι : Type*} (l : List ι) (g : ι → Fin d → ℂ) : + (l.map fun c => Matrix.diagonal (g c)).prod + = Matrix.diagonal fun i => (l.map fun c => g c i).prod := by + induction l with + | nil => simp + | cons a l ih => + rw [List.map_cons, List.prod_cons, ih, Matrix.diagonal_mul_diagonal] + refine congrArg Matrix.diagonal (funext fun i => ?_) + rw [List.map_cons, List.prod_cons] + +/-- **The `Rₖ` phase gate is diagonal**: `qftRk k = diagonal ![1, e^{2πi/2ᵏ}]` (N&C eq. 5.11 in +diagonal form). -/ +theorem qftRk_eq_diagonal (k : ℕ) : + qftRk k = Matrix.diagonal ![1, Complex.exp (2 * Real.pi * Complex.I / 2 ^ k)] := by + rw [qftRk, Matrix.diagonal_fin_two] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] + +/-- **The control wires of target `t` all lie strictly above `t`.** If `c` controls target `t` in +the Figure 5.1 circuit (`c ∈ qftTargetControls n t`, the wires `t+1, …, n-1`), then `t < c`; in +particular `t ≠ c`, so `t` is not among its own controls. -/ +theorem qftTargetControls_lt {n : ℕ} {t c : Fin n} (hc : c ∈ qftTargetControls n t) : + (t : ℕ) < (c : ℕ) := by + rw [qftTargetControls, List.mem_iff_getElem] at hc + obtain ⟨k, hk, hck⟩ := hc + rw [List.getElem_drop, List.getElem_finRange] at hck + have h2 := congrArg Fin.val hck + simp only [Fin.val_cast] at h2 + omega + +/-- **Each Figure 5.1 conditional rotation is a diagonal phase gate.** For `t ≠ c`, the +controlled-`Rₖ` gate from control wire `c` onto target wire `t` is +`diagonal (fun i => if x_c = 1 ∧ x_t = 1 then e^{2πi/2^{c-t+1}} else 1)`: it multiplies `|enc x⟩` by +the rotation phase `e^{2πi/2^{c-t+1}}` exactly when both the control bit `x_c` and the target bit +`x_t` are `1`, and by `1` otherwise (`mcCtrlSingleQubit_diagonal` on the diagonal block `Rₖ`). -/ +theorem qftControlledGate_eq_diagonal (n : ℕ) (t c : Fin n) (htc : t ≠ c) : + qftControlledGate n t c = Matrix.diagonal fun i => + if finFunctionFinEquiv.symm i c = 1 ∧ finFunctionFinEquiv.symm i t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1 := by + rw [qftControlledGate, qftRk_eq_diagonal, + mcCtrlSingleQubit_diagonal _ (by simpa using htc)] + refine congrArg Matrix.diagonal (funext fun i => ?_) + simp only [Finset.mem_singleton, forall_eq] + by_cases hc : finFunctionFinEquiv.symm i c = 1 + · rw [ite_eq_left hc] + generalize finFunctionFinEquiv.symm i t = v + fin_cases v <;> simp [hc] + · rw [ite_eq_right hc] + simp [hc] + +/-- **Target `t`'s controlled-`Rₖ` cascade is a single diagonal phase gate** (N&C eqs. 5.5–5.6). +The product of all of target `t`'s conditional rotations is the diagonal gate whose phase on +`|enc x⟩` is the product, over `t`'s control wires `c`, of `e^{2πi/2^{c-t+1}}` for each active +control (`x_c = 1`) when the target bit `x_t = 1` is set — collapsing the whole rotation cascade of +Figure 5.1's block to one diagonal matrix. Every factor is diagonal +(`qftControlledGate_eq_diagonal`, each control wire lying above `t` by `qftTargetControls_lt`), and +diagonals multiply pointwise (`diagonal_map_prod`). -/ +theorem qftBlockControlledGates_prod_eq_diagonal (n : ℕ) (t : Fin n) : + (qftBlockControlledGates n t).prod = Matrix.diagonal fun i => + ((qftTargetControls n t).map fun c => + if finFunctionFinEquiv.symm i c = 1 ∧ finFunctionFinEquiv.symm i t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod := by + rw [qftBlockControlledGates, + List.map_congr_left fun c hc => qftControlledGate_eq_diagonal n t c + (Fin.ne_of_val_ne (ne_of_lt (qftTargetControls_lt hc))), + diagonal_map_prod] + +/-! +## Correctness certificate: the two-qubit circuit computes the transform + +Beyond the structural cascade lemma above, we certify that the gate circuit actually *equals* the +Fourier matrix in the smallest nontrivial case, `n = 2`: `qftGateCircuit 2 = qftMatrix 4`. Under the +little-endian encoding this is the two-qubit circuit — the wire reversal, then `H₀`, the controlled +`R₂` from wire `1` onto wire `0`, and `H₁` — reproducing `Fₖⱼ = ½·iʲᵏ` exactly. The computation +proceeds by rewriting each of the four elementary gates to its explicit `4 × 4` matrix and +multiplying. + +This is the certificate that fixes the *endianness convention* of `qftGateSequence`: the wire +reversal is applied **first** (`qftGateSequence = swap :: blocks`), which is precisely what lands +the circuit on the little-endian `qftMatrix 4` — applying it last would instead give `P·qftMatrix·P` +(the transform conjugated by the bit reversal). The general-`n` identity +`qftGateCircuit n = qftMatrix 2ⁿ` (N&C eqs. 5.12–5.18) is proved in +`AxQM/Concrete/QftGateCircuitEqMatrix.lean`, built on this cascade lemma and the product +representation `qftMatrix_apply_eq_prod_wirePhase`. -/ + +/-- **The little-endian basis-decode table on `Fin (2²)`:** bit `j` of index `i` is +`![![0, 0], ![1, 0], ![0, 1], ![1, 1]] i j` — i.e. `0 ↦ (0,0), 1 ↦ (1,0), 2 ↦ (0,1), 3 ↦ (1,1)` +(wire `0` least significant). A finite decidable table shared by the two-qubit gate-literal proofs +below, replacing the per-gate inline decode facts. Stated in the fully-applied +`finFunctionFinEquiv.symm i j` form and over `Fin (2 ^ 2)` (the register index type produced by +`singleQubitOnWire`) so that it matches those goals; it is applied through `simp only` (the default +simp set otherwise pre-empts the rewrite). -/ +private theorem finFunctionFinEquiv_symm_fin_four (i : Fin (2 ^ 2)) (j : Fin 2) : + finFunctionFinEquiv.symm i j = ![![0, 0], ![1, 0], ![0, 1], ![1, 1]] i j := by + decide +revert + +/-- The Hadamard on wire `0` of the two-qubit register as an explicit `4 × 4` matrix (block-diagonal +over the wire-`1` value, in the little-endian basis order `00, 10, 01, 11`). -/ +private theorem qftHadamardGate_two_zero : + qftHadamardGate 2 0 = (Real.sqrt 2 : ℂ)⁻¹ • + !![1, 1, 0, 0; 1, -1, 0, 0; 0, 0, 1, 1; 0, 0, 1, -1] := by + rw [qftHadamardGate]; ext i j + fin_cases i <;> fin_cases j <;> + (simp only [singleQubitOnWire_apply, Fin.forall_fin_two, finFunctionFinEquiv_symm_fin_four]; + simp [hadamardC]) + +/-- The Hadamard on wire `1` of the two-qubit register as an explicit `4 × 4` matrix. -/ +private theorem qftHadamardGate_two_one : + qftHadamardGate 2 1 = (Real.sqrt 2 : ℂ)⁻¹ • + !![1, 0, 1, 0; 0, 1, 0, 1; 1, 0, -1, 0; 0, 1, 0, -1] := by + rw [qftHadamardGate]; ext i j + fin_cases i <;> fin_cases j <;> + (simp only [singleQubitOnWire_apply, Fin.forall_fin_two, finFunctionFinEquiv_symm_fin_four]; + simp [hadamardC]) + +/-- The controlled-`R₂` gate from wire `1` onto wire `0` as an explicit `4 × 4` matrix: the diagonal +phase gate multiplying the `|11⟩` amplitude by `e^{2πi/4} = i`. -/ +private theorem qftControlledGate_two : + qftControlledGate 2 0 1 = !![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, Complex.I] := by + have hI : Complex.exp + (2 * Real.pi * Complex.I / 2 ^ (((1 : Fin 2) : ℕ) - ((0 : Fin 2) : ℕ) + 1)) = Complex.I := by + rw [show (((1 : Fin 2) : ℕ) - ((0 : Fin 2) : ℕ) + 1) = 2 from by decide, + show (2 * (Real.pi : ℂ) * Complex.I / 2 ^ 2) = ((Real.pi / 2 : ℝ) : ℂ) * Complex.I by + push_cast; ring, Complex.exp_mul_I] + simp + rw [qftControlledGate_eq_diagonal 2 0 1 (by decide)] + simp only [hI] + ext i j + fin_cases i <;> fin_cases j <;> + (simp only [Matrix.diagonal_apply, finFunctionFinEquiv_symm_fin_four]; simp) + +/-- The two-qubit wire-reversal (swap) gate as an explicit `4 × 4` permutation matrix: it swaps the +basis states `|10⟩` and `|01⟩` (indices `1` and `2`). -/ +private theorem qftBitReversal_two_permGate : + permGate finFunctionFinEquiv (qftBitReversal 2) + = !![1, 0, 0, 0; 0, 0, 1, 0; 0, 1, 0, 0; 0, 0, 0, 1] := by + -- The reversal permutation of the basis indices is `0 ↦ 0, 1 ↦ 2, 2 ↦ 1, 3 ↦ 3`. + have hσ : ∀ k : Fin 4, finFunctionFinEquiv (qftBitReversal 2 (finFunctionFinEquiv.symm k)) + = ![0, 2, 1, 3] k := by decide + ext i j + fin_cases i <;> fin_cases j <;> simp [permGate_apply, hσ] + +/-- The two-qubit gate circuit as the ordered matrix product `H₁ · R₂ · H₀ · swap` (the wire +reversal applied first, per `qftGateSequence`). -/ +private theorem qftGateCircuit_two_eq_prod : + qftGateCircuit 2 = qftHadamardGate 2 1 * qftControlledGate 2 0 1 * qftHadamardGate 2 0 + * permGate finFunctionFinEquiv (qftBitReversal 2) := by + rw [qftGateCircuit, qftGateSequence] + have h : (List.finRange 2).flatMap (qftBlock 2) + = [qftHadamardGate 2 0, qftControlledGate 2 0 1, qftHadamardGate 2 1] := by + simp [List.finRange, qftBlock, qftBlockControlledGates, qftTargetControls, List.flatMap] + rw [h] + simp only [List.reverse_cons, List.reverse_nil, List.nil_append, List.cons_append, + List.prod_cons, List.prod_nil, mul_one, mul_assoc] + +/-- **The two-qubit gate circuit computes the quantum Fourier transform:** +`qftGateCircuit 2 = qftMatrix 4` (Nielsen & Chuang §5.1, the `n = 2` case of the circuit +correctness). Rewriting each of the four elementary gates to its explicit `4 × 4` matrix, the +ordered product `H₁ · R₂ · H₀ · swap` (wire reversal first) reproduces `Fₖⱼ = ½·iʲᵏ` exactly — the +Fourier matrix, not its bit-reversal conjugate. This certifies the swap-first convention of +`qftGateSequence` and is the base case of `qftGateCircuit n = qftMatrix 2ⁿ`. -/ +theorem qftGateCircuit_two_eq_qftMatrix : qftGateCircuit 2 = qftMatrix 4 := by + -- `½ = (√2)⁻¹ · (√2)⁻¹`, the two Hadamard normalisations combining. + have hsqrt : (Real.sqrt 2 : ℂ)⁻¹ * (Real.sqrt 2 : ℂ)⁻¹ = 2⁻¹ := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num)]; norm_num + -- The four elementary gates (integer/`i` parts) multiply to the Fourier matrix's `iʲᵏ` table. + have hprod : (!![1, 0, 1, 0; 0, 1, 0, 1; 1, 0, -1, 0; 0, 1, 0, -1] : Matrix (Fin 4) (Fin 4) ℂ) + * !![1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, Complex.I] + * !![1, 1, 0, 0; 1, -1, 0, 0; 0, 0, 1, 1; 0, 0, 1, -1] + * !![1, 0, 0, 0; 0, 0, 1, 0; 0, 1, 0, 0; 0, 0, 0, 1] + = !![1, 1, 1, 1; + 1, Complex.I, -1, -Complex.I; + 1, -1, 1, -1; + 1, -Complex.I, -1, Complex.I] := by + ext i j; fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_four] + -- `qftMatrix 4` in the same explicit form: `½ · iʲᵏ`. + have hR : qftMatrix 4 = (2 : ℂ)⁻¹ • + !![1, 1, 1, 1; + 1, Complex.I, -1, -Complex.I; + 1, -1, 1, -1; + 1, -Complex.I, -1, Complex.I] := by + have hroot : qftPrimitiveRoot 4 = Complex.I := by + rw [qftPrimitiveRoot, Nat.cast_ofNat, show (2 * (Real.pi : ℂ) * Complex.I / 4) + = ((Real.pi / 2 : ℝ) : ℂ) * Complex.I by push_cast; ring, Complex.exp_mul_I] + simp + have h4 : (Real.sqrt 4 : ℂ) = 2 := by + rw [show (4 : ℝ) = 2 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)]; norm_num + ext i j + fin_cases i <;> fin_cases j <;> + simp [qftMatrix, hroot, h4, Matrix.smul_apply, pow_succ, Complex.I_mul_I] + rw [qftGateCircuit_two_eq_prod, qftHadamardGate_two_one, qftControlledGate_two, + qftHadamardGate_two_zero, qftBitReversal_two_permGate, hR] + simp only [Matrix.smul_mul, Matrix.mul_smul, smul_smul] + rw [hsqrt, hprod] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftGateCircuitEqMatrix.lean b/LeanPool/AxQM/Concrete/QftGateCircuitEqMatrix.lean new file mode 100644 index 0000000000..2159e87eb7 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftGateCircuitEqMatrix.lean @@ -0,0 +1,269 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QftGateCircuitState +public import LeanPool.AxQM.Concrete.QftProductRepresentation + +/-! +# Concrete: the Figure 5.1 QFT circuit computes the transform (`qftGateCircuit n = qftMatrix 2ⁿ`) + +This file completes the correctness of the gate-level Figure 5.1 quantum-Fourier-transform circuit, +Nielsen & Chuang eqs. 5.12–5.18: the explicit gate product `Concrete.qftGateCircuit n` **equals** +the Fourier matrix `qftMatrix 2ⁿ`. It closes the arc begun in `AxQM/Concrete/QftGateCircuit.lean` +(the circuit as a matrix product), `AxQM/Concrete/QftGateCircuitCorrectness.lean` (each +controlled-`Rₖ` cascade is diagonal; the `n = 2` certificate), and +`AxQM/Concrete/QftGateCircuitState.lean` (the block sequence maps a basis input to the product state +`qftPartialState`). + +## The remaining step + +`AxQM/Concrete/QftGateCircuitState.lean` proved `qftBlocksProd_mulVec_basis`: the block sequence +(Hadamards + controlled-`Rₖ` cascades, **without** the swap layer) sends `|enc a⟩` to the explicit +product state `qftPartialState n a n = (1/√2ⁿ) ∏ₜ (qftBlockPhase n a t)^{kₜ}`. Two things remain to +match this to `qftMatrix`: + +* **The bit-reversal.** `qftGateSequence` applies the wire-reversal permutation **first** + (`qftGateCircuit = (blocks).reverse.prod · P`, the swap-first convention fixed by the `n = 2` + certificate), so on `|enc jbits⟩` the blocks act on `a = qftBitReversal n jbits` (bits read in + reverse, `a s = jbits (Fin.rev s)`). `permGate_mulVec_single` turns the swap into that reindex. +* **The reversal identity** `qftBlockPhase_qftBitReversal`: the circuit's block phase on the + reversed input equals the matrix's wire phase, `qftBlockPhase n (qftBitReversal n jbits) t = + qftWirePhase n (finFunctionFinEquiv jbits) t`. Its two-line heart is that the block phase + accumulates the binary fraction `0.jₜ₋₁…j₀` on wire `t` from the *low* input bits, while the + matrix's wire phase `e^{2πi j 2ᵗ/2ⁿ}` is `2πi`-periodic in the *high* bits — so, factor by factor + under the `Fin.rev` reindex, the two agree (the discarded high-bit factors are `e^{2πi·ℤ} = 1`). + +`qftBlockPhase_eq_prod` and `qftWirePhase_eq_prod` rewrite each phase as a single `Finset.univ` +product of unit-modulus exponentials, and the identity is then a per-factor `Fin.rev` matching. +Feeding these into `qftBlocksProd_mulVec_basis` and matching the normalisation +(`(1/√2)ⁿ = 1/√2ⁿ`, `sqrt_two_pow_inv`) gives, column by column, +`qftGateCircuit n *ᵥ |j⟩ = qftMatrix 2ⁿ *ᵥ |j⟩` (`qftGateCircuit_mulVec_basis`), hence the matrix +equality `qftGateCircuit_eq_qftMatrix`. + +## Why this file exists (Exercise 5.6) + +The faithful `Ω(n²/p(n))` lower bound of Exercise 5.6 perturbs the circuit's controlled-`Rₖ` gates, +and needs the identification of the gate product with the transform to compare the perturbed circuit +against the ideal `qftEvolution`. This file supplies exactly that identification; the reversal +identity and the `blocks · swap` decomposition (`qftGateCircuit_eq_blocks_mul_perm`) are the +reusable hooks the perturbation argument builds on. + +## Setting + +Every statement is about complex matrices/vectors (`Matrix`, `Matrix.mulVec`, `Pi.single`, +`qftMatrix`, `qftGateCircuit`), the encoding equivalence `finFunctionFinEquiv`, permutations, and +the phase scalars of the circuit. +-/ + +@[expose] public section + +open scoped Matrix + +namespace AxQM.Concrete + +open Matrix Finset + +/-- Both values of `Fin 2` are `0` or `1` — the case split used in the phase algebra below. -/ +private theorem fin_two_eq_zero_or_one' (x : Fin 2) : x = 0 ∨ x = 1 := by decide +revert + +/-- **The Hadamard sign as a phase** (Nielsen & Chuang eq. 5.6, wire `t`'s own contribution): +`(-1)^{v} = e^{2πi·v/2}` for a bit `v : Fin 2`. The `s = t` factor of the block phase, matching the +distance-`0` control convention `2^{(t-t)+1} = 2`. -/ +theorem neg_one_pow_eq_exp (v : Fin 2) : + (-1 : ℂ) ^ (v : ℕ) + = Complex.exp (2 * Real.pi * Complex.I * (v : ℕ) / 2 ^ (1 : ℕ)) := by + have hv : (v : ℕ) = 0 ∨ (v : ℕ) = 1 := by have := v.isLt; omega + rcases hv with h | h <;> rw [h] + · simp + · rw [pow_one, show (2 * (Real.pi : ℂ) * Complex.I * ((1 : ℕ) : ℂ) / 2 ^ (1 : ℕ)) + = Real.pi * Complex.I from by push_cast; ring, Complex.exp_pi_mul_I] + +/-- Target `t`'s control wires form a duplicate-free list (a sublist of `List.finRange n`). -/ +theorem qftTargetControls_nodup (n : ℕ) (t : Fin n) : (qftTargetControls n t).Nodup := by + rw [qftTargetControls]; exact (List.nodup_finRange n).drop + +/-- **Target `t`'s control wires, as a `Finset`, are the wires strictly above `t`:** +`(qftTargetControls n t).toFinset = {c | t < c}`. Used to turn the block's controlled-`Rₖ` cascade +(a list product) into a `Finset` product for the reversal identity. -/ +theorem qftTargetControls_toFinset (n : ℕ) (t : Fin n) : + (qftTargetControls n t).toFinset + = Finset.univ.filter (fun c : Fin n => (t : ℕ) < (c : ℕ)) := by + ext c + simp only [List.mem_toFinset, Finset.mem_filter, Finset.mem_univ, true_and] + rw [qftTargetControls, List.mem_iff_getElem] + constructor + · rintro ⟨i, hi, rfl⟩ + rw [List.getElem_drop, List.getElem_finRange]; simp only [Fin.val_cast]; omega + · intro h + refine ⟨(c : ℕ) - (t + 1), ?_, ?_⟩ + · rw [List.length_drop, List.length_finRange]; omega + · rw [List.getElem_drop, List.getElem_finRange]; apply Fin.ext + simp only [Fin.val_cast]; omega + +/-- **The block phase as a single `Finset.univ` product of unit-modulus phases** (Nielsen & Chuang +eqs. 5.5–5.6). Uniting the block-opening Hadamard (wire `t`, `s = t`) and the controlled-`Rₖ` +cascade (`s > t`), every wire `s ≥ t` contributes the factor `e^{2πi·aₛ/2^{s-t+1}}`, and the wires +`s < t` contribute `1`: +`qftBlockPhase n a t = ∏ₛ (if t ≤ s then e^{2πi·aₛ/2^{s-t+1}} else 1)`. -/ +theorem qftBlockPhase_eq_prod (n : ℕ) (a : Fin n → Fin 2) (t : Fin n) : + qftBlockPhase n a t + = ∏ s : Fin n, (if (t : ℕ) ≤ (s : ℕ) + then Complex.exp (2 * Real.pi * Complex.I * (a s : ℕ) / 2 ^ ((s : ℕ) - (t : ℕ) + 1)) + else 1) := by + rw [← Finset.prod_filter] + rw [show (Finset.univ.filter (fun s : Fin n => (t : ℕ) ≤ (s : ℕ))) + = insert t (Finset.univ.filter (fun s : Fin n => (t : ℕ) < (s : ℕ))) from by + ext s + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Fin.ext_iff] + omega] + rw [Finset.prod_insert (by + simp only [Finset.mem_filter, Finset.mem_univ, true_and]; omega)] + rw [qftBlockPhase] + congr 1 + · rw [Nat.sub_self, zero_add] + exact neg_one_pow_eq_exp (a t) + · rw [← List.prod_toFinset _ (qftTargetControls_nodup n t), qftTargetControls_toFinset] + apply Finset.prod_congr rfl + intro c _ + rcases fin_two_eq_zero_or_one' (a c) with h | h <;> rw [h] <;> simp + +/-- **The wire phase as a single `Finset.univ` product** over the input bits (Nielsen & Chuang eq. +5.4). Expanding `j = ∑ₛ jbitsₛ 2ˢ` in the output-phase exponent factorises `qftWirePhase` over the +input wires: `qftWirePhase n (finFunctionFinEquiv jbits) t = ∏ₛ e^{2πi·jbitsₛ·2^{s+t}/2ⁿ}`. -/ +theorem qftWirePhase_eq_prod (n : ℕ) (jbits : Fin n → Fin 2) (t : Fin n) : + qftWirePhase n (finFunctionFinEquiv jbits) t + = ∏ s : Fin n, Complex.exp + (2 * Real.pi * Complex.I * ((jbits s : ℕ) * 2 ^ ((s : ℕ) + (t : ℕ))) + / (2 ^ n : ℕ)) := by + rw [qftWirePhase, ← Complex.exp_sum] + congr 1 + have hj : (((finFunctionFinEquiv jbits : Fin (2 ^ n)) : ℕ) : ℂ) + = ∑ s, ((jbits s : ℕ) : ℂ) * 2 ^ (s : ℕ) := by + rw [finFunctionFinEquiv_apply_val]; push_cast; ring + rw [hj, Finset.sum_mul, Finset.mul_sum, Finset.sum_div] + apply Finset.sum_congr rfl + intro s _ + rw [pow_add] + push_cast + ring + +/-- **The wire-reversal permutation reverses the bit string:** `qftBitReversal n jbits s = +jbits (Fin.rev s)` — the swap layer sends wire `s` to wire `Fin.rev s = n-1-s`. -/ +theorem qftBitReversal_apply (n : ℕ) (jbits : Fin n → Fin 2) (s : Fin n) : + qftBitReversal n jbits s = jbits (Fin.rev s) := by + simp only [qftBitReversal, Equiv.arrowCongr_apply, Function.comp_apply, + Equiv.refl_apply, Fin.revPerm_symm, Fin.revPerm_apply] + +/-- **The reversal identity** (Nielsen & Chuang eqs. 5.4–5.6, the heart of Figure 5.1's +correctness): the Figure 5.1 block phase acquired by wire `t` on the **reversed** input +`qftBitReversal n jbits` +equals the quantum-Fourier-transform matrix's single-qubit output phase on wire `t`, +`qftBlockPhase n (qftBitReversal n jbits) t = qftWirePhase n (finFunctionFinEquiv jbits) t`. + +Both phases are products over the `n` wires of unit-modulus exponentials (`qftBlockPhase_eq_prod`, +`qftWirePhase_eq_prod`). Reindexing the block product by `Fin.rev`, the block's factor for wire +`Fin.rev s'` (present only when `t ≤ n-1-s'`, i.e. `s' + t < n`) is `e^{2πi·jbitsₛ'/2^{n-s'-t}}`, +which equals the wire's factor `e^{2πi·jbitsₛ'·2^{s'+t}/2ⁿ}` in that same range; and when +`s' + t ≥ n` the block factor is `1` while the wire factor is `e^{2πi·(integer)} = 1` by +`2πi`-periodicity (`Complex.exp_nat_mul_two_pi_mul_I`). So the two agree factor by factor. -/ +theorem qftBlockPhase_qftBitReversal (n : ℕ) (jbits : Fin n → Fin 2) (t : Fin n) : + qftBlockPhase n (qftBitReversal n jbits) t + = qftWirePhase n (finFunctionFinEquiv jbits) t := by + rw [qftBlockPhase_eq_prod, qftWirePhase_eq_prod, ← Equiv.prod_comp Fin.revPerm] + apply Finset.prod_congr rfl + intro s' _ + rw [Fin.revPerm_apply, qftBitReversal_apply, Fin.rev_rev, Fin.val_rev] + by_cases h : (s' : ℕ) + (t : ℕ) < n + · rw [ite_eq_left (by omega)] + congr 1 + rw [show (n - ((s' : ℕ) + 1)) - (t : ℕ) + 1 = n - (s' : ℕ) - (t : ℕ) from by omega] + have hpow : (((2 : ℕ) ^ n : ℕ) : ℂ) + = 2 ^ ((s' : ℕ) + (t : ℕ)) * 2 ^ (n - (s' : ℕ) - (t : ℕ)) := by + push_cast; rw [← pow_add]; congr 1; omega + rw [hpow] + field_simp + · rw [ite_eq_right (by omega)] + symm + have h2 : ((2 : ℂ) ^ ((s' : ℕ) + (t : ℕ))) + = 2 ^ n * 2 ^ ((s' : ℕ) + (t : ℕ) - n) := by + rw [← pow_add]; congr 1; omega + rw [show (2 * Real.pi * Complex.I * ((jbits s' : ℕ) * 2 ^ ((s' : ℕ) + (t : ℕ))) + / (((2 : ℕ) ^ n : ℕ) : ℂ)) + = (((jbits s' : ℕ) * 2 ^ ((s' : ℕ) + (t : ℕ) - n) : ℕ) : ℂ) + * (2 * Real.pi * Complex.I) from by + push_cast + rw [h2] + field_simp] + exact Complex.exp_nat_mul_two_pi_mul_I _ + +/-- **The full product state at `m = n`** — the amplitude of `qftPartialState n a n`. Once every +block has acted, the pinned condition is vacuous and the phase product runs over all wires: +`qftPartialState n a n i = (1/√2)ⁿ · ∏ₛ (qftBlockPhase n a s)^{kₛ}` with `k = enc.symm i`. -/ +theorem qftPartialState_full (n : ℕ) (a : Fin n → Fin 2) (i : Fin (2 ^ n)) : + qftPartialState n a n i + = (Real.sqrt 2 : ℂ)⁻¹ ^ n + * ∏ s : Fin n, qftBlockPhase n a s ^ (finFunctionFinEquiv.symm i s : ℕ) := by + rw [qftPartialState, ite_eq_left (fun s hs => absurd hs (Nat.not_le.mpr s.isLt)), + Finset.filter_true_of_mem (fun s _ => s.isLt)] + +/-- The `n`-fold Hadamard normalisation equals the transform's `1/√2ⁿ`: +`(1/√2)ⁿ = 1/√(2ⁿ)`. -/ +theorem sqrt_two_pow_inv (n : ℕ) : + (Real.sqrt 2 : ℂ)⁻¹ ^ n = (Real.sqrt ((2 : ℕ) ^ n) : ℂ)⁻¹ := by + rw [inv_pow, ← Complex.ofReal_pow] + congr 2 + have hsq : ((Real.sqrt 2) ^ n) ^ 2 = ((2 : ℕ) ^ n : ℝ) := by + rw [← pow_mul, mul_comm, pow_mul, Real.sq_sqrt (by norm_num)]; push_cast; ring + rw [← hsq, Real.sqrt_sq (by positivity)] + +/-- **The Figure 5.1 gate list factors as blocks-then-swap** (the swap-first convention): +`qftGateCircuit n = (∏ blocks) · P`, where `P = permGate finFunctionFinEquiv (qftBitReversal n)` is +the wire-reversal and `∏ blocks = ((List.finRange n).flatMap (qftBlock n)).reverse.prod`. The +operator reads with the swap acting first (rightmost). Reusable for the perturbed (`Ω`) circuit, +whose blocks alone carry the perturbed `Rₖ` gates. -/ +theorem qftGateCircuit_eq_blocks_mul_perm (n : ℕ) : + qftGateCircuit n + = ((List.finRange n).flatMap (qftBlock n)).reverse.prod + * permGate finFunctionFinEquiv (qftBitReversal n) := by + rw [qftGateCircuit, qftGateSequence, List.reverse_cons, List.prod_append, List.prod_singleton] + +/-- **The circuit and the matrix agree on every basis column** (Nielsen & Chuang eqs. 5.12–5.18): +`qftGateCircuit n *ᵥ |enc jbits⟩ = qftMatrix 2ⁿ *ᵥ |enc jbits⟩`. The swap sends `|enc jbits⟩` to the +reversed input (`permGate_mulVec_single`); the block sequence maps it to the product state +`qftPartialState` (`qftBlocksProd_mulVec_basis`); and, entry by entry, that product state matches +column `enc jbits` of `qftMatrix` via the reversal identity `qftBlockPhase_qftBitReversal` (the +phases) and `sqrt_two_pow_inv` (the normalisation). -/ +theorem qftGateCircuit_mulVec_basis (n : ℕ) (jbits : Fin n → Fin 2) : + qftGateCircuit n *ᵥ Pi.single (finFunctionFinEquiv jbits) 1 + = qftMatrix (2 ^ n) *ᵥ Pi.single (finFunctionFinEquiv jbits) 1 := by + rw [qftGateCircuit_eq_blocks_mul_perm, ← Matrix.mulVec_mulVec, permGate_mulVec_single, + qftBlocksProd_mulVec_basis] + funext i + rw [qftPartialState_full, Matrix.mulVec_single_one, Matrix.col_apply] + conv_rhs => rw [show i = finFunctionFinEquiv (finFunctionFinEquiv.symm i) from + (Equiv.apply_symm_apply _ _).symm, qftMatrix_apply_eq_prod_wirePhase] + rw [sqrt_two_pow_inv] + congr 1 + · norm_cast + · exact Finset.prod_congr rfl fun s _ => by rw [qftBlockPhase_qftBitReversal] + +/-- **The gate-level Figure 5.1 circuit computes the quantum Fourier transform:** +`qftGateCircuit n = qftMatrix 2ⁿ` (Nielsen & Chuang §5.1, eqs. 5.12–5.18). Two matrices agreeing on +every standard-basis column are equal, and `qftGateCircuit_mulVec_basis` supplies exactly that +column-by-column agreement. This is the general-`n` correctness of the circuit, of which +`qftGateCircuit_two_eq_qftMatrix` was the `n = 2` certificate; it is the object the faithful +`Ω(n²/p(n))` half of Exercise 5.6 perturbs. -/ +theorem qftGateCircuit_eq_qftMatrix (n : ℕ) : qftGateCircuit n = qftMatrix (2 ^ n) := by + refine Matrix.ext_of_mulVec_single fun j => ?_ + rw [show j = finFunctionFinEquiv (finFunctionFinEquiv.symm j) from + (Equiv.apply_symm_apply _ _).symm] + exact qftGateCircuit_mulVec_basis n _ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftGateCircuitState.lean b/LeanPool/AxQM/Concrete/QftGateCircuitState.lean new file mode 100644 index 0000000000..902182c303 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftGateCircuitState.lean @@ -0,0 +1,303 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QftGateCircuitCorrectness + +/-! +# Concrete: state propagation through the Figure 5.1 QFT circuit blocks (N&C eqs. 5.5–5.10) + +Building toward the correctness of the gate-level Figure 5.1 circuit +(`Concrete.qftGateCircuit n = qftMatrix 2ⁿ`, N&C eqs. 5.12–5.18), this file computes the **action of +the block sequence on a computational-basis input** — the state-vector propagation N&C run in eqs. +5.5–5.10. The circuit `qftGateCircuit n = ((qftGateSequence n)).reverse.prod` is the wire-reversal +`permGate` followed (in circuit/time order) by each target's block +`qftBlock n t = H_t ::` (its controlled-`Rₖ` cascade). Feeding a basis state `|enc a⟩` through the +blocks (the reversal is handled separately, in the final assembly), the state after the first +`m` blocks is the explicit superposition tracked here. + +## The invariant + +`qftPartialState n a m` is the register state after processing blocks `0, …, m-1` on the input +`|enc a⟩`: wires `≥ m` are still pinned to the input bits `a`, while each processed wire `s < m` +has been Hadamard-freed and carries the block phase `qftBlockPhase n a s` on its `|1⟩` component. At +index `i` with bits `k = enc.symm i`, + +`qftPartialState n a m i = ⟦∀ s ≥ m, kₛ = aₛ⟧ · (1/√2)^m · ∏_{s < m} (qftBlockPhase n a s)^{kₛ}`. + +The **block phase** `qftBlockPhase n a t` is the phase wire `t`'s `|1⟩` amplitude acquires in its +block: the Hadamard sign `(-1)^{a_t}` times the controlled-`Rₖ` cascade +`∏_{c > t, a_c = 1} e^{2πi/2^{c-t+1}}` from the (still pinned) higher wires — N&C's map appending +the binary fraction `0.a_t…a_{n-1}` to wire `t`. + +## What is formalised + +* `qftBlockPhase`, `qftPartialState` — the phase and the invariant state above. +* `qftPartialState_zero` — the input state: `qftPartialState n a 0 = |enc a⟩` (`Pi.single`). +* `qftBlockControlledGates_reverse_prod_eq_diagonal`, `qftBlock_reverse_prod` — the operator form of + one block: `(qftBlock n t).reverse.prod = D_t · H_t`, the diagonal cascade `D_t` after the + Hadamard `H_t`. +* `qftPartialState_succ` — **the single-block step**: applying block `m` to + `qftPartialState n a m` gives `qftPartialState n a (m+1)`; the Hadamard frees wire `m` off the + pinned set and the diagonal cascade multiplies its `|1⟩` by `qftBlockPhase`, the phase algebra + `D_t · (-1)^{k_t a_t} = qftBlockPhase^{k_t}` closing the step. +* `qftBlocksProd_mulVec_basis` — **the block induction**: the whole block sequence maps `|enc a⟩` to + the product state `qftPartialState n a n = (1/√2^n) ∏_t (qftBlockPhase n a t)^{k_t}` (the product + representation, up to the input reversal — matched to `qftMatrix` in the final assembly). + +## Why this file exists (Exercise 5.6) + +The faithful `Ω(n²/p(n))` half of Exercise 5.6 needs the Figure 5.1 circuit as a formal object whose +controlled-`Rₖ` gates one can perturb, and the identification `qftGateCircuit n = qftMatrix 2ⁿ`. +This file supplies the reusable heart of that identification — the block-by-block state propagation, +and the single-block step is itself reusable for the *perturbed* circuit of the `Ω` argument (the +Hadamard-plus-cascade shape, with each `Rₖ` phase shifted). The final matrix equality (reversal +identity + match to `qftMatrix_apply_eq_prod_wirePhase`) is proved in `QftGateCircuitEqMatrix.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **The block phase of wire `t`** (Nielsen & Chuang eqs. 5.5–5.6): the phase acquired by wire +`t`'s `|1⟩` amplitude as its Figure 5.1 block acts on the input-pinned state — the Hadamard sign +`(-1)^{a_t}` times the controlled-`Rₖ` cascade `∏_{c > t, a_c = 1} e^{2πi/2^{c-t+1}}` from the +higher wires (still holding the input bits `a`). This is N&C's map appending the binary fraction +`0.a_t a_{t+1} … a_{n-1}` to the phase of wire `t`. -/ +noncomputable def qftBlockPhase (n : ℕ) (a : Fin n → Fin 2) (t : Fin n) : ℂ := + (-1) ^ (a t : ℕ) * + ((qftTargetControls n t).map fun c => + if a c = 1 then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) + else 1).prod + +/-- **The register state after the first `m` Figure 5.1 blocks act on `|enc a⟩`** (Nielsen & Chuang +eqs. 5.5–5.10). At basis index `i` with bit string `k = enc.symm i`: wires `s ≥ m` are still pinned +to the input bits `a` (the indicator `⟦∀ s ≥ m, kₛ = aₛ⟧`), the normalisation is `(1/√2)^m`, and +each processed wire `s < m` carries the block phase `qftBlockPhase n a s` raised to its output bit +`kₛ`. +`qftPartialState n a 0 = |enc a⟩` and `qftPartialState n a n` is the full product-representation +state. -/ +noncomputable def qftPartialState (n : ℕ) (a : Fin n → Fin 2) (m : ℕ) : Fin (2 ^ n) → ℂ := + fun i => + if ∀ s : Fin n, m ≤ (s : ℕ) → finFunctionFinEquiv.symm i s = a s then + (Real.sqrt 2 : ℂ)⁻¹ ^ m * + ∏ s ∈ Finset.univ.filter (fun s : Fin n => (s : ℕ) < m), + qftBlockPhase n a s ^ (finFunctionFinEquiv.symm i s : ℕ) + else 0 + +/-- Both bits of `Fin 2` are `0` or `1` — the case split used in the block phase algebra. -/ +private theorem fin_two_eq_zero_or_one (x : Fin 2) : x = 0 ∨ x = 1 := by + decide +revert + +/-- **The input state**: before any block acts (`m = 0`), the state is the basis vector `|enc a⟩`, +`qftPartialState n a 0 = Pi.single (finFunctionFinEquiv a) 1`. The pinned condition `∀ s, 0 ≤ s → +kₛ = aₛ` says `enc.symm i = a`, i.e. `i = enc a`; the empty phase product and `(1/√2)^0 = 1` leave +the amplitude `1`. -/ +theorem qftPartialState_zero (n : ℕ) (a : Fin n → Fin 2) : + qftPartialState n a 0 = Pi.single (finFunctionFinEquiv a) 1 := by + funext i + have hfil : (Finset.univ.filter (fun s : Fin n => (s : ℕ) < 0)) = ∅ := by simp + have key : (∀ s : Fin n, (0 : ℕ) ≤ (s : ℕ) → finFunctionFinEquiv.symm i s = a s) + ↔ i = finFunctionFinEquiv a := by + constructor + · intro h + rw [← Equiv.symm_apply_eq] + funext s; exact h s (Nat.zero_le _) + · intro h s _; rw [h, Equiv.symm_apply_apply] + rw [qftPartialState, hfil, Finset.prod_empty, mul_one, pow_zero, Pi.single_apply] + by_cases h : i = finFunctionFinEquiv a + · rw [ite_eq_left (key.mpr h), ite_eq_left h] + · rw [ite_eq_right (fun hh => h (key.mp hh)), ite_eq_right h] + +/-- **A block's controlled-`Rₖ` cascade, product in reverse, is the same diagonal phase gate.** The +cascade gates are diagonal (`qftBlockControlledGates_prod_eq_diagonal`), so their product is +independent of order; the reverse product (which appears when reading `qftBlock.reverse.prod`) is +the same diagonal. -/ +theorem qftBlockControlledGates_reverse_prod_eq_diagonal (n : ℕ) (t : Fin n) : + (qftBlockControlledGates n t).reverse.prod = Matrix.diagonal fun i => + ((qftTargetControls n t).map fun c => + if finFunctionFinEquiv.symm i c = 1 ∧ finFunctionFinEquiv.symm i t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod := by + rw [qftBlockControlledGates, ← List.map_reverse, + List.map_congr_left fun c hc => qftControlledGate_eq_diagonal n t c + (Fin.ne_of_val_ne (ne_of_lt (qftTargetControls_lt (List.mem_reverse.mp hc)))), + diagonal_map_prod] + refine congrArg Matrix.diagonal (funext fun i => ?_) + rw [List.map_reverse, List.prod_reverse] + +/-- **One Figure 5.1 block as an operator**: `(qftBlock n t).reverse.prod = D_t · H_t`, the Hadamard +`H_t = qftHadamardGate n t` on wire `t` followed by the diagonal cascade `D_t`. The block list +`H_t :: cascade` read as `.reverse.prod` is the operator +`cascade.reverse.prod · H_t = D_t · H_t`. -/ +theorem qftBlock_reverse_prod (n : ℕ) (t : Fin n) : + (qftBlock n t).reverse.prod + = (Matrix.diagonal fun i => ((qftTargetControls n t).map fun c => + if finFunctionFinEquiv.symm i c = 1 ∧ finFunctionFinEquiv.symm i t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod) + * qftHadamardGate n t := by + rw [qftBlock, List.reverse_cons, List.prod_append, List.prod_singleton, + qftBlockControlledGates_reverse_prod_eq_diagonal] + +/-- **The block phase collapses the diagonal cascade against the Hadamard sign.** For a fixed output +bit `kt` on the target wire (its controls holding the input bits `a`), the diagonal cascade phase +times the Hadamard coefficient `hadamardC kt (a t)` is `(1/√2) · (qftBlockPhase n a t)^{kt}`: when +`kt = 0` the cascade is trivial and both sides are `(1/√2)`; when `kt = 1` the cascade +`∏_{c, a_c=1} e^{…}` times the sign `(-1)^{a_t}` is exactly `qftBlockPhase`. -/ +private theorem cascade_mul_hadamardC (n : ℕ) (a : Fin n → Fin 2) (t : Fin n) (kt : Fin 2) : + ((qftTargetControls n t).map fun c => + if a c = 1 ∧ kt = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod + * hadamardC kt (a t) + = (Real.sqrt 2 : ℂ)⁻¹ * qftBlockPhase n a t ^ (kt : ℕ) := by + have hH := hadamardC_apply kt (a t) + have hD : ((qftTargetControls n t).map fun c => + if a c = 1 ∧ kt = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod + = ((qftTargetControls n t).map fun c => + if a c = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod + ^ (kt : ℕ) := by + rcases fin_two_eq_zero_or_one kt with h | h <;> subst h + · simp only [Fin.val_zero, pow_zero] + refine List.prod_eq_one fun x hx => ?_ + simp only [List.mem_map] at hx + obtain ⟨c, _, rfl⟩ := hx + simp + · rw [Fin.val_one, pow_one] + refine congrArg _ (List.map_congr_left fun c _ => ?_) + simp + rw [hD, hH, qftBlockPhase, mul_pow, ← pow_mul] + ring + +/-- **The single-block step** (Nielsen & Chuang eqs. 5.5–5.10, one wire): applying block `m` to the +state after the first `m` blocks gives the state after `m+1` blocks. The Hadamard `H_m` frees wire +`m` off the pinned set (its `|1⟩`/`|0⟩` amplitudes get the sign `(-1)^{a_m}`), and the diagonal +cascade `D_m` multiplies wire `m`'s `|1⟩` by `∏_{c > m, a_c = 1} e^{2πi/2^{c-m+1}}`; the two combine +into `qftBlockPhase n a ⟨m⟩` on the freed wire, extending the phase product by one factor and the +normalisation by `1/√2`. -/ +theorem qftPartialState_succ (n : ℕ) (a : Fin n → Fin 2) (m : ℕ) (hm : m < n) : + (qftBlock n ⟨m, hm⟩).reverse.prod *ᵥ qftPartialState n a m = qftPartialState n a (m + 1) := by + set t : Fin n := ⟨m, hm⟩ with ht + have htv : (t : ℕ) = m := by rw [ht] + rw [qftBlock_reverse_prod, ← Matrix.mulVec_mulVec] + funext i + rw [Matrix.mulVec_diagonal, qftHadamardGate, singleQubitOnWire_mulVec] + set k := finFunctionFinEquiv.symm i with hk + set Φ := ∏ s ∈ Finset.univ.filter (fun s : Fin n => (s : ℕ) < m), + qftBlockPhase n a s ^ (k s : ℕ) with hΦ + -- The invariant state at the two wire-`t` updates of `i`. + have hval : ∀ b : Fin 2, qftPartialState n a m (finFunctionFinEquiv (Function.update k t b)) + = if b = a t ∧ (∀ s : Fin n, m + 1 ≤ (s : ℕ) → k s = a s) + then (Real.sqrt 2 : ℂ)⁻¹ ^ m * Φ else 0 := by + intro b + have hcond : (∀ s : Fin n, m ≤ (s : ℕ) → Function.update k t b s = a s) + ↔ (b = a t ∧ ∀ s : Fin n, m + 1 ≤ (s : ℕ) → k s = a s) := by + constructor + · intro h + refine ⟨?_, fun s hs => ?_⟩ + · have := h t (le_of_eq htv.symm) + rwa [Function.update_self] at this + · have hst : s ≠ t := Fin.ne_of_val_ne (by rw [htv]; omega) + rw [← Function.update_of_ne hst b k] + exact h s (by omega) + · rintro ⟨hb, hab⟩ s hs + rcases eq_or_lt_of_le hs with heq | hlt + · have hst : s = t := Fin.ext (by rw [htv]; omega) + rw [hst, Function.update_self]; exact hb + · rw [Function.update_of_ne (Fin.ne_of_val_ne (by rw [htv]; omega))] + exact hab s (by omega) + simp only [qftPartialState, Equiv.symm_apply_apply] + by_cases hc : b = a t ∧ (∀ s : Fin n, m + 1 ≤ (s : ℕ) → k s = a s) + · rw [ite_eq_left (hcond.mpr hc), ite_eq_left hc, hΦ] + congr 1 + refine Finset.prod_congr rfl fun s hs => ?_ + have hsm : (s : ℕ) < m := (Finset.mem_filter.mp hs).2 + rw [Function.update_of_ne (Fin.ne_of_val_ne (by rw [htv]; omega))] + · rw [ite_eq_right (fun h => hc (hcond.mp h)), ite_eq_right hc] + -- The state at `m+1`, with the phase product split off wire `t`. + have hnotmem : t ∉ Finset.univ.filter (fun s : Fin n => (s : ℕ) < m) := by + simp only [Finset.mem_filter, Finset.mem_univ, true_and]; rw [htv]; omega + have hfilsucc : Finset.univ.filter (fun s : Fin n => (s : ℕ) < m + 1) + = insert t (Finset.univ.filter (fun s : Fin n => (s : ℕ) < m)) := by + ext s + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] + constructor + · intro hs; rcases Nat.lt_succ_iff_lt_or_eq.mp hs with h | h + · exact Or.inr h + · exact Or.inl (Fin.ext (by rw [htv]; exact h)) + · rintro (rfl | h) + · rw [htv]; omega + · omega + have hrhs : qftPartialState n a (m + 1) i + = if (∀ s : Fin n, m + 1 ≤ (s : ℕ) → k s = a s) + then (Real.sqrt 2 : ℂ)⁻¹ ^ (m + 1) * (qftBlockPhase n a t ^ (k t : ℕ) * Φ) else 0 := by + simp only [qftPartialState, ← hk] + rw [hfilsucc, Finset.prod_insert hnotmem, hΦ] + rw [hval 0, hval 1, hrhs] + by_cases hp : ∀ s : Fin n, m + 1 ≤ (s : ℕ) → k s = a s + · rw [ite_eq_left hp] + have hpin : ∀ c ∈ qftTargetControls n t, k c = a c := fun c hc => + hp c (by have := qftTargetControls_lt hc; rw [htv] at this; omega) + have hDeq : ((qftTargetControls n t).map fun c => + if k c = 1 ∧ k t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) else 1).prod + = ((qftTargetControls n t).map fun c => + if a c = 1 ∧ k t = 1 + then Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) + else 1).prod := by + congr 1 + exact List.map_congr_left fun c hc => by rw [hpin c hc] + rw [hDeq] + simp only [and_iff_left hp] + have hsum : hadamardC (k t) 0 * (if (0 : Fin 2) = a t then (Real.sqrt 2 : ℂ)⁻¹ ^ m * Φ else 0) + + hadamardC (k t) 1 * (if (1 : Fin 2) = a t then (Real.sqrt 2 : ℂ)⁻¹ ^ m * Φ else 0) + = hadamardC (k t) (a t) * ((Real.sqrt 2 : ℂ)⁻¹ ^ m * Φ) := by + rcases fin_two_eq_zero_or_one (a t) with hat | hat <;> rw [hat] + · rw [ite_eq_left rfl, ite_eq_right (by decide)]; ring + · rw [ite_eq_right (by decide), ite_eq_left rfl]; ring + rw [hsum, ← mul_assoc, cascade_mul_hadamardC, pow_succ] + ring + · rw [ite_eq_right hp, ite_eq_right (fun h => hp h.2), ite_eq_right (fun h => hp h.2)] + ring + +/-- **The block sequence maps a basis input to the product state** (Nielsen & Chuang eqs. 5.5–5.10). +The whole Figure 5.1 block sequence (all `qftBlock`s, without the wire reversal) applied to +`|enc a⟩` is the product-representation state `qftPartialState n a n`, i.e. `(1/√2^n) ∏_t +(qftBlockPhase n a t)^{k_t}`. By induction on the number of blocks processed, peeling the last block +with the single-block step `qftPartialState_succ`. -/ +theorem qftBlocksProd_mulVec_basis (n : ℕ) (a : Fin n → Fin 2) : + ((List.finRange n).flatMap (qftBlock n)).reverse.prod *ᵥ Pi.single (finFunctionFinEquiv a) 1 + = qftPartialState n a n := by + have H : ∀ m, m ≤ n → + (((List.finRange n).take m).flatMap (qftBlock n)).reverse.prod + *ᵥ Pi.single (finFunctionFinEquiv a) 1 + = qftPartialState n a m := by + intro m + induction m with + | zero => + intro _ + rw [List.take_zero, List.flatMap_nil, List.reverse_nil, List.prod_nil, Matrix.one_mulVec, + qftPartialState_zero] + | succ m ih => + intro hm1 + have hm : m < n := hm1 + have hlen : m < (List.finRange n).length := by rw [List.length_finRange]; exact hm + have hget : (List.finRange n)[m]'hlen = (⟨m, hm⟩ : Fin n) := by simp [List.getElem_finRange] + have htk : (List.finRange n).take (m + 1) + = (List.finRange n).take m ++ [(⟨m, hm⟩ : Fin n)] := by + rw [List.take_add_one, List.getElem?_eq_getElem hlen, hget]; rfl + rw [htk, List.flatMap_append, List.reverse_append, List.prod_append, List.flatMap_cons, + List.flatMap_nil, List.append_nil, ← Matrix.mulVec_mulVec, ih (le_of_lt hm), + qftPartialState_succ n a m hm] + have hfull := H n (le_refl n) + rwa [List.take_of_length_le (le_of_eq List.length_finRange)] at hfull + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftGateCount.lean b/LeanPool/AxQM/Concrete/QftGateCount.lean new file mode 100644 index 0000000000..84589ea55b --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftGateCount.lean @@ -0,0 +1,116 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Asymptotics.Theta +public import Mathlib.Order.Filter.AtTopBot.Basic +public import Mathlib.Algebra.BigOperators.Intervals +public import Mathlib.Tactic + +/-! +# Concrete: the quantum-Fourier-transform gate count `n(n-1)/2 = Θ(n²)` (N&C Exercise 5.6) + +The `n`-qubit quantum Fourier transform circuit (Nielsen & Chuang, Figure 5.1) applies, to qubit +`j` (counting `1 … n`), one Hadamard followed by controlled-`R₂ … R_{n-j+1}` phase rotations, i.e. +`n - j` controlled-`Rₖ` gates. The controlled-`Rₖ` gates are the only ones carrying a continuous +phase parameter, hence the only gates that must be implemented to finite **precision**; their total +number is + +`∑_{j=1}^{n} (n - j) = (n-1) + (n-2) + ⋯ + 0 = n(n-1)/2`. + +This file provides that count as `qftControlledRkCount` and proves it grows quadratically, +`qftControlledRkCount n = Θ(n²)` (`qftControlledRkCount_isTheta_sq`) — the `Θ(n²)` factor of +Exercise 5.6's error scaling `Θ(n²/p(n))`. The companion `qftApproxErrorBound_isTheta` divides the +count by an arbitrary precision denominator `p` to give the full `Θ(n²/p(n))` scaling of the +guaranteed error bound. + +Everything here is `ℕ`/`ℝ` arithmetic and asymptotics (there is no quantum object at all, only the +gate-count function), mirroring `AxQM/Concrete/MultiControlledNotAsymptotics.lean` (the `Cⁿ(X)` +`O(n²)` count). The physics +consequence — that this many gates, each to precision `Δ = 1/p(n)`, approximates the QFT unitary to +error `≤ qftControlledRkCount n · Δ` — is [upstream `AxQM/NC/Ch5/Exercise5_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_6.lean), built on the Box +4.1 chaining bound `Evolution.gateError_prod_le`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Filter Asymptotics + +/-- **The controlled-`Rₖ` gate count of the `n`-qubit QFT circuit** (Nielsen & Chuang, Figure 5.1): +`qftControlledRkCount n = n(n-1)/2`. Qubit `j` receives `n - j` controlled phase rotations, and +`∑_{j=1}^{n} (n - j) = n(n-1)/2`; these are the circuit's only gates carrying a continuous phase +parameter (the Hadamards and swaps are exact), hence the only ones implemented to finite precision +in Exercise 5.6. -/ +def qftControlledRkCount (n : ℕ) : ℕ := n * (n - 1) / 2 + +/-- The QFT gate count is the Gauss sum `∑_{j < n} j` — the `∑_{j=1}^{n} (n - j)` of Figure 5.1 +reindexed — establishing `qftControlledRkCount n = n(n-1)/2` is the count of controlled rotations, +not an arbitrary closed form (`Finset.sum_range_id`). -/ +theorem qftControlledRkCount_eq_sum (n : ℕ) : + qftControlledRkCount n = ∑ j ∈ Finset.range n, j := + (Finset.sum_range_id n).symm + +/-- The doubled gate count `2 · qftControlledRkCount n = n(n-1)`; the exact (division-free) form of +`n(n-1)/2`, used for the quadratic lower bound. Since `n(n-1)` is even the halving is exact. -/ +theorem two_mul_qftControlledRkCount (n : ℕ) : + 2 * qftControlledRkCount n = n * (n - 1) := by + have := Finset.sum_range_id_mul_two n + rw [Finset.sum_range_id] at this + unfold qftControlledRkCount + omega + +/-- Quadratic upper bound on the gate count: `qftControlledRkCount n ≤ n²`. -/ +theorem qftControlledRkCount_le_sq (n : ℕ) : qftControlledRkCount n ≤ n ^ 2 := by + unfold qftControlledRkCount + calc n * (n - 1) / 2 ≤ n * (n - 1) := Nat.div_le_self _ _ + _ ≤ n * n := by apply Nat.mul_le_mul_left; omega + _ = n ^ 2 := by ring + +/-- Quadratic lower bound on the gate count: `n² ≤ 4 · qftControlledRkCount n` for `n ≥ 2`. With the +upper bound `qftControlledRkCount_le_sq` this pins the count to `Θ(n²)`. -/ +theorem sq_le_four_mul_qftControlledRkCount {n : ℕ} (hn : 2 ≤ n) : + n ^ 2 ≤ 4 * qftControlledRkCount n := by + obtain ⟨d, rfl⟩ : ∃ d, n = d + 1 := ⟨n - 1, by omega⟩ + have h := two_mul_qftControlledRkCount (d + 1) + simp only [Nat.add_sub_cancel] at h + nlinarith [h, hn] + +/-- **The QFT gate count grows quadratically:** `qftControlledRkCount n = Θ(n²)` (as `n → ∞`). This +is the `Θ(n²)` factor of Exercise 5.6's error scaling `Θ(n²/p(n))`: the number of imprecise +controlled-`Rₖ` gates in the QFT circuit is quadratic in the number of qubits. The `O(n²)` half is +`qftControlledRkCount_le_sq` (bound `1`), the `Ω(n²)` half `sq_le_four_mul_qftControlledRkCount` +(bound `4`, eventually). -/ +theorem qftControlledRkCount_isTheta_sq : + (fun n : ℕ => (qftControlledRkCount n : ℝ)) =Θ[atTop] (fun n : ℕ => (n : ℝ) ^ 2) := by + constructor + · refine IsBigO.of_bound 1 ?_ + filter_upwards with n + rw [Real.norm_of_nonneg (by positivity), Real.norm_of_nonneg (by positivity), one_mul] + exact_mod_cast qftControlledRkCount_le_sq n + · refine IsBigO.of_bound 4 ?_ + filter_upwards [eventually_ge_atTop 2] with n hn + rw [Real.norm_of_nonneg (by positivity), Real.norm_of_nonneg (by positivity)] + exact_mod_cast sq_le_four_mul_qftControlledRkCount hn + +/-- **The approximate-QFT error bound scales as `Θ(n²/p(n))`** (Nielsen & Chuang, Exercise 5.6). For +any precision denominator `p : ℕ → ℝ` (`Δ = 1/p(n)`), the guaranteed error bound `n(n-1)/(2·p(n)) = +qftControlledRkCount n / p n` — the imprecise-gate count times the per-gate precision — grows as +`Θ(n²/p(n))`, since the gate count is `Θ(n²)` (`qftControlledRkCount_isTheta_sq`) and `p n` is a +common factor. This is the scaling of the error *bound*; the physics statement that the actual QFT +approximation error `E(U,V)` is dominated by this bound (hence `O(n²/p(n))`) is +`AxQM.qftApprox_gateError_le_div`. -/ +theorem qftApproxErrorBound_isTheta (p : ℕ → ℝ) : + (fun n : ℕ => (qftControlledRkCount n : ℝ) / p n) + =Θ[atTop] (fun n : ℕ => (n : ℝ) ^ 2 / p n) := by + have := qftControlledRkCount_isTheta_sq.mul (isTheta_refl (fun n : ℕ => (p n)⁻¹) atTop) + simpa only [div_eq_mul_inv] using this + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QftProductRepresentation.lean b/LeanPool/AxQM/Concrete/QftProductRepresentation.lean new file mode 100644 index 0000000000..18ae4a9826 --- /dev/null +++ b/LeanPool/AxQM/Concrete/QftProductRepresentation.lean @@ -0,0 +1,150 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QuantumFourierTransform +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import Mathlib.Algebra.BigOperators.Field + +/-! +# Concrete: the product representation of the quantum Fourier transform (N&C eq. 5.4) + +Nielsen & Chuang, §5.1, derive from the defining action (eq. 5.2) + +``` + 1 d-1 +|j⟩ ↦ ──── Σ e^{2πi jk/d} |k⟩ (5.2) + √d k=0 +``` + +the **product representation** of the `n`-qubit quantum Fourier transform (`d = 2ⁿ`), + +``` + (|0⟩ + e^{2πi 0.jₙ}|1⟩)(|0⟩ + e^{2πi 0.jₙ₋₁jₙ}|1⟩)···(|0⟩ + e^{2πi 0.j₁···jₙ}|1⟩) +|j₁…jₙ⟩ ↦ ─────────────────────────────────────────────────────────────────────────────── , + 2^{n/2} +``` (5.4) + +obtained (eqs. 5.5–5.10) purely from the factorisation of the Fourier kernel over the bits of the +**output** index `k`: writing `k = ∑ₗ kₗ 2ˡ`, + +``` + e^{2πi jk/2ⁿ} = ∏ₗ e^{2πi j kₗ 2ˡ / 2ⁿ} = ∏ₗ (e^{2πi j 2ˡ/2ⁿ})^{kₗ} . (5.7) +``` + +N&C call this representation "so useful that you may even wish to consider this to be the definition +of the quantum Fourier transform": it is the bridge that turns the monolithic matrix `qftMatrix 2ⁿ` +into a **circuit** of one-qubit gates (Figure 5.1), and it is the object every gate-level QFT +argument reduces to. + +## What is formalised + +This file works with the matrix `Concrete.qftMatrix`: it establishes the kernel factorisation +(5.7) — hence the amplitude form of (5.4) — for a general number of qubits `n`, +indexing the `2ⁿ`-dimensional register by bit strings +`kbits : Fin n → Fin 2` through `finFunctionFinEquiv` (`k = ∑ₗ kₗ 2ˡ`, little-endian). + +* `qftWirePhase n j l = e^{2πi · j · 2ˡ / 2ⁿ}` — the **single-qubit output phase** attached to wire + `l` in the product representation (the `e^{2πi 0.j…}` factor of (5.4); by periodicity it depends + only on `j mod 2^{n−l}`, i.e. the binary fraction `0.j_{…}`). `norm_qftWirePhase` records that it + is a unit-modulus phase, `‖qftWirePhase n j l‖ = 1`. +* `qftMatrix_apply_prod` — the kernel factorisation (5.7): the `(k, j)` entry of `qftMatrix 2ⁿ`, at + `k = finFunctionFinEquiv kbits`, factors as `(1/√2ⁿ) · ∏ₗ e^{2πi j (kₗ 2ˡ)/2ⁿ}`. +* `qftMatrix_apply_eq_prod_wirePhase` — the product representation (5.4) proper: the same entry is + `(1/√2ⁿ) · ∏ₗ (qftWirePhase n j l)^{kₗ}`, exhibiting column `j` of the QFT as the tensor product + `⨂ₗ (|0⟩ + qftWirePhase n j l · |1⟩)/√2` in the computational basis (the factor for wire `l` is + `1` when `kₗ = 0` and `qftWirePhase n j l` when `kₗ = 1`). + +## Why this file exists (Exercise 5.6) + +The faithful `Ω(n²/p(n))` half of Exercise 5.6 (the approximate QFT: perturbing the controlled-`Rₖ` +gates to precision `Δ = 1/p(n)` costs error `Θ(n²/p(n))`) requires the **gate-level** Figure 5.1 +circuit as a formal object — a decomposition `qftMatrix 2ⁿ = (Hadamards · controlled-Rₖ · swaps)` +whose `Rₖ` factors one then perturbs (the abstract chaining tightness in +`Postulates/API/ApproxErrorTight.lean` is QFT-agnostic and does not, by itself, give a faithful +lower bound). Proving that gate decomposition correct is exactly proving the circuit reproduces the +product representation (5.4); this file supplies its right-hand side — the amplitude target the +gate-by-gate computation must hit, and the product-of-phases structure the coherent +`Rₖ`-perturbation lower bound exploits. It is reusable QFT infrastructure (the general-`n` +counterpart of the two-qubit factorisation `qftFour_eq_prod`), built ahead of the gate-level circuit +that consumes it. + +The matrix `qftMatrix` itself is defined in `AxQM/Concrete/QuantumFourierTransform.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Complex + +/-- The **single-qubit output phase** of the quantum Fourier transform on wire `l` (Nielsen & +Chuang eq. 5.4): `qftWirePhase n j l = e^{2πi · j · 2ˡ / 2ⁿ}`. This is the phase `e^{2πi 0.j_{…}}` +that multiplies `|1⟩` on output wire `l` in the product representation of `F|j⟩`; by the periodicity +of the exponential it depends only on `j mod 2^{n−l}` — the binary fraction `0.j_{…}` of N&C's +notation. -/ +noncomputable def qftWirePhase (n : ℕ) (j : Fin (2 ^ n)) (l : Fin n) : ℂ := + Complex.exp (2 * Real.pi * Complex.I * ((j : ℕ) * 2 ^ (l : ℕ)) / (2 ^ n : ℕ)) + +/-- The single-qubit output phase is a **unit-modulus phase**: `‖qftWirePhase n j l‖ = 1`. Its +argument `2πi · j · 2ˡ/2ⁿ` is purely imaginary, so `‖e^{iθ}‖ = 1` +(`Complex.norm_exp_ofReal_mul_I`). -/ +theorem norm_qftWirePhase (n : ℕ) (j : Fin (2 ^ n)) (l : Fin n) : + ‖qftWirePhase n j l‖ = 1 := by + rw [qftWirePhase, + show (2 * (Real.pi : ℂ) * Complex.I * ((j : ℕ) * 2 ^ (l : ℕ)) / (2 ^ n : ℕ) : ℂ) + = ((2 * Real.pi * ((j : ℕ) * 2 ^ (l : ℕ)) / (2 ^ n : ℕ) : ℝ) : ℂ) * Complex.I from by + push_cast; ring] + exact Complex.norm_exp_ofReal_mul_I _ + +/-- **The Fourier-kernel factorisation over the output bits** (Nielsen & Chuang eq. 5.7). Writing +the output index `k` in binary as `k = finFunctionFinEquiv kbits = ∑ₗ kₗ 2ˡ`, the `(k, j)` entry of +`2ⁿ`-dimensional quantum Fourier transform matrix factors over the `n` wires: + +`qftMatrix 2ⁿ k j = (1/√2ⁿ) · ∏ₗ e^{2πi · j · (kₗ · 2ˡ) / 2ⁿ}`. + +This is the algebraic heart of the QFT's product representation (5.4): `e^{2πi jk/2ⁿ} = ∏ₗ e^{2πi j +kₗ 2ˡ/2ⁿ}` because `jk = ∑ₗ j kₗ 2ˡ` (`finFunctionFinEquiv_apply_val`), and `Complex.exp` turns the +sum in the exponent into the product (`Complex.exp_sum`). -/ +theorem qftMatrix_apply_prod (n : ℕ) (j : Fin (2 ^ n)) (kbits : Fin n → Fin 2) : + qftMatrix (2 ^ n) (finFunctionFinEquiv kbits) j + = (Real.sqrt (2 ^ n : ℕ) : ℂ)⁻¹ * + ∏ l : Fin n, Complex.exp (2 * Real.pi * Complex.I * + ((j : ℕ) * ((kbits l : ℕ) * 2 ^ (l : ℕ))) / (2 ^ n : ℕ)) := by + have hkC : (((finFunctionFinEquiv kbits : Fin (2 ^ n)) : ℕ) : ℂ) + = ∑ i, ((kbits i : ℕ) : ℂ) * 2 ^ (i : ℕ) := by + rw [finFunctionFinEquiv_apply_val]; push_cast; ring + rw [qftMatrix_apply, ← Complex.exp_sum] + congr 1 + congr 1 + rw [hkC, Finset.mul_sum, Finset.mul_sum, Finset.sum_div] + +/-- **The product representation of the quantum Fourier transform** (Nielsen & Chuang eq. 5.4). At +output index `k = finFunctionFinEquiv kbits`, the `(k, j)` entry of `qftMatrix 2ⁿ` is + +`qftMatrix 2ⁿ k j = (1/√2ⁿ) · ∏ₗ (qftWirePhase n j l)^{kₗ}`, + +so column `j` of the QFT is the tensor product `⨂ₗ (|0⟩ + qftWirePhase n j l · |1⟩)/√2` in the +computational basis: on wire `l` the amplitude carries the single-qubit phase `qftWirePhase n j l` +raised to the output bit `kₗ` (a factor of `1` when `kₗ = 0`, and the phase itself when `kₗ = 1`). +The bit-power form follows from the kernel factorisation `qftMatrix_apply_prod` by pulling the bit +`kₗ` out of the exponent (`Complex.exp_nat_mul`). -/ +theorem qftMatrix_apply_eq_prod_wirePhase (n : ℕ) (j : Fin (2 ^ n)) (kbits : Fin n → Fin 2) : + qftMatrix (2 ^ n) (finFunctionFinEquiv kbits) j + = (Real.sqrt (2 ^ n : ℕ) : ℂ)⁻¹ * ∏ l : Fin n, qftWirePhase n j l ^ (kbits l : ℕ) := by + rw [qftMatrix_apply_prod] + congr 1 + apply Finset.prod_congr rfl + intro l _ + rw [qftWirePhase, ← Complex.exp_nat_mul] + congr 1 + push_cast + ring + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/QuantumFourierTransform.lean b/LeanPool/AxQM/Concrete/QuantumFourierTransform.lean new file mode 100644 index 0000000000..cff842211b --- /dev/null +++ b/LeanPool/AxQM/Concrete/QuantumFourierTransform.lean @@ -0,0 +1,187 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import Mathlib.RingTheory.RootsOfUnity.Complex +public import Mathlib.Algebra.Field.GeomSum + +/-! +# Concrete: the `d`-dimensional quantum Fourier transform matrix and its unitarity + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, §5.1 (eq. 5.2) defines the +**quantum Fourier transform** on an orthonormal basis `|0⟩, …, |d-1⟩` by its action on basis +states, + +``` + 1 d-1 +|j⟩ ↦ ──── Σ e^{2πi jk/d} |k⟩ . (5.2) + √d k=0 +``` + +The corresponding `d × d` matrix `F` (column `j` = image of `|j⟩`) therefore has entries + +``` + Fₖⱼ = (1/√d) · e^{2πi jk/d} , +``` + +and N&C remark that this transformation "is a unitary transformation, and thus can be implemented +as the dynamics for a quantum computer" (the direct unitarity check is Exercise 5.1). This file +provides that matrix and a **direct proof that it is unitary**, for a general dimension `d ≥ 1`. + +## What is formalised + +* `qftPrimitiveRoot d = e^{2πi/d}` — the primitive `d`-th root of unity generating the transform + (`Complex.isPrimitiveRoot_exp`). +* `qftMatrix d` — the matrix `Fₖⱼ = (1/√d) · ω^{jk}` (`ω = qftPrimitiveRoot d`), with + `qftMatrix_apply` re-expressing the entry in the literal `(1/√d) · e^{2πi jk/d}` form of (5.2). +* `qftMatrix_star_mul_self` — `F† F = 1`, and hence `qftMatrix_mem_unitaryGroup` — + `F ∈ Matrix.unitaryGroup (Fin d) ℂ`. + +## Proof of unitarity + +The `(i, j)` entry of `F† F` is `∑ₖ conj(Fₖᵢ) Fₖⱼ = (1/d) ∑ₖ ω^{(j-i)k} = (1/d) ∑ₖ ζ^k`, where +`ζ = (ω^i)⁻¹ ω^j`. Two cases: + +* `i = j`: `ζ = 1`, so `∑ₖ ζ^k = d` and the entry is `(1/d)·d = 1` (using `(√d)² = d`). +* `i ≠ j`: `ζ ≠ 1` because `ω` is a primitive `d`-th root, so `ω^i = ω^j` forces `i = j` + (`IsPrimitiveRoot.pow_inj`); and `ζ^d = 1`, so the geometric sum `∑_{k (Real.sqrt d : ℂ)⁻¹ * qftPrimitiveRoot d ^ ((j : ℕ) * (k : ℕ)) + +/-- The quantum Fourier transform entry in the **literal exponential form** of Nielsen & Chuang +eq. (5.2): `Fₖⱼ = (1/√d) · e^{2πi jk/d}`. This unfolds the `ω^{jk}` power of `qftMatrix` back to +`e^{2πi jk/d}` (`Complex.exp_nat_mul`). -/ +theorem qftMatrix_apply (d : ℕ) (k j : Fin d) : + qftMatrix d k j + = (Real.sqrt d : ℂ)⁻¹ * Complex.exp (2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d) := by + rw [qftMatrix, qftPrimitiveRoot, ← Complex.exp_nat_mul] + congr 2 + push_cast + ring + +/-- **Conjugate-transpose entry of the quantum Fourier transform matrix:** +`(Fᴴ)ⱼₖ = (1/√d) · e^{−2πi jk/d}` — the forward entry `qftMatrix_apply` conjugated, i.e. the +inverse-DFT amplitude. Since `(Fᴴ)ⱼₖ = conj(Fₖⱼ)`, `conj((1/√d)) = 1/√d` (real) and +`conj(e^{2πi jk/d}) = e^{conj(2πi jk/d)} = e^{−2πi jk/d}`. The `Concrete` companion of +`qftMatrix_apply` used to realize the inverse quantum Fourier transform (Nielsen & Chuang +Exercise 5.5). -/ +theorem qftMatrix_conjTranspose_apply (d : ℕ) (j k : Fin d) : + (qftMatrix d)ᴴ j k + = (Real.sqrt d : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d)) := by + rw [Matrix.conjTranspose_apply, qftMatrix_apply, ← starRingEnd_apply, map_mul] + congr 1 + · rw [map_inv₀, Complex.conj_ofReal] + · rw [← Complex.exp_conj] + congr 1 + simp only [map_div₀, map_mul, Complex.conj_I, Complex.conj_ofReal, map_natCast, map_ofNat] + ring + +/-- The generating root of unity is closed under conjugation with `conj ω = ω⁻¹`: from +`conj(e^z) = e^{conj z}` and `conj(2πi/d) = -(2πi/d)`, so `conj ω = e^{-2πi/d} = ω⁻¹`. This is the +only complex-conjugation fact used in the unitarity proof. -/ +theorem qftPrimitiveRoot_conj (d : ℕ) : + (starRingEnd ℂ) (qftPrimitiveRoot d) = (qftPrimitiveRoot d)⁻¹ := by + rw [qftPrimitiveRoot, ← Complex.exp_conj, ← Complex.exp_neg] + congr 1 + simp only [map_div₀, map_mul, map_ofNat, Complex.conj_ofReal, Complex.conj_I, + Complex.conj_natCast] + ring + +/-- Conjugation of the generating root, in `star` form: `star ω = ω⁻¹` +(`qftPrimitiveRoot_conj` restated via `starRingEnd_apply`). -/ +theorem qftPrimitiveRoot_star (d : ℕ) : + star (qftPrimitiveRoot d) = (qftPrimitiveRoot d)⁻¹ := by + rw [← starRingEnd_apply]; exact qftPrimitiveRoot_conj d + +/-- **The quantum Fourier transform matrix is an isometry:** `F† F = 1`. Entrywise this is the +root-of-unity orthogonality `(1/d) ∑ₖ ζ^k = δᵢⱼ` with `ζ = (ω^i)⁻¹ ω^j`: for `i = j`, `ζ = 1` and +the sum is `d`; for `i ≠ j`, `ζ ≠ 1` (primitivity, `IsPrimitiveRoot.pow_inj`) and `ζ^d = 1`, so the +geometric sum vanishes (`geom_sum_eq`). -/ +theorem qftMatrix_star_mul_self (d : ℕ) [NeZero d] : + star (qftMatrix d) * qftMatrix d = 1 := by + have hd : (d : ℕ) ≠ 0 := NeZero.ne d + have hω : IsPrimitiveRoot (qftPrimitiveRoot d) d := Complex.isPrimitiveRoot_exp d hd + have hω0 : qftPrimitiveRoot d ≠ 0 := by rw [qftPrimitiveRoot]; exact Complex.exp_ne_zero _ + ext i j + rw [Matrix.mul_apply, Matrix.one_apply] + have hterm : ∀ k : Fin d, + (star (qftMatrix d)) i k * qftMatrix d k j + = (Real.sqrt d : ℂ)⁻¹ * (Real.sqrt d : ℂ)⁻¹ + * ((qftPrimitiveRoot d ^ (i : ℕ))⁻¹ * qftPrimitiveRoot d ^ (j : ℕ)) ^ (k : ℕ) := by + intro k + rw [Matrix.star_apply] + simp only [qftMatrix, star_mul', star_pow, star_inv₀, qftPrimitiveRoot_star, + Complex.star_def, Complex.conj_ofReal, mul_pow, inv_pow, ← pow_mul] + ring + rw [Finset.sum_congr rfl (fun k _ => hterm k), ← Finset.mul_sum] + rw [Fin.sum_univ_eq_sum_range + (fun k => ((qftPrimitiveRoot d ^ (i : ℕ))⁻¹ * qftPrimitiveRoot d ^ (j : ℕ)) ^ k) d] + set ζ : ℂ := (qftPrimitiveRoot d ^ (i : ℕ))⁻¹ * qftPrimitiveRoot d ^ (j : ℕ) with hζ + have hd0 : (d : ℂ) ≠ 0 := by exact_mod_cast hd + have hsq : (Real.sqrt d : ℂ) * (Real.sqrt d : ℂ) = (d : ℂ) := by + rw [← Complex.ofReal_mul, Real.mul_self_sqrt (by positivity), Complex.ofReal_natCast] + by_cases hij : i = j + · subst hij + have hz1 : ζ = 1 := by rw [hζ]; exact inv_mul_cancel₀ (pow_ne_zero _ hω0) + rw [hz1, ite_eq_left rfl] + simp only [one_pow, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one] + rw [← mul_inv, hsq, inv_mul_cancel₀ hd0] + · have hζ1 : ζ ≠ 1 := by + rw [hζ] + intro h + rw [inv_mul_eq_one₀ (pow_ne_zero _ hω0)] at h + exact hij (Fin.ext (hω.pow_inj i.isLt j.isLt h)) + have hζd : ζ ^ d = 1 := by + rw [hζ, mul_pow, inv_pow, ← pow_mul, ← pow_mul, mul_comm (i : ℕ) d, mul_comm (j : ℕ) d, + pow_mul, pow_mul] + simp [hω.pow_eq_one] + rw [geom_sum_eq hζ1 d, hζd, sub_self, zero_div, mul_zero, ite_eq_right hij] + +/-- **The quantum Fourier transform matrix is unitary:** `F ∈ Matrix.unitaryGroup (Fin d) ℂ` +(Nielsen & Chuang, Exercise 5.1 / the unitarity underlying Problem 5.1), from `F† F = 1` +(`qftMatrix_star_mul_self`). -/ +theorem qftMatrix_mem_unitaryGroup (d : ℕ) [NeZero d] : + qftMatrix d ∈ Matrix.unitaryGroup (Fin d) ℂ := + Matrix.mem_unitaryGroup_iff'.mpr (qftMatrix_star_mul_self d) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/ReachableCircuits.lean b/LeanPool/AxQM/Concrete/ReachableCircuits.lean new file mode 100644 index 0000000000..681872dddf --- /dev/null +++ b/LeanPool/AxQM/Concrete/ReachableCircuits.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.UnitaryToffoliSingleQubitProduct + +/-! +# Generic reachable-circuit density over an abstract single-qubit gate set (N&C §4.5/§4.3) + +The §4.5/§4.3 universality assembly — every register unitary is a product of `Toffoli`/`CNOT`/`NOT` +and uncontrolled single-qubit wire gates (`exists_isToffoliOrSingleQubit_list_prod_eq`), each +approximated up to a global phase, the phases combining into one global phase — is **generic** in +the reachable single-qubit gate set. This file states it once, parameterised over an abstract set +`S` of +`2 × 2` gates whose per-wire density (up to a global phase) is supplied as a hypothesis, so the two +universality items reuse it rather than re-proving the ~90-line assembly per item: + +* Exercise 4.43 (`H, S, CNOT, Toffoli`): `S = reachableRotations θ`, `cos θ = 3/5` + (`Concrete/FourGateUniversality.lean`); +* Exercise 4.44 (the Deutsch gate `G = C²(iR_x(πα))`): `S = deutschWireGateSubmonoid α`, `α` + irrational (`Concrete/DeutschReachableCircuits.lean`). + +## The construction and results + +* `reachableGateSetOf enc S` — the elementary gates the reduction bottoms out in: the `≤ 2`-control + reversible gates `IsToffoliPermGate enc G` (`Toffoli`/`CNOT`/`NOT`) together with, on every wire + `j`, the uncontrolled single-qubit gates `singleQubitOnWire enc j g` whose block `g` lies in `S`. +* `reachableCircuitsOf enc S` — the submonoid they generate (finite products of reachable gates). +* `exists_phase_smul_mem_closure_reachableCircuitsOf` — **the generic density**: given the per-wire + density hypothesis `hS` (for every wire `j` and `U ∈ U(2)`, some global phase makes + `e^{ia} • singleQubitOnWire enc j U` a limit of `singleQubitOnWire enc j '' S`), an `m`-qubit + encoding with `m ≥ 1`, and any `U ∈ U(d)`, some global phase `e^{ia}` makes `e^{ia} • U` a limit + of `reachableCircuitsOf enc S` — the reachable circuits are dense in `U(d)` up to a global phase. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The reachable gate set over an abstract single-qubit gate set `S`.** The elementary matrix +gates the §4.5/§4.3 universality reduction bottoms out in: the `≤ 2`-control reversible gates +`IsToffoliPermGate enc G` (`Toffoli`/`CNOT`/`NOT`) together with, on every wire `j`, the +uncontrolled single-qubit gates `singleQubitOnWire enc j g` whose block `g` lies in `S`. +Instantiating `S` gives +Exercise 4.43's `reachableGateSet` (`S = reachableRotations θ`) and Exercise 4.44's +`deutschReachableGateSet` (`S = deutschWireGateSubmonoid α`). -/ +noncomputable def reachableGateSetOf (enc : (Fin m → Fin 2) ≃ Fin d) + (S : Set (Matrix (Fin 2) (Fin 2) ℂ)) : Set (Matrix (Fin d) (Fin d) ℂ) := + {G | IsToffoliPermGate enc G} ∪ ⋃ j : Fin m, singleQubitOnWire enc j '' S + +/-- **The reachable circuits over an abstract single-qubit gate set `S`.** The submonoid of +`Matrix (Fin d) (Fin d) ℂ` generated by `reachableGateSetOf enc S` — the finite products of +reachable gates. Universality is the statement that its closure fills `U(d)` up to a global phase +(`exists_phase_smul_mem_closure_reachableCircuitsOf`). -/ +noncomputable def reachableCircuitsOf (enc : (Fin m → Fin 2) ≃ Fin d) + (S : Set (Matrix (Fin 2) (Fin 2) ℂ)) : Submonoid (Matrix (Fin d) (Fin d) ℂ) := + Submonoid.closure (reachableGateSetOf enc S) + +/-- Each `≤ 2`-control reversible gate (`Toffoli`/`CNOT`/`NOT`) is a reachable circuit — one of +the gates that generate `reachableCircuitsOf`. -/ +theorem isToffoliPermGate_mem_reachableCircuitsOf (enc : (Fin m → Fin 2) ≃ Fin d) + (S : Set (Matrix (Fin 2) (Fin 2) ℂ)) {G : Matrix (Fin d) (Fin d) ℂ} + (hG : IsToffoliPermGate enc G) : G ∈ reachableCircuitsOf enc S := + Submonoid.subset_closure (Or.inl hG) + +/-- Each uncontrolled single-qubit gate on a wire whose block lies in `S` is a reachable circuit — a +generator of `reachableCircuitsOf`. -/ +theorem singleQubitOnWire_mem_reachableCircuitsOf (enc : (Fin m → Fin 2) ≃ Fin d) + (S : Set (Matrix (Fin 2) (Fin 2) ℂ)) (j : Fin m) {g : Matrix (Fin 2) (Fin 2) ℂ} + (hg : g ∈ S) : singleQubitOnWire enc j g ∈ reachableCircuitsOf enc S := + Submonoid.subset_closure (Or.inr (Set.mem_iUnion.2 ⟨j, Set.mem_image_of_mem _ hg⟩)) + +/-- **Each terminal gate is, up to a global phase, a limit of reachable circuits.** Given the +per-wire density hypothesis `hS`, for a terminal gate `G` (`IsToffoliOrSingleQubitGate enc G`) there +is a phase `a` with `e^{ia} • G` in the closure of `reachableCircuitsOf enc S`: +* a `Toffoli`/`CNOT`/`NOT` is *exactly* a reachable generator, so the phase is `0`; +* an uncontrolled single-qubit unitary on a wire is a limit of `singleQubitOnWire` applied to `S`, + up to a global phase — this is exactly the hypothesis `hS`, whose image sits inside the reachable + circuits (`singleQubitOnWire_mem_reachableCircuitsOf`). -/ +theorem exists_phase_smul_mem_closure_reachableCircuitsOf_of_isToffoliOrSingleQubit + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Set (Matrix (Fin 2) (Fin 2) ℂ)} + (hS : ∀ (j : Fin m) {U : Matrix (Fin 2) (Fin 2) ℂ}, U ∈ Matrix.unitaryGroup (Fin 2) ℂ → + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • singleQubitOnWire enc j U + ∈ closure (singleQubitOnWire enc j '' S)) + {G : Matrix (Fin d) (Fin d) ℂ} (hG : IsToffoliOrSingleQubitGate enc G) : + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • G + ∈ closure (↑(reachableCircuitsOf enc S) : Set (Matrix (Fin d) (Fin d) ℂ)) := by + rcases hG with h | ⟨j, U, hU, rfl⟩ + · -- `Toffoli`/`CNOT`/`NOT`: exact generator, phase `0`. + refine ⟨0, ?_⟩ + rw [Complex.ofReal_zero, zero_mul, Complex.exp_zero, one_smul] + exact subset_closure (isToffoliPermGate_mem_reachableCircuitsOf enc S h) + · -- Single-qubit gate on a wire: the density hypothesis, image inside the circuits. + obtain ⟨a, ha⟩ := hS j hU + refine ⟨a, closure_mono ?_ ha⟩ + rintro _ ⟨g, hg, rfl⟩ + exact singleQubitOnWire_mem_reachableCircuitsOf enc S j hg + +/-- **A product of terminal gates is, up to a global phase, a limit of reachable circuits.** Given +the per-wire density hypothesis `hS`, for a list `gates` all of whose members are terminal gates +there is a phase `a` with `e^{ia} • gates.prod` in the closure of `reachableCircuitsOf enc S`. The +closure of the submonoid is again a submonoid (matrix multiplication is continuous), so the per-gate +approximations multiply, and their phases add into one global phase. -/ +theorem exists_phase_smul_prod_mem_closure_reachableCircuitsOf + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Set (Matrix (Fin 2) (Fin 2) ℂ)} + (hS : ∀ (j : Fin m) {U : Matrix (Fin 2) (Fin 2) ℂ}, U ∈ Matrix.unitaryGroup (Fin 2) ℂ → + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • singleQubitOnWire enc j U + ∈ closure (singleQubitOnWire enc j '' S)) + {gates : List (Matrix (Fin d) (Fin d) ℂ)} + (hgates : ∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) : + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • gates.prod + ∈ closure (↑(reachableCircuitsOf enc S) : Set (Matrix (Fin d) (Fin d) ℂ)) := by + induction gates with + | nil => + refine ⟨0, ?_⟩ + rw [List.prod_nil, Complex.ofReal_zero, zero_mul, Complex.exp_zero, one_smul] + exact subset_closure (one_mem _) + | cons g gs ih => + obtain ⟨ag, hag⟩ := + exists_phase_smul_mem_closure_reachableCircuitsOf_of_isToffoliOrSingleQubit enc hS + (hgates g (List.mem_cons_self ..)) + obtain ⟨as, has⟩ := ih fun x hx => hgates x (List.mem_cons_of_mem _ hx) + refine ⟨ag + as, ?_⟩ + rw [List.prod_cons, Complex.ofReal_add, add_mul, Complex.exp_add, ← smul_mul_smul_comm] + exact (reachableCircuitsOf enc S).topologicalClosure.mul_mem hag has + +/-- **Generic universality density over an abstract single-qubit gate set `S`.** Given the per-wire +density hypothesis `hS` (for every wire `j` and `U ∈ U(2)`, some global phase makes +`e^{ia} • singleQubitOnWire enc j U` a limit of `singleQubitOnWire enc j '' S`), an encoding +`enc : (Fin m → Fin 2) ≃ Fin d` of an `m`-qubit register with at least one qubit, and *any* +`U ∈ U(d)`, some global phase `e^{ia}` makes `e^{ia} • U ∈ closure ↑(reachableCircuitsOf enc S)`. + +In the finite-dimensional product topology on `Matrix (Fin d) (Fin d) ℂ`, closure is approximation +to arbitrary accuracy, so this is exactly: **the reachable circuits are dense in `U(d)` up to a +global phase**. Chains the exact terminal-gate decomposition +`exists_isToffoliOrSingleQubit_list_prod_eq` +with the per-product approximation `exists_phase_smul_prod_mem_closure_reachableCircuitsOf`. The two +universality items — Exercise 4.43 (`reachableRotations θ`) and Exercise 4.44 +(`deutschWireGateSubmonoid α`) — obtain their headline by instantiating this with the appropriate +per-wire density for `hS`. -/ +theorem exists_phase_smul_mem_closure_reachableCircuitsOf [Nontrivial (Fin m → Fin 2)] + (enc : (Fin m → Fin 2) ≃ Fin d) {S : Set (Matrix (Fin 2) (Fin 2) ℂ)} + (hS : ∀ (j : Fin m) {U : Matrix (Fin 2) (Fin 2) ℂ}, U ∈ Matrix.unitaryGroup (Fin 2) ℂ → + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • singleQubitOnWire enc j U + ∈ closure (singleQubitOnWire enc j '' S)) + {U : Matrix (Fin d) (Fin d) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + ∃ a : ℝ, Complex.exp ((a : ℂ) * Complex.I) • U + ∈ closure (↑(reachableCircuitsOf enc S) : Set (Matrix (Fin d) (Fin d) ℂ)) := by + obtain ⟨gates, hgates, hprod⟩ := exists_isToffoliOrSingleQubit_list_prod_eq enc hU + obtain ⟨a, ha⟩ := exists_phase_smul_prod_mem_closure_reachableCircuitsOf enc hS hgates + exact ⟨a, hprod ▸ ha⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/Rotation.lean b/LeanPool/AxQM/Concrete/Rotation.lean new file mode 100644 index 0000000000..fb8da05d91 --- /dev/null +++ b/LeanPool/AxQM/Concrete/Rotation.lean @@ -0,0 +1,207 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliExponential + +/-! +# Concrete: the single-qubit rotation operators (Nielsen & Chuang, §4.2, eq. 4.4–4.8) + +For a real three-vector `n` and a real angle `θ`, Nielsen & Chuang define the rotation about the +`n`-axis by +`R_n̂(θ) ≡ exp(−iθ (n·σ)/2)` (eq. 4.8), +and the three coordinate rotations `R_x`, `R_y`, `R_z` as the special cases `n = x̂, y_hat, e_z` +(eq. 4.4–4.6). This is pure `2 × 2` complex-matrix mathematics: the matrix exponential +is Mathlib's `NormedSpace.exp`, and the statements involve only `pauliDot n = n·σ`, matrices, and +the real trigonometric functions. + +## What is formalized + +* `rotAxis n θ = exp(−i (θ/2) (n·σ))` — the rotation operator (eq. 4.8), for *any* three-vector `n`. +* `rotAxis_eq_of_unit` — the closed form `R_n̂(θ) = cos(θ/2) I − i sin(θ/2) (n·σ)` for a unit `n` + (the right-hand side of eq. 4.8), reusing the Exercise 2.35 exponential `pauliDot_exp_of_unit`. +* `rotAxis_mem_unitaryGroup` — every rotation is unitary. This holds for *any* axis: the exponent + `A = −i(θ/2)(n·σ)` is skew-Hermitian (`n·σ` is Hermitian), and `exp` commutes with the adjoint + (`Matrix.exp_conjTranspose`), so `Rᴴ R = exp(−A) exp(A) = exp 0 = I`. +* `rotAxis_mul_same` / `rotAxis_zero` — the one-parameter group law `R_n̂(a) R_n̂(b) = R_n̂(a+b)` + and `R_n̂(0) = I`, both immediate from `exp(A) exp(B) = exp(A+B)` for the commuting exponents + about a fixed axis. +* `rotX`, `rotY`, `rotZ` — the coordinate rotations (eq. 4.4–4.6), with their explicit `2 × 2` + closed forms `rotX_eq`, `rotY_eq`, `rotZ_eq` and unitarity. + +These rotation operators are the shared foundation for the Chapter 4 single-qubit-decomposition +items — the Z-Y decomposition (Theorem 4.1), the ABC decomposition (Corollary 4.2), and the many +exercises about `R_n̂` (Ex 4.4–4.11). Everything here names raw matrix data only, so it lives in +`Concrete/`. + +## Design notes + +* `R_n̂(θ)` is defined literally as N&C's `exp(−iθ(n·σ)/2)` (not as an explicit matrix), so the + definition is manifestly faithful to eq. 4.8 and unitarity/the group law are inherited from the + exponential. The explicit matrices (eq. 4.4–4.6) are then *theorems* + (`rotX_eq`/`rotY_eq`/`rotZ_eq`), computed from the closed form and `pauliDot_eq`. +* The axis is a bare `Fin 3 → ℝ` with normalization the scalar hypothesis + `n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1`, matching `Concrete/Pauli.lean` and N&C's `n̂ · σ ≡ Σᵢ nᵢ σᵢ`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex NormedSpace + +/-- The **rotation operator** `R_n̂(θ) ≡ exp(−iθ (n·σ)/2)` about the axis `n` by angle `θ` +(Nielsen & Chuang, eq. 4.8). Defined for any three-vector `n`; for a unit vector it has the closed +form `cos(θ/2) I − i sin(θ/2) (n·σ)` (`rotAxis_eq_of_unit`). -/ +noncomputable def rotAxis (n : Fin 3 → ℝ) (θ : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := + exp ((((-(θ / 2) : ℝ) : ℂ) * Complex.I) • pauliDot n) + +/-- The **closed form** of the rotation operator (Nielsen & Chuang, eq. 4.8, right-hand side): for a +unit axis `n` (`n₀² + n₁² + n₂² = 1`), +`R_n̂(θ) = cos(θ/2) • I − (sin(θ/2) · i) • (n·σ)`. +This is the Exercise 2.35 exponential `pauliDot_exp_of_unit` at angle `−θ/2`. -/ +theorem rotAxis_eq_of_unit {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) : + rotAxis n θ = (Real.cos (θ / 2) : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ) + - ((Real.sin (θ / 2) : ℂ) * Complex.I) • pauliDot n := by + rw [rotAxis, pauliDot_exp_of_unit hn, Real.cos_neg, Real.sin_neg] + push_cast + module + +/-- Each rotation operator is **unitary** in the sense of `Rᴴ R = I`. This needs no unit hypothesis: +the exponent `A = −i(θ/2)(n·σ)` is skew-Hermitian (`Aᴴ = −A`, since `(n·σ)ᴴ = n·σ`), so +`Rᴴ R = (exp A)ᴴ exp A = exp(Aᴴ) exp A = exp(−A) exp A = exp(−A + A) = exp 0 = I` +using `Matrix.exp_conjTranspose` and `exp(X)exp(Y) = exp(X+Y)` for the commuting `−A, A`. -/ +theorem rotAxis_conjTranspose_mul_self (n : Fin 3 → ℝ) (θ : ℝ) : + (rotAxis n θ)ᴴ * rotAxis n θ = 1 := by + set A : Matrix (Fin 2) (Fin 2) ℂ := (((-(θ / 2) : ℝ) : ℂ) * Complex.I) • pauliDot n with hA + have hskew : Aᴴ = -A := by + rw [hA, conjTranspose_smul, pauliDot_conjTranspose, + show star (((-(θ / 2) : ℝ) : ℂ) * Complex.I) = -(((-(θ / 2) : ℝ) : ℂ) * Complex.I) by + simp [Complex.conj_I], neg_smul] + have hcomm : Commute (-A) A := (Commute.refl A).neg_left + calc (rotAxis n θ)ᴴ * rotAxis n θ + = exp Aᴴ * exp A := by rw [rotAxis, ← Matrix.exp_conjTranspose] + _ = exp (-A) * exp A := by rw [hskew] + _ = exp (-A + A) := (Matrix.exp_add_of_commute (-A) A hcomm).symm + _ = 1 := by rw [neg_add_cancel, NormedSpace.exp_zero] + +/-- Each rotation operator is **unitary** (`R ∈ unitaryGroup`), the group-membership form of +`rotAxis_conjTranspose_mul_self`. -/ +theorem rotAxis_mem_unitaryGroup (n : Fin 3 → ℝ) (θ : ℝ) : + rotAxis n θ ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + rw [Matrix.mem_unitaryGroup_iff', star_eq_conjTranspose] + exact rotAxis_conjTranspose_mul_self n θ + +/-- Each rotation operator is **unitary** in the sense of `R Rᴴ = I` (the companion of +`rotAxis_conjTranspose_mul_self`'s `Rᴴ R = I`), the group-membership `rotAxis_mem_unitaryGroup` +read as `R * star R = 1`. -/ +theorem rotAxis_mul_conjTranspose_self (n : Fin 3 → ℝ) (θ : ℝ) : + rotAxis n θ * (rotAxis n θ)ᴴ = 1 := by + rw [← star_eq_conjTranspose] + exact Matrix.mem_unitaryGroup_iff.mp (rotAxis_mem_unitaryGroup n θ) + +/-- The **one-parameter group law** for rotations about a fixed axis: +`R_n̂(a) R_n̂(b) = R_n̂(a+b)`. Both factors are `exp` of scalar multiples of the same `n·σ`, which +commute, so `exp exp = exp(sum)`. -/ +theorem rotAxis_mul_same (n : Fin 3 → ℝ) (a b : ℝ) : + rotAxis n a * rotAxis n b = rotAxis n (a + b) := by + have hcomm : Commute ((((-(a / 2) : ℝ) : ℂ) * Complex.I) • pauliDot n) + ((((-(b / 2) : ℝ) : ℂ) * Complex.I) • pauliDot n) := + ((Commute.refl (pauliDot n)).smul_left _).smul_right _ + rw [rotAxis, rotAxis, rotAxis, ← Matrix.exp_add_of_commute _ _ hcomm, ← add_smul] + congr 2 + push_cast + ring + +/-- The **zero rotation** is the identity: `R_n̂(0) = I` (`exp 0 = I`). -/ +theorem rotAxis_zero (n : Fin 3 → ℝ) : rotAxis n 0 = 1 := by + rw [rotAxis] + simp only [neg_zero, zero_div, Complex.ofReal_zero, zero_mul, zero_smul, NormedSpace.exp_zero] + +/-- **Iterating a rotation composes the angle:** `R_n̂(θ)^k = R_n̂(kθ)`, by induction from the +one-parameter group law `rotAxis_mul_same`. -/ +theorem rotAxis_pow (n : Fin 3 → ℝ) (θ : ℝ) (k : ℕ) : rotAxis n θ ^ k = rotAxis n (k * θ) := by + induction k with + | zero => simp [rotAxis_zero] + | succ m ih => rw [pow_succ, ih, rotAxis_mul_same]; congr 1; push_cast; ring + +/-- The **rotation about the `x̂` axis** `R_x(θ) ≡ exp(−iθX/2)` (Nielsen & Chuang, eq. 4.4). -/ +noncomputable def rotX (θ : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := rotAxis ![1, 0, 0] θ + +/-- The **rotation about the `y_hat` axis** `R_y(θ) ≡ exp(−iθY/2)` (Nielsen & Chuang, eq. 4.5). -/ +noncomputable def rotY (θ : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := rotAxis ![0, 1, 0] θ + +/-- The **rotation about the `e_z` axis** `R_z(θ) ≡ exp(−iθZ/2)` (Nielsen & Chuang, eq. 4.6). -/ +noncomputable def rotZ (θ : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := rotAxis ![0, 0, 1] θ + +/-- The explicit matrix of `R_x` (Nielsen & Chuang, eq. 4.4): +`R_x(θ) = !![cos(θ/2), −i sin(θ/2); −i sin(θ/2), cos(θ/2)]`. -/ +theorem rotX_eq (θ : ℝ) : + rotX θ = !![(Real.cos (θ / 2) : ℂ), -(Real.sin (θ / 2) : ℂ) * Complex.I; + -(Real.sin (θ / 2) : ℂ) * Complex.I, (Real.cos (θ / 2) : ℂ)] := by + rw [rotX, rotAxis_eq_of_unit (by simp), pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp + +/-- **One-parameter group law for `x`-rotations:** `R_x(a) R_x(b) = R_x(a+b)`, the coordinate case +of `rotAxis_mul_same` (companion to `rotY_mul_rotY`/`rotZ_mul_rotZ`). -/ +theorem rotX_mul_rotX (a b : ℝ) : rotX a * rotX b = rotX (a + b) := rotAxis_mul_same _ a b + +/-- The explicit matrix of `R_y` (Nielsen & Chuang, eq. 4.5): +`R_y(θ) = !![cos(θ/2), −sin(θ/2); sin(θ/2), cos(θ/2)]`. -/ +theorem rotY_eq (θ : ℝ) : + rotY θ = !![(Real.cos (θ / 2) : ℂ), -(Real.sin (θ / 2) : ℂ); + (Real.sin (θ / 2) : ℂ), (Real.cos (θ / 2) : ℂ)] := by + rw [rotY, rotAxis_eq_of_unit (by simp), pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Complex.ext_iff] + +/-- The explicit matrix of `R_z` (Nielsen & Chuang, eq. 4.6): +`R_z(θ) = !![exp(−iθ/2), 0; 0, exp(iθ/2)]` (a diagonal phase). -/ +theorem rotZ_eq (θ : ℝ) : + rotZ θ = !![Complex.exp (-(θ / 2) * Complex.I), 0; 0, Complex.exp ((θ / 2) * Complex.I)] := by + have e1 : Complex.exp (-(θ / 2) * Complex.I) + = (Real.cos (θ / 2) : ℂ) - (Real.sin (θ / 2) : ℂ) * Complex.I := by + rw [show (-(θ / 2) : ℂ) * Complex.I = ((-(θ / 2) : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, Real.cos_neg, Real.sin_neg] + push_cast; ring + have e2 : Complex.exp ((θ / 2) * Complex.I) + = (Real.cos (θ / 2) : ℂ) + (Real.sin (θ / 2) : ℂ) * Complex.I := by + rw [show ((θ / 2) : ℂ) * Complex.I = ((θ / 2 : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin] + rw [rotZ, rotAxis_eq_of_unit (by simp), pauliDot_eq, e1, e2] + ext i j + fin_cases i <;> fin_cases j <;> simp + +/-- `R_x(θ)` is unitary. -/ +theorem rotX_mem_unitaryGroup (θ : ℝ) : rotX θ ∈ Matrix.unitaryGroup (Fin 2) ℂ := + rotAxis_mem_unitaryGroup _ θ + +/-- `R_y(θ)` is unitary. -/ +theorem rotY_mem_unitaryGroup (θ : ℝ) : rotY θ ∈ Matrix.unitaryGroup (Fin 2) ℂ := + rotAxis_mem_unitaryGroup _ θ + +/-- `R_z(θ)` is unitary. -/ +theorem rotZ_mem_unitaryGroup (θ : ℝ) : rotZ θ ∈ Matrix.unitaryGroup (Fin 2) ℂ := + rotAxis_mem_unitaryGroup _ θ + +/-- The `(0,0)` diagonal entry of `R_z(θ) = diag(e^{-iθ/2}, e^{iθ/2})` is `e^{-iθ/2}` — the +eigenvalue of the `z`-rotation on `|0⟩`. -/ +theorem rotZ_apply_zero_zero (θ : ℝ) : + rotZ θ 0 0 = Complex.exp (-(θ / 2) * Complex.I) := by + rw [rotZ_eq]; simp + +/-- The `(1,1)` diagonal entry of `R_z(θ) = diag(e^{-iθ/2}, e^{iθ/2})` is `e^{iθ/2}` — the +eigenvalue of the `z`-rotation on `|1⟩`. -/ +theorem rotZ_apply_one_one (θ : ℝ) : + rotZ θ 1 1 = Complex.exp ((θ / 2) * Complex.I) := by + rw [rotZ_eq]; simp + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/RotationConjugation.lean b/LeanPool/AxQM/Concrete/RotationConjugation.lean new file mode 100644 index 0000000000..4d4568fa40 --- /dev/null +++ b/LeanPool/AxQM/Concrete/RotationConjugation.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation + +/-! +# Concrete: conjugating the single-qubit rotations by Pauli-`X` (Nielsen & Chuang, Exercise 4.7) + +Nielsen & Chuang, Exercise 4.7 asks to show `X Y X = -Y` and to use it to prove +`X R_y(θ) X = R_y(-θ)`. Both are `2 × 2` complex-matrix identities, stated for the concrete +Pauli matrices `pauliX`/`pauliY`/`pauliZ` and the rotation operators `rotY`/`rotZ`. + +## What is formalized + +* `pauliX_mul_pauliY_mul_pauliX` — `X Y X = -Y` (Exercise 4.7, first part). +* `pauliX_mul_pauliZ_mul_pauliX` — `X Z X = -Z` (the same computation for `Z`). +* `pauliX_mul_rotY_mul_pauliX` — `X R_y(θ) X = R_y(-θ)` (Exercise 4.7, second part). +* `pauliX_mul_rotZ_mul_pauliX` — `X R_z(θ) X = R_z(-θ)` (the `R_z` analogue). + +The two `X σ X = -σ` facts hold because conjugation by `X` fixes `X` but negates the two Pauli +matrices that anticommute with it. Since `R_a(θ) = cos(θ/2) I − i sin(θ/2) a` for `a ∈ {Y, Z}` +(the closed form of eq. 4.5/4.6) and `X I X = I`, conjugation by `X` therefore flips the sign of +the `sin` term, i.e. sends `θ ↦ −θ`: +`X R_a(θ) X = cos(θ/2) I − i sin(θ/2) (X a X) = cos(θ/2) I + i sin(θ/2) a = R_a(−θ)`. + +## Use in later results + +These conjugation identities are the shared foundation for the `X`-based reshufflings in +Chapter 4's single-qubit decompositions. In particular the ABC decomposition (N&C Corollary 4.2) +uses exactly `X R_y(θ) X = R_y(-θ)` and `X R_z(θ) X = R_z(-θ)` to move the two `X` gates through +the middle rotation `B`. + +## Design notes + +* The two rotation identities are proved directly from the explicit closed-form matrices + `rotY_eq`/`rotZ_eq` (eq. 4.5/4.6) by the entrywise `2 × 2` computation, with the sign flip + supplied by `Real.cos_neg`/`Real.sin_neg`. This is the same reduce-to-a-closed-form-and-compute + idiom used throughout `Concrete/Pauli.lean` and `Concrete/Rotation.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **Nielsen & Chuang, Exercise 4.7 (first part)**: conjugating `Y` by `X` negates it, +`X Y X = -Y`. -/ +theorem pauliX_mul_pauliY_mul_pauliX : pauliX * pauliY * pauliX = -pauliY := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, pauliY, Matrix.mul_apply, Fin.sum_univ_two, Matrix.neg_apply] + +/-- Conjugating `Z` by `X` negates it, `X Z X = -Z` (the analogue of the first part of +Exercise 4.7 for `Z`; used in the ABC decomposition, Corollary 4.2). -/ +theorem pauliX_mul_pauliZ_mul_pauliX : pauliX * pauliZ * pauliX = -pauliZ := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, pauliZ, Matrix.mul_apply, Fin.sum_univ_two, Matrix.neg_apply] + +/-- **Nielsen & Chuang, Exercise 4.7 (second part)**: `X R_y(θ) X = R_y(-θ)`. Conjugation by `X` +negates the `Y` component of the rotation, sending `θ ↦ -θ`. -/ +theorem pauliX_mul_rotY_mul_pauliX (θ : ℝ) : pauliX * rotY θ * pauliX = rotY (-θ) := by + rw [rotY_eq, rotY_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, Matrix.mul_apply, Fin.sum_univ_two, Real.cos_neg, Real.sin_neg, neg_div] + +/-- `X R_z(θ) X = R_z(-θ)` (the `R_z` analogue of Exercise 4.7). Conjugation by `X` swaps the two +diagonal phases `exp(∓iθ/2)`, which is exactly `R_z(-θ)`. Used in the ABC decomposition +(Corollary 4.2). -/ +theorem pauliX_mul_rotZ_mul_pauliX (θ : ℝ) : pauliX * rotZ θ * pauliX = rotZ (-θ) := by + rw [rotZ_eq, rotZ_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp [pauliX, Matrix.mul_apply, Fin.sum_univ_two, Complex.ofReal_neg, neg_div] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/RotationDecomposition.lean b/LeanPool/AxQM/Concrete/RotationDecomposition.lean new file mode 100644 index 0000000000..2f6cd4e606 --- /dev/null +++ b/LeanPool/AxQM/Concrete/RotationDecomposition.lean @@ -0,0 +1,245 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Rotation +public import Mathlib.LinearAlgebra.Matrix.NonsingularInverse +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse + +/-! +# Concrete: the Z–Y decomposition of a single-qubit unitary (Nielsen & Chuang, Theorem 4.1) + +Building on the rotation matrices +`rotY`, `rotZ` of `Concrete/Rotation.lean` (N&C eqs. 4.5, 4.6), it proves the **Z–Y decomposition** +— **Nielsen & Chuang, Theorem 4.1** (eq. 4.11): every single-qubit unitary `U` factors as + +`U = e^{iα} R_z(β) R_y(γ) R_z(δ)` + +for some real `α, β, γ, δ`. This is the algebraic backbone of the construction of controlled +single-qubit operations (Corollary 4.2 and §4.3). + +## What is formalised + +* `rotZ_mul_rotY_mul_rotZ` — the closed form of the product `R_z(β) R_y(γ) R_z(δ)` as the single + `2 × 2` matrix of N&C eq. (4.12) (up to the global phase). This is the reusable computational + core, obtained from the explicit-matrix lemmas `rotZ_eq`/`rotY_eq` and `Matrix.mul_fin_two`. +* `exists_zy_decomposition` — **Theorem 4.1 itself**: for `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` + there exist real `α, β, γ, δ` with `U = e^{iα} • (R_z(β) R_y(γ) R_z(δ))`. +* `zyMatrixForm` — the entry-explicit matrix of N&C eq. (4.12) itself: the diagonal entries + `e^{i(α ∓ β/2 ∓ δ/2)} cos(γ/2)` and off-diagonal `∓ e^{i(α ∓ β/2 ± δ/2)} sin(γ/2)`, with the + global phase `e^{iα}` folded in. +* `zyMatrixForm_eq_smul_rotZ_mul_rotY_mul_rotZ` — the bridge `zyMatrixForm α β γ δ = + e^{iα} • (R_z(β) R_y(γ) R_z(δ))`, folding the phase of `rotZ_mul_rotY_mul_rotZ` into each entry. +* `exists_zyMatrixForm` — **Nielsen & Chuang, Exercise 4.9**: every unitary + `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` can be written in the explicit form (4.12), i.e. + `∃ α β γ δ, U = zyMatrixForm α β γ δ`. It is the entrywise restatement of Theorem 4.1, obtained by + applying the bridge to `exists_zy_decomposition`. + +## Design notes + +* **`rotY`/`rotZ` are reused, not redefined.** The rotation matrices come from + `Concrete/Rotation.lean` (where `R_n̂(θ) ≡ exp(-iθ(n·σ)/2)` and `rotY`/`rotZ` are its + coordinate cases); here we consume their explicit-matrix forms `rotY_eq`/`rotZ_eq` and add only + the decomposition-specific results, so there is a single source of truth for the rotations. +* **"Unitary" as `Matrix.unitaryGroup`.** A single-qubit unitary is a `2 × 2` complex matrix with + `Uᴴ U = I`, i.e. membership in `Matrix.unitaryGroup (Fin 2) ℂ` — N&C's own definition of a + quantum gate. No dimension or determinant is fixed, so the statement is Theorem 4.1 in full + generality (all of `U(2)`, not just `SU(2)`). +* **Proof.** The four entries of `U` are pinned by unitarity: writing `a = U₀₀`, `c = U₁₀`, the + columns are orthonormal so `‖a‖² + ‖c‖² = 1`, and `Uᴴ = U⁻¹ = (det U)⁻¹ · adj U` forces + `U₁₁ = det U · conj a` and `U₀₁ = -det U · conj c` (via `adjugate_fin_two`). Choosing + `α = arg(det U)/2`, `β = arg c - arg a`, `γ = 2 arccos ‖a‖`, `δ = arg(det U) - arg a - arg c` and + reading each entry through the polar form `z = ‖z‖ e^{i arg z}` matches + `e^{iα} R_z(β) R_y(γ) R_z(δ)` entrywise. The `det`-based bookkeeping computes the phases of the + two "dependent" entries `U₁₁, U₀₁` from their closed forms rather than from `arg U₁₁`, `arg U₀₁` + directly — avoiding the mod-`2π` ambiguity of `Complex.arg` on a product. + +The statement of Theorem 4.1 is `exists_zy_decomposition`, in [upstream `AxQM/NC/Ch4/Theorem4_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Theorem4_1.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The product `R_z(β) R_y(γ) R_z(δ)` in closed form (Nielsen & Chuang eq. 4.12, without the +global phase): a single `2 × 2` matrix whose entries are `e^{∓i(β±δ)/2}` times `cos(γ/2)` +(diagonal) or `sin(γ/2)` (off-diagonal). This is the computational core of the Z–Y decomposition +(`exists_zy_decomposition`), obtained from the explicit forms `rotZ_eq`/`rotY_eq`. -/ +theorem rotZ_mul_rotY_mul_rotZ (β γ δ : ℝ) : + rotZ β * rotY γ * rotZ δ = + !![Complex.exp ((-((β : ℂ) + δ) / 2) * I) * (Real.cos (γ / 2) : ℂ), + -(Complex.exp ((-((β : ℂ) - δ) / 2) * I) * (Real.sin (γ / 2) : ℂ)); + Complex.exp (((β : ℂ) - δ) / 2 * I) * (Real.sin (γ / 2) : ℂ), + Complex.exp (((β : ℂ) + δ) / 2 * I) * (Real.cos (γ / 2) : ℂ)] := by + rw [rotZ_eq, rotY_eq, rotZ_eq] + simp only [Matrix.mul_fin_two, mul_zero, zero_mul, add_zero, zero_add, mul_neg, neg_zero] + rw [show (-((β : ℂ) + δ) / 2 * I) = (-(β : ℂ) / 2 * I) + (-(δ : ℂ) / 2 * I) by ring, + show (-((β : ℂ) - δ) / 2 * I) = (-(β : ℂ) / 2 * I) + ((δ : ℂ) / 2 * I) by ring, + show (((β : ℂ) - δ) / 2 * I) = ((β : ℂ) / 2 * I) + (-(δ : ℂ) / 2 * I) by ring, + show (((β : ℂ) + δ) / 2 * I) = ((β : ℂ) / 2 * I) + ((δ : ℂ) / 2 * I) by ring, + Complex.exp_add, Complex.exp_add, Complex.exp_add, Complex.exp_add] + ring_nf + +/-- **Nielsen & Chuang, Theorem 4.1 (Z–Y decomposition of a single-qubit unitary).** Every +`2 × 2` unitary `U` (a single-qubit gate, `Uᴴ U = I`) factors as +`U = e^{iα} R_z(β) R_y(γ) R_z(δ)` for some real numbers `α, β, γ, δ` (eq. 4.11). The angles are +extracted from the entries of `U`: `α = arg(det U)/2`, `β = arg U₁₀ - arg U₀₀`, +`γ = 2 arccos ‖U₀₀‖`, `δ = arg(det U) - arg U₀₀ - arg U₁₀`, and the equality is checked entrywise +against the closed form `rotZ_mul_rotY_mul_rotZ` using the polar decomposition of each entry and +the unitarity constraints `‖U₀₀‖² + ‖U₁₀‖² = 1`, `U₁₁ = det U · conj U₀₀`, +`U₀₁ = -det U · conj U₁₀`. -/ +theorem exists_zy_decomposition (U : Matrix (Fin 2) (Fin 2) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ α β γ δ : ℝ, U = Complex.exp ((α : ℂ) * Complex.I) • (rotZ β * rotY γ * rotZ δ) := by + have hUsU : U * star U = 1 := (Matrix.mem_unitaryGroup_iff).1 hU + have hsUU : star U * U = 1 := (Matrix.mem_unitaryGroup_iff').1 hU + -- `det U` is a unit, with inverse `det (star U)`. + have hunit : IsUnit U.det := + IsUnit.of_mul_eq_one (star U).det (by rw [← Matrix.det_mul, hUsU, Matrix.det_one]) + have hrmul : U.det * Ring.inverse U.det = 1 := Ring.mul_inverse_cancel _ hunit + -- `star U = U⁻¹ = (det U)⁻¹ • adj U`, and `adj` of a `2 × 2` matrix is explicit. + have hstar : star U = Ring.inverse U.det • !![U 1 1, -U 0 1; -U 1 0, U 0 0] := by + rw [(Matrix.inv_eq_left_inv hsUU).symm, Matrix.inv_def, Matrix.adjugate_fin_two] + -- The two "dependent" entries in closed form. + have hd : U 1 1 = U.det * star (U 0 0) := by + have h := congrFun (congrFun hstar 0) 0 + simp only [Matrix.star_eq_conjTranspose, Matrix.conjTranspose_apply, Matrix.smul_apply, + Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, Matrix.empty_val', + Matrix.cons_val_fin_one, smul_eq_mul] at h + rw [h, ← mul_assoc, hrmul, one_mul] + have hb : U 0 1 = -(U.det * star (U 1 0)) := by + have h := congrFun (congrFun hstar 0) 1 + simp only [Matrix.star_eq_conjTranspose, Matrix.conjTranspose_apply, Matrix.smul_apply, + Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, smul_eq_mul] at h + rw [h, ← mul_assoc, hrmul, one_mul, neg_neg] + -- Column `0` of `U` is a unit vector. + have hcol : ‖U 0 0‖ ^ 2 + ‖U 1 0‖ ^ 2 = 1 := by + have h := congrFun (congrFun hsUU 0) 0 + simp only [Matrix.mul_apply, Fin.sum_univ_two, Matrix.star_eq_conjTranspose, + Matrix.conjTranspose_apply, Matrix.one_apply_eq] at h + simp only [← starRingEnd_apply] at h + rw [Complex.conj_mul', Complex.conj_mul'] at h + exact_mod_cast h + -- `|det U| = 1`. + have hdetnorm : ‖U.det‖ = 1 := by + have hmul : ‖U.det‖ * ‖U.det‖ = 1 := by + have e1 : ‖U.det‖ * ‖(star U).det‖ = 1 := by + rw [← norm_mul, ← Matrix.det_mul, hUsU, Matrix.det_one, norm_one] + rwa [Matrix.star_eq_conjTranspose, Matrix.det_conjTranspose, norm_star] at e1 + rcases mul_self_eq_one_iff.1 hmul with h | h + · exact h + · have := norm_nonneg U.det; linarith + -- Magnitude/angle facts for `γ = 2 arccos ‖U₀₀‖`. + have hna1 : ‖U 0 0‖ ≤ 1 := by nlinarith [hcol, norm_nonneg (U 0 0), sq_nonneg ‖U 1 0‖] + have hna0 : (-1 : ℝ) ≤ ‖U 0 0‖ := le_trans (by norm_num) (norm_nonneg _) + have hcos : Real.cos (2 * Real.arccos ‖U 0 0‖ / 2) = ‖U 0 0‖ := by + rw [show 2 * Real.arccos ‖U 0 0‖ / 2 = Real.arccos ‖U 0 0‖ by ring, Real.cos_arccos hna0 hna1] + have hsin : Real.sin (2 * Real.arccos ‖U 0 0‖ / 2) = ‖U 1 0‖ := by + rw [show 2 * Real.arccos ‖U 0 0‖ / 2 = Real.arccos ‖U 0 0‖ by ring, Real.sin_arccos, + show 1 - ‖U 0 0‖ ^ 2 = ‖U 1 0‖ ^ 2 by linarith [hcol], Real.sqrt_sq (norm_nonneg _)] + -- Polar forms. + have hdet : U.det = Complex.exp ((↑U.det.arg : ℂ) * I) := by + conv_lhs => rw [← Complex.norm_mul_exp_arg_mul_I U.det] + rw [hdetnorm]; simp + have hstarEq : ∀ z : ℂ, star z = (↑‖z‖ : ℂ) * Complex.exp (-↑z.arg * I) := by + intro z + have h := congrArg (starRingEnd ℂ) (Complex.norm_mul_exp_arg_mul_I z) + rw [map_mul, Complex.conj_ofReal, ← Complex.exp_conj, map_mul, Complex.conj_ofReal, + Complex.conj_I, show (↑z.arg : ℂ) * -I = -↑z.arg * I by ring] at h + exact h.symm + have detConj : ∀ z : ℂ, + U.det * star z = (↑‖z‖ : ℂ) * Complex.exp ((↑U.det.arg - ↑z.arg) * I) := by + intro z + rw [hstarEq z] + conv_lhs => rw [hdet] + rw [show Complex.exp ((↑U.det.arg : ℂ) * I) * (↑‖z‖ * Complex.exp (-↑z.arg * I)) + = ↑‖z‖ * (Complex.exp ((↑U.det.arg : ℂ) * I) * Complex.exp (-↑z.arg * I)) by ring, + ← Complex.exp_add, + show ((↑U.det.arg : ℂ) * I + -↑z.arg * I) = (↑U.det.arg - ↑z.arg) * I by ring] + have hU11 : U 1 1 = (↑‖U 0 0‖ : ℂ) * Complex.exp ((↑U.det.arg - ↑(U 0 0).arg) * I) := by + rw [hd]; exact detConj (U 0 0) + have hU01 : U 0 1 = -((↑‖U 1 0‖ : ℂ) * Complex.exp ((↑U.det.arg - ↑(U 1 0).arg) * I)) := by + rw [hb, detConj (U 1 0)] + -- The reassembly identity: `e^{iα} · e^{iw} · ↑m = ↑m · e^{iθ}` when `α + w = θ`. + have fin4 : ∀ (m : ℝ) (w θ : ℂ), (↑(U.det.arg / 2) : ℂ) * I + w = θ → + (↑m : ℂ) * Complex.exp θ + = Complex.exp ((↑(U.det.arg / 2) : ℂ) * I) * (Complex.exp w * ↑m) := by + intro m w θ hE + rw [show Complex.exp ((↑(U.det.arg / 2) : ℂ) * I) * (Complex.exp w * ↑m) + = ↑m * (Complex.exp ((↑(U.det.arg / 2) : ℂ) * I) * Complex.exp w) by ring, + ← Complex.exp_add, hE] + refine ⟨U.det.arg / 2, (U 1 0).arg - (U 0 0).arg, 2 * Real.arccos ‖U 0 0‖, + U.det.arg - (U 0 0).arg - (U 1 0).arg, ?_⟩ + rw [rotZ_mul_rotY_mul_rotZ] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, + Fin.mk_zero, Fin.mk_one, smul_eq_mul, hcos, hsin] + · -- (0,0): `U₀₀ = ‖U₀₀‖ e^{i arg U₀₀}` + rw [← fin4 ‖U 0 0‖ _ (↑(U 0 0).arg * I) (by push_cast; ring), + Complex.norm_mul_exp_arg_mul_I] + · -- (0,1): `U₀₁ = -det U · conj U₁₀` + rw [hU01, mul_neg, ← fin4 ‖U 1 0‖ _ ((↑U.det.arg - ↑(U 1 0).arg) * I) (by push_cast; ring)] + · -- (1,0): `U₁₀ = ‖U₁₀‖ e^{i arg U₁₀}` + rw [← fin4 ‖U 1 0‖ _ (↑(U 1 0).arg * I) (by push_cast; ring), + Complex.norm_mul_exp_arg_mul_I] + · -- (1,1): `U₁₁ = det U · conj U₀₀` + rw [hU11, ← fin4 ‖U 0 0‖ _ ((↑U.det.arg - ↑(U 0 0).arg) * I) (by push_cast; ring)] + +/-- The explicit `2 × 2` matrix of Nielsen & Chuang eq. (4.12): the Z–Y decomposition +`e^{iα} R_z(β) R_y(γ) R_z(δ)` written out entrywise, with the global phase `e^{iα}` folded into each +entry. Every entry is a phase `e^{i(α ± β/2 ± δ/2)}` times `cos(γ/2)` (diagonal) or `± sin(γ/2)` +(off-diagonal). This is the target form of N&C Exercise 4.9; +`zyMatrixForm_eq_smul_rotZ_mul_rotY_mul_rotZ` identifies it with the phased rotation product of the +Z–Y decomposition (`exists_zy_decomposition`). -/ +noncomputable def zyMatrixForm (α β γ δ : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := + !![Complex.exp (((α : ℂ) - (β : ℂ) / 2 - (δ : ℂ) / 2) * I) * (Real.cos (γ / 2) : ℂ), + -(Complex.exp (((α : ℂ) - (β : ℂ) / 2 + (δ : ℂ) / 2) * I) * (Real.sin (γ / 2) : ℂ)); + Complex.exp (((α : ℂ) + (β : ℂ) / 2 - (δ : ℂ) / 2) * I) * (Real.sin (γ / 2) : ℂ), + Complex.exp (((α : ℂ) + (β : ℂ) / 2 + (δ : ℂ) / 2) * I) * (Real.cos (γ / 2) : ℂ)] + +/-- The explicit matrix form (4.12) equals the global-phase-times-rotations product of the Z–Y +decomposition: `zyMatrixForm α β γ δ = e^{iα} • (R_z(β) R_y(γ) R_z(δ))`. Folding the phase `e^{iα}` +into each entry of the closed form `rotZ_mul_rotY_mul_rotZ` and combining the two exponentials +turns the phased product into the entrywise matrix of N&C eq. (4.12). -/ +theorem zyMatrixForm_eq_smul_rotZ_mul_rotY_mul_rotZ (α β γ δ : ℝ) : + zyMatrixForm α β γ δ = Complex.exp ((α : ℂ) * I) • (rotZ β * rotY γ * rotZ δ) := by + have key : ∀ (t p q r : ℂ), p = q + r → + Complex.exp p * t = Complex.exp q * (Complex.exp r * t) := fun t p q r hpqr => by + rw [hpqr, Complex.exp_add, mul_assoc] + rw [rotZ_mul_rotY_mul_rotZ, zyMatrixForm] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.of_apply, Matrix.cons_val', Matrix.cons_val_zero, + Matrix.cons_val_one, Matrix.empty_val', Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, + smul_eq_mul, mul_neg] + · exact key _ _ _ _ (by ring) + · rw [neg_inj]; exact key _ _ _ _ (by ring) + · exact key _ _ _ _ (by ring) + · exact key _ _ _ _ (by ring) + +/-- **Nielsen & Chuang, Exercise 4.9.** Any single-qubit unitary `U` (a `2 × 2` complex matrix with +`Uᴴ U = I`, i.e. `U ∈ Matrix.unitaryGroup (Fin 2) ℂ`) can be written in the explicit form (4.12): +there exist real numbers `α, β, γ, δ` with `U = zyMatrixForm α β γ δ`. Because `U` is unitary its +rows and columns are orthonormal, so the Z–Y decomposition (`exists_zy_decomposition`, Theorem 4.1) +yields angles with `U = e^{iα} R_z(β) R_y(γ) R_z(δ)`; rewriting that product entrywise via +`zyMatrixForm_eq_smul_rotZ_mul_rotY_mul_rotZ` puts `U` in the matrix form (4.12). -/ +theorem exists_zyMatrixForm (U : Matrix (Fin 2) (Fin 2) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ α β γ δ : ℝ, U = zyMatrixForm α β γ δ := by + obtain ⟨α, β, γ, δ, hUeq⟩ := exists_zy_decomposition U hU + refine ⟨α, β, γ, δ, ?_⟩ + rw [hUeq, zyMatrixForm_eq_smul_rotZ_mul_rotY_mul_rotZ] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/RotationDecompositionXY.lean b/LeanPool/AxQM/Concrete/RotationDecompositionXY.lean new file mode 100644 index 0000000000..6837b341d3 --- /dev/null +++ b/LeanPool/AxQM/Concrete/RotationDecompositionXY.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.RotationDecomposition +public import LeanPool.AxQM.Concrete.Hadamard + +/-! +# Concrete: the X–Y decomposition of a single-qubit unitary (Nielsen & Chuang, Exercise 4.10) + +Nielsen & Chuang, Exercise 4.10 +(*X–Y decomposition of rotations*) asks for a decomposition analogous to Theorem 4.1 (the Z–Y +decomposition) but using `R_x` instead of `R_z`: every single-qubit unitary `U` factors as + +`U = e^{iα} R_x(β) R_y(γ) R_x(δ)` + +for some real `α, β, γ, δ`. The statement of Exercise 4.10 is `exists_xy_decomposition`, in +[upstream `AxQM/NC/Ch4/Exercise4_10.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_10.lean). + +## What is formalised + +* `hadamardC_mul_rotZ_mul_hadamardC` — `H R_z(θ) H = R_x(θ)`: conjugating a `z`-rotation by the + Hadamard gate turns it into the `x`-rotation of the same angle (`H` exchanges the `x̂`/`e_z` + axes). +* `hadamardC_mul_rotY_mul_hadamardC` — `H R_y(θ) H = R_y(-θ)`: conjugating a `y`-rotation by `H` + negates its angle (`H` flips the `y_hat` axis, `H Y H = -Y`). +* `exists_xy_decomposition` — **Exercise 4.10 itself**: for `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` + there exist real `α, β, γ, δ` with `U = e^{iα} • (R_x(β) R_y(γ) R_x(δ))`. + +## Design notes + +* **Reduction to Theorem 4.1 by Hadamard conjugation, not a second entrywise derivation.** The + Hadamard gate is an involution (`H² = I`, `hadamardC_mul_self`) that exchanges the `x̂` and `e_z` + axes and flips `y_hat`; hence `H R_z(θ) H = R_x(θ)` and `H R_y(θ) H = R_y(-θ)`. For a unitary `U`, + `H U H` is again unitary, so the Z–Y decomposition (`exists_zy_decomposition`, Theorem 4.1) gives + `H U H = e^{iα} R_z(β) R_y(γ) R_z(δ)`. Conjugating back by `H` (using `H (H U H) H = U`, since + `H² = I`) and pushing the two `H`s through each factor turns every `R_z` into `R_x` and the middle + `R_y(γ)` into `R_y(-γ)`, giving `U = e^{iα} R_x(β) R_y(-γ) R_x(δ)`. The middle angle `-γ` is just + a real number, so this is the X–Y decomposition with `γ' := -γ`. Reusing Theorem 4.1 avoids + redoing + the entry-by-entry angle extraction from `U`. +* **"Unitary" as `Matrix.unitaryGroup`.** Exactly as in Theorem 4.1: a single-qubit unitary is a + `2 × 2` complex matrix with `Uᴴ U = I`, so the statement is Exercise 4.10 in full generality (all + of `U(2)`). +* **The conjugation lemmas are proved from the explicit closed forms** `rotZ_eq`/`rotX_eq`/`rotY_eq` + (eqs. 4.4–4.6) by the entrywise `2 × 2` computation, the same idiom as + `Concrete/HadamardRotation.lean` and `Concrete/RotationConjugation.lean`; the scalar `(√2)⁻¹² = ½` + collapses the Hadamard normalisation. They are named theorems because Hadamard conjugation of the + coordinate rotations is reusable Chapter-4 infrastructure. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- Conjugating the `z`-rotation by the Hadamard gate gives the `x`-rotation of the same angle: +`H R_z(θ) H = R_x(θ)`. The Hadamard reflection exchanges the `x̂` and `e_z` axes (`H Z H = X`), so +it +carries `R_z(θ) = exp(-iθZ/2)` to `R_x(θ) = exp(-iθX/2)`. Proved from the closed forms `rotZ_eq`, +`rotX_eq`: the diagonal phases `e^{∓iθ/2}` combine, via `H = (√2)⁻¹ !![1,1;1,-1]`, into the +`cos(θ/2)` / `-i sin(θ/2)` entries of `R_x`. -/ +theorem hadamardC_mul_rotZ_mul_hadamardC (θ : ℝ) : + hadamardC * rotZ θ * hadamardC = rotX θ := by + have e1 : Complex.exp (-(θ / 2) * Complex.I) + = (Real.cos (θ / 2) : ℂ) - (Real.sin (θ / 2) : ℂ) * Complex.I := by + rw [show (-(θ / 2) : ℂ) * Complex.I = ((-(θ / 2) : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, Real.cos_neg, Real.sin_neg] + push_cast; ring + have e2 : Complex.exp ((θ / 2) * Complex.I) + = (Real.cos (θ / 2) : ℂ) + (Real.sin (θ / 2) : ℂ) * Complex.I := by + rw [show ((θ / 2) : ℂ) * Complex.I = ((θ / 2 : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin] + rw [hadamardC, Matrix.smul_mul, Matrix.smul_mul, Matrix.mul_smul, smul_smul, + inv_sqrt_two_mul_self, rotZ_eq, rotX_eq, e1, e2] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.mul_apply, Fin.sum_univ_two, Matrix.of_apply, + Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.empty_val', + Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, smul_eq_mul, mul_zero, + add_zero, zero_add] <;> + ring + +/-- Conjugating the `y`-rotation by the Hadamard gate negates its angle: `H R_y(θ) H = R_y(-θ)`. +The Hadamard reflection flips the `y_hat` axis (`H Y H = -Y`), so it sends `R_y(θ) = exp(-iθY/2)` to +`exp(iθY/2) = R_y(-θ)`. Proved from the closed form `rotY_eq` by the entrywise `2 × 2` computation, +with the sign flip supplied by `Real.cos_neg` / `Real.sin_neg`. -/ +theorem hadamardC_mul_rotY_mul_hadamardC (θ : ℝ) : + hadamardC * rotY θ * hadamardC = rotY (-θ) := by + rw [hadamardC, Matrix.smul_mul, Matrix.smul_mul, Matrix.mul_smul, smul_smul, + inv_sqrt_two_mul_self, rotY_eq, rotY_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Matrix.smul_apply, Matrix.mul_apply, Fin.sum_univ_two, Matrix.of_apply, + Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.empty_val', + Matrix.cons_val_fin_one, Fin.mk_zero, Fin.mk_one, smul_eq_mul, neg_div, + Real.cos_neg, Real.sin_neg, Complex.ofReal_neg] <;> + ring + +/-- **Nielsen & Chuang, Exercise 4.10 (X–Y decomposition of a single-qubit unitary).** Every +`2 × 2` unitary `U` (a single-qubit gate, `Uᴴ U = I`) factors as `U = e^{iα} R_x(β) R_y(γ) R_x(δ)` +for some real numbers `α, β, γ, δ` — Theorem 4.1 with `R_z` replaced by `R_x`. Since the Hadamard +gate `H` is an involution exchanging the `x̂`/`e_z` axes and flipping `y_hat`, the conjugate `H U +H` is +unitary, so the Z–Y decomposition (`exists_zy_decomposition`) yields +`H U H = e^{iα} R_z(β) R_y(γ) R_z(δ)`; conjugating back and pushing the `H`s through each factor +(`hadamardC_mul_rotZ_mul_hadamardC`, `hadamardC_mul_rotY_mul_hadamardC`) gives +`U = e^{iα} R_x(β) R_y(-γ) R_x(δ)`, i.e. the claim with middle angle `-γ`. -/ +theorem exists_xy_decomposition (U : Matrix (Fin 2) (Fin 2) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ α β γ δ : ℝ, U = Complex.exp ((α : ℂ) * Complex.I) • (rotX β * rotY γ * rotX δ) := by + -- `H U H` is unitary (product of unitaries). + have hHUH : hadamardC * U * hadamardC ∈ Matrix.unitaryGroup (Fin 2) ℂ := + mul_mem (mul_mem hadamardC_mem_unitaryGroup hU) hadamardC_mem_unitaryGroup + obtain ⟨α, β, γ, δ, hV⟩ := exists_zy_decomposition (hadamardC * U * hadamardC) hHUH + refine ⟨α, β, -γ, δ, ?_⟩ + -- Push the two `H`s through the phased Z–Y product (`hadamardC_conj_mul` is `H²=I` + -- multiplicativity of conjugation), turning each `R_z` into `R_x` and `R_y(γ)` into `R_y(-γ)`. + have key : hadamardC * (rotZ β * rotY γ * rotZ δ) * hadamardC + = rotX β * rotY (-γ) * rotX δ := by + rw [hadamardC_conj_mul, hadamardC_conj_mul, hadamardC_mul_rotZ_mul_hadamardC, + hadamardC_mul_rotY_mul_hadamardC, hadamardC_mul_rotZ_mul_hadamardC] + -- `U = H (H U H) H` (`hadamardC_conj_conj` is `H²=I` double-conjugation); substitute the Z–Y + -- decomposition of `H U H`, pull the phase out, and apply `key`. + rw [← hadamardC_conj_conj U, hV, Matrix.mul_smul, Matrix.smul_mul, key] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/RotationDensity.lean b/LeanPool/AxQM/Concrete/RotationDensity.lean new file mode 100644 index 0000000000..d575dc6f1b --- /dev/null +++ b/LeanPool/AxQM/Concrete/RotationDensity.lean @@ -0,0 +1,181 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.RotationDecompositionXY +public import LeanPool.AxQM.ToMathlib.NumberTheory.CosThreeFifthsIrrational +public import Mathlib.Topology.Algebra.Order.ArchimedeanDiscrete +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle + +/-! +# Concrete: iterating an irrational-angle `z`-rotation densely fills the `z`-rotations + +## Mathematical content (the analytic core of Nielsen & Chuang, Exercise 4.43) + +Nielsen & Chuang's Exercise 4.43 assembles the "universality of `H, S, CNOT, Toffoli`" from the two +preceding exercises: Exercise 4.41 realises the `z`-rotation `R_z(θ)` with `cos θ = 3/5` from those +gates (a measurement-based circuit), and Exercise 4.42 shows that `θ` is an *irrational* multiple of +`2π`. The step this file formalises is the inference N&C then draw — **repeated application of +`R_z(θ)` approximates any `R_z(α)` to arbitrary accuracy**: + +* `rotZ_mem_closure_range_zsmul` — if `θ / (2π)` is irrational then, for every angle `α`, the + rotation `R_z(α)` lies in the closure of `{R_z(nθ) : n ∈ ℤ}`. Equivalently, the cyclic group of + `z`-rotations generated by `R_z(θ)` is dense in the one-parameter family of all `z`-rotations. +* `rotZ_mem_closure_range_zsmul_of_cos_eq_three_div_five` — the same conclusion under the exercise's + hypothesis `cos θ = 3/5`, obtained from the number-theoretic Exercise 4.42 + (`irrational_div_two_pi_of_cos_eq_three_div_five`). +* `rotX_mem_closure_range_zsmul` / `rotX_mem_closure_range_zsmul_of_cos_eq_three_div_five` — the + corresponding density for the `x`-rotations, transported through the Hadamard conjugation + `H R_z(θ) H = R_x(θ)` (`hadamardC_mul_rotZ_mul_hadamardC`). Density for both non-commuting axes is + what feeds — via the Z–Y decomposition (`exists_zy_decomposition`, Theorem 4.1) — the + approximation of an arbitrary single-qubit unitary. + +## Design notes + +* **Why the integer powers.** The set `{R_z(nθ) : n ∈ ℤ}` is exactly the cyclic subgroup generated + by the gate `R_z(θ)` (its inverse `R_z(θ)⁻¹ = R_z(-θ)` is again available). This is the standard + "operations reachable by iterating the gate" and is the faithful reading of N&C's "repeated + iteration"; it is not a weakening (the forward `ℕ`-orbit is dense as well, by the same + equidistribution, but the subgroup statement is the natural group-theoretic one and is all the + universality argument needs). +* **Period `4π`, not `2π`.** `R_z` has period `4π` (`R_z(θ) = diag(e^{-iθ/2}, e^{iθ/2})`), so + `R_z(θ + 2π) = -R_z(θ)` differs from `R_z(θ)` by a global phase. To land on `R_z(α)` *on the nose* + (not merely up to sign) the density is proved through the two-generator subgroup `⟨θ, 4π⟩ ⊆ ℝ`: + it is dense because `θ / (2π)` is irrational (were `⟨θ, 4π⟩ = ⟨a⟩` cyclic, `θ` and `4π` would be + integer multiples of a common `a`, forcing `θ / (2π) = 2p/q ∈ ℚ`), and `R_z` is continuous and + constant on cosets of `4πℤ`, so its image of the dense subgroup is `{R_z(nθ)}` and its closure + contains the whole continuous image `Set.range rotZ`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **`R_z` is continuous** as a function of the rotation angle (each matrix entry is +`θ ↦ e^{±iθ/2}`, continuous). -/ +theorem continuous_rotZ : Continuous rotZ := by + refine continuous_matrix fun i j => ?_ + simp only [rotZ_eq] + fin_cases i <;> fin_cases j <;> + simp only [Fin.zero_eta, Fin.mk_one, Fin.isValue, of_apply, cons_val', cons_val_zero, + cons_val_one, cons_val_fin_one, empty_val'] <;> + fun_prop + +/-- **`R_z` has period `4π`:** shifting the angle by an integer multiple of `4π` leaves the +`z`-rotation unchanged, since `e^{-i(θ + 4πm)/2} = e^{-iθ/2} · e^{-2πi m} = e^{-iθ/2}`. -/ +theorem rotZ_add_zsmul_four_pi (θ : ℝ) (m : ℤ) : + rotZ (θ + m • (4 * Real.pi)) = rotZ θ := by + rw [rotZ_eq, rotZ_eq] + have hφ : ((θ + m • (4 * Real.pi) : ℝ) : ℂ) / 2 + = (θ : ℂ) / 2 + (m : ℂ) * (2 * Real.pi) := by + push_cast [zsmul_eq_mul]; ring + have e11 : Complex.exp (↑(θ + m • (4 * Real.pi)) / 2 * Complex.I) + = Complex.exp (↑θ / 2 * Complex.I) := by + rw [hφ, add_mul, Complex.exp_add, + show (m : ℂ) * (2 * ↑Real.pi) * Complex.I = (m : ℂ) * (2 * ↑Real.pi * Complex.I) by ring, + Complex.exp_int_mul_two_pi_mul_I, mul_one] + have e00 : Complex.exp (-(↑(θ + m • (4 * Real.pi)) / 2) * Complex.I) + = Complex.exp (-(↑θ / 2) * Complex.I) := by + rw [hφ, + show -(↑θ / 2 + (m : ℂ) * (2 * ↑Real.pi)) * Complex.I + = -(↑θ / 2) * Complex.I + ((-m : ℤ) : ℂ) * (2 * ↑Real.pi * Complex.I) by push_cast; ring, + Complex.exp_add, Complex.exp_int_mul_two_pi_mul_I, mul_one] + rw [e00, e11] + +/-- **The two-generator subgroup `⟨θ, 4π⟩ ⊆ ℝ` is dense** whenever `θ / (2π)` is irrational. If it +were cyclic, `⟨a⟩`, then `θ = p • a` and `4π = q • a` for integers `p, q` (with `q ≠ 0`), giving the +rational value `θ / (2π) = 2p/q` — contradicting the hypothesis. -/ +theorem dense_zmultiples_sup {θ : ℝ} (hθ : Irrational (θ / (2 * Real.pi))) : + Dense ((AddSubgroup.zmultiples θ ⊔ AddSubgroup.zmultiples (4 * Real.pi) : AddSubgroup ℝ) : + Set ℝ) := by + rw [AddSubgroup.dense_iff_not_isAddCyclic, AddSubgroup.isAddCyclic_iff_exists_zmultiples_eq] + rintro ⟨a, heq⟩ + replace heq := heq.symm + have hθmem : θ ∈ AddSubgroup.zmultiples a := by + rw [← heq]; exact AddSubgroup.mem_sup_left (AddSubgroup.mem_zmultiples θ) + have h4mem : 4 * Real.pi ∈ AddSubgroup.zmultiples a := by + rw [← heq]; exact AddSubgroup.mem_sup_right (AddSubgroup.mem_zmultiples (4 * Real.pi)) + obtain ⟨p, hp⟩ := AddSubgroup.mem_zmultiples_iff.mp hθmem + obtain ⟨q, hq⟩ := AddSubgroup.mem_zmultiples_iff.mp h4mem + rw [zsmul_eq_mul] at hp hq + have hq0 : (q : ℝ) ≠ 0 := by + rintro h0 + rw [h0, zero_mul] at hq + have := Real.pi_pos + linarith [hq] + apply hθ + refine ⟨2 * (p : ℚ) / (q : ℚ), ?_⟩ + have hqℝ : ((2 * (p : ℚ) / (q : ℚ) : ℚ) : ℝ) = 2 * (p : ℝ) / (q : ℝ) := by push_cast; ring + have ha : a = 4 * Real.pi / (q : ℝ) := by rw [eq_div_iff hq0, mul_comm]; exact hq + have key : θ / (2 * Real.pi) = 2 * (p : ℝ) / (q : ℝ) := by + rw [← hp, ha]; field_simp; ring + rw [hqℝ, key] + +/-- **Iterating `R_z(θ)` approximates every `z`-rotation** when `θ / (2π)` is irrational: for every +angle `α`, `R_z(α)` lies in the closure of the integer powers `{R_z(nθ) : n ∈ ℤ}`. + +`R_z` is continuous and `4π`-periodic, so it factors through the circle `ℝ / 4πℤ`; the two-generator +subgroup `⟨θ, 4π⟩` is dense in `ℝ` (`dense_zmultiples_sup`) and `R_z` collapses its `4πℤ` part, so +the continuous image of that dense subgroup is `{R_z(nθ)}` and its closure engulfs the entire family +`Set.range rotZ`. -/ +theorem rotZ_mem_closure_range_zsmul {θ : ℝ} (hθ : Irrational (θ / (2 * Real.pi))) (α : ℝ) : + rotZ α ∈ closure (Set.range fun n : ℤ => rotZ (n • θ)) := by + have hdense := dense_zmultiples_sup hθ + have hsub : rotZ '' + ((AddSubgroup.zmultiples θ ⊔ AddSubgroup.zmultiples (4 * Real.pi) : AddSubgroup ℝ) : Set ℝ) + ⊆ Set.range (fun n : ℤ => rotZ (n • θ)) := by + rintro _ ⟨x, hx, rfl⟩ + obtain ⟨y, hy, z, hz, rfl⟩ := AddSubgroup.mem_sup.mp hx + obtain ⟨k, rfl⟩ := AddSubgroup.mem_zmultiples_iff.mp hy + obtain ⟨m, rfl⟩ := AddSubgroup.mem_zmultiples_iff.mp hz + exact ⟨k, (rotZ_add_zsmul_four_pi (k • θ) m).symm⟩ + have h1 : rotZ α ∈ rotZ '' + (closure ((AddSubgroup.zmultiples θ ⊔ AddSubgroup.zmultiples (4 * Real.pi) : AddSubgroup ℝ) : + Set ℝ)) := by + rw [hdense.closure_eq]; exact ⟨α, Set.mem_univ α, rfl⟩ + exact closure_mono hsub (image_closure_subset_closure_image continuous_rotZ h1) + +/-- **Iterating `R_z(θ)` with `cos θ = 3/5` approximates every `z`-rotation** (Nielsen & Chuang, +Exercise 4.43, `z`-axis half). Combines `rotZ_mem_closure_range_zsmul` with Exercise 4.42 +(`irrational_div_two_pi_of_cos_eq_three_div_five`): `cos θ = 3/5` forces `θ / (2π)` irrational. -/ +theorem rotZ_mem_closure_range_zsmul_of_cos_eq_three_div_five {θ : ℝ} + (hθ : Real.cos θ = 3 / 5) (α : ℝ) : + rotZ α ∈ closure (Set.range fun n : ℤ => rotZ (n • θ)) := + rotZ_mem_closure_range_zsmul (irrational_div_two_pi_of_cos_eq_three_div_five hθ) α + +/-- **Iterating `R_x(θ)` approximates every `x`-rotation** when `θ / (2π)` is irrational. +Transported from the `z`-axis version through the Hadamard conjugation `H R_z(θ) H = R_x(θ)` +(`hadamardC_mul_rotZ_mul_hadamardC`), whose conjugation map `M ↦ H M H` is continuous. -/ +theorem rotX_mem_closure_range_zsmul {θ : ℝ} (hθ : Irrational (θ / (2 * Real.pi))) (α : ℝ) : + rotX α ∈ closure (Set.range fun n : ℤ => rotX (n • θ)) := by + have hg : Continuous (fun M : Matrix (Fin 2) (Fin 2) ℂ => hadamardC * M * hadamardC) := by + fun_prop + have hconj : ∀ β : ℝ, hadamardC * rotZ β * hadamardC = rotX β := hadamardC_mul_rotZ_mul_hadamardC + have himg : (fun M : Matrix (Fin 2) (Fin 2) ℂ => hadamardC * M * hadamardC) '' + (Set.range fun n : ℤ => rotZ (n • θ)) ⊆ Set.range (fun n : ℤ => rotX (n • θ)) := by + rintro _ ⟨_, ⟨n, rfl⟩, rfl⟩ + exact ⟨n, (hconj (n • θ)).symm⟩ + have hmem : (fun M : Matrix (Fin 2) (Fin 2) ℂ => hadamardC * M * hadamardC) (rotZ α) + ∈ closure (Set.range fun n : ℤ => rotX (n • θ)) := + closure_mono himg + (image_closure_subset_closure_image hg ⟨rotZ α, rotZ_mem_closure_range_zsmul hθ α, rfl⟩) + have hmem' : hadamardC * rotZ α * hadamardC ∈ closure (Set.range fun n : ℤ => rotX (n • θ)) := + hmem + rwa [hconj α] at hmem' + +/-- **Iterating `R_x(θ)` with `cos θ = 3/5` approximates every `x`-rotation** (Nielsen & Chuang, +Exercise 4.43, `x`-axis half). -/ +theorem rotX_mem_closure_range_zsmul_of_cos_eq_three_div_five {θ : ℝ} + (hθ : Real.cos θ = 3 / 5) (α : ℝ) : + rotX α ∈ closure (Set.range fun n : ℤ => rotX (n • θ)) := + rotX_mem_closure_range_zsmul (irrational_div_two_pi_of_cos_eq_three_div_five hθ) α + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/SingleQubitRotationUniversality.lean b/LeanPool/AxQM/Concrete/SingleQubitRotationUniversality.lean new file mode 100644 index 0000000000..127809414b --- /dev/null +++ b/LeanPool/AxQM/Concrete/SingleQubitRotationUniversality.lean @@ -0,0 +1,213 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.RotationDensity +public import Mathlib.Topology.Instances.Matrix +public import Mathlib.Topology.Algebra.Monoid + +/-! +# Concrete: the reachable single-qubit rotations are dense in the single-qubit unitaries + +Every statement is about `2 × 2` matrices and the concrete rotations `rotZ`/`rotX`/`rotY`. + +## Mathematical content (the single-qubit half of Nielsen & Chuang, Exercise 4.43) + +Building on `RotationDensity.lean` (iterating an irrational-angle `R_z(θ)` / `R_x(θ)` densely fills +the one-parameter `z`- / `x`-rotation families) this file assembles the two non-parallel dense axes +into **single-qubit universality up to a global phase**: every single-qubit unitary is a limit of +finite products of the reachable gates `R_z(±θ)`, `R_x(±θ)` (with `cos θ = 3/5`), up to an +irrelevant overall phase. + +* `reachableRotations θ` — the submonoid of `Matrix (Fin 2) (Fin 2) ℂ` generated by the four gates + `R_z(θ), R_z(-θ), R_x(θ), R_x(-θ)`. Its elements are exactly the finite products of `R_z(nθ)` and + `R_x(mθ)` (`n, m ∈ ℤ`) — the operations reachable by iterating the two gates and their inverses. +* `rotZ_mem_closure_reachableRotations` / `rotX_mem_closure_reachableRotations` — for every angle + `α`, `R_z(α)` (resp. `R_x(α)`) lies in the topological closure of `reachableRotations θ`. This + lifts the one-axis density of `RotationDensity.lean` to membership in the two-generator monoid. +* `rotY_eq_rotZ_mul_rotX_mul_rotZ` — the bridge that puts the *third* axis into reach: + `R_y(γ) = R_z(π/2) · R_x(γ) · R_z(-π/2)` (conjugating `x` by a quarter `z`-turn sends `X ↦ Y`). + Hence `R_y(γ)` too lies in the closure (`rotY_mem_closure_reachableRotations`). +* `exists_phase_smul_mem_closure_reachableRotations` — **the headline**: for `cos θ = 3/5` and + every `U ∈ U(2)`, some phase `α` has `e^{iα} U ∈ closure (reachableRotations θ)`. Proof: the Z–Y + decomposition (`exists_zy_decomposition`, Theorem 4.1) writes `U = e^{iα} R_z(β) R_y(γ) R_z(δ)`; + each factor is in the closure, and the closure of a submonoid is closed under multiplication + (`Submonoid.top_closure_mul_self_subset`), so the phase-stripped product `e^{-iα} U` is too. + +## Design notes + +* **Why a submonoid and its topological closure.** The reachable gates form a submonoid `S`; the set + of operations *approximable* by them is exactly the topological closure `closure ↑S`. In a + topological monoid this closure is again a submonoid (`Submonoid.topologicalClosure`), so it is + closed under products — the one fact the assembly needs to multiply the three closure-membership + facts for the `R_z`, `R_y`, `R_z` factors of the Z–Y decomposition. +* **Global phase.** `rotZ`/`rotX`/`rotY` all have determinant `1`, so `reachableRotations θ` and its + closure sit inside `SU(2)`; a general `U ∈ U(2)` has `det U = e^{iφ}` and is reachable only after + stripping the phase `e^{iα}` (physically irrelevant). This is exactly what N&C's argument delivers + and is not a weakening. +* **The three-axis bridge.** Density is proved for two axes (`z` via the circuit, `x` via Hadamard + conjugation); the Z–Y decomposition uses `R_y`. `rotY_eq_rotZ_mul_rotX_mul_rotZ` writes `R_y` + itself as a `z`-`x`-`z` product, so no separate `R_y` density is needed. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- **Integer orbit of a one-parameter family lands in a generating submonoid.** If `f : ℝ → M` +satisfies `f 0 = 1` and `f a * f b = f (a + b)`, and both `f θ` and `f (-θ)` lie in a submonoid `S`, +then `f (n • θ) ∈ S` for every `n : ℤ` (each is a finite product of the two generators). The +abstract engine behind `rotZ`/`rotX` membership in `reachableRotations`. -/ +theorem zsmul_mem_of_one_of_mul {M : Type*} [Monoid M] {S : Submonoid M} {f : ℝ → M} {θ : ℝ} + (h0 : f 0 = 1) (hmul : ∀ a b : ℝ, f a * f b = f (a + b)) (hp : f θ ∈ S) (hn : f (-θ) ∈ S) : + ∀ n : ℤ, f (n • θ) ∈ S := by + intro n + induction n using Int.induction_on with + | zero => simp [h0] + | succ k ih => + rw [show ((k : ℤ) + 1) • θ = (k : ℤ) • θ + θ by push_cast [zsmul_eq_mul]; ring, + ← hmul] + exact mul_mem ih hp + | pred k ih => + rw [show (-(k : ℤ) - 1) • θ = (-(k : ℤ)) • θ + (-θ) by push_cast [zsmul_eq_mul]; ring, + ← hmul] + exact mul_mem ih hn + +/-- **The reachable single-qubit rotations.** The submonoid of `2 × 2` matrices generated by the +four gates `R_z(±θ), R_x(±θ)`; its elements are the finite products of `R_z(nθ)` and `R_x(mθ)` +(`n, m ∈ ℤ`). With `cos θ = 3/5` these are the single-qubit operations exactly realisable by the +`H, S, CNOT, Toffoli` gate set (via the Exercise 4.41 circuit for `R_z(θ)` and Hadamard conjugation +for `R_x(θ)`). -/ +noncomputable def reachableRotations (θ : ℝ) : Submonoid (Matrix (Fin 2) (Fin 2) ℂ) := + Submonoid.closure {rotZ θ, rotZ (-θ), rotX θ, rotX (-θ)} + +/-- Every integer power `R_z(nθ)` lies in `reachableRotations θ`. -/ +theorem rotZ_zsmul_mem_reachableRotations (θ : ℝ) (n : ℤ) : + rotZ (n • θ) ∈ reachableRotations θ := + zsmul_mem_of_one_of_mul (f := rotZ) (rotAxis_zero _) (fun a b => rotAxis_mul_same _ a b) + (Submonoid.subset_closure (by simp)) (Submonoid.subset_closure (by simp)) n + +/-- Every integer power `R_x(nθ)` lies in `reachableRotations θ`. -/ +theorem rotX_zsmul_mem_reachableRotations (θ : ℝ) (n : ℤ) : + rotX (n • θ) ∈ reachableRotations θ := + zsmul_mem_of_one_of_mul (f := rotX) (rotAxis_zero _) (fun a b => rotAxis_mul_same _ a b) + (Submonoid.subset_closure (by simp)) (Submonoid.subset_closure (by simp)) n + +/-- **Every `z`-rotation is reachable** (in the closure) when `cos θ = 3/5`: transports the one-axis +density `rotZ_mem_closure_range_zsmul_of_cos_eq_three_div_five` along +`{R_z(nθ)} ⊆ reachableRotations θ`. -/ +theorem rotZ_mem_closure_reachableRotations {θ : ℝ} (hθ : Real.cos θ = 3 / 5) (α : ℝ) : + rotZ α ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := by + refine closure_mono ?_ (rotZ_mem_closure_range_zsmul_of_cos_eq_three_div_five hθ α) + rintro _ ⟨n, rfl⟩ + exact rotZ_zsmul_mem_reachableRotations θ n + +/-- **Every `x`-rotation is reachable** (in the closure) when `cos θ = 3/5`. -/ +theorem rotX_mem_closure_reachableRotations {θ : ℝ} (hθ : Real.cos θ = 3 / 5) (α : ℝ) : + rotX α ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := by + refine closure_mono ?_ (rotX_mem_closure_range_zsmul_of_cos_eq_three_div_five hθ α) + rintro _ ⟨n, rfl⟩ + exact rotX_zsmul_mem_reachableRotations θ n + +/-- **The reachable closure is closed under multiplication** — the topological closure of a +submonoid is a submonoid (`Submonoid.top_closure_mul_self_subset`). -/ +theorem mul_mem_closure_reachableRotations {θ : ℝ} {a b : Matrix (Fin 2) (Fin 2) ℂ} + (ha : a ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ))) + (hb : b ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ))) : + a * b ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := + Submonoid.top_closure_mul_self_subset _ (Set.mul_mem_mul ha hb) + +/-- **The third axis as a `z`-`x`-`z` product:** `R_y(γ) = R_z(π/2) · R_x(γ) · R_z(-π/2)`. +Conjugating the `x`-rotation by a quarter `z`-turn sends the `X` generator to `Y`; concretely the +outer diagonal phases `e^{∓iπ/4}` cancel on the diagonal and combine to `e^{∓iπ/2} = ∓i` off the +diagonal, turning `R_x(γ)`'s `∓i sin(γ/2)` entries into `R_y(γ)`'s `∓sin(γ/2)`. -/ +theorem rotY_eq_rotZ_mul_rotX_mul_rotZ (γ : ℝ) : + rotY γ = rotZ (Real.pi / 2) * rotX γ * rotZ (-(Real.pi / 2)) := by + rw [rotY_eq, rotZ_eq, rotX_eq, rotZ_eq] + simp only [Complex.ofReal_neg, neg_neg, neg_div, Matrix.mul_fin_two] + set P := Complex.exp (↑(Real.pi / 2) / 2 * Complex.I) with hP + set N := Complex.exp (-(↑(Real.pi / 2) / 2) * Complex.I) with hN + have hNP : N * P = 1 := by + rw [hN, hP, ← Complex.exp_add, + show (-(↑(Real.pi / 2) / 2) * Complex.I + ↑(Real.pi / 2) / 2 * Complex.I : ℂ) = 0 by ring, + Complex.exp_zero] + have hNN : N * N = -Complex.I := by + rw [hN, ← Complex.exp_add, + show (-(↑(Real.pi / 2) / 2) * Complex.I + -(↑(Real.pi / 2) / 2) * Complex.I : ℂ) + = ((-(Real.pi / 2) : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, Real.cos_neg, Real.sin_neg, + Real.cos_pi_div_two, Real.sin_pi_div_two] + push_cast; ring + have hPP : P * P = Complex.I := by + rw [hP, ← Complex.exp_add, + show (↑(Real.pi / 2) / 2 * Complex.I + ↑(Real.pi / 2) / 2 * Complex.I : ℂ) + = ((Real.pi / 2 : ℝ) : ℂ) * Complex.I by push_cast; ring, + Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin, + Real.cos_pi_div_two, Real.sin_pi_div_two] + push_cast; ring + ext i j + fin_cases i <;> fin_cases j <;> + simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, Matrix.of_apply, Matrix.cons_val', + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_fin_one, Matrix.empty_val', + mul_zero, zero_mul, add_zero, zero_add] + · -- (0,0): N * cos * P, with N * P = 1 + rw [show N * (Real.cos (γ / 2) : ℂ) * P = N * P * (Real.cos (γ / 2) : ℂ) by ring, hNP, one_mul] + · -- (0,1): N * (-sin·i) * N, with N * N = -i + rw [show N * (-(Real.sin (γ / 2) : ℂ) * Complex.I) * N + = N * N * (-(Real.sin (γ / 2) : ℂ) * Complex.I) by ring, hNN, + show (-Complex.I) * (-(Real.sin (γ / 2) : ℂ) * Complex.I) + = (Real.sin (γ / 2) : ℂ) * (Complex.I * Complex.I) by ring, Complex.I_mul_I] + ring + · -- (1,0): P * (-sin·i) * P, with P * P = i + rw [show P * (-(Real.sin (γ / 2) : ℂ) * Complex.I) * P + = P * P * (-(Real.sin (γ / 2) : ℂ) * Complex.I) by ring, hPP, + show Complex.I * (-(Real.sin (γ / 2) : ℂ) * Complex.I) + = -((Real.sin (γ / 2) : ℂ) * (Complex.I * Complex.I)) by ring, Complex.I_mul_I] + ring + · -- (1,1): P * cos * N, with N * P = 1 + rw [show P * (Real.cos (γ / 2) : ℂ) * N = N * P * (Real.cos (γ / 2) : ℂ) by ring, hNP, one_mul] + +/-- **Every `y`-rotation is reachable** (in the closure) when `cos θ = 3/5`, via the `z`-`x`-`z` +factorisation `rotY_eq_rotZ_mul_rotX_mul_rotZ` and closure-under-multiplication. -/ +theorem rotY_mem_closure_reachableRotations {θ : ℝ} (hθ : Real.cos θ = 3 / 5) (γ : ℝ) : + rotY γ ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := by + rw [rotY_eq_rotZ_mul_rotX_mul_rotZ] + exact mul_mem_closure_reachableRotations + (mul_mem_closure_reachableRotations (rotZ_mem_closure_reachableRotations hθ _) + (rotX_mem_closure_reachableRotations hθ _)) + (rotZ_mem_closure_reachableRotations hθ _) + +/-- **Single-qubit universality up to a global phase** (the single-qubit content of Nielsen & +Chuang, Exercise 4.43). For `cos θ = 3/5` and every single-qubit unitary `U`, some global phase +`e^{iα}` makes `e^{iα} U` a limit of finite products of the reachable gates `R_z(±θ), R_x(±θ)`. + +Combining the Z–Y decomposition `U = e^{iα₀} R_z(β) R_y(γ) R_z(δ)` (Theorem 4.1, +`exists_zy_decomposition`) with the reachability of every `z`-, `x`- and `y`-rotation and closure of +`closure (reachableRotations θ)` under products, the phase-stripped `e^{-iα₀} U` lies in that +closure. -/ +theorem exists_phase_smul_mem_closure_reachableRotations {θ : ℝ} (hθ : Real.cos θ = 3 / 5) + (U : Matrix (Fin 2) (Fin 2) ℂ) (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ α : ℝ, Complex.exp ((α : ℂ) * Complex.I) • U + ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := by + obtain ⟨a, β, γ, δ, hUeq⟩ := exists_zy_decomposition U hU + refine ⟨-a, ?_⟩ + have hW : rotZ β * rotY γ * rotZ δ + ∈ closure (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ)) := + mul_mem_closure_reachableRotations + (mul_mem_closure_reachableRotations (rotZ_mem_closure_reachableRotations hθ β) + (rotY_mem_closure_reachableRotations hθ γ)) + (rotZ_mem_closure_reachableRotations hθ δ) + rw [hUeq, smul_smul, ← Complex.exp_add, + show ((-a : ℝ) : ℂ) * Complex.I + (a : ℂ) * Complex.I = 0 by push_cast; ring, + Complex.exp_zero, one_smul] + exact hW + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/SingleQubitWire.lean b/LeanPool/AxQM/Concrete/SingleQubitWire.lean new file mode 100644 index 0000000000..d615ffcd0d --- /dev/null +++ b/LeanPool/AxQM/Concrete/SingleQubitWire.lean @@ -0,0 +1,227 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.ControlledSingleQubit +public import LeanPool.AxQM.Concrete.SingleQubitRotationUniversality + +/-! +# Concrete: the (uncontrolled) single-qubit gate on a wire (N&C §4.3/§4.5) + +(Nielsen & Chuang §4.3, §4.5.2, p. 182–193 — the `n`-qubit lift.) + +The §4.5 decomposition (`Concrete/UnitaryControlledProduct.lean`) writes any register unitary as a +product of *controlled* single-qubit gates (`ctrlSingleQubit`). The next stage of Nielsen & Chuang's +argument (§4.3) reduces each such controlled gate to a circuit of **uncontrolled single-qubit gates +placed on individual wires** and `CNOT`s; then the single-qubit gates are approximated by the +reachable set (`SingleQubitRotationUniversality.lean`) and, through the error-chaining inequality +(§4.5.3), the whole register unitary is approximated. This file provides the matrix object that +reduction produces and the approximation consumes — the **single-qubit gate on wire `j`** — together +with the property that makes the approximation phase-clean. + +## The construction + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the `m`-bit strings as the `d = 2 ^ m` basis +indices, a wire `j : Fin m`, and a `2 × 2` matrix `g`. + +* `AxQM.Concrete.singleQubitOnWire enc j g` — on `|enc x⟩` it applies `g` to bit `j` of `x` + (regardless of the other bits), fixing the other bits. It is the `ctrlSingleQubit` gate with its + control condition dropped: `g` acts on *every* fibre of the `j`-th bit, so the matrix is block + diagonal over those two-dimensional fibres. + +## Why it matters — the phase-clean property + +A general `2 × 2` unitary is reachable only *up to a global phase* (`exists_zy_decomposition`); the +reachable single-qubit set sits in `SU(2)`. On a **controlled** gate that residual phase is a +*relative* phase and cannot be absorbed. On an **uncontrolled** wire gate it is a genuine *global* +phase: `singleQubitOnWire enc j (c • g) = c • singleQubitOnWire enc j g` — the scalar `c` multiplies +the *whole* `d × d` matrix (`singleQubitOnWire_smul`), not just a sub-block. This is exactly why +N&C's §4.3 reduces controlled gates to uncontrolled single-qubit gates *before* approximating: the +per-gate phase ambiguities then combine into one physically irrelevant global phase. + +The algebra confirms `singleQubitOnWire enc j` is a `*`-homomorphism on the block +(`singleQubitOnWire_one`, `singleQubitOnWire_mul`, `singleQubitOnWire_conjTranspose`), so it sends +unitaries to unitaries (`singleQubitOnWire_mem_unitaryGroup`); and it is continuous +(`continuous_singleQubitOnWire`). Assembling these: + +* `AxQM.Concrete.exists_phase_smul_singleQubitOnWire_mem_closure` — **the headline**: for + `cos θ = 3/5` and every `U ∈ U(2)`, some global phase `e^{iα}` makes + `e^{iα} • singleQubitOnWire enc j U` a limit of `singleQubitOnWire enc j` applied to the reachable + single-qubit gates. It is the single-qubit universality of Exercise 4.43 (Step 2), lifted to a + chosen wire of the `m`-qubit register and kept phase-clean. + +## Use + +This is reused by the `n`-qubit lift of Exercise 4.43 ([upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean)). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The single-qubit gate on wire `j`.** Relative to an encoding `enc : (Fin m → Fin 2) ≃ Fin d`, +a wire `j`, and a `2 × 2` matrix `g`, it applies `g` to bit `j` of `x` on the basis state `|enc x⟩` +(regardless of the other bits), fixing the other bits. It is `ctrlSingleQubit` with the control +condition removed — `g` acts on every fibre of the `j`-th bit. -/ +def singleQubitOnWire (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (g : Matrix (Fin 2) (Fin 2) ℂ) : Matrix (Fin d) (Fin d) ℂ := + Matrix.of fun i i' => + if ∀ k, k ≠ j → enc.symm i k = enc.symm i' k then g (enc.symm i j) (enc.symm i' j) else 0 + +/-- Unfolding lemma for `singleQubitOnWire` entries. -/ +theorem singleQubitOnWire_apply (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (g : Matrix (Fin 2) (Fin 2) ℂ) (i i' : Fin d) : + singleQubitOnWire enc j g i i' = + if ∀ k, k ≠ j → enc.symm i k = enc.symm i' k then g (enc.symm i j) (enc.symm i' j) + else 0 := rfl + +/-- **`singleQubitOnWire` is the fibrewise gate (`wireGate`, `ControlledSingleQubit.lean`) with a +constant block.** The gate's action / multiplicativity / identity lemmas below are one-line +consequences of the general `wireGate_*` lemmas through this bridge. -/ +theorem singleQubitOnWire_eq_wireGate (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (g : Matrix (Fin 2) (Fin 2) ℂ) : + singleQubitOnWire enc j g = wireGate enc j (fun _ => g) := by + ext i i' + simp only [singleQubitOnWire, wireGate, Matrix.of_apply] + +/-- **A diagonal single-qubit block on a wire is a diagonal matrix.** `singleQubitOnWire enc j +(diagonal v) = diagonal (fun i => v (enc.symm i j))`: with a diagonal block, the gate multiplies the +basis state `|enc x⟩` by `v (bit j of x)` and mixes nothing (two distinct basis states agreeing off +wire `j` disagree at `j`, so the off-diagonal entry vanishes by `Matrix.diagonal_apply_ne`). -/ +theorem singleQubitOnWire_diagonal (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) (v : Fin 2 → ℂ) : + singleQubitOnWire enc j (Matrix.diagonal v) = Matrix.diagonal fun i => v (enc.symm i j) := by + ext i i' + rw [singleQubitOnWire_apply] + by_cases hii : i = i' + · subst hii + rw [ite_eq_left fun _ _ => rfl, Matrix.diagonal_apply_eq, Matrix.diagonal_apply_eq] + · rw [Matrix.diagonal_apply_ne _ hii] + by_cases hbits : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hbits] + exact Matrix.diagonal_apply_ne v fun hj => hii (enc.symm.injective (funext fun k => by + rcases eq_or_ne k j with rfl | hk + · exact hj + · exact hbits k hk)) + · rw [ite_eq_right hbits] + +/-- **A scalar pulls out of the whole matrix** — the phase-clean property. Because the gate is +uncontrolled, multiplying its `2 × 2` block by `c` multiplies the *entire* `d × d` matrix by `c`. -/ +theorem singleQubitOnWire_smul (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) (c : ℂ) + (g : Matrix (Fin 2) (Fin 2) ℂ) : + singleQubitOnWire enc j (c • g) = c • singleQubitOnWire enc j g := by + ext i i' + simp only [singleQubitOnWire, Matrix.of_apply, Matrix.smul_apply, smul_eq_mul] + split_ifs <;> simp + +/-- **The action of a single-qubit wire gate on a vector.** It mixes only the two components whose +bit-strings agree off wire `j`, through `g`. -/ +theorem singleQubitOnWire_mulVec (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (g : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) (i : Fin d) : + (singleQubitOnWire enc j g *ᵥ v) i = + g (enc.symm i j) 0 * v (enc (Function.update (enc.symm i) j 0)) + + g (enc.symm i j) 1 * v (enc (Function.update (enc.symm i) j 1)) := by + rw [singleQubitOnWire_eq_wireGate, wireGate_mulVec] + +/-- The single-qubit wire gate of the `2 × 2` identity is the `d × d` identity. -/ +theorem singleQubitOnWire_one (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) : + singleQubitOnWire enc j (1 : Matrix (Fin 2) (Fin 2) ℂ) = 1 := by + rw [singleQubitOnWire_eq_wireGate, wireGate_one] + +/-- **`singleQubitOnWire enc j` is multiplicative on the block**: it respects matrix products. +It is the constant-block case of the general fibrewise multiplicativity `wireGate_mul` +(`ControlledSingleQubit.lean`), through the bridge `singleQubitOnWire_eq_wireGate`. -/ +theorem singleQubitOnWire_mul (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (a b : Matrix (Fin 2) (Fin 2) ℂ) : + singleQubitOnWire enc j a * singleQubitOnWire enc j b + = singleQubitOnWire enc j (a * b) := by + simp only [singleQubitOnWire_eq_wireGate, wireGate_mul] + +/-- **`singleQubitOnWire enc j` commutes with the conjugate transpose**: +`(singleQubitOnWire enc j g)ᴴ = singleQubitOnWire enc j gᴴ`. -/ +theorem singleQubitOnWire_conjTranspose (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + (g : Matrix (Fin 2) (Fin 2) ℂ) : + (singleQubitOnWire enc j g)ᴴ = singleQubitOnWire enc j gᴴ := by + ext i i' + rw [Matrix.conjTranspose_apply, singleQubitOnWire_apply, singleQubitOnWire_apply, + Matrix.conjTranspose_apply] + by_cases hoff : ∀ k, k ≠ j → enc.symm i k = enc.symm i' k + · rw [ite_eq_left hoff, ite_eq_left (fun k hk => (hoff k hk).symm)] + · rw [ite_eq_right hoff, ite_eq_right (fun h => hoff (fun k hk => (h k hk).symm)), star_zero] + +/-- **A single-qubit wire gate with unitary block is unitary.** Follows from the `*`-homomorphism +laws: `(SQ g)ᴴ · SQ g = SQ (gᴴ · g) = SQ 1 = 1`. -/ +theorem singleQubitOnWire_mem_unitaryGroup (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) + {g : Matrix (Fin 2) (Fin 2) ℂ} (hg : g ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + singleQubitOnWire enc j g ∈ Matrix.unitaryGroup (Fin d) ℂ := by + rw [Matrix.mem_unitaryGroup_iff'] at hg ⊢ + rw [Matrix.star_eq_conjTranspose] at hg ⊢ + rw [singleQubitOnWire_conjTranspose, singleQubitOnWire_mul, hg, singleQubitOnWire_one] + +/-- **`singleQubitOnWire enc j` is continuous** in its `2 × 2` block: each matrix entry is either +the constant `0` or the continuous projection `g ↦ g a b`. -/ +theorem continuous_singleQubitOnWire (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) : + Continuous (fun g : Matrix (Fin 2) (Fin 2) ℂ => singleQubitOnWire enc j g) := by + apply continuous_matrix + intro i i' + simp only [singleQubitOnWire, Matrix.of_apply] + split_ifs with h + · exact (continuous_apply _).comp (continuous_apply _) + · exact continuous_const + +/-- **The per-wire phase-clean transport** (N&C §4.3/§4.5, the generic single-qubit-density lift). +If some global phase `e^{iα}` makes `e^{iα} • U` a closure limit of a set `S` of `2 × 2` gates, then +the *same* phase makes `e^{iα} • singleQubitOnWire enc j U` a closure limit of +`singleQubitOnWire enc j '' S`. Because `singleQubitOnWire enc j` is *continuous* +(`continuous_singleQubitOnWire`) it carries the closure membership through +(`image_closure_subset_closure_image`), and because the phase pulls out *globally* on the +uncontrolled wire (`singleQubitOnWire_smul`) the residual phase survives as a genuine global phase +on the whole register — the property the §4.3 reduction to uncontrolled gates buys and the +error-chaining assembly needs. + +This is the transport shared by every single-qubit density on a wire: it is fed the reachable +rotations for Exercise 4.43 (`exists_phase_smul_singleQubitOnWire_mem_closure`) and the Deutsch +single-qubit submonoid for Exercise 4.44 +(`exists_phase_smul_singleQubitOnWire_mem_closure_deutschWireGateSubmonoid`, +`Concrete/DeutschWireUniversality.lean`). -/ +theorem exists_phase_smul_singleQubitOnWire_mem_closure_of_exists_phase_smul_mem_closure + (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) {S : Set (Matrix (Fin 2) (Fin 2) ℂ)} + {U : Matrix (Fin 2) (Fin 2) ℂ} + (h : ∃ α : ℝ, Complex.exp ((α : ℂ) * Complex.I) • U ∈ closure S) : + ∃ α : ℝ, Complex.exp ((α : ℂ) * Complex.I) • singleQubitOnWire enc j U + ∈ closure (singleQubitOnWire enc j '' S) := by + obtain ⟨α, hα⟩ := h + refine ⟨α, ?_⟩ + have hmem := image_closure_subset_closure_image (continuous_singleQubitOnWire enc j) + (Set.mem_image_of_mem (singleQubitOnWire enc j) hα) + rwa [singleQubitOnWire_smul] at hmem + +/-- **Single-qubit universality on a wire, kept phase-clean** (Exercise 4.43, Step 2 lifted to the +`m`-qubit register). For `cos θ = 3/5` and every single-qubit unitary `U`, some global phase +`e^{iα}` makes `e^{iα} • singleQubitOnWire enc j U` a limit of `singleQubitOnWire enc j` applied to +the reachable gates `R_z(±θ), R_x(±θ)`. + +A one-line application of the generic per-wire transport +`exists_phase_smul_singleQubitOnWire_mem_closure_of_exists_phase_smul_mem_closure` to the reachable +set's density up to a phase (`exists_phase_smul_mem_closure_reachableRotations`): the transport +keeps the residual phase global on the uncontrolled wire — the property the §4.3 reduction buys and +the error-chaining assembly needs. -/ +theorem exists_phase_smul_singleQubitOnWire_mem_closure {θ : ℝ} (hθ : Real.cos θ = 3 / 5) + (enc : (Fin m → Fin 2) ≃ Fin d) (j : Fin m) {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ α : ℝ, Complex.exp ((α : ℂ) * Complex.I) • singleQubitOnWire enc j U + ∈ closure (singleQubitOnWire enc j '' + (reachableRotations θ : Set (Matrix (Fin 2) (Fin 2) ℂ))) := + exists_phase_smul_singleQubitOnWire_mem_closure_of_exists_phase_smul_mem_closure enc j + (exists_phase_smul_mem_closure_reachableRotations hθ U hU) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/SpecialOrthogonalAxisAngle.lean b/LeanPool/AxQM/Concrete/SpecialOrthogonalAxisAngle.lean new file mode 100644 index 0000000000..8ca3c2147a --- /dev/null +++ b/LeanPool/AxQM/Concrete/SpecialOrthogonalAxisAngle.lean @@ -0,0 +1,314 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.SpecialOrthogonalFixedAxis +public import LeanPool.AxQM.Concrete.BlochRotation +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle + +/-! +# Concrete: the axis–angle decomposition of a proper rotation of `ℝ³` + +This file supplies the pure linear-algebra content behind the **axis–angle decomposition** of a +proper rotation, the second ingredient (after the axis-existence theorem +`Concrete.exists_unit_mulVec_self_of_mem_specialOrthogonalGroup`, Euler's theorem) of the qubit +converse of **Nielsen & Chuang, Problem 8.3** (p. 396): + +> **Axis–angle decomposition.** For every `O ∈ SO(3)` there is a *unit* axis `n̂` and an angle `θ` +> with `O v = rot3D n̂ θ v` for all `v`: `O` is the Rodrigues rotation by `θ` about `n̂`. + +## Context in N&C + +Problem 8.3's qubit direction realises a unital single-qubit channel's Bloch matrix `M` as +`M = O₁ · diagonal d · O₂` (`Concrete.exists_specialOrthogonalGroup_diagonal_factor`), then must +realise the proper rotations `O₁, O₂ ∈ SO(3)` as *unitary conjugations* on the Bloch sphere (the +`SU(2) → SO(3)` cover, forward direction `Concrete.blochRotationOfUnitary`). The surjectivity of +that cover reduces to this axis–angle decomposition: once `O = rot3D n̂ θ`, the qubit rotation gate +`rotAxis n̂ θ` realises it (`Concrete.pauliDot_conj_rotAxis`, N&C Ex. 4.6), closing the converse. + +## The proof (the orthonormal-frame argument) + +Euler's theorem gives a unit axis `n` fixed by `O` (`O n = n`). Complete `n` to a right-handed +orthonormal frame `{n, u, w}` with `w = n × u` (`exists_unit_dotProduct_zero` for the perpendicular +`u`; `frame_expansion` for the resulting basis). Because `O` is orthogonal it preserves the dot +product (`mulVec_dotProduct_mulVec_of_mem_orthogonalGroup`), so `O u` lies in the `n`-orthogonal +plane: `O u = c • u + s • w` with `c² + s² = 1`; pick `θ` with `cos θ = c`, `sin θ = s`. Then +`O u = rot3D n θ u`. Because `O ∈ SO(3)` it also preserves the cross product +(`mulVec_crossProduct_of_mem_specialOrthogonalGroup`), so +`O w = O (n × u) = (O n) × (O u) = n × (c • u + s • w) = -s • u + c • w = rot3D n θ w`. The two maps +agree on `n` (both fix it), `u`, and `w`; since `{n, u, w}` spans `ℝ³` and both maps are `ℝ`-linear, +they agree on every `v`. + +Compare the companion files `AxQM/Concrete/SpecialOrthogonalFixedAxis.lean` and +`AxQM/Concrete/BlochRotation.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **`rot3D` is additive** in its vector argument: `rot3D n θ (a + b) = rot3D n θ a + rot3D n θ b`. +Each Rodrigues term (`cos θ • v`, `sin θ • (n × v)`, `(1 − cos θ)(n·v) • n`) is linear in `v`. -/ +theorem rot3D_add (n : Fin 3 → ℝ) (θ : ℝ) (a b : Fin 3 → ℝ) : + rot3D n θ (a + b) = rot3D n θ a + rot3D n θ b := by + simp only [rot3D, map_add, dotProduct_add] + module + +/-- **`rot3D` is homogeneous** in its vector argument: `rot3D n θ (c • a) = c • rot3D n θ a`. +Each Rodrigues term is linear in `v`. -/ +theorem rot3D_smul (n : Fin 3 → ℝ) (θ : ℝ) (c : ℝ) (a : Fin 3 → ℝ) : + rot3D n θ (c • a) = c • rot3D n θ a := by + simp only [rot3D, map_smul, dotProduct_smul, smul_eq_mul] + module + +/-- **The Binet/Lagrange cross-product identity under a matrix.** For any `3 × 3` matrix `O`, +`Oᵀ ((O u) × (O v)) = det O • (u × v)`. A polynomial identity in the entries of `O` and the +components of `u, v`, proved by `ring` after expanding the matrix operations. It is the algebraic +core of `mulVec_crossProduct_of_mem_specialOrthogonalGroup`. -/ +theorem transpose_mulVec_crossProduct_mulVec (O : Matrix (Fin 3) (Fin 3) ℝ) (u v : Fin 3 → ℝ) : + Oᵀ.mulVec (crossProduct (O.mulVec u) (O.mulVec v)) = O.det • crossProduct u v := by + funext i + fin_cases i <;> + simp only [Fin.isValue, Fin.reduceFinMk, Matrix.mulVec, Matrix.transpose_apply, + dotProduct, cross_apply, Fin.sum_univ_three, Matrix.det_fin_three, Pi.smul_apply, + smul_eq_mul, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons] <;> + ring + +/-- **`SO(3)` preserves the cross product.** For `O ∈ SO(3)`, +`O (u × v) = (O u) × (O v)`. From the Binet identity `Oᵀ ((O u) × (O v)) = det O • (u × v) = u × v` +(det `O = 1`), left-multiplied by `O` (using `O Oᵀ = 1`). -/ +theorem mulVec_crossProduct_of_mem_specialOrthogonalGroup + {O : Matrix (Fin 3) (Fin 3) ℝ} (hO : O ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ) + (u v : Fin 3 → ℝ) : + O.mulVec (crossProduct u v) = crossProduct (O.mulVec u) (O.mulVec v) := by + obtain ⟨hOorth, hdet⟩ := Matrix.mem_specialOrthogonalGroup_iff.mp hO + have hOtO : Oᵀ * O = 1 := (Matrix.mem_orthogonalGroup_iff' (Fin 3) ℝ).mp hOorth + have hOOt : O * Oᵀ = 1 := mul_eq_one_comm.mp hOtO + have key := transpose_mulVec_crossProduct_mulVec O u v + rw [hdet, one_smul] at key + calc O.mulVec (crossProduct u v) + = O.mulVec (Oᵀ.mulVec (crossProduct (O.mulVec u) (O.mulVec v))) := by rw [key] + _ = (O * Oᵀ).mulVec (crossProduct (O.mulVec u) (O.mulVec v)) := by rw [Matrix.mulVec_mulVec] + _ = crossProduct (O.mulVec u) (O.mulVec v) := by rw [hOOt, Matrix.one_mulVec] + +/-- **An orthogonal matrix preserves the dot product.** For `O` in the orthogonal group over any +finite index type, `(O x) ⬝ᵥ (O y) = x ⬝ᵥ y`. From `Oᵀ O = 1`; nothing three-dimensional is used. -/ +theorem mulVec_dotProduct_mulVec_of_mem_orthogonalGroup {m : Type*} [Fintype m] [DecidableEq m] + {O : Matrix m m ℝ} (hO : O ∈ Matrix.orthogonalGroup m ℝ) + (x y : m → ℝ) : + (O.mulVec x) ⬝ᵥ (O.mulVec y) = x ⬝ᵥ y := by + have hOtO : Oᵀ * O = 1 := (Matrix.mem_orthogonalGroup_iff' m ℝ).mp hO + rw [Matrix.dotProduct_mulVec, ← Matrix.mulVec_transpose, Matrix.mulVec_mulVec, hOtO, + Matrix.one_mulVec] + +/-- **An orthogonal transformation preserves the Bloch-ball length.** For `O ∈ O(3)` the squared +length `r₀² + r₁² + r₂²` is invariant under `r ↦ O r`, so an orthogonal map (in particular a proper +`SO(3)` rotation) sends the closed unit ball to itself. Only **orthogonality** is used — the +determinant plays no role — so the hypothesis is `orthogonalGroup`, not `specialOrthogonalGroup`. +Immediate from `mulVec_dotProduct_mulVec_of_mem_orthogonalGroup` (orthogonality preserves the dot +product): `∑ (O r)ᵢ² = (O r) ⬝ᵥ (O r) = r ⬝ᵥ r = ∑ rᵢ²`. The `Fin 3` sum-of-squares *form* is kept +(not generalised) because it is exactly the ball hypothesis of `blochState`: the membership fact +needed to feed an `O r` back into `blochState` when assembling the qubit converse of Nielsen & +Chuang, Problem 8.3 (realising the singular-value rotations of a unital channel's Bloch matrix as +unitary conjugations requires the rotated Bloch vectors to stay in the ball). -/ +theorem mem_orthogonalGroup_mulVec_sq_sum {O : Matrix (Fin 3) (Fin 3) ℝ} + (hO : O ∈ Matrix.orthogonalGroup (Fin 3) ℝ) (r : Fin 3 → ℝ) : + (O.mulVec r) 0 ^ 2 + (O.mulVec r) 1 ^ 2 + (O.mulVec r) 2 ^ 2 + = r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 := by + have key := mulVec_dotProduct_mulVec_of_mem_orthogonalGroup hO r r + simp only [dotProduct, Fin.sum_univ_three] at key + nlinarith [key] + +/-- **The special orthogonal group is closed under transpose.** If `O ∈ SO(n)` over a commutative +ring `R`, then `Oᵀ ∈ SO(n)`: `Oᵀ` is orthogonal because `(Oᵀ)ᵀ · Oᵀ = O · Oᵀ = 1` (orthogonality +of `O`), and `det Oᵀ = det O = 1`. Nothing about the index type `n` or the base ring `R` is used, so +this is stated in full generality. Applied at `n = Fin 3`, `R = ℝ` to realise the *inverse* +singular-value rotations `O₁ᵀ, O₂ᵀ` of a unital qubit channel's Bloch matrix as unitary conjugations +(via the `SU(2) → SO(3)` cover) when diagonalising the channel — the geometric assembly of Nielsen & +Chuang, Problem 8.3's qubit converse. -/ +theorem mem_specialOrthogonalGroup_transpose {n : Type*} [DecidableEq n] [Fintype n] + {R : Type*} [CommRing R] {O : Matrix n n R} + (hO : O ∈ Matrix.specialOrthogonalGroup n R) : + Oᵀ ∈ Matrix.specialOrthogonalGroup n R := by + obtain ⟨hOo, hdet⟩ := Matrix.mem_specialOrthogonalGroup_iff.mp hO + have hOtO : Oᵀ * O = 1 := (Matrix.mem_orthogonalGroup_iff' n R).mp hOo + have hOOt : O * Oᵀ = 1 := mul_eq_one_comm.mp hOtO + rw [Matrix.mem_specialOrthogonalGroup_iff] + exact ⟨by rw [Matrix.mem_orthogonalGroup_iff' n R, Matrix.transpose_transpose]; exact hOOt, + by rw [Matrix.det_transpose]; exact hdet⟩ + +/-- **`n × u` is a unit vector for an orthonormal pair.** If `n ⬝ᵥ n = 1`, `u ⬝ᵥ u = 1` and +`n ⬝ᵥ u = 0`, then `(n × u) ⬝ᵥ (n × u) = 1`. Immediate from Lagrange's identity +`Matrix.cross_dot_cross`. -/ +theorem crossProduct_dotProduct_self_of_orthonormal {n u : Fin 3 → ℝ} + (hn : n ⬝ᵥ n = 1) (hu : u ⬝ᵥ u = 1) (hnu : n ⬝ᵥ u = 0) : + (crossProduct n u) ⬝ᵥ (crossProduct n u) = 1 := by + rw [cross_dot_cross, hn, hu, hnu]; ring + +/-- **Orthonormal-frame expansion.** If `{n, u, n × u}` is a right-handed orthonormal frame +(`n ⬝ᵥ n = 1`, `u ⬝ᵥ u = 1`, `n ⬝ᵥ u = 0`), every vector `x` is the sum of its projections onto the +frame: `x = (n·x) • n + (u·x) • u + ((n×u)·x) • (n×u)`. Proved from the cross-product identities +`(n×u) × x = (n·x) • u − (u·x) • n` and `(n×u) × ((n×u) × x) = (n×u·x) • (n×u) − x`. -/ +theorem frame_expansion {n u : Fin 3 → ℝ} (hn : n ⬝ᵥ n = 1) (hu : u ⬝ᵥ u = 1) (hnu : n ⬝ᵥ u = 0) + (x : Fin 3 → ℝ) : + x = (n ⬝ᵥ x) • n + (u ⬝ᵥ x) • u + ((crossProduct n u) ⬝ᵥ x) • (crossProduct n u) := by + set w := crossProduct n u with hw + have hww : w ⬝ᵥ w = 1 := by + rw [hw]; exact crossProduct_dotProduct_self_of_orthonormal hn hu hnu + have hwu : crossProduct w u = -n := by + rw [hw, cross_cross_eq_smul_sub_smul, hnu, hu, zero_smul, one_smul, zero_sub] + have hwn : crossProduct w n = u := by + rw [hw, cross_cross_eq_smul_sub_smul, hn, one_smul, dotProduct_comm u n, hnu, zero_smul, + sub_zero] + have hwx : crossProduct w x = (n ⬝ᵥ x) • u - (u ⬝ᵥ x) • n := by + rw [hw, cross_cross_eq_smul_sub_smul] + have hwwx1 : crossProduct w (crossProduct w x) = -((n ⬝ᵥ x) • n) - (u ⬝ᵥ x) • u := by + rw [hwx, map_sub, map_smul, map_smul, hwu, hwn, smul_neg] + have hwwx2 : crossProduct w (crossProduct w x) = (w ⬝ᵥ x) • w - x := by + rw [cross_cross_eq_smul_sub_smul', hww, one_smul] + have key := hwwx1.symm.trans hwwx2 + rw [eq_sub_iff_add_eq] at key + linear_combination (norm := module) key + +/-- **Every unit vector of `ℝ³` has a unit vector orthogonal to it.** Given `n ⬝ᵥ n = 1`, there is a +`u` with `u ⬝ᵥ u = 1` and `n ⬝ᵥ u = 0`. Take `(−n₁, n₀, 0)` normalised (or `(1, 0, 0)` when `n` is +along `e_z`). -/ +theorem exists_unit_dotProduct_zero {n : Fin 3 → ℝ} (hn : n ⬝ᵥ n = 1) : + ∃ u : Fin 3 → ℝ, u ⬝ᵥ u = 1 ∧ n ⬝ᵥ u = 0 := by + have hn' : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1 := by + simpa only [dotProduct, Fin.sum_univ_three, ← pow_two] using hn + by_cases h : n 0 = 0 ∧ n 1 = 0 + · refine ⟨![1, 0, 0], ?_, ?_⟩ + · simp [dotProduct, Fin.sum_univ_three] + · simp only [dotProduct, Fin.sum_univ_three, Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.head_cons, Matrix.cons_val_two, Matrix.tail_cons, mul_one, mul_zero, add_zero] + exact h.1 + · -- `p = (−n₁, n₀, 0)` is nonzero and orthogonal to `n`. + set s : ℝ := n 0 ^ 2 + n 1 ^ 2 with hs + have hs_pos : 0 < s := by + rcases not_and_or.mp h with h0 | h1 + · have : 0 < n 0 ^ 2 := by positivity + nlinarith [sq_nonneg (n 1)] + · have : 0 < n 1 ^ 2 := by positivity + nlinarith [sq_nonneg (n 0)] + refine ⟨(Real.sqrt s)⁻¹ • ![-n 1, n 0, 0], ?_, ?_⟩ + · have hpp : (![-n 1, n 0, 0] : Fin 3 → ℝ) ⬝ᵥ ![-n 1, n 0, 0] = s := by + simp only [dotProduct, Fin.sum_univ_three, Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.head_cons, Matrix.cons_val_two, Matrix.tail_cons] + rw [hs]; ring + rw [smul_dotProduct, dotProduct_smul, hpp, smul_eq_mul, smul_eq_mul, ← mul_assoc, + ← mul_inv, Real.mul_self_sqrt hs_pos.le, inv_mul_cancel₀ hs_pos.ne'] + · have hnp : n ⬝ᵥ (![-n 1, n 0, 0] : Fin 3 → ℝ) = 0 := by + simp only [dotProduct, Fin.sum_univ_three, Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.head_cons, Matrix.cons_val_two, Matrix.tail_cons] + ring + rw [dotProduct_smul, hnp, smul_zero] + +/-- **A point on the unit circle is `(cos θ, sin θ)` for some `θ`.** If `c² + s² = 1` there is a +real `θ` with `cos θ = c` and `sin θ = s`; take `θ = arg (c + s i)`. -/ +theorem exists_cos_sin_of_sq_add_sq {c s : ℝ} (h : c ^ 2 + s ^ 2 = 1) : + ∃ θ : ℝ, Real.cos θ = c ∧ Real.sin θ = s := by + have hne : (⟨c, s⟩ : ℂ) ≠ 0 := by + intro hz + rw [Complex.ext_iff] at hz + simp only [Complex.zero_re, Complex.zero_im] at hz + nlinarith [hz.1, hz.2] + have hnorm : c * c + s * s = 1 := by nlinarith [h] + refine ⟨(⟨c, s⟩ : ℂ).arg, ?_, ?_⟩ + · rw [Complex.cos_arg hne] + simp only [Complex.norm_def, Complex.normSq_mk] + rw [hnorm]; simp + · rw [Complex.sin_arg] + simp only [Complex.norm_def, Complex.normSq_mk] + rw [hnorm]; simp + +/-- **Axis–angle decomposition of a proper rotation (Euler's theorem, full form).** Every +`O ∈ SO(3)` is a Rodrigues rotation: there is a unit axis `n` (`n₀² + n₁² + n₂² = 1`) and an angle +`θ` with `O v = rot3D n θ v` for every `v : Fin 3 → ℝ`. + +`n` is the fixed axis of `O` (Euler, +`exists_unit_mulVec_self_of_mem_specialOrthogonalGroup`); completing `n` to a right-handed +orthonormal frame `{n, u, w = n × u}`, orthogonality gives `O u = cos θ • u + sin θ • w` and (via +`SO(3)`-cross-product preservation) `O w = -sin θ • u + cos θ • w`, so `O` and `rot3D n θ` agree on +the frame, hence everywhere. This is the axis–angle ingredient of the qubit converse of Nielsen & +Chuang, Problem 8.3. -/ +theorem exists_rot3D_eq_mulVec_of_mem_specialOrthogonalGroup + {O : Matrix (Fin 3) (Fin 3) ℝ} (hO : O ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ) : + ∃ (n : Fin 3 → ℝ) (θ : ℝ), (n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) ∧ + ∀ v, O.mulVec v = rot3D n θ v := by + obtain ⟨hOorth, hdet⟩ := Matrix.mem_specialOrthogonalGroup_iff.mp hO + -- Euler axis `n`, fixed by `O`. + obtain ⟨n, hnsq, hOn⟩ := exists_unit_mulVec_self_of_mem_specialOrthogonalGroup hO + have hnn : n ⬝ᵥ n = 1 := by simpa only [dotProduct, Fin.sum_univ_three, ← pow_two] using hnsq + -- A unit vector `u ⟂ n`, and the completing `w = n × u`. + obtain ⟨u, huu, hnu⟩ := exists_unit_dotProduct_zero hnn + set w := crossProduct n u with hw + have hnw : n ⬝ᵥ w = 0 := by rw [hw]; exact dot_self_cross n u + have huw : u ⬝ᵥ w = 0 := by rw [hw]; exact dot_cross_self n u + have hwu : w ⬝ᵥ u = 0 := by rw [dotProduct_comm]; exact huw + -- `O` preserves dot & cross products. + have hdotpres := mulVec_dotProduct_mulVec_of_mem_orthogonalGroup hOorth + have hcrosspres := mulVec_crossProduct_of_mem_specialOrthogonalGroup hO + -- `O u` lies in the `n`-orthogonal plane. + have hnOu : n ⬝ᵥ (O.mulVec u) = 0 := by + conv_lhs => rw [← hOn] + rw [hdotpres]; exact hnu + set c : ℝ := u ⬝ᵥ (O.mulVec u) with hc + set s : ℝ := w ⬝ᵥ (O.mulVec u) with hs + have hOu : O.mulVec u = c • u + s • w := by + have := frame_expansion hnn huu hnu (O.mulVec u) + rw [hnOu, zero_smul, zero_add, ← hw, ← hc, ← hs] at this + exact this + -- `c² + s² = 1`. + have hcs : c ^ 2 + s ^ 2 = 1 := by + have expand : (O.mulVec u) ⬝ᵥ (O.mulVec u) + = c ^ 2 * (u ⬝ᵥ u) + c * s * (u ⬝ᵥ w) + s * c * (w ⬝ᵥ u) + s ^ 2 * (w ⬝ᵥ w) := by + conv_lhs => rw [hOu] + simp only [dotProduct_add, add_dotProduct, smul_dotProduct, dotProduct_smul, smul_eq_mul] + ring + rw [hdotpres, huu, huw, hwu] at expand + have hww : w ⬝ᵥ w = 1 := by + rw [hw]; exact crossProduct_dotProduct_self_of_orthonormal hnn huu hnu + rw [hww] at expand + nlinarith [expand, huu] + -- The angle. + obtain ⟨θ, hcos, hsin⟩ := exists_cos_sin_of_sq_add_sq hcs + refine ⟨n, θ, hnsq, fun v => ?_⟩ + -- `n × w = -u`. + have hnw' : crossProduct n w = -u := by + rw [hw, cross_cross_eq_smul_sub_smul', hnu, hnn, zero_smul, one_smul, zero_sub] + -- Agreement on the three frame vectors. + have hOn_eq : O.mulVec n = rot3D n θ n := by rw [hOn, rot3D_self hnsq] + have hru : rot3D n θ u = c • u + s • w := by + rw [rot3D, hnu, mul_zero, zero_smul, add_zero, hcos, hsin, ← hw] + have hOu_eq : O.mulVec u = rot3D n θ u := by rw [hOu, hru] + have hOw : O.mulVec w = -(s • u) + c • w := by + rw [hw, hcrosspres, hOn, ← hw, hOu, map_add, map_smul, map_smul, ← hw, hnw'] + module + have hrw : rot3D n θ w = -(s • u) + c • w := by + rw [rot3D, hnw, mul_zero, zero_smul, add_zero, hcos, hsin, hnw'] + module + have hOw_eq : O.mulVec w = rot3D n θ w := by rw [hOw, hrw] + -- Extend to all `v` by frame expansion and linearity. + have hv := frame_expansion hnn huu hnu v + rw [← hw] at hv + calc O.mulVec v + = O.mulVec ((n ⬝ᵥ v) • n + (u ⬝ᵥ v) • u + (w ⬝ᵥ v) • w) := by rw [← hv] + _ = (n ⬝ᵥ v) • O.mulVec n + (u ⬝ᵥ v) • O.mulVec u + (w ⬝ᵥ v) • O.mulVec w := by + simp only [Matrix.mulVec_add, Matrix.mulVec_smul] + _ = (n ⬝ᵥ v) • rot3D n θ n + (u ⬝ᵥ v) • rot3D n θ u + (w ⬝ᵥ v) • rot3D n θ w := by + rw [hOn_eq, hOu_eq, hOw_eq] + _ = rot3D n θ ((n ⬝ᵥ v) • n + (u ⬝ᵥ v) • u + (w ⬝ᵥ v) • w) := by + rw [rot3D_add, rot3D_add, rot3D_smul, rot3D_smul, rot3D_smul] + _ = rot3D n θ v := by rw [← hv] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/SpecialOrthogonalFixedAxis.lean b/LeanPool/AxQM/Concrete/SpecialOrthogonalFixedAxis.lean new file mode 100644 index 0000000000..ebe0114f67 --- /dev/null +++ b/LeanPool/AxQM/Concrete/SpecialOrthogonalFixedAxis.lean @@ -0,0 +1,100 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv +public import Mathlib.Analysis.SpecialFunctions.Sqrt + +/-! +# Concrete: every proper rotation of `ℝ³` fixes an axis (Euler's rotation theorem) + +This file supplies the pure linear-algebra content behind the *axis* step of the qubit converse of +**Nielsen & Chuang, Problem 8.3** (p. 396): every `O ∈ SO(3)` has a unit vector it fixes. + +> **Euler's rotation theorem.** For every `O ∈ SO(3)` there is a *unit* vector `n : Fin 3 → ℝ` +> (`n₀² + n₁² + n₂² = 1`) with `O n = n`. + +## Context in N&C + +Problem 8.3's qubit direction realises a unital single-qubit channel's Bloch matrix `M` as +`M = O₁ · diagonal d · O₂` (`Concrete.exists_specialOrthogonalGroup_diagonal_factor`) and must then +realise the proper rotations `O₁, O₂ ∈ SO(3)` as *unitary conjugations* on the Bloch sphere (the +`SU(2) → SO(3)` cover, whose forward direction is `Concrete.blochRotationOfUnitary`). The +surjectivity of that cover reduces to the classical **axis–angle decomposition** `O = rot3D n̂ θ`: +every proper +rotation is a rotation by some angle `θ` about some *axis* `n̂`, and `n̂` is exactly the unit +eigenvector of eigenvalue `1` provided here. Realising `rot3D n̂ θ` by the qubit rotation gate +`rotAxis n̂ θ` (`Concrete.blochMatrix_conj_rotAxis`) then closes the converse. + +This file is the first ingredient: the *existence of the axis*. + +## The proof (the classical determinant argument) + +The eigenvalue `1` exists because `det(O − 1) = 0`. Transposing and using `Oᵀ O = 1`, `det O = 1`, + +> `det(O − 1) = det((O − 1)ᵀ) = det(Oᵀ − 1) = det(Oᵀ (1 − O)) = det Oᵀ · det(1 − O)` +> ` = det(1 − O)`, + +while `1 − O = (−1) • (O − 1)` gives `det(1 − O) = (−1)³ det(O − 1) = −det(O − 1)` in odd dimension +`3`. Hence `det(O − 1) = −det(O − 1)`, so `det(O − 1) = 0`. A singular matrix has a nonzero kernel +vector (`Matrix.exists_mulVec_eq_zero_iff`): some `v ≠ 0` with `(O − 1) v = 0`, i.e. `O v = v`. +Normalising `v` to `n = ‖v‖⁻¹ v` keeps `O n = n` (linearity) and makes it a unit vector. + +Compare the `SO(3)` files `AxQM/Concrete/BlochSVD.lean` and +`AxQM/Concrete/BlochAffineDecomposition.lean`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **Euler's rotation theorem (existence of the axis).** Every proper rotation `O ∈ SO(3)` fixes a +unit vector: there is `n : Fin 3 → ℝ` with `n₀² + n₁² + n₂² = 1` and `O n = n`. + +`n` is a unit eigenvector of eigenvalue `1`, whose existence follows from `det(O − 1) = 0` (the +classical determinant argument, using `Oᵀ O = 1`, `det O = 1`, and oddness of the dimension). It is +the rotation axis of the axis–angle decomposition `O = rot3D n̂ θ` underlying the `SU(2) → SO(3)` +surjectivity of the qubit converse of Nielsen & Chuang, Problem 8.3. -/ +theorem exists_unit_mulVec_self_of_mem_specialOrthogonalGroup + {O : Matrix (Fin 3) (Fin 3) ℝ} (hO : O ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ) : + ∃ n : Fin 3 → ℝ, n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1 ∧ O.mulVec n = n := by + obtain ⟨hOgroup, hdetO⟩ := Matrix.mem_specialOrthogonalGroup_iff.mp hO + have hOO : Oᵀ * O = 1 := (Matrix.mem_orthogonalGroup_iff' (Fin 3) ℝ).mp hOgroup + -- `det (O - 1) = det (1 - O)` by transposing and factoring `Oᵀ - 1 = Oᵀ (1 - O)`. + have hfac : Oᵀ - 1 = Oᵀ * (1 - O) := by rw [Matrix.mul_sub, Matrix.mul_one, hOO] + have key : (O - 1).det = (1 - O).det := by + rw [← Matrix.det_transpose (O - 1), Matrix.transpose_sub, Matrix.transpose_one, hfac, + Matrix.det_mul, Matrix.det_transpose, hdetO, one_mul] + -- but `1 - O = (-1) • (O - 1)`, so in dimension 3 `det (1 - O) = -det (O - 1)`. + have hdet : (O - 1).det = 0 := by + have h2 : (1 - O) = (-1 : ℝ) • (O - 1) := by rw [neg_one_smul]; abel + rw [h2, Matrix.det_smul, Fintype.card_fin] at key + have h3 : ((-1 : ℝ)) ^ 3 = -1 := by norm_num + rw [h3] at key + linarith [key] + -- A singular matrix has a nonzero kernel vector `v`; then `O v = v`. + obtain ⟨v, hv0, hv⟩ := Matrix.exists_mulVec_eq_zero_iff.mpr hdet + have hOv : O.mulVec v = v := by + rw [Matrix.sub_mulVec, Matrix.one_mulVec] at hv + exact sub_eq_zero.mp hv + -- `v ≠ 0` so its squared length is positive; normalise `v` to a unit vector. + have hs_pos : 0 < v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2 := by + obtain ⟨i, hi⟩ := Function.ne_iff.mp hv0 + simp only [Pi.zero_apply] at hi + fin_cases i <;> simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, Fin.reduceFinMk] at hi <;> + positivity + refine ⟨(Real.sqrt (v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2))⁻¹ • v, ?_, ?_⟩ + · simp only [Pi.smul_apply, smul_eq_mul, mul_pow, inv_pow, Real.sq_sqrt hs_pos.le, ← mul_add, + inv_mul_cancel₀ hs_pos.ne'] + · rw [Matrix.mulVec_smul, hOv] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/SqrtNot.lean b/LeanPool/AxQM/Concrete/SqrtNot.lean new file mode 100644 index 0000000000..ddb10eb267 --- /dev/null +++ b/LeanPool/AxQM/Concrete/SqrtNot.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.Pauli + +/-! +# Concrete: the `√NOT` gate — Barenco's `V` (with `V² = X`) for the tight-register `Cⁿ(X)` + +This file introduces the **square-root-of-`NOT`** gate + +`√X = V = ½ !![1 + i, 1 − i; 1 − i, 1 + i]`, + +a fixed `2 × 2` unitary with `V² = X` (the Pauli/`NOT` gate). It is the elementary building block +of Nielsen & Chuang's *no-work-qubit* multiply-controlled-`NOT` construction (Exercise 4.30 / +Barenco *et al.* Lemma 7.5): a `Cⁿ(X)` on a **tight** register of exactly `n + 1` qubits (`n` +controls, one target, no spare/work wire) is reduced using controlled-`V`/controlled-`V†` gates +together with two smaller `Cⁿ⁻¹(X)` gates. + +## Why a genuine single-qubit gate is unavoidable here (parity) + +On a tight `n + 1`-wire register (`n ≥ 3`), `Cⁿ(X)` — with control set *all* `n` other wires and a +single target — is, as a permutation of the `2^{n+1}` computational basis states, a **single +transposition** (it swaps only the two strings with every control set to `1`), hence an **odd** +permutation. Every gate with at most two controls (`Toffoli`, `CNOT`, `NOT`) on `≥ 4` wires is, by +contrast, an **even** permutation (it swaps `2^{k}` disjoint pairs with `k ≥ 1`). A product of even +permutations is even, so `Cⁿ(X)` on the tight register is **provably not** a product of +`Toffoli`/`CNOT`/`NOT` *permutation* gates: N&C's "single-qubit gates" in Exercise 4.29 are +essential and cannot be replaced by classical `NOT`s. `√X` is the non-permutation single-qubit gate +that resolves the parity obstruction — its off-diagonal-plus-diagonal complex entries make it a true +unitary rotation, not a basis permutation. + +This is the matrix-level counterpart of the Evolution-level `sqrtChain`/`barencoNCircuit` +development (`AxQM.cnx_eq_barencoNCircuit`); the `Cⁿ(X)` reduction driving Exercise 4.43 +runs on the encoded-basis matrix gates (`ctrlSingleQubit enc`, `singleQubitOnWire enc`), so it needs +a *matrix* `√X`. + +Everything here is pure `2 × 2` complex-matrix algebra. The proofs mirror +`AxQM/Concrete/Pauli.lean`: reduce to the closed `!!`-form and compute entrywise. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix Complex + +/-- The **`√NOT` gate** `V = ½ !![1 + i, 1 − i; 1 − i, 1 + i]`, a fixed square root of the Pauli +`X`/`NOT` gate (`V² = X`, `sqrtNot_mul_self`). It is unitary but *not* Hermitian and *not* a +permutation matrix; it is Barenco's `V` for the tight-register `Cⁿ(X)` reduction (Exercise 4.30). -/ +noncomputable def sqrtNot : Matrix (Fin 2) (Fin 2) ℂ := + !![(1 + I) / 2, (1 - I) / 2; (1 - I) / 2, (1 + I) / 2] + +/-- **The defining Barenco property**: `V² = X`. The diagonal entries are +`((1 ± i)/2)² + ((1 ∓ i)/2)² = i/2 − i/2 = 0` and the off-diagonal entries are +`2 · (1 + i)(1 − i)/4 = 1`, so `V · V = !![0, 1; 1, 0] = X`. -/ +theorem sqrtNot_mul_self : sqrtNot * sqrtNot = pauliX := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sqrtNot, pauliX, Matrix.mul_apply, Fin.sum_univ_two, Complex.ext_iff] <;> norm_num + +/-- The conjugate transpose of `V` in closed form: `Vᴴ = ½ !![1 − i, 1 + i; 1 + i, 1 − i]`. Since +`V` is symmetric, `Vᴴ` is its entrywise complex conjugate. -/ +theorem sqrtNot_conjTranspose : + sqrtNotᴴ = !![(1 - I) / 2, (1 + I) / 2; (1 + I) / 2, (1 - I) / 2] := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [sqrtNot, Matrix.conjTranspose_apply, Complex.ext_iff] + +/-- `V` is unitary: `Vᴴ V = I`. With `Vᴴ = ½ !![1 − i, 1 + i; 1 + i, 1 − i]`, each diagonal entry of +`Vᴴ V` is `2 · (1 + i)(1 − i)/4 = 1` and each off-diagonal entry is +`((1 ∓ i)² + (1 ± i)²)/4 = 0`. -/ +theorem sqrtNot_conjTranspose_mul_self : sqrtNotᴴ * sqrtNot = 1 := by + rw [sqrtNot_conjTranspose] + ext i j + fin_cases i <;> fin_cases j <;> + simp [sqrtNot, Matrix.mul_apply, Fin.sum_univ_two, Complex.ext_iff] <;> norm_num + +/-- `V` is unitary: `V Vᴴ = I` (companion of `sqrtNot_conjTranspose_mul_self`, flipped through +`mul_eq_one_comm` rather than recomputed). -/ +theorem sqrtNot_mul_conjTranspose : sqrtNot * sqrtNotᴴ = 1 := + mul_eq_one_comm.mpr sqrtNot_conjTranspose_mul_self + +/-- **`V` is unitary** (`V ∈ Matrix.unitaryGroup`), so the `√NOT` gate is a legitimate single-qubit +gate — the target family the tight-register `Cⁿ(X)` reduction places on individual wires. -/ +theorem sqrtNot_mem_unitaryGroup : sqrtNot ∈ Matrix.unitaryGroup (Fin 2) ℂ := + Matrix.mem_unitaryGroup_iff'.mpr (by + rw [Matrix.star_eq_conjTranspose]; exact sqrtNot_conjTranspose_mul_self) + +/-- **`Vᴴ` is unitary** (`Vᴴ ∈ Matrix.unitaryGroup`) — the adjoint of a unitary is unitary. Since +`Matrix.unitaryGroup` is `unitary (Matrix …)` and `Vᴴ = star V`, this is the general structural +`Unitary.star_mem` applied to `sqrtNot_mem_unitaryGroup`. The controlled-`V†` factor of the Barenco +tight-register `Cⁿ(X)` recursion is therefore a legitimate single-qubit gate. -/ +theorem sqrtNot_conjTranspose_mem_unitaryGroup : sqrtNotᴴ ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + rw [← Matrix.star_eq_conjTranspose] + exact Unitary.star_mem sqrtNot_mem_unitaryGroup + +/-- `Vᴴ` is also a square root of `X`: `(Vᴴ)² = X`. Indeed `(Vᴴ)² = (V²)ᴴ = Xᴴ = X`, since `X` is +Hermitian; it is the controlled-`V†` factor of the Barenco reduction. -/ +theorem sqrtNot_conjTranspose_mul_self_eq_pauliX : sqrtNotᴴ * sqrtNotᴴ = pauliX := by + rw [← Matrix.conjTranspose_mul, sqrtNot_mul_self]; exact pauliX_isHermitian + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerCodeDimension.lean b/LeanPool/AxQM/Concrete/StabilizerCodeDimension.lean new file mode 100644 index 0000000000..819c4eeacd --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerCodeDimension.lean @@ -0,0 +1,320 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.CheckMatrix +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Trace +public import Mathlib.LinearAlgebra.Projection +public import Mathlib.LinearAlgebra.Matrix.ToLin +public import Mathlib.Algebra.Module.Submodule.EqLocus +public import Mathlib.Data.List.OfFn + +/-! +# Concrete: Nielsen & Chuang Proposition 10.5 — a stabilizer code space is `2^k`-dimensional + +This file formalizes Nielsen & Chuang's +**Proposition 10.5** (§10.5.1, p. 458), the dimension count for stabilizer code spaces. + +Proposition 10.5: a stabilizer generated by n − k independent commuting elements with −I ∉ S fixes a +2^k-dimensional subspace. + +Here `V_S` is the **stabilized subspace** `{|ψ⟩ : g|ψ⟩ = |ψ⟩ for all g ∈ S}`, the simultaneous +`+1`-eigenspace of the generators. + +## Statement shape and faithfulness + +We work with the **phase-free** Pauli strings `Concrete.pauliString g` (indexed by `g : Fin n → +Fin 4`), on the `n`-qubit register `(Fin n → Fin 2) → ℂ`. Three design points make the statement +faithful to N&C, matching the conventions used for Propositions 10.3 and 10.4: + +* **`-I ∉ S` enters only through `gⱼ² = I`.** N&C's hypothesis `-I ∉ S` forces every generator to + square to the identity and hence be a Hermitian involution (Exercises 10.34/10.35). Every + `pauliString g` is unconditionally an involution (`pauliString_mul_self`) and Hermitian + (`pauliString_isHermitian`), so the phase-free representation supplies exactly the consequence + of `-I ∉ S` the proof uses, with no `-I ∉ S` hypothesis to carry. +* **"independent generators" ⇔ "check-matrix rows linearly independent".** This is Proposition + 10.3 (in the `-I ∉ S` world). We state independence directly as `LinearIndependent (ZMod 2) + (fun j ↦ checkRow gⱼ)`, the equivalent (not weaker) form the proof consumes, via the check row + `checkRow` (`AxQM/Concrete/CheckMatrix.lean`). +* **"commuting generators"** is stated as `∀ i j, Commute (pauliString gᵢ) (pauliString gⱼ)` — + literally that the operators commute. + +The conclusion is the honest linear-algebra statement `Module.finrank ℂ (stabilizedSubspace g) * +2 ^ m = 2 ^ n` for `m` generators (`stabilizedSubspace_finrank_mul`); the `2^k` form of N&C +follows for `m = n - k` and `k ≤ n` (`stabilizedSubspace_finrank`). The multiplicative form avoids +natural subtraction and needs no separate `m ≤ n` hypothesis (that `m ≤ n` is forced is a +*consequence*: the right-hand side `2^n` must be divisible by `2^m`). + +## The proof + +We follow N&C's projector argument, in the direct trace form. Let + +`P_S = 2^{-m} · ∏_{j} (I + gⱼ)` (`stabilizerProjector`), + +the matrix `∏_j (I + gⱼ)/2`. Two matrix facts, each a short induction peeling the leading factor +of the ordered product `∏_j (I + gⱼ)` (`stabilizerProduct`, a `List.ofFn` product), show `P_S` is +an honest projection onto `V_S`: + +* `stabilizerProduct_absorb`: each generator absorbs the product, `gᵢ · ∏ = ∏` (commutativity + slides `gᵢ` to its factor `(I + gᵢ)`, where `gᵢ(I + gᵢ) = I + gᵢ` by the involution). Hence + `gᵢ P_S = P_S`, so `P_S` maps every vector into `V_S`. +* `stabilizerProduct_mulVec`: if every `gⱼ` fixes `v` then each factor doubles it, `∏ ·ᵥ v = + 2^m v`, so `P_S ·ᵥ v = v`; `P_S` is the identity on `V_S`. + +Thus `Matrix.toLin' P_S` is a `LinearMap.IsProj (stabilizedSubspace g)`, and by +`LinearMap.IsProj.trace`, `trace P_S = finrank V_S`. The trace of `P_S` is `2^{n-m}`: expanding the +product, only the empty subproduct `I` survives, because every *nonempty* subproduct `∏_{j ∈ T} gⱼ` +is `± pauliString(⊕_{j∈T} gⱼ)` with a *nonzero* index (independence of the check rows forbids a +nonempty subset summing to `0`), hence traceless (`pauliString_trace`). We realize this without an +explicit power-set expansion, by a "test Pauli" induction: + +* `stabilizerProduct_trace_mul_of_notMem`: if `checkRow h` is not in the span of the generators' + check rows, then `trace(pauliString h · ∏) = 0`. Peeling the leading factor produces two smaller + instances with test Paulis `h` and `h ⊙ g₀`, both still outside the tail's span. +* `stabilizerProduct_trace`: for independent generators, `trace ∏ = 2^n` (take the trivial test + Pauli `I`; the leading generator is outside the tail's span by independence). + +Combining, `(finrank V_S) · 2^m = 2^n`. + +Everything is stated for raw matrix / index data (`Matrix`, `Concrete.pauliString`, `checkRow`, +`ZMod 2`, `Fin n → Fin 4`, `Submodule`, `Module.finrank`). + +The statement of N&C Proposition 10.5 (p. 458) is in [upstream `AxQM/NC/Ch10/Proposition10_5.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Proposition10_5.lean). +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The ordered product `∏_j (I + gⱼ)` -/ + +/-- The **ordered product of stabilizer factors** `∏_{j} (I + P_{gⱼ})`, over the generators +`g : Fin m → (Fin n → Fin 4)`. Scaled by `2^{-m}` this is the stabilizer projector +`stabilizerProjector`; the factors commute when the generators do, so the order is immaterial, but +we fix the `List.ofFn` order to make the leading-factor inductions literal. -/ +noncomputable def stabilizerProduct {m : ℕ} (g : Fin m → (Fin n → Fin 4)) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + (List.ofFn fun j => 1 + pauliString (g j)).prod + +/-- The empty stabilizer product (`m = 0` generators) is the identity. -/ +theorem stabilizerProduct_zero (g : Fin 0 → (Fin n → Fin 4)) : stabilizerProduct g = 1 := by + rw [stabilizerProduct, List.ofFn_zero, List.prod_nil] + +/-- Peeling the leading factor: `∏_{j < m+1} (I + gⱼ) = (I + g₀) · ∏_{i < m} (I + g_{i+1})`. -/ +theorem stabilizerProduct_succ {m : ℕ} (g : Fin (m + 1) → (Fin n → Fin 4)) : + stabilizerProduct g = (1 + pauliString (g 0)) * stabilizerProduct (fun i => g i.succ) := by + rw [stabilizerProduct, List.ofFn_succ, List.prod_cons] + rfl + +/-- **Each generator absorbs the stabilizer product**: `P_{gᵢ} · ∏_j (I + P_{gⱼ}) = ∏_j (I + +P_{gⱼ})` for commuting generators. Sliding `P_{gᵢ}` (which commutes with every factor) to its own +factor `(I + P_{gᵢ})`, the involution `P_{gᵢ}(I + P_{gᵢ}) = P_{gᵢ} + I = I + P_{gᵢ}` absorbs it. +This is the matrix fact behind `P_S` mapping every vector into the stabilized subspace. -/ +theorem stabilizerProduct_absorb : + ∀ {m : ℕ} (g : Fin m → (Fin n → Fin 4)), + (∀ i j, Commute (pauliString (g i)) (pauliString (g j))) → ∀ i : Fin m, + pauliString (g i) * stabilizerProduct g = stabilizerProduct g := by + intro m + induction m with + | zero => intro g _ i; exact i.elim0 + | succ m ih => + intro g hcomm i + rw [stabilizerProduct_succ] + refine Fin.cases ?_ ?_ i + · rw [← mul_assoc, mul_add, mul_one, pauliString_mul_self, add_comm (pauliString (g 0)) 1] + · intro i' + have hc : Commute (pauliString (g i'.succ)) (1 + pauliString (g 0)) := + (Commute.one_right _).add_right (hcomm i'.succ 0) + rw [← mul_assoc, hc.eq, mul_assoc] + congr 1 + exact ih (fun i => g i.succ) (fun a b => hcomm a.succ b.succ) i' + +/-- **The stabilizer product doubles a jointly-stabilized vector**: if every generator fixes `v` +(`P_{gⱼ} ·ᵥ v = v`), then `(∏_j (I + P_{gⱼ})) ·ᵥ v = 2^m • v`, since each factor sends +`v ↦ v + v = 2v`. This is the matrix fact behind `P_S` acting as the identity on `V_S`. -/ +theorem stabilizerProduct_mulVec : + ∀ {m : ℕ} (g : Fin m → (Fin n → Fin 4)) (v : (Fin n → Fin 2) → ℂ), + (∀ i, (pauliString (g i)).mulVec v = v) → + (stabilizerProduct g).mulVec v = (2 : ℂ) ^ m • v := by + intro m + induction m with + | zero => + intro g v _ + rw [stabilizerProduct_zero, Matrix.one_mulVec, pow_zero, one_smul] + | succ m ih => + intro g v hv + rw [stabilizerProduct_succ, ← Matrix.mulVec_mulVec, + ih (fun i => g i.succ) v (fun i => hv i.succ), Matrix.add_mulVec, Matrix.one_mulVec, + Matrix.mulVec_smul, hv 0, ← add_smul, ← two_mul, ← pow_succ'] + +/-! ### Traces of stabilizer products -/ + +/-- **Trace of a stabilizer product against an "off-span" test Pauli vanishes.** If `checkRow h` is +not in the `ZMod 2`-span of the generators' check rows, then `tr(P_h · ∏_j (I + P_{gⱼ})) = 0`. +Peeling the leading factor `(I + P_{g₀})` splits the trace into the test Paulis `h` and `h ⊙ g₀`, +both of which stay outside the *tail's* span (for `h ⊙ g₀`: if `checkRow (h ⊙ g₀) = checkRow h + +checkRow g₀` were in the span, then `checkRow h` would be too, since `checkRow g₀` is), so both +sub-traces vanish by induction. This is the engine that kills every nonempty subproduct. -/ +theorem stabilizerProduct_trace_mul_of_notMem : + ∀ {m : ℕ} (g : Fin m → (Fin n → Fin 4)) (h : Fin n → Fin 4), + checkRow h ∉ Submodule.span (ZMod 2) (Set.range fun j => checkRow (g j)) → + (pauliString h * stabilizerProduct g).trace = 0 := by + intro m + induction m with + | zero => + intro g h hh + have hne : ¬ h = 0 := by + rw [← checkRow_eq_zero_iff] + intro h0 + exact hh (by rw [h0]; exact Submodule.zero_mem _) + rw [stabilizerProduct_zero, mul_one, pauliString_trace, ite_eq_right hne] + | succ m ih => + intro g h hh + have hsub : Submodule.span (ZMod 2) (Set.range fun j : Fin m => checkRow (g j.succ)) + ≤ Submodule.span (ZMod 2) (Set.range fun j : Fin (m + 1) => checkRow (g j)) := by + apply Submodule.span_mono + rintro _ ⟨i, rfl⟩ + exact ⟨i.succ, rfl⟩ + have hh1 : checkRow h + ∉ Submodule.span (ZMod 2) (Set.range fun j : Fin m => checkRow (g j.succ)) := + fun hc => hh (hsub hc) + have hg0 : checkRow (g 0) + ∈ Submodule.span (ZMod 2) (Set.range fun j : Fin (m + 1) => checkRow (g j)) := + Submodule.subset_span ⟨0, rfl⟩ + have hh2 : checkRow (pauliMulIndex h (g 0)) + ∉ Submodule.span (ZMod 2) (Set.range fun j : Fin m => checkRow (g j.succ)) := by + intro hc + apply hh + have hrw : checkRow h = checkRow (pauliMulIndex h (g 0)) - checkRow (g 0) := by + rw [checkRow_pauliMulIndex, add_sub_cancel_right] + rw [hrw] + exact Submodule.sub_mem _ (hsub hc) hg0 + rw [stabilizerProduct_succ, ← mul_assoc, mul_add, mul_one, pauliString_mul_eq_smul, add_mul, + smul_mul_assoc, Matrix.trace_add, Matrix.trace_smul, ih (fun i => g i.succ) h hh1, + ih (fun i => g i.succ) (pauliMulIndex h (g 0)) hh2, smul_zero, add_zero] + +/-- **Trace of the stabilizer product of independent generators is `2^n`.** For check rows that are +`ZMod 2`-linearly independent, `tr(∏_j (I + P_{gⱼ})) = 2^n`. By induction on the number of +generators: the empty product is `I` with trace `2^n`; adding a generator `g₀` splits the trace as +`tr(∏_{tail}) + tr(P_{g₀} · ∏_{tail})`, the first `= 2^n` by induction and the second `= 0` because +`checkRow g₀` lies outside the span of the tail's rows (independence), via +`stabilizerProduct_trace_mul_of_notMem`. -/ +theorem stabilizerProduct_trace : + ∀ {m : ℕ} (g : Fin m → (Fin n → Fin 4)), + LinearIndependent (ZMod 2) (fun j => checkRow (g j)) → + (stabilizerProduct g).trace = (2 : ℂ) ^ n := by + intro m + induction m with + | zero => + intro g _ + rw [stabilizerProduct_zero, Matrix.trace_one] + simp only [Fintype.card_fun, Fintype.card_fin] + push_cast + ring + | succ m ih => + intro g hindep + have hnotmem : checkRow (g 0) + ∉ Submodule.span (ZMod 2) (Set.range fun j : Fin m => checkRow (g j.succ)) := by + intro hc + refine hindep.notMem_span 0 ?_ + refine Submodule.span_mono ?_ hc + rintro _ ⟨i, rfl⟩ + exact ⟨i.succ, Fin.succ_ne_zero i, rfl⟩ + rw [stabilizerProduct_succ, add_mul, one_mul, Matrix.trace_add, + ih (fun i => g i.succ) (hindep.comp Fin.succ (Fin.succ_injective m)), + stabilizerProduct_trace_mul_of_notMem (fun i => g i.succ) (g 0) hnotmem, add_zero] + +/-! ### The stabilized subspace and its dimension -/ + +/-- The **stabilized subspace** `V_S = {v : ∀ j, P_{gⱼ} ·ᵥ v = v}`, the simultaneous +`+1`-eigenspace of the (phase-free) generators `g`, as a `ℂ`-submodule of the `n`-qubit register. -/ +noncomputable def stabilizedSubspace {m : ℕ} (g : Fin m → (Fin n → Fin 4)) : + Submodule ℂ ((Fin n → Fin 2) → ℂ) := + ⨅ i, LinearMap.eqLocus (Matrix.toLin' (pauliString (g i))) LinearMap.id + +/-- Membership in the stabilized subspace: `v ∈ V_S ↔ ∀ i, P_{gᵢ} ·ᵥ v = v`. -/ +theorem mem_stabilizedSubspace {m : ℕ} {g : Fin m → (Fin n → Fin 4)} + {v : (Fin n → Fin 2) → ℂ} : + v ∈ stabilizedSubspace g ↔ ∀ i, (pauliString (g i)).mulVec v = v := by + simp only [stabilizedSubspace, Submodule.mem_iInf, LinearMap.mem_eqLocus, Matrix.toLin'_apply, + LinearMap.id_apply] + +/-- The **stabilizer projector** `P_S = 2^{-m} · ∏_j (I + P_{gⱼ}) = ∏_j (I + P_{gⱼ})/2`. For +commuting generators this is the orthogonal projector onto the stabilized subspace `V_S`. -/ +noncomputable def stabilizerProjector {m : ℕ} (g : Fin m → (Fin n → Fin 4)) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + ((2 : ℂ) ^ m)⁻¹ • stabilizerProduct g + +/-- Each generator absorbs the stabilizer projector: `P_{gᵢ} · P_S = P_S` (commuting generators). -/ +theorem stabilizerProjector_absorb {m : ℕ} (g : Fin m → (Fin n → Fin 4)) + (hcomm : ∀ i j, Commute (pauliString (g i)) (pauliString (g j))) (i : Fin m) : + pauliString (g i) * stabilizerProjector g = stabilizerProjector g := by + rw [stabilizerProjector, mul_smul_comm, stabilizerProduct_absorb g hcomm i] + +/-- **The stabilizer projector is a projection onto `V_S`.** For commuting generators, +`Matrix.toLin' P_S` is a `LinearMap.IsProj` onto the stabilized subspace: it maps every vector into +`V_S` (`stabilizerProjector_absorb`) and fixes `V_S` pointwise (`stabilizerProduct_mulVec`). -/ +theorem stabilizerProjector_isProj {m : ℕ} (g : Fin m → (Fin n → Fin 4)) + (hcomm : ∀ i j, Commute (pauliString (g i)) (pauliString (g j))) : + LinearMap.IsProj (stabilizedSubspace g) (Matrix.toLin' (stabilizerProjector g)) := by + refine ⟨fun v => ?_, fun v hv => ?_⟩ + · rw [mem_stabilizedSubspace] + intro i + rw [Matrix.toLin'_apply, Matrix.mulVec_mulVec, stabilizerProjector_absorb g hcomm i] + · rw [Matrix.toLin'_apply, stabilizerProjector, Matrix.smul_mulVec, + stabilizerProduct_mulVec g v (mem_stabilizedSubspace.mp hv), smul_smul, + inv_mul_cancel₀ (pow_ne_zero m two_ne_zero), one_smul] + +/-- **Nielsen & Chuang, Proposition 10.5 (multiplicative form).** For `m` phase-free generators +`g : Fin m → (Fin n → Fin 4)` that pairwise commute and whose check-matrix rows are `ZMod +2`-linearly independent (equivalently, by Proposition 10.3, the generators are independent; `-I ∉ S` +is automatic for phase-free strings), the stabilized subspace `V_S` satisfies + +`finrank ℂ V_S · 2^m = 2^n`, + +i.e. `V_S` has dimension `2^{n-m}`. The stabilizer projector `P_S` is a projection onto `V_S` +(`stabilizerProjector_absorb` gives `P_S ↦ V_S`, `stabilizerProduct_mulVec` gives `P_S = id` on +`V_S`), so `finrank V_S = trace P_S` by `LinearMap.IsProj.trace`; and `trace P_S = 2^{-m} · 2^n` by +`stabilizerProduct_trace`. -/ +theorem stabilizedSubspace_finrank_mul {m : ℕ} (g : Fin m → (Fin n → Fin 4)) + (hcomm : ∀ i j, Commute (pauliString (g i)) (pauliString (g j))) + (hindep : LinearIndependent (ZMod 2) (fun j => checkRow (g j))) : + Module.finrank ℂ (stabilizedSubspace g) * 2 ^ m = 2 ^ n := by + have h2m : (2 : ℂ) ^ m ≠ 0 := pow_ne_zero m two_ne_zero + -- `finrank V_S = trace P_S = 2^{-m} · 2^n`. + have htrace : + (stabilizerProjector g).trace = (Module.finrank ℂ (stabilizedSubspace g) : ℂ) := by + rw [← Matrix.trace_toLin'_eq]; exact (stabilizerProjector_isProj g hcomm).trace + rw [stabilizerProjector, Matrix.trace_smul, stabilizerProduct_trace g hindep, smul_eq_mul] + at htrace + have key : (Module.finrank ℂ (stabilizedSubspace g) : ℂ) * (2 : ℂ) ^ m = (2 : ℂ) ^ n := by + rw [← htrace, mul_comm (((2 : ℂ) ^ m)⁻¹) ((2 : ℂ) ^ n), mul_assoc, inv_mul_cancel₀ h2m, + mul_one] + exact_mod_cast key + +/-- **Nielsen & Chuang, Proposition 10.5.** A stabilizer code space stabilized by `n - k` +independent commuting phase-free generators is `2^k`-dimensional: `finrank ℂ V_S = 2^k` (for +`k ≤ n`). Immediate from the multiplicative form `stabilizedSubspace_finrank_mul` by cancelling the +common factor `2^{n-k}` from `finrank V_S · 2^{n-k} = 2^n = 2^k · 2^{n-k}`. -/ +theorem stabilizedSubspace_finrank {n k : ℕ} (hk : k ≤ n) (g : Fin (n - k) → (Fin n → Fin 4)) + (hcomm : ∀ i j, Commute (pauliString (g i)) (pauliString (g j))) + (hindep : LinearIndependent (ZMod 2) (fun j => checkRow (g j))) : + Module.finrank ℂ (stabilizedSubspace g) = 2 ^ k := by + have h := stabilizedSubspace_finrank_mul g hcomm hindep + have hn : (2 : ℕ) ^ n = 2 ^ k * 2 ^ (n - k) := by rw [← pow_add, Nat.add_sub_cancel' hk] + rw [hn] at h + exact Nat.eq_of_mul_eq_mul_right (pow_pos (by norm_num : (0 : ℕ) < 2) (n - k)) h + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerCodeProjector.lean b/LeanPool/AxQM/Concrete/StabilizerCodeProjector.lean new file mode 100644 index 0000000000..b2d62905c2 --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerCodeProjector.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliGroupNegOne +public import Mathlib.Algebra.Group.Subgroup.Basic +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic + +/-! +# Concrete: the group-average stabilizer code projector (Nielsen & Chuang, Theorem 10.8 setup) + +This file builds the **projector onto the +code space `C(S)`** of a stabilizer code, directly from the abstract stabilizer group `S`, and +proves the algebra Nielsen & Chuang's **Theorem 10.8** consumes. Everything here is stated for the +abstract `n`-qubit Pauli group `PauliGroup n`, its subgroups, and raw matrices +(`Matrix`, `Concrete.pauliString`). + +## The stabilizer and its code projector + +A **stabilizer** is a subgroup `S ≤ Gₙ` of the `n`-qubit Pauli group with `-I ∉ S` (`negOne n ∉ S`). +This is *exactly* Nielsen & Chuang's notion of a stabilizer group: `-I ∉ S` already forces `S` to be +abelian and every element to square to `I` (`mul_comm_of_negOne_notMem`, +`sq_eq_one_of_negOne_notMem`), so such an `S` is an elementary abelian `2`-group and admits `n - k` +independent commuting generators — the presentation N&C give is a *consequence*, not an extra +hypothesis. Working with the abstract subgroup is therefore faithful, not a weakening. + +The projector onto the code space `C(S)` (the joint `+1`-eigenspace `V_S`) is the **group average** + +`P_S = |S|⁻¹ · ∑_{s ∈ S} toMat(s)` (`codeProjector`), + +where `toMat` is the faithful matrix representation `iˢ • P_a` (`PauliGroup.toMat`). This is the +standard basis-free form of the code projector (equal to the generator product `∏_l (I + gₗ)/2` +of Proposition 10.5, but not requiring a chosen generating set). Its defining algebra falls out of +one fact — **left/right translation is a bijection of `S`** — with no commutativity or induction: + +* `toMat_mul_codeProjector` / `codeProjector_mul_toMat` — **absorption**: `s ∈ S ⟹ toMat(s) · P = P` + and `P · toMat(s) = P`. (N&C: "`P` is invariant under multiplication by elements of `S`".) +* `codeProjector_isHermitian` — `P† = P` (`S` is closed under inverse and `toMat(s⁻¹) = toMat(s)†`). +* `codeProjector_mul_self` — `P² = P`: `P` is a genuine (self-adjoint idempotent) projector. +* `codeProjector_mulVec_self_iff` — **`P` is the projector onto `C(S)`**: `P ·ᵥ v = v` iff every + `s ∈ S` fixes `v` (`toMat(s) ·ᵥ v = v`), i.e. the range of `P` is exactly the joint + `+1`-eigenspace `V_S`. + +These are the standing facts of Theorem 10.8's proof; the theorem itself +(`AxQM/Concrete/StabilizerErrorCorrection.lean`) supplies the error operators and the +Knill–Laflamme conclusion. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The group-average code projector -/ + +/-- The **unnormalized stabilizer sum** `Q = ∑_{s ∈ S} toMat(s)` over a stabilizer subgroup `S`. -/ +noncomputable def stabilizerSum (S : Subgroup (PauliGroup n)) [Fintype S] : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + ∑ s : S, (↑s : PauliGroup n).toMat + +/-- `stabilizerSum` unfolded to its defining sum (a `rfl` lemma, for targeted rewriting). -/ +theorem stabilizerSum_eq (S : Subgroup (PauliGroup n)) [Fintype S] : + stabilizerSum S = ∑ s : S, (↑s : PauliGroup n).toMat := rfl + +/-- The **group-average code projector** `P_S = |S|⁻¹ · ∑_{s ∈ S} toMat(s)`, the projector onto the +code space `C(S) = V_S` of the stabilizer code with stabilizer `S`. -/ +noncomputable def codeProjector (S : Subgroup (PauliGroup n)) [Fintype S] : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + (Fintype.card S : ℂ)⁻¹ • stabilizerSum S + +/-- The order `|S|` of a stabilizer subgroup is nonzero as a complex scalar (it contains `I`). -/ +theorem card_stabilizer_ne_zero (S : Subgroup (PauliGroup n)) [Fintype S] : + (Fintype.card S : ℂ) ≠ 0 := by + have : Nonempty S := ⟨⟨1, S.one_mem⟩⟩ + exact_mod_cast Fintype.card_ne_zero + +/-! ### Absorption: `S` fixes the stabilizer sum on both sides -/ + +/-- **Left absorption**: `s ∈ S ⟹ toMat(s) · Q = Q`. Multiplication by `toMat p` sends the summand +`toMat s` to `toMat (p·s)`, and `s ↦ ⟨p, hp⟩ · s` is a bijection of `S` (`Equiv.mulLeft`), so the +sum is unchanged. -/ +theorem toMat_mul_stabilizerSum {S : Subgroup (PauliGroup n)} [Fintype S] {p : PauliGroup n} + (hp : p ∈ S) : p.toMat * stabilizerSum S = stabilizerSum S := by + rw [stabilizerSum_eq, Matrix.mul_sum, + ← Equiv.sum_comp (Equiv.mulLeft (⟨p, hp⟩ : S)) (fun t : S => (↑t : PauliGroup n).toMat)] + refine Finset.sum_congr rfl (fun s _ => ?_) + rw [Equiv.coe_mulLeft, Subgroup.coe_mul, PauliGroup.toMat_mul] + +/-- **Right absorption**: `s ∈ S ⟹ Q · toMat(s) = Q`. Symmetric to `toMat_mul_stabilizerSum`, via +the right-translation bijection `s ↦ s · ⟨p, hp⟩` (`Equiv.mulRight`). -/ +theorem stabilizerSum_mul_toMat {S : Subgroup (PauliGroup n)} [Fintype S] {p : PauliGroup n} + (hp : p ∈ S) : stabilizerSum S * p.toMat = stabilizerSum S := by + rw [stabilizerSum_eq, Matrix.sum_mul, + ← Equiv.sum_comp (Equiv.mulRight (⟨p, hp⟩ : S)) (fun t : S => (↑t : PauliGroup n).toMat)] + refine Finset.sum_congr rfl (fun s _ => ?_) + rw [Equiv.coe_mulRight, Subgroup.coe_mul, PauliGroup.toMat_mul] + +/-! ### `Q` is Hermitian and idempotent up to scale -/ + +/-- **`Q` is Hermitian**: `Q† = Q`. Conjugate-transposing each summand gives `(toMat s)† = +toMat (s⁻¹)` (`PauliGroup.toMat_inv`), and `s ↦ s⁻¹` is a bijection of `S`. -/ +theorem stabilizerSum_conjTranspose {S : Subgroup (PauliGroup n)} [Fintype S] : + (stabilizerSum S)ᴴ = stabilizerSum S := by + rw [stabilizerSum_eq, conjTranspose_sum, + ← Equiv.sum_comp (Equiv.inv S) (fun t : S => (↑t : PauliGroup n).toMat)] + refine Finset.sum_congr rfl (fun s _ => ?_) + rw [Equiv.inv_apply, Subgroup.coe_inv, PauliGroup.toMat_inv] + +/-- **`Q · Q = |S| · Q`**: distributing the left factor, each `toMat s · Q = Q` +(`toMat_mul_stabilizerSum`), so the product is `∑_{s ∈ S} Q = |S| · Q`. -/ +theorem stabilizerSum_mul_self {S : Subgroup (PauliGroup n)} [Fintype S] : + stabilizerSum S * stabilizerSum S = (Fintype.card S : ℂ) • stabilizerSum S := by + nth_rewrite 1 [stabilizerSum_eq] + rw [Matrix.sum_mul, Finset.sum_congr rfl (fun (s : S) _ => toMat_mul_stabilizerSum s.2), + Finset.sum_const, Finset.card_univ, Nat.cast_smul_eq_nsmul] + +/-! ### The code projector is a self-adjoint idempotent onto `C(S)` -/ + +/-- **The code projector is self-adjoint**: `P† = P`. Immediate from `stabilizerSum_conjTranspose` +(the scalar `|S|⁻¹` is real). -/ +theorem codeProjector_isHermitian {S : Subgroup (PauliGroup n)} [Fintype S] : + (codeProjector S).IsHermitian := by + change (codeProjector S)ᴴ = codeProjector S + rw [codeProjector, conjTranspose_smul, stabilizerSum_conjTranspose, star_inv₀, star_natCast] + +/-- **The code projector is idempotent**: `P · P = P`. From `Q · Q = |S| · Q` +(`stabilizerSum_mul_self`) and `|S|⁻¹ · |S|⁻¹ · |S| = |S|⁻¹`. -/ +theorem codeProjector_mul_self {S : Subgroup (PauliGroup n)} [Fintype S] : + codeProjector S * codeProjector S = codeProjector S := by + rw [codeProjector, smul_mul_smul_comm, stabilizerSum_mul_self, smul_smul, mul_assoc, + inv_mul_cancel₀ (card_stabilizer_ne_zero S), mul_one] + +/-- **Left absorption for the projector**: `s ∈ S ⟹ toMat(s) · P = P`. -/ +theorem toMat_mul_codeProjector {S : Subgroup (PauliGroup n)} [Fintype S] {p : PauliGroup n} + (hp : p ∈ S) : p.toMat * codeProjector S = codeProjector S := by + rw [codeProjector, mul_smul_comm, toMat_mul_stabilizerSum hp] + +/-- **Right absorption for the projector**: `s ∈ S ⟹ P · toMat(s) = P`. -/ +theorem codeProjector_mul_toMat {S : Subgroup (PauliGroup n)} [Fintype S] {p : PauliGroup n} + (hp : p ∈ S) : codeProjector S * p.toMat = codeProjector S := by + rw [codeProjector, smul_mul_assoc, stabilizerSum_mul_toMat hp] + +/-- **The code projector is the projector onto the code space `C(S)`.** A vector `v` is fixed by +`P` iff it is a joint `+1`-eigenvector of every element of `S`: `P ·ᵥ v = v ↔ ∀ s ∈ S, +toMat(s) ·ᵥ v = v`. Thus `range P = V_S`, the code space. The forward direction reads +`toMat(s) ·ᵥ v = toMat(s) ·ᵥ (P ·ᵥ v) = (toMat(s) · P) ·ᵥ v = P ·ᵥ v = v` (left absorption); the +backward direction computes `Q ·ᵥ v = ∑_{s ∈ S} v = |S| • v`, so +`P ·ᵥ v = |S|⁻¹ • (|S| • v) = v`. -/ +theorem codeProjector_mulVec_self_iff {S : Subgroup (PauliGroup n)} [Fintype S] + (v : (Fin n → Fin 2) → ℂ) : + (codeProjector S).mulVec v = v ↔ ∀ p ∈ S, p.toMat.mulVec v = v := by + constructor + · intro hv p hp + have h1 : (p.toMat * codeProjector S).mulVec v = v := by + rw [toMat_mul_codeProjector hp, hv] + rwa [← Matrix.mulVec_mulVec, hv] at h1 + · intro hv + have hQ : (stabilizerSum S).mulVec v = (Fintype.card S : ℂ) • v := by + rw [stabilizerSum_eq, Matrix.sum_mulVec, + Finset.sum_congr rfl (fun (s : S) _ => hv (↑s) s.2), + Finset.sum_const, Finset.card_univ, Nat.cast_smul_eq_nsmul] + rw [codeProjector, Matrix.smul_mulVec, hQ, smul_smul, + inv_mul_cancel₀ (card_stabilizer_ne_zero S), one_smul] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerErrorCorrection.lean b/LeanPool/AxQM/Concrete/StabilizerErrorCorrection.lean new file mode 100644 index 0000000000..b5a5567514 --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerErrorCorrection.lean @@ -0,0 +1,334 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.StabilizerCodeProjector +public import LeanPool.AxQM.Concrete.StabilizerCodeDimension +public import LeanPool.AxQM.ToMathlib.GroupTheory.Subgroup.Centralizer +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumErrorCorrection +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix + +/-! +# Concrete: error-correction conditions for stabilizer codes (Nielsen & Chuang, Theorem 10.8) + +This file completes the formalisation of Nielsen & Chuang **Theorem 10.8** (the *error-correction +conditions for stabilizer codes*, p. 466) begun in `AxQM/Concrete/StabilizerCodeProjector.lean`. +Everything here is stated for the abstract Pauli group `PauliGroup n`, its subgroups, and raw +matrices / operators. + +## The theorem + +Stabilizer QEC conditions: {Ej} with Ej-dag Ek not in N(S)-S for all j,k is a correctable error set +for C(S). + +N&C's proof shows the projector `P` onto `C(S)` and the errors satisfy the **Knill–Laflamme / +quantum error-correction conditions** of Theorem 10.1 (eq. (10.16)): `P Eⱼ† Eₖ P = αⱼₖ P` for a +Hermitian matrix `α`; then, since `C(S)` is a code (`P ≠ 0`, which is exactly what the stabilizer +hypothesis `-I ∉ S` guarantees), Theorem 10.1's sufficiency direction produces a recovery operation +correcting `{Eⱼ}`. Both halves are proved here. + +Errors are modelled as elements `E : ι → PauliGroup n` of the Pauli group `Gₙ` (N&C: "operators in +`Gₙ`"). For group elements the adjoint is the inverse (`PauliGroup.toMat_inv`: +`(toMat p)ᴴ = toMat p⁻¹`), so `Eⱼ† Eₖ` is the operator of the single group element `Eⱼ⁻¹ Eₖ`, and +the hypothesis `Eⱼ† Eₖ ∉ N(S) − S` reads `¬ (Eⱼ⁻¹ Eₖ ∈ N(S) ∧ Eⱼ⁻¹ Eₖ ∉ S)` (i.e. +`Eⱼ⁻¹ Eₖ ∉ N(S) \ S`) with `N(S)` the group-theoretic normalizer `Subgroup.normalizer S`. + +## What is proved + +* `codeProjector_conj_toMat_eq_self` / `codeProjector_conj_toMat_eq_zero` — the two cases of N&C's + proof: `p ∈ S ⟹ P (toMat p) P = P` (absorption + idempotence) and, when `p` anticommutes with + some `g ∈ S`, `P (toMat p) P = 0` (`P = P·toMat g`, `toMat p · toMat g = -(toMat g · toMat p)`, + `toMat g · P = P` force `P (toMat p) P = -(P (toMat p) P)`, hence `0`). +* `codeProjector_conj_toMat` — the two cases assembled: for `p ∉ N(S) \ S`, + `P (toMat p) P = 1_S(p) • P` (`1_S` the indicator of `S`), using the operator commute/anticommute + dichotomy (`PauliGroup.toMat_anticomm_of_ne_mul_comm`) and `Subgroup.centralizer_le_normalizer`. +* `stabilizerKLCoeff` / `stabilizerKLCoeff_isHermitian` — the Hermitian coefficient matrix + `αⱼₖ = 1_S(Eⱼ⁻¹ Eₖ)` (`S` closed under inverse; `(Eⱼ⁻¹ Eₖ)⁻¹ = Eₖ⁻¹ Eⱼ`). +* `codeProjector_satisfiesKL` — the Knill–Laflamme conditions `P Eⱼ† Eₖ P = αⱼₖ P` (N&C eq. (10.16)) + at the matrix level, holding for **any** finite stabilizer subgroup (no `-I ∉ S` needed). +* `codeProjector_satisfiesKLConditions` — the same, transported through the `*`-algebra isomorphism + `Matrix.toEuclideanCLM` into the exact predicate `ContinuousLinearMap.SatisfiesKLConditions` of + Theorem 10.1. +* `codeProjector_ne_zero` — for a genuine stabilizer (`-I ∉ S`) the code projector is nonzero + (`tr P = |S|⁻¹ · 2ⁿ ≠ 0`, as the only stabilizer element with a nonzero-trace operator is `I`). +* `codeProjector_isCorrectableErrorSet` — **Theorem 10.8**: for `-I ∉ S` and `Eⱼ⁻¹ Eₖ ∉ N(S) \ S`, + a trace-preserving recovery `R` (`∑ₒ Rₒ† Rₒ = 1`) corrects `{Eⱼ}`, obtained by feeding the five + hypotheses (`IsSelfAdjoint P`, `P² = P`, `P ≠ 0`, Hermitian `α`, KL conditions) into + `ContinuousLinearMap.corrects_of_satisfiesKLConditions`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### The two cases of Theorem 10.8's proof -/ + +/-- **Case `p ∈ S`.** `P (toMat p) P = P`: `toMat p` is absorbed by `P` (`toMat_mul_codeProjector`) +and `P` is idempotent (`codeProjector_mul_self`). N&C's `P Eⱼ† Eₖ P = P` when `Eⱼ† Eₖ ∈ S`. -/ +theorem codeProjector_conj_toMat_eq_self {S : Subgroup (PauliGroup n)} [Fintype S] + {p : PauliGroup n} (hp : p ∈ S) : + codeProjector S * p.toMat * codeProjector S = codeProjector S := by + rw [mul_assoc, toMat_mul_codeProjector hp, codeProjector_mul_self] + +/-- **Case `p` anticommutes with some `g ∈ S`.** `P (toMat p) P = 0`. Writing `a = toMat p`, +`b = toMat g`, the two-sided absorption `b · P = P = P · b` and the anticommutation `a · b = +-(b · a)` give `P · a · P = P · a · (b · P) = P · (a · b) · P = -(P · b · a · P) = -(P · a · P)`, so +`2 (P a P) = 0` and `P a P = 0`. This is N&C's `P Eⱼ† Eₖ P = 0` when `Eⱼ† Eₖ ∈ Gₙ − N(S)` +(anticommuting with a generator `g₁ ∈ S`). -/ +theorem codeProjector_conj_toMat_eq_zero {S : Subgroup (PauliGroup n)} [Fintype S] + {p g : PauliGroup n} (hg : g ∈ S) + (hanti : p.toMat * g.toMat = -(g.toMat * p.toMat)) : + codeProjector S * p.toMat * codeProjector S = 0 := by + have h1 : g.toMat * codeProjector S = codeProjector S := toMat_mul_codeProjector hg + have h2 : codeProjector S * g.toMat = codeProjector S := codeProjector_mul_toMat hg + set P := codeProjector S + set a := p.toMat + set b := g.toMat + have key : P * a * P = -(P * a * P) := + calc P * a * P + = P * a * (b * P) := by rw [h1] + _ = P * (a * b) * P := by noncomm_ring + _ = P * (-(b * a)) * P := by rw [hanti] + _ = -(P * b * a * P) := by noncomm_ring + _ = -(P * a * P) := by rw [h2] + have hsum : P * a * P + P * a * P = 0 := by + nth_rewrite 2 [key]; exact add_neg_cancel _ + have h2x : (2 : ℂ) • (P * a * P) = 0 := by rw [two_smul]; exact hsum + exact (smul_eq_zero.mp h2x).resolve_left two_ne_zero + +/-! ### Theorem 10.8: the code projector satisfies the Knill–Laflamme conditions -/ + +/-- **Single-element form of Theorem 10.8.** For a Pauli-group element `p ∉ N(S) \ S` (written +`¬ (p ∈ N(S) ∧ p ∉ S)`), `P (toMat p) P = 1_S(p) • P` where `1_S` is the indicator of `S`. The +hypothesis splits into `p ∈ S` (`codeProjector_conj_toMat_eq_self`) and `p ∉ N(S)`, where — `p` +failing to commute with some `g ∈ S` (the contrapositive of `Subgroup.centralizer_le_normalizer`) +and the resulting operator anticommutation (`PauliGroup.toMat_anticomm_of_ne_mul_comm`) — +`codeProjector_conj_toMat_eq_zero` applies. -/ +theorem codeProjector_conj_toMat {S : Subgroup (PauliGroup n)} [Fintype S] {p : PauliGroup n} + (hp : ¬ (p ∈ Subgroup.normalizer S ∧ p ∉ S)) : + codeProjector S * p.toMat * codeProjector S + = Set.indicator (↑S) (fun _ => (1 : ℂ)) p • codeProjector S := by + by_cases hmem : p ∈ S + · rw [Set.indicator_of_mem (SetLike.mem_coe.2 hmem), one_smul] + exact codeProjector_conj_toMat_eq_self hmem + · rw [Set.indicator_of_notMem (by simpa using hmem), zero_smul] + have hnotnorm : p ∉ Subgroup.normalizer S := fun hn => hp ⟨hn, hmem⟩ + -- `p ∉ N(S)` gives a `g ∈ S` failing to commute with `p`, hence anticommuting operators. + obtain ⟨g, hg, hne⟩ : ∃ g ∈ S, p * g ≠ g * p := by + by_contra hcon + refine hnotnorm (Subgroup.centralizer_le_normalizer (S : Set (PauliGroup n)) ?_) + rw [Subgroup.mem_centralizer_iff] + intro g hg + by_contra hne + exact hcon ⟨g, hg, fun h => hne h.symm⟩ + exact codeProjector_conj_toMat_eq_zero hg (PauliGroup.toMat_anticomm_of_ne_mul_comm p g hne) + +/-- The **Knill–Laflamme coefficient matrix** of a stabilizer code for an error family +`E : ι → Gₙ`: `αⱼₖ = 1_S(Eⱼ⁻¹ Eₖ)` — the indicator of `S`, i.e. `1` if `Eⱼ⁻¹ Eₖ ∈ S` and `0` +otherwise. This is N&C's `α` in eq. (10.16): `1` on the errors that differ by a stabilizer, `0` on +those that anticommute with `S`. -/ +noncomputable def stabilizerKLCoeff {ι : Type*} (S : Subgroup (PauliGroup n)) + (E : ι → PauliGroup n) : Matrix ι ι ℂ := + fun j k => Set.indicator (↑S) (fun _ => (1 : ℂ)) ((E j)⁻¹ * E k) + +/-- **The Knill–Laflamme coefficient matrix is Hermitian** (N&C requires `α` Hermitian). Its entries +are real (`0`/`1`), and `Eₖ⁻¹ Eⱼ = (Eⱼ⁻¹ Eₖ)⁻¹` lies in `S` exactly when `Eⱼ⁻¹ Eₖ` does (`S` is +closed under inverse), so `αₖⱼ = αⱼₖ`. -/ +theorem stabilizerKLCoeff_isHermitian {ι : Type*} (S : Subgroup (PauliGroup n)) + (E : ι → PauliGroup n) : (stabilizerKLCoeff S E).IsHermitian := by + ext j k + rw [Matrix.conjTranspose_apply] + simp only [stabilizerKLCoeff] + have hiff : (E k)⁻¹ * E j ∈ S ↔ (E j)⁻¹ * E k ∈ S := by + rw [← Subgroup.inv_mem_iff (x := (E j)⁻¹ * E k), _root_.mul_inv_rev, inv_inv] + by_cases h : (E k)⁻¹ * E j ∈ S + · rw [Set.indicator_of_mem (SetLike.mem_coe.2 h), + Set.indicator_of_mem (SetLike.mem_coe.2 (hiff.mp h)), star_one] + · rw [Set.indicator_of_notMem (by simpa using h), + Set.indicator_of_notMem (by simpa using (fun hc => h (hiff.mpr hc))), star_zero] + +/-- The **Knill–Laflamme conditions** for a stabilizer code (Nielsen & Chuang, Theorem 10.8, eq. +(10.16)). For Pauli errors `E : ι → Gₙ` with `Eⱼ⁻¹ Eₖ ∉ N(S) \ S` — N&C's `Eⱼ† Eₖ ∉ N(S) − S`, +since `(toMat Eⱼ)ᴴ = toMat Eⱼ⁻¹` (`PauliGroup.toMat_inv`) — the code projector `P = codeProjector S` +satisfies `P (toMat Eⱼ)ᴴ (toMat Eₖ) P = αⱼₖ • P` with the Hermitian `α = stabilizerKLCoeff S E` +(`stabilizerKLCoeff_isHermitian`). This is the QEC-conditions half of Theorem 10.8; it holds for any +finite stabilizer subgroup (no `-I ∉ S` needed). Each entry is `codeProjector_conj_toMat` applied to +`Eⱼ⁻¹ Eₖ` (using `(toMat Eⱼ)ᴴ · toMat Eₖ = toMat (Eⱼ⁻¹ Eₖ)`). -/ +theorem codeProjector_satisfiesKL {ι : Type*} {S : Subgroup (PauliGroup n)} [Fintype S] + (E : ι → PauliGroup n) + (hE : ∀ j k, ¬ ((E j)⁻¹ * E k ∈ Subgroup.normalizer S ∧ (E j)⁻¹ * E k ∉ S)) (j k : ι) : + codeProjector S * ((E j).toMat)ᴴ * (E k).toMat * codeProjector S + = stabilizerKLCoeff S E j k • codeProjector S := by + have hprod : ((E j).toMat)ᴴ * (E k).toMat = ((E j)⁻¹ * E k).toMat := by + rw [PauliGroup.toMat_mul, PauliGroup.toMat_inv] + rw [mul_assoc (codeProjector S) (((E j).toMat)ᴴ) ((E k).toMat), hprod, + codeProjector_conj_toMat (hE j k)] + rfl + +/-- The Knill–Laflamme conditions of `codeProjector_satisfiesKL`, transported through the +`*`-algebra isomorphism `Matrix.toEuclideanCLM` +(`Matrix n n ℂ ≃⋆ₐ[ℂ] (EuclideanSpace ℂ n →L[ℂ] EuclideanSpace ℂ n)`, intertwining `·ᴴ`↦`adjoint`, +`*`↦`comp`), into the exact predicate `ContinuousLinearMap.SatisfiesKLConditions` of Theorem 10.1: +the code projector `P` and the errors `E` — as continuous linear maps on the qubit Hilbert space — +satisfy `SatisfiesKLConditions` with the Hermitian coefficient matrix `stabilizerKLCoeff S E`. This +supplies two of the five hypotheses `corrects_of_satisfiesKLConditions` needs (the fifth, `P ≠ 0`, +requires `-I ∉ S`); `codeProjector_isCorrectableErrorSet` assembles them into correctability. -/ +theorem codeProjector_satisfiesKLConditions {ι : Type*} {S : Subgroup (PauliGroup n)} [Fintype S] + (E : ι → PauliGroup n) + (hE : ∀ j k, ¬ ((E j)⁻¹ * E k ∈ Subgroup.normalizer S ∧ (E j)⁻¹ * E k ∉ S)) : + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S)).SatisfiesKLConditions + (fun i => Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (E i).toMat) + (stabilizerKLCoeff S E) := by + intro i j + have hadj := (Matrix.toEuclideanCLM_conjTranspose_eq_adjoint (𝕜 := ℂ) (n := Fin n → Fin 2) + (E i).toMat).symm + rw [hadj] + simp only [← ContinuousLinearMap.mul_def, ← map_mul, ← map_smul] + congr 1 + rw [← codeProjector_satisfiesKL E hE i j] + noncomm_ring + +/-! ### The code projector is nonzero, and `{Eⱼ}` is correctable -/ + +/-- **The code projector of a genuine stabilizer is nonzero.** For `S` with `-I ∉ S`, +`tr P = |S|⁻¹ · 2ⁿ ≠ 0`: expanding `tr(∑_{s∈S} toMat s)`, a summand `tr(iˢ P_a) = iˢ · [a = 0] · 2ⁿ` +is nonzero only when the string index is `0`, and the only such element of `S` is the identity `I` +(`eq_one_of_checkRowHom_eq_zero_of_negOne_notMem`, using `-I ∉ S`), contributing `tr I = 2ⁿ`; hence +`P ≠ 0`. (For `-I ∈ S` the group average is `0` — `C(S)` is trivial — so `-I ∉ S` is essential.) -/ +theorem codeProjector_ne_zero {S : Subgroup (PauliGroup n)} [Fintype S] + (hS : PauliGroup.negOne n ∉ S) : + codeProjector S ≠ 0 := by + have hsum : (stabilizerSum S).trace = (2 : ℂ) ^ n := by + rw [stabilizerSum_eq, Matrix.trace_sum, + Finset.sum_eq_single_of_mem (1 : S) (Finset.mem_univ _)] + · rw [OneMemClass.coe_one, PauliGroup.toMat_one, + show (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) = pauliString 0 from + pauliString_const_zero.symm, pauliString_trace, ite_eq_left rfl] + · intro t _ hne + rw [PauliGroup.toMat, Matrix.trace_smul, pauliString_trace, smul_eq_mul, ite_eq_right, + mul_zero] + intro h0 + exact hne (Subtype.ext ((PauliGroup.eq_one_of_checkRowHom_eq_zero_of_negOne_notMem hS t.2 + ((PauliGroup.checkRowHom_eq_zero_iff _).mpr h0)).trans (OneMemClass.coe_one S).symm)) + intro hP + have hQ : stabilizerSum S = 0 := + (smul_eq_zero.mp hP).resolve_left (inv_ne_zero (card_stabilizer_ne_zero S)) + rw [hQ, Matrix.trace_zero] at hsum + exact pow_ne_zero n two_ne_zero hsum.symm + +/-- **A nonzero common `+1`-eigenvector forces `-I ∉ ⟨g⟩`** (the genuine-stabilizer criterion). For +a phase-free generator family `g : Fin m → 𝔽₄ⁿ`, if the simultaneous `+1`-eigenspace +`stabilizedSubspace g` (the code space `V_S`) is nonzero, then `-I` is not in the group +`S = ⟨(0, gᵢ)⟩` generated by the corresponding phase-`+1` Pauli-group elements. `-I` is a commutator +of `Gₙ`, so it survives no abelian quotient — the argument goes through the faithful representation: +pick `v ≠ 0` fixed by every `toMat (gᵢ) = pauliString (gᵢ)`; the set `H = {p | toMat p ·ᵥ v = v}` is +a subgroup containing every generator, hence `S ≤ H`, while `toMat (-I) ·ᵥ v = -v ≠ v`. The +companion of `codeProjector_ne_zero` (`-I ∉ S ⟹ P ≠ 0`) in the reverse direction, and the reusable +engine +behind the `-I ∉ S` obligation of Theorem 10.8 for a concrete code whose code space is known nonzero +(e.g. via Proposition 10.5, `stabilizedSubspace_finrank`). -/ +theorem negOne_notMem_closure_of_ne_bot {n m : ℕ} {g : Fin m → (Fin n → Fin 4)} + (hbot : stabilizedSubspace g ≠ ⊥) : + PauliGroup.negOne n ∉ Subgroup.closure (Set.range (fun i => (⟨0, g i⟩ : PauliGroup n))) := by + obtain ⟨v, hvmem, hvne⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hbot + have hvfix : ∀ i, (pauliString (g i)).mulVec v = v := mem_stabilizedSubspace.mp hvmem + -- `H = {p | toMat p ·ᵥ v = v}` is a subgroup of `Gₙ`. + let H : Subgroup (PauliGroup n) := + { carrier := {p | p.toMat.mulVec v = v} + one_mem' := by simp only [Set.mem_ofPred_eq, PauliGroup.toMat_one, Matrix.one_mulVec] + mul_mem' := fun {a b} ha hb => by + simp only [Set.mem_ofPred_eq] at ha hb ⊢ + rw [PauliGroup.toMat_mul, ← Matrix.mulVec_mulVec, hb, ha] + inv_mem' := fun {a} ha => by + simp only [Set.mem_ofPred_eq] at ha ⊢ + conv_lhs => rw [← ha] + rw [Matrix.mulVec_mulVec, ← PauliGroup.toMat_mul, inv_mul_cancel, + PauliGroup.toMat_one, Matrix.one_mulVec] } + -- every generator fixes `v`, hence `⟨(0, gᵢ)⟩ = closure (range …) ≤ H`. + have hsub : Subgroup.closure (Set.range (fun i => (⟨0, g i⟩ : PauliGroup n))) ≤ H := by + refine (Subgroup.closure_le H).mpr ?_ + rintro _ ⟨i, rfl⟩ + change ((⟨0, g i⟩ : PauliGroup n)).toMat.mulVec v = v + have hg : ((⟨0, g i⟩ : PauliGroup n)).toMat = pauliString (g i) := by + simp only [PauliGroup.toMat, zmod4Pow_zero, one_smul] + rw [hg]; exact hvfix i + -- if `-I` were in the group it would fix `v`, but `toMat (-I) ·ᵥ v = -v`, forcing `v = 0`. + intro hmem + have hfix : (PauliGroup.negOne n).toMat.mulVec v = v := hsub hmem + have hneg : (PauliGroup.negOne n).toMat.mulVec v = -v := by + have hz : pauliString (0 : Fin n → Fin 4) = 1 := pauliString_const_zero + have h1 : (PauliGroup.negOne n).toMat + = (-1 : ℂ) • (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) := by + simp only [PauliGroup.toMat, PauliGroup.negOne, zmod4Pow_two, hz] + rw [h1, Matrix.smul_mulVec, Matrix.one_mulVec, neg_one_smul] + rw [hneg] at hfix + exact hvne (neg_eq_self.mp hfix) + +/-- **The code projector, as a Euclidean continuous linear map, is self-adjoint.** `toEuclideanCLM` +is a `*`-algebra isomorphism intertwining `·ᴴ` with `adjoint`, and `codeProjector S` is Hermitian +(`codeProjector_isHermitian`). One of the three standing hypotheses of Theorem 10.1 that both +stabilizer correctability theorems (`codeProjector_isCorrectableErrorSet` and the below-distance +variant `codeProjector_isCorrectableErrorSet_of_weight_lt`) feed to +`corrects_of_satisfiesKLConditions`. -/ +theorem isSelfAdjoint_toEuclideanCLM_codeProjector {S : Subgroup (PauliGroup n)} [Fintype S] : + IsSelfAdjoint (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S)) := by + rw [isSelfAdjoint_iff, ← map_star] + congr 1 + rw [Matrix.star_eq_conjTranspose] + exact codeProjector_isHermitian + +/-- **The code projector, as a Euclidean continuous linear map, is idempotent.** `toEuclideanCLM` is +multiplicative and `codeProjector S` is idempotent (`codeProjector_mul_self`). The projector +hypothesis `P² = P` of Theorem 10.1 shared by both stabilizer correctability theorems. -/ +theorem toEuclideanCLM_codeProjector_comp_self {S : Subgroup (PauliGroup n)} [Fintype S] : + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S)).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S)) + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S) := by + rw [← ContinuousLinearMap.mul_def, ← map_mul, codeProjector_mul_self] + +/-- **The code projector, as a Euclidean continuous linear map, is nonzero** for a genuine +stabilizer (`-I ∉ S`): `toEuclideanCLM` is injective and `codeProjector S ≠ 0` +(`codeProjector_ne_zero`, where +`-I ∉ S` enters). The `P ≠ 0` hypothesis of Theorem 10.1 shared by both stabilizer correctability +theorems. -/ +theorem toEuclideanCLM_codeProjector_ne_zero {S : Subgroup (PauliGroup n)} [Fintype S] + (hS : PauliGroup.negOne n ∉ S) : + Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S) ≠ 0 := fun h => + codeProjector_ne_zero hS ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2)).injective + (by rw [map_zero]; exact h)) + +/-- **Nielsen & Chuang, Theorem 10.8** (error-correction conditions for stabilizer codes). Let `S` +be a stabilizer (`-I ∉ S`) and `P = codeProjector S` the projector onto its code space `C(S)`. If a +family of Pauli errors `E : ι → Gₙ` satisfies `Eⱼ⁻¹ Eₖ ∉ N(S) \ S` for all `j, k` (N&C's +`Eⱼ† Eₖ ∉ N(S) − S`), then `{Eⱼ}` is a **correctable set of errors** for `C(S)`: there is a +trace-preserving recovery operation `R` (`∑ₒ Rₒ† Rₒ = 1`) that corrects `{Eⱼ}`. This is exactly the +sufficiency half of Theorem 10.1 (`ContinuousLinearMap.corrects_of_satisfiesKLConditions`), fed the +five hypotheses: `P` (as a CLM) is self-adjoint (`isSelfAdjoint_toEuclideanCLM_codeProjector`), +idempotent (`toEuclideanCLM_codeProjector_comp_self`), nonzero +(`toEuclideanCLM_codeProjector_ne_zero`, where `-I ∉ S` enters), the coefficient matrix is Hermitian +(`stabilizerKLCoeff_isHermitian`), and the KL conditions hold +(`codeProjector_satisfiesKLConditions`). -/ +theorem codeProjector_isCorrectableErrorSet {ι : Type} [Fintype ι] + {S : Subgroup (PauliGroup n)} [Fintype S] (hS : PauliGroup.negOne n ∉ S) (E : ι → PauliGroup n) + (hE : ∀ j k, ¬ ((E j)⁻¹ * E k ∈ Subgroup.normalizer S ∧ (E j)⁻¹ * E k ∉ S)) : + ∃ (κ : Type) (_ : Fintype κ) + (R : κ → EuclideanSpace ℂ (Fin n → Fin 2) →L[ℂ] EuclideanSpace ℂ (Fin n → Fin 2)), + (∑ o, (ContinuousLinearMap.adjoint (R o)).comp (R o) = 1) ∧ + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (codeProjector S)).Corrects + (fun i => Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin n → Fin 2) (E i).toMat) R := + ContinuousLinearMap.corrects_of_satisfiesKLConditions + isSelfAdjoint_toEuclideanCLM_codeProjector toEuclideanCLM_codeProjector_comp_self + (toEuclideanCLM_codeProjector_ne_zero hS) + (stabilizerKLCoeff_isHermitian S E) (codeProjector_satisfiesKLConditions E hE) + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerGeneratorFlip.lean b/LeanPool/AxQM/Concrete/StabilizerGeneratorFlip.lean new file mode 100644 index 0000000000..3a670618c2 --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerGeneratorFlip.lean @@ -0,0 +1,248 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.CheckMatrix +public import Mathlib.Algebra.Field.ZMod +public import Mathlib.LinearAlgebra.BilinearForm.Properties +public import Mathlib.LinearAlgebra.Matrix.BilinearForm +public import Mathlib.LinearAlgebra.Basis.VectorSpace + +/-! +# Concrete: Nielsen & Chuang Proposition 10.4 — flipping a single stabilizer generator + +This file formalizes Nielsen & Chuang's +**Proposition 10.4** (§10.5.1, p. 458), the "innocuous looking" but repeatedly-used fact behind +the dimension count for stabilizer code spaces (Proposition 10.5) and the manipulation of +stabilizers under Clifford gates. + +Proposition 10.4: for independent generators with −I ∉ S there is a Pauli conjugating one generator +to its negative and fixing the others. + +## Statement shape and faithfulness + +We work throughout with the **phase-free** Pauli strings `Concrete.pauliString g` (indexed by +`g : Fin n → Fin 4`), which carry no `±1, ±i` prefactor. Two design points make this faithful to +N&C: + +* **`-I ∉ S` enters only through `gⱼ² = I`.** N&C's hypothesis `-I ∉ S` forces every element of `S` + — in particular every generator — to square to the identity and hence to be a *Hermitian + involution* (Exercises 10.34/10.35). That per-generator involution property is all the proof of + 10.4 actually uses, and every `pauliString g` is already an involution (`pauliString_mul_self`) + and Hermitian (`pauliString_isHermitian`) unconditionally. So the phase-free representation + supplies exactly the consequence of `-I ∉ S` the argument needs — with no `-I ∉ S` hypothesis to + carry. (It does *not* claim the phase-free strings generate a group avoiding `-I`; e.g. + `(P_X P_Z)² = -I`. The proof never needs that group-level fact.) +* **"independent generators" ⇔ "check-matrix rows linearly independent".** This is exactly the + content of Proposition 10.3 (in the `-I ∉ S` world). N&C's proof of 10.4 opens by invoking 10.3 + to pass to linear independence of the rows, and the whole argument then uses only that. We + therefore state the hypothesis directly as `LinearIndependent (ZMod 2) (fun j ↦ checkRow (gⱼ))` + — the equivalent (not weaker) form the proof consumes. The check row `checkRow` + (`Concrete/CheckMatrix.lean`) is the `(x | z)` symplectic representation. + +The conjugation `g gⱼ g†` is `pauliString p * pauliString (gⱼ) * star (pauliString p)`, with +`star` the Hermitian adjoint (`†`); a phase-free Pauli string is Hermitian, so `star (pauliString +p) = pauliString p`, but writing the adjoint keeps the statement literally N&C's `g gⱼ g†`. + +## The proof + +Conjugation by a Pauli string reads off the commutation sign (`pauliString_conj`): +`P_p P_h P_p† = (-1)^{⟨p, h⟩} P_h`, where `⟨p, h⟩ = pauliAnticommCount p h` is the symplectic form +of Exercise 10.33. So the task is to find `p` whose symplectic form with `gⱼ` has parity `δᵢⱼ`. + +This is the linear-algebra heart of N&C's proof ("`GΛx = eᵢ` has a solution because the rows of +`G` are independent"). We realize it over the field `ZMod 2`: + +* `checkSymplectic` is the binary symplectic form `⟨(x, z), (x', z')⟩ = ∑ₖ (xₖ z'ₖ + zₖ x'ₖ)` on + check rows; `checkSymplectic_checkRow` identifies it with `(pauliAnticommCount g h : ZMod 2)`. +* `checkSymplectic_nondegenerate`: the form is nondegenerate. +* Since the rows `checkRow (gⱼ)` are linearly independent, `checkRow (gᵢ)` is not in the span of the + others (`LinearIndependent.notMem_span`), so there is a *separating functional* `f` + (`Submodule.exists_le_ker_of_notMem`) with `f (checkRow gᵢ) ≠ 0` and `f` vanishing on the others. + Over `ZMod 2` "nonzero" means "`= 1`", so `f (checkRow gⱼ) = δᵢⱼ`. +* Nondegeneracy makes `checkSymplectic` a linear equivalence to the dual + (`LinearMap.BilinForm.toDual`), so `f = checkSymplectic w` for some `w`; and `checkRow` is onto + (`checkRow_surjective`), so `w = checkRow p` for a Pauli index `p`. Then + `(pauliAnticommCount p gⱼ : ZMod 2) = f (checkRow gⱼ) = δᵢⱼ`, i.e. the count is odd exactly for + `j = i`, giving `P_p P_{gᵢ} P_p† = -P_{gᵢ}` and `P_p P_{gⱼ} P_p† = P_{gⱼ}` for `j ≠ i`. + +The reusable pieces (`pauliString_conj`, `checkSymplectic` and its nondegeneracy, +`checkRow_surjective`) are used throughout the Chapter 10 stabilizer development +(Proposition 10.5, Theorems 10.6–10.8). + +These are the statements of N&C Proposition 10.4 (p. 458). +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-! ### Conjugation of a Pauli string by another -/ + +/-- **Conjugation of a Pauli string reads off the commutation sign.** Conjugating `P_h` by another +Pauli string `P_p` (with its Hermitian adjoint `P_p† = star (pauliString p)`, which equals `P_p`) +multiplies it by the symplectic-form sign: +`P_p P_h P_p† = (-1)^{pauliAnticommCount p h} • P_h`. Immediate from the commutation sign law +`pauliString_mul_comm_sign` (`P_p P_h = (-1)^{…} P_h P_p`) and the involution `pauliString_mul_self` +(`P_p P_p = I`), after replacing the adjoint by `P_p` (`pauliString_isHermitian`). -/ +theorem pauliString_conj (p h : Fin n → Fin 4) : + pauliString p * pauliString h * star (pauliString p) + = (-1 : ℂ) ^ pauliAnticommCount p h • pauliString h := by + rw [Matrix.star_eq_conjTranspose, (pauliString_isHermitian p).eq, + pauliString_mul_comm_sign p h, smul_mul_assoc, mul_assoc, pauliString_mul_self, mul_one] + +/-- Conjugation **fixes** a Pauli string that commutes with the conjugator (even symplectic form): +`P_p P_h P_p† = P_h` when `pauliAnticommCount p h` is even. The sign `(-1)^{even}` is `+1`. -/ +theorem pauliString_conj_of_even (p h : Fin n → Fin 4) + (hc : Even (pauliAnticommCount p h)) : + pauliString p * pauliString h * star (pauliString p) = pauliString h := by + rw [pauliString_conj, hc.neg_one_pow, one_smul] + +/-- Conjugation **flips** a Pauli string that anticommutes with the conjugator (odd symplectic +form): `P_p P_h P_p† = -P_h` when `pauliAnticommCount p h` is odd. The sign `(-1)^{odd}` is `-1`. -/ +theorem pauliString_conj_of_odd (p h : Fin n → Fin 4) + (hc : Odd (pauliAnticommCount p h)) : + pauliString p * pauliString h * star (pauliString p) = -pauliString h := by + rw [pauliString_conj, hc.neg_one_pow, neg_one_smul] + +/-! ### The binary symplectic form on check rows -/ + +/-- The **binary symplectic form** on check-matrix rows, `⟨(x, z), (x', z')⟩ = ∑ₖ (xₖ z'ₖ + zₖ +x'ₖ)` over `ZMod 2`. This is `r(g) Λ r(g')ᵀ` for `Λ = [[0, I], [I, 0]]`; it is the mod-2 quantity +of Nielsen & Chuang, Exercise 10.33, packaged as an honest `ZMod 2`-bilinear form so that its +nondegeneracy is available for the linear algebra of Proposition 10.4. -/ +def checkSymplectic : + LinearMap.BilinForm (ZMod 2) ((Fin n → ZMod 2) × (Fin n → ZMod 2)) := + LinearMap.mk₂ (ZMod 2) + (fun u v => ∑ k, (u.1 k * v.2 k + u.2 k * v.1 k)) + (fun u₁ u₂ v => by + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [Prod.fst_add, Prod.snd_add, Pi.add_apply]; ring) + (fun c u v => by + rw [Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [Prod.smul_fst, Prod.smul_snd, Pi.smul_apply, smul_eq_mul]; ring) + (fun u v₁ v₂ => by + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [Prod.fst_add, Prod.snd_add, Pi.add_apply]; ring) + (fun c u v => by + rw [Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [Prod.smul_fst, Prod.smul_snd, Pi.smul_apply, smul_eq_mul]; ring) + +@[simp] +theorem checkSymplectic_apply (u v : (Fin n → ZMod 2) × (Fin n → ZMod 2)) : + checkSymplectic u v = ∑ k, (u.1 k * v.2 k + u.2 k * v.1 k) := by + simp only [checkSymplectic, LinearMap.mk₂_apply] + +/-- The symplectic form on check rows **is** the mod-2 anticommutation count: +`checkSymplectic (r g) (r h) = (pauliAnticommCount g h : ZMod 2)`. Both sides are the sum over +qubits of `x_g z_h + z_g x_h`; the left computes it in `ZMod 2`, the right casts the `ℕ`-valued +`pauliAnticommCount` (a sum of `singlePauliAnticomm`s). -/ +theorem checkSymplectic_checkRow (g h : Fin n → Fin 4) : + checkSymplectic (checkRow g) (checkRow h) = (pauliAnticommCount g h : ZMod 2) := by + rw [checkSymplectic_apply, pauliAnticommCount, Nat.cast_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [checkRow, pauliBit, singlePauliAnticomm] + push_cast + ring + +/-- **The binary symplectic form is nondegenerate.** If `u`'s symplectic form with every vector +vanishes, then `u = 0`: testing against `(0, eₖ)` extracts `u.1 k` and against `(eₖ, 0)` extracts +`u.2 k`. Over the field `ZMod 2` on the finite free module `(Fin n → ZMod 2)²`, left-separating +already gives full nondegeneracy (`Nondegenerate.ofSeparatingLeft`). -/ +theorem checkSymplectic_nondegenerate : (checkSymplectic (n := n)).Nondegenerate := by + apply LinearMap.BilinForm.Nondegenerate.ofSeparatingLeft + intro u hu + have h1 : ∀ k, u.1 k = 0 := by + intro k + have hk := hu (0, Pi.single k 1) + simpa [checkSymplectic_apply, Pi.single_apply, Finset.sum_ite_eq'] using hk + have h2 : ∀ k, u.2 k = 0 := by + intro k + have hk := hu (Pi.single k 1, 0) + simpa [checkSymplectic_apply, Pi.single_apply, Finset.sum_ite_eq'] using hk + exact Prod.ext (funext h1) (funext h2) + +/-! ### Surjectivity of the check-row map -/ + +/-- The inverse of the single-qubit check-bit map `pauliBit`: the Pauli index with prescribed +`(x, z)` bits (`(0,0) ↦ I`, `(1,0) ↦ X`, `(1,1) ↦ Y`, `(0,1) ↦ Z`). Used to invert `checkRow` +qubitwise. -/ +def bitToPauli (b : ZMod 2 × ZMod 2) : Fin 4 := + if b.1 = 0 then (if b.2 = 0 then 0 else 3) else (if b.2 = 0 then 1 else 2) + +/-- `bitToPauli` is a right inverse of `pauliBit`: `pauliBit (bitToPauli b) = b`. A finite check on +the four `(x, z)` bit patterns. -/ +theorem pauliBit_bitToPauli : ∀ b : ZMod 2 × ZMod 2, pauliBit (bitToPauli b) = b := by decide + +/-- **The check-row map is surjective.** Every `(x, z) : (Fin n → ZMod 2) × (Fin n → ZMod 2)` is the +check row `r(p)` of some Pauli string `p`: take `p k` to be the Pauli with bits `(xₖ, zₖ)` +(`bitToPauli`). This lets us realize any solution vector of the symplectic system as an actual +element of the Pauli group. -/ +theorem checkRow_surjective : Function.Surjective (checkRow (n := n)) := by + intro v + exact ⟨fun k => bitToPauli (v.1 k, v.2 k), by simp only [checkRow, pauliBit_bitToPauli]⟩ + +/-! ### Proposition 10.4 -/ + +/-- **Nielsen & Chuang, Proposition 10.4.** For a family of `l` phase-free generators `g₁, …, g_l` +(`g : Fin l → (Fin n → Fin 4)`) whose check-matrix rows are `ZMod 2`-linearly independent +(equivalently, by Proposition 10.3, the generators are independent; `-I ∉ S` is automatic for +phase-free Pauli strings), and any fixed index `i`, there is a Pauli string `p ∈ Gₙ` whose +conjugation **flips** `gᵢ` (`P_p P_{gᵢ} P_p† = -P_{gᵢ}`) and **fixes** every other generator +(`P_p P_{gⱼ} P_p† = P_{gⱼ}` for `j ≠ i`). + +The witness `p` is built from a separating functional for the independent rows, realized as a +symplectic pairing via nondegeneracy and pulled back through `checkRow`; conjugation then flips or +fixes each `gⱼ` according to the parity of `pauliAnticommCount p (g j)`, which is `1` for `j = i` +and `0` otherwise. -/ +theorem exists_pauliString_conj_flip {l : ℕ} (g : Fin l → (Fin n → Fin 4)) + (hindep : LinearIndependent (ZMod 2) fun j => checkRow (g j)) (i : Fin l) : + ∃ p : Fin n → Fin 4, + pauliString p * pauliString (g i) * star (pauliString p) = -pauliString (g i) ∧ + ∀ j, j ≠ i → + pauliString p * pauliString (g j) * star (pauliString p) = pauliString (g j) := by + classical + -- A separating functional `f`: nonzero on row `i`, vanishing on the others. + obtain ⟨f, hfi, hker⟩ := Submodule.exists_le_ker_of_notMem (hindep.notMem_span i) + have hf_i : f (checkRow (g i)) = 1 := by + have h01 : ∀ x : ZMod 2, x ≠ 0 → x = 1 := by decide + exact h01 _ hfi + have hf_j : ∀ j, j ≠ i → f (checkRow (g j)) = 0 := by + intro j hj + have hmem : checkRow (g j) ∈ + Submodule.span (ZMod 2) ((fun j => checkRow (g j)) '' {i}ᶜ) := + Submodule.subset_span ⟨j, hj, rfl⟩ + exact LinearMap.mem_ker.mp (hker hmem) + -- Nondegeneracy realizes `f` as a symplectic pairing; `checkRow` is onto, so the pairing partner + -- is `checkRow p` for a Pauli string `p`. + obtain ⟨w, hw⟩ := (checkSymplectic.toDual checkSymplectic_nondegenerate).surjective f + obtain ⟨p, hp⟩ := checkRow_surjective w + have key : ∀ j, f (checkRow (g j)) = (pauliAnticommCount p (g j) : ZMod 2) := by + intro j + rw [← hw, LinearMap.BilinForm.toDual_def, ← hp, checkSymplectic_checkRow] + refine ⟨p, ?_, ?_⟩ + · apply pauliString_conj_of_odd + rw [← ZMod.natCast_ne_zero_iff_odd, ← key i, hf_i] + exact one_ne_zero + · intro j hj + apply pauliString_conj_of_even + rw [← ZMod.natCast_eq_zero_iff_even, ← key j] + exact hf_j j hj + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerSimulationCost.lean b/LeanPool/AxQM/Concrete/StabilizerSimulationCost.lean new file mode 100644 index 0000000000..1bdb65c955 --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerSimulationCost.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit + +/-! +# Concrete: the Gottesman–Knill efficiency bound — `O(n²m)` classical simulation cost + +The **efficiency bound** of the Gottesman–Knill theorem (Nielsen & Chuang **Theorem 10.7**, +§10.5.4, p. 464). + +Cost of classically simulating a stabilizer circuit. + +N&C's argument (p. 464) is a *counting* claim: the classical computer keeps track of the `n` +generators of the stabilizer, and each allowed operation — state preparation in the computational +basis, a Hadamard / phase / controlled-`NOT` gate, a Pauli gate, or a measurement of a Pauli-group +observable — is simulated by updating that generator description "using `O(n²)` steps"; a generator +is an `n`-qubit Pauli string, so touching all `n` of them is `O(n²)` work. Summed over the `m` +operations of a computation, the total cost is `O(n²m)`. + +This file formalises exactly that, following the library's established resource-bound idiom — a +**defined** `ℕ`-valued cost function together with a *uniform* polynomial ceiling (cf. +`Concrete.mcNotGateBound_isBigO_sq`, `Concrete.qftControlledRkCount`, and the sibling **Theorem +10.6** `Concrete.isPauliNormalizer_eq_smul_cliffordCircuit_bigO` with `List.length C ≤ K · n²`): + +* `StabilizerOp n` — the inductive **stabiliser-computation operation** type enumerating exactly + N&C's allowed elements: `prep`, `clifford g` (`H` / `S` / `CNOT`, reusing + `Concrete.CliffordGate`), `pauli p`, and `measure p` (measurement of the Pauli-group observable + `p`). +* `StabilizerComputation n := List (StabilizerOp n)` — a computation is the sequence of `m` + operations actually executed. +* `StabilizerOp.tableauCost` — the per-operation count of elementary tableau updates: `n · (n+1)` + for each of `prep` / `clifford` / `pauli` (update all `n` generators, each an `n`-cell Pauli + string plus a sign), and `2 · n · (n+1)` for `measure` (a commutation-scan pass over the `n` + generators followed by an update pass). Each is `≤ 4 · n²` (`StabilizerOp.tableauCost_le`). +* `StabilizerComputation.simCost` — the total classical simulation cost, `∑` of the per-operation + costs. +* `exists_simCost_le_mul_sq_length` — **the `O(n²m)` headline**: a *single universal constant* `K` + (here `4`) with `simCost prog ≤ K · n² · prog.length` for every `n` and every computation `prog`. + The constant is uniform in both `n` and `m = prog.length`, so this is the faithful reading of + N&C's `O(n²m)` (a per-`n` existential `K` would be vacuous). + +## Design notes (fidelity) + +* **Why a defined count, not an instrumented step trace.** As with `mcNotGateBound` / + `qftControlledRkCount`, `tableauCost` is a *documented* closed-form count of the standard + generator-tableau update for each operation, not a reduction-step counter of a Lean program. The + companion computable tableau simulator whose per-step work this count measures — and the + correctness of its tracked stabiliser against the actual quantum state — is treated separately + (by `Concrete.CliffordCircuit.updatedGenerator_mulVec_toMatrix_mulVec_of_mem` for the unitary + part and the §10.5.3 rules in `AxQM/Postulates/API/StabilizerMeasurement.lean` for measurement). + +* **Classical control.** A real stabiliser computation may condition later operations on measurement + outcomes; the `StabilizerComputation` list models the sequence of operations *actually executed* + in one run. Classical control only selects which operations run — it changes neither the operation + count `m` nor the `O(n²)` cost of simulating each, so the `O(n²m)` bound is control-independent. + +* **Uniform `O(n²)` per operation.** N&C bound *every* listed operation by `O(n²)` steps (dominated + by measurement). Assigning each operation a cost `≤ 4·n²` is exactly that claim; a cheaper local + gate is still `≤ 4·n²`, so the total ceiling is faithful and not a weakening. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +variable {n : ℕ} + +/-- An **operation of a stabiliser computation** on the `n`-qubit register: exactly the elements +Nielsen & Chuang **Theorem 10.7** allows. + +* `prep` — preparation of the computational-basis state (reset the tracked stabiliser to the trivial + `⟨Z₁, …, Zₙ⟩`); +* `clifford g` — a Hadamard, phase (`S`), or controlled-`NOT` gate (the elementary Clifford gates + `Concrete.CliffordGate n`); +* `pauli p` — a Pauli gate: the Pauli operator with Pauli string `p : Fin n → Fin 4` applied as a + unitary (its tableau action changes only generator signs); +* `measure p` — a measurement of the Pauli-group observable with Pauli string `p`. + +A computation is a finite sequence of these (`StabilizerComputation`), and the Gottesman–Knill +theorem asserts each is classically simulable in `O(n²)` steps. -/ +inductive StabilizerOp (n : ℕ) : Type where + /-- Prepare the computational-basis state (reset to the trivial stabiliser `⟨Z₁, …, Zₙ⟩`). -/ + | prep : StabilizerOp n + /-- Apply an elementary Clifford gate (Hadamard, phase, or controlled-`NOT`). -/ + | clifford (g : CliffordGate n) : StabilizerOp n + /-- Apply the Pauli gate with Pauli string `p`. -/ + | pauli (p : Fin n → Fin 4) : StabilizerOp n + /-- Measure the Pauli-group observable with Pauli string `p`. -/ + | measure (p : Fin n → Fin 4) : StabilizerOp n + +/-- A **stabiliser computation** on the `n`-qubit register: the finite sequence of `m` operations +(`StabilizerOp n`) actually executed. Its classical simulation cost is `O(n²m)` +(`exists_simCost_le_mul_sq_length`). -/ +abbrev StabilizerComputation (n : ℕ) : Type := List (StabilizerOp n) + +/-- The **classical cost of simulating one operation**: the number of elementary tableau-cell +updates the standard generator-tracking simulator performs. The stabiliser of an `n`-qubit state is +tracked as `n` generators, each an `n`-qubit Pauli string (`n` Pauli cells) with a `±1` sign, so a +full pass over the tableau costs `n · (n + 1)`. + +* `prep`, `clifford`, `pauli` — one pass updating all `n` generators: `n · (n + 1)`. +* `measure` — a commutation-scan pass (which generators anticommute with the measured observable) + followed by an update pass: `2 · n · (n + 1)`. + +Every value is `≤ 4 · n²` (`StabilizerOp.tableauCost_le`) — N&C's uniform "`O(n²)` steps per +operation". -/ +def StabilizerOp.tableauCost : StabilizerOp n → ℕ + | .prep => n * (n + 1) + | .clifford _ => n * (n + 1) + | .pauli _ => n * (n + 1) + | .measure _ => 2 * (n * (n + 1)) + +/-- **Each operation costs `O(n²)`.** Every `StabilizerOp.tableauCost` value is bounded by `4 · n²`, +uniformly in the operation — the faithful reading of N&C's "may all be done using `O(n²)` steps on a +classical computer". -/ +theorem StabilizerOp.tableauCost_le (op : StabilizerOp n) : op.tableauCost ≤ 4 * n ^ 2 := by + cases op <;> simp only [StabilizerOp.tableauCost] <;> nlinarith [Nat.le_self_pow two_ne_zero n] + +/-- The **total classical cost of simulating a stabiliser computation**: the sum of the +per-operation tableau-update costs `StabilizerOp.tableauCost`. This is `O(n²m)` for +`m = prog.length` (`exists_simCost_le_mul_sq_length`). + +(`StabilizerComputation` is a `List` abbreviation, so this is spelled `StabilizerComputation.simCost +prog` — dot notation `prog.simCost` would resolve into the `List` namespace.) -/ +def StabilizerComputation.simCost (prog : StabilizerComputation n) : ℕ := + (prog.map StabilizerOp.tableauCost).sum + +@[simp] theorem StabilizerComputation.simCost_nil : + StabilizerComputation.simCost ([] : StabilizerComputation n) = 0 := rfl + +@[simp] theorem StabilizerComputation.simCost_cons (op : StabilizerOp n) + (prog : StabilizerComputation n) : + StabilizerComputation.simCost (op :: prog) = + op.tableauCost + StabilizerComputation.simCost prog := by + simp [StabilizerComputation.simCost] + +/-- **The Gottesman–Knill efficiency theorem (N&C Theorem 10.7, the `O(n²m)` headline).** +There is a *universal* constant `K` (here `4`) such that every stabiliser computation `prog` of +`m = prog.length` operations on `n` qubits is classically simulated in at most `K · n² · m` +elementary tableau updates: +`∃ K, ∀ n (prog : StabilizerComputation n), simCost prog ≤ K · n² · prog.length`. + +The constant `K` is uniform in **both** `n` and `m`, so this is the faithful formalisation of N&C's +"`O(n²m)` operations on a classical computer" (a per-`n` existential `K` would be vacuous). It +follows from `StabilizerOp.tableauCost_le` (each of the `m` operations costs `≤ 4 · n²`) via +`List.sum_le_card_nsmul`. This mirrors the sibling Theorem 10.6 headline +`isPauliNormalizer_eq_smul_cliffordCircuit_bigO` (`List.length C ≤ K · n²`). -/ +theorem exists_simCost_le_mul_sq_length : + ∃ K, ∀ (n : ℕ) (prog : StabilizerComputation n), + StabilizerComputation.simCost prog ≤ K * n ^ 2 * prog.length := by + refine ⟨4, fun n prog => ?_⟩ + have hbound : (prog.map StabilizerOp.tableauCost).sum ≤ + (prog.map StabilizerOp.tableauCost).length • (4 * n ^ 2) := by + refine List.sum_le_length_nsmul _ _ ?_ + intro x hx + obtain ⟨op, _, rfl⟩ := List.mem_map.mp hx + exact op.tableauCost_le + calc StabilizerComputation.simCost prog = (prog.map StabilizerOp.tableauCost).sum := rfl + _ ≤ (prog.map StabilizerOp.tableauCost).length • (4 * n ^ 2) := hbound + _ = prog.length * (4 * n ^ 2) := by rw [List.length_map, smul_eq_mul] + _ = 4 * n ^ 2 * prog.length := by ring + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/StabilizerSimulator.lean b/LeanPool/AxQM/Concrete/StabilizerSimulator.lean new file mode 100644 index 0000000000..ae4ffa9efc --- /dev/null +++ b/LeanPool/AxQM/Concrete/StabilizerSimulator.lean @@ -0,0 +1,269 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.StabilizerSimulationCost +public import LeanPool.AxQM.Concrete.CliffordStabilizerTracking +public import LeanPool.AxQM.Concrete.StabilizerGeneratorFlip +public import LeanPool.AxQM.Concrete.PauliStringEncodingLayers +public import LeanPool.AxQM.Concrete.PauliNormalizerRestrict + +/-! +# Concrete: the stabiliser tableau simulator and its unitary-fragment correctness + +The **correctness of the classical stabiliser simulator** underlying the +Gottesman–Knill theorem (Nielsen & Chuang **Theorem 10.7**, §10.5.4, p. 464), for the *unitary +fragment* of a stabiliser computation. + +N&C's proof runs a classical simulation that "keep[s] track of the generators of the stabiliser": +the state of an `n`-qubit stabiliser computation is described by `n` generators, each an `n`-qubit +Pauli string with a `±1` sign, and every allowed operation updates that description in `O(n²)` steps +(the efficiency headline `Concrete.exists_simCost_le_mul_sq_length`, this file's sibling in +`Concrete/StabilizerSimulationCost.lean`). This file supplies the missing **correctness** half: the +tracked generators really do stabilise the actual quantum state. + +The classically-tracked description is a `StabilizerTableau` (the `n` signed generators). The +simulator's per-operation update (`StabilizerOp.stepTableau`) runs *in lockstep* with the actual +raw-state evolution (`StabilizerOp.stepState`), and the invariant `StabilizerTableau.Stabilizes` +("each signed generator fixes the state vector") is **preserved** by every unitary operation: + +* `zGenPauli_mulVec_compBasisZero` / `StabilizerTableau.prep_stabilizes` — **preparation**: the + computational-basis state `|0…0⟩` is stabilised by the trivial tableau `⟨Z₁, …, Zₙ⟩`. +* `CliffordGate.smul_pauliString_mulVec_stabilizes` — **Clifford gate** (`H` / `S` / `CNOT`): the + updated signed generator `(c · sign) • P_{act}` fixes the evolved vector `U ·ᵥ v` (Eq. (10.87), + via `conj_mulVec_toMatrix_mulVec` and `CliffordGate.conj`). +* `pauli_smul_pauliString_mulVec_stabilizes` — **Pauli gate**: conjugation by a Pauli string flips + only the sign (`pauliString_conj`), leaving the check row fixed; the sign-updated generator fixes + the evolved vector. +* `StabilizerOp.step_stabilizes` — the three assembled into one preservation step, and + `StabilizerTableau.run_stabilizes` — folded over a whole computation: for a **measurement-free** + computation `prog`, if the tableau `T` stabilises `v` then the run's tableau + `StabilizerTableau.run prog T` stabilises the evolved state `runState prog v`. + +## Why the correctness theorem is stated for the measurement-free fragment + +Measurement of a Pauli-group observable is the one allowed operation whose effect on the state is +**not** a matrix acting on a vector: it is a projective (Born-rule) collapse. Its stabiliser +update and state correctness are exactly the §10.5.3 measurement rules in +`AxQM/Postulates/API/StabilizerMeasurement.lean` (deterministic and random cases, generator +replacement). +Accordingly `StabilizerOp.stepState` / `StabilizerOp.stepTableau` carry the state and tableau +through a `measure` unchanged, and `StabilizerTableau.run_stabilizes` is stated with an explicit +measurement-free hypothesis — it is the **unitary-fragment** half of the correctness claim, which +together with the measurement rules gives Theorem 10.7. This is a component of the correctness +statement, not a weakening of it. +-/ + +@[expose] public section + +open scoped Matrix + +namespace AxQM.Concrete + +noncomputable section + +variable {n : ℕ} + +/-- The **all-zeros computational-basis vector** `|0…0⟩` on the `n`-qubit register, as a raw vector +`(Fin n → Fin 2) → ℂ`: the standard basis vector `Pi.single 0 1` supported at the all-zeros bit +string. This is the state prepared by `StabilizerOp.prep`. -/ +def compBasisZero (n : ℕ) : (Fin n → Fin 2) → ℂ := Pi.single 0 1 + +/-- **`Z_j` fixes `|0…0⟩`.** Every pure-`Z` generator `Zⱼ` stabilises the all-zeros +computational-basis vector: `pauliString (zGenPauli j) ·ᵥ |0…0⟩ = |0…0⟩`. On the all-zeros column a +`Z` factor is indistinguishable from `I` (both act as `+1` on `|0⟩`), so the column of +`pauliString (zGenPauli j)` at the all-zeros index is again the all-zeros indicator. This is the +preparation fact for the stabiliser simulator. -/ +theorem zGenPauli_mulVec_compBasisZero (j : Fin n) : + (pauliString (zGenPauli j)).mulVec (compBasisZero n) = compBasisZero n := by + rw [compBasisZero, Matrix.mulVec_single_one] + funext i + rw [Matrix.col_apply, pauliString_apply, Pi.single_apply] + simp only [Pi.zero_apply] + have hfac : ∀ k, pauli (zGenPauli j k) (i k) (0 : Fin 2) + = if i k = (0 : Fin 2) then (1 : ℂ) else 0 := by + intro k + simp only [zGenPauli, Function.update_apply, Pi.zero_apply] + rcases eq_or_ne k j with hk | hk + · rw [ite_eq_left hk, show pauli 3 = pauliZ from rfl, pauliZ_apply'] + rcases eq_or_ne (i k) (0 : Fin 2) with hik | hik <;> simp [hik] + · rw [ite_eq_right hk, show pauli 0 = (1 : Matrix (Fin 2) (Fin 2) ℂ) from rfl, + Matrix.one_apply] + rw [Finset.prod_congr rfl (fun k _ => hfac k), Finset.prod_boole] + simp only [Finset.mem_univ, forall_true_left] + by_cases hi : i = 0 + · subst hi; simp + · rw [ite_eq_right, ite_eq_right hi] + intro h + exact hi (funext h) + +/-! ### The stabiliser tableau -/ + +/-- A **stabiliser tableau** on the `n`-qubit register: the classical description the +Gottesman–Knill simulator tracks — `n` generators `gen i` (each a Pauli string `Fin n → Fin 4`), +together +with the `±1` sign `sign i` of each. It represents the signed generator family +`(sign i • pauliString (gen i))ᵢ`. -/ +structure StabilizerTableau (n : ℕ) where + /-- The `n` generators, each a phase-free Pauli string (a check-matrix row). -/ + gen : Fin n → Fin n → Fin 4 + /-- The `±1` sign carried by each generator. -/ + sign : Fin n → ℂ + +/-- The tableau **stabilises** the vector `v` when every signed generator fixes it: +`(sign i • pauliString (gen i)) ·ᵥ v = v` for all `i`. This is the simulator's correctness +invariant — "the tracked generators are a genuine stabiliser of the state". -/ +def StabilizerTableau.Stabilizes (T : StabilizerTableau n) (v : (Fin n → Fin 2) → ℂ) : Prop := + ∀ i, (T.sign i • pauliString (T.gen i)).mulVec v = v + +/-- The **trivial preparation tableau** `⟨Z₁, …, Zₙ⟩`: generator `i` is the pure-`Z` string `Zᵢ` +(`zGenPauli i`) with sign `+1`. This is the stabiliser of the computational-basis state `|0…0⟩` +produced by `StabilizerOp.prep`. -/ +def StabilizerTableau.prep (n : ℕ) : StabilizerTableau n where + gen := zGenPauli + sign := fun _ => 1 + +/-- **Preparation is correct.** The trivial tableau `⟨Z₁, …, Zₙ⟩` stabilises the all-zeros +computational-basis state `|0…0⟩`. Immediate from `zGenPauli_mulVec_compBasisZero`. -/ +theorem StabilizerTableau.prep_stabilizes : + (StabilizerTableau.prep n).Stabilizes (compBasisZero n) := by + intro i + simp only [StabilizerTableau.prep, one_smul] + exact zGenPauli_mulVec_compBasisZero i + +/-! ### Per-operation preservation of the stabiliser invariant -/ + +/-- **Clifford tracking, one signed generator.** If the signed Pauli string `c • P_a` fixes `v`, +then applying an elementary Clifford gate `g` updates the generator to +`(c · g.sign a) • P_{g.act a}` — its check row `g.act a` and sign `c · g.sign a` — which fixes the +evolved vector `g.toMatrix ·ᵥ v`. +This is Eq. (10.87) at the level of one signed generator: `conj_mulVec_toMatrix_mulVec` (unitarity +`g.toMatrix · g.toMatrixᴴ = 1`) applied to the conjugation identity `CliffordGate.conj`. -/ +theorem CliffordGate.smul_pauliString_mulVec_stabilizes (g : CliffordGate n) (c : ℂ) + (a : Fin n → Fin 4) {v : (Fin n → Fin 2) → ℂ} + (hv : (c • pauliString a).mulVec v = v) : + ((c * g.sign a) • pauliString (g.act a)).mulVec (g.toMatrix.mulVec v) + = g.toMatrix.mulVec v := by + have hconj : g.toMatrix * (c • pauliString a) * g.toMatrixᴴ + = (c * g.sign a) • pauliString (g.act a) := by + rw [mul_smul_comm, smul_mul_assoc, g.conj, smul_smul] + rw [← hconj] + exact conj_mulVec_toMatrix_mulVec g.mul_conjTranspose hv + +/-- **Pauli tracking, one signed generator.** If the signed Pauli string `c • P_a` fixes `v`, then +applying the Pauli gate `P_p` flips only the sign — conjugation by a Pauli string leaves the check +row fixed and multiplies by the commutation sign `(-1)^{pauliAnticommCount p a}` +(`pauliString_conj`) — so the sign-updated generator `(c · (-1)^{…}) • P_a` fixes the evolved +vector `P_p ·ᵥ v`. The Pauli +gate is the sign-only (`act = id`) case of Eq. (10.87), using involutivity `P_p · P_pᴴ = 1`. -/ +theorem pauli_smul_pauliString_mulVec_stabilizes (p : Fin n → Fin 4) (c : ℂ) + (a : Fin n → Fin 4) {v : (Fin n → Fin 2) → ℂ} + (hv : (c • pauliString a).mulVec v = v) : + ((c * (-1) ^ pauliAnticommCount p a) • pauliString a).mulVec ((pauliString p).mulVec v) + = (pauliString p).mulVec v := by + have hU : pauliString p * (pauliString p)ᴴ = 1 := by + rw [(pauliString_isHermitian p : (pauliString p)ᴴ = pauliString p)] + exact pauliString_mul_self p + have hconj : pauliString p * (c • pauliString a) * (pauliString p)ᴴ + = (c * (-1) ^ pauliAnticommCount p a) • pauliString a := by + rw [mul_smul_comm, smul_mul_assoc, + show ((pauliString p)ᴴ : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + = star (pauliString p) from rfl, pauliString_conj, smul_smul] + rw [← hconj] + exact conj_mulVec_toMatrix_mulVec hU hv + +/-! ### The simulator: per-operation update and the full run -/ + +/-- Whether a stabiliser operation is a **measurement** (`measure p`). The correctness theorem +`StabilizerTableau.run_stabilizes` is scoped to measurement-free computations; see the module +docstring. -/ +def StabilizerOp.IsMeasurement : StabilizerOp n → Prop + | .measure _ => True + | _ => False + +/-- The **actual raw-state evolution** of one stabiliser operation on the `n`-qubit register: +`prep` prepares `|0…0⟩`, a Clifford / Pauli gate applies its unitary matrix, and `measure` carries +the state through unchanged (its Born-rule collapse is the physics engine of §10.5.3 — see the +module docstring). -/ +def StabilizerOp.stepState : StabilizerOp n → ((Fin n → Fin 2) → ℂ) → ((Fin n → Fin 2) → ℂ) + | .prep, _ => compBasisZero n + | .clifford g, v => g.toMatrix.mulVec v + | .pauli p, v => (pauliString p).mulVec v + | .measure _, v => v + +/-- The **classical tableau update** of one stabiliser operation — the Gottesman–Knill simulator's +per-operation step: `prep` resets to the trivial tableau `⟨Z₁, …, Zₙ⟩`, a Clifford gate `g` maps +each generator's check row by `g.act` and sign by `· g.sign`, a Pauli gate `p` flips each +generator's sign +by `(-1)^{pauliAnticommCount p ·}` (check row unchanged), and `measure` carries the tableau through +unchanged (its genuine generator-replacement update is the §10.5.3 physics engine). -/ +def StabilizerOp.stepTableau : StabilizerOp n → StabilizerTableau n → StabilizerTableau n + | .prep, _ => StabilizerTableau.prep n + | .clifford g, T => ⟨fun i => g.act (T.gen i), fun i => T.sign i * g.sign (T.gen i)⟩ + | .pauli p, T => ⟨T.gen, fun i => T.sign i * (-1) ^ pauliAnticommCount p (T.gen i)⟩ + | .measure _, T => T + +/-- **One preservation step.** If a stabiliser operation is not a measurement and the tableau `T` +stabilises `v`, then the updated tableau `op.stepTableau T` stabilises the evolved state +`op.stepState v`. Assembles the three per-operation lemmas (`prep_stabilizes`, +`CliffordGate.smul_pauliString_mulVec_stabilizes`, `pauli_smul_pauliString_mulVec_stabilizes`). -/ +theorem StabilizerOp.step_stabilizes (op : StabilizerOp n) (hop : ¬ op.IsMeasurement) + (T : StabilizerTableau n) (v : (Fin n → Fin 2) → ℂ) (hTv : T.Stabilizes v) : + (op.stepTableau T).Stabilizes (op.stepState v) := by + cases op with + | prep => exact StabilizerTableau.prep_stabilizes + | clifford g => + intro i + exact g.smul_pauliString_mulVec_stabilizes (T.sign i) (T.gen i) (hTv i) + | pauli p => + intro i + exact pauli_smul_pauliString_mulVec_stabilizes p (T.sign i) (T.gen i) (hTv i) + | measure p => exact absurd trivial hop + +/-- The **tableau run** of a stabiliser computation: fold the per-operation classical update +`StabilizerOp.stepTableau` over the operation list, left to right (first operation first). -/ +def StabilizerTableau.run : StabilizerComputation n → StabilizerTableau n → StabilizerTableau n + | [], T => T + | op :: rest, T => StabilizerTableau.run rest (op.stepTableau T) + +/-- The **actual state** after running a stabiliser computation: fold the raw-state evolution +`StabilizerOp.stepState` over the operation list, left to right. -/ +def runState : StabilizerComputation n → ((Fin n → Fin 2) → ℂ) → ((Fin n → Fin 2) → ℂ) + | [], v => v + | op :: rest, v => runState rest (op.stepState v) + +/-- **The stabiliser simulator is correct on the unitary fragment (N&C Theorem 10.7).** For a +**measurement-free** stabiliser computation `prog` (state preparations and Hadamard / phase / +controlled-`NOT` / Pauli gates), if the tableau `T` stabilises the state `v`, then after running the +computation the tracked tableau `StabilizerTableau.run prog T` stabilises the actually-evolved state +`runState prog v`. So "the classical computer keeps track of the generators of the stabiliser" +(N&C §10.5.4) is **correct** for the whole unitary fragment: the tracked signed generators +`(sign i • P_{gen i})ᵢ` are a genuine stabiliser of the evolved quantum state at every step. + +Starting from `StabilizerTableau.prep`/`compBasisZero` (`StabilizerTableau.prep_stabilizes`) this +propagates the invariant along any prefix of unitary operations. Measurement's stabiliser update and +its post-collapse correctness are the §10.5.3 measurement rules +(`AxQM/Postulates/API/StabilizerMeasurement.lean`); assembling the two halves gives Theorem 10.7. +By induction on `prog` from `StabilizerOp.step_stabilizes`. -/ +theorem StabilizerTableau.run_stabilizes : + ∀ (prog : StabilizerComputation n), (∀ op ∈ prog, ¬ op.IsMeasurement) → + ∀ (T : StabilizerTableau n) (v : (Fin n → Fin 2) → ℂ), + T.Stabilizes v → (StabilizerTableau.run prog T).Stabilizes (runState prog v) := by + intro prog + induction prog with + | nil => intro _ T v hTv; exact hTv + | cons op rest ih => + intro hprog T v hTv + refine ih (fun o ho => hprog o (List.mem_cons.2 (Or.inr ho))) (op.stepTableau T) + (op.stepState v) ?_ + exact op.step_stabilizes (hprog op (List.mem_cons.2 (Or.inl rfl))) T v hTv + +end + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TraceDistancePOVM.lean b/LeanPool/AxQM/Concrete/TraceDistancePOVM.lean new file mode 100644 index 0000000000..9547d53efd --- /dev/null +++ b/LeanPool/AxQM/Concrete/TraceDistancePOVM.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVM +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.Concrete.ClassicalTraceDistance + +/-! +# The POVM characterization of the trace distance (Nielsen & Chuang, Theorem 9.1) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 9.1 +(p. 405) relates the (quantum) trace distance `D(ρ, σ) = ½ tr|ρ − σ|` of two +density operators to the classical trace distances of the outcome distributions +produced by measuring them: for a POVM `{Eₘ}` with outcome probabilities +`pₘ = tr(ρ Eₘ)` and `qₘ = tr(σ Eₘ)`, +``` +D(ρ, σ) = max_{Eₘ} D(pₘ, qₘ). +``` + +This file contains the **mathematical core** of the theorem: the two +inequalities that together express the maximum, phrased over operators +`ρ σ : E →L[𝕜] E` and a `POVM ι 𝕜 E`, with the classical distance measured by +`AxQM.Concrete.classicalTraceDist` and the quantum distance by +`½ · traceNorm`. The statement for states and measurements is in +`LeanPool/AxQM/NC/Ch9/Theorem1.lean`. + +## Main statements + +* `classicalTraceDist_toPMF_le` — the **upper bound** `(9.24)–(9.30)`: for *every* + POVM `M`, `D(pₘ, qₘ) ≤ ½ ‖ρ − σ‖₁`. No hypothesis on `ρ, σ` is needed. +* `classicalTraceDist_toPMF_eigenbasis_eq` — **achievability**: the projective + measurement in an eigenbasis of the self-adjoint operator `ρ − σ` attains the + bound, `D(pₘ, qₘ) = ½ ‖ρ − σ‖₁`. This is the converse direction of the theorem. +* `exists_povm_classicalTraceDist_eq` — the resulting **existence** statement + packaging the maximum: some POVM attains `½ ‖ρ − σ‖₁`. + +## Proof outline + +*Upper bound.* Writing `dᵢ = pᵢ − qᵢ = re ⟪ρ − σ, Eᵢ⟫_HS` +(`POVM.re_hsPairing_elements_sub_eq_toPMF_sub`) and choosing signs `rᵢ = ±1` with +`|dᵢ| = rᵢ · dᵢ`, the witness `W = ∑ᵢ rᵢ • Eᵢ` has operator norm `≤ 1` +(`POVM.opNorm_sum_real_smul_le_one`), so `∑ᵢ |dᵢ| = re ⟪ρ − σ, W⟫_HS ≤ ‖ρ − σ‖₁` +by the variational bound `ContinuousLinearMap.re_hsPairing_le_traceNorm_of_opNorm_le_one`. + +*Achievability.* Measuring in an orthonormal eigenbasis `b` of `ρ − σ`, the outcome +`i` has `pᵢ − qᵢ = re ⟪bᵢ, (ρ − σ) bᵢ⟫ = λᵢ` (the `i`-th eigenvalue), so +`∑ᵢ |pᵢ − qᵢ| = ∑ᵢ |λᵢ| = ‖ρ − σ‖₁` by +`LinearMap.IsSymmetric.traceNorm_eq_sum_abs_eigenvalues`. + +## References + +Nielsen, M. A., & Chuang, I. L. (2010). *Quantum Computation and Quantum +Information* (10th anniv. ed.). Cambridge University Press. Theorem 9.1, §9.2.1. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open scoped BigOperators + +variable {ι : Type*} [Fintype ι] + {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + +/-- **Nielsen & Chuang, Theorem 9.1 (upper bound / measurement monotonicity).** +For any POVM `M` on `E` and any operators `ρ σ : E →L[𝕜] E`, the classical trace +distance of the Born-rule outcome distributions `pₘ = M.toPMF ρ`, `qₘ = M.toPMF σ` +is bounded by half the trace norm of `ρ − σ`: +`D(pₘ, qₘ) ≤ ½ ‖ρ − σ‖₁`. + +This is the direction `(9.24)–(9.30)` of the theorem, valid for *all* POVMs and +with no positivity/self-adjointness hypothesis on `ρ, σ`. -/ +theorem classicalTraceDist_toPMF_le (M : POVM ι 𝕜 E) (ρ σ : E →L[𝕜] E) : + classicalTraceDist (M.toPMF ρ) (M.toPMF σ) ≤ (ρ - σ).traceNorm / 2 := by + have : CompleteSpace E := FiniteDimensional.completeSpace 𝕜 E + -- The `±1` sign witness realizing `|pᵢ − qᵢ| = rᵢ · (pᵢ − qᵢ)`. + set r : ι → ℝ := fun i => if 0 ≤ M.toPMF ρ i - M.toPMF σ i then 1 else -1 with hr + have hr_abs_le : ∀ i, |r i| ≤ 1 := fun i => by simp only [hr]; split <;> simp + have habs : ∀ i, |M.toPMF ρ i - M.toPMF σ i| = r i * (M.toPMF ρ i - M.toPMF σ i) := + fun i => by + simp only [hr] + by_cases h : 0 ≤ M.toPMF ρ i - M.toPMF σ i + · rw [ite_eq_left h, one_mul, abs_of_nonneg h] + · rw [ite_eq_right h, neg_one_mul, abs_of_neg (lt_of_not_ge h)] + -- The witness operator `W = ∑ᵢ rᵢ • Eᵢ`, with `‖W‖ ≤ 1`. + set W : E →L[𝕜] E := ∑ i, (r i : 𝕜) • M.elements i with hW + have hW_norm : ‖W‖ ≤ 1 := M.opNorm_sum_real_smul_le_one r hr_abs_le + -- `∑ᵢ |pᵢ − qᵢ| = re ⟪ρ − σ, W⟫_HS`. + have hsum : (∑ i, |M.toPMF ρ i - M.toPMF σ i|) = RCLike.re ((ρ - σ).hsPairing W) := by + rw [hW, ContinuousLinearMap.hsPairing_sum_right, RCLike.re_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.hsPairing_smul_right, ← starRingEnd_apply, RCLike.conj_ofReal, + RCLike.re_ofReal_mul, M.re_hsPairing_elements_sub_eq_toPMF_sub ρ σ i, ← habs i] + -- Assemble: `D(p,q) = ½ ∑|pᵢ − qᵢ| ≤ ½ ‖ρ − σ‖₁`. + rw [classicalTraceDist, hsum] + gcongr + exact ContinuousLinearMap.re_hsPairing_le_traceNorm_of_opNorm_le_one _ hW_norm + +/-- **Nielsen & Chuang, Theorem 9.1 (achievability).** The projective measurement +in an orthonormal *eigenbasis* of the self-adjoint operator `ρ − σ` — the POVM +`POVM.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl)` — realizes the trace +distance exactly: +`D(pₘ, qₘ) = ½ ‖ρ − σ‖₁`. + +On the eigenbasis the signed difference of outcome probabilities is the eigenvalue, +`pᵢ − qᵢ = λᵢ`, so `∑ᵢ |pᵢ − qᵢ| = ∑ᵢ |λᵢ| = ‖ρ − σ‖₁`. The hypothesis `hsymm` +records that `ρ − σ` is symmetric (its self-adjointness); for density operators +`ρ, σ` it always holds. -/ +theorem classicalTraceDist_toPMF_eigenbasis_eq (ρ σ : E →L[𝕜] E) + (hsymm : ((ρ - σ : E →L[𝕜] E) : E →ₗ[𝕜] E).IsSymmetric) : + classicalTraceDist ((POVM.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl)).toPMF ρ) + ((POVM.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl)).toPMF σ) + = (ρ - σ).traceNorm / 2 := by + -- On the eigenbasis, `pᵢ − qᵢ = re ⟪bᵢ, (ρ − σ) bᵢ⟫ = λᵢ`. + have hdiff : ∀ i, (POVM.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl)).toPMF ρ i + - (POVM.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl)).toPMF σ i + = hsymm.eigenvalues (rfl : Module.finrank 𝕜 E = _) i := by + intro i + rw [POVM.toPMF_ofOrthonormalBasis, POVM.toPMF_ofOrthonormalBasis, ← map_sub, + ← inner_sub_right, ← sub_apply, ← ContinuousLinearMap.coe_coe (ρ - σ), + hsymm.apply_eigenvectorBasis rfl i, inner_smul_right, + OrthonormalBasis.inner_eq_one _ i, mul_one, RCLike.ofReal_re] + rw [classicalTraceDist] + simp_rw [hdiff] + rw [← hsymm.traceNorm_eq_sum_abs_eigenvalues rfl, ContinuousLinearMap.traceNorm_toLinearMap] + +/-- **Nielsen & Chuang, Theorem 9.1 (the maximum is attained).** Combining the +upper bound with achievability: for self-adjoint `ρ − σ`, *some* POVM attains +`D(pₘ, qₘ) = ½ ‖ρ − σ‖₁`. Together with `classicalTraceDist_toPMF_le` (which bounds +every POVM below this value) this says `½ ‖ρ − σ‖₁` is the maximum of `D(pₘ, qₘ)` +over all POVMs. -/ +theorem exists_povm_classicalTraceDist_eq (ρ σ : E →L[𝕜] E) + (hsymm : ((ρ - σ : E →L[𝕜] E) : E →ₗ[𝕜] E).IsSymmetric) : + ∃ (n : ℕ) (M : POVM (Fin n) 𝕜 E), + classicalTraceDist (M.toPMF ρ) (M.toPMF σ) = (ρ - σ).traceNorm / 2 := + ⟨_, _, classicalTraceDist_toPMF_eigenbasis_eq ρ σ hsymm⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelColumnClear.lean b/LeanPool/AxQM/Concrete/TwoLevelColumnClear.lean new file mode 100644 index 0000000000..c1c517fb7e --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelColumnClear.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelEmbedding +public import LeanPool.AxQM.Concrete.GivensRotation + +/-! +# Concrete: clearing a column with two-level unitaries (N&C §4.5.1, eqs. 4.44–4.50) + +The two-level decomposition of an arbitrary `d × d` unitary (Nielsen & Chuang §4.5.1, p. 189) +proceeds by repeatedly *clearing a column*: given a unitary `U`, one multiplies it on the left by a +sequence `U₁, U₂, …` of two-level unitaries so that the product's first column becomes a multiple of +`e₀` (all entries below the top are zeroed — eqs. (4.44)–(4.50)). Each `Uₖ` is the Givens rotation +`givensRotation` (`Concrete/GivensRotation.lean`) embedded into the coordinate pair `{0, q}` +(`twoLevelEmbed`, `Concrete/TwoLevelEmbedding.lean`), which zeroes one below-diagonal entry while +leaving the already-cleared entries fixed. + +This file provides that step as reusable `Concrete/` lemmas, phrased first for a **vector** and then +for the **first column of a matrix**: + +* `exists_twoLevelUnitaryList_mulVec_eq_zero_of_ne` — for every `v : Fin (d+1) → ℂ` there is a list + `L` of two-level unitaries whose product sends `v` to a vector supported on coordinate `0` + (`(L.prod *ᵥ v) j = 0` for every `j ≠ 0`). +* `exists_twoLevelUnitaryList_clear_first_column` — the same, applied to the first column of a + matrix `U`: `(L.prod * U) i 0 = 0` for every `i ≠ 0`. This is the form the block-diagonal peel of + the §4.5.1 induction (`Concrete/TwoLevelDecomposition.lean`) consumes. + +The value that accumulates in coordinate `0` is deliberately left unspecified: the induction that +uses this step recovers it (it is a unit modulus when `v` is a column of a unitary) from the +unitarity of `L.prod * U`, so pinning it here would only add noise. + +## Use + +This is a shared building block for the §4.5.1 development (Exercise 4.43's `n`-qubit lift, also +used by Ex 4.37/4.38/4.39); the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **Clearing a chosen set of coordinates into coordinate `0`.** For a finite set `S` of +coordinates not containing `0`, there is a list `L` of two-level unitaries — each a Givens rotation +embedded in a pair `{0, q}` with `q ∈ S` — whose product zeroes every coordinate in `S` while +leaving every coordinate outside `S ∪ {0}` unchanged (coordinate `0` accumulates the cleared mass +and is left unconstrained). Proved by induction on `S`: each step adds one Givens factor on `{0, q}` +that zeroes `q` without disturbing the coordinates already handled. -/ +theorem exists_twoLevelUnitaryList_clear_finset (S : Finset (Fin (d + 1))) + (hS : (0 : Fin (d + 1)) ∉ S) (v : Fin (d + 1) → ℂ) : + ∃ L : List (Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ), + (∀ M ∈ L, IsTwoLevelUnitary M) ∧ + (∀ j ∈ S, (L.prod *ᵥ v) j = 0) ∧ + (∀ j, j ≠ 0 → j ∉ S → (L.prod *ᵥ v) j = v j) := by + induction S using Finset.induction_on with + | empty => + exact ⟨[], by simp, by simp, fun j _ _ => by simp [Matrix.one_mulVec]⟩ + | @insert q S' hqS' ih => + have hq0 : q ≠ 0 := fun h => hS (h ▸ Finset.mem_insert_self q S') + have hS' : (0 : Fin (d + 1)) ∉ S' := fun h => hS (Finset.mem_insert_of_mem h) + obtain ⟨L', hL', hzero', hfix'⟩ := ih hS' + set w := L'.prod *ᵥ v with hw + -- each step's product·ᵥv is the new Givens factor applied to the previous `w` + have hstep : ∀ j, (List.prod (twoLevelEmbed 0 q (givensRotation (w 0) (w q)) :: L') *ᵥ v) j + = (twoLevelEmbed 0 q (givensRotation (w 0) (w q)) *ᵥ w) j := fun j => by + rw [List.prod_cons, ← Matrix.mulVec_mulVec] + refine ⟨twoLevelEmbed 0 q (givensRotation (w 0) (w q)) :: L', ?_, ?_, ?_⟩ + · intro M hM + rcases List.mem_cons.mp hM with hM | hM + · exact hM ▸ isTwoLevelUnitary_twoLevelEmbed (Ne.symm hq0) + (givensRotation_mem_unitaryGroup _ _) + · exact hL' M hM + · -- every coordinate of `insert q S'` is zeroed + intro j hj + rw [hstep j, twoLevelEmbed_mulVec (Ne.symm hq0)] + rcases Finset.mem_insert.mp hj with hjq | hjS' + · -- `j = q`: the Givens rotation zeroes it + have hjne0 : j ≠ 0 := hjq ▸ hq0 + rw [ite_eq_right hjne0, ite_eq_left hjq] + exact givensRotation_row_one_dotProduct (w 0) (w q) + · -- `j ∈ S'`: untouched by this Givens step, already zero by the IH + have hjne0 : j ≠ 0 := fun h => hS' (h ▸ hjS') + have hjneq : j ≠ q := fun h => hqS' (h ▸ hjS') + rw [ite_eq_right hjne0, ite_eq_right hjneq] + exact hzero' j hjS' + · -- coordinates outside `insert q S' ∪ {0}` are unchanged + intro j hj0 hjins + have hjq : j ≠ q := fun h => hjins (h ▸ Finset.mem_insert_self q S') + have hjS' : j ∉ S' := fun h => hjins (Finset.mem_insert_of_mem h) + rw [hstep j, twoLevelEmbed_mulVec (Ne.symm hq0), ite_eq_right hj0, ite_eq_right hjq] + exact hfix' j hj0 hjS' + +/-- **Column clearing for a vector (N&C eqs. 4.44–4.50).** For every `v : Fin (d+1) → ℂ` there is a +list `L` of two-level unitaries whose product sends `v` to a vector supported on coordinate `0`: +`(L.prod *ᵥ v) j = 0` for every `j ≠ 0`. Instance of `exists_twoLevelUnitaryList_clear_finset` with +`S` the set of all nonzero coordinates. -/ +theorem exists_twoLevelUnitaryList_mulVec_eq_zero_of_ne (v : Fin (d + 1) → ℂ) : + ∃ L : List (Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ), + (∀ M ∈ L, IsTwoLevelUnitary M) ∧ ∀ j : Fin (d + 1), j ≠ 0 → (L.prod *ᵥ v) j = 0 := by + obtain ⟨L, hL, hzero, _⟩ := + exists_twoLevelUnitaryList_clear_finset (Finset.univ.erase 0) (by simp) v + exact ⟨L, hL, fun j hj => hzero j (Finset.mem_erase.mpr ⟨hj, Finset.mem_univ j⟩)⟩ + +/-- **Column clearing for the first column of a matrix (N&C eq. 4.50).** For every +`U : Matrix (Fin (d+1)) (Fin (d+1)) ℂ` there is a list `L` of two-level unitaries such that the +first column of `L.prod * U` is a multiple of `e₀`: `(L.prod * U) i 0 = 0` for every `i ≠ 0`. This +is the first step of the §4.5.1 two-level decomposition, applied to `U`'s first column. -/ +theorem exists_twoLevelUnitaryList_clear_first_column (U : Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ) : + ∃ L : List (Matrix (Fin (d + 1)) (Fin (d + 1)) ℂ), + (∀ M ∈ L, IsTwoLevelUnitary M) ∧ ∀ i : Fin (d + 1), i ≠ 0 → (L.prod * U) i 0 = 0 := by + obtain ⟨L, hL, hzero⟩ := exists_twoLevelUnitaryList_mulVec_eq_zero_of_ne (fun k => U k 0) + refine ⟨L, hL, fun i hi => ?_⟩ + simpa [Matrix.mul_apply, Matrix.mulVec, dotProduct] using hzero i hi + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelControlledDecomposition.lean b/LeanPool/AxQM/Concrete/TwoLevelControlledDecomposition.lean new file mode 100644 index 0000000000..5d5e0b0bb3 --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelControlledDecomposition.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelControlledIdentification + +/-! +# Concrete: the §4.5.2 realisation of a two-level unitary, assembled at the matrix level + +(Nielsen & Chuang §4.5.2, p. 191–193.) + +The §4.5.2 realisation of a two-level unitary `U` (acting non-trivially only on two computational +basis states `|s⟩`, `|t⟩`) as a circuit has two stages: **walk a Gray code** to relocate the two +active states onto a bit-adjacent pair (a sequence of basis-state swaps), then apply a **controlled +single-qubit gate**, then undo the swaps. The junction +`swapConj_swapChain_grayCode_eq_ctrlSingleQubit` established that conjugating `U` by the Gray-code +swap chain produces, verbatim, a controlled single-qubit gate. This file assembles that into the +decomposition of `U` itself, and shows the swaps are themselves controlled single-qubit gates. + +## The pieces + +* `AxQM.Concrete.swap_eq_twoLevelEmbed_swapTwo` — a basis transposition is the two-level + embedding of the elementary `2 × 2` swap: + `Matrix.swap ℂ p q = twoLevelEmbed p q (Matrix.swap ℂ 0 1)` (`p ≠ q`). +* `AxQM.Concrete.swap_eq_ctrlSingleQubit` — **a bit-adjacent basis transposition is a + controlled single-qubit gate.** For `differsInOneBit a b`, `Matrix.swap ℂ (enc a) (enc b)` equals + `ctrlSingleQubit enc j c (Matrix.swap ℂ 0 1)` — the swap that shuffles the two active states is a + controlled-`NOT` (the `2 × 2` block `Matrix.swap ℂ 0 1` is the `X`/`NOT` gate), so each swap of + the Gray-code walk is one of the same family of controlled single-qubit gates as the final + controlled-`U₀`. Its block is unitary (`swapTwo_mem_unitaryGroup`). +* `AxQM.Concrete.swapConj_reverse_swapConj` — conjugating by the reversed list undoes + conjugating by the list (`swapConj L.reverse (swapConj L U) = U`); the swaps are involutions, so + the walk is invertible. +* `AxQM.Concrete.twoLevelUnitary_eq_swapConj_ctrlSingleQubit` — **the assembled + decomposition**: a two-level unitary `U` supported on `{enc s, enc t}` (`s ≠ t`) *equals* the + swap-conjugate (by the reversed Gray-code chain) of a controlled single-qubit gate + `ctrlSingleQubit enc j c U₀` with `U₀` a `2 × 2` unitary. Combined with `swap_eq_ctrlSingleQubit` + (each chain swap is itself a controlled single-qubit gate) this exhibits `U` as built entirely + from controlled single-qubit gates — the §4.5.2 conclusion at the matrix level. + +## Use + +This is used in the §4.5.2 development of Exercise 4.43's `n`-qubit lift; the statement of +Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- The elementary `2 × 2` basis transposition `Matrix.swap ℂ 0 1` (the `X`/`NOT` gate) is +unitary. -/ +theorem swapTwo_mem_unitaryGroup : + Matrix.swap ℂ (0 : Fin 2) 1 ∈ Matrix.unitaryGroup (Fin 2) ℂ := + (isTwoLevelUnitary_swap 0 1).1 + +/-- **A basis transposition is the two-level embedding of the elementary `2 × 2` swap.** For +`p ≠ q`, `Matrix.swap ℂ p q = twoLevelEmbed p q (Matrix.swap ℂ 0 1)`: placing the `2 × 2` swap +`!![0, 1; 1, 0]` into the `{p, q}` block reproduces the `d × d` transposition. -/ +theorem swap_eq_twoLevelEmbed_swapTwo {p q : Fin d} (hpq : p ≠ q) : + Matrix.swap ℂ p q = twoLevelEmbed p q (Matrix.swap ℂ (0 : Fin 2) 1) := by + have s00 : Matrix.swap ℂ (0 : Fin 2) 1 0 0 = 0 := by + rw [swap_apply_eq_one_row, Equiv.swap_apply_left]; exact Matrix.one_apply_ne (by decide) + have s01 : Matrix.swap ℂ (0 : Fin 2) 1 0 1 = 1 := by + rw [swap_apply_eq_one_row, Equiv.swap_apply_left]; exact Matrix.one_apply_eq _ + have s10 : Matrix.swap ℂ (0 : Fin 2) 1 1 0 = 1 := by + rw [swap_apply_eq_one_row, Equiv.swap_apply_right]; exact Matrix.one_apply_eq _ + have s11 : Matrix.swap ℂ (0 : Fin 2) 1 1 1 = 0 := by + rw [swap_apply_eq_one_row, Equiv.swap_apply_right]; exact Matrix.one_apply_ne (by decide) + ext i j + rw [swap_apply_eq_one_row, twoLevelEmbed_apply, s00, s01, s10, s11] + rcases eq_or_ne i p with hip | hip + · rw [hip, Equiv.swap_apply_left, ite_eq_left rfl] + rcases eq_or_ne j p with hjp | hjp + · rw [hjp, ite_eq_left rfl]; exact Matrix.one_apply_ne (Ne.symm hpq) + · rw [ite_eq_right hjp] + rcases eq_or_ne j q with hjq | hjq + · rw [hjq, ite_eq_left rfl]; exact Matrix.one_apply_eq _ + · rw [ite_eq_right hjq]; exact Matrix.one_apply_ne (Ne.symm hjq) + · rcases eq_or_ne i q with hiq | hiq + · rw [ite_eq_right hip, hiq, Equiv.swap_apply_right, ite_eq_left rfl] + rcases eq_or_ne j p with hjp | hjp + · rw [hjp, ite_eq_left rfl]; exact Matrix.one_apply_eq _ + · rw [ite_eq_right hjp] + rcases eq_or_ne j q with hjq | hjq + · rw [hjq, ite_eq_left rfl]; exact Matrix.one_apply_ne hpq + · rw [ite_eq_right hjq]; exact Matrix.one_apply_ne (Ne.symm hjp) + · rw [ite_eq_right hip, ite_eq_right hiq, Equiv.swap_apply_of_ne_of_ne hip hiq] + exact Matrix.one_apply + +variable {m : ℕ} + +/-- **A bit-adjacent basis transposition is a controlled single-qubit gate.** Fix an encoding +`enc : (Fin m → Fin 2) ≃ Fin d`. For bit-strings `a`, `b` differing in exactly one bit +(`differsInOneBit a b`), the basis transposition `Matrix.swap ℂ (enc a) (enc b)` equals a controlled +single-qubit gate `ctrlSingleQubit enc j c (Matrix.swap ℂ 0 1)` — a controlled-`NOT` with the target +on the single differing bit `j`. So each swap of the §4.5.2 Gray-code walk belongs to the same +family of controlled single-qubit gates as the final controlled-`U₀`. -/ +theorem swap_eq_ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) {a b : Fin m → Fin 2} + (hab : differsInOneBit a b) : + ∃ (j : Fin m) (c : Fin m → Fin 2), + Matrix.swap ℂ (enc a) (enc b) + = ctrlSingleQubit enc j c (Matrix.swap ℂ (0 : Fin 2) 1) := by + obtain ⟨j, hj, hoff⟩ := hab + refine ⟨j, a, ?_⟩ + have hne : a ≠ b := fun h => hj (by rw [h]) + have hencne : enc a ≠ enc b := enc.injective.ne hne + rw [ctrlSingleQubit_eq_twoLevelEmbed] + rcases update_zero_one_eq_pair hj hoff with ⟨h0, h1⟩ | ⟨h0, h1⟩ + · rw [h0, h1]; exact swap_eq_twoLevelEmbed_swapTwo hencne + · rw [h0, h1, ← swap_eq_twoLevelEmbed_swapTwo hencne.symm] + exact Matrix.swap_comm (enc a) (enc b) + +/-- Conjugating `X` by the transposition `Matrix.swap ℂ p q` twice returns `X`: the swap is an +involution (`Matrix.swap_mul_self`), so the double conjugation collapses. -/ +theorem swap_swap_conj (p q : Fin d) (X : Matrix (Fin d) (Fin d) ℂ) : + Matrix.swap ℂ p q * (Matrix.swap ℂ p q * X * Matrix.swap ℂ p q) * Matrix.swap ℂ p q + = X := by + set s := Matrix.swap ℂ p q with hs_def + have hs : s * s = 1 := by rw [hs_def]; exact Matrix.swap_mul_self p q + have hre : s * (s * X * s) * s = s * s * X * (s * s) := by noncomm_ring + rw [hre, hs, one_mul, mul_one] + +/-- **Conjugating by the reversed list undoes conjugating by the list**: +`swapConj L.reverse (swapConj L U) = U`. Each basis transposition is an involution, so the reversed +Gray-code walk inverts the forward walk. This is what turns the junction (which conjugates `U` +into a controlled single-qubit gate) into a decomposition of `U` itself. -/ +theorem swapConj_reverse_swapConj (L : List (Fin d × Fin d)) (U : Matrix (Fin d) (Fin d) ℂ) : + swapConj L.reverse (swapConj L U) = U := by + induction L with + | nil => rfl + | cons pq L ih => + rw [List.reverse_cons, swapConj_cons, swapConj_append, swapConj_cons, swapConj_nil, + swap_swap_conj, ih] + +/-- **The §4.5.2 decomposition of a two-level unitary, assembled.** A two-level unitary `U` +supported on `{enc s, enc t}` (`s ≠ t`) equals the swap-conjugate — by the *reversed* Gray chain — +of a controlled single-qubit gate `ctrlSingleQubit enc j c U₀` with `U₀` a `2 × 2` unitary: +`U = swapConj (swapChain ((grayCode s t).dropLast.map enc)).reverse (ctrlSingleQubit enc j c U₀)`. +Chains the junction `swapConj_swapChain_grayCode_eq_ctrlSingleQubit` (which conjugates `U` into a +controlled single-qubit gate) with `swapConj_reverse_swapConj` (which inverts the conjugation). +Since each swap of the chain is itself a controlled single-qubit gate (`swap_eq_ctrlSingleQubit`), +this exhibits `U` as built entirely from controlled single-qubit gates — the §4.5.2 conclusion. -/ +theorem twoLevelUnitary_eq_swapConj_ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) + {s t : Fin m → Fin 2} (hst : s ≠ t) {U : Matrix (Fin d) (Fin d) ℂ} + (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ enc s ∧ i ≠ enc t) ∨ (j ≠ enc s ∧ j ≠ enc t) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + ∃ (j : Fin m) (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ), + U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ + U = swapConj (swapChain ((grayCode s t).dropLast.map enc)).reverse + (ctrlSingleQubit enc j c U₀) := by + obtain ⟨j, c, U₀, hU₀, heq⟩ := + swapConj_swapChain_grayCode_eq_ctrlSingleQubit enc hst hunit hsupp + exact ⟨j, c, U₀, hU₀, by rw [← heq, swapConj_reverse_swapConj]⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelControlledIdentification.lean b/LeanPool/AxQM/Concrete/TwoLevelControlledIdentification.lean new file mode 100644 index 0000000000..439afefc4e --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelControlledIdentification.lean @@ -0,0 +1,198 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.ControlledSingleQubit +public import LeanPool.AxQM.Concrete.TwoLevelGrayWalk + +/-! +# Concrete: a two-level unitary supported on a bit-adjacent pair *is* a controlled single-qubit gate + +(Nielsen & Chuang §4.5.2, the first-stage → controlled-`U₀` junction, p. 191–193.) + +The §4.5.2 realisation of a two-level unitary as a circuit of single-qubit and `CNOT` gates has two +stages. The **first stage** (`swapConj_swapChain_grayCode_support`) walks a Gray code to relocate +the two active basis states of a two-level unitary onto a pair `{enc e, enc t}` differing in exactly +one bit; the **second stage** applies a controlled single-qubit gate. This file supplies the +*junction* between them: a two-level unitary whose support is a bit-adjacent pair is, verbatim, one +of the controlled single-qubit gates `ctrlSingleQubit` of `Concrete/ControlledSingleQubit.lean`. + +`ctrlSingleQubit_eq_twoLevelEmbed` already runs the *forward* direction — a controlled +single-qubit gate is a two-level embedding. The converse needed here is structural, in two layers. + +## The general two-level converse (reusable, no bit-strings) + +For any `d × d` matrix `W` agreeing with the identity off a coordinate pair `{p, q}` (`p ≠ q`): + +* `AxQM.Concrete.twoLevelBlock W p q` — the `2 × 2` block `!![W p p, W p q; W q p, W q q]`. +* `AxQM.Concrete.eq_twoLevelEmbed_of_support` — + **`W = twoLevelEmbed p q (twoLevelBlock W p q)`**: a matrix supported on `{p, q}` is the two-level + embedding of its own block. This is the structural converse of `isTwoLevelUnitary_twoLevelEmbed`. +* `AxQM.Concrete.twoLevelEmbed_injective` — `twoLevelEmbed p q` is injective on the block + (`p ≠ q`), read off the four block entries. +* `AxQM.Concrete.twoLevelBlock_mem_unitaryGroup` — **the block of a two-level *unitary* is + unitary**: from `Wᴴ W = 1`, the `*`-homomorphism laws give `twoLevelEmbed p q (GᴴG) = + twoLevelEmbed p q 1`, so injectivity forces `Gᴴ G = 1`. + +## The controlled single-qubit identification + +* `AxQM.Concrete.eq_ctrlSingleQubit_of_support` — **a two-level unitary supported on a + bit-adjacent encoded pair `{enc a, enc b}` (`differsInOneBit a b`) equals + `ctrlSingleQubit enc j c U₀`** for the differing bit `j`, control pattern `c = a`, and a `2 × 2` + *unitary* block `U₀`. The two active states `{c[j↦0], c[j↦1]}` are exactly `{a, b}` (in some + order — `update_zero_one_eq_pair`), so the general converse applies at the pair + `(enc c[j↦0], enc c[j↦1])` and `ctrlSingleQubit_eq_twoLevelEmbed` closes it. +* `AxQM.Concrete.swapConj_swapChain_grayCode_eq_ctrlSingleQubit` — **the junction, + assembled**: conjugating a two-level unitary supported on `{enc s, enc t}` (`s ≠ t`) by the + Gray-code swap chain yields, verbatim, a controlled single-qubit gate `ctrlSingleQubit enc j c U₀` + with `U₀` unitary. This hands the §4.5.2 first stage's output straight to the controlled-`U₀` + object. + +## Use + +This is used in the §4.5.2 development of Exercise 4.43's `n`-qubit lift; the statement of +Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- The `2 × 2` principal block of a `d × d` matrix `W` at the coordinate pair `{p, q}` +(`p ↦ 0`, `q ↦ 1`). For a matrix supported on `{p, q}` it is the block `twoLevelEmbed` re-embeds +(`eq_twoLevelEmbed_of_support`). -/ +def twoLevelBlock (W : Matrix (Fin d) (Fin d) ℂ) (p q : Fin d) : Matrix (Fin 2) (Fin 2) ℂ := + !![W p p, W p q; W q p, W q q] + +/-- Off the `{p, q} × {p, q}` block, `twoLevelEmbed p q G` agrees with the identity — the "acts +non-trivially on at most two components" clause, extracted as a reusable entry lemma. -/ +theorem twoLevelEmbed_eq_one_of_off (G : Matrix (Fin 2) (Fin 2) ℂ) {p q i j : Fin d} + (hij : (i ≠ p ∧ i ≠ q) ∨ (j ≠ p ∧ j ≠ q)) : + twoLevelEmbed p q G i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j := by + rw [twoLevelEmbed_apply, Matrix.one_apply] + rcases hij with ⟨hip, hiq⟩ | ⟨hjp, hjq⟩ <;> split_ifs <;> simp_all + +/-- **A matrix supported on a coordinate pair is the two-level embedding of its own block.** If `W` +agrees with the identity on every entry off the `{p, q} × {p, q}` block (`p ≠ q`), then +`W = twoLevelEmbed p q (twoLevelBlock W p q)`. This is the structural converse of +`isTwoLevelUnitary_twoLevelEmbed`. -/ +theorem eq_twoLevelEmbed_of_support {W : Matrix (Fin d) (Fin d) ℂ} {p q : Fin d} (hpq : p ≠ q) + (hsupp : ∀ i j : Fin d, (i ≠ p ∧ i ≠ q) ∨ (j ≠ p ∧ j ≠ q) → + W i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + W = twoLevelEmbed p q (twoLevelBlock W p q) := by + ext i j + by_cases hoff : (i ≠ p ∧ i ≠ q) ∨ (j ≠ p ∧ j ≠ q) + · rw [hsupp i j hoff, twoLevelEmbed_eq_one_of_off (twoLevelBlock W p q) hoff] + · simp only [not_or, not_and_or, not_not] at hoff + obtain ⟨hi, hj⟩ := hoff + rcases hi with rfl | rfl <;> rcases hj with rfl | rfl <;> + simp [twoLevelEmbed_apply, twoLevelBlock, hpq.symm] + +/-- **`twoLevelEmbed p q` is injective on the `2 × 2` block** (`p ≠ q`): two embeddings agree iff +the blocks do, read off the four block entries `(p,p), (p,q), (q,p), (q,q)`. -/ +theorem twoLevelEmbed_injective {p q : Fin d} (hpq : p ≠ q) {A B : Matrix (Fin 2) (Fin 2) ℂ} + (h : twoLevelEmbed p q A = twoLevelEmbed p q B) : A = B := by + ext a b + fin_cases a <;> fin_cases b + · simpa [twoLevelEmbed_apply, hpq] using congrFun (congrFun h p) p + · simpa [twoLevelEmbed_apply, hpq, hpq.symm] using congrFun (congrFun h p) q + · simpa [twoLevelEmbed_apply, hpq, hpq.symm] using congrFun (congrFun h q) p + · simpa [twoLevelEmbed_apply, hpq, hpq.symm] using congrFun (congrFun h q) q + +/-- **The block of a two-level unitary is a `2 × 2` unitary.** If `W` is unitary and supported on +`{p, q}` (`p ≠ q`), then `twoLevelBlock W p q ∈ U(2)`: unfolding `Wᴴ W = 1` through the +`*`-homomorphism laws of `twoLevelEmbed` gives `twoLevelEmbed p q (GᴴG) = twoLevelEmbed p q 1`, and +injectivity forces `Gᴴ G = 1`. -/ +theorem twoLevelBlock_mem_unitaryGroup {W : Matrix (Fin d) (Fin d) ℂ} {p q : Fin d} (hpq : p ≠ q) + (hW : W ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ p ∧ i ≠ q) ∨ (j ≠ p ∧ j ≠ q) → + W i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + twoLevelBlock W p q ∈ Matrix.unitaryGroup (Fin 2) ℂ := by + set G := twoLevelBlock W p q with hG + have hWe : W = twoLevelEmbed p q G := eq_twoLevelEmbed_of_support hpq hsupp + rw [Matrix.mem_unitaryGroup_iff'] at hW ⊢ + rw [Matrix.star_eq_conjTranspose] at hW ⊢ + rw [hWe, twoLevelEmbed_conjTranspose, twoLevelEmbed_mul hpq, ← twoLevelEmbed_one hpq] at hW + exact twoLevelEmbed_injective hpq hW + +variable {m : ℕ} + +/-- The two states `a[j↦0]` and `a[j↦1]` obtained by pinning bit `j` of `a` to `0`/`1` are exactly +`{a, b}` (in one of the two orders) whenever `a` and `b` differ precisely at bit `j`. -/ +theorem update_zero_one_eq_pair {a b : Fin m → Fin 2} {j : Fin m} (hj : a j ≠ b j) + (hoff : ∀ k, k ≠ j → a k = b k) : + (Function.update a j 0 = a ∧ Function.update a j 1 = b) ∨ + (Function.update a j 0 = b ∧ Function.update a j 1 = a) := by + have hb : Function.update a j (b j) = b := by + funext k + rcases eq_or_ne k j with rfl | hk + · rw [Function.update_self] + · rw [Function.update_of_ne hk]; exact hoff k hk + rcases (by omega : a j = 0 ∨ a j = 1) with h0 | h1 + · refine Or.inl ⟨?_, ?_⟩ + · rw [← h0]; exact Function.update_eq_self j a + · rw [← (by omega : b j = 1)]; exact hb + · refine Or.inr ⟨?_, ?_⟩ + · rw [← (by omega : b j = 0)]; exact hb + · rw [← h1]; exact Function.update_eq_self j a + +/-- **A two-level unitary supported on a bit-adjacent pair is a controlled single-qubit gate.** Fix +an encoding `enc : (Fin m → Fin 2) ≃ Fin d`. If `W` is unitary and acts non-trivially only on the +two basis states `{enc a, enc b}` for bit-strings differing in exactly one bit +(`differsInOneBit a b`), then `W = ctrlSingleQubit enc j c U₀` for the differing bit `j`, control +pattern `c = a`, and a `2 × 2` *unitary* `U₀` — the §4.5.2 controlled-`U₀` gate. -/ +theorem eq_ctrlSingleQubit_of_support (enc : (Fin m → Fin 2) ≃ Fin d) {a b : Fin m → Fin 2} + (hab : differsInOneBit a b) {W : Matrix (Fin d) (Fin d) ℂ} + (hW : W ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ enc a ∧ i ≠ enc b) ∨ (j ≠ enc a ∧ j ≠ enc b) → + W i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + ∃ (j : Fin m) (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ), + U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ W = ctrlSingleQubit enc j c U₀ := by + obtain ⟨j, hj, hoff⟩ := hab + set p := enc (Function.update a j 0) with hp + set q := enc (Function.update a j 1) with hq + have hpq : p ≠ q := enc.injective.ne (update_zero_ne_update_one a) + -- `{p, q} = {enc a, enc b}` as a set, so the support hypothesis transfers to the pair `(p, q)`. + have hset : ∀ x : Fin d, (x ≠ p ∧ x ≠ q) ↔ (x ≠ enc a ∧ x ≠ enc b) := by + intro x + rcases update_zero_one_eq_pair hj hoff with ⟨h0, h1⟩ | ⟨h0, h1⟩ + · simp only [hp, hq, h0, h1] + · simp only [hp, hq, h0, h1]; tauto + have hsupp' : ∀ i j' : Fin d, (i ≠ p ∧ i ≠ q) ∨ (j' ≠ p ∧ j' ≠ q) → + W i j' = (1 : Matrix (Fin d) (Fin d) ℂ) i j' := by + rintro i j' (h | h) + · exact hsupp i j' (Or.inl ((hset i).mp h)) + · exact hsupp i j' (Or.inr ((hset j').mp h)) + refine ⟨j, a, twoLevelBlock W p q, twoLevelBlock_mem_unitaryGroup hpq hW hsupp', ?_⟩ + rw [ctrlSingleQubit_eq_twoLevelEmbed] + exact eq_twoLevelEmbed_of_support hpq hsupp' + +/-- **The §4.5.2 first-stage → controlled-`U₀` junction, assembled.** Conjugating a two-level +unitary +`U` supported on `{enc s, enc t}` (`s ≠ t`) by the Gray-code swap chain +`swapChain ((grayCode s t).dropLast.map enc)` yields, verbatim, a controlled single-qubit gate +`ctrlSingleQubit enc j c U₀` with `U₀` a `2 × 2` unitary. Chains the first-stage relocation +(`swapConj_swapChain_grayCode_support`, which lands the support on a bit-adjacent pair) into the +controlled-gate identification (`eq_ctrlSingleQubit_of_support`). -/ +theorem swapConj_swapChain_grayCode_eq_ctrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) + {s t : Fin m → Fin 2} (hst : s ≠ t) {U : Matrix (Fin d) (Fin d) ℂ} + (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ enc s ∧ i ≠ enc t) ∨ (j ≠ enc s ∧ j ≠ enc t) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + ∃ (j : Fin m) (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ), + U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ + swapConj (swapChain ((grayCode s t).dropLast.map enc)) U = ctrlSingleQubit enc j c U₀ := by + obtain ⟨e, hdiff, hu, hsupp'⟩ := swapConj_swapChain_grayCode_support enc hst hunit hsupp + exact eq_ctrlSingleQubit_of_support enc hdiff hu hsupp' + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelControlledProduct.lean b/LeanPool/AxQM/Concrete/TwoLevelControlledProduct.lean new file mode 100644 index 0000000000..9ec4270967 --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelControlledProduct.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelControlledDecomposition + +/-! +# Concrete: a two-level unitary as an explicit product of controlled single-qubit gates (N&C §4.5.2) + +(Nielsen & Chuang §4.5.2, p. 191–193.) + +`Concrete/TwoLevelControlledDecomposition.lean` established the §4.5.2 decomposition of a two-level +unitary `U` (supported on two computational basis states `|s⟩`, `|t⟩`) in *swap-conjugation* form, +`U = swapConj (reversed Gray chain) (ctrlSingleQubit …)`, and that each Gray-code swap is itself a +controlled single-qubit gate. This file flattens that conjugation into a **single explicit product +(`List.prod`) of controlled single-qubit gates** — the concrete "circuit as a list of gates" form +that the `n`-qubit lift of Exercise 4.43 consumes. + +## The pieces + +* `AxQM.Concrete.IsCtrlSingleQubit` — the predicate "`g` is a controlled single-qubit gate + for the encoding `enc`": `g = ctrlSingleQubit enc j c U₀` for some target bit `j`, control pattern + `c`, and `2 × 2` *unitary* `U₀`. Both stages of the §4.5.2 circuit — the Gray-code swaps + (controlled-`NOT`s) and the final controlled-`U₀` — are of this family. +* `AxQM.Concrete.isCtrlSingleQubit_swap` — a bit-adjacent basis transposition is one + (repackages `swap_eq_ctrlSingleQubit`: the `2 × 2` block is the swap `!![0,1;1,0] = X`, unitary). +* `AxQM.Concrete.rel_of_mem_swapChain` — **the combinatorial bridge**: if the path is a + chain for a relation `R` (`List.IsChain R path`), every transposition `(p, q)` of `swapChain path` + has `R p q` (it is a consecutive pair of the path). Applied with `R = differsInOneBit` through the + encoding, this makes *every* swap of the Gray-code chain bit-adjacent, hence a controlled-`NOT`. +* `AxQM.Concrete.swapConj_eq_prod` — **the algebra**: conjugation by a transposition + list is an explicit product, `swapConj L V = (L.map swap ++ V :: L.reverse.map swap).prod`. +* `AxQM.Concrete.twoLevelUnitary_isProd_ctrlSingleQubit` — **the headline**: a two-level + unitary supported on `{enc s, enc t}` (`s ≠ t`) equals `gates.prod` for an explicit list `gates` + *every* member of which is a controlled single-qubit gate. It flattens + `twoLevelUnitary_eq_swapConj_ctrlSingleQubit` via `swapConj_eq_prod`, then classifies each factor: + the middle factor is the controlled-`U₀`, and each swap factor is a Gray-chain transposition, + shown + bit-adjacent by `rel_of_mem_swapChain` fed the Gray chain `grayCode_isChain`. This is the §4.5.2 + conclusion "a two-level unitary is a product of controlled single-qubit gates" in gate-list form. + +## Use + +This is used in the §4.5.2 development of Exercise 4.43's `n`-qubit lift; the statement of +Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- A `d × d` matrix `g` is a **controlled single-qubit gate** for the encoding +`enc : (Fin m → Fin 2) ≃ Fin d` when `g = ctrlSingleQubit enc j c U₀` for some target bit `j`, +control pattern `c`, and `2 × 2` *unitary* block `U₀`. This is the gate family both stages of the +§4.5.2 circuit belong to: the Gray-code swaps (controlled-`NOT`s) and the final controlled-`U₀`. -/ +def IsCtrlSingleQubit {m d : ℕ} (enc : (Fin m → Fin 2) ≃ Fin d) + (g : Matrix (Fin d) (Fin d) ℂ) : Prop := + ∃ (j : Fin m) (c : Fin m → Fin 2) (U₀ : Matrix (Fin 2) (Fin 2) ℂ), + U₀ ∈ Matrix.unitaryGroup (Fin 2) ℂ ∧ g = ctrlSingleQubit enc j c U₀ + +/-- **A bit-adjacent basis transposition is a controlled single-qubit gate** (a controlled-`NOT`). +Repackages `swap_eq_ctrlSingleQubit`: for `differsInOneBit a b`, `Matrix.swap ℂ (enc a) (enc b)` is +`ctrlSingleQubit enc j c (Matrix.swap ℂ 0 1)`, whose `2 × 2` block `!![0,1;1,0] = X` is unitary +(`swapTwo_mem_unitaryGroup`). -/ +theorem isCtrlSingleQubit_swap {m d : ℕ} (enc : (Fin m → Fin 2) ≃ Fin d) + {a b : Fin m → Fin 2} (hab : differsInOneBit a b) : + IsCtrlSingleQubit enc (Matrix.swap ℂ (enc a) (enc b)) := by + obtain ⟨j, c, hjc⟩ := swap_eq_ctrlSingleQubit enc hab + exact ⟨j, c, Matrix.swap ℂ (0 : Fin 2) 1, swapTwo_mem_unitaryGroup, hjc⟩ + +/-- **Every transposition of a swap chain relates its two coordinates under any relation the path is +a chain for.** If `List.IsChain R l` then each pair `(p, q) ∈ swapChain l` satisfies `R p q` — it is +a consecutive pair of the path. With `R = differsInOneBit` (through the encoding) this makes every +Gray-code swap bit-adjacent, hence a controlled-`NOT`. Proved by the `swapChain` recursion: the +outer swap `(a, b)` of `swapChain (a :: b :: l)` is related by the chain's head step `R a b`, the +rest by the inductive hypothesis on `b :: l`. -/ +theorem rel_of_mem_swapChain {d : ℕ} {R : Fin d → Fin d → Prop} : + ∀ {l : List (Fin d)}, List.IsChain R l → ∀ pq ∈ swapChain l, R pq.1 pq.2 := by + intro l + induction l using swapChain.induct with + | case1 => intro _ pq hpq; simp at hpq + | case2 a => intro _ pq hpq; simp at hpq + | case3 a b l ih => + intro hch pq hpq + rw [swapChain_cons_cons, List.mem_append, List.mem_singleton] at hpq + rcases (List.isChain_cons_iff R a (b :: l)).mp hch with h | ⟨b', l', hab, hbl, heq⟩ + · simp at h + · obtain ⟨rfl, rfl⟩ : b = b' ∧ l = l' := by simpa using heq + rcases hpq with hpq | rfl + · exact ih hbl pq hpq + · exact hab + +/-- **Conjugation by a list of basis transpositions is an explicit product of swap matrices around +the conjugand.** `swapConj L V` equals the product of the swap matrices of `L`, then `V`, then the +swap matrices of `L.reverse`: +`swapConj L V = (L.map (swap ·.1 ·.2) ++ V :: L.reverse.map (swap ·.1 ·.2)).prod`. Proved by +induction on `L`; the cons step reassociates `s * (P·V·Q) * s = (s·P)·(V·(Q·s))` (`noncomm_ring`), +matching the head swap `s` peeled off the front and the back of the reversed tail. -/ +theorem swapConj_eq_prod {d : ℕ} (L : List (Fin d × Fin d)) (V : Matrix (Fin d) (Fin d) ℂ) : + swapConj L V + = ((L.map fun pq => Matrix.swap ℂ pq.1 pq.2) + ++ V :: (L.reverse.map fun pq => Matrix.swap ℂ pq.1 pq.2)).prod := by + induction L with + | nil => simp + | cons pq L ih => + rw [swapConj_cons, ih] + simp only [List.map_cons, List.reverse_cons, List.map_append, List.map_nil, + List.prod_append, List.prod_cons, List.prod_nil, mul_one] + noncomm_ring + +/-- **The §4.5.2 decomposition of a two-level unitary as an explicit product of controlled +single-qubit gates.** A two-level unitary `U` supported on `{enc s, enc t}` (`s ≠ t` two distinct +`m`-bit strings, `enc : (Fin m → Fin 2) ≃ Fin d`) *equals* `gates.prod` for an explicit list `gates` +**every** member of which is a controlled single-qubit gate (`IsCtrlSingleQubit enc`). + +Flattens `twoLevelUnitary_eq_swapConj_ctrlSingleQubit` (`U` as the swap-conjugate of a +controlled-`U₀` by the reversed Gray chain) via `swapConj_eq_prod`, then classifies each factor of +the resulting product: the single middle factor is the controlled-`U₀` itself, and every swap is a +transposition of the Gray-code swap chain — shown bit-adjacent (hence a controlled-`NOT`, +`isCtrlSingleQubit_swap`) by feeding `grayCode_isChain` to `rel_of_mem_swapChain`. This is the +§4.5.2 conclusion "a two-level unitary is built entirely from controlled single-qubit gates", +delivered as a concrete gate list — the structural input to Exercise 4.43's `n`-qubit lift. -/ +theorem twoLevelUnitary_isProd_ctrlSingleQubit {m d : ℕ} (enc : (Fin m → Fin 2) ≃ Fin d) + {s t : Fin m → Fin 2} (hst : s ≠ t) {U : Matrix (Fin d) (Fin d) ℂ} + (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ enc s ∧ i ≠ enc t) ∨ (j ≠ enc s ∧ j ≠ enc t) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsCtrlSingleQubit enc g) ∧ U = gates.prod := by + obtain ⟨j, c, U₀, hU₀, hUeq⟩ := + twoLevelUnitary_eq_swapConj_ctrlSingleQubit enc hst hunit hsupp + set gpath := (grayCode s t).dropLast.map enc with hgpath + set chainRev := (swapChain gpath).reverse with hchainRev + refine ⟨(chainRev.map fun pq => Matrix.swap ℂ pq.1 pq.2) + ++ ctrlSingleQubit enc j c U₀ :: chainRev.reverse.map fun pq => Matrix.swap ℂ pq.1 pq.2, + ?_, ?_⟩ + · -- Every gate in the list is a controlled single-qubit gate. + -- Consecutive coordinates of the encoded Gray path differ in exactly one bit. + have hchain : List.IsChain (fun p q => differsInOneBit (enc.symm p) (enc.symm q)) gpath := by + rw [hgpath] + refine List.isChain_map_of_isChain enc ?_ ((grayCode_isChain s t).dropLast) + intro a b hab + simpa only [Equiv.symm_apply_apply] using hab + -- Hence every transposition of the Gray swap chain is a controlled-`NOT`. + have hswap : ∀ pq ∈ swapChain gpath, IsCtrlSingleQubit enc (Matrix.swap ℂ pq.1 pq.2) := by + intro pq hpq + have hrel := rel_of_mem_swapChain hchain pq hpq + have := isCtrlSingleQubit_swap enc hrel + rwa [enc.apply_symm_apply, enc.apply_symm_apply] at this + intro g hg + rw [List.mem_append] at hg + rcases hg with hg | hg + · rw [List.mem_map] at hg + obtain ⟨pq, hpq, rfl⟩ := hg + rw [hchainRev, List.mem_reverse] at hpq + exact hswap pq hpq + · rw [List.mem_cons] at hg + rcases hg with rfl | hg + · exact ⟨j, c, U₀, hU₀, rfl⟩ + · rw [List.mem_map] at hg + obtain ⟨pq, hpq, rfl⟩ := hg + rw [List.mem_reverse, hchainRev, List.mem_reverse] at hpq + exact hswap pq hpq + · -- The product equals `U`. + rw [hUeq, swapConj_eq_prod] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelDecomposition.lean b/LeanPool/AxQM/Concrete/TwoLevelDecomposition.lean new file mode 100644 index 0000000000..607f308cdf --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelDecomposition.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.BlockDiagonalPeel +public import LeanPool.AxQM.Concrete.TwoLevelColumnClear + +/-! +# Concrete: every `d × d` unitary is a product of two-level unitaries (N&C §4.5.1 headline) + +Nielsen & Chuang §4.5.1 (p. 189–191) proves that **an arbitrary `d × d` unitary matrix `U` can be +written as a product of two-level unitaries** — the structural fact that reduces universality to the +single-qubit + `CNOT` case. This file assembles that result from the lemmas +proved in the files it imports, by an induction on the dimension. + +## The induction (N&C eqs. 4.44–4.51) + +The statement is `exists_twoLevelUnitaryList_prod_eq`: for every unitary `U` there is a list `L` of +two-level unitaries with `L.prod = U`. Induction on `d`: + +* **`d = 0`.** `Matrix (Fin 0) (Fin 0) ℂ` is a subsingleton, so `U = 1 = [].prod`; the empty list + works. +* **`d + 1`.** Three steps, each already available: + 1. **Column-clear** (`exists_twoLevelUnitaryList_clear_first_column`): a list `L₀` of two-level + unitaries with `W := L₀.prod * U` having its first column a multiple of `e₀`. `L₀.prod` is + unitary (a product of unitaries, `list_prod_mem`), hence so is `W`. + 2. **Block-diagonal peel** (`exists_phaseShift_mul_blockOne_of_clearFirstColumn`): unitarity turns + the cleared first column into `W = phaseShift c * blockOne C` with `|c| = 1` and `C` a `d × d` + unitary corner. + 3. **Recurse** on `C`: the induction hypothesis gives `C = M.prod` for a two-level list `M`. Since + `blockOne` is a homomorphism (`prod_map_blockOne`), `blockOne C = (M.map blockOne).prod`, each + factor two-level (`isTwoLevelUnitary_blockOne`); with `phaseShift c` two-level + (`isTwoLevelUnitary_phaseShift`) this exhibits `W` as a product of two-level unitaries. + + Finally `U = (L₀.prod)ᴴ * W`: prepending the *reversed conjugate transposes* of `L₀` — + `(L₀.map conjTranspose).reverse`, whose product is `(L₀.prod)ᴴ` by + `Matrix.conjTranspose_list_prod` and each of whose entries `Wᴴ` is again a two-level unitary + (`IsTwoLevelUnitary.conjTranspose`) — + cancels `L₀.prod` (`(L₀.prod)ᴴ * L₀.prod = 1`, unitarity), leaving `U`. No matrix inverse is + needed: the conjugate transpose *is* the inverse of a unitary, and it is again two-level, so the + whole assembled list stays inside the two-level class. + +Two small reusable lemmas support the assembly: + +* `IsTwoLevelUnitary.conjTranspose` — the conjugate transpose of a two-level unitary is a two-level + unitary (same distinguished pair `{p, q}`). +* `prod_map_blockOne` — `blockOne` carries a list product to the product of the embedded factors, + `(L.map blockOne).prod = blockOne L.prod` (the list form of the `blockOne_one`/`blockOne_mul` + homomorphism laws). + +## Use + +This is the shared §4.5.1 result used across the two-level items (Ex 4.37/4.38 and +Exercise 4.43's `n`-qubit lift); the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). + +## Not formalised here + +This completes N&C §4.5.1. The remaining Exercise 4.43 work is the **`n`-qubit lift**: each +two-level unitary is realised by `CNOT` + single-qubit gates (Exercise 4.39), the single-qubit gates +are approximable by the reachable set (`exists_phase_smul_mem_closure_reachableRotations`, already +in the library), and together with `CNOT` this gives universality on any number of qubits. The +top-level `n`-qubit universality statement — the item's headline theorem — is not formalised here. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **The conjugate transpose of a two-level unitary is a two-level unitary**, with the same +distinguished pair `{p, q}`. Unitarity of `Uᴴ` is closure of the unitary group under `ᴴ`; the +off-`{p,q}` entries of `Uᴴ` are the conjugated off-`{p,q}` entries of `U` (with `(i,j)` reading +`U`'s `(j,i)`), which agree with the (real, symmetric) identity. Used to invert the column-clearing +factors while staying inside the two-level class. -/ +theorem IsTwoLevelUnitary.conjTranspose {U : Matrix (Fin d) (Fin d) ℂ} + (hU : IsTwoLevelUnitary U) : IsTwoLevelUnitary Uᴴ := by + obtain ⟨hunit, p, q, hpq⟩ := hU + refine ⟨?_, p, q, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose, + Matrix.conjTranspose_conjTranspose, ← Matrix.star_eq_conjTranspose] + exact Matrix.mem_unitaryGroup_iff.mp hunit + · intro i j h + rw [Matrix.conjTranspose_apply, hpq j i h.symm, Matrix.one_apply, Matrix.one_apply] + by_cases hij : j = i + · subst hij; simp + · rw [ite_eq_right hij, ite_eq_right (Ne.symm hij), star_zero] + +/-- **`blockOne` carries a list product to the product of the embedded factors**: +`(L.map blockOne).prod = blockOne L.prod`. The list form of the `blockOne_one`/`blockOne_mul` +homomorphism laws, letting the inductive step embed the corner's decomposition +`C = M.prod` as `blockOne C = (M.map blockOne).prod`. -/ +theorem prod_map_blockOne (M : List (Matrix (Fin d) (Fin d) ℂ)) : + (M.map blockOne).prod = blockOne M.prod := by + induction M with + | nil => simp [blockOne_one] + | cons a M ih => simp only [List.map_cons, List.prod_cons, ih, blockOne_mul] + +/-- **Every `d × d` unitary is a product of two-level unitaries (Nielsen & Chuang §4.5.1).** For any +`U ∈ U(d)` there is a list `L` of two-level unitaries with `L.prod = U`. Proved by induction on `d`: +column-clearing (`exists_twoLevelUnitaryList_clear_first_column`) then the block-diagonal peel +(`exists_phaseShift_mul_blockOne_of_clearFirstColumn`) reduces `U` to a `phaseShift` factor times a +`blockOne` of a `d × d` corner unitary, whose decomposition the induction hypothesis supplies; the +column-clearing factors are undone by their conjugate transposes (`IsTwoLevelUnitary.conjTranspose`, +`Matrix.conjTranspose_list_prod`), which are themselves two-level. This is the structural input to +the §4.5.2 reduction of universality to single-qubit gates and `CNOT`. -/ +theorem exists_twoLevelUnitaryList_prod_eq {d : ℕ} (U : Matrix (Fin d) (Fin d) ℂ) + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + ∃ L : List (Matrix (Fin d) (Fin d) ℂ), + (∀ V ∈ L, IsTwoLevelUnitary V) ∧ L.prod = U := by + induction d with + | zero => exact ⟨[], by simp, by ext i; exact i.elim0⟩ + | succ d ih => + obtain ⟨L₀, hL₀, hcol⟩ := exists_twoLevelUnitaryList_clear_first_column U + have hL₀prod : L₀.prod ∈ Matrix.unitaryGroup (Fin (d + 1)) ℂ := + list_prod_mem (fun M hM => (hL₀ M hM).1) + have hWunit : (L₀.prod * U) ∈ Matrix.unitaryGroup (Fin (d + 1)) ℂ := mul_mem hL₀prod hU + obtain ⟨c, C, hc, hCunit, hWeq⟩ := + exists_phaseShift_mul_blockOne_of_clearFirstColumn hWunit hcol + obtain ⟨M, hM, hMprod⟩ := ih C hCunit + refine ⟨(L₀.map Matrix.conjTranspose).reverse ++ (phaseShift c :: M.map blockOne), ?_, ?_⟩ + · -- every factor is a two-level unitary + intro V hV + rcases List.mem_append.mp hV with hV | hV + · -- the undoing factors `Wᴴ` for `W ∈ L₀` + rw [List.mem_reverse, List.mem_map] at hV + obtain ⟨W, hWL₀, rfl⟩ := hV + exact (hL₀ W hWL₀).conjTranspose + · rcases List.mem_cons.mp hV with hV | hV + · exact hV ▸ isTwoLevelUnitary_phaseShift hc + · -- the embedded corner factors `blockOne N` for `N ∈ M` + rw [List.mem_map] at hV + obtain ⟨N, hNM, rfl⟩ := hV + exact isTwoLevelUnitary_blockOne (hM N hNM) + · -- the product telescopes to `U` + rw [List.prod_append, ← Matrix.conjTranspose_list_prod, List.prod_cons, prod_map_blockOne, + hMprod, ← hWeq, ← Matrix.mul_assoc] + have h1 : (L₀.prod)ᴴ * L₀.prod = 1 := by + rw [← Matrix.star_eq_conjTranspose]; exact Matrix.mem_unitaryGroup_iff'.mp hL₀prod + rw [h1, Matrix.one_mul] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelEmbedding.lean b/LeanPool/AxQM/Concrete/TwoLevelEmbedding.lean new file mode 100644 index 0000000000..0065469c6e --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelEmbedding.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QFTTwoLevel + +/-! +# Concrete: embedding a 2×2 unitary into a coordinate pair of a `d × d` matrix (N&C §4.5.1) + +The two-level decomposition of an arbitrary `d × d` unitary (Nielsen & Chuang §4.5.1, p. 189) is +built from *two-level* unitaries, each of which is a single `2 × 2` unitary block placed into a +chosen coordinate pair `{p, q}` and acting as the identity everywhere else. This file provides that +general **embedding** `twoLevelEmbed p q G`, independently of the particular `2 × 2` +block chosen (the Givens rotation of `AxQM.Concrete.GivensRotation` is one such block) and +of the column-clearing induction (`Concrete/TwoLevelDecomposition.lean`). + +## The construction and its algebra + +`twoLevelEmbed p q G` is the `d × d` matrix whose `{p, q} × {p, q}` principal submatrix is `G` and +whose remaining entries are those of the identity. The key structural fact is that, for `p ≠ q`, +`twoLevelEmbed p q` is a **`*`-homomorphism on the `2 × 2` block**: + +* `twoLevelEmbed_one` — it sends `1 ↦ 1`; +* `twoLevelEmbed_mul` — it is multiplicative, `embed A * embed B = embed (A * B)`; +* `twoLevelEmbed_conjTranspose` — it commutes with `ᴴ`, `(embed G)ᴴ = embed Gᴴ`. + +Unitarity then needs no direct sum manipulation: `(embed G)ᴴ * embed G = embed Gᴴ * embed G = +embed (Gᴴ * G) = embed 1 = 1`. So a unitary `G` embeds to a two-level unitary +(`isTwoLevelUnitary_twoLevelEmbed`), with `{p, q}` as its distinguished block. The action on a +vector (`twoLevelEmbed_mulVec`) mixes only the `p`- and `q`-components via `G`, fixing the rest — +the form the column-clearing step consumes. + +## Use + +This is a shared building block for the §4.5.1 development (Exercise 4.43's `n`-qubit lift, also +used by Ex 4.37/4.38/4.39); the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **The two-level embedding.** `twoLevelEmbed p q G` places the `2 × 2` matrix `G` into the +`{p, q} × {p, q}` block of a `d × d` matrix (`p ↦ 0`, `q ↦ 1`) and is the identity on all other +entries. -/ +def twoLevelEmbed (p q : Fin d) (G : Matrix (Fin 2) (Fin 2) ℂ) : Matrix (Fin d) (Fin d) ℂ := + Matrix.of fun i j => + if i = p then (if j = p then G 0 0 else if j = q then G 0 1 else 0) + else if i = q then (if j = p then G 1 0 else if j = q then G 1 1 else 0) + else if i = j then 1 else 0 + +/-- Unfolding lemma for `twoLevelEmbed` entries. -/ +theorem twoLevelEmbed_apply (p q : Fin d) (G : Matrix (Fin 2) (Fin 2) ℂ) (i j : Fin d) : + twoLevelEmbed p q G i j = + if i = p then (if j = p then G 0 0 else if j = q then G 0 1 else 0) + else if i = q then (if j = p then G 1 0 else if j = q then G 1 1 else 0) + else if i = j then 1 else 0 := rfl + +variable {p q : Fin d} {G A B : Matrix (Fin 2) (Fin 2) ℂ} + +/-- The embedding of the `2 × 2` identity is the `d × d` identity. -/ +theorem twoLevelEmbed_one (h : p ≠ q) : + twoLevelEmbed p q (1 : Matrix (Fin 2) (Fin 2) ℂ) = 1 := by + ext i j + rw [twoLevelEmbed_apply] + simp only [Matrix.one_apply] + split_ifs <;> simp_all + +/-- **`twoLevelEmbed p q` is multiplicative on the block** (`p ≠ q`): embedding respects matrix +products. This is the structural core making an embedded unitary two-level unitary. -/ +theorem twoLevelEmbed_mul (h : p ≠ q) (A B : Matrix (Fin 2) (Fin 2) ℂ) : + twoLevelEmbed p q A * twoLevelEmbed p q B = twoLevelEmbed p q (A * B) := by + ext i j + rw [Matrix.mul_apply] + by_cases hip : i = p + · rw [Finset.sum_eq_add p q h + (fun c _ hc => by simp [twoLevelEmbed_apply, hip, hc.1, hc.2]) (by simp) (by simp)] + by_cases hjp : j = p <;> by_cases hjq : j = q <;> + simp [twoLevelEmbed_apply, hip, hjp, hjq, Ne.symm h, Matrix.mul_apply, + Fin.sum_univ_two] + · by_cases hiq : i = q + · rw [Finset.sum_eq_add p q h + (fun c _ hc => by simp [twoLevelEmbed_apply, hiq, hc.1, hc.2]) (by simp) (by simp)] + by_cases hjp : j = p <;> by_cases hjq : j = q <;> + simp [twoLevelEmbed_apply, hiq, hjp, hjq, Ne.symm h, Matrix.mul_apply, + Fin.sum_univ_two] + · rw [Finset.sum_eq_single i + (fun c _ hc => by simp [twoLevelEmbed_apply, hip, hiq, Ne.symm hc]) (by simp)] + simp [twoLevelEmbed_apply, hip, hiq] + +/-- **`twoLevelEmbed p q` commutes with the conjugate transpose**: +`(embed G)ᴴ = embed Gᴴ`. The block `ᴴ` is `G`'s, the identity part is real. -/ +theorem twoLevelEmbed_conjTranspose (G : Matrix (Fin 2) (Fin 2) ℂ) : + (twoLevelEmbed p q G)ᴴ = twoLevelEmbed p q Gᴴ := by + ext i j + rw [Matrix.conjTranspose_apply, twoLevelEmbed_apply, twoLevelEmbed_apply] + simp only [Matrix.conjTranspose_apply] + split_ifs <;> simp <;> simp_all + +/-- **An embedded `2 × 2` unitary is a two-level unitary** (`p ≠ q`), with `{p, q}` its +distinguished block. The unitarity follows from the `*`-homomorphism laws above: +`(embed G)ᴴ · embed G = embed (Gᴴ · G) = embed 1 = 1`. -/ +theorem isTwoLevelUnitary_twoLevelEmbed (h : p ≠ q) + (hG : G ∈ Matrix.unitaryGroup (Fin 2) ℂ) : IsTwoLevelUnitary (twoLevelEmbed p q G) := by + refine ⟨?_, p, q, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff'] at hG ⊢ + rw [Matrix.star_eq_conjTranspose] at hG ⊢ + rw [twoLevelEmbed_conjTranspose, twoLevelEmbed_mul h, hG, twoLevelEmbed_one h] + · intro i j hij + rw [twoLevelEmbed_apply, Matrix.one_apply] + rcases hij with ⟨hip, hiq⟩ | ⟨hjp, hjq⟩ <;> split_ifs <;> simp_all + +/-- **The action of an embedded block on a vector** (`p ≠ q`): `twoLevelEmbed p q G` mixes only the +`p`- and `q`-components of `v` through `G`, leaving every other component fixed. This is the form +consumed by the column-clearing step of §4.5.1. -/ +theorem twoLevelEmbed_mulVec (h : p ≠ q) (G : Matrix (Fin 2) (Fin 2) ℂ) (v : Fin d → ℂ) + (i : Fin d) : + (twoLevelEmbed p q G *ᵥ v) i = + if i = p then G 0 0 * v p + G 0 1 * v q + else if i = q then G 1 0 * v p + G 1 1 * v q + else v i := by + simp only [Matrix.mulVec, dotProduct] + by_cases hip : i = p + · rw [Finset.sum_eq_add p q h + (fun c _ hc => by simp [twoLevelEmbed_apply, hip, hc.1, hc.2]) (by simp) (by simp)] + simp [twoLevelEmbed_apply, hip, Ne.symm h] + · by_cases hiq : i = q + · rw [Finset.sum_eq_add p q h + (fun c _ hc => by simp [twoLevelEmbed_apply, hiq, hc.1, hc.2]) (by simp) (by simp)] + simp [twoLevelEmbed_apply, hiq, Ne.symm h] + · rw [Finset.sum_eq_single i + (fun c _ hc => by simp [twoLevelEmbed_apply, hip, hiq, Ne.symm hc]) (by simp)] + simp [twoLevelEmbed_apply, hip, hiq] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelGrayWalk.lean b/LeanPool/AxQM/Concrete/TwoLevelGrayWalk.lean new file mode 100644 index 0000000000..c57dc5f8a0 --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelGrayWalk.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelSwapChain +public import LeanPool.AxQM.Concrete.GrayCode + +/-! +# Concrete: the Gray-code swap chain relocates a two-level unitary onto a bit-adjacent pair + +(Nielsen & Chuang §4.5.2, first stage.) + +Nielsen & Chuang §4.5.2 (p. 191–193) realises a two-level unitary `U` on `n` qubits — one acting +non-trivially only on the two computational basis states `|s⟩` and `|t⟩` (`s ≠ t` two distinct +`n`-bit strings) — as a circuit of single-qubit and `CNOT` gates. The first stage *walks a Gray +code* `g₁ = s, g₂, …, g_m = t` from `s` to `t`: a sequence of basis-state swaps +`|g₁⟩ ↔ |g₂⟩, …, |g_{m-2}⟩ ↔ |g_{m-1}⟩` moves the two active states of `U` from `{s, t}` to +`{g_{m-1}, t}`, **two basis states differing in exactly one bit** (adjacent Gray-code words), at +which point the two-level unitary is a *controlled single-qubit gate* ready for the controlled-`U₀` +step; the swaps are then undone. + +This file assembles that first stage into a single statement, joining the two halves already in the +library: + +* the **matrix engine** `swapConj_swapChain_support` (`Concrete/TwoLevelSwapChain.lean`) — + conjugating a two-level unitary with support `{s', w'}` by the swap chain of a path with head + `s'`, last entry `e'`, and `w'` off the path relocates the support to `{e', w'}`, *at the raw + `Fin d` index level*; +* the **combinatorial input** from `Concrete/GrayCode.lean` — for the path + `(grayCode s t).dropLast = [g₁, …, g_{m-1}]`: its head is `s` (`grayCode_dropLast_head?`), its + last entry is bit-adjacent to + `t` (`grayCode_dropLast_getLast?_differsInOneBit`), and `t` lies off it + (`grayCode_getLast_not_mem_dropLast`). + +The bridge is any encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the `m`-bit strings as the +`d = 2 ^ m` computational-basis indices (e.g. `finFunctionFinEquiv`); pushing the Gray-code path +through it turns +the bit-string combinatorics into a `Fin d` path the swap-chain engine consumes. The result, +`swapConj_swapChain_grayCode_support`, is the §4.5.2 first-stage milestone: *conjugating a two-level +unitary supported on `{s, t}` by the Gray-code swap chain yields a two-level unitary supported on a +pair of basis states differing in a single bit.* + +## Use + +This is the shared §4.5.2 first-stage assembly used by Exercise 4.43's `n`-qubit lift; the +statement of Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **The Gray-code swap chain relocates a two-level unitary's active pair onto two basis states +differing in a single bit** — Nielsen & Chuang §4.5.2's first stage (eqs. 4.54–4.57), assembled. + +Fix an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of `m`-bit strings as the `d = 2 ^ m` computational +basis indices. If `U` is unitary and acts non-trivially only on the two basis states +`{enc s, enc t}` for distinct bit-strings `s ≠ t`, then conjugating `U` by the swap chain of the +Gray-code path `(grayCode s t).dropLast` (mapped into `Fin d` by `enc`) is again unitary and acts +non-trivially only on `{enc e, enc t}` for some bit-string `e` with `differsInOneBit e t` — i.e. the +relocated active pair `{enc e, enc t}` differs in **exactly one bit**, the form of a *controlled +single-qubit gate*. + +The proof reads the three path facts (`grayCode_dropLast_head?`, +`grayCode_dropLast_getLast?_differsInOneBit`, `grayCode_getLast_not_mem_dropLast`) into the +`enc`-image of the path via `List.head?_map` / `List.getLast?_map` / `List.mem_map` and injectivity +of `enc`, then feeds them to the matrix engine `swapConj_swapChain_support`. -/ +theorem swapConj_swapChain_grayCode_support {m d : ℕ} (enc : (Fin m → Fin 2) ≃ Fin d) + {s t : Fin m → Fin 2} (hst : s ≠ t) {U : Matrix (Fin d) (Fin d) ℂ} + (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ enc s ∧ i ≠ enc t) ∨ (j ≠ enc s ∧ j ≠ enc t) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + ∃ e : Fin m → Fin 2, differsInOneBit e t ∧ + swapConj (swapChain ((grayCode s t).dropLast.map enc)) U ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + ∀ i j : Fin d, (i ≠ enc e ∧ i ≠ enc t) ∨ (j ≠ enc e ∧ j ≠ enc t) → + swapConj (swapChain ((grayCode s t).dropLast.map enc)) U i j + = (1 : Matrix (Fin d) (Fin d) ℂ) i j := by + obtain ⟨e, he, hdiff⟩ := grayCode_dropLast_getLast?_differsInOneBit s t hst + refine ⟨e, hdiff, ?_⟩ + have hhead : ((grayCode s t).dropLast.map enc).head? = some (enc s) := by + rw [List.head?_map, grayCode_dropLast_head? s t hst]; rfl + have hlast : ((grayCode s t).dropLast.map enc).getLast? = some (enc e) := by + rw [List.getLast?_map, he]; rfl + have hnotmem : enc t ∉ (grayCode s t).dropLast.map enc := by + rw [List.mem_map] + rintro ⟨x, hx, hxe⟩ + exact grayCode_getLast_not_mem_dropLast s t (by rwa [enc.injective hxe] at hx) + exact swapConj_swapChain_support hhead hlast hnotmem hunit hsupp + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelSwap.lean b/LeanPool/AxQM/Concrete/TwoLevelSwap.lean new file mode 100644 index 0000000000..ee87d22495 --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelSwap.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.QFTTwoLevel +public import Mathlib.LinearAlgebra.Matrix.Swap + +/-! +# Concrete: the basis-transposition swap as a two-level unitary (N&C §4.5.2) + +Nielsen & Chuang §4.5.2 (p. 191–193) realises an arbitrary two-level unitary on `n` qubits — one +acting non-trivially only on the two computational basis states `|s⟩` and `|t⟩` — as a circuit of +single-qubit and `CNOT` gates by *walking a Gray code* from `s` to `t`. Each one-bit step of the +code is a **swap** of two neighbouring basis states, performed by a (multiply-)controlled bit flip; +the swaps shuffle `|s⟩` next to `|t⟩`, a single controlled-`U₀` acts, and the swaps are undone. + +This file supplies the matrix-level engine of that swap stage: at the level of `d × d` complex +matrices, "swap the basis states `|p⟩` and `|q⟩`" is the **basis transposition** permutation matrix +`Matrix.swap ℂ p q`, and each Gray-code step conjugates the two-level unitary by one such swap. We +prove the two facts §4.5.2 uses: + +* `isTwoLevelUnitary_swap` — the basis transposition `Matrix.swap ℂ p q` is itself a two-level + unitary (it acts non-trivially only on `{p, q}`); it is the elementary swap the Gray-code walk is + built from. +* `IsTwoLevelUnitary.swap_conj` — **conjugation by a basis transposition relocates the support**: + if `U` is a two-level unitary with distinguished pair `{a, b}`, then + `Matrix.swap ℂ p q * U * Matrix.swap ℂ p q` is again a two-level unitary, now with pair + `{swap p q a, swap p q b}`. Iterating this along a Gray code moves the two active states + until they differ in a single bit — the point at which the two-level unitary is a plain + controlled single-qubit gate. + +The workhorse is the entry-reindex identity `swap_conj_apply`: +`(Matrix.swap ℂ p q * U * Matrix.swap ℂ p q) i j = U (Equiv.swap p q i) (Equiv.swap p q j)`, i.e. +conjugation by the transposition permutes both the row and column indices by `Equiv.swap p q`. It is +derived from the one-sided reindex identities `swap_mul_apply_eq` / `mul_swap_apply_eq`, which +package Mathlib's pointwise `Matrix.swap_mul_apply_*` / `Matrix.mul_swap_apply_*` lemmas into a +single "multiply by a swap ↦ reindex by `Equiv.swap`" statement. + +## Use + +This is the shared swap lemma of the §4.5.2 two-level → single-qubit + `CNOT` reduction used by +Exercise 4.43's `n`-qubit lift; the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **Left multiplication by a basis transposition reindexes the rows.** For any `d × d` matrix `A`, +`(Matrix.swap ℂ p q * A) a b = A (Equiv.swap p q a) b`: multiplying on the left by the transposition +of `p` and `q` permutes the row index by `Equiv.swap p q`. Packages the pointwise +`Matrix.swap_mul_apply_left/right/of_ne` lemmas into one reindex identity. -/ +theorem swap_mul_apply_eq (A : Matrix (Fin d) (Fin d) ℂ) (p q a b : Fin d) : + (Matrix.swap ℂ p q * A) a b = A (Equiv.swap p q a) b := by + by_cases hap : a = p + · subst hap; rw [Matrix.swap_mul_apply_left, Equiv.swap_apply_left] + · by_cases haq : a = q + · subst haq; rw [Matrix.swap_mul_apply_right, Equiv.swap_apply_right] + · rw [Matrix.swap_mul_of_ne hap haq, Equiv.swap_apply_of_ne_of_ne hap haq] + +/-- **Right multiplication by a basis transposition reindexes the columns.** For any `d × d` matrix +`A`, `(A * Matrix.swap ℂ p q) a b = A a (Equiv.swap p q b)`: multiplying on the right by the +transposition of `p` and `q` permutes the column index by `Equiv.swap p q`. Packages the pointwise +`Matrix.mul_swap_apply_left/right/of_ne` lemmas into one reindex identity. -/ +theorem mul_swap_apply_eq (A : Matrix (Fin d) (Fin d) ℂ) (p q a b : Fin d) : + (A * Matrix.swap ℂ p q) a b = A a (Equiv.swap p q b) := by + by_cases hbp : b = p + · subst hbp; rw [Matrix.mul_swap_apply_left, Equiv.swap_apply_left] + · by_cases hbq : b = q + · subst hbq; rw [Matrix.mul_swap_apply_right, Equiv.swap_apply_right] + · rw [Matrix.mul_swap_of_ne hbp hbq, Equiv.swap_apply_of_ne_of_ne hbp hbq] + +/-- Entry of a basis transposition, reindexed by rows: `Matrix.swap ℂ p q i j = 1 (swap p q i) j`. +The transposition matrix is the identity with its rows permuted by `Equiv.swap p q`. -/ +theorem swap_apply_eq_one_row (p q i j : Fin d) : + Matrix.swap ℂ p q i j = (1 : Matrix (Fin d) (Fin d) ℂ) (Equiv.swap p q i) j := by + conv_lhs => rw [← Matrix.mul_one (Matrix.swap ℂ p q)] + rw [swap_mul_apply_eq] + +/-- Entry of a basis transposition, reindexed by columns: +`Matrix.swap ℂ p q i j = 1 i (swap p q j)`. The transposition matrix is the identity with its +columns permuted by `Equiv.swap p q`. -/ +theorem swap_apply_eq_one_col (p q i j : Fin d) : + Matrix.swap ℂ p q i j = (1 : Matrix (Fin d) (Fin d) ℂ) i (Equiv.swap p q j) := by + conv_lhs => rw [← Matrix.one_mul (Matrix.swap ℂ p q)] + rw [mul_swap_apply_eq] + +/-- **The basis transposition `Matrix.swap ℂ p q` is a two-level unitary.** It is unitary — being a +self-inverse (`Matrix.swap_mul_self`), self-adjoint (`Matrix.conjTranspose_swap`) permutation +matrix — and it acts non-trivially only on the two basis states `{p, q}`: outside the +`{p,q} × {p,q}` block it agrees with the identity. This is the elementary swap the §4.5.2 Gray-code +walk is built from (the `p = q` case is the identity, still two-level). -/ +theorem isTwoLevelUnitary_swap (p q : Fin d) : IsTwoLevelUnitary (Matrix.swap ℂ p q) := by + refine ⟨?_, p, q, ?_⟩ + · rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose, Matrix.conjTranspose_swap] + exact Matrix.swap_mul_self p q + · intro i j h + rcases h with ⟨hip, hiq⟩ | ⟨hjp, hjq⟩ + · rw [swap_apply_eq_one_row, Equiv.swap_apply_of_ne_of_ne hip hiq] + · rw [swap_apply_eq_one_col, Equiv.swap_apply_of_ne_of_ne hjp hjq] + +/-- **Conjugating by a basis transposition reindexes both indices.** +`(Matrix.swap ℂ p q * U * Matrix.swap ℂ p q) i j = U (Equiv.swap p q i) (Equiv.swap p q j)`: the +transposition permutes the row and column indices of `U` by `Equiv.swap p q`. This is the matrix +identity behind "swap the basis states `|p⟩` and `|q⟩`" in the §4.5.2 circuit. -/ +theorem swap_conj_apply (U : Matrix (Fin d) (Fin d) ℂ) (p q i j : Fin d) : + (Matrix.swap ℂ p q * U * Matrix.swap ℂ p q) i j + = U (Equiv.swap p q i) (Equiv.swap p q j) := by + rw [mul_swap_apply_eq, swap_mul_apply_eq] + +/-- **Conjugation by a basis transposition relocates the support — with explicit witnesses.** If `U` +is unitary and acts non-trivially only on the two basis states `{a, b}` (its entries outside the +`{a,b} × {a,b}` block agree with the identity), then `Matrix.swap ℂ p q * U * Matrix.swap ℂ p q` is +unitary and acts non-trivially only on `{Equiv.swap p q a, Equiv.swap p q b}` — the images of `a` +and `b` under the transposition. This is the explicit-support form of the swap-reduction step: the +distinguished pair is named, not merely existentially quantified. `IsTwoLevelUnitary.swap_conj` is +its existential repackaging, and folding it along a list gives +`AxQM.Concrete.swapConj_unitary_support`. -/ +theorem swap_conj_support {U : Matrix (Fin d) (Fin d) ℂ} {a b : Fin d} + (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ a ∧ i ≠ b) ∨ (j ≠ a ∧ j ≠ b) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) (p q : Fin d) : + Matrix.swap ℂ p q * U * Matrix.swap ℂ p q ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + ∀ i j : Fin d, + (i ≠ Equiv.swap p q a ∧ i ≠ Equiv.swap p q b) ∨ + (j ≠ Equiv.swap p q a ∧ j ≠ Equiv.swap p q b) → + (Matrix.swap ℂ p q * U * Matrix.swap ℂ p q) i j + = (1 : Matrix (Fin d) (Fin d) ℂ) i j := by + refine ⟨mul_mem (mul_mem (isTwoLevelUnitary_swap p q).1 hunit) + (isTwoLevelUnitary_swap p q).1, ?_⟩ + -- `x ≠ swap p q y ↔ swap p q x ≠ y`, the negation of Mathlib's `Equiv.swap_apply_eq_iff`. + have hconv : ∀ x y : Fin d, x ≠ Equiv.swap p q y ↔ Equiv.swap p q x ≠ y := + fun _ _ => not_congr Equiv.swap_apply_eq_iff.symm + intro i j h + rw [swap_conj_apply, hsupp _ _ ?_] + · simp only [Matrix.one_apply, Equiv.apply_eq_iff_eq] + · rcases h with ⟨hia, hib⟩ | ⟨hja, hjb⟩ + · exact Or.inl ⟨(hconv i a).mp hia, (hconv i b).mp hib⟩ + · exact Or.inr ⟨(hconv j a).mp hja, (hconv j b).mp hjb⟩ + +/-- **Conjugation by a basis transposition relocates the support of a two-level unitary.** If `U` is +a two-level unitary with distinguished pair `{a, b}`, then +`Matrix.swap ℂ p q * U * Matrix.swap ℂ p q` is again a two-level unitary, with distinguished pair +`{Equiv.swap p q a, Equiv.swap p q b}`. Walking +a Gray code — conjugating by one such swap per one-bit step — moves the two active basis states of a +two-level unitary until they differ in a single bit, at which point it is a controlled single-qubit +gate. This is the §4.5.2 swap-reduction step at the matrix level, the existential repackaging of +`swap_conj_support`. -/ +theorem IsTwoLevelUnitary.swap_conj {U : Matrix (Fin d) (Fin d) ℂ} + (hU : IsTwoLevelUnitary U) (p q : Fin d) : + IsTwoLevelUnitary (Matrix.swap ℂ p q * U * Matrix.swap ℂ p q) := by + obtain ⟨hunit, a, b, hab⟩ := hU + obtain ⟨hu, hs⟩ := swap_conj_support hunit hab p q + exact ⟨hu, Equiv.swap p q a, Equiv.swap p q b, hs⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelSwapChain.lean b/LeanPool/AxQM/Concrete/TwoLevelSwapChain.lean new file mode 100644 index 0000000000..df4754415e --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelSwapChain.lean @@ -0,0 +1,153 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelSwapList + +/-! +# Concrete: the swap chain of a basis-state path (N&C §4.5.2, eqs. 4.54–4.57) + +Nielsen & Chuang §4.5.2 (p. 191–193) realises a two-level unitary `U` on `n` qubits — one acting +non-trivially only on the computational basis states `|s⟩` and `|t⟩` — by *walking a Gray code* +`g₁ = s, g₂, …, g_m = t`. The first stage performs a sequence of `m − 2` basis-state swaps, +`|g₁⟩ ↔ |g₂⟩`, `|g₂⟩ ↔ |g₃⟩`, …, `|g_{m-2}⟩ ↔ |g_{m-1}⟩`, whose net effect (N&C eqs. 4.54–4.57) is + +``` +|g₁⟩ → |g_{m-1}⟩, |g₂⟩ → |g₁⟩, |g₃⟩ → |g₂⟩, …, |g_{m-1}⟩ → |g_{m-2}⟩, +``` + +**all other computational basis states left unchanged** — in particular `|g_m⟩ = |t⟩` is fixed. The +two active basis states of `U` are thereby moved from `{g₁, g_m} = {s, t}` to `{g_{m-1}, g_m}`, +which differ in exactly one bit (adjacent Gray-code words); there the two-level unitary is a +*controlled* +single-qubit gate, ready for the controlled-`U₀` step. The swaps are then undone. + +This file provides the **combinatorial engine of that first stage**, at the raw-matrix / index- +permutation level — the transposition list read off a path of basis indices, and the two facts that +pin down its permutation action on the endpoints: + +* `swapChain path` — the list of transpositions `[(g_{m-2}, g_{m-1}), …, (g₂, g₃), (g₁, g₂)]` read + off a path `path = [g₁, …, g_{m-1}]` of basis indices, ordered so that (via `swapPerm`, head + outermost) the swap `|g₁⟩ ↔ |g₂⟩` is applied *first* and `|g_{m-2}⟩ ↔ |g_{m-1}⟩` *last*. +* `swapPerm_swapChain_eq` — the permutation carries the path's **head to its last element** + (`swapPerm (swapChain path) s = e` when `path.head? = some s`, `path.getLast? = some e`): this is + N&C eq. 4.54, `|g₁⟩ → |g_{m-1}⟩`. +* `swapPerm_swapChain_apply_of_not_mem` — it **fixes every index off the path** + (`swapPerm (swapChain path) w = w` for `w ∉ path`): the "all other states unchanged" clause, whose + consequence for `w = g_m = t` is that `|t⟩` is fixed. +* `swapConj_swapChain_support` — **the headline**: conjugating a unitary `U` with two-level support + `{s, w}` (here `s = g₁` is the path head, `w = g_m = t` lies off the path) by `swapChain path` + yields a unitary with support `{e, w}` where `e = g_{m-1}` is the path's last element — the + §4.5.2 relocation of the active pair to two adjacent basis states, at the matrix level. + +## Use + +This reuses the existing `swapConj` / `swapPerm` lemmas. It is the shared first-stage lemma of the +§4.5.2 two-level → single-qubit + `CNOT` reduction used by Exercise 4.43's `n`-qubit lift; the +statement of Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **The swap chain read off a path of basis indices** (N&C §4.5.2, first stage): the list of +consecutive-pair transpositions `[(g_{m-2}, g_{m-1}), …, (g₁, g₂)]` of `path = [g₁, …, g_{m-1}]`, +ordered with the *first* swap `(g₁, g₂)` **last** so that, read through `swapPerm` (head outermost) +/ `swapConj`, the swap `|g₁⟩ ↔ |g₂⟩` is applied first and `|g_{m-2}⟩ ↔ |g_{m-1}⟩` last. Defined by +the structural recursion `swapChain (a :: b :: l) = swapChain (b :: l) ++ [(a, b)]` so its action +on the endpoints unfolds cleanly (`swapPerm_swapChain_eq`). -/ +def swapChain : List (Fin d) → List (Fin d × Fin d) + | [] => [] + | [_] => [] + | a :: b :: l => swapChain (b :: l) ++ [(a, b)] + +@[simp] theorem swapChain_nil : swapChain ([] : List (Fin d)) = [] := rfl + +@[simp] theorem swapChain_singleton (a : Fin d) : swapChain [a] = [] := rfl + +theorem swapChain_cons_cons (a b : Fin d) (l : List (Fin d)) : + swapChain (a :: b :: l) = swapChain (b :: l) ++ [(a, b)] := rfl + +/-- **The composite permutation of a swap chain peels the first transposition on the right.** +`swapPerm (swapChain (a :: b :: l)) = swapPerm (swapChain (b :: l)) * Equiv.swap a b`: the swap +`(a, b)` sits innermost (applied first). Follows from `swapPerm_append`. -/ +theorem swapPerm_swapChain_cons_cons (a b : Fin d) (l : List (Fin d)) : + swapPerm (swapChain (a :: b :: l)) = swapPerm (swapChain (b :: l)) * Equiv.swap a b := by + rw [swapChain_cons_cons, swapPerm_append, swapPerm_cons, swapPerm_nil, mul_one] + +/-- **A swap chain fixes every index off its path** — N&C's "all other computational basis states +are left unchanged" (the clause that keeps `|t⟩ = |g_m⟩` fixed, since `t` lies off the path +`[g₁, …, g_{m-1}]`). Proved by structural induction: the outer swap `(a, b)` fixes +`w ∉ a :: b :: l`, and the inductive hypothesis fixes it under the shorter chain. -/ +theorem swapPerm_swapChain_apply_of_not_mem : + ∀ {l : List (Fin d)} {w : Fin d}, w ∉ l → swapPerm (swapChain l) w = w := by + intro l + induction l using swapChain.induct with + | case1 => intro w _; simp + | case2 a => intro w _; simp + | case3 a b l ih => + intro w hw + rw [List.mem_cons, not_or, List.mem_cons, not_or] at hw + obtain ⟨hwa, hwb, hwl⟩ := hw + rw [swapPerm_swapChain_cons_cons, Equiv.Perm.mul_apply, + Equiv.swap_apply_of_ne_of_ne hwa hwb, ih (by simp [hwb, hwl])] + +/-- **A swap chain carries the path's head to its last element** — N&C eq. 4.54, `|g₁⟩ → |g_{m-1}⟩`. +For a nonempty path `path` with `path.head? = some s` and `path.getLast? = some e`, +`swapPerm (swapChain path) s = e`. Proved by structural induction on the `a :: b :: l` recursion: +the outer swap sends `a` to `b = (b :: l).head`, and the inductive hypothesis carries that head to +the common last element. (No `Nodup` needed — only the head is tracked.) -/ +theorem swapPerm_swapChain_eq : + ∀ {l : List (Fin d)} {s e : Fin d}, l.head? = some s → l.getLast? = some e → + swapPerm (swapChain l) s = e := by + intro l + induction l using swapChain.induct with + | case1 => intro s e hs _; simp at hs + | case2 a => + intro s e hs he + rw [List.head?_cons, Option.some_inj] at hs + rw [List.getLast?_singleton, Option.some_inj] at he + subst hs he + simp + | case3 a b l ih => + intro s e hs he + rw [List.head?_cons, Option.some_inj] at hs + subst hs + rw [List.getLast?_cons_cons] at he + rw [swapPerm_swapChain_cons_cons, Equiv.Perm.mul_apply, Equiv.swap_apply_left] + exact ih (List.head?_cons) he + +/-- **The swap chain relocates a two-level unitary's support from `{s, w}` to `{e, w}`** — the +matrix-level statement of N&C's §4.5.2 first stage. If `U` is unitary and acts non-trivially only on +the two computational basis states `{s, w}`, where `s` is the head of `path` and `w` lies off the +path, then conjugating `U` by the swap chain of `path` (`swapConj (swapChain path) U`) is unitary +and acts non-trivially only on `{e, w}`, where `e` is the last element of `path`. Instantiating +`path` at a +Gray code `[g₁, …, g_{m-1}]` (`s = g₁`, `e = g_{m-1}`, `w = g_m = t`) moves the active pair to +`{g_{m-1}, g_m}`, two basis states differing in a single bit — the point where the two-level unitary +is a controlled single-qubit gate. Combines `swapConj_unitary_support` (support tracked by the +composite permutation) with the two endpoint facts above. -/ +theorem swapConj_swapChain_support {path : List (Fin d)} {s e w : Fin d} + (hs : path.head? = some s) (he : path.getLast? = some e) (hw : w ∉ path) + {U : Matrix (Fin d) (Fin d) ℂ} (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ s ∧ i ≠ w) ∨ (j ≠ s ∧ j ≠ w) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + swapConj (swapChain path) U ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + ∀ i j : Fin d, (i ≠ e ∧ i ≠ w) ∨ (j ≠ e ∧ j ≠ w) → + swapConj (swapChain path) U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j := by + obtain ⟨hu, hs'⟩ := swapConj_unitary_support (swapChain path) hunit hsupp + rw [swapPerm_swapChain_eq hs he, swapPerm_swapChain_apply_of_not_mem hw] at hs' + exact ⟨hu, hs'⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/TwoLevelSwapList.lean b/LeanPool/AxQM/Concrete/TwoLevelSwapList.lean new file mode 100644 index 0000000000..c7614ef212 --- /dev/null +++ b/LeanPool/AxQM/Concrete/TwoLevelSwapList.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelSwap + +/-! +# Concrete: folding the basis-transposition conjugation along a list (N&C §4.5.2) + +Nielsen & Chuang §4.5.2 (p. 191–193) realises a two-level unitary `U` on `n` qubits — one acting +non-trivially only on the computational basis states `|s⟩` and `|t⟩` — by *walking a Gray code* from +`s` to `t`: a **sequence** of basis-state swaps shuffles `|s⟩` next to `|t⟩`, a single controlled +single-qubit gate acts, and the swaps are undone. `IsTwoLevelUnitary.swap_conj` (in +`Concrete/TwoLevelSwap.lean`) is the matrix engine of *one* such swap step — conjugation by one +basis transposition `Matrix.swap ℂ p q` relocates the two active basis states from `{a, b}` to +`{swap p q a, swap p q b}`. This file iterates that step along a whole list of transpositions, which +is the form the Gray-code walk consumes. + +* `swapConj L U` — conjugate `U` by the list `L` of transpositions, head **outermost**: + `swapConj [] U = U` and + `swapConj ((p,q) :: L) U = Matrix.swap ℂ p q * swapConj L U * Matrix.swap ℂ p q`. +* `swapPerm L` — the composite permutation `Equiv.swap p₁ q₁ * ⋯ * Equiv.swap pₖ qₖ` of the index + set that `L` effects; the two active basis states of `swapConj L U` are the images under it of + those of `U`. +* `swapConj_unitary_support` — **the headline**: if `U` is unitary with support `{a, b}` then + `swapConj L U` is unitary with support `{swapPerm L a, swapPerm L b}` (the support is carried + along by the composite permutation, tracked *explicitly* — not merely "some pair" — so a consumer + can compute where `s` and `t` land). +* `isTwoLevelUnitary_swapConj` — the packaged corollary: `swapConj L U` is a two-level unitary + whenever `U` is (support existentially quantified again). +* `swapConj_append` / `swapPerm_append` — the walk composes: conjugating by `L₁ ++ L₂` is + conjugating by `L₂` and then by `L₁`, and the composite permutation is + `swapPerm L₁ * swapPerm L₂`. This is the algebra the "undo the swaps" half of the walk uses. + +## Use + +This is the shared list-level swap lemma of the §4.5.2 two-level → single-qubit + `CNOT` +reduction used by Exercise 4.43's `n`-qubit lift; the statement of Exercise 4.43 is in +[upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {d : ℕ} + +/-- **Conjugation of a matrix by a list of basis transpositions**, applied one at a time with the +list head **outermost**: `swapConj [] U = U` and +`swapConj ((p,q) :: L) U = Matrix.swap ℂ p q * swapConj L U * Matrix.swap ℂ p q`. Iterating N&C's +one-step swap conjugation (`IsTwoLevelUnitary.swap_conj`) along the Gray-code walk of §4.5.2. -/ +noncomputable def swapConj : + List (Fin d × Fin d) → Matrix (Fin d) (Fin d) ℂ → Matrix (Fin d) (Fin d) ℂ + | [], U => U + | pq :: L, U => Matrix.swap ℂ pq.1 pq.2 * swapConj L U * Matrix.swap ℂ pq.1 pq.2 + +@[simp] theorem swapConj_nil (U : Matrix (Fin d) (Fin d) ℂ) : swapConj [] U = U := rfl + +@[simp] theorem swapConj_cons (pq : Fin d × Fin d) (L : List (Fin d × Fin d)) + (U : Matrix (Fin d) (Fin d) ℂ) : + swapConj (pq :: L) U + = Matrix.swap ℂ pq.1 pq.2 * swapConj L U * Matrix.swap ℂ pq.1 pq.2 := rfl + +/-- **The composite permutation of the index set effected by a list of basis transpositions**: +`swapPerm [] = 1` and `swapPerm ((p,q) :: L) = Equiv.swap p q * swapPerm L`. If `U` acts +non-trivially only on the basis states `{a, b}`, then `swapConj L U` acts non-trivially only on +`{swapPerm L a, swapPerm L b}` (see `swapConj_unitary_support`). -/ +def swapPerm : List (Fin d × Fin d) → Equiv.Perm (Fin d) + | [] => 1 + | pq :: L => Equiv.swap pq.1 pq.2 * swapPerm L + +@[simp] theorem swapPerm_nil : swapPerm ([] : List (Fin d × Fin d)) = 1 := rfl + +@[simp] theorem swapPerm_cons (pq : Fin d × Fin d) (L : List (Fin d × Fin d)) : + swapPerm (pq :: L) = Equiv.swap pq.1 pq.2 * swapPerm L := rfl + +/-- **Conjugating by `L₁ ++ L₂` is conjugating by `L₂`, then by `L₁`.** The `++` splits the walk +into two stages; used with `swapConj_cons` to compose a Gray-code walk with the reversed walk that +undoes it. -/ +theorem swapConj_append (L₁ L₂ : List (Fin d × Fin d)) (U : Matrix (Fin d) (Fin d) ℂ) : + swapConj (L₁ ++ L₂) U = swapConj L₁ (swapConj L₂ U) := by + induction L₁ with + | nil => rfl + | cons pq L ih => rw [List.cons_append, swapConj_cons, swapConj_cons, ih] + +/-- **The composite permutation of `L₁ ++ L₂` is `swapPerm L₁ * swapPerm L₂`.** The list-of-swaps ↦ +permutation map is a monoid homomorphism from `(List _, ++)` to `Equiv.Perm _`. -/ +theorem swapPerm_append (L₁ L₂ : List (Fin d × Fin d)) : + swapPerm (L₁ ++ L₂) = swapPerm L₁ * swapPerm L₂ := by + induction L₁ with + | nil => rw [List.nil_append, swapPerm_nil, one_mul] + | cons pq L ih => rw [List.cons_append, swapPerm_cons, swapPerm_cons, ih, mul_assoc] + +/-- **Folding the basis-transposition conjugation along a list relocates the support explicitly.** +If `U` is unitary and acts non-trivially only on the two computational basis states `{a, b}` (its +entries outside the `{a,b} × {a,b}` block agree with the identity), then `swapConj L U` is unitary +and acts non-trivially only on `{swapPerm L a, swapPerm L b}` — the images of `a` and `b` under the +composite permutation `swapPerm L`. Tracking the support *pair by name* (rather than existentially, +as in `IsTwoLevelUnitary`) is what lets the §4.5.2 Gray-code walk conclude that the two active basis +states end up differing in exactly one bit. Proved by induction on `L`, each step applying the +single-transposition `swap_conj_support` to the inductive hypothesis's explicit support pair. -/ +theorem swapConj_unitary_support (L : List (Fin d × Fin d)) {U : Matrix (Fin d) (Fin d) ℂ} + {a b : Fin d} (hunit : U ∈ Matrix.unitaryGroup (Fin d) ℂ) + (hsupp : ∀ i j : Fin d, (i ≠ a ∧ i ≠ b) ∨ (j ≠ a ∧ j ≠ b) → + U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j) : + swapConj L U ∈ Matrix.unitaryGroup (Fin d) ℂ ∧ + ∀ i j : Fin d, + (i ≠ swapPerm L a ∧ i ≠ swapPerm L b) ∨ (j ≠ swapPerm L a ∧ j ≠ swapPerm L b) → + swapConj L U i j = (1 : Matrix (Fin d) (Fin d) ℂ) i j := by + induction L with + | nil => exact ⟨hunit, by simpa using hsupp⟩ + | cons pq L ih => + -- One list step is exactly the single-transposition `swap_conj_support`, applied to the + -- inductive hypothesis's *explicit* support pair `{swapPerm L a, swapPerm L b}`. + -- `swapConj (pq :: L) U` is defeq to `swap * swapConj L U * swap`, so `swap_conj_support` + -- discharges both goals directly (no `swapConj_cons` unfold needed). + obtain ⟨hu, hs⟩ := ih + obtain ⟨hu', hs'⟩ := swap_conj_support hu hs pq.1 pq.2 + refine ⟨hu', fun i j h => hs' i j ?_⟩ + simpa only [swapPerm_cons, Equiv.Perm.mul_apply] using h + +/-- **Conjugating a two-level unitary by a list of basis transpositions yields a two-level +unitary.** The packaged corollary of `swapConj_unitary_support`: `swapConj L U` is a two-level +unitary whenever `U` is (here the relocated support `{swapPerm L a, swapPerm L b}` is repackaged +into the existential of `IsTwoLevelUnitary`). This is the §4.5.2 statement "the Gray-code swaps +carry a two-level unitary to a two-level unitary" at the matrix level. -/ +theorem isTwoLevelUnitary_swapConj (L : List (Fin d × Fin d)) {U : Matrix (Fin d) (Fin d) ℂ} + (hU : IsTwoLevelUnitary U) : IsTwoLevelUnitary (swapConj L U) := by + obtain ⟨hunit, a, b, hab⟩ := hU + obtain ⟨hu, hs⟩ := swapConj_unitary_support L hunit hab + exact ⟨hu, swapPerm L a, swapPerm L b, hs⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/UnitaryControlledProduct.lean b/LeanPool/AxQM/Concrete/UnitaryControlledProduct.lean new file mode 100644 index 0000000000..95e7534f0a --- /dev/null +++ b/LeanPool/AxQM/Concrete/UnitaryControlledProduct.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.TwoLevelControlledProduct +public import LeanPool.AxQM.Concrete.TwoLevelDecomposition + +/-! +# Concrete: every `2ⁿ × 2ⁿ` unitary is a product of controlled single-qubit gates (N&C §4.5) + +(Nielsen & Chuang §4.5, p. 189–193 — the `n`-qubit lift, first stage.) + +This file composes the two structural halves of §4.5 that are already in place: + +* **§4.5.1** (`exists_twoLevelUnitaryList_prod_eq`, `Concrete/TwoLevelDecomposition.lean`) — every + `d × d` unitary is an explicit product of *two-level* unitaries. +* **§4.5.2** (`twoLevelUnitary_isProd_ctrlSingleQubit`, `Concrete/TwoLevelControlledProduct.lean`) — + a two-level unitary supported on two *distinct* encoded basis states `{enc s, enc t}` (`s ≠ t`) is + an explicit product of controlled single-qubit gates. + +Chaining them gives the §4.5 milestone that Exercise 4.43's `n`-qubit lift rests on: **any unitary +on an `m`-bit register (`enc : (Fin m → Fin 2) ≃ Fin d`, `m ≥ 1`) is an exact product of controlled +single-qubit gates.** + +## The pieces + +* `AxQM.Concrete.isProd_ctrlSingleQubit_of_isTwoLevelUnitary` — **the bridge**: *any* + two-level unitary `V` (in the sense of `IsTwoLevelUnitary`, whose support pair `{p, q}` may be + *degenerate*, `p = q`, i.e. a single-coordinate phase) is a product of controlled single-qubit + gates. When `p ≠ q` this is `twoLevelUnitary_isProd_ctrlSingleQubit` applied at + `(enc.symm p, enc.symm q)`. When `p = q` the support `{p}` sits inside `{p, p'}` for *any* other + index `p'` (one exists because there is at least one qubit, `Nontrivial (Fin m → Fin 2)`), so `V` + still satisfies the two-index support hypothesis at the distinct pair `(enc.symm p, p')` and the + same theorem applies — the single-coordinate phase is realised as a controlled single-qubit gate + with a diagonal `2 × 2` block on that (arbitrary) partner qubit. +* `AxQM.Concrete.isProd_ctrlSingleQubit_of_forall_isTwoLevelUnitary` — **the list step**: + a list `L` all of whose members are two-level unitaries yields a single list of controlled + single-qubit gates with the *same* product (concatenate the per-factor decompositions; list + induction, one application of the bridge per factor). +* `AxQM.Concrete.exists_isCtrlSingleQubit_list_prod_eq` — **the headline**: for + `enc : (Fin m → Fin 2) ≃ Fin d` with at least one qubit and any `U ∈ U(d)`, there is a list + `gates`, every member a controlled single-qubit gate (`IsCtrlSingleQubit enc`), with + `gates.prod = U`. It feeds the §4.5.1 two-level decomposition of `U` through the list step. + +The `Nontrivial (Fin m → Fin 2)` hypothesis is exactly "at least one qubit" (`m ≥ 1`): on a +zero-qubit system (`Fin 1`) there are no gates at all, and the §4.5.1 decomposition of a genuine +`d × d` unitary contains single-coordinate `phaseShift` factors (`p = q`) that can only be hosted as +controlled gates once a partner qubit exists, so this is the faithful hypothesis, not a weakening. + +The statement of Exercise 4.43 is in [upstream `AxQM/NC/Ch4/Exercise4_43.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_43.lean). +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +/-- **The bridge — any two-level unitary is a product of controlled single-qubit gates.** For an +encoding `enc : (Fin m → Fin 2) ≃ Fin d` with at least one qubit (`Nontrivial (Fin m → Fin 2)`), +every `V` with `IsTwoLevelUnitary V` equals `gates.prod` for a list `gates` all of whose members are +controlled single-qubit gates (`IsCtrlSingleQubit enc`). + +`IsTwoLevelUnitary` allows a *degenerate* support pair `p = q` (a single-coordinate phase). Such a +`V` is supported on `{p} ⊆ {p, enc t}` for any second bit-string `t ≠ enc.symm p` (one exists by +nontriviality), so it satisfies the two-*distinct*-index support hypothesis of +`twoLevelUnitary_isProd_ctrlSingleQubit` at `(enc.symm p, t)`; the honest two-level case `p ≠ q` +uses that theorem directly at `(enc.symm p, enc.symm q)`. -/ +theorem isProd_ctrlSingleQubit_of_isTwoLevelUnitary {m d : ℕ} [Nontrivial (Fin m → Fin 2)] + (enc : (Fin m → Fin 2) ≃ Fin d) {V : Matrix (Fin d) (Fin d) ℂ} + (hV : IsTwoLevelUnitary V) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsCtrlSingleQubit enc g) ∧ V = gates.prod := by + obtain ⟨hVu, p, q, hsupp⟩ := hV + by_cases hpq : p = q + · subst hpq + obtain ⟨t, ht⟩ := exists_ne (enc.symm p) + refine twoLevelUnitary_isProd_ctrlSingleQubit enc (s := enc.symm p) (t := t) + (fun h => ht h.symm) hVu ?_ + intro i j hij + simp only [Equiv.apply_symm_apply] at hij + exact hsupp i j (hij.imp (fun h => ⟨h.1, h.1⟩) (fun h => ⟨h.1, h.1⟩)) + · refine twoLevelUnitary_isProd_ctrlSingleQubit enc (s := enc.symm p) (t := enc.symm q) + (fun h => hpq (enc.symm.injective h)) hVu ?_ + intro i j hij + simp only [Equiv.apply_symm_apply] at hij + exact hsupp i j hij + +/-- **The list step — a list of two-level unitaries becomes a list of controlled single-qubit gates +with the same product.** If every member of `L` is a two-level unitary then there is a list `gates`, +every member a controlled single-qubit gate, with `gates.prod = L.prod`. Proved by list induction, +applying `isProd_ctrlSingleQubit_of_isTwoLevelUnitary` to each factor and concatenating the +results. -/ +theorem isProd_ctrlSingleQubit_of_forall_isTwoLevelUnitary {m d : ℕ} [Nontrivial (Fin m → Fin 2)] + (enc : (Fin m → Fin 2) ≃ Fin d) : + ∀ L : List (Matrix (Fin d) (Fin d) ℂ), (∀ V ∈ L, IsTwoLevelUnitary V) → + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsCtrlSingleQubit enc g) ∧ gates.prod = L.prod := by + intro L + induction L with + | nil => exact fun _ => ⟨[], by simp, by simp⟩ + | cons V L' ih => + intro hL + obtain ⟨gV, hgV, hgVprod⟩ := + isProd_ctrlSingleQubit_of_isTwoLevelUnitary enc (hL V (List.mem_cons.mpr (Or.inl rfl))) + obtain ⟨gL', hgL', hgL'prod⟩ := ih (fun W hW => hL W (List.mem_cons.mpr (Or.inr hW))) + refine ⟨gV ++ gL', ?_, ?_⟩ + · intro g hg + rw [List.mem_append] at hg + rcases hg with h | h + · exact hgV g h + · exact hgL' g h + · rw [List.prod_append, ← hgVprod, hgL'prod, List.prod_cons] + +/-- **Every unitary on an `m`-bit register is an exact product of controlled single-qubit gates +(N&C §4.5).** For an encoding `enc : (Fin m → Fin 2) ≃ Fin d` with at least one qubit +(`Nontrivial (Fin m → Fin 2)`) and any `U ∈ U(d)`, there is an explicit list `gates`, **every** +member of which is a controlled single-qubit gate (`IsCtrlSingleQubit enc`), with `gates.prod = U`. + +This is the composition of the two §4.5 halves: the §4.5.1 two-level decomposition +(`exists_twoLevelUnitaryList_prod_eq`) writes `U` as a product of two-level unitaries, and the list +step turns each two-level factor into controlled single-qubit gates (via the §4.5.2 gate-list form). +It is the first stage of Exercise 4.43's `n`-qubit lift: reducing an arbitrary unitary to the +controlled single-qubit gates that are later realised over `H, S, CNOT, Toffoli`. -/ +theorem exists_isCtrlSingleQubit_list_prod_eq {m d : ℕ} [Nontrivial (Fin m → Fin 2)] + (enc : (Fin m → Fin 2) ≃ Fin d) {U : Matrix (Fin d) (Fin d) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsCtrlSingleQubit enc g) ∧ gates.prod = U := by + obtain ⟨L, hL, hLprod⟩ := exists_twoLevelUnitaryList_prod_eq U hU + obtain ⟨gates, hgates, hgprod⟩ := + isProd_ctrlSingleQubit_of_forall_isTwoLevelUnitary enc L hL + exact ⟨gates, hgates, hgprod.trans hLprod⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/UnitarySquareRoot.lean b/LeanPool/AxQM/Concrete/UnitarySquareRoot.lean new file mode 100644 index 0000000000..86c9a3d9ce --- /dev/null +++ b/LeanPool/AxQM/Concrete/UnitarySquareRoot.lean @@ -0,0 +1,78 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.AxisAngleDecomposition + +/-! +# AxQM.Concrete — the unitary square root of a single-qubit unitary + +Every `2 × 2` unitary matrix has a unitary square root: for `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` +there is a `V` in the same unitary group with `V * V = U`. This is the matrix core behind the +gate square root `Evolution.exists_comp_self_eq` (`Postulates/API/UnitarySquareRoot.lean`), which +Nielsen & Chuang's Figure 4.8 construction of `C²(U)` needs: that circuit is built from a `V` with +`V² = U`, and the square root's existence is what makes the *"for any single-qubit unitary `U`"* +statement of Exercise 4.22 honest. + +## What is formalised + +* `AxQM.Concrete.exists_unitary_sq` — for `U ∈ Matrix.unitaryGroup (Fin 2) ℂ`, + `∃ V ∈ Matrix.unitaryGroup (Fin 2) ℂ, V * V = U`. + +## Design notes + +**Construction (half-angle rotation).** Via the axis-angle decomposition (Exercise 4.8, +`Concrete.exists_axis_angle_decomposition`): write `U = e^{iα} R_n̂(θ)` for a real phase `α`, angle +`θ`, and unit axis `n̂`. The half-angle rotation `V := e^{iα/2} R_n̂(θ/2)` squares to `U`: the +one-parameter group law `rotAxis_mul_same` gives `R_n̂(θ/2) R_n̂(θ/2) = R_n̂(θ)`, and +`e^{iα/2} · e^{iα/2} = e^{iα}` (`Complex.exp_add`). Unitarity holds because `V` is a unit-modulus +scalar (`‖e^{iα/2}‖ = 1`) times the unitary rotation `R_n̂(θ/2)` +(`rotAxis_mul_conjTranspose_self`). +-/ + +@[expose] public section + +open Matrix Complex + +namespace AxQM.Concrete + +/-- **Every `2 × 2` unitary has a unitary square root.** For `U ∈ Matrix.unitaryGroup (Fin 2) ℂ` +there is a unitary `V` with `V * V = U`. Taking the axis-angle form `U = e^{iα} R_n̂(θ)` +(`exists_axis_angle_decomposition`), the witness is the half-angle rotation +`V = e^{iα/2} R_n̂(θ/2)`, whose square is `U` by the rotation group law `rotAxis_mul_same` +(with `θ/2 + θ/2 = θ`) and `e^{iα/2} · e^{iα/2} = e^{iα}`. -/ +theorem exists_unitary_sq {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ V ∈ Matrix.unitaryGroup (Fin 2) ℂ, V * V = U := by + obtain ⟨α, θ, n, hn, hUeq⟩ := exists_axis_angle_decomposition U hU + -- `star (e^{iα/2}) = e^{-iα/2}` (conjugating a real-times-`i` exponent flips the sign). + have hstar : star (Complex.exp (((α / 2 : ℝ) : ℂ) * Complex.I)) + = Complex.exp (((-(α / 2) : ℝ) : ℂ) * Complex.I) := by + rw [Complex.star_def, ← Complex.exp_conj] + congr 1 + rw [map_mul, Complex.conj_ofReal, Complex.conj_I] + push_cast + ring + -- `e^{iα/2} · star (e^{iα/2}) = 1`, i.e. the scalar has unit modulus. + have hcc : Complex.exp (((α / 2 : ℝ) : ℂ) * Complex.I) + * star (Complex.exp (((α / 2 : ℝ) : ℂ) * Complex.I)) = 1 := by + rw [hstar, ← Complex.exp_add, + show ((α / 2 : ℝ) : ℂ) * Complex.I + ((-(α / 2) : ℝ) : ℂ) * Complex.I = 0 by + push_cast; ring, Complex.exp_zero] + refine ⟨Complex.exp (((α / 2 : ℝ) : ℂ) * Complex.I) • rotAxis n (θ / 2), ?_, ?_⟩ + · -- Unitarity: `(c • R) (c • R)ᴴ = (c · star c) • (R Rᴴ) = 1 • 1 = 1`. + rw [Matrix.mem_unitaryGroup_iff, star_smul, smul_mul_smul_comm, + Matrix.star_eq_conjTranspose, rotAxis_mul_conjTranspose_self, hcc, one_smul] + · -- Square: `(c • R(θ/2)) (c • R(θ/2)) = (c·c) • R(θ/2 + θ/2) = e^{iα} • R(θ) = U`. + rw [smul_mul_smul_comm, rotAxis_mul_same, ← Complex.exp_add, + show (θ / 2 + θ / 2) = θ by ring, + show (((α / 2 : ℝ) : ℂ) * Complex.I + ((α / 2 : ℝ) : ℂ) * Complex.I) + = ((α : ℝ) : ℂ) * Complex.I by push_cast; ring, ← hUeq] + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Concrete/UnitaryToffoliSingleQubitProduct.lean b/LeanPool/AxQM/Concrete/UnitaryToffoliSingleQubitProduct.lean new file mode 100644 index 0000000000..451e20cea2 --- /dev/null +++ b/LeanPool/AxQM/Concrete/UnitaryToffoliSingleQubitProduct.lean @@ -0,0 +1,165 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.UnitaryControlledProduct +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitTightReduction +public import LeanPool.AxQM.Concrete.ControlledSingleQubitNormalisation + +/-! +# Every unitary on an `m`-qubit register is an exact product of `Toffoli`/`CNOT`/single-qubit gates + +*(Supports N&C Exercise 4.43 — universality of `H, S, CNOT, Toffoli`.)* + +This file composes the two completed halves of the Nielsen & Chuang §4.5/§4.3 development into the +exact-decomposition milestone of Exercise 4.43's `n`-qubit lift: + +* the §4.5 first stage `exists_isCtrlSingleQubit_list_prod_eq` writes any unitary `U ∈ U(d)` + (`d = 2^m`, at least one qubit) as an exact product of **controlled** single-qubit gates + (`IsCtrlSingleQubit`, i.e. `ctrlSingleQubit enc j c U₀`, controlled on *all* other wires + matching a + pattern `c`); +* the §4.3 spare-wire-free reduction `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit'` + reduces any **subset**-controlled single-qubit gate `mcCtrlSingleQubit enc S j U₀` to an exact + product of the **terminal** gate class `IsToffoliOrSingleQubitGate` (a `Toffoli`/`CNOT`/`NOT`, or + an uncontrolled single-qubit unitary on a wire). + +The bridge between them is N&C's §4.3 control-pattern normalisation: an arbitrary control pattern is +conjugated to the all-`1` pattern by a product of `X`-on-wire gates +(`exists_wireFlipProd_conj_ctrlSingleQubit_one`), and the all-`1`-controlled gate is the +full-control member of the subset-controlled family (`mcCtrlSingleQubit_univ_sdiff`: +`mcCtrlSingleQubit enc (univ \ {j}) j U₀ = ctrlSingleQubit enc j 1 U₀`). The conjugating `X`-on-wire +gates are themselves terminal gates (uncontrolled single-qubit unitaries on a wire), so the whole +`ctrlSingleQubit` factor reduces to terminal gates. + +## Results + +* `exists_isToffoliOrSingleQubit_prod_eq_wireFlipProd` — a `wireFlipProd enc L` (the normalising + product of `X`-on-wire gates) is an exact product of terminal gates: each factor is the + uncontrolled `NOT`-on-wire `singleQubitOnWire enc k (Matrix.swap ℂ 0 1)`, itself terminal. +* `exists_isToffoliOrSingleQubit_prod_eq_of_isCtrlSingleQubit` — **the bridge**: a controlled + single-qubit gate `IsCtrlSingleQubit enc g` is an exact product of terminal gates. Normalise the + control pattern, identify the all-`1`-controlled gate as the full subset-controlled gate, and + discharge it with the §4.3 reduction; the two normalising `wireFlipProd` conjugation factors are + terminal-gate products. +* `exists_isToffoliOrSingleQubit_prod_eq_of_forall_isCtrlSingleQubit` — the list step: a list all of + whose members are controlled single-qubit gates yields one flattened list of terminal gates with + the same product (list induction, concatenating the per-factor bridges). +* `exists_isToffoliOrSingleQubit_list_prod_eq` — **the headline**: for an encoding + `enc : (Fin m → Fin 2) ≃ Fin d` + with at least one qubit (`Nontrivial (Fin m → Fin 2)`) and any `U ∈ U(d)`, there is an explicit + list `gates`, **every** member an `IsToffoliOrSingleQubitGate`, with `gates.prod = U`. Feeds the + §4.5 controlled-single-qubit decomposition of `U` through the bridge. This is the *exact* + gate-decomposition input the §4.5.3 approximation calculus (per-wire density + `exists_phase_smul_singleQubitOnWire_mem_closure` + the chaining inequality + `norm_listProd_sub_listProd_le`) will turn into approximate `n`-qubit universality over + `H, S, CNOT, Toffoli`. +-/ + +@[expose] public section + +namespace AxQM.Concrete + +open Matrix + +variable {m d : ℕ} + +/-- **The normalising product of `X`-on-wire gates is a product of terminal gates.** +`wireFlipProd enc L` is by definition the product of `NOT`-on-wire gates +`singleQubitOnWire enc k (Matrix.swap ℂ 0 1)` over `k ∈ L`, and each such gate is an uncontrolled +single-qubit unitary on a wire (the `2 × 2` block `Matrix.swap ℂ 0 1 = X` is unitary, +`swapTwo_mem_unitaryGroup`), hence an `IsToffoliOrSingleQubitGate`. -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_wireFlipProd (enc : (Fin m → Fin 2) ≃ Fin d) + (L : List (Fin m)) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ gates.prod = wireFlipProd enc L := by + refine ⟨L.map fun k => singleQubitOnWire enc k (Matrix.swap ℂ (0 : Fin 2) 1), ?_, rfl⟩ + intro g hg + rw [List.mem_map] at hg + obtain ⟨k, _, rfl⟩ := hg + exact Or.inr ⟨k, Matrix.swap ℂ (0 : Fin 2) 1, swapTwo_mem_unitaryGroup, rfl⟩ + +/-- **A controlled single-qubit gate is an exact product of `Toffoli`/`CNOT`/single-qubit gates.** +For `IsCtrlSingleQubit enc g` (so `g = ctrlSingleQubit enc j c U₀` with `U₀ ∈ U(2)`) there is a list +`gates`, every member an `IsToffoliOrSingleQubitGate`, with `gates.prod = g`. + +Proof (N&C §4.3): normalise the control pattern to all-`1` by conjugating with a product of +`X`-on-wire gates (`exists_wireFlipProd_conj_ctrlSingleQubit_one`, +`g = wireFlipProd enc L.reverse * ctrlSingleQubit enc j 1 U₀ * wireFlipProd enc L`); the +all-`1`-controlled gate is the full subset-controlled gate +(`mcCtrlSingleQubit_univ_sdiff`, +`ctrlSingleQubit enc j 1 U₀ = mcCtrlSingleQubit enc (univ \ {j}) j U₀`), reduced to terminal gates +by +the §4.3 spare-wire-free reduction `exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit'`; and +the two conjugating `wireFlipProd` factors are terminal-gate products +(`exists_isToffoliOrSingleQubit_prod_eq_wireFlipProd`). Concatenating the three lists gives the +result. -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_of_isCtrlSingleQubit (enc : (Fin m → Fin 2) ≃ Fin d) + {g : Matrix (Fin d) (Fin d) ℂ} (hg : IsCtrlSingleQubit enc g) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g' ∈ gates, IsToffoliOrSingleQubitGate enc g') ∧ gates.prod = g := by + obtain ⟨j, c, U₀, hU₀, rfl⟩ := hg + obtain ⟨L, _hL, hnorm⟩ := exists_wireFlipProd_conj_ctrlSingleQubit_one enc j c U₀ + have hjS : j ∉ (Finset.univ \ {j} : Finset (Fin m)) := by simp + obtain ⟨Gm, hGm, hGmprod⟩ := + exists_isToffoliOrSingleQubit_prod_eq_mcCtrlSingleQubit' enc hjS hU₀ + obtain ⟨Gr, hGr, hGrprod⟩ := exists_isToffoliOrSingleQubit_prod_eq_wireFlipProd enc L.reverse + obtain ⟨Gl, hGl, hGlprod⟩ := exists_isToffoliOrSingleQubit_prod_eq_wireFlipProd enc L + refine ⟨Gr ++ Gm ++ Gl, ?_, ?_⟩ + · exact List.forall_mem_append.2 ⟨List.forall_mem_append.2 ⟨hGr, hGm⟩, hGl⟩ + · rw [List.prod_append, List.prod_append, hGrprod, hGlprod, ← hGmprod, + mcCtrlSingleQubit_univ_sdiff, hnorm] + +/-- **A list of controlled single-qubit gates flattens to a list of terminal gates with the same +product.** If every member of `cgates` is an `IsCtrlSingleQubit`, there is a single list `gates`, +every member an `IsToffoliOrSingleQubitGate`, with `gates.prod = cgates.prod`. Proved by list +induction, concatenating the per-factor terminal-gate expansions +(`exists_isToffoliOrSingleQubit_prod_eq_of_isCtrlSingleQubit`). -/ +theorem exists_isToffoliOrSingleQubit_prod_eq_of_forall_isCtrlSingleQubit + (enc : (Fin m → Fin 2) ≃ Fin d) : + ∀ cgates : List (Matrix (Fin d) (Fin d) ℂ), (∀ g ∈ cgates, IsCtrlSingleQubit enc g) → + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ gates.prod = cgates.prod := by + intro cgates + induction cgates with + | nil => intro _; exact ⟨[], by simp, rfl⟩ + | cons g cg ih => + intro hall + obtain ⟨gG, hgG, hgGprod⟩ := exists_isToffoliOrSingleQubit_prod_eq_of_isCtrlSingleQubit enc + (hall g (List.mem_cons_self ..)) + obtain ⟨gR, hgR, hgRprod⟩ := ih fun g' hg' => hall g' (List.mem_cons_of_mem g hg') + refine ⟨gG ++ gR, ?_, ?_⟩ + · exact List.forall_mem_append.2 ⟨hgG, hgR⟩ + · rw [List.prod_append, hgGprod, hgRprod, List.prod_cons] + +/-- **Every unitary on an `m`-qubit register is an exact product of `Toffoli`/`CNOT`/single-qubit +gates** (Nielsen & Chuang §4.5 + §4.3, the exact-decomposition milestone of Exercise 4.43). For an +encoding `enc : (Fin m → Fin 2) ≃ Fin d` with at least one qubit (`Nontrivial (Fin m → Fin 2)`) and +any `U ∈ U(d)`, there is an explicit list `gates`, **every** member of which is an +`IsToffoliOrSingleQubitGate` (a `Toffoli`/`CNOT`/`NOT` or an uncontrolled single-qubit unitary on a +wire), with `gates.prod = U`. + +Composes the §4.5 controlled-single-qubit decomposition (`exists_isCtrlSingleQubit_list_prod_eq`) +with the §4.3 reduction of each controlled single-qubit gate to terminal gates (the bridge +`exists_isToffoliOrSingleQubit_prod_eq_of_forall_isCtrlSingleQubit`). This is the *exact* gate +decomposition; the residual global phase on each uncontrolled wire gate — harmless, unlike a +relative phase on a controlled gate — is what the §4.5.3 approximation calculus then discharges to +obtain +approximate universality over `H, S, CNOT, Toffoli` on any number of qubits. -/ +theorem exists_isToffoliOrSingleQubit_list_prod_eq [Nontrivial (Fin m → Fin 2)] + (enc : (Fin m → Fin 2) ≃ Fin d) {U : Matrix (Fin d) (Fin d) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + ∃ gates : List (Matrix (Fin d) (Fin d) ℂ), + (∀ g ∈ gates, IsToffoliOrSingleQubitGate enc g) ∧ gates.prod = U := by + obtain ⟨cgates, hcg, hcgprod⟩ := exists_isCtrlSingleQubit_list_prod_eq enc hU + obtain ⟨gates, hgates, hgprod⟩ := + exists_isToffoliOrSingleQubit_prod_eq_of_forall_isCtrlSingleQubit enc cgates hcg + exact ⟨gates, hgates, hgprod.trans hcgprod⟩ + +end AxQM.Concrete diff --git a/LeanPool/AxQM/Core/BarencoBlockFlatten.lean b/LeanPool/AxQM/Core/BarencoBlockFlatten.lean new file mode 100644 index 0000000000..25363669b1 --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoBlockFlatten.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerComposeRight +public import LeanPool.AxQM.Core.TensorPowMultiControlledX +public import LeanPool.AxQM.Postulates.API.BlockGatePlacement + +/-! +# Flattening a `barencoNCircuit` block's register onto the symmetric power (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`), whose distinctive content is +bottoming its internal multiply-controlled `NOT` blocks `Cᵏ(X)` to genuine `Toffoli`s. Each such +block is `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` acting on the control tower +`qtower k (qubit ⊗ qtower d qubit)` — `k` outer control qubits, the `X`-target the head of the +inner `qubit ⊗ (qtower d qubit)`, and `d + 1` idle target-module wires (`M = qtower d qubit`, the +already-peeled controls that this block does not touch, `Exercise4_30.barencoNCircuit`). + +The block's reduction is described from opposite ends, but on **different registers**: + +* `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` reads the block's computational-basis + action on the **tower** `qtower k (qubit ⊗ qtower d qubit)`, on inputs + `ctrlTower k c (|i⟩ ⊗ towerKet d e)` (controls `c`, target `i`, idle module `e`); +* `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` exhibits the bounded `O(k²)` `Toffoli` + circuit for `(tensorPowMcCtrlX k).onBlock (d+1)` on the **flattened symmetric register** + `qubit ^⊗ₛ (k + 1 + (d + 1))`. + +The isomorphism `qtowerComposeRight` pulls the idle module out of the tower, +`qtower k (qubit ⊗ M) ≃ₛ (qtower k qubit) ⊗ M`. This file composes it with the +`qtower ↔ tensor-power` bridge `qtowerQubitTensorPow` on each factor and the block-split +`QSystem.tensorPowAdd` to land exactly on the flattened register +`qubit ^⊗ₛ (k + 1 + (d + 1))` of `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`, and reads off the +induced computational dictionary. Matching the block's tower truth table +(`mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower`) to the flattened circuit across this bridge +gives the per-block `Toffoli` reduction, an `Evolution`-level equality by computational-basis +extensionality. + +## What is formalised + +* `barencoBlockFlatten k d` — the **block-flattening bridge** + `qtower k (qubit ⊗ qtower d qubit) ≃ₛ qubit ^⊗ₛ (k + 1 + (d + 1))`, the three-step composite + `(qtowerComposeRight k).trans ((qtowerQubitTensorPow k).tmul (qtowerQubitTensorPow d)) |>.trans + (tensorPowAdd qubit (k+1) (d+1)).symm`: factor the idle module out of the tower, flatten each + `qtower` factor to its symmetric power, then merge the two symmetric powers into one. The block's + `k` controls and its `X`-target become the leading `k + 1` wires; the `d + 1` idle module wires + the trailing block — exactly the shape `(tensorPowMcCtrlX k).onBlock (d + 1)` acts on. +* `barencoBlockFlatten_congr_ctrlTower` — the **basis dictionary**: the bridge carries a block tower + input `ctrlTower k c (|i⟩ ⊗ towerKet d e)` (controls `c`, target `i`, idle module bits `e`) to the + symmetric product basis state over the concatenated bit-string `Fin.append (Fin.snoc c i) e`: + `barencoBlockFlatten k d (ctrlTower k c (|i⟩ ⊗ towerKet d e))` + ` = ⨂_w |Fin.append (Fin.snoc c i) e w⟩`. + So the `k + 1 + (d + 1)` wires of the flattened register carry, in order, the controls `c`, the + target `i`, and the idle module `e` — the correspondence on which the block reduction is read. +* `barencoBlockFlatten_symm_congr_piTensor` — the **backward** dictionary (its `.symm` companion via + `PureState.congr_symm_congr`), used when a gate computed on the flattened register is transported + back onto the block's tower. + +Supporting fact: + +* `ctrlTower_qubitBasis_eq_towerKet` — a control tower over a single target basis vector is a + computational tower ket, `ctrlTower k c |i⟩ = towerKet k (Fin.snoc c i)`. + +The general transport lemmas the dictionary chains through — `PureState.congr_trans` / +`PureState.congr_tmul` (functoriality of `PureState.congr` in `Iso.trans` / `Iso.tmul`) and +`QSystem.tensorPowAdd_symm_congr_piTensor` (the backward block-split product dictionary, +`(tensorPowAdd S a b).symm ((⨂ P) ⊗ (⨂ Q)) = ⨂ (Fin.append P Q)`) — are in +`AxQM/Postulates/API/` (`SystemIsoComm` beside `PureState.congr_symm_congr`, and +`BlockGatePlacement` beside the forward `QSystem.tensorPowAdd_congr_piTensor`). + +## Design notes + +* **Why this exact three-step composite.** The block lives on the right-nested tower + `qtower k (qubit ⊗ qtower d qubit)` while the `O(k²)` `Toffoli` circuit lives on the symmetric + register `qubit ^⊗ₛ (k + 1 + (d + 1))`, split as `(k+1) + (d+1)` by `onBlock (d+1)`. + `qtowerComposeRight` first isolates the idle module as a right factor, so the remaining tower over + the controls-and-target and the tower over the idle module can each be flattened by the + bridge `qtowerQubitTensorPow`; `tensorPowAdd` then fuses the two flat powers into one at the + `(k+1) + (d+1)` split point. Every leg is an existing isomorphism. +* **Why the dictionary chains cleanly.** With `PureState.congr_trans`/`_tmul` the transport of the + composite factors through each sub-dictionary (`qtowerComposeRight_congr_ctrlTower`, + `qtowerQubitTensorPow_congr_towerKet` twice, and the backward `tensorPowAdd` product dictionary) + reduces the proof to a `Fin.append` bookkeeping on the final bit-string. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### `ctrlTower` over a single target basis vector as a `towerKet` -/ + +/-- **A control tower over a single target basis vector is a computational tower ket.** +`ctrlTower k c |i⟩ = towerKet k (Fin.snoc c i)`: prepending `k` control qubits +`|c 0⟩ ⊗ … ⊗ |c (k-1)⟩` to the target `|i⟩` yields the `(k+1)`-qubit computational basis state whose +wires are the controls `c` followed by the target `i`. Proved by induction on `k`: the head control +peels off through `towerKet_succ`, using `Fin.snoc_apply_zero` for the head wire and a per-wire +`Fin.lastCases` for the shifted tail `(Fin.snoc c i) ∘ Fin.succ = Fin.snoc (tail c) i`. -/ +theorem ctrlTower_qubitBasis_eq_towerKet (k : ℕ) (c : Fin k → Fin 2) (i : Fin 2) : + ctrlTower k c (qubitBasis i) = towerKet k (Fin.snoc c i) := by + induction k with + | zero => + rw [ctrlTower_zero, towerKet_zero] + rfl + | succ k ih => + rw [ctrlTower_succ, ih (fun j => c j.succ), towerKet_succ, Fin.snoc_apply_zero] + congr 2 + funext j + induction j using Fin.lastCases with + | last => simp + | cast j => rw [Fin.snoc_castSucc, Fin.succ_castSucc, Fin.snoc_castSucc] + +/-! ### The block-register flattening bridge -/ + +/-- **The `barencoNCircuit`-block flattening bridge** +`qtower k (qubit ⊗ qtower d qubit) ≃ₛ qubit ^⊗ₛ (k + 1 + (d + 1))`: the system isomorphism carrying +one internal `Cᵏ(X)` block's control-tower register onto the flattened symmetric register its +bounded `Toffoli` circuit lives on (`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`). Built as the +three-step composite — factor the idle target module out of the tower (`qtowerComposeRight k`), +flatten each `qtower` factor to its symmetric power (`qtowerQubitTensorPow`, tensored), then merge +the two symmetric powers into one at the `(k+1) + (d+1)` split (`QSystem.tensorPowAdd`). Its basis +action is `barencoBlockFlatten_congr_ctrlTower`. -/ +def barencoBlockFlatten (k d : ℕ) : + (qtower k (qubit ⊗ qtower d qubit)).Iso (qubit ^⊗ₛ (k + 1 + (d + 1))) := + ((qtowerComposeRight (S := qubit) (M := qtower d qubit) k).trans + (QSystem.Iso.tmul (qtowerQubitTensorPow k) (qtowerQubitTensorPow d))).trans + (QSystem.tensorPowAdd qubit (k + 1) (d + 1)).symm + +/-- **Basis dictionary for the block-flattening bridge.** The bridge +`barencoBlockFlatten k d` carries a block control-tower input — `k` control qubits `c`, one target +`|i⟩`, and an idle module state `towerKet d e` — to the symmetric product basis state over the +concatenated bit-string `Fin.append (Fin.snoc c i) e`: + +`barencoBlockFlatten k d (ctrlTower k c (|i⟩ ⊗ towerKet d e))` +` = ⨂_w |Fin.append (Fin.snoc c i) e w⟩`. + +So the flattened register's `k + 1 + (d + 1)` wires carry, in order, the block's controls `c`, its +target `i`, and the idle module bits `e` — the correspondence on which the per-block `Toffoli` +reduction (matching the tower action of `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` to the +flattened circuit of `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`) is read. Proved by +chaining the three factors' dictionaries through `PureState.congr_trans`/`_tmul` +(`qtowerComposeRight_congr_ctrlTower`, `qtowerQubitTensorPow_congr_towerKet` on each factor via +`ctrlTower_qubitBasis_eq_towerKet`, and the backward `QSystem.tensorPowAdd_symm_congr_piTensor`), +closing on a `Fin.append` bit-string bookkeeping. -/ +theorem barencoBlockFlatten_congr_ctrlTower (k d : ℕ) (c : Fin k → Fin 2) (i : Fin 2) + (e : Fin (d + 1) → Fin 2) : + PureState.congr (barencoBlockFlatten k d) + (ctrlTower k c ((qubitBasis i).tmul (towerKet d e))) + = PureState.piTensor (fun w => qubitBasis (Fin.append (Fin.snoc c i) e w)) := by + rw [barencoBlockFlatten, PureState.congr_trans, PureState.congr_trans, + qtowerComposeRight_congr_ctrlTower, PureState.congr_tmul, + ctrlTower_qubitBasis_eq_towerKet, qtowerQubitTensorPow_congr_towerKet, + qtowerQubitTensorPow_congr_towerKet, QSystem.tensorPowAdd_symm_congr_piTensor] + refine congrArg PureState.piTensor (funext fun w => ?_) + refine Fin.addCases (fun j => ?_) (fun j => ?_) w + · simp only [Fin.append_left] + · simp only [Fin.append_right] + +/-- **Backward basis dictionary for the block-flattening bridge.** The *inverse* bridge +`(barencoBlockFlatten k d).symm` folds the symmetric product state over +`Fin.append (Fin.snoc c i) e` +back into the block control-tower input `ctrlTower k c (|i⟩ ⊗ towerKet d e)` — the direction used +when a gate computed on the flattened register (the `Toffoli` circuit of +`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`) is transported back onto the block's tower. The +`.symm` companion of `barencoBlockFlatten_congr_ctrlTower` via +`PureState.congr_symm_congr`. -/ +theorem barencoBlockFlatten_symm_congr_piTensor (k d : ℕ) (c : Fin k → Fin 2) (i : Fin 2) + (e : Fin (d + 1) → Fin 2) : + PureState.congr (barencoBlockFlatten k d).symm + (PureState.piTensor (fun w => qubitBasis (Fin.append (Fin.snoc c i) e w))) + = ctrlTower k c ((qubitBasis i).tmul (towerKet d e)) := by + rw [← barencoBlockFlatten_congr_ctrlTower, PureState.congr_symm_congr] + +end AxQM diff --git a/LeanPool/AxQM/Core/BarencoBlockReduction.lean b/LeanPool/AxQM/Core/BarencoBlockReduction.lean new file mode 100644 index 0000000000..72fc8f5cfe --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoBlockReduction.lean @@ -0,0 +1,203 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.BarencoBlockFlatten +public import LeanPool.AxQM.Core.McNotCircuitDecomposition + +/-! +# A `barencoNCircuit` internal `Cᵏ(X)` block is a bounded Toffoli circuit on its tower register +(N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`), whose distinctive content is +bottoming its internal multiply-controlled `NOT` blocks `Cᵏ(X)` to genuine `Toffoli`s. Each such +block is `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` acting on the control tower +`qtower k (qubit ⊗ qtower d qubit)` — `k` outer control qubits, the `X`-target the head of the inner +`qubit ⊗ (qtower d qubit)`, and `d + 1` idle target-module wires. + +Three results describe the reduction of one such block, but on **different registers** and only +up to a register bridge: + +* `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` reads the block's computational-basis + action on the **tower** `qtower k (qubit ⊗ qtower d qubit)`; +* `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` exhibits the bounded `O(k²)` `Toffoli` + circuit for `(tensorPowMcCtrlX k).onBlock (d+1)` on the **flattened** register + `qubit ^⊗ₛ (k + 1 + (d + 1))`; +* `barencoBlockFlatten` is the isomorphism `qtower k (qubit ⊗ qtower d qubit) ≃ₛ + qubit ^⊗ₛ (k + 1 + (d + 1))` bridging the two, with its basis dictionary + `barencoBlockFlatten_congr_ctrlTower`. + +This file makes the reduction an honest `Evolution` identity, matching the tower truth table of +`mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` to the flattened circuit of +`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` across the bridge `barencoBlockFlatten` by +computational-basis extensionality (`Evolution.ext_qubitBasis`). + +## What is formalised + +* `barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft` — the **transport identity**: carrying the + block through the flattening bridge lands exactly on the contiguous front-block placement, + `Evolution.congr (barencoBlockFlatten k d) (mcCtrl k (pauliXGate.onLeft (qtower d qubit))) + = (Evolution.tensorPowMcCtrlX k).onBlock (d + 1)`. + Both sides act on a computational product state `⨂ᵢ |c i⟩` as the classical multiply-controlled + `NOT` on the front `k + 1` wires; the left via the block tower truth table + (`mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower`) read through the bridge dictionary + (`barencoBlockFlatten_congr_ctrlTower`), the right via the flattened block truth table + (`tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis`). +* `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` — the **per-block reduction on the tower**: the block + `mcCtrl k (pauliXGate.onLeft (qtower d qubit))`, *on its own control-tower register*, **is** a + genuine circuit `U` of `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) of `O(k²)` count, transported + back onto that register through the flattening bridge: + `mcCtrl k (pauliXGate.onLeft (qtower d qubit)) + = Evolution.congr (barencoBlockFlatten k d).symm U`. + Combines the transport identity with the circuit of + `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` (`= U`) and the gate-transport roundtrip + `Evolution.congr_symm_congr`. This is the per-block decomposition by which every internal `Cᵏ(X)` + block of the no-work-qubit `Cⁿ(X)` circuit is replaced; summed over the `O(n)` blocks it is the + exercise's `O(n²)` gate count. + +## The proof of the transport identity + +`Evolution.ext_qubitBasis` reduces the identity to agreement on every computational product basis +state `⨂ᵢ |c i⟩` of the flattened register `qubit ^⊗ₛ (k + 1 + (d + 1))`. Any such bit-string `c` +splits as `Fin.append (Fin.snoc ctrl tgt) mod` — the front `k` control wires `ctrl`, the target wire +`tgt`, and the trailing `d + 1` idle module wires `mod`. On that input: + +* the **left** side, transported, is computed by the transport law + `Evolution.congr_evolvePure_congr` + and the bridge dictionary `barencoBlockFlatten_congr_ctrlTower` (both directions): it feeds the + input back to the tower state `ctrlTower k ctrl (|tgt⟩ ⊗ towerKet d mod)`, applies the block truth + table `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` flipping the target + `tgt ↦ tgt + [∀ j, ctrl j = 1]`, and folds the result forward + to `⨂ᵢ |Fin.append (Fin.snoc ctrl (tgt + …)) mod i⟩`; +* the **right** side is the flattened block truth table + `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis`, + `⨂ᵢ |mcNot (front controls) (front target) c i⟩`. + +The two land on the same bit-string: `Concrete.ctrlBit` of the front control image equals the tower +guard `∀ j, ctrl j = 1` (`Concrete.ctrlBit_image` + `cnxControls_eq_image_castSucc` + +`Fin.snoc_castSucc`), and `mcNot` flips exactly the target wire, matching the `Fin.snoc` update. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **N&C Exercise 4.29: a `barencoNCircuit` block flattens onto +its front-block placement.** Carrying the internal `Cᵏ(X)` block `mcCtrl k (pauliXGate.onLeft +(qtower d qubit))` — on the control tower `qtower k (qubit ⊗ qtower d qubit)` — through the +block-flattening bridge `barencoBlockFlatten k d` lands exactly on the contiguous +front-block placement `(Evolution.tensorPowMcCtrlX k).onBlock (d + 1)` on the symmetric register +`qubit ^⊗ₛ (k + 1 + (d + 1))` (whose bounded `O(k²)` `Toffoli` circuit +`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` exhibits): + +`Evolution.congr (barencoBlockFlatten k d) (mcCtrl k (pauliXGate.onLeft (qtower d qubit))) + = (Evolution.tensorPowMcCtrlX k).onBlock (d + 1)`. + +Proved by computational-basis extensionality (`Evolution.ext_qubitBasis`): on `⨂ᵢ |c i⟩` (`c` split +into the `k` controls, the target, and the `d + 1` idle module wires) the left side, transported via +`Evolution.congr_evolvePure_congr` and the bridge dictionary `barencoBlockFlatten_congr_ctrlTower`, +is the block tower truth table `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower`, and the right side +is the flattened block truth table `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis`; both flip the +target wire iff every +control is set. -/ +theorem barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft (k d : ℕ) : + Evolution.congr (barencoBlockFlatten k d) (mcCtrl k (pauliXGate.onLeft (qtower d qubit))) + = (Evolution.tensorPowMcCtrlX k).onBlock (d + 1) := by + refine Evolution.ext_qubitBasis fun x => ?_ + -- Split the flattened bit-string `x` into the `k` controls, the target, and the `d+1` idle wires. + set ctrl : Fin k → Fin 2 := fun j => x (Fin.castAdd (d + 1) j.castSucc) with hctrl + set tgt : Fin 2 := x (Fin.castAdd (d + 1) (Fin.last k)) with htgt + set mod : Fin (d + 1) → Fin 2 := fun j => x (Fin.natAdd (k + 1) j) with hmod + have hx : x = Fin.append (Fin.snoc ctrl tgt) mod := by + funext w + refine Fin.addCases (fun j => ?_) (fun j => ?_) w + · rw [Fin.append_left] + induction j using Fin.lastCases with + | last => rw [Fin.snoc_last, htgt] + | cast j => rw [Fin.snoc_castSucc, hctrl] + · rw [Fin.append_right, hmod] + rw [hx] + -- Right side: the flattened block truth table. + rw [tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis] + -- Left side: feed the input to the tower, apply the block truth table, fold back. + rw [← barencoBlockFlatten_congr_ctrlTower k d ctrl tgt mod, Evolution.congr_evolvePure_congr, + mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower, barencoBlockFlatten_congr_ctrlTower] + -- Both sides are `⨂` over a bit-string; reconcile the two front-target flips wire by wire. + refine congrArg PureState.piTensor (funext fun w => ?_) + refine congrArg qubitBasis ?_ + -- `ctrlBit` of the front control image is the tower guard `∀ j, ctrl j = 1`. + have hguard : Concrete.ctrlBit ((cnxControls k).image (Fin.castAdd (d + 1))) + (Fin.append (Fin.snoc ctrl tgt) mod) = if ∀ j, ctrl j = 1 then (1 : Fin 2) else 0 := by + rw [Concrete.ctrlBit_image] + have hpull : (fun j : Fin (k + 1) => + Fin.append (Fin.snoc ctrl tgt) mod (Fin.castAdd (d + 1) j)) = Fin.snoc ctrl tgt := + funext fun j => Fin.append_left _ _ j + rw [hpull, Concrete.ctrlBit, cnxControls_eq_image_castSucc] + simp only [Finset.forall_mem_image, Finset.mem_univ, forall_const, Fin.snoc_castSucc] + refine Fin.addCases (fun j => ?_) (fun j => ?_) w + · rw [Fin.append_left] + induction j using Fin.lastCases with + | last => + rw [Fin.snoc_last, Concrete.mcNot_apply_self, hguard, Fin.append_left, Fin.snoc_last] + | cast j => + have hne : Fin.castAdd (d + 1) (Fin.castSucc j) + ≠ Fin.castAdd (d + 1) (Fin.last k) := by + simp only [ne_eq, Fin.castAdd_inj] + exact Fin.castSucc_ne_last j + rw [Fin.snoc_castSucc, Concrete.mcNot_apply_of_ne _ _ _ hne, Fin.append_left, + Fin.snoc_castSucc] + · have hne : Fin.natAdd (k + 1) j ≠ Fin.castAdd (d + 1) (Fin.last k) := by + simp only [ne_eq, Fin.ext_iff, Fin.val_natAdd, Fin.val_castAdd, Fin.val_last] + omega + rw [Fin.append_right, Concrete.mcNot_apply_of_ne _ _ _ hne, Fin.append_right] + +/-- **N&C Exercise 4.29: a `barencoNCircuit` block is a bounded +`O(k²)` Toffoli circuit on its tower register.** The internal `Cᵏ(X)` block +`mcCtrl k (pauliXGate.onLeft (qtower d qubit))` — as it sits in `barencoNCircuit` on the control +tower `qtower k (qubit ⊗ qtower d qubit)` — **is**, as an `Evolution`, a genuine circuit `U` of +`≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`, target never a control) with `O(k²)` count, transported +onto that tower register through the flattening bridge: + +`mcCtrl k (pauliXGate.onLeft (qtower d qubit)) = Evolution.congr (barencoBlockFlatten k d).symm U`, + +where the circuit `gs` satisfies: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ Concrete.mcNotGateBound k` — the `O(k²)` gate count + (`Concrete.mcNotGateBound_isBigO_sq`); +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs`. + +This is the per-block decomposition by which every internal `Cᵏ(X)` block (`k < n`, always with the +idle module wires as spare) of the no-work-qubit `Cⁿ(X)` circuit is replaced by. Immediate from the +transport identity `barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft`, the flattened +circuit `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` (`= U`), and the gate-transport roundtrip +`Evolution.congr_symm_congr`. -/ +theorem mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit (k d : ℕ) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound k ∧ + (∀ c : Fin (k + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + mcCtrl k (pauliXGate.onLeft (qtower d qubit)) + = Evolution.congr (barencoBlockFlatten k d).symm U := by + obtain ⟨gs, U, hgs, hlen, hUc, hplaced⟩ := + tensorPowMcCtrlX_onBlock_eq_toffoliCircuit (k := k) (b := d + 1) (by omega) + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [← hplaced, ← barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft, Evolution.congr_symm_congr] + +end AxQM diff --git a/LeanPool/AxQM/Core/BarencoLayerBudget.lean b/LeanPool/AxQM/Core/BarencoLayerBudget.lean new file mode 100644 index 0000000000..cf5b65496a --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoLayerBudget.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudget +public import LeanPool.AxQM.Core.BarencoBlockReduction + +/-! +# Every `barencoNCircuit` layer has a `CircuitBudget` (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a `comp`-chain whose +pieces are one Barenco tail layer `barencoTail j W = Cʲ(X) · C(W†) · Cʲ(X) · C(W)` per block index +`j = k, k-1, …, 1`, plus the innermost base `barencoReductionCircuit 0 W` +(`barencoNCircuit_succ` / `barencoNCircuit_zero`, Exercise 4.30). The file +`AxQM/Core/CircuitBudget.lean` gives the compositional gate-count abstraction `CircuitBudget` and +the **per-layer budget for the large layers**, `barencoTail_unCtrl_circuitBudget`: for block index +`≥ 3`, one tail is at most `16 j = O(j)` `≤ 2`-control gates and two single-qubit-controlled gates. + +## What is formalised + +This file completes the per-piece budgets so that **every** piece of the recursion — every tail +layer *and* the base — is accounted for, as the whole-circuit fold requires. + +* `barencoTail_small_circuitBudget` — the **small-block** tail budget. For block index `m ≤ 2` the + block `Cᵐ(X)` is already a single elementary gate (`NOT`/`CNOT`/`Toffoli`), so the block + reduction `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` (which needs only a spare wire, at + **any** index) bottoms it to a gate list of length `≤ mcNotGateBound m = 1`. Hence + `CircuitBudget (barencoTail m (unCtrl d g)) 2 2` — at most two `≤ 2`-control gates (the two + blocks) and exactly two single-qubit-controlled gates `C(W)`, `C(W†)`. + +* `barencoTail_circuitBudget` — the **uniform** per-layer tail budget, for **every** block index + `m ≥ 1`: `CircuitBudget (barencoTail m (unCtrl d g)) (16 m) 2`. It is `barencoTail_small_…` + weakened for `m ≤ 2` and `barencoTail_unCtrl_circuitBudget` for `m ≥ 3`; the common + bound `16 m` (linear) is what makes the summed count over the `O(n)` layers `Σⱼ 16 j = O(n²)`. + +* `barencoReductionCircuit_zero_circuitBudget` — the **base** budget: + `CircuitBudget (barencoReductionCircuit 0 (unCtrl d g)) 2 3`. The base splits as its leading + multiplexer `C⁰(V) = V` (`barencoReductionCircuit_eq_mux_comp_tail`) composed with the tail + `barencoTail 0 W`; the multiplexer is the bare uncontrolled single-qubit gate the `single` + leaf accounts for, and the tail is `barencoTail_small_…` at `m = 0`. + +## Whole-circuit count + +`barencoNCircuit V k 0` is a `comp`-chain of `k` tail layers plus the base +(`barencoNCircuit_succ`), so folding `barencoTail_circuitBudget` (per tail) and +`barencoReductionCircuit_zero_circuitBudget` (the base) over the recursion — via +`CircuitBudget.comp` and `CircuitBudget.cast_congr` — and summing the counts `Σⱼ 16 j = 8 k (k+1)` +gives the whole circuit a `CircuitBudget` with `O(n²)` `≤ 2`-control gates and `O(n)` single-qubit +gates, on exactly the `n + 1`-wire register. Every internal `Cᵏ(X)` block is bottomed linearly by +the split reduction `mcCtrl_pauliXGate_onLeft_eq_splitLinearToffoliCircuit` (in +`AxQM/Core/BarencoSplitLinearBlockReduction.lean`) that the large-layer budget consumes; the small +blocks and base cost `O(1)`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +/-- **N&C Exercise 4.29: the small-block tail budget.** For block index `m ≤ 2` and any +single-qubit root `g : Evolution qubit`, one Barenco tail layer `barencoTail m (unCtrl d g)` — on +the control tower `qtower m (qubit ⊗ qtower d qubit)` — has + +`CircuitBudget (barencoTail m (unCtrl d g)) 2 2`, + +i.e. at most two `≤ 2`-control gates (the two `Cᵐ(X)` blocks, each already a single +`NOT`/`CNOT`/`Toffoli`) and exactly two single-qubit-controlled gates `C(unCtrl d g)`, +`C((unCtrl d g)†)`. For `m ≤ 2` the block `Cᵐ(X)` is elementary, so the block reduction +`mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` bottoms it to a gate list of length +`≤ mcNotGateBound m = 1` (`Concrete.mcNotGateBound_of_le`): the two transported blocks +`B = Evolution.congr (barencoBlockFlatten m d).symm U` each get `block` + `congr`, the two +single-qubit-controlled gates get `ctrlGateAdj` / `ctrlGate`, and `comp` sums the counts +(`2 · 1 = 2` block gates, `2` controlled gates). This is the `m ≤ 2` counterpart of +`barencoTail_unCtrl_circuitBudget` (`m ≥ 3`, linear), completing the per-layer budget at every +index. -/ +theorem barencoTail_small_circuitBudget (m d : ℕ) (hm : m ≤ 2) (g : Evolution qubit) : + CircuitBudget (barencoTail m (unCtrl d g)) 2 2 := by + obtain ⟨gs, U, hgs, hlen, hUc, hblock⟩ := mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit m d + rw [Concrete.mcNotGateBound_of_le hm] at hlen + unfold barencoTail + rw [hblock] + have hB : CircuitBudget (Evolution.congr (barencoBlockFlatten m d).symm U) gs.length 0 := + CircuitBudget.congr (IsWireReindexing.barencoBlockFlatten m d).symm + (CircuitBudget.block gs U hgs hUc) + refine (hB.comp ((CircuitBudget.ctrlGateAdj (n := m) (d := d) g).comp + (hB.comp (CircuitBudget.ctrlGate (n := m) (d := d) g)))).mono ?_ ?_ + · omega + · omega + +/-- **N&C Exercise 4.29: the uniform per-layer tail budget.** For **every** block index +`m ≥ 1` and any single-qubit root `g : Evolution qubit`, one Barenco tail layer +`barencoTail m (unCtrl d g)` has + +`CircuitBudget (barencoTail m (unCtrl d g)) (16 * m) 2`, + +i.e. at most `16 m = O(m)` `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) and exactly two +single-qubit-controlled gates. The common **linear** bound `16 m` is what lets the per-layer counts +be summed to the exercise's `O(n²)` over the `O(n)` layers of `barencoNCircuit` (`Σⱼ 16 j = O(n²)`). +It weakens the small-block budget `barencoTail_small_circuitBudget` (`2 ≤ 16 m`) for `m ≤ 2`, and is +`barencoTail_unCtrl_circuitBudget` verbatim for `m ≥ 3`. -/ +theorem barencoTail_circuitBudget (m d : ℕ) (hm : 1 ≤ m) (g : Evolution qubit) : + CircuitBudget (barencoTail m (unCtrl d g)) (16 * m) 2 := by + by_cases h : m ≤ 2 + · exact (barencoTail_small_circuitBudget m d h g).mono (by omega) le_rfl + · obtain ⟨k, rfl⟩ : ∃ k, m = k + 3 := ⟨m - 3, by omega⟩ + exact barencoTail_unCtrl_circuitBudget (k + 2) d (by omega) g + +/-- **N&C Exercise 4.29: the base budget.** The innermost Barenco reduction layer +`barencoReductionCircuit 0 (unCtrl d g)` — the `k = 0` base of the `barencoNCircuit` recursion — has + +`CircuitBudget (barencoReductionCircuit 0 (unCtrl d g)) 2 3`, + +i.e. at most two `≤ 2`-control gates and three single-qubit gates. The base splits as its leading +multiplexer `C⁰(unCtrl d g) = (unCtrl d g).onRight qubit` composed with the tail `barencoTail 0` +(`barencoReductionCircuit_eq_mux_comp_tail`): the multiplexer is a **bare uncontrolled single-qubit +gate** — the one gate of the recursion accounted for by the `single` leaf, not by any `≤ 2`-control +or *controlled* single-qubit leaf — and the tail contributes `barencoTail_small_circuitBudget` at +`m = 0` (two `NOT` blocks + `C(W)`, `C(W†)`), giving `(0 + 2, 1 + 2) = (2, 3)`. -/ +theorem barencoReductionCircuit_zero_circuitBudget (d : ℕ) (g : Evolution qubit) : + CircuitBudget (barencoReductionCircuit 0 (unCtrl d g)) 2 3 := by + rw [barencoReductionCircuit_eq_mux_comp_tail, mcCtrl_zero] + exact (CircuitBudget.single (d := d) g).comp (barencoTail_small_circuitBudget 0 d (by norm_num) g) + +end AxQM diff --git a/LeanPool/AxQM/Core/BarencoLinearBlockReduction.lean b/LeanPool/AxQM/Core/BarencoLinearBlockReduction.lean new file mode 100644 index 0000000000..3320ba2c7b --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoLinearBlockReduction.lean @@ -0,0 +1,219 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.BarencoTailReduction +public import LeanPool.AxQM.Core.BorrowedMcNotEvolution + +/-! +# A `barencoNCircuit` block/layer is a **linear** Toffoli circuit (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a nested stack of +reduction layers, each `barencoTail k W = Cᵏ(X) · C(W†) · Cᵏ(X) · C(W)` composed under a leading +multiplexer, whose distinctive content is bottoming its internal multiply-controlled +`NOT` blocks `Cᵏ(X)` to genuine `Toffoli`s. + +The block and layer reductions are available **structurally**, but at the `Θ(k²)` per-block count of +the **halving** construction `Concrete.exists_mcNotCircuit` (`Concrete.mcNotGateBound`): + +* `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` — one block on its control tower; +* `barencoTail_pauliXGate_onLeft_eq_toffoliBlocks` — one whole reduction layer. + +Summed over `barencoNCircuit`'s `O(n)` internal blocks that `Θ(k²)` per-block bound is `Θ(n³)` — +overshooting the exercise's `O(n²)`. The **linear-cascade** construction fixes the per-block count: +`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit` exhibits, for the contiguous front-block +placement `(Evolution.tensorPowMcCtrlX k).onBlock b`, a genuine `Evolution` circuit of `≤ 2`-control +gates with the **linear** count `≤ 4 (k - 2) + 1 = O(k)` — provided the register carries at least +`k - 2` idle ambient wires to borrow (`k - 2 ≤ b`, the honest cost of Barenco *Elementary gates* +Lemma 7.2's `k - 2` dirty ancillas). + +This file is the linear counterpart of `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` and +`barencoTail_pauliXGate_onLeft_eq_toffoliBlocks`: it carries the linear circuit of +`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit` up to the `barencoNCircuit` block on its own +control tower, and then to one whole reduction layer, by reusing the structural bridges — the +transport identity `barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft` and the definitional +unfolding of `barencoTail` / `barencoReductionCircuit_eq_mux_comp_tail`. Only the per-block circuit +`U` (hence the count) is swapped `Θ(k²) → O(k)`; the identities are route-independent, so the +proofs are verbatim those of the `Θ(k²)` versions with the linear circuit and its honest wire +budget. + +## What is formalised + +* `mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit` — the **per-block linear reduction on the + tower**. For `2 ≤ k` and the wire budget `k - 2 ≤ d + 1`, the internal `Cᵏ(X)` block + `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` — as it sits in `barencoNCircuit` on the control + tower `qtower k (qubit ⊗ qtower d qubit)`, with its `d + 1` idle module wires the borrowed dirty + ancillas — **is**, as an `Evolution`, a genuine circuit `U` of `≤ 2`-control gates + (`Toffoli`/`CNOT`/`NOT`) with the **linear** count `≤ 4 (k - 2) + 1`, transported onto that tower + register through the flattening bridge: + `mcCtrl k (pauliXGate.onLeft (qtower d qubit)) + = Evolution.congr (barencoBlockFlatten k d).symm U`. The linear counterpart of + `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit`; obtained from the linear circuit and the transport + identity by the gate-transport roundtrip `Evolution.congr_symm_congr`. + +* `barencoTail_pauliXGate_onLeft_eq_linearToffoliBlocks` / + `barencoReductionCircuit_pauliXGate_onLeft_eq_linearToffoliBlocks` — the **per-layer linear + reduction**. For `1 ≤ k` and the budget `k - 1 ≤ d + 1`, one Barenco tail layer + `barencoTail (k+1) W` (resp. the full Figure-4.8 layer `barencoReductionCircuit (k+1) W`) is the + `Evolution` composition `B · C(W†) · B · C(W)` (resp. with the leading multiplexer `Cᵏ⁺¹(W)` + kept), where the two `Cᵏ⁺¹(X)` blocks are **both** the single transported linear circuit + `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` of the per-block reduction — of length + `≤ 4 (k + 1 - 2) + 1`. The linear counterpart of + `barencoTail_pauliXGate_onLeft_eq_toffoliBlocks`; immediate from the per-block reduction + and the definitional unfolding of `barencoTail` (`barencoReductionCircuit_eq_mux_comp_tail`). + +## The wire budget — an honest scoping note + +The budget `k - 2 ≤ d + 1` (per block) / `k - 1 ≤ d + 1` (per layer at level `k+1`) is Lemma 7.2's +requirement of `k - 2` borrowed **dirty** ancillas among the block's `d + 1` idle module wires. In +`barencoNCircuit V (n-1) 0` an internal `Cʲ(X)` block sits at recursion depth `d = (n-1) - j`, so it +has `d + 1 = n - j` idle module wires; the budget `j - 2 ≤ n - j` holds exactly for the smaller +blocks `j ≤ n/2 + 1`. The larger blocks (down to the top `C^{n-1}(X)` with a single idle wire) carry +too few module ancillas for Lemma 7.2 directly, and are the regime of Barenco's one-dirty-ancilla +Lemma 7.3 (splitting a `Cᵐ(X)` into two `≈ Cᵐ/²(X)` sub-blocks, each satisfying Lemma 7.2 on the +other half). That budget-free version is in `AxQM/Core/BarencoSplitLinearBlockReduction.lean`; this +file uses only the Lemma 7.2 double cascade `Concrete.borrowedMcNot`, and delivers the linear +per-block / per-layer reduction wherever the module-wire budget suffices. The parity obstruction +still forbids a permutation-only circuit on exactly `n + 1` wires, so the `√X` +single-qubit-controlled gates `C(W)`/`C(W†)` remain essential and stay intact here. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **N&C Exercise 4.29: a `barencoNCircuit` block is a bounded **linear** `O(k)` Toffoli +circuit on its tower register.** For `2 ≤ k` and the wire budget `k - 2 ≤ d + 1`, the internal +`Cᵏ(X)` block `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` — as it sits in `barencoNCircuit` on +the control tower `qtower k (qubit ⊗ qtower d qubit)`, with its `d + 1` idle module wires available +as borrowed **dirty** ancillas — **is**, as an `Evolution`, a genuine circuit `U` of `≤ 2`-control +gates (`Toffoli`/`CNOT`/`NOT`, target never a control) with the **linear** count `≤ 4 (k - 2) + 1`, +transported onto that tower register through the flattening bridge: + +`mcCtrl k (pauliXGate.onLeft (qtower d qubit)) = Evolution.congr (barencoBlockFlatten k d).symm U`, + +where the circuit `gs` satisfies: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 4 * (k - 2) + 1` — the **linear** `O(k)` gate count (versus the `Θ(k²)` of + `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit`), + the count the `O(n²)` assembly needs; +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs`. + +The linear counterpart of `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit`: identical proof, +with the **linear** circuit `tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit` in place of +the `Θ(k²)` one `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`, its wire budget `k - 2 ≤ b = d + 1` +threaded through. Immediate from that circuit, the transport identity +`barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft`, and the +gate-transport roundtrip `Evolution.congr_symm_congr`. -/ +theorem mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit (k d : ℕ) (hk : 2 ≤ k) + (hb : k - 2 ≤ d + 1) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 4 * (k - 2) + 1 ∧ + (∀ c : Fin (k + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + mcCtrl k (pauliXGate.onLeft (qtower d qubit)) + = Evolution.congr (barencoBlockFlatten k d).symm U := by + obtain ⟨gs, U, hgs, hlen, hUc, hplaced⟩ := + tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit (k := k) (b := d + 1) hk hb + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [← hplaced, ← barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft, Evolution.congr_symm_congr] + +/-- **N&C Exercise 4.29: one Barenco reduction layer's `Cᵏ(X)` blocks are a bounded +**linear** Toffoli circuit.** For `1 ≤ k` and the wire budget `k - 1 ≤ d + 1`, and every +single-qubit-chain gate `W : Evolution (qtower d qubit)`, the Barenco tail layer +`barencoTail (k+1) W` — on the control tower `qtower (k+1) (qubit ⊗ qtower d qubit)` — is the +`Evolution` composition + +`barencoTail (k+1) W = B · C(W†) · B · C(W)`, + +where the two `Cᵏ⁺¹(X)` blocks `mcCtrl (k+1) (pauliXGate.onLeft (qtower d qubit))` are **both** the +single transported **linear** circuit `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` of +the per-block reduction, and `C(W) = unCtrl (k+1) (controlledUnitary W)`, +`C(W†) = unCtrl (k+1) (controlledUnitary W.adjoint)` are the single-qubit-controlled gates. The +transported block `B` carries the linear certificates for `gs`: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — every gate is a `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 4 * (k + 1 - 2) + 1` — the **linear** per-block gate count; +* `U` acts on every computational basis state `⨂ᵢ |c i⟩` as the classical circuit `mcNotDenote gs`. + +So one layer's whole `≤ 2`-control content is `2 · gs.length ≤ 2 · (4 (k+1-2) + 1)` (the same `gs` +twice), plus two single-qubit-controlled gates. The linear counterpart of +`barencoTail_pauliXGate_onLeft_eq_toffoliBlocks`; immediate from the per-block linear reduction +`mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit` (at index `k+1`, whence the budget +`k - 1 ≤ d + 1`) and the definition of `barencoTail`. -/ +theorem barencoTail_pauliXGate_onLeft_eq_linearToffoliBlocks (k d : ℕ) (hk : 1 ≤ k) + (hb : k - 1 ≤ d + 1) (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 4 * (k + 1 - 2) + 1 ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoTail (k + 1) W + = (Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W)))) := by + obtain ⟨gs, U, hgs, hlen, hUc, hblock⟩ := + mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit (k + 1) d (by omega) (by omega) + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + unfold barencoTail + rw [hblock] + +/-- **N&C Exercise 4.29: one full Figure-4.8 reduction layer, with its `Cᵏ(X)` blocks +bottomed to **linear** Toffolis.** For `1 ≤ k` and the wire budget `k - 1 ≤ d + 1`, and +single-qubit-chain gate `W : Evolution (qtower d qubit)`, the whole Figure-4.8 reduction circuit +`barencoReductionCircuit (k+1) W` (= `Cᵏ⁺¹(W) · barencoTail (k+1) W`, +`barencoReductionCircuit_eq_mux_comp_tail`) is the `Evolution` composition + +`barencoReductionCircuit (k+1) W = Cᵏ⁺¹(W) · B · C(W†) · B · C(W)`, + +with the leading multiplexer `Cᵏ⁺¹(W) = mcCtrl (k+1) (W.onRight qubit)` left as is (it is what the +`barencoNCircuit` recursion expands next), the two `Cᵏ⁺¹(X)` blocks replaced by the single +transported **linear** `≤ 2`-control circuit +`B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` +(certificates as in `barencoTail_pauliXGate_onLeft_eq_linearToffoliBlocks`, length +`≤ 4 (k + 1 - 2) + 1`), and the two single-qubit-controlled gates `C(W)`, `C(W†)` kept. This is the +reduction layer exactly as it appears in `barencoNCircuit`, with its multiply-controlled `NOT`s +bottomed to a linear Toffoli count. The linear counterpart of +`barencoReductionCircuit_pauliXGate_onLeft_eq_toffoliBlocks`; immediate from +`barencoReductionCircuit_eq_mux_comp_tail` and the tail reduction. -/ +theorem barencoReductionCircuit_pauliXGate_onLeft_eq_linearToffoliBlocks (k d : ℕ) (hk : 1 ≤ k) + (hb : k - 1 ≤ d + 1) (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 4 * (k + 1 - 2) + 1 ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoReductionCircuit (k + 1) W + = (mcCtrl (k + 1) (W.onRight qubit)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W))))) := by + obtain ⟨gs, U, hgs, hlen, hUc, htail⟩ := + barencoTail_pauliXGate_onLeft_eq_linearToffoliBlocks k d hk hb W + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [barencoReductionCircuit_eq_mux_comp_tail, htail] + +end AxQM diff --git a/LeanPool/AxQM/Core/BarencoSplitLinearBlockReduction.lean b/LeanPool/AxQM/Core/BarencoSplitLinearBlockReduction.lean new file mode 100644 index 0000000000..134b462468 --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoSplitLinearBlockReduction.lean @@ -0,0 +1,215 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.BarencoTailReduction +public import LeanPool.AxQM.Core.SplitMcNotOnBlock + +/-! +# A `barencoNCircuit` block/layer is a budget-free linear Toffoli circuit (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a nested stack of +reduction layers, each `barencoTail k W = Cᵏ(X) · C(W†) · Cᵏ(X) · C(W)` composed under a leading +multiplexer, whose distinctive content is bottoming its internal multiply-controlled +`NOT` blocks `Cᵏ(X)` to genuine `Toffoli`s at a **linear** `O(k)` per-block count (so the summed +count over `barencoNCircuit`'s `O(n)` blocks is the exercise's `O(n²)`, not `O(n³)`). + +The file `AxQM/Core/BarencoLinearBlockReduction.lean` carries a **linear** `O(k)` per-block / +per-layer circuit up to the `barencoNCircuit` block on its own control tower, but through the +Lemma-7.2 dirty cascade (`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit`), which needs +`k - 2` idle ambient wires to borrow — the honest wire budget `k - 2 ≤ d + 1` (per block) / +`k - 1 ≤ d + 1` (per layer at level `k+1`). That budget is met only by the **smaller** blocks of +`barencoNCircuit` (`j ≤ n/2 + 1`); the **larger** blocks — down to the top `C^{n-1}(X)` with a +single idle module wire — carry too few module ancillas for Lemma 7.2 directly, so that +reduction does **not** cover them. + +The file `AxQM/Core/SplitMcNotOnBlock.lean` closes that gap at the block level: through Barenco's +**Lemma 7.3** control split (`tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit`) the contiguous +front-block `Cᵏ(X)` `(Evolution.tensorPowMcCtrlX k).onBlock b` is a linear `≤ 8 k = O(k)` Toffoli +circuit needing just **one** borrowed dirty wire (`1 ≤ b`, `k ≥ 3`) — the two control halves +supplying each other's Lemma-7.2 ancillas. + +## What is formalised + +This file is the split-route, budget-free counterpart of +`AxQM/Core/BarencoLinearBlockReduction.lean`. It carries the +one-borrowed-wire linear circuit of `tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit` up to +the `barencoNCircuit` block on its own control tower, and then to one whole reduction layer, by +reusing the structural bridges — the transport identity +`barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft` and the definitional unfolding of +`barencoTail` / `barencoReductionCircuit_eq_mux_comp_tail`. Only the per-block circuit `U` (hence +the count `≤ 8 k`) and its **wire budget** change: the condition `1 ≤ b = d + 1` holds for +**every** `d` (`d + 1 ≥ 1` always), so the reductions here carry **no wire-budget hypothesis at +all** — they apply uniformly to every internal block of `barencoNCircuit`, including the largest. +The identities themselves are route-independent, so the proofs are verbatim those of +`BarencoLinearBlockReduction` with the split circuit in place of the `k - 2`-borrowed one. + +* `mcCtrl_pauliXGate_onLeft_eq_splitLinearToffoliCircuit` — the **per-block** reduction on the + tower. For `3 ≤ k` and **no** wire budget, the internal `Cᵏ(X)` block + `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` — as it sits in `barencoNCircuit` on the control + tower `qtower k (qubit ⊗ qtower d qubit)`, with its `d + 1` idle module wires supplying the single + borrowed dirty ancilla — **is**, as an `Evolution`, a genuine circuit `U` of `≤ 2`-control gates + (`Toffoli`/`CNOT`/`NOT`) with the **linear** count `≤ 8 k`, transported onto that tower register: + `mcCtrl k (pauliXGate.onLeft (qtower d qubit)) = Evolution.congr (barencoBlockFlatten k d).symm U` + (no borrowed-wire hypothesis). + +* `barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks` / + `barencoReductionCircuit_pauliXGate_onLeft_eq_splitLinearToffoliBlocks` — the **per-layer** + reduction. For `2 ≤ k` (so the block index `k + 1 ≥ 3`) and **no** wire budget, one Barenco tail + layer `barencoTail (k+1) W` (resp. the full Figure-4.8 layer `barencoReductionCircuit (k+1) W`) + is the `Evolution` composition `B · C(W†) · B · C(W)` (resp. with the leading multiplexer + `Cᵏ⁺¹(W)` kept), where the two `Cᵏ⁺¹(X)` blocks are **both** the single transported linear circuit + `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` of the per-block reduction — of length + `≤ 8 (k + 1)`. + +## The count for the whole circuit + +This removes the `k - 2 ≤ d + 1` wire budget of `BarencoLinearBlockReduction` entirely: a single +idle module wire — which **every** internal `barencoNCircuit` block has — now suffices to bottom +**any** block linearly. Applied uniformly across the `O(n)` internal `Cᵏ(X)` blocks of +`barencoNCircuit`, the linear `O(k)` per-block count gives the exercise's `O(n²)` total on exactly +the `n + 1`-wire register, with no cubic count and no gap for the large blocks. The parity +obstruction still forbids a permutation-only circuit on exactly `n + 1` wires, so the `√X` +single-qubit-controlled gates `C(W)`/`C(W†)` remain essential; the one borrowed ancilla here is an +idle tower module wire, staying within the `n + 1`-wire register (Barenco *Elementary gates for +quantum computation*, Lemma 7.3). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **N&C Exercise 4.29: a `barencoNCircuit` block is a budget-free bounded **linear** +`O(k)` Toffoli circuit on its tower register.** For `3 ≤ k` and **no** wire budget, the internal +`Cᵏ(X)` block `mcCtrl k (pauliXGate.onLeft (qtower d qubit))` — as it sits in `barencoNCircuit` on +the control tower `qtower k (qubit ⊗ qtower d qubit)`, with its `d + 1` idle module wires supplying +the single borrowed **dirty** ancilla — **is**, as an `Evolution`, a genuine circuit `U` of +`≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`, target never a control) with the **linear** count +`≤ 8 k`, transported onto that tower register through the flattening bridge: + +`mcCtrl k (pauliXGate.onLeft (qtower d qubit)) = Evolution.congr (barencoBlockFlatten k d).symm U`, + +where the circuit `gs` satisfies: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 8 * k` — the **linear** `O(k)` gate count, the count the `O(n²)` assembly needs; +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs`. + +The split-route counterpart of `mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit`: +identical proof, with the one-borrowed-wire circuit +`tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit` in place of the `k - 2`-borrowed +`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit`, +whose wire budget `1 ≤ b = d + 1` holds for every `d` — so, unlike that one, this reduction carries +**no** wire budget and applies to every internal block. Immediate from that circuit, the transport +identity `barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft`, and the gate-transport roundtrip +`Evolution.congr_symm_congr`. -/ +theorem mcCtrl_pauliXGate_onLeft_eq_splitLinearToffoliCircuit (k d : ℕ) (hk : 3 ≤ k) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 8 * k ∧ + (∀ c : Fin (k + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + mcCtrl k (pauliXGate.onLeft (qtower d qubit)) + = Evolution.congr (barencoBlockFlatten k d).symm U := by + obtain ⟨gs, U, hgs, hlen, hUc, hplaced⟩ := + tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit (k := k) (b := d + 1) hk (by omega) + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [← hplaced, ← barencoBlockFlatten_congr_mcCtrl_pauliXGate_onLeft, Evolution.congr_symm_congr] + +/-- **N&C Exercise 4.29: one Barenco reduction layer's `Cᵏ(X)` blocks are a budget-free +bounded **linear** Toffoli circuit.** For `2 ≤ k` (so the block index `k + 1 ≥ 3`), **no** wire +budget, and every single-qubit-chain gate `W : Evolution (qtower d qubit)`, the Barenco tail layer +`barencoTail (k+1) W` — on the control tower `qtower (k+1) (qubit ⊗ qtower d qubit)` — is the +`Evolution` composition + +`barencoTail (k+1) W = B · C(W†) · B · C(W)`, + +where the two `Cᵏ⁺¹(X)` blocks `mcCtrl (k+1) (pauliXGate.onLeft (qtower d qubit))` are **both** the +single transported **linear** circuit `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` of +the per-block reduction, and `C(W) = unCtrl (k+1) (controlledUnitary W)`, +`C(W†) = unCtrl (k+1) (controlledUnitary W.adjoint)` are the single-qubit-controlled gates. The +transported block `B` carries the linear certificates for `gs`: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — every gate is a `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 8 * (k + 1)` — the **linear** per-block gate count; +* `U` acts on every computational basis state `⨂ᵢ |c i⟩` as the classical circuit `mcNotDenote gs`. + +So one layer's whole `≤ 2`-control content is `2 · gs.length ≤ 2 · 8 (k+1)` (the same `gs` twice), +plus two single-qubit-controlled gates. The split-route counterpart of +`barencoTail_pauliXGate_onLeft_eq_linearToffoliBlocks`, but **budget-free**; immediate from the +per-block split reduction `mcCtrl_pauliXGate_onLeft_eq_splitLinearToffoliCircuit` (at index `k+1`, +whence `3 ≤ k + 1` from `2 ≤ k`) and the definition of `barencoTail`. -/ +theorem barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks (k d : ℕ) (hk : 2 ≤ k) + (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 8 * (k + 1) ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoTail (k + 1) W + = (Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W)))) := by + obtain ⟨gs, U, hgs, hlen, hUc, hblock⟩ := + mcCtrl_pauliXGate_onLeft_eq_splitLinearToffoliCircuit (k + 1) d (by omega) + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + unfold barencoTail + rw [hblock] + +/-- **N&C Exercise 4.29: one full Figure-4.8 reduction layer, with its `Cᵏ(X)` blocks +bottomed to budget-free **linear** Toffolis.** For `2 ≤ k` (so the block index `k + 1 ≥ 3`), **no** +wire budget, and single-qubit-chain gate `W : Evolution (qtower d qubit)`, the whole Figure-4.8 +reduction circuit `barencoReductionCircuit (k+1) W` (= `Cᵏ⁺¹(W) · barencoTail (k+1) W`, +`barencoReductionCircuit_eq_mux_comp_tail`) is the `Evolution` composition + +`barencoReductionCircuit (k+1) W = Cᵏ⁺¹(W) · B · C(W†) · B · C(W)`, + +with the leading multiplexer `Cᵏ⁺¹(W) = mcCtrl (k+1) (W.onRight qubit)` left as is (it is what the +`barencoNCircuit` recursion expands next), the two `Cᵏ⁺¹(X)` blocks replaced by the single +transported **linear** `≤ 2`-control circuit +`B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` +(certificates as in `barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks`, length +`≤ 8 (k + 1)`), and the two single-qubit-controlled gates `C(W)`, `C(W†)` kept. This is the +reduction layer exactly as it appears in `barencoNCircuit`, with its multiply-controlled `NOT`s +bottomed to a budget-free linear Toffoli count. The split-route counterpart of +`barencoReductionCircuit_pauliXGate_onLeft_eq_linearToffoliBlocks`; immediate from +`barencoReductionCircuit_eq_mux_comp_tail` and the tail reduction. -/ +theorem barencoReductionCircuit_pauliXGate_onLeft_eq_splitLinearToffoliBlocks (k d : ℕ) (hk : 2 ≤ k) + (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 8 * (k + 1) ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoReductionCircuit (k + 1) W + = (mcCtrl (k + 1) (W.onRight qubit)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W))))) := by + obtain ⟨gs, U, hgs, hlen, hUc, htail⟩ := + barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks k d hk W + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [barencoReductionCircuit_eq_mux_comp_tail, htail] + +end AxQM diff --git a/LeanPool/AxQM/Core/BarencoTailReduction.lean b/LeanPool/AxQM/Core/BarencoTailReduction.lean new file mode 100644 index 0000000000..52c2a9489d --- /dev/null +++ b/LeanPool/AxQM/Core/BarencoTailReduction.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.BarencoBlockReduction + +/-! +# One Barenco reduction layer's `Cᵏ(X)` blocks are bounded Toffoli circuits (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a nested stack of +**reduction layers**, each layer being a `barencoTail k W` composed under a leading multiplexer +(`barencoReductionCircuit_eq_mux_comp_tail`). Every `barencoTail k W` is, by definition, + +`barencoTail k W = Cᵏ(X) · C(W†) · Cᵏ(X) · C(W)` + +— **two** multiply-controlled `NOT` blocks `Cᵏ(X) = mcCtrl k (pauliXGate.onLeft M)` and two +single-qubit-controlled gates `C(W)`, `C(W†)` (`unCtrl k (controlledUnitary …)`), where in +`barencoNCircuit` the target module is `M = qtower d qubit` (the `d` already-peeled controls, idle). +The exercise's distinctive content is bottoming those `Cᵏ(X)` blocks to genuine `Toffoli`s. + +`mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` does this for **one** block on its control +tower. This file lifts that to one whole layer: it replaces both `Cᵏ(X)` blocks of a +`barencoTail (k+1) W` (`W : Evolution (qtower d qubit)`) by the transported bounded +`≤ 2`-control (`Toffoli`/`CNOT`/`NOT`) circuit of that theorem, leaving the two +single-qubit-controlled gates `C(W)`, `C(W†)` intact. It is the per-layer object that is folded over +the recursion of `barencoNCircuit`. + +## What is formalised + +`barencoTail_pauliXGate_onLeft_eq_toffoliBlocks` — for every `k`, `d` and every single-qubit-chain +gate `W : Evolution (qtower d qubit)`, one Barenco tail layer is an honest `Evolution` composition + +`barencoTail (k+1) W = B · C(W†) · B · C(W)`, + +where `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` is the transported circuit of +`mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` — +a genuine circuit `gs` of `≤ 2`-control gates (`∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1`), of length +`gs.length ≤ mcNotGateBound (k+1)`, acting on every computational basis state as `mcNotDenote gs` — +and `C(W)`, `C(W†)` are the single-qubit-controlled gates (`unCtrl (k+1) (controlledUnitary …)`). +The **same** block circuit `B` serves both `Cᵏ⁺¹(X)` occurrences (they are the identical gate), so +the layer's whole `≤ 2`-control content is `2 · gs.length ≤ 2 · mcNotGateBound (k+1)` plus the two +single-qubit-controlled gates. Immediate from `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` and the +definitional unfolding of `barencoTail`. + +## The gate count — an honest scoping note + +This file gives property **(ii)** of the exercise (each block is a genuine +`Toffoli`/`CNOT`/`NOT` circuit) at the layer level; it does **not** by itself give the +exercise's **(iii)** `O(n²)` count for the whole `barencoNCircuit`. `barencoNCircuit V k 0` has one +layer for each `j = 1, …, k`, contributing two `Cʲ(X)` blocks; summing the per-block bound +over the layers gives `Σⱼ 2·mcNotGateBound j`, and `mcNotGateBound` is `Θ(j²)`, so the +sum is `Θ(k³) = O(n³)`, **not** the exercise's `O(n²)`. Barenco's `O(n²)` needs each `Cʲ(X)` block +bottomed in `O(j)` **linear** `Toffoli`s using an available idle wire as a borrowed (dirty) ancilla +(Barenco *Elementary gates*, Lemma 7.2 / 7.3); that construction is in +`AxQM/Core/BarencoLinearBlockReduction.lean` and `AxQM/Core/BarencoSplitLinearBlockReduction.lean` +(the `Θ(k²)` halving used here is `Concrete.exists_mcNotCircuit`). This layer reduction stays valid +for it (it is a **structural** identity — only the per-block length bound `B` carries is replaced). +The structure given here (`2` bounded blocks + `2` single-qubit-controlled gates per layer) is +route-independent. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **N&C Exercise 4.29: one Barenco reduction layer's `Cᵏ(X)` +blocks are a bounded Toffoli circuit.** For every `k`, `d` and every single-qubit-chain gate +`W : Evolution (qtower d qubit)`, the Barenco tail layer `barencoTail (k+1) W` — on the control +tower `qtower (k+1) (qubit ⊗ qtower d qubit)` — is the `Evolution` composition + +`barencoTail (k+1) W = B · C(W†) · B · C(W)`, + +where the two `Cᵏ⁺¹(X)` blocks `mcCtrl (k+1) (pauliXGate.onLeft (qtower d qubit))` are **both** the +single transported circuit `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` of +`mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit`, +and `C(W) = unCtrl (k+1) (controlledUnitary W)`, `C(W†) = unCtrl (k+1) (controlledUnitary +W.adjoint)` are the two single-qubit-controlled gates. The transported block `B` carries the +certificates of that theorem for the circuit `gs : List (McNotGate (k+1+1+(d+1)))`: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — every gate is a `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ mcNotGateBound (k+1)` — the per-block gate count; +* `U` acts on every computational basis state `⨂ᵢ |c i⟩` as the classical circuit `mcNotDenote gs`. + +So one layer's whole `≤ 2`-control content is `2 · gs.length` (the same `gs` twice), plus two +single-qubit-controlled gates. This is the per-layer object that the full `barencoNCircuit` +assembly folds over; see the file docstring for the honest `O(n²)`-vs-`O(n³)` count scoping. +Immediate from `mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit` and the definition of +`barencoTail`. -/ +theorem barencoTail_pauliXGate_onLeft_eq_toffoliBlocks (k d : ℕ) + (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound (k + 1) ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoTail (k + 1) W + = (Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W)))) := by + obtain ⟨gs, U, hgs, hlen, hUc, hblock⟩ := + mcCtrl_pauliXGate_onLeft_eq_toffoliCircuit (k + 1) d + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + unfold barencoTail + rw [hblock] + +/-- **N&C Exercise 4.29: one full Figure-4.8 reduction layer, with +its `Cᵏ(X)` blocks bottomed to Toffolis.** For every `k`, `d` and single-qubit-chain gate +`W : Evolution (qtower d qubit)`, the whole Figure-4.8 reduction circuit `barencoReductionCircuit +(k+1) W` (= `Cᵏ⁺¹(W) · barencoTail (k+1) W`, `barencoReductionCircuit_eq_mux_comp_tail`) is the +`Evolution` composition + +`barencoReductionCircuit (k+1) W = Cᵏ⁺¹(W) · B · C(W†) · B · C(W)`, + +with the leading multiplexer `Cᵏ⁺¹(W) = mcCtrl (k+1) (W.onRight qubit)` left as is (it is what the +`barencoNCircuit` recursion expands next), the two `Cᵏ⁺¹(X)` blocks replaced by the single +transported bounded `≤ 2`-control circuit `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` +(certificates as in `barencoTail_pauliXGate_onLeft_eq_toffoliBlocks`), and the two +single-qubit-controlled gates `C(W)`, `C(W†)` kept. This is the reduction layer exactly as it +appears in `barencoNCircuit`, with its multiply-controlled `NOT`s bottomed. Immediate from +`barencoReductionCircuit_eq_mux_comp_tail` and the tail reduction. -/ +theorem barencoReductionCircuit_pauliXGate_onLeft_eq_toffoliBlocks (k d : ℕ) + (W : Evolution (qtower d qubit)) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + 1 + (d + 1)))) + (U : Evolution (qubit ^⊗ₛ (k + 1 + 1 + (d + 1)))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound (k + 1) ∧ + (∀ c : Fin (k + 1 + 1 + (d + 1)) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + barencoReductionCircuit (k + 1) W + = (mcCtrl (k + 1) (W.onRight qubit)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + ((unCtrl (k + 1) (controlledUnitary W.adjoint)).comp + ((Evolution.congr (barencoBlockFlatten (k + 1) d).symm U).comp + (unCtrl (k + 1) (controlledUnitary W))))) := by + obtain ⟨gs, U, hgs, hlen, hUc, htail⟩ := + barencoTail_pauliXGate_onLeft_eq_toffoliBlocks k d W + refine ⟨gs, U, hgs, hlen, hUc, ?_⟩ + rw [barencoReductionCircuit_eq_mux_comp_tail, htail] + +end AxQM diff --git a/LeanPool/AxQM/Core/BorrowedMcNotEvolution.lean b/LeanPool/AxQM/Core/BorrowedMcNotEvolution.lean new file mode 100644 index 0000000000..e8e2a16bff --- /dev/null +++ b/LeanPool/AxQM/Core/BorrowedMcNotEvolution.lean @@ -0,0 +1,199 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.McNotCircuitDecomposition +public import LeanPool.AxQM.Concrete.MultiControlledNotBorrowedMcNot + +/-! +# The dirty-ancilla `Cᵏ(X)` is a **linear** `Evolution` circuit (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The per-block decomposition +`exists_mcNotCircuitEvolution_eq_placedMcNot` realises a placed `Cᵏ(X)` as a genuine `Evolution` +circuit, but only through the **halving** classical construction +`Concrete.exists_mcNotCircuit`, whose gate count is `Θ(k²)` (`Concrete.mcNotGateBound`). Summed over +`barencoNCircuit`'s `O(n)` internal blocks that is `Θ(n³)` — overshooting the exercise's `O(n²)`. + +The file `AxQM/Concrete/MultiControlledNotBorrowedMcNot.lean` fixes the *classical* count: the +double borrowed-wire cascade `Concrete.borrowedMcNot as cs tgt` is a genuine `Cᵏ(X)` in a **linear** +`≤ 4|as| + 1` `Toffoli`/`CNOT`/`NOT` gates (`|as| = |cs| - 2` **dirty** borrowed ancillas, +`Concrete.mcNotDenote_borrowedMcNot`; Barenco *Elementary gates*, Lemma 7.2/7.3). This file lifts +that linear classical circuit to the closed-system `Evolution` level. + +## What is formalised + +* `exists_borrowedCircuitEvolution_eq_placedMcNot` — the **abstract linear lift**. For control and + borrowed-ancilla wire lists `cs`, `as` with `|cs| = |as| + 2` (all distinct, target `tgt` off + both), the placed multiply-controlled `NOT` `Evolution.placedMcNot cs.toFinset tgt` **equals**, as + an `Evolution` on `qubit ^⊗ₛ m`, a genuine circuit `gs` of `≤ 2`-control gates with the **linear** + count `gs.length ≤ 4 |as| + 1 = O(|cs|)` — not the `Θ(k²)` of + `exists_mcNotCircuitEvolution_eq_placedMcNot`. The `Evolution`-level + counterpart of the classical statement: feed `Concrete.borrowedMcNot as cs tgt` (whose gates are + `≤ 2`-control by `borrowedMcNot_gate_mem` and whose denotation is `Concrete.mcNot cs.toFinset tgt` + by `mcNotDenote_borrowedMcNot`) to the whole-circuit lift `exists_mcNotCircuitEvolution`, then + identify the result with the placed gate by computational-basis extensionality + (`Evolution.ext_qubitBasis`, both act as `Concrete.mcNot cs.toFinset tgt`). + +* `tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit` — the **contiguous front-block** form the + Barenco assembly consumes. Whenever the register carries at least `k - 2` idle ambient wires to + borrow (`k - 2 ≤ b`, the honest wire budget of Lemma 7.2's `k - 2` dirty ancillas), the + block-embedded `Cᵏ(X)` `(Evolution.tensorPowMcCtrlX k).onBlock b` on `qubit ^⊗ₛ (k+1+b)` equals a + genuine `Evolution` circuit of `≤ 2`-control gates with the **linear** count + `≤ 4 (k - 2) + 1 = O(k)`. The linear-count counterpart of + `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`, obtained by instantiating the abstract lift at + `cs =` the `k` front control wires `(cnxControls k).image (Fin.castAdd b)` and `as =` the first + `k - 2` ambient wires `Fin.natAdd (k+1) ·`, then matching to `onBlock` through the block truth + table `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis`. + +## The count for `barencoNCircuit` + +This replaces the `Θ(k²)` per-block bound of `exists_mcNotCircuitEvolution_eq_placedMcNot` and +`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` by the `O(k)` linear one. Summed over the +`O(n)` internal `Cᵏ(X)` blocks of the no-work-qubit `Cⁿ(X)` circuit (`barencoNCircuit`), the +linear per-block count gives the exercise's `O(n²)` rather than `O(n³)`. The +wire budget `k - 2 ≤ b` is the honest cost of the Lemma 7.2 construction (`k - 2` borrowed dirty +ancillas); it is discharged from `barencoNCircuit`'s idle-wire register in +`AxQM/Core/BarencoLinearBlockReduction.lean`, and the one-borrowed-ancilla Lemma 7.3 route where the +budget is tighter is in `AxQM/Core/BarencoSplitLinearBlockReduction.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +/-- **N&C Exercise 4.29: the dirty-ancilla `Cᵏ(X)` is a linear `Evolution` circuit.** +Given a control wire list `cs`, a borrowed dirty-ancilla wire list `as` with `|cs| = |as| + 2`, a +target `tgt`, all wires distinct (`cs.Nodup`, `as.Nodup`, `cs.Disjoint as`, `tgt ∉ cs`, `tgt ∉ as`), +there is a circuit `gs` of gates each with at most two controls (a `Toffoli`/`CNOT`/`NOT`, target +never a control) and a single closed-system `Evolution U` on `qubit ^⊗ₛ m` with: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 4 * as.length + 1` — the **linear** `O(|cs|)` gate count (`|as| = |cs| - 2`), the + count the `O(n²)` assembly needs, versus the `Θ(k²)` halving bound of + `exists_mcNotCircuitEvolution_eq_placedMcNot`; +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs` — so `U` *is* the placed gate sequence of `gs`; and +* `Evolution.placedMcNot cs.toFinset tgt = U` — the placed multiply-controlled `NOT` on the wires + `(cs.toFinset, tgt)` **is** that linear circuit, as an `Evolution`. + +The `Evolution`-level lift of the classical `Concrete.mcNotDenote_borrowedMcNot`: the classical +circuit is `Concrete.borrowedMcNot as cs tgt` (gate set by `Concrete.borrowedMcNot_gate_mem`, length +by `Concrete.borrowedMcNot_length_le`, denotation `= Concrete.mcNot cs.toFinset tgt` by +`Concrete.mcNotDenote_borrowedMcNot`); `exists_mcNotCircuitEvolution` lifts it to `U`, +and computational-basis extensionality (`Evolution.ext_qubitBasis`) identifies it with the placed +gate (`Evolution.placedMcNot_evolvePure_qubitBasis`). -/ +theorem exists_borrowedCircuitEvolution_eq_placedMcNot {m : ℕ} + (as cs : List (Fin m)) (tgt : Fin m) + (hlen : cs.length = as.length + 2) (hcs : cs.Nodup) (has : as.Nodup) + (hdisj : cs.Disjoint as) (htcs : tgt ∉ cs) (htas : tgt ∉ as) : + ∃ (gs : List (Concrete.McNotGate m)) (U : Evolution (qubit.tensorPow m)), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 4 * as.length + 1 ∧ + (∀ c : Fin m → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + Evolution.placedMcNot cs.toFinset tgt (mt List.mem_toFinset.mp htcs) = U := by + have hgate := Concrete.borrowedMcNot_gate_mem as cs tgt hlen hcs has hdisj htcs htas + obtain ⟨U, hU⟩ := exists_mcNotCircuitEvolution (Concrete.borrowedMcNot as cs tgt) + (fun g hg => (hgate g hg).2) + refine ⟨Concrete.borrowedMcNot as cs tgt, U, hgate, + Concrete.borrowedMcNot_length_le as cs tgt, hU, ?_⟩ + refine Evolution.ext_qubitBasis fun c => ?_ + rw [Evolution.placedMcNot_evolvePure_qubitBasis, hU, + Concrete.mcNotDenote_borrowedMcNot as cs tgt hlen hcs has hdisj htcs htas] + +/-- **N&C Exercise 4.29: the block-embedded `Cᵏ(X)` is a linear Toffoli circuit.** The +contiguous front-block placement `(Evolution.tensorPowMcCtrlX k).onBlock b` — the grounded `Cᵏ(X)` +(`k` controls, one target = the leading `k + 1` wires) acting as the identity on the trailing `b` +ambient wires of `qubit ^⊗ₛ (k+1+b)` — is, **as an `Evolution`**, a genuine circuit of `≤ 2`-control +gates (`Toffoli`/`CNOT`/`NOT`) with the **linear** count `≤ 4 (k - 2) + 1 = O(k)`, provided the +register carries at least `k - 2` idle ambient wires to borrow (`k - 2 ≤ b`). + +The linear-count counterpart of `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` (which uses +the `Θ(k²)` halving circuit). Instantiates `exists_borrowedCircuitEvolution_eq_placedMcNot` at the +`k` front control wires `cs = ((cnxControls k).image (Fin.castAdd b)).toList` and the first `k - 2` +ambient wires `as = ((Fin.natAdd (k+1)) <$> List.finRange b).take (k - 2)`, then identifies the +resulting `Evolution.placedMcNot cs.toFinset (Fin.castAdd b (Fin.last k))` with the block +`onBlock` through the block truth table `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis` and the +placed-gate truth table `Evolution.placedMcNot_evolvePure_qubitBasis` +(`Evolution.ext_qubitBasis`). The wire budget `k - 2 ≤ b` is the honest cost of the Lemma 7.2 +construction's `k - 2` borrowed dirty ancillas; it is discharged from +`barencoNCircuit`'s idle-wire register in `AxQM/Core/BarencoLinearBlockReduction.lean`. -/ +theorem tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit {k b : ℕ} (hk : 2 ≤ k) (hb : k - 2 ≤ b) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + b))) (U : Evolution (qubit.tensorPow (k + 1 + b))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 4 * (k - 2) + 1 ∧ + (∀ c : Fin (k + 1 + b) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + (Evolution.tensorPowMcCtrlX k).onBlock b = U := by + -- The `k` front control wires and the target wire `k`. + set S : Finset (Fin (k + 1 + b)) := (cnxControls k).image (Fin.castAdd b) with hS + set cs : List (Fin (k + 1 + b)) := S.toList with hcs_def + set tgt : Fin (k + 1 + b) := Fin.castAdd b (Fin.last k) with htgt + -- The first `k - 2` ambient wires (all with value `≥ k + 1`) as borrowed dirty ancillas. + set as : List (Fin (k + 1 + b)) := + ((List.finRange b).map (Fin.natAdd (k + 1))).take (k - 2) with has_def + -- Wire-value bounds separating controls (`≤ k`) from ambient ancillas (`≥ k + 1`). + have hcs_val : ∀ x ∈ cs, (x : ℕ) < k + 1 := by + intro x hx + rw [hcs_def, Finset.mem_toList, hS, Finset.mem_image] at hx + obtain ⟨j, _, rfl⟩ := hx + simpa using j.2 + have has_val : ∀ x ∈ as, k + 1 ≤ (x : ℕ) := by + intro x hx + have hx' : x ∈ (List.finRange b).map (Fin.natAdd (k + 1)) := + (List.take_subset _ _) hx + rw [List.mem_map] at hx' + obtain ⟨j, _, rfl⟩ := hx' + simp [Fin.natAdd] + -- Distinctness bookkeeping. + have hcs_nodup : cs.Nodup := by rw [hcs_def]; exact Finset.nodup_toList _ + have has_nodup : as.Nodup := by + rw [has_def] + exact (((List.nodup_finRange b).map (Fin.natAdd_injective _ _)).sublist + (List.take_sublist _ _)) + have hcs_len : cs.length = k := by + rw [hcs_def, Finset.length_toList, hS, + Finset.card_image_of_injective _ (Fin.castAdd_injective _ _), + cnxControls_eq_image_castSucc, Finset.card_image_of_injective _ (Fin.castSucc_injective k), + Finset.card_univ, Fintype.card_fin] + have has_len : as.length = k - 2 := by + rw [has_def, List.length_take, List.length_map, List.length_finRange] + exact Nat.min_eq_left hb + have hlen : cs.length = as.length + 2 := by rw [hcs_len, has_len]; omega + have hdisj : cs.Disjoint as := fun x hxcs hxas => + absurd (has_val x hxas) (by have := hcs_val x hxcs; omega) + have htcs : tgt ∉ cs := by + intro h + rw [hcs_def, Finset.mem_toList, hS, Finset.mem_image] at h + obtain ⟨j, hj, hje⟩ := h + rw [htgt] at hje + exact last_notMem_cnxControls k ((Fin.castAdd_injective _ _ hje) ▸ hj) + have htas : tgt ∉ as := fun h => by + have := has_val tgt h + rw [htgt] at this + simp only [Fin.val_castAdd, Fin.val_last] at this + omega + obtain ⟨gs, U, hgate, hglen, hUc, hplaced⟩ := + exists_borrowedCircuitEvolution_eq_placedMcNot as cs tgt hlen hcs_nodup has_nodup hdisj htcs + htas + refine ⟨gs, U, hgate, has_len ▸ hglen, hUc, ?_⟩ + rw [← hplaced] + refine Evolution.ext_qubitBasis fun c => ?_ + rw [tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis, Evolution.placedMcNot_evolvePure_qubitBasis] + refine congrArg PureState.piTensor ?_ + funext i + refine congrArg qubitBasis ?_ + rw [hcs_def, Finset.toList_toFinset, hS, htgt] + +end AxQM diff --git a/LeanPool/AxQM/Core/ChannelHolevoChi.lean b/LeanPool/AxQM/Core/ChannelHolevoChi.lean new file mode 100644 index 0000000000..243378792f --- /dev/null +++ b/LeanPool/AxQM/Core/ChannelHolevoChi.lean @@ -0,0 +1,148 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.HolevoChiBound +public import LeanPool.AxQM.Postulates.API.QuantumChannel + +/-! +# The output-ensemble Holevo quantity of a state map + +The **Holevo χ quantity** of a trace-preserving quantum operation `E` is the left-hand side of the +Holevo–Schumacher–Westmoreland (HSW) theorem (Nielsen & Chuang, Theorem 12.8, eq. (12.71)): + +`χ(E) ≡ max_{{pⱼ, ρⱼ}} [ S(E(∑ⱼ pⱼ ρⱼ)) − ∑ⱼ pⱼ S(E(ρⱼ)) ]`, + +the maximum, over all input ensembles `{pⱼ, ρⱼ}`, of the Holevo χ of the corresponding *output* +ensemble `{pⱼ, E(ρⱼ)}`. The HSW theorem states that `χ(E)` equals the product-state capacity +`C⁽¹⁾(E)` of the channel; this file defines the χ(E) quantity itself and proves its foundational +properties. + +## Design + +For an arbitrary state map `E : State S → State S`, `χ(E)` is the supremum of the Holevo χ +(`State.holevoChi`, N&C eq. (12.208)) of the output ensemble `{pⱼ, E(ρⱼ)}` over input ensembles. +This form has two useful properties. + +* directly reuses the ensemble Holevo χ, inheriting its bounds + (`holevoChi_nonneg`, `holevoChi_le_vonNeumannEntropy_mix`); and +* **equals N&C's eq. (12.71) form** `S(E(∑ⱼ pⱼ ρⱼ)) − ∑ⱼ pⱼ S(E(ρⱼ))` whenever `E` is a channel, + because a channel is affine over probabilistic mixtures — the entropy of the output mixture + `S(∑ⱼ pⱼ E(ρⱼ))` equals the entropy of the channel applied to the input mixture + `S(E(∑ⱼ pⱼ ρⱼ))`. This is exactly `holevoChi_comp_eq_of_isChannel` (the fidelity bridge), + resting on `map_mix_of_isChannel`. + +The maximization is a supremum over ensembles indexed by `Fin n` for arbitrary `n : ℕ`; restricting +to `Fin n` is without loss of generality (any finite ensemble reindexes to a `Fin n` one with the +same χ value, since χ depends on the ensemble only through the mixture and the weighted-average +entropy). The supremum is well defined: the value set is bounded above (each element is +`≤ S(mixture) ≤ log d`, `channelHolevoChiSet_bddAbove`) and `χ(E) ≥ 0` (each output-ensemble χ is +non-negative; the empty case gives `sSup ∅ = 0`, `channelHolevoChi_nonneg`). + +## Main definitions and results + +* `AxQM.channelHolevoChi` — the Holevo χ quantity `χ(E)` of a channel. +* `AxQM.map_mix_of_isChannel` — a channel is affine over mixtures, + `E(∑ⱼ pⱼ ρⱼ) = ∑ⱼ pⱼ E(ρⱼ)`. +* `AxQM.holevoChi_comp_eq_of_isChannel` — the fidelity bridge: for a channel, the + per-ensemble summand equals N&C's eq. (12.71) expression. +* `AxQM.le_channelHolevoChi` — each input ensemble's output Holevo χ is `≤ χ(E)`. +* `AxQM.channelHolevoChi_nonneg` — `0 ≤ χ(E)`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A quantum channel is affine over probabilistic mixtures**: for a channel `E` and an ensemble +`{pᵢ, ρᵢ}`, `E(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ E(ρᵢ)`. A channel is the restriction to states of a *linear* +superoperator `Φ` (`IsChannel`), and linearity commutes with the convex combination defining the +mixture `State.mix`. -/ +theorem map_mix_of_isChannel {E : State S → State S} (hE : IsChannel E) + {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ρ : ι → State S) : + E (State.mix p hp hsum ρ) = State.mix p hp hsum (fun i => E (ρ i)) := by + obtain ⟨Φ, _, _, hΦ⟩ := hE + apply State.ext + rw [hΦ, State.mix_op, State.mix_op, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [map_smul, hΦ] + +/-- The set of Holevo χ values `χ({pⱼ, E(ρⱼ)})` of the *output* ensemble obtained by pushing a +finite input ensemble `{pⱼ, ρⱼ}` (indexed by `Fin n`, WLOG for finite ensembles) through `E`. Its +supremum is the channel Holevo χ quantity `channelHolevoChi E`. -/ +def channelHolevoChiSet (E : State S → State S) : Set ℝ := + {x | ∃ (n : ℕ) (p : Fin n → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : Fin n → State S), + x = State.holevoChi p hp hsum (fun i => E (ρ i))} + +/-- The supremal Holevo χ of the output ensembles `{pⱼ, E(ρⱼ)}` of a state map `E`. Each +ensemble contributes `S(∑ⱼ pⱼ E(ρⱼ)) − ∑ⱼ pⱼ S(E(ρⱼ))`. When `IsChannel E` holds, +`holevoChi_comp_eq_of_isChannel` rewrites the entropy term to `S(E(∑ⱼ pⱼ ρⱼ))` as in +Nielsen & Chuang's equation (12.71). -/ +def channelHolevoChi (E : State S → State S) : ℝ := + sSup (channelHolevoChiSet E) + +/-- The output-ensemble Holevo χ of any input ensemble is a member of `channelHolevoChiSet E`. -/ +theorem holevoChi_comp_mem_channelHolevoChiSet (E : State S → State S) {n : ℕ} (p : Fin n → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : Fin n → State S) : + State.holevoChi p hp hsum (fun i => E (ρ i)) ∈ channelHolevoChiSet E := + ⟨n, p, hp, hsum, ρ, rfl⟩ + +/-- `channelHolevoChiSet E` is bounded above: every output-ensemble Holevo χ is at most the entropy +of its output mixture (`holevoChi_le_vonNeumannEntropy_mix`), which is at most `log d`. -/ +theorem channelHolevoChiSet_bddAbove (E : State S → State S) : + BddAbove (channelHolevoChiSet E) := by + refine ⟨Real.log (Module.finrank ℂ S.space), ?_⟩ + rintro x ⟨n, p, hp, hsum, ρ, rfl⟩ + exact (State.holevoChi_le_vonNeumannEntropy_mix p hp hsum _).trans + (State.vonNeumannEntropy_le_log_finrank _) + +/-- `channelHolevoChiSet E` is nonempty: the trivial one-state ensemble contributes a value (hence +the `[Nonempty (State S)]` hypothesis). The companion of `channelHolevoChiSet_bddAbove`. -/ +theorem channelHolevoChiSet_nonempty [Nonempty (State S)] (E : State S → State S) : + (channelHolevoChiSet E).Nonempty := + ⟨_, holevoChi_comp_mem_channelHolevoChiSet E (fun _ : Fin 1 => 1) (fun _ => zero_le_one) + (by simp) (fun _ => Classical.arbitrary (State S))⟩ + +/-- **The maximization property of `χ(E)`**: for every input ensemble `{pⱼ, ρⱼ}`, the Holevo χ of +the output ensemble `{pⱼ, E(ρⱼ)}` is at most `χ(E)`. -/ +theorem le_channelHolevoChi (E : State S → State S) {n : ℕ} (p : Fin n → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : Fin n → State S) : + State.holevoChi p hp hsum (fun i => E (ρ i)) ≤ channelHolevoChi E := + le_csSup (channelHolevoChiSet_bddAbove E) (holevoChi_comp_mem_channelHolevoChiSet E p hp hsum ρ) + +/-- **Non-negativity of the channel Holevo χ quantity**: `0 ≤ χ(E)`. Each output-ensemble Holevo χ +is non-negative (`State.holevoChi_nonneg`), and if there are no ensembles at all the supremum of the +empty set is `0`. -/ +theorem channelHolevoChi_nonneg (E : State S → State S) : 0 ≤ channelHolevoChi E := by + rcases (channelHolevoChiSet E).eq_empty_or_nonempty with h | ⟨x, hx⟩ + · rw [channelHolevoChi, h, Real.sSup_empty] + · obtain ⟨n, p, hp, hsum, ρ, rfl⟩ := hx + exact le_csSup_of_le (channelHolevoChiSet_bddAbove E) + (holevoChi_comp_mem_channelHolevoChiSet E p hp hsum ρ) (State.holevoChi_nonneg p hp hsum _) + +/-- **Fidelity bridge to N&C eq. (12.71).** For a **channel** `E`, the per-ensemble summand defining +`χ(E)` — the Holevo χ of the output ensemble `{pⱼ, E(ρⱼ)}` — equals Nielsen & Chuang's eq. (12.71) +expression `S(E(∑ⱼ pⱼ ρⱼ)) − ∑ⱼ pⱼ S(E(ρⱼ))`, the entropy of the channel applied to the *input* +mixture minus the average output entropy. The two forms agree because a channel is affine over +mixtures (`map_mix_of_isChannel`), so `S(∑ⱼ pⱼ E(ρⱼ)) = S(E(∑ⱼ pⱼ ρⱼ))`. -/ +theorem holevoChi_comp_eq_of_isChannel {E : State S → State S} (hE : IsChannel E) + {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ρ : ι → State S) : + State.holevoChi p hp hsum (fun i => E (ρ i)) = + (E (State.mix p hp hsum ρ)).vonNeumannEntropy - ∑ i, p i * (E (ρ i)).vonNeumannEntropy := by + rw [State.holevoChi_def, map_mix_of_isChannel hE] + +end AxQM diff --git a/LeanPool/AxQM/Core/ChannelHolevoChiEnsemble.lean b/LeanPool/AxQM/Core/ChannelHolevoChiEnsemble.lean new file mode 100644 index 0000000000..d5adaf3bae --- /dev/null +++ b/LeanPool/AxQM/Core/ChannelHolevoChiEnsemble.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ChannelHolevoChi + +/-! +# A near-optimal input ensemble for the channel Holevo χ (N&C Theorem 12.8, achievability) + +The random-coding (achievability) half of the Holevo–Schumacher–Westmoreland theorem (Nielsen & +Chuang, Theorem 12.8, Box 12.5) begins by fixing an input ensemble `{pₐ, ρₐ}` whose output-ensemble +Holevo χ, `χ({pₐ, E(ρₐ)})`, is *close to* the channel Holevo χ quantity `χ(E)` — indeed strictly +above the target rate `R`. This is the entry point of the whole argument: Alice's codebook draws +its letters i.i.d. from this ensemble, and the error estimate of eqs. (12.72)–(12.83) then shows +that any rate below `χ({pₐ, E(ρₐ)})` (hence below `χ(E)`) is achievable. + +This file extends that existence step to arbitrary state maps. It uses the supremum of +output-ensemble values, each computed using the mixture of the outputs. For a quantum +channel, `holevoChi_comp_eq_of_isChannel` identifies each of these values with the +per-ensemble expression in equation (12.71), which applies the channel to the input mixture. + +## Main result + +* `AxQM.exists_holevoChi_comp_gt_of_lt_channelHolevoChi` — for any rate `R < χ(E)`, there + is a *finite input ensemble* `{pₐ, ρₐ}` (indexed by `Fin m`) whose output-ensemble Holevo χ + strictly exceeds `R`: `R < χ({pₐ, E(ρₐ)})`. + + The one-state ensemble contributes `0` to `channelHolevoChiSet E`, using the hypothesis + `[Nonempty (State S)]`. Since `χ(E)` is the supremum of this nonempty set, some member + exceeds `R` (`exists_lt_of_lt_csSup`). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- For a state map `E`, any rate below `channelHolevoChi E` is exceeded by the Holevo χ +of the output of some finite input ensemble. This extends the opening step of Nielsen & +Chuang, Box 12.5, using the supremum of output-ensemble values. When `IsChannel E` holds, +`holevoChi_comp_eq_of_isChannel` gives the per-ensemble expression in equation (12.71). -/ +theorem exists_holevoChi_comp_gt_of_lt_channelHolevoChi [Nonempty (State S)] + (E : State S → State S) {R : ℝ} (hR : R < channelHolevoChi E) : + ∃ (m : ℕ) (p : Fin m → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : Fin m → State S), + R < State.holevoChi p hp hsum (fun i => E (ρ i)) := by + -- `R` is below the supremum `χ(E) = sSup (channelHolevoChiSet E)` of the nonempty set of + -- output-ensemble χ values, so some member exceeds it. + obtain ⟨x, hxmem, hxR⟩ := exists_lt_of_lt_csSup (channelHolevoChiSet_nonempty E) hR + obtain ⟨m, p, hp, hsum, ρ, rfl⟩ := hxmem + exact ⟨m, p, hp, hsum, ρ, hxR⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/ChannelHolevoChiPure.lean b/LeanPool/AxQM/Core/ChannelHolevoChiPure.lean new file mode 100644 index 0000000000..1aacd92656 --- /dev/null +++ b/LeanPool/AxQM/Core/ChannelHolevoChiPure.lean @@ -0,0 +1,199 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ChannelHolevoChi +public import LeanPool.AxQM.Postulates.API.Ensemble +public import LeanPool.AxQM.Postulates.API.EntropyConcavity + +/-! +# Reducing the channel Holevo supremum to pure-state ensembles + +Nielsen & Chuang, Exercise 12.11 (p. 555), asks to show that the maximum defining the Holevo χ +quantity of a channel `E` (eq. (12.71), the left-hand side of the HSW theorem), + +`χ(E) = max_{{pⱼ, ρⱼ}} [ S(E(∑ⱼ pⱼ ρⱼ)) − ∑ⱼ pⱼ S(E(ρⱼ)) ]`, + +has a maximizing pure-state ensemble. This file proves equality of the unrestricted +supremum and the supremum over the pure-state value set `channelHolevoChiPureSet`: + +`χ(E) = sSup (channelHolevoChiPureSet E)` for a channel `E` + +(`channelHolevoChi_eq_sSup_channelHolevoChiPureSet`). Attainment requires a separate existence +argument. A Carathéodory reduction to ensembles of at most `d²` pure states is in +`LeanPool/AxQM/Core/ChannelHolevoChiPureCard.lean`, where `d` is the input dimension. + +## Proof idea + +Restricting the maximization to pure ensembles cannot *increase* the supremum, since pure ensembles +are a subset of all ensembles. For the reverse, we **refine** an arbitrary input ensemble +`{pⱼ, ρⱼ}` into a pure one without decreasing the output-ensemble χ: replace each `ρⱼ` by its +eigenensemble `{λⱼₖ, |ψⱼₖ⟩}` (`Ensemble.ofState`, which reproduces `ρⱼ` by +`Ensemble.ofState_toState`). The refined ensemble `{pⱼ λⱼₖ, |ψⱼₖ⟩}` has the **same mixture** +`∑ⱼₖ pⱼ λⱼₖ |ψⱼₖ⟩⟨ψⱼₖ| = ∑ⱼ pⱼ ρⱼ`, so the first term `S(E(mixture))` is unchanged, while, because a +channel is affine over mixtures (`map_mix_of_isChannel`) and the von Neumann entropy is **concave** +(`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`), each `S(E(ρⱼ)) ≥ ∑ₖ λⱼₖ S(E ψⱼₖ)`, +so the subtracted average output entropy only *decreases*. Hence the refined pure ensemble has +output χ `≥` the original, and the pure supremum matches the full one. + +## Main definitions and results + +* `AxQM.channelHolevoChiPureSet` — the χ-value set over pure-state input ensembles. +* `AxQM.Ensemble.toState_eq_mix` — an ensemble's density operator is the `State.mix` of its + pure components (an `Ensemble`↔`Mixture` bridge). +* `AxQM.channelHolevoChi_eq_sSup_channelHolevoChiPureSet` — **the Part 1 reduction**. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **An ensemble's density operator is the `State.mix` of its pure components**: +`ρ = ∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ| = State.mix p (fun i => |ψᵢ⟩⟨ψᵢ|)`. Both sides have the same operator +`∑ᵢ (pᵢ : ℂ) • |ψᵢ⟩⟨ψᵢ|` (`Ensemble.toState_op`, `State.mix_op`). Bridges the eigenensemble +construction (`Ensemble.ofState`) to the mixture `State.mix`, so channel-affineness +and entropy concavity apply to a spectral decomposition. -/ +theorem Ensemble.toState_eq_mix (e : Ensemble S) : + e.toState = State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState) := by + apply State.ext + rw [Ensemble.toState_op, State.mix_op] + +/-- The set of Holevo χ values `χ({pⱼ, E(ψⱼ)})` of the *output* ensemble obtained by pushing a +finite **pure-state** input ensemble `{pⱼ, |ψⱼ⟩}` (indexed by `Fin n`, WLOG for finite ensembles) +through `E`. Its supremum is the pure-restricted channel Holevo χ; `channelHolevoChi_eq_sSup_…` +shows it equals the full `channelHolevoChi E` when `E` is a channel. -/ +def channelHolevoChiPureSet (E : State S → State S) : Set ℝ := + {x | ∃ (n : ℕ) (p : Fin n → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ψ : Fin n → PureState S), x = State.holevoChi p hp hsum (fun i => E (ψ i).toState)} + +/-- **Any finite pure-state ensemble contributes its output-χ to `channelHolevoChiPureSet`.** +The ensemble may be indexed by an arbitrary finite type `κ`; it is reindexed to `Fin (card κ)` via +`Fintype.equivFin`, leaving the χ value unchanged (`State.holevoChi_equiv`). -/ +theorem holevoChi_pureEnsemble_mem (E : State S → State S) {κ : Type*} [Fintype κ] + (q : κ → ℝ) (hq : ∀ i, 0 ≤ q i) (hqsum : ∑ i, q i = 1) (ψ : κ → PureState S) : + State.holevoChi q hq hqsum (fun i => E (ψ i).toState) ∈ channelHolevoChiPureSet E := by + let e := (Fintype.equivFin κ).symm + have hp' : ∀ i, 0 ≤ q (e i) := fun i => hq _ + have hsum' : ∑ i, q (e i) = 1 := by rw [Equiv.sum_comp e q]; exact hqsum + exact ⟨Fintype.card κ, fun i => q (e i), hp', hsum', fun i => ψ (e i), + (State.holevoChi_equiv e q hq hqsum (fun k => E (ψ k).toState) hp' hsum').symm⟩ + +/-- **The pure-state χ set is contained in the full χ set** (`channelHolevoChiSet`): a pure-state +ensemble is an ensemble. In particular the pure set is bounded above. -/ +theorem channelHolevoChiPureSet_subset (E : State S → State S) : + channelHolevoChiPureSet E ⊆ channelHolevoChiSet E := by + rintro x ⟨n, p, hp, hsum, ψ, rfl⟩ + exact ⟨n, p, hp, hsum, fun i => (ψ i).toState, rfl⟩ + +/-- **Refinement into a pure ensemble does not decrease the output-χ.** For a channel `E` and any +input ensemble `{pⱼ, ρⱼ}`, there is a pure-state ensemble (its output-χ lies in +`channelHolevoChiPureSet E`) whose output Holevo χ is at least that of `{pⱼ, E(ρⱼ)}`. The pure +ensemble is the eigenensemble refinement `{pⱼ λⱼₖ, |ψⱼₖ⟩}`; it has the same mixture, and by +concavity of the entropy across each component's spectral decomposition the subtracted average +output entropy only decreases. -/ +theorem exists_pure_holevoChi_ge_of_isChannel {E : State S → State S} (hE : IsChannel E) + {n : ℕ} (p : Fin n → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : Fin n → State S) : + ∃ y ∈ channelHolevoChiPureSet E, + State.holevoChi p hp hsum (fun i => E (ρ i)) ≤ y := by + classical + -- refined weights and pure states, indexed by the sigma of per-component eigenensembles + set q : (j : Fin n) × Fin ((Ensemble.ofState (ρ j)).card) → ℝ := + fun x => p x.1 * (Ensemble.ofState (ρ x.1)).prob x.2 with hq_def + set ψ : (j : Fin n) × Fin ((Ensemble.ofState (ρ j)).card) → PureState S := + fun x => (Ensemble.ofState (ρ x.1)).states x.2 with hψ_def + have hq : ∀ x, 0 ≤ q x := fun x => + mul_nonneg (hp x.1) ((Ensemble.ofState (ρ x.1)).prob_nonneg x.2) + have hqsum : ∑ x, q x = 1 := by + rw [← Finset.univ_sigma_univ, Finset.sum_sigma] + simp only [hq_def] + rw [← hsum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [← Finset.mul_sum, (Ensemble.ofState (ρ j)).sum_prob, mul_one] + -- the refinement has the same mixture as the original ensemble + have hmixeq : State.mix q hq hqsum (fun x => (ψ x).toState) = State.mix p hp hsum ρ := by + apply State.ext + rw [State.mix_op, State.mix_op, ← Finset.univ_sigma_univ, Finset.sum_sigma] + refine Finset.sum_congr rfl fun j _ => ?_ + have hrho : ∑ k, (((Ensemble.ofState (ρ j)).prob k : ℂ)) • + ((Ensemble.ofState (ρ j)).states k).toState.op = (ρ j).op := by + rw [← Ensemble.toState_op (Ensemble.ofState (ρ j)), Ensemble.ofState_toState] + rw [← hrho, Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [hq_def, hψ_def] + rw [Complex.ofReal_mul, smul_smul] + -- per component: concavity of the entropy across the eigenensemble + have hj : ∀ j, ∑ k, (Ensemble.ofState (ρ j)).prob k * + (E (((Ensemble.ofState (ρ j)).states k).toState)).vonNeumannEntropy + ≤ (E (ρ j)).vonNeumannEntropy := by + intro j + have hEρj : E (ρ j) = State.mix (Ensemble.ofState (ρ j)).prob + (Ensemble.ofState (ρ j)).prob_nonneg (Ensemble.ofState (ρ j)).sum_prob + (fun k => E (((Ensemble.ofState (ρ j)).states k).toState)) := by + conv_lhs => rw [← Ensemble.ofState_toState (ρ j)] + rw [Ensemble.toState_eq_mix, map_mix_of_isChannel hE] + rw [hEρj] + exact State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix' _ _ _ _ + -- the average output entropy of the refinement is ≤ that of the original ensemble + have hentineq : ∑ x, q x * (E ((ψ x).toState)).vonNeumannEntropy + ≤ ∑ i, p i * (E (ρ i)).vonNeumannEntropy := by + rw [← Finset.univ_sigma_univ, Finset.sum_sigma] + refine Finset.sum_le_sum fun j _ => ?_ + have hfac : ∑ k, q ⟨j, k⟩ * (E ((ψ ⟨j, k⟩).toState)).vonNeumannEntropy + = p j * ∑ k, (Ensemble.ofState (ρ j)).prob k * + (E (((Ensemble.ofState (ρ j)).states k).toState)).vonNeumannEntropy := by + rw [Finset.mul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [hq_def, hψ_def] + ring + rw [hfac] + exact mul_le_mul_of_nonneg_left (hj j) (hp j) + -- assemble: the refined pure ensemble's output-χ dominates the original's + refine ⟨State.holevoChi q hq hqsum (fun x => E (ψ x).toState), + holevoChi_pureEnsemble_mem E q hq hqsum ψ, ?_⟩ + rw [holevoChi_comp_eq_of_isChannel hE, holevoChi_comp_eq_of_isChannel hE, hmixeq] + linarith [hentineq] + +/-- **Pure-state supremum reduction for Nielsen & Chuang, Exercise 12.11.** For a channel +`E`, the channel Holevo quantity is the same supremum when restricted to pure-state inputs: + +`χ(E) = sSup (channelHolevoChiPureSet E)`. + +The `≤`-direction restricted to pure ensembles is trivial (they are a subset); the reverse is the +eigenensemble refinement `exists_pure_holevoChi_ge_of_isChannel`, which produces, for every +ensemble, a pure ensemble of at least the same output-χ. -/ +theorem channelHolevoChi_eq_sSup_channelHolevoChiPureSet {E : State S → State S} + (hE : IsChannel E) : + channelHolevoChi E = sSup (channelHolevoChiPureSet E) := by + rcases (channelHolevoChiSet E).eq_empty_or_nonempty with hempty | hne + · -- no ensembles at all ⇒ the pure set is empty too + have hpe : channelHolevoChiPureSet E = ∅ := + Set.eq_empty_of_subset_empty (hempty ▸ channelHolevoChiPureSet_subset E) + rw [hpe] + exact congrArg sSup hempty + · have hbdd : BddAbove (channelHolevoChiPureSet E) := + BddAbove.mono (channelHolevoChiPureSet_subset E) (channelHolevoChiSet_bddAbove E) + apply le_antisymm + · -- χ(E) = sSup full ≤ sSup pure, via the refinement of each ensemble + apply csSup_le hne + rintro x ⟨n, p, hp, hsum, ρ, rfl⟩ + obtain ⟨y, hy_mem, hxy⟩ := exists_pure_holevoChi_ge_of_isChannel hE p hp hsum ρ + exact hxy.trans (le_csSup hbdd hy_mem) + · -- sSup pure ≤ sSup full = χ(E); the pure set is nonempty (refine any full witness) + refine csSup_le_csSup (channelHolevoChiSet_bddAbove E) ?_ (channelHolevoChiPureSet_subset E) + obtain ⟨x, n, p, hp, hsum, ρ, rfl⟩ := hne + obtain ⟨y, hy_mem, _⟩ := exists_pure_holevoChi_ge_of_isChannel hE p hp hsum ρ + exact ⟨y, hy_mem⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/ChannelHolevoChiPureCard.lean b/LeanPool/AxQM/Core/ChannelHolevoChiPureCard.lean new file mode 100644 index 0000000000..92924f537e --- /dev/null +++ b/LeanPool/AxQM/Core/ChannelHolevoChiPureCard.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ChannelHolevoChiPure +public import LeanPool.AxQM.Postulates.API.EntropyMixLine +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.SupportReduction +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SelfAdjointFinrank + +/-! +# Reducing the channel Holevo supremum to ensembles of at most `d²` pure states + +Nielsen & Chuang, Exercise 12.11 (p. 555) asks to show that the maximum defining the Holevo χ +quantity of a channel `E` (eq. (12.71), the left-hand side of the HSW theorem) is achieved by an +ensemble of at most `d²` **pure** states, where `d` is the input dimension. +`LeanPool/AxQM/Core/ChannelHolevoChiPure.lean` reduces the supremum to pure-state ensembles. +This file proves the cardinality reduction for that supremum. + +`χ(E) = sSup (channelHolevoChiPureLeCardSet E)` for a channel `E` + +(`channelHolevoChi_eq_sSup_channelHolevoChiPureLeCardSet`), where `channelHolevoChiPureLeCardSet E` +restricts the supremum to pure-state input ensembles of at most `S.dim ^ 2` elements. +Attainment of this supremum is a separate assertion in the exercise. + +## Proof idea + +A pure-state ensemble `{pⱼ, |ψⱼ⟩}` contributes the output χ `S(E(∑ⱼ pⱼ|ψⱼ⟩⟨ψⱼ|)) − ∑ⱼ pⱼ S(E ψⱼ)`. +The rank-one projections `|ψⱼ⟩⟨ψⱼ|` are **self-adjoint operators** — points of the real vector space +`selfAdjoint (S.space →L[ℂ] S.space)`, of real dimension `d²` +(`finrank_real_selfAdjoint_continuousLinearMap`, +`ToMathlib/Analysis/InnerProductSpace/SelfAdjointFinrank.lean`) — and each has **unit trace**, so +all lie on the affine hyperplane `{φ = 1}` for the real-trace functional `φ = re ∘ tr`. The abstract +hyperplane-refined Carathéodory theorem `exists_reduced_weights_le_finrank` +(`ToMathlib/Analysis/Convex/SupportReduction.lean`) then replaces +the weights `pⱼ` by nonnegative weights `w'ⱼ` with + +* the **same barycenter** `∑ⱼ w'ⱼ |ψⱼ⟩⟨ψⱼ| = ∑ⱼ pⱼ |ψⱼ⟩⟨ψⱼ|` — so the output mixture, hence + `S(E(mixture))`, is unchanged; +* the **same total** `∑ⱼ w'ⱼ = 1` — so `w'` is again a probability distribution; +* a **no-larger objective** `∑ⱼ w'ⱼ S(E ψⱼ) ≤ ∑ⱼ pⱼ S(E ψⱼ)` — so the subtracted average output + entropy only decreases, i.e. the output χ does not decrease; and +* **support of size `≤ d²`**. + +Dropping the (harmless) zero-weight states leaves a pure ensemble of `≤ d²` states with output χ at +least as large (`exists_pureLeCard_holevoChi_ge_of_isChannel`); composing with Part 1 gives the +supremum equality. The bound `d²` uses the real dimension of the self-adjoint operator space and +the affine constraint of unit trace. + +## Main definitions and results + +* `AxQM.channelHolevoChiPureLeCardSet` — the χ-value set over pure-state input ensembles of + at most `d²` elements. +* `AxQM.exists_pureLeCard_holevoChi_ge_of_isChannel` — every pure ensemble is refined into + a `≤ d²`-element pure ensemble of at least the same output χ. +* `AxQM.channelHolevoChi_eq_sSup_channelHolevoChiPureLeCardSet` — **the Part 2 reduction**. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.3.2, Theorem 12.8, eq. (12.71); Exercise 12.11. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The set of Holevo χ values `χ({pⱼ, E(ψⱼ)})` of the *output* ensemble obtained by pushing a +finite **pure-state** input ensemble `{pⱼ, |ψⱼ⟩}` of at most `d² = S.dim ^ 2` states (indexed by +`Fin n` with `n ≤ S.dim ^ 2`) through `E`. Its supremum equals the full `channelHolevoChi E` when +`E` is a +channel (`channelHolevoChi_eq_sSup_channelHolevoChiPureLeCardSet`); `d` is the dimension of the +channel input. -/ +def channelHolevoChiPureLeCardSet (E : State S → State S) : Set ℝ := + {x | ∃ (n : ℕ) (_ : n ≤ S.dim ^ 2) (p : Fin n → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ψ : Fin n → PureState S), x = State.holevoChi p hp hsum (fun i => E (ψ i).toState)} + +/-- **Any finite pure-state ensemble of at most `d²` states contributes its output-χ to +`channelHolevoChiPureLeCardSet`.** The ensemble may be indexed by an arbitrary finite type `κ` with +`Fintype.card κ ≤ S.dim ^ 2`; it is reindexed to `Fin (card κ)` via `Fintype.equivFin`, leaving +the χ value unchanged (`State.holevoChi_equiv`) and the cardinality bound intact. -/ +theorem holevoChi_pureEnsemble_card_le_mem (E : State S → State S) {κ : Type*} [Fintype κ] + (hκ : Fintype.card κ ≤ S.dim ^ 2) + (q : κ → ℝ) (hq : ∀ i, 0 ≤ q i) (hqsum : ∑ i, q i = 1) (ψ : κ → PureState S) : + State.holevoChi q hq hqsum (fun i => E (ψ i).toState) ∈ channelHolevoChiPureLeCardSet E := by + let e := (Fintype.equivFin κ).symm + have hp' : ∀ i, 0 ≤ q (e i) := fun i => hq _ + have hsum' : ∑ i, q (e i) = 1 := by rw [Equiv.sum_comp e q]; exact hqsum + exact ⟨Fintype.card κ, hκ, fun i => q (e i), hp', hsum', fun i => ψ (e i), + (State.holevoChi_equiv e q hq hqsum (fun k => E (ψ k).toState) hp' hsum').symm⟩ + +/-- **The `≤ d²` pure-state χ set is contained in the pure-state χ set** +(`channelHolevoChiPureSet`): a `≤ d²`-element pure ensemble is a pure ensemble. In particular it is +bounded above. -/ +theorem channelHolevoChiPureLeCardSet_subset (E : State S → State S) : + channelHolevoChiPureLeCardSet E ⊆ channelHolevoChiPureSet E := by + rintro x ⟨n, _, p, hp, hsum, ψ, rfl⟩ + exact ⟨n, p, hp, hsum, ψ, rfl⟩ + +/-- **Cardinality reduction: a pure ensemble is refined into a `≤ d²`-element pure ensemble without +decreasing the output-χ.** For a channel `E` and any pure-state input ensemble `{pⱼ, |ψⱼ⟩}`, there +is a pure-state ensemble of at most `d² = S.dim ^ 2` states (its output-χ lies in +`channelHolevoChiPureLeCardSet E`) whose output Holevo χ is at least that of `{pⱼ, E(ψⱼ)}`. + +The rank-one projections `|ψⱼ⟩⟨ψⱼ|` are unit-trace self-adjoint operators — points of the affine +hyperplane `{re ∘ tr = 1}` in the `d²`-real-dimensional space `selfAdjoint (S.space →L[ℂ] S.space)` +(`finrank_real_selfAdjoint_continuousLinearMap`). The hyperplane-refined Carathéodory theorem +`exists_reduced_weights_le_finrank` reduces the weights to support `≤ d²` while preserving the +barycenter `∑ⱼ pⱼ |ψⱼ⟩⟨ψⱼ|` (hence the output mixture and `S(E(mixture))`) and the total, and not +increasing `∑ⱼ pⱼ S(E ψⱼ)` (hence not decreasing the output χ). -/ +theorem exists_pureLeCard_holevoChi_ge_of_isChannel {E : State S → State S} (hE : IsChannel E) + {n : ℕ} (p : Fin n → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ψ : Fin n → PureState S) : + ∃ y ∈ channelHolevoChiPureLeCardSet E, + State.holevoChi p hp hsum (fun i => E (ψ i).toState) ≤ y := by + classical + -- the ambient real vector space: self-adjoint operators, of real dimension `d²` + set V := selfAdjoint.submodule ℝ (S.space →L[ℂ] S.space) with hVdef + have hsa : ∀ j, (ψ j).toState.op ∈ V := fun j => + selfAdjoint.mem_iff.mpr (State.isSelfAdjoint_op _) + -- the real-trace functional `re ∘ tr`, built locally + let φ : V →ₗ[ℝ] ℝ := + { toFun := fun A => (LinearMap.trace ℂ S.space (A : S.space →L[ℂ] S.space)).re + map_add' := fun A B => by + simp only [Submodule.coe_add, ContinuousLinearMap.toLinearMap_add, map_add, Complex.add_re] + map_smul' := fun r A => by + have key : ((r • A : V) : S.space →L[ℂ] S.space) + = (↑r : ℂ) • (A : S.space →L[ℂ] S.space) := by + rw [SetLike.val_smul, Complex.coe_smul] + simp only [RingHom.id_apply, smul_eq_mul, key, ContinuousLinearMap.toLinearMap_smul, + map_smul, + Complex.re_ofReal_mul] } + -- each rank-one projection lies on the hyperplane `{φ = 1}` (unit trace) + have hv1 : ∀ j : Fin n, φ ⟨(ψ j).toState.op, hsa j⟩ = 1 := by + intro j + change (LinearMap.trace ℂ S.space ((ψ j).toState.op : S.space →L[ℂ] S.space)).re = 1 + rw [State.trace_op_eq_one]; simp + -- support reduction, minimizing the output-entropy objective `t j = S(E ψⱼ)` + obtain ⟨w', hw'0, hbary, htot, hobj, s, hs_iff, hs_card⟩ := + exists_reduced_weights_le_finrank (v := fun j => (⟨(ψ j).toState.op, hsa j⟩ : V)) φ hv1 + (fun j => (E (ψ j).toState).vonNeumannEntropy) hp + have hw'z : ∀ j ∉ s, w' j = 0 := fun j hj => by + by_contra h; exact hj ((hs_iff j).mp h) + -- the reduced weights over the (`≤ d²`-element) support `s` + have hq0 : ∀ i : ↥s, 0 ≤ w' ↑i := fun i => hw'0 _ + have hqsum : ∑ i : ↥s, w' ↑i = 1 := by + rw [Finset.sum_coe_sort s w', Finset.sum_subset s.subset_univ (fun j _ hj => hw'z j hj), + htot, hsum] + have hcard : Fintype.card ↥s ≤ S.dim ^ 2 := by + rw [Fintype.card_coe] + exact hs_card.trans_eq (finrank_real_selfAdjoint_continuousLinearMap (E := S.space)) + refine ⟨State.holevoChi (fun i : ↥s => w' ↑i) hq0 hqsum (fun i => E (ψ ↑i).toState), + holevoChi_pureEnsemble_card_le_mem E hcard _ hq0 hqsum (fun i => ψ ↑i), ?_⟩ + -- the reduced ensemble has the same mixture (same barycenter of the `|ψⱼ⟩⟨ψⱼ|`) + have hmix : State.mix (fun i : ↥s => w' ↑i) hq0 hqsum (fun i => (ψ ↑i).toState) + = State.mix p hp hsum (fun j => (ψ j).toState) := by + apply State.ext + rw [State.mix_op, State.mix_op, + Finset.sum_coe_sort s (fun j => (↑(w' j) : ℂ) • (ψ j).toState.op), + Finset.sum_subset s.subset_univ (fun j _ hj => by rw [hw'z j hj]; simp)] + have h := congrArg V.subtype hbary + rw [map_sum, map_sum] at h + simp only [map_smul, Submodule.subtype_apply] at h + -- both endpoints are `Complex.coe_smul` cast-normalizations of `h`'s ℝ-smul sum + simpa only [Complex.coe_smul] using h + -- and no larger average output entropy + have hentr : ∑ i : ↥s, w' ↑i * (E (ψ ↑i).toState).vonNeumannEntropy + ≤ ∑ j, p j * (E (ψ j).toState).vonNeumannEntropy := by + rw [Finset.sum_coe_sort s (fun j => w' j * (E (ψ j).toState).vonNeumannEntropy), + Finset.sum_subset s.subset_univ (fun j _ hj => by rw [hw'z j hj]; ring)] + exact hobj + rw [holevoChi_comp_eq_of_isChannel hE, holevoChi_comp_eq_of_isChannel hE, hmix] + linarith [hentr] + +/-- **Cardinality reduction for Nielsen & Chuang, Exercise 12.11.** For a channel `E`, +the channel Holevo supremum equals the supremum restricted to pure-state input ensembles +with at most `d² = S.dim ^ 2` elements: + +`χ(E) = sSup (channelHolevoChiPureLeCardSet E)`. + +By Part 1 (`channelHolevoChi_eq_sSup_channelHolevoChiPureSet`) it suffices to match the supremum +over *all* pure ensembles. The `≥`-direction restricted to `≤ d²`-element ensembles is trivial +(they are a subset); the reverse is the cardinality reduction +`exists_pureLeCard_holevoChi_ge_of_isChannel`, which produces, for every pure ensemble, a +`≤ d²`-element pure ensemble of at least the same output-χ. -/ +theorem channelHolevoChi_eq_sSup_channelHolevoChiPureLeCardSet {E : State S → State S} + (hE : IsChannel E) : + channelHolevoChi E = sSup (channelHolevoChiPureLeCardSet E) := by + rw [channelHolevoChi_eq_sSup_channelHolevoChiPureSet hE] + rcases (channelHolevoChiPureSet E).eq_empty_or_nonempty with hempty | hne + · -- no pure ensembles at all ⇒ the `≤ d²` set is empty too + have hle : channelHolevoChiPureLeCardSet E = ∅ := + Set.eq_empty_of_subset_empty (hempty ▸ channelHolevoChiPureLeCardSet_subset E) + rw [hempty, hle] + · have hbddPure : BddAbove (channelHolevoChiPureSet E) := + BddAbove.mono (channelHolevoChiPureSet_subset E) (channelHolevoChiSet_bddAbove E) + have hbddLe : BddAbove (channelHolevoChiPureLeCardSet E) := + BddAbove.mono (channelHolevoChiPureLeCardSet_subset E) hbddPure + apply le_antisymm + · -- sSup pure ≤ sSup (≤ d²), via the cardinality reduction of each pure ensemble + apply csSup_le hne + rintro x ⟨m, q, hq, hqsum, ψ', rfl⟩ + obtain ⟨y, hy_mem, hxy⟩ := exists_pureLeCard_holevoChi_ge_of_isChannel hE q hq hqsum ψ' + exact hxy.trans (le_csSup hbddLe hy_mem) + · -- sSup (≤ d²) ≤ sSup pure; the `≤ d²` set is nonempty (reduce any pure witness) + refine csSup_le_csSup hbddPure ?_ (channelHolevoChiPureLeCardSet_subset E) + obtain ⟨x, m, q, hq, hqsum, ψ', rfl⟩ := hne + obtain ⟨y, hy_mem, _⟩ := exists_pureLeCard_holevoChi_ge_of_isChannel hE q hq hqsum ψ' + exact ⟨y, hy_mem⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/CircuitBudget.lean b/LeanPool/AxQM/Core/CircuitBudget.lean new file mode 100644 index 0000000000..46b5be9cb5 --- /dev/null +++ b/LeanPool/AxQM/Core/CircuitBudget.lean @@ -0,0 +1,246 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.BarencoSplitLinearBlockReduction +public import LeanPool.AxQM.Core.QuditPowTower + +/-! +# A compositional elementary-gate budget for `Evolution` circuits (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a nested stack of +`O(n)` reduction layers, each a tail `barencoTail k W = Cᵏ(X) · C(W†) · Cᵏ(X) · C(W)` under a +leading multiplexer that the recursion expands. Each internal `Cᵏ(X)` block is a **linear** +`O(k)` `Toffoli`/`CNOT`/`NOT` circuit with **no** wire budget +(`barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks`). To obtain the exercise's `O(n²)` +*count* one needs a way to **add** those per-layer counts across the recursion: every +existing reduction lemma is a per-block / per-layer existential on its own tower register, and there +is no abstraction under which the counts compose. + +## What is formalised + +This file supplies exactly that abstraction. + +* `CircuitBudget E t s` — the proposition that the `Evolution` `E` is built, up to wire + reindexing, from **at most `t`** `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) and **at most `s`** + single-qubit-controlled gates `C(V)` (`V` a single-qubit gate). It is closed under sequential + composition (`comp`, budgets add), register transport (`congr`), and weakening (`mono`); its + leaves are a `≤ 2`-control block realised by a classical gate list (`block`, contributing + `gs.length` to `t`), and a single-qubit-controlled gate `C(unCtrl d g)` or its adjoint (`ctrlGate` + / `ctrlGateAdj`, contributing `1` to `s`). Because no constructor can *lower* a budget, + `CircuitBudget E t s` is an honest **upper bound** on the elementary-gate count of a realisation. + +* `CircuitBudget.cast_congr` — transport a budget along a bare register **equality** + `cast (congrArg Evolution h)`, the shape the `barencoNCircuit` recursion glues its layers with + (`barencoNCircuit_succ`). It is what folds a budget over that recursion. + +* `barencoTail_unCtrl_circuitBudget` — the **per-layer budget**: for `2 ≤ k` (block index + `k+1 ≥ 3`) and any single-qubit root `g : Evolution qubit`, one Barenco tail layer + `barencoTail (k+1) (unCtrl d g)` has `CircuitBudget … (16 (k+1)) 2` — at most `16 (k+1) = O(k)` + `≤ 2`-control gates (two blocks of `≤ 8 (k+1)` each) and exactly two + single-qubit-controlled gates `C(W)`, `C(W†)`. This is the per-layer reduction repackaged + as a *composable* budget. + +## Use for the `O(n²)` count + +`barencoNCircuit`'s recursion is a composition of `O(n)` such tail layers (`barencoNCircuit_succ`), +each with `W = unCtrl d (V (d+1))` a single-qubit root, so folding +`barencoTail_unCtrl_circuitBudget` over the recursion (via `CircuitBudget.comp` and +`CircuitBudget.cast_congr`) and summing the linear per-layer counts `Σⱼ 16 (j+1) = O(n²)` yields the +exercise's `O(n²)` `≤ 2`-control-gate total together with the `O(n)` single-qubit-controlled gates, +on exactly the `n + 1`-wire register. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +namespace QSystem.Iso + +/-- Register isomorphisms that only regroup or relabel wires. Tensor associativity and symmetry +leave each factor intact. A qudit split uses the fixed product-basis encoding, so it merely exposes +the two factors of the encoded register. -/ +inductive IsWireReindexing : {S T : QSystem.{0}} → S.Iso T → Prop where + | refl (S : QSystem.{0}) : IsWireReindexing (QSystem.Iso.refl S) + | symm {S T : QSystem.{0}} {e : S.Iso T} (he : IsWireReindexing e) : + IsWireReindexing e.symm + | trans {S T U : QSystem.{0}} {e : S.Iso T} {f : T.Iso U} + (he : IsWireReindexing e) (hf : IsWireReindexing f) : IsWireReindexing (e.trans f) + | tmul {S S' T T' : QSystem.{0}} {e : S.Iso S'} {f : T.Iso T'} + (he : IsWireReindexing e) (hf : IsWireReindexing f) : IsWireReindexing (e.tmul f) + | assoc (S T U : QSystem.{0}) : IsWireReindexing (QSystem.assoc S T U) + | comm (S T : QSystem.{0}) : IsWireReindexing (QSystem.Iso.comm S T) + | tensorPowOne (S : QSystem.{0}) : IsWireReindexing S.tensorPowOne + | tensorPowSuccHead (S : QSystem.{0}) (n : ℕ) : IsWireReindexing (S.tensorPowSuccHead n) + | tensorPowAdd (S : QSystem.{0}) (a b : ℕ) : IsWireReindexing (S.tensorPowAdd a b) + | quditDimCongr {d e : ℕ} (h : d = e) : IsWireReindexing (AxQM.quditDimCongr h) + | quditProdIso (d e : ℕ) : IsWireReindexing (AxQM.quditProdIso d e) + +namespace IsWireReindexing + +theorem leftComm (A B C : QSystem.{0}) : IsWireReindexing (QSystem.Iso.leftComm A B C) := by + unfold QSystem.Iso.leftComm + exact ((assoc A B C).trans ((comm A B).tmul (refl C))).trans (assoc B A C).symm + +theorem qtowerComposeRight (S M : QSystem.{0}) (n : ℕ) : + IsWireReindexing (AxQM.qtowerComposeRight (S := S) (M := M) n) := by + induction n with + | zero => exact refl (S ⊗ M) + | succ n ih => + exact ((refl qubit).tmul ih).trans (assoc qubit (qtower n S) M) + +theorem qtowerQubitTensorPow (n : ℕ) : IsWireReindexing (AxQM.qtowerQubitTensorPow n) := by + induction n with + | zero => exact tensorPowOne qubit + | succ n ih => + exact ((refl qubit).tmul ih).trans (tensorPowSuccHead qubit (n + 1)).symm + +theorem barencoBlockFlatten (k d : ℕ) : IsWireReindexing (AxQM.barencoBlockFlatten k d) := by + unfold AxQM.barencoBlockFlatten + exact ((qtowerComposeRight qubit (qtower d qubit) k).trans + ((qtowerQubitTensorPow k).tmul (qtowerQubitTensorPow d))).trans + (tensorPowAdd qubit (k + 1) (d + 1)).symm + +theorem quditPowTower (n : ℕ) : IsWireReindexing (AxQM.quditPowTower n) := by + induction n with + | zero => exact refl qubit + | succ n ih => + exact (quditDimCongr (pow_succ' 2 (n + 1))).trans + ((quditProdIso 2 (2 ^ (n + 1))).trans ((refl qubit).tmul ih)) + +end IsWireReindexing + +end QSystem.Iso + +open QSystem.Iso (IsWireReindexing) + +/-- **The elementary-gate budget of an `Evolution` circuit (N&C Ex 4.29).** `CircuitBudget E t s` +holds when `E` is built, up to wire reindexing, from **at most `t`** `≤ 2`-control gates +(`Toffoli`/`CNOT`/`NOT`) and **at most `s`** single-qubit gates — single-qubit-*controlled* gates +`C(V)` (`ctrlGate`/`ctrlGateAdj`) or bare uncontrolled ones (`single`), `V` a single-qubit gate. +The predicate is the compositional accountant the `O(n²)` count of `Cⁿ(X)` +circuit needs: its leaves witness genuine elementary gates, and its structural constructors let the +counts of a composed circuit **add**. No constructor lowers a budget, so `CircuitBudget E t s` is an +honest upper bound on the gate count of a realisation of `E`. + +* `block` — a `≤ 2`-control block: a classical gate list `gs` (each gate `≤ 2` controls, + target not a control) whose circuit denotation `mcNotDenote gs` is realised by the `Evolution` `U` + on the flattened register `qubit ^⊗ₛ m`; contributes `gs.length` to the `≤ 2`-control count. +* `ctrlGate` / `ctrlGateAdj` — a single-qubit-controlled gate `C(unCtrl d g)` (resp. its adjoint + `C((unCtrl d g)†)`), `g : Evolution qubit`, wrapped by `n` idle controls; contributes `1` to the + single-qubit count. +* `single` — a bare (uncontrolled) single-qubit gate `g : Evolution qubit`, lifted `d` times by idle + wraps and placed on one wire of a register (`(unCtrl d g).onRight qubit`); contributes `1` to the + single-qubit count. This is the leading multiplexer `C⁰(V) = V` of the innermost Barenco reduction + layer (`barencoReductionCircuit 0`), the one gate of the `barencoNCircuit` recursion that is + neither a `≤ 2`-control gate nor a *controlled* single-qubit gate. It is an honest "single qubit + gate" in the exercise's sense; so the single-qubit count `s` bounds the controlled *and* + uncontrolled single-qubit gates together (each `O(1)`-decomposable to single-qubit + `CNOT` gates, + Exercise 4.22 / Figure 4.6). +* `bare` — a bare single-qubit gate `g : Evolution qubit` on a one-qubit register, with no idle + wires at all; contributes `1` to the single-qubit count. The degenerate leaf of `single` (the + register carries no wire to place a gate *on the right of*): it is the base of the single-qubit + gate on one tower wire (`qtowerSingleWire_circuitBudget`) when the tower is a single qubit. No + `unCtrl`/`onRight` wrap can shrink a register below one qubit, so it is its own constructor. +* `comp` — sequential composition: budgets add. +* `congr` — transport along a wire reindexing `e : S ≃ₛ T`: budget preserved. +* `mono` — weakening: a budget may be freely increased. -/ +inductive CircuitBudget : {S : QSystem} → Evolution S → ℕ → ℕ → Prop where + | block {m : ℕ} (gs : List (Concrete.McNotGate m)) (U : Evolution (qubit ^⊗ₛ m)) + (hgs : ∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) + (hU : ∀ c : Fin m → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) : + CircuitBudget U gs.length 0 + | ctrlGate {d n : ℕ} (g : Evolution qubit) : + CircuitBudget (unCtrl n (controlledUnitary (unCtrl d g))) 0 1 + | ctrlGateAdj {d n : ℕ} (g : Evolution qubit) : + CircuitBudget (unCtrl n (controlledUnitary (unCtrl d g).adjoint)) 0 1 + | single {d : ℕ} (g : Evolution qubit) : + CircuitBudget ((unCtrl d g).onRight qubit) 0 1 + | bare (g : Evolution qubit) : + CircuitBudget g 0 1 + | comp {S : QSystem} {E F : Evolution S} {t₁ s₁ t₂ s₂ : ℕ} + (hE : CircuitBudget E t₁ s₁) (hF : CircuitBudget F t₂ s₂) : + CircuitBudget (E.comp F) (t₁ + t₂) (s₁ + s₂) + | congr {S T : QSystem} {e : S.Iso T} {E : Evolution S} {t s : ℕ} + (he : IsWireReindexing e) (h : CircuitBudget E t s) : + CircuitBudget (Evolution.congr e E) t s + | mono {S : QSystem} {E : Evolution S} {t s t' s' : ℕ} + (h : CircuitBudget E t s) (ht : t ≤ t') (hs : s ≤ s') : + CircuitBudget E t' s' + +/-- **A budget transports along a register `Eq`.** If `E : Evolution M` has `CircuitBudget E t s`, +and `h : M = N`, then the transport `cast (congrArg Evolution h) E : Evolution N` has the same +budget. This is the equality-cast counterpart of the `congr` isomorphism constructor: it matches the +bare `cast (congrArg Evolution (qtower_qubit_comm ..))` the `barencoNCircuit` recursion uses to glue +a deeper layer onto its parent register (`barencoNCircuit_succ`). -/ +theorem CircuitBudget.cast_congr {M N : QSystem} (h : M = N) {E : Evolution M} {t s : ℕ} + (hb : CircuitBudget E t s) : + CircuitBudget (cast (congrArg Evolution h) E) t s := by + subst h + simpa using hb + +/-- **A product of uniformly-budgeted gates costs, per factor, one copy of that budget.** If every +gate in a list `l` has the *same* budget `CircuitBudget · t₀ s₀`, then their composition `l.prod` +has `CircuitBudget l.prod (l.length * t₀) (l.length * s₀)` — the counts scale with the number of +factors. The single induction behind every wire-by-wire gate layer, in both count coordinates at +once: `comp` adds the head gate's budget onto the tail's accumulated `t.length • (t₀, s₀)` (the +`succ_mul` step), and the `nil` base is the register-identity budget `hid` (`0 * t₀ = 0`, needed +because a general system `S` carries no elementary-gate witness for `1`). Its single-qubit +specialisation `CircuitBudget.listProd` (`t₀ = 0`, `s₀ = 1`) and its `≤ 2`-control specialisation +`CircuitBudget.listProd_twoControl` (`t₀ = 1`, `s₀ = 0`) recover the ergonomic clean-slot +conclusions `0 l.length` and `l.length 0` that callers consume. -/ +theorem CircuitBudget.listProd_uniform {S : QSystem} {t₀ s₀ : ℕ} + (hid : CircuitBudget (1 : Evolution S) 0 0) + (l : List (Evolution S)) (h : ∀ E ∈ l, CircuitBudget E t₀ s₀) : + CircuitBudget l.prod (l.length * t₀) (l.length * s₀) := by + induction l with + | nil => simpa using hid + | cons a t ih => + rw [List.prod_cons, List.length_cons, Evolution.mul_def, add_one_mul, add_one_mul] + exact ((h a (by simp)).comp (ih fun E hE => h E (by simp [hE]))).mono (by omega) (by omega) + +/-- **N&C Exercise 4.29: the per-layer budget.** For `2 ≤ k` (so the block index `k + 1` +is `≥ 3`) and any single-qubit root `g : Evolution qubit`, one Barenco tail reduction layer +`barencoTail (k+1) (unCtrl d g)` — on the control tower `qtower (k+1) (qubit ⊗ qtower d qubit)` — +has + +`CircuitBudget (barencoTail (k+1) (unCtrl d g)) (16 * (k + 1)) 2`, + +i.e. it is built from at most `16 (k+1) = O(k)` `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) — two +`Cᵏ⁺¹(X)` blocks of `≤ 8 (k+1)` each — and exactly two single-qubit-controlled gates +`C(unCtrl d g)`, `C((unCtrl d g)†)`. This repackages the per-layer reduction +`barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks` as a *composable* budget: the two +transported blocks `B = Evolution.congr (barencoBlockFlatten (k+1) d).symm U` each get `block` + +`congr`, the two single-qubit-controlled gates get `ctrlGateAdj` / `ctrlGate`, and `comp` sums the +counts (`2 · 8 (k+1)` blocks, `2` controlled gates), rounded to `16 (k+1)` via `mono`. Folding this +over the `barencoNCircuit` recursion gives the `O(n²)` count of Exercise 4.29. -/ +theorem barencoTail_unCtrl_circuitBudget (k d : ℕ) (hk : 2 ≤ k) (g : Evolution qubit) : + CircuitBudget (barencoTail (k + 1) (unCtrl d g)) (16 * (k + 1)) 2 := by + obtain ⟨gs, U, hgs, hlen, hUc, htail⟩ := + barencoTail_pauliXGate_onLeft_eq_splitLinearToffoliBlocks k d hk (unCtrl d g) + rw [htail] + have hB : CircuitBudget + (Evolution.congr (barencoBlockFlatten (k + 1) d).symm U) gs.length 0 := + CircuitBudget.congr (IsWireReindexing.barencoBlockFlatten (k + 1) d).symm + (CircuitBudget.block gs U hgs hUc) + refine (hB.comp + ((CircuitBudget.ctrlGateAdj (n := k + 1) (d := d) g).comp + (hB.comp (CircuitBudget.ctrlGate (n := k + 1) (d := d) g)))).mono ?_ ?_ + · omega + · omega + +end AxQM diff --git a/LeanPool/AxQM/Core/CircuitBudgetAdjoint.lean b/LeanPool/AxQM/Core/CircuitBudgetAdjoint.lean new file mode 100644 index 0000000000..e6424ba086 --- /dev/null +++ b/LeanPool/AxQM/Core/CircuitBudgetAdjoint.lean @@ -0,0 +1,185 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudget +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# The adjoint of a budgeted circuit is budgeted (N&C Problem 4.1, the `U_f†` uncompute) +# The adjoint of a budgeted circuit is budgeted (N&C Problem 4.1, the `U_f†` uncompute) + +Nielsen & Chuang, Problem 4.1 builds the compute–phase–uncompute circuit +`C = U_f† ∘ (I_A ⊗ D) ∘ U_f` and counts it as `2T + n` gates: the two Toffoli blocks `U_f`, `U_f†` +(`2T`) and the `n`-gate phase layer `D`. The uncompute step `U_f†` is, in N&C's words, "another `T` +Toffoli gates" — physically because *reversing* a circuit of `T` gates gives a circuit of `T` gates +(a Toffoli/CNOT/NOT is its own inverse, so `U_f†` is literally the same `T` gates in reverse order). + +The gate-count predicate `CircuitBudget E t s` (N&C Ex 4.29, `AxQM/Core/CircuitBudget.lean`) needs +the matching **closure**: if `E` is realised by at most `t` `≤ 2`-control gates and `s` single-qubit +gates, so is its adjoint `E†`. This file proves that closure, so that the `2T + n` count can +derive `CircuitBudget U_f† T 0` from the oracle's given `CircuitBudget U_f T 0` — rather than +assuming `U_f†`'s budget as a second, redundant hypothesis (which would be a weakening: `U_f†`'s +count is a *consequence* of `U_f`'s, not an independent given). + +## What is formalised + +* `CircuitBudget.adjoint` — **the closure**: `CircuitBudget E t s → CircuitBudget E.adjoint t s`, + by induction on the budget derivation. The reversal is honest per constructor — a controlled + single-qubit gate `C(V)` becomes `C(V†)` (`ctrlGate ↔ ctrlGateAdj`), a bare single-qubit gate + `g` becomes `g†`, a sequential composition reverses order (`(E ∘ F)† = F† ∘ E†`, budgets still + add), register transport commutes with the adjoint, and a `≤ 2`-control block `gs` + becomes the **reversed block** `gs.reverse` (same length, same valid gates). The gate *counts* + `(t, s)` are preserved exactly. + +The `block` case rests on the classical fact `Concrete.mcNotDenote_mcNotDenote_reverse` (a reversed +multiply-controlled-`NOT` circuit inverts the original, `mcNotDenote gs (mcNotDenote gs.reverse x) = +x`, from `Concrete.mcNot_involutive`), which is pure `Concrete` bit-string combinatorics and is +in `AxQM/Concrete/MultiControlledNotCircuit.lean` beside its `mcNotDenote_*` siblings. + +* `controlledUnitary_adjoint`, `unCtrl_adjoint`, `Evolution.onRight_adjoint`, + `Evolution.congr_adjoint`, `Evolution.adjoint_id` — the **adjoint-distribution helpers** the + closure fans out over: `C(U)† = C(U†)`, `(unCtrl n E)† = unCtrl n E†`, `(1 ⊗ V)† = 1 ⊗ V†`, + `(congr e U)† = congr e U†`, `1† = 1`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The identity gate is self-adjoint**, `1† = 1`. -/ +theorem Evolution.adjoint_id : (Evolution.id : Evolution S).adjoint = Evolution.id := by + apply Evolution.ext + rw [Evolution.adjoint_op, Evolution.id_op, ← ContinuousLinearMap.star_eq_adjoint, star_one] + +/-- **The adjoint distributes over the right-factor lift**, `(1 ⊗ V)† = 1 ⊗ V†`: the adjoint of a +gate acting on the right factor `T` of `S ⊗ T` (identity on `S`) is that factor gate's adjoint, +still on the right. The `.op` is `TensorProduct.mapL 1 V.op` (`Evolution.onRight`/`tmul_op`/ +`id_op`), whose adjoint distributes over the tensor (`TensorProduct.adjoint_mapL`), fixing the +self-adjoint +identity slot. -/ +theorem Evolution.onRight_adjoint (V : Evolution T) (S : QSystem) : + (V.onRight S).adjoint = V.adjoint.onRight S := by + apply Evolution.ext + have hone : ContinuousLinearMap.adjoint (1 : S.space →L[ℂ] S.space) = 1 := by + rw [← ContinuousLinearMap.star_eq_adjoint, star_one] + -- restate at the raw tensor head, where `adjoint`/`mapL` align for `TensorProduct.adjoint_mapL` + change ContinuousLinearMap.adjoint (TensorProduct.mapL (1 : S.space →L[ℂ] S.space) V.op) + = TensorProduct.mapL (1 : S.space →L[ℂ] S.space) (ContinuousLinearMap.adjoint V.op) + rw [TensorProduct.adjoint_mapL, hone] + +/-- **The adjoint commutes with register transport**, `(congr e U)† = congr e U†`: transporting `U` +along a system isomorphism `e` and taking the adjoint is the same as taking the adjoint and then +transporting. Holds because transport is conjugation by a `⋆`-algebra equivalence +(`LinearIsometryEquiv.conjStarAlgEquiv`), which preserves `star = adjoint` (`map_star`). -/ +theorem Evolution.congr_adjoint (e : S.Iso T) (U : Evolution S) : + (Evolution.congr e U).adjoint = Evolution.congr e U.adjoint := by + apply Evolution.ext + rw [Evolution.adjoint_op, Evolution.congr_op, Evolution.congr_op, Evolution.adjoint_op, + ← ContinuousLinearMap.star_eq_adjoint, ← ContinuousLinearMap.star_eq_adjoint, map_star] + +/-- **The adjoint of the idle wrapping**, `(unCtrl n E)† = unCtrl n E†`: wrapping a gate with `n` +idle control qubits and taking the adjoint equals taking the adjoint and re-wrapping (idle wires are +untouched by the reversal). Induction on `n` via `unCtrl_succ` and `Evolution.onRight_adjoint`. -/ +theorem unCtrl_adjoint (n : ℕ) (E : Evolution S) : + (unCtrl n E).adjoint = unCtrl n E.adjoint := by + induction n with + | zero => rfl + | succ n ih => + -- `unCtrl (n+1) E = (unCtrl n E).onRight qubit` definitionally; restate to align the + -- `Evolution.adjoint` system index with `onRight_adjoint`'s (`rw` needs a syntactic match) + change ((unCtrl n E).onRight qubit).adjoint = (unCtrl n E.adjoint).onRight qubit + rw [Evolution.onRight_adjoint, ih] + +/-- **The controlled-`U` gate's adjoint is the controlled adjoint**, `C(U)† = C(U†)` +(Nielsen & Chuang §4.3): `(|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U)† = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U†`, since the +rank-one computational-basis projectors and `I` are self-adjoint and the adjoint distributes over +`+` and `TensorProduct.mapL` (`TensorProduct.adjoint_mapL`). This mirrors the `hadjop` step of +`controlledUnitary_op_mem_unitary`. It is what turns a controlled single-qubit gate `C(V)` in a +`CircuitBudget` into `C(V†)` under the adjoint (`ctrlGate ↔ ctrlGateAdj`). -/ +theorem controlledUnitary_adjoint (U : Evolution S) : + (controlledUnitary U).adjoint = controlledUnitary U.adjoint := by + apply Evolution.ext + have hone : ContinuousLinearMap.adjoint (1 : S.space →L[ℂ] S.space) = 1 := by + rw [← ContinuousLinearMap.star_eq_adjoint, star_one] + -- restate at the raw tensor head `qubit.space ⊗[ℂ] S.space`, where the `+`/`adjoint`/`mapL` + -- align so the distribution lemmas fire (the composite `(qubit ⊗ S).space` head blocks them) + change ContinuousLinearMap.adjoint + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op) + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + (ContinuousLinearMap.adjoint U.op) + simp only [map_add, TensorProduct.adjoint_mapL, InnerProductSpace.adjoint_rankOne, hone] + +/-- **The adjoint of a budgeted circuit has the same budget** (Nielsen & Chuang Problem 4.1: the +`U_f†` uncompute costs the same `T` gates as `U_f`). If `E` is realised by at most `t` `≤ 2`-control +gates and `s` single-qubit gates (`CircuitBudget E t s`), then its adjoint `E†` is too: +`CircuitBudget E.adjoint t s`. The counts are preserved *exactly* — reversing a circuit neither adds +nor removes gates. + +Proved by induction on the budget derivation, reversing each constructor honestly: + +* `block gs` — the adjoint realises the **reversed** gate list `gs.reverse` (same length, same valid + gates): `U†` sends `|c⟩ ↦ |mcNotDenote gs.reverse c⟩`, obtained from `U|c⟩ = |mcNotDenote gs c⟩` + by `Evolution.evolvePure_adjoint_evolvePure` and the reverse-inverts identity + `Concrete.mcNotDenote_mcNotDenote_reverse`. +* `ctrlGate` / `ctrlGateAdj` — a controlled single-qubit gate `C(V)` swaps with its adjoint `C(V†)` + (`controlledUnitary_adjoint`, `unCtrl_adjoint`, and `Evolution.adjoint_adjoint`). +* `single` / `bare` — a single-qubit gate `g` becomes `g†` (`Evolution.onRight_adjoint`, + `unCtrl_adjoint`). +* `comp` — `(E ∘ F)† = F† ∘ E†` (`Evolution.adjoint_comp`); the budgets still add (`+` is + commutative). +* `congr` — transport commutes with the adjoint (`Evolution.congr_adjoint`). +* `mono` — a preserved budget is still `≤` the weakened bound. -/ +theorem CircuitBudget.adjoint {E : Evolution S} {t s : ℕ} (h : CircuitBudget E t s) : + CircuitBudget E.adjoint t s := by + induction h with + | block gs U hgs hU => + have hb : CircuitBudget U.adjoint gs.reverse.length 0 := + CircuitBudget.block gs.reverse U.adjoint + (fun g hg => hgs g (List.mem_reverse.mp hg)) + (fun c => by + have hrev : Concrete.mcNotDenote gs (Concrete.mcNotDenote gs.reverse c) = c := + Concrete.mcNotDenote_mcNotDenote_reverse gs (fun g hg => (hgs g hg).2) c + have hval := hU (Concrete.mcNotDenote gs.reverse c) + simp only [hrev] at hval + have h2 := congrArg U.adjoint.evolvePure hval + erw [Evolution.evolvePure_adjoint_evolvePure] at h2 + exact h2.symm) + rwa [List.length_reverse] at hb + | ctrlGate g => + rw [unCtrl_adjoint, controlledUnitary_adjoint] + exact CircuitBudget.ctrlGateAdj g + | ctrlGateAdj g => + rw [unCtrl_adjoint, controlledUnitary_adjoint, Evolution.adjoint_adjoint] + exact CircuitBudget.ctrlGate g + | single g => + rw [Evolution.onRight_adjoint, unCtrl_adjoint] + exact CircuitBudget.single g.adjoint + | bare g => exact CircuitBudget.bare g.adjoint + | comp hE hF ihE ihF => + rw [Evolution.adjoint_comp] + simpa only [Nat.add_comm] using ihF.comp ihE + | congr he hE ih => + rw [Evolution.congr_adjoint] + exact CircuitBudget.congr he ih + | mono hE ht hs ih => exact ih.mono ht hs + +end AxQM diff --git a/LeanPool/AxQM/Core/CircuitBudgetOnRight.lean b/LeanPool/AxQM/Core/CircuitBudgetOnRight.lean new file mode 100644 index 0000000000..4cf544be1f --- /dev/null +++ b/LeanPool/AxQM/Core/CircuitBudgetOnRight.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudget +public import LeanPool.AxQM.Core.PiTensorSuccHead +public import LeanPool.AxQM.Postulates.API.TensorPowSplit +public import LeanPool.AxQM.Postulates.API.SystemIsoCongrTmul +public import LeanPool.AxQM.Postulates.API.LeftPairGate + +/-! +# Adding an idle head wire preserves the elementary-gate budget (N&C Ex 4.29 / Prob 4.1) + +The elementary-gate budget `CircuitBudget E t s` (`Core/CircuitBudget`) is closed under sequential +composition, register transport, and weakening, but its constructors only *place* a gate on a fixed +register. Assembling a circuit wire-by-wire — the wire-addressed single-qubit gates of Problem 4.1's +phase layer `D`, each a `qtowerSingleWire n i g` peeling an idle head wire off the tower — needs one +more closure: **prepending an idle qubit preserves the budget.** That closure, +`CircuitBudget.onRight`, is the main result of this file. + +`CircuitBudget.onRight` — `CircuitBudget E t s → CircuitBudget (E.onRight qubit) t s`. Wrapping a +circuit with one idle head qubit `1 ⊗ E` costs no extra gates. By induction on the budget +derivation: the `single`/`ctrlGate`/`ctrlGateAdj` leaves absorb the extra idle qubit into their +`unCtrl` wrap (`unCtrl_succ`); `comp`/`congr`/`mono` distribute (via `Evolution.onRight_comp`, the +naturality `Evolution.congr_onRight`, and `mono`); and the `block` leaf reindexes its +classical `McNotGate` circuit by the head-wire shift `Concrete.mcNotConsWire` — the new head wire +`0` passes through (`Concrete.mcNotDenote_map_mcNotConsWire`), and the shifted block, transported +across the head split `QSystem.tensorPowSuccHead qubit m : qubit ^⊗ₛ (m+1) ≃ₛ qubit ⊗ qubit ^⊗ₛ m`, +is exactly `U.onRight qubit`. + +The proof uses the following general lemmas: +`Evolution.congr_tmul` / `Evolution.congr_onRight` (`AxQM/Postulates/API/SystemIsoCongrTmul.lean`), +`Evolution.evolvePure_congr` (`AxQM/Postulates/API/LeftPairGate.lean`), `QSystem.Iso.symm_symm` +(`AxQM/Postulates/API/SystemIsoComm.lean`), and the `PureState` head-split dictionaries +`tensorPowSuccHead_congr_piTensor` / `tensorPowSuccHead_symm_congr_tmul_piTensor` +(`AxQM/Core/PiTensorSuccHead.lean`, beside their `State` sibling); the `McNotGate` prepend-wire +reindex lemmas are in `AxQM/Concrete/MultiControlledNotCircuit.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **Adding an idle head qubit preserves the elementary-gate budget** (the wire-by-wire assembly +closure of N&C Ex 4.29's cost model). If `E` is built from at most `t` `≤ 2`-control gates and `s` +single-qubit gates, then so is the idle-front wrap `1 ⊗ E = E.onRight qubit`: wrapping a circuit +with one untouched head qubit adds no gates, +`CircuitBudget E t s → CircuitBudget (E.onRight qubit) t s`. + +Proved by induction on the budget derivation: + +* `single` / `ctrlGate` / `ctrlGateAdj`: the extra idle qubit is absorbed into the leaf's own idle + wrap, `(unCtrl n _).onRight qubit = unCtrl (n+1) _` (`unCtrl_succ`), reproducing the same leaf one + level up. +* `bare`: a bare gate `g.onRight qubit` is the `single` leaf at zero lifting, `unCtrl 0 g = g` + (`unCtrl_zero`). +* `comp`: the wrap distributes over composition (`Evolution.onRight_comp`) and the sub-budgets add. +* `congr`: the wrap commutes with the transport by the naturality `Evolution.congr_onRight`, then + `CircuitBudget.congr` re-applies it. +* `mono`: weaken the wrapped budget. +* `block`: the classical circuit `gs` on `qubit ^⊗ₛ m` is reindexed by the head-wire shift + `Concrete.mcNotConsWire` to a circuit `gs.map …` on `qubit ^⊗ₛ (m+1)` of the same length; the new + head wire passes through (`Concrete.mcNotDenote_map_mcNotConsWire`), so the shifted block — + transported across the head split `QSystem.tensorPowSuccHead qubit m` — is exactly + `U.onRight qubit`. The `1 ⊗ U` is realised on the computational basis by peeling the head factor + (`tensorPowSuccHead_congr_piTensor`), letting `U` act on the tail (`Evolution.onRight_evolvePure`, + `hU`), and reassembling the `cons` (`tensorPowSuccHead_symm_congr_tmul_piTensor`). -/ +theorem CircuitBudget.onRight {R : QSystem} {E : Evolution R} {t s : ℕ} + (h : CircuitBudget E t s) : CircuitBudget (E.onRight qubit) t s := by + induction h with + | @block m gs U hgs hU => + -- The shifted block, transported across the head split, is `U.onRight qubit`. + have key : CircuitBudget + (Evolution.congr (QSystem.tensorPowSuccHead qubit m).symm (U.onRight qubit)) + (gs.map Concrete.mcNotConsWire).length 0 := by + refine CircuitBudget.block (gs.map Concrete.mcNotConsWire) _ ?_ ?_ + · intro g' hg' + simp only [List.mem_map] at hg' + obtain ⟨g, hg, rfl⟩ := hg' + exact ⟨by rw [Concrete.mcNotConsWire_card]; exact (hgs g hg).1, + Concrete.mcNotConsWire_target_not_mem (hgs g hg).2⟩ + · intro c' + erw [Evolution.evolvePure_congr, QSystem.Iso.symm_symm, tensorPowSuccHead_congr_piTensor] + erw [Evolution.onRight_evolvePure] + rw [hU (fun j => c' j.succ), tensorPowSuccHead_symm_congr_tmul_piTensor] + have hmc : Concrete.mcNotDenote (gs.map Concrete.mcNotConsWire) c' + = Fin.cons (c' 0) (Concrete.mcNotDenote gs fun j => c' j.succ) := by + conv_lhs => rw [← Fin.cons_self_tail c'] + rw [Concrete.mcNotDenote_map_mcNotConsWire] + rfl + congr 1 + funext i + rw [hmc] + refine Fin.cases ?_ (fun j => ?_) i <;> + simp only [Fin.cons_zero, Fin.cons_succ] + rw [List.length_map] at key + have hcongr := CircuitBudget.congr + (IsWireReindexing.tensorPowSuccHead qubit m) key + rwa [Evolution.congr_congr_symm] at hcongr + | @single d g => + rw [← unCtrl_succ]; exact CircuitBudget.single g + | @bare g => + -- one idle head qubit over a bare gate is the `single` leaf with no lifting (`unCtrl 0`) + have h := CircuitBudget.single (d := 0) g + rwa [unCtrl_zero] at h + | @ctrlGate d n g => + rw [← unCtrl_succ]; exact CircuitBudget.ctrlGate g + | @ctrlGateAdj d n g => + rw [← unCtrl_succ]; exact CircuitBudget.ctrlGateAdj g + | comp _ _ ihE ihF => + rw [← Evolution.onRight_comp]; exact CircuitBudget.comp ihE ihF + | congr he _ ih => + rw [Evolution.congr_onRight] + exact CircuitBudget.congr ((IsWireReindexing.refl qubit).tmul he) ih + | mono _ ht hs ih => + exact ih.mono ht hs + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/CircuitBudgetOnRightTower.lean b/LeanPool/AxQM/Core/CircuitBudgetOnRightTower.lean new file mode 100644 index 0000000000..52016f2593 --- /dev/null +++ b/LeanPool/AxQM/Core/CircuitBudgetOnRightTower.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudgetOnRight +public import LeanPool.AxQM.Core.MultiControlledReduction +public import LeanPool.AxQM.Postulates.API.MeasureObservableRegister + +/-! +# Adding an idle head *tower* preserves the elementary-gate budget (N&C Problem 4.1) + +The single-qubit closure `CircuitBudget.onRight` (`Core/CircuitBudgetOnRight`) prepends **one** idle +head qubit to a budgeted circuit without changing its gate count. Problem 4.1's phase layer `D`, +however, is applied on the *ancilla* of the two-register circuit `qudit (2^m) ⊗ qudit (2^n)` — so to +budget the full phase block `I_A ⊗ D` we must prepend the whole idle **input register** `I_A`, a +tower of `m` qubits, not one. This file supplies that iterated closure. + +* `CircuitBudget.onRight_qtower` — the **tower closure**: + `CircuitBudget E t s → CircuitBudget (E.onRight (qtower k qubit)) t s`. Prepending the idle + `(k+1)`-qubit control tower `qtower k qubit` (`= qubitᵏ⁺¹`) adds no gates. Proved by induction on + `k`: the base `qtower 0 qubit = qubit` is the single-qubit closure `CircuitBudget.onRight`, and + each step peels the head qubit off the tower (`qtower (k+1) qubit = qubit ⊗ qtower k qubit` + definitionally), applies `CircuitBudget.onRight` to the inductive hypothesis, and re-associates + the two idle heads with `Evolution.congr_assoc_onRight_onRight` + `CircuitBudget.congr`. + +The associator naturality it iterates, `Evolution.congr_assoc_onRight_onRight` (the onRight mirror +of `Evolution.congr_assoc_symm_onLeft_onLeft`), is a general `Evolution.congr`/`onRight` transport +with no budget content; it is in `AxQM/Postulates/API/MeasureObservableRegister.lean` with the rest +of the `congr∘assoc∘{onLeft,onRight}` naturality family. + +Its Problem 4.1 use: with `E = D = diagPhase (computablePhaseAngle (n+1))` and the input register +`qudit (2^(m+1)) ≃ qtower m qubit` (`quditPowTower`), this gives +`CircuitBudget (I_A ⊗ D) 0 (n+1)` — the `n` single-qubit phase gates of the `2T + n` count, now on +the *full* input⊗ancilla register, which is then composed with the oracle's `2T` +Toffoli gates (`diagPhase_computablePhaseAngle_onRight_circuitBudget` in +[upstream `AxQM/NC/Ch4/Problem4_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_1.lean)). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **Prepending an idle control tower preserves the elementary-gate budget** (N&C Problem 4.1, the +idle input register of `I_A ⊗ D`). If `E` is built from at most `t` `≤ 2`-control gates and `s` +single-qubit gates, then so is the idle-tower wrap `1_{qtowerᵏ} ⊗ E = E.onRight (qtower k qubit)`: +prepending the untouched `(k+1)`-qubit tower `qtower k qubit` adds no gates, +`CircuitBudget E t s → CircuitBudget (E.onRight (qtower k qubit)) t s`. + +Proved by induction on `k`: + +* `k = 0`: `qtower 0 qubit = qubit`, so this is the single-qubit closure `CircuitBudget.onRight`. +* `k + 1`: `qtower (k+1) qubit = qubit ⊗ qtower k qubit` (definitionally), so the goal is + `CircuitBudget (E.onRight (qubit ⊗ qtower k qubit)) t s`. By + `Evolution.congr_assoc_onRight_onRight`, that circuit is the associator transport of + `(E.onRight (qtower k qubit)).onRight qubit` — the inductive hypothesis with one further idle head + qubit (`CircuitBudget.onRight`), whose budget is preserved by `CircuitBudget.congr`. -/ +theorem CircuitBudget.onRight_qtower {R : QSystem} {E : Evolution R} {t s : ℕ} + (h : CircuitBudget E t s) (k : ℕ) : + CircuitBudget (E.onRight (qtower k qubit)) t s := by + induction k with + | zero => exact h.onRight + | succ k ih => + change CircuitBudget (E.onRight (qubit ⊗ qtower k qubit)) t s + rw [← Evolution.congr_assoc_onRight_onRight E qubit (qtower k qubit)] + exact CircuitBudget.congr (IsWireReindexing.assoc qubit (qtower k qubit) R) + ih.onRight + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/CircuitBudgetSingleWire.lean b/LeanPool/AxQM/Core/CircuitBudgetSingleWire.lean new file mode 100644 index 0000000000..8a9ffb12e3 --- /dev/null +++ b/LeanPool/AxQM/Core/CircuitBudgetSingleWire.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudgetOnRight +public import LeanPool.AxQM.Core.QtowerSingleWireGate +public import LeanPool.AxQM.Postulates.API.MeasureObservableRegister +public import LeanPool.AxQM.Postulates.API.CompositeReducedEvolution + +/-! +# A single-qubit gate on *any* tower wire costs one single-qubit gate (N&C Problem 4.1) + +The elementary-gate budget `CircuitBudget E t s` (`Core/CircuitBudget`) has a leaf, `single`, for a +single-qubit gate on the **deepest** wire of the control tower (`(unCtrl d g).onRight qubit`), and +the idle-front closure `CircuitBudget.onRight` (`Core/CircuitBudgetOnRight`) that prepends one idle +head wire. Assembling Problem 4.1's phase layer `D` gate-by-gate needs a single-qubit gate on +**each** ancilla wire, not just the deepest one: the phase layer read on the tower is +`∏ₜ qtowerSingleWire n t.rev (phaseShiftGate (φ t))` (`quditPowTower_congr_phaseGradientLayer`), one +`Evolution.qtowerSingleWire` per wire `t.rev` ranging over **all** of `Fin (n+1)`. +This file proves that **placing a single-qubit gate on any tower wire costs +exactly one single-qubit gate.** + +* `qtowerSingleWire_zero_circuitBudget` — the **head-wire budget**: for every tower depth `m`, + `CircuitBudget (g.onLeft (qtower m qubit)) 0 1` — a single-qubit gate `g` on wire `0` (the head) + of `qtower (m+1) qubit`. By induction on `m`: the base `g.onLeft qubit` is the bare gate wrapped + by one idle wire and swapped to the front (`CircuitBudget.bare`, `CircuitBudget.onRight`, + `Evolution.tmul_congr_comm` on the braiding `QSystem.Iso.comm`); the step re-associates one more + idle wire to the front with the middle-factor braiding + `Evolution.congr_leftComm_onLeft_onRight`, `congr (leftComm) ((g.onLeft _).onRight qubit) = + g.onLeft (qubit ⊗ _)`, keeping the budget via `CircuitBudget.congr`. + +* `qtowerSingleWire_circuitBudget` — **main result**: `CircuitBudget (qtowerSingleWire n i g) 0 1` + for an arbitrary wire `i : Fin (n+1)`. By induction on `n` with `Fin.cases` on `i` over the + `qtowerSingleWire` recursion: at the single-qubit tower (`n = 0`) it is the bare gate + (`CircuitBudget.bare`, since `qtowerSingleWire 0 i g = g`); on wire `0` it is the head-wire budget + (`qtowerSingleWire_zero`); on wire `i'+1` it peels the idle head wire and applies the induction + hypothesis under `CircuitBudget.onRight` (`qtowerSingleWire_succ`). This makes each of Problem + 4.1's `n` single-qubit phase gates an honest `0 1` budget, whatever wire it sits on — the reusable + step feeding the phase-layer budget `CircuitBudget (I_A ⊗ D) 0 n`. + +Placing the *same* single-qubit gate on a different wire is one single-qubit gate either way: the +`CircuitBudget.congr` transports here relabel the register through **system isomorphisms** (the +tensor-factor braidings `comm` / `leftComm`), never insert a physical swap, so no gate is hidden. + +The idle-front closure it builds on is in `AxQM/Core/CircuitBudgetOnRight.lean`, and the +wire-addressed gate it budgets is in `AxQM/Core/QtowerSingleWireGate.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **The head-wire budget** (N&C Problem 4.1). A single-qubit gate `g` placed on wire `0` (the +head) of the control tower — `g.onLeft (qtower m qubit) = g ⊗ 1` on `qtower (m+1) qubit` — is one +single-qubit gate: `CircuitBudget (g.onLeft (qtower m qubit)) 0 1`. + +Proved by induction on the tower depth `m`. The base `m = 0` is the bare gate `g` wrapped by one +idle wire on the right (`CircuitBudget.bare` then `CircuitBudget.onRight`, giving `1 ⊗ g`), then +swapped to the front by the braiding `QSystem.Iso.comm` (`Evolution.tmul_congr_comm`: +`congr comm (1 ⊗ g) = g ⊗ 1`). The step re-associates one further idle wire to the front: the IH on +the +depth-`m` tower gets an idle head wire via `CircuitBudget.onRight`, then the middle-factor braiding +`Evolution.congr_leftComm_onLeft_onRight` (`congr (leftComm qubit qubit _) ((g.onLeft _).onRight +qubit) = g.onLeft (qubit ⊗ _)`) carries it into the depth-`m+1` head position, the budget preserved +by `CircuitBudget.congr`. -/ +theorem qtowerSingleWire_zero_circuitBudget : + ∀ (m : ℕ) (g : Evolution qubit), + CircuitBudget (g.onLeft (qtower m qubit)) 0 1 + | 0, g => by + -- base: `g ⊗ 1 = congr comm (1 ⊗ g)`, where `1 ⊗ g = g.onRight qubit` is the idle-front bare + have hbudget : CircuitBudget (Evolution.congr (QSystem.Iso.comm qubit qubit) + (g.onRight qubit)) 0 1 := + CircuitBudget.congr (IsWireReindexing.comm qubit qubit) + (CircuitBudget.bare g).onRight + have heq : Evolution.congr (QSystem.Iso.comm qubit qubit) (g.onRight qubit) + = g.onLeft qubit := Evolution.tmul_congr_comm Evolution.id g + rwa [heq] at hbudget + | m + 1, g => by + -- step: peel an idle head wire off the depth-`m` head gate, then braid it to the front + have h : CircuitBudget ((g.onLeft (qtower m qubit)).onRight qubit) 0 1 := + (qtowerSingleWire_zero_circuitBudget m g).onRight + have hbudget := CircuitBudget.congr + (IsWireReindexing.leftComm qubit qubit (qtower m qubit)) h + rwa [Evolution.congr_leftComm_onLeft_onRight] at hbudget + +/-- **A single-qubit gate on any tower wire costs one single-qubit gate** (N&C Problem 4.1, the `n` +single-qubit gates of the `2T + n` count). For every wire `i : Fin (n+1)` of the control tower +`qtower n qubit`, placing a single-qubit gate there has budget `CircuitBudget (qtowerSingleWire n i +g) 0 1` — at most one single-qubit gate, no `≤ 2`-control gates. + +Proved by induction on `n` with `Fin.cases` on the wire `i`, following the `qtowerSingleWire` +recursion: when the tower is a single qubit (`n = 0`, `qtowerSingleWire 0 i g = g`) it is the bare +leaf `CircuitBudget.bare`; on the head wire (`i = 0`, `qtowerSingleWire_zero`) it is the head-wire +budget `qtowerSingleWire_zero_circuitBudget`; on a later wire (`i = i'+1`, `qtowerSingleWire_succ`) +the placement peels an idle head wire, so the induction hypothesis on the depth-`n` tower is lifted +by the idle-front closure `CircuitBudget.onRight`. + +This is the reusable per-wire budget the phase-layer assembly folds over: each single-qubit phase +gate `qtowerSingleWire n t.rev (phaseShiftGate (φ t))` of Problem 4.1's phase gradient contributes +exactly `0 1`, whatever wire `t.rev` it sits on. -/ +theorem qtowerSingleWire_circuitBudget : + ∀ (n : ℕ) (i : Fin (n + 1)) (g : Evolution qubit), + CircuitBudget (Evolution.qtowerSingleWire n i g) 0 1 + | 0, _, g => CircuitBudget.bare g + | n + 1, i, g => by + refine Fin.cases ?_ (fun i' => ?_) i + · rw [Evolution.qtowerSingleWire_zero] + exact qtowerSingleWire_zero_circuitBudget n g + · rw [Evolution.qtowerSingleWire_succ] + exact (qtowerSingleWire_circuitBudget n i' g).onRight + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/CnotFanEvolutionBudget.lean b/LeanPool/AxQM/Core/CnotFanEvolutionBudget.lean new file mode 100644 index 0000000000..cf8a7d6958 --- /dev/null +++ b/LeanPool/AxQM/Core/CnotFanEvolutionBudget.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CnotFanEvolution +public import LeanPool.AxQM.Core.McNotCircuitBudget +public import LeanPool.AxQM.Core.FourGateReversibleWireTower +public import LeanPool.AxQM.Core.FourGateReachableWireTower +public import LeanPool.AxQM.Core.PhaseLayerBudget + +/-! +# The Figure-4.19 parity `CNOT` fan is `O(n)` two-qubit gates; the collector `Z`-rotation, one gate + +This file discharges the gate-count half of the **third step** of Nielsen & Chuang +**Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit gates". After the +`O(n)` single-qubit basis change of Problem 4.3(3) step 2 (`Core/PauliDiagWireTower`), the diagonal +Hamiltonian `Z^{⊗S}` is implemented by the Figure-4.19 parity circuit: a `CNOT` fan `V` computing +the support parity onto a collector wire, a single-qubit `Z`-rotation on the collector, then the +uncomputation `V†` (`Concrete/PauliStringParityCascade`). This file counts the two pieces — the fan +and the collector rotation — with the elementary-gate budget `CircuitBudget` (`Core/CircuitBudget`). + +The two pieces are the register `Evolution`s `cnotFanIntoEvolution` / `rotZWireEvolution` +(`Postulates/API`); their budgets are read off on the qubit control tower, where `CircuitBudget` +folds, using the register-tower bridges `quditPowTower_congr_mcNotWireEvolution` / +`quditPowTower_congr_rotZWireEvolution` already in the library. + +## What is formalised + +* `mcNotWireEvolution_circuitBudget` — the **register `≤ 2`-control leaf**: for `S.card ≤ 2`, + `CircuitBudget (mcNotWireEvolution (n+1) S t ht) 1 0` — a register `Toffoli`/`CNOT`/`NOT` is one + `≤ 2`-control gate. The register analogue of the tower leaf `mcNotTowerGate_circuitBudget` + (`Core/McNotCircuitBudget`): transport onto the tower along the reversible-wire register bridge + turns it into `mcNotTowerGate n (S.map Fin.revPerm) t.rev`, whose budget is + `mcNotTowerGate_circuitBudget` (the card unchanged by the wire relabelling, `Finset.card_map`). + +* `rotZWireEvolution_circuitBudget` — the **collector `Z`-rotation budget**: + `CircuitBudget (rotZWireEvolution (n+1) t θ) 0 1` — the single-qubit `R_z(θ)` on any register wire + is one single-qubit gate, whatever the angle `θ`. The `R_z`-instance of the per-wire single-qubit + budget: transport along `quditPowTower_congr_rotZWireEvolution` makes it the tower single-wire + gate `qtowerSingleWire n t.rev (rotZGate θ)`, budgeted `0 1` by `qtowerSingleWire_circuitBudget`. + This is the one single-qubit gate of Figure 4.19's collector rotation (its angle `θ = 2 h_g Δ` is + irrelevant to the count). + +* `cnotFanIntoEvolution_circuitBudget` — the **fan budget**: for a collector `c ∉ ts`, + `CircuitBudget (cnotFanIntoEvolution (n+1) c ts) ts.length 0` — the reverse `CNOT` fan into `c` + costs its `ts.length` `CNOT`s in `≤ 2`-control gates and no single-qubit gates. Proof (the + `≤ 2`-control analogue of `pauliDiagLayer_circuitBudget`): transport the fan onto the tower with + `Evolution.congr_prod` (a product of transported factors), then fold the per-`CNOT` budgets with + `CircuitBudget.listProd_twoControl` (base `CircuitBudget.id_qtower`). Each factor + `cnotWireEvolution (n+1) t c` for `t ∈ ts` is a genuine `CNOT` (`c ≠ t`, from `c ∉ ts`), budgeted + `1 0` by `mcNotWireEvolution_circuitBudget` (its single control `{t}` has card `1 ≤ 2`); the + `List.length` of the transported list is `ts.length` (`List.length_map`). The `ts.length` here is + the fan's `|S| − 1` `CNOT`s; with the uncomputation `V†` it is the `2(|S| − 1) = O(n)` two-qubit + gates of Figure 4.19. + +The tower `≤ 2`-control leaf it transports is in `AxQM/Core/McNotCircuitBudget.lean`, and +`AxQM/Core/PhaseLayerBudget.lean` has the `listProd`/`id_qtower` pattern it mirrors. The fan +`Evolution` itself is defined in `AxQM/Postulates/API/CnotFanEvolution.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **A register `Toffoli`/`CNOT`/`NOT` is one `≤ 2`-control gate.** For a control set `S` with at +most two wires (`S.card ≤ 2`) and target `t ∉ S`, the register multiply-controlled `NOT` +`mcNotWireEvolution (n+1) S t ht` on `qudit (2ⁿ⁺¹)` has budget +`CircuitBudget (mcNotWireEvolution (n+1) S t ht) 1 0`. The register analogue of the grounded tower +leaf `mcNotTowerGate_circuitBudget` (`Core/McNotCircuitBudget`): transport the gate onto the +`(n+1)`-qubit control tower along `quditPowTower_congr_mcNotWireEvolution`, where it is +`mcNotTowerGate n (S.map Fin.revPerm) t.rev` (the wire relabelling leaving the control count fixed, +`Finset.card_map`), read its budget with `mcNotTowerGate_circuitBudget`, and carry it back off the +tower with `CircuitBudget.congr`. This is the per-`CNOT` leaf the parity fan +`cnotFanIntoEvolution_circuitBudget` folds. -/ +theorem mcNotWireEvolution_circuitBudget {n : ℕ} (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) + (ht : t ∉ S) (hcard : S.card ≤ 2) : CircuitBudget (mcNotWireEvolution (n + 1) S t ht) 1 0 := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (mcNotWireEvolution (n + 1) S t ht), + quditPowTower_congr_mcNotWireEvolution] + exact CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm + (mcNotTowerGate_circuitBudget _ t.rev _ (by rw [Finset.card_map]; exact hcard)) + +/-- **The collector `Z`-rotation on a register wire is one single-qubit gate.** For every wire +`t : Fin (n+1)` and angle `θ`, the `R_z(θ)` rotation on wire `t` of the `2ⁿ⁺¹`-level register has +budget `CircuitBudget (rotZWireEvolution (n+1) t θ) 0 1` — one single-qubit gate and no +`≤ 2`-control gates. The `R_z`-instance of the per-wire single-qubit tower budget: transport along +`quditPowTower_congr_rotZWireEvolution` makes the transported gate the tower single-wire gate +`qtowerSingleWire n t.rev (rotZGate θ)`, whose budget is `qtowerSingleWire_circuitBudget`, then +`CircuitBudget.congr` carries the budget back off the tower. This is Figure 4.19's collector +`Z`-rotation `exp(-i h_g Δ Z_c)` counted as its one single-qubit gate (the angle irrelevant to the +count). The reachable-rotation analogue of `pauliDiagWireEvolution_circuitBudget`. -/ +theorem rotZWireEvolution_circuitBudget {n : ℕ} (t : Fin (n + 1)) (θ : ℝ) : + CircuitBudget (rotZWireEvolution (n + 1) t θ) 0 1 := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (rotZWireEvolution (n + 1) t θ), + quditPowTower_congr_rotZWireEvolution] + exact CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm + (qtowerSingleWire_circuitBudget n t.rev (rotZGate θ)) + +/-- **A single register `CNOT` (distinct control `a`, target `b`) is one `≤ 2`-control gate.** +For `b ≠ a`, `cnotWireEvolution (n+1) a b` reduces to `mcNotWireEvolution (n+1) {a} b` (the +`dif_neg` branch), a single control (`card {a} = 1 ≤ 2`), budgeted `1 0` by +`mcNotWireEvolution_circuitBudget`. The per-`CNOT` leaf folded by +`cnotFanIntoEvolution_circuitBudget`; the `≤ 2`-control twin of `rotZWireEvolution_circuitBudget`, +restoring the file's symmetry where every atomic register gate it touches carries its own named +`_circuitBudget`. -/ +theorem cnotWireEvolution_circuitBudget {n : ℕ} (a b : Fin (n + 1)) (h : b ≠ a) : + CircuitBudget (cnotWireEvolution (n + 1) a b) 1 0 := by + rw [cnotWireEvolution, dite_eq_right h] + exact mcNotWireEvolution_circuitBudget {a} b _ (by rw [Finset.card_singleton]; omega) + +/-- **Problem 4.3(3)'s Figure-4.19 parity `CNOT` fan is `ts.length` two-qubit gates.** For a +collector `c ∉ ts` (a duplicate-free control list `ts`), the reverse `CNOT` fan into `c` has budget + + `CircuitBudget (cnotFanIntoEvolution (n+1) c ts) ts.length 0` + +— at most `ts.length` `≤ 2`-control gates (its `CNOT`s) and no single-qubit gates. Together with the +uncomputation `V†` this is the `2(|S| − 1) = O(n)` two-qubit gates of Figure 4.19 (here +`ts` is the support minus the collector, so `ts.length = |S| − 1`). + +Proof — the `≤ 2`-control analogue of `pauliDiagLayer_circuitBudget`: transport the fan onto the +`(n+1)`-qubit control tower (`Evolution.congr_symm_congr` + `Evolution.congr_prod` + `List.map_map` +push the transport through the `List.prod`), where it is the ordered product of the transported +per-`CNOT` gates; fold their budgets with `CircuitBudget.listProd_twoControl` +(`Core/McNotCircuitBudget`, base `CircuitBudget.id_qtower`); then `CircuitBudget.congr` carries the +budget back off the tower. Each factor `cnotWireEvolution (n+1) t c` for `t ∈ ts` is a genuine +`CNOT` — `c ≠ t` from `c ∉ ts` — budgeted `1 0` by `cnotWireEvolution_circuitBudget`, and the +transported list has length `ts.length` (`List.length_map`). -/ +theorem cnotFanIntoEvolution_circuitBudget {n : ℕ} (c : Fin (n + 1)) (ts : List (Fin (n + 1))) + (hc : c ∉ ts) : CircuitBudget (cnotFanIntoEvolution (n + 1) c ts) ts.length 0 := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (cnotFanIntoEvolution (n + 1) c ts)] + refine CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm ?_ + rw [cnotFanIntoEvolution, Evolution.congr_prod, List.map_map] + have h := CircuitBudget.listProd_twoControl (CircuitBudget.id_qtower n) + (ts.map fun t => Evolution.congr (quditPowTower n) (cnotWireEvolution (n + 1) t c)) + (by + intro E hE + simp only [List.mem_map] at hE + obtain ⟨t, htmem, rfl⟩ := hE + exact CircuitBudget.congr (IsWireReindexing.quditPowTower n) + (cnotWireEvolution_circuitBudget t c (by rintro rfl; exact hc htmem))) + rwa [List.length_map] at h + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/ConditionalEntropy.lean b/LeanPool/AxQM/Core/ConditionalEntropy.lean new file mode 100644 index 0000000000..bbdd27f0bc --- /dev/null +++ b/LeanPool/AxQM/Core/ConditionalEntropy.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.PartialTrace + +/-! +# AxQM — quantum conditional entropy `S(A|B)` + +The **quantum conditional entropy** of a bipartite state `ρ` on `A ⊗ B` (Nielsen & Chuang §11.3.4, +summary of Chapter 11): + +`S(A|B) = S(A,B) − S(B)`, + +the von Neumann entropy of the whole minus that of the `B`-marginal. Unlike its classical +counterpart it can be **negative** — the signature of entanglement (a maximally entangled `ρ_{AB}` +has `S(A,B) = 0` but `S(B) = log dim B > 0`, so `S(A|B) = −log dim B < 0`). This negativity is what +makes several classical entropy inequalities fail quantumly (Nielsen & Chuang Problem 11.3). + +It is defined from `State.vonNeumannEntropy` and `State.reducedRight` (trace out the left +factor `A`). + +## Main definitions + +* `AxQM.State.condVonNeumannEntropy` — `S(A|B) = S(A,B) − S(B)`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- The **quantum conditional entropy** `S(A|B) = S(A,B) − S(B)` of a bipartite state `ρ` on +`A ⊗ B`: the von Neumann entropy of the joint state minus that of the reduced state on the +conditioning system `B` (the right factor, `ρ.reducedRight = Tr_A ρ`). Nielsen & Chuang §11.3.4. +May be negative when `A` and `B` are entangled. -/ +def State.condVonNeumannEntropy (ρ : State (S ⊗ T)) : ℝ := + ρ.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy + +/-- Unfolding lemma for the conditional entropy: `S(A|B) = S(A,B) − S(B)`. -/ +theorem State.condVonNeumannEntropy_def (ρ : State (S ⊗ T)) : + ρ.condVonNeumannEntropy = ρ.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy := rfl + +/-- The **coherent information** `I(A⟩B) = S(B) − S(A,B)` of a bipartite state `ρ` on `A ⊗ B`, +the negative of the conditional entropy `S(A|B)` (Nielsen & Chuang §12.4.2). It measures how much +quantum information about the reference `A` is preserved by the state on `B`; being `−S(A|B)`, it is +positive exactly when `S(A|B) < 0`, i.e. when `A` and `B` are entangled. In N&C's data processing +inequality (Theorem 12.10) the coherent information `I(ρ, E)` of a *quantum operation* is this +quantity evaluated on the reference–system state `R'Q'` obtained by purifying `ρ` and applying `E` +to the system factor. -/ +def State.coherentInfoOfState (ρ : State (S ⊗ T)) : ℝ := -ρ.condVonNeumannEntropy + +/-- Unfolding lemma for the state coherent information: `I(A⟩B) = S(B) − S(A,B)`, the right marginal +entropy minus the joint entropy. -/ +theorem State.coherentInfoOfState_def (ρ : State (S ⊗ T)) : + ρ.coherentInfoOfState = ρ.reducedRight.vonNeumannEntropy - ρ.vonNeumannEntropy := by + rw [State.coherentInfoOfState, State.condVonNeumannEntropy_def]; ring + +/-- **The state coherent information as mutual information minus reference entropy:** +`I(A⟩B) = S(A:B) − S(A)`. Both sides equal `S(B) − S(A,B)`: expanding the quantum mutual information +`S(A:B) = S(A) + S(B) − S(A,B)` and subtracting the reference marginal entropy `S(A)` leaves exactly +the coherent information. This bridge lets coherent-information (in)equalities be discharged by the +corresponding mutual-information results (the left/reference marginal `S(A)` being the shared, +often channel-invariant, term). -/ +theorem State.coherentInfoOfState_eq_vonNeumannMutualInfo_sub_reducedLeft (ρ : State (S ⊗ T)) : + ρ.coherentInfoOfState = ρ.vonNeumannMutualInfo - ρ.reducedLeft.vonNeumannEntropy := by + rw [State.coherentInfoOfState_def, State.vonNeumannMutualInfo_def]; ring + +end AxQM diff --git a/LeanPool/AxQM/Core/ControlledPowerSequence.lean b/LeanPool/AxQM/Core/ControlledPowerSequence.lean new file mode 100644 index 0000000000..1bd2a87a1b --- /dev/null +++ b/LeanPool/AxQM/Core/ControlledPowerSequence.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledReduction + +/-! +# The phase-estimation controlled-`U` sequence — first stage of Figure 5.2 (Nielsen & Chuang §5.2) + +The building blocks behind the first stage of the phase-estimation circuit +(N&C Figure 5.2): a `t`-qubit control register wrapping a target `S`, and, for each control wire, a +controlled power of `U` acting on `S`. On a computational-basis control `|j⟩ = |j₁…j_t⟩` the wire +`jₛ` applies `U^{jₛ·2^{t-s}}`, so the whole sequence applies `Uʲ`. + +These are the direct analogs, over an **arbitrary** inner target system `S`, of the register ket +`towerKet` (`Core/MultiControlledNotBasis`, inner system a qubit) and its gate-action lemmas: shared +theory that the phase-estimation cluster (N&C Exercises 5.7, 5.8, 5.9, …) consumes. Exercise 5.7 +([upstream `AxQM/NC/Ch5/Exercise5_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_7.lean)) applies `seqCtrlPow_evolvePure` (proved here) to state it. + +## What is formalised + +* `qtowerKet t b u` — the input state `|b₀…b_{t-1}⟩ ⊗ |u⟩` on the register `qtower t S` (`t` control + qubits wrapping the target `S`), for a bit-string `b : Fin t → Fin 2` (`b 0` the outermost / + most-significant wire) and an **arbitrary** target pure state `u : PureState S`. +* `seqCtrlPow U t` — the sequence of controlled-`U` operations of Figure 5.2, as an `Evolution` on + `qtower t S`. Built by recursion on the number of controls: the outermost (most-significant) wire + controls `U^{2^t}` on the target — reaching *through* the inner controls via the idle wrap + `unCtrl t` — and the remaining wires are the `t`-control sequence `seqCtrlPow U t`. +* `unCtrl_evolvePure_qtowerKet` — the idle wrap acts only on the target of a tower ket: the building + block that lets the outermost controlled gate of `seqCtrlPow` apply a power of `U` to the + innermost target. + +## Design notes + +* **Reaching through the register.** The `s`-th wire controls a power of `U` on the *innermost* + target `S`, which sits below the other control qubits. The idle wrap `unCtrl t (U^{2^t})` places + `U^{2^t}` on `S` while acting as the identity on the `t` inner control qubits, so no associator or + swap is needed; `controlledUnitary` then conditions it on the outermost wire. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The control register in a computational-basis state -/ + +/-- **The phase-estimation input state** `|b₀ … b_{t-1}⟩ ⊗ |u⟩` on `qtower t S` (`t` control qubits +wrapping the target `S`): the control register in the computational-basis state indexed by the +bit-string `b : Fin t → Fin 2` (`b 0` the outermost / most-significant wire), tensored with an +arbitrary target pure state `u`. The arbitrary-inner-system analog of `towerKet`. -/ +def qtowerKet : (t : ℕ) → (Fin t → Fin 2) → PureState S → PureState (qtower t S) + | 0, _, u => u + | (t + 1), b, u => (qubitBasis (b 0)) ⊗ qtowerKet t (Fin.tail b) u + +@[simp] theorem qtowerKet_zero (b : Fin 0 → Fin 2) (u : PureState S) : qtowerKet 0 b u = u := rfl + +/-- Peeling the outermost control wire of a tower ket: +`qtowerKet (t+1) b u = |b₀⟩ ⊗ qtowerKet t (tail b) u`. -/ +theorem qtowerKet_succ (t : ℕ) (b : Fin (t + 1) → Fin 2) (u : PureState S) : + qtowerKet (t + 1) b u = (qubitBasis (b 0)) ⊗ qtowerKet t (Fin.tail b) u := rfl + +/-! ### The sequence of controlled-`U` operations (first stage of Figure 5.2) -/ + +/-- **The sequence of controlled-`U` operations of Figure 5.2**, as an `Evolution` on the register +`qtower t S`. Recursion on the number of controls: `seqCtrlPow U 0` is the identity (no controls), +and `seqCtrlPow U (t+1)` conditions `U^{2^t}` on the outermost (most-significant) wire — placed on +the target `S` through the `t` inner controls by `unCtrl t` — and then runs the `t`-control sequence +on the remaining wires. On a computational-basis control `|j⟩` the wire of weight `2^w` contributes +`U^{jₛ·2^w}`, so the whole sequence applies `Uʲ` (`seqCtrlPow_evolvePure`, in +[upstream `AxQM/NC/Ch5/Exercise5_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_7.lean)). -/ +def seqCtrlPow (U : Evolution S) : (t : ℕ) → Evolution (qtower t S) + | 0 => Evolution.id + | (t + 1) => (controlledUnitary (unCtrl t (U ^ 2 ^ t))).comp ((seqCtrlPow U t).onRight qubit) + +@[simp] theorem seqCtrlPow_zero (U : Evolution S) : seqCtrlPow U 0 = Evolution.id := rfl + +/-- Peeling the outermost control of the sequence: +`seqCtrlPow U (t+1) = C(unCtrl t (U^{2^t})) · (seqCtrlPow U t on the inner register)`. -/ +theorem seqCtrlPow_succ (U : Evolution S) (t : ℕ) : + seqCtrlPow U (t + 1) + = (controlledUnitary (unCtrl t (U ^ 2 ^ t))).comp ((seqCtrlPow U t).onRight qubit) := rfl + +/-! ### The idle wrap acts only on the target of a tower ket -/ + +/-- **The idle wrap reaches through the controls to the target.** `unCtrl t V` (`V` wrapped by `t` +idle control qubits) acts on `|b⟩ ⊗ |u⟩` by leaving the control register `|b⟩` untouched and +applying `V` to the target `u`: `(unCtrl t V)(|b⟩⊗|u⟩) = |b⟩⊗(V|u⟩)`. The building block that lets +the outermost controlled gate of `seqCtrlPow` apply a power of `U` to the innermost target. -/ +theorem unCtrl_evolvePure_qtowerKet (V : Evolution S) : + ∀ (t : ℕ) (b : Fin t → Fin 2) (u : PureState S), + (unCtrl t V).evolvePure (qtowerKet t b u) = qtowerKet t b (V.evolvePure u) + | 0, _, _ => rfl + | (t + 1), b, u => by + simp only [qtower, unCtrl_succ, qtowerKet_succ, Evolution.onRight_evolvePure, + unCtrl_evolvePure_qtowerKet V t (Fin.tail b) u] + +end AxQM diff --git a/LeanPool/AxQM/Core/DeferredMeasurementReading.lean b/LeanPool/AxQM/Core/DeferredMeasurementReading.lean new file mode 100644 index 0000000000..46d3e601f1 --- /dev/null +++ b/LeanPool/AxQM/Core/DeferredMeasurementReading.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# Deferring a *composition* of gates past a measurement, at the reading level + +The operator-level results `Measurement.{bornProb,postMeasurement}_evolve_prod_of_forall_comm` +(`AxQM/Postulates/API/DeferredMeasurement.lean`) defer a whole composition `(Us.map V).prod` of +gates past a measurement `m` from the *operator* commutations `Mᵢ (V a) = (W a i) Mᵢ`. + +For gates and measurements such as `qtowerSingleWire` past `qtowerMeasurement`, the per-gate +commutation is not available as an operator identity. What one does have is each gate's two +*readings* — Born-probability invariance and post-measurement deferral. This file is the +**reading-level analog** of the operator-level results: it composes those readings down a list, so +a whole composition of gates — each individually invisible-to / deferring-past a measurement — +defers past it as one, with **no** operator commutation needed. + +If every gate `V a` is invisible to the statistics of `m` (`hb`) and defers past `m` to a branch +gate `W a i` (`hpm`), then: + +* `Measurement.bornProb_evolve_prod_of_forall_defers` — the whole composition `(Us.map V).prod` is + invisible to the statistics of `m`; +* `Measurement.postMeasurement_evolve_prod_of_forall_defers` — the whole composition defers past `m` + to the composed branch gates `(Us.map (fun a => W a i)).prod`. + +Both are plain `List` inductions chaining the single-gate readings; the collapse induction +transports the measured state across the peel with `Measurement.postMeasurement_congr_state` +(post-measurement states depend only on the state measured, not on the possibility proof). The +statements involve only `Measurement.bornProb`, `Measurement.postMeasurement` and +`Evolution.evolve`, and they subsume the several reading-level cascade deferrals that would +otherwise be proved separately for each item. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {α : Type*} {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- **Post-measurement states depend only on the measured state, not on the possibility proof.** If +`ρ = ρ'` then the collapsed states agree (once both outcomes are possible), by `subst` and proof +irrelevance of the `bornProb … ≠ 0` argument. This lets a deferral induction rewrite the *state* +being measured across a peeling step without dependent-cast friction. -/ +theorem postMeasurement_congr_state (m : Measurement ι S) {ρ ρ' : State S} (h : ρ = ρ') {i : ι} + (hp : m.bornProb ρ i ≠ 0) (hp' : m.bornProb ρ' i ≠ 0) : + m.postMeasurement ρ i hp = m.postMeasurement ρ' i hp' := by + subst h; rfl + +/-- **Outcome probabilities are unchanged when a whole composition of gates is deferred** (Postulate +3), from the per-gate *reading* (not operator commutation). If every gate `V a` is invisible to the +statistics of `m` — `m.bornProb ((V a).evolve ρ) i = m.bornProb ρ i` (`hb`) — then so is their whole +composition `(Us.map V).prod`. A plain `List` induction: the empty composition is the identity gate +(`Evolution.evolve_id`), and each `cons` peels the head gate off the front via +`Evolution.evolve_comp` and applies `hb` then the inductive hypothesis. The reading-level analog of +`bornProb_evolve_prod_of_forall_comm`, usable when no per-gate operator commutation is available. -/ +theorem bornProb_evolve_prod_of_forall_defers (m : Measurement ι S) (V : α → Evolution S) + (hb : ∀ (a : α) (ρ : State S) (i : ι), m.bornProb ((V a).evolve ρ) i = m.bornProb ρ i) + (Us : List α) (ρ : State S) (i : ι) : + m.bornProb ((Us.map V).prod.evolve ρ) i = m.bornProb ρ i := by + induction Us with + | nil => rw [List.map_nil, List.prod_nil, Evolution.one_def, Evolution.evolve_id] + | cons a t ih => + rw [List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.evolve_comp, hb a] + exact ih + +/-- **The post-measurement state defers a whole composition of gates** (Postulate 4), from the +per-gate *readings*. If every gate `V a` is invisible to the statistics of `m` (`hb`) and defers +past `m` to a branch gate `W a i` — `postMeas((V a) ρ (V a)†, i) = (W a i) · postMeas(ρ, i)` +(`hpm`) — then the whole composition `(Us.map V).prod` defers past `m` to the composed branch gates +`(Us.map (fun a => W a i)).prod`: + + `postMeas((Vₖ ⋯ V₁) ρ (Vₖ ⋯ V₁)†, i) = (Wₖ ⋯ W₁)ᵢ · postMeas(ρ, i)`. + +A `List` induction peeling the head gate off the front (`Evolution.evolve_comp`): the tail +composition defers by the inductive hypothesis, then the head gate defers by `hpm`, chained by +`postMeasurement_congr_state` (which moves the measured state across the peel without dependent-cast +friction). The reading-level analog of `postMeasurement_evolve_prod_of_forall_comm`, usable when no +per-gate operator commutation is available. -/ +theorem postMeasurement_evolve_prod_of_forall_defers (m : Measurement ι S) (V : α → Evolution S) + (W : α → ι → Evolution S) + (hb : ∀ (a : α) (ρ : State S) (i : ι), m.bornProb ((V a).evolve ρ) i = m.bornProb ρ i) + (hpm : ∀ (a : α) (ρ : State S) (i : ι) (hρ : m.bornProb ρ i ≠ 0) + (hρ' : m.bornProb ((V a).evolve ρ) i ≠ 0), + m.postMeasurement ((V a).evolve ρ) i hρ' = (W a i).evolve (m.postMeasurement ρ i hρ)) + (Us : List α) (ρ : State S) (i : ι) (hp : m.bornProb ρ i ≠ 0) + (hp' : m.bornProb ((Us.map V).prod.evolve ρ) i ≠ 0) : + m.postMeasurement ((Us.map V).prod.evolve ρ) i hp' + = (Us.map (fun a => W a i)).prod.evolve (m.postMeasurement ρ i hp) := by + revert hp' + induction Us with + | nil => + intro hp' + have hnil : (([] : List α).map V).prod.evolve ρ = ρ := by + rw [List.map_nil, List.prod_nil, Evolution.one_def, Evolution.evolve_id] + rw [postMeasurement_congr_state m hnil hp' hp, + List.map_nil, List.prod_nil, Evolution.one_def, Evolution.evolve_id] + | cons a t ih => + intro hp' + have hp_rest : m.bornProb ((t.map V).prod.evolve ρ) i ≠ 0 := by + rw [bornProb_evolve_prod_of_forall_defers m V hb t ρ i]; exact hp + have hp'' : m.bornProb ((V a).evolve ((t.map V).prod.evolve ρ)) i ≠ 0 := by + rw [hb a]; exact hp_rest + have hcons : ((a :: t).map V).prod.evolve ρ + = (V a).evolve ((t.map V).prod.evolve ρ) := by + rw [List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.evolve_comp] + rw [postMeasurement_congr_state m hcons hp' hp'', + hpm a ((t.map V).prod.evolve ρ) i hp_rest hp'', ih hp_rest, + List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.evolve_comp] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Core/DistillableEntanglement.lean b/LeanPool/AxQM/Core/DistillableEntanglement.lean new file mode 100644 index 0000000000..e76dae1d9a --- /dev/null +++ b/LeanPool/AxQM/Core/DistillableEntanglement.lean @@ -0,0 +1,116 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MaxEntMarginal +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.TensorPowState +public import LeanPool.AxQM.Postulates.API.TensorPowDim +public import LeanPool.AxQM.Postulates.API.StateMajorization +public import LeanPool.AxQM.Postulates.API.TraceDistance + +/-! +# AxQM — the asymptotic entanglement-distillation rate framework + +The framework behind **entanglement distillation** (N&C §12.5.2): the achievable-rate +predicate `IsDistillationRate` and the operational `distillableEntanglement := sSup` of achievable +rates, with their well-definedness (`bddAbove`, `nonneg`, the maximisation property). This mirrors +the `productStateCapacity` definitions in `AxQM/Core/ProductStateCapacity.lean` (a `sSup` of +achievable rates with its own `bddAbove`/`nonneg`/`le_*`). + +For a bipartite pure state `|ψ⟩`, `distillableEntanglement ρ_ψ` (`ρ_ψ` its reduced state) is the +operational amount of entanglement, in nats, extractable from copies of `|ψ⟩` as Bell states by +LOCC. The **optimality** upper bound `distillableEntanglement ρ ≤ S(ρ)` — the content of N&C +Exercise 12.23 — needs Fannes' inequality and is the subject of +[upstream `AxQM/NC/Ch12/Exercise12_23.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Exercise12_23.lean); here we prove only the crude, Fannes-free +well-definedness. + +## Well-definedness (Fannes-free) + +`bddAbove_isDistillationRate` bounds every achievable rate by `log (dim S)` **without** Fannes: +each target `μ_m` is a rank-`K_m` maximally entangled marginal with `S(μ_m) = log K_m`, and the +maximum-entropy bound `State.vonNeumannEntropy_le_log_finrank` gives +`log K_m = S(μ_m) ≤ log (finrank ℂ (S^⊗ₘ).space) = m · log (dim S)`, so `log K_m / m ≤ log (dim S)` +and hence `R ≤ log (dim S)` in the limit. This crude dimensional bound is all `sSup` needs; the +sharp bound `R ≤ S(ρ)` (the optimality converse) is proved separately with Fannes. +-/ + +@[expose] public section + +noncomputable section + +open Filter Topology + +namespace AxQM + +variable {S : QSystem} + +/-- **An achievable entanglement-distillation rate** (N&C §12.5.2). A real `R` (in *nats* of +entanglement per copy) is achievable for the marginal `ρ` if there is a family of LOCC protocols +that, from `ρ^⊗m` (Alice's marginal of `m` copies of `|ψ⟩`), produce outputs `σ_m` converging in +trace distance (fidelity → 1) to genuine rank-`K_m` maximally entangled marginals `μ_m`, with the +extraction rate `log (K_m) / m → R`. + +The `μ_m` pin the target to *actual* `K_m`-dimensional maximal entanglement (`IsMaxEntMarginal`), so +this captures LOCC extraction of Bell-type resources, not merely production of a high-entropy state. +For `K_m = 2ⁿ` the target is `n` Bell pairs. -/ +def IsDistillationRate (ρ : State S) (R : ℝ) : Prop := + ∃ (K : ℕ → ℕ) (σ μ : (m : ℕ) → State (S.tensorPow m)), + (∀ m, (ρ.tensorPow m).LOCCConvertible (σ m)) ∧ + (∀ m, (μ m).IsMaxEntMarginal (K m)) ∧ + Tendsto (fun m => (σ m).traceDistance (μ m)) atTop (𝓝 0) ∧ + Tendsto (fun m => Real.log (K m) / m) atTop (𝓝 R) + +/-- **The distillable entanglement** `D(ρ)` (N&C §12.5.2): the supremum of all achievable +distillation rates. Mirrors `productStateCapacity` (a `sSup` of achievable rates). For the marginal +`ρ_ψ` of a bipartite pure state `|ψ⟩`, `D(ρ_ψ)` is the operational amount of entanglement (in nats) +extractable from `|ψ⟩` as Bell states by LOCC. -/ +def distillableEntanglement (ρ : State S) : ℝ := + sSup {R | IsDistillationRate ρ R} + +/-- Achievable distillation rates are non-negative: `log K_m / m ≥ 0` for every `m` (`K_m : ℕ`, so +`log K_m ≥ 0`), hence so is the limit `R`. -/ +theorem isDistillationRate_nonneg {ρ : State S} {R : ℝ} (h : IsDistillationRate ρ R) : 0 ≤ R := by + obtain ⟨K, _, _, _, _, _, hR⟩ := h + refine le_of_tendsto_of_tendsto tendsto_const_nhds hR ?_ + filter_upwards with m + exact div_nonneg (Real.log_natCast_nonneg (K m)) (Nat.cast_nonneg m) + +/-- **The set of achievable distillation rates is bounded above** (by `log (dim S)`), so +`distillableEntanglement ρ` is a genuine supremum. Proved **without** Fannes: for `m ≥ 1`, the +rank-`K_m` maximally entangled target `μ_m` has `log K_m = S(μ_m)`, and the maximum-entropy bound +`State.vonNeumannEntropy_le_log_finrank` gives `S(μ_m) ≤ log (finrank ℂ (S^⊗ₘ).space) = +m · log (dim S)`, whence `log K_m / m ≤ log (dim S)` and, in the limit, `R ≤ log (dim S)`. -/ +theorem bddAbove_isDistillationRate (ρ : State S) : BddAbove {R | IsDistillationRate ρ R} := by + refine ⟨Real.log S.dim, ?_⟩ + rintro R ⟨K, _, μ, -, hμ, -, hR⟩ + refine le_of_tendsto_of_tendsto hR tendsto_const_nhds ?_ + filter_upwards [eventually_ge_atTop 1] with m hm + have hmpos : (0 : ℝ) < m := by exact_mod_cast hm + have hSμ : (μ m).vonNeumannEntropy = Real.log (K m) := (hμ m).vonNeumannEntropy_eq + -- `S(μ_m) ≤ log (finrank (S^⊗ₘ).space) = m · log (dim S)`. + have hfin : Module.finrank ℂ (S.tensorPow m).space = S.dim ^ m := QSystem.dim_tensorPow S m + have hle : (μ m).vonNeumannEntropy ≤ (m : ℝ) * Real.log S.dim := by + have h := (μ m).vonNeumannEntropy_le_log_finrank + rw [hfin, Nat.cast_pow, Real.log_pow] at h + exact h + rw [div_le_iff₀ hmpos, ← hSμ] + calc (μ m).vonNeumannEntropy ≤ (m : ℝ) * Real.log S.dim := hle + _ = Real.log S.dim * m := by ring + +/-- The maximisation property: an achievable distillation rate is `≤ distillableEntanglement ρ`. -/ +theorem le_distillableEntanglement {ρ : State S} {R : ℝ} (h : IsDistillationRate ρ R) : + R ≤ distillableEntanglement ρ := + le_csSup (bddAbove_isDistillationRate ρ) h + +/-- The distillable entanglement is non-negative. -/ +theorem distillableEntanglement_nonneg (ρ : State S) : 0 ≤ distillableEntanglement ρ := + Real.sSup_nonneg fun _ hR => isDistillationRate_nonneg hR + +end AxQM diff --git a/LeanPool/AxQM/Core/EntanglementEntropyMonotone.lean b/LeanPool/AxQM/Core/EntanglementEntropyMonotone.lean new file mode 100644 index 0000000000..bf9eb080b8 --- /dev/null +++ b/LeanPool/AxQM/Core/EntanglementEntropyMonotone.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.StateMajorization +public import LeanPool.AxQM.Postulates.API.RandomUnitaryEntropy + +/-! +# AxQM — von Neumann entropy is monotone non-increasing under LOCC / majorization + +For bipartite pure states, converting `|ψ⟩` to `|φ⟩` by local operations and classical +communication (LOCC) can only **decrease** the entanglement, measured by the von Neumann entropy of +the reduced state. At the reduced-state level (where Nielsen's theorem lives, N&C Thm 12.15): + +`ρ.Majorize σ → σ.vonNeumannEntropy ≤ ρ.vonNeumannEntropy`, + +equivalently `ρ.LOCCConvertible σ → S(σ) ≤ S(ρ)`. Since `ρ ≺ σ` (majorization) is Nielsen's +condition for `|ψ⟩ → |φ⟩` by LOCC — and majorization `ρ ≺ σ` means the eigenvalue distribution of +`σ` is *more concentrated* (lower Shannon entropy) than that of `ρ` — this is the statement that +**entanglement entropy cannot be increased by LOCC**. + +## Use in N&C Exercise 12.23 + +This is the monotone behind the **optimality of entanglement distillation** (N&C +Exercise 12.23): the distillable entanglement of `|ψ⟩` cannot exceed `S(ρ_ψ)`, because distilling +Bell states out of copies of `|ψ⟩` by LOCC can only reduce the total entanglement entropy, and `n` +Bell states carry entanglement entropy `n · log 2`. The converse bound of Exercise 12.23 +uses this lemma together with additivity of the entropy across copies and the asymptotic +distillation-rate framework. + +## Proof + +`ρ ≺ σ` is realised as a **random-unitary mixture** of `σ`: by the forward operator-majorization +theorem (`State.exists_op_eq_sum_unitary_conj_of_majorize`, N&C Thm 12.13 at the density-operator +level) there are unitaries `Uⱼ` and probabilities `pⱼ` with `ρ.op = ∑ⱼ pⱼ Uⱼ σ.op Uⱼ†`, i.e. +`ρ = ∑ⱼ pⱼ (Uⱼ σ Uⱼ†)` is the probabilistic mixture of the unitary conjugates `(Uⱼ).evolve σ`. +A mixture of unitary conjugates of `σ` never decreases the entropy +(`State.vonNeumannEntropy_le_mix_evolve`, the shared core also behind +`RandomUnitaryChannel.vonNeumannEntropy_apply_ge`): faithfulness-free concavity +(`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`, the mixture being generally +rank-deficient) gives `S(ρ) ≥ ∑ⱼ pⱼ S(Uⱼ σ Uⱼ†)`, and unitary invariance +(`State.vonNeumannEntropy_evolve`, `S(Uⱼ σ Uⱼ†) = S(σ)`) collapses the right-hand side to +`(∑ⱼ pⱼ) S(σ) = S(σ)`. + +The proof works at the operator level (`.op`); the operator-level majorization results it invokes +are in `AxQM/Postulates/API/StateMajorization.lean`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +namespace State + +variable {S : QSystem} + +/-- **Entanglement entropy is monotone non-increasing under majorization.** If `ρ.Majorize σ` +(N&C's `ρ ≺ σ`, Nielsen's LOCC condition on the reduced states) then `S(σ) ≤ S(ρ)`. + +`ρ ≺ σ` presents `ρ` as a random-unitary mixture `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` of `σ` +(`State.exists_op_eq_sum_unitary_conj_of_majorize`), and a mixture of unitary conjugates of `σ` +never decreases the entropy (`State.vonNeumannEntropy_le_mix_evolve`), giving `S(σ) ≤ S(ρ)`. -/ +theorem Majorize.vonNeumannEntropy_le {ρ σ : State S} (h : ρ.Majorize σ) : + σ.vonNeumannEntropy ≤ ρ.vonNeumannEntropy := by + obtain ⟨ι, hι, p, U, hp, hsum, hunit, hρ⟩ := exists_op_eq_sum_unitary_conj_of_majorize h + -- `ρ` is the random-unitary mixture of `σ`: package each unitary `Uⱼ` as an evolution. + have hmix : ρ = State.mix p hp hsum (fun j => (⟨U j, hunit j⟩ : Evolution S).evolve σ) := by + apply State.ext + rw [State.mix_op, hρ] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [Evolution.evolve_op] + -- A mixture of unitary conjugates of `σ` never decreases the entropy. + rw [hmix] + exact State.vonNeumannEntropy_le_mix_evolve p hp hsum (fun j => ⟨U j, hunit j⟩) σ + +/-- **Entanglement entropy cannot be increased by LOCC** (the `LOCCConvertible` form of +`State.Majorize.vonNeumannEntropy_le`). If `ρ` is one-way LOCC convertible to `σ` then +`S(σ) ≤ S(ρ)`. Follows from the forward direction of Nielsen's theorem +(`State.LOCCConvertible.majorize`, `ρ.LOCCConvertible σ → ρ.Majorize σ`) and the majorization +monotone. -/ +theorem LOCCConvertible.vonNeumannEntropy_le {ρ σ : State S} (h : ρ.LOCCConvertible σ) : + σ.vonNeumannEntropy ≤ ρ.vonNeumannEntropy := + h.majorize.vonNeumannEntropy_le + +end State + +end AxQM diff --git a/LeanPool/AxQM/Core/EntropyTensorPow.lean b/LeanPool/AxQM/Core/EntropyTensorPow.lean new file mode 100644 index 0000000000..1a304e770c --- /dev/null +++ b/LeanPool/AxQM/Core/EntropyTensorPow.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.PiTensorSuccHead +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.Postulates.API.TensorPowState +public import LeanPool.AxQM.Postulates.API.TensorPowDim +public import LeanPool.AxQM.Postulates.API.Entropy + +/-! +# AxQM — von Neumann entropy is additive across tensor factors + +The von Neumann entropy adds over the factors of an (uncorrelated) product state. This file lifts +the binary additivity `State.vonNeumannEntropy_tmul` (N&C Exercise 11.13, `S(ρ ⊗ σ) = S(ρ) + S(σ)`) +to the `n`-ary indexed product `State.piTensor` and, as the constant-family special case, to the +`n`-fold tensor power `State.tensorPow`: + +* `State.vonNeumannEntropy_piTensor`: `S(⨂ᵢ fᵢ) = ∑ᵢ S(fᵢ)`; +* `State.vonNeumannEntropy_tensorPow`: `S(ρ^⊗n) = n · S(ρ)`. + +## Use in N&C Exercise 12.23 + +Copy-accounting for the **optimality of entanglement distillation** (N&C Exercise 12.23): distilling +Bell states out of `m` copies of `|ψ⟩` by LOCC can only reduce the entanglement entropy +(`State.LOCCConvertible.vonNeumannEntropy_le`), and the total entanglement entropy of the `m` +copies is `S(ρ_ψ^⊗m) = m · S(ρ_ψ)`. This exact linear scaling — supplied by +`State.vonNeumannEntropy_tensorPow` — is what turns the per-transformation monotone into the +asymptotic converse bound `rate ≤ S(ρ_ψ)` (the distillable entanglement cannot exceed `S(ρ_ψ)`). + +## Proof + +Induction on the number of tensor factors, mirroring `State.holevoChi_piTensor_le`. + +* **Base (`n = 0`).** The empty product lives on the one-dimensional system `S ^⊗ₛ 0`, so its + entropy is squeezed between `0` (`State.vonNeumannEntropy_nonneg`) and `log (dim) = log 1 = 0` + (`State.vonNeumannEntropy_le_log_finrank` with `QSystem.finrank_tensorPow_space`), while the empty + sum is `0`. +* **Step (`n+1`).** Peel the head factor with the `cons`-recursion isomorphism + `State.tmul_piTensor_congr_tensorPowSuccHead_symm`, writing `⨂ᵢ fᵢ` as a system-isomorphic copy of + `f 0 ⊗ (⨂ⱼ f j.succ)`. Entropy is transport-invariant (`State.vonNeumannEntropy_congr`), then the + binary additivity (`State.vonNeumannEntropy_tmul`) and the induction hypothesis give + `S(f 0) + ∑ⱼ S(f j.succ) = ∑ᵢ S(fᵢ)` (`Fin.sum_univ_succ`). + +The `succ` step uses the head-peel recursion `State.tmul_piTensor_congr_tensorPowSuccHead_symm` +(`AxQM/Core/PiTensorSuccHead.lean`). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +namespace State + +variable {S : QSystem} + +/-- **Additivity of the von Neumann entropy over an indexed product state.** For a finite family of +states `f : Fin n → State S`, the entropy of the product `⨂ᵢ fᵢ` is the sum of the entropies: + +`S(⨂ᵢ fᵢ) = ∑ᵢ S(fᵢ)`. + +The `n`-ary form of `State.vonNeumannEntropy_tmul`, proved by induction on the number of factors +using the head-peel recursion `State.tmul_piTensor_congr_tensorPowSuccHead_symm` (the empty product +sits on the one-dimensional system `S ^⊗ₛ 0`, so has zero entropy). -/ +theorem vonNeumannEntropy_piTensor : + ∀ {n : ℕ} (f : Fin n → State S), + (State.piTensor f).vonNeumannEntropy = ∑ i, (f i).vonNeumannEntropy + | 0, f => by + -- `S ^⊗ₛ 0` is one-dimensional, so every state on it has zero entropy; the empty sum is `0`. + have hz : ∀ σ : State (S ^⊗ₛ 0), σ.vonNeumannEntropy = 0 := fun σ => by + have h := σ.vonNeumannEntropy_le_log_finrank + rw [QSystem.finrank_tensorPow_space, pow_zero, Nat.cast_one, Real.log_one] at h + exact le_antisymm h σ.vonNeumannEntropy_nonneg + rw [Fin.sum_univ_zero] + exact hz _ + | n + 1, f => by + have ih := vonNeumannEntropy_piTensor (fun j : Fin n => f j.succ) + -- Peel the head factor: `⨂ᵢ fᵢ ≃ₛ f 0 ⊗ (⨂ⱼ f j.succ)`, and entropy is transport-invariant. + have hcongr : (State.piTensor f).vonNeumannEntropy + = ((f 0).tmul (State.piTensor fun j : Fin n => f j.succ)).vonNeumannEntropy := by + conv_lhs => rw [← State.tmul_piTensor_congr_tensorPowSuccHead_symm f] + exact State.vonNeumannEntropy_congr _ _ + rw [hcongr, State.vonNeumannEntropy_tmul, ih, Fin.sum_univ_succ] + +/-- **The von Neumann entropy is additive across copies.** For a state `ρ : State S` and `n : ℕ`, +the entropy of the `n`-fold tensor power scales linearly: + +`S(ρ^⊗n) = n · S(ρ)`. + +The constant-family special case of `State.vonNeumannEntropy_piTensor`, collapsing +`∑ _ : Fin n, S(ρ)` to `n · S(ρ)`. This is the copy-accounting behind the optimality of +entanglement distillation (N&C Exercise 12.23): +`m` copies of `|ψ⟩` carry total entanglement entropy `m · S(ρ_ψ)`. -/ +theorem vonNeumannEntropy_tensorPow (ρ : State S) (n : ℕ) : + (ρ.tensorPow n).vonNeumannEntropy = n * ρ.vonNeumannEntropy := by + have h : (ρ.tensorPow n).vonNeumannEntropy = ∑ _i : Fin n, ρ.vonNeumannEntropy := + vonNeumannEntropy_piTensor (fun _ : Fin n => ρ) + rw [h, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + +end State + +end AxQM diff --git a/LeanPool/AxQM/Core/EvolutionQubitBasisExt.lean b/LeanPool/AxQM/Core/EvolutionQubitBasisExt.lean new file mode 100644 index 0000000000..770df93759 --- /dev/null +++ b/LeanPool/AxQM/Core/EvolutionQubitBasisExt.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.WirePermutation +public import LeanPool.AxQM.Postulates.API.Qubit +public import Mathlib.LinearAlgebra.PiTensorProduct.Basis + +/-! +# Computational-basis extensionality for evolutions on a qubit register (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. `Cⁿ(X)` and every `Toffoli`/`CNOT`/`NOT` block +are **classical** gates — they permute the computational basis — so the natural way to prove two +such gates *equal* is to check they agree on every computational basis state and invoke *"agreement +on all basis states is full agreement"*. The results `cnx_evolvePure_towerKet`, +`tensorPowMcCtrlX_evolvePure_piTensor` and `placedMcCtrlX_evolvePure_qubitBasis` all state their +content as such a computational-basis **truth table**; turning a pair of matching truth tables into +an `Evolution` identity is the step this file makes into a lemma. + +The library already has `Evolution.ext_tensorPow`: two evolutions of `S ^⊗ₛ n` are equal once their +operators agree on **every** elementary tensor `⨂ᵢ f i` (arbitrary vectors `f i : S.space`). Product +states span the register, so that is full agreement. This file specialises it to the qubit register, +replacing the *continuum* of elementary tensors `⨂ᵢ f i` by the *finite* family of computational +product states `⨂ᵢ |c i⟩` (`c : Fin m → Fin 2`): since the two computational basis vectors +`|0⟩, |1⟩` are a basis of `qubit.space`, the products `⨂ᵢ |c i⟩` are a basis of `qubit ^⊗ₛ m` +(`Basis.piTensorProduct`), so agreement there already forces operator equality. + +## What is formalised + +* `Evolution.ext_qubitBasis` — **two evolutions of `qubit ^⊗ₛ m` agreeing on every computational + product state are equal.** It upgrades a computational-basis truth table (the form every + classical-gate result is stated in) to an honest `Evolution` identity: to prove `A = B` for two + classical gates it suffices to check `A |c⟩ = B |c⟩` for every bit-string `c : Fin m → Fin 2`. + +## Design notes + +* **Why the finite computational basis, not all product states.** `Evolution.ext_tensorPow` demands + agreement on `⨂ᵢ f i` for *arbitrary* `f i : qubit.space` — but a classical gate's truth table is + only ever known on the computational basis `|0⟩, |1⟩`. Because those two vectors are a `ℂ`-basis + of the two-dimensional `qubit.space` (`finrank_qubit_space`, `qubitBasis_vec_orthonormal`), the + computational products `⨂ᵢ |c i⟩` form the `Basis.piTensorProduct` basis of `qubit ^⊗ₛ m`, and a + (continuous) linear map is determined by its values on a basis (`Basis.ext`). So the finite, + checkable hypothesis is *equivalent* to the elementary-tensor one, not weaker. +* **The proof.** `Evolution.ext` reduces to `A.op = B.op`; `ContinuousLinearMap.coe_injective` + reduces that to the underlying linear maps; `Basis.ext` against the qubit + `Basis.piTensorProduct` reduces to agreement on each basis vector `⨂ᵢ |c i⟩`; and there the + bridges `Evolution.evolvePure_vec` (`(A |ψ⟩).vec = A.op ψ.vec`) and `PureState.piTensor_vec` + (`(⨂ᵢ ψ i).vec = ⨂ᵢ (ψ i).vec`) — both `@[simp]`/`rfl` — collapse the hypothesis `A |c⟩ = B |c⟩` + onto the required operator equation by kernel-level defeq. The qubit `ℂ`-basis is the reusable + `qubitModuleBasis` (`AxQM/Postulates/API/Qubit.lean`, alongside `quditOrthonormalBasis`). +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Computational-basis extensionality for evolutions of a qubit register.** Two evolutions +`A B : Evolution (qubit ^⊗ₛ m)` are equal once they agree on every computational product basis state +`⨂ᵢ |c i⟩` (`c : Fin m → Fin 2`). This is the classical-gate analogue of `Evolution.ext_tensorPow`: +it replaces the continuum of elementary tensors `⨂ᵢ f i` by the finite, checkable family of +computational product states, because the two computational basis vectors `|0⟩, |1⟩` are a basis of +`qubit.space` and hence the products `⨂ᵢ |c i⟩` are a basis of the register +(`Basis.piTensorProduct`). It is the tool that turns a computational-basis truth table — the form in +which `Cⁿ(X)` and every `Toffoli`/`CNOT`/`NOT` block is specified — into an honest `Evolution` +identity ("agreement on all basis states is full agreement"). -/ +theorem Evolution.ext_qubitBasis {m : ℕ} {A B : Evolution (qubit ^⊗ₛ m)} + (h : ∀ c : Fin m → Fin 2, + A.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = B.evolvePure (PureState.piTensor fun i => qubitBasis (c i))) : + A = B := by + -- Reduce to equality of the underlying linear operators, then check on the computational product + -- basis `⨂ᵢ |c i⟩`, the `Basis.piTensorProduct` of the qubit `ℂ`-basis `|0⟩, |1⟩` + -- (`qubitModuleBasis`). + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + refine (Basis.piTensorProduct fun _ : Fin m => qubitModuleBasis).ext ?_ + intro c + rw [Basis.piTensorProduct_apply] + simp only [qubitModuleBasis_apply] + -- The remaining operator goal is `congrArg vec (h c)` up to the `@[simp]`/`rfl` bridges + -- `Evolution.evolvePure_vec` and `PureState.piTensor_vec` (kernel-level defeq). + exact congrArg PureState.vec (h c) + +end AxQM diff --git a/LeanPool/AxQM/Core/EvolutionTowerBasisExt.lean b/LeanPool/AxQM/Core/EvolutionTowerBasisExt.lean new file mode 100644 index 0000000000..a1bd902bfc --- /dev/null +++ b/LeanPool/AxQM/Core/EvolutionTowerBasisExt.lean @@ -0,0 +1,116 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerCircuit +public import LeanPool.AxQM.Core.QtowerTensorPow +public import LeanPool.AxQM.Core.EvolutionQubitBasisExt + +/-! +# Computational-basis extensionality for tower evolutions (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` and must re-express each of its transported gates — +`Evolution.congr (quditPowTower n) (quditGate M)` — as a **wire-addressed tower `Evolution`** (a +Hadamard on a wire `Evolution.qtowerSingleWire`, a controlled-`Rₖ` on a wire pair). Every such +re-expression is an **`Evolution` identity**, and the way each is proved is by checking the two +gates agree on every computational tower basis state `towerKet n b` — the form in which the reader +`quditPowTower_congr_evolvePure_towerKet` and the placement gates' +actions (`qtowerSingleWire_evolvePure_towerKet`, `qtowerPermWires_evolvePure_towerKet`) are all +stated. This file proves the bridge from *"agree on every `towerKet n b`"* to *"equal as +`Evolution`s"* on the tower, and gives the combinator that turns a transported-gate +re-expression into exactly that basis-ket check. + +## What is formalised + +* `Evolution.ext_towerKet` — **two evolutions of `qtower n qubit` agreeing on every computational + tower basis state are equal.** The `qtower` analogue of `Evolution.ext_qubitBasis` (which lives on + the *symmetric* register `qubit ^⊗ₛ (n+1)`): it lets a computational-basis truth table on the + right-nested control tower be upgraded to an honest `Evolution` identity. Proved by + transporting both gates across the `qtower ↔ tensor-power` bridge `qtowerQubitTensorPow n` and + invoking `Evolution.ext_qubitBasis` there, then pulling the equality back through the transport + roundtrip `Evolution.congr_symm_congr`. +* `quditPowTower_congr_eq_of_evolvePure_towerKet` — **the transported-gate re-expression + combinator.** To prove a transported register gate `Evolution.congr (quditPowTower n) U` equals a + wire-addressed tower gate `V`, it suffices to check, for every bit-string `b`, that `V` sends + `towerKet n b` to the transport of `U`'s action on the register ket + `|finFunctionFinEquiv (b ∘ Fin.rev)⟩` — i.e. exactly the right-hand side the tower reader + `quditPowTower_congr_evolvePure_towerKet` computes for the transported gate. This packages + `Evolution.ext_towerKet` with the reader into the single tool each Figure 5.1 gate's + wire-addressed re-expression is discharged by. + +It is assembled from the bridge `AxQM/Core/QtowerTensorPow.lean`, the tower reader in +`AxQM/Core/QftTowerCircuit.lean`, and the sibling qubit-register extensionality in +`AxQM/Core/EvolutionQubitBasisExt.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Computational-basis extensionality for evolutions of the control tower.** Two evolutions +`A B : Evolution (qtower n qubit)` are equal once they agree on every computational tower basis +state `towerKet n b` (`b : Fin (n+1) → Fin 2`). This is the `qtower` analogue of +`Evolution.ext_qubitBasis` (the same fact on the symmetric register `qubit ^⊗ₛ (n+1)`): it upgrades +a computational-basis truth table on the grounded, right-nested control tower to an honest +`Evolution` identity — the step every wire-addressed re-expression of a Figure 5.1 gate (Problem +5.2) closes with. + +Proved by transporting `A` and `B` across the `qtower ↔ tensor-power` bridge +`qtowerQubitTensorPow n` via `Evolution.congr`: the bridge carries `towerKet n b` to the product +`⨂ᵢ |b i⟩` (`qtowerQubitTensorPow_congr_towerKet`) and intertwines the actions +(`Evolution.congr_evolvePure_congr`), so the transported gates agree on every `⨂ᵢ |b i⟩` and hence +are equal by `Evolution.ext_qubitBasis`; the transport roundtrip `Evolution.congr_symm_congr` pulls +that equality back to `A = B`. -/ +theorem Evolution.ext_towerKet {n : ℕ} {A B : Evolution (qtower n qubit)} + (h : ∀ b : Fin (n + 1) → Fin 2, + A.evolvePure (towerKet n b) = B.evolvePure (towerKet n b)) : + A = B := by + -- `Evolution.congr (qtowerQubitTensorPow n)` is injective (the transport roundtrip + -- `Evolution.congr_symm_congr` is a `LeftInverse`), so it suffices that the two transports onto + -- `qubit ^⊗ₛ (n+1)` agree — and they do on the product basis `⨂ᵢ |b i⟩` (the bridge image of + -- `towerKet n b`), hence everywhere by `ext_qubitBasis`. + refine Function.LeftInverse.injective (Evolution.congr_symm_congr (qtowerQubitTensorPow n)) ?_ + apply Evolution.ext_qubitBasis + intro b + rw [← qtowerQubitTensorPow_congr_towerKet n b, Evolution.congr_evolvePure_congr, + Evolution.congr_evolvePure_congr, h b] + +/-- **Re-expressing a transported register gate as a wire-addressed tower gate.** To prove that the +register gate `U : Evolution (qudit (2ⁿ⁺¹))` transported onto the tower, +`Evolution.congr (quditPowTower n) U`, equals a wire-addressed tower gate `V : Evolution +(qtower n qubit)`, it suffices to check on every computational tower basis state `towerKet n b`: + + `V.evolvePure (towerKet n b) + = quditPowTower n • (U.evolvePure |finFunctionFinEquiv (b ∘ Fin.rev)⟩)`. + +The right-hand side is exactly what the tower reader `quditPowTower_congr_evolvePure_towerKet` +computes for the *transported* gate `Evolution.congr (quditPowTower n) U` on +`towerKet n b` (the `Fin.rev` reconciling the big-endian register bridge with the little-endian +`finFunctionFinEquiv` wire-indexing of the Figure 5.1 matrix gates). So this combinator — +`Evolution.ext_towerKet` composed with the reader — is the single tool each Figure 5.1 gate's +wire-addressed re-expression (the Hadamard as `Evolution.qtowerSingleWire`, the +controlled-`Rₖ` on a wire pair) is discharged by: compute `V`'s basis action, compute `U`'s +register-ket action, and match. -/ +theorem quditPowTower_congr_eq_of_evolvePure_towerKet {n : ℕ} + (U : Evolution (qudit (2 ^ (n + 1)))) (V : Evolution (qtower n qubit)) + (h : ∀ b : Fin (n + 1) → Fin 2, + V.evolvePure (towerKet n b) + = PureState.congr (quditPowTower n) + (U.evolvePure (quditBasis (finFunctionFinEquiv (fun i => b i.rev))))) : + Evolution.congr (quditPowTower n) U = V := by + apply Evolution.ext_towerKet + intro b + rw [quditPowTower_congr_evolvePure_towerKet, h b] + +end AxQM diff --git a/LeanPool/AxQM/Core/FourGateNamedReversibleTower.lean b/LeanPool/AxQM/Core/FourGateNamedReversibleTower.lean new file mode 100644 index 0000000000..050b54976a --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateNamedReversibleTower.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.FourGateReversibleWireTower +public import LeanPool.AxQM.Core.PlacedMultiControlledX +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary + +/-! +# The reachable reversible gate cores, over the named gates `CNOT, Toffoli` +(N&C Exercise 4.43, named-gate re-expression of the reversible family) + +The universality argument of Exercise 4.43 shows the **operator density on the control tower** +(`exists_phase_smul_op_mem_closure_op_reachableTowerCircuitEvolutions`, +`AxQM/Postulates/API/FourGateReachableTowerDensity.lean`): up to a global phase every tower +evolution is a limit of the operators of the tower circuit submonoid +`reachableTowerCircuitEvolutions n θ` (`AxQM/Core/FourGateReachableCircuitTower.lean`). That +submonoid is generated by two families of gates: + +* the single-tower-wire reachable single-qubit rotations `Evolution.qtowerSingleWire n i E` + (`E ∈ reachableRotationGates θ`), and +* the `≤ 2`-control reversible tower gates `mcNotTowerGate n S t ht` (`|S| ≤ 2`). + +For the *named* four-gate universality conclusion, these gates must be re-expressed +over the four **named** gates `hadamardGate, sGate, cnotGate, toffoliGate`. +`AxQM/Core/FourGateNamedRotationTower.lean` does this for the **rotation** family (with +`hadamardGate`, `sGate`). **This file does it for the reversible +family**: it identifies the multiply-controlled `NOT` blocks `Cᵏ(X)` that the reversible +gates are built from — for the reachable range `k = |S| ≤ 2` — with the named gates +`NOT = pauliXGate`, `CNOT = cnotGate`, `Toffoli = toffoliGate`. + +## The core of a reversible gate is the named gate + +Each reversible gate `mcNotTowerGate n S t ht` (`AxQM/Core/FourGateReversibleWireTower.lean`) is +the `placedMcNot S t ht` gate transported onto the tower, and `placedMcNot` +(`AxQM/Core/McNotCircuitEvolution.lean`) places the arity-indexed block +`Evolution.placedMcCtrlX (S.card) …` — the `Cᵏ(X)` gate on `k = |S|` controls — onto the wires +`(S, t)`. That block is +`Evolution.placedMcCtrlX k b σ = (Evolution.tensorPowMcCtrlX k).onWires b σ` +(`AxQM/Core/PlacedMultiControlledX.lean`), and the symmetric-register `Cᵏ(X)` gate itself is +`Evolution.tensorPowMcCtrlX k = Evolution.congr (qtowerQubitTensorPow k) (mcCtrl k pauliXGate)` +(`AxQM/Core/TensorPowMultiControlledX.lean`). So the *core* of every reversible gate, before any +wire placement or register transport, is the multiply-controlled `NOT` `mcCtrl k pauliXGate`. For +the reachable range `k = |S| ≤ 2` this core **is** one of the three named reversible gates. + +## What is formalised + +* `mcCtrl_one_pauliXGate_eq_cnotGate`, `mcCtrl_two_pauliXGate_eq_toffoliGate` — **the root + identifications.** The multiply-controlled `NOT` core is the named `CNOT`/`Toffoli`: + + `mcCtrl 1 pauliXGate = cnotGate`, `mcCtrl 2 pauliXGate = toffoliGate`. + + (`k = 0` is `mcCtrl 0 pauliXGate = pauliXGate`, the base case `mcCtrl_zero`.) Immediate from the + `mcCtrl` recursion `mcCtrl (k+1) E = controlledUnitary (mcCtrl k E)` + (`mcCtrl_succ` / `mcCtrl_zero`) and the named-gate definitions + `cnotGate = controlledUnitary pauliXGate` (`cnotGate_def`) / + `toffoliGate = ccontrolledUnitary pauliXGate = controlledUnitary (controlledUnitary pauliXGate)`. + These are the reversible counterpart of the rotation half's + `reachableRotationGates_le_closure_named`, which does the same for `H`/`S`. +* `tensorPowMcCtrlX_zero_eq_congr_pauliXGate`, `tensorPowMcCtrlX_one_eq_congr_cnotGate`, + `tensorPowMcCtrlX_two_eq_congr_toffoliGate` — **the symmetric-register `Cᵏ(X)` block is the + named gate.** Transporting the root identification along the tower ↔ tensor-power bridge + `qtowerQubitTensorPow k`: + + `Evolution.tensorPowMcCtrlX k = Evolution.congr (qtowerQubitTensorPow k) ` + + for the three named gates at `k = 0, 1, 2`. This is the `Cᵏ(X)` block on the symmetric + `(k+1)`-fold power the wire placement `Evolution.onWires` consumes. +* `placedMcCtrlX_zero_eq_onWires_pauliXGate`, `placedMcCtrlX_one_eq_onWires_cnotGate`, + `placedMcCtrlX_two_eq_onWires_toffoliGate` — **the wire-placed `Cᵏ(X)` block is the named gate + placed on wires.** The exact form `placedMcNot` (hence every reversible gate + `mcNotTowerGate`) uses: + + `Evolution.placedMcCtrlX k b σ` + `= (Evolution.congr (qtowerQubitTensorPow k) ).onWires b σ` + + for `k = 0, 1, 2` — the wire-addressed `NOT`/`CNOT`/`Toffoli`. So every reversible gate of + `reachableTowerCircuitEvolutions n θ`, for `|S| ≤ 2`, has as its placed core exactly one of the + four named gates `pauliXGate` / `cnotGate` / `toffoliGate` (the `NOT = pauliXGate` being itself an + `{H, S}` circuit, `pauliXGate_eq_hadamardGate_sGateSq`, already inside the named rotation gate + set), placed on the wire set `(S, t)`. +-/ + +@[expose] public section + +namespace AxQM + +noncomputable section + +/-- **The single-control `NOT` core is the named `CNOT`.** The one-controlled multiply-controlled +`NOT` `mcCtrl 1 pauliXGate` (on `qtower 1 qubit = qubit ⊗ qubit`) is the named CNOT gate +`cnotGate`. Immediate from the `mcCtrl` recursion +`mcCtrl 1 E = controlledUnitary (mcCtrl 0 E) = controlledUnitary E` (`mcCtrl_succ` / `mcCtrl_zero`) +and `cnotGate = controlledUnitary pauliXGate` (`cnotGate_def`). -/ +theorem mcCtrl_one_pauliXGate_eq_cnotGate : mcCtrl 1 pauliXGate = cnotGate := by + rw [mcCtrl_succ, mcCtrl_zero]; rfl + +/-- **The two-control `NOT` core is the named `Toffoli`.** The two-controlled multiply-controlled +`NOT` `mcCtrl 2 pauliXGate` (on `qtower 2 qubit = qubit ⊗ (qubit ⊗ qubit)`) is the named Toffoli +gate `toffoliGate`. Immediate from iterating the `mcCtrl` recursion to +`controlledUnitary (controlledUnitary pauliXGate)` (`mcCtrl_succ` twice, `mcCtrl_zero`) and +`toffoliGate = ccontrolledUnitary pauliXGate = controlledUnitary (controlledUnitary pauliXGate)`. -/ +theorem mcCtrl_two_pauliXGate_eq_toffoliGate : mcCtrl 2 pauliXGate = toffoliGate := by + rw [mcCtrl_succ, mcCtrl_succ, mcCtrl_zero]; rfl + +/-- **The symmetric-register `C⁰(X)` block is the named `NOT`.** The zero-control block +`Evolution.tensorPowMcCtrlX 0` on `qubit ^⊗ₛ 1` is the named Pauli-`X` gate transported along +the tower ↔ tensor-power bridge: +`tensorPowMcCtrlX 0 = Evolution.congr (qtowerQubitTensorPow 0) pauliXGate`. +From `tensorPowMcCtrlX_def` and `mcCtrl_zero`. -/ +theorem tensorPowMcCtrlX_zero_eq_congr_pauliXGate : + Evolution.tensorPowMcCtrlX 0 = Evolution.congr (qtowerQubitTensorPow 0) pauliXGate := by + rw [Evolution.tensorPowMcCtrlX_def, mcCtrl_zero] + +/-- **The symmetric-register `C¹(X)` block is the named `CNOT`.** The one-control block +`Evolution.tensorPowMcCtrlX 1` on `qubit ^⊗ₛ 2` is the named CNOT gate transported along the +tower ↔ tensor-power bridge: +`tensorPowMcCtrlX 1 = Evolution.congr (qtowerQubitTensorPow 1) cnotGate`. +From `tensorPowMcCtrlX_def` and `mcCtrl_one_pauliXGate_eq_cnotGate`. -/ +theorem tensorPowMcCtrlX_one_eq_congr_cnotGate : + Evolution.tensorPowMcCtrlX 1 = Evolution.congr (qtowerQubitTensorPow 1) cnotGate := by + rw [Evolution.tensorPowMcCtrlX_def, mcCtrl_one_pauliXGate_eq_cnotGate] + +/-- **The symmetric-register `C²(X)` block is the named `Toffoli`.** The two-control block +`Evolution.tensorPowMcCtrlX 2` on `qubit ^⊗ₛ 3` is the named Toffoli gate transported along the +tower ↔ tensor-power bridge: +`tensorPowMcCtrlX 2 = Evolution.congr (qtowerQubitTensorPow 2) toffoliGate`. From +`tensorPowMcCtrlX_def` and `mcCtrl_two_pauliXGate_eq_toffoliGate`. -/ +theorem tensorPowMcCtrlX_two_eq_congr_toffoliGate : + Evolution.tensorPowMcCtrlX 2 = Evolution.congr (qtowerQubitTensorPow 2) toffoliGate := by + rw [Evolution.tensorPowMcCtrlX_def, mcCtrl_two_pauliXGate_eq_toffoliGate] + +/-- **The wire-placed `C⁰(X)` block is the named `NOT` placed on wires.** The exact form +`placedMcNot` uses for a `|S| = 0` gate: `Evolution.placedMcCtrlX 0 b σ` is the transported named +`NOT` gate placed on the `σ`-image wires, +`(Evolution.congr (qtowerQubitTensorPow 0) pauliXGate).onWires b σ`. From `placedMcCtrlX_def` and +`tensorPowMcCtrlX_zero_eq_congr_pauliXGate`. -/ +theorem placedMcCtrlX_zero_eq_onWires_pauliXGate (b : ℕ) (σ : Equiv.Perm (Fin (0 + 1 + b))) : + Evolution.placedMcCtrlX 0 b σ + = (Evolution.congr (qtowerQubitTensorPow 0) pauliXGate).onWires b σ := by + rw [Evolution.placedMcCtrlX_def, tensorPowMcCtrlX_zero_eq_congr_pauliXGate] + +/-- **The wire-placed `C¹(X)` block is the named `CNOT` placed on wires.** The exact form +`placedMcNot` uses for a `|S| = 1` gate: `Evolution.placedMcCtrlX 1 b σ` is the transported named +`CNOT` gate placed on the `σ`-image wires, +`(Evolution.congr (qtowerQubitTensorPow 1) cnotGate).onWires b σ`. From `placedMcCtrlX_def` and +`tensorPowMcCtrlX_one_eq_congr_cnotGate`. -/ +theorem placedMcCtrlX_one_eq_onWires_cnotGate (b : ℕ) (σ : Equiv.Perm (Fin (1 + 1 + b))) : + Evolution.placedMcCtrlX 1 b σ + = (Evolution.congr (qtowerQubitTensorPow 1) cnotGate).onWires b σ := by + rw [Evolution.placedMcCtrlX_def, tensorPowMcCtrlX_one_eq_congr_cnotGate] + +/-- **The wire-placed `C²(X)` block is the named `Toffoli` placed on wires.** The exact form +`placedMcNot` uses for a `|S| = 2` gate: `Evolution.placedMcCtrlX 2 b σ` is the transported named +`Toffoli` gate placed on the `σ`-image wires, +`(Evolution.congr (qtowerQubitTensorPow 2) toffoliGate).onWires b σ`. From `placedMcCtrlX_def` and +`tensorPowMcCtrlX_two_eq_congr_toffoliGate`. -/ +theorem placedMcCtrlX_two_eq_onWires_toffoliGate (b : ℕ) (σ : Equiv.Perm (Fin (2 + 1 + b))) : + Evolution.placedMcCtrlX 2 b σ + = (Evolution.congr (qtowerQubitTensorPow 2) toffoliGate).onWires b σ := by + rw [Evolution.placedMcCtrlX_def, tensorPowMcCtrlX_two_eq_congr_toffoliGate] + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/FourGateNamedRotationTower.lean b/LeanPool/AxQM/Core/FourGateNamedRotationTower.lean new file mode 100644 index 0000000000..e4d88ff4b8 --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateNamedRotationTower.lean @@ -0,0 +1,168 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableRotation +public import LeanPool.AxQM.Core.QtowerSingleWireGate + +/-! +# The reachable rotation tower gates, over the named gates `H, S` +(N&C Exercise 4.43, named-gate re-expression of the rotation family) + +The universality argument of Exercise 4.43 shows the **operator density on the +control tower**: +`exists_phase_smul_op_mem_closure_op_reachableTowerCircuitEvolutions` +(`AxQM/Postulates/API/FourGateReachableTowerDensity.lean`) shows that, up to a global phase, every +tower evolution is a limit of the operators of the tower circuit submonoid +`reachableTowerCircuitEvolutions n θ`. That submonoid has two generating families +(`AxQM/Core/FourGateReachableCircuitTower.lean`): + +* the single-tower-wire reachable single-qubit rotations `Evolution.qtowerSingleWire n i E` + (`E ∈ reachableRotationGates θ`), and +* the `≤ 2`-control reversible tower gates `mcNotTowerGate n S t ht`. + +For the *named* four-gate universality conclusion, these generating gates must be re-expressed +over the four **named** gates `hadamardGate, sGate, cnotGate, toffoliGate` (with the +measurement-realised `rzThreeFifthsCircuit` for the irrational `R_z(θ)`). **This file does it for +the rotation family**: it shows every reachable single-qubit rotation gate — and its placement on a +tower wire — is generated by the two named gates `hadamardGate`, `sGate` together with the single +non-Clifford base rotation `rotZGate θ` (the gate the Exercise 4.41 measurement circuit +`rzThreeFifthsCircuit` realises, on its success branch, `rzThreeFifthsCircuit_success_eq_rotZ`). + +## What is formalised + +* `reachableRotationGates_le_closure_named` — **the single-qubit re-expression.** The reachable + single-qubit rotation submonoid is contained in the submonoid generated by + `{hadamardGate, sGate, rotZGate θ}`: + + `reachableRotationGates θ ≤ Submonoid.closure {hadamardGate, sGate, rotZGate θ}`. + + Each of the four generators `R_z(±θ), R_x(±θ)` is a finite composition of `H`, `S`, and the base + rotation `R_z(θ)`: `R_z(θ)` is a generator; `R_z(-θ) = (H·S²·H)·R_z(θ)·(H·S²·H)` + (`rotZGate_neg_eq_hadamardGate_sGate_conj`, using the `{H, S}` circuit `X = H·S²·H`); + `R_x(θ) = H·R_z(θ)·H` (`hadamardGate_comp_rotZGate_comp_hadamardGate`); and + `R_x(-θ) = H·R_z(-θ)·H`. So the *only* non-`{H, S}` ingredient is the single base rotation + `R_z(θ)` — the measurement-realised gate, whose reachability (Exercise 4.41/4.42) is the essential + content of the exercise. +* `namedRotationTowerGates n θ` — **the named rotation tower submonoid.** The submonoid of + `Evolution (qtower n qubit)` generated by the single-tower-wire placements of the three gates + `hadamardGate, sGate, rotZGate θ` (over every wire `i`). The tower counterpart of + `Submonoid.closure {hadamardGate, sGate, rotZGate θ}`; a sub-submonoid of the full + named four-gate tower submonoid. +* `qtowerSingleWire_mem_namedRotationTowerGates` — **the tower re-expression.** Every reachable + rotation gate placed on a tower wire lies in the named rotation tower submonoid: for + `E ∈ reachableRotationGates θ` and any wire `i`, + + `Evolution.qtowerSingleWire n i E ∈ namedRotationTowerGates n θ`. + + Proved by `Submonoid.closure_induction` over the single-qubit re-expression: + `qtowerSingleWire n i` is a monoid homomorphism (`Evolution.qtowerSingleWire_id` / + `Evolution.qtowerSingleWire_comp`), so + it carries the closure `Submonoid.closure {hadamardGate, sGate, rotZGate θ}` into the closure of + the wire placements of `{hadamardGate, sGate, rotZGate θ}`. This is exactly the rotation half of + the containment `reachableTowerCircuitEvolutions n θ ≤ (named four-gate tower submonoid)` used in + the universality theorem. + +The rotation lifts are in `AxQM/Core/FourGateReachableWireSubmonoid.lean` and +`AxQM/Core/FourGateReachableCircuitTower.lean`; `reachableRotationGates` and the `{H, S}` +conjugation lemmas are in `AxQM/Postulates/API/FourGateReachableRotation.lean`. +-/ + +@[expose] public section + +namespace AxQM + +noncomputable section + +/-- **The reachable single-qubit rotations are `{H, S}` circuits around `R_z(θ)`.** The reachable +single-qubit rotation submonoid `reachableRotationGates θ` (generated by `R_z(±θ), R_x(±θ)`) is +contained in the submonoid generated by the named gates `hadamardGate`, `sGate` together with the +single base rotation `rotZGate θ`: + + `reachableRotationGates θ ≤ Submonoid.closure {hadamardGate, sGate, rotZGate θ}`. + +Each generator is a finite composition of `H`, `S`, `R_z(θ)`: `R_z(θ)` is itself a generator; +`R_z(-θ) = (H·S²·H)·R_z(θ)·(H·S²·H)` (`rotZGate_neg_eq_hadamardGate_sGate_conj`, with `NOT = H·S²·H` +the `{H, S}` realisation of the Pauli-`X`); `R_x(θ) = H·R_z(θ)·H` +(`hadamardGate_comp_rotZGate_comp_hadamardGate`); and `R_x(-θ) = H·R_z(-θ)·H`. Proved by +`Submonoid.closure_le`: it suffices that the four *generators* lie in the target submonoid; the unit +and products are then automatic. Only the single base rotation `R_z(θ)` — the measurement-realised +gate (Exercise 4.41) — is not itself an `{H, S}` word. -/ +theorem reachableRotationGates_le_closure_named (θ : ℝ) : + reachableRotationGates θ ≤ + Submonoid.closure ({hadamardGate, sGate, rotZGate θ} : Set (Evolution qubit)) := by + set G := Submonoid.closure ({hadamardGate, sGate, rotZGate θ} : Set (Evolution qubit)) + have hH : hadamardGate ∈ G := Submonoid.subset_closure (by simp) + have hS : sGate ∈ G := Submonoid.subset_closure (by simp) + have hZ : rotZGate θ ∈ G := Submonoid.subset_closure (by simp) + -- `NOT = H·S²·H ∈ G`; `Evolution.comp` is the monoid `*`, so `mul_mem` closes `.comp` goals. + have hX : hadamardGate.comp ((sGate.comp sGate).comp hadamardGate) ∈ G := + mul_mem hH (mul_mem (mul_mem hS hS) hH) + -- `R_z(-θ) = (H·S²·H)·R_z(θ)·(H·S²·H) ∈ G`. + have hZneg : rotZGate (-θ) ∈ G := by + rw [rotZGate_neg_eq_hadamardGate_sGate_conj] + simp only [← Evolution.mul_def] at hX ⊢ + exact mul_mem hX (mul_mem hZ hX) + -- `reachableRotationGates θ = Submonoid.closure {R_z(±θ), R_x(±θ)}`, so it suffices to place each + -- of the four generators in `G`; the unit and products of `Submonoid.closure_le` are automatic. + refine Submonoid.closure_le.2 ?_ + rintro x (rfl | rfl | rfl | rfl) + · exact hZ + · exact hZneg + · rw [← hadamardGate_comp_rotZGate_comp_hadamardGate] + exact mul_mem hH (mul_mem hZ hH) + · rw [← hadamardGate_comp_rotZGate_comp_hadamardGate] + exact mul_mem hH (mul_mem hZneg hH) + +/-- **The named rotation tower submonoid.** The submonoid of `Evolution (qtower n qubit)` generated +by the single-tower-wire placements `Evolution.qtowerSingleWire n i g` of the three named gates +`g ∈ {hadamardGate, sGate, rotZGate θ}`, over every wire `i`. The tower counterpart of +`Submonoid.closure {hadamardGate, sGate, rotZGate θ}`, and the rotation part of the eventual full +named four-gate tower submonoid; every reachable rotation gate on a tower wire lies in it +(`qtowerSingleWire_mem_namedRotationTowerGates`). -/ +noncomputable def namedRotationTowerGates (n : ℕ) (θ : ℝ) : + Submonoid (Evolution (qtower n qubit)) := + Submonoid.closure + (⋃ i : Fin (n + 1), + Evolution.qtowerSingleWire n i '' + ({hadamardGate, sGate, rotZGate θ} : Set (Evolution qubit))) + +/-- **Every reachable rotation gate on a tower wire is a named rotation tower gate.** For a +reachable single-qubit rotation gate `E ∈ reachableRotationGates θ` and any tower wire `i`, its +placement +`Evolution.qtowerSingleWire n i E` lies in the named rotation tower submonoid +`namedRotationTowerGates n θ`. + +The single-qubit re-expression `reachableRotationGates_le_closure_named` places `E` in +`Submonoid.closure {hadamardGate, sGate, rotZGate θ}`; then `Submonoid.closure_induction` transports +the word onto wire `i`, using that `Evolution.qtowerSingleWire n i` is a monoid homomorphism +(`Evolution.qtowerSingleWire_id` for the unit, `Evolution.qtowerSingleWire_comp` for products) that +carries each generator `g ∈ {hadamardGate, sGate, rotZGate θ}` to the generator +`Evolution.qtowerSingleWire n i g` of `namedRotationTowerGates n θ`. This is the rotation half of +the containment `reachableTowerCircuitEvolutions n θ ≤ (named four-gate tower submonoid)`. -/ +theorem qtowerSingleWire_mem_namedRotationTowerGates + {n : ℕ} {θ : ℝ} (i : Fin (n + 1)) {E : Evolution qubit} + (hE : E ∈ reachableRotationGates θ) : + Evolution.qtowerSingleWire n i E ∈ namedRotationTowerGates n θ := by + have hE' : E ∈ Submonoid.closure ({hadamardGate, sGate, rotZGate θ} : Set (Evolution qubit)) := + reachableRotationGates_le_closure_named θ hE + clear hE + induction hE' using Submonoid.closure_induction with + | mem x hx => + exact Submonoid.subset_closure (Set.mem_iUnion.2 ⟨i, Set.mem_image_of_mem _ hx⟩) + | one => + simpa only [Evolution.one_def, Evolution.qtowerSingleWire_id] using + one_mem (namedRotationTowerGates n θ) + | mul x y _ _ ihx ihy => + rw [Evolution.mul_def, Evolution.qtowerSingleWire_comp, ← Evolution.mul_def] + exact mul_mem ihx ihy + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/FourGateNamedTower.lean b/LeanPool/AxQM/Core/FourGateNamedTower.lean new file mode 100644 index 0000000000..175bf21078 --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateNamedTower.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.FourGateReachableCircuitTower +public import LeanPool.AxQM.Core.FourGateNamedRotationTower +public import LeanPool.AxQM.Core.FourGateNamedReversibleTower + +/-! +# The named four-gate tower submonoid, containing every reachable tower circuit +(N&C Exercise 4.43, named-gate assembly) + +The universality argument of Exercise 4.43 shows the **operator density on the control tower** +(`exists_phase_smul_op_mem_closure_op_reachableTowerCircuitEvolutions`, +`AxQM/Postulates/API/FourGateReachableTowerDensity.lean`): up to a global phase every tower +evolution is a limit of the operators of the tower circuit submonoid +`reachableTowerCircuitEvolutions n θ` (`AxQM/Core/FourGateReachableCircuitTower.lean`), whose two +generating families are + +* the single-tower-wire reachable single-qubit rotations `Evolution.qtowerSingleWire n i E` + (`E ∈ reachableRotationGates θ`), and +* the `≤ 2`-control reversible tower gates `mcNotTowerGate n S t ht` (`|S| ≤ 2`). + +The two per-family named re-expressions are `AxQM/Core/FourGateNamedRotationTower.lean`, which +shows the rotation generators lie in the submonoid generated by the single-wire placements of +`{hadamardGate, sGate, rotZGate θ}` (`qtowerSingleWire_mem_namedRotationTowerGates`), and +`AxQM/Core/FourGateNamedReversibleTower.lean`, which identifies the reversible gates' `Cᵏ(X)` cores +with the named gates `cnotGate` / `toffoliGate` for `|S| ≤ 2` +(`placedMcCtrlX_{one,two}_eq_onWires_{…}`). + +**This file assembles both halves into one submonoid generated by the four named gates and shows the +whole reachable tower submonoid lies inside it.** Density then transfers to the named submonoid by a +single `closure_mono` step (`AxQM/Postulates/API/FourGateNamedTowerDensity.lean`). + +## What is formalised + +* `namedMcNotGate k` — the **named `≤ 2`-control reversible gate**: `NOT = H·S²·H` (`k = 0`), + `cnotGate` (`k = 1`), `toffoliGate` (`k = 2`), and the raw `mcCtrl (k) pauliXGate` filler for the + unused `k ≥ 3`. The `k = 0` value is the `{H, S}` circuit `H·S²·H` (not a bare `pauliXGate`), so + the generating set below names *exactly* the four gates `H, S, CNOT, Toffoli` — no separate fifth + gate `X`. Keeping the arity `k` symbolic (rather than case-splitting `S.card` at the placed + gate, whose wire count and permutation depend on `S.card`) is what makes the membership proof go + through by a single core rewrite. +* `mcCtrl_pauliXGate_eq_namedMcNotGate` — **the core identification**: `mcCtrl k pauliXGate = + namedMcNotGate k` for `k ≤ 2`, from the reversible-core lemmas `mcCtrl_zero` + + `pauliXGate_eq_hadamardGate_sGateSq` (`k = 0`), `mcCtrl_one_pauliXGate_eq_cnotGate` (`k = 1`) and + `mcCtrl_two_pauliXGate_eq_toffoliGate` (`k = 2`). +* `namedFourGateTowerGates n θ` — **the named four-gate tower submonoid**: the submonoid of + `Evolution (qtower n qubit)` generated by + - the single-tower-wire placements `Evolution.qtowerSingleWire n i g` of the three named gates + `g ∈ {hadamardGate, sGate, rotZGate θ}` (over every wire `i`), and + - the named reversible gates `namedMcNotGate k` (`k ≤ 2`) placed on an arbitrary wire set and + transported onto the tower — the exact form `placedMcNot` produces, with its raw `Cᵏ(X)` core + replaced by the named gate. + + Its generators are only the four gates `hadamardGate, sGate, cnotGate, toffoliGate` (through + `namedMcNotGate`) together with the measurement-realised base rotation `rotZGate θ` (Exercise + 4.41, the gate the four *unitary* gates alone cannot supply). +* `namedRotationTowerGates_le_namedFourGateTowerGates` — the named rotation tower submonoid is a + sub-submonoid (its generators are the left half of the generating set; `Submonoid.closure_mono`). +* `mcNotTowerGate_mem_namedFourGateTowerGates` — **the reversible membership**: for `|S| ≤ 2` the + reversible tower gate `mcNotTowerGate n S t ht` lies in `namedFourGateTowerGates n θ`. + Unfolding `mcNotTowerGate` / `Evolution.placedMcNot` / `Evolution.placedMcCtrlX` / + `Evolution.tensorPowMcCtrlX` exposes the raw core `mcCtrl (S.card) pauliXGate`, which the core + identification `mcCtrl_pauliXGate_eq_namedMcNotGate` rewrites to `namedMcNotGate (S.card)` — + turning the gate into exactly a named reversible generator (the wire count and permutation are + read off by unification). +* `reachableTowerCircuitEvolutions_le_namedFourGateTowerGates` — **the containment**: the whole + grounded reachable tower submonoid is contained in the named four-gate tower submonoid, + + `reachableTowerCircuitEvolutions n θ ≤ namedFourGateTowerGates n θ`, + + by `Submonoid.closure_le`: the rotation generators land via + `qtowerSingleWire_mem_namedRotationTowerGates` + the sub-submonoid inclusion, the reversible + generators via `mcNotTowerGate_mem_namedFourGateTowerGates`. Every reachable tower circuit is + thus a circuit of the four *named* gates (with measurement) on tower wires, so density transfers. +-/ + +@[expose] public section + +namespace AxQM + +noncomputable section + +/-- **The named `≤ 2`-control reversible gate.** The multiply-controlled `NOT` with `k` controls, +for the reachable range `k ≤ 2`, as one of the named gates: `NOT = H·S²·H` (`k = 0`), the named CNOT +`cnotGate` (`k = 1`), the named Toffoli `toffoliGate` (`k = 2`); for the unused `k ≥ 3` it is the +raw `mcCtrl k pauliXGate` (a filler, never referenced by the reachable generators). The `k = 0` +value is the `{H, S}` circuit `H·S²·H` (`= pauliXGate` by `pauliXGate_eq_hadamardGate_sGateSq`), so +`namedFourGateTowerGates` is generated by *exactly* the four gates `H, S, CNOT, Toffoli` — the `NOT` +is not a separate fifth gate but the `{H, S}` realisation. Its type +`Evolution (qtower k qubit)` matches the core of `Evolution.tensorPowMcCtrlX k` +(`mcCtrl k pauliXGate`), via +`mcCtrl_pauliXGate_eq_namedMcNotGate`. -/ +def namedMcNotGate : (k : ℕ) → Evolution (qtower k qubit) + | 0 => hadamardGate.comp ((sGate.comp sGate).comp hadamardGate) + | 1 => cnotGate + | 2 => toffoliGate + | (k + 3) => mcCtrl (k + 3) pauliXGate + +/-- **The multiply-controlled `NOT` core is the named reversible gate.** For the reachable range +`k ≤ 2`, the `Cᵏ(X)` core `mcCtrl k pauliXGate` is the named gate `namedMcNotGate k`: + + `mcCtrl k pauliXGate = namedMcNotGate k`. + +The three cases are the reversible-core identifications: `k = 0` is +`mcCtrl 0 pauliXGate = pauliXGate = H·S²·H` (`mcCtrl_zero` + `pauliXGate_eq_hadamardGate_sGateSq`); +`k = 1` is +`mcCtrl_one_pauliXGate_eq_cnotGate`; `k = 2` is `mcCtrl_two_pauliXGate_eq_toffoliGate`. This is the +one rewrite the reversible membership performs, so keeping `k` symbolic here (rather than at the +placed gate) confines the case split to this non-dependent core equality. -/ +theorem mcCtrl_pauliXGate_eq_namedMcNotGate (k : ℕ) (hk : k ≤ 2) : + mcCtrl k pauliXGate = namedMcNotGate k := by + interval_cases k + · rw [mcCtrl_zero]; exact pauliXGate_eq_hadamardGate_sGateSq + · exact mcCtrl_one_pauliXGate_eq_cnotGate + · exact mcCtrl_two_pauliXGate_eq_toffoliGate + +/-- **The named `≤ 2`-control reversible tower generators.** The right-hand generator family of both +`namedFourGateTowerGates` and its measurement-realised refinement `fourGateMeasurementReachable` +(`Postulates/API/FourGateMeasurementUniversal`): the named reversible gates `namedMcNotGate k` +(`k ≤ 2` — a `NOT`/`CNOT`/`Toffoli`) placed on an arbitrary wire set by `Evolution.onWires` and +transported onto the tower — the exact form `Evolution.placedMcNot` produces (`Evolution.congr +(qtowerQubitTensorPow n).symm` of a `QSystem.tensorPowCongr`-cast `onWires` gate), with its raw +`mcCtrl k pauliXGate` core replaced by the named gate. It is a shared definition so the two +submonoids differ *only* in their rotation-generator half. -/ +def namedReversibleTowerGenerators (n : ℕ) : Set (Evolution (qtower n qubit)) := + {E | ∃ (k b : ℕ) (_ : k ≤ 2) (σ : Equiv.Perm (Fin (k + 1 + b))) (h : k + 1 + b = n + 1), + E = Evolution.congr (qtowerQubitTensorPow n).symm + (((Evolution.congr (qtowerQubitTensorPow k) (namedMcNotGate k)).onWires b σ).congr + (QSystem.tensorPowCongr qubit (finCongr h)))} + +/-- **The named four-gate tower submonoid.** The submonoid of `Evolution (qtower n qubit)` generated +by the two named generator families: + +* the single-tower-wire placements `Evolution.qtowerSingleWire n i g` of the three named gates + `g ∈ {hadamardGate, sGate, rotZGate θ}`, over every wire `i` (the rotation half), and +* the named reversible gates `namedMcNotGate k` (`k ≤ 2` — a `NOT`/`CNOT`/`Toffoli`) placed on an + arbitrary wire set by `Evolution.onWires` and transported onto the tower — the exact form + `Evolution.placedMcNot` produces (`Evolution.congr (qtowerQubitTensorPow n).symm` of a + `QSystem.tensorPowCongr`-cast `onWires` gate), with its raw `mcCtrl k pauliXGate` core replaced by + the named gate. + +Every generator is one of the four gates `hadamardGate, sGate, cnotGate, toffoliGate` (through +`namedMcNotGate`) or the base rotation `rotZGate θ` (realised separately by the Exercise 4.41 +measurement circuit). It contains the whole reachable tower submonoid +(`reachableTowerCircuitEvolutions_le_namedFourGateTowerGates`). -/ +noncomputable def namedFourGateTowerGates (n : ℕ) (θ : ℝ) : + Submonoid (Evolution (qtower n qubit)) := + Submonoid.closure + ((⋃ i : Fin (n + 1), + Evolution.qtowerSingleWire n i '' + ({hadamardGate, sGate, rotZGate θ} : Set (Evolution qubit))) ∪ + namedReversibleTowerGenerators n) + +/-- **The named rotation tower submonoid sits inside the named four-gate tower submonoid.** The +generators of `namedRotationTowerGates n θ` (the single-wire placements of `hadamardGate, sGate, +rotZGate θ`) are the left half of the generating set of `namedFourGateTowerGates n θ`, so +`Submonoid.closure_mono` gives `namedRotationTowerGates n θ ≤ namedFourGateTowerGates n θ`. -/ +theorem namedRotationTowerGates_le_namedFourGateTowerGates (n : ℕ) (θ : ℝ) : + namedRotationTowerGates n θ ≤ namedFourGateTowerGates n θ := + Submonoid.closure_mono Set.subset_union_left + +/-- **The grounded reversible tower gate is a named four-gate tower gate.** For `|S| ≤ 2` the +grounded reversible tower gate `mcNotTowerGate n S t ht` lies in `namedFourGateTowerGates n θ`. + +`mcNotTowerGate n S t ht` unfolds to `Evolution.congr (qtowerQubitTensorPow n).symm` of the +register-cast placed block `Evolution.placedMcCtrlX (S.card) b σ`, and `placedMcCtrlX` / +`tensorPowMcCtrlX` expose its raw core `mcCtrl (S.card) pauliXGate`; the core identification +`mcCtrl_pauliXGate_eq_namedMcNotGate (S.card) hcard` rewrites it to `namedMcNotGate (S.card)`. The +result is exactly a named reversible generator (`k := S.card`; the wire count `b` and permutation +`σ` of `placedMcNot`, and the register-cast proof `card_succ_add_sub`, are read off by unification), +so +`Submonoid.subset_closure` closes the membership. -/ +theorem mcNotTowerGate_mem_namedFourGateTowerGates {n : ℕ} {θ : ℝ} (S : Finset (Fin (n + 1))) + (t : Fin (n + 1)) (ht : t ∉ S) (hcard : S.card ≤ 2) : + mcNotTowerGate n S t ht ∈ namedFourGateTowerGates n θ := by + apply Submonoid.subset_closure + apply Or.inr + rw [mcNotTowerGate, Evolution.placedMcNot, Evolution.placedMcCtrlX_def, + Evolution.tensorPowMcCtrlX_def, mcCtrl_pauliXGate_eq_namedMcNotGate S.card hcard] + exact ⟨S.card, _, hcard, _, _, rfl⟩ + +/-- **Every grounded reachable tower circuit is a named four-gate tower circuit.** The whole +grounded reachable tower circuit submonoid is contained in the named four-gate tower submonoid: + + `reachableTowerCircuitEvolutions n θ ≤ namedFourGateTowerGates n θ`. + +By `Submonoid.closure_le` it suffices to place each of the two generator families of +`reachableTowerCircuitEvolutions n θ` inside `namedFourGateTowerGates n θ`: a single-tower-wire +reachable rotation gate `Evolution.qtowerSingleWire n i E` (`E ∈ reachableRotationGates θ`) via +`qtowerSingleWire_mem_namedRotationTowerGates` and the sub-submonoid inclusion +`namedRotationTowerGates_le_namedFourGateTowerGates`; a `≤ 2`-control grounded reversible gate +`mcNotTowerGate n S t ht` via `mcNotTowerGate_mem_namedFourGateTowerGates`. + +This step re-expresses every generator of the grounded tower +submonoid over the four *named* gates `hadamardGate, sGate, cnotGate, toffoliGate` (with the +measurement-realised `rotZGate θ`), so the tower operator density +(`exists_phase_smul_op_mem_closure_op_reachableTowerCircuitEvolutions`) transfers to the named +submonoid by `closure_mono`. -/ +theorem reachableTowerCircuitEvolutions_le_namedFourGateTowerGates (n : ℕ) (θ : ℝ) : + reachableTowerCircuitEvolutions n θ ≤ namedFourGateTowerGates n θ := by + rw [reachableTowerCircuitEvolutions] + refine Submonoid.closure_le.2 ?_ + rintro x (hrot | hrev) + · rw [Set.mem_iUnion] at hrot + obtain ⟨i, E, hE, rfl⟩ := hrot + exact namedRotationTowerGates_le_namedFourGateTowerGates n θ + (qtowerSingleWire_mem_namedRotationTowerGates i hE) + · obtain ⟨S, t, ht, hcard, rfl⟩ := hrev + exact mcNotTowerGate_mem_namedFourGateTowerGates S t ht hcard + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/FourGateReachableCircuitTower.lean b/LeanPool/AxQM/Core/FourGateReachableCircuitTower.lean new file mode 100644 index 0000000000..fd8527d485 --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateReachableCircuitTower.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableCircuit +public import LeanPool.AxQM.Core.FourGateReachableWireSubmonoid +public import LeanPool.AxQM.Core.FourGateReversibleWireTower + +/-! +# The whole register reachable circuit submonoid, as four-gate circuits on the tower +(N&C Exercise 4.43, whole-submonoid register lift onto the control tower) + +The universality argument of Exercise 4.43 exhibits the *abstract* reachable circuit set +of `Concrete.exists_phase_smul_mem_closure_reachableCircuits` — dense in `U(2ⁿ⁺¹)` up to a global +phase — as circuits of the `H, S, CNOT, Toffoli` gates. Its register-side counterpart, +the submonoid `reachableCircuitEvolutions n θ` of `Evolution (qudit 2ⁿ⁺¹)` +(`AxQM/Postulates/API/FourGateReachableCircuit.lean`), is identified operator-by-operator with the +matrix reachable circuit set (`exists_reachableCircuitEvolution_op_eq`). This file **lifts that +whole +register submonoid onto the control tower `qtower n qubit`**, re-expressing each of its members as a +circuit whose generators are gates on individual tower wires. + +The two generating families of `reachableCircuitEvolutions n θ` each have a tower +re-expression: + +* the per-wire reachable single-qubit rotations `reachableRotationWireEvolutions n j θ`, by the + whole-submonoid rotation lift `exists_reachableRotationGate_congr_quditPowTower_eq` + (`AxQM/Core/FourGateReachableWireSubmonoid.lean`): transported by `quditPowTower n`, each member + is `Evolution.qtowerSingleWire n j.rev E` for a reachable rotation gate + `E ∈ reachableRotationGates θ` (an `{H, S}`-conjugate of the measurement-realised `R_z(θ)`, + Exercise 4.41); +* the `≤ 2`-control reversible gates `mcNotWireEvolution (n+1) S t ht`, by the reversible register + lift `quditPowTower_congr_mcNotWireEvolution` (`AxQM/Core/FourGateReversibleWireTower.lean`): + transported by `quditPowTower n`, each is the `mcNotTowerGate n (S.map rev) t.rev _` — the + `placedMcNot` (a `Toffoli`/`CNOT`/`NOT` for `|S| ≤ 2`) on the reversed tower wire set. + +This file assembles the two into one tower submonoid and transports the *whole* register +submonoid into it, one member at a time. + +## What is formalised + +* `reachableTowerCircuitEvolutions n θ` — the **tower circuit submonoid**: the submonoid of + `Evolution (qtower n qubit)` generated by the single-tower-wire reachable rotation gates + `Evolution.qtowerSingleWire n i E` (`E ∈ reachableRotationGates θ`, over every wire `i`) together + with the `≤ 2`-control reversible tower gates `mcNotTowerGate n S t ht` (`|S| ≤ 2`, + `t ∉ S`). Every generator is a genuine circuit of the `H, S, CNOT, Toffoli` gates on + a tower wire (rotations: `{H, S}`-conjugates of the Exercise 4.41 measurement circuit + `rzThreeFifthsCircuit`; reversible: `placedMcNot` = `Toffoli`/`CNOT`/`NOT`) — the tower + counterpart of the register submonoid `reachableCircuitEvolutions n θ`. +* `congr_quditPowTower_mem_reachableTowerCircuitEvolutions` — **the whole-submonoid tower lift**: + every member `E` of the register submonoid `reachableCircuitEvolutions n θ`, transported onto the + control tower via the register bridge `quditPowTower n`, lies in the tower submonoid: + + `Evolution.congr (quditPowTower n) E ∈ reachableTowerCircuitEvolutions n θ`. + + Proved by `Submonoid.closure_induction`. On a generator: a per-wire rotation member (wire `j`) + maps by the rotation lift `exists_reachableRotationGate_congr_quditPowTower_eq` to + `Evolution.qtowerSingleWire n j.rev E` (`E ∈ reachableRotationGates θ`), a generator of the tower + submonoid; a reversible generator `mcNotWireEvolution (n+1) S t ht` (`|S| ≤ 2`) maps by + `quditPowTower_congr_mcNotWireEvolution` to `mcNotTowerGate n (S.map rev) t.rev _`, whose reversed + control set still has `card ≤ 2` (`Finset.card_map`) and excludes the reversed target + (`Finset.mem_map_equiv`) — a generator too. The `1` / product cases are the monoid-homomorphism + laws of `Evolution.congr` (`Evolution.congr_id` / `Evolution.congr_comp`) feeding `one_mem` / + `mul_mem`. The whole-circuit analogue of the single-family rotation lift + `exists_reachableRotationGate_congr_quditPowTower_eq`. + +So every reachable register circuit is, on the tower, a circuit built entirely from the +four named gates `H, S, CNOT, Toffoli` on individual tower wires. This is the register-lift step in +the universality theorem: the matrix density transported through `Matrix.toEuclideanCLM` +lands in the closure of the operator image of `reachableCircuitEvolutions n θ` +(`exists_reachableCircuitEvolution_op_eq`), which this lift re-expresses over the four-gate +tower gates. + +The two half-lifts it assembles are `AxQM/Core/FourGateReachableWireSubmonoid.lean` (rotations) and +`AxQM/Core/FourGateReversibleWireTower.lean` (reversible). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The tower circuit submonoid.** The submonoid of `Evolution (qtower n qubit)` +generated by the two tower generating families: the single-tower-wire reachable single-qubit +rotation gates `Evolution.qtowerSingleWire n i E` (`E ∈ reachableRotationGates θ`, over every wire +`i`) and the `≤ 2`-control reversible tower gates `mcNotTowerGate n S t ht` (`|S| ≤ 2`, +`t ∉ S`). Each generator is a genuine circuit of the `H, S, CNOT, Toffoli` gates on a +tower wire — the tower counterpart of the register submonoid +`reachableCircuitEvolutions n θ` (`congr_quditPowTower_mem_reachableTowerCircuitEvolutions`). -/ +noncomputable def reachableTowerCircuitEvolutions (n : ℕ) (θ : ℝ) : + Submonoid (Evolution (qtower n qubit)) := + Submonoid.closure + ((⋃ i : Fin (n + 1), + (Evolution.qtowerSingleWire n i '' (reachableRotationGates θ : Set (Evolution qubit)))) ∪ + {E | ∃ (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) (ht : t ∉ S), + S.card ≤ 2 ∧ E = mcNotTowerGate n S t ht}) + +/-- **The whole register reachable circuit submonoid lifts to tower circuits.** Every +member `E` of the register-level reachable circuit submonoid `reachableCircuitEvolutions n θ`, +transported onto the control tower via the register bridge `quditPowTower n`, lies in the +tower circuit submonoid: + + `Evolution.congr (quditPowTower n) E ∈ reachableTowerCircuitEvolutions n θ`. + +Proved by `Submonoid.closure_induction` over `reachableCircuitEvolutions n θ`. On a generator: a +per-wire reachable-rotation member (wire `j`) is carried by the rotation whole-submonoid lift +`exists_reachableRotationGate_congr_quditPowTower_eq` to `Evolution.qtowerSingleWire n j.rev E` for +a reachable rotation gate `E ∈ reachableRotationGates θ` — a generator of the tower submonoid (at +wire `i = j.rev`); a `≤ 2`-control reversible generator `mcNotWireEvolution (n+1) S t ht` is carried +by the reversible register lift `quditPowTower_congr_mcNotWireEvolution` to the +`mcNotTowerGate n (S.map Fin.revPerm.toEmbedding) t.rev _`, whose reversed control set again has +`card ≤ 2` (`Finset.card_map`) and excludes the reversed target (`Finset.mem_map_equiv`) — also a +generator. The `1` and product cases are the monoid-homomorphism laws of `Evolution.congr` +(`Evolution.congr_id` / `Evolution.congr_comp`, via `Evolution.one_def` / `Evolution.mul_def`), +landing in the tower submonoid by `one_mem` / `mul_mem`. + +So every reachable register circuit is realised, on the tower, as a circuit built entirely +from `H, S, CNOT, Toffoli` on individual tower wires — the register-lift step in the density +transport and the universality theorem. -/ +theorem congr_quditPowTower_mem_reachableTowerCircuitEvolutions {n : ℕ} {θ : ℝ} + {E : Evolution (qudit (2 ^ (n + 1)))} (hE : E ∈ reachableCircuitEvolutions n θ) : + Evolution.congr (quditPowTower n) E ∈ reachableTowerCircuitEvolutions n θ := by + induction hE using Submonoid.closure_induction with + | mem x hx => + rcases hx with hrot | hperm + · -- reachable single-qubit rotation on register wire `j`. + rw [Set.mem_iUnion] at hrot + obtain ⟨j, hj⟩ := hrot + have hj' : x ∈ reachableRotationWireEvolutions n j θ := hj + obtain ⟨G, hG, hGeq⟩ := exists_reachableRotationGate_congr_quditPowTower_eq hj' + rw [hGeq] + exact Submonoid.subset_closure + (Or.inl (Set.mem_iUnion.2 ⟨j.rev, Set.mem_image_of_mem _ hG⟩)) + · -- `≤ 2`-control reversible register gate `mcNotWireEvolution (n+1) S t ht`. + obtain ⟨S, t, ht, hcard, rfl⟩ := hperm + rw [quditPowTower_congr_mcNotWireEvolution] + refine Submonoid.subset_closure (Or.inr ⟨S.map Fin.revPerm.toEmbedding, t.rev, ?_, ?_, rfl⟩) + · rw [Finset.mem_map_equiv]; simpa using ht + · rw [Finset.card_map]; exact hcard + | one => + simpa only [Evolution.one_def, Evolution.congr_id] using + one_mem (reachableTowerCircuitEvolutions n θ) + | mul x y _ _ ihx ihy => + rw [Evolution.mul_def x y, Evolution.congr_comp, ← Evolution.mul_def] + exact mul_mem ihx ihy + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/FourGateReachableWireSubmonoid.lean b/LeanPool/AxQM/Core/FourGateReachableWireSubmonoid.lean new file mode 100644 index 0000000000..e4bc215940 --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateReachableWireSubmonoid.lean @@ -0,0 +1,119 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.FourGateReachableWireTower +public import LeanPool.AxQM.Postulates.API.FourGateReachableRotation +public import LeanPool.AxQM.Postulates.API.FourGateReachableWireMonoid + +/-! +# The whole reachable single-qubit rotation submonoid on a register wire, as tower gates +(N&C Exercise 4.43, whole-submonoid stage) + +The universality argument of Exercise 4.43 exhibits the *abstract* reachable gate set of +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` as circuits of the +`H, S, CNOT, Toffoli` gates. Its rotation half uses the single-qubit reachable rotations placed +on a wire — the matrices `Concrete.singleQubitOnWire enc j g` for **every** `g` in the submonoid +`Concrete.reachableRotations θ`, not only its four generators. The register lift in +`AxQM/Core/FourGateReachableWireTower.lean` handles the four *generators* +`R_z(±θ), R_x(±θ)` on a wire (`quditPowTower_congr_rotZWireEvolution` / +`quditPowTower_congr_rotXWireEvolution`); this file closes the submonoid, transferring the lift from +the generators to *every* product of them. + +The single-wire-placement monoid-homomorphism facts this lift turns on — +`Evolution.qtowerSingleWire_id` / `Evolution.qtowerSingleWire_comp` (`qtowerSingleWire n i` sends +the identity gate to the identity and a composition `g · h` to +`(qtowerSingleWire n i g) · (qtowerSingleWire n i h)`) — are in +`AxQM/Core/QtowerSingleWireGate.lean`. + +## What is formalised + +The register-level reachable-rotation wire submonoid `reachableRotationWireEvolutions n t θ` — the +submonoid of `Evolution (qudit (2ⁿ⁺¹))` generated by the four wire gates +`rotZWireEvolution (n+1) t (±θ)`, `rotXWireEvolution (n+1) t (±θ)`, the register-gate counterpart of +`Concrete.reachableRotations θ` placed on wire `t` — is defined in +`AxQM/Postulates/API/FourGateReachableWireMonoid.lean`, together with the matrix→submonoid bridge +`quditGate_singleQubitOnWire_mem_reachableRotationWireEvolutions`. + +* `exists_reachableRotationGate_congr_quditPowTower_eq` — **the whole-submonoid lift**: every member + of `reachableRotationWireEvolutions n t θ`, transported onto the control tower via the register + bridge `quditPowTower n`, is the gate `qtowerSingleWire n t.rev E` for some + `E ∈ reachableRotationGates θ` — a reachable single-qubit rotation gate (built, with measurement, + from `H, S, CNOT, Toffoli`) placed on the single tower wire `t.rev`. Proved by + `Submonoid.closure_induction`: on the four generators it is the register lift together with the + membership of the corresponding `rotZGate (±θ)` / `rotXGate (±θ)` in `reachableRotationGates θ`; + on `1` and on products it is the two monoid-homomorphism facts on each side — + `Evolution.congr` (`Evolution.congr_id` / `Evolution.congr_comp`) and `qtowerSingleWire` + (`Evolution.qtowerSingleWire_id` / `Evolution.qtowerSingleWire_comp`) transporting the closure of + `reachableRotationGates θ` under `mul_mem` / `one_mem`. + +So the *whole* single-qubit reachable-rotation submonoid on a register wire — the exact shape +`⋃ j, singleQubitOnWire enc j '' reachableRotations θ` in which the reachable rotations enter the +abstract `reachableGateSet` — is realised, on the tower, by the reachable rotation gates. +`AxQM/Postulates/API/FourGateReachableWireMonoid.lean` identifies the register wire matrix gate +`quditGate (singleQubitOnWire finFunctionFinEquiv t g)` with a member of +`reachableRotationWireEvolutions n t θ`, which this lift then applies to. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### The register reachable-rotation wire submonoid and its lift -/ + +/-- **The whole reachable-rotation wire submonoid lifts to tower gates.** Every member `F` +of the register submonoid `reachableRotationWireEvolutions n t θ`, transported onto the control +tower via the register bridge `quditPowTower n`, is the gate `qtowerSingleWire n t.rev E` +applying a reachable single-qubit rotation gate `E ∈ reachableRotationGates θ` to the tower wire +`t.rev`: + + `Evolution.congr (quditPowTower n) F = Evolution.qtowerSingleWire n t.rev E`. + +Extends the generator-level register lift (`quditPowTower_congr_rotZWireEvolution` / +`quditPowTower_congr_rotXWireEvolution`) from the four generators to the whole submonoid: by +`Submonoid.closure_induction`, the generators give the register lift with the corresponding +`rotZGate (±θ)` / `rotXGate (±θ)` a generator of `reachableRotationGates θ`, and the `1` / product +cases are the monoid-homomorphism laws of `Evolution.congr` (`Evolution.congr_id` / +`Evolution.congr_comp`) and `qtowerSingleWire` (`Evolution.qtowerSingleWire_id` / +`Evolution.qtowerSingleWire_comp`), landing in `reachableRotationGates θ` by `one_mem` / `mul_mem`. +Since a reachable rotation gate is a `{H, S}`-composition around the measurement-realised `R_z(θ)` +(the Exercise 4.41 circuit `rzThreeFifthsCircuit`), every reachable single-qubit rotation on a +register wire is thereby a genuine circuit on a tower wire. -/ +theorem exists_reachableRotationGate_congr_quditPowTower_eq {n : ℕ} {t : Fin (n + 1)} {θ : ℝ} + {F : Evolution (qudit (2 ^ (n + 1)))} (hF : F ∈ reachableRotationWireEvolutions n t θ) : + ∃ E ∈ reachableRotationGates θ, + Evolution.congr (quditPowTower n) F = Evolution.qtowerSingleWire n t.rev E := by + induction hF using Submonoid.closure_induction with + | mem x hx => + rcases hx with rfl | rfl | rfl | rfl + · exact ⟨rotZGate θ, Submonoid.subset_closure (by simp), + quditPowTower_congr_rotZWireEvolution n t θ⟩ + · exact ⟨rotZGate (-θ), Submonoid.subset_closure (by simp), + quditPowTower_congr_rotZWireEvolution n t (-θ)⟩ + · exact ⟨rotXGate θ, Submonoid.subset_closure (by simp), + quditPowTower_congr_rotXWireEvolution n t θ⟩ + · exact ⟨rotXGate (-θ), Submonoid.subset_closure (by simp), + quditPowTower_congr_rotXWireEvolution n t (-θ)⟩ + | one => + exact ⟨1, one_mem _, by + simp only [Evolution.one_def, Evolution.congr_id, Evolution.qtowerSingleWire_id]⟩ + | mul x y _ _ ihx ihy => + obtain ⟨Ex, hEx, hxeq⟩ := ihx + obtain ⟨Ey, hEy, hyeq⟩ := ihy + refine ⟨Ex * Ey, mul_mem hEx hEy, ?_⟩ + rw [Evolution.mul_def x y, Evolution.congr_comp, hxeq, hyeq, Evolution.mul_def Ex Ey, + Evolution.qtowerSingleWire_comp] + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/FourGateReachableWireTower.lean b/LeanPool/AxQM/Core/FourGateReachableWireTower.lean new file mode 100644 index 0000000000..9016508632 --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateReachableWireTower.lean @@ -0,0 +1,133 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableWire +public import LeanPool.AxQM.Core.QftTowerHadamard + +/-! +# The reachable single-qubit rotations as rotation gates on a tower wire (N&C Exercise +4.43, register lift) + +The universality argument of Exercise 4.43 transfers the abstract density result +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` onto the `H, S, CNOT, Toffoli` +gate set. One generating family of the reachable gate set is the reachable single-qubit rotations +placed on a wire, `Concrete.singleQubitOnWire finFunctionFinEquiv t g` for +`g ∈ Concrete.reachableRotations θ`. This file re-expresses such a **wire gate on the qudit +register** as the rotation **gate on the corresponding tower wire**, relating the matrix-level +generators to the `Evolution` gates, exactly as `AxQM/Core/QftTowerHadamard.lean` does for the +Figure 5.1 Hadamard. + +## What is formalised + +* `quditPowTower_congr_rotZWireEvolution` / `quditPowTower_congr_rotXWireEvolution` — **the register + lift for the reachable rotation generators**: the wire-`t` reachable rotation gate on the register + is, on the tower, the gate `rotZGate θ` (resp. `rotXGate θ`) on the single tower wire + `t.rev`: + + `Evolution.congr (quditPowTower n) (rotZWireEvolution (n+1) t θ)` + `= Evolution.qtowerSingleWire n t.rev (rotZGate θ)`. + + The four generators of `Concrete.reachableRotations θ` are `R_z(±θ), R_x(±θ)`, so these two + families (at `θ` and `-θ`) cover them all: every generator of the reachable single-qubit + rotations, placed on a register wire, is a rotation gate on a tower wire — a genuine + one-qubit gate on one wire, built (with measurement) from `H, S, CNOT, Toffoli`. + +## Proof + +Both are the exact analogue of `quditPowTower_congr_qftHadamardEvolution` (the Figure 5.1 +Hadamard on a tower wire) with the Hadamard block replaced by the reachable rotation. Via the +transported-gate re-expression combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: on every +basis input +`towerKet n b`, both sides produce the two-term superposition +`∑_z (rotZ θ) z (b t.rev) · towerKet n (update b t.rev z)`, the single-wire side via +`qtowerSingleWire_evolvePure_towerKet` and the tensor multilinearity of the tower product state (the +shared `towerProd_vec_update_sum_smul`), the register side via +`rotZWireEvolution_evolvePure_quditBasis`, the bridge isometry, and +`quditPowTower_congr_quditBasis_apply` (the two `Fin.rev`s collapsing by `Fin.rev_rev`). The +register basis action (`rotZWireEvolution_evolvePure_quditBasis`) and the single-qubit column +(`rotZGate_evolvePure_qubitBasis_sum`) are the two matching two-term superpositions, both the column +`((rotZ θ) · , b t.rev)`. The tensor-multilinearity step is the lemma +`towerProd_vec_update_sum_smul` (`AxQM/Postulates/API/TowerProdMultilinear.lean`); the two purely +ket-combinatorial steps are the lemmas `towerProd_update_qubitBasis` / `update_rev_eq` +(`AxQM/Core/QtowerSingleWireGate.lean`). The wire gates and their basis actions are in +`AxQM/Postulates/API/FourGateReachableWire.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The transported reachable wire `z`-rotation is the grounded `z`-rotation on tower wire +`t.rev`.** Transporting the register gate `rotZWireEvolution (n+1) t θ` (the reachable `R_z(θ)` on +register wire `t`) onto the `(n+1)`-qubit control tower via the register bridge `quditPowTower n` +yields exactly the single-wire gate applying the grounded gate `rotZGate θ` to tower wire `t.rev`: + + `Evolution.congr (quditPowTower n) (rotZWireEvolution (n+1) t θ)` + `= Evolution.qtowerSingleWire n t.rev (rotZGate θ)`. + +The register wire gate — a genuine one-qubit gate — is, on the grounded tower, precisely the +reachable `z`-rotation gate on the single wire `t.rev` (the `Fin.rev` reconciling the big-endian +register bridge with the little-endian wire-indexing). The exact analogue of +`quditPowTower_congr_qftHadamardEvolution`, with the Hadamard block replaced by `R_z(θ)`: on each +basis input both sides give `∑_z (rotZ θ) z (b t.rev) · towerKet n (update b t.rev z)` (register +side `rotZWireEvolution_evolvePure_quditBasis`, single-wire side +`rotZGate_evolvePure_qubitBasis_sum`). -/ +theorem quditPowTower_congr_rotZWireEvolution (n : ℕ) (t : Fin (n + 1)) (θ : ℝ) : + Evolution.congr (quditPowTower n) (rotZWireEvolution (n + 1) t θ) + = Evolution.qtowerSingleWire n t.rev (rotZGate θ) := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + rw [qtowerSingleWire_evolvePure_towerKet, PureState.congr_vec, + rotZWireEvolution_evolvePure_quditBasis, + towerProd_vec_update_sum_smul n (fun j => qubitBasis (b j)) t.rev + (fun z => Concrete.rotZ θ z (b t.rev)) qubitBasis + ((rotZGate θ).evolvePure (qubitBasis (b t.rev))) + (rotZGate_evolvePure_qubitBasis_sum θ (b t.rev)), + map_sum] + refine Finset.sum_congr rfl (fun z _ => ?_) + rw [map_smul, towerProd_update_qubitBasis b t z, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply, update_rev_eq b t z] + +/-- **The transported reachable wire `x`-rotation is the grounded `x`-rotation on tower wire +`t.rev`.** The `x`-axis counterpart of `quditPowTower_congr_rotZWireEvolution`: + + `Evolution.congr (quditPowTower n) (rotXWireEvolution (n+1) t θ)` + `= Evolution.qtowerSingleWire n t.rev (rotXGate θ)`. + +Together with the `z`-axis version (at `θ` and `-θ`) this covers all four generators `R_z(±θ), +R_x(±θ)` of `Concrete.reachableRotations θ`: every reachable single-qubit rotation generator, placed +on a register wire, is a grounded rotation gate on a tower wire. Same proof as the `z`-axis version +with the `R_x(θ)` column (`rotXWireEvolution_evolvePure_quditBasis` / +`rotXGate_evolvePure_qubitBasis_sum`). -/ +theorem quditPowTower_congr_rotXWireEvolution (n : ℕ) (t : Fin (n + 1)) (θ : ℝ) : + Evolution.congr (quditPowTower n) (rotXWireEvolution (n + 1) t θ) + = Evolution.qtowerSingleWire n t.rev (rotXGate θ) := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + rw [qtowerSingleWire_evolvePure_towerKet, PureState.congr_vec, + rotXWireEvolution_evolvePure_quditBasis, + towerProd_vec_update_sum_smul n (fun j => qubitBasis (b j)) t.rev + (fun z => Concrete.rotX θ z (b t.rev)) qubitBasis + ((rotXGate θ).evolvePure (qubitBasis (b t.rev))) + (rotXGate_evolvePure_qubitBasis_sum θ (b t.rev)), + map_sum] + refine Finset.sum_congr rfl (fun z _ => ?_) + rw [map_smul, towerProd_update_qubitBasis b t z, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply, update_rev_eq b t z] + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/FourGateReversibleWireTower.lean b/LeanPool/AxQM/Core/FourGateReversibleWireTower.lean new file mode 100644 index 0000000000..e8215199fc --- /dev/null +++ b/LeanPool/AxQM/Core/FourGateReversibleWireTower.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReversibleWire +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.McNotCircuitEvolution + +/-! +# The reversible ≤ 2-control gates as `placedMcNot` on a tower wire set + +*(N&C Exercise 4.43, reversible register lift.)* + +The universality argument of Exercise 4.43 transfers the abstract density result +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` onto the `H, S, CNOT, Toffoli` +gate set. One generating family of the reachable gate set is the `≤ 2`-control reversible gates +`Concrete.IsToffoliPermGate finFunctionFinEquiv G` — the matrices +`permGate finFunctionFinEquiv (mcNotPerm S t)` with `|S| ≤ 2` (`Toffoli`/`CNOT`/`NOT`). This file +re-expresses such a **matrix gate on the qudit register** as the multiply-controlled `NOT` +**gate on the corresponding tower wire set**, relating the matrix-level generators +to the `Evolution` gates, exactly as `AxQM/Core/FourGateReachableWireTower.lean` does for the +rotation generators (and `AxQM/Core/QftTowerHadamard.lean` for the Figure 5.1 Hadamard). + +The target is `Evolution.placedMcNot` — the multiply-controlled `NOT` `Cᵏ(X)` placed on a +wire set of the symmetric register `qubit ^⊗ₛ (n+1)`, which for `|S| ≤ 2` is a genuine +`Toffoli`/`CNOT`/`NOT` built from the four gates. Because the rotation half lands on the control +tower `qtower n qubit`, so must the reversible half; `placedMcNot` is therefore transported back +onto the tower along the bridge `qtowerQubitTensorPow n : qtower n qubit ≃ₛ qubit ^⊗ₛ (n+1)`. + +## What is formalised + +* `mcNotTowerGate n S t ht` — the reversible **gate on the control tower**: the placed + multiply-controlled `NOT` `Evolution.placedMcNot S t ht` (a `Toffoli`/`CNOT`/`NOT` for `|S| ≤ 2`), + transported from the symmetric register `qubit ^⊗ₛ (n+1)` back onto the tower `qtower n qubit` via + `(qtowerQubitTensorPow n).symm`. Its computational-basis action is + `mcNotTowerGate_evolvePure_towerKet` — it flips wire `t` iff every control in `S` is set: + `towerKet n b ↦ towerKet n (mcNot S t b)`. The reversible counterpart of the rotation half's + `qtowerSingleWire n t.rev (rotZGate θ)`. +* `quditPowTower_congr_mcNotWireEvolution` — **the register lift for the reversible gates**: + the wire-`(S, t)` reversible gate on the register (`mcNotWireEvolution (n+1) S t ht`) is, on the + tower, the gate `mcNotTowerGate` on the reversed wire set + `(S.map Fin.revPerm.toEmbedding, t.rev)` (the `Fin.rev` reconciling the big-endian register bridge + with the little-endian wire indexing, as for the rotation register-lift's `t.rev`): + + `Evolution.congr (quditPowTower n) (mcNotWireEvolution (n+1) S t ht)` + `= mcNotTowerGate n (S.map Fin.revPerm.toEmbedding) t.rev _`. + + Proved via the transported-gate re-expression combinator + `quditPowTower_congr_eq_of_evolvePure_towerKet`: on every basis input both sides send + `towerKet n b` to `towerKet n (mcNot (S.map rev) t.rev b)`; the register side computes it through + `mcNotWireEvolution_evolvePure_quditBasis` and the bridge dictionary + `quditPowTower_congr_quditBasis_apply`, the tower side through + `mcNotTowerGate_evolvePure_towerKet`, and the two are reconciled by the `mcNot` relabelling + naturality `Concrete.mcNot_map_equiv` at `σ = Fin.revPerm`. Since a reversible gate is a basis + permutation there is **no** tensor-multilinearity step (the rotation half's inline `mult`) — the + proof stays entirely in basis states. + +The definition of `mcNotWireEvolution` (via the permutation matrix) is in +`AxQM/Postulates/API/FourGateReversibleWire.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The grounded reversible gate on the control tower.** The multiply-controlled `NOT` with +controls `S` and target `t ∉ S`, as a genuine grounded `Evolution (qtower n qubit)`: the placed +gate `Evolution.placedMcNot S t ht` on the symmetric register `qubit ^⊗ₛ (n+1)` (a +`Toffoli`/`CNOT`/`NOT` for `|S| ≤ 2`, built from the four gates) transported back onto the tower +along the bridge `(qtowerQubitTensorPow n).symm`. Its computational-basis action is +`mcNotTowerGate_evolvePure_towerKet` (`towerKet n b ↦ towerKet n (mcNot S t b)`); the reversible +counterpart of `qtowerSingleWire n t.rev (rotZGate θ)`. -/ +def mcNotTowerGate (n : ℕ) (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) (ht : t ∉ S) : + Evolution (qtower n qubit) := + Evolution.congr (qtowerQubitTensorPow n).symm (Evolution.placedMcNot S t ht) + +/-- **The grounded reversible tower gate is the classical `mcNot` on the tower basis.** On the +computational tower basis state `towerKet n b` the gate `mcNotTowerGate n S t ht` produces +`towerKet n (mcNot S t b)`: it flips wire `t` iff every control in `S` is set. Proved by carrying +the `placedMcNot` truth table `Evolution.placedMcNot_evolvePure_qubitBasis` across the tower ↔ +tensor-power bridge: `towerKet n c` is the bridge preimage of the product basis state `⨂ᵢ |c i⟩` +(`qtowerQubitTensorPow_congr_towerKet` + the transport roundtrip `PureState.congr_symm_congr`), and +`Evolution.congr_evolvePure_congr` intertwines the transported gate's action with that of +`placedMcNot`. -/ +theorem mcNotTowerGate_evolvePure_towerKet {n : ℕ} (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) + (ht : t ∉ S) (b : Fin (n + 1) → Fin 2) : + (mcNotTowerGate n S t ht).evolvePure (towerKet n b) = towerKet n (Concrete.mcNot S t b) := by + have key : ∀ c : Fin (n + 1) → Fin 2, towerKet n c + = PureState.congr (qtowerQubitTensorPow n).symm + (PureState.piTensor fun i => qubitBasis (c i)) := fun c => by + rw [← qtowerQubitTensorPow_congr_towerKet n c, PureState.congr_symm_congr] + erw [mcNotTowerGate, key b, Evolution.congr_evolvePure_congr, + Evolution.placedMcNot_evolvePure_qubitBasis, ← key (Concrete.mcNot S t b)] + +/-- **The transported reachable wire multiply-controlled `NOT` is the grounded `placedMcNot` on the +reversed tower wire set.** Transporting the register gate `mcNotWireEvolution (n+1) S t ht` (the +`≤ 2`-control reversible gate on register wires `(S, t)`) onto the `(n+1)`-qubit control tower via +the register bridge `quditPowTower n` yields exactly the grounded reversible gate on the reversed +wire set: + + `Evolution.congr (quditPowTower n) (mcNotWireEvolution (n+1) S t ht)` + `= mcNotTowerGate n (S.map Fin.revPerm.toEmbedding) t.rev _`. + +The register gate — a genuine `Toffoli`/`CNOT`/`NOT` — is, on the grounded tower, precisely the +`placedMcNot` gate on the reversed wire set (the `Fin.rev` reconciling the big-endian register +bridge with the little-endian wire-indexing, as for the rotation register-lift's `t.rev`). Proved +via the transported-gate re-expression combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: +on each basis input both sides give `towerKet n (mcNot (S.map rev) t.rev b)` — register side +`mcNotWireEvolution_evolvePure_quditBasis` + the bridge dictionary +`quditPowTower_congr_quditBasis_apply`, grounded side `mcNotTowerGate_evolvePure_towerKet` — +reconciled by the `mcNot` relabelling naturality `Concrete.mcNot_map_equiv` at `σ = Fin.revPerm`. -/ +theorem quditPowTower_congr_mcNotWireEvolution (n : ℕ) (S : Finset (Fin (n + 1))) + (t : Fin (n + 1)) (ht : t ∉ S) : + Evolution.congr (quditPowTower n) (mcNotWireEvolution (n + 1) S t ht) + = mcNotTowerGate n (S.map Fin.revPerm.toEmbedding) t.rev (by + rw [Finset.mem_map_equiv] + simpa using ht) := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + rw [mcNotTowerGate_evolvePure_towerKet, mcNotWireEvolution_evolvePure_quditBasis, + quditPowTower_congr_quditBasis_apply] + congr 1 + funext i + have h := Concrete.mcNot_map_equiv Fin.revPerm S t b i + simpa only [Fin.revPerm_apply, Fin.revPerm_symm] using h + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/FredkinFiveGateCircuit.lean b/LeanPool/AxQM/Core/FredkinFiveGateCircuit.lean new file mode 100644 index 0000000000..f8f3a26ccc --- /dev/null +++ b/LeanPool/AxQM/Core/FredkinFiveGateCircuit.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.TwoQubitGateCircuit +public import LeanPool.AxQM.Core.FredkinTwoQubitCircuit +public import LeanPool.AxQM.Postulates.API.ControlBranchExt +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Postulates.API.AxisAngleGateValues + +/-! +# The five-two-qubit-gate Fredkin construction: gate + control-branch reduction (N&C Ex 4.25.4) + +Nielsen & Chuang **Exercise 4.25** part (4) asks for an *even simpler* Fredkin construction using +"only **five two-qubit gates**" — the Smolin–DiVincenzo result. This file contains the +gate and the control-branch reduction for that construction in the `TwoQubitGate3` cost model of +`Core.TwoQubitGateCircuit`. + +## The shape of the five-gate circuit + +Part 2 gives `Fredkin = (I ⊗ CNOT) · middleToffoli · (I ⊗ CNOT)` and part 3 expands the middle +Toffoli by Figure 4.8 to get *six* two-qubit gates. The five-gate construction cannot come from +merging further: a controlled-single-qubit alphabet on the control pairs cannot reach five (the same +obstruction as Problem 3.5). It must use a genuinely **entangling** two-qubit gate. The clean choice +places the two entangling gates on the *target* pair `{a, b}` (`pair B`, `pair B†`) sandwiching +three +controlled-single-qubit gates (`ctrl`), so that on control `|0⟩` the `pair` gates cancel +(`B† B = 1`) and on control `|1⟩` the whole thing must implement `SWAP`. Concretely the five-gate +list is +``` +[pair B†, ctrl 0 W₃, ctrl 1 W₂, pair B, ctrl 0 W₁] +``` +with `B` an entangling two-qubit gate and `W₁, W₂, W₃` single-qubit gates. This is exactly the shape +whose *control-branch reduction* is `twoQubitCircuit_pair_ctrl_eq_fredkinGate` below. + +## What is formalised + +* `swapDiagonalizingGate` — the entangling two-qubit gate `B` used on the target pair, + `B = (I ⊗ H) · revC(S) · (H ⊗ I) · CNOT`, a product of four elementary gates. It is the (unique up + to phase) gate that diagonalises the four-cycle permutation `(I ⊗ X) · SWAP`, a "Fourier-type" + entangling gate — the kind the five-gate construction provably needs (a controlled-single-qubit + alphabet cannot supply it). +* `twoQubitCircuit_pair_ctrl_eq_fredkinGate` — **the control-branch reduction.** For *any* two-qubit + gate `B` and single-qubit gates `W₁, W₂, W₃`, if the control-`|1⟩` branch operator implements the + swap, + `B† · (W₃ on a) · (W₂ on b) · B · (W₁ on a) = SWAP`, + then the five-gate circuit `[pair B†, ctrl 0 W₃, ctrl 1 W₂, pair B, ctrl 0 W₁]` equals + `fredkinGate`. This reduces "the five-gate circuit is the Fredkin gate" to a single **two-qubit** + identity, discharging the three-qubit control structure once and for all. + +## Design notes + +* **Why the reduction is clean.** The three-qubit circuit is split on its control qubit with + `controlBranch_evolution_ext` (agreement on `|i⟩ ⊗ φ`, `i ∈ {0, 1}`, `φ` arbitrary). On `|0⟩` the + `ctrl` gates are identities and the two `pair` gates cancel by `B† B = 1` + (`Evolution.evolvePure_adjoint_evolvePure`); on `|1⟩` the `ctrl` gates fire and the branch + operator + is exactly the swap hypothesis, matched against `fredkinGate = controlledUnitary SWAP` via + `controlledUnitary_evolvePure_ketOne`. No superposition bookkeeping — that is isolated to the + separate two-qubit `SWAP`-conjugation identity a consumer supplies. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### The swap-diagonalizing entangling gate -/ + +/-- **The swap-diagonalizing gate** `B = (I ⊗ H) · revC(S) · (H ⊗ I) · CNOT` on two qubits: the +entangling two-qubit gate used on the target pair of the five-two-qubit-gate Fredkin construction +(Exercise 4.25 part 4). Reading right to left (`CNOT` applied first): a `CNOT` with control the +first qubit, a Hadamard on the first qubit, a reversed controlled-`S` (control second, target +first), then a Hadamard on the second qubit. It is the (unique up to phase) gate diagonalising the +four-cycle permutation `(I ⊗ X) · SWAP`; being a genuinely entangling "Fourier-type" gate it +supplies the entanglement a controlled-single-qubit alphabet cannot (Smolin–DiVincenzo). -/ +def swapDiagonalizingGate : Evolution (qubit ⊗ qubit) := + (hadamardGate.onRight qubit).comp + ((reversedControlledUnitary sGate).comp + ((hadamardGate.onLeft qubit).comp cnotGate)) + +/-! ### Control-branch reduction to the Fredkin gate -/ + +/-- **Control-branch reduction for the five-two-qubit-gate Fredkin construction** (Exercise 4.25 +part 4). For any two-qubit gate `B` and single-qubit gates `W₁, W₂, W₃`, if the control-`|1⟩` branch +operator implements the swap, +`B† · (W₃ on the first target) · (W₂ on the second target) · B · (W₁ on the first target) = SWAP`, +then the five-gate circuit `[pair B†, ctrl 0 W₃, ctrl 1 W₂, pair B, ctrl 0 W₁]` equals the Fredkin +gate `C(SWAP)`. + +Proof: split on the control qubit with `controlBranch_evolution_ext`. On control `|0⟩` the three +`ctrl` gates act as the identity and the two `pair` gates cancel (`B† B = 1`, +`Evolution.evolvePure_adjoint_evolvePure`), matching `fredkinGate`'s identity branch. On control +`|1⟩` the `ctrl` gates fire, exhibiting exactly the branch operator of the hypothesis, matched +against `fredkinGate = controlledUnitary SWAP` on the swap branch +(`controlledUnitary_evolvePure_ketOne`). No superposition bookkeeping is needed here; it is confined +to establishing the two-qubit swap hypothesis for a concrete `B`. -/ +theorem twoQubitCircuit_pair_ctrl_eq_fredkinGate + (B : Evolution (qubit ⊗ qubit)) (W₁ W₂ W₃ : Evolution qubit) + (hswap : B.adjoint.comp + ((W₃.onLeft qubit).comp ((W₂.onRight qubit).comp (B.comp (W₁.onLeft qubit)))) + = Evolution.swap) : + twoQubitCircuit + [TwoQubitGate3.pair B.adjoint, TwoQubitGate3.ctrl 0 W₃, TwoQubitGate3.ctrl 1 W₂, + TwoQubitGate3.pair B, TwoQubitGate3.ctrl 0 W₁] + = fredkinGate := by + refine controlBranch_evolution_ext (fun i φ => ?_) + simp only [twoQubitCircuit_cons, twoQubitCircuit_nil, TwoQubitGate3.denote_pair, + TwoQubitGate3.denote_ctrl_zero, TwoQubitGate3.denote_ctrl_one, Evolution.one_def, + Evolution.comp_id, Evolution.evolvePure_comp] + fin_cases i + · -- control |0⟩ : the ctrl gates are identities and the pair gates cancel. + rw [Fin.mk_zero, controlledUnitary_evolvePure_ketZero, Evolution.onRight_evolvePure, + controlledUnitary_evolvePure_ketZero, controlledUnitary_evolvePure_ketZero, + Evolution.onRight_evolvePure, Evolution.evolvePure_adjoint_evolvePure, + fredkinGate_evolvePure_ketZero_left] + · -- control |1⟩ : the ctrl gates fire; the branch operator is the swap hypothesis. + rw [Fin.mk_one, controlledUnitary_evolvePure_ketOne, Evolution.onRight_evolvePure, + controlledUnitary_evolvePure_ketOne, controlledUnitary_evolvePure_ketOne, + Evolution.onRight_evolvePure, fredkinGate, controlledUnitary_evolvePure_ketOne] + have := congrArg (fun U => U.evolvePure φ) hswap + simp only [Evolution.evolvePure_comp] at this + rw [this] + +end AxQM diff --git a/LeanPool/AxQM/Core/FredkinFiveGateSwapIdentity.lean b/LeanPool/AxQM/Core/FredkinFiveGateSwapIdentity.lean new file mode 100644 index 0000000000..deb53eef28 --- /dev/null +++ b/LeanPool/AxQM/Core/FredkinFiveGateSwapIdentity.lean @@ -0,0 +1,90 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.FredkinFiveGateCircuit +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.CnotXBasis +public import LeanPool.AxQM.Postulates.API.PhaseGateEigenbasis + +/-! +# The two-qubit `SWAP`-conjugation identity for the swap-diagonalizing gate (N&C Ex 4.25.4) + +The control-branch reduction `twoQubitCircuit_pair_ctrl_eq_fredkinGate` +(`Core.FredkinFiveGateCircuit`) reduces "the five-two-qubit-gate circuit +`[pair B†, ctrl 0 W₃, ctrl 1 W₂, pair B, ctrl 0 W₁]` equals the Fredkin gate" to a single +**two-qubit `SWAP` identity**, +`B† · (W₃ on the first) · (W₂ on the second) · B · (W₁ on the first) = SWAP`. +This file proves that identity for the concrete gates of the Smolin–DiVincenzo +construction: `B = swapDiagonalizingGate`, `W₁ = X`, `W₂ = Z`, `W₃ = S`. + +## The identity + +`swapDiagonalizingGate_swapConjugation` proves +`B† · S_a · Z_b · B · X_a = SWAP`, +where `S_a = S ⊗ 1`, `Z_b = 1 ⊗ Z`, `X_a = X ⊗ 1` and `B = (I ⊗ H) · revC(S) · (H ⊗ I) · CNOT` is +the swap-diagonalizing gate. This identity is the input to the five-two-qubit-gate Fredkin +construction (N&C Exercise 4.25 part 4), assembled in [upstream `AxQM/NC/Ch4/Exercise4_25.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_25.lean). + +## Proof: peel off the adjoint, then a basis computation + +Multiplying by `B` moves the identity to the equivalent form that never mentions `B†`, +`hkey : S_a · Z_b · B · X_a = B · SWAP`, +because `B† · (B · SWAP) = (B† · B) · SWAP = SWAP` (`Evolution.adjoint_comp_self'`). The point of +`hkey` is that `B` maps each computational basis state `|x⟩ ⊗ |y⟩` to a **product** state +`Sⁱ(H|x⟩) ⊗ H|y⊕x⟩` (the control of every internal gate is a basis state, so no entanglement is +created), so both sides evaluate — factor by factor — to concrete `|±⟩`/`|±i⟩` products. `hkey` is +therefore discharged by two-qubit computational-basis extensionality (`twoQubit_evolution_ext`): +`fin_cases` on the two input bits, then a single `simp only` unfolding `B` through the constituent +`evolvePure` action laws (`cnotGate_evolvePure_qubitBasis`, `Evolution.onLeft_evolvePure`, +`reversedControlledUnitary_evolvePure_ketZero`/`ketOne`, `Evolution.onRight_evolvePure`, +`Evolution.swap_evolvePure_tmul`) and the single-qubit truth tables for `H`, `S`, `Z` on `|±⟩`, +`|±i⟩` (`Postulates.API.PhaseGateEigenbasis`, `hadamardGate_evolvePure_qubitBasis_*`). + +The `X`/`Y`-eigenstate superposition bookkeeping that the constituent single-qubit truth tables +require is in `AxQM/Postulates/API/PhaseGateEigenbasis.lean`. +-/ + +@[expose] public section + +namespace AxQM + +/-- **The two-qubit `SWAP`-conjugation identity for the swap-diagonalizing gate** (N&C Exercise 4.25 +part 4). For `B = swapDiagonalizingGate`, +`B† · (S ⊗ 1) · (1 ⊗ Z) · B · (X ⊗ 1) = SWAP`, +i.e. `swapDiagonalizingGate.adjoint.comp ((sGate.onLeft qubit).comp ((pauliZGate.onRight qubit).comp +(swapDiagonalizingGate.comp (pauliXGate.onLeft qubit)))) = Evolution.swap`. This is the concrete +two-qubit hypothesis consumed by `twoQubitCircuit_pair_ctrl_eq_fredkinGate` to obtain the +five-two-qubit-gate Fredkin construction. + +Proof: the equivalent `B†`-free form `hkey : S_a · Z_b · B · X_a = B · SWAP` holds pointwise on the +four computational basis states (`B` sends each to a product of `|±⟩`/`|±i⟩` factors), proved by +`twoQubit_evolution_ext`; conjugating back through `B† B = 1` gives the stated identity. -/ +theorem swapDiagonalizingGate_swapConjugation : + swapDiagonalizingGate.adjoint.comp + ((sGate.onLeft qubit).comp ((pauliZGate.onRight qubit).comp + (swapDiagonalizingGate.comp (pauliXGate.onLeft qubit)))) + = Evolution.swap := by + have hkey : (sGate.onLeft qubit).comp ((pauliZGate.onRight qubit).comp + (swapDiagonalizingGate.comp (pauliXGate.onLeft qubit))) + = swapDiagonalizingGate.comp Evolution.swap := by + refine twoQubit_evolution_ext (fun i j => ?_) + fin_cases i <;> fin_cases j <;> + simp only [Fin.mk_zero, Fin.mk_one, swapDiagonalizingGate, Evolution.evolvePure_comp, + pauliXGate_evolvePure_qubitBasis, Evolution.onLeft_evolvePure, + cnotGate_evolvePure_qubitBasis, + Evolution.onRight_evolvePure, Evolution.swap_evolvePure_tmul, + reversedControlledUnitary_evolvePure_ketZero, reversedControlledUnitary_evolvePure_ketOne, + hadamardGate_evolvePure_qubitBasis_zero, hadamardGate_evolvePure_qubitBasis_one, + sGate_evolvePure_qubitPlus, sGate_evolvePure_qubitMinus, sGate_evolvePure_qubitPlusI, + sGate_evolvePure_qubitMinusI, pauliZGate_evolvePure_qubitPlus, + pauliZGate_evolvePure_qubitMinus, Fin.reduceAdd, Fin.isValue] + rw [hkey, ← Evolution.comp_assoc, Evolution.adjoint_comp_self', Evolution.id_comp] + +end AxQM diff --git a/LeanPool/AxQM/Core/FredkinTwoQubitCircuit.lean b/LeanPool/AxQM/Core/FredkinTwoQubitCircuit.lean new file mode 100644 index 0000000000..e071f07f74 --- /dev/null +++ b/LeanPool/AxQM/Core/FredkinTwoQubitCircuit.lean @@ -0,0 +1,200 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.TwoQubitGateCircuit +public import LeanPool.AxQM.Postulates.API.Fredkin +public import LeanPool.AxQM.Postulates.API.UnitarySquareRoot + +/-! +# Figure 4.8 for the middle Toffoli: `middleToffoliGate` as five two-qubit gates (N&C Ex 4.25.3) + +Nielsen & Chuang **Exercise 4.25** part (3) instructs one to "replace the middle Toffoli gate with +the circuit in Figure 4.8" to obtain a Fredkin construction using only *two-qubit gates*. The middle +Toffoli of the swap construction (`middleToffoliGate`, Exercise 4.25 part 1) is the +doubly-controlled `X` with controls on qubits 1 and 3 and target qubit 2 — a `C²(X)` whose target is +the *middle* wire rather than the last. This file decomposes the middle Toffoli into a genuine +**five-two-qubit-gate** circuit in the `TwoQubitGate3` cost model of `Core.TwoQubitGateCircuit`, so +that the six-gate (part 3) and five-gate (part 4) constructions can merge it against the outer +`CNOT`s (see [upstream `AxQM/NC/Ch4/Exercise4_25.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_25.lean)). + +## The construction (Figure 4.8 on the middle-wire layout) + +Figure 4.8 (Exercise 4.21, `ccontrolledUnitaryCircuit`) decomposes `C²(V²)` — for a single-qubit +square root `V`, `V² = U` — as five gates: `C(V)`, `CNOT`, `C(V†)`, `CNOT`, `C(V)`. For the middle +Toffoli the two controls are wires `0` and `2` and the target is wire `1`, so choosing wire `0` as +the "outer" control `c₁` and wire `2` as the "inner" control `c₂` places the five gates as +(reading left to right — leftmost acts first): + +1. `C(V)` with control wire `2` on target wire `1`; +2. `CNOT` with control wire `0` on wire `2`; +3. `C(V†)` with control wire `2` on target wire `1`; +4. `CNOT` with control wire `0` on wire `2`; +5. `C(V)` with control wire `0` on target wire `1`. + +Every gate is a genuine two-qubit gate of the `TwoQubitGate3` alphabet: + +* gates 1, 3 are `pair`s — a `C(V)` / `C(V†)` **controlled on wire `2`, targeting wire `1`**, i.e. + the two-qubit gate `reversedControlledUnitary V` on the target pair `{1, 2}` (control on the + *second* factor, target on the *first*), with wire `0` idle; +* gates 2, 4 are `ctrl 1 X` — the control-wire-`0` bit flip of wire `2`; +* gate 5 is `ctrl 0 V` — the control-wire-`0` gate `V` on wire `1`. + +The "reversed" placement of gates 1, 3 is exactly the placement the six-gate merge of part 3 needs: +they sit on the swapped pair `{1, 2}`, so one of the outer `CNOT`s of the part-2 construction +(`Fredkin = (I ⊗ CNOT) · middleToffoli · (I ⊗ CNOT)`) is adjacent to a `pair` gate and merges into +it, dropping the count `7 → 6`. + +## What is formalised + +* `reversedControlledUnitary U` — the **reversed controlled-`U`** on two qubits: control on the + *second* qubit, target on the *first*, `SWAP · C(U) · SWAP`. Generalises `reversedCnotGate` + (`= reversedControlledUnitary pauliXGate`); its two branch actions are + `reversedControlledUnitary_evolvePure_ketZero`/`_ketOne`. +* `middleToffoliTwoQubitGates V` — the length-5 list of `TwoQubitGate3`s above. +* `twoQubitCircuit_middleToffoliTwoQubitGates` — **the Figure 4.8 identity**, fully general in `V`: + the circuit implements the middle-layout `C²(V²)`, `twoQubitCircuit (middleToffoliTwoQubitGates V) + = controlledUnitary (reversedControlledUnitary (V.comp V))`. +* `twoQubitCircuit_middleToffoliTwoQubitGates_eq_middleToffoliGate` — the **middle-Toffoli + specialisation**: whenever `V² = X`, the circuit equals `middleToffoliGate`. +* `exists_twoQubitCircuit_eq_middleToffoliGate` — the **five-two-qubit-gate existence statement**: + there is a two-qubit-gate circuit equal to `middleToffoliGate` with `twoQubitCount = 5` (the `V` + is supplied by `Evolution.exists_comp_self_eq`, so no concrete √X is named). + +## Design notes + +* **Fidelity.** The main identity is proved for an **arbitrary** single-qubit `V` + (it implements `C²(V²)`), exactly mirroring Exercise 4.21's generality; the middle Toffoli is the + `V² = X` instance. `V†` is the genuine adjoint gate `V.adjoint = V⁻¹`, and the equalities are full + `Evolution` equalities, not "on basis states" surrogates. +* **Proof.** `threeQubit_evolution_ext` reduces to agreement on the eight basis inputs; the circuit + unfolds one gate at a time; casework on the two controls `(wire 0, wire 2)` drives the + factor-wise gate actions and the unitarity cancellations `V† V = 1`, `V V† = 1`, `V (V ψ) = V² ψ` + — the same mechanism as `ccontrolledUnitaryCircuit_eq_ccontrolledUnitary`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### The reversed controlled-`U` gate -/ + +/-- **The reversed controlled-`U` gate** on two qubits: the single-qubit unitary `U` is applied to +the *first* qubit exactly when the *second* qubit is `|1⟩` — the roles of control and target of +`controlledUnitary` interchanged. Realised as the swap-conjugate `SWAP · C(U) · SWAP`, so it is a +genuine unitary `Evolution`. It generalises `reversedCnotGate` (which is `reversedControlledUnitary +pauliXGate`), and supplies the `pair` gates of the middle Toffoli's Figure 4.8 decomposition (a +`C(V)` on the target pair `{1, 2}` controlled on the *second* wire). -/ +def reversedControlledUnitary (U : Evolution qubit) : Evolution (qubit ⊗ qubit) := + (Evolution.swap (S := qubit)).comp ((controlledUnitary U).comp (Evolution.swap (S := qubit))) + +/-- **Reversed controlled-`U`, control (second qubit) `|0⟩`:** the target (first qubit) is +untouched, `revC(U)(ψ ⊗ |0⟩) = ψ ⊗ |0⟩`. Computed from `SWAP · C(U) · SWAP` factor by factor. -/ +theorem reversedControlledUnitary_evolvePure_ketZero (U : Evolution qubit) (ψ : PureState qubit) : + (reversedControlledUnitary U).evolvePure (ψ ⊗ (qubitBasis 0)) = ψ ⊗ (qubitBasis 0) := by + rw [reversedControlledUnitary, Evolution.evolvePure_comp, Evolution.evolvePure_comp, + Evolution.swap_evolvePure_tmul, controlledUnitary_evolvePure_ketZero, + Evolution.swap_evolvePure_tmul] + +/-- **Reversed controlled-`U`, control (second qubit) `|1⟩`:** the gate `U` is applied to the target +(first qubit), `revC(U)(ψ ⊗ |1⟩) = (Uψ) ⊗ |1⟩`. Computed from `SWAP · C(U) · SWAP` factor by +factor. -/ +theorem reversedControlledUnitary_evolvePure_ketOne (U : Evolution qubit) (ψ : PureState qubit) : + (reversedControlledUnitary U).evolvePure (ψ ⊗ (qubitBasis 1)) + = (U.evolvePure ψ) ⊗ (qubitBasis 1) := by + rw [reversedControlledUnitary, Evolution.evolvePure_comp, Evolution.evolvePure_comp, + Evolution.swap_evolvePure_tmul, controlledUnitary_evolvePure_ketOne, + Evolution.swap_evolvePure_tmul] + +/-- **The middle Toffoli equals the reversed doubly-controlled `X`.** Unfolding definitions, +`middleToffoliGate = controlledUnitary reversedCnotGate` and `reversedCnotGate = +reversedControlledUnitary pauliXGate` (both are `SWAP · CNOT · SWAP` since `cnotGate = +controlledUnitary pauliXGate`), so `middleToffoliGate = controlledUnitary (reversedControlledUnitary +pauliXGate)` — the middle-wire `C²(X)`. This is the `V² = X` case of +`twoQubitCircuit_middleToffoliTwoQubitGates`'s right-hand side. -/ +theorem middleToffoliGate_eq_controlledUnitary_reversedControlledUnitary : + middleToffoliGate = controlledUnitary (reversedControlledUnitary pauliXGate) := rfl + +/-! ### The middle Toffoli as five two-qubit gates -/ + +/-- **The five two-qubit gates of the middle Toffoli's Figure 4.8 decomposition** (for a +single-qubit square root `V`, `V² = X`), as a `TwoQubitGate3` list on `qubit ⊗ (qubit ⊗ qubit)`. In +*list order* the leftmost element is applied last (it is the leftmost `comp` factor), so reading the +circuit left to right — leftmost gate first — the list is the reverse: `C(V)`(0→1), `CNOT`(0→2), +`C(V†)`(2→1), `CNOT`(0→2), `C(V)`(2→1). Gates 1, 3 (the wire-`2`-controlled `C(V)` / `C(V†)` +on target wire `1`) are `pair (reversedControlledUnitary _)`; gates 2, 4 are `ctrl 1 X`; gate 5 is +`ctrl 0 V`. -/ +def middleToffoliTwoQubitGates (V : Evolution qubit) : List TwoQubitGate3 := + [TwoQubitGate3.ctrl 0 V, + TwoQubitGate3.ctrl 1 pauliXGate, + TwoQubitGate3.pair (reversedControlledUnitary V.adjoint), + TwoQubitGate3.ctrl 1 pauliXGate, + TwoQubitGate3.pair (reversedControlledUnitary V)] + +/-- **Nielsen & Chuang, Exercise 4.25 part 3 (Figure 4.8 for the middle Toffoli).** For every +single-qubit gate `V`, the five-two-qubit-gate circuit `middleToffoliTwoQubitGates V` implements the +middle-wire doubly-controlled gate on `U = V²`, `twoQubitCircuit (middleToffoliTwoQubitGates V) = +controlledUnitary (reversedControlledUnitary (V.comp V))` (controls on wires `0`, `2`, target wire +`1`). + +This is the faithful, fully general Figure 4.8 identity (the analogue of +`ccontrolledUnitaryCircuit_eq_ccontrolledUnitary` for the middle-wire target). Proved by three-qubit +computational-basis extensionality: unfold the circuit, then case on the two controls `(q1, q3)` = +(wire 0, wire 2); the factor-wise gate actions and the unitarity cancellations `V† V = 1`, +`V V† = 1`, `V (V ψ) = (V²) ψ` make each of the four branches agree. -/ +theorem twoQubitCircuit_middleToffoliTwoQubitGates (V : Evolution qubit) : + twoQubitCircuit (middleToffoliTwoQubitGates V) + = controlledUnitary (reversedControlledUnitary (V.comp V)) := by + refine threeQubit_evolution_ext (fun q1 q2 q3 => ?_) + simp only [middleToffoliTwoQubitGates, twoQubitCircuit_cons, twoQubitCircuit_nil, + TwoQubitGate3.denote_ctrl_zero, TwoQubitGate3.denote_ctrl_one, TwoQubitGate3.denote_pair, + Evolution.evolvePure_comp, Evolution.one_def, Evolution.id_evolvePure] + fin_cases q1 <;> fin_cases q3 <;> + simp only [Fin.mk_zero, Fin.mk_one, Fin.isValue, + controlledUnitary_evolvePure_ketZero, controlledUnitary_evolvePure_ketOne, + Evolution.onLeft_evolvePure, Evolution.onRight_evolvePure, + reversedControlledUnitary_evolvePure_ketZero, reversedControlledUnitary_evolvePure_ketOne, + pauliXGate_evolvePure_qubitBasis, Fin.reduceAdd, + Evolution.evolvePure_adjoint_evolvePure, Evolution.evolvePure_adjoint_evolvePure', + Evolution.evolvePure_comp] + +/-- **The middle Toffoli is a five-two-qubit-gate circuit** (Exercise 4.25 part 3). Whenever `V` is +a square root of `X` (`V.comp V = pauliXGate`), the circuit `middleToffoliTwoQubitGates V` equals +`middleToffoliGate`. Immediate from the general Figure 4.8 identity +`twoQubitCircuit_middleToffoliTwoQubitGates` and `middleToffoliGate = controlledUnitary +(reversedControlledUnitary X)`. -/ +theorem twoQubitCircuit_middleToffoliTwoQubitGates_eq_middleToffoliGate (V : Evolution qubit) + (hV : V.comp V = pauliXGate) : + twoQubitCircuit (middleToffoliTwoQubitGates V) = middleToffoliGate := by + rw [twoQubitCircuit_middleToffoliTwoQubitGates, hV, + middleToffoliGate_eq_controlledUnitary_reversedControlledUnitary] + +/-- **The middle Toffoli's decomposition uses five two-qubit gates.** The list has length `5`, so +its `twoQubitCount` is `5` — every element is a genuine two-qubit gate. -/ +theorem twoQubitCount_middleToffoliTwoQubitGates (V : Evolution qubit) : + twoQubitCount (middleToffoliTwoQubitGates V) = 5 := rfl + +/-- **The middle Toffoli is implementable by five two-qubit gates** (Exercise 4.25 part 3, existence +form). There is a `TwoQubitGate3` circuit whose evolution is `middleToffoliGate` and whose +`twoQubitCount` is `5`. The square root `V` of `X` is supplied by `Evolution.exists_comp_self_eq`, +so no concrete √X gate is named. This is the honest "middle Toffoli = five two-qubit gates" +proposition the six- and five-gate Fredkin constructions build on. -/ +theorem exists_twoQubitCircuit_eq_middleToffoliGate : + ∃ gs : List TwoQubitGate3, + twoQubitCircuit gs = middleToffoliGate ∧ twoQubitCount gs = 5 := by + obtain ⟨V, hV⟩ := Evolution.exists_comp_self_eq pauliXGate + exact ⟨middleToffoliTwoQubitGates V, + twoQubitCircuit_middleToffoliTwoQubitGates_eq_middleToffoliGate V hV, + twoQubitCount_middleToffoliTwoQubitGates V⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/GateCircuit.lean b/LeanPool/AxQM/Core/GateCircuit.lean new file mode 100644 index 0000000000..ef483ef22c --- /dev/null +++ b/LeanPool/AxQM/Core/GateCircuit.lean @@ -0,0 +1,181 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary + +/-! +# A typed gate-count model for three-qubit circuits (Nielsen & Chuang §4.3) + +Nielsen & Chuang's controlled-operation exercises make **gate-count** claims — "a `C²(U)` gate can +be built from at most eight one-qubit gates and six CNOTs" (Exercise 4.22), "reduce the number of +single-qubit gates from three to two" (Exercise 4.23), and so on. To state such a claim *faithfully* +the count must be a genuine proposition about a circuit, not a manifest term the reader tallies by +eye. This file provides the shared vehicle: a typed **circuit** on the three-qubit system +`qubit ⊗ (qubit ⊗ qubit)` (wires `0, 1, 2`) as a `List` of `Gate3`s, each either a one-qubit gate on +a chosen wire or a CNOT on one of three directed wire pairs, together with + +* `Gate3.denote` / `gateCircuit` — the `Evolution` a gate / gate list implements (the monoid product + of the gate denotations), so a circuit *means* a concrete unitary; and +* `oneQubitCount` / `cnotCount` — the number of one-qubit / CNOT gates in a list, + +turning "`C²(U)` uses at most `m` one-qubit gates and `n` CNOTs" into the honest existential +`∃ gs, gateCircuit gs = C²(U) ∧ oneQubitCount gs ≤ m ∧ cnotCount gs ≤ n` (assembled for `m = 8`, +`n = 6` in Exercise 4.22). + +## What is formalised + +* `Gate3` — a gate on `qubit ⊗ (qubit ⊗ qubit)`: `oneQubit (wire) (g)` or `cnot (wires)`. +* `Gate3.onWire` / `Gate3.cnotOn` — the `Evolution` embeddings of the two gate kinds; `Gate3.denote` + packages them. `gateCircuit gs = (gs.map Gate3.denote).prod` composes a whole list. +* `oneQubitCount` / `cnotCount` — the two `List.countP` occurrence counts. +* structural rewrites `gateCircuit_nil/cons/append` and `oneQubitCount`/`cnotCount` on `nil`/`cons`/ + `append`, the API a circuit-assembly proof rewrites with. + +## Design notes + +* **Why `List.prod` over the `Evolution` monoid.** `Evolution` is a `Monoid` under `comp` + (unit `1`), so `gateCircuit` is literally the list product and inherits `List.prod_cons` / + `List.prod_append`; the list is read in **operator order** (leftmost gate is the leftmost factor, + i.e. applied *last*), matching how `Evolution.comp` chains are written (`Exercise4_21`'s + Figure 4.8 circuit). +* **The wire embeddings (resolving the non-adjacent-CNOT question).** A one-qubit gate reaches wire + `0/1/2` by `onLeft`/`onRight` nesting. A CNOT reaches the three pairs that occur in the Chapter-4 + constructions without any SWAP conjugation: `(0,1) = C(X on wire 1) = controlledUnitary X.onLeft` + and — the *non-adjacent* case — `(0,2) = C(X on wire 2) = controlledUnitary (X.onRight)`, because + `controlledUnitary` controls on wire `0` and can target either sub-wire directly; `(1,2) = + 1 ⊗ CNOT = cnotGate.onRight`. The CNOT instruction type enumerates these three pairs. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +namespace Gate3 + +/-- The directed CNOT wire pairs used by the three-qubit constructions. -/ +inductive CnotPair where + | /-- Control on the first wire, target on the second. -/ + firstToSecond + | /-- Control on the first wire, target on the third. -/ + firstToThird + | /-- Control on the second wire, target on the third. -/ + secondToThird + +end Gate3 + +/-- **A gate in a three-qubit circuit** on `qubit ⊗ (qubit ⊗ qubit)` (wires `0, 1, 2`): either a +one-qubit gate `g` on a chosen `wire`, or a `CNOT` on one of the supported wire pairs. This +is the syntactic alphabet whose `Gate3.denote`ation is an `Evolution` and whose one-qubit / CNOT +occurrences are counted by `oneQubitCount` / `cnotCount`, so "uses at most `m` one-qubit gates and +`n` CNOTs" becomes a genuine proposition. -/ +inductive Gate3 where + | /-- A one-qubit gate `g` acting on the wire `wire ∈ {0, 1, 2}`. -/ + oneQubit (wire : Fin 3) (g : Evolution qubit) + | /-- A CNOT on the control and target wires encoded by `wires`. -/ + cnot (wires : Gate3.CnotPair) + +namespace Gate3 + +/-- **A one-qubit gate on a chosen wire** of `qubit ⊗ (qubit ⊗ qubit)`: `g` is placed on wire `0` +(the left factor), wire `1` (the left sub-factor of the right factor), or wire `2` (the right +sub-factor), the rest idle, via `Evolution.onLeft`/`onRight` nesting. -/ +def onWire : Fin 3 → Evolution qubit → Evolution (qubit ⊗ (qubit ⊗ qubit)) + | 0, g => g.onLeft (qubit ⊗ qubit) + | 1, g => (g.onLeft qubit).onRight qubit + | _, g => (g.onRight qubit).onRight qubit + +/-- Realize a CNOT on the chosen pair in `qubit ⊗ (qubit ⊗ qubit)`. -/ +def cnotOn : CnotPair → Evolution (qubit ⊗ (qubit ⊗ qubit)) + | .firstToSecond => controlledUnitary (pauliXGate.onLeft qubit) + | .firstToThird => controlledUnitary (pauliXGate.onRight qubit) + | .secondToThird => cnotGate.onRight qubit + +/-- **The `Evolution` denoted by a single gate**: the wire embedding of a one-qubit gate, or the +control/target embedding of a CNOT. -/ +def denote : Gate3 → Evolution (qubit ⊗ (qubit ⊗ qubit)) + | oneQubit w g => onWire w g + | cnot wires => cnotOn wires + +/-- Whether a gate is a one-qubit gate (used by `oneQubitCount`). -/ +def isOneQubit : Gate3 → Bool + | oneQubit .. => true + | cnot .. => false + +/-- Whether a gate is a CNOT gate (used by `cnotCount`). -/ +def isCnot : Gate3 → Bool + | oneQubit .. => false + | cnot .. => true + +end Gate3 + +/-- **The evolution implemented by a gate list**: the monoid product of the gate denotations, +`(gs.map Gate3.denote).prod`, in operator order (the leftmost gate is the leftmost `comp` factor, +applied last). -/ +def gateCircuit (gs : List Gate3) : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + (gs.map Gate3.denote).prod + +/-- **The number of one-qubit gates** in a circuit. -/ +def oneQubitCount (gs : List Gate3) : ℕ := gs.countP Gate3.isOneQubit + +/-- **The number of CNOT gates** in a circuit. -/ +def cnotCount (gs : List Gate3) : ℕ := gs.countP Gate3.isCnot + +@[simp] theorem gateCircuit_nil : gateCircuit [] = 1 := rfl + +/-- The circuit of `g :: gs` applies `g` last: its evolution is `g.denote ∘ (circuit of gs)`. -/ +@[simp] theorem gateCircuit_cons (g : Gate3) (gs : List Gate3) : + gateCircuit (g :: gs) = g.denote.comp (gateCircuit gs) := by + rw [gateCircuit, List.map_cons, List.prod_cons, gateCircuit, Evolution.mul_def] + +/-- Concatenating circuits composes their evolutions: `gateCircuit (gs ++ hs) = gs-circuit ∘ +hs-circuit`, so `hs` acts first. -/ +theorem gateCircuit_append (gs hs : List Gate3) : + gateCircuit (gs ++ hs) = (gateCircuit gs).comp (gateCircuit hs) := by + rw [gateCircuit, List.map_append, List.prod_append, gateCircuit, gateCircuit, Evolution.mul_def] + +@[simp] theorem oneQubitCount_nil : oneQubitCount [] = 0 := rfl + +@[simp] theorem cnotCount_nil : cnotCount [] = 0 := rfl + +/-- A one-qubit gate adds one to the one-qubit count. -/ +@[simp] theorem oneQubitCount_cons_oneQubit (w : Fin 3) (g : Evolution qubit) (gs : List Gate3) : + oneQubitCount (Gate3.oneQubit w g :: gs) = oneQubitCount gs + 1 := by + simp [oneQubitCount, List.countP_cons, Gate3.isOneQubit] + +/-- A CNOT gate does not change the one-qubit count. -/ +@[simp] theorem oneQubitCount_cons_cnot (wires : Gate3.CnotPair) (gs : List Gate3) : + oneQubitCount (Gate3.cnot wires :: gs) = oneQubitCount gs := by + simp [oneQubitCount, Gate3.isOneQubit] + +/-- A CNOT gate adds one to the CNOT count. -/ +@[simp] theorem cnotCount_cons_cnot (wires : Gate3.CnotPair) (gs : List Gate3) : + cnotCount (Gate3.cnot wires :: gs) = cnotCount gs + 1 := by + simp [cnotCount, List.countP_cons, Gate3.isCnot] + +/-- A one-qubit gate does not change the CNOT count. -/ +@[simp] theorem cnotCount_cons_oneQubit (w : Fin 3) (g : Evolution qubit) (gs : List Gate3) : + cnotCount (Gate3.oneQubit w g :: gs) = cnotCount gs := by + simp [cnotCount, Gate3.isCnot] + +/-- One-qubit counts add over concatenation. -/ +theorem oneQubitCount_append (gs hs : List Gate3) : + oneQubitCount (gs ++ hs) = oneQubitCount gs + oneQubitCount hs := by + rw [oneQubitCount, oneQubitCount, oneQubitCount, List.countP_append] + +/-- CNOT counts add over concatenation. -/ +theorem cnotCount_append (gs hs : List Gate3) : + cnotCount (gs ++ hs) = cnotCount gs + cnotCount hs := by + rw [cnotCount, cnotCount, cnotCount, List.countP_append] + +end AxQM diff --git a/LeanPool/AxQM/Core/GlobalPhaseCircuitBudget.lean b/LeanPool/AxQM/Core/GlobalPhaseCircuitBudget.lean new file mode 100644 index 0000000000..4fa5706347 --- /dev/null +++ b/LeanPool/AxQM/Core/GlobalPhaseCircuitBudget.lean @@ -0,0 +1,106 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudgetSingleWire +public import LeanPool.AxQM.Core.QftRegisterBridge +public import LeanPool.AxQM.Postulates.API.NMRControlledZ + +/-! +# The global-phase gate is one single-qubit gate (N&C Problem 4.3(6)) + +The global-phase gate `globalPhaseGate α = e^{iα} · 1` (`Postulates/API/NMRControlledZ`) multiplies +every state vector of the register by a fixed unit-modulus scalar. In N&C Problem 4.3's Trotter +construction it is the summand corresponding to the **identity Pauli string** `g = I^{⊗n}`: the +propagator `exp(-i h_I · I · Δ) = e^{-i h_I Δ} · 1` is exactly such a global phase. To count the +Figure-4.19 Trotter circuit with the elementary-gate budget `CircuitBudget` (`Core/CircuitBudget`), +that identity summand — like every other summand — needs an honest gate count. + +This file supplies it: + +* `globalPhaseGate_circuitBudget` — for every register `qudit (2ⁿ⁺¹)` and phase `α`, + `CircuitBudget (globalPhaseGate α : Evolution (qudit (2ⁿ⁺¹))) 0 1`: **one single-qubit gate**, no + `≤ 2`-control gates. A global phase `e^{iα} · 1` on the whole register is realised as the scalar + single-qubit gate `e^{iα} · 1₂` placed on one wire — `(e^{iα} · 1₂) ⊗ 1 = e^{iα} · 1` — which the + single-wire tower budget `qtowerSingleWire_circuitBudget` counts as one single-qubit gate. + +## Proof route (the reachable `R_z`-rotation budget's global-phase analogue) + +Mirroring `rotZWireEvolution_circuitBudget`, the register gate is transported onto the `(n+1)`-qubit +control tower `qtower n qubit` along the register bridge `quditPowTower n` and counted there: + +* `Evolution.congr_globalPhaseGate` (in `Postulates/API/NMRControlledZ`, beside `globalPhaseGate`) — + the global phase is **invariant under transport**: for any system isomorphism `e`, + `Evolution.congr e (globalPhaseGate α) = globalPhaseGate α`, because `Evolution.congr` conjugates + the operator by the (linear, unital) `conjStarAlgEquiv`, and conjugating the scalar `e^{iα} · 1` + leaves it fixed (`map_smul`/`map_one`). So the transported register phase is the tower phase. +* `qtowerSingleWire_zero_globalPhaseGate` — placing the one-qubit phase gate on the head wire is the + whole-tower phase: `qtowerSingleWire n 0 (globalPhaseGate α) = globalPhaseGate α`, since + `(e^{iα} · 1₂) ⊗ 1 = e^{iα} · 1` (the `n = 0` tower is a single qubit, giving the phase directly; + the `n+1` case is the head-wire placement `g ⊗ 1`, discharged by the structural lemma + `globalPhaseGate_onLeft`). + +Transport gives a tower budget from `qtowerSingleWire_circuitBudget n 0 (globalPhaseGate α)`, which +`CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm` carries back onto the register. + +The wire-gate budgets this one mirrors are in `CircuitBudgetSingleWire` and +`CnotFanEvolutionBudget`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **Placing the one-qubit global phase on the head wire is the whole-tower global phase.** +`Evolution.qtowerSingleWire n 0 (globalPhaseGate α) = globalPhaseGate α` on `qtower n qubit`: the +scalar phase `e^{iα} · 1₂` on wire `0`, tensored with the identity on the remaining wires, is the +register-wide phase `(e^{iα} · 1₂) ⊗ 1 = e^{iα} · 1`. On the single-qubit tower (`n = 0`) the gate +*is* the phase; on `qtower (m+1) qubit` the head-wire placement `g.onLeft (qtower m qubit) = g ⊗ 1` +is the same global phase by the structural lemma `globalPhaseGate_onLeft`. -/ +theorem qtowerSingleWire_zero_globalPhaseGate (n : ℕ) (α : ℝ) : + Evolution.qtowerSingleWire n 0 (globalPhaseGate α) + = (globalPhaseGate α : Evolution (qtower n qubit)) := by + cases n with + | zero => rfl + | succ m => + rw [Evolution.qtowerSingleWire_zero] + exact globalPhaseGate_onLeft α qubit (qtower m qubit) + +/-- **Problem 4.3(6): the global-phase gate costs one single-qubit gate.** For every register +`qudit (2ⁿ⁺¹)` and phase `α`, + + `CircuitBudget (globalPhaseGate α : Evolution (qudit (2ⁿ⁺¹))) 0 1` + +— at most one single-qubit gate and no `≤ 2`-control gates. This is the identity-Pauli-string +summand `exp(-i h_I · I · Δ) = e^{-i h_I Δ} · 1` of the N&C Trotter product, counted as the single +single-qubit gate that realises a global phase (`e^{iα} · 1₂` on one wire). + +Proof: transport onto the control tower via `quditPowTower n` — the phase is transport-invariant +(`Evolution.congr_globalPhaseGate`), so the register phase becomes the tower phase; that tower phase +is the head-wire placement `qtowerSingleWire n 0 (globalPhaseGate α)` +(`qtowerSingleWire_zero_globalPhaseGate`), which `qtowerSingleWire_circuitBudget` budgets `0 1`; +then the inverse wire reindexing carries the budget back onto the register. The +`R_z`-rotation budget `rotZWireEvolution_circuitBudget`'s global-phase analogue. -/ +theorem globalPhaseGate_circuitBudget (n : ℕ) (α : ℝ) : + CircuitBudget (globalPhaseGate α : Evolution (qudit (2 ^ (n + 1)))) 0 1 := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (globalPhaseGate α), + Evolution.congr_globalPhaseGate] + refine CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm ?_ + rw [← qtowerSingleWire_zero_globalPhaseGate n α] + exact qtowerSingleWire_circuitBudget n 0 (globalPhaseGate α) + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/HolevoChi.lean b/LeanPool/AxQM/Core/HolevoChi.lean new file mode 100644 index 0000000000..42c3480e86 --- /dev/null +++ b/LeanPool/AxQM/Core/HolevoChi.lean @@ -0,0 +1,219 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.EntropyJointTheorem +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.ArakiLiebEqualityConditions +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.PartialTraceTensor +public import LeanPool.AxQM.Postulates.API.EntropyConcavity +public import LeanPool.AxQM.Postulates.API.EntropyEvolution +public import LeanPool.AxQM.Postulates.API.EntropyComposite + +/-! +# AxQM — the Holevo χ quantity and its classical–quantum representation + +The **Holevo χ quantity** of an ensemble `{pₓ, ρₓ}` of quantum states (Nielsen & Chuang, +eq. (12.208)): + +`χ ≡ S(ρ) − ∑ₓ pₓ S(ρₓ)`, with `ρ = ∑ₓ pₓ ρₓ`, + +is the amount by which the average component entropy falls short of the entropy of the mixture. +It is the central quantity of Chapter 12 (the Holevo bound, the HSW theorem) and of the +alternate proof of the Holevo bound (N&C Problem 12.1), whose engine is that `χ` **equals a +quantum mutual information**: attaching a classical *index register* `P` correlated with the +ensemble produces the **classical–quantum state** + +`ρᴾ⁄S = ∑ₓ pₓ |x⟩⟨x|ᴾ ⊗ ρₓ`, + +whose mutual information `S(P : S)` is exactly `χ`. This file supplies the following pieces: + +* `State.holevoChi` — the χ quantity of an ensemble of states; +* `State.holevoCQState` — the classical–quantum state, with the classical register realised as the + computational basis of `qudit (Fintype.card ι)` (a concrete register, so + no abstract-register orthogonality hypothesis is needed); +* `State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState` — the bridge `χ = S(P : S)`. + +Elementary χ facts (used by the no-cloning argument, N&C Problem 12.2): + +* `State.holevoChi_eq_sum_mul_quantumRelativeEntropy` — `χ = ∑ᵢ pᵢ D(ρᵢ ‖ μ)` (concavity gap); +* `State.holevoChi_nonneg` — `0 ≤ χ`; +* `State.holevoChi_of_forall_vonNeumannEntropy_zero` / `State.holevoChi_pure` — for a pure-state + ensemble, `χ = S(μ)`. + +Once `χ = S(P : S)`, N&C's Problem 12.1 follows from two facts: +discarding a subsystem cannot increase mutual information +(`State.vonNeumannMutualInfo_le_of_discard'`, part (1)) and a quantum operation on one factor +cannot increase it (Theorem 11.15(3), part (2)); those parts, and the apparatus construction of +part (3), are the subject of `LeanPool/AxQM/NC/Ch12/Problem1.lean`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + +/-- The **Holevo χ quantity** of an ensemble `{pᵢ, ρᵢ}` (Nielsen & Chuang, eq. (12.208)): +`χ = S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ)`, the entropy of the mixture minus the average component entropy. -/ +def State.holevoChi : ℝ := + (State.mix p hp hsum ρ).vonNeumannEntropy - ∑ i, p i * (ρ i).vonNeumannEntropy + +/-- Unfolding lemma for the Holevo χ quantity: `χ = S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ)`. -/ +theorem State.holevoChi_def : + State.holevoChi p hp hsum ρ = + (State.mix p hp hsum ρ).vonNeumannEntropy - ∑ i, p i * (ρ i).vonNeumannEntropy := rfl + +/-- The **classical–quantum state** `∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ` associated to an ensemble `{pᵢ, ρᵢ}` +(Nielsen & Chuang Problem 12.1, the "extra system correlated with the ensemble"): the classical +index register is the computational basis `|i⟩` of `qudit (Fintype.card ι)`, tensored with the +corresponding ensemble state and mixed with weight `pᵢ`. Its mutual information between the +register and the system equals the Holevo χ (see +`State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState`). -/ +def State.holevoCQState : State (qudit (Fintype.card ι) ⊗ S) := + State.mix p hp hsum (fun i => (quditBasis (Fintype.equivFin ι i)).toState.tmul (ρ i)) + +/-- The system marginal of the classical–quantum state is the ensemble mixture: tracing out the +classical register `P` from `∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ` leaves `∑ᵢ pᵢ ρᵢ`. -/ +theorem State.holevoCQState_reducedRight : + (State.holevoCQState p hp hsum ρ).reducedRight = State.mix p hp hsum ρ := by + unfold State.holevoCQState + rw [State.reducedRight_mix] + simp only [State.reducedRight_tmul] + +/-- The von Neumann entropy of the classical–quantum state decomposes as the Shannon entropy of the +weights plus the average component entropy: `S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. This is +the joint entropy theorem `State.vonNeumannEntropy_jointEntropyTheorem` (N&C Theorem 11.8(5)) +applied to the orthonormal register kets `|i⟩` (the computational basis of `qudit (Fintype.card ι)` +reindexed by `Fintype.equivFin`, orthonormal by `quditBasis_orthonormal`). -/ +theorem State.vonNeumannEntropy_holevoCQState : + (State.holevoCQState p hp hsum ρ).vonNeumannEntropy + = Real.entropy p + ∑ i, p i * (ρ i).vonNeumannEntropy := by + unfold State.holevoCQState + exact State.vonNeumannEntropy_jointEntropyTheorem p hp hsum + (fun i => quditBasis (Fintype.equivFin ι i)) (quditBasis_equivFin_orthonormal ι) ρ + +/-- The register marginal of the classical–quantum state has entropy equal to the Shannon entropy +of the weights: `S(Tr_S (∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ)) = H(p)`. Tracing out `S` leaves the diagonal register +state `∑ᵢ pᵢ |i⟩⟨i|`, a mixture of the orthonormal pure states `|i⟩`; its entropy is `H(p)` by +`State.vonNeumannEntropy_mix_toState_orthonormal`. -/ +theorem State.vonNeumannEntropy_reducedLeft_holevoCQState : + (State.holevoCQState p hp hsum ρ).reducedLeft.vonNeumannEntropy = Real.entropy p := by + unfold State.holevoCQState + rw [State.reducedLeft_mix] + simp only [State.reducedLeft_tmul] + exact State.vonNeumannEntropy_mix_toState_orthonormal p hp hsum + (fun i => quditBasis (Fintype.equivFin ι i)) (quditBasis_equivFin_orthonormal ι) + +/-- **The Holevo χ quantity is a quantum mutual information** (Nielsen & Chuang Problem 12.1, the +key identity): for the classical–quantum state `∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ`, the mutual information between +the classical register `P` and the system `S` equals the Holevo χ, + +`S(P : S) = χ = S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ)`. + +The register marginal contributes `H(p)`, the system marginal `S(∑ᵢ pᵢ ρᵢ)`, and the joint state +`H(p) + ∑ᵢ pᵢ S(ρᵢ)`, so the `H(p)` terms cancel. This turns every χ-monotonicity statement of +Problem 12.1 into a mutual-information monotonicity statement already available in the library. -/ +theorem State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState : + (State.holevoCQState p hp hsum ρ).vonNeumannMutualInfo = State.holevoChi p hp hsum ρ := by + rw [State.vonNeumannMutualInfo_def, State.vonNeumannEntropy_reducedLeft_holevoCQState, + State.holevoCQState_reducedRight, State.vonNeumannEntropy_holevoCQState, State.holevoChi_def] + ring + +/-- The Holevo χ quantity is the **average relative entropy to the mean**: +`χ = ∑ᵢ pᵢ D(ρᵢ ‖ μ)`, where `μ = ∑ⱼ pⱼ ρⱼ` is the average state. This is the concavity-gap form +of the entropy (Nielsen & Chuang Theorem 11.10), obtained from the mixing identity +`State.sum_mul_quantumRelativeEntropy_mix`. -/ +theorem State.holevoChi_eq_sum_mul_quantumRelativeEntropy : + State.holevoChi p hp hsum ρ + = ∑ i, p i * (ρ i).quantumRelativeEntropy (State.mix p hp hsum ρ) := by + rw [State.holevoChi_def] + exact (State.sum_mul_quantumRelativeEntropy_mix p hp hsum ρ).symm + +/-- The Holevo χ quantity is **non-negative**, `0 ≤ χ`. This is exactly concavity of the von +Neumann entropy, `∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)` +(`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`, the faithfulness-free form). -/ +theorem State.holevoChi_nonneg : 0 ≤ State.holevoChi p hp hsum ρ := by + rw [State.holevoChi_def, sub_nonneg] + exact State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix' p hp hsum ρ + +/-- If every component of the ensemble has zero von Neumann entropy (in particular, if every `ρᵢ` is +pure), the Holevo χ quantity **collapses to the entropy of the average state**, `χ = S(μ)`. -/ +theorem State.holevoChi_of_forall_vonNeumannEntropy_zero + (h : ∀ i, (ρ i).vonNeumannEntropy = 0) : + State.holevoChi p hp hsum ρ = (State.mix p hp hsum ρ).vonNeumannEntropy := by + simp [State.holevoChi_def, h] + +/-- For an ensemble of **pure** states `{pᵢ, |ψᵢ⟩}` the Holevo χ quantity equals the von Neumann +entropy of the average state, `χ = S(∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|)`, since each pure state has zero entropy +(`PureState.vonNeumannEntropy_toState_eq_zero`). This is the form used in the no-cloning argument +(Nielsen & Chuang Problem 12.2). -/ +theorem State.holevoChi_pure (ψ : ι → PureState S) : + State.holevoChi p hp hsum (fun i => (ψ i).toState) = + (State.mix p hp hsum (fun i => (ψ i).toState)).vonNeumannEntropy := + State.holevoChi_of_forall_vonNeumannEntropy_zero p hp hsum _ + (fun i => (ψ i).vonNeumannEntropy_toState_eq_zero) + +/-- **The Holevo χ quantity is invariant under a unitary applied to every ensemble state**: +`χ(p, U ρ U†) = χ(p, ρ)`. Both the mixture entropy — `S(∑ᵢ pᵢ U ρᵢ U†) = S(U (∑ᵢ pᵢ ρᵢ) U†) = +S(∑ᵢ pᵢ ρᵢ)` via `State.evolve_mix` and the unitary invariance `State.vonNeumannEntropy_evolve` — +and each component entropy `S(U ρᵢ U†) = S(ρᵢ)` are unchanged. This is the "apply the unitary +interaction of the environment" step of the alternate Holevo-bound proof (N&C Problem 12.1(2)). -/ +theorem State.holevoChi_evolve (U : Evolution S) : + State.holevoChi p hp hsum (fun i => U.evolve (ρ i)) = State.holevoChi p hp hsum ρ := by + rw [State.holevoChi_def, State.holevoChi_def, ← State.evolve_mix] + simp only [State.vonNeumannEntropy_evolve] + +/-- **The Holevo χ quantity is invariant under appending a fixed pure ancilla**: +`χ(p, ρᵢ ⊗ |ω⟩⟨ω|) = χ(p, ρ)`. Tensoring the pure state `ω` onto every component adds +`S(ω) = 0` to both the mixture entropy — `S((∑ᵢ pᵢ ρᵢ) ⊗ ω) = S(∑ᵢ pᵢ ρᵢ)` via `State.mix_tmul` +and additivity `State.vonNeumannEntropy_tmul` — and each component entropy, so χ is unchanged. This +is the "adjoin the environment in a pure state" step of the alternate Holevo-bound proof +(N&C Problem 12.1(2)). -/ +theorem State.holevoChi_tmul_pure_right {C : QSystem} (ω : PureState C) : + State.holevoChi p hp hsum (fun i => (ρ i).tmul ω.toState) = State.holevoChi p hp hsum ρ := by + rw [State.holevoChi_def, State.holevoChi_def, ← State.mix_tmul] + simp only [State.vonNeumannEntropy_tmul, PureState.vonNeumannEntropy_toState_eq_zero, add_zero] + +/-- **The Holevo χ quantity is invariant under transporting every ensemble state along a system +isomorphism**: `χ(p, e ρᵢ e⁻¹) = χ(p, ρ)` for `e : S ≃ₛ T`. Transport commutes with mixing +(`State.congr_mix`, so `S(∑ᵢ pᵢ e ρᵢ e⁻¹) = S(e (∑ᵢ pᵢ ρᵢ) e⁻¹) = S(∑ᵢ pᵢ ρᵢ)`) and leaves the von +Neumann entropy unchanged (`State.vonNeumannEntropy_congr`), so both the mixture entropy and each +component entropy are unchanged. The `State.congr` companion of `State.holevoChi_evolve`; it lets a +χ-monotonicity statement be transported across a re-association or swap of the underlying systems +(e.g. `State.holevoChi_reducedRight_le`, tracing out the *left* factor via the swap isomorphism). -/ +theorem State.holevoChi_congr {T : QSystem} (e : S.Iso T) : + State.holevoChi p hp hsum (fun i => State.congr e (ρ i)) = State.holevoChi p hp hsum ρ := by + rw [State.holevoChi_def, State.holevoChi_def, ← State.congr_mix] + simp only [State.vonNeumannEntropy_congr] + +/-- **The Holevo χ quantity is invariant under reindexing the ensemble by an equivalence** +`e : α ≃ β`: `χ(p ∘ e, ρ ∘ e) = χ(p, ρ)`. The χ depends on the ensemble only through its mixture and +its weighted-average component entropy, both finite sums invariant under bijective reindexing +(`Equiv.sum_comp`). The reindexing companion of `State.holevoChi_evolve` / `State.holevoChi_congr`; +it lets an ensemble indexed by an arbitrary finite type be moved to a `Fin n` index without changing +its χ value. -/ +theorem State.holevoChi_equiv {α β : Type*} [Fintype α] [Fintype β] (e : α ≃ β) + (p : β → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : β → State S) + (hp' : ∀ i, 0 ≤ p (e i)) (hsum' : ∑ i, p (e i) = 1) : + State.holevoChi (fun i => p (e i)) hp' hsum' (fun i => ρ (e i)) + = State.holevoChi p hp hsum ρ := by + rw [State.holevoChi_def, State.holevoChi_def] + congr 1 + · congr 1 + apply State.ext + rw [State.mix_op, State.mix_op] + exact Equiv.sum_comp e (fun k => (p k : ℂ) • (ρ k).op) + · exact Equiv.sum_comp e (fun k => p k * (ρ k).vonNeumannEntropy) + +end AxQM diff --git a/LeanPool/AxQM/Core/HolevoChiBound.lean b/LeanPool/AxQM/Core/HolevoChiBound.lean new file mode 100644 index 0000000000..ad0a4e13fc --- /dev/null +++ b/LeanPool/AxQM/Core/HolevoChiBound.lean @@ -0,0 +1,45 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.HolevoChi + +/-! +# AxQM — the Holevo χ quantity is bounded by the entropy of the mixture + +The Holevo χ quantity `χ = S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ)` of an ensemble is at most the von Neumann +entropy of the mixture, because the average component entropy `∑ᵢ pᵢ S(ρᵢ)` is non-negative +(each `S(ρᵢ) ≥ 0` and each `pᵢ ≥ 0`). This is the first half of the standard chain +`χ ≤ S(∑ᵢ pᵢ ρᵢ) ≤ log d` bounding χ by the log of the Hilbert-space dimension — the argument of +Nielsen & Chuang's Exercise 12.3. + +## Main results + +* `AxQM.State.holevoChi_le_vonNeumannEntropy_mix` — `χ({pᵢ, ρᵢ}) ≤ S(∑ᵢ pᵢ ρᵢ)`. +-/ + +@[expose] public section + +namespace AxQM.State + +variable {S : AxQM.QSystem} {ι : Type*} [Fintype ι] + +/-- **The Holevo χ quantity is at most the entropy of the mixture**: for an ensemble `{pᵢ, ρᵢ}`, +`χ({pᵢ, ρᵢ}) ≤ S(∑ᵢ pᵢ ρᵢ)`. Since `χ = S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ)` and the subtracted average +component entropy `∑ᵢ pᵢ S(ρᵢ)` is non-negative (each `pᵢ ≥ 0` and `S(ρᵢ) ≥ 0`), χ can only be +smaller than `S(∑ᵢ pᵢ ρᵢ)`. -/ +theorem holevoChi_le_vonNeumannEntropy_mix (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + holevoChi p hp hsum ρ ≤ (mix p hp hsum ρ).vonNeumannEntropy := by + rw [holevoChi_def] + have hnonneg : 0 ≤ ∑ i, p i * (ρ i).vonNeumannEntropy := + Finset.sum_nonneg fun i _ => mul_nonneg (hp i) (ρ i).vonNeumannEntropy_nonneg + linarith + +end AxQM.State diff --git a/LeanPool/AxQM/Core/LOCCProtocol.lean b/LeanPool/AxQM/Core/LOCCProtocol.lean new file mode 100644 index 0000000000..d7c24825a6 --- /dev/null +++ b/LeanPool/AxQM/Core/LOCCProtocol.lean @@ -0,0 +1,344 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement +public import LeanPool.AxQM.Postulates.API.MeasurementPrecompose +public import LeanPool.AxQM.Postulates.API.CertainMeasurement +public import LeanPool.AxQM.Postulates.API.DeferredMeasurement +public import LeanPool.AxQM.Postulates.API.ToffoliHadamard +public import LeanPool.AxQM.Postulates.API.AdaptiveMeasurement +public import LeanPool.AxQM.Postulates.API.MeasurementReindex +public import LeanPool.AxQM.Postulates.Composite + +/-! +# Finite-round two-way LOCC protocols on a bipartite system + +This module introduces the apparatus needed to state **Nielsen & Chuang, Proposition 12.14** +faithfully — a formal type of **LOCC protocol** (Local Operations and Classical Communication) over +a bipartite system `A ⊗ B`, together with its deterministic transformation semantics and the +one-way (single Alice-measurement / Bob-unitary) protocol form that the proposition reduces to. + +## The model + +A finite-round two-way LOCC protocol is a tree (`LOCCProtocol A B`): at each node one party performs +a **local operation** on their own factor — a measurement (a local *instrument*, the general form of +a local quantum operation, with the classical outcome broadcast to the other party) or a local +unitary — and the protocol continues, with the next operation allowed to depend on the whole +classical record so far (the branch). The five constructors are: + +* `terminal` — stop. +* `aliceMeasure n m k` — Alice measures `m` (an `n`-outcome measurement on `A`), broadcasts the + outcome `j`, and the protocol continues as `k j` (Alice→Bob classical communication). +* `bobMeasure n m k` — Bob measures `m` on `B`, broadcasts `j`, continue as `k j` (Bob→Alice + classical communication). +* `aliceUnitary U k` / `bobUnitary V k` — a party applies a local unitary and continues. + +Outcome sets are taken to be `Fin n`; every finite measurement reindexes to this canonical form, so +this is a faithful model, not a restriction. This is a genuine model of the finite-round two-way +LOCC of N&C §12.5.1: local instruments interleaved with two-way classical communication (the +alternation of `aliceMeasure`/`bobMeasure` and the outcome-dependent continuation `k`). + +## Semantics + +`LOCCProtocol.Transforms P ρ σ` is **deterministic** transformation of `ρ` into `σ`: running `P` on +`ρ`, *every* branch that occurs with nonzero probability ends in `σ`. This is exactly N&C's notion +of "`ρ` can be transformed to `σ` by LOCC" in the pure-state setting — "she starts with `ρ` and ends +with `σ` regardless of the measurement outcome" (Theorem 12.15's usage of this proposition). + +## The reduction target and the Proposition 12.14 goal + +`OneWayLOCC ρ σ` is the single-round form: `∃` an Alice measurement `{Mⱼ}` and Bob unitaries `{Vⱼ}` +such that on every branch `j`, after Alice measures and Bob applies `Vⱼ`, the state is `σ`. It is +realized by the concrete protocol `LOCCProtocol.oneWay` (`OneWayLOCC.exists_transforms`), so it is a +bona-fide sub-class of general LOCC transformability. This is precisely the density-operator content +that `State.LOCCConvertible` (Theorem 12.15) packages on the *reduced* states. + +**Proposition 12.14** concerns transformations between bipartite pure states. The pinned +upstream proof proves a pure-input reduction with an arbitrary deterministic target state. + +```text +∀ (P : LOCCProtocol A B) (ψ : PureState (A ⊗ B)) (σ : State (A ⊗ B)), + P.Transforms ψ.toState σ → OneWayLOCC ψ.toState σ +``` + +This module defines the protocols and proves closure steps for the reduction. The pure-input +reduction theorem is `OneWayLOCC.of_transforms_pureState` in the +[pinned AxQMLib proof](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Proposition12_14.lean#L453-L455). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- A **finite-round two-way LOCC protocol** on the bipartite system `A ⊗ B`: a tree of local +operations (measurements and unitaries by either party) interleaved with classical communication. +At an `aliceMeasure`/`bobMeasure` node the measuring party broadcasts its `Fin n` outcome and the +continuation `k` may depend on it (the classical record); `aliceUnitary`/`bobUnitary` are +deterministic local unitary rounds. Outcome sets are `Fin n` (every finite measurement reindexes to +this), so the model is faithful to N&C §12.5.1's LOCC without loss of generality. -/ +inductive LOCCProtocol (A B : QSystem) where + /-- Stop: the protocol performs no further operations. -/ + | terminal : LOCCProtocol A B + /-- Alice measures the `n`-outcome measurement `m` on her factor `A`, broadcasts the outcome `j`, + and the protocol continues as `k j` (Alice→Bob classical communication). -/ + | aliceMeasure (n : ℕ) (m : Measurement (Fin n) A) (k : Fin n → LOCCProtocol A B) : + LOCCProtocol A B + /-- Bob measures the `n`-outcome measurement `m` on his factor `B`, broadcasts the outcome `j`, + and the protocol continues as `k j` (Bob→Alice classical communication). -/ + | bobMeasure (n : ℕ) (m : Measurement (Fin n) B) (k : Fin n → LOCCProtocol A B) : + LOCCProtocol A B + /-- Alice applies the local unitary `U` on her factor `A`, then continues as `k`. -/ + | aliceUnitary (U : Evolution A) (k : LOCCProtocol A B) : LOCCProtocol A B + /-- Bob applies the local unitary `V` on his factor `B`, then continues as `k`. -/ + | bobUnitary (V : Evolution B) (k : LOCCProtocol A B) : LOCCProtocol A B + +variable {A B : QSystem} + +/-- **Deterministic transformation semantics.** `P.Transforms ρ σ` holds when running the protocol +`P` on the joint state `ρ` sends *every* branch of nonzero probability to `σ`. This is N&C's +"transformed to `σ` by LOCC" in the deterministic sense: the outcome is `σ` regardless of the +measurement results. Defined by structural recursion on `P`: a measurement round requires each +possible post-measurement branch to transform onward to `σ`; a unitary round evolves the state and +continues; `terminal` requires the current state to already be `σ`. -/ +def LOCCProtocol.Transforms : + LOCCProtocol A B → State (A.compose B) → State (A.compose B) → Prop + | .terminal, ρ, σ => ρ = σ + | .aliceMeasure _ m k, ρ, σ => + ∀ j, (h : (m.onLeft B).bornProb ρ j ≠ 0) → + (k j).Transforms ((m.onLeft B).postMeasurement ρ j h) σ + | .bobMeasure _ m k, ρ, σ => + ∀ j, (h : (m.onRight A).bornProb ρ j ≠ 0) → + (k j).Transforms ((m.onRight A).postMeasurement ρ j h) σ + | .aliceUnitary U k, ρ, σ => k.Transforms ((U.onLeft B).evolve ρ) σ + | .bobUnitary V k, ρ, σ => k.Transforms ((V.onRight A).evolve ρ) σ + +@[simp] theorem LOCCProtocol.terminal_transforms_iff (ρ σ : State (A.compose B)) : + (LOCCProtocol.terminal : LOCCProtocol A B).Transforms ρ σ ↔ ρ = σ := Iff.rfl + +/-- `terminal` transforms every state to itself. -/ +theorem LOCCProtocol.terminal_transforms_self (ρ : State (A.compose B)) : + (LOCCProtocol.terminal : LOCCProtocol A B).Transforms ρ ρ := rfl + +@[simp] theorem LOCCProtocol.aliceMeasure_transforms_iff (n : ℕ) (m : Measurement (Fin n) A) + (k : Fin n → LOCCProtocol A B) (ρ σ : State (A.compose B)) : + (LOCCProtocol.aliceMeasure n m k).Transforms ρ σ + ↔ ∀ j, (h : (m.onLeft B).bornProb ρ j ≠ 0) → + (k j).Transforms ((m.onLeft B).postMeasurement ρ j h) σ := Iff.rfl + +@[simp] theorem LOCCProtocol.bobMeasure_transforms_iff (n : ℕ) (m : Measurement (Fin n) B) + (k : Fin n → LOCCProtocol A B) (ρ σ : State (A.compose B)) : + (LOCCProtocol.bobMeasure n m k).Transforms ρ σ + ↔ ∀ j, (h : (m.onRight A).bornProb ρ j ≠ 0) → + (k j).Transforms ((m.onRight A).postMeasurement ρ j h) σ := Iff.rfl + +@[simp] theorem LOCCProtocol.aliceUnitary_transforms_iff (U : Evolution A) (k : LOCCProtocol A B) + (ρ σ : State (A.compose B)) : + (LOCCProtocol.aliceUnitary U k).Transforms ρ σ ↔ k.Transforms ((U.onLeft B).evolve ρ) σ := + Iff.rfl + +@[simp] theorem LOCCProtocol.bobUnitary_transforms_iff (V : Evolution B) (k : LOCCProtocol A B) + (ρ σ : State (A.compose B)) : + (LOCCProtocol.bobUnitary V k).Transforms ρ σ ↔ k.Transforms ((V.onRight A).evolve ρ) σ := + Iff.rfl + +/-- The canonical **one-way protocol** of N&C Proposition 12.14: Alice performs the single +measurement `m` on her factor, broadcasts the outcome `j`, and Bob applies the conditional unitary +`V j` on his factor. This is the form produced by the pure-input reduction of Proposition 12.14. -/ +def LOCCProtocol.oneWay (n : ℕ) (m : Measurement (Fin n) A) (V : Fin n → Evolution B) : + LOCCProtocol A B := + .aliceMeasure n m (fun j => .bobUnitary (V j) .terminal) + +/-- The one-way protocol `LOCCProtocol.oneWay n m V` transforms `ρ` to `σ` exactly when, for every +outcome `j` Alice can obtain, applying Bob's conditional unitary `V j` to Alice's post-measurement +state gives `σ`. This is N&C's single-round form written out. -/ +theorem LOCCProtocol.oneWay_transforms (n : ℕ) (m : Measurement (Fin n) A) + (V : Fin n → Evolution B) (ρ σ : State (A.compose B)) : + (LOCCProtocol.oneWay n m V).Transforms ρ σ + ↔ ∀ j, (h : (m.onLeft B).bornProb ρ j ≠ 0) → + ((V j).onRight A).evolve ((m.onLeft B).postMeasurement ρ j h) = σ := Iff.rfl + +/-- **One-way LOCC reachability** of joint states (N&C Proposition 12.14's target form): there is an +Alice measurement `{Mⱼ}` and a family of Bob unitaries `{Vⱼ}` such that, deterministically on every +branch, Alice measuring and Bob applying `Vⱼ` carries `ρ` to `σ`. This is the joint-state form of +the one-way protocol that the reduced-state predicate `State.LOCCConvertible` (Theorem 12.15) +packages. Proposition 12.14 supplies this form for pure-state transformations. -/ +def OneWayLOCC (ρ σ : State (A.compose B)) : Prop := + ∃ (n : ℕ) (m : Measurement (Fin n) A) (V : Fin n → Evolution B), + (LOCCProtocol.oneWay n m V).Transforms ρ σ + +/-- The one-way form is a genuine LOCC protocol: if `ρ` is one-way reachable to `σ`, then some +`LOCCProtocol` transforms `ρ` to `σ`. Hence `OneWayLOCC` is a sub-class of general LOCC +transformability. This gives the forward inclusion for pure-state instances of Proposition 12.14. -/ +theorem OneWayLOCC.exists_transforms {ρ σ : State (A.compose B)} (h : OneWayLOCC ρ σ) : + ∃ P : LOCCProtocol A B, P.Transforms ρ σ := by + obtain ⟨n, m, V, hP⟩ := h + exact ⟨_, hP⟩ + +/-! ## Closure of one-way LOCC under the deterministic protocol steps + +The pure-input reduction `P.Transforms ψ.toState σ → OneWayLOCC ψ.toState σ` is proved upstream +by induction on the protocol tree `P`, using one closure property of `OneWayLOCC` per constructor. +The first three below cover the *deterministic* steps (`terminal`, `aliceUnitary`, +`bobUnitary`), which need no measurement simulation: reflexivity, and closure under prepending a +local unitary by either party. `prepend_aliceMeasure` handles the `aliceMeasure` case by combining +Alice's rounds into a single measurement (the dependent Ex. 2.57 cascade). The last case +(`bobMeasure`, simulating Bob's measurement by Alice — N&C's Eq. (12.159) crux) is built in +[upstream `NC/Ch12/Proposition12_14.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Proposition12_14.lean) (`OneWayLOCC.prepend_bobMeasure`). -/ + +/-- **Reflexivity of one-way LOCC reachability.** Every joint state is one-way reachable to itself: +Alice performs the trivial single-outcome measurement (which does not disturb the state) and Bob +does nothing. This is the `terminal` case of the Proposition 12.14 reduction induction. -/ +theorem OneWayLOCC.refl (ρ : State (A.compose B)) : OneWayLOCC ρ ρ := by + refine ⟨1, certainMeasurement (T := A) (0 : Fin 1), fun _ => Evolution.id, ?_⟩ + rw [LOCCProtocol.oneWay_transforms] + intro j hj + have hop : ((certainMeasurement (T := A) (0 : Fin 1)).onLeft B).op j = 1 := by + have hj0 : j = 0 := Subsingleton.elim j 0 + subst hj0 + rw [Measurement.onLeft_op, certainMeasurement_op, ite_eq_left rfl] + exact TensorProduct.mapL_one + rw [Measurement.postMeasurement_eq_self_of_op_eq_one + ((certainMeasurement (T := A) (0 : Fin 1)).onLeft B) ρ j hop hj, + Evolution.id_onRight, Evolution.evolve_id] + +/-- **One-way LOCC absorbs a leading Alice-local unitary.** If the state `(U ⊗ 1) ρ (U ⊗ 1)†` +obtained after Alice applies `U` on her factor is one-way reachable to `σ`, then so is `ρ`: fold `U` +into Alice's measurement operators (`Measurement.precompose`), since "apply `U` then measure `m`" is +itself a single Alice measurement. This is the `aliceUnitary` case of the reduction induction. -/ +theorem OneWayLOCC.prepend_aliceUnitary (U : Evolution A) {ρ σ : State (A.compose B)} + (h : OneWayLOCC ((U.onLeft B).evolve ρ) σ) : OneWayLOCC ρ σ := by + obtain ⟨n, m, V, hP⟩ := h + rw [LOCCProtocol.oneWay_transforms] at hP + refine ⟨n, m.precompose U, V, ?_⟩ + rw [LOCCProtocol.oneWay_transforms] + intro j hj + rw [Measurement.onLeft_precompose_postMeasurement] + exact hP j _ + +/-- **One-way LOCC absorbs a leading Bob-local unitary.** If the state `(1 ⊗ V) ρ (1 ⊗ V)†` obtained +after Bob applies `V` on his factor is one-way reachable to `σ`, then so is `ρ`: `V` commutes with +Alice's measurement (they act on disjoint factors), so it defers past her round and composes into +Bob's conditional correction `Wⱼ ↦ Wⱼ V`. This is the `bobUnitary` case of the reduction. -/ +theorem OneWayLOCC.prepend_bobUnitary (V : Evolution B) {ρ σ : State (A.compose B)} + (h : OneWayLOCC ((V.onRight A).evolve ρ) σ) : OneWayLOCC ρ σ := by + obtain ⟨n, m, W, hP⟩ := h + rw [LOCCProtocol.oneWay_transforms] at hP + refine ⟨n, m, fun j => (W j).comp V, ?_⟩ + rw [LOCCProtocol.oneWay_transforms] + intro j hj + have hcomm : ∀ k, ((m.onLeft B).op k).comp (V.onRight A).op + = (V.onRight A).op.comp ((m.onLeft B).op k) := + fun k => Measurement.onLeft_op_comm_onRight_op m V k + have hjV : (m.onLeft B).bornProb ((V.onRight A).evolve ρ) j ≠ 0 := by + rw [Measurement.bornProb_evolve_of_comm (m.onLeft B) (V.onRight A) (fun _ => V.onRight A) + hcomm ρ j] + exact hj + rw [← Evolution.onRight_comp, Evolution.evolve_comp, + ← Measurement.postMeasurement_evolve_of_comm (m.onLeft B) (V.onRight A) (fun _ => V.onRight A) + hcomm ρ j hj] + exact hP j hjV + +/-- **One-way LOCC absorbs a leading Alice measurement round** — the `aliceMeasure` case of the +Proposition 12.14 reduction, and the formal content of N&C's "all the measurements performed by +Alice can be combined into one single measurement (Exercise 2.57)". + +If, after Alice measures `m` (an `n`-outcome measurement on her factor) and obtains any possible +outcome `j`, the resulting post-measurement state is one-way reachable to `σ`, then `ρ` itself is: +Alice performs the *single* measurement `m.adaptiveCascade M'` that measures `m` and then, depending +on the outcome `j`, the measurement `M' j` witnessing the reachability of branch `j` (the dependent +Exercise 2.57 cascade). Its `Σ j, Fin (N j)` outcomes are relabelled to `Fin _` +(`reindexOutcome`); for the joint outcome `⟨j, k⟩` Bob applies the correction `V' j k` from branch +`j`'s witness. A joint outcome `⟨j, k⟩` of nonzero probability forces `j` to be a possible outcome +of `m` (`adaptiveCascade_bornProb_fst_ne_zero`), so the branch witness applies; the Born +probabilities and post-measurement states of the combined round chain through the cascade laws +(`adaptiveCascade_bornProb` / `adaptiveCascade_postMeasurement`). Branches `j` of zero probability +are filled with a trivial witness — they never occur, so their choice is immaterial. -/ +theorem OneWayLOCC.prepend_aliceMeasure {n : ℕ} (m : Measurement (Fin n) A) + {ρ σ : State (A.compose B)} + (h : ∀ j, (hj : (m.onLeft B).bornProb ρ j ≠ 0) → + OneWayLOCC ((m.onLeft B).postMeasurement ρ j hj) σ) : + OneWayLOCC ρ σ := by + classical + -- Totalise the per-branch witnesses (trivial on the zero-probability branches, which never + -- occur). + have h' : ∀ j, ∃ (N : ℕ) (M' : Measurement (Fin N) A) (V' : Fin N → Evolution B), + (hj : (m.onLeft B).bornProb ρ j ≠ 0) → + (LOCCProtocol.oneWay N M' V').Transforms ((m.onLeft B).postMeasurement ρ j hj) σ := by + intro j + by_cases hj : (m.onLeft B).bornProb ρ j = 0 + · exact ⟨1, certainMeasurement (T := A) (0 : Fin 1), fun _ => Evolution.id, + fun hj' => absurd hj hj'⟩ + · obtain ⟨N, M', V', hV'⟩ := h j hj + exact ⟨N, M', V', fun _ => hV'⟩ + choose N M' V' hV' using h' + set e : Fin (Fintype.card (Σ j, Fin (N j))) ≃ (Σ j, Fin (N j)) := + (Fintype.equivFin (Σ j, Fin (N j))).symm with he + refine ⟨Fintype.card (Σ j, Fin (N j)), (m.adaptiveCascade M').reindexOutcome e, + fun i => V' (e i).1 (e i).2, ?_⟩ + rw [LOCCProtocol.oneWay_transforms] + intro i hi + rcases hjk : e i with ⟨j, k⟩ + -- The reindexed combined measurement (lifted to `A ⊗ B`) at outcome `i` has the same operator as + -- the lifted adaptive cascade at `⟨j, k⟩`, so its statistics transport through the cascade laws. + have hop : (((m.adaptiveCascade M').reindexOutcome e).onLeft B).op i + = ((m.onLeft B).adaptiveCascade (fun j' => (M' j').onLeft B)).op ⟨j, k⟩ := by + rw [Measurement.onLeft_op, Measurement.reindexOutcome_op, hjk, + ← Measurement.adaptiveCascade_onLeft_op, Measurement.onLeft_op] + have hcomb : + ((m.onLeft B).adaptiveCascade (fun j' => (M' j').onLeft B)).bornProb ρ ⟨j, k⟩ ≠ 0 := by + rwa [← Measurement.bornProb_congr hop ρ] + have hl : (m.onLeft B).bornProb ρ j ≠ 0 := + Measurement.adaptiveCascade_bornProb_fst_ne_zero (m.onLeft B) (fun j' => (M' j').onLeft B) + ρ j k hcomb + have hfac : ((m.onLeft B).adaptiveCascade (fun j' => (M' j').onLeft B)).bornProb ρ ⟨j, k⟩ + = (m.onLeft B).bornProb ρ j + * ((M' j).onLeft B).bornProb ((m.onLeft B).postMeasurement ρ j hl) k := + Measurement.adaptiveCascade_bornProb (m.onLeft B) (fun j' => (M' j').onLeft B) ρ j k hl + have hm : ((M' j).onLeft B).bornProb ((m.onLeft B).postMeasurement ρ j hl) k ≠ 0 := + right_ne_zero_of_mul (hfac ▸ hcomb) + have hpost : (((m.adaptiveCascade M').reindexOutcome e).onLeft B).postMeasurement ρ i hi + = ((M' j).onLeft B).postMeasurement ((m.onLeft B).postMeasurement ρ j hl) k hm := by + rw [Measurement.postMeasurement_congr hop ρ hi hcomb] + exact Measurement.adaptiveCascade_postMeasurement (m.onLeft B) (fun j' => (M' j').onLeft B) + ρ j k hl hm + rw [hpost] + have key := hV' j hl + rw [LOCCProtocol.oneWay_transforms] at key + exact key k hm + +/-- **One-way LOCC absorbs a leading Alice measurement round with an arbitrary finite outcome set.** +The general-outcome-index form of `OneWayLOCC.prepend_aliceMeasure`: for a measurement `m` on +Alice's factor whose outcomes range over any finite type `κ` (not necessarily `Fin n`), if each +possible post-measurement branch is one-way reachable to `σ`, then so is `ρ`. Relabel the outcomes +`κ → Fin (Fintype.card κ)` along `Fintype.equivFin` (`Measurement.reindexOutcome`) and apply the +`Fin`-indexed `prepend_aliceMeasure`; the relabelling leaves the physics untouched, so Born +probabilities and post-measurement states transport by `Measurement.bornProb_congr` / +`Measurement.postMeasurement_congr` on the equal outcome operators +(`(m.reindexOutcome e).op i = m.op (e i)`). This lets an Alice measurement with a non-`Fin` +outcome set feed the `aliceMeasure` closure — used by Proposition 12.14, whose simulating Alice +measurement is indexed by `Option ι` (Bob's outcomes plus a completeness caveat). -/ +theorem OneWayLOCC.prepend_aliceMeasure' {κ : Type*} [Fintype κ] (m : Measurement κ A) + {ρ σ : State (A.compose B)} + (h : ∀ j, (hj : (m.onLeft B).bornProb ρ j ≠ 0) → + OneWayLOCC ((m.onLeft B).postMeasurement ρ j hj) σ) : + OneWayLOCC ρ σ := by + refine OneWayLOCC.prepend_aliceMeasure (m.reindexOutcome (Fintype.equivFin κ).symm) + (fun i hi => ?_) + have hop : ((m.reindexOutcome (Fintype.equivFin κ).symm).onLeft B).op i + = (m.onLeft B).op ((Fintype.equivFin κ).symm i) := by + rw [Measurement.onLeft_op, Measurement.reindexOutcome_op, Measurement.onLeft_op] + have hj : (m.onLeft B).bornProb ρ ((Fintype.equivFin κ).symm i) ≠ 0 := by + rwa [← Measurement.bornProb_congr hop ρ] + rw [Measurement.postMeasurement_congr hop ρ hi hj] + exact h _ hj + +end AxQM diff --git a/LeanPool/AxQM/Core/McNotCircuitBudget.lean b/LeanPool/AxQM/Core/McNotCircuitBudget.lean new file mode 100644 index 0000000000..10130d4ba9 --- /dev/null +++ b/LeanPool/AxQM/Core/McNotCircuitBudget.lean @@ -0,0 +1,138 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudget +public import LeanPool.AxQM.Core.FourGateReversibleWireTower + +/-! +# The elementary two-control-gate budget: a placed/tower `CNOT`/`Toffoli` is one gate + +This file supplies the **leaf** and **fold** of the elementary-gate budget `CircuitBudget` +(`Core/CircuitBudget`) for `≤ 2`-control gates — the counterpart, for `Toffoli`/`CNOT`/`NOT`, of the +single-qubit-gate machinery `qtowerSingleWire_circuitBudget` (leaf) and `CircuitBudget.listProd` +(fold) that Problem 4.1's phase layer uses. It is the budget foundation of Nielsen & Chuang +**Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit gates" — whose +Figure-4.19 parity circuit (`Concrete/PauliStringParityCascade`) is a fan of `≤ n` `CNOT`s (the two- +control gates counted here) around a single collector `Z`-rotation. + +## The `CircuitBudget` leaf for a multiply-controlled `NOT` + +`CircuitBudget E t s` (N&C Ex 4.29) counts an `Evolution` `E` as at most `t` `≤ 2`-control gates +(`Toffoli`/`CNOT`/`NOT`) and `s` single-qubit gates. Its `block` constructor already witnesses that +a list `gs` of `≤ 2`-control classical gates, realised by an `Evolution` on the flat register +`qubit ^⊗ₛ m`, costs `gs.length` `≤ 2`-control gates. A *single* placed multiply-controlled `NOT` +`Evolution.placedMcNot S t ht` is exactly the `gs = [(S, t)]` case of `block`: its computational- +basis truth table is the classical `mcNot S t` (`Evolution.placedMcNot_evolvePure_qubitBasis`), i.e. +the denotation `mcNotDenote [(S, t)]`. So, whenever it addresses `≤ 2` control wires (`S.card ≤ 2` — +a `Toffoli`, `CNOT`, or `NOT`), it costs **one** `≤ 2`-control gate. + +## What is formalised + +* `Evolution.placedMcNot_circuitBudget` — the **leaf on the flat register**: for `S.card ≤ 2`, + `CircuitBudget (Evolution.placedMcNot S t ht) 1 0` — a placed `Toffoli`/`CNOT`/`NOT` on + `qubit ^⊗ₛ m` is one `≤ 2`-control gate and no single-qubit gates. Direct from the + `CircuitBudget.block` leaf with the singleton gate list `[(S, t)]`, whose truth table is + `placedMcNot_evolvePure_qubitBasis`. + +* `mcNotTowerGate_circuitBudget` — the **leaf on the control tower**: for `S.card ≤ 2`, + `CircuitBudget (mcNotTowerGate n S t ht) 1 0` — the same gate read on the qubit control tower + `qtower n qubit`, where the elementary-gate budget is folded. Immediate from the flat-register + leaf transported along the bridge `qtowerQubitTensorPow n` by `CircuitBudget.congr`, since + `mcNotTowerGate n S t ht = Evolution.congr (qtowerQubitTensorPow n).symm + (Evolution.placedMcNot S t ht)`. This is the tower analogue of `qtowerSingleWire_circuitBudget` + (the single-qubit wire gate) for `≤ 2`-control gates. + +* `CircuitBudget.listProd_twoControl` — the **two-control fold**: a `List.prod` of gates each + costing `1 0` (one `≤ 2`-control gate) costs `l.length 0`. The `≤ 2`-control twin of + `CircuitBudget.listProd` (which folds single-qubit `0 1` gates): `comp` sums the two-control + counts down the list, the empty product discharged by an identity budget on the register + (`hid`, e.g. `CircuitBudget.id_qtower` on a tower). This is the accountant that turns the `≤ n` + per-`CNOT` leaves of the Figure-4.19 parity fan into its `O(n)` two-qubit-gate total (used in + `AxQM/Core/CnotFanEvolutionBudget.lean`, Problem 4.3(3)). + +The `block` leaf it specialises is in `Core/CircuitBudget`, and the single-qubit `listProd` fold it +mirrors is in `Core/PhaseLayerBudget`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +/-- **A placed `Toffoli`/`CNOT`/`NOT` is one `≤ 2`-control gate.** For a control set `S` with at +most two wires (`S.card ≤ 2`) and target `t ∉ S`, the placed multiply-controlled `NOT` +`Evolution.placedMcNot S t ht` on the flat register `qubit ^⊗ₛ m` has budget + + `CircuitBudget (Evolution.placedMcNot S t ht) 1 0` + +— at most one `≤ 2`-control gate (`Toffoli` for `|S| = 2`, `CNOT` for `|S| = 1`, `NOT` for +`|S| = 0`) and no single-qubit gates. This is the `gs = [(S, t)]` case of the `CircuitBudget.block` +leaf: the +singleton list of `≤ 2`-control gates has `hgs` from `S.card ≤ 2` and `t ∉ S`, and its denotation +`mcNotDenote [(S, t)] = mcNot S t` is exactly the placed gate's computational-basis truth table +`Evolution.placedMcNot_evolvePure_qubitBasis`. It is the two-control analogue of the single-qubit +wire leaf `qtowerSingleWire_circuitBudget`. -/ +theorem Evolution.placedMcNot_circuitBudget {m : ℕ} (S : Finset (Fin m)) (t : Fin m) (ht : t ∉ S) + (hcard : S.card ≤ 2) : CircuitBudget (Evolution.placedMcNot S t ht) 1 0 := by + have h := CircuitBudget.block [(S, t)] (Evolution.placedMcNot S t ht) + (by + intro g hg + rw [List.mem_singleton] at hg + subst hg + exact ⟨hcard, ht⟩) + (by + intro c + rw [Evolution.placedMcNot_evolvePure_qubitBasis] + simp only [Concrete.mcNotDenote_cons, Concrete.mcNotDenote_nil] + rfl) + simpa using h + +/-- **A tower `Toffoli`/`CNOT`/`NOT` is one `≤ 2`-control gate.** For a control set `S` with at most +two wires (`S.card ≤ 2`) and target `t ∉ S`, the multiply-controlled `NOT` `mcNotTowerGate n S t ht` +on the qubit control tower `qtower n qubit` has budget + + `CircuitBudget (mcNotTowerGate n S t ht) 1 0` + +— at most one `≤ 2`-control gate and no single-qubit gates. Immediate from the flat-register leaf +`Evolution.placedMcNot_circuitBudget` transported off the tensor power onto the tower along the +bridge `qtowerQubitTensorPow n` by `CircuitBudget.congr`, since +`mcNotTowerGate n S t ht = Evolution.congr (qtowerQubitTensorPow n).symm (Evolution.placedMcNot S t +ht)`. This is the tower `≤ 2`-control leaf the Figure-4.19 `CNOT` parity fan of Problem 4.3(3) folds +wire-by-wire (`CircuitBudget.listProd_twoControl`) — the tower counterpart, for `≤ 2`-control gates, +of the single-qubit wire leaf `qtowerSingleWire_circuitBudget`. -/ +theorem mcNotTowerGate_circuitBudget {n : ℕ} (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) + (ht : t ∉ S) (hcard : S.card ≤ 2) : CircuitBudget (mcNotTowerGate n S t ht) 1 0 := + CircuitBudget.congr (IsWireReindexing.qtowerQubitTensorPow n).symm + (Evolution.placedMcNot_circuitBudget S t ht hcard) + +/-- **A product of `≤ 2`-control gates costs one gate per factor.** If every gate in a list `l` has +budget `CircuitBudget · 1 0` (one `≤ 2`-control gate, no single-qubit gates), then their composition +`l.prod` has `CircuitBudget l.prod l.length 0` — the `≤ 2`-control counts add down the list. The +`≤ 2`-control twin of `CircuitBudget.listProd` (which folds single-qubit `0 1` gates): the reusable +accountant behind a `Toffoli`/`CNOT` fan or layer, e.g. the Figure-4.19 `CNOT` parity fan of +Problem 4.3(3). The empty product `1` needs an identity budget on the register, passed as `hid` +because a general system carries no elementary-gate witness for `1` (its constructors place gates on +qubit registers only); on a qubit tower `hid` is `CircuitBudget.id_qtower`. The `t₀ = 1, s₀ = 0` +specialisation of the general uniform fold `CircuitBudget.listProd_uniform` +(`l.length * 1 = l.length`, `l.length * 0 = 0`) — the count twin of the single-qubit +`CircuitBudget.listProd` (`t₀ = 0, s₀ = 1`). -/ +theorem CircuitBudget.listProd_twoControl {S : QSystem} (hid : CircuitBudget (1 : Evolution S) 0 0) + (l : List (Evolution S)) (h : ∀ E ∈ l, CircuitBudget E 1 0) : + CircuitBudget l.prod l.length 0 := by + simpa using CircuitBudget.listProd_uniform hid l h + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/McNotCircuitDecomposition.lean b/LeanPool/AxQM/Core/McNotCircuitDecomposition.lean new file mode 100644 index 0000000000..562f2edc71 --- /dev/null +++ b/LeanPool/AxQM/Core/McNotCircuitDecomposition.lean @@ -0,0 +1,182 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.McNotCircuitEvolution +public import LeanPool.AxQM.Core.EvolutionQubitBasisExt + +/-! +# A placed `Cᵏ(X)` gate decomposes into a bounded Toffoli circuit (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. `exists_mcNotCircuitEvolution` +lifts a whole *classical* `mcNot` circuit +`gs : List (McNotGate m)` to an `Evolution` on the ambient register `qubit ^⊗ₛ m`, but only +certifies its action *on the computational basis*. This file upgrades that basis-action agreement +to an honest **`Evolution` identity**: a single multiply-controlled `NOT` gate `Cᵏ(X)` placed on the +wires `(S, t)` of a register that has **at least one wire outside the gate's support** *is equal, as +an `Evolution`*, to a genuine circuit of placed `Toffoli`/`CNOT`/`NOT` gates. + +## What is formalised + +`exists_mcNotCircuitEvolution_eq_placedMcNot` — for a control set `S : Finset (Fin m)`, a target +`t ∉ S`, and one spare wire outside the gate's support (`(insert t S).card < m` — the dirty borrowed +wire the recursion needs), there is a circuit `gs` of gates each with `≤ 2` controls (a +`Toffoli`/`CNOT`/`NOT`, target never a control) and an `Evolution U` on `qubit ^⊗ₛ m` such that + +* every gate of `gs` has `≤ 2` controls (`g.1.card ≤ 2 ∧ g.2 ∉ g.1`); +* the circuit has `O(k²)` gates: `gs.length ≤ mcNotGateBound |S|`, and + `mcNotGateBound =O[atTop] k²` (`Concrete.mcNotGateBound_isBigO_sq`); +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs` — so `U` *is* the closed-system gate sequence of `gs`; and +* **`Evolution.placedMcNot S t ht = U`** — the placed `Cᵏ(X)` gate and the assembled bounded-control + circuit are the *same* `Evolution`, not merely equal on basis states. + +The equality is the composition of three facts read through computational-basis +extensionality (`Evolution.ext_qubitBasis`): the placed gate's truth table +(`Evolution.placedMcNot_evolvePure_qubitBasis`, `= mcNot S t`), the circuit Evolution's truth table +(`exists_mcNotCircuitEvolution`, `= mcNotDenote gs`), and the classical circuit's correctness +(`Concrete.exists_mcNotCircuit`, `mcNotDenote gs = mcNot S t`). + +The companion `exists_mcNotCircuitEvolution_eq_placedMcCtrlX` states the same for a `Cᵏ(X)` block +placed by a *wire permutation* `σ` (the `Evolution.onWires` form). The last theorem specialises it +further to `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` — the **contiguous front-block** form +`(Evolution.tensorPowMcCtrlX k).onBlock b` (identity permutation, `Evolution.placedMcCtrlX_one`), +the shape a Barenco `Cᵏ(X)` block takes once the control tower is flattened (its `k` controls and +target are the leading `k + 1` wires, the `b ≥ 1` idle inner wires the spare). + +## Its role in the no-work-qubit circuit + +This is the **per-block** decomposition every Barenco layer of the tight no-work-qubit +`Cⁿ(X)` circuit needs. On exactly `n + 1` wires the *top* gate `Cⁿ(X)` (support = all `n + 1` +wires, no spare) cannot itself be a permutation-only Toffoli circuit — it is an odd permutation +while every `≤ 2`-control gate is even (the parity obstruction) — so it is decomposed through the +single-qubit `√X` gates (`barencoNCircuit`). But each *internal* block that decomposition +produces is a `Cᵏ(X)` with `k < n`, whose support `k + 1 ≤ n < n + 1` leaves a spare wire, so +`(insert t S).card < m` holds and *this* lemma realises it as a genuine `O(k²)` Toffoli circuit. +Summed over the `O(n)` layers this is the exercise's `O(n²)` gate count. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +/-- **N&C Exercise 4.29: a placed `Cᵏ(X)` decomposes into a bounded +Toffoli/CNOT/NOT circuit.** Given a control set `S : Finset (Fin m)`, a target `t ∉ S`, and one wire +outside the gate's support (`(insert t S).card < m`, the borrowed dirty wire), there is a circuit +`gs` of gates each with at most two controls (a `Toffoli`/`CNOT`/`NOT`, target never a control) and +a single closed-system `Evolution U` on `qubit ^⊗ₛ m` with: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ Concrete.mcNotGateBound S.card` — the `O(k²)` gate count + (`k = |S|`; `mcNotGateBound =O[atTop] k²`, `Concrete.mcNotGateBound_isBigO_sq`); +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` exactly as the classical circuit denotation + `Concrete.mcNotDenote gs` — i.e. `U` is the composite (`exists_mcNotCircuitEvolution`) of the + placed gates of `gs`; and +* `Evolution.placedMcNot S t ht = U` — the placed `Cᵏ(X)` gate **is** that assembled circuit, as an + `Evolution`. + +The equality follows from computational-basis extensionality (`Evolution.ext_qubitBasis`): both +sides act on `|⨂ᵢ c i⟩` as the classical multiply-controlled `NOT` `Concrete.mcNot S t` — the placed +gate by `Evolution.placedMcNot_evolvePure_qubitBasis`, the circuit `U` by the truth table of +`exists_mcNotCircuitEvolution` composed with the circuit correctness `Concrete.exists_mcNotCircuit` +(`mcNotDenote gs = mcNot S t`). + +This is the per-block decomposition consumed by every internal `Cᵏ(X)` block (`k < n`, always with a +spare wire) of the no-work-qubit `Cⁿ(X)` circuit; see the module docstring. -/ +theorem exists_mcNotCircuitEvolution_eq_placedMcNot {m : ℕ} (S : Finset (Fin m)) (t : Fin m) + (ht : t ∉ S) (hspare : (insert t S).card < m) : + ∃ (gs : List (Concrete.McNotGate m)) (U : Evolution (qubit.tensorPow m)), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound S.card ∧ + (∀ c : Fin m → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + Evolution.placedMcNot S t ht = U := by + obtain ⟨gs, hgs, hden, hlen⟩ := Concrete.exists_mcNotCircuit S t ht hspare + obtain ⟨U, hU⟩ := exists_mcNotCircuitEvolution gs fun g hg => (hgs g hg).2 + refine ⟨gs, U, hgs, hlen, hU, ?_⟩ + refine Evolution.ext_qubitBasis fun c => ?_ + rw [Evolution.placedMcNot_evolvePure_qubitBasis, hU, hden] + +/-- **N&C Exercise 4.29: the wire-permutation form of the per-block +decomposition.** The same statement as `exists_mcNotCircuitEvolution_eq_placedMcNot`, but for a +`Cᵏ(X)` block placed by a *wire permutation* `σ` (the form produced by the arbitrary-wire combinator +`Evolution.onWires`, hence the shape a placed Barenco block naturally takes): as soon as there is at +least one idle wire (`1 ≤ b`, so the `k + 1` support wires do not fill the `k + 1 + b`-wire +register), the placed gate `Evolution.placedMcCtrlX k b σ` **equals** a genuine `Evolution` circuit +of `≤ 2`-control gates with `O(k²)` count. + +Reduces to `exists_mcNotCircuitEvolution_eq_placedMcNot` applied to the placed gate's own control +set `S = {σ(0), …, σ(k-1)}` (`= Finset.image (σ ∘ Fin.castAdd b) (cnxControls k)`) and target +`t = σ k` (`= σ (Fin.castAdd b (Fin.last k))`): the spare-wire hypothesis holds because `|S| = k` +(the placement is injective) and `|insert t S| = k + 1 < k + 1 + b`, and +`placedMcCtrlX k b σ = placedMcNot S t` by computational-basis extensionality (both have truth +table `Concrete.mcNot S t`). -/ +theorem exists_mcNotCircuitEvolution_eq_placedMcCtrlX {k b : ℕ} (hb : 1 ≤ b) + (σ : Equiv.Perm (Fin (k + 1 + b))) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + b))) (U : Evolution (qubit.tensorPow (k + 1 + b))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound k ∧ + (∀ c : Fin (k + 1 + b) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + Evolution.placedMcCtrlX k b σ = U := by + have hinj : Function.Injective (fun j : Fin (k + 1) => σ (Fin.castAdd b j)) := + σ.injective.comp (Fin.castAdd_injective _ _) + have ht_notin : σ (Fin.castAdd b (Fin.last k)) ∉ + Finset.image (fun j => σ (Fin.castAdd b j)) (cnxControls k) := by + rw [hinj.mem_finset_image]; exact last_notMem_cnxControls k + have hcard : (Finset.image (fun j => σ (Fin.castAdd b j)) (cnxControls k)).card = k := by + rw [Finset.card_image_of_injective _ hinj, cnxControls_eq_image_castSucc, + Finset.card_image_of_injective _ (Fin.castSucc_injective k), Finset.card_univ, + Fintype.card_fin] + have hspare : (insert (σ (Fin.castAdd b (Fin.last k))) + (Finset.image (fun j => σ (Fin.castAdd b j)) (cnxControls k))).card < k + 1 + b := by + rw [Finset.card_insert_of_notMem ht_notin, hcard]; omega + obtain ⟨gs, U, hgs, hlen, hUc, hplaced⟩ := + exists_mcNotCircuitEvolution_eq_placedMcNot _ _ ht_notin hspare + refine ⟨gs, U, hgs, ?_, hUc, ?_⟩ + · rwa [hcard] at hlen + · rw [← hplaced] + refine Evolution.ext_qubitBasis fun c => ?_ + rw [placedMcCtrlX_evolvePure_qubitBasis, Evolution.placedMcNot_evolvePure_qubitBasis] + +/-- **N&C Exercise 4.29: the block-embedded `Cᵏ(X)` decomposes into +a bounded Toffoli circuit.** The contiguous front-block placement +`(Evolution.tensorPowMcCtrlX k).onBlock b` — the grounded `Cᵏ(X)` (`k` controls, one target = the +leading `k + 1` wires) acting as the identity on the trailing `b` ambient wires of +`qubit ^⊗ₛ (k+1+b)` — is, **as an `Evolution`**, a genuine circuit of `≤ 2`-control gates +(`Toffoli`/`CNOT`/`NOT`) with `O(k²)` count, provided at least one ambient wire is present +(`1 ≤ b`, the borrowed dirty wire the recursion needs). + +This is the contiguous-front specialisation of `exists_mcNotCircuitEvolution_eq_placedMcCtrlX` at +the identity wire permutation (`Evolution.placedMcCtrlX_one`): the placed gate's control set and +target are then the front wires `(cnxControls k).image (Fin.castAdd b)` and +`Fin.castAdd b (Fin.last k)`. It is the form the multiply-controlled `NOT` blocks of the tight +no-work-qubit `Cⁿ(X)` circuit take after the tower is flattened — the Barenco reduction +(`barencoNCircuit`) puts each internal `Cᵏ(X)` block's `k` controls on the outer tower wires and its +target on the next wire, with the remaining `≥ 1` inner wires idle, i.e. exactly a leading +`(k+1)`-wire block with `b ≥ 1` spare — so each such block is realised here as an `O(k²)` Toffoli +circuit, and the `O(n)` blocks sum to the exercise's `O(n²)` gate count. -/ +theorem tensorPowMcCtrlX_onBlock_eq_toffoliCircuit {k b : ℕ} (hb : 1 ≤ b) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + b))) (U : Evolution (qubit.tensorPow (k + 1 + b))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ Concrete.mcNotGateBound k ∧ + (∀ c : Fin (k + 1 + b) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + (Evolution.tensorPowMcCtrlX k).onBlock b = U := by + obtain ⟨gs, U, hgs, hlen, hUc, hplaced⟩ := + exists_mcNotCircuitEvolution_eq_placedMcCtrlX hb (1 : Equiv.Perm (Fin (k + 1 + b))) + exact ⟨gs, U, hgs, hlen, hUc, (Evolution.placedMcCtrlX_one k b).symm.trans hplaced⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/McNotCircuitEvolution.lean b/LeanPool/AxQM/Core/McNotCircuitEvolution.lean new file mode 100644 index 0000000000..4b4e215000 --- /dev/null +++ b/LeanPool/AxQM/Core/McNotCircuitEvolution.lean @@ -0,0 +1,218 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.WireGatherPermutation +public import LeanPool.AxQM.Concrete.MultiControlledNotCircuit +public import LeanPool.AxQM.Postulates.API.TensorPowSplit +public import LeanPool.AxQM.Postulates.API.LeftPairGate + +/-! +# A classical `mcNot` circuit as an `Evolution` (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The classical development +(`Concrete/MultiControlledNot*`) produces that circuit as a `List` of gates +`gs : List (McNotGate m)` — each gate `(Sᵢ, tᵢ)` a wire-addressed multiply-controlled `NOT` +`Concrete.mcNot Sᵢ tᵢ` with `|Sᵢ| ≤ 2` — with composite denotation `Concrete.mcNotDenote gs` the +reversible bit-string permutation `Cⁿ(X)`. `placedMcCtrlX_wireGather_evolvePure_qubitBasis` turns a +**single** such gate `(S, t)` into a genuine closed-system `Evolution` — but on the *gate-local* +register `qubit ^⊗ₛ (|S| + 1 + b)` sized to that one gate's control arity. This file reconciles +those varying gate-local registers with the **one ambient register** `qubit ^⊗ₛ m` a circuit's gates +all share, and composes the gates into a single `Evolution` realising the whole circuit. + +The reconciliation is the **register cast** (`QSystem.tensorPowCongr`): for a gate +`(S, t)` with `t ∉ S`, the support `insert t S` has `|S| + 1 ≤ m` wires, so +`|S| + 1 + (m - (|S| + 1)) = m` +and the gate-local register `qubit ^⊗ₛ (|S| + 1 + (m - (|S| + 1)))` is *propositionally* the ambient +`qubit ^⊗ₛ m`. Transporting that gate along `QSystem.tensorPowCongr qubit (finCongr …)` (the +gate transported by `Evolution.congr`, the state by `PureState.congr`) lands it on `qubit ^⊗ₛ m` +with its truth table `Concrete.mcNot S t` intact — the equivariance of `mcNot` under the wire +relabelling (`Concrete.mcNot_map_equiv`) carries the classical action through the cast. + +## What is formalised + +* `Evolution.congr_tensorPowCongr_evolvePure_qubitBasis` — the **register-cast dictionary for a + classical gate**: if `G : Evolution (qubit ^⊗ₛ a)` has computational-basis truth table + `G |⨂ d⟩ = |⨂ γ d⟩` and `e : Fin a ≃ Fin p`, then the transported gate + `G.congr (QSystem.tensorPowCongr qubit e)` on `qubit ^⊗ₛ p` acts on `|⨂ c⟩` as + `|⨂ⱼ (γ (c ∘ e)) (e.symm j)⟩` — the classical action `γ` conjugated by the wire relabelling `e`. +* `Evolution.placedMcNot S t ht` — a single classical gate `(S, t)` (`t ∉ S`) realised as a genuine + `Evolution (qubit ^⊗ₛ m)` on the **ambient** register, the register cast of the gate-local + `Evolution.placedMcCtrlX` gathered onto `(S, t)` by `wireGatherPerm`. Its computational-basis + truth table `Evolution.placedMcNot_evolvePure_qubitBasis` is exactly `Concrete.mcNot S t` on + `Fin m`. +* `exists_mcNotCircuitEvolution` — the **circuit assembly**: for any classical circuit + `gs : List (McNotGate m)` whose gates all satisfy `tᵢ ∉ Sᵢ`, there is a single `Evolution` on + `qubit ^⊗ₛ m` — the composite of the per-gate `Evolution.placedMcNot` gates — acting on every + computational basis state `|⨂ c⟩` exactly as the classical circuit denotation + `Concrete.mcNotDenote gs`. Applied to the `O(n²)` circuit `Concrete.exists_mcNotCircuit` produces, + this exhibits `Cⁿ(X)` (on its dirty-borrow register) as a genuine `Evolution` circuit of placed + `Toffoli`/`CNOT`/`NOT` gates. + +## Design notes + +* **Why a register cast, not a fresh placement.** `Evolution.placedMcCtrlX k b σ` is typed on + `qubit ^⊗ₛ (k + 1 + b)` by construction (it embeds the `(k+1)`-wire gate into `k+1+b` wires via + `Evolution.onWires`). A circuit's gates have *varying* `kᵢ = |Sᵢ|`, so no single `k + 1 + b` is + `m` definitionally; the cast `QSystem.tensorPowCongr qubit (finCongr h)` (with `h : k+1+b = m`) is + the minimal, purely structural reconciliation — it relabels the wire *index type* without + touching the gate's action, so the gate-local truth table survives up to `mcNot` equivariance. +* **Why the truth table survives.** Transporting `G |⨂ d⟩ = |⨂ γ d⟩` across the cast conjugates the + bit-string action by `e`: the input `|⨂ c⟩` is read as `|⨂ (c ∘ e)⟩` on the gate-local register, + `γ` acts there, and the output is relabelled back by `e.symm`. For `γ = Concrete.mcNot S' t'` + (with `S' = S.map e.symm.toEmbedding`, `t' = e.symm t` the pulled-back gate data) this conjugated + action is exactly `Concrete.mcNot S t` on the ambient register — `Concrete.mcNot_map_equiv`, the + naturality of `mcNot` under a bijective wire relabelling. +* **Why an existence statement for the circuit.** The circuit assembly returns *some* realising + `Evolution` (the fold of the per-gate gates over `Evolution.comp`) rather than a total + `List → Evolution` function: the per-gate `Evolution.placedMcNot` needs the gate hypothesis + `tᵢ ∉ Sᵢ`, which the `O(n²)` construction `Concrete.exists_mcNotCircuit` guarantees for every + gate but which a *total* function over unconstrained lists would have to fake. The existence form + threads the hypothesis through the list induction cleanly (base = `Evolution.id`, `cons` = + `Evolution.comp`). +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {m : ℕ} + +/-- **The gate-local register matches the ambient register.** For a gate `(S, t)` with `t ∉ S` on +`Fin m`, the support `insert t S` uses `|S| + 1 ≤ m` wires, so the gate-local wire count +`|S| + 1 + (m - (|S| + 1))` (the `Evolution.placedMcCtrlX` register arity) is exactly `m`. The +arithmetic identity the register cast `finCongr` consumes. -/ +theorem card_succ_add_sub (S : Finset (Fin m)) (t : Fin m) (ht : t ∉ S) : + S.card + 1 + (m - (S.card + 1)) = m := by + have h : S.card + 1 ≤ m := by + have hle := Finset.card_le_univ (insert t S) + rwa [Finset.card_insert_of_notMem ht, Fintype.card_fin] at hle + omega + +/-- **Register-cast dictionary for a classical gate.** If `G : Evolution (qubit ^⊗ₛ a)` is a +classical gate — it permutes the computational basis, `G |⨂ᵢ d i⟩ = |⨂ᵢ γ d i⟩` for a bit-string +action `γ : (Fin a → Fin 2) → (Fin a → Fin 2)` — then transporting it along the factor-relabelling +register cast `QSystem.tensorPowCongr qubit e` (`e : Fin a ≃ Fin p`) yields a classical gate on +`qubit ^⊗ₛ p` whose action is `γ` conjugated by the wire relabelling: on `|⨂ⱼ c j⟩` it produces +`|⨂ⱼ (γ (c ∘ e)) (e.symm j)⟩` — read the input on the relabelled wires (`c ∘ e`), run `γ`, relabel +the output back by `e.symm`. Proved by rewriting the input as the transport of `|⨂ᵢ c (e i)⟩` under +`QSystem.tensorPowCongr_congr_piTensor`, pushing the transport through `G` with the gate transport +law `Evolution.congr_evolvePure_congr`, applying `γ` via `hG`, and reading the output back through +the cast. -/ +theorem Evolution.congr_tensorPowCongr_evolvePure_qubitBasis {a p : ℕ} + (G : Evolution (qubit ^⊗ₛ a)) (e : Fin a ≃ Fin p) + (γ : (Fin a → Fin 2) → (Fin a → Fin 2)) + (hG : ∀ d : Fin a → Fin 2, + G.evolvePure (PureState.piTensor fun i => qubitBasis (d i)) + = PureState.piTensor fun i => qubitBasis (γ d i)) + (c : Fin p → Fin 2) : + (G.congr (QSystem.tensorPowCongr qubit e)).evolvePure + (PureState.piTensor fun j => qubitBasis (c j)) + = PureState.piTensor fun j => qubitBasis (γ (fun i => c (e i)) (e.symm j)) := by + have hinput : PureState.piTensor (fun j => qubitBasis (c j)) + = PureState.congr (QSystem.tensorPowCongr qubit e) + (PureState.piTensor fun i => qubitBasis (c (e i))) := by + rw [QSystem.tensorPowCongr_congr_piTensor] + simp only [Equiv.apply_symm_apply] + have hcongr := Evolution.congr_evolvePure_congr (QSystem.tensorPowCongr qubit e) G + (PureState.piTensor fun i => qubitBasis (c (e i))) + rw [hinput, hcongr, hG, QSystem.tensorPowCongr_congr_piTensor] + +/-- **A single classical `mcNot` gate placed on the ambient register.** Given a control set +`S : Finset (Fin m)` and target `t ∉ S`, the multiply-controlled `NOT` gate `(S, t)` realised as a +genuine closed-system `Evolution (qubit ^⊗ₛ m)` on the whole ambient register. Built from the +gate-local `Evolution.placedMcCtrlX` (`Cᵏ(X)`, `k = |S|`) gathered onto the wires `(S, t)` by +`wireGatherPerm`, then cast from its gate-local register `qubit ^⊗ₛ (|S| + 1 + (m - (|S| + 1)))` +onto the ambient `qubit ^⊗ₛ m` by the register cast `QSystem.tensorPowCongr` (the two are +propositionally equal, `card_succ_add_sub`). For `|S| ≤ 2` this is a `Toffoli`/`CNOT`/`NOT` +addressed to the wires `(S, t)`; its computational-basis truth table is +`Evolution.placedMcNot_evolvePure_qubitBasis`. -/ +def Evolution.placedMcNot (S : Finset (Fin m)) (t : Fin m) (ht : t ∉ S) : + Evolution (qubit ^⊗ₛ m) := + (Evolution.placedMcCtrlX S.card (m - (S.card + 1)) + (wireGatherPerm (S.map (finCongr (card_succ_add_sub S t ht)).symm.toEmbedding) + ((finCongr (card_succ_add_sub S t ht)).symm t) + (by rw [Finset.card_map]) + (by + intro hmem + rw [Finset.mem_map] at hmem + obtain ⟨x, hx, hxe⟩ := hmem + rw [Equiv.coe_toEmbedding] at hxe + exact ht ((finCongr (card_succ_add_sub S t ht)).symm.injective hxe ▸ hx)))).congr + (QSystem.tensorPowCongr qubit (finCongr (card_succ_add_sub S t ht))) + +/-- **Computational-basis truth table of the ambient-register `mcNot` gate.** The placed gate +`Evolution.placedMcNot S t ht` acts on every computational product basis state `|⨂ᵢ c i⟩` exactly as +the classical multiply-controlled `NOT` `Concrete.mcNot S t` on the ambient register `Fin m`: +`placedMcNot S t ht |⨂ᵢ c i⟩ = |⨂ᵢ (mcNot S t c) i⟩`. So the placed quantum gate **is** the +reversible bit-string permutation flipping wire `t` iff every control in `S` is set — the +wire-addressed `Toffoli`/`CNOT`/`NOT` truth table on the shared circuit register. Proved by feeding +the gate-local truth table (`placedMcCtrlX_wireGather_evolvePure_qubitBasis`, with classical +action `Concrete.mcNot (S.map e.symm.toEmbedding) (e.symm t)`) through the register-cast dictionary +`Evolution.congr_tensorPowCongr_evolvePure_qubitBasis`, then collapsing the conjugated action to +`Concrete.mcNot S t` by the `mcNot` relabelling naturality `Concrete.mcNot_map_equiv`. -/ +theorem Evolution.placedMcNot_evolvePure_qubitBasis (S : Finset (Fin m)) (t : Fin m) (ht : t ∉ S) + (c : Fin m → Fin 2) : + (Evolution.placedMcNot S t ht).evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => qubitBasis (Concrete.mcNot S t c i) := by + rw [Evolution.placedMcNot, + Evolution.congr_tensorPowCongr_evolvePure_qubitBasis _ (finCongr (card_succ_add_sub S t ht)) _ + (placedMcCtrlX_wireGather_evolvePure_qubitBasis _ _ _ _)] + refine congrArg PureState.piTensor ?_ + funext j + refine congrArg qubitBasis ?_ + rw [Concrete.mcNot_map_equiv] + simp only [Equiv.symm_symm, Equiv.apply_symm_apply] + +/-- **A whole classical `mcNot` circuit realised as an `Evolution`.** For any classical circuit +`gs : List (McNotGate m)` whose every gate `(Sᵢ, tᵢ)` has target off its controls (`tᵢ ∉ Sᵢ`), +there is a single closed-system `Evolution` on the ambient qubit register `qubit ^⊗ₛ m` — the +composite (under `Evolution.comp`) of the per-gate `Evolution.placedMcNot` gates — acting on every +computational product basis state `|⨂ᵢ c i⟩` exactly as the classical circuit denotation +`Concrete.mcNotDenote gs`: `U |⨂ᵢ c i⟩ = |⨂ᵢ (mcNotDenote gs c) i⟩`. + +Applied to the circuit `Concrete.exists_mcNotCircuit` produces for `Cⁿ(X)` (whose gates each have +`≤ 2` controls, so are genuine `Toffoli`/`CNOT`/`NOT` gates), this exhibits `Cⁿ(X)` — on the +dirty-borrow register `Fin m` with `m ≥ n + 2` — as a genuine `Evolution` circuit built from placed +two-control gates, closing the gap between the classical bit-string circuit and a bona fide +closed-system gate sequence. Proved by induction on `gs`: the empty circuit is `Evolution.id`, and +`g :: gs` is `Evolution.placedMcNot g.1 g.2 · |>.comp` the inductive gate, tracked through +`Evolution.evolvePure_comp` and the per-gate truth table +`Evolution.placedMcNot_evolvePure_qubitBasis`. -/ +theorem exists_mcNotCircuitEvolution (gs : List (Concrete.McNotGate m)) + (hgs : ∀ g ∈ gs, g.2 ∉ g.1) : + ∃ U : Evolution (qubit ^⊗ₛ m), ∀ c : Fin m → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i) := by + induction gs with + | nil => + refine ⟨Evolution.id, fun c => ?_⟩ + let ψ0 : PureState (qubit ^⊗ₛ m) := PureState.piTensor fun i => qubitBasis (c i) + change Evolution.id.evolvePure ψ0 = _ + rw [Evolution.id_evolvePure] + simp only [Concrete.mcNotDenote_nil] + rfl + | cons g gs IH => + obtain ⟨U, hU⟩ := IH fun g' hg' => hgs g' (List.mem_cons.2 (Or.inr hg')) + refine ⟨(Evolution.placedMcNot g.1 g.2 (hgs g (List.mem_cons.2 (Or.inl rfl)))).comp U, + fun c => ?_⟩ + let ψ0 : PureState (qubit ^⊗ₛ m) := PureState.piTensor fun i => qubitBasis (c i) + change ((Evolution.placedMcNot g.1 g.2 (hgs g (List.mem_cons.2 (Or.inl rfl)))).comp + U).evolvePure + ψ0 = _ + rw [Evolution.evolvePure_comp, hU, Evolution.placedMcNot_evolvePure_qubitBasis] + simp only [Concrete.mcNotDenote_cons] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Core/MeasuredQftOuterStep.lean b/LeanPool/AxQM/Core/MeasuredQftOuterStep.lean new file mode 100644 index 0000000000..1a7d9fec5f --- /dev/null +++ b/LeanPool/AxQM/Core/MeasuredQftOuterStep.lean @@ -0,0 +1,160 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerPeel +public import LeanPool.AxQM.Core.QtowerPermMeasurement +public import LeanPool.AxQM.Core.QtowerHeadIdleMeasurement +public import LeanPool.AxQM.Core.DeferredMeasurementReading + +/-! +# Deferrals of the measured-QFT outer induction (N&C Problem 5.2) + +The measured quantum Fourier transform (Problem 5.2) is assembled by an outer induction over the +tower depth `n`, processing the Figure 5.1 **head-layer peel** +`qftTowerEvolution (n+1) = Φ · qftTailEvolution n · qftHeadLayer n` +(`qftTowerEvolution_succ_eq_qftHeadLayer_peel`) one control wire at a time under the terminal +per-wire measurement `qtowerMeasurement (n+1)`. Here +`Φ = Evolution.qtowerPermWires (finRotate (n+2)).symm` is the cyclic wire permutation routing the +head-produced output wire into place, and `qftTailEvolution n = (qftTowerEvolution n).onRight qubit` +is the recursive tail QFT on wires `1, …, n+1`, idle on the head wire `0`. + +This file records **two steps of that induction** — the ones that need neither the +`Measurement.cascade` split (N&C Ex. 2.57) nor the head-cascade reading engine. They isolate, at the +scale of the whole transported QFT, the two Figure 5.1 gate shapes that carry **no genuine two-qubit +gate** into the semiclassical circuit: + +* **The final swap network becomes a classical relabelling of the outcome.** Peeling the head layer +exposes `Φ` as the *outermost* gate before the terminal measurement, and `Φ` — a + bare wire permutation — defers past that measurement + (`qtowerPermWires_measure_{bornProb,postMeasurement}`) as a pure relabelling `r ↦ r ∘ σ` of the + recorded bit-string, `σ = (finRotate (n+2)).symm`. So the measured `(n+1)`-tower QFT reduces to + the **swap-free** circuit `qftTailEvolution n · qftHeadLayer n` measured, with the outcome read + through `σ`: `qftTowerEvolution_succ_measure_swapDefer_{bornProb,postMeasurement}`. This is the + outermost step of the outer induction; it removes the Figure 5.1 swap layer from all further + reasoning, at no cost of a two-qubit gate. + +* **The recursive tail QFT slips past the head-wire measurement.** The terminal measurement's head + factor is `controlMeasurement (qtower n qubit)` (measure wire `0`; `qtowerMeasurement_succ`), and + the tail QFT `qftTailEvolution n = (qftTowerEvolution n).onRight qubit = 1 ⊗ Q` + leaves wire `0` idle, so it is invisible to the head statistics and defers past the head-wire + measurement unchanged: `qftTailEvolution_measure_head_{bornProb,postMeasurement}`. These are the + instances at `g = qftTowerEvolution n` of the head-idle disjoint-factor deferral + (`controlMeasurement_onRight_measure_head_{bornProb,postMeasurement}`), named for the exact gate + the outer induction pushes the head-wire measurement past before deferring the head control + cascade and recursing on the tail (`qtowerMeasurement n` after `qftTowerEvolution n`). + +Compare the sibling terminal-measurement deferrals in `AxQM/Core/QtowerPermMeasurement.lean` and +`AxQM/Core/QtowerHeadIdleMeasurement.lean`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-! ### The final swap network defers past the terminal measurement -/ + +/-- **Problem 5.2 (the swap network becomes a classical relabelling — outcome statistics).** +Measuring every wire (`qtowerMeasurement (n+1)`) after the whole transported quantum Fourier +transform `qftTowerEvolution (n+1)` gives, for every outcome bit-string `r`, the same Born +probability as measuring after only its **swap-free** part `qftTailEvolution n · qftHeadLayer n`, +with the outcome read through the cyclic relabelling `σ = (finRotate (n+2)).symm`: + + `p(r ∣ qftTowerEvolution (n+1)) = p(r ∘ σ ∣ qftTailEvolution n · qftHeadLayer n)`. + +The Figure 5.1 head-layer peel (`qftTowerEvolution_succ_eq_qftHeadLayer_peel`) +exposes the cyclic wire permutation `Φ = Evolution.qtowerPermWires σ` as the outermost gate; being a +bare relabelling of the wires it defers past the terminal measurement +(`qtowerPermWires_measure_bornProb`) as a relabelling `r ↦ r ∘ σ` of the recorded +bits — no two-qubit gate. This is the outermost step of the measured-QFT outer induction. -/ +theorem qftTowerEvolution_succ_measure_swapDefer_bornProb + (ρ : State (qtower (n + 1) qubit)) (r : Fin (n + 2) → Fin 2) : + (qtowerMeasurement (n + 1)).bornProb ((qftTowerEvolution (n + 1)).evolve ρ) r + = (qtowerMeasurement (n + 1)).bornProb + ((qftTailEvolution n).evolve ((qftHeadLayer n).evolve ρ)) + (fun j => r ((finRotate (n + 2)).symm j)) := by + rw [qftTowerEvolution_succ_evolve_peel, qtowerPermWires_measure_bornProb] + +/-- **Problem 5.2 (the swap network becomes a classical relabelling — post-measurement state).** +The state after the whole transported quantum Fourier transform `qftTowerEvolution (n+1)` and +*then* measuring every wire, at outcome `r`, equals the cyclic wire permutation +`Φ = Evolution.qtowerPermWires (finRotate (n+2)).symm` applied to the state obtained from the +**swap-free** circuit `qftTailEvolution n · qftHeadLayer n` measured at the relabelled outcome +`r ∘ σ`: + + `postMeas(qftTowerEvolution (n+1) · ρ, r) = Φ · postMeas(swap-free circuit · ρ, r ∘ σ)`. + +On the collapsed computational-basis state `Φ` is a pure wire relabelling: the Figure 5.1 swap layer +at the end of the quantum Fourier transform has become a relabelling of the classical measurement +record, no two-qubit gate. The head-layer peel followed by the swap deferral +(`qtowerPermWires_measure_postMeasurement`); the input state is carried across the peel by +`Measurement.postMeasurement_congr_state`. -/ +theorem qftTowerEvolution_succ_measure_swapDefer_postMeasurement + (ρ : State (qtower (n + 1) qubit)) (r : Fin (n + 2) → Fin 2) + (hp : (qtowerMeasurement (n + 1)).bornProb + ((qftTailEvolution n).evolve ((qftHeadLayer n).evolve ρ)) + (fun j => r ((finRotate (n + 2)).symm j)) ≠ 0) : + (qtowerMeasurement (n + 1)).postMeasurement ((qftTowerEvolution (n + 1)).evolve ρ) r + (by rw [qftTowerEvolution_succ_measure_swapDefer_bornProb]; exact hp) + = (Evolution.qtowerPermWires (finRotate (n + 2)).symm).evolve + ((qtowerMeasurement (n + 1)).postMeasurement + ((qftTailEvolution n).evolve ((qftHeadLayer n).evolve ρ)) + (fun j => r ((finRotate (n + 2)).symm j)) hp) := by + refine (Measurement.postMeasurement_congr_state (qtowerMeasurement (n + 1)) + (qftTowerEvolution_succ_evolve_peel ρ) _ + (by rw [qtowerPermWires_measure_bornProb]; exact hp)).trans ?_ + exact qtowerPermWires_measure_postMeasurement _ _ r hp + +/-! ### The recursive tail QFT slips past the head-wire measurement -/ + +/-- **Problem 5.2 (the tail QFT is invisible to the head-wire statistics).** Measuring the head wire +of the tower (`controlMeasurement (qtower n qubit)`, the head factor of the terminal measurement +`qtowerMeasurement (n+1)`) *after* the recursive tail QFT +`qftTailEvolution n = (qftTowerEvolution n).onRight qubit = 1 ⊗ Q` gives, for every outcome `i`, the +same Born probability as measuring the input `ρ` directly: the tail QFT leaves the head wire idle +and so is invisible to the head-wire measurement. The instance at `g = qftTowerEvolution n` of the +head-idle deferral (`controlMeasurement_onRight_measure_head_bornProb`); it is the +step the measured-QFT outer induction uses to push the head-wire measurement past the recursive tail +QFT before deferring the head control cascade and recursing on the tail. -/ +theorem qftTailEvolution_measure_head_bornProb + (ρ : State (qubit ⊗ qtower n qubit)) (i : Fin 2) : + (controlMeasurement (qtower n qubit)).bornProb ((qftTailEvolution n).evolve ρ) i + = (controlMeasurement (qtower n qubit)).bornProb ρ i := by + rw [qftTailEvolution] + exact controlMeasurement_onRight_measure_head_bornProb (qftTowerEvolution n) ρ i + +/-- **Problem 5.2 (the head-wire post-measurement state carries the tail QFT along).** The state +after measuring outcome `i` on the head wire of the tower, applied to the input evolved by the +recursive tail QFT `qftTailEvolution n = (qftTowerEvolution n).onRight qubit = 1 ⊗ Q`, equals that +same tail QFT applied to the state after measuring `ρ`: + + `postMeas((1 ⊗ Q) · ρ, i) = (1 ⊗ Q) · postMeas(ρ, i)`. + +The recursive tail QFT **defers past** the head-wire measurement unchanged, because it acts on the +tail factor, disjoint from the measured head wire. The instance at `g = qftTowerEvolution n` of the +head-idle deferral (`controlMeasurement_onRight_measure_head_postMeasurement`); the +outcome is equally possible after the tail QFT because the probabilities agree +(`qftTailEvolution_measure_head_bornProb`). It is the step the measured-QFT outer induction uses to +carry the recursive tail QFT past the head-wire measurement, exposing the tail as +`qtowerMeasurement n` after `qftTowerEvolution n` — the level-`n` measured QFT — for the +recursion. -/ +theorem qftTailEvolution_measure_head_postMeasurement + (ρ : State (qubit ⊗ qtower n qubit)) (i : Fin 2) + (hp : (controlMeasurement (qtower n qubit)).bornProb ρ i ≠ 0) : + (controlMeasurement (qtower n qubit)).postMeasurement ((qftTailEvolution n).evolve ρ) i + (by rw [qftTailEvolution_measure_head_bornProb]; exact hp) + = (qftTailEvolution n).evolve + ((controlMeasurement (qtower n qubit)).postMeasurement ρ i hp) := by + exact controlMeasurement_onRight_measure_head_postMeasurement (qftTowerEvolution n) ρ i hp + +end AxQM diff --git a/LeanPool/AxQM/Core/MeasurementChannel.lean b/LeanPool/AxQM/Core/MeasurementChannel.lean new file mode 100644 index 0000000000..5835e08391 --- /dev/null +++ b/LeanPool/AxQM/Core/MeasurementChannel.lean @@ -0,0 +1,170 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.ArakiLiebEqualityConditions +public import LeanPool.AxQM.Postulates.API.RelativeEntropy +public import LeanPool.AxQM.Postulates.API.QuditMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyDiagonal + +/-! +# AxQM — the POVM measurement outcome channel + +The **measurement outcome channel** of a measurement `m : Measurement ι S`: the map sending a +state `ρ` of `S` to the *diagonal Born-distribution state* + +`𝓜(ρ) = ∑_y p(y) |y⟩⟨y|`, with `p(y) = Tr(E_y ρ)` the Born probability of outcome `y`, + +on the classical outcome register, realised concretely as `qudit (Fintype.card ι)` with the +computational basis `|y⟩` (reindexed from `ι` by `Fintype.equivFin`, exactly as the Holevo +classical–quantum state `State.holevoCQState` realises its index register). This is the "measure and +record the outcome, forget the post-measurement state" channel — the non-selective measurement seen +as a preparation of a *classical* state whose eigenvalues are the outcome probabilities. + +It is the object the modern proof of the Holevo bound (Nielsen & Chuang, Theorem 12.1) processes: +the classical mutual information `H(X:Y)` between Alice's label `X` and Bob's outcome `Y` is +expressed through the quantum relative entropies `D(𝓜(ρₓ)‖𝓜(ρ))`, which the measurement +data-processing inequality bounds by `D(ρₓ‖ρ)`, summing to the Holevo χ. + +This file supplies the following pieces: + +* `Measurement.measState` — the outcome channel `𝓜` as a state of the outcome register; +* `Measurement.measState_def` — its unfolding to the diagonal Born mixture; +* `Measurement.bornProb_mix` — the Born rule is affine over mixtures, + `Tr(E_y ∑ₖ pₖ ρₖ) = ∑ₖ pₖ Tr(E_y ρₖ)` (the linearity the Holevo assembly consumes to identify the + outcome marginal with the Born distribution of the mixture); +* `Measurement.measState_mix` — the outcome channel is affine, `𝓜(∑ₖ pₖ ρₖ) = ∑ₖ pₖ 𝓜(ρₖ)` (the + channel linearity of the map, in place of an endomorphic `IsChannel`, which does not type-check + for a system-changing map `State S → State (qudit …)`); +* `Measurement.vonNeumannEntropy_measState` — `S(𝓜(ρ)) = H(Tr(E_· ρ))`, the diagonal Born state's + von Neumann entropy is the Shannon entropy of the Born distribution (the bridge to the classical + `H(X:Y)` in the alternate Holevo-bound proof, N&C Problem 12.1(3)); +* `Measurement.quantumRelativeEntropy_measState_eq_relativeEntropy_bornProb` — the relative entropy + of two outcome states is the classical KL divergence of their Born distributions, + `D(𝓜(ρ) ‖ 𝓜(σ)) = D_cl(p(·|ρ) ‖ p(·|σ))` (the outcome states are diagonal in the same + computational basis, so the Umegaki relative entropy collapses to the classical one). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- The **measurement outcome channel** `𝓜(ρ) = ∑_y Tr(E_y ρ) |y⟩⟨y|` of a measurement +`m : Measurement ι S`: the state of the classical outcome register `qudit (Fintype.card ι)` whose +`|y⟩⟨y|` weight is the Born probability of outcome `y`. The outcome kets are the computational basis +`quditBasis` reindexed from `ι` by `Fintype.equivFin`; the weights `m.bornProb ρ` form a probability +distribution (`bornProb_nonneg`, `sum_bornProb_eq_one`), so this is a genuine `State`. -/ +def measState (m : Measurement ι S) (ρ : State S) : State (qudit (Fintype.card ι)) := + State.mix (m.bornProb ρ) (m.bornProb_nonneg ρ) (m.sum_bornProb_eq_one ρ) + (fun i => (quditBasis (Fintype.equivFin ι i)).toState) + +/-- Unfolding lemma for the measurement outcome channel: `𝓜(ρ)` is the diagonal Born mixture +`∑_y p(y) |y⟩⟨y|` over the reindexed computational basis. -/ +theorem measState_def (m : Measurement ι S) (ρ : State S) : + m.measState ρ = State.mix (m.bornProb ρ) (m.bornProb_nonneg ρ) (m.sum_bornProb_eq_one ρ) + (fun i => (quditBasis (Fintype.equivFin ι i)).toState) := rfl + +/-- The **Born rule is affine over mixtures**: for an ensemble `{pₖ, ρₖ}` with mixture +`ρ = ∑ₖ pₖ ρₖ`, the outcome probability of `y` is the `p`-average of the component outcome +probabilities, `Tr(E_y ∑ₖ pₖ ρₖ) = ∑ₖ pₖ Tr(E_y ρₖ)`. Linearity of the trace and of operator +composition in the density operator, over the convex combination `State.mix_op`. -/ +theorem bornProb_mix {κ : Type*} [Fintype κ] (m : Measurement ι S) + (p : κ → ℝ) (hp : ∀ k, 0 ≤ p k) (hsum : ∑ k, p k = 1) (ρ : κ → State S) (i : ι) : + m.bornProb (State.mix p hp hsum ρ) i = ∑ k, p k * m.bornProb (ρ k) i := by + simp only [bornProb, POVM.toPMF_eq, State.mix_op, ContinuousLinearMap.comp_finsetSum, + ContinuousLinearMap.comp_smul, ContinuousLinearMap.toLinearMap_sum, + ContinuousLinearMap.toLinearMap_smul, + map_sum, map_smul, smul_eq_mul] + exact Finset.sum_congr rfl fun x _ => RCLike.re_ofReal_mul (p x) _ + +/-- The **measurement outcome channel is affine**: `𝓜(∑ₖ pₖ ρₖ) = ∑ₖ pₖ 𝓜(ρₖ)`. Both sides are +diagonal Born mixtures over the same outcome basis; the outcome weight of `y` matches on the two +sides by `bornProb_mix`. This is the channel-linearity of `measState` (an endomorphic `IsChannel` +does not type-check for the system-changing map `State S → State (qudit …)`). -/ +theorem measState_mix {κ : Type*} [Fintype κ] (m : Measurement ι S) + (p : κ → ℝ) (hp : ∀ k, 0 ≤ p k) (hsum : ∑ k, p k = 1) (ρ : κ → State S) : + m.measState (State.mix p hp hsum ρ) + = State.mix p hp hsum (fun k => m.measState (ρ k)) := by + apply State.ext + simp only [measState_def, State.mix_op, Finset.smul_sum, smul_smul] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← Finset.sum_smul, bornProb_mix] + simp only [Complex.ofReal_sum, Complex.ofReal_mul] + +/-- **The von Neumann entropy of the outcome channel is the Shannon entropy of the Born +distribution**: `S(𝓜(ρ)) = H(Tr(E_· ρ))`. Since `𝓜(ρ) = ∑_y Tr(E_y ρ) |y⟩⟨y|` is a mixture of the +orthonormal computational-basis kets `|y⟩` with weights `m.bornProb ρ`, its spectrum is exactly the +Born distribution, and the entropy of an orthonormal-support mixture is the Shannon entropy of the +weights (`State.vonNeumannEntropy_mix_toState_orthonormal`, with the register basis orthonormal by +`quditBasis_equivFin_orthonormal`). This is the bridge that turns the Holevo χ of the +measure-and-record ensemble into the classical mutual information `H(X:Y)` in the alternate Holevo +bound proof (Nielsen & Chuang Problem 12.1(3)). -/ +theorem vonNeumannEntropy_measState (m : Measurement ι S) (ρ : State S) : + (m.measState ρ).vonNeumannEntropy = Real.entropy (m.bornProb ρ) := by + rw [measState_def] + exact State.vonNeumannEntropy_mix_toState_orthonormal (m.bornProb ρ) (m.bornProb_nonneg ρ) + (m.sum_bornProb_eq_one ρ) (fun i => quditBasis (Fintype.equivFin ι i)) + (quditBasis_equivFin_orthonormal ι) + +/-- **The quantum relative entropy of two measurement-outcome states is the classical KL divergence +of their Born distributions**: for a measurement `m` and states `ρ, σ`, + +`D(𝓜(ρ) ‖ 𝓜(σ)) = D_cl(p(·|ρ) ‖ p(·|σ))`, with `p(y|ρ) = Tr(E_y ρ) = m.bornProb ρ y`. + +Both outcome states `𝓜(ρ), 𝓜(σ)` are diagonal in the *same* computational basis `|y⟩` of the +outcome register `qudit (Fintype.card ι)`, with eigenvalues the Born probabilities. Hence their +Umegaki relative entropy collapses to the classical relative entropy of the diagonals +(`ContinuousLinearMap.quantumRelativeEntropy_eq_relativeEntropy_of_isEigenbasis`). The equality is +unconditional — no faithfulness needed — since `Real.log 0 = 0` makes zero-probability outcomes +harmless on both sides. + +This is the identity (Nielsen & Chuang, Theorem 12.1) that rewrites the classical mutual +information `H(X:Y)` of the Holevo bound as a sum of quantum relative entropies of the outcome +states `D(𝓜(ρₓ) ‖ 𝓜(ρ))`, on which the measurement data-processing inequality then acts. -/ +theorem quantumRelativeEntropy_measState_eq_relativeEntropy_bornProb + (m : Measurement ι S) (ρ σ : State S) : + (m.measState ρ).quantumRelativeEntropy (m.measState σ) + = Real.relativeEntropy (m.bornProb ρ) (m.bornProb σ) := by + classical + -- The outcome kets `|y⟩` form an orthonormal basis of the outcome register, indexed by `ι`. + set b : OrthonormalBasis ι ℂ (qudit (Fintype.card ι)).space := + (quditOrthonormalBasis (Fintype.card ι)).reindex (Fintype.equivFin ι).symm with hb_def + have hb : ∀ i, b i = (quditBasis (Fintype.equivFin ι i)).vec := by + intro i + rw [hb_def, OrthonormalBasis.reindex_apply, Equiv.symm_symm, quditOrthonormalBasis_apply] + -- Each outcome state is diagonal in `b`, with the Born probability as eigenvalue. + have hdiag : ∀ (τ : State S) (j : ι), + (m.measState τ).op (b j) = (m.bornProb τ j : ℂ) • b j := by + intro τ j + rw [measState_def, State.mix_op, sum_apply, Finset.sum_eq_single j] + · rw [smul_apply, PureState.toState_op, ← hb j, + InnerProductSpace.rankOne_apply, orthonormal_iff_ite.mp b.orthonormal j j, ite_eq_left rfl, + one_smul] + · intro i _ hij + rw [smul_apply, PureState.toState_op, ← hb i, + InnerProductSpace.rankOne_apply, orthonormal_iff_ite.mp b.orthonormal i j, ite_eq_right hij, + zero_smul, smul_zero] + · intro h; exact absurd (Finset.mem_univ j) h + rw [State.quantumRelativeEntropy_def] + exact ContinuousLinearMap.quantumRelativeEntropy_eq_relativeEntropy_of_isEigenbasis b + (m.measState ρ).isDensity.isPositive.isSelfAdjoint + (m.measState σ).isDensity.isPositive.isSelfAdjoint (hdiag ρ) (hdiag σ) + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Core/MultiControlledNotBasis.lean b/LeanPool/AxQM/Core/MultiControlledNotBasis.lean new file mode 100644 index 0000000000..9391e336ad --- /dev/null +++ b/LeanPool/AxQM/Core/MultiControlledNotBasis.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledReduction +public import LeanPool.AxQM.Concrete.MultiControlledNot + +/-! +# The multiply-controlled `NOT` `Cⁿ(X)` acts on the computational basis as the classical `mcNot` +(N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for an `O(n²)`-gate no-work-qubit circuit of Toffoli, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. Every such gate is a +permutation of the computational basis, and `AxQM/Concrete/MultiControlledNot*.lean` builds +the whole construction — the dirty-borrow reduction `mcNot_union_borrow`, the recursive circuit +`exists_mcNotCircuit`, and its `O(n²)` gate-count bound `mcNotGateBound_isBigO_sq` — at the level of +the **classical** reversible model: bit-strings `Fin m → Fin 2` and the multiply-controlled `NOT` +`Concrete.mcNot S t`. + +This file is the **bridge** that ties that classical model to the quantum gate. +The quantum `Cⁿ(X)` is `mcCtrl n pauliXGate : Evolution (qtower n qubit)` — the Pauli-`X` gate +wrapped by `n` control qubits (`Core/MultiControlledReduction`), acting on the `(n+1)`-qubit +register `qtower n qubit` with **no work qubit**. We prove it acts on the computational basis +exactly as the classical `mcNot` with controls the first `n` wires and target the last: + +`(mcCtrl n pauliXGate).evolvePure (towerKet n b)` +` = towerKet n (mcNot (cnxControls n) (Fin.last n) b)` + (`mcCtrl_pauliXGate_evolvePure_towerKet`), + +where `towerKet n : (Fin (n+1) → Fin 2) → PureState (qtower n qubit)` is the `(n+1)`-qubit +computational basis (wire `0` the outermost control, wire `n` the target). So the *quantum* `Cⁿ(X)` +**is** the *classical* `Cⁿ(X)` on basis states: the reversible permutation whose `O(n²)` +no-work-qubit circuit the `Concrete/` development exhibits. The statement of Exercise 4.29 +is in [upstream `AxQM/NC/Ch4/Exercise4_29.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_29.lean). + +## The proof + +Induction on `n`, peeling one control at a time. `mcCtrl (n+1) E = C(mcCtrl n E)` and +`towerKet (n+1) b = |b 0⟩ ⊗ towerKet n (b ∘ succ)`, so the control-`|0⟩`/`|1⟩` action of +`controlledUnitary` (`controlledUnitary_evolvePure_ketZero` / `_ketOne`) splits the step: on +`b 0 = 0` the gate is the identity and `mcNot` fixes `b` (the outer control is unset, so +`ctrlBit = 0`); on `b 0 = 1` it recurses on the tail, matched to the tail `mcNot` by +`ctrlBit_cnxControls_succ` (the outer control being set makes the `(n+1)`-control condition collapse +to the `n`-control one on the shifted wires). The base case is `pauliXGate_evolvePure_qubitBasis` +(`X|i⟩ = |i+1⟩`) against `ctrlBit ∅ = 1` (the empty-control `NOT` always flips). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +open AxQM.Concrete + +/-- **The `(n+1)`-qubit computational basis** `towerKet n b` of the control register +`qtower n qubit = qubitⁿ ⊗ qubit`, indexed by a bit-string `b : Fin (n+1) → Fin 2` with wire `0` the +outermost control and wire `n` the target: the product state `|b 0⟩ ⊗ |b 1⟩ ⊗ … ⊗ |b n⟩`. -/ +def towerKet : (n : ℕ) → (Fin (n + 1) → Fin 2) → PureState (qtower n qubit) + | 0, b => qubitBasis (b 0) + | n + 1, b => (qubitBasis (b 0)).tmul (towerKet n (fun i => b i.succ)) + +/-- Base unfolding of `towerKet`: a single-qubit register is the basis state of its one wire. -/ +@[simp] theorem towerKet_zero (b : Fin 1 → Fin 2) : towerKet 0 b = qubitBasis (b 0) := rfl + +/-- Step unfolding of `towerKet`: peel the outermost control wire as a left tensor factor. -/ +theorem towerKet_succ (n : ℕ) (b : Fin (n + 2) → Fin 2) : + towerKet (n + 1) b = (qubitBasis (b 0)).tmul (towerKet n (fun i => b i.succ)) := rfl + +/-- **The `n` control wires** `{0, 1, …, n-1}` of the aligned `Cⁿ(X)` on `qtower n qubit`; the +target is the last wire `Fin.last n`. Defined so that +`cnxControls (n+1) = insert 0 (image succ (cnxControls n))` holds by `rfl`, matching how `mcCtrl` +adds one control on the left. -/ +def cnxControls : (n : ℕ) → Finset (Fin (n + 1)) + | 0 => ∅ + | n + 1 => insert 0 ((cnxControls n).image Fin.succ) + +/-- **Membership in the control-wire set** `cnxControls k` (`= {0, 1, …, k-1} ⊆ Fin (k+1)`): a wire +`j : Fin (k+1)` is a control iff its value is below `k` (equivalently, iff it is not the target +wire `Fin.last k`). Proved by induction on `k`, unfolding +`cnxControls (k+1) = insert 0 (image succ …)`. -/ +theorem mem_cnxControls {k : ℕ} (j : Fin (k + 1)) : j ∈ cnxControls k ↔ (j : ℕ) < k := by + induction k with + | zero => simp [cnxControls] + | succ k ih => + simp only [cnxControls, Finset.mem_insert, Finset.mem_image] + constructor + · rintro (rfl | ⟨a, ha, rfl⟩) + · simp + · have := (ih a).mp ha; simp only [Fin.val_succ]; omega + · intro hj + rcases Fin.eq_zero_or_eq_succ j with rfl | ⟨j', rfl⟩ + · exact Or.inl rfl + · refine Or.inr ⟨j', (ih j').mpr ?_, rfl⟩ + simp only [Fin.val_succ] at hj; omega + +/-- **The control-wire set as the image of `Fin.castSucc`.** The `k` front control wires +`cnxControls k` of `Fin (k+1)` are exactly the images `Fin.castSucc i` of the `k` wires +`i : Fin k` — the front `k` of the `k+1` wires. Lets an image over `cnxControls k` be reindexed to +an image over `Finset.univ : Finset (Fin k)`. -/ +theorem cnxControls_eq_image_castSucc (k : ℕ) : + cnxControls k = Finset.univ.image Fin.castSucc := by + ext j + simp only [Finset.mem_image, Finset.mem_univ, true_and, mem_cnxControls] + constructor + · intro hj; exact ⟨⟨(j : ℕ), hj⟩, by ext; simp⟩ + · rintro ⟨i, rfl⟩; simp only [Fin.val_castSucc]; exact i.isLt + +/-- The target wire `Fin.last n` is never one of the controls `cnxControls n` (so the aligned +`Cⁿ(X)` is a genuine `mcNot` with `target ∉ controls`). -/ +theorem last_notMem_cnxControls (n : ℕ) : Fin.last n ∉ cnxControls n := by + induction n with + | zero => simp [cnxControls] + | succ n ih => + simp only [cnxControls, Finset.mem_insert, Finset.mem_image, not_or] + refine ⟨Fin.last_pos.ne', ?_⟩ + rintro ⟨j, hj, hji⟩ + exact ih (by simpa using (Fin.succ_injective _ (hji.trans (Fin.succ_last n).symm)) ▸ hj) + +/-- The control bit of the `(n+1)`-control set factors through the outermost control `0` and the +`n`-control set on the shifted wires: every wire in `cnxControls (n+1)` is set iff wire `0` is set +and every wire in `cnxControls n` is set after shifting by `Fin.succ`. -/ +theorem ctrlBit_cnxControls_succ (n : ℕ) (b : Fin (n + 2) → Fin 2) : + ctrlBit (cnxControls (n + 1)) b + = if b 0 = 1 ∧ ∀ j ∈ cnxControls n, b j.succ = 1 then 1 else 0 := by + rw [cnxControls, ctrlBit_insert] + simp only [Finset.forall_mem_image] + +/-- **Nielsen & Chuang, Exercise 4.29 (the quantum–classical bridge).** The postulate-grounded +`n`-controlled `NOT` `mcCtrl n pauliXGate` acts on the `(n+1)`-qubit computational basis exactly as +the classical multiply-controlled `NOT` `Concrete.mcNot` with controls the first `n` wires +(`cnxControls n`) and target the last wire (`Fin.last n`): +`Cⁿ(X)|b⟩ = |mcNot (controls) (target) b⟩`. Thus the quantum `Cⁿ(X)` **is** the reversible +bit-string permutation whose `O(n²)` no-work-qubit circuit of Toffoli/`CNOT`/single-qubit gates the +`Concrete/MultiControlledNot*` development exhibits (`exists_mcNotCircuit`, +`mcNotGateBound_isBigO_sq`). + +Proof by induction on `n`, peeling one control at a time with `controlledUnitary`'s basis action. -/ +theorem mcCtrl_pauliXGate_evolvePure_towerKet (n : ℕ) (b : Fin (n + 1) → Fin 2) : + (mcCtrl n pauliXGate).evolvePure (towerKet n b) + = towerKet n (mcNot (cnxControls n) (Fin.last n) b) := by + induction n with + | zero => + -- Force the register `qtower 0 qubit` to reduce to `qubit` and `mcCtrl 0` to `pauliXGate`. + change pauliXGate.evolvePure (towerKet 0 b) = towerKet 0 (mcNot (cnxControls 0) (Fin.last 0) b) + rw [towerKet_zero, pauliXGate_evolvePure_qubitBasis, towerKet_zero] + -- `ctrlBit ∅ = 1`: the empty-control `NOT` always flips, matching `X|b 0⟩ = |b 0 + 1⟩`, so the + -- two basis indices agree definitionally. + congr 1 + | succ n ih => + -- Force `qtower (n+1) qubit ≡ qubit ⊗ qtower n qubit` and `mcCtrl (n+1) ≡ C(mcCtrl n)`, so the + -- control-branch lemmas below match on the `qubit ⊗ _` register. (A bare + -- `rw [mcCtrl_succ, towerKet_succ]` leaves `evolvePure`'s implicit *system* index as the + -- unreduced `qtower (n+1) qubit`, so `controlledUnitary_evolvePure_ketOne/ketZero` fail to + -- match — the displayed goal looks identical because that index is not printed.) + change (controlledUnitary (mcCtrl n pauliXGate)).evolvePure (towerKet (n + 1) b) + = towerKet (n + 1) (mcNot (cnxControls (n + 1)) (Fin.last (n + 1)) b) + rw [towerKet_succ] + by_cases h0 : b 0 = 1 + · -- Outer control set: the gate recurses on the tail; the `(n+1)`-control `mcNot` collapses to + -- the `n`-control one on the shifted wires. + rw [h0, controlledUnitary_evolvePure_ketOne, ih, towerKet_succ] + have key : mcNot (cnxControls n) (Fin.last n) (fun i => b i.succ) + = fun i => mcNot (cnxControls (n + 1)) (Fin.last (n + 1)) b i.succ := by + funext i + by_cases hi : i = Fin.last n + · subst hi + rw [mcNot_apply_self, Fin.succ_last, mcNot_apply_self, ctrlBit_cnxControls_succ, ctrlBit] + simp only [h0, true_and] + · have hne : i.succ ≠ Fin.last (n + 1) := by + rw [← Fin.succ_last]; exact fun h => hi (Fin.succ_injective _ h) + rw [mcNot_apply_of_ne _ _ _ hi, mcNot_apply_of_ne _ _ _ hne] + rw [key] + congr 1 + rw [mcNot_apply_of_ne _ _ _ Fin.last_pos.ne, h0] + · -- Outer control unset: the gate is the identity, and `mcNot` fixes `b`. + have h0' : b 0 = 0 := by omega + rw [h0', controlledUnitary_evolvePure_ketZero] + have hc : ctrlBit (cnxControls (n + 1)) b = 0 := by + rw [ctrlBit_cnxControls_succ]; simp [h0'] + rw [mcNot_of_ctrlBit_eq_zero _ _ _ hc, towerKet_succ, h0'] + +end AxQM diff --git a/LeanPool/AxQM/Core/MultiControlledReduction.lean b/LeanPool/AxQM/Core/MultiControlledReduction.lean new file mode 100644 index 0000000000..c2754c33af --- /dev/null +++ b/LeanPool/AxQM/Core/MultiControlledReduction.lean @@ -0,0 +1,269 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlBranchExt +public import LeanPool.AxQM.Postulates.API.ToffoliHadamard + +/-! +# The Barenco no-work-qubit reduction for multiply-controlled gates (Nielsen & Chuang §4.3) + +Nielsen & Chuang's Figure 4.8 builds the *doubly*-controlled gate `C²(V²)` from single-qubit +controlled `V`, `V†` and two `CNOT`s (Exercise 4.21). Exercise 4.28 asks for the analogous +construction of an `n`-control gate `Cⁿ(V²)` **using no work qubits**. The key step, generalising +Figure 4.8, expresses an `(m+1)`-control gate on `V²` in terms of + +* the single-qubit controlled `V` and `V†` (conditioned on the *innermost* control), +* two `m`-controlled `NOT`s (`Cᵐ(X)`, conditioned on the *outer* `m` controls, targeting the + innermost control), and +* one `m`-controlled `V` (`Cᵐ(V)`, conditioned on the outer `m` controls, targeting the target). + +Iterating the step (each level introduces a fresh square root `Vⱼ² = Vⱼ₋₁`) unfolds `Cⁿ(U)` all the +way down to single-qubit controlled gates and multiply-controlled `NOT`s — the no-work-qubit +construction of Exercise 4.28 (assembled, for `n = 5`, in [upstream `NC/Ch4/Exercise4_28.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_28.lean)). + +## What is formalised + +* `qtower n S` — the register `qubitⁿ ⊗ S`: `n` control qubits wrapping an inner system `S`. +* `mcCtrl n E` / `unCtrl n E` — `E : Evolution S` wrapped by `n` outer control qubits, **either** + each *controlling* `E` (`mcCtrl`, so `E` fires iff all `n` controls are `|1⟩` — the `Cⁿ` + multiplexer) **or** each *idle* (`unCtrl`, so `E` fires unconditionally). Their monoid laws + (`mcCtrl_comp`, `unCtrl_comp`, `unCtrl_id`) and the recursion identity `mcCtrl_succ`. +* `qtower_qubit_comm`, `controlledUnitary_cast`, `mcCtrl_succ_inner` — the register-reassociation + lemmas an *iterated* reduction needs: `qtower m (qubit ⊗ S) = qtower (m+1) S` and, on top of it, + the one honest cast `mcCtrl (k+1) E = mcCtrl k (C(E))` moving a control from outside `mcCtrl` into + a `controlledUnitary` (used by the `Cⁿ(U)`/`Cⁿ(X)` unfoldings of Exercises 4.28–4.30). +* `barencoReductionCircuit k Vg` — the right-hand side of the reduction on + `qtower k (qubit ⊗ M)` (inner = control ⊗ target-module `M`, `Vg : Evolution M`): the ordered + composition `Cᵏ(V) · Cᵏ(X) · C(V†) · Cᵏ(X) · C(V)`. +* `barencoTail k Vg` — the multiplexer-free tail `Cᵏ(X) · C(V†) · Cᵏ(X) · C(V)` of one layer, and + `barencoReductionCircuit_eq_mux_comp_tail` splitting a layer as its leading `Cᵏ(V)` multiplexer · + tail: the shape an iterated reduction (Ex. 4.28–4.30) stacks, each multiplexer expanded. +* `mcCtrl_controlledUnitary_sq` — **the reduction:** `Cᵏ⁺¹(V²) = barencoReductionCircuit k Vg`, + i.e. `mcCtrl k (C(V²)) = barencoReductionCircuit k V`. This is the heart of Exercises + 4.28–4.30; for `k = 1` it is exactly Figure 4.8 / Exercise 4.21. + +## Design notes + +* **Adjacency, not associators.** Taking the inner system as `qubit ⊗ M` (innermost control ⊗ + target-module) keeps every gate of the reduction adjacent: the single-qubit `C(V)`/`C(V†)` live on + the inner `qubit ⊗ M`, the `Cᵏ(X)` flips the innermost control via `pauliXGate.onLeft M`, and the + `Cᵏ(V)` skips the innermost control via `Vg.onRight qubit` — all placed by `mcCtrl`/`unCtrl`, so + no associator or `SWAP` is ever needed. Letting `M` be an *arbitrary* system (not just one qubit) + is what lets the caller recurse: the `Cᵏ(V)` term is itself a `mcCtrl` of a `V.onRight …`, a + square, ready for the next reduction with a fresh root. +* **Proof of the reduction (induction on `k`).** `controlBranch_evolution_ext` peels the outer + controls one at a time. The base `k = 0` is the two-qubit Figure-4.8 identity (casework on the one + control, with `V† V = 1`, `V V† = 1`, `V(Vψ) = V²ψ`). The step conditions everything on the new + outer qubit: with the qubit `|0⟩` the two `mᵏ` multiplexers are idle and the two idle `C(V†)`, + `C(V)` cancel (`V† V = 1`, via `unCtrl_comp` / `controlledUnitary_comp` / `controlledUnitary_id`); + with the qubit `|1⟩` every factor acts by its `mcCtrl k`/`unCtrl k` version and the goal is + exactly the inductive hypothesis. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S M : QSystem} + +/-! ### The control register and its two wrappings -/ + +/-- **The control register** `qtower n S = qubitⁿ ⊗ S`: `n` control qubits (added on the left, one +at a time) wrapping an inner system `S`. -/ +def qtower : ℕ → QSystem → QSystem + | 0, S => S + | (n + 1), S => qubit ⊗ qtower n S + +/-- **The `n`-controlled multiplexer** `mcCtrl n E = Cⁿ(E)`: the gate `E : Evolution S` wrapped by +`n` control qubits, applied to `S` exactly when *all* `n` controls are `|1⟩`. Built by iterating the +single control `controlledUnitary`; `mcCtrl 0 E = E` and `mcCtrl (n+1) E = C(mcCtrl n E)`. -/ +def mcCtrl : (n : ℕ) → Evolution S → Evolution (qtower n S) + | 0, E => E + | (n + 1), E => controlledUnitary (mcCtrl n E) + +/-- **The idle wrapping** `unCtrl n E`: the gate `E : Evolution S` wrapped by `n` *idle* qubits, so +`E` is applied to `S` regardless of the `n` qubits. Built by iterating the idle wrap +`Evolution.onRight`; `unCtrl 0 E = E` and `unCtrl (n+1) E` wraps `unCtrl n E` with an idle qubit. -/ +def unCtrl : (n : ℕ) → Evolution S → Evolution (qtower n S) + | 0, E => E + | (n + 1), E => (unCtrl n E).onRight qubit + +@[simp] theorem mcCtrl_zero (E : Evolution S) : mcCtrl 0 E = E := rfl + +@[simp] theorem mcCtrl_succ (n : ℕ) (E : Evolution S) : + mcCtrl (n + 1) E = controlledUnitary (mcCtrl n E) := rfl + +@[simp] theorem unCtrl_zero (E : Evolution S) : unCtrl 0 E = E := rfl + +@[simp] theorem unCtrl_succ (n : ℕ) (E : Evolution S) : + unCtrl (n + 1) E = (unCtrl n E).onRight qubit := rfl + +/-! ### Monoid laws of the wrappings -/ + +/-- **`Cⁿ` is a homomorphism:** `Cⁿ(A) Cⁿ(B) = Cⁿ(A B)` — stacking two `n`-controlled gates sharing +the controls is the `n`-controlled gate of the composite (`controlledUnitary_comp` per level). -/ +theorem mcCtrl_comp (n : ℕ) (A B : Evolution S) : + (mcCtrl n A).comp (mcCtrl n B) = mcCtrl n (A.comp B) := by + induction n with + | zero => rfl + | succ n ih => + simp only [mcCtrl_succ] + exact (controlledUnitary_comp _ _).trans (congrArg controlledUnitary ih) + +/-- **The idle wrapping is a homomorphism:** `unCtrl n A · unCtrl n B = unCtrl n (A B)`. -/ +theorem unCtrl_comp (n : ℕ) (A B : Evolution S) : + (unCtrl n A).comp (unCtrl n B) = unCtrl n (A.comp B) := by + induction n with + | zero => rfl + | succ n ih => + simp only [unCtrl_succ] + exact (Evolution.onRight_comp _ _ (unCtrl n A) (unCtrl n B)).trans + (congrArg (Evolution.onRight · qubit) ih) + +/-- **The idle wrapping preserves the identity:** `unCtrl n 1 = 1`. -/ +theorem unCtrl_id (n : ℕ) : unCtrl n (Evolution.id : Evolution S) = Evolution.id := by + induction n with + | zero => rfl + | succ n ih => + simp only [unCtrl_succ] + rw [ih] + exact Evolution.id_onRight qubit (qtower n S) + +/-! ### Register reassociation + +These identify the tower registers that an *iterated* Barenco reduction (the `Cⁿ(U)` no-work-qubit +unfoldings of Exercises 4.28–4.30) walks through: peeling a control turns the target module `M` into +`qubit ⊗ M`, so the surviving multiplexer lives on `qtower k (qubit ⊗ (qubit ⊗ M))` while its parent +lives on `qtower (k+1) (qubit ⊗ M)` — the same register, but only propositionally (`qtower` recurses +on its first argument, so it does not unfold for symbolic `k`). -/ + +/-- **Pushing a control from the target into the tower.** `qtower m (qubit ⊗ S) = qtower (m+1) S`: +both are the right-nested tower of `m + 1` control qubits over `S`. This is *not* definitional +(`qtower` recurses on its first argument, so `qtower m (qubit ⊗ S)` does not unfold for symbolic +`m`); it is the propositional equality that lets an iterated Barenco reduction move a peeled control +from the target module back out to a fresh control qubit. -/ +theorem qtower_qubit_comm (m : ℕ) (S : QSystem) : + qtower m (qubit ⊗ S) = qtower (m + 1) S := by + induction m with + | zero => rfl + | succ k ih => exact congrArg (qubit ⊗ ·) ih + +/-- Transporting a gate along a system equality commutes with adding a control: casting the target +system of `x` and then controlling equals controlling and then casting the (control-wrapped) target. +The bookkeeping lemma behind `mcCtrl_succ_inner`. -/ +theorem controlledUnitary_cast {R₁ R₂ : QSystem} (hq : R₁ = R₂) (x : Evolution R₁) : + controlledUnitary (cast (congrArg Evolution hq) x) + = cast (congrArg Evolution (congrArg (qubit ⊗ ·) hq)) (controlledUnitary x) := by + subst hq + rfl + +/-- **Moving a control from outside `mcCtrl` into a `controlledUnitary`.** The `(k+1)`-fold +multiplexer of `E` equals the `k`-fold multiplexer of the *single*-controlled `C(E)`, once the +registers are identified by `qtower_qubit_comm`. Both sides are `C^(k+1)(E)`; the equality is stated +with the honest cast because the two presentations live on the propositionally-equal registers +`qtower (k+1) S` and `qtower k (qubit ⊗ S)`. This is the one cast an iterated no-work-qubit +reduction (Exercises 4.28–4.30) needs to re-expose a peeled multiplexer as a square for the next +step. -/ +theorem mcCtrl_succ_inner (k : ℕ) (E : Evolution S) : + mcCtrl (k + 1) E + = cast (congrArg Evolution (qtower_qubit_comm k S)) (mcCtrl k (controlledUnitary E)) := by + induction k with + | zero => rfl + | succ k ih => + rw [mcCtrl_succ, ih, mcCtrl_succ] + exact controlledUnitary_cast (qtower_qubit_comm k S) (mcCtrl k (controlledUnitary E)) + +/-! ### The reduction -/ + +/-- **The Figure-4.8 reduction circuit** for `Cᵏ⁺¹(V²)` on `qtower k (qubit ⊗ M)` (inner = innermost +control ⊗ target-module `M`, with `Vg : Evolution M`). Reading right to left (the rightmost acts +first), the five gates are: `C(V)` on the inner control; `Cᵏ(X)` on the outer `k` controls targeting +the inner control (`pauliXGate.onLeft M`); `C(V†)` on the inner control; `Cᵏ(X)` again; and `Cᵏ(V)` +on the outer `k` controls targeting the target-module, skipping the inner control (`Vg.onRight +qubit`). The single-qubit `C(V)`/`C(V†)` are idle over the outer controls (`unCtrl`); the `Cᵏ(X)`, +`Cᵏ(V)` are controlled by them (`mcCtrl`). -/ +def barencoReductionCircuit (k : ℕ) (Vg : Evolution M) : Evolution (qtower k (qubit ⊗ M)) := + (mcCtrl k (Vg.onRight qubit)).comp + ((mcCtrl k (pauliXGate.onLeft M)).comp + ((unCtrl k (controlledUnitary Vg.adjoint)).comp + ((mcCtrl k (pauliXGate.onLeft M)).comp + (unCtrl k (controlledUnitary Vg))))) + +/-- **The tail of one Barenco reduction layer** on `qtower k (qubit ⊗ M)`: everything of +`barencoReductionCircuit k Vg` *after* the leading `Cᵏ(V)` multiplexer, i.e. +`Cᵏ(X) · C(V†) · Cᵏ(X) · C(V)` — two multiply-controlled `NOT`s (`mcCtrl k (pauliXGate.onLeft M)`) +and the two idle single-qubit-controlled gates `C(V†)`, `C(V)` (`unCtrl k (controlledUnitary …)`). +Factoring the tail out lets an iterated reduction (the `Cⁿ(U)` no-work-qubit unfoldings of Exercises +4.28–4.30) be written as a nested stack of layers whose leading multiplexers have been recursively +expanded, matching the reduction proof exactly. -/ +def barencoTail (k : ℕ) (Vg : Evolution M) : Evolution (qtower k (qubit ⊗ M)) := + (mcCtrl k (pauliXGate.onLeft M)).comp + ((unCtrl k (controlledUnitary Vg.adjoint)).comp + ((mcCtrl k (pauliXGate.onLeft M)).comp + (unCtrl k (controlledUnitary Vg)))) + +/-- One Barenco layer splits as its leading multiplexer `Cᵏ(V)` (`mcCtrl k (Vg.onRight qubit)`) +composed with its tail (`barencoTail k Vg`). Definitional. -/ +theorem barencoReductionCircuit_eq_mux_comp_tail (k : ℕ) (Vg : Evolution M) : + barencoReductionCircuit k Vg = (mcCtrl k (Vg.onRight qubit)).comp (barencoTail k Vg) := + rfl + +/-- **Nielsen & Chuang, Exercise 4.28 (the reduction step).** The `(k+1)`-control gate on `V²` +decomposes, with **no work qubits**, into single-qubit controlled `V`/`V†` and multiply-controlled +gates: +`Cᵏ⁺¹(V²) = Cᵏ(V) · Cᵏ(X) · C(V†) · Cᵏ(X) · C(V)`, +i.e. `mcCtrl k (controlledUnitary (V·V)) = barencoReductionCircuit k V`. `V†` is the genuine adjoint +gate `V.adjoint`, and `M` (the target-module) is arbitrary, so a caller reduces the `Cᵏ(V)` term +again with a fresh square root of `V`. For `k = 1` this is exactly Figure 4.8 (Exercise 4.21). + +Proved by induction on `k` via `controlBranch_evolution_ext`. Base `k = 0`: the two-qubit identity +by casework on the single control (`V† V = 1`, `V V† = 1`, `V(Vψ) = V²ψ`). Step: casework on the new +outer control — `|0⟩` collapses (the idle `C(V†) C(V) = C(V† V) = 1` cancels, the multiplexers +idle), `|1⟩` reduces to the inductive hypothesis. -/ +theorem mcCtrl_controlledUnitary_sq (k : ℕ) (Vg : Evolution M) : + mcCtrl k (controlledUnitary (Vg.comp Vg)) = barencoReductionCircuit k Vg := by + induction k with + | zero => + apply controlBranch_evolution_ext + intro i ψ + -- `qtower` normalises the register type so `evolvePure_comp` can spread the composition. + simp only [barencoReductionCircuit, mcCtrl_zero, unCtrl_zero, qtower, Evolution.evolvePure_comp] + fin_cases i <;> + simp only [Fin.mk_zero, Fin.mk_one, Fin.isValue, + controlledUnitary_evolvePure_ketZero, controlledUnitary_evolvePure_ketOne, + Evolution.onLeft_evolvePure, Evolution.onRight_evolvePure, + pauliXGate_evolvePure_qubitBasis, Fin.reduceAdd, + Evolution.evolvePure_adjoint_evolvePure', Evolution.evolvePure_comp] + | succ k ih => + -- The two idle single-qubit gates cancel when the new outer control is `|0⟩`. + have hcancel : (unCtrl k (controlledUnitary Vg.adjoint)).comp + (unCtrl k (controlledUnitary Vg)) = Evolution.id := by + rw [unCtrl_comp, controlledUnitary_comp, Evolution.adjoint_comp_self', controlledUnitary_id, + unCtrl_id] + apply controlBranch_evolution_ext + intro i ψ + fin_cases i + · -- outer control `|0⟩`: everything collapses to the identity. + simp only [barencoReductionCircuit, qtower, mcCtrl_succ, unCtrl_succ, + Evolution.evolvePure_comp, Fin.mk_zero, Fin.isValue, controlledUnitary_evolvePure_ketZero, + Evolution.onRight_evolvePure] + rw [← Evolution.evolvePure_comp, hcancel, Evolution.id_evolvePure] + · -- outer control `|1⟩`: reduces to the inductive hypothesis. + simp only [barencoReductionCircuit, qtower, mcCtrl_succ, unCtrl_succ, + Evolution.evolvePure_comp, Fin.mk_one, Fin.isValue, controlledUnitary_evolvePure_ketOne, + Evolution.onRight_evolvePure] + rw [ih] + simp only [barencoReductionCircuit, Evolution.evolvePure_comp] + +end AxQM diff --git a/LeanPool/AxQM/Core/MultiControlledTowerAction.lean b/LeanPool/AxQM/Core/MultiControlledTowerAction.lean new file mode 100644 index 0000000000..ce651980d0 --- /dev/null +++ b/LeanPool/AxQM/Core/MultiControlledTowerAction.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledReduction + +/-! +# The multiplexer `Cᵏ(G)` acts on a control tower as `G` gated on all controls (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The `n+1`-wire construction is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`): a nested stack of +`barencoTail` layers built from single-qubit-controlled `√X` gates and **multiply-controlled `NOT` +blocks** `Cᵏ(X) = mcCtrl k (pauliXGate.onLeft M)` (`Core/MultiControlledReduction.barencoTail`), +each acting on `qtower k (qubit ⊗ M)` — `k` outer control qubits, one `X`-target head of the +inner `qubit ⊗ M`, and the idle target-module `M`. Bottoming those blocks to genuine `Toffoli`s is +the other distinctive content of the exercise. + +This file reads off the **computational-basis action of one such block** — the quantum side of the +per-block reduction. The basis bridge `mcCtrl_pauliXGate_evolvePure_towerKet` +(`Core/MultiControlledNotBasis`) handles the *aligned* gate `mcCtrl n pauliXGate` whose +target is the *innermost* wire (target module trivial). A `barencoNCircuit` block instead carries a +whole idle target module `M`, so its action must be stated with `M` present. + +## What is formalised + +* `ctrlTower k c ρ` — the **control-tower input state** on `qtower k R`: `k` computational control + qubits `|c 0⟩ ⊗ … ⊗ |c (k-1)⟩` prepended (one per control wire) to an arbitrary base pure state + `ρ : PureState R` on the inner system `R`. (For `R = qubit` this specialises to the aligned tower + ket `towerKet`; here `R = qubit ⊗ M` carries the block's target-plus-idle module.) +* `mcCtrl_evolvePure_ctrlTower` — the **general multiplexer truth table**: for *any* inner gate + `G : Evolution R`, the `k`-controlled `Cᵏ(G)` acts on `ctrlTower k c ρ` by applying `G` to the + base state exactly when *all* `k` controls are set, and as the identity otherwise: + `Cᵏ(G) (|c⟩ ⊗ ρ) = |c⟩ ⊗ (if ∀ j, c j = 1 then G ρ else ρ)`. + This is the meaning of "the multiplexer fires iff every control is `|1⟩`", read + on product inputs; it holds for an arbitrary gate on an arbitrary base system. +* `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` — its **specialisation to a `barencoNCircuit` + block**: `mcCtrl k (pauliXGate.onLeft M)` flips the target qubit `|i⟩ ↦ |i + 1⟩` iff all `k` + controls are set and leaves the idle module `M` (state `φ`) untouched: + `Cᵏ(X) (|c⟩ ⊗ |i⟩ ⊗ φ) = |c⟩ ⊗ |i + (if ∀ j, c j = 1 then 1 else 0)⟩ ⊗ φ`. + So each internal `Cᵏ(X)` block of the no-work-qubit `Cⁿ(X)` circuit is, on the computational + basis, exactly the classical multiply-controlled `NOT` on its `k` control wires and target wire — + the reversible permutation whose bounded `Toffoli` circuit is exhibited in + `AxQM/Core/McNotCircuitDecomposition.lean`. Matching this action to that circuit (through the + register bridge) is the block reduction. + +## The proof + +`mcCtrl_evolvePure_ctrlTower` is an induction on `k` peeling one control at a time, exactly the +shape of the aligned bridge `mcCtrl_pauliXGate_evolvePure_towerKet`. +`mcCtrl (k+1) G = C(mcCtrl k G)` and +`ctrlTower (k+1) c ρ = |c 0⟩ ⊗ ctrlTower k (c ∘ succ) ρ`, so the control-`|0⟩`/`|1⟩` action of +`controlledUnitary` (`controlledUnitary_evolvePure_ketZero` / `_ketOne`) splits the step: on +`c 0 = 0` the gate is the identity and the "all controls set" guard is false; on `c 0 = 1` it +recurses on the tail via the inductive hypothesis, and `Fin.forall_fin_succ` collapses the +`(k+1)`-control guard to the `k`-control one. The base `k = 0` is `mcCtrl 0 G = G` against the +vacuously-true empty guard. The specialisation then feeds `Evolution.onLeft_evolvePure` +(`(X ⊗ 1)(ψ ⊗ φ) = Xψ ⊗ φ`) and `pauliXGate_evolvePure_qubitBasis` (`X|i⟩ = |i+1⟩`) into the guard's +two branches. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {R M : QSystem} + +/-- **The control-tower input state** `ctrlTower k c ρ` on `qtower k R`: the `k` computational +control qubits `|c 0⟩ ⊗ |c 1⟩ ⊗ … ⊗ |c (k-1)⟩` (wire `0` outermost) prepended one at a time to a +base pure state `ρ : PureState R` on the inner system. This is the product input on which the +multiplexer `mcCtrl k G` reads out its controlled action (`mcCtrl_evolvePure_ctrlTower`); for +`R = qubit` it is the aligned computational tower ket. -/ +def ctrlTower : (k : ℕ) → (Fin k → Fin 2) → PureState R → PureState (qtower k R) + | 0, _, ρ => ρ + | k + 1, c, ρ => (qubitBasis (c 0)).tmul (ctrlTower k (fun i => c i.succ) ρ) + +/-- Base unfolding of `ctrlTower`: with no control qubits the tower is the base state itself. -/ +@[simp] theorem ctrlTower_zero (c : Fin 0 → Fin 2) (ρ : PureState R) : + ctrlTower 0 c ρ = ρ := rfl + +/-- Step unfolding of `ctrlTower`: peel the outermost control wire `|c 0⟩` as a left tensor factor, +leaving the `k`-control tower on the shifted controls. -/ +theorem ctrlTower_succ (k : ℕ) (c : Fin (k + 1) → Fin 2) (ρ : PureState R) : + ctrlTower (k + 1) c ρ = (qubitBasis (c 0)).tmul (ctrlTower k (fun i => c i.succ) ρ) := rfl + +/-- **The multiplexer truth table.** For any inner gate `G : Evolution R`, the `k`-controlled gate +`Cᵏ(G) = mcCtrl k G` acts on a control-tower input `ctrlTower k c ρ` by applying `G` to the base +state `ρ` when **every** control is set (`∀ j, c j = 1`) and as the identity otherwise: + +`Cᵏ(G) (|c 0⟩ ⊗ … ⊗ |c (k-1)⟩ ⊗ ρ) = |c 0⟩ ⊗ … ⊗ |c (k-1)⟩ ⊗ (if ∀ j, c j = 1 then G ρ else ρ)`. + +This is the statement that the multiplexer fires iff all controls are `|1⟩`, read on product +inputs, for an arbitrary gate `G` on an arbitrary base system `R`. Proved by +induction on `k`, peeling one control with `controlledUnitary`'s `|0⟩`/`|1⟩` basis action and +collapsing the `(k+1)`-control guard to the `k`-control one via `Fin.forall_fin_succ`. -/ +theorem mcCtrl_evolvePure_ctrlTower (G : Evolution R) : + ∀ (k : ℕ) (c : Fin k → Fin 2) (ρ : PureState R), + (mcCtrl k G).evolvePure (ctrlTower k c ρ) + = ctrlTower k c (if ∀ j, c j = 1 then G.evolvePure ρ else ρ) := by + intro k + induction k with + | zero => + intro c ρ + -- `mcCtrl 0 G ≡ G` and `ctrlTower 0 c ρ ≡ ρ`; the empty-control guard `∀ j : Fin 0, _` is true. + change G.evolvePure ρ = ctrlTower 0 c _ + rw [ctrlTower_zero, ite_eq_left (fun j => j.elim0)] + | succ k ih => + intro c ρ + -- Force `mcCtrl (k+1) G ≡ C(mcCtrl k G)` and the register `qtower (k+1) R ≡ qubit ⊗ qtower k R` + -- so the control-branch lemmas match (cf. `mcCtrl_pauliXGate_evolvePure_towerKet`). + change (controlledUnitary (mcCtrl k G)).evolvePure (ctrlTower (k + 1) c ρ) = _ + rw [ctrlTower_succ] + by_cases h0 : c 0 = 1 + · rw [h0, controlledUnitary_evolvePure_ketOne, ih, ctrlTower_succ, h0] + congr 2 + by_cases hrest : ∀ j : Fin k, c j.succ = 1 + · rw [ite_eq_left hrest, ite_eq_left (Fin.forall_fin_succ.2 ⟨h0, hrest⟩)] + · rw [ite_eq_right hrest, ite_eq_right (fun h => hrest fun j : Fin k => h j.succ)] + · have h0' : c 0 = 0 := by omega + rw [h0', controlledUnitary_evolvePure_ketZero, ctrlTower_succ, h0', + ite_eq_right (fun h => absurd ((h 0).symm.trans h0') (by decide))] + +/-- **A `barencoNCircuit` internal block acts as its classical multiply-controlled `NOT`.** The +block `mcCtrl k (pauliXGate.onLeft M)` (`Cᵏ(X)` with `k` controls, the `X`-target the head of the +inner `qubit ⊗ M`, and the target module `M` idle — the shape of every `Cᵏ(X)` block of the +no-work-qubit `Cⁿ(X)` circuit, `barencoTail`) acts on a control-tower input whose base is a target +basis state tensored with an idle module state `φ : PureState M`: it flips the target +`|i⟩ ↦ |i + 1⟩` when all `k` controls are set and leaves the controls and the idle module `φ` alone: + +`Cᵏ(X) (|c⟩ ⊗ |i⟩ ⊗ φ) = |c⟩ ⊗ |i + (if ∀ j, c j = 1 then 1 else 0)⟩ ⊗ φ`. + +So on the computational basis each internal `Cᵏ(X)` block **is** the classical multiply-controlled +`NOT` on its `k` control wires and its target wire — the reversible permutation whose bounded +`O(k²)` `Toffoli`/`CNOT`/`NOT` circuit is exhibited in `AxQM/Core/McNotCircuitDecomposition.lean`. +Proved by feeding +`Evolution.onLeft_evolvePure` (`(X ⊗ 1)(ψ ⊗ φ) = Xψ ⊗ φ`) and `pauliXGate_evolvePure_qubitBasis` +(`X|i⟩ = |i+1⟩`) into the two guard branches of `mcCtrl_evolvePure_ctrlTower`. -/ +theorem mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower (k : ℕ) (c : Fin k → Fin 2) (i : Fin 2) + (φ : PureState M) : + (mcCtrl k (pauliXGate.onLeft M)).evolvePure (ctrlTower k c ((qubitBasis i).tmul φ)) + = ctrlTower k c ((qubitBasis (i + if ∀ j, c j = 1 then 1 else 0)).tmul φ) := by + rw [mcCtrl_evolvePure_ctrlTower] + by_cases h : ∀ j, c j = 1 + · rw [ite_eq_left h, ite_eq_left h, Evolution.onLeft_evolvePure, pauliXGate_evolvePure_qubitBasis] + · rw [ite_eq_right h, ite_eq_right h, add_zero] + +end AxQM diff --git a/LeanPool/AxQM/Core/NmrTomographyReconstruction.lean b/LeanPool/AxQM/Core/NmrTomographyReconstruction.lean new file mode 100644 index 0000000000..be75af1da4 --- /dev/null +++ b/LeanPool/AxQM/Core/NmrTomographyReconstruction.lean @@ -0,0 +1,86 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.PauliTomographyExpectation +public import LeanPool.AxQM.Concrete.NmrTomographyExperimentCount + +/-! +# AxQM.Core — state reconstruction from a complete NMR tomography scheme (N&C §7.7.4) + +The **grounded reconstruction theorem for the NMR tomography scheme** of Nielsen & Chuang Exercises +7.45–7.46: a state `ρ` on the `n`-qubit register `qudit (2ⁿ)` is uniquely determined by the Pauli +expectations `⟨P_g⟩_ρ` that a *tomographically complete* family of measurement settings observes. It +ties the combinatorial covering of the pre-rotation scheme (`Concrete.TomographyComplete`, +`Concrete.SettingObserves`, from Exercise 7.46) to the reconstruction principle +`State.eq_of_expectation_pauliStringHamiltonian_eq`. + +## The physics (N&C §7.7.4, eqs. 7.143, 7.166–7.168) + +Each experiment applies to each spin one of three pre-pulses `{I, R_x, R_y}` — equivalently, it +measures each spin in one of three bases `{Z, Y, X}` — so a *setting* is `s : Fin n → Fin 3`, and +the coupled-spin readout of experiment `s` delivers the expectation `⟨P_g⟩_ρ` of exactly the Pauli +strings `g` it *observes* (`SettingObserves s g`: each non-identity factor of `g` matches that +spin's measured basis, N&C eq. 7.168 read out under the pre-rotation). A family `T` of settings is +*tomographically complete* when every non-identity Pauli string is observed by some setting in `T`. +Then the observed expectations span all `4ⁿ − 1` non-identity Pauli coefficients (N&C's traceless +*deviation density matrix*), and with the fixed normalisation `tr ρ = 1` they reconstruct `ρ`. + +## Statement + +* `State.eq_of_expectation_pauliString_of_tomographyComplete` — if `T` is tomographically complete + and two states `ρ, σ` agree on `⟨P_g⟩` for every Pauli string `g` observed by some setting in `T`, + then + `ρ = σ`. This is "a complete tomography scheme's data determine the state," grounded in + `State.expectation`, for every `n`. Exercise 7.45 (two spins, the nine `{I, R_x, R_y}²` + settings) is its `n = 2` instance; Exercise 7.46 (three spins) the `n = 3` instance. + +## Design + +* **Index-level predicates.** The statement uses `State.expectation`, the observable + `pauliStringHamiltonian`, and the *index-level* combinatorial predicates + `Concrete.TomographyComplete` / `Concrete.SettingObserves` (`Prop`s over the plain index types + `Fin n → Fin 3` / `Fin n → Fin 4`). +* **Readout model.** The readout is + modelled at the *observable* level: that experiment `s` delivers `⟨P_g⟩_ρ` for the strings it + observes is *posited* (abstracting the time-domain `V(t)` and its resolved + single-quantum-coherence spectrum, N&C eq. 7.143), while the covering + (`Concrete.tomographyComplete_univ`) and the + reconstruction are proved rigorously — the intellectual content of the exercise. +* **Proof.** Immediate from the reconstruction principle: for each non-identity Pauli string `g`, + completeness of `T` supplies a setting in `T` observing `g`, and the hypothesis then furnishes the + equal expectation `⟨P_g⟩_ρ = ⟨P_g⟩_σ`. +-/ + +@[expose] public section + +namespace AxQM + +variable {n : ℕ} + +/-- **Reconstruction from a complete NMR tomography scheme** (Nielsen & Chuang §7.7.4, Ex +7.45–7.46). If a family `T` of measurement settings is *tomographically complete* (every +non-identity Pauli string is observed by some setting, `Concrete.TomographyComplete`) and two +states `ρ, σ` on the `n`-qubit register `qudit (2ⁿ)` agree on the expectation `⟨P_g⟩` of every +Pauli-string observable +`P_g = pauliStringHamiltonian g 1` that some setting in `T` observes, then `ρ = σ`. The observed +expectations span all `4ⁿ − 1` non-identity Pauli coefficients, so with the fixed normalisation +`tr ρ = 1` they reconstruct the state (`State.eq_of_expectation_pauliStringHamiltonian_eq`). The +readout of each experiment (which strings it delivers) is modelled at the observable level; the +covering and the reconstruction are proved. -/ +theorem State.eq_of_expectation_pauliString_of_tomographyComplete + {ρ σ : State (qudit (2 ^ n))} {T : Finset (Fin n → Fin 3)} + (hT : Concrete.TomographyComplete T) + (h : ∀ g : Fin n → Fin 4, (∃ s ∈ T, Concrete.SettingObserves s g) → + ρ.expectation (pauliStringHamiltonian g 1) + = σ.expectation (pauliStringHamiltonian g 1)) : + ρ = σ := + State.eq_of_expectation_pauliStringHamiltonian_eq fun g hg => h g (hT g hg) + +end AxQM diff --git a/LeanPool/AxQM/Core/PauliDiagWireTower.lean b/LeanPool/AxQM/Core/PauliDiagWireTower.lean new file mode 100644 index 0000000000..d67cc6f68e --- /dev/null +++ b/LeanPool/AxQM/Core/PauliDiagWireTower.lean @@ -0,0 +1,198 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliDiagWire +public import LeanPool.AxQM.Core.CircuitBudgetSingleWire +public import LeanPool.AxQM.Core.QftTowerHadamard +public import LeanPool.AxQM.Core.PhaseLayerBudget + +/-! +# The Problem 4.3(3) basis-change gate on a register wire is one single-qubit gate on the tower + +Problem 4.3(3)'s basis-change layer `B = ⨂ₖ B_{gₖ}` is built from the per-wire gates +`pauliDiagWireEvolution n t (g t)` (`Postulates/API/PauliDiagWire`) on the flat `2ⁿ`-level register +`qudit (2ⁿ)`; the elementary-gate accountant `CircuitBudget` (`Core/CircuitBudget`) instead counts +gates on the qubit control tower. This file transports each such wire gate across the register +bridge `quditPowTower n` onto the tower — where its budget lives — and reads off its cost. It is the +basis-change analogue of `Core/PhaseWireTower` (the phase gate) and `Core/QftTowerHadamard` (the +Hadamard), specialised to the Problem 4.3 diagonalising gates `pauliDiagGate a`. + +## What is formalised + +* `quditPowTower_congr_pauliDiagWireEvolution` — **the register lift.** Transporting the register + gate `pauliDiagWireEvolution (n+1) t a` onto the `(n+1)`-qubit control tower via `quditPowTower n` + yields exactly the single-wire gate applying the grounded gate `pauliDiagGateEvolution a` to tower + wire `t.rev`: + + `Evolution.congr (quditPowTower n) (pauliDiagWireEvolution (n+1) t a)` + `= Evolution.qtowerSingleWire n t.rev (pauliDiagGateEvolution a)`. + + The `Fin.rev` reconciles the big-endian register bridge with the little-endian wire-indexing. The + exact analogue of `quditPowTower_congr_qftHadamardEvolution` with the Hadamard block replaced by + `pauliDiagGate a`: on each basis input both sides give `∑_z (pauliDiagGate a) z (b t.rev) · + towerKet n (update b t.rev z)` (register side `pauliDiagWireEvolution_evolvePure_quditBasis`, + single-wire side `pauliDiagGateEvolution_evolvePure_qubitBasis_sum`), matched through the tensor + multilinearity of the tower product state. + +* `pauliDiagWireEvolution_circuitBudget` — **the per-wire budget**: + `CircuitBudget (pauliDiagWireEvolution (n+1) t a) 0 1` — the basis-change gate on any wire of the + `2ⁿ⁺¹`-level register costs at most one single-qubit gate and no `≤ 2`-control gates, whatever the + Pauli `a` and wire `t`. Proved by transporting the budget across the register bridge: the register + lift makes the transported gate the tower single-wire gate + `qtowerSingleWire n t.rev (pauliDiagGateEvolution a)`, whose budget is + `qtowerSingleWire_circuitBudget`, then `CircuitBudget.congr` carries it back off the tower. This + is the per-wire cost the basis-change layer `B = ∏ₜ pauliDiagWireEvolution n t (g t)` + folds with `CircuitBudget.listProd` to obtain `CircuitBudget B 0 n` — the `n` single-qubit gates + of Problem 4.3(3). + +* `quditPowTower_congr_pauliDiagLayer` — **the layer bridge**: the whole basis-change layer + `pauliDiagLayer (n+1) g` (`Postulates/API/PauliDiagWire`), read on the tower, is the ordered + product of the `n+1` single-wire gates `qtowerSingleWire n t.rev (pauliDiagGateEvolution (g t))`. + The basis-change analogue of `quditPowTower_congr_phaseGradientLayer`, via `Evolution.congr_prod` + and the per-wire bridge above. + +* `pauliDiagLayer_circuitBudget` — **the layer budget**: + `CircuitBudget (pauliDiagLayer (n+1) g) 0 (n+1)` — the whole basis-change layer `B = ⨂ₖ B_{gₖ}` + costs at most `n+1` single-qubit gates and no `≤ 2`-control gates. Transports the layer onto the + tower (`quditPowTower_congr_pauliDiagLayer`), folds the per-wire budgets with + `CircuitBudget.listProd` (base `CircuitBudget.id_qtower`), and carries the budget back off the + tower. Together with the faithfulness `pauliDiagLayer_op` (`Postulates/API/PauliDiagWire`), this + is Problem 4.3(3)'s basis-change layer counted as its `n` single-qubit gates. + +The proof mirrors that of `Core/QftTowerHadamard`; the per-wire tower budget it transports is in +`Core/CircuitBudgetSingleWire`, and the wire gates and their basis actions are defined in +`Postulates/API/PauliDiagWire`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +/-- **The transported Problem 4.3(3) basis-change wire gate is the grounded gate on tower wire +`t.rev`.** Transporting the register gate `pauliDiagWireEvolution (n+1) t a` (the diagonalising gate +`pauliDiagGate a` on register wire `t`) onto the `(n+1)`-qubit control tower via the register bridge +`quditPowTower n` yields exactly the single-wire gate applying `pauliDiagGateEvolution a` to tower +wire `t.rev`: + + `Evolution.congr (quditPowTower n) (pauliDiagWireEvolution (n+1) t a)` + `= Evolution.qtowerSingleWire n t.rev (pauliDiagGateEvolution a)`. + +The basis-change analogue of `quditPowTower_congr_qftHadamardEvolution` / +`quditPowTower_congr_phaseWireEvolution` (whose gate blocks are the Hadamard and the phase gate). +Proved through the combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: both the single-wire +gate (via `qtowerSingleWire_evolvePure_towerKet` and the shared tower-product multilinearity +`towerProd_vec_update_sum_smul`) and the transported register gate (via +`pauliDiagWireEvolution_evolvePure_quditBasis`, the bridge isometry, and the dictionary +`quditPowTower_congr_quditBasis_apply`) send `towerKet n b` to the two-term superposition +`∑_z (pauliDiagGate a) z (b t.rev) · towerKet n (Function.update b t.rev z)`, the two `Fin.rev`s +collapsing by `Fin.rev_rev`. +-/ +theorem quditPowTower_congr_pauliDiagWireEvolution (n : ℕ) (t : Fin (n + 1)) (a : Fin 4) : + Evolution.congr (quditPowTower n) (pauliDiagWireEvolution (n + 1) t a) + = Evolution.qtowerSingleWire n t.rev (pauliDiagGateEvolution a) := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + rw [qtowerSingleWire_evolvePure_towerKet, PureState.congr_vec, + pauliDiagWireEvolution_evolvePure_quditBasis, + towerProd_vec_update_sum_smul n (fun j => qubitBasis (b j)) t.rev + (fun z => Concrete.pauliDiagGate a z (b t.rev)) qubitBasis + ((pauliDiagGateEvolution a).evolvePure (qubitBasis (b t.rev))) + (pauliDiagGateEvolution_evolvePure_qubitBasis_sum a (b t.rev)), + map_sum] + refine Finset.sum_congr rfl (fun z _ => ?_) + rw [map_smul, towerProd_update_qubitBasis b t z, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply, update_rev_eq b t z] + +/-- **The Problem 4.3(3) basis-change gate on any wire costs one single-qubit gate.** For every wire +`t : Fin (n+1)` of the `2ⁿ⁺¹`-level register and every Pauli `a : Fin 4`, placing the diagonalising +gate `pauliDiagGate a` on wire `t` has budget + + `CircuitBudget (pauliDiagWireEvolution (n+1) t a) 0 1` + +— at most one single-qubit gate and no `≤ 2`-control gates. Proved by transporting the budget across +the register bridge: `quditPowTower_congr_pauliDiagWireEvolution` makes the transported gate the +tower single-wire gate `qtowerSingleWire n t.rev (pauliDiagGateEvolution a)`, whose budget is +`qtowerSingleWire_circuitBudget`, and `CircuitBudget.congr` carries the budget back off the tower +(the register round-trip `Evolution.congr_symm_congr`). This is the per-wire cost the basis-change +layer `B = ∏ₜ pauliDiagWireEvolution n t (g t)` folds with `CircuitBudget.listProd` to obtain +`CircuitBudget B 0 n` — the `n` single-qubit gates of Problem 4.3(3). -/ +theorem pauliDiagWireEvolution_circuitBudget (n : ℕ) (t : Fin (n + 1)) (a : Fin 4) : + CircuitBudget (pauliDiagWireEvolution (n + 1) t a) 0 1 := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (pauliDiagWireEvolution (n + 1) t a), + quditPowTower_congr_pauliDiagWireEvolution] + exact CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm + (qtowerSingleWire_circuitBudget n t.rev (pauliDiagGateEvolution a)) + +/-- **The transported basis-change layer is the ordered product of single-wire gates on the tower.** +Transporting the whole register basis-change layer `pauliDiagLayer (n+1) g` — the product of the +`n+1` per-wire diagonalising gates on the flat register `qudit (2ⁿ⁺¹)` — onto the qubit control +tower `qtower n qubit` yields the ordered product of the `n+1` single-qubit gates +`pauliDiagGateEvolution (g t)` placed on tower wire `t.rev`: + + `Evolution.congr (quditPowTower n) (pauliDiagLayer (n+1) g)` + `= ((List.finRange (n+1)).map fun t => Evolution.qtowerSingleWire n t.rev + (pauliDiagGateEvolution (g t))).prod`. + +The basis-change analogue of `quditPowTower_congr_phaseGradientLayer` (the phase gate replaced by +the diagonalising gate `pauliDiagGateEvolution (g t)`). It follows from the per-wire bridge +`quditPowTower_congr_pauliDiagWireEvolution` and the monoid-homomorphism property +`Evolution.congr_prod` of the register transport, which pushes the transport through the list +product gate-by-gate. -/ +theorem quditPowTower_congr_pauliDiagLayer (n : ℕ) (g : Fin (n + 1) → Fin 4) : + Evolution.congr (quditPowTower n) (pauliDiagLayer (n + 1) g) + = ((List.finRange (n + 1)).map + (fun t => Evolution.qtowerSingleWire n t.rev (pauliDiagGateEvolution (g t)))).prod := by + rw [pauliDiagLayer, Evolution.congr_prod, List.map_map] + refine congrArg List.prod (List.map_congr_left fun t _ => ?_) + simpa only [Function.comp_apply] using quditPowTower_congr_pauliDiagWireEvolution n t (g t) + +/-- **Problem 4.3(3)'s basis-change layer is `n+1` single-qubit gates.** For any Pauli string +`g : Fin (n+1) → Fin 4`, the basis-change layer `pauliDiagLayer (n+1) g` on the `(n+1)`-qubit +register `qudit (2ⁿ⁺¹)` — the product of the `n+1` per-wire diagonalising gates +`pauliDiagWireEvolution (n+1) t (g t)` — has budget + + `CircuitBudget (pauliDiagLayer (n+1) g) 0 (n+1)`: + +at most `n+1` single-qubit gates and **no** `≤ 2`-control gates. This is the `O(n)` single-qubit +basis-change cost that opens Problem 4.3(3)'s circuit, made a genuine `CircuitBudget`; combined with +`pauliDiagLayer_op` it shows the tensor basis change `B = ⨂ₖ B_{gₖ}` is implemented by exactly `n+1` +single-qubit gates. + +Proof (the analogue of `phaseGradientLayer_circuitBudget`): transport the layer onto the qubit +control tower via `quditPowTower_congr_pauliDiagLayer`, where it is the ordered product of the `n+1` +single-wire gates `qtowerSingleWire n t.rev (pauliDiagGateEvolution (g t))`, each budgeted `0 1` by +`qtowerSingleWire_circuitBudget`; fold those with `CircuitBudget.listProd` (base +`CircuitBudget.id_qtower`) to get `0 (n+1)`; then carry the budget back off the tower with +`CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm` and `Evolution.congr_symm_congr`. -/ +theorem pauliDiagLayer_circuitBudget (n : ℕ) (g : Fin (n + 1) → Fin 4) : + CircuitBudget (pauliDiagLayer (n + 1) g) 0 (n + 1) := by + rw [← Evolution.congr_symm_congr (quditPowTower n) (pauliDiagLayer (n + 1) g), + quditPowTower_congr_pauliDiagLayer] + refine CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm ?_ + have hbud := CircuitBudget.listProd (CircuitBudget.id_qtower n) + ((List.finRange (n + 1)).map + (fun t => Evolution.qtowerSingleWire n t.rev (pauliDiagGateEvolution (g t)))) + (by + intro E hE + simp only [List.mem_map] at hE + obtain ⟨t, -, rfl⟩ := hE + exact qtowerSingleWire_circuitBudget n t.rev (pauliDiagGateEvolution (g t))) + rwa [List.length_map, List.length_finRange] at hbud + +end AxQM + +end diff --git a/LeanPool/AxQM/Core/PauliStringExpCircuitBudget.lean b/LeanPool/AxQM/Core/PauliStringExpCircuitBudget.lean new file mode 100644 index 0000000000..e9a9bf1bdc --- /dev/null +++ b/LeanPool/AxQM/Core/PauliStringExpCircuitBudget.lean @@ -0,0 +1,91 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliStringExpCircuit +public import LeanPool.AxQM.Core.PauliDiagWireTower +public import LeanPool.AxQM.Core.CnotFanEvolutionBudget +public import LeanPool.AxQM.Core.CircuitBudgetAdjoint + +/-! +# Problem 4.3(3) gate count: the assembled Figure-4.19 circuit is `O(n)` elementary gates + +Problem 4.3(3) asks to implement the Trotter summand `exp(-i h_g g Δ)` — a rotation about the Pauli +string `g` — using `O(n)` one- and two-qubit gates. The *operator faithfulness* of the standard +compute–rotate–uncompute cascade `B ∘ V† ∘ R_z ∘ V ∘ B†` (`pauliStringExpCircuit`) was already +proved: `pauliStringExpCircuit_op_eq_propagator` shows its operator is exactly that summand. This +file supplies the other half of Problem 4.3(3) — the **elementary-gate count** — by giving the +assembled `Evolution` a genuine `CircuitBudget`. + +* `pauliStringExpCircuit_circuitBudget` — for a collector `c ∉ ts` on the `(n+1)`-qubit register, + the cascade `pauliStringExpCircuit (n+1) g c ts θ` has budget + `CircuitBudget (pauliStringExpCircuit (n+1) g c ts θ) (2 * ts.length) (2 * n + 3)`: at most + `2 · ts.length` two-qubit (`≤ 2`-control) gates and `2n + 3` single-qubit gates. Since the + string's support is `insert c ts`, `ts.length = |support| − 1 ≤ n`, so both counts are linear in + the number of qubits — this is exactly the `O(n)` one- and two-qubit gate count of Problem 4.3(3). + +## Where the counts come from + +The five pieces of `pauliStringExpCircuit (n+1) g c ts θ = B · V† · R_z · V · B†` each carry a +budget established elsewhere: + +* `B = pauliDiagLayer (n+1) g` — the basis-change layer: `n+1` single-qubit gates + (`pauliDiagLayer_circuitBudget`); `B†` its adjoint, another `n+1` single-qubit gates. +* `V = cnotFanIntoEvolution (n+1) c ts` — the parity `CNOT` fan: `ts.length` two-qubit gates + (`cnotFanIntoEvolution_circuitBudget`); `V†` its uncomputation, another `ts.length`. +* `R_z = rotZWireEvolution (n+1) c θ` — the collector `z`-rotation: one single-qubit gate + (`rotZWireEvolution_circuitBudget`). + +Summing along the composition (`CircuitBudget.comp` adds budgets; `CircuitBudget.adjoint` preserves +a gate count exactly — reversing a circuit neither adds nor removes gates) gives two-qubit total +`ts.length + ts.length = 2 · ts.length` and single-qubit total `(n+1) + 1 + (n+1) = 2n + 3`; +`CircuitBudget.mono` rewrites the raw folded sums into that closed form. + +The `Evolution` `pauliStringExpCircuit` is defined in `Postulates/API/PauliStringExpCircuit`. +-/ + +@[expose] public section + +namespace AxQM + +noncomputable section + +/-- **Problem 4.3(3): the Figure-4.19 circuit implementing `exp(-i h_g g Δ)` costs `O(n)` gates.** +For a collector wire `c ∉ ts` on the `(n+1)`-qubit register, the assembled compute–rotate–uncompute +cascade `pauliStringExpCircuit (n+1) g c ts θ = B · V† · R_z · V · B†` has budget + + `CircuitBudget (pauliStringExpCircuit (n+1) g c ts θ) (2 * ts.length) (2 * n + 3)`: + +at most `2 · ts.length` two-qubit (`≤ 2`-control) gates and `2n + 3` single-qubit gates. When `g`'s +support is `insert c ts` (the case the faithfulness lemma `pauliStringExpCircuit_op_eq_propagator` +covers) `ts.length = |support| − 1 ≤ n`, so this is the linear — `O(n)` — one- and two-qubit gate +count Problem 4.3(3) demands. + +The budget is independent of the correctness hypotheses: it holds for any control list `ts` with +`c ∉ ts` (the only condition the fan's budget needs) and any angle `θ`. + +Proof: unfold the cascade into its five `Evolution` factors, fold their budgets with +`CircuitBudget.comp` (the two uncomputations `V†`, `B†` reuse the same forward budgets via +`CircuitBudget.adjoint`, which preserves gate counts exactly), and relax the folded sums to the +closed form `(2 * ts.length, 2 * n + 3)` with `CircuitBudget.mono` (both `≤` are equalities, by +`omega`). -/ +theorem pauliStringExpCircuit_circuitBudget {n : ℕ} (g : Fin (n + 1) → Fin 4) (c : Fin (n + 1)) + (ts : List (Fin (n + 1))) (hc : c ∉ ts) (θ : ℝ) : + CircuitBudget (pauliStringExpCircuit (n + 1) g c ts θ) (2 * ts.length) (2 * n + 3) := by + rw [pauliStringExpCircuit] + simp only [Evolution.mul_def] + refine (((((pauliDiagLayer_circuitBudget n g).comp + (cnotFanIntoEvolution_circuitBudget c ts hc).adjoint).comp + (rotZWireEvolution_circuitBudget c θ)).comp + (cnotFanIntoEvolution_circuitBudget c ts hc)).comp + (pauliDiagLayer_circuitBudget n g).adjoint).mono ?_ ?_ <;> omega + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PauliTomographyExpectation.lean b/LeanPool/AxQM/Core/PauliTomographyExpectation.lean new file mode 100644 index 0000000000..eb517dea08 --- /dev/null +++ b/LeanPool/AxQM/Core/PauliTomographyExpectation.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTomographyExpectation + +/-! +# AxQM.Core — tomographic reconstruction: a state is fixed by its Pauli expectations + +The **grounded reconstruction principle** of *state tomography* (Nielsen & Chuang +§7.7.4, eqns 7.166–7.168): a quantum state `ρ` on the `n`-qubit register `qudit (2ⁿ)` is uniquely +determined by the expectation values `⟨P_g⟩_ρ` of the non-identity Pauli-string observables +`P_g = pauliStringHamiltonian g 1` (`g ≠ 0`). This is the precise content of "the state can be +reconstructed from its measured Pauli expectation values": two states with identical Pauli +measurement statistics are equal. + +## Statement + +* `State.eq_of_expectation_pauliStringHamiltonian_eq` — if + `ρ.expectation (pauliStringHamiltonian g 1) = σ.expectation (pauliStringHamiltonian g 1)` for + every **non-identity** Pauli string `g ≠ (fun _ => 0)`, then `ρ = σ`. For `n = 2` (two spins) this + is the `4² − 1 = 15` non-identity two-qubit Pauli expectations of Exercise 7.45; the identity is + the fixed normalisation `tr ρ = 1`, not a measurement, matching N&C's traceless *deviation density + matrix* (the `4ⁿ − 1` real parameters). + +## Design + +* **Where the ingredients are.** The statement uses `State.expectation` and the observable + `pauliStringHamiltonian`. It is proved through `State.pauliMatrix`, the (7.168) trace + identity `State.expectation_pauliStringHamiltonian` and `State.eq_of_pauliMatrix_eq`, all in + `AxQM/Postulates/API/PauliTomographyExpectation.lean`; the underlying matrix uniqueness is + `eq_of_trace_eq_of_trace_pauliString_eq` in `AxQM/Concrete/PauliTomography.lean`. +* **`n`-general.** Stated for every `n`, so it serves both Exercise 7.45 (two spins) and Exercise + 7.46 (three spins) verbatim. +* **Proof.** Reduce `ρ = σ` to the matrix identity `ρ.pauliMatrix = σ.pauliMatrix` + (`State.eq_of_pauliMatrix_eq`), then apply the Concrete deviation-uniqueness backbone: the traces + agree (both density matrices have `tr = 1`, `State.trace_pauliMatrix`), and each non-identity + Pauli trace pairing agrees because the bridge turns the hypothesis into + `Re tr(P_g ρ) = Re tr(P_g σ)`, which lifts to full equality since both pairings are real + (`Concrete.trace_pauliString_mul_im`, the pairings of Hermitian matrices). +-/ + +@[expose] public section + +open scoped BigOperators + +namespace AxQM + +variable {n : ℕ} + +/-- **Tomographic reconstruction of a state from its Pauli expectations** (Nielsen & Chuang §7.7.4, +eqns 7.166–7.168; the reconstruction underlying Exercise 7.45). A state `ρ` on the `n`-qubit +register `qudit (2ⁿ)` is uniquely determined by the expectations `⟨P_g⟩_ρ` of the **non-identity** +Pauli-string observables `P_g = pauliStringHamiltonian g 1`: if `ρ` and `σ` have equal such +expectations for every `g ≠ 0`, then `ρ = σ`. The identity Pauli `P_0 = I` is not needed — it pairs +to the fixed normalisation `tr ρ = 1`, N&C's traceless *deviation density matrix* — so the +`4ⁿ − 1` non-identity expectations (`15` for two spins) suffice. -/ +theorem State.eq_of_expectation_pauliStringHamiltonian_eq {ρ σ : State (qudit (2 ^ n))} + (h : ∀ g : Fin n → Fin 4, g ≠ (fun _ => 0) → + ρ.expectation (pauliStringHamiltonian g 1) + = σ.expectation (pauliStringHamiltonian g 1)) : + ρ = σ := by + refine State.eq_of_pauliMatrix_eq (Concrete.eq_of_trace_eq_of_trace_pauliString_eq ?_ ?_) + · rw [ρ.trace_pauliMatrix, σ.trace_pauliMatrix] + · intro g hg + have hre : ((Concrete.pauliString g * ρ.pauliMatrix).trace).re + = ((Concrete.pauliString g * σ.pauliMatrix).trace).re := by + rw [← ρ.expectation_pauliStringHamiltonian, ← σ.expectation_pauliStringHamiltonian] + exact h g hg + have himρ := Concrete.trace_pauliString_mul_im ρ.pauliMatrix_isHermitian g + have himσ := Concrete.trace_pauliString_mul_im σ.pauliMatrix_isHermitian g + exact Complex.ext hre (himρ.trans himσ.symm) + +end AxQM diff --git a/LeanPool/AxQM/Core/PauliTrotterCapstoneBudget.lean b/LeanPool/AxQM/Core/PauliTrotterCapstoneBudget.lean new file mode 100644 index 0000000000..e12d89b246 --- /dev/null +++ b/LeanPool/AxQM/Core/PauliTrotterCapstoneBudget.lean @@ -0,0 +1,84 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.PauliTrotterStepBudget + +/-! +# Problem 4.3(6) gate count: the `k`-fold Trotter circuit costs `O(k·n·4ⁿ)` gates + +The Problem 4.3(6) approximation `[∏_g exp(-i h_g g Δ)]ᵏ` is the `k`-fold power of one Trotter step +`pauliTrotterStep (n+1) h t` (`Postulates/API/PauliTrotterStep.lean`), which itself costs `O(n·4ⁿ)` +one- and two-qubit gates (`pauliTrotterStep_circuitBudget`, `Core/PauliTrotterStepBudget.lean`). +Running it `k` times therefore costs `k` times as much — `O(k·n·4ⁿ)` gates. This file records that +`k`-fold count. + +* `pauliTrotterStep_pow_circuitBudget` — for every `h : (Fin (n+1) → Fin 4) → ℝ`, time `t`, and + repetition count `k`, + `CircuitBudget ((pauliTrotterStep (n+1) h t) ^ k)` + `(k * (4^(n+1) * (2*n))) (k * (4^(n+1) * (2*n+3)))`: at most `k · 4ⁿ⁺¹ · 2n` two-qubit + (`≤ 2`-control) and `k · 4ⁿ⁺¹ · (2n+3)` single-qubit gates. + +## Where the count comes from + +The `k`-fold power `E ^ k` is the product `(List.replicate k E).prod` of `k` copies of `E` +(`List.prod_replicate`). The uniform product fold `CircuitBudget.listProd_uniform` +(`Core/CircuitBudget.lean`) then scales the per-copy budget by the list length `k` +(`List.length_replicate`): every copy is the single Trotter step, budgeted uniformly +`(4^(n+1)·2n, 4^(n+1)·(2n+3))` by `pauliTrotterStep_circuitBudget`, and the empty-product base +is the named register-identity budget `CircuitBudget.id_qudit` on `qudit (2ⁿ⁺¹)`. + +## Toward N&C's `O(n·16ⁿ/ε)` + +Choosing `k` proportional to `1/ε` (here `k = O(C/ε)` for the first-order Trotter constant `C`, +chosen in [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean) so that the part-(5) error `C/k` drops below `ε`) +turns this `O(k·n·4ⁿ)` count into `O(n·4ⁿ·C/ε)`. N&C's `16ⁿ = 4ⁿ · 4ⁿ` is (i) the `4ⁿ⁺¹` gates +*per step* (explicit here) times (ii) the `O(4ⁿ)` *number of steps* `k`. Factor (ii), i.e. +`C = O(4ⁿ)`, is a **rigorous** bound: for a first-order Trotter product of unitaries the error +scales as `O(Λ²)/k`, `Λ = Σ_g |h_g| = O(2ⁿ)` (from `‖H‖ ≤ 2π`), with no exponential prefactor. This +file's budget is uniform in `k`, so it already supplies factor (i) for *any* `k`; pinning +`k = O(4ⁿ/ε)` — i.e. `C = O(4ⁿ)` — needs the unitarity-aware Trotter bound + the coefficient +estimate `Σ_g |h_g| = O(2ⁿ)`, needed for Problem 4.3(6); see [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +noncomputable section + +/-- **Problem 4.3(6): the `k`-fold Trotter circuit costs `O(k·n·4ⁿ)` gates.** For every coefficient +function `h : (Fin (n+1) → Fin 4) → ℝ`, time `t`, and repetition count `k`, +`CircuitBudget ((pauliTrotterStep (n+1) h t) ^ k)` +`(k * (4^(n+1) * (2*n))) (k * (4^(n+1) * (2*n+3)))`: +at most `k · 4ⁿ⁺¹ · 2n` two-qubit (`≤ 2`-control) and `k · 4ⁿ⁺¹ · (2n+3)` single-qubit gates — the +per-step count `O(n·4ⁿ)` (`pauliTrotterStep_circuitBudget`) multiplied by the `k` repetitions. + +The power `E ^ k` is the product of `k` copies of `E` (`List.prod_replicate`); the uniform product +fold `CircuitBudget.listProd_uniform` scales the per-copy Trotter-step budget +`pauliTrotterStep_circuitBudget` by the list length `k` (`List.length_replicate`), over the +register-identity base `CircuitBudget.id_qudit`. Choosing `k = O(C/ε)` (see +[upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean)) gives an `O(n·4ⁿ·C/ε)` total; N&C's `O(n·16ⁿ/ε)` follows once `C` is +pinned to `O(4ⁿ)` (rigorous; see [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean)). -/ +theorem pauliTrotterStep_pow_circuitBudget {n : ℕ} (h : (Fin (n + 1) → Fin 4) → ℝ) (t : ℝ) + (k : ℕ) : + CircuitBudget ((pauliTrotterStep (n + 1) h t) ^ k) + (k * (4 ^ (n + 1) * (2 * n))) (k * (4 ^ (n + 1) * (2 * n + 3))) := by + -- `E ^ k = (List.replicate k E).prod`: fold the per-copy budget over the `k` copies. + have hbud := CircuitBudget.listProd_uniform (CircuitBudget.id_qudit n) + (List.replicate k (pauliTrotterStep (n + 1) h t)) + (fun E hE => by + rw [List.eq_of_mem_replicate hE]; exact pauliTrotterStep_circuitBudget h t) + rwa [List.length_replicate, List.prod_replicate] at hbud + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PauliTrotterStepBudget.lean b/LeanPool/AxQM/Core/PauliTrotterStepBudget.lean new file mode 100644 index 0000000000..acf5311ca1 --- /dev/null +++ b/LeanPool/AxQM/Core/PauliTrotterStepBudget.lean @@ -0,0 +1,83 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTrotterStep +public import LeanPool.AxQM.Core.PauliTrotterSummandBudget +public import LeanPool.AxQM.Core.PhaseLayerBudget + +/-! +# Problem 4.3(6) gate count: one full Trotter step costs `O(n·4ⁿ)` gates + +The full Trotter step `pauliTrotterStep (n+1) h t` (`Postulates/API/PauliTrotterStep`) is the +ordered product, over all `4ⁿ⁺¹` Pauli strings `g : Fin (n+1) → Fin 4`, of the per-string summands +`exp(-i h_g g t)`. Each summand costs `O(n)` gates uniformly (`pauliTrotterSummand_circuitBudget`, +`Core/PauliTrotterSummandBudget`), so their product — one Trotter step — costs `4ⁿ⁺¹ · O(n) = +O(n·4ⁿ)` gates. This is the per-step count that, taken to the `k = O(4ⁿ/ε)`-th power (part (5)), +gives the `O(n·16ⁿ/ε)` total of Problem 4.3(6). + +* `pauliTrotterStep_circuitBudget` — for every `h : (Fin (n+1) → Fin 4) → ℝ` and time `t`, + `CircuitBudget (pauliTrotterStep (n+1) h t) (4^(n+1) * (2*n)) (4^(n+1) * (2*n+3))`: at most + `4ⁿ⁺¹ · 2n` two-qubit (`≤ 2`-control) and `4ⁿ⁺¹ · (2n+3)` single-qubit gates — `O(n·4ⁿ)` in the + qubit number. + +## Where the count comes from + +The step is a `List.prod` of `4ⁿ⁺¹` factors, one per Pauli string, each budgeted uniformly +`(2n, 2n+3)` by `pauliTrotterSummand_circuitBudget`. The uniform product fold +`CircuitBudget.listProd_uniform` (`Core/CircuitBudget`) turns that into +`CircuitBudget · (l.length · 2n) (l.length · (2n+3))` for the product, where the list length is the +number of Pauli strings `Finset.univ.toList.length = Fintype.card (Fin (n+1) → Fin 4) = 4ⁿ⁺¹` +(`Fintype.card_fun`, `Fintype.card_fin`). The empty-product base the fold needs is the named +register-identity budget `CircuitBudget.id_qudit` (`CircuitBudget (1 : Evolution (qudit (2ⁿ⁺¹))) +0 0`, the qudit-register analogue of `CircuitBudget.id_qtower`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +noncomputable section + +/-- **Problem 4.3(6): one full Trotter step costs `O(n·4ⁿ)` gates.** For every coefficient function +`h : (Fin (n+1) → Fin 4) → ℝ` and time `t`, +`CircuitBudget (pauliTrotterStep (n+1) h t) (4^(n+1) * (2*n)) (4^(n+1) * (2*n+3))`: at most +`4ⁿ⁺¹ · 2n` two-qubit (`≤ 2`-control) and `4ⁿ⁺¹ · (2n+3)` single-qubit gates — linear in the qubit +number times the `4ⁿ⁺¹ = O(4ⁿ)` Pauli strings, i.e. N&C's `O(n·4ⁿ)` per Trotter step. + +The step is the product over all `4ⁿ⁺¹` Pauli strings of the per-string summands, each budgeted +uniformly `(2n, 2n+3)` by `pauliTrotterSummand_circuitBudget`; the uniform product fold +`CircuitBudget.listProd_uniform` scales that per factor, giving `(l.length · 2n, l.length · (2n+3))` +with `l.length = 4ⁿ⁺¹` the number of Pauli strings (`Fintype.card_fun`). The empty-product base is +the named register-identity budget `CircuitBudget.id_qudit` on `qudit (2ⁿ⁺¹)`. -/ +theorem pauliTrotterStep_circuitBudget {n : ℕ} (h : (Fin (n + 1) → Fin 4) → ℝ) (t : ℝ) : + CircuitBudget (pauliTrotterStep (n + 1) h t) + (4 ^ (n + 1) * (2 * n)) (4 ^ (n + 1) * (2 * n + 3)) := by + rw [pauliTrotterStep] + -- Fold the uniform per-summand budget over the product, over the register-identity base + -- `CircuitBudget.id_qudit` (the empty-product budget on `qudit (2ⁿ⁺¹)`). + have hbud := CircuitBudget.listProd_uniform (CircuitBudget.id_qudit n) + (Finset.univ.toList.map fun g => pauliTrotterSummand (n + 1) g (h g) t) + (by + intro E hE + simp only [List.mem_map] at hE + obtain ⟨g, -, rfl⟩ := hE + exact pauliTrotterSummand_circuitBudget g (h g) t) + -- The number of factors is the number of Pauli strings, `4ⁿ⁺¹`. + have hlen : (Finset.univ.toList.map fun g => pauliTrotterSummand (n + 1) g (h g) t).length + = 4 ^ (n + 1) := by + rw [List.length_map, Finset.length_toList, Finset.card_univ, Fintype.card_fun, + Fintype.card_fin, Fintype.card_fin] + rwa [hlen] at hbud + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PauliTrotterSummandBudget.lean b/LeanPool/AxQM/Core/PauliTrotterSummandBudget.lean new file mode 100644 index 0000000000..d61b733ae8 --- /dev/null +++ b/LeanPool/AxQM/Core/PauliTrotterSummandBudget.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTrotterSummand +public import LeanPool.AxQM.Core.PauliStringExpCircuitBudget +public import LeanPool.AxQM.Core.GlobalPhaseCircuitBudget + +/-! +# Problem 4.3(6) gate count: the total per-string Trotter summand costs `O(n)` gates + +The total summand `pauliTrotterSummand (n+1) g coeff t` (`Postulates/API/PauliTrotterSummand.lean`) +realises `exp(-i · coeff · t · g)` for *every* Pauli string `g` on the `(n+1)`-qubit register. This +file gives it a uniform `O(n)` elementary-gate `CircuitBudget`, the other half of what the full +Trotter step (product over all `4ⁿ` strings) needs to reach the `O(n · 4ⁿ)` and, ultimately, +`O(n · 16ⁿ / ε)` gate counts of Problem 4.3(6). + +* `pauliTrotterSummand_circuitBudget` — for every `g : Fin (n+1) → Fin 4`, + `CircuitBudget (pauliTrotterSummand (n+1) g coeff t) (2 * n) (2 * n + 3)`: at most `2n` two-qubit + (`≤ 2`-control) and `2n + 3` single-qubit gates — linear in the qubit number, i.e. `O(n)`, for + *both* the nonempty-support (Pauli rotation) and identity-string (global phase) cases. + +## Where the count comes from + +The summand splits on the support of `g`: + +* **Nonempty support** — the Figure-4.19 cascade `pauliStringExpCircuit (n+1) g c ts (2 coeff t)`, + budgeted `(2 · ts.length) (2 n + 3)` by `pauliStringExpCircuit_circuitBudget`. Here `ts` is the + support minus its least element `c`, so `ts.length = |support| − 1 ≤ (n+1) − 1 = n` + (`Finset.card_erase_of_mem`, `Finset.card_le_univ`); hence `2 · ts.length ≤ 2 n`, and + `CircuitBudget.mono` relaxes the two-qubit count to `2 n`. +* **Empty support** — the identity string, whose summand is the global phase + `globalPhaseGate (-(coeff t))`, budgeted `(0) (1)` by `globalPhaseGate_circuitBudget`; `0 ≤ 2 n` + and `1 ≤ 2 n + 3`, so `CircuitBudget.mono` lifts it to the common bound. + +The uniform bound `(2 n, 2 n + 3)` dominates both branches, so the summand — whichever `g` it is +built for — costs `O(n)` gates. +-/ + +@[expose] public section + +namespace AxQM + +noncomputable section + +/-- **Problem 4.3(6): the total per-string Trotter summand costs `O(n)` gates.** For every Pauli +string `g : Fin (n+1) → Fin 4`, +`CircuitBudget (pauliTrotterSummand (n+1) g coeff t) (2 * n) (2 * n + 3)`: at most `2n` two-qubit +(`≤ 2`-control) and `2n + 3` single-qubit gates — linear in the number of qubits, N&C's `O(n)`. The +bound is uniform over both cases of the summand: the Figure-4.19 Pauli-rotation cascade +(`pauliStringExpCircuit_circuitBudget`, whose `2 · ts.length ≤ 2n` since `ts` is the support minus +one wire) and the identity string's global phase (`globalPhaseGate_circuitBudget`, budget `0 1`), +each relaxed to the common bound by `CircuitBudget.mono`. -/ +theorem pauliTrotterSummand_circuitBudget {n : ℕ} (g : Fin (n + 1) → Fin 4) (coeff t : ℝ) : + CircuitBudget (pauliTrotterSummand (n + 1) g coeff t) (2 * n) (2 * n + 3) := by + unfold pauliTrotterSummand + by_cases hne : (Concrete.pauliStringSupport g).Nonempty + · -- Nonempty support: the Figure-4.19 cascade, `2·ts.length ≤ 2n`. + rw [dite_eq_left hne] + set S := Concrete.pauliStringSupport g with hSdef + set c := S.min' hne with hcdef + have hcmem : c ∈ S := S.min'_mem hne + have hcnotmem : c ∉ (S.erase c).toList := by + rw [Finset.mem_toList]; exact Finset.notMem_erase c S + have hlen : (S.erase c).toList.length ≤ n := by + have hcard : S.card ≤ n + 1 := by + have h := Finset.card_le_univ S + rwa [Fintype.card_fin] at h + rw [Finset.length_toList, Finset.card_erase_of_mem hcmem] + omega + exact (pauliStringExpCircuit_circuitBudget g c ((S.erase c).toList) hcnotmem + (2 * coeff * t)).mono (by omega) (by omega) + · -- Empty support: the identity string's global phase, budget `0 1`. + rw [dite_eq_right hne] + exact (globalPhaseGate_circuitBudget n (-(coeff * t))).mono (by omega) (by omega) + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PhaseLayerBudget.lean b/LeanPool/AxQM/Core/PhaseLayerBudget.lean new file mode 100644 index 0000000000..5ed45b8004 --- /dev/null +++ b/LeanPool/AxQM/Core/PhaseLayerBudget.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.CircuitBudgetSingleWire +public import LeanPool.AxQM.Core.PhaseWireTower +public import LeanPool.AxQM.Core.QtowerTensorPow + +/-! +# The phase layer of Problem 4.1 is `n` single-qubit gates (N&C Problem 4.1, the `n` of `2T + n`) + +Problem 4.1's phase layer `D = diagPhase (computablePhaseAngle n)` is, in the textbook construction, +**`n` single-qubit phase gates** — one on each ancilla wire. The elementary-gate budget +`CircuitBudget E t s` (`Core/CircuitBudget`) counts gates on the qubit control tower, where a single +tower-wire gate has budget `0 1` (`qtowerSingleWire_circuitBudget`), and the +phase-gradient layer read on the tower is the ordered product of those wire gates +(`quditPowTower_congr_phaseGradientLayer`). This file assembles those two facts into the +gate-count of the whole phase layer. + +* `CircuitBudget.listProd` — the **product fold**: a `List.prod` of gates each costing `0 1` costs + `0 (length)`. The reusable accountant behind every wire-by-wire layer: `comp` sums the budgets + down the list, with the empty product discharged by an identity budget on the register (supplied + as a hypothesis, since a general system carries no elementary-gate budget for `1`). + +* `CircuitBudget.id_qtower` — the **tower identity budget** `CircuitBudget (1 : Evolution (qtower n + qubit)) 0 0`: the identity on the qubit tower is an empty circuit, `0` gates. Proved by the empty + `block` leaf on `qubit ^⊗ₛ (n+1)` transported back across the tower bridge `qtowerQubitTensorPow` + (`congr` of `1` is `1`). This is the base the product fold needs on the tower register. + +* `phaseGradientLayer_circuitBudget` — **the phase-layer budget**: + `CircuitBudget (phaseGradientLayer (n+1) φ) 0 (n+1)`. The register `qudit (2ⁿ⁺¹)`'s phase-gradient + layer — the product of the `n+1` single-wire phase gates `phaseWireEvolution (n+1) t (φ t)` — + costs at most `n+1` single-qubit gates and no `≤ 2`-control gates, whatever the per-wire angles + `φ`. Proof: transport the layer onto the tower (`quditPowTower_congr_phaseGradientLayer`), where + it is the product of `n+1` single-wire gates each budgeted `0 1` + (`qtowerSingleWire_circuitBudget`); fold with `CircuitBudget.listProd` to get + `0 (n+1)`; then transport the budget back off the tower (`CircuitBudget.congr` + + `Evolution.congr_symm_congr`). + +The `n+1` here is exactly the ancilla size: the phase layer of an `(n+1)`-qubit ancilla is `n+1` +single-qubit gates, faithful to the exercise's positive integer `n`. Its instance at the computable +phase angle — `D = diagPhase (computablePhaseAngle (n+1))`, via +`phaseGradientLayer_phaseWireAngle_eq_diagPhase` — is `diagPhase_computablePhaseAngle_circuitBudget` +in [upstream `AxQM/NC/Ch4/Problem4_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_1.lean), the `CircuitBudget D 0 n` ingredient of the `2T + n` +bound. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +open QSystem.Iso (IsWireReindexing) + +noncomputable section + +/-- **A product of single-qubit gates costs one gate per factor.** If every gate in a list `l` has +budget `CircuitBudget · 0 1` (one single-qubit gate, no `≤ 2`-control gates), then their composition +`l.prod` has `CircuitBudget l.prod 0 l.length` — the single-qubit counts add down the list. The +reusable fold behind a wire-by-wire gate layer (Problem 4.1's phase gradient, the QFT rotation +cascades of Problem 5.1/5.2). The empty product `1` needs an identity budget on the register, passed +as `hid` because a general system `S` carries no elementary-gate witness for `1` (its constructors +place gates on qubit registers only); on a qubit tower `hid` is `CircuitBudget.id_qtower`. The +`t₀ = 0, s₀ = 1` specialisation of the general uniform fold `CircuitBudget.listProd_uniform` +(`l.length * 0 = 0`, `l.length * 1 = l.length`). -/ +theorem CircuitBudget.listProd {S : QSystem} (hid : CircuitBudget (1 : Evolution S) 0 0) + (l : List (Evolution S)) (h : ∀ E ∈ l, CircuitBudget E 0 1) : + CircuitBudget l.prod 0 l.length := by + simpa using CircuitBudget.listProd_uniform hid l h + +/-- **The identity on a qubit tower is a zero-gate circuit.** +`CircuitBudget (1 : Evolution (qtower n qubit)) 0 0` — the identity evolution on the `(n+1)`-qubit +control tower has budget `0 0`, since it is the empty circuit. Proved from the empty-list `block` +leaf `CircuitBudget (1 : Evolution (qubit ^⊗ₛ (n+1))) 0 0` (the classical circuit `[]` realises `1`, +`mcNotDenote_nil`), transported off the tensor power back onto the tower along the bridge +`qtowerQubitTensorPow n` (the transport of `1` is `1`, `Evolution.congr_one`). This is the +register-identity base the product fold `CircuitBudget.listProd` consumes on a tower. -/ +theorem CircuitBudget.id_qtower (n : ℕ) : CircuitBudget (1 : Evolution (qtower n qubit)) 0 0 := by + have hblk : CircuitBudget (1 : Evolution (qubit.tensorPow (n + 1))) 0 0 := by + have h := CircuitBudget.block ([] : List (Concrete.McNotGate (n + 1))) + (1 : Evolution (qubit.tensorPow (n + 1))) (by simp) (by + intro c + erw [Evolution.one_def, Evolution.id_evolvePure] + simp only [Concrete.mcNotDenote_nil] + rfl) + simpa using h + rw [← Evolution.congr_one (qtowerQubitTensorPow n).symm] + exact CircuitBudget.congr (IsWireReindexing.qtowerQubitTensorPow n).symm hblk + +/-- **The identity on the `2ⁿ⁺¹`-level qudit register is a zero-gate circuit.** +`CircuitBudget (1 : Evolution (qudit (2ⁿ⁺¹))) 0 0` — the register-identity base the product folds +`CircuitBudget.listProd`/`listProd_uniform` consume on a `qudit (2ⁿ⁺¹)` register, the qudit-side +analogue of `CircuitBudget.id_qtower`. Obtained by transporting the tower identity budget +`id_qtower` back onto the register along the register↔tower bridge `quditPowTower n` +(`CircuitBudget.congr`), the transport of `1` being `1` (`Evolution.congr_one`). This is the base +every wire-by-wire register layer needs on `qudit (2ⁿ⁺¹)` — e.g. the Problem 4.3(6) Trotter step +`pauliTrotterStep_circuitBudget` and its `k`-fold power. -/ +theorem CircuitBudget.id_qudit (n : ℕ) : + CircuitBudget (1 : Evolution (qudit (2 ^ (n + 1)))) 0 0 := by + rw [← Evolution.congr_one (quditPowTower n).symm] + exact CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm (CircuitBudget.id_qtower n) + +/-- **Problem 4.1's phase layer is `n+1` single-qubit gates.** For any per-wire angles +`φ : Fin (n+1) → ℝ`, the phase-gradient layer `phaseGradientLayer (n+1) φ` on the `(n+1)`-qubit +ancilla register `qudit (2ⁿ⁺¹)` — the product of the `n+1` single-wire phase gates +`phaseWireEvolution (n+1) t (φ t)` — has budget + +`CircuitBudget (phaseGradientLayer (n+1) φ) 0 (n+1)`: + +at most `n+1` single-qubit gates and **no** `≤ 2`-control gates. This is the `n` (here the ancilla +size `n+1`) of Problem 4.1's `2T + n` gate count, made a genuine `CircuitBudget`. + +Proof: transport the layer onto the qubit control tower via +`quditPowTower_congr_phaseGradientLayer`, where it is the ordered product of the `n+1` single-wire +gates +`qtowerSingleWire n t.rev (phaseShiftGate (φ t))`, each budgeted `0 1` by +`qtowerSingleWire_circuitBudget`; fold those with `CircuitBudget.listProd` (base +`CircuitBudget.id_qtower`) to get budget `0 (n+1)` for the tower product; then carry the budget back +off the tower using the inverse wire reindexing and `Evolution.congr_symm_congr`. -/ +theorem phaseGradientLayer_circuitBudget (n : ℕ) (φ : Fin (n + 1) → ℝ) : + CircuitBudget (phaseGradientLayer (n + 1) φ) 0 (n + 1) := by + -- Rewrite the goal, via the tower round-trip, to the transported layer — the product of `n+1` + -- single-wire phase gates — on the tower, then budget that product wire-by-wire. + rw [← Evolution.congr_symm_congr (quditPowTower n) (phaseGradientLayer (n + 1) φ), + quditPowTower_congr_phaseGradientLayer] + refine CircuitBudget.congr (IsWireReindexing.quditPowTower n).symm ?_ + have hbud := CircuitBudget.listProd (CircuitBudget.id_qtower n) + ((List.finRange (n + 1)).map + (fun t => Evolution.qtowerSingleWire n t.rev (phaseShiftGate (φ t)))) + (by + intro E hE + simp only [List.mem_map] at hE + obtain ⟨t, -, rfl⟩ := hE + exact qtowerSingleWire_circuitBudget n t.rev (phaseShiftGate (φ t))) + rwa [List.length_map, List.length_finRange] at hbud + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PhaseWireTower.lean b/LeanPool/AxQM/Core/PhaseWireTower.lean new file mode 100644 index 0000000000..e42d52f5f0 --- /dev/null +++ b/LeanPool/AxQM/Core/PhaseWireTower.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PhaseWire +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.TowerProdMultilinear +public import LeanPool.AxQM.Core.QtowerSingleWireGate +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.QftTowerBasis + +/-! +# Register phase-wire gates as single-qubit phase gates on a tower wire (N&C Problem 4.1, gate-count +bridge) + +Problem 4.1's phase layer `D = diagPhase (computablePhaseAngle n)` is, in the textbook construction, +**`n` single-qubit phase gates** — one on each wire of the `n`-qubit ancilla register. The register +side of that decomposition is `phaseGradientLayer n φ` (`Postulates/API/PhaseWire`): the product of +the `n` single-wire phase gates `phaseWireEvolution n t (φ t)` on the *flat* `2ⁿ`-level register +`qudit (2ⁿ)`. The elementary-gate cost model `CircuitBudget` (`Core/CircuitBudget`) instead counts +gates on the **qubit control tower** `qtower n qubit`, where a single-qubit gate is placed by +`Evolution.qtowerSingleWire`. This file supplies the missing register bridge: it transports each +register phase-wire gate — and the whole phase-gradient layer — across the register isomorphism +`quditPowTower n : qudit (2ⁿ⁺¹) ≃ₛ qtower n qubit` onto the tower, where the budget lives. + +* `quditPowTower_congr_phaseWireEvolution` — **the per-wire bridge**: transporting the register + gate `phaseWireEvolution (n+1) t φ` onto the tower gives exactly the grounded single-qubit phase + gate `phaseShiftGate φ` placed on tower wire `t.rev`: + + `Evolution.congr (quditPowTower n) (phaseWireEvolution (n+1) t φ)` + `= Evolution.qtowerSingleWire n t.rev (phaseShiftGate φ)`. + + The phase analogue of `quditPowTower_congr_rotZWireEvolution`, with the `z`-rotation replaced by + the phase gate `P(φ) = diag(1, e^{iφ})`. Because the phase gate is *diagonal*, its basis action + has no off-diagonal branch: on each computational tower ket `towerKet n b` both sides equal the + single scalar multiple `(e^{iφ})^{b t.rev} · towerKet n b`, so the proof is a one-scalar + computation rather than the two-term rotation sum. + +* `quditPowTower_congr_phaseGradientLayer` — **the layer bridge**: transporting the whole + phase-gradient layer `phaseGradientLayer (n+1) φ` gives the ordered product of the `n+1` + single-wire phase gates on the tower, + + `Evolution.congr (quditPowTower n) (phaseGradientLayer (n+1) φ)` + `= ((List.finRange (n+1)).map fun t => qtowerSingleWire n t.rev (phaseShiftGate (φ t))).prod`. + + This exhibits Problem 4.1's phase layer, read on the tower, as literally the composition of `n+1` + single-qubit phase gates — the `n` of the exercise's `2T + n` gate count, now on the register the + `CircuitBudget` accountant operates on. It follows from the per-wire bridge and the monoid-hom + property `Evolution.congr_prod` of the transport. + +The proof mirrors that of `quditPowTower_congr_rotZWireEvolution` in +`AxQM/Core/FourGateReachableWireTower.lean`; the wire gate `phaseWireEvolution` and its diagonal +basis action are defined in `AxQM/Postulates/API/PhaseWire.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +noncomputable section + +/-- **The transported register phase-wire gate is the grounded phase gate on tower wire `t.rev`.** +Transporting the register gate `phaseWireEvolution (n+1) t φ` (the single-qubit phase gate +`P(φ) = diag(1, e^{iφ})` on register wire `t`) onto the `(n+1)`-qubit control tower via the register +bridge `quditPowTower n` yields exactly the single-wire gate applying the grounded phase gate +`phaseShiftGate φ` to tower wire `t.rev`: + + `Evolution.congr (quditPowTower n) (phaseWireEvolution (n+1) t φ)` + `= Evolution.qtowerSingleWire n t.rev (phaseShiftGate φ)`. + +The phase analogue of `quditPowTower_congr_rotZWireEvolution`, with the `z`-rotation block replaced +by the phase gate. Because `P(φ)` is diagonal, its basis action has no off-diagonal branch: on each +computational tower ket `towerKet n b`, the single-wire side scales wire `t.rev` by +`(e^{iφ})^{b t.rev}` (`phaseShiftGate_evolvePure_qubitBasis`, pulled through the tower product by +the shared single-wire multilinearity `towerProd_vec_update_smul`), and the register side scales +`|f⟩` by the same `(e^{iφ})^{f t}` with +`f = b ∘ Fin.rev` (`phaseWireEvolution_evolvePure_quditBasis`); both are +`(e^{iφ})^{b t.rev} · towerKet n b` (the `Fin.rev` reconciling the big-endian register bridge with +the little-endian wire indexing, `quditPowTower_congr_quditBasis_rev`). -/ +theorem quditPowTower_congr_phaseWireEvolution (n : ℕ) (t : Fin (n + 1)) (φ : ℝ) : + Evolution.congr (quditPowTower n) (phaseWireEvolution (n + 1) t φ) + = Evolution.qtowerSingleWire n t.rev (phaseShiftGate φ) := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + -- `phaseShiftGate φ` on wire `t.rev` scales by the single diagonal phase `(e^{iφ})^{b t.rev}` + -- (`phaseShiftGate_evolvePure_qubitBasis`), pulled through the tower product by + -- `towerProd_vec_update_smul`; the register side scales `|f⟩` by the same power. + rw [qtowerSingleWire_evolvePure_towerKet, + towerProd_vec_update_smul n (fun j => qubitBasis (b j)) t.rev + (Complex.exp ((φ : ℂ) * Complex.I) ^ ((b t.rev : Fin 2) : ℕ)) + ((phaseShiftGate φ).evolvePure (qubitBasis (b t.rev))) + (phaseShiftGate_evolvePure_qubitBasis φ (b t.rev)), + ← towerKet_eq_towerProd, PureState.congr_vec, phaseWireEvolution_evolvePure_quditBasis, + map_smul, ← PureState.congr_vec, quditPowTower_congr_quditBasis_rev] + +/-- **The transported phase-gradient layer is the ordered product of single-wire phase gates on the +tower.** Transporting the whole register phase-gradient layer `phaseGradientLayer (n+1) φ` — the +product of the `n+1` single-wire phase gates on the flat register `qudit (2ⁿ⁺¹)` — onto the qubit +control tower `qtower n qubit` yields the ordered product of the `n+1` single-qubit phase gates +`phaseShiftGate (φ t)` placed on tower wire `t.rev`: + + `Evolution.congr (quditPowTower n) (phaseGradientLayer (n+1) φ)` + `= (List.finRange (n+1)).map (fun t => qtowerSingleWire n t.rev (phaseShiftGate (φ t)))).prod`. + +This is Problem 4.1's phase layer, read on the tower, as **literally the composition of `n+1` +single-qubit phase gates** — the `n` single-qubit gates of the exercise's `2T + n` count, now placed +on the register the `CircuitBudget` accountant counts gates on. It follows from the per-wire bridge +`quditPowTower_congr_phaseWireEvolution` and the monoid-homomorphism property `Evolution.congr_prod` +of the register transport (which pushes the transport through the list product gate-by-gate). -/ +theorem quditPowTower_congr_phaseGradientLayer (n : ℕ) (φ : Fin (n + 1) → ℝ) : + Evolution.congr (quditPowTower n) (phaseGradientLayer (n + 1) φ) + = ((List.finRange (n + 1)).map + (fun t => Evolution.qtowerSingleWire n t.rev (phaseShiftGate (φ t)))).prod := by + rw [phaseGradientLayer, Evolution.congr_prod, List.map_map] + refine congrArg List.prod (List.map_congr_left fun t _ => ?_) + simpa only [Function.comp_apply] using quditPowTower_congr_phaseWireEvolution n t (φ t) + +end + +end AxQM diff --git a/LeanPool/AxQM/Core/PiTensorSuccHead.lean b/LeanPool/AxQM/Core/PiTensorSuccHead.lean new file mode 100644 index 0000000000..c37f40a3ec --- /dev/null +++ b/LeanPool/AxQM/Core/PiTensorSuccHead.lean @@ -0,0 +1,91 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PiTensorSuccHead +public import LeanPool.AxQM.Postulates.API.Qubit + +/-! +# Head-peel recursion for the indexed product state `State.piTensor` + +Lifting the head-peel conjugation +`QSystem.tensorPowSuccHeadIsometry_symm_conj` (`Postulates/API/PiTensorSuccHead`) to the level of +**product states**, this file gives the missing `succ`-recursion for the indexed product (mixed) +state `State.piTensor`: + +`⨂ₚ i, f i = (f 0) ⊗ (⨂ₚ j, f j.succ)` (transported along the head-peel). + +It is the `State` companion of the pure-state head-peel action lemmas, and the structural step +behind any induction over the number of tensor factors of a mixed product state — in particular the +`n`-fold subadditivity of the Holevo χ quantity underlying the HSW converse single-letterisation +(N&C Theorem 12.8). + +The proof uses `QSystem.tensorPowSuccHeadIsometry_symm_conj` from +`AxQM/Postulates/API/PiTensorSuccHead.lean`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Head-peel recursion for `State.piTensor`** (the `cons` direction). Transporting the product +state `(f 0) ⊗ (⨂ⱼ f j.succ)` on `S ⊗ S ^⊗ₛ n` *backwards* along the head-peel isomorphism +`QSystem.tensorPowSuccHead S n` reconstructs the full `(n+1)`-fold product state `⨂ᵢ f i` on +`S ^⊗ₛ (n+1)`: + +`((f 0) ⊗ (⨂ⱼ f j.succ)).congr (QSystem.tensorPowSuccHead S n).symm = ⨂ᵢ f i`. + +The `State`-level analogue of `QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod`; the structural +`succ` step for an induction over the tensor factors of a mixed product state. Reduces, via +`State.congr_op`/`State.tmul_op`/`State.piTensor_op`, to +`QSystem.tensorPowSuccHeadIsometry_symm_conj`. -/ +theorem State.tmul_piTensor_congr_tensorPowSuccHead_symm {n : ℕ} (f : Fin (n + 1) → State S) : + ((f 0).tmul (State.piTensor fun j : Fin n => f j.succ)).congr + (QSystem.tensorPowSuccHead S n).symm + = State.piTensor f := by + apply State.ext + erw [State.congr_op, State.tmul_op, State.piTensor_op, State.piTensor_op, + QSystem.Iso.symm_toIsometry] + exact QSystem.tensorPowSuccHeadIsometry_symm_conj S n fun i => (f i).op + +/-- **`PureState` head-peel of the tensor-power head split.** `⨂ₚ ᵢ ψ i ↦ ψ 0 ⊗ (⨂ₚ ⱼ ψ j.succ)`: +transporting a product state along `QSystem.tensorPowSuccHead qubit m` peels the head factor off the +front. The pure-state companion of `State.tmul_piTensor_congr_tensorPowSuccHead_symm` (forward +direction); reduces, via `PureState.congr_vec`/`piTensor_vec`/`tmul_vec`, to the isometry action +`QSystem.tensorPowSuccHead_toIsometry_tprod`. -/ +theorem tensorPowSuccHead_congr_piTensor (m : ℕ) (ψ : Fin (m + 1) → PureState qubit) : + PureState.congr (QSystem.tensorPowSuccHead qubit m) (PureState.piTensor ψ) + = (ψ 0).tmul (PureState.piTensor fun j => ψ j.succ) := by + apply PureState.ext + erw [PureState.congr_vec, PureState.piTensor_vec, PureState.tmul_vec, PureState.piTensor_vec] + rw [QSystem.tensorPowSuccHead_toIsometry_tprod] + rfl + +/-- **`PureState` `cons` of the inverse tensor-power head split.** +`a ⊗ (⨂ₚ ⱼ φ j) ↦ ⨂ₚ ᵢ (Fin.cons a φ) i`: transporting along `(tensorPowSuccHead qubit m).symm` +prepends a head factor `a` to the tail product `⨂ₚ φ`. The pure-state `cons` companion of +`State.tmul_piTensor_congr_tensorPowSuccHead_symm`; reduces to the isometry action +`QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod`. -/ +theorem tensorPowSuccHead_symm_congr_tmul_piTensor (m : ℕ) (a : PureState qubit) + (φ : Fin m → PureState qubit) : + PureState.congr (QSystem.tensorPowSuccHead qubit m).symm (a.tmul (PureState.piTensor φ)) + = PureState.piTensor (Fin.cons a φ) := by + apply PureState.ext + erw [PureState.congr_vec, PureState.tmul_vec, PureState.piTensor_vec, PureState.piTensor_vec, + QSystem.Iso.symm_toIsometry, QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod] + congr 1 + exact (Fin.comp_cons PureState.vec a φ).symm + +end AxQM diff --git a/LeanPool/AxQM/Core/PlacedMultiControlledX.lean b/LeanPool/AxQM/Core/PlacedMultiControlledX.lean new file mode 100644 index 0000000000..31527af9f4 --- /dev/null +++ b/LeanPool/AxQM/Core/PlacedMultiControlledX.lean @@ -0,0 +1,208 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.TensorPowMultiControlledX +public import LeanPool.AxQM.Core.EvolutionQubitBasisExt +public import LeanPool.AxQM.Postulates.API.WireGatePlacement + +/-! +# Placing `Cᵏ(X)` on a chosen set of wires (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The recursive Barenco construction (Exercise +4.30's `barencoNCircuit`, and the classical halving circuit of `Concrete/MultiControlledNot*`) +bottoms out into a sequence of multiply-controlled `NOT` blocks `Cᵏ(X)` (`k ≤ 2` are exactly the +`Toffoli`/`CNOT`/`NOT` gates), **each acting on a chosen, non-contiguous set of `k + 1` wires** of +the register. This file turns such a block into a genuine closed-system `Evolution`. + +Two earlier constructions provide the two halves: + +* `Evolution.tensorPowMcCtrlX k : Evolution (qubit ^⊗ₛ (k+1))` — the grounded `Cᵏ(X)` + transported onto the symmetric power, with computational-basis action + `tensorPowMcCtrlX_evolvePure_piTensor` equal to the classical `Concrete.mcNot (cnxControls k) + (Fin.last k)`; +* `Evolution.onWires G b σ` — placing a gate `G : Evolution (qubit ^⊗ₛ a)` on the wire + set `σ '' (front a wires)` of `qubit ^⊗ₛ (a+b)`, with the computational-basis truth table + `Evolution.onWires_evolvePure_qubitBasis` for a classical `G`. + +Feeding the classical `Cᵏ(X)` gate into the placement combinator realises `Cᵏ(X)` on any chosen +wires; reading off its truth table is the wire-addressed multiply-controlled `NOT` the circuit +assembly composes. + +## What is formalised + +* `Evolution.placedMcCtrlX k b σ` — the `Cᵏ(X)` gate (`k` controls, one target = `k + 1` wires) + placed on the `(k+1)`-wire set `σ 0, …, σ k` of the `(k+1+b)`-wire register `qubit ^⊗ₛ (k+1+b)`, + built as `(Evolution.tensorPowMcCtrlX k).onWires b σ`. A genuine closed-system `Evolution` on the + whole register — no work qubit beyond the `b` ambient wires it acts on as identity. +* `placedMcCtrlX_evolvePure_qubitBasis` — its **computational-basis truth table**: it acts on the + product basis `⨂ₖ |c k⟩` exactly as the classical multiply-controlled `NOT` + `Concrete.mcNot Cσ tσ` whose controls `Cσ = (cnxControls k).image (σ ∘ Fin.castAdd b)` are the + images of the `k` front control wires and whose target `tσ = σ (Fin.castAdd b (Fin.last k))` is + the image of the front target wire. So the placed quantum `Cᵏ(X)` **is** the reversible bit-string + permutation that flips wire `tσ` iff every control wire in `Cσ` is set — the wire-addressed + `Toffoli`/`CNOT`/`NOT` truth table the assembly uses. + +The wire assignment is carried by the permutation `σ`, an explicit input; choosing `σ` to gather a +prescribed control set `C` and target `t` onto the front block (so `Cσ = C`, `tσ = t`) is a +`Finset`-level construction that is not carried out in this file. + +Two further facts specialise the placement to the case in which the target wires already are the +leading `k + 1` wires (the shape a Barenco `Cᵏ(X)` block takes once the control tower is flattened): + +* `Evolution.placedMcCtrlX_one` — at the identity permutation the placement is the block embedding + `(Evolution.tensorPowMcCtrlX k).onBlock b` (`Evolution.onWires_one`); +* `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis` — its computational-basis truth table, flipping + the front target wire `Fin.castAdd b (Fin.last k)` iff the front controls + `(cnxControls k).image (Fin.castAdd b)` are all set. + +## Design notes + +* **Why `σ`-parametrised, not `(C, t)`-parametrised.** `Evolution.onWires` already takes the wire + permutation as input, and its truth table `onWires_evolvePure_qubitBasis` is stated over that + permutation. Reading the placed gate's controls/target *off* `σ` (as `Cσ`/`tσ`) keeps this a + one-step specialisation of the placement dictionary, with no `Finset`→permutation + construction; the reverse direction — build `σ` realising a *given* `(C, t)` — is a separate + combinatorial step (order-isos of `C ∪ {t}` and its complement) belonging to the assembly, where + the wires are concretely given. +* **The truth-table proof.** `onWires_evolvePure_qubitBasis` (with `γ = mcNot (cnxControls k) + (Fin.last k)` and `hG = tensorPowMcCtrlX_evolvePure_piTensor k`) rewrites the placed gate's action + to `⨂ₖ |Fin.append (γ (c ∘ σ ∘ castAdd)) (c ∘ σ ∘ natAdd) (σ⁻¹ k)⟩`. Substituting `k = σ p` and + casing `p` over `Fin.addCases`: on the front target wire (`p = castAdd (Fin.last k)`) both sides + flip by the same control bit — the classical `ctrlBit` matches through the relabelling by + `Concrete.ctrlBit_image`; on a front control wire (`p = castAdd j`, `j ≠ last`) and on an ambient + wire (`p = natAdd j`) neither side touches the bit (`mcNot_apply_of_ne`, the two wires distinct + from `tσ` by injectivity of `σ` and `Fin.castAdd`, and `natAdd ≠ castAdd`). +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **`Cᵏ(X)` placed on a chosen set of wires.** Given a wire permutation +`σ : Equiv.Perm (Fin (k + 1 + b))`, the multiply-controlled `NOT` `Cᵏ(X)` (`k` controls, one target, +so `k + 1` wires) placed on the wire set `σ 0, …, σ k` of the `(k+1+b)`-wire register +`qubit ^⊗ₛ (k+1+b)`, built by placing the symmetric-register `Cᵏ(X)` gate +`Evolution.tensorPowMcCtrlX k` via the arbitrary-wire combinator `Evolution.onWires`. A genuine +closed-system `Evolution` acting as `Cᵏ(X)` on its `k + 1` target wires and as the identity on the +other `b`. For `k ≤ 2` this is a `Toffoli`/`CNOT`/`NOT` addressed to arbitrary wires; its +computational-basis truth table is `placedMcCtrlX_evolvePure_qubitBasis`. -/ +def Evolution.placedMcCtrlX (k b : ℕ) (σ : Equiv.Perm (Fin (k + 1 + b))) : + Evolution (qubit ^⊗ₛ (k + 1 + b)) := + (Evolution.tensorPowMcCtrlX k).onWires b σ + +/-- Definitional unfolding of `Evolution.placedMcCtrlX` as the placed symmetric-register `Cᵏ(X)`. -/ +theorem Evolution.placedMcCtrlX_def (k b : ℕ) (σ : Equiv.Perm (Fin (k + 1 + b))) : + Evolution.placedMcCtrlX k b σ = (Evolution.tensorPowMcCtrlX k).onWires b σ := + rfl + +/-- **Computational-basis truth table of the placed `Cᵏ(X)`.** The gate `Evolution.placedMcCtrlX k b +σ` acts on the computational product basis state `⨂ₖ |c k⟩` exactly as the classical +multiply-controlled `NOT` `Concrete.mcNot Cσ tσ`, whose controls +`Cσ = (cnxControls k).image (fun j => σ (Fin.castAdd b j))` are the wires the `k` front +controls are relabelled to, and whose target `tσ = σ (Fin.castAdd b (Fin.last k))` is the wire the +front target is relabelled to: +`placedMcCtrlX k b σ (⨂ₖ |c k⟩) = ⨂ₖ |mcNot Cσ tσ c k⟩`. + +So the placed quantum `Cᵏ(X)` **is** the reversible bit-string permutation that flips wire `tσ` iff +every wire in `Cσ` is set — the wire-addressed `Toffoli`/`CNOT`/`NOT` truth table the `O(n²)` +circuit assembly composes. Proved from the placement dictionary +`Evolution.onWires_evolvePure_qubitBasis` with classical action +`Concrete.mcNot (cnxControls k) (Fin.last k)` supplied by the symmetric-register truth table +`tensorPowMcCtrlX_evolvePure_piTensor`, then a wire-by-wire comparison over +`Fin.addCases`. -/ +theorem placedMcCtrlX_evolvePure_qubitBasis (k b : ℕ) (σ : Equiv.Perm (Fin (k + 1 + b))) + (c : Fin (k + 1 + b) → Fin 2) : + (Evolution.placedMcCtrlX k b σ).evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => + qubitBasis (Concrete.mcNot ((cnxControls k).image fun j => σ (Fin.castAdd b j)) + (σ (Fin.castAdd b (Fin.last k))) c i) := by + rw [Evolution.placedMcCtrlX_def, + Evolution.onWires_evolvePure_qubitBasis (Evolution.tensorPowMcCtrlX k) b σ + (Concrete.mcNot (cnxControls k) (Fin.last k)) + (tensorPowMcCtrlX_evolvePure_piTensor k) c] + refine congrArg PureState.piTensor ?_ + funext i + refine congrArg qubitBasis ?_ + obtain ⟨p, rfl⟩ : ∃ p, i = σ p := ⟨σ.symm i, (σ.apply_symm_apply i).symm⟩ + rw [Equiv.symm_apply_apply] + induction p using Fin.addCases with + | left j => + rw [Fin.append_left] + by_cases hj : j = Fin.last k + · subst hj + simp only [Concrete.mcNot_apply_self, Concrete.ctrlBit_image] + · have hne : σ (Fin.castAdd b j) ≠ σ (Fin.castAdd b (Fin.last k)) := + fun h => hj (Fin.castAdd_injective _ _ (σ.injective h)) + rw [Concrete.mcNot_apply_of_ne _ _ _ hj, + Concrete.mcNot_apply_of_ne _ _ _ hne] + | right j => + rw [Fin.append_right] + have hne : σ (Fin.natAdd (k + 1) j) ≠ σ (Fin.castAdd b (Fin.last k)) := by + apply σ.injective.ne + simp [Fin.ext_iff]; omega + rw [Concrete.mcNot_apply_of_ne _ _ _ hne] + +/-- **The placed `Cᵏ(X)` gate depends only on its wire data `(Cσ, tσ)`.** If two wire permutations +`σ, τ : Equiv.Perm (Fin (k + 1 + b))` gather the `k` front control wires onto the same control set +(`Cσ = (cnxControls k).image (σ ∘ Fin.castAdd b)`) and the front target wire onto the same target +(`tσ = σ (Fin.castAdd b (Fin.last k))`), then the placement gates `Evolution.placedMcCtrlX k b σ` +and `Evolution.placedMcCtrlX k b τ` are **equal**. + +This turns the wire-data reading of `placedMcCtrlX_evolvePure_qubitBasis` into a genuine `Evolution` +identity via the computational-basis extensionality `Evolution.ext_qubitBasis`: both gates are +classical (basis-permuting) and their truth tables `mcNot Cσ tσ` / `mcNot Cτ tτ` coincide under the +hypotheses, so agreement on every basis state forces the gates equal. It certifies that the placed +`Cᵏ(X)` is well-defined as a function of the *abstract* control set and target wire — not of the +particular gathering permutation — which is exactly what the circuit-assembly stage relies on when +it constructs a `σ` realising a prescribed `(C, t)` (the design note of `placedMcCtrlX`). -/ +theorem Evolution.placedMcCtrlX_congr {k b : ℕ} {σ τ : Equiv.Perm (Fin (k + 1 + b))} + (hC : ((cnxControls k).image fun j => σ (Fin.castAdd b j)) + = (cnxControls k).image fun j => τ (Fin.castAdd b j)) + (ht : σ (Fin.castAdd b (Fin.last k)) = τ (Fin.castAdd b (Fin.last k))) : + Evolution.placedMcCtrlX k b σ = Evolution.placedMcCtrlX k b τ := by + refine Evolution.ext_qubitBasis fun c => ?_ + rw [placedMcCtrlX_evolvePure_qubitBasis, placedMcCtrlX_evolvePure_qubitBasis, hC, ht] + +/-- **`Cᵏ(X)` placed by the identity permutation is the contiguous front-block gate.** With the +identity wire permutation the `k + 1` target wires stay the front block, so the placement +`Evolution.placedMcCtrlX` degenerates to the block-embedded symmetric-register `Cᵏ(X)`: +`Evolution.placedMcCtrlX k b 1 = (Evolution.tensorPowMcCtrlX k).onBlock b`. Immediate from +`Evolution.onWires_one`. This is the shape a `Cᵏ(X)` block whose controls-and-target *already* are +the leading `k + 1` wires takes — for instance the multiply-controlled `NOT` blocks +`mcCtrl k (pauliXGate.onLeft M)` of the Barenco reduction (Exercise 4.30's `barencoNCircuit`), whose +controls are the outer tower wires and whose idle target-module `M` is the inner block. -/ +theorem Evolution.placedMcCtrlX_one (k b : ℕ) : + Evolution.placedMcCtrlX k b 1 = (Evolution.tensorPowMcCtrlX k).onBlock b := by + rw [Evolution.placedMcCtrlX_def, Evolution.onWires_one] + +/-- **Computational-basis truth table of the block-embedded `Cᵏ(X)`.** The contiguous front-block +placement `(Evolution.tensorPowMcCtrlX k).onBlock b` on `qubit ^⊗ₛ (k+1+b)` acts on the product +basis state `⨂ₖ |c k⟩` exactly as the classical multiply-controlled `NOT` flipping the front target +wire `Fin.castAdd b (Fin.last k)` iff every front control wire — the set +`(cnxControls k).image (Fin.castAdd b)` — is set: +`onBlock b (⨂ₖ |c k⟩) = ⨂ₖ |mcNot ((cnxControls k).image (castAdd b)) (castAdd b (last k)) c k⟩`. +The special case of `placedMcCtrlX_evolvePure_qubitBasis` at the identity permutation +(`placedMcCtrlX_one`), where the wire images `σ ∘ Fin.castAdd b` collapse to `Fin.castAdd b`. -/ +theorem tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis (k b : ℕ) (c : Fin (k + 1 + b) → Fin 2) : + ((Evolution.tensorPowMcCtrlX k).onBlock b).evolvePure + (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => + qubitBasis (Concrete.mcNot ((cnxControls k).image (Fin.castAdd b)) + (Fin.castAdd b (Fin.last k)) c i) := by + rw [← Evolution.placedMcCtrlX_one, placedMcCtrlX_evolvePure_qubitBasis] + simp only [Equiv.Perm.coe_one, id_eq] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Core/ProductStateAvgAchievable.lean b/LeanPool/AxQM/Core/ProductStateAvgAchievable.lean new file mode 100644 index 0000000000..240a6cccf9 --- /dev/null +++ b/LeanPool/AxQM/Core/ProductStateAvgAchievable.lean @@ -0,0 +1,272 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ProductStateCapacity +public import LeanPool.AxQM.Core.ProductStateCodeExpurgation +public import LeanPool.AxQM.Core.ProductStateCodePrettyGood +public import LeanPool.AxQM.Core.ChannelHolevoChi +public import LeanPool.AxQM.ToMathlib.Analysis.SpecificLimits.ExpNatMul + +/-! +# From average-error codes to an achievable rate (N&C Theorem 12.8, achievability, eq. (12.83)) + +The random-coding half of the Holevo–Schumacher–Westmoreland theorem (Nielsen & Chuang, +Theorem 12.8) produces, for every rate `R < χ(E)`, a family of product-state codes whose **average** +error probability `p_av` tends to `0` (the culmination of the error estimate of Box 12.5, +eqs. (12.72)–(12.82)). Operational achievability, however, is stated with the **maximum** error +probability (`IsProductStateAchievableRate`, `AxQM/Core/ProductStateCapacity.lean`): Bob must decode +*every* message reliably. N&C's closing paragraph after eq. (12.83) bridges the two by +**expurgation** — discard the worse half of the codewords — at an asymptotically negligible rate +cost. + +This file formalises both that bridge and the random-coding bound feeding it, as code-level +statements: + +* `AxQM.IsProductStateAvgAchievableRate E R` — the **average-error analogue** of + `IsProductStateAchievableRate`: a family of product-state codes + `codeₙ : ProductStateCode E n ⌈exp (n·R)⌉₊` whose *average* error `avgError` tends to `0`. + +* `AxQM.isProductStateAvgAchievableRate_of_lt_channelHolevoChi` — the **random-coding + bound** (Box 12.5, eqs. (12.72)–(12.83)): every rate `R < χ(E)` is average-achievable. From + `χ(E) = sSup` of the output-ensemble χ's it picks a near-optimal input ensemble with output χ + `> R`, feeds the derandomized per-block bound + `ProductStateCode.exists_const_avgError_prettyGood_le` + a rate-`R` message count `K = ⌈eⁿᴿ⌉₊`, and squeezes the resulting + `p_bar ≤ C/n + (K−1)·exp(−n(χ₀−2ε))` to `0` (the confusion exponent stays negative because + `K−1 < eⁿᴿ`). See its docstring for the three steps. + +* `AxQM.IsProductStateAvgAchievableRate.isProductStateAchievableRate_of_lt` — the + **bridge**: if `R` is average-achievable then every strictly smaller rate `R' < R` is achievable + (`IsProductStateAchievableRate E R'`). + + The strict inequality is intrinsic to the expurgation, exactly as in N&C: expurgation halves the + codebook, losing a factor of two in the message count (an asymptotically vanishing rate cost that + a strictly smaller target rate absorbs). Concretely, for each block length `n`: + + 1. **Expurgate** the average-error code `codeₙ` (`ProductStateCode.exists_expurgated`, + N&C eq. (12.83)): a subcode `c'ₙ` on `K'ₙ` messages with `⌈eⁿᴿ⌉ ≤ 2·K'ₙ` (at least half the + messages survive) and `maxError c'ₙ ≤ 2·avgError codeₙ`. + 2. **Count**: since `K'ₙ ≥ ⌈eⁿᴿ⌉/2 ≥ eⁿᴿ/2` and `⌈eⁿᴿ'⌉ ≤ eⁿᴿ' + 1`, for large `n` the target + message count `⌈eⁿᴿ'⌉` is `≤ K'ₙ` (because `eⁿᴿ'/eⁿᴿ = e⁻ⁿ⁽ᴿ⁻ᴿ'⁾ → 0` when `R > 0`; when + `R ≤ 0` both counts collapse to `1`). + 3. **Truncate** `c'ₙ` to its first `⌈eⁿᴿ'⌉` messages (`ProductStateCode.truncate`, + `truncate_maxError_le`): a genuine rate-`R'` code whose maximum error is + `≤ maxError c'ₙ ≤ 2·avgError codeₙ → 0`. (For the finitely many small `n` where the count + bound fails, any code — a one-outcome junk decoder — serves; the limit is unaffected.) + + A squeeze on `0 ≤ maxErrorₙ ≤ 2·avgError codeₙ → 0` gives `maxError → 0`, i.e. `R'` achievable. + +It builds on `AxQM/Core/ProductStateCapacity.lean` and `AxQM/Core/ProductStateCodeExpurgation.lean`. +-/ + +@[expose] public section + +open Filter Topology +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- A **junk product-state code**: encode every message to an arbitrary input state and always +announce the inconclusive outcome `none`. It conveys no information; it only fills the +finitely-many block lengths a code family leaves otherwise unconstrained — `n = 0`, or the small `n` +where a count bound fails — which do not affect the `n → ∞` error limit. `[Nonempty (State S)]` +supplies the (irrelevant) input state the encoder must name. The decoder is +`certainMeasurement none`. -/ +def ProductStateCode.junk [Nonempty (State S)] (E : State S → State S) (n K : ℕ) : + ProductStateCode E n K where + encoder := fun _ _ => Classical.arbitrary (State S) + decoder := certainMeasurement none + +/-- A rate `R` (in **nats** per channel use) is **average-achievable** for the memoryless channel +`E` when there is a family of product-state codes `codeₙ : ProductStateCode E n ⌈exp (n·R)⌉₊`, one +per block length `n`, whose *average* error probability `avgError` tends to `0` as `n → ∞`. This is +the average-error analogue of `IsProductStateAchievableRate` (which uses `maxError`) and the natural +output of the random-coding error estimate (Nielsen & Chuang, Theorem 12.8, eqs. (12.72)–(12.82)): +the expected average error over random codebooks tends to `0`, so some codebook achieves it. -/ +def IsProductStateAvgAchievableRate (E : State S → State S) (R : ℝ) : Prop := + ∃ code : (n : ℕ) → ProductStateCode E n ⌈Real.exp ((n : ℝ) * R)⌉₊, + Tendsto (fun n => (code n).avgError) atTop (𝓝 0) + +/-- **The average-error → achievability bridge** (Nielsen & Chuang, Theorem 12.8, the expurgation +paragraph after eq. (12.83)). If a rate `R` is average-achievable for `E`, then every strictly +smaller rate `R' < R` is achievable (`IsProductStateAchievableRate E R'`). + +Expurgation (`ProductStateCode.exists_expurgated`) turns each average-error code into a subcode with +at least half the messages and maximum error at most twice the average; the surviving message count +`K'ₙ ≥ ⌈eⁿᴿ⌉/2` still exceeds the target `⌈eⁿᴿ'⌉` for large `n` (as `R' < R`), so truncating +(`ProductStateCode.truncate`) yields a genuine rate-`R'` code with `maxError → 0`. See the module +docstring for the full argument. `[Nonempty (State S)]` supplies the (irrelevant) input state the +junk codes for small `n` must name. -/ +theorem IsProductStateAvgAchievableRate.isProductStateAchievableRate_of_lt [Nonempty (State S)] + {E : State S → State S} {R R' : ℝ} (hRR : R' < R) (h : IsProductStateAvgAchievableRate E R) : + IsProductStateAchievableRate E R' := by + classical + obtain ⟨code, hcode⟩ := h + -- Expurgate each block: a subcode `c' n` with `⌈eⁿᴿ⌉ ≤ 2·K' n` and `maxError ≤ 2·avgError`. + have hexp : ∀ n : ℕ, ∃ (K' : ℕ) (c' : ProductStateCode E n K'), + ⌈Real.exp ((n : ℝ) * R)⌉₊ ≤ 2 * K' ∧ c'.maxError ≤ 2 * (code n).avgError := by + intro n + have : NeZero ⌈Real.exp ((n : ℝ) * R)⌉₊ := ⟨(Nat.ceil_pos.mpr (Real.exp_pos _)).ne'⟩ + exact (code n).exists_expurgated + choose K' c' hK' hmax using hexp + -- Each block keeps at least one message. + have hKpos : ∀ n : ℕ, 1 ≤ K' n := by + intro n + have h1 : 1 ≤ ⌈Real.exp ((n : ℝ) * R)⌉₊ := Nat.ceil_pos.mpr (Real.exp_pos _) + have h2 := hK' n + omega + -- The target message count `⌈eⁿᴿ'⌉` fits inside the surviving `K' n` for large `n`. + have hcount : ∀ᶠ n : ℕ in atTop, ⌈Real.exp ((n : ℝ) * R')⌉₊ ≤ K' n := by + rcases le_or_gt R 0 with hR0 | hRpos + · -- `R ≤ 0`: then `R' < R ≤ 0`, so `eⁿᴿ' ≤ 1 ≤ K' n` for every `n`. + refine Eventually.of_forall fun n => ?_ + have hle1 : ⌈Real.exp ((n : ℝ) * R')⌉₊ ≤ 1 := by + rw [Nat.ceil_le, Nat.cast_one] + exact Real.exp_le_one_iff.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) n]) + exact le_trans hle1 (hKpos n) + · -- `R > 0`: exponential growth makes `eⁿᴿ'/eⁿᴿ → 0`, so eventually `eⁿᴿ' + 1 ≤ eⁿᴿ/2 ≤ K' n`. + have hftend : Tendsto (fun n : ℕ => + Real.exp ((n : ℝ) * (R' - R)) + Real.exp ((n : ℝ) * (-R))) atTop (𝓝 0) := by + have e1 : Tendsto (fun n : ℕ => Real.exp ((n : ℝ) * (R' - R))) atTop (𝓝 0) := + Real.tendsto_exp_nat_mul_atTop_nhds_zero (by linarith) + have e2 : Tendsto (fun n : ℕ => Real.exp ((n : ℝ) * (-R))) atTop (𝓝 0) := + Real.tendsto_exp_nat_mul_atTop_nhds_zero (by linarith) + simpa using e1.add e2 + have hev : ∀ᶠ n : ℕ in atTop, + Real.exp ((n : ℝ) * (R' - R)) + Real.exp ((n : ℝ) * (-R)) < 1 / 2 := + hftend.eventually (eventually_lt_nhds (by norm_num)) + filter_upwards [hev] with n hn + -- `eⁿᴿ' + 1 = (e^{n(R'-R)} + e^{-nR})·eⁿᴿ < (1/2)·eⁿᴿ`. + have hexpR : (0 : ℝ) < Real.exp ((n : ℝ) * R) := Real.exp_pos _ + have h1 : (n : ℝ) * (R' - R) + (n : ℝ) * R = (n : ℝ) * R' := by ring + have h2 : (n : ℝ) * (-R) + (n : ℝ) * R = 0 := by ring + have hid : Real.exp ((n : ℝ) * R') + 1 = + (Real.exp ((n : ℝ) * (R' - R)) + Real.exp ((n : ℝ) * (-R))) * Real.exp ((n : ℝ) * R) := by + rw [add_mul, ← Real.exp_add, ← Real.exp_add, h1, h2, Real.exp_zero] + have hlt : Real.exp ((n : ℝ) * R') + 1 < Real.exp ((n : ℝ) * R) / 2 := by + rw [hid] + have hmul := mul_lt_mul_of_pos_right hn hexpR + linarith [hmul] + -- `eⁿᴿ/2 ≤ K' n`, from `⌈eⁿᴿ⌉ ≤ 2·K' n`. + have hKR : Real.exp ((n : ℝ) * R) / 2 ≤ (K' n : ℝ) := by + have hc : Real.exp ((n : ℝ) * R) ≤ (⌈Real.exp ((n : ℝ) * R)⌉₊ : ℝ) := Nat.le_ceil _ + have hc2 : (⌈Real.exp ((n : ℝ) * R)⌉₊ : ℝ) ≤ 2 * (K' n : ℝ) := by + exact_mod_cast hK' n + linarith + -- `⌈eⁿᴿ'⌉ < eⁿᴿ' + 1 ≤ eⁿᴿ/2 ≤ K' n`. + have hceil : (⌈Real.exp ((n : ℝ) * R')⌉₊ : ℝ) < Real.exp ((n : ℝ) * R') + 1 := + Nat.ceil_lt_add_one (Real.exp_pos _).le + have : (⌈Real.exp ((n : ℝ) * R')⌉₊ : ℝ) < (K' n : ℝ) := by linarith + exact_mod_cast this.le + -- The junk code for the finitely many small `n` where the count bound fails (any code has + -- `maxError ≤ 1`, so it does not affect the limit). + set junk : (n : ℕ) → ProductStateCode E n ⌈Real.exp ((n : ℝ) * R')⌉₊ := + fun n => ProductStateCode.junk E n ⌈Real.exp ((n : ℝ) * R')⌉₊ with hjunk + -- Build the rate-`R'` family: truncate where possible, junk otherwise. + refine ⟨fun n => + if hn : ⌈Real.exp ((n : ℝ) * R')⌉₊ ≤ K' n then (c' n).truncate hn else junk n, ?_⟩ + -- `maxError → 0` by squeezing `0 ≤ maxErrorₙ ≤ 2·avgError codeₙ`. + have hR0 : Tendsto (fun n => 2 * (code n).avgError) atTop (𝓝 0) := by + simpa using hcode.const_mul (2 : ℝ) + have hub : ∀ᶠ n : ℕ in atTop, + (if hn : ⌈Real.exp ((n : ℝ) * R')⌉₊ ≤ K' n then (c' n).truncate hn + else junk n).maxError ≤ 2 * (code n).avgError := by + filter_upwards [hcount] with n hn + rw [dite_eq_left hn] + exact le_trans ((c' n).truncate_maxError_le hn) (hmax n) + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hR0 + (Eventually.of_forall fun n => ProductStateCode.maxError_nonneg _) hub + +/-- **Every rate below `χ(E)` is average-achievable** — the analytic core of the random-coding +half of the Holevo–Schumacher–Westmoreland theorem (Nielsen & Chuang, Theorem 12.8, Box 12.5, +eqs. (12.72)–(12.83)). For any rate `R < χ(E)` (the channel Holevo χ quantity `channelHolevoChi E`) +there is a family of product-state codes `codeₙ : ProductStateCode E n ⌈eⁿᴿ⌉₊` whose *average* error +probability tends to `0`: `IsProductStateAvgAchievableRate E R`. + +This turns the whole Box 12.5 error estimate into the achievability input the operational assembly +consumes. The three steps of the argument: + +1. **Near-optimal input ensemble.** `χ(E) = sSup` of the output-ensemble χ's (`channelHolevoChi`, + `channelHolevoChiSet`), so `R < χ(E)` gives (`exists_lt_of_lt_csSup`, using + `channelHolevoChiSet_nonempty`) an input ensemble `{pₐ, ρₐ}` whose output χ + `χ₀ = χ({pₐ, E(ρₐ)})` strictly exceeds `R`. Take the margin `ε = (χ₀ − R)/4 > 0`, so the + surviving exponent `β = (χ₀ − 2ε) − R = (χ₀ − R)/2 > 0`. + +2. **Derandomized per-block bound.** `ProductStateCode.exists_const_avgError_prettyGood_le` (the + preceding development, eqs. (12.79)–(12.83)) supplies a constant `C ≥ 0` such that for every + block length `n ≥ 1` and message count `K ≥ 1` there is a code `cₙ` with + `p_bar(cₙ) ≤ C/n + (K − 1)·exp(−n(χ₀ − 2ε))`. Take `K = Kₙ = ⌈eⁿᴿ⌉₊` (a rate-`R` code family); + for the finitely-many-irrelevant `n = 0` a junk one-message code fills the family. + +3. **The bound vanishes.** `Kₙ − 1 < eⁿᴿ` (`Nat.ceil_lt_add_one`), so the confusion term + `(Kₙ − 1)·exp(−n(χ₀ − 2ε)) ≤ eⁿᴿ·exp(−n(χ₀ − 2ε)) = exp(−nβ)` with `β > 0`. Hence + `p_bar(cₙ) ≤ C/n + exp(−nβ) → 0`, and a squeeze gives `p_bar → 0`. + +Composed with the average → maximum error bridge +(`IsProductStateAvgAchievableRate.isProductStateAchievableRate_of_lt`) this yields the achievability +direction `χ(E) ≤ C⁽¹⁾(E)` of the HSW theorem; the final `le_antisymm` +with the converse `productStateCapacity_le_channelHolevoChi` is in +`LeanPool/AxQM/NC/Ch12/Theorem8.lean`. The channel `E` is an arbitrary state-map. -/ +theorem isProductStateAvgAchievableRate_of_lt_channelHolevoChi [Nonempty (State S)] + {E : State S → State S} {R : ℝ} (hR : R < channelHolevoChi E) : + IsProductStateAvgAchievableRate E R := by + classical + -- Step 1: a near-optimal input ensemble `{p, ρ}` with output χ strictly above `R`. + obtain ⟨χv, hmem, hRχ⟩ := exists_lt_of_lt_csSup (channelHolevoChiSet_nonempty E) hR + obtain ⟨N, p, hp, hsum, ρ, rfl⟩ := hmem + -- `hRχ : R < χ₀`, `χ₀ = χ({pₐ, E(ρₐ)})`. + have hεpos : (0 : ℝ) < (State.holevoChi p hp hsum (fun a => E (ρ a)) - R) / 4 := by + linarith + -- Step 2: the derandomized per-block bound at margin `ε = (χ₀ − R)/4`. + obtain ⟨C, -, hbound⟩ := ProductStateCode.exists_const_avgError_prettyGood_le + p hp hsum E ρ (∑ a, p a * (E (ρ a)).vonNeumannEntropy) + ((State.holevoChi p hp hsum (fun a => E (ρ a)) - R) / 4) hεpos rfl + set χ₀ := State.holevoChi p hp hsum (fun a => E (ρ a)) with hχ₀ + set ε := (χ₀ - R) / 4 with hεdef + set β := χ₀ - 2 * ε - R with hβ + have hβpos : 0 < β := by rw [hβ, hεdef]; linarith + -- A code for each block length `n ≥ 1` meeting the bound with `K = Kₙ = ⌈eⁿᴿ⌉₊`. + have hcode : ∀ n : ℕ, 0 < n → ∃ c : ProductStateCode E n ⌈Real.exp ((n : ℝ) * R)⌉₊, + c.avgError ≤ C / (n : ℝ) + + ((⌈Real.exp ((n : ℝ) * R)⌉₊ : ℝ) - 1) * Real.exp (-(n : ℝ) * (χ₀ - 2 * ε)) := + fun n hn => hbound n hn ⌈Real.exp ((n : ℝ) * R)⌉₊ (Nat.ceil_pos.mpr (Real.exp_pos _)) + choose code hcodebound using hcode + -- A junk one-message code for the (limit-irrelevant) `n = 0`. + set junk : (n : ℕ) → ProductStateCode E n ⌈Real.exp ((n : ℝ) * R)⌉₊ := + fun n => ProductStateCode.junk E n ⌈Real.exp ((n : ℝ) * R)⌉₊ with hjunk + refine ⟨fun n => if hn : 0 < n then code n hn else junk n, ?_⟩ + -- Step 3: `avgError → 0` by squeezing against `C/n + exp(−nβ) → 0`. + have hlim : Tendsto (fun n : ℕ => C / (n : ℝ) + Real.exp (-(n : ℝ) * β)) atTop (𝓝 0) := by + have h1 : Tendsto (fun n : ℕ => C / (n : ℝ)) atTop (𝓝 0) := + tendsto_const_div_atTop_nhds_zero_nat C + have h2 : Tendsto (fun n : ℕ => Real.exp (-(n : ℝ) * β)) atTop (𝓝 0) := by + simpa only [neg_mul, mul_neg] using + Real.tendsto_exp_nat_mul_atTop_nhds_zero (show -β < 0 by linarith) + simpa using h1.add h2 + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlim + (Eventually.of_forall fun n => ProductStateCode.avgError_nonneg _) ?_ + filter_upwards [eventually_gt_atTop 0] with n hn + rw [dite_eq_left hn] + refine (hcodebound n hn).trans ?_ + -- The confusion term collapses: `(Kₙ − 1)·exp(−n(χ₀ − 2ε)) ≤ eⁿᴿ·exp(−n(χ₀ − 2ε)) = exp(−nβ)`. + have hexpeq : Real.exp ((n : ℝ) * R) * Real.exp (-(n : ℝ) * (χ₀ - 2 * ε)) + = Real.exp (-(n : ℝ) * β) := by + rw [← Real.exp_add]; congr 1; rw [hβ]; ring + gcongr + rw [← hexpeq] + gcongr + have h := Nat.ceil_lt_add_one (Real.exp_pos ((n : ℝ) * R)).le + linarith + +end AxQM diff --git a/LeanPool/AxQM/Core/ProductStateCapacity.lean b/LeanPool/AxQM/Core/ProductStateCapacity.lean new file mode 100644 index 0000000000..4d2471fabd --- /dev/null +++ b/LeanPool/AxQM/Core/ProductStateCapacity.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ProductStateCode +public import LeanPool.AxQM.Postulates.API.CertainMeasurement +public import LeanPool.AxQM.Postulates.API.Distinguishability +public import LeanPool.AxQM.Postulates.API.TensorPowDim + +/-! +# The product-state capacity `C⁽¹⁾(E)` of a state map + +This file defines the **product-state capacity** `C⁽¹⁾(E)` for independent uses of a state +map `E`. It is the supremum of the rates at which Alice can reliably send classical +information to Bob using product-state codewords and a joint measurement. This extends +the operational capacity in Nielsen & Chuang §12.3.2 from quantum channels to state maps. +For quantum channels it is the right-hand side of the Holevo–Schumacher–Westmoreland +theorem (Theorem 12.8). + +Building on the product-state coding model of `AxQM.ProductStateCode` (encoder + POVM +decoder, with `maxError` the maximum error probability), this file supplies: + +* `IsProductStateAchievableRate E R` — a rate `R` is **achievable** when there is a family of + product-state codes `codeₙ : ProductStateCode E n ⌈exp (n · R)⌉₊`, one per block length `n`, whose + maximum error probability tends to `0` as `n → ∞` (N&C p. 552, transcribed to the memoryless + quantum channel); +* `productStateCapacity E` — the capacity `C⁽¹⁾(E)`, the supremum of the achievable rates. + +## Design + +**Units — nats, not bits.** N&C states the coding problem with `2ⁿᴿ` messages and entropy in bits. +This library measures von Neumann entropy with the *natural* logarithm (`vonNeumannEntropy` uses +`Real.log`), so the Holevo χ quantity `channelHolevoChi E` is in nats. To keep +the HSW equality `χ(E) = C⁽¹⁾(E)` a *verbatim* identity — with no stray `log 2` conversion factor — +the capacity here is defined in the same units: a code of block length `n` with `K` messages carries +`(ln K)/n` nats per channel use, so a rate-`R` family has `K = ⌈exp (n · R)⌉₊` messages (at least +`eⁿᴿ`). This mirrors the classical `Real.channelOpCapacity` (Theorem 12.7) with +`2ⁿᴿ = exp (n R log 2)` replaced by `eⁿᴿ = exp (n R)` — i.e. the classical `log 2` factor dropped, +exactly the bits→nats change. It is a faithful reformulation, not a weakening. + +**Well-formedness `[Nonempty (State S)]`.** Building even the trivial one-message code needs an +input state to encode; a genuine quantum system has states (the same well-formedness hypothesis +the Chapter 9 fixed-point exercises carry). It is not a weakening: on a `0`-dimensional system no +state +exists and the whole communication setup is vacuous, so N&C's presupposition of a real channel is +recorded here as `[Nonempty (State S)]`. + +**Bounds on the supremum.** Given a state, the achievable-rate set contains `0` by the +one-message code. It is bounded above by `log d`, where `d = dim S` +(`bddAbove_isProductStateAchievableRate`). The distinguishability bound on the `n`-fold +output gives `∑_M tr(σ_M E_M) ≤ dⁿ` for a code with `K` messages. Thus +`K(1 − max error) ≤ dⁿ`, and for `R > log d` the message count `K = ⌈eⁿᴿ⌉₊` outgrows `dⁿ`. +The supremum is therefore an upper bound on each achievable rate (`le_productStateCapacity`). +The tight converse bound `C⁽¹⁾(E) ≤ χ(E)` is `productStateCapacity_le_channelHolevoChi` in +`LeanPool/AxQM/NC/Ch12/Theorem8.lean`, following the Fano, Holevo, and subadditivity argument +of N&C eqs. (12.96)–(12.102). + +The channel `E` enters only as an arbitrary state-map `State S → State S`. The trivial zero-error +decoder is `AxQM.certainMeasurement`; the `BddAbove` proof uses the distinguishability bound +`Measurement.sum_bornProb_self_le_finrank`, with the dimension `dⁿ` given by +`finrank (Sⁿ) = (finrank S)ⁿ`. + +## Main definitions and results + +* `AxQM.IsProductStateAchievableRate` — achievability of a rate `R` (N&C p. 552). +* `AxQM.productStateCapacity` — the product-state capacity `C⁽¹⁾(E)`. +* `AxQM.isProductStateAchievableRate_zero` — rate `0` is achievable. +* `AxQM.productStateCapacity_nonneg` — `0 ≤ C⁽¹⁾(E)`. +* `AxQM.bddAbove_isProductStateAchievableRate` — the achievable-rate set is bounded above + (distinguishability bound), so `C⁽¹⁾(E)` is a genuine supremum. +* `AxQM.le_productStateCapacity` — every achievable rate is `≤ C⁽¹⁾(E)`. +-/ + +@[expose] public section + +open ContinuousLinearMap InnerProductSpace Filter Topology +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- A rate `R` (in **nats** per channel use) is **achievable** for the memoryless channel `E` when +there is a family of product-state codes `codeₙ : ProductStateCode E n ⌈exp (n · R)⌉₊`, one for each +block length `n`, whose maximum error probability `maxError` tends to `0` as `n → ∞` (Nielsen & +Chuang, p. 552, for the quantum product-state model). The message count `⌈exp (n · R)⌉₊` is at least +`eⁿᴿ`, i.e. a rate of `R` nats per use over `n` uses — the natural-log analogue of N&C's `2ⁿᴿ` (see +the module docstring on the nats convention). -/ +def IsProductStateAchievableRate (E : State S → State S) (R : ℝ) : Prop := + ∃ code : (n : ℕ) → ProductStateCode E n ⌈Real.exp ((n : ℝ) * R)⌉₊, + Tendsto (fun n => (code n).maxError) atTop (𝓝 0) + +/-- The **product-state capacity** `C⁽¹⁾(E)` of a state map `E`, defined as the supremum of +achievable rates for independent uses with product-state inputs and joint decoding. +For a quantum channel this is the operational capacity in Nielsen & Chuang, Theorem 12.8. -/ +def productStateCapacity (E : State S → State S) : ℝ := + sSup {R | IsProductStateAchievableRate E R} + +/-- **Rate `0` is achievable.** Use the one-message code (`⌈exp (n · 0)⌉₊ = 1` message) whose +decoder is the certain-outcome measurement announcing that sole message: every message is decoded +correctly, so the maximum error probability is `0` for every block length, and a fortiori tends to +`0`. Requires `[Nonempty (State S)]` only to supply the (irrelevant) input state the encoder must +name. -/ +theorem isProductStateAchievableRate_zero [Nonempty (State S)] (E : State S → State S) : + IsProductStateAchievableRate E 0 := by + have hpos : ∀ n : ℕ, 0 < ⌈Real.exp ((n : ℝ) * 0)⌉₊ := fun n => Nat.ceil_pos.mpr (Real.exp_pos _) + have hle : ∀ n : ℕ, ⌈Real.exp ((n : ℝ) * 0)⌉₊ ≤ 1 := by + intro n; rw [mul_zero, Real.exp_zero, Nat.ceil_one] + refine ⟨fun n => { encoder := fun _ _ => Classical.arbitrary (State S) + decoder := certainMeasurement (some ⟨0, hpos n⟩) }, ?_⟩ + refine tendsto_const_nhds.congr fun n => ?_ + have : Subsingleton (Fin ⌈Real.exp ((n : ℝ) * 0)⌉₊) := + Fin.subsingleton_iff_le_one.mpr (hle n) + refine (le_antisymm (Real.iSup_le (fun m => ?_) le_rfl) + (ProductStateCode.maxError_nonneg _)).symm + have hm : m = ⟨0, hpos n⟩ := Subsingleton.elim _ _ + simp only [ProductStateCode.errorProb, ProductStateCode.successProb, hm, + certainMeasurement_bornProb_self, sub_self, le_refl] + +/-- **The product-state capacity is non-negative**, `0 ≤ C⁽¹⁾(E)`. When the achievable-rate set is +bounded above, rate `0` lies in it (`isProductStateAchievableRate_zero`), so the supremum is `≥ 0`; +otherwise `sSup` is `0` by convention. -/ +theorem productStateCapacity_nonneg [Nonempty (State S)] (E : State S → State S) : + 0 ≤ productStateCapacity E := by + by_cases h : BddAbove {R | IsProductStateAchievableRate E R} + · exact le_csSup h (isProductStateAchievableRate_zero E) + · rw [productStateCapacity, Real.sSup_of_not_bddAbove h] + +/-- **The achievable-rate set is bounded above**, so `C⁽¹⁾(E)` is a genuine supremum. Every +achievable rate `R` is at most `log d` nats, `d = dim S`, by the **distinguishability bound**: for a +product-state code with `K = ⌈eⁿᴿ⌉₊` messages, the total success probability of the decoder is +`∑_M tr(σ_M E_M) ≤ dⁿ` (`Measurement.sum_bornProb_self_le_finrank` applied to the output codewords, +using `finrank (Sⁿ) = dⁿ`). Since the average error `p_av` obeys `∑_M tr(σ_M E_M) = K(1 − p_av)` and +`p_av ≤ max error`, this gives `K(1 − max error) ≤ dⁿ`, hence `eⁿᴿ(1 − max errorₙ) ≤ dⁿ` and +`1 − max errorₙ ≤ (d / eᴿ)ⁿ`. If `R > log d` then `d / eᴿ < 1`, so the right side `→ 0` while the +left `→ 1` (max errorₙ `→ 0` by achievability) — a contradiction. Thus every achievable rate is +`≤ log d`. This is the crude dimensional half of the HSW converse (N&C Exercise 12.3 route); +`[Nonempty (State S)]` supplies the input state the codes name and forces `d ≥ 1`. -/ +theorem bddAbove_isProductStateAchievableRate [Nonempty (State S)] (E : State S → State S) : + BddAbove {R | IsProductStateAchievableRate E R} := by + have : Nontrivial S.space := (Classical.arbitrary (State S)).nontrivial_space + set d : ℕ := Module.finrank ℂ S.space with hd_def + have hd_pos : 0 < d := Module.finrank_pos + have hdR : (0 : ℝ) < d := by exact_mod_cast hd_pos + refine ⟨Real.log d, ?_⟩ + rintro R ⟨code, hcode⟩ + by_contra hlt + rw [not_le] at hlt + -- Distinguishability: the total decoder success probability is at most `dⁿ`. + have hdist : ∀ n : ℕ, ∑ M, (code n).successProb M ≤ (d : ℝ) ^ n := by + intro n + have hle := (code n).decoder.sum_bornProb_self_le_finrank + (fun o => match o with + | none => State.tensorPow (Classical.arbitrary (State S)) n + | some M => (code n).outputCodeword M) + rw [Fintype.sum_option, + show Module.finrank ℂ (S.tensorPow n).space = d ^ n from QSystem.finrank_tensorPow_space S n, + Nat.cast_pow] at hle + have hnn : 0 ≤ (code n).decoder.bornProb + (State.tensorPow (Classical.arbitrary (State S)) n) none := + (code n).decoder.bornProb_nonneg _ _ + have hcongr : ∑ M, (code n).decoder.bornProb ((code n).outputCodeword M) (some M) + = ∑ M, (code n).successProb M := rfl + rw [hcongr] at hle + linarith + -- The geometric ratio `q = d / eᴿ` is in `[0, 1)` exactly because `log d < R`. + set q : ℝ := (d : ℝ) / Real.exp R with hq_def + have hq0 : 0 ≤ q := div_nonneg hdR.le (Real.exp_pos R).le + have hdexp : (d : ℝ) < Real.exp R := by + rw [← Real.exp_log hdR]; exact Real.exp_lt_exp.mpr hlt + have hq1 : q < 1 := (div_lt_one (Real.exp_pos R)).mpr hdexp + -- Per block length: `1 − max errorₙ ≤ qⁿ`. + have hpern : ∀ n : ℕ, 1 - (code n).maxError ≤ q ^ n := by + intro n + set K : ℕ := ⌈Real.exp ((n : ℝ) * R)⌉₊ with hK_def + have hKpos : 0 < K := Nat.ceil_pos.mpr (Real.exp_pos _) + have hKR : (0 : ℝ) < K := by exact_mod_cast hKpos + have hmaxle : (code n).avgError ≤ (code n).maxError := (code n).avgError_le_maxError + have hmax1 : (code n).maxError ≤ 1 := (code n).maxError_le_one + have hexpK : Real.exp ((n : ℝ) * R) ≤ (K : ℝ) := Nat.le_ceil _ + have herr : (code n).avgError * (K : ℝ) = ∑ M, (code n).errorProb M := by + rw [ProductStateCode.avgError, div_mul_cancel₀ _ (ne_of_gt hKR)] + have hsum_succ : ∑ M, (code n).successProb M = (K : ℝ) - ∑ M, (code n).errorProb M := by + have hse : ∀ M, (code n).successProb M = 1 - (code n).errorProb M := fun M => by + simp [ProductStateCode.errorProb] + simp only [hse, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one, ← hK_def] + -- `eⁿᴿ (1 − max error) ≤ K(1 − max error) ≤ K(1 − p_av) = ∑ success ≤ dⁿ`. + have hCeq : (K : ℝ) * (1 - (code n).avgError) = ∑ M, (code n).successProb M := by + rw [hsum_succ, ← herr]; ring + have hchain : Real.exp ((n : ℝ) * R) * (1 - (code n).maxError) ≤ (d : ℝ) ^ n := by + calc Real.exp ((n : ℝ) * R) * (1 - (code n).maxError) + ≤ (K : ℝ) * (1 - (code n).maxError) := + mul_le_mul_of_nonneg_right hexpK (by linarith) + _ ≤ (K : ℝ) * (1 - (code n).avgError) := + mul_le_mul_of_nonneg_left (by linarith) hKR.le + _ = ∑ M, (code n).successProb M := hCeq + _ ≤ (d : ℝ) ^ n := hdist n + have hdivq : (d : ℝ) ^ n / Real.exp ((n : ℝ) * R) = q ^ n := by + rw [hq_def, div_pow, Real.exp_nat_mul] + rw [← hdivq, le_div_iff₀ (Real.exp_pos _)] + linarith [hchain] + -- The two sides converge to `1` and `0`, contradiction. + have hL : Tendsto (fun n => 1 - (code n).maxError) atTop (𝓝 1) := by + simpa using hcode.const_sub (1 : ℝ) + have hR0 : Tendsto (fun n => q ^ n) atTop (𝓝 0) := + tendsto_pow_atTop_nhds_zero_of_lt_one hq0 hq1 + have hcontra : (1 : ℝ) ≤ 0 := le_of_tendsto_of_tendsto' hL hR0 hpern + linarith + +/-- Every achievable rate is at most the product-state capacity `C⁽¹⁾(E)`, the supremum of +the achievable-rate set. -/ +theorem le_productStateCapacity [Nonempty (State S)] {E : State S → State S} {R : ℝ} + (hR : IsProductStateAchievableRate E R) : R ≤ productStateCapacity E := + le_csSup (bddAbove_isProductStateAchievableRate E) hR + +end AxQM diff --git a/LeanPool/AxQM/Core/ProductStateCode.lean b/LeanPool/AxQM/Core/ProductStateCode.lean new file mode 100644 index 0000000000..829176e92b --- /dev/null +++ b/LeanPool/AxQM/Core/ProductStateCode.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.API.TensorPowState + +/-! +# The product-state coding model for a noisy quantum channel (N&C §12.3.2) + +This file sets up the operational model behind the **product-state capacity** `C⁽¹⁾(E)` of a +trace-preserving quantum operation `E`, the object on the right-hand side of the +Holevo–Schumacher–Westmoreland (HSW) theorem (Nielsen & Chuang, Theorem 12.8). It is the quantum +analogue of the classical noisy-channel coding setup (N&C §12.2.2): Alice encodes a message using a +**product state** of single-use channel inputs, Bob decodes the channel output with a measurement, +and the figures of merit are the resulting error probabilities. + +A **product-state code** `ProductStateCode E n K` for the channel `E`, block length `n`, and message +set `{0, …, K−1}` consists of + +* an **encoder** `Fin K → Fin n → State S`, associating to each message `M` the `n` single-use input + states `ρ_{M₁}, …, ρ_{Mₙ}` whose product `ρ_M = ρ_{M₁} ⊗ ⋯ ⊗ ρ_{Mₙ}` is the codeword (Alice may + only prepare *product* inputs — this is the defining restriction of the product-state capacity); +* a **decoder** `Measurement (Option (Fin K)) (S ^⊗ₛ n)` on the `n`-fold output system, whose + outcome `some M` means "decoded `M`" and whose outcome `none` is the extra POVM element `E₀` that + N&C allows for inconclusive results. + +## Design: the memoryless output codeword + +Because the channel is *memoryless* (applied independently to each of the `n` uses) and Alice's +inputs are *product* states, the channel output for message `M`, + +`σ_M = E⊗ⁿ(ρ_M) = E(ρ_{M₁}) ⊗ ⋯ ⊗ E(ρ_{Mₙ})`, + +is itself a product state — the product of the individual single-use outputs `E(ρ_{Mᵢ})`. We +therefore *define* the output codeword directly as this product (`outputCodeword`), which avoids +introducing a separate `n`-fold channel object `E⊗ⁿ` and its `IsChannel` proof: the product form is +exactly what N&C uses throughout the proof (eqs. (12.74)–(12.83)), and it is the form the converse +and achievability arguments consume. + +The success probability for message `M` is the Born probability `tr(σ_M E_M)` of Bob's decoding +measurement returning `some M` on `σ_M` (`successProb`, via the Born rule +`Measurement.bornProb`); the error probability is `pᵉ_M = 1 − tr(σ_M E_M)` (`errorProb`, N&C's +`pᵉ_M`). The two operational error measures are the **average** error `p_av` over a uniform message +(N&C eq. (12.72)) and the **maximum** error over all messages; the converse bounds `p_av` from +below, while achievability produces codes with small maximum error. + +The channel `E` enters only as an arbitrary state-map `State S → State S`; codes are defined for +any such `E`, and the trace-preserving/`IsChannel` hypothesis is imposed at the capacity theorems +that need it. + +## Main definitions and results + +* `AxQM.ProductStateCode` — a product-state code (encoder + POVM decoder). +* `AxQM.ProductStateCode.outputCodeword` — the channel output `σ_M = ⊗ᵢ E(ρ_{Mᵢ})`. +* `AxQM.ProductStateCode.successProb` / `errorProb` — `tr(σ_M E_M)` and its + complement `pᵉ_M = 1 − tr(σ_M E_M)`. +* `AxQM.ProductStateCode.avgError` / `maxError` — average (N&C eq. (12.72)) and maximum + error probability, with their `[0,1]` bounds and `avgError ≤ maxError`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- A **product-state code** for a channel `E`, block length `n`, and message set `Fin K` +(Nielsen & Chuang §12.3.2). Alice's `encoder` sends each message to the `n` single-use input states +whose tensor product is the codeword; Bob's `decoder` is a measurement (POVM) on the `n`-fold output +system `S ^⊗ₛ n`, with outcome `some M` decoding to message `M` and `none` the inconclusive element +`E₀`. The code uses `E` only as a state map and applies it independently to each input. -/ +structure ProductStateCode (E : State S → State S) (n K : ℕ) where + /-- The encoder: message `M ↦ (ρ_{M₁}, …, ρ_{Mₙ})`, the single-use inputs whose product + `ρ_{M₁} ⊗ ⋯ ⊗ ρ_{Mₙ}` is Alice's codeword for `M`. -/ + encoder : Fin K → Fin n → State S + /-- Bob's decoding measurement on the `n`-fold output system: outcome `some M` = "decoded `M`", + outcome `none` = the extra inconclusive POVM element `E₀`. -/ + decoder : Measurement (Option (Fin K)) (S.tensorPow n) + +namespace ProductStateCode + +variable {E : State S → State S} {n K : ℕ} + +/-- The **channel output for message `M`**, `σ_M = E⊗ⁿ(ρ_M) = E(ρ_{M₁}) ⊗ ⋯ ⊗ E(ρ_{Mₙ})`. Because +the channel is memoryless and the input codeword is a product state, `σ_M` is the product of the +single-use outputs `E(ρ_{Mᵢ})`, defined here directly (no separate `E⊗ⁿ` object is needed). -/ +def outputCodeword (c : ProductStateCode E n K) (m : Fin K) : State (S.tensorPow n) := + State.piTensor fun i => E (c.encoder m i) + +/-- The **probability that Bob correctly decodes message `M`**, `tr(σ_M E_M)`: the Born probability +that the decoding measurement returns the outcome `some M` on the channel output `σ_M`. -/ +def successProb (c : ProductStateCode E n K) (m : Fin K) : ℝ := + c.decoder.bornProb (c.outputCodeword m) (some m) + +/-- The **error probability for message `M`**, `pᵉ_M = 1 − tr(σ_M E_M)` (Nielsen & Chuang, the +quantity just below eq. (12.71)): the probability Bob's decoding measurement does *not* return +`some M` on the channel output `σ_M`. -/ +def errorProb (c : ProductStateCode E n K) (m : Fin K) : ℝ := + 1 - c.successProb m + +/-- The **average error probability** `p_av = (1/K) ∑_M pᵉ_M` over a uniformly random message +(Nielsen & Chuang, eq. (12.72)). -/ +def avgError (c : ProductStateCode E n K) : ℝ := + (∑ m, c.errorProb m) / (K : ℝ) + +/-- The **maximum error probability** `max_M pᵉ_M` over all messages. -/ +def maxError (c : ProductStateCode E n K) : ℝ := + ⨆ m, c.errorProb m + +/-- The success probability is nonnegative (a Born probability). -/ +theorem successProb_nonneg (c : ProductStateCode E n K) (m : Fin K) : 0 ≤ c.successProb m := + c.decoder.bornProb_nonneg _ _ + +/-- The success probability is at most `1` (a Born probability). -/ +theorem successProb_le_one (c : ProductStateCode E n K) (m : Fin K) : c.successProb m ≤ 1 := + c.decoder.bornProb_le_one _ _ + +/-- The error probability is nonnegative. -/ +theorem errorProb_nonneg (c : ProductStateCode E n K) (m : Fin K) : 0 ≤ c.errorProb m := by + have := c.successProb_le_one m + simp only [errorProb]; linarith + +/-- The error probability is at most `1`. -/ +theorem errorProb_le_one (c : ProductStateCode E n K) (m : Fin K) : c.errorProb m ≤ 1 := by + have := c.successProb_nonneg m + simp only [errorProb]; linarith + +/-- Each message's error probability is at most the maximum error probability. -/ +theorem errorProb_le_maxError (c : ProductStateCode E n K) (m : Fin K) : + c.errorProb m ≤ c.maxError := + le_ciSup (Finite.bddAbove_range _) m + +/-- The maximum error probability is nonnegative. -/ +theorem maxError_nonneg (c : ProductStateCode E n K) : 0 ≤ c.maxError := by + simp only [maxError]; exact Real.iSup_nonneg c.errorProb_nonneg + +/-- The maximum error probability is at most `1`. -/ +theorem maxError_le_one (c : ProductStateCode E n K) : c.maxError ≤ 1 := + Real.iSup_le (fun m => c.errorProb_le_one m) (by norm_num) + +/-- The average error probability is nonnegative. -/ +theorem avgError_nonneg (c : ProductStateCode E n K) : 0 ≤ c.avgError := by + apply div_nonneg _ (by positivity) + exact Finset.sum_nonneg fun m _ => c.errorProb_nonneg m + +/-- The **average error is at most the maximum error**: `p_av ≤ max_M pᵉ_M`. -/ +theorem avgError_le_maxError (c : ProductStateCode E n K) : c.avgError ≤ c.maxError := by + rcases Nat.eq_zero_or_pos K with hK | hK + · subst hK; simp [avgError, maxError] + · rw [avgError, div_le_iff₀ (by exact_mod_cast hK)] + calc ∑ m, c.errorProb m + ≤ ∑ _m : Fin K, c.maxError := Finset.sum_le_sum fun m _ => c.errorProb_le_maxError m + _ = c.maxError * (K : ℝ) := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul, mul_comm] + +/-- The average error probability is at most `1`. -/ +theorem avgError_le_one (c : ProductStateCode E n K) : c.avgError ≤ 1 := + c.avgError_le_maxError.trans c.maxError_le_one + +end ProductStateCode + +end AxQM diff --git a/LeanPool/AxQM/Core/ProductStateCodeExpurgation.lean b/LeanPool/AxQM/Core/ProductStateCodeExpurgation.lean new file mode 100644 index 0000000000..1eaed5cd3f --- /dev/null +++ b/LeanPool/AxQM/Core/ProductStateCodeExpurgation.lean @@ -0,0 +1,269 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ProductStateCode +public import LeanPool.AxQM.Postulates.API.MeasurementCoarseGrain + +/-! +# Expurgation of a product-state code: from average error to maximum error (N&C eq. (12.83)) + +The random-coding half of the Holevo–Schumacher–Westmoreland theorem (Nielsen & Chuang, +Theorem 12.8) produces, for any rate `R < χ(E)`, a family of product-state codes whose **average** +error probability `p_av` tends to `0`. The operational notion of achievability, however, demands +codes whose **maximum** error probability tends to `0` — Bob must decode *every* message reliably, +not merely a random one. N&C's eq. (12.83) closes this gap by **expurgation**: from a code with +average error `p_av`, at least half the messages have error probability `≤ 2·p_av`, so *discarding +the worse half of the codewords* leaves a subcode, of essentially the same rate, whose maximum error +probability is at most `2·p_av`. + +This file supplies the code-level ingredients of that step — the subcode +constructions `restrict`/`truncate` and the expurgation lemma `exists_expurgated` — working with the +`AxQM.ProductStateCode` model (`Core/ProductStateCode`): + +* `AxQM.ProductStateCode.restrict` — the **subcode on a chosen set of messages** + `G : Finset (Fin K)`. Its encoder keeps only the codewords indexed by `G` (reindexed to + `Fin G.card` via `Finset.equivFin`), and its decoder is the original decoder with the outcomes + announcing a *discarded* message folded into the inconclusive element `E₀` — exactly the + measurement coarse-graining `Measurement.coarseGrain` (`Postulates/API/MeasurementCoarseGrain`, + N&C eq. (12.83)) along the map `Option (Fin K) → Option (Fin G.card)` that carries each retained + message to itself and everything else to `none`. +* `AxQM.ProductStateCode.restrict_errorProb` — a **retained message keeps its error + probability**: `(c.restrict G).errorProb k = c.errorProb ↑(G.equivFin.symm k)`. The decoding + outcome announcing a retained message has a singleton coarse-graining fibre, so + `coarseGrain_bornProb_of_filter_eq_singleton` preserves its Born probability. +* `AxQM.ProductStateCode.exists_expurgated` — the **expurgation lemma** proper: for any + code `c` with `K ≥ 1` messages there is a subcode `c'` on `K'` messages with `K ≤ 2·K'` (at + least half the messages survive) and `c'.maxError ≤ 2·c.avgError`. The message count bound is + the Markov + argument — the set of *bad* messages (error `> 2·p_av`) has size `≤ K/2`, since it would otherwise + contribute more than `K·p_av` to the total error — and the maximum-error bound is immediate from + `restrict_errorProb` on the retained (good) messages. +* `AxQM.ProductStateCode.truncate` — the **subcode on the first `m` messages** (`m ≤ K`): + the initial-segment special case of `restrict`, kept as its own construction so the message set is + *definitionally* `Fin m` (no `Finset.card` cast). Its encoder reuses message `Fin.castLE h k`, + and its decoder folds every discarded message (index `≥ m`, and the original inconclusive outcome) + into the inconclusive element via `Measurement.coarseGrain`. Companions + `truncate_outputCodeword`, `truncate_successProb`, `truncate_errorProb` — a **retained message + keeps its (output codeword, success, error) probability**, again by the singleton-fibre lemma + `coarseGrain_bornProb_of_filter_eq_singleton` — and `truncate_maxError_le` — **truncation does not + increase the maximum error**, `(c.truncate h).maxError ≤ c.maxError`. This is the exact + message-count trimming used to shrink an expurgated code to a target rate + (`Core/ProductStateAvgAchievable`). + +The subcodes `restrict`/`truncate` are built with the measurement constructor +`Measurement.coarseGrain`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +namespace ProductStateCode + +variable {S : QSystem} {E : State S → State S} {n K : ℕ} + +/-- **Restriction of a product-state code to a chosen set of messages** `G : Finset (Fin K)` +(the codeword-deletion construction underlying N&C's expurgation step, eq. (12.83)). + +The subcode `c.restrict G` has message set `Fin G.card`, reindexing the retained messages via +`Finset.equivFin`. Its encoder reuses message `↑(G.equivFin.symm k)` of `c`, and its decoder is +the original decoder coarse-grained along the outcome map that carries a retained message to its new +index and *every discarded message (and the original inconclusive outcome) to `none`* — i.e. the +outcomes announcing deleted codewords are folded into the subcode's inconclusive element `E₀`. -/ +def restrict (c : ProductStateCode E n K) (G : Finset (Fin K)) : + ProductStateCode E n G.card where + encoder k := c.encoder (G.equivFin.symm k) + decoder := + c.decoder.coarseGrain fun o => + match o with + | none => none + | some M => if h : M ∈ G then some (G.equivFin ⟨M, h⟩) else none + +/-- The output codeword of a retained message is unchanged: `c.restrict G` reuses `c`'s codeword for +the original message `↑(G.equivFin.symm k)`. -/ +theorem restrict_outputCodeword (c : ProductStateCode E n K) (G : Finset (Fin K)) + (k : Fin G.card) : + (c.restrict G).outputCodeword k = c.outputCodeword (G.equivFin.symm k) := rfl + +/-- **A retained message keeps its success probability.** The decoding outcome announcing a retained +message `k` has a singleton coarse-graining fibre — only the original message `↑(G.equivFin.symm k)` +maps to it — so `Measurement.coarseGrain_bornProb_of_filter_eq_singleton` preserves its Born +probability: +`(c.restrict G).successProb k = c.successProb ↑(G.equivFin.symm k)`. -/ +theorem restrict_successProb (c : ProductStateCode E n K) (G : Finset (Fin K)) (k : Fin G.card) : + (c.restrict G).successProb k = c.successProb (G.equivFin.symm k) := by + classical + set M₀ : Fin K := (G.equivFin.symm k : Fin K) with hM₀def + have hM₀mem : M₀ ∈ G := (G.equivFin.symm k).2 + -- The coarse-graining outcome map used by `restrict`. + set gmap : Option (Fin K) → Option (Fin G.card) := fun o => + match o with + | none => none + | some M => if h : M ∈ G then some (G.equivFin ⟨M, h⟩) else none with hgmap + -- The fibre of the retained outcome `some k` is the singleton `{some M₀}`. + have hfib : (Finset.univ.filter fun o => gmap o = some k) = {some M₀} := by + ext o + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] + cases o with + | none => simp [hgmap] + | some M => + simp only [hgmap] + by_cases hM : M ∈ G + · rw [dite_eq_left hM] + simp only [Option.some.injEq, ← Equiv.eq_symm_apply, Subtype.ext_iff, ← hM₀def] + · rw [dite_eq_right hM] + simp only [reduceCtorEq, Option.some.injEq, false_iff] + rintro rfl; exact hM hM₀mem + -- Read off the born probabilities through the singleton-fibre coarse-graining lemma. + exact Measurement.coarseGrain_bornProb_of_filter_eq_singleton c.decoder gmap + (c.outputCodeword M₀) (some k) (some M₀) hfib + +/-- **A retained message keeps its error probability**: +`(c.restrict G).errorProb k = c.errorProb ↑(G.equivFin.symm k)`. Immediate from +`restrict_successProb` and `errorProb = 1 − successProb`. -/ +theorem restrict_errorProb (c : ProductStateCode E n K) (G : Finset (Fin K)) (k : Fin G.card) : + (c.restrict G).errorProb k = c.errorProb (G.equivFin.symm k) := by + simp only [ProductStateCode.errorProb, restrict_successProb] + +/-- **The expurgation lemma** (Nielsen & Chuang, Theorem 12.8, eq. (12.83)). For any product-state +code `c` with `K ≥ 1` messages there is a subcode `c'` on `K'` messages such that at least half the +messages survive (`K ≤ 2·K'`) and the subcode's *maximum* error probability is at most twice the +original *average* error probability (`c'.maxError ≤ 2·c.avgError`). + +Take `G` to be the *good* messages, those with `errorProb ≤ 2·p_av`, and `c' = c.restrict G`. Each +retained message keeps its error probability (`restrict_errorProb`), which is `≤ 2·p_av` by +construction, giving the maximum-error bound. For the count bound, the *bad* messages +`Gᶜ` (error `> 2·p_av`) satisfy `2·|Gᶜ| ≤ K` by Markov's inequality — otherwise they alone would +contribute more than `K·p_av` to the total error `∑ errorProb = K·p_av` — and `|G| + |Gᶜ| = K` then +gives `K ≤ 2·|G| = 2·K'`. -/ +theorem exists_expurgated [NeZero K] (c : ProductStateCode E n K) : + ∃ (K' : ℕ) (c' : ProductStateCode E n K'), + K ≤ 2 * K' ∧ c'.maxError ≤ 2 * c.avgError := by + classical + have hKne : (K : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne K) + -- The good messages: those whose error probability is at most twice the average. + set G : Finset (Fin K) := Finset.univ.filter fun M => c.errorProb M ≤ 2 * c.avgError with hGdef + have hGprop : ∀ M ∈ G, c.errorProb M ≤ 2 * c.avgError := by + intro M hM; rw [hGdef, Finset.mem_filter] at hM; exact hM.2 + have hbad : ∀ M ∈ Gᶜ, 2 * c.avgError < c.errorProb M := by + intro M hM + rw [hGdef, Finset.mem_compl, Finset.mem_filter, not_and, not_le] at hM + exact hM (Finset.mem_univ M) + -- Total error is `K · p_av`. + have hsumErr : ∑ M, c.errorProb M = (K : ℝ) * c.avgError := by + rw [ProductStateCode.avgError]; field_simp + -- Markov: at most half the messages are bad, `2·|Gᶜ| ≤ K`. + have h2B : 2 * (Gᶜ : Finset (Fin K)).card ≤ K := by + rcases c.avgError_nonneg.lt_or_eq with hpos | hzero + · -- `p_av > 0`: the bad messages each carry error `> 2·p_av`, so Markov cancels `p_av`. + have hchain : ((Gᶜ : Finset (Fin K)).card : ℝ) * (2 * c.avgError) ≤ (K : ℝ) * c.avgError := by + calc ((Gᶜ : Finset (Fin K)).card : ℝ) * (2 * c.avgError) + = ∑ _M ∈ Gᶜ, 2 * c.avgError := by rw [Finset.sum_const, nsmul_eq_mul] + _ ≤ ∑ M ∈ Gᶜ, c.errorProb M := Finset.sum_le_sum fun M hM => le_of_lt (hbad M hM) + _ ≤ ∑ M, c.errorProb M := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun M _ _ => c.errorProb_nonneg M) + _ = (K : ℝ) * c.avgError := hsumErr + have h2c : (2 * ((Gᶜ : Finset (Fin K)).card : ℝ)) ≤ (K : ℝ) := + le_of_mul_le_mul_right (by nlinarith [hchain]) hpos + exact_mod_cast h2c + · -- `p_av = 0`: every error probability is `0`, so there are no bad messages. + have hsum0 : ∑ M, c.errorProb M = 0 := by rw [hsumErr, ← hzero, mul_zero] + have hallzero := (Finset.sum_eq_zero_iff_of_nonneg fun M _ => c.errorProb_nonneg M).mp hsum0 + have hcompl : (Gᶜ : Finset (Fin K)) = ∅ := by + apply Finset.eq_empty_of_forall_notMem + intro M hM + have hlt := hbad M hM + rw [hallzero M (Finset.mem_univ M), ← hzero, mul_zero] at hlt + exact lt_irrefl (0 : ℝ) hlt + rw [hcompl, Finset.card_empty, mul_zero]; exact Nat.zero_le K + -- `|G| + |Gᶜ| = K`, hence `K ≤ 2·|G|`. + have hcard : G.card + (Gᶜ : Finset (Fin K)).card = K := by + have h := Finset.card_add_card_compl G; rwa [Fintype.card_fin] at h + refine ⟨G.card, c.restrict G, by omega, ?_⟩ + -- The maximum error of the subcode: every retained message is good. + rw [ProductStateCode.maxError] + refine Real.iSup_le (fun k => ?_) (by have := c.avgError_nonneg; linarith) + rw [restrict_errorProb] + exact hGprop _ (G.equivFin.symm k).2 + +/-- **Truncation of a product-state code to its first `m` messages** (`m ≤ K`). The subcode +`c.truncate h` has message set `Fin m`, encodes message `k` as `c`'s message `Fin.castLE h k`, and +decodes with `c`'s decoder coarse-grained (`Measurement.coarseGrain`) along the outcome map carrying +each retained message `M` with `M < m` to itself and *everything else* (larger messages, and the +original inconclusive outcome) to `none`. It is the initial-segment special case of `restrict`, +kept as its own construction so the message set is *definitionally* `Fin m` (no `Finset.card` +cast) — the exact message count needed to shrink an expurgated code to a target rate. -/ +def truncate (c : ProductStateCode E n K) {m : ℕ} (h : m ≤ K) : ProductStateCode E n m where + encoder k := c.encoder (Fin.castLE h k) + decoder := + c.decoder.coarseGrain fun o => + match o with + | none => none + | some M => if hM : M.val < m then some ⟨M.val, hM⟩ else none + +/-- The output codeword of a retained message is unchanged: `c.truncate h` reuses `c`'s codeword for +the original message `Fin.castLE h k`. -/ +theorem truncate_outputCodeword (c : ProductStateCode E n K) {m : ℕ} (h : m ≤ K) (k : Fin m) : + (c.truncate h).outputCodeword k = c.outputCodeword (Fin.castLE h k) := rfl + +/-- **A retained message keeps its success probability**: +`(c.truncate h).successProb k = c.successProb (Fin.castLE h k)`. The decoding outcome announcing a +retained message `k` has a singleton coarse-graining fibre — only the original message +`Fin.castLE h k` maps to it — so `Measurement.coarseGrain_bornProb_of_filter_eq_singleton` preserves +its Born probability. -/ +theorem truncate_successProb (c : ProductStateCode E n K) {m : ℕ} (h : m ≤ K) (k : Fin m) : + (c.truncate h).successProb k = c.successProb (Fin.castLE h k) := by + classical + set gmap : Option (Fin K) → Option (Fin m) := fun o => + match o with + | none => none + | some M => if hM : M.val < m then some ⟨M.val, hM⟩ else none with hgmap + -- The fibre of the retained outcome `some k` is the singleton `{some (Fin.castLE h k)}`. + have hfib : (Finset.univ.filter fun o => gmap o = some k) = {some (Fin.castLE h k)} := by + ext o + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] + cases o with + | none => simp [hgmap] + | some M => + simp only [hgmap] + by_cases hM : M.val < m + · rw [dite_eq_left hM] + simp only [Option.some.injEq, Fin.ext_iff, Fin.val_castLE] + · rw [dite_eq_right hM] + simp only [reduceCtorEq, Option.some.injEq, false_iff] + rintro rfl + exact hM (by simp only [Fin.val_castLE]; exact k.2) + exact Measurement.coarseGrain_bornProb_of_filter_eq_singleton c.decoder gmap + (c.outputCodeword (Fin.castLE h k)) (some k) (some (Fin.castLE h k)) hfib + +/-- **A retained message keeps its error probability**: +`(c.truncate h).errorProb k = c.errorProb (Fin.castLE h k)`. -/ +theorem truncate_errorProb (c : ProductStateCode E n K) {m : ℕ} (h : m ≤ K) (k : Fin m) : + (c.truncate h).errorProb k = c.errorProb (Fin.castLE h k) := by + simp only [ProductStateCode.errorProb, truncate_successProb] + +/-- **Truncation does not increase the maximum error probability**: every retained message of +`c.truncate h` keeps its (original) error probability, which is at most `c.maxError`, so +`(c.truncate h).maxError ≤ c.maxError`. -/ +theorem truncate_maxError_le (c : ProductStateCode E n K) {m : ℕ} (h : m ≤ K) : + (c.truncate h).maxError ≤ c.maxError := by + rw [ProductStateCode.maxError] + refine Real.iSup_le (fun k => ?_) c.maxError_nonneg + rw [truncate_errorProb] + exact c.errorProb_le_maxError _ + +end ProductStateCode + +end AxQM diff --git a/LeanPool/AxQM/Core/ProductStateCodePrettyGood.lean b/LeanPool/AxQM/Core/ProductStateCodePrettyGood.lean new file mode 100644 index 0000000000..c553121e88 --- /dev/null +++ b/LeanPool/AxQM/Core/ProductStateCodePrettyGood.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ProductStateCode +public import LeanPool.AxQM.Core.HolevoChi +public import LeanPool.AxQM.Postulates.API.PrettyGoodDecoder +public import LeanPool.AxQM.Postulates.API.RandomCodingExpectedError +public import LeanPool.AxQM.Postulates.API.TensorPowMix +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyPinching +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence + +/-! +# The pretty-good product-state code and its derandomized per-block error bound (N&C Thm 12.8) + +The random-coding (achievability) half of the Holevo–Schumacher–Westmoreland theorem (Nielsen & +Chuang, Theorem 12.8, Box 12.5) builds, for each block length `n` and message count `K`, a +**product-state code** whose codewords are drawn i.i.d. from an input ensemble `{pₐ, ρₐ}` and which +Bob decodes with the **pretty-good (square-root) measurement** of the codeword family, projected +onto the average-output typical subspace. This file packages that construction and turns the +random-coding *expectation* bound (eqs. (12.79)–(12.82), +`State.expectation_avgError_prettyGood_le`) into a **single concrete code** via derandomization. + +## Main definitions and results + +* `AxQM.ProductStateCode.prettyGood` — for an ensemble `{pₐ, ρₐ}`, channel `E`, block + length `n`, parameters `s, ε`, and a codebook `w : Fin K → Fin n → α`, the product-state code + whose encoder sends message `M` to the letters `ρ_{w M 0}, …, ρ_{w M (n-1)}` and whose decoder + is the pretty-good measurement `Measurement.ofPOVM (POVM.prettyGood A)` of the conjugated family + `A_{M'} = P · P_{M'} · P` (`P` the average-output typical projector, `P_{M'}` the conditional + typical projector of codeword `M'`, N&C eq. (12.78)). + +* `AxQM.ProductStateCode.exists_const_avgError_prettyGood_le` — the **derandomized + per-block average-error bound**: for an ensemble `{pₐ, ρₐ}` and `ε > 0` there is a constant + `C ≥ 0` (depending only on the ensemble and `ε`) such that for every block length `n ≥ 1` and + message count `K ≥ 1` there is a product-state code `c : ProductStateCode E n K` with + + `p_bar(c) ≤ C / n + (K − 1)·exp(−n·(χ({pₐ, E(ρₐ)}) − 2ε))`, + + where `χ({pₐ, E(ρₐ)})` is the output-ensemble Holevo χ (`State.holevoChi`). This is the whole + random-coding error estimate collapsed to one code: + + 1. **Construct** the pretty-good code family `codeₙ,ₖ(w) = ProductStateCode.prettyGood …`; its + average error `p_bar(codeₙ,ₖ(w)) = (1/K) ∑_M (1 − Tr(σ_M E_M))` matches the per-code bracket of + the expectation bound (`Measurement.ofPOVM_bornProb_eq_re_trace` plus trace cyclicity). + 2. **Average** over the i.i.d. codebook (`State.expectation_avgError_prettyGood_le`, eqs. + (12.79)–(12.82)): `𝔼_w[p_bar] ≤ 3·Tr((1−P) σ_bar^⊗n) + 2·V/(n ε²) + (K−1)·exp(−n(S(σ_bar) − s + − 2ε))`. + 3. **Derandomize** (`Real.exists_le_of_weighted_sum_le`): the i.i.d. weights are a probability + distribution over codebooks, so some codebook `w` has `p_bar(codeₙ,ₖ(w)) ≤ 𝔼_w[p_bar]`. + 4. **Bound the three terms**: the typical-defect trace `Tr((1−P) σ_bar^⊗n) = 1 − Pr[σ_bar^⊗n + typical]` + (`State.re_trace_one_sub_avgOutputTypicalProj_tensorPow_eq`) is at most `V_σ_bar/(n ε²)` by the + classical typicality bound (`Real.sum_typicalSeq_ge`), so the first two terms fold into `C/n` + with `C = (3·V_σ_bar + 2·V)/ε²`; and `S(σ_bar) − s = χ({pₐ, E(ρₐ)})` (`State.holevoChi_def`). + + The bound is used for the achievability direction: with + `K = ⌈eⁿᴿ⌉` and `2ε < χ({pₐ, E(ρₐ)}) − R`, both terms tend to `0`, so `R` is average-achievable. + + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.78)–(12.83). +-/ + +@[expose] public section + +open scoped BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The pretty-good product-state code** (Nielsen & Chuang, Theorem 12.8, Box 12.5, eq. (12.78)). +For an input ensemble `{pₐ, ρₐ}` (`ρ : α → State S`), channel `E`, block length `n`, entropy +parameter `s`, threshold `ε`, and a codebook `w : Fin K → Fin n → α`, this is the product-state +code whose + +* **encoder** sends message `M` to the single-use inputs `ρ_{w M 0}, …, ρ_{w M (n−1)}` (so the + output codeword is `σ_M = ⨂ᵢ E(ρ_{w M i})`); and +* **decoder** is the pretty-good (square-root) measurement `Measurement.ofPOVM (POVM.prettyGood A)` + of the conjugated projector family `A_{M'} = P · P_{M'} · P`, where `P = avgOutputTypicalProj …` + is the average-output ε-typical subspace projector and `P_{M'} = condTypicalSubspaceProj …` the + conditional typical projector of codeword `M'`; the required positivity `0 ≤ A_{M'}` is + `State.avgOutputTypicalProj_condTypical_conj_nonneg`. -/ +def ProductStateCode.prettyGood (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (s ε : ℝ) {K : ℕ} + (w : Fin K → Fin n → α) : ProductStateCode E n K where + encoder := fun M i => ρ (w M i) + decoder := prettyGoodDecoder p hp hsum E ρ n s ε w + +/-- **The derandomized per-block average-error bound of the HSW pretty-good code** (Nielsen & +Chuang, Theorem 12.8, Box 12.5, eqs. (12.79)–(12.83)). See the module docstring for the four steps +(construct → average → derandomize → bound the three terms). -/ +theorem ProductStateCode.exists_const_avgError_prettyGood_le + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (s ε : ℝ) (hε : 0 < ε) + (hs : s = ∑ a, p a * (E (ρ a)).vonNeumannEntropy) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (n : ℕ), 0 < n → ∀ (K : ℕ), 0 < K → + ∃ c : ProductStateCode E n K, c.avgError ≤ + C / (n : ℝ) + ((K : ℝ) - 1) * + Real.exp (-(n : ℝ) * (State.holevoChi p hp hsum (fun a => E (ρ a)) - 2 * ε)) := by + classical + refine ⟨(3 * (∑ x, (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x * + (-Real.log ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x) + - Real.entropy (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist) ^ 2) + + 2 * (∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (-Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2)) / ε ^ 2, ?_, ?_⟩ + · -- `0 ≤ C`: both surprisal variances are nonnegative and `ε² ≥ 0`. + refine div_nonneg ?_ (sq_nonneg ε) + have hVbar : 0 ≤ ∑ x, (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x * + (-Real.log ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x) + - Real.entropy (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist) ^ 2 := + Finset.sum_nonneg fun x _ => + mul_nonneg ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist_nonneg x) (sq_nonneg _) + have hV : 0 ≤ ∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (-Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2 := + Finset.sum_nonneg fun a _ => mul_nonneg (hp a) + (Finset.sum_nonneg fun b _ => mul_nonneg ((E (ρ a)).eigenvalueDist_nonneg b) (sq_nonneg _)) + linarith + intro n hn K hK + have : NeZero K := ⟨hK.ne'⟩ + have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hε2 : ε ^ 2 ≠ 0 := pow_ne_zero 2 hε.ne' + -- Step 2: the random-coding expected per-code error bound (eqs. (12.80)–(12.82)). + have hexp := State.expectation_avgError_prettyGood_le p hp hsum E ρ n hn s ε hε hs + (State.avgOutputTypicalProj p hp hsum E ρ n ε) + (State.avgOutputTypicalProj_isSelfAdjoint p hp hsum E ρ n ε) + (State.avgOutputTypicalProj_idem p hp hsum E ρ n ε) + (State.avgOutputTypicalProj_eq p hp hsum E ρ n ε) (K := K) + (fun w M' => State.avgOutputTypicalProj_condTypical_conj_nonneg p hp hsum E ρ n ε + (fun i => E (ρ (w M' i))) s ε) + -- The i.i.d. codebook weights are a probability distribution. + have hW0 : ∀ w : Fin K → Fin n → α, 0 ≤ ∏ M'' : Fin K, ∏ i, p (w M'' i) := + fun w => Finset.prod_nonneg fun M'' _ => Finset.prod_nonneg fun i _ => hp _ + have hW1 : ∑ w : Fin K → Fin n → α, ∏ M'' : Fin K, ∏ i, p (w M'' i) = 1 := by + have key := Finset.prod_univ_sum (fun _ : Fin K => (Finset.univ : Finset (Fin n → α))) + (fun (_ : Fin K) (v : Fin n → α) => ∏ i, p (v i)) + rw [Fintype.piFinset_univ] at key + rw [← key, Finset.prod_congr rfl fun M'' _ => sum_iidProdWeight p hsum n, + Finset.prod_const_one] + -- Step 1: the pretty-good code's average error equals the per-code trace bracket. + have havg : ∀ w : Fin K → Fin n → α, + (ProductStateCode.prettyGood p hp hsum E ρ n s ε w).avgError + = (K : ℝ)⁻¹ * ∑ M : Fin K, (1 - RCLike.re ((LinearMap.trace ℂ + (QSystem.piTensor fun _ : Fin n => S).space) + (↑((State.piTensor fun i => E (ρ (w M i))).op.comp + ((POVM.prettyGood (fun M' => (State.avgOutputTypicalProj p hp hsum E ρ n ε).comp + ((State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε).comp + (State.avgOutputTypicalProj p hp hsum E ρ n ε))) + (fun M' => State.avgOutputTypicalProj_condTypical_conj_nonneg p hp hsum E ρ n ε + (fun i => E (ρ (w M' i))) s ε)).elements (some M))) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space))) := by + intro w + rw [ProductStateCode.avgError, div_eq_inv_mul] + congr 1 + refine Finset.sum_congr rfl fun M _ => ?_ + rw [ProductStateCode.errorProb, ProductStateCode.successProb] + congr 1 + simp only [ProductStateCode.prettyGood, ProductStateCode.outputCodeword, prettyGoodDecoder] + erw [Measurement.ofPOVM_bornProb_eq_re_trace] + congr 1 + exact ContinuousLinearMap.trace_toLinearMap_mul_comm _ _ + -- Step 3: derandomize — some codebook `w` beats the expectation. + obtain ⟨w, hw⟩ := Real.exists_le_of_weighted_sum_le _ hW0 hW1 + (fun w => (ProductStateCode.prettyGood p hp hsum E ρ n s ε w).avgError) _ + (le_of_eq_of_le (Finset.sum_congr rfl fun w _ => by simp only [havg w]) hexp) + refine ⟨ProductStateCode.prettyGood p hp hsum E ρ n s ε w, hw.trans ?_⟩ + -- Step 4: bound the three terms. Typical-defect term `Tr((1−P) σ_bar^⊗n) ≤ V_σ_bar/(n ε²)`. + have hterm1 : 3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.avgOutputTypicalProj p hp hsum E ρ n ε) * + (QSystem.tensorPow_eq S n ▸ + ((State.mix p hp hsum fun a => E (ρ a)).tensorPow n).op)) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) + ≤ 3 * ((∑ x, (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x * + (-Real.log ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x) + - Real.entropy (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist) ^ 2) + / ((n : ℝ) * ε ^ 2)) := by + rw [State.re_trace_one_sub_avgOutputTypicalProj_tensorPow_eq p hp hsum E ρ n ε, + (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceMeasurement_bornProb_true n ε] + have hge := Real.sum_typicalSeq_ge (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist_nonneg + (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist_sum_eq_one hn hε + linarith + -- `S(σ_bar) − s = χ({pₐ, E(ρₐ)})`. + have hgap : (State.mix p hp hsum fun a => E (ρ a)).vonNeumannEntropy - s - 2 * ε + = State.holevoChi p hp hsum (fun a => E (ρ a)) - 2 * ε := by + rw [State.holevoChi_def, ← hs] + rw [hgap] + -- Fold the two `1/n` terms into `C/n`. + have halg : 3 * ((∑ x, (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x * + (-Real.log ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x) + - Real.entropy (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist) ^ 2) + / ((n : ℝ) * ε ^ 2)) + + 2 * ((∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (-Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2) / ((n : ℝ) * ε ^ 2)) + = (3 * (∑ x, (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x * + (-Real.log ((State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist x) + - Real.entropy (State.mix p hp hsum fun a => E (ρ a)).eigenvalueDist) ^ 2) + + 2 * (∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (-Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2)) / ε ^ 2 / (n : ℝ) := by + field_simp + linarith [hterm1, halg] + +end AxQM diff --git a/LeanPool/AxQM/Core/ProjectorPropagatorConjugation.lean b/LeanPool/AxQM/Core/ProjectorPropagatorConjugation.lean new file mode 100644 index 0000000000..d2ed11b989 --- /dev/null +++ b/LeanPool/AxQM/Core/ProjectorPropagatorConjugation.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ProjectorHamiltonian +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# Conjugation covariance of the projector-Hamiltonian propagator (N&C §6.2, Exercise 6.7) + +The covariance law underlying **Figure 6.5** of Nielsen & Chuang, §6.2: the +propagator of a *transported* projector Hamiltonian is the conjugate of the original propagator. + +For a state-preparation unitary `W` (an `Evolution S`) and a reference pure state `φ`, the +transported state is `W|φ⟩` (`W.evolvePure φ`), whose projector Hamiltonian generates the propagator +`exp(-i|Wφ⟩⟨Wφ|t)`. Because `|Wφ⟩⟨Wφ| = W|φ⟩⟨φ|W†` and conjugation by a unitary commutes with the +functional calculus, that propagator is exactly the `W`-conjugate of the reference propagator: + +`exp(-i|Wφ⟩⟨Wφ|t) = W · exp(-i|φ⟩⟨φ|t) · W†`. + +This is the identity that turns **Figure 6.4** (which implements `exp(-i|x⟩⟨x|Δt)` for a *marked* +reference state, via the marking oracle) into **Figure 6.5** (which implements `exp(-i|ψ⟩⟨ψ|Δt)` for +`ψ = W|0⟩` the uniform superposition of eq. 6.24, `W = H^{⊗n}` the Walsh–Hadamard state-preparation +transform): conjugate the reference circuit by the query-side state-preparation unitary. N&C's own +choice `ψ = H^{⊗n}|0⟩` (6.24) is the special case `W = H^{⊗n}`, `φ = |0⟩`. + +## What is formalised + +* `AxQM.PureState.projObservable_propagator_conj` — the covariance law + `(W.evolvePure φ).projObservable.propagator 1 0 t` + `= W.comp ((φ.projObservable.propagator 1 0 t).comp W.adjoint)`, an equality of `Evolution`s. + +## Design + +* **Proof.** The proof reduces to the propagator's closed form + `PureState.projObservable_propagator_op_apply` + (`exp(-i|φ⟩⟨φ|t) v = v + (e^{-it}-1)⟨φ,v⟩|φ⟩`), the unitary cancellation `W W† = 1` + (`Evolution.comp_adjoint_self`), and the adjoint inner-product identity + `⟨φ, W† v⟩ = ⟨W φ, v⟩` (`ContinuousLinearMap.adjoint_inner_right`) — no `exp`-conjugation lemma + needed, since the closed form makes the conjugation a one-line vector computation. +* **Reuse.** This is general theory about `PureState.projObservable`, independent of the search + oracle; it is applied to Figure 6.5 in Exercise 6.7 ([upstream `AxQM/NC/Ch6/Exercise6_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch6/Exercise6_7.lean)). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Conjugation covariance of the projector-Hamiltonian propagator** (Nielsen & Chuang, §6.2, the +identity behind Figure 6.5). For a state-preparation unitary `W` and a reference pure state `φ`, the +propagator of the transported projector Hamiltonian `|Wφ⟩⟨Wφ|` equals the `W`-conjugate of the +reference propagator: + +`exp(-i|Wφ⟩⟨Wφ|t) = W · exp(-i|φ⟩⟨φ|t) · W†`. + +The whole content is that `|Wφ⟩⟨Wφ| = W|φ⟩⟨φ|W†` and unitary conjugation commutes with the +functional calculus. The proof works vectorwise from the propagator's closed form +(`PureState.projObservable_propagator_op_apply`): applying `W · exp(-i|φ⟩⟨φ|t) · W†` to `v` gives +`v + (e^{-it}-1)⟨φ, W†v⟩ (Wφ)`, and `W W† = 1` together with `⟨φ, W†v⟩ = ⟨Wφ, v⟩` collapses this to +`v + (e^{-it}-1)⟨Wφ, v⟩ (Wφ) = exp(-i|Wφ⟩⟨Wφ|t) v`. This is the covariance step that turns the +Figure 6.4 circuit (for a marked reference state) into the Figure 6.5 circuit (for `ψ = W|0⟩`, the +uniform superposition of eq. 6.24, via `W = H^{⊗n}`). -/ +theorem PureState.projObservable_propagator_conj (W : Evolution S) (φ : PureState S) (t : ℝ) : + ((W.evolvePure φ).projObservable).propagator 1 0 t + = W.comp (((φ.projObservable).propagator 1 0 t).comp W.adjoint) := by + have hWW : ∀ v : S.space, W.op (ContinuousLinearMap.adjoint W.op v) = v := fun v => by + rw [← ContinuousLinearMap.comp_apply, Evolution.comp_adjoint_self, + one_apply_eq_self] + apply Evolution.ext + rw [Evolution.comp_op, Evolution.comp_op, Evolution.adjoint_op] + ext v + simp only [ContinuousLinearMap.comp_apply, PureState.projObservable_propagator_op_apply, + map_add, map_smul, Evolution.evolvePure_vec, hWW, ContinuousLinearMap.adjoint_inner_right] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftRegisterBridge.lean b/LeanPool/AxQM/Core/QftRegisterBridge.lean new file mode 100644 index 0000000000..804de9df57 --- /dev/null +++ b/LeanPool/AxQM/Core/QftRegisterBridge.lean @@ -0,0 +1,60 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QuditPowTower +public import LeanPool.AxQM.Postulates.API.QftGateEvolution +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.LeftPairGate + +/-! +# The quantum Fourier transform on a qubit tower + +The register identification `quditPowTower n` transports the QFT on a register of dimension +`2^(n+1)` to a tower of `n+1` qubits. The same identification transports the Figure 5.1 circuit +and intertwines the actions on pure states. For the computational-basis expansion, see +`LeanPool/AxQM/Core/QftTowerBasis.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The quantum Fourier transform transported onto the qubit tower.** The QFT +`qftEvolution (2ⁿ⁺¹)` of the single register `qudit (2ⁿ⁺¹)`, carried onto the right-nested +`(n+1)`-qubit control tower +`qtower n qubit` along the register bridge `quditPowTower n`. This is the QFT as an `Evolution` on +the tensor register the whole-circuit measured-QFT reduction (Problem 5.2) operates over. -/ +def qftTowerEvolution (n : ℕ) : Evolution (qtower n qubit) := + Evolution.congr (quditPowTower n) (qftEvolution (2 ^ (n + 1))) + +/-- **The transported QFT is the transported Figure 5.1 circuit.** `qftTowerEvolution n` equals the +transport of the wire-addressed gate composition `qftCircuitEvolution (n+1)` (Hadamards, +controlled-`Rₖ` rotations, swap layer), because on the single register the two agree +(`qftEvolution_eq_qftCircuitEvolution`). This is the form the wire-addressed reduction +rewrites gate by gate. -/ +theorem qftTowerEvolution_eq_congr_qftCircuitEvolution (n : ℕ) : + qftTowerEvolution n = Evolution.congr (quditPowTower n) (qftCircuitEvolution (n + 1)) := by + rw [qftTowerEvolution, qftEvolution_eq_qftCircuitEvolution] + +/-- **The register bridge intertwines the two QFTs.** Running the transported QFT +`qftTowerEvolution n` on a transported input `Φ ψ` equals transporting the single-register QFT +output `Φ (qftEvolution (2ⁿ⁺¹) ψ)` (`Φ = quditPowTower n`): the transported operator genuinely *is* +the quantum Fourier transform read through the register identification, not merely some unitary on +the tower. The specialisation of `Evolution.congr_evolvePure_congr` to the QFT and the bridge. -/ +theorem qftTowerEvolution_evolvePure_congr (n : ℕ) (ψ : PureState (qudit (2 ^ (n + 1)))) : + (qftTowerEvolution n).evolvePure (PureState.congr (quditPowTower n) ψ) + = PureState.congr (quditPowTower n) ((qftEvolution (2 ^ (n + 1))).evolvePure ψ) := + Evolution.congr_evolvePure_congr (quditPowTower n) (qftEvolution (2 ^ (n + 1))) ψ + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerBasis.lean b/LeanPool/AxQM/Core/QftTowerBasis.lean new file mode 100644 index 0000000000..cc7c98a40d --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerBasis.lean @@ -0,0 +1,162 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftRegisterBridge +public import LeanPool.AxQM.Core.MultiControlledNotBasis + +/-! +# Digit-form basis action of the measured-QFT register bridge (N&C Problem 5.2) + +The register bridge `quditPowTower n : qudit (2ⁿ⁺¹) ≃ₛ qtower n qubit` identifies the +single `2ⁿ⁺¹`-level register — where the quantum Fourier transform `qftEvolution (2ⁿ⁺¹)` lives — +with the right-nested `(n+1)`-qubit control tower. Its action on the computational basis is given +there only in the *recursive peel* form `quditPowTower_congr_quditBasis_succ` (split off one leading +qubit per step). This file closes that recursion into the **global binary-expansion dictionary**: +the bridge sends the register ket `|j⟩` to the tower product state `towerKet n b` whose wire bits +`b` are the binary digits of `j`. + +## The endianness, and why `Fin.rev` + +Two conventions meet here and they run in *opposite* directions: + +* the **bridge** peels the leading qubit *big-endian* — `quditPowTower` iterates `quditProdIso 2 _`, + whose split `finProdFinEquiv (x, y) = y + 2ⁿ⁺¹ · x` puts the leading tower wire `0` at the *most + significant* bit (coefficient `2ⁿ`); +* the **matrix gates** of the Figure 5.1 circuit (`Concrete.singleQubitOnWire` / + `Concrete.mcCtrlSingleQubit`) address wires through `enc = finFunctionFinEquiv`, which is + *little-endian* — wire `c` carries the coefficient of `2ᶜ` (`finFunctionFinEquiv_symm_apply_val`). + +So tower wire `i` is register bit `n − i`, i.e. `finFunctionFinEquiv.symm j i.rev`, and the +dictionary carries the reversal `Fin.rev` that reconciles the two orderings. This is the +convention-alignment the wire-addressed gate re-expressions rewrite through. + +## What is formalised + +* `quditPowTower_congr_quditBasis` — the dictionary: `Φₙ |j⟩ = towerKet n (i ↦ (bits j) i.rev)` + with `bits j = finFunctionFinEquiv.symm j` the little-endian binary digits and `Φₙ = + quditPowTower n`. Proved by induction on `n`, closing the recursive peel + `quditPowTower_congr_quditBasis_succ` with the tower recursion `towerKet_succ`. +* `quditPowTower_congr_quditBasis_apply` — the **encode** form the matrix gates consume: for a + wire bit-string `k : Fin (n+1) → Fin 2`, the register ket at the little-endian index + `finFunctionFinEquiv k` maps to the tower state `towerKet n (k ∘ Fin.rev)`. (Every register index + is such a `finFunctionFinEquiv k`, so this is equivalent to the dictionary; it is the form in + which a Figure 5.1 gate — which acts on `quditBasis (finFunctionFinEquiv k)` — meets the tower.) + +This extends the bridge of `AxQM/Core/QftRegisterBridge.lean` and lands in the tower basis of +`AxQM/Core/MultiControlledNotBasis.lean`. The two `private` lemmas are local base-2 digit arithmetic +(pure `Nat` facts). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- The most-significant base-2 digit of `j : Fin (2ᵐ⁺¹)` is the quotient `j / 2ᵐ`: since +`j < 2ᵐ⁺¹ = 2ᵐ · 2`, the reduction mod `2` in `finFunctionFinEquiv.symm` is vacuous. A local +digit-arithmetic helper for the bridge dictionary. -/ +private theorem finFunctionFinEquiv_symm_last_eq_div (m : ℕ) (j : Fin (2 ^ (m + 1))) : + (finFunctionFinEquiv.symm j (Fin.last m) : ℕ) = (j : ℕ) / 2 ^ m := by + rw [finFunctionFinEquiv_symm_apply_val] + simp only [Fin.val_last] + have hj : (j : ℕ) < 2 ^ m * 2 := by rw [← pow_succ]; exact j.isLt + exact Nat.mod_eq_of_lt (Nat.div_lt_of_lt_mul hj) + +/-- A base-2 digit below the cut is untouched by reducing mod `2ᵐ⁺¹`: for `c ≤ m`, the `c`-th bit of +`a` equals the `c`-th bit of `a % 2ᵐ⁺¹`, because `2ᶜ⁺¹ ∣ 2ᵐ⁺¹`. A local digit-arithmetic helper for +the bridge dictionary. -/ +private theorem bit_eq_bit_mod_two_pow (m a c : ℕ) (hc : c < m + 1) : + a / 2 ^ c % 2 = a % 2 ^ (m + 1) / 2 ^ c % 2 := by + rw [← Nat.mod_mul_right_div_self, ← Nat.mod_mul_right_div_self, Nat.mod_mod_of_dvd] + calc 2 ^ c * 2 = 2 ^ (c + 1) := by rw [pow_succ] + _ ∣ 2 ^ (m + 1) := pow_dvd_pow 2 (by omega) + +/-- **The register bridge as a binary-expansion dictionary.** On a computational-basis ket, the +measured-QFT register bridge `quditPowTower n : qudit (2ⁿ⁺¹) ≃ₛ qtower n qubit` sends `|j⟩` to the +tower product state `towerKet n b` whose bits are the binary digits of `j`, with the big-endian +reversal `Fin.rev` (tower wire `i` is register bit `n − i`), i.e. +`b i = finFunctionFinEquiv.symm j i.rev`. + +This closes the recursive peel `quditPowTower_congr_quditBasis_succ` into a global closed form (by +induction on `n`, matched against the tower recursion `towerKet_succ`), the dictionary the +wire-addressed re-expression of the Figure 5.1 gates rewrites through. -/ +theorem quditPowTower_congr_quditBasis (n : ℕ) (j : Fin (2 ^ (n + 1))) : + PureState.congr (quditPowTower n) (quditBasis j) + = towerKet n (fun i => finFunctionFinEquiv.symm j i.rev) := by + induction n with + | zero => + have hj : finFunctionFinEquiv.symm j (Fin.last 0) = j := by + apply Fin.ext; rw [finFunctionFinEquiv_symm_last_eq_div]; simp + rw [towerKet_zero, Fin.rev_zero, hj] + exact PureState.congr_refl (quditBasis j) + | succ n ih => + -- Decompose `j = x·2ⁿ⁺¹ + y` big-endian: leading bit `x`, tail `y = j mod 2ⁿ⁺¹`. + have peel := quditPowTower_congr_quditBasis_succ n + (finFunctionFinEquiv.symm j (Fin.last (n + 1))) + ⟨(j : ℕ) % 2 ^ (n + 1), Nat.mod_lt _ (by positivity)⟩ + have hjxy : (finCongr (pow_succ' 2 (n + 1))).symm + (finProdFinEquiv (finFunctionFinEquiv.symm j (Fin.last (n + 1)), + ⟨(j : ℕ) % 2 ^ (n + 1), Nat.mod_lt _ (by positivity)⟩)) = j := by + apply Fin.ext + have hval : (((finCongr (pow_succ' 2 (n + 1))).symm + (finProdFinEquiv (finFunctionFinEquiv.symm j (Fin.last (n + 1)), + ⟨(j : ℕ) % 2 ^ (n + 1), Nat.mod_lt _ (by positivity)⟩))) : ℕ) + = ((j : ℕ) % 2 ^ (n + 1)) + + 2 ^ (n + 1) * (finFunctionFinEquiv.symm j (Fin.last (n + 1)) : ℕ) := by + simp [finCongr_symm] + rw [hval, finFunctionFinEquiv_symm_last_eq_div] + exact Nat.mod_add_div _ _ + rw [hjxy] at peel + rw [peel, ih, towerKet_succ, Fin.rev_zero] + -- Leading wire matches (`quditBasis`/`qubitBasis` agree on `Fin 2`); align the tail bits. + congr 1 + congr 1 + funext i + rw [Fin.rev_succ] + apply Fin.ext + rw [finFunctionFinEquiv_symm_apply_val, finFunctionFinEquiv_symm_apply_val, Fin.val_castSucc] + exact (bit_eq_bit_mod_two_pow n (j : ℕ) _ (Fin.rev i).isLt).symm + +/-- **The bridge dictionary in encode form** (the shape the Figure 5.1 matrix gates meet). For a +wire bit-string `k : Fin (n+1) → Fin 2`, the register ket at the little-endian index +`finFunctionFinEquiv k` is carried by the bridge `quditPowTower n` to the tower product state +`towerKet n (k ∘ Fin.rev)`. The matrix gates act on `quditBasis (finFunctionFinEquiv k)`, so this is +how such a gate's action is read on the qubit tower; it follows from +`quditPowTower_congr_quditBasis` by the round-trip +`finFunctionFinEquiv.symm ∘ finFunctionFinEquiv`. -/ +theorem quditPowTower_congr_quditBasis_apply (n : ℕ) (k : Fin (n + 1) → Fin 2) : + PureState.congr (quditPowTower n) (quditBasis (finFunctionFinEquiv k)) + = towerKet n (fun i => k i.rev) := by + rw [quditPowTower_congr_quditBasis] + congr 1 + funext i + rw [Equiv.symm_apply_apply] + +/-- **The bridge dictionary at the reversed wire index.** Specialising the encode form +`quditPowTower_congr_quditBasis_apply` to `k = b ∘ Fin.rev` cancels the two reversals +(`Fin.rev_rev`): the register ket at the little-endian index `finFunctionFinEquiv (b ∘ Fin.rev)` is +carried by the bridge `quditPowTower n` straight back to the tower product state `towerKet n b`. +This is exactly the shape the terminal computational-basis measurement's operator/vector bridge +consumes — the register outcome `towerMeasurementOutcomeEquiv n b`, being +`finFunctionFinEquiv (b ∘ rev)`, reads back to `towerKet n b`. It is shared +by both `qtowerMeasurement_eq_congr_quditMeasurement` and the collapse lemma +`qtowerMeasurement_postMeasurement_eq_towerKet`. -/ +theorem quditPowTower_congr_quditBasis_rev (n : ℕ) (b : Fin (n + 1) → Fin 2) : + PureState.congr (quditPowTower n) (quditBasis (finFunctionFinEquiv (fun j => b j.rev))) + = towerKet n b := by + rw [quditPowTower_congr_quditBasis_apply] + congr 1 + funext i + simp only [Fin.rev_rev] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerCircuit.lean b/LeanPool/AxQM/Core/QftTowerCircuit.lean new file mode 100644 index 0000000000..31390eb9f0 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerCircuit.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerBasis + +/-! +# The transported QFT circuit read on the qubit tower (N&C Problem 5.2) + +The register bridge `quditPowTower n : qudit (2ⁿ⁺¹) ≃ₛ qtower n qubit` carries the +quantum Fourier transform from the single `2ⁿ⁺¹`-level register — where `qftEvolution` and its +Figure 5.1 gate circuit `qftCircuitEvolution` live — onto the explicit `(n+1)`-qubit tensor tower, +as `qftTowerEvolution n := Evolution.congr (quditPowTower n) (qftEvolution (2ⁿ⁺¹))`. The +whole-circuit measured-QFT reduction (Problem 5.2) will defer a terminal per-wire measurement past +this circuit +gate by gate, so it must read the circuit **on the tower** in two complementary ways, both supplied +here: + +* **gate by gate** — the transported circuit is the *product of the transported Figure 5.1 gates* + (`qftTowerEvolution_eq_map_congr_prod`), obtained by pushing the transport through the + `Evolution`-monoid product with `Evolution.congr_prod`. This is the list of one- and two-wire + gates the semiclassical reduction defers the measurement past; +* **on a computational-basis state** — the transport of a gate reads any tower basis ket `towerKet n + b` through the binary-expansion dictionary of `Core/QftTowerBasis.lean`: it is the transport of + the gate's action on the register ket `|finFunctionFinEquiv (b ∘ Fin.rev)⟩` + (`quditPowTower_congr_evolvePure_towerKet`), specialising for the whole QFT to + `qftTowerEvolution_evolvePure_towerKet`. + +## The reader `quditPowTower_congr_evolvePure_towerKet` + +The dictionary `quditPowTower_congr_quditBasis_apply` says the bridge sends the register ket +`|finFunctionFinEquiv k⟩` to the tower state `towerKet n (k ∘ Fin.rev)`. Reading it at `k = b ∘ +Fin.rev` (and using `Fin.rev`'s involutivity) presents `towerKet n b` itself as a transported +register ket, `towerKet n b = Φₙ |finFunctionFinEquiv (b ∘ Fin.rev)⟩` with `Φₙ = quditPowTower n`. +Then the gate-transport law `Evolution.congr_evolvePure_congr` — a transported gate acts on a +transported state as the transport of the original action — turns the transported gate's action on +`towerKet n b` into the transport of the register gate's action on `|finFunctionFinEquiv (b ∘ +Fin.rev)⟩`. This holds for **any** gate `U : Evolution (qudit (2ⁿ⁺¹))`, so a single reader serves +every Figure 5.1 gate (and the whole circuit). + +The general monoid-homomorphism lemmas `Evolution.congr_id` / `Evolution.congr_prod` it uses are in +`AxQM/Postulates/API/SystemIsoComm.lean`, beside `Evolution.congr_comp`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **A gate transported onto the tower, read on a computational-basis ket.** For any gate +`U : Evolution (qudit (2ⁿ⁺¹))`, its transport `Evolution.congr (quditPowTower n) U` onto the +`(n+1)`-qubit tower acts on the tower basis state `towerKet n b` as the transport of `U`'s action on +the register ket `|finFunctionFinEquiv (b ∘ Fin.rev)⟩`: + + `(Φₙ • U).evolvePure (towerKet n b) = Φₙ • (U.evolvePure |finFunctionFinEquiv (b ∘ Fin.rev)⟩)` + +with `Φₙ = quditPowTower n` and `Φₙ • (-)` the transport `PureState.congr Φₙ` / +`Evolution.congr Φₙ`. Proved by rewriting `towerKet n b` as the transported register ket via the +binary-expansion dictionary `quditPowTower_congr_quditBasis_apply` (at `k = b ∘ Fin.rev`, using +`Fin.rev_rev`), then +applying the gate-transport law `Evolution.congr_evolvePure_congr`. The `Fin.rev` reconciles the +big-endian register bridge with the little-endian `finFunctionFinEquiv` wire-indexing of the Figure +5.1 matrix gates. This is the single reader every Figure 5.1 gate — and the whole circuit — is read +through on the tower. -/ +theorem quditPowTower_congr_evolvePure_towerKet (n : ℕ) (U : Evolution (qudit (2 ^ (n + 1)))) + (b : Fin (n + 1) → Fin 2) : + (Evolution.congr (quditPowTower n) U).evolvePure (towerKet n b) + = PureState.congr (quditPowTower n) + (U.evolvePure (quditBasis (finFunctionFinEquiv (fun i => b i.rev)))) := by + have hb := quditPowTower_congr_quditBasis_apply n (fun i => b i.rev) + simp only [Fin.rev_rev] at hb + rw [← hb, Evolution.congr_evolvePure_congr] + +/-- **The transported QFT circuit is the product of the transported Figure 5.1 gates.** Transporting +the QFT circuit `qftCircuitEvolution (n+1)` onto the tower distributes over its gates: the tower QFT +`qftTowerEvolution n` equals the `Evolution`-monoid product of the transported Figure 5.1 gates +`(qftGateEvolutionSequence (n+1)).map (Evolution.congr (quditPowTower n))` — the wire-reversal swap, +and each target's Hadamard + controlled-`Rₖ` cascade, each carried onto the `(n+1)`-qubit tower. +From `qftTowerEvolution_eq_congr_qftCircuitEvolution` and the monoid-homomorphism law +`Evolution.congr_prod`. This exhibits the tower QFT as the explicit list of one- and two-wire gates +the whole-circuit reduction defers the terminal measurement past. -/ +theorem qftTowerEvolution_eq_map_congr_prod (n : ℕ) : + qftTowerEvolution n + = ((qftGateEvolutionSequence (n + 1)).map (Evolution.congr (quditPowTower n))).prod := by + rw [qftTowerEvolution_eq_congr_qftCircuitEvolution, qftCircuitEvolution, Evolution.congr_prod] + +/-- **The tower QFT read on a computational-basis ket.** The transported quantum Fourier transform +`qftTowerEvolution n` acts on the tower basis state `towerKet n b` as the transport of the single +register QFT's action on the register ket `|finFunctionFinEquiv (b ∘ Fin.rev)⟩`: + + `(qftTowerEvolution n).evolvePure (towerKet n b) + = quditPowTower n • ((qftEvolution (2ⁿ⁺¹)).evolvePure |finFunctionFinEquiv (b ∘ Fin.rev)⟩)`. + +The reader `quditPowTower_congr_evolvePure_towerKet` at `U = qftEvolution (2ⁿ⁺¹)` (as +`qftTowerEvolution n = Evolution.congr (quditPowTower n) (qftEvolution (2ⁿ⁺¹))` definitionally): the +tower QFT genuinely *is* the quantum Fourier transform read through the register identification, +wire bits reversed by `Fin.rev`. -/ +theorem qftTowerEvolution_evolvePure_towerKet (n : ℕ) (b : Fin (n + 1) → Fin 2) : + (qftTowerEvolution n).evolvePure (towerKet n b) + = PureState.congr (quditPowTower n) + ((qftEvolution (2 ^ (n + 1))).evolvePure + (quditBasis (finFunctionFinEquiv (fun i => b i.rev)))) := + quditPowTower_congr_evolvePure_towerKet n (qftEvolution (2 ^ (n + 1))) b + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerControlled.lean b/LeanPool/AxQM/Core/QftTowerControlled.lean new file mode 100644 index 0000000000..e370eae901 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerControlled.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftControlledEvolution +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.QtowerCtrlWireGate + +/-! +# The QFT controlled-`Rₖ` gate re-expressed as a controlled single-wire gate on the tower (N&C +Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a product of *transported* Figure 5.1 gates +(`qftTowerEvolution_eq_map_congr_prod`). To defer the terminal per-wire measurement +past that product gate by gate, each transported gate must be re-expressed as an honest +**wire-addressed tower `Evolution`**. This file does so for a Figure 5.1 **controlled-`Rₖ`** +rotation — the last of the circuit's three gate shapes, and its only **two-wire** gate (the swap +layer is done in `QftTowerSwap`, the Hadamards in `QftTowerHadamard`). + +## What is formalised + +* `quditPowTower_congr_qftControlledEvolution` — **the transported Figure 5.1 controlled-`Rₖ` from + control wire `c` onto target wire `t` (`t < c`) is the controlled single-wire phase gate on the + tower wire pair `(c.rev, t.rev)`.** Transporting the register controlled-`Rₖ` gate + `qftControlledEvolution (n+1) t c` (`Postulates/API`) onto the tower through the register bridge + `quditPowTower n` equals the controlled single-wire gate that applies the one-qubit phase gate + `P(2π/2^{(c-t)+1})` to tower wire `t.rev` gated on tower wire `c.rev`: + + `Evolution.congr (quditPowTower n) (qftControlledEvolution (n+1) t c)` + `= Evolution.qtowerCtrlWire n c.rev t.rev (phaseShiftGate (2π/2^{(c-t)+1}))`. + + So the QFT circuit's conditional rotation — a two-wire gate — is, on the grounded control tower, + precisely a **controlled one-qubit phase gate** touching only the two wires `c.rev` (control) and + `t.rev` (target). The QFT drives target `t` from the *later* wires `c > t`, and the register + bridge reverses the wire order (`Fin.rev`), so on the tower the control lands *above* its target, + `c.rev < t.rev` — exactly the configuration `Evolution.qtowerCtrlWire` is built for. After + deferring the terminal measurement of the control wire this becomes a classically-controlled + single-wire gate (the per-gate reduction), so the two-wire gate leaves the tower. + +## Proof + +Via the transported-gate re-expression combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: +it suffices to check, for every bit-string `b`, that the controlled tower gate +sends `towerKet n b` to the transport of the register gate's action on +`|finFunctionFinEquiv (b ∘ Fin.rev)⟩`. Both gates are **diagonal** (unlike the Hadamard), so both +sides reduce to a phase times `towerKet n b`; the phase agrees branch by branch on the control bit +`b c.rev`: + +* the left side: `qtowerCtrlWire_evolvePure_towerKet` (`c.rev < t.rev`, via `Fin.rev_lt_rev`) fires + `phaseShiftGate φ` on wire `t.rev` when `b c.rev = 1`, and the scalar multilinearity of the tower + product state in wire `t.rev` (the inline `smul_update`) pulls the phase gate's eigenvalue + `[1, e^{iφ}]_{b t.rev}` (`phaseShiftGate_op_apply_qubitBasis`) out of the product, leaving + `towerKet n b`; +* the right side: `qftControlledEvolution_evolvePure_quditBasis` gives the register phase + `[1, e^{2πi/2ᵏ}]_{b t.rev}` when `b c.rev = 1`, whose transport is pushed through the bridge + isometry (`map_smul`) and read by the binary-expansion dictionary + `quditPowTower_congr_quditBasis_apply` — the `Fin.rev`s aligning the wire orderings, collapsing by + `Fin.rev_rev`. + +The two phases agree because `e^{iφ} = e^{2πi/2ᵏ}` for `φ = 2π/2ᵏ` (a cast identity, `hphase`). + +The controlled-`Rₖ` gate and its basis action are in +`AxQM/Postulates/API/QftControlledEvolution.lean`; the tower gates used are in `QtowerCtrlWireGate` +and `EvolutionTowerBasisExt`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The transported Figure 5.1 controlled-`Rₖ` is the controlled single-wire phase gate on the +tower.** For `t < c` (the QFT drives target `t` from a later control wire `c`), transporting the +register controlled-`Rₖ` gate `qftControlledEvolution (n+1) t c` from the `2ⁿ⁺¹`-level register onto +the `(n+1)`-qubit control tower via the register bridge `quditPowTower n` yields exactly the +controlled single-wire gate applying the one-qubit phase gate `P(2π/2^{(c-t)+1})` to tower wire +`t.rev` gated on tower wire `c.rev`, + + `Evolution.congr (quditPowTower n) (qftControlledEvolution (n+1) t c)` + `= Evolution.qtowerCtrlWire n c.rev t.rev (phaseShiftGate (2π/2^{(c-t)+1}))`. + +This re-expresses the QFT circuit's only two-wire gate as an honest wire-addressed tower gate — a +controlled one-qubit phase gate on the wire pair `(c.rev, t.rev)`, `c.rev < t.rev` after the +register bridge's `Fin.rev`, touching no other wire — the third of the three Figure 5.1 gate shapes +the whole-circuit measured-QFT reduction (Problem 5.2) defers the terminal measurement past. Proved +through the combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: both gates are diagonal, so +the controlled tower gate (via `qtowerCtrlWire_evolvePure_towerKet` and the inline scalar +multilinearity `smul_update` of the tower product state in one wire) and the transported register +gate (via +`qftControlledEvolution_evolvePure_quditBasis`, the bridge isometry, and the dictionary +`quditPowTower_congr_quditBasis_apply`) send `towerKet n b` to the same phased basis state, the +phases agreeing by `e^{iφ} = e^{2πi/2ᵏ}`. -/ +theorem quditPowTower_congr_qftControlledEvolution (n : ℕ) (t c : Fin (n + 1)) (htc : t < c) : + Evolution.congr (quditPowTower n) (qftControlledEvolution (n + 1) t c) + = Evolution.qtowerCtrlWire n c.rev t.rev + (phaseShiftGate (2 * Real.pi / 2 ^ ((c : ℕ) - (t : ℕ) + 1))) := by + set φ : ℝ := 2 * Real.pi / 2 ^ ((c : ℕ) - (t : ℕ) + 1) with hφ + have hrev : c.rev < t.rev := Fin.rev_lt_rev.mpr htc + have hne : t ≠ c := ne_of_lt htc + -- Scalar multilinearity of the tower product state in one wire: pulling a wire's phase out of the + -- product. The single-scalar companion of the Hadamard re-expression's two-term multilinearity. + have smul_update : ∀ (N : ℕ) (ψ : Fin (N + 1) → PureState qubit) (i : Fin (N + 1)) (z : ℂ) + (ρ χ : PureState qubit), χ.vec = z • ρ.vec → + (towerProd N (Function.update ψ i χ)).vec + = z • (towerProd N (Function.update ψ i ρ)).vec := by + intro N + induction N with + | zero => + intro ψ i z ρ χ h + obtain rfl := Fin.fin_one_eq_zero i + simp only [towerProd_zero, Function.update_self] + exact h + | succ N ih => + intro ψ i z ρ χ h + refine Fin.cases ?_ ?_ i + · rw [towerProd_succ, Function.update_self, Fin.tail_update_zero, PureState.tmul_vec, h, + towerProd_succ, Function.update_self, Fin.tail_update_zero, PureState.tmul_vec] + exact (TensorProduct.smul_tmul' z ρ.vec _).symm + · intro i' + rw [towerProd_succ, Function.update_of_ne (Fin.succ_ne_zero i').symm, + Fin.tail_update_succ, PureState.tmul_vec, ih (Fin.tail ψ) i' z ρ χ h, towerProd_succ, + Function.update_of_ne (Fin.succ_ne_zero i').symm, Fin.tail_update_succ, + PureState.tmul_vec] + exact TensorProduct.tmul_smul z (ψ 0).vec _ + -- Phase identification `e^{iφ} = e^{2πi/2ᵏ}` for `φ = 2π/2ᵏ`. + have hphase : Complex.exp ((φ : ℂ) * Complex.I) + = Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1)) := by + rw [hφ]; congr 1; push_cast; ring + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + rw [qtowerCtrlWire_evolvePure_towerKet n c.rev t.rev hrev _ b, PureState.congr_vec, + qftControlledEvolution_evolvePure_quditBasis (n + 1) t c hne (fun i => b i.rev)] + by_cases hbc : b c.rev = 1 + · -- Control wire is `|1⟩`: both sides carry the phase on the target wire. + rw [ite_eq_left hbc, ite_eq_left hbc] + have hz : ((phaseShiftGate φ).evolvePure (qubitBasis (b t.rev))).vec + = ![(1 : ℂ), Complex.exp ((φ : ℂ) * Complex.I)] (b t.rev) • (qubitBasis (b t.rev)).vec := by + rw [Evolution.evolvePure_vec, phaseShiftGate_op_apply_qubitBasis] + have hupd : Function.update (fun j => qubitBasis (b j)) t.rev (qubitBasis (b t.rev)) + = fun j => qubitBasis (b j) := + Function.update_eq_self t.rev _ + rw [smul_update n (fun j => qubitBasis (b j)) t.rev _ (qubitBasis (b t.rev)) _ hz, + hupd, ← towerKet_eq_towerProd, map_smul, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply, hphase] + simp only [Fin.rev_rev] + · -- Control wire is `|0⟩`: both sides are the untouched basis state. + rw [ite_eq_right hbc, ite_eq_right hbc, one_smul, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply] + simp only [Fin.rev_rev] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerHadamard.lean b/LeanPool/AxQM/Core/QftTowerHadamard.lean new file mode 100644 index 0000000000..9b2fe4ae81 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerHadamard.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftHadamardEvolution +public import LeanPool.AxQM.Postulates.API.TowerProdMultilinear +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.QtowerSingleWireGate + +/-! +# The QFT Hadamard layer re-expressed as a single-wire gate on the tower (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a product of *transported* Figure 5.1 gates +(`qftTowerEvolution_eq_map_congr_prod`). To defer the terminal per-wire measurement +past that product gate by gate, each transported gate must be re-expressed as an honest +**wire-addressed tower `Evolution`**. This file does so for a Figure 5.1 **Hadamard**, the second of +the circuit's three gate shapes (the swap layer is done in `QftTowerSwap`; the controlled-`Rₖ` +rotations follow). + +## What is formalised + +* `quditPowTower_congr_qftHadamardEvolution` — **the transported Figure 5.1 Hadamard on wire `t` is + the single-wire Hadamard on tower wire `t.rev`.** Transporting the register Hadamard gate + `qftHadamardEvolution (n+1) t` (`Postulates/API`) onto the tower through the register bridge + `quditPowTower n` equals the single-wire gate `Evolution.qtowerSingleWire n t.rev hadamardGate` + that applies the one-qubit Hadamard to tower wire `t.rev`, the identity on every other wire: + + `Evolution.congr (quditPowTower n) (qftHadamardEvolution (n+1) t)` + `= Evolution.qtowerSingleWire n t.rev hadamardGate`. + + So the QFT circuit's Hadamard — a genuine one-qubit gate, never touching two wires — is, on the + grounded control tower, precisely the Hadamard on the single wire `t.rev` (the reversal `Fin.rev` + reconciling the big-endian register bridge with the little-endian wire-indexing of the Figure 5.1 + matrix gates). It is thus already in the form the deferred-measurement reduction wants: a + one-qubit gate on one measured wire. + +## Proof + +Via the transported-gate re-expression combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: +it suffices to check, for every bit-string `b`, that the single-wire Hadamard +sends `towerKet n b` to the transport of the register Hadamard's action on +`|finFunctionFinEquiv (b ∘ Fin.rev)⟩`. Unlike the swap (a basis permutation), the Hadamard produces +a **superposition**, so both sides are matched at the vector level as the two-term sum + + `∑_z hadamardC z (b t.rev) · towerKet n (Function.update b t.rev z)`. + +* the left side: `qtowerSingleWire_evolvePure_towerKet` puts the wire into `hadamardGate |b t.rev⟩`, + and the **tensor multilinearity of the tower product state in wire `t.rev`** (the shared + `towerProd_vec_update_sum_smul`) distributes the qubit Hadamard's column + `hadamardGate_evolvePure_qubitBasis_sum` over the two branch kets; +* the right side: `qftHadamardEvolution_evolvePure_quditBasis` gives the register two-term + superposition, whose transport is pushed through the bridge isometry term by term + (`map_sum` / `map_smul`) and read by the binary-expansion dictionary + `quditPowTower_congr_quditBasis_apply` — the `Fin.rev`s aligning the wire orderings. + +The Hadamard gate and its basis action are in `AxQM/Postulates/API/QftHadamardEvolution.lean`; the +tower gates used are in `QtowerSingleWireGate` and `EvolutionTowerBasisExt`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The transported Figure 5.1 Hadamard on wire `t` is the single-wire Hadamard on tower wire +`t.rev`.** Transporting the register Hadamard gate `qftHadamardEvolution (n+1) t` from the +`2ⁿ⁺¹`-level register onto the `(n+1)`-qubit control tower via the register bridge `quditPowTower n` +yields exactly the single-wire gate applying the one-qubit Hadamard to tower wire `t.rev`, + + `Evolution.congr (quditPowTower n) (qftHadamardEvolution (n+1) t)` + `= Evolution.qtowerSingleWire n t.rev hadamardGate`. + +This re-expresses the QFT circuit's Hadamard as an honest wire-addressed tower gate — a genuine +one-qubit gate on the single wire `t.rev`, touching no two wires at once — the second of the three +Figure 5.1 gate shapes the whole-circuit measured-QFT reduction (Problem 5.2) defers the terminal +measurement past. Proved through the combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: +both the single-wire gate (via `qtowerSingleWire_evolvePure_towerKet` and the tensor multilinearity +of the tower product state) and the transported register Hadamard (via +`qftHadamardEvolution_evolvePure_quditBasis`, the bridge isometry, and the dictionary +`quditPowTower_congr_quditBasis_apply`) send `towerKet n b` to the two-term superposition +`∑_z hadamardC z (b t.rev) · towerKet n (Function.update b t.rev z)`, the two `Fin.rev`s collapsing +by `Fin.rev_rev`. -/ +theorem quditPowTower_congr_qftHadamardEvolution (n : ℕ) (t : Fin (n + 1)) : + Evolution.congr (quditPowTower n) (qftHadamardEvolution (n + 1) t) + = Evolution.qtowerSingleWire n t.rev hadamardGate := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + apply PureState.ext + rw [qtowerSingleWire_evolvePure_towerKet, PureState.congr_vec, + qftHadamardEvolution_evolvePure_quditBasis, + towerProd_vec_update_sum_smul n (fun j => qubitBasis (b j)) t.rev + (fun z => Concrete.hadamardC z (b t.rev)) qubitBasis + (hadamardGate.evolvePure (qubitBasis (b t.rev))) + (hadamardGate_evolvePure_qubitBasis_sum (b t.rev)), + map_sum] + refine Finset.sum_congr rfl (fun z _ => ?_) + rw [map_smul, towerProd_update_qubitBasis b t z, ← PureState.congr_vec, + quditPowTower_congr_quditBasis_apply, update_rev_eq b t z] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerHeadLayer.lean b/LeanPool/AxQM/Core/QftTowerHeadLayer.lean new file mode 100644 index 0000000000..4093977ffc --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerHeadLayer.lean @@ -0,0 +1,143 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerHeadPhaseControl +public import LeanPool.AxQM.Core.QftTowerPhaseRecursion + +/-! +# The quantum Fourier transform's Figure 5.1 head layer (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) is assembled by an induction over the tower +depth whose one step *peels* the head control wire's Figure 5.1 gates off `qftTowerEvolution (n+1)` +and recurses on the tail. Those head gates are the **head layer**: a Hadamard on the head wire `0` +followed by the head control wire's cascade of controlled-`Rₖ` phase rotations onto every tail wire. +This file computes the head layer's action on a computational tower ket — the computational content +the peel matches — and, crucially, *where* the head layer deposits its phase. + +## The head layer produces the *last* output wire + +Chunk 3b-v-j established that `qftEvolution` is the **symmetric** DFT: the head Hadamard + cascade +imprint the phase of the *last* output wire, not the head (`qftTowerWirePhase_last`). This file +makes that concrete at the state level. On the input `towerKet (n+1) b`: + +* the head Hadamard sends the head wire's basis state `|b 0⟩` to the phased-plus state + `|+_{π·b 0}⟩` (`hadamardGate_evolvePure_qubitBasis_qubitPhasePlus`), the tail + `towerKet n (Fin.tail b)` untouched (`qtowerSingleWire_zero_hadamardGate_evolvePure_towerKet`); +* the head control wire's controlled-`Rₖ` phase cascade then advances that phased-plus head by the + total phase `∑ₜ (Fin.tail b t)·(2π·2^{t.rev}/2ⁿ⁺²)` + (`qtowerHeadCtrlPhaseCascade_evolvePure_qubitPhasePlus`), the tail still untouched. + +So the head layer sends `towerKet (n+1) b` to `|+_{θ}⟩ ⊗ towerKet n (Fin.tail b)` with +`θ = π·(b 0) + ∑ₜ (Fin.tail b t)·(2π·2^{t.rev}/2ⁿ⁺²)` — which is *exactly* +`qftTowerWirePhase (n+1) b (Fin.last (n+1))`, the last output wire's phase +(`qftTowerWirePhase_last`). The head wire ends in the last output wire's phased-plus state, no wire +entangled with the head. This identifies the head-produced content and is why the outer-induction +peel needs a cyclic wire permutation to route the head wire to the last position. + +## What is formalised + +* `qftHeadRotationList n` — the head control wire's Figure 5.1 rotation phases: for each tail wire + `t : Fin (n+1)`, the angle `2π·2^{t.rev}/2ⁿ⁺²` (`= 2π/2^{t+2}`, the QFT's `Rₜ₊₂`). +* `qftHeadLayer n` — the **head layer** as an `Evolution` on `qtower (n+1) qubit`: the head control + wire's controlled-`Rₖ` phase cascade after the head Hadamard. +* `qtowerSingleWire_zero_hadamardGate_evolvePure_towerKet` — the head Hadamard's action on a tower + ket: `H` on wire `0` sends `towerKet (n+1) b` to `|+_{π·b 0}⟩ ⊗ towerKet n (Fin.tail b)`. +* `qftHeadLayer_evolvePure_towerKet` — the **head layer's action**: it sends `towerKet (n+1) b` to + `|+_{θ}⟩ ⊗ towerKet n (Fin.tail b)` with `θ = qftTowerWirePhase (n+1) b (Fin.last (n+1))`, the + last output wire's phase — the head layer produces the last output wire. + +It composes the head phase cascade and the phase recursion. The Hadamard-to-phased-plus fact it +uses, `hadamardGate_evolvePure_qubitBasis_qubitPhasePlus`, is a single-qubit identity in +`AxQM/Postulates/API/PhasedPlus.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The QFT head control wire's Figure 5.1 rotation phases.** For each tail wire `t : Fin (n+1)`, +the head control wire drives a controlled phase rotation of angle +`2π·2^{t.rev}/2ⁿ⁺²` (equal to `2π/2^{t+2}`, the quantum Fourier transform's `Rₜ₊₂`). Written in the +`2π·2^{t.rev}/2ⁿ⁺²` form so that the head layer's total advance matches the last output wire's phase +`qftTowerWirePhase_last` term by term. The gates on distinct tail wires are diagonal and commute, so +the list order (here `List.finRange (n+1)`) is immaterial. -/ +def qftHeadRotationList (n : ℕ) : List (Fin (n + 1) × ℝ) := + (List.finRange (n + 1)).map fun t => (t, 2 * Real.pi * 2 ^ (t.rev : ℕ) / 2 ^ (n + 2)) + +/-- **The QFT's Figure 5.1 head layer** as an `Evolution` on `qtower (n+1) qubit`: a Hadamard on +the head wire `0` (`Evolution.qtowerSingleWire (n+1) 0 hadamardGate`) followed by the head control +wire's cascade of controlled-`Rₖ` phase gates onto the tail wires — one +`Evolution.qtowerCtrlWire (n+1) 0 t.succ (phaseShiftGate φ)` per `(t, φ)` of +`qftHeadRotationList n`, all controlled on the head wire. These are exactly the Figure 5.1 gates the +head control wire +carries; the head layer is what the outer-induction peel of the measured-QFT reduction reads off +`qftTowerEvolution (n+1)` before recursing on the tail. -/ +def qftHeadLayer (n : ℕ) : Evolution (qtower (n + 1) qubit) := + ((qftHeadRotationList n).map fun p => + Evolution.qtowerCtrlWire (n + 1) 0 p.1.succ (phaseShiftGate p.2)).prod + * Evolution.qtowerSingleWire (n + 1) 0 hadamardGate + +/-- **The head Hadamard's action on a tower ket.** A Hadamard on the head wire `0` sends the +computational tower ket `towerKet (n+1) b` to the phased-plus head `|+_{π·b 0}⟩` tensored with the +untouched tail `towerKet n (Fin.tail b)`: + + `H₀ (towerKet (n+1) b) = |+_{π·(b 0)}⟩ ⊗ towerKet n (Fin.tail b)`. + +On wire `0` the single-wire gate is `hadamardGate` on the head factor +(`Evolution.qtowerSingleWire_zero`), and `H|b 0⟩ = |+_{π·(b 0)}⟩` +(`hadamardGate_evolvePure_qubitBasis_qubitPhasePlus`); the tail factor `towerKet n (Fin.tail b)` is +carried through unchanged. This is the input the head control wire's phase cascade then acts on. -/ +theorem qtowerSingleWire_zero_hadamardGate_evolvePure_towerKet (n : ℕ) (b : Fin (n + 2) → Fin 2) : + (Evolution.qtowerSingleWire (n + 1) 0 hadamardGate).evolvePure (towerKet (n + 1) b) + = (qubitPhasePlus (Real.pi * ((b 0 : ℕ) : ℝ))).tmul (towerKet n (Fin.tail b)) := by + rw [Evolution.qtowerSingleWire_zero, towerKet_succ] + -- the tower head-peel `qtower (n+1) qubit = qubit ⊗ qtower n qubit` is only definitional, so + -- `onLeft_evolvePure` matches up to reducible defeq (`erw`), not syntactically. + erw [Evolution.onLeft_evolvePure] + rw [hadamardGate_evolvePure_qubitBasis_qubitPhasePlus] + rfl + +/-- **Problem 5.2 (the Figure 5.1 head layer produces the last output wire).** The QFT's head layer +`qftHeadLayer n` sends the computational tower ket `towerKet (n+1) b` to the phased-plus head +`|+_{θ}⟩` tensored with the untouched tail `towerKet n (Fin.tail b)`, where +`θ = qftTowerWirePhase (n+1) b (Fin.last (n+1))` is the **last** output wire's QFT phase: + + `qftHeadLayer n (towerKet (n+1) b) + = |+_{qftTowerWirePhase (n+1) b (Fin.last (n+1))}⟩ ⊗ towerKet n (Fin.tail b)`. + +The head Hadamard puts the head wire into `|+_{π·(b 0)}⟩` +(`qtowerSingleWire_zero_hadamardGate_evolvePure_towerKet`) and the head control wire's +controlled-`Rₖ` cascade advances it by `∑ₜ (Fin.tail b t)·(2π·2^{t.rev}/2ⁿ⁺²)` +(`qtowerHeadCtrlPhaseCascade_evolvePure_qubitPhasePlus`), the tail untouched throughout — no wire +entangled with the head. Because `qftEvolution` is the **symmetric** DFT, that total angle is +exactly the *last* output wire's phase (`qftTowerWirePhase_last`), not the head +wire's. This is why the outer-induction peel routes the head-produced wire to the last position by a +cyclic wire +permutation. -/ +theorem qftHeadLayer_evolvePure_towerKet (n : ℕ) (b : Fin (n + 2) → Fin 2) : + (qftHeadLayer n).evolvePure (towerKet (n + 1) b) + = (qubitPhasePlus (qftTowerWirePhase (n + 1) b (Fin.last (n + 1)))).tmul + (towerKet n (Fin.tail b)) := by + rw [qftHeadLayer, Evolution.mul_def, Evolution.evolvePure_comp, + qtowerSingleWire_zero_hadamardGate_evolvePure_towerKet, + qtowerHeadCtrlPhaseCascade_evolvePure_qubitPhasePlus, qftTowerWirePhase_last] + -- The head cascade's total advance is the last output wire's Fourier fraction, term by term. + have hsum : ((qftHeadRotationList n).map fun p => p.2 * ((Fin.tail b p.1 : ℕ) : ℝ)).sum + = ∑ t : Fin (n + 1), + ((Fin.tail b t : ℕ) : ℝ) * (2 * Real.pi * 2 ^ (t.rev : ℕ) / 2 ^ (n + 2)) := by + rw [qftHeadRotationList, List.map_map, ← List.ofFn_eq_map, List.sum_ofFn] + exact Finset.sum_congr rfl fun t _ => mul_comm _ _ + rw [hsum] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerPeel.lean b/LeanPool/AxQM/Core/QftTowerPeel.lean new file mode 100644 index 0000000000..ae37317e26 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerPeel.lean @@ -0,0 +1,201 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerHeadLayer +public import LeanPool.AxQM.Core.QtowerWirePermutation +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt + +/-! +# The Figure 5.1 head-layer peel of the tower QFT (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) is assembled by an induction over the tower +depth whose one step *peels* the head control wire's Figure 5.1 gates off `qftTowerEvolution (n+1)` +and recurses on the tail. The head layer's state-level action is +`qftHeadLayer_evolvePure_towerKet`: the head Hadamard and head control cascade send +`towerKet (n+1) b` to `|+_θ⟩ ⊗ towerKet n (Fin.tail b)` with `θ` the **last** output wire's phase. +This file closes the peel: it exhibits `qftTowerEvolution (n+1)` as the composite + + `qftTowerEvolution (n+1) = Φ ∘ (qftTowerEvolution n on the tail) ∘ qftHeadLayer n`, + +`Φ` the cyclic wire permutation `(finRotate (n+2)).symm` that routes the head-produced last wire +back into position — the recursive circuit structure of Figure 5.1. + +## The peel and its permutation + +Read on a computational tower ket `towerKet (n+1) b`, the three factors compose to a product state +whose wires must be matched against the product form (N&C eq. 5.4, `qftTowerEvolution_evolvePure_ +towerKet_towerProd`). The head layer deposits the *last* output wire's phased-plus state on the head +wire and leaves the tail computational; the tail QFT +`(qftTowerEvolution n).onRight qubit` turns the tail into its product form, whose wires carry the +first `n+1` output phases (`qftTowerWirePhase_castSucc_qubitPhasePlus`). So after the +head layer and the tail QFT wire `0` holds output wire `n+1` and wire `j+1` holds output wire `j` — +one cyclic shift away from the product form. The permutation `Φ = (finRotate (n+2)).symm` closes +that shift: its action moves the factor on wire `finRotate (n+2) i` to wire `i`, i.e. output wire +`i` to wire `i`. + +## What is formalised + +* `qtowerQubitTensorPow_congr_towerProd` / `qtowerQubitTensorPow_symm_congr_piTensor_towerProd` — + the forward/backward `qtower ↔ tensor-power` bridge dictionary at the level of an **arbitrary** + product state `towerProd n φ` (the basis-input `qtowerQubitTensorPow_congr_towerKet` / + `qtowerQubitTensorPow_symm_congr_piTensor` are the special case `φ i = |b i⟩`): it carries + `towerProd n φ` to the symmetric product state `⨂ₚ i, φ i` and back. +* `qtowerPermWires_evolvePure_towerProd` — the tower wire-permutation gate's action on a product + state: `qtowerPermWires σ (towerProd n φ) = towerProd n (φ ∘ σ⁻¹)` (the arbitrary-factor + generalisation of `qtowerPermWires_evolvePure_towerKet`, which permutes basis wires). +* `qftTowerEvolution_succ_eq_qftHeadLayer_peel` — **the peel identity**: + `qftTowerEvolution (n+1) = qtowerPermWires (finRotate (n+2)).symm · (qftTowerEvolution n).onRight + qubit · qftHeadLayer n`, the recursive Figure 5.1 structure of the tower QFT. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **The `qtower ↔ tensor-power` bridge on a product state.** The bridge `qtowerQubitTensorPow n` +carries the right-nested product state `towerProd n φ` on `qtower n qubit` to the symmetric product +state `⨂ₚ i, φ i` on `qubit ^⊗ₛ (n+1)`. This is `qtowerQubitTensorPow_congr_towerKet` (which +handles the computational-basis case `φ i = |b i⟩`) generalised to an **arbitrary** per-wire pure +state `φ i`; the proof is the same tower induction, the head-peel iso +`qtower (k+1) qubit = qubit ⊗ qtower k qubit` handled definitionally by `change`. It lets the +wire-permutation action be read off a general product input. -/ +theorem qtowerQubitTensorPow_congr_towerProd (n : ℕ) (φ : Fin (n + 1) → PureState qubit) : + PureState.congr (qtowerQubitTensorPow n) (towerProd n φ) = PureState.piTensor fun i => φ i := by + suffices key : ∀ (m : ℕ) (ψ : Fin (m + 1) → PureState qubit), + (qtowerQubitTensorPow m).toIsometry (towerProd m ψ).vec = ⨂ₜ[ℂ] i, (ψ i).vec by + apply PureState.ext + rw [PureState.congr_vec, PureState.piTensor_vec] + exact key n φ + intro m + induction m with + | zero => + intro ψ + rw [qtowerQubitTensorPow_zero, towerProd_zero] + erw [QSystem.tensorPowOne_toIsometry_apply] + congr 1 + funext i + obtain rfl : i = 0 := Subsingleton.elim i 0 + rfl + | succ k ih => + intro ψ + rw [towerProd_succ, PureState.tmul_vec] + change (QSystem.tensorPowSuccHead qubit (k + 1)).symm.toIsometry + (((QSystem.Iso.refl qubit).tmul (qtowerQubitTensorPow k)).toIsometry + ((ψ 0).vec ⊗ₜ[ℂ] (towerProd k (Fin.tail ψ)).vec)) + = ⨂ₜ[ℂ] i, (ψ i).vec + rw [QSystem.Iso.tmul_toIsometry_tmul, ih (Fin.tail ψ), + QSystem.Iso.symm_toIsometry, QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod] + congr 1 + funext i + rcases Fin.eq_zero_or_eq_succ i with rfl | ⟨j, rfl⟩ <;> + simp [QSystem.Iso.refl_toIsometry, Fin.tail] + +/-- **Backward `qtower ↔ tensor-power` bridge on a product state.** The inverse bridge +`(qtowerQubitTensorPow n).symm` carries the symmetric product state `⨂ₚ i, φ i` back to the +right-nested tower product state `towerProd n φ`. The `.symm` companion of +`qtowerQubitTensorPow_congr_towerProd`, and the arbitrary-factor generalisation of the basis-input +`qtowerQubitTensorPow_symm_congr_piTensor`; obtained from the forward bridge by the +`PureState.congr` roundtrip cancellation `PureState.congr_symm_congr`. This is the +placement-dictionary direction the product-state wire-permutation action consumes. -/ +theorem qtowerQubitTensorPow_symm_congr_piTensor_towerProd (n : ℕ) + (φ : Fin (n + 1) → PureState qubit) : + PureState.congr (qtowerQubitTensorPow n).symm (PureState.piTensor fun i => φ i) + = towerProd n φ := by + rw [← qtowerQubitTensorPow_congr_towerProd n φ, PureState.congr_symm_congr] + +/-- **The tower wire-permutation gate on a product state.** Applying `Evolution.qtowerPermWires σ` +to the product state `towerProd n φ` yields `towerProd n (fun i => φ (σ⁻¹ i))`: the factor on wire +`j` is moved to wire `σ j`. This is the arbitrary-factor generalisation of +`qtowerPermWires_evolvePure_towerKet` (which permutes basis wires `|b j⟩`), obtained by transporting +`towerProd n φ` to the symmetric product state through the backward bridge dictionary +`qtowerQubitTensorPow_symm_congr_piTensor_towerProd`, applying the product-state permutation action +`Evolution.permWires_evolvePure_piTensor`, and folding back. -/ +theorem qtowerPermWires_evolvePure_towerProd (σ : Equiv.Perm (Fin (n + 1))) + (φ : Fin (n + 1) → PureState qubit) : + (Evolution.qtowerPermWires σ).evolvePure (towerProd n φ) + = towerProd n fun i => φ (σ.symm i) := by + erw [Evolution.qtowerPermWires, ← qtowerQubitTensorPow_symm_congr_piTensor_towerProd n φ, + Evolution.congr_evolvePure_congr, Evolution.permWires_evolvePure_piTensor] + exact qtowerQubitTensorPow_symm_congr_piTensor_towerProd n _ + +/-- **The tail QFT of the head-layer peel.** The `n`-tower quantum Fourier transform +`qftTowerEvolution n` lifted onto the `(n+1)`-tower as a gate acting on the tail wires `1 … n+1` +only (the head wire `0` idle), i.e. `(qftTowerEvolution n).onRight qubit` retyped through the +definitional head-peel `qtower (n+1) qubit = qubit ⊗ qtower n qubit`. This is the recursive call of +the Figure 5.1 peel `qftTowerEvolution_succ_eq_qftHeadLayer_peel`. -/ +def qftTailEvolution (n : ℕ) : Evolution (qtower (n + 1) qubit) := + (qftTowerEvolution n).onRight qubit + +/-- **Problem 5.2 (the Figure 5.1 head-layer peel).** The transported quantum Fourier transform on +the `(n+1)`-tower factors as its Figure 5.1 head layer, then the QFT on the tail wires, then a +cyclic wire permutation: + + `qftTowerEvolution (n+1) + = qtowerPermWires (finRotate (n+2)).symm · qftTailEvolution n · qftHeadLayer n`. + +Read on a computational tower ket `towerKet (n+1) b` and matched against the product form (N&C +eq. 5.4): the head layer produces `|+_{θ}⟩ ⊗ towerKet n (Fin.tail b)` with `θ` the **last** output +wire's phase (`qftHeadLayer_evolvePure_towerKet`); the tail QFT `qftTailEvolution n` turns the tail +into its product form, whose wire `j` carries output wire `j`'s phase +(`qftTowerWirePhase_castSucc_qubitPhasePlus`). So after the two the head wire holds output wire +`n+1` and wire `j+1` holds output wire `j` — the cyclic permutation +`(finRotate (n+2)).symm` (whose action sends the factor on wire `finRotate (n+2) i` to wire `i`) +routes each output wire `i` back to wire `i`, reproducing the product form +`qftTowerEvolution_evolvePure_towerKet_towerProd`. This is the recursive circuit structure of Figure +5.1: peel the head control wire's gates, recurse on the tail. -/ +theorem qftTowerEvolution_succ_eq_qftHeadLayer_peel (n : ℕ) : + qftTowerEvolution (n + 1) + = Evolution.qtowerPermWires (finRotate (n + 2)).symm + * qftTailEvolution n + * qftHeadLayer n := by + apply Evolution.ext_towerKet + intro b + rw [qftTowerEvolution_evolvePure_towerKet_towerProd] + simp only [Evolution.mul_def, Evolution.evolvePure_comp, qftTailEvolution] + rw [qftHeadLayer_evolvePure_towerKet] + erw [Evolution.mul_def, Evolution.evolvePure_comp, Evolution.onRight_evolvePure] + rw [qftTowerEvolution_evolvePure_towerKet_towerProd] + -- Repackage the head-plus-tail product `|+_θ⟩ ⊗ towerProd n (…)` as a single `towerProd (n+1)`. + rw [← towerProd_cons, qtowerPermWires_evolvePure_towerProd, Equiv.symm_symm] + -- Match wire by wire: the permuted head-plus-tail factor on wire `i` is output wire `i`'s phase. + congr 1 + funext i + induction i using Fin.lastCases with + | last => rw [finRotate_last, Fin.cons_zero] + | cast j => + rw [finRotate_apply, Fin.coeSucc_eq_succ, Fin.cons_succ, + qftTowerWirePhase_castSucc_qubitPhasePlus] + +/-- **Problem 5.2 (the head-layer peel at the state level).** The evolve-level twin of the +operator-level peel `qftTowerEvolution_succ_eq_qftHeadLayer_peel`: applying the transported quantum +Fourier transform on the `(n+1)`-tower to a state `ρ` factors as the head layer, then the tail QFT, +then the cyclic wire permutation, each applied in turn: + + `(qftTowerEvolution (n+1)).evolve ρ + = (qtowerPermWires (finRotate (n+2)).symm).evolve + ((qftTailEvolution n).evolve ((qftHeadLayer n).evolve ρ))`. + +Immediate from the operator-level peel by unfolding the `Evolution`-monoid product into sequential +state evolution (`Evolution.mul_def`, `Evolution.evolve_comp`). This is the form the measured-QFT +outer induction reads before deferring the terminal measurement past each layer. -/ +theorem qftTowerEvolution_succ_evolve_peel (ρ : State (qtower (n + 1) qubit)) : + (qftTowerEvolution (n + 1)).evolve ρ + = (Evolution.qtowerPermWires (finRotate (n + 2)).symm).evolve + ((qftTailEvolution n).evolve ((qftHeadLayer n).evolve ρ)) := by + rw [qftTowerEvolution_succ_eq_qftHeadLayer_peel] + simp only [Evolution.mul_def, Evolution.evolve_comp] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerPhaseRecursion.lean b/LeanPool/AxQM/Core/QftTowerPhaseRecursion.lean new file mode 100644 index 0000000000..f0b1f33d78 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerPhaseRecursion.lean @@ -0,0 +1,145 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerProductForm + +/-! +# The tower QFT product form's phase recursion (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) is assembled by an induction over the tower +depth. Its computational core is Nielsen & Chuang's product form (eq. 5.4, stated as +`qftTowerEvolution_evolvePure_towerKet_towerProd`): the transported QFT sends the +tower ket `towerKet n b` to the product state `towerProd n (fun i => qubitPhasePlus +(qftTowerWirePhase n b i))`, a phased-plus state `(|0⟩ + e^{iθᵢ}|1⟩)/√2` on every wire. This file +supplies the **recursion of the per-wire phases** `qftTowerWirePhase` that the outer induction's +peel matches — the number-theoretic heart of "peel the head Figure 5.1 gates off `qftTowerEvolution +(n+1)` and recurse on the tail". + +## The recursion (and why the naive head-first peel fails) + +Writing `J = Σₘ b(m) 2ⁿ⁺¹⁻ᵐ` for the big-endian register index of the input, output wire `i` of the +`(n+1)`-tower carries the binary fraction `qftTowerWirePhase (n+1) b i = 2π·J / 2^{i+1}` (mod 2π). +The **symmetric** DFT bakes the Figure 5.1 output-reversal into this formula, so: + +* the *first* `n+1` output wires `i.castSucc` (`i : Fin (n+1)`) carry exactly the phases of the + **`n`-tower QFT of the tail input** `Fin.tail b`: `qftTowerWirePhase (n+1) b i.castSucc` and + `qftTowerWirePhase n (Fin.tail b) i` differ by `2π·(b 0)·2^{i.rev}`, an integer multiple of `2π` + (`qftTowerWirePhase_castSucc`), hence the phased-plus states agree + (`qftTowerWirePhase_castSucc_qubitPhasePlus`); +* the *new*, last output wire `Fin.last (n+1)` carries the **full** fraction of all input bits, + `π·(b 0) + Σₜ (Fin.tail b t)·2π·2^{t.rev}/2ⁿ⁺²` (`qftTowerWirePhase_last`) — precisely the angle + a head Hadamard (`π·b 0`) then the head-wire controlled-`Rₖ` phase cascade (the sum) imprints. + +The key consequence for the reduction's design: it is the *last* output wire, not the head wire, +that the head Figure 5.1 gates produce, so a naive head-first peel `qftTowerEvolution (n+1) = tail ∘ +head-cascade ∘ head-Hadamard` with `tail = (qftTowerEvolution n).onRight qubit` does **not** hold — +the tail wire phases `qftTowerWirePhase (n+1) b (j.succ)` are *not* those of the `n`-tower QFT. The +faithful peel routes the head-produced wire to the last position by a cyclic wire permutation (the +Figure 5.1 swap layer, `Evolution.qtowerPermWires`); these phase identities are its bookkeeping. + +The `2π`-periodicity of `qubitPhasePlus` this uses is `qubitPhasePlus_two_pi_nat_add`, in +`AxQM/Postulates/API/PhasedPlus.lean`; the arithmetic register peel +`finFunctionFinEquiv_rev_succ` is a `private` lemma of this file. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Peel the leading bit off the big-endian register index.** The register index the bridge +identifies `towerKet (n+1) b` with, `Σₘ b(m.rev)·2ᵐ` over `Fin (n+2)`, splits as `(b 0)·2ⁿ⁺¹` (the +most-significant bit `b 0`, on wire `Fin.last` after the reversal) plus the tail register index +`Σₘ (Fin.tail b)(m.rev)·2ᵐ` over `Fin (n+1)`. The arithmetic behind the tower QFT phase recursion: +splitting the leading input wire out of the Fourier sum. `private` — a pure-arithmetic one-off with +no physics content, kept local to this file, matching the library's convention for +`finFunctionFinEquiv` helpers (cf. the `private` `finFunctionFinEquiv_symm_last_eq_div` in +`Core/QftTowerBasis`). -/ +private theorem finFunctionFinEquiv_rev_succ (n : ℕ) (b : Fin (n + 2) → Fin 2) : + ((finFunctionFinEquiv (fun m => b m.rev) : Fin (2 ^ (n + 2))) : ℕ) + = (b 0 : ℕ) * 2 ^ (n + 1) + + ((finFunctionFinEquiv (fun m => (Fin.tail b) m.rev) : Fin (2 ^ (n + 1))) : ℕ) := by + rw [finFunctionFinEquiv_apply, finFunctionFinEquiv_apply, Fin.sum_univ_castSucc, Fin.rev_last, + Fin.val_last, add_comm] + congr 1 + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Fin.rev_castSucc, Fin.val_castSucc] + rfl + +/-- **The tower QFT phase recursion (tail wires).** The first `n+1` output wires of the +`(n+1)`-tower QFT carry exactly the phases of the `n`-tower QFT of the tail input `Fin.tail b`, up +to an integer multiple of `2π`: + + `qftTowerWirePhase (n+1) b i.castSucc = 2π·(b 0)·2^{i.rev} + qftTowerWirePhase n (Fin.tail b) i`. + +Substituting the leading-bit peel `finFunctionFinEquiv_rev_succ` of the register index into the +phase formula: the extra term is the leading input bit `b 0`, which only shifts the phase by an +integer +multiple of `2π` on these wires (`2^{i.rev}` is a natural number). -/ +theorem qftTowerWirePhase_castSucc (n : ℕ) (b : Fin (n + 2) → Fin 2) (i : Fin (n + 1)) : + qftTowerWirePhase (n + 1) b i.castSucc + = 2 * Real.pi * (((b 0 : ℕ) * 2 ^ (i.rev : ℕ) : ℕ) : ℝ) + + qftTowerWirePhase n (Fin.tail b) i := by + rw [qftTowerWirePhase, qftTowerWirePhase, Fin.rev_castSucc, finFunctionFinEquiv_rev_succ, + Fin.val_succ, pow_succ (2 : ℝ) (i.rev : ℕ), pow_succ (2 : ℝ) (n + 1)] + push_cast + field_simp + +/-- **The tower QFT phase recursion, at the level of the phased-plus output wires.** On the first +`n+1` output wires, the transported `(n+1)`-tower QFT and the transported `n`-tower QFT of the tail +input produce the *same* phased-plus state: + + `qubitPhasePlus (qftTowerWirePhase (n+1) b i.castSucc) = qubitPhasePlus (qftTowerWirePhase n + (Fin.tail b) i)`. + +The `2π·(b 0)·2^{i.rev}` phase difference (`qftTowerWirePhase_castSucc`) is invisible to the +phased-plus state (`qubitPhasePlus_two_pi_nat_add`). This is the per-wire statement the outer +induction's peel matches against the tail recursion `(qftTowerEvolution n).onRight qubit`. -/ +theorem qftTowerWirePhase_castSucc_qubitPhasePlus (n : ℕ) (b : Fin (n + 2) → Fin 2) + (i : Fin (n + 1)) : + qubitPhasePlus (qftTowerWirePhase (n + 1) b i.castSucc) + = qubitPhasePlus (qftTowerWirePhase n (Fin.tail b) i) := by + rw [qftTowerWirePhase_castSucc, qubitPhasePlus_two_pi_nat_add] + +/-- **The tower QFT phase recursion (the new last wire).** The last output wire of the `(n+1)`-tower +QFT — the wire the recursion *adds* — carries the full binary fraction of all input bits: + + `qftTowerWirePhase (n+1) b (Fin.last (n+1)) + = π·(b 0) + Σₜ (Fin.tail b t)·(2π·2^{t.rev}/2ⁿ⁺²)`. + +This is exactly the phase a head Hadamard (contributing `π·(b 0)`, since `H|b₀⟩ = |+_{π·b₀}⟩`) +followed by the head control wire's controlled-`Rₖ` phase cascade (contributing the sum, one term +`2π·2^{t.rev}/2ⁿ⁺²` per tail wire `t`) imprints — the Figure 5.1 head layer the reduction defers the +measurement past. Proved by peeling the leading bit `b 0` (contributing `π·(b 0)`) out of the +register index and re-indexing the remaining Fourier sum over the tail wires by `Fin.rev`. -/ +theorem qftTowerWirePhase_last (n : ℕ) (b : Fin (n + 2) → Fin 2) : + qftTowerWirePhase (n + 1) b (Fin.last (n + 1)) + = Real.pi * (b 0 : ℕ) + + ∑ t : Fin (n + 1), + (Fin.tail b t : ℕ) * (2 * Real.pi * 2 ^ (t.rev : ℕ) / 2 ^ (n + 2)) := by + rw [qftTowerWirePhase, Fin.rev_last, finFunctionFinEquiv_rev_succ, finFunctionFinEquiv_apply, + Fin.val_zero, pow_zero, mul_one, + -- Re-index the tail register sum `Σₘ (tail b)(m.rev)·2ᵐ` over the wires `t = m.rev`. + show (∑ m : Fin (n + 1), ((Fin.tail b m.rev : Fin 2) : ℕ) * 2 ^ (m : ℕ) : ℕ) + = ∑ t : Fin (n + 1), ((Fin.tail b t : Fin 2) : ℕ) * 2 ^ (t.rev : ℕ) from + Fintype.sum_equiv Fin.revPerm _ _ (fun m => by simp [Fin.rev_rev])] + push_cast + rw [mul_add, add_div, Finset.mul_sum, Finset.sum_div] + congr 1 + · rw [pow_succ] + field_simp + ring + · refine Finset.sum_congr rfl fun t _ => ?_ + ring + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerProductForm.lean b/LeanPool/AxQM/Core/QftTowerProductForm.lean new file mode 100644 index 0000000000..c2a2fc817b --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerProductForm.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerCircuit +public import LeanPool.AxQM.Core.QtowerSingleWireGate +public import LeanPool.AxQM.Postulates.API.PhasedPlus + +/-! +# The tower QFT as a product of per-wire phased-plus states (N&C Problem 5.2) + +Nielsen & Chuang's **product form of the quantum Fourier transform** (eq. 5.4) reads the transform +on a computational-basis input as a *tensor product of single-qubit states*: each output wire +carries a phased-plus state `|+_θ⟩ = (|0⟩ + e^{iθ}|1⟩)/√2`, its relative phase the binary +fraction the QFT appends to that wire. This file transports that product form onto the tower +`qtower n qubit` on which the measured-QFT reduction (Problem 5.2) reads the circuit gate by gate. + +The outer tower induction that assembles the whole-circuit reduction peels the head control wire's +Figure 5.1 gates (a Hadamard and its controlled-`Rₖ` cascade) off `qftTowerEvolution (n+1)` and +recurses on the tail. The peel's content is an `Evolution` identity checked on every +computational tower ket `towerKet n b` (`Evolution.ext_towerKet`), and *both* sides of that check +are read against this product form — the transported QFT on the left, the composed head-and-tail +gates on the right. This basis-state reading is the shared computational core of the peel. + +## What is formalised + +* `qftTowerWirePhase n b i` — the **per-wire QFT phase** wire `i` of the tower acquires on input + `towerKet n b`: `2π · J · 2^{i.rev} / 2^{n+1}` with `J = finFunctionFinEquiv (b ∘ Fin.rev)` + the little-endian register index the bridge sends `towerKet n b` to. The `Fin.rev`s reconcile the + big-endian register bridge with the little-endian wire indexing of the Figure 5.1 gates. +* `qftTowerEvolution_evolvePure_towerKet_towerProd` — **the product form on the tower**: the + transported QFT sends `towerKet n b` to the tower product state + `towerProd n (fun i => qubitPhasePlus (qftTowerWirePhase n b i))` — a phased-plus state on every + wire, no entanglement (N&C eq. 5.4 read on the tower). + +## Proof + +The tower reader `qftTowerEvolution_evolvePure_towerKet` presents the left side as +the transport of the monolithic register QFT's action on `|J⟩`, and +`qftEvolution_evolvePure_quditBasis` expands it as the Fourier superposition +`∑_K (1/√2^{n+1}) e^{2πi J K / 2^{n+1}} |K⟩`. Re-indexing +the register sum over wire bit-strings `kbits` (`finFunctionFinEquiv`) turns the exponential into a +product over wires (`Complex.exp_sum`), transports each ket to `towerKet n (kbits ∘ Fin.rev)` (the +bridge dictionary `quditPowTower_congr_quditBasis_apply`), and — after the endianness re-index +`kbits ↦ kbits ∘ Fin.rev` — matches the multilinear expansion of the tower product state +`towerProd n (fun i => qubitPhasePlus …)` term by term, the per-wire coefficient +`invSqrt2 · e^{iθ_i}^{bit}` agreeing with the QFT's product coefficient. The all-wire multilinear +expansion of `towerProd` into the computational basis (the input to the match) is proved inline by +induction on the tower, the tensor bilinearity of `PureState.tmul` distributing the per-wire +superpositions — the all-wire generalisation of the single-wire multilinearity the Figure 5.1 +Hadamard re-expression uses. + +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open Matrix + +noncomputable section + +namespace AxQM + +/-- **The per-wire QFT phase.** On input `towerKet n b`, the transported quantum Fourier transform +leaves wire `i` of the tower in the phased-plus state `(|0⟩ + e^{iθ}|1⟩)/√2` with angle +`θ = qftTowerWirePhase n b i = 2π · J · 2^{i.rev} / 2^{n+1}`, where +`J = (finFunctionFinEquiv (fun m => b m.rev) : Fin (2^{n+1}))` is the little-endian register index +the bridge `quditPowTower n` identifies `towerKet n b` with. The `Fin.rev`s reconcile the big-endian +register bridge with the little-endian `finFunctionFinEquiv` wire indexing of the Figure 5.1 gates, +the same `Fin.rev` bookkeeping the tower reader carries. -/ +def qftTowerWirePhase (n : ℕ) (b : Fin (n + 1) → Fin 2) (i : Fin (n + 1)) : ℝ := + 2 * Real.pi * ((finFunctionFinEquiv (fun m => b m.rev) : Fin (2 ^ (n + 1))) : ℕ) + * (2 ^ (i.rev : ℕ)) / (2 ^ (n + 1)) + +/-- **Problem 5.2 (the tower QFT is a product of per-wire phased-plus states — N&C eq. 5.4).** The +transported quantum Fourier transform `qftTowerEvolution n` sends the computational tower ket +`towerKet n b` to the tower product state + + `towerProd n (fun i => qubitPhasePlus (qftTowerWirePhase n b i))`, + +a phased-plus state `(|0⟩ + e^{iθ_i}|1⟩)/√2` on every wire `i`, `θ_i = qftTowerWirePhase n b i`, +and no entanglement between wires — Nielsen & Chuang's product form (eq. 5.4) read on the qubit +tower. This is the shared basis-state reading the outer tower induction (Problem 5.2) matches both +the transported QFT and the composed head-and-tail Figure 5.1 gates against. -/ +theorem qftTowerEvolution_evolvePure_towerKet_towerProd (n : ℕ) (b : Fin (n + 1) → Fin 2) : + (qftTowerEvolution n).evolvePure (towerKet n b) + = towerProd n (fun i => qubitPhasePlus (qftTowerWirePhase n b i)) := by + -- **All-wire multilinear expansion of a tower product state**: + -- if each wire's state `φ i` expands with coefficients `c i`, the tower product `towerProd N φ` + -- expands over the whole computational tower basis with product coefficients. By induction on the + -- tower, distributing the head wire's superposition through the tensor product + -- (`PureState.tmul_vec` bilinearity) — the all-wire generalisation of the single-wire + -- multilinearity the Figure 5.1 Hadamard re-expression uses. + have towerProd_vec_eq_sum : ∀ (N : ℕ) (c : Fin (N + 1) → Fin 2 → ℂ) + (φ : Fin (N + 1) → PureState qubit), + (∀ i, (φ i).vec = ∑ z, c i z • (qubitBasis z).vec) → + (towerProd N φ).vec = ∑ k : Fin (N + 1) → Fin 2, (∏ i, c i (k i)) • (towerKet N k).vec := by + intro N + induction N with + | zero => + intro c φ hφ + rw [towerProd_zero, hφ 0] + refine (Fintype.sum_equiv (Equiv.funUnique (Fin 1) (Fin 2)) + (fun k => (∏ i, c i (k i)) • (towerKet 0 k).vec) + (fun z => c 0 z • (qubitBasis z).vec) (fun k => ?_)).symm + rw [Fin.prod_univ_one, towerKet_eq_towerProd, towerProd_zero] + rfl + | succ N ih => + intro c φ hφ + rw [towerProd_succ, PureState.tmul_vec, hφ 0, + ih (fun i => c i.succ) (Fin.tail φ) (fun i => hφ i.succ), TensorProduct.sum_tmul, + ← (Fin.consEquiv fun _ : Fin (N + 2) => Fin 2).sum_comp + (fun k => (∏ i, c i (k i)) • (towerKet (N + 1) k).vec), + Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun a _ => ?_ + rw [TensorProduct.tmul_sum] + refine Finset.sum_congr rfl fun k' _ => ?_ + simp only [Fin.consEquiv_apply, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, + towerKet_succ, PureState.tmul_vec] + rw [TensorProduct.smul_tmul_smul] + rfl + -- The per-wire computational-basis coefficient of the phased-plus output on wire `i`: + -- `invSqrt2 · (e^{iθ_i})^z`, so `c i 0 = invSqrt2` and `c i 1 = invSqrt2 · e^{iθ_i}`. + set c : Fin (n + 1) → Fin 2 → ℂ := fun i z => + Concrete.invSqrt2 * Complex.exp ((qftTowerWirePhase n b i : ℂ) * Complex.I) ^ (z : ℕ) + with hc_def + have hc : ∀ i : Fin (n + 1), + (qubitPhasePlus (qftTowerWirePhase n b i)).vec = ∑ z, c i z • (qubitBasis z).vec := by + intro i + rw [qubitPhasePlus_vec, Fin.sum_univ_two, hc_def] + simp only [Fin.val_zero, Fin.val_one, pow_zero, pow_one, mul_one] + rw [smul_add, smul_smul] + apply PureState.ext + rw [towerProd_vec_eq_sum n c (fun i => qubitPhasePlus (qftTowerWirePhase n b i)) hc, + qftTowerEvolution_evolvePure_towerKet, qftEvolution_evolvePure_quditBasis, + PureState.congr_vec, qftFourierImage_vec, map_sum] + -- Re-index the register sum `∑ x` over wire bit-strings `k`, `x = enc (k ∘ rev)`, so the two + -- `Fin.rev`s in the bridge dictionary and the wire indexing cancel and `x ↦ towerKet n k`. + refine (Fintype.sum_equiv + ((Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin 2))).trans finFunctionFinEquiv) + _ _ (fun k => ?_)).symm + have hEk : ((Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin 2))).trans finFunctionFinEquiv) k + = finFunctionFinEquiv (fun i => k i.rev) := by + rw [Equiv.trans_apply] + congr 1 + rw [hEk, map_smul, ← PureState.congr_vec, quditPowTower_congr_quditBasis_apply] + simp only [Fin.rev_rev] + congr 1 + -- The scalar identity: the product of per-wire coefficients is the QFT's Fourier coefficient. + simp only [hc_def, ← Complex.exp_nat_mul] + rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin, + ← Complex.exp_sum] + congr 1 + · -- The `(1/√2)ⁿ⁺¹` normalisation is the register `1/√(2ⁿ⁺¹)` (`Concrete.sqrt_two_pow`). + rw [Concrete.invSqrt2, inv_pow, ← Complex.ofReal_pow, Nat.cast_pow, Nat.cast_ofNat, + (Concrete.sqrt_two_pow (n + 1)).symm] + · -- The wire phases sum to the Fourier phase `2π·J·K / 2ⁿ⁺¹` because the register index + -- `K = ∑ᵢ kᵢ 2^{i.rev}` expands over the wires. + congr 1 + have hK : (((finFunctionFinEquiv (fun i => k i.rev) : Fin (2 ^ (n + 1))) : ℕ) : ℂ) + = ∑ i, ((k i : ℕ) : ℂ) * 2 ^ (i.rev : ℕ) := by + rw [finFunctionFinEquiv_apply_val] + push_cast + exact Fintype.sum_equiv Fin.revPerm (fun l => ((k l.rev : ℕ) : ℂ) * 2 ^ (l : ℕ)) + (fun i => ((k i : ℕ) : ℂ) * 2 ^ (i.rev : ℕ)) (fun l => by simp [Fin.rev_rev]) + rw [hK, Finset.mul_sum, Finset.mul_sum, Finset.sum_div] + refine Finset.sum_congr rfl fun i _ => ?_ + simp only [qftTowerWirePhase] + push_cast + ring + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerProductRep.lean b/LeanPool/AxQM/Core/QftTowerProductRep.lean new file mode 100644 index 0000000000..f2d3ffa4df --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerProductRep.lean @@ -0,0 +1,210 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerControlQft +public import LeanPool.AxQM.Core.QftTowerBasis +public import LeanPool.AxQM.Postulates.API.QuditPhaseGradient + +/-! +# The product representation of the phase gradient (N&C Problem 5.1, eq. 5.4) + +Kitaev's QFT-over-`Z_p` circuit (Problem 5.1) loads a linear **phase gradient** onto the control +register and then reads it out with an inverse QFT (N&C Figure 5.2). The phase-loading stage +produces the standalone gradient `towerPhaseGrad θ n = ⊗_w |+_{2ᵂ·θ}⟩` on the pure control tower +`qtower n qubit` — a *product* over the `n+1` control wires, each a phased-plus state +(`AxQM/Core/QtowerControlQft.lean`). The readout is the inverse tower QFT `qftTowerInverseEvolution +n`, which lives on the *single* `2ⁿ⁺¹`-level register `qudit (2ⁿ⁺¹)` transported onto the tower +along the register bridge `quditPowTower n` (`AxQM/Core/QftRegisterBridge.lean`). + +This file proves the **product representation** identifying the wire-by-wire +product `towerPhaseGrad θ n` with the single-register phase gradient +`quditPhaseGrad θ (2ⁿ⁺¹) = (1/√2ⁿ⁺¹) ∑ₖ e^{iθk} |k⟩` (`AxQM/Postulates/API/QuditPhaseGradient.lean`) +transported through the bridge. This is exactly N&C's eq. (5.4): expanding each phased-plus factor +`|+_{2ᵂθ}⟩ = (|0⟩ + e^{i2ᵂθ}|1⟩)/√2` and multiplying out reconstitutes the single sum +`(1/√2ⁿ⁺¹) ∑ₖ e^{iθk} |k⟩`, because the wire bits `b` of the register index `k = ∑_w 2^{n-w} b_w` +turn the product of per-wire phases `∏_w e^{i2^{n-w}θ b_w}` into the single phase `e^{iθk}`. + +## What is formalised + +* `towerPhaseGrad_eq_congr_quditPhaseGrad` — the **product representation** (eq. 5.4): + `towerPhaseGrad θ n = Φₙ (quditPhaseGrad θ (2ⁿ⁺¹))` (`Φₙ = PureState.congr (quditPowTower n)`), + for every real slope `θ`. The per-wire product IS the single-register phase gradient, read + through the register bridge. Proved by matching inner products against the computational basis: + on the qudit side the amplitude is `⟨j|φ_θ⟩ = (1/√2ⁿ⁺¹)e^{iθj}` + (`quditPhaseGrad_inner_quditBasis`), and on the tower side the per-wire product amplitude is + `(1/√2)ⁿ⁺¹ e^{iθ·Σ_w 2^{n-w} b_w}`, + with the binary expansion `j = Σ_w 2^{n-w} b_w` making the two phases agree. +* `qftTowerInverseEvolution_evolvePure_towerPhaseGrad` — the **readout reduced through the bridge**: + `qftTowerInverseEvolution n (towerPhaseGrad θ n) + = Φₙ (qftInverseEvolution (2ⁿ⁺¹) (quditPhaseGrad θ (2ⁿ⁺¹)))`. The inverse tower QFT of the + phase gradient is the transport of the single-register inverse QFT applied to the single-register + phase gradient — the frequency estimate the circuit reads out. +* `qftTowerInverseEvolution_evolvePure_towerPhaseGrad_dyadic` — the **exact dyadic readout**: at a + *dyadic* slope `θ = 2πM/2ⁿ⁺¹` the phase gradient is exactly the Fourier image `F|M⟩`, so the + inverse QFT recovers `|M⟩` on the nose and the readout is the computational-basis estimate + `towerKet n (i ↦ (bits M) i.rev)` — a genuine basis ket. This is the sense in which the circuit + *performs the quantum Fourier transform*: for a frequency `M/2ⁿ⁺¹` with a finite `(n+1)`-bit + binary expansion the phase-estimation readout is exact. (For a prime dimension `p`, `ℓ/p` is + *never* dyadic, so the Problem 5.1 readout is only a finite-precision estimate — its accuracy is + analysed in [upstream `AxQM/NC/Ch5/Problem5_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_1.lean).) + +The single-wire amplitude `⟨c|+_ψ⟩` is the lemma `qubitPhasePlus_inner_qubitBasis` +(`AxQM/Postulates/API/PhasedPlus.lean`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The binary-expansion identity behind the product representation.** For `j : Fin (2ⁿ⁺¹)` with +little-endian bits `bits = finFunctionFinEquiv.symm j`, the big-endian weighted sum of the reversed +bits recovers `j`: `Σ_{i} 2^{n-i} · (bits j)(i.rev) = j`. Reindexing `i ↦ i.rev` sends the tower +weight `2^{n-i}` on wire `i.rev` to the register weight `2^i` on bit `i`, so the sum collapses to +the little-endian expansion `j = Σ_i (bits j)(i) · 2^i`. -/ +private theorem sum_two_pow_sub_rev_bits (n : ℕ) (j : Fin (2 ^ (n + 1))) : + ∑ i : Fin (n + 1), 2 ^ (n - (i : ℕ)) * (finFunctionFinEquiv.symm j i.rev : ℕ) + = (j : ℕ) := by + have hj : (j : ℕ) + = ∑ i : Fin (n + 1), (finFunctionFinEquiv.symm j i : ℕ) * 2 ^ (i : ℕ) := by + conv_lhs => rw [← Equiv.apply_symm_apply finFunctionFinEquiv j, finFunctionFinEquiv_apply] + rw [hj, ← Equiv.sum_comp (Fin.revPerm) + (fun i : Fin (n + 1) => 2 ^ (n - (i : ℕ)) * (finFunctionFinEquiv.symm j i.rev : ℕ))] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Fin.revPerm_apply, Fin.rev_rev, mul_comm] + congr 2 + have := i.isLt + rw [Fin.val_rev] + omega + +/-- **Product representation of the phase gradient (N&C Problem 5.1, eq. 5.4).** The wire-by-wire +product phase gradient `towerPhaseGrad θ n = ⊗_w |+_{2ᵂθ}⟩` on the pure control tower equals the +single-register phase gradient `quditPhaseGrad θ (2ⁿ⁺¹) = (1/√2ⁿ⁺¹) ∑ₖ e^{iθk} |k⟩` transported +onto the tower along the register bridge `quditPowTower n`: + +`towerPhaseGrad θ n = PureState.congr (quditPowTower n) (quditPhaseGrad θ (2ⁿ⁺¹))`. + +This is the identity that multiplying out the per-wire phased-plus factors reconstitutes the single +Fourier sum. Proved by comparing amplitudes against the computational basis: transporting to the +`qudit (2ⁿ⁺¹)` side, both `⟨j|·⟩` equal `(1/√2ⁿ⁺¹)e^{iθj}` — the qudit side directly +(`quditPhaseGrad_inner_quditBasis`), the tower as the product `(1/√2)ⁿ⁺¹ e^{iθ·Σ_w 2^{n-w} b_w}` +of per-wire amplitudes (a `TensorProduct.inner_tmul` induction over the wires), with the binary +expansion `Σ_w 2^{n-w} b_w = j` (`sum_two_pow_sub_rev_bits`) matching the two phases. -/ +theorem towerPhaseGrad_eq_congr_quditPhaseGrad (θ : ℝ) (n : ℕ) : + towerPhaseGrad θ n + = PureState.congr (quditPowTower n) (quditPhaseGrad θ (2 ^ (n + 1))) := by + -- Tower amplitude: the product of per-wire amplitudes over the `m+1` wires. The single-wire + -- amplitude `⟨c | +_ψ⟩ = (1/√2)·e^{iψc}` is `qubitPhasePlus_inner_qubitBasis`. + have tower : ∀ (m : ℕ) (b : Fin (m + 1) → Fin 2), + inner ℂ (towerKet m b).vec (towerPhaseGrad θ m).vec + = (Concrete.invSqrt2 : ℂ) ^ (m + 1) + * Complex.exp ((θ : ℂ) * Complex.I + * ((∑ i : Fin (m + 1), 2 ^ (m - (i : ℕ)) * (b i : ℕ) : ℕ) : ℕ)) := by + intro m + induction m with + | zero => + intro b + rw [towerKet_zero, towerPhaseGrad_zero, pow_zero, one_mul] + change @inner ℂ qubit.space _ _ _ = _ + rw [qubitPhasePlus_inner_qubitBasis] + have hs : (∑ i : Fin (0 + 1), 2 ^ (0 - (i : ℕ)) * (b i : ℕ)) = (b 0 : ℕ) := by simp + rw [hs, pow_succ, pow_zero, one_mul] + | succ m ih => + intro b + rw [towerKet_succ, towerPhaseGrad_succ, PureState.tmul_vec, PureState.tmul_vec] + change @inner ℂ (TensorProduct ℂ qubit.space (qtower m qubit).space) _ _ _ = _ + rw [TensorProduct.inner_tmul, qubitPhasePlus_inner_qubitBasis, ih (fun i => b i.succ), + mul_mul_mul_comm, ← pow_succ', ← Complex.exp_add] + -- Peel the leading wire off the big-endian phase sum (a ℕ identity). + have hE : (∑ i : Fin (m + 2), 2 ^ (m + 1 - (i : ℕ)) * (b i : ℕ)) + = 2 ^ (m + 1) * (b 0 : ℕ) + + ∑ i : Fin (m + 1), 2 ^ (m - (i : ℕ)) * ((fun i => b i.succ) i : ℕ) := by + rw [Fin.sum_univ_succ] + simp only [Fin.val_zero, Nat.sub_zero] + congr 1 + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Fin.val_succ] + congr 2 + omega + rw [hE] + congr 2 + push_cast + ring + -- ONB of the qudit register, identified with the computational basis states. + have hext : PureState.congr (quditPowTower n).symm (towerPhaseGrad θ n) + = quditPhaseGrad θ (2 ^ (n + 1)) := by + apply PureState.ext + set b : OrthonormalBasis (Fin (2 ^ (n + 1))) ℂ (qudit (2 ^ (n + 1))).space := + EuclideanSpace.basisFun (Fin (2 ^ (n + 1))) ℂ with hb_def + have hb : ∀ j, b j = (quditBasis j).vec := fun j => + (EuclideanSpace.basisFun_apply (Fin (2 ^ (n + 1))) ℂ j).trans (quditBasis_vec j).symm + -- The two vectors have equal coordinates in the ONB. + rw [← b.sum_repr' (PureState.congr (quditPowTower n).symm (towerPhaseGrad θ n)).vec, + ← b.sum_repr' (quditPhaseGrad θ (2 ^ (n + 1))).vec] + refine Finset.sum_congr rfl fun j _ => ?_ + -- Move the transport off the tower factor (`PureState.inner_congr_symm`). + rw [hb, PureState.inner_congr_symm (quditPowTower n) (quditBasis j) (towerPhaseGrad θ n), + quditPowTower_congr_quditBasis, tower, quditPhaseGrad_inner_quditBasis] + -- Normalisation `(1/√2)ⁿ⁺¹ = (√2ⁿ⁺¹)⁻¹` and phase `Σ_w 2^{n-w} b_w = j`. + have hnorm : (Concrete.invSqrt2 : ℂ) ^ (n + 1) + = (Real.sqrt ((2 ^ (n + 1) : ℕ) : ℝ) : ℂ)⁻¹ := by + rw [Concrete.invSqrt2, Concrete.sqrt_two_pow_inv]; norm_num + rw [hnorm, sum_two_pow_sub_rev_bits] + rw [← hext, PureState.congr_congr_symm] + +/-- **The inverse-QFT readout of the phase gradient, reduced through the register bridge.** The +inverse tower QFT `qftTowerInverseEvolution n` applied to the phase gradient `towerPhaseGrad θ n` +is the transport (along the bridge `quditPowTower n`) of the single-register inverse QFT +`qftInverseEvolution (2ⁿ⁺¹)` on the single-register phase gradient `quditPhaseGrad θ (2ⁿ⁺¹)`: + +`qftTowerInverseEvolution n (towerPhaseGrad θ n) + = PureState.congr (quditPowTower n) (qftInverseEvolution (2ⁿ⁺¹) (quditPhaseGrad θ (2ⁿ⁺¹)))`. + +Immediate from the product representation `towerPhaseGrad_eq_congr_quditPhaseGrad` and the fact that +`qftTowerInverseEvolution n = Evolution.congr (quditPowTower n) (qftInverseEvolution (2ⁿ⁺¹))` is the +transported inverse QFT (`Evolution.congr_evolvePure_congr`). This is the frequency estimate the +circuit's readout stage produces. -/ +theorem qftTowerInverseEvolution_evolvePure_towerPhaseGrad (θ : ℝ) (n : ℕ) : + (qftTowerInverseEvolution n).evolvePure (towerPhaseGrad θ n) + = PureState.congr (quditPowTower n) + ((qftInverseEvolution (2 ^ (n + 1))).evolvePure (quditPhaseGrad θ (2 ^ (n + 1)))) := by + rw [towerPhaseGrad_eq_congr_quditPhaseGrad, qftTowerInverseEvolution, + Evolution.congr_evolvePure_congr] + +/-- **The exact dyadic readout: the circuit performs the QFT for dyadic frequencies.** At a +*dyadic* slope `θ = 2πM/2ⁿ⁺¹` (an integer `M : Fin (2ⁿ⁺¹)`), the phase gradient +`towerPhaseGrad (2πM/2ⁿ⁺¹) n` is exactly the Fourier image `F|M⟩ = qftFourierImage (2ⁿ⁺¹) M`, so the +inverse tower QFT recovers the computational-basis frequency estimate exactly: + +`qftTowerInverseEvolution n (towerPhaseGrad (2πM/2ⁿ⁺¹) n) = towerKet n (i ↦ (bits M) i.rev)`, + +a genuine basis ket (`bits M = finFunctionFinEquiv.symm M`, the binary digits of `M`, big-endian +reversed by `Fin.rev`). This is precisely "the circuit performs the quantum Fourier transform": +when the frequency `M/2ⁿ⁺¹` has an exact `(n+1)`-bit binary expansion, phase estimation reads it out +on the nose. Proved from the reduced readout `qftTowerInverseEvolution_evolvePure_towerPhaseGrad`, +the dyadic identity `quditPhaseGrad (2πM/2ⁿ⁺¹) (2ⁿ⁺¹) = F|M⟩` (`quditPhaseGrad_eq_qftFourierImage`), +the QFT round-trip `F⁻¹F|M⟩ = |M⟩` (`Evolution.evolvePure_adjoint_evolvePure`), and the bridge +dictionary `Φₙ|M⟩ = towerKet n (bits M rev)` (`quditPowTower_congr_quditBasis`). For a *prime* +dimension `p`, `ℓ/p` is never dyadic, so the Problem 5.1 readout is only a finite-precision +estimate. -/ +theorem qftTowerInverseEvolution_evolvePure_towerPhaseGrad_dyadic (n : ℕ) + (M : Fin (2 ^ (n + 1))) : + (qftTowerInverseEvolution n).evolvePure + (towerPhaseGrad (2 * Real.pi * (M : ℕ) / (2 ^ (n + 1) : ℕ)) n) + = towerKet n (fun i => finFunctionFinEquiv.symm M i.rev) := by + rw [qftTowerInverseEvolution_evolvePure_towerPhaseGrad, + ← quditPhaseGrad_eq_qftFourierImage, ← qftEvolution_evolvePure_quditBasis, + ← qftInverseEvolution_adjoint (2 ^ (n + 1)), + Evolution.evolvePure_adjoint_evolvePure', quditPowTower_congr_quditBasis] + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerRecursion.lean b/LeanPool/AxQM/Core/QftTowerRecursion.lean new file mode 100644 index 0000000000..27e136963c --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerRecursion.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerHadamard + +/-! +# The base case of the measured-QFT tower induction (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) is assembled by an induction on the tower +depth: the head control wire's Figure 5.1 gates (a Hadamard and the controlled-`Rₖ` cascade it +drives) are peeled off `qftTowerEvolution (n+1)`, its measurement deferred past the cascade +(`qtowerHeadPhaseCascade_measure_*`), and the tail recursion re-enters +`qftTowerEvolution n` on the remaining wires. Every induction needs a base case, and this file +supplies it: at depth `0` the tower QFT is a single one-qubit Hadamard — already a one-wire gate +with nothing to defer. + +## What is formalised + +* `qftEvolution_two_eq_qftHadamardEvolution` — **the quantum Fourier transform on one qubit is the + Hadamard gate** (Nielsen & Chuang §5.1: the `2 × 2` DFT is `H`). The register QFT + `qftEvolution 2` on `qudit 2` equals the Figure 5.1 Hadamard gate `qftHadamardEvolution 1 0` on + the single wire — both have operator `Matrix.toEuclideanCLM` of the same matrix, since + `qftMatrix 2 = singleQubitOnWire finFunctionFinEquiv 0 hadamardC` (each is `hadamardC`). +* `qftTowerEvolution_zero` — **the tower QFT at depth `0` is the single-wire Hadamard**, + `qftTowerEvolution 0 = hadamardGate`. The transported QFT `qftTowerEvolution 0` on the one-wire + tower `qtower 0 qubit = qubit` is, through the register bridge, the Figure 5.1 Hadamard placed on + the sole wire — which on a one-wire tower is just `hadamardGate`. This is the base case of the + outer tower induction: a genuine one-qubit gate, no two-wire gate, so the measured-QFT reduction + holds trivially at `n = 0`. + +## Proof + +`qftEvolution_two_eq_qftHadamardEvolution` reduces via `Evolution.ext` to the matrix identity +`qftMatrix 2 = singleQubitOnWire finFunctionFinEquiv 0 hadamardC`, split through `hadamardC`: the +QFT matrix `qftMatrix 2` is `hadamardC` because `qftPrimitiveRoot 2 = e^{πi} = -1`, so its entry +`(1/√2)·(qftPrimitiveRoot 2)^{jk}` is `(1/√2)·(-1)^{jk} = hadamardC k j`; and `singleQubitOnWire` +of a one-wire register is the block itself, its wire-locality guard on `Fin 1` being vacuous and +its bit read `finFunctionFinEquiv.symm i 0 = i`. `qftTowerEvolution_zero` then rewrites the QFT on +the tower through this identity and the Hadamard re-expression +`quditPowTower_congr_qftHadamardEvolution`, whose depth-`0` value +`Evolution.qtowerSingleWire 0 _ hadamardGate` is `hadamardGate` by the base case of +`Evolution.qtowerSingleWire`. + +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM + +open Concrete + +/-- **The quantum Fourier transform on one qubit is the Hadamard gate** (Nielsen & Chuang §5.1: the +`2 × 2` discrete Fourier transform `F₂` is the Hadamard `H`). The register QFT `qftEvolution 2` on +the two-level register `qudit 2` equals the Figure 5.1 Hadamard gate `qftHadamardEvolution 1 0` — +the single-wire Hadamard on the one-qubit register. Both operators are `Matrix.toEuclideanCLM` of +the same `2 × 2` matrix `hadamardC`: the QFT kernel `(1/√2)·(qftPrimitiveRoot 2)^{jk}` is +`(1/√2)·(-1)^{jk}` since `qftPrimitiveRoot 2 = e^{πi} = -1`, and `singleQubitOnWire` on a one-wire +register is its block. This is the depth-`0` fact the tower QFT base case `qftTowerEvolution_zero` +rewrites through. -/ +theorem qftEvolution_two_eq_qftHadamardEvolution : + qftEvolution 2 = qftHadamardEvolution 1 0 := by + have hroot : qftPrimitiveRoot 2 = -1 := by + rw [qftPrimitiveRoot, + show (2 * (Real.pi : ℂ) * Complex.I / (2 : ℕ)) = (Real.pi : ℂ) * Complex.I by push_cast; ring, + Complex.exp_pi_mul_I] + have hqft : qftMatrix 2 = hadamardC := by + ext k j + rw [qftMatrix, hroot, hadamardC_apply] + push_cast + rw [mul_comm (k : ℕ) (j : ℕ)] + have hsymm : ∀ i : Fin 2, finFunctionFinEquiv.symm i (0 : Fin 1) = i := by + intro i + apply Fin.ext + rw [finFunctionFinEquiv_symm_apply_val] + simp [Nat.mod_eq_of_lt i.isLt] + have hwire : singleQubitOnWire finFunctionFinEquiv (0 : Fin 1) hadamardC = hadamardC := by + ext i i' + rw [singleQubitOnWire_apply, ite_eq_left (fun x hx => absurd (Fin.fin_one_eq_zero x) hx), + hsymm i, hsymm i'] + apply Evolution.ext + rw [qftEvolution_op, qftHadamardEvolution, quditGate_op, hqft, hwire] + +/-- **The tower QFT at depth `0` is the single-wire Hadamard**: +`qftTowerEvolution 0 = hadamardGate`. +The quantum Fourier transform transported onto the one-wire control tower `qtower 0 qubit = qubit` +(through the register bridge `quditPowTower 0`) is a single one-qubit Hadamard — the QFT on one +qubit (`qftEvolution_two_eq_qftHadamardEvolution`) re-expressed on the tower as the Hadamard on the +sole wire (`quditPowTower_congr_qftHadamardEvolution`), which on a one-wire tower is `hadamardGate` +itself (`Evolution.qtowerSingleWire 0 _ g = g`). This is the base case of the outer tower induction +assembling the measured-QFT reduction (Problem 5.2): at `n = 0` the whole circuit is already a +genuine one-qubit gate on the single measured wire, with no two-wire gate to defer. -/ +theorem qftTowerEvolution_zero : qftTowerEvolution 0 = hadamardGate := by + have h : qftTowerEvolution 0 = Evolution.congr (quditPowTower 0) (qftHadamardEvolution 1 0) := by + rw [qftTowerEvolution]; congr 1; exact qftEvolution_two_eq_qftHadamardEvolution + rw [h, quditPowTower_congr_qftHadamardEvolution] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Core/QftTowerSwap.lean b/LeanPool/AxQM/Core/QftTowerSwap.lean new file mode 100644 index 0000000000..90ac6ba297 --- /dev/null +++ b/LeanPool/AxQM/Core/QftTowerSwap.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftSwapEvolution +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.QtowerWirePermutation + +/-! +# The QFT swap layer re-expressed as a wire-permutation gate on the tower (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a product of *transported* Figure 5.1 gates +(`qftTowerEvolution_eq_map_congr_prod`). To defer the final per-wire measurement +past that product gate by gate, each transported gate must be re-expressed as an honest +**wire-addressed tower `Evolution`**. This file does so for the **swap (wire-reversal) layer**, the +first of the circuit's three gate shapes (the Hadamards and the controlled-`Rₖ` rotations are in +`AxQM/Core/QftTowerHadamard.lean` and `AxQM/Core/QftTowerControlled.lean`). + +## What is formalised + +* `quditPowTower_congr_qftSwapEvolution` — **the transported swap layer is the tower wire-reversal + permutation.** Transporting the register swap `qftSwapEvolution (n+1)` + (`AxQM/Postulates/API/QftSwapEvolution.lean`) onto the tower through the register bridge + `quditPowTower n` equals the wire-permutation gate `Evolution.qtowerPermWires Fin.revPerm` that + reverses the tower's `n+1` wires: + + `Evolution.congr (quditPowTower n) (qftSwapEvolution (n+1))` + `= Evolution.qtowerPermWires Fin.revPerm`. + + So the QFT circuit's swap — a *relabelling* of the wires, not a two-wire entangling gate — is, + on the grounded control tower, precisely the wire reversal `Fin.rev`, and it never touches two + wires. It is thus already in the form the deferred-measurement reduction wants: a permutation of + the measured wires. + +## Proof + +Via the transported-gate re-expression combinator `quditPowTower_congr_eq_of_evolvePure_towerKet`: +it suffices to check, for every bit-string `b`, that +`qtowerPermWires Fin.revPerm` sends `towerKet n b` to the transport of the register swap's action on +`|finFunctionFinEquiv (b ∘ Fin.rev)⟩`. Both sides compute to `towerKet n (b ∘ Fin.rev)`: + +* the left side by `qtowerPermWires_evolvePure_towerKet` (`qtowerPermWires σ` sends `towerKet n b` + to `towerKet n (b ∘ σ⁻¹)`, and `Fin.revPerm⁻¹ = Fin.rev`); +* the right side because the register swap reverses the wire labels of the ket + (`qftSwapEvolution_evolvePure_quditBasis`), turning `b ∘ Fin.rev` into `b ∘ Fin.rev ∘ Fin.rev = b` + by `Fin.rev_rev`, and the register bridge then reads `|finFunctionFinEquiv b⟩` as + `towerKet n (b ∘ Fin.rev)` (`quditPowTower_congr_quditBasis_apply`). + +The `Fin.rev` reconciles the big-endian register bridge with the little-endian wire-indexing of the +Figure 5.1 matrix gates; that a *register* wire-reversal transports to a *tower* wire-reversal is +the content. + +The swap gate `qftSwapEvolution` and its basis action are in +`AxQM/Postulates/API/QftSwapEvolution.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The transported QFT swap layer is the tower wire-reversal permutation.** Transporting the +Figure 5.1 swap (wire-reversal) gate `qftSwapEvolution (n+1)` from the `2ⁿ⁺¹`-level register onto +the `(n+1)`-qubit control tower via the register bridge `quditPowTower n` yields exactly the +wire-permutation gate reversing the tower's wires, + + `Evolution.congr (quditPowTower n) (qftSwapEvolution (n+1))` + `= Evolution.qtowerPermWires Fin.revPerm`. + +This re-expresses the QFT circuit's swap layer as an honest wire-addressed tower gate — a bare +*relabelling* of the `n+1` wires, touching no two wires at once — the first of the three Figure 5.1 +gate shapes the whole-circuit measured-QFT reduction (Problem 5.2) defers the final measurement +past. Proved through the transported-gate re-expression combinator +`quditPowTower_congr_eq_of_evolvePure_towerKet`: both the tower permutation +(`qtowerPermWires_evolvePure_towerKet`, `Fin.revPerm⁻¹ = Fin.rev`) and the transported register swap +(`qftSwapEvolution_evolvePure_quditBasis` reversing the wire labels, then the register bridge +`quditPowTower_congr_quditBasis_apply`) send `towerKet n b` to `towerKet n (b ∘ Fin.rev)`, the two +`Fin.rev`s collapsing by `Fin.rev_rev`. -/ +theorem quditPowTower_congr_qftSwapEvolution (n : ℕ) : + Evolution.congr (quditPowTower n) (qftSwapEvolution (n + 1)) + = Evolution.qtowerPermWires Fin.revPerm := by + apply quditPowTower_congr_eq_of_evolvePure_towerKet + intro b + rw [qtowerPermWires_evolvePure_towerKet, qftSwapEvolution_evolvePure_quditBasis, + quditPowTower_congr_quditBasis_apply] + simp only [Fin.rev_rev, Fin.revPerm_symm, Fin.revPerm_apply] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerComposeRight.lean b/LeanPool/AxQM/Core/QtowerComposeRight.lean new file mode 100644 index 0000000000..29d86661aa --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerComposeRight.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledTowerAction +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.SystemIsoComm + +/-! +# Factoring an idle module out of a control tower (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The faithful `n+1`-wire circuit is the +Barenco unfolding `barencoNCircuit` (`cnx_eq_barencoNCircuit`), whose distinctive content is +bottoming its internal multiply-controlled `NOT` blocks `Cᵏ(X)` to genuine `Toffoli`s. +Each such block is `mcCtrl k (pauliXGate.onLeft M)` acting on the +control tower `qtower k (qubit ⊗ M)` — `k` outer control qubits, the `X`-target the head of the +inner `qubit ⊗ M`, and an **idle target-module `M`** (the wires the block does not touch). Its +reduction is described from opposite ends but on **different registers**: + +* `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower` reads the block's computational-basis action on + the tower `qtower k (qubit ⊗ M)`, with the idle `M` carried along as a right factor of the base + state; +* `tensorPowMcCtrlX_onBlock_eq_toffoliCircuit` exhibits the bounded `O(k²)` `Toffoli` circuit, but + on the **flattened symmetric register** `qubit ^⊗ₛ (k+1+b)`. + +Matching the two needs a structural bridge that separates the idle module from the tower. This file +constructs its first step: pulling the idle right factor `M` out of the tower's inner system, +`qtower k (S ⊗ M) ≃ₛ (qtower k S) ⊗ M`. (Composed with the `qtower ↔ tensor-power` bridge +`qtowerQubitTensorPow` on the `(qtower k S)` factor and the block split `tensorPowAdd`, this +reaches the flattened register `qubit ^⊗ₛ (k+1) ⊗ (qubit ^⊗ₛ b) ≃ₛ qubit ^⊗ₛ (k+1+b)` of +`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`.) + +## What is formalised + +* `qtowerComposeRight k` — the **module-factoring bridge** `qtower k (S ⊗ M) ≃ₛ (qtower k S) ⊗ M`. + Both sides prepend the same `k` control qubits; on the left the idle module `M` sits *inside* the + tower (`qubitᵏ ⊗ (S ⊗ M)`), on the right it is pulled *out* to a trailing factor + (`(qubitᵏ ⊗ S) ⊗ M`) — the same register up to reassociation. Built by induction on `k`: the base + `qtower 0 (S ⊗ M) = S ⊗ M = (qtower 0 S) ⊗ M` is the identity, and each step tensors the identity + on the peeled head control with the tail bridge and reassociates the new control past the module + through the associator `QSystem.assoc`. +* `qtowerComposeRight_congr_ctrlTower` — the **basis dictionary**: the bridge carries a + control-tower input whose base is a product `ρ ⊗ φ` (an inner state `ρ : PureState S` and an idle + module state `φ : PureState M`) to the control tower over `ρ` alone, tensored with the untouched + `φ`: + `qtowerComposeRight k (ctrlTower k c (ρ ⊗ φ)) = (ctrlTower k c ρ) ⊗ φ`. + With `S = qubit` and `ρ = |i⟩` this is exactly the flattening of a `barencoNCircuit`-block input + `ctrlTower k c (|i⟩ ⊗ φ)` (`mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower`) into a control tower + over the target qubit with the idle module split off — the form on which the block's `Toffoli` + reduction is read. +* `qtowerComposeRight_symm_congr_tmul` — the **backward** dictionary, the `.symm` companion (via the + `PureState.congr` roundtrip `PureState.congr_symm_congr`): the inverse bridge folds a flattened + input `(ctrlTower k c ρ) ⊗ φ` back to the tower input `ctrlTower k c (ρ ⊗ φ)` — the direction + used when a gate computed on the flattened register is transported back onto the block's tower. + +## Design notes + +* **Why general in `S`.** The controls prepended by `ctrlTower`/`qtower` are qubits regardless of + the inner system, so nothing in the construction uses `S = qubit`; keeping `S` and `M` arbitrary + makes the bridge reusable (the block reduction instantiates `S = qubit`, `ρ = qubitBasis i`). +* **Why the recursion matches definitionally.** `qtower (k+1) X = qubit ⊗ qtower k X` + *definitionally* (peeling the outer control is the defining equation of `qtower` on its `ℕ` + argument, the same reduction `mcCtrl_succ` uses), so both the + successor isomorphism `((Iso.refl qubit).tmul (bridge k)).trans (assoc …)` (of domain + `qubit ⊗ qtower k (S ⊗ M)`) and its codomain `(qubit ⊗ qtower k S) ⊗ M` type-check against the + expected `qtower (k+1) (S ⊗ M) ≃ₛ (qtower (k+1) S) ⊗ M` with no `cast`. +* **Proof of the dictionary.** By `PureState.ext` it reduces to an equation of state vectors, + proved by induction: the step peels the head control with `PureState.tmul_vec`, applies + `QSystem.Iso.tmul_toIsometry_tmul` and the inductive hypothesis to the tail, then re-brackets the + head control past the module with `QSystem.assoc_toIsometry_tmul_tmul`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S M : QSystem} + +/-- **The module-factoring bridge** `qtower k (S ⊗ M) ≃ₛ (qtower k S) ⊗ M`: the system isomorphism +that pulls the idle right factor `M` out of a control tower's inner system, from *inside* the tower +(`qubitᵏ ⊗ (S ⊗ M)`) to a trailing factor (`(qubitᵏ ⊗ S) ⊗ M`). Built by induction on `k` — the +base `qtower 0 (S ⊗ M) = S ⊗ M = (qtower 0 S) ⊗ M` is the identity, and each step tensors the +identity on the peeled head control with the tail bridge and reassociates the new control past the +module through `QSystem.assoc`. Its basis action is `qtowerComposeRight_congr_ctrlTower`. -/ +def qtowerComposeRight : (k : ℕ) → (qtower k (S ⊗ M)).Iso ((qtower k S) ⊗ M) + | 0 => QSystem.Iso.refl (S ⊗ M) + | k + 1 => + ((QSystem.Iso.refl qubit).tmul (qtowerComposeRight k)).trans + (QSystem.assoc qubit (qtower k S) M) + +/-- Base unfolding of the bridge: with no controls the tower is its inner system, so factoring the +module out is the identity. -/ +@[simp] theorem qtowerComposeRight_zero : + qtowerComposeRight (S := S) (M := M) 0 = QSystem.Iso.refl (S ⊗ M) := rfl + +/-- Step unfolding of the bridge: tensor the identity on the peeled head control with the tail +bridge, then reassociate the new control past the module through `QSystem.assoc`. -/ +theorem qtowerComposeRight_succ (k : ℕ) : + qtowerComposeRight (S := S) (M := M) (k + 1) + = ((QSystem.Iso.refl qubit).tmul (qtowerComposeRight k)).trans + (QSystem.assoc qubit (qtower k S) M) := rfl + +/-- **Basis dictionary for the module-factoring bridge.** The bridge +`qtower k (S ⊗ M) ≃ₛ (qtower k S) ⊗ M` carries a control-tower input whose base is a product state +`ρ ⊗ φ` — an inner state `ρ : PureState S` tensored with an idle module state `φ : PureState M` — to +the control tower over `ρ` alone, tensored with the untouched `φ`: + +`qtowerComposeRight k (ctrlTower k c (ρ ⊗ φ)) = (ctrlTower k c ρ) ⊗ φ`. + +Instantiated at `S = qubit`, `ρ = |i⟩` this flattens a `barencoNCircuit`-block input +`ctrlTower k c (|i⟩ ⊗ φ)` (the states of `mcCtrl_pauliXGate_onLeft_evolvePure_ctrlTower`) into +a control tower over the target qubit with the idle module `φ` split off as a trailing factor — the +form on which the block's bounded `Toffoli` circuit +(`tensorPowMcCtrlX_onBlock_eq_toffoliCircuit`, on the flattened register) is matched. Proved by +`PureState.ext` and induction on `k` on state vectors: peel the head control +(`PureState.tmul_vec`), push the tail through the +inductive hypothesis (`QSystem.Iso.tmul_toIsometry_tmul`), and re-bracket the head control past the +module (`QSystem.assoc_toIsometry_tmul_tmul`). -/ +theorem qtowerComposeRight_congr_ctrlTower (k : ℕ) (c : Fin k → Fin 2) (ρ : PureState S) + (φ : PureState M) : + PureState.congr (qtowerComposeRight k) (ctrlTower k c (ρ.tmul φ)) + = (ctrlTower k c ρ).tmul φ := by + suffices key : ∀ (m : ℕ) (d : Fin m → Fin 2), + (qtowerComposeRight m).toIsometry (ctrlTower m d (ρ.tmul φ)).vec + = (ctrlTower m d ρ).vec ⊗ₜ[ℂ] φ.vec by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec] + exact key k c + intro m + induction m with + | zero => + intro d + -- `qtowerComposeRight 0 = Iso.refl (S ⊗ M)` (identity isometry) and `ctrlTower 0 d ψ = ψ`. + rw [qtowerComposeRight_zero, ctrlTower_zero, ctrlTower_zero, PureState.tmul_vec] + rfl + | succ k ih => + intro d + -- `qtowerComposeRight (k+1)` is definitionally + -- `((refl qubit).tmul (bridge k)).trans (assoc qubit (qtower k S) M)`; apply its two isometry + -- factors in turn (`qtower (k+1) X = qubit ⊗ qtower k X` definitionally, so a `change` peels + -- the head-control isometry chain into its two `QSystem.Iso` factors with no `cast`). + rw [ctrlTower_succ, PureState.tmul_vec] + change (QSystem.assoc qubit (qtower k S) M).toIsometry + (((QSystem.Iso.refl qubit).tmul (qtowerComposeRight k)).toIsometry + ((qubitBasis (d 0)).vec ⊗ₜ[ℂ] (ctrlTower k (fun i => d i.succ) (ρ.tmul φ)).vec)) + = (ctrlTower (k + 1) d ρ).vec ⊗ₜ[ℂ] φ.vec + rw [QSystem.Iso.tmul_toIsometry_tmul, ih (fun i => d i.succ), assoc_toIsometry_tmul_tmul, + ctrlTower_succ, PureState.tmul_vec] + -- The residual `(Iso.refl qubit).toIsometry` on the head control is the identity isometry. + rfl + +/-- **Backward basis dictionary for the module-factoring bridge.** The *inverse* bridge +`(qtowerComposeRight k).symm` folds a flattened control-tower input `(ctrlTower k c ρ) ⊗ φ` — a +control tower over an inner state `ρ : PureState S` with a trailing idle module state +`φ : PureState M` — back into the tower input `ctrlTower k c (ρ ⊗ φ)` on `qtower k (S ⊗ M)`. The +`.symm` companion of `qtowerComposeRight_congr_ctrlTower`, obtained from it by the `PureState.congr` +roundtrip cancellation `PureState.congr_symm_congr`. This is the direction consumed when a gate +computed on the flattened register is transported back onto the block's tower. -/ +theorem qtowerComposeRight_symm_congr_tmul (k : ℕ) (c : Fin k → Fin 2) (ρ : PureState S) + (φ : PureState M) : + PureState.congr (qtowerComposeRight k).symm ((ctrlTower k c ρ).tmul φ) + = ctrlTower k c (ρ.tmul φ) := by + rw [← qtowerComposeRight_congr_ctrlTower k c ρ φ, PureState.congr_symm_congr] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerControlQft.lean b/LeanPool/AxQM/Core/QtowerControlQft.lean new file mode 100644 index 0000000000..76eb87d961 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerControlQft.lean @@ -0,0 +1,260 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerCircuit +public import LeanPool.AxQM.Core.QtowerPhaseGradient +public import LeanPool.AxQM.Core.QtowerComposeRight +public import LeanPool.AxQM.Postulates.API.InverseQuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary + +/-! +# The inverse-QFT readout on the control register (N&C §5.2, Figure 5.2, last stage) + +The final stage of the phase-estimation circuit (N&C Figure 5.2) applies the **inverse quantum +Fourier transform to the `t`-qubit control register**, leaving the target register alone. Run on the +phase-gradient superposition `⊗_w |+_{2^w·θ}⟩ ⊗ |u⟩` produced by the controlled powers +(`AxQM/Core/QtowerPhaseGradient.lean`), it reads the eigenphase `θ/2π` back into the control +register. + +The obstacle this file removes is **structural**. The phase-estimation stages live on the nested +control register `qtower t S` (`t` control qubits wrapping the target `S`), whereas the tower +quantum Fourier transform `qftTowerEvolution` (`AxQM/Core/QftRegisterBridge.lean`) lives on the +*pure* qubit tower `qtower n qubit` — it has no room for a separate target. Applying it to the +control register requires first **separating the control qubits from the target**, +`qtower (n+1) S ≃ₛ (qtower n qubit) ⊗ S` +(the two registers are the same up to reassociation, but *not* definitionally — the `qtower` +recursion peels a different number of wires on each side). This file supplies that split, transports +the phase gradient across it, and assembles the inverse-QFT readout gate. + +## What is formalised + +* `qtowerSplitControl n S` — the **control–target split** `qtower (n+1) S ≃ₛ (qtower n qubit) ⊗ S`: + it pulls the target `S` out from the bottom of the `(n+1)`-control register to a trailing factor, + gathering the `n+1` control qubits into the pure tower `qtower n qubit`. Built by induction on `n` + through the associator `QSystem.assoc`, exactly as the sibling module-factoring bridge + `qtowerComposeRight` (this is its specialisation reorganised so the split qubit lands *inside* the + control tower rather than in the base). +* `towerPhaseGrad θ n` — the **standalone phase gradient** `⊗_w |+_{2^w·θ}⟩` on the pure control + tower `qtower n qubit` (all `n+1` wires phased-plus, no target): the control-register content of + the phase gradient once the target is stripped off. +* `qtowerSplitControl_congr_qtowerPhaseGrad` — the **phase-gradient dictionary**: the split carries + the nested phase gradient to the standalone one tensored with the untouched target, + `qtowerSplitControl n S (qtowerPhaseGrad θ (n+1) u) = (towerPhaseGrad θ n) ⊗ u`; + `qtowerSplitControl_congr_qtowerKet` is its computational-basis analogue + (`qtowerKet (n+1) b u ↦ (towerKet n b) ⊗ u`). +* `qftTowerInverseEvolution n` — the **inverse tower QFT** `Evolution.congr (quditPowTower n) + (qftInverseEvolution (2^{n+1}))` on `qtower n qubit`, the register-tower transport of the inverse + QFT (Ex 5.5); `qftTowerInverseEvolution_evolvePure_towerKet` reads its action on a basis ket. +* `qtowerControlInverseQft n S` — the **inverse-QFT readout gate** on the phase-estimation register + `qtower (n+1) S`: the inverse tower QFT applied to the control qubits (through the split), the + identity on the target `S`. This is Figure 5.2's final box. +* `qtowerControlInverseQft_evolvePure_qtowerPhaseGrad` — the **readout action**: the gate carries + the phase gradient to `qftTowerInverseEvolution n (towerPhaseGrad θ n) ⊗ u` (through the split), + reducing the readout of the *nested* phase estimation to the inverse tower QFT of the *standalone* + control gradient, with the target `u` untouched. That the standalone image is the + computational-basis estimate `|m⟩` (the product representation, eq. 5.4, exact for a dyadic + `θ = 2πm/2^{n+1}`) is proved in `AxQM/Core/QftTowerProductRep.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The control–target split of the phase-estimation register -/ + +/-- **The control–target split** `qtower (n+1) S ≃ₛ (qtower n qubit) ⊗ S`: separate the `n+1` +control qubits (gathered into the pure tower `qtower n qubit`) from the target `S`, pulled out to a +trailing factor. Built by induction on `n`: the base `qtower 1 S = qubit ⊗ S = (qtower 0 qubit) ⊗ S` +is the identity, and each step tensors the identity on the peeled head control with the tail split +and reassociates the new control past the target through `QSystem.assoc`. Its action on the +phase-estimation states is `qtowerSplitControl_congr_qtowerPhaseGrad` / +`qtowerSplitControl_congr_qtowerKet`. -/ +def qtowerSplitControl : (n : ℕ) → (S : QSystem) → (qtower (n + 1) S).Iso ((qtower n qubit) ⊗ S) + | 0, S => QSystem.Iso.refl (qubit ⊗ S) + | (n + 1), S => + ((QSystem.Iso.refl qubit).tmul (qtowerSplitControl n S)).trans + (QSystem.assoc qubit (qtower n qubit) S) + +/-- Base unfolding of the control–target split: with a single control qubit the register is already +`qubit ⊗ S`, so the split is the identity. -/ +@[simp] theorem qtowerSplitControl_zero (S : QSystem) : + qtowerSplitControl 0 S = QSystem.Iso.refl (qubit ⊗ S) := rfl + +/-- Step unfolding of the control–target split: tensor the identity on the peeled head control with +the tail split, then reassociate the new control past the target through `QSystem.assoc`. -/ +theorem qtowerSplitControl_succ (n : ℕ) (S : QSystem) : + qtowerSplitControl (n + 1) S + = ((QSystem.Iso.refl qubit).tmul (qtowerSplitControl n S)).trans + (QSystem.assoc qubit (qtower n qubit) S) := rfl + +/-! ### The standalone phase gradient on the pure control tower -/ + +/-- **The standalone phase gradient** `⊗_w |+_{2^w·θ}⟩` on the pure control tower `qtower n qubit`: +all `n+1` wires in the phased-plus state, the outermost (most significant) wire carrying weight +`2^n`, the innermost weight `2^0`. This is the control-register content of the phase gradient +`qtowerPhaseGrad θ (n+1) u` once the target `u` is stripped off +(`qtowerSplitControl_congr_qtowerPhaseGrad`). -/ +def towerPhaseGrad (θ : ℝ) : (n : ℕ) → PureState (qtower n qubit) + | 0 => qubitPhasePlus ((2 : ℝ) ^ 0 * θ) + | (n + 1) => qubitPhasePlus ((2 : ℝ) ^ (n + 1) * θ) ⊗ towerPhaseGrad θ n + +/-- Base unfolding of the standalone phase gradient: a single wire carries the phase `2^0·θ`. -/ +@[simp] theorem towerPhaseGrad_zero (θ : ℝ) : + towerPhaseGrad θ 0 = qubitPhasePlus ((2 : ℝ) ^ 0 * θ) := rfl + +/-- Step unfolding of the standalone phase gradient: peel the outermost (most significant) wire +`|+_{2^{n+1}·θ}⟩`. -/ +theorem towerPhaseGrad_succ (θ : ℝ) (n : ℕ) : + towerPhaseGrad θ (n + 1) + = qubitPhasePlus ((2 : ℝ) ^ (n + 1) * θ) ⊗ towerPhaseGrad θ n := rfl + +/-! ### The split carries the phase-estimation states to control ⊗ target -/ + +/-- **Phase-gradient dictionary for the control–target split.** The split +`qtower (n+1) S ≃ₛ (qtower n qubit) ⊗ S` carries the nested phase gradient +`qtowerPhaseGrad θ (n+1) u` (the `n+1` phased-plus control wires wrapping the target `u`) to the +standalone phase gradient `towerPhaseGrad θ n` on the pure control tower, tensored with the +untouched target `u`: + +`qtowerSplitControl n S (qtowerPhaseGrad θ (n+1) u) = (towerPhaseGrad θ n) ⊗ u`. + +Proved by `PureState.ext` and induction on `n` on state vectors: the step peels the outermost +phased-plus wire (`qtowerPhaseGrad_succ`, `PureState.tmul_vec`), pushes the tail through the split +by the inductive hypothesis (`QSystem.Iso.tmul_toIsometry_tmul`), and reassociates the head wire +past the target through the associator (`assoc_toIsometry_tmul_tmul`). -/ +theorem qtowerSplitControl_congr_qtowerPhaseGrad (θ : ℝ) (n : ℕ) (u : PureState S) : + PureState.congr (qtowerSplitControl n S) (qtowerPhaseGrad θ (n + 1) u) + = (towerPhaseGrad θ n).tmul u := by + suffices key : ∀ (m : ℕ) (v : PureState S), + (qtowerSplitControl m S).toIsometry (qtowerPhaseGrad θ (m + 1) v).vec + = (towerPhaseGrad θ m).vec ⊗ₜ[ℂ] v.vec by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec] + exact key n u + intro m + induction m with + | zero => + intro v + erw [qtowerSplitControl_zero, qtowerPhaseGrad_succ, qtowerPhaseGrad_zero, towerPhaseGrad_zero, + PureState.tmul_vec] + rfl + | succ k ih => + intro v + rw [qtowerPhaseGrad_succ, PureState.tmul_vec] + change (QSystem.assoc qubit (qtower k qubit) S).toIsometry + (((QSystem.Iso.refl qubit).tmul (qtowerSplitControl k S)).toIsometry + ((qubitPhasePlus ((2 : ℝ) ^ (k + 1) * θ)).vec ⊗ₜ[ℂ] + (qtowerPhaseGrad θ (k + 1) v).vec)) + = (towerPhaseGrad θ (k + 1)).vec ⊗ₜ[ℂ] v.vec + rw [QSystem.Iso.tmul_toIsometry_tmul, ih v, assoc_toIsometry_tmul_tmul, towerPhaseGrad_succ, + PureState.tmul_vec] + rfl + +/-- **Computational-basis dictionary for the control–target split.** The split carries the +phase-estimation input `qtowerKet (n+1) b u` (the control register in the computational-basis state +`b`, wrapping the target `u`) to the pure tower basis ket `towerKet n b` tensored with the untouched +target `u`: + +`qtowerSplitControl n S (qtowerKet (n+1) b u) = (towerKet n b) ⊗ u`. + +The computational-basis companion of `qtowerSplitControl_congr_qtowerPhaseGrad`, proved the same way +(the control wires are basis kets `qubitBasis (b i)` rather than phased-plus states). -/ +theorem qtowerSplitControl_congr_qtowerKet (n : ℕ) (b : Fin (n + 1) → Fin 2) (u : PureState S) : + PureState.congr (qtowerSplitControl n S) (qtowerKet (n + 1) b u) + = (towerKet n b).tmul u := by + suffices key : ∀ (m : ℕ) (c : Fin (m + 1) → Fin 2) (v : PureState S), + (qtowerSplitControl m S).toIsometry (qtowerKet (m + 1) c v).vec + = (towerKet m c).vec ⊗ₜ[ℂ] v.vec by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec] + exact key n b u + intro m + induction m with + | zero => + intro c v + erw [qtowerSplitControl_zero, qtowerKet_succ, qtowerKet_zero, towerKet_zero, + PureState.tmul_vec] + rfl + | succ k ih => + intro c v + rw [qtowerKet_succ, PureState.tmul_vec] + change (QSystem.assoc qubit (qtower k qubit) S).toIsometry + (((QSystem.Iso.refl qubit).tmul (qtowerSplitControl k S)).toIsometry + ((qubitBasis (c 0)).vec ⊗ₜ[ℂ] (qtowerKet (k + 1) (Fin.tail c) v).vec)) + = (towerKet (k + 1) c).vec ⊗ₜ[ℂ] v.vec + rw [QSystem.Iso.tmul_toIsometry_tmul, ih (Fin.tail c) v, assoc_toIsometry_tmul_tmul, + towerKet_succ, PureState.tmul_vec] + rfl + +/-! ### The inverse-QFT readout gate -/ + +/-- **The inverse tower QFT** on the pure control register `qtower n qubit`: the inverse quantum +Fourier transform `qftInverseEvolution (2^{n+1})` (Ex 5.5) of the single `2^{n+1}`-level register, +transported onto the `(n+1)`-qubit tower along the register bridge `quditPowTower n`. The +`Evolution` undoing `qftTowerEvolution n`. -/ +def qftTowerInverseEvolution (n : ℕ) : Evolution (qtower n qubit) := + Evolution.congr (quditPowTower n) (qftInverseEvolution (2 ^ (n + 1))) + +/-- **The inverse tower QFT read on a computational-basis ket.** By the reader +`quditPowTower_congr_evolvePure_towerKet` at `U = qftInverseEvolution (2^{n+1})`, the inverse tower +QFT acts on `towerKet n b` as the transport of the single-register inverse QFT's action on the +register ket `|finFunctionFinEquiv (b ∘ Fin.rev)⟩` — so on the computational basis it genuinely +performs the inverse quantum Fourier transform, wire bits reversed by `Fin.rev`. -/ +theorem qftTowerInverseEvolution_evolvePure_towerKet (n : ℕ) (b : Fin (n + 1) → Fin 2) : + (qftTowerInverseEvolution n).evolvePure (towerKet n b) + = PureState.congr (quditPowTower n) + ((qftInverseEvolution (2 ^ (n + 1))).evolvePure + (quditBasis (finFunctionFinEquiv (fun i => b i.rev)))) := + quditPowTower_congr_evolvePure_towerKet n (qftInverseEvolution (2 ^ (n + 1))) b + +/-- **The inverse-QFT readout gate** on the phase-estimation register `qtower (n+1) S`: the inverse +tower QFT `qftTowerInverseEvolution n` applied to the `n+1` control qubits — through the +control–target split `qtowerSplitControl n S` — and the identity on the target `S`. This is the +final box of N&C Figure 5.2, the inverse quantum Fourier transform on the control register that +reads the eigenphase back into the estimate register. Its action on the phase gradient is +`qtowerControlInverseQft_evolvePure_qtowerPhaseGrad`. -/ +def qtowerControlInverseQft (n : ℕ) (S : QSystem) : Evolution (qtower (n + 1) S) := + Evolution.congr (qtowerSplitControl n S).symm ((qftTowerInverseEvolution n).onLeft S) + +/-- The nested phase gradient rewritten through the split: `qtowerPhaseGrad θ (n+1) u` is the +transport (back along the split) of the standalone phase gradient tensored with the target. The +`.symm` companion of `qtowerSplitControl_congr_qtowerPhaseGrad`. -/ +theorem qtowerPhaseGrad_eq_congr_qtowerSplitControl_symm (θ : ℝ) (n : ℕ) (u : PureState S) : + qtowerPhaseGrad θ (n + 1) u + = PureState.congr (qtowerSplitControl n S).symm ((towerPhaseGrad θ n).tmul u) := by + rw [← qtowerSplitControl_congr_qtowerPhaseGrad θ n u, PureState.congr_symm_congr] + +/-- **The inverse-QFT readout acts on the control register.** The readout gate +`qtowerControlInverseQft n S` carries the phase gradient `qtowerPhaseGrad θ (n+1) u` to the inverse +tower QFT of the *standalone* control gradient tensored with the untouched target `u` (transported +back along the split): + +`qtowerControlInverseQft n S (qtowerPhaseGrad θ (n+1) u) + = (split⁻¹) ((qftTowerInverseEvolution n (towerPhaseGrad θ n)) ⊗ u)`. + +So the readout of the *nested* phase estimation reduces to the inverse tower QFT of the standalone +gradient on the pure control tower — the target register is untouched (`Evolution.onLeft`), and the +control–target split intertwines the two (`Evolution.congr_evolvePure_congr`). That the standalone +image is the computational-basis estimate `|m⟩` for a dyadic `θ = 2πm/2^{n+1}` (the product +representation, eq. 5.4) is proved in `AxQM/Core/QftTowerProductRep.lean`. -/ +theorem qtowerControlInverseQft_evolvePure_qtowerPhaseGrad (θ : ℝ) (n : ℕ) (u : PureState S) : + (qtowerControlInverseQft n S).evolvePure (qtowerPhaseGrad θ (n + 1) u) + = PureState.congr (qtowerSplitControl n S).symm + (((qftTowerInverseEvolution n).evolvePure (towerPhaseGrad θ n)).tmul u) := by + rw [qtowerPhaseGrad_eq_congr_qtowerSplitControl_symm, qtowerControlInverseQft, + Evolution.congr_evolvePure_congr, Evolution.onLeft_evolvePure] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerCtrlWireGate.lean b/LeanPool/AxQM/Core/QtowerCtrlWireGate.lean new file mode 100644 index 0000000000..bc82616cb8 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerCtrlWireGate.lean @@ -0,0 +1,182 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerSingleWireGate + +/-! +# Placing a controlled single-qubit gate on a wire pair of the control tower (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` (the register bridge `quditPowTower`) as a +*product of wire-addressed tower gates* (`qftTowerEvolution_eq_map_congr_prod`), so +each transported Figure 5.1 gate must be re-expressed as such a tower gate. The gates come in three +shapes: the swap layer (a *wire permutation*, `Evolution.qtowerPermWires`), the **Hadamards** (a +*single-wire gate*, `Evolution.qtowerSingleWire`), and the +**controlled-`Rₖ`** rotations — the circuit's only **two-wire** gate. This file supplies the +wire-addressed placement of a *controlled* single-qubit gate on the tower, the two-wire sibling of +`Evolution.qtowerSingleWire`, with its computational-basis action. + +On the tower the QFT's controlled-`Rₖ` gate always has its **control wire above its target wire**: +in the register (little-endian `finFunctionFinEquiv`) target `t` is driven by the later control +wires `c > t`, and the register bridge reverses the wire order (`Fin.rev`), so on the tower the +control lands at index `c.rev < t.rev`. The placement here is therefore built for the +control-above-target configuration `c < t`, the exact shape the QFT produces. + +## What is formalised + +* `Evolution.qtowerCtrlWire n c t g` — the **controlled single-wire gate**: control wire `c`, target + wire `t`, applying the single-qubit `Evolution` `g` to wire `t` when wire `c` is `|1⟩`, the + identity on every other wire (and the identity when the control is `|0⟩`). Defined by recursion on + the tower peeling the head wire: when the control is the head (`c = 0`, `t = t'+1`) it is + `controlledUnitary (Evolution.qtowerSingleWire n t' g)` — control on the head, the single-wire + gate on the tail; when the head is idle (`c = c'+1`, `t = t'+1`) it wraps the tail placement with + an idle head, `(Evolution.qtowerCtrlWire n c' t' g).onRight qubit`. (The residual cases — + `t = 0`, or a one-wire tower — cannot arise under `c < t`; the definition returns `Evolution.id` + there.) The two-wire analogue of `Evolution.qtowerSingleWire`, built on the same head-peel + `qtower (n+1) qubit = qubit ⊗ qtower n qubit`. +* `Evolution.qtowerCtrlWire_ctrl_zero` / `_ctrl_succ` — the two head-peel unfoldings above. +* `qtowerCtrlWire_evolvePure_towerKet` — the **action** (for `c < t`): `Evolution.qtowerCtrlWire n c + t g` sends the computational tower basis state `towerKet n b` to `g` applied to wire `t` when the + control bit `b c` is `1`, and to `towerKet n b` unchanged otherwise: + + `(qtowerCtrlWire n c t g) (towerKet n b)` + `= if b c = 1 then towerProd n (Function.update (fun j => |b j⟩) t (g |b t⟩))` + ` else towerKet n b`. + + So the placement fires exactly on the `|1⟩` branch of its control wire, and there acts as a + single-wire gate on the target — touching only wires `c` and `t`. This is the form the + wire-addressed re-expression of the Figure 5.1 controlled-`Rₖ` rotations (read on the tower + through the register bridge, in `AxQM/Core/QftTowerControlled.lean`) is matched against. + +## The proof + +`qtowerCtrlWire_evolvePure_towerKet` is a recursion on the tower peeling the head wire, exactly the +shape of `qtowerSingleWire_evolvePure_towerProd` and `mcCtrl_evolvePure_ctrlTower`. Since `c < t` +forces `t = t'+1`, the outer wire is never the target; casing the control splits the step: + +* control is the head (`c = 0`): `controlledUnitary`'s `|0⟩`/`|1⟩` basis action + (`controlledUnitary_evolvePure_ketZero` / `_ketOne`) reads the control bit `b 0`, and on the `|1⟩` + branch `qtowerSingleWire_evolvePure_towerKet` places `g` on the tail's wire `t'`; +* the head is idle (`c = c'+1`): `Evolution.onRight_evolvePure` peels it and the inductive + hypothesis (at `c' < t'`, from `Fin.succ_lt_succ_iff`) handles the tail, the control bit + `b c'.succ = b c` unchanged. + +The head/tail bookkeeping — reassembling a `towerProd (n+1)` over an updated wire `t'+1` from its +head `|b 0⟩` and the tail update on wire `t'` — is the shared `towerProd_head_update` step, matching +`Function.update` across `Fin.tail` with `Fin.tail_update_succ` (as in +`AxQM/Core/QftTowerHadamard.lean`). + +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **A controlled single-qubit gate placed on a wire pair of the control tower** `qtower n qubit`: +control wire `c`, target wire `t`, applying the single-qubit gate `g` to wire `t` when wire `c` is +`|1⟩` and the identity everywhere else. Defined by recursion on the tower peeling the head wire — +when the control is the head (`c = 0`, `t = t'+1`) it is `controlledUnitary` of the single-wire gate +on the tail, `controlledUnitary (Evolution.qtowerSingleWire n t' g)`; when the head is idle +(`c = c'+1`, `t = t'+1`) it wraps the tail placement with an idle head, +`(Evolution.qtowerCtrlWire n c' t' g).onRight qubit`. The residual cases (`t = 0`, or a one-wire +tower) cannot arise under the intended `c < t`; the definition returns `Evolution.id` there. The +two-wire sibling of `Evolution.qtowerSingleWire`, the shape of the Figure 5.1 controlled-`Rₖ` gates; +its basis action is `qtowerCtrlWire_evolvePure_towerKet`. -/ +def Evolution.qtowerCtrlWire : + (n : ℕ) → Fin (n + 1) → Fin (n + 1) → Evolution qubit → Evolution (qtower n qubit) + | 0, _, _, _ => Evolution.id + | n + 1, c, t, g => + Fin.cases Evolution.id + (fun t' => + Fin.cases (controlledUnitary (Evolution.qtowerSingleWire n t' g)) + (fun c' => (Evolution.qtowerCtrlWire n c' t' g).onRight qubit) c) + t + +/-- Control-head unfolding: on control wire `0` and target wire `t'+1` the controlled single-wire +gate is `controlledUnitary` of the single-wire gate placed on the tail's wire `t'`, +`controlledUnitary (Evolution.qtowerSingleWire n t' g)`. -/ +theorem Evolution.qtowerCtrlWire_ctrl_zero (n : ℕ) (t' : Fin (n + 1)) (g : Evolution qubit) : + Evolution.qtowerCtrlWire (n + 1) 0 t'.succ g + = controlledUnitary (Evolution.qtowerSingleWire n t' g) := by + erw [Evolution.qtowerCtrlWire, Fin.cases_succ, Fin.cases_zero] + +/-- Idle-head unfolding: on control wire `c'+1` and target wire `t'+1` the controlled single-wire +gate wraps the tail placement with an idle head, +`(Evolution.qtowerCtrlWire n c' t' g).onRight qubit`. -/ +theorem Evolution.qtowerCtrlWire_ctrl_succ (n : ℕ) (c' t' : Fin (n + 1)) (g : Evolution qubit) : + Evolution.qtowerCtrlWire (n + 1) c'.succ t'.succ g + = (Evolution.qtowerCtrlWire n c' t' g).onRight qubit := by + erw [Evolution.qtowerCtrlWire, Fin.cases_succ, Fin.cases_succ] + +/-- **Computational action of the controlled single-wire gate on a basis input.** For a control wire +`c` above its target wire `t` (`c < t`), placing the controlled gate on the pair `(c, t)` sends the +computational tower basis state `towerKet n b` to `g` applied to wire `t` when the control bit `b c` +is `1`, and to `towerKet n b` unchanged otherwise: + + `(qtowerCtrlWire n c t g) (towerKet n b)` + `= if b c = 1 then towerProd n (Function.update (fun j => |b j⟩) t (g |b t⟩))` + ` else towerKet n b`. + +So the gate fires exactly on the `|1⟩` branch of its control wire, and there acts as the single-wire +gate `g` on the target wire, leaving every other wire (and, on the `|0⟩` branch, the target too) +fixed — it touches only wires `c` and `t`. Proved by recursion on the tower peeling the head wire: +since `c < t` forces `t = t'+1`, the head is never the target, and casing the control uses either +`controlledUnitary`'s `|0⟩`/`|1⟩` basis action with `qtowerSingleWire_evolvePure_towerKet` on the +tail (control head), or `Evolution.onRight_evolvePure` with the inductive hypothesis (idle head). +This is the form the Figure 5.1 controlled-`Rₖ` gates — read on the tower through the register +bridge — are re-expressed against. -/ +theorem qtowerCtrlWire_evolvePure_towerKet (n : ℕ) (c t : Fin (n + 1)) (hct : c < t) + (g : Evolution qubit) (b : Fin (n + 1) → Fin 2) : + (Evolution.qtowerCtrlWire n c t g).evolvePure (towerKet n b) + = if b c = 1 then + towerProd n + (Function.update (fun j => qubitBasis (b j)) t (g.evolvePure (qubitBasis (b t)))) + else towerKet n b := by + induction n with + | zero => + obtain rfl := Fin.fin_one_eq_zero c + obtain rfl := Fin.fin_one_eq_zero t + exact absurd hct (lt_irrefl 0) + | succ n ih => + -- Reassemble a `towerProd (n+1)` over an updated wire `t'+1` from head and tail update. + have towerProd_head_update : ∀ (t' : Fin (n + 1)) (χ : PureState qubit), + towerProd (n + 1) (Function.update (fun j => qubitBasis (b j)) t'.succ χ) + = (qubitBasis (b 0)).tmul + (towerProd n (Function.update (fun j => qubitBasis (b j.succ)) t' χ)) := by + intro t' χ + rw [towerProd_succ, Fin.tail_update_succ, Function.update_of_ne (Fin.succ_ne_zero t').symm] + rfl + -- `c < t` forces `t = t'+1`; the head wire is never the target. Case the control. + revert hct + refine Fin.cases (fun hct => absurd hct (Fin.not_lt_zero c)) (fun t' => ?_) t + refine Fin.cases (fun _ => ?_) (fun c' hct => ?_) c + · -- control is the head wire `0`; target `t'+1`. Expose `qtower (n+1) = qubit ⊗ qtower n`. + change (controlledUnitary (Evolution.qtowerSingleWire n t' g)).evolvePure + (towerKet (n + 1) b) = _ + rw [towerKet_succ] + by_cases h0 : b 0 = 1 + · erw [ite_eq_left h0, towerProd_head_update, h0, controlledUnitary_evolvePure_ketOne, + qtowerSingleWire_evolvePure_towerKet] + · erw [ite_eq_right h0] + have h0' : b 0 = 0 := by omega + rw [h0', controlledUnitary_evolvePure_ketZero] + · -- head wire idle; recurse on the tail with `c' < t'`. + change ((Evolution.qtowerCtrlWire n c' t' g).onRight qubit).evolvePure + (towerKet (n + 1) b) = _ + rw [towerKet_succ, Evolution.onRight_evolvePure, ih c' t' (Fin.succ_lt_succ_iff.mp hct)] + by_cases hc : b c'.succ = 1 + · erw [ite_eq_left hc, ite_eq_left hc, towerProd_head_update] + · erw [ite_eq_right hc, ite_eq_right hc, ← towerKet_succ] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerHadamardLayer.lean b/LeanPool/AxQM/Core/QtowerHadamardLayer.lean new file mode 100644 index 0000000000..9f1009bcb4 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerHadamardLayer.lean @@ -0,0 +1,102 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ControlledPowerSequence +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.CnotXBasis + +/-! +# The phase-estimation Hadamard layer (N&C §5.2, Figure 5.2) — the circuit's input-preparation gate + +The first gate of the phase-estimation circuit (N&C Figure 5.2) is a **Hadamard layer**: a Hadamard +applied to each of the `t` control qubits, leaving the target register `S` untouched. Run on the +computational input `|0…0⟩ ⊗ |u⟩` it prepares the equal superposition `(1/√2ᵗ) ∑_b |b⟩ ⊗ |u⟩` over +all `2ᵗ` control registers — the state the controlled-power sequence `seqCtrlPow U t` then acts on. + +## What is formalised + +* `qtowerPlusKet t u` — the **prepared control register** `|+⟩^{⊗t} ⊗ |u⟩` on `qtower t S`: the `t` + control qubits each in `|+⟩ = (|0⟩ + |1⟩)/√2`, tensored with the target `u`. Because + `|+⟩^{⊗t} = (1/√2ᵗ) ∑_b |b⟩`, this **is** the equal superposition of all computational control + registers; built through the `PureState.tmul` product (so its normalization is inherited, not + re-proved). +* `qtowerHadamardLayer t` — the **Hadamard layer** as an `Evolution` on `qtower t S`: a Hadamard on + each control wire, identity on the target. Recursion on the number of controls: `H` on the + outermost wire (`hadamardGate.onLeft`) composed with the layer on the remaining wires + (`(·).onRight`). +* `qtowerHadamardLayer_evolvePure_qtowerKet_zero` — **the gate's action**: on the computational + input `|0…0⟩ ⊗ |u⟩` the layer produces the prepared superposition + `qtowerHadamardLayer t (|0…0⟩ ⊗ |u⟩) = |+⟩^{⊗t} ⊗ |u⟩`. Induction on `t`, peeling the outermost + wire: `H|0⟩ = |+⟩` on the head and the layer's action on the tail (inductive hypothesis). +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The prepared control register** `|+⟩^{⊗t} ⊗ |u⟩` on `qtower t S`: each of the `t` control +qubits in `|+⟩ = (|0⟩ + |1⟩)/√2`, tensored with the target pure state `u`. Since +`|+⟩^{⊗t} = (1/√2ᵗ) ∑_b |b⟩`, this is the equal superposition of all `2ᵗ` computational control +registers — the output of the phase-estimation Hadamard layer, and the input to `seqCtrlPow U t`. -/ +def qtowerPlusKet : (t : ℕ) → PureState S → PureState (qtower t S) + | 0, u => u + | (t + 1), u => qubitPlus ⊗ qtowerPlusKet t u + +@[simp] theorem qtowerPlusKet_zero (u : PureState S) : qtowerPlusKet 0 u = u := rfl + +/-- Peeling the outermost wire: `qtowerPlusKet (t+1) u = |+⟩ ⊗ qtowerPlusKet t u`. -/ +theorem qtowerPlusKet_succ (t : ℕ) (u : PureState S) : + qtowerPlusKet (t + 1) u = qubitPlus ⊗ qtowerPlusKet t u := rfl + +/-- **The phase-estimation Hadamard layer** as an `Evolution` on `qtower t S`: a Hadamard on each of +the `t` control wires, identity on the target register `S`. Recursion on the number of controls: +`qtowerHadamardLayer 0` is the identity, and `qtowerHadamardLayer (t+1)` is a Hadamard on the +outermost wire (`hadamardGate.onLeft`) composed with the `t`-wire layer on the inner register +(`(·).onRight qubit`). The first gate of N&C Figure 5.2, generalised over an arbitrary target +`S`. -/ +def qtowerHadamardLayer : (t : ℕ) → Evolution (qtower t S) + | 0 => Evolution.id + | (t + 1) => (hadamardGate.onLeft (qtower t S)).comp ((qtowerHadamardLayer t).onRight qubit) + +/-- Peeling the outermost wire of the Hadamard layer: +`qtowerHadamardLayer (t+1) = (H ⊗ 1) · (layer on the inner register)`. -/ +theorem qtowerHadamardLayer_succ (t : ℕ) : + qtowerHadamardLayer (t + 1) (S := S) + = (hadamardGate.onLeft (qtower t S)).comp ((qtowerHadamardLayer t).onRight qubit) := rfl + +/-- **The Hadamard layer prepares the equal superposition.** On the computational input +`|0…0⟩ ⊗ |u⟩` (the control register all-zero, `qtowerKet t (fun _ => 0) u`), the Hadamard layer +produces the prepared control register `|+⟩^{⊗t} ⊗ |u⟩`: +`qtowerHadamardLayer t (|0…0⟩ ⊗ |u⟩) = qtowerPlusKet t u`. + +This is the state-preparation stage of the phase-estimation circuit — the equal superposition +`(1/√2ᵗ) ∑_b |b⟩ ⊗ |u⟩` on which the controlled-power sequence `seqCtrlPow U t` then loads the +eigenphases. Induction on the number of controls `t`: the outermost wire is peeled with +`Evolution.evolvePure_comp`; the outer Hadamard sends `|0⟩` to `|+⟩` (via +`Evolution.onLeft_evolvePure`, `hadamardGate_evolvePure_qubitBasis_zero`) and the inner layer acts +on the tail (`Evolution.onRight_evolvePure`, inductive hypothesis). -/ +theorem qtowerHadamardLayer_evolvePure_qtowerKet_zero : + ∀ (t : ℕ) (u : PureState S), + (qtowerHadamardLayer t).evolvePure (qtowerKet t (fun _ => 0) u) = qtowerPlusKet t u + | 0, _ => rfl + | (t + 1), u => by + simp only [qtower, qtowerHadamardLayer, qtowerKet_succ, Evolution.evolvePure_comp, + Evolution.onRight_evolvePure, Evolution.onLeft_evolvePure, + hadamardGate_evolvePure_qubitBasis_zero, qtowerPlusKet] + rw [show Fin.tail (fun _ : Fin (t + 1) => (0 : Fin 2)) = (fun _ => 0) from rfl, + qtowerHadamardLayer_evolvePure_qtowerKet_zero t u] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerHeadIdleMeasurement.lean b/LeanPool/AxQM/Core/QtowerHeadIdleMeasurement.lean new file mode 100644 index 0000000000..b31b8ac759 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerHeadIdleMeasurement.lean @@ -0,0 +1,86 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerMeasurement +public import LeanPool.AxQM.Postulates.API.DeferredMeasurementOnLeft + +/-! +# A head-idle gate defers past the terminal measurement's head wire (N&C Problem 5.2) + +The measured quantum Fourier transform (Problem 5.2) is assembled by an outer induction over the +tower depth that processes the Figure 5.1 head-layer peel +`qftTowerEvolution (n+1) = Φ · qftTailEvolution n · qftHeadLayer n` one wire at a +time under the terminal per-wire measurement `qtowerMeasurement (n+1)`. That terminal measurement +is a cascade of its **head** factor `controlMeasurement (qtower n qubit)` (measure wire `0`) and the +recursive tail (`qtowerMeasurement_succ`). To defer the head control wire's cascade, +the head-wire measurement must first be pushed leftward past the **recursive tail +QFT** `qftTailEvolution n = (qftTowerEvolution n).onRight qubit` — a right-factor gate `1 ⊗ Q` that +leaves the head wire idle. + +That push is a disjoint-factor commutation: the head measurement touches only wire `0` and the tail +QFT only the tail wires, so the tail QFT is **invisible** to the head statistics and **defers past** +the head measurement unchanged. This file records it for an arbitrary head-idle gate `g.onRight +qubit` (the tail QFT is the instance `g = qftTowerEvolution n`), for Born probabilities and for +post-measurement states — thin instances of the disjoint-factor deferral engine +`Measurement.{bornProb,postMeasurement}_evolve_onLeft_of_comm` +(`AxQM/Postulates/API/DeferredMeasurementOnLeft.lean`), since the head measurement +`controlMeasurement (qtower n qubit)` is *by definition* a left-factor measurement +`(·).onLeft (qtower n qubit)`. + +Compare the sibling terminal-measurement deferral `AxQM/Core/QtowerPermMeasurement.lean` (the swap +relabelling). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **A head-idle gate is invisible to the head-wire statistics.** Measuring the head wire of the +tower (`controlMeasurement (qtower n qubit)`) *after* a right-factor gate `g.onRight qubit = 1 ⊗ g` +that leaves the head wire idle gives, for every outcome `i`, the same Born probability as measuring +the input `ρ` directly: the tail-only gate is invisible to the head-wire measurement. The head +instance of the disjoint-factor engine `Measurement.bornProb_evolve_onLeft_of_comm`, since +`controlMeasurement (qtower n qubit) = (·).onLeft (qtower n qubit)` measures the *left* (head) +factor while `g.onRight qubit = 1 ⊗ g` acts on the *right* (tail) factor. Used by the measured-QFT +outer induction to push the head-wire measurement past the recursive tail QFT `qftTailEvolution n`. +-/ +theorem controlMeasurement_onRight_measure_head_bornProb (g : Evolution (qtower n qubit)) + (ρ : State (qubit ⊗ qtower n qubit)) (i : Fin 2) : + (controlMeasurement (qtower n qubit)).bornProb ((g.onRight qubit).evolve ρ) i + = (controlMeasurement (qtower n qubit)).bornProb ρ i := + Measurement.bornProb_evolve_onLeft_of_comm _ g ρ i + +/-- **The head-wire post-measurement state carries a head-idle gate along.** The state after +measuring outcome `i` on the head wire of the tower, applied to the input evolved by a head-idle +right-factor gate `g.onRight qubit = 1 ⊗ g`, equals that same gate applied to the state after +measuring `ρ`: + + `postMeas((1 ⊗ g) ρ (1 ⊗ g)†, i) = (1 ⊗ g) · postMeas(ρ, i)`. + +The tail-only gate **defers past** the head-wire measurement unchanged, because it acts on the tail +factor, disjoint from the measured head wire. The head instance of the disjoint-factor engine +`Measurement.postMeasurement_evolve_onLeft_of_comm`; the outcome is equally possible after the gate +because the probabilities agree (`controlMeasurement_onRight_measure_head_bornProb`). Used by the +measured-QFT outer induction to carry the recursive tail QFT `qftTailEvolution n` past the head-wire +measurement before the head control cascade is deferred. -/ +theorem controlMeasurement_onRight_measure_head_postMeasurement (g : Evolution (qtower n qubit)) + (ρ : State (qubit ⊗ qtower n qubit)) (i : Fin 2) + (hp : (controlMeasurement (qtower n qubit)).bornProb ρ i ≠ 0) : + (controlMeasurement (qtower n qubit)).postMeasurement ((g.onRight qubit).evolve ρ) i + (by rw [controlMeasurement_onRight_measure_head_bornProb]; exact hp) + = (g.onRight qubit).evolve + ((controlMeasurement (qtower n qubit)).postMeasurement ρ i hp) := + Measurement.postMeasurement_evolve_onLeft_of_comm _ g ρ i hp + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerHeadPhaseControl.lean b/LeanPool/AxQM/Core/QtowerHeadPhaseControl.lean new file mode 100644 index 0000000000..83d4c743ec --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerHeadPhaseControl.lean @@ -0,0 +1,128 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerCtrlWireGate +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryPhasePlus +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.TowerProdMultilinear + +/-! +# The head control wire's phase cascade rotates a phased-plus head (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) peels the head control wire's Figure 5.1 +gates off `qftTowerEvolution (n+1)`: a Hadamard puts the head wire into a phased-plus superposition, +and then the head wire's cascade of controlled-`Rₖ` phase gates acts on that superposed head with +the tail wires still in the computational basis. This file computes the action of those gates on +exactly such a state — a phased-plus head tensored with a basis tail — the computational heart of +the head layer of the outer-induction peel. + +Each Figure 5.1 controlled-`Rₖ` gate the head wire drives is the tower controlled single-wire gate +`Evolution.qtowerCtrlWire (n+1) 0 t.succ (phaseShiftGate φ)` (control the head wire `0`, phase gate +on a tail wire `t.succ`). Since a controlled-*phase* gate is diagonal, on a basis +tail it acts as a scalar phase `e^{iφ·bₜ}` on the target — the "phase kickback" that advances the +control's phased-plus angle rather than entangling the two wires. + +## What is formalised + +* `qtowerCtrlWire_zero_phaseShiftGate_evolvePure_qubitPhasePlus` — the **single head-controlled + phase gate** on a phased-plus head: + + `C₀(Rφ on wire t.succ) (|+_α⟩ ⊗ |c⟩) = |+_{α + φ·(c t)}⟩ ⊗ |c⟩`, + + the head wire's angle advancing by `φ` exactly when the target tail wire `t` reads `1`, the tail + `towerKet n c` returned unchanged. +* `qtowerHeadCtrlPhaseCascade_evolvePure_qubitPhasePlus` — the whole **head phase cascade** on a + phased-plus head: composing a list `gs` of `(t, φ)` gates advances the head angle by the total + `∑_{(t,φ)∈gs} φ·(c t)`, the tail `|c⟩` still unchanged — no wire ever entangled with the head. + +## Proof + +The single gate is `controlledUnitary (Evolution.qtowerSingleWire n t (phaseShiftGate φ))` +(`Evolution.qtowerCtrlWire_ctrl_zero`), and the inner single-wire phase gate acts on the basis tail +`towerKet n c` as the scalar phase `e^{iφ·(c t)}` (the phase gate's diagonal action +`phaseShiftGate_op_apply_qubitBasis` pulled through the product state `towerProd` by its tensor +multilinearity, `towerProd_vec_update_smul`), so the generic +phase-kickback lemma `controlledUnitary_evolvePure_qubitPhasePlus` applies. The cascade is then a +list induction over the single-gate step, the phases summing. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **A single head-controlled phase gate rotates a phased-plus head wire.** The tower controlled +single-wire gate `Evolution.qtowerCtrlWire (n+1) 0 t.succ (phaseShiftGate φ)` — control the head +wire `0`, the phase gate `P(φ)` on the tail wire `t.succ` — sends a phased-plus head tensored with +a basis tail to the phased-plus head with its angle advanced by `φ·(c t)`, the tail unchanged: + + `C₀(P(φ) on t.succ) (|+_α⟩ ⊗ towerKet n c) = |+_{α + φ·(c t)}⟩ ⊗ towerKet n c`. + +The gate is `controlledUnitary (Evolution.qtowerSingleWire n t (phaseShiftGate φ))`, and the inner +single-wire phase gate acts diagonally on the basis tail `towerKet n c` as the scalar phase +`e^{iφ·(c t)}`, so the phase-kickback lemma `controlledUnitary_evolvePure_qubitPhasePlus` advances +the control's phased-plus angle by that amount — no entanglement between the head and tail wires. -/ +theorem qtowerCtrlWire_zero_phaseShiftGate_evolvePure_qubitPhasePlus (n : ℕ) (t : Fin (n + 1)) + (φ α : ℝ) (c : Fin (n + 1) → Fin 2) : + (Evolution.qtowerCtrlWire (n + 1) 0 t.succ (phaseShiftGate φ)).evolvePure + ((qubitPhasePlus α).tmul (towerKet n c)) + = (qubitPhasePlus (α + φ * ((c t : ℕ) : ℝ))).tmul (towerKet n c) := by + -- The phase gate's diagonal cell `[1, e^{iφ}]_d` is the scalar `e^{iφ·d}`. + have hcell : ∀ d : Fin 2, (![1, Complex.exp ((φ : ℂ) * Complex.I)] d) + = Complex.exp (((φ * ((d : ℕ) : ℝ) : ℝ) : ℂ) * Complex.I) := by + intro d; fin_cases d <;> simp + -- The inner single-wire phase gate acts on the basis tail as the scalar phase `e^{iφ·(c t)}`. + have hphase : ((phaseShiftGate φ).evolvePure (qubitBasis (c t))).vec + = Complex.exp (((φ * ((c t : ℕ) : ℝ) : ℝ) : ℂ) * Complex.I) • (qubitBasis (c t)).vec := by + rw [Evolution.evolvePure_vec, phaseShiftGate_op_apply_qubitBasis, hcell (c t)] + rw [Evolution.qtowerCtrlWire_ctrl_zero] + apply controlledUnitary_evolvePure_qubitPhasePlus + -- The inner phase gate scales the wire `t` factor of the basis tail by `e^{iφ·(c t)}`; pull that + -- scalar out of the whole product via `towerProd`'s tensor multilinearity. + rw [qtowerSingleWire_evolvePure_towerKet, towerKet_eq_towerProd, + towerProd_vec_update_smul n (fun j => qubitBasis (c j)) t + (Complex.exp (((φ * ((c t : ℕ) : ℝ) : ℝ) : ℂ) * Complex.I)) + ((phaseShiftGate φ).evolvePure (qubitBasis (c t))) hphase] + +/-- **The head control wire's whole phase cascade rotates a phased-plus head wire.** Composing the +list `gs` of head-controlled tower phase gates — each `Evolution.qtowerCtrlWire (n+1) 0 p.1.succ +(phaseShiftGate p.2)`, control the head wire `0`, phase gate on tail wire `p.1.succ` — on a +phased-plus head tensored with a basis tail advances the head's phased-plus angle by the total phase +`∑_{(t,φ)∈gs} φ·(c t)`, the tail `towerKet n c` returned unchanged: + + `(∏_{(t,φ)∈gs} C₀(P(φ) on t.succ)) (|+_α⟩ ⊗ towerKet n c)` + `= |+_{α + ∑ φ·(c t)}⟩ ⊗ towerKet n c`. + +Since every gate is a diagonal controlled-phase whose target tail wire stays in the computational +basis, the head wire is never entangled with the tail: the whole cascade acts as a single phase +rotation of the head. A list induction over the single-gate step +(`qtowerCtrlWire_zero_phaseShiftGate_evolvePure_qubitPhasePlus`), the phases summing. This is the +head layer the outer-induction peel of the measured-QFT reduction reads off `qftTowerEvolution`. -/ +theorem qtowerHeadCtrlPhaseCascade_evolvePure_qubitPhasePlus (n : ℕ) + (gs : List (Fin (n + 1) × ℝ)) (α : ℝ) (c : Fin (n + 1) → Fin 2) : + ((gs.map fun p => + Evolution.qtowerCtrlWire (n + 1) 0 p.1.succ (phaseShiftGate p.2)).prod).evolvePure + ((qubitPhasePlus α).tmul (towerKet n c)) + = (qubitPhasePlus (α + (gs.map fun p => p.2 * ((c p.1 : ℕ) : ℝ)).sum)).tmul + (towerKet n c) := by + induction gs with + | nil => + simp only [List.map_nil, List.prod_nil, List.sum_nil, add_zero, Evolution.one_def] + exact Evolution.id_evolvePure _ + | cons p gs ih => + erw [List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.evolvePure_comp, ih, + qtowerCtrlWire_zero_phaseShiftGate_evolvePure_qubitPhasePlus, List.map_cons, List.sum_cons] + congr 2 + ring + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerMeasurement.lean b/LeanPool/AxQM/Core/QtowerMeasurement.lean new file mode 100644 index 0000000000..f3cc20cef0 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerMeasurement.lean @@ -0,0 +1,210 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QftTowerBasis +public import LeanPool.AxQM.Postulates.API.ControlMeasurementCommute +public import LeanPool.AxQM.Postulates.API.CascadedMeasurement +public import LeanPool.AxQM.Postulates.API.MeasurementReindex +public import LeanPool.AxQM.Postulates.API.MeasurementExt +public import LeanPool.AxQM.Postulates.API.QuditMeasurement +public import LeanPool.AxQM.Postulates.API.ProjectorCollapse + +/-! +# The terminal per-wire measurement on the control tower (N&C Problem 5.2) + +The measured quantum Fourier transform (N&C Problem 5.2) ends by measuring **every wire** of the +output register in the computational basis. The QFT unitary and each Figure 5.1 gate are +transported onto the `(n+1)`-qubit control tower `qtower n qubit` in +`AxQM/Core/QftTowerCircuit.lean`; this file constructs the other half of the circuit — the +*terminal measurement* — as a wire-addressed object on the same tower, so the whole-circuit +semiclassical reduction can defer it, wire by wire, past the controlled-`Rₖ` cascades. + +## The object + +`qtowerMeasurement n : Measurement (Fin (n+1) → Fin 2) (qtower n qubit)` is the joint +computational-basis measurement of all `n+1` wires, built **head-first** to match the tower +recursion `qtower (n+1) qubit = qubit ⊗ qtower n qubit` and the cascade deferral of +[upstream `AxQM/NC/Ch5/Problem5_2.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_2.lean) (which measures the head control wire with `controlMeasurement`): + +* `qtowerMeasurement 0` measures the single wire — the qudit computational measurement + `quditMeasurement 2` on `qtower 0 qubit = qubit`, its `Fin 2` outcome relabelled to + `Fin 1 → Fin 2`. +* `qtowerMeasurement (n+1)` is the **cascade** (`Measurement.cascade`, N&C Ex. 2.57) of + `controlMeasurement (qtower n qubit)` (measure the head wire `0`) with + `(qtowerMeasurement n).onRight qubit` (measure the remaining `n+1` wires), its + `Fin 2 × (Fin (n+1) → Fin 2)` outcome relabelled to `Fin (n+2) → Fin 2` by `Fin.consEquiv`. The + two operators act on disjoint tensor factors, so the cascade order is immaterial. + +The recursion makes the head peel `qtowerMeasurement_succ` **definitional**: it exhibits the head +wire's measurement as exactly the `controlMeasurement` that the cascade-deferral theorems +consume, with the rest of the tower measured by the recursive tail — the shape the semiclassical +induction needs. + +## Faithfulness + +`qtowerMeasurement_eq_congr_quditMeasurement` proves this per-wire measurement **is** the register's +computational-basis measurement: measuring the single `2ⁿ⁺¹`-level register `qudit (2ⁿ⁺¹)` — where +the QFT output lives — in the computational basis `quditMeasurement (2ⁿ⁺¹)`, transported onto the +tower by the register bridge `quditPowTower n`, equals `qtowerMeasurement n` (up to the wire↔index +relabelling `finFunctionFinEquiv ∘ (· ∘ Fin.rev)`, the same little-endian/big-endian reconciliation +`Fin.rev` the gate re-expressions use). So "measure every wire in the computational basis" and +"measure the register in the computational basis" are the same measurement — the measurement N&C +performs after the QFT, now wire-addressed on the tower. + +The proof matches the two projective measurements operator-by-operator. Each `qtowerMeasurement` +operator is the rank-one projector onto the tower basis vector `towerKet n b` (`key`, by induction: +the head peel splits it as `|b 0⟩⟨b 0| ⊗ (rest)` via `rankOne_tmul_self`); the transported +`quditMeasurement` operator is the projector onto +`quditPowTower n • |finFunctionFinEquiv (b ∘ rev)⟩ = towerKet n b` (the bridge dictionary +`quditPowTower_congr_quditBasis_apply`, with `rankOne_conjStarAlgEquiv` carrying the projector +through the isometry). Equal operators give equal measurements (`Measurement.ext_op`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **The terminal per-wire computational-basis measurement on the control tower.** +`qtowerMeasurement n` measures all `n+1` wires of `qtower n qubit` in the computational basis, +recording the bit-string `Fin (n+1) → Fin 2` of outcomes. Built head-first to match the tower +recursion: the head wire is measured with `controlMeasurement`, the remaining wires by the recursive +tail, joined by `Measurement.cascade` (with the outcome sets relabelled by `Fin.consEquiv` and, at +the base, `Equiv.funUnique`). This is the measurement the measured-QFT circuit performs after the +transported quantum Fourier transform (`qftTowerEvolution`). -/ +def qtowerMeasurement : (n : ℕ) → Measurement (Fin (n + 1) → Fin 2) (qtower n qubit) + | 0 => (quditMeasurement 2).reindexOutcome (Equiv.funUnique (Fin 1) (Fin 2)) + | n + 1 => + ((controlMeasurement (qtower n qubit)).cascade + ((qtowerMeasurement n).onRight qubit)).reindexOutcome + (Fin.consEquiv (fun _ : Fin (n + 2) => Fin 2)).symm + +/-- Base unfolding: a single-wire tower is measured by the qudit computational measurement. -/ +theorem qtowerMeasurement_zero : + qtowerMeasurement 0 = (quditMeasurement 2).reindexOutcome (Equiv.funUnique (Fin 1) (Fin 2)) := + rfl + +/-- **Head peel of the terminal measurement** (definitional). `qtowerMeasurement (n+1)` measures the +head control wire `0` with `controlMeasurement (qtower n qubit)` and the remaining wires with the +recursive tail `(qtowerMeasurement n).onRight qubit`, cascaded and relabelled by `Fin.consEquiv`. +This exhibits the terminal all-wire measurement as the `controlMeasurement` of the head wire +followed by the rest — exactly the shape the semiclassical reduction defers past a +control wire's controlled-`Rₖ` cascade (`controlledUnitaryCascade_measure_control_*`). -/ +theorem qtowerMeasurement_succ (n : ℕ) : + qtowerMeasurement (n + 1) = + ((controlMeasurement (qtower n qubit)).cascade + ((qtowerMeasurement n).onRight qubit)).reindexOutcome + (Fin.consEquiv (fun _ : Fin (n + 2) => Fin 2)).symm := + rfl + +/-- The wire↔register-index relabelling `b ↦ |finFunctionFinEquiv (b ∘ Fin.rev)⟩`: a tower wire +bit-string is read as the little-endian register index after the `Fin.rev` endianness flip (the +same flip the Figure 5.1 gate re-expressions carry). It relabels the register's +`Fin (2ⁿ⁺¹)` outcome set to the tower's `Fin (n+1) → Fin 2` wire outcomes. -/ +def towerMeasurementOutcomeEquiv (n : ℕ) : (Fin (n + 1) → Fin 2) ≃ Fin (2 ^ (n + 1)) := + (Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin 2))).trans finFunctionFinEquiv + +/-- **The terminal per-wire measurement is the register's computational-basis measurement.** +Measuring every wire of the tower in the computational basis (`qtowerMeasurement n`) equals the +single-register computational-basis measurement `quditMeasurement (2ⁿ⁺¹)` — the measurement N&C +performs on the QFT output — transported onto the tower by the register bridge `quditPowTower n`, +with the outcome sets matched by `towerMeasurementOutcomeEquiv`. So "measure each of the `n+1` wires +in the computational basis" *is* "measure the `2ⁿ⁺¹`-level register in the computational basis": the +per-wire object is faithful to the measured quantum Fourier transform, not merely some measurement +on the tower. + +The proof matches the two projective measurements operator-by-operator. Each `qtowerMeasurement` +operator is the rank-one projector onto the tower basis vector `towerKet n b` (`key`, by induction: +the head peel `qtowerMeasurement_succ` splits it as `|b 0⟩⟨b 0| ⊗ (rest)` via `rankOne_tmul_self`); +the transported `quditMeasurement` operator is the projector onto +`quditPowTower n • |finFunctionFinEquiv (b ∘ rev)⟩ = towerKet n b` (the bridge dictionary +`quditPowTower_congr_quditBasis_apply`, with `rankOne_conjStarAlgEquiv` carrying the projector +through the isometry). Equal operators give equal measurements. -/ +theorem qtowerMeasurement_eq_congr_quditMeasurement (n : ℕ) : + qtowerMeasurement n = + (Measurement.congr (quditPowTower n) (quditMeasurement (2 ^ (n + 1)))).reindexOutcome + (towerMeasurementOutcomeEquiv n) := by + -- Each `qtowerMeasurement` operator is the projector onto the tower basis vector `towerKet m b`. + have key : ∀ (m : ℕ) (b : Fin (m + 1) → Fin 2), + (qtowerMeasurement m).op b = rankOne ℂ (towerKet m b).vec (towerKet m b).vec := by + intro m + induction m with + | zero => + intro b + rw [qtowerMeasurement_zero, Measurement.reindexOutcome_op, quditMeasurement_op, towerKet_zero] + rw [quditBasis_vec, qubitBasis_vec] + rfl + | succ k ih => + intro b + have hstep : (qtowerMeasurement (k + 1)).op b + = TensorProduct.mapL (rankOne ℂ (qubitBasis (b 0)).vec (qubitBasis (b 0)).vec) + (rankOne ℂ (towerKet k (fun i => b i.succ)).vec + (towerKet k (fun i => b i.succ)).vec) := by + rw [qtowerMeasurement_succ, Measurement.reindexOutcome_op, Measurement.cascade_op, + Measurement.onRight_op, controlMeasurement_op, ih, + show ((Fin.consEquiv fun _ : Fin (k + 2) => Fin 2).symm b).1 = b 0 from rfl, + show ((Fin.consEquiv fun _ : Fin (k + 2) => Fin 2).symm b).2 = fun i => b i.succ from rfl] + refine (TensorProduct.mapL_comp _ _ _ _).symm.trans ?_ + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + ContinuousLinearMap.comp_id] + rw [hstep, towerKet_succ, PureState.tmul_vec] + exact (InnerProductSpace.rankOne_tmul_self _ _).symm + -- Match the two measurements operator-by-operator. + refine Measurement.ext_op fun b => ?_ + rw [key n b, Measurement.reindexOutcome_op, Measurement.congr_op, quditMeasurement_op, + InnerProductSpace.rankOne_conjStarAlgEquiv] + -- The transported register ket is the tower basis vector, by the bridge dictionary. + have hvec : (quditPowTower n).toIsometry (quditBasis (towerMeasurementOutcomeEquiv n b)).vec + = (towerKet n b).vec := by + rw [← PureState.congr_vec, + show towerMeasurementOutcomeEquiv n b = finFunctionFinEquiv (fun j => b j.rev) from rfl, + quditPowTower_congr_quditBasis_rev] + rw [hvec] + +/-- **The joint computational-basis measurement collapses any input to its outcome ket.** Measuring +every wire of the tower in the computational basis (`qtowerMeasurement n`) and obtaining the +bit-string `r` leaves the register in the corresponding computational-basis tower state +`towerKet n r` — **independent of the input state** `ρ` (mixed or pure): + + `postMeas(ρ, r) = (towerKet n r).toState`. + +A joint computational-basis measurement is projective and rank-one, so every wire is left definite +and the collapsed state remembers nothing of `ρ` beyond the recorded outcome. Its operator at `r` is +the rank-one projector `|towerKet n r⟩⟨towerKet n r|`, obtained here by **reusing** the +already-proven register identity `qtowerMeasurement_eq_congr_quditMeasurement` (rather than +re-running its head-peel `key` induction) and the shared bridge lemma +`quditPowTower_congr_quditBasis_rev`, so the projector collapse +`Measurement.postMeasurement_toState_of_op_eq_rankOne` applies. The reusable +state-update companion of the statistics; applied to `ρ = qftTowerEvolution n · ρ₀`, it gives the +collapsed state of the measured quantum Fourier transform (N&C Problem 5.2). -/ +theorem qtowerMeasurement_postMeasurement_eq_towerKet (n : ℕ) (ρ : State (qtower n qubit)) + (r : Fin (n + 1) → Fin 2) (hp : (qtowerMeasurement n).bornProb ρ r ≠ 0) : + (qtowerMeasurement n).postMeasurement ρ r hp = (towerKet n r).toState := by + -- The measurement operator at `r` is the rank-one projector onto `towerKet n r`. Obtain it by + -- reusing the register identity `qtowerMeasurement_eq_congr_quditMeasurement` (avoiding a re-run + -- of its head-peel `key` induction): push `.op` through the reindex/congr and the register + -- measurement (`quditMeasurement_op`), then transport the projector along the bridge lemma + -- `quditPowTower_congr_quditBasis_rev`. + have hop : (qtowerMeasurement n).op r + = rankOne ℂ (towerKet n r).vec (towerKet n r).vec := by + rw [qtowerMeasurement_eq_congr_quditMeasurement, Measurement.reindexOutcome_op, + Measurement.congr_op, quditMeasurement_op, InnerProductSpace.rankOne_conjStarAlgEquiv] + have hvec : (quditPowTower n).toIsometry (quditBasis (towerMeasurementOutcomeEquiv n r)).vec + = (towerKet n r).vec := by + rw [← PureState.congr_vec, show towerMeasurementOutcomeEquiv n r + = finFunctionFinEquiv (fun j => r j.rev) from rfl, quditPowTower_congr_quditBasis_rev] + rw [hvec] + exact Measurement.postMeasurement_toState_of_op_eq_rankOne _ (towerKet n r) ρ r hop hp + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerPermMeasurement.lean b/LeanPool/AxQM/Core/QtowerPermMeasurement.lean new file mode 100644 index 0000000000..1783186d37 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerPermMeasurement.lean @@ -0,0 +1,159 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerWirePermutation +public import LeanPool.AxQM.Core.QtowerMeasurement +public import LeanPool.AxQM.Postulates.API.DeferredMeasurementReindex + +/-! +# AxQM — a wire permutation defers past the terminal measurement (swaps ↦ relabelling) + +The wire-permutation gate `Evolution.qtowerPermWires σ` (`AxQM/Core/QtowerWirePermutation.lean`) +defers past the terminal per-wire computational-basis measurement `qtowerMeasurement n` +(`AxQM/Core/QtowerMeasurement.lean`) as a pure **relabelling of the classical outcomes**: measuring +outcome `r` after the permutation is measuring outcome `r ∘ σ` before it, and the collapsed state is +the permutation applied to the collapsed state of that relabelled outcome. + +* `qtowerPermWires_measure_bornProb` — the outcome statistics are relabelled: + `p(r ∣ σ·ρ·σ†) = p(r ∘ σ ∣ ρ)`. +* `qtowerPermWires_measure_postMeasurement` — the collapse defers the permutation: + `postMeas(σ·ρ·σ†, r) = σ · postMeas(ρ, r ∘ σ)`; on a computational-basis collapsed state the + permutation is just a wire relabelling. + +This is the step of **Nielsen & Chuang, Problem 5.2** that removes the swap network at the end +of the quantum Fourier transform (Figure 5.1): the swaps, applied immediately before the terminal +measurement, contribute only a permutation of the recorded measurement bits — *no two-qubit gate +survives*. The peel `qftTowerEvolution_succ_eq_qftHeadLayer_peel` leaves such a cyclic wire +permutation `Φ` outermost, and the measured-QFT reduction absorbs it here. + +## Proof + +Each public statement is a one-line projection of the private `qtowerPermWires_measure_defers`, +which applies the reindexing engine +`Measurement.{bornProb,postMeasurement}_evolve_of_reindex_comm` +(`AxQM/Postulates/API/DeferredMeasurementReindex.lean`) to the shared setup. + +The shared work is the reindexing commutation `Mᵣ (σ) = (σ) M_{r∘σ}` (`hcomm` below) — +each measurement operator is the rank-one projector onto its tower basis vector `towerKet` (via the +faithfulness `qtowerMeasurement_eq_congr_quditMeasurement`), and the unitary permutation carries the +projector of outcome `r` onto that of the relabelled outcome `r ∘ σ` +(`comp_rankOne_self_comp_adjoint`). The two statements that consume it are bundled into one `∧` +so that this operator-level setup is proved once, as in the sibling `qtowerHeadPhaseCascade` +deferrals of `AxQM/NC/Ch5/`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **Bundled deferral of a wire permutation past the terminal measurement** (private engine). Both +the Born-probability relabelling and the post-measurement deferral, exposed from a *single* proof so +that the operator-level setup they share — the reindexing commutation `Mᵣ (qtowerPermWires σ) = +(qtowerPermWires σ) M_{r∘σ}` (`hcomm`) — is discharged exactly once. The public projections are +`qtowerPermWires_measure_bornProb` and `qtowerPermWires_measure_postMeasurement`. -/ +private theorem qtowerPermWires_measure_defers (σ : Equiv.Perm (Fin (n + 1))) : + (∀ (ρ : State (qtower n qubit)) (r : Fin (n + 1) → Fin 2), + (qtowerMeasurement n).bornProb ((Evolution.qtowerPermWires σ).evolve ρ) r + = (qtowerMeasurement n).bornProb ρ (fun j => r (σ j))) + ∧ (∀ (ρ : State (qtower n qubit)) (r : Fin (n + 1) → Fin 2) + (hp : (qtowerMeasurement n).bornProb ρ (fun j => r (σ j)) ≠ 0) + (hp' : (qtowerMeasurement n).bornProb ((Evolution.qtowerPermWires σ).evolve ρ) r ≠ 0), + (qtowerMeasurement n).postMeasurement ((Evolution.qtowerPermWires σ).evolve ρ) r hp' + = (Evolution.qtowerPermWires σ).evolve + ((qtowerMeasurement n).postMeasurement ρ (fun j => r (σ j)) hp)) := by + -- The outcome relabelling `e r = r ∘ σ` induced by the wire permutation `σ`. + let e : (Fin (n + 1) → Fin 2) ≃ (Fin (n + 1) → Fin 2) := + { toFun := fun r j => r (σ j) + invFun := fun r j => r (σ.symm j) + left_inv := fun r => by funext j; simp + right_inv := fun r => by funext j; simp } + -- Each terminal-measurement operator is the rank-one projector onto its tower basis vector, via + -- the measurement's faithfulness to the register computational-basis measurement. + have hMop : ∀ b : Fin (n + 1) → Fin 2, + (qtowerMeasurement n).op b = rankOne ℂ (towerKet n b).vec (towerKet n b).vec := by + intro b + have hvec : (quditPowTower n).toIsometry (quditBasis (towerMeasurementOutcomeEquiv n b)).vec + = (towerKet n b).vec := by + rw [← PureState.congr_vec, + show towerMeasurementOutcomeEquiv n b = finFunctionFinEquiv (fun j => b j.rev) from rfl, + quditPowTower_congr_quditBasis_rev] + rw [qtowerMeasurement_eq_congr_quditMeasurement, Measurement.reindexOutcome_op, + Measurement.congr_op, quditMeasurement_op, InnerProductSpace.rankOne_conjStarAlgEquiv, hvec] + -- The permutation gate on a tower basis vector: `qtowerPermWires σ |b⟩ = |b ∘ σ⁻¹⟩`. + have hVvec : ∀ b : Fin (n + 1) → Fin 2, + (Evolution.qtowerPermWires σ).op (towerKet n b).vec + = (towerKet n (fun i => b (σ.symm i))).vec := by + intro b + rw [← Evolution.evolvePure_vec, qtowerPermWires_evolvePure_towerKet] + -- The reindexing commutation `Mᵢ V = V M_{e i}` the engine consumes. + have hcomm : ∀ i : Fin (n + 1) → Fin 2, + ((qtowerMeasurement n).op i).comp (Evolution.qtowerPermWires σ).op + = (Evolution.qtowerPermWires σ).op.comp ((qtowerMeasurement n).op (fun j => i (σ j))) := by + intro i + rw [hMop i, hMop (fun j => i (σ j))] + have hconj : rankOne ℂ (towerKet n i).vec (towerKet n i).vec + = (Evolution.qtowerPermWires σ).op.comp + ((rankOne ℂ (towerKet n (fun j => i (σ j))).vec + (towerKet n (fun j => i (σ j))).vec).comp + (adjoint (Evolution.qtowerPermWires σ).op)) := by + rw [ContinuousLinearMap.comp_rankOne_self_comp_adjoint, hVvec (fun j => i (σ j))] + simp only [Equiv.apply_symm_apply] + rw [hconj] + simp only [ContinuousLinearMap.comp_assoc, + (Evolution.qtowerPermWires σ).adjoint_comp_self] + rw [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id] + refine ⟨fun ρ r => ?_, fun ρ r hp hp' => ?_⟩ + · exact Measurement.bornProb_evolve_of_reindex_comm (qtowerMeasurement n) + (Evolution.qtowerPermWires σ) (fun _ => Evolution.qtowerPermWires σ) e hcomm ρ r + · exact Measurement.postMeasurement_evolve_of_reindex_comm (qtowerMeasurement n) + (Evolution.qtowerPermWires σ) (fun _ => Evolution.qtowerPermWires σ) e hcomm ρ r hp + +/-- **Problem 5.2 (the swap network is invisible to the terminal statistics).** Measuring every wire +of the tower (`qtowerMeasurement n`) after the wire-permutation gate `Evolution.qtowerPermWires σ` +gives, for every outcome bit-string `r`, the Born probability of the *relabelled* outcome `r ∘ σ` on +the input `ρ`: + + `p(r ∣ (qtowerPermWires σ) ρ (qtowerPermWires σ)†) = p(r ∘ σ ∣ ρ)`. + +The permutation only relabels which wire carries which measured bit — a classical relabelling of the +outcome, no two-qubit gate. -/ +theorem qtowerPermWires_measure_bornProb (σ : Equiv.Perm (Fin (n + 1))) + (ρ : State (qtower n qubit)) (r : Fin (n + 1) → Fin 2) : + (qtowerMeasurement n).bornProb ((Evolution.qtowerPermWires σ).evolve ρ) r + = (qtowerMeasurement n).bornProb ρ (fun j => r (σ j)) := + (qtowerPermWires_measure_defers σ).1 ρ r + +/-- **Problem 5.2 (the terminal measurement defers the swap network).** The state after applying the +wire-permutation gate `Evolution.qtowerPermWires σ` and *then* measuring every wire, at outcome `r`, +equals the permutation applied to the state obtained by measuring the *relabelled* outcome `r ∘ σ` +first: + + `postMeas(σ·ρ·σ†, r) = σ · postMeas(ρ, r ∘ σ)` (`σ = qtowerPermWires σ`). + +On the collapsed computational-basis state the permutation is a pure wire relabelling; the swap +network at the end of the quantum Fourier transform (Figure 5.1) has become a relabelling of the +classical measurement record. -/ +theorem qtowerPermWires_measure_postMeasurement (σ : Equiv.Perm (Fin (n + 1))) + (ρ : State (qtower n qubit)) (r : Fin (n + 1) → Fin 2) + (hp : (qtowerMeasurement n).bornProb ρ (fun j => r (σ j)) ≠ 0) : + (qtowerMeasurement n).postMeasurement ((Evolution.qtowerPermWires σ).evolve ρ) r + (by rw [qtowerPermWires_measure_bornProb]; exact hp) + = (Evolution.qtowerPermWires σ).evolve + ((qtowerMeasurement n).postMeasurement ρ (fun j => r (σ j)) hp) := + (qtowerPermWires_measure_defers σ).2 ρ r hp (by rw [qtowerPermWires_measure_bornProb]; exact hp) + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerPhaseGradient.lean b/LeanPool/AxQM/Core/QtowerPhaseGradient.lean new file mode 100644 index 0000000000..9a7acb6472 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerPhaseGradient.lean @@ -0,0 +1,190 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerHadamardLayer +public import LeanPool.AxQM.Postulates.API.PhasedPlus +public import LeanPool.AxQM.Postulates.API.KitaevPhaseEstimation + +/-! +# The phase-gradient superposition (N&C §5.2, Figure 5.2) — the output of the controlled powers + +The second stage of the phase-estimation circuit (N&C Figure 5.2) is the sequence of controlled +powers `seqCtrlPow U t`. Run on the equal superposition `|+⟩^{⊗t} ⊗ |u⟩` produced by the Hadamard +layer (`AxQM/Core/QtowerHadamardLayer.lean`), when `|u⟩` is an **eigenstate** `U|u⟩ = e^{iθ}|u⟩` +it produces the **phase gradient**: each control wire `w` (of weight `2^w`) picks up the phase +`e^{i·2^w·θ}` on its `|1⟩` branch, so the register becomes the product of phased-plus states + + `⊗_w (|0⟩ + e^{i·2^w·θ}|1⟩)/√2 ⊗ |u⟩ = (1/√2ᵗ) ∑_b e^{iθ·⟦b⟧} |b⟩ ⊗ |u⟩`, + +the linear-in-`⟦b⟧` phase that the final inverse QFT reads off as the eigenphase `θ/2π`. This is the +"before inverse QFT" state of phase estimation. + +## What is formalised + +* `qtowerPhaseGrad θ t u` — the **phase-gradient register** `⊗_w |+_{2^w·θ}⟩ ⊗ |u⟩` on `qtower t S`: + each control wire in the phased-plus state `qubitPhasePlus (2^w·θ)` (outermost wire the most + significant, weight `2^t`), tensored with the target `u`. Built through `PureState.tmul` from the + phased-plus combinator, so its normalization is inherited. +* `controlledUnitary_evolvePure_qubitPlus_hasEigenstate` — the **single-wire phase kickback**: + if `V|ψ⟩ = e^{iθ}|ψ⟩` then `C(V)(|+⟩ ⊗ |ψ⟩) = |+_θ⟩ ⊗ |ψ⟩` — a controlled gate on a `|+⟩` control + and an eigenstate target moves the eigenphase onto the control, turning `|+⟩` into `|+_θ⟩` and + leaving `|ψ⟩` untouched. The atomic step of phase estimation. +* `unCtrl_hasEigenstate_qtowerPhaseGrad` — the **reach-through**: the idle wrap `unCtrl t V` has the + gradient `qtowerPhaseGrad θ t u` as an eigenstate with the same eigenvalue `V` has on `u`, because + `unCtrl` acts only on the innermost target `u`. +* `seqCtrlPow_hasEigenstate_qtowerPlusKet` — **the gradient action:** for an eigenstate input + `U|u⟩ = e^{iθ}|u⟩`, `seqCtrlPow U t (|+⟩^{⊗t} ⊗ |u⟩) = qtowerPhaseGrad θ t u`. Induction on the + number of controls, peeling the outermost wire: the inner sequence gives the `t`-wire gradient + (inductive hypothesis), through which the outermost controlled `U^{2^t}` reaches the target + eigenstate (eigenvalue `e^{i·2^t·θ}` by `HasEigenstate.pow`) and kicks the phase back onto the + outer `|+⟩` (`controlledUnitary_evolvePure_qubitPlus_hasEigenstate`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The phase-gradient register -/ + +/-- **The phase-gradient register** `⊗_w |+_{2^w·θ}⟩ ⊗ |u⟩` on `qtower t S`: each of the `t` control +wires in the phased-plus state `qubitPhasePlus (2^w·θ)` (the outermost wire most significant, weight +`2^t`), tensored with the target pure state `u`. The output of the controlled-power sequence on the +prepared superposition when the target is an eigenstate of eigenphase `θ`; built through +`PureState.tmul` so its normalization is inherited. -/ +def qtowerPhaseGrad (θ : ℝ) : (t : ℕ) → PureState S → PureState (qtower t S) + | 0, u => u + | (t + 1), u => qubitPhasePlus ((2 : ℝ) ^ t * θ) ⊗ qtowerPhaseGrad θ t u + +@[simp] theorem qtowerPhaseGrad_zero (θ : ℝ) (u : PureState S) : qtowerPhaseGrad θ 0 u = u := rfl + +/-- Peeling the outermost wire of the phase-gradient register: +`qtowerPhaseGrad θ (t+1) u = |+_{2^t·θ}⟩ ⊗ qtowerPhaseGrad θ t u`. -/ +theorem qtowerPhaseGrad_succ (θ : ℝ) (t : ℕ) (u : PureState S) : + qtowerPhaseGrad θ (t + 1) u = qubitPhasePlus ((2 : ℝ) ^ t * θ) ⊗ qtowerPhaseGrad θ t u := rfl + +/-! ### The single-wire phase kickback -/ + +/-- **Single-wire phase kickback.** If `|ψ⟩` is an eigenstate of `V` with eigenvalue `e^{iθ}` +(`V.HasEigenstate (e^{iθ}) ψ`), then the controlled gate `C(V)` on a `|+⟩` control and target `|ψ⟩` +moves the eigenphase onto the control, turning `|+⟩` into the phased-plus state `|+_θ⟩` and leaving +`|ψ⟩` unchanged: `C(V)(|+⟩ ⊗ |ψ⟩) = |+_θ⟩ ⊗ |ψ⟩`. + +The atomic step of phase estimation. Proof at the vector level: unfold `C(V)` to its block operator +`|0⟩⟨0|⊗1 + |1⟩⟨1|⊗V` and apply it to `|+⟩ ⊗ |ψ⟩`; the two rank-one projectors reduce against `|+⟩` +(`⟨i|+⟩ = 1/√2`, `inner_qubitBasis_qubitPlus`) and the `|1⟩` branch turns `V|ψ⟩` into `e^{iθ}|ψ⟩` +(the eigenvalue hypothesis), leaving `(1/√2)(|0⟩ + e^{iθ}|1⟩) ⊗ |ψ⟩ = |+_θ⟩ ⊗ |ψ⟩` +(`qubitPhasePlus_vec`) — the residual qubit-factor amplitude identity closing by `module`. -/ +theorem controlledUnitary_evolvePure_qubitPlus_hasEigenstate (V : Evolution S) (θ : ℝ) + (ψ : PureState S) (h : V.HasEigenstate (Complex.exp ((θ : ℂ) * Complex.I)) ψ) : + (controlledUnitary V).evolvePure (qubitPlus ⊗ ψ) = qubitPhasePlus θ ⊗ ψ := by + apply PureState.ext + rw [Evolution.evolvePure_vec, PureState.tmul_vec, PureState.tmul_vec, qubitPhasePlus_vec] + -- Unfold the controlled gate to its block operator `|0⟩⟨0|⊗1 + |1⟩⟨1|⊗V`, apply it to the + -- product, and reduce the two rank-one projectors against `|+⟩` (`⟨i|+⟩ = 1/√2`). Every scalar + -- stays on the qubit factor, so the residual amplitude identity closes by `module`. + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) V.op) + (qubitPlus.vec ⊗ₜ[ℂ] ψ.vec) = _ + rw [add_apply, TensorProduct.mapL_tmul, TensorProduct.mapL_tmul, + InnerProductSpace.rankOne_apply, InnerProductSpace.rankOne_apply, one_apply_eq_self, + inner_qubitBasis_qubitPlus, inner_qubitBasis_qubitPlus, Concrete.xPlus_apply, + Concrete.xPlus_apply, show V.op ψ.vec = Complex.exp ((θ : ℂ) * Complex.I) • ψ.vec from h, + ← TensorProduct.smul_tmul, ← TensorProduct.add_tmul] + congr 1 + module + +/-! ### Reaching through the controls to the target -/ + +/-- **The idle wrap reaches through to the target of the phase gradient.** `unCtrl t V` (`V` +wrapped by `t` idle control qubits) leaves the gradient's `t` phased-plus control factors untouched +and applies `V` to the innermost target: `(unCtrl t V)(qtowerPhaseGrad θ t u) = qtowerPhaseGrad θ t +(V|u⟩)`. Induction on the number of controls, peeling one idle wire +(`Evolution.onRight_evolvePure`). +The arbitrary-target analogue of `unCtrl_evolvePure_qtowerKet`. -/ +theorem unCtrl_evolvePure_qtowerPhaseGrad (V : Evolution S) (θ : ℝ) : + ∀ (t : ℕ) (u : PureState S), + (unCtrl t V).evolvePure (qtowerPhaseGrad θ t u) = qtowerPhaseGrad θ t (V.evolvePure u) + | 0, _ => rfl + | (t + 1), u => by + simp only [qtower, unCtrl_succ, qtowerPhaseGrad_succ, Evolution.onRight_evolvePure, + unCtrl_evolvePure_qtowerPhaseGrad V θ t u] + +/-- **The idle wrap has the phase gradient as an eigenstate.** If `V|u⟩ = μ|u⟩` then the idle wrap +`unCtrl t V` has the phase-gradient register `qtowerPhaseGrad θ t u` as an eigenstate with the +*same* +eigenvalue `μ`: `unCtrl` reaches through the `t` control wires to the innermost target `u` +(`unCtrl_evolvePure_qtowerPhaseGrad`), and `qtowerPhaseGrad` is linear in the target's global phase +(the `vecscale` induction, `|+_·⟩^{⊗t} ⊗ (c • u) = c • (|+_·⟩^{⊗t} ⊗ u)`), so the eigenphase `μ` +factors out. -/ +theorem unCtrl_hasEigenstate_qtowerPhaseGrad (V : Evolution S) {μ : ℂ} {u : PureState S} + (h : V.HasEigenstate μ u) (θ : ℝ) (t : ℕ) : + (unCtrl t V).HasEigenstate μ (qtowerPhaseGrad θ t u) := by + have vecscale : ∀ (c : ℂ) (v w : PureState S), w.vec = c • v.vec → + ∀ s : ℕ, (qtowerPhaseGrad θ s w).vec = c • (qtowerPhaseGrad θ s v).vec := by + intro c v w hvw s + induction s with + | zero => exact hvw + | succ s ih => + rw [qtowerPhaseGrad_succ, qtowerPhaseGrad_succ, PureState.tmul_vec, PureState.tmul_vec, ih] + exact TensorProduct.tmul_smul _ _ _ + rw [Evolution.HasEigenstate, ← Evolution.evolvePure_vec, unCtrl_evolvePure_qtowerPhaseGrad] + have hVu : (V.evolvePure u).vec = μ • u.vec := by rw [Evolution.evolvePure_vec]; exact h + exact vecscale μ u (V.evolvePure u) hVu t + +/-! ### The gradient action of the controlled-power sequence -/ + +/-- **The controlled powers produce the phase gradient.** For an eigenstate input +`U|u⟩ = e^{iθ}|u⟩` (`U.HasEigenstate (e^{iθ}) u`), the controlled-power sequence `seqCtrlPow U t` +(N&C Figure 5.2, second stage) takes the prepared equal superposition `|+⟩^{⊗t} ⊗ |u⟩` +(`qtowerPlusKet t u`) to the phase-gradient register `⊗_w |+_{2^w·θ}⟩ ⊗ |u⟩` +(`qtowerPhaseGrad θ t u`): +`seqCtrlPow U t (|+⟩^{⊗t} ⊗ |u⟩) = qtowerPhaseGrad θ t u`. + +Each control wire `w` ends in the phased-plus state carrying the eigenphase `2^w·θ` scaled by its +weight — the linear-in-control-value phase gradient the final inverse QFT reads out. + +Induction on the number of controls `t`, peeling the outermost wire (`seqCtrlPow_succ`, +`qtowerPlusKet_succ`): the inner sequence produces the `t`-wire gradient +`qtowerPhaseGrad θ t u` (inductive hypothesis, through `Evolution.onRight_evolvePure`), which is an +eigenstate of the outermost controlled `U^{2^t}` with eigenvalue `(e^{iθ})^{2^t} = e^{i·2^t·θ}` +(`unCtrl_hasEigenstate_qtowerPhaseGrad` on `Evolution.HasEigenstate.pow`); the single-wire kickback +`controlledUnitary_evolvePure_qubitPlus_hasEigenstate` then turns the outer `|+⟩` into +`|+_{2^t·θ}⟩`, +building `qtowerPhaseGrad θ (t+1) u`. -/ +theorem seqCtrlPow_hasEigenstate_qtowerPlusKet (U : Evolution S) (θ : ℝ) (u : PureState S) + (h : U.HasEigenstate (Complex.exp ((θ : ℂ) * Complex.I)) u) : + ∀ t : ℕ, (seqCtrlPow U t).evolvePure (qtowerPlusKet t u) = qtowerPhaseGrad θ t u + | 0 => by + simp only [seqCtrlPow_zero, qtowerPlusKet_zero, qtowerPhaseGrad_zero] + exact Evolution.id_evolvePure u + | (t + 1) => by + have ih := seqCtrlPow_hasEigenstate_qtowerPlusKet U θ u h t + simp only [qtower, seqCtrlPow_succ, qtowerPlusKet_succ, Evolution.evolvePure_comp, + Evolution.onRight_evolvePure, ih, qtowerPhaseGrad_succ] + apply controlledUnitary_evolvePure_qubitPlus_hasEigenstate + have hpow : (U ^ 2 ^ t).HasEigenstate ((Complex.exp ((θ : ℂ) * Complex.I)) ^ 2 ^ t) u := + Evolution.HasEigenstate.pow h (2 ^ t) + have hexp : (Complex.exp ((θ : ℂ) * Complex.I)) ^ 2 ^ t + = Complex.exp (((((2 : ℝ) ^ t * θ) : ℝ) : ℂ) * Complex.I) := by + rw [← Complex.exp_nat_mul] + congr 1 + push_cast + ring + rw [hexp] at hpow + exact unCtrl_hasEigenstate_qtowerPhaseGrad (U ^ 2 ^ t) hpow θ t + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerSingleWireGate.lean b/LeanPool/AxQM/Core/QtowerSingleWireGate.lean new file mode 100644 index 0000000000..32bda7b662 --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerSingleWireGate.lean @@ -0,0 +1,244 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledNotBasis +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary + +/-! +# Placing a single-qubit gate on one wire of the control tower (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` (the register bridge `quditPowTower`). Its +gates come in three shapes: the swap layer (a *wire permutation*, already placed on the tower as +`Evolution.qtowerPermWires`), the controlled-`Rₖ` rotations (two-wire), and the **Hadamards** — each +a single-qubit gate acting on *one wire*. This file defines the wire-addressed placement of a +single-qubit gate on the tower, the direct sibling of `Evolution.qtowerPermWires`, with its +computational-basis action. + +## What is formalised + +* `towerProd n ψ` — the **product state** `ψ 0 ⊗ ψ 1 ⊗ ⋯ ⊗ ψ n` on `qtower n qubit` built from an + arbitrary family of single-wire pure states `ψ : Fin (n+1) → PureState qubit`. The + arbitrary-per-wire generalisation of the computational tower basis `towerKet` (`towerKet` is the + special case `ψ i = |b i⟩`, `towerKet_eq_towerProd`); it is needed because a single-wire gate can + send a basis wire to a *superposition* (a Hadamard does), so the output is a product state whose + wires are no longer all basis states. +* `Evolution.qtowerSingleWire n i g` — the **single-wire gate**: the single-qubit `Evolution` `g` + placed on wire `i` of `qtower n qubit`, the identity on every other wire. Defined by recursion on + the tower: on the head wire (`i = 0`) it is `g.onLeft` (`g ⊗ 1`), and on a later wire (`i = i'+1`) + it wraps the placement on the tail with an idle head, `(qtowerSingleWire i' g).onRight qubit` + (`1 ⊗ ⋯`) — the peel `qtower (n+1) qubit = qubit ⊗ qtower n qubit` that `towerKet` and + `mcCtrl` are built on. +* `qtowerSingleWire_evolvePure_towerProd` — the **action**: `qtowerSingleWire n i g` acts on a + product state `towerProd n ψ` by updating exactly wire `i`, `ψ ↦ Function.update ψ i (g ψᵢ)`, + leaving every other wire untouched. Proved by recursion on the tower, peeling the head with + `Evolution.onLeft_evolvePure` / `Evolution.onRight_evolvePure` and matching the update against + `Fin.tail_update_zero` / `Fin.tail_update_succ` — the analog of `unCtrl_evolvePure_qtowerKet`. +* `qtowerSingleWire_evolvePure_towerKet` — the specialisation to a **computational-basis** input: + `qtowerSingleWire n i g` sends `towerKet n b` to the product state that is `|b j⟩` on every wire + `j ≠ i` and `g |b i⟩` on wire `i`. This is the form the wire-addressed re-expression of the + Figure 5.1 Hadamards (read on the tower through the bridge) is matched against. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### The product state on the tower -/ + +/-- **The product state** `ψ 0 ⊗ ψ 1 ⊗ ⋯ ⊗ ψ n` on `qtower n qubit`, built from an arbitrary family +`ψ : Fin (n+1) → PureState qubit` of single-wire pure states (`ψ 0` the outermost / head wire). The +arbitrary-per-wire generalisation of the computational tower basis `towerKet` (recovered as the +special case `ψ i = |b i⟩`, `towerKet_eq_towerProd`); it is what a single-wire gate produces, since +that gate may send a basis wire to a superposition. -/ +def towerProd : (n : ℕ) → (Fin (n + 1) → PureState qubit) → PureState (qtower n qubit) + | 0, ψ => ψ 0 + | n + 1, ψ => (ψ 0) ⊗ towerProd n (Fin.tail ψ) + +/-- Base unfolding of `towerProd`: a single-wire tower is the pure state of its one wire. -/ +@[simp] theorem towerProd_zero (ψ : Fin 1 → PureState qubit) : towerProd 0 ψ = ψ 0 := rfl + +/-- Step unfolding of `towerProd`: peel the head wire as a left tensor factor, +`towerProd (n+1) ψ = ψ 0 ⊗ towerProd n (Fin.tail ψ)`. -/ +theorem towerProd_succ (n : ℕ) (ψ : Fin (n + 2) → PureState qubit) : + towerProd (n + 1) ψ = (ψ 0) ⊗ towerProd n (Fin.tail ψ) := rfl + +/-- **The `towerProd` constructor.** The right-nested tower product state of `Fin.cons x φ` splits +off its head factor: `towerProd (n+1) (Fin.cons x φ) = x ⊗ towerProd n φ`. The constructor companion +of the destructor `towerProd_succ`, packaging a head-plus-tail tensor back into a single tower +product. -/ +theorem towerProd_cons (n : ℕ) (x : PureState qubit) (φ : Fin (n + 1) → PureState qubit) : + towerProd (n + 1) (Fin.cons x φ) = x.tmul (towerProd n φ) := by + rw [towerProd_succ, Fin.cons_zero, Fin.tail_cons] + +/-- **The computational tower basis is the product of its basis wires.** `towerKet n b` is the +product state `towerProd n` of the single-wire computational-basis states `|b j⟩`: both peel the +head wire the same way, so this holds by induction on `n`. This exhibits `towerKet` as the +basis-input special case of `towerProd`, the bridge the single-wire gate action uses to specialise +from an arbitrary product input to a computational-basis one. -/ +theorem towerKet_eq_towerProd (n : ℕ) (b : Fin (n + 1) → Fin 2) : + towerKet n b = towerProd n (fun j => qubitBasis (b j)) := by + induction n with + | zero => rfl + | succ n ih => rw [towerKet_succ, towerProd_succ, ih]; rfl + +/-- **Updating one basis wire commutes with `towerKet`.** Replacing wire `t.rev` of the +basis-wire family `fun j => |b j⟩` by `|z⟩` gives the tower product of the bit-string `b` updated at +`t.rev`: +`towerProd n (Function.update (fun j => |b j⟩) t.rev |z⟩) = towerKet n (Function.update b t.rev z)`. +Both sides are the product of the same per-wire basis kets (`towerKet_eq_towerProd` then a pointwise +`Function.update` comparison). The shared ket-bookkeeping step every non-diagonal single-wire gate's +tower re-expression (`AxQM/Core/QftTowerHadamard.lean`, +`AxQM/Core/FourGateReachableWireTower.lean`, `AxQM/Core/PauliDiagWireTower.lean`) uses to name the +updated branch ket. -/ +theorem towerProd_update_qubitBasis {n : ℕ} (b : Fin (n + 1) → Fin 2) (t : Fin (n + 1)) + (z : Fin 2) : + towerProd n (Function.update (fun j => qubitBasis (b j)) t.rev (qubitBasis z)) + = towerKet n (Function.update b t.rev z) := by + rw [towerKet_eq_towerProd] + congr 1 + funext j + rcases eq_or_ne j t.rev with rfl | hj + · rw [Function.update_self, Function.update_self] + · rw [Function.update_of_ne hj, Function.update_of_ne hj] + +/-- **The reversed, wire-`t`-updated digit-string is the wire-`t.rev`-updated string.** +`(fun i => Function.update (fun i' => b i'.rev) t z i.rev) = Function.update b t.rev z` — the +`Fin.rev` bookkeeping that aligns the big-endian register bridge with the little-endian wire +indexing when a single wire is updated. Off wire `t.rev` both sides restrict to `b ∘ Fin.rev ∘ rev = +b` (`Fin.rev_rev`); at wire `t.rev` both are `z`. Shared by every single-wire gate's tower +re-expression. -/ +theorem update_rev_eq {n : ℕ} (b : Fin (n + 1) → Fin 2) (t : Fin (n + 1)) (z : Fin 2) : + (fun i => Function.update (fun i' => b i'.rev) t z i.rev) = Function.update b t.rev z := by + funext i + rcases eq_or_ne i t.rev with rfl | hi + · rw [Fin.rev_rev, Function.update_self, Function.update_self] + · have hi' : i.rev ≠ t := fun h => hi (by rw [← h, Fin.rev_rev]) + rw [Function.update_of_ne hi', Function.update_of_ne hi, Fin.rev_rev] + +/-! ### The single-wire gate on the tower -/ + +/-- **A single-qubit gate placed on one wire of the control tower** `qtower n qubit`: the gate `g` +acts on wire `i`, the identity on every other wire. Defined by recursion on the tower — on the head +wire (`i = 0`) it is `g.onLeft (qtower n qubit)` (`g ⊗ 1`), and on a later wire (`i = i'+1`) it +wraps the placement on the tail with an idle head, +`(Evolution.qtowerSingleWire n i' g).onRight qubit` +(`1 ⊗ ⋯`). The wire-addressed placement of a one-qubit gate on the tower — the shape of the +Figure 5.1 Hadamards — the single-gate sibling of the wire-permutation gate +`Evolution.qtowerPermWires`; its basis action is `qtowerSingleWire_evolvePure_towerKet`. -/ +def Evolution.qtowerSingleWire : + (n : ℕ) → Fin (n + 1) → Evolution qubit → Evolution (qtower n qubit) + | 0, _, g => g + | n + 1, i, g => + Fin.cases (g.onLeft (qtower n qubit)) + (fun i' => (Evolution.qtowerSingleWire n i' g).onRight qubit) i + +/-- Head-wire unfolding: on wire `0` the single-wire gate is `g` on the head factor, +`g.onLeft (qtower n qubit) = g ⊗ 1`. -/ +theorem Evolution.qtowerSingleWire_zero (n : ℕ) (g : Evolution qubit) : + Evolution.qtowerSingleWire (n + 1) 0 g = g.onLeft (qtower n qubit) := by + rfl + +/-- Later-wire unfolding: on wire `i'+1` the single-wire gate wraps the tail placement with an idle +head, `(Evolution.qtowerSingleWire n i' g).onRight qubit = 1 ⊗ ⋯`. -/ +theorem Evolution.qtowerSingleWire_succ (n : ℕ) (i' : Fin (n + 1)) (g : Evolution qubit) : + Evolution.qtowerSingleWire (n + 1) i'.succ g + = (Evolution.qtowerSingleWire n i' g).onRight qubit := by + rfl + +/-- **The single-wire placement of the identity gate is the identity.** Placing the identity gate on +any wire `i` of the tower leaves every wire — including `i` — untouched, so +`qtowerSingleWire n i 1 = 1`. By recursion on the tower: the head wire (`i = 0`) is +`Evolution.id_onLeft`, a later wire (`i = i'+1`) reduces to the tail placement (induction +hypothesis) with an idle head, `Evolution.id_onRight`. Together with +`Evolution.qtowerSingleWire_comp` this exhibits `qtowerSingleWire n i` as a monoid homomorphism +in the placed gate (identity to identity, composition to composition). -/ +theorem Evolution.qtowerSingleWire_id : + ∀ (n : ℕ) (i : Fin (n + 1)), + Evolution.qtowerSingleWire n i Evolution.id = Evolution.id + | 0, _ => rfl + | n + 1, i => by + refine Fin.cases ?_ (fun i' => ?_) i + · rw [Evolution.qtowerSingleWire_zero] + exact Evolution.id_onLeft _ _ + · rw [Evolution.qtowerSingleWire_succ, Evolution.qtowerSingleWire_id n i'] + exact Evolution.id_onRight _ _ + +/-- **The single-wire placement respects composition.** Placing a composite gate `g · h` on wire `i` +is the composite of the individual placements: `qtowerSingleWire n i (g · h) = +(qtowerSingleWire n i g) · (qtowerSingleWire n i h)` — the placement touches only wire `i`, so the +two factors act on that wire in sequence and idly elsewhere. By recursion on the tower, from +`Evolution.onLeft_comp` (head wire) and `Evolution.onRight_comp` (later wire); together with +`Evolution.qtowerSingleWire_id` this makes `qtowerSingleWire n i` a monoid homomorphism in the +placed gate. -/ +theorem Evolution.qtowerSingleWire_comp : + ∀ (n : ℕ) (i : Fin (n + 1)) (g h : Evolution qubit), + Evolution.qtowerSingleWire n i (g.comp h) + = (Evolution.qtowerSingleWire n i g).comp (Evolution.qtowerSingleWire n i h) + | 0, _, _, _ => rfl + | n + 1, i, g, h => by + refine Fin.cases ?_ (fun i' => ?_) i + · rw [Evolution.qtowerSingleWire_zero, Evolution.qtowerSingleWire_zero, + Evolution.qtowerSingleWire_zero] + exact (Evolution.onLeft_comp _ _ g h).symm + · rw [Evolution.qtowerSingleWire_succ, Evolution.qtowerSingleWire_succ, + Evolution.qtowerSingleWire_succ, Evolution.qtowerSingleWire_comp n i' g h] + exact (Evolution.onRight_comp _ _ _ _).symm + +/-- **Computational action of the single-wire gate on a product input.** Placing `g` on wire `i` +acts on the product state `towerProd n ψ` by updating exactly that wire and leaving the rest fixed: + + `(qtowerSingleWire n i g) (ψ 0 ⊗ ⋯ ⊗ ψ n) = ψ 0 ⊗ ⋯ ⊗ (g ψᵢ) ⊗ ⋯ ⊗ ψ n`, + +i.e. `towerProd n (Function.update ψ i (g.evolvePure (ψ i)))`. Proved by recursion on the tower: the +head wire is peeled with `Evolution.onLeft_evolvePure` (`i = 0`, `Fin.tail_update_zero`) or +`Evolution.onRight_evolvePure` (`i = i'+1`, `Fin.tail_update_succ`), the analog of +`unCtrl_evolvePure_qtowerKet`. This is the wire-locality of the placement: it touches only wire `i`. +-/ +theorem qtowerSingleWire_evolvePure_towerProd : + ∀ (n : ℕ) (i : Fin (n + 1)) (g : Evolution qubit) (ψ : Fin (n + 1) → PureState qubit), + (Evolution.qtowerSingleWire n i g).evolvePure (towerProd n ψ) + = towerProd n (Function.update ψ i (g.evolvePure (ψ i))) + | 0, i, g, ψ => by + obtain rfl := Fin.fin_one_eq_zero i + simp only [qtower, Evolution.qtowerSingleWire, towerProd_zero, Function.update_self] + | n + 1, i, g, ψ => by + refine Fin.cases ?_ ?_ i + · simp only [qtower, Evolution.qtowerSingleWire_zero, towerProd_succ, + Evolution.onLeft_evolvePure, Function.update_self, Fin.tail_update_zero] + · intro i' + simp only [qtower, Evolution.qtowerSingleWire_succ, towerProd_succ, + Evolution.onRight_evolvePure, + qtowerSingleWire_evolvePure_towerProd n i' g (Fin.tail ψ), + Function.update_of_ne (Fin.succ_ne_zero i').symm, Fin.tail_update_succ] + rfl + +/-- **Computational action of the single-wire gate on a basis input.** Placing `g` on wire `i` sends +the computational tower basis state `towerKet n b` to the product state that is `|b j⟩` on every +wire `j ≠ i` and `g |b i⟩` on wire `i`: + + `(qtowerSingleWire n i g) (towerKet n b) + = towerProd n (Function.update (fun j => |b j⟩) i (g |b i⟩))`. + +The specialisation of `qtowerSingleWire_evolvePure_towerProd` to a basis input via +`towerKet_eq_towerProd`. This is the form the Figure 5.1 Hadamards — read on the tower through the +register bridge — are re-expressed against. -/ +theorem qtowerSingleWire_evolvePure_towerKet (n : ℕ) (i : Fin (n + 1)) (g : Evolution qubit) + (b : Fin (n + 1) → Fin 2) : + (Evolution.qtowerSingleWire n i g).evolvePure (towerKet n b) + = towerProd n (Function.update (fun j => qubitBasis (b j)) i + (g.evolvePure (qubitBasis (b i)))) := by + rw [towerKet_eq_towerProd, qtowerSingleWire_evolvePure_towerProd] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerTensorPow.lean b/LeanPool/AxQM/Core/QtowerTensorPow.lean new file mode 100644 index 0000000000..710000811d --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerTensorPow.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledNotBasis +public import LeanPool.AxQM.Postulates.API.TensorPowSplit +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.PiTensorState + +/-! +# The `qtower ↔ tensor-power` structural bridge (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit implementing +`Cⁿ(X)`. The grounded `Cⁿ(X) = mcCtrl n pauliXGate` lives on the **right-nested** control +tower `qtower n qubit = qubit ⊗ (qubit ⊗ (⋯ ⊗ qubit))` +(`AxQM/Core/MultiControlledReduction.lean`), while the `SWAP`-network wire-permutation gate +`Evolution.permWires` — the gate for placing a `Toffoli`/`CNOT` on *non-contiguous* wires — lives on +the **symmetric** register `qubit ^⊗ₛ (n+1)` (the `n+1`-fold `PiTensorProduct`, +`AxQM/Postulates/API/WirePermutation.lean`). Transporting a wire permutation onto the grounded gate +therefore needs a structural isomorphism connecting the two registers. + +## What is formalised + +* `qtowerQubitTensorPow n` — the **bridge** `qtower n qubit ≃ₛ qubit ^⊗ₛ (n+1)`, built by induction + on `n`: the base `qtower 0 qubit = qubit ≃ₛ qubit ^⊗ₛ 1` is `QSystem.tensorPowOne`, and each step + reassociates the peeled head control through `QSystem.tensorPowSuccHead` after applying + the isomorphism to the `n`-fold tail (`QSystem.Iso.tmul` with the identity on the head qubit). +* `qtowerQubitTensorPow_congr_towerKet` — the **basis correspondence**: the bridge carries the + `(n+1)`-qubit computational tower basis state `towerKet n b` to the symmetric product basis state + `⨂ᵢ |b i⟩` (`PureState.piTensor fun i => qubitBasis (b i)`). This is what lets the effect of a + wire-addressed gate on a basis input — read off on `qubit ^⊗ₛ (n+1)` via + `Evolution.permWires_op_tprod` — be pulled back to the grounded `qtower` register. +* `qtowerQubitTensorPow_symm_congr_piTensor` — the **backward** basis correspondence: the inverse + bridge carries `⨂ᵢ |b i⟩` back to `towerKet n b`, the `.symm` companion of the previous lemma (via + the `PureState.congr` roundtrip). This is the placement-dictionary direction consumed when a gate + computed on the symmetric register is transported onto the grounded `qtower`. + +## Design notes + +* **The pieces on the symmetric side.** `Evolution.permWires` (the wire permutation as an + `Evolution`) and `QSystem.tensorPowSuccHead` (the head-peel `S ^⊗ₛ (n+1) ≃ₛ S ⊗ S ^⊗ₛ n`) are + assembled here into the qtower-specific bridge and its basis dictionary, which lets the wire + permutation be transported onto `qtower n qubit` (`Evolution.congr`) for the `Cᵏ(X)`-block + `Toffoli` reduction. +* **Why the recursion matches definitionally.** `qtower (n+1) qubit = qubit ⊗ qtower n qubit` + *definitionally* (peeling the outer control is the defining equation of `qtower` on its `ℕ` + argument), so the successor isomorphism `(Iso.refl qubit).tmul (bridge n)` — of type + `qubit ⊗ qtower n qubit ≃ₛ qubit ⊗ qubit ^⊗ₛ (n+1)` — type-checks against the expected domain + `qtower (n+1) qubit` with no `cast`. (This is unlike the `qtower m (qubit ⊗ S) = qtower (m+1) S` + rearrangement of Exercise 4.30, which is only *propositional*.) +* **Proof of the basis correspondence.** By `PureState.ext` it reduces to the equation of state + vectors `(bridge n).toIsometry (towerKet n b).vec = ⨂ᵢ (qubitBasis (b i)).vec`, proved by + induction: the step peels the head wire with `PureState.tmul_vec`, applies + `QSystem.Iso.tmul_toIsometry_tmul` and the inductive hypothesis to the tail, then re-cons's the + head with `QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod`, closing with + `Fin.cons_self_tail`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The `qtower ↔ tensor-power` bridge** `qtower n qubit ≃ₛ qubit ^⊗ₛ (n+1)`: the system +isomorphism identifying the right-nested `(n+1)`-qubit control tower `qtower n qubit` with the +symmetric `(n+1)`-fold power `qubit ^⊗ₛ (n+1)`. Built by induction on `n` — the base +`qtower 0 qubit = qubit ≃ₛ qubit ^⊗ₛ 1` is `QSystem.tensorPowOne`, and each successor step tensors +the identity on the head qubit with the tail bridge and reassociates through the head-peel iso +`QSystem.tensorPowSuccHead`. Its action on the computational basis is +`qtowerQubitTensorPow_congr_towerKet`. -/ +def qtowerQubitTensorPow : (n : ℕ) → (qtower n qubit).Iso (qubit ^⊗ₛ (n + 1)) + | 0 => qubit.tensorPowOne + | n + 1 => + ((QSystem.Iso.refl qubit).tmul (qtowerQubitTensorPow n)).trans + (QSystem.tensorPowSuccHead qubit (n + 1)).symm + +/-- Base unfolding of the bridge: the single-qubit tower is the one-factor collapse. -/ +@[simp] theorem qtowerQubitTensorPow_zero : + qtowerQubitTensorPow 0 = qubit.tensorPowOne := rfl + +/-- Step unfolding of the bridge: tensor the identity on the head control with the tail bridge, then +reassociate through the head-peel iso. -/ +theorem qtowerQubitTensorPow_succ (n : ℕ) : + qtowerQubitTensorPow (n + 1) + = ((QSystem.Iso.refl qubit).tmul (qtowerQubitTensorPow n)).trans + (QSystem.tensorPowSuccHead qubit (n + 1)).symm := rfl + +/-- **Basis correspondence for the bridge.** The `qtower ↔ tensor-power` bridge carries the +`(n+1)`-qubit computational tower basis state `towerKet n b` (the right-nested product +`|b 0⟩ ⊗ ⋯ ⊗ |b n⟩` on `qtower n qubit`) to the symmetric product basis state `⨂ᵢ |b i⟩` on +`qubit ^⊗ₛ (n+1)`. This is the dictionary between the two registers' computational bases, so a +gate's action on a basis input computed on `qubit ^⊗ₛ (n+1)` (e.g. a wire permutation via +`Evolution.permWires_op_tprod`) transports to the grounded `qtower` register. -/ +theorem qtowerQubitTensorPow_congr_towerKet (n : ℕ) (b : Fin (n + 1) → Fin 2) : + PureState.congr (qtowerQubitTensorPow n) (towerKet n b) + = PureState.piTensor (fun i => qubitBasis (b i)) := by + -- Reduce to the equation of state vectors and induct there. + -- The `succ` step uses that `qtower (k+1) qubit = qubit ⊗ qtower k qubit` *definitionally*, so a + -- `change` peels the head-wire isometry chain into its two `QSystem.Iso` factors with no `cast`. + suffices key : ∀ (m : ℕ) (c : Fin (m + 1) → Fin 2), + (qtowerQubitTensorPow m).toIsometry (towerKet m c).vec + = ⨂ₜ[ℂ] i, (qubitBasis (c i)).vec by + apply PureState.ext + rw [PureState.congr_vec, PureState.piTensor_vec] + exact key n b + intro m + induction m with + | zero => + intro c + rw [qtowerQubitTensorPow_zero, towerKet_zero] + erw [QSystem.tensorPowOne_toIsometry_apply] + congr 1 + funext i + obtain rfl : i = 0 := Subsingleton.elim i 0 + rfl + | succ k ih => + intro c + rw [towerKet_succ, PureState.tmul_vec] + -- `qtowerQubitTensorPow (k+1)` is definitionally `((refl qubit).tmul (bridge k)).trans + -- (tensorPowSuccHead qubit (k+1)).symm`; apply its two isometry factors in turn. + change (QSystem.tensorPowSuccHead qubit (k + 1)).symm.toIsometry + (((QSystem.Iso.refl qubit).tmul (qtowerQubitTensorPow k)).toIsometry + ((qubitBasis (c 0)).vec ⊗ₜ[ℂ] (towerKet k (fun i => c i.succ)).vec)) + = ⨂ₜ[ℂ] i, (qubitBasis (c i)).vec + rw [QSystem.Iso.tmul_toIsometry_tmul, ih (fun i => c i.succ), + QSystem.Iso.symm_toIsometry, QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod] + congr 1 + funext i + rcases Fin.eq_zero_or_eq_succ i with rfl | ⟨j, rfl⟩ + · rw [Fin.cons_zero] + rfl + · rw [Fin.cons_succ] + +/-- **Backward basis correspondence for the bridge.** The *inverse* bridge +`(qtowerQubitTensorPow n).symm` carries the symmetric product basis state `⨂ᵢ |b i⟩` on +`qubit ^⊗ₛ (n+1)` back to the `(n+1)`-qubit computational tower basis state `towerKet n b` on +`qtower n qubit`. The `.symm` companion of `qtowerQubitTensorPow_congr_towerKet`, obtained from it +by the `PureState.congr` roundtrip cancellation `PureState.congr_symm_congr`. This is the +wire-addressed **placement dictionary** direction: a gate's action on a basis input on the symmetric +register (e.g. a wire permutation) is pulled back to the grounded `qtower` register through it. -/ +theorem qtowerQubitTensorPow_symm_congr_piTensor (n : ℕ) (b : Fin (n + 1) → Fin 2) : + PureState.congr (qtowerQubitTensorPow n).symm (PureState.piTensor fun i => qubitBasis (b i)) + = towerKet n b := by + rw [← qtowerQubitTensorPow_congr_towerKet n b, PureState.congr_symm_congr] + +end AxQM diff --git a/LeanPool/AxQM/Core/QtowerWirePermutation.lean b/LeanPool/AxQM/Core/QtowerWirePermutation.lean new file mode 100644 index 0000000000..cd67a52afd --- /dev/null +++ b/LeanPool/AxQM/Core/QtowerWirePermutation.lean @@ -0,0 +1,102 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerTensorPow +public import LeanPool.AxQM.Postulates.API.WirePermutation +public import LeanPool.AxQM.Postulates.API.LeftPairGate + +/-! +# Placing a wire permutation on the control tower (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit implementing +`Cⁿ(X)`. The grounded `Cⁿ(X) = mcCtrl n pauliXGate` lives on the **right-nested** control +tower `qtower n qubit` (`AxQM/Core/MultiControlledReduction.lean`); bottoming its +multiply-controlled-`NOT` blocks to genuine two-control gates on the tight `(n+1)`-wire register +requires placing a `Toffoli`/`CNOT` on **non-contiguous** wires — done by conjugating a contiguous +gate by the wire permutation that gathers the chosen wires. The wire-permutation gate +`Evolution.permWires` (`AxQM/Postulates/API/WirePermutation.lean`) lives on the **symmetric** power +`qubit ^⊗ₛ (n+1)`, and the `qtower ↔ tensor-power` bridge `qtowerQubitTensorPow` +(`AxQM/Core/QtowerTensorPow.lean`) connects the two registers. This file assembles them: the wire +permutation transported onto the grounded control tower, with its computational-basis action read +off in the tower's own basis `towerKet`. + +## What is formalised + +* `Evolution.qtowerPermWires σ` — the **wire-permutation gate on the control tower** + `qtower n qubit`: the symmetric-register gate `Evolution.permWires σ` transported through the + bridge `(qtowerQubitTensorPow n).symm` by `Evolution.congr`. It is a genuine closed-system + `Evolution` on + exactly the `(n+1)`-wire register — no work qubit — realising an arbitrary relabelling of the + tower's wires. +* `qtowerPermWires_evolvePure_towerKet` — its **computational-basis action** in the tower's own + basis: `qtowerPermWires σ (towerKet n b) = towerKet n (b ∘ σ⁻¹)`, i.e. the wire carrying `b j` is + moved to wire `σ j`. This is exactly the wire-addressed placement dictionary the `Cᵏ(X)`-block + `Toffoli` reduction consumes — the effect of any wire permutation on a computational-basis tower + input, computed directly. + +## Design notes + +* **Why the transport route.** `Evolution.permWires` is defined on the symmetric `PiTensorProduct` + register `qubit ^⊗ₛ (n+1)`, where a factor relabelling is a clean `reindexₗᵢ` (no associator + surgery). The grounded gate lives on the right-nested `qtower n qubit`. Rather than redefine the + permutation gate directly on the awkward right-nested tower, we transport the clean symmetric-side + gate through the structural bridge `qtowerQubitTensorPow` via `Evolution.congr` — reusing the + basis dictionary `qtowerQubitTensorPow_congr_towerKet` for the basis action. +* **The basis-action proof.** By the transport law `Evolution.congr_evolvePure_congr`, evolving a + transported state by the transported gate equals the transport of the original action. Feeding the + tower basis state `towerKet n b`, the backward bridge dictionary + `qtowerQubitTensorPow_symm_congr_piTensor` (`AxQM/Core/QtowerTensorPow.lean`) rewrites it as the + transport of the symmetric product basis `⨂ₚ i, |b i⟩`; the general pure-state action + `Evolution.permWires_evolvePure_piTensor` (`AxQM/Postulates/API/WirePermutation.lean`) permutes + the factors to `⨂ₚ i, |b (σ⁻¹ i)⟩`; and the same dictionary (applied forwards) folds this back to + `towerKet n (b ∘ σ⁻¹)`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **The wire-permutation gate on the control tower** `qtower n qubit`: given a permutation +`σ : Equiv.Perm (Fin (n+1))` of the `n + 1` wires, the closed-system `Evolution` that relabels them +by `σ`. It is the symmetric-register wire-permutation gate `Evolution.permWires σ` (defined on +`qubit ^⊗ₛ (n+1)`) transported onto the right-nested control tower through the +`qtower ↔ tensor-power` bridge `(qtowerQubitTensorPow n).symm` via `Evolution.congr`. It acts on +exactly the `(n+1)`-wire register — no work qubit — and its computational-basis action is +`qtowerPermWires_evolvePure_towerKet`. -/ +def Evolution.qtowerPermWires (σ : Equiv.Perm (Fin (n + 1))) : Evolution (qtower n qubit) := + Evolution.congr (qtowerQubitTensorPow n).symm (Evolution.permWires σ) + +/-- **Computational-basis action of the tower wire-permutation gate.** Applying +`Evolution.qtowerPermWires σ` to the `(n+1)`-qubit computational tower basis state `towerKet n b` +yields `towerKet n (b ∘ σ⁻¹)`: the wire carrying `b j` is moved to wire `σ j`. This is the +wire-addressed placement dictionary — the effect of an arbitrary wire permutation on a +computational-basis tower input, computed directly on the grounded register. Proved from the +transport law `Evolution.congr_evolvePure_congr`, the backward bridge dictionary +`qtowerQubitTensorPow_symm_congr_piTensor`, and the product-basis action +`Evolution.permWires_evolvePure_piTensor`. -/ +theorem qtowerPermWires_evolvePure_towerKet (σ : Equiv.Perm (Fin (n + 1))) + (b : Fin (n + 1) → Fin 2) : + (Evolution.qtowerPermWires σ).evolvePure (towerKet n b) + = towerKet n fun i => b (σ.symm i) := by + -- Transport `towerKet n b` to the symmetric product basis (backward dictionary), apply the + -- transport law + the product-basis permutation action, then fold back with the same dictionary. + rw [Evolution.qtowerPermWires, ← qtowerQubitTensorPow_symm_congr_piTensor n b] + have h := Evolution.congr_evolvePure_congr (qtowerQubitTensorPow n).symm (Evolution.permWires σ) + (⨂ₚ (i : Fin (n + 1)), qubitBasis (b i)) + rw [h, Evolution.permWires_evolvePure_piTensor] + exact qtowerQubitTensorPow_symm_congr_piTensor n _ + +end AxQM diff --git a/LeanPool/AxQM/Core/QuditPowTower.lean b/LeanPool/AxQM/Core/QuditPowTower.lean new file mode 100644 index 0000000000..eb3785c061 --- /dev/null +++ b/LeanPool/AxQM/Core/QuditPowTower.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.MultiControlledReduction +public import LeanPool.AxQM.Postulates.API.QuditDimCongr +public import LeanPool.AxQM.Postulates.API.QuditTensorFactor +public import LeanPool.AxQM.Postulates.API.SystemIsoComm + +/-! +# Qudit registers encoded as qubit towers + +The fixed big-endian product basis identifies a register of dimension `2^(n+1)` with a +right-nested tower of `n+1` qubits. The successor lemma computes how the isomorphism splits +a computational-basis state into its leading qubit and remaining register state. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The qudit-to-tower register bridge** `qudit (2ⁿ⁺¹) ≃ₛ qtower n qubit`: the system isomorphism +identifying the `2ⁿ⁺¹`-level register with the right-nested `(n+1)`-qubit control tower +`qtower n qubit`. Built by induction on +`n`: the base `qudit (2¹) = qubit = qtower 0 qubit` is the identity, and each step peels the leading +qubit off the front with the tensor-factorisation iso `quditProdIso 2 (2ⁿ⁺¹)` — after the +`quditDimCongr` cast reconciling `2ⁿ⁺² = 2·2ⁿ⁺¹` (`pow_succ'`) — then tensors the identity on that +qubit with the tail bridge. Its action on the computational basis peels wire by wire +(`quditPowTower_congr_quditBasis_succ`). -/ +def quditPowTower : (n : ℕ) → (qudit (2 ^ (n + 1))) ≃ₛ (qtower n qubit) + | 0 => QSystem.Iso.refl qubit + | n + 1 => + (quditDimCongr (pow_succ' 2 (n + 1))).trans + ((quditProdIso 2 (2 ^ (n + 1))).trans + ((QSystem.Iso.refl qubit).tmul (quditPowTower n))) + +/-- Base unfolding of the register bridge: the single-qubit register `qudit (2¹)` is +`qtower 0 qubit` under the identity. -/ +@[simp] theorem quditPowTower_zero : quditPowTower 0 = QSystem.Iso.refl qubit := rfl + +/-- Step unfolding of the register bridge: cast `2ⁿ⁺² = 2·2ⁿ⁺¹`, peel the leading qubit with +`quditProdIso 2 (2ⁿ⁺¹)`, then tensor the identity on that qubit with the tail bridge. -/ +theorem quditPowTower_succ (n : ℕ) : + quditPowTower (n + 1) + = (quditDimCongr (pow_succ' 2 (n + 1))).trans + ((quditProdIso 2 (2 ^ (n + 1))).trans + ((QSystem.Iso.refl qubit).tmul (quditPowTower n))) := + rfl + +/-- **Basis peel for the register bridge.** On a computational-basis ket the bridge splits off the +leading (most-significant) qubit: writing the register index big-endian as `x·2ⁿ⁺¹ + y` +(`finProdFinEquiv (x, y)`, cast into `Fin (2ⁿ⁺²)`), the transported state is `|x⟩ ⊗ Φₙ |y⟩` with +`Φₙ = quditPowTower n` the tail bridge and `x : Fin 2` the leading bit. The recursive +computational-basis correctness of `quditPowTower`, obtained by feeding the tensor-factorisation +action `quditProdIso_congr_quditBasis` through the successor unfolding. -/ +theorem quditPowTower_congr_quditBasis_succ (n : ℕ) (x : Fin 2) (y : Fin (2 ^ (n + 1))) : + PureState.congr (quditPowTower (n + 1)) + (quditBasis ((finCongr (pow_succ' 2 (n + 1))).symm (finProdFinEquiv (x, y)))) + = (quditBasis x).tmul (PureState.congr (quditPowTower n) (quditBasis y)) := by + -- Unfold one step, then push `PureState.congr` through the three iso factors using their action + -- lemmas. `erw` is needed for the `congr_trans` steps: the composite's codomain + -- `qubit ⊗ qtower n qubit` is only *definitionally* `qtower (n+1) qubit`, so keyed `rw` matching + -- of the shared system metavariable fails; `rfl` closes the final `qudit 2` vs `qubit` defeq. + rw [quditPowTower_succ] + erw [PureState.congr_trans, quditDimCongr_congr_quditBasis, Equiv.apply_symm_apply, + PureState.congr_trans, quditProdIso_congr_quditBasis, PureState.congr_tmul, + PureState.congr_refl] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Core/SplitMcNotEvolution.lean b/LeanPool/AxQM/Core/SplitMcNotEvolution.lean new file mode 100644 index 0000000000..3cf0dcf803 --- /dev/null +++ b/LeanPool/AxQM/Core/SplitMcNotEvolution.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.McNotCircuitDecomposition +public import LeanPool.AxQM.Concrete.MultiControlledNotSplit + +/-! +# The one-borrowed-wire `Cᵐ(X)` split is a **linear** `Evolution` circuit (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. The `O(n²)` count is +reached by bottoming each internal `Cᵏ(X)` block of `barencoNCircuit` in a **linear** `O(k)` number +of `Toffoli`s, borrowing the register's idle wires as **dirty** ancillas. + +The Lemma-7.2 dirty cascade `Concrete.borrowedMcNot` is lifted to the `Evolution` level in +`AxQM/Core/BorrowedMcNotEvolution.lean` (`exists_borrowedCircuitEvolution_eq_placedMcNot`): a placed +`Cᵏ(X)` **is** a linear `≤ 4|as| + 1` `Toffoli`/`CNOT`/`NOT` `Evolution` circuit — but consuming +`|as| = |cs| - 2` **dirty borrowed ancillas**. That budget is met by the **small** blocks of +`barencoNCircuit V (n-1) 0` (a `Cʲ(X)` block sits with `n - j` idle module wires, so the `j - 2` +needed ancillas fit iff `j ≤ n/2 + 1`), but the **large** blocks — up to the top `C^{n-1}(X)` with +a *single* idle module wire — carry too few ancillas for Lemma 7.2 directly (the per-block +reduction `mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit` therefore carries the wire budget +`k - 2 ≤ d + 1`). + +`AxQM/Concrete/MultiControlledNotSplit.lean` closes that gap at the *classical* level with +Barenco's **Lemma 7.3**: `Concrete.splitMcNot asA A asB B a t = W · V · W · V`, a `Cᵐ(X)` +(`m = |A| + |B|`) needing only **one** borrowed dirty wire `a`, by splitting the controls into two +halves `A`, `B` that supply each other's Lemma-7.2 dirty ancillas (`asA ⊆ B`, `asB ⊆ A`). It is a +genuine `Cᵐ(X)` restoring every wire (`Concrete.mcNotDenote_splitMcNot`), of `≤ 2`-control gates +(`Concrete.splitMcNot_gate_mem`), in a **linear** `≤ 8|asA| + 8|asB| + 4 = O(m)` count +(`Concrete.splitMcNot_length_le`). This file lifts that one-borrowed-wire classical circuit to the +closed-system `Evolution` level — the split-route counterpart of the abstract lift +`exists_borrowedCircuitEvolution_eq_placedMcNot`. + +## What is formalised + +* `exists_splitCircuitEvolution_eq_placedMcNot` — the **abstract one-borrowed-wire linear lift**. + For control halves `A`, `B` with cross-borrowed dirty ancillas `asA`, `asB` + (`|A| = |asA| + 2`, `|B| = |asB| + 1`), one borrowed dirty wire `a`, and target `t`, all wires + suitably distinct (the same disjointness bundle Lemma 7.3 needs), the placed multiply-controlled + `NOT` `Evolution.placedMcNot (A.toFinset ∪ B.toFinset) t` **equals**, as an `Evolution` on + `qubit ^⊗ₛ m`, a genuine circuit `gs` of `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`, target never + a control) with the **linear** count `gs.length ≤ 8|asA| + 8|asB| + 4 = O(|A| + |B|)`. The + `Evolution`-level counterpart of `Concrete.splitMcNot`: feed `Concrete.splitMcNot asA A asB B a t` + (gate set by + `Concrete.splitMcNot_gate_mem`, length by `Concrete.splitMcNot_length_le`, denotation + `= Concrete.mcNot (A.toFinset ∪ B.toFinset) t` by `Concrete.mcNotDenote_splitMcNot`) to the + whole-circuit lift `exists_mcNotCircuitEvolution`, then identify the result with the placed gate + by computational-basis extensionality (`Evolution.ext_qubitBasis`, both act as + `Concrete.mcNot (A.toFinset ∪ B.toFinset) t`). + +## Role in the `O(n²)` construction + +The borrowed-wire lift consumes `|cs| - 2` borrowed ancillas; this one consumes just **one** (`a`) — +`asA`, `asB` are among the controls themselves. So it is the `Evolution`-level per-block reduction +the **large** `barencoNCircuit` blocks need, where only a single idle module wire remains. Applying +it to a `barencoNCircuit` block means choosing a half-split of the block's `k` front control wires +(`A`, `B`, `asA ⊆ B`, `asB ⊆ A`, `a` = one ambient wire), instantiating this lift, and identifying +`Evolution.placedMcNot (A.toFinset ∪ B.toFinset) t` with the contiguous front-block +`(Evolution.tensorPowMcCtrlX k).onBlock b` (the split-route counterpart of +`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit`) — removing the `k - 2 ≤ d + 1` wire budget of +`mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit` and giving the uniform `O(n²)` count over all +blocks. The parity obstruction still forbids a permutation-only circuit on exactly `n + 1` wires, so +the `√X` single-qubit-controlled gates of `barencoNCircuit` remain essential; the linear per-block +ancillas here are borrowed from the tower's idle module wires, staying within the `n + 1`-wire +register (Barenco *Elementary gates for quantum computation*, Lemma 7.3). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +/-- **N&C Exercise 4.29: the one-borrowed-wire `Cᵐ(X)` split is a linear `Evolution` +circuit.** For the two control halves `A`, `B` with cross-borrowed dirty ancillas `asA ⊆ B`, +`asB ⊆ A` (`|A| = |asA| + 2`, `|B| = |asB| + 1`), one borrowed dirty wire `a`, and target `t`, all +wires suitably distinct (`A.Nodup`, `asA.Nodup`, `B.Nodup`, `asB.Nodup`, the cross-disjointness +`A.Disjoint asA`, `B.Disjoint asB`, `a` outside `A`/`asA`/`B`/`asB`, `t` outside `A`/`B`/`asB`, +`a ≠ t`), there is a circuit `gs` of gates each with at most two controls (a `Toffoli`/`CNOT`/`NOT`, +target never a control) and a single closed-system `Evolution U` on `qubit ^⊗ₛ m` with: + +* `∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1` — the gate set is `Toffoli`/`CNOT`/`NOT`; +* `gs.length ≤ 8 * asA.length + 8 * asB.length + 4` — the **linear** `O(|A| + |B|)` gate count (four + half-size Lemma-7.2 cascades), versus the `Θ(k²)` halving bound `Concrete.mcNotGateBound`, using + just **one** borrowed dirty wire (`a`) rather than the `|cs| - 2` of + `exists_borrowedCircuitEvolution_eq_placedMcNot`; +* `U` acts on every computational basis state `|⨂ᵢ c i⟩` as the classical circuit denotation + `Concrete.mcNotDenote gs`; and +* `Evolution.placedMcNot (A.toFinset ∪ B.toFinset) t = U` — the placed multiply-controlled `NOT` on + the wires `(A ∪ B, t)` **is** that linear circuit, as an `Evolution`. + +The `Evolution`-level lift of `Concrete.mcNotDenote_splitMcNot`: the classical circuit is +`Concrete.splitMcNot asA A asB B a t` (gate set by `Concrete.splitMcNot_gate_mem`, length by +`Concrete.splitMcNot_length_le`, denotation `= Concrete.mcNot (A.toFinset ∪ B.toFinset) t` by +`Concrete.mcNotDenote_splitMcNot`); `exists_mcNotCircuitEvolution` lifts it to `U`, and +computational-basis extensionality (`Evolution.ext_qubitBasis`) identifies it with the placed gate +(`Evolution.placedMcNot_evolvePure_qubitBasis`). The split-route counterpart of +`exists_borrowedCircuitEvolution_eq_placedMcNot`. -/ +theorem exists_splitCircuitEvolution_eq_placedMcNot {m : ℕ} + (asA A asB B : List (Fin m)) (a t : Fin m) + (hAlen : A.length = asA.length + 2) (hBlen : B.length = asB.length + 1) + (hA : A.Nodup) (hasA : asA.Nodup) (hB : B.Nodup) (hasB : asB.Nodup) + (hAasA : A.Disjoint asA) (hBasB : B.Disjoint asB) + (haA : a ∉ A) (haasA : a ∉ asA) (haB : a ∉ B) (haasB : a ∉ asB) + (htA : t ∉ A) (htB : t ∉ B) (htasB : t ∉ asB) (hat : a ≠ t) : + ∃ (gs : List (Concrete.McNotGate m)) (U : Evolution (qubit.tensorPow m)), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 8 * asA.length + 8 * asB.length + 4 ∧ + (∀ c : Fin m → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + Evolution.placedMcNot (A.toFinset ∪ B.toFinset) t + (fun h => (Finset.mem_union.mp h).elim + (mt List.mem_toFinset.mp htA) (mt List.mem_toFinset.mp htB)) = U := by + have hgate := Concrete.splitMcNot_gate_mem asA A asB B a t hAlen hBlen hA hasA hB hasB + hAasA hBasB haA haasA haB haasB htB htasB hat + obtain ⟨U, hU⟩ := exists_mcNotCircuitEvolution (Concrete.splitMcNot asA A asB B a t) + (fun g hg => (hgate g hg).2) + refine ⟨Concrete.splitMcNot asA A asB B a t, U, hgate, + Concrete.splitMcNot_length_le asA A asB B a t, hU, ?_⟩ + refine Evolution.ext_qubitBasis fun c => ?_ + rw [Evolution.placedMcNot_evolvePure_qubitBasis, hU, + Concrete.mcNotDenote_splitMcNot asA A asB B a t hAlen hBlen hA hasA hB hasB + hAasA hBasB haA haasA haB haasB htA htB htasB hat] + +end AxQM diff --git a/LeanPool/AxQM/Core/SplitMcNotOnBlock.lean b/LeanPool/AxQM/Core/SplitMcNotOnBlock.lean new file mode 100644 index 0000000000..2c5847cc52 --- /dev/null +++ b/LeanPool/AxQM/Core/SplitMcNotOnBlock.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.SplitMcNotEvolution + +/-! +# Block-embedded `Cᵏ(X)` is a one-borrowed-wire linear `Evolution` circuit (N&C Ex 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. `barencoNCircuit` reduces `Cⁿ(X)` to a +sequence of internal multiply-controlled `NOT` blocks `Cᵏ(X)`; bottoming each block to a +**linear** `O(k)` Toffoli circuit makes the summed count `O(n²)`. + +`AxQM/Core/BorrowedMcNotEvolution.lean` gives a linear `Evolution` circuit for the +contiguous front-block `(Evolution.tensorPowMcCtrlX k).onBlock b` +(`tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit`), but through the Lemma-7.2 dirty cascade — so +it needs `k - 2` idle ambient wires to borrow (`k - 2 ≤ b`). That budget is met by the **small** +blocks of `barencoNCircuit` but fails for the **large** ones (up to `C^{n-1}(X)` with a single idle +module wire). `AxQM/Core/SplitMcNotEvolution.lean` lifts Barenco's **Lemma 7.3** split +(`Concrete.splitMcNot`, `W·V·W·V`) to the `Evolution` level +(`exists_splitCircuitEvolution_eq_placedMcNot`): a placed `Cᵐ(X)` **is** a linear circuit needing +just **one** borrowed dirty wire, the two control halves supplying each other's Lemma-7.2 ancillas. + +## What is formalised + +* `tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit` — the **split-route** contiguous + front-block reduction for the *large* blocks of the Barenco construction. For `k ≥ 3` and just + **one** idle ambient wire (`1 ≤ b`), the block-embedded `Cᵏ(X)` + `(Evolution.tensorPowMcCtrlX k).onBlock b` on `qubit ^⊗ₛ (k+1+b)` equals a genuine `Evolution` + circuit of `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) with the **linear** count `≤ 8 k = O(k)` — + the split-route counterpart of `tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit`, but + replacing its wire budget `k - 2 ≤ b` by `1 ≤ b`. + + Obtained by instantiating the abstract lift `exists_splitCircuitEvolution_eq_placedMcNot` at the + **balanced half-split** of the `k` front control wires `cs = ((cnxControls k).image (Fin.castAdd + b)).toList`: `A = cs.take p`, `B = cs.drop p` with `p = k - k/2 = ⌈k/2⌉`, `q = k/2 = ⌊k/2⌋`, + cross-borrowed dirty ancillas `asA = B.take (p-2)`, `asB = A.take (q-1)` (each half supplies the + other's ancillas: `asA ⊆ B`, `asB ⊆ A`), and one borrowed ambient wire `a = ⟨k+1, _⟩`. The split's + control set is exactly the front controls (`A.toFinset ∪ B.toFinset = (cnxControls k).image + (Fin.castAdd b)`, from `take ++ drop = cs`), so the resulting `Evolution.placedMcNot (A.toFinset ∪ + B.toFinset) t` matches the block `onBlock` through the block truth table + `tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis` and the placed-gate truth table + `Evolution.placedMcNot_evolvePure_qubitBasis` (`Evolution.ext_qubitBasis`). + +## Role in the `O(n²)` construction + +This removes the `k - 2 ≤ d + 1` wire budget of `mcCtrl_pauliXGate_onLeft_eq_linearToffoliCircuit`: +a single idle module wire now suffices to bottom **any** internal block linearly. Applied uniformly +across the `O(n)` internal `Cᵏ(X)` blocks of `barencoNCircuit`, the linear `O(k)` per-block count +gives the exercise's `O(n²)` total. The parity obstruction still forbids a permutation-only circuit +on exactly `n + 1` wires, so the `√X` single-qubit-controlled gates of `barencoNCircuit` remain +essential; the one borrowed ancilla here is an idle tower module wire, staying within the +`n + 1`-wire register (Barenco *Elementary gates for quantum computation*, Lemma 7.3). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace AxQM + +/-- **N&C Exercise 4.29: the block-embedded `Cᵏ(X)` is a one-borrowed-wire linear +Toffoli circuit.** The contiguous front-block placement `(Evolution.tensorPowMcCtrlX k).onBlock b` — +the grounded `Cᵏ(X)` (`k` controls, one target = the leading `k + 1` wires) acting as the identity +on the trailing `b` ambient wires of `qubit ^⊗ₛ (k+1+b)` — is, **as an `Evolution`**, a genuine +circuit of `≤ 2`-control gates (`Toffoli`/`CNOT`/`NOT`) with the **linear** count `≤ 8 k = O(k)`, +provided the register carries **one** idle ambient wire to borrow (`1 ≤ b`, `k ≥ 3`). + +The split-route counterpart of `tensorPowMcCtrlX_onBlock_eq_linearToffoliCircuit` (which +needs `k - 2 ≤ b` borrowed wires). Instantiates `exists_splitCircuitEvolution_eq_placedMcNot` +(Barenco Lemma 7.3) at the balanced half-split of the `k` front control wires +`cs = ((cnxControls k).image (Fin.castAdd b)).toList`: `A = cs.take (k - k/2)`, +`B = cs.drop (k - k/2)`, cross-borrowed dirty ancillas `asA = B.take (k - k/2 - 2)`, +`asB = A.take (k/2 - 1)`, and one borrowed ambient wire `a = ⟨k+1, _⟩`. Since +`A.toFinset ∪ B.toFinset` is exactly the front control set (`take ++ drop = cs`), the resulting +`Evolution.placedMcNot (A.toFinset ∪ B.toFinset) t` is identified with the block `onBlock` by +computational-basis extensionality (`Evolution.ext_qubitBasis`, both act as +`Concrete.mcNot ((cnxControls k).image (Fin.castAdd b)) (Fin.castAdd b (Fin.last k))`). The `1 ≤ b` +wire budget is the cost of the Lemma 7.3 construction's single borrowed dirty ancilla; it is met +by `barencoNCircuit`'s idle-wire register even for the largest blocks. -/ +theorem tensorPowMcCtrlX_onBlock_eq_splitLinearToffoliCircuit {k b : ℕ} + (hk : 3 ≤ k) (hb : 1 ≤ b) : + ∃ (gs : List (Concrete.McNotGate (k + 1 + b))) (U : Evolution (qubit.tensorPow (k + 1 + b))), + (∀ g ∈ gs, g.1.card ≤ 2 ∧ g.2 ∉ g.1) ∧ + gs.length ≤ 8 * k ∧ + (∀ c : Fin (k + 1 + b) → Fin 2, + U.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) = + PureState.piTensor fun i => qubitBasis (Concrete.mcNotDenote gs c i)) ∧ + (Evolution.tensorPowMcCtrlX k).onBlock b = U := by + -- The `k` front control wires as a list, and the register's half-split. + set cs : List (Fin (k + 1 + b)) := ((cnxControls k).image (Fin.castAdd b)).toList with hcs_def + set p : ℕ := k - k / 2 with hp + set q : ℕ := k / 2 with hq + set A : List (Fin (k + 1 + b)) := cs.take p with hA_def + set B : List (Fin (k + 1 + b)) := cs.drop p with hB_def + set asA : List (Fin (k + 1 + b)) := B.take (p - 2) with hasA_def + set asB : List (Fin (k + 1 + b)) := A.take (q - 1) with hasB_def + set a : Fin (k + 1 + b) := ⟨k + 1, by omega⟩ with ha_def + set t : Fin (k + 1 + b) := Fin.castAdd b (Fin.last k) with htgt + -- Basic facts about the control list `cs`. + have hcs_nodup : cs.Nodup := by rw [hcs_def]; exact Finset.nodup_toList _ + have hcs_len : cs.length = k := by + rw [hcs_def, Finset.length_toList, + Finset.card_image_of_injective _ (Fin.castAdd_injective _ _), + cnxControls_eq_image_castSucc, Finset.card_image_of_injective _ (Fin.castSucc_injective k), + Finset.card_univ, Fintype.card_fin] + have hcs_val : ∀ x ∈ cs, (x : ℕ) < k := by + intro x hx + rw [hcs_def, Finset.mem_toList, Finset.mem_image] at hx + obtain ⟨j, hj, rfl⟩ := hx + rw [Fin.val_castAdd] + exact (mem_cnxControls j).mp hj + -- Lengths of the four split lists. + have hA_len : A.length = p := by + rw [hA_def, List.length_take, hcs_len, Nat.min_eq_left (by omega)] + have hB_len : B.length = q := by rw [hB_def, List.length_drop, hcs_len]; omega + have hasA_len : asA.length = p - 2 := by + rw [hasA_def, List.length_take, hB_len, Nat.min_eq_left (by omega)] + have hasB_len : asB.length = q - 1 := by + rw [hasB_def, List.length_take, hA_len, Nat.min_eq_left (by omega)] + have hAlen : A.length = asA.length + 2 := by rw [hA_len, hasA_len]; omega + have hBlen : B.length = asB.length + 1 := by rw [hB_len, hasB_len]; omega + -- Nodups. + have hA_nodup : A.Nodup := by rw [hA_def]; exact hcs_nodup.sublist (List.take_sublist _ _) + have hB_nodup : B.Nodup := by rw [hB_def]; exact hcs_nodup.sublist (List.drop_sublist _ _) + have hasA_nodup : asA.Nodup := by rw [hasA_def]; exact hB_nodup.sublist (List.take_sublist _ _) + have hasB_nodup : asB.Nodup := by rw [hasB_def]; exact hA_nodup.sublist (List.take_sublist _ _) + -- Cross-disjointness of the halves and their borrowed ancillas. + have hAasA : A.Disjoint asA := by + rw [hA_def, hasA_def, hB_def] + exact fun x hx hx' => List.disjoint_take_drop hcs_nodup le_rfl hx (List.take_subset _ _ hx') + have hBasB : B.Disjoint asB := by + rw [hB_def, hasB_def, hA_def] + exact fun x hx hx' => + (List.disjoint_take_drop hcs_nodup le_rfl).symm hx (List.take_subset _ _ hx') + -- Subset facts locating every split wire inside `cs`. + have hA_sub : A ⊆ cs := by rw [hA_def]; exact List.take_subset _ _ + have hB_sub : B ⊆ cs := by rw [hB_def]; exact List.drop_subset _ _ + have hasA_sub : asA ⊆ cs := by + rw [hasA_def]; exact List.Subset.trans (List.take_subset _ _) hB_sub + have hasB_sub : asB ⊆ cs := by + rw [hasB_def]; exact List.Subset.trans (List.take_subset _ _) hA_sub + -- The borrowed ambient wire `a` (value `k+1`) and the target `t` (value `k`) miss every control. + have ha_val : (a : ℕ) = k + 1 := by rw [ha_def] + have ht_val : (t : ℕ) = k := by rw [htgt]; simp only [Fin.val_castAdd, Fin.val_last] + have ha_cs : a ∉ cs := fun h => by have := hcs_val a h; omega + have ht_cs : t ∉ cs := fun h => by have := hcs_val t h; omega + have haA : a ∉ A := fun h => ha_cs (hA_sub h) + have haB : a ∉ B := fun h => ha_cs (hB_sub h) + have haasA : a ∉ asA := fun h => ha_cs (hasA_sub h) + have haasB : a ∉ asB := fun h => ha_cs (hasB_sub h) + have htA : t ∉ A := fun h => ht_cs (hA_sub h) + have htB : t ∉ B := fun h => ht_cs (hB_sub h) + have htasB : t ∉ asB := fun h => ht_cs (hasB_sub h) + have hat : a ≠ t := Fin.ne_of_val_ne (by rw [ha_val, ht_val]; omega) + -- The split's control set is exactly the front controls. + have hAB : A.toFinset ∪ B.toFinset = (cnxControls k).image (Fin.castAdd b) := by + rw [hA_def, hB_def, ← List.toFinset_append, List.take_append_drop, hcs_def, + Finset.toList_toFinset] + -- Feed the half-split into the abstract one-borrowed-wire lift. + obtain ⟨gs, U, hgate, hglen, hUc, hplaced⟩ := + exists_splitCircuitEvolution_eq_placedMcNot asA A asB B a t hAlen hBlen + hA_nodup hasA_nodup hB_nodup hasB_nodup hAasA hBasB haA haasA haB haasB htA htB htasB hat + refine ⟨gs, U, hgate, le_trans hglen ?_, hUc, ?_⟩ + · rw [hasA_len, hasB_len]; omega + · rw [← hplaced] + refine Evolution.ext_qubitBasis fun c => ?_ + rw [tensorPowMcCtrlX_onBlock_evolvePure_qubitBasis, Evolution.placedMcNot_evolvePure_qubitBasis, + hAB, htgt] + +end AxQM diff --git a/LeanPool/AxQM/Core/StrictContraction.lean b/LeanPool/AxQM/Core/StrictContraction.lean new file mode 100644 index 0000000000..c17f2f42e5 --- /dev/null +++ b/LeanPool/AxQM/Core/StrictContraction.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TraceDistance +public import Mathlib.Dynamics.FixedPoints.Basic + +/-! +# Strictly contractive state-maps and uniqueness of fixed points (Nielsen & Chuang §9.2.1) + +Nielsen & Chuang, in the fixed-point exercises of §9.2.1 (Exercises 9.9–9.13, p. 408–409), +distinguish two notions for a trace-preserving quantum operation `E`: + +* **contractive** — `D(E(ρ), E(σ)) ≤ D(ρ, σ)` for all `ρ`, `σ` (Theorem 9.2, always true); +* **strictly contractive** — `D(E(ρ), E(σ)) < D(ρ, σ)` for all `ρ ≠ σ` (Exercise 9.10). + +This file introduces the predicate `AxQM.StrictlyContractive` capturing the +second notion for an arbitrary state-map, together with its elementary but reusable consequence: +a strictly contractive map has **at most one** fixed point. These are the shared ingredients behind +Exercises 9.10 (unique fixed point), 9.11 (a mixing operation is strictly contractive), and 9.13 +(the bit-flip channel is contractive but *not* strictly). + +## Scope of this file: uniqueness + +The content packaged here is the **uniqueness** half of the fixed-point story — "at most one fixed +point", elementary and needing *only* strict contraction — together with the "uniqueness given +existence" assembly `strictlyContractive_existsUnique_fixedPoint_of_exists`, which turns an assumed +fixed point into the unique `∃!`. It proves nothing about *existence* itself; that is the separate +matter of Exercise 9.9 (`IsChannel.exists_fixedPoint`). The two combine into the full Exercise 9.10 +(`IsChannel.existsUnique_fixedPoint_of_strictlyContractive`) in [upstream `AxQM/NC/Ch9/Exercise9_10.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch9/Exercise9_10.lean). + +## The predicate and the `ρ ≠ σ` guard + +N&C write the strict-contraction condition as "for any `ρ` and `σ`, `D(E(ρ), E(σ)) < D(ρ, σ)`". +Read literally over *all* pairs this is unsatisfiable: at `ρ = σ` both distances are `0`, and +`0 < 0` is false, so a literal `∀ ρ σ` would make the hypothesis `False` and every theorem +using it *vacuously* true — a dishonest reading. The intended and standard meaning (the metric-space +notion of a *contractive* map, in Edelstein's sense) restricts to *distinct* states: +`∀ ρ σ, ρ ≠ σ → D(E(ρ), E(σ)) < D(ρ, σ)`. That is exactly `StrictlyContractive`; the guard is a +faithful transcription, not an added hypothesis. + +Note strict contraction is genuinely weaker than a Banach/Lipschitz contraction +(`ContractingWith K` with a uniform `K < 1`): it provides no uniform contraction constant, which is +why Mathlib's contraction-mapping API does not apply directly. + +## Fixed points + +Fixed points are spelled with the Mathlib fixed-point API (`Function.IsFixedPt`, +`Function.fixedPoints`) so these lemmas compose with the library. + +## Main declarations + +* `AxQM.StrictlyContractive` — the predicate `∀ ρ σ, ρ ≠ σ → D(f ρ, f σ) < D(ρ, σ)`. +* `AxQM.StrictlyContractive.eq_of_isFixedPoint` — two fixed points of a strictly + contractive map coincide (the uniqueness kernel: at most one fixed point). +* `AxQM.StrictlyContractive.subsingleton_fixedPoints` — the packaging of the kernel: + the fixed-point set `Function.fixedPoints f` is a subsingleton. +* `AxQM.strictlyContractive_existsUnique_fixedPoint_of_exists` — the reusable "uniqueness + given existence" assembly: a strictly contractive map with a fixed point has a *unique* one + (`∃!`). Existence is a hypothesis, discharged elsewhere (Exercise 9.9 for a channel). + +## References + +Nielsen, M. A., & Chuang, I. L. (2010). *Quantum Computation and Quantum Information* (10th anniv. +ed.). Cambridge University Press. §9.2.1, Exercises 9.9–9.13 (p. 408–409). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- A state-map `f : State S → State S` is **strictly contractive** for the trace distance when it +strictly decreases the distance between any two *distinct* states: +`D(f ρ, f σ) < D(ρ, σ)` whenever `ρ ≠ σ` (Nielsen & Chuang, Exercise 9.10, p. 408). + +This is the metric notion of a *contractive* map (Edelstein): unlike `ContractingWith K`, it assumes +no uniform contraction constant `K < 1`. The `ρ ≠ σ` guard is the honest reading of N&C's informal +"for any `ρ` and `σ`" — at `ρ = σ` the strict inequality is impossible, so an unguarded quantifier +would be a `False` hypothesis. -/ +def StrictlyContractive (f : State S → State S) : Prop := + ∀ ρ σ : State S, ρ ≠ σ → (f ρ).traceDistance (f σ) < ρ.traceDistance σ + +/-- **A strictly contractive map has at most one fixed point** (the uniqueness kernel of Nielsen & +Chuang, Exercise 9.10). If `f` is strictly contractive and both `ρ` and `σ` are fixed points, then +`ρ = σ`. + +Proof: were `ρ ≠ σ`, strict contraction would give `D(f ρ, f σ) < D(ρ, σ)`; but `f ρ = ρ` and +`f σ = σ` turn the left side into `D(ρ, σ)`, yielding `D(ρ, σ) < D(ρ, σ)`, a contradiction. -/ +theorem StrictlyContractive.eq_of_isFixedPoint {f : State S → State S} + (hf : StrictlyContractive f) {ρ σ : State S} + (hρ : Function.IsFixedPt f ρ) (hσ : Function.IsFixedPt f σ) : ρ = σ := by + by_contra hne + have h := hf ρ σ hne + rw [hρ, hσ] at h + exact lt_irrefl _ h + +/-- The **fixed-point set of a strictly contractive map is a subsingleton** — the set-level +packaging of `StrictlyContractive.eq_of_isFixedPoint`. Any two members of `Function.fixedPoints f` +are equal, so the fixed point (when it exists) is unique. -/ +theorem StrictlyContractive.subsingleton_fixedPoints {f : State S → State S} + (hf : StrictlyContractive f) : (Function.fixedPoints f).Subsingleton := + fun _ hρ _ hσ => hf.eq_of_isFixedPoint hρ hσ + +/-- **Uniqueness given existence** (Nielsen & Chuang, Exercise 9.10). A strictly contractive +state-map `f` that possesses a fixed point possesses a *unique* one: `∃! ρ, f ρ = ρ`. + +This is the reusable "uniqueness given existence" assembly: it isolates the part strict contraction +contributes (uniqueness, through `eq_of_isFixedPoint`) from *existence*, which is supplied as the +hypothesis `hex`. It holds for *any* strictly contractive map with a fixed point; for a +trace-preserving quantum operation `hex` is discharged by Exercise 9.9's existence theorem, giving +the full Exercise 9.10 (`IsChannel.existsUnique_fixedPoint_of_strictlyContractive`, in +[upstream `AxQM/NC/Ch9/Exercise9_10.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch9/Exercise9_10.lean)). The `_of_exists` suffix marks that existence is assumed, not +proved. -/ theorem strictlyContractive_existsUnique_fixedPoint_of_exists {f : State S → State S} + (hf : StrictlyContractive f) (hex : ∃ ρ : State S, Function.IsFixedPt f ρ) : + ∃! ρ : State S, Function.IsFixedPt f ρ := by + obtain ⟨ρ, hρ⟩ := hex + exact ⟨ρ, hρ, fun σ hσ => hf.eq_of_isFixedPoint hσ hρ⟩ + +end AxQM diff --git a/LeanPool/AxQM/Core/TensorPowMultiControlledX.lean b/LeanPool/AxQM/Core/TensorPowMultiControlledX.lean new file mode 100644 index 0000000000..f158555682 --- /dev/null +++ b/LeanPool/AxQM/Core/TensorPowMultiControlledX.lean @@ -0,0 +1,113 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerTensorPow +public import LeanPool.AxQM.Postulates.API.LeftPairGate + +/-! +# `Cⁿ(X)` on the symmetric tensor-power register (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of Toffoli, +`CNOT` and single-qubit gates implementing the `n`-controlled `NOT` `Cⁿ(X)`. The postulate-grounded +`Cⁿ(X) = mcCtrl n pauliXGate` lives on the **right-nested** control tower `qtower n qubit` +(`Core/MultiControlledReduction`). The arbitrary-wire gate-placement combinator +`Evolution.onWires` (`AxQM/Postulates/API/WireGatePlacement.lean`) — the surgery that bottoms a +multiply-controlled-`NOT` block to genuine two-control gates on chosen, non-contiguous wires — lives +instead on the **symmetric** power `qubit ^⊗ₛ (n+1)` (the `n+1`-fold `PiTensorProduct`, where a wire +relabelling is a clean `reindexₗᵢ`). Assembling an `onWires`-built circuit and comparing it to +`Cⁿ(X)` therefore needs the grounded gate carried onto that same symmetric register. + +This file performs that transport, once, and reads off its computational-basis truth table. + +## What is formalised + +* `Evolution.tensorPowMcCtrlX n` — the **symmetric-register form of `Cⁿ(X)`**: the grounded gate + `mcCtrl n pauliXGate` transported onto `qubit ^⊗ₛ (n+1)` through the `qtower ↔ tensor-power` + bridge `qtowerQubitTensorPow n` by `Evolution.congr`. A genuine closed-system + `Evolution` on + exactly the `(n+1)`-wire register — no work qubit — equal to `Cⁿ(X)` up to the (isometric) change + of register description. +* `tensorPowMcCtrlX_evolvePure_piTensor` — its **computational-basis truth table**: on the symmetric + product basis state `⨂ᵢ |b i⟩` it produces `⨂ᵢ |mcNot (cnxControls n) (Fin.last n) b i⟩`, i.e. it + acts exactly as the classical multiply-controlled `NOT` `Concrete.mcNot` with controls the first + `n` wires and target the last. This is the truth table the `onWires`-assembled circuit is compared + against, in the register the circuit is built on. + +## Design notes + +* **Why transport `Cⁿ(X)` to the symmetric register, not the placement gates to `qtower`.** The + two objects live on different registers: the target `Cⁿ(X)` on the right-nested + `qtower n qubit`, and the placement combinators (`Evolution.permWires`, + `Evolution.onBlock`, `Evolution.onWires`) on the symmetric + `qubit ^⊗ₛ (a+b)`. Only one of the two needs to move. Carrying a *placement* gate + `Evolution.onWires _ b σ : Evolution (qubit ^⊗ₛ (a+b))` onto `qtower` would require the bridge at + `qtower (a+b-1) qubit`, and `(a+b-1)+1 = a+b` holds only *propositionally* (not by `rfl`) — a + `cast`. Carrying the *single target* `Cⁿ(X) : Evolution (qtower n qubit)` onto + `qubit ^⊗ₛ (n+1)` is `Evolution.congr (qtowerQubitTensorPow n) ·` — no subtraction, no `cast` — + and it is transported once rather than once per placement gate. The two framings are + interchangeable + (`Evolution.congr` is an isomorphism), so a `Cⁿ(X) = circuit` claim on the symmetric + register pulls back to the grounded `qtower` gate by the same iso. +* **The truth-table proof.** By the transport law `Evolution.congr_evolvePure_congr`, evolving a + transported state by the transported gate equals the transport of the original action. The input + `⨂ᵢ |b i⟩` is rewritten as `PureState.congr (bridge n) (towerKet n b)` via the forward basis + dictionary `qtowerQubitTensorPow_congr_towerKet`; the grounded action + `mcCtrl_pauliXGate_evolvePure_towerKet` (the Exercise 4.29 quantum–classical bridge) sends + `towerKet n b ↦ towerKet n (mcNot …)`; and the same dictionary (forwards) folds the result back to + `⨂ᵢ |mcNot … b i⟩`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The multiply-controlled `NOT` `Cⁿ(X)` on the symmetric tensor-power register.** The grounded +gate `mcCtrl n pauliXGate : Evolution (qtower n qubit)` transported onto the symmetric `(n+1)`-fold +power `qubit ^⊗ₛ (n+1)` through the `qtower ↔ tensor-power` bridge `qtowerQubitTensorPow n` +by `Evolution.congr`. It acts on exactly the `(n+1)`-wire register — no work qubit — and +equals +`Cⁿ(X)` up to the isometric change of register description; its computational-basis action is +`tensorPowMcCtrlX_evolvePure_piTensor`. This is the object an `Evolution.onWires`-assembled Toffoli +circuit (which lives natively on `qubit ^⊗ₛ (n+1)`) is compared against. -/ +def Evolution.tensorPowMcCtrlX (n : ℕ) : Evolution (qubit ^⊗ₛ (n + 1)) := + Evolution.congr (qtowerQubitTensorPow n) (mcCtrl n pauliXGate) + +/-- Definitional unfolding of `Evolution.tensorPowMcCtrlX` as the transported grounded `Cⁿ(X)`. -/ +theorem Evolution.tensorPowMcCtrlX_def (n : ℕ) : + Evolution.tensorPowMcCtrlX n + = Evolution.congr (qtowerQubitTensorPow n) (mcCtrl n pauliXGate) := + rfl + +/-- **Computational-basis truth table of `Cⁿ(X)` on the symmetric register.** The symmetric-register +`Cⁿ(X)` gate `Evolution.tensorPowMcCtrlX n` acts on the computational product basis state `⨂ᵢ |b i⟩` +(`PureState.piTensor fun i => qubitBasis (b i)`) exactly as the classical multiply-controlled `NOT` +`Concrete.mcNot` with controls the first `n` wires (`cnxControls n`) and target the last +(`Fin.last n`): +`tensorPowMcCtrlX n (⨂ᵢ |b i⟩) = ⨂ᵢ |mcNot (cnxControls n) (Fin.last n) b i⟩`. + +So on the symmetric register too, the quantum `Cⁿ(X)` **is** the reversible bit-string permutation +whose `O(n²)` no-work-qubit circuit the `Concrete/MultiControlledNot*` development exhibits — now +stated on the register where an arbitrary-wire (`Evolution.onWires`) Toffoli circuit is assembled. +Proved from the transport law `Evolution.congr_evolvePure_congr`, the forward basis dictionary +`qtowerQubitTensorPow_congr_towerKet` (used both to feed the input and to fold the output), and the +grounded quantum–classical bridge `mcCtrl_pauliXGate_evolvePure_towerKet` (Exercise 4.29). -/ +theorem tensorPowMcCtrlX_evolvePure_piTensor (n : ℕ) (b : Fin (n + 1) → Fin 2) : + (Evolution.tensorPowMcCtrlX n).evolvePure (PureState.piTensor fun i => qubitBasis (b i)) + = PureState.piTensor fun i => + qubitBasis (Concrete.mcNot (cnxControls n) (Fin.last n) b i) := by + rw [Evolution.tensorPowMcCtrlX_def, ← qtowerQubitTensorPow_congr_towerKet n b, + Evolution.congr_evolvePure_congr, mcCtrl_pauliXGate_evolvePure_towerKet, + qtowerQubitTensorPow_congr_towerKet] + +end AxQM diff --git a/LeanPool/AxQM/Core/TwoQubitGateCircuit.lean b/LeanPool/AxQM/Core/TwoQubitGateCircuit.lean new file mode 100644 index 0000000000..8e309723e4 --- /dev/null +++ b/LeanPool/AxQM/Core/TwoQubitGateCircuit.lean @@ -0,0 +1,204 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.ControlPairGates + +/-! +# A two-qubit-gate-count model for three-qubit circuits (Nielsen & Chuang §4.3) + +Nielsen & Chuang **Exercise 4.25** (Fredkin gate construction) closes with two *gate-count* claims +phrased over **two-qubit gates**: part (3) builds the Fredkin gate "using only **six two-qubit +gates**", and part (4) asks for an even simpler construction with "only **five two-qubit gates**". +Here a *controlled single-qubit gate* `C(V)` counts as **one** two-qubit gate — the same convention +that makes Figure 4.8's `C²(U)` decomposition "five two-qubit gates" (`C(V)`, `CNOT`, `C(V†)`, +`CNOT`, `C(V)`). To state such a claim *faithfully* the count must be a genuine proposition about a +circuit, not a term the reader tallies by eye. + +This is a **coarser** cost model than the one-qubit + `CNOT` model of `Core.GateCircuit` (`Gate3`, +`oneQubitCount`, `cnotCount`, Exercise 4.22): there a `C(V)` is *decomposed* into single-qubit gates +and `CNOT`s (the ABC decomposition), so it is not one gate. Both models are honest; they count +different alphabets for different exercises. This file provides the vehicle Exercise 4.25 parts 3–4 +need: a typed **two-qubit-gate circuit** on `qubit ⊗ (qubit ⊗ qubit)` (wires `0, 1, 2`) as a `List` +of `TwoQubitGate3`s, each of which is a genuine **two-qubit** gate — it acts on at most two of the +three wires — together with + +* `TwoQubitGate3.denote` / `twoQubitCircuit` — the `Evolution` a gate / gate list implements (the + monoid product of the gate denotations), so a circuit *means* a concrete unitary; and +* `twoQubitCount` — the number of two-qubit gates, which is simply the list length (every element + *is* a two-qubit gate), + +turning "the Fredkin gate can be built from at most `n` two-qubit gates" into the honest existential +`∃ gs, twoQubitCircuit gs = fredkinGate ∧ twoQubitCount gs ≤ n`. + +## What is formalised + +* `TwoQubitGate3` — a two-qubit gate on `qubit ⊗ (qubit ⊗ qubit)`, in one of four forms. The + parts-1–3 forms `pair`/`ctrl` are chosen so the placements those parts need are bare composites + with no associator/SWAP bookkeeping (the placements in `ccontrolledUnitaryCircuit`, Exercise + 4.21); the part-4 forms `pairAB`/`pairAC` add an arbitrary gate on a *control* pair via + associator/`leftComm` transport (see the design note below): + * `pair U` — an **arbitrary** two-qubit gate `U : Evolution (qubit ⊗ qubit)` on the target pair + `{1, 2}`, with the control wire `0` idle (`U.onRight qubit = 1 ⊗ U`); + * `ctrl t g` — a **control-wire-`0`** gate: the single-qubit gate `g` on wire `1` (`t = 0`) or + wire `2` (`t = 1`), conditioned on wire `0`, with the remaining wire idle + (`controlledUnitary (g.onLeft/onRight qubit)`). + * `pairAB U` / `pairAC U` — an **arbitrary** two-qubit gate `U` on a *control* pair, `{0,1}` + (`leftPairGate U`, wire `2` idle) or `{0,2}` (`outerPairGate U`, wire `1` idle). Unlike `ctrl` + these admit *entangling* gates on a control pair — the class Exercise 4.25 part 4's + five-two-qubit-gate Fredkin construction provably needs (a controlled-single-qubit alphabet + cannot reach five gates). Parts 1–3 use only `pair`/`ctrl`; these extend the *same* count model + so "five two-qubit gates" is compared like-for-like with part 3's "six". + Each form is a genuine two-qubit gate: `pair U` leaves wire `0` untouched + (`TwoQubitGate3.pair_denote_evolvePure`), and `ctrl t g` acts on wire `0` and one target wire. +* `twoQubitCircuit gs = (gs.map TwoQubitGate3.denote).prod` — the composite `Evolution`, in operator + order (leftmost gate is the leftmost `comp` factor, applied last). +* `twoQubitCount gs = gs.length` — the two-qubit-gate count. +* structural rewrites `twoQubitCircuit_nil/cons/append` and the denotation unfoldings + `denote_pair`/`denote_ctrl_zero`/`denote_ctrl_one`/`denote_pairAB`/`denote_pairAC` — the API a + circuit-assembly proof uses. + +## Design notes + +* **Statements.** Every declaration's statement names only gates (`Evolution` and its monoid + `comp`/`1`, `controlledUnitary`, `Evolution.onLeft`/`onRight`) and plain `List`/`ℕ` data. The + gates it composes are in `AxQM/Postulates/API/`; Exercise 4.25 itself is in + [upstream `AxQM/NC/Ch4/Exercise4_25.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_25.lean). +* **Why these constructors (an honest, non-ad-hoc alphabet).** Reading Figure 4.8 (Exercise 4.21, + `ccontrolledUnitaryCircuit`) shows its five gates are *already* `pair`s and `ctrl`s: + `(controlledUnitary V).onRight qubit` is a `pair`, and the `controlledUnitary (_.onLeft/onRight + qubit)` gates are `ctrl`s. So `pair`/`ctrl` are the natural alphabet for the Chapter-4 controlled + constructions (parts 1–3), not a Fredkin-specific gadget. Like `Gate3.cnotOn` — which realises the + non-adjacent `(0,2)` `CNOT` as a control-wire-`0` gate rather than by SWAP conjugation — those two + forms are *tailored* to the placements parts 1–3 use and need no associator transport. Part 4's + five-two-qubit-gate construction *does* need a genuinely entangling gate on a *control* pair (not + of `ctrl` form): `pairAB`/`pairAC` supply exactly the general `{0,1}` / `{0,2}` placements — an + arbitrary two-qubit gate carried across `QSystem.assoc` / `QSystem.Iso.leftComm` with + `Evolution.congr`. +* **Why the count is the list length.** In `Gate3` a list mixes one-qubit gates and `CNOT`s, so the + count is a `List.countP`. Here *every* element is a two-qubit gate, so the number of two-qubit + gates is exactly `gs.length`; `twoQubitCount` is a transparent alias for it, inheriting + `List.length_cons`/`length_append`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **A two-qubit gate in a three-qubit circuit** on `qubit ⊗ (qubit ⊗ qubit)` (wires `0, 1, 2`), +in one of four genuine two-qubit forms: + +* `pair U` — an arbitrary two-qubit gate `U` on the target pair `{1, 2}`, control wire `0` idle; +* `ctrl t g` — the single-qubit gate `g` on wire `1` (`t = 0`) or wire `2` (`t = 1`), controlled on + wire `0`, the remaining wire idle; +* `pairAB U` — an arbitrary two-qubit gate `U` on the left control pair `{0, 1}` (via + `leftPairGate`, wire `2` idle); +* `pairAC U` — an arbitrary two-qubit gate `U` on the outer control pair `{0, 2}` (via + `outerPairGate`, wire `1` idle). + +`pairAB`/`pairAC` admit *entangling* gates on a control pair — the class Exercise 4.25 part 4's +five-two-qubit-gate Fredkin construction needs, which `ctrl` (controlled-single-qubit) cannot give. +Its `TwoQubitGate3.denote`ation is an `Evolution`; because every gate is a two-qubit gate, the +number of two-qubit gates in a list is just its `twoQubitCount` (= length), so "the Fredkin gate is +built from at most `n` two-qubit gates" becomes a genuine proposition. -/ +inductive TwoQubitGate3 where + | /-- An arbitrary two-qubit gate `U` on the target pair `{1, 2}` (control wire `0` idle). -/ + pair (U : Evolution (qubit ⊗ qubit)) + | /-- The single-qubit gate `g` controlled on wire `0`, targeting wire `1` (`target = 0`) or + wire `2` (`target = 1`). -/ + ctrl (target : Fin 2) (g : Evolution qubit) + | /-- An arbitrary two-qubit gate `U` on the left control pair `{0, 1}` (wire `2` idle), placed + via `leftPairGate`. Needed for the five-two-qubit-gate Fredkin construction (Exercise 4.25 + part 4), whose entangling gate on a control pair is not of `ctrl` (controlled-single-qubit) + form. -/ + pairAB (U : Evolution (qubit ⊗ qubit)) + | /-- An arbitrary two-qubit gate `U` on the outer control pair `{0, 2}` (wire `1` idle), placed + via `outerPairGate`. -/ + pairAC (U : Evolution (qubit ⊗ qubit)) + +namespace TwoQubitGate3 + +/-- **The `Evolution` denoted by a single two-qubit gate** (all four forms): `pair U = 1 ⊗ U` places +`U` on the target pair `{1, 2}`; `ctrl 0 g` / `ctrl 1 g` place the control-wire-`0` gate `C(g)` on +wire `1` / wire `2` (via `g.onLeft qubit` / `g.onRight qubit` inside `controlledUnitary`); +`pairAB U = leftPairGate U` places `U` on the left control pair `{0, 1}` and +`pairAC U = outerPairGate U` places `U` on the outer control pair `{0, 2}`. -/ +def denote : TwoQubitGate3 → Evolution (qubit ⊗ (qubit ⊗ qubit)) + | pair U => U.onRight qubit + | ctrl 0 g => controlledUnitary (g.onLeft qubit) + | ctrl _ g => controlledUnitary (g.onRight qubit) + | pairAB U => leftPairGate U + | pairAC U => outerPairGate U + +@[simp] theorem denote_pair (U : Evolution (qubit ⊗ qubit)) : + (pair U).denote = U.onRight qubit := rfl + +@[simp] theorem denote_ctrl_zero (g : Evolution qubit) : + (ctrl 0 g).denote = controlledUnitary (g.onLeft qubit) := rfl + +@[simp] theorem denote_ctrl_one (g : Evolution qubit) : + (ctrl 1 g).denote = controlledUnitary (g.onRight qubit) := rfl + +@[simp] theorem denote_pairAB (U : Evolution (qubit ⊗ qubit)) : + (pairAB U).denote = leftPairGate U := rfl + +@[simp] theorem denote_pairAC (U : Evolution (qubit ⊗ qubit)) : + (pairAC U).denote = outerPairGate U := rfl + +/-- **A `pair` gate is a genuine two-qubit gate**: it leaves the control wire `0` untouched, +`(1 ⊗ U)(ψ ⊗ φ) = ψ ⊗ (U φ)`. -/ +theorem pair_denote_evolvePure (U : Evolution (qubit ⊗ qubit)) (ψ : PureState qubit) + (φ : PureState (qubit ⊗ qubit)) : + (pair U).denote.evolvePure (ψ ⊗ φ) = ψ ⊗ (U.evolvePure φ) := + Evolution.onRight_evolvePure U qubit ψ φ + +end TwoQubitGate3 + +/-- **The evolution implemented by a two-qubit-gate list**: the monoid product of the gate +denotations, `(gs.map TwoQubitGate3.denote).prod`, in operator order (the leftmost gate is the +leftmost `comp` factor, applied last). -/ +def twoQubitCircuit (gs : List TwoQubitGate3) : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + (gs.map TwoQubitGate3.denote).prod + +/-- **The number of two-qubit gates** in a two-qubit-gate circuit. Since every element of the list +is a two-qubit gate, this is simply the list length. -/ +def twoQubitCount (gs : List TwoQubitGate3) : ℕ := gs.length + +@[simp] theorem twoQubitCircuit_nil : twoQubitCircuit [] = 1 := rfl + +/-- The circuit of `g :: gs` applies `g` last: its evolution is `g.denote ∘ (circuit of gs)`. -/ +@[simp] theorem twoQubitCircuit_cons (g : TwoQubitGate3) (gs : List TwoQubitGate3) : + twoQubitCircuit (g :: gs) = g.denote.comp (twoQubitCircuit gs) := by + rw [twoQubitCircuit, List.map_cons, List.prod_cons, twoQubitCircuit, Evolution.mul_def] + +/-- Concatenating circuits composes their evolutions: `twoQubitCircuit (gs ++ hs) = gs-circuit ∘ +hs-circuit`, so `hs` acts first. -/ +theorem twoQubitCircuit_append (gs hs : List TwoQubitGate3) : + twoQubitCircuit (gs ++ hs) = (twoQubitCircuit gs).comp (twoQubitCircuit hs) := by + rw [twoQubitCircuit, List.map_append, List.prod_append, twoQubitCircuit, twoQubitCircuit, + Evolution.mul_def] + +@[simp] theorem twoQubitCount_nil : twoQubitCount [] = 0 := rfl + +/-- Each gate adds one to the two-qubit-gate count. -/ +@[simp] theorem twoQubitCount_cons (g : TwoQubitGate3) (gs : List TwoQubitGate3) : + twoQubitCount (g :: gs) = twoQubitCount gs + 1 := by + rw [twoQubitCount, twoQubitCount, List.length_cons] + +/-- Two-qubit-gate counts add over concatenation. -/ +theorem twoQubitCount_append (gs hs : List TwoQubitGate3) : + twoQubitCount (gs ++ hs) = twoQubitCount gs + twoQubitCount hs := by + rw [twoQubitCount, twoQubitCount, twoQubitCount, List.length_append] + +end AxQM diff --git a/LeanPool/AxQM/Core/UniversalityReduction.lean b/LeanPool/AxQM/Core/UniversalityReduction.lean new file mode 100644 index 0000000000..add51447c2 --- /dev/null +++ b/LeanPool/AxQM/Core/UniversalityReduction.lean @@ -0,0 +1,96 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution + +/-! +# The universality-reduction principle + +Nielsen & Chuang's universality arguments repeatedly take the shape *"gate family `𝒢` is already +universal; a new resource can perform every gate of `𝒢`; therefore the new resource is universal"*. +This is the reduction behind **Problem 4.6** (a resource of single-qubit unitaries, Bell-basis +measurements and four-qubit state preparation performing `CNOT` and single-qubit gates), Exercise +7.52 (`√SWAP` with single-qubit gates performing `CNOT`), and every "complete the gate set" argument +in §4.5. This file isolates that reduction as one reusable theorem, independent of *which* resource, +gate family, or register is in play. + +"Universality of a family `IsGenerator` on a register `S`" is expressed in the library's standard +list-decomposition form (the shape of `linearOptics_universal`): every `E : Evolution S` is a finite +ordered product `L.prod` of gates each satisfying `IsGenerator`. "A resource *realizes* `U`" is +modelled by an arbitrary predicate `Realizes` that contains the identity and is closed under +composition — the algebraic shell shared by every concrete notion of deterministic implementation (a +single available gate, a measurement-based gadget, a whole circuit). The reduction then says: a +resource that realizes each generator of a universal family realizes *every* evolution. + +## What is formalised + +* `Evolution.realizes_of_universal` — the reduction in predicate form: if `Realizes 1`, `Realizes` + is closed under `Evolution.comp`, and every `IsGenerator` gate is realized, then every evolution + of a universal family is realized. +* `Evolution.submonoid_eq_top_of_universal` — the `Submonoid` phrasing: a submonoid of `Evolution S` + containing a universal generating family is `⊤` (all evolutions). + +## Design notes + +* The `Realizes` predicate is deliberately abstract. A concrete universality result supplies the + register `S`, the generating family `IsGenerator`, and the realizability notion `Realizes`, then + discharges the three hypotheses. For Problem 4.6, the `hgen` obligation splits into: single-qubit + generators, realized by direct application (resource #1); and the `CNOT` generator, realized by + the gate-teleportation gadget + (`bellPairsMeasurement_corrected_reducedRight_gateTeleportResourceRegister`). `hUniversal` is + N&C's *given* that `{CNOT, single-qubit}` is a universal gate set. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **The universality reduction (predicate form).** Let `Realizes` be a predicate on `Evolution S` +that holds for the identity (`hone`) and is closed under composition (`hcomp`) — the algebraic shape +of "the resource can deterministically perform this unitary operation". If the resource realizes +every gate of a family `IsGenerator` (`hgen`), and that family is *universal* — every evolution is a +finite ordered product of its gates (`hUniversal`, the library's `linearOptics_universal`-style +statement) — then the resource realizes **every** evolution `E`. + +This is the logical core of "adding the missing gate makes a set universal": one instantiates +`IsGenerator` with `{CNOT, single-qubit gates}` (universal by hypothesis, N&C's given) and shows the +new resource realizes each — whence, by this theorem, it realizes all of `U(S)`. The proof feeds +the decomposition into `List.prod_induction`: the empty product is the identity (`hone`) and each +factor, realized by `hgen`, is folded in by `hcomp`. -/ +theorem Evolution.realizes_of_universal + {Realizes : Evolution S → Prop} {IsGenerator : Evolution S → Prop} + (hone : Realizes 1) + (hcomp : ∀ {U V : Evolution S}, Realizes U → Realizes V → Realizes (U.comp V)) + (hgen : ∀ V : Evolution S, IsGenerator V → Realizes V) + (hUniversal : ∀ E : Evolution S, + ∃ L : List (Evolution S), (∀ V ∈ L, IsGenerator V) ∧ L.prod = E) + (E : Evolution S) : Realizes E := by + obtain ⟨L, hL, rfl⟩ := hUniversal E + exact List.prod_induction Realizes (fun _ _ => hcomp) hone fun V hV => hgen V (hL V hV) + +/-- **The universality reduction (submonoid form).** If a submonoid `M` of the evolution monoid +`Evolution S` contains every gate of a universal generating family `IsGenerator` (`hgen`; universal +via `hUniversal`), then `M = ⊤`: it contains every evolution. This is `realizes_of_universal` +specialised to `Realizes := (· ∈ M)`, whose `hone`/`hcomp` are `M.one_mem`/`M.mul_mem`. Use it when +the realizable operations are literally the circuits over a gate family (their `Submonoid.closure`), +so "universal" reads as "the closure is everything". -/ +theorem Evolution.submonoid_eq_top_of_universal + {M : Submonoid (Evolution S)} {IsGenerator : Evolution S → Prop} + (hgen : ∀ V : Evolution S, IsGenerator V → V ∈ M) + (hUniversal : ∀ E : Evolution S, + ∃ L : List (Evolution S), (∀ V ∈ L, IsGenerator V) ∧ L.prod = E) : + M = ⊤ := by + rw [eq_top_iff] + intro E _ + exact Evolution.realizes_of_universal M.one_mem M.mul_mem hgen hUniversal E + +end AxQM diff --git a/LeanPool/AxQM/Core/WireGatherPermutation.lean b/LeanPool/AxQM/Core/WireGatherPermutation.lean new file mode 100644 index 0000000000..f0c3099381 --- /dev/null +++ b/LeanPool/AxQM/Core/WireGatherPermutation.lean @@ -0,0 +1,232 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.PlacedMultiControlledX + +/-! +# Realising a *chosen* `Cᵏ(X)` gate `(S, t)` (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit of `Toffoli`, +`CNOT` and single-qubit gates implementing `Cⁿ(X)`. The recursive Barenco construction bottoms out +into a sequence of multiply-controlled `NOT` gates `Cᵏ(X)` (`k ≤ 2` are exactly the +`Toffoli`/`CNOT`/`NOT` gates), **each addressed to a prescribed control set `S` and target wire +`t`** of the register — the gate `Concrete.mcNot S t` of the classical circuit +`Concrete.mcNotDenote`. + +The gate `Evolution.placedMcCtrlX k b σ` realises a `Cᵏ(X)` on the wire set `σ 0, …, σ k` carried +by an explicit wire permutation `σ : Equiv.Perm (Fin (k + 1 + b))`, and `placedMcCtrlX_congr` +proves the gate depends only on the resulting wire data `(Cσ, tσ)`. The combinatorial converse — +*given* a control set `S` and target `t`, build a `σ` that gathers them onto the front block — is +supplied here, and the file reads off the resulting gate's computational-basis truth table as +`Concrete.mcNot S t`, so the classical circuit's gates can each be turned into an `Evolution`. + +## What is formalised + +* `wireGatherPerm S t hk ht` — the **wire-gather permutation** of `Fin (k + 1 + b)`: for a control + set `S` with `S.card = k` and a target `t ∉ S`, an `Equiv.Perm` that sends the `k` front control + wires (`Fin.castAdd b ∘ Fin.castSucc`) onto `S` (in increasing order), the front target wire + (`Fin.castAdd b (Fin.last k)`) onto `t`, and the remaining `b` wires onto the complement + `(insert t S)ᶜ`. Built as `Equiv.ofBijective` of the piecewise function `gatherFun` assembled + from the order embeddings `Finset.orderEmbOfFin` of `S` and of `(insert t S)ᶜ`. +* `wireGatherPerm_castAdd_last`, `wireGatherPerm_image_cnxControls` — the two **gather properties**: + the front target wire maps to `t`, and the image of the `k` front control wires `cnxControls k` + under `σ ∘ Fin.castAdd b` is exactly `S`. These are precisely the hypotheses + `placedMcCtrlX_evolvePure_qubitBasis` reads its control set / target off of. +* `placedMcCtrlX_wireGather_evolvePure_qubitBasis` — the **payoff**: the placed gate + `Evolution.placedMcCtrlX k b (wireGatherPerm S t hk ht)` acts on the computational product basis + `⨂ₖ |c k⟩` exactly as the classical gate `Concrete.mcNot S t`. So a `Cᵏ(X)` addressed to *any* + prescribed `(S, t)` (with `|S| = k`, `t ∉ S`) is realised as a genuine closed-system `Evolution` + on the `(k+1+b)`-wire qubit register with the intended truth table — the per-gate realisation the + circuit assembly composes. + +Two general facts about the control-wire set `cnxControls` used here — +`mem_cnxControls` (membership is `(j : ℕ) < k`) and `cnxControls_eq_image_castSucc` +(`cnxControls k = Finset.univ.image Fin.castSucc`, the front `k` wires as the `Fin.castSucc` +image) — are proved next to the `cnxControls` definition in +`AxQM/Core/MultiControlledNotBasis.lean`. + +## Design notes + +* **Why the register is `Fin (k + 1 + b)`, not `Fin m`.** `Evolution.placedMcCtrlX k b σ` lives on + `qubit ^⊗ₛ (k + 1 + b)` by construction, so the gather and its truth table are stated on that + same register — no `cast`. A circuit's gates have *varying* control arity `kᵢ = |Sᵢ| ∈ {0, 1, 2}`, + so a gate on a fixed ambient register `Fin m` has `kᵢ + 1 + bᵢ = m` only *propositionally*; + reconciling the per-gate register `Fin (kᵢ + 1 + bᵢ)` with the common `Fin m` is the *separate* + register-cast step (`QSystem.tensorPowCongr`), applied where the gates are composed. + The gather here is kept free of that cast. +* **Why `Equiv.ofBijective` of a piecewise `gatherFun`.** The three domain blocks — the `k` front + controls, the front target, the `b` back wires — map to the three *disjoint* codomain finsets + `S`, `{t}`, `(insert t S)ᶜ` (a partition, since `|S| = k`, `t ∉ S`, `|(insert t S)ᶜ| = b`). + Injectivity is a `Fin.addCases`/`Fin.lastCases` case analysis whose cross-block cases are closed + by disjointness (`Finset.orderEmbOfFin_mem` places each value in its block, and the blocks are + pairwise disjoint) and whose same-block cases are the injectivity of the order embeddings; on a + finite type injective ⇒ bijective (`Finite.injective_iff_bijective`). Using `Finset.orderEmbOfFin` + (whose values enumerate `S`) makes both the membership facts one-liners and the image equation + `Finset.univ.image (S.orderEmbOfFin hk) = S` exactly `Finset.image_orderEmbOfFin_univ`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {k b : ℕ} + +/-- The complement `(insert t S)ᶜ` of the gate's support has exactly `b` wires (the number of +ambient wires the placed gate acts on as identity): `|(insert t S)ᶜ| = (k+1+b) - (k+1) = b`, using +`|insert t S| = |S| + 1 = k + 1` (as `t ∉ S`). -/ +theorem card_compl_insert (S : Finset (Fin (k + 1 + b))) (t : Fin (k + 1 + b)) + (hk : S.card = k) (ht : t ∉ S) : (insert t S)ᶜ.card = b := by + rw [Finset.card_compl, Fintype.card_fin, Finset.card_insert_of_notMem ht, hk]; omega + +/-- The piecewise **gather function** on `Fin (k + 1 + b)` underlying `wireGatherPerm`: send the +front control wires `Fin.castAdd b (Fin.castSucc i)` to the `i`-th element of `S` (in increasing +order, `S.orderEmbOfFin`), the front target wire `Fin.castAdd b (Fin.last k)` to `t`, and the back +wires `Fin.natAdd (k+1) j` to the `j`-th element of the complement `(insert t S)ᶜ`. -/ +def gatherFun (S : Finset (Fin (k + 1 + b))) (t : Fin (k + 1 + b)) + (hk : S.card = k) (ht : t ∉ S) : Fin (k + 1 + b) → Fin (k + 1 + b) := + Fin.addCases + (fun y => Fin.lastCases (motive := fun _ => Fin (k + 1 + b)) t + (fun i => S.orderEmbOfFin hk i) y) + (fun j => (insert t S)ᶜ.orderEmbOfFin (card_compl_insert S t hk ht) j) + +variable (S : Finset (Fin (k + 1 + b))) (t : Fin (k + 1 + b)) (hk : S.card = k) (ht : t ∉ S) + +/-- `gatherFun` on a front control wire `Fin.castAdd b (Fin.castSucc i)` is the `i`-th element of +`S`. -/ +theorem gatherFun_castAdd_castSucc (i : Fin k) : + gatherFun S t hk ht (Fin.castAdd b (Fin.castSucc i)) = S.orderEmbOfFin hk i := by + simp only [gatherFun, Fin.addCases_left, Fin.lastCases_castSucc] + +/-- `gatherFun` on the front target wire `Fin.castAdd b (Fin.last k)` is the target `t`. -/ +theorem gatherFun_castAdd_last : + gatherFun S t hk ht (Fin.castAdd b (Fin.last k)) = t := by + simp only [gatherFun, Fin.addCases_left, Fin.lastCases_last] + +/-- `gatherFun` on a back wire `Fin.natAdd (k+1) j` is the `j`-th element of the complement. -/ +theorem gatherFun_natAdd (j : Fin b) : + gatherFun S t hk ht (Fin.natAdd (k + 1) j) + = (insert t S)ᶜ.orderEmbOfFin (card_compl_insert S t hk ht) j := by + simp only [gatherFun, Fin.addCases_right] + +/-- **`gatherFun` is injective.** Its three domain blocks (front controls, front target, back +wires) map to the three disjoint finsets `S`, `{t}`, `(insert t S)ᶜ`; a +`Fin.addCases`/`Fin.lastCases` case analysis closes cross-block cases by disjointness and same-block +cases by the injectivity of the order embeddings. -/ +theorem gatherFun_injective : Function.Injective (gatherFun S t hk ht) := by + have hAmem : ∀ i, S.orderEmbOfFin hk i ∈ S := fun i => Finset.orderEmbOfFin_mem S hk i + have hCmem : ∀ j, (insert t S)ᶜ.orderEmbOfFin (card_compl_insert S t hk ht) j ∈ (insert t S)ᶜ := + fun j => Finset.orderEmbOfFin_mem _ _ j + intro x y hxy + induction x using Fin.addCases with + | left xl => + induction xl using Fin.lastCases with + | last => + induction y using Fin.addCases with + | left yl => + induction yl using Fin.lastCases with + | last => rfl + | cast yi => + rw [gatherFun_castAdd_last, gatherFun_castAdd_castSucc] at hxy + exact absurd (hxy ▸ hAmem yi) ht + | right yj => + rw [gatherFun_castAdd_last, gatherFun_natAdd] at hxy + have hy := hCmem yj + rw [Finset.mem_compl, Finset.mem_insert, not_or] at hy + exact absurd hxy.symm hy.1 + | cast xi => + induction y using Fin.addCases with + | left yl => + induction yl using Fin.lastCases with + | last => + rw [gatherFun_castAdd_castSucc, gatherFun_castAdd_last] at hxy + exact absurd (hxy ▸ hAmem xi) ht + | cast yi => + rw [gatherFun_castAdd_castSucc, gatherFun_castAdd_castSucc] at hxy + have := (S.orderEmbOfFin hk).injective hxy + rw [this] + | right yj => + rw [gatherFun_castAdd_castSucc, gatherFun_natAdd] at hxy + have hx : S.orderEmbOfFin hk xi ∈ S := hAmem xi + have hy := hCmem yj + rw [Finset.mem_compl, Finset.mem_insert, not_or] at hy + exact absurd (hxy ▸ hx) hy.2 + | right xj => + induction y using Fin.addCases with + | left yl => + induction yl using Fin.lastCases with + | last => + rw [gatherFun_natAdd, gatherFun_castAdd_last] at hxy + have hx := hCmem xj + rw [Finset.mem_compl, Finset.mem_insert, not_or] at hx + exact absurd hxy hx.1 + | cast yi => + rw [gatherFun_natAdd, gatherFun_castAdd_castSucc] at hxy + have hy : S.orderEmbOfFin hk yi ∈ S := hAmem yi + have hx := hCmem xj + rw [Finset.mem_compl, Finset.mem_insert, not_or] at hx + exact absurd (hxy.symm ▸ hy) hx.2 + | right yj => + rw [gatherFun_natAdd, gatherFun_natAdd] at hxy + have := ((insert t S)ᶜ.orderEmbOfFin (card_compl_insert S t hk ht)).injective hxy + rw [this] + +/-- **The wire-gather permutation** of `Fin (k + 1 + b)` for a control set `S` (`S.card = k`) and +target `t ∉ S`: the bijectivisation of `gatherFun`. It gathers the `k` front control wires onto +`S`, the front target wire onto `t`, and the `b` back wires onto `(insert t S)ᶜ` — the permutation +to feed into `Evolution.placedMcCtrlX` to place a `Cᵏ(X)` on the prescribed wires `(S, t)`. -/ +def wireGatherPerm : Equiv.Perm (Fin (k + 1 + b)) := + Equiv.ofBijective (gatherFun S t hk ht) + (Finite.injective_iff_bijective.mp (gatherFun_injective S t hk ht)) + +/-- `wireGatherPerm` applies as its underlying `gatherFun` (definitional). -/ +theorem wireGatherPerm_apply (x : Fin (k + 1 + b)) : + wireGatherPerm S t hk ht x = gatherFun S t hk ht x := rfl + +/-- **Target gather property**: `wireGatherPerm` sends the front target wire +`Fin.castAdd b (Fin.last k)` to the prescribed target `t`. This is the target +`placedMcCtrlX_evolvePure_qubitBasis` reads off the placed gate. -/ +theorem wireGatherPerm_castAdd_last : + wireGatherPerm S t hk ht (Fin.castAdd b (Fin.last k)) = t := by + rw [wireGatherPerm_apply, gatherFun_castAdd_last] + +/-- **Controls gather property**: the image of the `k` front control wires `cnxControls k` under +`wireGatherPerm ∘ Fin.castAdd b` is exactly the prescribed control set `S`. This is the control set +`placedMcCtrlX_evolvePure_qubitBasis` reads off the placed gate. Proved by reindexing +`cnxControls k` as `Finset.univ.image Fin.castSucc`, evaluating the gather on each front control +wire to the matching element of `S`, and closing with `Finset.image_orderEmbOfFin_univ` (the order +embedding of `S` enumerates `S`). -/ +theorem wireGatherPerm_image_cnxControls : + (cnxControls k).image (fun j => wireGatherPerm S t hk ht (Fin.castAdd b j)) = S := by + simp only [cnxControls_eq_image_castSucc, Finset.image_image, Function.comp_def, + wireGatherPerm_apply, gatherFun_castAdd_castSucc] + exact Finset.image_orderEmbOfFin_univ S hk + +/-- **Computational-basis truth table of the `(S, t)`-addressed `Cᵏ(X)`.** Placing the `Cᵏ(X)` gate +on the wires gathered by `wireGatherPerm S t hk ht` yields a gate whose action on the computational +product basis `⨂ₖ |c k⟩` is exactly the classical multiply-controlled `NOT` `Concrete.mcNot S t`: +`placedMcCtrlX k b (wireGatherPerm S t hk ht) (⨂ₖ |c k⟩) = ⨂ₖ |mcNot S t c k⟩`. + +So a `Cᵏ(X)` addressed to *any* prescribed control set `S` (`|S| = k`) and target `t ∉ S` is +realised as a genuine closed-system `Evolution` on the `(k+1+b)`-wire qubit register with the +intended truth table — the per-gate realisation the `O(n²)` circuit assembly composes (each gate of +`Concrete.mcNotDenote`). Immediate from `placedMcCtrlX_evolvePure_qubitBasis` once the +placed gate's control set and target are rewritten to `S` and `t` by the two gather properties. -/ +theorem placedMcCtrlX_wireGather_evolvePure_qubitBasis (c : Fin (k + 1 + b) → Fin 2) : + (Evolution.placedMcCtrlX k b (wireGatherPerm S t hk ht)).evolvePure + (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => qubitBasis (Concrete.mcNot S t c i) := by + rw [placedMcCtrlX_evolvePure_qubitBasis, wireGatherPerm_image_cnxControls, + wireGatherPerm_castAdd_last] + +end AxQM diff --git a/LeanPool/AxQM/Imports.lean b/LeanPool/AxQM/Imports.lean new file mode 100644 index 0000000000..777e62cf1d --- /dev/null +++ b/LeanPool/AxQM/Imports.lean @@ -0,0 +1,672 @@ +/- +Copyright (c) 2026 Lean Pool contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Lean Pool contributors +-/ +module -- shake: keep-all --deprecated_module: ignore + +-- Generated project imports; run `lake exe mk_all`. +public import LeanPool.AxQM +public import LeanPool.AxQM.Concrete.ABCDecomposition +public import LeanPool.AxQM.Concrete.AxisAngleDecomposition +public import LeanPool.AxQM.Concrete.AxisAngleGateValues +public import LeanPool.AxQM.Concrete.BlochMatrix +public import LeanPool.AxQM.Concrete.BlochPureState +public import LeanPool.AxQM.Concrete.BlochRotation +public import LeanPool.AxQM.Concrete.BlochUnitaryRotation +public import LeanPool.AxQM.Concrete.BlockDiagonalPeel +public import LeanPool.AxQM.Concrete.BlockOneEmbedding +public import LeanPool.AxQM.Concrete.CheckMatrix +public import LeanPool.AxQM.Concrete.ClassicalTraceDistance +public import LeanPool.AxQM.Concrete.CliffordCircuitInverse +public import LeanPool.AxQM.Concrete.CliffordStabilizerTracking +public import LeanPool.AxQM.Concrete.CnotWirePermGate +public import LeanPool.AxQM.Concrete.CollectorZRotation +public import LeanPool.AxQM.Concrete.ComplexExpUnit +public import LeanPool.AxQM.Concrete.ControlledSingleQubit +public import LeanPool.AxQM.Concrete.ControlledSingleQubitConjugation +public import LeanPool.AxQM.Concrete.ControlledSingleQubitNormalisation +public import LeanPool.AxQM.Concrete.DensityMatrixRealDimension +public import LeanPool.AxQM.Concrete.FourGateUniversality +public import LeanPool.AxQM.Concrete.GivensRotation +public import LeanPool.AxQM.Concrete.GrayCode +public import LeanPool.AxQM.Concrete.Hadamard +public import LeanPool.AxQM.Concrete.HadamardABC +public import LeanPool.AxQM.Concrete.HadamardPauliConjugation +public import LeanPool.AxQM.Concrete.HadamardRotation +public import LeanPool.AxQM.Concrete.KronFamilyWireProduct +public import LeanPool.AxQM.Concrete.MultiControlledNot +public import LeanPool.AxQM.Concrete.MultiControlledNotBorrowedMcNot +public import LeanPool.AxQM.Concrete.MultiControlledNotCircuit +public import LeanPool.AxQM.Concrete.MultiControlledNotDirtyCascade +public import LeanPool.AxQM.Concrete.MultiControlledNotGate +public import LeanPool.AxQM.Concrete.MultiControlledNotPermProduct +public import LeanPool.AxQM.Concrete.MultiControlledNotSplit +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubit +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitABCReduction +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitBarenco +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitSpareReduction +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitTightReduction +public import LeanPool.AxQM.Concrete.NmrTomographyExperimentCount +public import LeanPool.AxQM.Concrete.Pauli +public import LeanPool.AxQM.Concrete.PauliEigenstateBloch +public import LeanPool.AxQM.Concrete.PauliEigenvectors +public import LeanPool.AxQM.Concrete.PauliExponential +public import LeanPool.AxQM.Concrete.PauliGroup +public import LeanPool.AxQM.Concrete.PauliGroupNegOne +public import LeanPool.AxQM.Concrete.PauliNormalizer +public import LeanPool.AxQM.Concrete.PauliNormalizerCnotClear +public import LeanPool.AxQM.Concrete.PauliNormalizerDecouple +public import LeanPool.AxQM.Concrete.PauliNormalizerFirstPair +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCount +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountFirstPair +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountGadgets +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountPair +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountReduce +public import LeanPool.AxQM.Concrete.PauliNormalizerGateCountSynthesis +public import LeanPool.AxQM.Concrete.PauliNormalizerGenerators +public import LeanPool.AxQM.Concrete.PauliNormalizerInduction +public import LeanPool.AxQM.Concrete.PauliNormalizerLayer +public import LeanPool.AxQM.Concrete.PauliNormalizerPairReduce +public import LeanPool.AxQM.Concrete.PauliNormalizerReduceGenerator +public import LeanPool.AxQM.Concrete.PauliNormalizerRestrict +public import LeanPool.AxQM.Concrete.PauliNormalizerRestrictNormalizer +public import LeanPool.AxQM.Concrete.PauliNormalizerSwap +public import LeanPool.AxQM.Concrete.PauliNormalizerSweep +public import LeanPool.AxQM.Concrete.PauliNormalizerSymplectic +public import LeanPool.AxQM.Concrete.PauliNormalizerZClear +public import LeanPool.AxQM.Concrete.PauliOuterProduct +public import LeanPool.AxQM.Concrete.PauliString +public import LeanPool.AxQM.Concrete.PauliStringBasisChange +public import LeanPool.AxQM.Concrete.PauliStringCliffordCircuit +public import LeanPool.AxQM.Concrete.PauliStringCliffordConjugation +public import LeanPool.AxQM.Concrete.PauliStringCnotConjugation +public import LeanPool.AxQM.Concrete.PauliStringCommutation +public import LeanPool.AxQM.Concrete.PauliStringDiagonalize +public import LeanPool.AxQM.Concrete.PauliStringEncodingCnotLayer +public import LeanPool.AxQM.Concrete.PauliStringEncodingLayers +public import LeanPool.AxQM.Concrete.PauliStringEncodingPhaseCZLayer +public import LeanPool.AxQM.Concrete.PauliStringLocality +public import LeanPool.AxQM.Concrete.PauliStringParityCascade +public import LeanPool.AxQM.Concrete.PauliStringStdInvolution +public import LeanPool.AxQM.Concrete.PauliTomography +public import LeanPool.AxQM.Concrete.PermutationGate +public import LeanPool.AxQM.Concrete.PiEighthGate +public import LeanPool.AxQM.Concrete.PlusStateTensorPower +public import LeanPool.AxQM.Concrete.QFTTwoLevel +public import LeanPool.AxQM.Concrete.QftGateCircuit +public import LeanPool.AxQM.Concrete.QftGateCircuitCorrectness +public import LeanPool.AxQM.Concrete.QftGateCircuitEqMatrix +public import LeanPool.AxQM.Concrete.QftGateCircuitState +public import LeanPool.AxQM.Concrete.QftGateCount +public import LeanPool.AxQM.Concrete.QftProductRepresentation +public import LeanPool.AxQM.Concrete.QuantumFourierTransform +public import LeanPool.AxQM.Concrete.ReachableCircuits +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.Concrete.RotationConjugation +public import LeanPool.AxQM.Concrete.RotationDecomposition +public import LeanPool.AxQM.Concrete.RotationDecompositionXY +public import LeanPool.AxQM.Concrete.RotationDensity +public import LeanPool.AxQM.Concrete.SingleQubitRotationUniversality +public import LeanPool.AxQM.Concrete.SingleQubitWire +public import LeanPool.AxQM.Concrete.SpecialOrthogonalAxisAngle +public import LeanPool.AxQM.Concrete.SpecialOrthogonalFixedAxis +public import LeanPool.AxQM.Concrete.SqrtNot +public import LeanPool.AxQM.Concrete.StabilizerCodeDimension +public import LeanPool.AxQM.Concrete.StabilizerCodeProjector +public import LeanPool.AxQM.Concrete.StabilizerErrorCorrection +public import LeanPool.AxQM.Concrete.StabilizerGeneratorFlip +public import LeanPool.AxQM.Concrete.StabilizerSimulationCost +public import LeanPool.AxQM.Concrete.StabilizerSimulator +public import LeanPool.AxQM.Concrete.TraceDistancePOVM +public import LeanPool.AxQM.Concrete.TwoLevelColumnClear +public import LeanPool.AxQM.Concrete.TwoLevelControlledDecomposition +public import LeanPool.AxQM.Concrete.TwoLevelControlledIdentification +public import LeanPool.AxQM.Concrete.TwoLevelControlledProduct +public import LeanPool.AxQM.Concrete.TwoLevelDecomposition +public import LeanPool.AxQM.Concrete.TwoLevelEmbedding +public import LeanPool.AxQM.Concrete.TwoLevelGrayWalk +public import LeanPool.AxQM.Concrete.TwoLevelSwap +public import LeanPool.AxQM.Concrete.TwoLevelSwapChain +public import LeanPool.AxQM.Concrete.TwoLevelSwapList +public import LeanPool.AxQM.Concrete.UnitaryControlledProduct +public import LeanPool.AxQM.Concrete.UnitarySquareRoot +public import LeanPool.AxQM.Concrete.UnitaryToffoliSingleQubitProduct +public import LeanPool.AxQM.Core.BarencoBlockFlatten +public import LeanPool.AxQM.Core.BarencoBlockReduction +public import LeanPool.AxQM.Core.BarencoLayerBudget +public import LeanPool.AxQM.Core.BarencoLinearBlockReduction +public import LeanPool.AxQM.Core.BarencoSplitLinearBlockReduction +public import LeanPool.AxQM.Core.BarencoTailReduction +public import LeanPool.AxQM.Core.BorrowedMcNotEvolution +public import LeanPool.AxQM.Core.ChannelHolevoChi +public import LeanPool.AxQM.Core.ChannelHolevoChiEnsemble +public import LeanPool.AxQM.Core.ChannelHolevoChiPure +public import LeanPool.AxQM.Core.ChannelHolevoChiPureCard +public import LeanPool.AxQM.Core.CircuitBudget +public import LeanPool.AxQM.Core.CircuitBudgetAdjoint +public import LeanPool.AxQM.Core.CircuitBudgetOnRight +public import LeanPool.AxQM.Core.CircuitBudgetOnRightTower +public import LeanPool.AxQM.Core.CircuitBudgetSingleWire +public import LeanPool.AxQM.Core.CnotFanEvolutionBudget +public import LeanPool.AxQM.Core.ConditionalEntropy +public import LeanPool.AxQM.Core.ControlledPowerSequence +public import LeanPool.AxQM.Core.DeferredMeasurementReading +public import LeanPool.AxQM.Core.DistillableEntanglement +public import LeanPool.AxQM.Core.EntanglementEntropyMonotone +public import LeanPool.AxQM.Core.EntropyTensorPow +public import LeanPool.AxQM.Core.EvolutionQubitBasisExt +public import LeanPool.AxQM.Core.EvolutionTowerBasisExt +public import LeanPool.AxQM.Core.FourGateNamedReversibleTower +public import LeanPool.AxQM.Core.FourGateNamedRotationTower +public import LeanPool.AxQM.Core.FourGateNamedTower +public import LeanPool.AxQM.Core.FourGateReachableCircuitTower +public import LeanPool.AxQM.Core.FourGateReachableWireSubmonoid +public import LeanPool.AxQM.Core.FourGateReachableWireTower +public import LeanPool.AxQM.Core.FourGateReversibleWireTower +public import LeanPool.AxQM.Core.FredkinFiveGateCircuit +public import LeanPool.AxQM.Core.FredkinFiveGateSwapIdentity +public import LeanPool.AxQM.Core.FredkinTwoQubitCircuit +public import LeanPool.AxQM.Core.GateCircuit +public import LeanPool.AxQM.Core.GlobalPhaseCircuitBudget +public import LeanPool.AxQM.Core.HolevoChi +public import LeanPool.AxQM.Core.HolevoChiBound +public import LeanPool.AxQM.Core.LOCCProtocol +public import LeanPool.AxQM.Core.McNotCircuitBudget +public import LeanPool.AxQM.Core.McNotCircuitDecomposition +public import LeanPool.AxQM.Core.McNotCircuitEvolution +public import LeanPool.AxQM.Core.MeasuredQftOuterStep +public import LeanPool.AxQM.Core.MeasurementChannel +public import LeanPool.AxQM.Core.MultiControlledNotBasis +public import LeanPool.AxQM.Core.MultiControlledReduction +public import LeanPool.AxQM.Core.MultiControlledTowerAction +public import LeanPool.AxQM.Core.NmrTomographyReconstruction +public import LeanPool.AxQM.Core.PauliDiagWireTower +public import LeanPool.AxQM.Core.PauliStringExpCircuitBudget +public import LeanPool.AxQM.Core.PauliTomographyExpectation +public import LeanPool.AxQM.Core.PauliTrotterCapstoneBudget +public import LeanPool.AxQM.Core.PauliTrotterStepBudget +public import LeanPool.AxQM.Core.PauliTrotterSummandBudget +public import LeanPool.AxQM.Core.PhaseLayerBudget +public import LeanPool.AxQM.Core.PhaseWireTower +public import LeanPool.AxQM.Core.PiTensorSuccHead +public import LeanPool.AxQM.Core.PlacedMultiControlledX +public import LeanPool.AxQM.Core.ProductStateAvgAchievable +public import LeanPool.AxQM.Core.ProductStateCapacity +public import LeanPool.AxQM.Core.ProductStateCode +public import LeanPool.AxQM.Core.ProductStateCodeExpurgation +public import LeanPool.AxQM.Core.ProductStateCodePrettyGood +public import LeanPool.AxQM.Core.ProjectorPropagatorConjugation +public import LeanPool.AxQM.Core.QftRegisterBridge +public import LeanPool.AxQM.Core.QftTowerBasis +public import LeanPool.AxQM.Core.QftTowerCircuit +public import LeanPool.AxQM.Core.QftTowerControlled +public import LeanPool.AxQM.Core.QftTowerHadamard +public import LeanPool.AxQM.Core.QftTowerHeadLayer +public import LeanPool.AxQM.Core.QftTowerPeel +public import LeanPool.AxQM.Core.QftTowerPhaseRecursion +public import LeanPool.AxQM.Core.QftTowerProductForm +public import LeanPool.AxQM.Core.QftTowerProductRep +public import LeanPool.AxQM.Core.QftTowerRecursion +public import LeanPool.AxQM.Core.QftTowerSwap +public import LeanPool.AxQM.Core.QtowerComposeRight +public import LeanPool.AxQM.Core.QtowerControlQft +public import LeanPool.AxQM.Core.QtowerCtrlWireGate +public import LeanPool.AxQM.Core.QtowerHadamardLayer +public import LeanPool.AxQM.Core.QtowerHeadIdleMeasurement +public import LeanPool.AxQM.Core.QtowerHeadPhaseControl +public import LeanPool.AxQM.Core.QtowerMeasurement +public import LeanPool.AxQM.Core.QtowerPermMeasurement +public import LeanPool.AxQM.Core.QtowerPhaseGradient +public import LeanPool.AxQM.Core.QtowerSingleWireGate +public import LeanPool.AxQM.Core.QtowerTensorPow +public import LeanPool.AxQM.Core.QtowerWirePermutation +public import LeanPool.AxQM.Core.QuditPowTower +public import LeanPool.AxQM.Core.SplitMcNotEvolution +public import LeanPool.AxQM.Core.SplitMcNotOnBlock +public import LeanPool.AxQM.Core.StrictContraction +public import LeanPool.AxQM.Core.TensorPowMultiControlledX +public import LeanPool.AxQM.Core.TwoQubitGateCircuit +public import LeanPool.AxQM.Core.UniversalityReduction +public import LeanPool.AxQM.Core.WireGatherPermutation +public import LeanPool.AxQM.NC.Ch11.Exercise24 +public import LeanPool.AxQM.NC.Ch11.StrongSubadditivityGeneral +public import LeanPool.AxQM.NC.Ch11.Subadditivity +public import LeanPool.AxQM.NC.Ch11.Theorem10 +public import LeanPool.AxQM.NC.Ch11.Theorem15 +public import LeanPool.AxQM.NC.Ch11.Theorem16 +public import LeanPool.AxQM.NC.Ch11.Theorem6 +public import LeanPool.AxQM.NC.Ch11.Theorem8 +public import LeanPool.AxQM.NC.Ch11.Theorem9 +public import LeanPool.AxQM.NC.Ch11.TriangleInequality +public import LeanPool.AxQM.NC.Ch12.CoherentInformation +public import LeanPool.AxQM.NC.Ch12.Problem1 +public import LeanPool.AxQM.NC.Ch12.Theorem1 +public import LeanPool.AxQM.NC.Ch12.Theorem10 +public import LeanPool.AxQM.NC.Ch12.Theorem15 +public import LeanPool.AxQM.NC.Ch12.Theorem5 +public import LeanPool.AxQM.NC.Ch12.Theorem6 +public import LeanPool.AxQM.NC.Ch12.Theorem8 +public import LeanPool.AxQM.NC.Ch2.Exercise74 +public import LeanPool.AxQM.NC.Ch2.Exercise78 +public import LeanPool.AxQM.NC.Ch2.Problem2 +public import LeanPool.AxQM.NC.Ch2.Theorem5 +public import LeanPool.AxQM.NC.Ch2.Theorem6 +public import LeanPool.AxQM.NC.Ch4.Exercise1 +public import LeanPool.AxQM.NC.Ch9.Theorem1 +public import LeanPool.AxQM.NC.Ch9.Theorem3 +public import LeanPool.AxQM.NC.Ch9.Theorem4 +public import LeanPool.AxQM.NC.Ch9.Theorem6 +public import LeanPool.AxQM.NC.Ch9.Theorem7 +public import LeanPool.AxQM.Postulates.API.AdaptiveMeasurement +public import LeanPool.AxQM.Postulates.API.ArakiLiebEqualityConditions +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.AvgOutputTypicalSubspace +public import LeanPool.AxQM.Postulates.API.AxisAngleGateValues +public import LeanPool.AxQM.Postulates.API.AxisAngleRotation +public import LeanPool.AxQM.Postulates.API.BellBasis +public import LeanPool.AxQM.Postulates.API.BellReducedState +public import LeanPool.AxQM.Postulates.API.BellState +public import LeanPool.AxQM.Postulates.API.BlochRotationGate +public import LeanPool.AxQM.Postulates.API.BlochState +public import LeanPool.AxQM.Postulates.API.BlockGatePlacement +public import LeanPool.AxQM.Postulates.API.CNOTDensityMatrix +public import LeanPool.AxQM.Postulates.API.CascadedMeasurement +public import LeanPool.AxQM.Postulates.API.CertainMeasurement +public import LeanPool.AxQM.Postulates.API.CnotFanEvolution +public import LeanPool.AxQM.Postulates.API.CnotPauliPropagation +public import LeanPool.AxQM.Postulates.API.CnotRotationCommutation +public import LeanPool.AxQM.Postulates.API.CnotXBasis +public import LeanPool.AxQM.Postulates.API.CollectorZRotationEvolution +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement +public import LeanPool.AxQM.Postulates.API.CompositeReducedEvolution +public import LeanPool.AxQM.Postulates.API.CompositeState +public import LeanPool.AxQM.Postulates.API.CompositeStateEvolution +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspace +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceConfusion +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceDecoder +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceDiagonal +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceExpectation +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceFrame +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspacePerCode +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspacePerCodeError +public import LeanPool.AxQM.Postulates.API.ConditionalEntropyConcave +public import LeanPool.AxQM.Postulates.API.ContinuousSearchHamiltonian +public import LeanPool.AxQM.Postulates.API.ControlBranchExt +public import LeanPool.AxQM.Postulates.API.ControlMeasurementCommute +public import LeanPool.AxQM.Postulates.API.ControlPairGates +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.ControlledRotation +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryPhasePlus +public import LeanPool.AxQM.Postulates.API.ControlledZ +public import LeanPool.AxQM.Postulates.API.DeferredMeasurement +public import LeanPool.AxQM.Postulates.API.DeferredMeasurementOnLeft +public import LeanPool.AxQM.Postulates.API.DeferredMeasurementReindex +public import LeanPool.AxQM.Postulates.API.Distinguishability +public import LeanPool.AxQM.Postulates.API.EigenspaceCollapse +public import LeanPool.AxQM.Postulates.API.Eigenstate +public import LeanPool.AxQM.Postulates.API.Ensemble +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.Postulates.API.EntropyConcavity +public import LeanPool.AxQM.Postulates.API.EntropyEvolution +public import LeanPool.AxQM.Postulates.API.EntropyJointTheorem +public import LeanPool.AxQM.Postulates.API.EntropyMixLine +public import LeanPool.AxQM.Postulates.API.EntropyMixture +public import LeanPool.AxQM.Postulates.API.EntropyOrthogonalMixture +public import LeanPool.AxQM.Postulates.API.EntropySpectral +public import LeanPool.AxQM.Postulates.API.ErrorCorrectionDiscretization +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.EvolutionTensorHom +public import LeanPool.AxQM.Postulates.API.Fannes +public import LeanPool.AxQM.Postulates.API.Fidelity +public import LeanPool.AxQM.Postulates.API.FourGateReachableCircuit +public import LeanPool.AxQM.Postulates.API.FourGateReachableRotation +public import LeanPool.AxQM.Postulates.API.FourGateReachableWire +public import LeanPool.AxQM.Postulates.API.FourGateReachableWireMonoid +public import LeanPool.AxQM.Postulates.API.FourGateReversibleWire +public import LeanPool.AxQM.Postulates.API.Fredkin +public import LeanPool.AxQM.Postulates.API.GateCommute +public import LeanPool.AxQM.Postulates.API.GeneralMeasurementEnvironment +public import LeanPool.AxQM.Postulates.API.GeneralizedDepolarizingChannel +public import LeanPool.AxQM.Postulates.API.HadamardABC +public import LeanPool.AxQM.Postulates.API.HadamardEigen +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Postulates.API.HadamardRotation +public import LeanPool.AxQM.Postulates.API.HamiltonianGenerator +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementChannel +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementDilation +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementMarginal +public import LeanPool.AxQM.Postulates.API.InverseQuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.InvolutionPropagatorConjugation +public import LeanPool.AxQM.Postulates.API.InvolutiveObservable +public import LeanPool.AxQM.Postulates.API.KitaevPhaseEstimation +public import LeanPool.AxQM.Postulates.API.LeftPairGate +public import LeanPool.AxQM.Postulates.API.MaxEntMarginal +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.Postulates.API.MeasureObservable +public import LeanPool.AxQM.Postulates.API.MeasureObservableRegister +public import LeanPool.AxQM.Postulates.API.MeasurementCoarseGrain +public import LeanPool.AxQM.Postulates.API.MeasurementExt +public import LeanPool.AxQM.Postulates.API.MeasurementModel +public import LeanPool.AxQM.Postulates.API.MeasurementOperation +public import LeanPool.AxQM.Postulates.API.MeasurementPrecompose +public import LeanPool.AxQM.Postulates.API.MeasurementReindex +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.MutualInformationAncilla +public import LeanPool.AxQM.Postulates.API.MutualInformationEvolution +public import LeanPool.AxQM.Postulates.API.NMRControlledZ +public import LeanPool.AxQM.Postulates.API.NMRCoupledSpinFID +public import LeanPool.AxQM.Postulates.API.Observable +public import LeanPool.AxQM.Postulates.API.PartialTraceReassoc +public import LeanPool.AxQM.Postulates.API.PauliDiagWire +public import LeanPool.AxQM.Postulates.API.PauliEigen +public import LeanPool.AxQM.Postulates.API.PauliExpansion +public import LeanPool.AxQM.Postulates.API.PauliMeasurement +public import LeanPool.AxQM.Postulates.API.PauliStringExpCircuit +public import LeanPool.AxQM.Postulates.API.PauliTomographyExpectation +public import LeanPool.AxQM.Postulates.API.PauliTrotter +public import LeanPool.AxQM.Postulates.API.PauliTrotterStep +public import LeanPool.AxQM.Postulates.API.PauliTrotterSummand +public import LeanPool.AxQM.Postulates.API.PeriodShift +public import LeanPool.AxQM.Postulates.API.PhaseFlipCode +public import LeanPool.AxQM.Postulates.API.PhaseGateEigenbasis +public import LeanPool.AxQM.Postulates.API.PhaseWire +public import LeanPool.AxQM.Postulates.API.PhasedPlus +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Postulates.API.PiTensorEigenbasis +public import LeanPool.AxQM.Postulates.API.PiTensorSuccHead +public import LeanPool.AxQM.Postulates.API.PrettyGoodDecoder +public import LeanPool.AxQM.Postulates.API.ProjectiveMeasurement +public import LeanPool.AxQM.Postulates.API.ProjectorCollapse +public import LeanPool.AxQM.Postulates.API.ProjectorHamiltonian +public import LeanPool.AxQM.Postulates.API.PseudoInverse +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.Postulates.API.Purity +public import LeanPool.AxQM.Postulates.API.QftControlledEvolution +public import LeanPool.AxQM.Postulates.API.QftGateEvolution +public import LeanPool.AxQM.Postulates.API.QftHadamardEvolution +public import LeanPool.AxQM.Postulates.API.QftSwapEvolution +public import LeanPool.AxQM.Postulates.API.QuantumChannel +public import LeanPool.AxQM.Postulates.API.QuantumErrorCorrection +public import LeanPool.AxQM.Postulates.API.QuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.QuantumOperation +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Postulates.API.QubitThree +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.API.QuditDimCongr +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Postulates.API.QuditMeasurement +public import LeanPool.AxQM.Postulates.API.QuditPairPermGate +public import LeanPool.AxQM.Postulates.API.QuditPhaseGradient +public import LeanPool.AxQM.Postulates.API.QuditTensorFactor +public import LeanPool.AxQM.Postulates.API.RandomCodingConfusion +public import LeanPool.AxQM.Postulates.API.RandomCodingConfusionExpectation +public import LeanPool.AxQM.Postulates.API.RandomCodingExpectedError +public import LeanPool.AxQM.Postulates.API.RandomUnitaryChannel +public import LeanPool.AxQM.Postulates.API.RandomUnitaryEntropy +public import LeanPool.AxQM.Postulates.API.ReducedEigenEnsemble +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.ReducedStateLeftBlock +public import LeanPool.AxQM.Postulates.API.ReducedStateReshape +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.Postulates.API.ReferencePurification +public import LeanPool.AxQM.Postulates.API.RelativeEntropy +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.SchmidtDecomposition +public import LeanPool.AxQM.Postulates.API.SchmidtNumber +public import LeanPool.AxQM.Postulates.API.SchumacherConverse +public import LeanPool.AxQM.Postulates.API.SchumacherDirect +public import LeanPool.AxQM.Postulates.API.SquareRootMeasurement +public import LeanPool.AxQM.Postulates.API.StabilizerEvolution +public import LeanPool.AxQM.Postulates.API.StabilizerMeasurement +public import LeanPool.AxQM.Postulates.API.StateMajorization +public import LeanPool.AxQM.Postulates.API.StrongSubadditivity +public import LeanPool.AxQM.Postulates.API.SubadditivityReformulations +public import LeanPool.AxQM.Postulates.API.Support +public import LeanPool.AxQM.Postulates.API.Swap +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.SystemIsoCongrTmul +public import LeanPool.AxQM.Postulates.API.Teleportation +public import LeanPool.AxQM.Postulates.API.TensorPowDim +public import LeanPool.AxQM.Postulates.API.TensorPowMix +public import LeanPool.AxQM.Postulates.API.TensorPowSplit +public import LeanPool.AxQM.Postulates.API.TensorPowState +public import LeanPool.AxQM.Postulates.API.ToffoliHadamard +public import LeanPool.AxQM.Postulates.API.TowerProdMultilinear +public import LeanPool.AxQM.Postulates.API.TraceDistance +public import LeanPool.AxQM.Postulates.API.TrotterProduct +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.Postulates.API.TypicalSubspaceEquipartition +public import LeanPool.AxQM.Postulates.API.Uhlmann +public import LeanPool.AxQM.Postulates.API.UniformSuperposition +public import LeanPool.AxQM.Postulates.API.UnitaryBlochRotation +public import LeanPool.AxQM.Postulates.API.UnitaryFreedom +public import LeanPool.AxQM.Postulates.API.UnitarySquareRoot +public import LeanPool.AxQM.Postulates.API.UnreadMeasurement +public import LeanPool.AxQM.Postulates.API.WeakMonotonicity +public import LeanPool.AxQM.Postulates.API.WeakMonotonicityReducedRight +public import LeanPool.AxQM.Postulates.API.WeakMonotonicitySecondComplement +public import LeanPool.AxQM.Postulates.API.WireGatePlacement +public import LeanPool.AxQM.Postulates.API.WirePermutation +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.Postulates.PartialTraceTensor +public import LeanPool.AxQM.Postulates.PiTensor +public import LeanPool.AxQM.Postulates.PiTensorState +public import LeanPool.AxQM.Postulates.QSystem +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import LeanPool.AxQM.ToMathlib.Algebra.Group.Subgroup.InvolutionClosure +public import LeanPool.AxQM.ToMathlib.Algebra.Ring.Equiv +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ApproximateUnit +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Integral +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousLinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.MatrixToEuclideanCLM +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Unitary.Exp +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Unitary.ExpEndomorphism +public import LeanPool.AxQM.ToMathlib.Analysis.Calculus.Deriv.RingInverse +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.Function +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.FunctionTopology +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.Majorization +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.SierpinskiMidpoint +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.SupportReduction +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamily +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamilySigma +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtTraceInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCTensor +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DensitySubunital +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DepolarizingPartialTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DepolarizingTwirl +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DiagonalOperatorEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Dual +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EigenvalueMonotone +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelityBound +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntropyExchange +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EuclideanConjVec +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.FidelityMonotone +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedInverseSqrt +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedKleinInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeometricMeanMaximality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GramMatrix +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GramSquareRoot +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.IdempotentDensityOp +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.InvolutionRotation +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.JointEigenspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LiebConcavityRpow +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LiebConcavityTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MatricizationRank +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MinimalOperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MirskyInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.NormalOperator +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorBlockRow +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorGram +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumCP +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoi +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiKraus +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiPositive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumComposition +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumDilation +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumFreedom +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumReverse +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumTheorem +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Orthonormal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVM +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVMMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceComm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceLeftBlock +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductDensity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarNormal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarUnitary +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PosNegPart +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PostMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurementError +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Purification +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumConditionalEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumDataCompression +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumErrorCorrection +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumFanoInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyConvexNonfaithful +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyDiagonal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyMonotone +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyPinching +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumStrongSubadditivity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneProjector +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.ReducedState +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchmidtDecomposition +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherCompression +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherConverse +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherEncoder +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchurComplement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SelfAdjointFinrank +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorPower +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProductCongrConj +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Transpose +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Uhlmann +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UhlmannAncilla +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UhlmannMixture +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryExtension +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryTwirl +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyContinuous +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyFano +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyGram +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyMixture +public import LeanPool.AxQM.ToMathlib.Analysis.Matrix.HermitianMajorization +public import LeanPool.AxQM.ToMathlib.Analysis.Matrix.HilbertSchmidt +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.ExponentialInvolution +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.LieTrotter +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.MatrixExponential +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Ring.ProductTelescope +public import LeanPool.AxQM.ToMathlib.Analysis.RCLike.Basic +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.BinaryEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ConditionalEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ConditionalEntropyChain +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Deriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.EntropyDeriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.ResolventBounds +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.ResolventSquareIntegral +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.TraceDeriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.GeometricMean +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.ConjSqrt +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Isometric +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.RingInverseOrder +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.DataProcessingInequality +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.EntropySubadditive +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.Basic +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.NegMulLog +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.RpowTendsto +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.MutualInformationMap +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecificLimits.ExpNatMul +public import LeanPool.AxQM.ToMathlib.Data.Fintype.EquivOfMultisetMap +public import LeanPool.AxQM.ToMathlib.Data.Real.Sqrt +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuation +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuationPi +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuationPiInvolution +public import LeanPool.AxQM.ToMathlib.GroupTheory.Subgroup.Centralizer +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelAchievability +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelCodingTheorem +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelExpurgation +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelRandomCoding +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelRandomCodingLimit +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelTypicalSequence +public import LeanPool.AxQM.ToMathlib.InformationTheory.CollisionEntropy +public import LeanPool.AxQM.ToMathlib.InformationTheory.CollisionEntropyLaw +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalCollisionEntropy +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalTypicalConcentration +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalTypicalSequence +public import LeanPool.AxQM.ToMathlib.InformationTheory.Fano +public import LeanPool.AxQM.ToMathlib.InformationTheory.IIDConcentration +public import LeanPool.AxQM.ToMathlib.InformationTheory.NoiselessCoding +public import LeanPool.AxQM.ToMathlib.InformationTheory.NoisyChannel +public import LeanPool.AxQM.ToMathlib.InformationTheory.RandomCodingExpectation +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence +public import LeanPool.AxQM.ToMathlib.InformationTheory.UniversalHashEntropy +public import LeanPool.AxQM.ToMathlib.InformationTheory.UniversalHashRefutation +public import LeanPool.AxQM.ToMathlib.InformationTheory.UniversalHashing +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Eigenspace.Idempotent +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Hermitian +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.HermitianUnitary +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Kronecker +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Permutation +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.PermutationUnitary +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Trace +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.PiTensorProduct.Finiteness +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.PiTensorProduct.Finrank +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.TensorPower.Endomorphism +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.TensorProduct.Map +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Trace +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.UnitaryGroup +public import LeanPool.AxQM.ToMathlib.NumberTheory.CosThreeFifthsIrrational +public import LeanPool.AxQM.ToMathlib.NumberTheory.DiophantineApproximation.LegendreSharp +public import LeanPool.AxQM.ToMathlib.NumberTheory.NontrivialSqrtOne +public import LeanPool.AxQM.ToMathlib.Probability.WeakLaw +public import LeanPool.AxQM.ToMathlib.RingTheory.ZMod.OrderFinding +public import LeanPool.AxQM.ToMathlib.Topology.Algebra.Module.FiniteDimension +public import LeanPool.AxQM.ToMathlib.Topology.UniformSpace.LocallyUniformConvergence diff --git a/LeanPool/AxQM/NC/Ch11/Exercise24.lean b/LeanPool/AxQM/NC/Ch11/Exercise24.lean new file mode 100644 index 0000000000..7ff620a990 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Exercise24.lean @@ -0,0 +1,153 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.WeakMonotonicity +public import LeanPool.AxQM.Postulates.API.WeakMonotonicityReducedRight +public import LeanPool.AxQM.Postulates.API.WeakMonotonicitySecondComplement +public import LeanPool.AxQM.Postulates.API.ReducedStateLeftBlock +public import LeanPool.AxQM.NC.Ch11.StrongSubadditivityGeneral + +/-! +# N&C Exercise 11.24 — weak monotonicity from strong subadditivity + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, **Exercise 11.24** (p. 521). N&C +obtained strong subadditivity `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` (eq. (11.108)) *from* the +"form-1" inequality — **weak monotonicity** `S(A) + S(B) ≤ S(A,C) + S(B,C)` (eq. (11.107)). The +exercise asks for the converse: derive weak monotonicity **as a consequence of strong +subadditivity**. + +## The result + +`State.vonNeumannEntropy_weakMonotonicity` — for an arbitrary state `ρ` on the tripartite system +`A ⊗ (B ⊗ C)`, + +`S(A) + S(C) ≤ S(A,B) + S(B,C)`, + +with the marginals read off as reduced states: `S(A) = S(ρ.reducedLeft)`, +`S(C) = S(ρ.reducedRight.reducedRight)`, `S(A,B) = S((assoc A B C · ρ).reducedLeft)` and +`S(B,C) = S(ρ.reducedRight)`. This is N&C eq. (11.107) with the subsystem labels permuted +(`B ↔ C` versus the book's `S(A) + S(B) ≤ S(A,C) + S(B,C)`); the labels are universally quantified, +so the two are the same theorem. This "shared-A" orientation makes all four terms clean adjacent +marginals of `ρ` (both mixed pairs `A,B` and `B,C` are adjacent), and is the exact form used for +the second-entry conditional subadditivity `S(A|B,C) ≤ S(A|B) + S(A|C)` (N&C Theorem 11.16) and the +mutual-information bound `S(A:B) + S(A:C) ≤ 2 S(A)` (N&C Exercise 11.26). + +## The derivation (N&C's, dualised) + +Introduce a reference `R` purifying `ρ` (`State.purify`) to a pure four-party state `ψ` on +`(A ⊗ (B ⊗ C)) ⊗ R`. Apply the general (faithfulness-free) strong subadditivity +`State.vonNeumannEntropy_add_le_add'` (N&C Theorem 11.14) to the reference marginal +`τ = Tr_A ψ` on `R ⊗ (B ⊗ C)`, reshaped to `R ⊗ (C ⊗ B)` so the middle factor is `C`: + +`S(R,C,B) + S(C) ≤ S(R,C) + S(C,B)`. + +Rewrite the reference terms by pure-state complementary-subsystem entropy (N&C Theorem 11.8(3)): +`S(R,C,B) = S(A)` (the `1‖3` split, via +`PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape`) +and `S(R,C) = S(A,B)` (the `2‖2` split `PureState.vonNeumannEntropy_ab_eq_cr`). Marginal consistency +(`State.reducedRight_reducedRight_congr_pullRefReshape`, `State.reducedRight_congr_comm`) identifies +`S(C,B)` and `S(C)` with `ρ`'s own `S(B,C)` and `S(C)`, giving eq. (11.107). `linarith` assembles. + +## Supporting results + +`State.vonNeumannEntropy_weakMonotonicity` depends on the general strong-subadditivity theorem +`State.vonNeumannEntropy_add_le_add'` in `AxQM/NC/Ch11/StrongSubadditivityGeneral.lean` (N&C +Theorem 11.14). Its supporting reshape-frame identity +`QSystem.pullRefReshape_assoc_eq_abcrReshape_comm` is an equality of two `QSystem.Iso` composites, +proved by extensionality on pure tensors. The purification, complementarity and +marginal-consistency results it uses are in `AxQM/Postulates/API/WeakMonotonicity.lean`, +`AxQM/Postulates/API/WeakMonotonicityReducedRight.lean`, +`AxQM/Postulates/API/WeakMonotonicitySecondComplement.lean` and +`AxQM/Postulates/API/ReducedStateLeftBlock.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- Reshape-frame bridge for weak monotonicity: the associator/swap composite that the +strong-subadditivity `R ⊗ C` marginal is read through equals the front-pair reshape +`QSystem.abcrReshape` post-composed with the inner `C ↔ R` swap. Both send +`(a ⊗ (b ⊗ c)) ⊗ r ↦ a ⊗ (b ⊗ (r ⊗ c))`; proved by extensionality on pure tensors. -/ +theorem QSystem.pullRefReshape_assoc_eq_abcrReshape_comm {A B C R : QSystem} : + (((A.pullRefReshape (B ⊗ C) R).trans + ((QSystem.Iso.refl A).tmul + (((QSystem.Iso.refl R).tmul (QSystem.Iso.comm B C)).trans (QSystem.assoc R C B)))).trans + ((QSystem.Iso.refl A).tmul (QSystem.Iso.comm (R ⊗ C) B))) + = ((A.abcrReshape B C R).trans (QSystem.assoc A B (C ⊗ R)).symm).trans + ((QSystem.Iso.refl A).tmul ((QSystem.Iso.refl B).tmul (QSystem.Iso.comm C R))) := by + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + refine TensorProduct.ext_threefold fun a bc r => ?_ + simp only [QSystem.pullRefReshape, QSystem.abcrReshape] + induction bc using TensorProduct.inductionOn with + | add u v hu hv => + erw [TensorProduct.tmul_add, TensorProduct.add_tmul, map_add, map_add, hu, hv] + | tmul b c => rfl + +/-- **Weak monotonicity of the von Neumann entropy** (Nielsen & Chuang, Exercise 11.24, the +"form-1" strong-subadditivity inequality eq. (11.107)): for an arbitrary state `ρ` on the +tripartite system `A ⊗ (B ⊗ C)`, + +`S(A) + S(C) ≤ S(A,B) + S(B,C)`, + +derived here **as a consequence of strong subadditivity** (`State.vonNeumannEntropy_add_le_add'`). +The proof purifies `ρ` with a reference `R`, applies strong subadditivity to the `R ⊗ (C ⊗ B)` +marginal of the purification, and rewrites the reference terms `S(R,C,B) = S(A)` and `S(R,C) = +S(A,B)` by pure-state complementary-subsystem entropy (Theorem 11.8(3)); see the module docstring. +Faithful to N&C up to a `B ↔ C` relabelling of the bound subsystems (this "shared-`A`" orientation +is the one Theorem 11.16 and Exercise 11.26 consume). -/ +theorem State.vonNeumannEntropy_weakMonotonicity (ρ : State (A ⊗ (B ⊗ C))) : + ρ.reducedLeft.vonNeumannEntropy + ρ.reducedRight.reducedRight.vonNeumannEntropy ≤ + (State.congr (QSystem.assoc A B C) ρ).reducedLeft.vonNeumannEntropy + + ρ.reducedRight.vonNeumannEntropy := by + -- Purify `ρ` on `A ⊗ (B ⊗ C)` with reference `R`. + set ψ := ρ.purify with hψ + -- The reference-pull marginal `τ = Tr_A (pullRefReshape ψ)` on `R ⊗ (B ⊗ C)`. + set τ := (State.congr (QSystem.pullRefReshape A (B ⊗ C) _) ψ.toState).reducedRight with hτ + -- Reshape `τ` to `R ⊗ (C ⊗ B)` so strong subadditivity has middle factor `C`. + set σ := State.congr (QSystem.Iso.tmul (QSystem.Iso.refl _) (QSystem.Iso.comm B C)) τ with hσ + have hρ : ψ.toState.reducedLeft = ρ := State.purify_reducedLeft_eq ρ + -- `S(σ) = S(A)`: total of the reference marginal is the `A`-entropy (first purity identity). + have hA : σ.vonNeumannEntropy = ρ.reducedLeft.vonNeumannEntropy := by + rw [hσ, State.vonNeumannEntropy_congr, hτ, + ← PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape ψ, hρ] + -- `S(σ.reducedRight) = S(B,C)`: the `C ⊗ B` marginal of `τ` is `ρ`'s `B ⊗ C` marginal. + have hBC : σ.reducedRight.vonNeumannEntropy = ρ.reducedRight.vonNeumannEntropy := by + rw [hσ, State.reducedRight_congr_tmul_right, State.vonNeumannEntropy_congr, hτ, + State.reducedRight_reducedRight_congr_pullRefReshape, hρ] + -- `S(σ.reducedRight.reducedLeft) = S(C)`: further tracing `B` gives the `C` marginal. + have hC : σ.reducedRight.reducedLeft.vonNeumannEntropy + = ρ.reducedRight.reducedRight.vonNeumannEntropy := by + rw [hσ, State.reducedRight_congr_tmul_right, hτ, + State.reducedRight_reducedRight_congr_pullRefReshape, hρ, + ← State.reducedRight_congr_comm] + -- `S((assoc R C B σ).reducedLeft) = S(A,B)`: the `R ⊗ C` marginal, matched by complementarity. + have hAB : (State.congr (QSystem.assoc _ C B) σ).reducedLeft.vonNeumannEntropy + = (State.congr (QSystem.assoc A B C) ρ).reducedLeft.vonNeumannEntropy := by + rw [← hρ, PureState.vonNeumannEntropy_ab_eq_cr ψ, hσ, hτ, ← State.congr_trans, + ← State.reducedRight_congr_tmul_right, ← State.congr_trans, + ← State.reducedRight_reducedRight_congr_assoc_symm, ← State.congr_trans] + rw [State.reducedLeft_congr_comm, ← State.reducedRight_congr_tmul_right, ← State.congr_trans, + QSystem.pullRefReshape_assoc_eq_abcrReshape_comm, State.congr_trans, + State.reducedRight_congr_tmul_right, State.reducedRight_congr_tmul_right, + State.vonNeumannEntropy_congr] + have hssa := State.vonNeumannEntropy_add_le_add' σ + rw [hA, hC, hAB, hBC] at hssa + exact hssa + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/StrongSubadditivityGeneral.lean b/LeanPool/AxQM/NC/Ch11/StrongSubadditivityGeneral.lean new file mode 100644 index 0000000000..f684bf6363 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/StrongSubadditivityGeneral.lean @@ -0,0 +1,197 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.StrongSubadditivity +public import LeanPool.AxQM.Postulates.API.ArakiLiebEqualityConditions +public import LeanPool.AxQM.NC.Ch11.Theorem10 + +/-! +# General (faithfulness-free) strong subadditivity of the von Neumann entropy + +The theorem `State.vonNeumannEntropy_add_le_add` (N&C Theorem 11.14, eq. (11.73)) +proves strong subadditivity `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` only for a **faithful** (strictly +positive) tripartite state. +This file removes that hypothesis: + +* `AxQM.State.vonNeumannEntropy_add_le_add'` — strong subadditivity + `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` for an **arbitrary** state `ρ` on `A ⊗ (B ⊗ C)`. + +This is N&C eq. (11.73) exactly as stated, with no restriction on the state, and it is the general +form used for the "form-1" inequality (weak monotonicity, N&C eq. (11.72) / Exercise 11.24) and +hence the second-entry subadditivity of the conditional entropy (Theorem 11.16, eq. (11.118)): +those two derive from strong subadditivity applied to a **marginal of a purification**, which is a +pure (rank-one) state's reduced state and hence generically **not** faithful — so the faithful form +alone cannot reach them. + +## Method + +The removal of faithfulness is a **perturbation/limiting** argument (below), continuous in the trace +distance via Fannes' inequality. The continuity corollary +`State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance` is in +`LeanPool/AxQM/NC/Ch11/Theorem10.lean` (it uses the Fannes bound of +`LeanPool/AxQM/NC/Ch11/Theorem6.lean`). +The perturbation proof mirrors that of the sibling `State.vonNeumannEntropy_mix_le'`. + +## Proof + +For `εₙ = 1/(n+1) ↓ 0`, replace `ρ` by the faithful state `ρₙ = (1 − εₙ) ρ + εₙ (I/d)` +(strictly positive, since the maximally mixed `I/d` is and `IsStrictlyPositive.nonneg_add`), apply +the faithful strong subadditivity to `ρₙ`, and pass to the limit `n → ∞`. Every one of the four +entropy terms is `S` of a marginal of `ρₙ`, and each marginal of a finite mixture is the mixture of +the marginals — reusing the operator-linearity facts `State.reducedLeft_mix`, +`State.reducedRight_mix` (`AxQM/Postulates/API/ArakiLiebEqualityConditions.lean`) and +`State.congr_mix` (`AxQM/Postulates/API/Mixture.lean`) — so it converges to the corresponding +marginal of `ρ` in trace distance (joint convexity of the trace distance, +`State.traceDistance_mix_jointly_convex`). Continuity of the +entropy in trace distance (`State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance`) turns each +into an entropy limit, and `le_of_tendsto_of_tendsto'` carries the per-`n` faithful inequality +across to the limit. The perturbation is written as a two-point `State.mix` over `Fin 2` (rather +than `State.mixPair`) so those marginal-of-mixture identities discharge through the `Finset.sum` +linearity of the partial trace. This keeps full N&C generality. +-/ + +@[expose] public section + +open Filter +open scoped Topology TensorProduct InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- **Entropy convergence for a two-point perturbation** (the limiting engine of the general strong +subadditivity below). If a sequence of states `G n` is the two-point mixture +`(wₙ)₀ g₀ + (wₙ)₁ g₁` and the second weight `(wₙ)₁ → 0`, then `S(G n) → S(g₀)`. Proof: the trace +distance `D(G n, g₀)` is bounded by `(wₙ)₁ · D(g₁, g₀)` (joint convexity of the trace distance, +`State.traceDistance_mix_jointly_convex`, with `D(g₀, g₀) = 0`), which tends to `0`; continuity of +the entropy in trace distance (`State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance`) finishes. +Kept universe-polymorphic in `W`, to apply to marginals on different composite systems. -/ +private theorem State.tendsto_vonNeumannEntropy_mixPerturb {W : QSystem} (w : ℕ → Fin 2 → ℝ) + (hw0 : ∀ n i, 0 ≤ w n i) (hwsum : ∀ n, ∑ i, w n i = 1) + (hε : Tendsto (fun n : ℕ => w n 1) atTop (𝓝 0)) (G : ℕ → State W) (g₀ g₁ : State W) + (hG : ∀ n, G n = State.mix (w n) (hw0 n) (hwsum n) ![g₀, g₁]) : + Tendsto (fun n => (G n).vonNeumannEntropy) atTop (𝓝 g₀.vonNeumannEntropy) := by + apply State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance + have hbnd : Tendsto (fun n : ℕ => w n 1 * g₁.traceDistance g₀) atTop (𝓝 0) := by + simpa using hε.mul_const (g₁.traceDistance g₀) + refine squeeze_zero (fun n => State.traceDistance_nonneg _ _) (fun n => ?_) hbnd + rw [hG n] + calc (State.mix (w n) (hw0 n) (hwsum n) ![g₀, g₁]).traceDistance g₀ + = (State.mix (w n) (hw0 n) (hwsum n) ![g₀, g₁]).traceDistance + (State.mix (w n) (hw0 n) (hwsum n) (fun _ => g₀)) := by rw [State.mix_const] + _ ≤ ∑ i, w n i * (![g₀, g₁] i).traceDistance g₀ := + State.traceDistance_mix_jointly_convex _ _ _ _ _ + _ = w n 1 * g₁.traceDistance g₀ := by + rw [Fin.sum_univ_two] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one, State.traceDistance_self, mul_zero, + zero_add] + +/-- **Strong subadditivity of the von Neumann entropy, general form** (Nielsen & Chuang, +Theorem 11.14, eq. (11.73)): for an **arbitrary** state `ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)`, + +with the marginals read off as reduced states exactly as in the faithful form +`State.vonNeumannEntropy_add_le_add`. This is the faithfulness-free strengthening: it drops the +`IsStrictlyPositive ρ.op` hypothesis, matching N&C's statement, which is what the weak-monotonicity +"form-1" inequality (eq. (11.72) / Exercise 11.24) and the second-entry conditional subadditivity +(Theorem 11.16, eq. (11.118)) require — they apply strong subadditivity to a marginal of a +purification, a non-faithful state. + +The proof perturbs `ρ` toward the maximally mixed state, `ρₙ = (1 − εₙ) ρ + εₙ (I/d)` with +`εₙ = 1/(n+1) ↓ 0` (strictly positive, so the faithful form applies), and passes to the limit; both +sides are continuous in trace distance via Fannes' inequality +(`State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance`), and each marginal of `ρₙ` converges to +that of `ρ` because the marginal of a mixture is the mixture of the marginals. -/ +theorem State.vonNeumannEntropy_add_le_add' (ρ : State (A ⊗ (B ⊗ C))) : + ρ.vonNeumannEntropy + ρ.reducedRight.reducedLeft.vonNeumannEntropy ≤ + (ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy + + ρ.reducedRight.vonNeumannEntropy := by + classical + have : Nontrivial (A ⊗ (B ⊗ C)).space := ρ.nontrivial_space + -- The maximally mixed reference state `I/d`, and the two-point family `![ρ, I/d]`. + set τ : State (A ⊗ (B ⊗ C)) := maximallyMixedState (A ⊗ (B ⊗ C)) with hτ + have hτpos : IsStrictlyPositive τ.op := by + rw [hτ]; exact maximallyMixedState_isStrictlyPositive _ + -- Make `τ` opaque (only `hτpos` is needed below): this keeps the marginal-identity `rfl`s cheap, + -- since they would otherwise unfold `maximallyMixedState` through the nested partial traces. + clear_value τ + set states : Fin 2 → State (A ⊗ (B ⊗ C)) := ![ρ, τ] with hstates + -- Perturbation weights `wₙ = ![1 − εₙ, εₙ]`, `εₙ = 1/(n+1) ↓ 0`. + have hεpos : ∀ n : ℕ, (0 : ℝ) < 1 / (n + 1) := fun n => by positivity + have hεle : ∀ n : ℕ, (1 : ℝ) / (n + 1) ≤ 1 := fun n => by + rw [div_le_one (by positivity)]; have : (0 : ℝ) ≤ (n : ℝ) := Nat.cast_nonneg n; linarith + set w : ℕ → Fin 2 → ℝ := fun n => ![1 - 1 / (n + 1), 1 / (n + 1)] with hw + have hw0 : ∀ n, ∀ i, 0 ≤ w n i := fun n => by + rw [Fin.forall_fin_two] + refine ⟨?_, ?_⟩ <;> simp only [hw, Matrix.cons_val_zero, Matrix.cons_val_one] + · linarith [hεle n] + · linarith [hεpos n] + have hwsum : ∀ n, ∑ i, w n i = 1 := fun n => by + simp only [hw, Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one] + ring + have hεtendsto : Tendsto (fun n : ℕ => (1 : ℝ) / (n + 1)) atTop (𝓝 0) := + tendsto_one_div_add_atTop_nhds_zero_nat + -- The perturbed state `ρₙ = (1 − εₙ) ρ + εₙ (I/d)`, faithful for every `n`. + set F : ℕ → State (A ⊗ (B ⊗ C)) := fun n => State.mix (w n) (hw0 n) (hwsum n) states with hF + have hposN : ∀ n, IsStrictlyPositive (F n).op := by + intro n + rw [hF, State.mix_op, Fin.sum_univ_two] + simp only [hw, hstates, Matrix.cons_val_zero, Matrix.cons_val_one, Complex.coe_smul] + refine IsStrictlyPositive.nonneg_add ?_ ?_ + · exact smul_nonneg (by linarith [hεle n]) ρ.isDensity.nonneg + · exact IsStrictlyPositive.smul (hεpos n) hτpos + -- Generic marginal convergence: for endpoint states `g₀ g₁`, the entropy of the perturbed mixture + -- `(1 − εₙ) g₀ + εₙ g₁` converges to `S(g₀)` (as `εₙ ↓ 0`). + have hε : Tendsto (fun n : ℕ => w n 1) atTop (𝓝 0) := by + simpa only [hw, Matrix.cons_val_one, Matrix.cons_val_zero] using hεtendsto + -- The four entropy terms converge; each is `S` of a marginal of `F n`, identified with the + -- corresponding two-point mixture `(1 − εₙ) (marginal ρ) + εₙ (marginal τ)`. Passing the marginal + -- *sequence* to `tendsto_vonNeumannEntropy_mixPerturb` keeps its conclusion syntactically equal + -- to the goal (no `whnf` on the marginal-of-mixture terms, which would unfold partial traces). + have hABC : Tendsto (fun n => (F n).vonNeumannEntropy) atTop (𝓝 ρ.vonNeumannEntropy) := + State.tendsto_vonNeumannEntropy_mixPerturb w hw0 hwsum hε F ρ τ + (fun n => by simp only [hF, hstates]) + have hBC : Tendsto (fun n => (F n).reducedRight.vonNeumannEntropy) atTop + (𝓝 ρ.reducedRight.vonNeumannEntropy) := by + have hfam : (fun i => (states i).reducedRight) = ![ρ.reducedRight, τ.reducedRight] := by + funext i; fin_cases i <;> rfl + exact State.tendsto_vonNeumannEntropy_mixPerturb w hw0 hwsum hε + ((fun n => (F n).reducedRight) : ℕ → State (B ⊗ C)) ρ.reducedRight τ.reducedRight + (fun n => by simp only [hF, State.reducedRight_mix, hfam]) + have hB : Tendsto (fun n => (F n).reducedRight.reducedLeft.vonNeumannEntropy) atTop + (𝓝 ρ.reducedRight.reducedLeft.vonNeumannEntropy) := by + have hfam : (fun i => (states i).reducedRight.reducedLeft) + = ![ρ.reducedRight.reducedLeft, τ.reducedRight.reducedLeft] := by + funext i; fin_cases i <;> (rw [hstates]; rfl) + exact State.tendsto_vonNeumannEntropy_mixPerturb w hw0 hwsum hε + ((fun n => (F n).reducedRight.reducedLeft) : ℕ → State B) ρ.reducedRight.reducedLeft + τ.reducedRight.reducedLeft + (fun n => by simp only [hF, State.reducedRight_mix, State.reducedLeft_mix, hfam]) + have hAB : Tendsto (fun n => ((F n).congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy) + atTop (𝓝 (ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy) := by + have hfam : (fun i => ((states i).congr (QSystem.assoc A B C)).reducedLeft) + = ![(ρ.congr (QSystem.assoc A B C)).reducedLeft, + (τ.congr (QSystem.assoc A B C)).reducedLeft] := by + funext i; fin_cases i <;> (rw [hstates]; rfl) + exact State.tendsto_vonNeumannEntropy_mixPerturb w hw0 hwsum hε + ((fun n => ((F n).congr (QSystem.assoc A B C)).reducedLeft) : ℕ → State (A ⊗ B)) + (ρ.congr (QSystem.assoc A B C)).reducedLeft (τ.congr (QSystem.assoc A B C)).reducedLeft + (fun n => by simp only [hF, State.congr_mix, State.reducedLeft_mix, hfam]) + -- The faithful inequality holds along the sequence; pass to the limit. + have hbound : ∀ n, (F n).vonNeumannEntropy + (F n).reducedRight.reducedLeft.vonNeumannEntropy ≤ + ((F n).congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy + + (F n).reducedRight.vonNeumannEntropy := + fun n => State.vonNeumannEntropy_add_le_add (F n) (hposN n) + exact le_of_tendsto_of_tendsto' (hABC.add hB) (hAB.add hBC) hbound + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Subadditivity.lean b/LeanPool/AxQM/NC/Ch11/Subadditivity.lean new file mode 100644 index 0000000000..98086a01b7 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Subadditivity.lean @@ -0,0 +1,305 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch11.StrongSubadditivityGeneral +public import LeanPool.AxQM.NC.Ch11.Theorem8 +public import LeanPool.AxQM.NC.Ch2.Exercise78 +public import LeanPool.AxQM.Postulates.API.ReducedEigenEnsemble +public import LeanPool.AxQM.Postulates.API.EntropyConcavity +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.MutualInformationAncilla +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.Postulates.API.ReducedStateReshape +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.CompositeState +public import LeanPool.AxQM.Postulates.API.Qudit + +/-! +# Subadditivity of the von Neumann entropy (N&C §11.3.4, eq. (11.74)) + +Nielsen & Chuang, §11.3.4: for a bipartite state `ρ` on `A ⊗ B`, + +`S(A, B) ≤ S(A) + S(B)` (**subadditivity**, eq. (11.74)), + +equivalently `0 ≤ S(A : B)` (the quantum mutual information is non-negative). This file proves +this basic bipartite inequality, the weaker companion of *strong* subadditivity +(`State.vonNeumannEntropy_add_le_add'`, Theorem 11.14). + +## Why this is not the `B`-trivial case of strong subadditivity for free + +Subadditivity `S(A,B) ≤ S(A) + S(B)` is the specialisation of strong subadditivity +`S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` to a **trivial middle system** `B`. We realise exactly that: +insert a one-dimensional system `qudit 1` (prepared in the pure state `|0⟩`, contributing zero +entropy) as the middle factor of a tripartite state built from `ρ`, and apply the faithfulness-free +strong subadditivity `State.vonNeumannEntropy_add_le_add'`. Reading off the four marginal entropies +of that inserted state collapses the inequality to `S(A,B) + 0 ≤ S(A) + S(B)`. + +The one non-formal step this needs is the entropy of the `A ⊗ (trivial)`-marginal: appending an +uncorrelated pure system does not change the entropy. That is the content of the reusable +factorisation crux proved first: + +* `State.eq_tmul_of_isPure_reducedRight` — a bipartite state whose **right marginal is pure** + factorises as the product of its marginals, `ρ = ρ_A ⊗ ρ_B`. (A mixed-state companion of + Exercise 2.78, which handles the pure-state case.) Its entropy corollary + `State.vonNeumannEntropy_eq_reducedLeft_of_isPure_reducedRight` gives `S(ρ) = S(ρ_A)` when `ρ_B` + is pure. + +## Proof of the factorisation crux + +`ρ` with `ρ_B` pure: decompose `ρ` into its reduced eigenensemble `{μⱼ, |gⱼ⟩}` (all `μⱼ > 0`), so +`ρ = ∑ⱼ μⱼ |gⱼ⟩⟨gⱼ|`. Tracing out `A` gives `ρ_B = ∑ⱼ μⱼ (|gⱼ⟩⟨gⱼ|)_B`, a convex combination equal +to the *pure* state `ρ_B`; a pure state is an extreme point of the state space +(`State.eq_of_isPure_mix`, proved from the equality condition for concavity of the von Neumann +entropy `State.vonNeumannEntropy_mix_eq_sum_iff'`), so every component `(|gⱼ⟩⟨gⱼ|)_B = ρ_B` is +pure. By Exercise 2.78 (`PureState.isProduct_iff_isPure_reducedRight`) each eigenvector `|gⱼ⟩` is +then a product `|aⱼ⟩|bⱼ⟩` with `|bⱼ⟩⟨bⱼ| = ρ_B`, whence +`ρ = (∑ⱼ μⱼ |aⱼ⟩⟨aⱼ|) ⊗ ρ_B = ρ_A ⊗ ρ_B` by linearity of the tensor product over mixtures. + +## Ingredients + +The proofs use the faithfulness-free strong subadditivity `State.vonNeumannEntropy_add_le_add'` +(`AxQM/NC/Ch11/StrongSubadditivityGeneral.lean`) and the product-state characterisation +`PureState.isProduct_iff_isPure_reducedRight` (`LeanPool/AxQM/NC/Ch2/Exercise78.lean`); the `qudit +1` +trivial system used in the subadditivity proof appears only in proof bodies, never in a statement. + +## Main results + +* `AxQM.State.eq_of_isPure_mix` — a pure state is extreme: if a mixture is pure, each + positive-weight component equals it. +* `AxQM.State.eq_tmul_of_isPure_reducedRight` — pure right marginal ⇒ product state. +* `AxQM.State.vonNeumannEntropy_eq_reducedLeft_of_isPure_reducedRight` — `S(ρ) = S(ρ_A)` + when `ρ_B` is pure. +* `AxQM.State.vonNeumannEntropy_le_reducedLeft_add_reducedRight` — subadditivity + `S(A,B) ≤ S(A) + S(B)` (N&C eq. (11.74)). +* `AxQM.State.vonNeumannMutualInfo_nonneg` — `0 ≤ S(A : B)`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S T X Y : QSystem} + +/-- **A pure state is an extreme point of the state space.** If a finite mixture +`∑ᵢ pᵢ ρᵢ = State.mix p hp hsum ρ` is a *pure* state, then every component `ρ i` with positive +weight `pᵢ > 0` equals the mixture. The concavity gap `S(mix) − ∑ᵢ pᵢ S(ρᵢ)` is squeezed to `0` +between the faithfulness-free concavity +`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'` and the vanishing entropy of the pure +mixture, and the equality condition `State.vonNeumannEntropy_mix_eq_sum_iff'` then forces +`ρ i = mix`. -/ +theorem State.eq_of_isPure_mix {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) (hpure : (State.mix p hp hsum ρ).IsPure) {i : ι} + (hpi : 0 < p i) : ρ i = State.mix p hp hsum ρ := by + have hS : (State.mix p hp hsum ρ).vonNeumannEntropy = 0 := + State.vonNeumannEntropy_eq_zero_of_isPure _ hpure + have hconc : ∑ j, p j * (ρ j).vonNeumannEntropy ≤ (State.mix p hp hsum ρ).vonNeumannEntropy := + State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix' p hp hsum ρ + have hnonneg : 0 ≤ ∑ j, p j * (ρ j).vonNeumannEntropy := + Finset.sum_nonneg fun j _ => mul_nonneg (hp j) (State.vonNeumannEntropy_nonneg _) + have heq : (State.mix p hp hsum ρ).vonNeumannEntropy = ∑ j, p j * (ρ j).vonNeumannEntropy := by + rw [hS]; linarith + exact (State.vonNeumannEntropy_mix_eq_sum_iff' p hp hsum ρ).mp heq i hpi + +/-- **A bipartite state with a pure right marginal is a product state.** If the marginal +`ρ_B = ρ.reducedRight` of `ρ : State (X ⊗ Y)` is pure, then `ρ = ρ_A ⊗ ρ_B` with +`ρ_A = ρ.reducedLeft`. This is the mixed-state companion of Nielsen & Chuang, Exercise 2.78 +(`PureState.isProduct_iff_isPure_reducedRight`, the pure-state case): a pure marginal means the +second party carries no correlations. Proved via the spectral (reduced eigenensemble) decomposition +of `ρ`, the extreme-point property of the pure marginal (`State.eq_of_isPure_mix`), Exercise 2.78 +applied to each eigenvector, and linearity of the tensor product over mixtures +(`State.mix_tmul`). -/ +theorem State.eq_tmul_of_isPure_reducedRight (ρ : State (X.compose Y)) + (h : ρ.reducedRight.IsPure) : ρ = ρ.reducedLeft.tmul ρ.reducedRight := by + set e := ρ.reducedEigenEnsemble with he + have hetoState : e.toState = ρ := by rw [he]; exact State.reducedEigenEnsemble_toState ρ + -- `ρ` is the mixture of its eigenprojectors. + have hmix : State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState) = ρ := by + rw [← hetoState] + apply State.ext + rw [State.mix_op, Ensemble.toState_op] + -- the right marginal is the mixture of the components' right marginals + have hRmix : ρ.reducedRight + = State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState.reducedRight) := by + rw [← hmix, State.reducedRight_mix] + -- each component's right marginal equals the (pure) marginal, by extremality + have hprodR : ∀ i, (e.states i).toState.reducedRight = ρ.reducedRight := by + intro i + have hpure : (State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedRight)).IsPure := by rw [← hRmix]; exact h + have hpi : 0 < e.prob i := State.reducedEigenEnsemble_prob_pos ρ i + have hcomp := State.eq_of_isPure_mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedRight) hpure hpi + rw [← hRmix] at hcomp + exact hcomp + -- each eigenvector is a product, so each component factors as (·)_A ⊗ ρ_B + have hfactor : ∀ i, (e.states i).toState + = (e.states i).toState.reducedLeft.tmul ρ.reducedRight := by + intro i + have hProd : (e.states i).IsProduct := by + rw [PureState.isProduct_iff_isPure_reducedRight, hprodR i]; exact h + obtain ⟨a, b, hab⟩ := hProd + have hb : b.toState = ρ.reducedRight := by + rw [← hprodR i, hab, reducedRight_toState_tmul] + have hstate : (e.states i).toState = a.toState.tmul b.toState := by + rw [hab, PureState.toState_tmul] + have hleft : (e.states i).toState.reducedLeft = a.toState := by + rw [hab, reducedLeft_toState_tmul] + rw [hleft, hstate, hb] + -- assemble + have hfam : (fun i => (e.states i).toState) + = (fun i => ((e.states i).toState.reducedLeft).tmul ρ.reducedRight) := funext hfactor + calc ρ = State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState) := hmix.symm + _ = State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => ((e.states i).toState.reducedLeft).tmul ρ.reducedRight) := by rw [hfam] + _ = (State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedLeft)).tmul ρ.reducedRight := + (State.mix_tmul e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedLeft) ρ.reducedRight).symm + _ = ρ.reducedLeft.tmul ρ.reducedRight := by + rw [← State.reducedLeft_mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState), hmix] + +/-- **A bipartite state with a pure left marginal is a product state.** If the marginal +`ρ_A = ρ.reducedLeft` of `ρ : State (X ⊗ Y)` is pure, then `ρ = ρ_A ⊗ ρ_B` with +`ρ_B = ρ.reducedRight`. The left companion of `State.eq_tmul_of_isPure_reducedRight`: a pure +marginal means the first party carries no correlations. Proved by the same spectral (reduced +eigenensemble) decomposition, the extreme-point property of the pure marginal +(`State.eq_of_isPure_mix`), Exercise 2.78 (`PureState.isProduct_iff_isPure_reducedLeft`) applied to +each eigenvector, and linearity of the tensor product over mixtures (`State.tmul_mix`). -/ +theorem State.eq_tmul_of_isPure_reducedLeft (ρ : State (X.compose Y)) + (h : ρ.reducedLeft.IsPure) : ρ = ρ.reducedLeft.tmul ρ.reducedRight := by + set e := ρ.reducedEigenEnsemble with he + have hetoState : e.toState = ρ := by rw [he]; exact State.reducedEigenEnsemble_toState ρ + have hmix : State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState) = ρ := by + rw [← hetoState] + apply State.ext + rw [State.mix_op, Ensemble.toState_op] + -- the left marginal is the mixture of the components' left marginals + have hLmix : ρ.reducedLeft + = State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState.reducedLeft) := by + rw [← hmix, State.reducedLeft_mix] + -- each component's left marginal equals the (pure) marginal, by extremality + have hprodL : ∀ i, (e.states i).toState.reducedLeft = ρ.reducedLeft := by + intro i + have hpure : (State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedLeft)).IsPure := by rw [← hLmix]; exact h + have hpi : 0 < e.prob i := State.reducedEigenEnsemble_prob_pos ρ i + have hcomp := State.eq_of_isPure_mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedLeft) hpure hpi + rw [← hLmix] at hcomp + exact hcomp + -- each eigenvector is a product, so each component factors as ρ_A ⊗ (·)_B + have hfactor : ∀ i, (e.states i).toState + = ρ.reducedLeft.tmul ((e.states i).toState.reducedRight) := by + intro i + have hProd : (e.states i).IsProduct := by + rw [PureState.isProduct_iff_isPure_reducedLeft, hprodL i]; exact h + obtain ⟨a, b, hab⟩ := hProd + have ha : a.toState = ρ.reducedLeft := by + rw [← hprodL i, hab, reducedLeft_toState_tmul] + have hstate : (e.states i).toState = a.toState.tmul b.toState := by + rw [hab, PureState.toState_tmul] + have hright : (e.states i).toState.reducedRight = b.toState := by + rw [hab, reducedRight_toState_tmul] + rw [hright, hstate, ha] + -- assemble + have hfam : (fun i => (e.states i).toState) + = (fun i => ρ.reducedLeft.tmul ((e.states i).toState.reducedRight)) := funext hfactor + calc ρ = State.mix e.prob e.prob_nonneg e.sum_prob (fun i => (e.states i).toState) := hmix.symm + _ = State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => ρ.reducedLeft.tmul ((e.states i).toState.reducedRight)) := by rw [hfam] + _ = ρ.reducedLeft.tmul (State.mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState.reducedRight)) := + (State.tmul_mix e.prob e.prob_nonneg e.sum_prob ρ.reducedLeft + (fun i => (e.states i).toState.reducedRight)).symm + _ = ρ.reducedLeft.tmul ρ.reducedRight := by + rw [← State.reducedRight_mix e.prob e.prob_nonneg e.sum_prob + (fun i => (e.states i).toState), hmix] + +/-- **Entropy of a state with a pure right marginal.** If `ρ.reducedRight` is pure, then +`S(ρ) = S(ρ.reducedLeft)`: the (uncorrelated, pure) second factor contributes nothing to the +entropy. Immediate from the factorisation `State.eq_tmul_of_isPure_reducedRight`, the additivity of +entropy over tensor products (`State.vonNeumannEntropy_tmul`), and the vanishing entropy of a pure +state. -/ +theorem State.vonNeumannEntropy_eq_reducedLeft_of_isPure_reducedRight (ρ : State (X.compose Y)) + (h : ρ.reducedRight.IsPure) : ρ.vonNeumannEntropy = ρ.reducedLeft.vonNeumannEntropy := by + conv_lhs => rw [State.eq_tmul_of_isPure_reducedRight ρ h] + rw [State.vonNeumannEntropy_tmul, State.vonNeumannEntropy_eq_zero_of_isPure _ h, add_zero] + +/-- **Subadditivity of the von Neumann entropy** (Nielsen & Chuang, §11.3.4, eq. (11.74)): for a +bipartite state `σ` on `S ⊗ T`, + +`S(σ) ≤ S(σ_S) + S(σ_T)`. + +Realised as the trivial-middle-system case of strong subadditivity: append a pure one-dimensional +ancilla `τ = |0⟩⟨0|` on `qudit 1` and re-associate `σ ⊗ τ` into the tripartite state +`ρ` on `S ⊗ ((qudit 1) ⊗ T)`, so that `qudit 1` sits in the *middle*. Strong subadditivity +`State.vonNeumannEntropy_add_le_add'` for `ρ` reads `S(σ) + S(τ) ≤ S(M) + S(σ_T)`, where `M` is the +`S ⊗ (qudit 1)`-marginal; since `τ` is pure (`S(τ) = 0`) and `M` has a pure `qudit 1`-marginal +(`S(M) = S(σ_S)` by `State.vonNeumannEntropy_eq_reducedLeft_of_isPure_reducedRight`), this collapses +to the subadditivity inequality. -/ +theorem State.vonNeumannEntropy_le_reducedLeft_add_reducedRight (σ : State (S.compose T)) : + σ.vonNeumannEntropy ≤ σ.reducedLeft.vonNeumannEntropy + σ.reducedRight.vonNeumannEntropy := by + -- trivial one-dimensional middle system, prepared pure + set τ : State (qudit 1) := (quditBasis (0 : Fin 1)).toState with hτdef + have hτpure : τ.IsPure := ⟨quditBasis (0 : Fin 1), hτdef⟩ + have hτ0 : τ.vonNeumannEntropy = 0 := State.vonNeumannEntropy_eq_zero_of_isPure _ hτpure + -- `κ` on `S ⊗ (T ⊗ triv)`: `σ` with a pure trivial factor appended on the far right + set κ : State (S.compose (T.compose (qudit 1))) := + State.congr (QSystem.assoc S T (qudit 1)).symm (σ.tmul τ) with hκdef + have hκL : κ.reducedLeft = σ.reducedLeft := State.reducedLeft_congr_symm_assoc_tmul σ τ + have hκR : κ.reducedRight = σ.reducedRight.tmul τ := State.reducedRight_congr_symm_assoc_tmul σ τ + have hκent : κ.vonNeumannEntropy = σ.vonNeumannEntropy := by + rw [hκdef, State.vonNeumannEntropy_congr, State.vonNeumannEntropy_tmul, hτ0, add_zero] + -- `ρ` on `S ⊗ (triv ⊗ T)`: swap the middle trivial factor inward + set ρ : State (S.compose ((qudit 1).compose T)) := + State.congr ((QSystem.Iso.refl S).tmul (QSystem.Iso.comm T (qudit 1))) κ with hρdef + have hρL : ρ.reducedLeft = σ.reducedLeft := by + rw [hρdef, State.reducedLeft_congr_tmul_refl, hκL] + have hρR : ρ.reducedRight + = State.congr (QSystem.Iso.comm T (qudit 1)) (σ.reducedRight.tmul τ) := by + rw [hρdef, State.reducedRight_congr_tmul_right, hκR] + have hρent : ρ.vonNeumannEntropy = σ.vonNeumannEntropy := by + rw [hρdef, State.vonNeumannEntropy_congr, hκent] + have hρRL : ρ.reducedRight.reducedLeft = τ := by + rw [hρR, ← State.reducedRight_congr_comm (σ.reducedRight.tmul τ), State.reducedRight_tmul] + have hρRent : ρ.reducedRight.vonNeumannEntropy = σ.reducedRight.vonNeumannEntropy := by + rw [hρR, State.vonNeumannEntropy_congr, State.vonNeumannEntropy_tmul, hτ0, add_zero] + -- the `S ⊗ triv`-marginal `M` has entropy `S(σ_S)`, since its trivial factor is pure + set M : State (S.compose (qudit 1)) := + (State.congr (QSystem.assoc S (qudit 1) T) ρ).reducedLeft with hMdef + have hML : M.reducedLeft = σ.reducedLeft := by + rw [hMdef, State.reducedLeft_reducedLeft_congr_assoc, hρL] + have hMR : M.reducedRight = τ := by + rw [hMdef, State.reducedRight_reducedLeft_congr_assoc, hρRL] + have hMent : M.vonNeumannEntropy = σ.reducedLeft.vonNeumannEntropy := by + rw [State.vonNeumannEntropy_eq_reducedLeft_of_isPure_reducedRight M + (by rw [hMR]; exact hτpure), hML] + -- strong subadditivity with the trivial middle system collapses to subadditivity + have hSSA := State.vonNeumannEntropy_add_le_add' ρ + rw [hρent, hρRL, hτ0, ← hMdef, hMent, hρRent] at hSSA + linarith + +/-- **Non-negativity of the quantum mutual information** (Nielsen & Chuang, §11.3.4): for a +bipartite state `σ` on `S ⊗ T`, `0 ≤ S(S : T)`. This is subadditivity +`State.vonNeumannEntropy_le_reducedLeft_add_reducedRight` rewritten through the definition +`S(S : T) = S(σ_S) + S(σ_T) − S(σ)`. -/ +theorem State.vonNeumannMutualInfo_nonneg (σ : State (S.compose T)) : + 0 ≤ σ.vonNeumannMutualInfo := by + rw [State.vonNeumannMutualInfo_def] + linarith [State.vonNeumannEntropy_le_reducedLeft_add_reducedRight σ] + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem10.lean b/LeanPool/AxQM/NC/Ch11/Theorem10.lean new file mode 100644 index 0000000000..067a9e8fbe --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem10.lean @@ -0,0 +1,214 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.EntropyMixture +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.NC.Ch11.Theorem6 +public import LeanPool.AxQM.NC.Ch9.Theorem3 +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# N&C Theorem 11.10 — Entropy of a mixture of quantum states + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.10, p. 518. + +For a mixture `ρ = ∑ᵢ pᵢ ρᵢ` of quantum states `ρᵢ` with a probability distribution `p`, the von +Neumann entropy obeys the upper bound (eq. (11.87)) + +`S(ρ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`, + +with equality **iff** the states `ρᵢ` have support on orthogonal subspaces. Paired with the +concavity inequality `∑ᵢ pᵢ S(ρᵢ) ≤ S(ρ)` (Theorem 11.8), this bounds the Holevo χ quantity +`χ = S(ρ) − ∑ᵢ pᵢ S(ρᵢ)` between `0` and `H(p)` (eq. (11.86)). + +## What is proved here + +This file proves two results about `State.vonNeumannEntropy`, `State.mix`, and +`State.traceDistance`, using the Fannes inequality (`State.abs_vonNeumannEntropy_sub_le_fannes`, +Theorem 11.6): + +* `AxQM.State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance` — **continuity of the von + Neumann entropy in trace distance**: if `σᵢ → ρ` in trace distance along a filter, then + `S(σᵢ) → S(ρ)`. A reusable Fannes corollary. +* `AxQM.State.vonNeumannEntropy_mix_le'` — the **general** (faithfulness-free) upper bound + `S(∑ᵢ pᵢ ρᵢ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)` for an arbitrary family of states, i.e. eq. (11.87) exactly as + N&C state it (no strict-positivity hypothesis). + +The remaining results, whose statements are in terms of the density operators `.op`, are in +`AxQM/Postulates/API/`: + +* `AxQM.State.vonNeumannEntropy_mix_le` + (`AxQM/Postulates/API/EntropyMixture.lean`) — the *faithful* form of the bound (each + `(ρ i).op` strictly positive), derived from the `ToMathlib/` bound + `ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy`. The general bound + `vonNeumannEntropy_mix_le'` here is obtained *from* it by perturbation (below). +* `AxQM.State.vonNeumannEntropy_mix_of_orthonormal_rankOne` + (`AxQM/Postulates/API/EntropyOrthogonalMixture.lean`) — the equality "if" engine: + `S(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ S(ρᵢ) + H(p)` when the components carry jointly-orthonormal eigen- + decompositions (= orthogonal supports), N&C's own eq. (11.92) computation. +* `AxQM.State.vonNeumannEntropy_mix_eq_iff_orthogonal` + (`AxQM/Postulates/API/EntropyMixtureReverse.lean`) — **the equality condition itself**: + `S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)` iff the components of non-zero probability have orthogonal + supports (`(ρ i).op * (ρ j).op = 0` for `i ≠ j`, `pᵢ, pⱼ ≠ 0`). Its `⟹` direction is N&C's mixed- + case argument (eq. (11.92)–(11.94)): reduce the mixture to its combined eigen-ensemble + `{pᵢ λᵢₖ, |eᵢₖ⟩}` and invoke the pure-state converse + `AxQM.Ensemble.inner_states_eq_zero_of_vonNeumannEntropy_toState_eq` + (eq. (11.88)–(11.91)); its `⇐` direction is the orthogonal-support "if" engine above, restricted + to the positive-weight components. + +## Proof route for the general bound + +N&C prove the bound by an auxiliary-system argument (purify, then invoke Theorem 11.9). The library +takes the **relative-entropy route** for the *faithful* case (`vonNeumannEntropy_mix_le`), which +needs each `ρᵢ` strictly positive because the antitonicity lever requires the reference `pᵢ ρᵢ` +strictly positive. + +The general bound removes that hypothesis by **perturbation**: for `εₙ = 1/(n+1) ↓ 0`, replace each +`ρᵢ` by the faithful state `ρᵢ⁽ⁿ⁾ = (1−εₙ) ρᵢ + εₙ (I/d)` (strictly positive, since the maximally +mixed `I/d` is), apply the faithful bound to the family `ρ⁽ⁿ⁾`, and pass to the limit `n → ∞`. Both +sides are continuous in trace distance (via Fannes, +`tendsto_vonNeumannEntropy_of_tendsto_traceDistance`), and `ρᵢ⁽ⁿ⁾ → ρᵢ`, `μ⁽ⁿ⁾ → μ` in trace +distance (joint convexity of the trace distance under mixing), so the faithful inequality survives +the limit. This keeps full N&C generality. + +The equality condition (equality iff the `ρᵢ` have orthogonal supports) is assembled as +`AxQM.State.vonNeumannEntropy_mix_eq_iff_orthogonal` +(`AxQM/Postulates/API/EntropyMixtureReverse.lean`, listed above). +-/ + +@[expose] public section + +namespace AxQM + +open Filter +open scoped Topology + +variable {S : QSystem} + +/-- **Continuity of the von Neumann entropy in trace distance.** If a family of states `σ i` +converges to `ρ` in trace distance along a filter `l`, then their von Neumann entropies converge: +`S(σ i) → S(ρ)`. This is a direct corollary of Fannes' inequality +(`State.abs_vonNeumannEntropy_sub_le_fannes`): the entropy gap is squeezed between `0` and +`2 D · log d + η(2 D)`, which tends to `0` as the trace distance `D` does (`η = Real.negMulLog` is +continuous at `0` with `η 0 = 0`). -/ +theorem State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance {ι : Type*} {l : Filter ι} + (σ : ι → State S) (ρ : State S) + (h : Tendsto (fun i => (σ i).traceDistance ρ) l (𝓝 0)) : + Tendsto (fun i => (σ i).vonNeumannEntropy) l (𝓝 ρ.vonNeumannEntropy) := by + have h2 : Tendsto (fun i => 2 * (σ i).traceDistance ρ) l (𝓝 0) := by + simpa using h.const_mul 2 + have hA : Tendsto (fun i => 2 * (σ i).traceDistance ρ * Real.log (S.dim : ℝ)) l (𝓝 0) := by + simpa using h2.mul_const (Real.log (S.dim : ℝ)) + have hB : Tendsto (fun i => Real.negMulLog (2 * (σ i).traceDistance ρ)) l (𝓝 0) := by + have hcomp := (Real.continuous_negMulLog.tendsto (0 : ℝ)).comp h2 + rw [Real.negMulLog_zero] at hcomp + exact hcomp + have hg : Tendsto (fun i => 2 * (σ i).traceDistance ρ * Real.log (S.dim : ℝ) + + Real.negMulLog (2 * (σ i).traceDistance ρ)) l (𝓝 0) := by + simpa using hA.add hB + have hev : ∀ᶠ i in l, ‖(σ i).vonNeumannEntropy - ρ.vonNeumannEntropy‖ + ≤ 2 * (σ i).traceDistance ρ * Real.log (S.dim : ℝ) + + Real.negMulLog (2 * (σ i).traceDistance ρ) := by + have hsmall : ∀ᶠ i in l, 2 * (σ i).traceDistance ρ < Real.exp (-1) := + h2.eventually (Iio_mem_nhds (Real.exp_pos _)) + filter_upwards [hsmall] with i hi + rw [Real.norm_eq_abs] + exact (σ i).abs_vonNeumannEntropy_sub_le_fannes ρ hi.le + have hsub : Tendsto (fun i => (σ i).vonNeumannEntropy - ρ.vonNeumannEntropy) l (𝓝 0) := + squeeze_zero_norm' hev hg + simpa using hsub.add_const ρ.vonNeumannEntropy + +/-- **Entropy of a mixture — upper bound, general form** (Nielsen & Chuang, Theorem 11.10, +eq. (11.87)). For *any* probability distribution `p` and *any* family `ρ : ι → State S` of quantum +states, the von Neumann entropy of the mixture is bounded by the average component entropy plus the +Shannon entropy of the weights: + +`S(∑ᵢ pᵢ ρᵢ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`. + +This is the faithfulness-free strengthening of `State.vonNeumannEntropy_mix_le` (which assumes each +`(ρ i).op` strictly positive): it is exactly N&C eq. (11.87), with no restriction on the states. + +The proof perturbs each component toward the maximally mixed state, +`ρᵢ⁽ⁿ⁾ = (1 − εₙ) ρᵢ + εₙ (I/d)` with `εₙ = 1/(n+1) ↓ 0` (strictly positive, so the faithful bound +applies), and passes to the limit: both `S(∑ᵢ pᵢ ρᵢ⁽ⁿ⁾) → S(∑ᵢ pᵢ ρᵢ)` and +`∑ᵢ pᵢ S(ρᵢ⁽ⁿ⁾) → ∑ᵢ pᵢ S(ρᵢ)` by continuity of the entropy in trace distance +(`State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance`), the trace-distance convergence coming +from joint convexity of the trace distance under mixing. -/ +theorem State.vonNeumannEntropy_mix_le' {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + (State.mix p hp hsum ρ).vonNeumannEntropy + ≤ ∑ i, p i * (ρ i).vonNeumannEntropy + Real.entropy p := by + classical + -- The weights sum to `1`, so the index type is nonempty and `S.space` is nontrivial; hence the + -- maximally mixed reference state `I/d` exists. + obtain ⟨i₀⟩ : Nonempty ι := by + by_contra h + rw [not_nonempty_iff] at h + rw [Finset.univ_eq_empty, Finset.sum_empty] at hsum + exact zero_ne_one hsum + have : Nontrivial S.space := State.nontrivial_space (ρ i₀) + set τ : State S := maximallyMixedState S with hτ + have hτpos : IsStrictlyPositive τ.op := by + rw [hτ]; exact maximallyMixedState_isStrictlyPositive S + -- Perturbation weights `εₙ = 1/(n+1) ∈ (0, 1]`, `εₙ ↓ 0`. + have hεpos : ∀ n : ℕ, (0 : ℝ) < 1 / (n + 1) := fun n => by positivity + have hεle : ∀ n : ℕ, (1 : ℝ) / (n + 1) ≤ 1 := fun n => by + have hn : (0 : ℝ) ≤ (n : ℝ) := Nat.cast_nonneg n + rw [div_le_one (by positivity)]; linarith + have h0 : ∀ n : ℕ, (0 : ℝ) ≤ 1 - 1 / (n + 1) := fun n => by linarith [hεle n] + have h1 : ∀ n : ℕ, (1 : ℝ) - 1 / (n + 1) ≤ 1 := fun n => by linarith [hεpos n] + have hεtendsto : Tendsto (fun n : ℕ => (1 : ℝ) / (n + 1)) atTop (𝓝 0) := + tendsto_one_div_add_atTop_nhds_zero_nat + -- Perturbed components `ρᵢ⁽ⁿ⁾ = (1 − εₙ) ρᵢ + εₙ τ`. + set F : ℕ → ι → State S := fun n i => State.mixPair (h0 n) (h1 n) (ρ i) τ with hF + -- Each perturbed component is faithful (strictly positive). + have hposN : ∀ n i, IsStrictlyPositive (F n i).op := by + intro n i + simp only [hF, State.mixPair_op, Complex.coe_smul] + refine IsStrictlyPositive.nonneg_add ?_ ?_ + · exact smul_nonneg (h0 n) ((ρ i).isDensity.nonneg) + · have hpos : (0 : ℝ) < 1 - (1 - 1 / (n + 1)) := by have := hεpos n; linarith + exact IsStrictlyPositive.smul hpos hτpos + -- Each component converges to `ρᵢ` in trace distance. + have hDcomp : ∀ i, Tendsto (fun n => (F n i).traceDistance (ρ i)) atTop (𝓝 0) := by + intro i + have hg : Tendsto (fun n : ℕ => 1 / (n + 1) * τ.traceDistance (ρ i)) atTop (𝓝 0) := by + simpa using hεtendsto.mul_const (τ.traceDistance (ρ i)) + refine squeeze_zero (fun n => State.traceDistance_nonneg _ _) (fun n => ?_) hg + simp only [hF] + have hconv := State.traceDistance_mixPair_jointly_convex (h0 n) (h1 n) (ρ i) τ (ρ i) (ρ i) + rw [State.mixPair_self (h0 n) (h1 n) (ρ i), State.traceDistance_self] at hconv + exact hconv.trans (le_of_eq (by ring)) + -- Hence each component entropy converges, and the mixture converges in trace distance. + have hScomp : ∀ i, Tendsto (fun n => (F n i).vonNeumannEntropy) atTop + (𝓝 (ρ i).vonNeumannEntropy) := fun i => + State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance (fun n => F n i) (ρ i) (hDcomp i) + have hsumD : Tendsto (fun n => ∑ i, p i * (F n i).traceDistance (ρ i)) atTop (𝓝 0) := by + have := tendsto_finsetSum Finset.univ (fun i _ => (hDcomp i).const_mul (p i)) + simpa using this + have hμlim : Tendsto (fun n => (State.mix p hp hsum (F n)).vonNeumannEntropy) atTop + (𝓝 (State.mix p hp hsum ρ).vonNeumannEntropy) := by + apply State.tendsto_vonNeumannEntropy_of_tendsto_traceDistance + refine squeeze_zero (fun n => State.traceDistance_nonneg _ _) (fun n => ?_) hsumD + exact State.traceDistance_mix_jointly_convex p hp hsum (F n) ρ + -- Assemble: the faithful bound holds along the sequence and both sides converge. + have hbound : ∀ n, (State.mix p hp hsum (F n)).vonNeumannEntropy + ≤ ∑ i, p i * (F n i).vonNeumannEntropy + Real.entropy p := + fun n => State.vonNeumannEntropy_mix_le p hp hsum (F n) (fun i => hposN n i) + have hRHSlim : Tendsto (fun n => ∑ i, p i * (F n i).vonNeumannEntropy + Real.entropy p) atTop + (𝓝 (∑ i, p i * (ρ i).vonNeumannEntropy + Real.entropy p)) := by + have hsumS : Tendsto (fun n => ∑ i, p i * (F n i).vonNeumannEntropy) atTop + (𝓝 (∑ i, p i * (ρ i).vonNeumannEntropy)) := + tendsto_finsetSum Finset.univ (fun i _ => (hScomp i).const_mul (p i)) + simpa using hsumS.add_const (Real.entropy p) + exact le_of_tendsto_of_tendsto' hμlim hRHSlim hbound + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem15.lean b/LeanPool/AxQM/NC/Ch11/Theorem15.lean new file mode 100644 index 0000000000..6b6ef6dc5d --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem15.lean @@ -0,0 +1,200 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch11.StrongSubadditivityGeneral +public import LeanPool.AxQM.Postulates.API.SubadditivityReformulations +public import LeanPool.AxQM.Postulates.API.MutualInformationAncilla +public import LeanPool.AxQM.Postulates.API.MutualInformationEvolution + +/-! +# N&C Theorem 11.15 — reformulations of strong subadditivity + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.15, p. 522. + +Theorem 11.15 collects three elementary reformulations of strong subadditivity that "provide a +powerful intuitive guide to the properties of quantum entropy": + +1. **Conditioning reduces entropy.** For a composite system `A ⊗ (B ⊗ C)`, `S(A|B,C) ≤ S(A|B)`. +2. **Discarding quantum systems never increases mutual information.** For `A ⊗ (B ⊗ C)`, + `S(A:B) ≤ S(A:B,C)`. +3. **Quantum operations never increase mutual information.** For a composite `A ⊗ B` and a + trace-preserving quantum operation `E` on `B`, `S(A':B') ≤ S(A:B)`. + +N&C proves (1) and (2) as pure algebraic rearrangements of strong subadditivity +`S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` (Theorem 11.14, eq. (11.73)); (3) via the Chapter-8 dilation of +a channel to a unitary interaction with an ancilla followed by discarding the ancilla, so that (3) +reduces to (2). + +## The formalisation + +The *strictly-positive* forms of parts (1) and (2) carry the hypothesis `IsStrictlyPositive ρ.op` +(the finite, real-valued requirement inherited from the strong subadditivity +`State.vonNeumannEntropy_add_le_add`). They are in `AxQM/Postulates/API/`, as for Theorem 11.14 and +Problem 11.4, which they follow from: + +* `AxQM.State.vonNeumannMutualInfo` + (`AxQM/Postulates/API/MutualInformation.lean`) — the quantum mutual-information + `S(A:B) = S(A) + S(B) − S(A,B)` that part (2) is phrased over. +* `AxQM.State.conditioning_reduces_vonNeumannEntropy` + (`AxQM/Postulates/API/SubadditivityReformulations.lean`) — **part (1)**, `S(A|B,C) ≤ S(A|B)`, + stated inline over von Neumann entropy differences (its two sides are the values of the + conditional entropy `State.condVonNeumannEntropy`). +* `AxQM.State.vonNeumannMutualInfo_le_of_discard` + (`AxQM/Postulates/API/SubadditivityReformulations.lean`) — **part (2)**, `S(A:B) ≤ S(A:B,C)`, + stated over the mutual information. + +Both reduce to strong subadditivity via the two marginal-consistency lemmas +`State.reducedLeft_reducedLeft_congr_assoc` (the `S(A)`-marginal) and +`State.reducedRight_reducedLeft_congr_assoc` (the `S(B)`-marginal), which identify the marginals of +the `A ⊗ B`-marginal state with those of the original tripartite state. + +The **positivity-free forms** of parts (1) and (2) — matching N&C, who state both +reformulations for an *arbitrary* quantum state — drop the `IsStrictlyPositive` hypothesis. They are +`State.conditioning_reduces_vonNeumannEntropy'` and `State.vonNeumannMutualInfo_le_of_discard'`, +proved in this file. Each is immediate from the **faithfulness-free strong +subadditivity** `State.vonNeumannEntropy_add_le_add'` +(`AxQM/NC/Ch11/StrongSubadditivityGeneral.lean`, also used for Theorem 11.16), together with the two +marginal-consistency lemmas above. + +## Part (3): quantum operations never increase mutual information + +Part (3) is proved here as `State.vonNeumannMutualInfo_dilatedChannelOnRight_le`, following N&C's +own argument on p. 523: the channel `E` on `B` is dilated to a unitary interaction `U` on `B ⊗ C` +with an ancilla `C` prepared in a **pure** product state `ω`, and the operation `(id_A ⊗ E) ρ` is +realised as the state `ρ.dilatedChannelOnRight U ω` — adjoin the pure ancilla, act by `I_A ⊗ U` on +the `B ⊗ C` factor, discard `C`. The monotonicity `S(A' : B') ≤ S(A : B)` is then read straight off +the graph as + +`S(A':B') ≤ S(A:B,C) = S(A:B,C)ₚᵣₑ = S(A:B)`, + +chaining three facts: the **discarding** step (first inequality) is the faithful discard bound +`State.vonNeumannMutualInfo_le_of_discard'`; the **local unitary** `I_A ⊗ U` leaves the mutual +information invariant (`State.vonNeumannMutualInfo_evolve_id_tmul`, the equality-case ingredient); +and the **pure product ancilla** contributes no mutual information +(`State.vonNeumannMutualInfo_tmul_pure_right`, +`AxQM/Postulates/API/MutualInformationAncilla.lean`). + +The discarding step applies part (2) — equivalently, strong +subadditivity — to the *dilated* tripartite state `U (ρ_AB ⊗ |0⟩⟨0|_C) U†`, whose pure ancilla +`|0⟩⟨0|_C` makes it rank-deficient, hence *not* strictly positive, so the strict part (2) does not +apply there. The **positivity-free discard bound `State.vonNeumannMutualInfo_le_of_discard'`** +applies: it holds for every state, resting on the faithfulness-free SSA +`State.vonNeumannEntropy_add_le_add'` obtained by a regularisation/limiting argument +(`ρ_t := (1-t)·ρ + t·(d⁻¹·1)`, `t → 0⁺`) with continuity keystone +`ContinuousLinearMap.IsDensityOp.continuousOn_vonNeumannEntropy` +(`ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyContinuous.lean`). + +Stating the operation via its dilation (rather than an abstract trace-preserving map) is faithful to +N&C's proof: the channel is given by its environment/Stinespring representation rather than as an +abstract trace-preserving map. + +## Main results (this file) + +* `AxQM.State.conditioning_reduces_vonNeumannEntropy'` — N&C Thm 11.15(1), arbitrary `ρ`. +* `AxQM.State.vonNeumannMutualInfo_le_of_discard'` — N&C Thm 11.15(2), arbitrary `ρ`. +* `AxQM.State.dilatedChannelOnRight` — the output `(id_A ⊗ E) ρ` of a dilated channel on + `B`. +* `AxQM.State.vonNeumannMutualInfo_dilatedChannelOnRight_le` — N&C Thm 11.15(3). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- **N&C Theorem 11.15(1), faithful form: conditioning reduces entropy for every state.** For an +*arbitrary* state `ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A|B,C) ≤ S(A|B)`, + +written inline over von Neumann entropy differences exactly as in the strictly-positive +`State.conditioning_reduces_vonNeumannEntropy` (each side is the corresponding value of the +conditional entropy). Immediate from the +faithfulness-free strong subadditivity `State.vonNeumannEntropy_add_le_add'` +(`AxQM/NC/Ch11/StrongSubadditivityGeneral.lean`); no faithfulness hypothesis is needed, matching +N&C's statement for a general state. -/ +theorem State.conditioning_reduces_vonNeumannEntropy' (ρ : State (A ⊗ (B ⊗ C))) : + ρ.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy ≤ + (ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy - + ρ.reducedRight.reducedLeft.vonNeumannEntropy := by + have h := State.vonNeumannEntropy_add_le_add' ρ + linarith + +/-- **N&C Theorem 11.15(2), faithful form: discarding never increases mutual information for every +state.** For an *arbitrary* state `ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A:B) ≤ S(A:B,C)`, + +with `S(A:B)` the mutual information of the `A ⊗ B`-marginal and `S(A:B,C)` that of `ρ`. Every +state's operator is a density operator, so no faithfulness hypothesis is needed — matching N&C, who +state the reformulation for a general quantum state. The proof mirrors the strictly-positive +`State.vonNeumannMutualInfo_le_of_discard` but invokes the faithfulness-free strong subadditivity +`State.vonNeumannEntropy_add_le_add'` (`AxQM/NC/Ch11/StrongSubadditivityGeneral.lean`); the shared +`S(A)` and `S(B)` marginals are identified across the two readings by +`State.reducedLeft_reducedLeft_congr_assoc` and `State.reducedRight_reducedLeft_congr_assoc`. This +form is used for part (3), on the rank-deficient pure-ancilla dilated state. -/ +theorem State.vonNeumannMutualInfo_le_of_discard' (ρ : State (A ⊗ (B ⊗ C))) : + ((ρ.congr (QSystem.assoc A B C)).reducedLeft).vonNeumannMutualInfo ≤ + ρ.vonNeumannMutualInfo := by + have hSSA := State.vonNeumannEntropy_add_le_add' ρ + rw [State.vonNeumannMutualInfo_def, State.vonNeumannMutualInfo_def, + State.reducedLeft_reducedLeft_congr_assoc, State.reducedRight_reducedLeft_congr_assoc] + linarith + +/-- **The output of a dilated quantum operation on `B`.** For a bipartite state `ρ` on `A ⊗ B`, a +unitary `U` on `B ⊗ C`, and an ancilla `C` prepared in the pure state `ω`, this is the state on +`A ⊗ B` obtained by Nielsen & Chuang's Chapter-8 dilation of a channel `E` on `B`: adjoin the pure +ancilla (`ρ ⊗ |ω⟩⟨ω|`, re-associated to `A ⊗ (B ⊗ C)`), let `U` act on the `B ⊗ C` factor +(`I_A ⊗ U`), then discard `C` (re-associate to `(A ⊗ B) ⊗ C` and trace it out). It realises +`(id_A ⊗ E) ρ` with `E(·) = Tr_C (U (· ⊗ |ω⟩⟨ω|) U†)` — every trace-preserving quantum operation on +`B` arises this way (the environment/Stinespring representation, N&C §8.2.3). -/ +noncomputable def State.dilatedChannelOnRight (ρ : State (A ⊗ B)) (U : Evolution (B ⊗ C)) + (ω : PureState C) : State (A ⊗ B) := + ((((Evolution.id (S := A)).tmul U).evolve + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω.toState))).congr + (QSystem.assoc A B C)).reducedLeft + +/-- **N&C Theorem 11.15(3): quantum operations never increase mutual information.** For a bipartite +state `ρ` on `A ⊗ B` and a trace-preserving quantum operation `E` on `B`, presented by its +Chapter-8 dilation (a unitary `U` on `B ⊗ C` with the ancilla `C` in a pure state `ω`), + +`S(A' : B') ≤ S(A : B)`, + +where the primed state is `(id_A ⊗ E) ρ = ρ.dilatedChannelOnRight U ω`. This is N&C's proof on +p. 523 read off the graph: the discarding step is the faithful discard bound +`State.vonNeumannMutualInfo_le_of_discard'` (which, being positivity-free, applies to the +*rank-deficient* pure-ancilla dilated state); the local unitary `I_A ⊗ U` on the `B ⊗ C` factor +leaves the mutual information unchanged (`State.vonNeumannMutualInfo_evolve_id_tmul`); and appending +the pure product ancilla creates no correlations (`State.vonNeumannMutualInfo_tmul_pure_right`), so +the two chained equalities carry `S(A : B, C)` back to the original `S(A : B)`. + +Stating the operation via its dilation is faithful to N&C's own argument: the channel is given by +its environment (Stinespring) representation rather than as an abstract trace-preserving map. -/ +theorem State.vonNeumannMutualInfo_dilatedChannelOnRight_le (ρ : State (A ⊗ B)) + (U : Evolution (B ⊗ C)) (ω : PureState C) : + (ρ.dilatedChannelOnRight U ω).vonNeumannMutualInfo ≤ ρ.vonNeumannMutualInfo := by + unfold State.dilatedChannelOnRight + calc ((((Evolution.id (S := A)).tmul U).evolve + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω.toState))).congr + (QSystem.assoc A B C)).reducedLeft.vonNeumannMutualInfo + ≤ (((Evolution.id (S := A)).tmul U).evolve + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω.toState))).vonNeumannMutualInfo := + State.vonNeumannMutualInfo_le_of_discard' _ + _ = (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω.toState)).vonNeumannMutualInfo := + State.vonNeumannMutualInfo_evolve_id_tmul U _ + _ = ρ.vonNeumannMutualInfo := State.vonNeumannMutualInfo_tmul_pure_right ρ ω + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem16.lean b/LeanPool/AxQM/NC/Ch11/Theorem16.lean new file mode 100644 index 0000000000..c8abde3a0b --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem16.lean @@ -0,0 +1,206 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch11.StrongSubadditivityGeneral +public import LeanPool.AxQM.NC.Ch11.Exercise24 +public import LeanPool.AxQM.Postulates.API.ReducedStateReshape +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.Postulates.API.SubadditivityReformulations + +/-! +# N&C Theorem 11.16 — subadditivity of the conditional entropy + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.16, p. 523. The quantum conditional entropy `S(·|·) = S(·,·) − S(·)` is subadditive both +jointly and in each of its two entries. N&C imposes **no positivity restriction** — the inequalities +hold for arbitrary states (the `0·log 0 = 0` convention, eq. (11.40)) — and all three are formalised +here at that full generality (**faithfulness-free**): + +* **(11.116) joint** — `State.vonNeumannEntropy_joint_cond_subadditive`, four-system composite, + `S(A,B|C,D) ≤ S(A|C) + S(B|D)`; +* **(11.117) first entry** — `State.vonNeumannEntropy_cond_subadditive_first`, for a three-system + composite, `S(A,B|C) ≤ S(A|C) + S(B|C)`; +* **(11.118) second entry** — `State.vonNeumannEntropy_cond_subadditive_second`, + `S(A|B,C) ≤ S(A|B) + S(A|C)`. + +## Ingredients + +Each conditional entropy is written out inline as its defining `S(·,·) − S(·)` von Neumann entropy +difference. The common ingredient is the general (faithfulness-free) strong subadditivity +`State.vonNeumannEntropy_add_le_add'` (`AxQM/NC/Ch11/StrongSubadditivityGeneral.lean`, N&C +Theorem 11.14 eq. (11.73)); the second entry additionally needs weak monotonicity +`State.vonNeumannEntropy_weakMonotonicity` (`LeanPool/AxQM/NC/Ch11/Exercise24.lean`, N&C eq. +(11.72)). + +## The reductions to strong subadditivity + +* **First entry (11.117).** With the state on `A ⊗ (C ⊗ B)`, strong subadditivity with middle `C` + reads `S(A,C,B) + S(C) ≤ S(A,C) + S(C,B)`; writing each conditional entropy as its difference + makes the claim a one-line `linarith`, matching N&C p. 523 ("trivially equivalent to strong + subadditivity"). +* **Joint (11.116).** With the state on `A ⊗ (C ⊗ (D ⊗ B))`, two direct strong-subadditivity + instances suffice — one on `ρ` (middle `C`), one on the `B,C,D` marginal `ρ.reducedRight` + (middle `D`). The shared marginal `S(B,C,D) = S(ρ.reducedRight)` is the *same* reduced state in + both, so `linarith` cancels it with no re-association; the arrangement is chosen so every marginal + reads off directly. Faithfulness-free because the general strong subadditivity applies to the + non-faithful marginal too. +* **Second entry (11.118).** The equivalent (11.123) + `S(A,B,C) + S(B) + S(C) ≤ S(A,B) + S(A,C) + S(B,C)` is the arithmetic mean of three inequalities + (N&C p. 523 proves it by a case split; the mean avoids it): strong subadditivity with middle `B` + (`S(A,B,C)+S(B) ≤ S(A,B)+S(B,C)`), with middle `C` (`S(A,B,C)+S(C) ≤ S(A,C)+S(B,C)`), and weak + monotonicity with shared `A` (`S(B)+S(C) ≤ S(A,B)+S(A,C)`). Summing and halving gives (11.123); + `linarith` assembles. The three instances live on three reshapes of `ρ` + (`A ⊗ (B ⊗ C)`, `A ⊗ (C ⊗ B)`, `B ⊗ (A ⊗ C)`), so most of the proof identifies their marginals + with `ρ`'s own via the reduced-state transport toolkit; the `S(A,C)` term produced by the two + strong-subadditivity/weak-monotonicity reshapes is matched through an `{A,C}`-block reshape-frame + identity. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C D : QSystem} + +/-- **N&C Theorem 11.16, subadditivity of the conditional entropy in the first entry (11.117).** +For an **arbitrary** state `ρ` on the tripartite system `A ⊗ (C ⊗ B)`, + +`S(A,B|C) ≤ S(A|C) + S(B|C)`, + +with each conditional entropy written as its defining difference `S(·|C) = S(·,C) − S(C)` — +`S(A,B|C) = S(ρ) − S(C)`, `S(A|C) = S(A,C) − S(C)`, `S(B|C) = S(B,C) − S(C)` — and the marginals +read off as `S(C) = S(ρ.reducedRight.reducedLeft)` (the middle subsystem), +`S(A,C) = S((ρ.congr (assoc A C B)).reducedLeft)` (re-associate to `(A ⊗ C) ⊗ B`, trace out `B`), +`S(B,C) = S(ρ.reducedRight)`. Immediate from the general strong subadditivity +`S(A,C,B) + S(C) ≤ S(A,C) + S(C,B)` (middle `C`) by `linarith`; faithfulness-free, matching N&C. -/ +theorem State.vonNeumannEntropy_cond_subadditive_first (ρ : State (A ⊗ (C ⊗ B))) : + ρ.vonNeumannEntropy - ρ.reducedRight.reducedLeft.vonNeumannEntropy ≤ + ((ρ.congr (QSystem.assoc A C B)).reducedLeft.vonNeumannEntropy + - ρ.reducedRight.reducedLeft.vonNeumannEntropy) + + (ρ.reducedRight.vonNeumannEntropy - ρ.reducedRight.reducedLeft.vonNeumannEntropy) := by + have h := State.vonNeumannEntropy_add_le_add' ρ + linarith + +/-- **N&C Theorem 11.16, joint subadditivity of the conditional entropy (11.116).** For an +**arbitrary** state `ρ` on the four-system composite `A ⊗ (C ⊗ (D ⊗ B))`, + +`S(A,B|C,D) ≤ S(A|C) + S(B|D)`, + +with each conditional entropy written as its defining difference. The marginals are read off as +reduced states: `S(A,B,C,D) = S(ρ)`; +`S(C,D) = S((ρ.reducedRight.congr (assoc C D B)).reducedLeft)` (the `C ⊗ D` marginal of the `B,C,D` +marginal `ρ.reducedRight`); `S(A,C) = S((ρ.congr (assoc A C (D ⊗ B))).reducedLeft)` (trace out +`D ⊗ B`); `S(C) = S(ρ.reducedRight.reducedLeft)`; `S(B,D) = S(ρ.reducedRight.reducedRight)`; +`S(D) = S(ρ.reducedRight.reducedRight.reducedLeft)`. So `S(A,B|C,D) = S(ρ) − S(C,D)`, +`S(A|C) = S(A,C) − S(C)`, `S(B|D) = S(B,D) − S(D)`. + +The proof adds two strong-subadditivity instances (N&C p. 524, eqs. (11.119)–(11.122)): one on `ρ` +(middle `C`), one on the `B,C,D` marginal `ρ.reducedRight` (middle `D`); the shared marginal +`S(B,C,D) = S(ρ.reducedRight)` is the *same* term in both, so `linarith` cancels it. +Faithfulness-free — the general strong subadditivity applies to the (non-faithful) marginal +`ρ.reducedRight` directly, so no marginal-faithfulness side condition is needed. -/ +theorem State.vonNeumannEntropy_joint_cond_subadditive (ρ : State (A ⊗ (C ⊗ (D ⊗ B)))) : + ρ.vonNeumannEntropy + - (ρ.reducedRight.congr (QSystem.assoc C D B)).reducedLeft.vonNeumannEntropy ≤ + ((ρ.congr (QSystem.assoc A C (D ⊗ B))).reducedLeft.vonNeumannEntropy + - ρ.reducedRight.reducedLeft.vonNeumannEntropy) + + (ρ.reducedRight.reducedRight.vonNeumannEntropy + - ρ.reducedRight.reducedRight.reducedLeft.vonNeumannEntropy) := by + have hi := State.vonNeumannEntropy_add_le_add' ρ + have hii := State.vonNeumannEntropy_add_le_add' ρ.reducedRight + linarith + +/-- The "shared-`A`" reshape `A ⊗ (B ⊗ C) ≃ₛ B ⊗ (A ⊗ C)`: move `A` into the middle so weak +monotonicity `S(B) + S(C) ≤ S(A,B) + S(A,C)` reads off directly. -/ +private def secondEntryReshape (A B C : QSystem) : (A ⊗ (B ⊗ C)) ≃ₛ (B ⊗ (A ⊗ C)) := + (QSystem.assoc A B C).trans + (((QSystem.Iso.comm A B).tmul (QSystem.Iso.refl C)).trans (QSystem.assoc B A C).symm) + +/-- **N&C Theorem 11.16, subadditivity of the conditional entropy in the second entry (11.118).** +For an **arbitrary** state `ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A|B,C) ≤ S(A|B) + S(A|C)`, + +with each conditional entropy written as its defining difference — `S(A|B,C) = S(ρ) − S(B,C)`, +`S(A|B) = S(A,B) − S(B)`, `S(A|C) = S(A,C) − S(C)` — and the marginals read off as reduced states: +`S(B,C) = S(ρ.reducedRight)`, `S(A,B) = S((ρ.congr (assoc A B C)).reducedLeft)`, +`S(B) = S(ρ.reducedRight.reducedLeft)`, `S(C) = S(ρ.reducedRight.reducedRight)`, and the `A ⊗ C` +marginal `S(A,C) = S(((ρ.congr (id ⊗ comm B C)).congr (assoc A C B)).reducedLeft)` (reshape to +`A ⊗ (C ⊗ B)`, re-associate to `(A ⊗ C) ⊗ B`, trace out `B`). + +Equivalent to (11.123) `S(A,B,C) + S(B) + S(C) ≤ S(A,B) + S(A,C) + S(B,C)`, the mean of two strong +subadditivity instances (`State.vonNeumannEntropy_add_le_add'`, middles `B` and `C`) and weak +monotonicity (`State.vonNeumannEntropy_weakMonotonicity`, shared `A`); see the module docstring. +Faithfulness-free — the weak-monotonicity ingredient itself needs general strong subadditivity. -/ +theorem State.vonNeumannEntropy_cond_subadditive_second (ρ : State (A ⊗ (B ⊗ C))) : + ρ.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy ≤ + ((ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy + - ρ.reducedRight.reducedLeft.vonNeumannEntropy) + + (((ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl A) (QSystem.Iso.comm B C))).congr + (QSystem.assoc A C B)).reducedLeft.vonNeumannEntropy + - ρ.reducedRight.reducedRight.vonNeumannEntropy) := by + -- form2-i: strong subadditivity on ρ, middle B — `S(A,B,C)+S(B) ≤ S(A,B)+S(B,C)`. + have hi := State.vonNeumannEntropy_add_le_add' ρ + -- form2-ii: strong subadditivity on ρ reshaped to A ⊗ (C ⊗ B), middle C — + -- `S(A,B,C)+S(C) ≤ S(A,C)+S(B,C)`. + have hii := State.vonNeumannEntropy_add_le_add' + (ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl A) (QSystem.Iso.comm B C))) + rw [State.reducedRight_congr_tmul_right, State.vonNeumannEntropy_congr, + ← State.reducedRight_congr_comm, State.vonNeumannEntropy_congr] at hii + -- WM: weak monotonicity on ρ reshaped to B ⊗ (A ⊗ C) — `S(B)+S(C) ≤ S(A,B)+S(A,C)`. + have hwm := State.vonNeumannEntropy_weakMonotonicity (ρ.congr (secondEntryReshape A B C)) + -- `S(B) = S(ρ_B)`: the `B`-marginal of the reshaped state is `ρ`'s. + have eB : (State.congr (secondEntryReshape A B C) ρ).reducedLeft + = ρ.reducedRight.reducedLeft := by + simp only [secondEntryReshape] + rw [State.congr_trans, State.congr_trans, State.reducedLeft_congr_assoc_symm, + State.reducedLeft_congr_tmul_left, ← State.reducedRight_congr_comm, + State.reducedRight_reducedLeft_congr_assoc] + -- `S(C) = S(ρ_C)`. + have eC : (State.congr (secondEntryReshape A B C) ρ).reducedRight.reducedRight + = ρ.reducedRight.reducedRight := by + simp only [secondEntryReshape] + rw [State.congr_trans, State.congr_trans, State.reducedRight_reducedRight_congr_assoc_symm, + State.reducedRight_congr_tmul_refl, + ← State.reducedRight_reducedRight_congr_assoc_symm (State.congr (QSystem.assoc A B C) ρ), + ← State.congr_trans, QSystem.Iso.trans_symm_self, State.congr_refl] + -- `S(B,A) = S(A,B)`: the `assoc` cancels its inverse in `e3`, leaving `ρ_{AB}` up to `A ↔ B`. + have eAB : + (State.congr (QSystem.assoc B A C) (State.congr (secondEntryReshape A B C) ρ)).reducedLeft + = (ρ.congr (QSystem.assoc A B C)).reducedLeft.congr (QSystem.Iso.comm A B) := by + simp only [secondEntryReshape] + rw [State.congr_trans, State.congr_trans, ← State.congr_trans, QSystem.Iso.symm_trans_self, + State.congr_refl, State.reducedLeft_congr_tmul_left] + -- `S(A,C)`: the `{A,C}` marginal of the reshaped state matches the one in the statement. + have eAC : (State.congr (secondEntryReshape A B C) ρ).reducedRight + = ((ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl A) (QSystem.Iso.comm B C))).congr + (QSystem.assoc A C B)).reducedLeft := by + rw [State.reducedRight_congr_comm, ← State.congr_trans, ← State.congr_trans] + apply congrArg State.reducedLeft + apply congrArg (fun e => State.congr e ρ) + -- both isos send `a ⊗ (b ⊗ c) ↦ (a ⊗ c) ⊗ b`; prove equal on pure tensors. + simp only [secondEntryReshape] + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + apply TensorProduct.ext' + intro a bc + induction bc using TensorProduct.inductionOn with + | add u v hu hv => erw [TensorProduct.tmul_add, map_add, map_add, hu, hv] + | tmul b c => rfl + rw [eB, eC, eAB, eAC, State.vonNeumannEntropy_congr] at hwm + linarith + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem6.lean b/LeanPool/AxQM/NC/Ch11/Theorem6.lean new file mode 100644 index 0000000000..512de29f60 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem6.lean @@ -0,0 +1,197 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Fannes +public import Mathlib.Analysis.Complex.ExponentialBounds + +/-! +# Nielsen & Chuang, Theorem 11.6 (Fannes' inequality) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.6, Box 11.2, p. 512. + +*Fannes' inequality* bounds how much the von Neumann entropy can change when a state is perturbed. +N&C's Theorem 11.6 states **two** inequalities within the theorem box; both are formalised here: + +* `abs_vonNeumannEntropy_sub_le_fannes` — the main bound (N&C eq. (11.44)): + `|S(ρ) − S(σ)| ≤ T · log d + η(T)`, under the hypothesis `T ≤ 1/e`; +* `abs_vonNeumannEntropy_sub_le_fannes_weak` — the weaker **unconditional** bound (N&C eq. (11.45)): + `|S(ρ) − S(σ)| ≤ T · log d + 1/e`, with the `T ≤ 1/e` restriction removed, + +where `d` is the dimension of the state space, `η(x) = −x log x = Real.negMulLog x`, and +`1/e = Real.exp (-1)`. + +## The trace-distance convention + +N&C's Box 11.2 writes the trace distance in its Fannes proof as `T(ρ, σ) = tr(R) + tr(Q)` where +`ρ − σ = Q − R` is the Jordan decomposition into positive parts (eq. (11.46)): this is the **full +trace norm** `‖ρ − σ‖₁ = tr|ρ − σ|`, *twice* the metric trace distance `D(ρ, σ) = ½‖ρ − σ‖₁` of +N&C §9.2.1 eq. (9.11). The library `State.traceDistance` is the metric `D = ½‖·‖₁`, so N&C's `T` +equals `2 · State.traceDistance`. Both theorems are stated with the trace distance +and the explicit factor `2`: N&C's `T` is `2 · D(ρ, σ)` throughout, so these are exactly +N&C (11.44) and (11.45) with `T = 2D`. + +## Base convention + +The library measures entropy in *nats* (natural logarithm), so `S`, `log`, and `η` throughout use +`Real.log`. + +* **(11.44) is base-invariant.** Every term — `S`, `log d`, and the additive `η(T)` — scales by the + same factor `ln b` under a change to base `b`, so the inequality is the base-scaled image of + N&C's base-2 statement; the nat rendering is a faithful reformulation. +* **(11.45)'s constant `1/e` is base-specific, and the nat rendering is the correct one.** Its + additive term is `1/e = max_{x ≥ 0} η(x)`, a *constant*, not a term that scales with `S` and + `log d`. The maximiser `x = 1/e` of `η_b(x) = −x log_b x` is base-independent, but the maximum + *value* `η_b(1/e) = 1/(e · ln b)` is not: it is `1/e` in nats and `1/(e · ln 2) ≈ 0.53` in + base 2. We state (11.45) in nats precisely because there `max η = 1/e = Real.exp (-1)`, matching + N&C's literal `1/e`; this is the mathematically-correct reading of N&C's constant (in a base-2 + presentation the max-`η` constant would instead be `1/(e · ln 2)`). Both theorem *statements* are + faithful; only this constant is not base-invariant. + +## Proof + +Both bounds share the analytic core `State.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff` +(`AxQM/Postulates/API/Fannes.lean`), which — using the sorted eigenvalue spectra `r`, `s` of `ρ`, +`σ`, Mirsky's inequality, the total-variation bound `|rᵢ − sᵢ| ≤ Δ/2`, the continuity kernel +`Real.abs_negMulLog_sub_le`, and the grouping bound `Real.sum_negMulLog_le` — establishes, whenever +`‖ρ.op − σ.op‖₁ ≤ 1`, the `Δ`-form + +`|S(ρ) − S(σ)| ≤ Δ · log d + η(Δ)`, `Δ = ∑ᵢ |rᵢ − sᵢ|`. + +The two theorems apply this core and then diverge only in the last step: + +* **(11.44)** (`T ≤ 1/e`, hence `‖ρ.op − σ.op‖₁ = T ≤ 1`): with `Δ ≤ T` (Mirsky) and `log d ≥ 0`, + and `η` monotone on `[0, 1/e]` (`Real.strictMonoOn_negMulLog_Icc`) with `0 ≤ Δ ≤ T ≤ 1/e`, the + `Δ`-form lifts to `|S(ρ) − S(σ)| ≤ T · log d + η(T)` (eq. (11.49)). +* **(11.45)** (unconditional): N&C's remark that it "follows with minor modifications" is inaccurate + — the continuity step needs `|rᵢ − sᵢ| ≤ 1/2`, which fails once `T > 1`. We split on `T`: + * if `T ≤ 1` the core applies, and `η(Δ) ≤ 1/e` (`Real.negMulLog_le_exp_neg_one`, the maximum of + `η`) with `Δ · log d ≤ T · log d` gives `|S(ρ) − S(σ)| ≤ T · log d + 1/e`; + * if `T > 1` then `|S(ρ) − S(σ)| ≤ log d ≤ T · log d ≤ T · log d + 1/e` directly, since both + entropies lie in `[0, log d]` (`State.vonNeumannEntropy_nonneg`, + `State.vonNeumannEntropy_le_log_finrank`) and `log d ≥ 0`. + +The correction to N&C's proof of the `|rᵢ − sᵢ| ≤ 1/2` step (N&C's "a moment's thought shows +`|rᵢ − sᵢ| ≤ 1/2`" does *not* follow from the eigenvalues lying in `[0,1]` — a pure `ρ` against `σ` +with spectrum `(0.4, 0.3, 0.3)` gives `|r₁ − s₁| = 0.6` — but from the total-variation bound +`|rᵢ − sᵢ| ≤ Δ/2`) lives in the core lemma's proof. + +## Ingredients + +Both statements are about `State.vonNeumannEntropy` and `State.traceDistance`. The shared analytic +core is the lemma `State.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff` +(`AxQM/Postulates/API/Fannes.lean`); the spectral and real-analysis results it uses are in +`ToMathlib/` (`Real.sum_negMulLog_le`, `Real.abs_negMulLog_sub_le`, +`Real.strictMonoOn_negMulLog_Icc`, `Real.negMulLog_le_exp_neg_one`, and Mirsky's +`IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm`). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +variable {S : QSystem} + +/-- **Fannes' inequality** (Nielsen & Chuang, Theorem 11.6, eq. (11.44)). For states `ρ, σ` of a +quantum system `S` whose trace distance satisfies `2·D(ρ, σ) ≤ 1/e`, the von Neumann entropies +differ by at most + +`|S(ρ) − S(σ)| ≤ 2·D(ρ, σ) · log d + η(2·D(ρ, σ))`, + +where `d = S.dim` is the dimension of the state space and `η = Real.negMulLog`. Here `2·D(ρ, σ) = +‖ρ.op − σ.op‖₁` is N&C's trace-distance `T` (see the module docstring: N&C's `T` is the full trace +norm, twice the metric `State.traceDistance`), so this is exactly N&C (11.44) with `T = 2D`. -/ +theorem State.abs_vonNeumannEntropy_sub_le_fannes (ρ σ : State S) + (hT : 2 * ρ.traceDistance σ ≤ Real.exp (-1)) : + |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ 2 * ρ.traceDistance σ * Real.log (S.dim : ℝ) + + Real.negMulLog (2 * ρ.traceDistance σ) := by + obtain ⟨n, hn⟩ : ∃ n, Module.finrank ℂ S.space = n := ⟨_, rfl⟩ + -- `T = ‖ρ.op − σ.op‖₁ = 2·D(ρ, σ)` is N&C's trace distance; `T ≤ 1/e ≤ 1/2 ≤ 1`. + set T : ℝ := (ρ.op - σ.op).traceNorm + have hT2 : 2 * ρ.traceDistance σ = T := by rw [State.traceDistance_eq]; ring + have hTe : T ≤ Real.exp (-1) := hT2 ▸ hT + have hehalf : Real.exp (-1) ≤ 1 / 2 := by + rw [Real.exp_neg] + have h2 : (2 : ℝ) ≤ Real.exp 1 := by linarith [Real.exp_one_gt_d9] + calc (Real.exp 1)⁻¹ ≤ (2 : ℝ)⁻¹ := by gcongr + _ = 1 / 2 := by norm_num + have hT1 : T ≤ 1 := by linarith [hTe, hehalf] + -- `log d ≥ 0`: `d = n ≥ 1` since a state forces `S.space` nontrivial. + have hL0 : 0 ≤ Real.log (n : ℝ) := hn ▸ ρ.log_finrank_nonneg + have hdimn : (S.dim : ℝ) = (n : ℝ) := by exact_mod_cast hn + -- The shared `Δ`-form core, then lift `η(Δ) ≤ η(T)` by monotonicity on `[0, 1/e]`. + have hcore := ρ.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff σ hn hT1 + set Δ : ℝ := ∑ i, |ρ.isDensity.isSymmetric.eigenvalues hn i + - σ.isDensity.isSymmetric.eigenvalues hn i| + have hMirsky : Δ ≤ T := + IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm + ρ.isDensity.isPositive.isSelfAdjoint σ.isDensity.isPositive.isSelfAdjoint hn + have hΔ0 : 0 ≤ Δ := Finset.sum_nonneg fun i _ => abs_nonneg _ + have hT0 : 0 ≤ T := ContinuousLinearMap.traceNorm_nonneg _ + have hmono : Δ.negMulLog ≤ T.negMulLog := + Real.strictMonoOn_negMulLog_Icc.monotoneOn ⟨hΔ0, le_trans hMirsky hTe⟩ ⟨hT0, hTe⟩ hMirsky + have hmul : Δ * Real.log (n : ℝ) ≤ T * Real.log (n : ℝ) := + mul_le_mul_of_nonneg_right hMirsky hL0 + rw [hT2, hdimn] + calc |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ Δ * Real.log (n : ℝ) + Δ.negMulLog := hcore + _ ≤ T * Real.log (n : ℝ) + T.negMulLog := by linarith [hmul, hmono] + +/-- **Weaker (unconditional) Fannes' inequality** (Nielsen & Chuang, Theorem 11.6, eq. (11.45)). +Dropping the `T ≤ 1/e` restriction, for *any* states `ρ, σ` of a quantum system `S`, + +`|S(ρ) − S(σ)| ≤ 2·D(ρ, σ) · log d + 1/e`, + +where `d = S.dim`, `1/e = Real.exp (-1)`, and `2·D(ρ, σ) = ‖ρ.op − σ.op‖₁` is N&C's trace-distance +`T` (see the module docstring). This is N&C (11.45) with `T = 2D`. The bound is genuinely weaker +than (11.44) — it replaces `η(T)` by its maximum `1/e` — but holds with no hypothesis on the trace +distance. -/ +theorem State.abs_vonNeumannEntropy_sub_le_fannes_weak (ρ σ : State S) : + |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ 2 * ρ.traceDistance σ * Real.log (S.dim : ℝ) + Real.exp (-1) := by + obtain ⟨n, hn⟩ : ∃ n, Module.finrank ℂ S.space = n := ⟨_, rfl⟩ + set T : ℝ := (ρ.op - σ.op).traceNorm + have hT2 : 2 * ρ.traceDistance σ = T := by rw [State.traceDistance_eq]; ring + have hL0 : 0 ≤ Real.log (n : ℝ) := hn ▸ ρ.log_finrank_nonneg + have hexp0 : (0 : ℝ) ≤ Real.exp (-1) := (Real.exp_pos _).le + have hdimn : (S.dim : ℝ) = (n : ℝ) := by exact_mod_cast hn + rw [hT2, hdimn] + by_cases hT1 : T ≤ 1 + · -- Case `T ≤ 1`: the shared core, then bound the tail by the maximum `η(Δ) ≤ 1/e`. + have hcore := ρ.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff σ hn hT1 + set Δ : ℝ := ∑ i, |ρ.isDensity.isSymmetric.eigenvalues hn i + - σ.isDensity.isSymmetric.eigenvalues hn i| + have hMirsky : Δ ≤ T := + IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm + ρ.isDensity.isPositive.isSelfAdjoint σ.isDensity.isPositive.isSelfAdjoint hn + have hΔ0 : 0 ≤ Δ := Finset.sum_nonneg fun i _ => abs_nonneg _ + have hmul : Δ * Real.log (n : ℝ) ≤ T * Real.log (n : ℝ) := + mul_le_mul_of_nonneg_right hMirsky hL0 + have hηΔ : Δ.negMulLog ≤ Real.exp (-1) := Real.negMulLog_le_exp_neg_one hΔ0 + calc |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ Δ * Real.log (n : ℝ) + Δ.negMulLog := hcore + _ ≤ T * Real.log (n : ℝ) + Real.exp (-1) := by linarith [hmul, hηΔ] + · -- Case `T > 1`: the crude bound `|S(ρ) − S(σ)| ≤ log d ≤ T · log d`. + rw [not_le] at hT1 + have hSρ0 : 0 ≤ ρ.vonNeumannEntropy := ρ.vonNeumannEntropy_nonneg + have hSσ0 : 0 ≤ σ.vonNeumannEntropy := σ.vonNeumannEntropy_nonneg + have hSρd : ρ.vonNeumannEntropy ≤ Real.log (n : ℝ) := by + have h := ρ.vonNeumannEntropy_le_log_finrank; rwa [hn] at h + have hSσd : σ.vonNeumannEntropy ≤ Real.log (n : ℝ) := by + have h := σ.vonNeumannEntropy_le_log_finrank; rwa [hn] at h + calc |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ Real.log (n : ℝ) := abs_sub_le_iff.mpr ⟨by linarith, by linarith⟩ + _ ≤ T * Real.log (n : ℝ) := le_mul_of_one_le_left hL0 hT1.le + _ ≤ T * Real.log (n : ℝ) + Real.exp (-1) := by linarith [hexp0] + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem8.lean b/LeanPool/AxQM/NC/Ch11/Theorem8.lean new file mode 100644 index 0000000000..09e3e23da9 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem8.lean @@ -0,0 +1,170 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Purity +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy + +/-! +# Nielsen & Chuang, Theorem 11.8 (Basic properties of von Neumann entropy) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.8, p. 513. + +The theorem collects the basic properties of the von Neumann entropy `S(ρ)` of a state `ρ`: + +1. `S(ρ) ≥ 0`, with `S(ρ) = 0` **iff** `ρ` is pure. +2. In a `d`-dimensional space `S(ρ) ≤ log d`, with equality **iff** `ρ` is the maximally mixed + state `I/d`. +3. If a composite system `AB` is in a pure state then `S(A) = S(B)`. +4. If probabilities `pᵢ` and states `ρᵢ` have support on mutually orthogonal subspaces, then + `S(∑ᵢ pᵢ ρᵢ) = H(pᵢ) + ∑ᵢ pᵢ S(ρᵢ)`. +5. **Joint entropy theorem:** for probabilities `pᵢ`, orthonormal states `|i⟩` of a system `A`, and + arbitrary states `ρᵢ` of a system `B`, `S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(pᵢ) + ∑ᵢ pᵢ S(ρᵢ)`. + +**Base convention.** The library measures entropy in *nats* (natural logarithm), so `S` and `log` +throughout are natural log. Every statement below is invariant under the choice of logarithm base +(both sides scale by the same factor), a faithful reformulation of N&C's base-2 presentation. + +## The formalisation + +Theorem 11.8 is a five-part theorem, most parts requiring their own spectral development. + +**Forward directions and value facts of parts (1)–(2):** + +* Part 1, non-negativity `S(ρ) ≥ 0` — `AxQM.State.vonNeumannEntropy_nonneg` + (`AxQM/Postulates/API/Entropy.lean`). +* Part 1, `ρ` pure `⇒ S(ρ) = 0` — `AxQM.PureState.vonNeumannEntropy_toState_eq_zero` + (for a `PureState`) and, for a general state satisfying `State.IsPure`, + `AxQM.State.vonNeumannEntropy_eq_zero_of_isPure` **(this file)**. +* Part 1, converse `S(ρ) = 0 ⇒ ρ` pure — `AxQM.State.isPure_of_vonNeumannEntropy_eq_zero`, + and hence the full first-item characterization `S(ρ) = 0 ↔ ρ` pure — + `AxQM.State.vonNeumannEntropy_eq_zero_iff_isPure` **(this file)**. +* Part 2, upper bound `S(ρ) ≤ log d` — `AxQM.State.vonNeumannEntropy_le_log_finrank` + (`AxQM/Postulates/API/Entropy.lean`). +* Part 2, value at the maximally mixed state `S(I/d) = log d` — + `AxQM.State.vonNeumannEntropy_maximallyMixed` (`AxQM/Postulates/API/EntropyComposite.lean`). +* Part 2, equality characterization `S(ρ) = log d ↔ ρ = I/d` — + `AxQM.State.vonNeumannEntropy_eq_log_finrank_iff_eq_maximallyMixed`, assembled from the + forward value above and the converse `State.eq_maximallyMixed_of_vonNeumannEntropy_eq_log_finrank` + (`AxQM/Postulates/API/EntropyExtremal.lean`). + +**Analytic engine for the remaining parts.** Parts (3)–(5) and the equality-*characterizations* of +(1)–(2) all reduce a von Neumann entropy to the Shannon entropy of an eigenvalue spectrum presented +in a task-specific eigenbasis. That reduction is +`AxQM.State.vonNeumannEntropy_eq_entropy_of_isEigenbasis` +(`AxQM/Postulates/API/EntropySpectral.lean`): `S(ρ) = H(μ)` for any orthonormal basis diagonalizing +`ρ.op` with real eigenvalues `μ`. + +**Part 3, `S(A) = S(B)` for a pure composite.** +`AxQM.PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight` +(`AxQM/Postulates/API/PureMarginalEntropy.lean`): both reduced states of a bipartite pure state have +von Neumann entropy `H(λ²)`, the Shannon entropy of the squared Schmidt coefficients, so they agree. +The two reduced operators are read off a Schmidt decomposition `|ψ⟩ = ∑ᵢ λᵢ |aᵢ⟩|bᵢ⟩` as +`ρᴬ = ∑ᵢ λᵢ² |aᵢ⟩⟨aᵢ|` and `ρᴮ = ∑ᵢ λᵢ² |bᵢ⟩⟨bᵢ|` +(`LinearMap.partialTrace{Right,Left}_rankOne_eq_sum_rankOne_of_schmidt`), and the shared +orthonormal-eigenfamily engine `State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum` +(`AxQM/Postulates/API/EntropySpectral.lean`) evaluates each entropy to `H(λ²)`. It is also used in +Exercise 11.14 and in the reverse direction of Theorem 11.10. + +**Part 4, orthogonal-support mixture identity.** +`AxQM.State.vonNeumannEntropy_mix_orthogonalSupport` +(`AxQM/Postulates/API/EntropyOrthogonalMixture.lean`): for a probability distribution `pᵢ` and +states `ρᵢ` with *pairwise orthogonal supports*, `S(∑ᵢ pᵢ ρᵢ) = H(pᵢ) + ∑ᵢ pᵢ S(ρᵢ)` (eq. (11.57)). +Here `State.support` is a `Submodule ℂ S.space`, built from the density operator `.op`. The proof +assembles the summands' eigenbases into a rank-one decomposition of the mixture that is orthonormal +on its support (orthogonal supports ⇒ cross terms vanish), applies the degenerate-weight engine +`State.vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero` +(`AxQM/Postulates/API/EntropySpectral.lean`), and splits the resulting Shannon entropy with the +grouping identity `Real.entropy_sigma_mul` +(`ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean`). The same file also contains the +equivalent constructive form `State.vonNeumannEntropy_mix_of_orthonormal_rankOne` (the +Theorem 11.10 equality "if" direction), which takes the jointly-orthonormal eigen-decompositions +as hypotheses rather than deriving them. + +**Part 5, the joint entropy theorem.** +`AxQM.State.vonNeumannEntropy_jointEntropyTheorem` +(`AxQM/Postulates/API/EntropyJointTheorem.lean`): for probabilities `pᵢ`, an orthonormal family of +pure states `|i⟩ = e i` of a system `A` (`Orthonormal ℂ (fun i => (e i).vec)`), and *arbitrary* +states `ρᵢ` of a system `B`, `S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(pᵢ) + ∑ᵢ pᵢ S(ρᵢ)` (eq. (11.58)). +The orthonormality hypothesis is stated for the state vectors `.vec`. As N&C notes, it is "immediate +from the preceding result": the block states `|i⟩⟨i| ⊗ ρᵢ` have mutually orthogonal supports (their +operator product vanishes because `⟪i|j⟫ = 0` for `i ≠ j`), so part (4) +`State.vonNeumannEntropy_mix_orthogonalSupport` applies, and tensor additivity +`State.vonNeumannEntropy_tmul` with `S(|i⟩⟨i|) = 0` (`PureState.vonNeumannEntropy_toState_eq_zero`) +collapses each `S(|i⟩⟨i| ⊗ ρᵢ) = S(ρᵢ)`. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **A pure state has zero von Neumann entropy** (Nielsen–Chuang Theorem 11.8, part (1), forward +direction, for a general state). If `ρ` is pure — `ρ = |ψ⟩⟨ψ|` for some `PureState ψ` — then +`S(ρ) = 0`. This is the `State.IsPure` form of `PureState.vonNeumannEntropy_toState_eq_zero`: +purity means `ρ.op` is a rank-one projector `|v⟩⟨v|` (`State.isPure_iff_exists_rankOne`), whose +spectrum is `(1, 0, …, 0)` and hence has zero Shannon entropy +(`ContinuousLinearMap.vonNeumannEntropy_rankOne_self`). -/ +theorem State.vonNeumannEntropy_eq_zero_of_isPure (ρ : State S) (h : ρ.IsPure) : + ρ.vonNeumannEntropy = 0 := by + obtain ⟨v, hv, hop⟩ := ρ.isPure_iff_exists_rankOne.mp h + rw [State.vonNeumannEntropy_def, hop] + exact ContinuousLinearMap.vonNeumannEntropy_rankOne_self hv + +/-- **A state of zero von Neumann entropy is pure** (Nielsen–Chuang Theorem 11.8, part (1), +converse direction): if `S(ρ) = 0` then `ρ` is pure. + +Diagonalize `ρ.op` in its canonical orthonormal eigenbasis `e` with eigenvalue spectrum `μ`, a +probability distribution (`IsDensityOp.eigenvalues_nonneg` / `eigenvalues_sum_eq_one`). Then +`S(ρ) = H(μ)` (`vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq`), so `S(ρ) = 0` means the +Shannon entropy of the spectrum vanishes; the general point-mass characterization +`Real.entropy_eq_zero_iff` then forces exactly one eigenvalue `μ_k = 1` with the rest `0`. Hence the +spectral reconstruction `ρ.op = ∑ᵢ μᵢ |eᵢ⟩⟨eᵢ|` (`IsSelfAdjoint.spectral_sum`) collapses to the +single rank-one projector `|e_k⟩⟨e_k|` of the unit vector `e_k`, so `ρ` is pure by +`State.isPure_iff_exists_rankOne`. -/ +theorem State.isPure_of_vonNeumannEntropy_eq_zero (ρ : State S) (h : ρ.vonNeumannEntropy = 0) : + ρ.IsPure := by + classical + have := ρ.nontrivial_space + have hsa : IsSelfAdjoint ρ.op := ρ.isDensity.isPositive.isSelfAdjoint + have hfin : Module.finrank ℂ S.space = Module.finrank ℂ S.space := rfl + have : Nonempty (Fin (Module.finrank ℂ S.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + -- The canonical spectrum `μ` is a probability distribution and `S(ρ) = H(μ) = 0`. + have hnonneg : ∀ i, 0 ≤ hsa.isSymmetric.eigenvalues hfin i := + fun i => ρ.isDensity.eigenvalues_nonneg hfin i + have hsum : ∑ i, hsa.isSymmetric.eigenvalues hfin i = 1 := + ρ.isDensity.eigenvalues_sum_eq_one hfin + have hent : Real.entropy (fun i => hsa.isSymmetric.eigenvalues hfin i) = 0 := by + rw [← ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq + hsa.isSymmetric hfin, ← State.vonNeumannEntropy_def] + exact h + -- The vanishing entropy of the probability spectrum forces a point mass: `μ_k = 1`, rest `0`. + obtain ⟨k, hμk, hrest⟩ := (Real.entropy_eq_zero_iff hnonneg hsum).mp hent + -- Spectral reconstruction collapses to the single rank-one projector `|e_k⟩⟨e_k|`. + refine ρ.isPure_iff_exists_rankOne.mpr + ⟨hsa.isSymmetric.eigenvectorBasis hfin k, + (hsa.isSymmetric.eigenvectorBasis hfin).norm_eq_one k, ?_⟩ + refine (hsa.spectral_sum hfin).trans ?_ + rw [Finset.sum_eq_single k (fun i _ hik => by simp [hrest i hik]) + (fun hknot => absurd (Finset.mem_univ k) hknot), + hμk] + simp + +/-- **The von Neumann entropy vanishes exactly on pure states** (Nielsen–Chuang Theorem 11.8, +part (1)): `S(ρ) = 0 ↔ ρ` is pure. The forward direction is +`State.isPure_of_vonNeumannEntropy_eq_zero`; the backward direction is +`State.vonNeumannEntropy_eq_zero_of_isPure`. Together with `State.vonNeumannEntropy_nonneg` +(`S(ρ) ≥ 0`) this is the full first item of the theorem. -/ +theorem State.vonNeumannEntropy_eq_zero_iff_isPure (ρ : State S) : + ρ.vonNeumannEntropy = 0 ↔ ρ.IsPure := + ⟨ρ.isPure_of_vonNeumannEntropy_eq_zero, ρ.vonNeumannEntropy_eq_zero_of_isPure⟩ + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/Theorem9.lean b/LeanPool/AxQM/NC/Ch11/Theorem9.lean new file mode 100644 index 0000000000..3fe0e86756 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/Theorem9.lean @@ -0,0 +1,147 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.UnreadMeasurement +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.RelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyPinching +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedKleinInequality + +/-! +# N&C Theorem 11.9 — Projective measurements increase entropy + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.9, p. 515. + +Projective measurements increase entropy: S(rho')>=S(rho), equality iff rho=rho'. + +Here `ρ'` is the **unread (non-selective) post-measurement state** +(`AxQM.Measurement.unreadState`) of a **projective** measurement +(`AxQM.Measurement.IsProjective`), and `S` is the von Neumann entropy +(`AxQM.State.vonNeumannEntropy`). + +## The two claims + +The theorem's two independent claims are formalised as two named theorems, not bundled into one +conjunction: + +* `Measurement.IsProjective.vonNeumannEntropy_unreadState_ge` — `S(ρ) ≤ S(ρ')` (eq. (11.66)). +* `Measurement.IsProjective.vonNeumannEntropy_unreadState_eq_iff` — `S(ρ') = S(ρ) ↔ ρ' = ρ`, + the equality condition. + +Both statements are about `Measurement`, `Measurement.IsProjective`, `Measurement.unreadState`, +`State` and `State.vonNeumannEntropy`. Compare Klein's inequality, Theorem 11.7 +([upstream `AxQM/NC/Ch11/Theorem11_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Theorem11_7.lean)). + +## Proof, and fidelity to N&C + +The proof is exactly Nielsen & Chuang's: apply Klein's inequality to `ρ` and `ρ'` and use the +**entropy-increase identity** `D(ρ ‖ ρ') = S(ρ') − S(ρ)`. That identity holds because each +projector `Pᵢ` commutes with `ρ' = Σⱼ Pⱼ ρ Pⱼ`, hence with `log ρ'`, so the completeness relation +`Σᵢ Pᵢ = 1` and cyclicity of the trace give `tr((log ρ') ρ) = tr((log ρ') ρ') = −S(ρ')` — i.e. +`−tr(ρ log ρ') = S(ρ')` (N&C eqs. (11.68)–(11.71)). Non-negativity of `D` then gives `S(ρ') ≥ S(ρ)`, +and the equality case of Klein gives `ρ = ρ'`. + +The result is proved in **full N&C generality** — for *every* density operator `ρ`, with no +faithfulness hypothesis (which would be a silent weakening). The +faithful Klein inequality needs the second argument full-rank, but here `ρ' = Σᵢ Pᵢ ρ Pᵢ` is +generally rank-deficient. This is handled by the **support condition**: the pinching never enlarges +the support, `ker ρ' ≤ ker ρ` (`ContinuousLinearMap.hasSupportLE_krausSumₗ_of_isStarProjection`), +under which the non-faithful Klein inequality applies. The two ingredients are in +`ToMathlib/`: + +* `ContinuousLinearMap.quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub` — the + entropy-increase identity `D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = S(Σᵢ Pᵢ ρ Pᵢ) − S(ρ)`; +* `ContinuousLinearMap.quantumRelativeEntropy_nonneg_of_hasSupportLE` and + `ContinuousLinearMap.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE` — the non-faithful Klein + inequality `D ≥ 0` and `D = 0 ↔ ρ = σ` under `HasSupportLE ρ σ`. + +The unread state `ρ'` of a projective measurement has operator `Σᵢ Pᵢ ρ Pᵢ` on the nose +(`Measurement.unreadState_op` gives `ρ'.op = krausSumₗ m.op ρ.op`, and for a projective measurement +`krausSumₗ m.op ρ.op = Σᵢ Pᵢ ρ Pᵢ`), so the operator results apply directly to states through the +`_def` bridges. +-/ + +@[expose] public section + +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +/-- **Nielsen & Chuang Theorem 11.9, eq. (11.66): projective measurements never decrease entropy.** +For a projective measurement `m` and any state `ρ`, the unread (non-selective) post-measurement +state `ρ' = Σᵢ Pᵢ ρ Pᵢ` (`m.unreadState ρ`) has entropy at least that of `ρ`, + + `S(ρ) ≤ S(ρ')`. + +Proof (N&C's): the entropy-increase identity `D(ρ ‖ ρ') = S(ρ') − S(ρ)`, together with +non-negativity of the relative entropy under the support condition `ker ρ' ≤ ker ρ` — which the +pinching always satisfies — gives `0 ≤ S(ρ') − S(ρ)`. Full N&C generality: no faithfulness +hypothesis on `ρ`. -/ +theorem Measurement.IsProjective.vonNeumannEntropy_unreadState_ge {m : Measurement ι S} + (h : m.IsProjective) (ρ : State S) : + ρ.vonNeumannEntropy ≤ (m.unreadState ρ).vonNeumannEntropy := by + have hP : ∀ i, IsStarProjection (m.op i) := h + have horth : ∀ i j, i ≠ j → m.op i * m.op j = 0 := fun _ _ hij => h.orthogonal hij + have hsum : ∑ i, m.op i = 1 := h.sum_op_eq_one + have hρ : ρ.op.IsDensityOp := ρ.isDensity + have hρ'D : (krausSumₗ m.op ρ.op).IsDensityOp := + isDensityOp_krausSumₗ_of_isStarProjection hP hsum hρ + have hsupp : HasSupportLE ρ.op (krausSumₗ m.op ρ.op) := + hasSupportLE_krausSumₗ_of_isStarProjection hP hsum hρ.isPositive + have hident := quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub hP horth hsum hρ + have hnonneg := hρ.quantumRelativeEntropy_nonneg_of_hasSupportLE hρ'D hsupp + rw [State.vonNeumannEntropy_def ρ, State.vonNeumannEntropy_def (m.unreadState ρ), + Measurement.unreadState_op] + rw [hident] at hnonneg + linarith + +/-- **Nielsen & Chuang Theorem 11.9, equality condition.** For a projective measurement `m` and any +state `ρ`, the unread post-measurement state `ρ' = Σᵢ Pᵢ ρ Pᵢ` (`m.unreadState ρ`) has the *same* +entropy as `ρ` if and only if the measurement leaves the state unchanged, + + `S(ρ') = S(ρ) ↔ ρ' = ρ`. + +Proof: by the entropy-increase identity `D(ρ ‖ ρ') = S(ρ') − S(ρ)`, `S(ρ') = S(ρ)` is equivalent to +`D(ρ ‖ ρ') = 0`, which by the equality case of the (non-faithful) Klein inequality holds iff +`ρ = ρ'`. -/ +theorem Measurement.IsProjective.vonNeumannEntropy_unreadState_eq_iff {m : Measurement ι S} + (h : m.IsProjective) (ρ : State S) : + (m.unreadState ρ).vonNeumannEntropy = ρ.vonNeumannEntropy ↔ m.unreadState ρ = ρ := by + have hP : ∀ i, IsStarProjection (m.op i) := h + have horth : ∀ i j, i ≠ j → m.op i * m.op j = 0 := fun _ _ hij => h.orthogonal hij + have hsum : ∑ i, m.op i = 1 := h.sum_op_eq_one + have hρ : ρ.op.IsDensityOp := ρ.isDensity + have hρ'D : (krausSumₗ m.op ρ.op).IsDensityOp := + isDensityOp_krausSumₗ_of_isStarProjection hP hsum hρ + have hsupp : HasSupportLE ρ.op (krausSumₗ m.op ρ.op) := + hasSupportLE_krausSumₗ_of_isStarProjection hP hsum hρ.isPositive + have hident := quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub hP horth hsum hρ + have hklein := hρ.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE hρ'D hsupp + rw [State.vonNeumannEntropy_def (m.unreadState ρ), State.vonNeumannEntropy_def ρ, + Measurement.unreadState_op] + constructor + · intro heq + have hD0 : ρ.op.quantumRelativeEntropy (krausSumₗ m.op ρ.op) = 0 := by rw [hident]; linarith + have hopeq := hklein.mp hD0 + apply State.ext + rw [Measurement.unreadState_op] + exact hopeq.symm + · intro heq + have hopeq : ρ.op = krausSumₗ m.op ρ.op := by rw [← Measurement.unreadState_op, heq] + have hD0 := hklein.mpr hopeq + rw [hident] at hD0 + linarith + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch11/TriangleInequality.lean b/LeanPool/AxQM/NC/Ch11/TriangleInequality.lean new file mode 100644 index 0000000000..8570b8cff6 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch11/TriangleInequality.lean @@ -0,0 +1,122 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch11.Subadditivity +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.Postulates.API.WeakMonotonicityReducedRight +public import LeanPool.AxQM.Postulates.API.ReducedStateLeftBlock +public import LeanPool.AxQM.Postulates.API.ReducedStateComm + +/-! +# Araki–Lieb triangle inequality for the von Neumann entropy (N&C §11.3.4, eq. (11.79)) + +Nielsen & Chuang, §11.3.4: for a bipartite state `ρ` on `A ⊗ B`, + +`|S(A) − S(B)| ≤ S(A, B)` (**triangle / Araki–Lieb inequality**, eq. (11.79)), + +the lower companion of subadditivity `S(A,B) ≤ S(A) + S(B)` +(`State.vonNeumannEntropy_le_reducedLeft_add_reducedRight`). Both directions of the absolute value +are supplied here as separate inequalities: + +* `State.vonNeumannEntropy_reducedLeft_sub_reducedRight_le` — `S(A) − S(B) ≤ S(A,B)`; +* `State.vonNeumannEntropy_reducedRight_sub_reducedLeft_le` — `S(B) − S(A) ≤ S(A,B)`. + +## Proof + +N&C's argument (p. 516): purify `ρ` by a reference `R` into a pure state `Θ` on `(A ⊗ B) ⊗ R` +(`State.purify`, whose left marginal is `ρ`). Then + +* `S(ρ) = S(R)` because `Θ` is pure on `(A ⊗ B) ⊗ R` + (`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`, N&C Theorem 11.8(3): complementary + marginals of a pure state are isentropic); +* re-associating `Θ` to `A ⊗ (B ⊗ R)` it is pure on the bipartition `A | (B ⊗ R)`, so + `S(A) = S(B, R)` by the same complementarity; +* subadditivity on the `B ⊗ R` marginal gives `S(B, R) ≤ S(B) + S(R) = S(B) + S(ρ)`. + +Chaining these yields `S(A) − S(B) ≤ S(ρ)`, the first inequality. The second is obtained by +applying the first to the swapped state `ρ.congr (comm A B)` on `B ⊗ A`, under which the two +marginals exchange roles and the joint entropy is unchanged. + +## Ingredients + +The proofs use the faithfulness-free subadditivity of `AxQM/NC/Ch11/Subadditivity.lean`; the +purifying reference `R` appears only in proof bodies, never in a statement. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {A B : QSystem} + +/-- **Araki–Lieb triangle inequality, first direction** (Nielsen & Chuang, §11.3.4, eq. (11.79)): +for a bipartite state `ρ` on `A ⊗ B`, + +`S(A) − S(B) ≤ S(A, B)`. + +Purify `ρ` by a reference `R` (`State.purify`, left marginal `ρ`); the purification `Θ` on +`(A ⊗ B) ⊗ R` is pure, so `S(ρ) = S(R)`. Re-associating `Θ` to `A ⊗ (B ⊗ R)` it is pure on the +bipartition `A | (B ⊗ R)`, whence `S(A) = S(B, R)` by pure-state complementarity +(`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`); subadditivity of the `B ⊗ R` marginal +(`State.vonNeumannEntropy_le_reducedLeft_add_reducedRight`) gives `S(B, R) ≤ S(B) + S(R) = S(B) + +S(ρ)`. The three marginal identifications use the associator reshaping lemmas +`State.reducedLeft_congr_assoc_symm`, `State.reducedRight_reducedLeft_congr_assoc_symm`, +`State.reducedRight_reducedRight_congr_assoc_symm`. -/ +theorem State.vonNeumannEntropy_reducedLeft_sub_reducedRight_le (ρ : State (A.compose B)) : + ρ.reducedLeft.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy ≤ ρ.vonNeumannEntropy := by + -- purification `Θ` on `(A ⊗ B) ⊗ R`, left marginal `ρ` + have hΘL : ρ.purify.toState.reducedLeft = ρ := State.purify_reducedLeft_eq ρ + -- `S(ρ) = S(R)` by pure-state complementarity + have hSρ : ρ.vonNeumannEntropy = ρ.purify.toState.reducedRight.vonNeumannEntropy := by + have hpc := PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight ρ.purify + rw [hΘL] at hpc + exact hpc + -- the re-associated pure state `Θ' = Θ.congr (assoc A B R).symm` on `A ⊗ (B ⊗ R)` + set Θ' : State (A.compose (B.compose _)) := + (PureState.congr (A.assoc B _).symm ρ.purify).toState with hΘ' + -- `S(A) = S(B, R)` by pure-state complementarity on the bipartition `A | (B ⊗ R)` + have hcompl : Θ'.reducedLeft.vonNeumannEntropy = Θ'.reducedRight.vonNeumannEntropy := by + rw [hΘ']; exact PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight _ + -- identify the marginals of `Θ'`: left is `ρ_A`, right's left is `ρ_B`, right's right is `R` + have hΘ'L : Θ'.reducedLeft = ρ.reducedLeft := by + rw [hΘ', PureState.congr_toState, State.reducedLeft_congr_assoc_symm, hΘL] + have hΘ'RL : Θ'.reducedRight.reducedLeft = ρ.reducedRight := by + rw [hΘ', PureState.congr_toState, State.reducedRight_reducedLeft_congr_assoc_symm, hΘL] + have hΘ'RR : Θ'.reducedRight.reducedRight = ρ.purify.toState.reducedRight := by + rw [hΘ', PureState.congr_toState, State.reducedRight_reducedRight_congr_assoc_symm] + -- subadditivity on the `B ⊗ R` marginal `Θ'_right` + have hsub := State.vonNeumannEntropy_le_reducedLeft_add_reducedRight Θ'.reducedRight + rw [hΘ'RL, hΘ'RR] at hsub + rw [hΘ'L] at hcompl + -- `S(A) = S(Θ'_right) ≤ S(B) + S(R) = S(B) + S(ρ)` + linarith [hcompl, hsub, hSρ] + +/-- **Araki–Lieb triangle inequality, second direction** (Nielsen & Chuang, §11.3.4, eq. (11.79)): +for a bipartite state `ρ` on `A ⊗ B`, + +`S(B) − S(A) ≤ S(A, B)`. + +Obtained from the first direction `State.vonNeumannEntropy_reducedLeft_sub_reducedRight_le` applied +to the swapped state `ρ.congr (QSystem.Iso.comm A B)` on `B ⊗ A`: the swap exchanges the two +marginals (`State.reducedLeft_congr_comm`, `State.reducedRight_congr_comm`) and preserves the joint +entropy (`State.vonNeumannEntropy_congr`). Together with subadditivity this is the quantum triangle +inequality `|S(A) − S(B)| ≤ S(A, B)`. -/ +theorem State.vonNeumannEntropy_reducedRight_sub_reducedLeft_le (ρ : State (A.compose B)) : + ρ.reducedRight.vonNeumannEntropy - ρ.reducedLeft.vonNeumannEntropy ≤ ρ.vonNeumannEntropy := by + have h := State.vonNeumannEntropy_reducedLeft_sub_reducedRight_le + (State.congr (QSystem.Iso.comm A B) ρ) + rw [← State.reducedRight_congr_comm, ← State.reducedLeft_congr_comm, + State.vonNeumannEntropy_congr] at h + exact h + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/CoherentInformation.lean b/LeanPool/AxQM/NC/Ch12/CoherentInformation.lean new file mode 100644 index 0000000000..4b7c18f24e --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/CoherentInformation.lean @@ -0,0 +1,222 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch11.Theorem15 +public import LeanPool.AxQM.NC.Ch11.TriangleInequality +public import LeanPool.AxQM.NC.Ch12.Problem1 +public import LeanPool.AxQM.Core.ConditionalEntropy +public import LeanPool.AxQM.Postulates.API.ReferencePurification +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport + +/-! +# Entropy exchange and coherent information (N&C §12.4.1–12.4.2) + +Definitions and lemmas for the quantum data processing inequality (N&C Theorem 12.10). Following +Nielsen & Chuang §12.4.1–12.4.2, a trace-preserving quantum operation `E` on a system `Q` is +presented by its Chapter-8 dilation — a unitary `U` on `Q ⊗ C` with the environment `C` prepared in +a pure state `ω`, so that `E(ρ) = Tr_C(U(ρ ⊗ |ω⟩⟨ω|)U†) = ρ.dilatedChannel U ω`. + +## The `R'Q'` state and its marginals + +Introduce a reference `R` and purify `ρ` into `|RQ⟩ = State.refPurify ρ` (reference on the left, +`State.refPurify`). Applying `E` to the system factor gives the state +`R'Q' = (refPurify ρ).dilatedChannelOnRight U ω` on `R ⊗ Q`. The two entropy-exchange definitions +rest on how tracing out one factor of a **channel acting on the right** behaves — proved here for a +*general* bipartite state, so the lemmas are reusable: + +* `State.reducedLeft_dilatedChannelOnRight` — the left (untouched) marginal is unchanged, + `Tr_B((id ⊗ E) ρ) = Tr_B ρ`; +* `State.reducedRight_dilatedChannelOnRight` — the right marginal is the channel applied to the + right marginal, `Tr_A((id ⊗ E) ρ) = E(Tr_A ρ)`. + +## The quantities (N&C eq. (12.107)/(12.118)) + +* `State.entropyExchange ρ U ω := S(R'Q')` — the **entropy exchange** `S(ρ, E)`, N&C's purification + formulation `S(ρ, E) = S(R', Q')` (§12.4.1). This is the purification-side companion + of Theorem 12.9's w-matrix quantity `ContinuousLinearMap.entropyExchange` + (`S(ρ, E) = S(W)`); the two agree but this one exposes the `R'Q'` bipartite structure that the + data processing inequality needs. +* `State.coherentInfo ρ U ω := S(E(ρ)) − S(ρ, E)` — the **coherent information** `I(ρ, E)` + (eq. (12.118)). + +## The purification reference + +The purification reference is `State.refPurify` (in `AxQM/Postulates/API/`); it appears here only in +proof bodies, never in a statement. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C Q : QSystem} + +/-- **A quantum operation on the right factor leaves the left marginal unchanged.** For a bipartite +state `ρ` on `A ⊗ B` and a channel `E` on `B` presented by its dilation `(U, ω)`, tracing out `B` +from `(id_A ⊗ E) ρ = ρ.dilatedChannelOnRight U ω` gives the same `A`-marginal as tracing out `B` +from `ρ`: `Tr_B((id_A ⊗ E) ρ) = Tr_B ρ`. Read off the dilation by pushing `reducedLeft` through the +associator reshapes (`State.reducedLeft_reducedLeft_congr_assoc`, +`State.reducedLeft_congr_assoc_symm`), the local unitary `id ⊗ U` +(`State.reducedLeft_evolve_id_tmul`), and the pure ancilla (`State.reducedLeft_tmul`). -/ +theorem State.reducedLeft_dilatedChannelOnRight (ρ : State (A ⊗ B)) (U : Evolution (B ⊗ C)) + (ω : PureState C) : (ρ.dilatedChannelOnRight U ω).reducedLeft = ρ.reducedLeft := by + unfold State.dilatedChannelOnRight + rw [State.reducedLeft_reducedLeft_congr_assoc, State.reducedLeft_evolve_id_tmul, + State.reducedLeft_congr_assoc_symm, State.reducedLeft_tmul] + +/-- **A quantum operation on the right factor acts on the right marginal.** For a bipartite state +`ρ` on `A ⊗ B` and a channel `E` on `B` presented by its dilation `(U, ω)`, tracing out `A` from +`(id_A ⊗ E) ρ = ρ.dilatedChannelOnRight U ω` gives `E` applied to the `B`-marginal of `ρ`: +`Tr_A((id_A ⊗ E) ρ) = E(Tr_A ρ) = (Tr_A ρ).dilatedChannel U ω`. This is the compatibility of the +partial trace with a local channel; read off the dilation by pushing `reducedRight` through the +associator reshape (`State.reducedRight_reducedLeft_congr_assoc`), the local unitary `id ⊗ U` +(`State.reducedRight_evolve_id_tmul`), and the ancilla adjunction +(`State.reducedRight_congr_symm_assoc_tmul`), landing on the single-system dilation +`State.dilatedChannel`. -/ +theorem State.reducedRight_dilatedChannelOnRight (ρ : State (A ⊗ B)) (U : Evolution (B ⊗ C)) + (ω : PureState C) : + (ρ.dilatedChannelOnRight U ω).reducedRight = ρ.reducedRight.dilatedChannel U ω := by + unfold State.dilatedChannelOnRight State.dilatedChannel + rw [State.reducedRight_reducedLeft_congr_assoc, State.reducedRight_evolve_id_tmul, + State.reducedRight_congr_symm_assoc_tmul] + +/-- **Entropy exchange** `S(ρ, E)` of a quantum operation `E` on `Q`, presented by its dilation +`(U, ω)` (Nielsen & Chuang §12.4.1, eq. (12.107)). Purify `ρ` into `R'Q' = R ⊗ Q` via +`State.refPurify` and apply `E` to the system factor; the entropy exchange is the von Neumann +entropy of the resulting joint state, `S(ρ, E) = S(R', Q')`. Equivalently (Theorem 12.9) this is +`S(W)` for the w-matrix `W_{ij} = tr(Eᵢ ρ Eⱼ†)`; the purification form is used here because the data +processing inequality argument reasons about the `R'Q'` bipartition directly. -/ +def State.entropyExchange (ρ : State Q) (U : Evolution (Q ⊗ C)) (ω : PureState C) : ℝ := + ((State.refPurify ρ).toState.dilatedChannelOnRight U ω).vonNeumannEntropy + +/-- **Coherent information** `I(ρ, E)` of a quantum operation `E` on `Q`, presented by its dilation +`(U, ω)` (Nielsen & Chuang §12.4.2, eq. (12.118)): + +`I(ρ, E) = S(E(ρ)) − S(ρ, E)`, + +the entropy of the output state `E(ρ) = ρ.dilatedChannel U ω` minus the entropy exchange +`State.entropyExchange`. It plays, in the quantum data processing inequality (Theorem 12.10), the +role the mutual information `H(X:Y)` plays classically. -/ +def State.coherentInfo (ρ : State Q) (U : Evolution (Q ⊗ C)) (ω : PureState C) : ℝ := + (ρ.dilatedChannel U ω).vonNeumannEntropy - ρ.entropyExchange U ω + +/-- **First inequality of the quantum data processing inequality** (Nielsen & Chuang Theorem 12.10, +eq. (12.119), first stage): the coherent information never exceeds the input entropy, + +`I(ρ, E) ≤ S(ρ)`. + +This is N&C's argument (12.122)–(12.126) cast in the purification picture. Writing +`σ = R'Q' = (refPurify ρ).dilatedChannelOnRight U ω` for the reference–system state after `E`, the +coherent information is `I(ρ, E) = S(Q') − S(R', Q')` since the output marginal is `E(ρ)` +(`State.reducedRight_dilatedChannelOnRight` + `State.refPurify_reducedRight`) and the joint entropy +is the entropy exchange (`State.entropyExchange`). The Araki–Lieb triangle inequality +`S(Q') − S(R') ≤ S(R', Q')` (`State.vonNeumannEntropy_reducedRight_sub_reducedLeft_le`, N&C +eq. (11.79)) then bounds it by `S(R')`, and the reference marginal is isentropic with the input, +`S(R') = S(ρ)` (the channel leaves the `R`-marginal untouched, +`State.reducedLeft_dilatedChannelOnRight`, and `R` is a purifying reference, +`State.vonNeumannEntropy_refPurify_reducedLeft`). N&C note equality holds iff `E` is perfectly +reversible on `ρ` (Exercise 12.16). -/ +theorem State.coherentInfo_le_vonNeumannEntropy (ρ : State Q) (U : Evolution (Q ⊗ C)) + (ω : PureState C) : ρ.coherentInfo U ω ≤ ρ.vonNeumannEntropy := by + have hAL := State.vonNeumannEntropy_reducedRight_sub_reducedLeft_le + ((State.refPurify ρ).toState.dilatedChannelOnRight U ω) + rw [State.reducedRight_dilatedChannelOnRight, State.refPurify_reducedRight, + State.reducedLeft_dilatedChannelOnRight, State.vonNeumannEntropy_refPurify_reducedLeft] at hAL + unfold State.coherentInfo State.entropyExchange + linarith + +/-! +## The data processing inequality (second stage): `I(ρ, E1) ≥ I(ρ, E2 ∘ E1)` + +The second inequality of N&C Theorem 12.10 is the *quantum data processing inequality* proper. N&C +prove it (eqs (12.122)–(12.131)) with a four-system construction `R Q E1 E2` and the **strong +subadditivity** inequality. We recast that argument in the purification picture already set up for +the first inequality, so that the whole second stage becomes a monotonicity statement about the +**state coherent information** `I(A⟩B) = S(B) − S(A,B)` (`State.coherentInfoOfState`, the negative +conditional entropy, `AxQM/Core/ConditionalEntropy.lean`) under a channel acting on the `B` +factor. That monotonicity is a corollary: via the bridge `I(A⟩B) = S(A:B) − S(A)` +(`State.coherentInfoOfState_eq_vonNeumannMutualInfo_sub_reducedLeft`) and the channel-invariance of +the reference marginal `S(A)` (`State.reducedLeft_dilatedChannelOnRight`), it follows +from the mutual-information monotonicity +`State.vonNeumannMutualInfo_dilatedChannelOnRight_le` (N&C Theorem 11.15(3), which itself packages +N&C's SSA-discard / local-unitary / product-ancilla argument). + +The key observations: + +* The channel coherent information `I(ρ, E)` is the state quantity on the processed purification: + it is `I(R'⟩Q')` for `R'Q' = (refPurify ρ).dilatedChannelOnRight U ω` (derived in the proof of + `State.coherentInfoComp_le_coherentInfo`; cf. `State.entropyExchange`, which likewise uses + `refPurify` only in its body). +* Applying `E2` to the system factor of `R'Q'` produces `R''Q''`, whose output marginal is + `E2(E1(ρ)) = (E2 ∘ E1)(ρ)` (each right-factor dilation commutes with tracing out the reference, + `State.reducedRight_dilatedChannelOnRight`, and the reference marginal of the purification is `ρ`, + `State.refPurify_reducedRight`) and whose joint entropy is the entropy exchange `S(ρ, E2 ∘ E1)` + (the purification formulation, N&C eq. (12.130) read through the purity of the global + `R''Q''E1''E2''` state). Hence `I(R''⟩Q'') = S((E2 ∘ E1)(ρ)) − S(ρ, E2 ∘ E1) = I(ρ, E2 ∘ E1)`, + captured by the definition `State.coherentInfoComp`. +* `State.coherentInfoOfState_dilatedChannelOnRight_le` is the monotonicity `I(A'⟩B') ≤ I(A⟩B)` under + a channel on `B`; instantiated at `σ = R'Q'` it is exactly `I(ρ, E2 ∘ E1) ≤ I(ρ, E1)`. + +This route sidesteps composing the two dilations into a single environment `Q ⊗ (C1 ⊗ C2)`: +sequential application on the right factor already realises `E2 ∘ E1` faithfully, and the +purification definition of the entropy exchange makes `S(ρ, E2 ∘ E1) = S(R''Q'')` +hold by construction. +-/ + +/-- **The state coherent information is non-increasing under a channel on the system factor** — the +state-level quantum data processing inequality. For a bipartite state `σ` on `A ⊗ B` and a +trace-preserving quantum operation `E` on `B`, presented by its Chapter-8 dilation (a unitary `U` on +`B ⊗ C` with the ancilla `C` in a pure state `ω`), + +`I(A ⟩ E(B)) ≤ I(A⟩B)`, + +where the processed state is `(id_A ⊗ E) σ = σ.dilatedChannelOnRight U ω`. This is a direct +corollary of the mutual-information monotonicity +`State.vonNeumannMutualInfo_dilatedChannelOnRight_le` (N&C Theorem 11.15(3), which packages +N&C's SSA-discard / local-unitary / product-ancilla dilation argument): via the bridge +`I(A⟩B) = S(A:B) − S(A)` (`State.coherentInfoOfState_eq_vonNeumannMutualInfo_sub_reducedLeft`), the +two coherent informations differ from their mutual informations by the *same* reference marginal +entropy `S(A)`, which the channel on `B` leaves untouched +(`State.reducedLeft_dilatedChannelOnRight`, `Tr_A((id_A ⊗ E) σ) = Tr_A σ`); so the +coherent-information inequality is the mutual-information one shifted by that common constant. -/ +theorem State.coherentInfoOfState_dilatedChannelOnRight_le (σ : State (A ⊗ B)) + (U : Evolution (B ⊗ C)) (ω : PureState C) : + (σ.dilatedChannelOnRight U ω).coherentInfoOfState ≤ σ.coherentInfoOfState := by + have hmi := σ.vonNeumannMutualInfo_dilatedChannelOnRight_le U ω + rw [State.coherentInfoOfState_eq_vonNeumannMutualInfo_sub_reducedLeft, + State.coherentInfoOfState_eq_vonNeumannMutualInfo_sub_reducedLeft, + State.reducedLeft_dilatedChannelOnRight] + linarith + +/-- **Coherent information of the two-stage composed operation** `I(ρ, E2 ∘ E1)` (Nielsen & Chuang +Theorem 12.10). The composed channel `E2 ∘ E1` — first `E1` (dilation `(U₁, ω₁)` on `Q ⊗ C₁`), then +`E2` (dilation `(U₂, ω₂)` on `Q ⊗ C₂`) — is realised faithfully by applying the two dilations in +sequence to the system factor of the reference purification of `ρ`, giving the reference–system +state `R''Q''`. The composed coherent information is the state coherent information of `R''Q''`: + +`I(ρ, E2 ∘ E1) = I(R''⟩Q'') = S((E2 ∘ E1)(ρ)) − S(ρ, E2 ∘ E1)`. + +The output marginal of `R''Q''` is `(E2 ∘ E1)(ρ)` (each right-factor dilation commutes with tracing +out the reference, `State.reducedRight_dilatedChannelOnRight`, and the reference marginal of the +purification is `ρ`, `State.refPurify_reducedRight`), and its joint entropy `S(R''Q'')` is the +entropy exchange `S(ρ, E2 ∘ E1)` — the purification formulation of N&C eq. (12.130), matching the +single-channel `State.entropyExchange`. Presenting the composition as sequential right-factor +dilations, rather than as one dilation on a combined environment `Q ⊗ (C₁ ⊗ C₂)`, avoids reshaping +across the joint environment while remaining faithful to N&C. -/ +def State.coherentInfoComp (ρ : State Q) (U₁ : Evolution (Q ⊗ C)) (ω₁ : PureState C) {D : QSystem} + (U₂ : Evolution (Q ⊗ D)) (ω₂ : PureState D) : ℝ := + (((State.refPurify ρ).toState.dilatedChannelOnRight U₁ ω₁).dilatedChannelOnRight U₂ + ω₂).coherentInfoOfState + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Problem1.lean b/LeanPool/AxQM/NC/Ch12/Problem1.lean new file mode 100644 index 0000000000..facbeb2f2c --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Problem1.lean @@ -0,0 +1,375 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.HolevoChi +public import LeanPool.AxQM.Core.MeasurementChannel +public import LeanPool.AxQM.NC.Ch11.Theorem15 +public import LeanPool.AxQM.Postulates.API.PartialTraceReassoc +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementMarginal +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementDilation +public import LeanPool.AxQM.Postulates.API.QuditMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy + +/-! +# N&C Problem 12.1 — an alternate proof of the Holevo bound + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Problem 12.1, p. 602. + +The problem develops an alternate proof of the Holevo bound built entirely on the **monotonicity of +the Holevo χ quantity** `χ = S(ρ) − ∑ₓ pₓ S(ρₓ)` (eq. (12.208)). It has three parts: + +1. **`χ_A ≤ χ_AB`** — for an ensemble of states on a bipartite system `A ⊗ B`, the χ of the + `A`-marginal ensemble is at most the χ of the joint ensemble (χ cannot increase when a subsystem + is traced out). N&C's hint is to introduce an index system correlated with the ensemble and apply + strong subadditivity. +2. **`χ′ ≤ χ`** — the Holevo χ decreases under any quantum operation `E`. +3. The **apparatus construction**: for a POVM `{Eᵧ}` and an apparatus register `M`, the operation + `E(ρ ⊗ |0⟩⟨0|) = ∑ᵧ √Eᵧ ρ √Eᵧ ⊗ |y⟩⟨y|` produces `χ_M = H(X : Y)`; combined with parts (1)–(2) + this yields the Holevo bound `H(X : Y) ≤ S(ρ) − ∑ₓ pₓ S(ρₓ)` (eq. (12.212)). + +The engine, supplied by `Core/HolevoChi.lean`, is that **χ is the quantum mutual +information of the classical–quantum state** `∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ` +(`State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState`). Under that identification each +χ-monotonicity statement becomes a mutual-information monotonicity already proved in +`NC/Ch11/Theorem15.lean`. + +## This file (Parts 1–3 and the assembled Holevo bound) + +`State.holevoChi_reducedLeft_le` is **Part (1)**, `χ_A ≤ χ_AB` (eq. (12.209)). Its proof is exactly +N&C's hint made precise: + +* the "index system correlated with `AB`" is the classical register `P` of the cq-state + `holevoCQState`, so `χ_AB = S(P : A,B)` and `χ_A = S(P : A)` by the χ ↔ mutual-information bridge; +* discarding the subsystem `B` sends the tripartite cq-state on `P ⊗ (A ⊗ B)` to the bipartite + cq-state on `P ⊗ A` of the `A`-marginal ensemble — this is the marginal-consistency lemma + `State.holevoCQState_congr_assoc_reducedLeft`; +* strong subadditivity, in the form "discarding never increases mutual information" + (`State.vonNeumannMutualInfo_le_of_discard'`, N&C Theorem 11.15(2), faithfulness-free so it + applies to the rank-deficient cq-state), gives `S(P : A) ≤ S(P : A,B)`, i.e. `χ_A ≤ χ_AB`. + +`State.holevoChi_dilatedChannel_le` is **Part (2)**, `χ′ ≤ χ` (eq. (12.210)): the Holevo χ of the +image ensemble `{pᵢ, E(ρᵢ)}` under a quantum operation `E` is at most the χ of `{pᵢ, ρᵢ}`. Following +N&C's own three-step argument (append the environment, evolve unitarily, discard it), the operation +is presented by its Chapter-8 **dilation** — `State.dilatedChannel ρ U ω = Tr_C (U (ρ ⊗ |ω⟩⟨ω|) U†)` +for a unitary `U` on `S ⊗ C` and a pure ancilla `ω` — exactly as N&C's Theorem 11.15(3) presents the +channel it feeds on (a general trace-preserving `E` has no Kraus/dilation form to quantify over in +the library's API). The three steps are each a χ-monotonicity/invariance already in the library: + +* **discard the environment** `C`: `χ(E∘ρ) = χ_S ≤ χ_{S,C} = χ(U(ρ ⊗ ω)U†)` is Part (1) + `State.holevoChi_reducedLeft_le` (`E(ρᵢ)` is the `S`-marginal `Tr_C` of `U(ρᵢ ⊗ ω)U†`); +* **the unitary interaction** leaves χ invariant, `χ(U(ρ ⊗ ω)U†) = χ(ρ ⊗ ω)` + (`State.holevoChi_evolve`, from unitary invariance of the von Neumann entropy); +* **appending the pure environment** leaves χ invariant, `χ(ρ ⊗ ω) = χ(ρ)` + (`State.holevoChi_tmul_pure_right`, since a pure ancilla adds `S(ω) = 0` entropy). + +Chaining the three gives `χ(E∘ρ) ≤ χ(ρ)`. (This route reuses Part (1) +rather than the dilated-channel mutual-information bound +`vonNeumannMutualInfo_dilatedChannelOnRight_le` directly: it needs only the two clean +χ-invariance lemmas above plus Part (1), all already available.) + +`State.holevoChi_measState_eq_mutualInfo` is **Part (3)**, the apparatus identity `χ_M = H(X:Y)` +(which N&C states with no equation number): Alice prepares `ρₓ` with probability `pₓ` (random +variable `X`) and Bob measures with a POVM `m` (outcome `Y`). N&C's apparatus operation +`E(ρ ⊗ |0⟩⟨0|) = ∑ᵧ √Eᵧ ρ √Eᵧ ⊗ |y⟩⟨y|` (eq. (12.211)) leaves the apparatus register `M` in the +marginal `Tr_S E(ρₓ ⊗ |0⟩⟨0|) = ∑ᵧ Tr(Eᵧ ρₓ) |y⟩⟨y|`, which +is exactly the measure-and-record outcome channel `m.measState ρₓ` (`Measurement.measState`, from +`Core/MeasurementChannel.lean`) — so the χ of the ensemble `{pₓ, m.measState ρₓ}` is stated +directly over `measState`, without reconstructing `E`. It equals the classical mutual information of +the joint distribution `p(x, y) = pₓ · Tr(Eᵧ ρₓ)`: + +* each apparatus state is diagonal in the outcome basis, so its von Neumann entropy is the Shannon + entropy of its Born distribution (`Measurement.vonNeumannEntropy_measState`); hence + `χ_M = H(Y) − ∑ₓ pₓ H(Y | X = x)`; +* the χ-mixture is the outcome channel of the average state + (`Measurement.measState_mix`), whose Born distribution is the average of the component + distributions (`Measurement.bornProb_mix`); +* the classical conditional-joint identity `Real.mutualInfo_prod_conditional` + (`H(X:Y) = H(Y) − H(Y|X)` for a joint `pₓ · q x y`) identifies `χ_M` with `H(X:Y)`. + +The Holevo χ ↔ classical-mutual-information transcription mirrors, on the outcome register, +the bridge `State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState` that drives Parts (1)–(2). + +`State.holevoChi_measState_le` composes Parts (1)–(3) into the χ-monotonicity heart of the bound, +`χ(fun x => m.measState ρₓ) ≤ χ(ρ)` (Holevo χ decreases under a measurement). It reruns N&C's +apparatus argument on `𝓔` (`holevoMeasurementChannel`, Exercise 12.2): apply `𝓔` to `ρₓ ⊗ |0⟩`, +whose apparatus `M`-marginal `Tr_Q 𝓔(ρₓ ⊗ |0⟩⟨0|)` is the diagonal Born state +`holevoMeasurementChannel_reducedRight` — i.e. `m.measState ρₓ` up to the register reindexing +`quditFinCardIso` (`qudit r ≃ₛ qudit (Fintype.card (Fin r))`, since `measState` records in +`qudit (Fintype.card (Fin r))` but `𝓔` in `qudit r`); then discard `Q` (Part (1), `reducedRight` +form), invoke that `𝓔` is a dilation (`holevoMeasurementChannel_eq_reducedLeft_evolve`) and apply +Part (2), and strip the reset apparatus (`State.holevoChi_tmul_pure_right`). + +`holevoBound_of_chi_monotone` is the **headline Holevo bound** `H(X:Y) ≤ S(ρ) − ∑ₓ pₓ S(ρₓ)` +(eq. (12.212)): Part (3) `State.holevoChi_measState_eq_mutualInfo` rewrites `H(X:Y)` as +`χ(fun x => m.measState ρₓ)`, which `State.holevoChi_measState_le` bounds by `χ(ρ) = S(ρ) − ∑ₓ pₓ +S(ρₓ)`. This is N&C's alternate route — χ monotonicity throughout, in place of the direct +relative-entropy / data-processing argument of Theorem 12.1. + +## Dependencies + +Part (1) uses the discard bound `State.vonNeumannMutualInfo_le_of_discard'` +(`AxQM/NC/Ch11/Theorem15.lean`), and Part (2) uses Part (1). The proof of the assembled bound +`holevoBound_of_chi_monotone` also uses the register-reindexing isomorphism `quditFinCardIso` and +the measurement apparatus `holevoMeasurementChannel` with its marginal and dilation bridges, both +in `AxQM/Postulates/API/`. -/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {A B : QSystem} {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State (A ⊗ B)) + +/-- **Discarding a subsystem sends the joint cq-state to the marginal cq-state.** For an ensemble +`{pᵢ, ρᵢ}` of states on `A ⊗ B`, re-associating the classical–quantum state +`∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ` on `P ⊗ (A ⊗ B)` to `(P ⊗ A) ⊗ B` and tracing out `B` yields the +classical–quantum state `∑ᵢ pᵢ |i⟩⟨i| ⊗ (ρᵢ)_A` of the `A`-marginal ensemble `{pᵢ, (ρᵢ)_A}`: + +`Tr_B (assoc (holevoCQState p ρ)) = holevoCQState p (fun i => (ρ i)_A)`. + +Both `State.congr`/`State.reducedLeft` are linear on mixtures (`State.congr_mix`, +`State.reducedLeft_mix`), reducing the claim to the per-component middle-marginal fact +`State.reducedLeft_congr_assoc_tmul`: the classical ket `|i⟩⟨i|` passes through the trace untouched +while `B` is traced off `ρᵢ`, leaving `|i⟩⟨i| ⊗ (ρᵢ)_A`. This is the structural heart of N&C's hint +(the "extra system correlated with `AB`" is the classical register `P`). -/ +theorem State.holevoCQState_congr_assoc_reducedLeft : + (State.congr (QSystem.assoc (qudit (Fintype.card ι)) A B) + (State.holevoCQState p hp hsum ρ)).reducedLeft = + State.holevoCQState p hp hsum (fun i => (ρ i).reducedLeft) := by + unfold State.holevoCQState + simp only [State.congr_mix, State.reducedLeft_mix, State.reducedLeft_congr_assoc_tmul] + +/-- **N&C Problem 12.1(1): the Holevo χ quantity decreases under tracing out a subsystem** +(eq. (12.209)). For an ensemble `{pᵢ, ρᵢ}` of states on a bipartite system `A ⊗ B`, + +`χ_A ≤ χ_AB`, + +where `χ_A` is the Holevo χ of the `A`-marginal ensemble `{pᵢ, (ρᵢ)_A}` and `χ_AB` is the Holevo χ +of the joint ensemble `{pᵢ, ρᵢ}`. + +The proof is N&C's hint made precise. By the χ ↔ mutual-information bridge +`State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState`, `χ_AB = S(P : A,B)` for the +classical–quantum state on `P ⊗ (A ⊗ B)`, and `χ_A = S(P : A)` for its `A`-marginal cq-state, which +`State.holevoCQState_congr_assoc_reducedLeft` identifies with the discarded marginal. Strong +subadditivity in the form "discarding never increases mutual information" +(`State.vonNeumannMutualInfo_le_of_discard'`, N&C Theorem 11.15(2)) then gives +`S(P : A) ≤ S(P : A,B)`. -/ +theorem State.holevoChi_reducedLeft_le : + State.holevoChi p hp hsum (fun i => (ρ i).reducedLeft) ≤ State.holevoChi p hp hsum ρ := by + rw [← State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState p hp hsum + (fun i => (ρ i).reducedLeft), + ← State.holevoChi_eq_vonNeumannMutualInfo_holevoCQState p hp hsum ρ, + ← State.holevoCQState_congr_assoc_reducedLeft p hp hsum ρ] + exact State.vonNeumannMutualInfo_le_of_discard' (State.holevoCQState p hp hsum ρ) + +/-- **The Holevo χ quantity decreases under tracing out the *left* subsystem**: the mirror of +Part (1) `State.holevoChi_reducedLeft_le` for the other factor. For an ensemble `{pᵢ, ρᵢ}` of states +on `A ⊗ B`, + +`χ_B ≤ χ_AB`, + +where `χ_B` is the Holevo χ of the `B`-marginal ensemble `{pᵢ, (ρᵢ)_B}` (`State.reducedRight`, which +traces out the *left* factor `A`). The apparatus step of the alternate Holevo-bound proof discards +the *measured system* `S` and keeps the *apparatus* register `M`, i.e. traces out the left factor; +this lemma supplies that direction. It reduces to Part (1) by the swap isomorphism: tracing out the +left factor is tracing out the right factor of the swapped state +(`State.reducedRight_congr_comm`), and χ is invariant under the swap transport +(`State.holevoChi_congr`). -/ +theorem State.holevoChi_reducedRight_le : + State.holevoChi p hp hsum (fun i => (ρ i).reducedRight) ≤ State.holevoChi p hp hsum ρ := + calc State.holevoChi p hp hsum (fun i => (ρ i).reducedRight) + = State.holevoChi p hp hsum + (fun i => (State.congr (QSystem.Iso.comm A B) (ρ i)).reducedLeft) := by + simp only [State.reducedRight_congr_comm] + _ ≤ State.holevoChi p hp hsum (fun i => State.congr (QSystem.Iso.comm A B) (ρ i)) := + State.holevoChi_reducedLeft_le p hp hsum + (fun i => State.congr (QSystem.Iso.comm A B) (ρ i)) + _ = State.holevoChi p hp hsum ρ := + State.holevoChi_congr p hp hsum ρ (QSystem.Iso.comm A B) + +/-- **The output of a dilated quantum operation on a single system.** For a state `ρ` on `S`, a +unitary `U` on `S ⊗ C`, and an environment `C` prepared in the pure state `ω`, this is Nielsen & +Chuang's Chapter-8 dilation `E(ρ) = Tr_C (U (ρ ⊗ |ω⟩⟨ω|) U†)` of a trace-preserving quantum +operation `E` on `S`: adjoin the pure ancilla (`ρ ⊗ |ω⟩⟨ω|`), evolve by `U`, then discard `C` +(trace out the right factor). Every trace-preserving quantum operation on `S` arises this way (the +environment/Stinespring representation, N&C §8.2.3). This is the single-system counterpart of +`State.dilatedChannelOnRight` (which dilates a channel acting on the right factor of a bipartite +state); presenting `E` by its dilation, rather than as an abstract trace-preserving map, is forced +by the library's API (no general Kraus/dilation-form theorem to quantify over) and matches N&C's own +argument. -/ +noncomputable def State.dilatedChannel {S C : QSystem} (ρ : State S) (U : Evolution (S ⊗ C)) + (ω : PureState C) : State S := + (U.evolve (ρ.tmul ω.toState)).reducedLeft + +/-- **N&C Problem 12.1(2): the Holevo χ quantity decreases under a quantum operation** +(eq. (12.210)). +For an ensemble `{pᵢ, ρᵢ}` of states on `S` and a trace-preserving quantum operation `E` on `S`, +presented by its Chapter-8 dilation (a unitary `U` on `S ⊗ C` with the environment `C` in a pure +state `ω`), + +`χ′ = χ(E∘ρ) ≤ χ = χ(ρ)`, + +where `χ(E∘ρ)` is the Holevo χ of the image ensemble `{pᵢ, E(ρᵢ)}`. + +The proof is N&C's own argument (p. 601), reusing Part (1): `E(ρᵢ) = Tr_C (U (ρᵢ ⊗ ω) U†)` is the +`S`-marginal of `U (ρᵢ ⊗ ω) U†`, so discarding the environment gives +`χ(E∘ρ) ≤ χ(U(ρ ⊗ ω)U†)` by Part (1) `State.holevoChi_reducedLeft_le`; the unitary interaction +leaves χ invariant, `χ(U(ρ ⊗ ω)U†) = χ(ρ ⊗ ω)` (`State.holevoChi_evolve`); and the pure +environment adds no χ, `χ(ρ ⊗ ω) = χ(ρ)` (`State.holevoChi_tmul_pure_right`). -/ +theorem State.holevoChi_dilatedChannel_le {S C : QSystem} {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (U : Evolution (S ⊗ C)) (ω : PureState C) : + State.holevoChi p hp hsum (fun i => (ρ i).dilatedChannel U ω) + ≤ State.holevoChi p hp hsum ρ := by + simp only [State.dilatedChannel] + calc State.holevoChi p hp hsum (fun i => (U.evolve ((ρ i).tmul ω.toState)).reducedLeft) + ≤ State.holevoChi p hp hsum (fun i => U.evolve ((ρ i).tmul ω.toState)) := + State.holevoChi_reducedLeft_le p hp hsum (fun i => U.evolve ((ρ i).tmul ω.toState)) + _ = State.holevoChi p hp hsum (fun i => (ρ i).tmul ω.toState) := + State.holevoChi_evolve p hp hsum (fun i => (ρ i).tmul ω.toState) U + _ = State.holevoChi p hp hsum ρ := + State.holevoChi_tmul_pure_right p hp hsum ρ ω + +/-- **N&C Problem 12.1(3): the Holevo χ quantity of the measurement apparatus equals the classical +mutual information** `H(X : Y)` (which N&C states with no equation number). Alice prepares the state +`ρₓ` with probability `pₓ` (`{pₓ, ρₓ}`, random variable `X`); Bob performs a POVM measurement `m` +with outcome `Y`. Under N&C's apparatus operation `E(ρ ⊗ |0⟩⟨0|) = ∑ᵧ √Eᵧ ρ √Eᵧ ⊗ |y⟩⟨y|` +(eq. (12.211)) the apparatus register `M` +ends in the marginal `Tr_S E(ρₓ ⊗ |0⟩⟨0|) = ∑ᵧ Tr(Eᵧ ρₓ) |y⟩⟨y|`, which is exactly the +measure-and-record outcome channel `m.measState ρₓ`. This theorem states that the Holevo χ of the +apparatus ensemble `{pₓ, m.measState ρₓ}` equals the classical mutual information of the joint +distribution `p(x, y) = pₓ · Tr(Eᵧ ρₓ) = pₓ · m.bornProb ρₓ y` of `X` and `Y`: + +`χ_M = H(X : Y)`. + +Proof: `S(m.measState ρ) = H(m.bornProb ρ)` (`Measurement.vonNeumannEntropy_measState`, each +apparatus state is diagonal in the outcome basis), and the χ-mixture is the outcome channel of the +average state (`Measurement.measState_mix`) whose Born distribution is the average of the components +(`Measurement.bornProb_mix`); so `χ_M = H(Y) − ∑ₓ pₓ H(Y|X=x)`, which the conditional-joint identity +`Real.mutualInfo_prod_conditional` identifies with `H(X:Y)`. Combined with Parts (1)–(2) this yields +the Holevo bound (assembled in `holevoBound_of_chi_monotone` below). -/ +theorem State.holevoChi_measState_eq_mutualInfo {S : QSystem} {κ ι : Type*} [Fintype κ] [Fintype ι] + (p : κ → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) (ρ : κ → State S) + (m : Measurement ι S) : + State.holevoChi p hp hsum (fun x => m.measState (ρ x)) + = Real.mutualInfo (fun xy : κ × ι => p xy.1 * m.bornProb (ρ xy.1) xy.2) := by + have hq : ∀ x, ∑ y, m.bornProb (ρ x) y = 1 := fun x => m.sum_bornProb_eq_one (ρ x) + have hbar : m.bornProb (State.mix p hp hsum ρ) = fun y => ∑ x, p x * m.bornProb (ρ x) y := by + funext y; exact m.bornProb_mix p hp hsum ρ y + rw [State.holevoChi_def, ← Measurement.measState_mix m p hp hsum ρ] + simp_rw [Measurement.vonNeumannEntropy_measState] + rw [hbar, ← Real.mutualInfo_prod_conditional p (fun x => m.bornProb (ρ x)) hq] + +section HolevoBound + +variable {Q : QSystem} {r : ℕ} [NeZero r] {κ : Type*} [Fintype κ] + (p : κ → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) (ρ : κ → State Q) + (m : Measurement (Fin r) Q) + +/-- **N&C Problem 12.1: the Holevo χ quantity decreases under a measurement** — the composition of +Parts (1)–(3). For an ensemble `{pₓ, ρₓ}` of states on `Q` and a measurement `m` with `r` outcomes, +recording the outcome with the apparatus operation and discarding the measured system cannot +increase χ: + +`χ(fun x => m.measState (ρ x)) ≤ χ(fun x => ρ x)`, + +where `m.measState (ρ x) = ∑_y Tr(E_y ρ_x) |y⟩⟨y|` is the measure-and-record outcome state. + +This is the (★) inequality of the alternate Holevo-bound proof, obtained by applying N&C's apparatus +operation `𝓔` (`holevoMeasurementChannel`, Exercise 12.2) to `ρ_x ⊗ |0⟩` and then following the four +χ-monotonicity/invariance steps: + +* **(i)** `m.measState (ρ x)` is the transported apparatus `M`-marginal `Tr_Q 𝓔(ρ_x ⊗ |0⟩⟨0|)` + (`holevoMeasurementChannel_reducedRight` gives the diagonal Born state; the register mismatch + `qudit (Fintype.card (Fin r))` vs `qudit r` is bridged by `quditFinCardIso`, under which χ is + invariant, `State.holevoChi_congr`); +* **(ii)** discarding the measured system `Q` cannot increase χ (Part (1) in its `reducedRight` + form `State.holevoChi_reducedRight_le`); +* **(iii)** the apparatus operation `𝓔` is a dilated quantum operation + (`holevoMeasurementChannel_eq_reducedLeft_evolve` presents it as + `State.dilatedChannel`), under which χ cannot increase (Part (2) + `State.holevoChi_dilatedChannel_le`); +* **(iv)** appending the reset apparatus `|0⟩` leaves χ unchanged + (`State.holevoChi_tmul_pure_right`). -/ +theorem State.holevoChi_measState_le : + State.holevoChi p hp hsum (fun x => m.measState (ρ x)) + ≤ State.holevoChi p hp hsum ρ := by + -- Step (i): each outcome state is the transported apparatus `M`-marginal of `𝓔(ρ_x ⊗ |0⟩⟨0|)`. + have hstep1 : (fun x => m.measState (ρ x)) + = fun x => State.congr (quditFinCardIso r) + ((holevoMeasurementChannel m ((ρ x).tmul (quditBasis (0 : Fin r)).toState)).reducedRight) + := by + funext x + rw [Measurement.measState_def, holevoMeasurementChannel_reducedRight, State.congr_mix] + simp only [quditFinCardIso_congr_toState] + calc State.holevoChi p hp hsum (fun x => m.measState (ρ x)) + = State.holevoChi p hp hsum + (fun x => State.congr (quditFinCardIso r) + ((holevoMeasurementChannel m + ((ρ x).tmul (quditBasis (0 : Fin r)).toState)).reducedRight)) + := by rw [hstep1] + -- (i) χ is invariant under the register reindexing. + _ = State.holevoChi p hp hsum + (fun x => + (holevoMeasurementChannel m ((ρ x).tmul (quditBasis (0 : Fin r)).toState)).reducedRight) + := State.holevoChi_congr p hp hsum _ (quditFinCardIso r) + -- (ii) discarding the measured system `Q` cannot increase χ. + _ ≤ State.holevoChi p hp hsum + (fun x => holevoMeasurementChannel m ((ρ x).tmul (quditBasis (0 : Fin r)).toState)) + := State.holevoChi_reducedRight_le p hp hsum _ + -- (iii) `𝓔` is a dilated quantum operation, under which χ cannot increase. + _ ≤ State.holevoChi p hp hsum + (fun x => (ρ x).tmul (quditBasis (0 : Fin r)).toState) := by + have hfam : (fun x => holevoMeasurementChannel m + ((ρ x).tmul (quditBasis (0 : Fin r)).toState)) + = fun x => State.dilatedChannel ((ρ x).tmul (quditBasis (0 : Fin r)).toState) + (measurementModelEvolution (quditOrthonormalBasis r) + (quditBasis (0 : Fin r)).normalized (holevoMeasurementKraus m) + (holevoMeasurementKraus_completeness m)) (quditBasis (0 : Fin r)) := by + funext x + exact holevoMeasurementChannel_eq_reducedLeft_evolve m + ((ρ x).tmul (quditBasis (0 : Fin r)).toState) + rw [hfam] + exact State.holevoChi_dilatedChannel_le p hp hsum + (fun x => (ρ x).tmul (quditBasis (0 : Fin r)).toState) _ (quditBasis (0 : Fin r)) + -- (iv) appending the reset apparatus leaves χ unchanged. + _ = State.holevoChi p hp hsum ρ := + State.holevoChi_tmul_pure_right p hp hsum ρ (quditBasis (0 : Fin r)) + +/-- **N&C Problem 12.1: the Holevo bound** (eq. (12.212)), assembled from Parts (1)–(3) via the +monotonicity of the Holevo χ quantity — the alternate proof developed in this problem. Alice +prepares the state `ρₓ` with probability `pₓ` (random variable `X`); Bob measures with a POVM `m` +with `r` outcomes (random variable `Y`). Then the classical mutual information of the joint +distribution `p(x, y) = pₓ · Tr(Eᵧ ρₓ)` obeys + +`H(X : Y) ≤ S(ρ) − ∑ₓ pₓ S(ρₓ)`, + +the right-hand side being the Holevo χ quantity `χ = S(∑ₓ pₓ ρₓ) − ∑ₓ pₓ S(ρₓ)` +(`State.holevoChi`, `State.holevoChi_def`). + +The proof combines the two ingredients of this file: Part (3) +`State.holevoChi_measState_eq_mutualInfo` rewrites `H(X : Y)` as the Holevo χ of the +measure-and-record ensemble `{pₓ, m.measState ρₓ}`, and `State.holevoChi_measState_le` — the +composition of Parts (1)–(2) with the apparatus construction — bounds that by the χ of the original +ensemble `{pₓ, ρₓ}`. This is N&C's alternate route to the Holevo bound, replacing the direct +relative-entropy / data-processing argument (Theorem 12.1) by χ monotonicity throughout. -/ +theorem holevoBound_of_chi_monotone : + Real.mutualInfo (fun xy : κ × Fin r => p xy.1 * m.bornProb (ρ xy.1) xy.2) + ≤ State.holevoChi p hp hsum ρ := by + rw [← State.holevoChi_measState_eq_mutualInfo p hp hsum ρ m] + exact State.holevoChi_measState_le p hp hsum ρ m + +end HolevoBound + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem1.lean b/LeanPool/AxQM/NC/Ch12/Theorem1.lean new file mode 100644 index 0000000000..e04f57c4b6 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem1.lean @@ -0,0 +1,93 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch12.Problem1 + +/-! +# N&C Theorem 12.1 — the Holevo bound + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 12.1, p. 531. + +Alice prepares a state `ρₓ` with probability `pₓ` (random variable `X`, ranging over a finite index +`κ`); Bob performs a POVM measurement `m` on that state and obtains an outcome `Y` (ranging over the +`r` outcomes `Fin r`). The **Holevo bound** (eq. (12.6)) states that, for *any* such measurement, + +`H(X : Y) ≤ S(ρ) − ∑ₓ pₓ S(ρₓ)`, where `ρ = ∑ₓ pₓ ρₓ`. + +`holevo_bound` is this statement, verbatim: the left-hand side is the classical mutual information +`Real.mutualInfo` of the joint distribution `p(x, y) = pₓ · Tr(Eᵧ ρₓ) = pₓ · m.bornProb (ρₓ) y` of +Alice's preparation `X` and Bob's outcome `Y`; the right-hand side is written out explicitly as +`S(∑ₓ pₓ ρₓ) − ∑ₓ pₓ S(ρₓ)` — the entropy of the average state `State.mix` minus the average of the +component entropies (the Holevo χ quantity `χ`, N&C eq. (12.6), spelled out). + +## Statement shape and fidelity + +The bound is stated at N&C's full generality: an arbitrary system `Q`, an arbitrary finite ensemble +`{pₓ, ρₓ}` (index `κ`), and an arbitrary finite-outcome measurement `m : Measurement (Fin r) Q` +(`r ≥ 1` via `NeZero`). Bob's "POVM `{Eᵧ}`" is presented as a +`Measurement (Fin r) Q` rather than a bare POVM: every POVM is `m.toPOVM` for some such +measurement, so no generality is lost and no hypothesis is added — the common weakening +(fixing a dimension, adding a +faithfulness/full-rank hypothesis) is avoided. The right-hand side is deliberately unfolded to the +explicit entropy difference `S(ρ) − ∑ₓ pₓ S(ρₓ)` matching the textbook display, rather than +`State.holevoChi`, so the statement reads as N&C's Theorem 12.1 itself. + +## Proof route and reuse + +N&C's own proof of Theorem 12.1 introduces a tripartite system `P ⊗ Q ⊗ M` and bounds the mutual +information by the quantum data-processing inequality. The direct relative-entropy / data-processing +argument is **not used** in this library: the relative-entropy data-processing inequalities of +`ToMathlib/` all require `IsStrictlyPositive`, but the +Stinespring-dilated state is never full rank, so they do not compose into a channel DPI without a +regularization/continuity development the library lacks. The proof instead follows N&C's +*faithfulness-free* mutual-information / apparatus argument, whose χ-monotonicity engine is +developed in **Problem 12.1** (`LeanPool/AxQM/NC/Ch12/Problem1.lean`): Part (1) χ +decreases under discarding a subsystem, Part (2) χ decreases under a quantum operation, Part (3) +the measurement apparatus has `χ_M = H(X : Y)`. Their composition is `holevoBound_of_chi_monotone` +(`H(X : Y) ≤ χ`). + +Theorem 12.1 and Problem 12.1 prove the *same* inequality, so `holevo_bound` uses +`holevoBound_of_chi_monotone` from `LeanPool/AxQM/NC/Ch12/Problem1.lean` rather than re-proving it. +The +proof is one step: unfold the explicit right-hand side to `State.holevoChi` +(`State.holevoChi_def`, definitional), then apply `holevoBound_of_chi_monotone`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- **N&C Theorem 12.1 (the Holevo bound)** (eq. (12.6)). Alice prepares `ρₓ` with probability `pₓ` +(random variable `X` over the finite index `κ`); Bob performs the POVM measurement `m` and obtains +outcome `Y` (over `Fin r`). Then the classical mutual information of the joint distribution +`p(x, y) = pₓ · m.bornProb (ρₓ) y` of `X` and `Y` is bounded by the Holevo χ quantity of Alice's +ensemble: + +`H(X : Y) ≤ S(ρ) − ∑ₓ pₓ S(ρₓ)`, where `ρ = ∑ₓ pₓ ρₓ`, + +the right-hand side being the entropy of the average state minus the average of the component +entropies. Holds for any measurement Bob may perform, with no restriction on the ensemble or the +dimension. + +The right-hand side is `State.holevoChi p hp hsum ρ` unfolded via `State.holevoChi_def`; the +bound is then the χ-monotonicity result `holevoBound_of_chi_monotone` (N&C Problem 12.1's +alternate proof, shared with this theorem — see the module docstring for the route). -/ +theorem holevo_bound {Q : QSystem} {r : ℕ} [NeZero r] {κ : Type*} [Fintype κ] + (p : κ → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) (ρ : κ → State Q) + (m : Measurement (Fin r) Q) : + Real.mutualInfo (fun xy : κ × Fin r => p xy.1 * m.bornProb (ρ xy.1) xy.2) + ≤ (State.mix p hp hsum ρ).vonNeumannEntropy - ∑ x, p x * (ρ x).vonNeumannEntropy := by + rw [← State.holevoChi_def p hp hsum ρ] + exact holevoBound_of_chi_monotone p hp hsum ρ m + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem10.lean b/LeanPool/AxQM/NC/Ch12/Theorem10.lean new file mode 100644 index 0000000000..402ca4f0f4 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem10.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.NC.Ch12.CoherentInformation + +/-! +# N&C Theorem 12.10 — the quantum data processing inequality + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 12.10, p. 564. + +For a quantum state `ρ` and trace-preserving quantum operations `E1`, `E2`, the coherent information +`I(ρ, E) = S(E(ρ)) − S(ρ, E)` (N&C eq. (12.118)) obeys the two-stage chain + +`S(ρ) ≥ I(ρ, E1) ≥ I(ρ, E2 ∘ E1)` (eq. (12.119)), + +the quantum analogue of the classical data processing inequality `H(X) ≥ H(X:Y) ≥ H(X:Z)` for a +Markov chain `X → Y → Z`. This file formalises this inequality chain; +N&C's additional clause — equality in the first inequality iff `E1` is perfectly +reversible on `ρ` (Exercise 12.16) — is a separate characterisation and is not formalised here. + +## The formalisation (two named claims) + +The two inequalities of the chain are the two claims, stated as separate theorems. + +* **First inequality** `S(ρ) ≥ I(ρ, E1)` — `AxQM.State.coherentInfo_le_vonNeumannEntropy` + (`NC/Ch12/CoherentInformation.lean`). N&C's subadditivity argument (12.122)–(12.126) in the + purification picture: with `R'Q' = (refPurify ρ).dilatedChannelOnRight U₁ ω₁`, the Araki–Lieb + triangle inequality bounds `I(ρ, E1) = S(Q') − S(R'Q')` by `S(R') = S(ρ)`. +* **Second inequality** `I(ρ, E1) ≥ I(ρ, E2 ∘ E1)` — `State.coherentInfoComp_le_coherentInfo` + (below). N&C's strong-subadditivity argument (12.127)–(12.131). Both coherent informations are + read as the state coherent information `I(A⟩B) = S(B) − S(A,B)` of the reference–system state + (`State.coherentInfoComp`; the identification of `I(ρ, E1)` is derived in the proof body), and the + inequality is the monotonicity of `I(A⟩B)` under a channel on `B` + (`State.coherentInfoOfState_dilatedChannelOnRight_le`) instantiated at `σ = R'Q'`. + +## Presentation of the operations and the composition + +As throughout §12.4 (the library has no abstract "every trace-preserving map has a +Kraus/dilation form" to quantify over), each operation is presented by its Chapter-8 dilation — a +unitary `U` on `Q ⊗ Cᵢ` with the environment `Cᵢ` prepared in a pure state `ωᵢ`. The composition +`E2 ∘ E1` is realised by applying the two dilations in sequence to the system factor of the +reference purification (`State.coherentInfoComp`), which is faithful to N&C's four-system dynamics +(`Q` interacts with `E1`, then with `E2`, while the reference `R` is untouched) and makes +`S(ρ, E2 ∘ E1) = S(R''Q'')` hold by the framework's purification definition of the entropy exchange. + +The data processing infrastructure — `State.coherentInfoOfState`, the dilation marginal lemmas, +the coherent-information definitions and monotonicity — is in +`AxQM/Core/ConditionalEntropy.lean` and `AxQM/NC/Ch12/CoherentInformation.lean`; this file states +the second inequality and assembles the theorem. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {Q C : QSystem} + +/-- **Second inequality of the quantum data processing inequality** (Nielsen & Chuang Theorem 12.10, +eq. (12.119), second stage): + +`I(ρ, E2 ∘ E1) ≤ I(ρ, E1)`. + +The composed coherent information `I(ρ, E2 ∘ E1)` (`State.coherentInfoComp`, the state coherent +information of the twice-processed reference–system state `R''Q''`) is at most the single-channel +coherent information `I(ρ, E1)` (`ρ.coherentInfo U₁ ω₁`). This is N&C's strong-subadditivity +argument (12.127)–(12.131): rewriting `I(ρ, E1)` as the state coherent information `I(R'⟩Q')` of +`R'Q' = (refPurify ρ).dilatedChannelOnRight U₁ ω₁` (an in-body step, from the dilation marginal +identities and `State.refPurify_reducedRight`), the claim is the monotonicity of the state +coherent information under the channel `E2` acting on the system factor `Q'` +(`State.coherentInfoOfState_dilatedChannelOnRight_le`), whose engine is strong subadditivity. + +Together with `State.coherentInfo_le_vonNeumannEntropy` (the first inequality `S(ρ) ≥ I(ρ, E1)`) +this gives the full chain `S(ρ) ≥ I(ρ, E1) ≥ I(ρ, E2 ∘ E1)`. -/ +theorem State.coherentInfoComp_le_coherentInfo (ρ : State Q) (U₁ : Evolution (Q ⊗ C)) + (ω₁ : PureState C) {D : QSystem} (U₂ : Evolution (Q ⊗ D)) (ω₂ : PureState D) : + ρ.coherentInfoComp U₁ ω₁ U₂ ω₂ ≤ ρ.coherentInfo U₁ ω₁ := by + unfold State.coherentInfoComp + -- `I(ρ, E1) = I(R'⟩Q')`: the single-channel coherent information is the state coherent info + -- of the processed purification; cf. `State.entropyExchange`. + have hEq : ρ.coherentInfo U₁ ω₁ + = ((State.refPurify ρ).toState.dilatedChannelOnRight U₁ ω₁).coherentInfoOfState := by + unfold State.coherentInfo State.entropyExchange + rw [State.coherentInfoOfState_def, State.reducedRight_dilatedChannelOnRight, + State.refPurify_reducedRight] + rw [hEq] + exact State.coherentInfoOfState_dilatedChannelOnRight_le _ U₂ ω₂ + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem15.lean b/LeanPool/AxQM/NC/Ch12/Theorem15.lean new file mode 100644 index 0000000000..045d84396c --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem15.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.StateMajorization + +/-! +# Nielsen–Chuang, Theorem 12.15 — Nielsen's theorem + +**Theorem 12.15** (N&C §12.5.1, p. 573). *"A bipartite pure state `|ψ⟩` may be +transformed to `|ϕ⟩` by local operations and classical communication (LOCC) if and only if +`λ_ψ ≺ λ_ϕ`"*, where `λ_ψ` is the vector of squared Schmidt coefficients of `|ψ⟩` — equivalently the +eigenvalue distribution of the reduced density operator `ρ_ψ`. + +## What is formalised + +The faithful content of the theorem is an *iff between the reduced states* `ρ = ρ_ψ`, `σ = ρ_ϕ`: + +`AxQM.State.loccConvertible_iff_majorize` : + `ρ.LOCCConvertible σ ↔ ρ.Majorize σ`. + +* `State.Majorize ρ σ` (`AxQM/Postulates/API/StateMajorization.lean`) is N&C's `λ_ψ ≺ λ_ϕ`: + majorization of the eigenvalue distributions, `Majorize ρ.eigenvalueDist σ.eigenvalueDist`. + Because `λ_ψ` *is* the eigenvalue vector of `ρ_ψ`, this is exactly the theorem's condition on + the reduced states. +* `State.LOCCConvertible ρ σ` (`AxQM/Postulates/API/StateMajorization.lean`) is the density-operator + content of "`|ψ⟩ → |ϕ⟩` by LOCC": there is a measurement `{Mⱼ}` and a probability distribution + `pⱼ` with `Mⱼ ρ Mⱼ† = pⱼ σ` for every outcome — Alice's one-way measurement carrying `ρ` to `σ` + deterministically, Bob completing the transfer by a local unitary. + +The two directions are the theorems it is assembled from: +* forward (`⟹`) `State.LOCCConvertible.majorize` — the measurement-realizability condition forces + `ρ ≺ σ` (via polar decomposition + the reverse operator-majorization Theorem 12.13); +* converse (`⇐`) `State.LOCCConvertible_of_majorize` — `ρ ≺ σ` is realized by an explicit + measurement built from the inverse-square-root pseudo-inverse `(√ρ)⁺`, with no invertibility + hypothesis on `ρ` (N&C Exercise 12.20; the rank-deficient case is handled by an extra + kernel-projector outcome). + +## Scope + +The Lean equivalence concerns one-way measurement realizability on reduced density operators. +Nielsen & Chuang's Theorem 12.15 concerns transformations between bipartite pure states. The +textbook's Proposition 12.14 reduces two-way protocols to the one-way form on pure-state +inputs. The corresponding pure-input reduction is proved in +[pinned AxQMLib](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Proposition12_14.lean#L453-L455) +as `OneWayLOCC.of_transforms_pureState`. The equivalence below relates the reduced-state +measurement condition `State.LOCCConvertible` to majorization. +-/ + +@[expose] public section + +namespace AxQM + +namespace State + +variable {S : QSystem} + +/-- **Nielsen's theorem** (Nielsen–Chuang, Theorem 12.15), reduced-state form: a bipartite pure +state `|ψ⟩` can be converted to `|ϕ⟩` by one-way LOCC iff the reduced state `ρ = ρ_ψ` is majorized +by `σ = ρ_ϕ` (`λ_ψ ≺ λ_ϕ`). The `↔` combines the forward `LOCCConvertible.majorize` (LOCC ⟹ +majorization, via Theorem 12.13's reverse direction) with the converse `LOCCConvertible_of_majorize` +(majorization ⟹ LOCC, via the `(√ρ)⁺` measurement construction, no invertibility hypothesis). -/ +theorem loccConvertible_iff_majorize {ρ σ : State S} : + ρ.LOCCConvertible σ ↔ ρ.Majorize σ := + ⟨LOCCConvertible.majorize, LOCCConvertible_of_majorize⟩ + +end State + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem5.lean b/LeanPool/AxQM/NC/Ch12/Theorem5.lean new file mode 100644 index 0000000000..379c531408 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem5.lean @@ -0,0 +1,196 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace + +/-! +# N&C Theorem 12.5 — the typical subspace theorem (parts (1) and (2)) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 12.5, pp. 543–544. + +For an i.i.d. quantum source `ρ : State S` with spectral decomposition `ρ = ∑ₓ λ(x) |eₓ⟩⟨eₓ|`, the +**typical subspace theorem** is the quantum translation of the classical theorem of typical +sequences (N&C Theorem 12.2). Writing `P(n, ε) = ρ.typicalSubspaceProj n ε` for the projector onto +the ε-typical subspace `T(n, ε)` (N&C Eq. 12.42) and `S(ρ) = ρ.vonNeumannEntropy` for the von +Neumann entropy, N&C states three parts, all proved here: + +* **Part (1)** (`State.typicalSubspace_bornProb_ge`, N&C Eq. 12.43). Fix `ε > 0`. For any `δ > 0`, + for all sufficiently large `n`, the probability that `ρ^⊗n` lies in the ε-typical subspace is at + least `1 − δ`: `tr(P(n, ε) ρ^⊗n) ≥ 1 − δ`. +* **Part (2)** (`State.typicalSubspaceDim_bounds`, N&C Eq. 12.44). Fix `ε > 0` and `δ > 0`. For all + sufficiently large `n`, the dimension `|T(n, ε)| = tr(P(n, ε))` of the typical subspace satisfies + `(1 − δ) 2^{n(S(ρ)−ε)} ≤ |T(n, ε)| ≤ 2^{n(S(ρ)+ε)}`. + +* **Part (3)** (`State.smallSubspace_bornProb_le`, N&C Eq. 12.45). Fix a rate `R < S(ρ)`. For any + `δ > 0`, for all sufficiently large `n`, *every* subspace `S(n)` of dimension at most `2^{nR}` + satisfies `tr(S(n) ρ^⊗n) ≤ δ` — a small subspace cannot capture the source. `S(n)` is presented as + any projective two-outcome measurement `M` whose `true`-projector has rank + `M.trueSubspaceDim ≤ exp(n R)`, and the left-hand side is the Born probability + `M.bornProb (ρ^⊗n) true` of landing in it. + +## Statement shape and fidelity + +Both parts are stated over N&C's full data — an arbitrary system `S`, an arbitrary state `ρ`, and +the *exact* `ε`/`δ`/`n` quantifier structure of the textbook ("fix `ε > 0`; for any `δ > 0`, for +sufficiently large `n`, …") — with no dimension fixed and no hypothesis added. + +* Part (1) is stated through the Born probability `Measurement.bornProb`: `P(n, ε)` is packaged + as the two-outcome projective measurement `ρ.typicalSubspaceMeasurement n ε` (typical / atypical), + and the left-hand side is *literally* the Born probability of the typical outcome `true` on + `ρ^⊗n`. This is the faithful physical reading of N&C's `tr(P(n, ε) ρ^⊗n)` — the probability of + landing in the typical subspace — rather than a raw operator trace. +* Part (2) is stated over the dimension `ρ.typicalSubspaceDim n ε : ℕ = |T(n, ε)|`. N&C's identity + `|T(n, ε)| = tr(P(n, ε))` is `State.trace_typicalSubspaceProj_eq_typicalSubspaceDim` (in + `AxQM/Postulates/API/TypicalSubspace.lean`), so this cardinality *is* the trace of the + projector. +* Part (3) quantifies over N&C's "*any* subspace `S(n)` of dimension at most `2^{nR}`". Every such + subspace is the range of a genuine projector, faithfully modelled as the `true`-outcome projector + of a projective two-outcome `Measurement Bool (S ^⊗ₛ n)` — its rank is + `Measurement.trueSubspaceDim : ℕ` — and, as in Part (1), the conclusion `tr(S(n) ρ^⊗n) ≤ δ` is + the Born probability `Measurement.bornProb` of the `true` outcome. No generality is lost (any + projector arises this way) and none is added. + +**Nats convention**: the von Neumann entropy and the +exponentials are in nats (`Real.exp`), so N&C's base-`2` bounds `(1 − δ) 2^{n(S−ε)} ≤ |T| ≤ +2^{n(S+ε)}` read here as `(1 − δ) exp(n(S − ε)) ≤ |T| ≤ exp(n(S + ε))` — the same statement rescaled +by `log 2`, consistent with Theorems 12.2/12.4 in `ToMathlib/`. + +## Proof route and reuse + +The whole content is the reduction to the *classical* theorem of typical sequences applied to `ρ`'s +eigenvalue distribution `λ = ρ.eigenvalueDist` (a genuine probability distribution, +`eigenvalueDist_nonneg` / `eigenvalueDist_sum_eq_one`, with `H(λ) = S(ρ)`, +`vonNeumannEntropy_eq_entropy_eigenvalueDist`). +Both proofs are one application of the classical existence theorem followed by the two bridge +rewrites already established in `AxQM/Postulates/API/TypicalSubspace.lean`: + +* Part (1): `typicalSubspaceMeasurement_bornProb_true` rewrites the Born probability to the + classical typicality mass `∑_{κ ∈ T(n, ε)} ∏ᵢ λ(κᵢ)`, which `Real.exists_le_sum_typicalSeq` + bounds below by `1 − δ`. +* Part (2): `Real.exists_card_typicalSeq_bounds` bounds `|T(n, ε)| = (typicalSeq λ n ε).card` + (definitionally `typicalSubspaceDim`) between `(1 − δ) exp(n(H(λ) − ε))` and `exp(n(H(λ) + ε))`; + the entropy bridge turns `H(λ)` into `S(ρ)`. +* Part (3): `State.exists_weights_bornProb_true` expands the Born probability of + *any* projective `S(n)` on `ρ^⊗n` into the classical *weighted* mass `∑_κ w κ · ∏ᵢ λ(κᵢ)`, with + eigenbasis-diagonal weights `w κ ∈ [0, 1]` summing to `tr S(n) = M.trueSubspaceDim`; the weighted + small-set bound `Real.exists_sum_weighted_prod_le_of_sum_le_exp` (the fractional refinement of + `Real.exists_sum_prod_le_of_card_le_exp`) then forces it below `δ` once `M.trueSubspaceDim ≤ + exp(n R)` and `R < H(λ) = S(ρ)`. + +The machinery they reduce to (`typicalSubspaceProj`, the trace identities, the projective +measurement, `eigenvalueDist`, `trueSubspaceDim`, and the weighted-mass reduction +`exists_weights_bornProb_true`) is in `AxQM/Postulates/API/TypicalSubspace.lean`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Typical subspace theorem, part (1)** (Nielsen & Chuang, Theorem 12.5, Eq. 12.43): the source +`ρ^⊗n` lands in the ε-typical subspace with probability `≥ 1 − δ` for all sufficiently large `n`. +Fix `ε > 0`; then for any `δ > 0` there is an `N` such that for every `n ≥ N` the Born probability +of the typical outcome of the projective measurement `{P(n, ε), I − P(n, ε)}` on `ρ^⊗n` is at least +`1 − δ` — i.e. `tr(P(n, ε) ρ^⊗n) ≥ 1 − δ`. + +The proof rewrites the Born probability to the classical typicality mass `∑_{κ typical} ∏ᵢ λ(κᵢ)` +(`typicalSubspaceMeasurement_bornProb_true`) and applies the classical theorem of typical sequences +(`Real.exists_le_sum_typicalSeq`) to the eigenvalue distribution `λ = ρ.eigenvalueDist`. -/ +theorem State.typicalSubspace_bornProb_ge (ρ : State S) {ε : ℝ} (hε : 0 < ε) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, + 1 - δ ≤ (ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true := by + obtain ⟨N, hNpos, hN⟩ := + Real.exists_le_sum_typicalSeq ρ.eigenvalueDist_nonneg ρ.eigenvalueDist_sum_eq_one hε hδ + refine ⟨N, hNpos, fun n hn => ?_⟩ + rw [ρ.typicalSubspaceMeasurement_bornProb_true] + exact hN n hn + +/-- **Typical subspace theorem, part (1), limit form**: the probability that `ρ^⊗n` lies in the +ε-typical subspace tends to `1` as `n → ∞`, `tr(P(n, ε) ρ^⊗n) → 1`. The `Tendsto` companion of +`State.typicalSubspace_bornProb_ge` (which provides the eventual lower bound `≥ 1 − δ`): together +with `bornProb ≤ 1` (`Measurement.bornProb_le_one`) the two-sided squeeze gives the limit. The +citable driver of ensemble/entanglement-fidelity compression-reliability arguments. -/ +theorem State.typicalSubspace_bornProb_tendsto_one (ρ : State S) {ε : ℝ} (hε : 0 < ε) : + Filter.Tendsto (fun n => (ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true) + Filter.atTop (nhds 1) := by + rw [Metric.tendsto_atTop] + intro δ hδ + obtain ⟨N, -, hN⟩ := ρ.typicalSubspace_bornProb_ge hε (half_pos hδ) + refine ⟨N, fun n hn => ?_⟩ + have h2 := (ρ.typicalSubspaceMeasurement n ε).bornProb_le_one (ρ.tensorPow n) true + rw [Real.dist_eq, abs_of_nonpos (by linarith [hN n hn])]; linarith [hN n hn] + +/-- **Typical subspace theorem, part (2)** (Nielsen & Chuang, Theorem 12.5, Eq. 12.44): the +dimension of the ε-typical subspace is `2^{n S(ρ)}` up to the exponential tolerance `ε`. Fix `ε > 0` +and `δ > 0`; then for all sufficiently large `n` the dimension `|T(n, ε)| = tr(P(n, ε))` satisfies + +`(1 − δ) exp(n (S(ρ) − ε)) ≤ |T(n, ε)| ≤ exp(n (S(ρ) + ε))` + +(in nats; N&C's base-`2` `(1 − δ) 2^{n(S(ρ)−ε)} ≤ |T(n, ε)| ≤ 2^{n(S(ρ)+ε)}`). The dimension is +`ρ.typicalSubspaceDim n ε`, which equals `tr(P(n, ε))` by +`trace_typicalSubspaceProj_eq_typicalSubspaceDim`. + +The proof applies the classical dimension bounds (`Real.exists_card_typicalSeq_bounds`) to `λ = +ρ.eigenvalueDist` — whose typical-set cardinality is definitionally `typicalSubspaceDim` — and +rewrites the classical entropy `H(λ)` to the von Neumann entropy `S(ρ)` via the entropy bridge +`vonNeumannEntropy_eq_entropy_eigenvalueDist`. -/ +theorem State.typicalSubspaceDim_bounds (ρ : State S) {ε : ℝ} (hε : 0 < ε) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, + (1 - δ) * Real.exp (n * (ρ.vonNeumannEntropy - ε)) ≤ (ρ.typicalSubspaceDim n ε : ℝ) ∧ + (ρ.typicalSubspaceDim n ε : ℝ) ≤ Real.exp (n * (ρ.vonNeumannEntropy + ε)) := by + obtain ⟨N, hNpos, hN⟩ := + Real.exists_card_typicalSeq_bounds ρ.eigenvalueDist_nonneg ρ.eigenvalueDist_sum_eq_one hε hδ + refine ⟨N, hNpos, fun n hn => ?_⟩ + simp only [State.typicalSubspaceDim, ρ.vonNeumannEntropy_eq_entropy_eigenvalueDist] + exact hN n hn + +/-- **Typical subspace theorem, part (3)** (Nielsen & Chuang, Theorem 12.5, Eq. 12.45): a *small* +subspace carries negligible weight of the source. Fix a rate `R < S(ρ)`. For any `δ > 0`, for all +sufficiently large `n`, *every* subspace `S(n) ⊆ (S ^⊗ₛ n).space` of dimension at most `exp(n R)` — +presented as the `true`-outcome projector of a projective two-outcome measurement `M` with +`M.trueSubspaceDim ≤ exp(n R)` — satisfies `tr(S(n) ρ^⊗n) ≤ δ`: the probability of landing in `S(n)` +when measuring `ρ^⊗n` is at most `δ`. + +(In nats; N&C's base-`2` bound reads `dim S(n) ≤ 2^{nR}`, `R < S(ρ)`.) N&C quantifies over "any +subspace of `H^⊗n` of dimension at most `2^{nR}`"; every such subspace is the range of a genuine +projector `S(n)`, faithfully captured here as the `true`-outcome projector `M.op true` of the +two-outcome von Neumann measurement `{S(n), I − S(n)}`, with its rank `M.trueSubspaceDim` +bounded by `exp(n R)` — so the conclusion is the Born probability +`M.bornProb (ρ.tensorPow n) true`, the faithful reading +of `tr(S(n) ρ^⊗n)`. + +The proof expands `tr(S(n) ρ^⊗n) = ∑_κ ⟨e_κ, S(n) e_κ⟩ ∏ᵢ λ(κᵢ)` in the `ρ^⊗n` eigenbasis +(`exists_weights_bornProb_true`): the diagonal weights `w κ = ⟨e_κ, S(n) e_κ⟩ ∈ [0, 1]` sum to +`tr S(n) = dim S(n) ≤ exp(n R)`, so the classical *weighted* small-set bound +(`Real.exists_sum_weighted_prod_le_of_sum_le_exp`) applied to the eigenvalue distribution +`λ = ρ.eigenvalueDist` (with `entropy λ = S(ρ)`, `vonNeumannEntropy_eq_entropy_eigenvalueDist`) +forces the weighted mass below `δ`. -/ +theorem State.smallSubspace_bornProb_le (ρ : State S) {R : ℝ} (hR : R < ρ.vonNeumannEntropy) + {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, ∀ M : Measurement Bool (S ^⊗ₛ n), M.IsProjective → + (M.trueSubspaceDim : ℝ) ≤ Real.exp (n * R) → + M.bornProb (ρ.tensorPow n) true ≤ δ := by + have hR' : R < Real.entropy ρ.eigenvalueDist := by + rw [← ρ.vonNeumannEntropy_eq_entropy_eigenvalueDist]; exact hR + obtain ⟨N, hNpos, hN⟩ := + Real.exists_sum_weighted_prod_le_of_sum_le_exp ρ.eigenvalueDist_nonneg + ρ.eigenvalueDist_sum_eq_one hR' hδ + refine ⟨N, hNpos, fun n hn M hM hdim => ?_⟩ + obtain ⟨w, hw0, hw1, hwsum, hbp⟩ := ρ.exists_weights_bornProb_true n M hM + rw [hbp] + exact hN n hn w hw0 hw1 (by rw [hwsum]; exact hdim) + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem6.lean b/LeanPool/AxQM/NC/Ch12/Theorem6.lean new file mode 100644 index 0000000000..61c30af957 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem6.lean @@ -0,0 +1,120 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SchumacherDirect +public import LeanPool.AxQM.Postulates.API.SchumacherConverse + +/-! +# N&C Theorem 12.6 — Schumacher's noiseless channel coding theorem + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 12.6, p. 544. + +Schumacher's quantum noiseless channel coding theorem characterises exactly when an i.i.d. quantum +source `{H, ρ}` can be compressed reliably. For a (qubit) rate `R`, N&C states two directions: + +* **direct part** — if `R > S(ρ)` there is a reliable rate-`R` compression scheme (N&C Eqs. + 12.50–12.53); and +* **converse** — if `R < S(ρ)` no rate-`R` scheme is reliable (N&C Eqs. 12.54–12.58). + +So, away from the boundary `R = S(ρ)`, the source `ρ` is reliably compressible at rate `R` **iff** +`R > S(ρ)`. Here `S(ρ) = ρ.vonNeumannEntropy` (in nats), the qubit rate `R` compares as `R * log 2` +against `S(ρ)`, and *reliability* of a rate-`R` scheme means its entanglement fidelity for `ρ^⊗n` +tends to `1` as the block length `n → ∞`. + +## What this file contains + +The two directional halves are established in `AxQM/Postulates/API/SchumacherDirect.lean` and +`AxQM/Postulates/API/SchumacherConverse.lean`. They are stated for the predicate +`ContinuousLinearMap.ReliablyCompressible ρ.op R` of the density operator `ρ.op` +(`ToMathlib/Analysis/InnerProductSpace/QuantumDataCompression.lean`): + +* `State.reliablyCompressible_of_vonNeumannEntropy_lt` (direct, `SchumacherDirect.lean`): + `ρ.vonNeumannEntropy < R * log 2 → ContinuousLinearMap.ReliablyCompressible ρ.op R`; +* `State.not_reliablyCompressible_of_lt_vonNeumannEntropy` (converse, `SchumacherConverse.lean`): + `0 ≤ R → R * log 2 < ρ.vonNeumannEntropy → ¬ ContinuousLinearMap.ReliablyCompressible ρ.op R`. + +This file states the theorem for states: + +* `State.ReliablyCompressible` — reliable compressibility of a state `ρ : State S`, defined as the + predicate above on `ρ.op`. +* `State.reliablyCompressible_iff_vonNeumannEntropy_lt` — **the headline** (Theorem 12.6): for a + non-negative rate `R` away from the boundary, `ρ.ReliablyCompressible R ↔ ρ.vonNeumannEntropy < + R * log 2`. + +## Faithfulness + +* **The two halves, one equivalence.** N&C states Theorem 12.6 as two implications; the single + biconditional here is their exact conjunction and is the natural statement of the theorem + ("reliable compression iff `R > S(ρ)`"). The two directions remain available individually as + the lemmas above. +* **The boundary `R log 2 = S(ρ)` is deliberately excluded (`hne`), not a weakening.** N&C's theorem + says nothing at `R = S(ρ)` — it asserts reliability only for `R > S(ρ)` and unreliability only for + `R < S(ρ)` — so whether the source is reliably compressible *at* `R = S(ρ)` is left open by the + textbook. The hypothesis `R * log 2 ≠ ρ.vonNeumannEntropy` restricts the equivalence to exactly + the domain N&C characterises; claiming a strict iff at the boundary would overclaim beyond the + source. (The two halves together give only `reliable → S(ρ) ≤ R log 2`, not the strict `<`, so the + boundary genuinely cannot be resolved from them.) +* **Non-negative rate (`hR0`).** Inherited from the converse: a qubit rate is `R ≥ 0`, and the + hypothesis is necessary there — a pure source (`S(ρ) = 0`) is reliably compressible at *every* + rate, including the negative rates that are the only way `R log 2 < 0 = S(ρ)` can hold — which + would falsify an unconditional converse. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.50)–(12.58)). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Reliable compressibility of a quantum source** (Nielsen & Chuang, §12.2.2). A source +`ρ : State S` is *reliably compressible at (qubit) rate `R`* when its density operator `ρ.op` is: +there is a family of rate-`R` quantum compression schemes whose entanglement fidelity for `ρ^⊗n` +tends to `1` as the block length `n → ∞`. + +This is `ContinuousLinearMap.ReliablyCompressible` applied to the density operator `ρ.op`, so the +notion is stated for states. -/ +def State.ReliablyCompressible (ρ : State S) (R : ℝ) : Prop := + ContinuousLinearMap.ReliablyCompressible ρ.op R + +/-- **Schumacher's noiseless channel coding theorem** (Nielsen & Chuang, Theorem 12.6, p. 544). For +a non-negative (qubit) rate `R` away from the boundary `R = S(ρ)`, an i.i.d. quantum source `ρ` is +reliably compressible at rate `R` **iff** the rate exceeds the source entropy, `S(ρ) < R` (in nats, +`ρ.vonNeumannEntropy < R * log 2`). + +This assembles N&C's two directions for the predicate `State.ReliablyCompressible`: + +* if `S(ρ) < R log 2`, the direct part `State.reliablyCompressible_of_vonNeumannEntropy_lt` builds a + reliable scheme; and +* if `R log 2 < S(ρ)`, the converse `State.not_reliablyCompressible_of_lt_vonNeumannEntropy` (using + `0 ≤ R`) forbids one. + +The hypothesis `R * log 2 ≠ ρ.vonNeumannEntropy` excludes the boundary `R = S(ρ)`, which N&C leaves +open (see the module docstring); it is the exact domain the textbook characterises, not a +weakening. -/ +theorem State.reliablyCompressible_iff_vonNeumannEntropy_lt (ρ : State S) {R : ℝ} + (hR0 : 0 ≤ R) (hne : R * Real.log 2 ≠ ρ.vonNeumannEntropy) : + ρ.ReliablyCompressible R ↔ ρ.vonNeumannEntropy < R * Real.log 2 := by + constructor + · intro hrc + rcases lt_or_gt_of_ne hne with h | h + · exact absurd hrc (ρ.not_reliablyCompressible_of_lt_vonNeumannEntropy hR0 h) + · exact h + · intro h + exact ρ.reliablyCompressible_of_vonNeumannEntropy_lt h + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch12/Theorem8.lean b/LeanPool/AxQM/NC/Ch12/Theorem8.lean new file mode 100644 index 0000000000..4e2831ab26 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch12/Theorem8.lean @@ -0,0 +1,549 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.ChannelHolevoChi +public import LeanPool.AxQM.Core.PiTensorSuccHead +public import LeanPool.AxQM.Core.ProductStateCode +public import LeanPool.AxQM.Core.ProductStateCapacity +public import LeanPool.AxQM.Core.ProductStateAvgAchievable +public import LeanPool.AxQM.Postulates.API.TensorPowDim +public import LeanPool.AxQM.Postulates.API.MeasurementReindex +public import LeanPool.AxQM.NC.Ch12.Problem1 +public import LeanPool.AxQM.NC.Ch11.Subadditivity +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.Postulates.API.ArakiLiebEqualityConditions +public import LeanPool.AxQM.Postulates.PartialTraceTensor +public import LeanPool.AxQM.ToMathlib.InformationTheory.Fano + +/-! +# Extension of the HSW product-state capacity theorem to state maps + +Nielsen & Chuang's **Holevo–Schumacher–Westmoreland (HSW) theorem** (Theorem 12.8) states that the +Holevo χ quantity `χ(E)` of a trace-preserving quantum operation `E` equals its product-state +capacity `C⁽¹⁾(E)`. + +The Lean equality extends Theorem 12.8 to arbitrary state maps `E : State S → State S`. +`channelHolevoChi E` is the supremum of the Holevo χ of the output ensembles. +`productStateCapacity E` is the supremum of rates achievable using independent applications +of `E`, product-state inputs, and a joint decoder with vanishing maximum error. For a +quantum channel, `holevoChi_comp_eq_of_isChannel` identifies each output-ensemble value +with the per-ensemble expression in equation (12.71), which applies the channel to the +input mixture. + +The equality `channelHolevoChi_eq_productStateCapacity` follows by `le_antisymm`. The file +proves the converse `C⁽¹⁾(E) ≤ χ(E)` and then assembles the +random-coding **achievability** `χ(E) ≤ C⁽¹⁾(E)` from the development in `AxQM/Core/` +(`isProductStateAvgAchievableRate_of_lt_channelHolevoChi`). +In N&C's converse +(eqs. (12.96)–(12.102)) the accessible information `H(M:Y)` that Bob's decoding measurement extracts +about Alice's message is controlled via the Holevo bound, the **subadditivity of the von Neumann +entropy**, and the upper-bound property of the ensemble supremum `χ(E)`: + +`H(M:Y) ≤ χ({p_M, σ_M}) ≤ ∑ⱼ χ({p_M, σ_Mⱼ}) ≤ n·χ(E)` (N&C eqs. (12.99)–(12.101)), + +where `σ_M = σ_{M₁} ⊗ ⋯ ⊗ σ_{Mₙ}` is the memoryless product output of a length-`n` codeword. + +## What this file provides + +* `AxQM.mutualInfo_channelOutput_le_channelHolevoChi` — the **single-use bound** for a state + map `E`. The classical mutual information between the input label and the decoding + outcome is at most `χ(E)` by the Holevo bound and `le_channelHolevoChi`. For a quantum + channel this gives the bound from N&C eq. (12.99) with the per-ensemble expression of + eq. (12.71). + +* `AxQM.State.holevoChi_tmul_le` — the **subadditivity of the Holevo χ quantity over + product ensembles** (the reusable content of eq. (12.99)→(12.100)): for an ensemble `{pₓ, ρₓ⊗σₓ}` + of *product* states on `S ⊗ T`, + + `χ({pₓ, ρₓ⊗σₓ}) ≤ χ({pₓ, ρₓ}) + χ({pₓ, σₓ})`. + + This is the bipartite (`n = 2`) case of the single-letterisation collapse, and the inductive + ingredient for its `n`-fold generalisation. It rests on the subadditivity of the von + Neumann entropy (`State.vonNeumannEntropy_le_reducedLeft_add_reducedRight`, N&C §11.3.4) together + with the additivity of entropy over products (`State.vonNeumannEntropy_tmul`). + +* `AxQM.mutualInfo_channelOutput_tmul_le_two_mul_channelHolevoChi` — the **two-use channel + single-letterisation** (the `n = 2` instance of eq. (12.101)): for a two-letter product-state code + with inputs `ρₓ`, `σₓ` and any joint decoding measurement `m` on the two-use output `S ⊗ S`, + + `H(X:Y) ≤ 2·χ(E)`. + + Composes the single-use ingredients — the Holevo bound `holevoBound_of_chi_monotone`, the + χ-subadditivity `State.holevoChi_tmul_le`, and `le_channelHolevoChi` applied to each of the two + output marginal ensembles — exactly as N&C's eqs. (12.99)–(12.101) do at `n = 2`. + +* `AxQM.State.holevoChi_piTensor_le` — the **`n`-fold subadditivity of the Holevo χ over + product ensembles** (eq. (12.100), general `n`): `χ({pₓ, ⨂ⱼ ρₓⱼ}) ≤ ∑ⱼ χ({pₓ, ρₓⱼ})`. The + `n`-factor generalisation of `State.holevoChi_tmul_le`, proved by induction on the number of + tensor factors via the `State.piTensor` head-peel recursion + (`State.tmul_piTensor_congr_tensorPowSuccHead_symm`, `AxQM/Core/PiTensorSuccHead.lean`). + +* `AxQM.mutualInfo_channelOutput_piTensor_le_nsmul_channelHolevoChi` — the **full `n`-use + channel single-letterisation** (eqs. (12.99)–(12.101), general `n`): for a length-`n` + product-state code with memoryless output `⨂ⱼ E(ρ_{X,j})` and *any* joint decoding measurement `m` + on `S ^⊗ₛ n`, + + `H(X:Y) ≤ n·χ(E)`. + + Of this, `mutualInfo_channelOutput_tmul_le_two_mul_channelHolevoChi` is the `n = 2` instance. It + is the accessible-information ceiling underlying the operational converse `C⁽¹⁾(E) ≤ χ(E)`. + +* `AxQM.one_sub_maxError_mul_log_card_le_log_two_add_nsmul_channelHolevoChi` — the + **per-block converse inequality** (eqs. (12.97)–(12.101)): for a length-`n` product-state code `c` + with `K ≥ 1` messages, + + `(1 − p_bar)·log K ≤ log 2 + n·χ(E)`, + + where `p_bar = c.maxError`. This is the accessible-information ceiling of the previous bullet, + now + closed against the code's operational error via **classical Fano** — it forms the joint law of a + uniform message and Bob's decoding outcome (whose `Option (Fin K)` outcomes are relabelled to + `Fin (K + 1)` by `Measurement.reindexOutcome`), applies the single-letterisation and Fano's + uniform-input converse `Real.one_sub_fanoErrorProb_mul_log_card_le`, then bounds the Fano error + by `p_bar`. + +* `AxQM.IsProductStateAchievableRate.le_channelHolevoChi` — **every achievable rate is at + most `χ(E)`**: if a rate `R` (nats/use) is achievable, then `R ≤ χ(E)`. The short limiting + argument on the per-block bound: for `n ≥ 1`, `log Kₙ ≥ nR` and `1 − maxErrorₙ ≥ 0` turn the + per-block inequality into `(1 − maxErrorₙ)·R ≤ (log 2)/n + χ(E)`, whose two sides tend to `R` and + `χ(E)` as `n → ∞`. + +* `AxQM.productStateCapacity_le_channelHolevoChi` — the **operational converse of the HSW + theorem** (eqs. (12.96)–(12.102)): `C⁽¹⁾(E) ≤ χ(E)`. The supremum of the achievable rates is + `≤ χ(E)` because each achievable rate is (previous bullet) and `χ(E) ≥ 0` (`Real.sSup_le`); no + `[Nonempty (State S)]` is needed (the empty case is `sSup ∅ = 0 ≤ χ(E)`). This closes the whole + converse direction of Theorem 12.8. + +* `AxQM.channelHolevoChi_le_productStateCapacity` — the **achievability direction** + `χ(E) ≤ C⁽¹⁾(E)` (N&C Box 12.5): the operational payoff of the random-coding development in + `AxQM/Core/`. + For any `R < χ(E)`, `isProductStateAvgAchievableRate_of_lt_channelHolevoChi` makes `R` + average-achievable, the expurgation bridge + `IsProductStateAvgAchievableRate.isProductStateAchievableRate_of_lt` makes every `R' < R` + achievable, and `le_productStateCapacity` gives `R' ≤ C⁽¹⁾(E)`; two nested + `le_of_forall_lt_imp_le_of_dense` (over `R'` then `R`) bridge the two strict inequalities and pass + to the supremum. + +* `AxQM.channelHolevoChi_eq_productStateCapacity` — the **state-map extension of HSW**, + `χ(E) = C⁽¹⁾(E)` (the headline top-level claim of §12.3): `le_antisymm` of the converse + `productStateCapacity_le_channelHolevoChi` with the achievability + `channelHolevoChi_le_productStateCapacity`. + +The channel `E` enters only as an arbitrary state-map `State S → State S`. The proofs use the +Holevo bound `holevoBound_of_chi_monotone` (`LeanPool/AxQM/NC/Ch12/Problem1.lean`) and the entropy +subadditivity `State.vonNeumannEntropy_le_reducedLeft_add_reducedRight` +(`AxQM/NC/Ch11/Subadditivity.lean`). +-/ + +@[expose] public section + +open scoped BigOperators Topology + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- The mutual information between an input label and the measurement outcome after a +single use of a state map `E` is at most `channelHolevoChi E`. The Holevo bound controls +the mutual information by the Holevo χ of the output ensemble, and `le_channelHolevoChi` +bounds that value by the supremum. For a quantum channel, `holevoChi_comp_eq_of_isChannel` +gives the expression in Nielsen & Chuang eq. (12.71) for each ensemble, as used in the +single-use step of the HSW converse (eq. (12.99)). -/ +theorem mutualInfo_channelOutput_le_channelHolevoChi (E : State S → State S) {n r : ℕ} [NeZero r] + (p : Fin n → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) (ρ : Fin n → State S) + (m : Measurement (Fin r) S) : + (Real.mutualInfo fun xy => p xy.1 * m.bornProb (E (ρ xy.1)) xy.2) ≤ channelHolevoChi E := + le_trans (holevoBound_of_chi_monotone p hp hsum (fun i => E (ρ i)) m) + (le_channelHolevoChi E p hp hsum ρ) + +/-- **Subadditivity of the Holevo χ quantity over product ensembles** (Nielsen & Chuang, +Theorem 12.8, the content of eqs. (12.99)→(12.100)). For an ensemble `{pₓ, ρₓ ⊗ σₓ}` whose states +are *products* on a bipartite system `S ⊗ T`, the Holevo χ is subadditive over the two factors: + +`χ({pₓ, ρₓ ⊗ σₓ}) ≤ χ({pₓ, ρₓ}) + χ({pₓ, σₓ})`. + +This is the bipartite (`n = 2`) case of the single-letterisation collapse that turns the χ of a +memoryless product-output ensemble into a per-use sum, and the inductive step for its `n`-fold +generalisation. + +The proof is the ensemble form of the entropy-subadditivity argument. Write +`ω = ∑ₓ pₓ (ρₓ ⊗ σₓ)` for the ensemble mixture. Its marginals are the factor-wise mixtures, +`ω_S = ∑ₓ pₓ ρₓ` and `ω_T = ∑ₓ pₓ σₓ` (partial trace commutes with mixing, +`State.reducedLeft_mix`/`State.reducedRight_mix`, and kills the opposite factor of a product, +`State.reducedLeft_tmul`/`State.reducedRight_tmul`). Subadditivity of the von Neumann entropy +(`State.vonNeumannEntropy_le_reducedLeft_add_reducedRight`, N&C §11.3.4) gives +`S(ω) ≤ S(ω_S) + S(ω_T)`; additivity of entropy over each product component +(`State.vonNeumannEntropy_tmul`) gives `S(ρₓ ⊗ σₓ) = S(ρₓ) + S(σₓ)`, so the average-component term +splits. Subtracting, the two χ's separate. -/ +theorem State.holevoChi_tmul_le {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) (σ : ι → State T) : + State.holevoChi p hp hsum (fun i => (ρ i).tmul (σ i)) ≤ + State.holevoChi p hp hsum ρ + State.holevoChi p hp hsum σ := by + simp only [State.holevoChi_def] + -- the two factor marginals of the product-ensemble mixture are the factor-wise mixtures + have hL : (State.mix p hp hsum fun i => (ρ i).tmul (σ i)).reducedLeft + = State.mix p hp hsum ρ := by + rw [State.reducedLeft_mix]; simp only [State.reducedLeft_tmul] + have hR : + (State.mix p hp hsum fun i => (ρ i).tmul (σ i)).reducedRight = State.mix p hp hsum σ := by + rw [State.reducedRight_mix]; simp only [State.reducedRight_tmul] + -- subadditivity of the von Neumann entropy of the mixture, read off through the marginals + have hsub : (State.mix p hp hsum fun i => (ρ i).tmul (σ i)).vonNeumannEntropy ≤ + (State.mix p hp hsum ρ).vonNeumannEntropy + (State.mix p hp hsum σ).vonNeumannEntropy := by + have h := State.vonNeumannEntropy_le_reducedLeft_add_reducedRight + (State.mix p hp hsum fun i => (ρ i).tmul (σ i)) + rwa [hL, hR] at h + -- the average component entropy splits over each product state + have hcomp : ∑ i, p i * ((ρ i).tmul (σ i)).vonNeumannEntropy = + ∑ i, p i * (ρ i).vonNeumannEntropy + ∑ i, p i * (σ i).vonNeumannEntropy := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i _ => by rw [State.vonNeumannEntropy_tmul]; ring + rw [hcomp] + linarith [hsub] + +/-- **The two-use channel single-letterisation of the HSW converse** (Nielsen & Chuang, +Theorem 12.8, the `n = 2` instance of eqs. (12.99)–(12.101)). Alice sends a two-letter codeword: to +label `X` she assigns the product input `ρ_X ⊗ σ_X` (each factor a single-use input to the channel +`E`), so the two-use output is `E(ρ_X) ⊗ E(σ_X)`. Bob applies any joint decoding measurement `m` on +the two-use output system `S ⊗ S`. Then the classical mutual information between `X` and Bob's +outcome `Y` is at most twice the channel Holevo χ quantity: + +`H(X:Y) ≤ 2·χ(E)`. + +Composes the three single-use ingredients exactly as N&C's derivation does at `n = 2`: + +* the **Holevo bound** `holevoBound_of_chi_monotone` bounds `H(X:Y)` by the Holevo χ of the two-use + output ensemble `{pₓ, E(ρₓ) ⊗ E(σₓ)}` (eq. (12.99)); +* **subadditivity of χ over products** `State.holevoChi_tmul_le` splits that into the sum of the two + marginal-ensemble χ's `χ({pₓ, E(ρₓ)}) + χ({pₓ, E(σₓ)})` (eq. (12.100)); and +* the **maximisation property** `le_channelHolevoChi` bounds each marginal-ensemble χ by `χ(E)` + (eq. (12.101)). + +This is the bipartite (`n = 2`) instance of the converse single-letterisation; the general `n`-use +bound `H(X:Y) ≤ n·χ(E)` is proved below as +`mutualInfo_channelOutput_piTensor_le_nsmul_channelHolevoChi`, via the `n`-fold χ-subadditivity +`State.holevoChi_piTensor_le`. -/ +theorem mutualInfo_channelOutput_tmul_le_two_mul_channelHolevoChi (E : State S → State S) + {n r : ℕ} [NeZero r] (p : Fin n → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) + (ρ σ : Fin n → State S) (m : Measurement (Fin r) (S ⊗ S)) : + (Real.mutualInfo fun xy => p xy.1 * m.bornProb ((E (ρ xy.1)).tmul (E (σ xy.1))) xy.2) ≤ + 2 * channelHolevoChi E := by + refine (holevoBound_of_chi_monotone p hp hsum (fun x => (E (ρ x)).tmul (E (σ x))) m).trans ?_ + refine (State.holevoChi_tmul_le p hp hsum (fun x => E (ρ x)) (fun x => E (σ x))).trans ?_ + have hL := le_channelHolevoChi E p hp hsum ρ + have hR := le_channelHolevoChi E p hp hsum σ + linarith + +/-- **`n`-fold subadditivity of the Holevo χ quantity over product ensembles** (Nielsen & Chuang, +Theorem 12.8, the general form of eqs. (12.99)→(12.100)). For an ensemble `{pₓ, ⨂ⱼ ρₓⱼ}` whose +states are `n`-fold *products* on `S ^⊗ₛ n`, the Holevo χ is subadditive over the `n` factors: + +`χ({pₓ, ⨂ⱼ ρₓⱼ}) ≤ ∑ⱼ χ({pₓ, ρₓⱼ})`. + +The `n`-factor generalisation of the bipartite `State.holevoChi_tmul_le`, proved by induction on the +number of factors: the head-peel recursion `State.tmul_piTensor_congr_tensorPowSuccHead_symm` +rewrites `⨂ⱼ ρₓⱼ` as the transport of `(ρₓ 0) ⊗ (⨂ⱼ ρₓ,ⱼ₊₁)`, whose χ is bounded — via invariance +under system isomorphism (`State.holevoChi_congr`) and the bipartite subadditivity +(`State.holevoChi_tmul_le`) — by `χ({pₓ, ρₓ 0}) + χ({pₓ, ⨂ⱼ ρₓ,ⱼ₊₁})`, and the second summand is +controlled by the inductive hypothesis. The `n = 0` base is the trivial one-dimensional system +`S ^⊗ₛ 0`, on which every state has zero von Neumann entropy, so `χ = 0`. -/ +theorem State.holevoChi_piTensor_le {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) : + ∀ {n : ℕ} (ρ : ι → Fin n → State S), + State.holevoChi p hp hsum (fun x => State.piTensor fun j => ρ x j) ≤ + ∑ j, State.holevoChi p hp hsum fun x => ρ x j + | 0, ρ => by + -- `S ^⊗ₛ 0` is one-dimensional: every state has zero entropy, so `χ = 0 ≤ 0`. + have hz : ∀ σ : State (S ^⊗ₛ 0), σ.vonNeumannEntropy = 0 := by + intro σ + have h := σ.vonNeumannEntropy_le_log_finrank + rw [QSystem.finrank_tensorPow_space, pow_zero, Nat.cast_one, Real.log_one] at h + exact le_antisymm h σ.vonNeumannEntropy_nonneg + rw [State.holevoChi_of_forall_vonNeumannEntropy_zero p hp hsum + (fun x => State.piTensor fun j : Fin 0 => ρ x j) fun x => hz _, + Finset.univ_eq_empty, Finset.sum_empty] + exact (hz _).le + | n + 1, ρ => by + have heq : State.holevoChi p hp hsum (fun x => State.piTensor fun j : Fin (n + 1) => ρ x j) = + State.holevoChi p hp hsum + (fun x => (ρ x 0).tmul (State.piTensor fun j : Fin n => ρ x j.succ)) := by + rw [show (fun x => State.piTensor fun j : Fin (n + 1) => ρ x j) = + (fun x => State.congr (QSystem.tensorPowSuccHead S n).symm + ((ρ x 0).tmul (State.piTensor fun j : Fin n => ρ x j.succ))) from + funext fun x => (State.tmul_piTensor_congr_tensorPowSuccHead_symm (ρ x)).symm] + exact State.holevoChi_congr p hp hsum _ (QSystem.tensorPowSuccHead S n).symm + rw [heq, Fin.sum_univ_succ] + refine (State.holevoChi_tmul_le p hp hsum (fun x => ρ x 0) + (fun x => State.piTensor fun j : Fin n => ρ x j.succ)).trans ?_ + gcongr + exact State.holevoChi_piTensor_le p hp hsum fun x j => ρ x j.succ + +/-- **The `n`-use channel single-letterisation of the HSW converse** (Nielsen & Chuang, +Theorem 12.8, eqs. (12.99)–(12.101)). Alice sends an `n`-letter codeword: to label `X` she assigns +the product input `ρ_{X,0} ⊗ ⋯ ⊗ ρ_{X,n-1}` (each factor a single-use input to the channel `E`), so +the `n`-use output is the memoryless product `⨂ⱼ E(ρ_{X,j})`. Bob applies any joint decoding +measurement `m` on the `n`-use output system `S ^⊗ₛ n`. Then the classical mutual information +between `X` and Bob's outcome `Y` is at most `n` times the channel Holevo χ quantity: + +`H(X:Y) ≤ n·χ(E)`. + +This is the full converse single-letterisation, of which +`mutualInfo_channelOutput_tmul_le_two_mul_channelHolevoChi` was the `n = 2` instance. It composes +the three ingredients exactly as N&C's derivation does: the **Holevo bound** +`holevoBound_of_chi_monotone` (eq. (12.99)), the **`n`-fold subadditivity of χ over products** +`State.holevoChi_piTensor_le` (eq. (12.100)), and the **maximisation property** +`le_channelHolevoChi` applied to each of the `n` output marginal ensembles (eq. (12.101)). It is +the accessible-information ceiling on which the operational converse `C⁽¹⁾(E) ≤ χ(E)` rests, ready +to be combined with classical Fano's inequality over an `n`-use block code. -/ +theorem mutualInfo_channelOutput_piTensor_le_nsmul_channelHolevoChi (E : State S → State S) + {n K r : ℕ} [NeZero r] (p : Fin K → ℝ) (hp : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) + (ρ : Fin K → Fin n → State S) (m : Measurement (Fin r) (S ^⊗ₛ n)) : + (Real.mutualInfo fun xy => p xy.1 * m.bornProb (State.piTensor fun j => E (ρ xy.1 j)) xy.2) ≤ + n * channelHolevoChi E := by + refine (holevoBound_of_chi_monotone p hp hsum + (fun x => State.piTensor fun j => E (ρ x j)) m).trans ?_ + refine (State.holevoChi_piTensor_le p hp hsum fun x j => E (ρ x j)).trans ?_ + calc ∑ _j : Fin n, State.holevoChi p hp hsum (fun x => E (ρ x _j)) + ≤ ∑ _j : Fin n, channelHolevoChi E := + Finset.sum_le_sum fun j _ => le_channelHolevoChi E p hp hsum fun x => ρ x j + _ = n * channelHolevoChi E := by + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + +/-- **The per-block converse inequality of the HSW theorem** (Nielsen & Chuang, eqs. +(12.97)–(12.101)). For a length-`n` product-state code `c` with `K ≥ 1` messages on the memoryless +channel `E`, the reliably conveyable block rate `log K` is controlled by the accessible information +the channel provides over the `n` uses: + +`(1 − p_bar)·log K ≤ log 2 + n·χ(E)`, + +stated here with the maximum error `p_bar = maxError` (average error `≤ maxError`, so the bound with +the average error holds a fortiori). This is a single block of the operational converse +`C⁽¹⁾(E) ≤ χ(E)`: combined with `log K ≥ nR` and `maxErrorₙ → 0` for an achievable rate `R`, +dividing by `n` and letting `n → ∞` yields `R ≤ χ(E)` (the remaining, separate step). + +The proof forms the joint distribution of a uniformly random message `M` and Bob's decoding outcome +`Y`, `P(M, Y) = (1/K)·Tr(σ_M E_Y)`. Bob's decoder has `Option (Fin K)` outcomes (the `K` messages +plus the inconclusive element `E₀`); relabelling them to `Fin (K + 1)` via +`Measurement.reindexOutcome` along `finSuccEquiv` lets the two ingredients apply to the same law: + +* the **`n`-use single-letterisation** `mutualInfo_channelOutput_piTensor_le_nsmul_channelHolevoChi` + bounds the classical mutual information `H(M : Y) ≤ n·χ(E)`; +* **Fano's converse for a uniform input** `Real.one_sub_fanoErrorProb_mul_log_card_le` gives + `(1 − pₑ)·log K ≤ log 2 + H(M : Y)`, where `pₑ` is the Fano error probability of the guess + `Y_hat ↦ (message the decoder announces)`. + +Finally `pₑ ≤ p_av ≤ maxError`: guessing the announced message errs at most as often as the code +does, since the correct-guess probability `(1/K)∑_M Tr(σ_M E_M) = 1 − p_av` only grows when the +inconclusive branch carries mass. As `log K ≥ 0`, the maximum-error form follows. -/ +theorem one_sub_maxError_mul_log_card_le_log_two_add_nsmul_channelHolevoChi + (E : State S → State S) {n K : ℕ} [NeZero K] (c : ProductStateCode E n K) : + (1 - c.maxError) * Real.log K ≤ Real.log 2 + n * channelHolevoChi E := by + classical + have hK0 : (K : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne K) + have hK1 : (1 : ℝ) ≤ (K : ℝ) := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne K) + -- The relabelled decoder, with its `Option (Fin K)` outcomes carried to `Fin (K + 1)`. + set d : Measurement (Fin (K + 1)) (S ^⊗ₛ n) := c.decoder.reindexOutcome (finSuccEquiv K) with hd + -- The joint law of the uniform message `M` and the decoding outcome `Y`. + set P : Fin K × Fin (K + 1) → ℝ := + fun xy => (K : ℝ)⁻¹ * d.bornProb (c.outputCodeword xy.1) xy.2 with hP + have hPnn : ∀ q, 0 ≤ P q := by + intro q; simp only [hP]; exact mul_nonneg (by positivity) (d.bornProb_nonneg _ _) + -- Each message row of the joint law carries the uniform mass `1/K`. + have hmarg : ∀ x : Fin K, ∑ y, P (x, y) = (K : ℝ)⁻¹ := by + intro x + simp only [hP] + rw [← Finset.mul_sum, d.sum_bornProb_eq_one, mul_one] + have hPsum : ∑ q, P q = 1 := by + rw [Fintype.sum_prod_type] + simp_rw [hmarg] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_inv_cancel₀ hK0] + have hPuniform : ∀ i, Real.marginalFst P i = (Fintype.card (Fin K) : ℝ)⁻¹ := fun i => by + rw [Real.marginalFst_apply, Fintype.card_fin]; exact hmarg i + -- Single-letterisation: `H(M : Y) ≤ n·χ(E)`. + have hsl : Real.mutualInfo P ≤ (n : ℝ) * channelHolevoChi E := by + have hpu : ∀ _x : Fin K, (0 : ℝ) ≤ (K : ℝ)⁻¹ := fun _ => by positivity + have hsu : ∑ _x : Fin K, (K : ℝ)⁻¹ = 1 := by + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_inv_cancel₀ hK0] + have h := mutualInfo_channelOutput_piTensor_le_nsmul_channelHolevoChi + E (fun _ => (K : ℝ)⁻¹) hpu hsu c.encoder d + simpa only [hP, ProductStateCode.outputCodeword] using h + -- The guess: read off the message the decoder announces (`none` guesses an arbitrary message). + set z : Fin K := ⟨0, Nat.pos_of_ne_zero (NeZero.ne K)⟩ with hz + set g : Fin (K + 1) → Fin K := fun j => ((finSuccEquiv K) j).getD z with hg + -- Fano error probability `≤` average `≤` maximum error probability. + have hfano_le : Real.fanoErrorProb P g ≤ c.avgError := by + have hstep : ∑ j, P (g j, j) + = (K : ℝ)⁻¹ * c.decoder.bornProb (c.outputCodeword z) none + + ∑ m, (K : ℝ)⁻¹ * c.successProb m := by + simp only [hP, hg, hd, Measurement.reindexOutcome_bornProb] + rw [Fintype.sum_equiv (finSuccEquiv K) + (fun j => (K : ℝ)⁻¹ * + c.decoder.bornProb (c.outputCodeword (((finSuccEquiv K) j).getD z)) + ((finSuccEquiv K) j)) + (fun y => (K : ℝ)⁻¹ * c.decoder.bornProb (c.outputCodeword (y.getD z)) y) + (fun j => rfl), + Fintype.sum_option] + simp only [Option.getD_none, Option.getD_some, ProductStateCode.successProb] + have hsucc : ∑ m, (K : ℝ)⁻¹ * c.successProb m = 1 - c.avgError := by + have hse : ∀ m, c.successProb m = 1 - c.errorProb m := fun m => by + rw [ProductStateCode.errorProb]; ring + simp_rw [hse, mul_sub, mul_one, Finset.sum_sub_distrib] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_inv_cancel₀ hK0, + ← Finset.mul_sum, ProductStateCode.avgError, div_eq_inv_mul] + have hnn : 0 ≤ (K : ℝ)⁻¹ * c.decoder.bornProb (c.outputCodeword z) none := + mul_nonneg (by positivity) (c.decoder.bornProb_nonneg _ _) + rw [Real.fanoErrorProb, hstep, hsucc] + linarith + -- Fano's converse for the uniform message, and the assembly. + have hfano := Real.one_sub_fanoErrorProb_mul_log_card_le hPnn hPsum hPuniform g + rw [Fintype.card_fin] at hfano + have hlogK : 0 ≤ Real.log K := Real.log_nonneg hK1 + have hmono : (1 - c.maxError) * Real.log K ≤ (1 - Real.fanoErrorProb P g) * Real.log K := + mul_le_mul_of_nonneg_right (by linarith [c.avgError_le_maxError]) hlogK + linarith [hfano, hsl] + +/-- **Every achievable rate is at most `χ(E)`** — the analytic core of the HSW converse (Nielsen & +Chuang, eqs. (12.97)–(12.102)). If a rate `R` (in nats per channel use) is achievable for the +memoryless channel `E` — i.e. there is a family of product-state codes +`codeₙ : ProductStateCode E n ⌈eⁿᴿ⌉₊` with `maxErrorₙ → 0` — then `R ≤ χ(E)`. + +This is the short limiting argument sitting on top of the finite-block converse bound +`one_sub_maxError_mul_log_card_le_log_two_add_nsmul_channelHolevoChi`. For each block length +`n ≥ 1` the code has `Kₙ = ⌈eⁿᴿ⌉₊ ≥ 1` messages, so `log Kₙ ≥ n·R` (as `Kₙ ≥ eⁿᴿ`). Since +`1 − maxErrorₙ ≥ 0`, the per-block inequality gives + +`(1 − maxErrorₙ)·(n·R) ≤ (1 − maxErrorₙ)·log Kₙ ≤ log 2 + n·χ(E)`, + +and dividing by `n`, + +`(1 − maxErrorₙ)·R ≤ (log 2)/n + χ(E)`. + +As `n → ∞` the left side tends to `R` (because `maxErrorₙ → 0`) and the right side to `χ(E)` +(because `(log 2)/n → 0`), whence `R ≤ χ(E)` by comparison of limits. -/ +theorem IsProductStateAchievableRate.le_channelHolevoChi {E : State S → State S} {R : ℝ} + (hR : IsProductStateAchievableRate E R) : R ≤ channelHolevoChi E := by + obtain ⟨code, hcode⟩ := hR + -- The message count `Kₙ = ⌈eⁿᴿ⌉₊` is positive (`Kₙ ≥ 1`), supplying `[NeZero Kₙ]`. + have hKpos : ∀ n : ℕ, 0 < ⌈Real.exp ((n : ℝ) * R)⌉₊ := + fun n => Nat.ceil_pos.mpr (Real.exp_pos _) + -- The per-block inequality, divided by `n`, holds eventually in `n`. + have hab : ∀ᶠ n : ℕ in Filter.atTop, + (1 - (code n).maxError) * R ≤ Real.log 2 / (n : ℝ) + channelHolevoChi E := by + rw [Filter.eventually_atTop] + refine ⟨1, fun n hn => ?_⟩ + have : NeZero ⌈Real.exp ((n : ℝ) * R)⌉₊ := ⟨(hKpos n).ne'⟩ + have hnpos : (0 : ℝ) < n := by exact_mod_cast hn + have hn0 : (n : ℝ) ≠ 0 := ne_of_gt hnpos + -- `log Kₙ ≥ n·R`, from `eⁿᴿ ≤ Kₙ`. + have hKR : (0 : ℝ) < (⌈Real.exp ((n : ℝ) * R)⌉₊ : ℝ) := by exact_mod_cast hKpos n + have hlogK : (n : ℝ) * R ≤ Real.log (⌈Real.exp ((n : ℝ) * R)⌉₊ : ℝ) := + (Real.le_log_iff_exp_le hKR).mpr (Nat.le_ceil _) + -- The finite-block converse bound, and `1 − maxErrorₙ ≥ 0`. + have hblock := one_sub_maxError_mul_log_card_le_log_two_add_nsmul_channelHolevoChi E (code n) + have hmax1 : (code n).maxError ≤ 1 := (code n).maxError_le_one + have hstep : (1 - (code n).maxError) * ((n : ℝ) * R) + ≤ Real.log 2 + (n : ℝ) * channelHolevoChi E := + (mul_le_mul_of_nonneg_left hlogK (by linarith)).trans hblock + -- Divide by `n > 0`. + refine le_of_mul_le_mul_right ?_ hnpos + have eL : (1 - (code n).maxError) * R * (n : ℝ) + = (1 - (code n).maxError) * ((n : ℝ) * R) := by ring + have eR : (Real.log 2 / (n : ℝ) + channelHolevoChi E) * (n : ℝ) + = Real.log 2 + (n : ℝ) * channelHolevoChi E := by field_simp + rw [eL, eR]; exact hstep + -- Comparison of the two limits. + have hlimL : Filter.Tendsto (fun n : ℕ => (1 - (code n).maxError) * R) Filter.atTop (𝓝 R) := by + have h1 : Filter.Tendsto (fun n : ℕ => 1 - (code n).maxError) Filter.atTop (𝓝 1) := by + simpa using Filter.Tendsto.const_sub (1 : ℝ) hcode + simpa using h1.mul_const R + have hlimR : Filter.Tendsto (fun n : ℕ => Real.log 2 / (n : ℝ) + channelHolevoChi E) + Filter.atTop (𝓝 (channelHolevoChi E)) := by + have h0 : Filter.Tendsto (fun n : ℕ => Real.log 2 / (n : ℝ)) Filter.atTop (𝓝 0) := + tendsto_const_div_atTop_nhds_zero_nat (Real.log 2) + simpa using h0.add_const (channelHolevoChi E) + exact le_of_tendsto_of_tendsto hlimL hlimR hab + +/-- **The operational converse of the HSW theorem**, `C⁽¹⁾(E) ≤ χ(E)` (Nielsen & Chuang, +Theorem 12.8, eqs. (12.96)–(12.102)). The product-state capacity of any memoryless channel `E` is +at most its channel Holevo χ quantity: no product-state code family can reliably carry more than +`χ(E)` nats per channel use. + +Immediate from `IsProductStateAchievableRate.le_channelHolevoChi`: every achievable rate is +`≤ χ(E)`, and `χ(E) ≥ 0` (`channelHolevoChi_nonneg`), so their supremum — which is `C⁽¹⁾(E)` by +definition — is `≤ χ(E)` (`Real.sSup_le`, which also covers the degenerate empty case +`sSup ∅ = 0 ≤ χ(E)`, so no `[Nonempty (State S)]` hypothesis is needed). + +Together with the achievability direction `χ(E) ≤ C⁽¹⁾(E)` (random coding, N&C Box 12.5) — +`channelHolevoChi_le_productStateCapacity` below — this gives the HSW equality `χ(E) = C⁽¹⁾(E)`, +assembled by `le_antisymm` as `channelHolevoChi_eq_productStateCapacity` (both proved below in this +file). -/ +theorem productStateCapacity_le_channelHolevoChi (E : State S → State S) : + productStateCapacity E ≤ channelHolevoChi E := + Real.sSup_le (fun _ hR => IsProductStateAchievableRate.le_channelHolevoChi hR) + (channelHolevoChi_nonneg E) + +/-- **The achievability direction of the HSW theorem**, `χ(E) ≤ C⁽¹⁾(E)` (Nielsen & Chuang, +Theorem 12.8, the random-coding half, Box 12.5). The channel Holevo χ quantity of any memoryless +channel `E` is at most its product-state capacity: rates arbitrarily close to `χ(E)` nats per +channel use are achievable with product-state codes. + +This is the operational payoff of the whole random-coding development +(`isProductStateAvgAchievableRate_of_lt_channelHolevoChi`, N&C eqs. (12.72)–(12.83)). Fixing any +rate `R < χ(E)`, and any strictly smaller `R' < R`: + +* `R < χ(E)` makes `R` **average-achievable** + (`isProductStateAvgAchievableRate_of_lt_channelHolevoChi`): a random product-state codebook has + expected per-block error tending to `0`, so some codebook family realises rate `R` with + `avgError → 0`; +* the average→maximum error bridge + (`IsProductStateAvgAchievableRate.isProductStateAchievableRate_of_lt`, expurgation + truncation) + then makes every strictly smaller `R' < R` **achievable** (`maxError → 0`); +* hence `R' ≤ C⁽¹⁾(E)` by the upper bound `le_productStateCapacity`. + +`R'` was an arbitrary rate below `R`, so `R ≤ C⁽¹⁾(E)` (`le_of_forall_lt_imp_le_of_dense`, `ℝ` +densely ordered); and `R` was an arbitrary rate below `χ(E)`, so `χ(E) ≤ C⁽¹⁾(E)` by the same +denseness lemma. The two nested applications bridge the two strict +inequalities the random-coding argument leaves (average-achievability at `R`, achievability only +strictly below `R`). Needs `[Nonempty (State S)]` — the encoder must name an input state. -/ +theorem channelHolevoChi_le_productStateCapacity [Nonempty (State S)] (E : State S → State S) : + channelHolevoChi E ≤ productStateCapacity E := + le_of_forall_lt_imp_le_of_dense fun _ hR => + have hav := isProductStateAvgAchievableRate_of_lt_channelHolevoChi hR + le_of_forall_lt_imp_le_of_dense fun _ hR' => + le_productStateCapacity (hav.isProductStateAchievableRate_of_lt hR') + +/-- **Extension of the Holevo–Schumacher–Westmoreland theorem.** The output-ensemble Holevo +quantity of an arbitrary state map equals its capacity for independent uses and product-state +inputs. For quantum channels, `holevoChi_comp_eq_of_isChannel` identifies each ensemble summand +with Nielsen & Chuang's equation (12.71) in Theorem 12.8. + +The equality is + +`χ(E) = C⁽¹⁾(E)`. + +Capacity is the supremum of achievable rates for product-state inputs and joint decoding. +The proof combines the following bounds. + +* the operational **converse** `C⁽¹⁾(E) ≤ χ(E)` (`productStateCapacity_le_channelHolevoChi`, + eqs. (12.96)–(12.102): Holevo bound + subadditivity single-letterisation + Fano); and +* the random-coding **achievability** `χ(E) ≤ C⁽¹⁾(E)` + (`channelHolevoChi_le_productStateCapacity`, Box 12.5). + +Needs `[Nonempty (State S)]` for the achievability direction (the encoder must name an input state); +the converse holds with no such hypothesis. -/ +theorem channelHolevoChi_eq_productStateCapacity [Nonempty (State S)] (E : State S → State S) : + channelHolevoChi E = productStateCapacity E := + le_antisymm (channelHolevoChi_le_productStateCapacity E) + (productStateCapacity_le_channelHolevoChi E) + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch2/Exercise74.lean b/LeanPool/AxQM/NC/Ch2/Exercise74.lean new file mode 100644 index 0000000000..8f56c3836e --- /dev/null +++ b/LeanPool/AxQM/NC/Ch2/Exercise74.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CompositeState +public import LeanPool.AxQM.Postulates.API.Purity +public import LeanPool.AxQM.Postulates.PartialTraceTensor + +/-! +# Nielsen & Chuang, Exercise 2.74 (reduced state of a pure product state) + +For product state |a>|b>, show reduced density operator of A is pure. + +The composite system is `A ⊗ B` and the joint state is the product pure state `ψ ⊗ φ` +(`PureState.tmul`), whose density operator is `|ψ ⊗ φ⟩⟨ψ ⊗ φ|` (`PureState.toState`). The +reduced density operator of `A` is the left marginal `ρᴬ = Tr_B(|ψ ⊗ φ⟩⟨ψ ⊗ φ|)` +(`State.reducedLeft`). The exercise asks to show `ρᴬ` is pure. + +The statement uses `State.reducedLeft` (partial trace, §2.4.3) and +`State.IsPure` (`AxQM/Postulates/API/Purity.lean`), and two shared results: + +* `PureState.toState_tmul` (`AxQM/Postulates/API/CompositeState.lean`) — the density operator of a + product pure state factorizes, `|ψ ⊗ φ⟩⟨ψ ⊗ φ| = |ψ⟩⟨ψ| ⊗ |φ⟩⟨φ|`. +* `State.reducedLeft_tmul` (`AxQM/Postulates/PartialTraceTensor.lean`) — the left marginal of a + product density state is its left factor, `Tr_B(ρ ⊗ σ) = ρ`. + +Chaining them computes the reduced state *explicitly* — `ρᴬ = |ψ⟩⟨ψ|`, exactly N&C's +`ρ = trB(ρ ⊗ σ) = ρ tr(σ) = ρ` (eq. 2.184) specialized to pure factors — which is manifestly +pure, discharging the exercise. (By contrast the Bell state, Ex 2.75, has a *mixed* reduced +state: entanglement, not a product, is what makes a subsystem mixed.) + +The main result is the explicit value `reducedLeft_toState_tmul`; the exercise's literal claim is +the corollary `isPure_reducedLeft_toState_tmul`. The symmetric **right-marginal** versions +`reducedRight_toState_tmul` / `isPure_reducedRight_toState_tmul` (`ρᴮ = |φ⟩⟨φ|`, via +`State.reducedRight_tmul`) are co-located here as the natural pair, reused by Exercise 2.78's +`product ↔ ρᴮ pure` equivalence. +-/ + +@[expose] public section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Nielsen & Chuang, Exercise 2.74 (explicit reduced state).** The reduced density operator +of system `A` for the product pure state `|ψ⟩|φ⟩` is exactly `|ψ⟩⟨ψ|`: +`Tr_B(|ψ ⊗ φ⟩⟨ψ ⊗ φ|) = |ψ⟩⟨ψ|`. Combines `PureState.toState_tmul` (factorization of the +product density operator) with `State.reducedLeft_tmul` (the left marginal of a product state +is its left factor). -/ +theorem reducedLeft_toState_tmul (ψ : PureState S) (φ : PureState T) : + ((ψ ⊗ φ).toState).reducedLeft = ψ.toState := by + rw [PureState.toState_tmul, State.reducedLeft_tmul] + +/-- **Nielsen & Chuang, Exercise 2.74.** The reduced density operator of system `A` alone, for a +composite in the product pure state `|ψ⟩|φ⟩`, is a pure state — namely `|ψ⟩⟨ψ|`, by +`reducedLeft_toState_tmul`. -/ +theorem isPure_reducedLeft_toState_tmul (ψ : PureState S) (φ : PureState T) : + ((ψ ⊗ φ).toState).reducedLeft.IsPure := + ⟨ψ, reducedLeft_toState_tmul ψ φ⟩ + +/-- **Right-marginal mirror.** The reduced density operator of system `B` for the product pure +state `|ψ⟩|φ⟩` is exactly `|φ⟩⟨φ|`: `Tr_A(|ψ ⊗ φ⟩⟨ψ ⊗ φ|) = |φ⟩⟨φ|`. Symmetric to +`reducedLeft_toState_tmul`, via `PureState.toState_tmul` and `State.reducedRight_tmul` (the right +marginal of a product density state is its right factor). -/ +theorem reducedRight_toState_tmul (ψ : PureState S) (φ : PureState T) : + ((ψ ⊗ φ).toState).reducedRight = φ.toState := by + rw [PureState.toState_tmul, State.reducedRight_tmul] + +/-- **Right-marginal mirror.** The reduced density operator of system `B` alone, for a composite in +the product pure state `|ψ⟩|φ⟩`, is a pure state — namely `|φ⟩⟨φ|`, by `reducedRight_toState_tmul`. +The `ρᴮ` companion of `isPure_reducedLeft_toState_tmul`. -/ +theorem isPure_reducedRight_toState_tmul (ψ : PureState S) (φ : PureState T) : + ((ψ ⊗ φ).toState).reducedRight.IsPure := + ⟨φ, reducedRight_toState_tmul ψ φ⟩ + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch2/Exercise78.lean b/LeanPool/AxQM/NC/Ch2/Exercise78.lean new file mode 100644 index 0000000000..6a55a19bda --- /dev/null +++ b/LeanPool/AxQM/NC/Ch2/Exercise78.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MatricizationRank +public import LeanPool.AxQM.Postulates.API.SchmidtNumber +public import LeanPool.AxQM.Postulates.API.CompositeState +public import LeanPool.AxQM.NC.Ch2.Problem2 +public import LeanPool.AxQM.NC.Ch2.Exercise74 + +/-! +# Nielsen & Chuang, Exercise 2.78 (product states, Schmidt number 1, and pure marginals) + +Prove |psi> is a product state iff Schmidt number 1 iff rho^A pure. + +The exercise establishes the equivalence, for a bipartite **pure** state `|ψ⟩`, of + +* `|ψ⟩` is a **product state** `|a⟩|b⟩`; +* `|ψ⟩` has **Schmidt number `1`** (a single non-zero Schmidt coefficient); +* the **reduced density operator `ρᴬ = tr_B(|ψ⟩⟨ψ|)` is pure**; +* the **reduced density operator `ρᴮ = tr_A(|ψ⟩⟨ψ|)` is pure** (the exercise's "and thus `ρᴮ`"). + +## Formalisation + +* `PureState.IsProduct` — the separability predicate `∃ a b, ψ = a ⊗ b`, phrased over + `PureState.tmul`, the tensor product of states, rather than via a vector-level + `ψ.vec = a ⊗ₜ b`. +* `PureState.isProduct_iff_schmidtNumber_eq_one` — `|ψ⟩` is a product state ↔ `Sch(ψ) = 1`. +* `PureState.isProduct_iff_isPure_reducedLeft` — `|ψ⟩` is a product state ↔ `ρᴬ` is pure. +* `PureState.isProduct_iff_isPure_reducedRight` — `|ψ⟩` is a product state ↔ `ρᴮ` is pure (the + exercise's parenthetical "and thus `ρᴮ`", formalised in full rather than left to symmetry). + +The exercise is assembled from the following results: + +* the marginal-of-a-product facts `isPure_reducedLeft_toState_tmul` / + `isPure_reducedRight_toState_tmul` (`ρᴬ = |a⟩⟨a|`, `ρᴮ = |b⟩⟨b|`) — + `LeanPool/AxQM/NC/Ch2/Exercise74.lean`; +* the Schmidt-number/rank bridges `schmidtNumber_eq_rank_reducedLeft` / + `schmidtNumber_eq_rank_reducedRight` (Problem 2.2(1) and its right mirror) — + `LeanPool/AxQM/NC/Ch2/Problem2.lean`; +* the general facts `one_le_schmidtNumber` (`Sch(ψ) ≥ 1`) and `State.rank_eq_one_of_isPure` + (a pure state has rank `1`) — `AxQM/Postulates/API/SchmidtNumber.lean`; +* the pure linear-algebra lemma `TensorProduct.exists_tmul_of_finrank_range_matricize_le_one` + (rank-`≤ 1` matricization ⇒ simple tensor) — + `ToMathlib/Analysis/InnerProductSpace/MatricizationRank.lean`. + +## Design and proof + +The equivalence pivots on the Schmidt number, through the bridges to both marginals +`Sch(ψ) = rank ρᴬ` (Problem 2.2(1)) and `Sch(ψ) = rank ρᴮ` (its right mirror). + +* **Product ↔ Schmidt number 1.** + *(→)* If `ψ = a ⊗ b` then `ψ.vec = a.vec ⊗ₜ b.vec` is a one-term product, so + `Sch(ψ) ≤ 1` (`schmidtNumber_le_card_of_sum_tmul`, Problem 2.2(2), over a singleton); with + `Sch(ψ) ≥ 1` (`one_le_schmidtNumber`) this forces `Sch(ψ) = 1`. + *(←)* If `Sch(ψ) = 1` then `matricize ψ.vec` is a rank-`≤ 1` operator, so + `ψ.vec = x ⊗ₜ y` is a simple tensor (`exists_tmul_of_finrank_range_matricize_le_one`). Since + `‖ψ.vec‖ = 1`, `‖x‖‖y‖ = 1`, so `x`, `y` are non-zero and their normalisations `a = x/‖x‖`, + `b = y/‖y‖` satisfy `ψ = a ⊗ b` (the two `‖·‖⁻¹` factors cancel against `‖x‖‖y‖ = 1`). + +* **Product ↔ `ρᴬ` pure** and **Product ↔ `ρᴮ` pure.** Both are symmetric. + *(→)* the marginals of a product pure state are `|a⟩⟨a|`, `|b⟩⟨b|` (Exercise 2.74 and its right + mirror). + *(←)* chains purity through the rank: `ρᴬ` (resp. `ρᴮ`) pure ⇒ `rank = 1` + (`State.rank_eq_one_of_isPure`) ⇒ `Sch(ψ) = 1` (`schmidtNumber_eq_rank_reducedLeft` / + `schmidtNumber_eq_rank_reducedRight`) ⇒ product. This routing avoids the harder spectral direction + `rank ρ = 1 ⇒ ρ` pure, which the exercise does not need. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- A bipartite pure state `|ψ⟩` of `S ⊗ T` is a **product state** when it factors as `|a⟩|b⟩` for +pure states `a` of `S` and `b` of `T` — i.e. `ψ = a ⊗ b` (`PureState.tmul`). -/ +def PureState.IsProduct (ψ : PureState (S ⊗ T)) : Prop := + ∃ (a : PureState S) (b : PureState T), ψ = a.tmul b + +/-- **Nielsen & Chuang, Exercise 2.78 (first equivalence).** A bipartite pure state `|ψ⟩` is a +product state if and only if it has Schmidt number `1`. Forward: a product `ψ.vec = a.vec ⊗ₜ b.vec` +is a single-term decomposition, so `Sch(ψ) ≤ 1`, and `Sch(ψ) ≥ 1` (`one_le_schmidtNumber`) gives +equality. Backward: `Sch(ψ) = 1` makes `matricize ψ.vec` rank-`≤ 1`, hence `ψ.vec` a simple tensor +`x ⊗ₜ y` (`exists_tmul_of_finrank_range_matricize_le_one`); normalising `x`, `y` (whose norms +multiply to `1`) yields the product factorisation. -/ +theorem PureState.isProduct_iff_schmidtNumber_eq_one (ψ : PureState (S ⊗ T)) : + ψ.IsProduct ↔ ψ.schmidtNumber = 1 := by + constructor + · rintro ⟨a, b, rfl⟩ + refine le_antisymm ?_ (a.tmul b).one_le_schmidtNumber + calc (a.tmul b).schmidtNumber + ≤ (Finset.univ : Finset Unit).card := + PureState.schmidtNumber_le_card_of_sum_tmul _ _ (fun _ => a.vec) (fun _ => b.vec) + (by simp only [PureState.tmul_vec, Finset.univ_unique, Finset.sum_singleton]; rfl) + _ = 1 := by simp + · intro h + set bT := stdOrthonormalBasis ℂ T.space with hbT + have hle : Module.finrank ℂ ↥(LinearMap.range + (TensorProduct.matricize bT (ψ.vec : S.space ⊗[ℂ] T.space)).toLinearMap) ≤ 1 := by + have hop : TensorProduct.matricize bT (ψ.vec : S.space ⊗[ℂ] T.space) = ψ.schmidtOp := by + rw [hbT]; rfl + rw [hop, ← ψ.schmidtNumber_eq_finrank_range_matricize] + exact h.le + obtain ⟨x, y, hxy⟩ := @TensorProduct.exists_tmul_of_finrank_range_matricize_le_one + ℂ S.space T.space _ _ _ _ _ _ _ _ (ψ.vec : S.space ⊗[ℂ] T.space) bT hle + have hnorm : ‖x‖ * ‖y‖ = 1 := by + rw [← TensorProduct.norm_tmul (𝕜 := ℂ) x y, ← hxy]; exact ψ.normalized + have hnx : x ≠ 0 := norm_ne_zero_iff.mp (left_ne_zero_of_mul_eq_one hnorm) + have hny : y ≠ 0 := norm_ne_zero_iff.mp (right_ne_zero_of_mul_eq_one hnorm) + have hc1 : (((‖x‖ : ℝ) : ℂ)⁻¹ * ((‖y‖ : ℝ) : ℂ)⁻¹) = 1 := by + rw [← mul_inv, ← Complex.ofReal_mul, hnorm, Complex.ofReal_one, inv_one] + refine ⟨PureState.normalize x hnx, PureState.normalize y hny, ?_⟩ + apply PureState.ext + rw [hxy, PureState.tmul_vec, PureState.normalize_vec, PureState.normalize_vec, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, smul_smul, hc1, one_smul] + +/-- **Nielsen & Chuang, Exercise 2.78 (second equivalence).** A bipartite pure state `|ψ⟩` is a +product state if and only if its reduced density operator `ρᴬ = tr_B(|ψ⟩⟨ψ|)` is pure. Forward is +Exercise 2.74 (the marginal of a product pure state is `|a⟩⟨a|`). Backward chains purity through the +rank: `ρᴬ` pure ⇒ `rank ρᴬ = 1` (`State.rank_eq_one_of_isPure`) ⇒ `Sch(ψ) = 1` +(`schmidtNumber_eq_rank_reducedLeft`) ⇒ product (the first equivalence). -/ +theorem PureState.isProduct_iff_isPure_reducedLeft (ψ : PureState (S ⊗ T)) : + ψ.IsProduct ↔ ψ.toState.reducedLeft.IsPure := by + constructor + · rintro ⟨a, b, rfl⟩ + exact isPure_reducedLeft_toState_tmul a b + · intro h + rw [ψ.isProduct_iff_schmidtNumber_eq_one, ψ.schmidtNumber_eq_rank_reducedLeft] + exact State.rank_eq_one_of_isPure h + +/-- **Nielsen & Chuang, Exercise 2.78 (second equivalence, `ρᴮ` form — the "and thus `ρᴮ`").** A +bipartite pure state `|ψ⟩` is a product state if and only if its reduced density operator +`ρᴮ = tr_A(|ψ⟩⟨ψ|)` is pure. Symmetric to `isProduct_iff_isPure_reducedLeft`: forward is +`isPure_reducedRight_toState_tmul` (Exercise 2.74's right mirror), backward chains `ρᴮ` pure ⇒ +`rank ρᴮ = 1` (`State.rank_eq_one_of_isPure`) ⇒ `Sch(ψ) = 1` (`schmidtNumber_eq_rank_reducedRight`) +⇒ product. -/ +theorem PureState.isProduct_iff_isPure_reducedRight (ψ : PureState (S ⊗ T)) : + ψ.IsProduct ↔ ψ.toState.reducedRight.IsPure := by + constructor + · rintro ⟨a, b, rfl⟩ + exact isPure_reducedRight_toState_tmul a b + · intro h + rw [ψ.isProduct_iff_schmidtNumber_eq_one, ψ.schmidtNumber_eq_rank_reducedRight] + exact State.rank_eq_one_of_isPure h + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch2/Problem2.lean b/LeanPool/AxQM/NC/Ch2/Problem2.lean new file mode 100644 index 0000000000..18315bdf92 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch2/Problem2.lean @@ -0,0 +1,100 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SchmidtNumber +public import LeanPool.AxQM.Postulates.API.SchmidtDecomposition + +/-! +# Nielsen & Chuang, Problem 2.2 (Properties of the Schmidt number) + +Properties of the Schmidt number: rank of rho^A, subadditivity over decompositions, +Sch(psi)>=|Sch(phi)-Sch(gamma)|. + +## Definitions + +The **definitions** — the Schmidt number `PureState.schmidtNumber` and the state rank +`State.rank` — are in `AxQM/Postulates/API/SchmidtNumber.lean`. The Schmidt number is defined there +as the number of non-zero singular values of the matricized coefficient operator +`M = matricize ψ.vec` (these singular values are the Schmidt coefficients `λᵢ` of +`|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩`). Defining it that way — rather than as the rank of `ρᴬ` — is what makes +**Part 1** a genuine theorem rather than a definitional tautology (a faithfulness requirement: +defining `Sch(ψ)` as `rank ρᴬ` would silently trivialise the problem). + +## Statements + +Part 1 is `PureState.schmidtNumber_eq_rank_reducedLeft` below. + +**Parts 2 and 3** have hypotheses that are equations between the underlying state vectors — a +product decomposition `ψ.vec = ∑ⱼ αⱼ ⊗ βⱼ` (Part 2) and a superposition +`ψ.vec = α • φ.vec + β • γ.vec` (Part 3). They are in `AxQM/Postulates/API/SchmidtNumber.lean`: + +* **Part 2** (number of product terms `≥ Sch(ψ)`) — `PureState.schmidtNumber_le_card_of_sum_tmul`: + if `ψ.vec = ∑ⱼ∈s αⱼ ⊗ βⱼ` then `Sch(ψ) ≤ s.card`. +* **Part 3** (`Sch(ψ) ≥ |Sch(φ) − Sch(γ)|` for `ψ = αφ + βγ`) — + `PureState.natAbs_sub_schmidtNumber_le`: if `ψ.vec = α • φ.vec + β • γ.vec` with `α, β ≠ 0` + then `|Sch(φ) − Sch(γ)| ≤ Sch(ψ)`. The nonzero amplitudes are a genuine correctness + hypothesis — the inequality is *false* for `α = 0` (`ψ = βγ` with `φ` maximally entangled and `γ` + a product state) — a faithful reading of N&C's tacit two-term superposition, not a weakening. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +variable {S T : QSystem} + +/-- **Problem 2.2(1).** The Schmidt number of a bipartite pure state `|ψ⟩` equals the +rank of its left reduced density operator `ρᴬ = tr_B(|ψ⟩⟨ψ|)`. + +The number of non-zero Schmidt coefficients (the singular values of the coefficient +operator `M = matricize ψ.vec`, by definition of `schmidtNumber`) equals `rank M` +(`schmidtNumber_eq_finrank_range_matricize`); and `ρᴬ = M Mᵀ` with `rank (M Mᵀ) = rank M` +(`rank_reducedLeft_toState_eq_finrank_range_matricize`). The statement is about +`schmidtNumber`, `reducedLeft`, and `rank`. -/ +theorem PureState.schmidtNumber_eq_rank_reducedLeft (ψ : PureState (S ⊗ T)) : + ψ.schmidtNumber = ψ.toState.reducedLeft.rank := + (ψ.schmidtNumber_eq_finrank_range_matricize).trans + (State.rank_reducedLeft_toState_eq_finrank_range_matricize ψ).symm + +/-- **Problem 2.2(1), right-hand mirror.** The Schmidt number of a bipartite pure state `|ψ⟩` also +equals the rank of its *right* reduced density operator `ρᴮ = tr_A(|ψ⟩⟨ψ|)` — both marginals share +the eigenvalues `λᵢ²`, so both have rank `Sch(ψ)`. Co-located with the left version +`schmidtNumber_eq_rank_reducedLeft`; reused by Exercise 2.78's `product ↔ ρᴮ pure` equivalence. + +Proof: from the Schmidt decomposition `|ψ⟩ = ∑ᵢ<ₙ λᵢ |iᴬ⟩|iᴮ⟩` (`exists_schmidt_decomposition`, +positive `λᵢ`, orthonormal Schmidt bases) both marginals diagonalise — `ρᴬ = ∑ᵢ λᵢ² |iᴬ⟩⟨iᴬ|` and +`ρᴮ = ∑ᵢ λᵢ² |iᴮ⟩⟨iᴮ|` (`partialTrace{Right,Left}_rankOne_eq_sum_rankOne_of_schmidt`) — so each has +rank `n` (`InnerProductSpace.finrank_range_sum_smul_rankOne_self`, the `λᵢ² ≠ 0`). With +`Sch(ψ) = rank ρᴬ = n` this gives `Sch(ψ) = rank ρᴮ`. The statement is about +`schmidtNumber`, `reducedRight`, and `rank`. -/ +theorem PureState.schmidtNumber_eq_rank_reducedRight (ψ : PureState (S ⊗ T)) : + ψ.schmidtNumber = ψ.toState.reducedRight.rank := by + obtain ⟨n, l, a, b, hpos, ha, hb, _, hdecomp⟩ := ψ.exists_schmidt_decomposition + have hcne : ∀ i, ((l i : ℂ)) ^ 2 ≠ 0 := fun i => + pow_ne_zero 2 (Complex.ofReal_ne_zero.mpr (ne_of_gt (hpos i))) + have hR : (ψ.toState.reducedRight.op : T.space →ₗ[ℂ] T.space) + = ∑ i, ((l i : ℂ)) ^ 2 • (InnerProductSpace.rankOne ℂ (b i) (b i)).toLinearMap := by + rw [State.reducedRight_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + exact LinearMap.partialTraceLeft_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ S.space) l a b (fun i j _ _ => orthonormal_iff_ite.mp ha i j) hdecomp + have hL : (ψ.toState.reducedLeft.op : S.space →ₗ[ℂ] S.space) + = ∑ i, ((l i : ℂ)) ^ 2 • (InnerProductSpace.rankOne ℂ (a i) (a i)).toLinearMap := by + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + exact LinearMap.partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ T.space) l a b hb hdecomp + have hrR : ψ.toState.reducedRight.rank = n := by + rw [State.rank, hR]; exact InnerProductSpace.finrank_range_sum_smul_rankOne_self b _ hb hcne + have hrL : ψ.toState.reducedLeft.rank = n := by + rw [State.rank, hL]; exact InnerProductSpace.finrank_range_sum_smul_rankOne_self a _ ha hcne + rw [ψ.schmidtNumber_eq_rank_reducedLeft, hrL, hrR] + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch2/Theorem5.lean b/LeanPool/AxQM/NC/Ch2/Theorem5.lean new file mode 100644 index 0000000000..a031df8931 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch2/Theorem5.lean @@ -0,0 +1,55 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Ensemble + +/-! +# Nielsen & Chuang, Theorem 2.5 (Characterization of density operators) + +Characterization of density operators: rho is a density operator iff trace one and positive. + +The theorem characterizes exactly which operators are quantum states. + +A `State S` is by definition a positive operator of trace one (Postulate 1 in the density-operator +formulation), so the conditions on a density operator are already part of the notion of state. +Theorem 2.5 is therefore the statement that the map from ensembles to states, +`Ensemble.toState : Ensemble S → State S`, sending an ensemble `{pᵢ, |ψᵢ⟩}` to its density operator +`∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|`, is **surjective**: + +* that `Ensemble.toState` lands in `State S` at all is the **forward** direction — every ensemble's + density operator satisfies the trace and positivity conditions; +* its **surjectivity** is the **converse** — every trace-one positive operator arises from an + ensemble (its eigenensemble, via the spectral decomposition, N&C eq. (2.157)). + +The `Ensemble` structure, the density-operator map `Ensemble.toState`, the eigenensemble +construction `Ensemble.ofState`, and the round-trip `Ensemble.ofState_toState` are in +`AxQM/Postulates/API/Ensemble.lean`. The operator-level biconditional "density operator iff trace +one and positive" is `AxQM.isDensityOp_iff_exists_ensemble`, also in that file. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen–Chuang Theorem 2.5 (characterization of density operators).** The map sending an +ensemble of pure states `{pᵢ, |ψᵢ⟩}` to its density operator `∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` is surjective onto +the states: every quantum state (a positive operator of trace one) arises from an ensemble. + +The codomain being `State S` encodes the *forward* direction of the biconditional (an ensemble's +density operator is positive with trace one); surjectivity is the *converse* (every positive +trace-one operator is realized by an ensemble — its eigenensemble, `Ensemble.ofState`). Together +they are Theorem 2.5. -/ +theorem Ensemble.toState_surjective : + Function.Surjective (Ensemble.toState (S := S)) := + fun ρ => ⟨Ensemble.ofState ρ, Ensemble.ofState_toState ρ⟩ + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch2/Theorem6.lean b/LeanPool/AxQM/NC/Ch2/Theorem6.lean new file mode 100644 index 0000000000..f0243f2219 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch2/Theorem6.lean @@ -0,0 +1,56 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.UnitaryFreedom + +/-! +# Nielsen & Chuang, Theorem 2.6 (Unitary freedom in the ensemble for density matrices) + +Unitary freedom in the ensemble: two sets generate the same density matrix iff unitarily related. + +The theorem characterizes exactly the freedom in the ensembles `{pᵢ, |ψᵢ⟩}` that give rise to a +given density operator `ρ`. + +The statement is the ensemble form (2.167): two ensembles `e`, `f` **of the same size** (the padded +form) give the same quantum state, `e.toState = f.toState`, if and only if they are *unitarily +related* (`Ensemble.UnitarilyRelated`), i.e. their subnormalized vectors `√pᵢ|ψᵢ⟩` are related by a +unitary coefficient matrix. Two ensembles of unequal size may still give the same state (by +padding); the theorem is stated for the equal-size case, exactly as Nielsen & Chuang state the +result after padding. + +The subnormalized vectors `Ensemble.tildeVec`, the bridge +`Ensemble.toState_op_eq_sum_rankOne_tildeVec` (`ρ = ∑ᵢ |ψ_tildeᵢ⟩⟨ψ_tildeᵢ|`), the relation +`Ensemble.UnitarilyRelated`, and the operator-form biconditional +`Ensemble.toState_op_eq_iff_unitarilyRelated` are in `AxQM/Postulates/API/UnitaryFreedom.lean`. The +vector-family biconditional `InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup` is +in `ToMathlib/Analysis/InnerProductSpace/RankOneSum.lean`. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen–Chuang Theorem 2.6 (unitary freedom in the ensemble).** Two ensembles `e`, `f` of a +quantum system `S`, of the same size (`e.card = f.card` — the padded form, obtained by padding the +smaller ensemble with probability-zero entries), give rise to the same quantum state +`e.toState = f.toState` **if and only if** they are unitarily related (`Ensemble.UnitarilyRelated`): +their subnormalized state vectors `√pᵢ|ψᵢ⟩` are related by a unitary coefficient matrix, +`√pᵢ|ψᵢ⟩ = ∑ⱼ uᵢⱼ √qⱼ|φⱼ⟩` (N&C eq. (2.167)). + +Equality of states is +`Ensemble.toState_op_eq_iff_unitarilyRelated` under `State`-extensionality (`State.ext_iff`), which +in turn is the vector-family biconditional applied to the subnormalized vectors. -/ +theorem Ensemble.toState_eq_iff_unitarilyRelated {e f : Ensemble S} (hcard : e.card = f.card) : + e.toState = f.toState ↔ e.UnitarilyRelated f := by + rw [State.ext_iff, Ensemble.toState_op_eq_iff_unitarilyRelated hcard] + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch4/Exercise1.lean b/LeanPool/AxQM/NC/Ch4/Exercise1.lean new file mode 100644 index 0000000000..3c2dac1e2b --- /dev/null +++ b/LeanPool/AxQM/NC/Ch4/Exercise1.lean @@ -0,0 +1,233 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.BlochState +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.Eigenstate +public import LeanPool.AxQM.Concrete.PauliEigenstateBloch + +/-! +# Nielsen & Chuang, Exercise 4.1 — Bloch-sphere points of the Pauli eigenvectors + +*(N&C p. 174.)* + +Find Bloch-sphere points for the normalized eigenvectors of the Pauli matrices. + +The Bloch-sphere point of a single-qubit pure state `|ψ⟩` is the vector `r_vec` for which its +density +operator is `|ψ⟩⟨ψ| = ½(I + r_vec·σ_vec)` — the (physics) Bloch vector of Exercise 2.72(1), unique +by +`blochState_injective`. This file computes it for the six normalized eigenvectors of `X, Y, Z` +(Exercise 2.11), given as the library's standard qubit pure states: + +* `qubitPlus`, `qubitMinus` (`|±⟩ = (|0⟩ ± |1⟩)/√2`, the `±1` eigenvectors of `X`) → `±x̂`; +* `qubitPlusI`, `qubitMinusI` (`|±i⟩ = (|0⟩ ± i|1⟩)/√2`, the `±1` eigenvectors of `Y`) → `±y_hat`; +* `qubitKet0`, `qubitBasis 1` (`|0⟩`, `|1⟩`, the `+1`/`-1` eigenvectors of `Z`) → `±e_z`. + +## What is proved + +For each eigenvector, a theorem `*_blochVector` stating `(state).toState = blochState axis`, i.e. +its density operator is `½(I + axis·σ_vec)`, pinning its Bloch vector (unique by +`blochState_injective`) to the coordinate axis. This is the exercise's answer. + +Complementing this, a theorem `*_hasEigenstate_pauli*` certifies — at the level of +observables — that each of these six states genuinely *is* a `±1` eigenstate of the corresponding +Pauli vector observable `n_vec·σ_vec` (`Observable.HasEigenstate`), so that "the eigenvectors of +the Pauli +matrices" is a theorem about states and observables, not merely a matrix fact asserted in prose: + +* `qubitPlus`/`qubitMinus` are the `±1` eigenstates of `pauliXObservable` (`X`); +* `qubitPlusI`/`qubitMinusI` are the `±1` eigenstates of `pauliYObservable` (`Y`); +* `qubitKet0`/`qubitBasis 1` are the `±1` eigenstates of `pauliZObservable` (`Z`). + +Together with the Bloch points, this is the full content of Exercise 4.1: these states are +the Pauli eigenstates, *and* their Bloch points are `±x̂ / ±y_hat / ±e_z`. + +## Design + +* **Standard qubit states.** The eigenvectors are stated as the standard + states — `qubitPlus`/`qubitMinus` (`AxQM/Postulates/API/RelativePhase.lean`), `qubitKet0` / + `qubitBasis` (`AxQM/Postulates/API/Qubit.lean`) — so they come with the inner-product, + orthonormality and Pauli-expectation results for those states. The `Y` eigenstates `|±i⟩` are + `qubitPlusI` / `qubitMinusI` (in `RelativePhase.lean`, defined like `qubitPlus` / `qubitMinus`). +* **The `*_eq_blochPureState` bridges** identify each canonical state with the §1.2 pure state + `blochPureState θ φ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩` (eq. 1.4) at the appropriate `(θ,φ)`. Each + is proved by `PureState.ext` from `Concrete.blochKet_* = xPlus/xMinus/yPlus/yMinus/ket 0/ket 1` + (`AxQM/Concrete/PauliEigenstateBloch.lean`). +* **The Bloch points** then use the identity `blochPureState_toState_op` (Exercise + 2.72(4): `|ψ(θ,φ)⟩⟨ψ(θ,φ)| = Matrix.toEuclideanCLM (blochMatrix (blochSphereVector θ φ))`) and + the axis evaluations `Concrete.blochSphereVector_* = ![±1, …]`; no new operator computation. +* The statements are for `PureState` and `State` (the state `blochState`), the Bloch vector being a + plain `Fin 3 → ℝ`. +* **The eigenstate certifications** are term-mode applications of `Observable.hasEigenstate_of_smul` + to two lemmas each: the `PureState`'s `_vec` identity and the operator eigenvalue equation + `pauli*Observable_apply_* : σ (toLp v) = ±1 • toLp v` — mirroring Exercise 2.53's Hadamard + eigenstates. The supporting lemmas are in `AxQM/Postulates/API/Qubit.lean`: + * `pauliYObservable` (`n = (0, 1, 0)`) and its `_op` lemma, beside `pauliXObservable` / + `pauliZObservable`; + * the `pauli*Observable_apply_toLp` bridges (`σ (toLp v) = toLp (σ *ᵥ v)`, fixing the `↑qubit`-vs- + `EuclideanSpace` operator-coercion mismatch via `exact`); + * the six `pauli*Observable_apply_*` operator eigenvalue equations, transporting Exercise 2.11's + concrete `Concrete.pauli*_mulVec_*` (`M *ᵥ v = μ • v`) through those bridges. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-! ### The canonical eigenstates as §1.2 pure states + +Each bridge is `PureState.ext` composed from the canonical state's `_vec` lemma and the +`Concrete.blochKet_* = …` eigenvector identification. -/ + +/-- `|+⟩` is the §1.2 pure state at `(θ,φ) = (π/2, 0)`. -/ +theorem qubitPlus_eq_blochPureState : qubitPlus = blochPureState (Real.pi / 2) 0 := by + apply PureState.ext + simp only [qubitPlus_vec, blochPureState_vec, Concrete.blochKet_pi_div_two_zero] + rfl + +/-- `|-⟩` is the §1.2 pure state at `(θ,φ) = (π/2, π)`. -/ +theorem qubitMinus_eq_blochPureState : qubitMinus = blochPureState (Real.pi / 2) Real.pi := by + apply PureState.ext + simp only [qubitMinus_vec, blochPureState_vec, Concrete.blochKet_pi_div_two_pi] + rfl + +/-- `|+i⟩` is the §1.2 pure state at `(θ,φ) = (π/2, π/2)`. -/ +theorem qubitPlusI_eq_blochPureState : + qubitPlusI = blochPureState (Real.pi / 2) (Real.pi / 2) := by + apply PureState.ext + simp only [qubitPlusI_vec, blochPureState_vec, Concrete.blochKet_pi_div_two_pi_div_two] + rfl + +/-- `|-i⟩` is the §1.2 pure state at `(θ,φ) = (π/2, 3π/2)`. -/ +theorem qubitMinusI_eq_blochPureState : + qubitMinusI = blochPureState (Real.pi / 2) (3 * Real.pi / 2) := by + apply PureState.ext + simp only [qubitMinusI_vec, blochPureState_vec, Concrete.blochKet_pi_div_two_three_pi_div_two] + rfl + +/-- `|0⟩` is the §1.2 pure state at the north pole `(θ,φ) = (0, 0)`. -/ +theorem qubitKet0_eq_blochPureState : qubitKet0 = blochPureState 0 0 := by + apply PureState.ext + simp only [qubitKet0_vec, blochPureState_vec, Concrete.blochKet_zero_zero] + rfl + +/-- `|1⟩` is the §1.2 pure state at the south pole `(θ,φ) = (π, 0)`. -/ +theorem qubitBasis_one_eq_blochPureState : qubitBasis 1 = blochPureState Real.pi 0 := by + apply PureState.ext + rw [qubitBasis_vec, blochPureState_vec, Concrete.blochKet_pi_zero] + rfl + +/-! ### The Bloch points — the answer to Exercise 4.1 + +Each eigenvector's density operator is `blochState axis = ½(I + axis·σ_vec)`, so (by +`blochState_injective`) its Bloch vector is the coordinate axis. Via the `*_eq_blochPureState` +bridges, `blochPureState_toState_op` (Exercise 2.72(4)) and the `Concrete.blochSphereVector_*` +axis evaluations. -/ + +/-- **The Bloch point of `|+⟩` is `+x̂ = (1, 0, 0)`.** -/ +theorem qubitPlus_blochVector : + qubitPlus.toState = blochState ![1, 0, 0] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitPlus_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, Concrete.blochSphereVector_pi_div_two_zero] + +/-- **The Bloch point of `|-⟩` is `-x̂ = (-1, 0, 0)`.** -/ +theorem qubitMinus_blochVector : + qubitMinus.toState = blochState ![-1, 0, 0] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitMinus_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, Concrete.blochSphereVector_pi_div_two_pi] + +/-- **The Bloch point of `|+i⟩` is `+y_hat = (0, 1, 0)`.** -/ +theorem qubitPlusI_blochVector : + qubitPlusI.toState = blochState ![0, 1, 0] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitPlusI_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, Concrete.blochSphereVector_pi_div_two_pi_div_two] + +/-- **The Bloch point of `|-i⟩` is `-y_hat = (0, -1, 0)`.** -/ +theorem qubitMinusI_blochVector : + qubitMinusI.toState = blochState ![0, -1, 0] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitMinusI_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, + Concrete.blochSphereVector_pi_div_two_three_pi_div_two] + +/-- **The Bloch point of `|0⟩` is `+e_z = (0, 0, 1)`.** -/ +theorem qubitKet0_blochVector : + qubitKet0.toState = blochState ![0, 0, 1] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitKet0_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, Concrete.blochSphereVector_zero_zero] + +/-- **The Bloch point of `|1⟩` is `-e_z = (0, 0, -1)`.** -/ +theorem qubitBasis_one_blochVector : + (qubitBasis 1).toState = blochState ![0, 0, -1] + (by norm_num [Matrix.cons_val_two, Matrix.tail_cons]) := by + rw [qubitBasis_one_eq_blochPureState] + apply State.ext + rw [blochPureState_toState_op, blochState_op, Concrete.blochSphereVector_pi_zero] + +/-! ### The states are the ±1 eigenstates of the Pauli observables + +The observable-level reading of "the eigenvectors of the Pauli matrices": each of the six +states is a `±1` eigenstate of the Pauli vector observable `n_vec·σ_vec` +(`Observable.HasEigenstate`). Each is a term-mode application of `Observable.hasEigenstate_of_smul` +to the state's `_vec` identity (the state is already normalized, so `c = 1`) and the +operator eigenvalue equation `pauli*Observable_apply_*` (in `AxQM/Postulates/API/Qubit.lean`). -/ + +/-- **`|+⟩` is the `+1` eigenstate of `X`:** `X |+⟩ = |+⟩`. -/ +theorem qubitPlus_hasEigenstate_pauliX : pauliXObservable.HasEigenstate 1 qubitPlus := + pauliXObservable.hasEigenstate_of_smul (qubitPlus_vec.trans (one_smul _ _).symm) + pauliXObservable_apply_xPlus + +/-- **`|-⟩` is the `-1` eigenstate of `X`:** `X |-⟩ = -|-⟩`. -/ +theorem qubitMinus_hasEigenstate_pauliX : pauliXObservable.HasEigenstate (-1) qubitMinus := + pauliXObservable.hasEigenstate_of_smul (qubitMinus_vec.trans (one_smul _ _).symm) + pauliXObservable_apply_xMinus + +/-- **`|+i⟩` is the `+1` eigenstate of `Y`:** `Y |+i⟩ = |+i⟩`. -/ +theorem qubitPlusI_hasEigenstate_pauliY : pauliYObservable.HasEigenstate 1 qubitPlusI := + pauliYObservable.hasEigenstate_of_smul (qubitPlusI_vec.trans (one_smul _ _).symm) + pauliYObservable_apply_yPlus + +/-- **`|-i⟩` is the `-1` eigenstate of `Y`:** `Y |-i⟩ = -|-i⟩`. -/ +theorem qubitMinusI_hasEigenstate_pauliY : pauliYObservable.HasEigenstate (-1) qubitMinusI := + pauliYObservable.hasEigenstate_of_smul (qubitMinusI_vec.trans (one_smul _ _).symm) + pauliYObservable_apply_yMinus + +/-- **`|0⟩` is the `+1` eigenstate of `Z`:** `Z |0⟩ = |0⟩`. -/ +theorem qubitKet0_hasEigenstate_pauliZ : pauliZObservable.HasEigenstate 1 qubitKet0 := + pauliZObservable.hasEigenstate_of_smul (qubitKet0_vec.trans (one_smul _ _).symm) + pauliZObservable_apply_ket0 + +/-- **`|1⟩` is the `-1` eigenstate of `Z`:** `Z |1⟩ = -|1⟩`. -/ +theorem qubitBasis_one_hasEigenstate_pauliZ : + pauliZObservable.HasEigenstate (-1) (qubitBasis 1) := + pauliZObservable.hasEigenstate_of_smul ((qubitBasis_vec 1).trans (one_smul _ _).symm) + pauliZObservable_apply_ket1 + +/-- **`|0⟩` is the `+1` eigenstate of `Z`:** `Z |0⟩ = |0⟩`, phrased on the `qubitBasis`-indexed ket +(the `+1` companion of `qubitBasis_one_hasEigenstate_pauliZ`; cf. `qubitKet0_hasEigenstate_pauliZ` +on `qubitKet0`). -/ +theorem qubitBasis_zero_hasEigenstate_pauliZ : + pauliZObservable.HasEigenstate 1 (qubitBasis 0) := + pauliZObservable.hasEigenstate_of_smul ((qubitBasis_vec 0).trans (one_smul _ _).symm) + pauliZObservable_apply_ket0 + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch9/Theorem1.lean b/LeanPool/AxQM/NC/Ch9/Theorem1.lean new file mode 100644 index 0000000000..d5e10b1060 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch9/Theorem1.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TraceDistance +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Concrete.TraceDistancePOVM + +/-! +# Nielsen & Chuang, Theorem 9.1 (trace distance as the maximum over measurements) + +D(rho,sigma) = max over POVMs of classical D(p_m,q_m) of measurement outcomes. +— Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 9.1 (p. 405). + +The (quantum) trace distance `D(ρ, σ) = ½‖ρ − σ‖₁` equals the **largest** classical +trace distance `D(pₘ, qₘ)` (N&C `(9.1)`) achievable between the outcome +distributions of `ρ` and `σ` under any measurement: no measurement can distinguish +`ρ` from `σ` better than the trace distance allows, and some measurement (a +projective measurement in an eigenbasis of `ρ − σ`) achieves the bound exactly. + +## The physical form + +The theorem is phrased for states and measurements. It reuses the operator-level +mathematical core proved in `AxQM/Concrete/TraceDistancePOVM.lean` (for operators +and a `POVM`), lifted to states and measurements through two definitional bridges: + +* the Born-rule outcome distribution is `Measurement.bornProb`, which is + *definitionally* `m.toPOVM.toPMF ρ.op` (the induced POVM's Born rule on the + density operator), so the classical distances match on the nose; +* the trace distance is `State.traceDistance` + (`AxQM/Postulates/API/TraceDistance.lean`), definitionally `½ ‖ρ.op − σ.op‖₁`. + +Every statement below is in terms of `bornProb`, `traceDistance` and `classicalTraceDist`. + +## Main statements + +* `State.classicalTraceDist_bornProb_le` — **the bound `(9.24)–(9.30)`**: for + *every* measurement `m`, the classical trace distance of the outcome + distributions is at most the trace distance, `D(pₘ, qₘ) ≤ D(ρ, σ)`. This is the + measurement-monotonicity direction, faithful to N&C's "for all POVMs". +* `State.exists_measurement_classicalTraceDist_bornProb_eq` — **achievability**: + some measurement (the projective measurement in an eigenbasis of `ρ − σ`) + attains the bound, `D(pₘ, qₘ) = D(ρ, σ)`. +* `State.isGreatest_classicalTraceDist_bornProb` — **the theorem itself**: + `D(ρ, σ)` is the *greatest* achievable classical trace distance — the two + directions assembled into N&C's equality-to-a-maximum via `IsGreatest`. + +## References + +Nielsen, M. A., & Chuang, I. L. (2010). *Quantum Computation and Quantum +Information* (10th anniv. ed.). Cambridge University Press. Theorem 9.1, §9.2.1. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open AxQM.Concrete + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen & Chuang, Theorem 9.1 (the bound `(9.24)–(9.30)`).** For every +measurement `m` on the system `S` and any states `ρ σ`, the classical trace +distance of the Born-rule outcome distributions is at most the trace distance of +the states: +`D(pₘ, qₘ) ≤ D(ρ, σ)`. + +A measurement can never distinguish `ρ` from `σ` more sharply than the trace +distance permits (measurement monotonicity). Faithful to N&C's "for all POVMs": +the bound is quantified over *arbitrary* finite outcome sets `ι`, so it covers +every POVM. Proof: `m.bornProb ρ` is definitionally `m.toPOVM.toPMF ρ.op`, so this +is exactly the operator-level upper bound `classicalTraceDist_toPMF_le` applied to +the induced POVM `m.toPOVM` and the density operators `ρ.op, σ.op`. -/ +theorem State.classicalTraceDist_bornProb_le {ι : Type*} [Fintype ι] + (m : Measurement ι S) (ρ σ : State S) : + classicalTraceDist (m.bornProb ρ) (m.bornProb σ) ≤ ρ.traceDistance σ := + classicalTraceDist_toPMF_le m.toPOVM ρ.op σ.op + +/-- **Nielsen & Chuang, Theorem 9.1 (achievability).** Some measurement attains the +trace distance: there is a projective measurement — the measurement in an +orthonormal eigenbasis of `ρ − σ`, `Measurement.ofOrthonormalBasis` of the +eigenvector basis — whose outcome distributions have classical trace distance +exactly `D(ρ, σ)`: +`D(pₘ, qₘ) = D(ρ, σ)`. + +Together with `State.classicalTraceDist_bornProb_le` (the bound for every +measurement) this exhibits `D(ρ, σ)` as the maximum. The self-adjointness of +`ρ − σ` — needed to diagonalize it — comes for free: density operators are +positive, hence self-adjoint, so their difference is self-adjoint. Proof: on the +eigenbasis `pₘ − qₘ = λₘ` (the eigenvalue), so `∑ₘ|pₘ − qₘ| = ∑ₘ|λₘ| = ‖ρ − σ‖₁`, +which is the operator-level `classicalTraceDist_toPMF_eigenbasis_eq`. -/ +theorem State.exists_measurement_classicalTraceDist_bornProb_eq (ρ σ : State S) : + ∃ (n : ℕ) (m : Measurement (Fin n) S), + classicalTraceDist (m.bornProb ρ) (m.bornProb σ) = ρ.traceDistance σ := by + have : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + -- `ρ − σ` is self-adjoint (difference of density operators, which are positive), + -- hence its underlying linear map is symmetric and can be diagonalized. + have hsa : IsSelfAdjoint (ρ.op - σ.op) := + ρ.isPositive_op.isSelfAdjoint.sub σ.isPositive_op.isSelfAdjoint + have hsymm : ((ρ.op - σ.op : S.space →L[ℂ] S.space) : S.space →ₗ[ℂ] S.space).IsSymmetric := + ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mp hsa + refine ⟨_, Measurement.ofOrthonormalBasis (hsymm.eigenvectorBasis rfl), ?_⟩ + -- The operator-level achievability lemma, re-expressed through the projective + -- measurement's induced POVM (`toPOVM_ofOrthonormalBasis`). The goal matches it up + -- to unfolding `bornProb = toPOVM.toPMF ∘ .op` and `traceDistance = ‖·‖₁/2` (defeq). + have h := classicalTraceDist_toPMF_eigenbasis_eq ρ.op σ.op hsymm + rw [← Measurement.toPOVM_ofOrthonormalBasis] at h + exact h + +/-- **Nielsen & Chuang, Theorem 9.1** (headline): the trace distance `D(ρ, σ)` is the +**greatest** classical trace distance of the outcome distributions achievable over +all measurements — +`D(ρ, σ) = max_{measurements} D(pₘ, qₘ)`. + +This is the theorem's headline equality-to-a-maximum, packaged as `IsGreatest`: the +value `D(ρ, σ)` both lies in the set of achievable classical distances (by +`State.exists_measurement_classicalTraceDist_bornProb_eq`) and is an upper bound for +it (by `State.classicalTraceDist_bornProb_le`). The measurements range over every +finite outcome cardinality `Fin n`; since every POVM is the induced POVM of some +measurement, this is N&C's maximum over all POVMs. -/ +theorem State.isGreatest_classicalTraceDist_bornProb (ρ σ : State S) : + IsGreatest + {d : ℝ | ∃ (n : ℕ) (m : Measurement (Fin n) S), + d = classicalTraceDist (m.bornProb ρ) (m.bornProb σ)} + (ρ.traceDistance σ) := by + constructor + · obtain ⟨n, m, hm⟩ := State.exists_measurement_classicalTraceDist_bornProb_eq ρ σ + exact ⟨n, m, hm.symm⟩ + · rintro d ⟨n, m, rfl⟩ + exact State.classicalTraceDist_bornProb_le m ρ σ + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch9/Theorem3.lean b/LeanPool/AxQM/NC/Ch9/Theorem3.lean new file mode 100644 index 0000000000..e25acea5be --- /dev/null +++ b/LeanPool/AxQM/NC/Ch9/Theorem3.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Concrete.ClassicalTraceDistance + +/-! +# Nielsen & Chuang, Theorem 9.3 (Strong convexity of the trace distance) + +Strong convexity of trace distance for mixtures of states and probability distributions. + +The trace distance between two *mixtures* is controlled by two separate sources of +distinguishability: the classical distance `D(p, q)` between the mixing weights, plus the +average `∑ᵢ pᵢ D(ρᵢ, σᵢ)` of the distances between the paired components. N&C call `(9.46)` +the **strong convexity** of the trace distance because the joint-convexity inequality `(9.50)` +follows from it as the special case `q = p`. + +## The physical form + +The two mixtures `∑ᵢ pᵢ ρᵢ` and `∑ᵢ qᵢ σᵢ` are formed with `AxQM.State.mix` +(`AxQM/Postulates/API/Mixture.lean`); `D` on states is `State.traceDistance` and `D` on +distributions is `AxQM.Concrete.classicalTraceDist` (N&C `(9.1)`). + +## Proof + +The proof is the **trace-norm triangle-inequality** argument, which is cleaner than and stronger +than N&C's projector construction (N&C `(9.47)–(9.49)` pick a maximizing projector `P`; the +triangle inequality avoids choosing one). Writing the difference of the two mixed operators as +``` +∑ᵢ pᵢρᵢ − ∑ᵢ qᵢσᵢ = ∑ᵢ pᵢ(ρᵢ − σᵢ) + ∑ᵢ (pᵢ − qᵢ)σᵢ, +``` +subadditivity of the trace norm over finite sums (`ContinuousLinearMap.traceNorm_sum_le`) and +its absolute homogeneity (`traceNorm_smul`) bound the two pieces by +`∑ᵢ pᵢ ‖ρᵢ − σᵢ‖₁` and `∑ᵢ |pᵢ − qᵢ| · ‖σᵢ‖₁`. Since each `σᵢ` is a density operator its trace +norm is `1` (`State.op_traceNorm_eq_one`), and `pᵢ ≥ 0`, so halving (`D = ½‖·‖₁`) turns these +into `∑ᵢ pᵢ D(ρᵢ, σᵢ)` and `D(p, q) = ½∑ᵢ|pᵢ − qᵢ|`. Only `pᵢ ≥ 0` and normalization of the +`σᵢ` are used for the inequality itself; the full probability-distribution hypotheses enter +through `State.mix`, which requires them to build the mixed states. + +## Main statements + +* `State.traceDistance_mix_le` — **Theorem 9.3, `(9.46)`**: the strong-convexity bound. +* `State.traceDistance_mix_jointly_convex` — **joint convexity, `(9.50)`**: the special case + `q = p`, `D(∑ᵢ pᵢ ρᵢ, ∑ᵢ pᵢ σᵢ) ≤ ∑ᵢ pᵢ D(ρᵢ, σᵢ)`, obtained by `classicalTraceDist_self`. + +## References + +Nielsen, M. A., & Chuang, I. L. (2010). *Quantum Computation and Quantum Information* +(10th anniv. ed.). Cambridge University Press. Theorem 9.3, §9.2.1. + +N&C Theorem 9.3, p. 407. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen & Chuang, Theorem 9.3 (Strong convexity of the trace distance, `(9.46)`).** For +probability distributions `p, q : ι → ℝ` over a finite index set and families of states +`ρ, σ : ι → State S`, the trace distance between the mixtures is bounded by the classical +distance of the weights plus the `p`-average of the componentwise distances: +`D(∑ᵢ pᵢ ρᵢ, ∑ᵢ qᵢ σᵢ) ≤ D(p, q) + ∑ᵢ pᵢ D(ρᵢ, σᵢ)`. + +The mixtures are `State.mix p hp hpsum ρ` and `State.mix q hq hqsum σ`. Proof: the trace-norm +triangle inequality (`ContinuousLinearMap.traceNorm_sum_le`, `traceNorm_add_le`) applied to the +splitting `∑ᵢ pᵢρᵢ − ∑ᵢ qᵢσᵢ = ∑ᵢ pᵢ(ρᵢ − σᵢ) + ∑ᵢ (pᵢ − qᵢ)σᵢ`, using `‖σᵢ‖₁ = 1` +(`State.op_traceNorm_eq_one`) and `pᵢ ≥ 0`. -/ +theorem State.traceDistance_mix_le {ι : Type*} [Fintype ι] + (p q : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hpsum : ∑ i, p i = 1) + (hq : ∀ i, 0 ≤ q i) (hqsum : ∑ i, q i = 1) (ρ σ : ι → State S) : + (State.mix p hp hpsum ρ).traceDistance (State.mix q hq hqsum σ) + ≤ Concrete.classicalTraceDist p q + ∑ i, p i * (ρ i).traceDistance (σ i) := by + -- Split the difference of the two mixed density operators into a component part and a + -- weight part: `∑ᵢ pᵢρᵢ − ∑ᵢ qᵢσᵢ = ∑ᵢ pᵢ(ρᵢ − σᵢ) + ∑ᵢ (pᵢ − qᵢ)σᵢ`. + have hA : (∑ i, (p i : ℂ) • (ρ i).op) - (∑ i, (q i : ℂ) • (σ i).op) + = (∑ i, (p i : ℂ) • ((ρ i).op - (σ i).op)) + + (∑ i, ((p i : ℂ) - (q i : ℂ)) • (σ i).op) := by + rw [← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [smul_sub, sub_smul]; module + -- Component part: `‖∑ᵢ pᵢ(ρᵢ − σᵢ)‖₁ ≤ ∑ᵢ pᵢ ‖ρᵢ − σᵢ‖₁` (subadditivity + `pᵢ ≥ 0`). + have hX : (∑ i, (p i : ℂ) • ((ρ i).op - (σ i).op)).traceNorm + ≤ ∑ i, p i * ((ρ i).op - (σ i).op).traceNorm := by + refine (ContinuousLinearMap.traceNorm_sum_le _ _).trans (le_of_eq ?_) + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.traceNorm_smul, Complex.norm_real, Real.norm_of_nonneg (hp i)] + -- Weight part: `‖∑ᵢ (pᵢ − qᵢ)σᵢ‖₁ ≤ ∑ᵢ |pᵢ − qᵢ|` (subadditivity + `‖σᵢ‖₁ = 1`). + have hY : (∑ i, ((p i : ℂ) - (q i : ℂ)) • (σ i).op).traceNorm ≤ ∑ i, |p i - q i| := by + refine (ContinuousLinearMap.traceNorm_sum_le _ _).trans (le_of_eq ?_) + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.traceNorm_smul, State.op_traceNorm_eq_one, mul_one, + ← Complex.ofReal_sub, Complex.norm_real, Real.norm_eq_abs] + -- Convert the `p`-average of trace distances to a trace-norm sum divided by two. + have hD : ∑ i, p i * (ρ i).traceDistance (σ i) + = (∑ i, p i * ((ρ i).op - (σ i).op).traceNorm) / 2 := by + rw [Finset.sum_div] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [State.traceDistance_eq]; ring + have hC : Concrete.classicalTraceDist p q = (∑ i, |p i - q i|) / 2 := rfl + rw [State.traceDistance_eq, State.mix_op, State.mix_op, hA, hC, hD] + have hXY := (ContinuousLinearMap.traceNorm_add_le + (∑ i, (p i : ℂ) • ((ρ i).op - (σ i).op)) (∑ i, ((p i : ℂ) - (q i : ℂ)) • (σ i).op)).trans + (add_le_add hX hY) + linarith [hXY] + +/-- **Joint convexity of the trace distance** (Nielsen & Chuang `(9.50)`), the special case of +strong convexity with equal weight distributions `q = p`: +`D(∑ᵢ pᵢ ρᵢ, ∑ᵢ pᵢ σᵢ) ≤ ∑ᵢ pᵢ D(ρᵢ, σᵢ)`. + +Immediate from `State.traceDistance_mix_le` at `q = p`, since the classical trace distance of a +distribution from itself vanishes (`classicalTraceDist_self`). -/ +theorem State.traceDistance_mix_jointly_convex {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hpsum : ∑ i, p i = 1) (ρ σ : ι → State S) : + (State.mix p hp hpsum ρ).traceDistance (State.mix p hp hpsum σ) + ≤ ∑ i, p i * (ρ i).traceDistance (σ i) := by + have h := State.traceDistance_mix_le p p hp hpsum hp hpsum ρ σ + rwa [Concrete.classicalTraceDist_self, zero_add] at h + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch9/Theorem4.lean b/LeanPool/AxQM/NC/Ch9/Theorem4.lean new file mode 100644 index 0000000000..2217739ff9 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch9/Theorem4.lean @@ -0,0 +1,119 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.Postulates.API.Uhlmann +public import LeanPool.AxQM.Postulates.API.Fidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Uhlmann + +/-! +# Nielsen & Chuang, Theorem 9.4 (Uhlmann's theorem) + +Uhlmann's theorem: F(rho,sigma)=max over purifications ||. +— Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 9.4 (p. 410). + +Uhlmann's theorem characterizes the fidelity `F(ρ, σ)` (N&C `(9.53)`, +`State.fidelity`) as the **greatest overlap** `‖⟨ψ|φ⟩‖` achievable between a +purification `|ψ⟩` of `ρ` and a purification `|φ⟩` of `σ` into the doubled system. It is +the physics companion of N&C Theorem 9.1 (the trace distance as a maximum over +measurements): both express a distance measure as an extremum, but where 9.1 maximizes a +classical distance over measurements, 9.4 maximizes a pure-state overlap over purifications. + +## The physical form + +The theorem is `State.isGreatest_norm_overlap_purification`, phrased for states: + +* the maximization ranges over `ψ φ : PureState (S ⊗ S)` — pure states of the doubled + system, the ancilla being a *copy of the system* `S` (N&C's "system `R`, a copy of `Q`"); +* `ψ` **is a purification of** `ρ` is the physical condition `ψ.toState.reducedLeft = ρ`: + tracing out the ancilla recovers `ρ` (`State.reducedLeft`, the marginal of §2.4.3); +* the overlap `⟨ψ|φ⟩` is `PureState.overlap`, the transition amplitude; +* the value is `ρ.fidelity σ`, packaged — exactly as Theorem 9.1's headline — as an + `IsGreatest`: the fidelity both is attained by some pair of purifications and bounds every + achievable overlap. + +Its proof reduces the physical statement to the operator-level core: + +* `TensorProduct.isGreatest_norm_inner_of_isPurification` (`ToMathlib`) — the abstract + Uhlmann theorem `IsGreatest {‖⟪Ψ, Φ⟫‖ | Ψ, Φ purify ρ.op, σ.op into E ⊗ E} ‖√ρ √σ‖₁`; +* `State.fidelity_eq_traceNorm` — the fidelity–trace-norm bridge `F(ρ, σ) = ‖√ρ √σ‖₁`; +* `PureState.reducedLeft_toState_eq_iff_isPurification` — the purification bridge translating + the physical `reducedLeft = ρ` into the abstract `TensorProduct.IsPurification ρ.op ψ.vec`. + +## Faithfulness + +N&C fix `R` to be *a copy of* `Q` (same dimension) and maximize over purifications into `RQ`; +we realize "a copy of `Q`" by the system `S` itself, so the doubled system is `S ⊗ S` with +state space `S.space ⊗ S.space` — matching the abstract theorem's `E ⊗ E` ancilla exactly. +The factor order (`QR` here vs. N&C's `RQ`) is immaterial: `reducedLeft` traces out the +ancilla and the overlap is unchanged. The maximization being **attained** (an `IsGreatest`, +not merely a supremum) is faithful to N&C's `max`. + +## Main statements + +* `State.isGreatest_norm_overlap_purification` — Uhlmann's theorem, `(9.62)`: + `F(ρ, σ) = max ‖⟨ψ|φ⟩‖` over purifications `ψ` of `ρ`, `φ` of `σ` into `S ⊗ S`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen & Chuang, Theorem 9.4 (Uhlmann's theorem)**, `(9.62)`: the fidelity `F(ρ, σ)` +is the **greatest overlap magnitude** `‖⟨ψ|φ⟩‖` achievable over all purifications `ψ` of `ρ` +and `φ` of `σ` into the doubled system `S ⊗ S` (the ancilla a copy of the system): +`F(ρ, σ) = max_{|ψ⟩,|φ⟩} |⟨ψ|φ⟩|`. + +Packaged as `IsGreatest`: `ρ.fidelity σ` both lies in the achievable set (attained by the +optimal pair of purifications) and upper-bounds it. Here a *purification* of `ρ` is a pure +state `ψ` of `S ⊗ S` whose left marginal `ψ.toState.reducedLeft` is `ρ`, and the overlap is +`PureState.overlap`. + +The proof reduces to the operator-level core +`TensorProduct.isGreatest_norm_inner_of_isPurification`: the fidelity is the trace norm +`‖√ρ √σ‖₁` (`State.fidelity_eq_traceNorm`), and the physics achievability set coincides with +the abstract purification-overlap set via the purification bridge +`PureState.reducedLeft_toState_eq_iff_isPurification` (using that every purification of a +density operator has unit norm, `TensorProduct.norm_eq_one_of_isPurification`). -/ +theorem State.isGreatest_norm_overlap_purification (ρ σ : State S) : + IsGreatest + {r : ℝ | ∃ ψ φ : PureState (S ⊗ S), + ψ.toState.reducedLeft = ρ ∧ φ.toState.reducedLeft = σ ∧ + r = ‖ψ.overlap φ‖} + (ρ.fidelity σ) := by + -- The achievable-overlap set is exactly the abstract purification-overlap set. + have hset : + {r : ℝ | ∃ ψ φ : PureState (S ⊗ S), + ψ.toState.reducedLeft = ρ ∧ φ.toState.reducedLeft = σ ∧ r = ‖ψ.overlap φ‖} + = {r : ℝ | ∃ Ψ Φ : TensorProduct ℂ S.space S.space, + TensorProduct.IsPurification ρ.op Ψ ∧ TensorProduct.IsPurification σ.op Φ ∧ + r = ‖(inner ℂ Ψ Φ : ℂ)‖} := by + ext r + simp only [Set.mem_ofPred_eq] + constructor + · rintro ⟨ψ, φ, hψ, hφ, rfl⟩ + exact ⟨ψ.vec, φ.vec, + (ψ.reducedLeft_toState_eq_iff_isPurification ρ).mp hψ, + (φ.reducedLeft_toState_eq_iff_isPurification σ).mp hφ, rfl⟩ + · rintro ⟨Ψ, Φ, hΨ, hΦ, rfl⟩ + exact ⟨⟨Ψ, TensorProduct.norm_eq_one_of_isPurification ρ.isDensity hΨ⟩, + ⟨Φ, TensorProduct.norm_eq_one_of_isPurification σ.isDensity hΦ⟩, + (PureState.reducedLeft_toState_eq_iff_isPurification _ ρ).mpr hΨ, + (PureState.reducedLeft_toState_eq_iff_isPurification _ σ).mpr hΦ, rfl⟩ + rw [State.fidelity_eq_traceNorm, hset] + exact TensorProduct.isGreatest_norm_inner_of_isPurification ρ.isDensity.nonneg σ.isDensity.nonneg + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch9/Theorem6.lean b/LeanPool/AxQM/NC/Ch9/Theorem6.lean new file mode 100644 index 0000000000..edf48ed0a0 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch9/Theorem6.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Fidelity +public import LeanPool.AxQM.Postulates.API.QuantumChannel +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.FidelityMonotone + +/-! +# Nielsen & Chuang, Theorem 9.6 (Monotonicity of the fidelity) + +Monotonicity of fidelity: F(E(rho),E(sigma))>=F(rho,sigma) for trace-preserving E. + +A physical process can never *increase* the distinguishability of two states measured by the +fidelity: applying a channel to both arguments can only bring them closer (fidelity closer to `1`). +This is the fidelity counterpart of the trace-distance contractivity `D(E(ρ), E(σ)) ≤ D(ρ, σ)` +(Nielsen & Chuang, Theorem 9.2) — with the inequality reversed, since larger +fidelity means *less* distinguishable. + +## Statement + +A **trace-preserving quantum operation** is a quantum *channel* (`AxQM.IsChannel f`): the +state-map `f` is the restriction of a completely-positive, trace-preserving superoperator. The +distance is the **fidelity** `AxQM.State.fidelity` (`ρ.fidelity σ = F(ρ, σ)`, N&C +`(9.53)`). The result is + +* `AxQM.State.fidelity_le_fidelity_channel` — `F(ρ, σ) ≤ F(f ρ, f σ)` for every channel + `f` and all states `ρ, σ`. + +## Proof + +The proof reduces to the operator-level heart, proved in `ToMathlib/` as +`ContinuousLinearMap.traceNorm_cfc_sqrt_mul_le_krausSum`: + + `‖√ρ √σ‖₁ ≤ ‖√(∑ₖ Eₖ ρ Eₖ†) √(∑ₖ Eₖ σ Eₖ†)‖₁` + +for a **complete** Kraus family (`∑ₖ Eₖ† Eₖ = 1`). That inequality is N&C's proof (§9.3): Uhlmann's +theorem (Theorem 9.4) realizes `‖√ρ √σ‖₁` as an overlap of purifications, which is *transported* +through the channel's environment dilation into a larger ancilla and bounded there by the +arbitrary-ancilla Uhlmann upper bound (Theorem 9.4, generalized) — completeness of the Kraus family +making the overlap invariant. + +Two ingredients bridge `IsChannel f` to that lemma: + +* **Fidelity as a trace norm.** `State.fidelity_eq_traceNorm` rewrites both fidelities to + `‖√· √·‖₁`. +* **A complete Kraus family for the channel.** From complete positivity + trace preservation the + channel's superoperator has an operator-sum representation `Φ = krausSumₗ E` + (`satisfiesOperationAxioms_iff_isOperatorSum`, N&C Theorem 8.1), whose operation elements satisfy + `∑ₖ Eₖ† Eₖ ≤ 1`; **trace preservation upgrades this to the completeness relation** + `∑ₖ Eₖ† Eₖ = 1` via `ContinuousLinearMap.sum_adjoint_comp_eq_one_of_trace_krausSumₗ_eq` (the + equality-sharpening of the trace bound, `ToMathlib/`, mirroring its `≤` sibling + `sum_adjoint_comp_le_one_of_isTraceNonIncreasing`). Then `(f ρ).op = Φ ρ.op = ∑ₖ Eₖ ρ.op Eₖ†`. + +N&C Theorem 9.6, p. 414. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Monotonicity of the fidelity under a trace-preserving quantum operation** (Nielsen & Chuang, +Theorem 9.6, `(9.87)`): a quantum channel `f` never decreases the fidelity, +`F(ρ, σ) ≤ F(f ρ, f σ)` for all states `ρ, σ`. + +The proof reduces, through `State.fidelity_eq_traceNorm`, to the operator-sum +monotonicity `ContinuousLinearMap.traceNorm_cfc_sqrt_mul_le_krausSum` (`ToMathlib/`, the +Uhlmann-plus-dilation argument). Complete positivity of the channel supplies a Kraus representation +`Φ = krausSumₗ E`, and trace preservation upgrades its trace bound to the completeness relation +`∑ₖ Eₖ† Eₖ = 1` required by that lemma. -/ +theorem State.fidelity_le_fidelity_channel {f : State S → State S} (hf : IsChannel f) + (ρ σ : State S) : ρ.fidelity σ ≤ (f ρ).fidelity (f σ) := by + obtain ⟨Φ, hΦCP, hΦTP, hfop⟩ := hf + -- Kraus representation of `Φ` (trace-preservation ⟹ trace-non-increasing ⟹ quantum operation). + obtain ⟨ι, _, E, hΦeq, _⟩ := + (ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum Φ).mp + ⟨hΦCP, fun τ _ => le_of_eq (by rw [hΦTP τ])⟩ + -- Completeness `∑ₖ Eₖ† Eₖ = 1` from trace preservation (the equality-sharpening of the + -- operator-sum trace bound, in `ToMathlib/`). + have hcomp : ∑ i, (ContinuousLinearMap.adjoint (E i)).comp (E i) = 1 := + ContinuousLinearMap.sum_adjoint_comp_eq_one_of_trace_krausSumₗ_eq E + fun ρ => by rw [← hΦeq]; exact hΦTP ρ + -- Reduce to the operator-level monotonicity through the trace-norm bridge. + have hfk : ∀ τ : State S, (f τ).op = ContinuousLinearMap.krausSumₗ E τ.op := + fun τ => by rw [hfop, hΦeq] + rw [State.fidelity_eq_traceNorm, State.fidelity_eq_traceNorm, hfk ρ, hfk σ] + exact ContinuousLinearMap.traceNorm_cfc_sqrt_mul_le_krausSum E hcomp + ρ.isDensity.nonneg σ.isDensity.nonneg + +end AxQM diff --git a/LeanPool/AxQM/NC/Ch9/Theorem7.lean b/LeanPool/AxQM/NC/Ch9/Theorem7.lean new file mode 100644 index 0000000000..0e6effa346 --- /dev/null +++ b/LeanPool/AxQM/NC/Ch9/Theorem7.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Fidelity +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UhlmannMixture + +/-! +# Nielsen & Chuang, Theorem 9.7 (Strong concavity of the fidelity) + +Strong concavity of fidelity for state mixtures with probability distributions. + +Mixing on *both* sides of the fidelity can only bring the two mixtures closer (raise the fidelity) +than the `√(pᵢ qᵢ)`-weighted average of the componentwise fidelities. N&C call this the **strong +concavity** of the fidelity, in analogy with the strong convexity of the trace distance (Theorem +9.3); it is the master inequality from which the joint concavity of the fidelity (Exercise 9.19) and +concavity in the first argument (Exercise 9.20) follow by specialization. + +## Statement + +The mixtures are `AxQM.State.mix` (`∑ᵢ pᵢ ρᵢ`, N&C mixtures), and the +distance is the **fidelity** `AxQM.State.fidelity` (`ρ.fidelity σ = F(ρ, σ)`, N&C +`(9.53)`). The result is + +* `AxQM.State.sum_sqrt_mul_fidelity_le_fidelity_mix` — + `∑ᵢ √(pᵢ qᵢ) F(ρᵢ, σᵢ) ≤ F(∑ᵢ pᵢ ρᵢ, ∑ᵢ qᵢ σᵢ)` for probability distributions `p, q` and families + of states `ρ, σ`. + +The weights `√(pᵢ qᵢ)` live entirely on the classical probability side. + +## Proof + +The statement is one rewrite away from the operator inequality proved in `ToMathlib/` as +`ContinuousLinearMap.traceNorm_cfc_sqrt_mul_cfc_sqrt_sum_ge`: + + `∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁ ≤ ‖√(∑ᵢ pᵢ ρᵢ) √(∑ᵢ qᵢ σᵢ)‖₁` + +for positive operators `ρᵢ, σᵢ` and non-negative weights `pᵢ, qᵢ` (no normalization required — the +probability constraints `∑ pᵢ = ∑ qᵢ = 1` are consumed only by `State.mix` here). That inequality is +N&C's proof (§9.2.2, p. 414): choosing per-component maximizing factorizations with real overlap and +assembling **block-row operators** on an enlarged ancilla realizes the joint overlap +`∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁` as a single Hilbert–Schmidt pairing, bounded by the general-ancilla Uhlmann +upper bound (Theorem 9.4, generalized). The block-row assembly is the operator counterpart of N&C's +joint purifications `|ψ⟩ ≡ ∑ᵢ √pᵢ |ψᵢ⟩|i⟩`, `|ϕ⟩ ≡ ∑ᵢ √qᵢ |ϕᵢ⟩|i⟩` (`(9.93)`). + +Two bridges lift that operator inequality to states: + +* **Fidelity as a trace norm.** `State.fidelity_eq_traceNorm` rewrites each `F(ρᵢ, σᵢ)` and the + mixture fidelity to `‖√· √·‖₁` (N&C `(9.71)`). +* **The mixture's density operator.** `State.mix_op` exposes `(∑ᵢ pᵢ ρᵢ).op = ∑ᵢ (pᵢ : ℂ) • ρᵢ.op`, + matching the operator lemma's mixed arguments; positivity of each `ρᵢ.op` / `σᵢ.op` is + `State.isDensity.nonneg`. + +N&C Theorem 9.7, p. 414. The operator core is in `ToMathlib/` (phase-aligned Uhlmann +achievement and the block-row assembly). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Strong concavity of the fidelity** (Nielsen & Chuang, Theorem 9.7, `(9.92)`): for probability +distributions `p, q` over a common finite index set and families of states `ρ, σ`, +`∑ᵢ √(pᵢ qᵢ) F(ρᵢ, σᵢ) ≤ F(∑ᵢ pᵢ ρᵢ, ∑ᵢ qᵢ σᵢ)`. + +Mixing on both arguments never decreases the fidelity below the `√(pᵢ qᵢ)`-weighted average of the +componentwise fidelities. The proof rewrites both sides through `State.fidelity_eq_traceNorm` and +`State.mix_op` to the operator inequality +`ContinuousLinearMap.traceNorm_cfc_sqrt_mul_cfc_sqrt_sum_ge` (`ToMathlib/`, the block-row Uhlmann +argument); positivity of each density operator supplies its hypotheses. This is the master +inequality behind the joint concavity of the fidelity (Exercise 9.19) and its concavity in the first +argument (Exercise 9.20). -/ +theorem State.sum_sqrt_mul_fidelity_le_fidelity_mix {ι : Type*} [Fintype ι] + (p q : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hq : ∀ i, 0 ≤ q i) + (hps : ∑ i, p i = 1) (hqs : ∑ i, q i = 1) (ρ σ : ι → State S) : + ∑ i, Real.sqrt (p i * q i) * (ρ i).fidelity (σ i) + ≤ (State.mix p hp hps ρ).fidelity (State.mix q hq hqs σ) := by + rw [State.fidelity_eq_traceNorm, State.mix_op, State.mix_op] + simp_rw [State.fidelity_eq_traceNorm] + exact ContinuousLinearMap.traceNorm_cfc_sqrt_mul_cfc_sqrt_sum_ge + (fun i => (ρ i).op) (fun i => (σ i).op) + (fun i => (ρ i).isDensity.nonneg) (fun i => (σ i).isDensity.nonneg) p q hp hq + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/AdaptiveMeasurement.lean b/LeanPool/AxQM/Postulates/API/AdaptiveMeasurement.lean new file mode 100644 index 0000000000..1cf4c16e42 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/AdaptiveMeasurement.lean @@ -0,0 +1,238 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CascadedMeasurement +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# AxQM — the adaptive cascade of measurements (dependent Exercise 2.57) + +The **adaptive cascade** `L.adaptiveCascade M`: given a measurement `L` with outcomes `κ` +and, for *each* outcome `j : κ`, a measurement `M j` with outcomes `μ j` (the second measurement is +allowed to *depend on the first outcome*), the composite that measures `L` and then the +outcome-dependent `M j` is itself a single measurement, with outcome set the sigma type +`Σ j, μ j` and operators + + `N₍ⱼ,ₖ₎ = (M j)ₖ Lⱼ`. + +This is the dependent generalization of the fixed cascade `Measurement.cascade` +(`AxQM/Postulates/API/CascadedMeasurement.lean`, Nielsen–Chuang Exercise 2.57): `cascade` uses +one fixed second measurement for every first outcome (`κ × μ`), whereas here the second +measurement — and even its outcome set — varies with `j`, so the joint outcome set is a sigma +type rather than a product. +It is exactly the "combine all of Alice's measurements into one single measurement (Exercise 2.57)" +step of Nielsen–Chuang Proposition 12.14, where the second measurement Alice performs is chosen +conditionally on the result she has already obtained. + +Completeness of the composite family chains the given completeness relations exactly as for the +fixed cascade, now summing over the sigma type: +`∑₍ⱼ,ₖ₎ N₍ⱼ,ₖ₎† N₍ⱼ,ₖ₎ = ∑ⱼ Lⱼ† (∑ₖ (M j)ₖ† (M j)ₖ) Lⱼ = ∑ⱼ Lⱼ† Lⱼ = 1`, so `adaptiveCascade` +produces a genuine `Measurement (Σ j, μ j) S`. + +Alongside the operator identities (`adaptiveCascade_op`, `postOp_adaptiveCascade`) this file +records the two physical-equivalence laws — the joint Born probability factorizes as +`p(j,k) = p(j)·p(k∣j)` (`adaptiveCascade_bornProb`) and the joint collapse equals the sequential one +(`adaptiveCascade_postMeasurement`). They are stated for `Measurement`, `State`, `bornProb` and +`postMeasurement`, and are the dependent analogues of `cascade_bornProb` / +`cascade_postMeasurement` ([upstream `AxQM/NC/Ch2/Exercise2_57.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_57.lean)). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {κ : Type*} [Fintype κ] {μ : κ → Type*} [∀ j, Fintype (μ j)] {S : QSystem} + +namespace Measurement + +/-- The **adaptive cascade** of a measurement `L` (outcomes `κ`) with an outcome-dependent family of +measurements `M j` (outcomes `μ j`): the single measurement with outcome set `Σ j, μ j` whose +operator for outcome `⟨j, k⟩` is `N₍ⱼ,ₖ₎ = (M j)ₖ Lⱼ`. This is the dependent version of +`Measurement.cascade` (Exercise 2.57), where the second measurement is chosen conditionally on the +first outcome `j`. Completeness `∑₍ⱼ,ₖ₎ N₍ⱼ,ₖ₎† N₍ⱼ,ₖ₎ = 1` chains the completeness relations of the +`M j` and of `L`. -/ +def adaptiveCascade (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) : + Measurement (Σ j, μ j) S where + op p := ((M p.1).op p.2).comp (L.op p.1) + complete := by + rw [← L.complete, ← Finset.univ_sigma_univ, Finset.sum_sigma] + refine Finset.sum_congr rfl fun j _ => ?_ + have hsummand : ∀ k : μ j, + (adjoint (((M j).op k).comp (L.op j))).comp (((M j).op k).comp (L.op j)) + = (adjoint (L.op j)).comp + (((adjoint ((M j).op k)).comp ((M j).op k)).comp (L.op j)) := + fun k => by rw [adjoint_comp, comp_assoc, comp_assoc] + simp only [hsummand] + rw [← ContinuousLinearMap.comp_finsetSum, ← ContinuousLinearMap.finsetSum_comp, + (M j).complete, ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp] + +@[simp] +theorem adaptiveCascade_op (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (j : κ) (k : μ j) : + (L.adaptiveCascade M).op ⟨j, k⟩ = ((M j).op k).comp (L.op j) := rfl + +/-- The post-measurement operation of the adaptive cascade factors through the two individual +post-measurement operations: `E₍ⱼ,ₖ₎(ρ) = (M j)ₖ Lⱼ ρ Lⱼ† (M j)ₖ† = Eₖ(Eⱼ(ρ))`. The operator +identity underlying both physical-equivalence laws. -/ +theorem postOp_adaptiveCascade (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (ρ : S →L[ℂ] S) (j : κ) (k : μ j) : + ContinuousLinearMap.postOp (L.adaptiveCascade M).op ρ ⟨j, k⟩ + = ContinuousLinearMap.postOp (M j).op (ContinuousLinearMap.postOp L.op ρ j) k := by + simp only [ContinuousLinearMap.postOp, adaptiveCascade_op, adjoint_comp, comp_assoc] + +/-- **Adaptive cascade: probabilities chain.** The Born probability of the single adaptive-cascade +measurement `L.adaptiveCascade M` for the joint outcome `⟨j, k⟩` equals the probability `p(j)` of +outcome `j` under `L` times the probability `p(k ∣ j)` of outcome `k` under the conditionally chosen +measurement `M j`, computed in the post-measurement state `L.postMeasurement ρ j` — the chained +probability `p(j, k) = p(j) · p(k ∣ j)`. The dependent analogue of `cascade_bornProb`. -/ +theorem adaptiveCascade_bornProb (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (ρ : State S) (j : κ) (k : μ j) (hl : L.bornProb ρ j ≠ 0) : + (L.adaptiveCascade M).bornProb ρ ⟨j, k⟩ + = L.bornProb ρ j * (M j).bornProb (L.postMeasurement ρ j hl) k := by + have hp : RCLike.re (LinearMap.trace ℂ S + (ContinuousLinearMap.postOp L.op ρ.op j : S →ₗ[ℂ] S)) ≠ 0 := by + rw [← Measurement.bornProb_eq_re_trace_postOp]; exact hl + have key : (M j).bornProb (L.postMeasurement ρ j hl) k + = (RCLike.re (LinearMap.trace ℂ S (ContinuousLinearMap.postOp L.op ρ.op j : S →ₗ[ℂ] S)))⁻¹ + * RCLike.re (LinearMap.trace ℂ S + (ContinuousLinearMap.postOp (M j).op (ContinuousLinearMap.postOp L.op ρ.op j) k + : S →ₗ[ℂ] S)) := by + rw [Measurement.bornProb_eq_re_trace_postOp, Measurement.postMeasurement_op, + ContinuousLinearMap.postState, ContinuousLinearMap.postOp_smul, + ContinuousLinearMap.toLinearMap_smul, + map_smul, smul_eq_mul] + simp + rw [Measurement.bornProb_eq_re_trace_postOp (L.adaptiveCascade M), + Measurement.postOp_adaptiveCascade, Measurement.bornProb_eq_re_trace_postOp L, key, + mul_inv_cancel_left₀ hp] + +/-- **Adaptive cascade: states chain.** The post-measurement `State` of the single adaptive-cascade +measurement `L.adaptiveCascade M` for the joint outcome `⟨j, k⟩` equals the state obtained by +collapsing first under `L` (outcome `j`) and then under the conditionally chosen measurement `M j` +(outcome `k`). Together with `adaptiveCascade_bornProb` this is the physical equivalence of the +adaptive cascade and the sequential adaptive procedure. The dependent analogue of +`cascade_postMeasurement`. -/ +theorem adaptiveCascade_postMeasurement (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (ρ : State S) (j : κ) (k : μ j) (hl : L.bornProb ρ j ≠ 0) + (hm : (M j).bornProb (L.postMeasurement ρ j hl) k ≠ 0) : + (L.adaptiveCascade M).postMeasurement ρ ⟨j, k⟩ + (by rw [adaptiveCascade_bornProb L M ρ j k hl]; exact mul_ne_zero hl hm) + = (M j).postMeasurement (L.postMeasurement ρ j hl) k hm := by + have hp : RCLike.re (LinearMap.trace ℂ S + (ContinuousLinearMap.postOp L.op ρ.op j : S →ₗ[ℂ] S)) ≠ 0 := by + rw [← Measurement.bornProb_eq_re_trace_postOp]; exact hl + apply State.ext + simp only [Measurement.postMeasurement_op] + have hLunfold : ContinuousLinearMap.postState L.op ρ.op j + = ((RCLike.re (LinearMap.trace ℂ S + (ContinuousLinearMap.postOp L.op ρ.op j : S →ₗ[ℂ] S)))⁻¹ : ℂ) + • ContinuousLinearMap.postOp L.op ρ.op j := rfl + rw [hLunfold, ← Complex.ofReal_inv, + ContinuousLinearMap.postState_smul (M j).op (ContinuousLinearMap.postOp L.op ρ.op j) k + (inv_ne_zero hp), + ContinuousLinearMap.postState, ContinuousLinearMap.postState, + Measurement.postOp_adaptiveCascade] + +/-- **Adaptive cascade: states chain, with the joint possibility supplied explicitly.** The variant +of `adaptiveCascade_postMeasurement` taking the joint-outcome possibility `hjoint` as an explicit +hypothesis instead of the `adaptiveCascade_bornProb`-derived proof embedded in its statement. +Interchangeable with `adaptiveCascade_postMeasurement` by proof irrelevance, but keeping `hjoint` +opaque matters when the cascade is instantiated at a large, deeply-composed measurement: with the +derived proof in the statement, the kernel re-verifies it at every use (unfolding the cascade's +operators — a heavy defeq); with `hjoint` opaque it never does. -/ +theorem adaptiveCascade_postMeasurement' (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (ρ : State S) (j : κ) (k : μ j) (hl : L.bornProb ρ j ≠ 0) + (hm : (M j).bornProb (L.postMeasurement ρ j hl) k ≠ 0) + (hjoint : (L.adaptiveCascade M).bornProb ρ ⟨j, k⟩ ≠ 0) : + (L.adaptiveCascade M).postMeasurement ρ ⟨j, k⟩ hjoint + = (M j).postMeasurement (L.postMeasurement ρ j hl) k hm := + adaptiveCascade_postMeasurement L M ρ j k hl hm + +/-- **The adaptive cascade lifted to the left factor.** On `S ⊗ T`, measuring the adaptive cascade +`L.adaptiveCascade M` and then lifting to the left factor (`.onLeft T`) has the same operator at +`⟨j, k⟩` as first lifting each stage and cascading there: both equal +`((M j)ₖ Lⱼ) ⊗ 1 = ((M j)ₖ ⊗ 1)(Lⱼ ⊗ 1)`. This lets the reduction reason about a combined Alice +measurement lifted to the composite `A ⊗ B` by transporting the cascade laws +(`adaptiveCascade_bornProb` / `adaptiveCascade_postMeasurement`) along `bornProb_congr` / +`postMeasurement_congr`. -/ +theorem adaptiveCascade_onLeft_op (L : Measurement κ S) (M : (j : κ) → Measurement (μ j) S) + (T : QSystem) (j : κ) (k : μ j) : + ((L.adaptiveCascade M).onLeft T).op ⟨j, k⟩ + = ((L.onLeft T).adaptiveCascade (fun j => (M j).onLeft T)).op ⟨j, k⟩ := by + simp only [Measurement.onLeft_op, adaptiveCascade_op] + exact TensorProduct.mapL_mul_one ((M j).op k) (L.op j) + +/-- **Each measurement effect is bounded by the identity.** For a measurement `N` on `S` and an +outcome `k`, the POVM effect satisfies `Nₖ† Nₖ ≤ 1` in the Loewner order, since it is one +nonnegative summand of the completeness sum `∑ i, Nᵢ† Nᵢ = 1`. -/ +theorem op_adjoint_mul_self_le_one {ι : Type*} [Fintype ι] (N : Measurement ι S) (k : ι) : + ContinuousLinearMap.adjoint (N.op k) * N.op k ≤ 1 := by + have hApos : ∀ i : ι, + (0 : S →L[ℂ] S) ≤ (ContinuousLinearMap.adjoint (N.op i)).comp (N.op i) := + fun i => (ContinuousLinearMap.nonneg_iff_isPositive).2 + (ContinuousLinearMap.isPositive_adjoint_comp_self (N.op i)) + have h1 := Finset.single_le_sum + (f := fun i => (ContinuousLinearMap.adjoint (N.op i)).comp (N.op i)) + (fun i _ => hApos i) (Finset.mem_univ k) + rwa [N.complete] at h1 + +/-- **A single measurement outcome is trace non-increasing.** For a measurement `N` on `S`, a +positive operator `X`, and an outcome `k`, the real trace of the post-measurement operation +`Eₖ(X) = Nₖ X Nₖ†` is at most the real trace of `X`: +`re tr(Nₖ X Nₖ†) = re tr(Nₖ† Nₖ X) ≤ re tr(1 · X) = re tr(X)`, using cyclicity of the trace, the +completeness bound `Nₖ† Nₖ ≤ 1`, and monotonicity of the trace pairing against `X ≥ 0`. -/ +theorem re_trace_postOp_le {ι : Type*} [Fintype ι] (N : Measurement ι S) + (X : S →L[ℂ] S) (hX : (0 : S →L[ℂ] S) ≤ X) (k : ι) : + RCLike.re ((LinearMap.trace ℂ S) (ContinuousLinearMap.postOp N.op X k : S →ₗ[ℂ] S)) + ≤ RCLike.re ((LinearMap.trace ℂ S) (X : S →ₗ[ℂ] S)) := by + have hcyc : (LinearMap.trace ℂ S) (ContinuousLinearMap.postOp N.op X k : S →ₗ[ℂ] S) + = (LinearMap.trace ℂ S) + ((((ContinuousLinearMap.adjoint (N.op k)) * (N.op k)) * X : S →L[ℂ] S) : S →ₗ[ℂ] S) := by + simp only [ContinuousLinearMap.postOp, ← ContinuousLinearMap.mul_def] + rw [ContinuousLinearMap.trace_mul_comm (N.op k) (X * ContinuousLinearMap.adjoint (N.op k)), + mul_assoc, ContinuousLinearMap.trace_mul_comm X + (ContinuousLinearMap.adjoint (N.op k) * N.op k)] + rw [hcyc] + simpa using ContinuousLinearMap.re_trace_mul_mono_left (N.op_adjoint_mul_self_le_one k) hX + +/-- **The joint adaptive-cascade probability never exceeds the first-stage probability.** For the +adaptive cascade `L.adaptiveCascade M`, `p(j, k) ≤ p(j)`: measuring the second (conditional) +measurement after the first can only lose probability. This is the marginal bound +`p(j, k) = re tr((M j)ₖ (Lⱼ ρ Lⱼ†) (M j)ₖ†) ≤ re tr(Lⱼ ρ Lⱼ†) = p(j)` from `re_trace_postOp_le`. -/ +theorem adaptiveCascade_bornProb_le_fst (L : Measurement κ S) + (M : (j : κ) → Measurement (μ j) S) (ρ : State S) (j : κ) (k : μ j) : + (L.adaptiveCascade M).bornProb ρ ⟨j, k⟩ ≤ L.bornProb ρ j := by + rw [Measurement.bornProb_eq_re_trace_postOp, Measurement.bornProb_eq_re_trace_postOp, + Measurement.postOp_adaptiveCascade] + exact (M j).re_trace_postOp_le (ContinuousLinearMap.postOp L.op ρ.op j) + ((ContinuousLinearMap.nonneg_iff_isPositive).2 + (ContinuousLinearMap.postOp_isPositive L.op ρ.isPositive_op j)) k + +/-- **A possible joint outcome forces the first stage to be possible.** If the adaptive cascade's +joint outcome `⟨j, k⟩` has nonzero Born probability, then so does the first-stage outcome `j` +(`p(j, k) ≤ p(j)` with `p(j, k) > 0`). This discharges the zero-probability first-stage branches +when combining Alice's rounds into a single measurement in the Proposition 12.14 reduction. -/ +theorem adaptiveCascade_bornProb_fst_ne_zero (L : Measurement κ S) + (M : (j : κ) → Measurement (μ j) S) (ρ : State S) (j : κ) (k : μ j) + (h : (L.adaptiveCascade M).bornProb ρ ⟨j, k⟩ ≠ 0) : L.bornProb ρ j ≠ 0 := by + intro hL + have hle := adaptiveCascade_bornProb_le_fst L M ρ j k + rw [hL] at hle + exact h (le_antisymm hle ((L.adaptiveCascade M).bornProb_nonneg ρ ⟨j, k⟩)) + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ArakiLiebEqualityConditions.lean b/LeanPool/AxQM/Postulates/API/ArakiLiebEqualityConditions.lean new file mode 100644 index 0000000000..14ccbe018a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ArakiLiebEqualityConditions.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Support +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.ConditionalEntropyConcave +public import LeanPool.AxQM.Postulates.API.EntropyOrthogonalMixture + +/-! +# AxQM — vocabulary for the Araki–Lieb equality conditions (N&C Exercise 11.16) + +Nielsen & Chuang's Exercise 11.16 characterises when the triangle (Araki–Lieb) inequality +`S(A, B) ≥ S(B) − S(A)` is saturated, in terms of the marginals `ρ^A_i = tr_B(|i⟩⟨i|)` and +`ρ^B_i = tr_A(|i⟩⟨i|)` of the eigenprojectors of `ρ^{AB}`. This file supplies the two +predicates that phrasing needs — "the `ρ^A_i` have a common eigenbasis" and "the `ρ^B_i` have +orthogonal support" — together with the partial-trace / support facts that +[upstream `AxQM/NC/Ch11/Exercise11_16.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Exercise11_16.lean) uses to discharge them. + +## Main definitions + +* `AxQM.State.HasCommonEigenbasis` — a finite family of states `ρ : ι → State S` is + simultaneously diagonalisable: there is a single orthonormal basis `e` of `S.space` every vector + of which is an eigenvector (real eigenvalue) of every `ρ i`. This is the precise reading of + N&C's "the operators `ρ^A_i` have a common eigenbasis". +* `AxQM.State.OrthogonalSupports` — a finite family `ρ : ι → State S` has pairwise + orthogonal supports, `(ρ i).support ⟂ (ρ j).support` for `i ≠ j` (`State.support`, the range of + the density operator). N&C's "the `ρ^B_i` have orthogonal support". + +## Main results + +* `AxQM.State.support_isOrtho_toState_of_inner_eq_zero` — two pure states with orthogonal + vectors have orthogonal supports, `⟪ψ, φ⟫ = 0 → |ψ⟩⟨ψ|.support ⟂ |φ⟩⟨φ|.support`. +* `AxQM.State.reducedLeft_mix` / `State.reducedRight_mix` — the partial trace is linear: + the reduced state of a mixture `∑ᵢ pᵢ ρᵢ` is the mixture `∑ᵢ pᵢ (ρᵢ)_A` of the reduced states. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **A finite family of states has a common eigenbasis** — it is simultaneously diagonalisable. +There exists an **orthonormal basis** of `S.space` (a family `e : Fin n → S.space` that is +orthonormal and spans, `Submodule.span ℂ (Set.range e) = ⊤`) every vector `e k` of which is an +eigenvector, with a real eigenvalue, of *every* member `ρ i`: `(ρ i).op (e k) = c • e k`. This is +the precise reading of Nielsen & Chuang's phrase "the operators `ρ^A_i` have a common eigenbasis" +(Exercise 11.16). -/ +def State.HasCommonEigenbasis {ι : Type*} (ρ : ι → State S) : Prop := + ∃ (n : ℕ) (e : Fin n → S.space), Orthonormal ℂ e ∧ Submodule.span ℂ (Set.range e) = ⊤ ∧ + ∀ (i : ι) (k : Fin n), ∃ c : ℝ, (ρ i).op (e k) = (c : ℂ) • e k + +/-- **A finite family of states has pairwise orthogonal supports.** For `i ≠ j` the supports +`(ρ i).support`, `(ρ j).support` (the ranges of the density operators, `State.support`) are +orthogonal submodules. Nielsen & Chuang's "the `ρ^B_i` have orthogonal support" (Exercise 11.16). -/ +def State.OrthogonalSupports {ι : Type*} (ρ : ι → State S) : Prop := + Pairwise fun i j => (ρ i).support ⟂ (ρ j).support + +/-- **Orthogonal vectors give orthogonal supports for the associated pure states.** If the unit +vectors of two pure states are orthogonal, `⟪ψ.vec, φ.vec⟫ = 0`, then the supports of the rank-one +projectors `|ψ⟩⟨ψ|` and `|φ⟩⟨φ|` are orthogonal submodules. The support of `|ψ⟩⟨ψ|` is the range of +`rankOne ψ.vec ψ.vec`, i.e. the line `ℂ · ψ.vec`; two such lines are orthogonal exactly when the +vectors are. The building block behind the "orthogonal support" hypothesis of Exercise 11.16 for +families of orthonormal pure states. -/ +theorem State.support_isOrtho_toState_of_inner_eq_zero (ψ φ : PureState S) + (h : inner ℂ ψ.vec φ.vec = 0) : + ψ.toState.support ⟂ φ.toState.support := by + rw [Submodule.isOrtho_iff_inner_eq] + intro u hu v hv + simp only [State.support, PureState.toState_op, LinearMap.mem_range] at hu hv + obtain ⟨x, rfl⟩ := hu + obtain ⟨y, rfl⟩ := hv + simp only [ContinuousLinearMap.coe_coe, InnerProductSpace.rankOne_apply, inner_smul_left, + inner_smul_right, h, mul_zero] + +/-- **An orthonormal family of pure states has pairwise orthogonal supports.** If the state vectors +`(ψ i).vec` are orthonormal, then the rank-one projectors `(ψ i).toState = |ψᵢ⟩⟨ψᵢ|` have pairwise +orthogonal supports (each pair of distinct vectors is orthogonal, so +`State.support_isOrtho_toState_of_inner_eq_zero` applies). The bridge from an orthonormal +eigen/Schmidt frame to the `OrthogonalSupports` / `vonNeumannEntropy_mix_orthogonalSupport` +hypotheses. -/ +theorem State.pairwise_support_isOrtho_of_orthonormal {ι : Type*} + (ψ : ι → PureState S) (h : Orthonormal ℂ fun i => (ψ i).vec) : + Pairwise fun i j => (ψ i).toState.support ⟂ (ψ j).toState.support := fun _ _ hij => + State.support_isOrtho_toState_of_inner_eq_zero _ _ (h.2 hij) + +/-- **The von Neumann entropy of a mixture of an orthonormal family of pure states is the Shannon +entropy of the mixing weights**: `S(∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|) = H(p)` when the `(ψ i).vec` are orthonormal. +The pure-component specialization of `State.vonNeumannEntropy_mix_orthogonalSupport` (each component +has zero entropy and the family has orthogonal supports by +`pairwise_support_isOrtho_of_orthonormal`), so the general `H(p) + ∑ᵢ pᵢ S(ρᵢ)` collapses to +`H(p)`. -/ +theorem State.vonNeumannEntropy_mix_toState_orthonormal {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ψ : ι → PureState S) + (h : Orthonormal ℂ fun i => (ψ i).vec) : + (State.mix p hp hsum (fun i => (ψ i).toState)).vonNeumannEntropy = Real.entropy p := by + rw [State.vonNeumannEntropy_mix_orthogonalSupport _ _ _ _ + (State.pairwise_support_isOrtho_of_orthonormal ψ h)] + simp only [PureState.vonNeumannEntropy_toState_eq_zero, mul_zero, Finset.sum_const_zero, add_zero] + +/-- **The partial trace over the right factor is linear on mixtures**: the left reduced state of a +mixture `∑ᵢ pᵢ ρᵢ` is the mixture `∑ᵢ pᵢ (ρᵢ)_A` of the left reduced states. Both `.op`s are +`∑ᵢ pᵢ · Tr_T(ρᵢ.op)` — the operator-level linearity `State.mix_reducedLeft_op` (built on the +structural `LinearMap.partialTraceRight_sum_smul`) plus the mixture bridge `State.mix_op`. -/ +theorem State.reducedLeft_mix {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State (S ⊗ T)) : + (State.mix p hp hsum ρ).reducedLeft = State.mix p hp hsum (fun i => (ρ i).reducedLeft) := by + ext1 + rw [State.mix_reducedLeft_op, State.mix_op] + +/-- **The partial trace over the left factor is linear on mixtures**: the right reduced state of a +mixture `∑ᵢ pᵢ ρᵢ` is the mixture `∑ᵢ pᵢ (ρᵢ)_B` of the right reduced states. The `reducedRight` +analogue of `State.reducedLeft_mix`, via the operator-level linearity `State.mix_reducedRight_op` +and the mixture bridge `State.mix_op`. -/ +theorem State.reducedRight_mix {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State (S ⊗ T)) : + (State.mix p hp hsum ρ).reducedRight = State.mix p hp hsum (fun i => (ρ i).reducedRight) := by + ext1 + rw [State.mix_reducedRight_op, State.mix_op] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Associator.lean b/LeanPool/AxQM/Postulates/API/Associator.lean new file mode 100644 index 0000000000..b7b9f0290a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Associator.lean @@ -0,0 +1,113 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# AxQM — the associator system isomorphism `A ⊗ (B ⊗ C) ≃ₛ (A ⊗ B) ⊗ C` + +Composite systems built by the binary tensor `⊗` (`QSystem.compose`) are literally +right-nested or left-nested tensor products of the underlying spaces; the physicist regards +`A ⊗ (B ⊗ C)` and `(A ⊗ B) ⊗ C` as the same tripartite system. The **associator** +`QSystem.assoc` is the `QSystem.Iso` witnessing this, so a state / observable / … on one +nesting can be transported to the other via the `*.congr` transport of +`AxQM.Postulates.SystemIso`. + +The underlying isometry is `(TensorProduct.assocIsometry ℂ A.space B.space C.space).symm` +(the inner-product-space associator `(A ⊗ B) ⊗ C ≃ₗᵢ A ⊗ (B ⊗ C)`, reversed). + +It is the structural conversion the strong-subadditivity route needs: the tripartite state +lives on the right-nested `A ⊗ (B ⊗ C)`, but the `A ⊗ B`-marginal is read off after +re-associating to `(A ⊗ B) ⊗ C` and tracing out `C` +(see `AxQM/Postulates/API/StrongSubadditivity.lean`). + +## Main definitions + +* `AxQM.QSystem.assoc` — the associator system isomorphism + `A ⊗ (B ⊗ C) ≃ₛ (A ⊗ B) ⊗ C`. +* `AxQM.QSystem.Iso.tmul` — the tensor product of two system isomorphisms, + `(S ⊗ T) ≃ₛ (S' ⊗ T')`, the `⊗` of the transport backbone (a sibling of + `QSystem.Iso.refl/symm/trans` and `QSystem.assoc`); it lets a structural conversion on one + factor act inside a composite while the other factor is untouched. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable (A B C : QSystem) + +/-- The **associator** system isomorphism `A ⊗ (B ⊗ C) ≃ₛ (A ⊗ B) ⊗ C`: the two nestings +of the tripartite composite are the same quantum system, re-bracketed. The underlying isometry +is the reversed inner-product associator +`(TensorProduct.assocIsometry ℂ A.space B.space C.space).symm`. -/ +def QSystem.assoc : (A ⊗ (B ⊗ C)) ≃ₛ ((A ⊗ B) ⊗ C) := + ⟨(TensorProduct.assocIsometry ℂ A.space B.space C.space).symm⟩ + +@[simp] +theorem QSystem.assoc_toIsometry : + (QSystem.assoc A B C).toIsometry = + (TensorProduct.assocIsometry ℂ A.space B.space C.space).symm := + rfl + +/-- The associator's **inverse** isometry is the *forward* `assocIsometry` (the two `.symm`s +cancel): `(QSystem.assoc A B C).symm.toIsometry = TensorProduct.assocIsometry ℂ …`. The `.symm` +companion of `QSystem.assoc_toIsometry`; extracted because the purification / marginal proofs that +re-associate a left-nested composite `(A ⊗ B) ⊗ C → A ⊗ (B ⊗ C)` repeatedly need it to expose the +transported operator as a forward-associator conjugation. -/ +@[simp] +theorem QSystem.assoc_symm_toIsometry : + (QSystem.assoc A B C).symm.toIsometry = + TensorProduct.assocIsometry ℂ A.space B.space C.space := + LinearIsometryEquiv.symm_symm _ + +/-- The **associator on a pure double tensor**: `(assoc A B C)(a ⊗ (b ⊗ c)) = (a ⊗ b) ⊗ c`. +Re-brackets a right-nested pure tensor to the left-nested form (the content of +`QSystem.assoc`, via `TensorProduct.assoc_symm_tmul`). -/ +theorem assoc_toIsometry_tmul_tmul {A B C : QSystem} (a : A.space) (b : B.space) (c : C.space) : + (QSystem.assoc A B C).toIsometry (a ⊗ₜ[ℂ] (b ⊗ₜ[ℂ] c)) = (a ⊗ₜ[ℂ] b) ⊗ₜ[ℂ] c := by + rw [QSystem.assoc_toIsometry]; exact TensorProduct.assoc_symm_tmul a b c + +/-- The **tensor product of two system isomorphisms** `e : S ≃ₛ S'` and `f : T ≃ₛ T'`, a system +isomorphism `(S ⊗ T) ≃ₛ (S' ⊗ T')` whose underlying isometry is +`TensorProduct.congrIsometry e.toIsometry f.toIsometry`. The `⊗` of the transport backbone: it +lets a structural conversion on one factor (e.g. an associator) act inside a composite while the +other factor is left untouched — the direct sibling of `QSystem.Iso.refl/symm/trans`. -/ +def QSystem.Iso.tmul {S S' T T' : QSystem} (e : S ≃ₛ S') (f : T ≃ₛ T') : + (S ⊗ T) ≃ₛ (S' ⊗ T') := + ⟨TensorProduct.congrIsometry e.toIsometry f.toIsometry⟩ + +/-- The action of `QSystem.Iso.tmul e f` on a pure tensor: `(e ⊗ f)(x ⊗ y) = e x ⊗ f y`. -/ +@[simp] +theorem QSystem.Iso.tmul_toIsometry_tmul {S S' T T' : QSystem} (e : S ≃ₛ S') (f : T ≃ₛ T') + (x : S.space) (y : T.space) : + (QSystem.Iso.tmul e f).toIsometry (x ⊗ₜ[ℂ] y) + = e.toIsometry x ⊗ₜ[ℂ] f.toIsometry y := + TensorProduct.congrIsometry_tmul e.toIsometry f.toIsometry x y + +/-- The tensor of two identity isomorphisms is the identity: `(refl S ⊗ refl T) = refl (S ⊗ T)` +(mirroring `TensorProduct.congrIsometry_refl_refl`). -/ +@[simp] +theorem QSystem.Iso.tmul_refl_refl (S T : QSystem) : + QSystem.Iso.tmul (QSystem.Iso.refl S) (QSystem.Iso.refl T) = QSystem.Iso.refl (S ⊗ T) := + congrArg QSystem.Iso.mk TensorProduct.congrIsometry_refl_refl + +/-- The inverse of a tensor of isomorphisms is the tensor of the inverses: +`(e ⊗ f)⁻¹ = e⁻¹ ⊗ f⁻¹` (mirroring `TensorProduct.congrIsometry_symm`). -/ +theorem QSystem.Iso.tmul_symm {S S' T T' : QSystem} (e : S ≃ₛ S') (f : T ≃ₛ T') : + (QSystem.Iso.tmul e f).symm = QSystem.Iso.tmul e.symm f.symm := + congrArg QSystem.Iso.mk (TensorProduct.congrIsometry_symm e.toIsometry f.toIsometry) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/AvgOutputTypicalSubspace.lean b/LeanPool/AxQM/Postulates/API/AvgOutputTypicalSubspace.lean new file mode 100644 index 0000000000..647aae7fa5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/AvgOutputTypicalSubspace.lean @@ -0,0 +1,202 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspace +public import LeanPool.AxQM.Postulates.API.Mixture + +/-! +# The average-output typical subspace projector, `piTensor`-native (N&C Theorem 12.8, Box 12.5) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, Box 12.5), the decoding measurement is built from the **typical subspace projector** +`P` of the *average output state* `σ_bar = ∑ₐ pₐ E(ρₐ)`, applied to the `n`-use output block, +together +with the **conditional typical subspace projectors** `P_M` of the individual product codewords +`σ_M = ⨂ᵢ E(ρ_{Mᵢ})`. + +These two operators are born on *definitionally equal but syntactically distinct* systems: the +average-output projector `σ_bar.typicalSubspaceProj n ε` lives on `S ^⊗ₛ n` (the `n`-fold tensor +**power**), while `State.condTypicalSubspaceProj` and the pretty-good decoder `POVM.prettyGood` +live on `⨂ₛ _ : Fin n, S` (the indexed tensor **product** of the constant family). The two systems +are equal by `QSystem.tensorPow_eq` — a `rfl` identity — but the `binop%`/coercion elaborator, which +unifies at *reducible* transparency, cannot bridge them, so a raw `QSystem.tensorPow_eq ▸ …` +transport left in a statement makes every later operator product re-run the cross-system +`▸`-match and time out. + +This file introduces the projector **once**, as an opaque `piTensor`-native definition, and proves +the handful of facts the pretty-good product-state code and its code-level expected-error bound +need, so those consumers use `avgOutputTypicalProj` as an atom — never the `▸`-blob. + +## What this file provides + +* `State.avgOutputTypicalProj p hp hsum E ρ n ε` — the average-output ε-typical subspace projector + `P = σ_bar.typicalSubspaceProj n ε` **presented on `⨂ₛ _ : Fin n, S`**, definitionally the + `QSystem.tensorPow_eq`-transport of `σ_bar.typicalSubspaceProj n ε` (`avgOutputTypicalProj_eq`), + for + `σ_bar = State.mix p hp hsum (fun a => E (ρ a))`. + +* `State.avgOutputTypicalProj_isSelfAdjoint` / `_idem` — `P` is a self-adjoint idempotent (an + orthogonal projection), inherited from `State.typicalSubspaceProj_isSelfAdjoint`/`_idem` across + the defeq transport. These are exactly the `IsSelfAdjoint P` / `P ∘ P = P` hypotheses of the + per-code + and expected-error bounds (`State.avgError_prettyGood_le_re_trace_percode`, + `State.expectation_avgError_prettyGood_le`). + +* `State.avgOutputTypicalProj_condTypical_conj_nonneg` — `0 ≤ P (P_M) P` for any product codeword's + conditional typical projector `P_M = State.condTypicalSubspaceProj σ s ε'`: the positivity of the + decoder family `A_{M'} = P P_{M'} P` (from which `POVM.prettyGood A` is assembled), via + `IsPositive.adjoint_conj` and self-adjointness of `P`. This discharges the `hA` hypothesis of + those bounds. + +* `State.re_trace_one_sub_avgOutputTypicalProj_tensorPow_eq` — the typical-weight trace identity + `re tr((1 − P) σ_bar^⊗n) = 1 − Pr[σ_bar^⊗n typical]`, expressing the first ("typical defect") term + of the HSW expected-error bound (N&C eq. (12.80)) as one minus the Born probability that + `σ_bar^⊗n` + lies in its own ε-typical subspace (`State.typicalSubspaceMeasurement`). Done once here, across + the change of representation, so that it is a clean rewrite against the typical-subspace + weight bound `tr((1 − P) σ_bar^⊗n) ≤ δ`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The average-output ε-typical subspace projector, `piTensor`-native** (Nielsen & Chuang, +Theorem 12.8, Box 12.5). For an input ensemble `{pₐ, ρₐ}`, quantum operation `E`, block length +`n`, and threshold `ε`, this is the ε-typical subspace projector `P(n, ε)` of the **average output +state** `σ_bar = ∑ₐ pₐ E(ρₐ)` (`State.mix p hp hsum (fun a => E (ρ a))`), presented as a continuous +linear +endomorphism of the indexed tensor product `⨂ₛ _ : Fin n, S` rather than the tensor power +`S ^⊗ₛ n`. + +Definitionally it is the `QSystem.tensorPow_eq S n`-transport of `σ_bar.typicalSubspaceProj n ε` +(`avgOutputTypicalProj_eq`); the two systems `S ^⊗ₛ n` and `⨂ₛ _ : Fin n, S` are equal by `rfl`. +The point of naming it is to hide that transport behind an opaque definition, so that the +pretty-good product-state decoder — which lives natively on `⨂ₛ _ : Fin n, S` alongside the +conditional typical projectors `State.condTypicalSubspaceProj` — can conjugate against `P` without +the cross-system +`▸`-match re-firing (and timing out) at every operator product. -/ +def State.avgOutputTypicalProj (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) : + (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space := + QSystem.tensorPow_eq S n ▸ (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj n ε + +/-- **Defining unfold of `avgOutputTypicalProj`**: it is the `QSystem.tensorPow_eq`-transport of the +average output state's typical subspace projector `σ_bar.typicalSubspaceProj n ε`. A `rfl` +identity; +the shape in which `State.expectation_avgError_prettyGood_le` (N&C eqs. (12.80)–(12.82)) takes its +typical projector, so instantiating that bound at `P = avgOutputTypicalProj` discharges its +`P = QSystem.tensorPow_eq S n ▸ σ_bar.typicalSubspaceProj n ε` hypothesis by `rfl`. -/ +theorem State.avgOutputTypicalProj_eq (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) : + State.avgOutputTypicalProj p hp hsum E ρ n ε + = QSystem.tensorPow_eq S n ▸ (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj n ε := + rfl + +/-- The average-output typical subspace projector `P` is **self-adjoint** (an orthonormal +projector), inherited from `State.typicalSubspaceProj_isSelfAdjoint` across the `rfl` transport. +Discharges the `IsSelfAdjoint P` hypothesis of the pretty-good per-code / expected-error bounds. -/ +theorem State.avgOutputTypicalProj_isSelfAdjoint (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) + (hsum : ∑ a, p a = 1) (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) : + IsSelfAdjoint (State.avgOutputTypicalProj p hp hsum E ρ n ε) := + (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj_isSelfAdjoint n ε + +/-- The average-output typical subspace projector `P` is **idempotent**, `P ∘ P = P` (an orthonormal +projector), inherited from `State.typicalSubspaceProj_idem` across the `rfl` transport. Discharges +the `P ∘ P = P` hypothesis of the pretty-good per-code / expected-error bounds. -/ +theorem State.avgOutputTypicalProj_idem (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) : + (State.avgOutputTypicalProj p hp hsum E ρ n ε).comp + (State.avgOutputTypicalProj p hp hsum E ρ n ε) + = State.avgOutputTypicalProj p hp hsum E ρ n ε := + (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj_idem n ε + +/-- **Positivity of the pretty-good decoder family** `A_{M'} = P P_{M'} P` (Nielsen & Chuang, +Theorem 12.8, Box 12.5, eq. (12.78)). For the average-output typical projector +`P = avgOutputTypicalProj …` and any product codeword's conditional typical projector +`P_{M'} = State.condTypicalSubspaceProj σ s ε'`, the conjugate `P P_{M'} P` is a positive operator. + +`P_{M'}` is a self-adjoint idempotent, hence positive +(`ContinuousLinearMap.IsIdempotentElem.isPositive_iff_isSelfAdjoint`); conjugating a positive +operator by the self-adjoint `P` (`ContinuousLinearMap.IsPositive.adjoint_conj`, using `P† = P`) +keeps it positive. This is exactly the family-positivity hypothesis `hA` of +`State.avgError_prettyGood_le_re_trace_percode` and `State.expectation_avgError_prettyGood_le`, from +which the square-root decoder `POVM.prettyGood A` is assembled. -/ +theorem State.avgOutputTypicalProj_condTypical_conj_nonneg (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) + (hsum : ∑ a, p a = 1) (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) + (σ : Fin n → State S) (s ε' : ℝ) : + (0 : (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) + ≤ (State.avgOutputTypicalProj p hp hsum E ρ n ε).comp + ((State.condTypicalSubspaceProj σ s ε').comp + (State.avgOutputTypicalProj p hp hsum E ρ n ε)) := by + have hPsa := State.avgOutputTypicalProj_isSelfAdjoint p hp hsum E ρ n ε + have h := (State.condTypicalSubspaceProj_isPositive σ s ε').adjoint_conj + (State.avgOutputTypicalProj p hp hsum E ρ n ε) + rw [hPsa.adjoint_eq] at h + exact ContinuousLinearMap.nonneg_iff_isPositive.mpr h + +/-- **The typical-defect trace identity** (Nielsen & Chuang, Theorem 12.8, Box 12.5, the first term +of eq. (12.80)). The average-output typical-defect trace `re tr((1 − P) σ_bar^⊗n)` equals one minus +the Born probability that the average output block `σ_bar^⊗n` lies in its own ε-typical subspace: + +`re tr((1 − P) σ_bar^⊗n) = 1 − Pr[σ_bar^⊗n ∈ T(n, ε)]`, + +where `P = avgOutputTypicalProj …` and the right-hand probability is the `true` outcome of +`σ_bar.typicalSubspaceMeasurement n ε` on `σ_bar^⊗n`. The left-hand side is exactly the first +summand of +`State.expectation_avgError_prettyGood_le`, transported to the `⨂ₛ _ : Fin n, S` system. + +Proof: split `re tr((1 − P)·A) = re tr A − re tr(P·A)` (`ContinuousLinearMap.re_trace_one_sub_mul`); +`re tr A = 1` since `A = σ_bar^⊗n.op` is a state (`State.trace_op_eq_one`), and `re tr(P·A)` is the +typical Born probability (`State.typicalSubspaceMeasurement_bornProb_eq_re_trace`, since `P` unfolds +to `σ_bar.typicalSubspaceProj n ε`). Both traces are read across the `rfl` transport of the average +output operator to `⨂ₛ _ : Fin n, S`. -/ +theorem State.re_trace_one_sub_avgOutputTypicalProj_tensorPow_eq (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) + (hsum : ∑ a, p a = 1) (E : State S → State S) (ρ : α → State S) (n : ℕ) (ε : ℝ) : + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.avgOutputTypicalProj p hp hsum E ρ n ε) * + (QSystem.tensorPow_eq S n ▸ ((State.mix p hp hsum fun a => E (ρ a)).tensorPow n).op)) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) + = 1 - ((State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceMeasurement n ε).bornProb + ((State.mix p hp hsum fun a => E (ρ a)).tensorPow n) true := by + set σbar := State.mix p hp hsum fun a => E (ρ a) + rw [ContinuousLinearMap.re_trace_one_sub_mul] + have h1 : RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) = 1 := by + have ht : (LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) = 1 := + (σbar.tensorPow n).trace_op_eq_one + rw [ht]; exact RCLike.one_re + have h2 : RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(State.avgOutputTypicalProj p hp hsum E ρ n ε * + (QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op)) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) + = (σbar.typicalSubspaceMeasurement n ε).bornProb (σbar.tensorPow n) true := by + rw [σbar.typicalSubspaceMeasurement_bornProb_eq_re_trace n ε (σbar.tensorPow n), + State.avgOutputTypicalProj_eq] + rfl + rw [h1, h2] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/AxisAngleGateValues.lean b/LeanPool/AxQM/Postulates/API/AxisAngleGateValues.lean new file mode 100644 index 0000000000..90b88a5792 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/AxisAngleGateValues.lean @@ -0,0 +1,83 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.AxisAngleRotation +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Concrete.AxisAngleGateValues + +/-! +# AxQM.Postulates.API — Exercise 4.8(2,3): the axis-angle values for `H` and `S` + +The content of parts 2 and 3 of Nielsen & Chuang, Exercise 4.8: the operator-level +identities pinning the axis-angle parameters `α, θ, n̂` in `U = e^{iα} R_n̂(θ)` (eq. 4.9) for the +Hadamard gate `H` and the phase gate `S = diag(1, i)`. + +* `sGate` — the **phase gate** `S = diag(1, i)` as an `Evolution qubit`, promoting the concrete + matrix `Concrete.sMatrix` through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; unitarity + (the `Evolution` obligation) is transported from `Concrete.sMatrix_mem_unitaryGroup`, exactly as + for `hadamardGate`/`tGate`. `sGate_op` is its `simp` bridge to the underlying operator. +* `hadamardGate_op_eq_expPiDivTwo_smul_rotAxisGate` — **Exercise 4.8(2)** at the operator level: + `H = e^{iπ/2} • R_{(1/√2, 0, 1/√2)}(π)` (`α = π/2`, `θ = π`, `n̂ = (1/√2, 0, 1/√2)`). +* `sGate_op_eq_expPiDivFour_smul_rotZGate` — **Exercise 4.8(3)** at the operator level: + `S = e^{iπ/4} • R_z(π/2)` (`α = π/4`, `θ = π/2`, `n̂ = e_z`). + +Each identity is the image, under the `ℂ`-linear `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` +(which preserves the scalar), of the concrete matrix identity in +`AxQM/Concrete/AxisAngleGateValues.lean`. +The gates used are `rotAxisGate` (`AxQM/Postulates/API/BlochRotationGate.lean`) for the general +axis of `H` and `rotZGate` (`AxQM/Postulates/API/PiEighthGate.lean`) for the `e_z` axis of `S`. + +The operator statements keep the explicit phase; the physically observable channel reading — that +`H` and `S` *are* these rotations, the phase being unobservable — is in +[upstream `AxQM/NC/Ch4/Exercise4_8.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_8.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **phase gate** `S = diag(1, i)` as a closed-system evolution of the `qubit` (Nielsen & +Chuang, §4.2). Its operator is the concrete matrix `Concrete.sMatrix` promoted through the +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; unitarity — the `Evolution` proof obligation — is +transported from `Concrete.sMatrix_mem_unitaryGroup`, exactly as for `hadamardGate`/`tGate`. -/ +def sGate : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) Concrete.sMatrix_mem_unitaryGroup + +@[simp] +theorem sGate_op : sGate.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix := rfl + +/-- **Nielsen & Chuang, Exercise 4.8(2) at the operator level.** The Hadamard gate is `e^{iπ/2}` +times the axis rotation by `θ = π` about `n̂ = (1/√2, 0, 1/√2)`: +`H = e^{iπ/2} • R_{(1/√2, 0, 1/√2)}(π)` (`α = π/2`, `θ = π`). The image under the `ℂ`-linear +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM` of the matrix identity +`Concrete.hadamardC_eq_expPiDivTwo_smul_rotAxis`. -/ +theorem hadamardGate_op_eq_expPiDivTwo_smul_rotAxisGate : + hadamardGate.op = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) • + (rotAxisGate ![(Real.sqrt 2)⁻¹, 0, (Real.sqrt 2)⁻¹] Real.pi).op := by + rw [hadamardGate_op, rotAxisGate_op, Concrete.hadamardC_eq_expPiDivTwo_smul_rotAxis] + exact map_smul _ _ _ + +/-- **Nielsen & Chuang, Exercise 4.8(3) at the operator level.** The phase gate `S = diag(1, i)` is +`e^{iπ/4}` times the `e_z`-axis rotation by `θ = π/2`: `S = e^{iπ/4} • R_z(π/2)` (`α = π/4`, +`θ = π/2`, `n̂ = e_z`). The image under the `ℂ`-linear `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM` +of the matrix identity `Concrete.sMatrix_eq_expPiDivFour_smul_rotZ`. -/ +theorem sGate_op_eq_expPiDivFour_smul_rotZGate : + sGate.op = Complex.exp ((Real.pi / 4 : ℝ) * Complex.I) • (rotZGate (Real.pi / 2)).op := by + rw [sGate_op, rotZGate_op, Concrete.sMatrix_eq_expPiDivFour_smul_rotZ] + exact map_smul _ _ _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/AxisAngleRotation.lean b/LeanPool/AxQM/Postulates/API/AxisAngleRotation.lean new file mode 100644 index 0000000000..cf6213ff48 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/AxisAngleRotation.lean @@ -0,0 +1,64 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.BlochRotationGate +public import LeanPool.AxQM.Concrete.AxisAngleDecomposition + +/-! +# AxQM.Postulates.API — Exercise 4.8(1): every single-qubit gate is a phase × `R_n̂(θ)` + +The content of the first part of Nielsen & Chuang, Exercise 4.8: the operator-level +statement that *every* single-qubit gate is a phase times an axis-rotation gate. + +The axis-rotation gate `rotAxisGate n θ` (`R_n̂(θ) = exp(-iθ n̂·σ/2)` as an `Evolution qubit`) and +its `simp` bridge `rotAxisGate_op` are **reused** from `AxQM/Postulates/API/BlochRotationGate.lean` +(Exercise 4.6's Bloch-sphere-rotation development). + +* `Evolution.exists_op_eq_phase_smul_rotAxisGate` — **Exercise 4.8(1) at the operator level**: for + every gate `U : Evolution qubit` there are real `α, θ` and a unit vector `n̂` with + `U.op = e^{iα} • (rotAxisGate n̂ θ).op` (eq. 4.9). Proof: `M := toEuclideanCLM⁻¹ U.op` + is unitary (`toEuclideanCLM` is a `⋆`-isomorphism), so `Concrete.exists_axis_angle_decomposition` + gives `M = e^{iα} rotAxis n̂ θ`, and applying `toEuclideanCLM` (`ℂ`-linear) lifts it to operators. + +The operator statement keeps the explicit phase `e^{iα}`; the physically observable channel +reading — that the phase is unobservable, so `U` *is* the rotation — is in +[upstream `AxQM/NC/Ch4/Exercise4_8.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_8.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Nielsen & Chuang, Exercise 4.8(1) at the operator level.** Every single-qubit gate +`U : Evolution qubit` equals a phase times an axis-rotation gate: there exist real numbers `α, θ` +and a real *unit* three-vector `n̂` (`n₀² + n₁² + n₂² = 1`) with +`U.op = e^{iα} • (rotAxisGate n̂ θ).op`, i.e. `U = e^{iα} R_n̂(θ)` (eq. 4.9) as operators. The +image, under the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (`ℂ`-linear, so it preserves it), +of the concrete matrix decomposition `Concrete.exists_axis_angle_decomposition` applied to the +matrix `toEuclideanCLM⁻¹ U.op` of `U` (unitary, as `toEuclideanCLM` is a `⋆`-isomorphism). -/ +theorem Evolution.exists_op_eq_phase_smul_rotAxisGate (U : Evolution qubit) : + ∃ (α θ : ℝ) (n : Fin 3 → ℝ), (n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) ∧ + U.op = Complex.exp ((α : ℂ) * Complex.I) • (rotAxisGate n θ).op := by + obtain ⟨α, θ, n, hn, hMeq⟩ := + Concrete.exists_axis_angle_decomposition + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).symm U.op) + (Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).symm U.unitary) + refine ⟨α, θ, n, hn, ?_⟩ + have hUM : (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).symm U.op) = U.op := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).apply_symm_apply U.op + rw [rotAxisGate_op, ← hUM, hMeq] + exact map_smul _ _ _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BellBasis.lean b/LeanPool/AxQM/Postulates/API/BellBasis.lean new file mode 100644 index 0000000000..f1aa12f575 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BellBasis.lean @@ -0,0 +1,155 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.BellState +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM.Postulates.API — the Bell basis of the two-qubit system + +The four **Bell states** `|β_xy⟩` (Nielsen & Chuang, §1.3.6 / §2.3, eqs. (2.134)–(2.137)) +as pure states of the two-qubit system `qubit ⊗ qubit`, and the proof that they form an +**orthonormal basis** of its state space (Nielsen & Chuang, Exercise 2.69). + +* `bellState x y` (`|β_xy⟩`) — the Bell state `(|0,y⟩ + (-1)ˣ |1, y_bar⟩)/√2`, a `PureState` + of `qubit ⊗ qubit`, indexed by the two classical bits `x, y : Fin 2` in N&C's own `β_xy` + notation. The four values are the states `(|00⟩+|11⟩)/√2`, `(|01⟩+|10⟩)/√2`, + `(|00⟩−|11⟩)/√2`, `(|01⟩−|10⟩)/√2` (`β₀₀, β₀₁, β₁₀, β₁₁`). The `β₀₀` case is the + maximally entangled state `bellPhiPlus` of `Postulates/API/BellState.lean` + (`bellState_zero_zero`). +* `bellState_orthonormal` — the family `(x, y) ↦ |β_xy⟩` is **orthonormal**. +* `bellBasis` — the Bell states packaged as an `OrthonormalBasis (Fin 2 × Fin 2) ℂ` of the + two-qubit state space: this is the content of Exercise 2.69. `bellBasis_apply` records + that its basis vectors are exactly the Bell states. + +## Design notes + +* The core computation is `bellBasisVec_inner`: `⟨β_xy|β_x'y'⟩ = δ_{xy,x'y'}`. It reduces the + four-term expansion of the inner product to the atomic inner products of the computational + two-qubit vectors via `TensorProduct.inner_tmul` (`qubitBasis_tmul_inner`), so the whole + Kronecker-delta table follows from the orthonormality of the single-qubit computational + basis (`qubitBasis_inner_qubitBasis`, from `Postulates/API/Qubit.lean`) together with the + sign bookkeeping of `(-1)ˣ`. +* From the inner-product table, orthonormality is `orthonormal_iff_ite`, and the + orthonormal-basis packaging is `basisOfOrthonormalOfCardEqFinrank` (four orthonormal + vectors in a space of `finrank = 2·2 = 4`) upgraded to an `OrthonormalBasis` via + `Module.Basis.toOrthonormalBasis`. +* The statement of Exercise 2.69 is in [upstream `AxQM/NC/Ch2/Exercise2_69.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_69.lean). The underlying-vector + family is named `bellBasisVec` (not `bellVec`) to avoid clashing with the unnormalised `Φ⁺` + vector `bellVec` of `AxQM/Postulates/API/BellState.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- Inner product of two **computational two-qubit** vectors `|ab⟩` and `|cd⟩`: +`⟨ab|cd⟩ = δ_{ac} δ_{bd}`, from `TensorProduct.inner_tmul` and single-qubit orthonormality +(`qubitBasis_inner_qubitBasis`). The `change` restates the composite inner product (which uses +the `QSystem.compose` inner instance) at the definitionally equal raw tensor-product inner so +`TensorProduct.inner_tmul` applies. -/ +theorem qubitBasis_tmul_inner (a b c d : Fin 2) : + inner ℂ ((qubitBasis a ⊗ qubitBasis b).vec) ((qubitBasis c ⊗ qubitBasis d).vec) + = (if a = c then (1 : ℂ) else 0) * (if b = d then 1 else 0) := by + rw [PureState.tmul_vec, PureState.tmul_vec] + change inner ℂ ((qubitBasis a).vec ⊗ₜ[ℂ] (qubitBasis b).vec) + ((qubitBasis c).vec ⊗ₜ[ℂ] (qubitBasis d).vec) = _ + rw [TensorProduct.inner_tmul ℂ, qubitBasis_inner_qubitBasis, qubitBasis_inner_qubitBasis] + +/-- The underlying two-qubit vector of the Bell state `|β_xy⟩ = (|0,y⟩ + (-1)ˣ |1, y_bar⟩)/√2`, +where `y_bar = y + 1` is the bit-flip of `y`. -/ +def bellBasisVec (x y : Fin 2) : (qubit ⊗ qubit).space := + (Real.sqrt 2 : ℂ)⁻¹ • + ((qubitBasis 0 ⊗ qubitBasis y).vec + + (-1 : ℂ) ^ (x : ℕ) • (qubitBasis 1 ⊗ qubitBasis (y + 1)).vec) + +/-- The squared magnitude of the Bell normalisation `(√2)⁻¹`: `conj((√2)⁻¹) · (√2)⁻¹ = ½`. The +`(√2)⁻¹ • (√2)⁻¹`-scalar factor that appears when the `(√2)⁻¹`-normalised Bell vector is pulled out +of both slots of an inner product (`bellBasisVec_inner`, `bellBasisVec_inner_tmul_id`). -/ +theorem conj_sqrtTwoInv_mul_self : + (starRingEnd ℂ) ((Real.sqrt 2 : ℂ)⁻¹) * (Real.sqrt 2 : ℂ)⁻¹ = 1 / 2 := by + rw [map_inv₀, Complex.conj_ofReal, ← Complex.ofReal_inv, ← Complex.ofReal_mul, + ← mul_inv, Real.mul_self_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + norm_num + +/-- **Inner-product table of the Bell vectors:** `⟨β_xy|β_x'y'⟩ = δ_{(x,y),(x',y')}`. This is +the heart of Exercise 2.69: it gives both normalization (the diagonal) and mutual +orthogonality (the off-diagonal). -/ +theorem bellBasisVec_inner (x y x' y' : Fin 2) : + inner ℂ (bellBasisVec x y) (bellBasisVec x' y') = if (x, y) = (x', y') then 1 else 0 := by + simp only [bellBasisVec] + rw [inner_smul_left, inner_smul_right, ← mul_assoc, conj_sqrtTwoInv_mul_self] + simp only [inner_add_left, inner_add_right, inner_smul_left, inner_smul_right, + qubitBasis_tmul_inner, map_pow, map_neg, map_one] + fin_cases x <;> fin_cases x' <;> fin_cases y <;> fin_cases y' <;> + norm_num [Prod.ext_iff] + +/-- Each Bell vector is a **unit vector** — the diagonal of `bellBasisVec_inner`, +`⟨β_xy|β_xy⟩ = 1`. -/ +theorem bellBasisVec_norm (x y : Fin 2) : ‖bellBasisVec x y‖ = 1 := by + rw [← Real.sqrt_one, norm_eq_sqrt_re_inner (𝕜 := ℂ), bellBasisVec_inner]; simp + +/-- The **Bell state** `|β_xy⟩ = (|0,y⟩ + (-1)ˣ |1, y_bar⟩)/√2` as a pure state of the two-qubit +system `qubit ⊗ qubit`, in Nielsen & Chuang's `β_xy` indexing. The four states are +`|β₀₀⟩ = (|00⟩+|11⟩)/√2`, `|β₀₁⟩ = (|01⟩+|10⟩)/√2`, `|β₁₀⟩ = (|00⟩−|11⟩)/√2` and +`|β₁₁⟩ = (|01⟩−|10⟩)/√2`. -/ +def bellState (x y : Fin 2) : PureState (qubit ⊗ qubit) where + vec := bellBasisVec x y + normalized := bellBasisVec_norm x y + +@[simp] +theorem bellState_vec (x y : Fin 2) : (bellState x y).vec = bellBasisVec x y := rfl + +/-- The `β₀₀` Bell state is the maximally entangled state `Φ⁺` of +`Postulates/API/BellState.lean`: `|β₀₀⟩ = |Φ⁺⟩ = (|00⟩ + |11⟩)/√2`. This ties the Bell-basis +family here to the standalone `bellPhiPlus` used by the Chapter 2 EPR/superdense items. -/ +theorem bellState_zero_zero : bellState 0 0 = bellPhiPlus := by + apply PureState.ext + simp only [bellState_vec, bellBasisVec, Fin.val_zero, pow_zero, one_smul, Fin.reduceAdd] + simp only [bellPhiPlus_vec, bellVec, PureState.tmul_vec, qubitBasis_vec] + rfl + +/-- **The Bell states are orthonormal** (Nielsen & Chuang, Exercise 2.69, first half): the family +`(x, y) ↦ |β_xy⟩` is an orthonormal family of pure states, directly from the inner-product table +`bellBasisVec_inner`. -/ +theorem bellState_orthonormal : + Orthonormal ℂ (fun p : Fin 2 × Fin 2 => (bellState p.1 p.2).vec) := by + rw [orthonormal_iff_ite] + rintro ⟨x, y⟩ ⟨x', y'⟩ + simpa only [bellState_vec] using bellBasisVec_inner x y x' y' + +/-- The two-qubit state space has **dimension `4 = 2·2`**, equal to the number of Bell states — +the cardinality/dimension match that upgrades the orthonormal family to a basis. -/ +theorem bell_card_eq : + Fintype.card (Fin 2 × Fin 2) = Module.finrank ℂ (qubit ⊗ qubit).space := by + change Fintype.card (Fin 2 × Fin 2) + = Module.finrank ℂ (TensorProduct ℂ (EuclideanSpace ℂ (Fin 2)) (EuclideanSpace ℂ (Fin 2))) + rw [Module.finrank_tensorProduct, finrank_euclideanSpace_fin] + decide + +/-- **Exercise 2.69:** the four **Bell states form an orthonormal basis** of the two-qubit state +space. Packaged as an `OrthonormalBasis (Fin 2 × Fin 2) ℂ` of `(qubit ⊗ qubit).space`: an +orthonormal family (`bellState_orthonormal`) of the correct cardinality (`bell_card_eq`, +`4 = finrank`) is a basis (`basisOfOrthonormalOfCardEqFinrank`), upgraded to an orthonormal +basis. `bellBasis_apply` records that its `(x, y)` basis vector is exactly `|β_xy⟩`. -/ +def bellBasis : OrthonormalBasis (Fin 2 × Fin 2) ℂ (qubit ⊗ qubit).space := + (basisOfOrthonormalOfCardEqFinrank bellState_orthonormal bell_card_eq).toOrthonormalBasis + (by rw [coe_basisOfOrthonormalOfCardEqFinrank]; exact bellState_orthonormal) + +@[simp] +theorem bellBasis_apply (p : Fin 2 × Fin 2) : bellBasis p = (bellState p.1 p.2).vec := by + simp only [bellBasis, Module.Basis.coe_toOrthonormalBasis, + coe_basisOfOrthonormalOfCardEqFinrank] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BellReducedState.lean b/LeanPool/AxQM/Postulates/API/BellReducedState.lean new file mode 100644 index 0000000000..86c8113a87 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BellReducedState.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.BellBasis +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.Postulates.PartialTraceTensor + +/-! +# AxQM.Postulates.API — reduced density operators of the Bell states + +The reduced density operators (marginals) of the four **Bell states** `|β_xy⟩` are the +**maximally mixed** qubit state `I/2` (Nielsen & Chuang, Exercise 2.75). Each Bell state is +maximally entangled, so tracing out either qubit destroys all information about the other and +leaves the completely mixed state — the operator-level content of Exercise 2.75. + +* `bellState_reducedLeft_op` / `bellState_reducedRight_op` — the reduced operators + `Tr_B|β_xy⟩⟨β_xy| = Tr_A|β_xy⟩⟨β_xy| = (1/2) I` on each qubit, for every `x, y`. +* `maximallyMixedState_qubit_op` — `(maximallyMixedState qubit).op = (1/2) I` (`dim qubit = 2`); + the bridge that turns the `_op` computations into the statement of Exercise 2.75. + +## Design notes + +The computation is a Schmidt-decomposition calculation. Each Bell vector is written in Schmidt +form `|β_xy⟩ = ∑ᵢ σᵢ |eᵢ⟩|fᵢ⟩` with the sign `(-1)ˣ` **folded into a real coefficient** +`σ = ![(√2)⁻¹, (-1)ˣ (√2)⁻¹]`, so **both** Schmidt factor families `eᵢ = |i⟩` and +`fᵢ = |y+i⟩` are the phase-free computational basis (`bellSchmidt_decomp`). This makes both +orthonormality conditions trivial and makes every squared coefficient `σᵢ² = 1/2` +(`bellSchmidt_coeff_sq`), independent of the sign. + +The Schmidt partial-trace lemmas +(`LinearMap.partialTrace{Right,Left}_rankOne_eq_sum_rankOne_of_schmidt`) then reduce the marginal +to `∑ᵢ (1/2) |gᵢ⟩⟨gᵢ|` over the surviving orthonormal computational basis, which is `(1/2) I` by +the resolution of identity `sum_rankOne_qubitBasis_eq_one` (`∑ᵢ |i⟩⟨i| = I`, reindexed by +`sum_rankOne_qubitBasis_shift` for the right marginal, whose surviving basis is `|y+i⟩`). + +The statement of Exercise 2.75, +`(bellState x y).toState.reduced{Left,Right} = maximallyMixedState qubit`, is in +[upstream `AxQM/NC/Ch2/Exercise2_75.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_75.lean), proved by `State.ext` from these `_op` lemmas. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- The maximally mixed qubit state is `I/2`: `(maximallyMixedState qubit).op = (1/2) I` +(since `dim qubit = 2`). The bridge from `bellState_reduced*_op` to Exercise 2.75. -/ +theorem maximallyMixedState_qubit_op : + (maximallyMixedState qubit).op = ((2 : ℂ)⁻¹ • 1 : qubit.space →L[ℂ] qubit.space) := by + rw [maximallyMixedState_op, finrank_qubit_space] + norm_num + +/-- **Resolution of identity for the qubit computational basis:** `∑ᵢ |i⟩⟨i| = I`. The standard +basis `|0⟩, |1⟩` is orthonormal (`EuclideanSpace.basisFun`), so its rank-one projectors sum to the +identity (`OrthonormalBasis.sum_rankOne_eq_id`). -/ +theorem sum_rankOne_qubitBasis_eq_one : + (∑ i : Fin 2, (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec : + qubit.space →L[ℂ] qubit.space)) = 1 := by + have h := OrthonormalBasis.sum_rankOne_eq_id (EuclideanSpace.basisFun (Fin 2) ℂ) + simp only [EuclideanSpace.basisFun_apply] at h + rw [ContinuousLinearMap.one_def]; exact h + +/-- **Shifted resolution of identity:** `∑ᵢ |y+i⟩⟨y+i| = I` for any `y`. Reindexing `sum_rankOne` +`_qubitBasis_eq_one` along the bijection `i ↦ y + i` (`Equiv.addLeft y`); needed for the right +marginal, whose surviving Schmidt basis is `|y⟩, |y_bar⟩` (i.e. `|y+i⟩`). -/ +theorem sum_rankOne_qubitBasis_shift (y : Fin 2) : + (∑ i : Fin 2, (InnerProductSpace.rankOne ℂ (qubitBasis (y + i)).vec (qubitBasis (y + i)).vec : + qubit.space →L[ℂ] qubit.space)) = 1 := by + rw [← sum_rankOne_qubitBasis_eq_one] + exact Equiv.sum_comp (Equiv.addLeft y) + (fun j => InnerProductSpace.rankOne ℂ (qubitBasis j).vec (qubitBasis j).vec) + +/-- The **Schmidt decomposition of the Bell vector** with the sign folded into a real coefficient: +`|β_xy⟩ = ∑ᵢ σᵢ |i⟩|y+i⟩` with `σ = ![(√2)⁻¹, (-1)ˣ (√2)⁻¹]`. Both factor families `|i⟩` and +`|y+i⟩` are the phase-free computational basis; the `(-1)ˣ` lives only in the real coefficient. -/ +theorem bellSchmidt_decomp (x y : Fin 2) : + (bellBasisVec x y : qubit.space ⊗[ℂ] qubit.space) + = ∑ i, ((![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] : Fin 2 → ℝ) i : ℂ) • + (fun i => (qubitBasis i).vec) i ⊗ₜ[ℂ] (fun i => (qubitBasis (y + i)).vec) i := by + simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + bellBasisVec, PureState.tmul_vec, add_zero] + erw [smul_add, smul_smul] + push_cast; rw [mul_comm]; rfl + +/-- Each **squared Schmidt coefficient is `1/2`**: `σᵢ² = 1/2` for `σ = ![(√2)⁻¹, (-1)ˣ (√2)⁻¹]`, +since `((√2)⁻¹)² = 1/2` and the sign `((-1)ˣ)² = 1` drops out. -/ +theorem bellSchmidt_coeff_sq (x : Fin 2) : ∀ i : Fin 2, + (((![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] : Fin 2 → ℝ) i : ℂ)) ^ 2 + = (2 : ℂ)⁻¹ := by + have hsq : ((Real.sqrt 2)⁻¹ : ℝ) ^ 2 = (2 : ℝ)⁻¹ := by + rw [inv_pow, Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + have hsign : ((-1 : ℝ) ^ (x : ℕ)) ^ 2 = 1 := by + rw [← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow] + rw [Fin.forall_fin_two] + refine ⟨?_, ?_⟩ <;> simp only [Matrix.cons_val_zero, Matrix.cons_val_one] <;> + rw [← Complex.ofReal_pow] + · rw [hsq, Complex.ofReal_inv, Complex.ofReal_ofNat] + · rw [mul_pow, hsq, hsign, one_mul, Complex.ofReal_inv, Complex.ofReal_ofNat] + +/-- The density operator of a Bell state as the rank-one projector on the Bell vector, ascribed to +the underlying tensor product space so the `ToMathlib` partial-trace API applies: +`|β_xy⟩⟨β_xy| = rankOne (bellBasisVec x y) (bellBasisVec x y)`. -/ +private theorem bellState_toState_op_toLinearMap (x y : Fin 2) : + ((bellState x y).toState.op.toLinearMap : + qubit.space ⊗[ℂ] qubit.space →ₗ[ℂ] qubit.space ⊗[ℂ] qubit.space) + = ↑(InnerProductSpace.rankOne ℂ (bellBasisVec x y : qubit.space ⊗[ℂ] qubit.space) + (bellBasisVec x y : qubit.space ⊗[ℂ] qubit.space)) := by + simp only [PureState.toState_op, bellState_vec] + +/-- **Left reduced operator of a Bell state is `I/2`** (Nielsen & Chuang, Exercise 2.75, operator +form): tracing out the second qubit of `|β_xy⟩⟨β_xy|` gives the maximally mixed qubit state, +`Tr_B|β_xy⟩⟨β_xy| = (1/2) I`, for every `x, y`. The right Schmidt factors `|y+i⟩` are orthonormal, +so the `partialTraceRight` Schmidt lemma gives `∑ᵢ σᵢ² |i⟩⟨i|`, which is `(1/2) I` by the +resolution of identity `∑ᵢ |i⟩⟨i| = I`. -/ +theorem bellState_reducedLeft_op (x y : Fin 2) : + (bellState x y).toState.reducedLeft.op = ((2 : ℂ)⁻¹ • 1 : qubit.space →L[ℂ] qubit.space) := by + have hforth : Orthonormal ℂ (fun i : Fin 2 => (qubitBasis (y + i)).vec) := by + rw [orthonormal_iff_ite]; intro i j + simp only [qubitBasis_inner_qubitBasis, add_right_inj] + apply ContinuousLinearMap.coe_injective + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, + bellState_toState_op_toLinearMap] + refine Eq.trans (LinearMap.partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ qubit.space) + ![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] + (fun i => (qubitBasis i).vec) (fun i => (qubitBasis (y + i)).vec) hforth + (bellSchmidt_decomp x y)) ?_ + rw [ContinuousLinearMap.toLinearMap_smul, ← sum_rankOne_qubitBasis_eq_one, + ContinuousLinearMap.toLinearMap_sum, Finset.smul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + congr 1 + exact bellSchmidt_coeff_sq x i + +/-- **Right reduced operator of a Bell state is `I/2`** (Nielsen & Chuang, Exercise 2.75, operator +form): tracing out the first qubit of `|β_xy⟩⟨β_xy|` gives the maximally mixed qubit state, +`Tr_A|β_xy⟩⟨β_xy| = (1/2) I`, for every `x, y`. The left Schmidt factors `|i⟩` are orthonormal, +so the `partialTraceLeft` Schmidt lemma gives `∑ᵢ σᵢ² |y+i⟩⟨y+i| = (1/2) ∑ᵢ |y+i⟩⟨y+i| = +(1/2) I` (resolution of identity over the reindexed basis, `sum_rankOne_qubitBasis_shift`). -/ +theorem bellState_reducedRight_op (x y : Fin 2) : + (bellState x y).toState.reducedRight.op = ((2 : ℂ)⁻¹ • 1 : qubit.space →L[ℂ] qubit.space) := by + have heorth : ∀ i j : Fin 2, + ((![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] : Fin 2 → ℝ) i) ≠ 0 → + ((![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] : Fin 2 → ℝ) j) ≠ 0 → + inner ℂ ((fun i => (qubitBasis i).vec) i) ((fun i => (qubitBasis i).vec) j) + = if i = j then (1 : ℂ) else 0 := + fun i j _ _ => qubitBasis_inner_qubitBasis i j + apply ContinuousLinearMap.coe_injective + rw [State.reducedRight_op, LinearMap.coe_toContinuousLinearMap, + bellState_toState_op_toLinearMap] + refine Eq.trans (LinearMap.partialTraceLeft_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ qubit.space) + ![(Real.sqrt 2)⁻¹, (-1 : ℝ) ^ (x : ℕ) * (Real.sqrt 2)⁻¹] + (fun i => (qubitBasis i).vec) (fun i => (qubitBasis (y + i)).vec) heorth + (bellSchmidt_decomp x y)) ?_ + rw [ContinuousLinearMap.toLinearMap_smul, ← sum_rankOne_qubitBasis_shift y, + ContinuousLinearMap.toLinearMap_sum, Finset.smul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + congr 1 + exact bellSchmidt_coeff_sq x i + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BellState.lean b/LeanPool/AxQM/Postulates/API/BellState.lean new file mode 100644 index 0000000000..1edbc6e469 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BellState.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Observable +public import LeanPool.AxQM.Postulates.API.Qubit + +/-! +# AxQM.Postulates.API — the Bell state Φ⁺ + +The maximally entangled two-qubit **Bell state** `|Φ⁺⟩ = (|00⟩ + |11⟩)/√2`, a `PureState` of the +composite system `qubit ⊗ qubit`. This is the canonical entangled state of Nielsen & Chuang §1.3.6 / +§2.3, used throughout Chapter 2 (superdense coding, the EPR/Bell exercises). + +* `bellVec` — the *unnormalised* vector `|00⟩ + |11⟩` in the tensor-product space + `qubit.space ⊗[ℂ] qubit.space`. +* `bellVec_inner_self` — `⟨β|β⟩ = 2`; the squared norm, from which normalisation follows. +* `bellPhiPlus` — the normalised Bell state `(√2)⁻¹ • (|00⟩ + |11⟩)`, a `PureState (qubit ⊗ qubit)`. + +## Design notes + +`bellVec` is entangled — it is **not** a `PureState.tmul` of single-qubit states — so it is built +directly from the tensor of computational-basis vectors and normalised by hand. + +The underlying space `(qubit ⊗ qubit).space` is *definitionally* the raw tensor product +`TensorProduct ℂ qubit.space qubit.space`, but the two present different heads, and the two families +of lemmas want different heads: + +* the **inner-product expansion** lemmas (`TensorProduct.inner_tmul`, `inner_add_left/right`) fire + on the raw tensor head, so `bellVec_inner_self` restates the goal over it with + `change (@inner ℂ (TensorProduct ℂ qubit.space qubit.space) _ …)` before rewriting; +* the **scalar-factoring** lemmas (`norm_smul`, `inner_smul_left/right`, `map_smul`) fire on the + composite `(qubit ⊗ qubit).space` head, whose `Inner`/`Module`/`Norm` instances are the + `…toInner`/`…toModule` forms those lemmas expect. + +The normalising scalar is written `(Real.sqrt 2 : ℂ)⁻¹` — an explicit `ℂ` scalar — so the smul is a +genuine `ℂ`-action and the `ℂ`-linearity lemmas fire; the spelling `(↑(Real.sqrt 2))⁻¹` instead +elaborates to a *real* scalar acting through the `ℝ`-scalar tower, which those lemmas do not match. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- The **unnormalised Bell vector** `|00⟩ + |11⟩` in the two-qubit space +`qubit.space ⊗[ℂ] qubit.space`. Its norm is `√2` (`bellVec_inner_self`); the normalised state is +`bellPhiPlus`. -/ +def bellVec : (qubit ⊗ qubit).space := + (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + +/-- **The squared norm of the unnormalised Bell vector is `2`:** `⟨β|β⟩ = 2`. Because `|00⟩` and +`|11⟩` are orthonormal (`qubitBasis_inner_qubitBasis` and `TensorProduct.inner_tmul`), the cross +terms vanish and `⟨(|00⟩ + |11⟩)|(|00⟩ + |11⟩)⟩ = ⟨00|00⟩ + ⟨11|11⟩ = 1 + 1 = 2`. -/ +theorem bellVec_inner_self : (inner ℂ bellVec bellVec : ℂ) = 2 := by + change (@inner ℂ (TensorProduct ℂ qubit.space qubit.space) _ bellVec bellVec : ℂ) = 2 + rw [bellVec, inner_add_left, inner_add_right, inner_add_right, + TensorProduct.inner_tmul, TensorProduct.inner_tmul, + TensorProduct.inner_tmul, TensorProduct.inner_tmul] + simp only [qubitBasis_inner_qubitBasis] + norm_num + +/-- The **Bell state** `|Φ⁺⟩ = (|00⟩ + |11⟩)/√2`, the maximally entangled pure state of the +composite system `qubit ⊗ qubit`. The underlying unit vector is `(√2)⁻¹ • bellVec`; it is +normalised because `‖bellVec‖ = √2` (from `bellVec_inner_self`). -/ +def bellPhiPlus : PureState (qubit ⊗ qubit) where + vec := (Real.sqrt 2 : ℂ)⁻¹ • bellVec + normalized := by + have hb : ‖bellVec‖ = Real.sqrt 2 := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ), bellVec_inner_self]; norm_num + rw [norm_smul, hb, norm_inv, Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg 2), inv_mul_cancel₀ (by positivity)] + +/-- The underlying unit vector of the Bell state `|Φ⁺⟩` is `(√2)⁻¹ • (|00⟩ + |11⟩)`. A `simp` lemma +exposing the vector for expectation computations. -/ +@[simp] +theorem bellPhiPlus_vec : bellPhiPlus.vec = (Real.sqrt 2 : ℂ)⁻¹ • bellVec := rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BlochRotationGate.lean b/LeanPool/AxQM/Postulates/API/BlochRotationGate.lean new file mode 100644 index 0000000000..82689de12c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BlochRotationGate.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Postulates.API.BlochState +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.Concrete.BlochRotation + +/-! +# AxQM.Postulates.API — the axis rotation gate `R_n̂(θ)` as a qubit evolution + +The single-qubit rotation about an arbitrary axis, Nielsen & Chuang +eq. 4.8: the rotation `R_n̂(θ) = exp(−iθ n̂·σ/2)` promoted from its concrete `2 × 2` unitary matrix +`Concrete.rotAxis n θ` to an `Evolution` of the `qubit`, alongside `rotZGate`/`rotXGate`. + +* `rotAxisGate n θ` — the gate as `Evolution qubit`. An `Evolution` bundles the + unitarity obligation, discharged from the matrix-level unitarity + `Concrete.rotAxis_mem_unitaryGroup` transported through the `⋆`-algebra isomorphism + `Matrix.toEuclideanCLM`, exactly as for `rotZGate`/`rotXGate`/`hadamardGate`. Unlike those axis + specializations (`Concrete.rotZ`/`Concrete.rotX`), this is the *general* axis rotation for any + three-vector `n`, needed by the Bloch-sphere interpretation of rotations (Exercise 4.6). +* `rotAxisGate_op` — a `simp` bridge exposing the underlying operator + `Matrix.toEuclideanCLM (Concrete.rotAxis n θ)`. +* `rotAxisGate_evolve_blochState` — **the Bloch-sphere action of the gate (Nielsen & Chuang, + Exercise 4.6)**: for a unit axis `n̂`, the state conjugation `ρ ↦ R_n̂(θ) ρ R_n̂(θ)†` + (`Evolution.evolve`) rotates the Bloch vector of `blochState v` by `θ` about `n̂`, + `(rotAxisGate n̂ θ).evolve (blochState v) = blochState (Concrete.rot3D n̂ θ v)`. + The statement of Exercise 4.6 is in [upstream `AxQM/NC/Ch4/Exercise4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_6.lean); the identity is also used by + the general single-qubit `unitaryGate_evolve_blochState`, the Problem 8.3 Pauli channel and the + `SU(2) → SO(3)` cover surjectivity. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- The **axis rotation gate** `R_n̂(θ) = exp(−iθ n̂·σ/2)` as a closed-system evolution of the +`qubit` (Nielsen & Chuang, eq. 4.8), for an arbitrary three-vector `n`. Its operator is the concrete +rotation matrix `Concrete.rotAxis n θ` promoted through the `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM`; unitarity — the `Evolution` proof obligation — is transported from +`Concrete.rotAxis_mem_unitaryGroup` (which holds for *any* axis, the exponential of an +anti-Hermitian matrix). The `z`- and `x`-axis specializations `rotZGate`/`rotXGate` use the +dedicated matrices `Concrete.rotZ`/`Concrete.rotX`; this is the general-axis rotation. -/ +def rotAxisGate (n : Fin 3 → ℝ) (θ : ℝ) : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotAxis n θ) + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + (Concrete.rotAxis_mem_unitaryGroup n θ) + +@[simp] +theorem rotAxisGate_op (n : Fin 3 → ℝ) (θ : ℝ) : + (rotAxisGate n θ).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotAxis n θ) := + rfl + +/-- **Nielsen & Chuang, Exercise 4.6 — the Bloch-sphere interpretation of rotations.** For a unit +axis `n̂` (`hn`), evolving the Bloch state `blochState v` — the qubit density operator +`½(I + v·σ)` — by the rotation gate `rotAxisGate n̂ θ = R_n̂(θ)` rotates its Bloch vector `v` by the +angle `θ` about `n̂`: +`(rotAxisGate n̂ θ).evolve (blochState v) = blochState (Concrete.rot3D n̂ θ v)`. + +The rotated vector stays in the Bloch ball (`Concrete.rot3D_sq_sum`: a rotation preserves the +squared length), so the right-hand `blochState` is well defined; that bound is the second argument. +The proof transports the concrete matrix conjugation identity `Concrete.blochMatrix_conj_rotAxis` +(`R_n̂(θ) · blochMatrix v · R_n̂(θ)ᴴ = blochMatrix (rot3D n̂ θ v)`) +through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` to the operator channel +`ρ ↦ R_n̂(θ) ρ R_n̂(θ)†` (`Evolution.evolve`), matching it to `blochState`'s operator via +`State.ext`. + +The unit-axis hypothesis `hn` is genuine (N&C's `n̂` is the rotation *axis*); `θ` and the Bloch +vector `v` are fully general. This is the general-axis +analogue of `unitaryGate_evolve_blochState`; it is used in the Problem 8.3 Pauli channel and the +`SU(2) → SO(3)` cover surjectivity, and is the statement of Exercise 4.6 +([upstream `AxQM/NC/Ch4/Exercise4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_6.lean)). -/ +theorem rotAxisGate_evolve_blochState {n : Fin 3 → ℝ} + (hn : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) (θ : ℝ) (v : Fin 3 → ℝ) + (h : v 0 ^ 2 + v 1 ^ 2 + v 2 ^ 2 ≤ 1) : + (rotAxisGate n θ).evolve (blochState v h) + = blochState (Concrete.rot3D n θ v) ((Concrete.rot3D_sq_sum hn θ v).trans_le h) := by + apply State.ext + simp only [Evolution.evolve_op, rotAxisGate_op, blochState_op] + rw [← Concrete.blochMatrix_conj_rotAxis hn, map_mul, map_mul, ← Matrix.star_eq_conjTranspose, + map_star, ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def, + ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_assoc] + -- both sides are now the operator conjugation `R · (v·σ) · R†`; the remaining `rfl` bridges the + -- `qubit.space ≡ EuclideanSpace ℂ (Fin 2)` defeq (unfolded only at default transparency). + rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BlochState.lean b/LeanPool/AxQM/Postulates/API/BlochState.lean new file mode 100644 index 0000000000..92b1ca2dc4 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BlochState.lean @@ -0,0 +1,154 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Concrete.BlochMatrix +public import LeanPool.AxQM.Concrete.BlochPureState +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.MatrixToEuclideanCLM + +/-! +# AxQM.Postulates.API — the qubit Bloch state `ρ = ½(I + r·σ)` + +The promotion of the concrete Bloch matrix `Concrete.blochMatrix r = ½(I + r·σ)` +to a genuine density operator of the `qubit`, for a Bloch vector `r` in the closed unit ball +(Nielsen & Chuang, Exercise 2.72(1)(2)). + +* `blochState r h` — for a real three-vector `r` with `‖r‖² = r₀² + r₁² + r₂² ≤ 1`, the **state** + `½(I + r·σ)` of the qubit: the concrete Hermitian trace-one matrix `Concrete.blochMatrix r` + promoted to a continuous linear operator through the C\*-algebra isomorphism + `Matrix.toEuclideanCLM`, packaged as a `State qubit`. It is a density operator because + `Concrete.blochMatrix r` is positive semidefinite (`Concrete.blochMatrix_posSemidef_iff`, using + `‖r‖² ≤ 1`) and has trace one (`Concrete.blochMatrix_trace`), both transported across the + isomorphism. This is the same bridge route used by `pauliObservable`. +* `blochState_op` — exposes the underlying operator `Matrix.toEuclideanCLM (Concrete.blochMatrix + r)`. +* `blochState_zero_op` — **`(blochState 0).op = ½ I`** (Nielsen & Chuang, Exercise 2.72(2)): the + state with Bloch vector `r_vec = 0` is the maximally mixed state `I/2`. This identifies the + operator; + together with the correspondence/uniqueness theorems in [upstream `AxQM/NC/Ch2/Exercise2_72.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_72.lean) it answers + part (2) ("the Bloch vector representation of `ρ = I/2` is `r_vec = 0`"). +* `blochPureState θ φ` — the **§1.2 pure state** `|ψ(θ,φ)⟩ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩` + (Nielsen & Chuang eq. 1.4) as a `PureState qubit`, the concrete unit vector `Concrete.blochKet θ + φ` embedded into `EuclideanSpace` (normalization `cos²(θ/2) + sin²(θ/2) = 1`). +* `blochPureState_toState_op` — **`|ψ(θ,φ)⟩⟨ψ(θ,φ)| = Matrix.toEuclideanCLM (Concrete.blochMatrix + (blochSphereVector θ φ))`** (Nielsen & Chuang, Exercise 2.72(4)): the density + operator of the §1.2 pure state is the Bloch state of the §1.2 Cartesian vector. This is the + content behind the state-level coincidence in [upstream `AxQM/NC/Ch2/Exercise2_72.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_72.lean). + +The construction and its inverse (the density-operator correspondence) rest on +two general matrix↔operator bridges, in +`ToMathlib/Analysis/CStarAlgebra/MatrixToEuclideanCLM.lean`: +`Matrix.isPositive_toEuclideanCLM_iff` (operator positivity `↔` matrix `PosSemidef`) and +`Matrix.trace_toEuclideanCLM` (operator trace `= A.trace`). + +## Design notes + +* The bridge `Matrix.toEuclideanCLM` is a `⋆`-algebra *equivalence*, so it preserves positivity and + trace (through its coercion to `Matrix.toEuclideanLin`). Building `blochState` on the concrete + matrix layer keeps every analytic fact (positivity, trace, determinant) in `Concrete/` and reuses + it here with no operator-level recomputation. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder + +noncomputable section + +namespace AxQM + +/-- The **Bloch state** `ρ = ½(I + r·σ)` of the qubit, for a Bloch vector `r` in the closed unit +ball `‖r‖² = r₀² + r₁² + r₂² ≤ 1` (Nielsen & Chuang, Exercise 2.72(1), eq. 2.175). Its density +operator is the concrete matrix `Concrete.blochMatrix r` promoted through the `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM`; it is positive because `Concrete.blochMatrix r` is positive +semidefinite (`Concrete.blochMatrix_posSemidef_iff`, using `‖r‖² ≤ 1`) and of trace one +(`Concrete.blochMatrix_trace`). -/ +def blochState (r : Fin 3 → ℝ) (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) : State qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.blochMatrix r) + isDensity := by + have h' : (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.blochMatrix + r)).IsDensityOp := by + rw [ContinuousLinearMap.isDensityOp_iff] + refine ⟨?_, ?_⟩ + · exact (Matrix.isPositive_toEuclideanCLM_iff _).mpr + ((Concrete.blochMatrix_posSemidef_iff r).mpr h) + · exact (Matrix.trace_toEuclideanCLM _).trans (Concrete.blochMatrix_trace r) + exact h' + +/-- The underlying density operator of `blochState r h` is the `Matrix.toEuclideanCLM` image of the +concrete Bloch matrix `Concrete.blochMatrix r`. A `simp` lemma exposing the operator. -/ +@[simp] +theorem blochState_op (r : Fin 3 → ℝ) (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) : + (blochState r h).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.blochMatrix r) := + rfl + +/-- **Congruence for the Bloch state in its Bloch vector.** Equal Bloch vectors give equal Bloch +states: `r = s` implies `blochState r hr = blochState s hs`, regardless of the (proof-irrelevant) +ball-membership witnesses `hr`, `hs`. -/ +theorem blochState_congr {r s : Fin 3 → ℝ} (hrs : r = s) + {hr : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1} {hs : s 0 ^ 2 + s 1 ^ 2 + s 2 ^ 2 ≤ 1} : + blochState r hr = blochState s hs := by + subst hrs; rfl + +/-- **`(blochState 0).op = ½ I` (Nielsen & Chuang, Exercise 2.72(2)).** The state with Bloch vector +`r_vec = 0` has density operator `I/2`, the maximally mixed state of the qubit: +`Concrete.blochMatrix 0 += ½ I` (`Concrete.blochMatrix_zero`) and `Matrix.toEuclideanCLM` carries `½ I` to `½·1`. This is +the operator content of part (2): the Bloch vector representation of `ρ = I/2` is `r_vec = 0`. -/ +theorem blochState_zero_op : + (blochState (0 : Fin 3 → ℝ) (by simp)).op = (2⁻¹ : ℂ) • 1 := by + rw [blochState_op, Concrete.blochMatrix_zero, map_smul, map_one] + rfl + +/-- The **§1.2 pure state** `|ψ(θ,φ)⟩ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩` of the qubit (Nielsen & +Chuang eq. 1.4), as a `PureState qubit`: the concrete unit vector `Concrete.blochKet θ φ` embedded +into `EuclideanSpace ℂ (Fin 2)`. It is normalized because `‖cos(θ/2)‖² + ‖e^{iφ} sin(θ/2)‖² += cos²(θ/2) + sin²(θ/2) = 1` (`‖e^{iφ}‖ = 1`). Its Bloch vector is computed in +`blochPureState_toState_op` (Exercise 2.72(4)). -/ +noncomputable def blochPureState (θ φ : ℝ) : PureState qubit where + vec := WithLp.toLp 2 (Concrete.blochKet θ φ) + normalized := by + change ‖(WithLp.toLp 2 (Concrete.blochKet θ φ) : EuclideanSpace ℂ (Fin 2))‖ = 1 + rw [EuclideanSpace.norm_eq, Fin.sum_univ_two] + simp only [Concrete.blochKet, Matrix.cons_val_zero, Matrix.cons_val_one, norm_mul, + Complex.norm_real, Complex.norm_exp_ofReal_mul_I, one_mul, Real.norm_eq_abs, sq_abs] + rw [Real.cos_sq_add_sin_sq, Real.sqrt_one] + +/-- The underlying unit vector of `blochPureState θ φ` is `Concrete.blochKet θ φ` in +`EuclideanSpace`. A `simp` lemma exposing the vector for the density-operator computation. -/ +@[simp] +theorem blochPureState_vec (θ φ : ℝ) : + (blochPureState θ φ).vec = WithLp.toLp 2 (Concrete.blochKet θ φ) := rfl + +/-- **`|ψ(θ,φ)⟩⟨ψ(θ,φ)| = Matrix.toEuclideanCLM (Concrete.blochMatrix (blochSphereVector θ φ))` +(Nielsen & Chuang, Exercise 2.72(4)).** The density operator of the §1.2 pure state +`blochPureState θ φ` is the operator of the Bloch state with the §1.2 Cartesian vector +`r_vec = (sin θ cos φ, sin θ sin φ, cos θ)`. + +Proof: the density operator is the rank-one projector `|ψ⟩⟨ψ| = InnerProductSpace.rankOne ℂ v v` +(`PureState.toState_op`) for `v = blochKet θ φ`. Under the `Matrix.toEuclideanCLM` isomorphism a +rank-one projector is `Matrix.toEuclideanCLM` of the outer product `Concrete.outerSelf v = vecMulVec +v (star v)` (via `Matrix.coe_toEuclideanCLM_eq_toEuclideanLin` and +`InnerProductSpace.symm_toEuclideanLin_rankOne`), and `Concrete.outerSelf_blochKet_eq_blochMatrix` +identifies that outer product with `Concrete.blochMatrix (blochSphereVector θ φ)`. -/ +theorem blochPureState_toState_op (θ φ : ℝ) : + (blochPureState θ φ).toState.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) + (Concrete.blochMatrix (Concrete.blochSphereVector θ φ)) := by + rw [PureState.toState_op, blochPureState_vec] + change InnerProductSpace.rankOne ℂ (WithLp.toLp 2 (Concrete.blochKet θ φ)) + (WithLp.toLp 2 (Concrete.blochKet θ φ)) + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) + (Concrete.blochMatrix (Concrete.blochSphereVector θ φ)) + rw [← Concrete.outerSelf_blochKet_eq_blochMatrix, Concrete.outerSelf] + apply ContinuousLinearMap.coe_injective + rw [Matrix.coe_toEuclideanCLM_eq_toEuclideanLin, ← InnerProductSpace.symm_toEuclideanLin_rankOne, + LinearEquiv.apply_symm_apply] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/BlockGatePlacement.lean b/LeanPool/AxQM/Postulates/API/BlockGatePlacement.lean new file mode 100644 index 0000000000..35a9dfc6ae --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/BlockGatePlacement.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TensorPowSplit +public import LeanPool.AxQM.Postulates.API.LeftPairGate +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.PiTensorState + +/-! +# Placing a gate on a contiguous block of wires (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit implementing +`Cⁿ(X)`. Reducing the multiply-controlled-`NOT` blocks `Cᵏ(X)` of the tight `(n+1)`-wire circuit to +two-control gates requires placing a `Toffoli`/`CNOT` on a chosen set of wires. This is done in two +moves on the **symmetric** register `S ^⊗ₛ (a+b)`: first place the gate on the *first* `a` wires (a +contiguous block), then relabel the wires by a permutation (`Evolution.permWires`) to send that +block to the target wire set. This file gives the first move. + +The block-split isomorphism `QSystem.tensorPowAdd` gives +`S ^⊗ₛ (a+b) ≃ₛ (S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)`. Here it is used to *place a gate*: a gate +`G : Evolution (S ^⊗ₛ a)` on the first block is lifted to `G.onLeft (S ^⊗ₛ b)` (act as `G` on the +`a`-wire block, identity on the `b`-wire block) and transported back onto the whole register through +`(tensorPowAdd S a b).symm` by `Evolution.congr`. + +## What is formalised + +* `Evolution.onBlock G b` — the **block-placement gate** on `S ^⊗ₛ (a+b)`: given a gate + `G : Evolution (S ^⊗ₛ a)` on the first `a` wires, the closed-system `Evolution` acting as `G` on + those wires and as the identity on the remaining `b`, defined as `G.onLeft (S ^⊗ₛ b)` transported + across `(QSystem.tensorPowAdd S a b).symm` via `Evolution.congr`. +* `QSystem.tensorPowAdd_congr_piTensor` — the **product-state split dictionary**: the block-split + isomorphism carries a symmetric product basis state `⨂ᵢ |f i⟩` on `S ^⊗ₛ (a+b)` to the pair of + product states `(⨂ᵢ |f (castAdd i)⟩) ⊗ (⨂ⱼ |f (natAdd j)⟩)` on the two blocks — the `PureState` + companion of `QSystem.tensorPowAdd_toIsometry_tprod`. +* `Evolution.onBlock_evolvePure_congr` — the **transport action**: on a state transported from a + pair `u ⊗ v` (with `u` on the first block, `v` on the second), `onBlock G b` acts as `G` on `u`, + `(G.onBlock b).evolvePure ((u ⊗ v).congr e⁻¹) = ((G.evolvePure u) ⊗ v).congr e⁻¹`. Immediate from + the transport law `Evolution.congr_evolvePure_congr` and `Evolution.onLeft_evolvePure`. +* `Evolution.onBlock_evolvePure_piTensor` — the **computational-basis action** in product form: on a + symmetric product input `⨂ᵢ |f i⟩`, `onBlock G b` applies `G` to the first-block product + `⨂ᵢ |f (castAdd i)⟩` and leaves the second-block product `⨂ⱼ |f (natAdd j)⟩` untouched, + reassembled through `(tensorPowAdd S a b).symm`. This is the placement dictionary used once + the wires are relabelled by `Evolution.permWires`. + +## Design notes + +* **Why the `onLeft`-then-transport route.** Placing a gate on the *first* `a` factors is exactly + what `Evolution.onLeft` does after the register is regrouped as `(S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)` — the + shape `QSystem.tensorPowAdd` produces. Transporting the regrouped gate back with `Evolution.congr` + keeps every proof a one-line application of the transport law `Evolution.congr_evolvePure_congr`, + reusing the existing block actions rather than re-deriving `PiTensorProduct` surgery. +* **Why the product-state form.** The `Cᵏ(X)`-block reduction of Exercise 4.29 reads gate effects on + *computational basis* inputs (products `⨂ᵢ |f i⟩`), so `onBlock_evolvePure_piTensor` — not just + the abstract transport action — is the usable interface. Its proof splits the input product with + `QSystem.tensorPowAdd_congr_piTensor` (then `PureState.congr_symm_congr` to pass to the `.symm` + side) and applies `onBlock_evolvePure_congr`; the `_toIsometry_tprod` action already used in the + dictionary lemma is the only further ingredient. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {a : ℕ} + +/-- **Product-state split dictionary for the block isomorphism.** The block-split isomorphism +`QSystem.tensorPowAdd S a b` carries the symmetric product basis state `⨂ᵢ |f i⟩` on `S ^⊗ₛ (a+b)` +to the pair of block product states `(⨂ᵢ |f (Fin.castAdd b i)⟩) ⊗ (⨂ⱼ |f (Fin.natAdd a j)⟩)` — the +first `a` wires and the last `b` wires. The `PureState` companion of the product +action `QSystem.tensorPowAdd_toIsometry_tprod`, used to feed a computational-basis input into the +block-placement gate. -/ +theorem QSystem.tensorPowAdd_congr_piTensor (a b : ℕ) (f : Fin (a + b) → PureState S) : + PureState.congr (QSystem.tensorPowAdd S a b) (PureState.piTensor f) + = PureState.piTensor (fun i => f (Fin.castAdd b i)) + ⊗ PureState.piTensor (fun j => f (Fin.natAdd a j)) := by + apply PureState.ext + simp only [PureState.tmul_vec, PureState.piTensor_vec] + exact QSystem.tensorPowAdd_toIsometry_tprod S a b (fun i => (f i).vec) + +/-- **Backward product dictionary for the block isomorphism.** The `.symm` companion of +`QSystem.tensorPowAdd_congr_piTensor`: the inverse block-split `(QSystem.tensorPowAdd S a b).symm` +reassembles a pair of symmetric products `(⨂ᵢ Pᵢ) ⊗ (⨂ⱼ Qⱼ)` on the two blocks into the single +symmetric product `⨂ (Fin.append P Q)` on `S ^⊗ₛ (a+b)`. This is the direction consumed when a gate +computed on the split register `(S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)` (e.g. a placed block gate) is transported +back onto the whole `(a+b)`-wire register on a computational product input. Proved from the forward +dictionary through the `PureState.congr` roundtrip `PureState.congr_symm_congr` (bridged in term +mode: the goal's `⊗` carries the system head `S ^⊗ₛ a` while the intermediate `have` carries the +defeq-but-syntactically-distinct `⨂ₛ i, S`, so `rw` cannot apply the intermediate equation). -/ +theorem QSystem.tensorPowAdd_symm_congr_piTensor (a b : ℕ) + (P : Fin a → PureState S) (Q : Fin b → PureState S) : + PureState.congr (QSystem.tensorPowAdd S a b).symm + ((PureState.piTensor P) ⊗ (PureState.piTensor Q)) + = PureState.piTensor (Fin.append P Q) := by + have heq : PureState.congr (QSystem.tensorPowAdd S a b) (PureState.piTensor (Fin.append P Q)) + = (PureState.piTensor P) ⊗ (PureState.piTensor Q) := by + rw [QSystem.tensorPowAdd_congr_piTensor] + congr 1 + · exact congrArg PureState.piTensor (funext fun i => Fin.append_left P Q i) + · exact congrArg PureState.piTensor (funext fun j => Fin.append_right P Q j) + exact (congrArg (PureState.congr (QSystem.tensorPowAdd S a b).symm) heq.symm).trans + (PureState.congr_symm_congr _ _) + +/-- **The block-placement gate** on `S ^⊗ₛ (a+b)`: given a gate `G : Evolution (S ^⊗ₛ a)` on the +first `a` wires, the closed-system `Evolution` that acts as `G` on those `a` wires and as the +identity on the remaining `b`. It is `G.onLeft (S ^⊗ₛ b)` — the gate on the left block of the split +register `(S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)` — transported back onto the full `(a+b)`-wire register through the +block-split isomorphism `(QSystem.tensorPowAdd S a b).symm` via `Evolution.congr`. Its +computational-basis action is `Evolution.onBlock_evolvePure_piTensor`. -/ +def Evolution.onBlock (G : Evolution (S ^⊗ₛ a)) (b : ℕ) : Evolution (S ^⊗ₛ (a + b)) := + (G.onLeft (S ^⊗ₛ b)).congr (QSystem.tensorPowAdd S a b).symm + +/-- **Transport action of the block-placement gate.** Feeding `Evolution.onBlock G b` a state +transported from a pair `u ⊗ v` (with `u` on the first `a`-wire block and `v` on the last `b`-wire +block) applies `G` to `u` alone: +`(G.onBlock b).evolvePure ((u ⊗ v).congr eˢ) = ((G u) ⊗ v).congr eˢ` where +`eˢ = (QSystem.tensorPowAdd S a b).symm`. Immediate from unfolding `onBlock`, the transport law +`Evolution.congr_evolvePure_congr`, and `Evolution.onLeft_evolvePure`. -/ +theorem Evolution.onBlock_evolvePure_congr (G : Evolution (S ^⊗ₛ a)) (b : ℕ) + (u : PureState (S ^⊗ₛ a)) (v : PureState (S ^⊗ₛ b)) : + (G.onBlock b).evolvePure (PureState.congr (QSystem.tensorPowAdd S a b).symm (u ⊗ v)) + = PureState.congr (QSystem.tensorPowAdd S a b).symm ((G.evolvePure u) ⊗ v) := by + unfold Evolution.onBlock + rw [Evolution.congr_evolvePure_congr, Evolution.onLeft_evolvePure] + +/-- **Computational-basis action of the block-placement gate.** On a symmetric product input +`⨂ᵢ |f i⟩` (a computational basis state of `S ^⊗ₛ (a+b)`), `Evolution.onBlock G b` applies `G` to +the first-block product `⨂ᵢ |f (Fin.castAdd b i)⟩` and leaves the second-block product +`⨂ⱼ |f (Fin.natAdd a j)⟩` untouched, the two reassembled through +`(QSystem.tensorPowAdd S a b).symm`. This is the wire-addressed placement dictionary the +`Cᵏ(X)`-block `Toffoli` reduction consumes (after the block is relabelled onto the target wires by +`Evolution.permWires`). Proved by splitting the input product with +`QSystem.tensorPowAdd_congr_piTensor` (via the `PureState.congr` roundtrip +`PureState.congr_symm_congr`) and applying `Evolution.onBlock_evolvePure_congr`. -/ +theorem Evolution.onBlock_evolvePure_piTensor (G : Evolution (S ^⊗ₛ a)) (b : ℕ) + (f : Fin (a + b) → PureState S) : + (G.onBlock b).evolvePure (PureState.piTensor f) + = PureState.congr (QSystem.tensorPowAdd S a b).symm + ((G.evolvePure (PureState.piTensor fun i => f (Fin.castAdd b i))) + ⊗ PureState.piTensor fun j => f (Fin.natAdd a j)) := by + rw [← PureState.congr_symm_congr (QSystem.tensorPowAdd S a b) (PureState.piTensor f), + QSystem.tensorPowAdd_congr_piTensor a b f] + exact Evolution.onBlock_evolvePure_congr G b _ _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CNOTDensityMatrix.lean b/LeanPool/AxQM/Postulates/API/CNOTDensityMatrix.lean new file mode 100644 index 0000000000..fbb2fe56f0 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CNOTDensityMatrix.lean @@ -0,0 +1,159 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary + +/-! +# AxQM.Postulates.API — CNOT as a permutation of the density matrix (N&C Ex 4.19) + +Nielsen & Chuang's Exercise 4.19: the action of the `CNOT` gate on a +two-qubit *density matrix* `ρ`, written out explicitly in the computational basis. + +Explicit action of CNOT on a density matrix in the computational basis. + +`CNOT` acts on a state (density operator) by conjugation, `ρ ↦ CNOT ρ CNOT†` (Postulate 5, +`Evolution.evolve`). Because `CNOT` merely *permutes* the computational basis +(`|c,t⟩ ↦ |c, t ⊕ c⟩`), conjugating `ρ` by it simply **permutes the matrix entries** by that same +permutation acting on both the row and the column index — the "rearrangement of elements" N&C +describes. + +## What this file provides + +* `State.twoQubitStdMatrix` — the **density matrix** of a two-qubit state in the computational + product basis `{|i⟩ ⊗ |j⟩}` (indexed by `Fin 2 × Fin 2`), whose `(i, j)` entry is + `⟨i|ρ|j⟩ = ⟪|i⟩, ρ|j⟩⟫`. The density-operator analogue of `Evolution.twoQubitStdMatrix` + (N&C Ex 4.16). +* `cnotBasisPerm` — the permutation of the computational basis `(c, t) ↦ (c, t ⊕ c)` induced by + `CNOT`, as an `Equiv.Perm (Fin 2 × Fin 2)` (`CNOT` "is a simple permutation"); it is the + transposition swapping `|10⟩` and `|11⟩` (`cnotBasisPerm_eq_swap`), fixing `|00⟩` and `|01⟩`. +* `cnotGate_op_qubitBasis_tmul` / `cnotGate_adjoint_op_qubitBasis_tmul` — the operator `CNOT` and + its adjoint act on the product basis by `|c,t⟩ ↦ |c, t ⊕ c⟩`. (`CNOT` is a self-inverse + permutation of the basis, so `CNOT†` acts the same way; this is obtained from unitarity, + `CNOT† CNOT = 1`, with no operator-algebra detour.) +* `cnotGate_evolve_twoQubitStdMatrix` — **Exercise 4.19:** the density matrix of `CNOT ρ CNOT†` is + the density matrix of `ρ` with its rows and columns reindexed by `cnotBasisPerm`: + `(CNOT.evolve ρ).twoQubitStdMatrix = ρ.twoQubitStdMatrix.submatrix cnotBasisPerm cnotBasisPerm`, + i.e. entrywise `⟨(c,t)|CNOT ρ CNOT†|(c',t')⟩ = ⟨(c, t⊕c)|ρ|(c', t'⊕c')⟩`. + +## Design notes + +* **Statement.** The statement is the exact conjugation action `ρ ↦ CNOT ρ CNOT†` of + the genuine gate `Evolution` on an *arbitrary* two-qubit state `ρ`, realised as an equality of + honest `4 × 4` complex matrices (`Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2) ℂ`) — not a claim only on + basis states or on a special ρ. `cnotBasisPerm` is a genuine `Equiv.Perm`, so "`CNOT` is a simple + permutation of the matrix elements" is captured literally; `cnotBasisPerm_eq_swap` pins it down as + the single transposition N&C's rearrangement amounts to. +* **Proof (no adjoint-of-a-matrix detour).** The entry of `CNOT ρ CNOT†` is + `⟪|i⟩, CNOT (ρ (CNOT† |j⟩))⟫`; `adjoint_inner_left` moves the outer `CNOT` across to give + `⟪CNOT† |i⟩, ρ (CNOT† |j⟩)⟫`. It then suffices to know `CNOT† |c,t⟩ = |c, t⊕c⟩`, which follows + purely from `CNOT`'s basis action together with unitarity `CNOT† CNOT = 1` + (`Evolution.adjoint_comp_self`): `CNOT†|c,t⟩ = CNOT†(CNOT|c,t⊕c⟩) = |c,t⊕c⟩` since `(t⊕c)⊕c = t`. + This sidesteps computing the adjoint of the underlying operator (equivalently, `CNOT`'s + self-adjointness). +* The statement of Exercise 4.19 is in [upstream `AxQM/NC/Ch4/Exercise4_19.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_19.lean); compare `Exercise4_16` + (the two-qubit *gate* matrix). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-! ### The density matrix of a two-qubit state in the computational basis -/ + +/-- The **computational-basis density matrix** of a two-qubit state `ρ`: the matrix in the product +basis `{|i⟩ ⊗ |j⟩}` (indexed by `Fin 2 × Fin 2`) whose `(i, j)` entry is the matrix element +`⟨i|ρ|j⟩ = ⟪|i⟩, ρ|j⟩⟫`. The density-operator analogue of `Evolution.twoQubitStdMatrix` +(N&C Ex 4.16); its entry formula is `State.twoQubitStdMatrix_apply`. -/ +def State.twoQubitStdMatrix (ρ : State (qubit ⊗ qubit)) : + Matrix (Fin 2 × Fin 2) (Fin 2 × Fin 2) ℂ := + Matrix.of fun i j => inner ℂ (qubitBasis i.1 ⊗ qubitBasis i.2).vec + (ρ.op (qubitBasis j.1 ⊗ qubitBasis j.2).vec) + +/-- **Entry formula** for the two-qubit density matrix: the `(i, j)` entry of +`ρ.twoQubitStdMatrix` is the matrix element `⟪|i₁⟩⊗|i₂⟩, ρ(|j₁⟩⊗|j₂⟩)⟫` of `ρ.op`. -/ +@[simp] +theorem State.twoQubitStdMatrix_apply (ρ : State (qubit ⊗ qubit)) (i j : Fin 2 × Fin 2) : + ρ.twoQubitStdMatrix i j = inner ℂ (qubitBasis i.1 ⊗ qubitBasis i.2).vec + (ρ.op (qubitBasis j.1 ⊗ qubitBasis j.2).vec) := rfl + +/-! ### The CNOT basis permutation -/ + +/-- The permutation of the two-qubit computational basis induced by `CNOT`, +`(c, t) ↦ (c, t ⊕ c)` (addition in `Fin 2`), as a genuine `Equiv.Perm (Fin 2 × Fin 2)`. It is an +involution — `CNOT` flips the target twice back to itself — so it is its own inverse. This encodes +N&C's statement that `CNOT` "is a simple permutation" of the density-matrix elements. -/ +def cnotBasisPerm : Equiv.Perm (Fin 2 × Fin 2) := + Function.Involutive.toPerm (fun p => (p.1, p.2 + p.1)) fun p => by + obtain ⟨a, b⟩ := p + have : b + a + a = b := by fin_cases a <;> fin_cases b <;> decide + simp [this] + +/-- The `CNOT` basis permutation sends `(c, t)` to `(c, t ⊕ c)`. -/ +@[simp] +theorem cnotBasisPerm_apply (p : Fin 2 × Fin 2) : cnotBasisPerm p = (p.1, p.2 + p.1) := rfl + +/-- The `CNOT` basis permutation is exactly the **transposition of `|10⟩` and `|11⟩`**, fixing +`|00⟩` and `|01⟩`: `cnotBasisPerm = swap (1,0) (1,1)`. This is the concrete "rearrangement of +elements" N&C describes — only the last two computational-basis states are exchanged. -/ +theorem cnotBasisPerm_eq_swap : + cnotBasisPerm = Equiv.swap ((1 : Fin 2), (0 : Fin 2)) ((1 : Fin 2), (1 : Fin 2)) := by + ext p : 1 + obtain ⟨a, b⟩ := p + fin_cases a <;> fin_cases b <;> decide + +/-! ### The action of CNOT and its adjoint on the computational basis -/ + +/-- **`CNOT` on the computational basis (operator form):** `CNOT|c,t⟩ = |c, t ⊕ c⟩`, i.e. +`cnotGate.op` sends the vector `|c⟩ ⊗ |t⟩` to `|c⟩ ⊗ |t ⊕ c⟩`. The operator-level restatement of +`cnotGate_evolvePure_qubitBasis`. -/ +theorem cnotGate_op_qubitBasis_tmul (c t : Fin 2) : + cnotGate.op (qubitBasis c ⊗ qubitBasis t).vec = (qubitBasis c ⊗ qubitBasis (t + c)).vec := by + rw [← Evolution.evolvePure_vec, cnotGate_evolvePure_qubitBasis] + +/-- **`CNOT†` on the computational basis:** `CNOT†|c,t⟩ = |c, t ⊕ c⟩` — the adjoint acts the same +way as `CNOT`, because `CNOT` is a self-inverse permutation of the basis. Proved from `CNOT`'s basis +action and unitarity `CNOT† CNOT = 1` (`Evolution.adjoint_comp_self`), with `(t ⊕ c) ⊕ c = t`, and +so needs no operator-algebra computation of the adjoint. -/ +theorem cnotGate_adjoint_op_qubitBasis_tmul (c t : Fin 2) : + (adjoint cnotGate.op) (qubitBasis c ⊗ qubitBasis t).vec + = (qubitBasis c ⊗ qubitBasis (t + c)).vec := by + have hidx : t + c + c = t := by fin_cases c <;> fin_cases t <;> decide + have key : cnotGate.op (qubitBasis c ⊗ qubitBasis (t + c)).vec + = (qubitBasis c ⊗ qubitBasis t).vec := by + rw [cnotGate_op_qubitBasis_tmul, hidx] + rw [← key, ← ContinuousLinearMap.comp_apply, cnotGate.adjoint_comp_self, + one_apply_eq_self] + +/-! ### Exercise 4.19: CNOT permutes the density-matrix entries -/ + +/-- **Nielsen & Chuang, Exercise 4.19: `CNOT` rearranges the density-matrix elements.** Conjugating +a two-qubit density matrix `ρ` by `CNOT` (the state evolution `ρ ↦ CNOT ρ CNOT†`, +`Evolution.evolve`) permutes the computational-basis matrix entries by `cnotBasisPerm` acting on +*both* the row and the column index: +`(CNOT.evolve ρ).twoQubitStdMatrix = ρ.twoQubitStdMatrix.submatrix cnotBasisPerm cnotBasisPerm`, +i.e. entrywise `⟨(c,t)|CNOT ρ CNOT†|(c',t')⟩ = ⟨(c, t⊕c)|ρ|(c', t'⊕c')⟩`. Since `cnotBasisPerm` is +the transposition `|10⟩ ↔ |11⟩` (`cnotBasisPerm_eq_swap`), the concrete effect is to swap the third +and fourth rows, and the third and fourth columns, of the density matrix. -/ +theorem cnotGate_evolve_twoQubitStdMatrix (ρ : State (qubit ⊗ qubit)) : + (cnotGate.evolve ρ).twoQubitStdMatrix + = ρ.twoQubitStdMatrix.submatrix cnotBasisPerm cnotBasisPerm := by + ext i j + simp only [Matrix.submatrix_apply, State.twoQubitStdMatrix_apply, cnotBasisPerm_apply, + Evolution.evolve_op, ContinuousLinearMap.comp_apply] + rw [← ContinuousLinearMap.adjoint_inner_left, cnotGate_adjoint_op_qubitBasis_tmul, + cnotGate_adjoint_op_qubitBasis_tmul] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CascadedMeasurement.lean b/LeanPool/AxQM/Postulates/API/CascadedMeasurement.lean new file mode 100644 index 0000000000..82caff45a2 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CascadedMeasurement.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# AxQM — the cascade of two measurements (N&C Exercise 2.57) + +The **cascade** construction `L.cascade M`: given a measurement `L` (outcomes `κ`) and a +measurement `M` (outcomes `μ`), the composite that measures `L` and then `M` is itself a single +measurement with outcome set `κ × μ` and operators + + `N₍ₗ,ₘ₎ = Mₘ Lₗ` (Nielsen–Chuang Exercise 2.57). + +Completeness of the composite family is exactly the two given completeness relations chained: +`∑₍ₗ,ₘ₎ N₍ₗ,ₘ₎† N₍ₗ,ₘ₎ = ∑ₗ Lₗ† (∑ₘ Mₘ† Mₘ) Lₗ = ∑ₗ Lₗ† Lₗ = 1`, so `cascade` produces a genuine +`Measurement (κ × μ) S` — this is the exercise's construction. The two physical-equivalence +statements (the joint Born probability factorizes as `p(l,m) = p(l)·p(m∣l)`, and the cascade +post-measurement state equals the sequential one) are the theorems in +[upstream `AxQM/NC/Ch2/Exercise2_57.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_57.lean), built on the identities here. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {κ μ : Type*} [Fintype κ] [Fintype μ] {S : QSystem} + +namespace Measurement + +/-- The **cascade** of two measurements `L` (outcomes `κ`) and `M` (outcomes `μ`): the single +measurement with outcome set `κ × μ` whose operator for outcome `(l, m)` is `N₍ₗ,ₘ₎ = Mₘ Lₗ` +(Nielsen–Chuang Exercise 2.57). Completeness `∑₍ₗ,ₘ₎ N₍ₗ,ₘ₎† N₍ₗ,ₘ₎ = 1` chains the completeness +relations of `M` and `L`. -/ +def cascade (L : Measurement κ S) (M : Measurement μ S) : Measurement (κ × μ) S where + op p := (M.op p.2).comp (L.op p.1) + complete := by + rw [← L.complete, Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun l _ => ?_ + have hsummand : ∀ m : μ, + (adjoint ((M.op m).comp (L.op l))).comp ((M.op m).comp (L.op l)) + = (adjoint (L.op l)).comp (((adjoint (M.op m)).comp (M.op m)).comp (L.op l)) := + fun m => by rw [adjoint_comp, comp_assoc, comp_assoc] + simp only [hsummand] + rw [← ContinuousLinearMap.comp_finsetSum, ← ContinuousLinearMap.finsetSum_comp, M.complete, + ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp] + +@[simp] +theorem cascade_op (L : Measurement κ S) (M : Measurement μ S) (l : κ) (m : μ) : + (L.cascade M).op (l, m) = (M.op m).comp (L.op l) := rfl + +/-- The post-measurement operation of the cascade factors through the two individual +post-measurement operations: `E₍ₗ,ₘ₎(ρ) = Mₘ Lₗ ρ Lₗ† Mₘ† = Eₘ(Eₗ(ρ))`. The identity +underlying both physical-equivalence theorems. -/ +theorem postOp_cascade (L : Measurement κ S) (M : Measurement μ S) (ρ : S →L[ℂ] S) (l : κ) (m : μ) : + ContinuousLinearMap.postOp (L.cascade M).op ρ (l, m) + = ContinuousLinearMap.postOp M.op (ContinuousLinearMap.postOp L.op ρ l) m := by + simp only [ContinuousLinearMap.postOp, cascade_op, adjoint_comp, comp_assoc] + +/-! ### Outcome-operator congruence + +Both the Born probability (Postulate 3) and the post-measurement collapse (Postulate 4) are +functions of a *single* outcome's measurement operator `Mᵢ`. Hence two measurements — even over +different outcome sets — that share an outcome operator assign that outcome identical statistics +and identical collapses. These general congruences are exactly what makes "two measurements whose +operators agree up to a relabeling of outcomes are physically equivalent" (e.g. Nielsen–Chuang +Exercise 10.3) a one-line consequence of an operator identity. -/ + +variable {ι₁ ι₂ : Type*} [Fintype ι₁] [Fintype ι₂] + +/-- **Born probabilities depend only on the outcome operator.** If two measurements have the same +operator at a pair of outcomes (`m₁.op i = m₂.op j`), those outcomes have equal Born probability in +every state. -/ +theorem bornProb_congr {m₁ : Measurement ι₁ S} {m₂ : Measurement ι₂ S} {i : ι₁} {j : ι₂} + (h : m₁.op i = m₂.op j) (ρ : State S) : m₁.bornProb ρ i = m₂.bornProb ρ j := by + rw [Measurement.bornProb_eq_re_trace_postOp, Measurement.bornProb_eq_re_trace_postOp, + ContinuousLinearMap.postOp, ContinuousLinearMap.postOp, h] + +/-- **Post-measurement states depend only on the outcome operator.** If two measurements have the +same operator at a pair of (possible) outcomes, those outcomes collapse every state identically. -/ +theorem postMeasurement_congr {m₁ : Measurement ι₁ S} {m₂ : Measurement ι₂ S} {i : ι₁} {j : ι₂} + (h : m₁.op i = m₂.op j) (ρ : State S) (hi : m₁.bornProb ρ i ≠ 0) (hj : m₂.bornProb ρ j ≠ 0) : + m₁.postMeasurement ρ i hi = m₂.postMeasurement ρ j hj := by + apply State.ext + rw [Measurement.postMeasurement_op, Measurement.postMeasurement_op, + ContinuousLinearMap.postState, ContinuousLinearMap.postState, ContinuousLinearMap.postOp, + ContinuousLinearMap.postOp, h] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CertainMeasurement.lean b/LeanPool/AxQM/Postulates/API/CertainMeasurement.lean new file mode 100644 index 0000000000..a7b5b6e892 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CertainMeasurement.lean @@ -0,0 +1,84 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# The certain-outcome measurement + +The **certain-outcome measurement** `certainMeasurement i₀` on a system `T` with outcome set `ι`: +the measurement whose operators are `M_{i₀} = 1` (the identity) and `Mⱼ = 0` for every other +outcome `j ≠ i₀`. It is a genuine `Measurement` (its completeness relation `∑ⱼ Mⱼ† Mⱼ = 1` holds +because only the `i₀` term survives, contributing `1† 1 = 1`), and measuring *any* state returns the +fixed outcome `i₀` with probability `1`. + +It is the quantum counterpart of a classical decision rule that always announces the same value — +the building block for a trivial zero-error code (used, e.g., to witness that rate `0` is an +achievable communication rate over any channel, `AxQM.isProductStateAchievableRate_zero`). + +Compare the other `Measurement` constructions (`Measurement.ofOrthonormalBasis`, +`Measurement.ofOrthonormalBasisFiber`). The Born-rule consequences +(`certainMeasurement_bornProb_self`, `certainMeasurement_bornProb_of_ne`) are stated with +`Measurement.bornProb`. + +## Main definitions and results + +* `AxQM.certainMeasurement` — the certain-outcome measurement with fixed outcome `i₀`. +* `AxQM.certainMeasurement_bornProb_self` — it returns `i₀` with probability `1`. +* `AxQM.certainMeasurement_bornProb_of_ne` — every other outcome has probability `0`. +-/ + +@[expose] public section + +open ContinuousLinearMap InnerProductSpace +open scoped BigOperators + +noncomputable section + +namespace AxQM + +/-- The **certain-outcome measurement** with fixed outcome `i₀`: the POVM `{Mⱼ}` with measurement +operator `M_{i₀} = 1` (the identity) and `Mⱼ = 0` for every other outcome `j ≠ i₀`. Completeness +`∑ⱼ Mⱼ† Mⱼ = 1` holds because only the `i₀` term survives, contributing `1† 1 = 1`. Measuring any +state returns the outcome `i₀` with probability `1` (`certainMeasurement_bornProb_self`); it is the +quantum counterpart of a decoder that always announces the same message. -/ +def certainMeasurement {ι : Type*} [Fintype ι] [DecidableEq ι] {T : QSystem} (i₀ : ι) : + Measurement ι T where + op := fun j => if j = i₀ then 1 else 0 + complete := by + rw [Finset.sum_eq_single i₀] + · rw [ite_eq_left rfl, ← ContinuousLinearMap.star_eq_adjoint, star_one, + ← ContinuousLinearMap.mul_def, one_mul] + · intro j _ hj; rw [ite_eq_right hj]; simp + · intro h; exact absurd (Finset.mem_univ i₀) h + +@[simp] +theorem certainMeasurement_op {ι : Type*} [Fintype ι] [DecidableEq ι] {T : QSystem} (i₀ j : ι) : + (certainMeasurement (T := T) i₀).op j = if j = i₀ then 1 else 0 := rfl + +/-- The certain-outcome measurement assigns probability `0` to any outcome `j ≠ i₀` (its POVM effect +`Mⱼ† Mⱼ = 0`). -/ +theorem certainMeasurement_bornProb_of_ne {ι : Type*} [Fintype ι] [DecidableEq ι] {T : QSystem} + (i₀ : ι) (ρ : State T) (j : ι) (hj : j ≠ i₀) : (certainMeasurement i₀).bornProb ρ j = 0 := by + rw [Measurement.bornProb, POVM.toPMF_eq, Measurement.toPOVM_elements, certainMeasurement_op, + ite_eq_right hj] + simp + +/-- The certain-outcome measurement returns its fixed outcome `i₀` with probability `1` on every +state: the other outcomes have probability `0` (`certainMeasurement_bornProb_of_ne`) and the Born +probabilities sum to `1`. -/ +theorem certainMeasurement_bornProb_self {ι : Type*} [Fintype ι] [DecidableEq ι] {T : QSystem} + (i₀ : ι) (ρ : State T) : (certainMeasurement i₀).bornProb ρ i₀ = 1 := by + have hsum := (certainMeasurement (T := T) i₀).sum_bornProb_eq_one ρ + rw [Finset.sum_eq_single i₀ (fun j _ hj => certainMeasurement_bornProb_of_ne i₀ ρ j hj) + (fun h => absurd (Finset.mem_univ i₀) h)] at hsum + exact hsum + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CnotFanEvolution.lean b/LeanPool/AxQM/Postulates/API/CnotFanEvolution.lean new file mode 100644 index 0000000000..df202056bb --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CnotFanEvolution.lean @@ -0,0 +1,212 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReversibleWire +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Concrete.CnotWirePermGate + +/-! +# The Figure-4.19 parity `CNOT` fan as a register `Evolution` + +Nielsen & Chuang **Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit +gates" — computes the parity `⊕_{i∈S} xᵢ` of a Pauli string's support onto a single *collector* +wire `c` with a fan of `CNOT`s (Figure 4.19). At the matrix level that fan is the reverse `CNOT` +fan `Concrete.cnotFanInto c ts` (control `t ∈ ts`, target `c`), a `Concrete.CliffordCircuit` +(`Concrete/PauliStringParityCascade`). To *count* it with the elementary-gate budget `CircuitBudget` +(which addresses `Evolution`s on the qubit control tower), the fan must first be a register +`Evolution`; this file supplies it. + +## What is formalised + +* `cnotWireEvolution n a b` — a single `CNOT` with control `a` and target `b`, placed on the + `2ⁿ`-level register as an `Evolution (qudit (2ⁿ))`: it is `mcNotWireEvolution n {a} b` (the + one-control multiply-controlled `NOT`) when `a ≠ b`, and the identity when `a = b` (a + self-targeting `CNOT` is undefined; the identity fallback makes the gate a total function of the + two wires, exactly as `Concrete.cnotStep` returns the empty circuit for `t = c`). It is used in + `Core/CnotFanEvolutionBudget`. + +* `cnotFanIntoEvolution n c ts` — the reverse `CNOT` fan into the collector `c`, as one + `Evolution (qudit (2ⁿ))`: the ordered product `∏_{t ∈ ts} cnotWireEvolution n t c` of the per- + control `CNOT`s (a `List.prod` over the control list `ts`). The `Evolution` promotion of + `Concrete.cnotFanInto c ts`; for a collector `c ∉ ts` its `ts.length` factors are genuine + `CNOT`s (each `≤ 2`-control), the `O(n)` two-qubit gates of Figure 4.19. + +The definition takes no `c ∉ ts` hypothesis: `cnotWireEvolution` is total, so the fan is a plain +`List.map … |>.prod`, which keeps the register-transport and gate-count proofs +(`Core/CnotFanEvolutionBudget`) a clean `Evolution.congr_prod` fold. The `c ∉ ts` hypothesis enters +only where it matters — the `O(n)` gate count, which needs every factor to be a real `CNOT`. + +* `cnotWireEvolution_op` / `cnotFanIntoEvolution_op` — **faithfulness**: the operators of the single + register `CNOT` and of the whole fan are exactly the Clifford matrices `(cnotStep a b).toMatrix` / + `(cnotFanInto c ts).toMatrix` (`Concrete/PauliStringParityCascade`), reindexed from bit strings + `Fin n → Fin 2` to the flat register `Fin (2ⁿ)` along `finFunctionFinEquiv` and promoted through + `Matrix.toEuclideanCLM`. So the `Evolution` promotion genuinely *is* the Figure-4.19 parity + circuit `V`, not merely some product of `CNOT`s. The single-gate case rests on the matrix bridge + `Concrete.permGate_mcNotPerm_singleton_eq_submatrix_cnotWireGate` + (`Concrete/CnotWirePermGate`); the fan folds it against `cnotFanInto_cons` / + `CliffordCircuit.toMatrix_append`, with `Matrix.toEuclideanCLM`'s `map_mul` and + `Matrix.submatrix_mul_equiv` distributing the promotion and the reindexing over the product. The + reindex is the same `.submatrix finFunctionFinEquiv.symm` that `pauliStringStd` / `kronFamilyStd` + use, so `cnotFanIntoEvolution_op` chains directly to the matrix-level parity collapse + `pauliString_exp_smul_conj_cnotFanInto`. + +The definitions wrap `mcNotWireEvolution` of `FourGateReversibleWire`, and the gate-count lift +`Core/CnotFanEvolutionBudget` uses `cnotWireEvolution` and `cnotFanIntoEvolution`. +-/ + +@[expose] public section + +open scoped InnerProductSpace Matrix + +namespace AxQM + +noncomputable section + +/-- **A single `CNOT` on register wires, control `a`, target `b`.** Placed on the `2ⁿ`-level +register `qudit (2ⁿ)` as an `Evolution`: the one-control multiply-controlled `NOT` +`mcNotWireEvolution n {a} b` when `a ≠ b` (`b ∉ {a}`), and the identity `1` when `a = b`. The +identity fallback makes `cnotWireEvolution` a total function of `(a, b)` — a self-targeting `CNOT` +being undefined — mirroring `Concrete.cnotStep`, whose circuit is empty for `t = c`. It is the +single-`CNOT` factor the parity fan `cnotFanIntoEvolution` is built from. -/ +def cnotWireEvolution (n : ℕ) (a b : Fin n) : Evolution (qudit (2 ^ n)) := + if h : b = a then 1 else mcNotWireEvolution n {a} b (Finset.notMem_singleton.mpr h) + +/-- **The reverse `CNOT` fan into a collector wire `c`, as a register `Evolution`.** The ordered +product `∏_{t ∈ ts} cnotWireEvolution n t c` of the per-control `CNOT`s `CNOT_{t→c}` (control +`t ∈ ts`, target the collector `c`), placed on the `2ⁿ`-level register `qudit (2ⁿ)`. The +`Evolution` promotion of the matrix-level fan `Concrete.cnotFanInto c ts` +(`Concrete/PauliStringParityCascade`): reading the product right-to-left is Figure 4.19's parity +accumulation, each `CNOT_{t→c}` adding `x_t` into the collector's bit. For a collector `c ∉ ts` all +`ts.length` factors are genuine `≤ 2`-control `CNOT`s, so the fan costs `ts.length` two-qubit gates +(`cnotFanIntoEvolution_circuitBudget`, `Core/CnotFanEvolutionBudget`) — the `O(n)` two-qubit gates +of Problem 4.3(3). -/ +def cnotFanIntoEvolution (n : ℕ) (c : Fin n) (ts : List (Fin n)) : Evolution (qudit (2 ^ n)) := + (ts.map fun t => cnotWireEvolution n t c).prod + +/-- **The fan on no controls is the identity.** `cnotFanIntoEvolution n c [] = 1`, the empty +`List.prod`. -/ +theorem cnotFanIntoEvolution_nil (n : ℕ) (c : Fin n) : cnotFanIntoEvolution n c [] = 1 := rfl + +/-- **Peeling the head control off the fan.** `cnotFanIntoEvolution n c (t :: ts)` +`= cnotWireEvolution n t c * cnotFanIntoEvolution n c ts`: the head `CNOT_{t→c}` composed before the +rest of the fan (`List.prod_cons`). The recursion the faithfulness `cnotFanIntoEvolution_op` folds +against the matrix fan's `cnotFanInto_cons`. -/ +theorem cnotFanIntoEvolution_cons (n : ℕ) (c t : Fin n) (ts : List (Fin n)) : + cnotFanIntoEvolution n c (t :: ts) + = cnotWireEvolution n t c * cnotFanIntoEvolution n c ts := by + simp only [cnotFanIntoEvolution, List.map_cons, List.prod_cons] + +/-- **Faithfulness of a single register `CNOT`.** The operator of `cnotWireEvolution n a b` is the +Clifford `CNOT` matrix of the step `cnotStep a b` (`Concrete/PauliStringEncodingCnotLayer`), +reindexed from bit strings `Fin n → Fin 2` to the flat register `Fin (2ⁿ)` along +`finFunctionFinEquiv` and promoted through `Matrix.toEuclideanCLM`: + +`(cnotWireEvolution n a b).op` +`= Matrix.toEuclideanCLM ((cnotStep a b).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm)`. + +Two branches, matching `cnotWireEvolution` / `cnotStep`'s shared self-target guard: for `a = b` both +collapse to the identity (`quditGate` of `1`, and the empty circuit), and for `a ≠ b` the register +gate is the one-control `mcNotWireEvolution n {a} b` — whose operator is `Matrix.toEuclideanCLM` of +`permGate finFunctionFinEquiv (mcNotPerm {a} …)` (`quditGate_op`) — which the single-`CNOT` matrix +bridge `Concrete.permGate_mcNotPerm_singleton_eq_submatrix_cnotWireGate` identifies with the +reindexed `cnotWireGate a b = (cnotStep a b).toMatrix` (`Concrete.cnotStep_toMatrix_of_ne`). -/ +theorem cnotWireEvolution_op (n : ℕ) (a b : Fin n) : + (cnotWireEvolution n a b).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((Concrete.CliffordCircuit.toMatrix (Concrete.cnotStep a b)).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm) := by + by_cases hab : a = b + · -- identity branch: `a = b` collapses both the register gate and the matrix step to `1`. + have hcw : cnotWireEvolution n a b = 1 := dite_eq_left hab.symm + have hcs : Concrete.CliffordCircuit.toMatrix (Concrete.cnotStep a b) = 1 := by + rw [show Concrete.cnotStep a b = [] from dite_eq_left hab]; rfl + rw [hcw, Evolution.one_def, Evolution.id_op, hcs, Matrix.submatrix_one_equiv] + exact (map_one _).symm + · -- genuine `CNOT` branch: identify the register gate with the reindexed Clifford matrix. + have hbne : ¬ (b = a) := fun h => hab h.symm + have hbmem : b ∉ ({a} : Finset (Fin n)) := Finset.notMem_singleton.mpr hbne + have hop : (cnotWireEvolution n a b).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + (Concrete.permGate finFunctionFinEquiv (Concrete.mcNotPerm {a} hbmem)) := by + rw [show cnotWireEvolution n a b = mcNotWireEvolution n {a} b hbmem from dite_eq_right hbne] + exact quditGate_op _ + rw [hop, Concrete.permGate_mcNotPerm_singleton_eq_submatrix_cnotWireGate finFunctionFinEquiv + a b hbmem, Concrete.cnotStep_toMatrix_of_ne hab] + +/-- **Faithfulness of the parity `CNOT` fan `V`.** The operator of the register fan +`cnotFanIntoEvolution n c ts` is exactly the matrix fan `Concrete.cnotFanInto c ts` +(`Concrete/PauliNormalizerZClear`), reindexed from bit strings `Fin n → Fin 2` to the flat register +`Fin (2ⁿ)` along `finFunctionFinEquiv` and promoted through `Matrix.toEuclideanCLM`: + +`(cnotFanIntoEvolution n c ts).op` +`= Matrix.toEuclideanCLM ((cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm)`. + +This is the **faithfulness** of the `Evolution` promotion: the register fan really *is* the +Figure-4.19 parity circuit `V` of `Concrete/PauliStringParityCascade`, not merely some product of +`CNOT`s — it is what chains the Evolution-level fan to the matrix-level parity collapse +`pauliString_exp_smul_conj_cnotFanInto` (the reindex is the same `.submatrix +finFunctionFinEquiv.symm` that `pauliStringStd` / `kronFamilyStd` use, since a bit-string matrix and +the flat register are identified along `finFunctionFinEquiv`). Proved by induction on the control +list: each `cons` splits off the head `CNOT` (`cnotFanIntoEvolution_cons`; the single-gate +faithfulness `cnotWireEvolution_op`) +and matches it against the matrix fan's `cnotFanInto_cons` + `CliffordCircuit.toMatrix_append`, +distributing the reindexing over the product with `Matrix.submatrix_mul_equiv` and the operator +product with `Matrix.toEuclideanCLM`'s `map_mul`; the `nil` base is `map_one`. -/ +theorem cnotFanIntoEvolution_op (n : ℕ) (c : Fin n) (ts : List (Fin n)) : + (cnotFanIntoEvolution n c ts).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((Concrete.cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm) := by + induction ts with + | nil => + rw [cnotFanIntoEvolution_nil, Evolution.one_def, Evolution.id_op, Concrete.cnotFanInto_nil, + show Concrete.CliffordCircuit.toMatrix ([] : Concrete.CliffordCircuit n) = 1 from rfl, + Matrix.submatrix_one_equiv] + exact (map_one _).symm + | cons t ts ih => + have hsub : ((Concrete.CliffordCircuit.toMatrix (Concrete.cnotStep t c) + * (Concrete.cnotFanInto c ts).toMatrix).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm) + = (Concrete.CliffordCircuit.toMatrix (Concrete.cnotStep t c)).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm + * (Concrete.cnotFanInto c ts).toMatrix.submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm := + (Matrix.submatrix_mul_equiv _ _ finFunctionFinEquiv.symm finFunctionFinEquiv.symm + finFunctionFinEquiv.symm).symm + rw [cnotFanIntoEvolution_cons, Evolution.mul_def, Evolution.comp_op, ih, cnotWireEvolution_op, + Concrete.cnotFanInto_cons, Concrete.CliffordCircuit.toMatrix_append, hsub, map_mul] + rfl + +/-- **Adjoint faithfulness of the parity `CNOT` fan (the uncomputation `V†`).** The operator of +`(cnotFanIntoEvolution n c ts).adjoint` is `Matrix.toEuclideanCLM` of the conjugate transpose of the +reindexed matrix fan `Concrete.cnotFanInto c ts`: + +`(cnotFanIntoEvolution n c ts).adjoint.op` +`= Matrix.toEuclideanCLM (((cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm)ᴴ)`. + +The adjoint companion of `cnotFanIntoEvolution_op`: the `Evolution` adjoint's operator is the +Hilbert-space adjoint of the fan's operator (`Evolution.adjoint_op`), which `toEuclideanCLM` carries +to the matrix conjugate transpose (`Matrix.toEuclideanCLM_conjTranspose_eq_adjoint`). This is the +faithfulness of the fan's *uncomputation* — the `V†` of the Figure-4.19 compute–rotate–uncompute +cascade (Problem 4.3(3)). -/ +theorem cnotFanIntoEvolution_adjoint_op (n : ℕ) (c : Fin n) (ts : List (Fin n)) : + (cnotFanIntoEvolution n c ts).adjoint.op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + (((Concrete.cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm)ᴴ) := by + rw [Evolution.adjoint_op, cnotFanIntoEvolution_op] + exact (Matrix.toEuclideanCLM_conjTranspose_eq_adjoint _).symm + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CnotPauliPropagation.lean b/LeanPool/AxQM/Postulates/API/CnotPauliPropagation.lean new file mode 100644 index 0000000000..fa65eb97d0 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CnotPauliPropagation.lean @@ -0,0 +1,249 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CnotXBasis +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.Teleportation + +/-! +# AxQM.Postulates.API — CNOT propagates Pauli byproducts + +The **Clifford propagation rules for `CNOT`** — how a single-qubit Pauli gate on an input of `CNOT` +commutes to the output — and, as their combined form, the propagation of a **Pauli byproduct** +`X^y Z^x` (`pauliByproduct`) through `CNOT`. This is the algebraic crux of Nielsen & Chuang +**Problem 4.6** ("Universality with prior entanglement"). + +## The role in Problem 4.6 + +Problem 4.6 asks to show that `{single-qubit unitaries, Bell-basis measurement, four-qubit state +preparation}` is a universal set, given that `{CNOT, single-qubit gates}` is. Since single-qubit +gates are shared, it suffices to implement a `CNOT` from the new resources, which is done by +**gate teleportation** (Gottesman–Chuang): the two input qubits are teleported through the +four-qubit resource state `cnotGateTeleportResource` (a `CNOT` pre-applied to two Bell pairs), and +`CNOT` — having been applied to the resource — acts on the teleported inputs. Each teleportation +leaves a **Pauli byproduct** `X^y Z^x` (`pauliByproduct`, resource #1 of Problem 4.6) on its output; +these byproducts sit on the *input* side of the pre-applied `CNOT`. The protocol succeeds — with a +*single-qubit* final correction, as the resource set demands — precisely because **conjugating +single-qubit Pauli byproducts by `CNOT` again yields single-qubit Pauli byproducts** (the Clifford +property). `cnotGate_comp_pauliByproduct_tmul` is exactly that fact, so it is the reason the +gate-teleportation corrections stay single-qubit and hence the reason the alternative resource set +is universal. + +## What is formalised + +The **elementary propagation rules** (the four generators, `CNOT` control = left qubit, target = +right qubit): + +* `cnotGate_comp_pauliXGate_onRight` — `X` on the **target** commutes with `CNOT`: + `CNOT · (1 ⊗ X) = (1 ⊗ X) · CNOT`. +* `cnotGate_comp_pauliXGate_onLeft` — `X` on the **control** copies to the target: + `CNOT · (X ⊗ 1) = (X ⊗ 1) · (1 ⊗ X) · CNOT`. +* `cnotGate_comp_pauliZGate_onLeft` — `Z` on the **control** commutes with `CNOT`: + `CNOT · (Z ⊗ 1) = (Z ⊗ 1) · CNOT`. +* `cnotGate_comp_pauliZGate_onRight` — `Z` on the **target** copies back to the control: + `CNOT · (1 ⊗ Z) = (Z ⊗ 1) · (1 ⊗ Z) · CNOT`. + +The **combined byproduct rule** assembled from them: + +* `cnotGate_comp_pauliByproduct_tmul` — + `CNOT · (X^{y₁}Z^{x₁} ⊗ X^{y₂}Z^{x₂}) = (X^{y₁}Z^{x₁+x₂} ⊗ X^{y₁+y₂}Z^{x₂}) · CNOT`, + i.e. a pair of single-qubit byproducts on the inputs of `CNOT` propagates to a pair of + single-qubit byproducts on its outputs (control `Z`-exponent `x₁ ⊕ x₂`, target `X`-exponent + `y₁ ⊕ y₂`). Stated over `pauliByproduct` so it reads as "the teleportation corrections propagate + through `CNOT` to teleportation corrections". + +Plus the reusable operator-level (arbitrary-vector) companions of the `Evolution` factorisation +lemmas (`Evolution.tmul_op_tmul`, `Evolution.onLeft_op_tmul`, `Evolution.onRight_op_tmul`), general +over `{S T : QSystem}` like their `evolvePure` siblings. + +## Design notes + +* **Statement shape (fidelity).** Each rule is a genuine equality of the gate `Evolution`s (values + of `Evolution`, Postulate 5), so it holds on *every* input, not up to phase or on + basis states. The commutation form `CNOT · P = P' · CNOT` (rather than the conjugation form + `CNOT · P · CNOT = P'`) is what the gate-teleportation protocol uses — pushing a byproduct from + the input side of `CNOT` to the output side — and needs no separate `CNOT² = 1` input. +* **Proof.** Each rule is verified on the four computational-basis inputs via + `twoQubit_evolution_ext`, dropping to the underlying vectors (`PureState.ext`) and computing with + the `CNOT` truth table and the Pauli actions. The `X` rules are sign-free (they stay at the + `PureState`/`evolvePure` level); the `Z` rules carry the phase `Z|i⟩ = (-1)ⁱ|i⟩`, so they descend + to the vector level where the sign is a scalar, reusing the raw-tensor-head homogeneity lemma + `cnotGate_op_smul` (of `Postulates/API/CnotXBasis.lean`) to move the phase through `CNOT`. +* **Reuse.** The same Clifford conjugation facts recur throughout the stabiliser formalism of + Chapter 10. Problem 4.6 itself is in [upstream `AxQM/NC/Ch4/Problem4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_6.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-! ### Operator-level companions of the `Evolution` factorisation lemmas + +The `evolvePure`-level factorisation lemmas of `Postulates/Composite.lean` / +`Postulates/API/ControlledControlledUnitary.lean` (`Evolution.tmul_evolvePure`, +`Evolution.onLeft_evolvePure`, `Evolution.onRight_evolvePure`) act on *pure states*. Their +operator-level companions below act on *arbitrary vectors* `a, b` (needed once a phase `(-1)ⁱ` +turns a basis state into `(-1)ⁱ • |i⟩`, no longer a `PureState`); they are stated general over the +factor systems `{S T : QSystem}` to match their siblings and `Evolution.tmul_op`. (The gate +composite `(U · V) ψ = U (V ψ)` is the existing `Evolution.evolvePure_comp` of +`Postulates/Evolution.lean`, reused directly.) -/ + +/-- **Operator action of a product gate on a pure tensor:** `(U ⊗ V)(a ⊗ b) = (U a) ⊗ (V b)` at the +vector level, for arbitrary vectors `a, b` (the operator-level companion of +`Evolution.tmul_evolvePure`). Since `(U ⊗ V).op` is *definitionally* `TensorProduct.mapL U.op V.op` +(`Evolution.tmul_op`), this is a direct application of `TensorProduct.mapL_tmul`. -/ +theorem Evolution.tmul_op_tmul {S T : QSystem} (U : Evolution S) (V : Evolution T) + (a : S.space) (b : T.space) : + (U ⊗ V).op (a ⊗ₜ[ℂ] b) = U.op a ⊗ₜ[ℂ] V.op b := + TensorProduct.mapL_tmul U.op V.op a b + +/-- **Operator action of a left-factor gate on a pure tensor:** `(U ⊗ 1)(a ⊗ b) = (U a) ⊗ b` at the +vector level, for arbitrary vectors `a, b` (the operator-level companion of +`Evolution.onLeft_evolvePure`). -/ +theorem Evolution.onLeft_op_tmul {S : QSystem} (U : Evolution S) (T : QSystem) + (a : S.space) (b : T.space) : + (U.onLeft T).op (a ⊗ₜ[ℂ] b) = U.op a ⊗ₜ[ℂ] b := by + rw [Evolution.onLeft, Evolution.tmul_op_tmul, Evolution.id_op, one_apply_eq_self] + +/-- **Operator action of a right-factor gate on a pure tensor:** `(1 ⊗ V)(a ⊗ b) = a ⊗ (V b)` at +the vector level, for arbitrary vectors `a, b` (the operator-level companion of +`Evolution.onRight_evolvePure`). -/ +theorem Evolution.onRight_op_tmul {T : QSystem} (V : Evolution T) (S : QSystem) + (a : S.space) (b : T.space) : + (V.onRight S).op (a ⊗ₜ[ℂ] b) = a ⊗ₜ[ℂ] V.op b := by + rw [Evolution.onRight, Evolution.tmul_op_tmul, Evolution.id_op, one_apply_eq_self] + +/-- **Operator of a right-factor gate:** `(V.onRight S).op = TensorProduct.mapL 1 V.op` — the full +`1 ⊗ V` operator, the operator-valued companion of the pointwise `Evolution.onRight_op_tmul`. +Unfolds `Evolution.onRight = id ⊗ V` through `Evolution.tmul_op` (`(U ⊗ V).op = mapL U.op V.op`) and +`Evolution.id_op` (`id.op = 1`), stated as a `TensorProduct.mapL` identity so a right-factor gate +composes with other `TensorProduct.mapL`s. -/ +theorem Evolution.onRight_op {T : QSystem} (V : Evolution T) (S : QSystem) : + (V.onRight S).op = TensorProduct.mapL (1 : S.space →L[ℂ] S.space) V.op := by + simp only [Evolution.onRight, Evolution.tmul_op, Evolution.id_op] + rfl + +/-- **Operator of a left-factor gate:** `(U.onLeft T).op = TensorProduct.mapL U.op 1` — the full +`U ⊗ 1` operator, the operator-valued companion of the pointwise `Evolution.onLeft_op_tmul` and the +left-factor mirror of `Evolution.onRight_op`. Unfolds `Evolution.onLeft = U ⊗ id` through +`Evolution.tmul_op` and `Evolution.id_op`, stated as a `TensorProduct.mapL` identity so a +left-factor gate composes with other `TensorProduct.mapL`s. -/ +theorem Evolution.onLeft_op {S : QSystem} (U : Evolution S) (T : QSystem) : + (U.onLeft T).op = TensorProduct.mapL U.op (1 : T.space →L[ℂ] T.space) := by + simp only [Evolution.onLeft, Evolution.tmul_op, Evolution.id_op] + rfl + +/-! ### Elementary CNOT–Pauli propagation rules -/ + +/-- **`X` on the target commutes with `CNOT`:** `CNOT · (1 ⊗ X) = (1 ⊗ X) · CNOT`. Flipping the +target before or after `CNOT` gives the same gate, since `CNOT` only adds the control to the target. +The `Z₂`-linear (sign-free) generator; a basis-state verification via `twoQubit_evolution_ext`. -/ +theorem cnotGate_comp_pauliXGate_onRight : + cnotGate.comp (pauliXGate.onRight qubit) = (pauliXGate.onRight qubit).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + rw [Evolution.evolvePure_comp, Evolution.evolvePure_comp, Evolution.onRight_evolvePure, + pauliXGate_evolvePure_qubitBasis, cnotGate_evolvePure_qubitBasis, + cnotGate_evolvePure_qubitBasis, Evolution.onRight_evolvePure, + pauliXGate_evolvePure_qubitBasis, add_right_comm] + +/-- **`X` on the control copies to the target through `CNOT`:** +`CNOT · (X ⊗ 1) = (X ⊗ 1) · (1 ⊗ X) · CNOT`. Flipping the control before `CNOT` also flips the +value copied onto the target, so pushing the `X` to the output side leaves an `X` on *both* qubits. +A basis-state verification via `twoQubit_evolution_ext` (sign-free). -/ +theorem cnotGate_comp_pauliXGate_onLeft : + cnotGate.comp (pauliXGate.onLeft qubit) + = ((pauliXGate.onLeft qubit).comp (pauliXGate.onRight qubit)).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + rw [Evolution.evolvePure_comp, Evolution.onLeft_evolvePure, pauliXGate_evolvePure_qubitBasis, + cnotGate_evolvePure_qubitBasis, Evolution.evolvePure_comp, Evolution.evolvePure_comp, + cnotGate_evolvePure_qubitBasis, Evolution.onRight_evolvePure, pauliXGate_evolvePure_qubitBasis, + Evolution.onLeft_evolvePure, pauliXGate_evolvePure_qubitBasis, add_assoc] + +/-- **`Z` on the control commutes with `CNOT`:** `CNOT · (Z ⊗ 1) = (Z ⊗ 1) · CNOT`. `Z` on the +control multiplies by the phase `(-1)ᶜ`, which `CNOT` (leaving the control fixed) does not disturb. +Verified on the computational basis via `twoQubit_evolution_ext`, descending to the vector level for +the phase. -/ +theorem cnotGate_comp_pauliZGate_onLeft : + cnotGate.comp (pauliZGate.onLeft qubit) = (pauliZGate.onLeft qubit).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + apply PureState.ext + simp only [Evolution.evolvePure_comp, Evolution.evolvePure_vec, PureState.tmul_vec] + rw [Evolution.onLeft_op_tmul, pauliZGate_op_apply_qubitBasis, ← TensorProduct.smul_tmul', + cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul] + rw [Evolution.onLeft_op_tmul, pauliZGate_op_apply_qubitBasis, ← TensorProduct.smul_tmul'] + rfl + +/-- **`Z` on the target copies back to the control through `CNOT`:** +`CNOT · (1 ⊗ Z) = (Z ⊗ 1) · (1 ⊗ Z) · CNOT`. `Z` on the target multiplies `|t⟩` by `(-1)ᵗ`; after +`CNOT` maps `t ↦ t ⊕ c`, the same phase reads as `(-1)^{t⊕c}`, i.e. a `Z` on *both* qubits. +Verified on the computational basis via `twoQubit_evolution_ext`, descending to the vector level +for the phase. -/ +theorem cnotGate_comp_pauliZGate_onRight : + cnotGate.comp (pauliZGate.onRight qubit) + = ((pauliZGate.onLeft qubit).comp (pauliZGate.onRight qubit)).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + apply PureState.ext + simp only [Evolution.evolvePure_comp, Evolution.evolvePure_vec, PureState.tmul_vec] + rw [Evolution.onRight_op_tmul, pauliZGate_op_apply_qubitBasis, TensorProduct.tmul_smul, + cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul] + rw [Evolution.onRight_op_tmul, pauliZGate_op_apply_qubitBasis, + Evolution.onLeft_op_tmul, pauliZGate_op_apply_qubitBasis, TensorProduct.tmul_smul, + ← TensorProduct.smul_tmul', smul_smul] + congr 1 + fin_cases c <;> fin_cases t <;> simp + +/-! ### The combined Pauli byproduct propagation -/ + +/-- **`CNOT` propagates single-qubit Pauli byproducts to single-qubit Pauli byproducts.** +For the teleportation byproducts `X^{y₁}Z^{x₁}` (control) and `X^{y₂}Z^{x₂}` (target), +`CNOT · (X^{y₁}Z^{x₁} ⊗ X^{y₂}Z^{x₂}) = (X^{y₁}Z^{x₁ ⊕ x₂} ⊗ X^{y₁ ⊕ y₂}Z^{x₂}) · CNOT`, +i.e. `cnotGate.comp (pauliByproduct x₁ y₁ ⊗ pauliByproduct x₂ y₂) += (pauliByproduct (x₁ + x₂) y₁ ⊗ pauliByproduct x₂ (y₁ + y₂)).comp cnotGate`. + +This is the Clifford property behind Nielsen & Chuang **Problem 4.6**: a pair of single-qubit Pauli +byproducts on the inputs of `CNOT` (the corrections left by teleporting the two input qubits into +the gate-teleportation resource state) commutes to a pair of single-qubit Pauli byproducts on the +outputs — the control acquires the target's `Z`-exponent (`x₁ ⊕ x₂`) and the target acquires the +control's `X`-exponent (`y₁ ⊕ y₂`). Because the propagated corrections are again single-qubit +unitaries, the gate-teleportation protocol implements `CNOT` using only the resource set's +single-qubit corrections; that is why `{single-qubit unitaries, Bell-basis measurement, four-qubit +state preparation}` is universal. + +Proved directly on the four computational-basis inputs (`twoQubit_evolution_ext` + `PureState.ext`): +each byproduct acts as `X^y Z^x|j⟩ = (-1)^{x·j}|j ⊕ y⟩` (`pauliByproduct_op_apply_qubitBasis`), and +after applying the `CNOT` truth table both sides reduce to a common signed computational-basis +vector whose phase is checked by cases. -/ +theorem cnotGate_comp_pauliByproduct_tmul (x₁ y₁ x₂ y₂ : Fin 2) : + cnotGate.comp (pauliByproduct x₁ y₁ ⊗ pauliByproduct x₂ y₂) + = (pauliByproduct (x₁ + x₂) y₁ ⊗ pauliByproduct x₂ (y₁ + y₂)).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + apply PureState.ext + simp only [Evolution.evolvePure_comp, Evolution.evolvePure_vec, PureState.tmul_vec] + rw [Evolution.tmul_op_tmul, pauliByproduct_op_apply_qubitBasis, + pauliByproduct_op_apply_qubitBasis, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, + smul_smul, cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul] + rw [cnotGate_op_qubitBasisVec_tmul, Evolution.tmul_op_tmul, + pauliByproduct_op_apply_qubitBasis, pauliByproduct_op_apply_qubitBasis, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, smul_smul, + show t + y₂ + (c + y₁) = t + c + (y₁ + y₂) by abel] + congr 1 + fin_cases x₁ <;> fin_cases x₂ <;> fin_cases c <;> fin_cases t <;> simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CnotRotationCommutation.lean b/LeanPool/AxQM/Postulates/API/CnotRotationCommutation.lean new file mode 100644 index 0000000000..06c573555c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CnotRotationCommutation.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.GateCommute +public import LeanPool.AxQM.Postulates.API.CnotPauliPropagation +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Postulates.API.HadamardRotation + +/-! +# AxQM.Postulates.API — CNOT commutes with rotations on the untouched axis + +The **rotation-commutation** companions of `AxQM/Postulates/API/CnotPauliPropagation.lean` +(which handles how the discrete Pauli gates propagate through `CNOT`): the two +continuous-rotation identities needed to complete Nielsen & Chuang **Exercise 4.31**, +eqs. (4.38)–(4.39), in +[upstream `AxQM/NC/Ch4/Exercise4_31.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_31.lean). + +Where a Pauli *conjugation* rewrites `CNOT · P · CNOT` to a new Pauli, a rotation on the axis that +`CNOT` leaves invariant simply **commutes** with `CNOT`: + +* `cnotGate_comp_rotZGate_onLeft` — a `z`-rotation on the **control** commutes with `CNOT`: + `CNOT · (R_z(θ) ⊗ 1) = (R_z(θ) ⊗ 1) · CNOT`. `CNOT` acts on the control only through the + computational-basis label `|c⟩`, which `R_z(θ)` merely rephases (`R_z(θ)|c⟩ = e_c |c⟩`); the + control label — hence the whole `CNOT` action — is untouched. +* `cnotGate_comp_rotXGate_onRight` — an `x`-rotation on the **target** commutes with `CNOT`: + `CNOT · (1 ⊗ R_x(θ)) = (1 ⊗ R_x(θ)) · CNOT`. `CNOT` acts on the target by the Pauli `X`, and + `R_x(θ)` is a function of `X`, so the two commute on the target factor; the general + `controlledUnitary_comm_onRight` (from `Postulates/API/GateCommute.lean`) then lifts that to the + controlled gate. + +## Supporting lemmas + +* `rotZGate_op_apply_qubitBasis` — the **eigen-action of `R_z(θ)` on the computational basis**: + `R_z(θ)|c⟩ = (R_z(θ))_{cc} |c⟩` (the `c`-th diagonal entry of the diagonal `Concrete.rotZ`). + The workhorse that lets the phase `e_c` slide through `CNOT`, exactly as + `pauliZGate_op_apply_qubitBasis` does for the `Z` gate in `CnotPauliPropagation.lean`. +* `pauliXGate_comp_rotXGate` — **`X` commutes with `R_x(θ)`** as single-qubit gates + (`X · R_x(θ) = R_x(θ) · X`), the hypothesis `controlledUnitary_comm_onRight` needs. A concrete + `2×2` matrix commutation (`Concrete.pauliX` with `Concrete.rotX θ`) pulled through the `⋆`-algebra + isomorphism `Matrix.toEuclideanCLM`. + +## Design notes + +* **Statement shape (fidelity).** Each commutation rule is a genuine equality of the gate + `Evolution`s (Postulate 5), holding on every input, in the form `CNOT · R = R · CNOT` — the same + commutation shape as the Pauli propagation rules, so [upstream `AxQM/NC/Ch4/Exercise4_31.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_31.lean) reads + the identities off directly (with `.symm`, matching N&C's `R·C = C·R` orientation). +* **Relation to the Pauli rules.** These are the continuous rotations commuting through `CNOT`, + as opposed to the discrete Paulis being conjugated in `CnotPauliPropagation.lean` and + `CnotPauliYPropagation.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Eigen-action of the `z`-rotation gate on the computational basis:** +`R_z(θ)|c⟩ = (R_z(θ))_{cc} |c⟩`, i.e. `(rotZGate θ).op` sends `|c⟩` to the `c`-th diagonal entry of +the (diagonal) matrix `Concrete.rotZ θ` times `|c⟩`. `R_z(θ) = exp(-iθZ/2)` is diagonal in the +computational basis, so every `|c⟩` is an eigenvector; the eigenvalue is left as the abstract +diagonal entry because only its passing *through* `CNOT` as a scalar matters. Proved on +the underlying vectors via `Matrix.ofLp_toEuclideanCLM` and the explicit diagonal form +`Concrete.rotZ_eq`, mirroring `pauliZGate_op_apply_qubitBasis`. -/ +theorem rotZGate_op_apply_qubitBasis (θ : ℝ) (c : Fin 2) : + (rotZGate θ).op (qubitBasis c).vec = Concrete.rotZ θ c c • (qubitBasis c).vec := by + rw [rotZGate_op, qubitBasis_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotZ θ)) + (EuclideanSpace.single c 1)).ofLp + = ((Concrete.rotZ θ c c) • (EuclideanSpace.single c 1 : EuclideanSpace ℂ (Fin 2))).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases c <;> fin_cases j <;> + simp [Concrete.rotZ_eq, Matrix.mulVec, dotProduct, EuclideanSpace.single] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The Pauli `X` gate commutes with the `x`-rotation gate:** `X · R_x(θ) = R_x(θ) · X`. Since +`R_x(θ) = exp(-iθX/2)` is a function of `X`, the two commute; formally, the concrete matrices +`Concrete.pauliX` and `Concrete.rotX θ` commute, and the `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM` (multiplicative) carries that to the gate operators. This is the hypothesis +`controlledUnitary_comm_onRight` needs to conclude `cnotGate_comp_rotXGate_onRight`. -/ +theorem pauliXGate_comp_rotXGate (θ : ℝ) : + pauliXGate.comp (rotXGate θ) = (rotXGate θ).comp pauliXGate := by + have hm : Concrete.pauliX * Concrete.rotX θ = Concrete.rotX θ * Concrete.pauliX := by + rw [Concrete.rotX_eq] + ext i j + fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliX, Matrix.mul_apply, Fin.sum_univ_two] + apply Evolution.ext + rw [Evolution.comp_op, Evolution.comp_op, pauliXGate_op, rotXGate_op] + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX) + * (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotX θ)) + = (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotX θ)) + * (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX) + rw [← map_mul, ← map_mul, hm] + +/-- **A `z`-rotation on the control commutes with `CNOT`:** +`CNOT · (R_z(θ) ⊗ 1) = (R_z(θ) ⊗ 1) · CNOT`. `R_z(θ)` merely rephases each control label +`|c⟩ ↦ e_c|c⟩`, and `CNOT` depends on the control only through that label, so the phase `e_c` +factors out and rides through `CNOT` unchanged. A basis-state verification via +`twoQubit_evolution_ext`, descending to the vector level (`PureState.ext`) for the phase and moving +it through `CNOT` with `cnotGate_op_smul`, exactly as in `cnotGate_comp_pauliZGate_onLeft`. -/ +theorem cnotGate_comp_rotZGate_onLeft (θ : ℝ) : + cnotGate.comp ((rotZGate θ).onLeft qubit) + = ((rotZGate θ).onLeft qubit).comp cnotGate := by + apply twoQubit_evolution_ext + intro c t + apply PureState.ext + simp only [Evolution.evolvePure_comp, Evolution.evolvePure_vec, PureState.tmul_vec] + rw [Evolution.onLeft_op_tmul, rotZGate_op_apply_qubitBasis, ← TensorProduct.smul_tmul', + cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul] + rw [Evolution.onLeft_op_tmul, rotZGate_op_apply_qubitBasis, ← TensorProduct.smul_tmul'] + rfl + +/-- **An `x`-rotation on the target commutes with `CNOT`:** +`CNOT · (1 ⊗ R_x(θ)) = (1 ⊗ R_x(θ)) · CNOT`. `CNOT = C(X)` acts on the target by `X`, and +`R_x(θ)` is a function of `X` (so they commute on the target, `pauliXGate_comp_rotXGate`); the +general controlled-gate/target-gate commutation `controlledUnitary_comm_onRight` then lifts that to +`CNOT`, since `cnotGate = controlledUnitary pauliXGate`. -/ +theorem cnotGate_comp_rotXGate_onRight (θ : ℝ) : + cnotGate.comp ((rotXGate θ).onRight qubit) + = ((rotXGate θ).onRight qubit).comp cnotGate := by + rw [cnotGate_def] + exact controlledUnitary_comm_onRight pauliXGate (rotXGate θ) (pauliXGate_comp_rotXGate θ) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CnotXBasis.lean b/LeanPool/AxQM/Postulates/API/CnotXBasis.lean new file mode 100644 index 0000000000..3dfaddc8e3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CnotXBasis.lean @@ -0,0 +1,199 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CNOTDensityMatrix +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.HadamardGate + +/-! +# AxQM.Postulates.API — CNOT in the `X` (`|±⟩`) basis + +Helpers for Nielsen & Chuang **Exercise 4.20** (CNOT basis transformations): +the operator-level action of `cnotGate` on tensor products of computational- and `X`-eigenbasis +vectors, plus the identification of the Hadamard gate's action on the computational basis with +the `|±⟩` states. The statements of Exercise 4.20 (the `±`-basis truth table and the +reversed-CNOT circuit identity) are proved from them in [upstream `AxQM/NC/Ch4/Exercise4_20.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_20.lean). + +* `cnotGate_op_qubitBasisVec_tmul` — the operator form of the CNOT truth table on the two-qubit + computational basis: `CNOT (|i⟩ ⊗ |j⟩) = |i⟩ ⊗ |j ⊕ i⟩`, at the vector level (the raw-`⊗ₜ` + restatement of `cnotGate_op_qubitBasis_tmul` of `Postulates/API/CNOTDensityMatrix.lean`). This is + the workhorse for computing the CNOT action on `X`-eigenbasis superpositions by linearity. +* `hadamardGate_evolvePure_qubitBasis_zero` / `_one` — `H|0⟩ = |+⟩`, `H|1⟩ = |-⟩`: the Hadamard + gate carries the computational basis to the `X`-eigenbasis. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **CNOT truth table at the operator level, raw-`⊗ₜ` phrasing:** `CNOT(|i⟩ ⊗ |j⟩) = |i⟩ ⊗ |j ⊕ i⟩` +with the tensor written on the underlying vectors `(qubitBasis i).vec ⊗ₜ (qubitBasis j).vec` (rather +than the product-state vector `(qubitBasis i ⊗ qubitBasis j).vec` of +`cnotGate_op_qubitBasis_tmul` in `Postulates/API/CNOTDensityMatrix.lean`, from which it is a +one-step restatement). This is the shape the bilinear expansion of an `X`-eigenvector produces, so +it is the +form the `±`-basis cores below rewrite with; the workhorse for the CNOT action on superpositions. -/ +theorem cnotGate_op_qubitBasisVec_tmul (i j : Fin 2) : + cnotGate.op ((qubitBasis i).vec ⊗ₜ[ℂ] (qubitBasis j).vec) + = (qubitBasis i).vec ⊗ₜ[ℂ] (qubitBasis (j + i)).vec := by + simpa only [PureState.tmul_vec] using cnotGate_op_qubitBasis_tmul i j + +/-- Additivity of `cnotGate.op` on the raw two-qubit tensor space, as an `rw`/`simp`-shaped lemma +(stated with the arguments at the raw tensor head `qubit.space ⊗[ℂ] qubit.space` so it matches the +tensor expansions of `X`-eigenbasis vectors, where the generic `map_add` fails to unify the head +against `cnotGate.op`'s composite domain). -/ +theorem cnotGate_op_add (x y : qubit.space ⊗[ℂ] qubit.space) : + cnotGate.op ((x + y : qubit.space ⊗[ℂ] qubit.space)) = cnotGate.op x + cnotGate.op y := + ContinuousLinearMap.map_add _ _ _ + +/-- Homogeneity of `cnotGate.op` on the raw two-qubit tensor space, the `smul` companion of +`cnotGate_op_add` (see its note on the head-unification issue). -/ +theorem cnotGate_op_smul (c : ℂ) (x : qubit.space ⊗[ℂ] qubit.space) : + cnotGate.op ((c • x : qubit.space ⊗[ℂ] qubit.space)) = c • cnotGate.op x := + ContinuousLinearMap.map_smul _ _ _ + +/-! ### The `±`-basis action of CNOT, on state vectors + +The vector-level cores of Nielsen & Chuang eqs. (4.24)–(4.27): `cnotGate.op` on the underlying +vectors of `|±⟩ ⊗ |±⟩`. Each is proved by expanding both `X`-eigenvectors in the computational +basis (`qubitPlus_vec_eq_smul_add`/`qubitMinus_vec_eq_smul_add`), applying the CNOT truth table +`cnotGate_op_qubitBasisVec_tmul` term by term through the raw-head linearity lemmas +`cnotGate_op_add`/`cnotGate_op_smul`, and recombining. The theorems of +[upstream `AxQM/NC/Ch4/Exercise4_20.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_20.lean) stating (4.24)–(4.27) use them through `PureState.ext`. -/ + +/-- Vector-level form of N&C eq. (4.24): `CNOT(|+⟩ ⊗ |+⟩) = |+⟩ ⊗ |+⟩` at the vector level. -/ +theorem cnotGate_op_qubitPlus_qubitPlus_vec : + cnotGate.op (qubitPlus.vec ⊗ₜ[ℂ] qubitPlus.vec) = qubitPlus.vec ⊗ₜ[ℂ] qubitPlus.vec := by + simp only [qubitPlus_vec_eq_smul_add, smul_add, TensorProduct.add_tmul, TensorProduct.tmul_add, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul] + simp only [cnotGate_op_add, cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul, Fin.reduceAdd] + have hgen : + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 0).vec) : + qubit.space ⊗[ℂ] qubit.space) = + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec) := by + module + exact hgen + +/-- Vector-level form of N&C eq. (4.25): `CNOT(|-⟩ ⊗ |+⟩) = |-⟩ ⊗ |+⟩` at the vector level. -/ +theorem cnotGate_op_qubitMinus_qubitPlus_vec : + cnotGate.op (qubitMinus.vec ⊗ₜ[ℂ] qubitPlus.vec) = qubitMinus.vec ⊗ₜ[ℂ] qubitPlus.vec := by + simp only [qubitPlus_vec_eq_smul_add, qubitMinus_vec_eq_smul_add, smul_add, + TensorProduct.add_tmul, TensorProduct.tmul_add, ← TensorProduct.smul_tmul', + TensorProduct.tmul_smul] + simp only [cnotGate_op_add, cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul, Fin.reduceAdd] + have hgen : + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 0).vec) : + qubit.space ⊗[ℂ] qubit.space) = + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 0).vec + + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec) := by + module + exact hgen + +/-- Vector-level form of N&C eq. (4.26): `CNOT(|+⟩ ⊗ |-⟩) = |-⟩ ⊗ |-⟩` at the vector level. -/ +theorem cnotGate_op_qubitPlus_qubitMinus_vec : + cnotGate.op (qubitPlus.vec ⊗ₜ[ℂ] qubitMinus.vec) = qubitMinus.vec ⊗ₜ[ℂ] qubitMinus.vec := by + simp only [qubitPlus_vec_eq_smul_add, qubitMinus_vec_eq_smul_add, smul_add, + TensorProduct.add_tmul, TensorProduct.tmul_add, ← TensorProduct.smul_tmul', + TensorProduct.tmul_smul] + simp only [cnotGate_op_add, cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul, Fin.reduceAdd] + have hgen : + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec + + (Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 0).vec) : + qubit.space ⊗[ℂ] qubit.space) = + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 0).vec + + (Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis + 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec) := by + module + exact hgen + +/-- Vector-level form of N&C eq. (4.27): `CNOT(|-⟩ ⊗ |-⟩) = |+⟩ ⊗ |-⟩` at the vector level. -/ +theorem cnotGate_op_qubitMinus_qubitMinus_vec : + cnotGate.op (qubitMinus.vec ⊗ₜ[ℂ] qubitMinus.vec) = qubitPlus.vec ⊗ₜ[ℂ] qubitMinus.vec := by + simp only [qubitPlus_vec_eq_smul_add, qubitMinus_vec_eq_smul_add, smul_add, + TensorProduct.add_tmul, TensorProduct.tmul_add, ← TensorProduct.smul_tmul', + TensorProduct.tmul_smul] + simp only [cnotGate_op_add, cnotGate_op_smul, cnotGate_op_qubitBasisVec_tmul, Fin.reduceAdd] + have hgen : + (Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + (Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (-1 : ℂ) • (qubitBasis + 1).vec ⊗ₜ[ℂ] (qubitBasis 0).vec) : + qubit.space ⊗[ℂ] qubit.space) = + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + Concrete.invSqrt2 • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + (Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec + + Concrete.invSqrt2 • (-1 : ℂ) • Concrete.invSqrt2 • (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis + 1).vec) := by + module + exact hgen + +/-- **`H|0⟩ = |+⟩`:** the Hadamard gate carries `|0⟩` to the `X`-eigenstate `|+⟩ = (|0⟩+|1⟩)/√2`. -/ +theorem hadamardGate_evolvePure_qubitBasis_zero : + hadamardGate.evolvePure (qubitBasis 0) = qubitPlus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, hadamardGate_op, qubitBasis_vec, qubitPlus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC) + (EuclideanSpace.single 0 1)).ofLp + = (WithLp.toLp 2 Concrete.xPlus : EuclideanSpace ℂ (Fin 2)).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.hadamardC, Concrete.xPlus, Concrete.invSqrt2, Matrix.mulVec, dotProduct, + EuclideanSpace.single] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **`H|1⟩ = |-⟩`:** the Hadamard gate carries `|1⟩` to the `X`-eigenstate `|-⟩ = (|0⟩-|1⟩)/√2`. -/ +theorem hadamardGate_evolvePure_qubitBasis_one : + hadamardGate.evolvePure (qubitBasis 1) = qubitMinus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, hadamardGate_op, qubitBasis_vec, qubitMinus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC) + (EuclideanSpace.single 1 1)).ofLp + = (WithLp.toLp 2 Concrete.xMinus : EuclideanSpace ℂ (Fin 2)).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.hadamardC, Concrete.xMinus, Concrete.invSqrt2, Matrix.mulVec, dotProduct, + EuclideanSpace.single] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CollectorZRotationEvolution.lean b/LeanPool/AxQM/Postulates/API/CollectorZRotationEvolution.lean new file mode 100644 index 0000000000..fa881b593d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CollectorZRotationEvolution.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableWire +public import LeanPool.AxQM.Concrete.CollectorZRotation + +/-! +# Faithfulness of the Figure-4.19 collector `Z`-rotation as a register `Evolution` + +Nielsen & Chuang **Problem 4.3(3)** — "implement `exp(-i h_g g Δ)` using `O(n)` one- and two-qubit +gates" — applies, after the `CNOT` parity fan computes the support parity onto the collector wire +`c`, a single-qubit `z`-rotation on the collector (Figure 4.19). That gate is the register +`Evolution` `rotZWireEvolution n c θ` (`Postulates/API/FourGateReachableWire.lean`), already +carrying the one-single-qubit-gate budget `rotZWireEvolution_circuitBudget` +(`Core/CnotFanEvolutionBudget.lean`). This file pins down its **operator**. + +## What is formalised + +* `rotZWireEvolution_op_eq_exp_smul_zGenPauli` — **faithfulness**: the operator of the collector + `z`-rotation is exactly the Figure-4.19 collector rotation `exp(s · P_{Z_c})` of the matrix + cascade (`Concrete/PauliStringParityCascade.lean`), reindexed from bit strings `Fin n → Fin 2` + to the flat register `Fin (2ⁿ)` along `finFunctionFinEquiv` and promoted through + `Matrix.toEuclideanCLM`, with scalar `s = (−θ/2) i`: + + `(rotZWireEvolution n c θ).op` + `= Matrix.toEuclideanCLM ((exp((−θ/2) i • pauliString (zGenPauli c))).submatrix e⁻¹ e⁻¹)`. + + The operator is `Matrix.toEuclideanCLM (singleQubitOnWire e c (rotZ θ))` (`quditGate_op`); + rewriting `rotZ θ = exp((−θ/2) i • Z)` (`Concrete.rotZ_eq_exp_smul_pauliZ`) and undoing the + single-wire placement `Concrete.exp_smul_pauliString_zGenPauli_submatrix_eq_singleQubitOnWire` + turns it into the reindexed collector exponential. The reindex `.submatrix e⁻¹ e⁻¹` is the + same one `cnotFanIntoEvolution_op` uses, so this and the fan faithfulness compose under + `Matrix.toEuclideanCLM`'s `map_mul` / `Matrix.submatrix_mul_equiv` to assemble the whole + Figure-4.19 circuit `V† · (Z-rotation) · V` at the operator level (the part-(3) statement, in + `AxQM/Postulates/API/PauliStringExpCircuit.lean`). + +Compare `CnotFanEvolution` (the fan faithfulness it composes with) and `FourGateReachableWire` +(where `rotZWireEvolution` is defined). Physically `θ = 2 h_g Δ` gives the +`s = -i h_g Δ` of the collector rotation. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +noncomputable section + +/-- **Faithfulness of the collector `z`-rotation.** The operator of the register `z`-rotation +`rotZWireEvolution n c θ` on the collector wire `c` is exactly the Figure-4.19 collector rotation +`exp(s · P_{Z_c})` of the parity cascade (`Concrete/PauliStringParityCascade.lean`), reindexed from +bit strings `Fin n → Fin 2` to the flat register `Fin (2ⁿ)` along `finFunctionFinEquiv` and promoted +through `Matrix.toEuclideanCLM`, with `s = (−θ/2) i` (so `θ = 2 h_g Δ` realises `s = -i h_g Δ`): + +`(rotZWireEvolution n c θ).op` +`= Matrix.toEuclideanCLM ((exp((−θ/2) i • pauliString (zGenPauli c))).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm)`. + +By `quditGate_op` the operator is `Matrix.toEuclideanCLM (singleQubitOnWire finFunctionFinEquiv c +(rotZ θ))`; `Concrete.rotZ_eq_exp_smul_pauliZ` rewrites the block `rotZ θ = exp((−θ/2) i • Z)` and +`Concrete.exp_smul_pauliString_zGenPauli_submatrix_eq_singleQubitOnWire` undoes the single-wire +placement to the reindexed collector exponential. This is the collector-rotation companion of the +fan faithfulness `cnotFanIntoEvolution_op`. -/ +theorem rotZWireEvolution_op_eq_exp_smul_zGenPauli (n : ℕ) (c : Fin n) (θ : ℝ) : + (rotZWireEvolution n c θ).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((NormedSpace.exp ((((-(θ / 2) : ℝ) : ℂ) * Complex.I) • + Concrete.pauliString (Concrete.zGenPauli c))).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm) := by + rw [rotZWireEvolution, quditGate_op] + congr 1 + rw [Concrete.exp_smul_pauliString_zGenPauli_submatrix_eq_singleQubitOnWire, + ← Concrete.rotZ_eq_exp_smul_pauliZ] + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CompositeMeasurement.lean b/LeanPool/AxQM/Postulates/API/CompositeMeasurement.lean new file mode 100644 index 0000000000..9eae95e4e3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CompositeMeasurement.lean @@ -0,0 +1,124 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM — measuring one factor of a composite system + +The **measurement on the right factor** `Measurement.onRight`: given a measurement `m` +on a system `T` (outcomes `ι`), the composite system `S ⊗ T` carries the measurement whose +operators act as `m` on `T` and trivially on `S`, + + `Nᵢ = 1_S ⊗ Mᵢ` (Nielsen–Chuang §2.2.8; measuring a subsystem of a composite). + +This is the `Measurement` counterpart of `Evolution.onRight` (`1 ⊗ V`): the reusable way to lift a +measurement of one component to the joint system, leaving the other component untouched. +Completeness `∑ᵢ Nᵢ† Nᵢ = 1` reduces to `m`'s completeness slot-by-slot: `∑ᵢ (1 ⊗ Mᵢ)† (1 ⊗ Mᵢ) = +1 ⊗ (∑ᵢ Mᵢ† Mᵢ) = 1 ⊗ 1 = 1`, via `TensorProduct.mapL_adjoint_comp_self` and +`TensorProduct.mapL_one_sum_right`. + +The mirror construction `Measurement.onLeft` measures the *left* component instead +(`Nᵢ = Mᵢ ⊗ 1_T`), completeness reducing the same way through `TensorProduct.mapL_sum_left`. Either +lift is needed whenever an item measures a subsystem of a composite while keeping the other factor +(e.g. Problem 8.2, where Alice measures the first two of three systems). + +These are used for any item that measures a subsystem of a composite (e.g. measuring the reference +of a purification, Exercise 2.82(2)/(3)). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {T : QSystem} + +namespace Measurement + +/-- **Measurement on the right factor** `Nᵢ = 1_S ⊗ Mᵢ` (Nielsen–Chuang §2.2.8): lift a measurement +`m` of the system `T` to the composite `S ⊗ T`, acting with `m` on `T` and identity on `S`. +Completeness `∑ᵢ Nᵢ† Nᵢ = 1` follows from `m.complete` slot-by-slot: each summand is +`(1 ⊗ Mᵢ)† (1 ⊗ Mᵢ) = 1 ⊗ (Mᵢ† Mᵢ)` (`TensorProduct.mapL_adjoint_comp_self`), and the sum pulls +into the right slot (`TensorProduct.mapL_one_sum_right`) as `1 ⊗ (∑ᵢ Mᵢ† Mᵢ) = 1 ⊗ 1 = 1`. -/ +def onRight (m : Measurement ι T) (S : QSystem) : Measurement ι (S ⊗ T) where + op i := TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i) + complete := by + have key : ∀ i, (adjoint (TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i))).comp + (TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i)) + = TensorProduct.mapL (1 : S →L[ℂ] S) ((adjoint (m.op i)).comp (m.op i)) := by + intro i + rw [TensorProduct.mapL_adjoint_comp_self] + congr 1 + rw [one_def, adjoint_id, id_comp] + calc ∑ i, (adjoint (TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i))).comp + (TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i)) + = ∑ i, TensorProduct.mapL (1 : S →L[ℂ] S) ((adjoint (m.op i)).comp (m.op i)) := + Finset.sum_congr rfl fun i _ => key i + _ = TensorProduct.mapL (1 : S →L[ℂ] S) (∑ i, (adjoint (m.op i)).comp (m.op i)) := + (TensorProduct.mapL_one_sum_right _).symm + _ = TensorProduct.mapL (1 : S →L[ℂ] S) 1 := by rw [m.complete] + _ = 1 := TensorProduct.mapL_one + +@[simp] +theorem onRight_op (m : Measurement ι T) (S : QSystem) (i : ι) : + (m.onRight S).op i = TensorProduct.mapL (1 : S →L[ℂ] S) (m.op i) := rfl + +/-- **Measurement on the left factor** `Nᵢ = Mᵢ ⊗ 1_T` (Nielsen–Chuang §2.2.8): lift a measurement +`m` of the system `S` to the composite `S ⊗ T`, acting with `m` on `S` and identity on `T` — the +mirror image of `onRight`, for measuring the *left* component of a composite. Completeness +`∑ᵢ Nᵢ† Nᵢ = 1` follows from `m.complete` slot-by-slot: each summand is +`(Mᵢ ⊗ 1)† (Mᵢ ⊗ 1) = (Mᵢ† Mᵢ) ⊗ 1` (`TensorProduct.mapL_adjoint_comp_self`), and the sum pulls +into the left slot (`TensorProduct.mapL_sum_left`) as `(∑ᵢ Mᵢ† Mᵢ) ⊗ 1 = 1 ⊗ 1 = 1`. -/ +def onLeft {S : QSystem} (m : Measurement ι S) (T : QSystem) : Measurement ι (S ⊗ T) where + op i := TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T) + complete := by + have key : ∀ i, (adjoint (TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T))).comp + (TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T)) + = TensorProduct.mapL ((adjoint (m.op i)).comp (m.op i)) (1 : T →L[ℂ] T) := by + intro i + rw [TensorProduct.mapL_adjoint_comp_self] + congr 1 + rw [one_def, adjoint_id, id_comp] + calc ∑ i, (adjoint (TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T))).comp + (TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T)) + = ∑ i, TensorProduct.mapL ((adjoint (m.op i)).comp (m.op i)) (1 : T →L[ℂ] T) := + Finset.sum_congr rfl fun i _ => key i + _ = TensorProduct.mapL (∑ i, (adjoint (m.op i)).comp (m.op i)) (1 : T →L[ℂ] T) := + (TensorProduct.mapL_sum_left _ _).symm + _ = TensorProduct.mapL (1 : S →L[ℂ] S) (1 : T →L[ℂ] T) := by rw [m.complete] + _ = 1 := TensorProduct.mapL_one + +@[simp] +theorem onLeft_op {S : QSystem} (m : Measurement ι S) (T : QSystem) (i : ι) : + (m.onLeft T).op i = TensorProduct.mapL (m.op i) (1 : T →L[ℂ] T) := rfl + +/-- The lifted measurement operator `m.onLeft T` acts on the left factor: for a pure tensor +`x ⊗ₜ y` on `S ⊗ T` its operator for outcome `i` is `(Mᵢ x) ⊗ₜ y` (identity on the right factor). -/ +theorem onLeft_op_tmul {S : QSystem} (m : Measurement ι S) (T : QSystem) (i : ι) (x : S.space) + (y : T.space) : (m.onLeft T).op i (x ⊗ₜ[ℂ] y) = (m.op i) x ⊗ₜ[ℂ] y := by + rw [Measurement.onLeft_op]; erw [TensorProduct.mapL_apply, TensorProduct.map_tmul] + rw [ContinuousLinearMap.coe_coe, ContinuousLinearMap.coe_coe, one_apply_eq_self] + +/-- The lifted measurement operator `m.onRight T` acts on the right factor: for a pure tensor +`x ⊗ₜ y` on `T ⊗ S` its operator for outcome `i` is `x ⊗ₜ (Mᵢ y)` (identity on the left factor). -/ +theorem onRight_op_tmul {S : QSystem} (m : Measurement ι S) (T : QSystem) (i : ι) (x : T.space) + (y : S.space) : (m.onRight T).op i (x ⊗ₜ[ℂ] y) = x ⊗ₜ[ℂ] (m.op i) y := by + rw [Measurement.onRight_op]; erw [TensorProduct.mapL_apply, TensorProduct.map_tmul] + rw [ContinuousLinearMap.coe_coe, ContinuousLinearMap.coe_coe, one_apply_eq_self] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CompositeReducedEvolution.lean b/LeanPool/AxQM/Postulates/API/CompositeReducedEvolution.lean new file mode 100644 index 0000000000..c40e5e019b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CompositeReducedEvolution.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MutualInformationEvolution +public import LeanPool.AxQM.Postulates.API.EvolutionTensorHom +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.CompositeStateEvolution + +/-! +# AxQM.Postulates.API — marginals of a product-unitary evolution + +The marginal (reduced-state) laws for a **product unitary** `U ⊗ V` acting on a bipartite state +`ρ` on `S ⊗ T`. They generalise the existing "one factor is the identity" laws +`State.reducedLeft_evolve_id_tmul` / `State.reducedRight_evolve_id_tmul` to the case where *both* +factors carry a nontrivial unitary — the situation that arises when Alice and Bob apply their own +local unitaries simultaneously on disjoint factors (Nielsen & Chuang Exercise 12.22, the +no-communication entanglement-conversion model). + +The physical content: a product unitary `U ⊗ V` conjugates each party's marginal by that party's own +unitary and leaves the other marginal's *support* alone (the other unitary, being trace preserving, +disappears when its factor is traced out). Concretely + +* `State.reducedLeft_evolve_tmul` — `Tr_T((U ⊗ V) ρ (U ⊗ V)†) = U (Tr_T ρ) U† = U.evolve ρ_S`; +* `State.reducedRight_evolve_tmul` — `Tr_S((U ⊗ V) ρ (U ⊗ V)†) = V (Tr_S ρ) V† = V.evolve ρ_T`. + +## Design + +Each law is obtained by factoring the product unitary `U ⊗ V = (U ⊗ I).comp (I ⊗ V)` +(`Evolution.tmul_comp` with the identity on the other factor) so that the two single-factor laws +apply in sequence (`Evolution.evolve_comp`): + +* for `reducedLeft`, the `I ⊗ V` step is invisible to Alice's marginal + (`State.reducedLeft_evolve_id_tmul`) and the `U ⊗ I` step conjugates it + (`State.reducedLeft_evolve_tmul_id`, the mirror of `State.reducedRight_evolve_id_tmul`); +* for `reducedRight`, symmetrically, via the swap `QSystem.Iso.comm` + (`State.reducedRight_congr_comm` reads a right marginal off as a left marginal) after which + `State.reducedLeft_evolve_tmul` applies — the swap turning `U ⊗ V` into `V ⊗ U` is + `Evolution.tmul_congr_comm`. + +The building block `State.reducedLeft_evolve_tmul_id` (Alice's unitary on the *kept* left factor, +identity on the traced right factor) mirrors `State.reducedRight_evolve_id_tmul` at the level of +operators: the partial trace over the traced factor commutes with the kept factor's unitary +(`LinearMap.partialTraceRight_tensorMap_id_comp` / `…_comp_tensorMap_id`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **A local unitary on the kept factor transforms that marginal covariantly.** For a state `ρ` on +`S ⊗ T` and a unitary `U` on the left factor `S`, the reduced state on the *left* factor of +`(U ⊗ I_T) ρ (U ⊗ I_T)†` is `U ρ_S U†` (`U.evolve ρ.reducedLeft`). The identity on the traced-out +`T` factor passes straight through the partial trace over `T` +(`LinearMap.partialTraceRight_tensorMap_id_comp` / `…_comp_tensorMap_id`), leaving the conjugation +by `U` acting on the surviving `S`-marginal. The mirror of `State.reducedRight_evolve_id_tmul`. -/ +theorem State.reducedLeft_evolve_tmul_id (U : Evolution S) (ρ : State (S ⊗ T)) : + ((U.tmul (Evolution.id (S := T))).evolve ρ).reducedLeft = U.evolve ρ.reducedLeft := by + -- Express the evolved operator as `(U ⊗ I) ρ (U ⊗ I)†` at the linear-map level. The adjoint of + -- `U ⊗ I` is `U† ⊗ I`; push it through `TensorProduct.map` via `adjoint_map` under a `congr` (the + -- `QSystem.compose` instance blocks a direct rewrite; `exact` unifies up to defeq). + have hbridge : ((U.tmul (Evolution.id (S := T))).evolve ρ).op.toLinearMap + = TensorProduct.map U.op.toLinearMap LinearMap.id ∘ₗ ρ.op.toLinearMap + ∘ₗ TensorProduct.map (LinearMap.adjoint U.op.toLinearMap) LinearMap.id := by + let ρopCLM : S.space ⊗[ℂ] T.space →L[ℂ] S.space ⊗[ℂ] T.space := ρ.op + have hgen : ((U.tmul (Evolution.id (S := T))).evolve ρ).op.toLinearMap + = (TensorProduct.mapL U.op (1 : T.space →L[ℂ] T.space) ∘L ρopCLM ∘L + TensorProduct.mapL (ContinuousLinearMap.adjoint U.op) + (1 : T.space →L[ℂ] T.space)).toLinearMap := by + rw [show ((U.tmul (Evolution.id (S := T))).evolve ρ).op + = TensorProduct.mapL U.op (1 : T.space →L[ℂ] T.space) ∘L ρopCLM ∘L + ContinuousLinearMap.adjoint (TensorProduct.mapL U.op (1 : T.space →L[ℂ] T.space)) + from rfl, + TensorProduct.adjoint_mapL, ContinuousLinearMap.adjoint_one] + rw [hgen, ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + TensorProduct.toLinearMap_mapL, TensorProduct.toLinearMap_mapL, + ContinuousLinearMap.toLinearMap_one] + rfl + ext1 + rw [State.reducedLeft_op, hbridge, LinearMap.partialTraceRight_tensorMap_id_comp] + apply ContinuousLinearMap.coe_injective + rw [LinearMap.coe_toContinuousLinearMap, Evolution.evolve_op, + ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, + ContinuousLinearMap.adjoint_toLinearMap] + congr 1 + exact LinearMap.partialTraceRight_comp_tensorMap_id (stdOrthonormalBasis ℂ T.space) + (LinearMap.adjoint U.op.toLinearMap) ρ.op.toLinearMap + +/-- **The left marginal after a product-unitary evolution undergoes only the left unitary.** For a +state `ρ` on `S ⊗ T` and a product unitary `U ⊗ V`, tracing out the right factor `T` from +`(U ⊗ V) ρ (U ⊗ V)†` gives `U ρ_S U† = U.evolve ρ.reducedLeft`: the right unitary `V`, being trace +preserving, disappears with its factor, and the left unitary `U` conjugates the surviving +`S`-marginal. Proved by factoring `U ⊗ V = (U ⊗ I).comp (I ⊗ V)` (`Evolution.tmul_comp`, +`Evolution.evolve_comp`) so `State.reducedLeft_evolve_id_tmul` clears the `I ⊗ V` step and +`State.reducedLeft_evolve_tmul_id` conjugates by `U`. -/ +theorem State.reducedLeft_evolve_tmul (U : Evolution S) (V : Evolution T) (ρ : State (S ⊗ T)) : + ((U.tmul V).evolve ρ).reducedLeft = U.evolve ρ.reducedLeft := by + have hUV : (U.tmul (Evolution.id (S := T))).comp ((Evolution.id (S := S)).tmul V) = U.tmul V := by + rw [Evolution.tmul_comp, Evolution.comp_id, Evolution.id_comp] + rw [← hUV, Evolution.evolve_comp, State.reducedLeft_evolve_tmul_id, + State.reducedLeft_evolve_id_tmul] + +/-- **Conjugating a product unitary by the factor swap exchanges its factors.** For unitaries `U` on +`S` and `V` on `T`, transporting `U ⊗ V` along the swap `S ⊗ T ≃ₛ T ⊗ S` gives `V ⊗ U`: +`(U ⊗ V).congr (comm S T) = V ⊗ U`. Proved pointwise on a pure tensor `y ⊗ x`, where both sides act +as `V y ⊗ U x` (the swap turns `y ⊗ x` into `x ⊗ y`, `U ⊗ V` sends it to `U x ⊗ V y`, and the swap +sends that back to `V y ⊗ U x`). The `Evolution` analogue of `State.reducedRight_congr_comm`'s +underlying swap, used to read a right marginal off as a left marginal in +`State.reducedRight_evolve_tmul`. -/ +theorem Evolution.tmul_congr_comm (U : Evolution S) (V : Evolution T) : + (U.tmul V).congr (QSystem.Iso.comm S T) = V.tmul U := by + ext1 + rw [Evolution.congr_op, Evolution.tmul_op, Evolution.tmul_op, QSystem.Iso.comm_toIsometry] + exact TensorProduct.commIsometry_conjStarAlgEquiv_mapL U.op V.op + +/-- **The right marginal after a product-unitary evolution undergoes only the right unitary.** For a +state `ρ` on `S ⊗ T` and a product unitary `U ⊗ V`, tracing out the left factor `S` from +`(U ⊗ V) ρ (U ⊗ V)†` gives `V ρ_T V† = V.evolve ρ.reducedRight`: the left unitary `U`, being trace +preserving, disappears with its factor, and the right unitary `V` conjugates the surviving +`T`-marginal. Proved by reading the right marginal off as a left marginal after the swap +`QSystem.Iso.comm` (`State.reducedRight_congr_comm`), which turns `U ⊗ V` into `V ⊗ U` +(`Evolution.tmul_congr_comm`, transported through evolution by `Evolution.congr_evolve_congr`), and +then applying `State.reducedLeft_evolve_tmul`. The mirror of `State.reducedLeft_evolve_tmul`. -/ +theorem State.reducedRight_evolve_tmul (U : Evolution S) (V : Evolution T) (ρ : State (S ⊗ T)) : + ((U.tmul V).evolve ρ).reducedRight = V.evolve ρ.reducedRight := by + rw [State.reducedRight_congr_comm, ← Evolution.congr_evolve_congr, Evolution.tmul_congr_comm, + State.reducedLeft_evolve_tmul, ← State.reducedRight_congr_comm] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CompositeState.lean b/LeanPool/AxQM/Postulates/API/CompositeState.lean new file mode 100644 index 0000000000..084cba5f87 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CompositeState.lean @@ -0,0 +1,54 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM.Postulates.API — the density operator of a product pure state + +A single derived bridge relating the two ways of forming composite states from pure +components. The pure-state tensor `PureState.tmul` (`ψ ⊗ φ`, N&C §2.2.8) and the +density-state tensor `State.tmul` (`ρ ⊗ σ`) are linked through the vector→operator bridge +`PureState.toState` (`|·⟩⟨·|`): + +* `PureState.toState_tmul` — `|ψ ⊗ φ⟩⟨ψ ⊗ φ| = |ψ⟩⟨ψ| ⊗ |φ⟩⟨φ|`, i.e. forming the density + operator of a product pure state commutes with the tensor product. + +The proof unfolds `State.op` and `PureState.vec` to the rank-one projector +`InnerProductSpace.rankOne`. The identity is used for composite-state reasoning (marginals of +product states, purity of reduced states, …). + +The key step is the general fact +`InnerProductSpace.rankOne_tmul_self` (`|u ⊗ v⟩⟨u ⊗ v| = mapL |u⟩⟨u| |v⟩⟨v|`), which is in +`ToMathlib/Analysis/InnerProductSpace/TensorProduct.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The density operator of a product pure state is the product of the factor density +operators**: `|ψ ⊗ φ⟩⟨ψ ⊗ φ| = |ψ⟩⟨ψ| ⊗ |φ⟩⟨φ|`. The `toState` bridge commutes with the +tensor product, connecting the pure-state tensor `PureState.tmul` with the density-state +tensor `State.tmul`. The key step is `InnerProductSpace.rankOne_tmul_self`. -/ +theorem PureState.toState_tmul (ψ : PureState S) (φ : PureState T) : + (ψ ⊗ φ).toState = ψ.toState ⊗ φ.toState := by + apply State.ext + rw [PureState.toState_op, State.tmul_op, PureState.toState_op, PureState.toState_op, + PureState.tmul_vec] + exact InnerProductSpace.rankOne_tmul_self ψ.vec φ.vec + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CompositeStateEvolution.lean b/LeanPool/AxQM/Postulates/API/CompositeStateEvolution.lean new file mode 100644 index 0000000000..bca07a7e15 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CompositeStateEvolution.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.SystemIso + +/-! +# AxQM.Postulates.API — composite-state evolution algebra + +The **density-operator** analogues of the pure-state composite-evolution laws +`Evolution.tmul_evolvePure` (`Postulates/API/ControlledControlledUnitary`) and +`Evolution.congr_evolvePure_congr` (`Postulates/API/LeftPairGate`): how a product unitary and a +system-isomorphism transport interact with the Schrödinger evolution `U ρ U†` of a mixed `State`. + +* `Evolution.tmul_evolve` — a **product unitary evolves a product state factorwise**: + `(U ⊗ V)(ρ ⊗ σ)(U ⊗ V)† = (U ρ U†) ⊗ (V σ V†)`. The mixed-state companion of + `Evolution.tmul_evolvePure`. +* `Evolution.congr_evolve_congr` — **state transport commutes with evolution**: + transporting the gate `U` and the state `ρ` along a system isomorphism `e` and then evolving is + the same as evolving and then transporting, `(e U e⁻¹)(e ρ e⁻¹)(e U e⁻¹)† = e (U ρ U†) e⁻¹`. The + mixed-state companion of `Evolution.congr_evolvePure_congr`. + +## Design notes + +Both proofs drop to the operators (`.op`) and reduce to the +`TensorProduct.mapL` algebra (`mapL_comp`, `mapL_adjoint`) and the `StarAlgEquiv` naturality of +`conjStarAlgEquiv`. The final `mapL`-adjoint step in `Evolution.tmul_evolve` is discharged by +`congr 2` down to `adjoint (mapL U V) = mapL (adjoint U) (adjoint V)` and then `exact`, rather than +`rw [TensorProduct.adjoint_mapL]`: the tensor-adjoint term produced by `Evolution.evolve_op` and the +one produced by `mapL_adjoint` are *defeq* but not syntactically equal (the composite system's +inner-product instance is a defeq-but-distinct copy of `TensorProduct`'s canonical one, the diamond +documented in `Postulates/API/Interchange`), so `rw`/`simp only [mapL_adjoint]` cannot match it +while a definitionally checked `exact` can. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **A product unitary evolves a product state factorwise:** `(U ⊗ V)(ρ ⊗ σ)(U ⊗ V)† = +(U ρ U†) ⊗ (V σ V†)`. The mixed-state companion of `Evolution.tmul_evolvePure`: the tensor operator +`U ⊗ V = mapL U.op V.op` conjugates the tensor density operator `ρ ⊗ σ = mapL ρ.op σ.op` slotwise, +by multiplicativity of `mapL` (`TensorProduct.mapL_comp`) and its compatibility with the adjoint +(`TensorProduct.adjoint_mapL`). -/ +theorem Evolution.tmul_evolve (U : Evolution S) (V : Evolution T) (ρ : State S) (σ : State T) : + (U ⊗ V).evolve (ρ ⊗ σ) = (U.evolve ρ) ⊗ (V.evolve σ) := by + ext1 + have := FiniteDimensional.completeSpace ℂ S.space + have := FiniteDimensional.completeSpace ℂ T.space + simp only [Evolution.evolve_op, State.tmul_op, Evolution.tmul_op] + have hkey : TensorProduct.mapL U.op V.op ∘L TensorProduct.mapL ρ.op σ.op ∘L + ContinuousLinearMap.adjoint (TensorProduct.mapL U.op V.op) + = TensorProduct.mapL (U.op ∘L ρ.op ∘L ContinuousLinearMap.adjoint U.op) + (V.op ∘L σ.op ∘L ContinuousLinearMap.adjoint V.op) := by + rw [TensorProduct.adjoint_mapL, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp] + exact hkey + +/-- **State transport commutes with evolution:** transporting the gate `U` and the state `ρ` along a +system isomorphism `e : S ≃ₛ T` and then evolving equals evolving and then transporting, +`(e U e⁻¹)(e ρ e⁻¹)(e U e⁻¹)† = e (U ρ U†) e⁻¹`. The mixed-state companion of +`Evolution.congr_evolvePure_congr`: the conjugation `conjStarAlgEquiv e` is a `StarAlgEquiv`, so it +distributes over the operator product and the adjoint that make up `U.evolve ρ = U ρ U†`. -/ +theorem Evolution.congr_evolve_congr (e : S.Iso T) (U : Evolution S) (ρ : State S) : + (U.congr e).evolve (State.congr e ρ) = State.congr e (U.evolve ρ) := by + ext1 + simp only [State.congr_op, Evolution.evolve_op, Evolution.congr_op, + ← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint, map_mul, map_star] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspace.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspace.lean new file mode 100644 index 0000000000..134c82c427 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspace.lean @@ -0,0 +1,195 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PiTensorEigenbasis +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalTypicalSequence + +/-! +# AxQM.Postulates.API — the conditional typical subspace `P_M` (N&C Eqs. 12.74–77) + +The infrastructure for the **conditional typical subspace** of a product codeword in +Nielsen & Chuang's proof of the Holevo–Schumacher–Westmoreland theorem (Theorem 12.8, random-coding +achievability). Alice's codeword for a message `M` produces the channel output +`σ_M = σ_{M₁} ⊗ ⋯ ⊗ σ_{Mₙ}` — an `n`-fold product of *different* output states `σ_{Mᵢ} = E(ρ_{Mᵢ})` +drawn from the input ensemble. Its typical subspace therefore cannot be read off the tensor-power +typical subspace `State.typicalSubspaceProj` (`Postulates/API/TypicalSubspace.lean`), which needs a +single repeated state; it must use the **product eigenbasis** of the distinct factors, +`State.piTensorEigenbasis` (`Postulates/API/PiTensorEigenbasis.lean`). + +Fix a finite family of quantum states `σ : (i : ι) → State (S i)` (the codeword's output factors, +`n = |ι|`). Each `σ i = ∑ₖ λᵢₖ |eᵢₖ⟩⟨eᵢₖ|` has eigenvalue distribution `λᵢ = (σ i).eigenvalueDist`, +so the product state `⨂ₚ i, σ i` is diagonal in the product eigenbasis `|E_κ⟩ = ⨂ᵢ |e_{i,κᵢ}⟩` with +eigenvalue `λ_κ = ∏ᵢ λ_{i,κᵢ}` (`State.piTensor_op_apply_piTensorEigenbasis`). N&C's *conditional* +typical set `T_M` (Eq. 12.75) — the `κ` with `|(1/n)∑ᵢ -log λ_{i,κᵢ} - S_bar| ≤ ε`, `S_bar = ∑ⱼ pⱼ +S(σⱼ)` +— is then exactly the classical `Real.condTypicalSeq λ S_bar ε` of the per-factor spectra, and the +conditional typical *subspace* projector is its `orthonormalProjector`. + +## Main definitions and results + +* `State.condTypicalSubspaceProj σ s ε` — the **conditional typical subspace projector** `P_M` + (N&C Eq. 12.75): the orthogonal projector onto the span of the product eigenvectors `|E_κ⟩` whose + index sequence `κ` is `(s, ε)`-typical for the per-factor eigenvalue distributions. +* `State.condTypicalSubspaceDim σ s ε` — the **rank** of `P_M`, a natural number, + namely the cardinality of the conditional typical set. +* `State.trace_condTypicalSubspaceProj_eq_condTypicalSubspaceDim` — `tr(P_M) = dim` (a projector's + trace is its rank). +* `State.condTypicalSubspaceDim_le` — **the dimension bound** (N&C Eq. 12.77): + `dim(P_M) ≤ exp (n (s + ε))`, a *deterministic* bound holding for every codeword `M` (with + `s = S_bar` the ensemble-average entropy, this is N&C's `tr(P_M) ≤ 2^{n(S_bar+ε)}`). Immediate + from the + classical + `Real.card_condTypicalSeq_le`, the per-factor spectra being probability distributions. +* `State.condTypicalSubspaceProj_isSelfAdjoint` / `State.condTypicalSubspaceProj_idem` — `P_M` is a + self-adjoint idempotent (an orthonormal projector), as the pretty-good decoder `E_M` (Eq. 12.78) + built from the `P_M` requires. + +The distinct-factor generalisation of the tensor-power typical subspace `State.typicalSubspaceProj` +(which is this projector for a constant family `σ i = ρ`). The random-coding *expectation* estimate +`E(tr(σ_M (I − P_M))) ≤ δ` (N&C Eq. 12.76), which needs the law of large numbers over the codeword +distribution, is a separate ingredient and is not part of this deterministic core. + +Compare its constant-family sibling `AxQM/Postulates/API/TypicalSubspace.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +/-- **The conditional typical subspace projector** `P_M` (Nielsen & Chuang, Theorem 12.8, +Eq. 12.75): the orthogonal projector onto the conditional typical subspace of the product codeword +`σ_M = ⨂ₚ i, σ i`, spanned by the product eigenvectors `|E_κ⟩ = ⨂ᵢ |e_{i,κᵢ}⟩` +(`State.piTensorEigenbasis`) whose index sequence `κ` is `(s, ε)`-typical for the per-factor +eigenvalue distributions `λᵢ = (σ i).eigenvalueDist`. Formally the +`InnerProductSpace.orthonormalProjector` of the product eigenbasis restricted to the classical +conditional typical set `Real.condTypicalSeq (fun i ↦ (σ i).eigenvalueDist) s ε`. The threshold `s` +is N&C's ensemble-average entropy `S_bar = ∑ⱼ pⱼ S(σⱼ)`; kept general here. The distinct-factor +generalisation of `State.typicalSubspaceProj` (this projector for a constant family). -/ +def State.condTypicalSubspaceProj (σ : (i : ι) → State (S i)) (s ε : ℝ) : + (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space := + orthonormalProjector ℂ (⇑(State.piTensorEigenbasis σ)) + (Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε) + +/-- **The dimension of the conditional typical subspace** (Nielsen & Chuang, Theorem 12.8): the rank +of `P_M`, i.e. the number of `(s, ε)`-typical index sequences `κ`. A natural number, so the +dimension bound (Eq. 12.77) can be stated for it without the trace. Definitionally the +cardinality of the conditional typical set; equal to `tr(P_M)` via +`trace_condTypicalSubspaceProj_eq_condTypicalSubspaceDim`. -/ +def State.condTypicalSubspaceDim (σ : (i : ι) → State (S i)) (s ε : ℝ) : ℕ := + (Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε).card + +/-- **`tr(P_M) = dim(P_M)`**: the trace of the conditional typical subspace projector equals its +rank (the number of typical sequences). Immediate from the general projector-trace identity +`InnerProductSpace.trace_orthonormalProjector` (trace of `∑_{κ ∈ s} |E_κ⟩⟨E_κ|` is `|s|`), applied +to the product eigenbasis and the conditional typical index set. -/ +theorem State.trace_condTypicalSubspaceProj_eq_condTypicalSubspaceDim (σ : (i : ι) → State (S i)) + (s ε : ℝ) : + LinearMap.trace ℂ (QSystem.piTensor S).space + (State.condTypicalSubspaceProj σ s ε : _ →ₗ[ℂ] _) + = (State.condTypicalSubspaceDim σ s ε : ℂ) := by + rw [State.condTypicalSubspaceProj, trace_orthonormalProjector, State.condTypicalSubspaceDim] + +/-- **The dimension bound of the conditional typical subspace** (Nielsen & Chuang, Theorem 12.8, +Eq. 12.77): `dim(P_M) ≤ exp (n (s + ε))`, `n = |ι|`. A *deterministic* bound — it holds for every +codeword `M`, needing only that each per-factor spectrum `(σ i).eigenvalueDist` is a probability +distribution (`eigenvalueDist_nonneg`, `eigenvalueDist_sum_eq_one`). With `s = S_bar = ∑ⱼ pⱼ S(σⱼ)` +this is N&C's `tr(P_M) ≤ 2^{n(S_bar+ε)}` (natural-log/nats convention). The quantum face of the +classical +`Real.card_condTypicalSeq_le`. -/ +theorem State.condTypicalSubspaceDim_le (σ : (i : ι) → State (S i)) (s ε : ℝ) : + (State.condTypicalSubspaceDim σ s ε : ℝ) ≤ Real.exp ((Fintype.card ι : ℝ) * (s + ε)) := by + rw [State.condTypicalSubspaceDim] + exact Real.card_condTypicalSeq_le (fun i b => (σ i).eigenvalueDist_nonneg b) + (fun i => (σ i).eigenvalueDist_sum_eq_one) s ε + +/-- The conditional typical subspace projector `P_M` is **self-adjoint** (it is an orthonormal +projector). -/ +theorem State.condTypicalSubspaceProj_isSelfAdjoint (σ : (i : ι) → State (S i)) (s ε : ℝ) : + IsSelfAdjoint (State.condTypicalSubspaceProj σ s ε) := + isSelfAdjoint_orthonormalProjector _ _ + +/-- The conditional typical subspace projector `P_M` is **idempotent**, `P_M ∘ P_M = P_M` (it is an +orthonormal projector). -/ +theorem State.condTypicalSubspaceProj_idem (σ : (i : ι) → State (S i)) (s ε : ℝ) : + (State.condTypicalSubspaceProj σ s ε).comp (State.condTypicalSubspaceProj σ s ε) + = State.condTypicalSubspaceProj σ s ε := + isIdempotentElem_orthonormalProjector (State.piTensorEigenbasis σ).orthonormal _ + +/-- The conditional typical subspace projector `P_M` is a **positive** operator (it is a +self-adjoint idempotent, hence `≥ 0` in the Loewner order). -/ +theorem State.condTypicalSubspaceProj_isPositive (σ : (i : ι) → State (S i)) (s ε : ℝ) : + (State.condTypicalSubspaceProj σ s ε).IsPositive := + (ContinuousLinearMap.IsIdempotentElem.isPositive_iff_isSelfAdjoint + (State.condTypicalSubspaceProj_idem σ s ε)).mpr + (State.condTypicalSubspaceProj_isSelfAdjoint σ s ε) + +/-- **The conditional-typical probability of a product codeword** (Nielsen & Chuang, Theorem 12.8, +the object of Eq. 12.76): the trace of the product output state `σ_M = ⨂ₚ i, σ i` against its +conditional typical subspace projector `P_M` is the classical probability mass of the conditional +typical set, + +`tr(σ_M P_M) = ∑_{κ ∈ T_M} ∏ᵢ λ_{i,κᵢ}`, + +the total probability that a run of independent draws `κᵢ ∼ (σ i).eigenvalueDist` lands in the +conditional typical set `T_M`. (Written here as `tr(P_M ∘ σ_M)`, equal to `tr(σ_M P_M)` by +cyclicity.) This is the quantum→classical bridge behind the random-coding estimate +`E(tr(σ_M(I − P_M))) ≤ δ` (Eq. 12.76): it reduces the (a)typical-subspace weight of a codeword to +the classical `condTypicalProb`, on which the law of large numbers over the codeword distribution +then acts. + +The distinct-factor generalisation of `State.typicalSubspaceMeasurement_bornProb_true`. Proof: the +projector-trace lemma `InnerProductSpace.trace_orthonormalProjector_comp` restricts `tr(P_M σ_M)` to +the conditional-typical diagonal `∑_{κ ∈ T_M} ⟪E_κ, σ_M E_κ⟫`, and `σ_M` is diagonal there with +eigenvalue `∏ᵢ λ_{i,κᵢ}` (`State.piTensor_op_apply_piTensorEigenbasis`). -/ +theorem State.re_trace_condTypicalSubspaceProj_comp_piTensor (σ : (i : ι) → State (S i)) (s ε : ℝ) : + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op : _ →ₗ[ℂ] _)) + = ∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ∏ i, (σ i).eigenvalueDist (κ i) := by + rw [State.condTypicalSubspaceProj, trace_orthonormalProjector_comp] + have hterm : ∀ κ, inner ℂ (State.piTensorEigenbasis σ κ) + ((State.piTensor σ).op (State.piTensorEigenbasis σ κ)) + = ((∏ i, (σ i).eigenvalueDist (κ i) : ℝ) : ℂ) := by + intro κ + rw [State.piTensor_op_apply_piTensorEigenbasis, inner_smul_right, + orthonormal_iff_ite.mp (State.piTensorEigenbasis σ).orthonormal, ite_eq_left rfl, mul_one] + rw [Finset.sum_congr rfl (fun κ _ => hterm κ), ← Complex.ofReal_sum] + exact Complex.ofReal_re _ + +/-- **The atypical weight of a product codeword** (Nielsen & Chuang, Theorem 12.8, the left side of +Eq. 12.76): the weight of the product output state `σ_M` outside its conditional typical subspace is +one minus the conditional-typical probability, + +`tr(σ_M (I − P_M)) = 1 − ∑_{κ ∈ T_M} ∏ᵢ λ_{i,κᵢ}`. + +Immediate from `State.re_trace_condTypicalSubspaceProj_comp_piTensor` and the unit trace +`State.trace_op_eq_one` (`tr(σ_M) = 1`): the trace is linear over `(I − P_M)`, and `re` of the real +scalar `1` is `1`. This is exactly N&C's `tr(σ_M(I − P_M))`, whose random-coding expectation is +bounded by `δ` (Eq. 12.76) once the law of large numbers is applied to the classical +`1 − condTypicalProb`. -/ +theorem State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor (σ : (i : ι) → State (S i)) + (s ε : ℝ) : + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (((1 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + - State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op : _ →ₗ[ℂ] _)) + = 1 - ∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ∏ i, (σ i).eigenvalueDist (κ i) := by + rw [ContinuousLinearMap.sub_comp, ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + ContinuousLinearMap.toLinearMap_sub, map_sub, State.trace_op_eq_one, map_sub, RCLike.one_re, + State.re_trace_condTypicalSubspaceProj_comp_piTensor] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceConfusion.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceConfusion.lean new file mode 100644 index 0000000000..6f8f9d15a9 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceConfusion.lean @@ -0,0 +1,242 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceFrame + +/-! +# The HSW cross-message confusion term (N&C Thm 12.8, Box 12.5, eqs. (12.94)→(12.95)) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability) the per-code average error is bounded by the pretty-good-measurement +error estimate of Box 12.5. Its abstract Gram-family form +(`InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le`, eq. (12.94)) has, as one of its +three right-hand frame sums, the **cross-message confusion** double sum + +`∑_{K ∈ T_M} λ^M_K ∑_{K' ∈ T_{M'}} |⟪E_tilde^M_K, E_tilde^{M'}_{K'}⟫|²`, `E_tilde^M_K = P|E^M_K⟩`, + +over the typical-subspace-compressed codeword eigenvectors of two *different* messages `M ≠ M'`. +"Calculating the spurs" (eqs. (12.94)→(12.95)) turns this frame sum into the physical confusion +trace `tr(P σ_M P P_{M'})` of eq. (12.95)/(12.79). This file provides that per-message-pair +evaluation, plus the reusable ordering fact it rests on. + +Both codewords live over the same block index `ι` and factor systems `S`, as HSW codewords do (all +outputs live in the single output space `⨂ₚ i, S`); `P` is any projection (a self-adjoint +idempotent), the typical projector in the application. + +## Main results + +* `AxQM.State.condTypicalSubspaceProj_comp_piTensor_op_le` — the **conditional typical + compression is dominated by the codeword**: `P_M ∘ σ_M ≤ σ_M` in the Loewner order. `P_M` is + spanned by eigenvectors of `σ_M`, so it commutes with `σ_M` and `σ_M − P_M σ_M = (1−P_M) σ_M + (1−P_M) ≥ 0`. This is N&C's step of dropping the `P_M` factor when passing from the exact frame + confusion sum to the over-estimate `tr(P σ_M P P_{M'})`. + +* `AxQM.State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion` — the + **confusion-term bound** (N&C eqs. (12.94)→(12.95)): + `∑_{κ} λ^M_κ ∑_{κ'} ‖⟪P E^M_κ, P E^{M'}_{κ'}⟫‖² ≤ re tr(P σ_M P P_{M'})`. + The frame double sum equals `re tr((P P_{M'} P) ∘ P_M ∘ σ_M)` (the frame operator + `P P_{M'} P = ∑ |E_tilde'⟩⟨E_tilde'|`, `comp_condTypicalSubspaceProj_comp_adjoint_eq_sum`, read + against the + spur evaluator `re_trace_comp_condTypicalSubspaceProj_comp_piTensor`); dropping the `P_M` via + `P_M σ_M ≤ σ_M` and trace monotonicity against the positive `P P_{M'} P` gives the physical trace. + +These use the frame identities of `CondTypicalSubspaceFrame`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.94), (12.95), (12.79). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +-- Operator algebra on the re-bundled `⨂ₛ` space (adjoint / positivity / Loewner order) is +-- elaboration-heavy, so the default heartbeat budget is raised. +/-- **The conditional typical compression is dominated by the codeword** (Nielsen & Chuang, +Theorem 12.8, Box 12.5). For a product codeword `σ_M = ⨂ₚ i, σ i` and its conditional typical +subspace projector `P_M = State.condTypicalSubspaceProj σ s ε`, + +`P_M ∘ σ_M ≤ σ_M` + +in the Loewner order. `P_M` is the orthogonal projector onto a set of eigenvectors of `σ_M`, so it +commutes with `σ_M` (both are diagonal in `State.piTensorEigenbasis σ`); hence +`σ_M − P_M σ_M = (1 − P_M) σ_M (1 − P_M)` is a conjugation of the positive `σ_M`, so it is positive. +This is exactly N&C's step of over-estimating the confusion contribution by dropping the leading +`P_M` when passing from the frame confusion sum to `tr(P σ_M P P_{M'})` (eqs. (12.94)→(12.95)). -/ +theorem State.condTypicalSubspaceProj_comp_piTensor_op_le (σ : (i : ι) → State (S i)) (s ε : ℝ) : + (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op ≤ (State.piTensor σ).op := by + rw [← sub_nonneg, ContinuousLinearMap.nonneg_iff_isPositive] + have hPsa : IsSelfAdjoint (State.condTypicalSubspaceProj σ s ε) := + State.condTypicalSubspaceProj_isSelfAdjoint σ s ε + have hAsa : IsSelfAdjoint (State.piTensor σ).op := State.isSelfAdjoint_op _ + -- `P_M ∘ σ_M` is self-adjoint: it is the eigenvalue-weighted sum of rank-one self-projectors. + have hPAsa : + IsSelfAdjoint ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) := by + have hstar : + star ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) + = (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op := by + rw [State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum, star_sum] + refine Finset.sum_congr rfl fun κ _ => ?_ + rw [star_smul, ContinuousLinearMap.star_eq_adjoint, adjoint_rankOne, ← starRingEnd_apply, + Complex.conj_ofReal] + exact hstar + -- commutation `σ_M ∘ P_M = P_M ∘ σ_M`: `P_M ∘ σ_M` is self-adjoint, so it equals its own adjoint. + have hcomm : (State.piTensor σ).op.comp (State.condTypicalSubspaceProj σ s ε) + = (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op := by + rw [← hPAsa.star_eq, ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_comp, + ← ContinuousLinearMap.star_eq_adjoint, ← ContinuousLinearMap.star_eq_adjoint, + hAsa.star_eq, hPsa.star_eq] + set P := State.condTypicalSubspaceProj σ s ε with hPdef + set A := (State.piTensor σ).op with hAdef + have hidem : P * P = P := State.condTypicalSubspaceProj_idem σ s ε + have hc : A * P = P * A := hcomm + have hdiff : A - P.comp A = (1 - P).comp (A.comp (1 - P)) := by + have hexp : (1 - P).comp (A.comp (1 - P)) = A - A * P - P * A + P * (A * P) := by + simp only [← ContinuousLinearMap.mul_def] + noncomm_ring + rw [show P.comp A = P * A from rfl, hexp, hc, ← mul_assoc, hidem] + abel + rw [hdiff] + have hApos : A.IsPositive := State.isPositive_op _ + have h1Padj : ContinuousLinearMap.adjoint (1 - P) = 1 - P := by + rw [← ContinuousLinearMap.star_eq_adjoint, star_sub, star_one, hPsa.star_eq] + have hconj := hApos.conj_adjoint (1 - P) + rw [h1Padj] at hconj + exact hconj + +-- Operator algebra on the re-bundled `⨂ₛ` space (adjoint / positivity / trace) is +-- elaboration-heavy, so the default heartbeat budget is raised. +/-- **The HSW cross-message confusion-term bound** (Nielsen & Chuang, Theorem 12.8, Box 12.5, the +"calculating the spurs" step, eqs. (12.94)→(12.95)). For two product codewords `σ_M = ⨂ₚ i, σ i`, +`σ_{M'} = ⨂ₚ i, τ i` over the same block index `ι`, and a projection `P` (self-adjoint idempotent — +the typical projector compressing the codeword eigenvectors to `E_tilde = P|E⟩`), + +`∑_{κ ∈ T_M} λ^M_κ ∑_{κ' ∈ T_{M'}} ‖⟪P E^M_κ, P E^{M'}_{κ'}⟫‖² ≤ re tr(P σ_M P P_{M'})`, + +where `T_M`, `T_{M'}` are the conditional typical sets (`Real.condTypicalSeq`), +`λ^M_κ = ∏ᵢ λ_{i,κᵢ}`, `E^M_κ = State.piTensorEigenbasis σ κ`, and +`P_{M'} = State.condTypicalSubspaceProj τ s ε`. + +This is one of the three physical traces N&C's spur substitution produces; instantiated at every +pair `M ≠ M'` it supplies the confusion sum `∑_{M'≠M} tr(P σ_M P P_{M'})` of the per-code error +bound (eq. (12.79)). + +Proof. The frame operator `P P_{M'} P = ∑_{κ'} |E_tilde^{M'}_{κ'}⟩⟨E_tilde^{M'}_{κ'}|` +(`State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum` with `A = P`, `adjoint P = P`); its +diagonal matrix element `⟪E^M_κ, (P P_{M'} P) E^M_κ⟫ = ∑_{κ'} ‖⟪P E^M_κ, P E^{M'}_{κ'}⟫‖²` +(rank-one expansion, using `P` self-adjoint idempotent so `⟪E^M_κ, P E'⟫ = ⟪P E^M_κ, P E'⟫`). The +spur evaluator `State.re_trace_comp_condTypicalSubspaceProj_comp_piTensor` with `B = P P_{M'} P` +then identifies the whole frame sum with `re tr((P P_{M'} P) ∘ P_M ∘ σ_M)`. Finally `P_M σ_M ≤ σ_M` +(`State.condTypicalSubspaceProj_comp_piTensor_op_le`) and trace monotonicity against the positive +`P P_{M'} P` (`ContinuousLinearMap.re_trace_mul_mono_left`) drop the `P_M`, and trace cyclicity +rearranges `(P P_{M'} P) σ_M` into `P σ_M P P_{M'}`. -/ +theorem State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion + (σ τ : (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) : + (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * + ∑ κ' ∈ Real.condTypicalSeq (fun i => (τ i).eigenvalueDist) s ε, + ‖inner ℂ (P (State.piTensorEigenbasis σ κ)) (P (State.piTensorEigenbasis τ κ'))‖ ^ 2) + ≤ RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P.comp ((State.piTensor σ).op.comp + (P.comp (State.condTypicalSubspaceProj τ s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + have hadjP : ContinuousLinearMap.adjoint P = P := hPsa.adjoint_eq + have hfin : ∀ z : ℂ, RCLike.re ((starRingEnd ℂ) z * z) = ‖z‖ ^ 2 := fun z => by + rw [mul_comm, Complex.mul_conj] + change Complex.normSq z = ‖z‖ ^ 2 + exact Complex.normSq_eq_norm_sq z + -- `B := P P_{M'} P` is the frame operator ∑ |E_tilde'⟩⟨E_tilde'| + have hframe : P.comp ((State.condTypicalSubspaceProj τ s ε).comp P) + = ∑ κ' ∈ Real.condTypicalSeq (fun i => (τ i).eigenvalueDist) s ε, + rankOne ℂ (P (State.piTensorEigenbasis τ κ')) (P (State.piTensorEigenbasis τ κ')) := by + have h := State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum τ s ε P + rwa [hadjP] at h + -- Step 1: the frame double sum equals `re tr((P P_{M'} P) ∘ P_M ∘ σ_M)`. + have hstep1 : + (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * + ∑ κ' ∈ Real.condTypicalSeq (fun i => (τ i).eigenvalueDist) s ε, + ‖inner ℂ (P (State.piTensorEigenbasis σ κ)) (P (State.piTensorEigenbasis τ κ'))‖ ^ 2) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((P.comp ((State.condTypicalSubspaceProj τ s ε).comp P)).comp + ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op)) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + rw [State.re_trace_comp_condTypicalSubspaceProj_comp_piTensor σ s ε + (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P))] + refine Finset.sum_congr rfl fun κ _ => ?_ + congr 1 + rw [hframe, _root_.sum_apply, inner_sum, RCLike.re_sum] + refine Finset.sum_congr rfl fun κ' _ => ?_ + rw [rankOne_apply, inner_smul_right] + have hz : inner ℂ (State.piTensorEigenbasis σ κ) (P (State.piTensorEigenbasis τ κ')) + = inner ℂ (P (State.piTensorEigenbasis σ κ)) (P (State.piTensorEigenbasis τ κ')) := by + rw [← ContinuousLinearMap.adjoint_inner_right P (State.piTensorEigenbasis σ κ) + (P (State.piTensorEigenbasis τ κ')), hadjP, + show P (P (State.piTensorEigenbasis τ κ')) + = (P.comp P) (State.piTensorEigenbasis τ κ') from rfl, hPidem] + rw [show inner ℂ (P (State.piTensorEigenbasis τ κ')) (State.piTensorEigenbasis σ κ) + = (starRingEnd ℂ) (inner ℂ (State.piTensorEigenbasis σ κ) + (P (State.piTensorEigenbasis τ κ'))) from + (inner_conj_symm (P (State.piTensorEigenbasis τ κ')) (State.piTensorEigenbasis σ κ)).symm, + hz, hfin] + rw [hstep1] + -- Step 2: drop the `P_M` factor and rearrange to `re tr(P σ_M P P_{M'})`. + have hBpos : (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ P.comp ((State.condTypicalSubspaceProj τ s ε).comp P) := by + rw [ContinuousLinearMap.nonneg_iff_isPositive] + have hPτpos : (State.condTypicalSubspaceProj τ s ε).IsPositive := by + rw [ContinuousLinearMap.IsIdempotentElem.isPositive_iff_isSelfAdjoint + (State.condTypicalSubspaceProj_idem τ s ε)] + exact State.condTypicalSubspaceProj_isSelfAdjoint τ s ε + have hcj := hPτpos.conj_adjoint P + rwa [hadjP] at hcj + have hle : (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op + ≤ (State.piTensor σ).op := + State.condTypicalSubspaceProj_comp_piTensor_op_le σ s ε + have hmono := ContinuousLinearMap.re_trace_mul_mono_left hle hBpos + have heq1 : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((P.comp ((State.condTypicalSubspaceProj τ s ε).comp P)).comp + ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op)) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) + * (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + rw [show (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P)).comp + ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) + = (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P)) + * ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) from rfl, + ContinuousLinearMap.trace_mul_comm] + have hrw2 : (State.piTensor σ).op * (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P)) + = ((State.piTensor σ).op.comp (P.comp (State.condTypicalSubspaceProj τ s ε))) * P := by + simp only [← ContinuousLinearMap.mul_def]; noncomm_ring + have heq2 : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((State.piTensor σ).op * (P.comp ((State.condTypicalSubspaceProj τ s ε).comp P))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P.comp ((State.piTensor σ).op.comp + (P.comp (State.condTypicalSubspaceProj τ s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + rw [hrw2, ContinuousLinearMap.trace_mul_comm, ContinuousLinearMap.mul_def] + rw [heq1] + exact hmono.trans_eq heq2 + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDecoder.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDecoder.lean new file mode 100644 index 0000000000..b40fa640bd --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDecoder.lean @@ -0,0 +1,215 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceFrame +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurementError +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedInverseSqrt + +/-! +# The pretty-good decoder-error bound at the codeword (N&C Thm 12.8, Box 12.5, eqs. (12.84)–(12.88)) + +The *instantiation* of the abstract pretty-good decoder-error reduction +(`InnerProductSpace.one_sub_re_trace_selfAdjoint_conj_frame_le`, N&C eqs. (12.86)→(12.88)) at the +concrete random-coding apparatus of Nielsen & Chuang's Holevo–Schumacher–Westmoreland achievability +argument (Theorem 12.8, `χ(E) = C⁽¹⁾(E)`). + +Alice's codebook is `σ : Fin K → (i : ι) → State (S i)`; message `M` is carried by the product +codeword `σ_M = ⨂ₚ i, σ M i` on `(QSystem.piTensor S).space`, diagonal in the product eigenbasis +`|E^M_κ⟩ = State.piTensorEigenbasis (σ M) κ` with eigenvalue `λ^M_κ = ∏ᵢ (σ M i).eigenvalueDist κᵢ` +(`State.piTensor_op_apply_piTensorEigenbasis`). With `P` the (typical-subspace) projector and +`P_{M'} = State.condTypicalSubspaceProj (σ M') s ε` the conditional typical projectors, N&C's +pretty-good (square-root) decoder is the POVM `POVM.prettyGood A` of the positive family +`A_{M'} = P · P_{M'} · P` (eq. (12.78)): its effect at the true message `M`, +`E_M = S^(-1/2) · (P P_M P) · S^(-1/2)` with `S = ∑_{M'} A_{M'}`, is the conjugation of `A_M` by the +generalized inverse square root `S^(-1/2)` of the total operator. + +## Main results + +* `AxQM.State.piTensor_op_eq_sum_smul_rankOne` — the **full spectral decomposition of a + product codeword**: `σ_M = ∑_κ λ^M_κ |E^M_κ⟩⟨E^M_κ|`, the sum over the *entire* product eigenbasis + (the `T = univ` companion of `State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum`). +* `AxQM.State.sum_prod_eigenvalueDist_eq_one` — the **normalisation of the product + eigenvalue distribution**: `∑_κ λ^M_κ = 1`, the product-of-marginals form of `tr σ_M = 1`. +* `AxQM.State.one_sub_re_trace_prettyGood_le` — the **per-message decoder-error bound** + (N&C eqs. (12.84)–(12.88)). For the pretty-good decoder `POVM.prettyGood A` of the family + `A_{M'} = P P_{M'} P` and any message `M`, the deficit of the correct-decoding trace satisfies + + `1 − re tr(σ_M · E_M) ≤ 2·∑_{κ∈T_M} λ^M_κ (1 − re⟪E_tilde^M_κ, S^(-1/2) E^M_κ⟫) + ∑_{κ∉T_M} + λ^M_κ`, + + where `T_M = Real.condTypicalSeq (fun i ↦ (σ M i).eigenvalueDist) s ε` is the conditional typical + set and `E_tilde^M_κ = P|E^M_κ⟩` the compressed eigenvector. This is N&C's eq. (12.88), with the + decoding overlap kept in the **physical form** `re⟪E_tilde^M_κ, S^(-1/2) E^M_κ⟫`. + +## Proof of the main result + +Instantiate the abstract reduction `InnerProductSpace.one_sub_re_trace_selfAdjoint_conj_frame_le` at +`T = S^(-1/2)` (self-adjoint, `ContinuousLinearMap.isSelfAdjoint_genInvSqrt`), spectral family +`φ_κ = |E^M_κ⟩`, frame family `ψ_κ = P|E^M_κ⟩`, weights `λ^M_κ`, and typical set `J = T_M`. Its +hypotheses `∑_κ λ^M_κ = 1` and `0 ≤ λ^M_κ` are `State.sum_prod_eigenvalueDist_eq_one` and +`State.eigenvalueDist_nonneg`. Its left-hand operator is identified with the physical decoder +trace: + +* `∑_κ λ^M_κ |E^M_κ⟩⟨E^M_κ| = σ_M` is `State.piTensor_op_eq_sum_smul_rankOne`; +* `∑_{κ∈T_M} |E_tilde^M_κ⟩⟨E_tilde^M_κ| = P P_M P = A_M` is the frame identity + `State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum` (with `A = P`, using `P⋆ = P`); +* `E_M = S^(-1/2) · A_M · S^(-1/2)` is `POVM.prettyGood_elements_some` (with `·` the composition + on the + operator monoid). + +The right-hand side is already N&C's eq. (12.88). The final identification of the physical overlap +`re⟪E_tilde^M_κ, S^(-1/2) E^M_κ⟫` with the Gram-square-root diagonal `re⟪e_{(M,κ)}, √Γ e_{(M,κ)}⟫` +of +`State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace` (via `P`-absorption of +`S^(-1/2)` and the Gram identity `ContinuousLinearMap.adjoint_comp_genInvSqrt_comp_self`), and the +average over `M`, are carried out in `AxQM/Postulates/API/CondTypicalSubspacePerCodeError.lean`. + +It composes the frame identities (`CondTypicalSubspaceFrame`) with the abstract +decoder reduction (`ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurementError`). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.78), (12.84)–(12.88). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +/-- **The full spectral decomposition of a product codeword** (Nielsen & Chuang, Theorem 12.8, +Box 12.5). The product state `σ_M = ⨂ₚ i, σ i` is the eigenvalue-weighted sum of the rank-one +projectors onto its *entire* product eigenbasis: + +`σ_M = ∑_κ λ_κ |E_κ⟩⟨E_κ|`, `λ_κ = ∏ᵢ (σ i).eigenvalueDist κᵢ`, +`|E_κ⟩ = State.piTensorEigenbasis σ κ`. + +The `T = univ` companion of `State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum` (which keeps +only the typical terms): the product eigenbasis's resolution of the identity +(`OrthonormalBasis.sum_rankOne_eq_id`) composed with `σ_M` contracts each rank-one's second slot +against `σ_M |E_κ⟩ = λ_κ |E_κ⟩` (`State.piTensor_op_apply_piTensorEigenbasis`, using the +self-adjointness `State.isSelfAdjoint_op`), and the real eigenvalue passes out of the +conjugate-linear slot. -/ +theorem State.piTensor_op_eq_sum_smul_rankOne (σ : (i : ι) → State (S i)) : + (State.piTensor σ).op + = ∑ κ : (i : ι) → Fin (Module.finrank ℂ (S i).space), + ((∏ i, (σ i).eigenvalueDist (κ i) : ℝ) : ℂ) • + rankOne ℂ (State.piTensorEigenbasis σ κ) (State.piTensorEigenbasis σ κ) := by + rw [← ContinuousLinearMap.id_comp (State.piTensor σ).op, + ← OrthonormalBasis.sum_rankOne_eq_id (State.piTensorEigenbasis σ), + ContinuousLinearMap.finsetSum_comp] + refine Finset.sum_congr rfl fun κ _ => ?_ + rw [InnerProductSpace.rankOne_comp, (State.isSelfAdjoint_op (State.piTensor σ)).adjoint_eq, + State.piTensor_op_apply_piTensorEigenbasis] + ext z + simp only [rankOne_apply, FunLike.coe_smul, Pi.smul_apply, inner_smul_left, + Complex.conj_ofReal, smul_smul] + +/-- **Normalisation of the product eigenvalue distribution** (Nielsen & Chuang, Theorem 12.8). The +product eigenvalues `λ_κ = ∏ᵢ (σ i).eigenvalueDist κᵢ` of the product codeword `σ_M = ⨂ₚ i, σ i` sum +to `1`: + +`∑_κ ∏ᵢ (σ i).eigenvalueDist κᵢ = 1`. + +The product-of-marginals form of `tr σ_M = 1`: the sum over product index sequences factors into the +product of the per-factor sums (`Finset.prod_univ_sum`), each of which is `1` +(`State.eigenvalueDist_sum_eq_one`). -/ +theorem State.sum_prod_eigenvalueDist_eq_one (σ : (i : ι) → State (S i)) : + ∑ κ : (i : ι) → Fin (Module.finrank ℂ (S i).space), ∏ i, (σ i).eigenvalueDist (κ i) = 1 := by + have h : (1 : ℝ) = ∏ i : ι, ∑ j, (σ i).eigenvalueDist j := by + simp only [State.eigenvalueDist_sum_eq_one, Finset.prod_const_one] + rw [h, Finset.prod_univ_sum, Fintype.piFinset_univ] + +/-- **The per-message decoder-error bound of the pretty-good measurement** (Nielsen & Chuang, +Theorem 12.8, Box 12.5, eqs. (12.84)–(12.88)). For a codebook `σ : Fin K → (i : ι) → State (S i)`, +a self-adjoint idempotent projector `P`, and the conditional typical projectors +`P_{M'} = State.condTypicalSubspaceProj (σ M') s ε`, form N&C's pretty-good (square-root) decoder +`POVM.prettyGood A` of the positive family `A_{M'} = P · P_{M'} · P` (eq. (12.78)); its effect at +the true message `M` is `E_M = S^(-1/2) · A_M · S^(-1/2)`, `S = ∑_{M'} A_{M'}`, `S^(-1/2) = +S.genInvSqrt`. +Then +the deficit of the correct-decoding trace `re tr(σ_M · E_M)` is bounded by N&C's eq. (12.88): + +`1 − re tr(σ_M · E_M) ≤ 2·∑_{κ∈T_M} λ^M_κ (1 − re⟪E_tilde^M_κ, S^(-1/2) E^M_κ⟫) + ∑_{κ∉T_M} +λ^M_κ`, + +where `T_M = Real.condTypicalSeq (fun i ↦ (σ M i).eigenvalueDist) s ε`, +`λ^M_κ = ∏ᵢ (σ M i).eigenvalueDist κᵢ`, `E^M_κ = State.piTensorEigenbasis (σ M) κ`, and +`E_tilde^M_κ = P E^M_κ` is the compressed eigenvector. The decoding overlap `re⟪E_tilde^M_κ, +S^(-1/2) E^M_κ⟫` is +N&C's diagonal `α_{(M,κ),(M,κ)}` kept in physical form +(its identification with the Gram-square-root diagonal `re⟪e, √Γ e⟫` is in +`AxQM/Postulates/API/CondTypicalSubspacePerCodeError.lean`). + +Instantiates the abstract reduction +`InnerProductSpace.one_sub_re_trace_selfAdjoint_conj_frame_le` at +`T = S^(-1/2)`, `φ = |E^M_κ⟩`, `ψ = P|E^M_κ⟩`, `λ = λ^M_κ`, `J = T_M`, identifying its left-hand +operator with the physical decoder trace via `State.piTensor_op_eq_sum_smul_rankOne` (the codeword +`σ_M`), `State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum` (the frame `A_M = P P_M P`), and +`POVM.prettyGood_elements_some` (the decoder effect `E_M`). -/ +theorem State.one_sub_re_trace_prettyGood_le {K : ℕ} (σ : Fin K → (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) + (hA : ∀ M', (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)) + (M : Fin K) : + 1 - RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((State.piTensor (σ M)).op.comp + ((POVM.prettyGood (fun M' => P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)) + hA).elements (some M))) : (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + ≤ 2 * ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + (∏ i, (σ M i).eigenvalueDist (κ i)) * + (1 - RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ M) κ)))) + + ∑ κ ∈ (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε)ᶜ, + ∏ i, (σ M i).eigenvalueDist (κ i) := by + classical + set A : Fin K → ((QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) := + fun M' => P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P) with hAdef + have hPadj : ContinuousLinearMap.adjoint P = P := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact hPsa + have hSop : (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) ≤ ∑ M', A M' := + Finset.sum_nonneg fun M' _ => hA M' + -- The frame operator `A_M = ∑_{κ∈T_M} |P E_κ⟩⟨P E_κ|`. + have hAM : A M = ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + rankOne ℂ (P (State.piTensorEigenbasis (σ M) κ)) (P (State.piTensorEigenbasis (σ M) κ)) := by + have h := State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum (σ M) s ε P + rw [hPadj] at h + exact h + -- The pretty-good decoder effect `E_M = S^(-1/2) · A_M · S^(-1/2)`, in composition form. + have hEff : (POVM.prettyGood A hA).elements (some M) + = (∑ M', A M').genInvSqrt.comp + ((∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + rankOne ℂ (P (State.piTensorEigenbasis (σ M) κ)) + (P (State.piTensorEigenbasis (σ M) κ))).comp (∑ M', A M').genInvSqrt) := by + rw [POVM.prettyGood_elements_some, hAM, mul_assoc] + rfl + -- Instantiate the abstract pretty-good decoder-error reduction (eqs. (12.86)→(12.88)). + have key := InnerProductSpace.one_sub_re_trace_selfAdjoint_conj_frame_le + (∑ M', A M').genInvSqrt (ContinuousLinearMap.isSelfAdjoint_genInvSqrt hSop) + (fun κ => State.piTensorEigenbasis (σ M) κ) + (fun κ => P (State.piTensorEigenbasis (σ M) κ)) + (fun κ => ∏ i, (σ M i).eigenvalueDist (κ i)) + (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => Finset.prod_nonneg fun i _ => State.eigenvalueDist_nonneg _ _) + (State.sum_prod_eigenvalueDist_eq_one (σ M)) + rw [hEff, State.piTensor_op_eq_sum_smul_rankOne (σ M)] + exact key + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDiagonal.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDiagonal.lean new file mode 100644 index 0000000000..0dd6e83849 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceDiagonal.lean @@ -0,0 +1,268 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceConfusion + +/-! +# The HSW same-message diagonal spur (N&C Thm 12.8, Box 12.5, eqs. (12.94)→(12.79)) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability) the per-code average error is bounded by the pretty-good-measurement +error estimate of Box 12.5. Its abstract Gram-family form +(`InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le`, eq. (12.94)) bounds the decoding +deficit `2·∑_c λ_c (1 − α_{cc})` — over the *global* typical index `c = (M, κ)`, `κ ∈ T_M` — +by three right-hand frame sums + +`2·∑_c λ_c − 3·∑_c λ_c ‖ψ_c‖² + ∑_c ∑_{c'} λ_c |⟪ψ_c, ψ_{c'}⟫|²`, `ψ_{(M,κ)} = P|E^M_κ⟩`. + +Grouping the global index by the message `M`, the contribution of one message splits into a +**same-message** part (the diagonal `M' = M`) plus the **cross-message** confusion part (`M' ≠ M`, +handled by `State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion`). This file +provides the same-message part: its three sums, `2·∑_{κ∈T} λ_κ`, `−3·∑_{κ∈T} λ_κ‖P E_κ‖²`, and the +diagonal frame double sum `∑_{κ∈T} λ_κ ∑_{κ'∈T} |⟪P E_κ, P E_{κ'}⟫|²`, combine into the two physical +error terms of the per-code bound eq. (12.79): + +`≤ 3·tr(σ_M (1 − P)) + tr(σ_M (1 − P_M))`. + +## Main result + +* `AxQM.State.sum_eigenvalueDist_sameMessageSpur_le_re_trace` — the same-message diagonal + spur bound: for a product codeword `σ_M = ⨂ₚ i, σ i`, its conditional typical subspace projector + `P_M = State.condTypicalSubspaceProj σ s ε`, and a projection `P` (self-adjoint idempotent — the + typical projector), + + `2·∑_{κ∈T} λ_κ − 3·∑_{κ∈T} λ_κ‖P E_κ‖² + ∑_{κ∈T} λ_κ ∑_{κ'∈T} ‖⟪P E_κ, P E_{κ'}⟫‖²` + ` ≤ 3·re tr((1 − P) σ_M) + re tr((1 − P_M) σ_M)`, + + where `T = Real.condTypicalSeq (fun i ↦ (σ i).eigenvalueDist) s ε`, `λ_κ = ∏ᵢ λ_{i,κᵢ}`, and + `E_κ = State.piTensorEigenbasis σ κ`. + +## Proof + +Abbreviate `A = σ_M`, `P_M`, and write `re tr(X)` for the real trace. Three trace identities read +the frame sums as physical traces (all via the spur/frame lemmas of `CondTypicalSubspaceFrame` +and the confusion bound of `CondTypicalSubspaceConfusion`): + +* `∑_{κ∈T} λ_κ = re tr(P_M A)` (the typical mass, `re_trace_condTypicalSubspaceProj_comp_piTensor`); +* `∑_{κ∈T} λ_κ ‖P E_κ‖² = re tr(P P_M A)` (the spur evaluator at `B = P`, using + `re⟪E_κ, P E_κ⟫ = ‖P E_κ‖²` for a projection `P`); +* the diagonal frame double sum `≤ re tr(P σ_M P P_M)` (the confusion bound at the *same* codeword + `σ`). + +The remaining step is trace algebra, closed by `linarith`, using that `P` and `P_M` are between `0` +and `1`, that `(1 − P_M) A` is positive (`P_M` is spanned by eigenvectors of `A`, so `P_M A ≤ A`, +`State.condTypicalSubspaceProj_comp_piTensor_op_le`), trace monotonicity +(`ContinuousLinearMap.re_trace_mul_mono_left`), and nonnegativity of the trace of a product of +positive operators (`ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg`). Concretely, with +`a = re tr(P A)`: the diagonal frame trace is `≤ re tr(P σ_M P P_M) ≤ re tr(P σ_M P) = a` (drop +`P_M ≤ 1`); and `re tr(P P_M A) ≥ a − tr((1 − P_M) A)` (the `P`-weight of the atypical block is +`≤` its full trace). The two combine to `≤ 3(re tr A − a) + (re tr A − re tr(P_M A))`, the two +physical terms. No use is made of `tr σ_M = 1`, so the bound holds for any positive `A`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.94), (12.95), (12.79). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +-- Operator algebra on the re-bundled `⨂ₛ` space (adjoint / positivity / trace) is +-- elaboration-heavy, so the default heartbeat budget is raised. +/-- **The HSW same-message diagonal spur bound** (Nielsen & Chuang, Theorem 12.8, Box 12.5, the +same-message part of the "calculating the spurs" step, eqs. (12.94)→(12.79)). For a product +codeword `σ_M = ⨂ₚ i, σ i` with conditional typical subspace projector +`P_M = State.condTypicalSubspaceProj σ s ε`, and a projection `P` (self-adjoint idempotent — the +typical projector compressing the codeword eigenvectors to `E_tilde = P|E⟩`), + +`2·∑_{κ∈T} λ_κ − 3·∑_{κ∈T} λ_κ‖P E_κ‖² + ∑_{κ∈T} λ_κ ∑_{κ'∈T} ‖⟪P E_κ, P E_{κ'}⟫‖²` +` ≤ 3·re tr((1 − P) σ_M) + re tr((1 − P_M) σ_M)`, + +where `T = Real.condTypicalSeq (fun i ↦ (σ i).eigenvalueDist) s ε`, `λ_κ = ∏ᵢ λ_{i,κᵢ}`, and +`E_κ = State.piTensorEigenbasis σ κ`. + +The left-hand side is the same-message (`M' = M`) contribution of the abstract Gram-family bound +(N&C eq. (12.94)) grouped by message; the right-hand side is the corresponding two physical error +terms of the per-code bound eq. (12.79) (`3·tr(σ_M(I−P)) + tr(σ_M(I−P_M))`). Together with the +cross-message confusion bound +(`State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion`, summed over `M' ≠ M`) +it supplies the per-message content of the global-index assembly of eq. (12.79). + +The three frame sums are read as physical traces via the spur/frame lemmas, and the trace +algebra is closed by `linarith` using `0 ≤ P, P_M ≤ 1`, positivity of `(1 − P_M) σ_M`, and trace +monotonicity/nonnegativity; see the module docstring. -/ +theorem State.sum_eigenvalueDist_sameMessageSpur_le_re_trace (σ : (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) : + 2 * (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ∏ i, (σ i).eigenvalueDist (κ i)) + - 3 * (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * ‖P (State.piTensorEigenbasis σ κ)‖ ^ 2) + + (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * + ∑ κ' ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ‖inner ℂ (P (State.piTensorEigenbasis σ κ)) + (P (State.piTensorEigenbasis σ κ'))‖ ^ 2) + ≤ 3 * RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((1 - P) * (State.piTensor σ).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + classical + -- `adjoint P = P` for the self-adjoint projection. + have hadjP : ContinuousLinearMap.adjoint P = P := hPsa.adjoint_eq + -- `P` and `P_M` are between `0` and `1` (they are self-adjoint idempotents). + have hPidemElt : IsIdempotentElem P := hPidem + have hP_le1 : P ≤ 1 := ContinuousLinearMap.IsIdempotentElem.le_one hPidemElt hPsa + have h1P_nonneg : + (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) ≤ 1 - P := + sub_nonneg.mpr hP_le1 + have hPmidemElt : IsIdempotentElem (State.condTypicalSubspaceProj σ s ε) := + State.condTypicalSubspaceProj_idem σ s ε + have hPmsa : IsSelfAdjoint (State.condTypicalSubspaceProj σ s ε) := + State.condTypicalSubspaceProj_isSelfAdjoint σ s ε + have hPm_le1 : State.condTypicalSubspaceProj σ s ε ≤ 1 := + ContinuousLinearMap.IsIdempotentElem.le_one hPmidemElt hPmsa + -- Positivity of the codeword and of the atypical block `(1 − P_M) σ_M`. + have hA_pos : (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ (State.piTensor σ).op := + ContinuousLinearMap.nonneg_iff_isPositive.mpr (State.isPositive_op _) + have hle : (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op + ≤ (State.piTensor σ).op := + State.condTypicalSubspaceProj_comp_piTensor_op_le σ s ε + have h1PmA_nonneg : + (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ (1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op := by + have hrw : ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) + = (State.piTensor σ).op + - (State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op := by + rw [sub_mul, one_mul] + rw [hrw] + have hlt : (State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op + ≤ (State.piTensor σ).op := by + rw [ContinuousLinearMap.mul_def]; exact hle + exact sub_nonneg.mpr hlt + -- Positivity of `P σ_M P` (conjugation of the positive `σ_M` by the self-adjoint `P`). + have hPAP_pos : (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ P * ((State.piTensor σ).op * P) := by + rw [ContinuousLinearMap.nonneg_iff_isPositive] + have hcj := (ContinuousLinearMap.nonneg_iff_isPositive.mp hA_pos).conj_adjoint P + rw [hadjP] at hcj + simpa only [← ContinuousLinearMap.mul_def] using hcj + -- `re⟪E_κ, P E_κ⟫ = ‖P E_κ‖²` for the projection `P`. + have hnorm : ∀ κ, RCLike.re (inner ℂ (State.piTensorEigenbasis σ κ) + (P (State.piTensorEigenbasis σ κ))) = ‖P (State.piTensorEigenbasis σ κ)‖ ^ 2 := by + intro κ + rw [inner_self_of_isSelfAdjoint_of_isIdempotent hPsa hPidemElt, RCLike.ofReal_re] + -- Frame sum 1 (typical mass): `∑ λ = re tr(P_M σ_M)`. + have e1 : (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ∏ i, (σ i).eigenvalueDist (κ i)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) := by + rw [show ((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) + = (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op from rfl, + State.re_trace_condTypicalSubspaceProj_comp_piTensor σ s ε] + -- Frame sum 2 (`‖P E_κ‖²`-weight): `∑ λ‖P E_κ‖² = re tr(P P_M σ_M)`. + have e2 : (∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * ‖P (State.piTensorEigenbasis σ κ)‖ ^ 2) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) : + _ →ₗ[ℂ] _)) := by + rw [show (P * ((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) + = P.comp ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) from rfl, + State.re_trace_comp_condTypicalSubspaceProj_comp_piTensor σ s ε P] + exact Finset.sum_congr rfl fun κ _ => by rw [hnorm κ] + -- Frame sum 3 (diagonal confusion sum): `≤ re tr(P σ_M P P_M)` (confusion bound at `σ = τ`). + have hC := State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion σ σ s ε P + hPsa hPidem + simp only [← ContinuousLinearMap.mul_def] at hC + -- Cyclicity/idempotence: `re tr(P σ_M P) = re tr(P σ_M)`. + have hPmul : P * P = P := hPidem + have heqPAP : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((State.piTensor σ).op * P)) : _ →ₗ[ℂ] _)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) := by + rw [congrArg RCLike.re (ContinuousLinearMap.trace_mul_comm P ((State.piTensor σ).op * P)), + show (((State.piTensor σ).op * P) * P) = (State.piTensor σ).op * P from by + rw [mul_assoc, hPmul], + congrArg RCLike.re (ContinuousLinearMap.trace_mul_comm (State.piTensor σ).op P)] + -- Drop `P_M ≤ 1`: `re tr(P σ_M P P_M) ≤ re tr(P σ_M)`. + have hassoc : (P * ((State.piTensor σ).op * P)) * (State.condTypicalSubspaceProj σ s ε) + = P * ((State.piTensor σ).op * (P * (State.condTypicalSubspaceProj σ s ε))) := by + rw [mul_assoc, mul_assoc] + have hCle : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((State.piTensor σ).op * (P * (State.condTypicalSubspaceProj σ s ε)))) : _ →ₗ[ℂ] _)) + ≤ RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) := by + have hcyc : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((State.piTensor σ).op * (P * (State.condTypicalSubspaceProj σ s ε)))) + : _ →ₗ[ℂ] _)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((State.condTypicalSubspaceProj σ s ε) * (P * ((State.piTensor σ).op * P))) + : _ →ₗ[ℂ] _)) := by + rw [← hassoc] + exact congrArg RCLike.re (ContinuousLinearMap.trace_mul_comm (P * ((State.piTensor σ).op * P)) + (State.condTypicalSubspaceProj σ s ε)) + have hm := ContinuousLinearMap.re_trace_mul_mono_left hPm_le1 hPAP_pos + rw [one_mul] at hm + rw [hcyc] + exact hm.trans (le_of_eq heqPAP) + -- `P_M`-split of `re tr(P σ_M) = re tr(P P_M σ_M) + re tr(P (1 − P_M) σ_M)`. + have hB : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) + = RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) : _ →ₗ[ℂ] _)) + + RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) + : _ →ₗ[ℂ] _)) := by + have hop : P * ((State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) + + P * ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) + = P * (State.piTensor σ).op := by + rw [← mul_add, ← add_mul, + show ((State.condTypicalSubspaceProj σ s ε) + (1 - State.condTypicalSubspaceProj σ s ε)) + = 1 from by abel, one_mul] + rw [← hop, ContinuousLinearMap.toLinearMap_add, map_add, map_add] + -- The `P`-weight of the atypical block is `≤` its full trace. + have hy : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) : _ →ₗ[ℂ] _)) + ≤ RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) := by + have hnn := ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg h1P_nonneg h1PmA_nonneg + have hsplit : ((1 - P) * ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op)) + = (1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op + - P * ((1 - State.condTypicalSubspaceProj σ s ε) * (State.piTensor σ).op) := by + rw [sub_mul, one_mul] + rw [hsplit, ContinuousLinearMap.toLinearMap_sub, map_sub, map_sub] at hnn + linarith + -- `re tr(P σ_M) ≤ re tr σ_M`. + have hx4le5 : RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P * (State.piTensor σ).op) : _ →ₗ[ℂ] _)) + ≤ RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(State.piTensor σ).op : _ →ₗ[ℂ] _)) := by + have hm := ContinuousLinearMap.re_trace_mul_mono_left hP_le1 hA_pos + rwa [one_mul] at hm + -- The two physical terms as trace differences (`re tr((1−X)σ_M) = re tr σ_M − re tr(X σ_M)`). + have hRHS1 := ContinuousLinearMap.re_trace_one_sub_mul P (State.piTensor σ).op + have hRHS2 := ContinuousLinearMap.re_trace_one_sub_mul + (State.condTypicalSubspaceProj σ s ε) (State.piTensor σ).op + rw [e1, e2, hRHS1, hRHS2] + linarith [hC, hCle, hB, hy, hx4le5, hRHS2] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceExpectation.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceExpectation.lean new file mode 100644 index 0000000000..c0748daf4c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceExpectation.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspace +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalTypicalConcentration + +/-! +# AxQM.Postulates.API — the random-coding expectation of the conditional atypical +weight (N&C Eq. 12.76) + +The random-coding *expectation* estimate for the conditional typical subspace `P_M` of Nielsen & +Chuang's proof of the Holevo–Schumacher–Westmoreland theorem (Theorem 12.8, achievability). The +deterministic core — the projector `State.condTypicalSubspaceProj`, its dimension bound (Eq. 12.77), +and the quantum→classical bridge `tr(σ_M (I − P_M)) = 1 − ∑_{κ ∈ T_M} ∏ᵢ λ_{i,κᵢ}` (Eq. 12.76, +`State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor`) — lives in +`Postulates/API/CondTypicalSubspace.lean`. This file supplies the missing *random-coding* half: +averaging that atypical weight over Alice's random codeword. + +Alice's codeword for a message is a length-`n` sequence `M : Fin n → α` of letters drawn i.i.d. from +an input ensemble `p : α → ℝ`; letter `a` maps to the channel output `τ a = E(ρ_a) : State S` +(all outputs on the *same* channel-output system `S`). The codeword output is the product state +`σ_M = ⨂ᵢ τ (Mᵢ)`, and its conditional typical subspace projector is +`State.condTypicalSubspaceProj (fun i ↦ τ (Mᵢ)) s ε`. With the threshold `s = S_bar = ∑ₐ pₐ S(τ_a)` +the ensemble-average output entropy, N&C's Eq. 12.76 bounds the ensemble expectation of the atypical +weight. + +## Main result + +* `State.expectation_re_trace_one_sub_condTypicalSubspaceProj_le` — **N&C Eq. 12.76**: the + `p`-weighted average over codewords `M` of `tr(σ_M (I − P_M))` is at most `V / (n ε²)`, where + `V = ∑ₐ pₐ · ∑_b λ_{a,b} · (−log λ_{a,b} − S_bar)²` (`λ_a = (τ a).eigenvalueDist`) is the + per-letter + spectral-surprisal variance of the ensemble. A *finite-`n`-explicit* bound; as `n → ∞` (with `ε` + fixed) the right side tends to `0`, giving the vanishing atypical weight that the random-coding + error estimate (Eqs. 12.80–12.82) consumes. + +The quantum face of the classical `Real.sum_weighted_one_sub_condTypicalSeq_le`: the per-codeword +bridge `State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor` turns each `tr(σ_M (I − P_M))` +into the classical conditional-atypical weight `1 − ∑_{κ ∈ T_M} ∏ᵢ λ_{Mᵢ,κᵢ}`, on which the +classical random-coding concentration then acts. The threshold identification `S_bar = ∑ₐ pₐ H(λ_a)` +is `State.vonNeumannEntropy_eq_entropy_eigenvalueDist` letterwise. +-/ + +@[expose] public section + +open scoped BigOperators +open Finset + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The random-coding expectation of the conditional atypical weight** (Nielsen & Chuang, +Theorem 12.8, Eq. 12.76). Alice draws a length-`n` codeword `M : Fin n → α` with letters i.i.d. from +the input ensemble `p : α → ℝ`; letter `a` maps to the channel output `τ a : State S`, so the +codeword output is the product state `σ_M = ⨂ᵢ τ (Mᵢ)` with conditional typical subspace projector +`P_M = State.condTypicalSubspaceProj (fun i ↦ τ (Mᵢ)) s ε`. With the threshold `s` equal to the +ensemble-average output entropy `S_bar = ∑ₐ pₐ S(τ_a)`, the `p`-weighted average over codewords of +the +atypical weight `tr(σ_M (I − P_M))` is at most `V / (n ε²)`, where + +`V = ∑ₐ pₐ · ∑_b λ_{a,b} · (−log λ_{a,b} − S_bar)²`, `λ_a = (τ a).eigenvalueDist`, + +is the per-letter spectral-surprisal variance of the ensemble. A *deterministic-in-`ε`*, +finite-`n`-explicit bound: as `n → ∞` (with `ε` fixed) `V / (n ε²) → 0`, so the expected atypical +weight vanishes — the vanishing that the random-coding decoding-error estimate (Eqs. 12.80–12.82) +consumes. + +Proof: the per-codeword bridge +`State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor` rewrites +each `tr(σ_M (I − P_M))` as the classical conditional-atypical weight +`1 − ∑_{κ ∈ T_M} ∏ᵢ λ_{Mᵢ,κᵢ}`; the classical random-coding concentration +`Real.sum_weighted_one_sub_condTypicalSeq_le` then bounds the ensemble average of that weight, the +threshold matching via `State.vonNeumannEntropy_eq_entropy_eigenvalueDist` +(`S_bar = ∑ₐ pₐ H(λ_a)`). -/ +theorem State.expectation_re_trace_one_sub_condTypicalSubspaceProj_le + (τ : α → State S) (p : α → ℝ) (hp0 : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) + {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) + {s : ℝ} (hs : s = ∑ a, p a * (τ a).vonNeumannEntropy) : + ∑ M : Fin n → α, (∏ i, p (M i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor (fun _ : Fin n => S)).space) + (((1 : (QSystem.piTensor (fun _ : Fin n => S)).space →L[ℂ] + (QSystem.piTensor (fun _ : Fin n => S)).space) + - State.condTypicalSubspaceProj (fun i => τ (M i)) s ε).comp + (State.piTensor (fun i => τ (M i))).op : _ →ₗ[ℂ] _)) + ≤ (∑ a, p a * ∑ b, (τ a).eigenvalueDist b * + (- Real.log ((τ a).eigenvalueDist b) - s) ^ 2) / (n * ε ^ 2) := by + -- The threshold `S_bar` is the ensemble-average Shannon entropy of the output spectra. + have hs' : s = ∑ a, p a * Real.entropy (τ a).eigenvalueDist := by + simp_rw [hs, State.vonNeumannEntropy_eq_entropy_eigenvalueDist] + -- Each codeword's atypical weight is the classical conditional-atypical mass (Eq. 12.76 bridge). + simp_rw [State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor] + exact Real.sum_weighted_one_sub_condTypicalSeq_le p hp0 hp1 (fun a => (τ a).eigenvalueDist) + (fun a b => (τ a).eigenvalueDist_nonneg b) (fun a => (τ a).eigenvalueDist_sum_eq_one) hn hε hs' + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceFrame.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceFrame.lean new file mode 100644 index 0000000000..7f219e3f34 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspaceFrame.lean @@ -0,0 +1,155 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspace +public import LeanPool.AxQM.Postulates.API.EntropyMixLine +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamily + +/-! +# AxQM.Postulates.API — codeword-eigenvector frame identities ("calculating the spurs") + +The *frame algebra* underlying Nielsen & Chuang's Box 12.5 "calculating the spurs" +step (eqs. (12.94)→(12.95)) in the random-coding achievability half of the +Holevo–Schumacher–Westmoreland theorem (Theorem 12.8, `χ(E) = C⁽¹⁾(E)`). + +Box 12.5 bounds the pretty-good (square-root) decoding deficit by the abstract Gram-trace +inequality `InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` (N&C eq. (12.94)), +whose right-hand side is a set of *frame sums* `∑ λ‖ψ‖²`, `∑∑ λ|⟪ψ, ψ⟫|²` over the compressed +codeword eigenvectors `ψ = |E_tilde_κ⟩ = A|E_κ⟩`. To recover N&C's physical error terms +`tr(σ_M(I−P))`, +`tr(P σ_M P P_{M'})`, `tr(σ_M(I−P_M))` (eq. (12.95)/(12.79)) those frame sums must be evaluated as +operator traces built from the codeword output `σ_M = ⨂ₚ i, σ i`, its conditional typical subspace +projector `P_M` (`State.condTypicalSubspaceProj`, N&C eq. (12.75)), and the typical projector `P`. +This file provides the three single-family lemmas that perform that evaluation. + +Fix a finite family of output states `σ : (i : ι) → State (S i)` (a codeword's channel-output +factors, `n = |ι|`), with product state `σ_M = ⨂ₚ i, σ i` diagonal in the product eigenbasis +`|E_κ⟩ = State.piTensorEigenbasis σ κ` with eigenvalue `λ_κ = ∏ᵢ λ_{i,κᵢ}` +(`State.piTensor_op_apply_piTensorEigenbasis`), and conditional typical set +`T = Real.condTypicalSeq (fun i ↦ (σ i).eigenvalueDist) s ε` (N&C eq. (12.75)). + +## Main results + +* `State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum` — the **eigendecomposition of the + typical-truncated codeword** `P_M ∘ σ_M = ∑_{κ ∈ T} λ_κ |E_κ⟩⟨E_κ|`: composing the conditional + typical projector with the codeword keeps exactly its typical eigenvalue-weighted rank-one terms. +* `State.re_trace_comp_condTypicalSubspaceProj_comp_piTensor` — the **spur evaluator**: for any + operator `B`, + + `re tr(B ∘ P_M ∘ σ_M) = ∑_{κ ∈ T} λ_κ · re⟪E_κ, B E_κ⟫`, + + the weighted diagonal of `B` over the typical eigenvectors. Its `B = 1` case is the + conditional-typical probability `re tr(P_M ∘ σ_M) = ∑_{κ ∈ T} λ_κ` + (`State.re_trace_condTypicalSubspaceProj_comp_piTensor`, N&C eq. (12.76)); the general form is + what N&C's spur substitution needs, since eq. (12.94) evaluates traces against the typical + projector `P` and the cross-message confusion operators `P P_{M'} P`. +* `State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum` — the **compressed-eigenvector frame + operator** `A ∘ P_M ∘ A⋆ = ∑_{κ ∈ T} |A E_κ⟩⟨A E_κ|`: conjugating `P_M` by an operator `A` yields + the sum of rank-one projectors onto the compressed eigenvectors `A|E_κ⟩`. With `A = P` this is + N&C's `P P_{M'} P = ∑_{κ' ∈ T_{M'}} |E_tilde_{κ'}^{M'}⟩⟨E_tilde_{κ'}^{M'}|`, the frame operator + of the + compressed typical codeword eigenvectors underlying the confusion term `tr(P σ_M P P_{M'})`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +/-- **Eigendecomposition of the typical-truncated codeword** (Nielsen & Chuang, Theorem 12.8, the +object of Box 12.5's spur calculation). Composing the conditional typical subspace projector `P_M` +with the product codeword `σ_M = ⨂ₚ i, σ i` keeps exactly the eigenvalue-weighted rank-one terms of +the *typical* eigenvectors: + +`P_M ∘ σ_M = ∑_{κ ∈ T} λ_κ |E_κ⟩⟨E_κ|`, `λ_κ = ∏ᵢ λ_{i,κᵢ}`, + +where `T = Real.condTypicalSeq (fun i ↦ (σ i).eigenvalueDist) s ε` (N&C eq. (12.75)) and +`|E_κ⟩ = State.piTensorEigenbasis σ κ`. The conditional typical projector is the sum of the typical +rank-one projectors `P_M = ∑_{κ ∈ T} |E_κ⟩⟨E_κ|` (`State.condTypicalSubspaceProj`, +`InnerProductSpace.orthonormalProjector`); composing each `|E_κ⟩⟨E_κ|` on the right with the +self-adjoint `σ_M` (`InnerProductSpace.rankOne_comp`, `State.isSelfAdjoint_op`) contracts the second +slot against `σ_M |E_κ⟩ = λ_κ |E_κ⟩` (`State.piTensor_op_apply_piTensorEigenbasis`), and the real +eigenvalue passes out of the conjugate-linear slot. -/ +theorem State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum (σ : (i : ι) → State (S i)) + (s ε : ℝ) : + (State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op + = ∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + ((∏ i, (σ i).eigenvalueDist (κ i) : ℝ) : ℂ) • + rankOne ℂ (State.piTensorEigenbasis σ κ) (State.piTensorEigenbasis σ κ) := by + rw [State.condTypicalSubspaceProj, InnerProductSpace.orthonormalProjector, + ContinuousLinearMap.finsetSum_comp] + refine Finset.sum_congr rfl fun κ _ => ?_ + rw [InnerProductSpace.rankOne_comp, (State.isSelfAdjoint_op (State.piTensor σ)).adjoint_eq, + State.piTensor_op_apply_piTensorEigenbasis] + ext z + simp only [rankOne_apply, FunLike.coe_smul, Pi.smul_apply, inner_smul_left, + Complex.conj_ofReal, smul_smul] + +/-- **The spur evaluator** (Nielsen & Chuang, Theorem 12.8, the trace-evaluation core of Box 12.5's +eqs. (12.94)→(12.95)). For any operator `B` on the codeword space, the real trace of `B` against +the typical-truncated codeword `P_M ∘ σ_M` is the eigenvalue-weighted diagonal of `B` over the +typical eigenvectors: + +`re tr(B ∘ P_M ∘ σ_M) = ∑_{κ ∈ T} λ_κ · re⟪E_κ, B E_κ⟫`. + +The `B = 1` case recovers the conditional-typical probability +`re tr(P_M ∘ σ_M) = ∑_{κ ∈ T} λ_κ` (`State.re_trace_condTypicalSubspaceProj_comp_piTensor`, N&C +eq. (12.76)). The general form is exactly what N&C's spur substitution (12.94)→(12.95) needs: with +`B = P` (typical projector) it evaluates `∑ λ_κ ‖P E_κ‖²`, and with `B = P P_{M'} P` the +cross-message confusion sums. Proof: `P_M ∘ σ_M` is the eigenvalue-weighted rank-one sum +(`State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum`), against which the trace of `B` splits as +`∑_κ λ_κ ⟪E_κ, B E_κ⟫` (`InnerProductSpace.trace_comp_sum_smul_rankOne_self`); the real eigenvalues +factor out of the real part. -/ +theorem State.re_trace_comp_condTypicalSubspaceProj_comp_piTensor (σ : (i : ι) → State (S i)) + (s ε : ℝ) (B : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) : + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (B.comp ((State.condTypicalSubspaceProj σ s ε).comp (State.piTensor σ).op) : _ →ₗ[ℂ] _)) + = ∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + (∏ i, (σ i).eigenvalueDist (κ i)) * + RCLike.re (inner ℂ (State.piTensorEigenbasis σ κ) + (B (State.piTensorEigenbasis σ κ))) := by + -- The eigenvalue-weighted rank-one sum, traced against `B`, splits termwise by the general + -- `Finset` form of `InnerProductSpace.trace_comp_sum_smul_rankOne_self`; the real eigenvalues + -- then factor out of the real part. + rw [State.condTypicalSubspaceProj_comp_piTensor_op_eq_sum, + InnerProductSpace.trace_comp_sum_smul_rankOne_self, map_sum] + exact Finset.sum_congr rfl fun κ _ => Complex.re_ofReal_mul _ _ + +/-- **The compressed-eigenvector frame operator** (Nielsen & Chuang, Theorem 12.8, Box 12.5). +Conjugating the conditional typical subspace projector `P_M` by an operator `A` yields the sum of +rank-one projectors onto the compressed eigenvectors `A|E_κ⟩`: + +`A ∘ P_M ∘ A⋆ = ∑_{κ ∈ T} |A E_κ⟩⟨A E_κ|`. + +With `A = P` the typical projector, the right-hand side is N&C's frame operator of the +compressed codeword eigenvectors `|E_tilde_κ⟩ = P|E_κ⟩`, so the left-hand side is +`P P_{M'} P = ∑_{κ' ∈ T_{M'}} |E_tilde_{κ'}^{M'}⟩⟨E_tilde_{κ'}^{M'}|`, the operator whose weighted +diagonal is +the confusion term `tr(P σ_M P P_{M'})` of eq. (12.95). Proof: `P_M = ∑_{κ ∈ T} |E_κ⟩⟨E_κ|` +(`State.condTypicalSubspaceProj`, `InnerProductSpace.orthonormalProjector`); conjugation distributes +over the sum, and `A |E_κ⟩⟨E_κ| A⋆ = |A E_κ⟩⟨A E_κ|` termwise +(`ContinuousLinearMap.comp_rankOne_self_comp_adjoint`). -/ +theorem State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum (σ : (i : ι) → State (S i)) (s ε : ℝ) + (A : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) : + A.comp ((State.condTypicalSubspaceProj σ s ε).comp (adjoint A)) + = ∑ κ ∈ Real.condTypicalSeq (fun i => (σ i).eigenvalueDist) s ε, + rankOne ℂ (A (State.piTensorEigenbasis σ κ)) (A (State.piTensorEigenbasis σ κ)) := by + rw [State.condTypicalSubspaceProj, InnerProductSpace.orthonormalProjector, + ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.comp_finsetSum] + refine Finset.sum_congr rfl fun κ _ => ?_ + rw [ContinuousLinearMap.comp_rankOne_self_comp_adjoint] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCode.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCode.lean new file mode 100644 index 0000000000..820d652aeb --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCode.lean @@ -0,0 +1,192 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceDiagonal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamilySigma + +/-! +# The HSW per-code spur instantiation (N&C Thm 12.8, Box 12.5, eqs. (12.94)→(12.95)/(12.79)) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability) the per-code average error of the pretty-good (square-root) decoder is +bounded by the abstract Gram-family estimate of Box 12.5. Its *message-grouped* form +(`InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma`, N&C eq. (12.94)) bounds +the total decoding deficit over the **global** typical index `c = (M, κ)`, `κ ∈ T_M`, + +`2·∑_c λ_c (1 − α_c)`, `α_c = re⟪e_c, √Γ e_c⟫`, `Γ = V⋆·V`, `V = synthesisMap ψ`, +`ψ_{(M,κ)} = P|E^M_κ⟩`, + +by a sum over the message `M` of a **same-message** block (the diagonal `M' = M`) plus a +**cross-message** block (`M' ≠ M`). + +This file performs the "calculating the spurs" substitution (N&C eqs. (12.94)→(12.95)): +instantiating that abstract bound at the concrete codebook family `ψ_{(M,κ)} = P|E^M_κ⟩`, over the +global typical index `Σ_M {κ ∈ T_M}`, and evaluating each block's frame sums as the physical error +traces of the per-code bound eq. (12.79). + +## Main result + +* `AxQM.State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace` — the + **per-code spur bound**. For a length-`n` codebook `σ : Fin K → (i : ι) → State (S i)` of `K` + product codewords `σ_M = ⨂ₚ i, σ M i` and a projection `P` (self-adjoint idempotent — the typical + projector), the total decoding deficit over the global typical index is bounded by the sum over + messages of the three physical error traces of eq. (12.79): + + `2·∑_{(M,κ) : Σ_M T_M} λ^M_κ (1 − α_{(M,κ)})` + ` ≤ ∑_M [ 3·re tr((1 − P) σ_M) + re tr((1 − P_M) σ_M) + ∑_{M'≠M} re tr(P σ_M P P_{M'}) ]`, + + where `T_M = Real.condTypicalSeq (fun i ↦ (σ M i).eigenvalueDist) s ε`, `λ^M_κ = ∏ᵢ λ_{i,κᵢ}`, + `α_{(M,κ)} = re⟪e_{(M,κ)}, √Γ e_{(M,κ)}⟫` is the diagonal of the square root of the Gram operator + `Γ = (synthesisMap ψ)⋆ ∘ synthesisMap ψ` of the global compressed-eigenvector family + `ψ_{(M,κ)} = P (State.piTensorEigenbasis (σ M) κ)`, and `P_{M'} = State.condTypicalSubspaceProj + (σ M') s ε`. + + Combined with the decoder-error → diagonal-α reduction (N&C eqs. (12.84)–(12.88), which identifies + the per-code error `p_av` with `α`), this is the per-code error bound eq. (12.79). + +## Proof + +Instantiate `two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma` at the sigma-indexed family +`ψ_{(M,κ)} = P|E^M_κ⟩` and weight `λ^M_κ = ∏ᵢ λ_{i,κᵢ}` (nonnegative, +`State.eigenvalueDist_nonneg`), the block index `a = M` ranging over `Fin K` and the block +`γ M = {κ // κ ∈ T_M}` the message's +conditional typical set. Its right-hand side is a sum over `M` of one same-message block and the +cross-message blocks; `Finset.sum_coe_sort` rewrites each subtype block sum as a `Finset` sum over +`T_M`, matching exactly the left-hand sides of the two per-message spur bounds: + +* the same-message block is closed by the same-message diagonal spur bound + `State.sum_eigenvalueDist_sameMessageSpur_le_re_trace` + (`≤ 3·re tr((1−P)σ_M) + re tr((1−P_M)σ_M)`); +* each cross-message block (fixed `M' ≠ M`) is closed by the confusion bound + `State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion` + (`≤ re tr(P σ_M P P_{M'})`), summed over `M' ≠ M` by `Finset.sum_le_sum`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.94), (12.95), (12.79). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +-- The functional calculus `cfc Real.sqrt` of the Gram operator on the concrete global typical index +-- `Σ M, {κ ∈ T_M}` drives elaboration-heavy operator-algebra instance synthesis, so both heartbeat +-- budgets are raised. +/-- **The HSW per-code spur bound** (Nielsen & Chuang, Theorem 12.8, Box 12.5, "calculating the +spurs", eqs. (12.94)→(12.95)/(12.79)). For a length-`n` codebook +`σ : Fin K → (i : ι) → State (S i)` of `K` product codewords `σ_M = ⨂ₚ i, σ M i`, and a projection +`P` (self-adjoint idempotent — the +typical projector compressing the codeword eigenvectors to `E_tilde = P|E⟩`), the total decoding +deficit +of the pretty-good decoder over the global typical index is bounded by the sum over messages of the +three physical error traces of the per-code bound eq. (12.79): + +`2·∑_{(M,κ)} λ^M_κ (1 − α_{(M,κ)})` +` ≤ ∑_M [ 3·re tr((1 − P) σ_M) + re tr((1 − P_M) σ_M) + ∑_{M'≠M} re tr(P σ_M P P_{M'}) ]`, + +where the sum on the left ranges over the sigma index `Σ_M {κ ∈ T_M}`, +`T_M = Real.condTypicalSeq (fun i ↦ (σ M i).eigenvalueDist) s ε`, `λ^M_κ = ∏ᵢ λ_{i,κᵢ}`, +`α_{(M,κ)} = re⟪e_{(M,κ)}, √Γ e_{(M,κ)}⟫` is the diagonal of the operator square root of the Gram +operator `Γ = (synthesisMap ψ)⋆ ∘ synthesisMap ψ` of the global compressed-eigenvector family +`ψ_{(M,κ)} = P (State.piTensorEigenbasis (σ M) κ)`, and `P_{M'} = State.condTypicalSubspaceProj +(σ M') s ε`. + +Instantiates the message-grouped Gram-family bound +`InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma` (eq. (12.94)) and evaluates +each block's frame sums as physical traces via the same-message diagonal spur bound +(`State.sum_eigenvalueDist_sameMessageSpur_le_re_trace`) and the cross-message confusion bound +(`State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion`). + +The functional calculus `cfc Real.sqrt` of the Gram operator on the concrete global typical index +`Σ M, {κ ∈ T_M}` drives elaboration-heavy operator-algebra instance synthesis, so both heartbeat +budgets are raised. -/ +theorem State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace + {K : ℕ} (σ : Fin K → (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) : + 2 * ∑ p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}), + (∏ i, (σ p.1 i).eigenvalueDist (p.2.1 i)) * + (1 - RCLike.re (inner ℂ + (EuclideanSpace.basisFun (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) ℂ p) + ((cfc Real.sqrt ((adjoint (synthesisMap + (fun p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + P (State.piTensorEigenbasis (σ p.1) p.2.1)))).comp + (synthesisMap (fun p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + P (State.piTensorEigenbasis (σ p.1) p.2.1))))) + (EuclideanSpace.basisFun (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) ℂ p)))) + ≤ ∑ M : Fin K, (3 * RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((1 - P) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re (LinearMap.trace ℂ (QSystem.piTensor S).space + (↑(P.comp ((State.piTensor (σ M)).op.comp + (P.comp (State.condTypicalSubspaceProj (σ M') s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) := by + classical + refine (InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma + (fun p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + P (State.piTensorEigenbasis (σ p.1) p.2.1)) + (fun p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + ∏ i, (σ p.1 i).eigenvalueDist (p.2.1 i)) + (fun p => Finset.prod_nonneg fun i _ => State.eigenvalueDist_nonneg _ _)).trans ?_ + refine Finset.sum_le_sum fun M _ => ?_ + -- Convert the inner frame sums over the subtype to `Finset` sums over the typical set. + -- The function shape is fixed (only the first argument `v` varies), so `simp` can match it under + -- the outer binders of both the same-message and the cross-message blocks. + have hcoeInner : ∀ (N : Fin K) (v : (QSystem.piTensor S).space), + (∑ κ' : {κ // κ ∈ Real.condTypicalSeq (fun i => (σ N i).eigenvalueDist) s ε}, + ‖inner ℂ v (P (State.piTensorEigenbasis (σ N) κ'.1))‖ ^ 2) + = ∑ κ' ∈ Real.condTypicalSeq (fun i => (σ N i).eigenvalueDist) s ε, + ‖inner ℂ v (P (State.piTensorEigenbasis (σ N) κ'))‖ ^ 2 := + fun N v => Finset.sum_coe_sort _ + (fun κ' => ‖inner ℂ v (P (State.piTensorEigenbasis (σ N) κ'))‖ ^ 2) + simp only [hcoeInner] + refine add_le_add ?_ ?_ + · -- same-message diagonal block: convert the three outer sums, then apply the diagonal bound + rw [Finset.sum_coe_sort (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => ∏ i, (σ M i).eigenvalueDist (κ i)), + Finset.sum_coe_sort (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => (∏ i, (σ M i).eigenvalueDist (κ i)) * + ‖P (State.piTensorEigenbasis (σ M) κ)‖ ^ 2), + Finset.sum_coe_sort (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => (∏ i, (σ M i).eigenvalueDist (κ i)) * + ∑ κ' ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + ‖inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + (P (State.piTensorEigenbasis (σ M) κ'))‖ ^ 2)] + exact State.sum_eigenvalueDist_sameMessageSpur_le_re_trace (σ M) s ε P hPsa hPidem + · -- cross-message confusion blocks: convert the outer sum per pair, apply the confusion bound + refine Finset.sum_le_sum fun M' _ => ?_ + rw [Finset.sum_coe_sort (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => (∏ i, (σ M i).eigenvalueDist (κ i)) * + ∑ κ' ∈ Real.condTypicalSeq (fun i => (σ M' i).eigenvalueDist) s ε, + ‖inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + (P (State.piTensorEigenbasis (σ M') κ'))‖ ^ 2)] + exact State.sum_eigenvalueDist_mul_sum_normSq_inner_proj_le_re_trace_confusion + (σ M) (σ M') s ε P hPsa hPidem + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCodeError.lean b/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCodeError.lean new file mode 100644 index 0000000000..fefd6a2cde --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/CondTypicalSubspacePerCodeError.lean @@ -0,0 +1,337 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceDecoder +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspacePerCode +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GramSquareRoot +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum + +/-! +# The √Γ identification of the pretty-good decoding overlap (N&C Thm 12.8, Box 12.5) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability), the per-message decoder-error bound +(`State.one_sub_re_trace_prettyGood_le`, N&C eq. (12.88)) keeps the pretty-good decoding overlap in +the **physical form** `re⟪E_tilde^M_κ, S^(-1/2) E^M_κ⟫`, where `E_tilde^M_κ = P|E^M_κ⟩` is the +compressed +codeword eigenvector, `E^M_κ = State.piTensorEigenbasis (σ M) κ`, and +`S^(-1/2) = (∑_{M'} P P_{M'} P).genInvSqrt` is the generalized inverse square root of the +pretty-good +total operator. The per-code spur bound +(`State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace`, N&C eq. (12.94)) instead +uses the **Gram form** `re⟪e_{(M,κ)}, √Γ e_{(M,κ)}⟫`, the diagonal of the operator square root of +the Gram operator `Γ = V⋆ V` of the compressed-eigenvector synthesis operator +`V = synthesisMap (fun p ↦ P|E^{p.1}_{p.2.1}⟩)` over the global typical index `Σ_M {κ ∈ T_M}`. + +This file bridges the two: it proves the two overlaps coincide. This is Nielsen & Chuang's +identity `α = Γ^{1/2}` between eqs. (12.85) and (12.86) (Box 12.5), evaluated on the diagonal, in +the concrete random-coding apparatus — the missing link between eq. (12.88) and eq. (12.94) that +lets the per-code average error be bounded by the physical error traces of eq. (12.79). + +## Main result + +* `AxQM.State.re_inner_proj_genInvSqrt_piTensorEigenbasis_eq_re_inner_cfc_sqrt_gram` — the + **√Γ identification of the decoding overlap**. For a codebook + `σ : Fin K → (i : ι) → State (S i)`, a self-adjoint idempotent projector `P`, and an index + `p = (M, κ)` of the global typical index + `Σ_M {κ ∈ T_M}`, + + `re⟪P E^M_κ, S^(-1/2) E^M_κ⟫ = re⟪e_p, √Γ e_p⟫`, + + where `S = ∑_{M'} P (P_{M'}) P` is the pretty-good total operator, + `P_{M'} = State.condTypicalSubspaceProj (σ M') s ε`, `S^(-1/2) = S.genInvSqrt`, + `Γ = V⋆ V`, `V = synthesisMap (fun p ↦ P|E^{p.1}_{p.2.1}⟩)`, and + `e_p = EuclideanSpace.basisFun _ ℂ p`. + +## Proof + +Let `V = synthesisMap ψ` for the global compressed-eigenvector family `ψ_p = P|E^{p.1}_{p.2.1}⟩`. + +* **`S = V V⋆`.** The frame operator identity + `∑_i |ψ_i⟩⟨ψ_i| = V ∘ V⋆` (`sum_rankOne_self_eq_synthesisMap_comp_adjoint`), regrouped over the + sigma index (`Fintype.sum_sigma`, `Finset.sum_coe_sort`), turns the sum of rank-one projectors + into `∑_M ∑_{κ ∈ T_M} |P E^M_κ⟩⟨P E^M_κ| = ∑_M P P_M P = S`, the last step being the + compressed-eigenvector frame identity + `State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum` (with `A = P`, `P⋆ = P`). +* **`P` is absorbed by `S^(-1/2)`.** Since `P P = P`, the total operator `S = ∑_{M'} P P_{M'} P` + satisfies `S P = S` and `P S = S`; as `S^(-1/2)` inherits the support of `S`, + `S^(-1/2) P = S^(-1/2)` (`ContinuousLinearMap.genInvSqrt_mul_of_mul_eq_self`, N&C's `A^(-1/2) P + = A^(-1/2)`). +* **Collapse.** The Gram square-root identity + `V⋆ ∘ S^(-1/2) ∘ V = √Γ` (`ContinuousLinearMap.adjoint_comp_genInvSqrt_comp_self`, using `S = V + V⋆`) + gives `⟪e_p, √Γ e_p⟫ = ⟪e_p, V⋆ (S^(-1/2) (V e_p))⟫ = ⟪V e_p, S^(-1/2) (V e_p)⟫` + (`adjoint_inner_right`); `V e_p = ψ_p = P E^M_κ` (`synthesisMap_basisFun`); and + `S^(-1/2) (P E^M_κ) = S^(-1/2) E^M_κ` by the absorption above. Taking `RCLike.re` of the + resulting + complex equality yields the claim. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.85), (12.86), (12.88), (12.94). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +-- The functional calculus `cfc Real.sqrt` of the Gram operator on the concrete global typical index +-- `Σ M, {κ ∈ T_M}` drives elaboration-heavy operator-algebra instance synthesis, so both heartbeat +-- budgets are raised. +/-- **The √Γ identification of the pretty-good decoding overlap** (Nielsen & Chuang, Theorem 12.8, +Box 12.5, the diagonal of the identity `α = Γ^{1/2}` between eqs. (12.85) and (12.86)). For a +codebook `σ : Fin K → (i : ι) → State (S i)`, a self-adjoint idempotent projector `P`, and an index +`p = (M, κ)` of the global conditional-typical index `Σ_M {κ ∈ T_M}`, the physical decoding overlap +of N&C's per-message error bound eq. (12.88) equals the Gram-square-root diagonal of the per-code +spur bound eq. (12.94): + +`re⟪P E^M_κ, S^(-1/2) E^M_κ⟫ = re⟪e_p, √Γ e_p⟫`, + +where `E^M_κ = State.piTensorEigenbasis (σ M) κ`, `S = ∑_{M'} P (P_{M'}) P` is the pretty-good total +operator, `P_{M'} = State.condTypicalSubspaceProj (σ M') s ε`, `S^(-1/2) = S.genInvSqrt`, and +`√Γ = cfc Real.sqrt (V⋆ V)` is the operator square root of the Gram operator of the compressed +synthesis operator `V = synthesisMap (fun p ↦ P|E^{p.1}_{p.2.1}⟩)` over the sigma index, evaluated +on the standard basis vector `e_p = EuclideanSpace.basisFun _ ℂ p`. + +Chains the frame identity `S = V V⋆` (`sum_rankOne_self_eq_synthesisMap_comp_adjoint` regrouped over +the sigma index, `State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum`), the `P`-absorption +`S^(-1/2) P = S^(-1/2)` (`ContinuousLinearMap.genInvSqrt_mul_of_mul_eq_self`), and the Gram +square-root +identity `V⋆ S^(-1/2) V = √Γ` (`ContinuousLinearMap.adjoint_comp_genInvSqrt_comp_self`). -/ +theorem State.re_inner_proj_genInvSqrt_piTensorEigenbasis_eq_re_inner_cfc_sqrt_gram + {K : ℕ} (σ : Fin K → (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) + (p : Σ M : Fin K, {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) : + RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ p.1) p.2.1)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ p.1) p.2.1))) + = RCLike.re (inner ℂ + (EuclideanSpace.basisFun (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) ℂ p) + ((cfc Real.sqrt ((adjoint (synthesisMap + (fun q : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + P (State.piTensorEigenbasis (σ q.1) q.2.1)))).comp + (synthesisMap (fun q : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) => + P (State.piTensorEigenbasis (σ q.1) q.2.1))))) + (EuclideanSpace.basisFun (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) ℂ p))) := by + classical + -- The global compressed-eigenvector family, its synthesis operator, and the total operator. + set ψ : (Σ M : Fin K, {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}) → + (QSystem.piTensor S).space := + fun q => P (State.piTensorEigenbasis (σ q.1) q.2.1) with hψ + set V := synthesisMap (𝕜 := ℂ) ψ with hV + set Ssum := ∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P) with hS + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hPsa + -- `S = V ∘ V⋆`: the frame operator of the compressed eigenvectors regrouped over the sigma index. + have hSV : Ssum = V.comp (adjoint V) := by + rw [hV, ← sum_rankOne_self_eq_synthesisMap_comp_adjoint ψ, Fintype.sum_sigma, hS] + refine Finset.sum_congr rfl fun M _ => ?_ + simp only [hψ] + rw [Finset.sum_coe_sort (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => rankOne ℂ (P (State.piTensorEigenbasis (σ M) κ)) + (P (State.piTensorEigenbasis (σ M) κ))), + ← State.comp_condTypicalSubspaceProj_comp_adjoint_eq_sum (σ M) s ε P, hPadj] + -- `0 ≤ S`, hence its generalized inverse square root is defined. + have hSnn : 0 ≤ Ssum := by + rw [hSV]; exact nonneg_iff_isPositive.mpr (isPositive_self_comp_adjoint V) + -- `P` fixes `S` on both sides (`P P = P`), so `S^(-1/2)` absorbs `P`. + have hSP : Ssum * P = Ssum := by + rw [hS, ContinuousLinearMap.mul_def, ContinuousLinearMap.finsetSum_comp] + refine Finset.sum_congr rfl fun M' _ => ?_ + rw [ContinuousLinearMap.comp_assoc, ContinuousLinearMap.comp_assoc, hPidem] + have hPS : P * Ssum = Ssum := by + rw [hS, ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_finsetSum] + refine Finset.sum_congr rfl fun M' _ => ?_ + rw [← ContinuousLinearMap.comp_assoc, hPidem] + have habs : Ssum.genInvSqrt * P = Ssum.genInvSqrt := genInvSqrt_mul_of_mul_eq_self hSnn hSP hPS + -- The Gram square-root identity `V⋆ · S^(-1/2) · V = √Γ`, with `V V⋆` replaced by `S`. + have hΓ : cfc Real.sqrt ((adjoint V).comp V) + = (adjoint V).comp (Ssum.genInvSqrt.comp V) := by + have h := adjoint_comp_genInvSqrt_comp_self V + rw [← hSV] at h + exact h.symm + -- Reduce to the complex-valued overlap identity, then assemble it. + congr 1 + rw [hΓ, ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply, + ContinuousLinearMap.adjoint_inner_right, hV, synthesisMap_basisFun] + simp only [hψ] + -- `S^(-1/2) (P E^M_κ) = S^(-1/2) E^M_κ` by the `P`-absorption. + rw [← mul_apply_eq_comp, habs] + +-- The functional calculus `cfc Real.sqrt` of the Gram operator on the concrete global typical index +-- `Σ M, {κ ∈ T_M}` drives elaboration-heavy operator-algebra instance synthesis, so both heartbeat +-- budgets are raised. +/-- **The per-code average-error bound of the pretty-good decoder** (Nielsen & Chuang, Theorem 12.8, +Box 12.5, eq. (12.79)). For a length-`n` codebook `σ : Fin K → (i : ι) → State (S i)` of `K` +product codewords, a self-adjoint idempotent projector `P` (the typical projector), and the +conditional typical projectors `P_{M'} = State.condTypicalSubspaceProj (σ M') s ε`, form N&C's +pretty-good (square-root) decoder `POVM.prettyGood A` of the family `A_{M'} = P P_{M'} P`; its +effect at message `M` is `E_M = S^(-1/2) (P P_M P) S^(-1/2)`, `S = ∑_{M'} A_{M'}`. The **average +decoding +error** `p_bar = (1/K) ∑_M (1 − re tr(σ_M E_M))` is bounded by the three physical error traces of +eq. (12.79), averaged over the codebook: + +`p_bar ≤ (1/K) ∑_M [3·re tr((1−P) σ_M) + 2·re tr((1−P_M) σ_M) + ∑_{M'≠M} re tr(P σ_M P P_{M'})]`. + +Composes the achievability pieces exactly as N&C's Box 12.5 does. Averaging the per-message +bound `State.one_sub_re_trace_prettyGood_le` (eq. (12.88)) over `M`, its typical block splits as +`2 ∑_M ∑_{κ∈T_M} λ^M_κ (1 − α^phys_{(M,κ)})`; the √Γ identification +`State.re_inner_proj_genInvSqrt_piTensorEigenbasis_eq_re_inner_cfc_sqrt_gram` (eqs. (12.85)→(12.86)) +turns each physical overlap `α^phys` into the Gram-square-root diagonal `α^Gram`, and regrouping the +message×typical double sum over the global sigma index `Σ_M {κ ∈ T_M}` (`Fintype.sum_sigma`, +`Finset.sum_coe_sort`) matches the left-hand side of the per-code spur bound +`State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace` (eq. (12.94)), which +supplies the `3·re tr((1−P)σ_M) + re tr((1−P_M)σ_M) + ∑_{M'≠M} re tr(Pσ_MPP_{M'})` bound. The +atypical block `∑_M ∑_{κ∉T_M} λ^M_κ` equals `∑_M re tr((1−P_M) σ_M)` by the conditional-typical mass +bridge `State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor` (eq. (12.76)) together with +the normalisation `State.sum_prod_eigenvalueDist_eq_one` (`∑_κ λ^M_κ = 1`, so +`∑_{κ∉T_M} = 1 − ∑_{κ∈T_M}`), adding a **second** copy of the conditional-atypical trace: hence the +coefficient `2` on `re tr((1−P_M)σ_M)` here, where N&C's eq. (12.79) carries `1`. This overcounting +arises because the same-message spur bound already folds eq. (12.95)'s +`tr(σ_M(1−P)P_M(1−P))` into `3 tr(σ_M(1−P)) + tr(σ_M(1−P_M))`, while eq. (12.88)'s separate atypical +term contributes the extra copy; it is immaterial for the random-coding expectation, where +every term vanishes for `R < χ(E)`. + +The functional calculus `cfc Real.sqrt` of the Gram operator on the concrete global typical index +`Σ M, {κ ∈ T_M}` drives elaboration-heavy operator-algebra instance synthesis, so both heartbeat +budgets are raised. -/ +theorem State.avgError_prettyGood_le_re_trace_percode + {K : ℕ} (σ : Fin K → (i : ι) → State (S i)) (s ε : ℝ) + (P : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) + (hA : ∀ M', (0 : (QSystem.piTensor S).space →L[ℂ] (QSystem.piTensor S).space) + ≤ P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)) : + (K : ℝ)⁻¹ * ∑ M : Fin K, (1 - RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((State.piTensor (σ M)).op.comp + ((POVM.prettyGood (fun M' => P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)) + hA).elements (some M))) : (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) + ≤ (K : ℝ)⁻¹ * ∑ M : Fin K, + (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - P) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + 2 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑(P.comp ((State.piTensor (σ M)).op.comp + (P.comp (State.condTypicalSubspaceProj (σ M') s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) := by + classical + refine mul_le_mul_of_nonneg_left ?_ (by positivity) + -- Regrouping any message×typical double sum over the global sigma index `Σ_M {κ ∈ T_M}`. + have hregroup : ∀ g : (M : Fin K) → ((i : ι) → Fin (Module.finrank ℂ (S i).space)) → ℝ, + (∑ p : (Σ M : Fin K, + {κ // κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε}), g p.1 p.2.1) + = ∑ M : Fin K, ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, g M κ := by + intro g + rw [Fintype.sum_sigma] + exact Finset.sum_congr rfl fun M _ => Finset.sum_coe_sort _ fun κ => g M κ + -- The typical block: average, rewrite `α^phys → α^Gram`, regroup, then apply the per-code spur + -- bound (eq. (12.94)). + have hSPUR_le : (∑ M : Fin K, 2 * ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + (∏ i, (σ M i).eigenvalueDist (κ i)) * + (1 - RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ M) κ))))) + ≤ ∑ M : Fin K, (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - P) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑(P.comp ((State.piTensor (σ M)).op.comp + (P.comp (State.condTypicalSubspaceProj (σ M') s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) := by + refine le_trans (le_of_eq ?_) + (State.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_codebook_le_re_trace σ s ε P hPsa hPidem) + rw [← Finset.mul_sum] + congr 1 + rw [← hregroup fun M κ => (∏ i, (σ M i).eigenvalueDist (κ i)) * + (1 - RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ M) κ))))] + refine Finset.sum_congr rfl fun p _ => ?_ + rw [State.re_inner_proj_genInvSqrt_piTensorEigenbasis_eq_re_inner_cfc_sqrt_gram + σ s ε P hPsa hPidem p] + -- The atypical block equals the conditional-atypical error trace `∑_M re tr((1−P_M)σ_M)`. + have hATYP : (∑ M : Fin K, ∑ κ ∈ (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε)ᶜ, + ∏ i, (σ M i).eigenvalueDist (κ i)) + = ∑ M : Fin K, RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) := by + refine Finset.sum_congr rfl fun M _ => ?_ + have hnorm := State.sum_prod_eigenvalueDist_eq_one (σ M) + have hcompl := Finset.sum_add_sum_compl + (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε) + (fun κ => ∏ i, (σ M i).eigenvalueDist (κ i)) + rw [hnorm] at hcompl + rw [ContinuousLinearMap.mul_def, + State.re_trace_one_sub_condTypicalSubspaceProj_comp_piTensor (σ M) s ε] + linarith [hcompl] + -- Assemble: per-message bound (eq. (12.88)), split, then close both blocks. + calc ∑ M : Fin K, (1 - RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((State.piTensor (σ M)).op.comp + ((POVM.prettyGood (fun M' => P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)) + hA).elements (some M))) : (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) + ≤ ∑ M : Fin K, (2 * ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + (∏ i, (σ M i).eigenvalueDist (κ i)) * + (1 - RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ M) κ)))) + + ∑ κ ∈ (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε)ᶜ, + ∏ i, (σ M i).eigenvalueDist (κ i)) := + Finset.sum_le_sum fun M _ => State.one_sub_re_trace_prettyGood_le σ s ε P hPsa hA M + _ = (∑ M : Fin K, 2 * ∑ κ ∈ Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε, + (∏ i, (σ M i).eigenvalueDist (κ i)) * + (1 - RCLike.re (inner ℂ (P (State.piTensorEigenbasis (σ M) κ)) + ((∑ M', P.comp ((State.condTypicalSubspaceProj (σ M') s ε).comp P)).genInvSqrt + (State.piTensorEigenbasis (σ M) κ))))) + + ∑ M : Fin K, ∑ κ ∈ (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε)ᶜ, + ∏ i, (σ M i).eigenvalueDist (κ i) := Finset.sum_add_distrib + _ ≤ (∑ M : Fin K, (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - P) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑(P.comp ((State.piTensor (σ M)).op.comp + (P.comp (State.condTypicalSubspaceProj (σ M') s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)))) + + ∑ M : Fin K, ∑ κ ∈ (Real.condTypicalSeq (fun i => (σ M i).eigenvalueDist) s ε)ᶜ, + ∏ i, (σ M i).eigenvalueDist (κ i) := add_le_add hSPUR_le le_rfl + _ = ∑ M : Fin K, + (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - P) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + 2 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑((1 - State.condTypicalSubspaceProj (σ M) s ε) * (State.piTensor (σ M)).op) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space)) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor S).space) + (↑(P.comp ((State.piTensor (σ M)).op.comp + (P.comp (State.condTypicalSubspaceProj (σ M') s ε)))) : + (QSystem.piTensor S).space →ₗ[ℂ] (QSystem.piTensor S).space))) := by + rw [hATYP, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun M _ => by ring + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ConditionalEntropyConcave.lean b/LeanPool/AxQM/Postulates/API/ConditionalEntropyConcave.lean new file mode 100644 index 0000000000..5c2fdca0d5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ConditionalEntropyConcave.lean @@ -0,0 +1,212 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RelativeEntropy +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumConditionalEntropy + +/-! +# AxQM — concavity of the quantum conditional entropy (N&C Corollary 11.13) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, **Corollary 11.13**: for a +composite system `A ⊗ B`, the quantum conditional entropy + +`S(A|B) = S(A,B) − S(B)` + +is **concave** in the state `ρ` of `A ⊗ B`. Averaging a family of states cannot decrease the +conditional entropy below the average of the conditional entropies: + +`∑ᵢ pᵢ S(A|B)(ρᵢ) ≤ S(A|B)(∑ᵢ pᵢ ρᵢ)`. + +## Proof (following N&C) + +Let `d = dim A`. The reduced-state identity (grounded in the lemma +`ContinuousLinearMap.quantumRelativeEntropy_mapL_maximallyMixed_left_eq`) + +`S(A|B)(ρ) = log d − D(ρ ‖ (I/d) ⊗ ρ_B)`, `ρ_B = Tr_A ρ = ρ.reducedRight`, + +expresses the conditional entropy as an **affine** image of the relative entropy against +`(I/d) ⊗ ρ_B`: the maximally mixed factor `I/d` is constant, and `ρ_B` is linear in `ρ`, so the +whole second argument is affine in `ρ`. The **joint convexity** of the relative entropy (N&C +Theorem 11.12, `State.quantumRelativeEntropy_jointly_convex_sum`) therefore transfers to concavity: +for the mixture `μ = ∑ᵢ pᵢ ρᵢ`, with `μ_B = ∑ᵢ pᵢ (ρᵢ)_B` and `(I/d) ⊗ μ_B = ∑ᵢ pᵢ (I/d) ⊗ (ρᵢ)_B`, + +`D(μ ‖ (I/d) ⊗ μ_B) ≤ ∑ᵢ pᵢ D(ρᵢ ‖ (I/d) ⊗ (ρᵢ)_B)`, + +and subtracting from `log d` (which `∑ᵢ pᵢ = 1` distributes) gives the concavity inequality. + +The conditional entropies are written out as their defining differences +`S(·) − S(·.reducedRight)`, as in the conditional strong-subadditivity theorem +`State.condEntropy_add_le_add` (N&C Problem 11.4). + +## Faithfulness + +As with Klein's inequality, joint convexity, and strong subadditivity, the finite real-valued +relative-entropy engine requires the states to be **faithful** (strictly positive spectrum). The +mixture `∑ᵢ pᵢ ρᵢ` of faithful states is again faithful (`State.isStrictlyPositive_mix_op`, via the +convexity of the strictly-positive cone), so both sides apply on the faithful branch. +The fully general (possibly rank-deficient) statement follows by the same continuity argument over +faithful approximants, which is not carried out here. + +## Main results + +* `AxQM.State.quantumRelativeEntropy_maximallyMixed_tmul_reducedRight_eq` — the identity + `D(ρ ‖ (I/d) ⊗ ρ_B) = log d + S(ρ_B) − S(ρ)`. +* `AxQM.State.vonNeumannEntropy_sub_reducedRight_concave` — Corollary 11.13, concavity of + `S(A|B) = S(ρ) − S(ρ.reducedRight)`. +* `AxQM.State.isStrictlyPositive_mix_op`, `AxQM.State.mix_reducedRight_op` — + supporting facts about probabilistic mixtures. +-/ + +@[expose] public section + +open Module +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **A probabilistic mixture of faithful states is faithful**: if every `ρ i` has strictly positive +density operator, so does the mixture `∑ᵢ pᵢ ρᵢ`. The strictly-positive operators form a convex cone +(`convex_isStrictlyPositive`), and the mixture is a convex combination of the `(ρ i).op`. -/ +theorem State.isStrictlyPositive_mix_op {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (hpos : ∀ i, IsStrictlyPositive (ρ i).op) : + IsStrictlyPositive (State.mix p hp hsum ρ).op := by + simp only [State.mix_op, Complex.coe_smul] + exact (Convex.sum_mem convex_isStrictlyPositive (fun i _ => hp i) hsum (fun i _ => hpos i) : + (∑ i, p i • (ρ i).op) ∈ {a : S.space →L[ℂ] S.space | IsStrictlyPositive a}) + +/-- **The right-reduced state of a mixture is the mixture of the right-reduced states**: +`Tr_A (∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ (Tr_A ρᵢ)`, at the level of density operators. The partial trace is linear +(`LinearMap.partialTraceLeft_sum_smul`), so it commutes with the convex combination defining +`State.mix`. -/ +theorem State.mix_reducedRight_op {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State (S ⊗ T)) : + (State.mix p hp hsum ρ).reducedRight.op = ∑ i, (p i : ℂ) • (ρ i).reducedRight.op := by + rw [State.reducedRight_op, State.mix_op] + simp only [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul, + State.reducedRight_op] + simp only [← map_smul, ← map_sum] + congr 1 + exact LinearMap.partialTraceLeft_sum_smul (stdOrthonormalBasis ℂ S.space) + (fun i => (p i : ℂ)) (fun i => (ρ i).op.toLinearMap) + +/-- **The left-reduced state of a mixture is the mixture of the left-reduced states**: +`Tr_B (∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ (Tr_B ρᵢ)`, at the level of density operators. The `reducedLeft` +companion of `State.mix_reducedRight_op`: the partial trace is linear +(`LinearMap.partialTraceRight_sum_smul`), so it commutes with the convex combination defining +`State.mix`. -/ +theorem State.mix_reducedLeft_op {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State (S ⊗ T)) : + (State.mix p hp hsum ρ).reducedLeft.op = ∑ i, (p i : ℂ) • (ρ i).reducedLeft.op := by + rw [State.reducedLeft_op, State.mix_op] + simp only [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul, + State.reducedLeft_op] + simp only [← map_smul, ← map_sum] + congr 1 + exact LinearMap.partialTraceRight_sum_smul (stdOrthonormalBasis ℂ T.space) + (fun i => (p i : ℂ)) (fun i => (ρ i).op.toLinearMap) + +/-- **The conditional entropy as a relative entropy against `(I/d) ⊗ ρ_B`** (the state-level lift of +`ContinuousLinearMap.quantumRelativeEntropy_mapL_maximallyMixed_left_eq`): for a faithful state `ρ` +on `S ⊗ T` (with `d = dim S`), + +`D(ρ ‖ (I/d) ⊗ ρ_B) = log d + S(ρ_B) − S(ρ)`, `ρ_B = ρ.reducedRight`, + +where `I/d = maximallyMixedState S`. Equivalently `S(ρ) − S(ρ_B) = log d − D(ρ ‖ (I/d) ⊗ ρ_B)`: the +conditional entropy `S(A|B)` is `log d` minus a relative entropy, the identity behind the concavity +of `S(A|B)` (N&C Corollary 11.13). -/ +theorem State.quantumRelativeEntropy_maximallyMixed_tmul_reducedRight_eq [Nontrivial S.space] + (ρ : State (S ⊗ T)) (hρ : IsStrictlyPositive ρ.op) : + ρ.quantumRelativeEntropy ((maximallyMixedState S).tmul ρ.reducedRight) + = Real.log (Module.finrank ℂ S.space) + ρ.reducedRight.vonNeumannEntropy + - ρ.vonNeumannEntropy := by + have : Nonempty (Fin (Module.finrank ℂ S.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + rw [State.quantumRelativeEntropy_def, State.tmul_op, maximallyMixedState_op, + State.vonNeumannEntropy_def, State.vonNeumannEntropy_def] + exact ContinuousLinearMap.quantumRelativeEntropy_mapL_maximallyMixed_left_eq + (stdOrthonormalBasis ℂ S.space) ρ.isDensity hρ rfl + +/-- **Concavity of the quantum conditional entropy** (Nielsen & Chuang, Corollary 11.13): for a +probability distribution `p` and a family `ρ : ι → State (S ⊗ T)` of **faithful** states, the +conditional entropy `S(A|B) = S(ρ) − S(ρ.reducedRight)` is concave — + +`∑ᵢ pᵢ (S(ρᵢ) − S((ρᵢ)_B)) ≤ S(μ) − S(μ_B)`, `μ = ∑ᵢ pᵢ ρᵢ = State.mix p hp hsum ρ`. + +The conditional entropy is written out as `S(·) − S(·.reducedRight)` (see the module docstring). +The proof rewrites each conditional entropy via +`State.quantumRelativeEntropy_maximallyMixed_tmul_reducedRight_eq` as `log d − D(· ‖ (I/d) ⊗ ·_B)` +and applies the joint convexity of the relative entropy +(`State.quantumRelativeEntropy_jointly_convex_sum`); the `log d` terms cancel via `∑ᵢ pᵢ = 1`. +Faithfulness of the mixture is `State.isStrictlyPositive_mix_op`, and the affine dependence of the +second argument on `ρ` is threaded by `State.mix_reducedRight_op` and +`TensorProduct.mapL_sum_smul_right`. -/ +theorem State.vonNeumannEntropy_sub_reducedRight_concave [Nontrivial S.space] + {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ρ : ι → State (S ⊗ T)) (hpos : ∀ i, IsStrictlyPositive (ρ i).op) : + ∑ i, p i * ((ρ i).vonNeumannEntropy - (ρ i).reducedRight.vonNeumannEntropy) ≤ + (State.mix p hp hsum ρ).vonNeumannEntropy + - (State.mix p hp hsum ρ).reducedRight.vonNeumannEntropy := by + classical + have : Nonempty (Fin (Module.finrank ℂ S.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + -- The mixture and each product state are faithful. + have hμpos : IsStrictlyPositive (State.mix p hp hsum ρ).op := + State.isStrictlyPositive_mix_op p hp hsum ρ hpos + have hσpos : ∀ i, IsStrictlyPositive ((maximallyMixedState S).tmul (ρ i).reducedRight).op := by + intro i + rw [State.tmul_op, maximallyMixedState_op] + exact TensorProduct.mapL_isStrictlyPositive + ContinuousLinearMap.isStrictlyPositive_finrank_inv_smul_one + ((hpos i).of_partialTraceLeft_eq (stdOrthonormalBasis ℂ S.space) rfl) + -- The two convex-combination hypotheses feeding joint convexity. + have hρeq : (State.mix p hp hsum ρ).op = ∑ i, p i • (ρ i).op := by + simp only [State.mix_op, Complex.coe_smul] + have hσeq : ((maximallyMixedState S).tmul (State.mix p hp hsum ρ).reducedRight).op + = ∑ i, p i • ((maximallyMixedState S).tmul (ρ i).reducedRight).op := by + have hpt := TensorProduct.mapL_sum_smul_right (maximallyMixedState S).op + (fun i => (p i : ℂ)) (fun i => (ρ i).reducedRight.op) + rw [State.tmul_op, State.mix_reducedRight_op, hpt] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [State.tmul_op]; exact Complex.coe_smul (p i) _ + -- Joint convexity of the relative entropy against `(I/d) ⊗ ·`. + have hjc := State.quantumRelativeEntropy_jointly_convex_sum (Finset.univ : Finset ι) + (State.mix p hp hsum ρ) + ((maximallyMixedState S).tmul (State.mix p hp hsum ρ).reducedRight) + ρ (fun i => (maximallyMixedState S).tmul (ρ i).reducedRight) p + (fun i _ => hpos i) (fun i _ => hσpos i) (fun i _ => hp i) hsum hρeq hσeq + -- Rewrite every relative entropy via the conditional-entropy identity. + rw [State.quantumRelativeEntropy_maximallyMixed_tmul_reducedRight_eq _ hμpos] at hjc + have hidi : ∀ i, (ρ i).quantumRelativeEntropy ((maximallyMixedState S).tmul (ρ i).reducedRight) + = Real.log (Module.finrank ℂ S.space) + (ρ i).reducedRight.vonNeumannEntropy + - (ρ i).vonNeumannEntropy := fun i => + State.quantumRelativeEntropy_maximallyMixed_tmul_reducedRight_eq (ρ i) (hpos i) + simp only [hidi] at hjc + -- Distribute the `log d` term through the average (`∑ᵢ pᵢ = 1`). + have hexp : ∑ i, p i * (Real.log (Module.finrank ℂ S.space) + + (ρ i).reducedRight.vonNeumannEntropy - (ρ i).vonNeumannEntropy) + = Real.log (Module.finrank ℂ S.space) + + ∑ i, p i * ((ρ i).reducedRight.vonNeumannEntropy - (ρ i).vonNeumannEntropy) := by + simp only [mul_add, mul_sub, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.sum_mul, hsum, one_mul] + ring + rw [hexp] at hjc + -- The goal's average is the negation of the average appearing in `hjc`. + have hrel : ∑ i, p i * ((ρ i).vonNeumannEntropy - (ρ i).reducedRight.vonNeumannEntropy) + + ∑ i, p i * ((ρ i).reducedRight.vonNeumannEntropy - (ρ i).vonNeumannEntropy) = 0 := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_eq_zero fun i _ => by ring + linarith + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ContinuousSearchHamiltonian.lean b/LeanPool/AxQM/Postulates/API/ContinuousSearchHamiltonian.lean new file mode 100644 index 0000000000..2be5799fbe --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ContinuousSearchHamiltonian.lean @@ -0,0 +1,257 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ProjectorHamiltonian +public import LeanPool.AxQM.Postulates.API.PureState +public import TauCeti.Analysis.Normed.Operator.Exponential +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle + +/-! +# AxQM.Postulates.API — the continuous-time search Hamiltonian + +The Hamiltonian behind Nielsen & Chuang's **quantum-search-as-simulation** +picture (§6.2, and the multiple-solution generalisation of Exercise 6.11): the two-projector +Hamiltonian + +`H = |a⟩⟨a| + |ψ⟩⟨ψ|` (N&C eq. 6.18, `|a⟩` the target and `|ψ⟩` the starting state) + +and the explicit continuous-time evolution it generates. This is the *abstract* engine — a pair of +pure states `a`, `ψ` with a **real overlap** `⟨a, ψ⟩ = α` — that both the single-solution search +of §6.2 (`a = |x⟩`, `α = 1/√N`) and the multiple-solution search of Exercise 6.11 +(`a = |β⟩`, the uniform superposition over the `M` solutions, `α = √(M/N)`) instantiate. + +## The mathematics (N&C eqs. 6.20–6.23) + +Working with the real overlap `α = ⟨a, ψ⟩`, the vectors `a ± ψ` are eigenvectors of `H`: + +`H (a + ψ) = (1 + α)(a + ψ)`, `H (a - ψ) = (1 - α)(a - ψ)` + +(the reality of `α` is exactly what makes `a ± ψ` eigenvectors). Since the propagator acts on an +eigenvector by a global phase (`Observable.propagator_op_apply_of_apply_eq_smul`), decomposing +`ψ = ½(a + ψ) - ½(a - ψ)` and re-collecting gives N&C eq. 6.23: + +`exp(-i H t) |ψ⟩ = e^{-it} (cos(α t) |ψ⟩ - i sin(α t) |a⟩)`. + +At `t = π/(2α)` this is `-i e^{-it} |a⟩`, i.e. the target `|a⟩` up to a global phase: the evolution +has rotated `|ψ⟩` exactly onto `|a⟩`, solving the search problem. + +## What is formalised + +* `Observable.propagator_op_apply_of_apply_eq_smul` — **energy eigenstate → phase**: if + `H |v⟩ = μ |v⟩` then `exp(-iHt) |v⟩ = e^{-iμt} |v⟩`. A reusable fact about the propagator + (built on the lemma `ContinuousLinearMap.exp_apply_of_apply_eq_smul`). +* `Observable.propagator_op_apply_of_two_state_eigen` / `evolvePure_toState_of_two_state_eigen` — + the **operator-agnostic two-state rotation**: for *any* `H` with `H(a ± ψ) = (c ± d)(a ± ψ)`, + `exp(-iHt)|ψ⟩ = e^{-ict}(cos(dt)|ψ⟩ - i sin(dt)|a⟩)`, reaching `|a⟩` (up to a global phase) at + `t = π/(2d)` (for `d ≠ 0`). This is the shared core both this search Hamiltonian (`c=1, d=α`) and + the Exercise 6.12 coupling Hamiltonian (`c=α, d=1`, in `Postulates/API/CouplingHamiltonian.lean`) + instantiate — the `_propagator_op_apply` / `_reaches_target` below are one-line derivations of it. +* `PureState.searchHamiltonian a ψ` — the Hamiltonian `|a⟩⟨a| + |ψ⟩⟨ψ|` as an `Observable` + (self-adjoint as a sum of two projector observables). +* `PureState.searchHamiltonian_apply_add` / `_apply_sub` — the eigenvector equations for `a ± ψ`. +* `PureState.searchHamiltonian_propagator_op_apply` — **N&C eq. 6.23**, the closed form of the + evolved state `exp(-iHt) |ψ⟩`. +* `PureState.searchHamiltonian_reaches_target` — at `t = π/(2α)` (for `α > 0`) the evolved state + equals the target `|a⟩` up to a global phase, + `((H.propagator 1 0 (π/(2α))).evolvePure ψ).toState = a.toState`: the search problem is solved. + +These definitions are used in [upstream `AxQM/NC/Ch6/Exercise6_11.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch6/Exercise6_11.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **An energy eigenstate evolves by a global phase.** If `v` is an eigenvector of the Hamiltonian +`H` with (necessarily real, but here allowed complex) eigenvalue `μ` — `H.op v = μ • v` — then the +propagator acts on it by the scalar phase `e^{-iμt}`: `(H.propagator 1 0 t).op v = e^{-iμt} • v`. +The proof rewrites the propagator as `exp(t • -i • H.op)` (`Observable.propagator_op`), computes +`(t • -i • H.op) v = (-i μ t) • v`, and applies the lemma +`ContinuousLinearMap.exp_apply_of_apply_eq_smul`. -/ +theorem Observable.propagator_op_apply_of_apply_eq_smul (H : Observable S) {v : S.space} {μ : ℂ} + (t : ℝ) (h : H.op v = μ • v) : + (H.propagator 1 0 t).op v = Complex.exp (-(Complex.I * (μ * (t : ℂ)))) • v := by + rw [Observable.propagator_op] + rw [Complex.exp_eq_exp_ℂ] + refine ContinuousLinearMap.exp_apply_of_apply_eq_smul _ ?_ + rw [smul_apply, h, smul_smul]; push_cast; ring_nf + +/-- **Two-state rotation — the propagator of any Hamiltonian whose `a ± ψ` are eigenvectors.** If a +Hamiltonian `H` has `H (a + ψ) = (c + d)(a + ψ)` and `H (a − ψ) = (c − d)(a − ψ)` — i.e. `a ± ψ` +are eigenvectors with eigenvalues `c ± d` — then it rotates the start `ψ` as + +`exp(−i H t) |ψ⟩ = e^{−ict} (cos(dt) · |ψ⟩ − i sin(dt) · |a⟩)`. + +This is the **operator-agnostic core** of the continuous-time search evolutions, shared by every +Hamiltonian of the `c ± d` eigenvalue shape: the §6.2 projector Hamiltonian `|a⟩⟨a| + |ψ⟩⟨ψ|` has +`(c, d) = (1, α)` (`searchHamiltonian_propagator_op_apply`), and the off-diagonal coupling +`|a⟩⟨ψ| + |ψ⟩⟨a|` of Exercise 6.12 has `(c, d) = (α, 1)` (`couplingHamiltonian_propagator_op_apply`) +— the same closed form, differing only in which of `1`, `α` is the phase rate `c` and which is the +rotation rate `d`. The proof decomposes `ψ = ½(a + ψ) − ½(a − ψ)`, evolves each eigenvector by its +phase (`propagator_op_apply_of_apply_eq_smul`, eigenvalues `c ± d`), and re-collects the `a` and `ψ` +components using `e^{−i(c±d)t} = e^{−ict} e^{∓idt}` and Euler's formula. -/ +theorem Observable.propagator_op_apply_of_two_state_eigen (H : Observable S) (a ψ : PureState S) + {c d : ℝ} (t : ℝ) + (hadd : H.op (a.vec + ψ.vec) = ((c + d : ℝ) : ℂ) • (a.vec + ψ.vec)) + (hsub : H.op (a.vec - ψ.vec) = ((c - d : ℝ) : ℂ) • (a.vec - ψ.vec)) : + (H.propagator 1 0 t).op ψ.vec + = Complex.exp (-(Complex.I * ((c * t : ℝ) : ℂ))) + • ((Real.cos (d * t) : ℂ) • ψ.vec - (Complex.I * (Real.sin (d * t) : ℂ)) • a.vec) := by + have ep := H.propagator_op_apply_of_apply_eq_smul t hadd + have em := H.propagator_op_apply_of_apply_eq_smul t hsub + have hψ : ψ.vec = (1 / 2 : ℂ) • (a.vec + ψ.vec) - (1 / 2 : ℂ) • (a.vec - ψ.vec) := by module + -- split each eigenvalue phase `e^{-i(c±d)t}` as `e^{-ict}·e^{∓idt}` (shared by `hcP`/`hcA`) + have e1 : -(Complex.I * (((c + d : ℝ) : ℂ) * (t : ℂ))) + = -(Complex.I * ((c * t : ℝ) : ℂ)) + (-((d * t : ℝ) : ℂ)) * Complex.I := by push_cast; ring + have e2 : -(Complex.I * (((c - d : ℝ) : ℂ) * (t : ℂ))) + = -(Complex.I * ((c * t : ℝ) : ℂ)) + (((d * t : ℝ) : ℂ)) * Complex.I := by push_cast; ring + have hcP : (1 / 2 : ℂ) * Complex.exp (-(Complex.I * (((c + d : ℝ) : ℂ) * (t : ℂ)))) + + (1 / 2) * Complex.exp (-(Complex.I * (((c - d : ℝ) : ℂ) * (t : ℂ)))) + = Complex.exp (-(Complex.I * ((c * t : ℝ) : ℂ))) * (Real.cos (d * t) : ℂ) := by + rw [e1, e2, Complex.exp_add, Complex.exp_add, Complex.exp_mul_I, Complex.exp_mul_I, + Complex.cos_neg, Complex.sin_neg, Complex.ofReal_cos]; ring + have hcA : (1 / 2 : ℂ) * Complex.exp (-(Complex.I * (((c + d : ℝ) : ℂ) * (t : ℂ)))) + - (1 / 2) * Complex.exp (-(Complex.I * (((c - d : ℝ) : ℂ) * (t : ℂ)))) + = -(Complex.exp (-(Complex.I * ((c * t : ℝ) : ℂ))) + * (Complex.I * (Real.sin (d * t) : ℂ))) := by + rw [e1, e2, Complex.exp_add, Complex.exp_add, Complex.exp_mul_I, Complex.exp_mul_I, + Complex.cos_neg, Complex.sin_neg, Complex.ofReal_sin]; ring + conv_lhs => rw [hψ] + rw [map_sub, map_smul, map_smul, ep, em] + match_scalars + · linear_combination (norm := (push_cast; ring1)) hcA + · linear_combination (norm := (push_cast; ring1)) hcP + +/-- **Two-state rotation reaches the target at `t = π/(2d)`.** Under the hypotheses of +`propagator_op_apply_of_two_state_eigen` (so `a ± ψ` are eigenvectors with eigenvalues `c ± d`) +together with `d ≠ 0`, evolving `ψ` for time `t = π/(2d)` produces the target `a` up to a global +phase — the density operators coincide, +`((H.propagator 1 0 (π/(2d))).evolvePure ψ).toState = a.toState`. At `t = π/(2d)` we have +`d t = π/2`, so `cos(d t) = 0`, `sin(d t) = 1` and the evolved vector is `−i e^{−icπ/(2d)} |a⟩`, a +unit-modulus phase times `|a⟩`; a global phase is invisible to the state +(`toState_eq_of_vec_eq_smul`). The observation time is set by the rotation rate `d` alone (the phase +rate `c` only feeds the invisible global phase) — for the projector search `(c, d) = (1, α)` this is +`t = π/(2α) = O(√N)`, whereas for the coupling Hamiltonian `(c, d) = (α, 1)` it is +`t = π/2 = O(1)`. -/ +theorem Observable.evolvePure_toState_of_two_state_eigen (H : Observable S) (a ψ : PureState S) + {c d : ℝ} (hd : d ≠ 0) + (hadd : H.op (a.vec + ψ.vec) = ((c + d : ℝ) : ℂ) • (a.vec + ψ.vec)) + (hsub : H.op (a.vec - ψ.vec) = ((c - d : ℝ) : ℂ) • (a.vec - ψ.vec)) : + ((H.propagator 1 0 (Real.pi / (2 * d))).evolvePure ψ).toState = a.toState := by + have hdt : d * (Real.pi / (2 * d)) = Real.pi / 2 := by field_simp + have hvec : (H.propagator 1 0 (Real.pi / (2 * d))).op ψ.vec + = (-(Complex.exp (-(Complex.I * ((c * (Real.pi / (2 * d)) : ℝ) : ℂ))) * Complex.I)) + • a.vec := by + rw [H.propagator_op_apply_of_two_state_eigen a ψ _ hadd hsub, hdt] + simp only [Real.cos_pi_div_two, Real.sin_pi_div_two, Complex.ofReal_zero, Complex.ofReal_one, + zero_smul, zero_sub, mul_one, smul_neg, smul_smul, neg_smul] + refine PureState.toState_eq_of_vec_eq_smul + (c := -(Complex.exp (-(Complex.I * ((c * (Real.pi / (2 * d)) : ℝ) : ℂ))) * Complex.I)) ?_ ?_ + · rw [norm_neg, norm_mul, Complex.norm_I, mul_one, Complex.norm_exp] + have hre : (-(Complex.I * ((c * (Real.pi / (2 * d)) : ℝ) : ℂ))).re = 0 := by + simp only [Complex.neg_re, Complex.mul_re, Complex.I_re, Complex.I_im, Complex.ofReal_re, + Complex.ofReal_im, zero_mul, mul_zero, sub_zero, neg_zero] + rw [hre, Real.exp_zero] + · rw [Evolution.evolvePure_vec]; exact hvec + +/-- **The continuous-time search Hamiltonian** `H = |a⟩⟨a| + |ψ⟩⟨ψ|` (Nielsen & Chuang eq. 6.18) +of a target pure state `a` and a starting pure state `ψ`, as an `Observable`. It is the sum of the +two projector Hamiltonians `a.projObservable` and `ψ.projObservable`, hence self-adjoint. Evolving +`ψ` under `H` rotates it towards `a` (`searchHamiltonian_propagator_op_apply`); this is the +Hamiltonian whose simulation reproduces the quantum search algorithm. -/ +def PureState.searchHamiltonian (a ψ : PureState S) : Observable S where + op := a.projObservable.op + ψ.projObservable.op + selfAdjoint := a.projObservable.selfAdjoint.add ψ.projObservable.selfAdjoint + +/-- The action of the search Hamiltonian `H = |a⟩⟨a| + |ψ⟩⟨ψ|` on a vector `v`: +`H v = ⟨a, v⟩ |a⟩ + ⟨ψ, v⟩ |ψ⟩`. -/ +theorem PureState.searchHamiltonian_op_apply (a ψ : PureState S) (v : S.space) : + (a.searchHamiltonian ψ).op v + = (inner ℂ a.vec v) • a.vec + (inner ℂ ψ.vec v) • ψ.vec := by + simp only [PureState.searchHamiltonian, add_apply, + PureState.projObservable_op, rankOne_apply] + +/-- **The action of the search Hamiltonian on the target `|a⟩`.** For pure states `a`, `ψ` with +real overlap `⟨a, ψ⟩ = α`, `H |a⟩ = |a⟩ + α |ψ⟩` (using `⟨a, a⟩ = 1` and the Hermitian symmetry +`⟨ψ, a⟩ = conj⟨a, ψ⟩ = α`, which uses the reality of `α`). -/ +theorem PureState.searchHamiltonian_apply_left (a ψ : PureState S) {α : ℝ} + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + (a.searchHamiltonian ψ).op a.vec = a.vec + (α : ℂ) • ψ.vec := by + have hpa : inner ℂ ψ.vec a.vec = (α : ℂ) := by rw [← inner_conj_symm, h, Complex.conj_ofReal] + rw [PureState.searchHamiltonian_op_apply, a.inner_self, hpa, one_smul] + +/-- **The action of the search Hamiltonian on the start `|ψ⟩`.** For pure states `a`, `ψ` with real +overlap `⟨a, ψ⟩ = α`, `H |ψ⟩ = α |a⟩ + |ψ⟩` (using `⟨a, ψ⟩ = α` and `⟨ψ, ψ⟩ = 1`). -/ +theorem PureState.searchHamiltonian_apply_right (a ψ : PureState S) {α : ℝ} + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + (a.searchHamiltonian ψ).op ψ.vec = (α : ℂ) • a.vec + ψ.vec := by + rw [PureState.searchHamiltonian_op_apply, h, ψ.inner_self, one_smul] + +/-- **The `(1 + α)`-eigenvector of the search Hamiltonian.** For pure states `a`, `ψ` with real +overlap `⟨a, ψ⟩ = α`, the vector `a + ψ` is an eigenvector of `H = |a⟩⟨a| + |ψ⟩⟨ψ|` with +eigenvalue `1 + α`: `H (a + ψ) = (1 + α)(a + ψ)`. (Reality of `α` — via `⟨ψ, a⟩ = conj⟨a, ψ⟩ = α` +— is what makes this an eigenvector.) -/ +theorem PureState.searchHamiltonian_apply_add (a ψ : PureState S) {α : ℝ} + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + (a.searchHamiltonian ψ).op (a.vec + ψ.vec) = ((1 + α : ℝ) : ℂ) • (a.vec + ψ.vec) := by + rw [map_add, a.searchHamiltonian_apply_left ψ h, a.searchHamiltonian_apply_right ψ h] + push_cast; module + +/-- **The `(1 - α)`-eigenvector of the search Hamiltonian.** For pure states `a`, `ψ` with real +overlap `⟨a, ψ⟩ = α`, the vector `a - ψ` is an eigenvector of `H = |a⟩⟨a| + |ψ⟩⟨ψ|` with +eigenvalue `1 - α`: `H (a - ψ) = (1 - α)(a - ψ)`. -/ +theorem PureState.searchHamiltonian_apply_sub (a ψ : PureState S) {α : ℝ} + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + (a.searchHamiltonian ψ).op (a.vec - ψ.vec) = ((1 - α : ℝ) : ℂ) • (a.vec - ψ.vec) := by + rw [map_sub, a.searchHamiltonian_apply_left ψ h, a.searchHamiltonian_apply_right ψ h] + push_cast; module + +/-- **Nielsen & Chuang eq. 6.23 — the continuous-time search evolution.** For pure states `a`, `ψ` +with real overlap `⟨a, ψ⟩ = α`, the state evolved under `H = |a⟩⟨a| + |ψ⟩⟨ψ|` for time `t` is + +`exp(-i H t) |ψ⟩ = e^{-it} (cos(α t) |ψ⟩ - i sin(α t) |a⟩)`. + +This is the two-state rotation `propagator_op_apply_of_two_state_eigen` at `(c, d) = (1, α)`: the +eigenvectors `a ± ψ` have eigenvalues `1 ± α` (`searchHamiltonian_apply_add` / `_apply_sub`), so the +phase rate is `c = 1` and the rotation rate is `d = α`. -/ +theorem PureState.searchHamiltonian_propagator_op_apply (a ψ : PureState S) {α : ℝ} (t : ℝ) + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + ((a.searchHamiltonian ψ).propagator 1 0 t).op ψ.vec + = Complex.exp (-(Complex.I * (t : ℂ))) + • ((Real.cos (α * t) : ℂ) • ψ.vec - (Complex.I * (Real.sin (α * t) : ℂ)) • a.vec) := by + have := (a.searchHamiltonian ψ).propagator_op_apply_of_two_state_eigen a ψ (c := 1) (d := α) t + (a.searchHamiltonian_apply_add ψ h) (a.searchHamiltonian_apply_sub ψ h) + simpa only [one_mul] using this + +/-- **The search Hamiltonian solves the search problem (N&C §6.2, eqs. 6.23–6.24).** For pure +states `a`, `ψ` with real, positive overlap `⟨a, ψ⟩ = α > 0`, evolving `ψ` under +`H = |a⟩⟨a| + |ψ⟩⟨ψ|` for time `t = π/(2α)` produces the target state `a` up to a global phase — +the density operators coincide: +`((H.propagator 1 0 (π/(2α))).evolvePure ψ).toState = a.toState`. This is the two-state landing +`evolvePure_toState_of_two_state_eigen` at `(c, d) = (1, α)` (rotation rate `d = α`, so the +observation time is `π/(2α)`): at `t = π/(2α)`, `cos(α t) = 0` and `sin(α t) = 1`, giving +`-i e^{-it} |a⟩`, a unit-modulus phase times `|a⟩` (invisible to the state, +`PureState.toState_eq_of_vec_eq_smul`). For the single-solution search `α = 1/√N`, this is the +observation time `t = π√N/2`. -/ +theorem PureState.searchHamiltonian_reaches_target (a ψ : PureState S) {α : ℝ} (hα : 0 < α) + (h : inner ℂ a.vec ψ.vec = (α : ℂ)) : + (((a.searchHamiltonian ψ).propagator 1 0 (Real.pi / (2 * α))).evolvePure ψ).toState + = a.toState := + (a.searchHamiltonian ψ).evolvePure_toState_of_two_state_eigen a ψ (c := 1) (d := α) + (ne_of_gt hα) (a.searchHamiltonian_apply_add ψ h) (a.searchHamiltonian_apply_sub ψ h) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlBranchExt.lean b/LeanPool/AxQM/Postulates/API/ControlBranchExt.lean new file mode 100644 index 0000000000..f9cee00777 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlBranchExt.lean @@ -0,0 +1,113 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# AxQM.Postulates.API — control-branch extensionality and gate-algebra helpers + +Machinery for **multiply-controlled** operations (Nielsen & Chuang §4.3), used to +reason about controlled gates on `qubit ⊗ R` for an *arbitrary* target system `R`. It generalises +the three-qubit tools of `ControlledControlledUnitary` from a fixed two-control system to an +arbitrary tail, so an `n`-control gate (`C(C(…C(U)…))`) can be handled one control at a time. + +## What is formalised + +* `controlBranch_evolution_ext` — **control-branch extensionality:** two evolutions of `qubit ⊗ R` + are equal as soon as they agree on every product input `|i⟩ ⊗ ψ` with `i ∈ {0, 1}` a + computational-basis control and `ψ` an arbitrary pure state of the tail `R`. This is the tool that + lets an induction on the number of controls peel one control at a time (the target `R` being the + remaining controls plus the target qubit), the direct generalisation of + `threeQubit_evolution_ext` to a variable tail. +* `Evolution.adjoint_comp_self'` — the gate-level unitarity cancellation `U† U = 1` (the + `Evolution`-valued form of the op-level `Evolution.adjoint_comp_self`). +* `controlledUnitary_id` — `C(1) = 1`: controlling the identity gate is the identity. + +The generic right-factor gate-algebra `Evolution.onRight_comp` (`(1 ⊗ V)(1 ⊗ W) = 1 ⊗ (V W)`) and +`Evolution.id_onRight` (`1 ⊗ 1 = 1`) are reused from `Postulates/API/ToffoliHadamard`. + +## Design notes + +* **The extensionality proof.** As in `threeQubit_evolution_ext`, reduce `Evolution` equality to + operator equality (`Evolution.ext`, `ContinuousLinearMap.coe_injective`) and apply + `Module.Basis.ext` to the tensor basis `basisFun (Fin 2) ⊗ stdOrthonormalBasis R.space` (via + `OrthonormalBasis.tensorProduct`). Each tail basis vector is a unit vector, hence the `vec` of a + `PureState`, so the product hypothesis supplies the required agreement after unfolding + `evolvePure_vec` / `PureState.tmul_vec`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### Control-branch extensionality -/ + +/-- **Control-branch extensionality for `qubit ⊗ R` gates.** Two evolutions `A`, `B` of `qubit ⊗ R` +(control qubit on the left, arbitrary tail `R` on the right) are equal as soon as they agree on +every product input `|i⟩ ⊗ ψ` with `i ∈ {0, 1}` a computational-basis control and `ψ` an arbitrary +pure state of `R`. This is the tool for peeling one control at a time in an induction over the +number of controls; it generalises `threeQubit_evolution_ext` from the fixed two-control tail +`qubit ⊗ qubit` to a variable tail `R`. + +Proved as in `threeQubit_evolution_ext`: reduce to operator equality (`Evolution.ext`, +`ContinuousLinearMap.coe_injective`) and apply `Module.Basis.ext` to the tensor basis +`EuclideanSpace.basisFun (Fin 2) ⊗ stdOrthonormalBasis R.space`; each tail basis vector `eR j` is a +unit vector, hence `(⟨eR j, _⟩ : PureState R).vec`, so the hypothesis supplies agreement on the +basis after unfolding `evolvePure_vec` / `PureState.tmul_vec`. -/ +theorem controlBranch_evolution_ext {R : QSystem} {A B : Evolution (qubit ⊗ R)} + (h : ∀ (i : Fin 2) (ψ : PureState R), + A.evolvePure ((qubitBasis i) ⊗ ψ) = B.evolvePure ((qubitBasis i) ⊗ ψ)) : + A = B := by + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + let bq : OrthonormalBasis (Fin 2) ℂ qubit.space := EuclideanSpace.basisFun (Fin 2) ℂ + let eR : OrthonormalBasis (Fin (Module.finrank ℂ R.space)) ℂ R.space := + stdOrthonormalBasis ℂ R.space + have hbq : ∀ i : Fin 2, bq i = (qubitBasis i).vec := fun i => by + rw [qubitBasis_vec]; exact EuclideanSpace.basisFun_apply (Fin 2) ℂ i + refine Module.Basis.ext (bq.tensorProduct eR).toBasis ?_ + rintro ⟨i, j⟩ + have hb : (bq.tensorProduct eR).toBasis (i, j) = (qubitBasis i).vec ⊗ₜ[ℂ] (eR j) := by + rw [OrthonormalBasis.coe_toBasis, OrthonormalBasis.tensorProduct_apply, hbq] + rw [hb] + let ψ : PureState R := ⟨eR j, eR.orthonormal.1 j⟩ + have hh := congrArg PureState.vec (h i ψ) + simp only [Evolution.evolvePure_vec, PureState.tmul_vec] at hh + exact hh + +/-! ### Gate-level unitarity cancellation -/ + +/-- **Uncompute cancellation** `U† U = 1` as an equality of `Evolution`s: the `Evolution`-valued +form of the op-level `Evolution.adjoint_comp_self` (named `_self'` to follow it, *not* the bare +`adjoint_comp`, which is Mathlib's adjoint-of-a-composition `(A ∘ B)† = B† ∘ A†`). -/ +theorem Evolution.adjoint_comp_self' (U : Evolution S) : U.adjoint.comp U = Evolution.id := by + apply Evolution.ext + rw [Evolution.comp_op, Evolution.adjoint_op, Evolution.id_op, U.adjoint_comp_self] + +/-! ### Controlling the identity -/ + +/-- **Controlling the identity gate is the identity:** `C(1) = 1`. With control `|0⟩` the target is +untouched and with control `|1⟩` the identity is applied, so nothing happens either way. -/ +theorem controlledUnitary_id : controlledUnitary (Evolution.id : Evolution S) = Evolution.id := by + apply controlBranch_evolution_ext + intro i _ + fin_cases i <;> + simp only [Fin.mk_zero, Fin.mk_one, Fin.isValue, controlledUnitary_evolvePure_ketZero, + controlledUnitary_evolvePure_ketOne, Evolution.id_evolvePure] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlMeasurementCommute.lean b/LeanPool/AxQM/Postulates/API/ControlMeasurementCommute.lean new file mode 100644 index 0000000000..9047e84bca --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlMeasurementCommute.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement + +/-! +# AxQM — measuring the control commutes with a controlled gate (N&C Exercise 4.35) + +The control-qubit instance of the deferred-measurement engine +(`AxQM/Postulates/API/DeferredMeasurement.lean`): the concrete measurement, gate family, +and — the crux — the operator commutation that N&C's Exercise 4.35 turns on. + +* `controlMeasurement S` — the projective **measurement of the control qubit** in the computational + basis, on `qubit ⊗ S`: the two-qubit-basis measurement `Mᵢ = |i⟩⟨i|` of the left factor lifted by + `Measurement.onLeft`, so `Mᵢ = |i⟩⟨i| ⊗ 1` on `qubit ⊗ S` (`controlMeasurement_op`). +* `classicalControl U` — the **classically-controlled gate** applied on the branch of outcome `i`: + the identity on outcome `0` and `1 ⊗ U` (`Evolution.onRight U qubit`) on outcome `1`. This is the + gate the rightmost circuit of Exercise 4.35 applies conditioned on the measured control bit. +* `controlMeasurement_op_comp_controlledUnitary` — **the commutation** `Mᵢ · C(U) = Wᵢ · Mᵢ`, the + hypothesis the deferred-measurement engine consumes. With control `|0⟩` both sides project onto + `|0⟩` (`W₀ = 1`); with control `|1⟩` both sides give `|1⟩⟨1| ⊗ U` (`W₁ = 1 ⊗ U`). This is why + measuring the control commutes with `C(U)`. + +The two physical readings — the measurement statistics and the post-measurement state agree between +"apply `C(U)` then measure the control" and "measure the control then apply the classical gate" — +are the theorems in [upstream `AxQM/NC/Ch4/Exercise4_35.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_35.lean), obtained by +feeding this commutation to the engine. + +## Proof of the commutation + +Both `Mᵢ = |i⟩⟨i| ⊗ 1` and `C(U) = |0⟩⟨0| ⊗ 1 + |1⟩⟨1| ⊗ U` are block operators, so the composite is +the block algebra of `controlledUnitary` (restated at the raw tensor head via `change`, then +`TensorProduct.mapL_comp` over the sum): the projector products `|i⟩⟨i| |j⟩⟨j| = δᵢⱼ |i⟩⟨i|` +collapse the diagonal, leaving `M₀ · C(U) = |0⟩⟨0| ⊗ 1 = M₀` and +`M₁ · C(U) = |1⟩⟨1| ⊗ U = (1 ⊗ U) · M₁`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The projective **measurement of the control qubit** in the computational basis, on `qubit ⊗ S`: +the two-outcome basis measurement `Mᵢ = |i⟩⟨i|` of the qubit (`Measurement.ofOrthonormalBasis` of +the standard basis) lifted to the *left* factor by `Measurement.onLeft`, so its operators are +`Mᵢ = |i⟩⟨i| ⊗ 1` (`controlMeasurement_op`). This is the measurement N&C's Exercise 4.35 performs on +the control wire. -/ +def controlMeasurement (S : QSystem) : Measurement (Fin 2) (qubit ⊗ S) := + (Measurement.ofOrthonormalBasis (EuclideanSpace.basisFun (Fin 2) ℂ)).onLeft S + +/-- The operators of `controlMeasurement` are the computational-basis control projectors +`Mᵢ = |i⟩⟨i| ⊗ 1` on `qubit ⊗ S`. Rewrites the standard-basis vectors `EuclideanSpace.single i 1` +to the qubit computational-basis states `(qubitBasis i).vec`. -/ +theorem controlMeasurement_op (S : QSystem) (i : Fin 2) : + (controlMeasurement S).op i + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec) + (1 : S.space →L[ℂ] S.space) := by + rw [controlMeasurement, Measurement.onLeft_op] + -- `(ofOrthonormalBasis b).op i = rankOne ℂ (b i) (b i)` (`ofOrthonormalBasis_op`, itself `rfl`) + -- and `basisFun i = single i 1 = (qubitBasis i).vec` are both matched up to the + -- `qubit.space`/`EuclideanSpace` FunLike-instance defeq (which `rw`/`simp` key on but + -- `exact` tolerates) via `congrArg`. + exact congrArg + (fun v => TensorProduct.mapL (InnerProductSpace.rankOne ℂ v v) (1 : S.space →L[ℂ] S.space)) + ((EuclideanSpace.basisFun_apply (Fin 2) ℂ i).trans (qubitBasis_vec i).symm) + +/-- The **classically-controlled gate** applied on the branch of measurement outcome `i`: the +identity for `i = 0` and `1 ⊗ U` (`Evolution.onRight U qubit`, i.e. `U` on the target) for `i = 1`. +This is the gate `Uᶜᵒⁿᵗʳᵒˡ` conditioned on the measured control bit in the rightmost circuit of +N&C Exercise 4.35. -/ +def classicalControl (U : Evolution S) : Fin 2 → Evolution (qubit ⊗ S) := + ![Evolution.id, Evolution.onRight U qubit] + +@[simp] +theorem classicalControl_zero (U : Evolution S) : classicalControl U 0 = Evolution.id := rfl + +@[simp] +theorem classicalControl_one (U : Evolution S) : + classicalControl U 1 = Evolution.onRight U qubit := rfl + +/-- **The commutation of Exercise 4.35** `Mᵢ · C(U) = Wᵢ · Mᵢ`: composing the control-projector +`Mᵢ = |i⟩⟨i| ⊗ 1` after the controlled-`U` gate equals the classical-control gate `Wᵢ` after `Mᵢ`. +For control `|0⟩`, `M₀ · C(U) = |0⟩⟨0| ⊗ 1 = 1 · M₀` (nothing is applied); for control `|1⟩`, +`M₁ · C(U) = |1⟩⟨1| ⊗ U = (1 ⊗ U) · M₁` (`U` on the target). This is the hypothesis fed to the +deferred-measurement engine (`Measurement.postOp_evolve_of_comm` and its corollaries) to prove that +measuring the control commutes with `C(U)`. -/ +theorem controlMeasurement_op_comp_controlledUnitary (U : Evolution S) (i : Fin 2) : + ((controlMeasurement S).op i).comp (controlledUnitary U).op + = (classicalControl U i).op.comp ((controlMeasurement S).op i) := by + fin_cases i + · simp only [Fin.mk_zero, Fin.isValue] + rw [controlMeasurement_op, controlledUnitary_op, classicalControl_zero, Evolution.id_op] + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space)).comp + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op) + = (1 : qubit.space ⊗[ℂ] S.space →L[ℂ] qubit.space ⊗[ℂ] S.space).comp + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1) + rw [ContinuousLinearMap.comp_add, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + rankOne_qubitBasis_comp_self 0, rankOne_qubitBasis_comp_orthogonal (by decide), + TensorProduct.mapL_zero_left, add_zero] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + ContinuousLinearMap.comp_id] + · simp only [Fin.mk_one, Fin.isValue] + rw [controlMeasurement_op, controlledUnitary_op, classicalControl_one] + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + (1 : S.space →L[ℂ] S.space)).comp + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op) + = (TensorProduct.mapL (1 : qubit.space →L[ℂ] qubit.space) U.op).comp + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) 1) + rw [ContinuousLinearMap.comp_add, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + rankOne_qubitBasis_comp_orthogonal (by decide), rankOne_qubitBasis_comp_self 1, + TensorProduct.mapL_zero_left, zero_add, ← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + ContinuousLinearMap.comp_id] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlPairGates.lean b/LeanPool/AxQM/Postulates/API/ControlPairGates.lean new file mode 100644 index 0000000000..a9c6e788d1 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlPairGates.lean @@ -0,0 +1,196 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.LeftPairGate +public import LeanPool.AxQM.Postulates.API.ToffoliHadamard + +/-! +# AxQM.Postulates.API — arbitrary two-qubit gates on the *control pairs* of three qubits + +Infrastructure placing an **arbitrary** two-qubit `Evolution (qubit ⊗ qubit)` on the +two wire pairs of the right-associated three-qubit system `qubit ⊗ (qubit ⊗ qubit)` that involve +the first (control) qubit: + +* `leftPairGate U` — `U` on qubits **1, 2** (wires `{0,1}`), qubit 3 idle; +* `outerPairGate U` — `U` on the **outer** qubits **1, 3** (wires `{0,2}`), qubit 2 idle. + +The remaining pair (qubits 2, 3, wires `{1,2}`) is already reachable directly as `U.onRight qubit` +(`= 1 ⊗ U`), so together with `onRight` these two placements let one drop an arbitrary two-qubit +gate on *any* of the three wire pairs. + +## Why this file exists (Nielsen & Chuang Exercise 4.25, part 4) + +Exercise 4.25 part (3) builds the Fredkin gate from **six** two-qubit gates (formalised in +`Core.FredkinTwoQubitCircuit` / [upstream `NC/Ch4/Exercise4_25.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_25.lean)) and part (4) asks for an even simpler +construction using only **five** two-qubit gates — the Smolin–DiVincenzo result. The five-gate +circuit is *not* expressible in the part-1–3 alphabet `TwoQubitGate3`, whose control-pair gates are +restricted to *controlled single-qubit* gates (`ctrl t g`): with only controlled-unitary gates on +the control pairs and an arbitrary gate on the target pair, the Fredkin gate cannot be reached in +five two-qubit gates even allowing free single-qubit gates — a genuine `√SWAP`-class entangling gate +on a control pair is unavoidable. (Concretely this is the same fact as Problem 3.5, that *classical* +one- and two-bit reversible gates cannot build the Toffoli/Fredkin: the five-gate construction must +use a superposition-creating two-qubit gate on a control pair.) + +These two placements supply exactly that missing class of gate — an arbitrary two-qubit gate on a +control pair — and generalise the existing single purpose-built placement `reversedCnotLeftGate` +(which is the `reversedCnotGate` special case of `leftPairGate`, recorded below as +`reversedCnotLeftGate_eq_leftPairGate`). + +## What is formalised + +* `leftPairGate U` / `outerPairGate U` — the two placements, realised by carrying the left/right + factor embedding of `U` across the appropriate structural system isomorphism (`QSystem.assoc` for + the left pair, `QSystem.Iso.leftComm` for the outer pair) with `Evolution.congr`, exactly as + `reversedCnotLeftGate` does for its special case. +* `leftPairGate_evolvePure` / `outerPairGate_evolvePure` — the **action laws**: how each placement + acts on a product state `ψ ⊗ (φ ⊗ χ)`, expressed via `U`'s action on the relevant pair (kept + abstract, so an entangling `U` is handled without expanding it into basis superpositions). +* `leftPairGate_evolvePure_tmul` / `outerPairGate_evolvePure_tmul` — the specialisations for when + `U`'s action on the pair *is* a product state (the truth-table case), with the associator + round-trip already discharged. +* `leftPairGate_comp` / `outerPairGate_comp` — the placements are composition homomorphisms. +* `reversedCnotLeftGate_eq_leftPairGate` — the subsumption of the purpose-built gate. +* `leftPairGate_cnotGate` / `leftPairGate_hadamardTmul` — two `leftPairGate` truth-table + identifications: the forward `CNOT` on the left pair is `cnotLeftGate`, and `H ⊗ H` on the left + pair splits into the wire-0 and wire-1 Hadamards. The forward-`CNOT` twin of + `reversedCnotLeftGate_eq_leftPairGate`, and the building blocks a Hadamard-conjugated left-pair + `CNOT` decomposes into. + +## Design notes + +* **Construction.** The gates are built from `Evolution.congr`, `QSystem.assoc`, + `QSystem.Iso.leftComm`, `Evolution.onLeft`/`onRight`, `PureState.congr`, `evolvePure` and `⊗`, + using the associator / commutation transport API, alongside `reversedCnotLeftGate`, `fredkinGate` + and the controlled-gate vocabulary. +* **Fidelity / generality.** `U` is an *arbitrary* two-qubit `Evolution`, so the placements are + fully general (`reversedCnotLeftGate` is one instance); the action laws keep `U`'s action + abstract, so a genuine entangling square root of `SWAP` can be used + without ever expanding it into computational-basis coefficients. +* **Proof.** `Evolution.congr_evolvePure_congr` turns each placement's action into `U`'s action on + the re-bracketed pair, exactly the `reversedCnotLeftGate_evolvePure_qubitBasis` mechanism, and the + structural transports `pureState_congr_assocSymm` / `pureState_congr_leftCommSymm` re-bracket the + product state back. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### An arbitrary two-qubit gate on the left pair (qubits 1, 2) -/ + +/-- **An arbitrary two-qubit gate on qubits 1, 2** (wires `{0,1}`) of the right-associated +three-qubit system, qubit 3 untouched: the two-qubit `U` placed on the left pair of the +left-associated `(qubit ⊗ qubit) ⊗ qubit` via `onLeft` and carried across the associator system +isomorphism `QSystem.assoc`. It generalises `reversedCnotLeftGate` (the `reversedCnotGate` instance, +`reversedCnotLeftGate_eq_leftPairGate`). -/ +def leftPairGate (U : Evolution (qubit ⊗ qubit)) : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + (U.onLeft qubit).congr (QSystem.assoc qubit qubit qubit).symm + +/-- **An arbitrary two-qubit gate on the outer qubits 1, 3** (wires `{0,2}`) of the right-associated +three-qubit system, qubit 2 untouched: the two-qubit `U` placed on the *right* factor +`qubit ⊗ qubit` of `qubit ⊗ (qubit ⊗ qubit)` after moving qubit 2 to the front with +`QSystem.Iso.leftComm`, then carried back. Concretely `U` acts on qubits 1 and 3, qubit 2 idle. -/ +def outerPairGate (U : Evolution (qubit ⊗ qubit)) : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + (U.onRight qubit).congr (QSystem.Iso.leftComm qubit qubit qubit).symm + +/-- **`leftPairGate` subsumes `reversedCnotLeftGate`.** The purpose-built reversed-`CNOT` on the +left pair is the `reversedCnotGate` instance of the general placement: both are +`(reversedCnotGate.onLeft qubit).congr (assoc).symm`. -/ +theorem reversedCnotLeftGate_eq_leftPairGate : + reversedCnotLeftGate = leftPairGate reversedCnotGate := rfl + +/-! ### Action laws -/ + +/-- **`leftPairGate` action law.** On a product state `ψ ⊗ (φ ⊗ χ)`, `leftPairGate U` applies `U` +to the front pair `ψ ⊗ φ` (qubits 1, 2) and re-brackets, leaving qubit 3 (`χ`) idle: +`leftPairGate U (ψ ⊗ (φ ⊗ χ)) = ((U (ψ ⊗ φ)) ⊗ χ).congr (assoc).symm`. `U`'s action stays abstract, +so an entangling `U` needs no basis expansion. -/ +theorem leftPairGate_evolvePure (U : Evolution (qubit ⊗ qubit)) (ψ φ χ : PureState qubit) : + (leftPairGate U).evolvePure (ψ ⊗ (φ ⊗ χ)) + = ((U.evolvePure (ψ ⊗ φ)) ⊗ χ).congr (QSystem.assoc qubit qubit qubit).symm := by + rw [leftPairGate, ← pureState_congr_assocSymm ψ φ χ, Evolution.congr_evolvePure_congr, + Evolution.onLeft_evolvePure] + +/-- **`outerPairGate` action law.** On a product state `ψ ⊗ (φ ⊗ χ)`, `outerPairGate U` applies `U` +to the outer pair `ψ ⊗ χ` (qubits 1, 3) and re-brackets, leaving qubit 2 (`φ`) idle: +`outerPairGate U (ψ ⊗ (φ ⊗ χ)) = (φ ⊗ (U (ψ ⊗ χ))).congr (leftComm).symm`. -/ +theorem outerPairGate_evolvePure (U : Evolution (qubit ⊗ qubit)) (ψ φ χ : PureState qubit) : + (outerPairGate U).evolvePure (ψ ⊗ (φ ⊗ χ)) + = (φ ⊗ (U.evolvePure (ψ ⊗ χ))).congr (QSystem.Iso.leftComm qubit qubit qubit).symm := by + rw [outerPairGate, ← pureState_congr_leftCommSymm ψ φ χ, Evolution.congr_evolvePure_congr, + Evolution.onRight_evolvePure] + +/-- **`leftPairGate` truth-table specialisation.** When `U` sends `ψ ⊗ φ` to a *product* `ψ' ⊗ φ'`, +`leftPairGate U` sends `ψ ⊗ (φ ⊗ χ)` to `ψ' ⊗ (φ' ⊗ χ)` — the associator round-trip is discharged. +-/ +theorem leftPairGate_evolvePure_tmul (U : Evolution (qubit ⊗ qubit)) + (ψ φ χ ψ' φ' : PureState qubit) (h : U.evolvePure (ψ ⊗ φ) = ψ' ⊗ φ') : + (leftPairGate U).evolvePure (ψ ⊗ (φ ⊗ χ)) = ψ' ⊗ (φ' ⊗ χ) := by + rw [leftPairGate_evolvePure, h, pureState_congr_assocSymm] + +/-- **`outerPairGate` truth-table specialisation.** When `U` sends `ψ ⊗ χ` to a *product* `ψ' ⊗ χ'`, +`outerPairGate U` sends `ψ ⊗ (φ ⊗ χ)` to `ψ' ⊗ (φ ⊗ χ')`. -/ +theorem outerPairGate_evolvePure_tmul (U : Evolution (qubit ⊗ qubit)) + (ψ φ χ ψ' χ' : PureState qubit) (h : U.evolvePure (ψ ⊗ χ) = ψ' ⊗ χ') : + (outerPairGate U).evolvePure (ψ ⊗ (φ ⊗ χ)) = ψ' ⊗ (φ ⊗ χ') := by + rw [outerPairGate_evolvePure, h, pureState_congr_leftCommSymm] + +/-! ### The placements are composition homomorphisms -/ + +/-- **`leftPairGate` is a composition homomorphism:** placing a product of two-qubit gates on the +left pair composes the placements, `leftPairGate (U · W) = leftPairGate U · leftPairGate W`. Lets +two adjacent left-pair gates merge into one. -/ +theorem leftPairGate_comp (U W : Evolution (qubit ⊗ qubit)) : + leftPairGate (U.comp W) = (leftPairGate U).comp (leftPairGate W) := by + rw [leftPairGate, leftPairGate, leftPairGate, ← Evolution.onLeft_comp, Evolution.congr_comp] + +/-- **`outerPairGate` is a composition homomorphism:** +`outerPairGate (U · W) = outerPairGate U · outerPairGate W`. -/ +theorem outerPairGate_comp (U W : Evolution (qubit ⊗ qubit)) : + outerPairGate (U.comp W) = (outerPairGate U).comp (outerPairGate W) := by + rw [outerPairGate, outerPairGate, outerPairGate, ← Evolution.onRight_comp, Evolution.congr_comp] + +/-! ### `leftPairGate` truth-table identifications -/ + +/-- **The forward `CNOT` on the left pair is `cnotLeftGate`.** +`leftPairGate cnotGate = cnotLeftGate`: the two-qubit `CNOT` (control first, target second) placed +on qubits 1, 2 of `qubit ⊗ (qubit ⊗ qubit)` is exactly the purpose-built left-pair `CNOT` +`|q₁,q₂,q₃⟩ ↦ |q₁, q₂ ⊕ q₁, q₃⟩`. The forward-`CNOT` +twin of `reversedCnotLeftGate_eq_leftPairGate`. Proved on computational-basis states via +`leftPairGate_evolvePure_tmul` (both `cnotGate` and `cnotLeftGate` are product-preserving). -/ +theorem leftPairGate_cnotGate : leftPairGate cnotGate = cnotLeftGate := by + apply threeQubit_evolution_ext + intro q1 q2 q3 + rw [leftPairGate_evolvePure_tmul cnotGate (qubitBasis q1) (qubitBasis q2) (qubitBasis q3) + (qubitBasis q1) (qubitBasis (q2 + q1)) (cnotGate_evolvePure_qubitBasis q1 q2), + cnotLeftGate_evolvePure_qubitBasis] + +/-- **`H ⊗ H` on the left pair splits into the wire-0 and wire-1 Hadamards.** +`leftPairGate (H ⊗ H) = (H ⊗ 1) · (1 ⊗ (H ⊗ 1))`, i.e. the placement of the two-qubit `H ⊗ H` on +qubits 1, 2 of `qubit ⊗ (qubit ⊗ qubit)` is the Hadamard on qubit 1 (`hadamardGate.onLeft (qubit ⊗ +qubit)`) composed with the Hadamard on qubit 2 (`(hadamardGate.onLeft qubit).onRight qubit`). Proved +on computational-basis states: `H ⊗ H` sends a product `ψ ⊗ φ` to the product `Hψ ⊗ Hφ`, so +`leftPairGate_evolvePure_tmul` discharges the associator round-trip with no superposition. -/ +theorem leftPairGate_hadamardTmul : + leftPairGate (hadamardGate.tmul hadamardGate) + = (hadamardGate.onLeft (qubit ⊗ qubit)).comp ((hadamardGate.onLeft qubit).onRight qubit) := by + apply threeQubit_evolution_ext + intro q1 q2 q3 + rw [leftPairGate_evolvePure_tmul (hadamardGate.tmul hadamardGate) (qubitBasis q1) (qubitBasis q2) + (qubitBasis q3) (hadamardGate.evolvePure (qubitBasis q1)) + (hadamardGate.evolvePure (qubitBasis q2)) (Evolution.tmul_evolvePure _ _ _ _)] + simp only [Evolution.evolvePure_comp, Evolution.onRight_evolvePure, Evolution.onLeft, + Evolution.tmul_evolvePure, Evolution.id_evolvePure] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledControlledUnitary.lean b/LeanPool/AxQM/Postulates/API/ControlledControlledUnitary.lean new file mode 100644 index 0000000000..a41c98b157 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledControlledUnitary.lean @@ -0,0 +1,222 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.QubitThree + +/-! +# AxQM.Postulates.API — the doubly-controlled gate `C²(U)` and three-qubit machinery + +Infrastructure for Nielsen & Chuang's **multiply-controlled** operations +(N&C §4.3, eq. 4.29): the doubly-controlled gate `C²(U)` and the tools needed to verify +three-qubit circuit identities against it (e.g. Exercise 4.21 — Figure 4.8). It sits above +`ControlledUnitary` (the single-qubit-controlled `C(U)` and `CNOT`) and is reused wherever a +two-control gate appears (the Toffoli gate `C²(X)`, Exercises 4.21–4.25). + +## What is formalised + +* **Factorised action of composite evolutions.** `Evolution.id_evolvePure`, + `Evolution.tmul_evolvePure`, `Evolution.onLeft_evolvePure`, `Evolution.onRight_evolvePure` — the + Schrödinger action of `1`, `U ⊗ V`, `U ⊗ 1` and `1 ⊗ V` on product pure states, all definitional + (`mapL` on a pure tensor is factorwise). These are the generic tools for computing a gate's + action on a computational-basis input, one tensor factor at a time. +* `ccontrolledUnitary U` — the **doubly-controlled gate** `C²(U) = C(C(U))` on the three-qubit + system `qubit ⊗ (qubit ⊗ qubit)`: apply the single-qubit unitary `U` to the last qubit exactly + when *both* of the first two ("control") qubits are `|1⟩` (N&C eq. 4.29 with `n = 2`, `k = 1`). + It is literally the single-qubit-controlled gate `controlledUnitary` applied twice, so it is a + genuine `Evolution` (its unitarity is inherited, no new obligation). +* `ccontrolledUnitary_evolvePure_ketZero_left` / `ccontrolledUnitary_evolvePure_ketOne_left` — the + **defining action** split on the first control: control `|0⟩` leaves the other two qubits + untouched; control `|1⟩` applies the *single*-controlled `C(U)` to the remaining two qubits. + Together with the `controlledUnitary` action lemmas these give the full `C²(U)` truth table. +* `threeQubit_evolution_ext` — **computational-basis extensionality** for three-qubit gates: two + evolutions of `qubit ⊗ (qubit ⊗ qubit)` are equal as soon as they agree on every computational + basis state `|q₁⟩ ⊗ |q₂⟩ ⊗ |q₃⟩`. This is what turns "verify the circuit on each of the eight + basis inputs" into a genuine equality of unitary gates. + +## Design notes + +* **`C²(U) = C(C(U))` (fidelity).** N&C defines `Cⁿ(U)` by `Cⁿ(U)|x₁…xₙ⟩|ψ⟩ = |x₁…xₙ⟩ U^{x₁⋯xₙ}|ψ⟩` + (eq. 4.29). For `n = 2` this is exactly `C(C(U))`: the outer `C` conditions on the first control, + and its target — the two-qubit gate `C(U)` — conditions on the second, so `U` fires iff both bits + are set. Taking the right-associated three-qubit system `qubit ⊗ (qubit ⊗ qubit)` (control₁ ⊗ + (control₂ ⊗ target)) makes this the definitional `controlledUnitary (controlledUnitary U)`, with + *no* associator bookkeeping. All five gates of a Figure-4.8-style decomposition then live on this + same system. +* **The extensionality bridge.** A unitary on the eight-dimensional space is determined by its + action on the computational basis `|q₁⟩⊗(|q₂⟩⊗|q₃⟩)`. The proof reduces `Evolution` equality to + operator equality (`Evolution.ext`), then to linear-map equality + (`ContinuousLinearMap.coe_injective`), and applies `Module.Basis.ext` to the tensor-product + orthonormal basis `EuclideanSpace.basisFun ⊗ (EuclideanSpace.basisFun ⊗ EuclideanSpace.basisFun)` + (via `OrthonormalBasis.tensorProduct`), whose eight vectors are exactly the + `|qᵢ⟩ = (qubitBasis _).vec`. + The `evolvePure` hypothesis supplies agreement on those vectors after unfolding `evolvePure_vec` + and `PureState.tmul_vec`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-! ### Factorised Schrödinger action of composite evolutions -/ + +/-- **The identity evolution acts trivially on pure states:** `1 · ψ = ψ`. -/ +theorem Evolution.id_evolvePure (ψ : PureState S) : Evolution.id.evolvePure ψ = ψ := by + apply PureState.ext; rfl + +/-- **A product gate acts factorwise on a product state:** `(U ⊗ V)(ψ ⊗ φ) = (Uψ) ⊗ (Vφ)`. The +tensor operator `U ⊗ V = TensorProduct.mapL U.op V.op` sends the pure tensor `ψ.vec ⊗ₜ φ.vec` to +`U.op ψ.vec ⊗ₜ V.op φ.vec`, definitionally. -/ +theorem Evolution.tmul_evolvePure (U : Evolution S) (V : Evolution T) + (ψ : PureState S) (φ : PureState T) : + (U ⊗ V).evolvePure (ψ ⊗ φ) = (U.evolvePure ψ) ⊗ (V.evolvePure φ) := by + apply PureState.ext; rfl + +/-- **A gate on the left factor acts only there:** `(U ⊗ 1)(ψ ⊗ φ) = (Uψ) ⊗ φ`. -/ +theorem Evolution.onLeft_evolvePure (U : Evolution S) (T : QSystem) + (ψ : PureState S) (φ : PureState T) : + (U.onLeft T).evolvePure (ψ ⊗ φ) = (U.evolvePure ψ) ⊗ φ := by + apply PureState.ext; rfl + +/-- **A gate on the right factor acts only there:** `(1 ⊗ V)(ψ ⊗ φ) = ψ ⊗ (Vφ)`. -/ +theorem Evolution.onRight_evolvePure (V : Evolution T) (S : QSystem) + (ψ : PureState S) (φ : PureState T) : + (V.onRight S).evolvePure (ψ ⊗ φ) = ψ ⊗ (V.evolvePure φ) := by + apply PureState.ext; rfl + +/-! ### The doubly-controlled gate `C²(U)` -/ + +/-- **The doubly-controlled gate** `C²(U)` (Nielsen & Chuang eq. 4.29, `n = 2`, `k = 1`) on the +three-qubit system `qubit ⊗ (qubit ⊗ qubit)`: the single-qubit unitary `U` is applied to the last +qubit exactly when *both* of the first two control qubits are `|1⟩`. It is the single-controlled +gate `controlledUnitary` iterated once, `C²(U) = C(C(U))`: the outer control is the first qubit and +its target is the two-qubit gate `C(U)` conditioning on the second qubit. Being a composition of +`controlledUnitary`, it is automatically a unitary `Evolution`. -/ +def ccontrolledUnitary (U : Evolution qubit) : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + controlledUnitary (controlledUnitary U) + +/-- **`C²(U)`, first control `|0⟩`:** the remaining two qubits are untouched, +`C²(U)(|0⟩ ⊗ ψ) = |0⟩ ⊗ ψ`. -/ +theorem ccontrolledUnitary_evolvePure_ketZero_left (U : Evolution qubit) + (ψ : PureState (qubit ⊗ qubit)) : + (ccontrolledUnitary U).evolvePure ((qubitBasis 0) ⊗ ψ) = (qubitBasis 0) ⊗ ψ := + controlledUnitary_evolvePure_ketZero (controlledUnitary U) ψ + +/-- **`C²(U)`, first control `|1⟩`:** the *single*-controlled gate `C(U)` is applied to the +remaining two qubits, `C²(U)(|1⟩ ⊗ ψ) = |1⟩ ⊗ C(U)ψ`. Conditioning `C(U)` further on the second +qubit yields the full `C²(U)` truth table: `U` fires on the target iff both controls are `|1⟩`. -/ +theorem ccontrolledUnitary_evolvePure_ketOne_left (U : Evolution qubit) + (ψ : PureState (qubit ⊗ qubit)) : + (ccontrolledUnitary U).evolvePure ((qubitBasis 1) ⊗ ψ) + = (qubitBasis 1) ⊗ ((controlledUnitary U).evolvePure ψ) := + controlledUnitary_evolvePure_ketOne (controlledUnitary U) ψ + +/-! ### Computational-basis extensionality for three-qubit gates -/ + +/-- **A three-qubit gate is determined by its action on the computational basis.** Two evolutions +`A`, `B` of `qubit ⊗ (qubit ⊗ qubit)` are equal as soon as they agree on every computational-basis +state `|q₁⟩ ⊗ (|q₂⟩ ⊗ |q₃⟩)`, `qᵢ ∈ {0, 1}`. This is the tool that turns a case-by-case verification +of a circuit on the eight basis inputs into a genuine equality of unitary gates. + +The proof reduces to operator equality (`Evolution.ext`), then linear-map equality +(`ContinuousLinearMap.coe_injective`), and applies `Module.Basis.ext` to the tensor-product basis +built from `EuclideanSpace.basisFun` by `OrthonormalBasis.tensorProduct`, whose basis vectors are +the computational-basis unit vectors `(qubitBasis _).vec`; the hypothesis supplies the required +agreement after unfolding `evolvePure_vec` and `PureState.tmul_vec`. -/ +theorem threeQubit_evolution_ext {A B : Evolution (qubit ⊗ (qubit ⊗ qubit))} + (h : ∀ q1 q2 q3 : Fin 2, + A.evolvePure ((qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3))) + = B.evolvePure ((qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3)))) : + A = B := by + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + let bq : OrthonormalBasis (Fin 2) ℂ qubit.space := EuclideanSpace.basisFun (Fin 2) ℂ + have hbq : ∀ i : Fin 2, bq i = (qubitBasis i).vec := fun i => by + rw [qubitBasis_vec]; exact EuclideanSpace.basisFun_apply (Fin 2) ℂ i + refine Module.Basis.ext (bq.tensorProduct (bq.tensorProduct bq)).toBasis ?_ + rintro ⟨q1, q2, q3⟩ + have hb : (bq.tensorProduct (bq.tensorProduct bq)).toBasis (q1, q2, q3) + = (qubitBasis q1).vec ⊗ₜ[ℂ] ((qubitBasis q2).vec ⊗ₜ[ℂ] (qubitBasis q3).vec) := by + rw [OrthonormalBasis.coe_toBasis, OrthonormalBasis.tensorProduct_apply, + OrthonormalBasis.tensorProduct_apply, hbq, hbq, hbq] + rw [hb] + have hh := congrArg PureState.vec (h q1 q2 q3) + simp only [Evolution.evolvePure_vec, PureState.tmul_vec] at hh + exact hh + +/-! ### The Toffoli gate `C²(X)` + +(The three-qubit computational basis `qubitThreeBasis` used as the reference frame for +`toffoliGate`'s truth table now lives in `Postulates/API/QubitThree.lean`, imported above, so it can +be shared without dragging the Toffoli machinery into its other consumers.) -/ + +/-- **The Toffoli gate** (controlled-controlled-`NOT`, `C²(X)`; Nielsen & Chuang §1.3.4) on the +three-qubit system `qubit ⊗ (qubit ⊗ qubit)`: it flips the last (target) qubit exactly when *both* +of the first two control qubits are `|1⟩`. It is the doubly-controlled gate `ccontrolledUnitary` +with `U = X`, exactly mirroring `cnotGate = controlledUnitary pauliXGate`. The canonical two-control +gate, reused throughout Chapter 4 (Exercises 4.24–4.27). -/ +def toffoliGate : Evolution (qubit ⊗ (qubit ⊗ qubit)) := ccontrolledUnitary pauliXGate + +/-- **The Toffoli truth table** (Nielsen & Chuang §1.3.4): +`Toffoli|q₁, q₂, q₃⟩ = |q₁, q₂, q₃ ⊕ q₁·q₂⟩` — the control qubits `q₁, q₂` are unchanged and the +target `q₃` is flipped exactly when both are `1` (`q₃ + q₁ * q₂` in `Fin 2`, using that `Fin 2` +multiplication is the logical `AND`). -/ +theorem toffoliGate_evolvePure_qubitBasis (q1 q2 q3 : Fin 2) : + toffoliGate.evolvePure ((qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3))) + = (qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis (q3 + q1 * q2))) := by + rw [toffoliGate] + fin_cases q1 <;> fin_cases q2 <;> + simp only [Fin.mk_zero, Fin.mk_one, ccontrolledUnitary_evolvePure_ketZero_left, + ccontrolledUnitary_evolvePure_ketOne_left, controlledUnitary_evolvePure_ketZero, + controlledUnitary_evolvePure_ketOne, pauliXGate_evolvePure_qubitBasis, mul_zero, mul_one, + add_zero] + +/-- **The Toffoli truth table at the raw-operator level:** `C²(X) |a, b, t⟩ = |a, b, t ⊕ ab⟩` on +the underlying vectors — the `Evolution.op`-on-`.vec` form of `toffoliGate_evolvePure_qubitBasis`. +The canonical op-level Toffoli truth table, sitting beside `toffoliGate` and its `evolvePure` +companion; reused wherever a phase must be moved through a Toffoli (e.g. +`RzThreeFifthsCircuit`, `ToffoliPauliPropagation`). -/ +theorem toffoliGate_op_qubitBasis_vec (a b t : Fin 2) : + toffoliGate.op ((qubitBasis a).tmul ((qubitBasis b).tmul (qubitBasis t))).vec + = ((qubitBasis a).tmul ((qubitBasis b).tmul (qubitBasis (t + a * b)))).vec := by + rw [← Evolution.evolvePure_vec, toffoliGate_evolvePure_qubitBasis] + +/-- **The Toffoli truth table on bare tensors:** `C²(X)(|a⟩ ⊗ |b⟩ ⊗ |c⟩) = |a⟩ ⊗ |b⟩ ⊗ |c ⊕ ab⟩` +(`c + a * b` in `Fin 2`) — the bare-`⊗ₜ` form of `toffoliGate_op_qubitBasis_vec`, obtained by +unfolding `PureState.tmul_vec`. In the same `.op`-on-bare-`⊗ₜ` shape as +`cnotGate_op_qubitBasisVec_tmul`, so it fires directly on a distributed superposition of +computational-basis tensors (e.g. the ancilla preparation of Exercises 10.68 / 10.72). -/ +theorem toffoliGate_op_qubitBasisVec_tmul (a b c : Fin 2) : + toffoliGate.op ((qubitBasis a).vec ⊗ₜ[ℂ] ((qubitBasis b).vec ⊗ₜ[ℂ] (qubitBasis c).vec)) + = (qubitBasis a).vec ⊗ₜ[ℂ] ((qubitBasis b).vec ⊗ₜ[ℂ] (qubitBasis (c + a * b)).vec) := by + have h := toffoliGate_op_qubitBasis_vec a b c + simp only [PureState.tmul_vec] at h + exact h + +/-- **The Toffoli gate is an involution:** `C²(X) · C²(X) = 1`. The Toffoli permutes the +computational basis by the single transposition `|110⟩ ↔ |111⟩`, so applying it twice restores every +basis state (`(q₃ ⊕ q₁q₂) ⊕ q₁q₂ = q₃` in `Fin 2`); verified on the eight basis inputs via +`threeQubit_evolution_ext`. The Toffoli analogue of `cnotGate_comp_cnotGate`: it is the ingredient +that turns each Clifford commutation rule `C²(X)·P = P'·C²(X)` into the conjugation identity +`C²(X)·P·C²(X) = P'` (via `Evolution.comp_comp_self_of_comm`). -/ +theorem toffoliGate_comp_toffoliGate : toffoliGate.comp toffoliGate = Evolution.id := by + apply threeQubit_evolution_ext + intro q1 q2 q3 + simp only [Evolution.evolvePure_comp, toffoliGate_evolvePure_qubitBasis, Evolution.id_evolvePure] + fin_cases q1 <;> fin_cases q2 <;> fin_cases q3 <;> rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledRotation.lean b/LeanPool/AxQM/Postulates/API/ControlledRotation.lean new file mode 100644 index 0000000000..7cc1bc6068 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledRotation.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HadamardABC +public import LeanPool.AxQM.Postulates.API.HadamardRotation +public import LeanPool.AxQM.Concrete.RotationDecompositionXY + +/-! +# AxQM.Postulates.API — gate-level rotation algebra for controlled rotations + +Gate-level lifts of the concrete single-qubit rotation identities, used to assemble +the controlled rotation gates of Nielsen & Chuang §4.3 (Exercise 4.23). Each lemma promotes a matrix +identity from `Concrete/` to the corresponding `Evolution qubit` gate through the `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM` (multiplicative and sending `1 ↦ 1`), so the reasoning about +controlled rotations can stay entirely at the gate level. + +## What is formalised + +The `R_y` and `R_z` gate families each get the same three algebra lemmas — the group law +(`rotYGate_comp`/`rotZGate_comp`, images of `Concrete.rotY_mul_rotY`/`rotZ_mul_rotZ`), the identity +value at `0` (`rotYGate_zero`/`rotZGate_zero`), and the `X`-conjugation +(`pauliXGate_comp_rotYGate_comp_pauliXGate`/`pauliXGate_comp_rotZGate_comp_pauliXGate`, images of +`Concrete.pauliX_mul_rotY_mul_pauliX`/`pauliX_mul_rotZ_mul_pauliX`, N&C Exercise 4.7). In addition: + +* `hadamardGate_comp_rotZGate_comp_hadamardGate` — the Hadamard basis change + `H · R_z(θ) · H = R_x(θ)` at the gate level (image of `Concrete.hadamardC_mul_rotZ_mul_hadamardC`, + since `H Z H = X`). This is what lets controlled-`R_x` be built from controlled-`R_z`. +* `controlledUnitary_rotZGate` — the reduced controlled-`R_z` construction + `C(R_z(θ)) = (1 ⊗ R_z(θ/2)) · CNOT · (1 ⊗ R_z(-θ/2)) · CNOT`, the `R_z` analogue of + `controlledUnitary_rotYGate`, obtained from `controlledUnitary_cnot_conj_cnot`. It is the helper + behind the controlled-`R_x` construction (N&C Exercise 4.23, [upstream `NC/Ch4/Exercise4_23.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_23.lean)). + +The `R_y`/`R_z` algebra is the reason the reduction to two single-qubit gates works for these axes: +with `A = R_a(θ/2)`, `B = R_a(-θ/2)`, `A · B = R_a(0) = I` and +`A · X · B · X = R_a(θ/2) · (X R_a(-θ/2) X) = R_a(θ/2) R_a(θ/2) = R_a(θ)`, so +`controlledUnitary_cnot_conj_cnot` yields `C(R_a(θ))` from just `A`, `B` and two `CNOT`s. (The same +does not hold for `R_x`, which commutes with `X`; controlled-`R_x` instead goes through the Hadamard +basis change above.) + +## Design notes + +* **Proof shape.** `Evolution.ext` reduces each gate equation to its underlying operators; `comp_op` + turns `Evolution.comp` into `ContinuousLinearMap.comp`. The concrete matrix identity is pulled + through `Matrix.toEuclideanCLM` with `map_mul`/`map_one`; the residual + `ContinuousLinearMap.comp` vs `*` gap closes by `rfl` (they are definitionally the algebra + product). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- **The `y`-rotation gates form a one-parameter group:** `R_y(a) · R_y(b) = R_y(a + b)` as gates +on the qubit. The gate-level image of `Concrete.rotY_mul_rotY` under `Matrix.toEuclideanCLM`. -/ +theorem rotYGate_comp (a b : ℝ) : (rotYGate a).comp (rotYGate b) = rotYGate (a + b) := by + apply Evolution.ext + simp only [Evolution.comp_op, rotYGate_op] + rw [← Concrete.rotY_mul_rotY a b, map_mul] + rfl + +/-- **`R_y(0)` is the identity gate.** The gate-level image of `Concrete.rotY_zero`. -/ +theorem rotYGate_zero : rotYGate 0 = Evolution.id := by + apply Evolution.ext + rw [rotYGate_op, Concrete.rotY_zero, map_one] + rfl + +/-- **Conjugating `R_y(θ)` by `X` negates its angle:** `X · R_y(θ) · X = R_y(-θ)` at the gate level +(Nielsen & Chuang, Exercise 4.7). The gate-level image of `Concrete.pauliX_mul_rotY_mul_pauliX`. -/ +theorem pauliXGate_comp_rotYGate_comp_pauliXGate (θ : ℝ) : + pauliXGate.comp ((rotYGate θ).comp pauliXGate) = rotYGate (-θ) := by + apply Evolution.ext + simp only [Evolution.comp_op, pauliXGate_op, rotYGate_op] + rw [← Concrete.pauliX_mul_rotY_mul_pauliX θ, map_mul, map_mul, mul_assoc] + rfl + +/-- **The `z`-rotation gates form a one-parameter group:** `R_z(a) · R_z(b) = R_z(a + b)` as gates +on the qubit. The gate-level image of `Concrete.rotZ_mul_rotZ` under `Matrix.toEuclideanCLM`. -/ +theorem rotZGate_comp (a b : ℝ) : (rotZGate a).comp (rotZGate b) = rotZGate (a + b) := by + apply Evolution.ext + simp only [Evolution.comp_op, rotZGate_op] + rw [← Concrete.rotZ_mul_rotZ a b, map_mul] + rfl + +/-- **`R_z(0)` is the identity gate.** The gate-level image of `Concrete.rotZ_zero`. -/ +theorem rotZGate_zero : rotZGate 0 = Evolution.id := by + apply Evolution.ext + rw [rotZGate_op, Concrete.rotZ_zero, map_one] + rfl + +/-- **Conjugating `R_z(θ)` by `X` negates its angle:** `X · R_z(θ) · X = R_z(-θ)` at the gate level +(Nielsen & Chuang, Exercise 4.7). The gate-level image of `Concrete.pauliX_mul_rotZ_mul_pauliX`. -/ +theorem pauliXGate_comp_rotZGate_comp_pauliXGate (θ : ℝ) : + pauliXGate.comp ((rotZGate θ).comp pauliXGate) = rotZGate (-θ) := by + apply Evolution.ext + simp only [Evolution.comp_op, pauliXGate_op, rotZGate_op] + rw [← Concrete.pauliX_mul_rotZ_mul_pauliX θ, map_mul, map_mul, mul_assoc] + rfl + +/-- **The Hadamard basis change `H · R_z(θ) · H = R_x(θ)`** at the gate level: since `H Z H = X`, +conjugating a `z`-rotation by the Hadamard gate turns it into the corresponding `x`-rotation. The +gate-level image of `Concrete.hadamardC_mul_rotZ_mul_hadamardC`. It converts the controlled-`R_z` +construction into a controlled-`R_x` construction (N&C Exercise 4.23). -/ +theorem hadamardGate_comp_rotZGate_comp_hadamardGate (θ : ℝ) : + hadamardGate.comp ((rotZGate θ).comp hadamardGate) = rotXGate θ := by + apply Evolution.ext + simp only [Evolution.comp_op, hadamardGate_op, rotZGate_op, rotXGate_op] + rw [← Concrete.hadamardC_mul_rotZ_mul_hadamardC θ, map_mul, map_mul, mul_assoc] + rfl + +/-- **The reduced controlled-`R_z` construction** (the `R_z` analogue of +`controlledUnitary_rotYGate`, N&C Exercise 4.23): +`C(R_z(θ)) = (1 ⊗ R_z(θ/2)) · CNOT · (1 ⊗ R_z(-θ/2)) · CNOT`, using two single-qubit gates and two +`CNOT`s (`R_z`, like `R_y`, has its axis perpendicular to `X`). Obtained by instantiating +`controlledUnitary_cnot_conj_cnot` at `V = R_z(θ/2)`, `W = R_z(-θ/2)` and collapsing +`R_z(θ/2) · X · R_z(-θ/2) · X` to `R_z(θ)`. This is the helper behind the controlled-`R_x` +construction. -/ +theorem controlledUnitary_rotZGate (θ : ℝ) : + controlledUnitary (rotZGate θ) + = (((rotZGate (θ / 2)).onRight qubit).comp cnotGate).comp + (((rotZGate (-(θ / 2))).onRight qubit).comp cnotGate) := by + have hVW : (rotZGate (θ / 2)).comp (rotZGate (-(θ / 2))) = Evolution.id := by + rw [rotZGate_comp, add_neg_cancel, rotZGate_zero] + rw [controlledUnitary_cnot_conj_cnot (rotZGate (θ / 2)) (rotZGate (-(θ / 2))) hVW] + congr 1 + rw [pauliXGate_comp_rotZGate_comp_pauliXGate, neg_neg, rotZGate_comp, add_halves] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledUnitary.lean b/LeanPool/AxQM/Postulates/API/ControlledUnitary.lean new file mode 100644 index 0000000000..53cf2f8959 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledUnitary.lean @@ -0,0 +1,364 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Postulates.API.BellReducedState +public import LeanPool.AxQM.Concrete.Pauli + +/-! +# AxQM.Postulates.API — the controlled-`U` gate and CNOT + +Nielsen & Chuang's controlled operations (N&C §4.3): the single-qubit-controlled unitary `C(U)` +and, as its canonical instance, the controlled-`NOT` gate. It is reused throughout Chapter 4 (and +by Problem 4.6's gate-teleportation formalisation). + +## What is formalised + +* `pauliXGate` — the Pauli-`X` (quantum `NOT`) gate as an `Evolution qubit`, obtained by promoting + the concrete matrix `Concrete.pauliX` through `Matrix.toEuclideanCLM`; unitarity is transported + from `Concrete.pauliX_mem_unitaryGroup` (N&C Exercise 2.19). +* `pauliXGate_evolvePure_qubitBasis` — the bit flip `X|i⟩ = |i ⊕ 1⟩` (`i + 1` in `Fin 2`). +* `controlledUnitary U` — the **controlled-`U` operation** `C(U) = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` + on `qubit ⊗ S` (control qubit on the left, target system `S` arbitrary), N&C eq. (4.24). This is + a genuine `Evolution` (Postulate 5): the unitarity obligation is exactly the statement that the + block-diagonal operator is unitary, discharged in `controlledUnitary_op_mem_unitary`. +* `controlledUnitary_evolvePure_ketZero` / `controlledUnitary_evolvePure_ketOne` — the **defining + action**: with control `|0⟩` the target is untouched, with control `|1⟩` the gate `U` is applied + to the target, i.e. `C(U)(|0⟩⊗ψ) = |0⟩⊗ψ` and `C(U)(|1⟩⊗ψ) = |1⟩⊗Uψ`. +* `controlledUnitary_onRight_conj` — **conjugating the target** of `C(U)` by local gates `V`, `W` + on the target factor (with `V W = 1`) conjugates the controlled unitary: + `(1 ⊗ V) · C(U) · (1 ⊗ W) = C(V U W)`. The general circuit identity behind building one controlled + gate from another (e.g. `CNOT` from a controlled-`Z` and two Hadamards, N&C Exercise 4.17). +* `cnotGate = controlledUnitary pauliXGate` — the **controlled-`NOT`** gate on `qubit ⊗ qubit`. +* `cnotGate_evolvePure_qubitBasis` — N&C's CNOT truth table `|c, t⟩ ↦ |c, t ⊕ c⟩` (with `⊕` the + `Fin 2` addition `t + c`), together with its two control-branch specialisations. + +## Design notes + +* **Generality / N&C fidelity.** `controlledUnitary` is the general controlled operation `C(U)` + for an *arbitrary* target system `S` (N&C §4.3), not just a two-qubit gate; `cnotGate` is the + `U = X` instance. This matches N&C, which introduces CNOT (§1.3.2) and then generalises to + controlled-`U`, and makes the construction reusable for every later controlled gate. CNOT's + truth table is a *corollary* of the controlled action composed with the bit flip `X|t⟩ = |t⊕1⟩`; + the definition is faithful because `pauliXGate` *is* the `NOT` gate. +* **Construction.** `C(U)` is the operator sum `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` built from the rank-one + computational-basis projectors and `TensorProduct.mapL`. Unitarity is a one-shot operator + computation: `C(U)† C(U) = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U†U = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ I = I` (the cross + terms vanish because `|0⟩⟨0|` and `|1⟩⟨1|` are orthogonal, `⟨0|1⟩ = 0`, and `|0⟩⟨0| + |1⟩⟨1| = I` + by `sum_rankOne_qubitBasis_eq_one`), and symmetrically for `C(U) C(U)†` using `UU† = I`. +* **Type heads.** The composite `(qubit ⊗ S).space` and the raw `qubit.space ⊗[ℂ] S.space` are + definitionally equal but present different heads, so `star`/`adjoint` and `rw` do not match across + them. `controlledUnitary_op_mem_unitary` is therefore stated and proved entirely at the raw + tensor head; it slots into the `Evolution` `unitary` field by defeq. The action lemmas restate the + applied operator at the raw head via `show` before firing `TensorProduct.mapL_tmul`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The Pauli-`X` (`NOT`) gate -/ + +/-- The **Pauli-`X` gate** `X` (the quantum `NOT`) as a closed-system `Evolution` of the qubit: +its operator is the concrete matrix `Concrete.pauliX = !![0,1;1,0]` promoted to a continuous linear +map via `Matrix.toEuclideanCLM`, with unitarity (the `Evolution` obligation, N&C Exercise 2.19) +transported from `Concrete.pauliX_mem_unitaryGroup`. -/ +def pauliXGate : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) Concrete.pauliX_mem_unitaryGroup + +/-- The underlying operator of `pauliXGate` is `Matrix.toEuclideanCLM Concrete.pauliX`. -/ +@[simp] +theorem pauliXGate_op : + pauliXGate.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX := rfl + +/-- **The Pauli-`X` gate flips the computational basis:** `X|i⟩ = |i ⊕ 1⟩`, i.e. +`pauliXGate` sends `|i⟩` to `|i + 1⟩` (addition in `Fin 2`). This is the `NOT` truth table; it is +the reason `cnotGate` implements the controlled-`NOT`. -/ +theorem pauliXGate_evolvePure_qubitBasis (i : Fin 2) : + pauliXGate.evolvePure (qubitBasis i) = qubitBasis (i + 1) := by + apply PureState.ext + rw [Evolution.evolvePure_vec, pauliXGate_op, qubitBasis_vec, qubitBasis_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX) + (EuclideanSpace.single i 1)).ofLp + = (EuclideanSpace.single (i + 1) 1 : EuclideanSpace ℂ (Fin 2)).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliX, Matrix.mulVec, dotProduct, EuclideanSpace.single] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-! ### Computational-basis rank-one projectors -/ + +/-- The computational-basis rank-one projectors are **idempotent**: `|i⟩⟨i| · |i⟩⟨i| = |i⟩⟨i|` +(from `⟨i|i⟩ = 1`). Shared building block for the block-diagonal algebra of `controlledUnitary`. -/ +theorem rankOne_qubitBasis_comp_self (i : Fin 2) : + (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec).comp + (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec) + = InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec := by + rw [InnerProductSpace.rankOne_comp_rankOne, qubitBasis_inner_qubitBasis]; simp + +/-- The computational-basis rank-one projectors are **orthogonal**: `|i⟩⟨i| · |j⟩⟨j| = 0` for +`i ≠ j` (from `⟨i|j⟩ = 0`). Shared building block for the block-diagonal algebra of +`controlledUnitary`. -/ +theorem rankOne_qubitBasis_comp_orthogonal {i j : Fin 2} (hij : i ≠ j) : + (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec).comp + (InnerProductSpace.rankOne ℂ (qubitBasis j).vec (qubitBasis j).vec) = 0 := by + rw [InnerProductSpace.rankOne_comp_rankOne, qubitBasis_inner_qubitBasis]; simp [hij] + +/-- The identity operator composed with itself is the identity, `1 ∘ 1 = 1` (the `Evolution`-target +`I·I = I` step in the controlled-`U` block algebra). -/ +theorem one_comp_one : (1 : S.space →L[ℂ] S.space).comp (1 : S.space →L[ℂ] S.space) = 1 := by + rw [← ContinuousLinearMap.mul_def, mul_one] + +/-! ### The controlled-`U` gate -/ + +/-- **The controlled-`U` operator is unitary** (N&C §4.3). For a single-qubit-controlled unitary, +the block-diagonal operator `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` on `qubit.space ⊗ S.space` lies in the +unitary group: `C(U)† C(U) = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U†U = I` (the cross terms drop by orthogonality +`⟨0|1⟩ = 0`, and `|0⟩⟨0| + |1⟩⟨1| = I`), and symmetrically `C(U) C(U)† = I`. + +Stated at the raw tensor head `qubit.space ⊗[ℂ] S.space` (where `star`/`adjoint` present a single +head); it discharges the `unitary` obligation of `controlledUnitary` by definitional equality with +`(qubit ⊗ S).space`. -/ +theorem controlledUnitary_op_mem_unitary (U : Evolution S) : + (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) U.op) + ∈ unitary (qubit.space ⊗[ℂ] S.space →L[ℂ] qubit.space ⊗[ℂ] S.space) := by + set p0 := InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec with hp0 + set p1 := InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec with hp1 + -- rank-one projector composition: `|i⟩⟨i| |j⟩⟨j| = δ_{ij} |i⟩⟨i|` (shared projector lemmas) + have h00 : p0.comp p0 = p0 := by rw [hp0]; exact rankOne_qubitBasis_comp_self 0 + have h11 : p1.comp p1 = p1 := by rw [hp1]; exact rankOne_qubitBasis_comp_self 1 + have h01 : p0.comp p1 = 0 := by + rw [hp0, hp1]; exact rankOne_qubitBasis_comp_orthogonal (by decide) + have h10 : p1.comp p0 = 0 := by + rw [hp0, hp1]; exact rankOne_qubitBasis_comp_orthogonal (by decide) + -- the projectors are self-adjoint and resolve the identity + have hadj0 : adjoint p0 = p0 := by rw [hp0, InnerProductSpace.adjoint_rankOne] + have hadj1 : adjoint p1 = p1 := by rw [hp1, InnerProductSpace.adjoint_rankOne] + have hadjone : adjoint (1 : S.space →L[ℂ] S.space) = 1 := by + rw [← ContinuousLinearMap.star_eq_adjoint, star_one] + have hsum : p0 + p1 = 1 := by + rw [hp0, hp1]; have := sum_rankOne_qubitBasis_eq_one; rwa [Fin.sum_univ_two] at this + -- unitarity of the target gate `U` + have hUU : (adjoint U.op).comp U.op = 1 := U.adjoint_comp_self + have hUUr : U.op.comp (adjoint U.op) = 1 := U.comp_adjoint_self + have hadjop : adjoint (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL p1 U.op) + = TensorProduct.mapL p0 1 + TensorProduct.mapL p1 (adjoint U.op) := by + simp only [map_add, TensorProduct.adjoint_mapL, hadj0, hadj1, hadjone] + refine Unitary.mem_iff.mpr ⟨?_, ?_⟩ + · rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def, hadjop, + comp_add, add_comp, add_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, h00, h01, h10, h11, hUU, one_comp_one, + TensorProduct.mapL_zero_left, TensorProduct.mapL_zero_left, add_zero, zero_add, + ← TensorProduct.mapL_add_left, hsum, TensorProduct.mapL_one] + · rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def, hadjop, + comp_add, add_comp, add_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, h00, h01, h10, h11, hUUr, one_comp_one, + TensorProduct.mapL_zero_left, TensorProduct.mapL_zero_left, add_zero, zero_add, + ← TensorProduct.mapL_add_left, hsum, TensorProduct.mapL_one] + +/-- **The controlled-`U` gate** `C(U)` (Nielsen & Chuang §4.3, eq. 4.24): the `Evolution` on the +composite `qubit ⊗ S` whose operator is `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` — the identity on the target when +the control qubit is `|0⟩`, and the unitary `U` on the target when it is `|1⟩`. Unitarity (the +`Evolution` obligation) is `controlledUnitary_op_mem_unitary`. -/ +def controlledUnitary (U : Evolution S) : Evolution (qubit ⊗ S) where + op := TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) U.op + unitary := controlledUnitary_op_mem_unitary U + +/-- The underlying operator of `controlledUnitary U` is `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U`. -/ +@[simp] +theorem controlledUnitary_op (U : Evolution S) : + (controlledUnitary U).op + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op := rfl + +/-- **Controlled-`U`, control `|0⟩`:** the target is untouched, `C(U)(|0⟩ ⊗ ψ) = |0⟩ ⊗ ψ`. -/ +theorem controlledUnitary_evolvePure_ketZero (U : Evolution S) (ψ : PureState S) : + (controlledUnitary U).evolvePure ((qubitBasis 0) ⊗ ψ) = (qubitBasis 0) ⊗ ψ := by + apply PureState.ext + rw [Evolution.evolvePure_vec, PureState.tmul_vec] + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) U.op) + ((qubitBasis 0).vec ⊗ₜ[ℂ] ψ.vec) = (qubitBasis 0).vec ⊗ₜ[ℂ] ψ.vec + rw [_root_.add_apply, TensorProduct.mapL_tmul, TensorProduct.mapL_tmul, + InnerProductSpace.rankOne_apply, InnerProductSpace.rankOne_apply, + qubitBasis_inner_qubitBasis, qubitBasis_inner_qubitBasis, one_apply_eq_self, + ite_eq_left rfl, ite_eq_right (by + decide), one_smul, zero_smul, TensorProduct.zero_tmul, add_zero] + +/-- **Controlled-`U`, control `|1⟩`:** the gate `U` is applied to the target, +`C(U)(|1⟩ ⊗ ψ) = |1⟩ ⊗ Uψ`. -/ +theorem controlledUnitary_evolvePure_ketOne (U : Evolution S) (ψ : PureState S) : + (controlledUnitary U).evolvePure ((qubitBasis 1) ⊗ ψ) = (qubitBasis 1) ⊗ (U.evolvePure ψ) := by + apply PureState.ext + rw [Evolution.evolvePure_vec, PureState.tmul_vec, PureState.tmul_vec, Evolution.evolvePure_vec] + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) U.op) + ((qubitBasis 1).vec ⊗ₜ[ℂ] ψ.vec) = (qubitBasis 1).vec ⊗ₜ[ℂ] U.op ψ.vec + rw [_root_.add_apply, TensorProduct.mapL_tmul, TensorProduct.mapL_tmul, + InnerProductSpace.rankOne_apply, InnerProductSpace.rankOne_apply, + qubitBasis_inner_qubitBasis, qubitBasis_inner_qubitBasis, one_apply_eq_self, + ite_eq_right (by + decide), ite_eq_left rfl, zero_smul, one_smul, TensorProduct.zero_tmul, zero_add] + +/-! ### Conjugating the target of a controlled gate -/ + +/-- **Conjugating the target of a controlled-`U` gate conjugates `U`.** Sandwiching `C(U)` between +`1 ⊗ V` on the left and `1 ⊗ W` on the right (gates acting on the *target* factor `S`, the control +qubit untouched) — with `V W = 1`, i.e. `W = V⁻¹` — turns `C(U)` into `C(V U W)`: +`(1 ⊗ V) · C(U) · (1 ⊗ W) = C(V U W)`. + +The control branch `|0⟩⟨0| ⊗ I` becomes `|0⟩⟨0| ⊗ (V W) = |0⟩⟨0| ⊗ I` (this is where `V W = 1` is +used), and the active branch `|1⟩⟨1| ⊗ U` becomes `|1⟩⟨1| ⊗ (V U W)`. This is the general circuit +identity behind building one controlled gate from another by conjugating the target with local +gates — e.g. `CNOT` from a controlled-`Z` and two Hadamards (N&C Exercise 4.17), where `V = W = H` +and `H Z H = X`. + +Proved by cracking to operators at the raw tensor head (`show`), where `1 ⊗ V = TensorProduct.mapL +1 V.op` etc., and running the `TensorProduct.mapL` composition algebra (`mapL_comp`, distributing +over the block sum); `V.op ∘ W.op = 1` collapses the `|0⟩` branch. -/ +theorem controlledUnitary_onRight_conj (U V W : Evolution S) (h : V.comp W = Evolution.id) : + (Evolution.onRight V qubit).comp + ((controlledUnitary U).comp (Evolution.onRight W qubit)) + = controlledUnitary (V.comp (U.comp W)) := by + have hVW : V.op.comp W.op = 1 := by rw [← Evolution.comp_op, h, Evolution.id_op] + have e1 : (Evolution.onRight V qubit).op = TensorProduct.mapL 1 V.op := by + unfold Evolution.onRight + rw [Evolution.tmul_op, Evolution.id_op] + have e2 : (Evolution.onRight W qubit).op = TensorProduct.mapL 1 W.op := by + unfold Evolution.onRight + rw [Evolution.tmul_op, Evolution.id_op] + -- The generic-tensor algebra, entirely at the raw head `qubit.space ⊗[ℂ] S.space`, where the + -- `mapL` composition algebra applies (the composite head would block the `mapL` rewrites by + -- presenting a different, defeq, `.comp`). + have goalGeneric : (TensorProduct.mapL 1 V.op).comp + ((TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op).comp (TensorProduct.mapL 1 W.op)) + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + (V.op.comp (U.op.comp W.op)) := by + set p0 := InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec + set p1 := InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec + rw [ContinuousLinearMap.add_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ContinuousLinearMap.comp_add, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + ContinuousLinearMap.comp_id, hVW] + apply Evolution.ext + rw [Evolution.comp_op, Evolution.comp_op, e1, e2, controlledUnitary_op, controlledUnitary_op] + exact goalGeneric + +/-- **Controlled gates compose by composing their targets:** `C(U) · C(V) = C(U · V)`. Both are +block-diagonal — `C(U) = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` and likewise for `V` — so their product multiplies +out to `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ (U · V)`: the `|0⟩`/`|1⟩` cross terms drop by orthogonality of the +computational-basis projectors (`⟨0|1⟩ = 0`) and `|0⟩⟨0|² = |0⟩⟨0|`, `|1⟩⟨1|² = |1⟩⟨1|`. This is the +key algebra of the controlled-`U` construction: stacking two controlled gates sharing the control is +the controlled gate of the composite target — used, e.g., to append a `CNOT` to a partially built +controlled rotation (N&C Exercise 4.23). + +Proved by cracking to operators at the raw tensor head `qubit.space ⊗[ℂ] S.space` (`change`, as in +`controlledUnitary_op_mem_unitary` — the composite head would block the `mapL` rewrites) and running +the `TensorProduct.mapL` composition algebra (`mapL_comp` distributing over the block sum), with the +projector products `p₀ ∘ p₀ = p₀`, `p₀ ∘ p₁ = 0`, `p₁ ∘ p₀ = 0`, `p₁ ∘ p₁ = p₁` collapsing the +diagonal. -/ +theorem controlledUnitary_comp (U V : Evolution S) : + (controlledUnitary U).comp (controlledUnitary V) = controlledUnitary (U.comp V) := by + apply Evolution.ext + set p0 := InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec with hp0 + set p1 := InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec with hp1 + have h00 : p0.comp p0 = p0 := by rw [hp0]; exact rankOne_qubitBasis_comp_self 0 + have h11 : p1.comp p1 = p1 := by rw [hp1]; exact rankOne_qubitBasis_comp_self 1 + have h01 : p0.comp p1 = 0 := by + rw [hp0, hp1]; exact rankOne_qubitBasis_comp_orthogonal (by decide) + have h10 : p1.comp p0 = 0 := by + rw [hp0, hp1]; exact rankOne_qubitBasis_comp_orthogonal (by decide) + change (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 U.op).comp + (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 V.op) + = TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 (U.op.comp V.op) + rw [ContinuousLinearMap.add_comp, ContinuousLinearMap.comp_add, ContinuousLinearMap.comp_add, + ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ← TensorProduct.mapL_comp, h00, h01, h10, h11, one_comp_one, TensorProduct.mapL_zero_left, + TensorProduct.mapL_zero_left, add_zero, zero_add] + +/-! ### The controlled-`NOT` gate -/ + +/-- **The controlled-`NOT` (CNOT) gate** on two qubits (Nielsen & Chuang §1.3.2), the controlled-`U` +gate with `U = X`: it flips the target qubit exactly when the control qubit is `|1⟩`. -/ +def cnotGate : Evolution (qubit ⊗ qubit) := controlledUnitary pauliXGate + +/-- `cnotGate` is definitionally the controlled-`X` gate: `CNOT = C(X)`. The citable unfolding used +whenever a `CNOT` needs to be handled through the general `controlledUnitary` API. -/ +theorem cnotGate_def : cnotGate = controlledUnitary pauliXGate := rfl + +/-- **CNOT, control `|0⟩`:** the target is untouched, `CNOT(|0⟩ ⊗ |t⟩) = |0⟩ ⊗ |t⟩`. -/ +theorem cnotGate_evolvePure_ketZero (t : Fin 2) : + cnotGate.evolvePure ((qubitBasis 0) ⊗ (qubitBasis t)) = (qubitBasis 0) ⊗ (qubitBasis t) := + controlledUnitary_evolvePure_ketZero pauliXGate (qubitBasis t) + +/-- **CNOT, control `|1⟩`:** the target is flipped, `CNOT(|1⟩ ⊗ |t⟩) = |1⟩ ⊗ |t ⊕ 1⟩`. -/ +theorem cnotGate_evolvePure_ketOne (t : Fin 2) : + cnotGate.evolvePure ((qubitBasis 1) ⊗ (qubitBasis t)) + = (qubitBasis 1) ⊗ (qubitBasis (t + 1)) := by + rw [cnotGate, controlledUnitary_evolvePure_ketOne, pauliXGate_evolvePure_qubitBasis] + +/-- **The CNOT truth table** (Nielsen & Chuang §1.3.2): `CNOT|c, t⟩ = |c, t ⊕ c⟩`, where `⊕` is +addition in `Fin 2` (`t + c`). The control qubit is unchanged and the target is XORed with the +control. -/ +theorem cnotGate_evolvePure_qubitBasis (c t : Fin 2) : + cnotGate.evolvePure ((qubitBasis c) ⊗ (qubitBasis t)) + = (qubitBasis c) ⊗ (qubitBasis (t + c)) := by + fin_cases c + · simpa using cnotGate_evolvePure_ketZero t + · simpa using cnotGate_evolvePure_ketOne t + +/-- **The two-`CNOT`, two-single-qubit-gate controlled construction** (Nielsen & Chuang §4.3, +Exercise 4.23). For target-qubit gates `V`, `W` with `V · W = I`, sandwiching two `CNOT`s between +them realises a controlled gate whose target is `V X W X`: +`(1 ⊗ V) · CNOT · (1 ⊗ W) · CNOT = C(V · X · W · X)`, +with the two `X` gates supplied by the `CNOT`s (conditioned on the control) and only `V`, `W` +applied unconditionally. This is the reduced Figure-4.6 circuit with `C = I`: when the target `U` +of a controlled-`U` factors as `U = V X W X` with `V W = I` (so `V`, `W` are the only single-qubit +gates), `C(U)` needs just these **two** single-qubit gates — the `3 → 2` reduction the exercise asks +for. It applies to `U = R_y(θ)` and `U = R_z(θ)` (`V = R_a(θ/2)`, `W = R_a(-θ/2)`), whose axes are +perpendicular to `X`; it does *not* apply to `R_x` (which commutes with `X`). + +Derived, not recomputed: reassociating to `((1 ⊗ V) · (CNOT · (1 ⊗ W))) · CNOT`, the bracket is +`controlledUnitary_onRight_conj` at `U = X` (using `V · W = I`), giving `C(V X W)`, and the trailing +`CNOT = C(X)` is absorbed by `controlledUnitary_comp` into `C(V X W · X)`. -/ +theorem controlledUnitary_cnot_conj_cnot (V W : Evolution qubit) (h : V.comp W = Evolution.id) : + ((V.onRight qubit).comp cnotGate).comp ((W.onRight qubit).comp cnotGate) + = controlledUnitary (V.comp (pauliXGate.comp (W.comp pauliXGate))) := by + rw [Evolution.comp_assoc, ← Evolution.comp_assoc cnotGate (W.onRight qubit) cnotGate, + ← Evolution.comp_assoc (V.onRight qubit) (cnotGate.comp (W.onRight qubit)) cnotGate, + cnotGate_def, controlledUnitary_onRight_conj pauliXGate V W h, controlledUnitary_comp, + Evolution.comp_assoc, Evolution.comp_assoc] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledUnitaryDecomposition.lean b/LeanPool/AxQM/Postulates/API/ControlledUnitaryDecomposition.lean new file mode 100644 index 0000000000..44049ee35a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledUnitaryDecomposition.lean @@ -0,0 +1,234 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Concrete.ABCDecomposition + +/-! +# AxQM.Postulates.API — Figure 4.6: controlled-`U` from single-qubit gates and two CNOTs + +Nielsen & Chuang's **controlled-operation gate count** (N&C §4.3, Figure 4.6): a +single-qubit-controlled gate `C(U)` is built from *unconditional* single-qubit gates and exactly +**two** CNOTs, using the ABC decomposition of `U` (Corollary 4.2). This is the fact that one +controlled-single-qubit gate costs two CNOTs, on which the gate counting of Exercise 4.22 (`C²(U)` +from ≤ 8 one-qubit gates and 6 CNOTs) rests, and it is reused by the other controlled-gate +constructions of Chapter 4 (Exercises 4.23, 4.28). + +## What is formalised + +* `phaseShiftGate α` — the **single-qubit phase-shift gate** `P(α) = diag(1, e^{iα})`, the general + relative-phase gate (`S = P(π/2)`, `T = P(π/4)` are special cases), as an `Evolution qubit`. + `phaseShiftGate_op`, `phaseShiftGate_op_apply_qubitBasis` (`P(α)|i⟩ = [1, e^{iα}]ᵢ |i⟩`) and + `phaseShiftGate_evolvePure_qubitBasis_zero` (`P(α)|0⟩ = |0⟩`) record its action. +* `twoQubit_evolution_ext` — **computational-basis extensionality** for two-qubit gates: two + evolutions of `qubit ⊗ qubit` are equal as soon as they agree on the four basis states + `|q₁⟩ ⊗ |q₂⟩`. The two-qubit analogue of `threeQubit_evolution_ext`. +* `controlledUnitary_eq_abc_cnot_circuit` — **Figure 4.6:** for every single-qubit gate `U` there + exist single-qubit gates `A, B, C` and a phase `α` with `A B C = 1` such that + `C(U) = (P(α) ⊗ 1) · (1 ⊗ A) · CNOT · (1 ⊗ B) · CNOT · (1 ⊗ C)`, i.e. `C(U)` is implemented by the + phase-shift gate on the control, the three unconditional single-qubit gates `A, B, C` on the + target, and two CNOTs. So a controlled-single-qubit gate needs **four one-qubit gates and two + CNOTs**. + +## Design notes + +* **Statement shape.** The theorem is the faithful "for *any* single-qubit `U`" form (N&C states + Figure 4.6 for an arbitrary single-qubit unitary): `A, B, C, α` are existentially quantified and + produced from the genuine ABC decomposition of `U` (`Concrete.exists_abc_decomposition`, Corollary + 4.2), with `A B C = 1` the honest witness condition, and it is a full equality of the gate + `Evolution`s (holding on every input), not an on-basis-states or up-to-phase surrogate. The + **relative** phase gate `P(α)` sits on the control (not folded into `A` as a global phase on the + target): a global phase absorbed into `A` would break the `|0⟩`-control branch (`P(α) A B C ≠ A B + C = 1`), so the controlled phase is essential — it is exactly why `C(U)` needs a phase gate that + `U` alone does not. +* **The phase-shift gate.** `phaseShiftGate α` is built directly as the computational-basis + diagonal operator `diag(1, e^{iα})` (`OrthonormalBasis.diagonalOperator`), unitary because both + diagonal entries have unit modulus, mirroring `diagPhase`; its action on `|i⟩` then comes for free + from `basisFun_diagonalOperator_apply_single`. +* **Proof.** `twoQubit_evolution_ext` reduces the equality to the four basis inputs `|q₁⟩ ⊗ |q₂⟩`; + casework on the control `q₁` (`fin_cases`) drives the factorwise gate actions + (`Evolution.onLeft/onRight_evolvePure`, `controlledUnitary_evolvePure_ketZero/ketOne`). Control + `|0⟩`: all CNOTs idle and `P(α)|0⟩ = |0⟩`, so the target sees `A B C = 1` (the ABC identity, + transported to gates through `Matrix.toEuclideanCLM`'s `map_mul`). Control `|1⟩`: the CNOTs act as + `X`, the target sees `A X B X C` and `P(α)|1⟩ = e^{iα}|1⟩`, matching `U = e^{iα}(A X B X C)` + (the ABC decomposition through `toEuclideanCLM`) once the control's relative phase is pushed into + the target factor (`TensorProduct.tmul_smul`/`smul_tmul'`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap Matrix + +noncomputable section + +namespace AxQM + +/-! ### The single-qubit phase-shift gate `P(α) = diag(1, e^{iα})` -/ + +/-- **The phase-shift gate** `P(α) = diag(1, e^{iα})` as a closed-system `Evolution` of the qubit: +the operator diagonal in the computational basis with entries `1` on `|0⟩` and `e^{iα}` on `|1⟩`. +It is unitary because both entries have unit modulus. This is the general relative-phase gate +(N&C §4.2), with the `S` gate `P(π/2) = diag(1, i)` and the `T` gate `P(π/4) = diag(1, e^{iπ/4})` as +special cases; it is the phase gate placed on the control qubit in Figure 4.6's controlled-`U` +construction. -/ +def phaseShiftGate (α : ℝ) : Evolution qubit where + op := (EuclideanSpace.basisFun (Fin 2) ℂ).diagonalOperator + (fun i => ![(1 : ℂ), Complex.exp ((α : ℂ) * Complex.I)] i) + unitary := by + refine OrthonormalBasis.diagonalOperator_mem_unitary _ _ (fun i => ?_) + fin_cases i <;> simp [Complex.norm_exp] + +/-- The underlying operator of `phaseShiftGate α` is the computational-basis diagonal operator +with entries `[1, e^{iα}]`. -/ +theorem phaseShiftGate_op (α : ℝ) : + (phaseShiftGate α).op = (EuclideanSpace.basisFun (Fin 2) ℂ).diagonalOperator + (fun i => ![(1 : ℂ), Complex.exp ((α : ℂ) * Complex.I)] i) := rfl + +/-- **Eigenvalue action of the phase-shift gate:** `P(α)|i⟩ = [1, e^{iα}]ᵢ |i⟩`, i.e. `P(α)` fixes +`|0⟩` and multiplies `|1⟩` by `e^{iα}`. -/ +theorem phaseShiftGate_op_apply_qubitBasis (α : ℝ) (i : Fin 2) : + (phaseShiftGate α).op (qubitBasis i).vec + = ![(1 : ℂ), Complex.exp ((α : ℂ) * Complex.I)] i • (qubitBasis i).vec := by + rw [qubitBasis_vec, phaseShiftGate_op] + exact basisFun_diagonalOperator_apply_single _ i + +/-- **The phase-shift gate's diagonal basis action as a phase power:** +`P(α)|j⟩ = (e^{iα})^j |j⟩`, i.e. `P(α)` fixes `|0⟩` and multiplies `|1⟩` by `e^{iα}`, written as the +`j`-th power of `e^{iα}` (`(e^{iα})^0 = 1`, `(e^{iα})^1 = e^{iα}`). The `evolvePure`/`.vec`-level +restatement of `phaseShiftGate_op_apply_qubitBasis` with the diagonal entry `![1, e^{iα}]ⱼ` folded +into `(e^{iα})^{j}` — the form in which the phase gate composes across the wires of a phase-gradient +layer (the exponents adding). The `Fin 2`-general companion of +`phaseShiftGate_evolvePure_qubitBasis_zero` (its `j = 0` case), and the diagonal analogue of +`rotZGate_evolvePure_qubitBasis_sum`. -/ +theorem phaseShiftGate_evolvePure_qubitBasis (α : ℝ) (j : Fin 2) : + ((phaseShiftGate α).evolvePure (qubitBasis j)).vec + = Complex.exp ((α : ℂ) * Complex.I) ^ (j : ℕ) • (qubitBasis j).vec := by + rw [Evolution.evolvePure_vec, phaseShiftGate_op_apply_qubitBasis] + fin_cases j <;> simp + +/-- **The phase-shift gate fixes `|0⟩`:** `P(α)|0⟩ = |0⟩`, the `|0⟩`-branch of the phase gate's +action (the control-`|0⟩` case of Figure 4.6, where no relative phase is applied). -/ +theorem phaseShiftGate_evolvePure_qubitBasis_zero (α : ℝ) : + (phaseShiftGate α).evolvePure (qubitBasis 0) = qubitBasis 0 := by + apply PureState.ext + rw [Evolution.evolvePure_vec, phaseShiftGate_op_apply_qubitBasis] + simp only [Nat.succ_eq_add_one, Nat.reduceAdd, Fin.isValue, cons_val_zero, qubitBasis_vec] + erw [one_smul] + +/-! ### Computational-basis extensionality for two-qubit gates -/ + +/-- **A two-qubit gate is determined by its action on the computational basis.** Two evolutions +`A`, `B` of `qubit ⊗ qubit` are equal as soon as they agree on every computational-basis state +`|q₁⟩ ⊗ |q₂⟩`, `qᵢ ∈ {0, 1}`. The two-qubit analogue of `threeQubit_evolution_ext`: it reduces a +case-by-case verification of a two-qubit circuit on the four basis inputs to a genuine equality of +unitary gates. + +The proof reduces to operator equality (`Evolution.ext`), then linear-map equality +(`ContinuousLinearMap.coe_injective`), and applies `Module.Basis.ext` to the tensor-product basis +built from `EuclideanSpace.basisFun` by `OrthonormalBasis.tensorProduct`, whose basis vectors are +the computational-basis unit vectors `(qubitBasis _).vec`; the hypothesis supplies the required +agreement after unfolding `evolvePure_vec` and `PureState.tmul_vec`. -/ +theorem twoQubit_evolution_ext {A B : Evolution (qubit ⊗ qubit)} + (h : ∀ q1 q2 : Fin 2, + A.evolvePure ((qubitBasis q1) ⊗ (qubitBasis q2)) + = B.evolvePure ((qubitBasis q1) ⊗ (qubitBasis q2))) : + A = B := by + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + let bq : OrthonormalBasis (Fin 2) ℂ qubit.space := EuclideanSpace.basisFun (Fin 2) ℂ + have hbq : ∀ i : Fin 2, bq i = (qubitBasis i).vec := fun i => by + rw [qubitBasis_vec]; exact EuclideanSpace.basisFun_apply (Fin 2) ℂ i + refine Module.Basis.ext (bq.tensorProduct bq).toBasis ?_ + rintro ⟨q1, q2⟩ + have hb : (bq.tensorProduct bq).toBasis (q1, q2) + = (qubitBasis q1).vec ⊗ₜ[ℂ] (qubitBasis q2).vec := by + rw [OrthonormalBasis.coe_toBasis, OrthonormalBasis.tensorProduct_apply, hbq, hbq] + rw [hb] + have hh := congrArg PureState.vec (h q1 q2) + simp only [Evolution.evolvePure_vec, PureState.tmul_vec] at hh + exact hh + +/-! ### Figure 4.6: `C(U)` from `A, B, C`, a phase gate, and two CNOTs -/ + +/-- **Nielsen & Chuang, Figure 4.6: the controlled-`U` gate from single-qubit gates and two CNOTs.** +For every single-qubit gate `U` there exist single-qubit gates `A, B, C` and a real phase `α` with +`A B C = 1` such that the controlled-`U` gate factors as +`C(U) = (P(α) ⊗ 1) · (1 ⊗ A) · CNOT · (1 ⊗ B) · CNOT · (1 ⊗ C)`, +the phase-shift gate `P(α)` on the control, the three unconditional single-qubit gates `A, B, C` +on the target, and two CNOTs. Hence a single-controlled single-qubit gate is built from four +one-qubit gates and two CNOTs — the count used in Exercise 4.22. + +The witnesses `A, B, C, α` are the genuine ABC decomposition of `U` (Corollary 4.2, +`Concrete.exists_abc_decomposition`): `A B C = 1` and `U = e^{iα}(A X B X C)`. Proved by two-qubit +computational-basis extensionality (`twoQubit_evolution_ext`) with casework on the control: control +`|0⟩` gives `A B C = 1` on the target (CNOTs idle, no phase); control `|1⟩` gives `e^{iα} A X B X C += U` on the target (CNOTs act as `X`, `P(α)|1⟩ = e^{iα}|1⟩`). -/ +theorem controlledUnitary_eq_abc_cnot_circuit (U : Evolution qubit) : + ∃ (A B C : Evolution qubit) (α : ℝ), + (A.comp B).comp C = 1 ∧ + controlledUnitary U = + ((phaseShiftGate α).onLeft qubit).comp + ((A.onRight qubit).comp + (cnotGate.comp + ((B.onRight qubit).comp + (cnotGate.comp (C.onRight qubit))))) := by + set clm := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) with hclm + -- The ABC decomposition of `U`'s matrix (Corollary 4.2): `A B C = 1`, `U = e^{iα}(A X B X C)`. + obtain ⟨α, Am, Bm, Cm, hAm, hBm, hCm, hABCm, hUm⟩ := + Concrete.exists_abc_decomposition (clm.symm U.op) (Unitary.map_mem clm.symm U.unitary) + -- Lift the matrix witnesses `A, B, C` to single-qubit gates through `toEuclideanCLM`. + set A : Evolution qubit := ⟨clm Am, Unitary.map_mem clm hAm⟩ with hA + set B : Evolution qubit := ⟨clm Bm, Unitary.map_mem clm hBm⟩ with hB + set C : Evolution qubit := ⟨clm Cm, Unitary.map_mem clm hCm⟩ with hC + -- `A B C = 1` at the gate level (`toEuclideanCLM` carries matrix product to composition). + have hABC : (A.comp B).comp C = 1 := by + apply Evolution.ext + rw [Evolution.comp_op, Evolution.comp_op] + change ((clm Am).comp (clm Bm)).comp (clm Cm) = (1 : Evolution qubit).op + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, ← map_mul, ← map_mul, + hABCm, map_one] + rfl + -- `U = e^{iα}(A X B X C)` at the operator level. + have hUop : U.op = Complex.exp ((α : ℂ) * Complex.I) • + (A.op.comp (pauliXGate.op.comp (B.op.comp (pauliXGate.op.comp C.op)))) := by + have hUeq : clm (clm.symm U.op) = U.op := clm.apply_symm_apply U.op + rw [← hUeq, hUm, map_smul] + refine congrArg (_ • ·) ?_ + change clm (Am * Concrete.pauliX * Bm * Concrete.pauliX * Cm) + = (clm Am).comp ((clm Concrete.pauliX).comp + ((clm Bm).comp ((clm Concrete.pauliX).comp (clm Cm)))) + simp only [map_mul, ContinuousLinearMap.mul_def] + rw [ContinuousLinearMap.comp_assoc, ContinuousLinearMap.comp_assoc, + ContinuousLinearMap.comp_assoc] + refine ⟨A, B, C, α, hABC, ?_⟩ + -- Verify on the four computational-basis inputs, casing on the control qubit. + apply twoQubit_evolution_ext + intro q1 q2 + fin_cases q1 + · -- control `|0⟩`: CNOTs idle, phase trivial; the target sees `A B C = 1`. + simp only [Fin.isValue, Fin.mk_zero, Evolution.evolvePure_comp, Evolution.onLeft_evolvePure, + Evolution.onRight_evolvePure, cnotGate, controlledUnitary_evolvePure_ketZero, + phaseShiftGate_evolvePure_qubitBasis_zero] + congr 1 + rw [← Evolution.evolvePure_comp, ← Evolution.evolvePure_comp, hABC, Evolution.one_def, + Evolution.id_evolvePure] + · -- control `|1⟩`: CNOTs act as `X`, phase `e^{iα}`; the target sees `e^{iα} A X B X C = U`. + simp only [Fin.isValue, Fin.mk_one, Evolution.evolvePure_comp, Evolution.onLeft_evolvePure, + Evolution.onRight_evolvePure, cnotGate, controlledUnitary_evolvePure_ketOne] + apply PureState.ext + simp only [PureState.tmul_vec, Evolution.evolvePure_vec] + rw [hUop, phaseShiftGate_op_apply_qubitBasis] + simp only [Fin.isValue, Matrix.cons_val_one, Matrix.cons_val_zero, + _root_.smul_apply, ContinuousLinearMap.comp_apply] + rw [TensorProduct.tmul_smul, ← TensorProduct.smul_tmul'] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledUnitaryPhasePlus.lean b/LeanPool/AxQM/Postulates/API/ControlledUnitaryPhasePlus.lean new file mode 100644 index 0000000000..b748cc500d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledUnitaryPhasePlus.lean @@ -0,0 +1,100 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.PhasedPlus + +/-! +# A controlled gate rotates a phased-plus control wire (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) peels the head control wire's Figure 5.1 +gates off `qftTowerEvolution (n+1)`: a Hadamard puts the head wire into the phased-plus state +`|+_α⟩ = (|0⟩ + e^{iα}|1⟩)/√2`, and then a *cascade of controlled-`Rₖ` phase gates* — controlled on +the head wire — acts on it. Each such gate is `controlledUnitary W` for a diagonal phase gate `W`; +on a computational-basis target it multiplies the target by a scalar phase `e^{iβ}`. This file +supplies the single-gate fact that powers that peel: a controlled gate whose inner gate acts on the +target as a **scalar phase** `e^{iβ}` simply **advances the control's phased-plus angle** by `β`. + +## What is formalised + +* `controlledUnitary_evolvePure_qubitPhasePlus` — for a control in the phased-plus state `|+_α⟩` and + a target `φ` on which the inner gate `W` acts as a scalar phase, `(W|φ⟩ = e^{iβ}|φ⟩`), + + `C(W) (|+_α⟩ ⊗ φ) = |+_{α+β}⟩ ⊗ φ`. + + The `|0⟩` branch of the control is untouched and the `|1⟩` branch picks up the extra phase + `e^{iβ}` from the target gate, so the two branches recombine into a phased-plus state with its + relative phase advanced from `α` to `α + β`, the target `φ` returned unchanged. (A controlled gate + whose target action is a genuine scalar phase feeds that phase back onto the control — the + interferometric "phase kickback" that drives phase estimation and the QFT alike.) + +It is proved from the phased-plus state `qubitPhasePlus` (in `AxQM/Postulates/API/PhasedPlus.lean`) +and the controlled-gate basis actions `controlledUnitary_evolvePure_ket{Zero,One}` (in +`AxQM/Postulates/API/ControlledUnitary.lean`). It is used in `AxQM/Core/QtowerHeadPhaseControl.lean` +for the action of the tower's head cascade. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **A controlled gate rotates a phased-plus control wire.** If the inner gate `W` acts on the +target state `φ` as the scalar phase `e^{iβ}` — `(W.evolvePure φ).vec = e^{iβ} • φ.vec` — then the +controlled gate `C(W)` sends the phased-plus control state `|+_α⟩` tensored with `φ` to the +phased-plus state with angle advanced by `β`, the target returned unchanged: + + `C(W) (|+_α⟩ ⊗ φ) = |+_{α+β}⟩ ⊗ φ`. + +The `|0⟩` branch of the control is fixed (`controlledUnitary_evolvePure_ketZero`) and the `|1⟩` +branch picks up `e^{iβ}` from the target gate (`controlledUnitary_evolvePure_ketOne` and the +scalar-phase hypothesis), so the two recombine into `|+_{α+β}⟩ = (|0⟩ + e^{i(α+β)}|1⟩)/√2` — the +phase kicked back onto the control. -/ +theorem controlledUnitary_evolvePure_qubitPhasePlus {S : QSystem} (W : Evolution S) + (φ : PureState S) (α β : ℝ) + (hW : (W.evolvePure φ).vec = Complex.exp ((β : ℂ) * Complex.I) • φ.vec) : + (controlledUnitary W).evolvePure ((qubitPhasePlus α).tmul φ) + = (qubitPhasePlus (α + β)).tmul φ := by + -- The target phase `e^{iβ}` and the control phase `e^{iα}` merge into `e^{i(α+β)}`. + have hexp : Complex.exp ((α : ℂ) * Complex.I) * Complex.exp ((β : ℂ) * Complex.I) + = Complex.exp (((α + β : ℝ) : ℂ) * Complex.I) := by + rw [← Complex.exp_add]; congr 1; push_cast; ring + -- The scalar-phase hypothesis at the operator level (`W.op x = (W.evolvePure x).vec`). + have hW' : W.op φ.vec = Complex.exp ((β : ℂ) * Complex.I) • φ.vec := hW + apply PureState.ext + simp only [Evolution.evolvePure_vec, PureState.tmul_vec, qubitPhasePlus_vec] + -- Unfold `C(W).op` to `|0⟩⟨0| ⊗ 1 + |1⟩⟨1| ⊗ W` so the tensor-map linearity lemmas fire. A + -- `change` (defeq to `controlledUnitary_op`'s rfl RHS) is needed, not `rw [controlledUnitary_op]` + -- — whose rewrite leaves ill-resolved instances on which `add_apply` fails to match — the same + -- `change` idiom the sibling `controlledUnitary_evolvePure_ket{Zero,One}` proofs use. + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) W.op) + ((Concrete.invSqrt2 • ((qubitBasis 0).vec + + Complex.exp ((α : ℂ) * Complex.I) • (qubitBasis 1).vec)) ⊗ₜ[ℂ] φ.vec) + = (Concrete.invSqrt2 • ((qubitBasis 0).vec + + Complex.exp (((α + β : ℝ) : ℂ) * Complex.I) • (qubitBasis 1).vec)) ⊗ₜ[ℂ] φ.vec + simp only [map_add, map_smul, add_apply, TensorProduct.mapL_tmul, + InnerProductSpace.rankOne_apply, one_apply_eq_self, qubitBasis_inner_qubitBasis, + hW'] + -- Reduce the branch inner products, collapse the killed branches, gather the scalars. + simp only [Fin.isValue, ↓reduceIte, zero_ne_one, one_ne_zero, zero_smul, smul_zero, add_zero, + zero_add, one_smul, TensorProduct.tmul_smul, smul_smul, TensorProduct.smul_tmul'] + -- Combine the control phase `e^{iα}` and the kicked-back target phase `e^{iβ}` into `e^{i(α+β)}`, + -- then distribute the phased-plus output over its two branches. + rw [show + Complex.exp ((β : ℂ) * Complex.I) * (Concrete.invSqrt2 * Complex.exp ((α : ℂ) * Complex.I)) + = Concrete.invSqrt2 * Complex.exp (((α + β : ℝ) : ℂ) * Complex.I) from by rw [← hexp]; ring, + smul_add, TensorProduct.add_tmul, smul_smul] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ControlledZ.lean b/LeanPool/AxQM/Postulates/API/ControlledZ.lean new file mode 100644 index 0000000000..5e003dd86b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ControlledZ.lean @@ -0,0 +1,152 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.Teleportation +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Concrete.HadamardPauliConjugation + +/-! +# AxQM.Postulates.API — the controlled-`Z` gate + +Nielsen & Chuang's controlled-`Z` (controlled-phase) gate (N&C §4.3), plus the gate-level +Hadamard–Pauli conjugation identity used to relate it to `CNOT`. It is defined alongside `cnotGate` +and reused throughout Chapter 4 (Exercises 4.17, 4.18, 4.19, 4.20). + +## What is formalised + +* `controlledZGate = controlledUnitary pauliZGate` — the **controlled-`Z`** gate on `qubit ⊗ qubit` + (N&C's `diag(1, 1, 1, -1)`): the `Evolution` `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z` that applies the phase + flip `Z` to the target exactly when the control qubit is `|1⟩`. As a `controlledUnitary` instance + it inherits the defining action lemmas (`controlledUnitary_evolvePure_ketZero` / `_ketOne`). +* `controlledZGate_op` — its operator form `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z`. +* `hadamardGate_comp_pauliZGate_comp_hadamardGate` — the **gate-level circuit identity `H Z H = X`** + (N&C Exercise 4.13, eq. 4.18) at the level of the `Evolution` gates: `H · Z · H = X` in the gate + monoid. This is the fact that makes conjugating a controlled-`Z`'s target by Hadamards produce a + `CNOT`. + +## Design notes + +* **N&C fidelity.** The controlled-`Z` gate is, by definition, "apply `Z` to the target iff the + control is `|1⟩`" — exactly `controlledUnitary pauliZGate`, whose operator is the block-diagonal + `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z`. In the computational basis this is N&C's specifying matrix + `diag(1, 1, 1, -1)` (the only non-identity entry is the `|11⟩` phase from `Z`'s `-1`). Building it + as a `controlledUnitary` instance (rather than a bespoke `4 × 4` matrix) makes it an `Evolution` + and immediately reuses the controlled-`U` action lemmas. +* **Gate-level `H Z H = X`.** The matrix identity `Concrete.hadamardC_mul_pauliZ_mul_hadamardC` + (Exercise 4.13, in `Concrete/`) is here lifted to the gate `Evolution`s by reducing + (`Evolution.ext`) to the operator identity `H.op ∘ Z.op ∘ H.op = X.op` and transporting it across + the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (`map_mul`). This is the physics reading of + Exercise 4.13 needed for the controlled-gate construction, complementing the raw matrix version. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-- **The controlled-`Z` gate** on two qubits (Nielsen & Chuang §4.3), the controlled-`U` gate with +`U = Z`: it applies the phase flip `Z` to the target qubit exactly when the control qubit is `|1⟩`. +Its operator `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z` is N&C's specifying matrix `diag(1, 1, 1, -1)` in the +computational basis. -/ +def controlledZGate : Evolution (qubit ⊗ qubit) := controlledUnitary pauliZGate + +/-- The underlying operator of `controlledZGate` is `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z`. -/ +@[simp] +theorem controlledZGate_op : + controlledZGate.op + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + pauliZGate.op := rfl + +/-- **Gate-level circuit identity `H Z H = X`** (Nielsen & Chuang, Exercise 4.13, eq. 4.18), at the +level of the `Evolution` gates: `hadamardGate · pauliZGate · hadamardGate = pauliXGate`. Reducing +(`Evolution.ext`) to the operator identity `H.op ∘ Z.op ∘ H.op = X.op` and transporting the matrix +identity `Concrete.hadamardC_mul_pauliZ_mul_hadamardC` across the `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM` (`map_mul`) closes it. This is the fact that turns a controlled-`Z` into a +`CNOT` when the target is conjugated by Hadamards (Exercise 4.17). -/ +theorem hadamardGate_comp_pauliZGate_comp_hadamardGate : + hadamardGate.comp (pauliZGate.comp hadamardGate) = pauliXGate := by + apply Evolution.ext + -- All three gate operators are `Matrix.toEuclideanCLM` of the corresponding concrete matrix + -- (defeq via `hadamardGate_op` / `pauliZGate` / `pauliXGate` definitions); transport the product. + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC).comp + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC)) + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, ← map_mul, ← map_mul, + ← mul_assoc, Concrete.hadamardC_mul_pauliZ_mul_hadamardC] + +/-- **Gate-level circuit identity `H Z = X H`** — the two-factor commuted form of +`hadamardGate_comp_pauliZGate_comp_hadamardGate` (`H Z H = X`): +`hadamardGate.comp pauliZGate = pauliXGate.comp hadamardGate` in the gate monoid. Equivalent to +`H Z H = X` together with the Hadamard involution `H² = 1`; proved by reducing (`Evolution.ext`) to +the concrete matrix identity `hadamardC * pauliZ = pauliX * hadamardC` (from +`Concrete.hadamardC_mul_pauliZ_mul_hadamardC` and `Concrete.hadamardC_mul_self`) and transporting it +across the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`. This is the rule that pushes a decoding +`Hadamard` past a `Z` error (e.g. in the fault-tolerant measurement of N&C Exercise 10.70, turning a +`Z` on the ancilla into an `X` on the readout after the decoding `Hadamard`). -/ +theorem hadamardGate_comp_pauliZGate : + hadamardGate.comp pauliZGate = pauliXGate.comp hadamardGate := by + apply Evolution.ext + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ) + = (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC) + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, ← map_mul, ← map_mul] + congr 1 + rw [← Concrete.hadamardC_mul_pauliZ_mul_hadamardC, mul_assoc, Concrete.hadamardC_mul_self, + mul_one] + +/-- **A `Z` error on the control commutes with a controlled gate.** For every target gate `U`, +`C(U) · (Z ⊗ 1) = (Z ⊗ 1) · C(U)` on `qubit ⊗ S`, where `Z ⊗ 1 = pauliZGate.onLeft S` acts on the +control qubit. No commutativity hypothesis on `U` is needed: `Z = |0⟩⟨0| - |1⟩⟨1|` is diagonal in +the control basis and `C(U) = |0⟩⟨0| ⊗ 1 + |1⟩⟨1| ⊗ U` is block-diagonal there, so both products are +`|0⟩⟨0| ⊗ 1 - |1⟩⟨1| ⊗ U`. The general controlled-gate∘Pauli-`Z` propagation fact (sibling of the +`CNOT`/`Toffoli` propagation rules); it is why a `Z` error on the measurement ancilla of N&C +Exercise 10.70 slides through the controlled-`M′` interaction and never acts on the encoded data. +Proved by cracking to `.op` (`controlledUnitary_op` + `TensorProduct.mapL` algebra), the +projector–`Z` commutations `|i⟩⟨i| · Z = Z · |i⟩⟨i|` coming from `rankOne_comp`/`comp_rankOne`, +Pauli-`Z` self-adjointness (`Concrete.pauliZ_isHermitian` mapped through `Matrix.toEuclideanCLM`), +and `pauliZGate_op_apply_qubitBasis`. -/ +theorem controlledUnitary_comm_pauliZGate_onLeft {S : QSystem} (U : Evolution S) : + (controlledUnitary U).comp (pauliZGate.onLeft S) + = (pauliZGate.onLeft S).comp (controlledUnitary U) := by + have hSA : IsSelfAdjoint pauliZGate.op := by + have hM : IsSelfAdjoint Concrete.pauliZ := Concrete.pauliZ_isHermitian + rw [pauliZGate_op]; exact hM.map Matrix.toEuclideanCLM + have hadj : ContinuousLinearMap.adjoint pauliZGate.op = pauliZGate.op := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact hSA + set p0 := InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec with hp0 + set p1 := InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec with hp1 + have hz0 : p0.comp pauliZGate.op = pauliZGate.op.comp p0 := by + rw [hp0, InnerProductSpace.rankOne_comp, InnerProductSpace.comp_rankOne, hadj, + pauliZGate_op_apply_qubitBasis] + simp only [Fin.val_zero, pow_zero, one_smul] + have hz1 : p1.comp pauliZGate.op = pauliZGate.op.comp p1 := by + rw [hp1, InnerProductSpace.rankOne_comp, InnerProductSpace.comp_rankOne, hadj, + pauliZGate_op_apply_qubitBasis] + rw [map_smulₛₗ, map_smul, _root_.smul_apply]; norm_num + apply Evolution.ext + change (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 U.op).comp + (TensorProduct.mapL pauliZGate.op 1) + = (TensorProduct.mapL pauliZGate.op 1).comp + (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 U.op) + rw [ContinuousLinearMap.add_comp, ContinuousLinearMap.comp_add, + ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id, ContinuousLinearMap.id_comp, + hz0, hz1] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/DeferredMeasurement.lean b/LeanPool/AxQM/Postulates/API/DeferredMeasurement.lean new file mode 100644 index 0000000000..b02939336d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/DeferredMeasurement.lean @@ -0,0 +1,196 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.API.DeferredMeasurementReindex + +/-! +# AxQM — deferring a gate past a measurement (the deferred-measurement engine) + +The reusable operator engine behind Nielsen & Chuang's **principle of deferred measurement** +(N&C §4.4, Exercise 4.35): a unitary applied *before* a measurement can be commuted to *after* +it, one outcome at a time, whenever the gate commutes with each measurement operator up to an +outcome-dependent unitary on the post-measurement branch. + +Concretely, fix a measurement `m` (operators `Mᵢ`, Postulate 3), a gate `V` (an `Evolution`, +Postulate 5), and a family of gates `Wᵢ` (one per outcome), and suppose + + `Mᵢ V = Wᵢ Mᵢ` for every outcome `i` (`hcomm`). + +Then measuring `m` on the evolved state `V ρ V†` is *equivalent* to measuring `m` on `ρ` and +then applying `Wᵢ` on the branch of outcome `i`: + +* `Measurement.postOp_evolve_of_comm` — the **branch-map identity** (the heart): the unnormalized + post-measurement operator `Eᵢ(V ρ V†) = Mᵢ (V ρ V†) Mᵢ†` equals `Wᵢ Eᵢ(ρ) Wᵢ†`, i.e. `Wᵢ` + applied as a channel to the branch of `ρ`. This single operator identity carries *both* physical + consequences below, since `tr` reads off the probability and the normalization reads off the + state. +* `Measurement.trace_postOp_evolve_of_comm` — the branch traces agree, `tr Eᵢ(V ρ V†) = tr Eᵢ(ρ)` + (conjugation by the unitary `Wᵢ` is trace-invariant). +* `Measurement.bornProb_evolve_of_comm` — **outcome probabilities are unchanged**, + `p(i ∣ V ρ V†) = p(i ∣ ρ)` (Postulate 3): the gate does not affect the measurement statistics. +* `Measurement.postMeasurement_evolve_of_comm` — **the post-measurement state defers the gate**: + `postMeas(V ρ V†, i) = Wᵢ · postMeas(ρ, i)` (Postulate 4), the collapsed state after measuring + the evolved input equals `Wᵢ` applied to the collapsed state after measuring `ρ`. + +## Generality + +`hcomm` (`Mᵢ V = Wᵢ Mᵢ`) is the exact structural condition N&C's argument uses; the conclusions hold +for an *arbitrary* measurement `m`, gate `V`, outcome-gate family `W`, and state `ρ`, no dimension +specialized. Exercise 4.35 is the instance `m = measure the control`, `V = C(U)`, `Wᵢ = U^i` on the +target (`ControlMeasurementCommute.lean`). + +## Relation to the reindexing engine + +`Mᵢ V = Wᵢ Mᵢ` is the special case of the *reindexing* commutation `Mᵢ V = Wᵢ M_{e i}` +(`DeferredMeasurementReindex.lean`) at the identity outcome-relabelling `e = Equiv.refl` — a gate +that *fixes* each measurement outcome, rather than permuting them. The four core lemmas below are +therefore thin `Equiv.refl` instances of their reindexing counterparts (no duplicated proof body); +only the product-form lemmas `op_comp_prod_of_forall_comm` and its Born/collapse corollaries — which +have no reindexing analogue — carry their own proofs. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- **Branch-map identity for deferring a gate past a measurement** (the engine of N&C's principle +of deferred measurement, §4.4). If each measurement operator `Mᵢ` of `m` commutes with the gate `V` +up to an outcome-gate `Wᵢ` — `Mᵢ V = Wᵢ Mᵢ` (`hcomm`) — then the unnormalized post-measurement +operator of outcome `i` on the *evolved* state `V ρ V†` equals `Wᵢ` conjugating the branch of `ρ`: + + `Eᵢ(V ρ V†) = Mᵢ (V ρ V†) Mᵢ† = Wᵢ (Mᵢ ρ Mᵢ†) Wᵢ† = Wᵢ Eᵢ(ρ) Wᵢ†`. + +This one operator identity packages both physical consequences (probability and post-state), since +the trace reads off `p(i)` and the normalization reads off the collapsed state. -/ +theorem postOp_evolve_of_comm (m : Measurement ι S) (V : Evolution S) (W : ι → Evolution S) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op i)) (ρ : State S) (i : ι) : + ContinuousLinearMap.postOp m.op (V.evolve ρ).op i + = (W i).op.comp ((ContinuousLinearMap.postOp m.op ρ.op i).comp (adjoint (W i).op)) := + postOp_evolve_of_reindex_comm m V W (Equiv.refl ι) hcomm ρ i + +/-- **The two branch traces agree:** `tr Eᵢ(V ρ V†) = tr Eᵢ(ρ)`. Conjugating the branch `Eᵢ(ρ)` by +the unitary `Wᵢ` (the branch-map identity `postOp_evolve_of_comm`) is trace-invariant, by cyclicity +of the trace collapsing `Wᵢ† Wᵢ = 1`. This is the operator fact under both the probability equality +and the shared normalization factor of the post-measurement states. -/ +theorem trace_postOp_evolve_of_comm (m : Measurement ι S) (V : Evolution S) (W : ι → Evolution S) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op i)) (ρ : State S) (i : ι) : + LinearMap.trace ℂ S.space (ContinuousLinearMap.postOp m.op (V.evolve ρ).op i : S.space →ₗ[ℂ] _) + = LinearMap.trace ℂ S.space (ContinuousLinearMap.postOp m.op ρ.op i : S.space →ₗ[ℂ] _) := + trace_postOp_evolve_of_reindex_comm m V W (Equiv.refl ι) hcomm ρ i + +/-- **Outcome probabilities are unchanged when the gate is deferred** (Postulate 3): under the +commutation `Mᵢ V = Wᵢ Mᵢ`, the Born probability of outcome `i` on the evolved state `V ρ V†` equals +that on `ρ`, `p(i ∣ V ρ V†) = p(i ∣ ρ)`. The measurement statistics do not see the gate `V`. -/ +theorem bornProb_evolve_of_comm (m : Measurement ι S) (V : Evolution S) (W : ι → Evolution S) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op i)) (ρ : State S) (i : ι) : + m.bornProb (V.evolve ρ) i = m.bornProb ρ i := + bornProb_evolve_of_reindex_comm m V W (Equiv.refl ι) hcomm ρ i + +/-- **The post-measurement state defers the gate** (Postulate 4): under the commutation +`Mᵢ V = Wᵢ Mᵢ`, the state after measuring outcome `i` on the evolved input `V ρ V†` equals `Wᵢ` +applied to the state after measuring outcome `i` on `ρ`, + + `postMeas(V ρ V†, i) = Wᵢ · postMeas(ρ, i)`. + +The `V`-then-measure branch is the measure-then-`Wᵢ` branch. The outcome must be possible on `ρ` +(`hp : p(i ∣ ρ) ≠ 0`); it is then equally possible on `V ρ V†`, since the probabilities agree +(`bornProb_evolve_of_comm`). -/ +theorem postMeasurement_evolve_of_comm (m : Measurement ι S) (V : Evolution S) (W : ι → Evolution S) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op i)) (ρ : State S) (i : ι) + (hp : m.bornProb ρ i ≠ 0) : + m.postMeasurement (V.evolve ρ) i + (by rw [bornProb_evolve_of_comm m V W hcomm ρ i]; exact hp) + = (W i).evolve (m.postMeasurement ρ i hp) := + postMeasurement_evolve_of_reindex_comm m V W (Equiv.refl ι) hcomm ρ i hp + +/-! ## Deferring a measurement past a *composition* of gates + +The single-gate deferral above commutes a measurement past one gate. A circuit is a *product* of +gates, so the whole-circuit reduction needs to commute a measurement past a run of them. If the +measurement commutes with *each* gate `V a` of a family (indexed by `a ∈ Us`) up to a branch family +`W a` — `Mᵢ (V a) = (W a i) Mᵢ` — then it commutes with the whole composition `(Us.map V).prod` up +to the *composition* of the branch gates, and the Born-rule / collapse readings follow at the +product. This is the inductive engine a measured circuit's reduction runs one gate at a time. -/ + +/-- **Deferring a measurement past a composition of gates** (the product form of the commutation +hypothesis `hcomm`). If a measurement `m` commutes with every gate `V a` (`a ∈ Us`) up to the branch +family `W a` — `Mᵢ (V a) = (W a i) Mᵢ` (`hcomm`) — then `m` commutes with their whole composition +`(Us.map V).prod` up to the *composed* branch gates `(Us.map (fun a => W a i)).prod`: + + `Mᵢ · (Vₖ ⋯ V₁) = (Wₖ ⋯ W₁)ᵢ · Mᵢ`. + +Induction over `Us`: the head commutation `Mᵢ (V hd) = (W hd i) Mᵢ` threads past the accumulated +tail commutation, using multiplicativity of `Evolution.op` on the list product +(`Evolution.mul_def` / `Evolution.comp_op`) and associativity of composition. This is the exact +hypothesis `postOp_evolve_of_comm` (and its corollaries) consume, so a whole sub-circuit of gates — +each individually deferrable — defers as one. -/ +theorem op_comp_prod_of_forall_comm {α : Type*} (m : Measurement ι S) (Us : List α) + (V : α → Evolution S) (W : α → ι → Evolution S) + (hcomm : ∀ a ∈ Us, ∀ i, (m.op i).comp (V a).op = (W a i).op.comp (m.op i)) (i : ι) : + (m.op i).comp (Us.map V).prod.op + = (Us.map (fun a => W a i)).prod.op.comp (m.op i) := by + revert hcomm + induction Us with + | nil => intro _; simp [ContinuousLinearMap.one_def] + | cons hd tl ih => + intro hcomm + simp only [List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.comp_op] + rw [← ContinuousLinearMap.comp_assoc, hcomm hd List.mem_cons_self i, + ContinuousLinearMap.comp_assoc, ih (fun a ha => hcomm a (List.mem_cons_of_mem hd ha)), + ← ContinuousLinearMap.comp_assoc] + +/-- **Outcome probabilities are unchanged when a whole composition of gates is deferred** +(Postulate 3, product form). Under the pointwise commutation `Mᵢ (V a) = (W a i) Mᵢ` for every +`a ∈ Us`, the Born probability of outcome `i` on the state evolved by the composition +`(Us.map V).prod` equals that on `ρ`: the measurement statistics do not see the sub-circuit. The +instance of `bornProb_evolve_of_comm` at the product gate and the composed branch family, whose +commutation is `op_comp_prod_of_forall_comm`. -/ +theorem bornProb_evolve_prod_of_forall_comm {α : Type*} (m : Measurement ι S) (Us : List α) + (V : α → Evolution S) (W : α → ι → Evolution S) + (hcomm : ∀ a ∈ Us, ∀ i, (m.op i).comp (V a).op = (W a i).op.comp (m.op i)) + (ρ : State S) (i : ι) : + m.bornProb ((Us.map V).prod.evolve ρ) i = m.bornProb ρ i := + bornProb_evolve_of_comm m (Us.map V).prod (fun i => (Us.map (fun a => W a i)).prod) + (fun i => op_comp_prod_of_forall_comm m Us V W hcomm i) ρ i + +/-- **The post-measurement state defers a whole composition of gates** (Postulate 4, product form). +Under the pointwise commutation `Mᵢ (V a) = (W a i) Mᵢ` for every `a ∈ Us`, the state after +measuring outcome `i` on the input evolved by the composition `(Us.map V).prod` equals the composed +branch gates `(Us.map (fun a => W a i)).prod` applied to the state after measuring `ρ`: + + `postMeas((Vₖ ⋯ V₁) ρ (Vₖ ⋯ V₁)†, i) = (Wₖ ⋯ W₁)ᵢ · postMeas(ρ, i)`. + +The whole sub-circuit is deferred past the measurement in one step. The instance of +`postMeasurement_evolve_of_comm` at the product gate and the composed branch family +(`op_comp_prod_of_forall_comm`). -/ +theorem postMeasurement_evolve_prod_of_forall_comm {α : Type*} (m : Measurement ι S) (Us : List α) + (V : α → Evolution S) (W : α → ι → Evolution S) + (hcomm : ∀ a ∈ Us, ∀ i, (m.op i).comp (V a).op = (W a i).op.comp (m.op i)) + (ρ : State S) (i : ι) (hp : m.bornProb ρ i ≠ 0) : + m.postMeasurement ((Us.map V).prod.evolve ρ) i + (by rw [bornProb_evolve_prod_of_forall_comm m Us V W hcomm]; exact hp) + = (Us.map (fun a => W a i)).prod.evolve (m.postMeasurement ρ i hp) := + postMeasurement_evolve_of_comm m (Us.map V).prod (fun i => (Us.map (fun a => W a i)).prod) + (fun i => op_comp_prod_of_forall_comm m Us V W hcomm i) ρ i hp + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/DeferredMeasurementOnLeft.lean b/LeanPool/AxQM/Postulates/API/DeferredMeasurementOnLeft.lean new file mode 100644 index 0000000000..beec7cf295 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/DeferredMeasurementOnLeft.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.DeferredMeasurement +public import LeanPool.AxQM.Postulates.API.MeasurementPrecompose + +/-! +# Deferring a right-factor gate past a left-factor measurement (the disjoint-factor commutation) + +The deferred-measurement engine (`DeferredMeasurement.lean`, N&C §4.4 / Exercise 4.35) commutes a +gate `g` past a measurement `m` on a system `S` whenever `Mᵢ g = Wᵢ Mᵢ` (operator commutation). The +sibling `DeferredMeasurementOnRight.lean` handles the case where a gate and a measurement act on the +*same* right factor; this file handles the complementary **disjoint-factor** case, where the gate +and the measurement touch *different* tensor factors. + +Nielsen & Chuang's measured quantum Fourier transform (Problem 5.2) reads `qftEvolution` off the +qubit tower `qubit ⊗ S` and measures the head wire with `controlMeasurement S = m.onLeft S` (a +*left*-factor measurement). Its Figure 5.1 head-layer peel leaves the recursive tail QFT +`(qftTowerEvolution n).onRight qubit` (a *right*-factor gate `1 ⊗ V`, idle on the head wire) applied +*after* the head control cascade. To measure the head wire the reduction must first push that head +measurement past the tail QFT — but the tail QFT touches only the right factor, disjoint from the +head, so it defers **unchanged** (its own branch gate on every outcome). This file supplies exactly +that. + +Let `m : Measurement ι S` be the left-factor measurement and `V : Evolution T` the right-factor +gate. On `S ⊗ T` the operators are `(m.onLeft T).op i = Mᵢ ⊗ 1` and `(V.onRight S).op = 1 ⊗ V`, and +they commute on disjoint factors (`onLeft_op_comm_onRight_op`): + + `(Mᵢ ⊗ 1)(1 ⊗ V) = Mᵢ ⊗ V = (1 ⊗ V)(Mᵢ ⊗ 1)`. + +So `V.onRight S` defers past `m.onLeft T` with the branch family the gate itself (`Wᵢ = V.onRight S` +for every `i`): the two readings are the instances of the single-measurement +`bornProb_evolve_of_comm` / `postMeasurement_evolve_of_comm` at that commutation. + +* `Measurement.bornProb_evolve_onLeft_of_comm` — the right-factor gate is **invisible to the + statistics** of the left-factor measurement (Postulate 3), `p(i ∣ (1⊗V) ρ (1⊗V)†) = p(i ∣ ρ)`. +* `Measurement.postMeasurement_evolve_onLeft_of_comm` — the left-factor **post-measurement state + defers the right-factor gate** unchanged (Postulate 4), + `postMeas((1⊗V) ρ (1⊗V)†, i) = (1⊗V) · postMeas(ρ, i)`. + +## Generality + +The conclusions hold for an arbitrary measurement `m`, gate `V`, extra factor `T`, and state on `S ⊗ +T`, no dimension specialized. Unlike the siblings `DeferredMeasurement` / +`DeferredMeasurementOnRight`, the two theorem statements here have no commutation premise `hcomm : +Mᵢ g = Wᵢ Mᵢ`, because the disjoint-factor commutation is *unconditional*: it is discharged inside +the proofs by `onLeft_op_comm_onRight_op` and +`Measurement.{bornProb,postMeasurement}_evolve_of_comm`. The tower-specific application, specialized +to `controlMeasurement (qtower n qubit)`, is `AxQM/Core/QtowerHeadIdleMeasurement.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- **A right-factor gate is invisible to the statistics of a left-factor measurement** (Postulate +3). On `S ⊗ T`, the left-factor measurement `m.onLeft T` (operators `Mᵢ ⊗ 1`) does not see the +right-factor gate `V.onRight S = 1 ⊗ V`: the Born probability of outcome `i` on the evolved state +`(1⊗V) ρ (1⊗V)†` equals that on `ρ`, + + `p(i ∣ (1⊗V) ρ (1⊗V)†) = p(i ∣ ρ)`. + +The instance of `bornProb_evolve_of_comm` at the gate `V.onRight S`, whose (self-)commutation with +`m.onLeft T` is the disjoint-factor `onLeft_op_comm_onRight_op` (`Mᵢ ⊗ V` either way). This is the +`hL`-side reading the measured-QFT outer induction uses to push the head-wire measurement past the +recursive tail QFT (N&C Problem 5.2). -/ +theorem bornProb_evolve_onLeft_of_comm (m : Measurement ι S) {T : QSystem} (V : Evolution T) + (ρ : State (S.compose T)) (i : ι) : + (m.onLeft T).bornProb ((V.onRight S).evolve ρ) i = (m.onLeft T).bornProb ρ i := + bornProb_evolve_of_comm (m.onLeft T) (V.onRight S) (fun _ => V.onRight S) + (fun i => onLeft_op_comm_onRight_op m V i) ρ i + +/-- **The post-measurement state defers a right-factor gate past a left-factor measurement** +(Postulate 4). On `S ⊗ T`, the state after measuring outcome `i` of the left-factor measurement +`m.onLeft T` on the right-factor-gate input `(1⊗V) ρ (1⊗V)†` equals that same right-factor gate +`V.onRight S = 1 ⊗ V` applied to the state after measuring `ρ`: + + `postMeas((1⊗V) ρ (1⊗V)†, i) = (1 ⊗ V) · postMeas(ρ, i)`. + +The right-factor gate **defers past** the left-factor measurement unchanged (its own branch gate on +every outcome), because they act on disjoint tensor factors and so commute +(`onLeft_op_comm_onRight_op`). The outcome is equally possible after `1⊗V` because the probabilities +agree (`bornProb_evolve_onLeft_of_comm`). The instance of `postMeasurement_evolve_of_comm` at the +gate `V.onRight S` and the constant branch family. This is the collapse reading the measured-QFT +outer induction uses to carry the recursive tail QFT past the head-wire measurement (N&C Problem +5.2). -/ +theorem postMeasurement_evolve_onLeft_of_comm (m : Measurement ι S) {T : QSystem} (V : Evolution T) + (ρ : State (S.compose T)) (i : ι) (hp : (m.onLeft T).bornProb ρ i ≠ 0) : + (m.onLeft T).postMeasurement ((V.onRight S).evolve ρ) i + (by rw [bornProb_evolve_onLeft_of_comm]; exact hp) + = (V.onRight S).evolve ((m.onLeft T).postMeasurement ρ i hp) := + postMeasurement_evolve_of_comm (m.onLeft T) (V.onRight S) (fun _ => V.onRight S) + (fun i => onLeft_op_comm_onRight_op m V i) ρ i hp + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/DeferredMeasurementReindex.lean b/LeanPool/AxQM/Postulates/API/DeferredMeasurementReindex.lean new file mode 100644 index 0000000000..53419d33f9 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/DeferredMeasurementReindex.lean @@ -0,0 +1,140 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.Evolution + +/-! +# AxQM — deferring a basis-permuting gate past a measurement (the reindexing engine) + +The reindexing companion of the deferred-measurement engine (`DeferredMeasurement.lean`). That +engine defers a gate whose measurement operators commute *up to a fixed outcome* — `Mᵢ V = Wᵢ Mᵢ`. +A gate that *permutes* the measurement basis (a swap network, a wire relabelling) does not satisfy +that: it carries the operator of one outcome onto that of *another*. The condition it satisfies is + + `Mᵢ V = Wᵢ M_{e i}` for every outcome `i` (`hcomm`), + +with `e : ι ≃ ι` the induced *outcome* relabelling. Then measuring `m` on the evolved state +`V ρ V†` is equivalent to measuring `m` on `ρ` at the *relabelled* outcome `e i` and then applying +`Wᵢ`: + +* `Measurement.postOp_evolve_of_reindex_comm` — the branch-map identity + `Eᵢ(V ρ V†) = Wᵢ E_{e i}(ρ) Wᵢ†` (the heart; carries both consequences below). +* `Measurement.trace_postOp_evolve_of_reindex_comm` — the branch traces agree, + `tr Eᵢ(V ρ V†) = tr E_{e i}(ρ)`. +* `Measurement.bornProb_evolve_of_reindex_comm` — **outcome probabilities are relabelled**, + `p(i ∣ V ρ V†) = p(e i ∣ ρ)`. +* `Measurement.postMeasurement_evolve_of_reindex_comm` — **the post-measurement state defers the + gate**, `postMeas(V ρ V†, i) = Wᵢ · postMeas(ρ, e i)`. + +The physical instance is Nielsen & Chuang, Problem 5.2: the swap network at the end of the quantum +Fourier transform, being applied just before a computational-basis measurement, contributes only a +relabelling of the classical outcomes — no two-qubit gate survives. A wire permutation permutes the +computational basis, so `Mᵢ (permWires σ) = (permWires σ) M_{e i}` with `e` the outcome relabelling +induced by `σ`, and `Wᵢ = permWires σ` (the permutation reappears on the collapsed basis state as a +classical wire relabelling). + +## Generality + +`hcomm` (`Mᵢ V = Wᵢ M_{e i}`) is the exact structural condition; the conclusions hold for an +*arbitrary* measurement `m`, gate `V`, outcome bijection `e`, outcome-gate family `W`, and state +`ρ`, no dimension specialized. + +## Proof notes + +Each proof is the exact analogue of its `DeferredMeasurement.lean` sibling, with the right-hand +outcome shifted from `i` to `e i`; `postOp_evolve_of_reindex_comm` regroups `Mᵢ (V ρ V†) Mᵢ†` as +`(Mᵢ V) ρ (Mᵢ V)†`, rewrites `Mᵢ V = Wᵢ M_{e i}`, and regroups back as +`Wᵢ (M_{e i} ρ M_{e i}†) Wᵢ†`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- **Branch-map identity for deferring a basis-permuting gate past a measurement.** If each +measurement operator `Mᵢ` of `m` carries the gate `V` onto the *reindexed* operator `M_{e i}` up to +an outcome-gate `Wᵢ` — `Mᵢ V = Wᵢ M_{e i}` (`hcomm`) — then the unnormalized post-measurement +operator of outcome `i` on the *evolved* state `V ρ V†` equals `Wᵢ` conjugating the branch of `ρ` +at the reindexed outcome `e i`: + + `Eᵢ(V ρ V†) = Mᵢ (V ρ V†) Mᵢ† = Wᵢ (M_{e i} ρ M_{e i}†) Wᵢ† = Wᵢ E_{e i}(ρ) Wᵢ†`. -/ +theorem postOp_evolve_of_reindex_comm (m : Measurement ι S) (V : Evolution S) (W : ι → Evolution S) + (e : ι ≃ ι) (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op (e i))) (ρ : State S) + (i : ι) : + ContinuousLinearMap.postOp m.op (V.evolve ρ).op i + = (W i).op.comp ((ContinuousLinearMap.postOp m.op ρ.op (e i)).comp (adjoint (W i).op)) := by + have conj_comp : ∀ A B X : S.space →L[ℂ] S.space, + (A.comp B).comp (X.comp (adjoint (A.comp B))) + = A.comp ((B.comp (X.comp (adjoint B))).comp (adjoint A)) := by + intro A B X + rw [ContinuousLinearMap.adjoint_comp] + simp only [ContinuousLinearMap.comp_assoc] + simp only [ContinuousLinearMap.postOp, Evolution.evolve_op] + rw [← conj_comp (m.op i) V.op ρ.op, hcomm i, conj_comp (W i).op (m.op (e i)) ρ.op] + +/-- **The two branch traces agree:** `tr Eᵢ(V ρ V†) = tr E_{e i}(ρ)`. Conjugating the branch by the +unitary `Wᵢ` (the branch-map identity `postOp_evolve_of_reindex_comm`) is trace-invariant. -/ +theorem trace_postOp_evolve_of_reindex_comm (m : Measurement ι S) (V : Evolution S) + (W : ι → Evolution S) (e : ι ≃ ι) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op (e i))) (ρ : State S) (i : ι) : + LinearMap.trace ℂ S.space (ContinuousLinearMap.postOp m.op (V.evolve ρ).op i : S.space →ₗ[ℂ] _) + = LinearMap.trace ℂ S.space + (ContinuousLinearMap.postOp m.op ρ.op (e i) : S.space →ₗ[ℂ] _) := by + rw [postOp_evolve_of_reindex_comm m V W e hcomm ρ i, ContinuousLinearMap.toLinearMap_comp, + ContinuousLinearMap.toLinearMap_comp, LinearMap.trace_comp_cycle, + ← ContinuousLinearMap.toLinearMap_comp, + (W i).adjoint_comp_self, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, + LinearMap.comp_id] + +/-- **Outcome probabilities are relabelled when a basis-permuting gate is deferred** (Postulate 3): +under `Mᵢ V = Wᵢ M_{e i}`, the Born probability of outcome `i` on `V ρ V†` equals that of the +relabelled outcome `e i` on `ρ`, `p(i ∣ V ρ V†) = p(e i ∣ ρ)`. -/ +theorem bornProb_evolve_of_reindex_comm (m : Measurement ι S) (V : Evolution S) + (W : ι → Evolution S) (e : ι ≃ ι) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op (e i))) (ρ : State S) (i : ι) : + m.bornProb (V.evolve ρ) i = m.bornProb ρ (e i) := by + rw [bornProb_eq_re_trace_postOp, bornProb_eq_re_trace_postOp, + trace_postOp_evolve_of_reindex_comm m V W e hcomm ρ i] + +/-- **The post-measurement state defers a basis-permuting gate** (Postulate 4): under +`Mᵢ V = Wᵢ M_{e i}`, the state after measuring outcome `i` on `V ρ V†` equals `Wᵢ` applied to the +state after measuring the relabelled outcome `e i` on `ρ`, + + `postMeas(V ρ V†, i) = Wᵢ · postMeas(ρ, e i)`. + +The outcome must be possible on `ρ` at `e i` (`hp`); it is then equally possible on `V ρ V†` at `i` +since the probabilities are relabelled (`bornProb_evolve_of_reindex_comm`). -/ +theorem postMeasurement_evolve_of_reindex_comm (m : Measurement ι S) (V : Evolution S) + (W : ι → Evolution S) (e : ι ≃ ι) + (hcomm : ∀ i, (m.op i).comp V.op = (W i).op.comp (m.op (e i))) (ρ : State S) (i : ι) + (hp : m.bornProb ρ (e i) ≠ 0) : + m.postMeasurement (V.evolve ρ) i + (by rw [bornProb_evolve_of_reindex_comm m V W e hcomm ρ i]; exact hp) + = (W i).evolve (m.postMeasurement ρ (e i) hp) := by + apply State.ext + rw [postMeasurement_op, ContinuousLinearMap.postState, + trace_postOp_evolve_of_reindex_comm m V W e hcomm ρ i, + postOp_evolve_of_reindex_comm m V W e hcomm ρ i, Evolution.evolve_op, postMeasurement_op, + ContinuousLinearMap.postState] + simp only [ContinuousLinearMap.comp_smul, ContinuousLinearMap.smul_comp] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Distinguishability.lean b/LeanPool/AxQM/Postulates/API/Distinguishability.lean new file mode 100644 index 0000000000..4ce635398c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Distinguishability.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DensitySubunital + +/-! +# The distinguishability bound for a measurement + +For a measurement `m` on a system `T` and *any* assignment `ρ : ι → State T` of a state to each +outcome, the total probability of "each outcome correctly reporting its own state", + +`∑ᵢ tr(Eᵢ ρᵢ) ≤ dim T`, + +is bounded by the Hilbert-space dimension `dim T = finrank ℂ T.space`, independently of how many +outcomes there are. This is the elementary **distinguishability bound** (a.k.a. the dimension bound +on a POVM), the operator fact behind the converse — the "no more than `dim` reliably distinguishable +states" limit — of Nielsen & Chuang's classical-communication capacity theorems (§12.2/§12.3): it +is what forces the number of reliably decodable codewords, and hence the achievable rate, to be +bounded. + +## Proof + +Two facts. First, for a POVM effect `E ≥ 0` and a density operator `ρ` the Born probability +`tr(E ρ)` never exceeds `tr(E)` itself (`ContinuousLinearMap.IsDensityOp.re_trace_comp_le`, the +general operator fact in the `ToMathlib` density API): the gap is `tr(E (1 − ρ)) ≥ 0`, positive +because `1 − ρ ≥ 0` (a density operator is subunital, `ContinuousLinearMap.IsDensityOp.le_one`) and +`E ≥ 0`. Second, summing over all outcomes and pulling the trace out of the sum, +`∑ᵢ tr(Eᵢ) = tr(∑ᵢ Eᵢ) = tr(1) = dim T` by the POVM completeness relation (`POVM.sum_eq_one`) and +`LinearMap.trace_one`. + +## Supporting facts + +The bound is stated in terms of the Born probability `Measurement.bornProb`. Its supporting operator +facts are general mathematics and are in the density-operator API +(`ToMathlib/Analysis/InnerProductSpace/DensitySubunital.lean`, +`ContinuousLinearMap.IsDensityOp.le_one` / `.re_trace_comp_le`). + +## Main results + +* `AxQM.Measurement.sum_bornProb_self_le_finrank` — the distinguishability bound + `∑ᵢ bornProb ρᵢ i ≤ dim T`. +-/ + +@[expose] public section + +open ContinuousLinearMap InnerProductSpace +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {T : QSystem} + +/-- **The distinguishability bound.** For a measurement `m` on the system `T` and any assignment +`ρ : ι → State T` of a state to each outcome, the total Born probability of every outcome correctly +reporting *its own* state is at most the dimension of `T`: + +`∑ᵢ bornProb (ρᵢ) i ≤ dim T`. + +Each term `bornProb (ρᵢ) i = re tr(Eᵢ ρᵢ) ≤ re tr(Eᵢ)` +(`ContinuousLinearMap.IsDensityOp.re_trace_comp_le`, as `ρᵢ` is a density operator and the effect +`Eᵢ = Mᵢ† Mᵢ` is positive), and summing, +`∑ᵢ re tr(Eᵢ) = re tr(∑ᵢ Eᵢ) = re tr(1) = dim T` by POVM completeness. Independent of the number of +outcomes, this is the operator input to the converse of the classical-communication capacity +theorems (N&C §12.2/§12.3). -/ +theorem Measurement.sum_bornProb_self_le_finrank (m : Measurement ι T) (ρ : ι → State T) : + ∑ i, m.bornProb (ρ i) i ≤ (Module.finrank ℂ T.space : ℝ) := by + calc ∑ i, m.bornProb (ρ i) i + = ∑ i, RCLike.re (LinearMap.trace ℂ T.space + ((m.toPOVM.elements i).comp (ρ i).op : T.space →ₗ[ℂ] T.space)) := by + simp only [Measurement.bornProb, POVM.toPMF_eq] + _ ≤ ∑ i, RCLike.re (LinearMap.trace ℂ T.space + (m.toPOVM.elements i : T.space →ₗ[ℂ] T.space)) := by + refine Finset.sum_le_sum fun i _ => ?_ + exact ContinuousLinearMap.IsDensityOp.re_trace_comp_le + ((ContinuousLinearMap.nonneg_iff_isPositive).mpr (m.toPOVM.isPositive i)) + (ρ i).isDensity + _ = RCLike.re (LinearMap.trace ℂ T.space + (↑(∑ i, m.toPOVM.elements i) : T.space →ₗ[ℂ] T.space)) := by + rw [ContinuousLinearMap.toLinearMap_sum, map_sum, RCLike.re_sum] + _ = RCLike.re (LinearMap.trace ℂ T.space (1 : T.space →ₗ[ℂ] T.space)) := by + rw [m.toPOVM.sum_eq_one, ContinuousLinearMap.toLinearMap_one] + _ = (Module.finrank ℂ T.space : ℝ) := by + rw [LinearMap.trace_one]; simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EigenspaceCollapse.lean b/LeanPool/AxQM/Postulates/API/EigenspaceCollapse.lean new file mode 100644 index 0000000000..221c07488e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EigenspaceCollapse.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasureObservable + +/-! +# AxQM.Postulates.API — collapse into the `±1` eigenspaces of an involution observable + +The results behind **Nielsen & Chuang, Exercise 5.9**: for a unitary `U` +with eigenvalues `±1` (a self-adjoint involution, `U² = I`), the phase-estimation circuit of +Exercise 4.34 (`measureObservableCircuit U = (H ⊗ 1) · C(U) · (H ⊗ 1)`) collapses an arbitrary input +`|ψ⟩` into one of the two eigenspaces of `U`, with the single ancilla qubit as the classical +indicator of which eigenspace. This file supplies the pieces that Exercise 4.34 did not need — the +`−1`-outcome collapse state, and the fact that *both* collapsed states are genuine `±1` eigenstates +of `U` — used in the statement of the collapse in [upstream `AxQM/NC/Ch5/Exercise5_9.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_9.lean). + +## What is formalised + +The `+1` post-measurement machinery of the sign measurement — `Observable.postMeasPlus`, +`postOp_signMeasurement_zero`, `bornProb_signMeasurement_plus_eq_normSq`, +`postMeasurement_signMeasurement_plus` — is in `AxQM/Postulates/API/PauliMeasurement.lean` +(introduced there for Exercise 2.61's `+1` outcome). This file adds: + +* `Observable.postMeasMinus` — the **normalized `−1` post-measurement pure state** + `P₋|ψ⟩ / ‖P₋|ψ⟩‖`, + the collapsed target when the `±1` measurement of `A` yields `−1`. The exact `−1` sibling of the + existing `Observable.postMeasPlus`, with its supporting `postOp_signMeasurement_one`, + `bornProb_signMeasurement_minus_eq_normSq`, `projMinus_apply_ne_zero_of_bornProb`, and + `postMeasurement_signMeasurement_minus` (the Postulate-4 collapse to `postMeasMinus`). +* `Observable.postMeasPlus_hasEigenstate` / `Observable.postMeasMinus_hasEigenstate` — **the + collapse lands in the eigenspace:** the `+1` (resp. `−1`) collapsed state is a genuine `+1` + (resp. `−1`) eigenstate of `A`, `A |ψ'⟩ = ±|ψ'⟩`. This is the content Exercise 5.9 emphasises + over 4.34: the post-measurement state is *the corresponding eigenvector*. Proved from + `Observable.op_mul_projPlus` / `op_mul_projMinus` (`A·P± = ±P±`, so `P±|ψ⟩` is a `±1` + eigenvector) transported to the + normalized state via `Observable.hasEigenstate_of_smul`. + +Together with `measureObservableCircuit_op_qubitBasisZero_tmul_signMeasurement` (in +`AxQM/Postulates/API/MeasureObservable.lean`, stated over an arbitrary target `S`) — the circuit +sends `|0⟩ ⊗ |ψ⟩` to +`|0⟩ ⊗ M₀|ψ⟩ + |1⟩ ⊗ M₁|ψ⟩` with `M₀ = P₊`, `M₁ = P₋` the operators of `Observable.signMeasurement` +— these say precisely: the circuit realises the sign measurement of `U`; a computational-basis +measurement of the ancilla returns the outcome `i ∈ {0, 1}` (the classical indicator) with Born +probability `‖Mᵢ|ψ⟩‖²`, and collapses the target onto `postMeasPlus`/`postMeasMinus`, a `±1` +eigenstate of `U` — one of the two eigenspaces. + +The circuit's deterministic action on a `±1` eigenstate input, with the indicator flagging the +eigenvalue, is stated in [upstream `AxQM/NC/Ch5/Exercise5_9.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_9.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace Observable + +/-! ### The `−1` post-measurement collapse (sibling of the `+1` machinery in `PauliMeasurement`) -/ + +/-- The post-measurement operation for the `−1` outcome sends `|ψ⟩⟨ψ|` to the rank-one operator +`|P₋ψ⟩⟨P₋ψ|`: `M₁ ρ M₁† = P₋ |ψ⟩⟨ψ| P₋ = |P₋ψ⟩⟨P₋ψ|`, using `adjoint P₋ = P₋` and the rank-one +composition rules. The `−1` sibling of `postOp_signMeasurement_zero`. -/ +theorem postOp_signMeasurement_one (A : Observable S) (hinv : A.op * A.op = 1) (ψ : PureState S) : + ContinuousLinearMap.postOp (A.signMeasurement hinv).op ψ.toState.op 1 + = rankOne ℂ (A.projMinus ψ.vec) (A.projMinus ψ.vec) := by + simp only [ContinuousLinearMap.postOp, signMeasurement_op_one, PureState.toState_op, + A.adjoint_projMinus, InnerProductSpace.comp_rankOne, InnerProductSpace.rankOne_comp] + +/-- **Born probability of `−1` as a squared norm:** `p(−1) = ‖P₋|ψ⟩‖²`. The `−1` sibling of +`bornProb_signMeasurement_plus_eq_normSq`; certifies that `−1` is a possible outcome (`p ≠ 0`) +exactly when `P₋|ψ⟩ ≠ 0`. -/ +theorem bornProb_signMeasurement_minus_eq_normSq (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = ‖A.projMinus ψ.vec‖ ^ 2 := by + rw [Measurement.bornProb_eq_re_trace_postOp, postOp_signMeasurement_one, + InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq] + +/-- If the `−1` outcome is possible (`p(−1) ≠ 0`), then `P₋|ψ⟩ ≠ 0` — the post-measurement state is +well-defined. Contrapositive of `bornProb_signMeasurement_minus_eq_normSq`. -/ +theorem projMinus_apply_ne_zero_of_bornProb (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) (hp : (A.signMeasurement hinv).bornProb ψ.toState 1 ≠ 0) : + A.projMinus ψ.vec ≠ 0 := by + intro h0 + apply hp + rw [bornProb_signMeasurement_minus_eq_normSq, h0, norm_zero] + norm_num + +/-- The **normalized `−1` post-measurement pure state** `P₋|ψ⟩ / ‖P₋|ψ⟩‖` — the collapsed state of +Postulate 4 after the `±1` measurement of `A` yields `−1`, defined when `P₋|ψ⟩ ≠ 0` (i.e. when `−1` +is a possible outcome). It is the `−1` eigenstate of `A`. The `−1` sibling of +`Observable.postMeasPlus`. -/ +def postMeasMinus (A : Observable S) (ψ : PureState S) (hne : A.projMinus ψ.vec ≠ 0) : + PureState S := + PureState.normalize (A.projMinus ψ.vec) hne + +@[simp] +theorem postMeasMinus_vec (A : Observable S) (ψ : PureState S) (hne : A.projMinus ψ.vec ≠ 0) : + (A.postMeasMinus ψ hne).vec = ((‖A.projMinus ψ.vec‖ : ℝ) : ℂ)⁻¹ • A.projMinus ψ.vec := rfl + +/-- **Postulate 4 (state update), `−1` outcome.** When the `±1` measurement of `A` on `|ψ⟩` yields +`−1`, the system collapses to the normalized state `P₋|ψ⟩ / ‖P₋|ψ⟩‖ = postMeasMinus`. The `−1` +sibling of `postMeasurement_signMeasurement_plus`; stated for +`Measurement.postMeasurement`. -/ +theorem postMeasurement_signMeasurement_minus (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) (hne : A.projMinus ψ.vec ≠ 0) + (hp : (A.signMeasurement hinv).bornProb ψ.toState 1 ≠ 0) : + (A.signMeasurement hinv).postMeasurement ψ.toState 1 hp = (A.postMeasMinus ψ hne).toState := by + have htr : RCLike.re (LinearMap.trace ℂ S.space + ↑(ContinuousLinearMap.postOp (A.signMeasurement hinv).op ψ.toState.op 1)) + = ‖A.projMinus ψ.vec‖ ^ 2 := by + rw [postOp_signMeasurement_one, InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq] + apply State.ext + rw [Measurement.postMeasurement_op, ContinuousLinearMap.postState, htr, + postOp_signMeasurement_one, PureState.toState_op, postMeasMinus_vec, + InnerProductSpace.rankOne_smul_smul_self] + congr 1 + rw [map_inv₀, Complex.conj_ofReal] + push_cast + ring + +/-! ### The collapse lands in the eigenspace: the collapsed states are `±1` eigenstates -/ + +/-- **The `+1` collapse is a `+1` eigenstate.** For a `±1` observable `A` (`A² = I`), the +post-measurement state `postMeasPlus = P₊|ψ⟩/‖P₊|ψ⟩‖` is a genuine `+1` eigenstate of `A`: +`A |ψ'⟩ = |ψ'⟩`. From `A·P₊ = P₊` (`op_mul_projPlus`), `P₊|ψ⟩` is a `+1` eigenvector, and rescaling +to the normalized state preserves the eigenvalue (`hasEigenstate_of_smul`). This is Exercise 5.9's +"the post-measurement state is the corresponding eigenvector", `+1` case. -/ +theorem postMeasPlus_hasEigenstate (A : Observable S) (hinv : A.op * A.op = 1) (ψ : PureState S) + (hne : A.projPlus ψ.vec ≠ 0) : + A.HasEigenstate 1 (A.postMeasPlus ψ hne) := by + refine A.hasEigenstate_of_smul (A.postMeasPlus_vec ψ hne) ?_ + have h := congrArg (fun T : S.space →L[ℂ] S.space => T ψ.vec) (A.op_mul_projPlus hinv) + simp only [mul_apply_eq_comp] at h + rw [h, Complex.ofReal_one, one_smul] + +/-- **The `−1` collapse is a `−1` eigenstate.** For a `±1` observable `A` (`A² = I`), the +post-measurement state `postMeasMinus = P₋|ψ⟩/‖P₋|ψ⟩‖` is a genuine `−1` eigenstate of `A`: +`A |ψ'⟩ = −|ψ'⟩`. From `A·P₋ = −P₋` (`op_mul_projMinus`), `P₋|ψ⟩` is a `−1` eigenvector, and +rescaling to the normalized state preserves the eigenvalue. This is Exercise 5.9's "post-measurement +state +is the corresponding eigenvector", `−1` case. -/ +theorem postMeasMinus_hasEigenstate (A : Observable S) (hinv : A.op * A.op = 1) (ψ : PureState S) + (hne : A.projMinus ψ.vec ≠ 0) : + A.HasEigenstate (-1) (A.postMeasMinus ψ hne) := by + refine A.hasEigenstate_of_smul (A.postMeasMinus_vec ψ hne) ?_ + have h := congrArg (fun T : S.space →L[ℂ] S.space => T ψ.vec) (A.op_mul_projMinus hinv) + simp only [mul_apply_eq_comp, _root_.neg_apply] at h + rw [h] + push_cast + module + +end Observable + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Eigenstate.lean b/LeanPool/AxQM/Postulates/API/Eigenstate.lean new file mode 100644 index 0000000000..18f3403407 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Eigenstate.lean @@ -0,0 +1,69 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Observable + +/-! +# AxQM.Postulates.API — eigenstates of an observable (general) + +Definitions and lemmas for the **eigenstates** of an observable, gate-agnostic and +reusable across every Nielsen–Chuang item that needs them (Exercise 2.53's Hadamard +eigendecomposition, Exercise 2.58's average/standard deviation in an eigenstate, …). + +* `Observable.HasEigenstate A μ ψ` — the pure-state eigenvalue equation `A ψ = μ ψ` of an + observable, with the eigenvalue `μ : ℝ` explicit (an observable's eigenvalues are its real + possible measurement values). +* `Observable.hasEigenstate_of_smul` — an eigenstate is unchanged by rescaling the underlying + vector, so the eigenvalue equation may be checked on an unnormalized representative and + transported to the normalized `PureState`. +* `PureState.expectation_of_hasEigenstate` — the expectation value of an observable in one of its + eigenstates *is* the eigenvalue: `⟪A⟫_ψ = μ`. The physical meaning of an eigenvalue as the + measurement outcome obtained with certainty. + +These three declarations were first introduced for Exercise 2.53 in +`AxQM/Postulates/API/HadamardEigen.lean`; they are reused, for instance, by the statistics +definitions in `AxQM/Postulates/API/Variance.lean` for Exercise 2.58. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **`ψ` is an eigenstate of the observable `A` with eigenvalue `μ`.** The pure-state eigenvalue +equation `A ψ = μ ψ` of an observable, with the eigenvalue `μ : ℝ` explicit (an observable's +eigenvalues are real — its possible measurement values). -/ +def Observable.HasEigenstate (A : Observable S) (μ : ℝ) (ψ : PureState S) : Prop := + A.op ψ.vec = (μ : ℂ) • ψ.vec + +/-- An eigenstate is unchanged by rescaling the underlying vector: if `A v = μ v` and `ψ`'s vector +is a scalar multiple `c • v` of `v`, then `ψ` is an eigenstate of `A` with eigenvalue `μ`. This lets +the eigenvalue equation be verified on an unnormalized representative and transported to the +normalized `PureState`. -/ +theorem Observable.hasEigenstate_of_smul {A : Observable S} {μ : ℝ} {ψ : PureState S} + {c : ℂ} {v : S} (hψ : ψ.vec = c • v) (hv : A.op v = (μ : ℂ) • v) : + A.HasEigenstate μ ψ := by + rw [Observable.HasEigenstate, hψ, map_smul, hv, smul_comm] + +/-- **The expectation value of an observable in one of its eigenstates equals the eigenvalue.** If +`ψ` is an eigenstate of `A` with eigenvalue `μ`, then `⟪A⟫_ψ = μ`: measuring `A` in `ψ` yields `μ` +with certainty. This is the physical meaning of an eigenvalue as a measurement outcome. -/ +theorem PureState.expectation_of_hasEigenstate {A : Observable S} {μ : ℝ} {ψ : PureState S} + (h : A.HasEigenstate μ ψ) : ψ.expectation A = μ := by + have hop : A.op ψ.vec = (μ : ℂ) • ψ.vec := h + rw [PureState.expectation, hop, inner_smul_right, inner_self_eq_norm_sq_to_K, ψ.normalized] + simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Ensemble.lean b/LeanPool/AxQM/Postulates/API/Ensemble.lean new file mode 100644 index 0000000000..a661185065 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Ensemble.lean @@ -0,0 +1,150 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum + +/-! +# AxQM — ensembles of pure states and the density operator they generate + +An **ensemble of pure states** `{pᵢ, |ψᵢ⟩}` (Nielsen–Chuang §2.4.1) is a finite family of +pure states `|ψᵢ⟩` together with a probability distribution `pᵢ`. Its **density operator** +is the probability-weighted mixture of the pure-state projectors, +`ρ = ∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` (eq. (2.138)). + +This file is the machinery behind **Theorem 2.5** (characterization of density +operators). The theorem says an operator is a density operator (arises from an ensemble) *iff* +it is positive with trace one. In this development a `State` already bundles +"positive with trace one", so the two halves are: + +* **forward** (ensemble ⟹ density operator): `Ensemble.toState` produces a genuine `State`; +* **converse** (density operator ⟹ ensemble): `Ensemble.ofState` builds the *eigenensemble* + (spectral decomposition, eq. (2.157)) and `Ensemble.ofState_toState` shows it reproduces the + state — hence `Ensemble.toState` is onto `State S` (`Ensemble.toState_surjective`, in + `LeanPool/AxQM/NC/Ch2/Theorem5.lean`). + +## Main definitions + +* `AxQM.Ensemble` — an ensemble of pure states: a finite family of `PureState`s with a + probability distribution. +* `AxQM.Ensemble.toState` — the density operator `∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` of an ensemble. +* `AxQM.Ensemble.ofState` — the eigenensemble of a state (spectral decomposition). + +## Main results + +* `Ensemble.toState_op` / `Ensemble.toState_op_apply` — the `_op` bridges: the ensemble's operator + is `∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|`. +* `Ensemble.ofState_toState` — the eigenensemble reproduces the state (converse of Theorem 2.5). +* `isDensityOp_iff_exists_ensemble` — Theorem 2.5, operator form: `T` is a density operator iff it + is the density operator of some ensemble. +-/ + +@[expose] public section + +open scoped ComplexOrder InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- An **ensemble of pure states** `{pᵢ, |ψᵢ⟩}` of a quantum system `S` (Nielsen–Chuang §2.4.1): +a finite family of pure states `states i` together with a probability distribution `prob i` +(non-negative, summing to one). The generating data for a (possibly mixed) density operator. -/ +structure Ensemble (S : QSystem) where + /-- The number of pure states in the ensemble. -/ + card : ℕ + /-- The probability weights `pᵢ` of the ensemble. -/ + prob : Fin card → ℝ + /-- The pure states `|ψᵢ⟩` of the ensemble. -/ + states : Fin card → PureState S + /-- Each probability is non-negative. -/ + prob_nonneg : ∀ i, 0 ≤ prob i + /-- The probabilities sum to one. -/ + sum_prob : ∑ i, prob i = 1 + +namespace Ensemble + +/-- The **density operator of an ensemble** `{pᵢ, |ψᵢ⟩}` (Nielsen–Chuang eq. (2.138)): the state +`ρ = ∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|`, the probability-weighted mixture of the pure-state projectors. This is the +*forward* half of Theorem 2.5 — every ensemble yields a genuine density operator — captured by the +target type `State S`: positivity is a sum of `pᵢ • (positive)` with `pᵢ ≥ 0`, and the trace is +`∑ᵢ pᵢ · 1 = ∑ᵢ pᵢ = 1`. -/ +def toState (e : Ensemble S) : State S where + op := ∑ i, (e.prob i : ℂ) • (e.states i).toState.op + isDensity := by + refine ⟨?_, ?_⟩ + · exact ContinuousLinearMap.isPositive_sum _ fun i _ => + (e.states i).toState.isPositive_op.smul_of_nonneg (by exact_mod_cast e.prob_nonneg i) + · rw [ContinuousLinearMap.toLinearMap_sum, map_sum] + simp only [ContinuousLinearMap.toLinearMap_smul, map_smul, State.trace_op_eq_one, smul_eq_mul, + mul_one] + rw [← Complex.ofReal_sum, e.sum_prob, Complex.ofReal_one] + +/-- The **`_op` bridge** for an ensemble's density operator: `ρ = ∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|`, i.e. Nielsen– +Chuang eq. (2.138). Definitional. -/ +theorem toState_op (e : Ensemble S) : + e.toState.op = ∑ i, (e.prob i : ℂ) • (e.states i).toState.op := rfl + +/-- The action of an ensemble's density operator on a vector: `ρ v = ∑ᵢ pᵢ ⟪ψᵢ, v⟫ |ψᵢ⟩`, +obtained from `toState_op` and `rankOne_apply`. The pointwise form consumed by +`Ensemble.ofState_toState`. -/ +theorem toState_op_apply (e : Ensemble S) (v : S) : + e.toState.op v = ∑ i, (e.prob i : ℂ) • (inner ℂ (e.states i).vec v • (e.states i).vec) := by + rw [toState_op, sum_apply] + simp only [smul_apply, PureState.toState_op, InnerProductSpace.rankOne_apply] + +/-- The **eigenensemble** of a state `ρ` (Nielsen–Chuang, converse of Theorem 2.5, eq. (2.157)): +the ensemble `{λⱼ, |j⟩}` whose pure states `|j⟩` form an orthonormal eigenbasis of the density +operator `ρ`, weighted by the eigenvalues `λⱼ`. The eigenvalues are non-negative and sum to one +(`IsDensityOp.eigenvalues_nonneg` / `eigenvalues_sum_eq_one`), so they form a probability +distribution; the eigenvectors are unit vectors (orthonormality). The construction +invokes the spectral theorem. -/ +def ofState (ρ : State S) : Ensemble S where + card := Module.finrank ℂ S.space + prob := ρ.isDensity.isSymmetric.eigenvalues rfl + states i := + ⟨ρ.isDensity.isSymmetric.eigenvectorBasis rfl i, + (ρ.isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal.norm_eq_one i⟩ + prob_nonneg i := ρ.isDensity.eigenvalues_nonneg rfl i + sum_prob := ρ.isDensity.eigenvalues_sum_eq_one rfl + +/-- **The eigenensemble reproduces the state**: `(Ensemble.ofState ρ).toState = ρ` for every state +`ρ`. This is the *converse* half of Nielsen–Chuang Theorem 2.5 — every density operator arises from +an ensemble (here the eigenensemble). Proved by the spectral expansion +`LinearMap.IsSymmetric.spectral_sum_apply`: on each vector `v`, +`ρ v = ∑ⱼ λⱼ ⟪|j⟩, v⟫ |j⟩ = (∑ⱼ λⱼ |j⟩⟨j|) v`. -/ +theorem ofState_toState (ρ : State S) : (ofState ρ).toState = ρ := by + refine State.ext ?_ + refine ContinuousLinearMap.ext fun v => ?_ + rw [toState_op_apply] + exact (ρ.isDensity.isSymmetric.spectral_sum_apply (n := (ofState ρ).card) rfl v).symm + +end Ensemble + +/-- **Nielsen–Chuang Theorem 2.5, operator form.** An operator `T` on a quantum system `S` is a +*density operator* — positive with trace one (`ContinuousLinearMap.IsDensityOp`) — if and only if +it is the density operator `∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` of some ensemble of pure states. The literal rendering +of the textbook "ρ is a density operator iff (1) trace one (2) positive": the `IsDensityOp` +predicate is exactly the trace-and-positivity conditions. + +Forward: pack `T` and its density hypothesis as a `State`, whose eigenensemble +(`Ensemble.ofState` / `ofState_toState`) reproduces it. Backward: an ensemble's operator is a +density operator by construction (`Ensemble.toState`). -/ +theorem isDensityOp_iff_exists_ensemble {T : S →L[ℂ] S} : + T.IsDensityOp ↔ ∃ e : Ensemble S, e.toState.op = T := by + constructor + · intro hT + exact ⟨Ensemble.ofState ⟨T, hT⟩, congrArg State.op (Ensemble.ofState_toState ⟨T, hT⟩)⟩ + · rintro ⟨e, rfl⟩ + exact e.toState.isDensity + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Entropy.lean b/LeanPool/AxQM/Postulates/API/Entropy.lean new file mode 100644 index 0000000000..39d354f840 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Entropy.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy + +/-! +# AxQM — von Neumann entropy of a quantum state + +The **von Neumann entropy** `S(ρ)` of a quantum state `ρ` (Nielsen–Chuang §11.3.1, eq. (11.44)) is + +`S(ρ) = -tr(ρ log ρ) = H(λ₁, …, λ_d)`, + +the Shannon entropy of the eigenvalue spectrum `λ₁, …, λ_d` of the density operator `ρ`. It is the +central quantity of Nielsen–Chuang Chapter 11 and the quantum generalization of the Shannon entropy. + +This file defines `State.vonNeumannEntropy`, the entropy of a state in terms of the operator-level +`ContinuousLinearMap.vonNeumannEntropy` of its density operator, together with the +basic properties collected in Nielsen–Chuang Theorem 11.8: non-negativity, the `log d` upper bound +(attained by the maximally mixed state), and the vanishing of the entropy on pure states. + +## Main definitions + +* `AxQM.State.vonNeumannEntropy` — the von Neumann entropy `S(ρ)` of a state `ρ`. + +## Main results + +* `AxQM.State.vonNeumannEntropy_nonneg` — `S(ρ) ≥ 0`. +* `AxQM.State.vonNeumannEntropy_le_log_finrank` — `S(ρ) ≤ log d`, `d = dim S.space`. +* `AxQM.PureState.vonNeumannEntropy_toState_eq_zero` — a pure state has zero entropy. +* `AxQM.State.vonNeumannEntropy_congr` — entropy is invariant under transport along a + system isomorphism. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- The **von Neumann entropy** `S(ρ) = -tr(ρ log ρ)` of a quantum state `ρ` +(Nielsen–Chuang §11.3.1, eq. (11.44)): the Shannon entropy of the eigenvalue spectrum of the +density operator `ρ.op`. Defined through `ContinuousLinearMap.vonNeumannEntropy`. -/ +noncomputable def State.vonNeumannEntropy (ρ : State S) : ℝ := + ρ.op.vonNeumannEntropy + +/-- The `_op` bridge: the state's von Neumann entropy is the operator-level von Neumann entropy of +its density operator. Holds definitionally; provided so proofs can rewrite +between `State.vonNeumannEntropy` and `ContinuousLinearMap.vonNeumannEntropy`. -/ +theorem State.vonNeumannEntropy_def (ρ : State S) : + ρ.vonNeumannEntropy = ρ.op.vonNeumannEntropy := + rfl + +/-- **Non-negativity of the von Neumann entropy** (Nielsen–Chuang Theorem 11.8, first item): +`S(ρ) ≥ 0`, since the eigenvalues of a density operator form a probability distribution and Shannon +entropy is non-negative. -/ +theorem State.vonNeumannEntropy_nonneg (ρ : State S) : 0 ≤ ρ.vonNeumannEntropy := + ρ.isDensity.vonNeumannEntropy_nonneg + +/-- **Upper bound on the von Neumann entropy** (Nielsen–Chuang Theorem 11.8, second item): +`S(ρ) ≤ log d` where `d = dim S.space`, with equality for the maximally mixed state. The +nontriviality of `S.space` needed by the underlying bound comes from `State.nontrivial_space`. -/ +theorem State.vonNeumannEntropy_le_log_finrank (ρ : State S) : + ρ.vonNeumannEntropy ≤ Real.log (Module.finrank ℂ S.space : ℝ) := by + have := ρ.nontrivial_space + exact ρ.isDensity.vonNeumannEntropy_le_log_dim + +/-- **A pure state has zero von Neumann entropy** (Nielsen–Chuang Theorem 11.8, purity item): +`S(|ψ⟩⟨ψ|) = 0`, since the density operator `|ψ⟩⟨ψ|` of a pure state is a rank-one projector whose +spectrum is `(1, 0, …, 0)`. -/ +theorem PureState.vonNeumannEntropy_toState_eq_zero (ψ : PureState S) : + ψ.toState.vonNeumannEntropy = 0 := by + rw [State.vonNeumannEntropy_def, ψ.toState_op] + exact ContinuousLinearMap.vonNeumannEntropy_rankOne_self ψ.normalized + +/-- **Invariance of the von Neumann entropy under transport**: a system isomorphism does not +change the entropy, `S(e ρ e⁻¹) = S(ρ)`. Rides the operator-level invariance +`ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv` (conjugating by an isometry preserves +the eigenvalue spectrum, hence the entropy) through the `State.congr` transport. The entropy +counterpart of `State.expectation_congr`; used e.g. to read the entropy of a re-associated +tripartite state (strong subadditivity, N&C Theorem 11.14). -/ +@[simp] theorem State.vonNeumannEntropy_congr {S T : QSystem} (e : S ≃ₛ T) (ρ : State S) : + (ρ.congr e).vonNeumannEntropy = ρ.vonNeumannEntropy := by + rw [State.vonNeumannEntropy_def, State.congr_op, + ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv, ← State.vonNeumannEntropy_def] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyComposite.lean b/LeanPool/AxQM/Postulates/API/EntropyComposite.lean new file mode 100644 index 0000000000..ee9dae82b6 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyComposite.lean @@ -0,0 +1,84 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM — von Neumann entropy of product and maximally mixed states + +Two basic values of the von Neumann entropy generator `State.vonNeumannEntropy` +(`AxQM/Postulates/API/Entropy.lean`), needed throughout Nielsen & Chuang Chapter 11: + +* **Additivity over a product state** `S(ρ ⊗ σ) = S(ρ) + S(σ)` (N&C Exercise 11.13): + the entropy of an uncorrelated composite is the sum of the parts. Lifts the operator-level + theorem `ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_tensorMap` to the `State` + abstraction through `State.tmul`. +* **The maximally mixed value** `S(I/d) = log d` (N&C Theorem 11.8): the maximally mixed + state `maximallyMixedState S` attains the `log d` upper bound + (`State.vonNeumannEntropy_le_log_finrank`), since all `d` eigenvalues of `I/d` equal `1/d` + and `H(1/d, …, 1/d) = log d`. + +They are the two entropy values used in the counterexamples and computations of +the chapter (e.g. Problem 11.3). + +## Main results + +* `AxQM.State.vonNeumannEntropy_tmul` — `S(ρ ⊗ σ) = S(ρ) + S(σ)`. +* `AxQM.State.vonNeumannEntropy_maximallyMixed` — `S(I/d) = log d`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Additivity of the von Neumann entropy over a product state** (Nielsen & Chuang, +Exercise 11.13): for states `ρ : State S` and `σ : State T`, the entropy of the uncorrelated +composite `ρ ⊗ σ` is the sum of the entropies, + +`S(ρ ⊗ σ) = S(ρ) + S(σ)`. + +Proved by unfolding the entropy to its density operator `State.tmul_op` +(`(ρ ⊗ σ).op = ρ.op ⊗ σ.op`) and applying the operator-level theorem +`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_tensorMap`, using the density-operator +witnesses `ρ.isDensity` / `σ.isDensity`. -/ +theorem State.vonNeumannEntropy_tmul (ρ : State S) (σ : State T) : + (ρ.tmul σ).vonNeumannEntropy = ρ.vonNeumannEntropy + σ.vonNeumannEntropy := by + rw [State.vonNeumannEntropy_def, State.vonNeumannEntropy_def, State.vonNeumannEntropy_def, + State.tmul_op] + have hkey : (TensorProduct.mapL ρ.op σ.op).vonNeumannEntropy + = ρ.op.vonNeumannEntropy + σ.op.vonNeumannEntropy := by + rw [← ContinuousLinearMap.vonNeumannEntropy_toLinearMap (T := TensorProduct.mapL ρ.op σ.op), + TensorProduct.toLinearMap_mapL] + exact ρ.isDensity.vonNeumannEntropy_tensorMap σ.isDensity + exact hkey + +/-- **Von Neumann entropy of the maximally mixed state** (Nielsen & Chuang, Theorem 11.8): the +maximally mixed state `I/d = maximallyMixedState S` has entropy + +`S(I/d) = log d`, where `d = dim S.space`, + +attaining the upper bound `State.vonNeumannEntropy_le_log_finrank`. A thin lift of the +operator-level lemma `ContinuousLinearMap.vonNeumannEntropy_finrank_inv_smul_one` (the pure spectral +computation that every eigenvalue of `(1/d) • I` equals `1/d`, so the entropy is the Shannon +entropy of the uniform spectrum `log d`) through `maximallyMixedState_op`. -/ +theorem State.vonNeumannEntropy_maximallyMixed (S : QSystem) [Nontrivial S.space] : + (maximallyMixedState S).vonNeumannEntropy = Real.log (Module.finrank ℂ S.space) := by + rw [State.vonNeumannEntropy_def, maximallyMixedState_op, + ContinuousLinearMap.vonNeumannEntropy_finrank_inv_smul_one] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyConcavity.lean b/LeanPool/AxQM/Postulates/API/EntropyConcavity.lean new file mode 100644 index 0000000000..f09ab53015 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyConcavity.lean @@ -0,0 +1,288 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RelativeEntropy +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyMixture + +/-! +# AxQM — concavity of the von Neumann entropy and its equality condition + +The von Neumann entropy is a **concave** function of its input (Nielsen & Chuang, +*Quantum Computation and Quantum Information*, §11.3.5, eq. (11.79)): for a probability +distribution `p` and a family of states `ρ : ι → State S`, + +`∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)`, + +and, moreover, the entropy is *strictly* concave — equality holds iff all the `ρᵢ` with `pᵢ > 0` +coincide (N&C **Exercise 11.18**). Both facts flow from a single algebraic identity relating the +concavity gap to the average relative entropy of the components to the mixture, + +`S(∑ᵢ pᵢ ρᵢ) − ∑ᵢ pᵢ S(ρᵢ) = ∑ᵢ pᵢ S(ρᵢ ‖ ∑ⱼ pⱼ ρⱼ)`, (†) + +which is the `State`-level form of the operator identity +`ContinuousLinearMap.sum_mul_quantumRelativeEntropy_mix`. Klein's inequality +(`State.quantumRelativeEntropy_nonneg`, `S(ρ ‖ σ) ≥ 0`) makes the right-hand side non-negative, +giving concavity; its equality condition (`State.quantumRelativeEntropy_eq_zero_iff`, +`S(ρ ‖ σ) = 0 ↔ ρ = σ`) turns the vanishing of the gap into the component-equality condition. + +This is a cleaner route than N&C's own proof (which derives concavity from subadditivity via an +auxiliary system `B` and reads the equality condition off the subadditivity equality condition +`ρ_AB = ρ_A ⊗ ρ_B`): identity (†) is exactly the relative-entropy content of that argument, +already proved for operators in `ToMathlib`. + +## Faithfulness + +Klein's inequality and its equality condition hold, in the finite real-valued branch of this +library, only for a **faithful** second argument — every eigenvalue of `σ.op` strictly positive +(`IsStrictlyPositive`; see `AxQM/Postulates/API/RelativeEntropy.lean` for why finiteness +forces this). Here the second argument is the mixture `μ = ∑ᵢ pᵢ ρᵢ`, so the concavity inequality +and its equality condition are stated with the hypothesis `IsStrictlyPositive μ.op` — the mixture +is full rank. This is the weakest faithfulness hypothesis for the argument (it does **not** require +the individual `ρᵢ` to be faithful) and is the finite-branch convention shared with the rest of the +Chapter 11 entropy cluster (Klein's inequality, joint convexity, subadditivity, strong +subadditivity). The mixing **identity** (†) itself needs no faithfulness — it holds for every +family of states. + +## Main results + +The statement of N&C Exercise 11.18 is in [upstream `AxQM/NC/Ch11/Exercise11_18.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Exercise11_18.lean); the +declarations are here. + +* `AxQM.State.sum_mul_quantumRelativeEntropy_mix` — the mixing identity (†). +* `AxQM.State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix` — concavity of the von + Neumann entropy (N&C eq. (11.79)), `∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)`, for a faithful mixture. +* `AxQM.State.vonNeumannEntropy_mix_eq_sum_iff` — **Exercise 11.18**: equality holds in the + concavity inequality iff all the components with positive weight coincide. +* `AxQM.State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'` / + `AxQM.State.vonNeumannEntropy_mix_eq_sum_iff'` — the **faithfulness-free** forms of the + concavity inequality and its equality condition (via the support-condition Klein inequality), + needed for the generally rank-deficient pinched state of Exercise 11.20. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **The mixing identity for the von Neumann entropy.** The concavity gap of a mixture +`μ = ∑ᵢ pᵢ ρᵢ` equals the average relative entropy of the components to the mixture: + +`∑ᵢ pᵢ S(ρᵢ ‖ μ) = S(μ) − ∑ᵢ pᵢ S(ρᵢ)`. + +This is the algebraic heart of both the concavity inequality (N&C eq. (11.79)) and its equality +condition (N&C Exercise 11.18); no faithfulness is needed. Lifts the operator identity +`ContinuousLinearMap.sum_mul_quantumRelativeEntropy_mix` to states through the `_def` lemmas and +`State.mix_op` (`μ.op = ∑ᵢ (pᵢ : ℂ) • ρᵢ.op`). -/ +theorem State.sum_mul_quantumRelativeEntropy_mix {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + ∑ i, p i * (ρ i).quantumRelativeEntropy (State.mix p hp hsum ρ) + = (State.mix p hp hsum ρ).vonNeumannEntropy - ∑ i, p i * (ρ i).vonNeumannEntropy := by + simp only [State.quantumRelativeEntropy_def, State.vonNeumannEntropy_def] + exact ContinuousLinearMap.sum_mul_quantumRelativeEntropy_mix + (fun i => (ρ i).isDensity) p (State.mix p hp hsum ρ).isDensity (State.mix_op p hp hsum ρ) + +/-- **Concavity of the von Neumann entropy** (Nielsen & Chuang §11.3.5, eq. (11.79)): for a +probability distribution `p` and a family of states `ρ : ι → State S` whose mixture +`μ = ∑ᵢ pᵢ ρᵢ` is **faithful** (`IsStrictlyPositive μ.op`), + +`∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)`. + +Immediate from the mixing identity `State.sum_mul_quantumRelativeEntropy_mix`: the concavity gap is +the average relative entropy `∑ᵢ pᵢ S(ρᵢ ‖ μ)`, non-negative because each `pᵢ ≥ 0` and each +`S(ρᵢ ‖ μ) ≥ 0` is Klein's inequality (`State.quantumRelativeEntropy_nonneg`) for the faithful +mixture `μ`. See the module docstring for the finite-branch faithfulness convention. -/ +theorem State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (hμ : IsStrictlyPositive (State.mix p hp hsum ρ).op) : + ∑ i, p i * (ρ i).vonNeumannEntropy ≤ (State.mix p hp hsum ρ).vonNeumannEntropy := by + have hμ_pos : ∀ j, 0 < (State.mix p hp hsum ρ).isDensity.isSymmetric.eigenvalues rfl j := + fun j => hμ.eigenvalues_pos _ rfl j + have hid := State.sum_mul_quantumRelativeEntropy_mix p hp hsum ρ + have hnn : 0 ≤ ∑ i, p i * (ρ i).quantumRelativeEntropy (State.mix p hp hsum ρ) := + Finset.sum_nonneg fun i _ => + mul_nonneg (hp i) (State.quantumRelativeEntropy_nonneg _ _ hμ_pos) + linarith [hid, hnn] + +/-- **Equality in the concavity inequality — strict concavity of the von Neumann entropy** +(Nielsen & Chuang **Exercise 11.18**): for a probability distribution `p` and a family of states +`ρ : ι → State S` whose mixture `μ = ∑ᵢ pᵢ ρᵢ` is **faithful** (`IsStrictlyPositive μ.op`), +equality holds in the concavity inequality (11.79), + +`S(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ S(ρᵢ)`, + +**iff all the components carrying positive weight are identical**, +`∀ i j, 0 < pᵢ → 0 < pⱼ → ρᵢ = ρⱼ`. (This is the precise reading of N&C's "all the `ρᵢ`s are the +same": components with `pᵢ = 0` are free, as they do not enter the mixture.) + +Proof via the mixing identity `State.sum_mul_quantumRelativeEntropy_mix`: the concavity gap is the +average relative entropy `∑ᵢ pᵢ S(ρᵢ ‖ μ)`, a sum of non-negative terms (Klein's inequality for the +faithful `μ`), so it vanishes iff each `pᵢ S(ρᵢ ‖ μ) = 0` +(`Finset.sum_eq_zero_iff_of_nonneg`). For `pᵢ > 0` this forces `S(ρᵢ ‖ μ) = 0`, i.e. `ρᵢ = μ` by the +equality condition of Klein's inequality (`State.quantumRelativeEntropy_eq_zero_iff`). Hence +equality ↔ every positive-weight component equals the average `μ` ↔ all positive-weight components +coincide (the reverse implication computes `μ = ρᵢ` from `μ.op = ∑ⱼ (pⱼ : ℂ) • ρⱼ.op` with the +common value factored out and `∑ⱼ pⱼ = 1`). See the module docstring for the faithfulness +convention. -/ +theorem State.vonNeumannEntropy_mix_eq_sum_iff {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (hμ : IsStrictlyPositive (State.mix p hp hsum ρ).op) : + (State.mix p hp hsum ρ).vonNeumannEntropy = ∑ i, p i * (ρ i).vonNeumannEntropy + ↔ ∀ i j, 0 < p i → 0 < p j → ρ i = ρ j := by + classical + have hid := State.sum_mul_quantumRelativeEntropy_mix p hp hsum ρ + have hμ_pos : ∀ j, 0 < (State.mix p hp hsum ρ).isDensity.isSymmetric.eigenvalues rfl j := + fun j => hμ.eigenvalues_pos _ rfl j + have hterm : ∀ i ∈ Finset.univ, + 0 ≤ p i * (ρ i).quantumRelativeEntropy (State.mix p hp hsum ρ) := + fun i _ => mul_nonneg (hp i) (State.quantumRelativeEntropy_nonneg _ _ hμ_pos) + set μ := State.mix p hp hsum ρ with hμdef + -- Reduce the entropy equality to the vanishing of every weighted relative-entropy term. + rw [← sub_eq_zero, ← hid, Finset.sum_eq_zero_iff_of_nonneg hterm] + constructor + · -- equality ⇒ every positive-weight component equals the average `μ`, hence all coincide + intro hall i j hpi hpj + have key : ∀ k, 0 < p k → ρ k = μ := by + intro k hpk + have hD : (ρ k).quantumRelativeEntropy μ = 0 := by + rcases mul_eq_zero.mp (hall k (Finset.mem_univ k)) with h | h + · exact absurd h (ne_of_gt hpk) + · exact h + exact (State.quantumRelativeEntropy_eq_zero_iff (ρ k) μ hμ_pos).mp hD + rw [key i hpi, key j hpj] + · -- all positive-weight components coincide ⇒ each equals `μ` ⇒ its relative entropy vanishes + intro hall i _ + rcases eq_or_lt_of_le (hp i) with h0 | hpos + · simp [← h0] + · have hiμ : ρ i = μ := + (State.mix_eq_of_forall_pos_eq p hp hsum ρ (ρ i) fun j hpj => hall j i hpj hpos).symm + rw [(State.quantumRelativeEntropy_eq_zero_iff (ρ i) μ hμ_pos).mpr hiμ, mul_zero] + +section Nonfaithful + +open ContinuousLinearMap +open scoped ComplexOrder + +/-- **Every component of a mixture is supported inside the mixture.** For a probability distribution +`p`, a family `ρ : ι → State S`, and an index `i` with `0 < pᵢ`, the density operator of `ρ i` is +supported inside that of the mixture `μ = ∑ⱼ pⱼ ρⱼ`, i.e. `(ρ i).op.HasSupportLE μ.op` +(`ker μ.op ≤ ker (ρ i).op`). + +This is the atomic fact behind faithfulness-free concavity below: a vector `x` killed by the mixture +satisfies `0 = ⟪x, μ.op x⟫ = ∑ⱼ pⱼ ⟪x, ρⱼ.op x⟫`, a sum of non-negative complex terms (each `ρⱼ.op` +positive, each `pⱼ ≥ 0`); it therefore vanishes termwise, and the `i`-th term with `pᵢ > 0` forces +`⟪x, ρᵢ.op x⟫ = 0`, whence `ρᵢ.op x = 0` because a positive operator annihilates the vectors on +which its quadratic form vanishes (`ContinuousLinearMap.apply_eq_zero_of_re_inner_self_eq_zero`). -/ +theorem State.hasSupportLE_mix {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (i : ι) (hpi : 0 < p i) : + (ρ i).op.HasSupportLE (State.mix p hp hsum ρ).op := by + rw [ContinuousLinearMap.hasSupportLE_iff] + intro x hx + rw [LinearMap.mem_ker] at hx ⊢ + simp only [ContinuousLinearMap.coe_coe] at hx ⊢ + -- `hx : (State.mix …).op x = 0`, goal `(ρ i).op x = 0`. + have hzsum : ∑ j, (p j : ℂ) * inner ℂ x ((ρ j).op x) = 0 := by + have h0 : inner ℂ x ((State.mix p hp hsum ρ).op x) = 0 := by rw [hx]; simp + rw [State.mix_op, _root_.sum_apply, inner_sum] at h0 + rw [← h0] + exact Finset.sum_congr rfl fun j _ => by + rw [_root_.smul_apply, inner_smul_right] + have hznn : ∀ j ∈ (Finset.univ : Finset ι), (0 : ℂ) ≤ (p j : ℂ) * inner ℂ x ((ρ j).op x) := + fun j _ => mul_nonneg (by exact_mod_cast hp j) ((ρ j).isDensity.isPositive.inner_nonneg_right x) + have hzi : (p i : ℂ) * inner ℂ x ((ρ i).op x) = 0 := + (Finset.sum_eq_zero_iff_of_nonneg hznn).mp hzsum i (Finset.mem_univ i) + have hpi' : (p i : ℂ) ≠ 0 := by exact_mod_cast ne_of_gt hpi + have hinner0 : inner ℂ x ((ρ i).op x) = 0 := (mul_eq_zero.mp hzi).resolve_left hpi' + exact ContinuousLinearMap.apply_eq_zero_of_re_inner_self_eq_zero + (ContinuousLinearMap.nonneg_iff_isPositive.mpr (ρ i).isDensity.isPositive) + (by rw [hinner0]; simp) + +-- The `State`-level support-condition Klein inequalities +-- (`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` and +-- `…_eq_zero_iff_of_hasSupportLE`) are the faithful finite-branch form of N&C Theorem 11.7 and +-- are in `AxQM.Postulates.API.RelativeEntropy` (imported above); they +-- are applied below through the mixture support fact `State.hasSupportLE_mix`. + +/-- **Concavity of the von Neumann entropy — faithfulness-free form** (Nielsen & Chuang eq. (11.79) +in full generality). For any probability distribution `p` and family `ρ : ι → State S`, + +`∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)`, + +with **no faithfulness hypothesis** on the mixture. This strengthens +`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix` (which assumes a faithful mixture, +`IsStrictlyPositive μ.op`); the faithfulness-free *equality* condition is +`State.vonNeumannEntropy_mix_eq_sum_iff'` below (via the support-condition Klein equality case). The +faithfulness-free form is what makes both applicable to the generally rank-deficient pinched state +of Exercise 11.20. + +Proof: the mixing identity `State.sum_mul_quantumRelativeEntropy_mix` writes the concavity gap as +`∑ᵢ pᵢ S(ρᵢ ‖ μ)`; each summand is `≥ 0` because for `pᵢ > 0` the support condition +`HasSupportLE (ρᵢ) μ` holds (`State.hasSupportLE_mix`), so the support-condition Klein inequality +`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` applies, while a `pᵢ = 0` summand vanishes. -/ +theorem State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix' {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + ∑ i, p i * (ρ i).vonNeumannEntropy ≤ (State.mix p hp hsum ρ).vonNeumannEntropy := by + have hid := State.sum_mul_quantumRelativeEntropy_mix p hp hsum ρ + have hnn : 0 ≤ ∑ i, p i * (ρ i).quantumRelativeEntropy (State.mix p hp hsum ρ) := by + refine Finset.sum_nonneg fun i _ => ?_ + rcases eq_or_lt_of_le (hp i) with h0 | hpos + · rw [← h0]; simp + · exact mul_nonneg (hp i) ((ρ i).quantumRelativeEntropy_nonneg_of_hasSupportLE _ + (State.hasSupportLE_mix p hp hsum ρ i hpos)) + linarith [hid, hnn] + +/-- **Equality in the concavity inequality — strict concavity, faithfulness-free form.** For any +probability distribution `p` and family `ρ : ι → State S`, equality in the (faithfulness-free) +concavity inequality `∑ᵢ pᵢ S(ρᵢ) ≤ S(∑ᵢ pᵢ ρᵢ)` holds **iff every component carrying positive +weight equals the mixture**: + +`S(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ S(ρᵢ) ↔ ∀ i, 0 < pᵢ → ρᵢ = ∑ⱼ pⱼ ρⱼ`. + +Unlike `State.vonNeumannEntropy_mix_eq_sum_iff` (Exercise 11.18, which assumes a **faithful** +mixture `IsStrictlyPositive μ.op`) this needs **no faithfulness**: it runs the same mixing-identity +argument but discharges the equality case of Klein's inequality through the *support condition* +(`State.hasSupportLE_mix` — each positive-weight component is supported inside the mixture — and the +support-condition Klein equality `State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE`). It +therefore applies to the generally rank-deficient pinched state of Exercise 11.20, where it supplies +the equality case of the concavity-based alternate proof of Theorem 11.9. -/ +theorem State.vonNeumannEntropy_mix_eq_sum_iff' {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + (State.mix p hp hsum ρ).vonNeumannEntropy = ∑ i, p i * (ρ i).vonNeumannEntropy + ↔ ∀ i, 0 < p i → ρ i = State.mix p hp hsum ρ := by + classical + have hid := State.sum_mul_quantumRelativeEntropy_mix p hp hsum ρ + set μ := State.mix p hp hsum ρ with hμdef + have hterm : ∀ i ∈ (Finset.univ : Finset ι), 0 ≤ p i * (ρ i).quantumRelativeEntropy μ := by + intro i _ + rcases eq_or_lt_of_le (hp i) with h0 | hpos + · rw [← h0, zero_mul] + · exact mul_nonneg (hp i) ((ρ i).quantumRelativeEntropy_nonneg_of_hasSupportLE _ + (State.hasSupportLE_mix p hp hsum ρ i hpos)) + have hequiv : (μ.vonNeumannEntropy = ∑ i, p i * (ρ i).vonNeumannEntropy) + ↔ (∑ i, p i * (ρ i).quantumRelativeEntropy μ = 0) := by + rw [hid]; constructor <;> intro hh <;> linarith + rw [hequiv, Finset.sum_eq_zero_iff_of_nonneg hterm] + constructor + · intro hall i hpi + have hD : (ρ i).quantumRelativeEntropy μ = 0 := + (mul_eq_zero.mp (hall i (Finset.mem_univ i))).resolve_left (ne_of_gt hpi) + exact (State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE (ρ i) μ + (State.hasSupportLE_mix p hp hsum ρ i hpi)).mp hD + · intro hall i _ + rcases eq_or_lt_of_le (hp i) with h0 | hpos + · rw [← h0, zero_mul] + · rw [(State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE (ρ i) μ + (State.hasSupportLE_mix p hp hsum ρ i hpos)).mpr (hall i hpos), mul_zero] + +end Nonfaithful + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyEvolution.lean b/LeanPool/AxQM/Postulates/API/EntropyEvolution.lean new file mode 100644 index 0000000000..ba324aa4de --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyEvolution.lean @@ -0,0 +1,61 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# AxQM — invariance of the von Neumann entropy under unitary evolution + +The von Neumann entropy is unchanged by unitary evolution: + +`S(U ρ U†) = S(ρ)`. + +This is the operator-conjugation counterpart of the transport-invariance lemma +`State.vonNeumannEntropy_congr` (entropy is unchanged along a *system* isomorphism): here the +isometry equivalence is the one packaged from the unitary `U` itself (`Evolution.toIsometryEquiv`), +so `U ρ U†` is `U.toIsometryEquiv`-conjugate to `ρ` and hence has the same eigenvalue spectrum. + +It is the first ingredient of Nielsen & Chuang's proof of **Theorem 11.15(3)** (quantum operations +never increase mutual information, p. 523): that proof dilates the channel on `B` to a unitary +interaction `U` on `B ⊗ C` with a pure ancilla, and uses that this *local* unitary changes neither +the joint entropy `S(A,B,C)` nor the marginal entropy `S(B,C)`, so the mutual information `S(A:B,C)` +is preserved. Both of those invariances are instances of the lemma below (applied to the joint state +and to the `B ⊗ C`-marginal). The full Theorem 11.15(3) is +`State.vonNeumannMutualInfo_dilatedChannelOnRight_le` in `LeanPool/AxQM/NC/Ch11/Theorem15.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Unitary invariance of the von Neumann entropy**: conjugation by a unitary evolution leaves the +entropy unchanged, `S(U ρ U†) = S(ρ)`. Unitary conjugation preserves the eigenvalue spectrum, so it +preserves the Shannon entropy of that spectrum. Proved by exhibiting `U.evolve ρ = U ρ U†` as the +`U.toIsometryEquiv`-conjugate of `ρ` (the bridge `Evolution.evolve_op_conjStarAlgEquiv`) and +invoking the operator fact `ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv`. No faithfulness +hypothesis is needed — the entropy of any state is preserved. + +The operator-conjugation counterpart of `State.vonNeumannEntropy_congr` (invariance along a system +isomorphism); a building block of Nielsen & Chuang Theorem 11.15(3). -/ +@[simp] theorem State.vonNeumannEntropy_evolve (U : Evolution S) (ρ : State S) : + (U.evolve ρ).vonNeumannEntropy = ρ.vonNeumannEntropy := by + -- `U ρ U†` is the conjugate of `ρ` by the isometry equivalence `U.toIsometryEquiv` + -- (`Evolution.evolve_op_conjStarAlgEquiv`), and conjugation preserves the spectrum. + rw [State.vonNeumannEntropy_def, State.vonNeumannEntropy_def, + Evolution.evolve_op_conjStarAlgEquiv, ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyJointTheorem.lean b/LeanPool/AxQM/Postulates/API/EntropyJointTheorem.lean new file mode 100644 index 0000000000..e099754b11 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyJointTheorem.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.EntropyOrthogonalMixture +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PosNegPart +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneProjector + +/-! +# AxQM — the joint entropy theorem (N&C Thm 11.8, part 5 / eq. (11.58)) + +The **joint entropy theorem** (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.8, part (5), eq. (11.58)): for a probability distribution `pᵢ`, an orthonormal family +of pure states `|i⟩` of a system `A`, and *arbitrary* states `ρᵢ` of a system `B`, + +`S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(pᵢ) + ∑ᵢ pᵢ S(ρᵢ)`. + +N&C obtains this "immediately from the preceding result": the block states `σᵢ := |i⟩⟨i| ⊗ ρᵢ` +have *mutually orthogonal supports* (their `A`-factors are the orthogonal one-dimensional ranges +of `|i⟩⟨i|`), so the orthogonal-support mixture identity of part (4) (eq. (11.57)) applies and gives +`S(∑ᵢ pᵢ σᵢ) = H(p) + ∑ᵢ pᵢ S(σᵢ)`; then tensor additivity `State.vonNeumannEntropy_tmul` +together with the purity of `|i⟩⟨i|` (`PureState.vonNeumannEntropy_toState_eq_zero`) collapses +each `S(σᵢ) = S(|i⟩⟨i|) + S(ρᵢ) = S(ρᵢ)`. + +The one non-trivial step, orthogonality of the block supports, is discharged purely algebraically +by the *vanishing of the block operator products*: for `i ≠ j`, +`σᵢ.op · σⱼ.op = mapL (|i⟩⟨i| · |j⟩⟨j|) (ρᵢ.op · ρⱼ.op) = mapL 0 (…) = 0`, using multiplicativity of +the tensor map (`TensorProduct.mapL_mul`) and the orthonormal-projector annihilation lemma +`InnerProductSpace.rankOne_self_mul_rankOne_self_eq_zero_of_orthonormal` +(`|i⟩⟨i| · |j⟩⟨j| = ⟪i|j⟫ • |i⟩⟨j| = 0` since `⟪i|j⟫ = 0`). That pairwise annihilation is fed to +`State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero` — the operator-product form of the +part-(4) identity, which converts vanishing products to orthogonal supports internally. + +## Main results + +The statement of Theorem 11.8 is in `LeanPool/AxQM/NC/Ch11/Theorem8.lean`; the declaration is here. + +* `AxQM.State.vonNeumannEntropy_jointEntropyTheorem` — Nielsen–Chuang Theorem 11.8 + part (5), the joint entropy theorem `S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {A B : QSystem} + +/-- **The joint entropy theorem** (Nielsen–Chuang Theorem 11.8, part (5), eq. (11.58)). For a +probability distribution `p`, an **orthonormal family of pure states** `|i⟩ = e i` of a system +`A` (`Orthonormal ℂ (fun i => (e i).vec)`), and an *arbitrary* family of states `ρ : ι → State B`, +the von Neumann entropy of the block-diagonal composite `∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ` is the Shannon entropy +of the weights plus the `p`-average of the component entropies: + +`S(∑ᵢ pᵢ |i⟩⟨i| ⊗ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. + +This applies the orthogonal-support mixture identity of part (4), through its operator-product +form `State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero`, to the block states +`σᵢ = (e i).toState.tmul (ρ i)`: their operators pairwise annihilate, +`σᵢ.op · σⱼ.op = 0` for `i ≠ j` (the `A`-factors `|i⟩⟨i|`, `|j⟩⟨j|` compose to +`⟪i|j⟫ • |i⟩⟨j| = 0`), and `S(σᵢ) = S(ρᵢ)` by tensor additivity +`State.vonNeumannEntropy_tmul` with `S(|i⟩⟨i|) = 0`. -/ +theorem State.vonNeumannEntropy_jointEntropyTheorem {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (e : ι → PureState A) (he : Orthonormal ℂ fun i => (e i).vec) (ρ : ι → State B) : + (State.mix p hp hsum fun i => (e i).toState.tmul (ρ i)).vonNeumannEntropy + = Real.entropy p + ∑ i, p i * (ρ i).vonNeumannEntropy := by + classical + set σ : ι → State (A.compose B) := fun i => (e i).toState.tmul (ρ i) with hσ + -- The block operators as `|i⟩⟨i| ⊗ ρᵢ`. + have hop : ∀ i, (σ i).op + = TensorProduct.mapL ((InnerProductSpace.rankOne ℂ (e i).vec) (e i).vec) (ρ i).op := by + intro i + simp only [hσ] + rw [State.tmul_op, PureState.toState_op] + -- Distinct blocks have vanishing operator product: `|i⟩⟨i| · |j⟩⟨j| = ⟪i|j⟫ • |i⟩⟨j| = 0`. + have hmul : ∀ i j, i ≠ j → (σ i).op * (σ j).op = 0 := by + intro i j hij + -- `σᵢ.op · σⱼ.op = mapL (|i⟩⟨i| · |j⟩⟨j|) (ρᵢ.op · ρⱼ.op)` by multiplicativity of `mapL`. + have key : (σ i).op * (σ j).op + = TensorProduct.mapL ((InnerProductSpace.rankOne ℂ (e i).vec) (e i).vec + * (InnerProductSpace.rankOne ℂ (e j).vec) (e j).vec) ((ρ i).op * (ρ j).op) := by + rw [hop i, hop j] + exact (TensorProduct.mapL_mul _ _ _ _).symm + -- The flag factors annihilate (`|i⟩⟨i| · |j⟩⟨j| = ⟪i|j⟫ • |i⟩⟨j| = 0`). + rw [key, InnerProductSpace.rankOne_self_mul_rankOne_self_eq_zero_of_orthonormal he hij] + exact TensorProduct.mapL_zero_left _ + -- Each block entropy is `S(ρᵢ)`: tensor additivity with the pure factor contributing `0`. + have hS : ∀ i, (σ i).vonNeumannEntropy = (ρ i).vonNeumannEntropy := by + intro i + simp only [hσ] + rw [State.vonNeumannEntropy_tmul, PureState.vonNeumannEntropy_toState_eq_zero, zero_add] + rw [State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero p hp hsum σ hmul] + simp_rw [hS] + +/-- **The joint entropy theorem, flag-on-the-right form.** For a probability distribution `p`, an +*arbitrary* family of states `ρ : ι → State A`, and an **orthonormal family of pure states** +`|i⟩ = e i` of a *second* system `B` (`Orthonormal ℂ (fun i => (e i).vec)`), the von Neumann entropy +of the block-diagonal composite `∑ᵢ pᵢ ρᵢ ⊗ |i⟩⟨i|` is again the Shannon entropy of the weights plus +the `p`-average of the component entropies: + +`S(∑ᵢ pᵢ ρᵢ ⊗ |i⟩⟨i|) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. + +This is `State.vonNeumannEntropy_jointEntropyTheorem` with the classical flag `|i⟩⟨i|` tensored +on the **right** rather than the left — the orientation needed when the flag is adjoined to a +bipartite payload `ρᵢ` and then re-associated (as in the concavity argument of N&C Exercise 11.25). +The proof is the mirror image of the left form: the block states `σᵢ := ρᵢ ⊗ |i⟩⟨i|` have pairwise +orthogonal supports because for `i ≠ j`, `σᵢ.op · σⱼ.op = mapL (ρᵢ.op · ρⱼ.op) (|i⟩⟨i| · |j⟩⟨j|) = +mapL (…) 0 = 0` (`TensorProduct.mapL_mul`, the annihilation lemma +`InnerProductSpace.rankOne_self_mul_rankOne_self_eq_zero_of_orthonormal`, and +`TensorProduct.mapL_zero_right`), so the orthogonal-support mixture identity applies (through its +operator-product form `State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero`), and +`S(σᵢ) = S(ρᵢ) + S(|i⟩⟨i|) = S(ρᵢ)` by tensor additivity and the purity of the flag. -/ +theorem State.vonNeumannEntropy_mix_tmul_toState_orthonormal_right {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ρ : ι → State A) (e : ι → PureState B) (he : Orthonormal ℂ fun i => (e i).vec) : + (State.mix p hp hsum fun i => (ρ i).tmul (e i).toState).vonNeumannEntropy + = Real.entropy p + ∑ i, p i * (ρ i).vonNeumannEntropy := by + classical + set σ : ι → State (A.compose B) := fun i => (ρ i).tmul (e i).toState with hσ + -- The block operators as `ρᵢ ⊗ |i⟩⟨i|`. + have hop : ∀ i, (σ i).op + = TensorProduct.mapL (ρ i).op ((InnerProductSpace.rankOne ℂ (e i).vec) (e i).vec) := by + intro i + simp only [hσ] + rw [State.tmul_op, PureState.toState_op] + -- Distinct blocks have vanishing operator product: the flag factors compose to zero. + have hmul : ∀ i j, i ≠ j → (σ i).op * (σ j).op = 0 := by + intro i j hij + -- `σᵢ.op · σⱼ.op = mapL (ρᵢ.op · ρⱼ.op) (|i⟩⟨i| · |j⟩⟨j|)` by multiplicativity of `mapL`. + have key : (σ i).op * (σ j).op + = TensorProduct.mapL ((ρ i).op * (ρ j).op) + ((InnerProductSpace.rankOne ℂ (e i).vec) (e i).vec + * (InnerProductSpace.rankOne ℂ (e j).vec) (e j).vec) := by + rw [hop i, hop j] + exact (TensorProduct.mapL_mul _ _ _ _).symm + -- The flag factors annihilate (`|i⟩⟨i| · |j⟩⟨j| = ⟪i|j⟫ • |i⟩⟨j| = 0`). + rw [key, InnerProductSpace.rankOne_self_mul_rankOne_self_eq_zero_of_orthonormal he hij] + exact TensorProduct.mapL_zero_right _ + -- Each block entropy is `S(ρᵢ)`: tensor additivity with the pure flag contributing `0`. + have hS : ∀ i, (σ i).vonNeumannEntropy = (ρ i).vonNeumannEntropy := by + intro i + simp only [hσ] + rw [State.vonNeumannEntropy_tmul, PureState.vonNeumannEntropy_toState_eq_zero, add_zero] + rw [State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero p hp hsum σ hmul] + simp_rw [hS] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyMixLine.lean b/LeanPool/AxQM/Postulates/API/EntropyMixLine.lean new file mode 100644 index 0000000000..60deb08c3c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyMixLine.lean @@ -0,0 +1,277 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.Mixture +public import Mathlib.Analysis.Convex.Deriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.EntropyDeriv +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyContinuous + +/-! +# AxQM — the von Neumann entropy along a mixing line, and the second-derivative +concavity criterion (Nielsen & Chuang Exercise 11.22, Part 1) + +Nielsen & Chuang **Exercise 11.22** ("Alternate proof of concavity", §11.3.5, p. 518) asks, for two +states `ρ, σ`, to define + +`f(p) ≡ S(p ρ + (1 − p) σ)`, + +to **argue that to show concavity it is sufficient to prove that `f''(p) ≤ 0`**, and then to prove +`f''(p) ≤ 0` (first for invertible `ρ, σ`, then in general). This file formalises the **sufficiency +reduction** — the first task — as a self-contained, complete development. Compare +`AxQM/Postulates/API/EntropyConcavity.lean`, which proves concavity of the entropy by the +relative-entropy route. + +* the entropy-along-a-mixing-line function `State.entropyMixLine ρ σ`, with `f(0) = S(σ)`, + `f(1) = S(ρ)`, and, on `[0,1]`, `f(p) = S(p ρ + (1 − p) σ)` (the entropy of the binary mixture + `State.mixPair`); +* the reduction `State.vonNeumannEntropy_concave_of_entropyMixLine_concaveOn`: if `f` is concave on + `[0,1]`, then the two-point concavity inequality `p S(ρ) + (1 − p) S(σ) ≤ S(p ρ + (1 − p) σ)` + (Nielsen & Chuang eq. (11.79) for two components) holds — obtained by reading concavity of `f` at + the endpoints `1, 0`; +* the calculus bridge `State.entropyMixLine_concaveOn_of_deriv2_nonpos`: if `f''(p) ≤ 0` on the + interior of `[0,1]` (with the usual continuity/differentiability, all packaged by Mathlib's + `concaveOn_of_deriv2_nonpos`), then `f` is concave on `[0,1]`; +* their composite `State.vonNeumannEntropy_concave_of_deriv2_nonpos`, which is exactly N&C's + assertion "**to show concavity it is sufficient to prove `f''(p) ≤ 0`**". + +Part 2 below proves `f''(p) ≤ 0`, and hence the concavity of `f`, for invertible `ρ, σ`. The general +case is not proved in this file. + +## Main definitions + +* `AxQM.State.entropyMixLine` — the function `f(p) = S(p ρ + (1 − p) σ)`. + +## Main results + +* `AxQM.State.vonNeumannEntropy_concave_of_entropyMixLine_concaveOn` — concavity of `f` on + `[0,1]` gives the two-point concavity inequality (11.79). +* `AxQM.State.entropyMixLine_concaveOn_of_deriv2_nonpos` — `f'' ≤ 0` gives concavity of + `f`. +* `AxQM.State.vonNeumannEntropy_concave_of_deriv2_nonpos` — the sufficiency reduction: + `f'' ≤ 0` (with smoothness) gives the two-point concavity inequality. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- The **von Neumann entropy along the mixing line** through two states `ρ, σ`: +`f(p) = S(p ρ + (1 − p) σ)` (Nielsen & Chuang Exercise 11.22). Defined as the entropy +of the operator `(p : ℂ) • ρ.op + (1 − p : ℂ) • σ.op` for every real `p`; on the physical interval +`p ∈ [0,1]` this operator is the density operator of the binary mixture `State.mixPair` (see +`State.entropyMixLine_eq_mixPair`), so `f` there is the entropy of an honest state. Extending `f` to +all of `ℝ` (where the operator need not be a density operator, and the entropy is whatever +`ContinuousLinearMap.vonNeumannEntropy` returns) lets `f` be treated as a plain function `ℝ → ℝ`, as +Mathlib's real-variable convexity/derivative API requires. -/ +noncomputable def State.entropyMixLine (ρ σ : State S) (p : ℝ) : ℝ := + ((p : ℂ) • ρ.op + ((1 - p : ℝ) : ℂ) • σ.op).vonNeumannEntropy + +/-- On `[0,1]` the mixing-line entropy is the entropy of the honest binary mixture: for `0 ≤ p ≤ 1`, +`f(p) = S(p ρ + (1 − p) σ) = S(State.mixPair p ρ σ)`. Both sides are the entropy of the same +operator (`State.mixPair_op`). -/ +theorem State.entropyMixLine_eq_mixPair {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (ρ σ : State S) : + ρ.entropyMixLine σ p = (State.mixPair hp0 hp1 ρ σ).vonNeumannEntropy := by + rw [State.vonNeumannEntropy_def, State.mixPair_op, State.entropyMixLine] + +/-- Left endpoint: `f(0) = S(σ)`. At `p = 0` the operator is `0 • ρ.op + 1 • σ.op = σ.op`. -/ +@[simp] theorem State.entropyMixLine_zero (ρ σ : State S) : + ρ.entropyMixLine σ 0 = σ.vonNeumannEntropy := by + simp only [State.entropyMixLine, Complex.ofReal_zero, zero_smul, zero_add, sub_zero, + Complex.ofReal_one, one_smul, State.vonNeumannEntropy_def] + +/-- Right endpoint: `f(1) = S(ρ)`. At `p = 1` the operator is `1 • ρ.op + 0 • σ.op = ρ.op`. -/ +@[simp] theorem State.entropyMixLine_one (ρ σ : State S) : + ρ.entropyMixLine σ 1 = ρ.vonNeumannEntropy := by + simp only [State.entropyMixLine, Complex.ofReal_one, one_smul, sub_self, Complex.ofReal_zero, + zero_smul, add_zero, State.vonNeumannEntropy_def] + +/-- **The sufficiency reduction, concavity form.** If the mixing-line entropy +`f(p) = S(p ρ + (1−p)σ)` is **concave on `[0,1]`**, then the two-point concavity inequality +(Nielsen & Chuang eq. (11.79) for +two components) holds: for `0 ≤ p ≤ 1`, + +`p S(ρ) + (1 − p) S(σ) ≤ S(p ρ + (1 − p) σ)`. + +This is the second half of N&C's Part-1 argument: concavity of `f` on `[0,1]`, evaluated at the +endpoints `x = 1` (giving `S(ρ)`) and `y = 0` (giving `S(σ)`) with weights `p, 1 − p`, is exactly +the concavity of the entropy. -/ +theorem State.vonNeumannEntropy_concave_of_entropyMixLine_concaveOn {ρ σ : State S} + (h : ConcaveOn ℝ (Set.Icc 0 1) (ρ.entropyMixLine σ)) {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + p * ρ.vonNeumannEntropy + (1 - p) * σ.vonNeumannEntropy + ≤ (State.mixPair hp0 hp1 ρ σ).vonNeumannEntropy := by + simpa [State.entropyMixLine_eq_mixPair hp0 hp1] using + h.2 (by norm_num : (1 : ℝ) ∈ Set.Icc (0 : ℝ) 1) (by norm_num : (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1) + hp0 (by linarith : (0 : ℝ) ≤ 1 - p) (by ring : p + (1 - p) = 1) + +/-- **The sufficiency reduction, calculus bridge.** If the mixing-line entropy `f` has non-positive +second derivative on the interior of `[0,1]` (with the continuity and twice-differentiability that +Mathlib's `concaveOn_of_deriv2_nonpos` requires), then `f` is concave on `[0,1]`. This is the +"`f''(p) ≤ 0` ⟹ concave" step that N&C invokes; the hypotheses are exactly the analytic input +supplied for invertible states by Part 2 below (the derivative-of-entropy computation). -/ +theorem State.entropyMixLine_concaveOn_of_deriv2_nonpos {ρ σ : State S} + (hcont : ContinuousOn (ρ.entropyMixLine σ) (Set.Icc 0 1)) + (hdiff : DifferentiableOn ℝ (ρ.entropyMixLine σ) (interior (Set.Icc 0 1))) + (hdiff2 : DifferentiableOn ℝ (deriv (ρ.entropyMixLine σ)) (interior (Set.Icc 0 1))) + (hf2 : ∀ p ∈ interior (Set.Icc (0 : ℝ) 1), (deriv^[2] (ρ.entropyMixLine σ)) p ≤ 0) : + ConcaveOn ℝ (Set.Icc 0 1) (ρ.entropyMixLine σ) := + concaveOn_of_deriv2_nonpos (convex_Icc 0 1) hcont hdiff hdiff2 hf2 + +/-- **N&C Exercise 11.22, Part 1 — "to show concavity it is sufficient to prove `f''(p) ≤ 0`".** +Combining the two reduction steps: if the mixing-line entropy `f(p) = S(p ρ + (1 − p) σ)` has +non-positive second derivative on `(0,1)` (with the packaged smoothness), then the two-point +concavity inequality holds: for `0 ≤ p ≤ 1`, + +`p S(ρ) + (1 − p) S(σ) ≤ S(p ρ + (1 − p) σ)`. + +The hypothesis `f''(p) ≤ 0` is proved for invertible states in Part 2 below. -/ +theorem State.vonNeumannEntropy_concave_of_deriv2_nonpos {ρ σ : State S} + (hcont : ContinuousOn (ρ.entropyMixLine σ) (Set.Icc 0 1)) + (hdiff : DifferentiableOn ℝ (ρ.entropyMixLine σ) (interior (Set.Icc 0 1))) + (hdiff2 : DifferentiableOn ℝ (deriv (ρ.entropyMixLine σ)) (interior (Set.Icc 0 1))) + (hf2 : ∀ p ∈ interior (Set.Icc (0 : ℝ) 1), (deriv^[2] (ρ.entropyMixLine σ)) p ≤ 0) + {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + p * ρ.vonNeumannEntropy + (1 - p) * σ.vonNeumannEntropy + ≤ (State.mixPair hp0 hp1 ρ σ).vonNeumannEntropy := + State.vonNeumannEntropy_concave_of_entropyMixLine_concaveOn + (State.entropyMixLine_concaveOn_of_deriv2_nonpos hcont hdiff hdiff2 hf2) hp0 hp1 + +/-! ## Part 2: `f''(p) ≤ 0` and the concavity it yields, for invertible `ρ, σ` + +The remaining task of Exercise 11.22 — prove `f''(p) ≤ 0` — is now carried out for the case where +`ρ` and `σ` are **invertible** (equivalently, strictly positive). The analytic input is the +operator-level statement +`deriv2_re_trace_cfc_negMulLog_add_smul_nonpos` (`ToMathlib`, +`.../ExpLog/EntropyDeriv.lean`): for a self-adjoint direction `b` and a base point where +`a + p • b` is strictly positive, the entropy `p ↦ re tr(cfc negMulLog (a + p • b))` has +non-positive second derivative — the Daleckii–Krein / resolvent-integral computation +`f''(p) = -∫₀^∞ tr(Δ (ω_p+s)⁻¹ Δ (ω_p+s)⁻¹) ds ≤ 0` with `Δ = ρ − σ`, `ω_p = p ρ + (1−p) σ`. + +The bridge to the mixing line is that `f(p) = S(p ρ + (1−p) σ)` is exactly this operator entropy +along the affine line `p ↦ σ.op + p • (ρ.op − σ.op)` (`entropyMixLine_eq_re_trace_cfc_negMulLog`), +whose base point is strictly positive on all of `[0,1]` when `ρ, σ` are invertible +(`isStrictlyPositive_op_add_smul`, a convex-combination-of-strictly-positive fact). Feeding the +resulting `f'' ≤ 0`, together with the differentiability the same operator lemmas provide, into the +Part-1 reduction gives concavity of `f`, hence the two-point concavity inequality (11.79) — for +invertible `ρ, σ`. -/ + +/-- The density operator of a state is self-adjoint (a density operator is symmetric, +`ContinuousLinearMap.IsDensityOp.isSymmetric`, hence self-adjoint on the finite-dimensional +space). The self-adjointness the affine-line derivative lemmas require of `ρ.op` and the direction +`ρ.op − σ.op`. -/ +theorem State.isSelfAdjoint_op (ρ : State S) : IsSelfAdjoint ρ.op := + ρ.isDensity.isSymmetric.isSelfAdjoint + +/-- The mixing-line entropy as the operator entropy along an affine line: for every `p`, +`f(p) = S(p ρ + (1−p) σ) = re tr(cfc negMulLog (σ.op + p • (ρ.op − σ.op)))`. The operator +`(p : ℂ) • ρ.op + (1 − p : ℂ) • σ.op` defining `f` equals the affine-line operator +`σ.op + p • (ρ.op − σ.op)` (a real-scalar reparametrisation), which is self-adjoint, so +`ContinuousLinearMap.vonNeumannEntropy_eq_re_trace_cfc_negMulLog` applies. This is the shape +consumed by the operator-level derivative lemmas of `ExpLog/EntropyDeriv.lean`. -/ +theorem State.entropyMixLine_eq_re_trace_cfc_negMulLog (ρ σ : State S) (p : ℝ) : + ρ.entropyMixLine σ p + = RCLike.re ((LinearMap.trace ℂ S.space) + ↑(cfc Real.negMulLog (σ.op + p • (ρ.op - σ.op)))) := by + have hb : IsSelfAdjoint (ρ.op - σ.op) := ρ.isSelfAdjoint_op.sub σ.isSelfAdjoint_op + have hsa : IsSelfAdjoint (σ.op + p • (ρ.op - σ.op)) := + σ.isSelfAdjoint_op.add ((IsSelfAdjoint.all p).smul hb) + rw [State.entropyMixLine, + show ((p : ℂ) • ρ.op + ((1 - p : ℝ) : ℂ) • σ.op) = σ.op + p • (ρ.op - σ.op) from by + simp only [Complex.coe_smul]; module, + ContinuousLinearMap.vonNeumannEntropy_eq_re_trace_cfc_negMulLog hsa] + +/-- For invertible (strictly positive) states `ρ, σ`, the affine-line operator +`σ.op + p • (ρ.op − σ.op) = p ρ.op + (1 − p) σ.op` is strictly positive for every `p ∈ [0,1]`: it is +a convex combination of the strictly positive operators `ρ.op, σ.op`, and the set of strictly +positive elements is convex (`convex_isStrictlyPositive`). -/ +theorem State.isStrictlyPositive_op_add_smul {ρ σ : State S} {p : ℝ} + (hρ : IsStrictlyPositive ρ.op) (hσ : IsStrictlyPositive σ.op) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + IsStrictlyPositive (σ.op + p • (ρ.op - σ.op)) := by + rw [show σ.op + p • (ρ.op - σ.op) = p • ρ.op + (1 - p) • σ.op from by module] + exact convex_isStrictlyPositive hρ hσ hp0 (by linarith) (by ring) + +/-- **Exercise 11.22, Part 2 (invertible case): `f''(p) ≤ 0`.** For invertible states `ρ, σ`, the +mixing-line entropy `f(p) = S(p ρ + (1 − p) σ)` has non-positive second derivative on the open +interval `(0,1)`. This is the operator-level second-derivative bound +`deriv2_re_trace_cfc_negMulLog_add_smul_nonpos` transported along the affine-line identification +`entropyMixLine_eq_re_trace_cfc_negMulLog`, whose base point is strictly positive on `(0,1)` by +`isStrictlyPositive_op_add_smul`. -/ +theorem State.entropyMixLine_deriv2_nonpos_of_isStrictlyPositive {ρ σ : State S} + (hρ : IsStrictlyPositive ρ.op) (hσ : IsStrictlyPositive σ.op) + {p : ℝ} (hp : p ∈ Set.Ioo (0 : ℝ) 1) : + (deriv^[2] (ρ.entropyMixLine σ)) p ≤ 0 := by + have : Nontrivial S.space := ρ.nontrivial_space + have hb : IsSelfAdjoint (ρ.op - σ.op) := ρ.isSelfAdjoint_op.sub σ.isSelfAdjoint_op + have hstrict : IsStrictlyPositive (σ.op + p • (ρ.op - σ.op)) := + State.isStrictlyPositive_op_add_smul hρ hσ hp.1.le hp.2.le + rw [funext (ρ.entropyMixLine_eq_re_trace_cfc_negMulLog σ)] + exact deriv2_re_trace_cfc_negMulLog_add_smul_nonpos hb hstrict + +/-- For invertible states `ρ, σ`, the mixing-line entropy `f` is concave on `[0,1]`. All the +smoothness inputs of the Part-1 reduction `entropyMixLine_concaveOn_of_deriv2_nonpos` are supplied +by the operator-level derivative lemmas of `ExpLog/EntropyDeriv.lean`: on `[0,1]` the base point +`σ.op + p • (ρ.op − σ.op)` is strictly positive (`isStrictlyPositive_op_add_smul`), so +`hasDerivAt_re_trace_cfc_negMulLog_add_smul` gives `f` a derivative at every such point (hence +continuity on `[0,1]` and differentiability on `(0,1)`); the first-derivative function is in turn +differentiable via `hasDerivAt_neg_re_trace_mul_cfc_log_add_smul`, and it agrees with `deriv f` on a +neighbourhood of each interior point (`eventually_isStrictlyPositive_add_smul`), giving +differentiability of `deriv f` on `(0,1)`; and `f'' ≤ 0` is +`entropyMixLine_deriv2_nonpos_of_isStrictlyPositive`. -/ +theorem State.entropyMixLine_concaveOn_of_isStrictlyPositive {ρ σ : State S} + (hρ : IsStrictlyPositive ρ.op) (hσ : IsStrictlyPositive σ.op) : + ConcaveOn ℝ (Set.Icc 0 1) (ρ.entropyMixLine σ) := by + have hnt : Nontrivial S.space := ρ.nontrivial_space + have hb : IsSelfAdjoint (ρ.op - σ.op) := ρ.isSelfAdjoint_op.sub σ.isSelfAdjoint_op + have hSP : ∀ q ∈ Set.Icc (0 : ℝ) 1, IsStrictlyPositive (σ.op + q • (ρ.op - σ.op)) := + fun q hq => State.isStrictlyPositive_op_add_smul hρ hσ hq.1 hq.2 + have hgeq : ρ.entropyMixLine σ = fun q => + RCLike.re ((LinearMap.trace ℂ S.space) ↑(cfc Real.negMulLog (σ.op + q • (ρ.op - σ.op)))) := + funext (ρ.entropyMixLine_eq_re_trace_cfc_negMulLog σ) + refine State.entropyMixLine_concaveOn_of_deriv2_nonpos ?_ ?_ ?_ ?_ + · rw [hgeq] + exact fun q hq => + (hasDerivAt_re_trace_cfc_negMulLog_add_smul hb (hSP q hq)).continuousAt.continuousWithinAt + · rw [hgeq, interior_Icc] + exact fun q hq => (hasDerivAt_re_trace_cfc_negMulLog_add_smul hb + (hSP q (Set.Ioo_subset_Icc_self hq))).differentiableAt.differentiableWithinAt + · rw [interior_Icc] + intro q hq + have hqI : q ∈ Set.Icc (0 : ℝ) 1 := Set.Ioo_subset_Icc_self hq + have hderivEq : deriv (ρ.entropyMixLine σ) =ᶠ[nhds q] fun r => + -RCLike.re ((LinearMap.trace ℂ S.space) + ↑((ρ.op - σ.op) * cfc Real.log (σ.op + r • (ρ.op - σ.op)))) + - RCLike.re ((LinearMap.trace ℂ S.space) ↑(ρ.op - σ.op)) := by + filter_upwards [eventually_isStrictlyPositive_add_smul (hSP q hqI) hb] with r hr + rw [hgeq] + exact (hasDerivAt_re_trace_cfc_negMulLog_add_smul hb hr).deriv + exact DifferentiableAt.differentiableWithinAt ((hderivEq.differentiableAt_iff).mpr + (hasDerivAt_neg_re_trace_mul_cfc_log_add_smul hb (hSP q hqI)).differentiableAt) + · rw [interior_Icc] + exact fun q hq => State.entropyMixLine_deriv2_nonpos_of_isStrictlyPositive hρ hσ hq + +/-- **Exercise 11.22, Part 2 (invertible case), concavity form.** For invertible states `ρ, σ` the +two-point concavity inequality (Nielsen & Chuang eq. (11.79)) holds: for `0 ≤ p ≤ 1`, + +`p S(ρ) + (1 − p) S(σ) ≤ S(p ρ + (1 − p) σ)`. + +This is the alternate (second-derivative) proof of concavity of the von Neumann entropy carried out +for invertible states: `f'' ≤ 0` (`entropyMixLine_concaveOn_of_isStrictlyPositive`) fed through the +Part-1 sufficiency reduction. -/ +theorem State.vonNeumannEntropy_concave_of_isStrictlyPositive {ρ σ : State S} + (hρ : IsStrictlyPositive ρ.op) (hσ : IsStrictlyPositive σ.op) + {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + p * ρ.vonNeumannEntropy + (1 - p) * σ.vonNeumannEntropy + ≤ (State.mixPair hp0 hp1 ρ σ).vonNeumannEntropy := + State.vonNeumannEntropy_concave_of_entropyMixLine_concaveOn + (State.entropyMixLine_concaveOn_of_isStrictlyPositive hρ hσ) hp0 hp1 + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyMixture.lean b/LeanPool/AxQM/Postulates/API/EntropyMixture.lean new file mode 100644 index 0000000000..5a2e9220ac --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyMixture.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyMixture + +/-! +# AxQM — entropy of a mixture of quantum states (N&C Theorem 11.10, upper bound) + +For a mixture `μ = State.mix p ρ = ∑ᵢ pᵢ ρᵢ` of quantum states `ρᵢ` with a probability +distribution `p`, the von Neumann entropy is bounded above by the average entropy of the components +plus the Shannon entropy of the weights: + +`S(μ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)` + +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.10, eq. (11.87), +upper-bound half). This is the `State`-level form of the operator bound +`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy`. + +## Proof + +The operator bound is proved on `EuclideanSpace ℂ (Fin d)`; the `State` version transports it to the +abstract system space `S.space` along the standard orthonormal basis +`(stdOrthonormalBasis ℂ S.space).repr`, using the isometry invariance of the von Neumann entropy +(`ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv`) and of the density-operator and +strict-positivity properties (`LinearIsometryEquiv.conjStarAlgEquiv_isDensityOp_iff`, +`LinearIsometryEquiv.conjStarAlgEquiv_isStrictlyPositive_iff`). + +## Faithfulness + +The relative-entropy route to the bound requires each component `ρᵢ` to be **faithful** (strictly +positive spectrum, `IsStrictlyPositive (ρ i).op`); this is the finite-branch faithfulness convention +shared with Klein's inequality, joint convexity, and strong subadditivity. The general +(possibly rank-deficient) case is not covered by this statement. The equality condition — +equality iff the `ρᵢ` have orthogonal supports — is treated in +`AxQM/Postulates/API/EntropyOrthogonalMixture.lean` and +`AxQM/Postulates/API/EntropyMixtureReverse.lean`. + +## Main results + +* `AxQM.State.vonNeumannEntropy_mix_le` — `S(∑ᵢ pᵢ ρᵢ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)` for a + mixture of faithful states. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- **Entropy of a mixture — upper bound** (Nielsen & Chuang, Theorem 11.10, eq. (11.87), +upper-bound half). For a probability distribution `p` and a family `ρ : ι → State S` of **faithful** +states (each `(ρ i).op` strictly positive), the von Neumann entropy of the mixture +`State.mix p hp hsum ρ` is bounded by the average component entropy plus the Shannon entropy +`H(p) = Real.entropy p` of the weights: + +`S(∑ᵢ pᵢ ρᵢ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`. + +Lifts the operator bound +`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy` to states. +That bound lives on `EuclideanSpace ℂ (Fin d)`; the proof transports the mixture into that space +along `(stdOrthonormalBasis ℂ S.space).repr`, where conjugation by the isometry preserves the von +Neumann entropy, the density-operator property, and strict positivity (so the component and mixture +hypotheses carry over and the entropies read straight back). + +The **faithfulness** hypothesis is inherent to the relative-entropy route (see the module +docstring); the orthogonal-support equality condition is treated in +`AxQM/Postulates/API/EntropyMixtureReverse.lean`. -/ +theorem State.vonNeumannEntropy_mix_le {ι : Type*} [Fintype ι] (p : ι → ℝ) + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (hpos : ∀ i, IsStrictlyPositive (ρ i).op) : + (State.mix p hp hsum ρ).vonNeumannEntropy + ≤ ∑ i, p i * (ρ i).vonNeumannEntropy + Real.entropy p := by + classical + set μ := State.mix p hp hsum ρ with hμ + -- Transport the mixture into `EuclideanSpace ℂ (Fin d)` along the standard orthonormal basis of + -- `S.space`, where the operator-level bound is available. Conjugation by the isometry `e` + -- preserves density, strict positivity, and the von Neumann entropy. + let e := (stdOrthonormalBasis ℂ S.space).repr + have hμop : μ.op = ∑ i, (p i : ℂ) • (ρ i).op := hμ ▸ State.mix_op p hp hsum ρ + have hpos' : ∀ i, IsStrictlyPositive (e.conjStarAlgEquiv (ρ i).op) := fun i => + e.conjStarAlgEquiv_isStrictlyPositive_iff.mpr (hpos i) + have hdens' : ∀ i, (e.conjStarAlgEquiv (ρ i).op).IsDensityOp := fun i => + e.conjStarAlgEquiv_isDensityOp_iff.mpr (ρ i).isDensity + have hμdens' : (e.conjStarAlgEquiv μ.op).IsDensityOp := + e.conjStarAlgEquiv_isDensityOp_iff.mpr μ.isDensity + have hμeq' : e.conjStarAlgEquiv μ.op = ∑ i, (p i : ℂ) • e.conjStarAlgEquiv (ρ i).op := by + rw [hμop, map_sum] + exact Finset.sum_congr rfl fun i _ => map_smul _ _ _ + have h := ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy + hpos' hdens' hp hμdens' hμeq' + simpa only [ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv, State.vonNeumannEntropy_def] + using h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropyOrthogonalMixture.lean b/LeanPool/AxQM/Postulates/API/EntropyOrthogonalMixture.lean new file mode 100644 index 0000000000..15b57bf55d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropyOrthogonalMixture.lean @@ -0,0 +1,218 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Mixture +public import LeanPool.AxQM.Postulates.API.EntropySpectral +public import LeanPool.AxQM.Postulates.API.Support + +/-! +# AxQM — entropy of a mixture with orthogonal supports (N&C Thm 11.8 part 4 / Thm 11.10) + +For a mixture `μ = State.mix p ρ = ∑ᵢ pᵢ ρᵢ` of quantum states whose components have **orthogonal +supports**, the von Neumann entropy is *exactly* the average component entropy plus the Shannon +entropy of the weights, + +`S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`, + +the equality case of the entropy-of-a-mixture bound (Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Theorem 11.10, eq. (11.87)) and the orthogonal-support mixture identity of +Theorem 11.8 (part (4), eq. (11.57)). + +This file supplies the shared "if" direction in two forms: + +* `State.vonNeumannEntropy_mix_of_orthonormal_rankOne` — the **constructive engine**: "orthogonal + supports" is given as a jointly-orthonormal family of eigen-decompositions + `ρᵢ.op = ∑ₖ wᵢₖ |eᵢₖ⟩⟨eᵢₖ|` (the combined family over `Σ i, κ i` orthonormal), exactly as in N&C's + own proof. It reads the mixture entropy off the single orthonormal rank-one sum and splits it with + the grouping identity `Real.entropy_sigma_mul`. This is the reusable engine for the joint-entropy + theorem (Thm 11.8 part 5) and the Thm 11.10 equality condition. +* `State.vonNeumannEntropy_mix_orthogonalSupport` — the **faithful N&C statement** of Theorem 11.8 + part (4): "orthogonal supports" is the literal `Pairwise ((ρ i).support ⟂ (ρ j).support)`. Its + proof derives the eigen-decompositions internally (`IsSelfAdjoint.spectral_sum`) and proves the + combined eigenfamily orthonormal on its support from the support-orthogonality hypothesis + (`State.eigenvectorBasis_mem_support_iff`, `Submodule.isOrtho_iff_inner_eq`), feeding the + degenerate-weight engine + `State.vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero` and the grouping + identity `Real.entropy_sigma_mul`. + +## Main results + +The statement of Theorem 11.8 is in `LeanPool/AxQM/NC/Ch11/Theorem8.lean`; the declarations are +here. + +* `AxQM.State.mix_op_eq_sum_sigma_rankOne` — the shared operator bridge: a mixture of + states with rank-one decompositions is the single `Σ`-indexed rank-one sum with weights `pᵢ wᵢₖ`. +* `AxQM.State.vonNeumannEntropy_mix_of_orthonormal_rankOne` — engine form, + `S(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ S(ρᵢ) + H(p)` for components with jointly-orthonormal eigen-decompositions. +* `AxQM.State.vonNeumannEntropy_mix_orthogonalSupport` — Nielsen–Chuang Theorem 11.8 + part (4), `S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)` under `Pairwise ((ρ i).support ⟂ (ρ j).support)`. +* `AxQM.State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero` — the **"if" direction** + of the Theorem 11.10 equality condition, stated over the intrinsic operator-product predicate + `Pairwise ((ρ i).op * (ρ j).op = 0)`: pairwise-vanishing density-operator products (= orthogonal + supports, `State.support_isOrtho_iff_op_mul_eq_zero`) give equality `S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ + S(ρᵢ)`. This is the form over which the iff `vonNeumannEntropy_mix_eq_iff_orthogonal` is + assembled in `AxQM/Postulates/API/EntropyMixtureReverse.lean`, where the converse ("only if") + is proved. +-/ + +@[expose] public section + +namespace AxQM + +open scoped InnerProductSpace + +variable {S : QSystem} + +/-- **The density operator of a mixture as a `Σ`-indexed rank-one sum.** If the components of a +mixture carry rank-one decompositions `(ρ i).op = ∑ₖ wᵢₖ |eᵢₖ⟩⟨eᵢₖ|`, then the mixture's operator +`∑ᵢ pᵢ ρᵢ` is the single rank-one sum over the sigma index `Σ i, κ i` with weights `pᵢ wᵢₖ`. The +shared operator-decomposition bridge behind both the constructive equality engine +`State.vonNeumannEntropy_mix_of_orthonormal_rankOne` and the orthogonal-support identity +`State.vonNeumannEntropy_mix_orthogonalSupport`. -/ +theorem State.mix_op_eq_sum_sigma_rankOne {ι : Type*} [Fintype ι] {κ : ι → Type*} + [∀ i, Fintype (κ i)] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (ρ : ι → State S) (e : (i : ι) → κ i → S.space) (w : (i : ι) → κ i → ℝ) + (hop : ∀ i, (ρ i).op = ∑ k, (w i k : ℂ) • (InnerProductSpace.rankOne ℂ (e i k)) (e i k)) : + (State.mix p hp hsum ρ).op + = ∑ ik : Σ i, κ i, ((p ik.1 * w ik.1 ik.2 : ℝ) : ℂ) • + (InnerProductSpace.rankOne ℂ (e ik.1 ik.2)) (e ik.1 ik.2) := by + rw [State.mix_op, Fintype.sum_sigma] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [hop i, Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [smul_smul]; congr 1; push_cast; ring + +/-- **Entropy of a mixture with orthogonal supports** (Nielsen & Chuang, Theorem 11.10, equality +case of eq. (11.87); the engine for Theorem 11.8 parts 4–5). For a probability distribution `p` and +a family `ρ : ι → State S` whose components carry orthonormal eigen-decompositions +`ρᵢ.op = ∑ₖ wᵢₖ |eᵢₖ⟩⟨eᵢₖ|` that are **jointly orthonormal** across components (the combined family +`⟨i, k⟩ ↦ eᵢₖ` is orthonormal — i.e. the `ρᵢ` have mutually orthogonal supports), the von Neumann +entropy of the mixture is the average component entropy plus the Shannon entropy of the weights: + +`S(∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ S(ρᵢ) + H(p)`, where `H(p) = Real.entropy p`. + +The mixed operator is the single orthonormal rank-one sum +`μ.op = ∑_{⟨i,k⟩} (pᵢ wᵢₖ) |eᵢₖ⟩⟨eᵢₖ|`, so +`State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum` evaluates `S(μ)` to the Shannon +entropy of `⟨i,k⟩ ↦ pᵢ wᵢₖ`; the grouping identity `Real.entropy_sigma_mul` (using `∑ₖ wᵢₖ = 1`) +splits this into `H(p) + ∑ᵢ pᵢ H(wᵢ)`, and each `S(ρᵢ) = H(wᵢ)` by the same engine restricted to +the `i`-th orthonormal block. -/ +theorem State.vonNeumannEntropy_mix_of_orthonormal_rankOne + {ι : Type*} [Fintype ι] {κ : ι → Type*} [∀ i, Fintype (κ i)] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (e : (i : ι) → κ i → S.space) (w : (i : ι) → κ i → ℝ) + (hortho : Orthonormal ℂ (fun ik : Σ i, κ i => e ik.1 ik.2)) + (hwsum : ∀ i, ∑ k, w i k = 1) + (hop : ∀ i, (ρ i).op + = ∑ k, (w i k : ℂ) • (InnerProductSpace.rankOne ℂ (e i k)) (e i k)) : + (State.mix p hp hsum ρ).vonNeumannEntropy + = ∑ i, p i * (ρ i).vonNeumannEntropy + Real.entropy p := by + classical + -- The mixture's operator is the single `Σ`-indexed orthonormal rank-one sum, weights `pᵢ wᵢₖ`. + have hmixop := State.mix_op_eq_sum_sigma_rankOne p hp hsum ρ e w hop + -- Entropy of the mixture read off the combined orthonormal decomposition. + have hmix := (State.mix p hp hsum ρ).vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum + hortho (fun ik => p ik.1 * w ik.1 ik.2) hmixop + -- Entropy of each component, from the `i`-th orthonormal block of the combined family. + have hcomp : ∀ i, (ρ i).vonNeumannEntropy = Real.entropy (w i) := fun i => + (ρ i).vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum + (hortho.comp (Sigma.mk i) sigma_mk_injective) (w i) (hop i) + -- Assemble via the classical grouping identity. + rw [hmix, Real.entropy_sigma_mul p w hwsum] + simp_rw [hcomp] + ring + +/-- **Entropy of an orthogonal-support mixture** (Nielsen–Chuang Theorem 11.8, part (4), +eq. (11.57)). For a probability distribution `p` and a family `ρ : ι → State S` whose supports are +**pairwise orthogonal** (`(ρ i).support ⟂ (ρ j).support` for `i ≠ j`), the von Neumann entropy of +the mixture `State.mix p hp hsum ρ = ∑ᵢ pᵢ ρᵢ` is the Shannon entropy `H(p)` of the weights plus the +`p`-average of the component entropies: + +`S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. + +This is the N&C-faithful form of the equality engine +`State.vonNeumannEntropy_mix_of_orthonormal_rankOne` above: rather than *assuming* +jointly-orthonormal eigen-decompositions, it derives them. Each summand is diagonalised +(`IsSelfAdjoint.spectral_sum`), the combined eigenfamily over `Σ i, Fin d` is orthonormal on the +non-zero weights because the supports are orthogonal (`State.eigenvectorBasis_mem_support_iff`, +`Submodule.isOrtho_iff_inner_eq`), and the degenerate-weight engine +`State.vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero` reads off +`S(mix) = H(⟨i,j⟩ ↦ pᵢ λᵢⱼ)`, which the grouping identity `Real.entropy_sigma_mul` splits into +`H(p) + ∑ᵢ pᵢ H(λᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. -/ +theorem State.vonNeumannEntropy_mix_orthogonalSupport {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (horth : Pairwise fun i j => (ρ i).support ⟂ (ρ j).support) : + (State.mix p hp hsum ρ).vonNeumannEntropy + = Real.entropy p + ∑ i, p i * (ρ i).vonNeumannEntropy := by + classical + set d := Module.finrank ℂ S.space + -- Canonical spectral data of each summand: eigenvector basis `b i` and eigenvalues `lam i`. + set b : (i : ι) → Fin d → S.space := + fun i j => (ρ i).isDensity.isSymmetric.eigenvectorBasis rfl j + set lam : (i : ι) → Fin d → ℝ := + fun i j => (ρ i).isDensity.isSymmetric.eigenvalues rfl j + set W : (Σ _ : ι, Fin d) → ℝ := fun x => p x.1 * lam x.1 x.2 with hW + -- Per-summand spectral decomposition, spectrum summing to one, and entropy `S(ρᵢ) = H(λᵢ)`. + have hspec : ∀ i, (ρ i).op + = ∑ j, (lam i j : ℂ) • (InnerProductSpace.rankOne ℂ (b i j)) (b i j) := + fun i => ((ρ i).isDensity.isPositive.isSelfAdjoint).spectral_sum rfl + have hq : ∀ i, ∑ j, lam i j = 1 := fun i => (ρ i).isDensity.eigenvalues_sum_eq_one rfl + have hSi : ∀ i, (ρ i).vonNeumannEntropy = Real.entropy (lam i) := fun i => + (ρ i).vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum + ((ρ i).isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal (lam i) (hspec i) + -- The mixture's density operator as a rank-one sum over the sigma index `Σ i, Fin d`. + have hmixop : (State.mix p hp hsum ρ).op + = ∑ x : Σ _ : ι, Fin d, + (W x : ℂ) • (InnerProductSpace.rankOne ℂ (b x.1 x.2)) (b x.1 x.2) := + State.mix_op_eq_sum_sigma_rankOne p hp hsum ρ b lam hspec + -- The eigenfamily is orthonormal on the non-zero weights: orthogonal supports do the work. + have horthfam : Orthonormal ℂ (fun x : {x : Σ _ : ι, Fin d // W x ≠ 0} => b x.1.1 x.1.2) := by + rw [orthonormal_iff_ite] + rintro ⟨⟨i, j⟩, hx⟩ ⟨⟨k, l⟩, hy⟩ + have hlij : lam i j ≠ 0 := fun h => hx (by simp [hW, h]) + have hlkl : lam k l ≠ 0 := fun h => hy (by simp [hW, h]) + have hmi : b i j ∈ (ρ i).support := ((ρ i).eigenvectorBasis_mem_support_iff j).mpr hlij + have hmk : b k l ∈ (ρ k).support := ((ρ k).eigenvectorBasis_mem_support_iff l).mpr hlkl + by_cases hik : i = k + · subst hik + rw [orthonormal_iff_ite.mp ((ρ i).isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal j l] + congr 1 + simp only [Subtype.ext_iff, Sigma.mk.inj_iff, heq_eq_eq, true_and] + · rw [ite_eq_right (by simp only [Subtype.ext_iff, Sigma.mk.inj_iff]; tauto)] + exact Submodule.isOrtho_iff_inner_eq.mp (horth hik) (b i j) hmi (b k l) hmk + -- Read off the mixture entropy, then split it with the classical grouping identity. + rw [(State.mix p hp hsum ρ).vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero + W horthfam hmixop, hW, Real.entropy_sigma_mul p lam hq] + simp_rw [hSi] + +/-- **Entropy of a mixture with orthogonal supports, intrinsic operator-product form** (the "if" +direction of the Nielsen–Chuang Theorem 11.10 equality condition). If the density operators of a +family `ρ : ι → State S` have **pairwise-vanishing products** `(ρ i).op * (ρ j).op = 0` for `i ≠ j` +— equivalently, pairwise orthogonal supports (`State.support_isOrtho_iff_op_mul_eq_zero`) — then the +von Neumann entropy of the mixture is exactly the average component entropy plus the Shannon entropy +of the weights: + +`S(∑ᵢ pᵢ ρᵢ) = H(p) + ∑ᵢ pᵢ S(ρᵢ)`. + +This restates `State.vonNeumannEntropy_mix_orthogonalSupport` over the intrinsic operator predicate +`(ρ i).op * (ρ j).op = 0` (rather than the geometric `(ρ i).support ⟂ (ρ j).support`), the form the +Theorem 11.10 equality *iff* `vonNeumannEntropy_mix_eq_iff_orthogonal` is assembled over. The proof +just relays each `(ρ i).op * (ρ j).op = 0` back to support-orthogonality via the characterization +`State.support_isOrtho_iff_op_mul_eq_zero`. The converse ("equality ⟹ orthogonal supports") is +developed separately (via purification and the equality condition of Theorem 11.9). -/ +theorem State.vonNeumannEntropy_mix_eq_of_pairwise_op_mul_eq_zero {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) + (horth : Pairwise fun i j => (ρ i).op * (ρ j).op = 0) : + (State.mix p hp hsum ρ).vonNeumannEntropy + = Real.entropy p + ∑ i, p i * (ρ i).vonNeumannEntropy := + State.vonNeumannEntropy_mix_orthogonalSupport p hp hsum ρ + fun i j hij => (State.support_isOrtho_iff_op_mul_eq_zero (ρ i) (ρ j)).mpr (horth hij) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EntropySpectral.lean b/LeanPool/AxQM/Postulates/API/EntropySpectral.lean new file mode 100644 index 0000000000..b805afb062 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EntropySpectral.lean @@ -0,0 +1,214 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy + +/-! +# AxQM — the spectral characterization of the von Neumann entropy + +Nielsen–Chuang open §11.3 with the defining identity for the von Neumann entropy: writing a density +operator in its spectral (eigen-) decomposition `ρ = ∑ᵢ λᵢ |eᵢ⟩⟨eᵢ|`, the entropy is the *Shannon +entropy of the eigenvalue spectrum*, + +`S(ρ) = H(λ₁, …, λ_d) = -∑ᵢ λᵢ log λᵢ`. + +The entropy `State.vonNeumannEntropy` is *defined* through +`ContinuousLinearMap.vonNeumannEntropy`, whose value on a self-adjoint operator is precisely the +Shannon entropy of its *canonical* eigenvalue sequence (`vonNeumannEntropy_of_isSymmetric`). This +file records the more flexible **any-eigenbasis** form: if `b` is *any* orthonormal basis +diagonalizing `ρ.op` with real eigenvalues `μ`, then `S(ρ) = H(μ)`. One is rarely handed the +Mathlib-canonical spectral order; concrete situations (Schmidt decompositions, block-diagonal +mixtures, explicit qubit states) come with their *own* diagonalizing basis, and this lemma lets one +compute the entropy directly from it. + +This is the analytic engine behind the substantive parts of Nielsen–Chuang Theorem 11.8 (the +equality `S(A) = S(B)` for a pure composite, the orthogonal-support mixture identity, and the joint +entropy theorem), all of which reduce a von Neumann entropy to the Shannon entropy of a spectrum +presented in a task-specific eigenbasis. + +## Main results + +* `AxQM.State.vonNeumannEntropy_eq_entropy_of_isEigenbasis` — `S(ρ) = H(μ)` whenever the + orthonormal basis `b` diagonalizes `ρ.op` with real eigenvalue sequence `μ`. +* `AxQM.State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum` — `S(ρ) = H(w)` + whenever `ρ.op = ∑ᵢ wᵢ |eᵢ⟩⟨eᵢ|` for an orthonormal (possibly *incomplete*) family `e`. This is + the workhorse for the spectral parts of Theorem 11.8: a task-specific eigenbasis (Schmidt bases, + block-diagonal mixtures) rarely spans the whole space, and this lemma reads the entropy off the + finite weight list directly — the extra `0` eigenvalues on the orthogonal complement contribute + nothing (`η(0) = 0`). +* `AxQM.State.vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero` — the + same conclusion `S(ρ) = H(w)` requiring the family `e` orthonormal only on the **non-zero-weight** + indices `{i : wᵢ ≠ 0}`. The zero-weight rank-one terms vanish and may overlap freely; this is what + the orthogonal-support mixture identity (Theorem 11.8 part 4) needs, since the assembled + eigenfamily of a mixture is orthonormal only across the summands' supports. +-/ + +@[expose] public section + +namespace AxQM + +open scoped InnerProductSpace + +variable {S : QSystem} {ι : Type*} [Fintype ι] + +/-- **Spectral characterization of the von Neumann entropy** (Nielsen–Chuang §11.3): for *any* +orthonormal basis `b` diagonalizing the density operator `ρ.op` with real eigenvalues `μ` +(`ρ.op (b i) = μ i • b i`), the entropy is the Shannon entropy of that eigenvalue spectrum, +`S(ρ) = H(μ)`. + +The proof feeds the given eigenbasis into the eigenvalue-recognition theorem +(`LinearMap.IsSymmetric.eigenvalues_multiset_map_eq_of_eigenbasis`): the multiset of `μ` agrees with +the multiset of `ρ.op`'s canonical eigenvalues, and Shannon entropy depends only on that multiset +(`Real.entropy_eq_of_multiset_map_eq`), so it agrees with the canonical value computed by +`ContinuousLinearMap.vonNeumannEntropy_of_isSymmetric`. -/ +theorem State.vonNeumannEntropy_eq_entropy_of_isEigenbasis (ρ : State S) + (b : OrthonormalBasis ι ℂ S.space) {μ : ι → ℝ} + (h : ∀ i, ρ.op (b i) = (μ i : ℂ) • b i) : + ρ.vonNeumannEntropy = Real.entropy μ := by + have hsym : ρ.op.toLinearMap.IsSymmetric := ρ.isDensity.isSymmetric + have hfin : Module.finrank ℂ S.space = Fintype.card ι := Module.finrank_eq_card_basis b.toBasis + have heigen : ∀ i, ρ.op.toLinearMap (b.toBasis i) = (μ i : ℂ) • b.toBasis i := by + intro i; rw [b.coe_toBasis]; exact h i + have hrec := hsym.eigenvalues_multiset_map_eq_of_eigenbasis hfin b.toBasis heigen + rw [State.vonNeumannEntropy_def, + ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq hsym hfin] + exact Real.entropy_eq_of_multiset_map_eq hrec.symm + +/-- **Extend an orthonormal rank-one eigenfamily to a full diagonalizing basis.** If the density +operator `ρ.op` is a weighted sum of rank-one projectors onto an *orthonormal* family +`e : ι → S.space` — `ρ.op = ∑ᵢ wᵢ |eᵢ⟩⟨eᵢ|` — then `e`, which need not span `S.space`, extends to a +full orthonormal basis `B` of `S.space` indexed by `ι ⊕ Fin (finrank (span e)ᗮ)` that diagonalizes +`ρ.op` with the real eigenvalue family `Sum.elim w 0`: on the `ι` block each `eᵢ` is an eigenvector +with eigenvalue `wᵢ` (orthonormality kills the cross terms), and the adjoined complement block — an +orthonormal basis `c` of `(span e)ᗮ` — lies in the kernel of every `|eᵢ⟩⟨eᵢ|`, so each `cⱼ` is an +eigenvector with eigenvalue `0`. + +The shared construction behind both spectral read-offs of such a decomposition — the entropy +`S(ρ) = H(w)` (`State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum`) and the +same-non-zero spectrum `w ≅ λ_ρ` (`State.sameNonzero_eigenvalueDist_of_orthonormal_rankOne_sum`) — +which differ only in the recognition lemma applied to the returned eigenbasis. -/ +theorem State.exists_eigenbasis_of_orthonormal_rankOne_sum (ρ : State S) {e : ι → S.space} + (he : Orthonormal ℂ e) (w : ι → ℝ) + (hop : ρ.op = ∑ i, (w i : ℂ) • (InnerProductSpace.rankOne ℂ (e i)) (e i)) : + ∃ B : OrthonormalBasis (ι ⊕ Fin (Module.finrank ℂ (Submodule.span ℂ (Set.range e))ᗮ)) ℂ S.space, + ∀ x, ρ.op (B x) = ((Sum.elim w (fun _ => (0 : ℝ)) x : ℝ) : ℂ) • B x := by + classical + set U : Submodule ℂ S.space := Submodule.span ℂ (Set.range e) with hUdef + set c : OrthonormalBasis (Fin (Module.finrank ℂ Uᗮ)) ℂ Uᗮ := stdOrthonormalBasis ℂ Uᗮ + set c' : Fin (Module.finrank ℂ Uᗮ) → S.space := fun j => (c j : S.space) with hc' + -- Membership facts anchoring the two blocks of the extended basis. + have hmem_e : ∀ i, e i ∈ U := fun i => Submodule.subset_span ⟨i, rfl⟩ + have hmem_c' : ∀ j, c' j ∈ Uᗮ := fun j => Submodule.coe_mem (c j) + -- The action of `ρ.op` on any vector, unfolded through the rank-one sum. + have key : ∀ x : S.space, ρ.op x = ∑ i, ((w i : ℂ) * inner ℂ (e i) x) • e i := by + intro x + rw [hop, sum_apply] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [smul_apply, InnerProductSpace.rankOne_apply, smul_smul] + -- Block 1: each `eᵢ` is an eigenvector with eigenvalue `wᵢ`. + have hdiag_e : ∀ i, ρ.op (e i) = (w i : ℂ) • e i := by + intro i + rw [key, Finset.sum_eq_single i] + · rw [orthonormal_iff_ite.mp he i i]; simp + · intro j _ hji + rw [orthonormal_iff_ite.mp he j i, ite_eq_right hji, mul_zero, zero_smul] + · intro h; exact absurd (Finset.mem_univ i) h + -- Block 2: each complement vector is an eigenvector with eigenvalue `0`. + have hdiag_c' : ∀ j, ρ.op (c' j) = 0 := by + intro j + rw [key] + refine Finset.sum_eq_zero fun i _ => ?_ + rw [Submodule.inner_right_of_mem_orthogonal (hmem_e i) (hmem_c' j), mul_zero, zero_smul] + -- The combined family is orthonormal. + have hgon : Orthonormal ℂ (Sum.elim e c') := by + rw [orthonormal_iff_ite] + rintro (i | j) (i' | j') <;> + simp only [Sum.elim_inl, Sum.elim_inr, Sum.inl.injEq, Sum.inr.injEq, + reduceCtorEq, ite_false] + · exact orthonormal_iff_ite.mp he i i' + · exact Submodule.inner_right_of_mem_orthogonal (hmem_e i) (hmem_c' j') + · exact Submodule.inner_left_of_mem_orthogonal (hmem_e i') (hmem_c' j) + · rw [hc']; exact orthonormal_iff_ite.mp c.orthonormal j j' + -- The combined family spans the whole space, so its complement is trivial. + have hspan : (Submodule.span ℂ (Set.range (Sum.elim e c')))ᗮ = ⊥ := by + rw [Submodule.orthogonal_eq_bot_iff, Set.Sum.elim_range, Submodule.span_union, ← hUdef] + have hcspan : Submodule.span ℂ (Set.range (⇑c)) = ⊤ := by + rw [← OrthonormalBasis.coe_toBasis]; exact c.toBasis.span_eq + have hc'span : Submodule.span ℂ (Set.range c') = Uᗮ := by + rw [hc', show (fun j => (c j : S.space)) = Uᗮ.subtype ∘ c from rfl, Set.range_comp, + Submodule.span_image, hcspan, Submodule.map_subtype_top] + rw [hc'span] + exact Submodule.sup_orthogonal_of_hasOrthogonalProjection + -- Assemble the extended orthonormal basis and read off the diagonal action. + set B : OrthonormalBasis (ι ⊕ Fin (Module.finrank ℂ Uᗮ)) ℂ S.space := + OrthonormalBasis.mkOfOrthogonalEqBot hgon hspan + have hBcoe : ⇑B = Sum.elim e c' := OrthonormalBasis.coe_of_orthogonal_eq_bot_mk hgon hspan + refine ⟨B, fun x => ?_⟩ + rw [hBcoe] + cases x with + | inl i => simpa using hdiag_e i + | inr j => simp [hdiag_c' j] + +/-- **Entropy from an orthonormal eigenfamily** (Nielsen–Chuang §11.3, spectral workhorse). If the +density operator `ρ.op` is a weighted sum of rank-one projectors onto an *orthonormal* family +`e : ι → S.space` — `ρ.op = ∑ᵢ wᵢ |eᵢ⟩⟨eᵢ|` — then the von Neumann entropy is the Shannon entropy of +the weight list, `S(ρ) = H(w)`. + +The family `e` need not span `S.space`: `State.exists_eigenbasis_of_orthonormal_rankOne_sum` extends +it to a full eigenbasis `B` with eigenvalue family `Sum.elim w 0` (the complement vectors carry +eigenvalue `0`). Feeding `B` into `State.vonNeumannEntropy_eq_entropy_of_isEigenbasis` gives +`S(ρ) = H(w ⊕ 0) = H(w)`, since the padded `0` eigenvalues contribute `η(0) = 0` to the Shannon +sum. -/ +theorem State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum (ρ : State S) + {e : ι → S.space} (he : Orthonormal ℂ e) (w : ι → ℝ) + (hop : ρ.op = ∑ i, (w i : ℂ) • (InnerProductSpace.rankOne ℂ (e i)) (e i)) : + ρ.vonNeumannEntropy = Real.entropy w := by + obtain ⟨B, hdiag⟩ := ρ.exists_eigenbasis_of_orthonormal_rankOne_sum he w hop + rw [ρ.vonNeumannEntropy_eq_entropy_of_isEigenbasis B hdiag, Real.entropy_eq, Real.entropy_eq, + Fintype.sum_sum_type] + simp [Real.negMulLog_zero] + +/-- **Dropping the zero-weight terms of a finite sum.** If `g i = 0` whenever `w i = 0`, then the +sum of `g` over the whole index type equals the sum over the sub-type of indices with non-zero +weight. Used to reduce a rank-one/entropy sum with a possibly-degenerate weight list to the +non-degenerate sub-family. A thin specialisation of the lemma `Finset.sum_congr_set` to the +support set `{i | w i ≠ 0}`. -/ +private theorem sum_eq_sum_subtype_ne_zero {α M : Type*} [Fintype α] [AddCommMonoid M] + (w : α → ℝ) (g : α → M) (hg : ∀ i, w i = 0 → g i = 0) : + ∑ i, g i = ∑ i : {i : α // w i ≠ 0}, g i.1 := by + classical + exact Finset.sum_congr_set {i | w i ≠ 0} g (fun i => g i.1) (fun _ _ => rfl) + (fun x hx => hg x (not_not.mp hx)) + +/-- **Entropy from a rank-one family orthonormal on its support** (the degenerate-weight +strengthening of `State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum`). If +`ρ.op = ∑ᵢ wᵢ |eᵢ⟩⟨eᵢ|` and the sub-family `{eᵢ : wᵢ ≠ 0}` — the vectors carrying non-zero weight — +is orthonormal, then `S(ρ) = H(w)`. The family `e` need *not* be orthonormal on the zero-weight +indices: those rank-one terms vanish (`0 • x = 0`) and contribute `η(0) = 0` to the Shannon sum, so +they may be discarded before invoking the orthonormal engine. + +This is the workhorse for the *orthogonal-support mixture* identity (Nielsen–Chuang Theorem 11.8, +part 4): the eigenvectors of the summands `ρᵢ` assemble into a rank-one decomposition of the mixture +whose full index family is orthonormal only on the support (the non-zero eigenvalues), precisely +because distinct summands have orthogonal supports. -/ +theorem State.vonNeumannEntropy_eq_entropy_of_rankOne_sum_orthonormal_on_ne_zero + (ρ : State S) {e : ι → S.space} (w : ι → ℝ) + (he : Orthonormal ℂ (fun i : {i : ι // w i ≠ 0} => e i.1)) + (hop : ρ.op = ∑ i, (w i : ℂ) • (InnerProductSpace.rankOne ℂ (e i)) (e i)) : + ρ.vonNeumannEntropy = Real.entropy w := by + have hop' : ρ.op = ∑ i : {i : ι // w i ≠ 0}, + (w i.1 : ℂ) • (InnerProductSpace.rankOne ℂ (e i.1)) (e i.1) := by + rw [hop]; exact sum_eq_sum_subtype_ne_zero w _ (fun i hi => by simp [hi]) + rw [ρ.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum he (fun i => w i.1) hop', + Real.entropy_eq, Real.entropy_eq] + exact (sum_eq_sum_subtype_ne_zero w (fun i => (w i).negMulLog) + (fun i hi => by simp [hi, Real.negMulLog_zero])).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ErrorCorrectionDiscretization.lean b/LeanPool/AxQM/Postulates/API/ErrorCorrectionDiscretization.lean new file mode 100644 index 0000000000..abbb06d624 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ErrorCorrectionDiscretization.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuantumChannel + +/-! +# AxQM.Postulates.API — discretization of the errors (Nielsen & Chuang, Theorem 10.2) + +Nielsen & Chuang's **Theorem 10.2** (the *discretization of the errors*, p. 438) is the deep fact +that makes quantum error-correction possible: a recovery operation built to correct one noise +process automatically corrects a whole *continuum* of noise processes. + +Discretization: R correcting noise E also corrects any F whose op elements are linear combinations +of Ei. + +## The structural core the proof uses + +The recovery `R` constructed in Theorem 10.1 has operation elements `{Rₖ}` (concretely +`Rₖ = Uₖ† Pₖ`) with the property that, on the code space, it maps each error `Eᵢ` back into the +code up to a scalar: N&C's Equation (10.35) reads `Uₖ† Pₖ Eᵢ √ρ = δₖᵢ √dₖₖ √ρ`, i.e. at the +operator level + + `Rₖ Eᵢ P = cₖᵢ P` + +for a code projector `P` and scalars `cₖᵢ` (Equation (10.29) of the necessity half of +Theorem 10.1). This **clean correction criterion** — captured here by `CorrectsErrors` — is the +*only* property of the constructed `R` that Theorem 10.2's proof uses, so we take it as the +hypothesis: the theorem is proved for **any** recovery `R` correcting `{Eᵢ}` in this sense, of +which Theorem 10.1's `R` is the instance. This is a faithful reading (a mild generalisation, not a +weakening): Theorem 10.1's specific `R` satisfies the hypothesis by construction. + +## Contents + +* `AxQM.CorrectsErrors` — the clean correction criterion `∃ c, ∀ k i, Rₖ Eᵢ P = cₖᵢ P` + for a code projector `P`, recovery elements `R`, and error elements `E`. +* `AxQM.correctsErrors_linearCombination` — **Theorem 10.2, core.** If `R` corrects `E` + then it corrects any `F` with `Fⱼ = ∑ᵢ mⱼᵢ Eᵢ` (the new scalars are `∑ᵢ mⱼᵢ cₖᵢ`). This is the + discretization step: `{Eᵢ}` correctable ⟹ every linear-combination family is correctable. +* `AxQM.CorrectsErrors.krausSumₗ_op_proportional` — the physical meaning of "corrects" + (N&C Eq. (10.15) and (10.38)–(10.40)): if `R` corrects `G`, there is a **single** `λ ≥ 0` + (state-independent, `λ = ∑ₖⱼ ‖cₖⱼ‖²`) with `(R ∘ G)(ρ) = ∑ₖⱼ Rₖ Gⱼ ρ Gⱼ† Rₖ† = λ ρ` for **every** + code state `ρ` (`P ρ P = ρ`) — `∃ λ, ∀ ρ`, so `R ∘ G` is proportional to the identity channel on + the code (not a merely per-state factor). +* `AxQM.correctsErrors_krausSumₗ_op_proportional_linearCombination` — the two combined: + Theorem 10.2 in full, `∃ λ ≥ 0, ∀ ρ ⊆ C, (R ∘ F)(ρ) = λ ρ` for the linear-combination noise `F` + (N&C's uniform proportionality constant on the whole code). + +## Operator sums + +The statement of Theorem 10.2 is in [upstream `AxQM/NC/Ch10/Theorem10_2.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Theorem10_2.lean); the declarations are here. + +The operator sum `∑ₖ Rₖ (·) Rₖ†` is the existing `ContinuousLinearMap.krausSumₗ` (N&C Chapter 8), +so `(R ∘ F)(ρ)` is `krausSumₗ R (krausSumₗ F ρ)`. +-/ + +@[expose] public section + +open scoped ComplexConjugate InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A recovery family corrects a set of errors on a code** (Nielsen & Chuang, the clean +correction criterion of Theorem 10.1, Eqs. (10.29) and (10.35)). Given a code projector +`P : S.space →L[ℂ] S.space`, recovery operation elements `R : κ → S.space →L[ℂ] S.space`, and error +operation elements `E : ι → S.space →L[ℂ] S.space`, we say `R` **corrects** `E` on the code `P` +when there are scalars `cₖᵢ` with + + `Rₖ Eᵢ P = cₖᵢ P` for all `k, i` + +(operator product `R k * E i * P`, composition on `S.space`). Physically: after an error `Eᵢ` acts +on a code state and recovery Kraus element `Rₖ` is applied, the result is the code state back again +up to the scalar `cₖᵢ`. This is exactly the structural property of the recovery operation `R` +constructed in the proof of Theorem 10.1 (N&C Eq. (10.35), `Uₖ† Pₖ Eᵢ √ρ = δₖᵢ √dₖₖ √ρ`), and the +only property Theorem 10.2 needs. -/ +def CorrectsErrors {κ ι : Type*} (P : S.space →L[ℂ] S.space) + (R : κ → S.space →L[ℂ] S.space) (E : ι → S.space →L[ℂ] S.space) : Prop := + ∃ c : κ → ι → ℂ, ∀ (k : κ) (i : ι), R k * E i * P = c k i • P + +/-- **Discretization of the errors** (Nielsen & Chuang, Theorem 10.2 — the core step). If a +recovery family `R` corrects the errors `E` on the code `P` (`CorrectsErrors P R E`), then it also +corrects any family `F` whose operation elements are **linear combinations** `Fⱼ = ∑ᵢ mⱼᵢ Eᵢ` of +the `Eᵢ` (here `F = fun j => ∑ i, m j i • E i`). + +The witnessing scalars for `F` are `cₖⱼ' = ∑ᵢ mⱼᵢ cₖᵢ`, since +`Rₖ (∑ᵢ mⱼᵢ Eᵢ) P = ∑ᵢ mⱼᵢ (Rₖ Eᵢ P) = ∑ᵢ mⱼᵢ cₖᵢ P = (∑ᵢ mⱼᵢ cₖᵢ) P`. This is the essence of the +discretization: correctability of `{Eᵢ}` transfers to every family built from linear combinations +of the `Eᵢ`, so a single recovery covers a whole (continuous) class of noise processes. -/ +theorem correctsErrors_linearCombination {κ ι ι' : Type*} [Fintype ι] + {P : S.space →L[ℂ] S.space} {R : κ → S.space →L[ℂ] S.space} + {E : ι → S.space →L[ℂ] S.space} (m : ι' → ι → ℂ) (h : CorrectsErrors P R E) : + CorrectsErrors P R (fun j => ∑ i, m j i • E i) := by + obtain ⟨c, hc⟩ := h + refine ⟨fun k j => ∑ i, m j i * c k i, fun k j => ?_⟩ + simp only [Finset.mul_sum, Finset.sum_mul, mul_smul_comm, smul_mul_assoc, hc, Finset.sum_smul, + smul_smul] + +/-- **A corrected noise process is discretized to a single scalar on the code** (Nielsen & Chuang, +Theorem 10.2, Eqs. (10.38)–(10.40); the physical meaning of "the recovery `R` corrects the noise"). +If the recovery family `R` corrects the errors `G` on the code `P` (`CorrectsErrors P R G`) and the +code projector `P` is self-adjoint, then there is **one** nonnegative constant `λ` — depending only +on `R`, `G`, `P` (not on the state) — such that for **every** state `ρ` whose support lies in the +code (`P ρ P = ρ`), applying the noise `G` and then the recovery `R` returns `ρ` scaled by that same +`λ`: + + `∃ λ ≥ 0, ∀ ρ ⊆ C, (R ∘ G)(ρ) = ∑ₖⱼ Rₖ Gⱼ ρ Gⱼ† Rₖ† = λ ρ`, `λ = ∑ₖⱼ ‖cₖⱼ‖²`. + +The order of quantifiers matters: `∃ λ, ∀ ρ` says `R ∘ G` acts as the *same* scalar multiple of the +identity on the whole code (N&C Eq. (10.39)'s state-independent constant `∑ₖⱼ|mⱼₖ|²dₖₖ`), so it +preserves code-state superpositions — genuine error-correction. (The weaker `∀ ρ, ∃ λ` would admit +`ρ`-dependent factors that corrupt superpositions.) This is N&C's `R(E(ρ)) ∝ ρ` (Eq. (10.15)): with +`Rₖ Gⱼ P = cₖⱼ P` and `ρ = P ρ P`, each term is `Rₖ Gⱼ ρ Gⱼ† Rₖ† = (cₖⱼ P) ρ (cₖⱼ P)† = ‖cₖⱼ‖² ρ`, +and the constant `∑ₖⱼ ‖cₖⱼ‖²` is built from the correction scalars `cₖⱼ` alone. -/ +theorem CorrectsErrors.krausSumₗ_op_proportional {κ ι : Type*} [Fintype κ] [Fintype ι] + {P : S.space →L[ℂ] S.space} {R : κ → S.space →L[ℂ] S.space} + {G : ι → S.space →L[ℂ] S.space} (h : CorrectsErrors P R G) (hP : IsSelfAdjoint P) : + ∃ lam : ℝ, 0 ≤ lam ∧ ∀ ρ : State S, P * ρ.op * P = ρ.op → + ContinuousLinearMap.krausSumₗ R (ContinuousLinearMap.krausSumₗ G ρ.op) + = (lam : ℂ) • ρ.op := by + obtain ⟨c, hc⟩ := h + refine ⟨∑ k, ∑ j, Complex.normSq (c k j), + Finset.sum_nonneg fun k _ => Finset.sum_nonneg fun j _ => Complex.normSq_nonneg _, ?_⟩ + intro ρ hρ + -- each recovery element sends `Gⱼ P` to a scalar; its adjoint sends `P Gⱼ†` to the conjugate + have key2 : ∀ (k : κ) (j : ι), + P * star (G j) * star (R k) = star (c k j) • P := by + intro k j + have hstar := congrArg star (hc k j) + rwa [star_mul, star_mul, hP.star_eq, star_smul, hP.star_eq, ← mul_assoc] at hstar + -- coefficient identity `cₖⱼ · cₖⱼ⋆ = ‖cₖⱼ‖²` (`Complex.mul_conj`, with `star = conj` on ℂ) + have hcoef : ∀ (k : κ) (j : ι), + c k j * star (c k j) = (↑(Complex.normSq (c k j)) : ℂ) := fun k j => Complex.mul_conj _ + -- per-term: `Rₖ (Gⱼ ρ Gⱼ†) Rₖ† = ‖cₖⱼ‖² ρ` for `ρ` supported in the code + have term : ∀ (k : κ) (j : ι), + R k * (G j * ρ.op * star (G j)) * star (R k) + = (↑(Complex.normSq (c k j)) : ℂ) • ρ.op := by + intro k j + calc R k * (G j * ρ.op * star (G j)) * star (R k) + = (R k * G j * P) * ρ.op * (P * star (G j) * star (R k)) := by + conv_lhs => rw [← hρ] + simp only [mul_assoc] + _ = (c k j • P) * ρ.op * (star (c k j) • P) := by rw [hc k j, key2 k j] + _ = (c k j * star (c k j)) • (P * ρ.op * P) := by + rw [smul_mul_assoc, smul_mul_assoc, mul_smul_comm, smul_smul] + _ = (↑(Complex.normSq (c k j)) : ℂ) • ρ.op := by rw [hρ, hcoef k j] + -- assemble the double sum + simp only [ContinuousLinearMap.krausSumₗ_eq_sum_mul_star, Finset.sum_mul, Finset.mul_sum, + Complex.ofReal_sum, Finset.sum_smul] + exact Finset.sum_congr rfl fun k _ => Finset.sum_congr rfl fun j _ => term k j + +/-- **Theorem 10.2 (discretization of the errors), in full** (Nielsen & Chuang, p. 438). If a +recovery family `R` corrects the errors `E` on the code `P` (`CorrectsErrors P R E`), `P` is a +self-adjoint code projector, and the noise `F` has operation elements that are **linear +combinations** `Fⱼ = ∑ᵢ mⱼᵢ Eᵢ` of the `Eᵢ`, then `R` also corrects `F`: there is a **single** +nonnegative constant `λ` (independent of the state) with + + `∀ ρ ⊆ C, (R ∘ F)(ρ) = λ ρ`, + +i.e. `R ∘ F` is proportional to the identity channel on the whole code — N&C's `R(F(ρ)) ∝ ρ` with +the uniform constant `∑ₖⱼ|mⱼₖ|²dₖₖ` of Eq. (10.39). Combines `correctsErrors_linearCombination` +(correctability transfers to the linear-combination family) with +`CorrectsErrors.krausSumₗ_op_proportional` (a corrected noise is returned to *one* scalar multiple +of the code states). -/ +theorem correctsErrors_krausSumₗ_op_proportional_linearCombination {κ ι ι' : Type*} + [Fintype κ] [Fintype ι] [Fintype ι'] {P : S.space →L[ℂ] S.space} + {R : κ → S.space →L[ℂ] S.space} {E : ι → S.space →L[ℂ] S.space} (m : ι' → ι → ℂ) + (h : CorrectsErrors P R E) (hP : IsSelfAdjoint P) : + ∃ lam : ℝ, 0 ≤ lam ∧ ∀ ρ : State S, P * ρ.op * P = ρ.op → + ContinuousLinearMap.krausSumₗ R + (ContinuousLinearMap.krausSumₗ (fun j => ∑ i, m j i • E i) ρ.op) + = (lam : ℂ) • ρ.op := + (correctsErrors_linearCombination m h).krausSumₗ_op_proportional hP + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Evolution.lean b/LeanPool/AxQM/Postulates/API/Evolution.lean new file mode 100644 index 0000000000..b62373958d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Evolution.lean @@ -0,0 +1,415 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.Postulates.API.Purity +public import Mathlib.Analysis.CStarAlgebra.Exponential + +/-! +# AxQM.Postulates.API — the Hamiltonian propagator + +The connection between the **continuous-time** picture of dynamics +(Nielsen–Chuang's Postulate 2′, the Schrödinger equation `iℏ d|ψ⟩/dt = H|ψ⟩` with a +Hermitian **Hamiltonian** `H`) and the **discrete-time** picture (Postulate 5 here / N&C's +Postulate 2, a unitary `Evolution`). Solving the Schrödinger equation for a +time-independent `H` gives (N&C eq. 2.90–2.91) +`|ψ(t₂)⟩ = U(t₁,t₂) |ψ(t₁)⟩`, `U(t₁,t₂) ≡ exp(-i H (t₂ - t₁) / ℏ)`. + +* `Observable.propagator H ℏ t₁ t₂` — the **time-evolution operator** `U(t₁,t₂)`, packaged + as an `Evolution S`. An `Evolution` *bundles* the unitarity obligation, so the + very existence of this term is Nielsen–Chuang **Exercise 2.55** ("prove that `U(t₁,t₂)` is + unitary"): the construction discharges exactly that proof obligation. +* `Observable.propagator_op` — its form exposing the operator as the exponential + `exp(-i H (t₂ - t₁) / ℏ)` (N&C eq. 2.91). +* `Observable.propagator_op_mem_unitary` — the literal statement of Exercise 2.55: that + exponential lies in the unitary group. + +This file also provides the general constructor `Evolution.ofLinearIsometryEquiv`, packaging a +linear isometry equivalence of `S.space` as a unitary `Evolution S`, and its inverse +`Evolution.toIsometryEquiv`, repackaging a unitary `Evolution` as a `≃ₗᵢ`. They are the standard +bridges used wherever a state is transformed by an *explicitly constructed* unitary — e.g. the +local unitaries relating two states with identical Schmidt coefficients (N&C Exercise 2.80) or two +purifications (Exercise 2.81) — or wherever an `Evolution`-valued unitary must feed an API expecting +a `≃ₗᵢ`. + +## Why the exponential is unitary + +Write the exponent as `i • a` with `a = (-(t₂ - t₁)/ℏ) • H.op` a **self-adjoint** operator +(a real multiple of the self-adjoint `H.op`). For self-adjoint `a`, `exp(i • a)` is unitary +— this is Mathlib's `selfAdjoint.expUnitary`, whose underlying fact is `(exp(i a))† = +exp(-i a) = exp(i a)⁻¹`. Physically this is why probability is conserved: a Hermitian +generator produces a norm-preserving evolution. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A linear isometry equivalence of `S.space`, packaged as a unitary evolution of `S`.** The +standard bridge from an explicitly constructed unitary (as a `LinearIsometryEquiv`) to the +`Evolution` structure: `Evolution` bundles the unitarity obligation, discharged here from +`Unitary.linearIsometryEquiv` (unitary operators on a Hilbert space are exactly its linear +isometry equivalences). Its action is `L` itself (`Evolution.ofLinearIsometryEquiv_op_apply`). -/ +def Evolution.ofLinearIsometryEquiv (L : S.space ≃ₗᵢ[ℂ] S.space) : Evolution S := + letI : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + ⟨↑(Unitary.linearIsometryEquiv.symm L), (Unitary.linearIsometryEquiv.symm L).2⟩ + +/-- The evolution `Evolution.ofLinearIsometryEquiv L` acts as `L` on vectors: its underlying +operator applied to `x` is `L x`. -/ +@[simp] +theorem Evolution.ofLinearIsometryEquiv_op_apply (L : S.space ≃ₗᵢ[ℂ] S.space) (x : S.space) : + (Evolution.ofLinearIsometryEquiv L).op x = L x := by + simp [Evolution.ofLinearIsometryEquiv, Unitary.coe_symm_linearIsometryEquiv_apply] + +/-- **A unitary `Evolution` packaged as a linear isometry equivalence** of `S.space` — the inverse +direction of `Evolution.ofLinearIsometryEquiv`. A unitary operator on a (finite-dimensional, hence +complete) Hilbert space is exactly a linear isometry equivalence (`Unitary.linearIsometryEquiv`), so +this repackages `U.op` losslessly. The general bridge used wherever an `Evolution`-valued unitary +must be handed to an API expecting a `≃ₗᵢ` (e.g. feeding a gate schedule into a +recursion typed over `S.space ≃ₗᵢ[ℂ] S.space`). Its action is `U.op` itself +(`Evolution.toIsometryEquiv_apply`). -/ +def Evolution.toIsometryEquiv (U : Evolution S) : S.space ≃ₗᵢ[ℂ] S.space := + letI : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + Unitary.linearIsometryEquiv ⟨U.op, U.unitary⟩ + +/-- The linear isometry equivalence `Evolution.toIsometryEquiv U` acts as the evolution's operator +`U.op` on vectors. -/ +@[simp] +theorem Evolution.toIsometryEquiv_apply (U : Evolution S) (x : S.space) : + U.toIsometryEquiv x = U.op x := by + let : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + exact DFunLike.congr_fun (Unitary.coe_linearIsometryEquiv_apply ⟨U.op, U.unitary⟩) x + +/-- **The evolved-state operator as a conjugation by an isometry equivalence.** The density +operator `U ρ U†` of the evolved state `U.evolve ρ` is `ρ.op` conjugated by the isometry +equivalence `U.toIsometryEquiv`: + +`(U.evolve ρ).op = (U.toIsometryEquiv).conjStarAlgEquiv ρ.op`. + +The `Evolution.evolve` counterpart of the transport bridges `State.congr_op` / `Evolution.congr_op` +(which deliver the same `…conjStarAlgEquiv …` form for a *system* isomorphism): it repackages the +composition form `U.op ∘ ρ.op ∘ U.op†` of `Evolution.evolve_op` as a `conjStarAlgEquiv`, so any +spectral/unitary-invariance lemma stated over `conjStarAlgEquiv` (e.g. +`ContinuousLinearMap.vonNeumannEntropy_conjStarAlgEquiv`) can be consumed by name. -/ +theorem Evolution.evolve_op_conjStarAlgEquiv (U : Evolution S) (ρ : State S) : + (U.evolve ρ).op = U.toIsometryEquiv.conjStarAlgEquiv ρ.op := by + ext x + rw [Evolution.evolve_op, LinearIsometryEquiv.conjStarAlgEquiv_apply_apply] + simp only [ContinuousLinearMap.comp_apply, Evolution.toIsometryEquiv_apply] + congr 2 + +/-- **Conjugation by a self-adjoint unitary.** When the unitary `U` of an evolution is self-adjoint +(`U† = U`, e.g. a reflection, a Pauli, or a sign operator), the evolved-state operator is the plain +two-sided product `(U.evolve ρ).op = U ρ U`, since the adjoint in `U ρ U†` collapses. The reusable +bridge behind the conjugation identities of such involutive unitaries. -/ +theorem Evolution.evolve_op_of_isSelfAdjoint {U : Evolution S} (hU : IsSelfAdjoint U.op) + (ρ : State S) : (U.evolve ρ).op = U.op * ρ.op * U.op := by + have hadj : adjoint U.op = U.op := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact hU.star_eq + rw [Evolution.evolve_op, hadj, ← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, + mul_assoc] + +/-- **The Hamiltonian propagator** `U(t₁,t₂) ≡ exp(-i H (t₂ - t₁) / ℏ)` (Nielsen–Chuang +eq. 2.91), packaged as an `Evolution S`. Given the Hamiltonian `H` (an `Observable`, i.e. a +Hermitian operator), Planck's constant `ℏ`, and two times `t₁ t₂`, this is the operator that +solves the Schrödinger equation, `|ψ(t₂)⟩ = U(t₁,t₂)|ψ(t₁)⟩`. + +Because `Evolution` bundles the unitarity obligation, producing this term *is* the content of +**N&C Exercise 2.55**: `U(t₁,t₂)` is unitary. The exponent `-i H (t₂ - t₁)/ℏ` equals +`i • ((-(t₂ - t₁)/ℏ) • H.op)`, i.e. `i` times a self-adjoint operator, and the exponential of +`i` times a self-adjoint operator is unitary (`selfAdjoint.expUnitary`). -/ +def Observable.propagator (H : Observable S) (ℏ t₁ t₂ : ℝ) : Evolution S where + op := NormedSpace.exp (((-Complex.I) * ((t₂ - t₁ : ℝ) : ℂ) / (ℏ : ℂ)) • H.op) + unitary := by + -- Reshape the physical exponent `-i(t₂-t₁)/ℏ • H.op` as `i • (s • H.op)` with the real + -- scalar `s = -(t₂-t₁)/ℏ`, i.e. `i` times the self-adjoint operator `s • H.op`. + have ha : IsSelfAdjoint (((-(t₂ - t₁) / ℏ : ℝ) : ℂ) • H.op) := + ((Complex.im_eq_zero_iff_isSelfAdjoint _).mp rfl).smul H.selfAdjoint + have hc : ((-Complex.I) * ((t₂ - t₁ : ℝ) : ℂ) / (ℏ : ℂ)) • H.op + = Complex.I • (((-(t₂ - t₁) / ℏ : ℝ) : ℂ) • H.op) := by + rw [smul_smul]; push_cast; ring_nf + rw [hc, ← selfAdjoint.expUnitary_coe ⟨((-(t₂ - t₁) / ℏ : ℝ) : ℂ) • H.op, + selfAdjoint.mem_iff.mpr ha⟩] + exact (selfAdjoint.expUnitary _).2 + +@[simp] +theorem Observable.propagator_op (H : Observable S) (ℏ t₁ t₂ : ℝ) : + (H.propagator ℏ t₁ t₂).op + = NormedSpace.exp (((-Complex.I) * ((t₂ - t₁ : ℝ) : ℂ) / (ℏ : ℂ)) • H.op) := rfl + +/-- **Nielsen–Chuang Exercise 2.55.** The time-evolution operator +`U(t₁,t₂) = exp(-i H (t₂ - t₁) / ℏ)` (eq. 2.91) generated by a Hamiltonian `H` is unitary. +The citable operator-level statement; it is exactly the unitarity field of +`Observable.propagator` read through `Observable.propagator_op`. -/ +theorem Observable.propagator_op_mem_unitary (H : Observable S) (ℏ t₁ t₂ : ℝ) : + NormedSpace.exp (((-Complex.I) * ((t₂ - t₁ : ℝ) : ℂ) / (ℏ : ℂ)) • H.op) + ∈ unitary (S →L[ℂ] S) := + (H.propagator ℏ t₁ t₂).unitary + +/-! ### Adjoint (inverse) evolution and eigenstates -/ + +/-- **The adjoint evolution** `U†`, whose operator is the Hilbert-space adjoint of `U.op`. +Because `U` is unitary (`U† U = U U† = 1`), `U†` is again a unitary `Evolution` and is the +inverse gate `U⁻¹`; it reverses the action of `U` (`U†` after `U` is the identity, via +`Evolution.adjoint_comp_self`). It is the "uncompute" step of a compute–phase–uncompute +circuit (N&C Problem 4.1). -/ +def Evolution.adjoint (U : Evolution S) : Evolution S where + op := ContinuousLinearMap.adjoint U.op + unitary := by + -- `U.adjoint.op = star U.op`, so unitarity is the star-closure of the unitary group. + rw [← ContinuousLinearMap.star_eq_adjoint] + exact Unitary.star_mem U.unitary + +@[simp] +theorem Evolution.adjoint_op (U : Evolution S) : + U.adjoint.op = ContinuousLinearMap.adjoint U.op := rfl + +/-- The co-isometry identity `U U† = 1` extracted from unitarity: the `U U† = 1` companion of the +frozen `Evolution.adjoint_comp_self` (which gives the isometry identity `U† U = 1`). Both halves of +unitarity are then citable facts for controlled/composed-unitarity proofs. -/ +theorem Evolution.comp_adjoint_self (U : Evolution S) : + U.op.comp (ContinuousLinearMap.adjoint U.op) = 1 := by + have h := (Unitary.mem_iff.mp U.unitary).2 + rwa [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def] at h + +/-- **Uncompute cancellation** `U†(Uψ) = ψ`: applying the adjoint gate `U†` after `U` returns any +pure state unchanged, since `U` is unitary (`U† U = 1`, `Evolution.adjoint_comp_self`). The +pure-state form of the compute–uncompute identity. -/ +theorem Evolution.evolvePure_adjoint_evolvePure (U : Evolution S) (ψ : PureState S) : + U.adjoint.evolvePure (U.evolvePure ψ) = ψ := by + apply PureState.ext + simp only [Evolution.evolvePure_vec, Evolution.adjoint_op] + rw [← ContinuousLinearMap.comp_apply, Evolution.adjoint_comp_self, + one_apply_eq_self] + +/-- **Uncompute cancellation** `U(U†ψ) = ψ`: applying `U` after its adjoint `U†` returns any pure +state unchanged, since `U` is unitary (`U U† = 1`, `Evolution.comp_adjoint_self`). The companion of +`Evolution.evolvePure_adjoint_evolvePure` with the roles of `U` and `U†` swapped. -/ +theorem Evolution.evolvePure_adjoint_evolvePure' (U : Evolution S) (ψ : PureState S) : + U.evolvePure (U.adjoint.evolvePure ψ) = ψ := by + apply PureState.ext + simp only [Evolution.evolvePure_vec, Evolution.adjoint_op] + rw [← ContinuousLinearMap.comp_apply, Evolution.comp_adjoint_self, + one_apply_eq_self] + +/-- **A unitary maps `normalize v` to `normalize (U v)`.** If a gate `U` sends the nonzero vector +`v` to `w`, then it sends the unit vector `normalize v` to `normalize w`: `U` preserves norms +(`Evolution.norm_op_apply`), so the two normalisation factors agree. The general bridge that lifts +an operator identity `U.op v = w` to a `PureState` equality +`U.evolvePure (normalize v) = normalize w`. -/ +theorem Evolution.evolvePure_normalize_of_op_eq (U : Evolution S) {v w : S} + (hv : v ≠ 0) (hw : w ≠ 0) (h : U.op v = w) : + U.evolvePure (PureState.normalize v hv) = PureState.normalize w hw := by + ext1 + have hn : ‖v‖ = ‖w‖ := by rw [← h, U.norm_op_apply] + rw [Evolution.evolvePure_vec, PureState.normalize_vec, map_smul, h, PureState.normalize_vec, hn] + +/-- **Gate-level co-isometry cancellation** `U ∘ U† = id`: a unitary evolution followed by its +adjoint is the identity gate. The `Evolution`-valued companion of the op-level +`Evolution.comp_adjoint_self` (`U U† = 1`), and the `U`/`U†`-swapped partner of the frozen +`Evolution.adjoint_comp_self'` (`U† ∘ U = id`). Together they say `U†` is a *two-sided* inverse +gate for `U`, so `U` is invertible in the composition monoid. -/ +theorem Evolution.comp_adjoint_self' (U : Evolution S) : U.comp U.adjoint = Evolution.id := by + apply Evolution.ext + rw [Evolution.comp_op, Evolution.adjoint_op, Evolution.id_op, U.comp_adjoint_self] + +/-- **State-level uncompute cancellation** `U†(U ρ U†)U = ρ`: conjugating a density operator `ρ` +by a unitary `U` and then by its adjoint `U†` returns `ρ` unchanged, since `U` is unitary +(`U† U = 1`, `Evolution.adjoint_comp_self`). This is the mixed-state (density-operator) form of +`Evolution.evolvePure_adjoint_evolvePure`, and it is the round-trip that makes conjugation of a +state by a unitary invertible — so a channel `ρ ↦ U ρ U†` has the two-sided inverse `ρ ↦ U† ρ U`. -/ +theorem Evolution.evolve_adjoint_evolve (U : Evolution S) (ρ : State S) : + U.adjoint.evolve (U.evolve ρ) = ρ := by + apply State.ext + have hUU : ContinuousLinearMap.adjoint U.op * U.op = 1 := by + rw [ContinuousLinearMap.mul_def]; exact U.adjoint_comp_self + -- `U†(U ρ U†)U = ρ`: unfold the two conjugations to a product and cancel `U† U = 1` twice. + simp only [Evolution.evolve_op, Evolution.adjoint_op, ContinuousLinearMap.adjoint_adjoint, + ← ContinuousLinearMap.mul_def] + rw [mul_assoc U.op (ρ.op * ContinuousLinearMap.adjoint U.op) U.op, + mul_assoc ρ.op (ContinuousLinearMap.adjoint U.op) U.op, hUU, mul_one, ← mul_assoc, hUU, + one_mul] + +/-- **Reversal of a composite circuit under the adjoint** `(U ∘ V)† = V† ∘ U†`: the adjoint +(inverse) of a composition of gates runs the individual adjoints in the *reverse* order. This is the +formal content of the textbook recipe "to reverse a quantum circuit, apply the inverse of each gate +in reverse order": a circuit `U = g_L ∘ ⋯ ∘ g_1` has inverse circuit `U† = g_1† ∘ ⋯ ∘ g_L†`. Lifts +the operator-level `ContinuousLinearMap.adjoint_comp` to the `Evolution` gate monoid. It is the +principle behind the inverse quantum Fourier transform (Nielsen & Chuang Exercise 5.5). -/ +theorem Evolution.adjoint_comp (U V : Evolution S) : + (U.comp V).adjoint = V.adjoint.comp U.adjoint := by + apply Evolution.ext + rw [Evolution.adjoint_op, Evolution.comp_op, Evolution.comp_op, Evolution.adjoint_op, + Evolution.adjoint_op, ContinuousLinearMap.adjoint_comp] + +/-- **The adjoint is an involution** `U†† = U`: inverting an evolution twice returns the original +gate. Lifts `ContinuousLinearMap.adjoint_adjoint` to `Evolution`. In particular every gate is the +inverse of its own inverse, so e.g. the quantum Fourier transform is recovered by inverting the +inverse-QFT circuit (`qftInverseEvolution_adjoint`). -/ +theorem Evolution.adjoint_adjoint (U : Evolution S) : U.adjoint.adjoint = U := by + apply Evolution.ext + rw [Evolution.adjoint_op, Evolution.adjoint_op, ContinuousLinearMap.adjoint_adjoint] + +/-- **State-level uncompute cancellation, swapped** `U (U† ρ U) U† = ρ`: conjugating a density +operator `ρ` by the adjoint `U†` and then by `U` returns `ρ` unchanged, since `U U† = 1`. The +`U`/`U†`-swapped partner of `Evolution.evolve_adjoint_evolve`; derived from it applied to `U†` +together with the involutivity `U†† = U` (`Evolution.adjoint_adjoint`). Together the two lemmas say +`ρ ↦ U ρ U†` and `ρ ↦ U† ρ U` are two-sided inverse channels, the fact behind the *symmetry* of +channel equivalence (N&C Problem 10.1). -/ +theorem Evolution.evolve_adjoint_evolve' (U : Evolution S) (ρ : State S) : + U.evolve (U.adjoint.evolve ρ) = ρ := by + have h := U.adjoint.evolve_adjoint_evolve ρ + rwa [Evolution.adjoint_adjoint] at h + +/-- **The identity evolution acts trivially on states** `1 ρ 1† = ρ`: conjugating a state by the +identity gate returns it unchanged. The density-operator (mixed-state) companion of the pure-state +`Evolution.id_evolvePure`, and the reflexivity witness for channel equivalence (N&C Problem 10.1): +`E = id ∘ E ∘ id`. -/ +@[simp] +theorem Evolution.evolve_id (ρ : State S) : (Evolution.id : Evolution S).evolve ρ = ρ := by + apply State.ext + rw [Evolution.evolve_op, Evolution.id_op, ← ContinuousLinearMap.star_eq_adjoint, star_one, + ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, ContinuousLinearMap.comp_id] + +/-- **`ψ` is an eigenstate of the evolution `U` with eigenvalue `μ`.** The pure-state +eigenvalue equation `U ψ = μ ψ`, with `μ : ℂ` a complex number (a unitary's eigenvalues lie on +the unit circle, so `μ` is generally complex — unlike an observable's real eigenvalues, cf. +`Observable.HasEigenstate`). `U.HasEigenstate μ ψ` is the eigenvalue equation of a unitary on a +state. -/ +def Evolution.HasEigenstate (U : Evolution S) (μ : ℂ) (ψ : PureState S) : Prop := + U.op ψ.vec = μ • ψ.vec + +/-- **A `+1` eigenstate of a unitary evolution is fixed by its `evolvePure`.** If +`U.HasEigenstate 1 ψ` then `U.evolvePure ψ = ψ` — the form for code states of "`ψ` is +stabilized by `U`" (every stabilizer element fixes every code state). -/ +theorem Evolution.HasEigenstate.evolvePure_eq {U : Evolution S} {ψ : PureState S} + (h : U.HasEigenstate 1 ψ) : U.evolvePure ψ = ψ := by + apply PureState.ext + rw [Evolution.evolvePure_vec, h, one_smul] + +/-- **A pure state fixed by `evolvePure` is a `+1` eigenstate.** The converse of +`Evolution.HasEigenstate.evolvePure_eq`: if `U.evolvePure ψ = ψ` then `U.HasEigenstate 1 ψ`. Proved +from `evolvePure_vec`, mirroring the forward direction. -/ +theorem Evolution.hasEigenstate_one_of_evolvePure_eq {U : Evolution S} {ψ : PureState S} + (h : U.evolvePure ψ = ψ) : U.HasEigenstate 1 ψ := by + change U.op ψ.vec = (1 : ℂ) • ψ.vec + rw [← Evolution.evolvePure_vec, h, one_smul] + +/-! ### Global-phase invariance of the induced channel -/ + +/-- **Global-phase invariance of the induced channel.** If the operators of two evolutions `U`, `V` +differ by a unit-modulus scalar `c` (`‖c‖ = 1`, `U.op = c • V.op`) — i.e. `U = V` *up to a global +phase* — then `U` and `V` induce the *same* state evolution `ρ ↦ U ρ U†`. The phase cancels in the +conjugation: `(c • V) ρ (c • V)† = (c · conj c) V ρ V† = ‖c‖² V ρ V† = V ρ V†`. This is the precise +sense in which a global phase is physically unobservable, and the shared lemma behind every +"up to a global phase, two gates are equal" statement (e.g. N&C Exercises 4.3, 4.14). -/ +theorem Evolution.evolve_eq_of_op_eq_phase_smul (U V : Evolution S) {c : ℂ} + (hc : ‖c‖ = 1) (h : U.op = c • V.op) (ρ : State S) : U.evolve ρ = V.evolve ρ := by + apply State.ext + have key : star c * c = 1 := by rw [← starRingEnd_apply, Complex.conj_mul', hc]; norm_num + simp only [Evolution.evolve_op, h, ← ContinuousLinearMap.star_eq_adjoint, star_smul, + ContinuousLinearMap.comp_smul, ContinuousLinearMap.smul_comp, smul_smul, key, one_smul] + +/-! ### Linearity of the operator over scalar-multiplied sums -/ + +/-- **`Evolution.op` distributes over a scalar-multiplied finite sum:** +`V.op (c • Σᵢ g i) = c • Σᵢ V.op (g i)`. An immediate consequence of `Evolution.op` being a +continuous `ℂ`-linear map (`map_smul`/`map_sum`), so it needs nothing about the particular system +`S`. It is used for pushing a gate through an explicit `½ Σ …` basis sum — e.g. the +gate-teleportation assembly's `cnotGate.onRight` over the reshaped register — without +`toLinearMap` bundling. -/ +theorem Evolution.op_smul_sum (V : Evolution S) {ι : Type*} [Fintype ι] (c : ℂ) + (g : ι → S.space) : V.op (c • ∑ i, g i) = c • ∑ i, V.op (g i) := by + rw [map_smul, map_sum] + +/-! ### The operator of a product of gates -/ + +/-- **`Evolution.op` respects monoid (list) products:** the operator of a product of `Evolution` +gates is the product of their operators, `l.prod.op = (l.map Evolution.op).prod`. Both `Evolution`'s +composition monoid and the operator ring `S.space →L[ℂ] S.space` are monoids and `Evolution.op` is +multiplicative (`Evolution.comp_op` + `ContinuousLinearMap.mul_def`), so this is the induced +list-product homomorphism. The reusable bridge from an `Evolution`-level gate product (a circuit as +a product of gates) to the operator-level product — e.g. it lets the symmetric-Trotter step's +palindromic product be reduced to a product of propagator operators. -/ +theorem Evolution.op_prod (l : List (Evolution S)) : + l.prod.op = (l.map Evolution.op).prod := by + induction l with + | nil => simp + | cons U l ih => + rw [List.prod_cons, List.map_cons, List.prod_cons, Evolution.mul_def, Evolution.comp_op, ih, + ContinuousLinearMap.mul_def] + +/-- **`Evolution.op` respects monoid powers:** the operator of an `m`-fold gate power is the +`m`-fold operator power, `(Uᵐ).op = U.opᵐ`. The power specialization of `Evolution.op_prod`: +`Evolution.op` is multiplicative (`Evolution.comp_op`) and unit-preserving (`Evolution.id_op`), so +it commutes with `_ ^ m`. Used to identify the `m`-fold repetition of a gate with the corresponding +operator power — e.g. to rewrite `(e^{-iHt})ᵐ` as `e^{-imHt}` in the propagator power law below. -/ +theorem Evolution.op_pow (U : Evolution S) (m : ℕ) : (U ^ m).op = U.op ^ m := by + induction m with + | zero => simp + | succ n ih => + rw [pow_succ, Evolution.mul_def, Evolution.comp_op, ih, pow_succ, ContinuousLinearMap.mul_def] + +/-- **The propagator semigroup / power law** (Nielsen–Chuang eq. 2.91 iterated): repeating the +unit-`ℏ` propagator over time `t` a total of `m` times is the propagator over time `m·t`, +`(H.propagator 1 0 t)ᵐ = H.propagator 1 0 (m·t)`. Physically, evolving for time `t` `m` times in a +row is evolving for time `m·t`: the `m` exponentials all share the generator `H.op`, so they add. +This is the identity `(e^{-iHt})ᵐ = e^{-imHt}` that Exercise 4.50(b) uses to write the `m`-fold +symmetric-Trotter target `(e^{-2iHΔt})ᵐ` as the exact long-time propagator `e^{-2miHΔt}`. Proved at +the operator level: `Evolution.op_pow` turns the `m`-fold gate power into `exp(_)ᵐ`, +`NormedSpace.exp_nsmul` collects it into a single `exp(m • _)`, and the exponent scalars agree by +`push_cast; ring`. -/ +theorem Observable.propagator_pow (H : Observable S) (t : ℝ) (m : ℕ) : + (H.propagator 1 0 t) ^ m = H.propagator 1 0 ((m : ℝ) * t) := by + have : NormedAlgebra ℚ (S.space →L[ℂ] S.space) := NormedAlgebra.restrictScalars ℚ ℝ _ + apply Evolution.ext + rw [Evolution.op_pow] + simp only [Observable.propagator_op] + rw [← NormedSpace.exp_nsmul] + congr 1 + rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul] + congr 1 + push_cast + ring + +/-- **The two pictures of unitary dynamics agree on a pure state** (Nielsen & Chuang, Exercise 8.1). +The density operator of the unitarily-evolved pure state equals the pure state's density operator +evolved by conjugation: `(U.evolvePure ψ).toState = U.evolve ψ.toState`, i.e. +`|Uψ⟩⟨Uψ| = U|ψ⟩⟨ψ|U†`. This is the equivalence between the vector picture `|ψ⟩ → U|ψ⟩` and the +density picture `ρ → E(ρ) ≡ UρU†` for `ρ = |ψ⟩⟨ψ|`. Reduces (`State.ext`) to the operator identity +`U(|ψ⟩⟨ψ|)U† = |Uψ⟩⟨Uψ|`, discharged by the rank-one composition lemmas. It is the +bridge between `evolvePure` (vector) and `evolve` (density), used wherever a +pure state is transported by a unitary (e.g. Ex 8.1, and the CSS-code equivalence of Ex 10.27). -/ +theorem toState_evolvePure (U : Evolution S) (ψ : PureState S) : + (U.evolvePure ψ).toState = U.evolve ψ.toState := by + apply State.ext + simp only [PureState.toState_op, Evolution.evolvePure_vec, Evolution.evolve_op, + InnerProductSpace.rankOne_comp, InnerProductSpace.comp_rankOne, + ContinuousLinearMap.adjoint_adjoint] + +/-- **Unitary evolution preserves purity.** If a state `ρ` is pure, so is its evolution +`U.evolve ρ = UρU†`: the quantum operation `E(ρ) = UρU†` maps pure states to pure states. Immediate +from `toState_evolvePure`, with `U.evolvePure ψ` the witnessing pure state of the evolved density +operator. -/ +theorem isPure_evolve (U : Evolution S) {ρ : State S} (hρ : ρ.IsPure) : + (U.evolve ρ).IsPure := by + obtain ⟨ψ, rfl⟩ := hρ + exact ⟨U.evolvePure ψ, (toState_evolvePure U ψ).symm⟩ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/EvolutionTensorHom.lean b/LeanPool/AxQM/Postulates/API/EvolutionTensorHom.lean new file mode 100644 index 0000000000..297501d3b2 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/EvolutionTensorHom.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM.Postulates.API — functoriality of the tensor product of gates + +The tensor product `⊗` of `Evolution`s respects composition and +identities — it is a monoidal functor. These are the gate-level lifts of `TensorProduct.mapL_comp` +and `TensorProduct.mapL_one`, complementing the single-factor homomorphisms `Evolution.onLeft_comp` +and `Evolution.onRight_comp`. Their +proofs open a gate to its underlying operator (`Evolution.tmul_op`, `Evolution.comp_op`) and +apply the `TensorProduct.mapL` algebra. + +## What is formalised + +* `Evolution.tmul_comp` — `(a ⊗ c) · (b ⊗ d) = (a·b) ⊗ (c·d)`: composing two product gates composes + their factors. +* `Evolution.id_tmul_id` — `1 ⊗ 1 = 1`: the tensor of the identity gates is the identity gate. +* `Evolution.onLeft_comp_onRight` — `(U ⊗ 1) · (1 ⊗ V) = U ⊗ V`: a local unitary on both factors + factors as an Alice-only gate after a Bob-only gate (and hence, via `Evolution.evolve_comp`, so + does the corresponding evolution), the reusable "peel a local `U ⊗ V`" step of the Proposition + 12.14 reduction. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The tensor product of gates is functorial for composition:** `(a ⊗ c) · (b ⊗ d) = +(a·b) ⊗ (c·d)`. The operator-level content is `TensorProduct.mapL_comp`. -/ +theorem Evolution.tmul_comp (a b : Evolution S) (c d : Evolution T) : + (a ⊗ c).comp (b ⊗ d) = (a.comp b) ⊗ (c.comp d) := by + ext1 + simp only [Evolution.comp_op, Evolution.tmul_op] + exact (TensorProduct.mapL_comp a.op b.op c.op d.op).symm + +/-- **The tensor of two identity gates is the identity:** `1 ⊗ 1 = 1`. The operator-level content is +`TensorProduct.mapL_one`. -/ +theorem Evolution.id_tmul_id : + ((Evolution.id : Evolution S) ⊗ (Evolution.id : Evolution T)) = Evolution.id := by + ext1 + simp only [Evolution.tmul_op, Evolution.id_op] + exact TensorProduct.mapL_one + +/-- **A local unitary on both factors is an Alice gate after a Bob gate:** `(U ⊗ 1) · (1 ⊗ V) = +U ⊗ V`, i.e. `(U.onLeft T).comp (V.onRight S) = U ⊗ V`. The disjoint-factor gates `U ⊗ 1` and +`1 ⊗ V` compose to the product gate `U ⊗ V` (a special case of `Evolution.tmul_comp` with the +trivial factor being the identity). Combined with `Evolution.evolve_comp` this peels a local unitary +`U ⊗ V` into an Alice round `U ⊗ 1` and a Bob round `1 ⊗ V` — the reusable step behind the +Proposition 12.14 LOCC reduction (`OneWayLOCC.prepend_bobMeasure_of_swapSymmetric`). -/ +theorem Evolution.onLeft_comp_onRight (U : Evolution S) (V : Evolution T) : + (U.onLeft T).comp (V.onRight S) = U ⊗ V := by + rw [Evolution.onLeft, Evolution.onRight, Evolution.tmul_comp, Evolution.comp_id, + Evolution.id_comp] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Fannes.lean b/LeanPool/AxQM/Postulates/API/Fannes.lean new file mode 100644 index 0000000000..4a267fd744 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Fannes.lean @@ -0,0 +1,143 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.API.TraceDistance +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MirskyInequality + +/-! +# AxQM — the analytic core of Fannes' inequality + +This file isolates the shared analytic core of Nielsen & Chuang's Theorem 11.6 (Fannes' +inequality), so that both the main bound (eq. (11.44)) and the weaker unconditional bound +(eq. (11.45)) — assembled in `LeanPool/AxQM/NC/Ch11/Theorem6.lean` — apply it rather than each +re-deriving it. + +The core, `State.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff`, bounds the entropy +difference of two states by the "`Δ`-form" + +`|S(ρ) − S(σ)| ≤ Δ · log d + η(Δ)`, where `Δ = ∑ᵢ |rᵢ − sᵢ|` + +is the `ℓ¹` distance between the sorted eigenvalue spectra `r`, `s` of `ρ`, `σ` +(`LinearMap.IsSymmetric.eigenvalues`), `d = finrank`, and `η = Real.negMulLog`. It is stated under +the single hypothesis `‖ρ.op − σ.op‖₁ ≤ 1`, which is exactly what makes the per-eigenvalue +continuity estimate available. + +**Why `Δ`, and why the `‖·‖₁ ≤ 1` hypothesis.** The two N&C bounds diverge only *after* this point +— (11.44) lifts `η(Δ) ≤ η(T)` by monotonicity of `η` (valid for `T ≤ 1/e`), while (11.45) uses the +maximum `η(Δ) ≤ 1/e` — so the last common step is the `Δ`-form, and the core exposes `Δ`. The +hypothesis `‖ρ.op − σ.op‖₁ ≤ 1` gives, via Mirsky's inequality (`Δ ≤ ‖ρ.op − σ.op‖₁`) and the +total-variation bound `|rᵢ − sᵢ| ≤ Δ/2` (both spectra sum to `1`), the per-eigenvalue estimate +`|rᵢ − sᵢ| ≤ Δ/2 ≤ 1/2` that the continuity kernel `Real.abs_negMulLog_sub_le` requires. + +The bounds where `Δ` is controlled by the `traceDistance` are in +`LeanPool/AxQM/NC/Ch11/Theorem6.lean`. + +## Main results + +* `AxQM.State.log_finrank_nonneg` — `0 ≤ log (finrank ℂ S.space)`. +* `AxQM.State.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff` — the `Δ`-form core. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +variable {S : QSystem} + +/-- The logarithm of a quantum system's dimension is nonnegative: a `State` witnesses that +`S.space` is nontrivial, so `finrank ℂ S.space ≥ 1` and `log d ≥ 0`. The foundational +positivity fact used by every `log d`-type entropy bound (here, both forms of Fannes' +inequality). -/ +theorem State.log_finrank_nonneg (ρ : State S) : + 0 ≤ Real.log (Module.finrank ℂ S.space : ℝ) := by + have := ρ.nontrivial_space + have hpos : 0 < Module.finrank ℂ S.space := Module.finrank_pos + exact Real.log_nonneg (by exact_mod_cast hpos) + +/-- **Analytic core of Fannes' inequality** (the `Δ`-form; Nielsen & Chuang Theorem 11.6, the +eq. (11.47)–(11.48) chain). For states `ρ, σ` of a quantum system `S` with sorted eigenvalue +spectra `r, s`, if the trace norm `‖ρ.op − σ.op‖₁ ≤ 1` then, writing `Δ = ∑ᵢ |rᵢ − sᵢ|`, + +`|S(ρ) − S(σ)| ≤ Δ · log d + η(Δ)`, + +where `d = finrank ℂ S.space` and `η = Real.negMulLog`. This is the step both Fannes bounds share; +they differ only in how the final `η(Δ)` term is bounded (see +`LeanPool/AxQM/NC/Ch11/Theorem6.lean`). + +The proof: `S(ρ) = ∑ᵢ η(rᵢ)`, `S(σ) = ∑ᵢ η(sᵢ)` +(`ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq`); Mirsky's inequality +gives `Δ ≤ ‖ρ.op − σ.op‖₁ ≤ 1`; since both spectra sum to `1`, the positive and negative parts of +`rᵢ − sᵢ` each sum to `Δ/2`, so `|rᵢ − sᵢ| ≤ Δ/2 ≤ 1/2` (total variation); the per-eigenvalue +continuity kernel `Real.abs_negMulLog_sub_le` then gives `|η(rᵢ) − η(sᵢ)| ≤ η(|rᵢ − sᵢ|)`, and +summing with the triangle inequality and the grouping bound `Real.sum_negMulLog_le` yields the +claim. -/ +theorem State.abs_vonNeumannEntropy_sub_le_sum_abs_eigenvalues_diff (ρ σ : State S) {n : ℕ} + (hn : Module.finrank ℂ S.space = n) (hT : (ρ.op - σ.op).traceNorm ≤ 1) : + |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + ≤ (∑ i, |ρ.isDensity.isSymmetric.eigenvalues hn i - σ.isDensity.isSymmetric.eigenvalues hn i|) + * Real.log (n : ℝ) + + (∑ i, |ρ.isDensity.isSymmetric.eigenvalues hn i + - σ.isDensity.isSymmetric.eigenvalues hn i|).negMulLog := by + classical + set r : Fin n → ℝ := fun i => ρ.isDensity.isSymmetric.eigenvalues hn i + set s : Fin n → ℝ := fun i => σ.isDensity.isSymmetric.eigenvalues hn i + -- The entropies are the (nat) Shannon entropies of the spectra. + have hSρ : ρ.vonNeumannEntropy = ∑ i, (r i).negMulLog := by + rw [State.vonNeumannEntropy_def, + ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq + ρ.isDensity.isSymmetric hn, Real.entropy_eq] + have hSσ : σ.vonNeumannEntropy = ∑ i, (s i).negMulLog := by + rw [State.vonNeumannEntropy_def, + ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq + σ.isDensity.isSymmetric hn, Real.entropy_eq] + -- Mirsky's inequality (N&C eq. (11.46)): `Δ ≤ ‖ρ.op − σ.op‖₁ ≤ 1`. + have hMirsky : ∑ i, |r i - s i| ≤ (ρ.op - σ.op).traceNorm := + IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm + ρ.isDensity.isPositive.isSelfAdjoint σ.isDensity.isPositive.isSelfAdjoint hn + set Δ : ℝ := ∑ i, |r i - s i| with hΔ_def + have hΔ0 : 0 ≤ Δ := Finset.sum_nonneg fun i _ => abs_nonneg _ + have hΔ1 : Δ ≤ 1 := le_trans hMirsky hT + -- Both spectra are probability distributions: they sum to `1`. + have hrsum : ∑ i, r i = 1 := ρ.isDensity.eigenvalues_sum_eq_one hn + have hssum : ∑ i, s i = 1 := σ.isDensity.eigenvalues_sum_eq_one hn + -- `|rⱼ − sⱼ| ≤ Δ/2`: the total-variation bound for equal-sum vectors. + have hhalfsum : ∀ j, |r j - s j| ≤ Δ / 2 := by + intro j + have hd0 : ∑ i, (r i - s i) = 0 := by rw [Finset.sum_sub_distrib, hrsum, hssum]; ring + have hsplit : (∑ i ∈ Finset.univ.erase j, (r i - s i)) + (r j - s j) = 0 := by + rw [Finset.sum_erase_add Finset.univ _ (Finset.mem_univ j)]; exact hd0 + have hj : r j - s j = -∑ i ∈ Finset.univ.erase j, (r i - s i) := by linarith + have hle : |r j - s j| ≤ ∑ i ∈ Finset.univ.erase j, |r i - s i| := by + rw [hj, abs_neg]; exact Finset.abs_sum_le_sum_abs _ _ + have hsum : (∑ i ∈ Finset.univ.erase j, |r i - s i|) + |r j - s j| = Δ := + Finset.sum_erase_add Finset.univ _ (Finset.mem_univ j) + linarith + have hhalf : ∀ i, |r i - s i| ≤ 1 / 2 := fun i => by have := hhalfsum i; linarith [hΔ1] + -- Per-eigenvalue continuity bound (N&C eq. (11.47)). + have hpt : ∀ i, |(r i).negMulLog - (s i).negMulLog| ≤ (|r i - s i|).negMulLog := fun i => + Real.abs_negMulLog_sub_le (ρ.isDensity.eigenvalues_nonneg hn i) + (ρ.isDensity.eigenvalues_le_one hn i) (σ.isDensity.eigenvalues_nonneg hn i) + (σ.isDensity.eigenvalues_le_one hn i) (hhalf i) + -- Grouping bound (N&C eq. (11.48)). + have hgroup : ∑ i, (|r i - s i|).negMulLog ≤ Δ * Real.log (n : ℝ) + Δ.negMulLog := by + have h := Real.sum_negMulLog_le (a := fun i => |r i - s i|) (fun i => abs_nonneg _) + rw [hΔ_def] + simpa [Fintype.card_fin] using h + calc |ρ.vonNeumannEntropy - σ.vonNeumannEntropy| + = |(∑ i, (r i).negMulLog) - ∑ i, (s i).negMulLog| := by rw [hSρ, hSσ] + _ = |∑ i, ((r i).negMulLog - (s i).negMulLog)| := by rw [Finset.sum_sub_distrib] + _ ≤ ∑ i, |(r i).negMulLog - (s i).negMulLog| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, (|r i - s i|).negMulLog := Finset.sum_le_sum fun i _ => hpt i + _ ≤ Δ * Real.log (n : ℝ) + Δ.negMulLog := hgroup + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Fidelity.lean b/LeanPool/AxQM/Postulates/API/Fidelity.lean new file mode 100644 index 0000000000..22d5b2db2a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Fidelity.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar + +/-! +# AxQM — the fidelity (Nielsen & Chuang §9.2.2) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, §9.2.2 +(equation `(9.53)`, p. 409) define the **fidelity** between two states `ρ` and +`σ` as +``` +F(ρ, σ) ≡ tr √(√ρ σ √ρ), +``` +the trace of the positive square root of `√ρ · σ · √ρ`. It is a second measure +of distance between quantum states (alongside the trace distance, +`State.traceDistance`) and — as N&C develop across §9.2.2 — underlies a genuine +metric (the angle `A(ρ,σ) = arccos F(ρ,σ)`). + +`State.fidelity` formalises this notion: it takes two states and returns the real number `re tr √(√ρ +σ √ρ)`. (The operand `√ρ σ √ρ` is positive semidefinite, so the trace of its CFC square root is a +nonnegative real; the `re` merely extracts it from `ℂ`, exactly as `State.traceOfPow` does for +`tr(ρᵏ)`.) The Nielsen–Chuang Chapter 9 fidelity statements (e.g. Uhlmann's theorem, Thm 9.4) are +stated with `fidelity`. + +## Design: the trace-norm form + +N&C's defining formula `(9.53)` is not manifestly symmetric, and connecting it +to the operator machinery (Uhlmann's theorem, unitary invariance) is far cleaner +through the equivalent **Schatten-1 / trace-norm** form +``` +F(ρ, σ) = ‖√ρ √σ‖₁ (State.fidelity_eq_traceNorm) +``` +which N&C themselves use (their `(9.71)`, `tr|√ρ√σ| = tr √(ρ^{1/2}σρ^{1/2})`). +We take `(9.53)` as the *definition* (faithful to the textbook) and prove the +trace-norm identity: `√ρ σ √ρ = A A†` with `A = √ρ √σ`, so +its CFC square root is `|A†|`, whose trace is `‖A†‖₁ = ‖A‖₁`. All the elementary +fidelity facts below (symmetry, nonnegativity, `F(ρ,ρ) = 1`) then reduce to +trace-norm lemmas. + +## Main definitions + +* `State.fidelity` — the fidelity `tr √(√ρ σ √ρ)` of N&C `(9.53)`. + +## Main statements + +* `State.adjoint_cfc_sqrt_op` — `(√ρ.op)† = √ρ.op`, self-adjointness of the CFC root. +* `State.adjoint_cfc_sqrt_op_mul` — `(√ρ √σ)† = √σ √ρ`. +* `State.fidelity_eq_traceNorm` — the trace-norm form `F(ρ, σ) = ‖√ρ √σ‖₁`. +* `State.fidelity_comm` — symmetry, `F(ρ, σ) = F(σ, ρ)`. +* `State.fidelity_nonneg` — `0 ≤ F(ρ, σ)`. +* `State.fidelity_self` — `F(ρ, ρ) = 1`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The **fidelity** between two states `ρ` and `σ` of the system `S`, +Nielsen & Chuang `(9.53)`: `F(ρ, σ) ≡ tr √(√ρ σ √ρ)`, the trace of the positive +square root of `√ρ · σ · √ρ`. Since that operator is positive semidefinite its +CFC square root has a nonnegative real trace, which `re` extracts (as for +`State.traceOfPow`). -/ +noncomputable def State.fidelity (ρ σ : State S) : ℝ := + RCLike.re ((LinearMap.trace ℂ S.space) + ↑(cfc Real.sqrt (cfc Real.sqrt ρ.op * σ.op * cfc Real.sqrt ρ.op))) + +/-- The **CFC square root of a state's density operator is self-adjoint**, +`(√ρ.op)† = √ρ.op`. A one-line specialisation of Mathlib's `IsSelfAdjoint.cfc` +(a real-valued functional-calculus image is self-adjoint) via `star = adjoint`, +in the `adjoint … = …` spelling the trace-norm manipulations below consume. This +`√ρ` self-adjointness is also needed for the Uhlmann factorisation +`M M† = ρ ⇔ M = √ρ U`. -/ +theorem State.adjoint_cfc_sqrt_op (ρ : State S) : + adjoint (cfc Real.sqrt ρ.op) = cfc Real.sqrt ρ.op := by + rw [← star_eq_adjoint]; exact IsSelfAdjoint.cfc + +/-- The **adjoint of the product `√ρ √σ` is `√σ √ρ`**: `adjoint` is a +`*`-antihomomorphism (`star_mul`) and each CFC square root is self-adjoint +(`State.adjoint_cfc_sqrt_op`). The load-bearing algebraic step shared by the +trace-norm bridge (where `A† = √σ √ρ`) and the symmetry proof. -/ +theorem State.adjoint_cfc_sqrt_op_mul (ρ σ : State S) : + adjoint (cfc Real.sqrt ρ.op * cfc Real.sqrt σ.op) + = cfc Real.sqrt σ.op * cfc Real.sqrt ρ.op := by + rw [← star_eq_adjoint, star_mul, star_eq_adjoint, star_eq_adjoint, + ρ.adjoint_cfc_sqrt_op, σ.adjoint_cfc_sqrt_op] + +/-- The **trace-norm form** of the fidelity: `F(ρ, σ) = ‖√ρ √σ‖₁`, the trace norm +of `√ρ √σ` (N&C `(9.71)`). Writing `A := √ρ √σ`, the operand of `(9.53)` is +`√ρ σ √ρ = A A†` (using `√σ √σ = σ` and self-adjointness of the CFC square roots), +so its CFC square root is `|A†|`; then `re tr|A†| = ‖A†‖₁ = ‖A‖₁`. This trace-norm +form is the shape used to prove symmetry, the bounds `0 ≤ F ≤ 1`, and Uhlmann's +theorem. -/ +theorem State.fidelity_eq_traceNorm (ρ σ : State S) : + ρ.fidelity σ = (cfc Real.sqrt ρ.op * cfc Real.sqrt σ.op).traceNorm := by + set A : S.space →L[ℂ] S.space := cfc Real.sqrt ρ.op * cfc Real.sqrt σ.op with hA + -- `A† = √σ √ρ`. + have hadjA : adjoint A = cfc Real.sqrt σ.op * cfc Real.sqrt ρ.op := by + rw [hA]; exact State.adjoint_cfc_sqrt_op_mul ρ σ + -- `√σ √σ = σ`. + have hσ : cfc Real.sqrt σ.op * cfc Real.sqrt σ.op = σ.op := + cfc_real_sqrt_mul_self_of_nonneg σ.isDensity.nonneg + -- The operand of (9.53) factors as `A A†`. + have hop : cfc Real.sqrt ρ.op * σ.op * cfc Real.sqrt ρ.op = A * adjoint A := by + have hfac : A * adjoint A + = cfc Real.sqrt ρ.op * (cfc Real.sqrt σ.op * cfc Real.sqrt σ.op) * cfc Real.sqrt ρ.op := by + rw [hA, hadjA]; simp only [mul_assoc] + rw [hfac, hσ] + -- `cfc √ (A A†) = |A†|`, and `re tr|A†| = ‖A†‖₁ = ‖A‖₁`. + have hcomp : A.comp (adjoint A) = A * adjoint A := rfl + have habs : cfc Real.sqrt (A * adjoint A) = (adjoint A).absoluteValue := by + rw [absoluteValue_eq_cfc_sqrt, adjoint_adjoint, hcomp] + rw [State.fidelity, hop, habs, + ← traceNorm_eq_re_trace_of_isPositive (absoluteValue_isPositive _), + traceNorm_absoluteValue, traceNorm_adjoint] + +/-- The fidelity is **symmetric**, `F(ρ, σ) = F(σ, ρ)`: through the trace-norm +bridge, `‖√ρ √σ‖₁ = ‖(√ρ √σ)†‖₁ = ‖√σ √ρ‖₁` (`ContinuousLinearMap.traceNorm_adjoint` +and self-adjointness of the CFC square roots). This symmetry is opaque in the +defining formula `(9.53)` but transparent here — one of N&C's motivations for the +trace-norm form. -/ +theorem State.fidelity_comm (ρ σ : State S) : ρ.fidelity σ = σ.fidelity ρ := by + rw [State.fidelity_eq_traceNorm, State.fidelity_eq_traceNorm, + ← traceNorm_adjoint (cfc Real.sqrt σ.op * cfc Real.sqrt ρ.op), + State.adjoint_cfc_sqrt_op_mul σ ρ] + +/-- The fidelity is **nonnegative**, `0 ≤ F(ρ, σ)`; immediate from the trace-norm +bridge and `ContinuousLinearMap.traceNorm_nonneg`. -/ +theorem State.fidelity_nonneg (ρ σ : State S) : 0 ≤ ρ.fidelity σ := by + rw [State.fidelity_eq_traceNorm] + exact traceNorm_nonneg _ + +/-- The fidelity of a state with **itself is one**, `F(ρ, ρ) = 1`: through the +bridge, `‖√ρ √ρ‖₁ = ‖ρ‖₁ = 1`. Here `cfc_real_sqrt_mul_self_of_nonneg` gives +`√ρ √ρ = ρ`, and a density operator has unit trace norm — its trace norm is the +real part of its trace (`traceNorm_eq_re_trace_of_isPositive`, as `ρ.op` is +positive), which is `1` (`State.trace_op_eq_one`). -/ +theorem State.fidelity_self (ρ : State S) : ρ.fidelity ρ = 1 := by + rw [State.fidelity_eq_traceNorm, cfc_real_sqrt_mul_self_of_nonneg ρ.isDensity.nonneg, + traceNorm_eq_re_trace_of_isPositive ρ.isPositive_op, ρ.trace_op_eq_one, RCLike.one_re] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/FourGateReachableCircuit.lean b/LeanPool/AxQM/Postulates/API/FourGateReachableCircuit.lean new file mode 100644 index 0000000000..82f4d73172 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/FourGateReachableCircuit.lean @@ -0,0 +1,145 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableWireMonoid +public import LeanPool.AxQM.Postulates.API.FourGateReversibleWire +public import LeanPool.AxQM.Concrete.FourGateUniversality + +/-! +# The reachable circuit matrices are operators of a register `Evolution` submonoid +(N&C Exercise 4.43, four-gate bridge — the combined matrix→`Evolution` connection) + +The four-gate universality bridge (Exercise 4.43) must exhibit the *abstract* reachable circuit set +of `Concrete.exists_phase_smul_mem_closure_reachableCircuits` — the submonoid +`Concrete.reachableCircuits finFunctionFinEquiv θ` of `Matrix (Fin 2ⁿ⁺¹) (Fin 2ⁿ⁺¹) ℂ`, dense in +`U(2ⁿ⁺¹)` up to a global phase — as circuits of the grounded `H, S, CNOT, Toffoli` gates. The +two generator families of the reachable gate set have each been re-expressed as register `Evolution` +gates: the reachable single-qubit rotations on a wire as members of the register wire submonoid +`reachableRotationWireEvolutions n j θ` (`AxQM/Postulates/API/FourGateReachableWireMonoid.lean`, +`exists_reachableRotationWireEvolution_op_eq`), and the `≤ 2`-control reversible gates as the named +register gates `mcNotWireEvolution (n+1) S t ht` +(`AxQM/Postulates/API/FourGateReversibleWire.lean`). This file **combines** the two into a single +register `Evolution` submonoid and identifies the reachable circuit set with it, one operator at a +time — the register-level counterpart of the abstract matrix submonoid `reachableCircuits`. + +## What is formalised + +* `reachableCircuitEvolutions n θ` — the **register-level reachable circuit submonoid**: the + submonoid of `Evolution (qudit 2ⁿ⁺¹)` generated by the two register generator families — the whole + per-wire reachable-rotation submonoids `reachableRotationWireEvolutions n j θ` (all wires `j`) and + the `≤ 2`-control reversible gates `mcNotWireEvolution (n+1) S t ht` (`|S| ≤ 2`, `t ∉ S`). Its + members are exactly the `Evolution`s whose operators are the reachable circuit matrices — the + register-gate counterpart of `Concrete.reachableCircuits finFunctionFinEquiv θ`. +* `exists_reachableCircuitEvolution_op_eq` — **the matrix→submonoid bridge (operator form)**: every + matrix `M ∈ Concrete.reachableCircuits finFunctionFinEquiv θ` is the operator of some member `E` + of `reachableCircuitEvolutions n θ`: + + `E.op = Matrix.toEuclideanCLM M`. + + Proved by `Submonoid.closure_induction` over the reachable circuit set. On a generator (a member + of `reachableGateSet`): a reachable single-qubit rotation on a wire `j` + (`singleQubitOnWire finFunctionFinEquiv j g`, `g ∈ reachableRotations θ`) is the operator of a + member of `reachableRotationWireEvolutions n j θ` (the per-wire bridge + `exists_reachableRotationWireEvolution_op_eq`), which sits inside the combined generating set; a + `≤ 2`-control reversible gate `permGate finFunctionFinEquiv (mcNotPerm S ht)` + (`IsToffoliPermGate`) is, by definition, the operator of `mcNotWireEvolution (n+1) S t ht` + (`quditGate_op`), also a generator. The `1` / product cases are the multiplicativity of + `Evolution.op` + (`Evolution.id_op` / `Evolution.comp_op`) and of `Matrix.toEuclideanCLM` (`map_one` / `map_mul`). + The whole-circuit analogue of the single-family `exists_reachableRotationWireEvolution_op_eq`. + +This is the register-side identification the density transport +(`AxQM/Postulates/API/FourGateReachableCircuitDensity.lean`) promotes: the matrix density statement +`exists_phase_smul_mem_closure_reachableCircuits`, transported through the continuous `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM`, lands in the closure of the operator image of +`reachableCircuitEvolutions n θ`; the whole-submonoid register lift then re-expresses each such +`Evolution` as a grounded `H, S, CNOT, Toffoli` circuit on the tower. + +The bridge statement is in terms of the reachable circuit matrices (`Concrete.reachableCircuits`, +`Concrete.singleQubitOnWire`, `Concrete.permGate`) and `Evolution.op` / `Matrix.toEuclideanCLM`. +It is placed beside `AxQM/Postulates/API/FourGateReachableWireMonoid.lean` (whose per-wire +submonoid it collects) and `AxQM/Postulates/API/FourGateReversibleWire.lean` (whose +`mcNotWireEvolution` it collects). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The register-level reachable circuit submonoid.** The submonoid of `Evolution (qudit 2ⁿ⁺¹)` +generated by the two register generator families realising the reachable gate set: the whole +per-wire reachable-rotation submonoids `reachableRotationWireEvolutions n j θ` (over every wire +`j`), and the `≤ 2`-control reversible gates `mcNotWireEvolution (n+1) S t ht` (`|S| ≤ 2`, `t ∉ S`) +— the `Toffoli`/`CNOT`/`NOT` register gates. The register-gate counterpart of the abstract matrix +submonoid `Concrete.reachableCircuits finFunctionFinEquiv θ`; its members are exactly the +`Evolution`s whose operators are reachable circuit matrices +(`exists_reachableCircuitEvolution_op_eq`). -/ +noncomputable def reachableCircuitEvolutions (n : ℕ) (θ : ℝ) : + Submonoid (Evolution (qudit (2 ^ (n + 1)))) := + Submonoid.closure + ((⋃ j : Fin (n + 1), + (reachableRotationWireEvolutions n j θ : Set (Evolution (qudit (2 ^ (n + 1)))))) ∪ + {E | ∃ (S : Finset (Fin (n + 1))) (t : Fin (n + 1)) (ht : t ∉ S), + S.card ≤ 2 ∧ E = mcNotWireEvolution (n + 1) S t ht}) + +/-- **The reachable circuit matrices are operators of the register circuit submonoid.** Every matrix +`M ∈ Concrete.reachableCircuits finFunctionFinEquiv θ` is the operator of some member `E` of the +register submonoid `reachableCircuitEvolutions n θ`: + + `E.op = Matrix.toEuclideanCLM M`. + +Proved by `Submonoid.closure_induction` over the reachable circuit set `reachableGateSet`. On a +generator: a reachable single-qubit rotation on a wire `j` (`singleQubitOnWire finFunctionFinEquiv j +g`, `g ∈ reachableRotations θ`) is, by the per-wire bridge +`exists_reachableRotationWireEvolution_op_eq`, the operator of a member of +`reachableRotationWireEvolutions n j θ` — a generator of the combined submonoid; a `≤ 2`-control +reversible gate `permGate finFunctionFinEquiv (mcNotPerm S ht)` (`IsToffoliPermGate`) is, by +definition (`quditGate_op`), the operator of `mcNotWireEvolution (n+1) S t ht`, also a generator. +The unit maps to `1`; products are carried by the multiplicativity of both `Evolution.op` +(`Evolution.comp_op`) and `Matrix.toEuclideanCLM` (`map_mul`). The whole-circuit analogue of the +single-family `exists_reachableRotationWireEvolution_op_eq`; the register-side identification the +density transport promotes onto the grounded `H, S, CNOT, Toffoli` gate set. -/ +theorem exists_reachableCircuitEvolution_op_eq {n : ℕ} {θ : ℝ} + {M : Matrix (Fin (2 ^ (n + 1))) (Fin (2 ^ (n + 1))) ℂ} + (hM : M ∈ Concrete.reachableCircuits finFunctionFinEquiv θ) : + ∃ E ∈ reachableCircuitEvolutions n θ, + E.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ (n + 1))) M := by + induction hM using Submonoid.closure_induction with + | mem x hx => + rcases hx with hperm | hrot + · -- `≤ 2`-control reversible gate: the operator of `mcNotWireEvolution`. + obtain ⟨S, t, ht, hcard, rfl⟩ := hperm + exact ⟨mcNotWireEvolution (n + 1) S t ht, + Submonoid.subset_closure (Or.inr ⟨S, t, ht, hcard, rfl⟩), quditGate_op _⟩ + · -- reachable single-qubit rotation on a wire `j`: a member of the per-wire submonoid. + simp only [Set.mem_iUnion, Set.mem_image] at hrot + obtain ⟨j, g, hg, rfl⟩ := hrot + obtain ⟨F, hF, hFop⟩ := exists_reachableRotationWireEvolution_op_eq (n := n) (t := j) hg + exact ⟨F, Submonoid.subset_closure (Or.inl (Set.mem_iUnion.2 ⟨j, hF⟩)), hFop⟩ + | one => + refine ⟨1, one_mem _, ?_⟩ + rw [Evolution.one_def, Evolution.id_op] + exact (map_one Matrix.toEuclideanCLM).symm + | mul x y _ _ ihx ihy => + obtain ⟨Ex, hEx, hExop⟩ := ihx + obtain ⟨Ey, hEy, hEyop⟩ := ihy + refine ⟨Ex * Ey, mul_mem hEx hEy, ?_⟩ + rw [Evolution.mul_def, Evolution.comp_op, hExop, hEyop] + exact (map_mul Matrix.toEuclideanCLM x y).symm + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/FourGateReachableRotation.lean b/LeanPool/AxQM/Postulates/API/FourGateReachableRotation.lean new file mode 100644 index 0000000000..cb497b82f1 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/FourGateReachableRotation.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledZ +public import LeanPool.AxQM.Postulates.API.ControlledRotation +public import LeanPool.AxQM.Postulates.API.HadamardRotation +public import LeanPool.AxQM.Postulates.API.AxisAngleGateValues +public import LeanPool.AxQM.Concrete.SingleQubitRotationUniversality + +/-! +# The reachable single-qubit rotations are `H, S, CNOT, Toffoli` gates (single-qubit bridge) + +*(Nielsen & Chuang, Exercise 4.43 — the four-gate universality bridge, single-qubit stage.)* + +The matrix-level universality theorem +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` proves that the *abstract* reachable +gate set is dense in `U(d)` up to a global phase, but it never names the four physical gates. This +file discharges the **single-qubit half** of the bridge that ties the abstract generators to the +grounded `H, S, CNOT, Toffoli` gates: it exhibits the single-qubit reachable rotations — the +submonoid `Concrete.reachableRotations θ` whose members appear (via `singleQubitOnWire`) among the +`reachableGateSet` generators — as gates built from `H, S, CNOT, Toffoli` (with measurement). + +## What the four gates realise, at the single qubit + +`reachableRotations θ` is generated by the four `2 × 2` matrices `R_z(±θ), R_x(±θ)`. Each is the +operator of a named-gate circuit: + +* **`R_z(θ)` with `cos θ = 3/5`** is realised by the Exercise 4.41 measurement circuit + `rzThreeFifthsCircuit` — the `(H⊗H)·T·(1⊗1⊗S)·T·(H⊗H)` gadget built from `H, S, CNOT, Toffoli` + — on its measurement-success branch (`rzThreeFifthsCircuit_success_eq_rotZ`). The measurement is + essential: the pure unitary Clifford+Toffoli group is discrete, so `R_z(θ)` (an irrational + rotation, Exercise 4.42) is *only* reachable with the aid of the measurement gadget. +* **`R_x(θ) = H · R_z(θ) · H`** by Hadamard conjugation + (`hadamardGate_comp_rotZGate_comp_hadamardGate`). +* **`R_z(-θ) = X · R_z(θ) · X`** (`pauliXGate_comp_rotZGate_comp_pauliXGate`), with the `NOT` gate + `X = H · S² · H` itself realised by `{H, S}` (`pauliXGate_eq_hadamardGate_sGateSq`, from `S² = Z` + and `H · Z · H = X`). +* **`R_x(-θ) = H · R_z(-θ) · H`** by Hadamard conjugation again. + +So every reachable rotation is a finite composition of `H, S` gates around the measurement-realised +`R_z(θ)` — the single-qubit operations reachable from `{H, S, CNOT, Toffoli}` with measurement. + +## The gate-level submonoid and the matrix bridge + +`reachableRotationGates θ` is the `Evolution`-gate counterpart of `reachableRotations θ`: the +submonoid of `Evolution qubit` generated by the four gates `R_z(±θ), R_x(±θ)`. The bridge +`exists_reachableRotationGate_op_eq` shows each reachable-rotation *matrix* is the operator of a +reachable-rotation *gate*, transporting the matrix submonoid onto the gate submonoid through the +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (each generator matches by definition; +`Evolution.op` and `toEuclideanCLM` are both multiplicative). This is the object the register lift +(`AxQM/Postulates/API/FourGateReachableWire.lean`) promotes onto a chosen wire. +-/ + +@[expose] public section + +namespace AxQM + +open Matrix + +/-- **`S² = Z` at the gate level:** composing the phase gate `S = diag(1, i)` with itself gives the +Pauli-`Z` gate. The gate-level image of `Concrete.sMatrix_mul_self_eq_pauliZ` through +`Matrix.toEuclideanCLM` (`map_mul`); `S²` is the phase flip. -/ +theorem sGate_comp_sGate : sGate.comp sGate = pauliZGate := by + apply Evolution.ext + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix) + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ + rw [← ContinuousLinearMap.mul_def, ← map_mul, Concrete.sMatrix_mul_self_eq_pauliZ] + +/-- **The `NOT` gate is a `{H, S}` circuit:** `X = H · S² · H`. Composing `S² = Z` +(`sGate_comp_sGate`) with `H · Z · H = X` (`hadamardGate_comp_pauliZGate_comp_hadamardGate`), this +exhibits the Pauli-`X` (`NOT`) gate — not itself one of `{H, S, CNOT, Toffoli}` — as built from the +phase gate `S` and Hadamard gate `H`. -/ +theorem pauliXGate_eq_hadamardGate_sGateSq : + pauliXGate = hadamardGate.comp ((sGate.comp sGate).comp hadamardGate) := by + rw [sGate_comp_sGate, hadamardGate_comp_pauliZGate_comp_hadamardGate] + +/-- **`R_z(-θ)` is a `{H, S}` conjugate of `R_z(θ)`:** `R_z(-θ) = (H·S²·H) · R_z(θ) · (H·S²·H)`. +Conjugating a `z`-rotation by the `NOT` gate negates its angle +(`pauliXGate_comp_rotZGate_comp_pauliXGate`), and the `NOT` gate is the `{H, S}` circuit `H·S²·H` +(`pauliXGate_eq_hadamardGate_sGateSq`), so `R_z(-θ)` is reachable +from `{H, S}` together with `R_z(θ)`. -/ +theorem rotZGate_neg_eq_hadamardGate_sGate_conj (θ : ℝ) : + rotZGate (-θ) = + (hadamardGate.comp ((sGate.comp sGate).comp hadamardGate)).comp + ((rotZGate θ).comp (hadamardGate.comp ((sGate.comp sGate).comp hadamardGate))) := by + rw [← pauliXGate_eq_hadamardGate_sGateSq, + pauliXGate_comp_rotZGate_comp_pauliXGate] + +/-- **The reachable single-qubit rotation gates.** The submonoid of `Evolution qubit` generated by +the four gates `R_z(±θ), R_x(±θ)` — the `Evolution`-level counterpart of the matrix submonoid +`Concrete.reachableRotations θ`. With `cos θ = 3/5` these are exactly the single-qubit operations +reachable from `{H, S, CNOT, Toffoli}` with measurement: `R_z(θ)` via the Exercise 4.41 circuit +`rzThreeFifthsCircuit`, and the remaining three by `{H, S}` conjugation (`sGate_comp_sGate`, +`pauliXGate_eq_hadamardGate_sGateSq`, +`hadamardGate_comp_rotZGate_comp_hadamardGate`, `rotZGate_neg_eq_hadamardGate_sGate_conj`). -/ +noncomputable def reachableRotationGates (θ : ℝ) : Submonoid (Evolution qubit) := + Submonoid.closure {rotZGate θ, rotZGate (-θ), rotXGate θ, rotXGate (-θ)} + +/-- **Matrix-to-gate bridge for the reachable rotations.** Every matrix `g` in the reachable +rotation submonoid `Concrete.reachableRotations θ` is the operator of some reachable rotation gate +`E ∈ reachableRotationGates θ`: `E.op = Matrix.toEuclideanCLM g`. Proved by induction on the +submonoid closure — each of the four generator matrices `R_z(±θ), R_x(±θ)` is the operator of the +corresponding gate (`rotZGate_op` / `rotXGate_op`), the unit maps to the identity gate, and products +are carried by the multiplicativity of both `Evolution.op` (`Evolution.comp_op`) and +`Matrix.toEuclideanCLM`. This transports the density statement over `reachableRotations` onto the +grounded `H, S, CNOT, Toffoli` gate set at the single qubit. -/ +theorem exists_reachableRotationGate_op_eq {θ : ℝ} {g : Matrix (Fin 2) (Fin 2) ℂ} + (hg : g ∈ Concrete.reachableRotations θ) : + ∃ E ∈ reachableRotationGates θ, E.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) g := by + induction hg using Submonoid.closure_induction with + | mem x hx => + rcases hx with rfl | rfl | rfl | rfl + · exact ⟨rotZGate θ, Submonoid.subset_closure (by simp), rotZGate_op θ⟩ + · exact ⟨rotZGate (-θ), Submonoid.subset_closure (by simp), rotZGate_op (-θ)⟩ + · exact ⟨rotXGate θ, Submonoid.subset_closure (by simp), rotXGate_op θ⟩ + · exact ⟨rotXGate (-θ), Submonoid.subset_closure (by simp), rotXGate_op (-θ)⟩ + | one => + refine ⟨1, one_mem _, ?_⟩ + rw [Evolution.one_def, Evolution.id_op] + exact (map_one Matrix.toEuclideanCLM).symm + | mul x y _ _ ihx ihy => + obtain ⟨Ex, hEx, hExop⟩ := ihx + obtain ⟨Ey, hEy, hEyop⟩ := ihy + refine ⟨Ex * Ey, mul_mem hEx hEy, ?_⟩ + rw [Evolution.mul_def, Evolution.comp_op, hExop, hEyop] + exact (map_mul Matrix.toEuclideanCLM x y).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/FourGateReachableWire.lean b/LeanPool/AxQM/Postulates/API/FourGateReachableWire.lean new file mode 100644 index 0000000000..9c981caf73 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/FourGateReachableWire.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftHadamardEvolution +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Postulates.API.HadamardRotation +public import LeanPool.AxQM.Concrete.Rotation +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# The reachable single-qubit rotations on a register wire +(N&C Exercise 4.43, four-gate bridge — register-side ingredients) + +The four-gate universality bridge (Exercise 4.43) must exhibit the *abstract* reachable gate set of +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` as circuits of the grounded +`H, S, CNOT, Toffoli` gates. Its single-qubit stage +(`AxQM/Postulates/API/FourGateReachableRotation.lean`) showed each reachable rotation *matrix* +`g ∈ Concrete.reachableRotations θ` is the operator of a reachable rotation *gate* +`E ∈ reachableRotationGates θ` — a finite `{H, S}`-composition around the measurement-realised +`R_z(θ)`. But the reachable gate set uses those rotations placed on an individual **wire** of the +`m`-qubit register, via `Concrete.singleQubitOnWire enc j g`. This file supplies the *register-side* +ingredients that let the tower re-expression (`AxQM/Core/FourGateReachableWireTower.lean`) +identify such a wire gate with the grounded rotation gate placed on that wire — exactly mirroring +the QFT Hadamard layer's `qftHadamardEvolution` / `AxQM/Core/QftTowerHadamard.lean` development. + +## What is formalised + +For the `z`- and `x`-axis reachable rotations (the generators of `Concrete.reachableRotations θ`): + +* `rotZWireEvolution n t θ` / `rotXWireEvolution n t θ` — the rotation `R_z(θ)` / `R_x(θ)` placed on + wire `t` of the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`: the `quditGate` + promotion of the gate matrix `singleQubitOnWire finFunctionFinEquiv t (rotZ θ)` (resp. `rotX θ`). + The direct analogue of `qftHadamardEvolution n t`, with the Hadamard block replaced by a + reachable rotation. +* `rotZWireEvolution_evolvePure_quditBasis` / `rotXWireEvolution_evolvePure_quditBasis` — their + **computational-basis action**: on `|finFunctionFinEquiv f⟩` the wire-`t` component is mixed + through the rotation's column, `∑_z (rotZ θ) z (f t) · |finFunctionFinEquiv (update f t z)⟩`. + Instances of the reusable bridge `quditGate_singleQubitOnWire_evolvePure_quditBasis` at + `G = rotZ θ` (resp. `rotX θ`). +* `rotZGate_evolvePure_qubitBasis_sum` / `rotXGate_evolvePure_qubitBasis_sum` — the **single-qubit + companions**: the one-qubit gate `rotZGate θ` (resp. `rotXGate θ`) acts on a basis state `|z⟩` as + its rotation-matrix column, `rotZGate θ |z⟩ = ∑_w (rotZ θ) w z · |w⟩`. The `d = 2` case of the + column action `Matrix.toEuclideanCLM_apply_single`, read through `rotZGate_op` (resp. + `rotXGate_op`). These are the single-wire factors the tower re-expression matches the register + superposition against. + +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The reachable `z`-rotation on a register wire.** The rotation `R_z(θ)` placed on wire `t` of +the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`: the `quditGate` promotion of the gate +matrix `singleQubitOnWire finFunctionFinEquiv t (rotZ θ)` (unitary, so `quditGate` applies). Its +It is used in the tower re-expression (`AxQM/Core/FourGateReachableWireTower.lean`); its basis +action is `rotZWireEvolution_evolvePure_quditBasis`. The direct analogue of +`qftHadamardEvolution n t` with the Hadamard block replaced by `R_z(θ)`. -/ +def rotZWireEvolution (n : ℕ) (t : Fin n) (θ : ℝ) : Evolution (qudit (2 ^ n)) := + quditGate (singleQubitOnWire_mem_unitaryGroup finFunctionFinEquiv t (rotZ_mem_unitaryGroup θ)) + +/-- **The reachable `x`-rotation on a register wire.** The rotation `R_x(θ)` placed on wire `t` of +the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`: the `quditGate` promotion of +`singleQubitOnWire finFunctionFinEquiv t (rotX θ)`. The `x`-axis counterpart of +`rotZWireEvolution`; its basis action is `rotXWireEvolution_evolvePure_quditBasis`. -/ +def rotXWireEvolution (n : ℕ) (t : Fin n) (θ : ℝ) : Evolution (qudit (2 ^ n)) := + quditGate (singleQubitOnWire_mem_unitaryGroup finFunctionFinEquiv t (rotX_mem_unitaryGroup θ)) + +/-- **The wire-`t` `z`-rotation mixes wire `t` through the `R_z(θ)` column.** +`rotZWireEvolution n t θ |finFunctionFinEquiv f⟩ = ∑_z (rotZ θ) z (f t) · |finFunctionFinEquiv +(update f t z)⟩`: the bit-string `f` addressing the wires has its wire-`t` component rotated, the +two branches carrying amplitudes `(rotZ θ) z (f t)`. The instance of the reusable bridge +`quditGate_singleQubitOnWire_evolvePure_quditBasis` at `G = rotZ θ`, `enc = finFunctionFinEquiv`. -/ +theorem rotZWireEvolution_evolvePure_quditBasis (n : ℕ) (t : Fin n) (θ : ℝ) (f : Fin n → Fin 2) : + ((rotZWireEvolution n t θ).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = ∑ z : Fin 2, rotZ θ z (f t) • + (quditBasis (finFunctionFinEquiv (Function.update f t z))).vec := + quditGate_singleQubitOnWire_evolvePure_quditBasis finFunctionFinEquiv t + (rotZ_mem_unitaryGroup θ) f + +/-- **The wire-`t` `x`-rotation mixes wire `t` through the `R_x(θ)` column.** +`rotXWireEvolution n t θ |finFunctionFinEquiv f⟩ = ∑_z (rotX θ) z (f t) · |finFunctionFinEquiv +(update f t z)⟩`. The `x`-axis instance of `quditGate_singleQubitOnWire_evolvePure_quditBasis`. -/ +theorem rotXWireEvolution_evolvePure_quditBasis (n : ℕ) (t : Fin n) (θ : ℝ) (f : Fin n → Fin 2) : + ((rotXWireEvolution n t θ).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = ∑ z : Fin 2, rotX θ z (f t) • + (quditBasis (finFunctionFinEquiv (Function.update f t z))).vec := + quditGate_singleQubitOnWire_evolvePure_quditBasis finFunctionFinEquiv t + (rotX_mem_unitaryGroup θ) f + +/-- **The qubit `z`-rotation acts as its matrix column.** On a computational-basis state `|z⟩` the +one-qubit gate `rotZGate θ` produces the superposition `∑_w (rotZ θ) w z · |w⟩`. The `d = 2` case of +the column action `Matrix.toEuclideanCLM_apply_single`, read through `rotZGate_op` and +`qubitBasis_vec`. The single-wire factor the tower re-expression of the wire `z`-rotation +(`AxQM/Core/FourGateReachableWireTower.lean`) matches the register superposition +`rotZWireEvolution_evolvePure_quditBasis` against. -/ +theorem rotZGate_evolvePure_qubitBasis_sum (θ : ℝ) (z : Fin 2) : + ((rotZGate θ).evolvePure (qubitBasis z)).vec + = ∑ w : Fin 2, rotZ θ w z • (qubitBasis w).vec := by + rw [Evolution.evolvePure_vec, rotZGate_op, qubitBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single (rotZ θ) z).trans (Finset.sum_congr rfl fun w _ => ?_) + exact congrArg (rotZ θ w z • ·) (qubitBasis_vec w).symm + +/-- **The qubit `x`-rotation acts as its matrix column.** On `|z⟩` the one-qubit gate `rotXGate θ` +produces `∑_w (rotX θ) w z · |w⟩`. The `x`-axis counterpart of `rotZGate_evolvePure_qubitBasis_sum`, +read through `rotXGate_op`. -/ +theorem rotXGate_evolvePure_qubitBasis_sum (θ : ℝ) (z : Fin 2) : + ((rotXGate θ).evolvePure (qubitBasis z)).vec + = ∑ w : Fin 2, rotX θ w z • (qubitBasis w).vec := by + rw [Evolution.evolvePure_vec, rotXGate_op, qubitBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single (rotX θ) z).trans (Finset.sum_congr rfl fun w _ => ?_) + exact congrArg (rotX θ w z • ·) (qubitBasis_vec w).symm + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/FourGateReachableWireMonoid.lean b/LeanPool/AxQM/Postulates/API/FourGateReachableWireMonoid.lean new file mode 100644 index 0000000000..31631ad548 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/FourGateReachableWireMonoid.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.FourGateReachableWire +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Concrete.SingleQubitRotationUniversality + +/-! +# The reachable single-qubit rotation matrices on a wire ARE the register wire submonoid +(N&C Exercise 4.43, four-gate bridge — matrix→submonoid connection) + +The four-gate universality bridge (Exercise 4.43) must exhibit the *abstract* reachable gate set of +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` as circuits of the grounded +`H, S, CNOT, Toffoli` gates. Its rotation half is the reachable single-qubit rotations placed +on a wire: the **matrices** `Concrete.singleQubitOnWire finFunctionFinEquiv t g` for every `g` in +the matrix submonoid `Concrete.reachableRotations θ` (the shape +`⋃ j, singleQubitOnWire enc j '' reachableRotations θ` in which the rotations enter the abstract +`reachableGateSet`). The whole submonoid `reachableRotationWireEvolutions n t θ` of register wire +gates lifts, via `quditPowTower`, to grounded reachable-rotation gates on the tower wire +(`AxQM/Core/FourGateReachableWireSubmonoid.lean`, +`exists_reachableRotationGate_congr_quditPowTower_eq`). This file supplies the **connection** that +feeds that lift: it identifies the `quditGate` promotion of the reachable rotation *matrix* on a +wire with a member of the register wire submonoid. + +## What is formalised + +* `reachableRotationWireEvolutions n t θ` — the **register-level reachable-rotation wire + submonoid**: the submonoid of `Evolution (qudit (2ⁿ⁺¹))` generated by the four wire gates + `rotZWireEvolution (n+1) t (±θ)`, `rotXWireEvolution (n+1) t (±θ)` — the register-gate counterpart + of `Concrete.reachableRotations θ` placed on wire `t`. +* `exists_reachableRotationWireEvolution_op_eq` — **the matrix→submonoid bridge (operator form)**: + every matrix `g ∈ Concrete.reachableRotations θ`, placed on wire `t` as + `singleQubitOnWire finFunctionFinEquiv t g`, is the operator of some member `F` of + `reachableRotationWireEvolutions n t θ`. Proved by `Submonoid.closure_induction`: each of the four + generator matrices `R_z(±θ), R_x(±θ)` on wire `t` is the operator of the corresponding named wire + gate `rotZWireEvolution`/`rotXWireEvolution (n+1) t (±θ)` (by `quditGate_op`), and the `1` / + product cases are the multiplicativity of `Evolution.op` (`Evolution.comp_op`) and of + `singleQubitOnWire` on its `2 × 2` block (`singleQubitOnWire_one` / `singleQubitOnWire_mul`), + carried by `map_one` / `map_mul` of the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`. The exact + wire-level analogue of the single-qubit `exists_reachableRotationGate_op_eq`. +* `quditGate_singleQubitOnWire_mem_reachableRotationWireEvolutions` — **the directly usable form**: + for `g ∈ Concrete.reachableRotations θ` and any unitarity witness `hU`, + `quditGate hU ∈ reachableRotationWireEvolutions n t θ`. Since `quditGate hU` is determined by its + operator alone, it equals the member `F` above (`Evolution.ext`), so it too lies in the submonoid. + This is the object the eventual density transport promotes: the `Evolution` a reachable-rotation + wire matrix generates is a genuine grounded circuit (composed, via the register lift, of the + `{H, S}`-conjugated Exercise 4.41 gadget on a tower wire). +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The register-level reachable-rotation wire submonoid.** The submonoid of +`Evolution (qudit (2ⁿ⁺¹))` generated by the four reachable rotation wire gates +`rotZWireEvolution (n+1) t (±θ)`, `rotXWireEvolution (n+1) t (±θ)` — the register-gate counterpart +of `Concrete.reachableRotations θ` placed on wire `t`. Its members are exactly the register wire +gates whose transport onto the control tower is a grounded reachable rotation gate on the tower wire +`t.rev` (`exists_reachableRotationGate_congr_quditPowTower_eq`), and exactly the `quditGate` +promotions of the reachable rotation matrices on wire `t` +(`quditGate_singleQubitOnWire_mem_reachableRotationWireEvolutions`). -/ +noncomputable def reachableRotationWireEvolutions (n : ℕ) (t : Fin (n + 1)) (θ : ℝ) : + Submonoid (Evolution (qudit (2 ^ (n + 1)))) := + Submonoid.closure {rotZWireEvolution (n + 1) t θ, rotZWireEvolution (n + 1) t (-θ), + rotXWireEvolution (n + 1) t θ, rotXWireEvolution (n + 1) t (-θ)} + +/-- **The reachable rotation matrices on a wire are operators of the register wire submonoid.** +For every matrix `g ∈ Concrete.reachableRotations θ`, its wire-`t` placement +`singleQubitOnWire finFunctionFinEquiv t g` is the operator of some member `F` of the register wire +submonoid `reachableRotationWireEvolutions n t θ`: + + `F.op = Matrix.toEuclideanCLM (singleQubitOnWire finFunctionFinEquiv t g)`. + +Proved by `Submonoid.closure_induction`: each generator matrix `R_z(±θ), R_x(±θ)` on wire `t` is the +operator of the named wire gate `rotZWireEvolution`/`rotXWireEvolution (n+1) t (±θ)` (a generator of +the submonoid, `quditGate_op`); the unit maps to `1`; products are carried by the multiplicativity +of both `Evolution.op` (`Evolution.comp_op`) and `singleQubitOnWire` on its block +(`singleQubitOnWire_mul`), transported through `map_mul` of `Matrix.toEuclideanCLM`. The wire-level +analogue of the single-qubit matrix→gate bridge `exists_reachableRotationGate_op_eq`. -/ +theorem exists_reachableRotationWireEvolution_op_eq {n : ℕ} {t : Fin (n + 1)} {θ : ℝ} + {g : Matrix (Fin 2) (Fin 2) ℂ} (hg : g ∈ Concrete.reachableRotations θ) : + ∃ F ∈ reachableRotationWireEvolutions n t θ, + F.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ (n + 1))) + (singleQubitOnWire finFunctionFinEquiv t g) := by + induction hg using Submonoid.closure_induction with + | mem x hx => + rcases hx with rfl | rfl | rfl | rfl + · exact ⟨rotZWireEvolution (n + 1) t θ, Submonoid.subset_closure (by simp), rfl⟩ + · exact ⟨rotZWireEvolution (n + 1) t (-θ), Submonoid.subset_closure (by simp), rfl⟩ + · exact ⟨rotXWireEvolution (n + 1) t θ, Submonoid.subset_closure (by simp), rfl⟩ + · exact ⟨rotXWireEvolution (n + 1) t (-θ), Submonoid.subset_closure (by simp), rfl⟩ + | one => + refine ⟨1, one_mem _, ?_⟩ + rw [Evolution.one_def, Evolution.id_op, singleQubitOnWire_one] + exact (map_one Matrix.toEuclideanCLM).symm + | mul x y _ _ ihx ihy => + obtain ⟨Fx, hFx, hFxop⟩ := ihx + obtain ⟨Fy, hFy, hFyop⟩ := ihy + refine ⟨Fx * Fy, mul_mem hFx hFy, ?_⟩ + erw [Evolution.mul_def, Evolution.comp_op, hFxop, hFyop, ← ContinuousLinearMap.mul_def, + ← singleQubitOnWire_mul] + exact (map_mul Matrix.toEuclideanCLM _ _).symm + +/-- **A reachable rotation matrix on a wire promotes into the register wire submonoid.** For +`g ∈ Concrete.reachableRotations θ` and any witness `hU` that its wire-`t` placement +`singleQubitOnWire finFunctionFinEquiv t g` is unitary, the promoted gate +`quditGate hU ∈ reachableRotationWireEvolutions n t θ`. Since `quditGate hU` is determined by its +operator (`Evolution.ext` + `quditGate_op`), it equals the member `F` supplied by the operator-form +bridge `exists_reachableRotationWireEvolution_op_eq`, hence lies in the submonoid. This is the +feed for the whole-submonoid register lift +`exists_reachableRotationGate_congr_quditPowTower_eq`: the `Evolution` a reachable-rotation wire +matrix generates is a grounded reachable-rotation gate (a `{H, S}`-circuit around the Exercise 4.41 +measurement gadget `rzThreeFifthsCircuit`) on the corresponding tower wire. -/ +theorem quditGate_singleQubitOnWire_mem_reachableRotationWireEvolutions {n : ℕ} {t : Fin (n + 1)} + {θ : ℝ} {g : Matrix (Fin 2) (Fin 2) ℂ} (hg : g ∈ Concrete.reachableRotations θ) + (hU : singleQubitOnWire finFunctionFinEquiv t g ∈ Matrix.unitaryGroup (Fin (2 ^ (n + 1))) ℂ) : + quditGate hU ∈ reachableRotationWireEvolutions n t θ := by + obtain ⟨F, hF, hFop⟩ := exists_reachableRotationWireEvolution_op_eq (t := t) hg + have hEq : quditGate hU = F := by + apply Evolution.ext + rw [quditGate_op, hFop] + rwa [hEq] + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/FourGateReversibleWire.lean b/LeanPool/AxQM/Postulates/API/FourGateReversibleWire.lean new file mode 100644 index 0000000000..edb794fb49 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/FourGateReversibleWire.lean @@ -0,0 +1,81 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftSwapEvolution +public import LeanPool.AxQM.Concrete.MultiControlledNotPermProduct + +/-! +# The reversible ≤ 2-control gates on a register wire +(N&C Exercise 4.43, four-gate bridge — register-side ingredient) + +The four-gate universality bridge (Exercise 4.43) must exhibit the *abstract* reachable gate set of +`Concrete.exists_phase_smul_mem_closure_reachableCircuits` as circuits of the grounded +`H, S, CNOT, Toffoli` gates. Its **reversible** generator family is the `≤ 2`-control +permutation gates `Concrete.IsToffoliPermGate enc G` — the `Toffoli`/`CNOT`/`NOT` gates +`permGate enc (mcNotPerm S t)` with `|S| ≤ 2`. This file supplies the *register-side* ingredient +that lets the tower re-expression (`AxQM/Core/FourGateReversibleWireTower.lean`) identify such a +matrix gate, placed on the little-endian register `qudit (2ⁿ)`, with the grounded +multiply-controlled `NOT` `Evolution.placedMcNot` — the exact reversible counterpart of the +rotation register-lift's `AxQM/Postulates/API/FourGateReachableWire.lean`. + +## What is formalised + +* `mcNotWireEvolution n S t ht` — the multiply-controlled `NOT` with controls `S` and target `t` + placed on the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`: the `quditGate` promotion + of the permutation matrix `Concrete.permGate finFunctionFinEquiv (mcNotPerm S ht)` (unitary, so + `quditGate` applies). It is the reversible analogue of `rotZWireEvolution`. +* `mcNotWireEvolution_evolvePure_quditBasis` — its **computational-basis action**: on + `|finFunctionFinEquiv f⟩` it is the classical multiply-controlled `NOT` on the bit-string, + `|finFunctionFinEquiv (mcNot S t f)⟩`. Unlike the rotation register gate (whose column is a + genuine two-term superposition), a reversible gate sends a basis state to a *basis state*, so it + is stated purely over `Evolution.evolvePure` / `quditBasis` / `Concrete.mcNot`. The instance of + `quditGate_permGate_evolvePure_quditBasis` at `σ = mcNotPerm S ht`, `enc = finFunctionFinEquiv`, + closed by `mcNotPerm_apply`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The multiply-controlled `NOT` on a register wire set.** The reversible gate with controls +`S : Finset (Fin n)` and target `t ∉ S` placed on the `2ⁿ`-level register, as a named +`Evolution (qudit (2ⁿ))`: the `quditGate` promotion of the permutation matrix +`permGate finFunctionFinEquiv (mcNotPerm S ht)` (unitary by `permGate_mem_unitaryGroup`, so +`quditGate` applies). For `|S| ≤ 2` this is the `Toffoli`/`CNOT`/`NOT` addressed to the wires +`(S, t)` — the reversible generator family of `reachableGateSet`. It is used in the tower +re-expression (`AxQM/Core/FourGateReversibleWireTower.lean`); its basis action is +`mcNotWireEvolution_evolvePure_quditBasis`. The reversible analogue of `rotZWireEvolution`. -/ +def mcNotWireEvolution (n : ℕ) (S : Finset (Fin n)) (t : Fin n) (ht : t ∉ S) : + Evolution (qudit (2 ^ n)) := + quditGate (permGate_mem_unitaryGroup finFunctionFinEquiv (mcNotPerm S ht)) + +/-- **The wire-`(S, t)` multiply-controlled `NOT` is the classical `mcNot` on the bit-string.** On +`|finFunctionFinEquiv f⟩` the register gate `mcNotWireEvolution n S t ht` produces +`|finFunctionFinEquiv (mcNot S t f)⟩`: the bit-string `f` addressing the wires has wire `t` flipped +iff every control in `S` is set. A reversible gate maps a computational basis state to a +computational basis state (no superposition), so this is stated purely over `Evolution.evolvePure` / +`quditBasis` / `Concrete.mcNot`. The instance of +`quditGate_permGate_evolvePure_quditBasis` at `σ = mcNotPerm S ht`, closed by `mcNotPerm_apply`. -/ +theorem mcNotWireEvolution_evolvePure_quditBasis (n : ℕ) (S : Finset (Fin n)) (t : Fin n) + (ht : t ∉ S) (f : Fin n → Fin 2) : + (mcNotWireEvolution n S t ht).evolvePure (quditBasis (finFunctionFinEquiv f)) + = quditBasis (finFunctionFinEquiv (mcNot S t f)) := by + have : NeZero (2 ^ n) := ⟨pow_ne_zero n (by norm_num)⟩ + rw [mcNotWireEvolution, quditGate_permGate_evolvePure_quditBasis, mcNotPerm_apply] + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Fredkin.lean b/LeanPool/AxQM/Postulates/API/Fredkin.lean new file mode 100644 index 0000000000..130f6a59bc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Fredkin.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.Swap + +/-! +# AxQM.Postulates.API — the Fredkin (controlled-`SWAP`) gate and its construction gates + +Infrastructure for Nielsen & Chuang **Exercise 4.25** (Fredkin gate construction): +the controlled-`SWAP` gate `fredkinGate` together with the two auxiliary gates its three-Toffoli +construction is built from — a reversed `CNOT` and the "middle" Toffoli (controls on qubits 1 and +3, target qubit 2). It sits above `ControlledControlledUnitary` (supplying `ccontrolledUnitary`, +`toffoliGate`, and the three-qubit extensionality bridge) and `Swap`. + +## What is formalised + +* `fredkinGate` — the **Fredkin gate** `C(SWAP)` on `qubit ⊗ (qubit ⊗ qubit)`: the single-qubit + controlled gate `controlledUnitary` applied to the two-qubit `SWAP`, i.e. it swaps qubits 2 and 3 + exactly when the control qubit 1 is `|1⟩`. This is precisely the transform of N&C eq. (4.30). +* `fredkinGate_evolvePure_ketZero_left` / `fredkinGate_evolvePure_ketOne_left` — the **defining + action** (the two diagonal blocks of the matrix 4.30): control `|0⟩` leaves the pair untouched, + `C(SWAP)(|0⟩ ⊗ ψ) = |0⟩ ⊗ ψ`; control `|1⟩` swaps the pair, `C(SWAP)(|1⟩ ⊗ |a⟩ ⊗ |b⟩) = + |1⟩ ⊗ |b⟩ ⊗ |a⟩`. +* `reversedCnotGate` — `CNOT` with the roles of the two qubits interchanged (control on the second + qubit, target on the first), realised as the swap-conjugate `SWAP · CNOT · SWAP`; its truth table + is `|a, b⟩ ↦ |a ⊕ b, b⟩` (`reversedCnotGate_evolvePure_qubitBasis`). +* `middleToffoliGate` — the doubly-controlled `X` with controls on qubits 1 and 3 and target + qubit 2, `C(reversedCNOT)`; its truth table is `|c, a, b⟩ ↦ |c, a ⊕ c·b, b⟩` + (`middleToffoliGate_evolvePure_qubitBasis`). This is the middle gate of the swap construction — a + Toffoli whose target is qubit 2 rather than qubit 3. + +## Design notes + +* **`fredkinGate = C(SWAP)` (N&C fidelity).** The Fredkin gate is the *controlled-swap*: conditioned + on the control qubit, it applies the two-qubit `SWAP` to the target pair. On the right-associated + three-qubit system `qubit ⊗ (qubit ⊗ qubit)` (control ⊗ (target₁ ⊗ target₂)) this is literally + `controlledUnitary (Evolution.swap)`, with no associator bookkeeping, and its two control branches + are exactly the identity/permutation blocks of the matrix (4.30). A value of + `Evolution (qubit ⊗ (qubit ⊗ qubit))` cannot be formed without the underlying unitarity, + inherited here from `controlledUnitary` and `Evolution.swap`. +* **Why a reversed `CNOT` and a permuted Toffoli.** The standard swap identity + `SWAP = CNOT · reversedCNOT · CNOT` (N&C §1.3.4) has its middle `CNOT` running the *opposite* + direction; controlling the whole identity on qubit 1 therefore produces two ordinary Toffolis + (`toffoliGate`, target qubit 3) around one Toffoli whose control/target roles on qubits 2, 3 are + interchanged (`middleToffoliGate`, target qubit 2). Both auxiliary gates are defined by + conjugation/controlling of gates already in the library, so they are automatically unitary + `Evolution`s, and their truth tables follow from the `controlledUnitary`/`SWAP`/`CNOT` action + lemmas one tensor factor at a time. +* **Related declarations.** The statements here use only `controlledUnitary`, `Evolution.swap`, + `cnotGate`, `evolvePure`, `⊗` and `qubitBasis`. The gates are built directly on the + controlled-gate API, alongside `cnotGate`, `toffoliGate`, and `Evolution.swap`. Exercise 4.25's + construction theorems (which are pure `Evolution` equalities) are in + [upstream `AxQM/NC/Ch4/Exercise4_25.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_25.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### The Fredkin (controlled-`SWAP`) gate -/ + +/-- **The Fredkin gate** `C(SWAP)` (Nielsen & Chuang §1.3.4, eq. 4.30): the `Evolution` on the +three-qubit system `qubit ⊗ (qubit ⊗ qubit)` that swaps the last two (target) qubits exactly when +the first (control) qubit is `|1⟩`. It is the single-qubit-controlled gate `controlledUnitary` +applied to the two-qubit `SWAP`, so it is a genuine unitary `Evolution` with no new obligation. -/ +def fredkinGate : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + controlledUnitary (Evolution.swap (S := qubit)) + +/-- **Fredkin, control `|0⟩`** (upper-left identity block of matrix 4.30): the target pair is +untouched, `C(SWAP)(|0⟩ ⊗ ψ) = |0⟩ ⊗ ψ`. -/ +theorem fredkinGate_evolvePure_ketZero_left (ψ : PureState (qubit ⊗ qubit)) : + fredkinGate.evolvePure ((qubitBasis 0) ⊗ ψ) = (qubitBasis 0) ⊗ ψ := + controlledUnitary_evolvePure_ketZero (Evolution.swap (S := qubit)) ψ + +/-- **Fredkin, control `|1⟩`** (lower-right swap block of matrix 4.30): the target pair is swapped, +`C(SWAP)(|1⟩ ⊗ |a⟩ ⊗ |b⟩) = |1⟩ ⊗ |b⟩ ⊗ |a⟩`. -/ +theorem fredkinGate_evolvePure_ketOne_left (a b : Fin 2) : + fredkinGate.evolvePure ((qubitBasis 1) ⊗ ((qubitBasis a) ⊗ (qubitBasis b))) + = (qubitBasis 1) ⊗ ((qubitBasis b) ⊗ (qubitBasis a)) := by + rw [fredkinGate, controlledUnitary_evolvePure_ketOne, Evolution.swap_evolvePure_tmul] + +/-! ### The reversed `CNOT` and the middle Toffoli of the swap construction -/ + +/-- **The reversed `CNOT`**: the controlled-`NOT` with control on the *second* qubit and target on +the *first*, obtained by conjugating `cnotGate` with the factor swap, `reversedCNOT = SWAP · CNOT · +SWAP`. Its truth table is `|a, b⟩ ↦ |a ⊕ b, b⟩` (`reversedCnotGate_evolvePure_qubitBasis`). -/ +def reversedCnotGate : Evolution (qubit ⊗ qubit) := + (Evolution.swap (S := qubit)).comp (cnotGate.comp (Evolution.swap (S := qubit))) + +/-- **The reversed-`CNOT` truth table:** `reversedCNOT|a, b⟩ = |a ⊕ b, b⟩` (`a + b` in `Fin 2`) — +the second qubit is the control (unchanged) and the first qubit is the target. Computed from +`SWAP · CNOT · SWAP` factor by factor. -/ +theorem reversedCnotGate_evolvePure_qubitBasis (a b : Fin 2) : + reversedCnotGate.evolvePure ((qubitBasis a) ⊗ (qubitBasis b)) + = (qubitBasis (a + b)) ⊗ (qubitBasis b) := by + rw [reversedCnotGate, Evolution.evolvePure_comp, Evolution.evolvePure_comp, + Evolution.swap_evolvePure_tmul, cnotGate_evolvePure_qubitBasis, Evolution.swap_evolvePure_tmul] + +/-- **The middle Toffoli** of the Fredkin swap construction: the doubly-controlled `X` with controls +on qubits 1 and 3 and target qubit 2, realised as `C(reversedCNOT)`. It is the middle of the three +Toffoli gates, differing from `toffoliGate` only in that its target is qubit 2 rather than qubit 3. +Its truth table is `|c, a, b⟩ ↦ |c, a ⊕ c·b, b⟩` (`middleToffoliGate_evolvePure_qubitBasis`). -/ +def middleToffoliGate : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + controlledUnitary reversedCnotGate + +/-- **The middle-Toffoli truth table:** `middleToffoli|c, a, b⟩ = |c, a ⊕ c·b, b⟩` — controls on +qubits 1 (`c`) and 3 (`b`), target qubit 2 (`a`), which is flipped exactly when both controls are +`1`. -/ +theorem middleToffoliGate_evolvePure_qubitBasis (c a b : Fin 2) : + middleToffoliGate.evolvePure ((qubitBasis c) ⊗ ((qubitBasis a) ⊗ (qubitBasis b))) + = (qubitBasis c) ⊗ ((qubitBasis (a + c * b)) ⊗ (qubitBasis b)) := by + rw [middleToffoliGate] + fin_cases c <;> + simp only [Fin.mk_zero, Fin.mk_one, controlledUnitary_evolvePure_ketZero, + controlledUnitary_evolvePure_ketOne, reversedCnotGate_evolvePure_qubitBasis, zero_mul, + one_mul, add_zero] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/GateCommute.lean b/LeanPool/AxQM/Postulates/API/GateCommute.lean new file mode 100644 index 0000000000..8be66f37a4 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/GateCommute.lean @@ -0,0 +1,87 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary + +/-! +# AxQM.Postulates.API — commuting gates on disjoint factors + +Two reusable gate-algebra facts about when gates on a composite system **commute**, both instances +of the physical principle *gates acting on disjoint sets of wires commute*. They underpin any +circuit verification where a gate has to be slid past a block of gates that touch other qubits (for +example, moving a `Hadamard` on the target wire past the phase/`CNOT` block on the control wires in +Nielsen & Chuang's Figure 4.9, [upstream `AxQM/NC/Ch4/Exercise4_24.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_24.lean)). + +## Main results + +* `Evolution.onLeft_comm_onRight` — a left-factor gate `g ⊗ 1` commutes with a right-factor gate + `1 ⊗ h`: `(g.onLeft T) · (h.onRight S) = (h.onRight S) · (g.onLeft T)`. Both products equal the + bare tensor `g ⊗ h`, so they agree; this is the base case of "disjoint factors commute". +* `controlledUnitary_comm_onRight` — a controlled gate `C(U)` commutes with a gate `1 ⊗ Z` on the + *whole* target factor, provided `U` and `Z` commute there: from `U · Z = Z · U` on `S`, + `C(U) · (Z.onRight qubit) = (Z.onRight qubit) · C(U)`. The `|0⟩` branch is `1 ⊗ Z` on both sides; + the `|1⟩` branch needs `U · Z = Z · U` (hence the hypothesis). + +Compare the gate-algebra lemmas `controlledUnitary_comp` and `Evolution.onRight_comp`. The proofs +go through the underlying `TensorProduct.mapL` operators (`change` at the raw tensor head, as in +`controlledUnitary_comp`) and run the block-diagonal `mapL` composition algebra. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Gates on disjoint factors commute (base case).** A gate on the left factor, `g ⊗ 1` +(`g.onLeft T`), and a gate on the right factor, `1 ⊗ h` (`h.onRight S`), commute: +`(g.onLeft T).comp (h.onRight S) = (h.onRight S).comp (g.onLeft T)`. Both composites equal the +product unitary `g ⊗ h` (`(g ⊗ 1)(1 ⊗ h) = g ⊗ h = (1 ⊗ h)(g ⊗ 1)`), proved by cracking to the raw +`TensorProduct.mapL` operators and applying `mapL_comp` with `1 ∘ f = f ∘ 1 = f`. -/ +theorem Evolution.onLeft_comm_onRight {S T : QSystem} (g : Evolution S) (h : Evolution T) : + (g.onLeft T).comp (h.onRight S) = (h.onRight S).comp (g.onLeft T) := by + apply Evolution.ext + change (TensorProduct.mapL g.op (1 : T.space →L[ℂ] T.space)).comp + (TensorProduct.mapL (1 : S.space →L[ℂ] S.space) h.op) + = (TensorProduct.mapL (1 : S.space →L[ℂ] S.space) h.op).comp + (TensorProduct.mapL g.op (1 : T.space →L[ℂ] T.space)) + rw [← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id, ContinuousLinearMap.id_comp] + +/-- **A controlled gate commutes with a gate on the whole target factor, when the targets commute.** +If `U` and `Z` commute on `S` (`U.comp Z = Z.comp U`), then the controlled-`U` gate `C(U)` commutes +with `1 ⊗ Z` (`Z.onRight qubit`): +`(controlledUnitary U).comp (Z.onRight qubit) = (Z.onRight qubit).comp (controlledUnitary U)`. +Both are block-diagonal: `C(U) = |0⟩⟨0| ⊗ 1 + |1⟩⟨1| ⊗ U` and `1 ⊗ Z`, so their product is +`|0⟩⟨0| ⊗ Z + |1⟩⟨1| ⊗ (U ∘ Z)` one way and `|0⟩⟨0| ⊗ Z + |1⟩⟨1| ⊗ (Z ∘ U)` the other; the +hypothesis `U ∘ Z = Z ∘ U` makes them equal. Proved by cracking to operators at the raw tensor head +and running the `TensorProduct.mapL` composition algebra (as in `controlledUnitary_comp`). -/ +theorem controlledUnitary_comm_onRight {S : QSystem} (U Z : Evolution S) + (h : U.comp Z = Z.comp U) : + (controlledUnitary U).comp (Z.onRight qubit) + = (Z.onRight qubit).comp (controlledUnitary U) := by + have hUZ : U.op.comp Z.op = Z.op.comp U.op := by + rw [← Evolution.comp_op, h, Evolution.comp_op] + apply Evolution.ext + set p0 := InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec + set p1 := InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec + change (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 U.op).comp + (TensorProduct.mapL 1 Z.op) + = (TensorProduct.mapL 1 Z.op).comp + (TensorProduct.mapL p0 (1 : S.space →L[ℂ] S.space) + TensorProduct.mapL p1 U.op) + rw [ContinuousLinearMap.add_comp, ContinuousLinearMap.comp_add, + ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp, + ← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id, ContinuousLinearMap.id_comp, + hUZ] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/GeneralMeasurementEnvironment.lean b/LeanPool/AxQM/Postulates/API/GeneralMeasurementEnvironment.lean new file mode 100644 index 0000000000..2fbbac9913 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/GeneralMeasurementEnvironment.lean @@ -0,0 +1,215 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasurementOperation +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# AxQM — reduced operation of a general measurement on system + environment (N&C Ex 8.7) + +The reduced operation behind **Nielsen–Chuang Exercise 8.7**. In §8.2.4 a principal system +`Q` (state `ρ`) is adjoined to an environment `E` (state `σ`), the pair interacts via a unitary `U`, +and a measurement is performed on the *combined* system `Q ⊗ E`. Where N&C's worked derivation +(eqs. (8.29)–(8.35)) uses a **projective** measurement `{Pₘ}`, Exercise 8.7 replaces it with a +**general** measurement `{Mₘ}` (`∑ₘ Mₘ† Mₘ = 1`, our `Measurement`) and asks for + +* the **quantum operation** `Eₘ` induced on the principal system, in operator-sum form; and +* that the outcome **probabilities** are `tr[Eₘ(ρ)]`. + +This file introduces the induced operation, settles the probability claim, and gives the +operator-sum representation (both of Exercise 8.7's asks). + +## The induced operation + +Tracing out the environment after the interaction and the (unnormalized) measurement of outcome `m` +gives the map on the principal system + + `Eₘ(ρ) = tr_E( Mₘ (U (ρ ⊗ σ) U†) Mₘ† )` (N&C eq. (8.32), generalized from `Pₘ` to `Mₘ`), + +whose normalization `Eₘ(ρ)/tr[Eₘ(ρ)]` is the final state of `Q` alone and whose trace `tr[Eₘ(ρ)]` +is the probability of outcome `m`. Here the inner conjugation is the Exercise 8.2 operation element +`Measurement.opElement M (U.evolve (ρ ⊗ σ)) m = Mₘ (U (ρ ⊗ σ) U†) Mₘ†` of the *lifted* measurement, +and `tr_E` is the partial trace over the right (environment) factor — exactly the partial +trace used by `State.reducedLeft`. + +## Contents + +* `generalMeasurementEnvOp` — the induced operation `Eₘ(ρ) = tr_E(Mₘ (U (ρ ⊗ σ) U†) Mₘ†)`, as a + `Q →L[ℂ] Q`. +* `bornProb_eq_trace_generalMeasurementEnvOp` — **Exercise 8.7 (probabilities):** the outcome + probability equals the trace of the induced operation, `(p(m) : ℂ) = tr[Eₘ(ρ)]`. Stated as the + complex equality (so the trace is real and equals the Born probability), for the general + measurement `M` on the post-interaction joint state `U.evolve (ρ ⊗ σ)`. +* `generalMeasurementEnvKrausOp` — the operation elements `Eⱼₖ = ⟨eₖ| Mₘ U |wⱼ⟩` (N&C's + `Eⱼₖ = √qⱼ ⟨eₖ| Mₘ U |j⟩` of Eq. (8.35), the weights absorbed into `wⱼ`). +* `generalMeasurementEnvOp_eq_sum_krausOp` — **Exercise 8.7 (operator-sum representation):** for an + ensemble decomposition `σ = ∑ⱼ |wⱼ⟩⟨wⱼ|`, `Eₘ(ρ) = ∑ⱼ ∑ₖ Eⱼₖ ρ Eⱼₖ†` (N&C Eqs. (8.33)–(8.35)). +* `generalMeasurementEnvOp_exists_operatorSum` — the existence form: `Eₘ` admits *some* operator-sum + representation `Eₘ(ρ) = ∑ᵢ Fᵢ ρ Fᵢ†` (the decomposition supplied by positivity of `σ.op`). + +The statement of Exercise 8.7 (the induced outcome distribution and the normalized final state) +is in [upstream `AxQM/NC/Ch8/Exercise8_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_7.lean). + +## Design notes + +* **Generality.** `Q`, `E`, `ρ`, `σ`, `U`, `M` are all arbitrary — an arbitrary + environment state `σ` (not a pure/standard state), an arbitrary unitary interaction, and an + arbitrary *general* measurement (`Measurement`, whose completeness `∑ₘ Mₘ† Mₘ = 1` is precisely + N&C's "measurement operators `{Mₘ}`"). Replacing N&C's projectors `Pₘ` by general `Mₘ` is exactly + the exercise; nothing is specialized to the projective case. `Eₘ(ρ)` is the *unnormalized* reduced + operation, matching N&C's `Eₘ(ρ) ≡ tr_E(Pₘ U(ρ ⊗ σ)U† Pₘ)` with `Pₘ ↦ Mₘ`, so its trace is + literally the outcome probability (not a surrogate). +* **Why the operation is defined via `opElement`.** The middle factor `Mₘ (U (ρ ⊗ σ) U†) Mₘ†` is the + Exercise 8.2 operation element of the lifted general measurement on the evolved joint state, so + `generalMeasurementEnvOp` is the partial trace of that already-grounded object. This makes the + probability proof a two-step bridge: the trace of a partial trace is the full trace + (`LinearMap.trace_partialTraceRight`), and the full trace of `Mₘ τ Mₘ†` is the Born probability + (`Measurement.bornProb_eq_trace_opElement`, Exercise 8.2). +* **Proof shape.** `bornProb_eq_trace_generalMeasurementEnvOp` rewrites the Born probability of the + lifted measurement on `U.evolve (ρ ⊗ σ)` to `tr((Q ⊗ E)) (Mₘ τ Mₘ†)` (Exercise 8.2), unfolds + `generalMeasurementEnvOp`, and collapses `tr_Q (tr_E(·)) = tr_{Q ⊗ E}(·)` via + `LinearMap.trace_partialTraceRight`; the two traces agree definitionally because + `(Q ⊗ E).space` is `Q.space ⊗[ℂ] E.space`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {Q E : QSystem} + +/-- **The induced quantum operation of a general measurement on system + environment** (Nielsen– +Chuang Exercise 8.7, eq. (8.32) with the projectors `Pₘ` replaced by general measurement operators +`Mₘ`): + + `Eₘ(ρ) = tr_E( Mₘ (U (ρ ⊗ σ) U†) Mₘ† )`, + +the map on the principal system `Q` obtained by preparing the joint state `ρ ⊗ σ`, applying the +system–environment interaction `U`, measuring the combined system with outcome `m`, and tracing out +the environment `E`. The inner conjugation is the Exercise 8.2 operation element +`Measurement.opElement M (U.evolve (ρ ⊗ σ)) m = Mₘ (U (ρ ⊗ σ) U†) Mₘ†`; `tr_E` is the partial trace +over the right (environment) factor. Its trace is the outcome probability +(`bornProb_eq_trace_generalMeasurementEnvOp`) and its normalization `Eₘ(ρ)/tr[Eₘ(ρ)]` is the final +state of `Q` alone. Defined as the partial trace of a raw operator. -/ +def generalMeasurementEnvOp (M : Measurement ι (Q ⊗ E)) (U : Evolution (Q ⊗ E)) + (σ : State E) (ρ : State Q) (m : ι) : Q →L[ℂ] Q := + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ E.space) + ((M.opElement (U.evolve (ρ ⊗ σ)) m).toLinearMap + : Q.space ⊗[ℂ] E.space →ₗ[ℂ] Q.space ⊗[ℂ] E.space)).toContinuousLinearMap + +/-- **Nielsen & Chuang, Exercise 8.7 (probabilities).** The probability of outcome `m` — the Born +probability of the general measurement `M` on the post-interaction joint state `U.evolve (ρ ⊗ σ)` — +equals the trace of the induced operation: + + `(p(m) : ℂ) = tr[Eₘ(ρ)]`. + +Stated as the complex equality (which records both that `tr[Eₘ(ρ)]` is real and that it equals the +Born probability), for an arbitrary system, environment, state, environment state, interaction, and +outcome. Proof: `Measurement.bornProb_eq_trace_opElement` (Exercise 8.2) rewrites `(p(m) : ℂ)` to +the full trace `tr_{Q ⊗ E}(Mₘ (U (ρ ⊗ σ) U†) Mₘ†)`, and `LinearMap.trace_partialTraceRight` +collapses `tr[Eₘ(ρ)] = tr_Q(tr_E(·))` to that same full trace (the two spaces agree +definitionally). -/ +theorem bornProb_eq_trace_generalMeasurementEnvOp (M : Measurement ι (Q ⊗ E)) + (U : Evolution (Q ⊗ E)) (σ : State E) (ρ : State Q) (m : ι) : + (M.bornProb (U.evolve (ρ ⊗ σ)) m : ℂ) + = LinearMap.trace ℂ Q.space (generalMeasurementEnvOp M U σ ρ m : Q.space →ₗ[ℂ] Q.space) := by + rw [Measurement.bornProb_eq_trace_opElement, generalMeasurementEnvOp, + LinearMap.coe_toContinuousLinearMap] + erw [LinearMap.trace_partialTraceRight] + rfl + +/-- **The operation elements of Exercise 8.7's operator-sum representation.** Given an ensemble +decomposition `σ = ∑ⱼ |wⱼ⟩⟨wⱼ|` of the environment state (the ensemble weights `√qⱼ` absorbed into +the vectors `wⱼ`, so `wⱼ = √qⱼ |j⟩` in N&C's notation) and the fixed environment orthonormal basis +`{eₖ}` (`stdOrthonormalBasis ℂ E.space`), the `(j, k)`-th operation element is + + `Eⱼₖ = ⟨eₖ| Mₘ U |wⱼ⟩`, + +Nielsen–Chuang's `Eⱼₖ = √qⱼ ⟨eₖ| Mₘ U |j⟩` of Eq. (8.35), generalized from the projectors `Pₘ` to +the general measurement operators `Mₘ`. Concretely it is the `k`-th Kraus operator +(`LinearMap.krausOp`) of the dilation `(Mₘ U) ∘ (· ⊗ wⱼ) : Q.space →ₗ Q.space ⊗ E.space`, i.e. apply +`Mₘ U` to the input tensored with `wⱼ` and contract the environment factor against `eₖ`. +A raw operator built from the measurement and the evolution. -/ +def generalMeasurementEnvKrausOp (M : Measurement ι (Q ⊗ E)) (U : Evolution (Q ⊗ E)) + {κ : Type*} (w : κ → E.space) (m : ι) (j : κ) + (k : Fin (Module.finrank ℂ E.space)) : Q.space →ₗ[ℂ] Q.space := + LinearMap.krausOp (stdOrthonormalBasis ℂ E.space) + (((M.op m).comp U.op).toLinearMap ∘ₗ LinearMap.tmulRightVec (w j)) k + +/-- **Nielsen & Chuang, Exercise 8.7 (operator-sum representation).** Given an ensemble +decomposition `σ = ∑ⱼ |wⱼ⟩⟨wⱼ|` of the environment state (hypothesis `hσ`; N&C's `σ = ∑ⱼ qⱼ |j⟩⟨j|` +with the weights absorbed, `wⱼ = √qⱼ |j⟩`), the induced operation `Eₘ` has the operator-sum +representation + + `Eₘ(ρ) = ∑ⱼ ∑ₖ Eⱼₖ ρ Eⱼₖ†`, `Eⱼₖ = ⟨eₖ| Mₘ U |wⱼ⟩` (N&C Eqs. (8.33)–(8.35), `Pₘ ↦ Mₘ`), + +the operation elements being `generalMeasurementEnvKrausOp`. This is N&C's first ask; combined with +`bornProb_eq_trace_generalMeasurementEnvOp` (the trace identity `p(m) = tr[Eₘ(ρ)]`, the second ask) +it settles Exercise 8.7 for the given decomposition. Stated at the `Q.space →ₗ[ℂ] Q.space` level +(the coercion of the operation, applied to the density operator `ρ.op`). + +Proof: `Eₘ(ρ) = tr_E(W (ρ ⊗ σ) W†)` with `W = Mₘ U`; substitute the decomposition of `σ` and apply +the general environment-model lemma +`LinearMap.partialTraceRight_conj_map_sum_rankOne_eq_sum_krausOp` +(itself the pure-state case `partialTraceRight_conj_map_rankOne_eq_sum_krausOp` distributed over the +rank-one terms). The bridge rewrites the Exercise 8.2 operation element `Mₘ (U (ρ ⊗ σ) U†) Mₘ†` into +the conjugation form `W (ρ ⊗ σ) W†` via `opElement`, `evolve`, and `State.tmul_op`. -/ +theorem generalMeasurementEnvOp_eq_sum_krausOp (M : Measurement ι (Q ⊗ E)) (U : Evolution (Q ⊗ E)) + (σ : State E) (ρ : State Q) (m : ι) {κ : Type*} [Fintype κ] (w : κ → E.space) + (hσ : (σ.op : E.space →ₗ[ℂ] E.space) + = ∑ j, ((InnerProductSpace.rankOne ℂ (w j) (w j)).toLinearMap : E.space →ₗ[ℂ] E.space)) : + (generalMeasurementEnvOp M U σ ρ m : Q.space →ₗ[ℂ] Q.space) + = ∑ j, ∑ k, generalMeasurementEnvKrausOp M U w m j k ∘ₗ (ρ.op : Q.space →ₗ[ℂ] Q.space) + ∘ₗ LinearMap.adjoint (generalMeasurementEnvKrausOp M U w m j k) := by + have hop : M.opElement (U.evolve (ρ ⊗ σ)) m + = ((M.op m).comp U.op).comp ((ρ ⊗ σ).op.comp + (ContinuousLinearMap.adjoint ((M.op m).comp U.op))) := by + simp only [Measurement.opElement_eq_postOp, ContinuousLinearMap.postOp, Evolution.evolve_op, + ContinuousLinearMap.adjoint_comp, ContinuousLinearMap.comp_assoc] + have hbridge : (M.opElement (U.evolve (ρ ⊗ σ)) m).toLinearMap + = ((M.op m).comp U.op).toLinearMap ∘ₗ TensorProduct.map ρ.op σ.op + ∘ₗ LinearMap.adjoint ((M.op m).comp U.op).toLinearMap := by + rw [hop, ContinuousLinearMap.toLinearMap_comp ((M.op m).comp U.op), + ContinuousLinearMap.toLinearMap_comp (ρ ⊗ σ).op, + State.tmul_op, TensorProduct.toLinearMap_mapL, ContinuousLinearMap.adjoint_toLinearMap] + rfl + rw [generalMeasurementEnvOp, LinearMap.coe_toContinuousLinearMap, hbridge, hσ] + exact LinearMap.partialTraceRight_conj_map_sum_rankOne_eq_sum_krausOp _ _ w _ + +/-- **Nielsen & Chuang, Exercise 8.7 (existence of an operator-sum representation).** The induced +operation `Eₘ` of a general measurement on system + environment *admits* an operator-sum +representation `Eₘ(ρ) = ∑ᵢ Fᵢ ρ Fᵢ†` on the principal system alone — the direct reading of N&C's +"find operator-sum representations for the corresponding quantum operations `Eₘ`". No ensemble +decomposition of `σ` need be supplied: it is produced from the positivity of the density operator +`σ.op` (`ContinuousLinearMap.isPositive_iff_eq_sum_rankOne`), showing the hypothesis of +`generalMeasurementEnvOp_eq_sum_krausOp` is always dischargeable, so the representation is never +vacuous. The operation elements are `generalMeasurementEnvKrausOp` for the chosen decomposition, +reindexed from the double sum `∑ⱼ ∑ₖ` to a single sum over the product index. -/ +theorem generalMeasurementEnvOp_exists_operatorSum (M : Measurement ι (Q ⊗ E)) + (U : Evolution (Q ⊗ E)) (σ : State E) (ρ : State Q) (m : ι) : + ∃ (κ : Type) (_ : Fintype κ) (F : κ → Q.space →ₗ[ℂ] Q.space), + (generalMeasurementEnvOp M U σ ρ m : Q.space →ₗ[ℂ] Q.space) + = ∑ i, F i ∘ₗ (ρ.op : Q.space →ₗ[ℂ] Q.space) ∘ₗ LinearMap.adjoint (F i) := by + obtain ⟨n, u, hu⟩ := ContinuousLinearMap.isPositive_iff_eq_sum_rankOne.mp σ.isPositive_op + have hσ : (σ.op : E.space →ₗ[ℂ] E.space) + = ∑ j, ((InnerProductSpace.rankOne ℂ (u j) (u j)).toLinearMap : E.space →ₗ[ℂ] E.space) := by + rw [hu] + simp only [ContinuousLinearMap.toLinearMap_sum] + exact ⟨Fin n × Fin (Module.finrank ℂ E.space), inferInstance, + fun p => generalMeasurementEnvKrausOp M U u m p.1 p.2, by + rw [generalMeasurementEnvOp_eq_sum_krausOp M U σ ρ m u hσ, Fintype.sum_prod_type]⟩ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/GeneralizedDepolarizingChannel.lean b/LeanPool/AxQM/Postulates/API/GeneralizedDepolarizingChannel.lean new file mode 100644 index 0000000000..36a466cd8c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/GeneralizedDepolarizingChannel.lean @@ -0,0 +1,217 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuantumChannel +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DepolarizingTwirl + +/-! +# AxQM.Postulates.API — the generalized depolarizing channel and its operator sum + +The **generalized depolarizing channel** on a `d`-dimensional quantum system (Nielsen & Chuang, +§8.3.4, eq. 8.106): with probability `p` the state is replaced by the maximally mixed state `I/d`, +and left untouched otherwise, +`E(ρ) = p (I/d) + (1 - p) ρ`. +This file gives its **operator-sum (Kraus) representation** — the object Nielsen & Chuang, +Exercise 8.19 asks for — reusing the completely-depolarizing unitary `1`-design of `ToMathlib`. + +* `AxQM.genDepolarizingChannel` — the channel `ρ ↦ (1 - p) ρ + p (I/d)` as a state-map on + `qudit d`, a genuine `State` (a convex combination of `ρ` and `maximallyMixedState`, for + `0 ≤ p ≤ 1`). +* `AxQM.genDepolarizingKraus` — the **operation elements** `{Eₖ}`, indexed by + `Option ((Fin d → Bool) × Equiv.Perm (Fin d))`: the identity `√(1-p) · I`, and one + `√(p/2ᵈd!) · Uⱼ` per depolarizing-design unitary `Uⱼ` (`OrthonormalBasis.depolarizingUnitary`). +* `AxQM.genDepolarizingChannel_op_eq_krausSum` — **the operator-sum representation** + `E(ρ) = ∑ₖ Eₖ ρ Eₖ†`: the channel acts as the Kraus sum of `genDepolarizingKraus`. The heart of + the exercise; proved by the depolarizing `1`-design twirl + `∑ⱼ (2ᵈd!)⁻¹ Uⱼ A Uⱼ† = (tr A / d) I` + (`OrthonormalBasis.sum_conjStarAlgEquiv_depolarizingUnitary`). +* `AxQM.genDepolarizingKraus_completeness` — **the completeness relation** + `∑ₖ Eₖ† Eₖ = I` (each `Uⱼ` unitary, and `(1-p) + 2ᵈd! · p/2ᵈd! = 1`), certifying `E` is trace + preserving. + +Together these two are the operator-sum representation. The statement that these form a genuine +CPTP quantum operation (`IsChannel`) is in [upstream `AxQM/NC/Ch8/Exercise8_19.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_19.lean). + +## Design notes + +* **Why the depolarizing `1`-design, not matrix units.** The completely-depolarizing part + `ρ ↦ (tr ρ) I/d` needs an operator basis whose conjugation-average is `(tr ·/d) I`. `ToMathlib` + supplies exactly this as a *unitary* `1`-design (the `2ᵈ d!` sign-flip×permutation unitaries + `OrthonormalBasis.depolarizingUnitary`, with twirl + `sum_conjStarAlgEquiv_depolarizingUnitary`), so the operation elements are `√pₖ Uₖ` and the + representation is manifestly *random-unitary* — the physically natural reading of "replace with + `I/d` with probability `p`", and the `d`-dimensional generalization of the qubit Pauli twirl + `I/2 = (ρ + XρX + YρY + ZρZ)/4` (N&C eq. 8.101, Exercise 8.17) used for the qubit case. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {d : ℕ} + +/-- The **computational orthonormal basis** `{|i⟩}` of `qudit d` (the standard basis of +`EuclideanSpace ℂ (Fin d)`), packaged at the qudit's state space so that operators on it have type +`(qudit d).space →L[ℂ] (qudit d).space`. -/ +def quditOrthonormalBasis (d : ℕ) : OrthonormalBasis (Fin d) ℂ (qudit d).space := + EuclideanSpace.basisFun (Fin d) ℂ + +/-- The `j`-th **depolarizing-design unitary** of the computational basis of `qudit d`, as a +(unitary) operator on the qudit space. Ranging over `j : (Fin d → Bool) × Equiv.Perm (Fin d)` these +are the `2ᵈ d!` sign-flip×permutation unitaries whose uniform conjugation-average is the completely +depolarizing map (`OrthonormalBasis.sum_conjStarAlgEquiv_depolarizingUnitary`). -/ +def depolarizingOp (d : ℕ) (j : (Fin d → Bool) × Equiv.Perm (Fin d)) : + (qudit d).space →L[ℂ] (qudit d).space := + ((quditOrthonormalBasis d).depolarizingUnitary j).toContinuousLinearEquiv + +/-- The depolarizing-design operators are unitary: `Uⱼ† Uⱼ = I`. -/ +theorem depolarizingOp_adjoint_comp_self (j : (Fin d → Bool) × Equiv.Perm (Fin d)) : + (adjoint (depolarizingOp d j)).comp (depolarizingOp d j) = 1 := by + rw [depolarizingOp, LinearIsometryEquiv.adjoint_eq_symm] + ext x + simp only [ContinuousLinearMap.coe_comp, Function.comp_apply, ContinuousLinearEquiv.coe_coe, + ContinuousLinearMap.one_def, ContinuousLinearMap.id_apply, + LinearIsometryEquiv.coe_toContinuousLinearEquiv, LinearIsometryEquiv.symm_apply_apply] + +/-- **The generalized depolarizing channel** `E(ρ) = (1 - p) ρ + p (I/d)` on `qudit d` +(Nielsen & Chuang eq. 8.106): with probability `p` the state is replaced by the maximally mixed +state `I/d = maximallyMixedState`, and left untouched otherwise. For `0 ≤ p ≤ 1` this is a genuine +`State`, being the convex combination of the states `ρ` and `I/d`. -/ +def genDepolarizingChannel (d : ℕ) [NeZero d] (p : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ρ : State (qudit d)) : State (qudit d) where + op := ((1 - p : ℝ) : ℂ) • ρ.op + ((p : ℝ) : ℂ) • (maximallyMixedState (qudit d)).op + isDensity := + ContinuousLinearMap.IsDensityOp.convex_combination ρ.isDensity + (maximallyMixedState (qudit d)).isDensity + (by exact_mod_cast (by linarith : (0:ℝ) ≤ 1 - p)) (by exact_mod_cast hp0) + (by push_cast; ring) + +/-- The operator of the generalized depolarizing channel is `(1-p) ρ + p (I/d)`. -/ +@[simp] +theorem genDepolarizingChannel_op [NeZero d] (p : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ρ : State (qudit d)) : + (genDepolarizingChannel d p hp0 hp1 ρ).op + = ((1 - p : ℝ) : ℂ) • ρ.op + ((p : ℝ) : ℂ) • (maximallyMixedState (qudit d)).op := rfl + +/-- The **operation elements** of the generalized depolarizing channel, indexed by +`Option ((Fin d → Bool) × Equiv.Perm (Fin d))`: + +* `none ↦ √(1-p) · I` — the "leave `ρ` untouched" branch; +* `some j ↦ √(p / 2ᵈd!) · Uⱼ` — one element per depolarizing-design unitary `Uⱼ` (`depolarizingOp`). + +Since the `Uⱼ` average by conjugation to the completely-depolarizing map, `∑ₖ Eₖ ρ Eₖ†` reproduces +`E(ρ)` (`genDepolarizingChannel_op_eq_krausSum`), and `∑ₖ Eₖ† Eₖ = I` +(`genDepolarizingKraus_completeness`). -/ +def genDepolarizingKraus (d : ℕ) (p : ℝ) : + Option ((Fin d → Bool) × Equiv.Perm (Fin d)) → + ((qudit d).space →L[ℂ] (qudit d).space) + | none => (Real.sqrt (1 - p) : ℂ) • 1 + | some j => (Real.sqrt (p / (2 ^ d * d.factorial : ℝ)) : ℂ) • depolarizingOp d j + +/-- The number of depolarizing-design unitaries is `2ᵈ d!`. -/ +theorem card_depolarizing_index : + Fintype.card ((Fin d → Bool) × Equiv.Perm (Fin d)) = 2 ^ d * d.factorial := by + rw [Fintype.card_prod, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, Fintype.card_perm, + Fintype.card_fin] + +/-- **The completeness relation** `∑ₖ Eₖ† Eₖ = I` for the generalized-depolarizing operation +elements (Nielsen & Chuang's trace condition, certifying `E` is trace preserving). Each `Uⱼ` is +unitary (`Uⱼ† Uⱼ = I`), so the sum is `(1-p) I + 2ᵈd! · (p/2ᵈd!) I = (1-p) I + p I = I`. -/ +theorem genDepolarizingKraus_completeness (p : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + ∑ k, (adjoint (genDepolarizingKraus d p k)).comp (genDepolarizingKraus d p k) = 1 := by + have hn : (0 : ℝ) < 2 ^ d * d.factorial := by positivity + rw [Fintype.sum_option] + -- the `none` (identity) branch contributes `(1-p) • I` + have hnone : (adjoint (genDepolarizingKraus d p none)).comp (genDepolarizingKraus d p none) + = ((1 - p : ℝ) : ℂ) • 1 := by + simp only [genDepolarizingKraus] + rw [← star_eq_adjoint, star_smul, star_one, smul_comp, comp_smul, smul_smul, + ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id] + congr 1 + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, + Real.mul_self_sqrt (by linarith)] + -- each `some j` branch contributes `(p / 2ᵈd!) • I` + have hsome : ∀ j, (adjoint (genDepolarizingKraus d p (some j))).comp + (genDepolarizingKraus d p (some j)) = ((p / (2 ^ d * d.factorial : ℝ) : ℝ) : ℂ) • 1 := by + intro j + simp only [genDepolarizingKraus] + rw [← star_eq_adjoint, star_smul, star_eq_adjoint, smul_comp, comp_smul, smul_smul, + depolarizingOp_adjoint_comp_self] + congr 1 + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, + Real.mul_self_sqrt (by positivity)] + rw [hnone, Finset.sum_congr rfl (fun j _ => hsome j), Finset.sum_const, Finset.card_univ, + card_depolarizing_index, ← Nat.cast_smul_eq_nsmul ℂ, smul_smul, ← add_smul] + rw [show ((2 ^ d * d.factorial : ℕ) : ℂ) * ((p / (2 ^ d * d.factorial : ℝ) : ℝ) : ℂ) + = ((p : ℝ) : ℂ) by push_cast; field_simp] + rw [show ((1 - p : ℝ) : ℂ) + ((p : ℝ) : ℂ) = 1 by push_cast; ring, one_smul] + +/-- **The operator-sum (Kraus) representation of the generalized depolarizing channel** +(Nielsen & Chuang, Exercise 8.19): the channel acts as the operator sum of its operation elements, +`E(ρ) = ∑ₖ Eₖ ρ Eₖ†`. The identity element contributes `(1-p) ρ`; the `2ᵈd!` depolarizing-design +elements average, by the twirl `∑ⱼ (2ᵈd!)⁻¹ Uⱼ ρ Uⱼ† = (tr ρ / d) I`, to `p (I/d)` (using +`tr ρ = 1`). Together with `genDepolarizingKraus_completeness` (`∑ₖ Eₖ† Eₖ = I`) this is the +operator-sum representation the exercise asks for. -/ +theorem genDepolarizingChannel_op_eq_krausSum [NeZero d] (p : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ρ : State (qudit d)) : + (genDepolarizingChannel d p hp0 hp1 ρ).op = krausSumₗ (genDepolarizingKraus d p) ρ.op := by + have hn : (0 : ℝ) < 2 ^ d * d.factorial := by positivity + rw [genDepolarizingChannel_op, ContinuousLinearMap.krausSumₗ_apply, Fintype.sum_option] + -- the `none` (identity) branch contributes `(1-p) • ρ.op` + have hnone : (genDepolarizingKraus d p none).comp (ρ.op.comp + (adjoint (genDepolarizingKraus d p none))) = ((1 - p : ℝ) : ℂ) • ρ.op := by + simp only [genDepolarizingKraus] + rw [← star_eq_adjoint, star_smul, star_one, smul_comp, comp_smul, comp_smul, smul_smul, + ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, ContinuousLinearMap.comp_id] + congr 1 + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, + Real.mul_self_sqrt (by linarith)] + -- each `some j` branch is `(p/2ᵈd!) · conjugation of ρ by Uⱼ` + have hterm : ∀ j, (genDepolarizingKraus d p (some j)).comp + (ρ.op.comp (adjoint (genDepolarizingKraus d p (some j)))) + = ((p / (2 ^ d * d.factorial : ℝ) : ℝ) : ℂ) + • ((quditOrthonormalBasis d).depolarizingUnitary j).conjStarAlgEquiv ρ.op := by + intro j + simp only [genDepolarizingKraus, depolarizingOp, LinearIsometryEquiv.conjStarAlgEquiv_apply] + rw [← star_eq_adjoint, star_smul, star_eq_adjoint, LinearIsometryEquiv.adjoint_eq_symm, + smul_comp, comp_smul, comp_smul, smul_smul] + congr 1 + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, + Real.mul_self_sqrt (by positivity)] + -- the twirl: the `some`-sum averages to `p • (I/d)` + have htwirl : ∑ j, (genDepolarizingKraus d p (some j)).comp + (ρ.op.comp (adjoint (genDepolarizingKraus d p (some j)))) + = ((p : ℝ) : ℂ) • (maximallyMixedState (qudit d)).op := by + have h := (quditOrthonormalBasis d).sum_conjStarAlgEquiv_depolarizingUnitary ρ.op + have hfac : ∀ j ∈ (Finset.univ : Finset ((Fin d → Bool) × Equiv.Perm (Fin d))), + (genDepolarizingKraus d p (some j)).comp + (ρ.op.comp (adjoint (genDepolarizingKraus d p (some j)))) + = ((p : ℝ) : ℂ) • ((2 ^ Fintype.card (Fin d) * + ((Fintype.card (Fin d)).factorial : ℂ))⁻¹ + • ((quditOrthonormalBasis d).depolarizingUnitary j).conjStarAlgEquiv ρ.op) := by + intro j _ + rw [hterm j, smul_smul, Fintype.card_fin] + congr 1 + push_cast + field_simp + rw [Finset.sum_congr rfl hfac, ← Finset.smul_sum, h, State.trace_op_eq_one, + maximallyMixedState_op] + rw [show Module.finrank ℂ (qudit d).space = Fintype.card (Fin d) by + rw [Fintype.card_fin]; exact finrank_euclideanSpace_fin, one_div] + rw [hnone, htwirl] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HadamardABC.lean b/LeanPool/AxQM/Postulates/API/HadamardABC.lean new file mode 100644 index 0000000000..830f1febbc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HadamardABC.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Concrete.HadamardABC + +/-! +# AxQM.Postulates.API — the ABC decomposition of the Hadamard gate (operator level) + +The operator-level content of Nielsen & Chuang, Exercise 4.12: the Hadamard gate `H` equals the ABC +product `A X B X C` (of `y`/`z`-rotation gates and the Pauli-`X` gate) up to the global phase +`e^{iπ/2}`, where the witnesses are those of Corollary 4.2 for the Hadamard's Z–Y parameters +(`Concrete/HadamardABC.lean`): + +`α = π/2`, `A = R_y(π/4)`, `B = R_y(-π/4) R_z(-π/2)`, `C = R_z(π/2)`. + +This is the operator-level statement; the statement that `H` and the ABC gate product induce the +*same state evolution* is in [upstream `AxQM/NC/Ch4/Exercise4_12.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_12.lean). + +## What is formalised + +* `rotYGate θ` — the **`y`-axis rotation gate** `R_y(θ) = exp(-iθY/2)` as an `Evolution qubit` (the + `y`-axis analogue of `rotXGate`/`rotZGate`), with the `simp` bridge `rotYGate_op`. It completes + the `R_x`/`R_y`/`R_z` gate family and is reusable infrastructure. +* `hadamardGate_op_eq_expPiDivTwo_smul_hadamardABCGate` — **Exercise 4.12 at the operator level**: + `H = e^{iπ/2} • (A X B X C)` as operators on the qubit state space, the image under the + `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (`ℂ`-linear, so it preserves the phase, and + multiplicative, so it carries the matrix product to the `Evolution.comp` composite) of the + concrete matrix identity `Concrete.hadamardC_eq_expPiDivTwo_smul_hadamardABC`. + +## Design notes + +* **Related results.** Compare `rotXGate`/`rotZGate` and + `hadamardGate_op_eq_expPiDivTwo_smul_rotXGate_rotZGate_rotXGate` (Exercise 4.4). +* **Composition order.** The `Evolution` composite is nested to match the left-associated matrix + product `A X B X C = ((((A · X) · B) · X) · C)`, with `B = R_y(-π/4) R_z(-π/2)` a composite too; + `Evolution.comp_op` and the `_op` bridges then identify the composite's operator with the image of + the matrix product under `Matrix.toEuclideanCLM` (`map_mul`), closed by `rfl` at the `*`/`.comp` + definitional equality. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- The **`y`-axis rotation gate** `R_y(θ) = exp(-iθY/2)` as a closed-system evolution of the +`qubit` (Nielsen & Chuang, eq. 4.5), the `y`-axis analogue of `rotXGate`/`rotZGate`. Its operator is +the concrete rotation matrix `Concrete.rotY θ` promoted through the `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM`; unitarity — the `Evolution` proof obligation — is transported from +`Concrete.rotY_mem_unitaryGroup`. -/ +def rotYGate (θ : ℝ) : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotY θ) + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) (Concrete.rotY_mem_unitaryGroup θ) + +@[simp] +theorem rotYGate_op (θ : ℝ) : + (rotYGate θ).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotY θ) := rfl + +/-- **Nielsen & Chuang, Exercise 4.12 at the operator level.** The Hadamard gate equals its ABC +product up to the global phase `e^{iπ/2}`: `H = e^{iπ/2} • (A X B X C)`, with `A = R_y(π/4)`, +`B = R_y(-π/4) R_z(-π/2)`, `C = R_z(π/2)` (Corollary 4.2's witnesses for the Hadamard's Z–Y +parameters), as operators on the qubit state space. This is the image under the `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM` (`ℂ`-linear and multiplicative) of the concrete matrix identity +`Concrete.hadamardC_eq_expPiDivTwo_smul_hadamardABC`. -/ +theorem hadamardGate_op_eq_expPiDivTwo_smul_hadamardABCGate : + hadamardGate.op = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) • + (((((rotYGate (Real.pi / 4)).comp pauliXGate).comp + ((rotYGate (-(Real.pi / 4))).comp (rotZGate (-(Real.pi / 2))))).comp pauliXGate).comp + (rotZGate (Real.pi / 2))).op := by + rw [hadamardGate_op, Concrete.hadamardC_eq_expPiDivTwo_smul_hadamardABC, map_smul] + refine congrArg (_ • ·) ?_ + simp only [Concrete.hadamardWitnessA, Concrete.hadamardWitnessB, Concrete.hadamardWitnessC, + map_mul, + Evolution.comp_op, rotYGate_op, rotZGate_op, pauliXGate_op] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HadamardEigen.lean b/LeanPool/AxQM/Postulates/API/HadamardEigen.lean new file mode 100644 index 0000000000..ec1acef405 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HadamardEigen.lean @@ -0,0 +1,263 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.Postulates.API.Eigenstate +public import LeanPool.AxQM.Postulates.Observable +public import Mathlib.Tactic.LinearCombination + +/-! +# AxQM.Postulates.API — eigenvalues and eigenvectors of the Hadamard gate + +The eigenvalues and eigenvectors of the Hadamard gate: **Nielsen & Chuang, Exercise 2.53** +("What are the eigenvalues and eigenvectors of `H`?", §2.2.2, p. 82). The Hadamard gate +`H = (1/√2)!![1,1;1,-1]` is both unitary (Exercise 2.51, `hadamardGate : Evolution qubit`) and +**Hermitian**, so it is a legitimate `Observable qubit` — a structure whose real spectrum is a set +of measurement values. Its eigenvalues are the possible measurement outcomes and its eigenvectors +the corresponding eigenstates, which is exactly what the exercise asks for. We therefore state the +eigendecomposition for the `Observable`. + +## The answer + +`H` is Hermitian with `H² = I` (Exercise 2.52), so its eigenvalues are `±1`. The (normalized) +eigenvectors are, in the computational basis, + +* `|h₊⟩ ∝ (1, √2 − 1)` with eigenvalue `+1`; +* `|h₋⟩ ∝ (√2 − 1, −1)` with eigenvalue `−1` + +(equivalently `cos(π/8)|0⟩ + sin(π/8)|1⟩` and `sin(π/8)|0⟩ − cos(π/8)|1⟩`: `H` is the reflection +about the line at angle `π/8`). The eigenvalues are *exactly* `±1` — nothing else is an eigenvalue, +because `H² = I` forces `μ² = 1` — and the two eigenvectors are orthogonal (an orthonormal pair). + +## What is formalised + +* the general eigenstate notions `Observable.HasEigenstate A μ ψ` (the predicate that the pure + state `ψ` is an eigenstate of the observable `A` with real eigenvalue `μ`: `A ψ = μ ψ`), + `Observable.hasEigenstate_of_smul` (an eigenstate is unchanged by rescaling the underlying + vector), and `PureState.expectation_of_hasEigenstate` (the expectation value in an eigenstate *is* + the eigenvalue — the physical meaning of "eigenvalue"), which are used here and are in + `AxQM/Postulates/API/Eigenstate.lean` (imported above); and + `Observable.eigenvalue_eq_of_op_mul_self` (an involution `A² = 1` has only `±1` as + eigenvalues — the exhaustiveness lever), which is proved here. +* `hadamardObservable : Observable qubit` — the Hadamard gate as an observable, with the same + operator as `hadamardGate` (`hadamardObservable_op_eq_hadamardGate`), and `H² = I` + (`hadamardObservable_op_mul_self`). +* `hadamardEigenstatePlus`, `hadamardEigenstateMinus : PureState qubit` — the normalized + eigenstates, with the eigenvalue equations `hadamardObservable_apply_eigenvecPlus` + / `_eigenvecMinus` (`H v = ±v` on the unnormalized directions). +* `hadamardEigenstate_orthogonal` — the two eigenstates are orthogonal. + +That these are eigenstates with eigenvalues `±1` +(`Observable.HasEigenstate`), that the eigenvalues are *exactly* `±1` +(`hadamardObservable_eigenvalue_eq_one_or_neg_one`), and that `⟪H⟫ = ±1` in each, is stated in +[upstream `AxQM/NC/Ch2/Exercise2_53.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_53.lean). + +## Design notes + +* **Observable, not evolution.** Eigenvalues/eigenvectors are the spectral content of an operator; + real eigenvalues signal Hermiticity, which is what `Observable` bundles. `H` really + is self-adjoint (`Concrete.hadamardC_isHermitian`), so presenting the eigendecomposition through + `Observable` is faithful — and `hadamardObservable_op_eq_hadamardGate` records that it is the same + operator as the Exercise 2.51 gate. The unitary/`H²=I` facts belong to Exercises 2.51/2.52. +* **Linear reduction.** The eigenvalue equation `A v = μ v` is linear, so it is proved once on the + simple *unnormalized* directions `(1, √2−1)` / `(√2−1, −1)` (`hadamardC_mulVec_plus/minus`); the + messy normalization constant enters only the `‖·‖ = 1` obligation of `PureState`, via + `hasEigenstate_of_smul`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +open Matrix Complex + +variable {S : QSystem} + +/-! ### Involutive observables have `±1` spectrum + +The general eigenstate predicate `Observable.HasEigenstate` and its helpers +`Observable.hasEigenstate_of_smul` / `PureState.expectation_of_hasEigenstate` are in +`AxQM/Postulates/API/Eigenstate.lean` (imported above), and are also used in +`AxQM/Postulates/API/Variance.lean`. -/ + +/-- **An involutive observable has only `±1` as eigenvalues.** If `A² = 1` (in the operator ring), +then every eigenvalue `μ` of `A` satisfies `μ = 1` or `μ = −1`. Applying `A` twice to an eigenstate +`A ψ = μ ψ` gives `ψ = A² ψ = μ² ψ`, and `ψ ≠ 0` (it is normalized) forces `μ² = 1`. This is the +`⊆` (exhaustiveness) direction of an eigenvalue computation for any self-adjoint involution. -/ +theorem Observable.eigenvalue_eq_of_op_mul_self {A : Observable S} (hA : A.op * A.op = 1) + {μ : ℝ} {ψ : PureState S} (h : A.HasEigenstate μ ψ) : μ = 1 ∨ μ = -1 := by + have hop : A.op ψ.vec = (μ : ℂ) • ψ.vec := h + have hsq : A.op (A.op ψ.vec) = ψ.vec := by + have := congrArg (fun T : S →L[ℂ] S => T ψ.vec) hA + simpa [mul_apply_eq_comp] using this + rw [hop, map_smul, hop, smul_smul] at hsq + have hne : ψ.vec ≠ 0 := fun hz => by + have := ψ.normalized; rw [hz, norm_zero] at this; norm_num at this + have hc : (μ : ℂ) * (μ : ℂ) = 1 := by + have hz : (((μ : ℂ) * (μ : ℂ)) - 1) • ψ.vec = 0 := by rw [sub_smul, hsq, one_smul, sub_self] + rcases smul_eq_zero.mp hz with h' | h' + · linear_combination h' + · exact absurd h' hne + exact mul_self_eq_one_iff.mp (by exact_mod_cast hc) + +/-! ### The Hadamard observable and its complex-matrix eigen-equations -/ + +/-- The **Hadamard gate as an observable** on the qubit: the operator of `Concrete.hadamardC` +promoted through `Matrix.toEuclideanCLM`. It is self-adjoint because `H` is Hermitian +(`Concrete.hadamardC_isHermitian`); this is the same operator as `hadamardGate` +(`hadamardObservable_op_eq_hadamardGate`). Its `±1` spectrum is the content of Exercise 2.53. -/ +def hadamardObservable : Observable qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC + selfAdjoint := + Concrete.hadamardC_isHermitian.isSelfAdjoint.map + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + +/-- The operator of `hadamardObservable` is the `Matrix.toEuclideanCLM` image of the concrete +Hadamard matrix `Concrete.hadamardC`. A `simp` bridge exposing the underlying operator. -/ +@[simp] +theorem hadamardObservable_op : + hadamardObservable.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC := + rfl + +/-- `hadamardObservable` and `hadamardGate` (Exercise 2.51) are the **same operator**: the Hadamard +matrix `H` viewed as a self-adjoint observable and as a unitary evolution. This records that the +eigendecomposition below is of the very gate of Exercise 2.51. -/ +theorem hadamardObservable_op_eq_hadamardGate : hadamardObservable.op = hadamardGate.op := rfl + +/-- **`H² = I` at the operator level** (Exercise 2.52's content, `Concrete.hadamardC_mul_self`, +transported through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` by `map_mul` / `map_one`). +This is the involution property that pins the Hadamard eigenvalues to `±1`. -/ +theorem hadamardObservable_op_mul_self : + hadamardObservable.op * hadamardObservable.op = 1 := by + change Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC + * Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC = 1 + rw [← map_mul, Concrete.hadamardC_mul_self, map_one] + +/-- `(√2 : ℂ) · (√2 : ℂ) = 2`. -/ +private theorem sqrt_two_mul_self : (Real.sqrt 2 : ℂ) * (Real.sqrt 2 : ℂ) = 2 := by + rw [← Complex.ofReal_mul, Real.mul_self_sqrt (by norm_num : (0 : ℝ) ≤ 2)]; norm_num + +/-- `(√2 : ℂ) ≠ 0`. -/ +private theorem sqrt_two_ne_zero : (Real.sqrt 2 : ℂ) ≠ 0 := by + rw [Complex.ofReal_ne_zero]; positivity + +/-- **Eigenvalue equation for `+1` at the matrix level:** `H · (1, √2−1) = (1, √2−1)`, i.e. the +column vector `(1, √2−1)` is a `+1`-eigenvector of the concrete Hadamard matrix. Proved from the +`(1/√2)`-free identity `!![1,1;1,-1] · (1, √2−1) = √2 · (1, √2−1)` after cancelling the `1/√2`. -/ +theorem hadamardC_mulVec_plus : + Concrete.hadamardC *ᵥ ![1, (Real.sqrt 2 - 1 : ℂ)] = (1 : ℂ) • ![1, (Real.sqrt 2 - 1 : ℂ)] := by + have base : (!![1, 1; 1, -1] : Matrix (Fin 2) (Fin 2) ℂ) *ᵥ ![1, (Real.sqrt 2 - 1 : ℂ)] + = (Real.sqrt 2 : ℂ) • ![1, (Real.sqrt 2 - 1 : ℂ)] := by + funext i + fin_cases i <;> simp [Matrix.mulVec, dotProduct, Fin.sum_univ_two] + linear_combination -sqrt_two_mul_self + rw [Concrete.hadamardC, Matrix.smul_mulVec, base, smul_smul, + inv_mul_cancel₀ sqrt_two_ne_zero, one_smul] + +/-- **Eigenvalue equation for `−1` at the matrix level:** `H · (√2−1, −1) = −(√2−1, −1)`, i.e. +`(√2−1, −1)` is a `−1`-eigenvector of the concrete Hadamard matrix. -/ +theorem hadamardC_mulVec_minus : + Concrete.hadamardC *ᵥ ![(Real.sqrt 2 - 1 : ℂ), -1] + = (-1 : ℂ) • ![(Real.sqrt 2 - 1 : ℂ), -1] := by + have base : (!![1, 1; 1, -1] : Matrix (Fin 2) (Fin 2) ℂ) *ᵥ ![(Real.sqrt 2 - 1 : ℂ), -1] + = (-(Real.sqrt 2 : ℂ)) • ![(Real.sqrt 2 - 1 : ℂ), -1] := by + funext i + fin_cases i <;> simp [Matrix.mulVec, dotProduct, Fin.sum_univ_two] + linear_combination sqrt_two_mul_self + rw [Concrete.hadamardC, Matrix.smul_mulVec, base, smul_smul, + show (Real.sqrt 2 : ℂ)⁻¹ * (-(Real.sqrt 2)) = -1 by + rw [mul_neg, inv_mul_cancel₀ sqrt_two_ne_zero]] + +/-! ### The eigenvectors and normalized eigenstates -/ + +/-- The unnormalized `+1`-eigenvector `(1, √2 − 1)` of `H`, as a qubit vector. -/ +def hadamardEigenvecPlus : qubit := WithLp.toLp 2 ![1, (Real.sqrt 2 - 1 : ℂ)] + +/-- The unnormalized `−1`-eigenvector `(√2 − 1, −1)` of `H`, as a qubit vector. -/ +def hadamardEigenvecMinus : qubit := WithLp.toLp 2 ![(Real.sqrt 2 - 1 : ℂ), -1] + +/-- `hadamardObservable` acts on `(1, √2−1)` as multiplication by `+1` (operator form of +`hadamardC_mulVec_plus`). -/ +theorem hadamardObservable_apply_eigenvecPlus : + hadamardObservable.op hadamardEigenvecPlus = (1 : ℂ) • hadamardEigenvecPlus := by + change Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC + (WithLp.toLp 2 ![1, (Real.sqrt 2 - 1 : ℂ)]) + = (1 : ℂ) • WithLp.toLp 2 ![1, (Real.sqrt 2 - 1 : ℂ)] + rw [Matrix.toEuclideanCLM_toLp, hadamardC_mulVec_plus, WithLp.toLp_smul] + +/-- `hadamardObservable` acts on `(√2−1, −1)` as multiplication by `−1` (operator form of +`hadamardC_mulVec_minus`). -/ +theorem hadamardObservable_apply_eigenvecMinus : + hadamardObservable.op hadamardEigenvecMinus = (-1 : ℂ) • hadamardEigenvecMinus := by + change Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC + (WithLp.toLp 2 ![(Real.sqrt 2 - 1 : ℂ), -1]) + = (-1 : ℂ) • WithLp.toLp 2 ![(Real.sqrt 2 - 1 : ℂ), -1] + rw [Matrix.toEuclideanCLM_toLp, hadamardC_mulVec_minus, WithLp.toLp_smul] + +/-- `(1, √2−1)` is nonzero (its first component is `1`), so it is a genuine eigenvector. -/ +theorem hadamardEigenvecPlus_ne_zero : hadamardEigenvecPlus ≠ 0 := by + intro h + have : (WithLp.ofLp hadamardEigenvecPlus) 0 = 0 := by rw [h]; rfl + simp [hadamardEigenvecPlus, WithLp.ofLp_toLp] at this + +/-- `(√2−1, −1)` is nonzero (its second component is `−1`), so it is a genuine eigenvector. -/ +theorem hadamardEigenvecMinus_ne_zero : hadamardEigenvecMinus ≠ 0 := by + intro h + have : (WithLp.ofLp hadamardEigenvecMinus) 1 = 0 := by rw [h]; rfl + simp [hadamardEigenvecMinus, WithLp.ofLp_toLp] at this + +/-! ### The normalized eigenstates -/ + +/-- The normalized `+1`-eigenstate `|h₊⟩` of the Hadamard observable, via the shared +`PureState.normalize`. -/ +def hadamardEigenstatePlus : PureState qubit := + PureState.normalize hadamardEigenvecPlus hadamardEigenvecPlus_ne_zero + +/-- The normalized `−1`-eigenstate `|h₋⟩` of the Hadamard observable, via the shared +`PureState.normalize`. -/ +def hadamardEigenstateMinus : PureState qubit := + PureState.normalize hadamardEigenvecMinus hadamardEigenvecMinus_ne_zero + +/-- The underlying vector of `|h₊⟩` is `‖v₊‖⁻¹ • v₊`, a scalar multiple of the `+1`-eigenvector +`v₊ = (1, √2−1)`. The bridge used to transport the eigenvalue equation to the normalized state. -/ +theorem hadamardEigenstatePlus_vec : + hadamardEigenstatePlus.vec + = ((‖hadamardEigenvecPlus‖ : ℝ) : ℂ)⁻¹ • hadamardEigenvecPlus := rfl + +/-- The underlying vector of `|h₋⟩` is `‖v₋‖⁻¹ • v₋`, a scalar multiple of the `−1`-eigenvector +`v₋ = (√2−1, −1)`. -/ +theorem hadamardEigenstateMinus_vec : + hadamardEigenstateMinus.vec + = ((‖hadamardEigenvecMinus‖ : ℝ) : ℂ)⁻¹ • hadamardEigenvecMinus := rfl + +/-- The two unnormalized Hadamard eigenvectors `(1, √2−1)` and `(√2−1, −1)` are orthogonal: +`⟪(1, √2−1), (√2−1, −1)⟫ = (√2−1) − (√2−1) = 0`. -/ +theorem hadamardEigenvec_orthogonal : + ⟪hadamardEigenvecPlus, hadamardEigenvecMinus⟫_ℂ = 0 := by + change ⟪(WithLp.toLp 2 ![1, (Real.sqrt 2 - 1 : ℂ)] : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 ![(Real.sqrt 2 - 1 : ℂ), -1]⟫_ℂ = 0 + rw [EuclideanSpace.inner_eq_star_dotProduct] + simp [dotProduct, Fin.sum_univ_two, Complex.conj_ofReal] + +/-- The two Hadamard eigenstates are **orthogonal** — an orthonormal pair, as befits eigenvectors of +a self-adjoint operator for distinct eigenvalues. (That `±1` are *all* the eigenvalues is proved +separately, from `H² = I`, by `hadamardObservable_eigenvalue_eq_one_or_neg_one`.) -/ +theorem hadamardEigenstate_orthogonal : + ⟪hadamardEigenstatePlus.vec, hadamardEigenstateMinus.vec⟫_ℂ = 0 := by + unfold hadamardEigenstatePlus hadamardEigenstateMinus + simp only [PureState.normalize_vec, inner_smul_left, inner_smul_right, + hadamardEigenvec_orthogonal, mul_zero] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HadamardGate.lean b/LeanPool/AxQM/Postulates/API/HadamardGate.lean new file mode 100644 index 0000000000..936798a7f1 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HadamardGate.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Concrete.Hadamard + +/-! +# AxQM.Postulates.API — the Hadamard gate as a qubit evolution + +Nielsen & Chuang's Hadamard gate as an evolution of the qubit. + +* `hadamardGate` — the **evolution** `H` on the qubit (Postulate 2 / `Evolution`), obtained by + promoting the concrete complex Hadamard matrix `Concrete.hadamardC` to a continuous linear + operator via the C\*-algebra isomorphism `Matrix.toEuclideanCLM`. Its `unitary` field — the + proof obligation bundled into `Evolution` — is exactly **Nielsen & Chuang, Exercise 2.51** + (`H` is unitary): constructing `hadamardGate` *is* the verification that `H` is a legitimate + closed-system evolution. The statement of Exercise 2.51 is in [upstream `AxQM/NC/Ch2/Exercise2_51.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_51.lean). +* `hadamardGate_op` — a `simp` bridge exposing the underlying operator + `hadamardGate.op = Matrix.toEuclideanCLM Concrete.hadamardC`, for operator + computations (e.g. the Hadamard involution `H² = I` of Exercise 2.52 and the eigenvector + analysis of Exercise 2.53). +* `hadamardGate_inner_qubitBasis` — the **computational-basis matrix element** `⟪|i⟩, H|j⟩⟫ = Hᵢⱼ`, + the single-qubit companion of `pauliXObservable_inner_qubitBasis` + (`AxQM/Postulates/API/Qubit.lean`); the input to the two-qubit gate matrices of Exercise 4.16. + +## Design notes + +* **Unitarity.** "The Hadamard gate is unitary" is carried by the structure + `Evolution`: a value of type `Evolution qubit` cannot be formed without discharging + `op ∈ unitary (…)`. We supply that from the matrix-level fact + `Concrete.hadamardC_mem_unitaryGroup` (Ex 2.51 as a `Matrix.unitaryGroup` membership), + transported through `Matrix.toEuclideanCLM` by `Unitary.map_mem`: a `⋆`-monoid homomorphism + maps unitaries to unitaries, so the operator inherits unitarity from the matrix with no + operator-level entrywise computation. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **Hadamard gate** `H` as a closed-system evolution of the qubit (Nielsen & Chuang, +Postulate 2 and eq. 2.85). Its operator is the concrete complex Hadamard matrix +`Concrete.hadamardC` promoted to a continuous linear map through the `⋆`-algebra isomorphism +`Matrix.toEuclideanCLM`; unitarity — the `Evolution` proof obligation, and the content of +**Exercise 2.51** — is transported from `Concrete.hadamardC_mem_unitaryGroup`. -/ +def hadamardGate : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + Concrete.hadamardC_mem_unitaryGroup + +/-- The underlying operator of `hadamardGate` is the `Matrix.toEuclideanCLM` image of the concrete +complex Hadamard matrix `Concrete.hadamardC`. A `simp` lemma exposing the operator for +operator computations (the involution `H² = I` and the eigenvector analysis of Exercises 2.52, +2.53). -/ +@[simp] +theorem hadamardGate_op : + hadamardGate.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC := + rfl + +/-- **Matrix element of the Hadamard gate in the computational basis:** `⟪|i⟩, H|j⟩⟫ = Hᵢⱼ`. The +inner product `⟨i|H|j⟩` is the `(i, j)` entry of the concrete complex Hadamard matrix +`Concrete.hadamardC`, read off through the matrix-to-operator bridge `Matrix.toEuclideanCLM`. The +single-qubit companion of `hadamardGate_op` (mirroring the Pauli-`X` matrix element +`pauliXObservable_inner_qubitBasis` of `AxQM/Postulates/API/Qubit.lean`); the input to the +two-qubit gate matrices of Exercise 4.16 (`AxQM/Postulates/API/TwoQubitGateMatrix.lean`). -/ +theorem hadamardGate_inner_qubitBasis (i j : Fin 2) : + inner ℂ (qubitBasis i).vec (hadamardGate.op (qubitBasis j).vec) = Concrete.hadamardC i j := by + rw [hadamardGate_op] + change inner ℂ (EuclideanSpace.single i (1 : ℂ)) + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC) + (EuclideanSpace.single j 1)) = _ + rw [EuclideanSpace.inner_single_left, Matrix.ofLp_toEuclideanCLM] + fin_cases i <;> fin_cases j <;> simp [Matrix.mulVec, dotProduct, Concrete.hadamardC] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HadamardRotation.lean b/LeanPool/AxQM/Postulates/API/HadamardRotation.lean new file mode 100644 index 0000000000..6fdef817a3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HadamardRotation.lean @@ -0,0 +1,79 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Postulates.API.PiEighthGate +public import LeanPool.AxQM.Concrete.HadamardRotation + +/-! +# AxQM.Postulates.API — the Hadamard gate as a product of `R_x`, `R_z` rotation gates + +The operator-level content of Nielsen & Chuang, Exercise 4.4: the Hadamard gate `H` equals the +product `R_x(π/2) R_z(π/2) R_x(π/2)` of `x`- and `z`-rotation gates, up to the global phase +`e^{iπ/2}`. This is the operator-level statement; the statement that `H` and the rotation +product induce the *same state evolution* is in [upstream `AxQM/NC/Ch4/Exercise4_4.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_4.lean). + +## What is formalised + +* `rotXGate θ` — the **`x`-axis rotation gate** `R_x(θ) = exp(-iθX/2)` as an `Evolution qubit` + (the `x`-axis analogue of `rotZGate` from `Postulates/API/PiEighthGate.lean`), with the `simp` + bridge `rotXGate_op`. +* `hadamardGate_op_eq_expPiDivTwo_smul_rotXGate_rotZGate_rotXGate` — **Exercise 4.4 at the operator + level** (eq. of eq. 4.4-flavoured decomposition): `H = e^{iπ/2} • (R_x(π/2) R_z(π/2) R_x(π/2))` + as operators on the qubit state space. The image, under the `⋆`-algebra isomorphism + `Matrix.toEuclideanCLM` (which is `ℂ`-linear, so it preserves the scalar, and multiplicative, so + it carries matrix products to composition), of the concrete matrix identity + `Concrete.hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX`. + +## Design notes + +* **Related results.** Compare `rotZGate` and `tGate_op_eq_expPiDivEight_smul_rotZGate`. +* **Composition order.** The Evolution composite + `((rotXGate (π/2)).comp (rotZGate (π/2))).comp (rotXGate (π/2))` has operator + `R_x(π/2) ∘ R_z(π/2) ∘ R_x(π/2)`, which `Matrix.toEuclideanCLM` identifies with the matrix + product `R_x(π/2) R_z(π/2) R_x(π/2)` (`map_mul`): applying the composite is "first `R_x`, then + `R_z`, then `R_x`", matching the right-to-left reading of the matrix product. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- The **`x`-axis rotation gate** `R_x(θ) = exp(-iθX/2)` as a closed-system evolution of the +`qubit` (Nielsen & Chuang, eq. 4.4). Its operator is the concrete rotation matrix `Concrete.rotX θ` +promoted through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; unitarity — the `Evolution` +proof obligation — is transported from `Concrete.rotX_mem_unitaryGroup`. -/ +def rotXGate (θ : ℝ) : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotX θ) + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) (Concrete.rotX_mem_unitaryGroup θ) + +@[simp] +theorem rotXGate_op (θ : ℝ) : + (rotXGate θ).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotX θ) := rfl + +/-- **Nielsen & Chuang, Exercise 4.4 at the operator level.** The Hadamard gate equals the +`X`–`Z`–`X` rotation product up to the global phase `e^{iπ/2}`: +`H = e^{iπ/2} • (R_x(π/2) R_z(π/2) R_x(π/2))`, as operators on the qubit state space. This is the +image under the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (`ℂ`-linear and multiplicative) of +the concrete matrix identity `Concrete.hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX`. -/ +theorem hadamardGate_op_eq_expPiDivTwo_smul_rotXGate_rotZGate_rotXGate : + hadamardGate.op = Complex.exp ((Real.pi / 2 : ℝ) * Complex.I) • + (((rotXGate (Real.pi / 2)).comp (rotZGate (Real.pi / 2))).comp + (rotXGate (Real.pi / 2))).op := by + rw [hadamardGate_op, Concrete.hadamardC_eq_expPiDivTwo_smul_rotX_rotZ_rotX, map_smul] + congr 1 + rw [map_mul, map_mul] + simp only [Evolution.comp_op, rotXGate_op, rotZGate_op] + rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HamiltonianGenerator.lean b/LeanPool/AxQM/Postulates/API/HamiltonianGenerator.lean new file mode 100644 index 0000000000..beb46748ee --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HamiltonianGenerator.lean @@ -0,0 +1,83 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Unitary.ExpEndomorphism + +/-! +# The Hamiltonian generator of a unitary evolution, with bounded spectrum + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Problem 4.3(1) asks to show that, +for a unitary `U` on `n` qubits, `H ≡ i ln(U)` is **Hermitian, with eigenvalues in the range `0` to +`2π`**. In this library a closed-system dynamics is an `Evolution` (a bundled unitary) and a +Hamiltonian is an `Observable` (a bundled self-adjoint operator); `Observable.propagator H 1 0 1` is +the unit-time, `ℏ = 1` propagator `exp(-i H)` (Nielsen–Chuang eq. 2.91). + +The existence half — *every* `Evolution` has a Hermitian generator — is +`AxQM.Evolution.exists_hamiltonian_generator` ([upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean)). This file adds +the **eigenvalue-range refinement**: the generator can be chosen with its spectrum contained in +`[0, 2π]`. + +* `AxQM.Evolution.exists_hamiltonian_generator_spectrum_Icc` — for any `Evolution U`, there + is an `Observable H` with `U = H.propagator 1 0 1` (i.e. `U = exp(-iH)`) **and** every eigenvalue + of `H` a real number in `[0, 2π]` (`spectrum ℂ H.op ⊆ ℝ ∩ [0, 2π]`). This is exactly Problem + 4.3(1): with the appropriate branch of `ln`, `H = i ln U` is Hermitian with spectrum in `[0, 2π]`. + +## Design + +* **The mathematics.** The operator-level fact — every unitary on a finite-dimensional complex + Hilbert space is `exp(-i • A)` for a self-adjoint `A` with `spectrum ℂ A ⊆ ℝ ∩ [0, 2π]` — is the + general lemma + `ContinuousLinearMap.exists_isSelfAdjoint_spectrum_Icc_exp_neg_smul_I_eq_of_mem_unitary`, + proved by a `[0, 2π)`-branch of the logarithm via the continuous functional calculus. Here + `H.op = A`, so + `H.propagator 1 0 1 = exp(-i H) = exp(-i • A) = U`. +* **Spectrum over `ℂ`.** The bound reads `spectrum ℂ H.op ⊆ Complex.ofReal '' [0, 2π]` — every + eigenvalue is a *real* number in `[0, 2π]` — which is the faithful content of "eigenvalues in the + range `0` to `2π`" for the Hermitian `H`, and avoids the `Algebra ℝ`/`IsScalarTower` scaffolding a + `spectrum ℝ` phrasing would require. See that lemma's docstring. +* **Generality.** N&C fix a unitary on `n` qubits (dimension `2ⁿ`); the theorem is stated for an + arbitrary finite-dimensional system `S`, which is strictly more general and specialises to the + `n`-qubit register. Part (1) makes no use of the tensor factorisation. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Nielsen & Chuang, Problem 4.3(1): the Hamiltonian generator can be chosen with spectrum in +`[0, 2π]`.** Every closed-system `Evolution U` on a finite-dimensional quantum system `S` is +generated by a Hamiltonian `H` (an `Observable`, i.e. a self-adjoint operator) with +`U = H.propagator 1 0 1` — that is, `U = exp(-iH)` — whose eigenvalues are all real numbers in +`[0, 2π]` (`spectrum ℂ H.op ⊆ Complex.ofReal '' Set.Icc 0 (2π)`). + +This is the full content of "`H = i ln(U)` is Hermitian, with eigenvalues in the range `0` to `2π`": +choosing the `[0, 2π)`-branch of `ln`, the generator's spectrum lands in `[0, 2π]`. It refines the +existence statement `Evolution.exists_hamiltonian_generator` ([upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean)) with +the eigenvalue-range clause. -/ +theorem Evolution.exists_hamiltonian_generator_spectrum_Icc (U : Evolution S) : + ∃ H : Observable S, U = H.propagator 1 0 1 ∧ + spectrum ℂ H.op ⊆ Complex.ofReal '' Set.Icc 0 (2 * Real.pi) := by + have : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + -- The unitary `U.op = exp(-i • A)` for a self-adjoint `A` with spectrum in `[0, 2π]`. + obtain ⟨A, hAsa, hAspec, hAexp⟩ := + ContinuousLinearMap.exists_isSelfAdjoint_spectrum_Icc_exp_neg_smul_I_eq_of_mem_unitary U.unitary + -- Take the Hamiltonian `H` with `H.op = A`; then `exp(-i H) = exp(-i • A) = U.op`. + refine ⟨⟨A, hAsa⟩, Evolution.ext ?_, hAspec⟩ + rw [Observable.propagator_op, ← hAexp] + norm_num + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HolevoMeasurementChannel.lean b/LeanPool/AxQM/Postulates/API/HolevoMeasurementChannel.lean new file mode 100644 index 0000000000..812129d4dd --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HolevoMeasurementChannel.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuantumChannel +public import LeanPool.AxQM.Postulates.API.PeriodShift +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar + +/-! +# AxQM.Postulates.API — the Holevo measurement operation `𝓔` (N&C Exercise 12.2) + +The construction realizing **Nielsen & Chuang, Exercise 12.2** (p. 533), the construction used in +the proof of the Holevo bound (Theorem 12.1). The quantum operation `𝓔` there acts on the system `Q` +Alice gives Bob together with Bob's measuring apparatus `M`, performing a measurement with POVM +elements `{E_y}` on `Q` and *storing the outcome* in `M`: + + `𝓔(σ ⊗ |0⟩⟨0|) = ∑_y √E_y σ √E_y ⊗ |y⟩⟨y|` (Nielsen & Chuang, Eq. (12.8)), + +where `|0⟩` is the apparatus' standard (reset) state. Exercise 12.2 asks one to exhibit an explicit +operator-sum (Kraus) representation of `𝓔` and verify it is trace-preserving: + +Show {sqrt(E_y) tensor U_y} defines a trace-preserving quantum operation matching (12.8). + +## The formalisation + +The measurement is modelled by `Measurement (Fin r) Q` (Postulate 3): a +family of measurement operators `M_y` with the completeness relation `∑_y M_y† M_y = 1`. Its induced +POVM has effects `E_y = M_y† M_y`, so the positive square root `√E_y = √(M_y† M_y)` is exactly the +**absolute value** `|M_y|` (`ContinuousLinearMap.absoluteValue`) — a self-adjoint positive operator +with `|M_y|² = M_y† M_y = E_y`. Every POVM `{E_y}` arises as `m.toPOVM` for some measurement `m` +(e.g. `M_y = √E_y`), so this loses no generality. The apparatus `M` is the `r`-level system +`qudit r` (`r = n + 1` outcomes), with computational basis `|y⟩` and the cyclic shift +`U_y = periodShift r y` (`U_y|0⟩ = |y⟩`). + +* `holevoMeasurementKraus m y` — the **operation element** `√E_y ⊗ U_y` of outcome `y` on `Q ⊗ M` + (`TensorProduct.mapL |M_y| U_y`). +* `holevoMeasurementKraus_completeness m` — **the trace-preservation / completeness relation** + `∑_y (√E_y ⊗ U_y)† (√E_y ⊗ U_y) = 1`, the condition that `{√E_y ⊗ U_y}` defines a + trace-preserving quantum operation. Each summand factors as `(|M_y|† |M_y|) ⊗ (U_y† U_y) = + E_y ⊗ 1`, and `∑_y E_y = 1` is the measurement's completeness. +* `holevoMeasurementChannel m` — the resulting **quantum operation `𝓔`** as a channel + `State (Q ⊗ M) → State (Q ⊗ M)`, `ρ ↦ ∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†`, with + `holevoMeasurementChannel_isChannel` proving it is a genuine CPTP map (`IsChannel`) via the + operator-sum direction of N&C Theorem 8.1 (`isChannel_of_kraus`). +* `holevoMeasurementChannel_apply_tmul` — **agreement with (12.8):** on a reset apparatus, + `𝓔(σ ⊗ |0⟩⟨0|) = ∑_y √E_y σ √E_y ⊗ |y⟩⟨y|`. The two identities used per summand are + `|M_y|† = |M_y|` (self-adjointness of the square root, so `√E_y σ √E_y†` reads `√E_y σ √E_y`) and + `U_y |0⟩⟨0| U_y† = |y⟩⟨y|` (`periodShift_op_conj_quditBasisZero`). + +The statement of Exercise 12.2 is in [upstream `AxQM/NC/Ch12/Exercise12_2.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Exercise12_2.lean). + +## Design notes + +* **Generality.** N&C introduces the operation elements `√E_y ⊗ U_y` and asks for two + facts — that they define a *trace-preserving* operation and that its action matches (12.8). The + formalisation names the elements as their own `def`, states the completeness relation and the + channel property as their own theorems, and states the (12.8) agreement over an arbitrary system + `Q`, an arbitrary measurement `m` on it (arbitrary number of outcomes `r = n + 1`), and an + arbitrary state `σ` of `Q` — no dimension is fixed and no hypothesis is added beyond `NeZero r` + (the apparatus must have at least one basis state). The right-hand side is stated in N&C's literal + Eq. (12.8) shape `∑_y √E_y σ √E_y ⊗ |y⟩⟨y|`, with `√E_y = |M_y|` and `|y⟩⟨y| = + (quditBasis y).toState.op`. +* **Why `|M_y|` for `√E_y`.** The absolute value `|M_y| = √(M_y† M_y)` is the positive square root + of the effect `E_y = M_y† M_y` (Postulate 3), so it is literally `√E_y`; the purpose-built lemma + `absoluteValue_sq` (`|M_y| |M_y| = M_y† M_y`) and its positivity/self-adjointness drive the two + short proofs, and the completeness relation of `{√E_y ⊗ U_y}` reduces directly to the + measurement's own completeness `∑_y M_y† M_y = 1`. +* **Proof.** Both theorems are per-summand rewrites over the tensor-operator API: + `TensorProduct.mapL_adjoint_comp_self` (`(f ⊗ g)† (f ⊗ g) = f†f ⊗ g†g`) for completeness, and + `TensorProduct.mapL_comp_self` (`(f ⊗ g) X (f ⊗ g)† = fXf† ⊗ gXg†` on a product `X`) for the + action. Two facts they use are elsewhere: the operator-theory + fact `|T|† = |T|` (`ContinuousLinearMap.adjoint_absoluteValue`) is in + `ToMathlib/Analysis/InnerProductSpace/Polar.lean`, and the shift conjugation + `U_y |0⟩⟨0| U_y† = |y⟩⟨y|` (`periodShift_op_conj_quditBasisZero`) is in + `AxQM/Postulates/API/PeriodShift.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {Q : QSystem} {r : ℕ} [NeZero r] + +/-- **The operation element `√E_y ⊗ U_y` of outcome `y`** (Nielsen & Chuang, Exercise 12.2), on the +composite of the measured system `Q` and the apparatus `qudit r`. Here `√E_y = |M_y|` is the +positive square root of the POVM effect `E_y = M_y† M_y` of the measurement `m` (the absolute value +of the measurement operator `M_y`), and `U_y = periodShift r y` is the cyclic shift storing the +outcome, `U_y|0⟩ = |y⟩`. -/ +def holevoMeasurementKraus (m : Measurement (Fin r) Q) (y : Fin r) : + (Q ⊗ qudit r).space →L[ℂ] (Q ⊗ qudit r).space := + TensorProduct.mapL (m.op y).absoluteValue (periodShift r y).op + +/-- **Nielsen & Chuang, Exercise 12.2 (trace preservation).** The operation elements `{√E_y ⊗ U_y}` +obey the completeness relation `∑_y (√E_y ⊗ U_y)† (√E_y ⊗ U_y) = 1`, so they define a +*trace-preserving* quantum operation. Each summand is `(|M_y|† |M_y|) ⊗ (U_y† U_y) = (M_y† M_y) ⊗ 1` +— the square root is self-adjoint with `|M_y|² = E_y` (`absoluteValue_sq`) and `U_y` is unitary — +and `∑_y M_y† M_y = 1` is the measurement's completeness (Postulate 3). -/ +theorem holevoMeasurementKraus_completeness (m : Measurement (Fin r) Q) : + ∑ y, (adjoint (holevoMeasurementKraus m y)).comp (holevoMeasurementKraus m y) = 1 := by + have key : ∀ y : Fin r, + (adjoint (holevoMeasurementKraus m y)).comp (holevoMeasurementKraus m y) + = TensorProduct.mapL ((adjoint (m.op y)).comp (m.op y)) + (1 : (qudit r).space →L[ℂ] (qudit r).space) := by + intro y + have h := TensorProduct.mapL_adjoint_comp_self (m.op y).absoluteValue (periodShift r y).op + rw [ContinuousLinearMap.adjoint_absoluteValue, ContinuousLinearMap.absoluteValue_sq, + (periodShift r y).adjoint_comp_self] at h + rw [holevoMeasurementKraus] + exact h + have step1 : ∑ y, (adjoint (holevoMeasurementKraus m y)).comp (holevoMeasurementKraus m y) + = ∑ y, TensorProduct.mapL ((adjoint (m.op y)).comp (m.op y)) + (1 : (qudit r).space →L[ℂ] (qudit r).space) := + Finset.sum_congr rfl (fun y _ => key y) + have step2 : ∑ y, TensorProduct.mapL ((adjoint (m.op y)).comp (m.op y)) + (1 : (qudit r).space →L[ℂ] (qudit r).space) + = TensorProduct.mapL (∑ y, (adjoint (m.op y)).comp (m.op y)) + (1 : (qudit r).space →L[ℂ] (qudit r).space) := + (TensorProduct.mapL_sum_left (fun y => (adjoint (m.op y)).comp (m.op y)) + (1 : (qudit r).space →L[ℂ] (qudit r).space)).symm + rw [m.complete] at step2 + exact step1.trans (step2.trans TensorProduct.mapL_one) + +/-- **The Holevo measurement operation `𝓔`** (Nielsen & Chuang, Exercise 12.2 / Eq. (12.8)), as a +quantum channel `State (Q ⊗ M) → State (Q ⊗ M)`: `ρ ↦ ∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†`, the +operator sum of the operation elements `holevoMeasurementKraus m`. It sends a state to a state +because the elements satisfy the completeness relation (`holevoMeasurementKraus_completeness`), so +the Kraus map preserves density operators (`isDensityOp_krausSumₗ`). -/ +def holevoMeasurementChannel (m : Measurement (Fin r) Q) : + State (Q ⊗ qudit r) → State (Q ⊗ qudit r) := fun ρ => + { op := ContinuousLinearMap.krausSumₗ (holevoMeasurementKraus m) ρ.op + isDensity := ContinuousLinearMap.isDensityOp_krausSumₗ (holevoMeasurementKraus m) + (holevoMeasurementKraus_completeness m) ρ.isDensity } + +/-- The underlying operator of the Holevo measurement operation is the Kraus sum +`𝓔(ρ) = ∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†`: the `.op`-unfolding lemma of `holevoMeasurementChannel` +(true by `rfl`), completing the def's API. -/ +@[simp] +theorem holevoMeasurementChannel_op (m : Measurement (Fin r) Q) (ρ : State (Q ⊗ qudit r)) : + (holevoMeasurementChannel m ρ).op + = ContinuousLinearMap.krausSumₗ (holevoMeasurementKraus m) ρ.op := rfl + +/-- **Nielsen & Chuang, Exercise 12.2 (a trace-preserving quantum operation).** The Holevo +measurement operation `𝓔` is a genuine quantum channel (completely positive and trace-preserving): +its operation elements `{√E_y ⊗ U_y}` satisfy the completeness relation, so +`isChannel_of_kraus` (the trace-preserving direction of the operator-sum theorem, N&C Theorem 8.1) +exhibits it as a CPTP map. -/ +theorem holevoMeasurementChannel_isChannel (m : Measurement (Fin r) Q) : + IsChannel (holevoMeasurementChannel m) := + isChannel_of_kraus (holevoMeasurementKraus m) (holevoMeasurementKraus_completeness m) + (fun _ => rfl) + +/-- **Nielsen & Chuang, Exercise 12.2 (agreement with Eq. (12.8)).** On a state of the form +`σ ⊗ |0⟩⟨0|` — the system `σ` together with the apparatus in its standard state `|0⟩` — the Holevo +measurement operation acts as + + `𝓔(σ ⊗ |0⟩⟨0|) = ∑_y √E_y σ √E_y ⊗ |y⟩⟨y|`, + +exactly Eq. (12.8). Per summand, the Kraus action `(√E_y ⊗ U_y)(σ ⊗ |0⟩⟨0|)(√E_y ⊗ U_y)†` factors +(`TensorProduct.mapL_comp_self`) into `(√E_y σ √E_y†) ⊗ (U_y |0⟩⟨0| U_y†)`; the square root is +self-adjoint (`ContinuousLinearMap.adjoint_absoluteValue`, giving `√E_y σ √E_y`) and the shift moves +the reset projector to `|y⟩⟨y|` (`periodShift_op_conj_quditBasisZero`). Here +`√E_y = (m.op y).absoluteValue` and `|y⟩⟨y| = (quditBasis y).toState.op`. -/ +theorem holevoMeasurementChannel_apply_tmul (m : Measurement (Fin r) Q) (σ : State Q) : + (holevoMeasurementChannel m (σ ⊗ (quditBasis (0 : Fin r)).toState)).op + = ∑ y, TensorProduct.mapL + ((m.op y).absoluteValue.comp (σ.op.comp (m.op y).absoluteValue)) + ((quditBasis y).toState.op) := by + have hks := ContinuousLinearMap.krausSumₗ_apply (holevoMeasurementKraus m) + (TensorProduct.mapL σ.op (quditBasis (0 : Fin r)).toState.op) + rw [holevoMeasurementChannel_op, State.tmul_op, hks] + refine Finset.sum_congr rfl (fun y _ => ?_) + have h := TensorProduct.mapL_comp_self (m.op y).absoluteValue (periodShift r y).op σ.op + ((quditBasis (0 : Fin r)).toState.op) + rw [ContinuousLinearMap.adjoint_absoluteValue, periodShift_op_conj_quditBasisZero] at h + rw [holevoMeasurementKraus] + exact h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HolevoMeasurementDilation.lean b/LeanPool/AxQM/Postulates/API/HolevoMeasurementDilation.lean new file mode 100644 index 0000000000..a58a8e8845 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HolevoMeasurementDilation.lean @@ -0,0 +1,145 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementChannel +public import LeanPool.AxQM.Postulates.API.MeasurementModel + +/-! +# AxQM.Postulates.API — the Holevo measurement operation as a dilated channel + +The **Stinespring / environment representation** of the Holevo measurement operation `𝓔` +(`holevoMeasurementChannel`, Nielsen & Chuang Exercise 12.2, Eq. (12.8)). The apparatus operation +`𝓔` is given as a Kraus channel `ρ ↦ ∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†` on `Q ⊗ M` +(`M = qudit r` the apparatus register); this file exhibits it in the **dilated form** + + `𝓔(ρ) = Tr_C (U (ρ ⊗ |0⟩⟨0|_C) U†)` + +of Nielsen & Chuang §8.2.3: append a fresh pure ancilla `C = qudit r` in the standard state `|0⟩`, +evolve by the joint unitary `U`, then discard `C`. This is precisely the form the χ-monotonicity +Part (2) of the alternate Holevo-bound proof (`State.holevoChi_dilatedChannel_le`) quantifies over — +so this bridge is what lets Part (2) act on the apparatus operation in the final assembly of the +Holevo bound (N&C Problem 12.1(3)). + +* `holevoMeasurementChannel_eq_reducedLeft_evolve` — the bridge itself: + `𝓔(ρ) = (U.evolve (ρ ⊗ |0⟩⟨0|)).reducedLeft`, where `U = measurementModelEvolution` is the + Stinespring dilation (N&C Exercise 8.9's joint unitary) assembled from the operation elements + `holevoMeasurementKraus m` — a genuine unitary because they satisfy the completeness relation + `holevoMeasurementKraus_completeness`. The right-hand side is definitionally `dilatedChannel`, so + the equation presents `𝓔` in Part (2)'s dilated form. + +The proof reuses the operator-sum recovery +`LinearMap.partialTraceRight_conj_tmulRightVec_krausDilation`: the joint unitary intertwines the +standard-ancilla embedding with the Stinespring dilation `V₀ = krausDilation` +(`measurementModelEvolution_op_tmul`, the `hUV` step below), so discarding the environment from the +conjugation of `ρ ⊗ |0⟩⟨0|` returns exactly the operator sum `∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†` — +the `.op` of `𝓔(ρ)` (`holevoMeasurementChannel_op`). + +The statement concerns `measurementModelEvolution` (whose argument is an `OrthonormalBasis` of +`(qudit r).space`) and the operation elements `holevoMeasurementKraus`; compare +`holevoMeasurementChannel` and the measurement model it dilates. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {Q : QSystem} {r : ℕ} [NeZero r] + +/-- **The Holevo measurement operation `𝓔` in dilated form** (Nielsen & Chuang §8.2.3, the +environment/Stinespring representation of Exercise 12.2's operation). For every state `ρ` on the +system–apparatus composite `Q ⊗ M` (`M = qudit r`), + + `𝓔(ρ) = Tr_C (U (ρ ⊗ |0⟩⟨0|_C) U†) = (U.evolve (ρ ⊗ |0⟩⟨0|)).reducedLeft`, + +where `C = qudit r` is a fresh pure environment in the standard state `|0⟩` and +`U = measurementModelEvolution (quditOrthonormalBasis r) _ (holevoMeasurementKraus m) _` is the +joint unitary (N&C Exercise 8.9) built from the operation elements `√E_y ⊗ U_y`, which satisfy the +completeness relation `holevoMeasurementKraus_completeness` and so define a genuine unitary. The +right-hand side is definitionally `State.dilatedChannel ρ U ⟨|0⟩⟩`, so this exhibits `𝓔` in the +form Part (2) `State.holevoChi_dilatedChannel_le` quantifies over. + +Proof: on the standard-ancilla slice the joint unitary is the Stinespring dilation, +`U.op ∘ tmulRightVec |0⟩ = krausDilation (quditOrthonormalBasis r) (√E_· ⊗ U_·)` (`hUV`, from +`measurementModelEvolution_op_tmul`); the operator-sum recovery +`LinearMap.partialTraceRight_conj_tmulRightVec_krausDilation` then rewrites the discarded +conjugation `Tr_C (U (ρ ⊗ |0⟩⟨0|) U†)` as `∑_y (√E_y ⊗ U_y) ρ (√E_y ⊗ U_y)†`, which is the `.op` of +`𝓔(ρ)` (`holevoMeasurementChannel_op`, `krausSumₗ`). The partial trace is switched from the standard +basis of the reduced marginal to `quditOrthonormalBasis r` (`partialTraceRight_eq_of_basis`, partial +trace being basis-independent) to match the dilation's basis. -/ +theorem holevoMeasurementChannel_eq_reducedLeft_evolve (m : Measurement (Fin r) Q) + (ρ : State (Q ⊗ qudit r)) : + holevoMeasurementChannel m ρ + = ((measurementModelEvolution (quditOrthonormalBasis r) + (quditBasis (0 : Fin r)).normalized (holevoMeasurementKraus m) + (holevoMeasurementKraus_completeness m)).evolve + (ρ.tmul (quditBasis (0 : Fin r)).toState)).reducedLeft := by + set b := quditOrthonormalBasis r with hb + set E := holevoMeasurementKraus m with hE_def + set U := measurementModelEvolution b (quditBasis (0 : Fin r)).normalized E + (holevoMeasurementKraus_completeness m) with hU_def + -- Pin one representative `U₀` of the unitary's underlying linear map. + set U₀ : (Q ⊗ qudit r).space ⊗[ℂ] (qudit r).space →ₗ[ℂ] + (Q ⊗ qudit r).space ⊗[ℂ] (qudit r).space := U.op.toLinearMap with hU₀ + -- The joint unitary intertwines the standard-ancilla embedding with the Stinespring dilation. + have hUV : U₀ ∘ₗ LinearMap.tmulRightVec (quditBasis (0 : Fin r)).vec + = LinearMap.krausDilation b (fun y => (E y).toLinearMap) := by + rw [hU₀] + refine LinearMap.ext fun ψ => ?_ + change U.op (ψ ⊗ₜ[ℂ] (quditBasis (0 : Fin r)).vec) + = LinearMap.krausDilation b (fun y => (E y).toLinearMap) ψ + rw [hU_def, measurementModelEvolution_op_tmul, LinearMap.krausDilation_apply] + simp only [ContinuousLinearMap.coe_coe] + rfl + -- The basis switch (`stdOrthonormalBasis` → `b`) on `.reducedLeft.op`, done abstractly (before + -- specializing to the concrete `U.evolve (...)`), so `partialTraceRight_eq_of_basis`'s `rw` + -- only ever sees the plain generic-tensor argument `ρ'.op.toLinearMap`, never the composite + -- `U.op ∘SL ⋯ ∘SL adjoint U.op` expression, which crosses the `QSystem.compose` instance diamond. + have hswitch : ∀ ρ' : State ((Q ⊗ qudit r) ⊗ qudit r), + ρ'.reducedLeft.op = (LinearMap.partialTraceRight b + (ρ'.op.toLinearMap : (Q ⊗ qudit r).space ⊗[ℂ] (qudit r).space →ₗ[ℂ] + (Q ⊗ qudit r).space ⊗[ℂ] (qudit r).space)).toContinuousLinearMap := by + intro ρ' + rw [State.reducedLeft_op] + exact congrArg LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight_eq_of_basis (stdOrthonormalBasis ℂ (qudit r).space) b + ρ'.op.toLinearMap) + refine State.ext ?_ + rw [holevoMeasurementChannel_op, hswitch, Evolution.evolve_op, State.tmul_op, + PureState.toState_op] + refine ContinuousLinearMap.coe_injective ?_ + rw [LinearMap.coe_toContinuousLinearMap] + have hfork := LinearMap.partialTraceRight_conj_tmulRightVec_krausDilation b + (fun y => (E y).toLinearMap) U₀ hUV ρ.op.toLinearMap + -- Rewrite the conjugation of `ρ ⊗ |0⟩⟨0|` into the lemma's shape, apply it, and match the + -- resulting operator sum with the Kraus sum defining `𝓔`. The final `congr 1` bridges the + -- `QSystem.compose` instance diamond between the bundled `U.op ∘SL ⋯ ∘SL adjoint U.op` and the + -- generic `U₀ ∘ₗ TensorProduct.map ⋯ ∘ₗ adjoint U₀` (`rw`'s motive-building can't cross it, but + -- `congr`'s own defeq check can). + rw [ContinuousLinearMap.krausSumₗ_apply] + simp only [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_comp, + ← ContinuousLinearMap.adjoint_toLinearMap] + rw [← hfork] + congr 1 + refine LinearMap.ext fun ψ => ?_ + rw [hU₀] + change U.op (TensorProduct.map ρ.op.toLinearMap + (((rankOne ℂ) (quditBasis 0).vec) (quditBasis 0).vec).toLinearMap (adjoint U.op ψ)) + = U.op (TensorProduct.mapL ρ.op (((rankOne ℂ) (quditBasis 0).vec) (quditBasis 0).vec) + (adjoint U.op ψ)) + exact congrArg U.op + (TensorProduct.mapL_apply ρ.op (((rankOne ℂ) (quditBasis 0).vec) (quditBasis 0).vec) + (adjoint U.op ψ)).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/HolevoMeasurementMarginal.lean b/LeanPool/AxQM/Postulates/API/HolevoMeasurementMarginal.lean new file mode 100644 index 0000000000..adc66f8d78 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/HolevoMeasurementMarginal.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.HolevoMeasurementChannel +public import LeanPool.AxQM.Postulates.API.Mixture + +/-! +# AxQM.Postulates.API — the outcome marginal of the Holevo measurement operation + +The **apparatus outcome marginal** of the Holevo measurement operation `𝓔` (Nielsen & Chuang, +Exercise 12.2 / Eq. (12.8), `AxQM.holevoMeasurementChannel`): after `𝓔` measures the +system `Q` with POVM `{E_y}` and *records* the outcome in the apparatus register `M = qudit r`, +**discarding `Q`** leaves the classical diagonal state whose weights are the Born probabilities. + +For a measurement `m : Measurement (Fin r) Q` and a system state `σ`, writing +`𝓔(σ ⊗ |0⟩⟨0|) = ∑_y √E_y σ √E_y ⊗ |y⟩⟨y|` (Eq. (12.8)), the `M`-marginal is + + `Tr_Q 𝓔(σ ⊗ |0⟩⟨0|) = ∑_y Tr(E_y σ) |y⟩⟨y| = ∑_y p(y|σ) |y⟩⟨y|`, + +the Born distribution `p(y|σ) = m.bornProb σ y` written as a diagonal state on the outcome register. +This is exactly the "measure and record the outcome, forget the post-measurement state" content of +the outcome channel `Measurement.measState` (`Core/MeasurementChannel.lean`), realised here as the +partial trace over `Q` of the concrete apparatus operation `𝓔`. + +## Role + +This is the **"discard the measured system `Q`" step** of the (Nielsen–Chuang, Theorem 12.1) Holevo +bound proof along the χ-monotonicity / apparatus route (N&C Problem 12.1). That proof runs +`H(X:Y) = χ_M ≤ χ`, where `χ_M` is the Holevo χ of the *measured* ensemble +`{pₓ, Tr_Q 𝓔(ρₓ ⊗ |0⟩⟨0|)}` and `χ` that of `{pₓ, ρₓ}`: the inequality `χ_M ≤ χ` is obtained by +tracing `Q` out of `𝓔(ρₓ ⊗ |0⟩⟨0|)` (Holevo χ monotonicity under discarding, N&C Problem 12.1(1)) +after `χ(𝓔∘·) ≤ χ` (monotonicity under the operation `𝓔`, N&C Problem 12.1(2)). This lemma +identifies that traced-out `M`-marginal with the diagonal Born state, connecting the concrete +apparatus `𝓔` (Exercise 12.2) to the outcome distribution used in the Holevo χ. + +## Proof + +The statement involves `holevoMeasurementChannel` (in +`AxQM/Postulates/API/HolevoMeasurementChannel.lean`), `State.reducedRight`, `State.mix`, +`Measurement.bornProb`, `quditBasis` and `PureState.toState`. +In the proof, `𝓔(σ ⊗ |0⟩⟨0|)`'s operator is the diagonal operator sum +(12.8); the partial trace over `Q` distributes over the sum and (`partialTraceLeft_tensorMap`) +reads off the block traces `Tr(√E_y σ √E_y) = Tr(E_y σ) = p(y|σ)`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {Q : QSystem} {r : ℕ} + +/-- **The trace of a POVM block equals the Born probability.** For a measurement `m` and state `σ`, +the trace of the outcome-`y` block `√E_y σ √E_y` of the apparatus operation (with `√E_y = |M_y|` the +absolute value of the measurement operator) is the Born probability of `y`: + +`Tr(√E_y σ √E_y) = Tr(E_y σ) = m.bornProb σ y`. + +By trace cyclicity `Tr(|M_y| σ |M_y|) = Tr(|M_y| |M_y| σ) = Tr(M_y† M_y σ)` (`absoluteValue_sq`) and +`m.bornProb σ y = Re Tr(M_y σ M_y†) = Re Tr(M_y† M_y σ)` (`bornProb_eq_re_trace_postOp` + trace +cyclicity); both are the same real number `Tr(E_y σ)`, which is genuinely real because +`√E_y σ √E_y` is a positive operator (`trace_postOp_eq_ofReal_re`). -/ +theorem trace_absoluteValue_conj_eq_bornProb (m : Measurement (Fin r) Q) (σ : State Q) (y : Fin r) : + LinearMap.trace ℂ Q.space + (((m.op y).absoluteValue.comp (σ.op.comp (m.op y).absoluteValue)) : Q.space →ₗ[ℂ] Q.space) + = (m.bornProb σ y : ℂ) := by + have habs : (m.op y).absoluteValue.comp (σ.op.comp (m.op y).absoluteValue) + = ContinuousLinearMap.postOp (fun i => (m.op i).absoluteValue) σ.op y := by + rw [ContinuousLinearMap.postOp, ContinuousLinearMap.adjoint_absoluteValue, + ← ContinuousLinearMap.comp_assoc] + rw [habs, ContinuousLinearMap.trace_postOp_eq_ofReal_re _ σ.isPositive_op y, + Measurement.bornProb_eq_re_trace_postOp] + congr 2 + rw [ContinuousLinearMap.trace_postOp, ContinuousLinearMap.trace_postOp, + ContinuousLinearMap.adjoint_absoluteValue, ← ContinuousLinearMap.comp_assoc, + ContinuousLinearMap.absoluteValue_sq, ContinuousLinearMap.comp_assoc] + +variable [NeZero r] + +/-- **The apparatus outcome marginal of the Holevo measurement operation is the diagonal Born +state.** Tracing out the measured system `Q` from `𝓔(σ ⊗ |0⟩⟨0|)` (Nielsen & Chuang, Exercise 12.2 / +Eq. (12.8)) yields the classical diagonal state whose weight on `|y⟩⟨y|` is the Born probability of +outcome `y`: + +`Tr_Q 𝓔(σ ⊗ |0⟩⟨0|) = ∑_y m.bornProb σ y • |y⟩⟨y|`. + +This is the "discard the measured system, keep the recorded outcome" step of the Holevo bound +(Theorem 12.1) via the apparatus route: the traced-out marginal is exactly the measure-and-record +outcome distribution (`Measurement.measState`). The proof reads `𝓔(σ ⊗ |0⟩⟨0|)`'s operator as the +diagonal operator sum `∑_y √E_y σ √E_y ⊗ |y⟩⟨y|` (`holevoMeasurementChannel_apply_tmul`), pushes the +partial trace over `Q` through the sum, and evaluates each block by `partialTraceLeft_tensorMap` +with `Tr(√E_y σ √E_y) = m.bornProb σ y` (`trace_absoluteValue_conj_eq_bornProb`). -/ +theorem holevoMeasurementChannel_reducedRight (m : Measurement (Fin r) Q) (σ : State Q) : + (holevoMeasurementChannel m (σ ⊗ (quditBasis (0 : Fin r)).toState)).reducedRight + = State.mix (m.bornProb σ) (m.bornProb_nonneg σ) (m.sum_bornProb_eq_one σ) + (fun y => (quditBasis y).toState) := by + apply State.ext + rw [State.reducedRight_op, holevoMeasurementChannel_apply_tmul, State.mix_op, + ContinuousLinearMap.toLinearMap_sum, ← LinearMap.partialTraceLeftLM_apply, map_sum, map_sum] + refine Finset.sum_congr rfl fun y _ => ?_ + rw [LinearMap.partialTraceLeftLM_apply, TensorProduct.toLinearMap_mapL, + LinearMap.partialTraceLeft_tensorMap, map_smul, + ContinuousLinearMap.toLinearMap_toContinuousLinearMap, trace_absoluteValue_conj_eq_bornProb] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/InverseQuantumFourierTransform.lean b/LeanPool/AxQM/Postulates/API/InverseQuantumFourierTransform.lean new file mode 100644 index 0000000000..2fae442032 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/InverseQuantumFourierTransform.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# AxQM.Postulates.API — the inverse quantum Fourier transform as a unitary evolution + +The inverse transform for Nielsen & Chuang **Exercise 5.5** ("give a quantum circuit to +perform the inverse quantum Fourier transform"). The quantum Fourier transform `F` is realized as a +unitary `Evolution` (`qftEvolution d`, built for Problem 5.1); its inverse `F⁻¹` is a unitary +transformation too, so it is itself an implementable circuit — the *adjoint* (inverse) gate `F†`. +This file packages `F⁻¹` and computes its action, mirroring the QFT development. + +## What is formalised + +* `qftInverseEvolution d` — the **inverse QFT as a unitary `Evolution (qudit d)`**, defined as the + adjoint `(qftEvolution d).adjoint = F†`. Because `Evolution.adjoint` is again a unitary + `Evolution`, the very existence of this term is the exercise's answer: the inverse transform *is* + a legitimate quantum circuit, the adjoint of the QFT circuit (which, gate for gate, is the QFT + circuit run in reverse with each gate daggered — the general reversal principle + `Evolution.adjoint_comp`). +* `qftInverseEvolution_op_eq` — its operator is `toEuclideanCLM` of the **conjugate-transpose** QFT + matrix, `F† = toEuclideanCLM (qftMatrix d)ᴴ`, since `Matrix.toEuclideanCLM` is a star-algebra + equivalence (adjoint of operator ↔ conjugate transpose of matrix). +* `qftInverseEvolution_op_apply_quditBasis` — the **inverse-transform action** + `F⁻¹|k⟩ = ∑ⱼ (1/√d)·e^{−2πijk/d} |j⟩`: the inverse discrete Fourier transform, the conjugate of + the forward action `qftEvolution_op_apply_quditBasis`. +* `qftInverseFourierImage d k` — that image state `∑ⱼ (1/√d)·e^{−2πijk/d} |j⟩` as a `PureState` + (normalized, being the image of a unit vector under the unitary `F†`). +* `qftInverseEvolution_adjoint` — inverting the inverse-QFT circuit recovers the QFT, + `(qftInverseEvolution d)† = qftEvolution d` (from the adjoint involution). + +The pure-state action, the two-sided inversion `F⁻¹ ∘ F = F ∘ F⁻¹ = id`, and the operational +round-trip `F⁻¹(F|ψ⟩) = |ψ⟩` are the statements of Nielsen & Chuang Exercise 5.5 in +[upstream `AxQM/NC/Ch5/Exercise5_5.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Exercise5_5.lean). + +## Design notes + +* **Adjoint = conjugate transpose.** `Matrix.toEuclideanCLM` is a `StarAlgEquiv`, hence + star-preserving; the operator adjoint (`star`) of `toEuclideanCLM (qftMatrix d)` is therefore + `toEuclideanCLM` of the matrix `star`, i.e. the conjugate transpose `(qftMatrix d)ᴴ`. No + entrywise re-derivation of the inverse matrix is needed. The action is then the `j`-th column of + `(qftMatrix d)ᴴ` (`Matrix.toEuclideanCLM_apply_single`), whose entry + `((qftMatrix d)ᴴ)ⱼₖ = conj((qftMatrix d)ₖⱼ) = (1/√d)·e^{−2πijk/d}` is the forward entry + conjugated. +* **General `d`.** As with the forward transform, everything holds for every dimension `d ≥ 1`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +open AxQM.Concrete +open scoped Matrix + +/-- The **inverse quantum Fourier transform on `qudit d`** as a unitary `Evolution` +(Nielsen & Chuang Exercise 5.5), defined as the adjoint (inverse) gate of the QFT evolution: +`F⁻¹ = F† = (qftEvolution d).adjoint`. Since a unitary's adjoint is again unitary, this is a genuine +`Evolution` — an implementable quantum circuit — realizing the inverse transform. At the gate level +it is the QFT circuit run in reverse with each gate daggered (`Evolution.adjoint_comp`). -/ +def qftInverseEvolution (d : ℕ) [NeZero d] : Evolution (qudit d) := (qftEvolution d).adjoint + +/-- The underlying operator of `qftInverseEvolution d` is the Hilbert-space adjoint of the QFT +operator, `F† = adjoint (toEuclideanCLM (qftMatrix d))`. -/ +@[simp] +theorem qftInverseEvolution_op (d : ℕ) [NeZero d] : + (qftInverseEvolution d).op + = ContinuousLinearMap.adjoint + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) (qftMatrix d)) := rfl + +/-- The inverse QFT operator is `toEuclideanCLM` of the **conjugate-transpose** QFT matrix, +`F† = toEuclideanCLM (qftMatrix d)ᴴ`. Because `Matrix.toEuclideanCLM` is a star-algebra equivalence +(`star` on operators is the adjoint, `star` on matrices is the conjugate transpose), the adjoint of +`toEuclideanCLM (qftMatrix d)` is `toEuclideanCLM` of `star (qftMatrix d) = (qftMatrix d)ᴴ`. -/ +theorem qftInverseEvolution_op_eq (d : ℕ) [NeZero d] : + (qftInverseEvolution d).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) (qftMatrix d)ᴴ := by + rw [qftInverseEvolution_op, ← ContinuousLinearMap.star_eq_adjoint, ← map_star, + Matrix.star_eq_conjTranspose] + +/-- **Action of the inverse QFT on a computational-basis state, compact form:** +`F⁻¹|k⟩ = ∑ⱼ (Fᴴ)ⱼₖ |j⟩`, the `k`-th column of the conjugate-transpose matrix `(qftMatrix d)ᴴ`. +The `(quditBasis _).vec`-phrased instance of `Matrix.toEuclideanCLM_apply_single` at the matrix +`(qftMatrix d)ᴴ` (whose associated operator is `F†` by `qftInverseEvolution_op_eq`). -/ +theorem qftInverseEvolution_op_apply_quditBasis_matrix (d : ℕ) [NeZero d] (k : Fin d) : + (qftInverseEvolution d).op (quditBasis k).vec + = ∑ j : Fin d, ((qftMatrix d)ᴴ j k) • (quditBasis j).vec := by + rw [qftInverseEvolution_op_eq] + exact Matrix.toEuclideanCLM_apply_single (qftMatrix d)ᴴ k + +/-- **Action of the inverse QFT on a computational-basis state** (Nielsen & Chuang Exercise 5.5, the +inverse of eq. 5.2): `F⁻¹|k⟩ = ∑ⱼ (1/√d)·e^{−2πijk/d} |j⟩`. Each amplitude is the forward QFT +amplitude conjugated, `((qftMatrix d)ᴴ)ⱼₖ = (1/√d)·e^{−2πijk/d}` +(`Concrete.qftMatrix_conjTranspose_apply`). This makes the proof the exact mirror of the forward +`qftEvolution_op_apply_quditBasis`: rewrite the compact column form, then the `Concrete` entry. -/ +theorem qftInverseEvolution_op_apply_quditBasis (d : ℕ) [NeZero d] (k : Fin d) : + (qftInverseEvolution d).op (quditBasis k).vec + = ∑ j : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d))) + • (quditBasis j).vec := by + rw [qftInverseEvolution_op_apply_quditBasis_matrix] + refine Finset.sum_congr rfl (fun j _ => ?_) + rw [qftMatrix_conjTranspose_apply] + +/-- The **inverse quantum Fourier image state** `F⁻¹|k⟩ = ∑ⱼ (1/√d)·e^{−2πijk/d} |j⟩` of the +computational-basis state `|k⟩`, as a `PureState` of `qudit d` (Nielsen & Chuang Exercise 5.5). It +is normalized because it is the image `(qftInverseEvolution d).op |k⟩` of a unit vector under the +unitary `F†` (`Evolution.norm_op_apply`, `quditBasis` normalized). -/ +def qftInverseFourierImage (d : ℕ) [NeZero d] (k : Fin d) : PureState (qudit d) where + vec := ∑ j : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d))) • (quditBasis j).vec + normalized := by + rw [← qftInverseEvolution_op_apply_quditBasis d k, (qftInverseEvolution d).norm_op_apply] + exact (quditBasis k).normalized + +/-- The underlying vector of `qftInverseFourierImage d k` is the explicit inverse-Fourier +superposition `∑ⱼ (1/√d)·e^{−2πijk/d} |j⟩`. -/ +@[simp] +theorem qftInverseFourierImage_vec (d : ℕ) [NeZero d] (k : Fin d) : + (qftInverseFourierImage d k).vec + = ∑ j : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d))) + • (quditBasis j).vec := + rfl + +/-- **The QFT is recovered by inverting the inverse-QFT circuit:** +`(qftInverseEvolution d)† = qftEvolution d`. Since `qftInverseEvolution d = F†` and the adjoint is +an involution (`Evolution.adjoint_adjoint`), `F†† = F`. The two circuits are mutual inverses. -/ +theorem qftInverseEvolution_adjoint (d : ℕ) [NeZero d] : + (qftInverseEvolution d).adjoint = qftEvolution d := + Evolution.adjoint_adjoint (qftEvolution d) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/InvolutionPropagatorConjugation.lean b/LeanPool/AxQM/Postulates/API/InvolutionPropagatorConjugation.lean new file mode 100644 index 0000000000..b10927b09f --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/InvolutionPropagatorConjugation.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.ExponentialInvolution + +/-! +# AxQM.Postulates.API — Heisenberg conjugation under an involution-generated propagator + +Formulas for the **Heisenberg-evolved operator** `U(t)† A U(t)` when +the propagator `U(t) = exp(-iHt)` is generated by a Hamiltonian whose operator is a scalar times an +**involution**: `H.op = c • G` with `G² = 1` (and `G` self-adjoint). This is the algebraic engine +behind the NMR free-induction-decay computations of Nielsen & Chuang §7.7 (Exercise 7.37): the +coupling Hamiltonian `H = J Z₁Z₂` has `H.op = J • (Z ⊗ Z)`, with `Z ⊗ Z` an involution, and the +readout operators `X₁, Y₁, Z₂` either commute or anticommute with it. + +Writing `U(t).op = cos(ct) • 1 - i sin(ct) • G` (Nielsen & Chuang Exercise 4.2 / eq. 4.7, via +`NormedSpace.exp_smul_mul_I_of_mul_self_eq_one`) and its adjoint `cos(ct) • 1 + i sin(ct) • G`: + +* `Observable.propagator_op_of_op_eq_smul_involution` — `U(t).op = cos(ct) • 1 - (sin(ct) i) • G`. +* `Observable.adjoint_propagator_op_of_op_eq_smul_involution` — the adjoint, + `cos(ct) • 1 + (sin(ct) i) • G`. +* `Observable.propagator_conj_op_commute` — if `A` **commutes** with `G` then it is fixed by the + Heisenberg evolution: `U(t)† A U(t) = A`. +* `Observable.propagator_conj_op_anticomm` — if `A` **anticommutes** with `G` then + `U(t)† A U(t) = cos(2ct) • A - (sin(2ct) i) • (A G)`, the frequency-doubled rotation of `A` into + `A G` characteristic of J-coupled evolution. + +## Design + +* **Proof.** No matrix arithmetic and no `cos`/`sin` *values*. `U(t).op` and its adjoint are put in + the `cos • 1 ± i sin • G` normal form once; then the conjugation is a short operator-algebra + computation via the span-of-`{1, G}` product law + `NormedSpace.smul_one_add_smul_mul_of_mul_self_eq_one`. For the anticommuting case the key step is + `A · U(t).op = U(t).op† · A` (`A` slides through the involution-function `U`, flipping the sign of + the `G`-part), whence `U(t)† A U(t) = (U(t)†)² A` and `(U(t)†)²` is the double-angle exponential + `cos(2ct) • 1 + (sin(2ct) i) • G`. The double-angle identities are `Real.cos_two_mul` / + `Real.sin_two_mul`, and `Complex.I_mul_I` turns `(sin(ct) i)²` into `-sin²(ct)`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The propagator `U(t) = exp(-iHt)` of a Hamiltonian with `H.op = c • G` for an involution +`G` (`G² = 1`) has operator `U(t).op = cos(ct) • 1 - (sin(ct) i) • G` — Nielsen & Chuang eq. (4.7) +applied to `G` at angle `-(ct)`. -/ +theorem Observable.propagator_op_of_op_eq_smul_involution (H : Observable S) {c : ℝ} + {G : S.space →L[ℂ] S.space} (hop : H.op = (c : ℂ) • G) (hG : G * G = 1) (t : ℝ) : + (H.propagator 1 0 t).op + = (Real.cos (c * t) : ℂ) • (1 : S.space →L[ℂ] S.space) + - ((Real.sin (c * t) : ℂ) * Complex.I) • G := by + rw [Observable.propagator_op, hop, smul_smul, + show (-Complex.I * ↑(t - 0) / ↑(1 : ℝ)) * (c : ℂ) = ((-(c * t) : ℝ) : ℂ) * Complex.I by + push_cast; ring, + NormedSpace.exp_smul_mul_I_of_mul_self_eq_one hG (-(c * t)), Real.cos_neg, Real.sin_neg] + push_cast + module + +/-- The adjoint of the propagator operator of `H.op = c • G` (`G` a self-adjoint involution): +`U(t).op† = cos(ct) • 1 + (sin(ct) i) • G`, the complex conjugate of the `cos • 1 - i sin • G` +normal form. -/ +theorem Observable.adjoint_propagator_op_of_op_eq_smul_involution (H : Observable S) {c : ℝ} + {G : S.space →L[ℂ] S.space} (hop : H.op = (c : ℂ) • G) (hG : G * G = 1) (hGsa : IsSelfAdjoint G) + (t : ℝ) : + ContinuousLinearMap.adjoint (H.propagator 1 0 t).op + = (Real.cos (c * t) : ℂ) • (1 : S.space →L[ℂ] S.space) + + ((Real.sin (c * t) : ℂ) * Complex.I) • G := by + have h1 : star ((Real.cos (c * t) : ℂ)) = (Real.cos (c * t) : ℂ) := Complex.conj_ofReal _ + have h2 : star ((Real.sin (c * t) : ℂ) * Complex.I) = -((Real.sin (c * t) : ℂ) * Complex.I) := by + rw [star_mul, show star Complex.I = -Complex.I from Complex.conj_I, + show star ((Real.sin (c * t) : ℂ)) = (Real.sin (c * t) : ℂ) from Complex.conj_ofReal _] + ring + rw [← ContinuousLinearMap.star_eq_adjoint, + H.propagator_op_of_op_eq_smul_involution hop hG t, star_sub, star_smul, star_smul, star_one, + hGsa.star_eq, h1, h2] + module + +/-- **Heisenberg conjugation, commuting case.** If the observable/operator `A` commutes with the +involution `G` generating `H` (`H.op = c • G`, `G² = 1`), then `A` is invariant under the Heisenberg +evolution generated by `H`: `U(t)† A U(t) = A`, because `A` commutes with the propagator (a function +of `G`) and `U(t)† U(t) = 1`. -/ +theorem Observable.propagator_conj_op_commute (H : Observable S) {c : ℝ} + {G A : S.space →L[ℂ] S.space} (hop : H.op = (c : ℂ) • G) (hG : G * G = 1) + (hcomm : A * G = G * A) (t : ℝ) : + ContinuousLinearMap.adjoint (H.propagator 1 0 t).op * A * (H.propagator 1 0 t).op = A := by + have hQ := H.propagator_op_of_op_eq_smul_involution hop hG t + -- `A · U = U · A`: A commutes with the involution-function U. + have hAU : A * (H.propagator 1 0 t).op = (H.propagator 1 0 t).op * A := by + rw [hQ] + simp only [mul_sub, sub_mul, mul_smul_comm, smul_mul_assoc, mul_one, one_mul, hcomm] + -- `U† · U = 1`: the propagator is unitary (`Observable.propagator_op_mem_unitary`), so the + -- adjoint (= `star`) is a left inverse. + have hPQ : ContinuousLinearMap.adjoint (H.propagator 1 0 t).op * (H.propagator 1 0 t).op = 1 := by + have hu := H.propagator_op_mem_unitary 1 0 t + rw [← H.propagator_op 1 0 t] at hu + rw [← ContinuousLinearMap.star_eq_adjoint] + exact (Unitary.mem_iff.mp hu).1 + rw [mul_assoc, hAU, ← mul_assoc, hPQ, one_mul] + +/-- **Heisenberg conjugation, anticommuting case.** If the observable/operator `A` anticommutes +with the involution `G` generating `H` (`H.op = c • G`, `G² = 1`), then the Heisenberg evolution +generated by `H` rotates `A` into `A G` at twice the coupling frequency: +`U(t)† A U(t) = cos(2ct) • A - (sin(2ct) i) • (A G)`. This is the operator identity behind J-coupled +NMR precession: `X₁` under `H = J Z₁Z₂` (so `A·G = X₁·Z₁Z₂ = (X Z)⊗Z = -i·Y₁Z₂`) Heisenberg-evolves +to `cos(2Jt) X₁ - sin(2Jt) Y₁Z₂`. -/ +theorem Observable.propagator_conj_op_anticomm (H : Observable S) {c : ℝ} + {G A : S.space →L[ℂ] S.space} (hop : H.op = (c : ℂ) • G) (hG : G * G = 1) + (hGsa : IsSelfAdjoint G) (hanti : A * G = -(G * A)) (t : ℝ) : + ContinuousLinearMap.adjoint (H.propagator 1 0 t).op * A * (H.propagator 1 0 t).op + = (Real.cos (2 * c * t) : ℂ) • A - ((Real.sin (2 * c * t) : ℂ) * Complex.I) • (A * G) := by + have hQ := H.propagator_op_of_op_eq_smul_involution hop hG t + have hP := H.adjoint_propagator_op_of_op_eq_smul_involution hop hG hGsa t + have hGA : G * A = -(A * G) := by rw [hanti, neg_neg] + -- `A · U = U† · A`: A slides through the involution-function U, flipping the sign of the G-part. + have hAU : A * (H.propagator 1 0 t).op + = ContinuousLinearMap.adjoint (H.propagator 1 0 t).op * A := by + rw [hP, hQ] + simp only [mul_sub, add_mul, mul_smul_comm, smul_mul_assoc, mul_one, one_mul, hGA, smul_neg] + module + -- `(U†)² = cos(2ct) • 1 + (sin(2ct) i) • G` — the double-angle exponential. + have hc2 : (Real.cos (c * t) : ℂ) * (Real.cos (c * t) : ℂ) + + ((Real.sin (c * t) : ℂ) * Complex.I) * ((Real.sin (c * t) : ℂ) * Complex.I) + = (Real.cos (2 * c * t) : ℂ) := by + have hR : Real.cos (2 * c * t) = Real.cos (c * t) ^ 2 - Real.sin (c * t) ^ 2 := by + rw [show 2 * c * t = 2 * (c * t) by ring, Real.cos_two_mul] + nlinarith [Real.sin_sq_add_cos_sq (c * t)] + rw [show ((Real.sin (c * t) : ℂ) * Complex.I) * ((Real.sin (c * t) : ℂ) * Complex.I) + = (Real.sin (c * t) : ℂ) ^ 2 * (Complex.I * Complex.I) by ring, Complex.I_mul_I, hR] + push_cast; ring + have hs2 : (Real.cos (c * t) : ℂ) * ((Real.sin (c * t) : ℂ) * Complex.I) + + ((Real.sin (c * t) : ℂ) * Complex.I) * (Real.cos (c * t) : ℂ) + = (Real.sin (2 * c * t) : ℂ) * Complex.I := by + have hR : Real.sin (2 * c * t) = 2 * Real.sin (c * t) * Real.cos (c * t) := by + rw [show 2 * c * t = 2 * (c * t) by ring, Real.sin_two_mul] + rw [hR]; push_cast; ring + have hPsq : ContinuousLinearMap.adjoint (H.propagator 1 0 t).op + * ContinuousLinearMap.adjoint (H.propagator 1 0 t).op + = (Real.cos (2 * c * t) : ℂ) • (1 : S.space →L[ℂ] S.space) + + ((Real.sin (2 * c * t) : ℂ) * Complex.I) • G := by + rw [hP, NormedSpace.smul_one_add_smul_mul_of_mul_self_eq_one hG (Real.cos (c * t) : ℂ) + ((Real.sin (c * t) : ℂ) * Complex.I) (Real.cos (c * t) : ℂ) + ((Real.sin (c * t) : ℂ) * Complex.I), hc2, hs2] + rw [mul_assoc, hAU, ← mul_assoc, hPsq, add_mul, smul_mul_assoc, smul_mul_assoc, one_mul, hGA, + smul_neg, ← sub_eq_add_neg] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/InvolutiveObservable.lean b/LeanPool/AxQM/Postulates/API/InvolutiveObservable.lean new file mode 100644 index 0000000000..c4b7b63b44 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/InvolutiveObservable.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTrotter +public import LeanPool.AxQM.Postulates.API.Eigenstate +public import LeanPool.AxQM.Concrete.PauliStringStdInvolution +public import LeanPool.AxQM.Postulates.API.InvolutionPropagatorConjugation + +/-! +# AxQM.Postulates.API — an involutive observable is a controllable unitary + +The bridge that turns an **involutive +observable** — a self-adjoint operator `A` with `A² = I`, i.e. a Hermitian operator with eigenvalues +`±1` — into an `Evolution` (a unitary), so it can be *controlled*. This is exactly the promotion +Nielsen & Chuang invoke for Figure 10.13: the measurement circuit `(H ⊗ 1) · C(U) · (H ⊗ 1)` needs +its measured operator as a controllable unitary `U`, and "`M` is an arbitrary Hermitian operator +with eigenvalues `±1`" — products of Pauli operators included. The stabilizer syndrome circuits of +§10.5.8 (Exercise 10.60) feed each stabilizer generator through this bridge. + +## What is provided + +* `Observable.toEvolution` — the bridge: from `A : Observable S` and a proof `A.op * A.op = 1`, + the `Evolution S` with operator `A.op`. Unitarity is immediate: `A` self-adjoint means + `star A.op = A.op`, so `star A.op * A.op = A.op * A.op = 1` and likewise on the other side. +* `Observable.toEvolution_op` — its operator is `A.op` (definitional; a `simp` lemma). +* `Observable.toEvolution_hasEigenstate` — an eigenstate of the observable `A` (real eigenvalue + `μ`) is an eigenstate of `A.toEvolution` (as the complex eigenvalue `μ`): the eigenvalue equation + is the same, `A.op ψ = μ ψ`. +* `pauliStringHamiltonian_op_mul_self` — the honest (phase `+1`) Pauli-string observable + `pauliStringHamiltonian g 1` is an involution: `(P_g)² = I`, from the matrix fact + `Concrete.pauliStringStd_mul_self` through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`. +-/ + +@[expose] public section + +open scoped Matrix + +namespace AxQM + +variable {S : QSystem} + +/-- **An involutive observable is a unitary evolution.** Given `A : Observable S` with `A² = I` +(`hA : A.op * A.op = 1`), the operator `A.op` is unitary — it is self-adjoint (Postulate 2), so +`star A.op = A.op` and `star A.op * A.op = A.op * A.op = 1`, and symmetrically `A.op * star A.op = +1`. Hence `A` promotes to an `Evolution` with the same operator. This is the "`M` is Hermitian with +eigenvalues `±1`, so `C(M)` makes sense" step of the Figure-10.13 operator-measurement circuit. -/ +def Observable.toEvolution (A : Observable S) (hA : A.op * A.op = 1) : Evolution S where + op := A.op + unitary := by + rw [Unitary.mem_iff] + have hsa : star A.op = A.op := A.selfAdjoint + rw [hsa] + exact ⟨hA, hA⟩ + +@[simp] +theorem Observable.toEvolution_op (A : Observable S) (hA : A.op * A.op = 1) : + (A.toEvolution hA).op = A.op := rfl + +/-- **Eigenstates transport across `toEvolution`.** If `ψ` is an eigenstate of the observable `A` +with (real) eigenvalue `μ`, it is an eigenstate of the unitary `A.toEvolution hA` with (complex) +eigenvalue `μ`: both are the single equation `A.op ψ = μ ψ`. Since `A² = I`, the possible values of +`μ` are `±1`, matching a unitary's unit-circle spectrum. -/ +theorem Observable.toEvolution_hasEigenstate {A : Observable S} (hA : A.op * A.op = 1) {μ : ℝ} + {ψ : PureState S} (h : A.HasEigenstate μ ψ) : (A.toEvolution hA).HasEigenstate (μ : ℂ) ψ := h + +/-- **An honest Pauli-string observable is an involution**: `(P_g)² = I` for +`P_g = pauliStringHamiltonian g 1`. Its operator is `Matrix.toEuclideanCLM (pauliStringStd g)`, and +that `⋆`-algebra isomorphism is multiplicative, so the square is +`Matrix.toEuclideanCLM (pauliStringStd g · pauliStringStd g) = Matrix.toEuclideanCLM I = I` by +`Concrete.pauliStringStd_mul_self`. -/ +theorem pauliStringHamiltonian_op_mul_self {n : ℕ} (g : Fin n → Fin 4) : + (pauliStringHamiltonian g 1).op * (pauliStringHamiltonian g 1).op = 1 := by + unfold pauliStringHamiltonian + simp only [Complex.ofReal_one, one_smul] + -- `erw` bridges the definitional coercion between `(qudit (2^n)).space` and `EuclideanSpace ℂ _`. + erw [← map_mul Matrix.toEuclideanCLM, Concrete.pauliStringStd_mul_self] + exact map_one Matrix.toEuclideanCLM + +/-- **The closed form of a Pauli-string Trotter summand (Nielsen & Chuang, Problem 4.3(3)).** For a +Pauli string `g : Fin n → Fin 4`, a real coefficient `c` and a real time `t`, the unit-`ℏ` +propagator of the Pauli-string Hamiltonian `c · g` is the explicit rotation +`exp(-i c t g) = cos(c t) · I - i sin(c t) · g`, +where `g = (pauliStringHamiltonian g 1).op` is the (involutive) unit-coefficient Pauli-string +operator. This is the concrete operator that Problem 4.3(3) asks to implement with `O(n)` one- and +two-qubit gates for `c = h_g`, `t = Δ = 1/k` — a genuine rotation whose axis is the Pauli string `g` +(`g² = I`, so the exponent's involution formula collapses the exponential to `cos - i sin`). + +It is the direct specialisation of `Observable.propagator_op_of_op_eq_smul_involution` (the general +`H.op = c • G`, `G² = I` ⟹ propagator `= cos(ct)·1 − (sin(ct)·i)·G` law) at +`H = pauliStringHamiltonian g c`, `G = (pauliStringHamiltonian g 1).op`: the scalar factorisation +`H.op = c • G` is `pauliStringHamiltonian_op` (with `↑(1:ℝ) • G = G`), and the involution `G² = I` +is `pauliStringHamiltonian_op_mul_self`. -/ +theorem pauliStringHamiltonian_propagator_op {n : ℕ} (g : Fin n → Fin 4) (c t : ℝ) : + ((pauliStringHamiltonian g c).propagator 1 0 t).op + = (Real.cos (c * t) : ℂ) • 1 + - ((Real.sin (c * t) : ℂ) * Complex.I) • (pauliStringHamiltonian g 1).op := by + refine (pauliStringHamiltonian g c).propagator_op_of_op_eq_smul_involution ?_ + (pauliStringHamiltonian_op_mul_self g) t + rw [pauliStringHamiltonian_op g 1, Complex.ofReal_one, one_smul] + exact pauliStringHamiltonian_op g c + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/KitaevPhaseEstimation.lean b/LeanPool/AxQM/Postulates/API/KitaevPhaseEstimation.lean new file mode 100644 index 0000000000..86a8681ad5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/KitaevPhaseEstimation.lean @@ -0,0 +1,148 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasureObservable +public import LeanPool.AxQM.Postulates.API.ControlMeasurementCommute + +/-! +# AxQM.Postulates.API — Kitaev's phase-estimation circuit + +The computation behind Nielsen & Chuang's **Problem 5.3 (Kitaev's algorithm)**: the +Hadamard-controlled-`U` circuit `(H ⊗ 1) · C(U) · (H ⊗ 1)` (`measureObservableCircuit`, generalised +to an arbitrary target register `S` in `MeasureObservable.lean`) run on `|0⟩ ⊗ |u⟩` with `|u⟩` an +eigenstate of `U`, and the Born-rule statistics of the ancilla (control) measurement. + +``` +|0⟩ ─── H ───•─── H ───⊙ (measure the control) + │ +|u⟩ ─/───────U────────── |u⟩ (eigenstate, unaffected) +``` + +## What is formalised + +* `Measurement.bornProb_toState_eq_normSq` — the **Born rule on a pure state** for *any* + measurement: `p(i) = ‖Mᵢ|ψ⟩‖²` (from `Mᵢ ρ Mᵢ† = |Mᵢψ⟩⟨Mᵢψ|` and `tr|v⟩⟨v| = ‖v‖²`). General + reusable infrastructure. +* `Evolution.HasEigenstate.pow` — an eigenstate of `U` (eigenvalue `μ`) is an eigenstate of `Uᵏ` + (eigenvalue `μᵏ`); this is what allows iterating the circuit with `U → Uᵏ`. +* `measureObservableCircuit_op_qubitBasisZero_tmul_smul` — the **phase kickback**: on an eigenstate + input `U|u⟩ = μ|u⟩` the circuit output *factorises* as `(½(1+μ) |0⟩ + ½(1−μ) |1⟩) ⊗ |u⟩`, the + target register left in the intact `|u⟩` — the precise sense in which `|u⟩` is *unaffected and + reusable*. +* `measureObservableCircuit_controlMeasurement_bornProb_zero_smul` — the **outcome-0 probability** + `‖½(1+μ)‖²` of measuring the control in the computational basis after the circuit, on an + eigenstate input. With `μ = e^{2πiφ}` this is `cos²(πφ)` (the pure-phase arithmetic is discharged + in [upstream `AxQM/NC/Ch5/Problem5_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_3.lean)). + +The Born-probability statements `p = cos²(πφ)` and its `Uᵏ` iteration are in +[upstream `AxQM/NC/Ch5/Problem5_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_3.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The Born rule on a pure state (general) -/ + +/-- **Born rule on a pure state.** For any measurement `m`, the probability of outcome `i` on a pure +state `|ψ⟩` is the squared norm of the collapsed (unnormalised) vector: `p(i) = ‖Mᵢ|ψ⟩‖²`. Holds for +*every* measurement (no projectivity/self-adjointness needed): `Mᵢ ρ Mᵢ† = |Mᵢψ⟩⟨Mᵢψ|` for +`ρ = |ψ⟩⟨ψ|`, and `tr|v⟩⟨v| = ⟨v, v⟩ = ‖v‖²`. General reusable infrastructure. -/ +theorem Measurement.bornProb_toState_eq_normSq {ι : Type*} [Fintype ι] (m : Measurement ι S) + (ψ : PureState S) (i : ι) : m.bornProb ψ.toState i = ‖m.op i ψ.vec‖ ^ 2 := by + rw [Measurement.bornProb_eq_re_trace_postOp] + have hpost : ContinuousLinearMap.postOp m.op ψ.toState.op i + = InnerProductSpace.rankOne ℂ (m.op i ψ.vec) (m.op i ψ.vec) := by + simp only [ContinuousLinearMap.postOp, PureState.toState_op, InnerProductSpace.rankOne_comp, + ContinuousLinearMap.adjoint_adjoint, InnerProductSpace.comp_rankOne] + rw [hpost, InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq] + +/-! ### Eigenstates of a gate power -/ + +/-- **An eigenstate of `U` is an eigenstate of `Uᵏ`.** If `U|ψ⟩ = μ|ψ⟩` then `Uᵏ|ψ⟩ = μᵏ|ψ⟩`, for +the gate monoid power `Uᵏ` (`Evolution` is a monoid under composition). The substance for iterating +Kitaev's circuit: replacing `U` by `Uᵏ` multiplies the eigenphase by `k`. -/ +theorem Evolution.HasEigenstate.pow {U : Evolution S} {μ : ℂ} {ψ : PureState S} + (h : U.HasEigenstate μ ψ) (k : ℕ) : (U ^ k).HasEigenstate (μ ^ k) ψ := by + simp only [Evolution.HasEigenstate] at h ⊢ + induction k with + | zero => + rw [pow_zero, pow_zero, Evolution.one_def, Evolution.id_op, one_apply_eq_self, + one_smul] + | succ n ih => + rw [pow_succ, pow_succ, Evolution.mul_def, Evolution.comp_op, ContinuousLinearMap.comp_apply, + h, map_smul, ih, smul_smul, mul_comm] + +/-! ### The circuit on an eigenstate: phase kickback and factorisation -/ + +/-- **Phase kickback / eigenstate factorisation.** On an eigenstate input `U|u⟩ = μ|u⟩`, the +Hadamard-controlled-`U` circuit sends `|0⟩ ⊗ |u⟩` to the *product* state +`(½(1+μ) |0⟩ + ½(1−μ) |1⟩) ⊗ |u⟩`: the target register stays factored out and unchanged in `|u⟩` +(so it may be reused), while the eigenphase `μ` appears as a relative phase on the control. + +Specialisation of the general circuit action `measureObservableCircuit_op_qubitBasisZero_tmul` +(`|0⟩ ⊗ x ↦ |0⟩ ⊗ ½(x+Ux) + |1⟩ ⊗ ½(x−Ux)`) at `Ux = μx`, collecting the two branches onto the +common right factor `x`. -/ +theorem measureObservableCircuit_op_qubitBasisZero_tmul_smul (U : Evolution S) {x : S.space} + {μ : ℂ} (hx : U.op x = μ • x) : + (measureObservableCircuit U).op ((qubitBasis 0).vec ⊗ₜ[ℂ] x) + = (((2⁻¹ : ℂ) * (1 + μ)) • (qubitBasis 0).vec + + ((2⁻¹ : ℂ) * (1 - μ)) • (qubitBasis 1).vec) ⊗ₜ[ℂ] x := by + rw [measureObservableCircuit_op_qubitBasisZero_tmul, hx, TensorProduct.add_tmul] + congr 1 <;> (rw [← TensorProduct.smul_tmul', ← TensorProduct.tmul_smul]; congr 1; module) + +/-! ### Applying the control measurement to a product state -/ + +/-- The control-measurement operator `Mᵢ = |i⟩⟨i| ⊗ 1` acting on a product `a ⊗ b` gives +`(|i⟩⟨i| a) ⊗ b`: the projector `|i⟩⟨i|` hits the control factor, the target factor is untouched. +Restated at the raw tensor head (`change`, as in the sibling `controlledUnitary` lemmas) so +`TensorProduct.mapL_tmul` fires. -/ +theorem controlMeasurement_op_tmul (i : Fin 2) (a : qubit.space) (b : S.space) : + (controlMeasurement S).op i (a ⊗ₜ[ℂ] b) + = (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec) a ⊗ₜ[ℂ] b := by + rw [controlMeasurement_op] + change (TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec) + (1 : S.space →L[ℂ] S.space)) (a ⊗ₜ[ℂ] b) = _ + rw [TensorProduct.mapL_tmul, one_apply_eq_self] + +/-! ### The control-measurement Born probability on an eigenstate -/ + +/-- **Outcome-`0` probability of the control measurement.** After the circuit, measuring the control +qubit in the computational basis yields `0` with probability `‖½(1+μ)‖²`, on an eigenstate input +`U|u⟩ = μ|u⟩`. Combines the phase-kickback factorisation +(`measureObservableCircuit_op_qubitBasisZero_tmul_smul`) — whose `|0⟩`-amplitude is `½(1+μ)` and +whose right factor `|u⟩` is normalised — with the pure-state Born rule +(`Measurement.bornProb_toState_eq_normSq`): the control projector `|0⟩⟨0| ⊗ 1` extracts the +`|0⟩`-amplitude, and `‖½(1+μ) • (|0⟩ ⊗ |u⟩)‖² = ‖½(1+μ)‖²`. -/ +theorem measureObservableCircuit_controlMeasurement_bornProb_zero_smul (U : Evolution S) + (u : PureState S) {μ : ℂ} (hu : U.op u.vec = μ • u.vec) : + (controlMeasurement S).bornProb + ((measureObservableCircuit U).evolvePure ((qubitBasis 0).tmul u)).toState 0 + = ‖(2⁻¹ : ℂ) * (1 + μ)‖ ^ 2 := by + rw [Measurement.bornProb_toState_eq_normSq, Evolution.evolvePure_vec, PureState.tmul_vec, + measureObservableCircuit_op_qubitBasisZero_tmul_smul U hu, controlMeasurement_op_tmul] + rw [map_add, map_smul, map_smul, InnerProductSpace.rankOne_apply, InnerProductSpace.rankOne_apply, + qubitBasis_inner_qubitBasis, qubitBasis_inner_qubitBasis] + simp only [Fin.isValue, ite_true, Fin.reduceEq, ite_false, one_smul, zero_smul, smul_zero, + add_zero] + -- View the product state at the raw tensor head `qubit.space ⊗[ℂ] S.space`, where + -- `TensorProduct.norm_tmul` fires (cf. `PureState.tmul`'s normalisation in `Composite.lean`). + change ‖(((2⁻¹ * (1 + μ)) • (qubitBasis 0).vec) ⊗ₜ[ℂ] u.vec : qubit.space ⊗[ℂ] S.space)‖ ^ 2 + = ‖(2⁻¹ : ℂ) * (1 + μ)‖ ^ 2 + rw [TensorProduct.norm_tmul, norm_smul, (qubitBasis 0).normalized, u.normalized, mul_one, mul_one] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/LeftPairGate.lean b/LeanPool/AxQM/Postulates/API/LeftPairGate.lean new file mode 100644 index 0000000000..5ed065901b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/LeftPairGate.lean @@ -0,0 +1,159 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Fredkin +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.SystemIsoComm + +/-! +# AxQM.Postulates.API — CNOT / reversed-CNOT on the *left pair* of three qubits + +The two `CNOT` placements that act on qubits **1 and 2** of the right-associated three-qubit +system `qubit ⊗ (qubit ⊗ qubit)`, leaving qubit 3 untouched. The existing gate +vocabulary (`cnotGate.onRight`, `reversedCnotGate.onRight`, `toffoliGate`, +`middleToffoliGate`) only reaches qubits 2 and 3, or uses qubit 1 as a *control*; nothing flips +qubit 1. These two gates fill that gap and are reused by any circuit that must act on the first +qubit as a target (e.g. N&C Exercise 4.27's partial cyclic permutation). + +## What is formalised + +* `Evolution.congr_evolvePure_congr` — the **transport law for gate action** through a system + isomorphism: `(U.congr e)` acts on the transported state `ψ.congr e` exactly as the transport of + `U`'s action, `(U.congr e).evolvePure (ψ.congr e) = (U.evolvePure ψ).congr e`. This is the general + lemma that lets a gate defined on one bracketing of a composite be evaluated on the other. +* `cnotLeftGate` — the `CNOT` with control qubit 1 and target qubit 2 (`|q₁,q₂,q₃⟩ ↦ + |q₁, q₂⊕q₁, q₃⟩`), realised as `C(X ⊗ 1)` (a single-qubit-controlled gate, so no re-bracketing is + needed). Truth table `cnotLeftGate_evolvePure_qubitBasis`. +* `reversedCnotLeftGate` — the `CNOT` with control qubit 2 and target qubit 1 (`|q₁,q₂,q₃⟩ ↦ + |q₁⊕q₂, q₂, q₃⟩`). Its target is qubit 1, unreachable by the controlled-gate constructors, so it + is the two-qubit `reversedCnotGate` placed on the left pair `(qubit ⊗ qubit) ⊗ qubit` via + `onLeft` and transported to the right-associated system by the associator. Truth table + `reversedCnotLeftGate_evolvePure_qubitBasis`. + +## Design notes + +* **Why the associator (`reversedCnotLeftGate`).** Every `CNOT`/Toffoli already in the library + either uses qubit 1 as a control (`controlledUnitary`, `ccontrolledUnitary`) or acts on the right + pair (`onRight`); none targets qubit 1, because in the right-associated `qubit ⊗ (qubit ⊗ qubit)` + a gate on qubits 1, 2 is not of `onRight`/`controlledUnitary` form. The honest fix is to place the + genuine two-qubit `reversedCnotGate` on the *left* pair of the left-associated + `(qubit ⊗ qubit) ⊗ qubit` (`reversedCnotGate.onLeft qubit`) and carry it across the associator + system-isomorphism `QSystem.assoc` with `Evolution.congr`. `Evolution.congr_evolvePure_congr` then + turns the truth table into the same one-tensor-factor-at-a-time computation as the other gates. +* **`cnotLeftGate` needs no associator.** A `CNOT` whose *control* is qubit 1 and target qubit 2 is + just `C(U)` with `U = X ⊗ 1` acting on the target pair, so `controlledUnitary (pauliXGate.onLeft + qubit)` places it directly on the right-associated system with the standard control-branch lemmas. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### Transport of gate action through a system isomorphism -/ + +/-- **Transport law for gate action.** A gate transported along a system isomorphism `e` acts on a +transported state exactly as the transport of the original action: +`(U.congr e).evolvePure (ψ.congr e) = (U.evolvePure ψ).congr e`. Both sides have underlying vector +`e (U.op ψ.vec)`: the left because conjugating `U.op` by `e` and then feeding `e ψ.vec` cancels the +inner `e⁻¹ ∘ e`; the right by definition of `PureState.congr` and `evolvePure`. -/ +theorem Evolution.congr_evolvePure_congr {S T : QSystem} (e : S.Iso T) (U : Evolution S) + (ψ : PureState S) : + (U.congr e).evolvePure (ψ.congr e) = (U.evolvePure ψ).congr e := by + apply PureState.ext + rw [Evolution.evolvePure_vec, Evolution.congr_op, PureState.congr_vec, PureState.congr_vec, + Evolution.evolvePure_vec] + simp [LinearIsometryEquiv.conjStarAlgEquiv_apply] + +/-- **Symm-transport law for gate action.** The `e.symm` companion of +`Evolution.congr_evolvePure_congr`: pulling the transported gate action `(U.congr e).evolvePure ψ` +back along `e.symm` is the transport-back of the original action — +`congr e.symm ((U.congr e).evolvePure ψ) = U.evolvePure (congr e.symm ψ)`. Rewriting the left side +backward through the forward law `Evolution.congr_evolvePure_congr` moves the outer `congr e.symm` +inside — onto both the gate `U.congr e` and the state `ψ` — and the gate's roundtrip `e.symm ∘ e` +then cancels (`Evolution.congr_symm_congr`). +Used to move a gate action between the two frames of a system isomorphism when the *state* is on the +target side `T` (e.g. transporting a joint dilation between the parties∣ancillas and Alice∣Bob cuts +of Nielsen & Chuang Exercise 12.22). -/ +theorem Evolution.evolvePure_congr_symm {S T : QSystem} (e : S.Iso T) (U : Evolution S) + (ψ : PureState T) : + PureState.congr e.symm ((Evolution.congr e U).evolvePure ψ) + = U.evolvePure (PureState.congr e.symm ψ) := by + rw [← Evolution.congr_evolvePure_congr, Evolution.congr_symm_congr] + +/-- **A transported gate acts on states by conjugation.** For `e : S ≃ₛ T`, gate `V` on `S`, and +state `χ` on `T`, `(congr e V).evolvePure χ = congr e (V.evolvePure (congr e.symm χ))`: pull `χ` +back along `e.symm`, evolve by `V`, push forward along `e`. The arbitrary-target form sitting +between +`Evolution.congr_evolvePure_congr` (state on the source side) and `Evolution.evolvePure_congr_symm` +(the `e.symm` frame): rewrite the left side backward through the roundtrip +`PureState.congr_congr_symm`, then `Evolution.evolvePure_congr_symm` moves `V` across the frame. -/ +theorem Evolution.evolvePure_congr {S T : QSystem} (e : S.Iso T) (V : Evolution S) + (χ : PureState T) : + (Evolution.congr e V).evolvePure χ + = PureState.congr e (V.evolvePure (PureState.congr e.symm χ)) := by + rw [← PureState.congr_congr_symm e ((Evolution.congr e V).evolvePure χ), + Evolution.evolvePure_congr_symm] + +/-! ### `CNOT` on the left pair, control qubit 1 -/ + +/-- **`CNOT` on qubits 1, 2 with control qubit 1**, `|q₁, q₂, q₃⟩ ↦ |q₁, q₂ ⊕ q₁, q₃⟩`: the +single-qubit-controlled gate `C(X ⊗ 1)` flipping qubit 2 exactly when qubit 1 is `|1⟩`, qubit 3 +untouched. Since the control is qubit 1 this needs no re-bracketing. -/ +def cnotLeftGate : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + controlledUnitary (pauliXGate.onLeft qubit) + +/-- **`cnotLeftGate` truth table:** `|q₁, q₂, q₃⟩ ↦ |q₁, q₂ ⊕ q₁, q₃⟩` (control qubit 1, target +qubit 2). -/ +theorem cnotLeftGate_evolvePure_qubitBasis (q1 q2 q3 : Fin 2) : + cnotLeftGate.evolvePure ((qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3))) + = (qubitBasis q1) ⊗ ((qubitBasis (q2 + q1)) ⊗ (qubitBasis q3)) := by + rw [cnotLeftGate] + fin_cases q1 <;> + simp only [Fin.mk_zero, Fin.mk_one, controlledUnitary_evolvePure_ketZero, + controlledUnitary_evolvePure_ketOne, Evolution.onLeft, Evolution.tmul_evolvePure, + pauliXGate_evolvePure_qubitBasis, Evolution.id_evolvePure, add_zero] + +/-! ### Reversed `CNOT` on the left pair, target qubit 1 -/ + +/-- **`CNOT` on qubits 1, 2 with control qubit 2**, `|q₁, q₂, q₃⟩ ↦ |q₁ ⊕ q₂, q₂, q₃⟩`: the +two-qubit `reversedCnotGate` (control second, target first) placed on the left pair +`(qubit ⊗ qubit) ⊗ qubit` and transported to the right-associated three-qubit system by the +associator. Its target is qubit 1, unreachable by the controlled-gate constructors. -/ +def reversedCnotLeftGate : Evolution (qubit ⊗ (qubit ⊗ qubit)) := + (reversedCnotGate.onLeft qubit).congr (QSystem.assoc qubit qubit qubit).symm + +/-- The associator (backwards) on a computational-basis state re-brackets left to right: +`((ψ ⊗ φ) ⊗ χ).congr (assoc).symm = ψ ⊗ (φ ⊗ χ)`. -/ +theorem pureState_congr_assocSymm {A B C : QSystem} (ψ : PureState A) (φ : PureState B) + (χ : PureState C) : + ((ψ ⊗ φ) ⊗ χ).congr (QSystem.assoc A B C).symm = ψ ⊗ (φ ⊗ χ) := by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec, PureState.tmul_vec, PureState.tmul_vec, + PureState.tmul_vec, show (QSystem.assoc A B C).symm.toIsometry + = (TensorProduct.assocIsometry ℂ A.space B.space C.space).symm.symm from rfl, + LinearIsometryEquiv.symm_symm] + exact (TensorProduct.assocIsometry_apply _).trans (TensorProduct.assoc_tmul ψ.vec φ.vec χ.vec) + +/-- **`reversedCnotLeftGate` truth table:** `|q₁, q₂, q₃⟩ ↦ |q₁ ⊕ q₂, q₂, q₃⟩` (control qubit 2, +target qubit 1). Computed by re-bracketing to the left pair (`pureState_congr_assocSymm`), running +`reversedCnotGate` on qubits 1, 2 (`Evolution.congr_evolvePure_congr`), and re-bracketing back. -/ +theorem reversedCnotLeftGate_evolvePure_qubitBasis (q1 q2 q3 : Fin 2) : + reversedCnotLeftGate.evolvePure ((qubitBasis q1) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3))) + = (qubitBasis (q1 + q2)) ⊗ ((qubitBasis q2) ⊗ (qubitBasis q3)) := by + rw [reversedCnotLeftGate, ← pureState_congr_assocSymm (qubitBasis q1) (qubitBasis q2) + (qubitBasis q3), Evolution.congr_evolvePure_congr, Evolution.onLeft, + Evolution.tmul_evolvePure, reversedCnotGate_evolvePure_qubitBasis, Evolution.id_evolvePure, + pureState_congr_assocSymm] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MaxEntMarginal.lean b/LeanPool/AxQM/Postulates/API/MaxEntMarginal.lean new file mode 100644 index 0000000000..e5f4e13fdb --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MaxEntMarginal.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SchmidtNumber +public import LeanPool.AxQM.Postulates.API.Entropy + +/-! +# AxQM — maximally entangled resource marginals + +`State.IsMaxEntMarginal ρ K`: the state `ρ` is the reduced state (one-party marginal) of a +**maximally entangled pure state of Schmidt rank `K`** — equivalently, `ρ` is maximally mixed on a +`K`-dimensional subspace (its `K` non-zero eigenvalues are all `1/K`). We characterise this by + +`ρ.rank = K ∧ ρ.vonNeumannEntropy = Real.log K`. + +This pair *is* the characterisation: a rank-`K` state has entropy `≤ log K` +(`State.vonNeumannEntropy_le_log_finrank` on its `K`-dimensional support) with equality **iff** the +spectrum is uniform, so `rank = K` together with the maximal value `S = log K` forces the `K` +non-zero eigenvalues to be exactly `1/K` — i.e. `ρ = (1/K)·P` for a rank-`K` projection `P`, the +marginal of `K`-dimensional maximal entanglement. For `K = 2ⁿ` this is the reduced state of `n` +shared Bell pairs, with entropy `n · log 2`. + +This is the *target-resource* predicate for entanglement distillation (N&C §12.5.2, +Exercise 12.23): distilling copies of `|ψ⟩` produces, with fidelity → 1, a state trace-close to some +`μ` with `μ.IsMaxEntMarginal K` — i.e. close to `K`-dimensional maximal entanglement. + +Here `State.rank` is `finrank ℂ` of the range of the density operator. The predicate is used in +the statement of Exercise 12.23 ([upstream `AxQM/NC/Ch12/Exercise12_23.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Exercise12_23.lean)). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +namespace State + +variable {S : QSystem} + +/-- `ρ.IsMaxEntMarginal K`: `ρ` is the marginal of a maximally entangled pure state of Schmidt +rank `K`, i.e. `ρ` is maximally mixed on a `K`-dimensional subspace. Characterised by its rank being +`K` and its entropy attaining the maximal value `log K` for that rank — which forces the `K` +non-zero eigenvalues to be uniform, each `1/K`. For `K = 2ⁿ` this is the reduced state of `n` shared +Bell pairs, `S(ρ) = n · log 2`. -/ +def IsMaxEntMarginal (ρ : State S) (K : ℕ) : Prop := + ρ.rank = K ∧ ρ.vonNeumannEntropy = Real.log K + +/-- The entropy of a rank-`K` maximally entangled marginal is `log K`. -/ +theorem IsMaxEntMarginal.vonNeumannEntropy_eq {ρ : State S} {K : ℕ} + (h : ρ.IsMaxEntMarginal K) : ρ.vonNeumannEntropy = Real.log K := + h.2 + +/-- The rank of a rank-`K` maximally entangled marginal is `K`. -/ +theorem IsMaxEntMarginal.rank_eq {ρ : State S} {K : ℕ} + (h : ρ.IsMaxEntMarginal K) : ρ.rank = K := + h.1 + +end State + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MaximallyMixed.lean b/LeanPool/AxQM/Postulates/API/MaximallyMixed.lean new file mode 100644 index 0000000000..d8b652dc16 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MaximallyMixed.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! +# AxQM.Postulates.API — the maximally mixed state `I/d` + +The **maximally mixed state** of a quantum system `S`: the density operator `I/d` where +`d = dim S` is the dimension of the state space. It is the state of maximal von Neumann entropy — +"total ignorance" — and the reduced state of a maximally entangled bipartite pure state +(Nielsen & Chuang §2.4.3; the `I/2` of Exercise 2.75). + +* `maximallyMixedState S` — the state `(dim S)⁻¹ • I`, a `State S` (requires `Nontrivial S.space`, + since a `0`-dimensional space has no density operator). + +## Design notes + +The operator is `(finrank ℂ S.space : ℂ)⁻¹ • 1`; it is a density operator by the lemma +`ContinuousLinearMap.isDensityOp_finrank_inv_smul_one` (positive, trace `d · (1/d) = 1`), which +needs `Nontrivial S.space` (on a subsingleton space `finrank = 0` and `0⁻¹ • 1 = 0` has trace `0`). + +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **maximally mixed state** `I/d` of the system `S`, where `d = dim S`: the density operator +`(finrank ℂ S.space)⁻¹ • 1`. Requires `Nontrivial S.space` (a state needs a nontrivial space). This +is the state of maximal entropy, and the marginal of a maximally entangled pure state. -/ +def maximallyMixedState (S : QSystem) [Nontrivial S.space] : State S where + op := (Module.finrank ℂ S.space : ℂ)⁻¹ • 1 + isDensity := ContinuousLinearMap.isDensityOp_finrank_inv_smul_one + +/-- The operator of the maximally mixed state is `(dim S)⁻¹ • I`. A `simp` lemma exposing the +operator for operator computations. -/ +@[simp] +theorem maximallyMixedState_op (S : QSystem) [Nontrivial S.space] : + (maximallyMixedState S).op = (Module.finrank ℂ S.space : ℂ)⁻¹ • 1 := rfl + +/-- **The maximally mixed state is faithful (strictly positive):** its operator `(dim S)⁻¹ • I` +has strictly positive spectrum. The canonical faithful reference state — e.g. the perturbation +target `(1 − ε) ρ + ε (I/d)` in faithfulness-free entropy arguments. -/ +theorem maximallyMixedState_isStrictlyPositive (S : QSystem) [Nontrivial S.space] : + IsStrictlyPositive (maximallyMixedState S).op := by + rw [maximallyMixedState_op] + exact ContinuousLinearMap.isStrictlyPositive_finrank_inv_smul_one + +/-- **Every unitary conjugation fixes the maximally mixed state:** `U (I/d) U† = I/d`, i.e. +`U.evolve (maximallyMixedState S) = maximallyMixedState S`. Since `I/d = (1/d) • I` and `U U† = I` +(`Evolution.comp_adjoint_self`), the conjugation `U ((1/d)•I) U† = (1/d) • (U U†) = (1/d) • I`. This +is the atomic reason a unitary channel — and hence any random-unitary mixture of unitary channels +(`RandomUnitaryChannel.isUnital`) — is unital. A general `Evolution` fact, placed here so it is +citable without the channel machinery. -/ +theorem Evolution.evolve_maximallyMixedState {S : QSystem} [Nontrivial S.space] (U : Evolution S) : + U.evolve (maximallyMixedState S) = maximallyMixedState S := by + apply State.ext + simp only [Evolution.evolve_op, maximallyMixedState_op, ContinuousLinearMap.smul_comp, + ContinuousLinearMap.comp_smul, ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, + U.comp_adjoint_self] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasureObservable.lean b/LeanPool/AxQM/Postulates/API/MeasureObservable.lean new file mode 100644 index 0000000000..1f524e745b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasureObservable.lean @@ -0,0 +1,290 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CnotXBasis +public import LeanPool.AxQM.Postulates.API.PauliEigen +public import LeanPool.AxQM.Postulates.API.ToffoliHadamard +public import LeanPool.AxQM.Postulates.API.ControlBranchExt + +/-! +# AxQM.Postulates.API — measuring an observable with a Hadamard-controlled-`U` circuit + +Nielsen & Chuang's Exercise 4.34 ("Measuring an operator"): the circuit +that implements a projective measurement of a single-qubit `±1` observable `U` (an operator that is +both Hermitian and unitary, hence both an observable and a gate) using one ancilla qubit, a +controlled-`U`, and two Hadamards. + +``` +|0⟩ ─── H ───•─── H ───⊙ (measure ancilla) + │ +|ψ⟩ ─────────U────────── +``` + +## What is formalised + +* `Evolution.toObservable U hsa` — a **Hermitian gate viewed as an observable**: a unitary `U` + (an `Evolution`) that is additionally self-adjoint (`IsSelfAdjoint U.op`) is packaged as an + `Observable`. `Evolution.toObservable_op_mul_self` records the resulting **involution** + `U² = I` (from unitary ∧ self-adjoint), the hypothesis every `±1`-observable API needs. +* `measureObservableCircuit U` — the **circuit** `(H ⊗ 1) · C(U) · (H ⊗ 1)` on `qubit ⊗ qubit` + (ancilla = left/control qubit; target = right qubit), an `Evolution`. +* `measureObservableCircuit_op_qubitBasisZero_tmul` — **the circuit action**: with the ancilla + prepared in `|0⟩`, the circuit sends `|0⟩ ⊗ |ψ⟩` to `|0⟩ ⊗ P₊|ψ⟩ + |1⟩ ⊗ P₋|ψ⟩`, where + `P₊ = (I + U)/2` and `P₋ = (I − U)/2` are the eigenprojectors of `U`. Stated at the raw operator + level (`(I ± U)/2` applied to a target vector `x`) so it needs no self-adjointness hypothesis. +* `measureObservableCircuit_op_qubitBasisZero_tmul_projMeas` — the same, with the target components + written as the eigenprojectors `Observable.projPlus`/`Observable.projMinus` of the observable + `U.toObservable`. +* `measureObservableCircuit_op_qubitBasisZero_tmul_signMeasurement` — the same, with the target + components written as the measurement operators `M₀`, `M₁` of `Observable.signMeasurement` — the + projective measurement **of the observable `U`** (N&C §2.2.5). This is the precise sense in which + the circuit *implements a measurement of `U`*: the theorem proves the *pre-measurement* correlated + state `|0⟩ ⊗ M₀x + |1⟩ ⊗ M₁x`, whose `|i⟩`-ancilla branch carries the target through the `i`-th + measurement operator of that measurement. A computational-basis measurement of the ancilla (read + `0 ↦ +1`, `1 ↦ −1`) then collapses the target onto `Mᵢx` with Born weight `‖Mᵢx‖²` — the + statistics and post-measurement states of the sign measurement of `U`. That last step is the + physical interpretation of the correlation, not part of what this theorem states (running the + ancilla measurement explicitly is done in `MeasureObservableAncilla.lean`; see the + [upstream `AxQM/NC/Ch4/Exercise4_34.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_34.lean) scope note). + +The **deterministic eigenstate behaviour** — on a `±1` eigenstate input the ancilla flags the +eigenvalue and leaves the target unchanged — is stated in +[upstream `AxQM/NC/Ch4/Exercise4_34.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_34.lean) and proved from the circuit action here. + +## Design notes + +* **Fidelity to N&C.** N&C's `U` is "both Hermitian and unitary, so it can be regarded + both as an observable and a quantum gate." We honour both roles literally: `U : Evolution qubit` + supplies the *gate* (fed to `controlledUnitary`), and `U.toObservable hsa` (with + `hsa : IsSelfAdjoint U.op`) supplies the *observable*, whose `signMeasurement` is precisely "the + measurement of `U`." The circuit action is a full operator identity on the whole target vector + `x`, not a claim about selected inputs, so the two eigenprojector branches `P₊`, `P₋` capture the + measurement completely (`P₊ + P₋ = I`). +* **Proof.** The core identity is a direct computation at the raw tensor head: `H` on the control + turns `|0⟩` into `(|0⟩ + |1⟩)/√2`; `C(U)` correlates the branches (`|1⟩` picks up `U` on the + target); the second `H` interferes them into `|0⟩ ⊗ (I + U)/2 · x + |1⟩ ⊗ (I − U)/2 · x`. The + `√2` factors combine to the eigenprojector coefficient `1/2` (`Concrete.invSqrt2_mul_self`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### A Hermitian gate viewed as an observable -/ + +/-- **A Hermitian gate as an observable.** A unitary evolution `U` (Postulate 5) that is +additionally self-adjoint is, by Postulate 2, an observable with the same underlying operator. +This is the object N&C's Exercise 4.34 calls "regarding `U` both as an observable and a quantum +gate": the gate is `U` itself, and the observable is `U.toObservable hsa`. -/ +def Evolution.toObservable (U : Evolution S) (hsa : IsSelfAdjoint U.op) : Observable S where + op := U.op + selfAdjoint := hsa + +/-- The underlying operator of `U.toObservable` is `U.op`. -/ +@[simp] +theorem Evolution.toObservable_op (U : Evolution S) (hsa : IsSelfAdjoint U.op) : + (U.toObservable hsa).op = U.op := rfl + +/-- **A self-adjoint unitary is an involution:** `U² = I`. From unitarity `U† U = I` and +self-adjointness `U† = U`, so `U U = U† U = I`. This is the `±1`-observable hypothesis +(`A.op * A.op = 1`) required by `Observable.signMeasurement` and the eigenprojector API. -/ +theorem Evolution.toObservable_op_mul_self (U : Evolution S) (hsa : IsSelfAdjoint U.op) : + (U.toObservable hsa).op * (U.toObservable hsa).op = 1 := by + rw [Evolution.toObservable_op] + have hu : star U.op * U.op = 1 := (Unitary.mem_iff.mp U.unitary).1 + have hsa' : star U.op = U.op := hsa + rwa [hsa'] at hu + +/-! ### Vector-level action of the Hadamard gate on the computational basis -/ + +/-- The Hadamard gate on `|0⟩` at the vector level: `H|0⟩ = (|0⟩ + |1⟩)/√2`. The operator-applied +form of `hadamardGate_evolvePure_qubitBasis_zero` (`H|0⟩ = |+⟩`) expanded through +`qubitPlus_vec_eq_smul_add`. -/ +theorem hadamardGate_op_qubitBasisVec_zero : + hadamardGate.op (qubitBasis 0).vec + = Concrete.invSqrt2 • ((qubitBasis 0).vec + (qubitBasis 1).vec) := by + rw [← Evolution.evolvePure_vec, hadamardGate_evolvePure_qubitBasis_zero, + qubitPlus_vec_eq_smul_add] + +/-- The Hadamard gate on `|1⟩` at the vector level: `H|1⟩ = (|0⟩ − |1⟩)/√2`. The operator-applied +form of `hadamardGate_evolvePure_qubitBasis_one` (`H|1⟩ = |−⟩`) expanded through +`qubitMinus_vec_eq_smul_sub`. -/ +theorem hadamardGate_op_qubitBasisVec_one : + hadamardGate.op (qubitBasis 1).vec + = Concrete.invSqrt2 • ((qubitBasis 0).vec - (qubitBasis 1).vec) := by + rw [← Evolution.evolvePure_vec, hadamardGate_evolvePure_qubitBasis_one, + qubitMinus_vec_eq_smul_sub] + +/-! ### The measurement circuit and its action -/ + +/-- **The Hadamard-controlled-`U` measurement circuit** of Nielsen & Chuang Exercise 4.34: the +`Evolution` on `qubit ⊗ S` given by `(H ⊗ 1) · C(U) · (H ⊗ 1)` — a Hadamard on the control +(left/ancilla) qubit, then the controlled-`U` gate, then another Hadamard on the control. Reading +the ancilla in the computational basis after this circuit is a measurement of the observable `U`. + +The target register `S` is *arbitrary* (not just a single qubit): with `S = qubit` and a `±1` +(Hermitian, unitary) `U` this is Exercise 4.34's operator-measurement circuit, and with an arbitrary +target and an eigenstate input it is **Kitaev's phase-estimation circuit** (Problem 5.3), whose +control-measurement statistics read off the eigenphase. -/ +def measureObservableCircuit (U : Evolution S) : Evolution (qubit ⊗ S) := + (hadamardGate.onLeft S).comp ((controlledUnitary U).comp (hadamardGate.onLeft S)) + +/-- **The measurement circuit splits over a product observable — the `H² = 1` block factorisation.** +Measuring the product `U · V` of two observables on the target register with one Hadamard-controlled +block is the same as measuring `U` and then `V` with two separate blocks: +`measureObservableCircuit (U · V) = measureObservableCircuit U · measureObservableCircuit V`. + +The controlled gate splits, `C(U·V) = C(U)·C(V)` (`controlledUnitary_comp`, the lemma this mirrors), +and the two ancilla Hadamards that meet where the blocks join annihilate — `H² = 1` on the ancilla +wire (`hadamardOnLeft_sq`, the `(H.onLeft S)·(H.onLeft S) = 1` lemma, whose +`Evolution.onLeft_comp`/`id_onLeft` reduction carries the Hadamard involution through +`TensorProduct.mapL`) — leaving the single block +`(H ⊗ 1)·C(U)·C(V)·(H ⊗ 1)` for `U·V`. Stated for an arbitrary target `S`, so a generator on any +number of data qubits factors one Pauli at a time. + +This is the identity by which a syndrome-measurement block for a *product* of stabilizer generators +(Nielsen & Chuang Figure 10.16) is rewritten as a *sequence* of single-generator blocks +(Exercise 10.59), each then simplified in isolation by the Figures 10.14 / 10.15 identities. -/ +theorem measureObservableCircuit_comp (U V : Evolution S) : + measureObservableCircuit (U.comp V) + = (measureObservableCircuit U).comp (measureObservableCircuit V) := by + simp only [measureObservableCircuit, ← controlledUnitary_comp, Evolution.comp_assoc] + rw [← Evolution.comp_assoc (hadamardGate.onLeft S) (hadamardGate.onLeft S), + hadamardOnLeft_sq S, Evolution.id_comp] + +/-- **Measuring the identity observable is the identity circuit:** `measureObservableCircuit 1 = 1`. +Controlling the identity gate does nothing (`controlledUnitary_id`, `C(1) = 1`), leaving the two +ancilla Hadamards adjacent, and they annihilate (`hadamardOnLeft_sq`, `H² = 1` on the ancilla wire). +This is the *unit* law that, with the *product* law `measureObservableCircuit_comp`, makes +`measureObservableCircuit` a composition-monoid homomorphism; see +`measureObservableCircuit_listComp`. -/ +theorem measureObservableCircuit_id : + measureObservableCircuit (Evolution.id : Evolution S) = Evolution.id := by + simp only [measureObservableCircuit, controlledUnitary_id, Evolution.id_comp] + exact hadamardOnLeft_sq S + +/-- **The measurement circuit splits over a product of any length — the `n`-fold `H² = 1` block +factorisation.** Measuring the ordered product `L.prod` of a list `L` of observables on the target +with one Hadamard-controlled block equals the product of the per-factor blocks: +`measureObservableCircuit L.prod = (L.map measureObservableCircuit).prod`. The product is the one of +the gate monoid `Evolution.instMonoid` (unit `Evolution.id`, multiplication `Evolution.comp`), so +this is exactly the statement that `measureObservableCircuit` is a *monoid homomorphism* +`(Evolution S, ·, 1) → (Evolution (qubit ⊗ S), ·, 1)` — the `n`-ary form of +`measureObservableCircuit_comp` (`map_mul`) with unit `measureObservableCircuit_id` (`map_one`), +proved by induction on `L`. + +This is the Nielsen & Chuang Figure 10.16 → Figure 10.17 block step in full generality: a single +ancilla's block for a stabilizer generator `gₐ = ∏ᵢ Pᵢ` — a product of single-wire Paulis of *any* +weight — becomes the *sequence* of one-Pauli blocks, the ancilla Hadamards between consecutive +factors having annihilated. Each one-factor block `measureObservableCircuit Pᵢ` is then compiled to +its reversed-CNOT Figure-10.17 form on its data wire by a register lift +(`measureObservableCircuit_onLeft` / `_onRight` / `_onMiddle`) and the atomic Figures 10.14 / 10.15 +identities (Exercise 10.59). -/ +theorem measureObservableCircuit_listComp (L : List (Evolution S)) : + measureObservableCircuit L.prod = (L.map measureObservableCircuit).prod := by + induction L with + | nil => + simp only [List.prod_nil, List.map_nil, Evolution.one_def] + exact measureObservableCircuit_id + | cons f t ih => + rw [List.prod_cons, Evolution.mul_def, measureObservableCircuit_comp, ih, List.map_cons, + List.prod_cons, Evolution.mul_def] + +/-- **The measurement circuit's action** (Nielsen & Chuang Exercise 4.34). With the ancilla +prepared in `|0⟩`, the circuit sends `|0⟩ ⊗ x` to +`|0⟩ ⊗ ½(I + U)x + |1⟩ ⊗ ½(I − U)x`: the ancilla `|0⟩` branch carries the target through the `+1` +eigenprojector `P₊ = ½(I + U)` and the `|1⟩` branch through the `−1` eigenprojector `P₋ = ½(I − U)`. + +Stated at the raw operator level (`½(x ± U·x)`), so it holds for *every* target vector `x` and needs +no self-adjointness hypothesis; the eigenprojector / measurement readings are the corollaries below. + +Proof: `H` turns the control `|0⟩` into `(|0⟩ + |1⟩)/√2`; `C(U)` applies `U` on the `|1⟩` branch +only, giving `(|0⟩ ⊗ x + |1⟩ ⊗ Ux)/√2`; the second `H` interferes the control back, and the two +`1/√2` factors combine (`invSqrt2_mul_self`) into the `1/2` of the eigenprojectors. -/ +theorem measureObservableCircuit_op_qubitBasisZero_tmul (U : Evolution S) (x : S.space) : + (measureObservableCircuit U).op ((qubitBasis 0).vec ⊗ₜ[ℂ] x) + = (qubitBasis 0).vec ⊗ₜ[ℂ] ((2⁻¹ : ℂ) • (x + U.op x)) + + (qubitBasis 1).vec ⊗ₜ[ℂ] ((2⁻¹ : ℂ) • (x - U.op x)) := by + -- Restate the whole circuit at the *raw* tensor head. The two operators written below are the + -- definitional forms of the gates — `(hadamardGate.onLeft qubit).op = mapL H.op 1` (`Evolution` + -- `.onLeft`/`tmul_op`/`id_op`) and `(controlledUnitary U).op = mapL |0⟩⟨0| 1 + mapL |1⟩⟨1| U.op` + -- (`controlledUnitary_op`, which is `rfl`) — so this `change` is a definitional re-heading, not + -- an independent hand-derivation. It is required (not `rw`/`simp only [controlledUnitary_op]`) + -- because that lemma leaves the operator at the *composite* head `(qubit ⊗ qubit).space →L …`, + -- where the bundled `+`/`•` block `ContinuousLinearMap.add_apply` / `map_add` / `map_smul` when + -- applied to a raw-tensor argument; at the raw head all the `TensorProduct.mapL` and CLM algebra + -- fires uniformly. This mirrors the sibling `controlledUnitary_op_mem_unitary` / `_comp` / + -- `_onRight_conj` lemmas, which restate the same operator at the raw head. + change (TensorProduct.mapL hadamardGate.op (1 : S.space →L[ℂ] S.space)) + ((TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) + (1 : S.space →L[ℂ] S.space) + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + U.op) + ((TensorProduct.mapL hadamardGate.op (1 : S.space →L[ℂ] S.space)) + ((qubitBasis 0).vec ⊗ₜ[ℂ] x))) = _ + rw [TensorProduct.mapL_tmul, one_apply_eq_self, hadamardGate_op_qubitBasisVec_zero, + ← TensorProduct.smul_tmul', TensorProduct.add_tmul, smul_add] + -- After the first Hadamard: `(|0⟩⊗x)/√2 + (|1⟩⊗x)/√2`. Distribute `C(U)` over the sum. + simp only [_root_.add_apply, map_add, map_smul, TensorProduct.mapL_tmul, + one_apply_eq_self, InnerProductSpace.rankOne_apply, qubitBasis_inner_qubitBasis] + -- After `C(U)`: `(|0⟩⊗x)/√2 + (|1⟩⊗Ux)/√2`. Apply the second Hadamard and collapse the + -- projector coefficients (`⟨i|j⟩ = δᵢⱼ`, `Fin.reduceEq`). + simp only [hadamardGate_op_qubitBasisVec_zero, hadamardGate_op_qubitBasisVec_one, ite_true, + Fin.reduceEq, ite_false, one_smul, zero_smul, TensorProduct.zero_tmul, add_zero, zero_add] + -- Combine the two `1/√2` factors into `1/2` and distribute both sides into the four basis atoms. + rw [← TensorProduct.smul_tmul', ← TensorProduct.smul_tmul', smul_smul, smul_smul, + Concrete.invSqrt2_mul_self] + simp only [TensorProduct.add_tmul, TensorProduct.sub_tmul, TensorProduct.tmul_add, + TensorProduct.tmul_sub, TensorProduct.tmul_smul, smul_add, smul_sub] + module + +/-- **The measurement circuit's action in terms of the eigenprojectors of `U`.** With the ancilla +in `|0⟩`, the circuit sends `|0⟩ ⊗ x` to `|0⟩ ⊗ P₊x + |1⟩ ⊗ P₋x`, where `P₊ = Observable.projPlus` +and `P₋ = Observable.projMinus` are the `±1` eigenprojectors of the observable `U.toObservable hsa`. +Restatement of `measureObservableCircuit_op_qubitBasisZero_tmul` recognising `½(x ± U·x)` as the +eigenprojectors applied to `x`. -/ +theorem measureObservableCircuit_op_qubitBasisZero_tmul_projMeas (U : Evolution S) + (hsa : IsSelfAdjoint U.op) (x : S.space) : + (measureObservableCircuit U).op ((qubitBasis 0).vec ⊗ₜ[ℂ] x) + = (qubitBasis 0).vec ⊗ₜ[ℂ] ((U.toObservable hsa).projPlus x) + + (qubitBasis 1).vec ⊗ₜ[ℂ] ((U.toObservable hsa).projMinus x) := by + have hplus : (2⁻¹ : ℂ) • (x + U.op x) = (U.toObservable hsa).projPlus x := by + simp only [Observable.projPlus, Evolution.toObservable_op, _root_.smul_apply, + _root_.add_apply, one_apply_eq_self] + have hminus : (2⁻¹ : ℂ) • (x - U.op x) = (U.toObservable hsa).projMinus x := by + simp only [Observable.projMinus, Evolution.toObservable_op, _root_.smul_apply, + _root_.sub_apply, one_apply_eq_self] + rw [measureObservableCircuit_op_qubitBasisZero_tmul, hplus, hminus] + +/-- **The circuit implements the measurement of the observable `U`.** With the ancilla in `|0⟩`, +the circuit sends `|0⟩ ⊗ x` to `|0⟩ ⊗ M₀x + |1⟩ ⊗ M₁x`, where `M₀`, `M₁` are the two measurement +operators of `Observable.signMeasurement` — the projective measurement *of the observable `U`* +(N&C §2.2.5), with `M₀ = P₊` (outcome `+1`) and `M₁ = P₋` (outcome `−1`). Thus reading the ancilla +in the computational basis after the circuit and interpreting `0 ↦ +1`, `1 ↦ −1` realises exactly +that measurement: outcome `i` occurs with probability `‖Mᵢx‖²` and leaves the target in the +(unnormalised) collapsed state `Mᵢx` — an eigenvector of `U` with the corresponding eigenvalue. -/ +theorem measureObservableCircuit_op_qubitBasisZero_tmul_signMeasurement (U : Evolution S) + (hsa : IsSelfAdjoint U.op) (x : S.space) : + (measureObservableCircuit U).op ((qubitBasis 0).vec ⊗ₜ[ℂ] x) + = (qubitBasis 0).vec ⊗ₜ[ℂ] + (((U.toObservable hsa).signMeasurement (U.toObservable_op_mul_self hsa)).op 0 x) + + (qubitBasis 1).vec ⊗ₜ[ℂ] + (((U.toObservable hsa).signMeasurement (U.toObservable_op_mul_self hsa)).op 1 x) := by + simp only [Observable.signMeasurement_op_zero, Observable.signMeasurement_op_one] + exact measureObservableCircuit_op_qubitBasisZero_tmul_projMeas U hsa x + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasureObservableRegister.lean b/LeanPool/AxQM/Postulates/API/MeasureObservableRegister.lean new file mode 100644 index 0000000000..4a4b146c78 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasureObservableRegister.lean @@ -0,0 +1,258 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasureObservable +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# AxQM.Postulates.API — lifting the measurement circuit onto a data register + +The operator-measurement circuit `measureObservableCircuit U` (`(H ⊗ 1) · C(U) · (H ⊗ 1)`, +Exercise 4.34) puts its ancilla on the **left** wire and controls the *whole* target register `S`. +When the measured observable is a single-qubit Pauli sitting on **one wire of a multi-qubit data +register** — the situation of Nielsen & Chuang Figure 10.16, where each ancilla's controlled gate +fans out to the code qubits named by the generator — the block must be re-expressed as a circuit +acting only on that wire (plus the ancilla), leaving the other data wires alone. This file provides +that **register-lifting** machinery for a Pauli on the *first* data wire. + +## Main result + +* `measureObservableCircuit_onLeft` — `measureObservableCircuit (U.onLeft T) + = congr (assoc qubit S T).symm ((measureObservableCircuit U).onLeft T)`. + Measuring `U ⊗ 1_T` (the observable `U` on the first block `S`, identity on the rest `T`) with one + ancilla equals the two-block circuit `measureObservableCircuit U` (ancilla + `S`) run with `T` + carried along untouched, re-associated from `(qubit ⊗ S) ⊗ T` to the ancilla's native bracketing + `qubit ⊗ (S ⊗ T)`. This is the identity by which a Figure-10.16 controlled gate targeting one code + qubit becomes a Figure-10.17 gate on just the ancilla + that qubit (Exercise 10.59); combined with + the Figure 10.14 / 10.15 atomic identities it compiles the first factor of a stabilizer generator. + +## Supporting lemmas + +* `Evolution.congr_assoc_symm_onLeft_onLeft` / `controlledUnitary_congr_assoc_symm_onLeft` — the + per-gate transports: a Hadamard `g ⊗ 1_S ⊗ 1_T` re-associates to `g ⊗ 1_{S⊗T}`, and a controlled + gate `C(U) ⊗ 1_T` re-associates to `C(U ⊗ 1_T)`. +* `Evolution.congr_assoc_onRight_onRight` — the **onRight mirror** of the first: prepending two idle + heads `(E.onRight B).onRight A` re-associates to prepending their composite `E.onRight (A ⊗ B)`. + It is used in `CircuitBudget.onRight_qtower` (`AxQM/Core/CircuitBudgetOnRightTower.lean`). + +These rest on the following general facts: +* `Evolution.congr_comp` (system-iso transport is a composition homomorphism) is in + `AxQM/Postulates/API/SystemIsoComm.lean`, beside the other `Evolution.congr` combinator lemmas. +* the reshaping facts `LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL` (associator + naturality of `mapL`) and `LinearMap.assocIsometry_conjStarAlgEquiv_add` (additivity of the + associator conjugation) are general inner-product-space facts in + `ToMathlib/Analysis/InnerProductSpace/PartialTraceAbstract.lean`, beside the + associator-conjugation + family (`assocIsometry_conjStarAlgEquiv_toLinearMap`, …). + +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-! ### Per-gate transports across the associator -/ + +/-- **A left-factor gate re-associates.** A gate `g` on the first factor, embedded as +`(g ⊗ 1_S) ⊗ 1_T` on `(A ⊗ S) ⊗ T`, transports along the associator to `g ⊗ 1_{S⊗T}` on +`A ⊗ (S ⊗ T)`: `congr (assoc A S T).symm ((g.onLeft S).onLeft T) = g.onLeft (S ⊗ T)`. This carries +the ancilla Hadamard `H ⊗ 1` of the measurement block from the two-block bracketing to the ancilla's +native bracketing over the full data register. -/ +theorem Evolution.congr_assoc_symm_onLeft_onLeft {A : QSystem} (g : Evolution A) : + Evolution.congr (QSystem.assoc A S T).symm ((g.onLeft S).onLeft T) = g.onLeft (S ⊗ T) := by + ext1 + rw [Evolution.congr_op, QSystem.assoc_symm_toIsometry] + simp only [Evolution.onLeft, Evolution.tmul_op, Evolution.id_op] + refine (LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL g.op 1 1).trans ?_ + exact congrArg (TensorProduct.mapL g.op) TensorProduct.mapL_one + +/-- **Associator naturality for the right-factor embedding.** The onRight mirror of +`Evolution.congr_assoc_symm_onLeft_onLeft`. Prepending two idle head systems `B` then `A` to a gate +`E` on `R`, `(E.onRight B).onRight A = 1_A ⊗ (1_B ⊗ E)` on `A ⊗ (B ⊗ R)`, transports along the +associator to prepending their composite in one step, `E.onRight (A ⊗ B) = 1_{A⊗B} ⊗ E` on +`(A ⊗ B) ⊗ R`: `congr (assoc A B R) ((E.onRight B).onRight A) = E.onRight (A ⊗ B)`. Proved at the +operator level: `congr (assoc A B R)` conjugates by `(assocIsometry A B R).symm`, so the nested +right-embedding `mapL 1 (mapL 1 E.op)` re-associates to `mapL (mapL 1 1) E.op` +(`LinearMap.assocIsometry_symm_conjStarAlgEquiv_mapL_mapL`, the `.symm` sibling of the map used by +the onLeft twin), and the two idle factors collapse `mapL 1 1 = 1` (`TensorProduct.mapL_one`). Its +consumer is the tower-prepend budget closure `CircuitBudget.onRight_qtower` +(`Core/CircuitBudgetOnRightTower`), which iterates it to lift a gate budget over an idle qubit +tower. -/ +theorem Evolution.congr_assoc_onRight_onRight {R : QSystem} (E : Evolution R) (A B : QSystem) : + Evolution.congr (QSystem.assoc A B R) ((E.onRight B).onRight A) = E.onRight (A ⊗ B) := by + ext1 + rw [Evolution.congr_op, QSystem.assoc_toIsometry] + simp only [Evolution.onRight, Evolution.tmul_op, Evolution.id_op] + refine (LinearMap.assocIsometry_symm_conjStarAlgEquiv_mapL_mapL 1 1 E.op).trans ?_ + exact congrArg (fun X => TensorProduct.mapL X E.op) TensorProduct.mapL_one + +/-- **A controlled gate re-associates onto the first data block.** The controlled-`U` gate with its +target extended by an untouched register, `C(U) ⊗ 1_T` on `(qubit ⊗ S) ⊗ T`, transports along the +associator to the controlled gate whose target is the first block, `C(U ⊗ 1_T)` on +`qubit ⊗ (S ⊗ T)`: `congr (assoc qubit S T).symm ((controlledUnitary U).onLeft T) += controlledUnitary (U.onLeft T)`. The block-diagonal operator `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U` is split by +`LinearMap.assocIsometry_conjStarAlgEquiv_add` and each summand reshaped by +`LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL`. -/ +theorem controlledUnitary_congr_assoc_symm_onLeft (U : Evolution S) : + Evolution.congr (QSystem.assoc qubit S T).symm ((controlledUnitary U).onLeft T) + = controlledUnitary (U.onLeft T) := by + ext1 + rw [Evolution.congr_op, QSystem.assoc_symm_toIsometry] + simp only [Evolution.onLeft, Evolution.tmul_op, Evolution.id_op, controlledUnitary_op] + refine (congrArg _ (TensorProduct.mapL_add_left _ _ _)).trans + ((LinearMap.assocIsometry_conjStarAlgEquiv_add _ _).trans ?_) + exact congrArg₂ (· + ·) + ((LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL _ 1 1).trans + (congrArg _ TensorProduct.mapL_one)) + (LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL _ U.op 1) + +/-! ### The measurement circuit lifted onto a data register -/ + +/-- **The measurement circuit of a first-wire observable, lifted onto the data register.** Measuring +`U ⊗ 1_T` — the observable `U` on the first data block `S`, the identity on the remaining register +`T` — with one ancilla equals the two-block measurement circuit `measureObservableCircuit U` (on the +ancilla and `S`) with `T` carried along untouched, re-bracketed from `(qubit ⊗ S) ⊗ T` to the +ancilla's native `qubit ⊗ (S ⊗ T)`: +`measureObservableCircuit (U.onLeft T) + = congr (assoc qubit S T).symm ((measureObservableCircuit U).onLeft T)`. + +This is how a Nielsen & Chuang Figure-10.16 syndrome block — one ancilla controlling a Pauli that +targets a single code qubit while acting as the identity elsewhere — is expressed as a gate on just +the ancilla and that qubit (the Figure-10.17 form of Exercise 10.59). Combined with the Figure +10.14 / 10.15 atomic identities (`measureObservableCircuit pauliZGate = reversedCNOT`, and the `X` +analogue) it compiles the *first* factor of a generator to its reversed-CNOT form. + +Proof: unfold the block `(H ⊗ 1) · C(U) · (H ⊗ 1)`, distribute the `.onLeft T` extension and the +`congr (assoc).symm` transport across the three gates (`Evolution.onLeft_comp`, +`Evolution.congr_comp`), then reshape each gate with its per-gate transport +(`Evolution.congr_assoc_symm_onLeft_onLeft` for the two Hadamards, +`controlledUnitary_congr_assoc_symm_onLeft` for the controlled gate). -/ +theorem measureObservableCircuit_onLeft (U : Evolution S) (T : QSystem) : + measureObservableCircuit (U.onLeft T) + = Evolution.congr (QSystem.assoc qubit S T).symm ((measureObservableCircuit U).onLeft T) := by + simp only [measureObservableCircuit] + rw [← Evolution.onLeft_comp, ← Evolution.onLeft_comp, Evolution.congr_comp, Evolution.congr_comp, + Evolution.congr_assoc_symm_onLeft_onLeft, controlledUnitary_congr_assoc_symm_onLeft] + +/-! ### The measurement circuit lifted onto an interior data wire (the `onRight` transport) -/ + +/-- **Left-commutation naturality of `mapL`.** Conjugating a right-embedded operator +`1_A ⊗ (Y ⊗ Z)` (with `Y` on the ancilla-like middle factor `B` and `Z` on `C`) by the +left-commutation reshape `leftComm A B C` brings the middle operator `Y` to the front: +`leftComm.conjStarAlgEquiv (mapL X (mapL Y Z)) = mapL Y (mapL X Z)`. The `mapL` companion of the +`leftComm` pure-tensor action lemmas, proved by extensionality on triple tensors through +`conjStarAlgEquiv_apply_apply` and the `leftComm` forward / inverse tensor actions. This is the +reshaping fact that carries a gate on the *right* factor of a data register past a spectator `A` on +the left, the heart of `measureObservableCircuit_onRight`. -/ +theorem QSystem.Iso.leftComm_conjStarAlgEquiv_mapL_mapL {A B C : QSystem} + (X : A.space →L[ℂ] A.space) (Y : B.space →L[ℂ] B.space) (Z : C.space →L[ℂ] C.space) : + (QSystem.Iso.leftComm A B C).toIsometry.conjStarAlgEquiv + (TensorProduct.mapL X (TensorProduct.mapL Y Z)) + = TensorProduct.mapL Y (TensorProduct.mapL X Z) := by + apply ContinuousLinearMap.coe_injective + refine TensorProduct.ext_threefold' fun b a c => ?_ + rfl + +/-- **A middle-factor gate re-associates onto the ancilla wire.** A gate `g` on the middle factor +`B`, embedded as `1_A ⊗ (g ⊗ 1_C)` on `A ⊗ (B ⊗ C)`, transports along `leftComm` to `g ⊗ 1_{A⊗C}` +on `B ⊗ (A ⊗ C)`: `congr (leftComm A B C) ((g.onLeft C).onRight A) = g.onLeft (A ⊗ C)`. This carries +the ancilla Hadamard `H ⊗ 1` of the measurement block from behind a left spectator `A` to the +ancilla's native front position. -/ +theorem Evolution.congr_leftComm_onLeft_onRight {A B : QSystem} (g : Evolution B) : + Evolution.congr (QSystem.Iso.leftComm A B S) ((g.onLeft S).onRight A) = g.onLeft (A ⊗ S) := by + ext1 + rw [Evolution.congr_op] + simp only [Evolution.onLeft, Evolution.onRight, Evolution.tmul_op, Evolution.id_op] + rw [QSystem.Iso.leftComm_conjStarAlgEquiv_mapL_mapL] + exact congrArg (TensorProduct.mapL g.op) TensorProduct.mapL_one + +/-- **A controlled gate re-associates onto an interior data block.** The controlled-`U` gate with a +spectator register `A` on the left, `1_A ⊗ C(U)` on `A ⊗ (qubit ⊗ S)`, transports along `leftComm` +to the controlled gate whose target extends over `A`, `C(1_A ⊗ U) = C(U.onRight A)` on +`qubit ⊗ (A ⊗ S)`: `congr (leftComm A qubit S) ((controlledUnitary U).onRight A) += controlledUnitary (U.onRight A)`. The block-diagonal operator `|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U`, embedded +under `1_A ⊗ ·`, is split by `mapL_add_right` / additivity of the conjugation and each summand +reshaped by `leftComm_conjStarAlgEquiv_mapL_mapL`. -/ +theorem controlledUnitary_congr_leftComm_onRight (U : Evolution S) (A : QSystem) : + Evolution.congr (QSystem.Iso.leftComm A qubit S) ((controlledUnitary U).onRight A) + = controlledUnitary (U.onRight A) := by + ext1 + rw [Evolution.congr_op] + simp only [Evolution.onRight, Evolution.tmul_op, Evolution.id_op, controlledUnitary_op] + refine (congrArg _ (TensorProduct.mapL_add_right _ _ _)).trans + ((map_add (QSystem.Iso.leftComm A qubit S).toIsometry.conjStarAlgEquiv _ _).trans ?_) + exact congrArg₂ (· + ·) + ((QSystem.Iso.leftComm_conjStarAlgEquiv_mapL_mapL _ _ _).trans + (congrArg _ TensorProduct.mapL_one)) + (QSystem.Iso.leftComm_conjStarAlgEquiv_mapL_mapL _ _ _) + +/-- **The measurement circuit of an interior-wire observable, lifted onto the data register.** +Measuring `1_A ⊗ U` — the identity on a spectator register `A`, the observable `U` on the block `S` +to its right — with one ancilla equals the two-block measurement circuit +`measureObservableCircuit U` (on the ancilla and `S`) with `A` carried along untouched, re-bracketed +from `A ⊗ (qubit ⊗ S)` to the ancilla's native `qubit ⊗ (A ⊗ S)` by the left-commutation reshape: +`measureObservableCircuit (U.onRight A) + = congr (leftComm A qubit S) ((measureObservableCircuit U).onRight A)`. + +This is the `onRight` companion of `measureObservableCircuit_onLeft`: where `onLeft` lifts a Pauli +on the *first* data wire, this lifts one on an *interior* wire — a stabilizer generator's factor +sitting past the wires that precede it (Nielsen & Chuang Figure 10.16 → 10.17). Together with the +Figure 10.14 / 10.15 atomic identities it compiles any single factor of a generator to its +reversed-CNOT form, regardless of which data wire it acts on. + +Proof: unfold the block `(H ⊗ 1) · C(U) · (H ⊗ 1)`, distribute the `.onRight A` extension +(`Evolution.onRight_comp`) and the `congr (leftComm)` transport (`Evolution.congr_comp`) across the +three gates, then reshape each gate with its per-gate transport +(`Evolution.congr_leftComm_onLeft_onRight` for the two ancilla Hadamards, +`controlledUnitary_congr_leftComm_onRight` for the controlled gate). -/ +theorem measureObservableCircuit_onRight (U : Evolution S) (A : QSystem) : + measureObservableCircuit (U.onRight A) + = Evolution.congr (QSystem.Iso.leftComm A qubit S) + ((measureObservableCircuit U).onRight A) := by + simp only [measureObservableCircuit] + rw [← Evolution.onRight_comp, ← Evolution.onRight_comp, Evolution.congr_comp, + Evolution.congr_comp, Evolution.congr_leftComm_onLeft_onRight, + controlledUnitary_congr_leftComm_onRight] + +/-! ### The measurement circuit lifted onto an interior data wire with spectators on both sides -/ + +/-- **The measurement circuit of a both-spectator interior-wire observable, lifted onto the data +register.** Measuring `1_A ⊗ U ⊗ 1_B` — the observable `U` on a data block flanked by a spectator +register `A` on its left *and* a spectator register `B` on its right — with one ancilla equals the +two-block measurement circuit `measureObservableCircuit U` (on the ancilla and `U`'s block) with `A` +and `B` carried along untouched, re-bracketed to the ancilla's native front: +`measureObservableCircuit ((U.onLeft B).onRight A) = congr (leftComm A qubit (S ⊗ B)) + ((congr (assoc qubit S B).symm ((measureObservableCircuit U).onLeft B)).onRight A)`. + +This is the genuine **interior-wire** lift — the composite `onRight ∘ onLeft` that +`measureObservableCircuit_onLeft` (a first wire, spectator only on the right) and +`measureObservableCircuit_onRight` (a wire with a spectator only on the left) do not individually +reach. Every code qubit strictly between the first and the last of a Nielsen & Chuang Figure-10.16 +data register is exactly such a both-spectator factor. Proof: strip the right spectator `B` with +`measureObservableCircuit_onLeft`, then the left spectator `A` with +`measureObservableCircuit_onRight` — the two one-sided lifts compose with no new physical content, +only nested reshaping. -/ +theorem measureObservableCircuit_onMiddle (U : Evolution S) (A B : QSystem) : + measureObservableCircuit ((U.onLeft B).onRight A) + = Evolution.congr (QSystem.Iso.leftComm A qubit (S ⊗ B)) + ((Evolution.congr (QSystem.assoc qubit S B).symm + ((measureObservableCircuit U).onLeft B)).onRight A) := by + rw [measureObservableCircuit_onRight, measureObservableCircuit_onLeft] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementCoarseGrain.lean b/LeanPool/AxQM/Postulates/API/MeasurementCoarseGrain.lean new file mode 100644 index 0000000000..7726d238c3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementCoarseGrain.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SquareRootMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVMMap + +/-! +# Coarse-graining the outcomes of a measurement + +Given a measurement `m : Measurement ι S` and a function `g : ι → κ` on the outcome index, the +**coarse-grained measurement** `m.coarseGrain g : Measurement κ S` groups (merges) the original +outcomes according to `g`: measuring `m.coarseGrain g` and obtaining `k` has the summed Born +probability of all original outcomes lying over `k`, + +`(m.coarseGrain g).bornProb ρ k = ∑_{i : g i = k} m.bornProb ρ i` (`coarseGrain_bornProb`). + +It is realised as the **square-root measurement** (`Measurement.ofPOVM`) of the pushforward POVM +`m.toPOVM.map g` (`POVM.map`): the induced POVM effect at `k` is the fibre-sum `∑_{g i = k} Eᵢ` of +`m`'s effects, and `ofPOVM` supplies canonical measurement operators (the operator square roots) +realising it. Since the physically observable content of a measurement is its Born rule (the +induced POVM), this is *the* coarse-graining: `reindexOutcome` (relabelling along an equivalence) +is the special case where `g` is a bijection and every fibre is a singleton. + +The intended use is the **achievability half of the Holevo–Schumacher–Westmoreland theorem** +(`χ(E) = C⁽¹⁾(E)`, Nielsen & Chuang Theorem 12.8): the *expurgation* step (N&C eq. (12.83)) passes +from a code with small **average** error to a subcode with small **maximum** error by discarding +the worst messages. The subcode's decoder is the original decoder with the outcomes announcing a +discarded message folded into the inconclusive outcome — exactly a coarse-graining along a +function `Option (Fin K) → Option (Fin K')` that carries each retained message to itself. +`coarseGrain_bornProb_of_filter_eq_singleton` records that such a *retained* (singleton-fibre) +outcome keeps its original Born probability, so the retained messages' error probabilities are +preserved. + +## Main definitions / results + +* `AxQM.Measurement.coarseGrain` — the coarse-grained measurement along `g : ι → κ`. +* `AxQM.Measurement.coarseGrain_bornProb` — its Born rule, + `(m.coarseGrain g).bornProb ρ k = ∑_{i : g i = k} m.bornProb ρ i`. +* `AxQM.Measurement.coarseGrain_bornProb_of_filter_eq_singleton` — a retained + (singleton-fibre) outcome keeps its Born probability, + `(m.coarseGrain g).bornProb ρ k = m.bornProb ρ i₀`. + +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +namespace Measurement + +variable {ι : Type*} [Fintype ι] {κ : Type*} [Fintype κ] [DecidableEq κ] {S : QSystem} + +/-- **Coarse-graining the outcomes of a measurement.** For a measurement `m : Measurement ι S` and a +function `g : ι → κ`, `m.coarseGrain g` is the measurement on `S` with outcome set `κ` that merges +the original outcomes along `g`. It is the square-root measurement (`Measurement.ofPOVM`) of the +pushforward POVM `m.toPOVM.map g`, whose effect at `k` is the fibre-sum `∑_{i : g i = k} Eᵢ` +of `m`'s effects. Its Born rule is the grouped Born rule `coarseGrain_bornProb`. -/ +def coarseGrain (m : Measurement ι S) (g : ι → κ) : Measurement κ S := + Measurement.ofPOVM (m.toPOVM.map g) + +/-- **Born rule of the coarse-grained measurement.** The probability that `m.coarseGrain g` assigns +to the merged outcome `k` on a state `ρ` is the sum of the probabilities `m` assigns to the original +outcomes lying over `k`: `(m.coarseGrain g).bornProb ρ k = ∑_{i : g i = k} m.bornProb ρ i`. +Combines the square-root measurement's Born rule (`ofPOVM_bornProb`) with the pushforward POVM's +Born rule +(`POVM.map_toPMF`); the summand `m.toPOVM.toPMF ρ.op i` is `m.bornProb ρ i` by definition. -/ +theorem coarseGrain_bornProb (m : Measurement ι S) (g : ι → κ) (ρ : State S) (k : κ) : + (m.coarseGrain g).bornProb ρ k = + ∑ i ∈ Finset.univ.filter (fun i => g i = k), m.bornProb ρ i := by + rw [coarseGrain, Measurement.ofPOVM_bornProb, POVM.map_toPMF] + rfl + +/-- **A retained (singleton-fibre) outcome keeps its Born probability.** If the fibre of `g` +over `k` is the single outcome `i₀` (its `filter` is `{i₀}`), then `m.coarseGrain g` assigns `k` +exactly the +Born probability `m` assigned to `i₀`: `(m.coarseGrain g).bornProb ρ k = m.bornProb ρ i₀`. This is +the outcome-preservation used by HSW expurgation, where each retained message's decoding outcome has +a singleton fibre. -/ +theorem coarseGrain_bornProb_of_filter_eq_singleton (m : Measurement ι S) (g : ι → κ) (ρ : State S) + (k : κ) (i₀ : ι) (h : Finset.univ.filter (fun i => g i = k) = {i₀}) : + (m.coarseGrain g).bornProb ρ k = m.bornProb ρ i₀ := by + rw [coarseGrain_bornProb, h, Finset.sum_singleton] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementExt.lean b/LeanPool/AxQM/Postulates/API/MeasurementExt.lean new file mode 100644 index 0000000000..c9f8ab8d1c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementExt.lean @@ -0,0 +1,47 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# Extensionality for measurements + +A `Measurement ι S` is its family of operators `op : ι → (S →L[ℂ] S)` together with a +*completeness* proof (a `Prop`). Two measurements with the same operators are therefore equal — +the completeness proofs coincide by proof irrelevance. `Measurement.ext_op` packages this so a +measurement identity can be reduced to a pointwise operator identity (the analogue of function +extensionality). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +namespace Measurement + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +/-- **Extensionality for measurements.** Two measurements on the same system with the same outcome +set are equal as soon as their operators agree at every outcome: the completeness proofs are +propositions and coincide by proof irrelevance. -/ +theorem ext_op {m₁ m₂ : Measurement ι S} (h : ∀ i, m₁.op i = m₂.op i) : m₁ = m₂ := by + cases m₁ with + | mk op₁ c₁ => + cases m₂ with + | mk op₂ c₂ => + have hop : op₁ = op₂ := funext h + subst hop + rfl + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementModel.lean b/LeanPool/AxQM/Postulates/API/MeasurementModel.lean new file mode 100644 index 0000000000..f669907c48 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementModel.lean @@ -0,0 +1,436 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.ProjectiveMeasurement +public import LeanPool.AxQM.Postulates.API.GeneralMeasurementEnvironment +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumDilation +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneProjector +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# AxQM — the measurement model of a set of quantum operations (N&C Exercise 8.9) + +The **measurement model** of Nielsen–Chuang Exercise 8.9. +Given a set of quantum operations `{Eₘ}` whose sum `∑ₘ Eₘ` is trace preserving, presented flatly by +a family of operation elements `E : ι → (Q →L Q)` (the `E_{mk}` of the exercise) together with a +labelling `out : ι → M` recording which outcome each element belongs to (`out (m,k) = m`), and an +environment `Env` with an orthonormal basis `b : OrthonormalBasis ι ℂ Env` in one-to-one +correspondence with the operation-element indices and a standard unit state `e₀`, this file +constructs the two physical objects the exercise measures: + +* `Measurement.ofOrthonormalBasisFiber b out` — the **environment measurement** with block + projectors `Pₘ = ∑_{out σ = m} |b σ⟩⟨b σ|` (Nielsen–Chuang's `Pₘ ≡ ∑ₖ |m,k⟩⟨m,k|`). This is a + genuine projective measurement (`Measurement.isProjective_ofOrthonormalBasisFiber`): each `Pₘ` is + an orthogonal projector (`InnerProductSpace.orthonormalProjector` of an orthonormal family) and + the `Pₘ` resolve the identity because the fibres of `out` partition the basis. +* `measurementModelEvolution b he₀ E hE` — the **joint unitary** `U` (Nielsen–Chuang eq. (8.40)), + packaged as an `Evolution (Q ⊗ Env)`. On the standard-ancilla slice it acts as the Stinespring + dilation `V₀` assembled from the Kraus family, `U (ψ ⊗ e₀) = ∑_σ (E σ ψ) ⊗ (b σ)` + (`measurementModelEvolution_op_tmul`). It exists as a *unitary* because the trace preservation of + `∑ₘ Eₘ`, `∑_σ (E σ)† (E σ) = 1`, makes `V₀` an isometry, which extends to a unitary of the joint + space (N&C Exercise 2.67 / Box 8.1). + +Building on that construction, this file proves the substance of Exercise 8.9 — that +measuring `Pₘ` after `U` gives outcome `m` with probability `tr(Eₘ ρ)` and post-measurement state +`Eₘ(ρ)/tr(Eₘ(ρ))`: + +* `measurementModelInducedOp E out ρ m` — the **induced operation element** `Eₘ(ρ) = ∑_{out σ = m} + E_σ ρ E_σ†` on the principal system, collecting the operation elements labelled `m`. +* `measurementModelEnvOp_eq_inducedOp` — the **induced-operation identity** + `tr_E(Pₘ U (ρ ⊗ |e₀⟩⟨e₀|) U† Pₘ) = Eₘ(ρ)`, obtained by instantiating Exercise 8.7's general + system–environment induced operation `generalMeasurementEnvOp` at the model's lifted measurement + `Pₘ ⊗ 1`, unitary `U`, and standard environment state `|e₀⟩⟨e₀|`, and evaluating the projected + partial trace with the projected environment operator-sum lemma + `LinearMap.partialTraceRight_conj_sum_proj_eq_sum_krausOp`. +* `measurementModel_bornProb_eq_trace` — **probability:** `p(m) = tr(Eₘ ρ)`, and +* `measurementModel_reducedLeft_postMeasurement_op` — **post-measurement state:** the principal + system's reduced state after a possible outcome `m` is `Eₘ(ρ)/tr(Eₘ(ρ))`. + +The statement of Exercise 8.9, for states, measurements and evolutions, is in +[upstream `AxQM/NC/Ch8/Exercise8_9.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_9.lean). + +## Construction of the unitary + +The unitary reuses the converse-dilation package +(`ToMathlib.Analysis.InnerProductSpace.OperatorSumDilation`): +`LinearMap.exists_unitary_krausDilation` +supplies the unitary extension of the assembled dilation `V₀ = krausDilation b E` (an isometry by +completeness), and `Evolution.ofLinearIsometryEquiv` promotes it to an `Evolution`. The +completeness hypothesis is stated in the physical `ContinuousLinearMap` form `∑_σ (E σ)† (E σ) = 1` +and bridged to the `LinearMap` form that package expects by the general lemma +`ContinuousLinearMap.sum_adjoint_comp_toLinearMap_eq_id`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §8.2 (System–environment models; Box 8.1; Exercise 8.9). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-! ### The environment's block-projective measurement `Pₘ` -/ + +variable {ι M : Type*} [Fintype ι] [Fintype M] [DecidableEq M] {S : QSystem} + +/-- **The block-projective measurement grouped by a labelling** `out : ι → M` of an orthonormal +basis `b` of `S` (Nielsen–Chuang Exercise 8.9's environment measurement `Pₘ ≡ ∑ₖ |m,k⟩⟨m,k|`). +Outcome `m` has measurement operator the orthogonal projector +`Pₘ = ∑_{σ : out σ = m} |b σ⟩⟨b σ|` (`InnerProductSpace.orthonormalProjector` of the sub-family of +basis vectors labelled `m`). + +Completeness `∑ₘ Pₘ† Pₘ = 1` holds because each `Pₘ` is a star projection (a self-adjoint +idempotent, `InnerProductSpace.isStarProjection_orthonormalProjector`), so `Pₘ† Pₘ = Pₘ`, and the +fibres of `out` partition the basis (`Finset.sum_fiberwise`), so `∑ₘ Pₘ = ∑_σ |b σ⟩⟨b σ| = 1` is +the resolution of the identity (`OrthonormalBasis.sum_rankOne_eq_id`). -/ +def Measurement.ofOrthonormalBasisFiber (b : OrthonormalBasis ι ℂ S) (out : ι → M) : + Measurement M S where + op m := orthonormalProjector ℂ (⇑b) (Finset.univ.filter (fun σ => out σ = m)) + complete := by + set P : Finset ι → (S →L[ℂ] S) := orthonormalProjector ℂ (⇑b) with hP + have hsq : ∀ s : Finset ι, (adjoint (P s)).comp (P s) = P s := by + intro s + have hsp : IsStarProjection (P s) := + hP ▸ isStarProjection_orthonormalProjector b.orthonormal s + rw [← ContinuousLinearMap.star_eq_adjoint, hsp.isSelfAdjoint.star_eq, + ← ContinuousLinearMap.mul_def] + exact hsp.isIdempotentElem + calc ∑ m, (adjoint (P (Finset.univ.filter (fun σ => out σ = m)))).comp + (P (Finset.univ.filter (fun σ => out σ = m))) + = ∑ m, P (Finset.univ.filter (fun σ => out σ = m)) := + Finset.sum_congr rfl fun m _ => hsq _ + _ = ∑ σ, rankOne ℂ (b σ) (b σ) := by + rw [hP]; exact Finset.sum_fiberwise Finset.univ out (fun σ => rankOne ℂ (b σ) (b σ)) + _ = 1 := by rw [b.sum_rankOne_eq_id, ← ContinuousLinearMap.one_def] + +@[simp] +theorem Measurement.ofOrthonormalBasisFiber_op (b : OrthonormalBasis ι ℂ S) (out : ι → M) (m : M) : + (Measurement.ofOrthonormalBasisFiber b out).op m + = orthonormalProjector ℂ (⇑b) (Finset.univ.filter (fun σ => out σ = m)) := rfl + +/-- The environment measurement `Measurement.ofOrthonormalBasisFiber b out` is **projective** (von +Neumann): each block operator `Pₘ` is an orthogonal projector +(`InnerProductSpace.isStarProjection_orthonormalProjector`), which is exactly the defining condition +`Measurement.IsProjective`. -/ +theorem Measurement.isProjective_ofOrthonormalBasisFiber (b : OrthonormalBasis ι ℂ S) + (out : ι → M) : (Measurement.ofOrthonormalBasisFiber b out).IsProjective := fun m => + isStarProjection_orthonormalProjector b.orthonormal (Finset.univ.filter (fun σ => out σ = m)) + +/-! ### The two-outcome measurement `{P, 1 − P}` of an orthogonal projector -/ + +/-- **The two-outcome von Neumann measurement `{P, 1 − P}` of an orthogonal projector** `P` +(`hP : IsStarProjection P`): outcome `true` has measurement operator `P` and outcome `false` has +`1 − P`. Completeness `∑_b Mᵦ† Mᵦ = 1` holds because both `P` and `1 − P` are star projections +(`IsStarProjection.one_sub`), so `Mᵦ† Mᵦ = Mᵦ` and `P + (1 − P) = 1`. This is the faithful reading +of "measure whether the state lies in the subspace `range P`", and gives a `Measurement` from an +arbitrary projector — the projector-indexed sibling of `Measurement.ofOrthonormalBasisFiber`. -/ +def Measurement.ofStarProjection (P : S.space →L[ℂ] S.space) (hP : IsStarProjection P) : + Measurement Bool S where + op b := cond b P (1 - P) + complete := by + have key : ∀ Q : S.space →L[ℂ] S.space, IsStarProjection Q → + (adjoint Q).comp Q = Q := fun Q hQ => by + rw [hQ.isSelfAdjoint.adjoint_eq, ← ContinuousLinearMap.mul_def] + exact hQ.isIdempotentElem + rw [Fintype.sum_bool, Bool.cond_true, Bool.cond_false, key _ hP, key _ hP.one_sub] + abel + +@[simp] +theorem Measurement.ofStarProjection_op_true (P : S.space →L[ℂ] S.space) + (hP : IsStarProjection P) : (Measurement.ofStarProjection P hP).op true = P := rfl + +@[simp] +theorem Measurement.ofStarProjection_op_false (P : S.space →L[ℂ] S.space) + (hP : IsStarProjection P) : (Measurement.ofStarProjection P hP).op false = 1 - P := rfl + +/-- The measurement `Measurement.ofStarProjection P hP` is **projective** (von Neumann): both +outcome operators `P` and `1 − P` are star projections. -/ +theorem Measurement.isProjective_ofStarProjection (P : S.space →L[ℂ] S.space) + (hP : IsStarProjection P) : (Measurement.ofStarProjection P hP).IsProjective := by + rintro (_ | _) + · exact hP.one_sub + · exact hP + +/-- **Born-rule bridge for `{P, 1 − P}`**: on any state `τ`, the probability of outcome `true` +(landing in `range P`) is `re tr(P τ)`. Proof: `bornProb = re tr(P† P τ)` +(`bornProb_eq_re_trace_postOp`, `trace_postOp`), and `P† P = P` since `P` is a self-adjoint +idempotent. -/ +theorem Measurement.bornProb_ofStarProjection_true (P : S.space →L[ℂ] S.space) + (hP : IsStarProjection P) (τ : State S) : + (Measurement.ofStarProjection P hP).bornProb τ true + = RCLike.re ((LinearMap.trace ℂ S.space) + ((P.comp τ.op : S.space →L[ℂ] S.space) : S.space →ₗ[ℂ] S.space)) := by + have hPP : P.comp P = P := by rw [← ContinuousLinearMap.mul_def]; exact hP.isIdempotentElem + rw [Measurement.bornProb_eq_re_trace_postOp, ContinuousLinearMap.trace_postOp, + Measurement.ofStarProjection_op_true, hP.isSelfAdjoint.adjoint_eq, + ← ContinuousLinearMap.comp_assoc, hPP] + +/-! ### The joint unitary of the measurement model -/ + +variable {Q Env : QSystem} + +/-- **The joint unitary of the measurement model** (Nielsen–Chuang Exercise 8.9, eq. (8.40)). From +a family of operation elements `E : ι → (Q →L Q)` for a trace-preserving `∑ₘ Eₘ` +(`hE : ∑_σ (E σ)† (E σ) = 1`), an orthonormal environment basis `b` in one-to-one correspondence +with the indices, and a standard unit environment state `e₀`, the joint dynamics is the unitary `U` +acting as `U (ψ ⊗ e₀) = ∑_σ (E σ ψ) ⊗ (b σ)` (`measurementModelEvolution_op_tmul`), packaged as an +`Evolution (Q ⊗ Env)`. + +It is genuinely unitary: the Stinespring dilation `V₀ = krausDilation b E` is an isometry (by the +completeness `hE`), and an isometry defined on the standard-ancilla slice extends to a unitary of +the joint space (N&C Exercise 2.67; the block-matrix freedom of Box 8.1). Obtained from +`LinearMap.exists_unitary_krausDilation` (the unitary extension) promoted to an +`Evolution` by `Evolution.ofLinearIsometryEquiv`. -/ +def measurementModelEvolution (b : OrthonormalBasis ι ℂ Env) {e₀ : Env.space} (he₀ : ‖e₀‖ = 1) + (E : ι → (Q →L[ℂ] Q)) (hE : ∑ σ, (adjoint (E σ)).comp (E σ) = 1) : + Evolution (Q ⊗ Env) := + Evolution.ofLinearIsometryEquiv + (LinearMap.exists_unitary_krausDilation b (fun σ => (E σ).toLinearMap) + (ContinuousLinearMap.sum_adjoint_comp_toLinearMap_eq_id E hE) he₀).choose + +/-- **The joint unitary on the standard-ancilla slice** (Nielsen–Chuang Exercise 8.9, eq. (8.40)): +`U (ψ ⊗ e₀) = ∑_σ (E σ ψ) ⊗ (b σ)`. This is the defining action `V₀` of the measurement model — the +Stinespring dilation assembled from the Kraus family — and the key identity the induced-operation +computation is built on. Immediate from the defining property of the unitary extension +(`LinearMap.exists_unitary_krausDilation`) and `LinearMap.krausDilation_apply`. -/ +theorem measurementModelEvolution_op_tmul (b : OrthonormalBasis ι ℂ Env) {e₀ : Env.space} + (he₀ : ‖e₀‖ = 1) (E : ι → (Q →L[ℂ] Q)) (hE : ∑ σ, (adjoint (E σ)).comp (E σ) = 1) (ψ : Q) : + (measurementModelEvolution b he₀ E hE).op (ψ ⊗ₜ[ℂ] e₀) = ∑ σ, E σ ψ ⊗ₜ[ℂ] b σ := by + have hex := LinearMap.exists_unitary_krausDilation b (fun σ => (E σ).toLinearMap) + (ContinuousLinearMap.sum_adjoint_comp_toLinearMap_eq_id E hE) he₀ + -- Name the isometry at the *bundled* `(Q ⊗ Env).space` type via a `let` (rather than an inline + -- ascription, which does not stick): `measurementModelEvolution` unfolds to + -- `Evolution.ofLinearIsometryEquiv hex.choose`, but `hex.choose`'s own natural type carries the + -- *generic* `Q.space ⊗[ℂ] Env.space` instances, so `rw`'s syntactic pattern matching against + -- `Evolution.ofLinearIsometryEquiv_op_apply`'s bundled-`S.space` pattern cannot fire directly on + -- the unfolded definition. A `let`-bound name declared at the bundled type is `zeta`-transparent, + -- so the following `rfl` (checked at full elaboration transparency, unlike `rw`) can still bridge + -- it back to `hex.choose`. + let L₀ : (Q ⊗ Env).space ≃ₗᵢ[ℂ] (Q ⊗ Env).space := hex.choose + -- The argument `ψ ⊗ₜ[ℂ] e₀` is itself typed at the *generic* `Q.space ⊗[ℂ] Env.space`, so `rw`'s + -- pattern for `Evolution.ofLinearIsometryEquiv_op_apply` (needing a syntactically bundled + -- argument) cannot fire on it either; instantiate the lemma directly (an ordinary application, + -- checked up to full defeq) instead of `rw`-matching it. + have hop_apply := Evolution.ofLinearIsometryEquiv_op_apply L₀ (ψ ⊗ₜ[ℂ] e₀) + rw [show measurementModelEvolution b he₀ E hE = Evolution.ofLinearIsometryEquiv L₀ from rfl, + hop_apply] + have hspec := hex.choose_spec ψ + rw [LinearMap.krausDilation_apply] at hspec + simp only [ContinuousLinearMap.coe_coe] at hspec + exact hspec + +/-! ### The induced operation and the measurement-model identities + +With the two physical objects of the model in hand — the environment block-projective measurement +`Pₘ` (`Measurement.ofOrthonormalBasisFiber`) and the joint unitary `U` (`measurementModelEvolution`) +— this section discharges what Exercise 8.9 asks to *show*: performing `U` on `ρ ⊗ |e₀⟩⟨e₀|` and +then measuring `Pₘ` on the environment induces the operation `Eₘ(ρ) = ∑_{out σ = m} E_σ ρ E_σ†`, +with outcome probability `tr(Eₘ ρ)` and post-measurement principal state `Eₘ(ρ)/tr(Eₘ ρ)`. + +The induced operation is obtained by *instantiating* Exercise 8.7's general system–environment +machinery (`generalMeasurementEnvOp`, `bornProb_eq_trace_generalMeasurementEnvOp`) at the model's +lifted measurement `Pₘ ⊗ 1` (`Measurement.onRight`), the model unitary `U`, and the standard +environment state `|e₀⟩⟨e₀|`, then evaluating the resulting partial trace with the projected +environment operator-sum lemma `LinearMap.partialTraceRight_conj_sum_proj_eq_sum_krausOp`. -/ + +/-- **The `m`-th induced operation element of the measurement model** (Nielsen–Chuang Exercise 8.9): +`Eₘ(ρ) = ∑_{out σ = m} E_σ ρ E_σ†`, the quantum operation `Eₘ` of the labelled Kraus family applied +to the principal state `ρ`, collecting exactly the operation elements `E_σ` whose outcome label is +`m` (N&C's `Eₘ(ρ) = ∑ₖ E_{mk} ρ E_{mk}†`). -/ +def measurementModelInducedOp (E : ι → (Q →L[ℂ] Q)) (out : ι → M) (ρ : State Q) (m : M) : + Q →L[ℂ] Q := + ∑ σ ∈ Finset.univ.filter (fun σ => out σ = m), (E σ).comp (ρ.op.comp (adjoint (E σ))) + +/-- **The induced-operation identity of the measurement model** (Nielsen–Chuang Exercise 8.9): the +general system–environment induced operation of Exercise 8.7 (`generalMeasurementEnvOp`), evaluated +at the model's lifted environment measurement `Pₘ ⊗ 1` (`Measurement.ofOrthonormalBasisFiber b out` +on the right, `Measurement.onRight`), its joint unitary `U = measurementModelEvolution`, and the +standard environment state `|e₀⟩⟨e₀|`, equals the `m`-th induced operation element `Eₘ(ρ)`: + + `tr_E(Pₘ U (ρ ⊗ |e₀⟩⟨e₀|) U† Pₘ) = ∑_{out σ = m} E_σ ρ E_σ†`. + +Proof: rewrite the Exercise 8.2 operation element of the lifted (self-adjoint) measurement `Pₘ ⊗ 1` +on the evolved state into the projector-conjugated ancilla form +`P_S (U (ρ ⊗ |e₀⟩⟨e₀|) U†) P_S`, with `P_S = ∑_{out σ = m} embedRight b σ ∘ₗ restrictRight b σ` the +environment block projector (`hPm`, `hMsa`); switch the partial trace to the basis `b` +(`LinearMap.partialTraceRight_eq_of_basis`), then apply the projected-and-ancilla +operator-sum lemma `LinearMap.partialTraceRight_conj_sum_proj_map_rankOne_eq_sum_krausOp`, whose +elements `krausOp b (U.op ∘ (·⊗e₀)) σ = E_σ` are read off from +`measurementModelEvolution_op_tmul`/`LinearMap.krausOp_krausDilation`. The underlying operator of +the unitary is pinned to a single representative `U₀` throughout so the composite-system space +`(Q ⊗ Env).space` and the plain tensor `Q.space ⊗ Env.space` never diverge under `rw`. -/ +theorem measurementModelEnvOp_eq_inducedOp (b : OrthonormalBasis ι ℂ Env) {e₀ : Env.space} + (he₀ : ‖e₀‖ = 1) (E : ι → (Q →L[ℂ] Q)) (hE : ∑ σ, (adjoint (E σ)).comp (E σ) = 1) + (out : ι → M) (ρ : State Q) (m : M) : + generalMeasurementEnvOp ((Measurement.ofOrthonormalBasisFiber b out).onRight Q) + (measurementModelEvolution b he₀ E hE) (⟨e₀, he₀⟩ : PureState Env).toState ρ m + = measurementModelInducedOp E out ρ m := by + -- Pin one representative `U₀` of the unitary's underlying operator so the composite-system + -- space `(Q ⊗ Env).space` and the raw tensor `Q.space ⊗ Env.space` never diverge under `rw`. + set U₀ : Q.space ⊗[ℂ] Env.space →ₗ[ℂ] Q.space ⊗[ℂ] Env.space := + (measurementModelEvolution b he₀ E hE).op.toLinearMap with hU₀ + clear_value U₀ + -- The lifted environment measurement `Pₘ ⊗ 1` is the block projector + -- `P_S = ∑_{out σ = m} embedRight b σ ∘ₗ restrictRight b σ`. + have hPm : (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).op m).toLinearMap + = ∑ σ ∈ Finset.univ.filter (fun σ => out σ = m), + LinearMap.embedRight b σ ∘ₗ LinearMap.restrictRight b σ := by + rw [Measurement.onRight_op, Measurement.ofOrthonormalBasisFiber_op, + TensorProduct.toLinearMap_mapL, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, + InnerProductSpace.orthonormalProjector, ContinuousLinearMap.toLinearMap_sum] + simp only [LinearMap.embedRight_comp_restrictRight_eq_map_rankOne, + ← TensorProduct.mapBilinear_apply, map_sum] + rfl + -- The lifted measurement operator `Pₘ ⊗ 1` is self-adjoint (a real, self-adjoint projector): + -- its underlying operator is the block projector, whose Hermiticity is the lemma + -- `LinearMap.adjoint_sum_embedRight_comp_restrictRight` (bridged over the mixed composite space + -- to the plain tensor by `exact`/defeq). `ContinuousLinearMap.adjoint_toLinearMap` is now the + -- upstream lemma in the opposite orientation; `_of_completeSpace` keeps the original orientation + -- (`ToMathlib.Analysis.InnerProductSpace.Adjoint`). + have hMsa : adjoint (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).op m) + = ((Measurement.ofOrthonormalBasisFiber b out).onRight Q).op m := by + refine ContinuousLinearMap.coe_injective ?_ + rw [ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace, hPm] + exact LinearMap.adjoint_sum_embedRight_comp_restrictRight b _ + -- The underlying linear map of `U.op†` is the linear-map adjoint of the pinned representative + -- `U₀`. + have hUadj : (adjoint (measurementModelEvolution b he₀ E hE).op).toLinearMap + = LinearMap.adjoint U₀ := by + rw [hU₀] + exact ContinuousLinearMap.adjoint_toLinearMap _ + -- The Stinespring dilation `V₀ = U.op ∘ (·⊗e₀) = krausDilation b E`, so `krausOp b V₀ σ = E_σ`. + have hUV : U₀ ∘ₗ LinearMap.tmulRightVec e₀ + = LinearMap.krausDilation b (fun σ => (E σ).toLinearMap) := by + rw [hU₀] + refine LinearMap.ext fun ψ => ?_ + change (measurementModelEvolution b he₀ E hE).op (ψ ⊗ₜ[ℂ] e₀) + = LinearMap.krausDilation b (fun σ => (E σ).toLinearMap) ψ + rw [measurementModelEvolution_op_tmul, LinearMap.krausDilation_apply] + simp only [ContinuousLinearMap.coe_coe] + rfl + -- Pin the generic-typed operation element of the lifted measurement on the evolved state via a + -- `let` (rather than an inline ascription, which does not stick, or unfolding + -- `generalMeasurementEnvOp` directly, whose own definition-site type ascription similarly does + -- not survive delta-unfolding): `Xgeneric`'s *declared* type is the plain tensor, so both the + -- later `LinearMap.partialTraceRight_eq_of_basis` rewrite and `hbridge` below can fire by + -- ordinary syntactic matching against this name, with `rfl`/`show` (full transparency, not `rw`'s + -- restricted matching) doing the actual bundled-vs-generic bridging. + let Xgeneric : Q.space ⊗[ℂ] Env.space →ₗ[ℂ] Q.space ⊗[ℂ] Env.space := + (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).opElement + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m).toLinearMap + have hgen : generalMeasurementEnvOp ((Measurement.ofOrthonormalBasisFiber b out).onRight Q) + (measurementModelEvolution b he₀ E hE) (⟨e₀, he₀⟩ : PureState Env).toState ρ m + = (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ Env.space) Xgeneric).toContinuousLinearMap + := rfl + -- The Exercise 8.2 operation element of the lifted measurement on the evolved state, as a + -- projector-conjugated ancilla dilation `P_S (U (ρ ⊗ |e₀⟩⟨e₀|) U†) P_S`. `.toLinearMap` is + -- distributed *fully*, over the still-entirely-bundled `(Q ⊗ Env).space` composite, *before* + -- `State.tmul_op` ever introduces the generic-instanced `TensorProduct.mapL ρ.op σ.op` term: + -- doing + -- the generic swap first would leave it sitting next to the still-bundled `adjoint U.op` inside a + -- `∘L`/`∘ₗ` node whose own implicit instance args were already fixed (bundled) when that node was + -- built, blocking any further `ContinuousLinearMap.toLinearMap_comp` match on that node. Once + -- fully + -- distributed, every atomic bundled leaf is isolated (no `.comp` sibling left to conflict with), + -- so + -- `State.tmul_op`/`PureState.toState_op`/`TensorProduct.toLinearMap_mapL`/`hUadj`/`hPm`/`← hU₀` + -- can + -- each rewrite its own leaf in place by ordinary syntactic matching. + have hbridge : Xgeneric + = (∑ σ ∈ Finset.univ.filter (fun σ => out σ = m), + LinearMap.embedRight b σ ∘ₗ LinearMap.restrictRight b σ) ∘ₗ + (U₀ ∘ₗ + TensorProduct.map ρ.op.toLinearMap (InnerProductSpace.rankOne ℂ e₀ e₀).toLinearMap ∘ₗ + LinearMap.adjoint U₀) ∘ₗ + (∑ σ ∈ Finset.univ.filter (fun σ => out σ = m), + LinearMap.embedRight b σ ∘ₗ LinearMap.restrictRight b σ) := by + change (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).opElement + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m).toLinearMap = _ + rw [Measurement.opElement_eq_postOp, ContinuousLinearMap.postOp, hMsa, Evolution.evolve_op] + simp only [ContinuousLinearMap.toLinearMap_comp] + rw [State.tmul_op, PureState.toState_op, TensorProduct.toLinearMap_mapL, hUadj, hPm, ← hU₀] + rfl + -- The projected environment operator-sum lemma, with `W = U₀` supplied explicitly. + have hfork := LinearMap.partialTraceRight_conj_sum_proj_map_rankOne_eq_sum_krausOp + b U₀ e₀ ρ.op.toLinearMap (Finset.univ.filter (fun σ => out σ = m)) + refine ContinuousLinearMap.coe_injective ?_ + rw [hgen, LinearMap.coe_toContinuousLinearMap, + LinearMap.partialTraceRight_eq_of_basis (stdOrthonormalBasis ℂ Env.space) b, hbridge] + refine hfork.trans ?_ + simp only [hUV, LinearMap.krausOp_krausDilation, measurementModelInducedOp, + ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_comp, + ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace] + +/-- **Nielsen & Chuang, Exercise 8.9 (outcome probability).** Performing `U` on `ρ ⊗ |e₀⟩⟨e₀|` and +then measuring the environment block projector `Pₘ` gives outcome `m` with probability the trace of +the induced operation element, `p(m) = tr(Eₘ ρ)`. Stated as the complex equality +`(p(m) : ℂ) = tr(Eₘ ρ)`, which records both that the trace is real and that it equals the Born +probability. Immediate from Exercise 8.7's `bornProb_eq_trace_generalMeasurementEnvOp` and the +induced-operation identity `measurementModelEnvOp_eq_inducedOp`. -/ +theorem measurementModel_bornProb_eq_trace (b : OrthonormalBasis ι ℂ Env) {e₀ : Env.space} + (he₀ : ‖e₀‖ = 1) (E : ι → (Q →L[ℂ] Q)) (hE : ∑ σ, (adjoint (E σ)).comp (E σ) = 1) + (out : ι → M) (ρ : State Q) (m : M) : + (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).bornProb + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m : ℂ) + = LinearMap.trace ℂ Q.space + (measurementModelInducedOp E out ρ m : Q.space →ₗ[ℂ] Q.space) := by + rw [bornProb_eq_trace_generalMeasurementEnvOp, measurementModelEnvOp_eq_inducedOp] + +/-- **Nielsen & Chuang, Exercise 8.9 (post-measurement state).** The corresponding post-measurement +state of the *principal* system — the left marginal (`State.reducedLeft`, tracing out the +environment) of the normalized post-measurement joint state `M.postMeasurement …` — is the induced +operation element normalized by its trace, `Eₘ(ρ)/tr(Eₘ ρ)` (N&C's `Eₘ(ρ)/tr(Eₘ(ρ))`), whenever the +outcome is possible (`hp : p(m) ≠ 0`). Proof: the reduced post-measurement operator is +`(p(m) : ℂ)⁻¹ • Eₘ(ρ)` — pushing the `p(m)⁻¹` scale of the collapse +(`postMeasurement_op_eq_bornProb_smul_opElement`) through the (linear) partial trace to recover the +induced operation `generalMeasurementEnvOp = Eₘ(ρ)` (`measurementModelEnvOp_eq_inducedOp`) — and +`p(m) = tr(Eₘ ρ)` (`measurementModel_bornProb_eq_trace`). -/ +theorem measurementModel_reducedLeft_postMeasurement_op (b : OrthonormalBasis ι ℂ Env) + {e₀ : Env.space} (he₀ : ‖e₀‖ = 1) (E : ι → (Q →L[ℂ] Q)) + (hE : ∑ σ, (adjoint (E σ)).comp (E σ) = 1) (out : ι → M) (ρ : State Q) (m : M) + (hp : ((Measurement.ofOrthonormalBasisFiber b out).onRight Q).bornProb + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m ≠ 0) : + (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).postMeasurement + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m hp).reducedLeft.op + = (LinearMap.trace ℂ Q.space (measurementModelInducedOp E out ρ m : Q.space →ₗ[ℂ] Q.space))⁻¹ + • measurementModelInducedOp E out ρ m := by + have hgen : (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).postMeasurement + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m hp).reducedLeft.op + = (((Measurement.ofOrthonormalBasisFiber b out).onRight Q).bornProb + ((measurementModelEvolution b he₀ E hE).evolve + (ρ ⊗ (⟨e₀, he₀⟩ : PureState Env).toState)) m : ℂ)⁻¹ + • generalMeasurementEnvOp ((Measurement.ofOrthonormalBasisFiber b out).onRight Q) + (measurementModelEvolution b he₀ E hE) (⟨e₀, he₀⟩ : PureState Env).toState ρ m := by + refine ContinuousLinearMap.coe_injective ?_ + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, + Measurement.postMeasurement_op_eq_bornProb_smul_opElement, + ContinuousLinearMap.toLinearMap_smul, + generalMeasurementEnvOp, ContinuousLinearMap.toLinearMap_smul, + LinearMap.coe_toContinuousLinearMap] + exact LinearMap.partialTraceRight_smul _ _ _ + rw [hgen, measurementModelEnvOp_eq_inducedOp, measurementModel_bornProb_eq_trace] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementOperation.lean b/LeanPool/AxQM/Postulates/API/MeasurementOperation.lean new file mode 100644 index 0000000000..ef406f66e3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementOperation.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# AxQM — measurement as a quantum operation (N&C Exercise 8.2) + +**Nielsen–Chuang Exercise 8.2**: a general measurement +(Postulate 3, `Measurement`) acts on density operators as the quantum operation + + `Eₘ(ρ) = Mₘ ρ Mₘ†` (Nielsen–Chuang Eq. (8.5)), + +and the two outputs of the measurement postulate are read off from this single operator: + +* the **outcome probability** is its trace, `p(m) = tr(Eₘ(ρ))`; +* the **post-measurement state** is its normalization, `Eₘ(ρ)/tr(Eₘ(ρ))`. + +The exercise is the statement that the Born probability and the post-measurement state — +`Measurement.bornProb` (Postulate 3 / the Born rule) and `Measurement.postMeasurement` +(Postulate 4 / collapse) — coincide with the operator-sum quantities `tr(Eₘ(ρ))` and +`Eₘ(ρ)/tr(Eₘ(ρ))`. + +## Contents + +* `Measurement.opElement` — the quantum operation element `Eₘ(ρ) = Mₘ ρ Mₘ†` of outcome `i` + (a thin `AxQM`-level name for `ContinuousLinearMap.postOp m.op ρ.op i`), with + `opElement_isPositive`: `Eₘ(ρ)` is a positive operator (a genuine subnormalized state). +* `Measurement.bornProb_eq_trace_opElement` — **Exercise 8.2, probability:** `p(m) = tr(Eₘ(ρ))`, + as the equality `(p(m) : ℂ) = tr(Eₘ(ρ))` (the trace is real and equals the Born probability). +* `Measurement.postMeasurement_op_eq_opElement_div` — **Exercise 8.2, state update:** the + post-measurement state is `Eₘ(ρ)/tr(Eₘ(ρ))` (N&C Eq. (8.5)), and + `postMeasurement_op_eq_bornProb_smul_opElement` gives its physical reading `Eₘ(ρ)/p(m)`. + +The statements of Exercise 8.2 are in [upstream `AxQM/NC/Ch8/Exercise8_2.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_2.lean), which refers to these +declarations. + +## Design notes + +* **Fidelity to N&C.** N&C introduces `Eₘ(ρ) ≡ Mₘ ρ Mₘ†` as a named object and asks for + two identities about it; the formalisation names `opElement` as its own `def` and states each + identity as its own theorem, about `bornProb`/`postMeasurement`, for an + arbitrary measurement `m`, state `ρ`, and outcome `i` — no dimension is specialized and no extra + hypothesis is added (`postMeasurement` already carries the standard `p(m) ≠ 0` side condition for + the collapse to be defined). The probability identity is stated as the *complex* equality + `(p(m) : ℂ) = tr(Eₘ(ρ))`, which simultaneously records that `tr(Eₘ(ρ))` is real and that it equals + `p(m)` — strictly stronger than the real-part form `p(m) = re tr(Eₘ(ρ))`. The state identity is + stated as N&C's literal `Eₘ(ρ)/tr(Eₘ(ρ))` (division by the complex trace), with a corollary in the + `Eₘ(ρ)/p(m)` form to make the physical normalization explicit. +* **Proof.** Both identities are short bridges over existing lemmas. + `bornProb_eq_trace_opElement` combines `bornProb_eq_re_trace_postOp` (`p(m) = re tr(Eₘ(ρ))`) with + `trace_postOp_eq_ofReal_re` (for positive `ρ`, the trace equals its own real part), the positivity + coming from `State.isPositive_op`. `postMeasurement_op_eq_bornProb_smul_opElement` unfolds + `postMeasurement.op = postState m.op ρ.op i = (re tr(Eₘ(ρ)))⁻¹ • Eₘ(ρ)` and rewrites the real + scale factor to `p(m)⁻¹` via the same Born-rule bridge; the literal Eq. (8.5) form follows by + substituting `tr(Eₘ(ρ)) = p(m)` from the probability identity. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- The **quantum operation element** of outcome `i` for the measurement `m` on state `ρ`: +`Eₘ(ρ) = Mₘ ρ Mₘ†` (Nielsen–Chuang Eq. (8.5)). A `AxQM`-level name for the operator-level +post-measurement operation `ContinuousLinearMap.postOp m.op ρ.op i`. -/ +def opElement (m : Measurement ι S) (ρ : State S) (i : ι) : S →L[ℂ] S := + ContinuousLinearMap.postOp m.op ρ.op i + +@[simp] +theorem opElement_eq_postOp (m : Measurement ι S) (ρ : State S) (i : ι) : + m.opElement ρ i = ContinuousLinearMap.postOp m.op ρ.op i := rfl + +/-- `Eₘ(ρ) = Mₘ ρ Mₘ†` is a positive operator when `ρ` is a state: it is a genuine (subnormalized) +density operator, which is why its normalization `Eₘ(ρ)/tr(Eₘ(ρ))` is again a state. -/ +theorem opElement_isPositive (m : Measurement ι S) (ρ : State S) (i : ι) : + (m.opElement ρ i).IsPositive := + ContinuousLinearMap.postOp_isPositive m.op ρ.isPositive_op i + +/-- **Nielsen & Chuang, Exercise 8.2 (outcome probability).** The probability of obtaining outcome +`i` is the trace of the quantum operation element: `p(m) = tr(Eₘ(ρ))`. Stated as the complex +equality `(p(m) : ℂ) = tr(Eₘ(ρ))`, which records both that `tr(Eₘ(ρ))` is real and that it equals +the Born probability `bornProb`. Combines the Born-rule bridge `bornProb_eq_re_trace_postOp` +(`p(m) = re tr(Eₘ(ρ))`) with the positivity fact `trace_postOp_eq_ofReal_re` that the trace of the +positive operator `Eₘ(ρ)` equals its own real part. -/ +theorem bornProb_eq_trace_opElement (m : Measurement ι S) (ρ : State S) (i : ι) : + (m.bornProb ρ i : ℂ) = LinearMap.trace ℂ S (m.opElement ρ i : S →ₗ[ℂ] S) := by + rw [opElement_eq_postOp, ContinuousLinearMap.trace_postOp_eq_ofReal_re m.op ρ.isPositive_op i, + bornProb_eq_re_trace_postOp] + +/-- **Nielsen & Chuang, Exercise 8.2 (state update, physical form).** The post-measurement state is +`Eₘ(ρ)/p(m)`: the quantum operation element normalized by the outcome probability. This is the +physical reading of the collapse rule; `postMeasurement_op_eq_opElement_div` gives N&C's literal +`Eₘ(ρ)/tr(Eₘ(ρ))` form (equal because `tr(Eₘ(ρ)) = p(m)`). Unfolds `postMeasurement.op` to the +normalized conjugation `(re tr(Eₘ(ρ)))⁻¹ • Eₘ(ρ)` and rewrites the real scale factor to `p(m)⁻¹`. -/ +theorem postMeasurement_op_eq_bornProb_smul_opElement (m : Measurement ι S) (ρ : State S) (i : ι) + (hp : m.bornProb ρ i ≠ 0) : + (m.postMeasurement ρ i hp).op = ((m.bornProb ρ i : ℂ))⁻¹ • m.opElement ρ i := by + rw [postMeasurement_op, opElement_eq_postOp, ContinuousLinearMap.postState, + bornProb_eq_re_trace_postOp] + +/-- **Nielsen & Chuang, Exercise 8.2 (state update, Eq. (8.5)).** The state of the system +immediately after obtaining outcome `i` is `Eₘ(ρ)/tr(Eₘ(ρ))`: the quantum operation element +normalized by its trace. This is N&C's Equation (8.5). Immediate from the probability identity +`bornProb_eq_trace_opElement` (`tr(Eₘ(ρ)) = p(m)`) and the physical form +`postMeasurement_op_eq_bornProb_smul_opElement`. -/ +theorem postMeasurement_op_eq_opElement_div (m : Measurement ι S) (ρ : State S) (i : ι) + (hp : m.bornProb ρ i ≠ 0) : + (m.postMeasurement ρ i hp).op + = (LinearMap.trace ℂ S (m.opElement ρ i : S →ₗ[ℂ] S))⁻¹ • m.opElement ρ i := by + rw [← bornProb_eq_trace_opElement, postMeasurement_op_eq_bornProb_smul_opElement] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementPrecompose.lean b/LeanPool/AxQM/Postulates/API/MeasurementPrecompose.lean new file mode 100644 index 0000000000..0b008c3efe --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementPrecompose.lean @@ -0,0 +1,160 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CompositeMeasurement + +/-! +# AxQM — pre-composing a measurement with a unitary, and trivial collapse + +Two small measurement facts shared by the **Nielsen & Chuang Proposition 12.14** +LOCC reduction (`AxQM/Core/LOCCProtocol.lean`), where the reduction induction must *absorb* a local +unitary applied just before a measurement into the measurement itself. + +* `Measurement.precompose m U` — the measurement with operator `Mᵢ U` for outcome `i` (measure `m` + *after* first applying the unitary `U`). Its Born probabilities and post-measurement states on a + state `ρ` coincide with those of `m` on the evolved state `U ρ U†` (`postOp_precompose`, + `precompose_bornProb`), and it commutes with the left-factor lift (`precompose_onLeft_op`), so an + Alice-side pre-unitary folds into Alice's measurement operators + (`onLeft_precompose_bornProb` / `onLeft_precompose_postMeasurement`). +* `Measurement.postMeasurement_eq_self_of_op_eq_one` — a measurement whose operator for a possible + outcome `i` is the identity (`Mᵢ = 1`) does not disturb the state: `postMeas(ρ, i) = ρ`. This + makes the identity/`certain`-outcome measurement a "do nothing" round. + +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- **Pre-composing a measurement by a unitary** `U`: the measurement with operators `Mᵢ ↦ Mᵢ U`, +i.e. "apply `U` first, then measure `m`". Still a measurement — the completeness relation is +conjugated, `∑ᵢ (Mᵢ U)† (Mᵢ U) = U† (∑ᵢ Mᵢ† Mᵢ) U = U† · 1 · U = 1` (unitarity `U† U = 1`). Its +statistics on `ρ` are those of `m` on `U ρ U†` (`precompose_bornProb`, `postOp_precompose`). -/ +def precompose (m : Measurement ι S) (U : Evolution S) : Measurement ι S where + op i := (m.op i).comp U.op + complete := by + have key : ∀ i, (adjoint ((m.op i).comp U.op)).comp ((m.op i).comp U.op) + = (adjoint U.op).comp (((adjoint (m.op i)).comp (m.op i)).comp U.op) := by + intro i + rw [ContinuousLinearMap.adjoint_comp] + simp only [ContinuousLinearMap.comp_assoc] + rw [Finset.sum_congr rfl fun i _ => key i, ← ContinuousLinearMap.comp_finsetSum, + ← ContinuousLinearMap.finsetSum_comp, m.complete] + simp only [← ContinuousLinearMap.mul_def, one_mul] + rw [ContinuousLinearMap.mul_def] + exact U.adjoint_comp_self + +/-- The operators of a pre-composed measurement: `(m.precompose U).op i = Mᵢ U`. -/ +@[simp] theorem precompose_op (m : Measurement ι S) (U : Evolution S) (i : ι) : + (m.precompose U).op i = (m.op i).comp U.op := rfl + +/-- **Branch-operator identity for pre-composition.** The unnormalized post-measurement operator of +outcome `i` for `m.precompose U` on `ρ` equals that of `m` on the evolved state `U ρ U†`: +`(Mᵢ U) ρ (Mᵢ U)† = Mᵢ (U ρ U†) Mᵢ†`. Carries both the probability equality and the post-state +equality below. -/ +theorem postOp_precompose (m : Measurement ι S) (U : Evolution S) (ρ : State S) (i : ι) : + ContinuousLinearMap.postOp (m.precompose U).op ρ.op i + = ContinuousLinearMap.postOp m.op (U.evolve ρ).op i := by + simp only [ContinuousLinearMap.postOp, precompose_op, Evolution.evolve_op, + ContinuousLinearMap.adjoint_comp, ContinuousLinearMap.comp_assoc] + +/-- **Pre-composition does not change the outcome statistics** (Postulate 3): measuring +`m.precompose U` on `ρ` has the same Born probabilities as measuring `m` on `U ρ U†`. -/ +theorem precompose_bornProb (m : Measurement ι S) (U : Evolution S) (ρ : State S) (i : ι) : + (m.precompose U).bornProb ρ i = m.bornProb (U.evolve ρ) i := by + rw [bornProb_eq_re_trace_postOp, bornProb_eq_re_trace_postOp, postOp_precompose] + +/-- **Pre-composition, on the post-measurement state** (Postulate 4): the state after measuring +`m.precompose U` on `ρ` equals the state after measuring `m` on the evolved input `U ρ U†`: +`postMeas(m.precompose U, ρ, i) = postMeas(m, U ρ U†, i)`. The Postulate-4 sibling of +`precompose_bornProb`; both follow from the branch-operator identity `postOp_precompose` +(`(Mᵢ U) ρ (Mᵢ U)† = Mᵢ (U ρ U†) Mᵢ†`), which carries the normalization along too. -/ +theorem precompose_postMeasurement (m : Measurement ι S) (U : Evolution S) (ρ : State S) (i : ι) + (hp : (m.precompose U).bornProb ρ i ≠ 0) : + (m.precompose U).postMeasurement ρ i hp + = m.postMeasurement (U.evolve ρ) i (by rwa [precompose_bornProb] at hp) := by + apply State.ext + rw [postMeasurement_op, postMeasurement_op, ContinuousLinearMap.postState, + ContinuousLinearMap.postState, postOp_precompose] + +/-- **Pre-composition commutes with the left-factor lift** (at the operator level): the measurement +operators of `(m.precompose U).onLeft T` and `(m.onLeft T).precompose (U.onLeft T)` agree — both are +`(Mᵢ ⊗ 1)(U ⊗ 1) = (Mᵢ U) ⊗ 1`. -/ +theorem precompose_onLeft_op (m : Measurement ι S) (U : Evolution S) (T : QSystem) : + ((m.precompose U).onLeft T).op = ((m.onLeft T).precompose (U.onLeft T)).op := by + funext i + simp only [onLeft_op, precompose_op, Evolution.onLeft, Evolution.tmul_op, Evolution.id_op] + exact TensorProduct.mapL_mul_one (m.op i) U.op + +/-- **Left-lifted pre-composition, on probabilities**: Alice measuring `(m.precompose U)` (lifted to +the left factor) on `ρ` has the same Born probabilities as Alice measuring `m` on +`(U ⊗ 1) ρ (U ⊗ 1)†` — the local pre-unitary `U` folds into Alice's measurement. -/ +theorem onLeft_precompose_bornProb (m : Measurement ι S) (U : Evolution S) (T : QSystem) + (ρ : State (S.compose T)) (i : ι) : + ((m.precompose U).onLeft T).bornProb ρ i + = (m.onLeft T).bornProb ((U.onLeft T).evolve ρ) i := by + rw [bornProb_eq_re_trace_postOp, bornProb_eq_re_trace_postOp, precompose_onLeft_op, + postOp_precompose] + +/-- **Left-lifted pre-composition, on the post-measurement state**: the state after Alice measures +`(m.precompose U)` (lifted) on `ρ` equals the state after Alice measures `m` on the evolved input +`(U ⊗ 1) ρ (U ⊗ 1)†`. This absorbs an Alice-side pre-unitary into her measurement in the +Proposition 12.14 reduction. -/ +theorem onLeft_precompose_postMeasurement (m : Measurement ι S) (U : Evolution S) (T : QSystem) + (ρ : State (S.compose T)) (i : ι) (hp : ((m.precompose U).onLeft T).bornProb ρ i ≠ 0) : + ((m.precompose U).onLeft T).postMeasurement ρ i hp + = (m.onLeft T).postMeasurement ((U.onLeft T).evolve ρ) i + (by rwa [onLeft_precompose_bornProb] at hp) := by + apply State.ext + rw [postMeasurement_op, postMeasurement_op, ContinuousLinearMap.postState, + ContinuousLinearMap.postState, precompose_onLeft_op, postOp_precompose] + +/-- **A left-factor measurement operator commutes with a right-factor unitary operator.** On +`S ⊗ T`, Alice's measurement operator `Mᵢ ⊗ 1` (`(m.onLeft T).op i`) commutes with Bob's `1 ⊗ V` +(`(V.onRight S).op`): both composites equal `Mᵢ ⊗ V`. This is the disjoint-factor commutation that +lets a Bob-local unitary defer past an Alice measurement in the Proposition 12.14 reduction. -/ +theorem onLeft_op_comm_onRight_op {T : QSystem} (m : Measurement ι S) (V : Evolution T) (i : ι) : + ((m.onLeft T).op i).comp (V.onRight S).op = (V.onRight S).op.comp ((m.onLeft T).op i) := by + have hmapL : ∀ (a : S.space →L[ℂ] S.space) (b : T.space →L[ℂ] T.space), + (TensorProduct.mapL a (1 : T.space →L[ℂ] T.space)).comp (TensorProduct.mapL 1 b) + = (TensorProduct.mapL (1 : S.space →L[ℂ] S.space) b).comp (TensorProduct.mapL a 1) := by + intro a b + rw [← TensorProduct.mapL_comp, ← TensorProduct.mapL_comp] + simp only [← ContinuousLinearMap.mul_def, mul_one, one_mul] + simp only [Measurement.onLeft_op, Evolution.onRight, Evolution.tmul_op, Evolution.id_op] + exact hmapL (m.op i) V.op + +/-- **A trivial-outcome measurement does not disturb the state.** If the operator `Mᵢ` of a possible +outcome `i` is the identity (`Mᵢ = 1`), then the post-measurement state for that outcome is `ρ` +itself: `Mᵢ ρ Mᵢ† / p(i) = 1 · ρ · 1 / 1 = ρ`. Makes the identity round (and the `certain`-outcome +measurement) a "do nothing" step. -/ +theorem postMeasurement_eq_self_of_op_eq_one (m : Measurement ι S) (ρ : State S) (i : ι) + (h : m.op i = 1) (hp : m.bornProb ρ i ≠ 0) : m.postMeasurement ρ i hp = ρ := by + apply State.ext + have hpost : ContinuousLinearMap.postOp m.op ρ.op i = ρ.op := by + simp only [ContinuousLinearMap.postOp, h, ← ContinuousLinearMap.star_eq_adjoint, star_one, + ← ContinuousLinearMap.mul_def, one_mul, mul_one] + have htr : RCLike.re (LinearMap.trace ℂ S.space (ρ.op : S.space →ₗ[ℂ] S.space)) = 1 := by + rw [ρ.isDensity.trace_eq_one, RCLike.one_re] + rw [postMeasurement_op, ContinuousLinearMap.postState, hpost, htr] + simp + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MeasurementReindex.lean b/LeanPool/AxQM/Postulates/API/MeasurementReindex.lean new file mode 100644 index 0000000000..b6c3db6e11 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MeasurementReindex.lean @@ -0,0 +1,87 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CascadedMeasurement + +/-! +# Relabelling the outcomes of a measurement + +Given a measurement `m : Measurement ι S` and an equivalence `e : Y ≃ ι` between outcome sets, the +**outcome relabelling** `m.reindexOutcome e : Measurement Y S` is the same POVM read through `e`: +its operator at `y` is `m.op (e y)`. Relabelling the outcomes of a measurement leaves the physics +untouched — the Born probability of a relabelled outcome `y` equals that of the original outcome +`e y` (`Measurement.reindexOutcome_bornProb`). + +This is the tool that lets a result proved for a measurement with `Fin r` outcomes be applied to +a measurement whose outcomes are packaged as some other finite type: relabel the latter along the +canonical `Fintype.equivFin` (or `finSuccEquiv`, …) and transport the Born probabilities. It is +used in the HSW converse (`LeanPool/AxQM/NC/Ch12/Theorem8.lean`) to feed a product-state code's +`Option (Fin K)`-valued decoder into the single-letterisation bound, which is phrased over +`Fin (K + 1)` outcomes. + +-/ + +@[expose] public section + +open ContinuousLinearMap InnerProductSpace +open scoped BigOperators + +noncomputable section + +namespace AxQM + +namespace Measurement + +variable {ι Y : Type*} [Fintype ι] [Fintype Y] {S : QSystem} + +/-- **Relabelling the outcomes of a measurement.** For a measurement `m : Measurement ι S` and an +equivalence `e : Y ≃ ι` of outcome sets, `m.reindexOutcome e` is the measurement on `S` with outcome +set `Y` whose operator at `y` is `m.op (e y)`. Completeness transfers along `e` because summing the +POVM effects over `Y` reindexes to the sum over `ι` (`Equiv.sum_comp`). -/ +def reindexOutcome (m : Measurement ι S) (e : Y ≃ ι) : Measurement Y S where + op y := m.op (e y) + complete := by + rw [Equiv.sum_comp e fun i => (adjoint (m.op i)).comp (m.op i)] + exact m.complete + +@[simp] +theorem reindexOutcome_op (m : Measurement ι S) (e : Y ≃ ι) (y : Y) : + (m.reindexOutcome e).op y = m.op (e y) := rfl + +/-- **Relabelling preserves Born probabilities.** The Born probability that the relabelled +measurement `m.reindexOutcome e` assigns to outcome `y` on a state `ρ` equals the Born probability +`m` assigns to the corresponding original outcome `e y`: + +`(m.reindexOutcome e).bornProb ρ y = m.bornProb ρ (e y)`. + +Born probabilities depend only on the outcome operator (`Measurement.bornProb_congr`), and +`(m.reindexOutcome e).op y = m.op (e y)` by construction. -/ +theorem reindexOutcome_bornProb (m : Measurement ι S) (e : Y ≃ ι) (ρ : State S) (y : Y) : + (m.reindexOutcome e).bornProb ρ y = m.bornProb ρ (e y) := + Measurement.bornProb_congr rfl ρ + +/-- **Relabelling preserves the post-measurement state.** The state after the relabelled measurement +`m.reindexOutcome e` collapses on outcome `y` equals the state after `m` collapses on the +corresponding original outcome `e y`: + +`(m.reindexOutcome e).postMeasurement ρ y hy = m.postMeasurement ρ (e y) _`. + +Post-measurement states depend only on the outcome operator (`Measurement.postMeasurement_congr`), +and `(m.reindexOutcome e).op y = m.op (e y)` by construction (`reindexOutcome_op`) — the Postulate-4 +sibling of `reindexOutcome_bornProb`. -/ +theorem reindexOutcome_postMeasurement (m : Measurement ι S) (e : Y ≃ ι) (ρ : State S) (y : Y) + (hy : (m.reindexOutcome e).bornProb ρ y ≠ 0) : + (m.reindexOutcome e).postMeasurement ρ y hy + = m.postMeasurement ρ (e y) (by rwa [reindexOutcome_bornProb] at hy) := + Measurement.postMeasurement_congr (reindexOutcome_op m e y) ρ hy _ + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Mixture.lean b/LeanPool/AxQM/Postulates/API/Mixture.lean new file mode 100644 index 0000000000..350a541a4e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Mixture.lean @@ -0,0 +1,252 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TraceDistance +public import LeanPool.AxQM.Postulates.API.RandomUnitaryChannel +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM.Postulates.API — probabilistic mixtures of states + +Nielsen & Chuang repeatedly form the **probabilistic mixture** `∑ᵢ pᵢ ρᵢ` of a family of +states `{ρᵢ}` weighted by a probability distribution `{pᵢ}` — the density operator describing +"prepare `ρᵢ` with probability `pᵢ`" (e.g. the mixtures of Theorem 9.3, the joint convexity +`(9.50)`, and the convexity exercises 9.8–9.13). This file defines `State.mix`: it takes +a probability distribution and a family of states and returns the mixed `State`, its density +operator property discharged by the convex-combination closure `isDensityOp_sum_prob_smul`. + +Statements about mixtures (such as the Chapter 9 distance results) can then name `State.mix` in +place of a hypothesis `ρ.op = ∑ᵢ pᵢ ρᵢ.op` on density operators. + +## Main definitions + +* `State.mix` — the mixed state `∑ᵢ pᵢ ρᵢ` (N&C mixtures). + +## Main statements + +* `State.mix_op` — the density operator of a mixture, `(mix p hp hsum ρ).op = ∑ᵢ pᵢ ρᵢ.op`. +* `State.op_traceNorm_eq_one` — a state's density operator has trace norm one, `‖ρ.op‖₁ = 1`. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The **probabilistic mixture** `∑ᵢ pᵢ ρᵢ` of a finite family of states `ρ : ι → State S` +weighted by a probability distribution `p : ι → ℝ` (`0 ≤ pᵢ` and `∑ᵢ pᵢ = 1`): the state whose +density operator is the convex combination `∑ᵢ (pᵢ : ℂ) • ρᵢ.op`. + +Its density-operator +property (positive, trace one) is the `n`-ary convex-combination closure +`isDensityOp_sum_prob_smul` applied to the `ρᵢ.isDensity`. The distance results of +N&C Chapter 9 name `mix` rather than an `.op = ∑ …` hypothesis. -/ +noncomputable def State.mix {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) : State S where + op := ∑ i, (p i : ℂ) • (ρ i).op + isDensity := isDensityOp_sum_prob_smul (fun i => (ρ i).isDensity) hp hsum + +/-- The **density operator of a mixture**: that of +`∑ᵢ pᵢ ρᵢ` is the convex combination `∑ᵢ (pᵢ : ℂ) • ρᵢ.op`. Definitional (`rfl`); +it is used to reason about `State.mix` through its operator. -/ +@[simp] +theorem State.mix_op {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) : + (State.mix p hp hsum ρ).op = ∑ i, (p i : ℂ) • (ρ i).op := rfl + +/-- The **mixture of a constant family is that state**: mixing a single state `σ` with *any* +probability distribution `p` returns `σ`. Since `∑ᵢ pᵢ = 1`, the convex combination collapses, +`∑ᵢ (pᵢ : ℂ) • σ.op = (∑ᵢ pᵢ) • σ.op = σ.op`. This is the algebraic fact that reduces a +convexity-in-one-argument statement to the joint form (e.g. N&C `(9.51)`, Exercise 9.8, from +joint convexity `(9.50)` by taking the second family constant) and appears in fixed-point +mixing arguments (Exercises 9.9–9.13). -/ +@[simp] +theorem State.mix_const {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (σ : State S) : + State.mix p hp hsum (fun _ => σ) = σ := by + ext + simp only [State.mix_op, ← Finset.sum_smul, ← Complex.ofReal_sum, hsum, Complex.ofReal_one, + one_smul] + +/-- **A mixture whose positive-weight components all equal a fixed state is that state.** If every +component `ρⱼ` carrying positive weight (`pⱼ > 0`) equals `σ`, then `∑ⱼ pⱼ ρⱼ = σ`; the zero-weight +components are irrelevant since they drop out of the convex combination. The collapse is the same +`∑ⱼ (pⱼ : ℂ) • σ.op = (∑ⱼ pⱼ) • σ.op = σ.op` used by `State.mix_const`, which is the +literally-constant-family special case (`h := fun _ _ => rfl`). Reusable across mixing/convexity +arguments; in particular it supplies the equality direction of the strict-concavity of the entropy +(N&C Exercise 11.18): a mixture equals its (faithful) value exactly when its positive-weight +components coincide. -/ +theorem State.mix_eq_of_forall_pos_eq {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (ρ : ι → State S) (σ : State S) + (h : ∀ j, 0 < p j → ρ j = σ) : State.mix p hp hsum ρ = σ := by + apply State.ext + have hcollapse : ∑ j, (p j : ℂ) • (ρ j).op = ∑ j, (p j : ℂ) • σ.op := + Finset.sum_congr rfl fun j _ => by + rcases eq_or_lt_of_le (hp j) with h0 | hpj + · simp [← h0] + · rw [h j hpj] + rw [State.mix_op, hcollapse, ← Finset.sum_smul, ← Complex.ofReal_sum, hsum, + Complex.ofReal_one, one_smul] + +/-- The **binary probabilistic mixture** `p ρ + (1 − p) σ` of two states, weighted by a single +probability `p ∈ [0, 1]`: the state whose density operator is the convex combination +`(p : ℂ) • ρ.op + (1 − p : ℂ) • σ.op`. The two-outcome special case of `State.mix` — "prepare `ρ` +with probability `p`, else `σ`" — which N&C's channel-mixing exercises repeatedly form: the mixing +operation `E(ρ) = p ρ₀ + (1 − p) E'(ρ)` of Exercise 9.11, the depolarizing channel `p I/2 + (1−p) ρ` +(Exercise 9.12), and the bit-flip channel (Exercise 9.13). Its density-operator property is the +binary convexity of the density set `ContinuousLinearMap.IsDensityOp.convex_combination`. -/ +noncomputable def State.mixPair {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (ρ σ : State S) : State S where + op := (p : ℂ) • ρ.op + ((1 - p : ℝ) : ℂ) • σ.op + isDensity := + ρ.isDensity.convex_combination σ.isDensity (Complex.zero_le_real.mpr hp0) + (Complex.zero_le_real.mpr (by linarith : (0 : ℝ) ≤ 1 - p)) (by push_cast; ring) + +/-- The **density operator of a binary mixture**: that of +`p ρ + (1 − p) σ` is `(p : ℂ) • ρ.op + (1 − p : ℂ) • σ.op`. Definitional (`rfl`); it is used +to reason about `State.mixPair` through its operator. -/ +@[simp] +theorem State.mixPair_op {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (ρ σ : State S) : + (State.mixPair hp0 hp1 ρ σ).op = (p : ℂ) • ρ.op + ((1 - p : ℝ) : ℂ) • σ.op := rfl + +/-- **A two-point mixture is strictly positive when its right operand is.** If the right operand `σ` +of `mixPair` has a strictly positive density operator and its weight `1 − p` is positive (`p < 1`), +then `(mixPair hp0 hp1 ρ σ).op = p • ρ.op + (1 − p) • σ.op` is strictly positive: a nonnegative +summand `p • ρ.op` (`ρ.op ≥ 0`, `p ≥ 0`) plus the strictly positive `(1 − p) • σ.op`. The +regularisation workhorse — mixing an arbitrary state towards a strictly positive reference (e.g. the +maximally mixed state) with positive weight makes it faithful. -/ +theorem State.isStrictlyPositive_mixPair_op {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (hp1' : p < 1) + {ρ σ : State S} (hσ : IsStrictlyPositive σ.op) : + IsStrictlyPositive (State.mixPair hp0 hp1 ρ σ).op := by + rw [State.mixPair_op] + exact IsStrictlyPositive.nonneg_add + (ContinuousLinearMap.nonneg_iff_isPositive.mpr + (ρ.isDensity.isPositive.smul_of_nonneg (by exact_mod_cast hp0))) + (IsStrictlyPositive.smul (by exact_mod_cast (by linarith : (0 : ℝ) < 1 - p)) hσ) + +/-- **Mixing a state with itself yields that state**: `mixPair p ρ ρ = ρ` for any weight +`p ∈ [0, 1]`. The convex combination collapses, +`(p : ℂ) • ρ.op + (1 − p : ℂ) • ρ.op = ((p + (1 − p)) : ℂ) • ρ.op = ρ.op`. The binary-mixture +analogue of `State.mix_const`; it lets a mixture-of-perturbations argument recognise the +unperturbed term (e.g. reducing a trace-distance convexity bound +`D(mixPair p ρ τ, ρ) = D(mixPair p ρ τ, mixPair p ρ ρ)` to the joint form). -/ +@[simp] +theorem State.mixPair_self {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (ρ : State S) : + State.mixPair hp0 hp1 ρ ρ = ρ := by + apply State.ext + rw [State.mixPair_op, ← add_smul] + have hc : (p : ℂ) + ((1 - p : ℝ) : ℂ) = 1 := by push_cast; ring + rw [hc, one_smul] + +/-- **Joint convexity of the trace distance for binary mixtures**: for a common weight `p ∈ [0, 1]`, +`D(p ρ₁ + (1−p) σ₁, p ρ₂ + (1−p) σ₂) ≤ p D(ρ₁, ρ₂) + (1−p) D(σ₁, σ₂)`. The two-outcome instance of +the joint convexity `(9.50)` (`State.traceDistance_mix_jointly_convex`), proved directly here by the +trace-norm triangle inequality: writing the difference of the two mixtures as +`p (ρ₁.op − ρ₂.op) + (1−p) (σ₁.op − σ₂.op)`, subadditivity (`traceNorm_add_le`) and absolute +homogeneity (`traceNorm_smul`, with `p, 1−p ≥ 0`) bound its trace norm by the weighted sum, and +halving gives the trace-distance form. This is the reusable convexity step behind the strict +contractivity of a channel mixing in a fixed state (Exercise 9.11). -/ +theorem State.traceDistance_mixPair_jointly_convex {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ρ₁ σ₁ ρ₂ σ₂ : State S) : + (State.mixPair hp0 hp1 ρ₁ σ₁).traceDistance (State.mixPair hp0 hp1 ρ₂ σ₂) + ≤ p * ρ₁.traceDistance ρ₂ + (1 - p) * σ₁.traceDistance σ₂ := by + rw [State.traceDistance_eq, State.mixPair_op, State.mixPair_op] + have hdiff : + ((p : ℂ) • ρ₁.op + ((1 - p : ℝ) : ℂ) • σ₁.op) + - ((p : ℂ) • ρ₂.op + ((1 - p : ℝ) : ℂ) • σ₂.op) + = (p : ℂ) • (ρ₁.op - ρ₂.op) + ((1 - p : ℝ) : ℂ) • (σ₁.op - σ₂.op) := by + rw [smul_sub, smul_sub]; abel + rw [hdiff] + have hbound := ContinuousLinearMap.traceNorm_add_le + ((p : ℂ) • (ρ₁.op - ρ₂.op)) (((1 - p : ℝ) : ℂ) • (σ₁.op - σ₂.op)) + rw [ContinuousLinearMap.traceNorm_smul, ContinuousLinearMap.traceNorm_smul, Complex.norm_real, + Complex.norm_real, Real.norm_of_nonneg hp0, + Real.norm_of_nonneg (by linarith : (0 : ℝ) ≤ 1 - p)] at hbound + rw [State.traceDistance_eq, State.traceDistance_eq] + linarith [hbound] + +/-- The **trace norm of a state's density operator is one**, `‖ρ.op‖₁ = 1`. A density +operator is positive, so its trace norm equals the real part of its trace +(`ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive`), which is `1` +(`State.trace_op_eq_one`). The normalization fact behind the classical-distance term of the +strong-convexity bound (N&C Theorem 9.3). -/ +theorem State.op_traceNorm_eq_one (ρ : State S) : ρ.op.traceNorm = 1 := by + rw [ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive ρ.isPositive_op, + ρ.trace_op_eq_one] + simp + +/-- **Transport of a finite mixture is the mixture of the transports**: carrying the mixture +`∑ᵢ pᵢ ρᵢ` along a system isomorphism `e` gives `∑ᵢ pᵢ (e ρᵢ e⁻¹)`. The conjugation +`conjStarAlgEquiv` implementing `State.congr` is `ℂ`-linear, so it commutes with the convex +combination defining `State.mix` (the `State.congr` companion of `State.reducedLeft_mix` / +`State.reducedRight_mix`). -/ +theorem State.congr_mix {T : QSystem} {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) (e : S ≃ₛ T) : + (State.mix p hp hsum ρ).congr e = State.mix p hp hsum (fun i => (ρ i).congr e) := by + apply State.ext + rw [State.congr_op, State.mix_op, State.mix_op] + simp only [map_sum, map_smul, State.congr_op] + +/-- **A unitary evolution distributes over a finite mixture**: applying `U` to the mixture +`∑ᵢ pᵢ ρᵢ` gives the mixture `∑ᵢ pᵢ (U ρᵢ U†)` of the evolved components. The conjugation +`conjStarAlgEquiv` implementing `Evolution.evolve` is `ℂ`-linear, so it commutes with the convex +combination defining `State.mix` — the `Evolution.evolve` companion of `State.congr_mix` / +`State.reducedLeft_mix`. -/ +theorem State.evolve_mix {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) (U : Evolution S) : + U.evolve (State.mix p hp hsum ρ) = State.mix p hp hsum (fun i => U.evolve (ρ i)) := by + apply State.ext + rw [Evolution.evolve_op_conjStarAlgEquiv, State.mix_op, State.mix_op] + simp only [map_sum, map_smul, Evolution.evolve_op_conjStarAlgEquiv] + +/-- **Tensoring a fixed state onto a finite mixture distributes**: +`(∑ᵢ pᵢ ρᵢ) ⊗ σ = ∑ᵢ pᵢ (ρᵢ ⊗ σ)`. The tensor-product map `TensorProduct.mapL` is linear in its +left argument (`TensorProduct.mapL_sum_left` / `TensorProduct.mapL_smul_left`), so it commutes with +the convex combination defining `State.mix` — the `State.tmul` companion of `State.congr_mix`. -/ +theorem State.mix_tmul {T : QSystem} {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (ρ : ι → State S) (σ : State T) : + (State.mix p hp hsum ρ).tmul σ = State.mix p hp hsum (fun i => (ρ i).tmul σ) := by + apply State.ext + rw [State.tmul_op, State.mix_op, State.mix_op, TensorProduct.mapL_sum_left] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [State.tmul_op] + exact TensorProduct.mapL_smul_left _ _ _ + +/-- **Tensoring a fixed state onto a finite mixture on the LEFT distributes**: +`σ ⊗ (∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ (σ ⊗ ρᵢ)`. The left-factor companion of `State.mix_tmul`, via the +right-argument linearity of `TensorProduct.mapL` (`TensorProduct.mapL_sum_right` / +`TensorProduct.mapL_smul_right`). -/ +theorem State.tmul_mix {T : QSystem} {ι : Type*} [Fintype ι] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (σ : State T) (ρ : ι → State S) : + σ.tmul (State.mix p hp hsum ρ) = State.mix p hp hsum (fun i => σ.tmul (ρ i)) := by + apply State.ext + rw [State.tmul_op, State.mix_op, State.mix_op, TensorProduct.mapL_sum_right] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [State.tmul_op] + exact TensorProduct.mapL_smul_right _ _ _ + +/-- **The action of a random-unitary channel as a probabilistic mixture.** A `RandomUnitaryChannel` +acts as the `State.mix` of its unitary conjugations `Uₖ ρ Uₖ†`: +`C.apply ρ = mix C.prob _ _ (fun k => (C.unitary k).evolve ρ)`. A general, citable fact about every +`RandomUnitaryChannel` (not pinching-specific). It lands here — rather than next to +`RandomUnitaryChannel.apply_op` — because it names `State.mix`, which is defined in this file, and +`Mixture` imports `RandomUnitaryChannel`, so the reverse import would be a cycle. -/ +theorem RandomUnitaryChannel.apply_eq_mix (C : RandomUnitaryChannel S) (ρ : State S) : + C.apply ρ = State.mix C.prob C.prob_nonneg C.sum_prob (fun k => (C.unitary k).evolve ρ) := by + apply State.ext + rw [RandomUnitaryChannel.apply_op, State.mix_op] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MutualInformation.lean b/LeanPool/AxQM/Postulates/API/MutualInformation.lean new file mode 100644 index 0000000000..123f2b2bec --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MutualInformation.lean @@ -0,0 +1,60 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.PartialTrace + +/-! +# AxQM — quantum mutual information `S(A:B)` + +The **quantum mutual information** of a bipartite state `ρ` on `A ⊗ B` (Nielsen & Chuang §11.3.4, +eq. (11.60)): + +`S(A:B) = S(A) + S(B) − S(A,B)`, + +the sum of the von Neumann entropies of the two marginals minus the joint entropy. It measures the +total (classical + quantum) correlations between `A` and `B`; strong subadditivity is exactly the +statement that it is monotone under discarding part of one subsystem (Nielsen & Chuang +Theorem 11.15(2), formalised in `AxQM/Postulates/API/SubadditivityReformulations.lean`). + +It is built from `State.vonNeumannEntropy`, `State.reducedLeft` (trace out `B`) and +`State.reducedRight` (trace out `A`). It is used in the strong-subadditivity reformulations of +Theorem 11.15 (`State.vonNeumannMutualInfo_le_of_discard`). The conditional-entropy reformulation of +the same theorem states the conditional entropy inline instead of using +`State.condVonNeumannEntropy`. + +## Main definitions + +* `AxQM.State.vonNeumannMutualInfo` — `S(A:B) = S(A) + S(B) − S(A,B)`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- The **quantum mutual information** `S(A:B) = S(A) + S(B) − S(A,B)` of a bipartite state `ρ` on +`A ⊗ B`: the sum of the von Neumann entropies of the reduced states on `A` (`ρ.reducedLeft`) and on +`B` (`ρ.reducedRight`) minus the von Neumann entropy of the joint state. Nielsen & Chuang §11.3.4, +eq. (11.60). Non-negative (subadditivity), and monotone under discarding a subsystem (strong +subadditivity, Theorem 11.15(2)). -/ +def State.vonNeumannMutualInfo (ρ : State (S ⊗ T)) : ℝ := + ρ.reducedLeft.vonNeumannEntropy + ρ.reducedRight.vonNeumannEntropy - ρ.vonNeumannEntropy + +/-- Unfolding lemma for the mutual information: `S(A:B) = S(A) + S(B) − S(A,B)`. -/ +theorem State.vonNeumannMutualInfo_def (ρ : State (S ⊗ T)) : + ρ.vonNeumannMutualInfo = + ρ.reducedLeft.vonNeumannEntropy + ρ.reducedRight.vonNeumannEntropy - ρ.vonNeumannEntropy := + rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MutualInformationAncilla.lean b/LeanPool/AxQM/Postulates/API/MutualInformationAncilla.lean new file mode 100644 index 0000000000..50c043372a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MutualInformationAncilla.lean @@ -0,0 +1,122 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.SubadditivityReformulations +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.EntropyComposite +public import LeanPool.AxQM.Postulates.PartialTraceTensor + +/-! +# AxQM — appending a pure product ancilla leaves the mutual information unchanged + +Adjoining a subsystem `C` prepared in a **pure product** state to a bipartite state `ρ` on `A ⊗ B` +does not change the quantum mutual information between `A` and the (now enlarged) second party: + +`S(A : B ⊗ C) = S(A : B)` when `C` starts in a pure product state. + +This is the third ingredient (labelled *(c)*) of Nielsen & Chuang's proof of **Theorem 11.15(3)** +(quantum operations never increase mutual information, p. 523): that proof models a channel on `B` +as a unitary interaction on `B ⊗ C` with the ancilla `C` initially pure, and uses that appending the +pure ancilla creates no correlations. It sits alongside the entropy-invariance ingredient *(a)* +(`State.vonNeumannEntropy_evolve`) and the local-unitary-invariance ingredient *(b)* +(`State.vonNeumannMutualInfo_evolve_id_tmul`). + +## The ancilla-adjoined state and its marginals + +For `ρ : State (A ⊗ B)` and `ω : State C`, the ancilla-adjoined state on `A ⊗ (B ⊗ C)` is +`σ := (ρ ⊗ ω).congr (QSystem.assoc A B C).symm` — the product `ρ ⊗ ω` (which lives on `(A ⊗ B) ⊗ C`) +re-associated to the `A ⊗ (B ⊗ C)` grouping the mutual-information reformulations use. Its three +marginals are read off: + +* `State.reducedLeft_congr_symm_assoc_tmul` — the `A`-marginal is `ρ`'s `A`-marginal, `Tr_{B⊗C} σ = + ρ_A` (via the `State.congr` roundtrip and the `S(A)`-marginal consistency lemma + `State.reducedLeft_reducedLeft_congr_assoc`); +* `State.reducedRight_congr_symm_assoc_tmul` — the `B ⊗ C`-marginal is `ρ_B ⊗ ω`, `Tr_A σ = + ρ.reducedRight ⊗ ω` (via the forward-associator partial-trace lemma + `LinearMap.partialTraceLeft_assocIsometry_conjStarAlgEquiv_map`). + +The statements need no faithfulness hypothesis (the result is positivity-free, like the invariance +ingredients). The marginal proofs go through partial traces of the re-associated density operator. + +## Main results + +* `AxQM.State.vonNeumannMutualInfo_tmul_pure_right` — `S(A : B ⊗ C) = S(A : B)` for a pure + product ancilla. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- **`A`-marginal of the ancilla-adjoined state.** For `ρ : State (A ⊗ B)` and `ω : State C`, the +left marginal of the re-associated product `σ := (ρ ⊗ ω).congr (QSystem.assoc A B C).symm` on +`A ⊗ (B ⊗ C)` is `ρ`'s left marginal: tracing out `B ⊗ C` from `σ` recovers `Tr_B ρ`. Proved by the +`State.congr` roundtrip (`σ.congr (QSystem.assoc A B C) = ρ ⊗ ω`) fed to the `S(A)`-marginal +consistency lemma `State.reducedLeft_reducedLeft_congr_assoc`, then `State.reducedLeft_tmul`. -/ +theorem State.reducedLeft_congr_symm_assoc_tmul (ρ : State (A ⊗ B)) (ω : State C) : + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω)).reducedLeft = ρ.reducedLeft := by + have h := State.reducedLeft_reducedLeft_congr_assoc + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω)) + rw [State.congr_congr_symm, State.reducedLeft_tmul] at h + exact h.symm + +/-- **`B ⊗ C`-marginal of the ancilla-adjoined state.** For `ρ : State (A ⊗ B)` and `ω : State C`, +the right marginal of the re-associated product `σ := (ρ ⊗ ω).congr (QSystem.assoc A B C).symm` on +`A ⊗ (B ⊗ C)` is `ρ.reducedRight ⊗ ω`: tracing out `A` from `σ` leaves the `B`-marginal of `ρ` +tensored with the untouched ancilla. Reduces, after unfolding the density operator, to the +forward-associator partial-trace lemma +`LinearMap.partialTraceLeft_assocIsometry_conjStarAlgEquiv_map`. -/ +theorem State.reducedRight_congr_symm_assoc_tmul (ρ : State (A ⊗ B)) (ω : State C) : + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω)).reducedRight = ρ.reducedRight.tmul ω := by + -- The re-associated product's operator is the *forward* associator conjugation of `ρ.op ⊗ ω.op` + -- (`(A.assoc B C).symm.toIsometry = assocIsometry`, cancelling the two `.symm`s). + apply State.ext + rw [State.reducedRight_op, State.congr_op, QSystem.assoc_symm_toIsometry, State.tmul_op, + State.tmul_op, State.reducedRight_op] + apply ContinuousLinearMap.coe_injective + rw [LinearMap.coe_toContinuousLinearMap, TensorProduct.toLinearMap_mapL, + LinearMap.coe_toContinuousLinearMap] + -- The `(A ⊗ B).space` factor of `mapL ρ.op ω.op` carries the bundled `QSystem.compose` instances, + -- defeq-but-not-syntactic to the raw `A.space ⊗ B.space` of the lemma; close by `exact`. + exact LinearMap.partialTraceLeft_assocIsometry_conjStarAlgEquiv_map + (stdOrthonormalBasis ℂ A.space) ρ.op ω.op + +/-- **N&C Theorem 11.15(3), ingredient (c): appending a pure product ancilla leaves the quantum +mutual information unchanged.** For a bipartite state `ρ` on `A ⊗ B` and a subsystem `C` prepared in +a pure product state `ω`, the mutual information between `A` and the enlarged second party `B ⊗ C` +equals the original mutual information between `A` and `B`: + +`S(A : B ⊗ C) = S(A : B)`, + +where the left-hand side is the mutual information of the ancilla-adjoined state +`σ := (ρ ⊗ ω).congr (QSystem.assoc A B C).symm`. Each term of `S(A:B⊗C) = S(A) + S(B⊗C) − S(A,B,C)` +matches: `S(A)` is unchanged (`State.reducedLeft_congr_symm_assoc_tmul`); `S(B ⊗ C) = S(B) + S(ω) = +S(B)` and `S(A,B,C) = S(A,B) + S(ω) = S(A,B)` because the ancilla is a pure product +(`State.reducedRight_congr_symm_assoc_tmul`, `State.vonNeumannEntropy_tmul`, +`PureState.vonNeumannEntropy_toState_eq_zero`, entropy transport-invariance +`State.vonNeumannEntropy_congr`). The pure product ancilla creates no correlations, matching N&C's +use of it in the dilation proof of Theorem 11.15(3). -/ +theorem State.vonNeumannMutualInfo_tmul_pure_right (ρ : State (A ⊗ B)) (ω : PureState C) : + (State.congr (QSystem.assoc A B C).symm (ρ.tmul ω.toState)).vonNeumannMutualInfo = + ρ.vonNeumannMutualInfo := by + rw [State.vonNeumannMutualInfo_def, State.vonNeumannMutualInfo_def, + State.reducedLeft_congr_symm_assoc_tmul, State.reducedRight_congr_symm_assoc_tmul, + State.vonNeumannEntropy_tmul, State.vonNeumannEntropy_congr, State.vonNeumannEntropy_tmul, + PureState.vonNeumannEntropy_toState_eq_zero] + ring + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/MutualInformationEvolution.lean b/LeanPool/AxQM/Postulates/API/MutualInformationEvolution.lean new file mode 100644 index 0000000000..5ab980e754 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/MutualInformationEvolution.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.EntropyEvolution +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# AxQM — invariance of the quantum mutual information under a local unitary + +Applying a unitary `V` to *one* subsystem of a bipartite state leaves the quantum mutual information +unchanged: + +`S(A : B) = S(A : V B V†)` (here the unitary acts on the second, `B`, factor). + +Physically: a *local* reversible operation on one party creates and destroys no correlations between +the two parties. Formally this is the special case of Nielsen & Chuang's **Theorem 11.15(3)** +(quantum operations never increase mutual information, p. 523) for a **unitary** operation — for +which the inequality is in fact an equality, since a unitary can be undone. + +It is also the second ingredient (labelled *(b)* in `EntropyEvolution`) of N&C's proof of the full +Theorem 11.15(3): that proof dilates a channel on `B` to a unitary interaction `U` on `B ⊗ C` with a +pure ancilla, and uses that this local unitary on the `B ⊗ C` factor leaves the mutual information +`S(A : B, C)` unchanged. The remaining ingredients are the entropy-invariance lemma +`State.vonNeumannEntropy_evolve` (ingredient *(a)*, already proved) and the discarding step, which +reduces to Theorem 11.15(2) but is blocked on a positivity-free data-processing inequality (see the +`## Toward Theorem 11.15(3)` note in `EntropyEvolution`). + +## Proof + +The mutual information `S(A : B) = S(A) + S(B) − S(A, B)` is invariant because each of its three +terms is: + +* `S(A, B)` — the joint entropy — is unchanged by *any* unitary evolution + (`State.vonNeumannEntropy_evolve`); +* the marginal on the *untouched* party `A` (`reducedLeft`) is literally unchanged + (`State.reducedLeft_evolve_id_tmul`): tracing out `B` after conjugating it by a unitary is the + same trace, by the naturality of the partial trace under a unitary on the traced factor + (`LinearMap.partialTraceRight_conjStarAlgEquiv_congrIsometry`); +* the marginal on the *acted-on* party `B` transforms covariantly, `ρ_B ↦ V ρ_B V†` + (`State.reducedRight_evolve_id_tmul`), because the identity on the traced-out `A` factor passes + through the partial trace (`LinearMap.partialTraceLeft_tensorMap_id_comp` and its companion + `…_comp_tensorMap_id`); its entropy is then unchanged by `State.vonNeumannEntropy_evolve`. + +The statements involve no faithfulness hypothesis (the result is positivity-free, like +`State.vonNeumannEntropy_evolve`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The isometry equivalence of a tensor of evolutions is the tensor of their isometry +equivalences.** `(U ⊗ V).toIsometryEquiv = congrIsometry U.toIsometryEquiv V.toIsometryEquiv`. The +`Evolution` analogue of `QSystem.Iso.tmul_toIsometry`. Proved by `TensorProduct.ext'`: both sides +act on a pure tensor `a ⊗ b` as `U a ⊗ V b` (definitionally), sidestepping the `QSystem.compose` +instance diamond that blocks a `mapL`-level rewrite. -/ +theorem Evolution.tmul_toIsometryEquiv (U : Evolution S) (V : Evolution T) : + (U.tmul V).toIsometryEquiv + = TensorProduct.congrIsometry U.toIsometryEquiv V.toIsometryEquiv := by + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + apply TensorProduct.ext' + intro a b + rfl + +/-- **The identity evolution's isometry equivalence is the identity.** +`Evolution.id.toIsometryEquiv = LinearIsometryEquiv.refl`. -/ +theorem Evolution.id_toIsometryEquiv : + (Evolution.id (S := S)).toIsometryEquiv = LinearIsometryEquiv.refl ℂ S.space := by + refine LinearIsometryEquiv.ext fun x => ?_ + rw [Evolution.toIsometryEquiv_apply, Evolution.id_op] + rfl + +/-- **A local unitary on the untouched party leaves its marginal unchanged.** For a state `ρ` on +`S ⊗ T` and a unitary `V` on the right factor `T`, the reduced state on the *left* factor `S` of +`(I_S ⊗ V) ρ (I_S ⊗ V)†` equals `ρ.reducedLeft`. Tracing out `T` after conjugating it by the unitary +`V` gives the same `S`-marginal, by the naturality of the partial trace under a unitary on the +traced factor (`LinearMap.partialTraceRight_conjStarAlgEquiv_congrIsometry`, transported across the +basis change with `LinearMap.partialTraceRight_eq_of_basis`). The mixed-state companion of +`PureState.reducedLeft_evolvePure_tmul_id`. -/ +theorem State.reducedLeft_evolve_id_tmul (V : Evolution T) (ρ : State (S ⊗ T)) : + (((Evolution.id (S := S)).tmul V).evolve ρ).reducedLeft = ρ.reducedLeft := by + ext1 + rw [State.reducedLeft_op, State.reducedLeft_op] + congr 1 + -- `I_S ⊗ V` is the tensor isometry `refl_S ⊗ V` (`Evolution.tmul_toIsometryEquiv`); tracing out + -- `T` after conjugating by it is the naturality lemma below, up to a basis change. + rw [Evolution.evolve_op_conjStarAlgEquiv, Evolution.tmul_toIsometryEquiv, + Evolution.id_toIsometryEquiv, + ← LinearMap.partialTraceRight_conjStarAlgEquiv_congrIsometry + (stdOrthonormalBasis ℂ T.space) V.toIsometryEquiv ρ.op] + exact LinearMap.partialTraceRight_eq_of_basis _ _ _ + +/-- **A local unitary on one party transforms that party's marginal covariantly.** For a state `ρ` +on `S ⊗ T` and a unitary `V` on the right factor `T`, the reduced state on the *right* factor `T` of +`(I_S ⊗ V) ρ (I_S ⊗ V)†` equals `V ρ_B V†` (`V.evolve ρ.reducedRight`). The identity on the +traced-out `S` factor passes straight through the partial trace over `S` +(`LinearMap.partialTraceLeft_tensorMap_id_comp` and `…_comp_tensorMap_id`), leaving the conjugation +by `V` acting on the surviving `T`-marginal. -/ +theorem State.reducedRight_evolve_id_tmul (V : Evolution T) (ρ : State (S ⊗ T)) : + (((Evolution.id (S := S)).tmul V).evolve ρ).reducedRight = V.evolve ρ.reducedRight := by + -- Express the evolved operator as `(I_S ⊗ V) ρ (I_S ⊗ V)†` at the linear-map level. The adjoint + -- of `I_S ⊗ V` is `I_S ⊗ V†`; we push it through `TensorProduct.map` via `adjoint_map` under a + -- `congr` (the `QSystem.compose` instance blocks a direct rewrite; `exact` unifies up to defeq). + -- The underlying operator of `(Evolution.id).tmul V`, bridged to the generic + -- `TensorProduct.map` form: proved + -- in isolation (no `ρ.op`/other bundled sibling adjacent via `∘ₗ`), so `Evolution.tmul_op`/ + -- `Evolution.id_op`/`TensorProduct.toLinearMap_mapL` fire by ordinary syntactic matching. + have hW : (((Evolution.id (S := S)).tmul V).op).toLinearMap + = TensorProduct.map LinearMap.id V.op.toLinearMap := by + rw [Evolution.tmul_op, Evolution.id_op, TensorProduct.toLinearMap_mapL, + ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id] + have hWadj : (ContinuousLinearMap.adjoint (((Evolution.id (S := S)).tmul V).op)).toLinearMap + = TensorProduct.map LinearMap.id (LinearMap.adjoint V.op.toLinearMap) := by + rw [ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace, hW] + refine (TensorProduct.adjoint_map (LinearMap.id : S.space →ₗ[ℂ] S.space) + V.op.toLinearMap).trans ?_ + rw [LinearMap.adjoint_id] + -- `ρ.op` (an atomic `State (S ⊗ T)`, not itself built from a further `TensorProduct.mapL`) has no + -- rewrite lemma handing it a generic-instanced form to swap to — name it at the generic type via + -- `let` (zeta-transparent), then bridge the whole composite via `hkey`, stated fresh with `ρopLM` + -- anchoring both `∘ₗ` nodes at the generic instances throughout, and closed by rewriting with the + -- already-isolated `hW`/`hWadj` (no diamond left to cross inside `hkey`'s own proof). + let ρopLM : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space := ρ.op.toLinearMap + have hkey : TensorProduct.map LinearMap.id V.op.toLinearMap ∘ₗ ρopLM + ∘ₗ TensorProduct.map LinearMap.id (LinearMap.adjoint V.op.toLinearMap) + = (((Evolution.id (S := S)).tmul V).op).toLinearMap ∘ₗ ρopLM + ∘ₗ (ContinuousLinearMap.adjoint (((Evolution.id (S := S)).tmul V).op)).toLinearMap := by + rw [hW, hWadj] + rfl + have hbridge : (((Evolution.id (S := S)).tmul V).evolve ρ).op.toLinearMap + = TensorProduct.map LinearMap.id V.op.toLinearMap ∘ₗ ρ.op.toLinearMap + ∘ₗ TensorProduct.map LinearMap.id (LinearMap.adjoint V.op.toLinearMap) := by + rw [Evolution.evolve_op] + simp only [ContinuousLinearMap.toLinearMap_comp] + exact hkey.symm + ext1 + rw [State.reducedRight_op, hbridge, LinearMap.partialTraceLeft_tensorMap_id_comp] + apply ContinuousLinearMap.coe_injective + rw [LinearMap.coe_toContinuousLinearMap, Evolution.evolve_op, + ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + State.reducedRight_op, LinearMap.coe_toContinuousLinearMap, + ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace] + congr 1 + exact LinearMap.partialTraceLeft_comp_tensorMap_id (stdOrthonormalBasis ℂ S.space) + (LinearMap.adjoint V.op.toLinearMap) ρ.op.toLinearMap + +/-- **Quantum mutual information is invariant under a local unitary.** For a bipartite state `ρ` on +`S ⊗ T`, applying a unitary `V` to the second party leaves the mutual information unchanged: +`S(A : V B V†) = S(A : B)`. + +This is the equality case of Nielsen & Chuang Theorem 11.15(3) for a *unitary* operation — a local +reversible operation creates no correlations — and the local-unitary-invariance ingredient of N&C's +proof of the general (channel) statement. Each term of `S(A:B) = S(A) + S(B) − S(A,B)` is preserved: +the joint entropy and the acted-on marginal's entropy by unitary invariance of the entropy +(`State.vonNeumannEntropy_evolve`), and the untouched marginal itself is unchanged +(`State.reducedLeft_evolve_id_tmul`). -/ +theorem State.vonNeumannMutualInfo_evolve_id_tmul (V : Evolution T) (ρ : State (S ⊗ T)) : + (((Evolution.id (S := S)).tmul V).evolve ρ).vonNeumannMutualInfo = ρ.vonNeumannMutualInfo := by + simp only [State.vonNeumannMutualInfo_def, State.reducedLeft_evolve_id_tmul, + State.reducedRight_evolve_id_tmul, State.vonNeumannEntropy_evolve] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/NMRControlledZ.lean b/LeanPool/AxQM/Postulates/API/NMRControlledZ.lean new file mode 100644 index 0000000000..066a2c3276 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/NMRControlledZ.lean @@ -0,0 +1,213 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.NMRCoupledSpinFID +public import LeanPool.AxQM.Postulates.API.ControlledZ +public import LeanPool.AxQM.Postulates.API.ContinuousSearchHamiltonian +public import LeanPool.AxQM.Postulates.API.CnotRotationCommutation + +/-! +# AxQM.Postulates.API — the NMR controlled-`Z` (N&C Ex 7.41) + +The realisation of the **controlled-`Z` gate** from the two-spin NMR +Hamiltonian (N&C eq. 7.147, `Hsys = a Z₁ + b Z₂ + c Z₁Z₂`) by one period of `Z₁Z₂`-coupled +evolution and a few single-qubit `z`-rotations (Nielsen & Chuang Exercise 7.41). The statement of +Exercise 7.41 is in [upstream `AxQM/NC/Ch7/Exercise7_41.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch7/Exercise7_41.lean). + +## What is here + +* `globalPhaseGate α` — the **global-phase gate** `e^{iα} · 1` as an `Evolution` on any system, + with its operator (`globalPhaseGate_op`), pointwise action (`globalPhaseGate_op_apply`), and the + physics fact that pre-composing it does not change the induced channel + (`globalPhaseGate_comp_evolve`): a global phase is physically unobservable. It reifies the scalar + `√i` of N&C's construction (7.152). +* `couplingZZHamiltonian_op_apply_qubitBasis` — the coupling Hamiltonian `c Z₁Z₂` acts on + `|a⟩⊗|b⟩` as the eigenvalue `c·(-1)ᵃ·(-1)ᵇ`; the input the propagator eigenvector lemma needs to + evaluate the coupled evolution on the computational basis. +* `nmrControlledZSequence c t` — the **explicit gate sequence**: one period of evolution under the + `Z₁Z₂` coupling `(couplingZZHamiltonian c).propagator 1 0 t` followed by a `90°` `z`-rotation + `R_z(-π/2)` on each spin. When `c·t = π/4` this equals the controlled-`Z` up to the global phase + `e^{-iπ/4}` — proved in [upstream `AxQM/NC/Ch7/Exercise7_41.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch7/Exercise7_41.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The global-phase gate -/ + +/-- **The global-phase gate** `e^{iα} · 1` as an `Evolution` on a quantum system `S`: the unitary +that multiplies every state vector by the fixed unit-modulus scalar `e^{iα}`. It reifies the +scalar prefactor `√i = e^{iπ/4}` appearing in N&C's controlled-`Z` construction (eq. 7.152). -/ +def globalPhaseGate (α : ℝ) : Evolution S where + op := Complex.exp ((α : ℂ) * Complex.I) • (1 : S.space →L[ℂ] S.space) + unitary := by + rw [Unitary.mem_iff] + have hconj : (starRingEnd ℂ) (Complex.exp ((α : ℂ) * Complex.I)) + = Complex.exp (-((α : ℂ) * Complex.I)) := by + rw [← Complex.exp_conj] + congr 1 + simp [Complex.conj_I, mul_comm] + have hmul : (starRingEnd ℂ) (Complex.exp ((α : ℂ) * Complex.I)) + * Complex.exp ((α : ℂ) * Complex.I) = 1 := by + rw [hconj, ← Complex.exp_add, neg_add_cancel, Complex.exp_zero] + have hmul' : Complex.exp ((α : ℂ) * Complex.I) + * (starRingEnd ℂ) (Complex.exp ((α : ℂ) * Complex.I)) = 1 := by + rw [mul_comm]; exact hmul + constructor + · rw [star_smul, star_one, smul_mul_smul_comm, one_mul, ← starRingEnd_apply, hmul, one_smul] + · rw [star_smul, star_one, smul_mul_smul_comm, one_mul, ← starRingEnd_apply, hmul', one_smul] + +/-- The operator of `globalPhaseGate α` is `e^{iα} · 1`. -/ +@[simp] +theorem globalPhaseGate_op (α : ℝ) : + (globalPhaseGate (S := S) α).op + = Complex.exp ((α : ℂ) * Complex.I) • (1 : S.space →L[ℂ] S.space) := + rfl + +/-- The pointwise action of `globalPhaseGate α`: `(e^{iα} · 1) v = e^{iα} • v`. -/ +theorem globalPhaseGate_op_apply (α : ℝ) (v : S.space) : + (globalPhaseGate (S := S) α).op v = Complex.exp ((α : ℂ) * Complex.I) • v := by + rw [globalPhaseGate_op, smul_apply, one_apply_eq_self] + +/-- **A global phase on the right tensor factor is the same global phase on the composite:** +`1 ⊗ (e^{iα}·1) = e^{iα}·1`, i.e. `(globalPhaseGate α).onRight S = globalPhaseGate α`. The scalar +`e^{iα}` factors out of the `TensorProduct.mapL` and `mapL 1 1 = 1`. -/ +theorem globalPhaseGate_onRight (α : ℝ) (S T : QSystem) : + ((globalPhaseGate α : Evolution T)).onRight S = globalPhaseGate α := by + apply Evolution.ext + rw [Evolution.onRight, Evolution.tmul_op, Evolution.id_op, globalPhaseGate_op, + TensorProduct.mapL_smul_right, TensorProduct.mapL_one, globalPhaseGate_op] + rfl + +/-- **A global phase on the left tensor factor is the same global phase on the composite:** +`(e^{iα}·1) ⊗ 1 = e^{iα}·1`, i.e. `(globalPhaseGate α).onLeft T = globalPhaseGate α`. Mirror of +`globalPhaseGate_onRight`. -/ +theorem globalPhaseGate_onLeft (α : ℝ) (S T : QSystem) : + ((globalPhaseGate α : Evolution S)).onLeft T = globalPhaseGate α := by + apply Evolution.ext + rw [Evolution.onLeft, Evolution.tmul_op, Evolution.id_op, globalPhaseGate_op, + TensorProduct.mapL_smul_left, TensorProduct.mapL_one, globalPhaseGate_op] + rfl + +/-- **The zero global phase is the identity gate:** `globalPhaseGate 0 = 1`, since `e^{i·0} = 1`. -/ +theorem globalPhaseGate_zero {S : QSystem} : globalPhaseGate (S := S) 0 = Evolution.id := by + apply Evolution.ext + simp only [globalPhaseGate_op, Evolution.id_op, Complex.ofReal_zero, zero_mul, Complex.exp_zero, + one_smul] + +/-- **The global phase is invariant under transport along a system isomorphism.** For any +`e : S ≃ₛ T`, `Evolution.congr e (globalPhaseGate α) = globalPhaseGate α`. Transport conjugates the +operator by the unital ℂ-linear `⋆`-algebra equivalence `e.toIsometry.conjStarAlgEquiv`, and +conjugating the scalar `e^{iα} · 1` fixes it: `conjStarAlgEquiv (e^{iα} • 1) = e^{iα} • 1` by +`map_smul` and `map_one`. The global-phase companion of `Evolution.congr_one`. -/ +theorem Evolution.congr_globalPhaseGate {S T : QSystem} (e : S ≃ₛ T) (α : ℝ) : + Evolution.congr e (globalPhaseGate α) = (globalPhaseGate α : Evolution T) := by + apply Evolution.ext + rw [Evolution.congr_op, globalPhaseGate_op, map_smul, map_one, globalPhaseGate_op] + +/-- **A global phase does not change the induced channel.** Pre-composing any evolution `E` with the +global-phase gate `e^{iα} · 1` leaves the density-operator evolution `ρ ↦ E ρ E†` unchanged — the +phase cancels in the conjugation, the precise sense in which a global phase is unobservable. -/ +theorem globalPhaseGate_comp_evolve (α : ℝ) (E : Evolution S) (ρ : State S) : + ((globalPhaseGate α).comp E).evolve ρ = E.evolve ρ := by + refine Evolution.evolve_eq_of_op_eq_phase_smul ((globalPhaseGate α).comp E) E + (c := Complex.exp ((α : ℂ) * Complex.I)) (Complex.norm_exp_ofReal_mul_I α) ?_ ρ + rw [Evolution.comp_op, globalPhaseGate_op, ContinuousLinearMap.smul_comp, + ← ContinuousLinearMap.mul_def, one_mul] + +/-! ### Computational-basis eigenvalues of the coupling Hamiltonian -/ + +/-- **The `Z₁Z₂` coupling Hamiltonian acts diagonally on the computational basis.** For coupling +strength `c`, `(c Z₁Z₂)` sends `|a⟩⊗|b⟩` to the eigenvalue `c·(-1)ᵃ·(-1)ᵇ`, because each factor +contributes its own Pauli-`Z` eigenvalue. This is the eigenvector hypothesis the propagator lemma +`Observable.propagator_op_apply_of_apply_eq_smul` needs to evaluate the coupled evolution +`exp(-i c Z₁Z₂ t)` on `|a⟩⊗|b⟩`. -/ +theorem couplingZZHamiltonian_op_apply_qubitBasis (c : ℝ) (a b : Fin 2) : + (couplingZZHamiltonian c).op ((qubitBasis a) ⊗ (qubitBasis b)).vec + = ((c : ℂ) * (-1) ^ (a : ℕ) * (-1) ^ (b : ℕ)) • ((qubitBasis a) ⊗ (qubitBasis b)).vec := by + -- Retype the (defeq) `QSystem.compose` state space to the raw tensor `qubit.space ⊗ qubit.space` + -- and `(Z ⊗ Z).op` to its `TensorProduct.mapL` form, so the scalar `↑c` and the `TensorProduct` + -- lemmas share one module (a bare `rw [Observable.tmul_op]` leaves the map at the unreduced + -- projection, where neither `mapL_tmul` nor the scalar combines fire). + rw [couplingZZHamiltonian_op, PureState.tmul_vec] + change (c : ℂ) • (TensorProduct.mapL pauliZObservable.op pauliZObservable.op) + ((qubitBasis a).vec ⊗ₜ[ℂ] (qubitBasis b).vec) + = ((c : ℂ) * (-1) ^ (a : ℕ) * (-1) ^ (b : ℕ)) • ((qubitBasis a).vec ⊗ₜ[ℂ] (qubitBasis b).vec) + rw [TensorProduct.mapL_tmul, pauliZObservable_op_apply_qubitBasis, + pauliZObservable_op_apply_qubitBasis] + simp only [TensorProduct.smul_tmul', TensorProduct.tmul_smul, smul_smul] + congr 2 + ring + +/-! ### The explicit gate sequence -/ + +/-- **The NMR controlled-`Z` gate sequence** (Nielsen & Chuang Exercise 7.41): one period of +evolution under the `Z₁Z₂` coupling `(couplingZZHamiltonian c).propagator 1 0 t = exp(-i c Z₁Z₂ t)`, +followed by a `90°` `z`-rotation `R_z(-π/2)` on each of the two spins. When `c · t = π/4`, this +equals the controlled-`Z` gate up to the global phase `e^{-iπ/4}` (see +[upstream `AxQM/NC/Ch7/Exercise7_41.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch7/Exercise7_41.lean)). -/ +def nmrControlledZSequence (c t : ℝ) : Evolution (qubit ⊗ qubit) := + ((couplingZZHamiltonian c).propagator 1 0 t).comp + (((rotZGate (-(Real.pi / 2))).onLeft qubit).comp + ((rotZGate (-(Real.pi / 2))).onRight qubit)) + +/-- **Diagonal action of the gate sequence on the computational basis.** On `|a⟩⊗|b⟩` the sequence +`nmrControlledZSequence c t` acts by the scalar +`R_z(-π/2)ₐₐ · R_z(-π/2)_bb · e^{-i c (-1)ᵃ(-1)ᵇ t}` — the two single-qubit `z`-rotation phases +times the coupled-evolution phase (from `Observable.propagator_op_apply_of_apply_eq_smul` applied to +`couplingZZHamiltonian_op_apply_qubitBasis`). -/ +theorem nmrControlledZSequence_op_apply_qubitBasis (c t : ℝ) (a b : Fin 2) : + (nmrControlledZSequence c t).op ((qubitBasis a) ⊗ (qubitBasis b)).vec + = (Concrete.rotZ (-(Real.pi / 2)) a a * Concrete.rotZ (-(Real.pi / 2)) b b + * Complex.exp (-(Complex.I * (((c : ℂ) * (-1) ^ (a : ℕ) * (-1) ^ (b : ℕ)) * (t : ℂ))))) + • ((qubitBasis a) ⊗ (qubitBasis b)).vec := by + have hcoupling : ((couplingZZHamiltonian c).propagator 1 0 t).op + ((qubitBasis a) ⊗ (qubitBasis b)).vec + = Complex.exp (-(Complex.I * (((c : ℂ) * (-1) ^ (a : ℕ) * (-1) ^ (b : ℕ)) * (t : ℂ)))) + • ((qubitBasis a) ⊗ (qubitBasis b)).vec := + Observable.propagator_op_apply_of_apply_eq_smul (couplingZZHamiltonian c) t + (couplingZZHamiltonian_op_apply_qubitBasis c a b) + rw [nmrControlledZSequence, Evolution.comp_op, Evolution.comp_op, + ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply, PureState.tmul_vec, + Evolution.onRight_op_tmul, rotZGate_op_apply_qubitBasis, Evolution.onLeft_op_tmul, + rotZGate_op_apply_qubitBasis, TensorProduct.smul_tmul_smul, ← PureState.tmul_vec] + -- Retype the (defeq) `TensorProduct`-level scalar to the propagator's domain + -- `(qubit ⊗ qubit).space`, so `map_smul` on the linear `.op` fires by a plain `rw`. + change ((couplingZZHamiltonian c).propagator 1 0 t).op + ((Concrete.rotZ (-(Real.pi / 2)) a a * Concrete.rotZ (-(Real.pi / 2)) b b) + • ((qubitBasis a) ⊗ (qubitBasis b)).vec) = _ + rw [map_smul, hcoupling, smul_smul, mul_assoc] + +/-- **Diagonal action of the controlled-`Z` gate on the computational basis.** `controlledZGate` +sends `|a⟩⊗|b⟩` to `(-1)^{a·b}·|a⟩⊗|b⟩`, i.e. it flips the sign of `|11⟩` only — the specifying +`diag(1,1,1,-1)`. Derived from the `controlledUnitary` action lemmas and `Z|b⟩ = (-1)ᵇ|b⟩`. -/ +theorem controlledZGate_op_apply_qubitBasis (a b : Fin 2) : + controlledZGate.op ((qubitBasis a) ⊗ (qubitBasis b)).vec + = (-1 : ℂ) ^ ((a : ℕ) * (b : ℕ)) • ((qubitBasis a) ⊗ (qubitBasis b)).vec := by + rw [← Evolution.evolvePure_vec, controlledZGate] + fin_cases a + · change ((controlledUnitary pauliZGate).evolvePure (qubitBasis 0 ⊗ qubitBasis b)).vec + = (-1 : ℂ) ^ (((0 : Fin 2) : ℕ) * (b : ℕ)) • (qubitBasis 0 ⊗ qubitBasis b).vec + rw [controlledUnitary_evolvePure_ketZero, Fin.val_zero, zero_mul, pow_zero, one_smul] + · change ((controlledUnitary pauliZGate).evolvePure (qubitBasis 1 ⊗ qubitBasis b)).vec + = (-1 : ℂ) ^ (((1 : Fin 2) : ℕ) * (b : ℕ)) • (qubitBasis 1 ⊗ qubitBasis b).vec + rw [controlledUnitary_evolvePure_ketOne, PureState.tmul_vec, Evolution.evolvePure_vec, + pauliZGate_op_apply_qubitBasis, TensorProduct.tmul_smul, ← PureState.tmul_vec] + congr 1 + rw [Fin.val_one, one_mul] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/NMRCoupledSpinFID.lean b/LeanPool/AxQM/Postulates/API/NMRCoupledSpinFID.lean new file mode 100644 index 0000000000..bd1cab3f69 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/NMRCoupledSpinFID.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.InvolutionPropagatorConjugation +public import LeanPool.AxQM.Postulates.API.Observable +public import LeanPool.AxQM.Postulates.API.Qubit + +/-! +# AxQM.Postulates.API — the J-coupled NMR readout operator (Nielsen & Chuang §7.7) + +The **transverse magnetization readout operator** of a two-spin, `J`-coupled NMR system and its +**Heisenberg evolution** — the algebraic core of the free-induction-decay computation of +Nielsen & Chuang Exercise 7.37. + +The coupling Hamiltonian is `H = J Z₁Z₂` (`couplingZZHamiltonian`), whose operator `J • (Z ⊗ Z)` +is a scalar multiple of the **involution** `G = Z ⊗ Z` (`G² = 1`). The pickup coil reads out the +spin-1 transverse magnetization through the *non-Hermitian* operator `i X₁ + Y₁` +(`nmrTransverseReadout`, the `k = 1` case of the readout `i Xₖ + Yₖ` of N&C eq. 7.143). Since it +**anticommutes** with `G`, the reusable involution-Heisenberg lemma +`Observable.propagator_conj_op_anticomm` (this directory's `InvolutionPropagatorConjugation`) +gives the Heisenberg-evolved readout in closed form: + +* `nmrReadout_heisenberg` — + `U(t)† (i X₁ + Y₁) U(t) = (i X₁ + Y₁) · (cos(2Jt) • 1 − (sin(2Jt) i) • Z₂)`, + +the raising-type operator `i X₁ + Y₁` picking up the neighbour phase `e^{-2iJ Z₂ t}` at **twice** +the coupling frequency. (Since `i X₁ + Y₁` absorbs its own `Z₁` — `(i X + Y) Z = i X + Y` — the +coupling generator `G = Z₁Z₂` collapses to the neighbour operator `Z₂`.) Expanded, this reads +`cos(2Jt) (i X₁ + Y₁) + sin(2Jt) (X₁ − i Y₁) Z₂`: the `J`-coupled precession that turns the +spin-1 magnetization into a spectral **doublet** at `±2J`. + +## Design + +* **Proof.** No matrix trigonometry: `Observable.propagator_conj_op_anticomm` supplies the + `cos(2ct)A − i sin(2ct)(A·G)` normal form for the whole readout `A = i X₁ + Y₁` at once (it + anticommutes with `G`), and the single operator identity `(i X₁ + Y₁) · G = (i X₁ + Y₁) · Z₂` + collapses the `G`-part to the neighbour operator `Z₂`. The single-qubit Pauli input is only the + shared `AxQM/Postulates/API/Qubit.lean` lemmas — the anticommutators `{X, Z} = {Y, Z} = 0` and the + raising identity `i (X Z) + Y Z = i X + Y` (both lifted to operators through the `⋆`-algebra map + `Matrix.toEuclideanCLM`) — assembled here into the composite (`TensorProduct.mapL`) statements. +-/ + +@[expose] public section + +open scoped ComplexOrder + +noncomputable section + +namespace AxQM + +/-! ### The J-coupling Hamiltonian and its involution generator + +The single-qubit Pauli operator facts this file builds on — `Z² = 1` +(`pauliZObservable_op_mul_self`), the anticommutators `{X, Z} = {Y, Z} = 0` +(`pauliXObservable_op_anticomm_pauliZObservable_op` / `…Y…`), and the raising-operator absorption +`i (X Z) + Y Z = i X + Y` (`pauliRaising_op_mul_pauliZObservable_op`) — are the generic shared +lemmas of `AxQM/Postulates/API/Qubit.lean`. -/ + +variable (J : ℝ) + +/-- The **two-spin `J`-coupling Hamiltonian** `H = J Z₁Z₂` of Nielsen & Chuang §7.7, as an +`Observable` on the two-qubit system whose operator is `J • (Z ⊗ Z)` — a real scalar multiple of +the `Z ⊗ Z` observable, the NMR Ising/`ZZ` coupling between two spins with coupling constant `J`. -/ +def couplingZZHamiltonian : Observable (qubit.compose qubit) where + op := (J : ℂ) • (pauliZObservable.tmul pauliZObservable).op + selfAdjoint := + ((Complex.im_eq_zero_iff_isSelfAdjoint _).mp rfl).smul + (pauliZObservable.tmul pauliZObservable).selfAdjoint + +@[simp] +theorem couplingZZHamiltonian_op : + (couplingZZHamiltonian J).op = (J : ℂ) • (pauliZObservable.tmul pauliZObservable).op := + rfl + +/-- The generator `G = Z ⊗ Z` of the `J`-coupling Hamiltonian is an **involution**: `G² = 1`, +because `Z² = 1` on each factor. -/ +theorem pauliZZ_op_mul_self : + (pauliZObservable.tmul pauliZObservable).op * (pauliZObservable.tmul pauliZObservable).op + = 1 := by + -- Prove the identity in the raw tensor operator ring (where the `mapL` lemmas apply directly), + -- then transport it to the goal by defeq (`(A ⊗ B).op ≡ mapL A.op B.op`). + have H : TensorProduct.mapL pauliZObservable.op pauliZObservable.op + * TensorProduct.mapL pauliZObservable.op pauliZObservable.op = 1 := by + rw [← TensorProduct.mapL_mul, pauliZObservable_op_mul_self, TensorProduct.mapL_one] + exact H + +/-! ### The transverse magnetization readout and its Heisenberg evolution -/ + +/-- The **spin-1 transverse magnetization readout** operator `i X₁ + Y₁` (`X₁ = X ⊗ 1`, +`Y₁ = Y ⊗ 1`) — the `k = 1` case of the non-Hermitian pickup operator `i Xₖ + Yₖ` of the +free-induction-decay signal `V(t)` (Nielsen & Chuang eq. 7.143). -/ +def nmrTransverseReadout : (qubit.compose qubit).space →L[ℂ] (qubit.compose qubit).space := + Complex.I • (pauliXObservable.tmul (Observable.id qubit)).op + + (pauliYObservable.tmul (Observable.id qubit)).op + +/-- The readout operator `i X₁ + Y₁` **anticommutes** with the coupling generator `G = Z ⊗ Z` +(both `X₁` and `Y₁` anticommute with `G`, `1` on the second factor commuting with `Z`). -/ +theorem nmrTransverseReadout_anticomm_pauliZZ : + nmrTransverseReadout * (pauliZObservable.tmul pauliZObservable).op + = -((pauliZObservable.tmul pauliZObservable).op * nmrTransverseReadout) := by + -- Per-factor anticommutation, in the raw tensor operator ring. + have hX : TensorProduct.mapL pauliXObservable.op 1 + * TensorProduct.mapL pauliZObservable.op pauliZObservable.op + = -(TensorProduct.mapL pauliZObservable.op pauliZObservable.op + * TensorProduct.mapL pauliXObservable.op 1) := by + rw [← TensorProduct.mapL_mul, ← TensorProduct.mapL_mul, one_mul, mul_one, + ← TensorProduct.mapL_neg_left, pauliXObservable_op_anticomm_pauliZObservable_op] + have hY : TensorProduct.mapL pauliYObservable.op 1 + * TensorProduct.mapL pauliZObservable.op pauliZObservable.op + = -(TensorProduct.mapL pauliZObservable.op pauliZObservable.op + * TensorProduct.mapL pauliYObservable.op 1) := by + rw [← TensorProduct.mapL_mul, ← TensorProduct.mapL_mul, one_mul, mul_one, + ← TensorProduct.mapL_neg_left, pauliYObservable_op_anticomm_pauliZObservable_op] + -- Assemble `i X₁ + Y₁` in the raw ring, then transport to the goal by defeq. + have H : (Complex.I • TensorProduct.mapL pauliXObservable.op 1 + + TensorProduct.mapL pauliYObservable.op 1) + * TensorProduct.mapL pauliZObservable.op pauliZObservable.op + = -(TensorProduct.mapL pauliZObservable.op pauliZObservable.op + * (Complex.I • TensorProduct.mapL pauliXObservable.op 1 + + TensorProduct.mapL pauliYObservable.op 1)) := by + rw [add_mul, mul_add, smul_mul_assoc, mul_smul_comm, hX, hY, smul_neg, ← neg_add] + exact H + +/-- **The readout absorbs the coupling into the neighbour: `(i X₁ + Y₁) G = (i X₁ + Y₁) Z₂`.** +Right-multiplying the raising-type readout by the coupling generator `G = Z₁Z₂` reduces to right +multiplication by the neighbour operator `Z₂ = 1 ⊗ Z`, because `i X + Y` absorbs its own `Z₁` +(`pauliRaising_op_mul_pauliZObservable_op`). -/ +theorem nmrTransverseReadout_mul_pauliZZ : + nmrTransverseReadout * (pauliZObservable.tmul pauliZObservable).op + = nmrTransverseReadout * ((Observable.id qubit).tmul pauliZObservable).op := by + -- Both sides reduce to `((i X + Y) L) ⊗ Z` in the raw tensor ring: with `L = Z` (the coupling) + -- and `L = 1` (the neighbour), and `(i X + Y) Z = i X + Y`, they coincide. + have H : (Complex.I • TensorProduct.mapL pauliXObservable.op 1 + + TensorProduct.mapL pauliYObservable.op 1) + * TensorProduct.mapL pauliZObservable.op pauliZObservable.op + = (Complex.I • TensorProduct.mapL pauliXObservable.op 1 + + TensorProduct.mapL pauliYObservable.op 1) + * TensorProduct.mapL (1 : qubit.space →L[ℂ] qubit.space) pauliZObservable.op := by + simp only [add_mul, smul_mul_assoc, ← TensorProduct.mapL_mul, one_mul, mul_one, + ← TensorProduct.mapL_smul_left, ← TensorProduct.mapL_add_left, + pauliRaising_op_mul_pauliZObservable_op] + exact H + +/-- **Heisenberg evolution of the transverse magnetization readout (N&C Ex 7.37, `H = J Z₁Z₂`).** +Under the `J`-coupling propagator `U(t) = exp(-i J Z₁Z₂ t)`, the readout operator `i X₁ + Y₁` +evolves in the Heisenberg picture to + +`U(t)† (i X₁ + Y₁) U(t) = (i X₁ + Y₁) · (cos(2Jt) • 1 − (sin(2Jt) i) • Z₂)`, + +i.e. the raising-type readout precesses at **twice** the coupling frequency, `i X₁ + Y₁` +acquiring the neighbour phase `cos(2Jt) − i sin(2Jt) Z₂ = e^{-2iJ Z₂ t}`. Proof: `i X₁ + Y₁` +anticommutes with the involution `G = Z ⊗ Z`, so `Observable.propagator_conj_op_anticomm` gives +`cos(2Jt)(i X₁+Y₁) − (sin(2Jt) i)((i X₁+Y₁) G)`, and `(i X₁+Y₁) G = (i X₁+Y₁) Z₂` +(`nmrTransverseReadout_mul_pauliZZ`) collapses the coupling to the neighbour `Z₂`. -/ +theorem nmrReadout_heisenberg (t : ℝ) : + ContinuousLinearMap.adjoint ((couplingZZHamiltonian J).propagator 1 0 t).op + * nmrTransverseReadout * ((couplingZZHamiltonian J).propagator 1 0 t).op + = nmrTransverseReadout + * ((Real.cos (2 * J * t) : ℂ) + • (1 : (qubit.compose qubit).space →L[ℂ] (qubit.compose qubit).space) + - ((Real.sin (2 * J * t) : ℂ) * Complex.I) + • ((Observable.id qubit).tmul pauliZObservable).op) := by + have hconj := (couplingZZHamiltonian J).propagator_conj_op_anticomm + (couplingZZHamiltonian_op J) pauliZZ_op_mul_self + (pauliZObservable.tmul pauliZObservable).selfAdjoint + nmrTransverseReadout_anticomm_pauliZZ t + rw [hconj, mul_sub, mul_smul_comm, mul_smul_comm, mul_one, nmrTransverseReadout_mul_pauliZZ] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Observable.lean b/LeanPool/AxQM/Postulates/API/Observable.lean new file mode 100644 index 0000000000..7678707943 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Observable.lean @@ -0,0 +1,138 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import Mathlib.Analysis.InnerProductSpace.StarOrder + +/-! +# AxQM.Postulates.API — bipartite observables and expectation bounds + +Observables of a composite system. + +* `Observable.tmul` (`A ⊗ B`) — the **tensor product of two observables**: the observable + of `S ⊗ T` acting as `A` on the first factor and `B` on the second. It completes the + `⊗` overload alongside `PureState.tmul` / `State.tmul` / `Evolution.tmul`, + and grounds Nielsen–Chuang Exercise 2.30 (the tensor of Hermitian operators is Hermitian). +* `PureState.re_inner_apply_le_of_le_smul_one` — the **operator-order → expectation bridge**, + raw-operator form: if `M ≤ c • 1` in the operator (Loewner) order, then `Re ⟪ψ, M ψ⟫ ≤ c` in + every normalized pure state. The general statement (a raw operator, not a bundled + `Observable`), so an operator bound on a *sum* of observables descends without repackaging. + This is the mechanism by which a C*-algebraic operator bound (e.g. Tsirelson's + `tsirelson_inequality`) descends to a bound on measured expectation values. +* `PureState.expectation_le_of_op_le_smul_one` — the `Observable`-bundled corollary: if + `A.op ≤ c • 1` then `⟪A⟫_ψ ≤ c`, i.e. the raw lemma at `M := A.op`. + +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct ComplexOrder + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Tensor product of observables** `A ⊗ B`: the observable of the composite system +`S ⊗ T` that measures `A` on the first factor and `B` on the second. It is self-adjoint +because the tensor product of self-adjoint operators is self-adjoint +(`IsSelfAdjoint.tensorMapL`). This is the observable analogue of `State.tmul` / +`Evolution.tmul`, and grounds Nielsen–Chuang Exercise 2.30 (the tensor of Hermitian +operators is Hermitian). -/ +def Observable.tmul (A : Observable S) (B : Observable T) : Observable (S ⊗ T) where + op := TensorProduct.mapL A.op B.op + selfAdjoint := IsSelfAdjoint.tensorMapL A.selfAdjoint B.selfAdjoint + +@[inherit_doc] scoped infixr:70 " ⊗ " => Observable.tmul + +@[simp] +theorem Observable.tmul_op (A : Observable S) (B : Observable T) : + (A ⊗ B).op = TensorProduct.mapL A.op B.op := rfl + +/-- **Action of a tensor observable on a pure tensor:** `(A ⊗ B)(a ⊗ b) = A a ⊗ B b`. Definitional +(`Observable.tmul_op` + `TensorProduct.mapL_tmul`), the observable analogue of +`Evolution.tmul_op_tmul`. -/ +theorem Observable.tmul_op_tmul (A : Observable S) (B : Observable T) (a : S.space) (b : T.space) : + (A ⊗ B).op (a ⊗ₜ[ℂ] b) = A.op a ⊗ₜ[ℂ] B.op b := + TensorProduct.mapL_tmul A.op B.op a b + +/-- **The tensor of two involutive observables is involutive:** if `A.op² = I` and `B.op² = I` then +`(A ⊗ B).op² = I`. Since `(A ⊗ B).op = mapL A.op B.op` and `mapL` is multiplicative +(`TensorProduct.mapL_mul`), `(A ⊗ B).op² = mapL (A.op²) (B.op²) = mapL 1 1 = 1`. A reusable bridge: +a product `±1` observable built by tensoring sign observables is again a `±1` observable (used for +the Shor-code syndrome observables and the first-qubit `X ⊗ I` / `Z ⊗ I` measurements of the +EPR-collapse item). -/ +theorem Observable.tmul_op_mul_self {A : Observable S} {B : Observable T} + (hA : A.op * A.op = 1) (hB : B.op * B.op = 1) : + (A ⊗ B).op * (A ⊗ B).op = 1 := by + change TensorProduct.mapL A.op B.op * TensorProduct.mapL A.op B.op = 1 + rw [← TensorProduct.mapL_mul A.op A.op B.op B.op, hA, hB, TensorProduct.mapL_one] + +/-- **The identity observable** `I` on a system `S`: the identity operator, self-adjoint. Its +expectation in any state is `1`; it is the trivial effect used to embed a single-factor observable +into a composite as `E ⊗ I` (e.g. Nielsen–Chuang Exercise 2.70). A derived observable, sibling of +`Observable.tmul`. -/ +def Observable.id (S : QSystem) : Observable S where + op := 1 + selfAdjoint := IsSelfAdjoint.one _ + +@[simp] theorem Observable.id_op (S : QSystem) : (Observable.id S).op = 1 := rfl + +/-- **Raw-operator form of the operator-order → expectation bridge.** If a raw operator `M` is +bounded above by `c • 1` in the operator (Loewner) order on `S →L[ℂ] S` — with the real scalar +`c` acting through the `ℝ`-action on the operator algebra — then `Re ⟪ψ, M ψ⟫ ≤ c` for every +normalized pure state `ψ`. + +The difference `(c : ℂ) • 1 - M` is a positive operator (`nonneg_iff_isPositive`), so +`0 ≤ ⟪ψ, ((c : ℂ) • 1 - M) ψ⟫`; taking real parts and using `‖ψ‖ = 1` gives the bound. This is +the general operator statement: it takes a *raw* operator rather than a bundled `Observable`, so +an operator bound on a **sum** of observables (e.g. the CHSH operator, or the `√2³ • 1` output of +Tsirelson's inequality) descends to a bound on the sum of expectation values without first +repackaging that sum as a single `Observable`. The `Observable`-bundled bridge +`PureState.expectation_le_of_op_le_smul_one` is the corollary at `M := A.op`. -/ +theorem PureState.re_inner_apply_le_of_le_smul_one (ψ : PureState S) {M : S →L[ℂ] S} {c : ℝ} + (h : M ≤ c • (1 : S →L[ℂ] S)) : (inner ℂ ψ.vec (M ψ.vec)).re ≤ c := by + rw [← Complex.coe_smul] at h + have hpos : ((c : ℂ) • (1 : S →L[ℂ] S) - M).IsPositive := + (ContinuousLinearMap.nonneg_iff_isPositive).mp (sub_nonneg.mpr h) + have key : 0 ≤ inner ℂ ψ.vec (((c : ℂ) • (1 : S →L[ℂ] S) - M) ψ.vec) := + hpos.inner_nonneg_right ψ.vec + have hnorm : inner ℂ ψ.vec ψ.vec = (1 : ℂ) := by + rw [inner_self_eq_norm_sq_to_K, ψ.normalized]; norm_num + rw [sub_apply, smul_apply, + one_apply_eq_self, inner_sub_right, inner_smul_right, hnorm, mul_one] at key + -- key : (0 : ℂ) ≤ ↑c - ⟪ψ.vec, M ψ.vec⟫ (ComplexOrder) + have hre := (Complex.le_def.mp key).1 + simp only [Complex.zero_re, Complex.sub_re, Complex.ofReal_re] at hre + -- hre : 0 ≤ c - (⟪ψ.vec, M ψ.vec⟫).re + linarith + +/-- **Operator-order → expectation bridge.** If an observable `A` is bounded above by +`c • 1` in the operator (Loewner) order — `A.op ≤ c • 1` in the `StarOrderedRing` order on +`S →L[ℂ] S` — then its expectation value in any pure state `ψ` is at most `c`. This lets an +operator inequality proved in the C*-algebra `S →L[ℂ] S` (such as Tsirelson's bound) be read off +as a bound on the measured expectation value. + +The `Observable`-bundled corollary of `PureState.re_inner_apply_le_of_le_smul_one` at `M := A.op` +(after unfolding `expectation` to `Re ⟪ψ, A.op ψ⟫`). The scalar is written `(c : ℂ) • 1` (rather +than `c • 1` over `ℝ`) so the operator lives in the ambient complex algebra without extra +real-scalar-tower bookkeeping; `Complex.coe_smul` bridges it to the general +lemma's `ℝ`-smul hypothesis. -/ +theorem PureState.expectation_le_of_op_le_smul_one (ψ : PureState S) (A : Observable S) + {c : ℝ} (h : A.op ≤ (c : ℂ) • (1 : S →L[ℂ] S)) : + ψ.expectation A ≤ c := by + rw [Complex.coe_smul] at h + rw [PureState.expectation] + exact ψ.re_inner_apply_le_of_le_smul_one h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PartialTraceReassoc.lean b/LeanPool/AxQM/Postulates/API/PartialTraceReassoc.lean new file mode 100644 index 0000000000..bdcd3f6025 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PartialTraceReassoc.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.PartialTraceTensor + +/-! +# AxQM — the middle marginal of a first-cut product state + +For a product state `ρ ⊗ σ` on `A ⊗ (V ⊗ W)` (uncorrelated across the `A | VW` cut), the +marginal on `A ⊗ V` — obtained by re-associating to `(A ⊗ V) ⊗ W` and tracing out the outer +factor `W` — is again a product, `ρ ⊗ (Tr_W σ)`: + +`Tr_W (ρ ⊗ σ) = ρ ⊗ σ.reducedLeft`. + +This is the reduced-state analogue of associativity: the spectator factor `A` passes through the +partial trace untouched, and the trace lands on `σ`'s right factor. It is the tool for reading off +the `A ⊗ V` marginal of a tripartite product state `A ⊗ (V ⊗ W)` — the marginal that is otherwise +not a top-level `reducedLeft`/`reducedRight` because `W` sits in the middle after re-association. + +The proof passes through the density operators to `LinearMap.partialTraceRight` and the tensor +associator; the statement uses `State.congr`, `QSystem.assoc`, `State.tmul`, `State.reducedLeft`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A V W : QSystem} + +/-- **Right-regrouping a triple product state.** For factor states `ρ : State A`, `σ : State V`, +`τ : State W`, transporting the left-bracketed product `(ρ ⊗ σ) ⊗ τ` along the inverse associator +`(A ⊗ V) ⊗ W ≃ₛ A ⊗ (V ⊗ W)` yields the right-bracketed product `ρ ⊗ (σ ⊗ τ)`: + +`State.congr (QSystem.assoc A V W).symm ((ρ ⊗ σ) ⊗ τ) = ρ ⊗ (σ ⊗ τ)`. + +The `State`-level companion of `pureState_congr_assocSymm` (the `PureState` version). Proved at the +operator level: the associator's `conjStarAlgEquiv` re-brackets the triple tensor +`mapL (mapL ρ σ) τ` into `mapL ρ (mapL σ τ)` (`LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL`), +the transport being `(A.assoc V W).symm.toIsometry = assocIsometry` +(`QSystem.assoc_symm_toIsometry`). -/ +theorem State.congr_assoc_symm_tmul_tmul (ρ : State A) (σ : State V) (τ : State W) : + State.congr (QSystem.assoc A V W).symm ((ρ.tmul σ).tmul τ) = ρ.tmul (σ.tmul τ) := by + apply State.ext + rw [State.congr_op, State.tmul_op, State.tmul_op, State.tmul_op, State.tmul_op, + QSystem.assoc_symm_toIsometry] + exact LinearMap.assocIsometry_conjStarAlgEquiv_mapL_mapL ρ.op σ.op τ.op + +/-- **Left-regrouping a triple product state.** The forward companion of +`State.congr_assoc_symm_tmul_tmul`: transporting the right-bracketed product `ρ ⊗ (σ ⊗ τ)` along the +associator `A ⊗ (V ⊗ W) ≃ₛ (A ⊗ V) ⊗ W` yields the left-bracketed product `(ρ ⊗ σ) ⊗ τ`: + +`State.congr (QSystem.assoc A V W) (ρ ⊗ (σ ⊗ τ)) = (ρ ⊗ σ) ⊗ τ`. + +Immediate from `State.congr_assoc_symm_tmul_tmul` by cancelling the associator round-trip +(`State.congr_congr_symm`). -/ +theorem State.congr_assoc_tmul_tmul (ρ : State A) (σ : State V) (τ : State W) : + State.congr (QSystem.assoc A V W) (ρ.tmul (σ.tmul τ)) = (ρ.tmul σ).tmul τ := by + rw [← State.congr_assoc_symm_tmul_tmul ρ σ τ, State.congr_congr_symm] + +/-- **Middle marginal of a first-cut product state.** For `ρ : State A` and `σ : State (V ⊗ W)`, +re-associating the product `ρ ⊗ σ` on `A ⊗ (V ⊗ W)` to `(A ⊗ V) ⊗ W` and tracing out the outer +factor `W` leaves `ρ ⊗ (Tr_W σ)`: + +`(State.congr (QSystem.assoc A V W) (ρ ⊗ σ)).reducedLeft = ρ ⊗ σ.reducedLeft`. + +The spectator `A` factors through the partial trace; the reduction acts on `σ`. Proved at the +operator level via `LinearMap.partialTraceRight_assoc_conj_map` (the partial trace of an +associator-conjugated tensor map). -/ +theorem State.reducedLeft_congr_assoc_tmul (ρ : State A) (σ : State (V ⊗ W)) : + (State.congr (QSystem.assoc A V W) (ρ.tmul σ)).reducedLeft = ρ.tmul σ.reducedLeft := by + apply State.ext + apply ContinuousLinearMap.coe_injective + simp only [State.reducedLeft_op, State.congr_op, QSystem.assoc_toIsometry, State.tmul_op, + LinearMap.coe_toContinuousLinearMap, TensorProduct.toLinearMap_mapL] + have h1 := LinearMap.assocIsometry_symm_conjStarAlgEquiv_toLinearMap + (𝕜 := ℂ) (E := A.space) (F := V.space) (G := W.space) + (TensorProduct.mapL ρ.op σ.op) + have h2 := LinearMap.partialTraceRight_assoc_conj_map (stdOrthonormalBasis ℂ W.space) + ρ.op.toLinearMap σ.op.toLinearMap + have h3 := TensorProduct.toLinearMap_mapL ρ.op σ.op + have h1' := h1.trans (congrArg (TensorProduct.assoc ℂ A.space V.space W.space).symm.conj h3) + exact (congrArg (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ W.space)) h1').trans h2 + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliDiagWire.lean b/LeanPool/AxQM/Postulates/API/PauliDiagWire.lean new file mode 100644 index 0000000000..bbb3147576 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliDiagWire.lean @@ -0,0 +1,188 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftHadamardEvolution +public import LeanPool.AxQM.Postulates.API.UnitaryBlochRotation +public import LeanPool.AxQM.Concrete.PauliStringDiagonalize +public import LeanPool.AxQM.Concrete.KronFamilyWireProduct + +/-! +# The Problem 4.3(3) basis-change gate on a register wire, as an `Evolution` + +Problem 4.3(3)'s `O(n)`-gate circuit for `exp(-i h_g g Δ)` opens with a layer `B = ⨂ₖ B_{gₖ}` of +single-qubit basis-change gates, one per wire: `B_{gₖ} = pauliDiagGate (gₖ)` diagonalises the Pauli +factor `σ_{gₖ}` to `Z` (Hadamard for `X`, `S·H` for `Y`, identity for `I`/`Z`; +`Concrete/PauliStringDiagonalize`). To *count* that layer with the elementary-gate budget +`CircuitBudget` — which operates on the qubit control tower — each per-wire factor must first be a +named register `Evolution`, exactly as Problem 4.1's phase layer is built from +`phaseWireEvolution`. This file supplies that register-side gate. + +## What is formalised + +* `pauliDiagGateEvolution a` — the diagonalising gate `B_a = pauliDiagGate a` as a one-qubit + `Evolution qubit` (the `unitaryGate` promotion of the unitary matrix `pauliDiagGate a`). It is the + single-qubit factor the wire gate collapses to on a tower wire. +* `pauliDiagWireEvolution n t a` — `B_a` placed on wire `t` of the `2ⁿ`-level register, as an + `Evolution (qudit (2ⁿ))`: the `quditGate` promotion of `singleQubitOnWire finFunctionFinEquiv t + (pauliDiagGate a)`. It is the direct analogue of `phaseWireEvolution n t φ` / + `rotZWireEvolution n t θ`, the basis-change gate indexed by the Pauli `a : Fin 4` rather than a + real angle. +* `pauliDiagWireEvolution_evolvePure_quditBasis` — its computational-basis action: on + `|finFunctionFinEquiv f⟩` the wire-`t` component is mixed through the `f t`-column of + `pauliDiagGate a`. The instance of the reusable single-wire bridge + `quditGate_singleQubitOnWire_evolvePure_quditBasis` at `G = pauliDiagGate a`. +* `pauliDiagGateEvolution_evolvePure_qubitBasis_sum` — the single-qubit companion: + `pauliDiagGateEvolution a |z⟩ = ∑_w (pauliDiagGate a) w z · |w⟩`, the `z`-column of `pauliDiagGate + a`. The instance of the general `unitaryGate_evolvePure_qubitBasis_sum` (in + `UnitaryBlochRotation`, beside `unitaryGate`) at `M = pauliDiagGate a`. +* `pauliDiagLayer n g` — **the whole basis-change layer** `B = ⨂ₖ B_{gₖ}` as one `Evolution (qudit + (2ⁿ))`: the ordered product `∏_{t pauliDiagGate (g k)))`. The layer's operator is *exactly* the matrix + basis change `B` of `Concrete/PauliStringDiagonalize`, so the `Evolution` promotion genuinely + realises the tensor basis change and not merely some product of `n` gates. Via the operator + product law `pauliDiagWireEvolution_listProd_op` and the matrix factorisation + `Concrete.kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The Problem 4.3(3) diagonalising gate `B_a` as a one-qubit `Evolution`.** `pauliDiagGate a` +(the identity for `I`/`Z`, Hadamard for `X`, `S·H` for `Y`) promoted to `Evolution qubit` via +`unitaryGate` (unitary by `pauliDiagGate_mem_unitaryGroup`). It is the +single-qubit factor the wire gate `pauliDiagWireEvolution` collapses to on a tower wire. -/ +def pauliDiagGateEvolution (a : Fin 4) : Evolution qubit := + unitaryGate (pauliDiagGate_mem_unitaryGroup a) + +/-- **The Problem 4.3(3) basis-change gate `B_a` on a register wire, as an `Evolution`.** The +diagonalising gate `pauliDiagGate a` placed on wire `t` of the `2ⁿ`-level register `qudit (2ⁿ)`: the +`quditGate` promotion of `singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate a)`. Its basis +action is `pauliDiagWireEvolution_evolvePure_quditBasis`. The direct analogue of +`phaseWireEvolution n t φ`, with the phase gate replaced by the basis-change gate indexed by the +Pauli `a : Fin 4`. Taking `a = g t` over all wires `t` gives the layer `B = ⨂ₖ B_{gₖ}` factor by +factor. -/ +def pauliDiagWireEvolution (n : ℕ) (t : Fin n) (a : Fin 4) : Evolution (qudit (2 ^ n)) := + quditGate + (singleQubitOnWire_mem_unitaryGroup finFunctionFinEquiv t (pauliDiagGate_mem_unitaryGroup a)) + +/-- **The wire-`t` basis-change gate mixes wire `t` through the `pauliDiagGate a` column.** +`pauliDiagWireEvolution n t a |finFunctionFinEquiv f⟩ = ∑_z (pauliDiagGate a) z (f t) · +|finFunctionFinEquiv (update f t z)⟩`: the bit-string `f` addressing the wires has its wire-`t` +component mixed through the `f t`-column of `pauliDiagGate a`. The instance of the reusable bridge +`quditGate_singleQubitOnWire_evolvePure_quditBasis` at `G = pauliDiagGate a`, +`enc = finFunctionFinEquiv`. -/ +theorem pauliDiagWireEvolution_evolvePure_quditBasis (n : ℕ) (t : Fin n) (a : Fin 4) + (f : Fin n → Fin 2) : + ((pauliDiagWireEvolution n t a).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = ∑ z : Fin 2, pauliDiagGate a z (f t) • + (quditBasis (finFunctionFinEquiv (Function.update f t z))).vec := + quditGate_singleQubitOnWire_evolvePure_quditBasis finFunctionFinEquiv t + (pauliDiagGate_mem_unitaryGroup a) f + +/-- **The one-qubit diagonalising gate acts as its matrix column.** +`pauliDiagGateEvolution a |z⟩ = ∑_w (pauliDiagGate a) w z · |w⟩`, the `z`-column of `pauliDiagGate +a`. The instance of the general `unitaryGate_evolvePure_qubitBasis_sum` at `M = pauliDiagGate a`. +The single-wire factor the tower re-expression matches the register superposition +`pauliDiagWireEvolution_evolvePure_quditBasis` against. -/ +theorem pauliDiagGateEvolution_evolvePure_qubitBasis_sum (a : Fin 4) (z : Fin 2) : + ((pauliDiagGateEvolution a).evolvePure (qubitBasis z)).vec + = ∑ w : Fin 2, pauliDiagGate a w z • (qubitBasis w).vec := + unitaryGate_evolvePure_qubitBasis_sum (pauliDiagGate_mem_unitaryGroup a) z + +/-- **A product of single-wire basis-change gates is `toEuclideanCLM` of the matrix product.** For +any list `l` of wires, the operator of the composed circuit `∏_{t ∈ l} B_{gₜ}` of per-wire +diagonalising gates is the promotion through `Matrix.toEuclideanCLM` of the ordered matrix product +of the single-wire gate matrices `singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate (g t))`: + +`((l.map fun t => pauliDiagWireEvolution n t (g t)).prod).op` +`= Matrix.toEuclideanCLM ((l.map fun t => singleQubitOnWire finFunctionFinEquiv t + (pauliDiagGate (g t))).prod)`. + +This is the operator-level shadow of the matrix factorisation +`Concrete.kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire`: each factor's operator is +`toEuclideanCLM` of its gate matrix (`quditGate_op`), and `Matrix.toEuclideanCLM` is a `⋆`-algebra +isomorphism, so it carries the matrix product to the operator composition (`map_mul`) and the empty +product to the identity (`map_one`). Proved by induction on `l`: each `cons` splits off the head +gate (`Evolution.comp_op`; `map_mul`) and the `nil` base is `map_one`. -/ +theorem pauliDiagWireEvolution_listProd_op (n : ℕ) (g : Fin n → Fin 4) (l : List (Fin n)) : + ((l.map fun t => pauliDiagWireEvolution n t (g t)).prod).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((l.map fun t => singleQubitOnWire finFunctionFinEquiv t (pauliDiagGate (g t))).prod) := by + induction l with + | nil => + simp only [List.map_nil, List.prod_nil, Evolution.one_def, Evolution.id_op] + exact (map_one (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)))).symm + | cons a l ih => + simp only [List.map_cons, List.prod_cons] + rw [Evolution.mul_def, Evolution.comp_op, ih, pauliDiagWireEvolution, quditGate_op, map_mul] + rfl + +/-- **The Problem 4.3(3) basis-change layer** `B = ⨂ₖ B_{gₖ}` as an `Evolution`. The composition +`∏_{t pauliDiagWireEvolution n t (g t)).prod + +/-- **The basis-change layer realises the tensor basis change `B`.** The operator of +`pauliDiagLayer n g` is exactly the matrix basis change `B = ⨂ₖ B_{gₖ}` diagonalising the Pauli +string `g`, promoted through `Matrix.toEuclideanCLM`: + +`(pauliDiagLayer n g).op = Matrix.toEuclideanCLM (kronFamilyStd (fun k => pauliDiagGate (g k)))`. + +This is the **faithfulness** of the promotion: the `n`-gate `Evolution` layer really *is* the +tensor-product basis change of `Concrete/PauliStringDiagonalize`, not merely some product of `n` +gates. Immediate from the operator product law `pauliDiagWireEvolution_listProd_op` and the matrix +factorisation `Concrete.kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire`. -/ +theorem pauliDiagLayer_op (n : ℕ) (g : Fin n → Fin 4) : + (pauliDiagLayer n g).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + (kronFamilyStd (fun k => pauliDiagGate (g k))) := by + rw [pauliDiagLayer, pauliDiagWireEvolution_listProd_op, + kronFamilyStd_pauliDiagGate_eq_prod_singleQubitOnWire] + +/-- **Adjoint faithfulness of the basis-change layer (the uncomputation `B†`).** The operator of +`(pauliDiagLayer n g).adjoint` is `Matrix.toEuclideanCLM` of the conjugate transpose of the tensor +basis-change matrix `B = ⨂ₖ B_{gₖ}`: + +`(pauliDiagLayer n g).adjoint.op = Matrix.toEuclideanCLM ((kronFamilyStd (fun k => pauliDiagGate +(g k)))ᴴ)`. + +The adjoint companion of `pauliDiagLayer_op`: the `Evolution` adjoint's operator is the +Hilbert-space adjoint of the layer's operator (`Evolution.adjoint_op`), which `toEuclideanCLM` +carries to the matrix conjugate transpose (`Matrix.toEuclideanCLM_conjTranspose_eq_adjoint`). This +is the faithfulness of the basis change's *uncomputation* — the `B†` that closes the Figure-4.19 +compute–rotate–uncompute cascade (Problem 4.3(3)). -/ +theorem pauliDiagLayer_adjoint_op (n : ℕ) (g : Fin n → Fin 4) : + (pauliDiagLayer n g).adjoint.op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ) := by + rw [Evolution.adjoint_op, pauliDiagLayer_op] + exact (Matrix.toEuclideanCLM_conjTranspose_eq_adjoint _).symm + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliEigen.lean b/LeanPool/AxQM/Postulates/API/PauliEigen.lean new file mode 100644 index 0000000000..b0479ea61d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliEigen.lean @@ -0,0 +1,188 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliMeasurement +public import LeanPool.AxQM.Postulates.API.HadamardEigen + +/-! +# AxQM.Postulates.API — the eigenprojectors of `v · σ` project onto its `±1` eigenspaces + +Results on the **second half of Nielsen & Chuang Exercise 2.60** ("the +projectors onto the corresponding eigenspaces are `P± = (I ± v_vec·σ_vec)/2`", §2.2.5, p. 90) and +the +eigenvalue-existence witnesses behind its first half. + +The eigenprojectors themselves — `Observable.projPlus A = (I + A)/2`, `Observable.projMinus A = +(I − A)/2`, their self-adjointness/idempotence, `P₊ + P₋ = 1`, and the two-outcome projective +`Observable.signMeasurement` — are in `AxQM/Postulates/API/PauliMeasurement.lean` (used +there for Exercise 2.61). This file adds what Exercise 2.60 additionally asserts of them, for an +arbitrary self-adjoint involution observable `A` (`A² = 1`): + +* `op_mul_projPlus` / `op_mul_projMinus` (`A·P₊ = P₊`, `A·P₋ = −P₋`) — the range of `P±` lies in + the `±1` eigenspace; with `projPlus_apply_eq_self` / `projMinus_apply_eq_self` + (`A u = ±u → P± u = u`) — the `±1` eigenspace lies in the range of `P±`; together `range P±` is + *exactly* the `(±1)`-eigenspace, i.e. `P±` **are** the projectors onto the eigenspaces; +* `projPlus_mul_projMinus` (`P₊ P₋ = 0`, orthogonal complementary) and + `projPlus_sub_projMinus` (`P₊ − P₋ = A`, the spectral decomposition `A = (+1)P₊ + (−1)P₋`); +* `exists_hasEigenstate_{one,neg_one}_of_proj…_ne_zero` — a nonvanishing eigenprojector realizes + its eigenvalue: `range P±` is the eigenspace, so a nonzero `P±` supplies a unit `±1`-eigenstate. + +Instantiated at `v · σ` (for any `v`): `pauliObservable_proj{Plus,Minus}_ne_zero` (both +eigenprojectors are nonzero — else `v · σ` would be the scalar `∓1`, contradicting the traceless +diagonal, via `Concrete.pauliDot_ne_{neg_one,one}`), from which +[upstream `AxQM/NC/Ch2/Exercise2_60.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_60.lean) derives that `v · σ` has both `±1` as eigenvalues. + +The statement that `v · σ` has eigenvalues *exactly* `±1` is in terms of +`Observable.HasEigenstate` in [upstream `AxQM/NC/Ch2/Exercise2_60.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_60.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +open ContinuousLinearMap Matrix + +variable {S : QSystem} + +/-! ### The eigenprojectors project onto the `±1` eigenspaces -/ + +/-- **`P₊` projects into the `+1` eigenspace:** `A · P₊ = P₊`, so `A(P₊ w) = P₊ w` for every `w`. +From `A² = 1`: `A·½(1+A) = ½(A + A²) = ½(A + 1) = ½(1 + A)`. -/ +theorem Observable.op_mul_projPlus (A : Observable S) (hinv : A.op * A.op = 1) : + A.op * A.projPlus = A.projPlus := by + simp only [Observable.projPlus, mul_smul_comm, mul_add, mul_one, hinv] + match_scalars <;> ring + +/-- **`P₋` projects into the `−1` eigenspace:** `A · P₋ = −P₋`, so `A(P₋ w) = −(P₋ w)` for every +`w`. From `A² = 1`: `A·½(1−A) = ½(A − A²) = ½(A − 1) = −½(1 − A)`. -/ +theorem Observable.op_mul_projMinus (A : Observable S) (hinv : A.op * A.op = 1) : + A.op * A.projMinus = -A.projMinus := by + simp only [Observable.projMinus, mul_smul_comm, mul_sub, mul_one, hinv] + match_scalars <;> ring + +/-- **The `+1` eigenspace lies in the range of `P₊`:** if `A u = u` then `P₊ u = u`. With +`op_mul_projPlus` this pins `range P₊` to the `+1` eigenspace exactly. -/ +theorem Observable.projPlus_apply_eq_self (A : Observable S) {u : S.space} (hu : A.op u = u) : + A.projPlus u = u := by + simp only [Observable.projPlus, _root_.smul_apply, _root_.add_apply, + one_apply_eq_self, hu] + module + +/-- **The `−1` eigenspace lies in the range of `P₋`:** if `A u = −u` then `P₋ u = u`. With +`op_mul_projMinus` this pins `range P₋` to the `−1` eigenspace exactly. -/ +theorem Observable.projMinus_apply_eq_self (A : Observable S) {u : S.space} (hu : A.op u = -u) : + A.projMinus u = u := by + simp only [Observable.projMinus, _root_.smul_apply, _root_.sub_apply, + one_apply_eq_self, hu] + module + +/-- **`P₊` on a `c`-eigenvector:** if `A u = c • u` then `P₊ u = ½(1 + c) • u`. The +general-eigenvalue form of `projPlus_apply_eq_self` (its `c = 1` case), giving the +`+1`-measurement coefficient on any eigenvector of a `±1` observable. -/ +theorem Observable.projPlus_apply_smul (A : Observable S) {v : S.space} {c : ℂ} + (h : A.op v = c • v) : A.projPlus v = (2⁻¹ * (1 + c)) • v := by + rw [Observable.projPlus, _root_.smul_apply, _root_.add_apply, + one_apply_eq_self, h] + module + +/-- **`P₋` on a `c`-eigenvector:** if `A u = c • u` then `P₋ u = ½(1 − c) • u`. The +general-eigenvalue form of `projMinus_apply_eq_self` (its `c = −1` case), giving the +`−1`-measurement coefficient on any eigenvector of a `±1` observable. -/ +theorem Observable.projMinus_apply_smul (A : Observable S) {v : S.space} {c : ℂ} + (h : A.op v = c • v) : A.projMinus v = (2⁻¹ * (1 - c)) • v := by + rw [Observable.projMinus, _root_.smul_apply, _root_.sub_apply, + one_apply_eq_self, h] + module + +/-- **Orthogonality of the eigenprojectors:** `P₊ P₋ = 0` (their ranges — the `±1` eigenspaces — +are orthogonal). From `A² = 1`: `¼(1 + A)(1 − A) = ¼(1 − A²) = 0`. -/ +theorem Observable.projPlus_mul_projMinus (A : Observable S) (hinv : A.op * A.op = 1) : + A.projPlus * A.projMinus = 0 := by + simp only [Observable.projPlus, Observable.projMinus, smul_mul_smul_comm, mul_sub, add_mul, + one_mul, mul_one, hinv] + match_scalars <;> ring + +/-- **Spectral decomposition:** `P₊ − P₋ = A`, i.e. `A = (+1)P₊ + (−1)P₋`. -/ +theorem Observable.projPlus_sub_projMinus (A : Observable S) : + A.projPlus - A.projMinus = A.op := by + simp only [Observable.projPlus, Observable.projMinus] + match_scalars <;> ring + +/-! ### Existence of eigenstates from nonvanishing eigenprojectors -/ + +/-- **A nonzero `+1` eigenprojector realizes the eigenvalue `+1`.** If `P₊ ≠ 0` then `A` has a +`+1` eigenstate: pick `x` with `P₊ x ≠ 0`; then `A(P₊ x) = P₊ x` (as `A · P₊ = P₊`), so the +normalized `P₊ x` (via the shared `PureState.normalize`) is a unit `+1` eigenstate. -/ +theorem Observable.exists_hasEigenstate_one_of_projPlus_ne_zero (A : Observable S) + (hinv : A.op * A.op = 1) (hne : A.projPlus ≠ 0) : + ∃ ψ : PureState S, A.HasEigenstate 1 ψ := by + obtain ⟨x, hx⟩ := DFunLike.ne_iff.mp hne + rw [_root_.zero_apply] at hx + have hAu : A.op (A.projPlus x) = A.projPlus x := by + have := congrArg (fun T : S.space →L[ℂ] S.space => T x) (A.op_mul_projPlus hinv) + simpa [mul_apply_eq_comp] using this + refine ⟨PureState.normalize _ hx, A.hasEigenstate_of_smul + (c := ((‖A.projPlus x‖ : ℝ) : ℂ)⁻¹) (v := A.projPlus x) rfl ?_⟩ + rw [hAu]; norm_num + +/-- **A nonzero `−1` eigenprojector realizes the eigenvalue `−1`.** If `P₋ ≠ 0` then `A` has a +`−1` eigenstate: pick `x` with `P₋ x ≠ 0`; then `A(P₋ x) = −(P₋ x)` (as `A · P₋ = −P₋`), so the +normalized `P₋ x` (via the shared `PureState.normalize`) is a unit `−1` eigenstate. -/ +theorem Observable.exists_hasEigenstate_neg_one_of_projMinus_ne_zero (A : Observable S) + (hinv : A.op * A.op = 1) (hne : A.projMinus ≠ 0) : + ∃ ψ : PureState S, A.HasEigenstate (-1) ψ := by + obtain ⟨x, hx⟩ := DFunLike.ne_iff.mp hne + rw [_root_.zero_apply] at hx + have hAu : A.op (A.projMinus x) = -(A.projMinus x) := by + have := congrArg (fun T : S.space →L[ℂ] S.space => T x) (A.op_mul_projMinus hinv) + simpa [mul_apply_eq_comp] using this + refine ⟨PureState.normalize _ hx, A.hasEigenstate_of_smul + (c := ((‖A.projMinus x‖ : ℝ) : ℂ)⁻¹) (v := A.projMinus x) rfl ?_⟩ + rw [hAu]; push_cast; module + +/-! ### The eigenprojectors of `v · σ` are nonzero -/ + +/-- **The `+1` eigenprojector of `v · σ` is nonzero** (for any `v`, in particular a unit vector). +Were `½(1 + v·σ) = 0` then `v · σ = −1` as an operator; injectivity of `Matrix.toEuclideanCLM` +forces `pauliDot v = −1`, impossible for the traceless diagonal `(v₂, −v₂)` +(`Concrete.pauliDot_ne_neg_one`). Hence (for a unit vector) `+1` is an eigenvalue of `v · σ`. -/ +theorem pauliObservable_projPlus_ne_zero (v : Fin 3 → ℝ) : + (pauliObservable v).projPlus ≠ 0 := by + intro h + rw [Observable.projPlus, smul_eq_zero] at h + rcases h with h | h + · norm_num at h + rw [pauliObservable_op] at h + refine Concrete.pauliDot_ne_neg_one v ?_ + apply (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).injective + rw [map_neg, map_one] + exact eq_neg_of_add_eq_zero_right h + +/-- **The `−1` eigenprojector of `v · σ` is nonzero** (for any `v`, in particular a unit vector). +Were `½(1 − v·σ) = 0` then `v · σ = 1`; injectivity forces `pauliDot v = 1`, impossible for the +traceless diagonal `(v₂, −v₂)` (`Concrete.pauliDot_ne_one`). Hence (for a unit vector) `−1` is an +eigenvalue of `v · σ`. -/ +theorem pauliObservable_projMinus_ne_zero (v : Fin 3 → ℝ) : + (pauliObservable v).projMinus ≠ 0 := by + intro h + rw [Observable.projMinus, smul_eq_zero] at h + rcases h with h | h + · norm_num at h + rw [pauliObservable_op] at h + refine Concrete.pauliDot_ne_one v ?_ + apply (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).injective + rw [map_one] + exact (sub_eq_zero.mp h).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliExpansion.lean b/LeanPool/AxQM/Postulates/API/PauliExpansion.lean new file mode 100644 index 0000000000..01653044af --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliExpansion.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Concrete.PauliString +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin + +/-! +# AxQM.Postulates.API — the real Pauli expansion of a Hamiltonian (N&C Problem 4.3(2)) + +Part (2) of Nielsen & Chuang, Problem 4.3: *the Hamiltonian +`H = i ln(U)` can be written `H = Σ_g h_g g` with real `h_g`, the sum over all `n`-fold tensor +products `g` of the Pauli matrices `{I, X, Y, Z}`.* In this library a Hamiltonian is an +`Observable` — a self-adjoint operator (Postulate 2) — and the `n`-qubit register is the +`2ⁿ`-level system `qudit (2ⁿ)`. The statement here says +that the matrix of *any* Hamiltonian on the `n`-qubit register, written in the computational +basis and reindexed to bit strings, is a **real**-coefficient combination of Pauli strings. + +The purely mathematical content — the `n`-fold Pauli strings form a basis of `M₂ₙ(ℂ)` and every +Hermitian matrix has a real Pauli expansion — is proved in `AxQM/Concrete/PauliString.lean` +(`AxQM.Concrete.exists_real_pauliString_expansion`). This file turns an `Observable` (a bundled +self-adjoint operator) into a Hermitian matrix and applies that mathematics, so part (2) is stated +for observables. + +## What this file provides + +* `Observable.stdMatrix` — the matrix of an observable (Hamiltonian) on `qudit d` in the + **computational basis** `|0⟩, …, |d-1⟩` (the orthonormal `EuclideanSpace.basisFun`): the + operator→matrix bridge for an `Observable`. (It represents a self-adjoint operator; the + Trotter parts (4)/(5) instead need the matrices of the *unitary* evolutions `exp(-iHΔ)`, a + distinct `Evolution`→matrix bridge, so `stdMatrix` does not serve them directly.) +* `Observable.stdMatrix_apply` — the characterizing entry formula `⟨i|H|j⟩ = ⟪|i⟩, H|j⟩⟫`. +* `Observable.stdMatrix_isHermitian` — that matrix is Hermitian, because the operator is + self-adjoint (the entries `⟨i|H|j⟩` satisfy `conj ⟨j|H|i⟩ = ⟨i|H|j⟩`). +* `Observable.exists_real_pauliString_expansion` — **Problem 4.3(2)**: for a Hamiltonian + `H : Observable (qudit (2ⁿ))`, its computational-basis matrix reindexed to bit strings + (`Fin n → Fin 2`) is `Σ_g (h_g : ℂ) • pauliString g` for real `h_g`. + +## Design notes + +* **Register model.** N&C's "`n` qubits" is the `2ⁿ`-dimensional register `qudit (2ⁿ)` + (`EuclideanSpace ℂ (Fin (2ⁿ))`). The Pauli-string mathematics is indexed by bit strings + `Fin n → Fin 2`, so we reindex the `Fin (2ⁿ)`-indexed matrix along `finFunctionFinEquiv : + (Fin n → Fin 2) ≃ Fin (2ⁿ)` (via `Matrix.submatrix`), which preserves Hermitianness + (`Matrix.IsHermitian.submatrix`). +* **Any Hamiltonian, not just `i ln U`.** N&C introduce `H` as `i ln U`, but the expansion uses + *only* that `H` is Hermitian; the `= i ln U` plays no role in part (2). Stating it for every + `Observable` is the faithful, reusable form, and specialises to `H = i ln U` by combining with + the generator existence `Evolution.exists_hamiltonian_generator` (part (1), + [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean)). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open Matrix + +noncomputable section + +namespace AxQM + +variable {d : ℕ} + +/-- The **computational-basis matrix** of an observable (Hamiltonian) on the `d`-level register +`qudit d`: the matrix of `H.op` with respect to the orthonormal computational basis +`EuclideanSpace.basisFun`, whose `(i, j)` entry is `⟨i|H|j⟩ = ⟪|i⟩, H|j⟩⟫`. The operator→matrix +bridge for an `Observable` on `qudit d`; its characterizing entry formula is `stdMatrix_apply`. -/ +def Observable.stdMatrix (H : Observable (qudit d)) : Matrix (Fin d) (Fin d) ℂ := + LinearMap.toMatrixOrthonormal (EuclideanSpace.basisFun (Fin d) ℂ) H.op.toLinearMap + +/-- **Entry formula for the computational-basis matrix**: the `(i, j)` entry of `H.stdMatrix` is the +matrix element `⟨i|H|j⟩ = ⟪|i⟩, H|j⟩⟫` of `H.op` between the computational-basis states +`|i⟩ = quditBasis i`. This is `LinearMap.toMatrixOrthonormal_apply_apply` composed with the +identification `EuclideanSpace.basisFun i = EuclideanSpace.single i 1 = (quditBasis i).vec`, so +the bridge can be used without re-deriving its entries. -/ +@[simp] +theorem Observable.stdMatrix_apply (H : Observable (qudit d)) (i j : Fin d) : + H.stdMatrix i j = inner ℂ (quditBasis i).vec (H.op (quditBasis j).vec) := by + rw [Observable.stdMatrix] + erw [LinearMap.toMatrixOrthonormal_apply_apply] + rw [EuclideanSpace.basisFun_apply, EuclideanSpace.basisFun_apply] + rfl + +/-- The computational-basis matrix of an observable is Hermitian. -/ +theorem Observable.stdMatrix_isHermitian (H : Observable (qudit d)) : H.stdMatrix.IsHermitian := by + rw [Matrix.IsHermitian] + ext i j + rw [Matrix.conjTranspose_apply, Observable.stdMatrix_apply, Observable.stdMatrix_apply, + RCLike.star_def, inner_conj_symm] + exact H.isSymmetric _ _ + +/-- **Nielsen & Chuang, Problem 4.3(2): real Pauli expansion of a Hamiltonian.** For a Hamiltonian +`H : Observable (qudit (2ⁿ))` on the `n`-qubit register, its computational-basis matrix, reindexed +to bit strings `Fin n → Fin 2`, is a **real**-coefficient combination of the `n`-fold Pauli strings: +`H = Σ_g (h_g : ℂ) • pauliString g` with `h_g : ℝ`. This uses that the +Hamiltonian is self-adjoint, hence its matrix is Hermitian (`Observable.stdMatrix_isHermitian`), and +the matrix-level expansion `Concrete.exists_real_pauliString_expansion`. -/ +theorem Observable.exists_real_pauliString_expansion {n : ℕ} (H : Observable (qudit (2 ^ n))) : + ∃ h : (Fin n → Fin 4) → ℝ, + H.stdMatrix.submatrix finFunctionFinEquiv finFunctionFinEquiv + = ∑ g, (h g : ℂ) • Concrete.pauliString g := + Concrete.exists_real_pauliString_expansion + (H.stdMatrix_isHermitian.submatrix finFunctionFinEquiv) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliMeasurement.lean b/LeanPool/AxQM/Postulates/API/PauliMeasurement.lean new file mode 100644 index 0000000000..0be4c86d2f --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliMeasurement.lean @@ -0,0 +1,347 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# AxQM.Postulates.API — projective measurement of a `±1` observable, and `v · σ` on `|0⟩` + +The infrastructure behind Nielsen & Chuang Exercises 2.60–2.61: the **projective +measurement of an observable whose square is the identity** (a self-adjoint involution, eigenvalues +`±1`), and its specialization to the Pauli vector observable `v · σ` measured on the computational +basis state `|0⟩`. + +## The `±1` (dichotomic) measurement + +For an observable `A : Observable S` with `A² = I`, the two orthogonal projectors + +* `Observable.projPlus A = (I + A)/2` (onto the `+1` eigenspace), +* `Observable.projMinus A = (I − A)/2` (onto the `−1` eigenspace) + +are the eigenprojectors of Exercise 2.60. Each is self-adjoint (`A` is), and — using `A² = I` — +idempotent (`P±² = P±`) with `P₊ + P₋ = I`; hence `∑ Mᵢ† Mᵢ = P₊ + P₋ = I` and they assemble into a +genuine two-outcome `Measurement (Fin 2) S`, `Observable.signMeasurement` (outcome `0 ↔ +1`, +`1 ↔ −1`). The Born rule for its `+1` outcome on a pure state is + +`bornProb (signMeasurement A) |ψ⟩⟨ψ| 0 = (1 + ⟪A⟫_ψ) / 2` + +(`Observable.bornProb_signMeasurement_plus`), in terms of the `Measurement.bornProb` and +`PureState.expectation` — the general form of Exercise 2.61's probability. + +## The qubit `|0⟩` and `v · σ` + +* `pauliObservable_expectation_qubitKet0` — `⟪v · σ⟫_{|0⟩} = v₃` (`= n 2`), since only the `Z` + component survives on `|0⟩`. (The `|0⟩` state `qubitKet0` and the normalization helper + `PureState.normalize` are in `AxQM/Postulates/API/Qubit.lean` and + `AxQM/Postulates/API/PureState.lean`.) + +Combining, the `+1` probability on `|0⟩` is `(1 + v₃)/2` — the answer to Exercise 2.61, stated as +the statement of Exercise 2.61 in [upstream `AxQM/NC/Ch2/Exercise2_61.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_61.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace Matrix +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace Observable + +/-! ### The eigenprojectors `P± = (I ± A)/2` of a `±1` observable -/ + +/-- The **`+1` eigenprojector** `P₊ = (I + A)/2` of an observable `A` (N&C Exercise 2.60). A genuine +projector exactly when `A² = I`. -/ +def projPlus (A : Observable S) : S →L[ℂ] S := (2⁻¹ : ℂ) • (1 + A.op) + +/-- The **`−1` eigenprojector** `P₋ = (I − A)/2` of an observable `A` (N&C Exercise 2.60). -/ +def projMinus (A : Observable S) : S →L[ℂ] S := (2⁻¹ : ℂ) • (1 - A.op) + +/-- `P₊` is self-adjoint: `A` is, and `(I + A)/2` is a real combination of self-adjoints. -/ +theorem projPlus_isSelfAdjoint (A : Observable S) : IsSelfAdjoint A.projPlus := by + rw [projPlus, IsSelfAdjoint, star_smul, star_add, star_one, A.selfAdjoint.star_eq] + norm_num + +/-- `P₋` is self-adjoint. -/ +theorem projMinus_isSelfAdjoint (A : Observable S) : IsSelfAdjoint A.projMinus := by + rw [projMinus, IsSelfAdjoint, star_smul, star_sub, star_one, A.selfAdjoint.star_eq] + norm_num + +/-- `adjoint P₊ = P₊` (self-adjointness in operator form). -/ +theorem adjoint_projPlus (A : Observable S) : adjoint A.projPlus = A.projPlus := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact A.projPlus_isSelfAdjoint + +/-- `adjoint P₋ = P₋`. -/ +theorem adjoint_projMinus (A : Observable S) : adjoint A.projMinus = A.projMinus := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact A.projMinus_isSelfAdjoint + +/-- For an involution `A² = I`, the `+1` eigenprojector is **idempotent**: `P₊² = P₊`. -/ +theorem projPlus_mul_self (A : Observable S) (hinv : A.op * A.op = 1) : + A.projPlus * A.projPlus = A.projPlus := by + have hB : (1 + A.op) * (1 + A.op) = (2 : ℂ) • (1 + A.op) := by + rw [two_smul, mul_add, add_mul, add_mul] + simp only [mul_one, one_mul, hinv]; abel + rw [projPlus, smul_mul_smul_comm, hB, smul_smul] + norm_num + +/-- For an involution `A² = I`, the `−1` eigenprojector is idempotent: `P₋² = P₋`. -/ +theorem projMinus_mul_self (A : Observable S) (hinv : A.op * A.op = 1) : + A.projMinus * A.projMinus = A.projMinus := by + have hB : (1 - A.op) * (1 - A.op) = (2 : ℂ) • (1 - A.op) := by + rw [two_smul, mul_sub, sub_mul, sub_mul] + simp only [mul_one, one_mul, hinv]; abel + rw [projMinus, smul_mul_smul_comm, hB, smul_smul] + norm_num + +/-- The eigenprojectors resolve the identity: `P₊ + P₋ = I`. -/ +theorem projPlus_add_projMinus (A : Observable S) : A.projPlus + A.projMinus = 1 := by + rw [projPlus, projMinus, ← smul_add] + rw [show (1 + A.op) + (1 - A.op) = (2 : ℂ) • (1 : S →L[ℂ] S) by rw [two_smul]; abel, smul_smul] + norm_num + +/-! ### The two-outcome projective measurement -/ + +/-- The **projective measurement of a `±1` observable** `A` (an involution `A² = I`): the +two-outcome measurement with operators `M₀ = P₊`, `M₁ = P₋` (outcome `0 ↔ +1`, `1 ↔ −1`). +Completeness `∑ᵢ Mᵢ† Mᵢ = P₊ + P₋ = I` uses that each `P±` is a self-adjoint idempotent. This is +the projective measurement "of the observable `A`" (N&C §2.2.5); its `+1` outcome is Exercise +2.61. -/ +def signMeasurement (A : Observable S) (hinv : A.op * A.op = 1) : Measurement (Fin 2) S where + op := ![A.projPlus, A.projMinus] + complete := by + rw [Fin.sum_univ_two] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one, + A.adjoint_projPlus, A.adjoint_projMinus, ← ContinuousLinearMap.mul_def, + A.projPlus_mul_self hinv, A.projMinus_mul_self hinv] + exact A.projPlus_add_projMinus + +@[simp] +theorem signMeasurement_op_zero (A : Observable S) (hinv : A.op * A.op = 1) : + (A.signMeasurement hinv).op 0 = A.projPlus := rfl + +@[simp] +theorem signMeasurement_op_one (A : Observable S) (hinv : A.op * A.op = 1) : + (A.signMeasurement hinv).op 1 = A.projMinus := rfl + +/-! ### The Born rule for the `+1` outcome on a pure state -/ + +/-- **Born rule for the `+1` outcome** of the `±1` measurement of `A` on a pure state `|ψ⟩`: +`p(+1) = (1 + ⟪A⟫_ψ)/2`. In terms of `Measurement.bornProb` and +`PureState.expectation`: `p(+1) = Re⟪ψ, P₊ ψ⟫ = Re⟪ψ, (ψ + A ψ)/2⟫ = (1 + Re⟪ψ, A ψ⟫)/2`. +The general form of Nielsen & Chuang Exercise 2.61's probability. -/ +theorem bornProb_signMeasurement_plus (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = (1 + ψ.expectation A) / 2 := by + rw [Measurement.bornProb, POVM.toPMF_eq, Measurement.toPOVM_elements, signMeasurement_op_zero, + A.adjoint_projPlus] + simp only [← ContinuousLinearMap.mul_def] + rw [A.projPlus_mul_self hinv, PureState.toState_op, ContinuousLinearMap.mul_def, + InnerProductSpace.comp_rankOne, InnerProductSpace.trace_rankOne, projPlus] + simp only [_root_.smul_apply, _root_.add_apply, + one_apply_eq_self, inner_smul_right, inner_add_right, + inner_self_eq_norm_sq_to_K, ψ.normalized, PureState.expectation] + rw [RCLike.re_to_complex, Complex.mul_re, Complex.add_re]; norm_num; ring + +/-- **Born rule for the `−1` outcome** of the `±1` measurement of `A` on a pure state `|ψ⟩`: +`p(−1) = (1 − ⟪A⟫_ψ)/2`. The companion of `bornProb_signMeasurement_plus`, obtained from it via +Born-rule normalization `p(+1) + p(−1) = 1` (`sum_bornProb_eq_one` on the two-outcome measurement): +`p(−1) = 1 − (1 + ⟪A⟫_ψ)/2 = (1 − ⟪A⟫_ψ)/2`. -/ +theorem bornProb_signMeasurement_minus (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = (1 - ψ.expectation A) / 2 := by + have hsum := (A.signMeasurement hinv).sum_bornProb_eq_one ψ.toState + rw [Fin.sum_univ_two, A.bornProb_signMeasurement_plus hinv ψ] at hsum + linarith + +/-- The post-measurement operation for the `+1` outcome sends `|ψ⟩⟨ψ|` to the rank-one operator +`|P₊ψ⟩⟨P₊ψ|`: `M₀ ρ M₀† = P₊ |ψ⟩⟨ψ| P₊ = |P₊ψ⟩⟨P₊ψ|`, using `adjoint P₊ = P₊` and the rank-one +composition rules. The core of both the Born-rule norm-square form and the collapse identity. -/ +theorem postOp_signMeasurement_zero (A : Observable S) (hinv : A.op * A.op = 1) (ψ : PureState S) : + ContinuousLinearMap.postOp (A.signMeasurement hinv).op ψ.toState.op 0 + = rankOne ℂ (A.projPlus ψ.vec) (A.projPlus ψ.vec) := by + simp only [ContinuousLinearMap.postOp, signMeasurement_op_zero, PureState.toState_op, + A.adjoint_projPlus, InnerProductSpace.comp_rankOne, InnerProductSpace.rankOne_comp] + +/-- **Born probability of `+1` as a squared norm:** `p(+1) = ‖P₊|ψ⟩‖²`. Follows from +`bornProb_eq_re_trace_postOp` and `postOp_signMeasurement_zero`. Used to certify that `+1` is a +possible outcome (`p ≠ 0`) exactly when `P₊|ψ⟩ ≠ 0`. -/ +theorem bornProb_signMeasurement_plus_eq_normSq (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = ‖A.projPlus ψ.vec‖ ^ 2 := by + rw [Measurement.bornProb_eq_re_trace_postOp, postOp_signMeasurement_zero, + InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq] + +/-- If the `+1` outcome is possible (`p(+1) ≠ 0`), then `P₊|ψ⟩ ≠ 0` — the post-measurement state is +well-defined. Contrapositive of `bornProb_signMeasurement_plus_eq_normSq`. -/ +theorem projPlus_apply_ne_zero_of_bornProb (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) (hp : (A.signMeasurement hinv).bornProb ψ.toState 0 ≠ 0) : + A.projPlus ψ.vec ≠ 0 := by + intro h0 + exact hp (by rw [bornProb_signMeasurement_plus_eq_normSq, h0, norm_zero]; norm_num) + +/-! ### The post-measurement state after obtaining `+1` -/ + +/-- The **normalized `+1` post-measurement pure state** `P₊|ψ⟩ / ‖P₊|ψ⟩‖` — the collapsed state of +Postulate 4 after the `±1` measurement of `A` yields `+1`, defined when `P₊|ψ⟩ ≠ 0` (i.e. when `+1` +is a possible outcome). It is the `+1` eigenstate of `A` (Nielsen & Chuang Exercise 2.61). -/ +def postMeasPlus (A : Observable S) (ψ : PureState S) (hne : A.projPlus ψ.vec ≠ 0) : + PureState S := + PureState.normalize (A.projPlus ψ.vec) hne + +@[simp] +theorem postMeasPlus_vec (A : Observable S) (ψ : PureState S) (hne : A.projPlus ψ.vec ≠ 0) : + (A.postMeasPlus ψ hne).vec = ((‖A.projPlus ψ.vec‖ : ℝ) : ℂ)⁻¹ • A.projPlus ψ.vec := rfl + +/-- **Postulate 4 / Exercise 2.61 (state update).** When the `±1` measurement of `A` on `|ψ⟩` yields +`+1`, the system collapses to the normalized state `P₊|ψ⟩ / ‖P₊|ψ⟩‖`: the post-measurement state is +`|ψ'⟩⟨ψ'|` for `|ψ'⟩ = postMeasPlus`. In terms of `Measurement.postMeasurement`. +Proof: `M₀ ρ M₀† = P₊|ψ⟩⟨ψ|P₊ = |P₊ψ⟩⟨P₊ψ|` (rank-one algebra, `adjoint P₊ = P₊`), and the +normalization `tr(·)⁻¹ = ‖P₊ψ‖⁻²` folds into the rank-one via sesquilinearity. -/ +theorem postMeasurement_signMeasurement_plus (A : Observable S) (hinv : A.op * A.op = 1) + (ψ : PureState S) (hne : A.projPlus ψ.vec ≠ 0) + (hp : (A.signMeasurement hinv).bornProb ψ.toState 0 ≠ 0) : + (A.signMeasurement hinv).postMeasurement ψ.toState 0 hp = (A.postMeasPlus ψ hne).toState := by + have htr : RCLike.re (LinearMap.trace ℂ S.space + ↑(ContinuousLinearMap.postOp (A.signMeasurement hinv).op ψ.toState.op 0)) + = ‖A.projPlus ψ.vec‖ ^ 2 := by + rw [postOp_signMeasurement_zero, InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq] + apply State.ext + rw [Measurement.postMeasurement_op, ContinuousLinearMap.postState, htr, + postOp_signMeasurement_zero, PureState.toState_op, postMeasPlus_vec, + InnerProductSpace.rankOne_smul_smul_self] + congr 1 + rw [map_inv₀, Complex.conj_ofReal] + push_cast + ring + +end Observable + +/-! ### The `±1` eigenvalue selected by a data bit -/ + +/-- **The `±1` eigenvalue selected by a bit `s`** under the sign-measurement convention: `+1` for +`s = 0`, `−1` for `s = 1` (i.e. `(-1)^s`). A protocol-neutral selector: in a qubit +key-distribution protocol the `s`-th data bit prepares the `signEigenvalue s`-eigenstate of a basis +observable, and `s` is the `Fin 2` index of the corresponding `Observable.signMeasurement` outcome +(`0 ↔ +1`, `1 ↔ −1`). Shared by the BB84 (Exercise 12.26) and six-state (Exercise 12.29) +protocols. -/ +def signEigenvalue : Fin 2 → ℝ := ![1, -1] + +@[simp] theorem signEigenvalue_zero : signEigenvalue 0 = 1 := rfl + +@[simp] theorem signEigenvalue_one : signEigenvalue 1 = -1 := rfl + +/-- `signEigenvalue s ≠ 0` (it is `±1`). The nonzero-eigenvalue side-condition consumed by the +anticommutation fair-coin rules (`Observable.bornProb_signMeasurement_*_of_anticomm_eigenstate`). -/ +theorem signEigenvalue_ne_zero (s : Fin 2) : signEigenvalue s ≠ 0 := by + fin_cases s <;> norm_num [signEigenvalue] + +/-! ### The Pauli vector observable on `|0⟩` -/ + +/-- **The expectation of `v · σ` in the state `|0⟩` is `v₃`** (`= n 2`): only the `Z` component of +`n · σ = n₀X + n₁Y + n₂Z` contributes on `|0⟩`, since `⟨0|X|0⟩ = ⟨0|Y|0⟩ = 0` and `⟨0|Z|0⟩ = 1`. +(`qubitKet0 = |0⟩` is the computational basis ket from `Postulates/API/Qubit.lean`.) -/ +theorem pauliObservable_expectation_qubitKet0 (n : Fin 3 → ℝ) : + qubitKet0.expectation (pauliObservable n) = n 2 := by + have happ : (pauliObservable n).op qubitKet0.vec + = WithLp.toLp 2 (Concrete.pauliDot n *ᵥ Concrete.ket 0) := by + rw [qubitKet0_vec, pauliObservable_op] + change Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.pauliDot n) + (WithLp.toLp 2 (Concrete.ket 0)) = _ + rw [Matrix.toEuclideanCLM_toLp] + rw [PureState.expectation, happ, qubitKet0_vec] + change (⟪(WithLp.toLp 2 (Concrete.ket 0) : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 (Concrete.pauliDot n *ᵥ Concrete.ket 0)⟫_ℂ).re = n 2 + rw [EuclideanSpace.inner_eq_star_dotProduct] + simp [Concrete.pauliDot_eq, Concrete.ket, dotProduct, Matrix.mulVec, Pi.single_apply] + +/-! ### The Pauli-`Z` eigenprojectors as computational rank-one projectors -/ + +/-- The `+1` eigenprojector of Pauli `Z` is `|0⟩⟨0|`: `(I + Z)/2 = |0⟩⟨0|`. -/ +theorem pauliZObservable_projPlus_rankOne : + pauliZObservable.projPlus = rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec := by + apply ContinuousLinearMap.coe_injective + apply Module.Basis.ext qubitModuleBasis + intro i + rw [qubitModuleBasis_apply] + simp only [ContinuousLinearMap.coe_coe, Observable.projPlus, _root_.smul_apply, + _root_.add_apply, one_apply_eq_self, + pauliZObservable_op_apply_qubitBasis, rankOne_apply, qubitBasis_inner_qubitBasis] + fin_cases i <;> + simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, pow_zero, pow_one, Fin.reduceEq, + ite_true, ite_false] + all_goals module + +/-- The `-1` eigenprojector of Pauli `Z` is `|1⟩⟨1|`: `(I - Z)/2 = |1⟩⟨1|`. -/ +theorem pauliZObservable_projMinus_rankOne : + pauliZObservable.projMinus = rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec := by + apply ContinuousLinearMap.coe_injective + apply Module.Basis.ext qubitModuleBasis + intro i + rw [qubitModuleBasis_apply] + simp only [ContinuousLinearMap.coe_coe, Observable.projMinus, _root_.smul_apply, + _root_.sub_apply, one_apply_eq_self, + pauliZObservable_op_apply_qubitBasis, rankOne_apply, qubitBasis_inner_qubitBasis] + fin_cases i <;> + simp only [Fin.isValue, Fin.zero_eta, Fin.mk_one, pow_zero, pow_one, Fin.reduceEq, + ite_true, ite_false] + all_goals module + +/-! ### The Pauli-`X` eigenprojectors as `|±⟩` rank-one projectors -/ + +/-- The `+1` eigenprojector of Pauli `X` is `|+⟩⟨+|`: `(I + X)/2 = |+⟩⟨+|`. The Hadamard-basis +counterpart of `pauliZObservable_projPlus_rankOne`; `|+⟩ = qubitPlus` is the `+1` eigenstate. -/ +theorem pauliXObservable_projPlus_rankOne : + pauliXObservable.projPlus = rankOne ℂ qubitPlus.vec qubitPlus.vec := by + apply ContinuousLinearMap.coe_injective + apply Module.Basis.ext qubitModuleBasis + intro i + rw [qubitModuleBasis_apply] + simp only [ContinuousLinearMap.coe_coe, Observable.projPlus, _root_.smul_apply, + _root_.add_apply, one_apply_eq_self, + pauliXObservable_op_apply_qubitBasis, rankOne_apply] + rw [← inner_conj_symm qubitPlus.vec (qubitBasis i).vec, inner_qubitBasis_qubitPlus, + Concrete.xPlus_apply, qubitPlus_vec_eq_smul_add, smul_smul] + have hc : (starRingEnd ℂ) Concrete.invSqrt2 * Concrete.invSqrt2 = 2⁻¹ := by + rw [starRingEnd_apply, Concrete.invSqrt2_star, Concrete.invSqrt2_mul_self] + rw [hc] + fin_cases i + · simp only [Fin.zero_eta, Fin.reduceAdd] + · simp only [Fin.mk_one, Fin.reduceAdd] + module + +/-- The `−1` eigenprojector of Pauli `X` is `|−⟩⟨−|`: `(I − X)/2 = |−⟩⟨−|`. The Hadamard-basis +counterpart of `pauliZObservable_projMinus_rankOne`; `|−⟩ = qubitMinus` is the `−1` eigenstate. -/ +theorem pauliXObservable_projMinus_rankOne : + pauliXObservable.projMinus = rankOne ℂ qubitMinus.vec qubitMinus.vec := by + apply ContinuousLinearMap.coe_injective + apply Module.Basis.ext qubitModuleBasis + intro i + rw [qubitModuleBasis_apply] + simp only [ContinuousLinearMap.coe_coe, Observable.projMinus, _root_.smul_apply, + _root_.sub_apply, one_apply_eq_self, + pauliXObservable_op_apply_qubitBasis, rankOne_apply] + rw [← inner_conj_symm qubitMinus.vec (qubitBasis i).vec, inner_qubitBasis_qubitMinus, + qubitMinus_vec_eq_smul_sub, smul_smul] + have hc : (starRingEnd ℂ) Concrete.invSqrt2 * Concrete.invSqrt2 = 2⁻¹ := by + rw [starRingEnd_apply, Concrete.invSqrt2_star, Concrete.invSqrt2_mul_self] + fin_cases i + · simp only [Concrete.xMinus, Fin.zero_eta, Matrix.cons_val_zero, hc, Fin.reduceAdd] + · simp only [Concrete.xMinus, Fin.mk_one, Matrix.cons_val_one, Matrix.cons_val_zero, + map_neg, neg_mul, hc, Fin.reduceAdd] + module + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliStringExpCircuit.lean b/LeanPool/AxQM/Postulates/API/PauliStringExpCircuit.lean new file mode 100644 index 0000000000..0bd2472ad3 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliStringExpCircuit.lean @@ -0,0 +1,239 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CnotFanEvolution +public import LeanPool.AxQM.Postulates.API.CollectorZRotationEvolution +public import LeanPool.AxQM.Postulates.API.PauliDiagWire +public import LeanPool.AxQM.Postulates.API.InvolutiveObservable +public import Mathlib.Analysis.Matrix.Normed + +/-! +# The Figure-4.19 circuit for a Trotter summand, and its faithfulness (N&C Problem 4.3(3)) + +Nielsen & Chuang **Problem 4.3(3)** asks to implement the Trotter summand `exp(-i h_g g Δ)` — the +unit-`ℏ` propagator `exp(-i c t · g)` of a single Pauli-string Hamiltonian `c · g` — with `O(n)` +one- and two-qubit gates. The construction is the compute–rotate–uncompute cascade of Figure +4.19 (N&C §4.7.3): + +1. a layer `B = ⨂ₖ B_{gₖ}` of single-qubit basis-change gates diagonalising each Pauli factor of `g` + to `Z` (`pauliDiagLayer`, `Postulates/API/PauliDiagWire`); +2. a fan `V` of `CNOT`s computing the support parity onto a collector wire `c` + (`cnotFanIntoEvolution`, `Postulates/API/CnotFanEvolution`), reversed as `V†`; +3. a single-qubit `z`-rotation `exp(-i c t · Z_c)` on the collector (`rotZWireEvolution`); +4. uncomputation `V` and `B†`. + +The preceding files of this sub-project built each piece as a register `Evolution` on `qudit (2ⁿ)`, +established its operator (`pauliDiagLayer_op`, `cnotFanIntoEvolution_op`, +`rotZWireEvolution_op_eq_exp_smul_zGenPauli`) and, for the `CircuitBudget`, its elementary-gate +count. This file **assembles** them and proves the assembly is *faithful*: the composite circuit's +operator is exactly the Trotter summand. + +## What is formalised + +* `pauliStringExpCircuit n g c ts θ` — the Figure-4.19 circuit `B · V† · R_z · V · B†` as one + `Evolution (qudit (2ⁿ))` (the `V†`/`B†` uncomputation are the `Evolution` adjoints of the fan and + the basis-change layer). Here `c` is the collector wire, `ts` the remaining support wires (so the + support of `g` is `insert c ts`), and `θ` the collector-rotation angle. + +* `pauliStringExpCircuit_op` — **the closed form**: for a Pauli string `g` whose support is exactly + `insert c ts` (`g c ≠ 0`, `g t ≠ 0` on `ts`, `g k = 0` off `insert c ts`), the circuit's operator + is the rotation `cos(θ/2) · 1 − (sin(θ/2) · i) · P_g`, where `P_g = Matrix.toEuclideanCLM + (pauliStringStd g)` is the Pauli-string operator (an involution). The Figure-4.19 cascade really + *is* the single-axis rotation about the Pauli string `g`, not merely some product of `O(n)` gates. + +* `pauliStringExpCircuit_op_eq_propagator` — **the faithfulness headline**: taking `θ = 2 c t`, the + circuit's operator equals the Trotter summand `((pauliStringHamiltonian g c).propagator 1 0 t).op + = exp(-i c t · g)`. So `pauliStringExpCircuit n g c ts (2 c t)` implements `exp(-i h_g g Δ)` for + `c = h_g`, `t = Δ` — the operator Problem 4.3(3) asks to realise. (The `O(n)` elementary-gate + `CircuitBudget` of this same assembly is `pauliStringExpCircuit_circuitBudget` + (`AxQM/Core/PauliStringExpCircuitBudget.lean`), folding the per-piece budgets + `pauliDiagLayer_circuitBudget`, `cnotFanIntoEvolution_circuitBudget`, + `rotZWireEvolution_circuitBudget` and their adjoints.) + +## Proof design + +The correctness composes the two matrix cores, kept entirely on the bit-string register +`Fin n → Fin 2` so the exponential never meets a `.submatrix`: + +* `Concrete.pauliString_exp_smul_conj_kronFamily_pauliDiagGate` (basis change): + `exp(s · g) = B · exp(s · d(g)) · B†`, `d(g) = pauliToZ ∘ g`; +* `Concrete.pauliString_exp_smul_conj_cnotFanInto` (Figure-4.19 parity): + `exp(s · d(g)) = V† · exp(s · Z_c) · V`. + +Composing gives the bit-string identity `B · V† · exp(s · Z_c) · V · B† = exp(s · g)`. The circuit's +operator is `Matrix.toEuclideanCLM` of exactly that five-fold product, each factor reindexed to the +flat register `Fin (2ⁿ)` by the `.submatrix finFunctionFinEquiv.symm` that the `_op` faithfulness +lemmas produce (the two adjoints `V†`/`B†` supply the conjugate transposes via +`Matrix.toEuclideanCLM_conjTranspose_eq_adjoint`); `Matrix.submatrix_mul_equiv` folds the product, +`map_mul` folds the `toEuclideanCLM`s, so the whole operator is +`toEuclideanCLM ((exp(s · g)).submatrix …)`. Finally `exp(s · g)` collapses to the rotation +`cos − i sin` because `pauliString g` is an involution +(`NormedSpace.exp_smul_mul_I_of_mul_self_eq_one`, `Concrete.pauliString_mul_self`), and that closed +form — being *linear* in `1` and `pauliString g` — reindexes and transports through `toEuclideanCLM` +without any `exp`/`submatrix` commutation. The collector-rotation scalar is `s = (−θ/2) i`, so +`θ = 2 c t` gives `s = -i c t`, matching the summand. +-/ + +@[expose] public section + +open Matrix +open scoped InnerProductSpace +-- The `L∞` operator norm supplies the `NormedRing`/`NormedAlgebra ℂ (Matrix …)` instances that +-- `NormedSpace.exp_smul_mul_I_of_mul_self_eq_one` needs to collapse the bit-string exponential to a +-- rotation; the resulting matrix `exp` is norm-independent (this only enables the lemma). +open scoped Matrix.Norms.Operator + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The Nielsen–Chuang Figure-4.19 circuit for a Pauli-string Trotter summand.** The +compute–rotate–uncompute cascade `B · V† · R_z(θ) · V · B†` implementing `exp(-i c t · g)` (for +`θ = 2 c t`), as one `Evolution (qudit (2ⁿ))`: + +* `B = pauliDiagLayer n g` — the layer of single-qubit basis-change gates diagonalising each Pauli + factor of `g` to `Z`; `B†` its adjoint; +* `V = cnotFanIntoEvolution n c ts` — the `CNOT` fan computing the support parity onto the collector + wire `c` (controls `ts`); `V†` its adjoint (the uncomputation); +* `R_z(θ) = rotZWireEvolution n c θ` — the single-qubit `z`-rotation on the collector. + +Reading the product right-to-left (the order gates act on a state): apply `B†`, then the parity fan +`V`, then the collector rotation, then uncompute the fan `V†`, then `B`. For a Pauli string whose +support is `insert c ts`, this realises `exp(-i c t · g)` (`pauliStringExpCircuit_op_eq_propagator`) +using `O(n)` elementary gates. -/ +def pauliStringExpCircuit (n : ℕ) (g : Fin n → Fin 4) (c : Fin n) (ts : List (Fin n)) (θ : ℝ) : + Evolution (qudit (2 ^ n)) := + pauliDiagLayer n g + * (cnotFanIntoEvolution n c ts).adjoint + * rotZWireEvolution n c θ + * cnotFanIntoEvolution n c ts + * (pauliDiagLayer n g).adjoint + +/-- **Problem 4.3(3): the Figure-4.19 circuit is a Pauli-string rotation.** For a Pauli string `g` +whose support is exactly `insert c ts` (`g c ≠ 0`, `g t ≠ 0` for `t ∈ ts`, and `g k = 0` for every +`k` off `insert c ts`; `ts` duplicate-free with `c ∉ ts`), the operator of the assembled cascade +`pauliStringExpCircuit n g c ts θ` is the single-axis rotation + +`toEuclideanCLM (cos(θ/2) · 1 − (sin(θ/2) · i) · pauliStringStd g)` + +about the Pauli string `g`. This is the **faithfulness** of the Figure-4.19 assembly: the composite +of the basis-change layer, the parity `CNOT` fan, the collector `z`-rotation and the two +uncomputations really computes the Pauli-string rotation, not merely some `O(n)`-gate circuit. + +The proof keeps the exponential on the bit-string register: the basis-change reduction +(`pauliString_exp_smul_conj_kronFamily_pauliDiagGate`) and the parity collapse +(`pauliString_exp_smul_conj_cnotFanInto`) compose to `B · V† · exp(s · Z_c) · V · B† = exp(s · g)` +(`s = (−θ/2) i`); the circuit operator is `toEuclideanCLM` of that five-fold product reindexed to +the register (`_op` faithfulness lemmas + `Matrix.submatrix_mul_equiv` + `map_mul`, the two adjoints +supplying the conjugate transposes via `Matrix.toEuclideanCLM_conjTranspose_eq_adjoint`); and +`exp(s · g)` collapses to the rotation because `pauliString g` is an involution +(`NormedSpace.exp_smul_mul_I_of_mul_self_eq_one`). -/ +theorem pauliStringExpCircuit_op {n : ℕ} (g : Fin n → Fin 4) (c : Fin n) (ts : List (Fin n)) + (hc : c ∉ ts) (hnd : ts.Nodup) (hgc : g c ≠ 0) (hgts : ∀ t ∈ ts, g t ≠ 0) + (hrest : ∀ k, k ≠ c → k ∉ ts → g k = 0) (θ : ℝ) : + (pauliStringExpCircuit n g c ts θ).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((Real.cos (θ / 2) : ℂ) • 1 + - ((Real.sin (θ / 2) : ℂ) * Complex.I) • Concrete.pauliStringStd g) := by + set s : ℂ := ((-(θ / 2) : ℝ) : ℂ) * Complex.I with hs + -- The `pauliToZ ∘ g` string is `Z` exactly on `insert c ts` (the support hypotheses on `g`). + have hac : Concrete.pauliToZ (g c) = 3 := Concrete.pauliToZ_eq_three_of_ne_zero _ hgc + have hats : ∀ t ∈ ts, Concrete.pauliToZ (g t) = 3 := fun t ht => + Concrete.pauliToZ_eq_three_of_ne_zero _ (hgts t ht) + have harest : ∀ k, k ≠ c → k ∉ ts → Concrete.pauliToZ (g k) = 0 := fun k h1 h2 => + Concrete.pauliToZ_eq_zero_iff.mpr (hrest k h1 h2) + -- The bit-string identity `B · V† · exp(s·Z_c) · V · B† = exp(s · g)` (five-fold, left-assoc). + have hMprime : + kronFamily (fun k => pauliDiagGate (g k)) * (cnotFanInto c ts).toMatrixᴴ + * NormedSpace.exp (s • Concrete.pauliString (Concrete.zGenPauli c)) + * (cnotFanInto c ts).toMatrix * (kronFamily (fun k => pauliDiagGate (g k)))ᴴ + = NormedSpace.exp (s • Concrete.pauliString g) := by + rw [Concrete.pauliString_exp_smul_conj_kronFamily_pauliDiagGate g s, + Concrete.pauliString_exp_smul_conj_cnotFanInto c ts hc hnd (fun k => Concrete.pauliToZ (g k)) + hac hats harest s] + simp only [mul_assoc] + -- The five-fold Std product on `Fin (2ⁿ)` folds (via `submatrix_mul_equiv`) to the reindexed + -- bit-string exponential. + have hStd : + kronFamilyStd (fun k => pauliDiagGate (g k)) + * ((cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm)ᴴ + * (NormedSpace.exp (s • Concrete.pauliString (Concrete.zGenPauli c))).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm + * (cnotFanInto c ts).toMatrix.submatrix finFunctionFinEquiv.symm finFunctionFinEquiv.symm + * (kronFamilyStd (fun k => pauliDiagGate (g k)))ᴴ + = (NormedSpace.exp (s • Concrete.pauliString g)).submatrix finFunctionFinEquiv.symm + finFunctionFinEquiv.symm := by + simp only [kronFamilyStd, Matrix.conjTranspose_submatrix, Matrix.submatrix_mul_equiv] + rw [hMprime] + -- The circuit operator as `toEuclideanCLM` of the reindexed bit-string exponential. The two + -- uncomputation adjoints `V†`, `B†` are the citable adjoint companions + -- `cnotFanIntoEvolution_adjoint_op` / `pauliDiagLayer_adjoint_op` of the forward `_op` lemmas. + have hcircop : (pauliStringExpCircuit n g c ts θ).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + ((NormedSpace.exp (s • Concrete.pauliString g)).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm) := by + rw [← hStd, map_mul, map_mul, map_mul, map_mul, pauliStringExpCircuit] + simp only [Evolution.mul_def, Evolution.comp_op, cnotFanIntoEvolution_adjoint_op, + pauliDiagLayer_adjoint_op, pauliDiagLayer_op, cnotFanIntoEvolution_op, + rotZWireEvolution_op_eq_exp_smul_zGenPauli, ← hs, ContinuousLinearMap.mul_def] + rfl + rw [hcircop] + congr 1 + -- The bit-string exponential collapses to the rotation `cos − i sin` (`pauliString g` is an + -- involution), and reindexing the linear combination commutes with `submatrix` (`reindexAlgEquiv` + -- is a ⋆-algebra iso, so `map_add`/`map_smul`/`map_one` distribute over the rotation). + have hexp : NormedSpace.exp (s • Concrete.pauliString g) + = (Real.cos (-(θ / 2)) : ℂ) • (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + + ((Real.sin (-(θ / 2)) : ℂ) * Complex.I) • Concrete.pauliString g := by + rw [hs] + exact NormedSpace.exp_smul_mul_I_of_mul_self_eq_one (Concrete.pauliString_mul_self g) (-(θ / 2)) + rw [hexp, + show ((Real.cos (-(θ / 2)) : ℂ) • (1 : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ) + + ((Real.sin (-(θ / 2)) : ℂ) * Complex.I) • Concrete.pauliString g).submatrix + finFunctionFinEquiv.symm finFunctionFinEquiv.symm + = Matrix.reindexAlgEquiv ℂ ℂ finFunctionFinEquiv + ((Real.cos (-(θ / 2)) : ℂ) • 1 + + ((Real.sin (-(θ / 2)) : ℂ) * Complex.I) • Concrete.pauliString g) from rfl, + map_add, map_smul, map_smul, map_one, Real.cos_neg, Real.sin_neg, Complex.ofReal_neg, neg_mul, + neg_smul, ← sub_eq_add_neg] + rfl + +/-- **Problem 4.3(3) faithfulness headline: the Figure-4.19 circuit implements `exp(-i h_g g Δ)`.** +For a Pauli string `g` whose support is exactly `insert c ts`, the assembled cascade +`pauliStringExpCircuit n g c ts (2 c t)` (basis change, parity `CNOT` fan, collector `z`-rotation at +angle `θ = 2 c t`, and the two uncomputations) has operator equal to the Trotter summand — the +unit-`ℏ` propagator of the Pauli-string Hamiltonian `c · g`: + +`(pauliStringExpCircuit n g c ts (2 c t)).op = ((pauliStringHamiltonian g c).propagator 1 0 t).op`, + +i.e. `exp(-i c t · g)`. So the circuit realises the operator `exp(-i h_g g Δ)` of Problem 4.3(3) for +`c = h_g`, `t = Δ = 1/k`. The proof puts both sides in the common closed form +`toEuclideanCLM (cos(c t) · 1 − (sin(c t) · i) · pauliStringStd g)`: the circuit side is +`pauliStringExpCircuit_op` (with `θ/2 = c t`), and the summand side is the involution rotation law +`pauliStringHamiltonian_propagator_op` transported through `toEuclideanCLM` +(`pauliStringHamiltonian_op`, `map_one`/`map_smul`/`map_sub`). The `O(n)` elementary-gate +`CircuitBudget` of the same `pauliStringExpCircuit` is `pauliStringExpCircuit_circuitBudget`. -/ +theorem pauliStringExpCircuit_op_eq_propagator {n : ℕ} (g : Fin n → Fin 4) (c : Fin n) + (ts : List (Fin n)) (hc : c ∉ ts) (hnd : ts.Nodup) (hgc : g c ≠ 0) (hgts : ∀ t ∈ ts, g t ≠ 0) + (hrest : ∀ k, k ≠ c → k ∉ ts → g k = 0) (coeff t : ℝ) : + (pauliStringExpCircuit n g c ts (2 * coeff * t)).op + = ((pauliStringHamiltonian g coeff).propagator 1 0 t).op := by + have hθ : (2 * coeff * t) / 2 = coeff * t := by ring + rw [pauliStringExpCircuit_op g c ts hc hnd hgc hgts hrest, hθ, + pauliStringHamiltonian_propagator_op, pauliStringHamiltonian_op g 1, Complex.ofReal_one, + one_smul, map_sub, map_smul, map_smul, map_one] + rfl + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliTomographyExpectation.lean b/LeanPool/AxQM/Postulates/API/PauliTomographyExpectation.lean new file mode 100644 index 0000000000..76b10f279f --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliTomographyExpectation.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTrotter +public import LeanPool.AxQM.Concrete.PauliTomography +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.MatrixToEuclideanCLM + +/-! +# AxQM.Postulates.API — the Pauli density matrix of a state and the tomographic bridge + +The bridge turning a `State ρ` on the `n`-qubit register `qudit (2ⁿ)` into the +`Matrix (Fin n → Fin 2)`-indexed density matrix on which the Concrete Pauli-trace reconstruction +backbone (`AxQM/Concrete/PauliTomography.lean`) acts, and connecting the postulate expectation value +`State.expectation ρ (pauliStringHamiltonian g 1) = ⟨P_g⟩_ρ` to the trace pairing `tr(P_g ρ)` of +Nielsen & Chuang eq. (7.168). This is the physics half of *state tomography* (§7.7.4, Ex 7.45): +it lets "the state is reconstructed from its Pauli expectation values" be stated for +states, observables and expectation values while being proved by the matrix mathematics. + +## What this file provides + +* `State.pauliMatrix` — the density matrix `toEuclideanCLM⁻¹ ρ.op` of a state, in the computational + basis, reindexed from `Fin (2ⁿ)` to bit strings `Fin n → Fin 2` along `finFunctionFinEquiv`. +* `State.pauliMatrix_isHermitian` — it is Hermitian (the density operator is self-adjoint). +* `State.trace_pauliMatrix` — its trace is `1` (a density operator has unit trace). +* `State.expectation_pauliStringHamiltonian` — **the (7.168) bridge**: the postulate expectation + `ρ.expectation (pauliStringHamiltonian g 1)` equals the real part of the Pauli trace pairing + `tr(P_g · ρ.pauliMatrix)` — `⟨P_g⟩_ρ = tr(ρ P_g)`. +* `State.eq_of_pauliMatrix_eq` — a state is determined by its Pauli density matrix (`toEuclideanCLM` + and the reindexing are injective), the bridge from a matrix identity back to a state identity. + +## Design + +* **Reconstruction.** The reconstruction principle built on this bridge, + `(∀ g ≠ 0, ⟨P_g⟩_ρ = ⟨P_g⟩_σ) → ρ = σ`, is in `AxQM/Core/PauliTomographyExpectation.lean`. +* **Bridge mechanism.** `Matrix.toEuclideanCLM : Matrix (Fin (2ⁿ)) (Fin (2ⁿ)) ℂ ≃⋆ₐ[ℂ] …` is the + `⋆`-algebra isomorphism identifying matrices with operators in the computational basis (the same + one `pauliStringHamiltonian` is built from). Under it, operator composition is matrix product + (`map_mul`), the operator trace is the matrix trace (`Matrix.trace_toEuclideanCLM`), and the + adjoint is conjugate transpose (`map_star`), so `State.expectation = Re Tr(ρ A)` is + matrix pairing `Re tr(P_g ρ)`. The register indexing `Fin (2ⁿ)` is reindexed to bit strings + `Fin n → Fin 2` (the index type of `Concrete.pauliString`) via `finFunctionFinEquiv`, matching the + reindexing already used by `pauliStringStd` / `Observable.stdMatrix`. +-/ + +@[expose] public section + +open Matrix + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- Reindexing a `Fin (2ⁿ)`-indexed matrix to bit strings `Fin n → Fin 2` along the bijection +`finFunctionFinEquiv` preserves the trace (a bijective relabelling of the diagonal sum). -/ +private theorem trace_submatrix_finFunctionFinEquiv + (A : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ) : + (A.submatrix finFunctionFinEquiv finFunctionFinEquiv).trace = A.trace := by + simp only [Matrix.trace, Matrix.diag_apply, Matrix.submatrix_apply] + exact Equiv.sum_comp finFunctionFinEquiv fun i => A i i + +/-- The **Pauli density matrix** of a state `ρ` on the `n`-qubit register `qudit (2ⁿ)`: the matrix +`toEuclideanCLM⁻¹ ρ.op` of the density operator in the computational basis, reindexed from +`Fin (2ⁿ)` to bit strings `Fin n → Fin 2` along `finFunctionFinEquiv`. This is the concrete matrix +on which the Pauli-trace reconstruction backbone (`Concrete.eq_of_trace_eq_of_trace_pauliString_eq`) +acts; `State.expectation_pauliStringHamiltonian` shows its Pauli trace pairings are the +expectations `⟨P_g⟩_ρ`. -/ +def State.pauliMatrix (ρ : State (qudit (2 ^ n))) : + Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ := + ((Matrix.toEuclideanCLM (𝕜 := ℂ)).symm ρ.op).submatrix finFunctionFinEquiv finFunctionFinEquiv + +/-- The Pauli density matrix of a state is **Hermitian**, because the density operator `ρ.op` is +self-adjoint (positive), the `⋆`-algebra isomorphism `toEuclideanCLM⁻¹` sends self-adjoint operators +to Hermitian matrices, and reindexing by `finFunctionFinEquiv` preserves Hermitianness. -/ +theorem State.pauliMatrix_isHermitian (ρ : State (qudit (2 ^ n))) : + ρ.pauliMatrix.IsHermitian := + (Matrix.isHermitian_iff_isSelfAdjoint.mpr + (ρ.isPositive_op.isSelfAdjoint.map (Matrix.toEuclideanCLM (𝕜 := ℂ)).symm)).submatrix + finFunctionFinEquiv + +/-- The Pauli density matrix of a state has **unit trace** (`tr ρ = 1`): the reindexing preserves +the trace, and the matrix trace of `toEuclideanCLM⁻¹ ρ.op` is the operator trace of `ρ.op`, which is +`1` +for a density operator (`State.trace_op_eq_one`). -/ +theorem State.trace_pauliMatrix (ρ : State (qudit (2 ^ n))) : ρ.pauliMatrix.trace = 1 := by + -- `qudit (2 ^ n) := QSystem.ofModel (EuclideanSpace ℂ (Fin (2 ^ n)))`, so `ρ.op`'s bundled + -- `(qudit _).space` instances and `toEuclideanCLM.symm`'s bare `EuclideanSpace` ones diverge + -- under `rw`'s syntactic matching even though defeq; `erw` bridges it. + erw [State.pauliMatrix, trace_submatrix_finFunctionFinEquiv, + ← Matrix.trace_toEuclideanCLM, StarAlgEquiv.apply_symm_apply] + exact ρ.trace_op_eq_one + +/-- **The (7.168) tomography bridge.** The postulate expectation value of the Pauli-string +observable `P_g = pauliStringHamiltonian g 1` in a state `ρ` is the real part of the Pauli trace +pairing: `⟨P_g⟩_ρ = Re tr(P_g · ρ)`, over the Pauli density matrix `ρ.pauliMatrix`. This is Nielsen +& Chuang's `rₖ = ⟨σₖ⟩ = tr(ρ σₖ)` (eq. 7.168), lifted to the `n`-qubit Pauli strings and grounded in +`State.expectation`. Proof: unfold `expectation` to `Re Tr(ρ.op ∘ P_g.op)`, replace `P_g.op` by +`toEuclideanCLM (pauliStringStd g)` and `ρ.op` by `toEuclideanCLM (toEuclideanCLM⁻¹ ρ.op)`; the +isomorphism turns the composite into `toEuclideanCLM (M_ρ * pauliStringStd g)` whose operator trace +is the matrix trace, which reindexes (cyclically) to `tr(pauliString g · ρ.pauliMatrix)`. -/ +theorem State.expectation_pauliStringHamiltonian (ρ : State (qudit (2 ^ n))) + (g : Fin n → Fin 4) : + ρ.expectation (pauliStringHamiltonian g 1) + = ((Concrete.pauliString g * ρ.pauliMatrix).trace).re := by + set M := (Matrix.toEuclideanCLM (𝕜 := ℂ)).symm ρ.op with hM + have hρop : ρ.op = Matrix.toEuclideanCLM (𝕜 := ℂ) M := + (StarAlgEquiv.apply_symm_apply _ _).symm + -- `Tr(ρ.op ∘ P_g.op)` as the matrix trace `tr(M * pauliStringStd g)`. + have hcomp : (LinearMap.trace ℂ (qudit (2 ^ n)).space) + ↑(ρ.op.comp (pauliStringHamiltonian g 1).op) + = (M * Concrete.pauliStringStd g).trace := by + have hopcomp : ρ.op.comp (pauliStringHamiltonian g 1).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (M * Concrete.pauliStringStd g) := by + rw [pauliStringHamiltonian_op, Complex.ofReal_one, one_smul, hρop, map_mul] + rfl + rw [hopcomp] + exact Matrix.trace_toEuclideanCLM _ + -- `(pauliStringStd g).submatrix e e = pauliString g` (the reindexings cancel). + have hpss : (Concrete.pauliStringStd g).submatrix finFunctionFinEquiv finFunctionFinEquiv + = Concrete.pauliString g := by + rw [Concrete.pauliStringStd, Matrix.submatrix_submatrix, Equiv.symm_comp_self, + Matrix.submatrix_id_id] + -- The matrix trace reindexes to the bit-string pairing `tr(pauliString g * ρ.pauliMatrix)`. + have hreindex : (M * Concrete.pauliStringStd g).trace + = (Concrete.pauliString g * ρ.pauliMatrix).trace := by + rw [Matrix.trace_mul_comm, + ← trace_submatrix_finFunctionFinEquiv (Concrete.pauliStringStd g * M), + ← Matrix.submatrix_mul_equiv (Concrete.pauliStringStd g) M finFunctionFinEquiv + finFunctionFinEquiv finFunctionFinEquiv, hpss, State.pauliMatrix, ← hM] + have hexp : ρ.expectation (pauliStringHamiltonian g 1) + = ((LinearMap.trace ℂ (qudit (2 ^ n)).space) + ↑(ρ.op.comp (pauliStringHamiltonian g 1).op)).re := rfl + rw [hexp, hcomp, hreindex] + +/-- A state on the `n`-qubit register is **determined by its Pauli density matrix**: if +`ρ.pauliMatrix = σ.pauliMatrix` then `ρ = σ`. Both `toEuclideanCLM` and the reindexing by the +bijection `finFunctionFinEquiv` are injective, so the density operators — hence the states +(`State.ext`) — coincide. This bridges a matrix reconstruction back to a state identity. -/ +theorem State.eq_of_pauliMatrix_eq {ρ σ : State (qudit (2 ^ n))} + (h : ρ.pauliMatrix = σ.pauliMatrix) : ρ = σ := by + apply State.ext + have hM : (Matrix.toEuclideanCLM (𝕜 := ℂ)).symm ρ.op + = (Matrix.toEuclideanCLM (𝕜 := ℂ)).symm σ.op := by + have hsub := congrArg + (fun X : Matrix (Fin n → Fin 2) (Fin n → Fin 2) ℂ => + X.submatrix finFunctionFinEquiv.symm finFunctionFinEquiv.symm) h + simpa only [State.pauliMatrix, Matrix.submatrix_submatrix, Equiv.self_comp_symm, + Matrix.submatrix_id_id] using hsub + exact (Matrix.toEuclideanCLM (𝕜 := ℂ)).symm.injective hM + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliTrotter.lean b/LeanPool/AxQM/Postulates/API/PauliTrotter.lean new file mode 100644 index 0000000000..346c3f0760 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliTrotter.lean @@ -0,0 +1,244 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliExpansion +public import LeanPool.AxQM.Postulates.API.TrotterProduct +public import LeanPool.AxQM.Postulates.API.HamiltonianGenerator +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix + +/-! +# AxQM.Postulates.API — the literal Pauli-string Trotter approximation (N&C Problem 4.3) + +This file joins the two independent halves of Nielsen & Chuang, Problem 4.3 that had been +formalised separately — the **Pauli expansion** of the generator (part (2)) and the **Trotter +product formula** for propagators (parts (4)/(5)) — into N&C's *literal* statement, in which the +approximating product runs over the `4ⁿ` Pauli strings: + +* **(4)** `exp(-i H Δ) = ∏_g exp(-i h_g g Δ) + O(Δ²)`; +* **(5)** `U = [∏_g exp(-i h_g g Δ)]ᵏ + O(1/k)` for `Δ = 1/k`. + +Here `H = Σ_g h_g g` is the Pauli expansion of a Hamiltonian on the `n`-qubit register +`qudit (2ⁿ)`, `g` ranges over the Pauli strings `Fin n → Fin 4` (a choice of `{I, X, Y, Z}` per +qubit), and each `exp(-i h_g g Δ)` is the propagator of the Pauli-string Hamiltonian `h_g · g`. + +The general Trotter bounds in `Postulates/API/TrotterProduct.lean` +(`Observable.exists_norm_prod_propagator_op_sub_propagator_op_le` and its `k`-fold power version) +already prove (4)/(5) for an *arbitrary* ordered decomposition `H = Σᵢ Hᵢ` of a Hamiltonian into +Hamiltonians. This file supplies the missing specialisation — the operator↔matrix transport that +turns N&C's `H = Σ_g h_g g` into such a decomposition — so those bounds fire on the literal +Pauli-string list. + +## What this file provides + +* `Observable.toEuclideanCLM_stdMatrix` — the **reverse bridge**: `Matrix.toEuclideanCLM H.stdMatrix + = H.op`. It recovers an observable's operator from its computational-basis matrix + (`Observable.stdMatrix`, the forward bridge of `PauliExpansion.lean`), by the round trip + `toLin ∘ toMatrix = id` in an orthonormal basis. This is the operator↔matrix + transport described above. +* `pauliStringHamiltonian g c` — the **Pauli-string Hamiltonian** `c · g` on `qudit (2ⁿ)`: the + real-scaled Pauli string `Concrete.pauliStringStd g` promoted to a self-adjoint operator through + `Matrix.toEuclideanCLM` (self-adjoint because the string is Hermitian and `c` is real). Its + propagator `(pauliStringHamiltonian g (h g)).propagator 1 0 Δ` is exactly N&C's + `exp(-i h_g g Δ)`. +* `Observable.op_eq_sum_pauliStringHamiltonian` — **part (2), operator form**: every Hamiltonian on + the `n`-qubit register is the sum `H.op = Σ_g (pauliStringHamiltonian g (h g)).op` of its + Pauli-string Hamiltonians, for real `h_g`. This is exactly the ordered decomposition the Trotter + bounds consume. +* `Observable.exists_norm_prod_pauliStringHamiltonian_propagator_sub_le` — **part (4)**, literal + form: `‖(∏_g exp(-i h_g g Δ)) - exp(-i H Δ)‖ ≤ C·Δ²`. +* `Observable.exists_norm_prod_pauliStringHamiltonian_propagator_pow_sub_le` — **part (5)**, literal + form: `‖(∏_g exp(-i h_g g /k))ᵏ - exp(-i H)‖ ≤ C/k`. +* `Evolution.exists_pauliString_trotter_approximation` — the conclusion of Problem 4.3: *every* + `n`-qubit unitary `U` is approximated to `O(1/k)` by the `k`-fold Pauli–Trotter product + `[∏_g exp(-i h_g g /k)]ᵏ`. Combining parts (1) (`U = exp(-iH)` for a Hermitian `H`), (2) + (`H = Σ_g h_g g`) and (5). + +## Design notes + +* **What is new versus the general bounds.** N&C's parts (4)/(5) are already captured, more + generally, by the arbitrary-decomposition bounds in `TrotterProduct.lean`; the physics content + (Trotterising a Hamiltonian sum) is identical. What is proved here in addition + is that N&C's *specific* decomposition into Pauli strings *is* such a sum, i.e. the transport of + the matrix-level Pauli expansion (`Observable.exists_real_pauliString_expansion`) into an equality + of operators `H.op = Σ_g (h_g · g).op`. The `4ⁿ` term count of N&C's `O(4ⁿ Δ²)`/`O(4ⁿ Δ)` is + absorbed into the constant `C`, as in the general bounds. +* **The ordering.** N&C fix "any ordering" of the Pauli strings; here the ordering is + `Finset.univ.toList` over `Fin n → Fin 4` (all `4ⁿ` strings). The bound holds for that fixed + ordering — the physical content is order-independent (the constant `C` may depend on it). +* **The register↔matrix transport.** An observable's operator lives on `EuclideanSpace ℂ (Fin 2ⁿ)`, + its `stdMatrix` on `Fin 2ⁿ`, and the Pauli-string mathematics on bit strings `Fin n → Fin 2`. + `Observable.toEuclideanCLM_stdMatrix` bridges operator↔matrix; `Concrete.pauliStringStd` bridges + the bit-string Pauli string to the flat `Fin 2ⁿ` indexing. The star-algebra isomorphism + `Matrix.toEuclideanCLM` is `ℂ`-linear and multiplicative, so it carries the matrix sum + `H.stdMatrix = Σ_g h_g · (pauli string)` to the operator sum verbatim. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open Matrix + +noncomputable section + +namespace AxQM + +variable {d n : ℕ} + +/-- The **reverse computational-basis bridge**: the `Matrix.toEuclideanCLM` image of an observable's +computational-basis matrix recovers its operator, `Matrix.toEuclideanCLM H.stdMatrix = H.op`. This +is the inverse of `Observable.stdMatrix` (the forward operator→matrix bridge of `PauliExpansion`): +`stdMatrix` is `toMatrixOrthonormal` in the orthonormal computational basis and `toEuclideanCLM` +coerces to `toEuclideanLin = toLin` in the same basis, so the two compose to the identity +(`Matrix.toLin_toMatrix`). It is the transport that lets a matrix-level identity about `H.stdMatrix` +be pushed to an operator identity about `H.op`. -/ +theorem Observable.toEuclideanCLM_stdMatrix (H : Observable (qudit d)) : + Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) H.stdMatrix = H.op := by + apply ContinuousLinearMap.coe_injective + rw [Matrix.coe_toEuclideanCLM_eq_toEuclideanLin, Matrix.toEuclideanLin_eq_toLin_orthonormal, + Observable.stdMatrix] + exact Matrix.toLin_toMatrix _ _ _ + +/-- The **Pauli-string Hamiltonian** `c · g` on the `n`-qubit register `qudit (2ⁿ)`, for a Pauli +string `g : Fin n → Fin 4` and a real coefficient `c`. Its operator is the Hermitian matrix +`c • Concrete.pauliStringStd g` (the standard-indexed Pauli string scaled by `c`) promoted to a +continuous linear map through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; it is +self-adjoint because the Pauli string is Hermitian and `c` is real (so `(c : ℂ)` is self-adjoint), +and that isomorphism preserves `star`. These are the summands `h_g · g` of the Pauli expansion of a +Hamiltonian, whose ordered propagator product is Trotterised in Nielsen & Chuang, +Problem 4.3(4)/(5). -/ +def pauliStringHamiltonian (g : Fin n → Fin 4) (c : ℝ) : Observable (qudit (2 ^ n)) where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) ((c : ℂ) • Concrete.pauliStringStd g) + selfAdjoint := by + have hc : IsSelfAdjoint (c : ℂ) := (Complex.im_eq_zero_iff_isSelfAdjoint ↑c).mp rfl + exact (hc.smul (Concrete.pauliStringStd_isHermitian g).isSelfAdjoint).map + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n))) + +/-- The operator of the Pauli-string Hamiltonian `c · g` is `c` times the operator of the Pauli +string: `(pauliStringHamiltonian g c).op = c • Matrix.toEuclideanCLM (Concrete.pauliStringStd g)`. +Immediate from the definition and the `ℂ`-linearity of `Matrix.toEuclideanCLM` (`map_smul`). -/ +theorem pauliStringHamiltonian_op (g : Fin n → Fin 4) (c : ℝ) : + (pauliStringHamiltonian g c).op + = (c : ℂ) • Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) + (Concrete.pauliStringStd g) := + map_smul _ _ _ + +/-- **Nielsen & Chuang, Problem 4.3(2), operator form with an explicit coefficient function.** From +a *fixed* real Pauli expansion `H.stdMatrix.submatrix _ _ = ∑_g (h_g : ℂ) • pauliString g` of a +Hamiltonian on the `n`-qubit register, its operator decomposes as the ordered sum of its +Pauli-string Hamiltonians, `H.op = Σ_g (pauliStringHamiltonian g (h g)).op`. This is the +form of `Observable.op_eq_sum_pauliStringHamiltonian`, with the coefficient function `h` and the +expansion `hexp` taken as explicit inputs rather than existentially bound — the form needed +when the *same* `h` is used in two places (e.g. the total Pauli weight +`∑_g |h_g|` of `AxQM/Postulates/API/PauliCoefficientOpNorm.lean`). The proof reindexes the +bit-string Pauli expansion to the flat `Fin (2ⁿ)` register, then transports the matrix identity +through the reverse bridge `Observable.toEuclideanCLM_stdMatrix` and the `ℂ`-linearity of +`Matrix.toEuclideanCLM`. -/ +theorem Observable.op_eq_sum_pauliStringHamiltonian_of_expansion (H : Observable (qudit (2 ^ n))) + {h : (Fin n → Fin 4) → ℝ} + (hexp : H.stdMatrix.submatrix ⇑finFunctionFinEquiv ⇑finFunctionFinEquiv + = ∑ g, (h g : ℂ) • Concrete.pauliString g) : + H.op = ((Finset.univ.toList.map fun g => pauliStringHamiltonian g (h g)).map + Observable.op).sum := by + -- Reindex the bit-string Pauli expansion to the flat `Fin (2ⁿ)` register indexing. + have hstd : H.stdMatrix = ∑ g, (h g : ℂ) • Concrete.pauliStringStd g := by + ext I J + have hIJ := congr_fun₂ hexp (finFunctionFinEquiv.symm I) (finFunctionFinEquiv.symm J) + simpa [Concrete.pauliStringStd, Matrix.submatrix_apply, Matrix.sum_apply, Matrix.smul_apply, + Equiv.apply_symm_apply] using hIJ + -- The list sum over `Finset.univ.toList` is the Finset sum over all Pauli strings. + have hlist : ((Finset.univ.toList.map fun g => pauliStringHamiltonian g (h g)).map + Observable.op).sum = ∑ g, (pauliStringHamiltonian g (h g)).op := by + rw [List.map_map, Finset.sum_map_toList]; rfl + -- Push the matrix identity through `toEuclideanCLM` (linear) to an operator identity. + rw [hlist, ← Observable.toEuclideanCLM_stdMatrix H, hstd, map_sum] + exact Finset.sum_congr rfl fun g _ => by rw [map_smul, pauliStringHamiltonian_op] + +/-- **Nielsen & Chuang, Problem 4.3(2), operator form: the Pauli-string decomposition of a +Hamiltonian.** Every Hamiltonian `H : Observable (qudit (2ⁿ))` on the `n`-qubit register is the sum +of its Pauli-string Hamiltonians `h_g · g` with real `h_g`: +`H.op = Σ_g (pauliStringHamiltonian g (h g)).op`, the sum over all `4ⁿ` Pauli strings +`g : Fin n → Fin 4` (written as the list `Finset.univ.toList`). This is the ordered Hamiltonian +decomposition `H = Σᵢ Hᵢ` that the Trotter bounds +(`Observable.exists_norm_prod_propagator_op_sub_propagator_op_le`) consume; it is the +existentially-bound corollary of `Observable.op_eq_sum_pauliStringHamiltonian_of_expansion` applied +to the real Pauli expansion `Observable.exists_real_pauliString_expansion`. -/ +theorem Observable.op_eq_sum_pauliStringHamiltonian (H : Observable (qudit (2 ^ n))) : + ∃ h : (Fin n → Fin 4) → ℝ, + H.op = ((Finset.univ.toList.map fun g => pauliStringHamiltonian g (h g)).map + Observable.op).sum := by + obtain ⟨h, hexp⟩ := H.exists_real_pauliString_expansion + exact ⟨h, H.op_eq_sum_pauliStringHamiltonian_of_expansion hexp⟩ + +/-- **Nielsen & Chuang, Problem 4.3(4): first-order Trotter error, literal Pauli-string form.** +For a Hamiltonian `H` on the `n`-qubit register, splitting its propagator `exp(-i H Δ)` into ordered +product `∏_g exp(-i h_g g Δ)` over the `4ⁿ` Pauli-string propagators incurs only a second-order +error: there are real coefficients `h_g` and a constant `C ≥ 0` with +`‖(∏_g exp(-i h_g g Δ)) - exp(-i H Δ)‖ ≤ C·Δ²` for every `Δ ∈ [0, 1]`. The specialisation of the +general Hamiltonian-sum bound `Observable.exists_norm_prod_propagator_op_sub_propagator_op_le` to +the Pauli-string decomposition `Observable.op_eq_sum_pauliStringHamiltonian`. -/ +theorem Observable.exists_norm_prod_pauliStringHamiltonian_propagator_sub_le + (H : Observable (qudit (2 ^ n))) : + ∃ (h : (Fin n → Fin 4) → ℝ) (C : ℝ), 0 ≤ C ∧ ∀ Δ : ℝ, 0 ≤ Δ → Δ ≤ 1 → + ‖(Finset.univ.toList.map fun g => + ((pauliStringHamiltonian g (h g)).propagator 1 0 Δ).op).prod + - (H.propagator 1 0 Δ).op‖ ≤ C * Δ ^ 2 := by + obtain ⟨h, hH⟩ := H.op_eq_sum_pauliStringHamiltonian + obtain ⟨C, hC0, hC⟩ := H.exists_norm_prod_propagator_op_sub_propagator_op_le + (Finset.univ.toList.map fun g => pauliStringHamiltonian g (h g)) hH + refine ⟨h, C, hC0, fun Δ hΔ0 hΔ1 => ?_⟩ + have hΔ := hC Δ hΔ0 hΔ1 + rwa [List.map_map] at hΔ + +/-- **Nielsen & Chuang, Problem 4.3(5): accumulated Trotter error, literal Pauli-string form.** +For a Hamiltonian `H` on the `n`-qubit register, `k` iterations of the ordered Pauli-string +product at step `Δ = 1/k` converge to the full propagator `exp(-i H)` at first order: there are real +coefficients `h_g` and a constant `C ≥ 0` with +`‖(∏_g exp(-i h_g g /k))ᵏ - exp(-i H)‖ ≤ C/k` for every `k ≥ 1`. The specialisation of the general +`k`-fold bound `Observable.exists_norm_prod_propagator_op_pow_sub_propagator_op_le` to the +Pauli-string decomposition. -/ +theorem Observable.exists_norm_prod_pauliStringHamiltonian_propagator_pow_sub_le + (H : Observable (qudit (2 ^ n))) : + ∃ (h : (Fin n → Fin 4) → ℝ) (C : ℝ), 0 ≤ C ∧ ∀ k : ℕ, 1 ≤ k → + ‖(Finset.univ.toList.map fun g => + ((pauliStringHamiltonian g (h g)).propagator 1 0 (k : ℝ)⁻¹).op).prod ^ k + - (H.propagator 1 0 1).op‖ ≤ C * (k : ℝ)⁻¹ := by + obtain ⟨h, hH⟩ := H.op_eq_sum_pauliStringHamiltonian + obtain ⟨C, hC0, hC⟩ := H.exists_norm_prod_propagator_op_pow_sub_propagator_op_le + (Finset.univ.toList.map fun g => pauliStringHamiltonian g (h g)) hH + refine ⟨h, C, hC0, fun k hk => ?_⟩ + have hk' := hC k hk + rwa [List.map_map] at hk' + +/-- **Nielsen & Chuang, Problem 4.3, the conclusion: universal Pauli–Trotter +approximation.** *Every* unitary `U` on the `n`-qubit register `qudit (2ⁿ)` is approximated, to +`O(1/k)`, by the `k`-fold product of Pauli-string propagators: there are real coefficients `h_g` and +a constant `C ≥ 0` with `‖(∏_g exp(-i h_g g /k))ᵏ - U‖ ≤ C/k` for every `k ≥ 1`. + +This is the whole point of Problem 4.3, assembled from its parts: `U = exp(-iH)` for a Hermitian `H` +(part (1), `Evolution.exists_hamiltonian_generator_spectrum_Icc`); `H = Σ_g h_g g` decomposes into +Pauli strings (part (2), `Observable.op_eq_sum_pauliStringHamiltonian`); and the `k`-fold product of +the component propagators converges to `exp(-iH) = U` (part (5), +`Observable.exists_norm_prod_pauliStringHamiltonian_propagator_pow_sub_le`). Since each +`exp(-i h_g g /k)` is implementable in `O(n)` one- and two-qubit gates (part (3)), +this exhibits `U` as approximable by a circuit of `O(n · 4ⁿ · k)` such gates — N&C's universality +construction. -/ +theorem Evolution.exists_pauliString_trotter_approximation (U : Evolution (qudit (2 ^ n))) : + ∃ (h : (Fin n → Fin 4) → ℝ) (C : ℝ), 0 ≤ C ∧ ∀ k : ℕ, 1 ≤ k → + ‖(Finset.univ.toList.map fun g => + ((pauliStringHamiltonian g (h g)).propagator 1 0 (k : ℝ)⁻¹).op).prod ^ k + - U.op‖ ≤ C * (k : ℝ)⁻¹ := by + obtain ⟨H, hU, _⟩ := U.exists_hamiltonian_generator_spectrum_Icc + obtain ⟨h, C, hC0, hC⟩ := H.exists_norm_prod_pauliStringHamiltonian_propagator_pow_sub_le + refine ⟨h, C, hC0, fun k hk => ?_⟩ + rw [hU] + exact hC k hk + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliTrotterStep.lean b/LeanPool/AxQM/Postulates/API/PauliTrotterStep.lean new file mode 100644 index 0000000000..d9a676f7ce --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliTrotterStep.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliTrotterSummand +public import LeanPool.AxQM.Postulates.API.PauliTrotter + +/-! +# One full Trotter step `∏_g exp(-i h_g g Δ)` over all `4ⁿ` Pauli strings (N&C Problem 4.3(6)) + +Nielsen & Chuang, Problem 4.3(6) assembles the universal approximation `U ≈ [∏_g exp(-i h_g g Δ)]ᵏ` +as the `k`-fold power (part (5)) of **one Trotter step** — the ordered product, over *all* `4ⁿ` +Pauli strings `g : Fin n → Fin 4`, of the summands `exp(-i h_g g Δ)`. Parts (2)–(5) of Problem 4.3 +already prove that this operator product is `O(Δ²)`-close to `exp(-i H Δ)` and its `k`-fold power +`O(1/k)`-close to `U` (`AxQM/Postulates/API/PauliTrotter.lean`). Those bounds are stated over the +**operator** product `∏_g ((pauliStringHamiltonian g (h g)).propagator 1 0 Δ).op`; part (6) +additionally needs the **circuit** — a single `Evolution` — whose *gate count* can be bounded, and +whose operator *is* that product. This file supplies that circuit. The statement of Problem 4.3 is +in [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean). + +## What this file provides + +* `pauliTrotterStep n h t` — **one full Trotter step** `∏_g exp(-i h_g g t)`, as one + `Evolution (qudit (2ⁿ))`: the ordered product `(Finset.univ.toList.map fun g => + pauliTrotterSummand n g (h g) t).prod` of the total per-string summands + (`AxQM/Postulates/API/PauliTrotterSummand.lean`), over the fixed list `Finset.univ.toList` of all + `4ⁿ` Pauli strings. Each factor — including the identity string's global phase — is a genuine + register `Evolution` (that is exactly why `pauliTrotterSummand` is a *total* function of `g`), so + the product is a well-defined circuit. + +* `pauliTrotterStep_op` — **faithfulness**: the step's operator is N&C's part-(5) propagator + product, `(pauliTrotterStep n h t).op = (Finset.univ.toList.map fun g => + ((pauliStringHamiltonian g (h g)).propagator 1 0 t).op).prod`. Immediate from the summand + faithfulness `pauliTrotterSummand_op` (uniform in `g`) pushed through `Evolution.op_prod` (the + operator of an `Evolution`-monoid product is the product of the operators). This is the bridge + that transfers N&C's parts (4)/(5) — proved for the operator product — onto the circuit + `pauliTrotterStep`: substituting `t = 1/k` and taking the `k`-fold power + `pauliTrotterStep_op ▸ (·^k)` + turns the base of `Evolution.exists_pauliString_trotter_approximation` into `(pauliTrotterStep n h + (1/k)).op ^ k`, so the universal `O(1/k)` bound holds for the circuit's operator (see + `AxQM/Postulates/API/PauliTrotterExplicit.lean`). + +## Design notes + +* **Why a separate `Evolution`, not just the operator product.** N&C's parts (4)/(5) live at the + operator level; part (6) is an *implementation* claim — approximate `U` with `O(n·16ⁿ/ε)` + **gates**. A gate count is a `CircuitBudget`, which is a predicate on an `Evolution`, not on an + operator. So we must exhibit the actual circuit realising the product and count *it*. + `pauliTrotterStep` is that + circuit; `pauliTrotterStep_op` certifies it computes the right operator, and + `pauliTrotterStep_circuitBudget` (`AxQM/Core/PauliTrotterStepBudget.lean`) counts its `O(n·4ⁿ)` + gates. +* **The fixed ordering.** The list is `Finset.univ.toList` over `Fin n → Fin 4` — *exactly* the + ordering N&C's part-(4)/(5) forms use in `AxQM/Postulates/API/PauliTrotter.lean` + (`Observable.exists_norm_prod_pauliStringHamiltonian_propagator_sub_le` and the theorem + `Evolution.exists_pauliString_trotter_approximation`). Matching the ordering verbatim is what lets + `pauliTrotterStep_op` rewrite the base of those existing bounds into this circuit's operator + without any reindexing; N&C fix "any ordering", and the physical content is order-independent. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open Matrix + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **One full Trotter step** `∏_g exp(-i h_g g t)` (Nielsen & Chuang, Problem 4.3(6)), as one +`Evolution (qudit (2ⁿ))`: the ordered product over *all* `4ⁿ` Pauli strings `g : Fin n → Fin 4` (the +fixed list `Finset.univ.toList`) of the total per-string summands `pauliTrotterSummand n g (h g) t`. +Each summand — including the identity string `g = I^{⊗n}` (whose summand is a global phase) — is a +genuine register `Evolution`, so the product is a well-defined circuit. + +Its operator is N&C's part-(5) propagator product (`pauliTrotterStep_op`) and it costs `O(n·4ⁿ)` +one- and two-qubit gates (`pauliTrotterStep_circuitBudget`). For `t = Δ = 1/k` and `h g = h_g` this +is N&C's `∏_g exp(-i h_g g Δ)`, the single Trotter step whose `k`-fold power approximates `U`. -/ +def pauliTrotterStep (n : ℕ) (h : (Fin n → Fin 4) → ℝ) (t : ℝ) : Evolution (qudit (2 ^ n)) := + (Finset.univ.toList.map fun g => pauliTrotterSummand n g (h g) t).prod + +/-- **Nielsen & Chuang, Problem 4.3(6), faithfulness of the full Trotter step.** The operator of one +Trotter step `pauliTrotterStep n h t` is exactly N&C's part-(5) ordered propagator product, +`(pauliTrotterStep n h t).op = (Finset.univ.toList.map fun g => +((pauliStringHamiltonian g (h g)).propagator 1 0 t).op).prod`. + +The operator of an `Evolution`-monoid product is the product of the operators +(`Evolution.op_prod`), so the step's operator is the product of the summand operators; each summand +operator is the corresponding Pauli-string propagator by the uniform faithfulness +`pauliTrotterSummand_op`. This is the identity that transfers N&C's parts (4)/(5) — stated over this +propagator product in `Postulates/API/PauliTrotter` — onto the circuit `pauliTrotterStep`: at +`t = 1/k`, `(pauliTrotterStep n h (1/k)).op ^ k` is exactly the base (raised to the `k`) of +`Evolution.exists_pauliString_trotter_approximation`, so the universal `O(1/k)` approximation of `U` +holds for the circuit's operator. -/ +theorem pauliTrotterStep_op (h : (Fin n → Fin 4) → ℝ) (t : ℝ) : + (pauliTrotterStep n h t).op + = (Finset.univ.toList.map fun g => + ((pauliStringHamiltonian g (h g)).propagator 1 0 t).op).prod := by + rw [pauliTrotterStep, Evolution.op_prod, List.map_map] + refine congrArg List.prod (List.map_congr_left fun g _ => ?_) + exact pauliTrotterSummand_op g (h g) t + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PauliTrotterSummand.lean b/LeanPool/AxQM/Postulates/API/PauliTrotterSummand.lean new file mode 100644 index 0000000000..cc12ba9af8 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PauliTrotterSummand.lean @@ -0,0 +1,148 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliStringExpCircuit +public import LeanPool.AxQM.Postulates.API.NMRControlledZ +public import LeanPool.AxQM.Concrete.PauliStringLocality + +/-! +# The total per-string Trotter summand `exp(-i h_g g Δ)` over all `4ⁿ` strings (N&C Problem 4.3(6)) + +Nielsen & Chuang, Problem 4.3(6) assembles the universal approximation `U ≈ [∏_g exp(-i h_g g Δ)]ᵏ` +as the `k`-fold power (part (5)) of one Trotter step, itself the ordered product over **all** `4ⁿ` +Pauli strings `g : Fin n → Fin 4` of the summands `exp(-i h_g g Δ)`. For that product to be a +well-defined `Evolution`-valued function of `g`, each summand — including the one for the **identity +string** `g = I^{⊗n}` — must be a single register `Evolution`. This file supplies exactly that total +function and its operator faithfulness; the `O(n)` gate count is `pauliTrotterSummand_circuitBudget` +(`AxQM/Core/PauliTrotterSummandBudget.lean`). + +## What this file provides + +* `pauliTrotterSummand n g coeff t` — the Trotter summand `exp(-i · coeff · t · g)` of the + Pauli-string Hamiltonian `coeff · g`, as one `Evolution (qudit (2ⁿ))`, defined by cases on the + **support** `Concrete.pauliStringSupport g = {k | g k ≠ 0}`: + * **nonempty support** (a genuine Pauli rotation): the Figure-4.19 compute–rotate–uncompute + cascade `pauliStringExpCircuit n g c ts (2 · coeff · t)`, with collector `c = min'` of the + support and remaining support wires `ts = (support.erase c).toList` (so the string's support is + exactly `insert c ts`); + * **empty support** (the identity string `g = I^{⊗n}`, whose summand `exp(-i coeff t · I)` is a + *global phase*, not a Pauli rotation — the part-(3) circuit needs a nonempty support/collector, + so it does not cover this case): the global-phase gate `globalPhaseGate (-(coeff · t))`. + +* `pauliTrotterSummand_op` — **faithfulness, for every `g`**: the summand's operator is the + propagator of the Pauli-string Hamiltonian, `(pauliTrotterSummand n g coeff t).op = + ((pauliStringHamiltonian g coeff).propagator 1 0 t).op`, i.e. exactly `exp(-i · coeff · t · g)` + (N&C's `exp(-i h_g g Δ)` at `coeff = h_g`, `t = Δ`). The nonempty case is the part-(3) result + `pauliStringExpCircuit_op_eq_propagator` (whose five support hypotheses are discharged from the + canonical collector/support-list choice); the identity case reduces the propagator's closed form + `pauliStringHamiltonian_propagator_op` at the all-identity string + (`(pauliStringHamiltonian g 1).op = 1` via `Concrete.pauliStringStd_zero`) to + `cos(coeff t)·1 − i·sin(coeff t)·1 = e^{-i coeff t}·1`, Euler's formula + (`Complex.exp_ofReal_mul_I`) matched against `globalPhaseGate_op`. + +## Design notes + +* **One total function, not two.** The full Trotter step + (`AxQM/Postulates/API/PauliTrotterStep.lean`) is the product + `∏_g pauliTrotterSummand n g (h g) Δ` over the fixed list of all `4ⁿ` strings; its operator equals + the part-(5) propagator product `∏_g ((pauliStringHamiltonian g (h g)).propagator 1 0 Δ).op` + precisely because `pauliTrotterSummand_op` holds *uniformly* in `g`. The identity string sits in + that list and must contribute a real `Evolution` with the right operator (a global phase), so the + case split lives inside the summand rather than being a special case the product must dodge. +* **Canonical collector/support-list.** The Figure-4.19 circuit `pauliStringExpCircuit` is faithful + only when its collector `c` and control list `ts` partition the support (`support = insert c ts`, + `c ∉ ts`, `ts` nodup). Choosing `c = support.min'` and `ts = (support.erase c).toList` makes this + automatic: `c ∈ support`, `ts` is exactly the rest of the support (nodup as a `Finset.toList`), + and a qubit off `{c} ∪ ts` is off the support hence `g = 0` there. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open Matrix + +noncomputable section + +namespace AxQM + +variable {n : ℕ} + +/-- **The total per-string Trotter summand** `exp(-i · coeff · t · g)` (Nielsen & Chuang, +Problem 4.3(6)), as one `Evolution (qudit (2ⁿ))`, defined for *every* Pauli string +`g : Fin n → Fin 4` by cases on its support `Concrete.pauliStringSupport g`: + +* **nonempty support** — a genuine Pauli rotation: the Figure-4.19 cascade + `pauliStringExpCircuit n g c ts (2 · coeff · t)` with collector `c` the least support wire and + `ts` the remaining support wires, so `g`'s support is exactly `insert c ts`; +* **empty support** — the identity string `g = I^{⊗n}`, whose summand `exp(-i coeff t · I)` is the + global phase `e^{-i coeff t} · I`: the gate `globalPhaseGate (-(coeff · t))`. + +Its operator is the Trotter summand propagator (`pauliTrotterSummand_op`) and it costs `O(n)` +one- and two-qubit gates (`pauliTrotterSummand_circuitBudget`). For `coeff = h_g`, `t = Δ` this is +N&C's `exp(-i h_g g Δ)`, the factor of the Trotter product `∏_g exp(-i h_g g Δ)`. -/ +def pauliTrotterSummand (n : ℕ) (g : Fin n → Fin 4) (coeff t : ℝ) : + Evolution (qudit (2 ^ n)) := + if hne : (Concrete.pauliStringSupport g).Nonempty then + pauliStringExpCircuit n g ((Concrete.pauliStringSupport g).min' hne) + (((Concrete.pauliStringSupport g).erase + ((Concrete.pauliStringSupport g).min' hne)).toList) (2 * coeff * t) + else + globalPhaseGate (-(coeff * t)) + +/-- **Nielsen & Chuang, Problem 4.3(6), faithfulness of the total summand.** For *every* Pauli +string `g : Fin n → Fin 4`, the operator of `pauliTrotterSummand n g coeff t` is the unit-`ℏ` +propagator of the Pauli-string Hamiltonian `coeff · g`, +`(pauliTrotterSummand n g coeff t).op = ((pauliStringHamiltonian g coeff).propagator 1 0 t).op`, +i.e. exactly the Trotter summand `exp(-i · coeff · t · g)` — N&C's `exp(-i h_g g Δ)` for +`coeff = h_g` and `t = Δ`. Uniform in `g`: the nonempty-support case is the part-(3) faithfulness +result `pauliStringExpCircuit_op_eq_propagator` (its five support hypotheses discharged from the +canonical `c = support.min'`, `ts = (support.erase c).toList`), and the identity-string case matches +`globalPhaseGate_op` against the propagator's closed form `pauliStringHamiltonian_propagator_op` at +`g = 0` (Euler's formula, `Complex.exp_ofReal_mul_I`). -/ +theorem pauliTrotterSummand_op (g : Fin n → Fin 4) (coeff t : ℝ) : + (pauliTrotterSummand n g coeff t).op + = ((pauliStringHamiltonian g coeff).propagator 1 0 t).op := by + unfold pauliTrotterSummand + by_cases hne : (Concrete.pauliStringSupport g).Nonempty + · -- Nonempty support: the Figure-4.19 circuit is faithful (part (3) result). + rw [dite_eq_left hne] + set S := Concrete.pauliStringSupport g with hSdef + set c := S.min' hne with hcdef + have hcmem : c ∈ S := S.min'_mem hne + refine pauliStringExpCircuit_op_eq_propagator g c _ ?_ ?_ ?_ ?_ ?_ coeff t + · rw [Finset.mem_toList]; exact Finset.notMem_erase c S + · exact Finset.nodup_toList _ + · exact Concrete.mem_pauliStringSupport.mp hcmem + · intro x hx + rw [Finset.mem_toList] at hx + exact Concrete.mem_pauliStringSupport.mp (Finset.mem_of_mem_erase hx) + · intro k hkc hknm + by_contra hk + exact hknm (by + rw [Finset.mem_toList] + exact Finset.mem_erase.mpr ⟨hkc, Concrete.mem_pauliStringSupport.mpr hk⟩) + · -- Empty support: the identity string, whose summand is a global phase. + rw [dite_eq_right hne] + have hg0 : g = 0 := by + funext k + exact Concrete.notMem_pauliStringSupport.mp fun hk => hne ⟨k, hk⟩ + have hop1 : (pauliStringHamiltonian g 1).op = 1 := by + rw [pauliStringHamiltonian_op, hg0, Concrete.pauliStringStd_zero, Complex.ofReal_one, + one_smul] + exact map_one _ + have hscalar : Complex.exp ((↑(-(coeff * t)) : ℂ) * Complex.I) + = (↑(Real.cos (coeff * t)) : ℂ) - (↑(Real.sin (coeff * t)) : ℂ) * Complex.I := by + rw [Complex.exp_ofReal_mul_I, Real.cos_neg, Real.sin_neg] + push_cast + ring + rw [globalPhaseGate_op, pauliStringHamiltonian_propagator_op, hop1, ← sub_smul, hscalar] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PeriodShift.lean b/LeanPool/AxQM/Postulates/API/PeriodShift.lean new file mode 100644 index 0000000000..fdd19421d6 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PeriodShift.lean @@ -0,0 +1,247 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.QuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.InverseQuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.QuditMeasurement + +/-! +# AxQM.Postulates.API — the period-shift operator and its Fourier eigenstates + +The development behind **Nielsen & Chuang Exercise 5.21** (Period-finding and phase +estimation). For a periodic function `f` with period `r` (`f(x+r) = f(x)`), whose `r` value states +`|f(0)⟩, …, |f(r-1)⟩` are distinct and orthonormal, one is given the **shift operator** `U_y` +(N&C's `U_y`) acting by `U_y|f(x)⟩ = |f(x+y)⟩`. Since the `r` value states are orthonormal and `U_y` +cyclically permutes them, they are canonically the computational basis of the `r`-level **period +register** `qudit r`, with `|f(x)⟩ = |x mod r⟩`; the shift is then the cyclic-shift gate +`|x⟩ ↦ |x+y⟩` on `Fin r` (`+` the modular addition of `Fin r`). Its Fourier eigenstates (N&C +eq. 5.63) + + `|f̂(ℓ)⟩ = (1/√r) ∑_{x (periodShift r y).op (((Real.sqrt r : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((x : ℕ) * (ℓ : ℕ)) / r))) + • (quditBasis x).vec)) + (fun x => Complex.exp (2 * Real.pi * Complex.I * ((y : ℕ) * (ℓ : ℕ)) / r) + • (((Real.sqrt r : ℂ)⁻¹ + * Complex.exp (-(2 * Real.pi * Complex.I * ((x : ℕ) * (ℓ : ℕ)) / r))) + • (quditBasis x).vec)) ?_ + intro x + simp only [Equiv.coe_addRight] + rw [map_smul, periodShift_op_apply_quditBasis, smul_smul, periodShift_phase_shift r y ℓ x] + +/-! ### Exercise 5.21(2): the value state is a uniform superposition of eigenstates -/ + +/-- **Nielsen & Chuang, Exercise 5.21(2) / eq. (5.64).** A value state `|f(x₀)⟩ = |x₀⟩` is the +equal-magnitude superposition of *all* Fourier eigenstates `|f̂(ℓ)⟩`: + + `|f(x₀)⟩ = (1/√r) ∑_ℓ e^{2πiℓx₀/r} |f̂(ℓ)⟩`. + +This is the inverse of eq. (5.63) and the crux of part (2): each `|f̂(ℓ)⟩` appears with amplitude of +modulus `1/√r`, so `|f(x₀)⟩` is to `U_y` what `|1⟩ = (1/√r) ∑_s |u_s⟩` (eq. 5.44) is to the +order-finding operator — a single, trivially preparable state that is an equal superposition of +every eigenstate. Phase estimation on `U_y` started from `|f(x₀)⟩` therefore samples the eigenphases +`ℓy/r` (from `periodShift_hasEigenstate_qftInverseFourierImage`) and recovers the period `r`. + +Proof: `|x₀⟩ = F⁻¹(F|x₀⟩)` (`Evolution.evolvePure_adjoint_evolvePure`, as +`qftInverseEvolution = F†`); `F|x₀⟩ = (1/√r) ∑_ℓ e^{2πiℓx₀/r}|ℓ⟩` (`qftFourierImage`); and expanding +`F⁻¹` over the sum sends each `|ℓ⟩` to `F⁻¹|ℓ⟩ = |f̂(ℓ)⟩`. -/ +theorem quditBasis_eq_sum_qftInverseFourierImage (r : ℕ) [NeZero r] (x₀ : Fin r) : + (quditBasis x₀).vec + = ∑ ℓ : Fin r, ((Real.sqrt r : ℂ)⁻¹ + * Complex.exp (2 * Real.pi * Complex.I * ((x₀ : ℕ) * (ℓ : ℕ)) / r)) + • (qftInverseFourierImage r ℓ).vec := by + have hround : (qftInverseEvolution r).evolvePure (qftFourierImage r x₀) = quditBasis x₀ := by + rw [← qftEvolution_evolvePure_quditBasis] + exact Evolution.evolvePure_adjoint_evolvePure (qftEvolution r) (quditBasis x₀) + have hvec : (qftInverseEvolution r).op ((qftFourierImage r x₀).vec) = (quditBasis x₀).vec := by + have h := congrArg PureState.vec hround + rwa [Evolution.evolvePure_vec] at h + rw [← hvec, qftFourierImage_vec, map_sum] + refine Finset.sum_congr rfl (fun ℓ _ => ?_) + rw [map_smul] + congr 1 + rw [qftInverseEvolution_op_apply_quditBasis, ← qftInverseFourierImage_vec] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PhaseFlipCode.lean b/LeanPool/AxQM/Postulates/API/PhaseFlipCode.lean new file mode 100644 index 0000000000..11e3905d47 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PhaseFlipCode.lean @@ -0,0 +1,232 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.Teleportation +public import LeanPool.AxQM.Postulates.API.QubitThree +public import LeanPool.AxQM.Postulates.API.CnotPauliPropagation +public import LeanPool.AxQM.Postulates.API.QuantumErrorCorrection + +/-! +# AxQM.Postulates.API — the three-qubit phase-flip code and its QEC conditions + +Nielsen & Chuang's **Exercise 10.8** (p. 441) asks to verify that the three-qubit *phase-flip code* +with logical states + + `|0_L⟩ = |+++⟩`, `|1_L⟩ = |−−−⟩` + +satisfies the quantum error-correction conditions (Theorem 10.1, eq. (10.16)) for the error set +`{I, Z₁, Z₂, Z₃}` (identity and a Pauli `Z` on each of the three qubits). + +The phase-flip code is the Hadamard-conjugate of the bit-flip code: in the `{|+⟩, |−⟩}` orthonormal +basis of each qubit it looks exactly like the bit-flip code in the computational basis, with the +Pauli `Z` (which sends `|+⟩ ↔ |−⟩`) playing the role of the bit-flip `X`. So the verification is a +computation over the `±`-basis: the eight vectors `Zᵢ|+++⟩` and `Zᵢ|−−−⟩` (`i = 0` meaning no error) +are mutually orthonormal `±`-basis vectors, whence `⟪Eᵢ v_a, Eⱼ v_b⟫ = δᵢⱼ δ_{a,b}` and the QEC +conditions hold with the **identity** coefficient matrix `α = 1` (a Hermitian matrix, as required). + +## Contents + +* `pmQubit` — the single-qubit `±` orthonormal frame `0 ↦ |+⟩`, `1 ↦ |−⟩`; `pmQubit_orthonormal` + and `pauliZGate_op_pmQubit` (`Z` flips the `±` label) are its two structural facts. +* `pmThreeVec` — the three-qubit `±`-basis vector `|σ₁σ₂σ₃⟩`; `pmThreeVec_inner` records that these + eight vectors are orthonormal. +* `phaseFlipErrorGate` / `phaseFlipErrorOp` — the error gates `{I, Z₁, Z₂, Z₃}` as evolutions and as + operators; `phaseFlipErrorOp_apply` computes their action on the `±` basis as a coordinate flip. +* `phaseFlipCodeword` — the logical codewords `|+++⟩`, `|−−−⟩`; `phaseFlipCodeProj` — the code + projector `P = |+++⟩⟨+++| + |−−−⟩⟨−−−|`. +* `phaseFlipCode_satisfiesQECConditions` — **Exercise 10.8**: `SatisfiesQECConditions + phaseFlipCodeProj phaseFlipErrorOp` (the conditions hold with the identity Hermitian matrix). + +The statement of Exercise 10.8 is in [upstream `AxQM/NC/Ch10/Exercise10_8.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Exercise10_8.lean). The Knill–Laflamme core +`ContinuousLinearMap.satisfiesKLConditions_of_inner_error_images` (the codeword-basis verification, +reusable for Exercises 10.7/10.9/10.10) is in +`ToMathlib/Analysis/InnerProductSpace/QuantumErrorCorrection.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct Matrix +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-! ### The single-qubit `±` frame -/ + +/-- **The Pauli-`Z` gate sends `|+⟩` to `|−⟩`:** `Z|+⟩ = |−⟩`, at operator level. -/ +theorem pauliZGate_op_qubitPlus : pauliZGate.op qubitPlus.vec = qubitMinus.vec := by + rw [pauliZGate_op, qubitPlus_vec, qubitMinus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ) + (WithLp.toLp 2 Concrete.xPlus)).ofLp = (WithLp.toLp 2 Concrete.xMinus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.pauliZ, Concrete.xPlus, Concrete.xMinus, Matrix.mulVec, dotProduct] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The Pauli-`Z` gate sends `|−⟩` to `|+⟩`:** `Z|−⟩ = |+⟩`, at operator level. -/ +theorem pauliZGate_op_qubitMinus : pauliZGate.op qubitMinus.vec = qubitPlus.vec := by + rw [pauliZGate_op, qubitPlus_vec, qubitMinus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ) + (WithLp.toLp 2 Concrete.xMinus)).ofLp = (WithLp.toLp 2 Concrete.xPlus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.pauliZ, Concrete.xPlus, Concrete.xMinus, Matrix.mulVec, dotProduct] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- `⟨−|−⟩ = 1`: the `|−⟩` state is a unit vector. -/ +theorem inner_qubitMinus_self : ⟪qubitMinus.vec, qubitMinus.vec⟫_ℂ = 1 := by + have := qubitMinus.normalized + rw [inner_self_eq_norm_sq_to_K, this]; norm_num + +/-- `⟨−|+⟩ = 0`: `|−⟩` and `|+⟩` are orthogonal (the conjugate of `inner_qubitPlus_qubitMinus`). -/ +theorem inner_qubitMinus_qubitPlus : ⟪qubitMinus.vec, qubitPlus.vec⟫_ℂ = 0 := by + rw [← inner_conj_symm, inner_qubitPlus_qubitMinus, map_zero] + +/-- **The single-qubit `±` orthonormal frame** `{|+⟩, |−⟩}`, as a family indexed by `Fin 2` +(`0 ↦ |+⟩`, `1 ↦ |−⟩`). This is the Hadamard basis in which the phase-flip code and its `Z`-errors +mirror the bit-flip code and its `X`-errors in the computational basis. -/ +def pmQubit : Fin 2 → qubit.space := ![qubitPlus.vec, qubitMinus.vec] + +/-- **The `±` frame is orthonormal:** `⟪|±⟩, |±⟩⟫ = δ`. -/ +theorem pmQubit_orthonormal : Orthonormal ℂ pmQubit := by + rw [orthonormal_iff_ite] + intro s t + fin_cases s <;> fin_cases t <;> + simp only [pmQubit, Fin.zero_eta, Fin.mk_one, Matrix.cons_val_zero, Matrix.cons_val_one, + Fin.isValue, inner_qubitPlus_self, inner_qubitPlus_qubitMinus, inner_qubitMinus_self, + inner_qubitMinus_qubitPlus, Fin.reduceEq, ite_true, ite_false] + +/-- **The Pauli-`Z` gate flips the `±` label:** `Z|σ⟩ = |σ ⊕ 1⟩` (`Z|+⟩ = |−⟩`, `Z|−⟩ = |+⟩`). This +is the exact analogue, in the `±` basis, of the bit-flip `X|i⟩ = |i ⊕ 1⟩` in the computational +basis. -/ +theorem pauliZGate_op_pmQubit (s : Fin 2) : pauliZGate.op (pmQubit s) = pmQubit (s + 1) := by + fin_cases s + · exact pauliZGate_op_qubitPlus + · exact pauliZGate_op_qubitMinus + +/-! ### The three-qubit `±` basis -/ + +/-- **The three-qubit `±`-basis vector** `|σ₁σ₂σ₃⟩ = |σ₁⟩ ⊗ (|σ₂⟩ ⊗ |σ₃⟩)` (each `σᵢ` selecting +`|+⟩` or `|−⟩`) of the register `qubit ⊗ (qubit ⊗ qubit)`. The eight such vectors form an +orthonormal basis; the two codewords `|+++⟩`, `|−−−⟩` are the `(0,0,0)` and `(1,1,1)` members. -/ +def pmThreeVec (s : Fin 2 × Fin 2 × Fin 2) : (qubit ⊗ (qubit ⊗ qubit)).space := + pmQubit s.1 ⊗ₜ[ℂ] (pmQubit s.2.1 ⊗ₜ[ℂ] pmQubit s.2.2) + +/-- **The three-qubit `±`-basis vectors are orthonormal:** `⟪|σ⟩, |τ⟩⟫ = δ_{σ,τ}`, from the +multiplicativity of the tensor inner product and orthonormality of the single-qubit `±` frame. -/ +theorem pmThreeVec_inner (s t : Fin 2 × Fin 2 × Fin 2) : + ⟪pmThreeVec s, pmThreeVec t⟫_ℂ = if s = t then 1 else 0 := by + obtain ⟨s1, s2, s3⟩ := s + obtain ⟨t1, t2, t3⟩ := t + change inner ℂ (pmQubit s1 ⊗ₜ[ℂ] (pmQubit s2 ⊗ₜ[ℂ] pmQubit s3)) + (pmQubit t1 ⊗ₜ[ℂ] (pmQubit t2 ⊗ₜ[ℂ] pmQubit t3)) = _ + rw [TensorProduct.inner_tmul, TensorProduct.inner_tmul, + orthonormal_iff_ite.mp pmQubit_orthonormal, orthonormal_iff_ite.mp pmQubit_orthonormal, + orthonormal_iff_ite.mp pmQubit_orthonormal] + by_cases h1 : s1 = t1 <;> by_cases h2 : s2 = t2 <;> by_cases h3 : s3 = t3 <;> + simp [h1, h2, h3, Prod.ext_iff] + +/-! ### The error operators `{I, Z₁, Z₂, Z₃}` -/ + +/-- **The error gates** `{I, Z₁, Z₂, Z₃}` on the three-qubit register, as evolutions (Postulate 5): +`0 ↦ I`, `1 ↦ Z⊗I⊗I`, `2 ↦ I⊗Z⊗I`, `3 ↦ I⊗I⊗Z`, built from `pauliZGate` and the single-wire +embeddings `Evolution.onLeft` / `Evolution.onRight`. -/ +def phaseFlipErrorGate : Fin 4 → Evolution (qubit ⊗ (qubit ⊗ qubit)) + | 0 => Evolution.id + | 1 => pauliZGate.onLeft (qubit ⊗ qubit) + | 2 => (pauliZGate.onLeft qubit).onRight qubit + | 3 => (pauliZGate.onRight qubit).onRight qubit + +/-- **The error operators** `{I, Z₁, Z₂, Z₃}` as operators on the register state space — the +operation elements of the noise the phase-flip code protects against (the `.op` of +`phaseFlipErrorGate`). -/ +def phaseFlipErrorOp (i : Fin 4) : + (qubit ⊗ (qubit ⊗ qubit)).space →L[ℂ] (qubit ⊗ (qubit ⊗ qubit)).space := + (phaseFlipErrorGate i).op + +/-- **The coordinate flip induced by each error on the `±`-basis index:** `I` fixes the index, +`Zₖ` flips the `k`-th `±` label. The combinatorial shadow of `phaseFlipErrorOp_apply`. -/ +def phaseFlipFlip : Fin 4 → (Fin 2 × Fin 2 × Fin 2) → (Fin 2 × Fin 2 × Fin 2) + | 0, s => s + | 1, (a, b, c) => (a + 1, b, c) + | 2, (a, b, c) => (a, b + 1, c) + | 3, (a, b, c) => (a, b, c + 1) + +/-- **The errors permute the `±` basis:** `Eᵢ |σ⟩ = |phaseFlipFlip i σ⟩`. Each `Zₖ` flips the `k`-th +`±` label (because `Z|+⟩ = |−⟩`, `Z|−⟩ = |+⟩`), and `I` fixes the state. -/ +theorem phaseFlipErrorOp_apply (i : Fin 4) (s : Fin 2 × Fin 2 × Fin 2) : + phaseFlipErrorOp i (pmThreeVec s) = pmThreeVec (phaseFlipFlip i s) := by + obtain ⟨a, b, c⟩ := s + fin_cases i + · change (Evolution.id : Evolution (qubit ⊗ (qubit ⊗ qubit))).op (pmThreeVec (a, b, c)) + = pmThreeVec (a, b, c) + rw [Evolution.id_op, one_apply_eq_self] + · change (pauliZGate.onLeft (qubit ⊗ qubit)).op (pmThreeVec (a, b, c)) + = pmThreeVec (a + 1, b, c) + rw [pmThreeVec] + have h := Evolution.onLeft_op_tmul pauliZGate (qubit ⊗ qubit) (pmQubit a) + (pmQubit b ⊗ₜ[ℂ] pmQubit c) + rw [h, pauliZGate_op_pmQubit] + rfl + · change ((pauliZGate.onLeft qubit).onRight qubit).op (pmThreeVec (a, b, c)) + = pmThreeVec (a, b + 1, c) + rw [pmThreeVec] + have h := Evolution.onRight_op_tmul (pauliZGate.onLeft qubit) qubit (pmQubit a) + (pmQubit b ⊗ₜ[ℂ] pmQubit c) + rw [h, Evolution.onLeft_op_tmul, pauliZGate_op_pmQubit] + rfl + · change ((pauliZGate.onRight qubit).onRight qubit).op (pmThreeVec (a, b, c)) + = pmThreeVec (a, b, c + 1) + rw [pmThreeVec] + have h := Evolution.onRight_op_tmul (pauliZGate.onRight qubit) qubit (pmQubit a) + (pmQubit b ⊗ₜ[ℂ] pmQubit c) + rw [h] + have h2 := Evolution.onRight_op_tmul pauliZGate qubit (pmQubit b) (pmQubit c) + rw [h2, pauliZGate_op_pmQubit] + rfl + +/-! ### The code and the QEC conditions -/ + +/-- **The logical codewords of the three-qubit phase-flip code:** `|0_L⟩ = |+++⟩` (`a = 0`) and +`|1_L⟩ = |−−−⟩` (`a = 1`). -/ +def phaseFlipCodeword (a : Fin 2) : (qubit ⊗ (qubit ⊗ qubit)).space := pmThreeVec (a, a, a) + +/-- **The code projector** `P = |+++⟩⟨+++| + |−−−⟩⟨−−−|` onto the phase-flip code space. -/ +def phaseFlipCodeProj : (qubit ⊗ (qubit ⊗ qubit)).space →L[ℂ] (qubit ⊗ (qubit ⊗ qubit)).space := + ∑ a, InnerProductSpace.rankOne ℂ (phaseFlipCodeword a) (phaseFlipCodeword a) + +/-- **The codeword matrix elements of the errors:** `⟪Eᵢ v_a, Eⱼ v_b⟫ = δᵢⱼ δ_{a,b}`, i.e. the +identity coefficient matrix. Each `Eᵢ v_a` is a `±`-basis vector (a single flip of the codeword +`|σσσ⟩`), and the eight such vectors — `{|+++⟩, |−++⟩, |+−+⟩, |++−⟩}` (weight `≤ 1`) for the `|+++⟩` +codeword and their bit-complements for `|−−−⟩` — are mutually orthonormal, so the overlap is `1` +exactly when `(i, a) = (j, b)`. -/ +theorem phaseFlipError_inner_codeword (i j : Fin 4) (a b : Fin 2) : + ⟪phaseFlipErrorOp i (phaseFlipCodeword a), phaseFlipErrorOp j (phaseFlipCodeword b)⟫_ℂ + = (1 : Matrix (Fin 4) (Fin 4) ℂ) i j * (if a = b then 1 else 0) := by + simp only [phaseFlipCodeword, phaseFlipErrorOp_apply, pmThreeVec_inner, Matrix.one_apply] + fin_cases i <;> fin_cases j <;> fin_cases a <;> fin_cases b <;> + simp [phaseFlipFlip, Prod.ext_iff] + +/-- **Nielsen & Chuang, Exercise 10.8.** The three-qubit phase-flip code +(`|0_L⟩ = |+++⟩`, `|1_L⟩ = |−−−⟩`) satisfies the quantum error-correction conditions (Theorem 10.1) +for the error set `{I, Z₁, Z₂, Z₃}`: the code projector `phaseFlipCodeProj` and error operators +`phaseFlipErrorOp` satisfy `SatisfiesQECConditions` with the **identity** Hermitian coefficient +matrix `α = 1` (`P Eᵢ† Eⱼ P = δᵢⱼ P`). Hence `{I, Z₁, Z₂, Z₃}` is a correctable set. -/ +theorem phaseFlipCode_satisfiesQECConditions : + SatisfiesQECConditions phaseFlipCodeProj phaseFlipErrorOp := + ⟨1, Matrix.isHermitian_one, + ContinuousLinearMap.satisfiesKLConditions_of_inner_error_images + phaseFlipCodeword phaseFlipErrorOp 1 phaseFlipError_inner_codeword⟩ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PhaseGateEigenbasis.lean b/LeanPool/AxQM/Postulates/API/PhaseGateEigenbasis.lean new file mode 100644 index 0000000000..d2c21917f1 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PhaseGateEigenbasis.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.AxisAngleGateValues +public import LeanPool.AxQM.Postulates.API.PhaseFlipCode + +/-! +# The phase gate `S` and Pauli `Z` on the `X`- and `Y`-eigenstates + +The single-qubit phase gate `S = diag(1, i)` and the Pauli `Z` gate act cleanly on the four +non-computational eigenstates `|±⟩ = (|0⟩ ± |1⟩)/√2` (`qubitPlus`, `qubitMinus`) and +`|±i⟩ = (|0⟩ ± i|1⟩)/√2` (`qubitPlusI`, `qubitMinusI`): + +* `S` rotates the `X`-eigenbasis into the `Y`-eigenbasis and back a quarter turn further: + `S|+⟩ = |+i⟩`, `S|−⟩ = |−i⟩`, `S|+i⟩ = |−⟩`, `S|−i⟩ = |+⟩` (so `S⁴ = 1` on the Bloch equator). +* `Z` swaps the `X`-eigenstates: `Z|+⟩ = |−⟩`, `Z|−⟩ = |+⟩`. + +These are the `PureState`-level (`evolvePure`) truth tables, each proved at the underlying vector +level by `PureState.ext`. The two `Z` tables are a lift of the operator truth tables +`pauliZGate_op_qubitPlus`/`pauliZGate_op_qubitMinus` (`AxQM/Postulates/API/PhaseFlipCode.lean`); the +four `S` tables go through `sGate_op` on the concrete unit vectors +`Concrete.xPlus`/`xMinus`/`yPlus`/`yMinus`. + +They are the single-qubit input to the two-qubit `SWAP`-conjugation identity of the +five-two-qubit-gate Fredkin construction (`AxQM/Core/FredkinFiveGateSwapIdentity.lean`, N&C +Exercise 4.25.4). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace AxQM + +/-- **The phase gate sends `|+⟩` to `|+i⟩`:** `S|+⟩ = |+i⟩`. The `X`-eigenstate `(|0⟩ + |1⟩)/√2` +maps to the `Y`-eigenstate `(|0⟩ + i|1⟩)/√2` because `S` fixes `|0⟩` and multiplies `|1⟩` by `i`. -/ +theorem sGate_evolvePure_qubitPlus : sGate.evolvePure qubitPlus = qubitPlusI := by + apply PureState.ext + rw [Evolution.evolvePure_vec, sGate_op, qubitPlus_vec, qubitPlusI_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix) + (WithLp.toLp 2 Concrete.xPlus)).ofLp = (WithLp.toLp 2 Concrete.yPlus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.sMatrix, Concrete.xPlus, Concrete.yPlus, Matrix.mulVec, dotProduct, mul_comm] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The phase gate sends `|−⟩` to `|−i⟩`:** `S|−⟩ = |−i⟩`. The sign-flipped companion of +`sGate_evolvePure_qubitPlus`: `S` fixes `|0⟩` and multiplies the `−|1⟩` component by `i`. -/ +theorem sGate_evolvePure_qubitMinus : sGate.evolvePure qubitMinus = qubitMinusI := by + apply PureState.ext + rw [Evolution.evolvePure_vec, sGate_op, qubitMinus_vec, qubitMinusI_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix) + (WithLp.toLp 2 Concrete.xMinus)).ofLp = (WithLp.toLp 2 Concrete.yMinus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.sMatrix, Concrete.xMinus, Concrete.yMinus, Matrix.mulVec, dotProduct, mul_comm] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The phase gate sends `|+i⟩` to `|−⟩`:** `S|+i⟩ = |−⟩`. Continuing the quarter-turn on the +Bloch equator (`S² = Z`): the `Y`-eigenstate `(|0⟩ + i|1⟩)/√2` maps to `(|0⟩ − |1⟩)/√2` since +`S` multiplies the `i|1⟩` component by a further `i`, giving `i² = −1`. -/ +theorem sGate_evolvePure_qubitPlusI : sGate.evolvePure qubitPlusI = qubitMinus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, sGate_op, qubitPlusI_vec, qubitMinus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix) + (WithLp.toLp 2 Concrete.yPlus)).ofLp = (WithLp.toLp 2 Concrete.xMinus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.sMatrix, Concrete.yPlus, Concrete.xMinus, Matrix.mulVec, dotProduct] + ring_nf + simp [Complex.I_sq] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The phase gate sends `|−i⟩` to `|+⟩`:** `S|−i⟩ = |+⟩`. The `Y`-eigenstate +`(|0⟩ − i|1⟩)/√2` maps to `(|0⟩ + |1⟩)/√2` since `S` multiplies the `−i|1⟩` component by `i`, +giving `−i² = 1`. -/ +theorem sGate_evolvePure_qubitMinusI : sGate.evolvePure qubitMinusI = qubitPlus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, sGate_op, qubitMinusI_vec, qubitPlus_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.sMatrix) + (WithLp.toLp 2 Concrete.yMinus)).ofLp = (WithLp.toLp 2 Concrete.xPlus).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases j <;> + simp [Concrete.sMatrix, Concrete.yMinus, Concrete.xPlus, Matrix.mulVec, dotProduct] + ring_nf + simp [Complex.I_sq] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- **The Pauli-`Z` gate sends `|+⟩` to `|−⟩`:** `Z|+⟩ = |−⟩`, at the `PureState` level. `Z` fixes +`|0⟩` and flips the sign of `|1⟩`, exchanging the two `X`-eigenstates. A mechanical lift of the +operator truth table `pauliZGate_op_qubitPlus`. -/ +theorem pauliZGate_evolvePure_qubitPlus : pauliZGate.evolvePure qubitPlus = qubitMinus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, pauliZGate_op_qubitPlus] + +/-- **The Pauli-`Z` gate sends `|−⟩` to `|+⟩`:** `Z|−⟩ = |+⟩`, at the `PureState` level. The +inverse direction of `pauliZGate_evolvePure_qubitPlus`; `Z` is its own inverse on the equator. A +mechanical lift of the operator truth table `pauliZGate_op_qubitMinus`. -/ +theorem pauliZGate_evolvePure_qubitMinus : pauliZGate.evolvePure qubitMinus = qubitPlus := by + apply PureState.ext + rw [Evolution.evolvePure_vec, pauliZGate_op_qubitMinus] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PhaseWire.lean b/LeanPool/AxQM/Postulates/API/PhaseWire.lean new file mode 100644 index 0000000000..2637e006ab --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PhaseWire.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QftHadamardEvolution +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Concrete.MultiControlledSingleQubitSpareReduction + +/-! +# Single-qubit phase gates on a register wire + +The phase layer `D = diagPhase θ` of the computable-phase-shift circuit (Nielsen & Chuang +Problem 4.1) is, in the textbook construction, **`n` single-qubit phase gates** — one on each wire +of the `n`-qubit ancilla register. This file supplies the register-side ingredient that makes that +gate count a genuine object: the single-qubit phase gate `P(φ) = diag(1, e^{iφ})` placed on one +wire of the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`, together with its +computational-basis action. + +* `phaseWireEvolution n t φ` — the phase gate `P(φ)` on wire `t` of `qudit (2ⁿ)`: the `quditGate` + promotion of `Concrete.singleQubitOnWire finFunctionFinEquiv t (Concrete.phaseGate e^{iφ})`. The + direct analogue of `rotZWireEvolution n t θ` with the `z`-rotation replaced by a **phase** gate; + because a phase gate is diagonal, its wire embedding is diagonal in the computational basis, so + its action carries **no** off-diagonal branch (unlike a rotation). +* `phaseWireEvolution_evolvePure_quditBasis` — its **diagonal basis action** + `P(φ)ₜ |f⟩ = (e^{iφ})^{f t} · |f⟩`: the gate leaves the basis ket unchanged and multiplies it by + the phase `e^{iφ}` exactly when wire `t` carries a `1`. This is the single-wire factor the + phase-gradient decomposition of `diagPhase` (Problem 4.1's phase layer) is assembled from. + +It reuses the single-wire-gate machinery of `AxQM/Postulates/API/FourGateReachableWire.lean` +(`rotZWireEvolution`) and `AxQM/Postulates/API/QftHadamardEvolution.lean`. +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The single-qubit phase gate `P(φ) = diag(1, e^{iφ})` on a register wire.** Placed on wire +`t` of the `2ⁿ`-level register, as a named `Evolution (qudit (2ⁿ))`: the `quditGate` promotion of +the gate matrix `Concrete.singleQubitOnWire finFunctionFinEquiv t (Concrete.phaseGate e^{iφ})` +(unitary, since `|e^{iφ}| = 1`). The direct analogue of `rotZWireEvolution n t θ` with the +`z`-rotation block replaced by the phase gate `P(φ)`; its diagonal basis action is +`phaseWireEvolution_evolvePure_quditBasis`. This is the single-wire factor the phase layer of the +computable-phase-shift circuit (N&C Problem 4.1) is decomposed into. -/ +def phaseWireEvolution (n : ℕ) (t : Fin n) (φ : ℝ) : Evolution (qudit (2 ^ n)) := + quditGate (singleQubitOnWire_mem_unitaryGroup finFunctionFinEquiv t + (Concrete.phaseGate_exp_mem_unitaryGroup φ)) + +/-- **The wire-`t` phase gate acts diagonally, scaling by `e^{iφ}` when wire `t` is set.** +`phaseWireEvolution n t φ |finFunctionFinEquiv f⟩ = (e^{iφ})^{f t} · |finFunctionFinEquiv f⟩`: +the phase gate `P(φ)` on wire `t` leaves the computational-basis ket `|f⟩` unchanged and multiplies +it by `e^{iφ}` exactly when the wire-`t` bit `f t` is `1` (and by `1` when it is `0`). Because +`P(φ) = diag(1, e^{iφ})` is diagonal, the two-term column superposition of the general single-wire +bridge `quditGate_singleQubitOnWire_evolvePure_quditBasis` collapses to a single diagonal term. -/ +theorem phaseWireEvolution_evolvePure_quditBasis (n : ℕ) (t : Fin n) (φ : ℝ) (f : Fin n → Fin 2) : + ((phaseWireEvolution n t φ).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = Complex.exp ((φ : ℂ) * Complex.I) ^ (f t : ℕ) • + (quditBasis (finFunctionFinEquiv f)).vec := by + rw [phaseWireEvolution, + quditGate_singleQubitOnWire_evolvePure_quditBasis finFunctionFinEquiv t + (Concrete.phaseGate_exp_mem_unitaryGroup φ) f, + Fin.sum_univ_two] + rcases (show f t = 0 ∨ f t = 1 by omega) with hft | hft <;> + · have h : Function.update f t (f t) = f := Function.update_eq_self t f + rw [hft] at h ⊢ + rw [h] + simp only [Concrete.phaseGate, Matrix.cons_val', Matrix.cons_val_zero, Matrix.cons_val_one, + Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.of_apply, Fin.val_zero, Fin.val_one, + pow_zero, pow_one] + module + +/-- **A product of single-wire phase gates acts by the product of the per-wire phases.** For any +list `l` of wires and per-wire angles `φ`, the composed circuit `∏_{t ∈ l} P(φ t)ₜ` scales the +computational-basis ket `|f⟩` by `∏_{t ∈ l} (e^{iφ t})^{f t}` — the phases of the wires carrying a +`1` multiply, leaving `|f⟩` fixed. This is the **phase-gradient** identity underlying Problem 4.1's +`n`-gate phase layer: each of the `n` single-qubit phase gates contributes one factor, and on the +ancilla index `f(x)` they multiply to the total computable phase. (`Evolution` is only a `Monoid`, +so the composed circuit is the `List.prod` over an ordering of the wires; the gates are diagonal and +so in fact commute.) Proved by induction on `l`: each factor is diagonal on `|f⟩` +(`phaseWireEvolution_evolvePure_quditBasis`), so it commutes past the accumulated scalar +(`map_smul`) and multiplies in its own phase. -/ +theorem phaseWireEvolution_listProd_op_quditBasis (n : ℕ) (φ : Fin n → ℝ) (l : List (Fin n)) + (f : Fin n → Fin 2) : + ((l.map (fun t => phaseWireEvolution n t (φ t))).prod).op + (quditBasis (finFunctionFinEquiv f)).vec + = (l.map (fun t => Complex.exp ((φ t : ℂ) * Complex.I) ^ (f t : ℕ))).prod • + (quditBasis (finFunctionFinEquiv f)).vec := by + induction l with + | nil => simp only [List.map_nil, List.prod_nil, one_smul]; rfl + | cons a l ih => + rw [List.map_cons, List.prod_cons, List.map_cons, List.prod_cons, Evolution.mul_def, + Evolution.comp_op, ContinuousLinearMap.comp_apply, ih, map_smul, ← Evolution.evolvePure_vec, + phaseWireEvolution_evolvePure_quditBasis, smul_smul, mul_comm] + +/-- **The phase-gradient layer** `∏_{t phaseWireEvolution n t (φ t))).prod + +/-- **The phase-gradient layer acts diagonally, by the product of the per-wire phases.** +`phaseGradientLayer n φ |f⟩ = (∏_{t} (e^{iφ t})^{f t}) · |f⟩`: the `n`-gate layer leaves the +computational-basis ket `|f⟩ = |finFunctionFinEquiv f⟩` fixed and scales it by the product of the +phases `e^{iφ t}` over exactly the wires `t` carrying a `1`. This is the `List.finRange n` +instance of the phase-gradient product law `phaseWireEvolution_listProd_op_quditBasis`, with the +list product rewritten as the (order-independent) `Finset` product `∏ t, …` over all wires. It is +the diagonal eigenvalue that identifies `phaseGradientLayer` with a `diagPhase` layer once the +per-wire angles are summed against the bit-decomposition of the index. -/ +theorem phaseGradientLayer_op_apply_quditBasis (n : ℕ) (φ : Fin n → ℝ) (f : Fin n → Fin 2) : + (phaseGradientLayer n φ).op (quditBasis (finFunctionFinEquiv f)).vec + = (∏ t, Complex.exp ((φ t : ℂ) * Complex.I) ^ (f t : ℕ)) • + (quditBasis (finFunctionFinEquiv f)).vec := by + rw [phaseGradientLayer, phaseWireEvolution_listProd_op_quditBasis n φ (List.finRange n) f, + ← List.ofFn_eq_map, List.prod_ofFn] + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PhasedPlus.lean b/LeanPool/AxQM/Postulates/API/PhasedPlus.lean new file mode 100644 index 0000000000..0eefaae9d5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PhasedPlus.lean @@ -0,0 +1,125 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RelativePhase +public import LeanPool.AxQM.Postulates.API.ControlledUnitaryDecomposition +public import LeanPool.AxQM.Postulates.API.CnotXBasis + +/-! +# AxQM.Postulates.API — the phased-plus qubit state `|+_θ⟩` + +The single-qubit **phased-plus** (equatorial) state + + `|+_θ⟩ = (|0⟩ + e^{iθ}|1⟩)/√2`, + +the equal-magnitude superposition of `|0⟩` and `|1⟩` with a relative phase `e^{iθ}` on `|1⟩`. It is +the state a phase-shift gate `P(θ)` produces from `|+⟩`, and it appears throughout interferometry +and phase estimation: after the controlled-power sequence of a phase-estimation circuit each control +wire carries such a state, its phase encoding the eigenvalue read out (the "phase gradient"). + +## What is formalised + +* `qubitPhasePlus θ` — the state `|+_θ⟩`, defined as `P(θ)|+⟩` + (`(phaseShiftGate θ).evolvePure qubitPlus`) so that its normalization is **inherited** from + `qubitPlus` (a gate applied to a unit vector), with no separate `{ vec := …, normalized := … }` + obligation. Its special cases are `qubitPlus` (`θ = 0`), `qubitMinus` (`θ = π`), + `qubitPlusI` (`θ = π/2`). +* `qubitPhasePlus_vec` — the computational-basis expansion `|+_θ⟩ = (1/√2)(|0⟩ + e^{iθ}|1⟩)`, from + `qubitPlus`'s expansion `(1/√2)(|0⟩ + |1⟩)` and the phase gate's diagonal action `P(θ)|0⟩ = |0⟩`, + `P(θ)|1⟩ = e^{iθ}|1⟩`. +* `qubitPhasePlus_zero` — `|+_0⟩ = |+⟩`, the phase-free base case. + +The state `qubitPhasePlus` is used, e.g., for the phase-gradient register `qtowerPhaseGrad` in +`AxQM/Core/QtowerPhaseGradient.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The phased-plus qubit state** `|+_θ⟩ = (|0⟩ + e^{iθ}|1⟩)/√2`: the equal-magnitude +superposition of `|0⟩` and `|1⟩` with relative phase `e^{iθ}` on `|1⟩`, defined as the image of +`|+⟩` under the phase-shift gate `P(θ)` (`(phaseShiftGate θ).evolvePure qubitPlus`). +Building it as `P(θ)|+⟩` (a gate applied to the unit vector `|+⟩`) makes normalization automatic — +no explicit norm proof. Generalises the fixed-phase states `qubitPlus` (`θ = 0`), `qubitMinus` +(`θ = π`) and `qubitPlusI` (`θ = π/2`). -/ +def qubitPhasePlus (θ : ℝ) : PureState qubit := (phaseShiftGate θ).evolvePure qubitPlus + +/-- **Computational-basis expansion of the phased-plus state:** +`|+_θ⟩ = (1/√2)(|0⟩ + e^{iθ}|1⟩)`. From `qubitPlus = (1/√2)(|0⟩ + |1⟩)` and the phase gate's +diagonal action `P(θ)|0⟩ = |0⟩`, `P(θ)|1⟩ = e^{iθ}|1⟩` (`phaseShiftGate_op_apply_qubitBasis`). -/ +theorem qubitPhasePlus_vec (θ : ℝ) : + (qubitPhasePlus θ).vec + = Concrete.invSqrt2 • ((qubitBasis 0).vec + + Complex.exp ((θ : ℂ) * Complex.I) • (qubitBasis 1).vec) := by + rw [qubitPhasePlus, Evolution.evolvePure_vec, qubitPlus_vec_eq_smul_add, map_smul, map_add, + phaseShiftGate_op_apply_qubitBasis, phaseShiftGate_op_apply_qubitBasis] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] + rw [one_smul] + +/-- **The phase-free phased-plus state is `|+⟩`:** `|+_0⟩ = |+⟩`, since `P(0) = 1` fixes `|+⟩`. -/ +@[simp] theorem qubitPhasePlus_zero : qubitPhasePlus 0 = qubitPlus := by + apply PureState.ext + rw [qubitPhasePlus_vec, qubitPlus_vec_eq_smul_add] + simp only [Complex.ofReal_zero, zero_mul, Complex.exp_zero] + erw [one_smul] + +/-- **Amplitude of the phased-plus state against the computational basis:** +`⟨c|+_ψ⟩ = (1/√2)·e^{iψc}` — the `c`-th coefficient of `|+_ψ⟩ = (1/√2)(|0⟩ + e^{iψ}|1⟩)`. Reads off +`⟨0|+_ψ⟩ = 1/√2` and `⟨1|+_ψ⟩ = (1/√2)e^{iψ}` from `qubitPhasePlus_vec` and the orthonormality of +`|0⟩, |1⟩` (`qubitBasis_inner_qubitBasis`). The single-wire amplitude behind the product +representation of a tower phase gradient (N&C Problem 5.1, eq. 5.4). -/ +theorem qubitPhasePlus_inner_qubitBasis (ψ : ℝ) (c : Fin 2) : + inner ℂ (qubitBasis c).vec (qubitPhasePlus ψ).vec + = (Concrete.invSqrt2 : ℂ) * Complex.exp ((ψ : ℂ) * Complex.I * (c : ℕ)) := by + rw [qubitPhasePlus_vec, inner_smul_right, inner_add_right, inner_smul_right, + qubitBasis_inner_qubitBasis, qubitBasis_inner_qubitBasis] + fin_cases c <;> simp + +/-- **The phased-plus state is `2π`-periodic in its phase:** `|+_{2πm + α}⟩ = |+_α⟩` for `m : ℕ`, +since `e^{i(2πm + α)} = e^{iα}` (`Complex.exp_nat_mul_two_pi_mul_I`). A general property of +`qubitPhasePlus`: two angles differing by an integer multiple of `2π` name the *same* +equatorial state. Used, e.g., to identify quantum-Fourier-transform output wires whose per-wire +phases agree only modulo `2π` (`qftTowerWirePhase_castSucc_qubitPhasePlus`, N&C Problem 5.2). -/ +theorem qubitPhasePlus_two_pi_nat_add (m : ℕ) (α : ℝ) : + qubitPhasePlus (2 * Real.pi * m + α) = qubitPhasePlus α := by + apply PureState.ext + rw [qubitPhasePlus_vec, qubitPhasePlus_vec, + show ((2 * Real.pi * m + α : ℝ) : ℂ) * Complex.I + = (m : ℂ) * (2 * Real.pi * Complex.I) + (α : ℂ) * Complex.I by push_cast; ring, + Complex.exp_add, Complex.exp_nat_mul_two_pi_mul_I, one_mul] + +/-- **`|−⟩` is the phased-plus state at `θ = π`:** `qubitMinus = |+_π⟩`, since +`|+_π⟩ = (|0⟩ + e^{iπ}|1⟩)/√2 = (|0⟩ − |1⟩)/√2 = |−⟩` (`Complex.exp_pi_mul_I` gives `e^{iπ} = −1`). +Makes the "`qubitMinus` is the `θ = π` special case of `qubitPhasePlus`" claim formal, the companion +of `qubitPhasePlus_zero` (`|+_0⟩ = |+⟩`). -/ +theorem qubitMinus_eq_qubitPhasePlus_pi : qubitMinus = qubitPhasePlus Real.pi := by + apply PureState.ext + rw [qubitPhasePlus_vec, qubitMinus_vec_eq_smul_add, Complex.exp_pi_mul_I] + +/-- **The Hadamard sends a computational basis state to a phased-plus state:** `H|d⟩ = |+_{πd}⟩`. +`H|0⟩ = |+⟩ = |+_0⟩` (`hadamardGate_evolvePure_qubitBasis_zero`, `qubitPhasePlus_zero`) and +`H|1⟩ = |−⟩ = |+_π⟩` (`hadamardGate_evolvePure_qubitBasis_one`, `qubitMinus_eq_qubitPhasePlus_pi`), +uniformly `|+_{π·d}⟩`. The single-qubit state the quantum Fourier transform's head Hadamard produces +from a computational input before the head control wire's controlled-`Rₖ` phase cascade acts on it +(N&C §5.1 Figure 5.1 / Problem 5.2). -/ +theorem hadamardGate_evolvePure_qubitBasis_qubitPhasePlus (d : Fin 2) : + hadamardGate.evolvePure (qubitBasis d) = qubitPhasePlus (Real.pi * ((d : ℕ) : ℝ)) := by + fin_cases d + · simp only [Fin.mk_zero, Nat.cast_zero, mul_zero, + hadamardGate_evolvePure_qubitBasis_zero, qubitPhasePlus_zero] + · simp only [Fin.mk_one, Nat.cast_one, mul_one, + hadamardGate_evolvePure_qubitBasis_one, qubitMinus_eq_qubitPhasePlus_pi] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PiEighthGate.lean b/LeanPool/AxQM/Postulates/API/PiEighthGate.lean new file mode 100644 index 0000000000..ed057a5d9a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PiEighthGate.lean @@ -0,0 +1,81 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Concrete.PiEighthGate + +/-! +# AxQM.Postulates.API — the π/8 (T) gate and `R_z` as qubit evolutions + +The single-qubit gates of Nielsen & Chuang's Exercise 4.3: the π/8 gate `T` and the `z`-axis +rotation `R_z(θ)`, each promoted from its concrete `2 × 2` unitary matrix (`Concrete.tMatrix`, +`Concrete.rotZ`) to an `Evolution` of the `qubit`, alongside `hadamardGate`. + +* `tGate`, `rotZGate θ` — the gates as `Evolution qubit`. An `Evolution` bundles the + unitarity obligation, discharged from the matrix-level unitarity + (`Concrete.tMatrix_mem_unitaryGroup`, `Concrete.rotZ_mem_unitaryGroup`) transported through the + `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`, exactly as for `hadamardGate`. +* `tGate_op_eq_expPiDivEight_smul_rotZGate` — the **operator-level statement of Exercise 4.3**: + `T = exp(iπ/8) • R_z(π/4)` at the operator level (`Evolution.op`), the image under + `Matrix.toEuclideanCLM` of the matrix identity `Concrete.tMatrix_eq_expPiDivEight_smul_rotZ`. + +The physical consequence — that `T` and `R_z(π/4)` induce the *same* state channel — follows from +the general **global-phase-invariance of the channel** lemma +`Evolution.evolve_eq_of_op_eq_phase_smul` (in `AxQM/Postulates/API/Evolution.lean`, +since it does not depend on the π/8 gate): two evolutions whose operators +differ by a unit-modulus scalar induce the same `evolve`. + +The physical statement that `T` and `R_z(π/4)` act identically on all states, in terms of +`Evolution.evolve`, is in [upstream `AxQM/NC/Ch4/Exercise4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_3.lean). `rotZGate` is a general `z`-rotation gate. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **π/8 (T) gate** `T` as a closed-system evolution of the `qubit` (Nielsen & Chuang, +eq. 4.2). Its operator is the concrete matrix `Concrete.tMatrix` promoted through the `⋆`-algebra +`Matrix.toEuclideanCLM`; unitarity — the `Evolution` proof obligation — is transported from +`Concrete.tMatrix_mem_unitaryGroup`. -/ +def tGate : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.tMatrix + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) Concrete.tMatrix_mem_unitaryGroup + +@[simp] +theorem tGate_op : tGate.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.tMatrix := rfl + +/-- The **`z`-axis rotation gate** `R_z(θ) = exp(-iθZ/2)` as a closed-system evolution of the +`qubit` (Nielsen & Chuang, eq. 4.6). Its operator is the concrete rotation matrix `Concrete.rotZ θ` +promoted through `Matrix.toEuclideanCLM`; unitarity is from `Concrete.rotZ_mem_unitaryGroup`. -/ +def rotZGate (θ : ℝ) : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotZ θ) + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) (Concrete.rotZ_mem_unitaryGroup θ) + +@[simp] +theorem rotZGate_op (θ : ℝ) : + (rotZGate θ).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.rotZ θ) := rfl + +/-- **Nielsen & Chuang Exercise 4.3 at the operator level** (eq. 4.3): the π/8 gate equals +`R_z(π/4)` up to the global phase `exp(iπ/8)`, `T = exp(iπ/8) • R_z(π/4)`. The image under the +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM` (which is `ℂ`-linear, so it preserves the scalar) +of the matrix identity `Concrete.tMatrix_eq_expPiDivEight_smul_rotZ`. -/ +theorem tGate_op_eq_expPiDivEight_smul_rotZGate : + tGate.op = Complex.exp ((Real.pi / 8 : ℝ) * Complex.I) • (rotZGate (Real.pi / 4)).op := by + rw [tGate_op, rotZGate_op, Concrete.tMatrix_eq_expPiDivEight_smul_rotZ] + exact map_smul _ _ _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PiTensorEigenbasis.lean b/LeanPool/AxQM/Postulates/API/PiTensorEigenbasis.lean new file mode 100644 index 0000000000..3ff28f7cf8 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PiTensorEigenbasis.lean @@ -0,0 +1,102 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductMap + +/-! +# AxQM.Postulates.API — the product eigenbasis of a family of states `⨂ᵢ ρᵢ` + +For a finite family of quantum states `ρ : (i : ι) → State (S i)`, the indexed product state +`⨂ₚ i, ρ i` (`State.piTensor`, `AxQM/Postulates/PiTensorState.lean`) is diagonal in the **product +eigenbasis** built from the individual spectral eigenbases: if each `ρ i = ∑ₖ λᵢₖ |eᵢₖ⟩⟨eᵢₖ|`, +then the elementary tensors `|e_κ⟩ = ⨂ᵢ |e_{i,κᵢ}⟩` (indexed by a choice `κ : (i : ι) → Fin dᵢ` +of an eigenvector in each factor) are eigenvectors of `⨂ₚ i, ρ i` with eigenvalue the product +`∏ᵢ λ_{i,κᵢ}`: + +`(⨂ₚ i, ρ i) |e_κ⟩ = (∏ᵢ λ_{i,κᵢ}) |e_κ⟩`. + +This is the **distinct-factor generalisation** of the tensor-power spectral decomposition +`State.tensorPowEigenbasis` / `State.tensorPow_op_apply_tensorPowEigenbasis` +(`AxQM/Postulates/API/TensorPowState.lean`), which handles only the constant family `ρ^⊗n` +(all factors equal). It is the eigenstructure Nielsen & Chuang's HSW achievability argument +(Theorem 12.8, Eqs. 12.74–12.75) needs for the **conditional typical subspace** of a product +codeword `σ_M = σ_{M₁} ⊗ ⋯ ⊗ σ_{Mₙ}`, whose factors `σ_{Mᵢ} = E(ρ_{Mᵢ})` are in general +*different* output states drawn from the input ensemble — so its typical subspace cannot be read +off `tensorPowEigenbasis` (which needs one repeated state). + +## Main definitions and results + +* `AxQM.State.piTensorEigenbasis` — the product eigenbasis `⨂ᵢ |e_{i,κᵢ}⟩` of + `⨂ₚ i, ρ i`, an orthonormal basis of `(QSystem.piTensor S).space` indexed by the dependent + sequences `κ : (i : ι) → Fin (dim (S i).space)`. +* `AxQM.State.piTensorEigenbasis_apply` — its value: the elementary tensor of the + per-factor eigenvectors. +* `AxQM.State.piTensor_op_apply_piTensorEigenbasis` — the spectral action + `(⨂ₚ i, ρ i) |e_κ⟩ = (∏ᵢ λ_{i,κᵢ}) |e_κ⟩`, with `λ_{i,·} = (ρ i).eigenvalueDist`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {S : ι → QSystem} + +/-- The **product eigenbasis** of the indexed product state `⨂ₚ i, ρ i`: the elementary tensor +`⨂ᵢ |e_{i,κᵢ}⟩` of each factor's canonical spectral eigenbasis `(ρ i).eigenbasis` +(`OrthonormalBasis.piTensorProduct`), an orthonormal basis of `(QSystem.piTensor S).space` indexed +by the dependent sequences `κ : (i : ι) → Fin (dim (S i).space)`. The distinct-factor +generalisation of `State.tensorPowEigenbasis` (which is this basis for the constant family +`fun _ ↦ ρ`). -/ +def State.piTensorEigenbasis (ρ : (i : ι) → State (S i)) : + OrthonormalBasis ((i : ι) → Fin (Module.finrank ℂ (S i).space)) ℂ + (QSystem.piTensor S).space := + OrthonormalBasis.piTensorProduct fun i => (ρ i).eigenbasis + +/-- The product eigenbasis vector at a dependent sequence `κ` is the elementary tensor +`⨂ᵢ |e_{i,κᵢ}⟩` of the per-factor eigenvectors. -/ +theorem State.piTensorEigenbasis_apply (ρ : (i : ι) → State (S i)) + (κ : (i : ι) → Fin (Module.finrank ℂ (S i).space)) : + State.piTensorEigenbasis ρ κ = ⨂ₜ[ℂ] i, (ρ i).eigenbasis (κ i) := + OrthonormalBasis.piTensorProduct_apply (fun i => (ρ i).eigenbasis) κ + +/-- **Spectral action of `⨂ₚ i, ρ i`** (Nielsen & Chuang, the eigenvalues underlying the HSW +conditional typical subspace, Eqs. 12.74–12.75). The product eigenvector +`|e_κ⟩ = ⨂ᵢ |e_{i,κᵢ}⟩` is an eigenvector of the indexed product state with eigenvalue the product +`∏ᵢ λ_{i,κᵢ}` of the corresponding per-factor eigenvalues: + +`(⨂ₚ i, ρ i) |e_κ⟩ = (∏ᵢ λ_{i,κᵢ}) |e_κ⟩`, `λ_{i,·} = (ρ i).eigenvalueDist`. + +The operator acts factor-by-factor via `PiTensorProduct.mapCLM_tprod` (`State.piTensor_op` unfolds +`⨂ₚ i, ρ i` to `PiTensorProduct.mapCLM (fun i ↦ (ρ i).op)`); each factor +`(ρ i).op |e_{i,κᵢ}⟩ = λ_{i,κᵢ} |e_{i,κᵢ}⟩` (`State.op_apply_eigenbasis`); and the scalars pull out +of the elementary tensor all at once by multilinearity (`MultilinearMap.map_smul_univ`). The +distinct-factor generalisation of `State.tensorPow_op_apply_tensorPowEigenbasis`. -/ +theorem State.piTensor_op_apply_piTensorEigenbasis (ρ : (i : ι) → State (S i)) + (κ : (i : ι) → Fin (Module.finrank ℂ (S i).space)) : + (State.piTensor ρ).op (State.piTensorEigenbasis ρ κ) = + ((∏ i, (ρ i).eigenvalueDist (κ i) : ℝ) : ℂ) • State.piTensorEigenbasis ρ κ := by + rw [State.piTensorEigenbasis_apply, State.piTensor_op] + calc (PiTensorProduct.mapCLM fun i => (ρ i).op) (⨂ₜ[ℂ] i, (ρ i).eigenbasis (κ i)) + = ⨂ₜ[ℂ] i, (ρ i).op ((ρ i).eigenbasis (κ i)) := + PiTensorProduct.mapCLM_tprod (fun i => (ρ i).op) _ + _ = ⨂ₜ[ℂ] i, (((ρ i).eigenvalueDist (κ i) : ℂ) • (ρ i).eigenbasis (κ i)) := by + simp only [State.op_apply_eigenbasis, State.eigenvalueDist] + _ = (∏ i, ((ρ i).eigenvalueDist (κ i) : ℂ)) • ⨂ₜ[ℂ] i, (ρ i).eigenbasis (κ i) := + (PiTensorProduct.tprod ℂ).map_smul_univ _ _ + _ = ((∏ i, (ρ i).eigenvalueDist (κ i) : ℝ) : ℂ) • ⨂ₜ[ℂ] i, (ρ i).eigenbasis (κ i) := by + rw [Complex.ofReal_prod] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PiTensorSuccHead.lean b/LeanPool/AxQM/Postulates/API/PiTensorSuccHead.lean new file mode 100644 index 0000000000..046c204526 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PiTensorSuccHead.lean @@ -0,0 +1,58 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TensorPowSplit + +/-! +# Head-peel conjugation for the indexed product operator + +The head-peel isometry `QSystem.tensorPowSuccHead S n : S ^⊗ₛ (n+1) ≃ₛ S ⊗ S ^⊗ₛ n` +(`AxQM/Postulates/API/TensorPowSplit.lean`) acts on the state vectors. This file records how it +conjugates the elementary *product operator* `PiTensorProduct.mapCLM` — the operator-level fact +behind the `State`-level product-state recursion `State.tmul_piTensor_congr_tensorPowSuccHead_symm` +(`AxQM/Core/PiTensorSuccHead.lean`), which lifts it to the product state `State.piTensor`. +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +/-- **Operator-level head-peel conjugation.** The head-peel isometry +`tensorPowSuccHeadIsometry S n` conjugates the elementary product operator +`(g 0) ⊗ (⨂ⱼ g j.succ)` on `S.space ⊗ (⨂ⱼ S.space)` back to the `(n+1)`-fold product operator +`⨂ᵢ g i` on `⨂ᵢ S.space`: + +`(tensorPowSuccHeadIsometry S n).symm.conj (mapL (g 0) (⨂ⱼ g j.succ)) = ⨂ᵢ g i`. + +The operator engine behind the `State`-level recursion +`State.tmul_piTensor_congr_tensorPowSuccHead_symm`. Stated on the raw `PiTensorProduct` space +`⨂[ℂ] _ : Fin (n+1), S.space` — whose module/inner instances are the canonical `PiTensorProduct` +ones — so the tensor extensionality `ContinuousLinearMap.ext_tprod` applies without meeting the +re-bundled instances of the `QSystem.piTensor` space. Proved by evaluating both sides on an +elementary tensor `⨂ᵢ vᵢ`: the head-peel maps it to `v 0 ⊗ (⨂ⱼ v j.succ)`, `mapL`/`mapCLM` act +factorwise, and the inverse head-peel reassembles the `cons` (`Fin.cons_self_tail`). -/ +theorem QSystem.tensorPowSuccHeadIsometry_symm_conj (S : QSystem) (n : ℕ) + (g : Fin (n + 1) → S.space →L[ℂ] S.space) : + (QSystem.tensorPowSuccHeadIsometry S n).symm.conjStarAlgEquiv + (TensorProduct.mapL (g 0) (PiTensorProduct.mapCLM fun j => g j.succ)) + = PiTensorProduct.mapCLM g := by + apply ContinuousLinearMap.ext_tprod + intro v + erw [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, LinearIsometryEquiv.symm_symm, + QSystem.tensorPowSuccHead_toIsometry_tprod, TensorProduct.mapL_tmul, + PiTensorProduct.mapCLM_tprod, PiTensorProduct.mapCLM_tprod, + QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod] + exact congrArg (PiTensorProduct.tprod ℂ) (Fin.cons_self_tail fun i => g i (v i)) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PrettyGoodDecoder.lean b/LeanPool/AxQM/Postulates/API/PrettyGoodDecoder.lean new file mode 100644 index 0000000000..e3cbaa3d89 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PrettyGoodDecoder.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.AvgOutputTypicalSubspace +public import LeanPool.AxQM.Postulates.API.SquareRootMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PrettyGoodMeasurement + +/-! +# The pretty-good decoding measurement of a product-state codebook (N&C Thm 12.8, Box 12.5) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, Box 12.5, eq. (12.78)), Bob decodes the `n`-use channel output of a length-`n` +product-state codebook `w : Fin K → Fin n → α` with the **pretty-good (square-root) measurement** of +the conjugated projector family + +`A_{M'} = P · P_{M'} · P`, + +where `P = avgOutputTypicalProj …` is the average-output ε-typical subspace projector and +`P_{M'} = condTypicalSubspaceProj …` is the conditional typical projector of codeword `M'`. + +## Main definition + +* `AxQM.prettyGoodDecoder` — the measurement + `Measurement.ofPOVM (POVM.prettyGood A)` on the `n`-fold output system `S ^⊗ₛ n`, with outcome + `some M` decoding message `M` and `none` the inconclusive element. The family positivity + `0 ≤ A_{M'}` needed by `POVM.prettyGood` is `State.avgOutputTypicalProj_condTypical_conj_nonneg`. + +It is used in the product-state code `ProductStateCode.prettyGood`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eq. (12.78). +-/ + +@[expose] public section + +open scoped BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The pretty-good decoding measurement of a product-state codebook** (Nielsen & Chuang, +Theorem 12.8, Box 12.5, eq. (12.78)). For an input ensemble `{pₐ, ρₐ}`, channel `E`, block length +`n`, entropy parameter `s`, threshold `ε`, and a codebook `w : Fin K → Fin n → α`, this is Bob's +decoding measurement `Measurement.ofPOVM (POVM.prettyGood A)` of the conjugated projector family +`A_{M'} = P · P_{M'} · P` — `P = avgOutputTypicalProj …` the average-output ε-typical projector, +`P_{M'} = condTypicalSubspaceProj …` the conditional typical projector of codeword `M'` — on the +`n`-fold output system, with `some M` decoding message `M` and `none` the inconclusive outcome. + +The family positivity `0 ≤ A_{M'}` required by `POVM.prettyGood` is +`State.avgOutputTypicalProj_condTypical_conj_nonneg`. -/ +def prettyGoodDecoder (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (s ε : ℝ) {K : ℕ} + (w : Fin K → Fin n → α) : Measurement (Option (Fin K)) (S.tensorPow n) := + Measurement.ofPOVM (POVM.prettyGood + (fun M' => (State.avgOutputTypicalProj p hp hsum E ρ n ε).comp + ((State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε).comp + (State.avgOutputTypicalProj p hp hsum E ρ n ε))) + (fun M' => State.avgOutputTypicalProj_condTypical_conj_nonneg p hp hsum E ρ n ε + (fun i => E (ρ (w M' i))) s ε)) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ProjectiveMeasurement.lean b/LeanPool/AxQM/Postulates/API/ProjectiveMeasurement.lean new file mode 100644 index 0000000000..fc5ea55823 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ProjectiveMeasurement.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import Mathlib.Analysis.CStarAlgebra.Projection +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousLinearMap + +/-! +# AxQM — projective measurements (N&C §2.2.5 / Exercise 2.62) + +A **projective (von Neumann) measurement** is the special case of the general measurement +postulate (Postulate 3, `Measurement`) in which the measurement +operators are *orthogonal projectors*. Nielsen–Chuang §2.2.5 describes it by projectors `Pₘ` +with + + `Pₘ Pₘ' = δₘₘ' Pₘ` and `∑ₘ Pₘ = I`. + +This file adds the vocabulary a projective measurement needs: + +* `Measurement.IsProjective` — the predicate carving out the projective measurements among all + measurements: every operator `Mᵢ` is a star projection (self-adjoint idempotent — an + orthogonal projector), and distinct operators are orthogonal (`Mᵢ Mⱼ = 0` for `i ≠ j`). This + is exactly the off-diagonal/diagonal split of N&C's `Pₘ Pₘ' = δₘₘ' Pₘ`. +* `Measurement.IsSelfPOVM` — the hypothesis of N&C Exercise 2.62: the measurement operators + coincide with their POVM effects, `Mᵢ = Eᵢ = Mᵢ† Mᵢ` (N&C: "all the POVM elements are the + same as the measurement operators themselves"). + +Two structural facts complete the correspondence with N&C's definition: + +* `Measurement.sum_op_eq_one_of_isStarProjection` / `Measurement.IsProjective.sum_op_eq_one` — + the resolution of the identity `∑ᵢ Mᵢ = 1` (N&C's `∑ₘ Pₘ = I`). It is *automatic* for a + measurement whose operators are projectors: the structural completeness `∑ᵢ Mᵢ† Mᵢ = 1` + collapses to `∑ᵢ Mᵢ = 1` because `Mᵢ† Mᵢ = Mᵢ` for a projector. +* `Measurement.mul_op_eq_zero_of_isStarProjection` — mutual orthogonality is likewise automatic: + projectors that resolve the identity are pairwise orthogonal. The short proof is C*-algebraic: + `Mᵢ ≤ 1 - Mⱼ` (the other projectors are positive and `∑ = 1`), and for star projections + `p ≤ q ↔ p q = p` (`IsStarProjection.le_iff_mul_eq_left`), giving `Mᵢ(1 - Mⱼ) = Mᵢ`, i.e. + `Mᵢ Mⱼ = 0`. This uses the C*-algebra / Loewner-order structure of `S →L[ℂ] S`. + +Exercise 2.62 — `IsSelfPOVM → IsProjective`, stated with these predicates — is in +[upstream `AxQM/NC/Ch2/Exercise2_62.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_62.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- A measurement is **projective** (von Neumann) when every operator `Mᵢ` is a star projection +(`IsStarProjection` — a self-adjoint idempotent, an orthogonal projector). This is the single +minimal condition carving out the projective measurements among all general measurements +(Postulate 3): the remaining defining data of N&C §2.2.5 is then automatic and supplied as +derived theorems, on equal footing — + +* `IsProjective.orthogonal` : `Mᵢ Mⱼ = 0` for `i ≠ j` (the off-diagonal of `Pₘ Pₘ' = δₘₘ' Pₘ`; + the `m = m'` diagonal is the idempotence already inside `IsStarProjection`); +* `IsProjective.sum_op_eq_one` : `∑ᵢ Mᵢ = 1` (N&C's `∑ₘ Pₘ = I`). + +Both hold for *any* `Measurement` whose operators are projectors — orthogonality from the +`m.complete` completeness relation, and the resolution of the identity likewise — so neither is a +bundled hypothesis; they are theorems, and together with the definition they are exactly N&C's +`Pₘ Pₘ' = δₘₘ' Pₘ`, `∑ₘ Pₘ = I`. -/ +def IsProjective (m : Measurement ι S) : Prop := ∀ i, IsStarProjection (m.op i) + +/-- The measurement operators **coincide with their POVM effects**: `Mᵢ = Eᵢ = Mᵢ† Mᵢ` for every +outcome (N&C Exercise 2.62 hypothesis). Equivalently the induced POVM `toPOVM` has the operators +themselves as its elements. -/ +def IsSelfPOVM (m : Measurement ι S) : Prop := ∀ i, m.op i = m.toPOVM.elements i + +/-- **Resolution of the identity from projectors.** If every operator of a measurement is a star +projection, they sum to the identity, `∑ᵢ Mᵢ = 1` (N&C's `∑ₘ Pₘ = I`). This is automatic: the +structural completeness relation `∑ᵢ Mᵢ† Mᵢ = 1` collapses because `Mᵢ† Mᵢ = Mᵢ` for a projector +(self-adjoint `Mᵢ† = Mᵢ`, idempotent `Mᵢ Mᵢ = Mᵢ`). -/ +theorem sum_op_eq_one_of_isStarProjection {m : Measurement ι S} + (hsp : ∀ i, IsStarProjection (m.op i)) : ∑ i, m.op i = 1 := by + have key : ∀ i, (adjoint (m.op i)).comp (m.op i) = m.op i := fun i => by + rw [← ContinuousLinearMap.star_eq_adjoint, (hsp i).isSelfAdjoint.star_eq, + ← ContinuousLinearMap.mul_def] + exact (hsp i).isIdempotentElem + calc ∑ i, m.op i = ∑ i, (adjoint (m.op i)).comp (m.op i) := + Finset.sum_congr rfl fun i _ => (key i).symm + _ = 1 := m.complete + +/-- **Projectors resolving the identity are mutually orthogonal.** If every operator of a +measurement is a star projection, distinct operators are orthogonal, `Mᵢ Mⱼ = 0` for `i ≠ j`. +Proof (C*-algebraic, in the C*-algebra `S →L[ℂ] S` with the Loewner order): from +`sum_op_eq_one_of_isStarProjection`, `∑ₖ Mₖ = 1`, so `Mᵢ ≤ ∑_{k ≠ j} Mₖ = 1 - Mⱼ` since the +projectors are positive; and for star projections `p ≤ q ↔ p q = p` +(`IsStarProjection.le_iff_mul_eq_left`), giving `Mᵢ(1 - Mⱼ) = Mᵢ`, i.e. `Mᵢ Mⱼ = 0`. -/ +theorem mul_op_eq_zero_of_isStarProjection {m : Measurement ι S} + (hsp : ∀ i, IsStarProjection (m.op i)) {i j : ι} (hij : i ≠ j) : + m.op i * m.op j = 0 := by + classical + have hsum : ∑ k, m.op k = 1 := sum_op_eq_one_of_isStarProjection hsp + have hle : m.op i ≤ 1 - m.op j := by + have h1 : m.op i ≤ ∑ k ∈ Finset.univ.erase j, m.op k := + Finset.single_le_sum (fun k _ => (hsp k).nonneg) + (Finset.mem_erase.mpr ⟨hij, Finset.mem_univ i⟩) + rwa [Finset.sum_erase_eq_sub (Finset.mem_univ j), hsum] at h1 + have hmul := ((hsp i).le_iff_mul_eq_left (hsp j).one_sub).mp hle + rw [mul_sub, mul_one] at hmul + exact sub_eq_self.mp hmul + +/-- **Orthogonality of a projective measurement:** distinct operators annihilate, `Mᵢ Mⱼ = 0` for +`i ≠ j` — the off-diagonal of N&C's `Pₘ Pₘ' = δₘₘ' Pₘ` (the diagonal `m = m'` is the idempotence +inside `IsProjective`). Automatic from the projectors resolving the identity +(`mul_op_eq_zero_of_isStarProjection`). -/ +theorem IsProjective.orthogonal {m : Measurement ι S} (h : m.IsProjective) {i j : ι} + (hij : i ≠ j) : m.op i * m.op j = 0 := + mul_op_eq_zero_of_isStarProjection h hij + +/-- **Resolution of the identity for a projective measurement:** `∑ᵢ Mᵢ = 1` (N&C's `∑ₘ Pₘ = I`), +the second defining property of a projective measurement alongside `Pₘ Pₘ' = δₘₘ' Pₘ`. Automatic +(`sum_op_eq_one_of_isStarProjection`), symmetric with `IsProjective.orthogonal`. -/ +theorem IsProjective.sum_op_eq_one {m : Measurement ι S} (h : m.IsProjective) : + ∑ i, m.op i = 1 := + sum_op_eq_one_of_isStarProjection h + +/-- **A basis measurement is projective (von Neumann).** The measurement `ofOrthonormalBasis b` +has each operator `Mᵢ = |bᵢ⟩⟨bᵢ|` (`ofOrthonormalBasis_op`) equal to the rank-one projector onto +the unit basis vector `bᵢ`, hence a star projection +(`InnerProductSpace.isStarProjection_rankOne_self`, using `‖bᵢ‖ = 1`). So it is projective in the +sense of N&C §2.2.5: by the derived theorems its operators are pairwise orthogonal +(`IsProjective.orthogonal`) and resolve the identity (`IsProjective.sum_op_eq_one`). General +reusable infrastructure — the genuine-basis case of `isProjective_ofOrthonormalBasisFiber`, which +coarse-grains outcomes through a map `ι → M` (needing `Fintype`/`DecidableEq` on `M`). -/ +theorem isProjective_ofOrthonormalBasis (b : OrthonormalBasis ι ℂ S.space) : + (Measurement.ofOrthonormalBasis b).IsProjective := fun i => by + rw [Measurement.ofOrthonormalBasis_op] + exact InnerProductSpace.isStarProjection_rankOne_self (b.orthonormal.1 i) + +/-- **Born rule for a projective measurement in an orthonormal basis, on a pure state.** The +probability of outcome `i` when measuring the pure state `ψ` in the basis `b` is the squared +magnitude of the amplitude `⟨bᵢ, ψ⟩`, i.e. `|amplitude|²` — N&C's `p(m) = |⟨m|ψ⟩|²` for a +computational-basis measurement. Immediate from the induced rank-one POVM: `bornProb` unfolds to +`re⟨bᵢ, |ψ⟩⟨ψ| bᵢ⟩ = re(⟨ψ, bᵢ⟩⟨bᵢ, ψ⟩) = ‖⟨bᵢ, ψ⟩‖²`. General reusable infrastructure. -/ +theorem bornProb_ofOrthonormalBasis_toState (b : OrthonormalBasis ι ℂ S.space) (ψ : PureState S) + (i : ι) : + (Measurement.ofOrthonormalBasis b).bornProb ψ.toState i = ‖(inner ℂ (b i) ψ.vec : ℂ)‖ ^ 2 := by + rw [Measurement.bornProb, Measurement.toPOVM_ofOrthonormalBasis, POVM.toPMF_ofOrthonormalBasis, + PureState.toState_op, InnerProductSpace.rankOne_apply, inner_smul_right, ← inner_conj_symm, + RCLike.conj_mul] + exact_mod_cast rfl + +/-- **Born rule for a projective measurement in an orthonormal basis, on a general state.** The +probability of outcome `i` when measuring the state `ρ` in the basis `b` is the diagonal density +matrix element `re⟨bᵢ, ρ bᵢ⟩`. Immediate from the induced rank-one POVM. The general-state +counterpart of `bornProb_ofOrthonormalBasis_toState`; general reusable infrastructure. -/ +theorem bornProb_ofOrthonormalBasis (b : OrthonormalBasis ι ℂ S.space) (ρ : State S) (i : ι) : + (Measurement.ofOrthonormalBasis b).bornProb ρ i = (⟪b i, ρ.op (b i)⟫_ℂ).re := by + rw [Measurement.bornProb, Measurement.toPOVM_ofOrthonormalBasis, POVM.toPMF_ofOrthonormalBasis] + rfl + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ProjectorCollapse.lean b/LeanPool/AxQM/Postulates/API/ProjectorCollapse.lean new file mode 100644 index 0000000000..2632dfe18b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ProjectorCollapse.lean @@ -0,0 +1,79 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasurementOperation +public import LeanPool.AxQM.Postulates.API.PureState + +/-! +# Collapse of a rank-one projective measurement outcome + +The state-update rule (Postulate 4) for an outcome whose measurement operator is a **rank-one +projector** onto a unit vector `|φ⟩`: obtaining that outcome collapses the register to `|φ⟩⟨φ|`, +**independent of the input state** — even a mixed one. + +`Measurement.postMeasurement_toState_of_op_eq_rankOne` is the mixed-input companion of +`Measurement.postMeasurement_toState_of_op_eq_smul` (which needs a *pure* input). A rank-one +projective outcome fully collapses the register, so the post-measurement state carries no memory of +`ρ`. This is the fact behind "a computational-basis measurement of a register leaves the recorded +basis state" — the collapse of a joint computational-basis wire measurement onto its outcome ket. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +/-- **A rank-one projective outcome collapses any input to the projector state.** If the measurement +operator of outcome `i` is the rank-one projector `Mᵢ = |φ⟩⟨φ|` onto a unit vector `|φ⟩` +(`meas.op i = rankOne φ.vec φ.vec`), then obtaining outcome `i` collapses **any** input state `ρ` +(mixed or pure) to the pure state `|φ⟩⟨φ|`: + + `postMeas(ρ, i) = φ.toState`. + +The mixed-input companion of `Measurement.postMeasurement_toState_of_op_eq_smul`, which needs a pure +input. The rank-one sandwich `Mᵢ ρ Mᵢ† = ⟪φ, ρ φ⟫ • |φ⟩⟨φ|` +(`opElement`, via `adjoint_rankOne` / `comp_rankOne` / `rankOne_comp_rankOne`) makes the +post-measurement operator a scalar multiple of `|φ⟩⟨φ|`; the collapsed state is a genuine state, so +its trace is `1` (`State.trace_op_eq_one`), forcing the scalar to `1` (`trace_rankOne` with `φ` a +unit vector). The input `ρ` enters only through the scalar, which the trace normalisation discards — +the collapse forgets `ρ` entirely. -/ +theorem Measurement.postMeasurement_toState_of_op_eq_rankOne + (meas : Measurement ι S) (φ : PureState S) (ρ : State S) (i : ι) + (hop : meas.op i = InnerProductSpace.rankOne ℂ φ.vec φ.vec) + (hp : meas.bornProb ρ i ≠ 0) : + meas.postMeasurement ρ i hp = φ.toState := by + set v := φ.vec with hv + -- The rank-one sandwich `Eᵢ(ρ) = Mᵢ ρ Mᵢ† = ⟪v, ρ v⟫ • |v⟩⟨v|`. + have hsand : meas.opElement ρ i + = (inner ℂ v (ρ.op v)) • InnerProductSpace.rankOne ℂ v v := by + rw [Measurement.opElement_eq_postOp] + simp only [ContinuousLinearMap.postOp] + rw [hop, InnerProductSpace.adjoint_rankOne, InnerProductSpace.comp_rankOne, + InnerProductSpace.rankOne_comp_rankOne] + have hvv : inner ℂ v v = (1 : ℂ) := φ.inner_self + have htrace : (LinearMap.trace ℂ S.space) ↑(InnerProductSpace.rankOne ℂ v v) = 1 := by + rw [InnerProductSpace.trace_rankOne, hvv] + -- The post-measurement operator is `((p(i))⁻¹ · ⟪v, ρ v⟫) • |v⟩⟨v|`. + have hred : (meas.postMeasurement ρ i hp).op + = ((meas.bornProb ρ i : ℂ)⁻¹ * inner ℂ v (ρ.op v)) • InnerProductSpace.rankOne ℂ v v := by + rw [Measurement.postMeasurement_op_eq_bornProb_smul_opElement, hsand, smul_smul] + -- Trace-one of the collapsed state pins the scalar to `1`. + have hd1 : (meas.bornProb ρ i : ℂ)⁻¹ * inner ℂ v (ρ.op v) = 1 := by + have h1 := State.trace_op_eq_one (meas.postMeasurement ρ i hp) + rw [hred, ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul, htrace, mul_one] at h1 + exact h1 + apply State.ext + rw [hred, hd1, one_smul, PureState.toState_op, hv] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ProjectorHamiltonian.lean b/LeanPool/AxQM/Postulates/API/ProjectorHamiltonian.lean new file mode 100644 index 0000000000..d55ed4e06d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ProjectorHamiltonian.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.ExponentialInvolution + +/-! +# AxQM.Postulates.API — the projector Hamiltonian and its propagator + +This file treats the **quantum-search-as-simulation** program of Nielsen & Chuang, §6.2 (and +Exercise 6.7): the rank-one *projector Hamiltonian* `H = |ψ⟩⟨ψ|`, and the closed form of the unitary +it generates. + +For a pure state `ψ`, `|ψ⟩⟨ψ|` is a self-adjoint operator, hence an `Observable` — a legitimate +Hamiltonian (N&C eq. 6.18 takes `H = |x⟩⟨x| + |ψ⟩⟨ψ|`, a sum of two such projectors). Its +time-evolution operator `exp(-i|ψ⟩⟨ψ|t)` has the closed form + +`exp(-i|ψ⟩⟨ψ|t) = I + (e^{-it} - 1)|ψ⟩⟨ψ|`, + +which follows purely from the idempotence `|ψ⟩⟨ψ|² = |ψ⟩⟨ψ|` (lemma +`NormedSpace.exp_smul_of_mul_self_eq_self`): the propagator fixes every state orthogonal to `|ψ⟩` +and multiplies the `|ψ⟩` component by the phase `e^{-it}`. + +## What is formalised + +* `AxQM.PureState.projObservable ψ` — the projector Hamiltonian `|ψ⟩⟨ψ|` packaged as an + `Observable`. An `Observable` bundles self-adjointness; producing this term discharges that + obligation (`|ψ⟩⟨ψ|† = |ψ⟩⟨ψ|`). +* `AxQM.PureState.projObservable_op` — its operator form `|ψ⟩⟨ψ| = rankOne ℂ ψ.vec ψ.vec`. +* `AxQM.PureState.projObservable_propagator_op` — **the target operator of N&C Exercise + 6.7**: `exp(-i|ψ⟩⟨ψ|t) = I + (e^{-it} - 1)|ψ⟩⟨ψ|`, i.e. + `(ψ.projObservable.propagator 1 0 t).op = 1 + (Complex.exp (-(I*t)) - 1) • rankOne ℂ ψ.vec ψ.vec`. +* `AxQM.PureState.projObservable_propagator_op_apply` — the same, applied to a vector `v`: + `exp(-i|ψ⟩⟨ψ|t) v = v + (e^{-it} - 1)⟨ψ, v⟩ |ψ⟩` — the propagator leaves `v` unchanged apart from + a phase on its `|ψ⟩` component, the "rotation of `|ψ⟩` towards `|x⟩`" of N&C §6.2 made exact. + +## The proof + +The whole content of the closed form is the Euler formula for an + idempotent, `NormedSpace.exp (z • a) = 1 + (Complex.exp z - 1) • a` for `a * a = a` + (`ToMathlib/Analysis/Normed/Algebra/ExponentialInvolution.lean`), specialised to the idempotent + rank-one projector `a = |ψ⟩⟨ψ|` (idempotent since `⟨ψ, ψ⟩ = 1`) and `z = -it`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The projector Hamiltonian** `H = |ψ⟩⟨ψ|` of a pure state `ψ`, as an `Observable`. The rank-one +projector `|ψ⟩⟨ψ| = rankOne ℂ ψ.vec ψ.vec` is self-adjoint (`|ψ⟩⟨ψ|† = |ψ⟩⟨ψ|`, from +`adjoint_rankOne`), so it is a legitimate observable (Postulate 2). This is the elementary +Hamiltonian whose simulation drives quantum search: Nielsen & Chuang, §6.2, takes +`H = |x⟩⟨x| + |ψ⟩⟨ψ|` (eq. 6.18), a sum of two such projectors, and Exercise 6.7 simulates each +summand `exp(-i|x⟩⟨x|Δt)`, `exp(-i|ψ⟩⟨ψ|Δt)` by a quantum circuit. -/ +def PureState.projObservable (ψ : PureState S) : Observable S where + op := rankOne ℂ ψ.vec ψ.vec + selfAdjoint := by rw [IsSelfAdjoint, ContinuousLinearMap.star_eq_adjoint, adjoint_rankOne] + +/-- The underlying operator of the projector Hamiltonian `|ψ⟩⟨ψ|` is `rankOne ℂ ψ.vec ψ.vec`. -/ +@[simp] +theorem PureState.projObservable_op (ψ : PureState S) : + (ψ.projObservable).op = rankOne ℂ ψ.vec ψ.vec := rfl + +/-- **The projector-Hamiltonian propagator** `exp(-i|ψ⟩⟨ψ|t) = I + (e^{-it} - 1)|ψ⟩⟨ψ|` +(Nielsen & Chuang, §6.2 — the operator that Exercise 6.7's circuits implement, for `H = |x⟩⟨x|` or +`H = |ψ⟩⟨ψ|`). With `ℏ = 1` and elapsed time `t`, the unit propagator of the projector Hamiltonian +`|ψ⟩⟨ψ|` (`ψ.projObservable`) equals `1 + (e^{-it} - 1)|ψ⟩⟨ψ|` at the operator level. The proof is +the idempotence of the rank-one projector (`|ψ⟩⟨ψ|² = |ψ⟩⟨ψ|`, since `⟨ψ, ψ⟩ = 1`) fed into the +Euler formula for an idempotent `NormedSpace.exp_smul_of_mul_self_eq_self` with `z = -it`. -/ +theorem PureState.projObservable_propagator_op (ψ : PureState S) (t : ℝ) : + ((ψ.projObservable).propagator 1 0 t).op + = 1 + (Complex.exp (-(Complex.I * (t : ℂ))) - 1) • rankOne ℂ ψ.vec ψ.vec := by + have hidem : rankOne ℂ ψ.vec ψ.vec * rankOne ℂ ψ.vec ψ.vec = rankOne ℂ ψ.vec ψ.vec := + InnerProductSpace.isIdempotentElem_rankOne_self ψ.normalized + have h1 : ((ψ.projObservable).propagator 1 0 t).op + = NormedSpace.exp ((-(Complex.I * (t : ℂ))) • rankOne ℂ ψ.vec ψ.vec) := by + rw [Observable.propagator_op, PureState.projObservable_op]; norm_num + rw [h1, NormedSpace.exp_smul_of_mul_self_eq_self hidem] + +/-- **The projector-Hamiltonian propagator, applied to a vector.** `exp(-i|ψ⟩⟨ψ|t) v = +v + (e^{-it} - 1)⟨ψ, v⟩ |ψ⟩`: the propagator fixes `v` except that its `|ψ⟩` component is scaled by +the phase `e^{-it}`. This is N&C's "the `|ψ⟩` vector is rotated slightly, into the `|x⟩` direction" +(§6.2, following eq. 6.20) made exact, and the operator identity that the Exercise 6.7 circuits +must reproduce on the query register. -/ +theorem PureState.projObservable_propagator_op_apply (ψ : PureState S) (t : ℝ) (v : S.space) : + ((ψ.projObservable).propagator 1 0 t).op v + = v + ((Complex.exp (-(Complex.I * (t : ℂ))) - 1) * inner ℂ ψ.vec v) • ψ.vec := by + rw [PureState.projObservable_propagator_op, add_apply, + one_apply_eq_self, smul_apply, rankOne_apply, smul_smul] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PseudoInverse.lean b/LeanPool/AxQM/Postulates/API/PseudoInverse.lean new file mode 100644 index 0000000000..a9c8bac7d9 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PseudoInverse.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum + +/-! +# AxQM — the pseudo-inverse `ρ⁻¹` of a density operator + +Nielsen & Chuang, in Exercise 2.73, use the operator `ρ⁻¹` *"defined to be the inverse of `ρ`, +when `ρ` is considered as an operator acting only on the support of `ρ`"* — the support being the +span of the eigenvectors of `ρ` with non-zero eigenvalues. Because a density operator need not be +invertible on the whole space (it can have a kernel), this restricted inverse is the standard +**Moore–Penrose pseudo-inverse** of `ρ`. + +We build it from the spectral decomposition of the (self-adjoint, positive) density operator +`ρ = ∑ₖ λₖ |bₖ⟩⟨bₖ|` over its orthonormal eigenbasis `bₖ` (Mathlib's +`LinearMap.IsSymmetric.eigenvectorBasis` / `eigenvalues`, the same machinery behind the +eigenensemble `Ensemble.ofState`). The pseudo-inverse inverts each non-zero eigenvalue and sends +the kernel (zero eigenvalues) to zero: +`ρ⁻¹ = ∑ₖ λₖ⁻¹ |bₖ⟩⟨bₖ|`, +using the real field inverse `(·)⁻¹ : ℝ → ℝ`, which is `x⁻¹` on `x ≠ 0` and `0` at `0` (Lean's +`GroupWithZero` convention), so the zero eigenvalues contribute nothing — exactly the "on the +support" restriction. + +## Main definitions + +* `AxQM.State.pseudoInverse` — the pseudo-inverse `ρ⁻¹`. + +## Main results + +* `State.pseudoInverse_apply` — the vector form `ρ⁻¹ v = ∑ₖ λₖ⁻¹ ⟪bₖ, v⟫ bₖ`. +* `State.pseudoInverse_apply_eigenvectorBasis` — the spectral action `ρ⁻¹ bⱼ = λⱼ⁻¹ bⱼ`. +* `State.op_apply_eigenvectorBasis` — the `ρ`-side companion `ρ bⱼ = λⱼ bⱼ` (shared by the proofs + below). +* `State.isSelfAdjoint_pseudoInverse` — `ρ⁻¹` is self-adjoint. +* `State.op_comp_pseudoInverse_comp_op` — the Moore–Penrose / "inverse on the support" identity + `ρ ρ⁻¹ ρ = ρ`. +* `State.pseudoInverse_comp_op_comp_pseudoInverse` — the dual identity `ρ⁻¹ ρ ρ⁻¹ = ρ⁻¹`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace State + +/-- **The pseudo-inverse `ρ⁻¹` of a density operator** (Nielsen–Chuang Exercise 2.73): the inverse +of `ρ` on its support, extended by zero on the kernel. Built from the spectral decomposition +`ρ = ∑ₖ λₖ |bₖ⟩⟨bₖ|` over the orthonormal eigenbasis `bₖ` by inverting each eigenvalue with the real +field inverse (so a zero eigenvalue stays `0`): `ρ⁻¹ = ∑ₖ λₖ⁻¹ |bₖ⟩⟨bₖ|`. -/ +def pseudoInverse (ρ : State S) : S.space →L[ℂ] S.space := + ∑ k, (((ρ.isDensity.isSymmetric.eigenvalues rfl k)⁻¹ : ℝ) : ℂ) • + rankOne ℂ (ρ.isDensity.isSymmetric.eigenvectorBasis rfl k) + (ρ.isDensity.isSymmetric.eigenvectorBasis rfl k) + +/-- **Vector form of the pseudo-inverse**: `ρ⁻¹ v = ∑ₖ λₖ⁻¹ ⟪bₖ, v⟫ bₖ`, the spectral expansion of +`ρ⁻¹` (compare `LinearMap.IsSymmetric.spectral_sum_apply` for `ρ` itself). -/ +theorem pseudoInverse_apply (ρ : State S) (v : S.space) : + ρ.pseudoInverse v = + ∑ k, (((ρ.isDensity.isSymmetric.eigenvalues rfl k)⁻¹ : ℝ) : ℂ) • + (inner ℂ (ρ.isDensity.isSymmetric.eigenvectorBasis rfl k) v • + ρ.isDensity.isSymmetric.eigenvectorBasis rfl k) := by + rw [pseudoInverse, sum_apply] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [smul_apply, rankOne_apply] + +/-- **Spectral action of the pseudo-inverse**: `ρ⁻¹ bⱼ = λⱼ⁻¹ bⱼ` on each eigenvector `bⱼ`. +Together with `ρ bⱼ = λⱼ bⱼ` this says `ρ⁻¹` inverts `ρ` eigenvalue-by-eigenvalue, mapping the zero +eigenvalues (the kernel) to `0`. Tagged `@[simp]` as the canonical rewrite target for `ρ⁻¹ bⱼ`. -/ +@[simp] +theorem pseudoInverse_apply_eigenvectorBasis (ρ : State S) (j : Fin (Module.finrank ℂ S.space)) : + ρ.pseudoInverse (ρ.isDensity.isSymmetric.eigenvectorBasis rfl j) = + (((ρ.isDensity.isSymmetric.eigenvalues rfl j)⁻¹ : ℝ) : ℂ) • + ρ.isDensity.isSymmetric.eigenvectorBasis rfl j := by + rw [pseudoInverse_apply, Finset.sum_eq_single j] + · rw [orthonormal_iff_ite.mp (ρ.isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal j j, + ite_eq_left rfl, one_smul] + · intro k _ hk + rw [orthonormal_iff_ite.mp (ρ.isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal k j, + ite_eq_right hk, zero_smul, smul_zero] + · intro h + exact absurd (Finset.mem_univ j) h + +/-- **Spectral action of `ρ` on its eigenvectors**: `ρ bⱼ = λⱼ bⱼ`. The continuous-linear-map +restatement of Mathlib's `LinearMap.IsSymmetric.apply_eigenvectorBasis` for a density operator +(bridging CLM application to the `LinearMap`-level lemma by definitional unfolding). The `ρ`-side +mirror of `pseudoInverse_apply_eigenvectorBasis`; shared by the Moore–Penrose proofs below. -/ +theorem op_apply_eigenvectorBasis (ρ : State S) (j : Fin (Module.finrank ℂ S.space)) : + ρ.op (ρ.isDensity.isSymmetric.eigenvectorBasis rfl j) = + (ρ.isDensity.isSymmetric.eigenvalues rfl j : ℂ) • + ρ.isDensity.isSymmetric.eigenvectorBasis rfl j := + ρ.isDensity.isSymmetric.apply_eigenvectorBasis rfl j + +/-- The **canonical orthonormal eigenbasis** of a state's density operator: the eigenvector basis of +the self-adjoint (symmetric) operator `ρ.op`, indexed by `Fin (dim S.space)`. The named form of +`ρ.isDensity.isSymmetric.eigenvectorBasis rfl`, whose eigenvalues are +`ρ.isDensity.isSymmetric.eigenvalues rfl` (`= State.eigenvalueDist`). Adopted by `ρ`-spectral +developments (`op_apply_eigenbasis` below, and the majorization module). -/ +def eigenbasis (ρ : State S) : + OrthonormalBasis (Fin (Module.finrank ℂ S.space)) ℂ S.space := + ρ.isDensity.isSymmetric.eigenvectorBasis rfl + +/-- **Spectral action on the eigenbasis**: `ρ (bⱼ) = λⱼ • bⱼ`, with `bⱼ = ρ.eigenbasis j` and +`λⱼ = ρ.isDensity.isSymmetric.eigenvalues rfl j` (`= ρ.eigenvalueDist j`). The `State.eigenbasis` +phrasing of `op_apply_eigenvectorBasis`. -/ +theorem op_apply_eigenbasis (ρ : State S) (j : Fin (Module.finrank ℂ S.space)) : + ρ.op (ρ.eigenbasis j) = (ρ.isDensity.isSymmetric.eigenvalues rfl j : ℂ) • ρ.eigenbasis j := + ρ.op_apply_eigenvectorBasis j + +/-- The eigenbasis vectors are orthonormal: `⟪bₖ, bₖ⟫ = 1`. -/ +theorem inner_eigenbasis_self (ρ : State S) (k : Fin (Module.finrank ℂ S.space)) : + inner ℂ (ρ.eigenbasis k) (ρ.eigenbasis k) = 1 := by + rw [orthonormal_iff_ite.mp ρ.eigenbasis.orthonormal k k] + simp + +/-- Each eigenbasis vector is a unit vector: `‖bₖ‖ = 1`. -/ +theorem norm_eigenbasis (ρ : State S) (k : Fin (Module.finrank ℂ S.space)) : + ‖ρ.eigenbasis k‖ = 1 := + ρ.eigenbasis.orthonormal.1 k + +/-- **The pseudo-inverse is self-adjoint.** Each summand `λₖ⁻¹ |bₖ⟩⟨bₖ|` is a real scalar times the +self-adjoint rank-one projector `|bₖ⟩⟨bₖ|`, and a sum of self-adjoint operators is self-adjoint. -/ +theorem isSelfAdjoint_pseudoInverse (ρ : State S) : IsSelfAdjoint ρ.pseudoInverse := by + rw [pseudoInverse] + refine isSelfAdjoint_sum Finset.univ fun k _ => ?_ + rw [Complex.coe_smul] + refine (IsSelfAdjoint.all _).smul ?_ + rw [isSelfAdjoint_iff, ContinuousLinearMap.star_eq_adjoint, adjoint_rankOne] + +/-- **The pseudo-inverse inverts `ρ` on its support** (Nielsen–Chuang Exercise 2.73): the +Moore–Penrose identity `ρ ρ⁻¹ ρ = ρ`. On each eigenvector `bⱼ` the composite scales by +`λⱼ · λⱼ⁻¹ · λⱼ = λⱼ` (equal to `λⱼ` whether or not `λⱼ = 0`), so it agrees with `ρ` on the +eigenbasis — the precise sense in which `ρ⁻¹` is the inverse of `ρ` on the support. -/ +theorem op_comp_pseudoInverse_comp_op (ρ : State S) : + ρ.op.comp (ρ.pseudoInverse.comp ρ.op) = ρ.op := by + refine ContinuousLinearMap.coe_injective + ((ρ.isDensity.isSymmetric.eigenvectorBasis rfl).toBasis.ext fun j => ?_) + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe, + ContinuousLinearMap.comp_apply, op_apply_eigenvectorBasis, map_smul, + pseudoInverse_apply_eigenvectorBasis, smul_smul] + congr 1 + rw [Complex.ofReal_inv, mul_inv_mul_cancel] + +/-- **The dual Moore–Penrose identity `ρ⁻¹ ρ ρ⁻¹ = ρ⁻¹`.** On each eigenvector `bⱼ` the composite +scales by `λⱼ⁻¹ · λⱼ · λⱼ⁻¹ = λⱼ⁻¹` (equal whether or not `λⱼ = 0`), so it agrees with `ρ⁻¹`. -/ +theorem pseudoInverse_comp_op_comp_pseudoInverse (ρ : State S) : + ρ.pseudoInverse.comp (ρ.op.comp ρ.pseudoInverse) = ρ.pseudoInverse := by + refine ContinuousLinearMap.coe_injective + ((ρ.isDensity.isSymmetric.eigenvectorBasis rfl).toBasis.ext fun j => ?_) + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe, + ContinuousLinearMap.comp_apply, pseudoInverse_apply_eigenvectorBasis, map_smul, + op_apply_eigenvectorBasis, smul_smul] + congr 1 + simpa [Complex.ofReal_inv] using + mul_inv_mul_cancel (ρ.isDensity.isSymmetric.eigenvalues rfl j : ℂ)⁻¹ + +end State + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PureMarginalEntropy.lean b/LeanPool/AxQM/Postulates/API/PureMarginalEntropy.lean new file mode 100644 index 0000000000..1104893edd --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PureMarginalEntropy.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SchmidtDecomposition +public import LeanPool.AxQM.Postulates.API.EntropySpectral +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# AxQM — equal marginal entropies of a pure bipartite state (`S(A) = S(B)`) + +For a pure state `ψ` of a composite system `A ⊗ B`, the two reduced states have equal von Neumann +entropy: `S(A) = S(B)`. This is Nielsen & Chuang **Theorem 11.8, part (3)** (eq. (11.88)). + +Both reduced density operators are read off a single Schmidt decomposition +`|ψ⟩ = ∑ᵢ λᵢ |aᵢ⟩ ⊗ |bᵢ⟩` in already-diagonal form — `ρᴬ = ∑ᵢ λᵢ² |aᵢ⟩⟨aᵢ|` and +`ρᴮ = ∑ᵢ λᵢ² |bᵢ⟩⟨bᵢ|` — sharing the one weight list `λ²`, so the orthonormal-eigenfamily engine +evaluates both entropies to `H(λ²)`. + +## The proof + +The proof needs the Schmidt decomposition (`PureState.exists_schmidt_decomposition`), the +partial-trace-of-a-Schmidt-sum identities, and the orthonormal-rank-one entropy engine +(`State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum`). The statement of Theorem 11.8 is +in `LeanPool/AxQM/NC/Ch11/Theorem8.lean`. The equality `S(A) = S(B)` is also used in Exercise 11.14 +(the +negative-conditional-entropy characterisation of entanglement) and Theorem 11.10 (the entropy of a +mixture, reverse direction). + +## Main result + +* `AxQM.PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight` — `S(A) = S(B)` for a pure + bipartite state. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The reduced states of a pure composite are isentropic** (Nielsen–Chuang Theorem 11.8, part +(3)): if a composite system `AB` is in a pure state `ψ`, then `S(A) = S(B)`, where `A = tr_B|ψ⟩⟨ψ|` +and `B = tr_A|ψ⟩⟨ψ|` are the two reduced states. + +N&C's proof: the Schmidt decomposition shows the two reduced density operators have the *same* +eigenvalues, and the entropy is a function of the eigenvalues alone. Formally, take any Schmidt +decomposition `|ψ⟩ = ∑ᵢ λᵢ |aᵢ⟩ ⊗ |bᵢ⟩` (`PureState.exists_schmidt_decomposition`) with strictly +positive coefficients `λᵢ` and orthonormal families `a`, `b`. Tracing out one factor of the +rank-one projector `|ψ⟩⟨ψ|` +(`LinearMap.partialTrace{Right,Left}_rankOne_eq_sum_rankOne_of_schmidt`) gives the +reduced operators in already-diagonal form, `ρᴬ = ∑ᵢ λᵢ² |aᵢ⟩⟨aᵢ|` and `ρᴮ = ∑ᵢ λᵢ² |bᵢ⟩⟨bᵢ|`, with +the *shared* weight list `λ²`. The orthonormal-eigenfamily engine +`State.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum` then evaluates both entropies to the +Shannon entropy `H(λ²)` of that one list, so they are equal. -/ +theorem PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight {T : QSystem} + (ψ : PureState (S.compose T)) : + ψ.toState.reducedLeft.vonNeumannEntropy = ψ.toState.reducedRight.vonNeumannEntropy := by + obtain ⟨n, l, a, b, _hpos, ha, hb, _hnorm, hvec⟩ := ψ.exists_schmidt_decomposition + -- `ρᴬ = ∑ᵢ λᵢ² |aᵢ⟩⟨aᵢ|`: trace out the right factor of `|ψ⟩⟨ψ|`. + have hAop : ψ.toState.reducedLeft.op + = ∑ i, (((l i) ^ 2 : ℝ) : ℂ) • (InnerProductSpace.rankOne ℂ (a i)) (a i) := by + apply ContinuousLinearMap.coe_injective + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + refine (LinearMap.partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ T.space) l a b hb hvec).trans ?_ + rw [ContinuousLinearMap.toLinearMap_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.toLinearMap_smul] + norm_cast + -- `ρᴮ = ∑ᵢ λᵢ² |bᵢ⟩⟨bᵢ|`: trace out the left factor of `|ψ⟩⟨ψ|`. + have hBop : ψ.toState.reducedRight.op + = ∑ i, (((l i) ^ 2 : ℝ) : ℂ) • (InnerProductSpace.rankOne ℂ (b i)) (b i) := by + apply ContinuousLinearMap.coe_injective + rw [State.reducedRight_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + refine (LinearMap.partialTraceLeft_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ S.space) l a b + (fun i j _ _ => orthonormal_iff_ite.mp ha i j) hvec).trans ?_ + rw [ContinuousLinearMap.toLinearMap_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.toLinearMap_smul] + norm_cast + rw [ψ.toState.reducedLeft.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum ha + (fun i => (l i) ^ 2) hAop, + ψ.toState.reducedRight.vonNeumannEntropy_eq_entropy_of_orthonormal_rankOne_sum hb + (fun i => (l i) ^ 2) hBop] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/PureState.lean b/LeanPool/AxQM/Postulates/API/PureState.lean new file mode 100644 index 0000000000..558a4d026e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/PureState.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap + +/-! +# AxQM.Postulates.API — shared facts on pure states + +Shared facts on pure states, concerning the state vector `PureState.vec` (or the induced density +operator `PureState.toState`): + +* `PureState.normalize v hv` — the pure state `‖v‖⁻¹ • v` of a nonzero vector `v : S`. Every + construction that presents a pure state as "the normalization of some explicit (unnormalized) + vector" — an eigenvector, a projected vector, a post-measurement direction — routes its `‖·‖ = 1` + obligation through this one lemma instead of re-proving it. +* `PureState.toState_eq_of_vec_eq_smul` — a **global phase is invisible to the density operator**: + vectors differing by a unit-modulus scalar induce the same `PureState.toState`. +* `PureState.inner_self` — a pure state's vector is a unit vector: `⟨ψ, ψ⟩ = 1`. The shared form of + the normalization fact whenever an inner product `⟪ψ.vec, ψ.vec⟫` appears in a computation. +* `PureState.overlap` — the **overlap** (transition amplitude) `⟨ψ|φ⟩` of two pure states, used in + place of the raw `inner` of state vectors (e.g. in Uhlmann's theorem, N&C Thm 9.4). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +namespace PureState + +variable {S : QSystem} + +/-- **A pure state's vector has unit self-inner-product: `⟨ψ, ψ⟩ = 1`.** The complex-valued +companion of `PureState.normalized` (`‖ψ.vec‖ = 1`). Cite this single shared lemma whenever +`⟪ψ.vec, ψ.vec⟫_ℂ` appears, rather than re-deriving it from `inner_self_eq_norm_sq_to_K`. +It is not `@[simp]`: `simp` already rewrites `⟪ψ.vec, ψ.vec⟫` to `↑‖ψ.vec‖ ^ 2`. -/ +theorem inner_self (ψ : PureState S) : inner ℂ ψ.vec ψ.vec = (1 : ℂ) := by + rw [inner_self_eq_norm_sq_to_K, ψ.normalized]; norm_num + +/-- **A pure state's underlying vector is nonzero:** its norm is `1`, so it cannot be the zero +vector. The foundational nonzero witness cited whenever a state vector must be shown nonzero — e.g. +to feed `PureState.normalize`, or to conclude from `μ • ψ.vec = ν • ψ.vec` that `μ = ν`. -/ +theorem vec_ne_zero (ψ : PureState S) : ψ.vec ≠ 0 := by + intro h + have hn := ψ.normalized + rw [h, norm_zero] at hn + norm_num at hn + +/-- The **overlap** (transition amplitude) `⟨ψ|φ⟩` of two pure states of the same system, +`⟪ψ.vec, φ.vec⟫`. It is used in place of the raw `inner` of state vectors — e.g. in Uhlmann's +theorem (N&C Thm 9.4), where the fidelity is the greatest overlap magnitude `‖ψ.overlap φ‖` +achievable over purifications. Following Mathlib's `inner ℂ` convention it is conjugate-linear in +the bra `ψ` and linear in the ket `φ`; its magnitude `‖ψ.overlap φ‖` is the physical transition +probability amplitude. -/ +def overlap (ψ φ : PureState S) : ℂ := inner ℂ ψ.vec φ.vec + +/-- Unfolding lemma for `PureState.overlap`: `ψ.overlap φ = ⟪ψ.vec, φ.vec⟫`. Kept out of the default +`simp` set (like `inner_self`) so `overlap` survives in statements that use it; cite it explicitly +when the raw inner product is needed. -/ +theorem overlap_def (ψ φ : PureState S) : ψ.overlap φ = inner ℂ ψ.vec φ.vec := rfl + +/-- **A pure state has unit overlap with itself: `⟨ψ|ψ⟩ = 1`.** The `overlap`-level companion of +`PureState.inner_self`; cite it whenever the diagonal transition amplitude `ψ.overlap ψ` appears +(e.g. the ancilla `⟨u|u⟩ = 1` normalization in N&C Proposition 12.18). Kept out of `simp` (like +`overlap_def`) so `overlap` is not eagerly unfolded. -/ +theorem overlap_self (ψ : PureState S) : ψ.overlap ψ = 1 := by + rw [overlap_def]; exact ψ.inner_self + +/-- **Two pure states with overlap `1` are equal.** If the transition amplitude `⟨ψ|φ⟩` equals `1` +then `ψ = φ`: the rigidity (equality) case of the Cauchy–Schwarz bound `‖⟨ψ|φ⟩‖ ≤ 1` for unit +vectors — a unit overlap forces the two unit vectors to coincide *exactly*, leaving not even a +global phase free. The shared lever for "unit overlap pins the state down", e.g. an undisturbed +probe whose ancilla is left unchanged (N&C Proposition 12.18). The direct equality-case lemma +`inner_eq_one_iff_of_norm_eq_one` (`‖x‖ = ‖y‖ = 1 → (⟨x, y⟩ = 1 ↔ x = y)`) applies through the +definitional unfolding of `overlap`. -/ +theorem eq_of_overlap_eq_one {ψ φ : PureState S} (h : ψ.overlap φ = 1) : ψ = φ := + PureState.ext ((inner_eq_one_iff_of_norm_eq_one ψ.normalized φ.normalized).mp h) + +/-- The **normalized pure state** `‖v‖⁻¹ • v` built from a nonzero vector `v : S`. The single shared +constructor for "the pure state in the direction of `v`"; its `‖·‖ = 1` proof is the one place the +`norm_smul` / `inv_mul_cancel₀` normalization argument is discharged. -/ +def normalize (v : S) (hv : v ≠ 0) : PureState S where + vec := ((‖v‖ : ℝ) : ℂ)⁻¹ • v + normalized := by + rw [norm_smul, norm_inv, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (norm_nonneg _), + inv_mul_cancel₀ (norm_ne_zero_iff.mpr hv)] + +@[simp] +theorem normalize_vec (v : S) (hv : v ≠ 0) : + (normalize v hv).vec = ((‖v‖ : ℝ) : ℂ)⁻¹ • v := rfl + +/-- **A global phase is invisible to the density operator.** If `ψ.vec = c • φ.vec` for a +unit-modulus scalar `c` (`‖c‖ = 1`), then the density operators coincide, `|ψ⟩⟨ψ| = |φ⟩⟨φ|`, hence +`ψ.toState = φ.toState`: a global phase never affects the state. (`|ψ⟩⟨ψ|` scales by +`c · conj c = ‖c‖² = 1`, `InnerProductSpace.rankOne_smul_smul_self`.) -/ +theorem toState_eq_of_vec_eq_smul {ψ φ : PureState S} {c : ℂ} (hc : ‖c‖ = 1) + (h : ψ.vec = c • φ.vec) : ψ.toState = φ.toState := by + refine State.ext ?_ + rw [toState_op, toState_op, h, InnerProductSpace.rankOne_smul_smul_self, + show c * (starRingEnd ℂ) c = 1 by rw [RCLike.mul_conj, hc]; norm_num, one_smul] + +end PureState + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Purity.lean b/LeanPool/AxQM/Postulates/API/Purity.lean new file mode 100644 index 0000000000..22cff2c878 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Purity.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PureState +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.IdempotentDensityOp + +/-! +# AxQM.Postulates.API — purity of a state + +Two quantities on states, used to state N&C Exercise 2.71 (the criterion +for deciding whether a state is mixed or pure): + +* `State.purity ρ` — the **purity** `tr(ρ²)` of a density operator, as a real number + (`re tr(ρ²)`; the trace of the positive operator `ρ²` is real), defined from `State.op` and + `LinearMap.trace`. +* `State.IsPure ρ` — the predicate "`ρ` is a pure state", i.e. `ρ = |ψ⟩⟨ψ|` for some + `ψ : PureState S`. + +The lemma `State.isPure_iff_exists_rankOne` restates `IsPure` in terms of the underlying +rank-one operator, the form in which the Mathlib density-operator API +(`ContinuousLinearMap.IsDensityOp.re_trace_mul_self_eq_one_iff_exists_rankOne`) delivers the pure +criterion. The consequences (`purity ≤ 1` and `purity = 1 ↔ IsPure`) are the Exercise 2.71 +theorems, in [upstream `AxQM/NC/Ch2/Exercise2_71.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_71.lean). +-/ + +@[expose] public section + +noncomputable section + +open scoped InnerProductSpace + +namespace AxQM + +variable {S : QSystem} + +/-- The **purity** `tr(ρ²)` of a state `ρ`, as a real number. Since `ρ` is a positive operator, +`ρ² = ρ.op * ρ.op` is positive and its trace is real; `purity` records that real trace. Equal to +`1` exactly when `ρ` is pure (see `State.purity_eq_one_iff_isPure`), and always at most `1` +(`State.purity_le_one`). -/ +def State.purity (ρ : State S) : ℝ := + RCLike.re (LinearMap.trace ℂ S ((ρ.op * ρ.op : S →L[ℂ] S) : S →ₗ[ℂ] S)) + +/-- A state `ρ` **is pure** when it is the rank-one projector `|ψ⟩⟨ψ|` of some pure state `ψ`, +i.e. `ρ = ψ.toState`. -/ +def State.IsPure (ρ : State S) : Prop := + ∃ ψ : PureState S, ρ = ψ.toState + +/-- **Purity in terms of rank-one operators.** A state is pure iff its density operator is the +rank-one self-projector `|v⟩⟨v|` of some unit vector `v`. Unfolds `State.IsPure` through +`toState_op` so it can be matched against the Mathlib pure criterion. -/ +theorem State.isPure_iff_exists_rankOne (ρ : State S) : + ρ.IsPure ↔ ∃ v : S, ‖v‖ = 1 ∧ ρ.op = InnerProductSpace.rankOne ℂ v v := by + constructor + · rintro ⟨ψ, rfl⟩ + exact ⟨ψ.vec, ψ.normalized, ψ.toState_op⟩ + · rintro ⟨v, hv, hop⟩ + refine ⟨⟨v, hv⟩, State.ext ?_⟩ + rw [hop] + exact (PureState.toState_op ⟨v, hv⟩).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QftControlledEvolution.lean b/LeanPool/AxQM/Postulates/API/QftControlledEvolution.lean new file mode 100644 index 0000000000..14836d0d71 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QftControlledEvolution.lean @@ -0,0 +1,120 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Concrete.QftGateCircuitCorrectness +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# The Figure 5.1 controlled-`Rₖ` gate as an `Evolution`, and its basis action (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a **product of wire-addressed tower gates** +(`qftTowerEvolution_eq_map_congr_prod`), so each transported Figure 5.1 gate must be re-expressed as +such a tower gate. The Figure 5.1 gates come in three shapes — the wire-reversal **swap** layer +(`QftSwapEvolution`), the **Hadamards** (`QftHadamardEvolution`), and the **controlled-`Rₖ`** +rotations, the circuit's only **two-wire** gate. This file supplies the register-side ingredient the +*controlled-`Rₖ`* re-expression needs: the conditional rotation as a named `Evolution` on the single +`2ⁿ`-level register, with its action on the computational basis computed. + +Unlike the Hadamard — which sends a basis ket to a *superposition* — the controlled-`Rₖ` gate is +**diagonal** (`Rₖ = diag(1, e^{2πi/2ᵏ})`), so it sends a basis ket to a *phased* basis ket: it +multiplies `|f⟩` by the phase `e^{2πi/2ᵏ}` exactly when both the control wire `c` and the target +wire `t` carry a `1`, and fixes it otherwise. Its computational-basis action is therefore a single +scalar, not a two-term sum, and the tower re-expression (`AxQM/Core/QftTowerControlled.lean`) +matches it against the phase gate `phaseShiftGate (2π/2ᵏ)` placed on the target of the controlled +tower gate `Evolution.qtowerCtrlWire`. + +## What is formalised + +* `qftControlledEvolution n t c` — the **Figure 5.1 controlled-`Rₖ` gate from control wire `c` onto + target wire `t` as an `Evolution`** on `qudit (2ⁿ)`: the `quditGate` promotion of the Concrete + gate matrix `qftControlledGate n t c = mcCtrlSingleQubit finFunctionFinEquiv {c} t Rₖ`, + `Rₖ = qftRk ((c-t)+1)` (the conditional rotation of `Concrete.qftGateSequence`). It is unitary (a + controlled unitary block), so `quditGate` applies. +* `qftControlledEvolution_evolvePure_quditBasis` — its **computational-basis action** (for `t ≠ c`): + the gate is diagonal, so it multiplies `|finFunctionFinEquiv f⟩` by the phase + `[1, e^{2πi/2^{(c-t)+1}}]_{f t}` when the control bit `f c` is `1`, and fixes it otherwise: + + `qftControlledEvolution n t c |ff f⟩` + `= (if f c = 1 then [1, e^{2πi/2ᵏ}]_{f t} else 1) • |ff f⟩`. + + Read off from `mcCtrlSingleQubit_diagonal` (the `Rₖ` block is `Matrix.diagonal ![1, e^{2πi/2ᵏ}]` + via `qftRk_eq_diagonal`), the column action of `Matrix.toEuclideanCLM` on a standard basis vector, + and the singleton control condition `∀ k ∈ {c}, f k = 1 ↔ f c = 1`. This is the register-side + action the tower re-expression (`AxQM/Core/QftTowerControlled.lean`) reads through the register + bridge `quditPowTower`. + +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **The Figure 5.1 controlled-`Rₖ` gate from control wire `c` onto target wire `t` as an +`Evolution`** on `qudit (2ⁿ)`: the `quditGate` promotion of the Concrete gate matrix +`qftControlledGate n t c = mcCtrlSingleQubit finFunctionFinEquiv {c} t (qftRk ((c-t)+1))` — the +conditional rotation `R_{(c-t)+1}` of `Concrete.qftGateSequence`, applying the phase `Rₖ` to wire +`t` when wire `c` is `|1⟩`. It is unitary (a controlled unitary block, `mcCtrlSingleQubit` of the +unitary `qftRk`), so `quditGate` applies. It is used in `AxQM/Core/QftTowerControlled.lean`; its +basis action is `qftControlledEvolution_evolvePure_quditBasis`. -/ +def qftControlledEvolution (n : ℕ) (t c : Fin n) : Evolution (qudit (2 ^ n)) := + quditGate (mcCtrlSingleQubit_mem_unitaryGroup finFunctionFinEquiv {c} t + (qftRk_mem_unitaryGroup ((c : ℕ) - (t : ℕ) + 1))) + +/-- **The controlled-`Rₖ` gate multiplies a basis ket by a control-and-target phase.** For `t ≠ c` +(the control and target are distinct wires), the diagonal gate `qftControlledEvolution n t c` acts +on the computational-basis ket `|finFunctionFinEquiv f⟩` as + + `qftControlledEvolution n t c |ff f⟩ + = (if f c = 1 then ![1, e^{2πi/2^{(c-t)+1}}] (f t) else 1) • |ff f⟩`: + +when the control bit `f c` is `1` it multiplies by the `Rₖ` diagonal entry `[1, e^{2πi/2ᵏ}]_{f t}` +(so by `e^{2πi/2ᵏ}` precisely when the target bit `f t` is also `1`), and otherwise fixes the ket. +Read off from `mcCtrlSingleQubit_diagonal` — the `Rₖ` block is `Matrix.diagonal ![1, e^{2πi/2ᵏ}]` +(`qftRk_eq_diagonal`), so the gate is `Matrix.diagonal` with entry +`if ∀ k ∈ {c}, f k = 1 then [1, e^{2πi/2ᵏ}]_{f t} else 1` at index `|ff f⟩` — through the column +action `Matrix.toEuclideanCLM_apply_single` and the singleton control condition +`∀ k ∈ {c}, f k = 1 ↔ f c = 1` (`Finset.forall_mem_singleton`). This is the register-side action the +tower re-expression reads through the register bridge `quditPowTower`; the two-wire structure +survives on the tower as `Evolution.qtowerCtrlWire`. -/ +theorem qftControlledEvolution_evolvePure_quditBasis (n : ℕ) (t c : Fin n) (hne : t ≠ c) + (f : Fin n → Fin 2) : + ((qftControlledEvolution n t c).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = (if f c = 1 then + ![(1 : ℂ), Complex.exp (2 * Real.pi * Complex.I / 2 ^ ((c : ℕ) - (t : ℕ) + 1))] (f t) + else 1) • (quditBasis (finFunctionFinEquiv f)).vec := by + have hts : t ∉ ({c} : Finset (Fin n)) := by simpa using hne + rw [Evolution.evolvePure_vec] + simp only [qftControlledEvolution, quditGate_op, quditBasis_vec] + rw [qftRk_eq_diagonal, mcCtrlSingleQubit_diagonal finFunctionFinEquiv hts] + refine (Matrix.toEuclideanCLM_apply_single _ (finFunctionFinEquiv f)).trans ?_ + rw [Finset.sum_eq_single (finFunctionFinEquiv f) + (fun j _ hj => by rw [Matrix.diagonal_apply_ne _ hj, zero_smul]) + (fun h => absurd (Finset.mem_univ _) h), + Matrix.diagonal_apply_eq] + simp only [Equiv.symm_apply_apply] + -- The singleton control condition `∀ k ∈ {c}, f k = 1` is just `f c = 1`; case-split so the two + -- `ite`s match branch-by-branch (avoiding a `Decidable`-instance mismatch on the conditions). + have hcond : (∀ k ∈ ({c} : Finset (Fin n)), f k = 1) ↔ f c = 1 := by + simp only [Finset.mem_singleton, forall_eq] + by_cases hc : f c = 1 + · rw [ite_eq_left (hcond.mpr hc), ite_eq_left hc]; rfl + · rw [ite_eq_right (fun h => hc (hcond.mp h)), ite_eq_right hc]; rfl + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QftGateEvolution.lean b/LeanPool/AxQM/Postulates/API/QftGateEvolution.lean new file mode 100644 index 0000000000..d0c937244d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QftGateEvolution.lean @@ -0,0 +1,118 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.QuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Concrete.QftGateCircuitEqMatrix + +/-! +# The QFT as an `Evolution`-gate composition (Nielsen & Chuang, Figure 5.1 / product form 5.4) + +The quantum Fourier transform is given as the *monolithic* unitary `qftEvolution (2ⁿ)` (its operator +the matrix `qftMatrix (2ⁿ)`). Problem 5.2 (the measured QFT) needs it instead as a **composition of +wire-addressed gates** — the Figure 5.1 circuit of Hadamards, controlled-`Rₖ` rotations, and a swap +layer — so that the terminal measurement can be deferred gate by gate. This file supplies that +bridge. + +The `Concrete` layer already builds the Figure 5.1 circuit as an explicit matrix product +(`Concrete.qftGateCircuit n = (Concrete.qftGateSequence n).reverse.prod`) and certifies it computes +the transform (`Concrete.qftGateCircuit_eq_qftMatrix : qftGateCircuit n = qftMatrix (2ⁿ)`). Here we +**lift that matrix product to the `Evolution` monoid**: each Figure 5.1 gate matrix is unitary +(`Concrete.qftGateSequence_forall_mem_unitaryGroup`), so `quditGate` promotes it to an +`Evolution (qudit (2ⁿ))`, and the sequential composition (the monoid product `Evolution.comp`) of +the promoted gates equals the monolithic `qftEvolution (2ⁿ)`: + +* `qftGateEvolutionSequence n` — the time-ordered list of Figure 5.1 gates as `Evolution`s; +* `qftCircuitEvolution n` — their sequential composition (reverse product, so the first-listed gate + acts first), the QFT *as a circuit*; +* `qftEvolution_eq_qftCircuitEvolution` — **the circuit is the transform**: `qftEvolution (2ⁿ)` + equals this explicit composition of one- and two-wire gates. This is the postulate-level + realisation of product form (5.4), the form over which the whole-circuit measured-QFT reduction + (Problem 5.2) defers each two-wire controlled gate. + +`quditGate` (matrix → `Evolution`) intertwines matrix multiplication with `Evolution` composition +onto the operator algebra (`quditGate_op` + `Evolution.op_prod` + multiplicativity of +`Matrix.toEuclideanCLM`), so the proof merely transports the `Concrete` matrix identity across it, +with no re-derivation of the circuit's correctness. + +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +/-- **The Figure 5.1 QFT gates as `Evolution`s**, listed in the order the circuit's operator +composes them (the reverse of Figure 5.1's time order, matching `Concrete.qftGateCircuit`'s reverse +product). Each gate matrix of `Concrete.qftGateSequence n` — the swap layer, and each target's +Hadamard + controlled-`Rₖ` cascade — is unitary (`qftGateSequence_forall_mem_unitaryGroup`), so +`quditGate` promotes it to a unitary `Evolution (qudit (2ⁿ))`. The last entry (the swap layer) +acts first on states; the plain product of this list is `qftCircuitEvolution`. -/ +def qftGateEvolutionSequence (n : ℕ) : List (Evolution (qudit (2 ^ n))) := + (Concrete.qftGateSequence n).reverse.pmap (fun _ h => quditGate h) + (fun g hg => Concrete.qftGateSequence_forall_mem_unitaryGroup n g (List.mem_reverse.mp hg)) + +/-- **The QFT circuit as a single `Evolution`.** The sequential composition (`Evolution`-monoid +product) of the Figure 5.1 gates `qftGateEvolutionSequence n`; since that list is in composition +order, the swap layer acts first on states, matching `Concrete.qftGateCircuit`. This is the quantum +Fourier transform expressed as a circuit of one- and two-wire gates; +`qftEvolution_eq_qftCircuitEvolution` identifies it with the monolithic `qftEvolution (2ⁿ)`. -/ +def qftCircuitEvolution (n : ℕ) : Evolution (qudit (2 ^ n)) := + (qftGateEvolutionSequence n).prod + +/-- Mapping the underlying operator over a list of `quditGate`-promoted unitary matrices recovers +the matrices promoted through `Matrix.toEuclideanCLM`. This is `quditGate_op` applied down the +list — the step turning an `Evolution`-monoid product of the promoted gates into the +operator-algebra product of the matrices. -/ +theorem map_op_pmap_quditGate {d : ℕ} [NeZero d] : + ∀ (l : List (Matrix (Fin d) (Fin d) ℂ)) + (H : ∀ g ∈ l, g ∈ Matrix.unitaryGroup (Fin d) ℂ), + (l.pmap (fun _ h => quditGate h) H).map Evolution.op + = l.map (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d)) + | [], _ => rfl + | a :: t, H => by + simp only [List.pmap, List.map_cons, quditGate_op] + congr 1 + exact map_op_pmap_quditGate t (fun g hg => H g (List.mem_cons_of_mem a hg)) + +/-- **The operator of the QFT circuit is the Figure 5.1 gate-product matrix.** Its underlying +continuous linear map is `Matrix.toEuclideanCLM (Concrete.qftGateCircuit n)`, because the operator +of an `Evolution`-monoid product is the operator product (`Evolution.op_prod`), each promoted gate's +operator is its matrix through `toEuclideanCLM` (`map_op_pmap_quditGate`), and `toEuclideanCLM` is +multiplicative (`map_list_prod`). -/ +theorem qftCircuitEvolution_op (n : ℕ) : + (qftCircuitEvolution n).op + = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n)) (Concrete.qftGateCircuit n) := by + rw [qftCircuitEvolution, Evolution.op_prod, qftGateEvolutionSequence, map_op_pmap_quditGate, + Concrete.qftGateCircuit] + exact (map_list_prod (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin (2 ^ n))) + (Concrete.qftGateSequence n).reverse).symm + +/-- **Problem 5.2 (the QFT is its Figure 5.1 circuit).** The monolithic quantum Fourier transform +`qftEvolution (2ⁿ)` equals the sequential composition `qftCircuitEvolution n` of its Figure 5.1 +gates — the wire-addressed Hadamards, the controlled-`Rₖ` rotations, and the swap layer (N&C +product form 5.4). Both operators are `Matrix.toEuclideanCLM (qftMatrix (2ⁿ))`: the circuit's by +`qftCircuitEvolution_op` together with the `Concrete` correctness +`Concrete.qftGateCircuit_eq_qftMatrix`, the transform's by definition. This is the postulate-level +realisation of the QFT as a circuit — the object over which the measured-QFT reduction defers each +two-wire controlled gate. -/ +theorem qftEvolution_eq_qftCircuitEvolution (n : ℕ) : + qftEvolution (2 ^ n) = qftCircuitEvolution n := by + apply Evolution.ext + rw [qftCircuitEvolution_op, Concrete.qftGateCircuit_eq_qftMatrix] + rfl + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QftHadamardEvolution.lean b/LeanPool/AxQM/Postulates/API/QftHadamardEvolution.lean new file mode 100644 index 0000000000..693d4f9324 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QftHadamardEvolution.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Postulates.API.HadamardGate +public import LeanPool.AxQM.Concrete.QftGateCircuit +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# The Figure 5.1 Hadamard layer as an `Evolution`, and its basis action (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a **product of wire-addressed tower gates** +(`qftTowerEvolution_eq_map_congr_prod`), so each transported Figure 5.1 gate must be re-expressed as +such a tower gate. The Figure 5.1 gates come in three shapes — the wire-reversal **swap** layer +(`QftSwapEvolution`), the **Hadamards**, and the **controlled-`Rₖ`** gates. This file supplies the +register-side ingredients the *Hadamard* re-expression needs: the Hadamard on a wire as a named +`Evolution` on the single `2ⁿ`-level register, with its action on the computational basis computed. + +Unlike the swap — a basis-permutation gate (basis ket ↦ basis ket) — the Hadamard maps a basis ket +to a **superposition** of two basis kets (the wire is put into `|±⟩`), so its computational-basis +action is a genuine two-term sum, and the tower re-expression (`AxQM/Core/QftTowerHadamard.lean`) +matches it through the tensor multilinearity of the tower product state. + +## What is formalised + +* `quditGate_singleQubitOnWire_evolvePure_quditBasis` — a **reusable bridge**: the `quditGate` + promotion of a single-qubit-on-wire gate `singleQubitOnWire enc t G` (an arbitrary one-qubit + matrix `G` on wire `t`) acts on the computational basis ket `|enc f⟩` as the two-term + wire-`t`-column superposition + + `quditGate (singleQubitOnWire enc t G) |enc f⟩ = ∑_{z} G z (f t) · |enc (update f t z)⟩`. + + The single-qubit-gate analogue of the permutation bridge + `quditGate_permGate_evolvePure_quditBasis` (`QftSwapEvolution`): from the column action of + `Matrix.toEuclideanCLM` on a standard basis vector (`Matrix.toEuclideanCLM_apply_single`) and the + entry form of `singleQubitOnWire` (`singleQubitOnWire_apply`) — the `enc f`-column of the gate + is supported on exactly the two rows `enc (Function.update f t z)`, `z : Fin 2`, with value + `G z (f t)`. Reused by every Figure 5.1 single-qubit wire gate — here the Hadamard layer + `qftHadamardEvolution`. +* `qftHadamardEvolution n t` — the **Figure 5.1 Hadamard on wire `t` as an `Evolution`** on + `qudit (2ⁿ)`: the `quditGate` promotion of the Concrete gate matrix + `qftHadamardGate n t = singleQubitOnWire finFunctionFinEquiv t hadamardC` (the block-opening gate + of `qftGateSequence`). +* `qftHadamardEvolution_evolvePure_quditBasis` — its **computational-basis action**: it puts wire + `t` into `|±⟩`, `qftHadamardEvolution n t |finFunctionFinEquiv f⟩ = ∑_z hadamardC z (f t) · + |finFunctionFinEquiv (update f t z)⟩`. The instance of the reusable bridge at `G = hadamardC`, + `enc = finFunctionFinEquiv`. This is the register-side action the tower re-expression + (`AxQM/Core/QftTowerHadamard.lean`) reads through the register bridge. +* `hadamardGate_evolvePure_qubitBasis_sum` — the **single-qubit companion**: the qubit Hadamard + `hadamardGate` acts on a computational-basis state `|z⟩` as its Hadamard-matrix column, + `hadamardGate |z⟩ = ∑_w hadamardC w z · |w⟩` — the `d = 2` case of the same column action. This + is the single-wire factor the tower re-expression matches the register two-term superposition + against. + +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **A `quditGate`-promoted single-qubit wire gate acts on the computational basis as a two-term +column superposition.** For an encoding `enc : (Fin m → Fin 2) ≃ Fin d` of the bit-strings, a wire +`t`, and a one-qubit matrix `G`, the gate `quditGate (singleQubitOnWire enc t G)` sends the basis +ket `|enc f⟩` to `∑_{z : Fin 2} G z (f t) · |enc (Function.update f t z)⟩` — it mixes only the two +basis states that agree with `f` off wire `t`, through the column `(G · , f t)` of `G`. The +single-qubit analogue of the permutation bridge `quditGate_permGate_evolvePure_quditBasis`: proved +from the column action of `Matrix.toEuclideanCLM` on a standard basis vector +(`Matrix.toEuclideanCLM_apply_single`) and the entry form `singleQubitOnWire_apply` — the `enc +f`-column is supported on exactly the two rows `enc (Function.update f t z)` (`z : Fin 2`), with +value `G z (f t)`. Reused by every Figure 5.1 single-qubit wire gate. -/ +theorem quditGate_singleQubitOnWire_evolvePure_quditBasis {m d : ℕ} + (enc : (Fin m → Fin 2) ≃ Fin d) (t : Fin m) {G : Matrix (Fin 2) (Fin 2) ℂ} + (hG : G ∈ Matrix.unitaryGroup (Fin 2) ℂ) (f : Fin m → Fin 2) : + ((quditGate (singleQubitOnWire_mem_unitaryGroup enc t hG)).evolvePure + (quditBasis (enc f))).vec + = ∑ z : Fin 2, G z (f t) • (quditBasis (enc (Function.update f t z))).vec := by + rw [Evolution.evolvePure_vec, quditGate_op, quditBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single (singleQubitOnWire enc t G) (enc f)).trans ?_ + simp only [quditBasis_vec] + -- The `enc f`-column of `singleQubitOnWire enc t G` vanishes off the two rows + -- `enc (update f t z)`, `z : Fin 2`; restrict the full sum to that image, then simplify entries. + have hsupp : ∀ k ∈ (Finset.univ : Finset (Fin d)), + k ∉ Finset.image (fun z : Fin 2 => enc (Function.update f t z)) Finset.univ → + singleQubitOnWire enc t G k (enc f) • + (EuclideanSpace.single k 1 : EuclideanSpace ℂ (Fin d)) = 0 := by + intro k _ hk + have hne : ¬ ∀ j, j ≠ t → enc.symm k j = enc.symm (enc f) j := by + intro hagree + refine hk (Finset.mem_image.2 ⟨enc.symm k t, Finset.mem_univ _, ?_⟩) + have hu : Function.update f t (enc.symm k t) = enc.symm k := by + funext j + rcases eq_or_ne j t with rfl | hj + · rw [Function.update_self] + · have := hagree j hj + rw [Equiv.symm_apply_apply] at this + rw [Function.update_of_ne hj, this] + rw [hu, Equiv.apply_symm_apply] + rw [singleQubitOnWire_apply, ite_eq_right hne, zero_smul] + rw [← Finset.sum_subset (Finset.subset_univ _) hsupp, + Finset.sum_image (by + intro a _ b _ hab + have := congrArg (fun x => enc.symm x t) hab + simpa [Equiv.symm_apply_apply, Function.update_self] using this)] + refine Finset.sum_congr rfl (fun z _ => ?_) + congr 1 + rw [singleQubitOnWire_apply, ite_eq_left] + · simp only [Equiv.symm_apply_apply, Function.update_self] + · intro j hj + simp only [Equiv.symm_apply_apply, Function.update_of_ne hj] + +/-- **The Figure 5.1 Hadamard on wire `t` as an `Evolution`** on `qudit (2ⁿ)`: the `quditGate` +promotion of the Concrete gate matrix +`qftHadamardGate n t = singleQubitOnWire finFunctionFinEquiv t hadamardC` — the parameter-free +block-opening gate of `Concrete.qftGateSequence`. It is unitary (a single-qubit wire gate with the +unitary Hadamard block), so `quditGate` applies. It is used in `AxQM/Core/QftTowerHadamard.lean`; +its basis action is `qftHadamardEvolution_evolvePure_quditBasis`. -/ +def qftHadamardEvolution (n : ℕ) (t : Fin n) : Evolution (qudit (2 ^ n)) := + quditGate (singleQubitOnWire_mem_unitaryGroup finFunctionFinEquiv t hadamardC_mem_unitaryGroup) + +/-- **The Hadamard layer puts wire `t` into `|±⟩`.** +`qftHadamardEvolution n t |finFunctionFinEquiv f⟩ = ∑_z hadamardC z (f t) · |finFunctionFinEquiv +(Function.update f t z)⟩`: the bit-string `f` addressing the wires has its wire-`t` component +replaced by the Hadamard superposition, the two branches carrying amplitudes `hadamardC z (f t)`. +The instance of the reusable bridge `quditGate_singleQubitOnWire_evolvePure_quditBasis` at +`G = hadamardC`, `enc = finFunctionFinEquiv`. This is the register-side action the tower +re-expression reads through the register bridge `quditPowTower`. -/ +theorem qftHadamardEvolution_evolvePure_quditBasis (n : ℕ) (t : Fin n) (f : Fin n → Fin 2) : + ((qftHadamardEvolution n t).evolvePure (quditBasis (finFunctionFinEquiv f))).vec + = ∑ z : Fin 2, hadamardC z (f t) • + (quditBasis (finFunctionFinEquiv (Function.update f t z))).vec := + quditGate_singleQubitOnWire_evolvePure_quditBasis finFunctionFinEquiv t + hadamardC_mem_unitaryGroup f + +/-- **The qubit Hadamard acts as its matrix column.** On a computational-basis state `|z⟩` the +one-qubit Hadamard gate `hadamardGate` produces the superposition `∑_w hadamardC w z · |w⟩`, i.e. +`|±⟩` for `z = 0, 1`. The `d = 2` case of the column action `Matrix.toEuclideanCLM_apply_single`, +read through `hadamardGate_op` and `qubitBasis_vec`. This is the single-wire factor the tower +re-expression of the Figure 5.1 Hadamard (`Core/QftTowerHadamard`) matches the register two-term +superposition `qftHadamardEvolution_evolvePure_quditBasis` against. -/ +theorem hadamardGate_evolvePure_qubitBasis_sum (z : Fin 2) : + (hadamardGate.evolvePure (qubitBasis z)).vec + = ∑ w : Fin 2, hadamardC w z • (qubitBasis w).vec := by + rw [Evolution.evolvePure_vec, hadamardGate_op, qubitBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single hadamardC z).trans (Finset.sum_congr rfl fun w _ => ?_) + exact congrArg (hadamardC w z • ·) (qubitBasis_vec w).symm + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QftSwapEvolution.lean b/LeanPool/AxQM/Postulates/API/QftSwapEvolution.lean new file mode 100644 index 0000000000..5512dde3df --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QftSwapEvolution.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuditGate +public import LeanPool.AxQM.Concrete.QftGateCircuit +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# The Figure 5.1 swap layer as an `Evolution`, and its computational-basis action (N&C Problem 5.2) + +The whole-circuit measured-QFT reduction (Problem 5.2) reads the Figure 5.1 QFT circuit on the +`(n+1)`-qubit control tower `qtower n qubit` as a **product of wire-addressed tower gates** +(`qftTowerEvolution_eq_map_congr_prod`), so each transported Figure 5.1 gate must be re-expressed as +such a tower gate. The Figure 5.1 gates come in three shapes — the wire-reversal **swap** layer, the +**Hadamards**, and the **controlled-`Rₖ`** rotations. This file supplies the ingredient the *swap* +re-expression needs: the swap layer as a named `Evolution` on the single `2ⁿ`-level register, with +its action on the computational basis computed. + +## What is formalised + +* `quditGate_permGate_evolvePure_quditBasis` — a **reusable bridge**: the `quditGate` promotion of a + `permGate` (a classical reversible / basis-permutation matrix) realises that permutation on the + computational basis, `quditGate (permGate enc σ) |enc x⟩ = |enc (σ x)⟩`. Proved from the column + action of `Matrix.toEuclideanCLM` on a standard basis vector + (`Matrix.toEuclideanCLM_apply_single`) and the entry form of `permGate` (`permGate_apply`): the + `enc x`-column of `permGate enc σ` is the indicator of `enc (σ x)`. +* `qftSwapEvolution n` — the **Figure 5.1 swap (wire-reversal) layer as an `Evolution`**: the + `quditGate` promotion of the Concrete swap matrix + `permGate finFunctionFinEquiv (qftBitReversal n)` (the first gate of `Concrete.qftGateSequence`). +* `qftSwapEvolution_evolvePure_quditBasis` — its **computational-basis action**: it reverses the + wire labels of a basis ket, + `qftSwapEvolution n |finFunctionFinEquiv f⟩ = |finFunctionFinEquiv (f ∘ Fin.rev)⟩` + (`qftBitReversal` is the wire reversal `f ↦ f ∘ Fin.rev`). The instance of the reusable bridge at + `σ = qftBitReversal n`, `enc = finFunctionFinEquiv`. This is the register-side action the tower + re-expression (`AxQM/Core/QftTowerSwap.lean`) reads through the bridge. + +-/ + +@[expose] public section + +open Matrix + +namespace AxQM + +noncomputable section + +open AxQM.Concrete + +/-- **A `quditGate`-promoted permutation matrix permutes the computational basis.** For an encoding +`enc : (Fin m → Fin 2) ≃ Fin d` of the bit-strings and a permutation `σ` of them, the gate +`quditGate (permGate enc σ)` sends the basis ket `|enc x⟩` to `|enc (σ x)⟩` — the +postulate-`Evolution` realisation of the classical reversible gate whose action on bit-strings is +`σ`. Proved from the column action of `Matrix.toEuclideanCLM` on a standard basis vector +(`Matrix.toEuclideanCLM_apply_single`, giving the `enc x`-column `∑ⱼ (permGate enc σ)ⱼ,ₑₙ𝒸ₓ |j⟩`) +and the entry form `permGate_apply` (that column is the indicator of `enc (σ x)`). Reused by every +Figure 5.1 basis-permutation gate — here the swap layer `qftSwapEvolution`. -/ +theorem quditGate_permGate_evolvePure_quditBasis {m d : ℕ} + (enc : (Fin m → Fin 2) ≃ Fin d) (σ : Equiv.Perm (Fin m → Fin 2)) (x : Fin m → Fin 2) : + (quditGate (permGate_mem_unitaryGroup enc σ)).evolvePure (quditBasis (enc x)) + = quditBasis (enc (σ x)) := by + apply PureState.ext + rw [Evolution.evolvePure_vec, quditGate_op, quditBasis_vec, quditBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single (permGate enc σ) (enc x)).trans ?_ + rw [Finset.sum_eq_single (enc (σ x))] + · rw [permGate_apply, Equiv.symm_apply_apply, ite_eq_left rfl, one_smul] + · intro j _ hj + rw [permGate_apply, Equiv.symm_apply_apply, ite_eq_right hj, zero_smul] + · intro h; exact absurd (Finset.mem_univ _) h + +/-- **The Figure 5.1 swap (wire-reversal) layer as an `Evolution`** on `qudit (2ⁿ)`: the `quditGate` +promotion of the Concrete swap matrix `permGate finFunctionFinEquiv (qftBitReversal n)` — the first +gate of `Concrete.qftGateSequence`, realising the wire-reversing permutation of the QFT circuit's +swap layer. It is unitary (a permutation gate), so `quditGate` applies. It is used in +`AxQM/Core/QftTowerSwap.lean`; its basis action is `qftSwapEvolution_evolvePure_quditBasis`. -/ +def qftSwapEvolution (n : ℕ) : Evolution (qudit (2 ^ n)) := + quditGate (permGate_mem_unitaryGroup finFunctionFinEquiv (qftBitReversal n)) + +/-- **The swap layer reverses the wire labels of a computational-basis ket.** +`qftSwapEvolution n |finFunctionFinEquiv f⟩ = |finFunctionFinEquiv (f ∘ Fin.rev)⟩`: the bit-string +`f` addressing the wires is precomposed with the wire reversal `Fin.rev` (wire `i` receives what +wire `i.rev` carried), because `qftBitReversal n f = f ∘ Fin.rev`. The instance of +`quditGate_permGate_evolvePure_quditBasis` at `σ = qftBitReversal n`, `enc = finFunctionFinEquiv` +(the final step `qftBitReversal n f = fun i => f i.rev` holds definitionally). This is the +register-side action the tower re-expression reads through the register bridge `quditPowTower`. -/ +theorem qftSwapEvolution_evolvePure_quditBasis (n : ℕ) (f : Fin n → Fin 2) : + (qftSwapEvolution n).evolvePure (quditBasis (finFunctionFinEquiv f)) + = quditBasis (finFunctionFinEquiv (fun i => f i.rev)) := by + rw [qftSwapEvolution, quditGate_permGate_evolvePure_quditBasis]; rfl + +end + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuantumChannel.lean b/LeanPool/AxQM/Postulates/API/QuantumChannel.lean new file mode 100644 index 0000000000..c2a8580ac4 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuantumChannel.lean @@ -0,0 +1,164 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumCP +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumTheorem +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumComposition + +/-! +# AxQM.Postulates.API — quantum channels (CPTP maps on states) + +A **quantum channel** is the completely-positive trace-preserving (CPTP) evolution of an open +quantum system: the trace-preserving special case of a Nielsen & Chuang *quantum operation* +(Chapter 8). Abstractly it is a linear superoperator `Φ` on operators that is completely positive +(N&C axiom A3) and trace-preserving (`tr Φ(A) = tr A`, N&C's trace condition with *equality* — a +deterministic process, no measurement outcome discarded). By the operator-sum representation +theorem (N&C Theorem 8.1) such a `Φ` is exactly one of the form `ρ ↦ ∑ₖ Eₖ ρ Eₖ†` with the +**completeness relation** `∑ₖ Eₖ† Eₖ = I`. + +* `AxQM.IsChannel` — the predicate on a state-map `f : State S → State S` saying `f` is a + quantum channel: it is the restriction to states of a completely-positive, trace-preserving + linear superoperator `Φ` on `S.space`. This is the object that Nielsen & Chuang's "unital + channel" of **Problem 8.3** quantifies over — the hypothesis of the qubit converse ("every unital + qubit channel is random-unitary") and the existential of the higher-dimensional counterexample. +* `AxQM.isChannel_of_kraus` — the **operator-sum ⟹ channel** constructor (the + trace-preserving direction of N&C Theorem 8.1): a Kraus family `E` whose operation elements obey + the completeness relation `∑ₖ Eₖ† Eₖ = 1` realises a channel. Complete positivity is + `krausSumₗ_isCompletelyPositive` (unconditional); trace preservation is `trace_krausSumₗ` + (`tr(∑ₖ Eₖ ρ Eₖ†) = tr((∑ₖ Eₖ† Eₖ) ρ) = tr ρ`) using the completeness relation. This is the + standard way to exhibit a concrete channel (random-unitary averages, the Werner–Holevo channel, + …) and is reused in both parts of Problem 8.3. + +`IsChannel` is phrased in terms of the density operator `State.op`, operators +`S.space →L[ℂ] S.space`, and `LinearMap.trace`, complete positivity and the operator-sum map +`krausSumₗ`, exactly like `maximallyMixedState`, `RandomUnitaryChannel`, and the ensemble mixture. + +## Design notes + +* **Why a predicate on `State S → State S`, not a bundled `Φ`.** The companion predicates + `IsUnital` and `IsRandomUnitary` (Problem 8.3) are already phrased on `f : State S → State S`, so + keeping `IsChannel` in the same shape lets Problem 8.3's claims read uniformly + (`IsChannel f → IsUnital f → IsRandomUnitary f`, and `∃ f, IsChannel f ∧ IsUnital f ∧ + ¬ IsRandomUnitary f`). The *linear* superoperator `Φ` — which carries the completely-positive / + trace-preserving content that a bare `State → State` map cannot — is existentially bundled: a + state-map is a channel exactly when *some* CPTP `Φ` restricts to it. +* **Why CP + trace-preserving abstractly (not "has an operator-sum with `∑ Eₖ†Eₖ = 1`").** Both are + equivalent by N&C Theorem 8.1, but the abstract CPTP form is the definitional meaning of + "channel" and privileges no particular Kraus representation; the operator-sum direction is + supplied as the constructor `isChannel_of_kraus`, which is what one uses to *build* a channel. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A quantum channel (CPTP map) on the states of `S`.** A state-map `f : State S → State S` is a +**channel** when it is the restriction to states of a linear superoperator `Φ` on the operators of +`S.space` that is + +* **completely positive** (`ContinuousLinearMap.IsCompletelyPositive`, Nielsen & Chuang axiom A3), + and +* **trace-preserving**, `tr Φ(A) = tr A` for every operator `A` (N&C's trace condition with + equality — the process is deterministic). + +i.e. `(f ρ).op = Φ ρ.op` for every state `ρ`. This is Nielsen & Chuang's *trace-preserving quantum +operation*; by the operator-sum representation theorem (N&C Theorem 8.1) it is equivalently a map +`ρ ↦ ∑ₖ Eₖ ρ Eₖ†` with `∑ₖ Eₖ† Eₖ = I` (see `isChannel_of_kraus`). It is the object over which +**Problem 8.3**'s "unital channel" ranges. -/ +def IsChannel (f : State S → State S) : Prop := + ∃ Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (S.space →L[ℂ] S.space), + ContinuousLinearMap.IsCompletelyPositive Φ ∧ + (∀ A : S.space →L[ℂ] S.space, + LinearMap.trace ℂ S.space ↑(Φ A) = LinearMap.trace ℂ S.space ↑A) ∧ + ∀ ρ : State S, (f ρ).op = Φ ρ.op + +/-- **Operator-sum ⟹ channel** — the trace-preserving direction of Nielsen & Chuang Theorem 8.1. +If a finite family of operation elements `E : ι → S.space →L[ℂ] S.space` obeys the **completeness +relation** `∑ₖ Eₖ† Eₖ = I`, then any state-map `f` acting as the operator sum +`(f ρ).op = ∑ₖ Eₖ ρ Eₖ†` is a quantum channel. The witnessing superoperator is the Kraus map +`krausSumₗ E`: it is completely +positive unconditionally (`krausSumₗ_isCompletelyPositive`) and trace-preserving because +`tr(∑ₖ Eₖ ρ Eₖ†) = tr((∑ₖ Eₖ† Eₖ) ρ) = tr(I ρ) = tr ρ` (`trace_krausSumₗ` with the completeness +relation). This is the constructor used to exhibit concrete channels. -/ +theorem isChannel_of_kraus {ι : Type*} [Fintype ι] + (E : ι → S.space →L[ℂ] S.space) + (hE : ∑ i, (ContinuousLinearMap.adjoint (E i)).comp (E i) = 1) + {f : State S → State S} + (hf : ∀ ρ : State S, (f ρ).op = ContinuousLinearMap.krausSumₗ E ρ.op) : + IsChannel f := by + refine ⟨ContinuousLinearMap.krausSumₗ E, + ContinuousLinearMap.krausSumₗ_isCompletelyPositive E, ?_, hf⟩ + intro A + rw [ContinuousLinearMap.trace_krausSumₗ, hE, ContinuousLinearMap.one_def, + ContinuousLinearMap.id_comp] + +/-- **A trace-preserving Kraus family gives a quantum channel** — the existence companion of +`isChannel_of_kraus`. If a finite family of operation elements `E : ι → S.space →L[ℂ] S.space` obeys +the completeness relation `∑ₖ Eₖ† Eₖ = I`, then the state-map `ρ ↦ ∑ₖ Eₖ ρ Eₖ†` exists as a genuine +quantum channel (`IsChannel`): the operator sum sends a density operator to a density operator +(`ContinuousLinearMap.isDensityOp_krausSumₗ`), defining the map on `State S`, and it is a channel by +`isChannel_of_kraus`. Use this to *construct* a channel from a completeness-satisfying Kraus family +(e.g. the recovery of N&C Theorem 10.1), rather than being handed the state-map. -/ +theorem exists_isChannel_of_completeness {ι : Type*} [Fintype ι] + (E : ι → S.space →L[ℂ] S.space) + (hE : ∑ i, (ContinuousLinearMap.adjoint (E i)).comp (E i) = 1) : + ∃ f : State S → State S, + IsChannel f ∧ ∀ ρ : State S, (f ρ).op = ContinuousLinearMap.krausSumₗ E ρ.op := + ⟨fun ρ => ⟨ContinuousLinearMap.krausSumₗ E ρ.op, + ContinuousLinearMap.isDensityOp_krausSumₗ E hE ρ.isDensity⟩, + isChannel_of_kraus E hE fun _ => rfl, fun _ => rfl⟩ + +/-- **Quantum channels are closed under composition.** If `f` and `g` are quantum channels of the +system `S` (`IsChannel`), then so is their composite `f ∘ g`, `fun ρ ↦ f (g ρ)` — the first +argument `f` being the *outer* map, matching the convention of `isRandomUnitary_comp` and +`RandomUnitaryChannel.comp` (whose action is `C.apply (D.apply ρ)`). The witnessing superoperator is +`Φ_f ∘ₗ Φ_g`: it is trace-preserving because each factor is (`tr Φ_f(Φ_g A) = tr Φ_g A = tr A`), and +it is completely positive by the **composition of quantum operations** (Nielsen & Chuang, +Exercise 8.6): each factor is a quantum operation (`SatisfiesOperationAxioms`, being completely +positive and — since trace-*preserving* — trace-non-increasing), hence has a Kraus representation +(the operator-sum theorem, N&C Theorem 8.1, +`ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum`), and the composite of two +operator-sum maps is again a quantum operation +(`ContinuousLinearMap.IsOperatorSum.comp_satisfiesAxioms`, Kraus family the products `{Fⱼ Eᵢ}`); +its completeness gives the complete positivity of `Φ_f ∘ₗ Φ_g`. + +This is the State-level companion of Exercise 8.6 (whose formal core, the composition of +operator-sum maps, is in `ToMathlib/`). It is the closure property the qubit converse of +**Problem 8.3** uses to *diagonalise* a unital qubit channel: conjugating a channel by the unitary +rotations realising the singular-value rotations `O₁, O₂` of its Bloch matrix — unitary +conjugations are themselves channels — yields a channel with diagonal Bloch action, on which the +complete-positivity (Fujiwara–Algoet) analysis is carried out. -/ +theorem isChannel_comp {f g : State S → State S} (hf : IsChannel f) (hg : IsChannel g) : + IsChannel (fun ρ => f (g ρ)) := by + obtain ⟨Φf, hΦfCP, hΦfTP, hfop⟩ := hf + obtain ⟨Φg, hΦgCP, hΦgTP, hgop⟩ := hg + -- Each factor is a quantum operation (CP + trace-non-increasing, the latter from + -- trace-preservation), hence has a Kraus representation by the operator-sum theorem. + obtain ⟨_, _, E, hE⟩ := + (ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum Φg).mp + ⟨hΦgCP, fun ρ _ => le_of_eq (by rw [hΦgTP ρ])⟩ + obtain ⟨_, _, F, hF⟩ := + (ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum Φf).mp + ⟨hΦfCP, fun ρ _ => le_of_eq (by rw [hΦfTP ρ])⟩ + -- The composite is a quantum operation (Exercise 8.6); take its completely-positive component. + refine ⟨Φf ∘ₗ Φg, (hE.comp_satisfiesAxioms hF).1, ?_, ?_⟩ + · intro A + rw [LinearMap.comp_apply, hΦfTP (Φg A), hΦgTP A] + · intro ρ + rw [hfop, hgop, LinearMap.comp_apply] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuantumErrorCorrection.lean b/LeanPool/AxQM/Postulates/API/QuantumErrorCorrection.lean new file mode 100644 index 0000000000..da88248e54 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuantumErrorCorrection.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuantumChannel +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumErrorCorrection + +/-! +# AxQM.Postulates.API — quantum error-correction conditions (N&C, Theorem 10.1) + +Nielsen & Chuang's **Theorem 10.1** (the *quantum error-correction conditions*, p. 436) is the +characterisation of when a noise process can be reversed on a code: + +QEC conditions: R correcting E on C exists iff P Ei-dag Ej P = alpha_ij P for Hermitian alpha. + +This file states the result over a quantum system `S : QSystem`: the code +projector `P`, the noise's operation elements `E`, and the recovery `R` are operators on the +system's state space `S.space`, and the recovery is exhibited as a genuine quantum channel +(`AxQM.IsChannel`) acting on the system's states (`State S`). The operator +theory itself — both directions of the biconditional and the explicit recovery construction — is +in `ToMathlib/Analysis/InnerProductSpace/QuantumErrorCorrection.lean` +(`ContinuousLinearMap.satisfiesKLConditions_iff_exists_correction`), as for N&C +Theorems 8.1/8.2. The statement of Theorem 10.1 is in [upstream `AxQM/NC/Ch10/Theorem10_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Theorem10_1.lean). + +## Contents + +* `AxQM.SatisfiesQECConditions` — the **quantum error-correction conditions** as a + predicate on a code projector `P` and noise operation elements `E`: + `∃ Hermitian α, P Eᵢ† Eⱼ P = αᵢⱼ P` (N&C Eq. (10.16)). +* `AxQM.satisfiesQECConditions_iff_exists_correction` — **Theorem 10.1**, as the + biconditional: `SatisfiesQECConditions P E ↔` there exists a trace-preserving recovery family + `R` (`∑ₒ Rₒ† Rₒ = 1`) correcting `E` on the code. +* `AxQM.SatisfiesQECConditions.exists_correctionChannel` — **the physical reading**: if + the QEC conditions hold, there is a recovery **channel** `rec` (`IsChannel`) and a single + state-independent `λ ≥ 0` such that on every code state `ρ`, applying the noise `E` and then the + recovery returns `ρ` to `λ • ρ` (N&C's `R(E(ρ)) ∝ ρ`, Eq. (10.15), with a *uniform* constant). + +The statements are phrased with operators `S.space →L[ℂ] S.space` and the density operator +`State.op`. Compare the neighbouring Theorem 10.2 +(`AxQM/Postulates/API/ErrorCorrectionDiscretization.lean`). +-/ + +@[expose] public section + +open scoped Matrix + +noncomputable section + +namespace AxQM + +universe uι + +variable {S : QSystem} {ι : Type uι} [Fintype ι] + +/-- **The quantum error-correction conditions** (Nielsen & Chuang, Theorem 10.1, Eq. (10.16)), as a +predicate on a quantum system `S`. For a code projector `P : S.space →L[ℂ] S.space` +and a finite family of noise operation elements `E : ι → S.space →L[ℂ] S.space`, the conditions hold +when there is a **Hermitian** matrix `α` with `P Eᵢ† Eⱼ P = αᵢⱼ P` for all `i, j` +(`ContinuousLinearMap.SatisfiesKLConditions`). This is N&C's "`P Eᵢ† Eⱼ P = αᵢⱼ P` for some +Hermitian matrix `α`" — the condition the theorem characterises correctability by. -/ +def SatisfiesQECConditions (P : S.space →L[ℂ] S.space) (E : ι → S.space →L[ℂ] S.space) : Prop := + ∃ α : Matrix ι ι ℂ, α.IsHermitian ∧ ContinuousLinearMap.SatisfiesKLConditions P E α + +/-- **Nielsen & Chuang, Theorem 10.1, for a quantum system.** For a **nonzero** orthogonal code +projector `P` (self-adjoint idempotent) on a quantum system `S` and a finite family of noise +operation elements `E`, the quantum error-correction conditions hold **iff** there is a +**trace-preserving** recovery family `R` (`∑ₒ Rₒ† Rₒ = 1` — an error-correction operation) that +**corrects** `E` on the code (`ContinuousLinearMap.Corrects P E R`: the composed noise-then-recovery +operator sum returns every operator supported on the code to a scalar multiple of itself). + +This is the physics reading of the operator biconditional +`ContinuousLinearMap.satisfiesKLConditions_iff_exists_correction`, for the +system `S` (its state space `S.space`). No assumption is made that `E` is itself a valid +quantum operation (`∑ᵢ Eᵢ† Eᵢ ≤ 1`): the characterisation holds for **any** family of operation +elements, a faithful generalisation of N&C's statement (which takes `E` a quantum operation). -/ +theorem satisfiesQECConditions_iff_exists_correction {P : S.space →L[ℂ] S.space} + {E : ι → S.space →L[ℂ] S.space} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) : + SatisfiesQECConditions P E ↔ + ∃ (κ : Type uι) (_ : Fintype κ) (R : κ → S.space →L[ℂ] S.space), + (∑ o, ContinuousLinearMap.adjoint (R o) ∘L R o = 1) ∧ + ContinuousLinearMap.Corrects P E R := + (ContinuousLinearMap.satisfiesKLConditions_iff_exists_correction hP hPidem hP0).symm + +/-- **The physical reading of the sufficiency of the quantum error-correction conditions** (Nielsen +& Chuang, Theorem 10.1). If the QEC conditions hold for a nonzero orthogonal code projector `P` and +noise operation elements `E`, then there is an **error-correction channel** +`rec : State S → State S` (a genuine quantum channel, `IsChannel`) with Kraus family `R`, and a +**single** nonnegative constant `λ` — depending only on `P`, `E`, `R`, not on the state — such that +for **every** code state `ρ` +(`P ρ P = ρ`), + + `krausSumₗ R (krausSumₗ E ρ) = λ • ρ`. + +The recovery channel's operator action is `krausSumₗ R` (`hrec`), so the displayed identity says the +composed noise-then-recovery process returns every code state to the *same* scalar multiple of +itself — N&C's `R(E(ρ)) ∝ ρ` (Eq. (10.15)) with a **state-independent** constant `λ`, the hallmark +of genuine error-correction (it preserves code-state superpositions). The uniform `λ ≥ 0` is N&C's +remark that the proportionality factor "must be a constant, if both sides are to be linear" +(Eq. (10.28)); it is derived, not assumed (`Corrects.exists_nonneg_forall_eq_smul`). -/ +theorem SatisfiesQECConditions.exists_correctionChannel {P : S.space →L[ℂ] S.space} + {E : ι → S.space →L[ℂ] S.space} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (h : SatisfiesQECConditions P E) : + ∃ (κ : Type uι) (_ : Fintype κ) (R : κ → S.space →L[ℂ] S.space) (rec : State S → State S), + IsChannel rec ∧ (∀ ρ : State S, (rec ρ).op = ContinuousLinearMap.krausSumₗ R ρ.op) ∧ + ∃ lam : ℝ, 0 ≤ lam ∧ ∀ ρ : State S, P ∘L ρ.op ∘L P = ρ.op → + ContinuousLinearMap.krausSumₗ R (ContinuousLinearMap.krausSumₗ E ρ.op) + = (lam : ℂ) • ρ.op := by + obtain ⟨α, hα, hE⟩ := h + obtain ⟨κ, hκ, R, hR, hcorr⟩ := + ContinuousLinearMap.corrects_of_satisfiesKLConditions hP hPidem hP0 hα hE + let : Fintype κ := hκ + obtain ⟨rec, hrecCh, hrecOp⟩ := exists_isChannel_of_completeness R hR + obtain ⟨lam, hlam0, hlam⟩ := hcorr.exists_nonneg_forall_eq_smul hP hPidem hP0 + refine ⟨κ, hκ, R, rec, hrecCh, hrecOp, lam, hlam0, fun ρ hρ => ?_⟩ + have hρ' := hlam ρ.op + rwa [hρ] at hρ' + +/-- **Discretization of the quantum error-correction conditions under linear recombination of the +errors** — the QEC-predicate form of Nielsen & Chuang's discretization of errors (Theorem 10.2). If +a code projector `P` and a finite noise error family `E : ι → S.space →L[ℂ] S.space` satisfy the QEC +conditions, then so does **any** family `F : κ → S.space →L[ℂ] S.space` each of whose members is a +linear combination `F k = ∑ i, u i k • E i` of the `E i` (for a matrix `u : Matrix ι κ ℂ` of +scalars). The recombined family is allowed to have a *different* (e.g. larger) number of members +(`κ ≠ ι`). + +This is exactly N&C's principle that "any error process whose operation elements are linear +combinations of a correctable set is itself corrected" (p. 440), stated for the conditions +themselves: the new Hermitian coefficient matrix is the Gram-type conjugate `uᴴ α u` (Hermitian +because `α` is), and the recombined conditions follow from +`ContinuousLinearMap.SatisfiesKLConditions.recombine`. A typical use: a code that corrects the +Pauli set `{I, Zᵢ}` automatically corrects any set of projectors/operators built from them, since +each is a linear combination of the `Zᵢ`. -/ +theorem SatisfiesQECConditions.recombine {κ : Type*} + {P : S.space →L[ℂ] S.space} {E : ι → S.space →L[ℂ] S.space} + (h : SatisfiesQECConditions P E) (u : Matrix ι κ ℂ) {F : κ → S.space →L[ℂ] S.space} + (hF : ∀ k, F k = ∑ i, u i k • E i) : + SatisfiesQECConditions P F := by + obtain ⟨α, hα, hE⟩ := h + refine ⟨uᴴ * α * u, Matrix.isHermitian_conjTranspose_mul_mul u hα, ?_⟩ + rw [funext hF] + exact hE.recombine u + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuantumFourierTransform.lean b/LeanPool/AxQM/Postulates/API/QuantumFourierTransform.lean new file mode 100644 index 0000000000..106d90556e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuantumFourierTransform.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Concrete.QuantumFourierTransform +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# AxQM.Postulates.API — the quantum Fourier transform as a unitary evolution + +The concrete `d`-dimensional quantum Fourier transform matrix +`Concrete.qftMatrix d` (Nielsen & Chuang eq. 5.2, `Fₖⱼ = (1/√d)·e^{2πijk/d}`, proved unitary in +`AxQM/Concrete/QuantumFourierTransform.lean`) is promoted here to a genuine unitary `Evolution` +of the qudit register `qudit d`, together with its action on computational-basis states, as used +in Nielsen & Chuang **Problem 5.1** ([upstream `AxQM/NC/Ch5/Problem5_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_1.lean)). + +## What is formalised + +* `qftEvolution d` — the **QFT as a unitary `Evolution (qudit d)`**, whose operator is the concrete + matrix promoted through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`. Unitarity is + transported from `Concrete.qftMatrix_mem_unitaryGroup` by `Unitary.map_mem`. That this typechecks + as an `Evolution` is the content of N&C's remark that the QFT "is a unitary transformation, and + thus can be implemented as the dynamics for a quantum computer." +* `qftEvolution_op_apply_quditBasis` — the **action (5.2)/(5.79)** + `F|j⟩ = ∑ₖ (1/√d)·e^{2πijk/d} |k⟩`: the QFT sends the computational-basis state `|j⟩` to the + explicit Fourier superposition. (`qftEvolution_op_apply_quditBasis_matrix` is the same in the + compact `∑ₖ Fₖⱼ |k⟩` form using the raw matrix entry.) +* `qftFourierImage d j` — the **QFT image state** `∑ₖ (1/√d)·e^{2πijk/d} |k⟩` as a `PureState` + in its own right (normalized, because it is the image of a unit vector under the unitary `F`). +* `qftEvolution_evolvePure_quditBasis` — the **pure-state form** of the action, + `evolvePure F |j⟩ = qftFourierImage d j`: evolving `|j⟩` under the QFT yields the named image + state. Stated for `evolvePure` and `quditBasis`, this + is the result that Problem 5.1 specializes to `p` prime. + +## Design notes + +* **Unitarity transport.** `Matrix.toEuclideanCLM` is a `StarAlgEquiv`, hence a star-monoid + homomorphism, so `Unitary.map_mem` carries `qftMatrix d ∈ unitary (Matrix …)` to + `toEuclideanCLM (qftMatrix d) ∈ unitary (EuclideanSpace … →L …)`, which is precisely the + `Evolution.unitary` obligation. No entrywise recomputation of `F†F = 1` is needed at the operator + level — it is inherited from the matrix. +* **Action proof.** The compact action `qftEvolution_op_apply_quditBasis_matrix` is a direct + instance of the general fact `Matrix.toEuclideanCLM_apply_single` — the `ToMathlib` + lemma `toEuclideanCLM M |j⟩ = ∑ₖ Mₖⱼ |k⟩`, i.e. the operator sends a computational-basis vector to + the matrix column, proved entrywise via `Matrix.ofLp_toEuclideanCLM`. The statements are + phrased over `(quditBasis _).vec` so that the `(qudit d).space` instances stay consistent. +* **General `d`.** The evolution, its unitarity, and the action all hold for every dimension + `d ≥ 1`; Problem 5.1's restriction to `p` prime concerns only the *efficient gate-level circuit*, + documented (not formalised) in [upstream `AxQM/NC/Ch5/Problem5_1.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch5/Problem5_1.lean). The statements here are in full + generality. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +open AxQM.Concrete + +/-- The **quantum Fourier transform on `qudit d`** as a unitary `Evolution` (Nielsen & Chuang +eq. 5.2). Its operator is the concrete matrix `qftMatrix d` (entry `Fₖⱼ = (1/√d)·e^{2πijk/d}`) +promoted through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; it is unitary because +`qftMatrix d` is (`Concrete.qftMatrix_mem_unitaryGroup`), transported by `Unitary.map_mem`. This is +the "dynamics for a quantum computer" realizing the transform. -/ +def qftEvolution (d : ℕ) [NeZero d] : Evolution (qudit d) where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) (qftMatrix d) + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d)) (qftMatrix_mem_unitaryGroup d) + +/-- The underlying operator of `qftEvolution d` is `Matrix.toEuclideanCLM (qftMatrix d)`. -/ +@[simp] +theorem qftEvolution_op (d : ℕ) [NeZero d] : + (qftEvolution d).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) (qftMatrix d) := rfl + +/-- **Action of the QFT on a computational-basis state, compact form:** +`F|j⟩ = ∑ₖ Fₖⱼ |k⟩` with `Fₖⱼ = qftMatrix d k j`. The `(quditBasis _).vec`-phrased instance of the +general fact `Matrix.toEuclideanCLM_apply_single` (`toEuclideanCLM M` acting on `|j⟩` is the +`j`-th column of `M`; here `M = qftMatrix d` and `|i⟩ = quditBasis i`). -/ +theorem qftEvolution_op_apply_quditBasis_matrix (d : ℕ) [NeZero d] (j : Fin d) : + (qftEvolution d).op (quditBasis j).vec + = ∑ k : Fin d, (qftMatrix d k j) • (quditBasis k).vec := + Matrix.toEuclideanCLM_apply_single (qftMatrix d) j + +/-- **Action of the QFT on a computational-basis state** (Nielsen & Chuang eq. 5.2, and eq. 5.79 of +Problem 5.1): `F|j⟩ = ∑ₖ (1/√d)·e^{2πijk/d} |k⟩`. Unfolds the matrix entry of +`qftEvolution_op_apply_quditBasis_matrix` to its literal exponential form (`qftMatrix_apply`). -/ +theorem qftEvolution_op_apply_quditBasis (d : ℕ) [NeZero d] (j : Fin d) : + (qftEvolution d).op (quditBasis j).vec + = ∑ k : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d)) + • (quditBasis k).vec := by + rw [qftEvolution_op_apply_quditBasis_matrix] + refine Finset.sum_congr rfl (fun k _ => ?_) + rw [qftMatrix_apply] + +/-- The **quantum Fourier image state** `F|j⟩ = ∑ₖ (1/√d)·e^{2πijk/d} |k⟩` of the +computational-basis state `|j⟩`, as a `PureState` of `qudit d` (N&C eq. 5.2 / 5.79). +It is normalized because it is the image `(qftEvolution d).op |j⟩` of a unit vector under the +unitary `F` (`Evolution.norm_op_apply`, `quditBasis` normalized). -/ +def qftFourierImage (d : ℕ) [NeZero d] (j : Fin d) : PureState (qudit d) where + vec := ∑ k : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d)) • (quditBasis k).vec + normalized := by + rw [← qftEvolution_op_apply_quditBasis d j, (qftEvolution d).norm_op_apply] + exact (quditBasis j).normalized + +/-- The underlying vector of `qftFourierImage d j` is the explicit Fourier superposition +`∑ₖ (1/√d)·e^{2πijk/d} |k⟩` (Nielsen & Chuang eq. 5.79). -/ +@[simp] +theorem qftFourierImage_vec (d : ℕ) [NeZero d] (j : Fin d) : + (qftFourierImage d j).vec + = ∑ k : Fin d, ((Real.sqrt d : ℂ)⁻¹ + * Complex.exp (2 * Real.pi * Complex.I * ((j : ℕ) * (k : ℕ)) / d)) • (quditBasis k).vec := + rfl + +/-- **The QFT evolution sends `|j⟩` to the Fourier image state** (pure-state form of +Nielsen & Chuang eq. 5.2 / 5.79): `evolvePure F |j⟩ = qftFourierImage d j`. Stated for +`Evolution.evolvePure` and `quditBasis`, this is the statement that Problem 5.1 specializes to +`p` prime. -/ +theorem qftEvolution_evolvePure_quditBasis (d : ℕ) [NeZero d] (j : Fin d) : + (qftEvolution d).evolvePure (quditBasis j) = qftFourierImage d j := by + apply PureState.ext + rw [Evolution.evolvePure_vec, qftFourierImage_vec, qftEvolution_op_apply_quditBasis] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuantumOperation.lean b/LeanPool/AxQM/Postulates/API/QuantumOperation.lean new file mode 100644 index 0000000000..62534577cc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuantumOperation.lean @@ -0,0 +1,128 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumTheorem + +/-! +# AxQM.Postulates.API — quantum operations (the operator-sum representation theorem) + +A **quantum operation** is the general (not necessarily deterministic) evolution of an open quantum +system — Nielsen & Chuang's object of Chapter 8, of which a *quantum channel* (CPTP, see +`AxQM.IsChannel`) is the trace-preserving special case. Abstractly it is a linear +superoperator `Φ` on operators that is **completely positive** (N&C axiom A3) and +**trace-non-increasing** (`re tr Φ(A) ≤ re tr A` for positive `A`; N&C axiom A1, so that +`tr[Φ(ρ)] ≤ 1` is a probability). By the operator-sum representation theorem (N&C **Theorem 8.1**) +such a `Φ` is exactly one of the form `ρ ↦ ∑ₖ Eₖ ρ Eₖ†` with the **trace condition** +`∑ₖ Eₖ† Eₖ ≤ I` — the inequality (not the equality of a channel), since a general operation may +occur with probability `< 1`. + +* `AxQM.IsQuantumOperation` — the predicate on a superoperator `Φ` from the operators of an + **input** system `S` to those of an **output** system `T` saying `Φ` is a quantum operation: + completely positive and trace-non-increasing (`ContinuousLinearMap.SatisfiesOperationAxioms`). + N&C's Theorem 8.1 explicitly allows the input and output Hilbert spaces to differ; the + same-system case is the specialisation `T = S`. This is the abstract quantum-operation object + that the section-8.2 exercises (8.3, 8.5, 8.6, Theorem 8.3, …) refer to. +* `AxQM.isQuantumOperation_iff_isOperatorSum` — **Theorem 8.1 for a quantum system**: `Φ` + is a quantum operation iff it admits an operator-sum (Kraus) representation + `ContinuousLinearMap.IsOperatorSum E Φ` (a finite family `E` with `Φ = krausSumₗ E` and + `∑ₖ Eₖ† Eₖ ≤ 1`). This is `ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum` read + at the physical systems `S`, `T`. +* `AxQM.IsQuantumOperation.isPositive_apply` / + `AxQM.IsQuantumOperation.re_trace_apply_le_one` — the physical meaning for + states: a quantum operation sends each state `ρ` to a *subnormalised density operator* + `Φ ρ` — a positive operator whose trace `tr[Φ(ρ)] ≤ 1` is the probability the process occurs. + +`IsQuantumOperation` is phrased in terms of operators `S.space →L[ℂ] S.space`, the density +operator `State.op`, `SatisfiesOperationAxioms`, `krausSumₗ` and `LinearMap.trace`, exactly like the +trace-preserving `IsChannel`. The underlying operator-sum theorem is general Hilbert-space +mathematics, proved in `ToMathlib/Analysis/InnerProductSpace/OperatorSumTheorem.lean`. + +## Design notes + +* **Why a predicate on a superoperator `Φ`, not a map `State S → State S`.** A quantum operation is + generally *not* trace-preserving, so `Φ ρ` is a subnormalised density operator (`tr ≤ 1`), which + is **not** a `State` (a `State` has trace one). The trace-preserving channel `IsChannel` can be + phrased on `State S → State S`; a general operation cannot, so it is stated on the superoperator, + matching how N&C and the section-8.2 development (`SatisfiesOperationAxioms Φ`, + `IsOperatorSum E Φ`) speak of it. The bridge lemmas re-expose the physical content on `State`. +* **Axiom A2.** Convex-linearity on density operators is subsumed by modelling `Φ` as a genuine + `ℂ`-linear superoperator (the unique linear extension of a convex-linear map, the density + operators spanning the operator space); see `ContinuousLinearMap.SatisfiesOperationAxioms`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **A quantum operation from system `S` to system `T`** (Nielsen & Chuang, Chapter 8; the object +of the operator-sum representation theorem, **Theorem 8.1**). A superoperator +`Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (T.space →L[ℂ] T.space)` is a quantum operation when it is + +* **completely positive** (`ContinuousLinearMap.IsCompletelyPositive`, N&C axiom A3), and +* **trace-non-increasing** (`ContinuousLinearMap.IsTraceNonIncreasing`, N&C axiom A1: for every + positive operator `A`, `re tr(Φ A) ≤ re tr A`, so that `tr[Φ(ρ)] ≤ 1` on a state `ρ`). + +Axiom A2 (convex-linearity on density operators) is subsumed by the `ℂ`-linearity of `Φ`. This is +`ContinuousLinearMap.SatisfiesOperationAxioms Φ`, read as a physical condition on a map between the +operators of two quantum systems. N&C allows the input system `S` and output system `T` to differ; +the same-system case is `T = S`. By `isQuantumOperation_iff_isOperatorSum` (Theorem 8.1) this is +equivalent to `Φ` having an operator-sum representation `ρ ↦ ∑ₖ Eₖ ρ Eₖ†` with `∑ₖ Eₖ† Eₖ ≤ I`. -/ +def IsQuantumOperation (Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (T.space →L[ℂ] T.space)) : Prop := + ContinuousLinearMap.SatisfiesOperationAxioms Φ + +/-- **Nielsen–Chuang Theorem 8.1, for a quantum system.** A superoperator `Φ` between the operators +of quantum systems `S` and `T` is a quantum operation (`IsQuantumOperation`, i.e. completely +positive and trace-non-increasing — axioms A1, A2, A3) **iff** it admits an operator-sum (Kraus) +representation: a finite family of operation elements `E : ι → (S.space →L[ℂ] T.space)` with +`Φ ρ = ∑ₖ Eₖ ρ Eₖ†` (`Φ = krausSumₗ E`) and the trace condition `∑ₖ Eₖ† Eₖ ≤ 1` +(`ContinuousLinearMap.IsOperatorSum E Φ`). + +This is the operator-sum theorem +`ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum` for the systems `S`, `T`. -/ +theorem isQuantumOperation_iff_isOperatorSum + (Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (T.space →L[ℂ] T.space)) : + IsQuantumOperation Φ ↔ + ∃ (ι : Type) (_ : Fintype ι) (E : ι → S.space →L[ℂ] T.space), + ContinuousLinearMap.IsOperatorSum E Φ := by + unfold IsQuantumOperation + exact ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum Φ + +/-- **A quantum operation sends a state to a positive operator.** For a quantum operation `Φ` and a +state `ρ` of the input system, the output `Φ ρ` is a positive operator — a valid (unnormalised) +density operator, part of the physical requirement A3. Proved from the operator-sum representation +(`isQuantumOperation_iff_isOperatorSum`): `Φ ρ.op = ∑ₖ Eₖ ρ Eₖ†` is a sum of conjugations of the +positive operator `ρ.op` (`ContinuousLinearMap.krausSumₗ_isPositive`). -/ +theorem IsQuantumOperation.isPositive_apply + {Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (T.space →L[ℂ] T.space)} + (hΦ : IsQuantumOperation Φ) (ρ : State S) : (Φ ρ.op).IsPositive := by + obtain ⟨ι, _, E, hE⟩ := (isQuantumOperation_iff_isOperatorSum Φ).mp hΦ + rw [hE.1] + exact ContinuousLinearMap.krausSumₗ_isPositive E ρ.isPositive_op + +/-- **A quantum operation does not increase probability** (Nielsen & Chuang axiom A1). For a quantum +operation `Φ` and a state `ρ` of the input system, `tr[Φ(ρ)] ≤ 1`: the trace of the output — the +probability that the process represented by `Φ` occurs on input `ρ` — is at most one. Immediate from +trace-non-increasing applied to the density operator `ρ.op` (positive, trace one). -/ +theorem IsQuantumOperation.re_trace_apply_le_one + {Φ : (S.space →L[ℂ] S.space) →ₗ[ℂ] (T.space →L[ℂ] T.space)} + (hΦ : IsQuantumOperation Φ) (ρ : State S) : + RCLike.re (LinearMap.trace ℂ T.space (Φ ρ.op : T.space →ₗ[ℂ] T.space)) ≤ 1 := by + obtain ⟨_, hTNI⟩ := hΦ + have h := hTNI ρ.op (ContinuousLinearMap.nonneg_iff_isPositive.2 ρ.isPositive_op) + rwa [ρ.trace_op_eq_one, RCLike.one_re] at h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Qubit.lean b/LeanPool/AxQM/Postulates/API/Qubit.lean new file mode 100644 index 0000000000..c700e2af10 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Qubit.lean @@ -0,0 +1,518 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Concrete.Pauli +public import LeanPool.AxQM.Concrete.PauliOuterProduct +public import LeanPool.AxQM.Concrete.PauliEigenvectors +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.MatrixToEuclideanCLM + +/-! +# AxQM.Postulates.API — the qubit and its Pauli vector observables + +The two-level system and its spin observables. + +* `qubit` — the two-level quantum system, `QSystem.ofModel (EuclideanSpace ℂ (Fin 2))`. +* `pauliObservable n` (`n · σ`) — for a real three-vector `n`, the **observable** + `n₀ X + n₁ Y + n₂ Z` on the qubit, obtained by promoting the concrete Pauli matrix + `Concrete.pauliDot n` to a continuous linear operator via the C\*-algebra isomorphism + `Matrix.toEuclideanCLM`. It is self-adjoint because `n · σ` is Hermitian + (`Concrete.pauliDot_isHermitian`). +* `pauliObservable_op_mul_self` — for a **unit** vector `n`, `(n · σ)² = 1` in the operator + ring, the involution property. This is the operator-level counterpart of + `Concrete.pauliDot_mul_self_of_unit`, and is the key input that makes the two-qubit Pauli + operators a CHSH tuple (Nielsen & Chuang Problem 2.3 / Tsirelson's inequality). +* `qubitBasis i` (`|i⟩`) — the **computational-basis pure state** `|0⟩` / `|1⟩` of the qubit, + the normalized standard basis vector `EuclideanSpace.single i 1`. These are the states + `|0⟩, |1⟩` used throughout Chapter 2 (e.g. the input `|0⟩` of Exercises 2.59 and 2.61). +* `pauliXObservable` (`X`) / `pauliYObservable` (`Y`) / `pauliZObservable` (`Z`) — the **Pauli `X` / + `Y` / `Z` observables** on the qubit, the Pauli vector observables for the unit directions + `(1, 0, 0)` / `(0, 1, 0)` / `(0, 0, 1)`. `pauliXObservable_op` / `pauliYObservable_op` / + `pauliZObservable_op` identify their operators with `Matrix.toEuclideanCLM Concrete.pauliX` / + `Concrete.pauliY` / `Concrete.pauliZ`, and `pauliXObservable_op_mul_self` records `X² = 1` (the + special case of the involution at `(1, 0, 0)`). +* `pauliXObservable_apply_toLp` / `pauliYObservable_apply_toLp` / `pauliZObservable_apply_toLp` + — the **operator-application bridges** `σ (WithLp.toLp 2 v) = WithLp.toLp 2 (σ.mulVec v)`, + lifting a concrete matrix eigenvalue equation `pauli* *ᵥ v = μ • v` to the observable + (e.g. the Pauli-eigenstate certifications of Exercise 4.1). +* `pauliXObservable_apply_{xPlus,xMinus}` / `pauliYObservable_apply_{yPlus,yMinus}` / + `pauliZObservable_apply_{ket0,ket1}` — the **operator eigenvalue equations** + `σ (toLp v) = ±1 • toLp v` of the six normalized Pauli eigenvectors (Exercise 2.11), the + inputs to Exercise 4.1's eigenstate certifications (the `-1` cases state the eigenvalue as + `((-1 : ℝ) : ℂ)`). +* `qubitBasis_inner_qubitBasis` — **orthonormality** `⟨i|j⟩ = δᵢⱼ` of the computational basis. +* `pauliXObservable_inner_qubitBasis` / `pauliZObservable_inner_qubitBasis` — the **basis matrix + elements** `⟨i|X|j⟩ = Xᵢⱼ` / `⟨i|Z|j⟩ = Zᵢⱼ`, reading the Pauli operator's entries off the + concrete matrices. These feed the two-qubit expectation computations (e.g. Exercise 2.66). + +## Design notes + +* The bridge is `Matrix.toEuclideanCLM : Matrix n n ℂ ≃⋆ₐ[ℂ] EuclideanSpace ℂ n →L[ℂ] …`, a + `⋆`-algebra *equivalence*. Because it is a `⋆`-algebra homomorphism it transports every + structural fact about `Concrete.pauliDot n` to its operator: `map_star` turns Hermiticity + into self-adjointness, and `map_mul`/`map_one` turn `(n·σ)² = I` into `op * op = 1`. No + entrywise operator computation is needed. +* `pauliObservable` is defined for an *arbitrary* `n` (self-adjointness holds unconditionally); + the unit-vector hypothesis is required only for the involution lemma, and is threaded there, + matching how Problem 2.3 restricts to unit vectors `q_vec, r_vec, s_vec, t_vec`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **qubit**: the two-level quantum system, whose state space is the standard +two-dimensional complex Hilbert space `EuclideanSpace ℂ (Fin 2)`. -/ +def qubit : QSystem := QSystem.ofModel (EuclideanSpace ℂ (Fin 2)) + +/-- **The qubit state space is nontrivial** (it is `EuclideanSpace ℂ (Fin 2)`, dimension `2`). Lets +constructions that need a nonzero space — e.g. `maximallyMixedState qubit` — resolve the +`Nontrivial` side-condition automatically. -/ +instance : Nontrivial qubit.space := + inferInstanceAs (Nontrivial (EuclideanSpace ℂ (Fin 2))) + +/-- **The qubit has dimension `2`**: `finrank ℂ qubit.space = 2`, since `qubit.space` is +`EuclideanSpace ℂ (Fin 2)`. -/ +theorem finrank_qubit_space : Module.finrank ℂ qubit.space = 2 := by + change Module.finrank ℂ (EuclideanSpace ℂ (Fin 2)) = 2 + exact finrank_euclideanSpace_fin + +/-- The **computational basis state `|0⟩ = (1, 0)`** as a pure state of the qubit — the standard +basis ket `Concrete.ket 0` viewed in `EuclideanSpace`. The fundamental single-qubit state, shared by +all qubit items (measurements, expectations, …). -/ +def qubitKet0 : PureState qubit where + vec := WithLp.toLp 2 (Concrete.ket 0) + normalized := by + have h : ‖(WithLp.toLp 2 (Concrete.ket 0) : EuclideanSpace ℂ (Fin 2))‖ = 1 := by + rw [EuclideanSpace.norm_eq] + simp [Concrete.ket, Fin.sum_univ_two] + exact h + +@[simp] +theorem qubitKet0_vec : qubitKet0.vec = WithLp.toLp 2 (Concrete.ket 0) := rfl + +/-- The **Pauli vector observable** `n · σ = n₀ X + n₁ Y + n₂ Z` on the qubit, for a real +three-vector `n`. Its operator is the concrete Hermitian matrix `Concrete.pauliDot n` promoted +to a continuous linear map through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; +self-adjointness follows from `Concrete.pauliDot_isHermitian` since that isomorphism preserves +`star`. These are the observables `Q, R, S, T` of Nielsen & Chuang Problem 2.3. -/ +def pauliObservable (n : Fin 3 → ℝ) : Observable qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.pauliDot n) + selfAdjoint := + (Concrete.pauliDot_isHermitian n).isSelfAdjoint.map + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + +/-- The underlying operator of `pauliObservable n` is the `Matrix.toEuclideanCLM` image of the +concrete matrix `Concrete.pauliDot n`. A `simp` lemma exposing the operator for +operator computations (e.g. assembling the two-qubit CHSH tuple of Problem 2.3). -/ +@[simp] +theorem pauliObservable_op (n : Fin 3 → ℝ) : + (pauliObservable n).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.pauliDot n) := + rfl + +/-- **The Pauli vector observable of a unit vector is an involution:** `(n · σ)² = 1` in the +qubit's operator ring, for a unit vector `n` (`n₀² + n₁² + n₂² = 1`). This transports the +concrete matrix identity `Concrete.pauliDot_mul_self_of_unit` across the `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM` (via `map_mul` and `map_one`). It is the input that makes +`Q, R, S, T` self-adjoint involutions — hence a CHSH tuple — in Problem 2.3. -/ +theorem pauliObservable_op_mul_self {n : Fin 3 → ℝ} + (h : n 0 ^ 2 + n 1 ^ 2 + n 2 ^ 2 = 1) : + (pauliObservable n).op * (pauliObservable n).op = 1 := by + -- The operator multiplication lives at `↑qubit →L ↑qubit`; restate it at the definitionally + -- equal `EuclideanSpace ℂ (Fin 2) →L …` so the `⋆`-algebra homomorphism lemmas apply. + change Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.pauliDot n) + * Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.pauliDot n) = 1 + rw [← map_mul, Concrete.pauliDot_mul_self_of_unit h, map_one] + +/-- The **computational-basis pure state** `|i⟩` of the qubit: the standard basis vector +`EuclideanSpace.single i 1`, which is normalized because `‖EuclideanSpace.single i 1‖ = ‖(1 : ℂ)‖ += 1` (`EuclideanSpace.norm_single`). Instantiating `i = 0` / `i = 1` gives the states `|0⟩` and +`|1⟩` of Chapter 2. -/ +def qubitBasis (i : Fin 2) : PureState qubit where + vec := EuclideanSpace.single i 1 + normalized := by + change ‖EuclideanSpace.single i (1 : ℂ)‖ = 1 + simp + +/-- The underlying unit vector of the computational-basis state `|i⟩` is `EuclideanSpace.single +i 1`. A `simp` lemma exposing the state vector for inner-product computations. -/ +@[simp] +theorem qubitBasis_vec (i : Fin 2) : + (qubitBasis i).vec = EuclideanSpace.single i 1 := rfl + +/-- The **Pauli `X` observable** on the qubit: the Pauli vector observable `n · σ` for the unit +direction `n = (1, 0, 0)`, i.e. `X = pauliObservable ![1, 0, 0]`. Constructed through the +established `pauliObservable` API so that `X² = 1` is the involution +`pauliObservable_op_mul_self` at a unit vector. -/ +def pauliXObservable : Observable qubit := pauliObservable ![1, 0, 0] + +/-- The operator of the Pauli `X` observable is `Matrix.toEuclideanCLM Concrete.pauliX`: the +Pauli direction `(1, 0, 0)` collapses `Concrete.pauliDot ![1, 0, 0]` to the concrete matrix +`Concrete.pauliX = !![0, 1; 1, 0]`. -/ +@[simp] +theorem pauliXObservable_op : + pauliXObservable.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX := by + rw [pauliXObservable, pauliObservable_op] + congr 1 + rw [Concrete.pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Concrete.pauliX] + +/-- **`X² = 1`:** the Pauli `X` observable is an involution in the qubit's operator ring. The +special case of `pauliObservable_op_mul_self` at the unit vector `(1, 0, 0)`. -/ +theorem pauliXObservable_op_mul_self : + pauliXObservable.op * pauliXObservable.op = 1 := by + rw [pauliXObservable] + exact pauliObservable_op_mul_self + (by norm_num [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons]) + +/-- The **Pauli `Y` observable** on the qubit: the Pauli vector observable `n · σ` for the unit +direction `n = (0, 1, 0)`, i.e. `Y = pauliObservable ![0, 1, 0]`. Constructed through the +established `pauliObservable` API, mirroring `pauliXObservable`; the `Y`-analogue that the library +lacked (the `Y`-eigenstate certifications of Exercise 4.1 need it as their observable). -/ +def pauliYObservable : Observable qubit := pauliObservable ![0, 1, 0] + +/-- The operator of the Pauli `Y` observable is `Matrix.toEuclideanCLM Concrete.pauliY`: the Pauli +direction `(0, 1, 0)` collapses `Concrete.pauliDot ![0, 1, 0]` to the concrete matrix +`Concrete.pauliY = !![0, -i; i, 0]`. -/ +@[simp] +theorem pauliYObservable_op : + pauliYObservable.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliY := by + rw [pauliYObservable, pauliObservable_op] + congr 1 + rw [Concrete.pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Concrete.pauliY] + +/-- The **Pauli `Z` observable** on the qubit: the Pauli vector observable `n · σ` for the unit +direction `n = (0, 0, 1)`, i.e. `Z = pauliObservable ![0, 0, 1]`. Constructed through the +established `pauliObservable` API, mirroring `pauliXObservable`. -/ +def pauliZObservable : Observable qubit := pauliObservable ![0, 0, 1] + +/-- The operator of the Pauli `Z` observable is `Matrix.toEuclideanCLM Concrete.pauliZ`: the Pauli +direction `(0, 0, 1)` collapses `Concrete.pauliDot ![0, 0, 1]` to the concrete matrix +`Concrete.pauliZ = !![1, 0; 0, -1]`. -/ +@[simp] +theorem pauliZObservable_op : + pauliZObservable.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ := by + rw [pauliZObservable, pauliObservable_op] + congr 1 + rw [Concrete.pauliDot_eq] + ext i j + fin_cases i <;> fin_cases j <;> simp [Concrete.pauliZ] + +/-! ### Operator-level products and (anti)commutators of the Pauli observables + +The single-qubit Pauli operator identities `Z² = 1`, `{X, Z} = {Y, Z} = 0` (N&C eq. 2.75), and the +"raising-operator absorption" `i (X Z) + Y Z = i X + Y`, all lifted from the concrete `2 × 2` +matrices through the `⋆`-algebra map `Matrix.toEuclideanCLM`. They sit beside +`pauliXObservable_op_mul_self` (`X² = 1`) as the shared home for Pauli operator algebra. -/ + +/-- **`Z² = 1`:** the Pauli `Z` observable is an involution in the qubit's operator ring. The +special case of `pauliObservable_op_mul_self` at the unit vector `(0, 0, 1)`. -/ +theorem pauliZObservable_op_mul_self : + pauliZObservable.op * pauliZObservable.op = 1 := by + rw [pauliZObservable] + exact pauliObservable_op_mul_self + (by norm_num [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons]) + +/-- **`Y² = 1`:** the Pauli `Y` observable is an involution in the qubit's operator ring. The +special case of `pauliObservable_op_mul_self` at the unit vector `(0, 1, 0)`. -/ +theorem pauliYObservable_op_mul_self : + pauliYObservable.op * pauliYObservable.op = 1 := by + rw [pauliYObservable] + exact pauliObservable_op_mul_self + (by norm_num [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, + Matrix.cons_val_two, Matrix.tail_cons]) + +/-- **`X Z = −Z X`:** the Pauli `X` and `Z` observables anticommute (N&C eq. 2.75), lifted to the +qubit operator ring through the `⋆`-algebra map `Matrix.toEuclideanCLM`. -/ +theorem pauliXObservable_op_anticomm_pauliZObservable_op : + pauliXObservable.op * pauliZObservable.op = -(pauliZObservable.op * pauliXObservable.op) := by + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + (eq_neg_of_add_eq_zero_left Concrete.pauliX_anticomm_pauliZ) + simp only [map_mul, map_neg] at h + rw [pauliXObservable_op, pauliZObservable_op] + exact h + +/-- **`Y Z = −Z Y`:** the Pauli `Y` and `Z` observables anticommute (N&C eq. 2.75). -/ +theorem pauliYObservable_op_anticomm_pauliZObservable_op : + pauliYObservable.op * pauliZObservable.op = -(pauliZObservable.op * pauliYObservable.op) := by + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + (eq_neg_of_add_eq_zero_left Concrete.pauliY_anticomm_pauliZ) + simp only [map_mul, map_neg] at h + rw [pauliYObservable_op, pauliZObservable_op] + exact h + +/-- **`X Y = −Y X`:** the Pauli `X` and `Y` observables anticommute (N&C eq. 2.75), the third member +of the anticommutation trio alongside `pauliXObservable_op_anticomm_pauliZObservable_op` and +`pauliYObservable_op_anticomm_pauliZObservable_op`. -/ +theorem pauliXObservable_op_anticomm_pauliYObservable_op : + pauliXObservable.op * pauliYObservable.op = -(pauliYObservable.op * pauliXObservable.op) := by + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) + (eq_neg_of_add_eq_zero_left Concrete.pauliX_anticomm_pauliY) + simp only [map_mul, map_neg] at h + rw [pauliXObservable_op, pauliYObservable_op] + exact h + +/-- **Raising-operator absorption `i (X Z) + Y Z = i X + Y`.** The single-qubit raising operator +`i X + Y` (proportional to `σ₊ = (X + i Y)/2` up to a phase) is fixed by *right* multiplication by +`Z`, i.e. `(i X + Y) Z = i X + Y`. Proved from the concrete `2 × 2` identity lifted through +`Matrix.toEuclideanCLM`. -/ +theorem pauliRaising_op_mul_pauliZObservable_op : + Complex.I • (pauliXObservable.op * pauliZObservable.op) + + pauliYObservable.op * pauliZObservable.op + = Complex.I • pauliXObservable.op + pauliYObservable.op := by + have hmat : Complex.I • (Concrete.pauliX * Concrete.pauliZ) + Concrete.pauliY * Concrete.pauliZ + = Complex.I • Concrete.pauliX + Concrete.pauliY := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliX, Concrete.pauliY, Concrete.pauliZ, Matrix.add_apply] + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) hmat + simp only [map_add, map_mul, map_smul] at h + rw [pauliXObservable_op, pauliYObservable_op, pauliZObservable_op] + exact h + +/-- **`Z Y = −i X`:** the Pauli `Z`·`Y` product (N&C eq. 2.40), lifted to the qubit operator ring +through the `⋆`-algebra map `Matrix.toEuclideanCLM`. -/ +theorem pauliZObservable_op_mul_pauliYObservable_op : + pauliZObservable.op * pauliYObservable.op = -Complex.I • pauliXObservable.op := by + have hmat : Concrete.pauliZ * Concrete.pauliY = -Complex.I • Concrete.pauliX := by + ext i j; fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliZ, Concrete.pauliY, Concrete.pauliX, Matrix.mul_apply, + Fin.sum_univ_two, Matrix.smul_apply] + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) hmat + simp only [map_mul, map_smul] at h + rw [pauliZObservable_op, pauliYObservable_op, pauliXObservable_op] + exact h + +/-- **Applying `X` to a `toLp` vector is `X *ᵥ`:** `X (toLp v) = toLp (Concrete.pauliX *ᵥ v)`. The +operator-application bridge that lifts a concrete eigenvalue equation `pauliX *ᵥ v = μ • v` to the +observable `X` (`Matrix.toEuclideanCLM_toLp`, whose `EuclideanSpace`-typed application is +brought to `X.op`'s form by `exact`). -/ +theorem pauliXObservable_apply_toLp (v : Fin 2 → ℂ) : + pauliXObservable.op (WithLp.toLp 2 v) = WithLp.toLp 2 (Concrete.pauliX.mulVec v) := by + rw [pauliXObservable_op]; exact Matrix.toEuclideanCLM_toLp Concrete.pauliX v + +/-- **Applying `Y` to a `toLp` vector is `Y *ᵥ`:** `Y (toLp v) = toLp (Concrete.pauliY *ᵥ v)`. -/ +theorem pauliYObservable_apply_toLp (v : Fin 2 → ℂ) : + pauliYObservable.op (WithLp.toLp 2 v) = WithLp.toLp 2 (Concrete.pauliY.mulVec v) := by + rw [pauliYObservable_op]; exact Matrix.toEuclideanCLM_toLp Concrete.pauliY v + +/-- **Applying `Z` to a `toLp` vector is `Z *ᵥ`:** `Z (toLp v) = toLp (Concrete.pauliZ *ᵥ v)`. -/ +theorem pauliZObservable_apply_toLp (v : Fin 2 → ℂ) : + pauliZObservable.op (WithLp.toLp 2 v) = WithLp.toLp 2 (Concrete.pauliZ.mulVec v) := by + rw [pauliZObservable_op]; exact Matrix.toEuclideanCLM_toLp Concrete.pauliZ v + +/-! ### Operator eigenvalue equations of the Pauli eigenvectors + +The `X`/`Y`/`Z` observables act on the six normalized Pauli eigenvectors of Exercise 2.11 +(`Concrete.xPlus`/…) as multiplication by `±1`, obtained from the concrete matrix eigenvalue +equations `Concrete.pauli*_mulVec_*` through the `_apply_toLp` bridges above. The `−1` cases state +the eigenvalue as `((-1 : ℝ) : ℂ)` so that each feeds `Observable.hasEigenstate_of_smul` directly in +`LeanPool/AxQM/NC/Ch4/Exercise1.lean` (which reads the eigenvalue as a real `μ`). -/ + +/-- `X |+⟩ = |+⟩`: `X`'s `+1` operator eigenvalue equation on `Concrete.xPlus`. -/ +theorem pauliXObservable_apply_xPlus : + pauliXObservable.op (WithLp.toLp 2 Concrete.xPlus) + = (1 : ℂ) • WithLp.toLp 2 Concrete.xPlus := by + rw [pauliXObservable_apply_toLp, Concrete.pauliX_mulVec_xPlus, WithLp.toLp_smul] + +/-- `X |-⟩ = -|-⟩`: `X`'s `-1` operator eigenvalue equation on `Concrete.xMinus`. -/ +theorem pauliXObservable_apply_xMinus : + pauliXObservable.op (WithLp.toLp 2 Concrete.xMinus) + = ((-1 : ℝ) : ℂ) • WithLp.toLp 2 Concrete.xMinus := by + rw [pauliXObservable_apply_toLp, Concrete.pauliX_mulVec_xMinus, WithLp.toLp_smul, + Complex.ofReal_neg, Complex.ofReal_one] + +/-- `Y |+i⟩ = |+i⟩`: `Y`'s `+1` operator eigenvalue equation on `Concrete.yPlus`. -/ +theorem pauliYObservable_apply_yPlus : + pauliYObservable.op (WithLp.toLp 2 Concrete.yPlus) + = (1 : ℂ) • WithLp.toLp 2 Concrete.yPlus := by + rw [pauliYObservable_apply_toLp, Concrete.pauliY_mulVec_yPlus, WithLp.toLp_smul] + +/-- `Y |-i⟩ = -|-i⟩`: `Y`'s `-1` operator eigenvalue equation on `Concrete.yMinus`. -/ +theorem pauliYObservable_apply_yMinus : + pauliYObservable.op (WithLp.toLp 2 Concrete.yMinus) + = ((-1 : ℝ) : ℂ) • WithLp.toLp 2 Concrete.yMinus := by + rw [pauliYObservable_apply_toLp, Concrete.pauliY_mulVec_yMinus, WithLp.toLp_smul, + Complex.ofReal_neg, Complex.ofReal_one] + +/-- `Z |0⟩ = |0⟩`: `Z`'s `+1` operator eigenvalue equation on `Concrete.ket 0`. -/ +theorem pauliZObservable_apply_ket0 : + pauliZObservable.op (WithLp.toLp 2 (Concrete.ket 0)) + = (1 : ℂ) • WithLp.toLp 2 (Concrete.ket 0) := by + rw [pauliZObservable_apply_toLp, Concrete.pauliZ_mulVec_ket_zero, WithLp.toLp_smul] + +/-- `Z |1⟩ = -|1⟩`: `Z`'s `-1` operator eigenvalue equation on `Concrete.ket 1`. -/ +theorem pauliZObservable_apply_ket1 : + pauliZObservable.op (WithLp.toLp 2 (Concrete.ket 1)) + = ((-1 : ℝ) : ℂ) • WithLp.toLp 2 (Concrete.ket 1) := by + rw [pauliZObservable_apply_toLp, Concrete.pauliZ_mulVec_ket_one, WithLp.toLp_smul, + Complex.ofReal_neg, Complex.ofReal_one] + +/-- **`Z |i⟩ = (-1)ⁱ |i⟩`** at the observable operator level: the Pauli `Z` observable acts on the +computational-basis ket `|i⟩` by the eigenvalue `(-1)ⁱ`. The uniform (`i : Fin 2`) form of +`pauliZObservable_apply_ket0` / `pauliZObservable_apply_ket1`, the shared eigenvalue equation +used wherever a `Z` acts on a computational-basis register (e.g. the `Z₁Z₂` coupling Hamiltonian, +the bit-flip syndrome observables). -/ +theorem pauliZObservable_op_apply_qubitBasis (i : Fin 2) : + pauliZObservable.op (qubitBasis i).vec = (-1 : ℂ) ^ (i : ℕ) • (qubitBasis i).vec := by + fin_cases i + · change pauliZObservable.op (WithLp.toLp 2 (Concrete.ket 0)) + = (-1 : ℂ) ^ (0 : ℕ) • WithLp.toLp 2 (Concrete.ket 0) + rw [pow_zero] + exact pauliZObservable_apply_ket0 + · change pauliZObservable.op (WithLp.toLp 2 (Concrete.ket 1)) + = (-1 : ℂ) ^ (1 : ℕ) • WithLp.toLp 2 (Concrete.ket 1) + rw [pow_one] + have h1 := pauliZObservable_apply_ket1 + simp only [Complex.ofReal_neg, Complex.ofReal_one] at h1 + exact h1 + +/-- **`X |i⟩ = |i ⊕ 1⟩`** at the observable operator level: the Pauli `X` observable flips the +computational-basis ket `|i⟩`. The `X` analogue of `pauliZObservable_op_apply_qubitBasis`, reduced +to the matrix action `pauliX ·ᵥ ket i = ket (i+1)` of `Concrete.pauliX = !![0,1;1,0]` on the +standard basis vector `Concrete.ket i`; the shared bit-flip equation used wherever an `X` acts on a +computational-basis register (e.g. the `X⊗X⊗X` block sign-readout of the Shor code). -/ +theorem pauliXObservable_op_apply_qubitBasis (i : Fin 2) : + pauliXObservable.op (qubitBasis i).vec = (qubitBasis (i + 1)).vec := by + have hket : ∀ k : Fin 2, (qubitBasis k).vec = WithLp.toLp 2 (Concrete.ket k) := fun k => by + rw [qubitBasis_vec]; rfl + rw [hket, pauliXObservable_apply_toLp, Concrete.pauliX_mulVec_ket, hket] + +/-- **`Y |i⟩ = i · (-1)ⁱ · |i ⊕ 1⟩`** at the observable operator level: the Pauli `Y` observable +flips the computational-basis ket `|i⟩` with a phase (`Y|0⟩ = i|1⟩`, `Y|1⟩ = -i|0⟩`). The `Y` +analogue of `pauliXObservable_op_apply_qubitBasis` / `pauliZObservable_op_apply_qubitBasis`, reduced +to the matrix action `pauliY ·ᵥ ket i = i(-1)ⁱ • ket (i+1)` of `Concrete.pauliY = !![0,-I;I,0]` on +the standard basis vector `Concrete.ket i`. -/ +theorem pauliYObservable_op_apply_qubitBasis (i : Fin 2) : + pauliYObservable.op (qubitBasis i).vec + = (Complex.I * (-1) ^ (i : ℕ)) • (qubitBasis (i + 1)).vec := by + have hket : ∀ k : Fin 2, (qubitBasis k).vec = WithLp.toLp 2 (Concrete.ket k) := fun k => by + rw [qubitBasis_vec]; rfl + rw [hket, pauliYObservable_apply_toLp, Concrete.pauliY_mulVec_ket, WithLp.toLp_smul, hket (i + 1)] + rfl + +/-- **Orthonormality of the computational basis:** `⟨i|j⟩ = δᵢⱼ`. The inner product of the +computational-basis states `|i⟩`, `|j⟩` of the qubit is `1` when `i = j` and `0` otherwise, since +`|i⟩ = EuclideanSpace.single i 1` is the standard orthonormal basis. -/ +theorem qubitBasis_inner_qubitBasis (i j : Fin 2) : + inner ℂ (qubitBasis i).vec (qubitBasis j).vec = if i = j then (1 : ℂ) else 0 := by + change inner ℂ (EuclideanSpace.single i (1 : ℂ)) (EuclideanSpace.single j (1 : ℂ)) = _ + rw [EuclideanSpace.inner_single_left] + simp [PiLp.single_apply] + +/-- **The qubit computational basis is orthonormal** as a family of state vectors: +`Orthonormal ℂ (fun i => |i⟩)`, from `qubitBasis_inner_qubitBasis` (`⟨i|j⟩ = δᵢⱼ`) via +`orthonormal_iff_ite`. The single-qubit analogue of `bellState_orthonormal`; a citable +computational-basis fact reused wherever a Schmidt/spectral decomposition uses `{|0⟩, |1⟩}` as an +orthonormal frame. -/ +theorem qubitBasis_vec_orthonormal : Orthonormal ℂ (fun i => (qubitBasis i).vec) := + orthonormal_iff_ite.mpr qubitBasis_inner_qubitBasis + +/-- **The computational basis `|0⟩, |1⟩` as a `ℂ`-basis of the qubit state space.** The two +computational kets are orthonormal (`qubitBasis_vec_orthonormal`) and number `2 = finrank ℂ +qubit.space` (`finrank_qubit_space`), so they form a `Module.Basis (Fin 2) ℂ qubit.space`. This is +the qubit counterpart of `quditOrthonormalBasis`, packaged as a `Module.Basis` for use with +`Basis.ext` / `Basis.piTensorProduct` — e.g. to reduce a computational-basis truth table to an +`Evolution` identity (`Evolution.ext_qubitBasis`). -/ +noncomputable def qubitModuleBasis : Module.Basis (Fin 2) ℂ qubit.space := + basisOfLinearIndependentOfCardEqFinrank + qubitBasis_vec_orthonormal.linearIndependent + (by rw [Fintype.card_fin, finrank_qubit_space]) + +/-- The `i`-th vector of `qubitModuleBasis` is the computational ket `|i⟩`, `(qubitBasis i).vec`. -/ +@[simp] theorem qubitModuleBasis_apply (i : Fin 2) : + qubitModuleBasis i = (qubitBasis i).vec := + congrFun (coe_basisOfLinearIndependentOfCardEqFinrank _ _) i + +/-- **The computational basis `qubitModuleBasis` is orthonormal.** The `Module.Basis`-form of +`qubitBasis_vec_orthonormal`, i.e. `Orthonormal ℂ ⇑qubitModuleBasis`, since the two agree pointwise +(`qubitModuleBasis_apply`). Feeds `Orthonormal.basisTensorProduct` to orthonormalize multi-qubit +tensor bases. -/ +theorem qubitModuleBasis_orthonormal : Orthonormal ℂ ⇑qubitModuleBasis := by + rw [show (⇑qubitModuleBasis) = (fun i => (qubitBasis i).vec) from funext qubitModuleBasis_apply] + exact qubitBasis_vec_orthonormal + +/-- **Matrix element of `X` in the computational basis:** `⟨i|X|j⟩ = Xᵢⱼ`. The inner product +`⟨i|X|j⟩` is the `(i, j)` entry of the Pauli matrix `Concrete.pauliX = !![0, 1; 1, 0]`, read off +via the matrix-to-operator bridge `Matrix.toEuclideanCLM`. -/ +theorem pauliXObservable_inner_qubitBasis (i j : Fin 2) : + inner ℂ (qubitBasis i).vec (pauliXObservable.op (qubitBasis j).vec) = Concrete.pauliX i j := by + rw [pauliXObservable_op] + change inner ℂ (EuclideanSpace.single i (1 : ℂ)) + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliX) + (EuclideanSpace.single j 1)) = _ + rw [EuclideanSpace.inner_single_left, Matrix.ofLp_toEuclideanCLM] + fin_cases i <;> fin_cases j <;> simp [Matrix.mulVec, dotProduct, Concrete.pauliX] + +/-- **Matrix element of `Z` in the computational basis:** `⟨i|Z|j⟩ = Zᵢⱼ`. The inner product +`⟨i|Z|j⟩` is the `(i, j)` entry of the Pauli matrix `Concrete.pauliZ = !![1, 0; 0, -1]`, read off +via the matrix-to-operator bridge `Matrix.toEuclideanCLM`. -/ +theorem pauliZObservable_inner_qubitBasis (i j : Fin 2) : + inner ℂ (qubitBasis i).vec (pauliZObservable.op (qubitBasis j).vec) = Concrete.pauliZ i j := by + rw [pauliZObservable_op] + change inner ℂ (EuclideanSpace.single i (1 : ℂ)) + ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ) + (EuclideanSpace.single j 1)) = _ + rw [EuclideanSpace.inner_single_left, Matrix.ofLp_toEuclideanCLM] + fin_cases i <;> fin_cases j <;> simp [Matrix.mulVec, dotProduct, Concrete.pauliZ] + +/-! ### Traces of the Pauli observables (single-qubit Hilbert–Schmidt building blocks) + +The single-qubit trace facts underlying two-qubit Hilbert–Schmidt orthogonality: the Paulis are +traceless (`tr X = tr Y = tr Z = 0`), `tr 1 = 2`, and the product `X Y = i Z` (hence `tr(XY) = 0`). +Each operator trace reduces to the matrix trace through `Matrix.trace_toEuclideanCLM`. -/ + +/-- The identity on a single qubit has **trace `2`** (`= dim`). -/ +theorem trace_one_qubit : + LinearMap.trace ℂ qubit.space (1 : qubit.space →ₗ[ℂ] qubit.space) = 2 := by + rw [LinearMap.trace_one, finrank_qubit_space]; norm_num + +/-- The Pauli `X` observable is **traceless**: `tr X = 0`. -/ +theorem trace_pauliXObservable : LinearMap.trace ℂ qubit.space ↑pauliXObservable.op = 0 := by + rw [pauliXObservable_op]; exact (Matrix.trace_toEuclideanCLM _).trans Concrete.pauliX_trace + +/-- The Pauli `Y` observable is **traceless**: `tr Y = 0`. -/ +theorem trace_pauliYObservable : LinearMap.trace ℂ qubit.space ↑pauliYObservable.op = 0 := by + rw [pauliYObservable_op]; exact (Matrix.trace_toEuclideanCLM _).trans Concrete.pauliY_trace + +/-- The Pauli `Z` observable is **traceless**: `tr Z = 0`. -/ +theorem trace_pauliZObservable : LinearMap.trace ℂ qubit.space ↑pauliZObservable.op = 0 := by + rw [pauliZObservable_op]; exact (Matrix.trace_toEuclideanCLM _).trans Concrete.pauliZ_trace + +/-- **`X Y = i Z`** in the qubit operator ring (N&C eq. 2.40), lifted through +`Matrix.toEuclideanCLM`. -/ +theorem pauliXObservable_op_mul_pauliYObservable_op : + pauliXObservable.op * pauliYObservable.op = Complex.I • pauliZObservable.op := by + have hmat : Concrete.pauliX * Concrete.pauliY = Complex.I • Concrete.pauliZ := by + ext i j; fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliX, Concrete.pauliY, Concrete.pauliZ, Matrix.mul_apply, Fin.sum_univ_two, + Matrix.smul_apply] + have h := congrArg (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) hmat + simp only [map_mul, map_smul] at h + rw [pauliXObservable_op, pauliYObservable_op, pauliZObservable_op] + exact h + +/-- **`tr(X Y) = 0`:** the Pauli `X`·`Y` product is traceless (`XY = iZ`, itself traceless). -/ +theorem trace_pauliXObservable_op_mul_pauliYObservable_op : + LinearMap.trace ℂ qubit.space ↑(pauliXObservable.op * pauliYObservable.op) = 0 := by + rw [pauliXObservable_op_mul_pauliYObservable_op, ContinuousLinearMap.toLinearMap_smul, map_smul, + trace_pauliZObservable, smul_zero] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QubitThree.lean b/LeanPool/AxQM/Postulates/API/QubitThree.lean new file mode 100644 index 0000000000..a0946857f5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QubitThree.lean @@ -0,0 +1,131 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Postulates.Composite +public import Mathlib.LinearAlgebra.TensorProduct.Basis +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# AxQM.Postulates.API — the three-qubit computational basis + +The three-qubit register `qubit ⊗ (qubit ⊗ qubit)`: its +computational basis and the tools needed to prove operator identities on it. It is used in +`AxQM/Postulates/API/ControlledControlledUnitary.lean`. + +* `qubitThreeBasis (q₁, q₂, q₃) = |q₁⟩ ⊗ (|q₂⟩ ⊗ |q₃⟩)` — the computational basis as a family of + pure states (the three-qubit analogue of `qubitBasis`). +* `qubitThreeModuleBasis` — the same family as a `Module.Basis` (the tensor product of three copies + of `qubitModuleBasis`), with `qubitThreeModuleBasis_apply` identifying its vectors with the kets. +* `qubitThree_op_ext` — **extensionality**: two operators on the three-qubit register are equal once + they agree on every computational basis ket. The workhorse for reducing an operator identity to a + finite per-basis-vector check. +* `qubitThreeBasis_orthonormal` and `qubitThreeBasis_rankOne_apply` (`|s⟩⟨s| · |b⟩ = δ_{s,b} |s⟩`) — + orthonormality of the basis and the resulting action of a rank-one projector on a basis ket. +* `qubitThreeFlip` / `qubitThreeCoord` — the index combinatorics shared by every single-qubit + operator on the register: flip the bit at a position (a bit-flip `X`/`Y`), read the bit at a + position (the sign exponent of a `Z`); `qubitThreeFlip_involutive` records that a double flip is + the identity. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **The computational basis of the three-qubit system** `qubit ⊗ (qubit ⊗ qubit)`, as a family of +pure states indexed by the bit string `(q₁, q₂, q₃)`: `|q₁, q₂, q₃⟩ = |q₁⟩ ⊗ (|q₂⟩ ⊗ |q₃⟩)`. The +three-qubit analogue of `qubitBasis`, usable as an orthonormal frame — e.g. as the reference basis +for a relative-phase comparison of three-qubit states (`PureState.RelativePhaseEquiv`), or as the +computational basis diagonalising the bit-flip syndrome observables. -/ +def qubitThreeBasis : Fin 2 × Fin 2 × Fin 2 → PureState (qubit ⊗ (qubit ⊗ qubit)) := + fun i => qubitBasis i.1 ⊗ (qubitBasis i.2.1 ⊗ qubitBasis i.2.2) + +/-- The **three-qubit computational basis** as a `Module.Basis`, the tensor product of three copies +of the single-qubit `qubitModuleBasis`. -/ +noncomputable def qubitThreeModuleBasis : + Module.Basis (Fin 2 × Fin 2 × Fin 2) ℂ (qubit.space ⊗[ℂ] (qubit.space ⊗[ℂ] qubit.space)) := + qubitModuleBasis.tensorProduct (qubitModuleBasis.tensorProduct qubitModuleBasis) + +/-- The basis vector at `(q₁, q₂, q₃)` is the computational ket `|q₁q₂q₃⟩`. -/ +theorem qubitThreeModuleBasis_apply (b : Fin 2 × Fin 2 × Fin 2) : + qubitThreeModuleBasis b = (qubitThreeBasis b).vec := by + obtain ⟨b1, b2, b3⟩ := b + rw [qubitThreeModuleBasis, Module.Basis.tensorProduct_apply', Module.Basis.tensorProduct_apply', + qubitModuleBasis_apply, qubitModuleBasis_apply, qubitModuleBasis_apply] + rfl + +/-- **Extensionality on the computational basis:** two operators on the three-qubit register are +equal once they agree on every computational basis ket `|q₁q₂q₃⟩`. -/ +theorem qubitThree_op_ext {T1 T2 : (qubit ⊗ (qubit ⊗ qubit)).space →L[ℂ] + (qubit ⊗ (qubit ⊗ qubit)).space} + (h : ∀ b : Fin 2 × Fin 2 × Fin 2, T1 (qubitThreeBasis b).vec = T2 (qubitThreeBasis b).vec) : + T1 = T2 := by + apply ContinuousLinearMap.coe_injective + apply Module.Basis.ext qubitThreeModuleBasis + intro b + rw [qubitThreeModuleBasis_apply] + exact h b + +/-- **The three-qubit computational basis kets are orthonormal.** -/ +theorem qubitThreeBasis_orthonormal : Orthonormal ℂ (fun b => (qubitThreeBasis b).vec) := by + rw [show (fun b => (qubitThreeBasis b).vec) = ⇑qubitThreeModuleBasis from + funext fun b => (qubitThreeModuleBasis_apply b).symm] + exact qubitModuleBasis_orthonormal.basisTensorProduct + (qubitModuleBasis_orthonormal.basisTensorProduct qubitModuleBasis_orthonormal) + +/-- **Distinct three-qubit computational basis kets are orthogonal:** +`⟪|a⟩, |b⟩⟫ = 0` whenever `a ≠ b`, the `if_neg` branch of `qubitThreeBasis_orthonormal`. The +foundational orthogonality fact behind the weight-mismatch overlaps of the Shor-code error +vectors. -/ +theorem qubitThreeBasis_inner_eq_zero_of_ne {a b : Fin 2 × Fin 2 × Fin 2} (h : a ≠ b) : + (inner ℂ (qubitThreeBasis a).vec (qubitThreeBasis b).vec : ℂ) = 0 := by + rw [orthonormal_iff_ite.mp qubitThreeBasis_orthonormal, ite_eq_right h] + +/-- **A rank-one projector onto a basis ket acts as a Kronecker delta:** +`|s⟩⟨s| · |b⟩ = δ_{s,b} |s⟩`, from orthonormality of the computational basis. -/ +theorem qubitThreeBasis_rankOne_apply (s b : Fin 2 × Fin 2 × Fin 2) : + (rankOne ℂ (qubitThreeBasis s).vec (qubitThreeBasis s).vec) (qubitThreeBasis b).vec + = (if s = b then (1 : ℂ) else 0) • (qubitThreeBasis s).vec := by + rw [InnerProductSpace.rankOne_apply, orthonormal_iff_ite.mp qubitThreeBasis_orthonormal s b] + +/-! ### Bit-flip combinatorics on the three-qubit index + +Two elementary combinators on the index type `Fin 2 × Fin 2 × Fin 2`, shared by every single-qubit +operator placed on the three-qubit register (a bit flip `X`/`Y`, or a sign `Z`): flipping the bit +at a position, and reading the bit at a position. -/ + +/-- **Flip the bit at position `pos`** of a three-qubit index `(q₁, q₂, q₃)` (mod `2`): +`pos = 0 ↦ (q₁+1, q₂, q₃)`, `pos = 1 ↦ (q₁, q₂+1, q₃)`, `pos = 2 ↦ (q₁, q₂, q₃+1)`. The +combinatorial shadow of a bit-flip (`X` or `Y`) on the `pos`-th qubit. -/ +def qubitThreeFlip : Fin 3 → (Fin 2 × Fin 2 × Fin 2) → (Fin 2 × Fin 2 × Fin 2) + | 0, (a, b, c) => (a + 1, b, c) + | 1, (a, b, c) => (a, b + 1, c) + | 2, (a, b, c) => (a, b, c + 1) + +/-- **`qubitThreeFlip pos` is an involution:** flipping the bit at `pos` twice restores the +index. -/ +theorem qubitThreeFlip_involutive (pos : Fin 3) (b : Fin 2 × Fin 2 × Fin 2) : + qubitThreeFlip pos (qubitThreeFlip pos b) = b := by + obtain ⟨b1, b2, b3⟩ := b + fin_cases pos <;> fin_cases b1 <;> fin_cases b2 <;> fin_cases b3 <;> decide + +/-- **The bit value at position `pos`** of a three-qubit index `(q₁, q₂, q₃)`: `q₁`, `q₂`, `q₃` for +`pos = 0, 1, 2`. The exponent of the `(-1)` sign a `Z` (or the phase of a `Y`) at `pos` produces. -/ +def qubitThreeCoord : Fin 3 → (Fin 2 × Fin 2 × Fin 2) → Fin 2 + | 0, (a, _, _) => a + | 1, (_, b, _) => b + | 2, (_, _, c) => c + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Qudit.lean b/LeanPool/AxQM/Postulates/API/Qudit.lean new file mode 100644 index 0000000000..c54158ef9c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Qudit.lean @@ -0,0 +1,168 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarNormal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryTwirl +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 + +/-! +# AxQM.Postulates.API — the `d`-level system (qudit) and diagonal phase gates + +A finite `d`-level system and the diagonal (phase) unitaries on it, generalizing +`AxQM/Postulates/API/Qubit.lean` (`qubit = qudit 2`) to arbitrary dimension. It is the register +model used by the circuit constructions of Nielsen & Chuang, Chapter 4 (e.g. Problem 4.1's +input and ancilla registers of dimension `2^m` / `2^n`). + +* `qudit d` — the `d`-level quantum system, `QSystem.ofModel (EuclideanSpace ℂ (Fin d))`. +* `quditBasis i` (`|i⟩`) — the **computational-basis pure state** `|i⟩` of `qudit d`, the + normalized standard basis vector `EuclideanSpace.single i 1` (mirrors `qubitBasis`). +* `diagPhase θ` — the **diagonal phase gate** `diag(e^{iθ₀},…,e^{iθ_{d-1}})` for a real + angle vector `θ : Fin d → ℝ`, packaged as a unitary `Evolution (qudit d)`. It is unitary + because a diagonal operator with unit-modulus entries (`|e^{iθ}| = 1`) is unitary; the + construction discharges that obligation. `diagPhase` models the layer of single-qubit phase + gates that, applied to a computational-basis register, imprints a computable phase — the `n` + one-qubit gates of Problem 4.1. +* `diagPhase_op_apply_quditBasis` — the **eigenvalue action** `D|i⟩ = e^{iθᵢ}|i⟩`: a diagonal + phase gate scales each computational-basis vector by its phase. The key computational input + for phase-kickback arguments. + +## Design notes + +* `diagPhase θ`'s operator is built directly on the spectral-operator API + `OrthonormalBasis.diagonalOperator` (`ToMathlib.Analysis.InnerProductSpace.PolarNormal`), + `b.diagonalOperator w = ∑ᵢ wᵢ • |bᵢ⟩⟨bᵢ|`, for `b = EuclideanSpace.basisFun (Fin d) ℂ` (the + computational basis) and `w i = e^{iθᵢ}`. Unitarity is `diagonalOperator_mem_unitary` (a + diagonal operator with unit-modulus diagonal is unitary), and the eigenvalue action is + `diagonalOperator_apply_self` (`(b.diagonalOperator w) (b q) = w q • b q`) — reusing the + purpose-built API rather than an entrywise matrix computation. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **`d`-level quantum system (qudit)**: the system whose state space is the standard +`d`-dimensional complex Hilbert space `EuclideanSpace ℂ (Fin d)`. The qubit is `qudit 2`; +`qudit (2^n)` is an `n`-qubit register. -/ +def qudit (d : ℕ) : QSystem := QSystem.ofModel (EuclideanSpace ℂ (Fin d)) + +@[simp] +theorem qudit_space (d : ℕ) : (qudit d).space = EuclideanSpace ℂ (Fin d) := rfl + +/-- The state space of `qudit d` is nontrivial when `d ≥ 1` (it contains the computational-basis +vectors `|i⟩`). Supplies the `Nontrivial S.space` hypothesis that state constructions such as the +maximally mixed state `I/d` require. -/ +instance qudit_space_nontrivial {d : ℕ} [NeZero d] : Nontrivial (qudit d).space := by + rw [qudit_space]; infer_instance + +/-- **The qudit has dimension `d`**: `finrank ℂ (qudit d).space = d`, since `(qudit d).space` is +`EuclideanSpace ℂ (Fin d)`. The `d`-level generalization of `finrank_qubit_space`; for `qudit (2^n)` +this is `2^n`, and for `qudit 4` it gives the `2⁻² = ¼` high-temperature prefactor of Exercise 7.36 +(`n = 2`). -/ +theorem finrank_qudit (d : ℕ) : Module.finrank ℂ (qudit d).space = d := by + change Module.finrank ℂ (EuclideanSpace ℂ (Fin d)) = d + exact finrank_euclideanSpace_fin + +/-- The **computational-basis pure state** `|i⟩` of `qudit d`: the standard basis vector +`EuclideanSpace.single i 1`, normalized because `‖EuclideanSpace.single i 1‖ = ‖(1 : ℂ)‖ = 1`. +The `d`-level generalization of `qubitBasis`. -/ +def quditBasis {d : ℕ} (i : Fin d) : PureState (qudit d) where + vec := EuclideanSpace.single i 1 + normalized := by + change ‖EuclideanSpace.single i (1 : ℂ)‖ = 1 + simp + +@[simp] +theorem quditBasis_vec {d : ℕ} (i : Fin d) : + (quditBasis i).vec = EuclideanSpace.single i 1 := rfl + +/-- The **computational basis of `qudit d` is orthonormal** (`⟨i|j⟩ = δᵢⱼ`), being the standard +`EuclideanSpace.single` basis (`EuclideanSpace.orthonormal_single`). -/ +theorem quditBasis_orthonormal (d : ℕ) : + Orthonormal ℂ (fun i : Fin d => (quditBasis i).vec) := by + simp only [quditBasis_vec] + exact EuclideanSpace.orthonormal_single + +/-- **Inner product of two computational-basis states** (orthonormality in δ-form): +`⟨x, y⟩ = δₓᵧ`, i.e. `1` if `x = y` and `0` otherwise. The δ-form of `quditBasis_orthonormal`, the +citable input to every amplitude computation over the computational basis. -/ +theorem quditBasis_inner {d : ℕ} (x y : Fin d) : + inner ℂ (quditBasis x).vec (quditBasis y).vec = if x = y then (1 : ℂ) else 0 := + orthonormal_iff_ite.mp (quditBasis_orthonormal d) x y + +/-- The **qudit computational basis reindexed along `Fintype.equivFin`** by an arbitrary finite +index type `ι` is orthonormal: `fun i => (quditBasis (Fintype.equivFin ι i)).vec` is an orthonormal +family. The reindexed form consumed whenever a classical register indexed by a general `Fintype ι` +is realised on `qudit (Fintype.card ι)` (e.g. the Holevo classical–quantum state). Orthonormality +of the underlying basis (`quditBasis_orthonormal`) is stable under precomposition with the injective +reindexing bijection `Fintype.equivFin ι`. -/ +theorem quditBasis_equivFin_orthonormal (ι : Type*) [Fintype ι] : + Orthonormal ℂ (fun i => (quditBasis (Fintype.equivFin ι i)).vec) := + (quditBasis_orthonormal (Fintype.card ι)).comp _ (Fintype.equivFin ι).injective + +/-- **A qudit gate is determined by its action on the computational basis.** Two evolutions +`A`, `B` of `qudit d` are equal as soon as their operators agree on every basis vector `|i⟩` +(`i : Fin d`). The `d`-level generalization of `qubit_evolution_ext`; it is the extensionality +lemma that reduces an operator identity between diagonal gates (e.g. a phase layer written two +ways) to a per-basis-vector eigenvalue comparison. -/ +theorem qudit_evolution_ext {d : ℕ} {A B : Evolution (qudit d)} + (h : ∀ i : Fin d, A.op (quditBasis i).vec = B.op (quditBasis i).vec) : A = B := by + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + refine Module.Basis.ext (EuclideanSpace.basisFun (Fin d) ℂ).toBasis (fun i => ?_) + rw [OrthonormalBasis.coe_toBasis, EuclideanSpace.basisFun_apply] + exact (by simpa only [quditBasis_vec] using h i : + A.op (EuclideanSpace.single i 1) = B.op (EuclideanSpace.single i 1)) + +/-- The **diagonal phase gate** `D = diag(e^{iθ₀}, …, e^{iθ_{d-1}})` on `qudit d`, for a real +angle vector `θ : Fin d → ℝ`, as a unitary `Evolution`. Its operator is the operator diagonal in +the computational basis with entries `e^{iθⱼ}`, i.e. +`(EuclideanSpace.basisFun (Fin d) ℂ).diagonalOperator (fun j => exp (θⱼ · i))`; it is unitary +because each diagonal entry `e^{iθⱼ}` has unit modulus +(`OrthonormalBasis.diagonalOperator_mem_unitary`). This is the phase layer used in the +computable-phase-shift circuit (N&C Problem 4.1). -/ +def diagPhase {d : ℕ} (θ : Fin d → ℝ) : Evolution (qudit d) where + op := (EuclideanSpace.basisFun (Fin d) ℂ).diagonalOperator + (fun i => Complex.exp ((θ i : ℂ) * Complex.I)) + unitary := by + change (EuclideanSpace.basisFun (Fin d) ℂ).diagonalOperator + (fun i => Complex.exp ((θ i : ℂ) * Complex.I)) + ∈ unitary (EuclideanSpace ℂ (Fin d) →L[ℂ] EuclideanSpace ℂ (Fin d)) + exact OrthonormalBasis.diagonalOperator_mem_unitary _ _ (fun i => by simp [Complex.norm_exp]) + +@[simp] +theorem diagPhase_op {d : ℕ} (θ : Fin d → ℝ) : + (diagPhase θ).op = (EuclideanSpace.basisFun (Fin d) ℂ).diagonalOperator + (fun i => Complex.exp ((θ i : ℂ) * Complex.I)) := rfl + +/-- **Action of a computational-basis diagonal operator on a standard basis vector:** +`(basisFun.diagonalOperator w)|i⟩ = wᵢ|i⟩`, since `|i⟩ = EuclideanSpace.basisFun … i` +(`OrthonormalBasis.diagonalOperator_apply_self`). The computation behind +`diagPhase_op_apply_quditBasis`. -/ +theorem basisFun_diagonalOperator_apply_single {d : ℕ} (w : Fin d → ℂ) (i : Fin d) : + (EuclideanSpace.basisFun (Fin d) ℂ).diagonalOperator w (EuclideanSpace.single i 1) + = w i • EuclideanSpace.single i (1 : ℂ) := by + rw [← EuclideanSpace.basisFun_apply, OrthonormalBasis.diagonalOperator_apply_self] + +/-- **Eigenvalue action of a diagonal phase gate:** `D|i⟩ = e^{iθᵢ}|i⟩`. The diagonal phase +gate `diagPhase θ` scales the `i`-th computational-basis vector by its phase `e^{iθᵢ}`. This +is the computational lever behind phase kickback: an ancilla left in `|f(x)⟩` picks up exactly +`e^{iθ_{f(x)}}`. -/ +theorem diagPhase_op_apply_quditBasis {d : ℕ} (θ : Fin d → ℝ) (i : Fin d) : + (diagPhase θ).op (quditBasis i).vec + = Complex.exp ((θ i : ℂ) * Complex.I) • (quditBasis i).vec := + basisFun_diagonalOperator_apply_single (fun j => Complex.exp ((θ j : ℂ) * Complex.I)) i + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditDimCongr.lean b/LeanPool/AxQM/Postulates/API/QuditDimCongr.lean new file mode 100644 index 0000000000..f682eb1036 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditDimCongr.lean @@ -0,0 +1,76 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuditTensorFactor + +/-! +# AxQM.Postulates.API — reindexing a qudit across an equality of dimensions + +Two qudit systems `qudit d` and `qudit e` whose dimensions are *propositionally* equal (`d = e`) +but not *definitionally* so — e.g. `qudit (2^(n+1))` and `qudit (2 * 2^n)` (`pow_succ'`), or +`qudit (2^(n+2))` and `qudit (2 * 2^(n+1))` — are distinct types, so a term of one cannot be used +where the other is expected. This file supplies the **system isomorphism** reconciling them, the +sibling of `quditFinCardIso` (which reconciles `qudit r` with `qudit (Fintype.card (Fin r))`). + +## What is formalised + +* `quditDimCongr h` — for `h : d = e`, the system isomorphism `qudit d ≃ₛ qudit e`, built as the + `OrthonormalBasis.equiv` sending the computational basis `quditOrthonormalBasis d` to + `quditOrthonormalBasis e` along `finCongr h : Fin d ≃ Fin e`; packaged as a `QSystem.Iso`, exactly + as `quditFinCardIso` is built. +* `quditDimCongr_toIsometry` — the underlying isometry is that basis-reindexing equivalence (an + unfolding lemma for the action proofs). +* `quditDimCongr_congr_quditBasis` — the **defining action**: the cast sends the computational-basis + ket `|j⟩` to `|Fin.cast h j⟩` (`= |finCongr h j⟩`). This is what a caller rewrites with, rather + than re-unfolding the iso. + +Compare `quditFinCardIso`, `quditProdIso` and `quditPairBasis`. A `QSystem.Iso` is a plain +isometry of the underlying state spaces. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {d e : ℕ} + +/-- **Reindexing a qudit across an equality of dimensions** `qudit d ≃ₛ qudit e` for `h : d = e`: +the system isomorphism identifying the two (propositionally-equal-dimension) registers, built as the +`OrthonormalBasis.equiv` sending the computational basis `quditOrthonormalBasis d` to +`quditOrthonormalBasis e` along `finCongr h : Fin d ≃ Fin e` — so `|j⟩ ↦ |Fin.cast h j⟩` +(`quditDimCongr_congr_quditBasis`). Mirrors `quditFinCardIso`'s `OrthonormalBasis.equiv` +construction of a `QSystem.Iso`; the special case reconciling `qudit (2·2ⁿ)` with `qudit (2ⁿ⁺¹)` +that the measured-QFT register bridge (Problem 5.2) iterates. -/ +def quditDimCongr (h : d = e) : (qudit d) ≃ₛ (qudit e) := + ⟨(quditOrthonormalBasis d).equiv (quditOrthonormalBasis e) (finCongr h)⟩ + +/-- The underlying isometry of `quditDimCongr` is the basis-reindexing equivalence it is defined by. +An unfolding lemma so the action lemma can rewrite through the `QSystem.Iso` wrapper. -/ +theorem quditDimCongr_toIsometry (h : d = e) : + (quditDimCongr h).toIsometry + = (quditOrthonormalBasis d).equiv (quditOrthonormalBasis e) (finCongr h) := + rfl + +/-- **Defining action of `quditDimCongr` on a computational-basis pure state.** The dimension cast +sends the ket `|j⟩` of `qudit d` to `|finCongr h j⟩ = |Fin.cast h j⟩` of `qudit e`. Proof: +`PureState.ext` reduces it to the action `Φ |j⟩ = |finCongr h j⟩`, which is +`OrthonormalBasis.equiv_apply_basis` for the two computational bases (after +`quditOrthonormalBasis_apply` moves between `(quditBasis _).vec` and the orthonormal basis). -/ +theorem quditDimCongr_congr_quditBasis (h : d = e) (j : Fin d) : + PureState.congr (quditDimCongr h) (quditBasis j) = quditBasis (finCongr h j) := by + apply PureState.ext + rw [PureState.congr_vec, quditDimCongr_toIsometry, ← quditOrthonormalBasis_apply, + OrthonormalBasis.equiv_apply_basis, quditOrthonormalBasis_apply] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditGate.lean b/LeanPool/AxQM/Postulates/API/QuditGate.lean new file mode 100644 index 0000000000..c699cc031a --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditGate.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# AxQM.Postulates.API — a unitary matrix as an `Evolution` gate on `qudit d` + +The construction promoting a `d × d` unitary matrix to a closed-system +`Evolution (qudit d)`. It is the arbitrary-dimension analogue of the single-qubit +`unitaryGate` (`AxQM/Postulates/API/UnitaryBlochRotation.lean`, `qubit = qudit 2`): the register +model of Nielsen & Chuang's circuits is `qudit (2ⁿ)`, and many gates are naturally specified +as concrete `d × d` unitary matrices (e.g. the beamsplitter / phase-shifter matrices of +Problem 7.2). + +* `quditGate hU` — the `Evolution (qudit d)` whose operator is the unitary matrix `U` + (`hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ`) promoted through the `⋆`-algebra isomorphism + `Matrix.toEuclideanCLM`. Unitarity of the operator is transported from `hU` by + `Unitary.map_mem`, exactly as `qftEvolution` / `pauliZGate` / `unitaryGate` do. +* `quditGate_op` — the `simp` bridge `(quditGate hU).op = Matrix.toEuclideanCLM U` exposing the + underlying operator (definitionally, `rfl`). +-/ + +@[expose] public section + +open Matrix + +noncomputable section + +namespace AxQM + +/-- The **unitary gate of a `d × d` unitary matrix** `U` (`hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ`) +as a closed-system `Evolution` of `qudit d`. Its operator is `U` promoted through the `⋆`-algebra +isomorphism `Matrix.toEuclideanCLM`; the `Evolution` unitarity obligation is transported from `hU` +by `Unitary.map_mem`. The arbitrary-dimension generalization of the single-qubit `unitaryGate` +(`qubit = qudit 2`); `qftEvolution` and `pauliZGate` are instances of this pattern. -/ +def quditGate {d : ℕ} {U : Matrix (Fin d) (Fin d) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + Evolution (qudit d) where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) U + unitary := Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d)) hU + +/-- The operator of `quditGate hU` is `U` promoted through `Matrix.toEuclideanCLM`. -/ +@[simp] +theorem quditGate_op {d : ℕ} {U : Matrix (Fin d) (Fin d) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) : + (quditGate hU).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin d) U := + rfl + +/-- **`quditGate` respects matrix equality.** If two unitary matrices on `Fin d` are equal, their +promoted evolutions are equal. This lets a matrix identity be transported through `quditGate` even +though the matrix appears in the type of the unitarity witness: unitary-group membership is a +`Prop`, so once the matrices coincide the two witnesses agree by proof irrelevance. -/ +theorem quditGate_congr {d : ℕ} {U V : Matrix (Fin d) (Fin d) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) (hV : V ∈ Matrix.unitaryGroup (Fin d) ℂ) + (h : U = V) : quditGate hU = quditGate hV := by + subst h; rfl + +/-- **The `quditGate` of the identity matrix is the identity evolution.** +`quditGate 1 = Evolution.id` on `qudit d`: both operators are `1` — the left by `quditGate_op` and +`toEuclideanCLM`'s `map_one`, the right by `Evolution.id_op`. -/ +theorem quditGate_one_eq_id {d : ℕ} + (h : (1 : Matrix (Fin d) (Fin d) ℂ) ∈ Matrix.unitaryGroup (Fin d) ℂ) : + quditGate h = Evolution.id := by + apply Evolution.ext + rw [quditGate_op, Evolution.id_op] + exact map_one _ + +/-- **A `quditGate`'s action on a computational basis vector is its matrix column.** +`(quditGate hU).op |z⟩ = ∑ₛ U_{sz} |s⟩`, the `z`-th column of `U` expanded over the computational +basis `quditBasis`. The general "gate on a basis vector" fact from which the column formula of any +`quditGate` is read off. The `qudit`-vs-`EuclideanSpace` identification of the state space is +bridged by `Matrix.toEuclideanCLM_apply_single` (`exact`, at full transparency). -/ +theorem quditGate_op_quditBasis_vec {d : ℕ} {U : Matrix (Fin d) (Fin d) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin d) ℂ) (z : Fin d) : + (quditGate hU).op (quditBasis z).vec = ∑ s : Fin d, U s z • (quditBasis s).vec := by + rw [quditGate_op, quditBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single U z).trans ?_ + exact Finset.sum_congr rfl (fun s _ => by congr 1) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditMeasurement.lean b/LeanPool/AxQM/Postulates/API/QuditMeasurement.lean new file mode 100644 index 0000000000..2b6383eaef --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditMeasurement.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.GeneralizedDepolarizingChannel +public import LeanPool.AxQM.Postulates.API.ProjectiveMeasurement +public import LeanPool.AxQM.Postulates.SystemIso + +/-! +# AxQM.Postulates.API — the computational-basis measurement of a qudit + +The **projective measurement of `qudit d` in the computational basis** `{|0⟩, …, |d−1⟩}`, the +final read-out step of the qudit quantum algorithms of Nielsen & Chuang (Chapters 5–6): measuring +the register and reading off which basis state `|i⟩` it collapsed to. + +* `quditMeasurement d` — the projective `Measurement (Fin d) (qudit d)` in the standard basis, + `Measurement.ofOrthonormalBasis` of the computational orthonormal basis `quditOrthonormalBasis d` + (`= EuclideanSpace.basisFun`). Outcome `i` has measurement operator `|i⟩⟨i|`. The `d`-level + generalisation of the two-outcome `groverSolutionMeasurement` of Exercise 6.4. +* `quditMeasurement_op` — the `.op`-level unfolding: `(quditMeasurement d).op x = |x⟩⟨x|`, the + rank-one projector onto the computational-basis state `|x⟩`. +* `bornProb_quditMeasurement_toState` — the Born rule for it on a pure state `ψ`: + `p(i) = ‖⟨i, ψ⟩‖²`, the squared amplitude of `|ψ⟩` on the basis state `|i⟩`. This is N&C's + `p(m) = |⟨m|ψ⟩|²` for a computational-basis measurement, specialised so the amplitude is written + against the computational-basis pure states `quditBasis i` used throughout the library. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {d : ℕ} + +/-- The **computational-basis (projective) measurement** of `qudit d`: the projective measurement in +the standard basis `{|i⟩}`, with outcome `i : Fin d` the rank-one projector `|i⟩⟨i|` — "the register +was found in the state `|i⟩`". Built from the computational orthonormal basis +`quditOrthonormalBasis` (`= EuclideanSpace.basisFun`). This is N&C's measurement of a register in +the computational basis (the read-out step of the search and other algorithms), and the `d`-level +generalisation of the two-outcome `groverSolutionMeasurement`. -/ +def quditMeasurement (d : ℕ) : Measurement (Fin d) (qudit d) := + Measurement.ofOrthonormalBasis (quditOrthonormalBasis d) + +/-- The computational orthonormal basis is the family of computational-basis pure states: +`quditOrthonormalBasis d i = |i⟩ = (quditBasis i).vec` (both are `EuclideanSpace.single i 1`). -/ +theorem quditOrthonormalBasis_apply (i : Fin d) : + quditOrthonormalBasis d i = (quditBasis i).vec := by + rw [quditBasis_vec]; exact EuclideanSpace.basisFun_apply (Fin d) ℂ i + +/-- **The reindexing isomorphism `qudit r ≃ₛ qudit (Fintype.card (Fin r))`.** For a type of `r` +outcomes, results indexed over `Fin r` (e.g. the apparatus register `qudit r` of a measurement +operation) and results indexed over a generic finite type `ι` reindexed by `Fintype.equivFin` +(e.g. `Measurement.measState`, which records the outcome in `qudit (Fintype.card ι)`) live on +distinct qudit systems, because `Fintype.card (Fin r) = r` holds only *propositionally*, not +definitionally. This is the system isomorphism reconciling them: it sends the computational ket +`|y⟩` to `|Fintype.equivFin y⟩`, built as the `OrthonormalBasis.equiv` of the two computational +bases along `Fintype.equivFin (Fin r)`. It is the `qudit (Fintype.card ι)` reindexing anticipated +by `quditBasis_equivFin_orthonormal`, and its action on states is `quditFinCardIso_congr_toState`. +Under it every system-iso-invariant quantity is preserved (`State.vonNeumannEntropy_congr`, +`State.holevoChi_congr`), so it lets the χ / entropy of a `qudit r`-marginal be identified with that +of the corresponding `measState`. -/ +def quditFinCardIso (r : ℕ) : (qudit r) ≃ₛ (qudit (Fintype.card (Fin r))) := + ⟨(quditOrthonormalBasis r).equiv (quditOrthonormalBasis (Fintype.card (Fin r))) + (Fintype.equivFin (Fin r))⟩ + +/-- **Action of `quditFinCardIso` on a computational-basis state.** Transporting the outcome ket +`|y⟩` on `qudit r` along the reindexing isomorphism gives the reindexed ket `|Fintype.equivFin y⟩` +on `qudit (Fintype.card (Fin r))`: + +`State.congr (quditFinCardIso r) |y⟩⟨y| = |Fintype.equivFin y⟩⟨Fintype.equivFin y|`. + +This is the companion action lemma of `quditFinCardIso`; it is what a caller rewrites with (rather +than re-unfolding the iso into its `OrthonormalBasis.equiv`), e.g. to match a `qudit r`-marginal's +diagonal Born state with `Measurement.measState`. Proof: `PureState.congr_toState` reduces it to +the vector action `quditFinCardIso |y⟩ = |Fintype.equivFin y⟩`, which is +`OrthonormalBasis.equiv_apply_basis` for the two computational bases. -/ +theorem quditFinCardIso_congr_toState (r : ℕ) (y : Fin r) : + State.congr (quditFinCardIso r) (quditBasis y).toState + = (quditBasis (Fintype.equivFin (Fin r) y)).toState := by + rw [← PureState.congr_toState] + congr 1 + apply PureState.ext + rw [PureState.congr_vec] + change (quditOrthonormalBasis r).equiv (quditOrthonormalBasis (Fintype.card (Fin r))) + (Fintype.equivFin (Fin r)) (quditBasis y).vec + = (quditBasis (Fintype.equivFin (Fin r) y)).vec + rw [← quditOrthonormalBasis_apply, OrthonormalBasis.equiv_apply_basis, + quditOrthonormalBasis_apply] + +/-- **The computational-basis measurement operator is the rank-one projector** `|x⟩⟨x|`: +`(quditMeasurement d).op x = |x⟩⟨x|` (`rankOne` of the computational-basis vector with itself). The +`.op`-level unfolding of `quditMeasurement = ofOrthonormalBasis (quditOrthonormalBasis d)` via +`Measurement.ofOrthonormalBasis_op` and `quditOrthonormalBasis_apply`. -/ +theorem quditMeasurement_op (x : Fin d) : + (quditMeasurement d).op x + = InnerProductSpace.rankOne ℂ (quditBasis x).vec (quditBasis x).vec := by + rw [quditMeasurement, Measurement.ofOrthonormalBasis_op, quditOrthonormalBasis_apply] + +/-- **Born rule for the computational-basis measurement, on a pure state.** The probability of +outcome `i` when the pure state `ψ` is measured in the computational basis is the squared amplitude +`‖⟨i, ψ⟩‖²` on the basis state `|i⟩ = quditBasis i` — N&C's `p(m) = |⟨m|ψ⟩|²`. Immediate from the +projective Born rule `bornProb_ofOrthonormalBasis_toState` and `quditOrthonormalBasis_apply`. -/ +theorem bornProb_quditMeasurement_toState (ψ : PureState (qudit d)) (i : Fin d) : + (quditMeasurement d).bornProb ψ.toState i = ‖inner ℂ (quditBasis i).vec ψ.vec‖ ^ 2 := by + rw [quditMeasurement, Measurement.bornProb_ofOrthonormalBasis_toState, + quditOrthonormalBasis_apply] + +/-- **The computational-basis measurement of a computational-basis state is deterministic.** The +probability of outcome `x` when the basis state `|y⟩` is measured in the computational basis is `1` +if `x = y` and `0` otherwise — the register is found in exactly the basis state it is in. Immediate +from `bornProb_quditMeasurement_toState` (`p(x) = ‖⟨x|y⟩‖²`) and orthonormality of the computational +basis (`quditBasis_inner`, `⟨x|y⟩ = δₓᵧ`). This is the `p(m) = |⟨m|ψ⟩|²` Born rule collapsing to a +Kronecker delta on a basis input; it is why measuring the computational-basis projectors on a +(corrupted) basis codeword yields a *certain* outcome. -/ +theorem bornProb_quditMeasurement_quditBasis (y x : Fin d) : + (quditMeasurement d).bornProb (quditBasis y).toState x = if x = y then 1 else 0 := by + rw [bornProb_quditMeasurement_toState, quditBasis_inner] + split_ifs with h <;> simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditPairPermGate.lean b/LeanPool/AxQM/Postulates/API/QuditPairPermGate.lean new file mode 100644 index 0000000000..a7d9613404 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditPairPermGate.lean @@ -0,0 +1,122 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# AxQM.Postulates.API — the two-register computational-basis permutation gate + +The *classical reversible circuit* on a pair of qudit registers: given a +permutation `σ` of the joint computational-basis labels `Fin d × Fin e`, the gate `quditPairPerm σ` +is the unitary `Evolution` of `qudit d ⊗ qudit e` sending each basis state `|x⟩ ⊗ |y⟩` to +`|(σ (x, y)).1⟩ ⊗ |(σ (x, y)).2⟩`. Every permutation of the basis is realised by such a unitary +(permuting an orthonormal basis is an isometry), so this is the general "permute the computational +basis" gate — the operator a reversible classical circuit on the two registers implements. + +## What is formalised + +* `quditPairBasis d e` — the computational **product** orthonormal basis of + `(qudit d ⊗ qudit e).space`, indexed by `Fin d × Fin e`: `Mathlib`'s + `OrthonormalBasis.tensorProduct` of the two standard bases. + `quditPairBasis d e (x, y) = |x⟩ ⊗ |y⟩` (`quditPairBasis_apply`). +* `quditPairPerm σ` — the **basis-permutation gate**: `Evolution.ofLinearIsometryEquiv` of the + linear isometry equivalence permuting `quditPairBasis` by `σ` (`OrthonormalBasis.equiv`). It is a + genuine `Evolution` (Postulate 5): unitarity is inherited from the isometry, so producing this + term *is* the fact that permuting the basis is a legitimate quantum operation. +* `quditPairPerm_op_tmul` / `quditPairPerm_evolvePure_quditBasis` — the **defining action** + `quditPairPerm σ (|x⟩ ⊗ |y⟩) = |(σ (x,y)).1⟩ ⊗ |(σ (x,y)).2⟩`, at the operator and pure-state + levels: the gate realises exactly the permutation `σ` on the computational basis. + +## Design notes + +* **Construction.** Mirrors `Evolution.swap` (the special case where `σ` exchanges the factors): a + basis-permutation gate is `Evolution.ofLinearIsometryEquiv` of an `OrthonormalBasis.equiv`, whose + action on a basis vector is `equiv_apply_basis`. The two `EuclideanSpace.basisFun` standard bases + tensor to `quditPairBasis`; `quditPairBasis (x, y) = |x⟩ ⊗ |y⟩` because + `basisFun i = EuclideanSpace.single i 1 = (quditBasis i).vec`. +* **Typing of `quditPairBasis`.** `quditPairBasis` is typed at the composite space + `(qudit d ⊗ qudit e).space` (defeq to the raw `EuclideanSpace ⊗ EuclideanSpace`) so that + `equiv_apply_basis` matches the operator produced by `ofLinearIsometryEquiv`; the raw + `tensorProduct_apply'` is bridged across the defeq by a term-level `have`, and the residual + raw-vs-composite `⊗ₜ` is closed by a full-transparency `rfl`. +* **Unitarity.** A value of type `Evolution (qudit d ⊗ qudit e)` cannot be formed without + discharging unitarity; here it comes from the isometry `OrthonormalBasis.equiv`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {d e : ℕ} + +/-- The **computational product basis** of `(qudit d ⊗ qudit e).space`, indexed by +`Fin d × Fin e`: the `Mathlib` tensor product `OrthonormalBasis.tensorProduct` of the two standard +bases `EuclideanSpace.basisFun`. Its basis vector at `(x, y)` is the product computational-basis +state `|x⟩ ⊗ |y⟩` (`quditPairBasis_apply`). -/ +def quditPairBasis (d e : ℕ) : + OrthonormalBasis (Fin d × Fin e) ℂ (qudit d ⊗ qudit e).space := + (EuclideanSpace.basisFun (Fin d) ℂ).tensorProduct (EuclideanSpace.basisFun (Fin e) ℂ) + +/-- The product-basis vector at a packed index `p` is `|p.1⟩ ⊗ |p.2⟩`. -/ +theorem quditPairBasis_apply' (d e : ℕ) (p : Fin d × Fin e) : + quditPairBasis d e p = (quditBasis p.1).vec ⊗ₜ[ℂ] (quditBasis p.2).vec := by + have key : quditPairBasis d e p + = (EuclideanSpace.basisFun (Fin d) ℂ) p.1 ⊗ₜ[ℂ] (EuclideanSpace.basisFun (Fin e) ℂ) p.2 := + OrthonormalBasis.tensorProduct_apply' _ _ p + rw [key] + simp only [EuclideanSpace.basisFun_apply, quditBasis_vec] + rfl + +/-- The product-basis vector at `(x, y)` is the product computational-basis state `|x⟩ ⊗ |y⟩`. -/ +theorem quditPairBasis_apply (d e : ℕ) (x : Fin d) (y : Fin e) : + quditPairBasis d e (x, y) = (quditBasis x).vec ⊗ₜ[ℂ] (quditBasis y).vec := + quditPairBasis_apply' d e (x, y) + +/-- **The computational-basis permutation gate** `quditPairPerm σ` on `qudit d ⊗ qudit e`: the +unitary `Evolution` that permutes the joint computational basis by `σ : Equiv.Perm (Fin d × Fin e)`, +`|x⟩ ⊗ |y⟩ ↦ |(σ (x,y)).1⟩ ⊗ |(σ (x,y)).2⟩`. It is `Evolution.ofLinearIsometryEquiv` of the +isometry `OrthonormalBasis.equiv` permuting `quditPairBasis` by `σ`, with unitarity inherited from +that isometry. -/ +def quditPairPerm (σ : Equiv.Perm (Fin d × Fin e)) : Evolution (qudit d ⊗ qudit e) := + Evolution.ofLinearIsometryEquiv ((quditPairBasis d e).equiv (quditPairBasis d e) σ) + +/-- **Action of the basis-permutation gate** on a product vector: +`quditPairPerm σ (|x⟩ ⊗ |y⟩) = |(σ (x,y)).1⟩ ⊗ |(σ (x,y)).2⟩`. -/ +theorem quditPairPerm_op_tmul (σ : Equiv.Perm (Fin d × Fin e)) (x : Fin d) (y : Fin e) : + (quditPairPerm σ).op ((quditBasis x).vec ⊗ₜ[ℂ] (quditBasis y).vec) + = (quditBasis (σ (x, y)).1).vec ⊗ₜ[ℂ] (quditBasis (σ (x, y)).2).vec := by + -- The argument `(quditBasis x).vec ⊗ₜ (quditBasis y).vec` is itself typed at the generic + -- `(qudit d).space ⊗[ℂ] (qudit e).space`, so `rw`'s pattern for + -- `Evolution.ofLinearIsometryEquiv_op_apply` (needing a syntactically bundled argument) cannot + -- fire on it; instantiate the lemma directly (an ordinary application, checked up to full defeq). + have hop_apply := Evolution.ofLinearIsometryEquiv_op_apply + ((quditPairBasis d e).equiv (quditPairBasis d e) σ) + ((quditBasis x).vec ⊗ₜ[ℂ] (quditBasis y).vec) + rw [quditPairPerm, hop_apply, ← quditPairBasis_apply, + OrthonormalBasis.equiv_apply_basis, quditPairBasis_apply'] + +/-- **Action of the basis-permutation gate on a product pure state:** +`quditPairPerm σ (|x⟩ ⊗ |y⟩) = |(σ (x,y)).1⟩ ⊗ |(σ (x,y)).2⟩`. The `evolvePure`-level companion of +`quditPairPerm_op_tmul`: the gate realises the permutation `σ` on the computational basis. -/ +theorem quditPairPerm_evolvePure_quditBasis (σ : Equiv.Perm (Fin d × Fin e)) + (x : Fin d) (y : Fin e) : + (quditPairPerm σ).evolvePure ((quditBasis x) ⊗ (quditBasis y)) + = (quditBasis (σ (x, y)).1) ⊗ (quditBasis (σ (x, y)).2) := by + apply PureState.ext + rw [Evolution.evolvePure_vec, PureState.tmul_vec, PureState.tmul_vec, quditPairPerm_op_tmul] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditPhaseGradient.lean b/LeanPool/AxQM/Postulates/API/QuditPhaseGradient.lean new file mode 100644 index 0000000000..6d8846268e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditPhaseGradient.lean @@ -0,0 +1,448 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.InverseQuantumFourierTransform +public import LeanPool.AxQM.Postulates.API.Qudit +public import LeanPool.AxQM.Postulates.API.UniformSuperposition +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.InvolutionRotation +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Orthonormal +public import Mathlib.Algebra.Order.Round + +/-! +# AxQM.Postulates.API — the qudit phase-gradient state + +The **phase-gradient state** `|φ_θ⟩ = (1/√d) ∑ₖ e^{iθk} |k⟩` of the register `qudit d`: the equal +superposition of all computational-basis states, with the `k`-th amplitude carrying the linear phase +`e^{iθk}`. It is the state a phase-estimation register holds after the controlled-power stage has +loaded a per-value linear phase gradient with slope `θ`, and the object the final inverse QFT +then reads out (N&C §5.2, Figure 5.2). + +This generalizes the Fourier image state `qftFourierImage d j = (1/√d) ∑ₖ e^{2πijk/d} |k⟩` from the +**dyadic/rational** slopes `θ = 2πj/d` (an integer `j`, so `θ` is a multiple of `2π/d`) to an +**arbitrary real** slope `θ`. That generality is exactly what Kitaev's QFT-over-`Z_p` circuit +(Problem 5.1) needs: phase estimation of the cyclic shift produces the gradient with slope +`θ = 2πℓ/p`, whose frequency `ℓ/p` is *not* of the form `m/d` for the `d = 2^{n+1}`-level control +register when `p` is prime — so the read-out is inherently a finite-precision *estimate*, and the +state at hand is a genuine `quditPhaseGrad θ d`, not any `qftFourierImage d m`. + +## What is formalised + +* `quditPhaseGrad θ d` — the state `(1/√d) ∑ₖ e^{iθk} |k⟩` as a `PureState (qudit d)`. It is + normalized for **every** real `θ` (each amplitude has modulus `1/√d` and the `|k⟩` are + orthonormal, so `‖φ_θ‖² = d·(1/√d)² = 1`), via `Orthonormal.norm_sum_smul_sq` — the same idiom as + `qftInverseFourierImage` / `orderEigenstate`. +* `quditPhaseGrad_vec` — its underlying vector, the explicit superposition. +* `quditPhaseGrad_eq_qftFourierImage` — the **dyadic specialization** identifying the forward + Fourier image as the phase gradient of slope `2πj/d`: + `qftFourierImage d j = quditPhaseGrad (2πj/d) d`. +* `quditPhaseGrad_eq_qftInverseFourierImage` — the inverse-image counterpart at slope `−2πk/d`: + `qftInverseFourierImage d k = quditPhaseGrad (−2πk/d) d`. +* `quditPhaseGrad_inner_quditPhaseGrad` — the **overlap** `⟨φ_α | φ_β⟩ = (1/d) ∑ₖ e^{i(β−α)k}` of + two phase gradients: the normalized geometric sum of the slope difference. +* `quditPhaseGrad_qftInverse_inner_quditBasis` — the **phase-estimation read-out amplitude** (N&C + §5.2.1, eqs. 5.23–5.24): the amplitude of computational-basis outcome `|m⟩` after the terminal + inverse QFT of the gradient is `⟨m | F⁻¹ | φ_θ⟩ = (1/d) ∑ₖ e^{i(θ − 2πm/d)k}` (N&C's `αₗ`). +* `quditPhaseGrad_qftInverse_inner_quditBasis_geom` — its **closed form** (N&C eqs. 5.25–5.26): + `(1/d)·(e^{iθd} − 1)/(e^{i(θ − 2πm/d)} − 1)` when the ratio `≠ 1`, numerator bin-independent. + These two read-out amplitudes are the foundation of the finite-precision accuracy of the prime-`p` + Kitaev circuit (Problem 5.1): since `ℓ/p` is non-dyadic the read-out never collapses to a single + bin, and the modulus of `αₗ` — bounded via the closed form (eqs. 5.28–5.34) — is what quantifies + how sharply the estimate concentrates. + +## Design notes + +* **Why a named definition (not an inline `qftFourierImage`).** The Kitaev-circuit + read-out needs the *general-slope* state, and its phase modulus argument (unit for any real `θ`) + is what makes it normalized without a background unitary — so it earns its own definition rather + than being a special case of `qftFourierImage`, whose slope is pinned to a rational multiple of + `2π`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +open scoped Matrix + +/-- The linear phase `e^{iθk}` (real slope `θ`, `k : ℕ`) has unit modulus: it is `e^{iφ}` for the +real angle `φ = θk`. -/ +private theorem norm_exp_phaseGrad (θ : ℝ) (k : ℕ) : + ‖Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ))‖ = 1 := by + simp [Complex.norm_exp] + +/-- The **qudit phase-gradient state** `|φ_θ⟩ = (1/√d) ∑ₖ e^{iθk} |k⟩` of `qudit d`: the equal +superposition of the computational basis with the `k`-th amplitude carrying the linear phase +`e^{iθk}` (slope `θ : ℝ`). Normalized for every real `θ`, because each amplitude has modulus +`1/√d` and the basis states `|k⟩ = quditBasis k` are orthonormal, so `‖φ_θ‖² = d·(1/d) = 1` +(`Orthonormal.norm_sum_smul_sq`). The general-slope generalization of `qftFourierImage` (slope +`2πj/d`); the state a phase-estimation register carries into the terminal inverse-QFT read-out. -/ +def quditPhaseGrad (θ : ℝ) (d : ℕ) [NeZero d] : PureState (qudit d) where + vec := ∑ k : Fin d, + ((Real.sqrt d : ℂ)⁻¹ * Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ))) • (quditBasis k).vec + normalized := by + have horth : Orthonormal ℂ (fun k : Fin d => (quditBasis k).vec) := quditBasis_orthonormal d + have hcoeff : ∀ k : Fin d, + ‖(Real.sqrt d : ℂ)⁻¹ * Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ))‖ ^ 2 = (d : ℝ)⁻¹ := + fun k => by + rw [norm_mul, norm_exp_phaseGrad, mul_one, norm_inv, Complex.norm_real, + Real.norm_of_nonneg (Real.sqrt_nonneg _), ← Real.sqrt_inv, Real.sq_sqrt (by positivity)] + have hsq : ‖(∑ k : Fin d, + ((Real.sqrt d : ℂ)⁻¹ * Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ))) + • (quditBasis k).vec)‖ ^ 2 = 1 := by + rw [horth.norm_sum_smul_sq, Finset.sum_congr rfl (fun k _ => hcoeff k)] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + mul_inv_cancel₀ (by exact_mod_cast (NeZero.ne d))] + rw [← Real.sqrt_one, ← hsq, Real.sqrt_sq (norm_nonneg _)] + +/-- The underlying vector of `quditPhaseGrad θ d` is the explicit phase-gradient superposition +`(1/√d) ∑ₖ e^{iθk} |k⟩`. -/ +@[simp] +theorem quditPhaseGrad_vec (θ : ℝ) (d : ℕ) [NeZero d] : + (quditPhaseGrad θ d).vec + = ∑ k : Fin d, + ((Real.sqrt d : ℂ)⁻¹ * Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ))) • (quditBasis k).vec := + rfl + +/-- **Amplitude extraction:** the `j`-th coefficient of the phase gradient is `(1/√d)·e^{iθj}`, +`⟨j|φ_θ⟩ = (1/√d)·e^{iθj}` — the inner product of a computational-basis state with `quditPhaseGrad` +reads off its amplitude, since the `|k⟩` are orthonormal. The datum a phase-estimation read-out +(inverse QFT) processes wire by wire. -/ +theorem quditPhaseGrad_inner_quditBasis (θ : ℝ) (d : ℕ) [NeZero d] (j : Fin d) : + inner ℂ (quditBasis j).vec (quditPhaseGrad θ d).vec + = (Real.sqrt d : ℂ)⁻¹ * Complex.exp ((θ : ℂ) * Complex.I * (j : ℕ)) := by + simp only [quditPhaseGrad_vec, inner_sum, inner_smul_right, quditBasis_inner, mul_ite, + mul_one, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + +/-- **At zero slope the phase gradient is the uniform superposition:** +`quditPhaseGrad 0 d = uniformSuperposition d`. With `θ = 0` every linear phase `e^{iθk}` is `1`, so +each amplitude collapses to `1/√d` — the equal superposition `(1/√d) ∑ₖ |k⟩`. -/ +theorem quditPhaseGrad_zero (d : ℕ) [NeZero d] : + quditPhaseGrad 0 d = uniformSuperposition d := by + apply PureState.ext + rw [quditPhaseGrad_vec, uniformSuperposition_vec, Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [Complex.ofReal_zero, zero_mul, zero_mul, Complex.exp_zero, mul_one] + +/-- **The forward Fourier image is the phase gradient of slope `2πj/d`.** The QFT image state +`qftFourierImage d j = (1/√d) ∑ₖ e^{2πijk/d} |k⟩` (N&C eq. 5.2/5.79) is exactly `quditPhaseGrad` at +the rational slope `θ = 2πj/d`: `qftFourierImage d j = quditPhaseGrad (2πj/d) d`. This is the sense +in which `quditPhaseGrad` generalizes the Fourier image — the linear phase `e^{2πijk/d}` is +`e^{iθk}` for `θ = 2πj/d`. -/ +theorem quditPhaseGrad_eq_qftFourierImage (d : ℕ) [NeZero d] (j : Fin d) : + qftFourierImage d j = quditPhaseGrad (2 * Real.pi * (j : ℕ) / d) d := by + apply PureState.ext + rw [qftFourierImage_vec, quditPhaseGrad_vec] + refine Finset.sum_congr rfl fun k _ => ?_ + congr 3; push_cast; ring + +/-- **The inverse Fourier image is the phase gradient of slope `−2πk/d`.** The inverse-QFT image +`qftInverseFourierImage d k = (1/√d) ∑ⱼ e^{−2πijk/d} |j⟩` (N&C Exercise 5.5) is `quditPhaseGrad` at +the rational slope `θ = −2πk/d`: `qftInverseFourierImage d k = quditPhaseGrad (−2πk/d) d`. The +eigenstates of the cyclic shift `periodShift p y` are inverse Fourier images, so this reads them as +phase gradients of the register. -/ +theorem quditPhaseGrad_eq_qftInverseFourierImage (d : ℕ) [NeZero d] (k : Fin d) : + qftInverseFourierImage d k = quditPhaseGrad (-(2 * Real.pi * (k : ℕ)) / d) d := by + apply PureState.ext + rw [qftInverseFourierImage_vec, quditPhaseGrad_vec] + refine Finset.sum_congr rfl fun j _ => ?_ + congr 3; push_cast; ring + +/-- **Overlap of two phase gradients.** For real slopes `α, β`, the inner product of the +phase-gradient states is the normalized geometric sum of the slope difference: +`⟨φ_α | φ_β⟩ = (1/d) ∑ₖ e^{i(β−α)k}`. The two `1/√d` normalizations combine to `1/d`, and +orthonormality of the computational basis collapses the double sum to its diagonal, where the +conjugate phase `e^{−iαk}` (from the antilinear first slot) meets `e^{iβk}`. This is the algebraic +heart of the phase-estimation read-out amplitude below. -/ +theorem quditPhaseGrad_inner_quditPhaseGrad (α β : ℝ) (d : ℕ) [NeZero d] : + inner ℂ (quditPhaseGrad α d).vec (quditPhaseGrad β d).vec + = (d : ℂ)⁻¹ * ∑ k : Fin d, Complex.exp (((β - α : ℝ) : ℂ) * Complex.I * (k : ℕ)) := by + conv_lhs => rw [quditPhaseGrad_vec] + rw [sum_inner, Finset.mul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [inner_smul_left, quditPhaseGrad_inner_quditBasis] + have hd : ((Real.sqrt d : ℂ))⁻¹ * (Real.sqrt d : ℂ)⁻¹ = (d : ℂ)⁻¹ := by + rw [← mul_inv, ← Complex.ofReal_mul, Real.mul_self_sqrt (by positivity), + Complex.ofReal_natCast] + have hconj : (starRingEnd ℂ) ((Real.sqrt d : ℂ)⁻¹ * Complex.exp ((α : ℂ) * Complex.I * (k : ℕ))) + = (Real.sqrt d : ℂ)⁻¹ * Complex.exp (-((α : ℂ) * Complex.I * (k : ℕ))) := by + rw [map_mul, map_inv₀, Complex.conj_ofReal, ← Complex.exp_conj] + congr 1 + simp [Complex.conj_I] + rw [hconj, mul_mul_mul_comm, hd, ← Complex.exp_add] + congr 2 + push_cast + ring + +/-- **The phase-estimation read-out amplitude** (N&C §5.2.1, eqs. 5.23–5.24). When the terminal +inverse QFT of phase estimation acts on the phase gradient `|φ_θ⟩` of slope `θ`, the amplitude of +the computational-basis outcome `|m⟩` is the normalized geometric sum +`⟨m | F⁻¹ | φ_θ⟩ = (1/d) ∑ₖ e^{i(θ − 2πm/d)k}` — N&C's coefficient `αₗ` (eq. 5.24) with `θ = 2πϕ`, +`d = 2ᵗ` and `m = b + l`. The slope offset `2πm/d` is the phase of the bin `|m⟩`, so the summand is +the *residual* phase `e^{i(θ − 2πm/d)k}`: `|αₘ|²` peaks at the bin `m/d` closest to the frequency +`θ/(2π)`. + +Proof: the inverse evolution is the adjoint of the QFT (`qftInverseEvolution = (qftEvolution d)†`), +so the adjoint moves across the inner product to give `⟨F|m⟩ | φ_θ⟩`; and `F|m⟩` is itself the phase +gradient of the dyadic slope `2πm/d` (`quditPhaseGrad_eq_qftFourierImage`), reducing the amplitude +to the phase-gradient overlap `quditPhaseGrad_inner_quditPhaseGrad` at `α = 2πm/d`, `β = θ`. -/ +theorem quditPhaseGrad_qftInverse_inner_quditBasis (θ : ℝ) (d : ℕ) [NeZero d] (m : Fin d) : + inner ℂ (quditBasis m).vec ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec + = (d : ℂ)⁻¹ * ∑ k : Fin d, + Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I * (k : ℕ)) := by + rw [Evolution.evolvePure_vec, qftInverseEvolution, Evolution.adjoint_op, + ContinuousLinearMap.adjoint_inner_right, ← Evolution.evolvePure_vec, + qftEvolution_evolvePure_quditBasis, quditPhaseGrad_eq_qftFourierImage, + quditPhaseGrad_inner_quditPhaseGrad] + +/-- **The read-out amplitude in closed form** (N&C §5.2.1, eqs. 5.25–5.26). Summing the geometric +series of `quditPhaseGrad_qftInverse_inner_quditBasis`, the amplitude on bin `|m⟩` is +`⟨m | F⁻¹ | φ_θ⟩ = (1/d)·(e^{iθd} − 1)/(e^{i(θ − 2πm/d)} − 1)`, valid whenever the ratio +`e^{i(θ − 2πm/d)} ≠ 1` (i.e. `θ − 2πm/d` is not a multiple of `2π`, so the geometric series is not +constant). This is N&C's eq. (5.25)/(5.26): the numerator `e^{iθd} − 1` is **bin-independent** — the +`2πm` phase of the bin drops out because `m` is an integer (`e^{−2πim} = 1`) — which is exactly what +makes `|numerator| ≤ 2` uniformly, the first step of the accuracy bound (eqs. 5.28–5.34). + +Proof: convert `∑ₖ e^{i(θ−2πm/d)k}` to `∑ₖ rᵏ` with `r = e^{i(θ−2πm/d)}` +(`Complex.exp_nat_mul`), sum it with `geom_sum_eq` (`r ≠ 1`), then simplify `rᵈ = e^{iθd}` by +absorbing the integer multiple `e^{−2πim} = 1` (`Complex.exp_int_mul_two_pi_mul_I`). -/ +theorem quditPhaseGrad_qftInverse_inner_quditBasis_geom (θ : ℝ) (d : ℕ) [NeZero d] (m : Fin d) + (hne : Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) ≠ 1) : + inner ℂ (quditBasis m).vec ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec + = (d : ℂ)⁻¹ * (Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) - 1) + / (Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) - 1) := by + rw [quditPhaseGrad_qftInverse_inner_quditBasis] + set φ : ℝ := θ - 2 * Real.pi * (m : ℕ) / d with hφ + have hr : ∀ k : Fin d, Complex.exp ((φ : ℂ) * Complex.I * (k : ℕ)) + = Complex.exp ((φ : ℂ) * Complex.I) ^ (k : ℕ) := fun k => by + rw [← Complex.exp_nat_mul]; congr 1; ring + have hsum : ∑ k : Fin d, Complex.exp ((φ : ℂ) * Complex.I * (k : ℕ)) + = (Complex.exp ((φ : ℂ) * Complex.I) ^ d - 1) / (Complex.exp ((φ : ℂ) * Complex.I) - 1) := by + rw [Finset.sum_congr rfl (fun k _ => hr k), + Fin.sum_univ_eq_sum_range (fun k => Complex.exp ((φ : ℂ) * Complex.I) ^ k) d, + geom_sum_eq hne] + have hpow : Complex.exp ((φ : ℂ) * Complex.I) ^ d + = Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) := by + rw [← Complex.exp_nat_mul] + have hdne : (d : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne d) + have key : (d : ℂ) * ((φ : ℂ) * Complex.I) + = ((θ * d : ℝ) : ℂ) * Complex.I + ((-m : ℤ) : ℂ) * (2 * (Real.pi : ℂ) * Complex.I) := by + rw [hφ]; push_cast; field_simp; ring + rw [key, Complex.exp_add, Complex.exp_int_mul_two_pi_mul_I, mul_one] + rw [hsum, hpow] + ring + +/-- **The modulus of the phase-estimation read-out amplitude, in closed form.** Taking the modulus +of the geometric closed form (`quditPhaseGrad_qftInverse_inner_quditBasis_geom`), the amplitude of +the computational outcome `|m⟩` after the terminal inverse QFT of the gradient `|φ_θ⟩` has modulus +`‖⟨m | F⁻¹ | φ_θ⟩‖ = (1/d)·‖e^{iθd} − 1‖ / ‖e^{iψ} − 1‖`, with `ψ = θ − 2πm/d` the residual phase of +the bin `|m⟩` (valid whenever `e^{iψ} ≠ 1`). The numerator `e^{iθd} − 1` is bin-independent; the +two chord lengths `‖e^{iθd} − 1‖` and `‖e^{iψ} − 1‖` are exactly the geometric quantities Nielsen & +Chuang bound in §5.2.1 (eqs. 5.28–5.29) to control how sharply `|αₘ|²` concentrates on the bin +nearest the frequency `θ/(2π)`. -/ +theorem quditPhaseGrad_qftInverse_norm_inner_quditBasis (θ : ℝ) (d : ℕ) [NeZero d] (m : Fin d) + (hne : Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) ≠ 1) : + ‖inner ℂ (quditBasis m).vec ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec‖ + = (d : ℝ)⁻¹ * ‖Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) - 1‖ + / ‖Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) - 1‖ := by + rw [quditPhaseGrad_qftInverse_inner_quditBasis_geom θ d m hne, norm_div, norm_mul, norm_inv, + Complex.norm_natCast] + +/-- **Nearest-bin concentration of phase estimation** — the read-out success amplitude. If the bin +`|m⟩` lies within half a bin-width of the frequency, i.e. its residual phase `ψ = θ − 2πm/d` +satisfies `|ψ| ≤ π/d`, then the read-out amplitude has modulus at least `2/π`: +`2/π ≤ ‖⟨m | F⁻¹ | φ_θ⟩‖`. Hence phase estimation places at least `(2/π)² = 4/π²` of the probability +on the bin nearest the frequency (`quditPhaseGrad_qftInverse_norm_inner_quditBasis_sq_ge`): the +sense in which the terminal inverse QFT reads out a good estimate even when `θ/(2π)` is not a dyadic +`m/d`. + +Proof: when `ψ = 0` the amplitude is exactly `1 ≥ 2/π`. Otherwise, through the closed-form modulus, +the numerator `‖e^{iθd} − 1‖ = ‖e^{iψd} − 1‖ ≥ (2/π)|ψd|` (the reverse chord bound +`Complex.two_div_pi_mul_abs_le_norm_one_sub_exp_ofReal_mul_I`, applicable since `|ψd| ≤ π`; the bin +phase `2πm` drops out as an integer multiple of `2π`), while the denominator `‖e^{iψ} − 1‖ ≤ |ψ|` +(the chord bound `Complex.norm_one_sub_exp_ofReal_mul_I_le`); the register size `d` cancels, leaving +`2/π`. -/ +theorem quditPhaseGrad_qftInverse_norm_inner_quditBasis_ge (θ : ℝ) (d : ℕ) [NeZero d] (m : Fin d) + (hnear : |θ - 2 * Real.pi * (m : ℕ) / d| ≤ Real.pi / d) : + 2 / Real.pi + ≤ ‖inner ℂ (quditBasis m).vec + ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec‖ := by + have hd0 : (d : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne d) + have hdpos : (0 : ℝ) < d := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne d) + have hd1 : (1 : ℝ) ≤ d := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne d) + rcases eq_or_ne (θ - 2 * Real.pi * (m : ℕ) / d) 0 with hz | hz + · -- Residual `ψ = 0`: the bin phase matches exactly, so the amplitude is `1`. + have hone : inner ℂ (quditBasis m).vec + ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec = 1 := by + rw [quditPhaseGrad_qftInverse_inner_quditBasis θ d m, hz] + simp only [Complex.ofReal_zero, zero_mul, Complex.exp_zero, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] + exact inv_mul_cancel₀ (by exact_mod_cast (NeZero.ne d : d ≠ 0)) + rw [hone, norm_one] + exact (div_le_one Real.pi_pos).mpr Real.two_le_pi + · -- Residual `ψ ≠ 0`: bound numerator below and denominator above through the closed form. + have hψabs : 0 < |θ - 2 * Real.pi * (m : ℕ) / d| := abs_pos.mpr hz + have hψπ : |θ - 2 * Real.pi * (m : ℕ) / d| ≤ Real.pi := by + have hle : Real.pi / (d : ℝ) ≤ Real.pi := by + rw [div_le_iff₀ hdpos] + calc Real.pi = Real.pi * 1 := (mul_one _).symm + _ ≤ Real.pi * d := mul_le_mul_of_nonneg_left hd1 Real.pi_pos.le + linarith + have hgeoψ := Complex.two_div_pi_mul_abs_le_norm_one_sub_exp_ofReal_mul_I hψπ + have hdenpos : 0 < + ‖Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) - 1‖ := by + rw [norm_sub_rev] + have hpos : 0 < 2 / Real.pi * |θ - 2 * Real.pi * (m : ℕ) / d| := mul_pos (by positivity) hψabs + linarith + have hne : Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) ≠ 1 := by + intro h; rw [h, sub_self, norm_zero] at hdenpos; exact lt_irrefl 0 hdenpos + -- Numerator: `e^{iθd} = e^{iψd}` after absorbing the integer bin phase `2πm`. + have hnumeq : Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) + = Complex.exp ((((θ - 2 * Real.pi * (m : ℕ) / d) * d : ℝ) : ℂ) * Complex.I) := by + have hdℂ : (d : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne d) + have key : ((θ * d : ℝ) : ℂ) * Complex.I + = (((θ - 2 * Real.pi * (m : ℕ) / d) * d : ℝ) : ℂ) * Complex.I + + (((m : ℕ) : ℤ) : ℂ) * (2 * (Real.pi : ℂ) * Complex.I) := by + push_cast + field_simp + ring + rw [key, Complex.exp_add, Complex.exp_int_mul_two_pi_mul_I, mul_one] + have hnum_ge : 2 / Real.pi * (|θ - 2 * Real.pi * (m : ℕ) / d| * d) + ≤ ‖Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) - 1‖ := by + rw [hnumeq, norm_sub_rev] + have hψd_le : |(θ - 2 * Real.pi * (m : ℕ) / d) * d| ≤ Real.pi := by + rw [abs_mul, abs_of_pos hdpos] + have hmul : |θ - 2 * Real.pi * (m : ℕ) / d| * d ≤ Real.pi / d * d := + mul_le_mul_of_nonneg_right hnear hdpos.le + rwa [div_mul_cancel₀ Real.pi hd0] at hmul + have hg := Complex.two_div_pi_mul_abs_le_norm_one_sub_exp_ofReal_mul_I hψd_le + rwa [abs_mul, abs_of_pos hdpos] at hg + have hden_le : ‖Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) - 1‖ + ≤ |θ - 2 * Real.pi * (m : ℕ) / d| := by + rw [norm_sub_rev] + exact Complex.norm_one_sub_exp_ofReal_mul_I_le _ + rw [quditPhaseGrad_qftInverse_norm_inner_quditBasis θ d m hne, le_div_iff₀ hdenpos] + -- Goal: `2/π · ‖e^{iψ}−1‖ ≤ d⁻¹ · ‖e^{iθd}−1‖`. + have hpi : Real.pi ≠ 0 := Real.pi_ne_zero + have hcancel : (d : ℝ)⁻¹ * (2 / Real.pi * (|θ - 2 * Real.pi * (m : ℕ) / d| * d)) + = 2 / Real.pi * |θ - 2 * Real.pi * (m : ℕ) / d| := by + field_simp + calc 2 / Real.pi + * ‖Complex.exp (((θ - 2 * Real.pi * (m : ℕ) / d : ℝ) : ℂ) * Complex.I) - 1‖ + ≤ 2 / Real.pi * |θ - 2 * Real.pi * (m : ℕ) / d| := + mul_le_mul_of_nonneg_left hden_le (by positivity) + _ = (d : ℝ)⁻¹ * (2 / Real.pi * (|θ - 2 * Real.pi * (m : ℕ) / d| * d)) := hcancel.symm + _ ≤ (d : ℝ)⁻¹ * ‖Complex.exp (((θ * d : ℝ) : ℂ) * Complex.I) - 1‖ := + mul_le_mul_of_nonneg_left hnum_ge (by positivity) + +/-- **Nearest-bin success probability `≥ 4/π²`.** The Born probability of the read-out landing on +the bin `|m⟩` nearest the frequency (residual phase `|ψ| ≤ π/d`) is at least `4/π² ≈ 0.405`, the +squared form of `quditPhaseGrad_qftInverse_norm_inner_quditBasis_ge`. This is the quantitative sense +in which Kitaev's phase-estimation read-out "performs the transform" to finite precision: a constant +fraction of the probability — bounded away from `0`, independent of the register size `d` — +concentrates on the best estimate. -/ +theorem quditPhaseGrad_qftInverse_norm_inner_quditBasis_sq_ge (θ : ℝ) (d : ℕ) [NeZero d] (m : Fin d) + (hnear : |θ - 2 * Real.pi * (m : ℕ) / d| ≤ Real.pi / d) : + 4 / Real.pi ^ 2 + ≤ ‖inner ℂ (quditBasis m).vec + ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec‖ ^ 2 := by + have h := quditPhaseGrad_qftInverse_norm_inner_quditBasis_ge θ d m hnear + rw [show (4 : ℝ) / Real.pi ^ 2 = (2 / Real.pi) ^ 2 from by ring, pow_two, pow_two] + exact mul_self_le_mul_self (by positivity) h + +/-- **The phase-gradient state is `2π`-periodic in its slope** (up to integer multiples of `2π`). +Shifting `θ` by an integer multiple of `2π` leaves every amplitude `e^{iθk}` unchanged, since +`e^{−2πijk} = 1` for integers `j, k` (`Complex.exp_int_mul_two_pi_mul_I`), so the state itself is +invariant: `quditPhaseGrad (θ − 2π·j) d = quditPhaseGrad θ d` for every `j : ℤ`. This lets a slope +be replaced by any representative in the same `2π`-class — used to bring the residual phase +`θ − 2πm/d` of the *wrap-around* nearest bin into `[−π/d, π/d]`. -/ +theorem quditPhaseGrad_sub_intMul_two_pi (θ : ℝ) (d : ℕ) [NeZero d] (j : ℤ) : + quditPhaseGrad (θ - 2 * Real.pi * j) d = quditPhaseGrad θ d := by + apply PureState.ext + rw [quditPhaseGrad_vec, quditPhaseGrad_vec] + refine Finset.sum_congr rfl fun k _ => ?_ + have hexp : Complex.exp (((θ - 2 * Real.pi * j : ℝ) : ℂ) * Complex.I * (k : ℕ)) + = Complex.exp ((θ : ℂ) * Complex.I * (k : ℕ)) := by + rw [show ((θ - 2 * Real.pi * j : ℝ) : ℂ) * Complex.I * (k : ℕ) + = (θ : ℂ) * Complex.I * (k : ℕ) + + ((-(j * (k : ℕ)) : ℤ) : ℂ) * (2 * (Real.pi : ℂ) * Complex.I) + from by push_cast; ring, + Complex.exp_add, Complex.exp_int_mul_two_pi_mul_I, mul_one] + rw [hexp] + +/-- **The nearest computational bin to a phase-gradient slope.** For real slope `θ` and register +size `d`, `nearestBin θ d : Fin d` is the computational-basis index `round(θ·d/(2π)) mod d` — the +bin whose phase `2π·(nearestBin θ d)/d` best matches `θ`, i.e. the best `⌈log₂ d⌉`-bit estimate of +the frequency `θ/(2π)`. The `round` picks the closest integer (`abs_sub_round`), and `mod d` folds +it into `Fin d` (absorbing the `2π` wrap-around when `θ/(2π)` is near `1`). This is the outcome the +phase-estimation read-out lands on with probability `≥ 4/π²` +(`quditPhaseGrad_qftInverse_norm_inner_nearestBin_sq_ge`). -/ +def nearestBin (θ : ℝ) (d : ℕ) [NeZero d] : Fin d := + ⟨(round (θ * (d : ℝ) / (2 * Real.pi)) % (d : ℤ)).toNat, by + have hdℤpos : (0 : ℤ) < d := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne d) + have h1 : 0 ≤ round (θ * (d : ℝ) / (2 * Real.pi)) % (d : ℤ) := + Int.emod_nonneg _ (by exact_mod_cast NeZero.ne d) + have h2 : round (θ * (d : ℝ) / (2 * Real.pi)) % (d : ℤ) < d := Int.emod_lt_of_pos _ hdℤpos + exact (Int.toNat_lt h1).mpr h2⟩ + +/-- **Nearest-bin concentration of phase estimation, unconditionally** (N&C §5.2.1, the read-out +success bound at the best estimate). For *every* real slope `θ`, the terminal inverse-QFT read-out +of the phase gradient `|φ_θ⟩` lands on the nearest computational bin `nearestBin θ d` with Born +probability at least `4/π²`: +`4/π² ≤ ‖⟨nearestBin θ d | F⁻¹ | φ_θ⟩‖²`. + +This removes the `|θ − 2πm/d| ≤ π/d` hypothesis of +`quditPhaseGrad_qftInverse_norm_inner_quditBasis_sq_ge` by *choosing* the bin: `nearestBin θ d` += `round(θd/2π) mod d`, whose phase is within half a bin-width of `θ` (up to the `2π` wrap). It is +the quantitative sense in which phase estimation reads out the frequency to finite precision for an +*arbitrary* — in particular non-dyadic — slope, the general form behind Kitaev's QFT-over-`Z_p` +read-out (Problem 5.1). + +Proof: let `j = round(θd/2π) / d` (integer division). The gradient is `2π`-periodic in the slope +(`quditPhaseGrad_sub_intMul_two_pi`), so the read-out at `θ` equals the read-out at the +representative `θ' = θ − 2π·j`; and `θ' − 2π·(nearestBin θ d)/d = θ − 2π·round(θd/2π)/d`, of modulus +`(2π/d)·|θd/2π − round(θd/2π)| ≤ (2π/d)·(1/2) = π/d` (`abs_sub_round`). Apply the hypothesis form at +`θ'`. -/ +theorem quditPhaseGrad_qftInverse_norm_inner_nearestBin_sq_ge (θ : ℝ) (d : ℕ) [NeZero d] : + 4 / Real.pi ^ 2 + ≤ ‖inner ℂ (quditBasis (nearestBin θ d)).vec + ((qftInverseEvolution d).evolvePure (quditPhaseGrad θ d)).vec‖ ^ 2 := by + have hd0 : (d : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne d) + have hdpos : (0 : ℝ) < d := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne d) + have h2pi : (2 * Real.pi) ≠ 0 := ne_of_gt (by positivity) + -- the bin's integer value is the nonnegative residue `round(θd/2π) mod d` + have hval : (((nearestBin θ d : Fin d) : ℕ) : ℤ) + = round (θ * (d : ℝ) / (2 * Real.pi)) % (d : ℤ) := + Int.toNat_of_nonneg (Int.emod_nonneg _ (by exact_mod_cast NeZero.ne d)) + -- replace the read-out at `θ` by the read-out at the periodic representative `θ − 2π·j` + rw [← quditPhaseGrad_sub_intMul_two_pi θ d (round (θ * (d : ℝ) / (2 * Real.pi)) / (d : ℤ))] + apply quditPhaseGrad_qftInverse_norm_inner_quditBasis_sq_ge + set r : ℤ := round (θ * (d : ℝ) / (2 * Real.pi)) with hr + set j : ℤ := r / (d : ℤ) with hj + -- integer split `r = d·j + (nearestBin θ d)`, so the residual telescopes + have hrdj : (d : ℤ) * j + (((nearestBin θ d : Fin d) : ℕ) : ℤ) = r := by + rw [hval, hj]; exact Int.mul_ediv_add_emod r (d : ℤ) + have hrdjR : (d : ℝ) * (j : ℝ) + (((nearestBin θ d : Fin d) : ℕ) : ℝ) = (r : ℝ) := by + exact_mod_cast hrdj + have hkey : (θ - 2 * Real.pi * (j : ℝ)) + - 2 * Real.pi * (((nearestBin θ d : Fin d) : ℕ) : ℝ) / (d : ℝ) + = (2 * Real.pi / d) * (θ * (d : ℝ) / (2 * Real.pi) - (r : ℝ)) := by + have hm : (((nearestBin θ d : Fin d) : ℕ) : ℝ) = (r : ℝ) - (d : ℝ) * (j : ℝ) := by + linarith [hrdjR] + rw [hm]; field_simp; ring + rw [hkey, abs_mul, abs_of_pos (by positivity : (0 : ℝ) < 2 * Real.pi / d)] + have habs : |θ * (d : ℝ) / (2 * Real.pi) - (r : ℝ)| ≤ 1 / 2 := by + rw [hr]; exact_mod_cast abs_sub_round (θ * (d : ℝ) / (2 * Real.pi)) + calc (2 * Real.pi / d) * |θ * (d : ℝ) / (2 * Real.pi) - (r : ℝ)| + ≤ (2 * Real.pi / d) * (1 / 2) := mul_le_mul_of_nonneg_left habs (by positivity) + _ = Real.pi / d := by field_simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/QuditTensorFactor.lean b/LeanPool/AxQM/Postulates/API/QuditTensorFactor.lean new file mode 100644 index 0000000000..f643101dc7 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/QuditTensorFactor.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.QuditPairPermGate +public import LeanPool.AxQM.Postulates.API.QuditMeasurement +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.SystemIso + +/-! +# AxQM.Postulates.API — factoring a qudit of composite dimension + +A `d·e`-level system is a *bipartite* system: `qudit (d·e) ≃ₛ qudit d ⊗ qudit e`, identifying the +computational basis `|x·e + y⟩` of the single register with the product basis `|x⟩ ⊗ |y⟩` of the +pair. This file supplies that **system isomorphism** and its computational-basis action. + +## What is formalised + +* `quditProdIso d e` — the system isomorphism `qudit (d·e) ≃ₛ qudit d ⊗ qudit e`. It is the + `OrthonormalBasis.equiv` sending the computational basis `quditOrthonormalBasis (d·e)` of + `qudit (d·e)` to the product basis `quditPairBasis d e` of `qudit d ⊗ qudit e` along + `finProdFinEquiv : Fin d × Fin e ≃ Fin (d·e)`; packaged as a `QSystem.Iso` (a linear isometric + equivalence of state spaces), exactly as `quditFinCardIso` is built from `OrthonormalBasis.equiv`. +* `quditProdIso_toIsometry_quditBasis` — the **defining action** on vectors: + `Φ |finProdFinEquiv (x, y)⟩ = |x⟩ ⊗ |y⟩`. +* `quditProdIso_congr_quditBasis` / `quditProdIso_congr_toState` — the same action transported to + pure states and to density-operator states: `Φ · |x·e+y⟩ = |x⟩ ⊗ |y⟩` and + `Φ · |x·e+y⟩⟨x·e+y| Φ⁻¹ = (|x⟩ ⊗ |y⟩)(⟨x| ⊗ ⟨y|)`. These are what a caller rewrites with, rather + than re-unfolding the iso into its `OrthonormalBasis.equiv`. + +## Index convention + +`finProdFinEquiv (x, y)` has value `x·e + y` (`finProdFinEquiv_apply_val`), so `x : Fin d` is the +**high** (most-significant) part and `y : Fin e` the low part. Hence `quditProdIso 2 e` (using +`qubit = qudit 2` definitionally) is `qudit (2·e) ≃ₛ qubit ⊗ qudit e` peeling the leading qubit off +the front — the big-endian `|j₁⟩ ⊗ |j₂…jₙ⟩` split of N&C's `|j₁,…,jₙ⟩` register (§5.1). Iterating it +identifies `qudit (2ⁿ)` with an `n`-qubit tensor register; that recursion, and the transport of +`qftEvolution` onto it, are used in the whole-circuit measured-QFT reduction (Problem 5.2). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {d e : ℕ} + +/-- **Factoring a composite-dimension qudit** `qudit (d·e) ≃ₛ qudit d ⊗ qudit e`: the system +isomorphism identifying the `d·e`-level register with the bipartite `d`-by-`e` register. Built as +the `OrthonormalBasis.equiv` sending the computational basis `quditOrthonormalBasis (d·e)` to the +product basis `quditPairBasis d e` along `finProdFinEquiv : Fin d × Fin e ≃ Fin (d·e)` — so +`|finProdFinEquiv (x, y)⟩ ↦ |x⟩ ⊗ |y⟩` (`quditProdIso_toIsometry_quditBasis`). Mirrors +`quditFinCardIso`'s `OrthonormalBasis.equiv` construction of a `QSystem.Iso`. -/ +def quditProdIso (d e : ℕ) : (qudit (d * e)) ≃ₛ (qudit d ⊗ qudit e) := + ⟨(quditOrthonormalBasis (d * e)).equiv (quditPairBasis d e) finProdFinEquiv.symm⟩ + +/-- The underlying isometry of `quditProdIso` is the basis-reindexing equivalence it is defined by. +An unfolding lemma so the action lemmas can rewrite through the `QSystem.Iso` wrapper. -/ +theorem quditProdIso_toIsometry (d e : ℕ) : + (quditProdIso d e).toIsometry + = (quditOrthonormalBasis (d * e)).equiv (quditPairBasis d e) finProdFinEquiv.symm := + rfl + +/-- **Defining action of `quditProdIso` on a computational-basis vector.** The factorisation +isometry sends the single-register ket `|finProdFinEquiv (x, y)⟩ = |x·e + y⟩` to the product ket +`|x⟩ ⊗ |y⟩`. Proof: the ket is the basis vector `quditOrthonormalBasis (d·e)` at +`finProdFinEquiv (x, y)` (`quditOrthonormalBasis_apply`), so `OrthonormalBasis.equiv_apply_basis` +moves the isometry to `quditPairBasis d e` at `finProdFinEquiv.symm (finProdFinEquiv (x, y)) = +(x, y)`, which is `|x⟩ ⊗ |y⟩` by `quditPairBasis_apply`. -/ +theorem quditProdIso_toIsometry_quditBasis (d e : ℕ) (x : Fin d) (y : Fin e) : + (quditProdIso d e).toIsometry (quditBasis (finProdFinEquiv (x, y))).vec + = (quditBasis x).vec ⊗ₜ[ℂ] (quditBasis y).vec := by + rw [quditProdIso_toIsometry, ← quditOrthonormalBasis_apply, OrthonormalBasis.equiv_apply_basis, + Equiv.symm_apply_apply, quditPairBasis_apply] + +/-- **Action of `quditProdIso` on a computational-basis pure state:** transporting the ket +`|finProdFinEquiv (x, y)⟩` of `qudit (d·e)` along the factorisation gives the product pure state +`|x⟩ ⊗ |y⟩` of `qudit d ⊗ qudit e`. The `PureState` companion of +`quditProdIso_toIsometry_quditBasis`. -/ +theorem quditProdIso_congr_quditBasis (d e : ℕ) (x : Fin d) (y : Fin e) : + PureState.congr (quditProdIso d e) (quditBasis (finProdFinEquiv (x, y))) + = (quditBasis x) ⊗ (quditBasis y) := by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec, quditProdIso_toIsometry_quditBasis] + +/-- **The symm-direction basis law for `quditProdIso`.** The companion of +`quditProdIso_congr_quditBasis`: transporting a product basis state `|x⟩ ⊗ |y⟩` back along +`(quditProdIso d e).symm` gives the computational basis vector at the packed index +`finProdFinEquiv (x, y)`. Immediate from the forward law via the `symm`-transport roundtrip +`PureState.congr_symm_congr`. -/ +theorem quditProdIso_symm_congr_quditBasis (d e : ℕ) (x : Fin d) (y : Fin e) : + PureState.congr (quditProdIso d e).symm ((quditBasis x).tmul (quditBasis y)) + = quditBasis (finProdFinEquiv (x, y)) := by + rw [← quditProdIso_congr_quditBasis d e x y, PureState.congr_symm_congr] + +/-- **Action of `quditProdIso` on a computational-basis density-operator state:** transporting the +diagonal state `|finProdFinEquiv (x, y)⟩⟨finProdFinEquiv (x, y)|` along the factorisation gives the +product state `(|x⟩ ⊗ |y⟩)(⟨x| ⊗ ⟨y|)`. The `State` companion, obtained from +`quditProdIso_congr_quditBasis` through `PureState.congr_toState`. -/ +theorem quditProdIso_congr_toState (d e : ℕ) (x : Fin d) (y : Fin e) : + State.congr (quditProdIso d e) (quditBasis (finProdFinEquiv (x, y))).toState + = ((quditBasis x) ⊗ (quditBasis y)).toState := by + rw [← PureState.congr_toState, quditProdIso_congr_quditBasis] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RandomCodingConfusion.lean b/LeanPool/AxQM/Postulates/API/RandomCodingConfusion.lean new file mode 100644 index 0000000000..271772f460 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RandomCodingConfusion.lean @@ -0,0 +1,238 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspace +public import LeanPool.AxQM.Postulates.API.TensorPowMix +public import LeanPool.AxQM.Postulates.API.TypicalSubspaceEquipartition +public import LeanPool.AxQM.Postulates.API.Mixture + +/-! +# The expected conditional typical subspace projector `𝔼(P_M)` (N&C Thm 12.8, eqs. 12.76–77) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability) the decoding POVM is built from the **conditional typical subspace +projectors** `P_M` of the output codewords `σ_M = ⨂ᵢ E(ρ_{Mᵢ})` +(`Postulates/API/CondTypicalSubspace`). The error estimate of Box 12.5 averages over the random +choice of codewords, and the **false-decoding** (confusion) term (N&C eqs. (12.80)–(12.82)) is +controlled through the *expected* conditional typical projector of a single random codeword, + +`Q := 𝔼(P_{M'}) = ∑_{t : Fin n → ι} (∏ᵢ p_{tᵢ}) • P_t`, + +where the codeword's `n` letters `t : Fin n → ι` are drawn i.i.d. from the a-priori distribution +`pⱼ` (weight `∏ᵢ p_{tᵢ}`, `Postulates/API/TensorPowMix`) and `P_t = P(σ_t)` is the conditional +typical projector of the resulting output `σ_t = ⨂ᵢ E(ρ_{tᵢ})`. + +Two facts about `Q` are exactly the random-coding inputs N&C uses: + +* `0 ≤ Q` (each `P_t` is an orthogonal projector, hence positive; a nonnegative combination stays + positive) — the positivity the false-decoding decay + `State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le` requires of its positive weight; and +* `re tr(Q) ≤ exp(n(s + ε))` (N&C eq. (12.77) in expectation, `s = S_bar = ∑ⱼ pⱼ S(E(ρⱼ))`) — the + expectation of the deterministic per-codeword dimension bound `tr(P_M) ≤ exp(n(S_bar+ε))` + (`State.condTypicalSubspaceDim_le`, N&C eq. (12.77)), averaged against the probability weights. + +This file defines `Q`, proves these two facts, and proves their product with the equipartition +false-decoding decay `re tr(P σ_bar^⊗n P · Q) ≤ exp(-n(S(σ_bar)-ε)) · re tr Q` +(`State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le_of_trace_le`, +`Postulates/API/TypicalSubspaceEquipartition`): the two factors combine into the exponent +`exp(-n(S(σ_bar) - S_bar - 2ε))` of the HSW confusion bound (eq. (12.82)). Weaving in the +random-coding +average `𝔼(σ_M) = σ_bar^⊗n` through the middle factor, scaling by the `2^{nR} - 1` confusing +messages, +and assembling the other two terms of eq. (12.79) are not carried out in this file. + +## Main results + +* `AxQM.re_trace_finsetSum_real_smul` — a general linearity helper: the real part of the + trace of a **real-weighted operator sum** splits as `re tr(∑ₖ cₖ • Mₖ) = ∑ₖ cₖ · re tr(Mₖ)`. The + vehicle for pushing the codeword average through `re ∘ tr`. + +* `AxQM.State.expectedCondTypicalSubspaceProj` — the expected conditional typical subspace + projector `Q = ∑_t (∏ᵢ p_{tᵢ}) • P_t`. + +* `AxQM.State.expectedCondTypicalSubspaceProj_nonneg` — `0 ≤ Q`. + +* `AxQM.State.re_trace_expectedCondTypicalSubspaceProj_le` — `re tr(Q) ≤ exp(n(s+ε))` + (N&C eq. (12.77) in expectation). + +* `State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_expectedCondTypicalSubspaceProj_le` — the + **HSW confusion (false-decoding) term decay** `re tr(P σ_bar^⊗n P · Q) ≤ exp(-n(S(σ_bar) - s - + 2ε))` + (N&C eq. (12.82) exponent), the product of the equipartition decay with the two facts above. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, eqs. (12.76), (12.77), Box 12.5. +-/ + +@[expose] public section + +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The real part of the trace of a real-weighted operator sum splits over the sum.** For a +finite family of operators `Mₖ` on a complex normed space `E` and real weights `cₖ`, + +`re tr(∑ₖ cₖ • Mₖ) = ∑ₖ cₖ · re tr(Mₖ)` + +(the scalars being the complex coercions `(cₖ : ℂ)`). Pure linearity — `LinearMap.trace` is +`ℂ`-linear and `RCLike.re` is `ℝ`-additive with `re(↑c · z) = c · re z` — with no use of any +`QSystem` structure, so it is stated over an abstract `E` (matching the sibling trace helpers +`AxQM.trace_smul_left`/`trace_smul_right`). It is the vehicle for pushing the +random-coding average of the HSW error estimate through `re ∘ tr` (its consumers here instantiate +at `E := (⨂ₛ _ : Fin n, S).space`). -/ +theorem re_trace_finsetSum_real_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] + {κ : Type*} (fs : Finset κ) (c : κ → ℝ) (M : κ → E →L[ℂ] E) : + RCLike.re (LinearMap.trace ℂ E + ((∑ k ∈ fs, (c k : ℂ) • M k : E →L[ℂ] E) : E →ₗ[ℂ] E)) + = ∑ k ∈ fs, c k * RCLike.re (LinearMap.trace ℂ E ((M k : E →ₗ[ℂ] E))) := by + rw [ContinuousLinearMap.toLinearMap_sum, map_sum, RCLike.re_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul] + exact RCLike.re_ofReal_mul _ _ + +variable {ι : Type*} [Fintype ι] + +/-- **The expected conditional typical subspace projector** `𝔼(P_M)` (Nielsen & Chuang, +Theorem 12.8, the random-coding average of eqs. (12.76)–(12.77)). For an a-priori distribution +`{pⱼ, ρⱼ}` of channel inputs, the quantum operation `E`, block length `n`, and thresholds `s`, `ε`, +it is the average — over the i.i.d. random choice of the codeword's `n` letters `t : Fin n → ι` +(weight `∏ᵢ p_{tᵢ}`) — of the conditional typical subspace projector `P_t` of the output codeword +`σ_t = ⨂ᵢ E(ρ_{tᵢ})`: + +`𝔼(P_M) = ∑_{t : Fin n → ι} (∏ᵢ p_{tᵢ}) • P_t`. + +It is the positive weight through which the false-decoding term of the HSW random-coding error +estimate is controlled (N&C eqs. (12.80)–(12.82)). -/ +def State.expectedCondTypicalSubspaceProj (p : ι → ℝ) (E : State S → State S) (ρ : ι → State S) + (n : ℕ) (s ε : ℝ) : (⨂ₛ _ : Fin n, S).space →L[ℂ] (⨂ₛ _ : Fin n, S).space := + ∑ t : Fin n → ι, ((∏ i, p (t i) : ℝ) : ℂ) • + State.condTypicalSubspaceProj (fun i => E (ρ (t i))) s ε + +/-- **The expected conditional typical projector is positive**, `0 ≤ 𝔼(P_M)` (Nielsen & Chuang, +Theorem 12.8). Each conditional typical projector `P_t` is an orthonormal (self-adjoint idempotent) +projector, hence positive (`IsStarProjection.nonneg`); the average with the nonnegative i.i.d. +weights `∏ᵢ p_{tᵢ}` is therefore a nonnegative combination of positive operators. This is the +positivity the false-decoding decay `State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le` +demands of its positive weight in the HSW random-coding estimate. -/ +theorem State.expectedCondTypicalSubspaceProj_nonneg (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (E : State S → State S) (ρ : ι → State S) (n : ℕ) (s ε : ℝ) : + 0 ≤ State.expectedCondTypicalSubspaceProj p E ρ n s ε := by + unfold State.expectedCondTypicalSubspaceProj + refine Finset.sum_nonneg fun t _ => ?_ + rw [Complex.coe_smul] + refine smul_nonneg (Finset.prod_nonneg fun i _ => hp (t i)) ?_ + exact (isStarProjection_orthonormalProjector + (State.piTensorEigenbasis (fun i => E (ρ (t i)))).orthonormal _).nonneg + +/-- **The expected conditional typical subspace dimension bound**, `re tr(𝔼(P_M)) ≤ exp(n(s+ε))` +(Nielsen & Chuang, Theorem 12.8, eq. (12.77) in expectation). The trace of the expected projector +is the expected rank `∑_t (∏ᵢ p_{tᵢ}) · dim(P_t)`; each `dim(P_t) ≤ exp(n(s+ε))` by the +deterministic per-codeword dimension bound `State.condTypicalSubspaceDim_le` (N&C eq. (12.77)), and +the weights sum to one (`sum_iidProdWeight`), so the expectation obeys the same bound. With +`s = S_bar = ∑ⱼ pⱼ S(E(ρⱼ))` this is N&C's `𝔼(tr(P_M)) ≤ 2^{n(S_bar+ε)}` (natural-log/nats +convention), +the term feeding the `exp(n(S_bar+ε))` factor of the confusion bound (eq. (12.82)). + +The proof pushes the trace through the average (`re_trace_finsetSum_real_smul`), rewrites each +`re tr(P_t)` to `dim(P_t)` (`State.trace_condTypicalSubspaceProj_eq_condTypicalSubspaceDim`), bounds +each summand, and collapses `∑_t (∏ᵢ p_{tᵢ}) · exp(n(s+ε)) = exp(n(s+ε))`. -/ +theorem State.re_trace_expectedCondTypicalSubspaceProj_le (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) (E : State S → State S) (ρ : ι → State S) (n : ℕ) (s ε : ℝ) : + RCLike.re (LinearMap.trace ℂ (⨂ₛ _ : Fin n, S).space + ((State.expectedCondTypicalSubspaceProj p E ρ n s ε : + (⨂ₛ _ : Fin n, S).space →ₗ[ℂ] (⨂ₛ _ : Fin n, S).space))) + ≤ Real.exp ((n : ℝ) * (s + ε)) := by + unfold State.expectedCondTypicalSubspaceProj + rw [re_trace_finsetSum_real_smul] + have hdim : ∀ t : Fin n → ι, RCLike.re (LinearMap.trace ℂ (⨂ₛ _ : Fin n, S).space + ((State.condTypicalSubspaceProj (fun i => E (ρ (t i))) s ε : + (⨂ₛ _ : Fin n, S).space →ₗ[ℂ] (⨂ₛ _ : Fin n, S).space))) + = (State.condTypicalSubspaceDim (fun i => E (ρ (t i))) s ε : ℝ) := fun t => by + rw [State.trace_condTypicalSubspaceProj_eq_condTypicalSubspaceDim] + simp + calc ∑ t : Fin n → ι, (∏ i, p (t i)) * RCLike.re (LinearMap.trace ℂ (⨂ₛ _ : Fin n, S).space + ((State.condTypicalSubspaceProj (fun i => E (ρ (t i))) s ε : + (⨂ₛ _ : Fin n, S).space →ₗ[ℂ] (⨂ₛ _ : Fin n, S).space))) + ≤ ∑ t : Fin n → ι, (∏ i, p (t i)) * Real.exp ((n : ℝ) * (s + ε)) := by + refine Finset.sum_le_sum fun t _ => ?_ + rw [hdim t] + refine mul_le_mul_of_nonneg_left ?_ (Finset.prod_nonneg fun i _ => hp (t i)) + have hle := State.condTypicalSubspaceDim_le (fun i => E (ρ (t i))) s ε + rwa [Fintype.card_fin] at hle + _ = (∑ t : Fin n → ι, ∏ i, p (t i)) * Real.exp ((n : ℝ) * (s + ε)) := by rw [Finset.sum_mul] + _ = Real.exp ((n : ℝ) * (s + ε)) := by rw [sum_iidProdWeight p hsum n, one_mul] + +/-- **The HSW confusion (false-decoding) term decay** (Nielsen & Chuang, Theorem 12.8, the confusion +exponent of eq. (12.82)). For the average channel output `σ_bar = ∑ⱼ pⱼ E(ρⱼ)` (`State.mix`), the +projector `P = σ_bar.typicalSubspaceProj n ε` onto its `ε`-typical subspace, and the expected +conditional typical projector `Q = 𝔼(P_M)` of a single random codeword, + +`re tr(P σ_bar^⊗n P · Q) ≤ exp(-n (S(σ_bar) - s - 2ε))` + +(in nats; N&C's base-`2` `tr(P σ_bar^⊗n P E(P₁)) ≤ 2^{-n(S(σ_bar) - S_bar - 2ε)}`, with the +threshold +`s = S_bar = ∑ⱼ pⱼ S(σⱼ)` defining `Q`). This is the middle, false-decoding contribution to the +random-coding +average error: in N&C's estimate the confusion of message `M` with a *different* random codeword +`M'` is governed by `tr(P 𝔼(σ_M) P 𝔼(P_{M'}))`, whose middle factor `𝔼(σ_M) = σ_bar^⊗n` is the +random-coding average and whose weight `𝔼(P_{M'}) = Q` is the expected conditional typical +projector. + +It is the exact product of the two ingredients recorded above with the equipartition decay in +`Postulates/API/TypicalSubspaceEquipartition`: + +* the **equipartition false-decoding decay** + `State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le_of_trace_le`, + `re tr(P σ_bar^⊗n P · Q) ≤ exp(-n(S(σ_bar) - ε)) · D` for any `0 ≤ Q` with `re tr Q ≤ D`; + instantiated at +* `Q = 𝔼(P_M)` (`State.expectedCondTypicalSubspaceProj`), positive + (`State.expectedCondTypicalSubspaceProj_nonneg`) with `re tr Q ≤ D = exp(n(s + ε))` + (`State.re_trace_expectedCondTypicalSubspaceProj_le`, N&C eq. (12.77) in expectation). + +The two exponential factors multiply into a single exponent, +`exp(-n(S(σ_bar) - ε)) · exp(n(s + ε)) = exp(-n(S(σ_bar) - s - 2ε))`. Provided `s = S_bar` and +`R < S(σ_bar) - S_bar`, this exponent (scaled by the `2^{nR} - 1` confusing messages) decays to +`0`, the +heart of the HSW achievability estimate (N&C eqs. (12.82)–(12.83)); that union-bound scaling and +the assembly of the other two terms of eq. (12.79) are not carried out in this file. + +`Q` lives on the constant-family system `⨂ₛ _ : Fin n, S` (its native form) while the equipartition +factor lives on `S ^⊗ₛ n`; the two systems are definitionally equal (`QSystem.tensorPow` *is* +`piTensor` of the constant family), so `Q` is transported along `QSystem.tensorPow_eq` (a `rfl` +identity) to sit on `S ^⊗ₛ n` for the product. -/ +theorem State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_expectedCondTypicalSubspaceProj_le + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) (E : State S → State S) + (ρ : ι → State S) (n : ℕ) (s ε : ℝ) : + RCLike.re (LinearMap.trace ℂ (S ^⊗ₛ n).space + ((((State.mix p hp hsum fun i => E (ρ i)).typicalSubspaceProj n ε).comp + (((State.mix p hp hsum fun i => E (ρ i)).tensorPow n).op.comp + ((State.mix p hp hsum fun i => E (ρ i)).typicalSubspaceProj n ε)) * + ((QSystem.tensorPow_eq S n).symm ▸ + State.expectedCondTypicalSubspaceProj p E ρ n s ε) : _ →L[ℂ] _) : _ →ₗ[ℂ] _)) + ≤ Real.exp (-(n : ℝ) * + ((State.mix p hp hsum fun i => E (ρ i)).vonNeumannEntropy - s - 2 * ε)) := by + have hkey := State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le_of_trace_le + (State.mix p hp hsum fun i => E (ρ i)) n ε + (State.expectedCondTypicalSubspaceProj_nonneg p hp E ρ n s ε) + (State.re_trace_expectedCondTypicalSubspaceProj_le p hp hsum E ρ n s ε) + refine hkey.trans_eq ?_ + rw [← Real.exp_add] + congr 1 + ring + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RandomCodingConfusionExpectation.lean b/LeanPool/AxQM/Postulates/API/RandomCodingConfusionExpectation.lean new file mode 100644 index 0000000000..744da30624 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RandomCodingConfusionExpectation.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.RandomCodingConfusion +public import LeanPool.AxQM.ToMathlib.InformationTheory.RandomCodingExpectation + +/-! +# The random-coding expectation of the HSW confusion term (N&C Thm 12.8, eqs. 12.80–12.82) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability), the per-code average error is bounded by three physical traces +(N&C eq. (12.79), `State.avgError_prettyGood_le_re_trace_percode`). The **confusion** +(false-decoding) contribution — the probability of decoding a random codeword `M` as a *different* +message `M'` — is `∑_{M'≠M} tr(P σ_M P P_{M'})`, where `P = σ_bar.typicalSubspaceProj n ε` is the +typical projector of the average output `σ_bar = ∑ⱼ pⱼ E(ρⱼ)`, `σ_M = ⨂ᵢ E(ρ_{Mᵢ})` the output +codeword, and +`P_{M'} = State.condTypicalSubspaceProj (σ_{M'}) s ε` its conditional typical projector. + +This file takes the **random-coding expectation** of one such confusion trace. For two *distinct* +messages `M ≠ M'` the codewords are drawn independently, so — averaging the codebook against the +i.i.d. product weight `∏_M ∏ᵢ p((w M) i)` — the two-codeword marginal +(`Real.sum_pi_weight_mul_apply₂`) factors the expectation into a product of single-codeword +expectations, `𝔼[σ_M] = σ_bar^⊗n` (`State.tensorPow_mix`) and `𝔼[P_{M'}] = 𝔼(P_M)` +(`State.expectedCondTypicalSubspaceProj`). The resulting middle-factor trace +`re tr(P σ_bar^⊗n P 𝔼(P_M))` is then exactly the confusion-decay bound of +`Postulates/API/RandomCodingConfusion` (N&C eq. (12.82) exponent). + +## Main results + +* `AxQM.re_trace_comp_finsetSum_comp_comp_finsetSum` — a general ℝ-bilinearity helper: the + sandwiched trace `re tr(P (∑ᵢ cᵢ Aᵢ) P (∑ⱼ dⱼ Bⱼ))` splits as + `∑ᵢ ∑ⱼ cᵢ dⱼ · re tr(P Aᵢ P Bⱼ)`. + +* `AxQM.State.expectation_re_trace_confusion_prettyGood_le` — the **expected confusion + trace** for a message pair `M ≠ M'`: averaged over the random codebook, the confusion trace of the + per-code bound is at most `exp(-n (S(σ_bar) - s - 2ε))` (N&C eq. (12.82), one summand of the + `2^{nR} - 1` in the confusion sum). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.79)–(12.82). +-/ + +@[expose] public section + +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Bilinear ℝ-linearity of the sandwiched trace over two real-weighted operator sums.** For +operators on a complex normed space `E`, a projector-like `P`, and finite real-weighted sums +`∑ᵢ cᵢ Aᵢ`, `∑ⱼ dⱼ Bⱼ`, + +`re tr(P (∑ᵢ cᵢ Aᵢ) P (∑ⱼ dⱼ Bⱼ)) = ∑ᵢ ∑ⱼ cᵢ dⱼ · re tr(P Aᵢ P Bⱼ)`. + +Pure ℝ-bilinearity: composition distributes over the finite sums and the scalars, and `re ∘ trace` +is ℝ-linear (`re_trace_finsetSum_real_smul`). Stated over an abstract `E` so that, applied to the +HSW confusion trace, the unifier bridges the definitionally-equal `S ^⊗ₛ n` / `piTensor` framings of +its operands. -/ +theorem re_trace_comp_finsetSum_comp_comp_finsetSum {E : Type*} [NormedAddCommGroup E] + [NormedSpace ℂ E] {ι κ : Type*} [Fintype ι] [Fintype κ] (P : E →L[ℂ] E) + (c : ι → ℝ) (d : κ → ℝ) (A : ι → E →L[ℂ] E) (B : κ → E →L[ℂ] E) : + RCLike.re ((LinearMap.trace ℂ E) + ((P.comp ((∑ i, (c i : ℂ) • A i).comp P)).comp (∑ j, (d j : ℂ) • B j) : E →ₗ[ℂ] E)) + = ∑ i, ∑ j, c i * d j * + RCLike.re ((LinearMap.trace ℂ E) + (P.comp ((A i).comp (P.comp (B j))) : E →ₗ[ℂ] E)) := by + simp only [ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.smul_comp, + ContinuousLinearMap.comp_finsetSum, ContinuousLinearMap.comp_smul, + re_trace_finsetSum_real_smul, Finset.mul_sum, ContinuousLinearMap.comp_assoc] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => by ring + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The random-coding expectation of the HSW confusion trace** (Nielsen & Chuang, Theorem 12.8, +Box 12.5, eqs. (12.80)–(12.82)). Fix the input ensemble `{pₐ, ρₐ}`, the channel `E`, the block +length `n`, thresholds `s`, `ε`, and let `P = σ_bar.typicalSubspaceProj n ε` be the typical +projector +of the average output `σ_bar = ∑ₐ pₐ E(ρₐ)` (transported to `P`'s `piTensor` framing via the +`rfl`-identity `QSystem.tensorPow_eq`). For two *distinct* messages `M ≠ M'` of a `K`-message code, +the confusion +trace `tr(P σ_M P P_{M'})` — averaged over the random codebook `w : Fin K → Fin n → α` with the +i.i.d. product weight `∏_{M''} ∏ᵢ p((w M'') i)` — is at most the confusion exponent: + +`𝔼[ tr(P σ_M P P_{M'}) ] ≤ exp(-n (S(σ_bar) - s - 2ε))`. + +Because `M ≠ M'`, the two codewords are independent, so the two-codeword marginal +`Real.sum_pi_weight_mul_apply₂` factors the expectation into `re tr(P σ_bar^⊗n P 𝔼(P_M))` — the +average +output `𝔼[σ_M] = σ_bar^⊗n` (`State.tensorPow_mix`) sandwiched between `P`, weighted by the expected +conditional typical projector `𝔼[P_{M'}] = 𝔼(P_M)` (`State.expectedCondTypicalSubspaceProj`). The +recombination of the resulting double sum into that single sandwiched trace is the ℝ-bilinearity +`re_trace_comp_finsetSum_comp_comp_finsetSum`, and the final bound is the confusion decay +`State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_expectedCondTypicalSubspaceProj_le` +(eq. (12.82)). Summed over the `K - 1` confusing messages `M' ≠ M` this yields the +`(2^{nR} - 1)·exp(...)` confusion contribution of N&C's eq. (12.82). -/ +theorem State.expectation_re_trace_confusion_prettyGood_le + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (s ε : ℝ) + (P : (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) + (hP : P = QSystem.tensorPow_eq S n ▸ + (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj n ε) + {K : ℕ} {M M' : Fin K} (hMM' : M ≠ M') : + ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (w M i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε)))))) + ≤ Real.exp (-(n : ℝ) * + ((State.mix p hp hsum fun a => E (ρ a)).vonNeumannEntropy - s - 2 * ε)) := by + classical + -- Two-codeword independence marginal: collapse the codebook sum to a double sum over the two + -- independent codewords `v = w M`, `v' = w M'`. + rw [Real.sum_pi_weight_mul_apply₂ (fun c : Fin n → α => ∏ i, p (c i)) + (sum_iidProdWeight p hsum n) + (fun v v' => RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (v i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (v' i))) s ε))))))) + hMM'] + -- `σ_bar^⊗n.op = E(σ_M)` as an i.i.d. mixture of product ops (`tensorPow_mix`, `mix_op`). + have hop : ((State.mix p hp hsum fun a => E (ρ a)).tensorPow n).op + = ∑ v : Fin n → α, (↑(∏ i, p (v i)) : ℂ) • (State.piTensor fun i => E (ρ (v i))).op := by + rw [State.tensorPow_mix p hp hsum (fun a => E (ρ a)) n, State.mix_op] + -- Recombine the double sum into the single sandwiched trace (bilinear ℝ-linearity), fold the two + -- codeword sums back into `σ_bar^⊗n.op` (`hop`) and `𝔼(P_M)`, and rewrite `P` to the typical + -- projector (`hP`) — exactly the confusion-decay trace. + rw [← re_trace_comp_finsetSum_comp_comp_finsetSum P (fun v : Fin n → α => ∏ i, p (v i)) + (fun t : Fin n → α => ∏ i, p (t i)) (fun v => (State.piTensor fun i => E (ρ (v i))).op) + (fun t => State.condTypicalSubspaceProj (fun i => E (ρ (t i))) s ε), + ← hop, ← State.expectedCondTypicalSubspaceProj, hP] + exact State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_expectedCondTypicalSubspaceProj_le + p hp hsum E ρ n s ε + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RandomCodingExpectedError.lean b/LeanPool/AxQM/Postulates/API/RandomCodingExpectedError.lean new file mode 100644 index 0000000000..85ff4bb2f0 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RandomCodingExpectedError.lean @@ -0,0 +1,229 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspacePerCodeError +public import LeanPool.AxQM.Postulates.API.CondTypicalSubspaceExpectation +public import LeanPool.AxQM.Postulates.API.RandomCodingConfusionExpectation + +/-! +# The random-coding expected per-code error of the HSW pretty-good decoder (N&C Thm 12.8) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability, Box 12.5), Alice draws a length-`n` product-state codebook of `K` +messages by choosing every letter i.i.d. from an input ensemble `{pₐ, ρₐ}`; message `M`'s output +codeword is `σ_M = ⨂ᵢ E(ρ_{wᵢ})`. The pretty-good (square-root) decoder's per-code average error +`p_bar` is bounded, for each fixed codebook, by three physical traces (N&C eq. (12.79), +`State.avgError_prettyGood_le_re_trace_percode`): + +`p_bar ≤ (1/K) ∑_M [3·re tr((1−P) σ_M) + 2·re tr((1−P_M) σ_M) + ∑_{M'≠M} re tr(P σ_M P P_{M'})]`. + +This file takes the **random-coding expectation** `𝔼[·]` of that bound over the i.i.d. codebook, +producing N&C's eqs. (12.80)–(12.82): each of the three terms is averaged by its own +expectation lemma, and because the resulting bound is independent of `M` the outer `(1/K) ∑_M` +collapses. + +## Main result + +* `AxQM.State.expectation_avgError_prettyGood_le` — the **expected per-code error bound**: + averaging the per-code bound over the random codebook `w : Fin K → Fin n → α`, + + `𝔼[p_bar] ≤ 3·re tr((1−P) σ_bar^⊗n) + 2·V/(n ε²) + (K−1)·exp(−n(S(σ_bar) − s − 2ε))`, + + where `σ_bar = ∑ₐ pₐ E(ρₐ)` is the average output, `P = σ_bar.typicalSubspaceProj n ε` its typical + projector, and `V = ∑ₐ pₐ ∑_b λ_{a,b}(−log λ_{a,b} − s)²` the per-letter surprisal variance. + + The three terms come from: + * the **typical-defect** term `𝔼[re tr((1−P) σ_M)] = re tr((1−P) σ_bar^⊗n)`, the single-codeword + marginal `Real.sum_pi_weight_mul_apply` folding the average output `𝔼[σ_M] = σ_bar^⊗n` + (`State.tensorPow_mix`) through the `ℝ`-linear `re ∘ tr` (`re_trace_finsetSum_real_smul`); + * the **conditional-atypical** term `𝔼[re tr((1−P_M) σ_M)] ≤ V/(n ε²)`, the single-codeword + marginal reducing it to `State.expectation_re_trace_one_sub_condTypicalSubspaceProj_le` + (N&C eq. (12.76)); and + * the **confusion** term `∑_{M'≠M} 𝔼[re tr(P σ_M P P_{M'})] ≤ (K−1)·exp(−n(S(σ_bar)−s−2ε))`, the + two-codeword independence marginal per pair + (`State.expectation_re_trace_confusion_prettyGood_le`, N&C eq. (12.82)), summed over the `K−1` + confusing messages. + + As `n → ∞` (with `ε` fixed) the typical-defect and atypical terms vanish, and for a rate + `R < χ(E)` the confusion term `(K−1)·exp(…) ≈ e^{nR}·e^{−nχ}` vanishes too — the vanishing + expected error that derandomises to an achievable rate (not carried out here). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.79)–(12.82). +-/ + +@[expose] public section + +open scoped BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {α : Type*} [Fintype α] + +/-- **The random-coding expected per-code error bound of the HSW pretty-good decoder** (Nielsen & +Chuang, Theorem 12.8, Box 12.5, eqs. (12.80)–(12.82)). See the module docstring. -/ +theorem State.expectation_avgError_prettyGood_le + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hsum : ∑ a, p a = 1) + (E : State S → State S) (ρ : α → State S) (n : ℕ) (hn : 0 < n) (s ε : ℝ) (hε : 0 < ε) + (hs : s = ∑ a, p a * (E (ρ a)).vonNeumannEntropy) + (P : (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) + (hPsa : IsSelfAdjoint P) (hPidem : P.comp P = P) + (hP : P = QSystem.tensorPow_eq S n ▸ + (State.mix p hp hsum fun a => E (ρ a)).typicalSubspaceProj n ε) + {K : ℕ} [NeZero K] + (hA : ∀ (w : Fin K → Fin n → α) (M' : Fin K), + (0 : (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) + ≤ P.comp ((State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε).comp P)) : + ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + ((K : ℝ)⁻¹ * ∑ M : Fin K, (1 - RCLike.re ((LinearMap.trace ℂ + (QSystem.piTensor fun _ : Fin n => S).space) + (↑((State.piTensor fun i => E (ρ (w M i))).op.comp + ((POVM.prettyGood (fun M' => P.comp ((State.condTypicalSubspaceProj + (fun i => E (ρ (w M' i))) s ε).comp P)) (hA w)).elements (some M))) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)))) + ≤ 3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (QSystem.tensorPow_eq S n ▸ + ((State.mix p hp hsum fun a => E (ρ a)).tensorPow n).op)) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) + + 2 * ((∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (- Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2) / (n * ε ^ 2)) + + ((K : ℝ) - 1) * Real.exp (-(n : ℝ) * + ((State.mix p hp hsum fun a => E (ρ a)).vonNeumannEntropy - s - 2 * ε)) := by + classical + set σbar := State.mix p hp hsum fun a => E (ρ a) with hσbar + -- The i.i.d. length-`n` product weight is a probability distribution over codewords. + have hWsum : ∑ v : Fin n → α, ∏ i, p (v i) = 1 := sum_iidProdWeight p hsum n + -- The average output codeword: `σ_bar^⊗n.op = ∑_v (∏ᵢ p_{vᵢ}) • (⨂ᵢ E(ρ_{vᵢ})).op`. + have hop : (σbar.tensorPow n).op + = ∑ v : Fin n → α, (↑(∏ i, p (v i)) : ℂ) • (State.piTensor fun i => E (ρ (v i))).op := by + rw [hσbar, State.tensorPow_mix p hp hsum (fun a => E (ρ a)) n, State.mix_op] + -- **(T1) Typical-defect term**: `𝔼[re tr((1−P) σ_M)] = re tr((1−P) σ_bar^⊗n)`, via the single- + -- codeword marginal folding the average output through the `ℝ`-linear `re ∘ tr`. + have hT1 : ∀ _M : Fin K, ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (State.piTensor fun i => E (ρ (w _M i))).op))) + = RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op)))) := by + intro M + rw [Real.sum_pi_weight_mul_apply (fun v : Fin n → α => ∏ i, p (v i)) hWsum + (fun v => RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (State.piTensor fun i => E (ρ (v i))).op)))) M] + have hopP : (QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op : + (QSystem.piTensor fun _ : Fin n => S).space →L[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space) + = ∑ v : Fin n → α, (↑(∏ i, p (v i)) : ℂ) • (State.piTensor fun i => E (ρ (v i))).op := hop + rw [hopP] + have hpull : (1 - P) * (∑ v : Fin n → α, (↑(∏ i, p (v i)) : ℂ) • + (State.piTensor fun i => E (ρ (v i))).op) + = ∑ v : Fin n → α, (↑(∏ i, p (v i)) : ℂ) • + ((1 - P) * (State.piTensor fun i => E (ρ (v i))).op) := by + rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_finsetSum] + exact Finset.sum_congr rfl fun v _ => by + rw [ContinuousLinearMap.comp_smul, ContinuousLinearMap.mul_def] + rw [hpull, re_trace_finsetSum_real_smul] + -- **(T2) Conditional-atypical term**: `𝔼[re tr((1−P_M) σ_M)] ≤ V/(n ε²)` (N&C eq. (12.76)). + have hT2 : ∀ _M : Fin K, ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.condTypicalSubspaceProj (fun i => E (ρ (w _M i))) s ε) * + (State.piTensor fun i => E (ρ (w _M i))).op))) + ≤ (∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (- Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2) / (n * ε ^ 2) := by + intro M + rw [Real.sum_pi_weight_mul_apply (fun v : Fin n → α => ∏ i, p (v i)) hWsum + (fun v => RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.condTypicalSubspaceProj (fun i => E (ρ (v i))) s ε) * + (State.piTensor fun i => E (ρ (v i))).op)))) M] + simp only [ContinuousLinearMap.mul_def] + exact State.expectation_re_trace_one_sub_condTypicalSubspaceProj_le (fun a => E (ρ a)) p hp hsum + hn hε hs + -- **(T3) Confusion term** (per confusing message `M' ≠ M`): `𝔼[re tr(P σ_M P P_{M'})] ≤ exp(…)`. + have hT3 : ∀ (M M' : Fin K), M ≠ M' → ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (w M i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε)))))) + ≤ Real.exp (-(n : ℝ) * (σbar.vonNeumannEntropy - s - 2 * ε)) := by + intro M M' hMM' + exact State.expectation_re_trace_confusion_prettyGood_le p hp hsum E ρ n s ε P hP hMM' + -- Weight the pointwise per-code bound over the random codebook. + refine le_trans (Finset.sum_le_sum fun w _ => mul_le_mul_of_nonneg_left + (State.avgError_prettyGood_le_re_trace_percode (fun M i => E (ρ (w M i))) s ε P hPsa hPidem + (hA w)) + (Finset.prod_nonneg fun M'' _ => Finset.prod_nonneg fun i _ => hp _)) ?_ + -- Pull out `(1/K)` and swap the codebook/message sums. + have hrearrange : ∀ f : (Fin K → Fin n → α) → Fin K → ℝ, + (∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * ((K : ℝ)⁻¹ * ∑ M, f w M)) + = (K : ℝ)⁻¹ * ∑ M, ∑ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * f w M := by + intro f + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun M _ => Finset.sum_congr rfl fun w _ => by ring + rw [hrearrange] + -- The target bound is `M`-independent, so `(1/K) ∑_{M : Fin K}` of it collapses. + have hcollapse : ∀ c : ℝ, (K : ℝ)⁻¹ * ∑ _M : Fin K, c = c := fun c => by + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← mul_assoc, + inv_mul_cancel₀ (Nat.cast_ne_zero.mpr (NeZero.ne K)), one_mul] + rw [← hcollapse (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (QSystem.tensorPow_eq S n ▸ (σbar.tensorPow n).op)) : + (QSystem.piTensor fun _ : Fin n => S).space →ₗ[ℂ] + (QSystem.piTensor fun _ : Fin n => S).space)) + + 2 * ((∑ a, p a * ∑ b, (E (ρ a)).eigenvalueDist b * + (- Real.log ((E (ρ a)).eigenvalueDist b) - s) ^ 2) / (n * ε ^ 2)) + + ((K : ℝ) - 1) * Real.exp (-(n : ℝ) * (σbar.vonNeumannEntropy - s - 2 * ε)))] + gcongr with M + -- Per-message bound: the expectation of the three-trace bracket `≤` the target constant. + -- Distribute the codebook weight over the bracket, term by term. + have step : ∀ w : Fin K → Fin n → α, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + (3 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (State.piTensor fun i => E (ρ (w M i))).op))) + + 2 * RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.condTypicalSubspaceProj (fun i => E (ρ (w M i))) s ε) * + (State.piTensor fun i => E (ρ (w M i))).op))) + + ∑ M' ∈ Finset.univ.erase M, RCLike.re + ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (w M i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε))))))) + = 3 * ((∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - P) * (State.piTensor fun i => E (ρ (w M i))).op)))) + + 2 * ((∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑((1 - State.condTypicalSubspaceProj (fun i => E (ρ (w M i))) s ε) * + (State.piTensor fun i => E (ρ (w M i))).op)))) + + ∑ M' ∈ Finset.univ.erase M, (∏ M'' : Fin K, ∏ i, p (w M'' i)) * RCLike.re + ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (w M i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε)))))) := by + intro w + rw [mul_add, mul_add, Finset.mul_sum]; ring + rw [Finset.sum_congr rfl fun w _ => step w, Finset.sum_add_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.mul_sum, Finset.sum_comm, hT1 M] + -- The confusion block: each of the `K − 1` distinct messages contributes `≤ exp(…)`. + have hconf : ∑ M' ∈ Finset.univ.erase M, ∑ w : Fin K → Fin n → α, + (∏ M'' : Fin K, ∏ i, p (w M'' i)) * + RCLike.re ((LinearMap.trace ℂ (QSystem.piTensor fun _ : Fin n => S).space) + (↑(P.comp ((State.piTensor fun i => E (ρ (w M i))).op.comp + (P.comp (State.condTypicalSubspaceProj (fun i => E (ρ (w M' i))) s ε)))))) + ≤ ((K : ℝ) - 1) * Real.exp (-(n : ℝ) * (σbar.vonNeumannEntropy - s - 2 * ε)) := by + refine le_trans (Finset.sum_le_sum fun M' hM' => hT3 M M' (Finset.ne_of_mem_erase hM').symm) ?_ + rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ M), Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, Nat.cast_sub (Nat.one_le_iff_ne_zero.mpr (NeZero.ne K)), + Nat.cast_one] + linarith [hT2 M, hconf] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RandomUnitaryChannel.lean b/LeanPool/AxQM/Postulates/API/RandomUnitaryChannel.lean new file mode 100644 index 0000000000..ea54d30ac4 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RandomUnitaryChannel.lean @@ -0,0 +1,335 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.API.MaximallyMixed +public import LeanPool.AxQM.Postulates.API.QuantumChannel + +/-! +# AxQM.Postulates.API — random-unitary (mixed-unitary) channels + +A **random-unitary channel** (also *mixed-unitary channel*) is a quantum operation of the form +`E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` where the `Uₖ` are unitaries and `{pₖ}` is a probability distribution: +the channel applies a *randomly chosen* unitary `Uₖ` with probability `pₖ`. It is the running +object of **Nielsen & Chuang, Problem 8.3** (*Random unitary channels*): it is "tempting to +believe that all unital channels — those with `E(I) = I` — are of this form", and the problem is to +show this holds for single qubits but *fails* for larger systems. + +This file provides the **framework** and the easy half of the Problem 8.3 story: + +* `AxQM.RandomUnitaryChannel` — the bundled data of a random-unitary channel of `S`: + a finite family of unitary `Evolution`s `Uₖ` together with a probability distribution `pₖ`. +* `AxQM.RandomUnitaryChannel.apply` — its action `E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` on states, + a genuine `State S` (a convex combination of the states `Uₖ ρ Uₖ†`). +* `AxQM.IsUnital` — a state-map is **unital** when it fixes the maximally mixed state + `I/d` (equivalently `E(I) = I`, since a channel is linear). +* `AxQM.IsRandomUnitary` — a state-map is **random-unitary** when it is realised by some + `RandomUnitaryChannel`. This is the predicate in which Problem 8.3's two claims are phrased. +* `AxQM.RandomUnitaryChannel.isUnital` / `AxQM.isUnital_of_isRandomUnitary` — + **the easy direction of Problem 8.3:** every random-unitary channel is unital (the concrete and + the `IsRandomUnitary`-predicate forms). This is the `⇐` half of the "tempting belief"; the + problem's actual content is the *converse* — true on a qubit, false in dimension `≥ 3`. + +The lemma `AxQM.Evolution.evolve_maximallyMixedState` — every unitary conjugation fixes +`I/d` (`U (I/d) U† = I/d`), the atomic reason a random-unitary channel is unital — is in +`AxQM/Postulates/API/MaximallyMixed.lean`, a general `Evolution` fact independent of the channel +construction. + +## Scope of this file vs. the full problem + +Problem 8.3's two claims — (i) *every unital qubit channel is random-unitary* and (ii) *there +is a unital channel in dimension `≥ 3` that is not random-unitary* — are **not** proved here. +(i)'s `∀`-form is not even statable without a general completely-positive **channel** object and +the Bloch affine-map representation of a unital qubit channel; (ii)'s non-membership proof requires +convex **extreme-point** / Choi-matrix analysis (the Landau–Streater argument). Neither is +formalised here. This file proves the easy direction: every random-unitary channel is unital. + +The statement of Problem 8.3 is in [upstream `AxQM/NC/Ch8/Problem8_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Problem8_3.lean). The helper +`AxQM.isDensityOp_sum_prob_smul` (a probability-weighted sum of density operators is a +density operator — the `n`-ary companion of the binary +`ContinuousLinearMap.IsDensityOp.convex_combination`) is stated fully generally (over any complex +inner-product space `E`, not pinned to `S.space`). + +## Design notes + +* **Why `State → State` and a bundled structure.** `apply` produces a genuine `State`, so + **trace preservation is automatic** — no separate theorem is needed. Bundling the family + `{pₖ, Uₖ}` (mirroring `Ensemble`) makes a channel a first-class value one can quantify over, + which is what Problem 8.3's "∃ a unital channel that is not random-unitary" needs. +* **Why `IsUnital` via `I/d`.** N&C states unitality as `E(I) = I` for the (unnormalised) identity + operator; for a linear channel this is equivalent to fixing the maximally mixed state `I/d`, which + *is* a `State`. Phrasing unitality as `E(I/d) = I/d` therefore states it over + `maximallyMixedState` instead of a bare identity operator. The equivalence + `E(I) = I ↔ E(I/d) = I/d` is the linear rescaling by `1/d`. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A probability-weighted sum of density operators is a density operator.** The `n`-ary +convex-combination closure of the density operators (the finite companion of the binary +`ContinuousLinearMap.IsDensityOp.convex_combination`): if each `ρ i` is a density operator, `p` is a +probability distribution (`0 ≤ p i`, `∑ p i = 1`), then `∑ᵢ pᵢ ρᵢ` is again a density operator. +Positivity is closure of positive operators under nonnegative scaling and finite sums; the trace is +`∑ᵢ pᵢ · tr ρᵢ = ∑ᵢ pᵢ · 1 = 1`. Stated for an arbitrary complex inner-product space `E` (the proof +uses nothing specific to `S.space`), so it applies at `E := S.space`. -/ +theorem isDensityOp_sum_prob_smul {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + {ι : Type*} [Fintype ι] + {ρ : ι → E →L[ℂ] E} (hρ : ∀ i, (ρ i).IsDensityOp) + {p : ι → ℝ} (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + (∑ i, (p i : ℂ) • ρ i).IsDensityOp := by + rw [ContinuousLinearMap.isDensityOp_iff] + refine ⟨?_, ?_⟩ + · -- positivity: a finite sum of nonnegative multiples of positive operators is positive + exact ContinuousLinearMap.isPositive_sum Finset.univ + fun i _ => (hρ i).isPositive.smul_of_nonneg (by exact_mod_cast hp i) + · -- trace: `tr (∑ᵢ pᵢ ρᵢ) = ∑ᵢ pᵢ · tr ρᵢ = ∑ᵢ pᵢ = 1` + have h : (LinearMap.trace ℂ E) ↑(∑ i, (p i : ℂ) • ρ i) = ∑ i, (p i : ℂ) := by + rw [ContinuousLinearMap.toLinearMap_sum, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.toLinearMap_smul, map_smul, (hρ i).trace_eq_one, smul_eq_mul, mul_one] + rw [h, ← Complex.ofReal_sum, hsum, Complex.ofReal_one] + +/-- **A random-unitary (mixed-unitary) channel** of the system `S` (Nielsen & Chuang, Problem 8.3): +a finite family of unitary `Evolution`s `unitary k` together with a probability distribution +`prob k` (nonnegative, summing to one). Its action `∑ₖ pₖ Uₖ ρ Uₖ†` is `RandomUnitaryChannel.apply`. +The data mirrors `Ensemble` (a probability distribution over a finite family), here of unitaries +rather than pure states. -/ +structure RandomUnitaryChannel (S : QSystem) where + /-- The number of unitaries in the mixture. -/ + card : ℕ + /-- The probability weights `pₖ`. -/ + prob : Fin card → ℝ + /-- The unitary evolutions `Uₖ` that are mixed over. -/ + unitary : Fin card → Evolution S + /-- Each probability is nonnegative. -/ + prob_nonneg : ∀ i, 0 ≤ prob i + /-- The probabilities sum to one. -/ + sum_prob : ∑ i, prob i = 1 + +namespace RandomUnitaryChannel + +/-- **The action of a random-unitary channel** on a state: `E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†`, the +probability-weighted mixture of the conjugated states `Uₖ ρ Uₖ† = (Uₖ).evolve ρ`. It is a genuine +`State S` — a convex combination of states — by `isDensityOp_sum_prob_smul`, so the channel is +automatically trace preserving. -/ +def apply (C : RandomUnitaryChannel S) (ρ : State S) : State S where + op := ∑ i, (C.prob i : ℂ) • ((C.unitary i).evolve ρ).op + isDensity := + isDensityOp_sum_prob_smul (fun i => ((C.unitary i).evolve ρ).isDensity) C.prob_nonneg C.sum_prob + +/-- The operator of `C.apply ρ` is the operator sum `∑ₖ pₖ Uₖ ρ Uₖ†`. -/ +@[simp] +theorem apply_op (C : RandomUnitaryChannel S) (ρ : State S) : + (C.apply ρ).op = ∑ i, (C.prob i : ℂ) • ((C.unitary i).evolve ρ).op := rfl + +/-- **The sesquilinear form of a random-unitary channel is the probability-weighted mixture of the +per-unitary forms:** `⟨φ, C(ρ) φ⟩ = ∑ₖ pₖ ⟨φ, Uₖ ρ Uₖ† φ⟩`. Immediate additivity / `ℂ`-linearity of +`⟨φ, · φ⟩` over the operator sum `apply_op`. Pairing this identity against a specific vector `φ` is +the entry point for reasoning about a random-unitary channel via matrix elements — e.g. the +pure-state non-membership argument for Nielsen & Chuang, Problem 8.3 +(`Postulates/API/WernerHolevoRandomUnitary`). -/ +theorem inner_apply_op_eq_sum (C : RandomUnitaryChannel S) (ρ : State S) (φ : S.space) : + (inner ℂ φ ((C.apply ρ).op φ) : ℂ) + = ∑ k, (C.prob k : ℂ) * (inner ℂ φ (((C.unitary k).evolve ρ).op φ) : ℂ) := by + rw [RandomUnitaryChannel.apply_op, sum_apply, inner_sum] + refine Finset.sum_congr rfl (fun k _ => ?_) + rw [smul_apply, inner_smul_right] + +end RandomUnitaryChannel + +/-- **A state-map (channel) `f` is unital** if it fixes the maximally mixed state `I/d`: +`f (I/d) = I/d`. For a **linear** channel this is Nielsen & Chuang's `E(I) = I` (the two differ by +the linear rescaling `I = d · (I/d)`); phrasing it over `maximallyMixedState` states the property +for states. This is the fixed-point form of the "unital channels" of Problem 8.3. + +Note the predicate is stated on an arbitrary `f : State S → State S` — it captures only the fixed +point, not linearity/complete-positivity. That is exactly what the easy direction here needs (it is +applied only to the *linear* `RandomUnitaryChannel.apply`). A formalisation of the *converse* claim +of Problem 8.3 must have its hypothesis range over a genuine (linear, completely-positive, +trace-preserving) **channel** — a bundled object the library does not yet have (see +[upstream `Problem8_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Problem8_3.lean)) — not over an arbitrary `I/d`-fixing state-map, or the ∀-statement would not be +N&C's claim. -/ +def IsUnital [Nontrivial S.space] (f : State S → State S) : Prop := + f (maximallyMixedState S) = maximallyMixedState S + +/-- **A state-map (channel) `f` is random-unitary (mixed-unitary)** if it agrees with the action of +some `RandomUnitaryChannel`, i.e. `f(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` for a probability distribution `pₖ` and +unitaries `Uₖ`. This is the predicate in which **both** claims of Nielsen & Chuang, Problem 8.3 are +phrased: for a *unital channel* `f`, is `f` random-unitary? — true for a qubit, false in dimension +`≥ 3`. (`Evolution.evolve_maximallyMixedState` — every unitary conjugation fixes `I/d` — is in +`AxQM/Postulates/API/MaximallyMixed.lean`.) -/ +def IsRandomUnitary (f : State S → State S) : Prop := + ∃ C : RandomUnitaryChannel S, ∀ ρ, C.apply ρ = f ρ + +/-- **Unital state-maps are closed under composition.** If `f` and `g` each fix the maximally mixed +state `I/d` (`IsUnital`), so does their composite `f ∘ g`, `fun ρ ↦ f (g ρ)`: `f (g (I/d)) = f (I/d) += I/d`. The first argument `f` is the *outer* map, matching the convention of `isRandomUnitary_comp` +(and `isChannel_comp`). Paired with `isChannel_comp` (channels are closed under composition), this +lets the qubit converse of Nielsen & Chuang, Problem 8.3 conjugate a *unital channel* by unitary +rotations and keep both properties — the diagonalisation step of the converse. -/ +theorem isUnital_comp [Nontrivial S.space] {f g : State S → State S} + (hf : IsUnital f) (hg : IsUnital g) : IsUnital (fun ρ => f (g ρ)) := by + change f (g (maximallyMixedState S)) = maximallyMixedState S + rw [hg, hf] + +/-- **The easy direction of Nielsen & Chuang, Problem 8.3:** every random-unitary channel +`E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` is **unital**, `E(I/d) = I/d`. Each unitary conjugation fixes `I/d` +(`Evolution.evolve_maximallyMixedState`), so the channel maps `I/d` to `∑ₖ pₖ · (I/d) = I/d` (the +weights sum to one). The problem's real content is the *converse* — that unitality forces the +random-unitary form on a qubit but not in dimension `≥ 3` — which this framework supports. -/ +theorem RandomUnitaryChannel.isUnital [Nontrivial S.space] (C : RandomUnitaryChannel S) : + IsUnital C.apply := by + apply State.ext + simp only [RandomUnitaryChannel.apply_op, Evolution.evolve_maximallyMixedState, + ← Finset.sum_smul, ← Complex.ofReal_sum, C.sum_prob, Complex.ofReal_one, one_smul] + +/-- **The easy direction of Nielsen & Chuang, Problem 8.3, over `IsRandomUnitary`:** every +random-unitary state-map is unital. This is the `⇐` half of the "tempting belief" — the direction +that N&C presents as *background*, whose *converse* is the problem. Immediate from +`RandomUnitaryChannel.isUnital` and the witnessing channel. -/ +theorem isUnital_of_isRandomUnitary [Nontrivial S.space] {f : State S → State S} + (hf : IsRandomUnitary f) : IsUnital f := by + obtain ⟨C, hC⟩ := hf + exact funext hC ▸ C.isUnital + +/-- **A random-unitary channel is a genuine CPTP quantum channel.** The operator-sum +`E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` is realised by the Kraus operators `Eₖ = √pₖ · Uₖ`, whose completeness +relation is `∑ₖ Eₖ† Eₖ = ∑ₖ pₖ Uₖ† Uₖ = (∑ₖ pₖ) · I = I` (each `Uₖ` unitary, the weights sum to +one). By `isChannel_of_kraus` this exhibits `E` as a completely-positive trace-preserving map: +random-unitary channels are honest channels, so the framework's easy direction strengthens from +"random-unitary ⟹ unital" (`RandomUnitaryChannel.isUnital`) to "random-unitary ⟹ *unital +channel*". -/ +theorem RandomUnitaryChannel.isChannel (C : RandomUnitaryChannel S) : IsChannel C.apply := by + -- the adjoint of a *real*-scalar multiple pulls the scalar out unchanged (it is self-conjugate) + have hadj : ∀ (c : ℝ) (A : S.space →L[ℂ] S.space), + ContinuousLinearMap.adjoint ((c : ℂ) • A) = (c : ℂ) • ContinuousLinearMap.adjoint A := by + intro c A + simp only [← ContinuousLinearMap.star_eq_adjoint, star_smul] + norm_num + refine isChannel_of_kraus (fun k => (Real.sqrt (C.prob k) : ℂ) • (C.unitary k).op) ?_ ?_ + · -- completeness relation `∑ₖ Eₖ† Eₖ = ∑ₖ pₖ Uₖ† Uₖ = (∑ₖ pₖ) • 1 = 1` + have key : ∀ k, (ContinuousLinearMap.adjoint + ((Real.sqrt (C.prob k) : ℂ) • (C.unitary k).op)).comp + ((Real.sqrt (C.prob k) : ℂ) • (C.unitary k).op) = (C.prob k : ℂ) • 1 := by + intro k + rw [hadj, ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, smul_smul, + (C.unitary k).adjoint_comp_self, ← Complex.ofReal_mul, Real.mul_self_sqrt (C.prob_nonneg k)] + rw [Finset.sum_congr rfl fun k _ => key k, ← Finset.sum_smul, ← Complex.ofReal_sum, + C.sum_prob, Complex.ofReal_one, one_smul] + · -- the operator sum reproduces `E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` + intro ρ + rw [ContinuousLinearMap.krausSumₗ_apply, RandomUnitaryChannel.apply_op] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [Evolution.evolve_op, hadj] + simp only [ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, smul_smul] + rw [← Complex.ofReal_mul, Real.mul_self_sqrt (C.prob_nonneg k)] + +/-- **A random-unitary state-map is a genuine CPTP quantum channel** (the +`IsRandomUnitary`-predicate form of `RandomUnitaryChannel.isChannel`). Together with +`isUnital_of_isRandomUnitary` this says a +random-unitary map is a *unital channel* — sharpening the easy half of Nielsen & Chuang, Problem 8.3 +to the very hypothesis (`IsChannel`) under which the problem's converse is posed. -/ +theorem isChannel_of_isRandomUnitary {f : State S → State S} (hf : IsRandomUnitary f) : + IsChannel f := by + obtain ⟨C, hC⟩ := hf + exact funext hC ▸ C.isChannel + +/-! ### Closure of the random-unitary channels + +The random-unitary channels form a *submonoid* of the state-maps: they contain every single unitary +conjugation and are closed under composition. This is the algebraic glue for the **qubit converse** +of Problem 8.3: a unital qubit channel factors on the Bloch sphere as `conj U₁ ∘ Pauli ∘ conj U₂` +(pre/post rotations `O₁, O₂` from the singular-value decomposition of its Bloch matrix, each a +unitary conjugation by `SU(2) → SO(3)`), so once the diagonal `Pauli` part is known random-unitary +(`pauliChannel_isRandomUnitary`), these closure facts assemble the general case. -/ + +/-- **A single unitary conjugation is a random-unitary channel.** The one-point mixture +`E(ρ) = 1 · U ρ U†` (all the weight on the single unitary `U`) realises the conjugation `U.evolve`, +so `U.evolve` is `IsRandomUnitary`. This is the base case of the random-unitary closure used in the +qubit converse of Nielsen & Chuang, Problem 8.3. -/ +theorem isRandomUnitary_evolve (U : Evolution S) : IsRandomUnitary U.evolve := by + refine ⟨⟨1, fun _ => 1, fun _ => U, fun _ => zero_le_one, by simp⟩, fun ρ => ?_⟩ + apply State.ext + simp [RandomUnitaryChannel.apply_op] + +/-- **A unitary conjugation is a CPTP quantum channel.** The map `ρ ↦ U ρ U†` induced by a unitary +evolution `U` (`Evolution.evolve`) is a completely-positive trace-preserving quantum channel +(`IsChannel`): it is the one-point random-unitary channel (`isRandomUnitary_evolve`), and every +random-unitary channel is a channel (`isChannel_of_isRandomUnitary`). This is the fact that makes +the pre- and post-composition unitaries `U`, `V` of a *channel equivalence* `E₂ = U ∘ E₁ ∘ V` +(Nielsen & Chuang, Problem 10.1) themselves channels, so `isChannel_comp` transfers the CPTP +property from `E₁` to the equivalent `E₂`. -/ +theorem isChannel_evolve (U : Evolution S) : IsChannel U.evolve := + isChannel_of_isRandomUnitary (isRandomUnitary_evolve U) + +/-- **The composite of two random-unitary channels.** Given random-unitary channels `C` (unitaries +`Uᵢ`, weights `pᵢ`) and `D` (unitaries `Vⱼ`, weights `qⱼ`), the composite mixes the +`C.card * D.card` composite unitaries `Uᵢ ∘ Vⱼ` (`Evolution.comp`) with the product distribution +`pᵢ qⱼ`. Its action is exactly the functional composition `C.apply ∘ D.apply` +(`RandomUnitaryChannel.apply_comp`), so random-unitary channels are closed under composition. The +index set `Fin (C.card * D.card)` is identified with the product `Fin C.card × Fin D.card` via +`finProdFinEquiv`. -/ +def RandomUnitaryChannel.comp (C D : RandomUnitaryChannel S) : RandomUnitaryChannel S where + card := C.card * D.card + prob k := C.prob (finProdFinEquiv.symm k).1 * D.prob (finProdFinEquiv.symm k).2 + unitary k := (C.unitary (finProdFinEquiv.symm k).1).comp (D.unitary (finProdFinEquiv.symm k).2) + prob_nonneg k := mul_nonneg (C.prob_nonneg _) (D.prob_nonneg _) + sum_prob := by + rw [Fintype.sum_equiv finProdFinEquiv.symm + (fun k => C.prob (finProdFinEquiv.symm k).1 * D.prob (finProdFinEquiv.symm k).2) + (fun ij : Fin C.card × Fin D.card => C.prob ij.1 * D.prob ij.2) fun _ => rfl, + Fintype.sum_prod_type] + rw [← Finset.sum_mul_sum, C.sum_prob, D.sum_prob, mul_one] + +/-- **The composite channel acts by functional composition:** `(C.comp D).apply ρ = C.apply +(D.apply ρ)`. Averaging the `Uᵢ ∘ Vⱼ`-conjugations against the product distribution `pᵢ qⱼ` equals +first averaging the `Vⱼ`-conjugations (that is `D.apply`) and then the `Uᵢ`-conjugations (that is +`C.apply`), because each `Uᵢ`-conjugation is linear in the state operator and so commutes past the +`D`-mixture. -/ +theorem RandomUnitaryChannel.apply_comp (C D : RandomUnitaryChannel S) (ρ : State S) : + (C.comp D).apply ρ = C.apply (D.apply ρ) := by + apply State.ext + -- Reindex the composite sum over the product `Fin C.card × Fin D.card` (defeq to + -- `Fin (C.card * D.card)` via `finProdFinEquiv`); `exact` matches up to definitional unfolding of + -- `RandomUnitaryChannel.comp`, so no fragile `rw` on `(C.comp D).card` is needed. + have hLHS : ((C.comp D).apply ρ).op + = ∑ ij : Fin C.card × Fin D.card, + ((C.prob ij.1 * D.prob ij.2 : ℝ) : ℂ) • + (((C.unitary ij.1).comp (D.unitary ij.2)).evolve ρ).op := by + rw [RandomUnitaryChannel.apply_op] + exact Fintype.sum_equiv finProdFinEquiv.symm _ _ fun _ => rfl + rw [hLHS, Fintype.sum_prod_type, RandomUnitaryChannel.apply_op] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Evolution.evolve_op (C.unitary i) (D.apply ρ), RandomUnitaryChannel.apply_op, + ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.comp_finsetSum, Finset.smul_sum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [Evolution.evolve_comp, ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, + ← Evolution.evolve_op, smul_smul, ← Complex.ofReal_mul] + +/-- **`IsRandomUnitary` is closed under composition:** if `f` and `g` are random-unitary state-maps, +so is `ρ ↦ f (g ρ)`, witnessed by the composite channel `RandomUnitaryChannel.comp`. Together with +`isRandomUnitary_evolve` this is the closure used to reduce the qubit converse of Nielsen & Chuang, +Problem 8.3 (`conj U₁ ∘ Pauli ∘ conj U₂`) to its diagonal (Pauli) case. -/ +theorem isRandomUnitary_comp {f g : State S → State S} + (hf : IsRandomUnitary f) (hg : IsRandomUnitary g) : + IsRandomUnitary fun ρ => f (g ρ) := by + obtain ⟨C, hC⟩ := hf + obtain ⟨D, hD⟩ := hg + exact ⟨C.comp D, fun ρ => by simp only [RandomUnitaryChannel.apply_comp, hC, hD]⟩ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RandomUnitaryEntropy.lean b/LeanPool/AxQM/Postulates/API/RandomUnitaryEntropy.lean new file mode 100644 index 0000000000..63e3ac4f98 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RandomUnitaryEntropy.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.EntropyConcavity +public import LeanPool.AxQM.Postulates.API.EntropyEvolution +public import LeanPool.AxQM.Postulates.API.RandomUnitaryChannel + +/-! +# AxQM.Postulates.API — random-unitary channels never decrease entropy + +A **random-unitary (mixed-unitary) channel** `E(ρ) = ∑ₖ pₖ Uₖ ρ Uₖ†` never *decreases* the von +Neumann entropy of its input: + +`S(ρ) ≤ S(E(ρ))`. + +This is the abstract content of the *alternate proof* of Nielsen & Chuang, Theorem 11.9 +(projective measurements never decrease entropy) requested by **Exercise 11.20**: once the pinching +`ρ ↦ P ρ P + Q ρ Q` is exhibited as a random-unitary channel (see +[upstream `AxQM/NC/Ch11/Exercise11_20.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Exercise11_20.lean)), this lemma delivers the entropy bound with no further +work. The proof is exactly N&C's concavity argument: + +`S(E(ρ)) = S(∑ₖ pₖ Uₖ ρ Uₖ†) ≥ ∑ₖ pₖ S(Uₖ ρ Uₖ†) = ∑ₖ pₖ S(ρ) = S(ρ)`, + +the inequality being *concavity* of the entropy +(`State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`, the faithfulness-free form — the +mixture `E(ρ)` is generally rank-deficient), and the two equalities +being *unitary invariance* of the entropy (`State.vonNeumannEntropy_evolve`, `S(UρU†) = S(ρ)`) and +`∑ₖ pₖ = 1`. + +## Main results + +* `AxQM.RandomUnitaryChannel.vonNeumannEntropy_apply_ge` — for a concrete + `RandomUnitaryChannel` `C`, `S(ρ) ≤ S(C.apply ρ)`. +* `AxQM.vonNeumannEntropy_le_of_isRandomUnitary` — the `IsRandomUnitary`-predicate form: + any random-unitary state-map `f` satisfies `S(ρ) ≤ S(f ρ)`. + +The proof uses the faithfulness-free concavity of the entropy from +`AxQM/Postulates/API/EntropyConcavity.lean`. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **A probabilistic mixture of unitary conjugates of `ρ` never decreases the entropy:** +`S(ρ) ≤ S(∑ⱼ pⱼ Uⱼ ρ Uⱼ†)`, over an arbitrary finite index type. Faithfulness-free concavity +(`sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`) plus unitary invariance +(`vonNeumannEntropy_evolve`, `S(Uⱼ ρ Uⱼ†) = S(ρ)`) collapse the average component entropy to +`(∑ⱼ pⱼ) S(ρ) = S(ρ)`. Shared core of `RandomUnitaryChannel.vonNeumannEntropy_apply_ge` and the +majorization monotone `State.Majorize.vonNeumannEntropy_le`. -/ +theorem State.vonNeumannEntropy_le_mix_evolve {ι : Type*} [Fintype ι] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (U : ι → Evolution S) (ρ : State S) : + ρ.vonNeumannEntropy ≤ (State.mix p hp hsum fun j => (U j).evolve ρ).vonNeumannEntropy := by + have hconc := State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix' p hp hsum + fun j => (U j).evolve ρ + have hev : ∀ j, ((U j).evolve ρ).vonNeumannEntropy = ρ.vonNeumannEntropy := + fun j => State.vonNeumannEntropy_evolve (U j) ρ + simp only [hev] at hconc + rwa [← Finset.sum_mul, hsum, one_mul] at hconc + +/-- **A random-unitary channel never decreases the von Neumann entropy:** `S(ρ) ≤ S(C.apply ρ)`. + +The channel output `C.apply ρ = ∑ₖ pₖ Uₖ ρ Uₖ†` is the probabilistic mixture of the conjugated +states `Uₖ ρ Uₖ† = (C.unitary k).evolve ρ`, so by concavity of the entropy (the faithfulness-free +form `State.sum_mul_vonNeumannEntropy_le_vonNeumannEntropy_mix'`, since the mixture is generally +rank-deficient) `S(C.apply ρ) ≥ ∑ₖ pₖ S(Uₖ ρ Uₖ†)`. Unitary conjugation preserves entropy +(`State.vonNeumannEntropy_evolve`, `S(Uₖ ρ Uₖ†) = S(ρ)`), so the right-hand side is `(∑ₖ pₖ) S(ρ) = +S(ρ)`. -/ +theorem RandomUnitaryChannel.vonNeumannEntropy_apply_ge (C : RandomUnitaryChannel S) (ρ : State S) : + ρ.vonNeumannEntropy ≤ (C.apply ρ).vonNeumannEntropy := by + rw [C.apply_eq_mix ρ] + exact State.vonNeumannEntropy_le_mix_evolve C.prob C.prob_nonneg C.sum_prob C.unitary ρ + +/-- **A random-unitary state-map never decreases the von Neumann entropy** (the `IsRandomUnitary` +form of `RandomUnitaryChannel.vonNeumannEntropy_apply_ge`): if `f` is realised by some +`RandomUnitaryChannel` (`IsRandomUnitary f`) then `S(ρ) ≤ S(f ρ)` for every `ρ`. This is the +reusable "probabilistic unitary mixtures never decrease entropy" lemma behind the concavity-based +alternate +proof of Nielsen & Chuang Theorem 11.9 (Exercise 11.20). -/ +theorem vonNeumannEntropy_le_of_isRandomUnitary {f : State S → State S} + (hf : IsRandomUnitary f) (ρ : State S) : + ρ.vonNeumannEntropy ≤ (f ρ).vonNeumannEntropy := by + obtain ⟨C, hC⟩ := hf + rw [← hC ρ] + exact C.vonNeumannEntropy_apply_ge ρ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReducedEigenEnsemble.lean b/LeanPool/AxQM/Postulates/API/ReducedEigenEnsemble.lean new file mode 100644 index 0000000000..a0bba3eabf --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReducedEigenEnsemble.lean @@ -0,0 +1,186 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Ensemble +public import LeanPool.AxQM.Postulates.API.Support +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum + +/-! +# AxQM — the reduced eigenensemble of a density operator + +Nielsen & Chuang, Exercise 2.73, call an ensemble `{pᵢ, |ψᵢ⟩}` **minimal** for `ρ` when it has +exactly `rank ρ` elements. The eigenensemble `Ensemble.ofState ρ` (spectral decomposition) has +`finrank ℂ S.space` elements — one per basis vector — which is *not* minimal once `ρ` has a kernel +(zero eigenvalues). This file trims it to its **reduced eigenensemble**: the spectral decomposition +restricted to the non-zero eigenvalues, +`ρ = ∑ⱼ μⱼ |gⱼ⟩⟨gⱼ|` (sum over `μⱼ ≠ 0`), +a genuine minimal ensemble (size `rank ρ`, strictly positive weights, orthonormal states, generating +`ρ`). It is the canonical witness that a minimal ensemble exists, and the fixed reference ensemble +against which any *other* minimal ensemble is compared (via Theorem 2.6) in the rest of Exercise +2.73 — both the existence of a minimal ensemble through a prescribed support vector and the +probability formula `pᵢ = 1/⟨ψᵢ|ρ⁻¹|ψᵢ⟩`. + +The construction reindexes the non-zero-eigenvalue indices onto `Fin (rank ρ)`. The count of +non-zero eigenvalues is exactly the rank: for the self-adjoint `ρ`, the zero-eigenspace is the +kernel (`Module.End.eigenspace_zero`), whose dimension counts the zero eigenvalues +(`card_filter_eigenvalues_eq`), and rank-nullity turns "space minus kernel" into +"non-zero eigenvalue count" (`rank_eq_card_eigenvalues_ne_zero`). The resulting bijection +`eigenIndexEquiv : Fin (rank ρ) ≃ {i // μᵢ ≠ 0}` selects the non-zero +spectrum. + +## Main definitions + +* `AxQM.State.eigenIndexEquiv` — a bijection `Fin (rank ρ) ≃ {i // μᵢ ≠ 0}` selecting the + non-zero-eigenvalue indices. +* `AxQM.State.reducedEigenEnsemble` — the reduced eigenensemble `{μⱼ, |gⱼ⟩}` (`μⱼ ≠ 0`). + +## Main results + +* `State.rank_eq_card_eigenvalues_ne_zero` — the rank is the number of non-zero eigenvalues. +* `State.reducedEigenEnsemble_card` — the reduced eigenensemble has `rank ρ` elements + (definitional). +* `State.reducedEigenEnsemble_prob_pos` — every weight `μⱼ` is strictly positive. +* `State.reducedEigenEnsemble_states_mem_support` — every state `|gⱼ⟩` lies in the support of `ρ`. +* `State.reducedEigenEnsemble_toState` — the reduced eigenensemble generates `ρ`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace State + +/-- **The rank of `ρ` is the number of its non-zero eigenvalues.** For the self-adjoint density +operator `ρ`, the zero-eigenspace is the kernel (`Module.End.eigenspace_zero`), so the number of +*zero* eigenvalues is `finrank (ker ρ)` (`card_filter_eigenvalues_eq` at `μ = 0`); rank-nullity +(`finrank (range ρ) + finrank (ker ρ) = finrank S.space`) then equates `rank ρ = finrank (range ρ)` +with the number of *non-zero* eigenvalues. The cardinality identity underlying the reindexing +`eigenIndexEquiv` used to build the reduced eigenensemble. -/ +theorem rank_eq_card_eigenvalues_ne_zero (ρ : State S) : + ρ.rank = + (Finset.univ.filter + (fun i : Fin (Module.finrank ℂ S.space) => + ρ.isDensity.isSymmetric.eigenvalues rfl i ≠ 0)).card := by + classical + -- rank-nullity for `ρ.op` + have hrn := LinearMap.finrank_range_add_finrank_ker (ρ.op : S.space →ₗ[ℂ] S.space) + -- the number of zero eigenvalues is `finrank (ker ρ)`: the zero-eigenspace is the kernel + have hzero : (Finset.univ.filter + (fun i => ρ.isDensity.isSymmetric.eigenvalues rfl i = 0)).card + = Module.finrank ℂ (LinearMap.ker (ρ.op : S.space →ₗ[ℂ] S.space)) := by + rw [← Module.End.eigenspace_zero, ← ρ.isDensity.isSymmetric.card_filter_eigenvalues_eq rfl 0] + exact congrArg Finset.card (Finset.filter_congr fun i _ => by rw [RCLike.ofReal_eq_zero]) + -- split `univ` into zero / non-zero eigenvalue indices + have hsplit : (Finset.univ.filter + (fun i => ρ.isDensity.isSymmetric.eigenvalues rfl i ≠ 0)).card + + (Finset.univ.filter (fun i => ρ.isDensity.isSymmetric.eigenvalues rfl i = 0)).card + = Module.finrank ℂ S.space := by + simp only [ne_eq] + rw [add_comm, Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset _)) + (fun i => ρ.isDensity.isSymmetric.eigenvalues rfl i = 0)] + simp + -- `rank = finrank range`, so `rank + #zero = finrank range + finrank ker = finrank space` + have hrank : ρ.rank = Module.finrank ℂ (LinearMap.range (ρ.op : S.space →ₗ[ℂ] S.space)) := rfl + omega + +/-- **The bijection selecting the non-zero-eigenvalue indices.** A chosen equivalence +`Fin (rank ρ) ≃ {i // μᵢ ≠ 0}` between `Fin (rank ρ)` and the indices of the non-zero eigenvalues, +available because the two are equinumerous (`rank_eq_card_eigenvalues_ne_zero`). Used to reindex the +non-zero spectrum onto `Fin (rank ρ)` when building the reduced eigenensemble. -/ +def eigenIndexEquiv (ρ : State S) : + Fin ρ.rank ≃ + {i : Fin (Module.finrank ℂ S.space) // ρ.isDensity.isSymmetric.eigenvalues rfl i ≠ 0} := + (Fintype.equivFinOfCardEq (by + classical + rw [Fintype.card_subtype] + exact (rank_eq_card_eigenvalues_ne_zero ρ).symm)).symm + +/-- **The eigenvalue selected by `eigenIndexEquiv` is non-zero.** By construction the reindexing +lands on non-zero-eigenvalue indices. -/ +theorem eigenvalues_eigenIndexEquiv_ne_zero (ρ : State S) (i : Fin ρ.rank) : + ρ.isDensity.isSymmetric.eigenvalues rfl (ρ.eigenIndexEquiv i).val ≠ 0 := + (ρ.eigenIndexEquiv i).2 + +/-- **Reindexing a spectral sum onto `Fin (rank ρ)`.** If `f` vanishes at every zero-eigenvalue +index, then summing `f` over the non-zero-eigenvalue indices (reindexed by `eigenIndexEquiv`) equals +summing `f` over the whole spectrum — the zero-eigenvalue terms contribute nothing. The shared +mechanism behind `reducedEigenEnsemble`'s `sum_prob` (weights) and `reducedEigenEnsemble_toState` +(operator). -/ +theorem sum_eigenIndexEquiv {M : Type*} [AddCommMonoid M] (ρ : State S) + (f : Fin (Module.finrank ℂ S.space) → M) + (hf : ∀ i, ρ.isDensity.isSymmetric.eigenvalues rfl i = 0 → f i = 0) : + ∑ i, f (ρ.eigenIndexEquiv i).val = ∑ i, f i := by + classical + rw [Equiv.sum_comp ρ.eigenIndexEquiv (fun x => f x.val), + ← Finset.sum_subtype (Finset.univ.filter + (fun i => ρ.isDensity.isSymmetric.eigenvalues rfl i ≠ 0)) + (fun i => by simp) f] + exact Finset.sum_filter_of_ne fun x _ hfx h0 => hfx (hf x h0) + +/-- **The reduced eigenensemble of `ρ`** (Nielsen–Chuang Exercise 2.73): the spectral decomposition +of `ρ` restricted to its non-zero eigenvalues, `{μⱼ, |gⱼ⟩}` over `μⱼ ≠ 0`. Its size is `rank ρ` +(one element per non-zero eigenvalue, via `eigenIndexEquiv`); the weights are the non-zero +eigenvalues `μⱼ > 0` and the states the corresponding orthonormal eigenvectors `|gⱼ⟩`. A minimal +ensemble for `ρ` (`reducedEigenEnsemble_card` / `reducedEigenEnsemble_toState`), and the canonical +reference against which any other minimal ensemble is compared via Theorem 2.6. -/ +def reducedEigenEnsemble (ρ : State S) : Ensemble S where + card := ρ.rank + prob i := ρ.isDensity.isSymmetric.eigenvalues rfl (ρ.eigenIndexEquiv i).val + states i := + ⟨ρ.isDensity.isSymmetric.eigenvectorBasis rfl (ρ.eigenIndexEquiv i).val, + (ρ.isDensity.isSymmetric.eigenvectorBasis rfl).orthonormal.norm_eq_one _⟩ + prob_nonneg i := ρ.isDensity.eigenvalues_nonneg rfl _ + sum_prob := by + rw [ρ.sum_eigenIndexEquiv (ρ.isDensity.isSymmetric.eigenvalues rfl) fun i hi => hi] + exact ρ.isDensity.eigenvalues_sum_eq_one rfl + +/-- **The reduced eigenensemble has `rank ρ` elements** — it is minimal (definitional). -/ +@[simp] +theorem reducedEigenEnsemble_card (ρ : State S) : ρ.reducedEigenEnsemble.card = ρ.rank := rfl + +/-- **The weights of the reduced eigenensemble are strictly positive.** Each weight is a non-zero +eigenvalue of the (positive) density operator `ρ`, hence `> 0`. -/ +theorem reducedEigenEnsemble_prob_pos (ρ : State S) (i : Fin ρ.rank) : + 0 < ρ.reducedEigenEnsemble.prob i := + lt_of_le_of_ne (ρ.isDensity.eigenvalues_nonneg rfl _) + (Ne.symm (ρ.eigenvalues_eigenIndexEquiv_ne_zero i)) + +/-- **The states of the reduced eigenensemble lie in the support of `ρ`.** Each is an eigenvector of +`ρ` with non-zero eigenvalue, so it lies in the support (`eigenvectorBasis_mem_support_iff`). -/ +theorem reducedEigenEnsemble_states_mem_support (ρ : State S) (i : Fin ρ.rank) : + (ρ.reducedEigenEnsemble.states i).vec ∈ ρ.support := + (ρ.eigenvectorBasis_mem_support_iff _).mpr (ρ.eigenvalues_eigenIndexEquiv_ne_zero i) + +/-- **The reduced eigenensemble generates `ρ`** (Nielsen–Chuang Exercise 2.73): its density operator +`∑ⱼ μⱼ |gⱼ⟩⟨gⱼ|` (over `μⱼ ≠ 0`) is `ρ`. Reindexing the reduced sum back onto the full spectrum +(`sum_eigenIndexEquiv`, the zero-eigenvalue terms vanishing) turns it into the full spectral +decomposition, which is `ρ` via the eigenensemble (`Ensemble.ofState_toState`). Together with +`reducedEigenEnsemble_card` this exhibits the reduced eigenensemble as a *minimal* ensemble for +`ρ`. -/ +theorem reducedEigenEnsemble_toState (ρ : State S) : ρ.reducedEigenEnsemble.toState = ρ := by + refine State.ext ?_ + -- both the reduced and the full eigenensemble generate the same operator (the full spectral sum) + have key : ρ.reducedEigenEnsemble.toState.op = (Ensemble.ofState ρ).toState.op := by + rw [Ensemble.toState_op, Ensemble.toState_op] + simp only [reducedEigenEnsemble, Ensemble.ofState, PureState.toState_op] + exact ρ.sum_eigenIndexEquiv (fun k => (ρ.isDensity.isSymmetric.eigenvalues rfl k : ℂ) • + InnerProductSpace.rankOne ℂ (ρ.isDensity.isSymmetric.eigenvectorBasis rfl k) + (ρ.isDensity.isSymmetric.eigenvectorBasis rfl k)) fun k hk => by simp [hk] + rw [key, Ensemble.ofState_toState] +end State + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReducedStateComm.lean b/LeanPool/AxQM/Postulates/API/ReducedStateComm.lean new file mode 100644 index 0000000000..e6c86b0af9 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReducedStateComm.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceComm + +/-! +# AxQM — the two reduced states are related by the factor swap + +The two reduced states are the two faces of one partial trace: `State.reducedLeft` traces +out the *right* factor, `State.reducedRight` traces out the *left* factor. This file records the +relation between them, mediated by the transport swap `QSystem.Iso.comm`: + +`ρ.reducedRight = (ρ.congr (QSystem.Iso.comm S T)).reducedLeft` — the right marginal of `ρ` on +`S ⊗ T` (trace out `S`) is the *left* marginal of the swapped state on `T ⊗ S`. + +## Why this is useful + +`State.reducedLeft` has a full transport-naturality API (`State.reducedLeft_congr_tmul_refl`, +`State.reducedLeft_congr_assoc_symm`, `State.reducedLeft_reducedLeft_congr_assoc`, …, in +`AxQM/Postulates/API/ReducedStateTransport.lean` and +`AxQM/Postulates/API/SubadditivityReformulations.lean`), because it is defined through +`LinearMap.partialTraceRight`, for which `ToMathlib` has the naturality lemmas (invariance under a +unitary on the traced factor, associator commutation). Its mirror `State.reducedRight`, defined +through `LinearMap.partialTraceLeft`, has *no* such API. Rather than re-prove every naturality fact +on the left, this relation lets a `reducedRight` goal be rewritten to a `reducedLeft` goal on the +swapped state, where the existing API applies. The purification proof of weak monotonicity (N&C +Exercise 11.24) uses it to trace out the *first* factor of a nested composite (a `reducedRight`) +and read the result off through the `reducedLeft` lemmas. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The right marginal is the left marginal of the swapped state.** For a bipartite state `ρ` on +`S ⊗ T`, tracing out the left factor `S` (`State.reducedRight`) is the same as swapping the factors +(`ρ.congr (QSystem.Iso.comm S T)`, a state on `T ⊗ S`) and tracing out the (now right) factor `S` +(`State.reducedLeft`): + +`ρ.reducedRight = (ρ.congr (QSystem.Iso.comm S T)).reducedLeft`. + +At the level of operators this is the partial-trace identity +`LinearMap.partialTraceLeft_eq_partialTraceRight_comm`: `reducedRight` is a `partialTraceLeft`, +`reducedLeft` of the swapped state is a `partialTraceRight` of the `comm`-conjugated operator, and +the two agree. It transfers the `reducedLeft` transport-naturality API to +`reducedRight` (see the module docstring). -/ +theorem State.reducedRight_congr_comm (ρ : State (S ⊗ T)) : + ρ.reducedRight = (ρ.congr (QSystem.Iso.comm S T)).reducedLeft := by + apply State.ext + apply ContinuousLinearMap.coe_injective + simp only [State.reducedRight_op, State.reducedLeft_op, State.congr_op, + LinearMap.coe_toContinuousLinearMap] + exact LinearMap.partialTraceLeft_eq_partialTraceRight_comm (stdOrthonormalBasis ℂ S.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space) + +/-- **The left marginal is the right marginal of the swapped state** (mirror of +`State.reducedRight_congr_comm`). For a bipartite state `ρ` on `S ⊗ T`, tracing out the right +factor `T` (`State.reducedLeft`) is the same as swapping the factors and tracing out the (now left) +factor `T` (`State.reducedRight`): + +`ρ.reducedLeft = (ρ.congr (QSystem.Iso.comm S T)).reducedRight`. + +Partial-trace identity `LinearMap.partialTraceRight_eq_partialTraceLeft_comm`. Transfers the +`reducedRight` API to `reducedLeft` (e.g. symmetry of the mutual information). -/ +theorem State.reducedLeft_congr_comm (ρ : State (S ⊗ T)) : + ρ.reducedLeft = (ρ.congr (QSystem.Iso.comm S T)).reducedRight := by + apply State.ext + apply ContinuousLinearMap.coe_injective + simp only [State.reducedRight_op, State.reducedLeft_op, State.congr_op, + LinearMap.coe_toContinuousLinearMap] + exact LinearMap.partialTraceRight_eq_partialTraceLeft_comm (stdOrthonormalBasis ℂ T.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReducedStateLeftBlock.lean b/LeanPool/AxQM/Postulates/API/ReducedStateLeftBlock.lean new file mode 100644 index 0000000000..aa53823dcb --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReducedStateLeftBlock.lean @@ -0,0 +1,104 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceLeftBlock + +/-! +# AxQM — tracing out a composite *left* factor of a state (N&C Exercise 11.24) + +`State.reducedLeft` traces out the *right* factor of a bipartite state and `State.reducedRight` the +*left* factor. The transport lemma `State.reducedLeft_congr_assoc_symm` +(`AxQM/Postulates/API/ReducedStateTransport.lean`) records how tracing out a composite *right* block +`Y ⊗ Z` decomposes after re-association: for `ω` on `(X ⊗ Y) ⊗ Z`, +`Tr_{Y⊗Z} (assoc⁻¹ ω) = Tr_Z (Tr_Y ω)` (an iterated `reducedLeft`). This file adds the mirror for +the composite *left* block, the `reducedRight` analogue: + +* `State.reducedRight_reducedRight_congr_assoc_symm` — for a state `b` on `(X ⊗ Y) ⊗ W`, tracing out + the left block `X ⊗ Y` in one step equals re-associating to `X ⊗ (Y ⊗ W)`, tracing out `X` + (`reducedRight`), then tracing out `Y` (`reducedRight`): + + `Tr_X (Tr_Y (assoc⁻¹ b)) = Tr_{X⊗Y} b`. + +* `State.reducedRight_congr_assoc` — the forward face of the same identity (for `b` on + `X ⊗ (Y ⊗ W)`), completing the `reducedRight` family alongside its `symm` face. + +## Use + +The purification proof of **weak monotonicity** `S(A) + S(B) ≤ S(A,C) + S(B,C)` (N&C Exercise 11.24) +reads the `S(A,C)` term off the purification as the marginal on the *composite* two-subsystem block +`A ⊗ C`, tracing out `R ⊗ B`. Turning that composite-block marginal into iterated single-factor +marginals — so it can be matched against strong subadditivity's `S(R,B)` term — is exactly this +decomposition. The `reducedLeft` half is in `AxQM/Postulates/API/ReducedStateTransport.lean`; the +`reducedRight` half is here. + +The proof reduces to the left-block partial-trace tower lemma +`LinearMap.partialTraceLeft_partialTraceLeft_assocIsometry_conjStarAlgEquiv` +(`ToMathlib/Analysis/InnerProductSpace/PartialTraceLeftBlock`, the left mirror of +`partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Tracing out a composite left factor decomposes as iterated single-factor traces** (the +`reducedRight` mirror of `State.reducedLeft_congr_assoc_symm`). For a state `b` on `(X ⊗ Y) ⊗ W`, +re-associating to `X ⊗ (Y ⊗ W)`, tracing out `X` (`reducedRight`), then tracing out `Y` +(`reducedRight`) gives the same `W`-marginal as tracing out the whole left block `X ⊗ Y` at once: + +`Tr_X (Tr_Y (assoc⁻¹ b)) = Tr_{X⊗Y} b`. + +Reduces to the left-block tower lemma +`LinearMap.partialTraceLeft_partialTraceLeft_assocIsometry_conjStarAlgEquiv` (up to +basis-independence of the partial trace, `LinearMap.partialTraceLeft_eq_of_basis`). This is the +identity that lets the weak-monotonicity purification argument (N&C Exercise 11.24) +express the `A ⊗ C`-block marginal of a purification as an iterated marginal. -/ +theorem State.reducedRight_reducedRight_congr_assoc_symm {X Y W : QSystem} + (b : State ((X ⊗ Y) ⊗ W)) : + ((State.congr (QSystem.assoc X Y W).symm b).reducedRight).reducedRight = b.reducedRight := by + apply State.ext + apply ContinuousLinearMap.coe_injective + change LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ Y.space) + (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ X.space) + (((QSystem.assoc X Y W).symm.toIsometry.conjStarAlgEquiv b.op).toLinearMap)) = + LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ (X ⊗ Y : QSystem).space) b.op.toLinearMap + rw [QSystem.assoc_symm_toIsometry] + -- `((X ⊗ Y) ⊗ W).space` is only `rfl`-defeq (via `QSystem.compose`, twice-nested) to the + -- generic `(X.space ⊗[ℂ] Y.space) ⊗[ℂ] W.space` the tower/basis-independence lemmas + -- need to match syntactically; restate `b.op` there via a `let` and bridge back with `exact`. + let bopCLM : (X.space ⊗[ℂ] Y.space) ⊗[ℂ] W.space →L[ℂ] + (X.space ⊗[ℂ] Y.space) ⊗[ℂ] W.space := b.op + have htower := LinearMap.partialTraceLeft_partialTraceLeft_assocIsometry_conjStarAlgEquiv + (stdOrthonormalBasis ℂ X.space) (stdOrthonormalBasis ℂ Y.space) bopCLM + have hbasis := LinearMap.partialTraceLeft_eq_of_basis + ((stdOrthonormalBasis ℂ X.space).tensorProduct (stdOrthonormalBasis ℂ Y.space)) + (stdOrthonormalBasis ℂ (X.space ⊗[ℂ] Y.space)) bopCLM.toLinearMap + exact htower.trans hbasis + +/-- **Tracing out a composite left factor is stable under association** — the forward face of +`State.reducedRight_reducedRight_congr_assoc_symm`, completing the `reducedRight` family. For a +state `b` on `X ⊗ (Y ⊗ W)`, re-associating to `(X ⊗ Y) ⊗ W` and tracing out the whole `X ⊗ Y` block +gives the same `W`-marginal as tracing out `X` then `Y`: `Tr_{X⊗Y}(assoc b) = Tr_Y(Tr_X b)`. Derived +from the `symm` face by cancelling the associator against its inverse, exactly as +`State.reducedLeft_reducedLeft_congr_assoc` (`AxQM/Postulates/API/SubadditivityReformulations.lean`) +mirrors +`State.reducedLeft_congr_assoc_symm`. -/ +theorem State.reducedRight_congr_assoc {X Y W : QSystem} (b : State (X ⊗ (Y ⊗ W))) : + (b.congr (QSystem.assoc X Y W)).reducedRight = b.reducedRight.reducedRight := by + have h := State.reducedRight_reducedRight_congr_assoc_symm (b.congr (QSystem.assoc X Y W)) + rw [← State.congr_trans, QSystem.Iso.trans_symm_self, State.congr_refl] at h + exact h.symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReducedStateReshape.lean b/LeanPool/AxQM/Postulates/API/ReducedStateReshape.lean new file mode 100644 index 0000000000..fcce7abf4b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReducedStateReshape.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ReducedStateComm + +/-! +# AxQM — the reduced states under a per-factor tensor reshape + +For a bipartite state `ρ` on `S ⊗ T`, `State.reducedLeft` traces out the *right* factor `T` and +`State.reducedRight` traces out the *left* factor `S`. This file records how these two marginals +behave when the state is transported (`State.congr`) along a reshape that acts on a **single** +tensor factor — `QSystem.Iso.tmul e (QSystem.Iso.refl _)` or `QSystem.Iso.tmul (QSystem.Iso.refl _) +e`. There are two faces: + +* **Reshape the traced-out factor ⟹ the marginal is unchanged.** Applying a unitary to the factor + that is about to be discarded cannot change the marginal. + - `State.reducedLeft_congr_tmul_refl` (right factor reshaped; in `ReducedStateTransport`); + - `State.reducedRight_congr_tmul_refl` (left factor reshaped) — its mirror, added here. +* **Reshape the kept factor ⟹ the marginal is conjugated.** A unitary on the surviving factor is + carried through the partial trace and reappears conjugating the marginal. + - `State.reducedLeft_congr_tmul_left` (left factor reshaped ⟹ `Tr_T · ↦ (Tr_T ·).congr`); + - `State.reducedRight_congr_tmul_right` (right factor reshaped ⟹ `Tr_S · ↦ (Tr_S ·).congr`). + +Together with `State.reducedLeft_congr_tmul_refl` this is the complete quartet of +"marginal of a state transported along a one-factor reshape" identities. + +## Use + +These `reducedRight` identities are used in the purification proof of **weak monotonicity** +(N&C eq. (11.72) / Exercise 11.24) — hence the second-entry subadditivity of the conditional +entropy (N&C Theorem 11.16, eq. (11.118)). That argument purifies a state, +applies strong subadditivity to a marginal of the purification, and reads the resulting entropies +back onto the original state's marginals; the reference is brought beside the traced block by the +reshape `QSystem.pullRefReshape = (assoc _ _ _).symm.trans (id ⊗ comm)`, whose `id ⊗ comm` step is a +kept-factor reshape whose `reducedRight` is exactly `State.reducedRight_congr_tmul_right`. + +The `reducedLeft` reshaping lemmas (`AxQM/Postulates/API/ReducedStateTransport.lean`) rest on the +`partialTraceRight` naturality; the mirror `reducedRight` lemmas would need the `partialTraceLeft` +counterparts, which are not available. Rather than add them, the `reducedRight` identities here are +derived from their `reducedLeft` siblings through the factor-swap bridge +`State.reducedRight_congr_comm` (`AxQM/Postulates/API/ReducedStateComm.lean`): a `reducedRight` +goal is rewritten to a `reducedLeft` goal on the `QSystem.Iso.comm`-swapped state, where the +existing API applies. The swap-commutes-past-a-one-factor-reshape identity that makes this +routing go through is the naturality square `QSystem.Iso.tmul_trans_comm` +(`AxQM/Postulates/API/SystemIsoComm.lean`), instantiated with `h := refl` (left-factor reshape) or +`g := refl` (right-factor reshape). The one +lemma proved directly from the partial trace is `State.reducedLeft_congr_tmul_left` (kept-left +conjugation), which reuses the kept-factor equivariance +`LinearMap.restrictRight_comp_tensorMap_id` (generalized here to a space-changing map); its +`reducedRight` mirror follows from it via the bridge. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S S' T T' : QSystem} + +/-- **Reshaping the traced-out left factor leaves the right marginal unchanged.** For a bipartite +state `ρ` on `S ⊗ T` and a reshape `g : S ≃ₛ S'` acting only on the left factor, transporting along +`g ⊗ id_T` and then tracing out the (reshaped) left factor gives the same right marginal as tracing +out the original left factor: + +`(ρ.congr (g ⊗ id_T)).reducedRight = ρ.reducedRight`. + +The `reducedRight` mirror of `State.reducedLeft_congr_tmul_refl`: the right marginal does not see a +unitary applied to the discarded left factor. Derived from that `reducedLeft` lemma by rewriting +both `reducedRight`s through the factor-swap bridge `State.reducedRight_congr_comm` and commuting +the swap past the reshape (`QSystem.Iso.tmul_trans_comm`, `h := refl`). -/ +theorem State.reducedRight_congr_tmul_refl (g : S ≃ₛ S') (ρ : State (S ⊗ T)) : + (ρ.congr (QSystem.Iso.tmul g (QSystem.Iso.refl T))).reducedRight = ρ.reducedRight := by + rw [State.reducedRight_congr_comm (ρ.congr (QSystem.Iso.tmul g (QSystem.Iso.refl T))), + State.reducedRight_congr_comm ρ, ← State.congr_trans, QSystem.Iso.tmul_trans_comm, + State.congr_trans, State.reducedLeft_congr_tmul_refl] + +/-- **Reshaping the kept left factor conjugates the left marginal.** For a bipartite state `ρ` on +`S ⊗ T` and a reshape `h : S ≃ₛ S'` acting only on the left factor, transporting along `h ⊗ id_T` +and then tracing out the right factor equals tracing out the right factor and then transporting the +`S`-marginal along `h`: + +`(ρ.congr (h ⊗ id_T)).reducedLeft = ρ.reducedLeft.congr h`. + +A unitary on the surviving (left) factor is carried through the partial trace and reappears +conjugating the marginal. Proved at the level of operators: the transported operator is the +conjugation `(h ⊗ 1) · (h ⊗ 1)⁻¹` of `ρ.op`, whose `partialTraceRight` is `h · h⁻¹` of +`partialTraceRight ρ.op` by the kept-factor equivariance +`LinearMap.restrictRight_comp_tensorMap_id` (applied inside the partial-trace sum). Its +`reducedRight` mirror `State.reducedRight_congr_tmul_right` follows from it through the factor-swap +bridge. -/ +theorem State.reducedLeft_congr_tmul_left (h : S ≃ₛ S') (ρ : State (S ⊗ T)) : + (ρ.congr (QSystem.Iso.tmul h (QSystem.Iso.refl T))).reducedLeft = ρ.reducedLeft.congr h := by + set b := stdOrthonormalBasis ℂ T.space with hb + -- Kept-factor equivariance of `restrictRight`: reshaping the (kept) left factor by `f` pulls `f` + -- out of the restriction (`restrictRight_comp_tensorMap_id`, whose space-changing case + -- this is; `restrictRight` only reads the right factor, which `f ⊗ id` fixes). + have hr : ∀ (f : S.space →ₗ[ℂ] S'.space) (k) (w : S.space ⊗[ℂ] T.space), + LinearMap.restrictRight b k (TensorProduct.map f LinearMap.id w) + = f (LinearMap.restrictRight b k w) := + fun f k w => LinearMap.congr_fun (LinearMap.restrictRight_comp_tensorMap_id b f k) w + apply State.ext + apply ContinuousLinearMap.coe_injective + simp only [State.reducedLeft_op, State.congr_op, QSystem.Iso.tmul_toIsometry, + QSystem.Iso.refl_toIsometry, LinearMap.coe_toContinuousLinearMap] + change LinearMap.partialTraceRight b + (((TensorProduct.congrIsometry h.toIsometry + (LinearIsometryEquiv.refl ℂ T.space)).conjStarAlgEquiv ρ.op).toLinearMap) = + (h.toIsometry.conjStarAlgEquiv (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b ρ.op.toLinearMap))).toLinearMap + -- Unfold the two conjugations to plain `TensorProduct.map`/`LinearMap` compositions. + have hcoe : ((TensorProduct.congrIsometry h.toIsometry + (LinearIsometryEquiv.refl ℂ T.space)).conjStarAlgEquiv ρ.op).toLinearMap = + TensorProduct.map h.toIsometry.toLinearMap LinearMap.id ∘ₗ ρ.op.toLinearMap ∘ₗ + TensorProduct.map h.toIsometry.symm.toLinearMap LinearMap.id := by + let ρopCLM : S.space ⊗[ℂ] T.space →L[ℂ] S.space ⊗[ℂ] T.space := ρ.op + have hgen : ((TensorProduct.congrIsometry h.toIsometry + (LinearIsometryEquiv.refl ℂ T.space)).conjStarAlgEquiv ρopCLM).toLinearMap = + TensorProduct.map h.toIsometry.toLinearMap LinearMap.id ∘ₗ ρopCLM.toLinearMap ∘ₗ + TensorProduct.map h.toIsometry.symm.toLinearMap LinearMap.id := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap, LinearEquiv.conj_apply, + TensorProduct.toLinearEquiv_congrIsometry] + simp only [TensorProduct.congr_symm, TensorProduct.toLinearMap_congr] + rfl + exact hgen + have hrhs : (h.toIsometry.conjStarAlgEquiv (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b ρ.op.toLinearMap))).toLinearMap = + h.toIsometry.toLinearMap ∘ₗ LinearMap.partialTraceRight b ρ.op.toLinearMap ∘ₗ + h.toIsometry.symm.toLinearMap := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap, LinearEquiv.conj_apply] + simp only [LinearMap.coe_toContinuousLinearMap] + rfl + rw [hcoe, hrhs] + -- Compute `partialTraceRight (map h 1 ∘ ρ.op ∘ map h⁻¹ 1)` slotwise and pull `h` out via `hr`. + apply LinearMap.ext + intro x + rw [LinearMap.partialTraceRight_apply] + simp only [LinearMap.comp_apply] + erw [LinearMap.partialTraceRight_apply, map_sum] + refine Finset.sum_congr rfl (fun k _ => ?_) + rw [hr] + congr 2 + +/-- **Reshaping the kept right factor conjugates the right marginal.** For a bipartite state `ρ` on +`S ⊗ T` and a reshape `h : T ≃ₛ T'` acting only on the right factor, transporting along `id_S ⊗ h` +and then tracing out the left factor equals tracing out the left factor and then transporting the +`T`-marginal along `h`: + +`(ρ.congr (id_S ⊗ h)).reducedRight = ρ.reducedRight.congr h`. + +The `reducedRight` mirror of `State.reducedLeft_congr_tmul_left`, and the exact identity the weak- +monotonicity purification proof uses to push the reference `R` beside the traced block (the +`id ⊗ comm` step of `QSystem.pullRefReshape`). Derived from the kept-left conjugation lemma by +rewriting the `reducedRight`s through the factor-swap bridge `State.reducedRight_congr_comm` and +commuting the swap past the reshape (`QSystem.Iso.tmul_trans_comm`, `g := refl`). -/ +theorem State.reducedRight_congr_tmul_right (h : T ≃ₛ T') (ρ : State (S ⊗ T)) : + (ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl S) h)).reducedRight = ρ.reducedRight.congr h := by + rw [State.reducedRight_congr_comm (ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl S) h)), + ← State.congr_trans, QSystem.Iso.tmul_trans_comm, State.congr_trans, + State.reducedLeft_congr_tmul_left, State.reducedRight_congr_comm ρ] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReducedStateTransport.lean b/LeanPool/AxQM/Postulates/API/ReducedStateTransport.lean new file mode 100644 index 0000000000..a7275b8589 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReducedStateTransport.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM — reduced-state transport and purification-entropy complementarity + +Structural facts about how the reduced states `State.reducedLeft` / `State.reducedRight` interact +with the transport of a state along a system isomorphism (`State.congr`), together with the entropy +identity relating a state to the ancilla marginal of its purification. They are used in the +purification proof of **weak monotonicity** (N&C eq. (11.72) / Exercise 11.24, the "form-1" +strong-subadditivity inequality `S(A) + S(B) ≤ S(A,C) + S(B,C)`) and hence the **second-entry +subadditivity of the conditional entropy** (N&C Theorem 11.16, eq. (11.118)): that argument purifies +a state, applies strong subadditivity to a marginal of the purification, and reads the resulting +entropies back onto the original state's marginals through exactly these transport lemmas. Compare +`AxQM/Postulates/API/SubadditivityReformulations.lean` and +`AxQM/Postulates/API/PartialTraceReassoc.lean`, whose companions these are. + +## Main results + +* `AxQM.State.congr_trans` — transports compose: + `ρ.congr (e.trans f) = (ρ.congr e).congr f`. +* `AxQM.State.congr_refl` / `AxQM.QSystem.Iso.trans_symm_self` / + `AxQM.QSystem.Iso.symm_trans_self` — the unit, right-inverse and left-inverse laws of the + transport backbone. +* `AxQM.State.reducedLeft_congr_tmul_refl` — reshaping the traced-out right factor of a + bipartite state leaves the left marginal unchanged. +* `AxQM.State.reducedLeft_congr_assoc_symm` — the left marginal after de-associating + `(X ⊗ Y) ⊗ Z → X ⊗ (Y ⊗ Z)` is the iterated left marginal (trace `Z`, then `Y`). This is the + single canonical associator–left-marginal lemma that applies the commutation fact + `partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv`; the reverse face + `State.reducedLeft_reducedLeft_congr_assoc` (`Postulates/API/SubadditivityReformulations`) + reuses it (via the transport unit/inverse laws) rather than re-proving the commutation fact. +* `AxQM.State.vonNeumannEntropy_purify_reducedRight` — a state and the ancilla marginal of + its canonical purification are isentropic, `S(ρ) = S(Tr_S ρ.purify)`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Transports compose.** Carrying a state along `e : S ≃ₛ T` and then along `f : T ≃ₛ U` is the +same as carrying it along the composite `e.trans f`. The `State` functoriality of the transport +backbone (`QSystem.Iso.trans`), the density-operator companion of `PureState.congr_trans` (stated in +the same orientation, `congr (e.trans f) = congr f ∘ congr e`). -/ +theorem State.congr_trans {S T U : QSystem} (e : S ≃ₛ T) (f : T ≃ₛ U) (ρ : State S) : + ρ.congr (e.trans f) = (ρ.congr e).congr f := by + apply State.ext + simp only [State.congr_op] + rfl + +/-- **Transport along the identity is the identity**: `ρ.congr (refl S) = ρ`. The unit law of the +transport backbone, paired with `State.congr_trans`; conjugating by the identity isometry +(`LinearIsometryEquiv.conjStarAlgEquiv_refl`) fixes the density operator. -/ +theorem State.congr_refl (ρ : State S) : ρ.congr (QSystem.Iso.refl S) = ρ := by + apply State.ext + simp only [State.congr_op, QSystem.Iso.refl_toIsometry, + LinearIsometryEquiv.conjStarAlgEquiv_refl, StarAlgEquiv.coe_refl, id_eq] + +/-- **A system isomorphism composed with its inverse is the identity**: `e.trans e.symm = refl S`. +The right-inverse law of the transport backbone (`QSystem.Iso.trans`/`symm`/`refl`), a +consequence of `LinearIsometryEquiv.self_trans_symm`. -/ +theorem QSystem.Iso.trans_symm_self {S T : QSystem} (e : S ≃ₛ T) : + e.trans e.symm = QSystem.Iso.refl S := + congrArg QSystem.Iso.mk (LinearIsometryEquiv.self_trans_symm e.toIsometry) + +/-- **A system isomorphism composed after its inverse is the identity**: `e.symm.trans e = refl T`. +The left-inverse law of the transport backbone (`QSystem.Iso.trans`/`symm`/`refl`), the companion of +the right-inverse law `QSystem.Iso.trans_symm_self`, a consequence of +`LinearIsometryEquiv.symm_trans_self`. -/ +theorem QSystem.Iso.symm_trans_self {S T : QSystem} (e : S ≃ₛ T) : + e.symm.trans e = QSystem.Iso.refl T := + congrArg QSystem.Iso.mk (LinearIsometryEquiv.symm_trans_self e.toIsometry) + +/-- **Reshaping the traced-out factor leaves the left marginal unchanged.** For a bipartite state +`ρ` on `S ⊗ T` and a system isomorphism `g : T ≃ₛ T'` reshaping only the right factor, transporting +along `id ⊗ g` and then tracing out the (reshaped) right factor gives the same left marginal as +tracing out the original right factor: `Tr_{T'} ((id ⊗ g) ρ (id ⊗ g)⁻¹) = Tr_T ρ`. The left marginal +does not see a unitary applied to the discarded factor (lemma +`LinearMap.partialTraceRight_conjStarAlgEquiv_congrIsometry`, up to basis-independence of the +partial trace). -/ +theorem State.reducedLeft_congr_tmul_refl {S T T' : QSystem} (g : T ≃ₛ T') (ρ : State (S ⊗ T)) : + (ρ.congr (QSystem.Iso.tmul (QSystem.Iso.refl S) g)).reducedLeft = ρ.reducedLeft := by + apply State.ext + apply ContinuousLinearMap.coe_injective + change (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ T'.space) + (((QSystem.Iso.tmul (QSystem.Iso.refl S) g).toIsometry.conjStarAlgEquiv ρ.op).toLinearMap)) = + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ T.space) ρ.op.toLinearMap) + have hbasis := LinearMap.partialTraceRight_eq_of_basis (stdOrthonormalBasis ℂ T'.space) + ((stdOrthonormalBasis ℂ T.space).map g.toIsometry) + (((QSystem.Iso.tmul (QSystem.Iso.refl S) g).toIsometry.conjStarAlgEquiv ρ.op).toLinearMap) + exact hbasis.trans (LinearMap.partialTraceRight_conjStarAlgEquiv_congrIsometry + (stdOrthonormalBasis ℂ T.space) g.toIsometry ρ.op) + +/-- **The left marginal is stable under de-association.** For a state `ω` on `(X ⊗ Y) ⊗ Z`, +re-associating to `X ⊗ (Y ⊗ Z)` and tracing out the whole right block `Y ⊗ Z` gives the same +`X`-marginal as tracing out `Z` (`reducedLeft`) and then `Y` (`reducedLeft`): +`Tr_{Y⊗Z} (assoc⁻¹ ω) = Tr_Y (Tr_Z ω)`. Reduces to the commutation lemma +`LinearMap.partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv` (with the +associator roundtrip absorbed), up to basis-independence of the partial trace. -/ +theorem State.reducedLeft_congr_assoc_symm {X Y Z : QSystem} (ω : State ((X ⊗ Y) ⊗ Z)) : + (ω.congr (QSystem.assoc X Y Z).symm).reducedLeft = ω.reducedLeft.reducedLeft := by + apply State.ext + apply ContinuousLinearMap.coe_injective + set e := TensorProduct.assocIsometry ℂ X.space Y.space Z.space with he + set ceq := e.conjStarAlgEquiv with hceq + have key := LinearMap.partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv + (stdOrthonormalBasis ℂ Y.space) (stdOrthonormalBasis ℂ Z.space) (ceq ω.op) + have hcancel := StarAlgEquiv.symm_apply_apply ceq ω.op + have keyed : LinearMap.partialTraceRight (stdOrthonormalBasis ℂ Y.space) + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ Z.space) + ((ceq.symm (ceq ω.op)).toLinearMap)) = + LinearMap.partialTraceRight + ((stdOrthonormalBasis ℂ Y.space).tensorProduct (stdOrthonormalBasis ℂ Z.space)) + (ceq ω.op).toLinearMap := + key + rw [hcancel] at keyed + clear key hcancel + change LinearMap.partialTraceRight (stdOrthonormalBasis ℂ (Y ⊗ Z : QSystem).space) + (((QSystem.assoc X Y Z).symm.toIsometry.conjStarAlgEquiv ω.op).toLinearMap) = + LinearMap.partialTraceRight (stdOrthonormalBasis ℂ Y.space) + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ Z.space) ω.op.toLinearMap) + rw [QSystem.assoc_symm_toIsometry] + have hbasis2 := LinearMap.partialTraceRight_eq_of_basis + (stdOrthonormalBasis ℂ (Y ⊗ Z : QSystem).space) + ((stdOrthonormalBasis ℂ Y.space).tensorProduct (stdOrthonormalBasis ℂ Z.space)) + ((e.conjStarAlgEquiv ω.op).toLinearMap) + exact hbasis2.trans keyed.symm + +/-- **A state is isentropic with the ancilla marginal of its purification.** For any state `ρ` on +`S`, the canonical purification `ρ.purify` is a pure state on `S ⊗ R` (`R` a copy of `S`) whose left +marginal is `ρ` (`State.purify_reducedLeft_eq`); since the two reduced states of a pure bipartite +state have equal von Neumann entropy (`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`, +N&C Theorem 11.8(3)), `ρ` and the ancilla marginal `Tr_S ρ.purify` are isentropic: + +`S(ρ) = S(Tr_S ρ.purify)`. + +This is the entropy half of the purification-complementarity fact (`S(X) = S(X^c)` for a pure +composite) that turns strong subadditivity into weak monotonicity (N&C eq. (11.72) / Exercise 11.24) +and the Araki–Lieb triangle inequality. -/ +theorem State.vonNeumannEntropy_purify_reducedRight (ρ : State S) : + ρ.vonNeumannEntropy = ρ.purify.toState.reducedRight.vonNeumannEntropy := by + rw [← PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight ρ.purify, ρ.purify_reducedLeft_eq] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ReferencePurification.lean b/LeanPool/AxQM/Postulates/API/ReferencePurification.lean new file mode 100644 index 0000000000..13bb29884e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ReferencePurification.lean @@ -0,0 +1,72 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.ReducedStateComm +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy + +/-! +# Reference purification with the reference on the left (N&C §12.4.1) + +Nielsen & Chuang's discussion of entropy exchange and coherent information (§12.4.1–12.4.2) +introduces a *reference system* `R` and a purification `|RQ⟩` of the input state `ρ` on `Q`, +written with the reference `R` as the **first** factor so that a quantum operation `E` on `Q` +acts on the *right* factor of `R ⊗ Q` (matching `State.dilatedChannelOnRight`, whose channel acts +on the right). + +The library's canonical purification `State.purify` places the ancilla on the *right* +(`ρ.purify : PureState (Q ⊗ R)`, left marginal `ρ`). This file wraps it with the swap isomorphism +`QSystem.Iso.comm` to obtain the reference-on-the-left form `State.refPurify ρ : PureState (R ⊗ Q)`, +together with the two facts the entropy-exchange development needs: + +* `State.refPurify_reducedRight` — the `Q`-marginal (right factor) of `refPurify ρ` is `ρ`; +* `State.vonNeumannEntropy_refPurify_reducedLeft` — the reference marginal `R` is isentropic with + `ρ`, `S(R) = S(ρ)`, since `refPurify ρ` is pure and complementary marginals of a pure state share + their entropy. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **Reference purification with the reference on the left.** For a state `ρ` on `S`, this is the +canonical purification `ρ.purify` (a pure state on `S ⊗ R` with left marginal `ρ`) with its two +factors swapped, giving a pure state on `R ⊗ S` — the reference `R` first, the system `S` second. +Nielsen & Chuang §12.4.1 use exactly this ordering `|RQ⟩` so that a quantum operation on the system +acts on the right factor. -/ +def State.refPurify (ρ : State S) : + PureState ((QSystem.ofModel (EuclideanSpace ℂ (Fin S.dim))).compose S) := + PureState.congr (QSystem.Iso.comm S _) ρ.purify + +/-- The system marginal of the reference purification is the original state: tracing out the +reference `R` (the left factor of `R ⊗ S`) from `refPurify ρ` recovers `ρ`. Since `refPurify` is +`ρ.purify` with the factors swapped and `ρ.purify` has left marginal `ρ` +(`State.purify_reducedLeft_eq`), the swap turns that left marginal into the right marginal +(`State.reducedLeft_congr_comm`). -/ +theorem State.refPurify_reducedRight (ρ : State S) : + (State.refPurify ρ).toState.reducedRight = ρ := by + rw [State.refPurify, PureState.congr_toState, ← State.reducedLeft_congr_comm, + State.purify_reducedLeft_eq] + +/-- The reference marginal of the reference purification is isentropic with the state: +`S(R) = S(ρ)`. As `refPurify ρ` is pure on `R ⊗ S`, its two reduced states share their von Neumann +entropy (`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`, N&C Theorem 11.8(3)), and the +`S`-marginal is `ρ` (`State.refPurify_reducedRight`). -/ +theorem State.vonNeumannEntropy_refPurify_reducedLeft (ρ : State S) : + (State.refPurify ρ).toState.reducedLeft.vonNeumannEntropy = ρ.vonNeumannEntropy := by + rw [PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight, State.refPurify_reducedRight] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RelativeEntropy.lean b/LeanPool/AxQM/Postulates/API/RelativeEntropy.lean new file mode 100644 index 0000000000..30c3387e46 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RelativeEntropy.lean @@ -0,0 +1,393 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyConvexNonfaithful +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyMonotone +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedKleinInequality + +/-! +# AxQM — quantum relative entropy of two states + +The **quantum relative entropy** (Umegaki relative entropy) of a state `ρ` with respect to a state +`σ` (Nielsen–Chuang §11.3.1, eq. (11.55)) is + +`S(ρ ‖ σ) = tr(ρ log ρ) − tr(ρ log σ)`, + +the quantum generalization of the classical Kullback–Leibler divergence. It is the central tool of +Nielsen–Chuang §11.3: **Klein's inequality** (Theorem 11.7) `S(ρ ‖ σ) ≥ 0` is the source of +essentially every entropy inequality in the chapter (subadditivity, concavity, and — through the +convexity of the relative entropy and its monotonicity under partial trace — strong subadditivity). + +This file defines the relative entropy `State.quantumRelativeEntropy` of states, from the operator +`ContinuousLinearMap.quantumRelativeEntropy` of their density operators, together with the two +halves of Klein's inequality: non-negativity `State.quantumRelativeEntropy_nonneg` and the equality +condition `State.quantumRelativeEntropy_eq_zero_iff`. + +## The finite branch (support condition), and faithfulness + +Klein's inequality is `S(ρ ‖ σ) ≥ 0`; N&C defines `S(ρ ‖ σ) = +∞` when `supp ρ ⊄ supp σ` and finite +otherwise. The definition here is the real-valued, finite quantity (`cfc Real.log` sends the zero +eigenvalues of a rank-deficient `σ` to `0` rather than `−∞`), so its natural domain is exactly N&C's +"finite otherwise" branch: the **support condition** `supp ρ ⊆ supp σ`, i.e. +`ρ.op.HasSupportLE σ.op` (`ker σ.op ≤ ker ρ.op`). On that branch Klein's inequality holds in full — +`S(ρ ‖ σ) ≥ 0`, with equality iff `ρ = σ` — with *no* restriction on `σ`'s rank; this is the +faithful statement (`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` and +`…_eq_zero_iff_of_hasSupportLE`), lifting the support-condition lemmas +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_{nonneg,eq_zero_iff}_of_hasSupportLE`. + +Requiring `σ` **faithful** — every eigenvalue of `σ.op` strictly positive, i.e. `σ` full rank — +is the strictly stronger special case `ker σ.op = ⊥` (a faithful `σ` dominates the support of every +`ρ`); it *narrows* the finite branch (dropping pairs with both `ρ, σ` rank-deficient) and so the +faithful forms `State.quantumRelativeEntropy_nonneg` / `…_eq_zero_iff` are kept only as convenience +corollaries for callers that already carry a strictly positive reference state. + +## Main definitions + +* `AxQM.State.quantumRelativeEntropy` — the relative entropy `S(ρ ‖ σ)` of states `ρ, σ`. + +## Main results + +* `AxQM.State.quantumRelativeEntropy_self_eq_zero` — `S(ρ ‖ ρ) = 0`. +* `AxQM.State.quantumRelativeEntropy_nonneg_of_hasSupportLE` — **Klein's inequality** (N&C + Theorem 11.7), the faithful finite-branch form: `S(ρ ‖ σ) ≥ 0` whenever `supp ρ ⊆ supp σ` + (`ρ.op.HasSupportLE σ.op`), no faithfulness of `σ`. +* `AxQM.State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE` — **Klein's inequality, + equality condition** (N&C Theorem 11.7): for `supp ρ ⊆ supp σ`, `S(ρ ‖ σ) = 0 ↔ ρ = σ`. +* `AxQM.State.quantumRelativeEntropy_nonneg` / `…_eq_zero_iff` — the faithful-`σ` + (`ker σ.op = ⊥`) special cases, kept as convenience corollaries. +* `AxQM.State.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub` — the bridge + `S(ρ ‖ σ) = −S(ρ) − re tr(ρ log σ)` relating the relative entropy to the von Neumann entropy. +* `AxQM.State.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE` — **joint + convexity of the relative entropy** (N&C Theorem 11.12), the faithful finite-branch form: the + `n`-ary `S(∑ wₖ ρₖ ‖ ∑ wₖ σₖ) ≤ ∑ wₖ S(ρₖ‖σₖ)` under only the **support condition** + `(ρₖ).op.HasSupportLE (σₖ).op` on each component — no faithfulness (rank-deficient states + allowed). +* `AxQM.State.quantumRelativeEntropy_jointly_convex_of_hasSupportLE` — its **two-point + form** `S(t ρ₁+s ρ₂ ‖ t σ₁+s σ₂) ≤ t S(ρ₁‖σ₁)+s S(ρ₂‖σ₂)`, N&C's literal statement. +* `AxQM.State.quantumRelativeEntropy_jointly_convex_sum` / `…_jointly_convex` — the + faithful-constituent (`IsStrictlyPositive`) special cases, kept as convenience corollaries; the + `n`-ary form is the one used in the strong-subadditivity argument. +* `AxQM.State.quantumRelativeEntropy_reduced_le_of_hasSupportLE` — **monotonicity under the + partial trace** (N&C Theorem 11.17), the **faithful finite-branch form**: tracing out the right + subsystem cannot increase the relative entropy, `S(ρ_A ‖ σ_A) ≤ S(ρ_AB ‖ σ_AB)`, under only the + **support condition** `ρ.op.HasSupportLE σ.op` — no faithfulness (rank-deficient states allowed); + the bridge to strong subadditivity (N&C Theorem 11.14). +* `AxQM.State.quantumRelativeEntropy_reduced_le` — the faithful-states + (`IsStrictlyPositive`) special case, kept as a convenience corollary. +-/ + +@[expose] public section + +namespace AxQM + +variable {S : QSystem} + +/-- The **quantum relative entropy** `S(ρ ‖ σ) = tr(ρ log ρ) − tr(ρ log σ)` of a state `ρ` with +respect to a state `σ` (Nielsen–Chuang §11.3.1, eq. (11.55)). It is +`ContinuousLinearMap.quantumRelativeEntropy` of the density operators. -/ +noncomputable def State.quantumRelativeEntropy (ρ σ : State S) : ℝ := + ρ.op.quantumRelativeEntropy σ.op + +/-- The `_def` bridge: the states' relative entropy is the operator relative entropy of their +density operators. Holds definitionally; provided so proofs can rewrite +between `State.quantumRelativeEntropy` and `ContinuousLinearMap.quantumRelativeEntropy`. -/ +theorem State.quantumRelativeEntropy_def (ρ σ : State S) : + ρ.quantumRelativeEntropy σ = ρ.op.quantumRelativeEntropy σ.op := + rfl + +/-- **The relative entropy of a state with itself vanishes**: `S(ρ ‖ ρ) = 0`. Immediate from the +`tr(ρ log ρ) − tr(ρ log ρ)` shape of the definition (no faithfulness needed). -/ +@[simp] theorem State.quantumRelativeEntropy_self_eq_zero (ρ : State S) : + ρ.quantumRelativeEntropy ρ = 0 := + ContinuousLinearMap.quantumRelativeEntropy_self ρ.op + +/-- **Klein's inequality** (Nielsen–Chuang Theorem 11.7), on the finite branch. The quantum relative +entropy of two states is non-negative, `S(ρ ‖ σ) ≥ 0`, whenever the **support condition** +`supp ρ ⊆ supp σ` holds — `ρ.op.HasSupportLE σ.op`, i.e. `ker σ.op ≤ ker ρ.op` — with **no +faithfulness of `σ` required**. + +This is N&C's theorem stated on exactly the branch where the relative entropy is finite: N&C define +`S(ρ ‖ σ) = +∞` when `supp ρ ⊄ supp σ` and finite otherwise, and the support condition +`ρ.op.HasSupportLE σ.op` is precisely that "finite otherwise" clause — the natural domain of the +real-valued quantity, not an added hypothesis narrowing the claim. It is therefore the faithful +statement of Klein's inequality; the faithful-`σ` form `State.quantumRelativeEntropy_nonneg` below +is the special case `ker σ.op = ⊥`, which genuinely *narrows* the theorem (it excludes finite-branch +pairs with both `ρ, σ` rank-deficient), so it is only a convenience corollary. + +Lifts the operator inequality +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_nonneg_of_hasSupportLE` through the `_def` +bridge. -/ +theorem State.quantumRelativeEntropy_nonneg_of_hasSupportLE (ρ σ : State S) + (h : ρ.op.HasSupportLE σ.op) : 0 ≤ ρ.quantumRelativeEntropy σ := + ρ.isDensity.quantumRelativeEntropy_nonneg_of_hasSupportLE σ.isDensity h + +/-- **Klein's inequality, equality condition** (Nielsen–Chuang Theorem 11.7), on the finite branch. +For states satisfying the **support condition** `supp ρ ⊆ supp σ` (`ρ.op.HasSupportLE σ.op`, i.e. +`ker σ.op ≤ ker ρ.op`), the quantum relative entropy vanishes iff the states coincide, +`S(ρ ‖ σ) = 0 ↔ ρ = σ` — with **no faithfulness of `σ` required**. Together with +`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` this is the full content of Klein's inequality +on the finite branch: `S(ρ ‖ σ) ≥ 0`, with equality exactly when `ρ = σ`. + +The faithful statement of the equality condition (see +`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` for why the support condition — N&C's own +"finite otherwise" branch — is the right hypothesis and not a weakening); the faithful-`σ` form +`State.quantumRelativeEntropy_eq_zero_iff` below is the special case `ker σ.op = ⊥`. + +Lifts the operator equality condition +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE` through the +`_def` bridge and `State.ext` (a state is determined by its density operator `.op`). -/ +theorem State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE (ρ σ : State S) + (h : ρ.op.HasSupportLE σ.op) : ρ.quantumRelativeEntropy σ = 0 ↔ ρ = σ := by + rw [State.quantumRelativeEntropy_def, + ρ.isDensity.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE σ.isDensity h] + exact ⟨fun hop => State.ext hop, fun hst => by rw [hst]⟩ + +/-- **Klein's inequality for a faithful `σ`** (Nielsen–Chuang Theorem 11.7): the quantum relative +entropy of two states is non-negative, `S(ρ ‖ σ) ≥ 0`, provided `σ` is **faithful** (all eigenvalues +of `σ.op` strictly positive). The `ker σ.op = ⊥` special case of the general finite-branch statement +`State.quantumRelativeEntropy_nonneg_of_hasSupportLE` (a faithful `σ` dominates the support of every +`ρ`); retained as a convenience corollary for the many callers that already work with a strictly +positive reference state. Grounds the operator Klein–Gibbs inequality +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_nonneg`. -/ +theorem State.quantumRelativeEntropy_nonneg (ρ σ : State S) + (hσ_pos : ∀ j, 0 < σ.isDensity.isSymmetric.eigenvalues rfl j) : + 0 ≤ ρ.quantumRelativeEntropy σ := + ρ.isDensity.quantumRelativeEntropy_nonneg σ.isDensity hσ_pos + +/-- **Klein's inequality equality condition, for a faithful `σ`** (Nielsen–Chuang Theorem 11.7): for +a **faithful** state `σ` (all eigenvalues of `σ.op` strictly positive), the quantum relative entropy +vanishes iff the states coincide, `S(ρ ‖ σ) = 0 ↔ ρ = σ`. The `ker σ.op = ⊥` special case of the +general finite-branch statement `State.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE`; retained +as a convenience corollary. Together with `State.quantumRelativeEntropy_nonneg` this is the full +content of Klein's inequality for a faithful reference: `S(ρ ‖ σ) ≥ 0`, with equality exactly when +`ρ = σ`. + +Lifts the operator equality condition +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_eq_zero_iff` to states: the +`_def` bridge turns the equation into the operator one `S(ρ.op ‖ σ.op) = 0 ↔ ρ.op = σ.op`, +and `State.ext_iff` (a state is determined by its density operator `.op`, the remaining field being +a proof) equates operator equality `ρ.op = σ.op` with state equality `ρ = σ`. Only `σ` need be +faithful; `ρ` may be rank-deficient. -/ +theorem State.quantumRelativeEntropy_eq_zero_iff (ρ σ : State S) + (hσ_pos : ∀ j, 0 < σ.isDensity.isSymmetric.eigenvalues rfl j) : + ρ.quantumRelativeEntropy σ = 0 ↔ ρ = σ := by + rw [State.quantumRelativeEntropy_def, + ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_eq_zero_iff ρ.isDensity σ.isDensity + hσ_pos] + exact State.ext_iff.symm + +/-- **Relative entropy in terms of the von Neumann entropy**: +`S(ρ ‖ σ) = −S(ρ) − re tr(ρ log σ)`, for any states `ρ, σ` (no faithfulness needed). Lifts +`ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub`; the +form in which the relative entropy enters the entropy inequalities (e.g. subadditivity +`S(A:B) = S(ρ_AB ‖ ρ_A ⊗ ρ_B)`). -/ +theorem State.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub (ρ σ : State S) : + ρ.quantumRelativeEntropy σ = -ρ.vonNeumannEntropy - + RCLike.re (LinearMap.trace ℂ S.space ((cfc Real.log σ.op).toLinearMap ∘ₗ ρ.op.toLinearMap)) := + ρ.isDensity.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub + +/-- **Joint convexity of the quantum relative entropy, `n`-ary form** (Nielsen–Chuang +Theorem 11.12), the **faithful finite-branch statement**: for families of states +`ρs, σs : κ → State S` and convex weights `w` (`w k ≥ 0`, `∑ w k = 1`) with the **support +condition** `(ρs k).op.HasSupportLE (σs k).op` (`ker (σs k).op ≤ ker (ρs k).op`) on every +component, if the mixed states `ρ, σ` are the convex combinations `ρ = ∑ₖ wₖ ρsₖ` and +`σ = ∑ₖ wₖ σsₖ` of the density +operators, then `S(ρ ‖ σ) ≤ ∑ₖ wₖ S(ρsₖ ‖ σsₖ)`. + +This is N&C's theorem stated on exactly the branch where the relative entropy is finite — N&C's +`S(ρ ‖ σ) = +∞` when `supp ρ ⊄ supp σ`, finite otherwise — with **no faithfulness (strict +positivity) required**; rank-deficient constituents are allowed. The support condition is precisely +that "finite otherwise" clause, the natural domain of the real-valued quantity (`cfc Real.log` +sends the zero eigenvalues of a rank-deficient operator to `0` rather than `−∞`), not a hypothesis +narrowing the claim. The `IsStrictlyPositive` form `State.quantumRelativeEntropy_jointly_convex_sum` +below is the strictly stronger special case (`ker (σs k).op = ⊥`), which excludes rank-deficient +pairs and so is only a convenience corollary. + +Lifts `ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE` +(Lindblad's theorem with faithfulness removed by the `ε → 0⁺` perturbation-and-limit argument, +itself built on Lieb's theorem, N&C Theorem 11.11) to states. The two positivity hypotheses +the operator inequality needs hold for any state (`isDensity.isPositive`); only the +support condition is a genuine hypothesis. The convex combination is supplied through the +`ρ.op = ∑ …` / `σ.op = ∑ …` hypotheses because `State` has no mixing operation. +This is the form used in the strong-subadditivity argument (N&C Theorem 11.14): monotonicity of the +relative entropy under partial trace averages a twirl over a unitary 1-design, a convex combination +of unitary conjugates. + +That inequality lives on an abstract finite-dimensional complex inner product space but needs +the real–complex scalar tower on the operator algebra; it is not a global instance for the space of +a `QSystem`, so it is supplied here via `NormedSpace.complexToReal`. -/ +theorem State.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE + {κ : Type*} (u : Finset κ) (ρ σ : State S) (ρs σs : κ → State S) (w : κ → ℝ) + (hsupp : ∀ k ∈ u, (ρs k).op.HasSupportLE (σs k).op) + (hw₀ : ∀ k ∈ u, 0 ≤ w k) (hw₁ : ∑ k ∈ u, w k = 1) + (hρ : ρ.op = ∑ k ∈ u, w k • (ρs k).op) + (hσ : σ.op = ∑ k ∈ u, w k • (σs k).op) : + ρ.quantumRelativeEntropy σ ≤ ∑ k ∈ u, w k * (ρs k).quantumRelativeEntropy (σs k) := by + have : NormedSpace ℝ (S.space →L[ℂ] S.space) := NormedSpace.complexToReal + have : IsScalarTower ℝ ℂ (S.space →L[ℂ] S.space) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + simp only [State.quantumRelativeEntropy_def] + rw [hρ, hσ] + exact ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE u + (fun k _ => (ρs k).isDensity.isPositive) (fun k _ => (σs k).isDensity.isPositive) + hsupp hw₀ hw₁ + +/-- **Joint convexity of the quantum relative entropy, two-point form** (Nielsen–Chuang +Theorem 11.12), the **faithful finite-branch statement** and N&C's literal two-point claim: for +states with the **support conditions** `ρ₁.op.HasSupportLE σ₁.op` and `ρ₂.op.HasSupportLE σ₂.op` and +probabilities `t, s ≥ 0`, `t + s = 1`, if `ρ = t ρ₁ + s ρ₂` and `σ = t σ₁ + s σ₂` (as density +operators), then `S(ρ ‖ σ) ≤ t · S(ρ₁ ‖ σ₁) + s · S(ρ₂ ‖ σ₂)`. + +The two-point specialization of `State.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE` +over a two-element (`Fin 2`) index. **No strict positivity is required** — only the support +condition, N&C's "finite otherwise" branch; the `IsStrictlyPositive` form +`State.quantumRelativeEntropy_jointly_convex` below is a convenience corollary. -/ +theorem State.quantumRelativeEntropy_jointly_convex_of_hasSupportLE + (ρ σ ρ₁ ρ₂ σ₁ σ₂ : State S) + (hs₁ : ρ₁.op.HasSupportLE σ₁.op) (hs₂ : ρ₂.op.HasSupportLE σ₂.op) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) + (hρ : ρ.op = t • ρ₁.op + s • ρ₂.op) + (hσ : σ.op = t • σ₁.op + s • σ₂.op) : + ρ.quantumRelativeEntropy σ ≤ + t * ρ₁.quantumRelativeEntropy σ₁ + s * ρ₂.quantumRelativeEntropy σ₂ := by + have key := State.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE + (Finset.univ : Finset (Fin 2)) ρ σ ![ρ₁, ρ₂] ![σ₁, σ₂] ![t, s] + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by simp [Fin.sum_univ_two, hts]) + (by rw [hρ]; simp [Fin.sum_univ_two]) + (by rw [hσ]; simp [Fin.sum_univ_two]) + simpa [Fin.sum_univ_two] using key + +/-- **Joint convexity for faithful constituents, `n`-ary form** (Nielsen–Chuang Theorem 11.12): the +`IsStrictlyPositive` (full-rank) special case of the faithful finite-branch statement +`State.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE`. When every `ρsₖ, σsₖ` is faithful +(strictly positive spectrum), each support condition `(ρs k).op.HasSupportLE (σs k).op` holds +unconditionally (`ker (σs k).op = ⊥`), so the general statement specializes to +`S(∑ₖ wₖ ρsₖ ‖ ∑ₖ wₖ σsₖ) ≤ ∑ₖ wₖ S(ρsₖ ‖ σsₖ)`. + +Requiring strict positivity *narrows* the theorem (it excludes rank-deficient constituents that the +support condition admits), so this is only a convenience corollary; it is retained because it is the +form used in the strong-subadditivity argument (N&C Theorem 11.14), whose twirl constituents are +faithful. It lifts the strict-positivity operator inequality +`ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_sum`. -/ +theorem State.quantumRelativeEntropy_jointly_convex_sum + {κ : Type*} (u : Finset κ) (ρ σ : State S) (ρs σs : κ → State S) (w : κ → ℝ) + (hρs : ∀ k ∈ u, IsStrictlyPositive (ρs k).op) + (hσs : ∀ k ∈ u, IsStrictlyPositive (σs k).op) + (hw₀ : ∀ k ∈ u, 0 ≤ w k) (hw₁ : ∑ k ∈ u, w k = 1) + (hρ : ρ.op = ∑ k ∈ u, w k • (ρs k).op) + (hσ : σ.op = ∑ k ∈ u, w k • (σs k).op) : + ρ.quantumRelativeEntropy σ ≤ ∑ k ∈ u, w k * (ρs k).quantumRelativeEntropy (σs k) := by + have : NormedSpace ℝ (S.space →L[ℂ] S.space) := NormedSpace.complexToReal + have : IsScalarTower ℝ ℂ (S.space →L[ℂ] S.space) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + simp only [State.quantumRelativeEntropy_def] + rw [hρ, hσ] + exact ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_sum u hρs hσs hw₀ hw₁ + +/-- **Joint convexity for faithful constituents, two-point form** (Nielsen–Chuang Theorem 11.12): +the `IsStrictlyPositive` (full-rank) special case of the faithful two-point statement +`State.quantumRelativeEntropy_jointly_convex_of_hasSupportLE`. For probabilities `t, s ≥ 0` with +`t + s = 1` and **faithful** states `ρ₁, ρ₂, σ₁, σ₂` whose density operators satisfy +`ρ = t ρ₁ + s ρ₂` and `σ = t σ₁ + s σ₂`, `S(ρ ‖ σ) ≤ t · S(ρ₁ ‖ σ₁) + s · S(ρ₂ ‖ σ₂)`. + +Requiring strict positivity narrows the finite-branch two-point statement (each faithful pair +satisfies the support condition unconditionally, `ker σᵢ.op = ⊥`), so this is only a convenience +corollary, kept for callers already working with strictly positive states; obtained from the `n`-ary +`State.quantumRelativeEntropy_jointly_convex_sum` over a two-element index. -/ +theorem State.quantumRelativeEntropy_jointly_convex + (ρ σ ρ₁ ρ₂ σ₁ σ₂ : State S) + (hρ₁ : IsStrictlyPositive ρ₁.op) (hρ₂ : IsStrictlyPositive ρ₂.op) + (hσ₁ : IsStrictlyPositive σ₁.op) (hσ₂ : IsStrictlyPositive σ₂.op) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) + (hρ : ρ.op = t • ρ₁.op + s • ρ₂.op) + (hσ : σ.op = t • σ₁.op + s • σ₂.op) : + ρ.quantumRelativeEntropy σ ≤ + t * ρ₁.quantumRelativeEntropy σ₁ + s * ρ₂.quantumRelativeEntropy σ₂ := by + have key := State.quantumRelativeEntropy_jointly_convex_sum + (Finset.univ : Finset (Fin 2)) ρ σ ![ρ₁, ρ₂] ![σ₁, σ₂] ![t, s] + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by simp [Fin.sum_univ_two, hts]) + (by rw [hρ]; simp [Fin.sum_univ_two]) + (by rw [hσ]; simp [Fin.sum_univ_two]) + simpa [Fin.sum_univ_two] using key + +/-- **Monotonicity of the quantum relative entropy under the partial trace, on the support +condition** (Nielsen–Chuang Theorem 11.17), the **faithful finite-branch statement**. Tracing out +the right subsystem cannot increase the relative entropy, + +`S(ρ_A ‖ σ_A) ≤ S(ρ_AB ‖ σ_AB)`, + +where `ρ_A = Tr_T ρ = ρ.reducedLeft` (and likewise for `σ`), whenever the **support condition** +`supp ρ ⊆ supp σ` holds — `ρ.op.HasSupportLE σ.op` (`ker σ.op ≤ ker ρ.op`) — with **no faithfulness +(strict positivity) of either state required**. + +This is N&C's theorem stated on exactly the branch where the relative entropy is finite: N&C define +`S(ρ ‖ σ) = +∞` when `supp ρ ⊄ supp σ` and finite otherwise, and the support condition +`ρ.op.HasSupportLE σ.op` is precisely that "finite otherwise" clause — the natural domain of the +real-valued quantity (`cfc Real.log` sends the zero eigenvalues of a rank-deficient operator to `0` +rather than `−∞`), not a hypothesis narrowing the claim. Rank-deficient `ρ, σ` are admitted; the +marginal support condition `supp ρ_A ⊆ supp σ_A` needed for the left-hand side descends from the +joint one automatically inside the operator-level proof. The `IsStrictlyPositive` form +`State.quantumRelativeEntropy_reduced_le` below is the strictly stronger special case +(`ker σ.op = ⊥`, both states full rank), so it is only a convenience corollary. + +Lifts `ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le_of_hasSupportLE` +to states through `State.reducedLeft`. The two positivity hypotheses the operator +inequality needs hold for any state (`isDensity.isPositive`); only the support +condition is a genuine hypothesis. Following N&C's proof, the completely depolarizing partial-trace +channel `τ ↦ (Tr_T τ) ⊗ I/d` is exhibited as a uniform mixed-unitary average over a unitary +`1`-design (N&C Ex 11.19) and fed into the mixed-unitary data-processing inequality, whose engine is +the **support-condition joint convexity** (N&C Theorem 11.12); the maximally mixed `I/d` factor is +cancelled by the common-right-factor tensor split, and faithfulness is removed throughout by the +`ε → 0⁺` identity-shift perturbation. The nontriviality of the traced-out factor `T.space` — needed +so `I/d` is a genuine density operator — is furnished by the reduced state +`ρ.reducedRight : State T`. +This is the monotonicity that, applied to a mutual-information relative entropy, yields the strong +subadditivity of the von Neumann entropy (N&C Theorem 11.14). -/ +theorem State.quantumRelativeEntropy_reduced_le_of_hasSupportLE {S T : QSystem} + (ρ σ : State (S.compose T)) (hsupp : ρ.op.HasSupportLE σ.op) : + ρ.reducedLeft.quantumRelativeEntropy σ.reducedLeft ≤ ρ.quantumRelativeEntropy σ := by + have : Nontrivial T.space := ρ.reducedRight.nontrivial_space + have : Nonempty (Fin (Module.finrank ℂ T.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + simp only [State.quantumRelativeEntropy_def, State.reducedLeft_op] + exact ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le_of_hasSupportLE + (stdOrthonormalBasis ℂ T.space) ρ.isDensity.isPositive σ.isDensity.isPositive hsupp + +/-- **Monotonicity of the quantum relative entropy under the partial trace, for faithful states** +(Nielsen–Chuang Theorem 11.17): the `IsStrictlyPositive` (full-rank) special case of the faithful +finite-branch statement `State.quantumRelativeEntropy_reduced_le_of_hasSupportLE`. For faithful +states `ρ, σ` (strictly positive spectrum) the support condition `ρ.op.HasSupportLE σ.op` holds +unconditionally (`ker σ.op = ⊥`), so tracing out the right subsystem cannot increase the relative +entropy, `S(ρ_A ‖ σ_A) ≤ S(ρ_AB ‖ σ_AB)`, where `ρ_A = Tr_T ρ = ρ.reducedLeft`. + +Requiring strict positivity *narrows* the theorem (it excludes rank-deficient states the support +condition admits), so this is only a convenience corollary; it is retained for callers already +working with strictly positive states (e.g. the strong-subadditivity argument, N&C Theorem 11.14, +whose twirl constituents are faithful). It lifts the density-operator inequality +`ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le`, whose strict-positivity engine is +the special case where both operators are full-rank. -/ +theorem State.quantumRelativeEntropy_reduced_le {S T : QSystem} + (ρ σ : State (S.compose T)) + (hρ : IsStrictlyPositive ρ.op) (hσ : IsStrictlyPositive σ.op) : + ρ.reducedLeft.quantumRelativeEntropy σ.reducedLeft ≤ ρ.quantumRelativeEntropy σ := by + have : Nontrivial T.space := ρ.reducedRight.nontrivial_space + have : Nonempty (Fin (Module.finrank ℂ T.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + simp only [State.quantumRelativeEntropy_def, State.reducedLeft_op] + exact ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le + (stdOrthonormalBasis ℂ T.space) ρ.isDensity σ.isDensity hρ hσ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/RelativePhase.lean b/LeanPool/AxQM/Postulates/API/RelativePhase.lean new file mode 100644 index 0000000000..962e092e6f --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/RelativePhase.lean @@ -0,0 +1,220 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.Concrete.PauliEigenvectors +public import LeanPool.AxQM.Concrete.PlusStateTensorPower +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle + +/-! +# AxQM.Postulates.API — the `|±⟩` states and relative-phase equivalence in a basis + +The `|±⟩` states and relative-phase equivalence for **Nielsen & Chuang, Exercise 2.65** +(§2.2.7, *Phase*, p. 93). The exercise asks to express `|+⟩ = (|0⟩ + |1⟩)/√2` and +`|-⟩ = (|0⟩ - |1⟩)/√2` in a basis in which they are *not* the same up to a relative phase shift. + +## Relative phase, following N&C §2.2.7 + +Two complex amplitudes `a` and `b` **differ by a relative phase** if `a = exp(iθ) b` for some +real `θ`. Two *states* differ by a relative phase *in a basis* if each amplitude of one, in that +basis, is `exp(iθ)` times the corresponding amplitude of the other — crucially, the phase `θ` +**may vary from amplitude to amplitude** (this is what distinguishes a *relative* phase from a +*global* one, and makes it a basis-dependent notion). We model a "basis" physically as a family of +pure states `e : ι → PureState S` (intended to be an orthonormal basis), and the amplitude of a +state `ψ` in direction `e i` as the inner product `⟪(e i).vec, ψ.vec⟫`. + +* `PureState.RelativePhaseEquiv e ψ φ` — the predicate that `ψ` and `φ` differ by a relative phase + in the frame `e`: `∀ i, ∃ θ : ℝ, ⟪(e i).vec, ψ.vec⟫ = exp(iθ) • ⟪(e i).vec, φ.vec⟫`. +* `PureState.RelativePhaseEquiv.norm_inner_eq` — its physical fingerprint: relative-phase-equivalent + states have **identical amplitude magnitudes** in every direction of the frame + (`|exp(iθ)| = 1`). This is the lever that certifies a basis where the equivalence *fails*. + +## The `|±⟩` states + +* `qubitPlus`, `qubitMinus : PureState qubit` — the `X`-eigenstates `|±⟩ = (|0⟩ ± |1⟩)/√2`, built + on the concrete unit vectors `Concrete.xPlus`/`Concrete.xMinus`. +* Amplitude lemmas: `inner_qubitBasis_qubitPlus`/`_qubitMinus` give the computational-basis + amplitudes (`⟨i|±⟩ = (xPlus/xMinus) i`), and `inner_qubitPlus_self`/`inner_qubitPlus_qubitMinus` + record that `{|+⟩, |-⟩}` is an **orthonormal** pair (`⟨+|+⟩ = 1`, `⟨+|-⟩ = 0`) — hence a genuine + basis of the qubit, the basis used as N&C's answer. + +## Design notes + +* **Basis as a family of pure states.** Representing the basis as `ι → PureState S` (rather than a + Mathlib `OrthonormalBasis` of the underlying space `↑S`) lets the statements in + [upstream `AxQM/NC/Ch2/Exercise2_65.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_65.lean) mention only `PureState` and this predicate. It is also the more + physical reading of "a basis of states". The two theorems of Exercise 2.65, stated with + `RelativePhaseEquiv`, are in [upstream `AxQM/NC/Ch2/Exercise2_65.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_65.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-! ### Relative-phase equivalence in a frame -/ + +/-- Two pure states `ψ`, `φ` of a system `S` **differ by a relative phase in the frame `e`** (a +family of pure states, intended to be an orthonormal basis) if each amplitude of `ψ` equals +`exp(iθ)` times the corresponding amplitude of `φ`, for some real phase `θ` that may depend on the +index. This is Nielsen & Chuang's basis-dependent notion of relative phase (§2.2.7): the amplitude +of a state in direction `e i` is the inner product `⟪(e i).vec, ·.vec⟫`, and the phase `θ` is +allowed to vary from index to index. -/ +def PureState.RelativePhaseEquiv {S : QSystem} {ι : Type*} (e : ι → PureState S) + (ψ φ : PureState S) : Prop := + ∀ i, ∃ θ : ℝ, ⟪(e i).vec, ψ.vec⟫_ℂ = Complex.exp ((θ : ℂ) * Complex.I) • ⟪(e i).vec, φ.vec⟫_ℂ + +/-- **Relative-phase-equivalent states have equal amplitude magnitudes.** If `ψ` and `φ` differ by +a relative phase in the frame `e`, then in every direction `e i` the magnitudes of their amplitudes +coincide, `‖⟪(e i).vec, ψ.vec⟫‖ = ‖⟪(e i).vec, φ.vec⟫‖`, because the relating factor `exp(iθ)` is a +unit complex number. This is the physical fingerprint of relative phase, and the lever used to +exhibit a basis in which two states are *not* relative-phase equivalent. -/ +theorem PureState.RelativePhaseEquiv.norm_inner_eq {S : QSystem} {ι : Type*} + {e : ι → PureState S} {ψ φ : PureState S} (h : PureState.RelativePhaseEquiv e ψ φ) (i : ι) : + ‖⟪(e i).vec, ψ.vec⟫_ℂ‖ = ‖⟪(e i).vec, φ.vec⟫_ℂ‖ := by + obtain ⟨θ, hθ⟩ := h i + rw [hθ, smul_eq_mul, norm_mul, Complex.norm_exp] + simp + +/-- **A single phase factor on the vectors gives relative-phase equivalence in every frame.** If +`ψ.vec = e^{iθ} φ.vec` (the two pure states differ by one *global* phase), then +`RelativePhaseEquiv e ψ φ` holds for *any* family `e`: each amplitude `⟪(e i).vec, ψ.vec⟫` is +`e^{iθ}` times `⟪(e i).vec, φ.vec⟫`, with the same `θ` for every index. The bridge used to lift a +global-phase identity on state vectors to a `RelativePhaseEquiv` statement. -/ +theorem PureState.relativePhaseEquiv_of_vec_eq_smul {S : QSystem} {ι : Type*} + (e : ι → PureState S) {ψ φ : PureState S} (θ : ℝ) + (h : ψ.vec = Complex.exp ((θ : ℂ) * Complex.I) • φ.vec) : + PureState.RelativePhaseEquiv e ψ φ := + fun i => ⟨θ, by rw [h, inner_smul_right, smul_eq_mul]⟩ + +/-! ### The `|±⟩` states -/ + +/-- The **`X`-eigenstate `|+⟩ = (|0⟩ + |1⟩)/√2`** as a pure state of the qubit, built on the +concrete unit vector `Concrete.xPlus = (1/√2, 1/√2)`. -/ +def qubitPlus : PureState qubit where + vec := WithLp.toLp 2 Concrete.xPlus + normalized := by + have h : ‖(WithLp.toLp 2 Concrete.xPlus : EuclideanSpace ℂ (Fin 2))‖ = 1 := by + rw [EuclideanSpace.norm_eq] + simp only [Concrete.xPlus_apply, Fin.sum_univ_two, Concrete.norm_invSqrt2_sq] + rw [show (2 : ℝ)⁻¹ + 2⁻¹ = 1 by norm_num, Real.sqrt_one] + exact h + +/-- The **`X`-eigenstate `|-⟩ = (|0⟩ - |1⟩)/√2`** as a pure state of the qubit, built on the +concrete unit vector `Concrete.xMinus = (1/√2, -1/√2)`. -/ +def qubitMinus : PureState qubit where + vec := WithLp.toLp 2 Concrete.xMinus + normalized := by + have h : ‖(WithLp.toLp 2 Concrete.xMinus : EuclideanSpace ℂ (Fin 2))‖ = 1 := by + rw [EuclideanSpace.norm_eq] + simp only [Concrete.xMinus, Fin.sum_univ_two, Matrix.cons_val_zero, + Matrix.cons_val_one, norm_neg, Concrete.norm_invSqrt2_sq] + rw [show (2 : ℝ)⁻¹ + 2⁻¹ = 1 by norm_num, Real.sqrt_one] + exact h + +@[simp] theorem qubitPlus_vec : qubitPlus.vec = WithLp.toLp 2 Concrete.xPlus := rfl + +@[simp] theorem qubitMinus_vec : qubitMinus.vec = WithLp.toLp 2 Concrete.xMinus := rfl + +/-! ### The `|±i⟩` states -/ + +/-- The **`Y`-eigenstate `|+i⟩ = (|0⟩ + i|1⟩)/√2`** as a pure state of the qubit, built on the +concrete unit vector `Concrete.yPlus = (1/√2, i/√2)`. The `Y`-analogue of `qubitPlus`; no canonical +`|±i⟩` pure state existed in the library before. -/ +def qubitPlusI : PureState qubit where + vec := WithLp.toLp 2 Concrete.yPlus + normalized := by + have h : ‖(WithLp.toLp 2 Concrete.yPlus : EuclideanSpace ℂ (Fin 2))‖ = 1 := by + rw [EuclideanSpace.norm_eq] + simp only [Concrete.yPlus, Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + norm_mul, Complex.norm_I, mul_one, Concrete.norm_invSqrt2_sq] + rw [show (2 : ℝ)⁻¹ + 2⁻¹ = 1 by norm_num, Real.sqrt_one] + exact h + +/-- The **`Y`-eigenstate `|-i⟩ = (|0⟩ - i|1⟩)/√2`** as a pure state of the qubit, built on the +concrete unit vector `Concrete.yMinus = (1/√2, -i/√2)`. The `Y`-analogue of `qubitMinus`. -/ +def qubitMinusI : PureState qubit where + vec := WithLp.toLp 2 Concrete.yMinus + normalized := by + have h : ‖(WithLp.toLp 2 Concrete.yMinus : EuclideanSpace ℂ (Fin 2))‖ = 1 := by + rw [EuclideanSpace.norm_eq] + simp only [Concrete.yMinus, Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + norm_neg, norm_mul, Complex.norm_I, mul_one, Concrete.norm_invSqrt2_sq] + rw [show (2 : ℝ)⁻¹ + 2⁻¹ = 1 by norm_num, Real.sqrt_one] + exact h + +@[simp] theorem qubitPlusI_vec : qubitPlusI.vec = WithLp.toLp 2 Concrete.yPlus := rfl + +@[simp] theorem qubitMinusI_vec : qubitMinusI.vec = WithLp.toLp 2 Concrete.yMinus := rfl + +/-- The `|+⟩` state expanded in the computational basis: `|+⟩ = (1/√2)(|0⟩ + |1⟩)`, i.e. +`qubitPlus.vec = invSqrt2 • (|0⟩ + |1⟩)`. Lifts the concrete `Concrete.xPlus_eq_smul_add` +(`xPlus = invSqrt2 • (ket 0 + ket 1)`) to the vector of the `PureState`, `WithLp.toLp` carrying +`ket i` to `EuclideanSpace.single i 1 = (qubitBasis i).vec` definitionally. -/ +theorem qubitPlus_vec_eq_smul_add : + qubitPlus.vec = Concrete.invSqrt2 • ((qubitBasis 0).vec + (qubitBasis 1).vec) := by + rw [qubitPlus_vec, Concrete.xPlus_eq_smul_add] + rfl + +/-- The `|-⟩` state expanded in the computational basis: `|-⟩ = (1/√2)(|0⟩ - |1⟩)`, i.e. +`qubitMinus.vec = invSqrt2 • (|0⟩ - |1⟩)`. Lifts the concrete `Concrete.xMinus_eq_smul_sub` +(`xMinus = invSqrt2 • (ket 0 - ket 1)`) to the vector of the `PureState`, the sign-flipped +companion of `qubitPlus_vec_eq_smul_add`. -/ +theorem qubitMinus_vec_eq_smul_sub : + qubitMinus.vec = Concrete.invSqrt2 • ((qubitBasis 0).vec - (qubitBasis 1).vec) := by + rw [qubitMinus_vec, Concrete.xMinus_eq_smul_sub] + rfl + +/-- `|-⟩` written with an explicit `(-1)`-scaled `|1⟩` branch: +`|-⟩ = (1/√2)(|0⟩ + (-1)|1⟩)`. The additive companion of `qubitMinus_vec_eq_smul_sub`, giving +`|-⟩` the same uniform `(1/√2)(|0⟩ + s|1⟩)` shape (`s = -1`) as `qubitPlus_vec_eq_smul_add` gives +`|+⟩` (`s = +1`). -/ +theorem qubitMinus_vec_eq_smul_add : + qubitMinus.vec = Concrete.invSqrt2 • ((qubitBasis 0).vec + (-1 : ℂ) • (qubitBasis 1).vec) := by + rw [qubitMinus_vec_eq_smul_sub, sub_eq_add_neg, ← neg_one_smul ℂ] + +/-! ### Amplitudes of `|±⟩` -/ + +/-- The computational-basis amplitude of `|+⟩`: `⟨i|+⟩ = (xPlus) i = 1/√2` for each `i`. -/ +theorem inner_qubitBasis_qubitPlus (i : Fin 2) : + ⟪(qubitBasis i).vec, qubitPlus.vec⟫_ℂ = Concrete.xPlus i := by + change ⟪(EuclideanSpace.single i 1 : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 Concrete.xPlus⟫_ℂ = Concrete.xPlus i + rw [EuclideanSpace.inner_single_left] + simp + +/-- The computational-basis amplitude of `|-⟩`: `⟨i|-⟩ = (xMinus) i`, which is `1/√2` at `i = 0` +and `-1/√2` at `i = 1` (the sign flip N&C highlights). -/ +theorem inner_qubitBasis_qubitMinus (i : Fin 2) : + ⟪(qubitBasis i).vec, qubitMinus.vec⟫_ℂ = Concrete.xMinus i := by + change ⟪(EuclideanSpace.single i 1 : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 Concrete.xMinus⟫_ℂ = Concrete.xMinus i + rw [EuclideanSpace.inner_single_left] + simp + +/-- `⟨+|+⟩ = 1`: the amplitude of `|+⟩` on itself is `1`. Together with `inner_qubitPlus_qubitMinus` +this certifies that `{|+⟩, |-⟩}` is an orthonormal pair, hence a basis of the qubit. -/ +theorem inner_qubitPlus_self : ⟪qubitPlus.vec, qubitPlus.vec⟫_ℂ = 1 := by + change ⟪(WithLp.toLp 2 Concrete.xPlus : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 Concrete.xPlus⟫_ℂ = 1 + rw [EuclideanSpace.inner_eq_star_dotProduct, dotProduct_comm] + simpa using Concrete.xPlus_dotProduct_self + +/-- `⟨+|-⟩ = 0`: `|+⟩` and `|-⟩` are orthogonal — the amplitude of `|-⟩` on `|+⟩` vanishes. -/ +theorem inner_qubitPlus_qubitMinus : ⟪qubitPlus.vec, qubitMinus.vec⟫_ℂ = 0 := by + change ⟪(WithLp.toLp 2 Concrete.xPlus : EuclideanSpace ℂ (Fin 2)), + WithLp.toLp 2 Concrete.xMinus⟫_ℂ = 0 + rw [EuclideanSpace.inner_eq_star_dotProduct, dotProduct_comm] + simpa using Concrete.xPlus_dotProduct_xMinus + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SchmidtDecomposition.lean b/LeanPool/AxQM/Postulates/API/SchmidtDecomposition.lean new file mode 100644 index 0000000000..25b014cdda --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SchmidtDecomposition.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchmidtDecomposition + +/-! +# AxQM — the Schmidt decomposition of a bipartite pure state (Nielsen–Chuang Theorem 2.7) + +The **Schmidt decomposition** (N&C §2.5, Theorem 2.7): every pure state `|ψ⟩` of a composite +system `S ⊗ T` can be written + + `|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩`, + +where the **Schmidt coefficients** `λᵢ` are strictly positive reals with `∑ᵢ λᵢ² = 1`, and the +**Schmidt bases** `{|iᴬ⟩}` (in `S`) and `{|iᴮ⟩}` (in `T`) are orthonormal families. + +## Statement shape and faithfulness + +We state the decomposition in **reduced form**: the sum ranges over `Fin n` with `n` the Schmidt +number (the number of *nonzero* Schmidt coefficients), the coefficients `λᵢ` are *strictly +positive* (`0 < λᵢ`), and the Schmidt bases are *genuine* orthonormal families (`Orthonormal`). +This is a faithful reformulation of N&C — indeed strictly stronger than the textbook's `λᵢ ≥ 0` +over a full basis, since the positive-coefficient form implies the padded form and the two are +equivalent (drop/append zero terms). N&C proves the equal-dimension case (leaving the general +case to Exercise 2.76); we prove it for **arbitrary** dimensions of `S` and `T`, which is more +general, not a weakening. + +The statement of Theorem 2.7 is in [upstream `AxQM/NC/Ch2/Theorem2_7.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Theorem2_7.lean). + +## Proof + +The mathematical core is the abstract Schmidt decomposition of a bipartite *tensor*, +`TensorProduct.exists_orthonormal_schmidt` (`ToMathlib`), obtained from the singular value +decomposition of the matricized coefficient operator `M = matricize ψ.vec`. Here we specialize +it to `ψ.vec` and use the pure-state normalization `‖ψ.vec‖ = 1` (`PureState.normalized`) to turn +the abstract identity `∑ᵢ λᵢ² = ‖ψ.vec‖²` into `∑ᵢ λᵢ² = 1`. + +## Main results + +* `AxQM.PureState.exists_schmidt_decomposition` — the Schmidt decomposition of a + bipartite pure state. +* `AxQM.PureState.exists_schmidt_decomposition_card_le` — **Exercise 2.76**: the same + decomposition with the number of Schmidt terms bounded by the *smaller* subsystem dimension, + `n ≤ min S.dim T.dim` (the extension to unequal dimensions). +* `AxQM.PureState.IsSchmidtDecomposition` — the predicate "`(l, a, b)` is a (reduced) + Schmidt decomposition of `ψ`", with `PureState.exists_isSchmidtDecomposition` its existence form + (used to state a *concrete* state's Schmidt decomposition as a single reusable claim, e.g. + **Exercise 2.79**). +* `AxQM.PureState.SameSchmidtCoeffs` — the predicate "`ψ` and `φ` have **identical Schmidt + coefficients**" (a common strictly-positive coefficient family over orthonormal Schmidt bases), + the hypothesis of **Exercise 2.80**. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Schmidt decomposition (Nielsen–Chuang Theorem 2.7).** Every bipartite pure state +`ψ : PureState (S ⊗ T)` decomposes as `|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩` for strictly positive Schmidt +coefficients `λᵢ` (with `∑ᵢ λᵢ² = 1`) and orthonormal Schmidt bases `{|iᴬ⟩}` (in `S`), +`{|iᴮ⟩}` (in `T`). Proved for arbitrary dimensions of `S` and `T` (N&C's equal-dimension proof +and Exercise 2.76 together; here uniform via the SVD). Specializes the abstract tensor Schmidt +decomposition `TensorProduct.exists_orthonormal_schmidt` to `ψ.vec`, converting `∑ᵢ λᵢ² = ‖ψ.vec‖²` +to `∑ᵢ λᵢ² = 1` via `ψ.normalized`. -/ +theorem PureState.exists_schmidt_decomposition (ψ : PureState (S ⊗ T)) : + ∃ (n : ℕ) (l : Fin n → ℝ) (a : Fin n → S.space) (b : Fin n → T.space), + (∀ i, 0 < l i) ∧ Orthonormal ℂ a ∧ Orthonormal ℂ b ∧ + (∑ i, l i ^ 2 = 1) ∧ ψ.vec = ∑ i, (l i : ℂ) • a i ⊗ₜ[ℂ] b i := by + obtain ⟨n, l, a, b, hl, ha, hb, hsum, hdecomp⟩ := + TensorProduct.exists_orthonormal_schmidt (ψ.vec : S.space ⊗[ℂ] T.space) + refine ⟨n, l, a, b, hl, ha, hb, ?_, hdecomp⟩ + rw [hsum] + -- the tensor-product norm of `ψ.vec` is defeq to its norm as a state vector, which is `1`. + change ‖ψ.vec‖ ^ 2 = 1 + rw [ψ.normalized, one_pow] + +/-- **Schmidt decomposition for subsystems of possibly unequal dimension (Nielsen–Chuang +Exercise 2.76).** Every bipartite pure state `ψ : PureState (S ⊗ T)` decomposes as +`|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩` (`exists_schmidt_decomposition`) with the number of Schmidt terms bounded +by the *smaller* of the two subsystem dimensions, `n ≤ min S.dim T.dim`. + +This is the content of N&C's Exercise 2.76. N&C prove Theorem 2.7 in the equal-dimension case, +where the coefficient array `a` (with `|ψ⟩ = ∑ⱼₖ aⱼₖ |j⟩|k⟩`) is a *square* matrix and its SVD +`a = u d v` uses square unitaries; extending the proof to `dim A ≠ dim B` makes `a` *rectangular*, +and the number of nonzero singular values — the number of Schmidt terms — is at most +`min(#rows, #cols) = min(dim A, dim B)`. Formally the bound is immediate from the Schmidt bases +being orthonormal families: `{|iᴬ⟩}` are `n` orthonormal vectors of `S.space` (so `n ≤ dim A`) and +`{|iᴮ⟩}` are `n` orthonormal vectors of `T.space` (so `n ≤ dim B`), whence `n ≤ min(dim A, dim B)`. +It is a strict *strengthening* of `exists_schmidt_decomposition`, not a weakening: it adds the term +bound and reuses that theorem's decomposition verbatim, bounding its term count via +`LinearIndependent.fintype_card_le_finrank`. -/ +theorem PureState.exists_schmidt_decomposition_card_le (ψ : PureState (S ⊗ T)) : + ∃ (n : ℕ) (l : Fin n → ℝ) (a : Fin n → S.space) (b : Fin n → T.space), + n ≤ min S.dim T.dim ∧ (∀ i, 0 < l i) ∧ Orthonormal ℂ a ∧ Orthonormal ℂ b ∧ + (∑ i, l i ^ 2 = 1) ∧ ψ.vec = ∑ i, (l i : ℂ) • a i ⊗ₜ[ℂ] b i := by + obtain ⟨n, l, a, b, hl, ha, hb, hsum, hdecomp⟩ := ψ.exists_schmidt_decomposition + refine ⟨n, l, a, b, le_min ?_ ?_, hl, ha, hb, hsum, hdecomp⟩ + · -- `n = card (Fin n) ≤ dim A`, the `n` orthonormal left Schmidt vectors living in `S.space`. + simpa [QSystem.dim] using ha.linearIndependent.fintype_card_le_finrank + · -- `n = card (Fin n) ≤ dim B`, the `n` orthonormal right Schmidt vectors living in `T.space`. + simpa [QSystem.dim] using hb.linearIndependent.fintype_card_le_finrank + +/-- **`(l, a, b)` is a Schmidt decomposition of the bipartite pure state `ψ`.** The data of a +Schmidt decomposition `|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩` (Nielsen–Chuang Theorem 2.7), stated in reduced +form: strictly positive Schmidt coefficients `l : Fin n → ℝ`, orthonormal Schmidt bases +`a : Fin n → S.space` and `b : Fin n → T.space`, normalisation `∑ᵢ lᵢ² = 1`, and the identity +`ψ.vec = ∑ᵢ (lᵢ : ℂ) • aᵢ ⊗ₜ bᵢ`. Its fields are exactly the conclusion of +`PureState.exists_schmidt_decomposition`; naming the concept lets a *concrete* state's Schmidt +decomposition be a single, reusable claim (e.g. N&C Exercise 2.79). -/ +def PureState.IsSchmidtDecomposition (ψ : PureState (S ⊗ T)) {n : ℕ} + (l : Fin n → ℝ) (a : Fin n → S.space) (b : Fin n → T.space) : Prop := + (∀ i, 0 < l i) ∧ Orthonormal ℂ a ∧ Orthonormal ℂ b ∧ + (∑ i, l i ^ 2 = 1) ∧ ψ.vec = ∑ i, (l i : ℂ) • a i ⊗ₜ[ℂ] b i + +/-- **Schmidt decomposition (Nielsen–Chuang Theorem 2.7), packaged via the predicate.** Every +bipartite pure state admits *some* Schmidt decomposition: `∃ n l a b, ψ.IsSchmidtDecomposition +l a b`. This is `PureState.exists_schmidt_decomposition` reread through +`PureState.IsSchmidtDecomposition`, confirming the predicate captures exactly the theorem's +conclusion. -/ +theorem PureState.exists_isSchmidtDecomposition (ψ : PureState (S ⊗ T)) : + ∃ (n : ℕ) (l : Fin n → ℝ) (a : Fin n → S.space) (b : Fin n → T.space), + ψ.IsSchmidtDecomposition l a b := + ψ.exists_schmidt_decomposition + +/-- **Two bipartite pure states have identical Schmidt coefficients** (the hypothesis of +Nielsen–Chuang Exercise 2.80). `ψ` and `φ` share a common family of Schmidt coefficients +`l : Fin n → ℝ` — strictly positive reals, `n` the Schmidt number — in the sense that each admits a +reduced Schmidt decomposition over orthonormal Schmidt bases with those *same* coefficients: +`|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩` and `|φ⟩ = ∑ᵢ λᵢ |i'ᴬ⟩|i'ᴮ⟩`. + +Since the Schmidt coefficients are the (uniquely determined) nonzero singular values of the +matricized state, this existential — a common *ordered* coefficient family `l` — holds exactly when +`ψ` and `φ` have the same Schmidt coefficients as a multiset: given equal multisets, permute one +decomposition's index to match the other. So the predicate is a faithful rendering of "identical +Schmidt coefficients", neither stronger nor weaker. + +It is the hypothesis of `PureState.exists_evolution_tmul_of_sameSchmidtCoeffs` +([upstream `AxQM/NC/Ch2/Exercise2_80.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch2/Exercise2_80.lean)). -/ +def PureState.SameSchmidtCoeffs (ψ φ : PureState (S ⊗ T)) : Prop := + ∃ (n : ℕ) (l : Fin n → ℝ) (a a' : Fin n → S.space) (b b' : Fin n → T.space), + (∀ i, 0 < l i) ∧ Orthonormal ℂ a ∧ Orthonormal ℂ b ∧ Orthonormal ℂ a' ∧ Orthonormal ℂ b' ∧ + ψ.vec = ∑ i, (l i : ℂ) • a i ⊗ₜ[ℂ] b i ∧ φ.vec = ∑ i, (l i : ℂ) • a' i ⊗ₜ[ℂ] b' i + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SchmidtNumber.lean b/LeanPool/AxQM/Postulates/API/SchmidtNumber.lean new file mode 100644 index 0000000000..f9c7d7b864 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SchmidtNumber.lean @@ -0,0 +1,271 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.Postulates.API.Purity +public import LeanPool.AxQM.Postulates.API.SchmidtDecomposition +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MatricizationRank +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Dual +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# AxQM — the Schmidt number of a bipartite pure state + +The **Schmidt number** of a pure state `ψ` of a composite system `S ⊗ T` +(Nielsen–Chuang §2.5): the number of non-zero *Schmidt coefficients* in the +Schmidt decomposition `|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩` (N&C Theorem 2.7). The Schmidt +coefficients are exactly the singular values of the *coefficient operator* +`M = matricize ψ.vec : T.space →L S.space` — the linear map whose matrix in fixed +orthonormal bases is the coefficient array `a` with `ψ = ∑ⱼₖ aⱼₖ |j⟩|k⟩` — so the +Schmidt number is the number of non-zero singular values of `M`. + +Defining it directly from the singular values (rather than as the rank of the +reduced density operator) keeps **Problem 2.2(1)** — *the Schmidt number equals +the rank of `ρᴬ`* — a genuine theorem rather than a definitional tautology. + +The statements about them (Problem 2.2) are in `LeanPool/AxQM/NC/Ch2/Problem2.lean`. + +## Main definitions + +* `AxQM.PureState.schmidtNumber` — the Schmidt number of a bipartite pure + state (number of non-zero singular values of the matricized coefficient operator). +* `AxQM.State.rank` — the rank of a (density-operator) state: the dimension + of the range of its operator. + +## Main results + +* `PureState.schmidtNumber_eq_finrank_range_matricize` — the Schmidt number equals + the rank (`finrank` of range) of the matricized coefficient operator. +* `PureState.reducedLeft_toState_op` — the `_op` bridge `ρᴬ = M Mᵀ` for the left + reduced state (`partialTraceRight_rankOne_self`); citable, reused by Parts 2/3. +* `State.rank_reducedLeft_toState_eq_finrank_range_matricize` — the rank of the left + reduced state `ρᴬ = tr_B(|ψ⟩⟨ψ|)` equals the same rank, via `reducedLeft_toState_op` + and `range (M Mᵀ) = range M`. +* `PureState.schmidtNumber_le_card_of_sum_tmul` — **Problem 2.2(2)**: if `|ψ⟩ = ∑ⱼ |αⱼ⟩|βⱼ⟩` + is a product decomposition into `s.card` (un-normalized) terms, then `Sch(ψ) ≤ s.card`. + The hypothesis is an equation between the state vectors. +* `PureState.natAbs_sub_schmidtNumber_le` — **Problem 2.2(3)**: if `|ψ⟩ = α|φ⟩ + β|γ⟩` with + `α, β ≠ 0`, then `Sch(ψ) ≥ |Sch(φ) − Sch(γ)|` (a reverse-triangle bound). The nonzero + amplitudes are a genuine correctness hypothesis, not a weakening: with `α = 0` the state is + `|ψ⟩ = β|γ⟩` and the inequality fails (take `|φ⟩` maximally entangled, `|γ⟩` a product state). + The hypothesis relates the state vectors. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- The **coefficient operator** of a bipartite pure state, matricized against the +standard orthonormal basis of the *right* factor `T`: the continuous linear map +`M : T.space →L[ℂ] S.space` whose singular values are the Schmidt coefficients of +`ψ` (the matrix of `M` in fixed orthonormal bases is the coefficient array `a` with +`ψ = ∑ⱼₖ aⱼₖ |j⟩|k⟩`). It is used by the Schmidt-number results below and +by the subadditivity/triangle results (Problem 2.2(2),(3)). -/ +def PureState.schmidtOp (ψ : PureState (S ⊗ T)) : T.space →L[ℂ] S.space := + TensorProduct.matricize (stdOrthonormalBasis ℂ T.space) (ψ.vec : S.space ⊗[ℂ] T.space) + +/-- **Schmidt number** of a bipartite pure state (Nielsen–Chuang §2.5): the number of +non-zero Schmidt coefficients `λᵢ` in the Schmidt decomposition `|ψ⟩ = ∑ᵢ λᵢ |iᴬ⟩|iᴮ⟩`. +The Schmidt coefficients are the singular values of the matricized coefficient operator +`M = matricize ψ.vec`, so this counts its non-zero singular values. -/ +def PureState.schmidtNumber (ψ : PureState (S ⊗ T)) : ℕ := + ψ.schmidtOp.toLinearMap.singularValues.support.card + +/-- **Rank of a state**: the dimension of the range of its density operator. For a pure +state's reduced state this is the Schmidt number (`PureState.schmidtNumber_eq_rank_reducedLeft`); +in general it is the number of non-zero eigenvalues of `ρ`. -/ +def State.rank (ρ : State S) : ℕ := + Module.finrank ℂ (LinearMap.range (ρ.op : S.space →ₗ[ℂ] S.space)) + +/-- The Schmidt number is the rank (`finrank` of the range) of the matricized +coefficient operator — the number of non-zero singular values equals the rank +(`LinearMap.card_support_singularValues`). -/ +theorem PureState.schmidtNumber_eq_finrank_range_matricize (ψ : PureState (S ⊗ T)) : + ψ.schmidtNumber + = Module.finrank ℂ (LinearMap.range ψ.schmidtOp.toLinearMap) := + LinearMap.card_support_singularValues _ + +/-- The operator of the left reduced state `ρᴬ = tr_B(|ψ⟩⟨ψ|)` of a bipartite pure state +equals `M Mᵀ`, where `M = ψ.schmidtOp` is the matricized coefficient operator. The +purification/`_op` bridge behind Problem 2.2(1) (`partialTraceRight_rankOne_self`); a +citable identity reused by the Schmidt subadditivity/triangle results (Parts 2/3). -/ +theorem PureState.reducedLeft_toState_op (ψ : PureState (S ⊗ T)) : + ((ψ.toState.reducedLeft).op : S.space →ₗ[ℂ] S.space) + = ↑(ψ.schmidtOp.comp (ContinuousLinearMap.adjoint ψ.schmidtOp)) := by + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + exact TensorProduct.partialTraceRight_rankOne_self + (stdOrthonormalBasis ℂ T.space) (ψ.vec : S.space ⊗[ℂ] T.space) + +/-- The rank of the left reduced state `ρᴬ = tr_B(|ψ⟩⟨ψ|)` equals the rank of the +matricized coefficient operator `M`. This is the structural half of Problem 2.2(1): +the purification identity `ρᴬ = M Mᵀ` (`PureState.reducedLeft_toState_op`) plus +`range (M ∘ Mᵀ) = range M` (`range_self_comp_adjoint`). -/ +theorem State.rank_reducedLeft_toState_eq_finrank_range_matricize (ψ : PureState (S ⊗ T)) : + (ψ.toState.reducedLeft).rank + = Module.finrank ℂ (LinearMap.range ψ.schmidtOp.toLinearMap) := by + rw [State.rank, ψ.reducedLeft_toState_op, ContinuousLinearMap.toLinearMap_comp, + ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace, LinearMap.range_self_comp_adjoint] + +/-- **The Schmidt number is the number of terms of any reduced Schmidt decomposition.** If +`(l, a, b)` is a Schmidt decomposition of `ψ` over `Fin n` (`ψ.IsSchmidtDecomposition l a b`: +strictly positive coefficients, orthonormal Schmidt bases, `∑ lᵢ² = 1`, `ψ.vec = ∑ᵢ lᵢ • aᵢ⊗bᵢ`), +then `ψ.schmidtNumber = n`. Because the Schmidt coefficients are the singular values of the +coefficient operator, every such decomposition has exactly `Sch(ψ)` terms: from the decomposition +the left marginal diagonalises as `ρᴬ = ∑ᵢ lᵢ² |aᵢ⟩⟨aᵢ|` +(`partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt`), which has rank `n` (the `lᵢ² ≠ 0`, +`finrank_range_sum_smul_rankOne_self`); with `Sch(ψ) = rank ρᴬ` this is `n` (the two matricization +bridges above, whose composite is Problem 2.2(1) `schmidtNumber_eq_rank_reducedLeft`). The companion +to `exists_isSchmidtDecomposition`, letting a *concrete* exhibited decomposition (e.g. the entangled +state of Exercise 2.79) fix the Schmidt number. -/ +theorem PureState.schmidtNumber_eq_of_isSchmidtDecomposition {n : ℕ} (ψ : PureState (S ⊗ T)) + {l : Fin n → ℝ} {a : Fin n → S.space} {b : Fin n → T.space} + (h : ψ.IsSchmidtDecomposition l a b) : ψ.schmidtNumber = n := by + obtain ⟨hpos, ha, hb, _, hdecomp⟩ := h + have hcne : ∀ i, ((l i : ℂ)) ^ 2 ≠ 0 := fun i => + pow_ne_zero 2 (Complex.ofReal_ne_zero.mpr (ne_of_gt (hpos i))) + have hL : (ψ.toState.reducedLeft.op : S.space →ₗ[ℂ] S.space) + = ∑ i, ((l i : ℂ)) ^ 2 • (InnerProductSpace.rankOne ℂ (a i) (a i)).toLinearMap := by + rw [State.reducedLeft_op, LinearMap.coe_toContinuousLinearMap, PureState.toState_op] + exact LinearMap.partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis ℂ T.space) l a b hb hdecomp + have hsr : ψ.schmidtNumber = ψ.toState.reducedLeft.rank := + (ψ.schmidtNumber_eq_finrank_range_matricize).trans + (State.rank_reducedLeft_toState_eq_finrank_range_matricize ψ).symm + rw [hsr, State.rank, hL] + exact InnerProductSpace.finrank_range_sum_smul_rankOne_self a _ ha hcne + +/-- **Problem 2.2(2).** If a bipartite pure state `|ψ⟩` has a product decomposition +`|ψ⟩ = ∑ⱼ |αⱼ⟩|βⱼ⟩` into `s.card` (possibly un-normalized) terms, then its Schmidt number is +at most the number of terms, `Sch(ψ) ≤ s.card`. + +The coefficient operator matricizes to `M = ∑ⱼ matricize(αⱼ ⊗ βⱼ)` (matricization is linear); +each summand is a rank-`≤ 1` operator (`TensorProduct.finrank_range_matricize_tmul_le_one`), so +by rank subadditivity (`LinearMap.finrank_range_sum_le`) `Sch(ψ) = finrank (range M) ≤ ∑ⱼ 1 = +s.card`. The exercise is stated in `LeanPool/AxQM/NC/Ch2/Problem2.lean`. -/ +theorem PureState.schmidtNumber_le_card_of_sum_tmul {ι : Type*} (s : Finset ι) + (ψ : PureState (S ⊗ T)) (a : ι → S.space) (b : ι → T.space) + (h : (ψ.vec : S.space ⊗[ℂ] T.space) = ∑ j ∈ s, a j ⊗ₜ[ℂ] b j) : + ψ.schmidtNumber ≤ s.card := by + have hM : ψ.schmidtOp = ∑ j ∈ s, TensorProduct.matricize (stdOrthonormalBasis ℂ T.space) + (a j ⊗ₜ[ℂ] b j) := by + rw [PureState.schmidtOp, h, map_sum] + rw [ψ.schmidtNumber_eq_finrank_range_matricize, hM, ContinuousLinearMap.toLinearMap_sum] + refine (LinearMap.finrank_range_sum_le s _).trans ?_ + calc ∑ j ∈ s, Module.finrank ℂ ↥(LinearMap.range + (TensorProduct.matricize (stdOrthonormalBasis ℂ T.space) (a j ⊗ₜ[ℂ] b j)).toLinearMap) + ≤ ∑ _j ∈ s, 1 := + Finset.sum_le_sum fun j _ => + TensorProduct.finrank_range_matricize_tmul_le_one _ (a j) (b j) + _ = s.card := by rw [Finset.sum_const, smul_eq_mul, mul_one] + +/-- **Problem 2.2(3).** If a bipartite pure state `|ψ⟩` is a superposition `|ψ⟩ = α|φ⟩ + β|γ⟩` +of two pure states with *nonzero* amplitudes `α, β`, then its Schmidt number satisfies the +reverse-triangle bound `Sch(ψ) ≥ |Sch(φ) − Sch(γ)|`. + +The nonzero amplitudes are a genuine correctness hypothesis, not a weakening of N&C: with +`α = 0` the state is `|ψ⟩ = β|γ⟩`, physically `|γ⟩`, so `Sch(ψ) = Sch(γ)`; taking `|φ⟩` +maximally entangled and `|γ⟩` a product state then makes `|Sch(φ) − Sch(γ)|` exceed `Sch(ψ)` +and the inequality genuinely fails. N&C's statement tacitly assumes a two-term superposition, +so `α, β ≠ 0` is the faithful reading. + +Matricization is `ℂ`-linear (`schmidtOp = matricize`, a `LinearEquiv`), so the coefficient +operators combine as `M_ψ = α • M_φ + β • M_γ`. The rank triangle inequality +(`LinearMap.finrank_range_le_finrank_range_add_add`) applied to `α • M_φ` and `β • M_γ`, with +`Sch = finrank ∘ range` (`schmidtNumber_eq_finrank_range_matricize`) and range-invariance under a +nonzero scalar (`LinearMap.range_smul`), gives `Sch(φ) ≤ Sch(ψ) + Sch(γ)`; the symmetric argument +gives `Sch(γ) ≤ Sch(ψ) + Sch(φ)`, and together they yield `|Sch(φ) − Sch(γ)| ≤ Sch(ψ)`. The +hypothesis relates the state vectors `ψ.vec`/`φ.vec`/`γ.vec`. The exercise is stated in +`LeanPool/AxQM/NC/Ch2/Problem2.lean`. -/ +theorem PureState.natAbs_sub_schmidtNumber_le (α β : ℂ) (φ γ ψ : PureState (S ⊗ T)) + (hα : α ≠ 0) (hβ : β ≠ 0) + (hψ : (ψ.vec : S.space ⊗[ℂ] T.space) + = α • (φ.vec : S.space ⊗[ℂ] T.space) + β • (γ.vec : S.space ⊗[ℂ] T.space)) : + ((φ.schmidtNumber : ℤ) - γ.schmidtNumber).natAbs ≤ ψ.schmidtNumber := by + -- The coefficient operators combine linearly, since `matricize` is a `LinearEquiv`. (The + -- linearity lemmas are applied in term mode: `S.space ⊗[ℂ] T.space` and `(S ⊗ T).space` carry + -- defeq-but-not-syntactically-equal additive structure, so `rw`/`simp` cannot match them.) + have hop : ψ.schmidtOp = α • φ.schmidtOp + β • γ.schmidtOp := by + simp only [PureState.schmidtOp, hψ] + exact (map_add (TensorProduct.matricize (stdOrthonormalBasis ℂ T.space)) _ _).trans + (congrArg₂ (· + ·) + (map_smul (TensorProduct.matricize (stdOrthonormalBasis ℂ T.space)) α _) + (map_smul (TensorProduct.matricize (stdOrthonormalBasis ℂ T.space)) β _)) + -- Push the identity down to the underlying linear maps. + have hlin : ψ.schmidtOp.toLinearMap + = (α • φ.schmidtOp).toLinearMap + (β • γ.schmidtOp).toLinearMap := by + rw [hop, ContinuousLinearMap.toLinearMap_add] + -- Express the three Schmidt numbers as ranks of the (scaled) coefficient operators. + have hψrank : ψ.schmidtNumber + = Module.finrank ℂ ↥(LinearMap.range + ((α • φ.schmidtOp).toLinearMap + (β • γ.schmidtOp).toLinearMap)) := by + rw [ψ.schmidtNumber_eq_finrank_range_matricize, hlin] + have hφrank : φ.schmidtNumber + = Module.finrank ℂ ↥(LinearMap.range (α • φ.schmidtOp).toLinearMap) := by + rw [φ.schmidtNumber_eq_finrank_range_matricize, ContinuousLinearMap.toLinearMap_smul, + LinearMap.range_smul _ _ hα] + have hγrank : γ.schmidtNumber + = Module.finrank ℂ ↥(LinearMap.range (β • γ.schmidtOp).toLinearMap) := by + rw [γ.schmidtNumber_eq_finrank_range_matricize, ContinuousLinearMap.toLinearMap_smul, + LinearMap.range_smul _ _ hβ] + -- The two reverse-triangle directions, from the rank triangle inequality. + have dirφ : φ.schmidtNumber ≤ ψ.schmidtNumber + γ.schmidtNumber := by + rw [hφrank, hψrank, hγrank] + exact LinearMap.finrank_range_le_finrank_range_add_add _ _ + have dirγ : γ.schmidtNumber ≤ ψ.schmidtNumber + φ.schmidtNumber := by + rw [hγrank, hψrank, hφrank, + add_comm (α • φ.schmidtOp).toLinearMap (β • γ.schmidtOp).toLinearMap] + exact LinearMap.finrank_range_le_finrank_range_add_add _ _ + omega + +/-- The **Schmidt number of any bipartite pure state is at least `1`**. Its coefficient operator +`M = matricize ψ.vec = ψ.schmidtOp` is non-zero (`matricize` is a linear equivalence and the unit +vector `ψ.vec` is non-zero), so its range in `Sch(ψ) = finrank (range M)` is non-trivial. In +particular `Sch(ψ) = 1` is the minimal non-degenerate value. -/ +theorem PureState.one_le_schmidtNumber (ψ : PureState (S ⊗ T)) : 1 ≤ ψ.schmidtNumber := by + have hvec : ψ.vec ≠ 0 := norm_ne_zero_iff.mp (by rw [ψ.normalized]; exact one_ne_zero) + rw [ψ.schmidtNumber_eq_finrank_range_matricize, Nat.one_le_iff_ne_zero, Ne, + Submodule.finrank_eq_zero, LinearMap.range_eq_bot] + intro hzero + have hz2 : ψ.schmidtOp = 0 := by + ext v; simpa using congrFun (congrArg DFunLike.coe hzero) v + rw [PureState.schmidtOp] at hz2 + -- Name `ψ.vec` at the generic `S.space ⊗[ℂ] T.space` type via a `let` — an inline ascription does + -- not stick (it only checks defeq of the whole ascribed expression, it does not change which + -- instances the surrounding `TensorProduct.matricize` application's implicit `E` unifies + -- against). + let ψvecLM : S.space ⊗[ℂ] T.space := ψ.vec + have hz2' : (TensorProduct.matricize (stdOrthonormalBasis ℂ T.space)) ψvecLM = 0 := hz2 + rw [(TensorProduct.matricize _).map_eq_zero_iff] at hz2' + exact hvec hz2' + +/-- A **pure state has rank `1`**: being a rank-one projector `|v⟩⟨v|` for a unit vector `v`, its +density operator has a one-dimensional range. The easy direction of "pure ↔ rank one"; the converse +(a rank-one density operator is pure) is not needed by its consumers. -/ +theorem State.rank_eq_one_of_isPure {ρ : State S} (h : ρ.IsPure) : ρ.rank = 1 := by + obtain ⟨v, hv, hop⟩ := ρ.isPure_iff_exists_rankOne.mp h + rw [State.rank, hop] + refine le_antisymm (InnerProductSpace.finrank_range_rankOne_le_one v v) ?_ + rw [Nat.one_le_iff_ne_zero, Ne, Submodule.finrank_eq_zero, LinearMap.range_eq_bot] + intro hz + have hv0 : v ≠ 0 := norm_ne_zero_iff.mp (by rw [hv]; norm_num) + have hrz : (InnerProductSpace.rankOne ℂ v v) = 0 := by + ext w; simpa using congrFun (congrArg DFunLike.coe hz) w + rw [InnerProductSpace.rankOne_eq_zero] at hrz + tauto + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SchumacherConverse.lean b/LeanPool/AxQM/Postulates/API/SchumacherConverse.lean new file mode 100644 index 0000000000..0dca3009d2 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SchumacherConverse.lean @@ -0,0 +1,174 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherConverse +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumDataCompression + +/-! +# AxQM.Postulates.API — the converse part of Schumacher's theorem (N&C Thm 12.6) + +The **converse (optimality) half** of Nielsen & Chuang's quantum noiseless channel coding theorem +(Theorem 12.6): for an i.i.d. quantum source `ρ : State S`, if the (qubit) rate `R ≥ 0` is *below* +the source entropy, `R < S(ρ)` (in nats: `R * log 2 < ρ.vonNeumannEntropy`), then `ρ` is **not** +reliably compressible at rate `R` — no family of rate-`R` schemes can drive the entanglement +fidelity for `ρ^⊗n` to `1` (`¬ ContinuousLinearMap.ReliablyCompressible ρ.op R`). + +## The construction (N&C Eqs. 12.54–12.58) + +Two established facts are combined: + +* **Fidelity bound** (`QuantumCompressionScheme.fidelity_le` in `ToMathlib`, + N&C Eqs. 12.54–12.58): for a single block length, if *every* orthogonal projector `P` onto a + subspace of dimension `≤ 2^numBits` carries only weight `re tr(P ρ^⊗n) ≤ δ` of the source, then + the scheme's entanglement fidelity is `≤ δ`. +* **Small-subspace bound** (typical subspace theorem, part (3), N&C Eq. 12.45): for a rate + `R' < S(ρ)`, for large `n`, every projective two-outcome measurement `M` whose `true`-projector + has rank `≤ exp(n R')` has Born probability `M.bornProb (ρ^⊗n) true ≤ δ`. Here it is derived from + `State.exists_weights_bornProb_true` (the eigenbasis-diagonal weighted-mass reduction) fed into + the classical weighted small-set bound `Real.exists_sum_weighted_prod_le_of_sum_le_exp`, exactly + as the direct part derives part (1). The same statement is `State.smallSubspace_bornProb_le` in + `LeanPool/AxQM/NC/Ch12/Theorem5.lean`. + +The bridge between them is `Measurement.ofStarProjection` (the general two-outcome projector +measurement, in `AxQM/Postulates/API/MeasurementModel.lean`): an arbitrary orthogonal (star) +projector `P` is packaged as the two-outcome von Neumann measurement `{P, 1 − P}`, whose +`true`-projector is `P`, whose `trueSubspaceDim` is `finrank (range P)`, and whose Born probability +is `re tr(P ρ^⊗n)`. +With the rate identified as `R' = R * log 2` (so `R' < S(ρ)` is the hypothesis and, since `R ≥ 0`, +`2^{⌊nR⌋} ≤ 2^{nR} = exp(n R')` bounds the rank), the small-subspace bound supplies exactly +`fidelity_le`'s hypothesis, forcing `F(ρ^⊗n, Dₙ∘Cₙ) ≤ δ` for every `δ` and large `n`; a family +whose fidelity also tends to `1` is impossible. + +## Fidelity to N&C: the rate is non-negative + +N&C's rate `R` is a number of qubits per symbol and is implicitly `R ≥ 0`; the hypothesis carries +`0 ≤ R`. This is *necessary*, not a weakening: for a pure source (`S(ρ) = 0`) the state `ρ^⊗n` is +deterministic and can be recovered perfectly from a one-dimensional compressed space, so a +*negative* rate `R` (the only way `R * log 2 < 0 = S(ρ)` can hold) makes the source reliably +compressible and the converse false. Restricting to the physical rate domain `R ≥ 0` — under which +N&C's `R < S` is `R * log 2 < S(ρ)` in nats — is the faithful statement; with it the proof is +uniform (`R' = R log 2`, no case split). The direct part needs no such hypothesis: there +`S(ρ) < R * log 2` with `S(ρ) ≥ 0` already forces `R > 0`. + +## Main results + +* `State.re_trace_smallSubspace_le` — the typical subspace theorem part (3) in the *operator form* + `QuantumCompressionScheme.fidelity_le` consumes: for `R' < S(ρ)`, for large `n`, every orthogonal + projector `P` on `(S ^⊗ₛ n).space` of rank `≤ exp(n R')` carries weight `re tr(P ρ^⊗n) ≤ δ`. +* `State.not_reliablyCompressible_of_lt_vonNeumannEntropy` — **the converse part of Theorem 12.6**: + `0 ≤ R → R * log 2 < ρ.vonNeumannEntropy → ¬ ReliablyCompressible ρ.op R`. + +The general two-outcome projector measurement `Measurement.ofStarProjection` used as the bridge +is defined beside its sibling `Measurement.ofOrthonormalBasisFiber` in +`AxQM/Postulates/API/MeasurementModel.lean`. The direct part is in +`AxQM/Postulates/API/SchumacherDirect.lean`; the iff of Theorem 12.6 is assembled from the two +halves in `LeanPool/AxQM/NC/Ch12/Theorem6.lean`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.54)–(12.58)). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace Filter + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The small-subspace weight bound in operator form -/ + +/-- **Small-subspace weight bound, operator form** (Nielsen & Chuang, Theorem 12.5, part (3), Eq. +12.45 — the hypothesis `QuantumCompressionScheme.fidelity_le` consumes). Fix a rate +`R' < S(ρ) = H(λ)`. For any `δ > 0`, for all sufficiently large `n`, *every* orthogonal projector +`P` on `(S ^⊗ₛ n).space` of rank `≤ exp(n R')` carries source weight `re tr(P ρ^⊗n) ≤ δ`. + +The projector `P` is packaged as the two-outcome von Neumann measurement `{P, 1 − P}` +(`Measurement.ofStarProjection`), so `re tr(P ρ^⊗n)` is its Born probability +(`bornProb_ofStarProjection_true`), `rank P = trueSubspaceDim` is its `true`-subspace dimension, and +`State.exists_weights_bornProb_true` rewrites the Born probability as the classical *weighted* mass +`∑_κ w κ · ∏ᵢ λ(κᵢ)` with `∑_κ w κ = rank P ≤ exp(n R')`; the classical weighted small-set bound +`Real.exists_sum_weighted_prod_le_of_sum_le_exp` (applied to `λ = ρ.eigenvalueDist`, `H(λ) = S(ρ)`) +then forces it below `δ`. This is the same statement as `State.smallSubspace_bornProb_le`, derived +from the same kernel. -/ +theorem State.re_trace_smallSubspace_le (ρ : State S) {R' : ℝ} + (hR' : R' < Real.entropy ρ.eigenvalueDist) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, ∀ n ≥ N, ∀ P : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space, IsStarProjection P → + (Module.finrank ℂ (LinearMap.range (P : (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space)) : ℝ) + ≤ Real.exp ((n : ℝ) * R') → + RCLike.re ((LinearMap.trace ℂ (S ^⊗ₛ n).space) + ((P.comp (ρ.tensorPow n).op : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space) : + (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space)) ≤ δ := by + obtain ⟨N, _, hN⟩ := Real.exists_sum_weighted_prod_le_of_sum_le_exp + ρ.eigenvalueDist_nonneg ρ.eigenvalueDist_sum_eq_one hR' hδ + refine ⟨N, fun n hn P hP hfin => ?_⟩ + rw [← Measurement.bornProb_ofStarProjection_true P hP (ρ.tensorPow n)] + obtain ⟨w, hw0, hw1, hwsum, hbpeq⟩ := ρ.exists_weights_bornProb_true n + (Measurement.ofStarProjection P hP) (Measurement.isProjective_ofStarProjection P hP) + rw [hbpeq] + refine hN n hn w hw0 hw1 ?_ + rw [hwsum] + exact hfin + +/-! ### The converse: a below-entropy rate is not reliable -/ + +/-- **The converse part of Schumacher's noiseless channel coding theorem** (Nielsen & Chuang, +Theorem 12.6, Eqs. 12.54–12.58). For a non-negative (qubit) rate `R` below the source entropy, +`R < S(ρ)` (in nats: `R * log 2 < ρ.vonNeumannEntropy`), the source `ρ` is **not** reliably +compressible at rate `R`: no family of rate-`R` schemes has entanglement fidelity for `ρ^⊗n` tending +to `1`. + +The hypothesis `0 ≤ R` is the physical rate domain and is necessary (a pure source is reliably +compressible at every rate, including negative ones). For large `n`, the fidelity bound +`QuantumCompressionScheme.fidelity_le` reduces reliability to the small-subspace weight bound +(`State.re_trace_smallSubspace_le` at rate `R log 2 < S(ρ)`): every rank-`≤ 2^{⌊nR⌋}` projector `P` +has `re tr(P ρ^⊗n) ≤ 1/2`, because `2^{⌊nR⌋} ≤ 2^{nR} = exp(n · R log 2)` (using `R ≥ 0`). Hence +`(sch n).fidelity (ρ^⊗n) ≤ 1/2` eventually, contradicting a fidelity tending to `1`. -/ +theorem State.not_reliablyCompressible_of_lt_vonNeumannEntropy (ρ : State S) {R : ℝ} + (hR0 : 0 ≤ R) (hR : R * Real.log 2 < ρ.vonNeumannEntropy) : + ¬ ContinuousLinearMap.ReliablyCompressible ρ.op R := by + rintro ⟨sch, hlim⟩ + have hR' : R * Real.log 2 < Real.entropy ρ.eigenvalueDist := by + rw [← ρ.vonNeumannEntropy_eq_entropy_eigenvalueDist]; exact hR + obtain ⟨N, hbound⟩ := ρ.re_trace_smallSubspace_le hR' (show (0 : ℝ) < 1 / 2 by norm_num) + -- Eventually the fidelity is `≤ 1/2`, via `fidelity_le` fed by the small-subspace bound. + have hle : ∀ᶠ n in atTop, + (sch n).fidelity (PiTensorProduct.mapCLM fun _ : Fin n => ρ.op) ≤ 1 / 2 := by + rw [eventually_atTop] + refine ⟨N, fun n hn => ?_⟩ + -- `fidelity_le` unifies its `(sch n).fidelity (ρ.tensorPow n).op` conclusion against the + -- `PiTensorProduct.mapCLM`-shaped goal up to defeq (`(ρ.tensorPow n).op = mapCLM …` is `rfl`). + refine ContinuousLinearMap.QuantumCompressionScheme.fidelity_le (sch n) + (ρ.tensorPow n).isDensity (fun P hP hrank => ?_) + -- The rank of `P` is `≤ exp(n · R log 2)`: `2^{⌊nR⌋} ≤ 2^{nR} = exp(n · R log 2)`. + refine hbound n hn P hP ?_ + have hnR : 0 ≤ (n : ℝ) * R := mul_nonneg (Nat.cast_nonneg n) hR0 + have hexp : ((2 : ℝ) ^ ⌊(n : ℝ) * R⌋₊) ≤ Real.exp ((n : ℝ) * (R * Real.log 2)) := by + calc ((2 : ℝ) ^ ⌊(n : ℝ) * R⌋₊) + = (2 : ℝ) ^ ((⌊(n : ℝ) * R⌋₊ : ℝ)) := by rw [Real.rpow_natCast] + _ ≤ (2 : ℝ) ^ ((n : ℝ) * R) := + Real.rpow_le_rpow_of_exponent_le (by norm_num) (Nat.floor_le hnR) + _ = Real.exp ((n : ℝ) * (R * Real.log 2)) := by + rw [Real.rpow_def_of_pos (by norm_num)]; congr 1; ring + exact le_trans (by exact_mod_cast hrank) hexp + -- A reliable family has fidelity `> 1/2` eventually, contradicting `hle`. + have h1 : ∀ᶠ n in atTop, + (1 : ℝ) / 2 < (sch n).fidelity (PiTensorProduct.mapCLM fun _ : Fin n => ρ.op) := + hlim.eventually_const_lt (by norm_num) + obtain ⟨n, hn1, hn2⟩ := (h1.and hle).exists + linarith + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SchumacherDirect.lean b/LeanPool/AxQM/Postulates/API/SchumacherDirect.lean new file mode 100644 index 0000000000..d6c5f9eb93 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SchumacherDirect.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherCompression +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelityBound +public import LeanPool.AxQM.ToMathlib.InformationTheory.NoiselessCoding + +/-! +# AxQM.Postulates.API — the direct part of Schumacher's theorem (N&C Thm 12.6) + +The **direct (achievability) half** of Nielsen & Chuang's quantum noiseless channel coding theorem +(Theorem 12.6): for an i.i.d. quantum source `ρ : State S`, if `S(ρ) < R` (in nats, +`ρ.vonNeumannEntropy < R * log 2`, with `R` a qubit rate) then `ρ` is **reliably compressible at +rate `R`** — there is a family of rate-`R` quantum compression schemes whose entanglement fidelity +for `ρ^⊗n` tends to `1` (`ContinuousLinearMap.ReliablyCompressible ρ.op R`). + +## The construction (N&C Eqs. 12.50–12.53) + +At each block length `n` the scheme is Schumacher's **projection–reset** scheme +(`QuantumCompressionScheme.projectionReset`) built on the ε-typical subspace projector `P(n, ε)` +(`State.typicalSubspaceProj`), for a fixed `ε` with `S(ρ) + ε < R * log 2`: + +* the compression `Cₙ` is the projection–reset encoder onto the span of the ε-typical product + eigenvectors of `ρ^⊗n`, the decompression `Dₙ` is the identity; +* the compressed subspace is the ε-typical subspace `T(n, ε)`, of dimension `|T(n, ε)|`. + +Two facts drive reliability, both already established: + +* **Rate.** For large `n` the ε-typical set has `|T(n, ε)| ≤ 2^{⌊nR⌋}` + (`Real.exists_card_typicalSeq_le_two_pow`, the classical theorem of typical sequences applied to + the eigenvalue distribution `λ = ρ.eigenvalueDist`, whose entropy is `S(ρ)`), so the scheme really + compresses into `⌊nR⌋` qubits. +* **Fidelity.** The projection–reset fidelity dominates the code overlap, + `F(ρ^⊗n, Dₙ ∘ Cₙ) ≥ |tr(ρ^⊗n P(n, ε))|²` (`projectionReset_fidelity_ge`, N&C Eq. 12.52), and + `tr(ρ^⊗n P(n, ε))` is the Born probability of landing in the typical subspace, which tends to `1` + (`State.typicalSubspaceMeasurement_bornProb_true` + `Real.exists_le_sum_typicalSeq`, part (1)). + Together with the universal upper bound `F ≤ 1` (`entanglementFidelity_le_one`) a squeeze gives + `F(ρ^⊗n, Dₙ ∘ Cₙ) → 1`. + +For the finitely many small `n` where the ε-typical set is empty or already too large, the family +falls back to a trivial single-vector scheme; the reliability limit only sees the tail, so the +fallback is irrelevant. + +## Main results + +* `State.bornProb_typicalSubspace_le_norm_trace` — the Born probability of the typical subspace is + `≤ ‖tr(ρ^⊗n P(n, ε))‖` (the bridge from `re tr(P ρ)` to `‖tr(ρ P)‖`), so squaring turns N&C's + part (1) probability bound into the fidelity lower bound of Eq. (12.52). +* `State.bornProb_typicalSubspace_tendsto_one` — the typical-subspace Born probability tends to `1` + (N&C part (1), asymptotic form). +* `State.reliablyCompressible_of_vonNeumannEntropy_lt` — **the direct part of Theorem 12.6**: + `ρ.vonNeumannEntropy < R * log 2 → ReliablyCompressible ρ.op R`. + +The iff `ReliablyCompressible ↔ S(ρ) < R` of Theorem 12.6 is assembled from this direct half and +the converse (`AxQM/Postulates/API/SchumacherConverse.lean`) in +`LeanPool/AxQM/NC/Ch12/Theorem6.lean`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.50)–(12.53)). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace Filter + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The typical-subspace Born probability is bounded by the code-overlap trace norm.** The +probability that `ρ^⊗n` lands in the ε-typical subspace, `tr(P(n, ε) ρ^⊗n)`, is at most +`‖tr(ρ^⊗n P(n, ε))‖` — the quantity squared in Schumacher's fidelity lower bound (N&C Eq. 12.52). + +The Born probability is `re tr(P† P ρ^⊗n) = re tr(P ρ^⊗n)` (`bornProb_eq_re_trace_postOp`, +`trace_postOp`, and `orthonormalProjector_adjoint_comp_self` collapsing `P† P = P`); the real +part of a complex number is at most its norm (`RCLike.re_le_norm`), and cyclicity of the trace +(`LinearMap.trace_comp_comm'`) identifies `‖tr(P ρ^⊗n)‖` with `‖tr(ρ^⊗n P)‖`. -/ +theorem State.bornProb_typicalSubspace_le_norm_trace (ρ : State S) (n : ℕ) (ε : ℝ) : + (ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true + ≤ ‖LinearMap.trace ℂ (S ^⊗ₛ n).space + (((ρ.tensorPow n).op * ρ.typicalSubspaceProj n ε : + (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space) : + (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space)‖ := by + rw [Measurement.bornProb_eq_re_trace_postOp, ContinuousLinearMap.trace_postOp, + State.typicalSubspaceMeasurement_op_true, State.typicalSubspaceProj, + ← ContinuousLinearMap.comp_assoc, + InnerProductSpace.orthonormalProjector_adjoint_comp_self + (ρ.tensorPowEigenbasis n).orthonormal] + refine le_trans (RCLike.re_le_norm _) (le_of_eq ?_) + congr 1 + rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.toLinearMap_comp, + ContinuousLinearMap.toLinearMap_comp, LinearMap.trace_comp_comm'] + +/-- **The typical-subspace Born probability tends to `1`** (Nielsen & Chuang, Theorem 12.5, +part (1), asymptotic form): fix `ε > 0`; then the probability that `ρ^⊗n` lands in the ε-typical +subspace, +`tr(P(n, ε) ρ^⊗n)`, tends to `1` as `n → ∞`. The probability is `≥ 1 − δ` for large `n` for every +`δ` (`Real.exists_le_sum_typicalSeq` applied to `λ = ρ.eigenvalueDist`, rewritten by the Born +identity `typicalSubspaceMeasurement_bornProb_true`) and is always `≤ 1` (`bornProb_le_one`). -/ +theorem State.bornProb_typicalSubspace_tendsto_one (ρ : State S) {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun n => (ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true) + atTop (nhds 1) := by + rw [Metric.tendsto_atTop] + intro η hη + obtain ⟨N, _, hN⟩ := Real.exists_le_sum_typicalSeq ρ.eigenvalueDist_nonneg + ρ.eigenvalueDist_sum_eq_one hε (half_pos hη) + refine ⟨N, fun n hn => ?_⟩ + have hle1 := Measurement.bornProb_le_one (ρ.typicalSubspaceMeasurement n ε) (ρ.tensorPow n) true + have hge := hN n hn + rw [← ρ.typicalSubspaceMeasurement_bornProb_true] at hge + rw [Real.dist_eq, abs_sub_comm, abs_of_nonneg (by linarith)] + linarith + +/-- **The direct part of Schumacher's noiseless channel coding theorem** (Nielsen & Chuang, Theorem +12.6, Eqs. 12.50–12.53). If the von Neumann entropy of the source is below the rate, +`S(ρ) < R` (in nats: `ρ.vonNeumannEntropy < R * log 2`, `R` a qubit rate), then `ρ` is **reliably +compressible at rate `R`**: there is a family of rate-`R` quantum compression schemes whose +entanglement fidelity for `ρ^⊗n` tends to `1`. + +The witness is Schumacher's projection–reset scheme on the ε-typical subspace for a fixed `ε` with +`S(ρ) + ε < R * log 2`. For large `n` the ε-typical set is nonempty and has cardinality `≤ 2^{⌊nR⌋}` +(`Real.exists_card_typicalSeq_le_two_pow` / `Real.exists_le_sum_typicalSeq` on `λ = +ρ.eigenvalueDist`), so the projection–reset scheme is well-defined; its fidelity dominates +`|tr(ρ^⊗n P(n, ε))|²` (`projectionReset_fidelity_ge`), the Born probability squared, which tends to +`1` (`bornProb_typicalSubspace_tendsto_one`). Together with `F ≤ 1` +(`entanglementFidelity_le_one`) a squeeze forces `F → 1`. Small `n` outside the good range use a +trivial fallback scheme, invisible to the limit. -/ +theorem State.reliablyCompressible_of_vonNeumannEntropy_lt (ρ : State S) {R : ℝ} + (hR : ρ.vonNeumannEntropy < R * Real.log 2) : + ContinuousLinearMap.ReliablyCompressible ρ.op R := by + classical + -- `S.space` is nonzero (a density operator has trace `1`), so the eigenbasis index type is + -- nonempty — needed for the fallback scheme's reference vector. + have hNE : Nonempty (Fin (Module.finrank ℂ S.space)) := by + have := ρ.nontrivial_space + exact ⟨⟨0, Module.finrank_pos⟩⟩ + -- Pick `ε > 0` with `S(ρ) + ε < R log 2`. + obtain ⟨ε, hε, hεR⟩ : ∃ ε, 0 < ε ∧ ρ.vonNeumannEntropy + ε < R * Real.log 2 := + ⟨(R * Real.log 2 - ρ.vonNeumannEntropy) / 2, by linarith, by linarith⟩ + have hεR' : Real.entropy ρ.eigenvalueDist + ε < R * Real.log 2 := by + rw [← ρ.vonNeumannEntropy_eq_entropy_eigenvalueDist]; exact hεR + -- The "good" range: for large `n` the ε-typical set is nonempty with cardinality `≤ 2^{⌊nR⌋}`. + obtain ⟨Ncard, hNcard⟩ := Real.exists_card_typicalSeq_le_two_pow ρ.eigenvalueDist + ρ.eigenvalueDist_nonneg ρ.eigenvalueDist_sum_eq_one hεR' + obtain ⟨Nne, _, hNne⟩ := Real.exists_le_sum_typicalSeq ρ.eigenvalueDist_nonneg + ρ.eigenvalueDist_sum_eq_one hε (by norm_num : (0:ℝ) < 1 / 2) + have hgood : ∀ n ≥ max Ncard Nne, + (Real.typicalSeq ρ.eigenvalueDist n ε).Nonempty ∧ + (Real.typicalSeq ρ.eigenvalueDist n ε).card ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ := by + intro n hn + refine ⟨?_, hNcard n (le_trans (le_max_left _ _) hn)⟩ + rw [Finset.nonempty_iff_ne_empty] + intro he + have := hNne n (le_trans (le_max_right _ _) hn) + rw [he, Finset.sum_empty] at this + linarith + -- The scheme family: the projection–reset scheme on the good range, a trivial fallback otherwise. + set sch : (n : ℕ) → QuantumCompressionScheme (⨂[ℂ] (_ : Fin n), S.space) ⌊(n : ℝ) * R⌋₊ := + fun n => + if h : (Real.typicalSeq ρ.eigenvalueDist n ε).Nonempty ∧ + (Real.typicalSeq ρ.eigenvalueDist n ε).card ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ then + QuantumCompressionScheme.projectionReset (ρ.tensorPowEigenbasis n) + (Real.typicalSeq ρ.eigenvalueDist n ε) h.1.choose h.1.choose_spec h.2 + else + QuantumCompressionScheme.projectionReset (ρ.tensorPowEigenbasis n) + {fun _ => hNE.some} (fun _ => hNE.some) (Finset.mem_singleton_self _) + (by rw [Finset.card_singleton]; exact Nat.one_le_two_pow) with hsch + refine ⟨sch, ?_⟩ + -- Upper bound: the entanglement fidelity is always `≤ 1`. + have hle_one : ∀ n, (sch n).fidelity (PiTensorProduct.mapCLM fun _ : Fin n => ρ.op) ≤ 1 := by + intro n + have hop : (PiTensorProduct.mapCLM fun _ : Fin n => ρ.op) = (ρ.tensorPow n).op := rfl + rw [hop] + unfold QuantumCompressionScheme.fidelity + exact ContinuousLinearMap.entanglementFidelity_le_one (ρ.tensorPow n).isDensity _ + (sch n).composite_isTracePreserving + -- Lower bound (eventually): the fidelity dominates the squared Born probability. + have hbp : Tendsto + (fun n => ((ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true) ^ 2) + atTop (nhds 1) := by + simpa using (ρ.bornProb_typicalSubspace_tendsto_one hε).pow 2 + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' hbp tendsto_const_nhds ?_ + (Eventually.of_forall hle_one) + rw [eventually_atTop] + refine ⟨max Ncard Nne, fun n hn => ?_⟩ + obtain ⟨hne, hcard⟩ := hgood n hn + have hsch_n : sch n = QuantumCompressionScheme.projectionReset (ρ.tensorPowEigenbasis n) + (Real.typicalSeq ρ.eigenvalueDist n ε) hne.choose hne.choose_spec hcard := by + simp only [hsch] + exact dite_eq_left ⟨hne, hcard⟩ + have hfge := QuantumCompressionScheme.projectionReset_fidelity_ge (ρ.tensorPowEigenbasis n) + (Real.typicalSeq ρ.eigenvalueDist n ε) hne.choose hne.choose_spec hcard ((ρ.tensorPow n).op) + calc ((ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true) ^ 2 + ≤ ‖LinearMap.trace ℂ (S ^⊗ₛ n).space + (((ρ.tensorPow n).op * ρ.typicalSubspaceProj n ε : + (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space) : + (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space)‖ ^ 2 := + pow_le_pow_left₀ (Measurement.bornProb_nonneg _ _ _) + (ρ.bornProb_typicalSubspace_le_norm_trace n ε) 2 + _ ≤ (sch n).fidelity (PiTensorProduct.mapCLM fun _ : Fin n => ρ.op) := by + rw [hsch_n]; exact hfge + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SquareRootMeasurement.lean b/LeanPool/AxQM/Postulates/API/SquareRootMeasurement.lean new file mode 100644 index 0000000000..a5dc61c8a4 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SquareRootMeasurement.lean @@ -0,0 +1,118 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Uhlmann + +/-! +# The square-root measurement realising a POVM (the `POVM → Measurement` bridge) + +A `Measurement ι S` stores *measurement operators* `Mᵢ` together with the +completeness relation `∑ᵢ Mᵢ† Mᵢ = 1`; its induced POVM `toPOVM` has effects `Eᵢ = Mᵢ† Mᵢ` +(`Measurement.toPOVM`). Going the other way — realising a *given* POVM `{Eᵢ}` (positive effects +summing to `1`) as an actual measurement — requires choosing measurement operators `Mᵢ` with +`Mᵢ† Mᵢ = Eᵢ`. The **canonical** such choice is `Mᵢ = √Eᵢ`, the operator square root +(`cfc Real.sqrt Eᵢ`): it is self-adjoint (`(√Eᵢ)† = √Eᵢ`) and squares back to the effect +(`√Eᵢ · √Eᵢ = Eᵢ` for `Eᵢ ≥ 0`), so `Mᵢ† Mᵢ = Eᵢ` and completeness `∑ᵢ √Eᵢ† √Eᵢ = ∑ᵢ Eᵢ = 1` +transports directly from the POVM. This is the **square-root (or "pretty-good") measurement** +of `{Eᵢ}`. + +`Measurement.ofPOVM` records this bridge, the partial inverse of `Measurement.toPOVM` +(`toPOVM (ofPOVM P) = P`). It is the missing constructor needed to turn a family of positive +effects back into a postulate `Measurement`, used in the achievability half of the +**Holevo–Schumacher–Westmoreland theorem** (`χ(E) = C⁽¹⁾(E)`, Nielsen & Chuang Theorem 12.8) to +build the pretty-good decoding POVM `{Eₘ}` (N&C eq. (12.78)) as a genuine measurement, and to +supply the "junk" element `√(1 − ∑ Eₘ)` completing a sub-code's POVM after expurgation. + +## What this file provides + +* `AxQM.Measurement.ofPOVM` — the square-root measurement `Mᵢ = √Eᵢ` of a POVM `P`. +* `AxQM.Measurement.ofPOVM_op` — its operators, `(ofPOVM P).op i = √(P.elements i)`. +* `AxQM.Measurement.toPOVM_ofPOVM` — the round-trip `(ofPOVM P).toPOVM = P`: the + square-root measurement induces exactly the POVM it was built from. +* `AxQM.Measurement.ofPOVM_bornProb` / `ofPOVM_bornProb_eq_re_trace` — its Born rule is the + POVM Born rule, `p(i) = P.toPMF ρ = re tr(Eᵢ ρ)`. + +The other `Measurement` constructors are in `Postulates.API.MeasurementModel`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-- **The operator square root squares back through the adjoint**: for a positive operator `A ≥ 0` +on a complex Hilbert space, `(√A)† √A = A`, where `√A = cfc Real.sqrt A`. Since `√A` is +self-adjoint (`adjoint_cfc_real_sqrt`) this is `√A · √A = A`, the C⋆-algebra square-root identity +`cfc_real_sqrt_mul_self_of_nonneg`. The completeness datum of the square-root measurement +`Measurement.ofPOVM`. -/ +private theorem cfc_real_sqrt_adjoint_comp_self {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [CompleteSpace E] {A : E →L[ℂ] E} (hA : 0 ≤ A) : + (ContinuousLinearMap.adjoint (cfc Real.sqrt A)).comp (cfc Real.sqrt A) = A := by + rw [ContinuousLinearMap.adjoint_cfc_real_sqrt, ← ContinuousLinearMap.mul_def, + cfc_real_sqrt_mul_self_of_nonneg hA] + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +/-- **The square-root ("pretty-good") measurement realising a POVM** `P` on the system `S`: the +measurement whose operators are the operator square roots of the POVM's effects, +`Mᵢ = √Eᵢ = cfc Real.sqrt (P.elements i)`. Completeness `∑ᵢ Mᵢ† Mᵢ = ∑ᵢ Eᵢ = 1` holds because each +`√Eᵢ` is self-adjoint and `√Eᵢ · √Eᵢ = Eᵢ` (`cfc_real_sqrt_adjoint_comp_self`), reducing the sum to +the POVM's own `∑ᵢ Eᵢ = 1`. This is the canonical partial inverse of `Measurement.toPOVM` +(`toPOVM_ofPOVM`), turning a family of positive effects back into a postulate `Measurement`. -/ +def Measurement.ofPOVM (P : POVM ι ℂ S.space) : Measurement ι S where + op i := cfc Real.sqrt (P.elements i) + complete := by + calc ∑ i, (ContinuousLinearMap.adjoint (cfc Real.sqrt (P.elements i))).comp + (cfc Real.sqrt (P.elements i)) + = ∑ i, P.elements i := + Finset.sum_congr rfl fun i _ => + cfc_real_sqrt_adjoint_comp_self + ((ContinuousLinearMap.nonneg_iff_isPositive).mpr (P.isPositive i)) + _ = 1 := P.sum_eq_one + +@[simp] +theorem Measurement.ofPOVM_op (P : POVM ι ℂ S.space) (i : ι) : + (Measurement.ofPOVM P).op i = cfc Real.sqrt (P.elements i) := rfl + +/-- **Round-trip**: the square-root measurement of a POVM induces exactly that POVM, +`(ofPOVM P).toPOVM = P`. Each induced effect is `(√Eᵢ)† √Eᵢ = Eᵢ` +(`cfc_real_sqrt_adjoint_comp_self`), so the two POVMs agree on all effects (`POVM.ext`). Thus +`Measurement.ofPOVM` is a genuine section of `Measurement.toPOVM`. -/ +@[simp] +theorem Measurement.toPOVM_ofPOVM (P : POVM ι ℂ S.space) : + (Measurement.ofPOVM P).toPOVM = P := by + refine POVM.ext (funext fun i => ?_) + rw [Measurement.toPOVM_elements, Measurement.ofPOVM_op] + exact cfc_real_sqrt_adjoint_comp_self + ((ContinuousLinearMap.nonneg_iff_isPositive).mpr (P.isPositive i)) + +/-- **Born rule of the square-root measurement**: measuring `ofPOVM P` on a state `ρ` gives outcome +`i` with the POVM's own Born probability, `(ofPOVM P).bornProb ρ i = P.toPMF ρ`. Immediate from the +round-trip `toPOVM_ofPOVM`, since `bornProb` is by definition the induced POVM's `toPMF`. -/ +theorem Measurement.ofPOVM_bornProb (P : POVM ι ℂ S.space) (ρ : State S) (i : ι) : + (Measurement.ofPOVM P).bornProb ρ i = P.toPMF ρ.op i := by + rw [Measurement.bornProb, Measurement.toPOVM_ofPOVM] + +/-- **Born rule of the square-root measurement, trace form**: `p(i) = re tr(Eᵢ ρ)`, the standard +POVM Born rule for the effect `Eᵢ = P.elements i`. Combines `ofPOVM_bornProb` with the POVM Born +rule `POVM.toPMF_eq`. -/ +theorem Measurement.ofPOVM_bornProb_eq_re_trace (P : POVM ι ℂ S.space) (ρ : State S) (i : ι) : + (Measurement.ofPOVM P).bornProb ρ i + = RCLike.re ((LinearMap.trace ℂ S.space) + ((P.elements i).comp ρ.op : S.space →ₗ[ℂ] S.space)) := by + rw [Measurement.ofPOVM_bornProb, POVM.toPMF_eq] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/StabilizerEvolution.lean b/LeanPool/AxQM/Postulates/API/StabilizerEvolution.lean new file mode 100644 index 0000000000..ff5e4d570b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/StabilizerEvolution.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Eigenstate +public import LeanPool.AxQM.Postulates.API.Evolution + +/-! +# AxQM.Postulates.API — stabilizer evolution under a unitary (N&C Eq. 10.87) + +**Nielsen & Chuang Eq. (10.87)** (§10.5.2, p. 459), the foundational equation of the stabilizer +description of unitary dynamics and the engine of the Gottesman–Knill theorem (Theorem 10.7): + +for `g ∈ S` stabilizing `|ψ⟩`, `U|ψ⟩ = UgU† U|ψ⟩`, so the evolved state is stabilized by `UgU†`. + +Concretely: if a pure state `|ψ⟩` is a `μ`-eigenstate of an observable `A` (`A|ψ⟩ = μ|ψ⟩`, in +particular `μ = 1` is "`A` stabilizes `|ψ⟩`"), then the evolved state `U|ψ⟩` +(`Evolution.evolvePure`) is a `μ`-eigenstate of the **conjugated observable** `U A U†` +(`Observable.conjByEvolution`). Applied to `A = g` a stabilizer generator (`μ = 1`), this is exactly +"`U|ψ⟩` is stabilized by `U g U†`": a unitary transforms the stabilizer of a state by conjugating +its generators. The Gottesman–Knill theorem specializes this to the case where `U` is a Clifford +(normalizer) gate, for which `U g U†` is again a Pauli-group element computed *classically* — see +the check-matrix form +`AxQM.Concrete.CliffordCircuit.updatedGenerator_mulVec_toMatrix_mulVec`. + +* `Observable.conjByEvolution` — the observable `U A U†` (self-adjoint by + `IsSelfAdjoint.conjugate`), with the formula for its + underlying operator `conjByEvolution_op`. +* `Observable.HasEigenstate.conjByEvolution_evolvePure` — Eq. (10.87) at a general eigenvalue. +* `Observable.HasEigenstate.conjByEvolution_evolvePure_one` — the stabilizer case (`μ = 1`), + "`U|ψ⟩` is stabilized by `U g U†`". + +The statement of Theorem 10.7 (classical simulability) is in +[upstream `AxQM/NC/Ch10/Theorem10_7_GottesmanKnill.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Theorem10_7_GottesmanKnill.lean). +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace Observable + +/-- **Conjugation of an observable by a unitary evolution** (N&C §10.5.2): the observable `U A U†`, +where `U` is a unitary `Evolution` and `A` an `Observable`. Self-adjoint because conjugation of a +self-adjoint element by any element preserves self-adjointness (`IsSelfAdjoint.conjugate`, using +`A† = A`). The observable whose eigenstates track those of `A` under the evolution `U`. -/ +def conjByEvolution (A : Observable S) (U : Evolution S) : Observable S where + op := U.op * A.op * star U.op + selfAdjoint := A.selfAdjoint.conjugate U.op + +/-- The underlying operator of `A.conjByEvolution U` is `U A U†` (`= U.op * A.op * star U.op`). -/ +@[simp] +theorem conjByEvolution_op (A : Observable S) (U : Evolution S) : + (A.conjByEvolution U).op = U.op * A.op * star U.op := rfl + +/-- **Nielsen & Chuang Eq. (10.87): unitary evolution transforms the stabilizer by conjugation.** +If `ψ` is a `μ`-eigenstate of the observable `A` (`A|ψ⟩ = μ|ψ⟩`), then the evolved state `U|ψ⟩` +(`U.evolvePure ψ`) is a `μ`-eigenstate of the conjugated observable `U A U†` +(`A.conjByEvolution U`): `(U A U†)(U|ψ⟩) = μ (U|ψ⟩)`. Proof: +`(U A U†)(Uψ) = U A (U†U ψ) = U A ψ = U (μ ψ) = μ (Uψ)`, using unitarity `U†U = 1`. -/ +theorem HasEigenstate.conjByEvolution_evolvePure {A : Observable S} {μ : ℝ} {ψ : PureState S} + (h : A.HasEigenstate μ ψ) (U : Evolution S) : + (A.conjByEvolution U).HasEigenstate μ (U.evolvePure ψ) := by + have hUadjU : star U.op * U.op = 1 := (Unitary.mem_iff.mp U.unitary).1 + have hAψ : A.op ψ.vec = (μ : ℂ) • ψ.vec := h + rw [Observable.HasEigenstate, conjByEvolution_op, Evolution.evolvePure_vec, + mul_apply_eq_comp, mul_apply_eq_comp, + ← mul_apply_eq_comp (star U.op) U.op, hUadjU, + one_apply_eq_self, hAψ, map_smul] + +/-- **N&C Eq. (10.87), the stabilizer case:** if the observable `A` (e.g. a stabilizer generator +`g`) stabilizes `ψ` (`A|ψ⟩ = |ψ⟩`), then `U A U†` stabilizes the evolved state `U|ψ⟩` — "the state +`U|ψ⟩` is stabilized by `U g U†`". The `μ = 1` case of +`HasEigenstate.conjByEvolution_evolvePure`. -/ +theorem HasEigenstate.conjByEvolution_evolvePure_one {A : Observable S} {ψ : PureState S} + (h : A.HasEigenstate 1 ψ) (U : Evolution S) : + (A.conjByEvolution U).HasEigenstate 1 (U.evolvePure ψ) := + h.conjByEvolution_evolvePure U + +end Observable + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/StabilizerMeasurement.lean b/LeanPool/AxQM/Postulates/API/StabilizerMeasurement.lean new file mode 100644 index 0000000000..bf66d60982 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/StabilizerMeasurement.lean @@ -0,0 +1,290 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PauliMeasurement +public import LeanPool.AxQM.Postulates.API.PauliEigen +public import LeanPool.AxQM.Postulates.API.EigenspaceCollapse + +/-! +# AxQM.Postulates.API — measurement in the stabilizer formalism (N&C §10.5.3) + +The update rules for **measuring a Pauli-group observable on a stabilizer state**, +the content of Nielsen & Chuang §10.5.3 (pp. 463–464) that the Gottesman–Knill theorem (Theorem +10.7) turns into a classical-simulation step. A Pauli-group element `g` (a product of Pauli +matrices, no `±1`/`±i` phase) is a self-adjoint **involution** `g² = I` — a `±1` observable — so +its projective measurement is the `Observable.signMeasurement` of `Postulates/API/PauliMeasurement` +(outcome `0 ↔ +1`, `1 ↔ −1`). Given a state `|ψ⟩` with stabilizer `⟨g₁, …, gₙ⟩`, N&C split the +measurement of such a `g` into two cases. + +## The deterministic case: `g` (or `−g`) is in the stabilizer + +If `g` commutes with all generators then either `g` or `−g` is in the stabilizer. N&C treat both +sub-outcomes; both are formalised here. + +*Sub-case `g ∈ S` (`g|ψ⟩ = |ψ⟩`, `A.HasEigenstate 1 ψ`):* outcome `+1` is certain and the state is +undisturbed — + +* `bornProb_signMeasurement_plus_of_hasEigenstate_one` — `p(+1) = 1`; +* `bornProb_signMeasurement_minus_of_hasEigenstate_one` — `p(−1) = 0`; +* `postMeasPlus_eq_of_hasEigenstate_one` — the collapse `P₊|ψ⟩/‖P₊|ψ⟩‖` equals `|ψ⟩`. + +*Sub-case `−g ∈ S` (`g|ψ⟩ = −|ψ⟩`, `A.HasEigenstate (-1) ψ`):* the mirror, outcome `−1` certain and +undisturbed — + +* `bornProb_signMeasurement_minus_of_hasEigenstate_neg_one` — `p(−1) = 1`; +* `bornProb_signMeasurement_plus_of_hasEigenstate_neg_one` — `p(+1) = 0`; +* `postMeasMinus_eq_of_hasEigenstate_neg_one` — the collapse `P₋|ψ⟩/‖P₋|ψ⟩‖` equals `|ψ⟩`. + +This is N&C's "a measurement of `g` yields `+1` with probability one … does not disturb the state … +leaves the stabilizer invariant", together with "if instead `−g ∈ S` … yields `−1` with probability +one, and again does not disturb the state". + +## The random case: `g` anticommutes with a stabilizer generator + +If `g` anticommutes with a generator `g₁` with `g₁|ψ⟩ = |ψ⟩`, then (N&C eqs. 10.96–10.100) the two +outcomes are equiprobable: + +* `expectation_eq_zero_of_anticomm_stabilizer` — the engine: `⟪g⟫_ψ = 0`, because + `⟪ψ, gψ⟫ = ⟪ψ, g g₁ ψ⟫ = −⟪ψ, g₁ g ψ⟫ = −⟪g₁ ψ, g ψ⟫ = −⟪ψ, g ψ⟫` (using `g₁|ψ⟩ = |ψ⟩`, `g₁` + self-adjoint and `g g₁ = −g₁ g`), so `⟪ψ, gψ⟫ = −⟪ψ, gψ⟫ = 0`; +* `bornProb_signMeasurement_plus_of_anticomm` — `p(+1) = 1/2`; +* `bornProb_signMeasurement_minus_of_anticomm` — `p(−1) = 1/2`. + +After outcome `+1` (resp. `−1`) the posterior state is a `+1` (resp. `−1`) eigenstate of `g` +(`Observable.postMeasPlus_hasEigenstate` / `postMeasMinus_hasEigenstate`), i.e. it is stabilized by +`g` (resp. `−g`) — the stabilizer's leading generator is replaced by `±g`. + +## Stabilizer preservation + +Any other generator that commutes with `g` and stabilizes `|ψ⟩` still stabilizes the collapsed +state, so the tail `g₂, …, gₙ` of the stabilizer is carried through unchanged: + +* `hasEigenstate_one_postMeasPlus_of_commute`, `hasEigenstate_one_postMeasMinus_of_commute`. + +Together the new stabilizer is `⟨±g, g₂, …, gₙ⟩`, exactly N&C's post-measurement stabilizer. These +lemmas presuppose the surviving generator commutes with `g` — N&C's WLOG normalisation of the +generator set: if some `gₖ` (`k ≥ 2`) anticommutes with `g`, replace it by `g₁ gₖ`, which commutes +with `g` and generates the same group, so that only `g₁` anticommutes. That purely +generator-bookkeeping reduction is not itself formalised here. + +This extends the `±1`-observable measurement family of `PauliMeasurement` / +`EigenspaceCollapse`. The statement of Theorem 10.7 (the classical-simulability statement) is in +[upstream `AxQM/NC/Ch10/Theorem10_7_GottesmanKnill.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch10/Theorem10_7_GottesmanKnill.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace Observable + +/-! ### The deterministic case: the observable already stabilizes `|ψ⟩` -/ + +/-- **N&C §10.5.3 (deterministic outcome).** If a `±1` observable `A` stabilizes `|ψ⟩` +(`A|ψ⟩ = |ψ⟩`, i.e. `A.HasEigenstate 1 ψ`), then measuring `A` yields `+1` with certainty: +`p(+1) = 1`. Immediate from `bornProb_signMeasurement_plus` (`p(+1) = (1 + ⟪A⟫_ψ)/2`) and +`expectation_of_hasEigenstate` (`⟪A⟫_ψ = 1`). -/ +theorem bornProb_signMeasurement_plus_of_hasEigenstate_one (A : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (h : A.HasEigenstate 1 ψ) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = 1 := by + rw [bornProb_signMeasurement_plus, PureState.expectation_of_hasEigenstate h]; norm_num + +/-- **N&C §10.5.3 (deterministic outcome).** If a `±1` observable `A` stabilizes `|ψ⟩`, the outcome +`−1` is impossible: `p(−1) = 0`. From `p(+1) = 1` and `∑ᵢ p(i) = 1`. -/ +theorem bornProb_signMeasurement_minus_of_hasEigenstate_one (A : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (h : A.HasEigenstate 1 ψ) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = 0 := by + have hsum := (A.signMeasurement hinv).sum_bornProb_eq_one ψ.toState + rw [Fin.sum_univ_two, + bornProb_signMeasurement_plus_of_hasEigenstate_one A hinv ψ h] at hsum + linarith + +/-- **N&C §10.5.3 (state undisturbed).** If a `±1` observable `A` stabilizes `|ψ⟩`, the `+1` +collapse leaves the state unchanged: `P₊|ψ⟩/‖P₊|ψ⟩‖ = |ψ⟩`. Here `P₊|ψ⟩ = |ψ⟩` +(`projPlus_apply_eq_self`) and `‖ψ‖ = 1`, so normalization is the identity. This is N&C's "the +measurement does not disturb the state of the system, and thus leaves the stabilizer invariant". -/ +theorem postMeasPlus_eq_of_hasEigenstate_one (A : Observable S) (ψ : PureState S) + (h : A.HasEigenstate 1 ψ) (hne : A.projPlus ψ.vec ≠ 0) : + A.postMeasPlus ψ hne = ψ := by + have hAψ : A.op ψ.vec = ψ.vec := by simpa [Observable.HasEigenstate] using h + apply PureState.ext + rw [postMeasPlus_vec, A.projPlus_apply_eq_self hAψ, ψ.normalized] + simp + +/-- **N&C §10.5.3 (deterministic outcome, `−g ∈ S`).** The mirror sub-case: if a `±1` observable +`A` has `|ψ⟩` as a `−1` eigenstate (`A|ψ⟩ = −|ψ⟩`, i.e. `−A` — equivalently `−g` — stabilizes +`|ψ⟩`), then measuring `A` yields `−1` with certainty: `p(−1) = 1`. From `p(−1) = ‖P₋|ψ⟩‖²` with +`P₋|ψ⟩ = |ψ⟩` (`projMinus_apply_eq_self`) and `‖ψ‖ = 1`. This is N&C's "if instead `−g ∈ S` … +yields `−1` with probability one". -/ +theorem bornProb_signMeasurement_minus_of_hasEigenstate_neg_one (A : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (h : A.HasEigenstate (-1) ψ) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = 1 := by + have hAψ : A.op ψ.vec = -ψ.vec := by simpa [Observable.HasEigenstate] using h + rw [bornProb_signMeasurement_minus_eq_normSq, A.projMinus_apply_eq_self hAψ, ψ.normalized] + norm_num + +/-- **N&C §10.5.3 (deterministic outcome, `−g ∈ S`).** If a `±1` observable `A` has `|ψ⟩` as a `−1` +eigenstate, the outcome `+1` is impossible: `p(+1) = 0`. From `p(+1) = (1 + ⟪A⟫_ψ)/2` and +`⟪A⟫_ψ = −1`. -/ +theorem bornProb_signMeasurement_plus_of_hasEigenstate_neg_one (A : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (h : A.HasEigenstate (-1) ψ) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = 0 := by + rw [bornProb_signMeasurement_plus, PureState.expectation_of_hasEigenstate h]; norm_num + +/-- **N&C §10.5.3 (state undisturbed, `−g ∈ S`).** If `A` has `|ψ⟩` as a `−1` eigenstate, the `−1` +collapse leaves the state unchanged: `P₋|ψ⟩/‖P₋|ψ⟩‖ = |ψ⟩` — the `−1` mirror of +`postMeasPlus_eq_of_hasEigenstate_one`. Completes the deterministic case faithfully to N&C's "and +again does not disturb the state" for the `−g ∈ S` sub-case. -/ +theorem postMeasMinus_eq_of_hasEigenstate_neg_one (A : Observable S) (ψ : PureState S) + (h : A.HasEigenstate (-1) ψ) (hne : A.projMinus ψ.vec ≠ 0) : + A.postMeasMinus ψ hne = ψ := by + have hAψ : A.op ψ.vec = -ψ.vec := by simpa [Observable.HasEigenstate] using h + apply PureState.ext + rw [postMeasMinus_vec, A.projMinus_apply_eq_self hAψ, ψ.normalized] + simp + +/-! ### The random case: the observable anticommutes with a stabilizer generator -/ + +/-- **The engine of N&C eqs. (10.96)–(10.100) at an arbitrary eigenvalue: a vanishing +expectation.** If a self-adjoint `B` has `|ψ⟩` as a `μ`-eigenstate with `μ ≠ 0` (`B|ψ⟩ = μ|ψ⟩`) +and `A` anticommutes with `B` (`A B = −B A`), then the expectation of `A` in `|ψ⟩` vanishes: +`⟪A⟫_ψ = 0`. The proof slides `B` across `⟪ψ, Aψ⟫` two ways — using `Bψ = μψ` and `B` self-adjoint +it is `μ ⟪ψ, Aψ⟫`, while `B(Aψ) = −μ (Aψ)` (from `AB = −BA` and `Bψ = μψ`) makes it `−μ ⟪ψ, Aψ⟫`; +hence `μ ⟪ψ, Aψ⟫ = −μ ⟪ψ, Aψ⟫`, and `μ ≠ 0` forces `⟪ψ, Aψ⟫ = 0`. (Only `B` self-adjoint is used, +not `A² = I`.) The `μ = 1` case is `expectation_eq_zero_of_anticomm_stabilizer`; the general form is +needed e.g. for BB84's `−1`-eigenstate encodings (Exercise 12.26). -/ +theorem expectation_eq_zero_of_anticomm_eigenstate (A B : Observable S) (ψ : PureState S) + {μ : ℝ} (hμ : μ ≠ 0) (hB : B.HasEigenstate μ ψ) + (hanti : A.op * B.op = -(B.op * A.op)) : + ψ.expectation A = 0 := by + have hBψ : B.op ψ.vec = (μ : ℂ) • ψ.vec := hB + -- `B (A ψ) = -(μ • A ψ)` from anticommutation applied to `ψ` together with `B ψ = μ ψ`. + have hBx : B.op (A.op ψ.vec) = -((μ : ℂ) • A.op ψ.vec) := by + have h1 := congrArg (fun T : S.space →L[ℂ] S.space => T ψ.vec) hanti + simp only [mul_apply_eq_comp, _root_.neg_apply] at h1 + rw [hBψ, map_smul] at h1 + rw [eq_comm, neg_eq_iff_eq_neg] at h1 + exact h1 + have hBadj : ContinuousLinearMap.adjoint B.op = B.op := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact B.selfAdjoint + -- Slide `B` across `⟪ψ, B(Aψ)⟫` two ways. + have e1 : inner ℂ ψ.vec (B.op (A.op ψ.vec)) = (μ : ℂ) * inner ℂ ψ.vec (A.op ψ.vec) := by + conv_lhs => rw [← hBadj] + rw [ContinuousLinearMap.adjoint_inner_right, hBψ, inner_smul_left, Complex.conj_ofReal] + have e2 : inner ℂ ψ.vec (B.op (A.op ψ.vec)) = -((μ : ℂ) * inner ℂ ψ.vec (A.op ψ.vec)) := by + rw [hBx, inner_neg_right, inner_smul_right] + have hz2 : (μ : ℂ) * inner ℂ ψ.vec (A.op ψ.vec) = 0 := by + have h := e1.symm.trans e2 + linear_combination h / 2 + have hz : inner ℂ ψ.vec (A.op ψ.vec) = 0 := + (mul_eq_zero.mp hz2).resolve_left (Complex.ofReal_ne_zero.mpr hμ) + rw [PureState.expectation, hz] + simp + +/-- **The engine of N&C eqs. (10.96)–(10.100): a vanishing expectation.** If a self-adjoint `B` +stabilizes `|ψ⟩` (`B|ψ⟩ = |ψ⟩`, `B.HasEigenstate 1 ψ`) and `A` anticommutes with `B` +(`A B = −B A`), then the expectation of `A` in `|ψ⟩` vanishes: `⟪A⟫_ψ = 0`. The `μ = 1` +specialization of `expectation_eq_zero_of_anticomm_eigenstate` (`1 ≠ 0`). -/ +theorem expectation_eq_zero_of_anticomm_stabilizer (A B : Observable S) (ψ : PureState S) + (hB : B.HasEigenstate 1 ψ) (hanti : A.op * B.op = -(B.op * A.op)) : + ψ.expectation A = 0 := + expectation_eq_zero_of_anticomm_eigenstate A B ψ one_ne_zero hB hanti + +/-- **N&C eq. (10.100) at an arbitrary eigenvalue (`+1` outcome).** If `B` has `|ψ⟩` as a +`μ`-eigenstate with `μ ≠ 0` and the `±1` observable `A` anticommutes with `B`, then measuring `A` +is a fair coin: `p(+1) = 1/2`. From `p(+1) = (1 + ⟪A⟫_ψ)/2` and `⟪A⟫_ψ = 0` +(`expectation_eq_zero_of_anticomm_eigenstate`). The `μ = 1` case is +`bornProb_signMeasurement_plus_of_anticomm`; the general form serves e.g. BB84's `−1`-eigenstate +encodings (Exercise 12.26). -/ +theorem bornProb_signMeasurement_plus_of_anticomm_eigenstate (A B : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) {μ : ℝ} (hμ : μ ≠ 0) + (hB : B.HasEigenstate μ ψ) (hanti : A.op * B.op = -(B.op * A.op)) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = 1 / 2 := by + rw [bornProb_signMeasurement_plus, expectation_eq_zero_of_anticomm_eigenstate A B ψ hμ hB hanti] + norm_num + +/-- **N&C eq. (10.100) at an arbitrary eigenvalue (`−1` outcome).** Under the same hypotheses, +`p(−1) = 1/2`. From `p(+1) = 1/2` and `∑ᵢ p(i) = 1`. The `μ = 1` case is +`bornProb_signMeasurement_minus_of_anticomm`. -/ +theorem bornProb_signMeasurement_minus_of_anticomm_eigenstate (A B : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) {μ : ℝ} (hμ : μ ≠ 0) + (hB : B.HasEigenstate μ ψ) (hanti : A.op * B.op = -(B.op * A.op)) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = 1 / 2 := by + have hsum := (A.signMeasurement hinv).sum_bornProb_eq_one ψ.toState + rw [Fin.sum_univ_two, + bornProb_signMeasurement_plus_of_anticomm_eigenstate A B hinv ψ hμ hB hanti] at hsum + linarith + +/-- **N&C eq. (10.100) (`+1` outcome).** If `B` stabilizes `|ψ⟩` and the `±1` observable `A` +anticommutes with `B`, then measuring `A` is a fair coin: `p(+1) = 1/2`. The `μ = 1` specialization +of `bornProb_signMeasurement_plus_of_anticomm_eigenstate`. -/ +theorem bornProb_signMeasurement_plus_of_anticomm (A B : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (hB : B.HasEigenstate 1 ψ) + (hanti : A.op * B.op = -(B.op * A.op)) : + (A.signMeasurement hinv).bornProb ψ.toState 0 = 1 / 2 := + bornProb_signMeasurement_plus_of_anticomm_eigenstate A B hinv ψ one_ne_zero hB hanti + +/-- **N&C eq. (10.100) (`−1` outcome).** Under the same anticommutation hypothesis, `p(−1) = 1/2`. +The `μ = 1` specialization of `bornProb_signMeasurement_minus_of_anticomm_eigenstate`. -/ +theorem bornProb_signMeasurement_minus_of_anticomm (A B : Observable S) + (hinv : A.op * A.op = 1) (ψ : PureState S) (hB : B.HasEigenstate 1 ψ) + (hanti : A.op * B.op = -(B.op * A.op)) : + (A.signMeasurement hinv).bornProb ψ.toState 1 = 1 / 2 := + bornProb_signMeasurement_minus_of_anticomm_eigenstate A B hinv ψ one_ne_zero hB hanti + +/-! ### Stabilizer preservation: commuting generators survive the collapse -/ + +/-- **N&C §10.5.3 (stabilizer preservation, `+1` outcome).** If `C` commutes with `A` and stabilizes +`|ψ⟩`, then `C` still stabilizes the `+1`-collapsed state `P₊|ψ⟩/‖P₊|ψ⟩‖`. So every generator of the +old stabilizer that commutes with the measured observable is carried through unchanged: with +`postMeasPlus_hasEigenstate` (`A` stabilizes the collapse) the new stabilizer is `⟨A, g₂, …, gₙ⟩`. +The commutativity hypothesis is N&C's WLOG generator-set normalisation (replace any anticommuting +`gₖ` by `g₁ gₖ` so only `g₁` anticommutes); see the module docstring. Proof: `C` fixes +`P₊|ψ⟩ = ½(|ψ⟩ + A|ψ⟩)` since `C|ψ⟩ = |ψ⟩` and `C A|ψ⟩ = A C|ψ⟩ = A|ψ⟩`. -/ +theorem hasEigenstate_one_postMeasPlus_of_commute (A C : Observable S) (ψ : PureState S) + (hcomm : C.op * A.op = A.op * C.op) (hC : C.HasEigenstate 1 ψ) + (hne : A.projPlus ψ.vec ≠ 0) : + C.HasEigenstate 1 (A.postMeasPlus ψ hne) := by + have hCψ : C.op ψ.vec = ψ.vec := by simpa [Observable.HasEigenstate] using hC + have hCA : C.op (A.op ψ.vec) = A.op ψ.vec := by + rw [← mul_apply_eq_comp, hcomm, mul_apply_eq_comp, hCψ] + have hfix : C.op (A.projPlus ψ.vec) = A.projPlus ψ.vec := by + rw [projPlus] + simp only [_root_.smul_apply, _root_.add_apply, + one_apply_eq_self, map_smul, map_add, hCψ, hCA] + exact hasEigenstate_of_smul (A.postMeasPlus_vec ψ hne) (by simpa using hfix) + +/-- **N&C §10.5.3 (stabilizer preservation, `−1` outcome).** If `C` commutes with `A` and stabilizes +`|ψ⟩`, then `C` still stabilizes the `−1`-collapsed state `P₋|ψ⟩/‖P₋|ψ⟩‖`. Together with +`postMeasMinus_hasEigenstate` (`−A` stabilizes the collapse) the new stabilizer is +`⟨−A, g₂, …, gₙ⟩`. -/ +theorem hasEigenstate_one_postMeasMinus_of_commute (A C : Observable S) (ψ : PureState S) + (hcomm : C.op * A.op = A.op * C.op) (hC : C.HasEigenstate 1 ψ) + (hne : A.projMinus ψ.vec ≠ 0) : + C.HasEigenstate 1 (A.postMeasMinus ψ hne) := by + have hCψ : C.op ψ.vec = ψ.vec := by simpa [Observable.HasEigenstate] using hC + have hCA : C.op (A.op ψ.vec) = A.op ψ.vec := by + rw [← mul_apply_eq_comp, hcomm, mul_apply_eq_comp, hCψ] + have hfix : C.op (A.projMinus ψ.vec) = A.projMinus ψ.vec := by + rw [projMinus] + simp only [_root_.smul_apply, _root_.sub_apply, + one_apply_eq_self, map_smul, map_sub, hCψ, hCA] + exact hasEigenstate_of_smul (A.postMeasMinus_vec ψ hne) (by simpa using hfix) + +end Observable + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/StateMajorization.lean b/LeanPool/AxQM/Postulates/API/StateMajorization.lean new file mode 100644 index 0000000000..1b504efe76 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/StateMajorization.lean @@ -0,0 +1,728 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.PseudoInverse +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.Postulates.API.Fidelity +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.Majorization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarUnitary +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryTwirl + +/-! +# AxQM — majorization of quantum states and the reverse operator-majorization theorem + +This is the spectral foundation for **Nielsen's theorem** (Nielsen–Chuang, Theorem 12.15): a +bipartite pure state `|ψ⟩` can be transformed to `|ϕ⟩` by LOCC iff `λ_ψ ≺ λ_ϕ`, where `λ_ψ` is the +vector of squared Schmidt coefficients — equivalently the eigenvalues of the reduced density +operator `ρ_ψ`. The condition `λ_ψ ≺ λ_ϕ` is *majorization of the reduced states*, which we make +first-class here. + +The spectral data of a density operator used here — `State.eigenbasis` and its +`op_apply_eigenbasis` / `inner_eigenbasis_self` / `norm_eigenbasis` lemmas — are in +`Postulates/API/PseudoInverse.lean` (alongside `State.op_apply_eigenvectorBasis`). + +## What is defined and proved + +* `AxQM.State.Majorize ρ σ` — **majorization of quantum states**: the eigenvalue + distribution `ρ.eigenvalueDist` is majorized by `σ.eigenvalueDist` (in the vector sense + `Majorize` of `ToMathlib.Analysis.Convex.Majorization`). This is N&C's `ρ ≺ σ` for density + operators, defined spectrally like `State.vonNeumannEntropy`. +* `AxQM.State.inner_op_self_eq_sum_eigenvalueDist` — the **spectral quadratic form** + `⟪u, σ u⟫ = ∑ₗ λₗ ‖⟪fₗ, u⟫‖²` (`fₗ = σ.eigenbasis l`, `λₗ = σ.eigenvalueDist l`). +* `AxQM.State.majorize_of_op_eq_sum_unitary_conj` — the **reverse operator-majorization + theorem** (the state-level reverse direction of N&C Theorem 12.13): if + `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` is a convex combination (`pⱼ ≥ 0`, `∑ pⱼ = 1`) of *unitary* conjugates of + `σ`, then `ρ ≺ σ`. This is exactly the input Nielsen's theorem invokes ("`ρ_ψ = ∑ pⱼ Uⱼ ρ_ϕ Uⱼ†` + whence `λ_ψ ≺ λ_ϕ` by Theorem 12.13"). +* `AxQM.State.exists_op_eq_sum_unitary_conj_of_majorize` — the **forward + operator-majorization theorem** (state-level forward direction of N&C Theorem 12.13): if `ρ ≺ σ` + then `ρ` *is* such a convex combination `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` of unitary conjugates of `σ`. + Together with the reverse above this is Theorem 12.13 for density operators. Proved + operator-natively: + Proposition 12.11 (`majorize_iff_exists_sum_perm`) expands `λ_ρ = ∑_π w_π (λ_σ ∘ π)`, and each + permutation `π` becomes a unitary change of eigenbasis `σ.eigenbasis.equiv ρ.eigenbasis π⁻¹`. +* `AxQM.State.LOCCConvertible ρ σ` — **one-way LOCC convertibility of reduced states** (the + standard protocol form of N&C Proposition 12.14): there is a measurement `{Mⱼ}` and a probability + distribution `pⱼ` with `Mⱼ ρ Mⱼ† = pⱼ σ` for every outcome `j`. This is the density-operator + condition on the reduced operators of bipartite pure states. The predicate is stated for + density operators and measurements. +* `AxQM.State.LOCCConvertible.majorize` — the **forward direction of Nielsen's theorem** + (N&C Theorem 12.15, `⟹`): `ρ.LOCCConvertible σ → ρ ≺ σ`. Polar-decomposing `Aⱼ = Mⱼ √ρ` gives + `ρ = ∑ⱼ pⱼ Uⱼ† σ Uⱼ`, and `majorize_of_op_eq_sum_unitary_conj` closes it. + +## Proof of the reverse operator-majorization theorem + +Reading the `(k, k)` entry of the mixture in `ρ`'s eigenbasis `e` and expanding `σ`'s quadratic +form in its eigenbasis `f` gives, with `uⱼₖ = Uⱼ† eₖ`, +`λ_ρ(k) = ⟪eₖ, ρ eₖ⟫ = ∑ⱼ pⱼ ⟪uⱼₖ, σ uⱼₖ⟫ = ∑ₗ (∑ⱼ pⱼ ‖⟪fₗ, uⱼₖ⟫‖²) λ_σ(l) = ∑ₗ Dₖₗ λ_σ(l)`, +so `λ_ρ = D λ_σ` where `Dₖₗ = ∑ⱼ pⱼ ‖⟪fₗ, uⱼₖ⟫‖²`. The matrix `D` is doubly stochastic — its rows +sum to one because `∑ₗ ‖⟪fₗ, uⱼₖ⟫‖² = ‖uⱼₖ‖² = ‖eₖ‖² = 1` (Parseval + `Uⱼ†` unitary) and +`∑ⱼ pⱼ = 1`, and its columns because `∑ₖ ‖⟪fₗ, Uⱼ† eₖ⟫‖² = ∑ₖ ‖⟪Uⱼ fₗ, eₖ⟫‖² = ‖Uⱼ fₗ‖² = 1`. +`Majorize.of_mem_doublyStochastic` (the easy direction of N&C Proposition 12.11) then gives +`D λ_σ ≺ λ_σ`, i.e. `ρ ≺ σ`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace State + +/-- **Spectral action on the eigenbasis, in `eigenvalueDist` form** (majorization plumbing): +`ρ (bⱼ) = (ρ.eigenvalueDist j) • bⱼ`. The `eigenvalueDist`-phrasing of the general +`State.op_apply_eigenbasis` (`Postulates/API/PseudoInverse`); `ρ.eigenvalueDist j` is definitionally +`ρ.isDensity.isSymmetric.eigenvalues rfl j`, so this is `op_apply_eigenbasis` unchanged. -/ +private theorem op_apply_eigenbasis' (ρ : State S) (j : Fin (Module.finrank ℂ S.space)) : + ρ.op (ρ.eigenbasis j) = (ρ.eigenvalueDist j : ℂ) • ρ.eigenbasis j := + ρ.op_apply_eigenbasis j + +/-- **Majorization of quantum states.** `ρ.Majorize σ` (N&C's `ρ ≺ σ` for density operators) holds +when the eigenvalue distribution of `ρ` is majorized by that of `σ` (`Majorize` on the eigenvalue +vectors). This is the exact condition `λ_ψ ≺ λ_ϕ` of Nielsen's theorem when `ρ`, `σ` are the reduced +states of bipartite pure states. -/ +def Majorize (ρ σ : State S) : Prop := + _root_.Majorize ρ.eigenvalueDist σ.eigenvalueDist + +/-- **Eigenvalue distribution from any eigenbasis (as a multiset).** If an orthonormal basis `b` +diagonalizes the density operator `ρ.op` with real eigenvalues `p` (`ρ.op (b i) = p i • b i`), then +the multiset of `ρ.eigenvalueDist` equals the multiset of `p`. The canonical eigenvalue +distribution is a specific ordering of the spectrum, so it agrees with *any* eigenbasis's diagonal +only up to a permutation; this records that agreement multiset-wise (all `Majorize` needs, being +permutation-invariant on each vector). Proved by the eigenvalue-recognition theorem +`LinearMap.IsSymmetric.eigenvalues_multiset_map_eq_of_eigenbasis`. -/ +theorem eigenvalueDist_multiset_map_eq {ι : Type*} [Fintype ι] (ρ : State S) + (b : OrthonormalBasis ι ℂ S.space) (p : ι → ℝ) + (hb : ∀ i, ρ.op (b i) = (p i : ℂ) • b i) : + Multiset.map ρ.eigenvalueDist Finset.univ.val = Multiset.map p Finset.univ.val := by + refine (LinearMap.IsSymmetric.eigenvalues_multiset_map_eq_of_eigenbasis + ρ.isDensity.isSymmetric rfl b.toBasis fun i => ?_).symm + simp only [OrthonormalBasis.coe_toBasis] + exact hb i + +/-- **The spectral quadratic form.** For a state `σ` with eigenbasis `f = σ.eigenbasis` and +eigenvalues `λ = σ.eigenvalueDist`, `⟪u, σ u⟫ = ∑ₗ λₗ · ‖⟪fₗ, u⟫‖²`. This is the diagonalization of +`σ.op` read off against an arbitrary vector `u`. -/ +theorem inner_op_self_eq_sum_eigenvalueDist (σ : State S) (u : S.space) : + inner ℂ u (σ.op u) = + ∑ l, (σ.eigenvalueDist l : ℂ) * ((‖inner ℂ (σ.eigenbasis l) u‖ ^ 2 : ℝ) : ℂ) := by + have hu : ∑ l, inner ℂ (σ.eigenbasis l) u • σ.eigenbasis l = u := by + simpa [OrthonormalBasis.repr_apply_apply] using σ.eigenbasis.sum_repr u + calc + inner ℂ u (σ.op u) + = inner ℂ u (σ.op (∑ l, inner ℂ (σ.eigenbasis l) u • σ.eigenbasis l)) := by rw [hu] + _ = inner ℂ u + (∑ l, inner ℂ (σ.eigenbasis l) u • ((σ.eigenvalueDist l : ℂ) • σ.eigenbasis l)) := by + rw [map_sum] + simp_rw [map_smul, σ.op_apply_eigenbasis'] + _ = ∑ l, (σ.eigenvalueDist l : ℂ) * + (inner ℂ (σ.eigenbasis l) u * inner ℂ u (σ.eigenbasis l)) := by + rw [inner_sum] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [inner_smul_right, inner_smul_right] + ring + _ = ∑ l, (σ.eigenvalueDist l : ℂ) * ((‖inner ℂ (σ.eigenbasis l) u‖ ^ 2 : ℝ) : ℂ) := by + refine Finset.sum_congr rfl fun l _ => ?_ + rw [show inner ℂ u (σ.eigenbasis l) + = (starRingEnd ℂ) (inner ℂ (σ.eigenbasis l) u) from + (inner_conj_symm u (σ.eigenbasis l)).symm, RCLike.mul_conj] + norm_num + +/-- **Reverse operator-majorization** (state-level reverse direction of N&C Theorem 12.13). If a +state `ρ` is a convex combination `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` of unitary conjugates of a state `σ` (with +`pⱼ ≥ 0`, `∑ pⱼ = 1`, each `Uⱼ` unitary), then `ρ ≺ σ`. This is the mathematical input Nielsen's +theorem invokes: from `ρ_ψ = ∑ pⱼ Uⱼ ρ_ϕ Uⱼ†` conclude `λ_ψ ≺ λ_ϕ`. -/ +theorem majorize_of_op_eq_sum_unitary_conj {ι : Type*} [Fintype ι] + (ρ σ : State S) {p : ι → ℝ} {U : ι → S.space →L[ℂ] S.space} + (hp : ∀ j, 0 ≤ p j) (hsum : ∑ j, p j = 1) + (hU : ∀ j, U j ∈ unitary (S.space →L[ℂ] S.space)) + (hρ : ρ.op = ∑ j, (p j : ℂ) • (U j).comp (σ.op.comp (adjoint (U j)))) : + ρ.Majorize σ := by + classical + -- adjoints of the `Uⱼ` are unitary too + have hUadj : ∀ j, adjoint (U j) ∈ unitary (S.space →L[ℂ] S.space) := by + intro j + rw [← ContinuousLinearMap.star_eq_adjoint] + exact Unitary.star_mem (hU j) + -- the doubly stochastic matrix `Dₖₗ = ∑ⱼ pⱼ ‖⟪fₗ, Uⱼ† eₖ⟫‖²` + set D : Matrix (Fin (Module.finrank ℂ S.space)) (Fin (Module.finrank ℂ S.space)) ℝ := + Matrix.of fun k l => + ∑ j, p j * ‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 + have hDentry : ∀ k l, D k l = + ∑ j, p j * ‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 := fun _ _ => rfl + -- `D` is doubly stochastic + have hDmem : D ∈ doublyStochastic ℝ (Fin (Module.finrank ℂ S.space)) := by + rw [mem_doublyStochastic_iff_sum] + refine ⟨?_, ?_, ?_⟩ + · -- nonnegative entries + intro k l + rw [hDentry] + exact Finset.sum_nonneg fun j _ => mul_nonneg (hp j) (sq_nonneg _) + · -- rows sum to one + intro k + have hone : ∀ j, + ∑ l, ‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 = 1 := by + intro j + rw [σ.eigenbasis.sum_sq_norm_inner_right, + ContinuousLinearMap.norm_map_of_mem_unitary (hUadj j), ρ.norm_eigenbasis k, one_pow] + have : ∑ l, D k l = ∑ j, p j := by + simp_rw [hDentry] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [← Finset.mul_sum, hone j, mul_one] + rw [this, hsum] + · -- columns sum to one + intro l + have hone : ∀ j, + ∑ k, ‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 = 1 := by + intro j + have hswap : ∀ k, inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k)) + = inner ℂ ((U j) (σ.eigenbasis l)) (ρ.eigenbasis k) := fun k => by + rw [adjoint_inner_right] + simp_rw [hswap] + rw [ρ.eigenbasis.sum_sq_norm_inner_left, + ContinuousLinearMap.norm_map_of_mem_unitary (hU j), σ.norm_eigenbasis l, one_pow] + have : ∑ k, D k l = ∑ j, p j := by + simp_rw [hDentry] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [← Finset.mul_sum, hone j, mul_one] + rw [this, hsum] + -- `λ_ρ = D λ_σ` + have hEq : D.mulVec σ.eigenvalueDist = ρ.eigenvalueDist := by + funext k + have hterm : ∀ j, inner ℂ (ρ.eigenbasis k) + (((p j : ℂ) • (U j).comp (σ.op.comp (adjoint (U j)))) (ρ.eigenbasis k)) + = (p j : ℂ) * ∑ l, (σ.eigenvalueDist l : ℂ) * + ((‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 : ℝ) : ℂ) := by + intro j + rw [_root_.smul_apply, inner_smul_right, ContinuousLinearMap.comp_apply, + ContinuousLinearMap.comp_apply, + ← adjoint_inner_left (U j) (σ.op (adjoint (U j) (ρ.eigenbasis k))) (ρ.eigenbasis k), + σ.inner_op_self_eq_sum_eigenvalueDist (adjoint (U j) (ρ.eigenbasis k))] + have key : (ρ.eigenvalueDist k : ℂ) = ∑ l, (D k l : ℂ) * (σ.eigenvalueDist l : ℂ) := + calc (ρ.eigenvalueDist k : ℂ) + = inner ℂ (ρ.eigenbasis k) (ρ.op (ρ.eigenbasis k)) := by + rw [ρ.op_apply_eigenbasis' k, inner_smul_right, ρ.inner_eigenbasis_self k, mul_one] + _ = ∑ j, inner ℂ (ρ.eigenbasis k) + (((p j : ℂ) • (U j).comp (σ.op.comp (adjoint (U j)))) (ρ.eigenbasis k)) := by + rw [hρ, _root_.sum_apply, inner_sum] + _ = ∑ j, ∑ l, (p j : ℂ) * ((σ.eigenvalueDist l : ℂ) * + ((‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 : ℝ) : ℂ)) := by + refine Finset.sum_congr rfl fun j _ => ?_ + rw [hterm j, Finset.mul_sum] + _ = ∑ l, ∑ j, (p j : ℂ) * ((σ.eigenvalueDist l : ℂ) * + ((‖inner ℂ (σ.eigenbasis l) (adjoint (U j) (ρ.eigenbasis k))‖ ^ 2 : ℝ) : ℂ)) := + Finset.sum_comm + _ = ∑ l, (D k l : ℂ) * (σ.eigenvalueDist l : ℂ) := by + refine Finset.sum_congr rfl fun l _ => ?_ + rw [hDentry] + push_cast + rw [Finset.sum_mul] + refine Finset.sum_congr rfl fun j _ => ?_ + ring + have hmv : (D.mulVec σ.eigenvalueDist) k = ∑ l, D k l * σ.eigenvalueDist l := by + simp only [Matrix.mulVec, dotProduct] + rw [hmv] + have hcast : ((∑ l, D k l * σ.eigenvalueDist l : ℝ) : ℂ) = (ρ.eigenvalueDist k : ℂ) := by + rw [key]; push_cast; ring + exact_mod_cast hcast + rw [State.Majorize, ← hEq] + exact Majorize.of_mem_doublyStochastic hDmem σ.eigenvalueDist + +/-- **Forward operator-majorization** (state-level forward direction of N&C Theorem 12.13). If a +state `ρ` is majorized by `σ` (`ρ ≺ σ`), then `ρ` is a convex combination `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` of +*unitary* conjugates of `σ` (`pⱼ ≥ 0`, `∑ pⱼ = 1`, each `Uⱼ` unitary). Paired with the reverse +`majorize_of_op_eq_sum_unitary_conj`, this is N&C Theorem 12.13 (`H ≺ K ↔ H = ∑ pⱼ Uⱼ K Uⱼ†`) at the +level of density operators — the "unitary-mixture" characterization Nielsen's theorem produces from +`λ_ψ ≺ λ_ϕ` before realizing it as a measurement. + +The proof is operator-native (no matrix bridge). Proposition 12.11 (`majorize_iff_exists_sum_perm`) +expands `ρ`'s eigenvalue vector as a convex combination `λ_ρ = ∑_π w_π (λ_σ ∘ π)` of permutations of +`σ`'s. Each permutation `π` is realized as the unitary change of eigenbasis +`Uπ = σ.eigenbasis.equiv ρ.eigenbasis π⁻¹` (sending `σ`'s `i`-th eigenvector to `ρ`'s `π⁻¹ i`-th), +for which `Uπ σ Uπ† (ρ.eigenbasis q) = λ_σ(π q) • ρ.eigenbasis q`; weighting by `w_π` and summing +reconstructs `ρ.op` diagonally in `ρ`'s own eigenbasis (`OrthonormalBasis.ext_inner_basis`). The +index type is `Equiv.Perm (Fin d)` (`d = dim S.space`). -/ +theorem exists_op_eq_sum_unitary_conj_of_majorize {ρ σ : State S} (h : ρ.Majorize σ) : + ∃ (ι : Type) (_ : Fintype ι) (p : ι → ℝ) (U : ι → (S.space →L[ℂ] S.space)), + (∀ j, 0 ≤ p j) ∧ (∑ j, p j = 1) ∧ + (∀ j, U j ∈ unitary (S.space →L[ℂ] S.space)) ∧ + ρ.op = ∑ j, (p j : ℂ) • (U j).comp (σ.op.comp (adjoint (U j))) := by + classical + have h' : _root_.Majorize ρ.eigenvalueDist σ.eigenvalueDist := h + obtain ⟨w, hw0, hwsum, hwdist⟩ := majorize_iff_exists_sum_perm.mp h' + -- the isometry realizing permutation `π` as a change of eigenbasis (`σ`'s → `ρ`'s) + set e : Equiv.Perm (Fin (Module.finrank ℂ S.space)) → (S.space ≃ₗᵢ[ℂ] S.space) := + fun π => σ.eigenbasis.equiv ρ.eigenbasis π⁻¹ with he + set U : Equiv.Perm (Fin (Module.finrank ℂ S.space)) → (S.space →L[ℂ] S.space) := + fun π => (↑(e π).toContinuousLinearEquiv : S.space →L[ℂ] S.space) with hU + -- `Uπ` carries `σ.eigenbasis (π q)` to `ρ.eigenbasis q` + have hUapply : ∀ (π : Equiv.Perm (Fin (Module.finrank ℂ S.space))) + (q : Fin (Module.finrank ℂ S.space)), U π (σ.eigenbasis (π q)) = ρ.eigenbasis q := by + intro π q + simp only [hU, he, ContinuousLinearEquiv.coe_coe, + LinearIsometryEquiv.coe_toContinuousLinearEquiv, OrthonormalBasis.equiv_apply_basis, + Equiv.Perm.inv_def, Equiv.symm_apply_apply] + -- `Uπ†` carries `ρ.eigenbasis q` to `σ.eigenbasis (π q)` + have hadj : ∀ (π : Equiv.Perm (Fin (Module.finrank ℂ S.space))) + (q : Fin (Module.finrank ℂ S.space)), + adjoint (U π) (ρ.eigenbasis q) = σ.eigenbasis (π q) := by + intro π q + have hst : adjoint (U π) = (↑(e π).symm.toContinuousLinearEquiv : S.space →L[ℂ] S.space) := by + simp only [hU]; exact LinearIsometryEquiv.adjoint_eq_symm (e π) + rw [hst, he] + simp only [OrthonormalBasis.equiv_symm, ContinuousLinearEquiv.coe_coe, + LinearIsometryEquiv.coe_toContinuousLinearEquiv, OrthonormalBasis.equiv_apply_basis, + Equiv.Perm.inv_def, Equiv.symm_symm] + -- each `Uπ` is unitary + have hunit : ∀ π, U π ∈ unitary (S.space →L[ℂ] S.space) := by + intro π + simp only [hU] + rw [← Unitary.coe_symm_linearIsometryEquiv_apply] + exact SetLike.coe_mem _ + -- `ρ.op = ∑ π, w π • Uπ σ.op Uπ†`, checked on `ρ`'s eigenbasis + have hvec : ∀ q : Fin (Module.finrank ℂ S.space), ρ.op (ρ.eigenbasis q) + = (∑ π, (w π : ℂ) • (U π).comp (σ.op.comp (adjoint (U π)))) (ρ.eigenbasis q) := by + intro q + rw [op_apply_eigenbasis', _root_.sum_apply] + have hterm : ∀ π, ((w π : ℂ) • (U π).comp (σ.op.comp (adjoint (U π)))) (ρ.eigenbasis q) + = ((w π : ℂ) * (σ.eigenvalueDist (π q) : ℂ)) • ρ.eigenbasis q := by + intro π + rw [_root_.smul_apply, ContinuousLinearMap.comp_apply, + ContinuousLinearMap.comp_apply, hadj π q, op_apply_eigenbasis', map_smul, hUapply π q, + smul_smul] + rw [Finset.sum_congr rfl (fun π _ => hterm π), ← Finset.sum_smul] + have hpt : (ρ.eigenvalueDist q : ℂ) = ∑ π, (w π : ℂ) * (σ.eigenvalueDist (π q) : ℂ) := by + have hc : ρ.eigenvalueDist q = ∑ π, w π * σ.eigenvalueDist (π q) := by + have h0 := congrFun hwdist q + rw [Finset.sum_apply] at h0 + simpa only [Pi.smul_apply, Matrix.permMatrix_mulVec, Function.comp_apply, + smul_eq_mul] using h0 + rw [hc]; push_cast; ring + rw [hpt] + refine ⟨_, inferInstance, w, U, hw0, hwsum, hunit, ?_⟩ + exact ρ.eigenbasis.ext_inner_basis (fun p q => by rw [hvec q]) + +/-- **The inverse-square-root pseudo-inverse `(√ρ)⁺` of a density operator.** The spectral operator +`∑ₖ (√λₖ)⁻¹ |bₖ⟩⟨bₖ|` over `ρ`'s orthonormal eigenbasis `bₖ = ρ.eigenbasis k` with eigenvalues +`λₖ = ρ.eigenvalueDist k`, inverting each *non-zero* `√λₖ` and sending the kernel (zero eigenvalues) +to `0` (the real field inverse is `0` at `0`). It is the Moore–Penrose pseudo-inverse of `√ρ`: +`sqrtPseudoInverse ρ` squares to `ρ.pseudoInverse` and is the operator that "divides by `√ρ` on the +support" in the converse of Nielsen's theorem. Defined spectrally, mirroring +`State.pseudoInverse`. -/ +def sqrtPseudoInverse (ρ : State S) : S.space →L[ℂ] S.space := + ∑ k, (((Real.sqrt (ρ.eigenvalueDist k))⁻¹ : ℝ) : ℂ) • + rankOne ℂ (ρ.eigenbasis k) (ρ.eigenbasis k) + +/-- **Spectral action of `(√ρ)⁺`**: `(√ρ)⁺ bⱼ = (√λⱼ)⁻¹ bⱼ` on each eigenvector `bⱼ`, mapping the +kernel (zero eigenvalues) to `0`. -/ +@[simp] +theorem sqrtPseudoInverse_apply_eigenbasis (ρ : State S) + (j : Fin (Module.finrank ℂ S.space)) : + ρ.sqrtPseudoInverse (ρ.eigenbasis j) + = (((Real.sqrt (ρ.eigenvalueDist j))⁻¹ : ℝ) : ℂ) • ρ.eigenbasis j := by + rw [sqrtPseudoInverse, _root_.sum_apply, Finset.sum_eq_single j] + · rw [_root_.smul_apply, rankOne_apply, inner_eigenbasis_self, one_smul] + · intro k _ hk + rw [_root_.smul_apply, rankOne_apply, + orthonormal_iff_ite.mp ρ.eigenbasis.orthonormal k j, ite_eq_right hk, zero_smul, smul_zero] + · intro h; exact absurd (Finset.mem_univ j) h + +/-- `(√ρ)⁺` is self-adjoint: each summand `(√λₖ)⁻¹ |bₖ⟩⟨bₖ|` is a real scalar times a self-adjoint +rank-one projector. -/ +theorem isSelfAdjoint_sqrtPseudoInverse (ρ : State S) : IsSelfAdjoint ρ.sqrtPseudoInverse := by + rw [sqrtPseudoInverse] + refine isSelfAdjoint_sum Finset.univ fun k _ => ?_ + rw [Complex.coe_smul] + refine (IsSelfAdjoint.all _).smul ?_ + rw [isSelfAdjoint_iff, ContinuousLinearMap.star_eq_adjoint, adjoint_rankOne] + +/-- `(√ρ)⁺ ∘ (√ρ)⁺ = ρ⁻¹`: the square of the inverse-square-root pseudo-inverse is the +Moore–Penrose pseudo-inverse of `ρ`, eigenvalue-by-eigenvalue `((√λ)⁻¹)² = λ⁻¹`. -/ +theorem sqrtPseudoInverse_comp_self (ρ : State S) : + ρ.sqrtPseudoInverse.comp ρ.sqrtPseudoInverse = ρ.pseudoInverse := by + refine ContinuousLinearMap.coe_injective (ρ.eigenbasis.toBasis.ext fun j => ?_) + have hpi : ρ.pseudoInverse (ρ.eigenbasis j) + = (((ρ.eigenvalueDist j)⁻¹ : ℝ) : ℂ) • ρ.eigenbasis j := + ρ.pseudoInverse_apply_eigenvectorBasis j + have hsq : (Real.sqrt (ρ.eigenvalueDist j))⁻¹ * (Real.sqrt (ρ.eigenvalueDist j))⁻¹ + = (ρ.eigenvalueDist j)⁻¹ := by + rw [← mul_inv, Real.mul_self_sqrt (ρ.eigenvalueDist_nonneg j)] + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe, + ContinuousLinearMap.comp_apply, sqrtPseudoInverse_apply_eigenbasis, map_smul, smul_smul, hpi] + rw [← Complex.ofReal_mul, hsq] + +/-- `(√ρ)⁺` commutes with `ρ`: `(√ρ)⁺ ∘ ρ = ρ ∘ (√ρ)⁺` (both are spectral in `ρ`). -/ +theorem sqrtPseudoInverse_comp_op_comm (ρ : State S) : + ρ.sqrtPseudoInverse.comp ρ.op = ρ.op.comp ρ.sqrtPseudoInverse := by + refine ContinuousLinearMap.coe_injective (ρ.eigenbasis.toBasis.ext fun j => ?_) + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe, + ContinuousLinearMap.comp_apply, op_apply_eigenbasis', sqrtPseudoInverse_apply_eigenbasis, + map_smul] + rw [smul_comm] + +/-- **One-way LOCC convertibility of reduced states** (the standard protocol form, N&C +Proposition 12.14). `ρ.LOCCConvertible σ` holds when Alice can perform a single measurement `{Mⱼ}` +on her system that carries the reduced state `ρ` to `σ` *deterministically*: for a probability +distribution `pⱼ` and **every** outcome `j`, `Mⱼ ρ Mⱼ† = pⱼ σ`. + +Operationally (Nielsen's theorem, N&C Theorem 12.15): Alice measures `{Mⱼ}`, obtains outcome `j` +with probability `pⱼ`, and her reduced state is `σ` regardless of `j`; Bob then rotates his half to +the target pure state by a local unitary (Exercises 2.80/2.81). This is the density-operator content +of the one-way protocol between bipartite pure states. Proposition 12.14 justifies the one-way +form for pure-state transformations. The +[pinned AxQMLib proof](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Proposition12_14.lean#L453-L455) +formalizes the pure-input reduction as `OneWayLOCC.of_transforms_pureState`. The definition below +expresses the reduced-state measurement condition. -/ +def LOCCConvertible (ρ σ : State S) : Prop := + ∃ (ι : Type) (_ : Fintype ι) (m : Measurement ι S) (p : ι → ℝ), + (∀ j, 0 ≤ p j) ∧ (∑ j, p j = 1) ∧ + ∀ j, (m.op j).comp (ρ.op.comp (adjoint (m.op j))) = (p j : ℂ) • σ.op + +/-- **Forward direction of Nielsen's theorem** (N&C Theorem 12.15, `⟹`): if the reduced state `ρ` +can be converted to `σ` by a one-way LOCC measurement, then `ρ ≺ σ`. + +Following N&C's proof, polar-decompose `Aⱼ := Mⱼ √ρ`. Since `√ρ` is self-adjoint with `√ρ √ρ = ρ`, +we have `Aⱼ Aⱼ† = Mⱼ ρ Mⱼ† = pⱼ σ` (the LOCC hypothesis) while `Aⱼ† Aⱼ = √ρ Mⱼ† Mⱼ √ρ`. The +polar-decomposition unitary equivalence `Aⱼ† Aⱼ = Uⱼ† (Aⱼ Aⱼ†) Uⱼ` +(`ContinuousLinearMap.exists_unitary_star_mul_self_eq_conj`, `Uⱼ` unitary) then gives +`Aⱼ† Aⱼ = pⱼ Uⱼ† σ Uⱼ`. Summing over `j` and +using the completeness relation `∑ⱼ Mⱼ† Mⱼ = 1` collapses the left side to `√ρ √ρ = ρ`, so +`ρ = ∑ⱼ pⱼ Uⱼ† σ Uⱼ = ∑ⱼ pⱼ Wⱼ σ Wⱼ†` with `Wⱼ := Uⱼ†` unitary. The reverse operator-majorization +theorem `majorize_of_op_eq_sum_unitary_conj` (the state-level reverse of N&C Theorem 12.13) +then gives `ρ ≺ σ`. All the operator algebra is carried out in the `*`/`star` endomorphism ring of +`S.space →L[ℂ] S.space` (where `f * g = f.comp g` and `star = adjoint`). -/ +theorem LOCCConvertible.majorize {ρ σ : State S} (h : ρ.LOCCConvertible σ) : ρ.Majorize σ := by + classical + obtain ⟨ι, hfin, m, p, hp, hsum, heq⟩ := h + let := hfin + -- `√ρ`, self-adjoint with `√ρ √ρ = ρ`. + set sq : S.space →L[ℂ] S.space := cfc Real.sqrt ρ.op with hsqdef + have hsqsa : adjoint sq = sq := by rw [hsqdef]; exact ρ.adjoint_cfc_sqrt_op + have hsqsa_star : star sq = sq := by rw [ContinuousLinearMap.star_eq_adjoint]; exact hsqsa + have hsqsq : sq * sq = ρ.op := by + have hh := ContinuousLinearMap.cfc_sqrt_comp_adjoint_eq_self_of_nonneg ρ.isDensity.nonneg + rw [← hsqdef, hsqsa] at hh + rwa [← ContinuousLinearMap.mul_def] at hh + -- The completeness relation `∑ⱼ Mⱼ† Mⱼ = 1`, in `*`/`star` form. + have hcomplete : ∑ j, star (m.op j) * m.op j = 1 := by + have := m.complete + simpa only [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint] using this + -- `Aⱼ := Mⱼ √ρ`. + set A : ι → (S.space →L[ℂ] S.space) := fun j => (m.op j) * sq with hAdef + -- Per outcome, a unitary `Uⱼ` witnessing `Aⱼ† Aⱼ = pⱼ • Uⱼ† σ Uⱼ`: the polar-decomposition + -- unitary equivalence `Aⱼ† Aⱼ = Uⱼ† (Aⱼ Aⱼ†) Uⱼ` (general lemma) fed `Aⱼ Aⱼ† = pⱼ σ` (physics). + have hUexists : ∀ j, ∃ U ∈ unitary (S.space →L[ℂ] S.space), + star (A j) * A j = (p j : ℂ) • (star U * σ.op * U) := by + intro j + obtain ⟨U, hU, hswap⟩ := ContinuousLinearMap.exists_unitary_star_mul_self_eq_conj (A j) + -- `Aⱼ Aⱼ† = Mⱼ ρ Mⱼ† = pⱼ • σ`. + have hAAstar_eq : A j * star (A j) = (p j : ℂ) • σ.op := by + have e1 : A j * star (A j) = (m.op j) * (sq * sq) * star (m.op j) := by + simp only [hAdef] + rw [star_mul, hsqsa_star] + simp only [mul_assoc] + rw [e1, hsqsq] + have hj := heq j + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, + ← ContinuousLinearMap.star_eq_adjoint, ← mul_assoc] at hj + exact hj + exact ⟨U, hU, by rw [hswap, hAAstar_eq, mul_smul_comm, smul_mul_assoc]⟩ + -- `∑ⱼ Aⱼ† Aⱼ = √ρ (∑ⱼ Mⱼ† Mⱼ) √ρ = √ρ √ρ = ρ`. + have hSumAA : ∑ j, star (A j) * A j = ρ.op := by + have hterm : ∀ j, star (A j) * A j = sq * (star (m.op j) * m.op j) * sq := by + intro j + simp only [hAdef] + rw [star_mul, hsqsa_star] + simp only [mul_assoc] + calc ∑ j, star (A j) * A j + = ∑ j, sq * (star (m.op j) * m.op j) * sq := by simp_rw [hterm] + _ = sq * (∑ j, star (m.op j) * m.op j) * sq := by rw [Finset.mul_sum, Finset.sum_mul] + _ = sq * 1 * sq := by rw [hcomplete] + _ = ρ.op := by rw [mul_one, hsqsq] + -- Assemble `ρ = ∑ⱼ pⱼ Uⱼ† σ Uⱼ` and apply the reverse operator-majorization theorem. + choose U hU hUeq using hUexists + have hfinal : ρ.op = ∑ j, (p j : ℂ) • (star (U j) * σ.op * U j) := by + rw [← hSumAA] + exact Finset.sum_congr rfl fun j _ => hUeq j + refine majorize_of_op_eq_sum_unitary_conj ρ σ hp hsum (fun j => Unitary.star_mem (hU j)) ?_ + rw [hfinal] + refine Finset.sum_congr rfl fun j _ => ?_ + simp only [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint, star_star, + mul_assoc] + +/-- `ρ.op` is self-adjoint (a positive operator is self-adjoint). A local helper; the public +`State.isSelfAdjoint_op` lives in a different module, so this avoids a cross-module name clash. -/ +private theorem op_isSelfAdjoint (ρ : State S) : IsSelfAdjoint ρ.op := + (ContinuousLinearMap.nonneg_iff_isPositive.mp ρ.isDensity.nonneg).isSelfAdjoint + +/-- `(√ρ)⁺ (√ρ)⁺ = ρ⁻¹` in `*`-ring form. -/ +private theorem sqrtPseudoInverse_mul_self_eq (ρ : State S) : + ρ.sqrtPseudoInverse * ρ.sqrtPseudoInverse = ρ.pseudoInverse := by + rw [ContinuousLinearMap.mul_def]; exact ρ.sqrtPseudoInverse_comp_self + +/-- The Moore–Penrose identity `ρ ρ⁻¹ ρ = ρ` in `*`-ring form. -/ +private theorem op_mul_pseudoInverse_mul_op (ρ : State S) : + ρ.op * ρ.pseudoInverse * ρ.op = ρ.op := by + have hh := ρ.op_comp_pseudoInverse_comp_op + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, ← mul_assoc] at hh + exact hh + +/-- **The support projector `Pₛ = (√ρ)⁺ ρ (√ρ)⁺`** of a density operator: the orthogonal projector +onto the support (range) of `ρ`. Built from the inverse-square-root pseudo-inverse `(√ρ)⁺`; it is a +self-adjoint idempotent (`isSelfAdjoint_supportProjector`, `isIdempotentElem_supportProjector`) that +restricts to the identity on the support (`supportProjector_comp_op` : `Pₛ ρ = ρ`). Defined +spectrally. -/ +def supportProjector (ρ : State S) : S.space →L[ℂ] S.space := + ρ.sqrtPseudoInverse * ρ.op * ρ.sqrtPseudoInverse + +/-- **The kernel projector `Pₖ = 1 - Pₛ`** of a density operator: the orthogonal projector onto +`ker ρ`, complementary to the support projector. Self-adjoint idempotent +(`isSelfAdjoint_kernelProjector`, `isIdempotentElem_kernelProjector`) that annihilates `ρ` +(`kernelProjector_comp_op` : `Pₖ ρ = 0`). -/ +def kernelProjector (ρ : State S) : S.space →L[ℂ] S.space := + 1 - ρ.supportProjector + +/-- The support projector is self-adjoint. -/ +theorem isSelfAdjoint_supportProjector (ρ : State S) : IsSelfAdjoint ρ.supportProjector := by + have hsi : star ρ.sqrtPseudoInverse = ρ.sqrtPseudoInverse := ρ.isSelfAdjoint_sqrtPseudoInverse + have hop : star ρ.op = ρ.op := ρ.op_isSelfAdjoint + change star ρ.supportProjector = ρ.supportProjector + rw [supportProjector] + simp only [star_mul, hsi, hop, mul_assoc] + +/-- **The support projector restricts to the identity on the support: `Pₛ ρ = ρ`** (Moore–Penrose). +`(√ρ)⁺ ρ (√ρ)⁺ ρ = (√ρ)⁺ ρ (√ρ)⁺·... ` collapses via `(√ρ)⁺(√ρ)⁺ = ρ⁻¹` and `ρ ρ⁻¹ ρ = ρ`. -/ +theorem supportProjector_comp_op (ρ : State S) : ρ.supportProjector.comp ρ.op = ρ.op := by + have hcomm : ρ.sqrtPseudoInverse * ρ.op = ρ.op * ρ.sqrtPseudoInverse := by + rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.mul_def] + exact ρ.sqrtPseudoInverse_comp_op_comm + rw [← ContinuousLinearMap.mul_def, supportProjector, hcomm, + show ρ.op * ρ.sqrtPseudoInverse * ρ.sqrtPseudoInverse * ρ.op + = ρ.op * (ρ.sqrtPseudoInverse * ρ.sqrtPseudoInverse) * ρ.op by simp only [mul_assoc], + ρ.sqrtPseudoInverse_mul_self_eq, ρ.op_mul_pseudoInverse_mul_op] + +/-- The support projector is idempotent: `Pₛ Pₛ = Pₛ`. -/ +theorem isIdempotentElem_supportProjector (ρ : State S) : + IsIdempotentElem ρ.supportProjector := by + change ρ.supportProjector * ρ.supportProjector = ρ.supportProjector + rw [supportProjector, + show (ρ.sqrtPseudoInverse * ρ.op * ρ.sqrtPseudoInverse) * + (ρ.sqrtPseudoInverse * ρ.op * ρ.sqrtPseudoInverse) + = ρ.sqrtPseudoInverse * ρ.op * (ρ.sqrtPseudoInverse * ρ.sqrtPseudoInverse) * + (ρ.op * ρ.sqrtPseudoInverse) by simp only [mul_assoc], ρ.sqrtPseudoInverse_mul_self_eq, + show ρ.sqrtPseudoInverse * ρ.op * ρ.pseudoInverse * (ρ.op * ρ.sqrtPseudoInverse) + = ρ.sqrtPseudoInverse * (ρ.op * ρ.pseudoInverse * ρ.op) * ρ.sqrtPseudoInverse by + simp only [mul_assoc], ρ.op_mul_pseudoInverse_mul_op] + +/-- The kernel projector is self-adjoint. -/ +theorem isSelfAdjoint_kernelProjector (ρ : State S) : IsSelfAdjoint ρ.kernelProjector := by + change star ρ.kernelProjector = ρ.kernelProjector + rw [kernelProjector, star_sub, star_one, ρ.isSelfAdjoint_supportProjector] + +/-- The kernel projector is idempotent: `Pₖ Pₖ = Pₖ`. -/ +theorem isIdempotentElem_kernelProjector (ρ : State S) : + IsIdempotentElem ρ.kernelProjector := by + change ρ.kernelProjector * ρ.kernelProjector = ρ.kernelProjector + have hpr : ρ.supportProjector * ρ.supportProjector = ρ.supportProjector := + ρ.isIdempotentElem_supportProjector + rw [kernelProjector, show (1 - ρ.supportProjector) * (1 - ρ.supportProjector) + = 1 - ρ.supportProjector - ρ.supportProjector + ρ.supportProjector * ρ.supportProjector by + noncomm_ring, hpr] + abel + +/-- **The kernel projector annihilates `ρ`: `Pₖ ρ = 0`.** Since `Pₛ ρ = ρ`, `(1 - Pₛ) ρ = 0`. -/ +theorem kernelProjector_comp_op (ρ : State S) : ρ.kernelProjector.comp ρ.op = 0 := by + have hsupp : ρ.supportProjector * ρ.op = ρ.op := by + rw [ContinuousLinearMap.mul_def]; exact ρ.supportProjector_comp_op + rw [← ContinuousLinearMap.mul_def, kernelProjector, sub_mul, one_mul, hsupp, sub_self] + +/-- **Converse of Nielsen's theorem** (Nielsen–Chuang Theorem 12.15, `⇐`), the reduced-state crux: +if `ρ ≺ σ` then `ρ` can be converted to `σ` by a one-way LOCC measurement. This is the direction +that *constructs* the protocol from the majorization condition, and it needs **no invertibility +hypothesis** on `ρ` (N&C Exercise 12.20): the measurement operators are built from the +inverse-square-root pseudo-inverse `(√ρ)⁺`, which acts on the support of `ρ` and sends its kernel to +`0`. + +By the forward operator-majorization theorem (`exists_op_eq_sum_unitary_conj_of_majorize`, N&C +Theorem 12.13) `ρ = ∑ⱼ pⱼ Uⱼ σ Uⱼ†` with each `Uⱼ` unitary. Take measurement operators +`Mⱼ = √pⱼ · √σ Uⱼ† (√ρ)⁺` (indexed by `some j`) together with one extra outcome `M₀ = Pₖ`, the +projector onto `ker ρ`, with probability `0`. Writing `Pₛ = (√ρ)⁺ ρ (√ρ)⁺` for the projector onto +the support of `ρ` (so `Pₖ = 1 - Pₛ`): + +* **completeness** `∑ Mᵢ† Mᵢ = (√ρ)⁺ ρ (√ρ)⁺ + Pₖ = Pₛ + Pₖ = 1`; +* **support outcomes** `Mⱼ ρ Mⱼ† = pⱼ √σ Uⱼ† Pₛ Uⱼ √σ = pⱼ σ`: since `Pₛ = 1 - Pₖ`, this needs + `pⱼ (√σ Uⱼ† Pₖ Uⱼ √σ) = 0`, which holds because `√σ Uⱼ† Pₖ = 0` whenever `pⱼ > 0` — from + `Pₖ ρ Pₖ = 0` and `⟪u, Pₖ ρ Pₖ u⟫ = ∑ₖ pₖ ‖√σ Uₖ† Pₖ u‖²`, every summand with `pⱼ > 0` vanishes; + and `Mⱼ = 0` when `pⱼ = 0`; +* **kernel outcome** `M₀ ρ M₀† = Pₖ ρ Pₖ = 0 = 0 · σ`. + +All the operator algebra is carried out in the `*`/`star` endomorphism ring. Combined with the +forward `LOCCConvertible.majorize`, this is Nielsen's theorem for the reduced states. -/ +theorem LOCCConvertible_of_majorize {ρ σ : State S} (h : ρ.Majorize σ) : + ρ.LOCCConvertible σ := by + classical + obtain ⟨ι, hfin, p, U, hp, hsum, hU, hρ⟩ := ρ.exists_op_eq_sum_unitary_conj_of_majorize h + let := hfin + -- `√σ`, self-adjoint with `√σ √σ = σ`. + set sσ : S.space →L[ℂ] S.space := cfc Real.sqrt σ.op with hsσdef + have hsσadj : adjoint sσ = sσ := by rw [hsσdef]; exact σ.adjoint_cfc_sqrt_op + have hsσsa : star sσ = sσ := by rw [ContinuousLinearMap.star_eq_adjoint]; exact hsσadj + have hsσsq : sσ * sσ = σ.op := by + have hh := ContinuousLinearMap.cfc_sqrt_comp_adjoint_eq_self_of_nonneg σ.isDensity.nonneg + rw [← hsσdef, hsσadj] at hh + rwa [← ContinuousLinearMap.mul_def] at hh + -- `(√ρ)⁺`, self-adjoint. + set si : S.space →L[ℂ] S.space := ρ.sqrtPseudoInverse with hsidef + have hsisa : star si = si := ρ.isSelfAdjoint_sqrtPseudoInverse + -- `ρ` as a `*`-ring sum of unitary conjugates of `σ`. + have hρ' : ρ.op = ∑ j, (p j : ℂ) • (U j * σ.op * star (U j)) := by + rw [hρ] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, + ← ContinuousLinearMap.star_eq_adjoint, ← mul_assoc] + -- The named support/kernel projectors and the projector facts they carry (API above). + set pr : S.space →L[ℂ] S.space := ρ.supportProjector with hprdef + set pk : S.space →L[ℂ] S.space := ρ.kernelProjector with hpkdef + have hpr_si : pr = si * ρ.op * si := by rw [hprdef, hsidef, supportProjector] + have hpksa : star pk = pk := ρ.isSelfAdjoint_kernelProjector + have hpkpk : pk * pk = pk := ρ.isIdempotentElem_kernelProjector + have hpkop : pk * ρ.op = 0 := by + rw [hpkdef, ContinuousLinearMap.mul_def]; exact ρ.kernelProjector_comp_op + have hpr_eq : pr = 1 - pk := by rw [hprdef, hpkdef, kernelProjector]; abel + -- The measurement over `Option ι`: the support operators plus the kernel projector `pk`. + set M : Option ι → (S.space →L[ℂ] S.space) := + fun i => i.elim pk (fun j => (Real.sqrt (p j) : ℂ) • (sσ * star (U j) * si)) + set pp : Option ι → ℝ := fun i => i.elim 0 p + have hMnone : M none = pk := rfl + have hMsome : ∀ j, M (some j) = (Real.sqrt (p j) : ℂ) • (sσ * star (U j) * si) := fun _ => rfl + have hppnone : pp none = 0 := rfl + have hppsome : ∀ j, pp (some j) = p j := fun _ => rfl + have hMstar : ∀ j, star (M (some j)) = (Real.sqrt (p j) : ℂ) • (si * U j * sσ) := by + intro j + rw [hMsome, star_smul, star_mul, star_mul, hsisa, star_star, hsσsa, + show star ((Real.sqrt (p j) : ℝ) : ℂ) = ((Real.sqrt (p j) : ℝ) : ℂ) from + Complex.conj_ofReal _, mul_assoc] + -- The kernel lemma: `pⱼ (√σ Uⱼ† pk Uⱼ √σ) = 0` for every outcome. + have hkernel : ∀ j, (p j : ℂ) • (sσ * star (U j) * pk * U j * sσ) = 0 := by + have hpkoppk : pk * ρ.op * pk = 0 := by rw [hpkop, zero_mul] + have hpkadj : adjoint pk = pk := by rw [← ContinuousLinearMap.star_eq_adjoint]; exact hpksa + have hqf : ∀ u : S.space, ∑ k, p k * ‖(sσ * star (U k) * pk) u‖ ^ 2 = 0 := by + intro u + have hval : inner ℂ (pk u) (ρ.op (pk u)) = 0 := by + have e : inner ℂ (pk u) (ρ.op (pk u)) = inner ℂ u ((pk * ρ.op * pk) u) := by + rw [show (pk * ρ.op * pk) u = pk (ρ.op (pk u)) by + simp only [mul_apply_eq_comp]] + conv_rhs => rw [← ContinuousLinearMap.adjoint_inner_left, hpkadj] + rw [e, hpkoppk, _root_.zero_apply, inner_zero_right] + have hexp : inner ℂ (pk u) (ρ.op (pk u)) + = ((∑ k, p k * ‖(sσ * star (U k) * pk) u‖ ^ 2 : ℝ) : ℂ) := by + rw [hρ', Complex.ofReal_sum] + simp only [_root_.sum_apply, _root_.smul_apply, + mul_apply_eq_comp, inner_sum, inner_smul_right] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [← ContinuousLinearMap.adjoint_inner_left (U k), ← ContinuousLinearMap.star_eq_adjoint, + ← hsσsq, mul_apply_eq_comp, + ← ContinuousLinearMap.adjoint_inner_left sσ, hsσadj, + show sσ (star (U k) (pk u)) = (sσ * star (U k) * pk) u by + simp only [mul_apply_eq_comp], + inner_self_eq_norm_sq_to_K] + norm_num + rw [hval] at hexp + exact_mod_cast hexp.symm + intro j + rcases eq_or_lt_of_le (hp j) with h0 | hpos + · rw [← h0, Complex.ofReal_zero, zero_smul] + · have hG : sσ * star (U j) * pk = 0 := by + refine ContinuousLinearMap.ext fun u => ?_ + have hterm : p j * ‖(sσ * star (U j) * pk) u‖ ^ 2 = 0 := + (Finset.sum_eq_zero_iff_of_nonneg + (fun k (_ : k ∈ Finset.univ) => mul_nonneg (hp k) (sq_nonneg _))).mp (hqf u) j + (Finset.mem_univ j) + have hn2 : ‖(sσ * star (U j) * pk) u‖ ^ 2 = 0 := by + rcases mul_eq_zero.mp hterm with hh | hh + · exact absurd hh hpos.ne' + · exact hh + have : ‖(sσ * star (U j) * pk) u‖ = 0 := by + have := pow_eq_zero_iff (n := 2) (by norm_num) |>.mp hn2 + simpa using this + rw [_root_.zero_apply] + exact norm_eq_zero.mp this + rw [show sσ * star (U j) * pk * U j * sσ = (sσ * star (U j) * pk) * (U j * sσ) by + simp only [mul_assoc], hG, zero_mul, smul_zero] + -- Completeness `∑ Mᵢ† Mᵢ = 1`. + have hcomplete : ∑ i, (adjoint (M i)).comp (M i) = 1 := by + have hnone : (adjoint (M none)).comp (M none) = pk := by + rw [hMnone, ← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint, hpksa, + hpkpk] + have hsome : ∀ j, (adjoint (M (some j))).comp (M (some j)) + = (p j : ℂ) • (si * U j * σ.op * star (U j) * si) := by + intro j + rw [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint, hMstar j, hMsome, + show ((Real.sqrt (p j) : ℂ) • (si * U j * sσ)) * + ((Real.sqrt (p j) : ℂ) • (sσ * star (U j) * si)) + = ((Real.sqrt (p j) : ℂ) * (Real.sqrt (p j) : ℂ)) • + ((si * U j * sσ) * (sσ * star (U j) * si)) by + rw [smul_mul_assoc, mul_smul_comm, smul_smul], + ← Complex.ofReal_mul, Real.mul_self_sqrt (hp j)] + congr 1 + rw [show (si * U j * sσ) * (sσ * star (U j) * si) = si * U j * (sσ * sσ) * star (U j) * si by + simp only [mul_assoc], hsσsq] + rw [Fintype.sum_option, hnone] + rw [show (∑ j, (adjoint (M (some j))).comp (M (some j))) = pr by + rw [hpr_si, hρ', Finset.mul_sum, Finset.sum_mul] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [hsome j] + simp only [smul_mul_assoc, mul_smul_comm, mul_assoc]] + rw [hpr_eq]; abel + -- The state-transfer condition `Mᵢ ρ Mᵢ† = ppᵢ • σ`. + have htransfer : ∀ i, (M i).comp (ρ.op.comp (adjoint (M i))) = (pp i : ℂ) • σ.op := by + rintro (_ | j) + · rw [hMnone, hppnone] + simp only [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint, hpksa] + rw [← mul_assoc, hpkop, zero_mul, Complex.ofReal_zero, zero_smul] + · have hUunit : star (U j) * U j = 1 := (Unitary.mem_iff.mp (hU j)).1 + rw [hppsome] + simp only [← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.star_eq_adjoint] + rw [hMstar j, hMsome, + show ((Real.sqrt (p j) : ℂ) • (sσ * star (U j) * si)) * + (ρ.op * ((Real.sqrt (p j) : ℂ) • (si * U j * sσ))) + = ((Real.sqrt (p j) : ℂ) * (Real.sqrt (p j) : ℂ)) • + ((sσ * star (U j) * si) * (ρ.op * (si * U j * sσ))) by + rw [mul_smul_comm, smul_mul_assoc, mul_smul_comm, smul_smul], + ← Complex.ofReal_mul, Real.mul_self_sqrt (hp j), + show (sσ * star (U j) * si) * (ρ.op * (si * U j * sσ)) + = sσ * star (U j) * (si * ρ.op * si) * U j * sσ by simp only [mul_assoc], + ← hpr_si, hpr_eq, + show sσ * star (U j) * (1 - pk) * U j * sσ + = sσ * (star (U j) * U j) * sσ - sσ * star (U j) * pk * U j * sσ by noncomm_ring, + hUunit, mul_one, hsσsq, smul_sub, hkernel, sub_zero] + -- Probabilities are a distribution. + have hpp_nonneg : ∀ i, 0 ≤ pp i := by + rintro (_ | j) + · exact le_of_eq hppnone.symm + · rw [hppsome]; exact hp j + have hpp_sum : ∑ i, pp i = 1 := by + rw [Fintype.sum_option, hppnone, zero_add] + simp only [hppsome] + exact hsum + exact ⟨Option ι, inferInstance, ⟨M, hcomplete⟩, pp, hpp_nonneg, hpp_sum, htransfer⟩ + +end State + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/StrongSubadditivity.lean b/LeanPool/AxQM/Postulates/API/StrongSubadditivity.lean new file mode 100644 index 0000000000..3fcc20e31e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/StrongSubadditivity.lean @@ -0,0 +1,121 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.API.Entropy +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumStrongSubadditivity + +/-! +# AxQM — strong subadditivity of the von Neumann entropy (N&C Theorem 11.14) + +For a tripartite quantum system `A ⊗ (B ⊗ C)` and a faithful state `ρ`, the von Neumann entropy +satisfies **strong subadditivity** + +`S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` + +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.14, eq. (11.73)), +where the marginals are the reduced states + +* `S(A,B,C) = S(ρ)` — the whole tripartite state; +* `S(B,C) = S(ρ.reducedRight)` — trace out `A`; +* `S(B) = S(ρ.reducedRight.reducedLeft)` — further trace out `C`; +* `S(A,B) = S((ρ.congr (QSystem.assoc A B C)).reducedLeft)` — re-associate to `(A ⊗ B) ⊗ C` + and trace out `C`. + +Equivalently, the quantum mutual information is monotone under discarding `C`, +`I(A:B) ≤ I(A:BC)`. + +## Relation to the operator-level theorem + +The theorem is stated with the entropy `State.vonNeumannEntropy` and the reduced states +`State.reducedLeft`, `State.reducedRight`, `State.congr`. The faithfulness hypothesis is +`IsStrictlyPositive ρ.op`, as in the relative-entropy theorems it descends from +(`State.quantumRelativeEntropy_reduced_le`, etc.). It is the state-level form of the operator +theorem `ContinuousLinearMap.vonNeumannEntropy_add_partialTrace_le`. + +## Faithfulness + +As with Klein's inequality, joint convexity, and monotonicity under partial trace, the finite, +real-valued relative-entropy engine underlying the proof requires the states to be **faithful** +(strictly positive spectrum). The fully general (entropy-only) statement follows by a +continuity/limiting argument over faithful approximants, which needs von Neumann entropy continuity; +it is not formalised here. + +## The other form of the theorem (N&C eq. (11.72)) + +N&C Theorem 11.14 also states the equivalent form `S(A) + S(B) ≤ S(A,C) + S(B,C)` (eq. (11.72)). +The two forms are equivalent, and deriving (11.72) from strong subadditivity is the content of the +separate **Exercise 11.24** (via purification and the equality of the entropies of +complementary subsystems of a pure state); it builds on this theorem rather than being re-proved. + +## Main results + +* `AxQM.State.vonNeumannEntropy_add_le_add` — strong subadditivity + `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` for a faithful tripartite state. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- **Strong subadditivity of the von Neumann entropy** (Nielsen & Chuang, Theorem 11.14, +eq. (11.73)): for a faithful (strictly positive) state `ρ` on the tripartite system +`A ⊗ (B ⊗ C)`, + +`S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)`, + +with the marginals read off as reduced states — `S(B,C) = S(ρ.reducedRight)` (trace out `A`), +`S(B) = S(ρ.reducedRight.reducedLeft)` (further trace out `C`), and +`S(A,B) = S((ρ.congr (QSystem.assoc A B C)).reducedLeft)` (re-associate to `(A ⊗ B) ⊗ C`, then +trace out `C`). Equivalently, the mutual information is monotone under discarding `C`, +`I(A:B) ≤ I(A:BC)`. + +This is the state-level form of the operator theorem +`ContinuousLinearMap.vonNeumannEntropy_add_partialTrace_le`. Faithfulness +(`IsStrictlyPositive ρ.op`) is the finite-branch hypothesis of the relative-entropy engine (module +docstring). The equivalent form `S(A) + S(B) ≤ S(A,C) + S(B,C)` (eq. (11.72)) is Exercise 11.24. -/ +theorem State.vonNeumannEntropy_add_le_add (ρ : State (A ⊗ (B ⊗ C))) + (hρ : IsStrictlyPositive ρ.op) : + ρ.vonNeumannEntropy + ρ.reducedRight.reducedLeft.vonNeumannEntropy ≤ + (ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy + + ρ.reducedRight.vonNeumannEntropy := by + -- Nontriviality of each factor (so the traced-out bases are nonempty), read off reduced states. + have : Nontrivial A.space := ρ.reducedLeft.nontrivial_space + have : Nontrivial B.space := ρ.reducedRight.reducedLeft.nontrivial_space + have : Nontrivial C.space := ρ.reducedRight.reducedRight.nontrivial_space + have : Nonempty (Fin (Module.finrank ℂ A.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + have : Nonempty (Fin (Module.finrank ℂ B.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + have : Nonempty (Fin (Module.finrank ℂ C.space)) := Fin.pos_iff_nonempty.mp Module.finrank_pos + -- The three marginal identities the operator-level theorem consumes, discharged from the + -- definitions. Each identity is definitional: the reduced states and transport unfold to exactly + -- the operator-level partial-trace expressions (the `stdOrthonormalBasis` canonicalization + -- matches). + have hBC : LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ A.space) ρ.op.toLinearMap = + ρ.reducedRight.op.toLinearMap := rfl + have hB : LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + ρ.reducedRight.op.toLinearMap = ρ.reducedRight.reducedLeft.op.toLinearMap := rfl + have hAB : LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + ((TensorProduct.assocIsometry ℂ A.space B.space C.space).symm.conjStarAlgEquiv + ρ.op).toLinearMap = + (ρ.congr (QSystem.assoc A B C)).reducedLeft.op.toLinearMap := rfl + have key := ContinuousLinearMap.vonNeumannEntropy_add_partialTrace_le + (stdOrthonormalBasis ℂ A.space) (stdOrthonormalBasis ℂ B.space) (stdOrthonormalBasis ℂ C.space) + ρ.isDensity hρ hAB hBC hB + simp only [State.vonNeumannEntropy_def] + exact key + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SubadditivityReformulations.lean b/LeanPool/AxQM/Postulates/API/SubadditivityReformulations.lean new file mode 100644 index 0000000000..1389c9acc7 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SubadditivityReformulations.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.StrongSubadditivity +public import LeanPool.AxQM.Postulates.API.MutualInformation +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# AxQM — reformulations of strong subadditivity (N&C Theorem 11.15) + +Two of the three elementary reformulations of strong subadditivity from Nielsen & Chuang, +Theorem 11.15 (p. 522): + +* **(1) Conditioning reduces entropy** — `S(A|B,C) ≤ S(A|B)` + (`State.conditioning_reduces_vonNeumannEntropy`); +* **(2) Discarding quantum systems never increases mutual information** — `S(A:B) ≤ S(A:B,C)` + (`State.vonNeumannMutualInfo_le_of_discard`). + +Both are *algebraic rearrangements* of strong subadditivity, `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` +(`State.vonNeumannEntropy_add_le_add`, N&C Theorem 11.14 eq. (11.73)), matching N&C's own proof on +p. 523: each reformulation is shown equivalent to strong subadditivity by moving the terms across +the inequality. The third reformulation — quantum *operations* never increase mutual information — +requires the environment (Stinespring) representation of a channel and is a separate development. + +## The two marginal-consistency lemmas + +The state lives on the right-nested composite `A ⊗ (B ⊗ C)`. The `A ⊗ B`-marginal is read off after +re-associating to `(A ⊗ B) ⊗ C` and tracing out `C`, i.e. as +`σ := (ρ.congr (QSystem.assoc A B C)).reducedLeft`. To relate `σ`'s own marginals back to `ρ`'s the +file proves that the two ways of computing the `S(A)`- and `S(B)`-marginals agree as **states**: + +* `State.reducedLeft_reducedLeft_congr_assoc` — `σ`'s `A`-marginal is `ρ`'s `A`-marginal + (trace out `B ⊗ C` at once vs. trace out `C` then `B` after re-association), via the + commutation lemma + `LinearMap.partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv` + together with basis-independence of the partial trace; +* `State.reducedRight_reducedLeft_congr_assoc` — `σ`'s `B`-marginal is the `B`-marginal of `ρ`'s + `B ⊗ C`-marginal (trace out `A` then `C` vs. trace out `C` then `A`), via + `LinearMap.partialTraceLeft_partialTraceRight_assoc`. + +## Hypotheses and notation + +Every statement here carries the faithfulness hypothesis `IsStrictlyPositive ρ.op`, the finite, +real-valued requirement inherited from the strong-subadditivity theorem and Problem 11.4's +conditional strong subadditivity that they descend from. The statement of Theorem 11.15 is in +`LeanPool/AxQM/NC/Ch11/Theorem15.lean`. + +Reformulation (1) is stated *inline* over von Neumann entropy differences rather than through the +conditional entropy `State.condVonNeumannEntropy`; its LHS/RHS are exactly `S(A|B,C)` and `S(A|B)` +by that definition. Reformulation (2) uses the mutual information `State.vonNeumannMutualInfo` +defined in `Postulates/API/MutualInformation`. + +## Main results + +* `AxQM.State.conditioning_reduces_vonNeumannEntropy` — N&C Theorem 11.15(1). +* `AxQM.State.vonNeumannMutualInfo_le_of_discard` — N&C Theorem 11.15(2). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C : QSystem} + +/-- **`S(A)`-marginal consistency.** For a tripartite state `ρ` on `A ⊗ (B ⊗ C)`, the `A`-marginal +of the `A ⊗ B`-marginal `σ = (ρ.congr (QSystem.assoc A B C)).reducedLeft` equals the `A`-marginal of +`ρ` itself: tracing out `B ⊗ C` in one step is the same as re-associating, tracing out `C`, then +tracing out `B`. Reduces to the commutation lemma +`LinearMap.partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv` plus +basis-independence of the partial trace. -/ +theorem State.reducedLeft_reducedLeft_congr_assoc (ρ : State (A ⊗ (B ⊗ C))) : + ((ρ.congr (QSystem.assoc A B C)).reducedLeft).reducedLeft = ρ.reducedLeft := by + -- The reverse face of the canonical associator–left-marginal lemma + -- `State.reducedLeft_congr_assoc_symm` (`Postulates/API/ReducedStateTransport`), which applies + -- the commutation fact once. Instantiate it at `ρ.congr (QSystem.assoc A B C)` and cancel + -- the associator against its inverse via the transport unit/inverse laws. + have h := State.reducedLeft_congr_assoc_symm (ρ.congr (QSystem.assoc A B C)) + rw [← State.congr_trans, QSystem.Iso.trans_symm_self, State.congr_refl] at h + exact h.symm + +/-- **`S(B)`-marginal consistency.** For a tripartite state `ρ` on `A ⊗ (B ⊗ C)`, the `B`-marginal +of the `A ⊗ B`-marginal `σ = (ρ.congr (QSystem.assoc A B C)).reducedLeft` equals the `B`-marginal of +the `B ⊗ C`-marginal of `ρ`: tracing out `A` then `C` is the same as tracing out `C` then `A`. +Reduces to the commutation lemma `LinearMap.partialTraceLeft_partialTraceRight_assoc` through +the bridge `LinearMap.assocIsometry_symm_conjStarAlgEquiv_toLinearMap`. -/ +theorem State.reducedRight_reducedLeft_congr_assoc (ρ : State (A ⊗ (B ⊗ C))) : + ((ρ.congr (QSystem.assoc A B C)).reducedLeft).reducedRight = ρ.reducedRight.reducedLeft := by + apply State.ext + -- Both operators are definitionally the displayed iterated partial traces; restate to that form, + -- then bridge the isometry conjugation to the plain-`LinearEquiv` conjugation the + -- commutation lemma is stated with, and commute the two partial traces (trace out `A` then `C`). + change (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ A.space) + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + (((TensorProduct.assocIsometry ℂ A.space B.space C.space).symm.conjStarAlgEquiv + ρ.op).toLinearMap))).toContinuousLinearMap = + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ A.space) + ρ.op.toLinearMap)).toContinuousLinearMap + -- `(A ⊗ (B ⊗ C)).space` is only `rfl`-defeq (via `QSystem.compose`, twice-nested) to the + -- generic `A.space ⊗[ℂ] (B.space ⊗[ℂ] C.space)` the tower lemmas need to match + -- syntactically; restate `ρ.op` there via a `let` and bridge back with `exact`. + let ρopCLM : A.space ⊗[ℂ] (B.space ⊗[ℂ] C.space) →L[ℂ] A.space ⊗[ℂ] (B.space ⊗[ℂ] C.space) := + ρ.op + have hfull : LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ A.space) + (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + (((TensorProduct.assocIsometry ℂ A.space B.space C.space).symm.conjStarAlgEquiv + ρopCLM).toLinearMap)) = + LinearMap.partialTraceRight (stdOrthonormalBasis ℂ C.space) + (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ A.space) ρopCLM.toLinearMap) := by + rw [LinearMap.assocIsometry_symm_conjStarAlgEquiv_toLinearMap, + LinearMap.partialTraceLeft_partialTraceRight_assoc] + exact congrArg LinearMap.toContinuousLinearMap hfull + +/-- **N&C Theorem 11.15(1): conditioning reduces entropy.** For a faithful (strictly positive) state +`ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A|B,C) ≤ S(A|B)`. + +Written inline over von Neumann entropy differences: the left-hand side +`S(ρ) − S(ρ.reducedRight)` is `S(A,B,C) − S(B,C) = S(A|B,C)`, and the right-hand side +`S((ρ.congr (QSystem.assoc A B C)).reducedLeft) − S(ρ.reducedRight.reducedLeft)` is +`S(A,B) − S(B) = S(A|B)` (each side is the corresponding value of the conditional entropy +`State.condVonNeumannEntropy`). Immediate from strong +subadditivity `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` (`State.vonNeumannEntropy_add_le_add`) by moving +the marginal entropies across, matching N&C's proof on p. 523. -/ +theorem State.conditioning_reduces_vonNeumannEntropy (ρ : State (A ⊗ (B ⊗ C))) + (hρ : IsStrictlyPositive ρ.op) : + ρ.vonNeumannEntropy - ρ.reducedRight.vonNeumannEntropy ≤ + (ρ.congr (QSystem.assoc A B C)).reducedLeft.vonNeumannEntropy - + ρ.reducedRight.reducedLeft.vonNeumannEntropy := by + have h := State.vonNeumannEntropy_add_le_add ρ hρ + linarith + +/-- **N&C Theorem 11.15(2): discarding quantum systems never increases mutual information.** For a +faithful (strictly positive) state `ρ` on the tripartite system `A ⊗ (B ⊗ C)`, + +`S(A:B) ≤ S(A:B,C)`, + +where `S(A:B)` is the mutual information of the `A ⊗ B`-marginal +`(ρ.congr (QSystem.assoc A B C)).reducedLeft` and `S(A:B,C)` is the mutual information of `ρ` +(read as a bipartite state on `A ⊗ (B ⊗ C)`). Equivalently, discarding the subsystem `C` from the +composite `B ⊗ C` cannot increase how much `A` and `B ⊗ C` know about each other. Immediate from +strong subadditivity once the shared `S(A)` and `S(B)` marginals are identified across the two +readings (`State.reducedLeft_reducedLeft_congr_assoc` and +`State.reducedRight_reducedLeft_congr_assoc`); matches N&C's proof on p. 523. -/ +theorem State.vonNeumannMutualInfo_le_of_discard (ρ : State (A ⊗ (B ⊗ C))) + (hρ : IsStrictlyPositive ρ.op) : + ((ρ.congr (QSystem.assoc A B C)).reducedLeft).vonNeumannMutualInfo ≤ + ρ.vonNeumannMutualInfo := by + have hSSA := State.vonNeumannEntropy_add_le_add ρ hρ + rw [State.vonNeumannMutualInfo_def, State.vonNeumannMutualInfo_def, + State.reducedLeft_reducedLeft_congr_assoc, State.reducedRight_reducedLeft_congr_assoc] + linarith + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Support.lean b/LeanPool/AxQM/Postulates/API/Support.lean new file mode 100644 index 0000000000..8c3e882a06 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Support.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SchmidtNumber +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# AxQM — the support of a density operator + +Nielsen & Chuang, in Exercise 2.73, work with the **support** of a density operator `ρ`: +*"the vector space spanned by the eigenvectors of `ρ` with non-zero eigenvalues"* (the general +definition, stated there for a Hermitian operator `A`, is the span of its non-kernel eigenvectors). +Equivalently — and this is the definition we take — the support is the **range** of `ρ`, and, since +`ρ` is self-adjoint, the **orthogonal complement of its kernel**: +`support ρ = range ρ = (ker ρ)ᗮ`. + +The three descriptions coincide because `ρ` is symmetric: +`LinearMap.IsSymmetric.range_eq_orthogonal_ker` gives `range = kerᗮ`, and the kernel of a +self-adjoint operator is the span of its zero-eigenvalue eigenvectors, so `kerᗮ` is the span of the +non-zero-eigenvalue eigenvectors — N&C's phrasing. + +Taking `support := range ρ` makes the dimension identity free: the **rank** `ρ.rank` +(`AxQM.State.rank`) is defined as `finrank (range ρ)`, so `finrank (support ρ) = ρ.rank` +holds definitionally. That rank identity is what the *minimal ensemble* part of Exercise 2.73 +needs: a minimal ensemble has exactly `rank ρ = finrank (support ρ)` elements. + +## Main definitions + +* `AxQM.State.support` — the support `range ρ` of a density operator, a `Submodule`. + +## Main results + +* `State.rank_eq_finrank_support` — `ρ.rank = finrank (support ρ)` (definitional). +* `State.support_eq_orthogonal_ker` — `support ρ = (ker ρ)ᗮ` (self-adjointness). +* `State.eigenvectorBasis_mem_ker_of_eigenvalue_eq_zero` — a zero-eigenvalue eigenvector lies in + `ker ρ` (zero-eigenspace = kernel); the shared building block behind the two lemmas below. +* `State.eigenvectorBasis_mem_support_iff` — an eigenvector `bⱼ` lies in the support iff its + eigenvalue is non-zero: the "span of non-zero eigenvectors" characterization of N&C. +* `State.inner_eigenvectorBasis_eq_zero_of_mem_support` — a state `ψ` in the support has zero + overlap with every zero-eigenvalue eigenvector `⟪bⱼ, ψ⟫ = 0`. This expresses "`|ψ⟩` lies in the + support" and shows that `⟨ψ|ρ⁻¹|ψ⟩` is a genuine (finite, positive) quantity even though `ρ⁻¹` + kills the kernel. +* `State.support_isOrtho_iff_op_mul_eq_zero` — **orthogonal supports as a vanishing operator + product**: `ρ.support ⟂ σ.support ↔ ρ.op * σ.op = 0`. An operator-level formulation of + "the states have orthogonal supports", used by the equality condition of the entropy-of-a-mixture + bound (N&C Theorem 11.10). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace State + +/-- **The support of a density operator** (Nielsen–Chuang Exercise 2.73): the range of `ρ`, which — +since `ρ` is self-adjoint — is the span of the eigenvectors of `ρ` with non-zero eigenvalues +(equivalently `(ker ρ)ᗮ`, see `support_eq_orthogonal_ker`). Defined as `range ρ` so that the rank +identity `finrank (support ρ) = ρ.rank` is definitional. -/ +def support (ρ : State S) : Submodule ℂ S.space := + LinearMap.range (ρ.op : S.space →ₗ[ℂ] S.space) + +/-- **The rank of `ρ` is the dimension of its support**: `ρ.rank = finrank (support ρ)`. Holds by +definition (`State.rank` is `finrank (range ρ)` and `support ρ = range ρ`); recorded as a named +lemma because the minimal-ensemble development refers to `finrank (support ρ)` and to `ρ.rank` +interchangeably. -/ +theorem rank_eq_finrank_support (ρ : State S) : + ρ.rank = Module.finrank ℂ ρ.support := + rfl + +/-- **The support is the orthogonal complement of the kernel**: `support ρ = (ker ρ)ᗮ`. For a +self-adjoint operator the range equals `kerᗮ` (`LinearMap.IsSymmetric.range_eq_orthogonal_ker`), and +`ρ` is symmetric as a density operator. -/ +theorem support_eq_orthogonal_ker (ρ : State S) : + ρ.support = (LinearMap.ker (ρ.op : S.space →ₗ[ℂ] S.space))ᗮ := + ρ.isDensity.isSymmetric.range_eq_orthogonal_ker + +/-- **A zero-eigenvalue eigenvector lies in the kernel**: if `λⱼ = 0` then `bⱼ ∈ ker ρ`. The +zero-eigenspace of a density operator is exactly its kernel — the foundational spectral fact dual to +`support_eq_orthogonal_ker` (`support = kerᗮ`), and the shared building block behind both the +"span of non-zero eigenvectors" characterization and the coefficient-vanishing handle below. -/ +theorem eigenvectorBasis_mem_ker_of_eigenvalue_eq_zero (ρ : State S) + (j : Fin (Module.finrank ℂ S.space)) + (hj : ρ.isDensity.isSymmetric.eigenvalues rfl j = 0) : + ρ.isDensity.isSymmetric.eigenvectorBasis rfl j ∈ + LinearMap.ker (ρ.op : S.space →ₗ[ℂ] S.space) := by + rw [LinearMap.mem_ker, ρ.isDensity.isSymmetric.apply_eigenvectorBasis rfl j, hj]; simp + +/-- **The support is spanned by the non-zero eigenvectors** (Nielsen–Chuang's phrasing): an +eigenvector `bⱼ` of `ρ` lies in the support iff its eigenvalue `λⱼ` is non-zero. Forward: if +`λⱼ = 0` then `bⱼ ∈ ker ρ`, and `bⱼ ∈ support = kerᗮ` would force `⟪bⱼ, bⱼ⟫ = 0`, contradicting +`‖bⱼ‖ = 1`. Backward: if `λⱼ ≠ 0` then `bⱼ = ρ (λⱼ⁻¹ • bⱼ) ∈ range ρ`. -/ +theorem eigenvectorBasis_mem_support_iff (ρ : State S) + (j : Fin (Module.finrank ℂ S.space)) : + ρ.isDensity.isSymmetric.eigenvectorBasis rfl j ∈ ρ.support ↔ + ρ.isDensity.isSymmetric.eigenvalues rfl j ≠ 0 := by + set hsym := ρ.isDensity.isSymmetric with hsym_def + have hb : (ρ.op : S.space →ₗ[ℂ] S.space) (hsym.eigenvectorBasis rfl j) + = (hsym.eigenvalues rfl j : ℂ) • hsym.eigenvectorBasis rfl j := + hsym.apply_eigenvectorBasis rfl j + constructor + · intro hmem hμ + rw [support_eq_orthogonal_ker] at hmem + have h0 : inner ℂ (hsym.eigenvectorBasis rfl j) (hsym.eigenvectorBasis rfl j) = 0 := + Submodule.inner_right_of_mem_orthogonal + (ρ.eigenvectorBasis_mem_ker_of_eigenvalue_eq_zero j hμ) hmem + rw [orthonormal_iff_ite.mp (hsym.eigenvectorBasis rfl).orthonormal j j, ite_eq_left rfl] at h0 + exact one_ne_zero h0 + · intro hμ + rw [support, LinearMap.mem_range] + refine ⟨(hsym.eigenvalues rfl j : ℂ)⁻¹ • hsym.eigenvectorBasis rfl j, ?_⟩ + rw [map_smul, hb, smul_smul, inv_mul_cancel₀ (Complex.ofReal_ne_zero.mpr hμ), one_smul] + +/-- **A state in the support is orthogonal to every zero-eigenvalue eigenvector**: if +`ψ ∈ support ρ` and `λⱼ = 0`, then `⟪bⱼ, ψ⟫ = 0`. Since `λⱼ = 0` gives `bⱼ ∈ ker ρ` and +`support = kerᗮ`, the two are orthogonal. This is the formal content of "`|ψ⟩` lies in the support +of `ρ`": `ψ` has no component along the kernel, so its expansion runs over the non-zero +eigenvectors only. -/ +theorem inner_eigenvectorBasis_eq_zero_of_mem_support (ρ : State S) {ψ : S.space} + (hψ : ψ ∈ ρ.support) (j : Fin (Module.finrank ℂ S.space)) + (hj : ρ.isDensity.isSymmetric.eigenvalues rfl j = 0) : + inner ℂ (ρ.isDensity.isSymmetric.eigenvectorBasis rfl j) ψ = 0 := by + rw [support_eq_orthogonal_ker] at hψ + exact Submodule.inner_right_of_mem_orthogonal + (ρ.eigenvectorBasis_mem_ker_of_eigenvalue_eq_zero j hj) hψ + +/-- **Orthogonal supports as a vanishing operator product** — the operator-level +characterization of "the states `ρ`, `σ` have orthogonal supports": the supports are orthogonal +submodules iff the product of the density operators vanishes, + +`ρ.support ⟂ σ.support ↔ ρ.op * σ.op = 0`. + +Commuting the orthogonality (`Submodule.isOrtho_comm`) puts the roles the right way round; then +`support ρ = range ρ.op`, `ρ.op` self-adjoint so `(ker ρ.op)ᗮᗮ = ker ρ.op` +(`support_eq_orthogonal_ker` + `Submodule.orthogonal_orthogonal`), reduces the condition to +`range σ.op ≤ ker ρ.op`, which by `LinearMap.range_le_ker_iff` is exactly `ρ.op ∘ σ.op = 0`, i.e. +`ρ.op * σ.op = 0`. This is the reusable "orthogonal supports" predicate behind the equality +condition of the entropy-of-a-mixture bound (N&C Theorem 11.10). -/ +theorem support_isOrtho_iff_op_mul_eq_zero (ρ σ : State S) : + ρ.support ⟂ σ.support ↔ ρ.op * σ.op = 0 := by + rw [Submodule.isOrtho_comm, Submodule.isOrtho_iff_le, State.support_eq_orthogonal_ker ρ, + Submodule.orthogonal_orthogonal, State.support, LinearMap.range_le_ker_iff, + ContinuousLinearMap.mul_def, ← ContinuousLinearMap.toLinearMap_comp] + have hzero : ((0 : S.space →L[ℂ] S.space) : S.space →ₗ[ℂ] S.space) = 0 := + ContinuousLinearMap.toLinearMap_zero + exact ContinuousLinearMap.coe_injective.eq_iff' hzero + +end State + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Swap.lean b/LeanPool/AxQM/Postulates/API/Swap.lean new file mode 100644 index 0000000000..da1b7a7f51 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Swap.lean @@ -0,0 +1,180 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledZ + +/-! +# AxQM.Postulates.API — the SWAP gate and the symmetry of controlled-`Z` + +The two-qubit `SWAP` gate and the operator identity behind Nielsen & Chuang Exercise 4.18 (the +controlled-`Z` gate is symmetric between the control and target qubits). Compare +`controlledUnitary`, `cnotGate`, and `controlledZGate`. + +## What is formalised + +* `Evolution.swap` — the **`SWAP` gate** `SWAP` on `S ⊗ S`, the closed-system evolution that + exchanges the two factors of an identical-system composite. It is + `Evolution.ofLinearIsometryEquiv` of the factor-swap `TensorProduct.commIsometry`, so it is + grounded in Postulate 5 and its action is `SWAP(x ⊗ y) = y ⊗ x` (`Evolution.swap_op_tmul`). +* `Evolution.swap_op_eq` — the gate as an operator: `SWAP.op = commIsometry` (as a continuous + linear map). It transports the `commIsometry` algebra to the gate. +* `Evolution.swap_comp_self` — `SWAP` is an involution: `SWAP · SWAP = 1` (swapping twice is the + identity). +* `pauliZGate_op_eq_rankOne_sub` — the **spectral decomposition of `Z` at the operator level**: + `Z = |0⟩⟨0| - |1⟩⟨1|`, the qubit-space image of the concrete matrix identity `pauliZ = + outerSelf(ket 0) - outerSelf(ket 1)` (Exercise 2.9). Uses + `toEuclideanCLM_outerSelf_ket : toEuclideanCLM |i⟩⟨i| = |i⟩⟨i|` between the concrete outer product + and the rank-one projector. +* `controlledZGate_swap_conj_op` — **the operator identity of Exercise 4.18:** conjugating the + controlled-`Z` operator by the factor-swap leaves it unchanged, `SWAP · CZ · SWAP = CZ`. It gives + the gate equality (via `Evolution.ext`) stated in [upstream `AxQM/NC/Ch4/Exercise4_18.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_18.lean). + +## Design notes + +* **Why the SWAP-conjugation shape (N&C fidelity).** N&C Exercise 4.18 asks to show, as a circuit + identity, that the controlled-`Z` gate is *symmetric* under interchanging its control and target + qubits: the gate obtained by treating the second qubit as control equals the original. + Interchanging the two qubits of a gate `U` is exactly conjugation by `SWAP` (`SWAP · U · SWAP` + runs `U` with the two qubits swapped), so "controlled-`Z` is symmetric between control and + target" is faithfully the equality `SWAP · CZ · SWAP = CZ` — equivalently, `CZ` commutes with + `SWAP`. This is a full unitary identity (an equality of `Evolution`s), not an "on basis states" + surrogate. +* **Proof.** With `CZ.op = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z` (`controlledZGate_op`), swap-conjugation of a + tensor-product operator interchanges its factors (`TensorProduct.commIsometry_conj_mapL`, in + `ToMathlib`), so `SWAP · CZ · SWAP = I ⊗ |0⟩⟨0| + Z ⊗ |1⟩⟨1|`. Substituting `I = |0⟩⟨0| + |1⟩⟨1|` + (`sum_rankOne_qubitBasis_eq_one`) and `Z = |0⟩⟨0| - |1⟩⟨1|` (`pauliZGate_op_eq_rankOne_sub`) and + expanding by bilinearity of `TensorProduct.mapL`, both sides equal the manifestly symmetric + `|0⟩⟨0|⊗|0⟩⟨0| + |0⟩⟨0|⊗|1⟩⟨1| + |1⟩⟨1|⊗|0⟩⟨0| - |1⟩⟨1|⊗|1⟩⟨1|`, closed by `abel`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The SWAP gate -/ + +/-- **The `SWAP` gate** on `S ⊗ S` (Nielsen & Chuang §1.3.4): the closed-system `Evolution` that +exchanges the two factors of an identical-system composite, `SWAP(x ⊗ y) = y ⊗ x`. It is +`Evolution.ofLinearIsometryEquiv` of the factor-swap isometry `TensorProduct.commIsometry`, so it is +grounded in the `Evolution` primitive with unitarity inherited from that isometry. -/ +def Evolution.swap : Evolution (S ⊗ S) := + Evolution.ofLinearIsometryEquiv (TensorProduct.commIsometry ℂ S.space S.space) + +/-- **Action of the `SWAP` gate** on a product vector: `SWAP(x ⊗ y) = y ⊗ x`. -/ +@[simp] +theorem Evolution.swap_op_tmul (x y : S.space) : + (Evolution.swap (S := S)).op (x ⊗ₜ[ℂ] y) = y ⊗ₜ[ℂ] x := by + rw [Evolution.swap] + have h := Evolution.ofLinearIsometryEquiv_op_apply (S := S ⊗ S) + (TensorProduct.commIsometry ℂ S.space S.space) (x ⊗ₜ[ℂ] y) + rw [h] + exact TensorProduct.comm_tmul ℂ S.space S.space x y + +/-- **Action of the `SWAP` gate on a product pure state:** `SWAP(ψ ⊗ φ) = φ ⊗ ψ`. The +`evolvePure`-level companion of `Evolution.swap_op_tmul`, used to compute circuits built from +`SWAP` on computational-basis inputs one tensor factor at a time. -/ +@[simp] +theorem Evolution.swap_evolvePure_tmul (ψ φ : PureState S) : + (Evolution.swap (S := S)).evolvePure (ψ ⊗ φ) = φ ⊗ ψ := by + apply PureState.ext + rw [Evolution.evolvePure_vec, PureState.tmul_vec, PureState.tmul_vec, Evolution.swap_op_tmul] + +/-- The underlying operator of the `SWAP` gate is the factor-swap `commIsometry`. The bridge from +the `Evolution` gate to the `commIsometry` algebra. -/ +theorem Evolution.swap_op_eq : + (Evolution.swap (S := S)).op + = (TensorProduct.commIsometry ℂ S.space S.space : + S.space ⊗[ℂ] S.space →L[ℂ] S.space ⊗[ℂ] S.space) := by + ext z + rw [Evolution.swap] + have h := Evolution.ofLinearIsometryEquiv_op_apply (S := S ⊗ S) + (TensorProduct.commIsometry ℂ S.space S.space) z + rw [h] + rfl + +/-- **The `SWAP` gate is an involution:** `SWAP · SWAP = 1`. Swapping the two factors twice is the +identity, from the involutivity of `commIsometry` (`TensorProduct.commIsometry_comp_self`). -/ +theorem Evolution.swap_comp_self : + (Evolution.swap (S := S)).comp (Evolution.swap (S := S)) = Evolution.id := by + apply Evolution.ext + rw [Evolution.comp_op, Evolution.id_op, Evolution.swap_op_eq] + exact TensorProduct.commIsometry_comp_self + +/-! ### Spectral decomposition of the Pauli-`Z` gate -/ + +/-- **Bridge:** the concrete outer product `|i⟩⟨i|` (as a matrix) promoted through +`Matrix.toEuclideanCLM` is the rank-one projector `|i⟩⟨i|` on the qubit space: +`toEuclideanCLM (outerSelf (ket i)) = |i⟩⟨i|`. -/ +theorem toEuclideanCLM_outerSelf_ket (i : Fin 2) : + Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) (Concrete.outerSelf (Concrete.ket i)) + = InnerProductSpace.rankOne ℂ (qubitBasis i).vec (qubitBasis i).vec := by + apply ContinuousLinearMap.coe_injective + rw [Matrix.coe_toEuclideanCLM_eq_toEuclideanLin, Concrete.outerSelf, + ← InnerProductSpace.symm_toEuclideanLin_rankOne, LinearEquiv.apply_symm_apply] + rfl + +/-- **Spectral decomposition of the Pauli-`Z` gate at the operator level:** +`Z = |0⟩⟨0| - |1⟩⟨1|`. The qubit-space image of the concrete matrix identity +`Concrete.pauliZ = outerSelf(ket 0) - outerSelf(ket 1)` (Nielsen & Chuang Exercise 2.9), +transported through the `⋆`-algebra map `Matrix.toEuclideanCLM` (which respects subtraction) via +`toEuclideanCLM_outerSelf_ket`. -/ +theorem pauliZGate_op_eq_rankOne_sub : + pauliZGate.op + = InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec + - InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec := by + rw [pauliZGate_op, Concrete.pauliZ_eq_outerSelf_sub, map_sub, + toEuclideanCLM_outerSelf_ket, toEuclideanCLM_outerSelf_ket] + rfl + +/-! ### Symmetry of the controlled-`Z` gate -/ + +/-- **Operator form of Nielsen & Chuang Exercise 4.18** (controlled-`Z` is symmetric between control +and target): conjugating the controlled-`Z` operator by the factor-swap leaves it unchanged, +`SWAP · CZ · SWAP = CZ` at the level of operators. Interchanging the two qubits turns +`|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ Z` into `I ⊗ |0⟩⟨0| + Z ⊗ |1⟩⟨1|` (`TensorProduct.commIsometry_conj_mapL`), +and the two coincide once `I = |0⟩⟨0| + |1⟩⟨1|` and `Z = |0⟩⟨0| - |1⟩⟨1|` are expanded (both are the +symmetric operator `∑_{i,j} (-1)^{ij} |i⟩⟨i| ⊗ |j⟩⟨j|`). -/ +theorem controlledZGate_swap_conj_op : + (Evolution.swap (S := qubit)).op.comp + (controlledZGate.op.comp (Evolution.swap (S := qubit)).op) = controlledZGate.op := by + have h1 : (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec + + InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + = (1 : qubit.space →L[ℂ] qubit.space) := by + have := sum_rankOne_qubitBasis_eq_one + rwa [Fin.sum_univ_two] at this + rw [Evolution.swap_op_eq, controlledZGate_op] + -- Restate the composition at the raw tensor head `qubit.space ⊗[ℂ] qubit.space`, where the + -- `commIsometry`/`mapL` composition algebra applies (the composite `(qubit ⊗ qubit).space` head + -- would block the `add_comp`/conjugation rewrites by presenting a different, defeq, `.comp`). + change (TensorProduct.commIsometry ℂ qubit.space qubit.space : + qubit.space ⊗[ℂ] qubit.space →L[ℂ] qubit.space ⊗[ℂ] qubit.space).comp + ((TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + pauliZGate.op).comp + (TensorProduct.commIsometry ℂ qubit.space qubit.space : + qubit.space ⊗[ℂ] qubit.space →L[ℂ] qubit.space ⊗[ℂ] qubit.space)) + = TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 0).vec (qubitBasis 0).vec) 1 + + TensorProduct.mapL (InnerProductSpace.rankOne ℂ (qubitBasis 1).vec (qubitBasis 1).vec) + pauliZGate.op + rw [ContinuousLinearMap.add_comp, ContinuousLinearMap.comp_add, + TensorProduct.commIsometry_conj_mapL, TensorProduct.commIsometry_conj_mapL, + pauliZGate_op_eq_rankOne_sub, ← h1] + simp only [TensorProduct.mapL_add_left, TensorProduct.mapL_add_right, + TensorProduct.mapL_sub_left, TensorProduct.mapL_sub_right] + abel + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SystemIsoComm.lean b/LeanPool/AxQM/Postulates/API/SystemIsoComm.lean new file mode 100644 index 0000000000..ce47e7bd54 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SystemIsoComm.lean @@ -0,0 +1,453 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM.Postulates.API — the swap system isomorphism and `.toIsometry` unfolding lemmas + +The swap isomorphism and unfolding lemmas for system isomorphisms (`QSystem.Iso`), alongside +`QSystem.Iso.refl/symm/trans/tmul` and `QSystem.assoc` (all defined in `Associator.lean` and +`SystemIso.lean`): + +* `QSystem.Iso.comm` — the **swap** `S ⊗ T ≃ₛ T ⊗ S`, exchanging the two factors of a bipartite + composite (the `QSystem.Iso` packaging of `TensorProduct.commIsometry`). The SWAP on an + *identical-system* composite is also available as an `Evolution` (`Evolution.swap`); this is the + general two-system version, as a `QSystem.Iso`. +* the `.toIsometry`-unfolding lemma family for the combinators + (`refl`/`trans`/`symm`/`tmul`/`comm`), completing `QSystem.assoc_toIsometry`. + +## Use in Problem 4.6 + +`QSystem.Iso.comm` is needed for the Nielsen & Chuang **Problem 4.6** +gate-teleportation identity ("Universality with prior entanglement"). Gate teleportation of a +`CNOT` teleports the two input qubits `q_A, q_B` through the four-qubit resource state, whose two +input halves are `a_in` (of the first Bell pair) and `b_in` (of the second). The two Bell-basis +measurements pair `(q_A, a_in)` and `(q_B, b_in)` — but in the natural register +`(q_A ⊗ q_B) ⊗ ((a_in ⊗ a_out) ⊗ (b_in ⊗ b_out))` these partners are *not* adjacent, so bringing +each input qubit beside its Bell-pair partner (the **two independent single-qubit teleportation +setups** `q_A ⊗ |Φ⁺⟩` and `q_B ⊗ |Φ⁺⟩`, on each of which `teleportation_identity` applies) needs a +swap/braid, which `QSystem.assoc` and `QSystem.Iso.tmul` alone cannot provide. The interchange +reshape `(A ⊗ B) ⊗ (C ⊗ D) ≃ₛ (A ⊗ C) ⊗ (B ⊗ D)` assembled from `assoc`/`tmul`/`comm` +(`AxQM/Postulates/API/Interchange.lean`), and the gate teleportation identity built on it +(`AxQM/Postulates/API/GateTeleportationIdentity.lean`), use `comm` and the `.toIsometry` unfolding +lemmas of this file. + +## What is formalised + +* `QSystem.Iso.comm` / `QSystem.Iso.comm_toIsometry` / `QSystem.Iso.comm_toIsometry_tmul` — the + swap iso, its isometry (`commIsometry`), and its pure-tensor action `(x ⊗ y) ↦ (y ⊗ x)`. +* `QSystem.Iso.refl_toIsometry`, `trans_toIsometry`, `symm_toIsometry`, `tmul_toIsometry` — the + `.toIsometry` of each backbone combinator, unfolded to its underlying isometry (all + definitional). With `QSystem.assoc_toIsometry` and `comm_toIsometry`, these reduce any composite + `QSystem.Iso` to a raw `LinearIsometryEquiv` expression. +* `assoc_symm_toIsometry_tmul_tmul` — the inverse associator on a pure tensor + `(assoc A B C).symm ((a ⊗ b) ⊗ c) = a ⊗ (b ⊗ c)`, the `.symm` companion of the existing + `assoc_toIsometry_tmul_tmul`. +* `PureState.congr_symm_congr` / `PureState.congr_congr_symm` — the **state-level roundtrip + cancellations** for the `PureState.congr` transport bridge: carrying a pure state along `e` and + back along `e.symm` (or vice versa) is the identity. The canonical roundtrip lemmas of the + `PureState.congr` API (`SystemIso.lean` exposes only `congr_vec` / `congr_toState`), the + state-level companions of `QSystem.Iso.symm_toIsometry`. + +## Design notes + +* **Generality.** `comm` is stated over two arbitrary systems `S T`; the `≃ₛ` carries + norm-preservation for free (it is a genuine `QSystem.Iso`), so transporting a state through it + needs no separate normalisation proof. +* **`.toIsometry` unfolding, not applied rewrites.** The applied form `(tmul e f).toIsometry x` is + not matched by `rw`/`simp` (the structure-projection + `≃ₗᵢ` `FunLike` coercion defeats the + discrimination tree) and forces `whnf` blow-up under `erw`. The unfolding lemmas here reduce at + the *function* level (`(tmul e f).toIsometry = congrIsometry …`), after which the well-behaved + Mathlib `TensorProduct.*Isometry` lemmas apply; this is the robust idiom for computing the action + of a composite iso (used by the interchange reshape in `AxQM/Postulates/API/Interchange.lean`). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-! ### Definitional `QSystem.Iso` action lemmas + +The `.toIsometry` of each transport-backbone combinator, unfolded to its underlying +isometry. All hold by `rfl`; they let a composite `QSystem.Iso` be reduced to a raw +`LinearIsometryEquiv` expression, whose action on pure tensors is then computed by the +well-behaved `TensorProduct.*Isometry` simp lemmas. (Rewriting the *applied* form +`(tmul e f).toIsometry (x ⊗ₜ y)` directly is unreliable — the structure-projection coercion is +not matched by `rw`/`simp` and forces `whnf` blow-up under `erw` — so we reduce at the function +level first.) -/ + +/-- `.toIsometry` of the identity iso is the identity isometry. -/ +theorem QSystem.Iso.refl_toIsometry (S : QSystem) : + (QSystem.Iso.refl S).toIsometry = LinearIsometryEquiv.refl ℂ S.space := + rfl + +/-- `.toIsometry` of a composite iso is the composite of the two isometries. -/ +theorem QSystem.Iso.trans_toIsometry {S T U : QSystem} (e : S ≃ₛ T) (f : T ≃ₛ U) : + (e.trans f).toIsometry = e.toIsometry.trans f.toIsometry := + rfl + +/-- `.toIsometry` of an inverse iso is the inverse isometry. -/ +theorem QSystem.Iso.symm_toIsometry {S T : QSystem} (e : S ≃ₛ T) : + e.symm.toIsometry = e.toIsometry.symm := + rfl + +/-- **Double inverse of a system isomorphism is the identity:** `e.symm.symm = e`, from the +underlying `LinearIsometryEquiv.symm_symm`. -/ +theorem QSystem.Iso.symm_symm {S T : QSystem} (e : S ≃ₛ T) : e.symm.symm = e := by + simp only [QSystem.Iso.symm, LinearIsometryEquiv.symm_symm] + +/-- `.toIsometry` of a tensor iso is `TensorProduct.congrIsometry` of the factor isometries. -/ +theorem QSystem.Iso.tmul_toIsometry {S S' T T' : QSystem} (e : S ≃ₛ S') (f : T ≃ₛ T') : + (QSystem.Iso.tmul e f).toIsometry = TensorProduct.congrIsometry e.toIsometry f.toIsometry := + rfl + +/-- The **inverse associator on a pure tensor**: `(assoc A B C).symm ((a ⊗ b) ⊗ c) = a ⊗ (b ⊗ c)`. +The `.symm` companion of `assoc_toIsometry_tmul_tmul`, obtained by inverting it through +injectivity of the associator isometry. -/ +theorem assoc_symm_toIsometry_tmul_tmul {A B C : QSystem} (a : A.space) (b : B.space) + (c : C.space) : + (QSystem.assoc A B C).symm.toIsometry ((a ⊗ₜ[ℂ] b) ⊗ₜ[ℂ] c) = a ⊗ₜ[ℂ] (b ⊗ₜ[ℂ] c) := by + change (QSystem.assoc A B C).toIsometry.symm ((a ⊗ₜ[ℂ] b) ⊗ₜ[ℂ] c) = a ⊗ₜ[ℂ] (b ⊗ₜ[ℂ] c) + apply (QSystem.assoc A B C).toIsometry.injective + -- `(A ⊗ B ⊗ C).space` vs the plain tensor `A.space ⊗[ℂ] B.space ⊗[ℂ] C.space` diverge under + -- `rw`'s syntactic matching even though defeq; `erw` bridges it. + erw [LinearIsometryEquiv.apply_symm_apply] + +/-! ### The swap (commutation) system isomorphism -/ + +/-- The **swap** system isomorphism `S ⊗ T ≃ₛ T ⊗ S`: the two orderings of a bipartite composite +are the same quantum system, with the factors exchanged. The isometry is +`TensorProduct.commIsometry ℂ S.space T.space`. The `⊗`-commutativity of the transport backbone, +a sibling of `QSystem.assoc` and `QSystem.Iso.tmul`. -/ +def QSystem.Iso.comm (S T : QSystem) : (S ⊗ T) ≃ₛ (T ⊗ S) := + ⟨TensorProduct.commIsometry ℂ S.space T.space⟩ + +/-- `.toIsometry` of the swap iso is `TensorProduct.commIsometry`. -/ +theorem QSystem.Iso.comm_toIsometry (S T : QSystem) : + (QSystem.Iso.comm S T).toIsometry = TensorProduct.commIsometry ℂ S.space T.space := + rfl + +/-- The action of `QSystem.Iso.comm` on a pure tensor: `comm (x ⊗ y) = y ⊗ x`. -/ +@[simp] +theorem QSystem.Iso.comm_toIsometry_tmul (S T : QSystem) (x : S.space) (y : T.space) : + (QSystem.Iso.comm S T).toIsometry (x ⊗ₜ[ℂ] y) = y ⊗ₜ[ℂ] x := by + rw [QSystem.Iso.comm_toIsometry] + erw [TensorProduct.commIsometry_apply] + rw [TensorProduct.comm_tmul] + +/-- **Swap naturality.** Reshaping the two factors and then swapping them is the same as swapping +first and then reshaping the (now exchanged) factors: + +`(g ⊗ h).trans (comm S' T') = (comm S T).trans (h ⊗ g)` + +for `g : S ≃ₛ S'`, `h : T ≃ₛ T'`. The commutation of the swap `QSystem.Iso.comm` with the tensor of +two reshapings, both sides acting as `x ⊗ y ↦ h y ⊗ g x`. A backbone naturality square, sibling of +`QSystem.Iso.comm_toIsometry_tmul`; the plumbing that lets a `reducedRight` naturality fact (which +traces out the *left* factor) be read off from the `reducedLeft` API through the swap bridge +`State.reducedRight_congr_comm` (see `State.reducedRight_congr_tmul_refl`). Both the `left`-factor +(`h := refl`) and `right`-factor (`g := refl`) specializations are instances. -/ +theorem QSystem.Iso.tmul_trans_comm {S S' T T' : QSystem} (g : S ≃ₛ S') (h : T ≃ₛ T') : + (QSystem.Iso.tmul g h).trans (QSystem.Iso.comm S' T') + = (QSystem.Iso.comm S T).trans (QSystem.Iso.tmul h g) := by + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + apply TensorProduct.ext' + intro x y + rfl + +/-! ### The left-commutation reshape `A ⊗ (B ⊗ C) ≃ₛ B ⊗ (A ⊗ C)` -/ + +/-- The **left-commutation** system isomorphism `A ⊗ (B ⊗ C) ≃ₛ B ⊗ (A ⊗ C)` — the +transport-backbone counterpart of `TensorProduct.leftComm`. It re-associates to `(A ⊗ B) ⊗ C`, swaps +the front pair to `(B ⊗ A) ⊗ C`, then de-associates to `B ⊗ (A ⊗ C)`, bringing the *middle* factor +`B` to the front while leaving `C` last. Two consumers: it carries a gate acting on the *right* +factor of a data register past a spectator register `A` on the left (the inner isomorphism of the +register-lift `measureObservableCircuit_onRight`), and it is the "shared-`A`" reshape whose +marginals drive the weak-monotonicity bound of Nielsen & Chuang Exercise 11.26 +(`State.vonNeumannMutualInfo_add_le_two_mul_vonNeumannEntropy`). A backbone sibling of +`QSystem.assoc` / `QSystem.Iso.comm` / `QSystem.Iso.tmul`. -/ +def QSystem.Iso.leftComm (A B C : QSystem) : (A ⊗ (B ⊗ C)) ≃ₛ (B ⊗ (A ⊗ C)) := + ((QSystem.assoc A B C).trans ((QSystem.Iso.comm A B).tmul (QSystem.Iso.refl C))).trans + (QSystem.assoc B A C).symm + +/-- The action of `QSystem.Iso.leftComm` on a pure tensor: `a ⊗ (b ⊗ c) ↦ b ⊗ (a ⊗ c)`, bringing +the middle factor to the front. Computed by reducing the composite iso at the function level +(`trans_toIsometry`) and threading the pure-tensor action lemmas for `assoc`, `comm`, and the +tensor of isos through the three stages. -/ +@[simp] +theorem QSystem.Iso.leftComm_toIsometry_tmul (A B C : QSystem) (a : A.space) (b : B.space) + (c : C.space) : + (QSystem.Iso.leftComm A B C).toIsometry (a ⊗ₜ[ℂ] (b ⊗ₜ[ℂ] c)) = b ⊗ₜ[ℂ] (a ⊗ₜ[ℂ] c) := + rfl + +/-- The action of the inverse `leftComm` on a pure tensor: `b ⊗ (a ⊗ c) ↦ a ⊗ (b ⊗ c)`. The `.symm` +companion of `leftComm_toIsometry_tmul`, obtained by inverting it through injectivity of the +`leftComm` isometry. -/ +@[simp] +theorem QSystem.Iso.leftComm_symm_toIsometry_tmul (A B C : QSystem) (a : A.space) (b : B.space) + (c : C.space) : + (QSystem.Iso.leftComm A B C).symm.toIsometry (b ⊗ₜ[ℂ] (a ⊗ₜ[ℂ] c)) = a ⊗ₜ[ℂ] (b ⊗ₜ[ℂ] c) := + rfl + +/-- Reshape-frame identity for the `B ⊗ A` marginal: post-composing `leftComm` with the `assoc` back +to `(B ⊗ A) ⊗ C` is the same as re-associating and swapping the front pair `A ↔ B` in place. Both +send `a ⊗ (b ⊗ c) ↦ (b ⊗ a) ⊗ c`; proved by extensionality on pure tensors. -/ +theorem QSystem.Iso.leftComm_trans_assoc {A B C : QSystem} : + (QSystem.Iso.leftComm A B C).trans (QSystem.assoc B A C) + = (QSystem.assoc A B C).trans ((QSystem.Iso.comm A B).tmul (QSystem.Iso.refl C)) := by + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + refine TensorProduct.ext_threefold' fun a b c => ?_ + simp only [QSystem.Iso.leftComm] + rfl + +/-- Reshape-frame identity for the `A ⊗ C` marginal: post-composing `leftComm` with the front `comm` +`B ⊗ (A ⊗ C) ≃ₛ (A ⊗ C) ⊗ B` is the same as swapping the inner pair `B ↔ C` and re-associating to +`(A ⊗ C) ⊗ B`. Both send `a ⊗ (b ⊗ c) ↦ (a ⊗ c) ⊗ b`; proved by extensionality on pure tensors. -/ +theorem QSystem.Iso.leftComm_trans_comm {A B C : QSystem} : + (QSystem.Iso.leftComm A B C).trans (QSystem.Iso.comm B (A ⊗ C)) + = (QSystem.Iso.tmul (QSystem.Iso.refl A) (QSystem.Iso.comm B C)).trans + (QSystem.assoc A C B) := by + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + refine TensorProduct.ext_threefold' fun a b c => ?_ + simp only [QSystem.Iso.leftComm] + rfl + +/-- Reshape-frame identity: de-associating `A ⊗ (B ⊗ C)` and undoing the `leftComm B A C` swap +equals swapping the front pair `A ↔ B` (`comm A B ⊗ refl C`) then de-associating `(B ⊗ A) ⊗ C`. Both +send `(a ⊗ b) ⊗ c ↦ b ⊗ (a ⊗ c)`; proved by extensionality on triple tensors. The `symm` companion +of `QSystem.Iso.leftComm_trans_assoc`, used to collapse the composite of two single-system dilations +into one joint dilation (`State.dilatedChannelComp_eq_dilatedChannel`). -/ +theorem QSystem.Iso.assoc_symm_trans_leftComm_symm {A B C : QSystem} : + (A.assoc B C).symm.trans (QSystem.Iso.leftComm B A C).symm + = ((QSystem.Iso.comm A B).tmul (QSystem.Iso.refl C)).trans (B.assoc A C).symm := by + apply congrArg QSystem.Iso.mk + apply LinearIsometryEquiv.toLinearEquiv_injective + apply LinearEquiv.toLinearMap_injective + refine TensorProduct.ext_threefold fun a b c => ?_ + simp only [QSystem.Iso.leftComm] + rfl + +/-! ### `PureState.congr` roundtrip cancellation + +Transporting a pure state through a system isomorphism and back is the identity — the state-level +companions of `QSystem.Iso.symm_toIsometry`, proved by pushing to the underlying vector +(`PureState.congr_vec`) and cancelling the isometry with `LinearIsometryEquiv.symm_apply_apply` / +`apply_symm_apply`. These are the roundtrip lemmas the `PureState.congr` bridge lacks +(`SystemIso.lean` exposes only `congr_vec` / `congr_toState`), reusable by any transport proof. -/ + +/-- **`PureState.congr` roundtrip (forward then back).** Transporting a pure state along `e` and +then back along `e.symm` recovers it: `PureState.congr e.symm (PureState.congr e ψ) = ψ`. -/ +theorem PureState.congr_symm_congr {S T : QSystem} (e : S ≃ₛ T) (ψ : PureState S) : + PureState.congr e.symm (PureState.congr e ψ) = ψ := by + apply PureState.ext + rw [PureState.congr_vec, PureState.congr_vec, QSystem.Iso.symm_toIsometry, + LinearIsometryEquiv.symm_apply_apply] + +/-- **`PureState.congr` roundtrip (back then forward).** Transporting a pure state along `e.symm` +and then forward along `e` recovers it: `PureState.congr e (PureState.congr e.symm ψ) = ψ`. -/ +theorem PureState.congr_congr_symm {S T : QSystem} (e : S ≃ₛ T) (ψ : PureState T) : + PureState.congr e (PureState.congr e.symm ψ) = ψ := by + apply PureState.ext + rw [PureState.congr_vec, PureState.congr_vec, QSystem.Iso.symm_toIsometry, + LinearIsometryEquiv.apply_symm_apply] + +/-- **`PureState.congr` is its own inner-product adjoint.** Transporting the *second* argument of an +inner product back along `e.symm` equals transporting the *first* forward along `e`: +`⟨x, PureState.congr e.symm y⟩ = ⟨PureState.congr e x, y⟩`. This is the unitary-adjoint identity +`⟨x, U† y⟩ = ⟨U x, y⟩` for the transport `U = PureState.congr e`, since `e.toIsometry` preserves +inner products (`LinearIsometryEquiv.inner_map_map`) and `congr e.symm` is `e.toIsometry.symm` +(`QSystem.Iso.symm_toIsometry`). The bridge any proof comparing amplitudes across a transported +register needs (e.g. matching a state against a transported computational basis). -/ +theorem PureState.inner_congr_symm {S T : QSystem} (e : S ≃ₛ T) + (x : PureState S) (y : PureState T) : + inner ℂ x.vec (PureState.congr e.symm y).vec + = inner ℂ (PureState.congr e x).vec y.vec := by + rw [PureState.congr_vec, PureState.congr_vec, QSystem.Iso.symm_toIsometry, + ← LinearIsometryEquiv.inner_map_map e.toIsometry x.vec (e.toIsometry.symm y.vec), + LinearIsometryEquiv.apply_symm_apply] + +/-! ### `Evolution.congr` roundtrip cancellation + +The gate-level companions of the `PureState.congr` roundtrips above: transporting a gate through a +system isomorphism and back is the identity. Both reduce, via `Evolution.ext` / +`Evolution.congr_op`, to the operator `conjStarAlgEquiv` roundtrip, where `symm_conjStarAlgEquiv` +(`e.conjStarAlgEquiv.symm = e.symm.conjStarAlgEquiv`) turns the two conjugations into a +`StarAlgEquiv` inverse pair. These are the transport-back lemmas any *gate* placement proof needs +(the `Postulates` `Evolution.congr` API exposes only `congr_op`) — e.g. carrying a circuit computed +on a flattened register back onto the register it was placed on. -/ + +/-- **`Evolution.congr` roundtrip (forward then back).** Transporting a gate along `e` and then back +along `e.symm` recovers it: `Evolution.congr e.symm (Evolution.congr e U) = U`. -/ +theorem Evolution.congr_symm_congr {S T : QSystem} (e : S ≃ₛ T) (U : Evolution S) : + Evolution.congr e.symm (Evolution.congr e U) = U := by + apply Evolution.ext + rw [Evolution.congr_op, Evolution.congr_op, QSystem.Iso.symm_toIsometry, + ← LinearIsometryEquiv.symm_conjStarAlgEquiv, StarAlgEquiv.symm_apply_apply] + +/-- **`Evolution.congr` roundtrip (back then forward).** Transporting a gate along `e.symm` and then +forward along `e` recovers it: `Evolution.congr e (Evolution.congr e.symm U) = U`. -/ +theorem Evolution.congr_congr_symm {S T : QSystem} (e : S ≃ₛ T) (U : Evolution T) : + Evolution.congr e (Evolution.congr e.symm U) = U := by + apply Evolution.ext + rw [Evolution.congr_op, Evolution.congr_op, QSystem.Iso.symm_toIsometry, + ← LinearIsometryEquiv.symm_conjStarAlgEquiv, StarAlgEquiv.apply_symm_apply] + +/-- **`Evolution.congr` is a composition homomorphism.** Transporting a composite gate along a +system isomorphism transports the factors: `Evolution.congr e (a · b) = Evolution.congr e a · +Evolution.congr e b`. Since `Evolution.congr` conjugates the operator by the unital ⋆-algebra +equivalence `e.toIsometry.conjStarAlgEquiv`, this is `map_mul` for that equivalence — the +multiplicative sibling of the `congr` roundtrip lemmas above. A gate placement / reassociation proof +that pushes a transport through a composite circuit needs this. -/ +theorem Evolution.congr_comp {S T : QSystem} (e : S ≃ₛ T) (a b : Evolution S) : + Evolution.congr e (a.comp b) = (Evolution.congr e a).comp (Evolution.congr e b) := by + ext1 + rw [Evolution.congr_op, Evolution.comp_op, Evolution.comp_op, Evolution.congr_op, + Evolution.congr_op, ← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, map_mul] + +/-- **`Evolution.congr` preserves the identity gate.** Transporting the identity evolution along a +system isomorphism is again the identity: `Evolution.congr e Evolution.id = Evolution.id`. Since +`Evolution.congr` conjugates the operator by the unital ⋆-algebra equivalence +`e.toIsometry.conjStarAlgEquiv`, this is `map_one` for that equivalence — the unit sibling of +`congr_comp`, so that `Evolution.congr e` is a monoid homomorphism. -/ +theorem Evolution.congr_id {S T : QSystem} (e : S ≃ₛ T) : + Evolution.congr e Evolution.id = Evolution.id := by + ext1 + rw [Evolution.congr_op, Evolution.id_op, map_one, Evolution.id_op] + +/-- **`Evolution.congr` along the identity isomorphism is the identity map.** Transporting a gate +`U` along the reflexive system isomorphism `QSystem.Iso.refl S` leaves it unchanged: +`Evolution.congr (QSystem.Iso.refl S) U = U`. The reflexivity law of `Evolution.congr` (the +`Evolution` sibling of `PureState.congr_refl` / `State.congr_refl`): the conjugation by +`(Iso.refl S).toIsometry = LinearIsometryEquiv.refl` is `StarAlgEquiv.refl`, which fixes `U.op`. A +proof that transports only *one* factor of a product gate (via `e.tmul (Iso.refl T)`) rewrites the +untouched factor with this. -/ +theorem Evolution.congr_refl {S : QSystem} (U : Evolution S) : + Evolution.congr (QSystem.Iso.refl S) U = U := by + ext1 + rw [Evolution.congr_op, QSystem.Iso.refl_toIsometry, + LinearIsometryEquiv.conjStarAlgEquiv_refl, StarAlgEquiv.coe_refl, id_eq] + +/-- **`Evolution.congr` preserves the monoid unit.** Transporting the unit gate `1` (the identity +evolution) along a system isomorphism is again `1`: `Evolution.congr e 1 = 1`. This is `congr_id` +phrased for the `Evolution`-monoid unit (`Evolution.one_def`) — the `map_one` sibling of +`congr_comp`/`congr_prod`, so `Evolution.congr e` is a monoid homomorphism. Any proof that +transports an identity gate off/onto a register (e.g. an idle-wire budget) rewrites with this. -/ +theorem Evolution.congr_one {S T : QSystem} (e : S ≃ₛ T) : + Evolution.congr e (1 : Evolution S) = 1 := by + simp only [Evolution.one_def, Evolution.congr_id] + +/-- **`Evolution.congr` transports a list product gate-by-gate.** Transporting the sequential +composition (`Evolution`-monoid product) of a list of gates along a system isomorphism is the +product of the transported gates: `Evolution.congr e l.prod = (l.map (Evolution.congr e)).prod`. The +list form of `congr_comp`/`congr_id` (`Evolution.congr e` is a monoid homomorphism), proved by +induction on `l`. A proof that pushes a transport through a whole circuit — a product of +wire-addressed gates — rewrites each gate with this. -/ +theorem Evolution.congr_prod {S T : QSystem} (e : S ≃ₛ T) (l : List (Evolution S)) : + Evolution.congr e l.prod = (l.map (Evolution.congr e)).prod := by + induction l with + | nil => simp only [List.map_nil, List.prod_nil, Evolution.one_def, Evolution.congr_id] + | cons a t ih => + rw [List.prod_cons, Evolution.mul_def, Evolution.congr_comp, ← Evolution.mul_def, + List.map_cons, List.prod_cons, ih] + +/-! ### `State.congr` roundtrip cancellation + +The mixed-state companions of the `PureState.congr` / `Evolution.congr` roundtrips above: +transporting a density operator through a system isomorphism and back is the identity. Reduces, via +`State.ext` / `State.congr_op`, to the operator `conjStarAlgEquiv` roundtrip +(`symm_conjStarAlgEquiv` turns the two conjugations into a `StarAlgEquiv` inverse pair). The +transport-back lemmas any *state* placement proof needs (the `Postulates` `State.congr` API exposes +only `congr_op`) — e.g. reading a marginal of a re-associated state back off the pre-association +product. -/ + +/-- **`State.congr` roundtrip (forward then back).** Transporting a state along `e` and then back +along `e.symm` recovers it: `State.congr e.symm (State.congr e ρ) = ρ`. -/ +theorem State.congr_symm_congr {S T : QSystem} (e : S ≃ₛ T) (ρ : State S) : + State.congr e.symm (State.congr e ρ) = ρ := by + apply State.ext + rw [State.congr_op, State.congr_op, QSystem.Iso.symm_toIsometry, + ← LinearIsometryEquiv.symm_conjStarAlgEquiv, StarAlgEquiv.symm_apply_apply] + +/-- **`State.congr` roundtrip (back then forward).** Transporting a state along `e.symm` and then +forward along `e` recovers it: `State.congr e (State.congr e.symm ρ) = ρ`. -/ +theorem State.congr_congr_symm {S T : QSystem} (e : S ≃ₛ T) (ρ : State T) : + State.congr e (State.congr e.symm ρ) = ρ := by + apply State.ext + rw [State.congr_op, State.congr_op, QSystem.Iso.symm_toIsometry, + ← LinearIsometryEquiv.symm_conjStarAlgEquiv, StarAlgEquiv.apply_symm_apply] + +/-- **`PureState.congr` along the identity is the identity.** Transporting a pure state along the +identity system isomorphism `QSystem.Iso.refl S` leaves it unchanged: +`PureState.congr (QSystem.Iso.refl S) ψ = ψ`. The identity law of the `PureState.congr` +functorial-action API, completing it alongside the composition law `congr_trans` and the roundtrips +above. -/ +theorem PureState.congr_refl {S : QSystem} (ψ : PureState S) : + PureState.congr (QSystem.Iso.refl S) ψ = ψ := by + apply PureState.ext + rw [PureState.congr_vec] + rfl + +/-- **`PureState.congr` is functorial in composition.** Transporting a pure state along a composite +system isomorphism `e.trans f` is transporting along `e` and then along `f`: +`PureState.congr (e.trans f) ψ = PureState.congr f (PureState.congr e ψ)`. The functoriality law +completing the `PureState.congr` transport API (`congr_vec` / the roundtrips above). -/ +theorem PureState.congr_trans {S T U : QSystem} (e : S ≃ₛ T) (f : T ≃ₛ U) (ψ : PureState S) : + PureState.congr (e.trans f) ψ = PureState.congr f (PureState.congr e ψ) := by + apply PureState.ext + simp only [PureState.congr_vec] + rfl + +/-- **`PureState.congr` distributes over the tensor of isomorphisms.** Transporting a product state +`u ⊗ v` along the tensor isomorphism `e.tmul f` is the product of the transports: +`PureState.congr (e.tmul f) (u ⊗ v) = (PureState.congr e u) ⊗ (PureState.congr f v)`. The monoidal +companion of `congr_trans`, riding the action `QSystem.Iso.tmul_toIsometry_tmul`. -/ +theorem PureState.congr_tmul {S S' T T' : QSystem} (e : S ≃ₛ S') (f : T ≃ₛ T') + (u : PureState S) (v : PureState T) : + PureState.congr (QSystem.Iso.tmul e f) (u ⊗ v) + = (PureState.congr e u) ⊗ (PureState.congr f v) := by + apply PureState.ext + simp only [PureState.congr_vec, PureState.tmul_vec, QSystem.Iso.tmul_toIsometry_tmul] + rfl + +/-- **`PureState.congr` along `comm` swaps a product pure state.** Transporting `ψ ⊗ φ` along the +swap isomorphism `QSystem.Iso.comm S T` yields `φ ⊗ ψ`. The `comm` companion of +`PureState.congr_tmul`, riding the action `QSystem.Iso.comm_toIsometry_tmul`; the reusable +ancilla-swap reshaping fact recurring across dilation proofs (e.g. reordering a product ancilla +`ωA ⊗ ωB` in `State.dilatedChannelNoComm_eq_dilatedChannel`). -/ +theorem PureState.congr_comm_tmul {S T : QSystem} (ψ : PureState S) (φ : PureState T) : + PureState.congr (QSystem.Iso.comm S T) (ψ.tmul φ) = φ.tmul ψ := by + apply PureState.ext + simp only [PureState.congr_vec, PureState.tmul_vec, QSystem.Iso.comm_toIsometry_tmul] + rfl + +/-- The `leftComm` isomorphism (backwards) on a product state exchanges the first two factors: +`(φ ⊗ (ψ ⊗ χ)).congr (leftComm A B C).symm = ψ ⊗ (φ ⊗ χ)`. The `leftComm` companion of the +associator transport `pureState_congr_assocSymm`, riding the action +`QSystem.Iso.leftComm_symm_toIsometry_tmul`. -/ +theorem pureState_congr_leftCommSymm {A B C : QSystem} (ψ : PureState A) (φ : PureState B) + (χ : PureState C) : + (φ ⊗ (ψ ⊗ χ)).congr (QSystem.Iso.leftComm A B C).symm = ψ ⊗ (φ ⊗ χ) := by + apply PureState.ext + rw [PureState.congr_vec, PureState.tmul_vec, PureState.tmul_vec, PureState.tmul_vec, + PureState.tmul_vec] + exact QSystem.Iso.leftComm_symm_toIsometry_tmul A B C ψ.vec φ.vec χ.vec + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/SystemIsoCongrTmul.lean b/LeanPool/AxQM/Postulates/API/SystemIsoCongrTmul.lean new file mode 100644 index 0000000000..68fdde1042 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/SystemIsoCongrTmul.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.SystemIsoComm +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProductCongrConj + +/-! +# AxQM.Postulates.API — transport of a product state distributes over the tensor + +Two elementary reshaping laws for transport along system isomorphisms, alongside +`QSystem.Iso.comm` / `QSystem.Iso.tmul` and `PureState.congr_tmul`: + +* `QSystem.Iso.comm_symm` — the inverse of the factor swap is the reversed swap, + `(comm S T)⁻¹ = comm T S`. +* `State.congr_tmul` — the **density-state** companion of `PureState.congr_tmul`: transporting a + product state `ρ ⊗ σ` along a product isomorphism `e ⊗ f` transports each factor separately, + `(e ⊗ f)(ρ ⊗ σ)(e ⊗ f)⁻¹ = (e ρ e⁻¹) ⊗ (f σ f⁻¹)`. + +The proof of `State.congr_tmul` works with the operators (`.op`, `TensorProduct.mapL`) and uses the +lemma `TensorProduct.congrIsometry_conjStarAlgEquiv_mapL`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The inverse of the factor swap is the reversed swap:** `(comm S T)⁻¹ = comm T S`. The +`QSystem.Iso` reading of `TensorProduct.commIsometry_symm`; the swap is its own inverse up to +reversing the factors. -/ +theorem QSystem.Iso.comm_symm (S T : QSystem) : + (QSystem.Iso.comm S T).symm = QSystem.Iso.comm T S := + congrArg QSystem.Iso.mk (TensorProduct.commIsometry_symm (𝕜 := ℂ) (E := S.space) (F := T.space)) + +variable {S S' T T' : QSystem} + +/-- **Transport of a product state distributes over the tensor:** for system isomorphisms +`e : S ≃ₛ S'`, `f : T ≃ₛ T'` and states `ρ` on `S`, `σ` on `T`, + +`(e ⊗ f)(ρ ⊗ σ)(e ⊗ f)⁻¹ = (e ρ e⁻¹) ⊗ (f σ f⁻¹)`, + +i.e. `State.congr (e.tmul f) (ρ.tmul σ) = (ρ.congr e).tmul (σ.congr f)`. The density-state companion +of `PureState.congr_tmul`: the product isomorphism `e ⊗ f` transports each factor of a product state +separately. Proved at the level of operators, where the transport `conjStarAlgEquiv (e ⊗ f)` +distributes over the tensor operator `mapL ρ.op σ.op` by +`TensorProduct.congrIsometry_conjStarAlgEquiv_mapL`. -/ +theorem State.congr_tmul (e : S ≃ₛ S') (f : T ≃ₛ T') (ρ : State S) (σ : State T) : + State.congr (e.tmul f) (ρ.tmul σ) = (State.congr e ρ).tmul (State.congr f σ) := by + have := FiniteDimensional.completeSpace ℂ S.space + have := FiniteDimensional.completeSpace ℂ S'.space + have := FiniteDimensional.completeSpace ℂ T.space + have := FiniteDimensional.completeSpace ℂ T'.space + ext1 + rw [State.congr_op, State.tmul_op, State.tmul_op, State.congr_op, State.congr_op] + exact TensorProduct.congrIsometry_conjStarAlgEquiv_mapL e.toIsometry f.toIsometry ρ.op σ.op + +/-- **Transport of a product gate distributes over the tensor:** for system isomorphisms +`e : S ≃ₛ S'`, `f : T ≃ₛ T'` and gates `U` on `S`, `V` on `T`, +`congr (e ⊗ f) (U ⊗ V) = (congr e U) ⊗ (congr f V)`. The `Evolution` companion of `State.congr_tmul` +(and of `PureState.congr_tmul`): the product isomorphism `e ⊗ f` transports each factor of a product +gate separately. Proved at the level of operators, where the transport `conjStarAlgEquiv (e ⊗ f)` +distributes over the tensor operator `mapL U.op V.op` by +`TensorProduct.congrIsometry_conjStarAlgEquiv_mapL`. -/ +theorem Evolution.congr_tmul (e : S ≃ₛ S') (f : T ≃ₛ T') (U : Evolution S) (V : Evolution T) : + Evolution.congr (e.tmul f) (U.tmul V) = (Evolution.congr e U).tmul (Evolution.congr f V) := by + apply Evolution.ext + rw [Evolution.congr_op, Evolution.tmul_op, Evolution.tmul_op, Evolution.congr_op, + Evolution.congr_op] + exact TensorProduct.congrIsometry_conjStarAlgEquiv_mapL e.toIsometry f.toIsometry U.op V.op + +/-- **Naturality of the idle-front wrap under register transport.** Transporting a gate `E` along +`e : T ≃ₛ T'` and then wrapping it with an idle left factor `S` equals wrapping first and then +transporting along the lifted isomorphism `(Iso.refl S) ⊗ e`: +`(congr e E).onRight S = congr ((Iso.refl S).tmul e) (E.onRight S)`. Since `E.onRight S = 1 ⊗ E`, +this is `Evolution.congr_tmul` on `1 ⊗ E` together with `congr (refl S) 1 = 1` +(`Evolution.congr_id`). Lives here beside `Evolution.congr_tmul` — the corollary it is built from — +rather than with the general `congr` API, as its proof needs the tensor-transport lemma +this file imports. -/ +theorem Evolution.congr_onRight (e : T ≃ₛ T') (E : Evolution T) (S : QSystem) : + (Evolution.congr e E).onRight S + = Evolution.congr ((QSystem.Iso.refl S).tmul e) (E.onRight S) := by + change Evolution.id.tmul (Evolution.congr e E) + = Evolution.congr ((QSystem.Iso.refl S).tmul e) (Evolution.id.tmul E) + rw [Evolution.congr_tmul, Evolution.congr_id] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Teleportation.lean b/LeanPool/AxQM/Postulates/API/Teleportation.lean new file mode 100644 index 0000000000..2f3a32fedc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Teleportation.lean @@ -0,0 +1,287 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledUnitary +public import LeanPool.AxQM.Postulates.API.BellBasis +public import LeanPool.AxQM.Postulates.API.Associator +public import LeanPool.AxQM.Postulates.Measurement + +/-! +# AxQM.Postulates.API — Pauli corrections and Bell-basis measurement + +The two non-CNOT resources of Nielsen & Chuang **Problem 4.6** ("Universality with prior +entanglement"): the **single-qubit unitaries** used as teleportation corrections (the Pauli +byproduct gates) and the **Bell-basis measurement** of a qubit pair. Together with the +four-qubit entangled resource state, these implement a CNOT by gate +teleportation and so form a universal set. + +## What is formalised + +* `pauliZGate` — the Pauli-`Z` gate as an `Evolution qubit`, obtained (like `pauliXGate`) by + promoting `Concrete.pauliZ = !![1,0;0,-1]` through `Matrix.toEuclideanCLM`; unitarity is + transported from `Concrete.pauliZ_mem_unitaryGroup`. `pauliZGate_op_apply_qubitBasis` is the + phase-flip action `Z|i⟩ = (-1)ⁱ |i⟩`. +* `pauliXGate_op_apply_qubitBasis` — the operator-level bit flip `X|i⟩ = |i ⊕ 1⟩`, the + `Evolution.op` form of `pauliXGate_evolvePure_qubitBasis` (from `ControlledUnitary`). +* `pauliByproduct x y` — the **Pauli byproduct** correction `X^y Z^x` (`x, y : Fin 2`) as an + `Evolution qubit`, i.e. a genuine *single-qubit unitary* (resource #1 of Problem 4.6): the + correction applied to the teleported qubit for the Bell-measurement outcome `(x, y)`. + `pauliByproduct_op_apply_qubitBasis` is its computational-basis action + `X^y Z^x |j⟩ = (-1)^{x·j} |j ⊕ y⟩` — the phase `(-1)^{x·j}` from `Z^x` and the bit flip + `j ↦ j ⊕ y` from `X^y`. +* `bellMeasurement` — the **Bell-basis measurement** of a qubit pair (resource #2 of Problem 4.6): + the projective measurement `Measurement.ofOrthonormalBasis bellBasis` of `qubit ⊗ qubit`, with + outcomes indexed by `Fin 2 × Fin 2` and operators the Bell projectors `|β_xy⟩⟨β_xy|` + (`bellMeasurement_op`). +* `teleportation_identity` — the **single-qubit teleportation identity** (Nielsen & Chuang §1.3.7): + for an arbitrary qubit state `|ψ⟩`, re-associating `|ψ⟩ ⊗ |Φ⁺⟩` and grouping the first two qubits, + `|ψ⟩ ⊗ |Φ⁺⟩ = ½ Σ_{x,y} |β_xy⟩ ⊗ (X^y Z^x |ψ⟩)`. A Bell measurement of the first pair then leaves + the third qubit in `X^y Z^x |ψ⟩`, undone by the single-qubit correction `pauliByproduct x y`: the + single-qubit special case of the Problem 4.6 gate-teleportation protocol. Proved directly by + expanding `|ψ⟩` over the computational basis. `teleportation_identity_qubitBasis` is its + specialisation to a basis input `|i⟩` (the concrete form N&C states first). +* `assoc_toIsometry_tmul_bellPhiPlus` / `bellBasisVec_tmul` — the raw tensor-distribution helpers + the identity is assembled from (the associated `v ⊗ |Φ⁺⟩`; the expansion of `|β_xy⟩ ⊗ w`), + building on the general `assoc_toIsometry_tmul_tmul` of `Postulates/API/Associator.lean`. + +## Design notes + +* **Corrections are single-qubit unitaries.** Problem 4.6 allows only single-qubit unitaries as + active operations (besides the Bell measurement and state preparation). Packaging each Pauli + byproduct `X^y Z^x` as an honest `Evolution qubit` records exactly this: the teleportation + correction is an `Evolution` (Postulate 5), so it *is* an admissible + single-qubit gate. `pauliByproduct` is built from `Evolution.comp` of the `x`/`y`-selected + Pauli gates (identity when the bit is `0`). +* **Byproduct convention.** `X^y Z^x` (in this order) is the correction pairing with the Bell + outcome `β_xy`; on `|j⟩` the `Z^x` factor is diagonal, giving `(-1)^{x·j}`, and `X^y` then flips + `j ↦ j ⊕ y`. This is the convention that makes the single-qubit teleportation + identity `|ψ⟩ ⊗ |Φ⁺⟩ = ½ ∑_{x,y} |β_xy⟩ ⊗ (X^y Z^x |ψ⟩)` hold on the nose. +* **Tensor-head friction in the teleportation identity.** The composite `(qubit ⊗ qubit).space` and + the raw `qubit.space ⊗[ℂ] qubit.space` are definitionally equal but present different heads, and + the `bellVec` / `bellBasisVec` summands live at the raw head while the outer tensors (through the + associator and `bellBasisVec ⊗ ·`) sit at the composite head; so the tensor bilinearity lemmas + (`tmul_add`, `add_tmul`, `smul_tmul'`) do not fire across the mismatch. The distribution helpers + restate the outer tensor at the raw head with a `change` before rewriting. The identity + is then a linear identity over the eight three-qubit computational basis vectors: both sides are + fully distributed to `scalar • (|a⟩⊗|b⟩)⊗|c⟩` atoms, and a closing `change` re-elaborates those + atoms with canonical instances (the atoms produced by the two construction paths are defeq but + carry different instance arguments, which `module`'s atom-matching distinguishes) so `module` + closes it. `assoc_toIsometry_tmul_bellPhiPlus`'s own `map_smul`/`map_add` step keeps the + associator's `ℂ`-linearity in term mode (`rw`/`simp` will not rewrite through the + `LinearIsometryEquiv` coercion here). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-! ### The Pauli-`Z` gate -/ + +/-- The **Pauli-`Z` gate** `Z` (the phase flip) as a closed-system `Evolution` of the qubit: +its operator is the concrete matrix `Concrete.pauliZ = !![1,0;0,-1]` promoted through +`Matrix.toEuclideanCLM`, with unitarity transported from `Concrete.pauliZ_mem_unitaryGroup`. -/ +def pauliZGate : Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ + unitary := + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) Concrete.pauliZ_mem_unitaryGroup + +/-- The underlying operator of `pauliZGate` is `Matrix.toEuclideanCLM Concrete.pauliZ`. -/ +@[simp] +theorem pauliZGate_op : + pauliZGate.op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ := rfl + +/-- **The Pauli-`Z` gate phase-flips the computational basis:** `Z|i⟩ = (-1)ⁱ |i⟩`, i.e. +`pauliZGate.op` sends `|i⟩` to `(-1)ⁱ • |i⟩`. -/ +theorem pauliZGate_op_apply_qubitBasis (i : Fin 2) : + pauliZGate.op (qubitBasis i).vec = (-1 : ℂ) ^ (i : ℕ) • (qubitBasis i).vec := by + rw [pauliZGate_op, qubitBasis_vec] + have hof : ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.pauliZ) + (EuclideanSpace.single i 1)).ofLp + = ((-1 : ℂ) ^ (i : ℕ) • (EuclideanSpace.single i 1 : EuclideanSpace ℂ (Fin 2))).ofLp := by + rw [Matrix.ofLp_toEuclideanCLM] + funext j + fin_cases i <;> fin_cases j <;> + simp [Concrete.pauliZ, Matrix.mulVec, dotProduct, EuclideanSpace.single] + exact (WithLp.equiv 2 (Fin 2 → ℂ)).injective hof + +/-- The Pauli-`X` gate action on the computational basis at operator level, `X|i⟩ = |i ⊕ 1⟩` +(the `Evolution.op` form of `pauliXGate_evolvePure_qubitBasis`). -/ +theorem pauliXGate_op_apply_qubitBasis (i : Fin 2) : + pauliXGate.op (qubitBasis i).vec = (qubitBasis (i + 1)).vec := by + rw [← Evolution.evolvePure_vec] + exact congrArg PureState.vec (pauliXGate_evolvePure_qubitBasis i) + +/-! ### The Pauli byproduct correction -/ + +/-- The **Pauli byproduct** `X^y Z^x` (`x, y : Fin 2`) as an `Evolution qubit`: the single-qubit +unitary correction applied to the teleported qubit given a Bell measurement outcome `(x, y)`. For +`y = 0` the `X` factor is the identity, for `y = 1` it is `pauliXGate`; likewise `x` selects +`pauliZGate`. Being a value of `Evolution` (Postulate 5), it is manifestly an admissible +single-qubit gate — resource #1 of Problem 4.6. -/ +def pauliByproduct (x y : Fin 2) : Evolution qubit := + (if y = 0 then Evolution.id else pauliXGate).comp (if x = 0 then Evolution.id else pauliZGate) + +/-- **Computational-basis action of the Pauli byproduct:** `X^y Z^x |j⟩ = (-1)^{x·j} |j ⊕ y⟩`. +The `Z^x` factor contributes the phase `(-1)^{x·j}` and the `X^y` factor the bit flip +`j ↦ j ⊕ y`. -/ +theorem pauliByproduct_op_apply_qubitBasis (x y j : Fin 2) : + (pauliByproduct x y).op (qubitBasis j).vec + = (-1 : ℂ) ^ ((x : ℕ) * (j : ℕ)) • (qubitBasis (j + y)).vec := by + rw [pauliByproduct] + fin_cases x <;> fin_cases y <;> + simp only [Fin.mk_zero, Fin.mk_one, Fin.isValue, Fin.reduceEq, ↓reduceIte, Evolution.comp_op, + Evolution.id_op, ContinuousLinearMap.comp_apply, one_apply_eq_self, + pauliXGate_op_apply_qubitBasis, pauliZGate_op_apply_qubitBasis, map_smul, + Nat.zero_mul, Nat.one_mul, pow_zero, one_smul, add_zero] + +/-! ### The Bell-basis measurement -/ + +/-- The **Bell-basis measurement** of a qubit pair (Problem 4.6 resource #2): the projective +measurement of `qubit ⊗ qubit` in the Bell basis, `Measurement.ofOrthonormalBasis bellBasis`, with +outcomes indexed by `Fin 2 × Fin 2`. It is a genuine `Measurement` (Postulate 3). -/ +def bellMeasurement : Measurement (Fin 2 × Fin 2) (qubit ⊗ qubit) := + Measurement.ofOrthonormalBasis bellBasis + +/-- The Bell-measurement operator for outcome `(x, y)` is the Bell projector `|β_xy⟩⟨β_xy|`. -/ +@[simp] +theorem bellMeasurement_op (p : Fin 2 × Fin 2) : + bellMeasurement.op p = rankOne ℂ (bellBasisVec p.1 p.2) (bellBasisVec p.1 p.2) := by + rw [bellMeasurement, Measurement.ofOrthonormalBasis_op, bellBasis_apply, bellState_vec] + +/-- **The POVM elements of the Bell measurement (Nielsen & Chuang Exercise 4.33).** The POVM +element for outcome `(x, y)` is the projector onto the Bell state, +`bellMeasurement.toPOVM.elements (x, y) = |β_xy⟩⟨β_xy|`. Since each measurement operator is a unit +rank-one projector it equals its own POVM element, so the four Bell projectors are simultaneously +the measurement operators and the POVM elements — the answer N&C asks for. -/ +theorem bellMeasurement_toPOVM_elements_eq_bellProjector (x y : Fin 2) : + bellMeasurement.toPOVM.elements (x, y) + = ((InnerProductSpace.rankOne ℂ) (bellState x y).vec) (bellState x y).vec := by + rw [Measurement.toPOVM_elements] + simp only [bellMeasurement_op] + rw [InnerProductSpace.adjoint_rankOne_comp_self (bellBasisVec_norm x y), bellState_vec] + +/-- **Measuring a Bell state in the Bell basis reads out which Bell state it is:** the Born-rule +probability of outcome `q` on `|β_xy⟩` is `1` if `q = (x, y)` and `0` otherwise. (`bellMeasurement` +is the projective measurement in the Bell basis; `bornProb` is the Born rule, Postulate 3.) +The diagonal case `q = (x, y)` is deterministic because the Bell states are orthonormal +(`bellBasisVec_inner`). -/ +theorem bellMeasurement_bornProb_bellState (x y : Fin 2) (q : Fin 2 × Fin 2) : + bellMeasurement.bornProb ((bellState x y).toState) q = if q = (x, y) then 1 else 0 := by + change bellMeasurement.toPOVM.toPMF (bellState x y).toState.op q = _ + rw [bellMeasurement, Measurement.toPOVM_ofOrthonormalBasis, PureState.toState_op, + POVM.toPMF_rankOne_self, POVM.ofOrthonormalBasis_elements, + ContinuousLinearMap.reApplyInnerSelf_apply, InnerProductSpace.rankOne_apply, + inner_smul_left, bellBasis_apply, bellState_vec, bellState_vec] + simp only [bellBasisVec_inner] + split_ifs with h <;> simp + +/-! ### The single-qubit teleportation identity -/ + +/-- Distribute the tensor `|β_xy⟩ ⊗ w` of a Bell vector with any vector `w`, pulling the Bell +normalisation and sign out to the raw tensor head: +`|β_xy⟩ ⊗ w = (√2)⁻¹ ((|0⟩⊗|y⟩)⊗w + (-1)ˣ (|1⟩⊗|y_bar⟩)⊗w)`. The `change` restates `bellBasisVec`'s +`+`/`•` (which live at the raw `qubit.space ⊗ qubit.space` head) so `TensorProduct.add_tmul` and +`TensorProduct.smul_tmul'` fire on the outer tensor. -/ +theorem bellBasisVec_tmul {S : QSystem} (x y : Fin 2) (w : S.space) : + bellBasisVec x y ⊗ₜ[ℂ] w + = (Real.sqrt 2 : ℂ)⁻¹ • (((qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis y).vec) ⊗ₜ[ℂ] w + + (-1 : ℂ) ^ (x : ℕ) • + (((qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis (y + 1)).vec) ⊗ₜ[ℂ] w)) := by + change ((Real.sqrt 2 : ℂ)⁻¹ • ((qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis y).vec + + (-1 : ℂ) ^ (x : ℕ) • ((qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis (y + 1)).vec)) + : qubit.space ⊗[ℂ] qubit.space) ⊗ₜ[ℂ] w = _ + rw [← TensorProduct.smul_tmul', TensorProduct.add_tmul, ← TensorProduct.smul_tmul'] + +/-- Apply the associator to `v ⊗ |Φ⁺⟩`, distributing the Bell normalisation and re-bracketing to +the left-nested `(v ⊗ ·) ⊗ ·` head: `assoc (v ⊗ |Φ⁺⟩) = (√2)⁻¹ ((v⊗|0⟩)⊗|0⟩ + (v⊗|1⟩)⊗|1⟩)`. +The `change` restates `|Φ⁺⟩`'s `+`/`•` (which live at the raw `qubit.space ⊗ qubit.space` head) so +`TensorProduct.tmul_add` fires on the outer tensor; each pure summand `(v⊗|k⟩)⊗|k⟩` is rewritten +back into `assoc (v ⊗ (|k⟩⊗|k⟩))` by `assoc_toIsometry_tmul_tmul`, and the associator's +`ℂ`-linearity (`map_smul`, `map_add`) then discharges the normalisation and the sum. -/ +theorem assoc_toIsometry_tmul_bellPhiPlus (v : qubit.space) : + (QSystem.assoc qubit qubit qubit).toIsometry (v ⊗ₜ[ℂ] bellPhiPlus.vec) + = (Real.sqrt 2 : ℂ)⁻¹ • ((v ⊗ₜ[ℂ] (qubitBasis 0).vec) ⊗ₜ[ℂ] (qubitBasis 0).vec + + (v ⊗ₜ[ℂ] (qubitBasis 1).vec) ⊗ₜ[ℂ] (qubitBasis 1).vec) := by + have h1 : v ⊗ₜ[ℂ] bellPhiPlus.vec + = (Real.sqrt 2 : ℂ)⁻¹ • (v ⊗ₜ[ℂ] ((qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec) + + v ⊗ₜ[ℂ] ((qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec)) := by + change v ⊗ₜ[ℂ] ((Real.sqrt 2 : ℂ)⁻¹ • ((qubitBasis 0).vec ⊗ₜ[ℂ] (qubitBasis 0).vec + + (qubitBasis 1).vec ⊗ₜ[ℂ] (qubitBasis 1).vec) : qubit.space ⊗[ℂ] qubit.space) = _ + rw [TensorProduct.tmul_smul, TensorProduct.tmul_add] + rw [h1, ← assoc_toIsometry_tmul_tmul v (qubitBasis 0).vec (qubitBasis 0).vec, + ← assoc_toIsometry_tmul_tmul v (qubitBasis 1).vec (qubitBasis 1).vec] + exact (map_smul _ _ _).trans (congrArg _ (map_add _ _ _)) + +-- Distributing both sides over the eight three-qubit computational basis vectors and closing the +-- linear identity by `module` exceeds the default heartbeat budget. +/-- **The single-qubit teleportation identity** (Nielsen & Chuang §1.3.7): for an arbitrary qubit +state `|ψ⟩`, re-associating `|ψ⟩ ⊗ |Φ⁺⟩` (with `|Φ⁺⟩` the shared Bell pair) and grouping the first +two qubits gives +`|ψ⟩ ⊗ |Φ⁺⟩ = ½ Σ_{x,y} |β_xy⟩ ⊗ (X^y Z^x |ψ⟩)`. +Measuring the first pair in the Bell basis therefore leaves the third qubit in `X^y Z^x |ψ⟩`, which +the single-qubit Pauli byproduct correction `pauliByproduct x y` undoes — this is the mechanism of +quantum teleportation, and the single-qubit special case of the gate-teleportation protocol of +Problem 4.6. Proved directly: expand `|ψ⟩ = Σ_i ⟨i|ψ⟩ |i⟩`, distribute both sides to the eight +computational three-qubit basis vectors, and close the resulting linear identity by `module`. -/ +theorem teleportation_identity (v : qubit.space) : + (QSystem.assoc qubit qubit qubit).toIsometry (v ⊗ₜ bellPhiPlus.vec) + = (2 : ℂ)⁻¹ • ∑ p : Fin 2 × Fin 2, + bellBasisVec p.1 p.2 ⊗ₜ (pauliByproduct p.1 p.2).op v := by + have hv : v = v.ofLp 0 • (qubitBasis 0).vec + v.ofLp 1 • (qubitBasis 1).vec := by + have h := (EuclideanSpace.sum_single_ofLp_eq v).symm + rw [Fin.sum_univ_two] at h + simp only [] at h + exact h + rw [assoc_toIsometry_tmul_bellPhiPlus, Fintype.sum_prod_type] + conv_lhs => rw [hv] + conv_rhs => rw [hv] + simp only [Fin.sum_univ_two, TensorProduct.add_tmul, ← TensorProduct.smul_tmul', + pauliByproduct_op_apply_qubitBasis, bellBasisVec_tmul, map_add, map_smul, + TensorProduct.tmul_add, TensorProduct.tmul_smul, Fin.isValue, Fin.val_zero, Fin.val_one, + Nat.mul_zero, Nat.mul_one, pow_zero, pow_one, one_smul, Fin.reduceAdd] + generalize v.ofLp 0 = c₀ + generalize v.ofLp 1 = c₁ + generalize (qubitBasis 0).vec = a + generalize (qubitBasis 1).vec = b + -- A linear identity in the eight computational three-qubit basis vectors, weighted by the + -- amplitudes `c₀, c₁` of `|ψ⟩`; the `change` re-elaborates the tensors with canonical instances + -- so the atoms coincide across both sides, and `module` closes it. + change (Real.sqrt 2 : ℂ)⁻¹ • (c₀ • a ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a + c₁ • b ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a + + (c₀ • a ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b + c₁ • b ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b)) = + (2 : ℂ)⁻¹ • + (c₀ • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a + b ⊗ₜ[ℂ] b ⊗ₜ[ℂ] a) + + c₁ • (1 : ℂ) • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] a ⊗ₜ[ℂ] b + b ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b) + + (c₀ • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b + b ⊗ₜ[ℂ] a ⊗ₜ[ℂ] b) + + c₁ • (1 : ℂ) • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] b ⊗ₜ[ℂ] a + b ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a)) + + (c₀ • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a + (-1 : ℂ) • b ⊗ₜ[ℂ] b ⊗ₜ[ℂ] a) + + c₁ • (-1 : ℂ) • (Real.sqrt 2 : ℂ)⁻¹ • + (a ⊗ₜ[ℂ] a ⊗ₜ[ℂ] b + (-1 : ℂ) • b ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b) + + (c₀ • (Real.sqrt 2 : ℂ)⁻¹ • (a ⊗ₜ[ℂ] b ⊗ₜ[ℂ] b + (-1 : ℂ) • b ⊗ₜ[ℂ] a ⊗ₜ[ℂ] b) + + c₁ • (-1 : ℂ) • (Real.sqrt 2 : ℂ)⁻¹ • + (a ⊗ₜ[ℂ] b ⊗ₜ[ℂ] a + (-1 : ℂ) • b ⊗ₜ[ℂ] a ⊗ₜ[ℂ] a)))) + simp only [smul_smul] + module + +/-- **Per-basis single-qubit teleportation identity:** the `teleportation_identity` for a +computational-basis input `|i⟩`, `assoc (|i⟩ ⊗ |Φ⁺⟩) = ½ Σ_{x,y} |β_xy⟩ ⊗ (X^y Z^x |i⟩)` — the +concrete form in which N&C §1.3.7 first presents teleportation. A direct specialisation of +`teleportation_identity` at `v := |i⟩`. -/ +theorem teleportation_identity_qubitBasis (i : Fin 2) : + (QSystem.assoc qubit qubit qubit).toIsometry ((qubitBasis i).vec ⊗ₜ bellPhiPlus.vec) + = (2 : ℂ)⁻¹ • ∑ p : Fin 2 × Fin 2, + bellBasisVec p.1 p.2 ⊗ₜ (pauliByproduct p.1 p.2).op (qubitBasis i).vec := + teleportation_identity (qubitBasis i).vec + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TensorPowDim.lean b/LeanPool/AxQM/Postulates/API/TensorPowDim.lean new file mode 100644 index 0000000000..def5cd41ae --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TensorPowDim.lean @@ -0,0 +1,61 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PiTensor +public import LeanPool.AxQM.Postulates.API.Qubit +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.PiTensorProduct.Finrank + +/-! +# AxQM.Postulates.API — dimension of a tensor-power system + +The Hilbert-space dimension of the `n`-fold tensor power `S ^⊗ₛ n` of a quantum system `S` is +`(dim S) ^ n`, since its state space is the `n`-ary tensor power `⨂[ℂ] (_ : Fin n), S.space` +(`QSystem.tensorPow_space`) and the finite rank of a tensor product is the product of the ranks +(`Module.finrank_piTensorProduct`). + +This is the dimension arithmetic behind the `n`-qubit register: `dim (qubitⁿ) = 2ⁿ`. + +## Main results + +* `AxQM.QSystem.finrank_tensorPow_space` — `dim (Sⁿ) = (dim S) ^ n`. +* `AxQM.QSystem.dim_tensorPow` — the `QSystem.dim` form of the same. +* `AxQM.finrank_qubit_tensorPow_space` — `dim (qubitⁿ) = 2 ^ n`. +-/ + +@[expose] public section + +namespace AxQM + +open scoped TensorProduct + +/-- **Dimension of a tensor-power system**: the Hilbert-space dimension of `S ^⊗ₛ n` is +`(dim S) ^ n`. The state space of `S ^⊗ₛ n` is `⨂[ℂ] (_ : Fin n), S.space` +(`QSystem.tensorPow_space`), whose finite rank is `∏ (_ : Fin n), finrank ℂ S.space = +(finrank ℂ S.space) ^ n` (`Module.finrank_piTensorProduct`). -/ +theorem QSystem.finrank_tensorPow_space (S : QSystem) (n : ℕ) : + Module.finrank ℂ (S.tensorPow n).space = Module.finrank ℂ S.space ^ n := by + have h : Module.finrank ℂ (S.tensorPow n).space = ∏ _i : Fin n, Module.finrank ℂ S.space := + Module.finrank_piTensorProduct (M := fun _ : Fin n => S.space) + rw [h, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + +/-- **Dimension of a tensor-power system** (`QSystem.dim` companion of +`QSystem.finrank_tensorPow_space`): the dimension of the `n`-fold tensor power `S ^⊗ₛ n` is +`(dim S) ^ n`. Restates `finrank_tensorPow_space` through `QSystem.dim`. -/ +theorem QSystem.dim_tensorPow (S : QSystem) (n : ℕ) : (S.tensorPow n).dim = S.dim ^ n := by + simp only [QSystem.dim]; exact QSystem.finrank_tensorPow_space S n + +/-- **Dimension of the `n`-qubit register**: `dim (qubit ^⊗ₛ n) = 2 ^ n`, since each qubit factor +has dimension `2` (`finrank_qubit_space`). This is the `2ⁿ` bound behind Nielsen & Chuang's +Exercise 12.3 (`n` qubits carry at most `n` bits of classical information). -/ +theorem finrank_qubit_tensorPow_space (n : ℕ) : + Module.finrank ℂ (qubit.tensorPow n).space = 2 ^ n := by + rw [QSystem.finrank_tensorPow_space, finrank_qubit_space] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TensorPowMix.lean b/LeanPool/AxQM/Postulates/API/TensorPowMix.lean new file mode 100644 index 0000000000..e295a5350f --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TensorPowMix.lean @@ -0,0 +1,127 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TensorPowState +public import LeanPool.AxQM.Postulates.API.Mixture + +/-! +# AxQM.Postulates.API — the tensor power of a mixture as an i.i.d. mixture of products + +The **random-coding average** step of the Holevo–Schumacher–Westmoreland theorem (Nielsen & Chuang, +Theorem 12.8, eq. (12.80)) rests on the identity `E(σ_M) = σ_bar^⊗n`: the expected output codeword +of a +length-`n` random product-state code, averaged over the i.i.d. random choice of its `n` letters, +equals the `n`-fold tensor power of the *average* output state `σ_bar = ∑ⱼ pⱼ σⱼ`. + +This file records the underlying algebraic identity — that the `n`-fold tensor power of a mixture is +the mixture (over all length-`n` index sequences, weighted by the i.i.d. product distribution) of +the corresponding product states: + +* **`State.tensorPow_mix`**: `(∑ⱼ pⱼ σⱼ)^⊗n = ∑_s (∏ᵢ p_{sᵢ}) · (⨂ᵢ σ_{sᵢ})`. + +It is the **mixed-state** counterpart of `Ensemble.iidPow_toState` +(`(e.iidPow n).toState = e.toState.tensorPow n`), which is the same identity for an ensemble of +*pure* inputs. HSW needs the mixed version because the objects being averaged are the *channel +outputs* `σⱼ = E(ρⱼ)`, which are generally mixed even when the inputs `ρⱼ` are pure. + +The two supporting facts about the i.i.d. product weight `p_s = ∏ᵢ p_{sᵢ}` (non-negativity and +summation to one) are recorded as `iidProdWeight_nonneg` / `sum_iidProdWeight`; they make +`fun s => ∏ᵢ p_{sᵢ}` a probability distribution over the `|ι|ⁿ` length-`n` index sequences, i.e. the +distribution of the random codeword. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, eq. (12.80). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +omit [Fintype ι] in +/-- The **i.i.d. product weight** `p_s = ∏ᵢ p_{sᵢ}` of a length-`n` index sequence `s : Fin n → ι` +is non-negative, being a product of the non-negative single-letter probabilities `pⱼ`. Together with +`sum_iidProdWeight` this makes `fun s => ∏ᵢ p_{sᵢ}` the probability distribution of the random +length-`n` codeword. -/ +theorem iidProdWeight_nonneg (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (n : ℕ) (s : Fin n → ι) : + 0 ≤ ∏ i, p (s i) := + Finset.prod_nonneg fun i _ => hp (s i) + +/-- The **i.i.d. product weights sum to one**: `∑_{s : Fin n → ι} ∏ᵢ p_{sᵢ} = 1`, so the length-`n` +product weight is a genuine probability distribution over the index sequences. The multiplicativity +of a sum over a product index (`Finset.prod_univ_sum`) collapses it to `∏ᵢ (∑ⱼ pⱼ) = ∏ᵢ 1 = 1`. -/ +theorem sum_iidProdWeight (p : ι → ℝ) (hsum : ∑ i, p i = 1) (n : ℕ) : + ∑ s : Fin n → ι, ∏ i, p (s i) = 1 := by + rw [← Fintype.piFinset_univ, ← Finset.prod_univ_sum, + Finset.prod_congr rfl fun i _ => hsum, Finset.prod_const_one] + +/-- **The tensor power of a mixture is the i.i.d. mixture of product states** (Nielsen & Chuang, +Theorem 12.8, the random-coding average `E(σ_M) = σ_bar^⊗n` of eq. (12.80)). For a finite family of +states `σ : ι → State S` and a probability distribution `p` (`∑ⱼ pⱼ = 1`), the `n`-fold tensor power +of the mixture `σ_bar = ∑ⱼ pⱼ σⱼ` equals the mixture — over all length-`n` index sequences +`s : Fin n → ι`, weighted by the i.i.d. product weight `p_s = ∏ᵢ p_{sᵢ}` (`sum_iidProdWeight`) — of +the product states `σ_s = σ_{s₁} ⊗ ⋯ ⊗ σ_{sₙ}`: + +`(∑ⱼ pⱼ σⱼ)^⊗n = ∑_s (∏ᵢ p_{sᵢ}) · (⨂ᵢ σ_{sᵢ})`. + +This is the mixed-state generalisation of the pure-state `Ensemble.iidPow_toState` +(`(e.iidPow n).toState = e.toState.tensorPow n`): where that averages an ensemble of *pure* inputs, +this averages a distribution over arbitrary *mixed* states — exactly the channel outputs +`σⱼ = E(ρⱼ)` of the HSW random-coding argument, for which the expected output codeword of the random +i.i.d. code equals `σ_bar^⊗n`. + +Proof. Both density operators agree on every elementary tensor `⨂ᵢ xᵢ`. The left side +`σ_bar^⊗n = ⨂ᵢ σ_bar` distributes the sum `σ_bar.op = ∑ⱼ pⱼ σⱼ.op` inside each of the `n` factors by +multilinearity of the `n`-ary tensor (`MultilinearMap.map_sum`, then `MultilinearMap.map_smul_univ` +to pull the products of weights out), giving `∑_s (∏ᵢ p_{sᵢ}) • ⨂ᵢ (σ_{sᵢ}.op xᵢ)`. The right side +is the mixture operator sum `∑_s p_s • (⨂ᵢ σ_{sᵢ}).op`, whose each summand acts on `⨂ᵢ xᵢ` as +`⨂ᵢ (σ_{sᵢ}.op xᵢ)` (`State.piTensor_op`, `PiTensorProduct.mapCLM_tprod`) — matching term by term +(`Complex.ofReal_prod` bridging `↑(∏ᵢ p_{sᵢ}) = ∏ᵢ ↑p_{sᵢ}`). -/ +theorem State.tensorPow_mix (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (σ : ι → State S) (n : ℕ) : + (State.mix p hp hsum σ).tensorPow n + = State.mix (fun s : Fin n → ι => ∏ i, p (s i)) (iidProdWeight_nonneg p hp n) + (sum_iidProdWeight p hsum n) (fun s => State.piTensor fun i => σ (s i)) := by + apply State.ext + rw [State.tensorPow_op] + -- Both operators agree on every elementary tensor `⨂ᵢ xᵢ` (mirroring `Ensemble.iidPow_toState`): + -- the mixture is expanded via `mix_op`/`sum_apply` only *after* it is applied to `⨂ᵢ xᵢ`, so the + -- operator stays on the tensor-power system's space and `rw` matches syntactically. + refine ContinuousLinearMap.ext_tprod fun x => ?_ + -- Left side: distribute `mapCLM (fun _ => σ_bar.op)` over the per-factor sums `σ_bar.op = ∑ⱼ pⱼ + -- σⱼ.op`. + have hL : (PiTensorProduct.mapCLM fun _ : Fin n => (State.mix p hp hsum σ).op) (⨂ₜ[ℂ] i, x i) + = ∑ s : Fin n → ι, (∏ i, (p (s i) : ℂ)) • ⨂ₜ[ℂ] i, (σ (s i)).op (x i) := by + rw [PiTensorProduct.mapCLM_tprod] + simp_rw [State.mix_op, _root_.sum_apply, _root_.smul_apply] + rw [MultilinearMap.map_sum] + simp_rw [MultilinearMap.map_smul_univ, RingHom.id_apply] + -- Right side: expand the mixture only once it is applied to `⨂ᵢ xᵢ`, then match term by term. + -- `change` re-presents the applied sum on the *raw* space `⨂[ℂ] i, S.space` (defeq, since the + -- factor map `(⨂ᵢ σ_{sᵢ}).op` is `mapCLM (fun i => σ_{sᵢ}.op)` by `State.piTensor_op = rfl`), so + -- `ContinuousLinearMap.sum_apply` distributes past the re-bundled tensor-power-system instance. + rw [hL, State.mix_op] + change (∑ s : Fin n → ι, (∏ i, (↑(p (s i)) : ℂ)) • + (PiTensorProduct.tprod ℂ) fun i => (σ (s i)).op (x i)) + = (∑ s : Fin n → ι, (↑(∏ i, p (s i)) : ℂ) • PiTensorProduct.mapCLM fun i => (σ (s i)).op) + ((PiTensorProduct.tprod ℂ) fun i => x i) + rw [_root_.sum_apply] + refine Finset.sum_congr rfl fun s _ => ?_ + rw [_root_.smul_apply, PiTensorProduct.mapCLM_tprod, Complex.ofReal_prod] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TensorPowSplit.lean b/LeanPool/AxQM/Postulates/API/TensorPowSplit.lean new file mode 100644 index 0000000000..4886e30f41 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TensorPowSplit.lean @@ -0,0 +1,334 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PiTensor +public import LeanPool.AxQM.Postulates.PiTensorState +public import LeanPool.AxQM.Postulates.API.SystemIsoComm + +/-! +# AxQM.Postulates.API — splitting a tensor power into factor blocks + +**System isomorphisms** regrouping the `n`-fold symmetric tensor power `S ^⊗ₛ n` into +sub-blocks of factors: + +* the "`succ`" **head-peel** `S ^⊗ₛ (n+1) ≃ₛ S ⊗ (S ^⊗ₛ n)`, splitting off the single head wire — + the tensor-power analogue of `QSystem.binaryPiEquiv`, matching the head-prepend recursion of the + right-nested control register `qtower (n+1) S = S ⊗ qtower n S` (`Core/MultiControlledReduction`); +* its **general-arity** form `S ^⊗ₛ (a+b) ≃ₛ (S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)` at an arbitrary block boundary + `a + b` (the head-peel is the `a = 1` case, up to the singleton collapse) — used + for placing a gate on a contiguous block of wires (via `Evolution.onLeft` across the split); +* the **factor relabelling** `S ^⊗ₛ a ≃ₛ S ^⊗ₛ b` induced by any reindexing `e : Fin a ≃ Fin b` + (which forces `a = b`) — the register cast that identifies two tensor powers of propositionally + equal arity, so gates whose control-arity varies (a placed `Cᵏ(X)`, `k + 1 + b = m`) compose on + one fixed register. + +## What is formalised + +* `QSystem.tensorPowSuccHead S n` — the head-peel isomorphism `S ^⊗ₛ (n+1) ≃ₛ S ⊗ (S ^⊗ₛ n)`, + built from the inner-product `PiTensorProduct` isometries of `ToMathlib`: reindex `Fin (n+1)` as + `Fin 1 ⊕ Fin n` (`reindexₗᵢ`), split the tensor along the `Sum` (`tmulEquivDepₗᵢ`), and collapse + the singleton head factor `⨂ᵢ : Fin 1, S.space ≃ S.space` (`subsingletonEquivₗᵢ`). +* `QSystem.tensorPowSuccHead_toIsometry_tprod` — its **action on a product state**: + `⨂ᵢ |fᵢ⟩ ↦ |f 0⟩ ⊗ (⨂ⱼ |f j.succ⟩)`, the head factor split off from the tail. +* `QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod` — the inverse **cons** action: + `|a⟩ ⊗ (⨂ⱼ |bⱼ⟩) ↦ ⨂ᵢ |(Fin.cons a b) i⟩`, prepending a head wire to a tail register. +* `QSystem.tensorPowOne S` — the one-factor collapse `S ≃ₛ S ^⊗ₛ 1` (the `n = 0` base of the + `qtower`-bridge induction), from the subsingleton-index isometry + `PiTensorProduct.subsingletonEquivₗᵢ`; its action on a vector is `v ↦ ⨂ᵢ v` + (`QSystem.tensorPowOne_toIsometry_apply`). +* `QSystem.blockSplit a b` — the index split `Fin (a+b) ≃ Fin a ⊕ Fin b` (`finSumFinEquiv.symm`) + underlying the block isomorphism, with its inverse `QSystem.blockSplit_symm`. +* `QSystem.tensorPowAdd S a b` — the **general block-split isomorphism** + `S ^⊗ₛ (a+b) ≃ₛ (S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)`, grouping the first `a` factors into the left block and + the last `b` into the right; built by reindexing along `QSystem.blockSplit a b` then the + `Sum`-split `tmulEquivDepₗᵢ` (no singleton collapse — neither block is forced to be one factor). +* `QSystem.tensorPowAdd_toIsometry_tprod` — its **action on a product state**: + `⨂ₖ |fₖ⟩ ↦ (⨂ᵢ |f (Fin.castAdd b i)⟩) ⊗ (⨂ⱼ |f (Fin.natAdd a j)⟩)`, the two blocks read off the + first `a` and last `b` wires. +* `QSystem.tensorPowAdd_symm_toIsometry_tmul_tprod` — the inverse **append** action: + `(⨂ᵢ |uᵢ⟩) ⊗ (⨂ⱼ |vⱼ⟩) ↦ ⨂ₖ |(Fin.append u v) k⟩`, concatenating a length-`a` and a length-`b` + block into one `(a+b)`-fold register. +* `QSystem.tensorPowCongr S e` — the **factor-relabelling isomorphism** `S ^⊗ₛ a ≃ₛ S ^⊗ₛ b` induced + by a wire reindexing `e : Fin a ≃ Fin b`, the **constant-family case of the indexed reindex** + `QSystem.piTensorReindex` (a thin named wrapper for the register-cast role), with product action + `QSystem.tensorPowCongr_toIsometry_tprod` (`⨂ᵢ |fᵢ⟩ ↦ ⨂ⱼ |f (e.symm j)⟩`) and its two + product-pure-state dictionaries `QSystem.tensorPowCongr_congr_piTensor` + (`⨂ₚ ᵢ ψ i ↦ ⨂ₚ ⱼ ψ (e.symm j)`, the constant-family case of + `PureState.piTensor_congr_piTensorReindex`) and `QSystem.tensorPowCongr_symm_congr_piTensor` + (`⨂ₚ ⱼ φ j ↦ ⨂ₚ ᵢ φ (e i)`). Unlike the block splits it does **not** regroup — same system, same + factor count, only the wire labelling changes — so it is the general-arity companion of the + wire-permutation gate `Evolution.permWires` (the `a = b`, `e : Equiv.Perm (Fin a)` case). + +## Design notes + +* **Use in Exercise 4.29.** Connecting the `SWAP`-network wire-permutation gate + `Evolution.permWires` (defined on the *symmetric* `S ^⊗ₛ n`, in + `AxQM/Postulates/API/WirePermutation.lean`) to the multiply-controlled `NOT` `mcCtrl n pauliXGate` + (defined on the *right-nested* tower `qtower n qubit`) requires an isomorphism + `qtower n qubit ≃ₛ qubit ^⊗ₛ (n+1)`. That isomorphism is an induction whose single step is exactly + the head-peel isomorphism (`qtower (n+1) qubit = qubit ⊗ qtower n qubit`, and + `qubit ⊗ (qubit ^⊗ₛ n) ≃ₛ qubit ^⊗ₛ (n+1)`; see `AxQM/Core/QtowerTensorPow.lean`). Likewise + `tensorPowAdd` is what places a Toffoli/`CNOT` on a **block** of `k+1` wires, + `G.onLeft (S ^⊗ₛ b)` transported across `(tensorPowAdd S a b).symm`, before it is relabelled by + `permWires` (see `AxQM/Postulates/API/BlockGatePlacement.lean`). +* **Why the `Fin _ ⊕ Fin _` route.** `S ^⊗ₛ n` is the symmetric `PiTensorProduct` over `Fin n`; + re-indexing it along a `Fin _ ⊕ Fin _` split (`QSystem.headSplit : Fin (n+1) ≃ Fin 1 ⊕ Fin n`, + head `0 ↦ inl 0`, `j.succ ↦ inr j`; or `QSystem.blockSplit : Fin (a+b) ≃ Fin a ⊕ Fin b`) puts it + in the shape the `Sum`-split isometry `tmulEquivDepₗᵢ` (and, for the head-peel, the + singleton-collapse `subsingletonEquivₗᵢ`) consume — the same assembly pattern as + `QSystem.binaryPiIsometry`. +* **Symbolic-boundary elaboration hazards.** At the *symbolic* boundary `a + b` (absent at the + numeral `n + 1` of the head-peel) the block-split isometry hits two `whnf`/`isDefEq` timeouts, + handled by: keeping the index split a **named** def (`QSystem.blockSplit`) so the `.trans` type + unification treats it opaquely (an inline `finSumFinEquiv.symm` is eagerly unfolded and loops); an + explicit constant-family codomain ascription on the `reindexₗᵢ` step. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {n : ℕ} + +/-! ### The index split `Fin (n+1) ≃ Fin 1 ⊕ Fin n` -/ + +/-- The index reshuffle `Fin (n + 1) ≃ Fin 1 ⊕ Fin n` underlying the head-peel isometry: the head +`0` maps to `Sum.inl 0` and each `j.succ` to `Sum.inr j` (see `QSystem.headSplit_symm_inl` / +`QSystem.headSplit_symm_inr`). Built from `finSumFinEquiv` after commuting `n + 1 = 1 + n`. -/ +def QSystem.headSplit (n : ℕ) : Fin (n + 1) ≃ Fin 1 ⊕ Fin n := + (finCongr (Nat.add_comm n 1)).trans finSumFinEquiv.symm + +@[simp] theorem QSystem.headSplit_symm_inl (n : ℕ) : + (QSystem.headSplit n).symm (Sum.inl 0) = (0 : Fin (n + 1)) := by + simp only [QSystem.headSplit, Equiv.symm_trans_apply, Equiv.symm_symm, finCongr_symm, + finCongr_apply] + ext + simp only [finSumFinEquiv_apply_left, Fin.val_cast, Fin.val_castAdd, Fin.val_zero] + +@[simp] theorem QSystem.headSplit_symm_inr (n : ℕ) (j : Fin n) : + (QSystem.headSplit n).symm (Sum.inr j) = j.succ := by + simp only [QSystem.headSplit, Equiv.symm_trans_apply, Equiv.symm_symm, finCongr_symm, + finCongr_apply] + ext + simp only [finSumFinEquiv_apply_right, Fin.val_cast, Fin.val_natAdd, Fin.val_succ] + omega + +/-! ### The head-peel isometry and system isomorphism -/ + +/-- The head-peel isometry `(S ^⊗ₛ (n+1)).space ≃ₗᵢ (S ⊗ S ^⊗ₛ n).space`: reindex the +factors along `QSystem.headSplit`, split off the `Sum` with `tmulEquivDepₗᵢ`, and collapse the +singleton head factor with `subsingletonEquivₗᵢ`. -/ +noncomputable def QSystem.tensorPowSuccHeadIsometry (S : QSystem) (n : ℕ) : + (⨂[ℂ] _ : Fin (n + 1), S.space) ≃ₗᵢ[ℂ] S.space ⊗[ℂ] (⨂[ℂ] _ : Fin n, S.space) := + (PiTensorProduct.reindexₗᵢ ℂ (fun _ : Fin (n + 1) => S.space) (QSystem.headSplit n)).trans + ((PiTensorProduct.tmulEquivDepₗᵢ ℂ (fun _ : Fin 1 ⊕ Fin n => S.space)).symm.trans + (TensorProduct.congrIsometry + (PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun _ : Fin 1 => S.space) 0) + (LinearIsometryEquiv.refl ℂ (⨂[ℂ] _ : Fin n, S.space)))) + +/-- **The head-peel system isomorphism** `S ^⊗ₛ (n+1) ≃ₛ S ⊗ (S ^⊗ₛ n)`: split the `(n+1)`-fold +tensor power into its head wire and the remaining `n`-fold power. The tensor-power `succ` +structural conversion, matching `qtower (n+1) S = S ⊗ qtower n S`. -/ +def QSystem.tensorPowSuccHead (S : QSystem) (n : ℕ) : S ^⊗ₛ (n + 1) ≃ₛ S ⊗ S ^⊗ₛ n := + ⟨QSystem.tensorPowSuccHeadIsometry S n⟩ + +/-- **Action of the head-peel isomorphism on a product state:** `⨂ᵢ |fᵢ⟩ ↦ |f 0⟩ ⊗ (⨂ⱼ |f j.succ⟩)`, +peeling the head factor `f 0` off the front of the tail register. -/ +theorem QSystem.tensorPowSuccHead_toIsometry_tprod (S : QSystem) (n : ℕ) + (f : Fin (n + 1) → S.space) : + (QSystem.tensorPowSuccHead S n).toIsometry (⨂ₜ[ℂ] i, f i) + = f 0 ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, f j.succ) := by + change (QSystem.tensorPowSuccHeadIsometry S n) (⨂ₜ[ℂ] i, f i) = _ + rw [QSystem.tensorPowSuccHeadIsometry, LinearIsometryEquiv.trans_apply, + LinearIsometryEquiv.trans_apply, PiTensorProduct.reindexₗᵢ_tprod, + PiTensorProduct.tmulEquivDepₗᵢ_symm_tprod, TensorProduct.congrIsometry_tmul, + PiTensorProduct.subsingletonEquivₗᵢ_tprod, LinearIsometryEquiv.coe_refl, id_eq] + simp only [QSystem.headSplit_symm_inl, QSystem.headSplit_symm_inr] + +/-- **Inverse (`cons`) action of the head-peel isomorphism:** `|a⟩ ⊗ (⨂ⱼ |bⱼ⟩) ↦ ⨂ᵢ |(Fin.cons a b) +i⟩`, prepending a head wire `a` to the tail register `⨂ⱼ |bⱼ⟩`. -/ +theorem QSystem.tensorPowSuccHead_symm_toIsometry_tmul_tprod (S : QSystem) (n : ℕ) (a : S.space) + (b : Fin n → S.space) : + (QSystem.tensorPowSuccHead S n).toIsometry.symm (a ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, b j)) + = ⨂ₜ[ℂ] i, @Fin.cons n (fun _ => S.space) a b i := by + have h : (QSystem.tensorPowSuccHead S n).toIsometry + (⨂ₜ[ℂ] i, @Fin.cons n (fun _ => S.space) a b i) = a ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, b j) := by + rw [QSystem.tensorPowSuccHead_toIsometry_tprod] + simp only [Fin.cons_zero, Fin.cons_succ] + rfl + apply (QSystem.tensorPowSuccHead S n).toIsometry.injective + exact (LinearIsometryEquiv.apply_symm_apply _ _).trans h.symm + +/-! ### The one-factor collapse `S ≃ₛ S ^⊗ₛ 1` -/ + +/-- **The one-factor collapse** `S ≃ₛ S ^⊗ₛ 1`: a single-factor tensor power is the system itself, +from the subsingleton-index isometry `PiTensorProduct.subsingletonEquivₗᵢ` over `Fin 1`. It is the +`n = 0` base case of the `qtower n qubit ≃ₛ qubit ^⊗ₛ (n+1)` bridge (`Core`) — the analogue, at the +bottom of the induction, of `QSystem.tensorPowSuccHead` at each successor step. -/ +def QSystem.tensorPowOne (S : QSystem) : S ≃ₛ S ^⊗ₛ 1 := + ⟨(PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun _ : Fin 1 => S.space) 0).symm⟩ + +/-- **Action of the one-factor collapse on a vector:** `v ↦ ⨂ᵢ v`, the one-factor product state. -/ +theorem QSystem.tensorPowOne_toIsometry_apply (S : QSystem) (v : S.space) : + (S.tensorPowOne).toIsometry v = ⨂ₜ[ℂ] _ : Fin 1, v := by + change (PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun _ : Fin 1 => S.space) 0).symm v = _ + apply (PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun _ : Fin 1 => S.space) 0).injective + rw [LinearIsometryEquiv.apply_symm_apply, PiTensorProduct.subsingletonEquivₗᵢ_tprod] + +/-! ### The block split `S ^⊗ₛ (a + b) ≃ₛ S ^⊗ₛ a ⊗ S ^⊗ₛ b` -/ + +/-- The index split `Fin (a + b) ≃ Fin a ⊕ Fin b` underlying the block-split isometry: the first `a` +indices go to the left summand and the last `b` to the right (`finSumFinEquiv.symm`). Kept as a +*named* definition (like `QSystem.headSplit`) so the block-split isometry's type unification treats +it opaquely — an inline `finSumFinEquiv.symm` is eagerly unfolded and loops (`whnf` timeout). -/ +def QSystem.blockSplit (a b : ℕ) : Fin (a + b) ≃ Fin a ⊕ Fin b := finSumFinEquiv.symm + +/-- The inverse of `QSystem.blockSplit` is `finSumFinEquiv` (undoing the `.symm`). -/ +@[simp] theorem QSystem.blockSplit_symm (a b : ℕ) : + (QSystem.blockSplit a b).symm = finSumFinEquiv := by + rw [QSystem.blockSplit, Equiv.symm_symm] + +/-- The block-split isometry +`(S ^⊗ₛ (a+b)).space ≃ₗᵢ (S ^⊗ₛ a ⊗ S ^⊗ₛ b).space`: reindex the `a + b` factors along +`QSystem.blockSplit a b : Fin (a+b) ≃ Fin a ⊕ Fin b`, then split the `Sum` with `tmulEquivDepₗᵢ`. +The general-arity companion of `QSystem.tensorPowSuccHeadIsometry` — no singleton collapse is needed +because neither block is forced to be a single factor. + +The reindex step carries an explicit codomain ascription `⨂[Fin a ⊕ Fin b] S.space`: it forces the +reindexed (constant) family into that form up front, avoiding a `whnf` timeout the `.trans` +unification otherwise hits reducing `(blockSplit a b).symm j` under the general symbolic split. -/ +noncomputable def QSystem.tensorPowAddIsometry (S : QSystem) (a b : ℕ) : + (⨂[ℂ] _ : Fin (a + b), S.space) ≃ₗᵢ[ℂ] + (⨂[ℂ] _ : Fin a, S.space) ⊗[ℂ] (⨂[ℂ] _ : Fin b, S.space) := + ((PiTensorProduct.reindexₗᵢ ℂ (fun _ : Fin (a + b) => S.space) (QSystem.blockSplit a b) : + (⨂[ℂ] _ : Fin (a + b), S.space) ≃ₗᵢ[ℂ] ⨂[ℂ] _ : Fin a ⊕ Fin b, S.space)).trans + (PiTensorProduct.tmulEquivDepₗᵢ ℂ (fun _ : Fin a ⊕ Fin b => S.space)).symm + +-- The `QSystem.Iso` ⟨⟩ constructor checks the raw isometry's types against +-- `(S ^⊗ₛ (a+b)).space` / `((S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)).space`; unfolding `piTensor.space` at the +-- *symbolic* index `a + b` is markedly heavier than at the numeral `n + 1` of `tensorPowSuccHead` +-- (but finite — a plain defeq, not a loop), so the default heartbeat budget is raised for it. +/-- **The block-split system isomorphism** `S ^⊗ₛ (a + b) ≃ₛ (S ^⊗ₛ a) ⊗ (S ^⊗ₛ b)`: split the +`(a+b)`-fold tensor power into its first `a` factors and its last `b` factors. The general-arity +tensor-power split, generalising the `succ` head-peel `QSystem.tensorPowSuccHead` (the `a = 1` case, +up to the singleton collapse of the head factor). This is what allows embedding a +gate acting on a contiguous block of `a` wires into the larger `(a+b)`-wire register (via +`Evolution.onLeft` across this split), the wire-addressed placement the `Cᵏ(X)`-block `Toffoli` +reduction of Exercise 4.29 needs. -/ +def QSystem.tensorPowAdd (S : QSystem) (a b : ℕ) : S ^⊗ₛ (a + b) ≃ₛ (S ^⊗ₛ a) ⊗ (S ^⊗ₛ b) := + ⟨QSystem.tensorPowAddIsometry S a b⟩ + +/-- **Action of the block split on a product state:** +`⨂ₖ |fₖ⟩ ↦ (⨂ᵢ |f (Fin.castAdd b i)⟩) ⊗ (⨂ⱼ |f (Fin.natAdd a j)⟩)`, grouping the first `a` factors +into the left block and the last `b` factors into the right block. The block boundaries are the +reduced indices `Fin.castAdd b i` (first `a` wires) and `Fin.natAdd a j` (last `b` wires) — matching +the reduced-index form of the sibling head-peel `tensorPowSuccHead_toIsometry_tprod` (`f 0`, +`f j.succ`). -/ +theorem QSystem.tensorPowAdd_toIsometry_tprod (S : QSystem) (a b : ℕ) (f : Fin (a + b) → S.space) : + (QSystem.tensorPowAdd S a b).toIsometry (⨂ₜ[ℂ] i, f i) + = (⨂ₜ[ℂ] i, f (Fin.castAdd b i)) + ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, f (Fin.natAdd a j)) := by + change (QSystem.tensorPowAddIsometry S a b) (⨂ₜ[ℂ] i, f i) = _ + rw [QSystem.tensorPowAddIsometry, LinearIsometryEquiv.trans_apply, + PiTensorProduct.reindexₗᵢ_tprod, PiTensorProduct.tmulEquivDepₗᵢ_symm_tprod] + simp only [QSystem.blockSplit_symm, finSumFinEquiv_apply_left, finSumFinEquiv_apply_right] + +/-- **Inverse (`append`) action of the block split:** +`(⨂ᵢ |uᵢ⟩) ⊗ (⨂ⱼ |vⱼ⟩) ↦ ⨂ₖ |(Fin.append u v) k⟩`, concatenating a length-`a` block `u` and a +length-`b` block `v` into one `(a+b)`-fold product register. The direction consumed when a gate +built on the first block is transported back onto the full register. -/ +theorem QSystem.tensorPowAdd_symm_toIsometry_tmul_tprod (S : QSystem) (a b : ℕ) + (u : Fin a → S.space) (v : Fin b → S.space) : + (QSystem.tensorPowAdd S a b).toIsometry.symm ((⨂ₜ[ℂ] i, u i) ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, v j)) + = ⨂ₜ[ℂ] k, Fin.append u v k := by + have h : (QSystem.tensorPowAdd S a b).toIsometry (⨂ₜ[ℂ] k, Fin.append u v k) + = (⨂ₜ[ℂ] i, u i) ⊗ₜ[ℂ] (⨂ₜ[ℂ] j, v j) := by + rw [QSystem.tensorPowAdd_toIsometry_tprod] + simp only [Fin.append_left, Fin.append_right] + rfl + apply (QSystem.tensorPowAdd S a b).toIsometry.injective + exact (LinearIsometryEquiv.apply_symm_apply _ _).trans h.symm + +/-! ### Relabelling the factors `S ^⊗ₛ a ≃ₛ S ^⊗ₛ b` -/ + +/-- **The factor-relabelling system isomorphism** `S ^⊗ₛ a ≃ₛ S ^⊗ₛ b` induced by a wire reindexing +`e : Fin a ≃ Fin b`. As a `Fin a ≃ Fin b` forces `a = b`, this re-labels the factors of a tensor +power by `e` without regrouping — the general-arity analogue of the wire-permutation gate +`Evolution.permWires` (the case `a = b`, `e : Equiv.Perm (Fin a)`), here across a *propositional* +size match. + +It is the **constant-family case of the indexed reindex** `QSystem.piTensorReindex`: since +`S ^⊗ₛ a = ⨂ₛ _ : Fin a, S`, reindexing the constant family `fun _ : Fin a => S` along `e` lands on +`⨂ₛ _ : Fin b, S = S ^⊗ₛ b`. A thin named wrapper (matching the register-cast role of its +`tensorPowSuccHead`/`tensorPowAdd` file-siblings), so its action dictionaries below reduce to the +`piTensorReindex` API rather than re-deriving a `reindexₗᵢ` from scratch. + +Its role in Exercise 4.29 is the **register cast**: identifying the register `qubit ^⊗ₛ (k + 1 + b)` +a placed `Cᵏ(X)` gate `Evolution.placedMcCtrlX` lives on with a circuit's fixed ambient register +`qubit ^⊗ₛ m` whenever `k + 1 + b = m` (via `e = finCongr`), so gates of varying control-arity `k` +compose on one register. -/ +def QSystem.tensorPowCongr (S : QSystem) {a b : ℕ} (e : Fin a ≃ Fin b) : S ^⊗ₛ a ≃ₛ S ^⊗ₛ b := + QSystem.piTensorReindex e (fun _ : Fin a => S) + +/-- **Action of the factor relabelling on a product state:** `⨂ᵢ |fᵢ⟩ ↦ ⨂ⱼ |f (e.symm j)⟩` — the +factor that sat at wire `e.symm j` is read at wire `j`. Read off +`QSystem.piTensorReindex_toIsometry` (`tensorPowCongr` *is* the constant-family `piTensorReindex`) +plus `PiTensorProduct.reindexₗᵢ_tprod`. -/ +theorem QSystem.tensorPowCongr_toIsometry_tprod (S : QSystem) {a b : ℕ} (e : Fin a ≃ Fin b) + (f : Fin a → S.space) : + (QSystem.tensorPowCongr S e).toIsometry (⨂ₜ[ℂ] i, f i) = ⨂ₜ[ℂ] j, f (e.symm j) := by + rw [QSystem.tensorPowCongr, QSystem.piTensorReindex_toIsometry] + exact PiTensorProduct.reindexₗᵢ_tprod e f + +/-- **`PureState` action of the factor relabelling:** `⨂ₚ ᵢ ψ i ↦ ⨂ₚ ⱼ ψ (e.symm j)`, the register +cast on product pure states — the **constant-family case** of the general naturality lemma +`PureState.piTensor_congr_piTensorReindex`. The dictionary the register cast is read through when +transporting a placed gate's computational-basis truth table onto the relabelled register. -/ +theorem QSystem.tensorPowCongr_congr_piTensor (S : QSystem) {a b : ℕ} (e : Fin a ≃ Fin b) + (ψ : Fin a → PureState S) : + PureState.congr (QSystem.tensorPowCongr S e) (PureState.piTensor ψ) + = PureState.piTensor fun j => ψ (e.symm j) := + PureState.piTensor_congr_piTensorReindex e ψ + +/-- **`PureState` action of the inverse factor relabelling:** `⨂ₚ ⱼ φ j ↦ ⨂ₚ ᵢ φ (e i)`, the +inverse dictionary of `QSystem.tensorPowCongr_congr_piTensor` (the wire at index `i` reads the +factor that will sit at `e i`). Used to *feed* a product-state input to a gate that was transported +onto the relabelled register. Derived from the forward dictionary by the `PureState.congr` roundtrip +`PureState.congr_symm_congr`. -/ +theorem QSystem.tensorPowCongr_symm_congr_piTensor (S : QSystem) {a b : ℕ} (e : Fin a ≃ Fin b) + (φ : Fin b → PureState S) : + PureState.congr (QSystem.tensorPowCongr S e).symm (PureState.piTensor φ) + = PureState.piTensor fun i => φ (e i) := by + have h : PureState.congr (QSystem.tensorPowCongr S e) (PureState.piTensor fun i => φ (e i)) + = PureState.piTensor φ := by + rw [QSystem.tensorPowCongr_congr_piTensor] + simp only [Equiv.apply_symm_apply] + rfl + exact (congrArg (PureState.congr (QSystem.tensorPowCongr S e).symm) h.symm).trans + (PureState.congr_symm_congr (QSystem.tensorPowCongr S e) _) + +/-- **Backward singleton dictionary:** `(QSystem.tensorPowOne S).symm` collapses the one-factor +product pure state `⨂ₚ ᵢ k i` (`i : Fin 1`) back to its single factor `k 0`. The one-factor sibling +of `QSystem.tensorPowAdd_congr_piTensor` / `QSystem.tensorPowCongr_symm_congr_piTensor`; used to +feed a computational-basis input through a `tensorPowOne` collapse. -/ +theorem QSystem.congr_tensorPowOne_symm_piTensor {S : QSystem} (k : Fin 1 → PureState S) : + PureState.congr (S.tensorPowOne).symm (PureState.piTensor k) = k 0 := by + have h1 : PureState.congr (S.tensorPowOne) (k 0) + = PureState.piTensor (fun _ : Fin 1 => k 0) := by + apply PureState.ext + rw [PureState.congr_vec, PureState.piTensor_vec, QSystem.tensorPowOne_toIsometry_apply] + have hk : k = (fun _ : Fin 1 => k 0) := funext fun i => by rw [Fin.eq_zero i] + rw [hk, ← h1, PureState.congr_symm_congr] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TensorPowState.lean b/LeanPool/AxQM/Postulates/API/TensorPowState.lean new file mode 100644 index 0000000000..5739cc790c --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TensorPowState.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PiTensorState +public import LeanPool.AxQM.Postulates.API.PseudoInverse +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct + +/-! +# AxQM.Postulates.API — the `n`-fold tensor-power state `ρ^⊗n` and its spectrum + +The **`n`-fold tensor power** of a quantum state `ρ : State S` is the product state +`ρ^⊗n = ρ ⊗ ⋯ ⊗ ρ` (`n` factors) living on the tensor-power system `S ^⊗ₛ n`. Because +`S ^⊗ₛ n` is definitionally the indexed composite `⨂ₛ _ : Fin n, S` +(`QSystem.tensorPow_eq`) and the indexed product state `⨂ₚ i, ρ i` is already available +(`State.piTensor`, `Postulates/PiTensorState.lean`), the tensor power is simply +`State.piTensor` over the *constant* family `fun _ : Fin n ↦ ρ`. It inherits its +density-operator status for free. + +This file records its **spectral decomposition**, the key technical input to Nielsen & +Chuang's typical subspace theorem (Theorem 12.5). If `ρ = ∑ₓ λₓ |eₓ⟩⟨eₓ|` is the spectral +decomposition of `ρ` (eigenbasis `e` indexed by `Fin d`, `d = dim S.space`), then `ρ^⊗n` is +diagonal in the **product eigenbasis** `{|e_{κ₁}⟩ ⊗ ⋯ ⊗ |e_{κₙ}⟩ : κ : Fin n → Fin d}`, with +eigenvalue `∏ᵢ λ_{κᵢ}`: + +`ρ^⊗n (|e_{κ}⟩) = (∏ᵢ λ_{κᵢ}) |e_{κ}⟩`. + +The product eigenbasis is the `n`-ary tensor of `ρ`'s eigenbasis +(`OrthonormalBasis.piTensorProduct`, `ToMathlib/`), and the product eigenvalue drops out of +`PiTensorProduct.mapCLM` acting factor-by-factor (`mapCLM_tprod`) together with the +multilinearity of the elementary tensor (`MultilinearMap.map_smul_univ`). Crucially the product +eigenbasis is indexed by the **length-`n` sequences** `Fin n → Fin d`, which are exactly the +sequences the classical theorem of typical sequences (N&C Theorem 12.2, +`ToMathlib/InformationTheory/TypicalSequence.lean`) is stated over — this is what lets Theorem 12.5 +reduce to Theorem 12.2 applied to the eigenvalue distribution `λ`. + +## Main definitions and results + +* `AxQM.State.tensorPow` (`ρ^⊗n`) — the `n`-fold tensor-power state, on `S ^⊗ₛ n`. +* `AxQM.State.tensorPow_op` — its density operator is the `n`-ary tensor + `PiTensorProduct.mapCLM (fun _ ↦ ρ.op)`. +* `AxQM.State.tensorPowEigenbasis` — the product eigenbasis + `⨂ᵢ |e_{κᵢ}⟩` of `ρ^⊗n`, an orthonormal basis of `(S ^⊗ₛ n).space` indexed by + `Fin n → Fin d`. +* `AxQM.State.tensorPow_op_apply_tensorPowEigenbasis` — the spectral action: + `ρ^⊗n |e_κ⟩ = (∏ᵢ λ_{κᵢ}) |e_κ⟩`. + +The typical subspace theorem itself is `LeanPool/AxQM/NC/Ch12/Theorem5.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The **`n`-fold tensor-power state** `ρ^⊗n` of a quantum state `ρ : State S`, living on the +tensor-power system `S ^⊗ₛ n`. It is the indexed product state `⨂ₚ _ : Fin n, ρ` +(`State.piTensor` over the constant family), the `n`-ary analogue of the binary product state +`ρ ⊗ σ` (`State.tmul`); a genuine `State` because the `n`-ary tensor of density operators is a +density operator. -/ +def State.tensorPow (ρ : State S) (n : ℕ) : State (S ^⊗ₛ n) := ⨂ₚ _ : Fin n, ρ + +/-- The density operator of `ρ^⊗n` is the `n`-ary tensor map `PiTensorProduct.mapCLM` of the +single-copy density operator `ρ.op`. Definitional (unfolds `State.piTensor`). -/ +@[simp] +theorem State.tensorPow_op (ρ : State S) (n : ℕ) : + (ρ.tensorPow n).op = PiTensorProduct.mapCLM (fun _ : Fin n => ρ.op) := rfl + +/-- The **product eigenbasis** of `ρ^⊗n`: the `n`-ary tensor `⨂ᵢ |e_{κᵢ}⟩` of `ρ`'s spectral +eigenbasis `e = ρ.isDensity.isSymmetric.eigenvectorBasis` (`OrthonormalBasis.piTensorProduct`), +an orthonormal basis of `(S ^⊗ₛ n).space` indexed by the length-`n` sequences +`κ : Fin n → Fin (dim S.space)`. These sequences are exactly the index type of the classical +`ε`-typical set `Real.typicalSeq`, which is what reduces Nielsen & Chuang's typical subspace +theorem to the classical theorem of typical sequences. -/ +def State.tensorPowEigenbasis (ρ : State S) (n : ℕ) : + OrthonormalBasis (Fin n → Fin (Module.finrank ℂ S.space)) ℂ (S ^⊗ₛ n).space := + OrthonormalBasis.piTensorProduct fun _ : Fin n => ρ.isDensity.isSymmetric.eigenvectorBasis rfl + +-- Unifying `(S ^⊗ₛ n).space` with `⨂[ℂ] i, S.space` exceeds the default recursion depth. +/-- The product eigenbasis vector at a sequence `κ` is the elementary tensor +`⨂ᵢ |e_{κᵢ}⟩` of `ρ`'s eigenvectors. -/ +theorem State.tensorPowEigenbasis_apply (ρ : State S) (n : ℕ) + (κ : Fin n → Fin (Module.finrank ℂ S.space)) : + ρ.tensorPowEigenbasis n κ = + ⨂ₜ[ℂ] i, ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i) := + OrthonormalBasis.piTensorProduct_apply + (fun _ : Fin n => ρ.isDensity.isSymmetric.eigenvectorBasis rfl) κ + +/-- **Spectral action of `ρ^⊗n`** (Nielsen & Chuang, the eigenvalues underlying Eq. 12.42/12.46). +The product eigenvector `|e_κ⟩ = ⨂ᵢ |e_{κᵢ}⟩` is an eigenvector of `ρ^⊗n` with eigenvalue the +product `∏ᵢ λ_{κᵢ}` of the corresponding single-copy eigenvalues: + +`ρ^⊗n |e_κ⟩ = (∏ᵢ λ_{κᵢ}) |e_κ⟩`. + +The operator acts factor-by-factor via `PiTensorProduct.mapCLM_tprod`; each factor `ρ.op |e_{κᵢ}⟩ = +λ_{κᵢ} |e_{κᵢ}⟩` (`State.op_apply_eigenvectorBasis`); and the scalars pull out of the elementary +tensor all at once by multilinearity (`MultilinearMap.map_smul_univ`). -/ +theorem State.tensorPow_op_apply_tensorPowEigenbasis (ρ : State S) (n : ℕ) + (κ : Fin n → Fin (Module.finrank ℂ S.space)) : + (ρ.tensorPow n).op (ρ.tensorPowEigenbasis n κ) = + ((∏ i, ρ.isDensity.isSymmetric.eigenvalues rfl (κ i) : ℝ) : ℂ) • + ρ.tensorPowEigenbasis n κ := by + rw [State.tensorPowEigenbasis_apply, State.tensorPow_op] + calc PiTensorProduct.mapCLM (fun _ : Fin n => ρ.op) + (⨂ₜ[ℂ] i, ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i)) + = ⨂ₜ[ℂ] i, ρ.op (ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i)) := + PiTensorProduct.mapCLM_tprod (fun _ : Fin n => ρ.op) _ + _ = ⨂ₜ[ℂ] i, ((ρ.isDensity.isSymmetric.eigenvalues rfl (κ i) : ℂ) • + ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i)) := by + simp only [State.op_apply_eigenvectorBasis] + _ = (∏ i, (ρ.isDensity.isSymmetric.eigenvalues rfl (κ i) : ℂ)) • + ⨂ₜ[ℂ] i, ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i) := + (PiTensorProduct.tprod ℂ).map_smul_univ _ _ + _ = ((∏ i, ρ.isDensity.isSymmetric.eigenvalues rfl (κ i) : ℝ) : ℂ) • + ⨂ₜ[ℂ] i, ρ.isDensity.isSymmetric.eigenvectorBasis rfl (κ i) := by + rw [Complex.ofReal_prod] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/ToffoliHadamard.lean b/LeanPool/AxQM/Postulates/API/ToffoliHadamard.lean new file mode 100644 index 0000000000..97632d5ebb --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/ToffoliHadamard.lean @@ -0,0 +1,155 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ControlledControlledUnitary +public import LeanPool.AxQM.Postulates.API.ControlledZ + +/-! +# The Toffoli gate as a Hadamard-conjugated doubly-controlled `Z` + +This file provides the algebraic heart of **Nielsen & Chuang, Exercise 4.24** ("verify that +Figure 4.9 implements the Toffoli gate"): the Toffoli gate equals the doubly-controlled-`Z` gate +conjugated on its target by Hadamard, + +`toffoliGate = H₃ · C²(Z) · H₃`, where `H₃ = (H.onRight qubit).onRight qubit`. + +This is the operator identity that makes Figure 4.9 work: `X = H Z H`, so the doubly-controlled +`X` (the Toffoli) is the doubly-controlled `Z` sandwiched by `H` on the target. Figure 4.9's actual +circuit is the drawn gate sequence `P · H₃ · Q · H₃` (with `P`, `Q` the two `Hadamard`-free blocks +of one- and two-qubit gates); combined with the identity here, verifying Figure 4.9 reduces to the +`Hadamard`-free (hence superposition-free) monomial identity `P · Q = C²(Z)`. That final step, and +the Figure 4.9 circuit itself, are in [upstream `AxQM/NC/Ch4/Exercise4_24.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_24.lean). + +## Main results + +* `toffoliGate_eq_hadamardConj_ccontrolledZ` — **the reduction:** `toffoliGate = H₃ · C²(Z) · H₃`, + proved by two applications of the target-conjugation lemma `controlledUnitary_onRight_conj` + (once through each control layer of `C²( · ) = C(C( · ))`) and the single-qubit identity + `H Z H = X` (`hadamardGate_comp_pauliZGate_comp_hadamardGate`). + +Supporting, reusable gate-algebra lemmas: + +* `Evolution.onRight_comp` / `Evolution.onLeft_comp` — the right- and left-factor embeddings are + homomorphisms for composition: `(V ⊗ 1)ᵣ · (W ⊗ 1)ᵣ = (V · W) ⊗ 1` (`onRight V S = 1 ⊗ V`) and + `(V ⊗ 1) · (W ⊗ 1) = (V · W) ⊗ 1` (`onLeft V T = V ⊗ 1`). +* `Evolution.id_onRight` / `Evolution.id_onLeft` — `1.onRight S = 1` and `1.onLeft T = 1`. +* `hadamardGate_comp_self` — `H · H = 1` (a restatement of N&C Exercise 2.52, derived from + `Concrete.hadamardC_mul_self`). +* `hadamardOnRight_sq` / `hadamardOnLeft_sq` — `(H.onRight S)² = 1` and `(H.onLeft S)² = 1`: the + involutivity for the conjugation lemma's two `V · W = 1` side conditions, and the ancilla-wire + `H² = 1` cancellation for `measureObservableCircuit_comp`. + +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +/-- **The right-factor embedding is a composition homomorphism.** With `V.onRight S = 1 ⊗ V`, +composing two right-factor gates composes their targets: `(1 ⊗ V) · (1 ⊗ W) = 1 ⊗ (V · W)`. -/ +theorem Evolution.onRight_comp (S T : QSystem) (V W : Evolution T) : + (V.onRight S).comp (W.onRight S) = (V.comp W).onRight S := by + apply Evolution.ext + change (TensorProduct.mapL 1 V.op).comp (TensorProduct.mapL 1 W.op) + = TensorProduct.mapL 1 (V.op.comp W.op) + rw [← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id] + +/-- **The left-factor embedding is a composition homomorphism.** The mirror of +`Evolution.onRight_comp`: with `V.onLeft T = V ⊗ 1`, composing two left-factor gates composes their +sources, `(V ⊗ 1) · (W ⊗ 1) = (V · W) ⊗ 1`. -/ +theorem Evolution.onLeft_comp (S T : QSystem) (V W : Evolution S) : + (V.onLeft T).comp (W.onLeft T) = (V.comp W).onLeft T := by + apply Evolution.ext + change (TensorProduct.mapL V.op 1).comp (TensorProduct.mapL W.op 1) + = TensorProduct.mapL (V.op.comp W.op) 1 + rw [← TensorProduct.mapL_comp] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.comp_id] + +/-- **The identity gate on the right factor is the identity.** `1.onRight S = 1`. -/ +theorem Evolution.id_onRight (S T : QSystem) : + (Evolution.id : Evolution T).onRight S = Evolution.id := by + apply Evolution.ext + change TensorProduct.mapL (1 : S.space →L[ℂ] S.space) 1 = 1 + exact TensorProduct.mapL_one + +/-- **The identity gate on the left factor is the identity.** `1.onLeft T = 1`. The mirror of +`Evolution.id_onRight`. -/ +theorem Evolution.id_onLeft (S T : QSystem) : + (Evolution.id : Evolution S).onLeft T = Evolution.id := by + apply Evolution.ext + change TensorProduct.mapL (1 : S.space →L[ℂ] S.space) (1 : T.space →L[ℂ] T.space) = 1 + exact TensorProduct.mapL_one + +/-- **The right-factor embedding carries a list product to the product of images:** +`(l.map (· .onRight S)).prod = (l.prod).onRight S`, i.e. `⨂ⱼ (1 ⊗ Uⱼ) = 1 ⊗ (⨂ⱼ Uⱼ)`. The +`List.prod` form of `Evolution.onRight_comp` / `Evolution.id_onRight` (the right-factor embedding is +a monoid homomorphism), proved by induction on the list. Used to reduce a cascade of right-factor +gates (e.g. the classically-controlled single-wire branch gates of a deferred control cascade) to a +single right-factor gate. -/ +theorem Evolution.onRight_list_prod (S T : QSystem) (l : List (Evolution T)) : + (l.map (fun U => U.onRight S)).prod = l.prod.onRight S := by + induction l with + | nil => simp only [List.map_nil, List.prod_nil]; exact (Evolution.id_onRight S T).symm + | cons hd tl ih => + rw [List.map_cons, List.prod_cons, Evolution.mul_def, ih, List.prod_cons, Evolution.mul_def, + Evolution.onRight_comp] + +/-- **The Hadamard gate is an involution:** `H · H = 1`. This is the content of N&C Exercise 2.52, +derived directly from the concrete matrix involution `Concrete.hadamardC_mul_self`. -/ +theorem hadamardGate_comp_self : hadamardGate.comp hadamardGate = Evolution.id := by + apply Evolution.ext + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) Concrete.hadamardC) = 1 + rw [← ContinuousLinearMap.mul_def, ← map_mul, Concrete.hadamardC_mul_self, map_one] + +/-- **The Hadamard gate on the right factor squares to the identity:** +`(H.onRight S) · (H.onRight S) = 1`. Supplies the `V · W = 1` side condition of +`controlledUnitary_onRight_conj` for the outer control layer of the Toffoli. -/ +theorem hadamardOnRight_sq (S : QSystem) : + (hadamardGate.onRight S).comp (hadamardGate.onRight S) = Evolution.id := by + rw [Evolution.onRight_comp, hadamardGate_comp_self, Evolution.id_onRight] + +/-- **The Hadamard gate on the left factor squares to the identity:** +`(H.onLeft S) · (H.onLeft S) = 1`, the left-factor mirror of `hadamardOnRight_sq` — the same +3-lemma reduction via `Evolution.onLeft_comp`, `hadamardGate_comp_self` (`H² = 1`) and +`Evolution.id_onLeft`. Supplies the ancilla-wire `H² = 1` cancellation for +`measureObservableCircuit_comp`. -/ +theorem hadamardOnLeft_sq (S : QSystem) : + (hadamardGate.onLeft S).comp (hadamardGate.onLeft S) = Evolution.id := by + rw [Evolution.onLeft_comp, hadamardGate_comp_self, Evolution.id_onLeft] + +/-- **Toffoli gate as a Hadamard-conjugated doubly-controlled `Z`** (Nielsen & Chuang, +Exercise 4.24, the operator identity behind Figure 4.9). On the three-qubit system +`qubit ⊗ (qubit ⊗ qubit)` (controls `q₁, q₂`, target `q₃`), + +`toffoliGate = (H on q₃) · C²(Z) · (H on q₃)`, + +where `H on q₃ = (hadamardGate.onRight qubit).onRight qubit` and `C²(Z) = ccontrolledUnitary +pauliZGate`. Since `X = H Z H`, the doubly-controlled `X` is the doubly-controlled `Z` conjugated by +`H` on the target. Proved by rewriting `X = H Z H` inside the inner `controlledUnitary` and pushing +the two Hadamards out through each control layer with `controlledUnitary_onRight_conj` (using +`H · H = 1` and `(H.onRight qubit) · (H.onRight qubit) = 1` for its side conditions). -/ +theorem toffoliGate_eq_hadamardConj_ccontrolledZ : + toffoliGate + = ((hadamardGate.onRight qubit).onRight qubit).comp + ((ccontrolledUnitary pauliZGate).comp + ((hadamardGate.onRight qubit).onRight qubit)) := by + rw [toffoliGate, ccontrolledUnitary, ← hadamardGate_comp_pauliZGate_comp_hadamardGate, + ← controlledUnitary_onRight_conj pauliZGate hadamardGate hadamardGate hadamardGate_comp_self, + ccontrolledUnitary, + ← controlledUnitary_onRight_conj (controlledUnitary pauliZGate) + (hadamardGate.onRight qubit) (hadamardGate.onRight qubit) (hadamardOnRight_sq qubit)] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TowerProdMultilinear.lean b/LeanPool/AxQM/Postulates/API/TowerProdMultilinear.lean new file mode 100644 index 0000000000..c163f9e03d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TowerProdMultilinear.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Core.QtowerSingleWireGate + +/-! +# Tensor multilinearity of the tower product state on one wire (N&C Problem 5.2 support) + +The tower product state `towerProd n ψ = ψ 0 ⊗ ⋯ ⊗ ψ n` on `qtower n qubit` +(`Core/QtowerSingleWireGate`) is multilinear in its wires: a scalar multiple placed on one wire's +factor factors out of the whole product. This file records that fact as a reusable `.vec`-level +lemma, the wire-locality counterpart of the single-wire gate action `qtowerSingleWire_evolvePure_*`. + +It is needed wherever a *diagonal* single-wire gate — a phase gate acting on a basis wire — is read +on a computational tower state: such a gate sends the wire to a scalar multiple of itself, and this +lemma pulls that scalar out of the whole product (e.g. the head-controlled phase cascade of the +measured-QFT reduction, `Core/QtowerHeadPhaseControl`). + +## What is formalised + +* `towerProd_vec_update_smul` — replacing wire `i` of `towerProd m ψ` by a scalar multiple + `χ = s • ψᵢ` scales the whole product's state vector by `s`: + + `χ.vec = s • (ψ i).vec → (towerProd m (update ψ i χ)).vec = s • (towerProd m ψ).vec`. + + By recursion on the tower, the head wire peeled with `PureState.tmul_vec` and the scalar pulled + through the tensor product (`TensorProduct.smul_tmul'` on the head, `TensorProduct.tmul_smul` on a + later wire). + +* `towerProd_vec_update_sum_smul` — the **sum form**: replacing wire `i` by a `Fin 2`-superposition + `χ = ∑_z c z • φ z` distributes as the corresponding superposition of the updated products: + + `χ.vec = ∑_z c z • (φ z).vec → + (towerProd m (update ψ i χ)).vec = ∑_z c z • (towerProd m (update ψ i (φ z))).vec`. + + This is the two-term linearity a **non-diagonal** single-wire gate needs: such a gate sends a + basis wire to a superposition of two basis states, and this lemma distributes that superposition + over the whole product. Same recursion as the scalar form, the sum pushed through the tensor + product termwise (`TensorProduct.sum_tmul`/`tmul_sum`). Consumed by every non-diagonal single-wire + gate's tower re-expression — the Hadamard (`Core/QftTowerHadamard`), the reachable rotations + (`Core/FourGateReachableWireTower`), and the Problem 4.3(3) basis-change gate + (`Core/PauliDiagWireTower`). + +The statement is an equation of vectors `PureState.vec`; it has no `PureState`-level form, since a +scalar multiple of a unit vector is not itself a `PureState`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +/-- **Tensor multilinearity of the tower product state on one wire.** Replacing wire `i` of a +product state `towerProd m ψ` by a scalar multiple `χ = s • ψᵢ` scales the whole product's state +vector by `s`: + + `χ.vec = s • (ψ i).vec → (towerProd m (Function.update ψ i χ)).vec = s • (towerProd m ψ).vec`. + +By recursion on the tower: the head wire (`i = 0`) is peeled with `PureState.tmul_vec` and the +scalar pulled out of the left factor (`TensorProduct.smul_tmul'`); a later wire (`i = i'+1`) +recurses on the tail and pulls the scalar out of the right factor (`TensorProduct.tmul_smul`). It is +the +`.vec`-level wire-locality of `towerProd`, the reusable ingredient for reading a diagonal +single-wire gate (a phase on a basis wire) on a computational tower state. -/ +theorem towerProd_vec_update_smul : ∀ (m : ℕ) (ψ : Fin (m + 1) → PureState qubit) + (i : Fin (m + 1)) (s : ℂ) (χ : PureState qubit), χ.vec = s • (ψ i).vec → + (towerProd m (Function.update ψ i χ)).vec = s • (towerProd m ψ).vec + | 0, ψ, i, s, χ, h => by + obtain rfl := Fin.fin_one_eq_zero i + rw [towerProd_zero, towerProd_zero, Function.update_self] + exact h + | m + 1, ψ, i, s, χ, h => by + revert h + refine Fin.cases ?_ ?_ i + · intro h + rw [towerProd_succ, towerProd_succ, Function.update_self, Fin.tail_update_zero, + PureState.tmul_vec, PureState.tmul_vec, h] + exact (TensorProduct.smul_tmul' _ _ _).symm + · intro i' h + rw [towerProd_succ, towerProd_succ, Function.update_of_ne (Fin.succ_ne_zero i').symm, + Fin.tail_update_succ, PureState.tmul_vec, PureState.tmul_vec, + towerProd_vec_update_smul m (Fin.tail ψ) i' s χ h] + exact TensorProduct.tmul_smul _ _ _ + +/-- **Tensor multilinearity of the tower product state on one wire, sum form.** Replacing wire `i` +of a product state `towerProd m ψ` by a `Fin 2`-superposition `χ = ∑_z c z • φ z` distributes as the +superposition of the updated products: + + `χ.vec = ∑_z c z • (φ z).vec → + (towerProd m (update ψ i χ)).vec = ∑_z c z • (towerProd m (update ψ i (φ z))).vec`. + +The two-term counterpart of `towerProd_vec_update_smul` (a single scalar): a **non-diagonal** +single-wire gate sends a basis wire to a superposition of two basis states, and this lemma +distributes that superposition over the whole product. Same recursion as the scalar form — the head +wire (`i = 0`) peeled with `PureState.tmul_vec` and the sum pushed out of the left factor +(`TensorProduct.sum_tmul` / `smul_tmul'`); a later wire (`i = i'+1`) recurses on the tail and pushes +the sum out of the right factor (`TensorProduct.tmul_sum` / `tmul_smul`). The reusable ingredient +for reading a non-diagonal single-wire gate (Hadamard, a reachable rotation, the Problem 4.3(3) +basis-change gate) on a computational tower state. -/ +theorem towerProd_vec_update_sum_smul : ∀ (m : ℕ) (ψ : Fin (m + 1) → PureState qubit) + (i : Fin (m + 1)) (c : Fin 2 → ℂ) (φ : Fin 2 → PureState qubit) (χ : PureState qubit), + χ.vec = ∑ z, c z • (φ z).vec → + (towerProd m (Function.update ψ i χ)).vec + = ∑ z, c z • (towerProd m (Function.update ψ i (φ z))).vec := by + intro m + induction m with + | zero => + intro ψ i c φ χ h + obtain rfl := Fin.fin_one_eq_zero i + simp only [towerProd_zero, Function.update_self] + exact h + | succ N ih => + intro ψ i c φ χ h + refine Fin.cases ?_ ?_ i + · rw [towerProd_succ, Function.update_self, Fin.tail_update_zero, PureState.tmul_vec, h, + TensorProduct.sum_tmul] + refine Finset.sum_congr rfl fun z _ => ?_ + rw [towerProd_succ, Function.update_self, Fin.tail_update_zero, PureState.tmul_vec] + exact (TensorProduct.smul_tmul' (c z) (φ z).vec _).symm + · intro i' + rw [towerProd_succ, Function.update_of_ne (Fin.succ_ne_zero i').symm, + Fin.tail_update_succ, PureState.tmul_vec, ih (Fin.tail ψ) i' c φ χ h, + TensorProduct.tmul_sum] + refine Finset.sum_congr rfl fun z _ => ?_ + rw [towerProd_succ, Function.update_of_ne (Fin.succ_ne_zero i').symm, + Fin.tail_update_succ, PureState.tmul_vec] + exact TensorProduct.tmul_smul (c z) (ψ 0).vec _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TraceDistance.lean b/LeanPool/AxQM/Postulates/API/TraceDistance.lean new file mode 100644 index 0000000000..46ac5278a5 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TraceDistance.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm + +/-! +# AxQM — the quantum trace distance (Nielsen & Chuang §9.2.1) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, §9.2.1 +(equation `(9.11)`, p. 403) define the **trace distance** between two states +`ρ` and `σ` as +``` +D(ρ, σ) ≡ ½ tr|ρ − σ| = ½ ‖ρ − σ‖₁, +``` +half the trace norm of the difference of their density operators. It is the +quantum generalization of the classical trace distance +`AxQM.Concrete.classicalTraceDist` (N&C `(9.1)`), and — as N&C stress in +§9.2.1 — it is a genuine *metric* on the space of density operators. + +`State.traceDistance` takes two states and returns the real number +`½ ‖ρ.op − σ.op‖₁`. + +## Main definitions + +* `State.traceDistance` — the trace distance `½ ‖ρ − σ‖₁` of N&C `(9.11)`. + +## Main statements + +The elementary "distance" properties N&C invoke to justify calling `D` a metric +(the metric axioms, less the triangle inequality): + +* `State.traceDistance_nonneg` — `0 ≤ D(ρ, σ)`. +* `State.traceDistance_self` — `D(ρ, ρ) = 0`. +* `State.traceDistance_comm` — symmetry, `D(ρ, σ) = D(σ, ρ)`. +* `State.traceDistance_eq` — the defining equation, `D(ρ, σ) = ½ ‖ρ.op − σ.op‖₁`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The **quantum trace distance** between two states `ρ` and `σ` of the system `S`, +Nielsen & Chuang `(9.11)`: `D(ρ, σ) ≡ ½ tr|ρ − σ| = ½ ‖ρ − σ‖₁`, half the trace +norm of the difference of their density operators. The quantum generalization of +the classical trace distance `AxQM.Concrete.classicalTraceDist`, and the +trace distance of states, defined through `.op` and `traceNorm`. -/ +noncomputable def State.traceDistance (ρ σ : State S) : ℝ := + (ρ.op - σ.op).traceNorm / 2 + +/-- The defining **equation** for the trace distance: `D(ρ, σ) = ½ ‖ρ.op − σ.op‖₁`. +Unfolds the definition to its underlying trace-norm expression, so that `traceDistance` can be +reasoned about through the trace norm. -/ +theorem State.traceDistance_eq (ρ σ : State S) : + ρ.traceDistance σ = (ρ.op - σ.op).traceNorm / 2 := rfl + +/-- The trace distance is **nonnegative**, `0 ≤ D(ρ, σ)` (a metric is nonnegative); +immediate from `ContinuousLinearMap.traceNorm_nonneg`. -/ +theorem State.traceDistance_nonneg (ρ σ : State S) : 0 ≤ ρ.traceDistance σ := + div_nonneg (ContinuousLinearMap.traceNorm_nonneg _) (by norm_num) + +/-- The trace distance of a state from **itself is zero**, `D(ρ, ρ) = 0` (a metric +vanishes on the diagonal): `ρ.op − ρ.op = 0` and `‖0‖₁ = 0`. -/ +theorem State.traceDistance_self (ρ : State S) : ρ.traceDistance ρ = 0 := by + rw [State.traceDistance, sub_self, ContinuousLinearMap.traceNorm_zero, zero_div] + +/-- The trace distance is **symmetric**, `D(ρ, σ) = D(σ, ρ)` (a metric is symmetric): +`σ.op − ρ.op = −(ρ.op − σ.op)` and `‖−T‖₁ = ‖T‖₁` (`ContinuousLinearMap.traceNorm_neg`). -/ +theorem State.traceDistance_comm (ρ σ : State S) : ρ.traceDistance σ = σ.traceDistance ρ := by + rw [State.traceDistance, State.traceDistance, + ← ContinuousLinearMap.traceNorm_neg (σ.op - ρ.op), neg_sub] + +/-- The trace distance **vanishes exactly on equal states**, `D(ρ, σ) = 0 ↔ ρ = σ`: the +identity-of-indiscernibles axiom of a metric (N&C note in §9.2.1 that `D(ρ, σ) = 0` iff `ρ = σ`). +Since `D(ρ, σ) = ½‖ρ.op − σ.op‖₁`, the trace distance is zero iff the trace norm of the difference +is zero, iff `ρ.op − σ.op = 0` (`ContinuousLinearMap.traceNorm_eq_zero_iff`), iff `ρ.op = σ.op`, +iff `ρ = σ` (`State.ext`). Together with `traceDistance_nonneg`, `traceDistance_self`, +`traceDistance_comm`, and the triangle inequality this is what makes `D` a genuine metric; it turns +`ρ ≠ σ` into `D(ρ, σ) > 0`, as used in the fixed-point arguments of Exercises 9.10–9.13. -/ +theorem State.traceDistance_eq_zero_iff (ρ σ : State S) : ρ.traceDistance σ = 0 ↔ ρ = σ := by + rw [State.traceDistance_eq, div_eq_zero_iff] + constructor + · rintro (h | h) + · rw [ContinuousLinearMap.traceNorm_eq_zero_iff, sub_eq_zero] at h + exact State.ext h + · norm_num at h + · rintro rfl + exact Or.inl (by rw [sub_self, ContinuousLinearMap.traceNorm_zero]) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TrotterProduct.lean b/LeanPool/AxQM/Postulates/API/TrotterProduct.lean new file mode 100644 index 0000000000..d3802de9e2 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TrotterProduct.lean @@ -0,0 +1,187 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.LieTrotter + +/-! +# AxQM.Postulates.API — the Trotter product formula for propagators (N&C Problem 4.3(4)(5)) + +The instantiation for propagators of parts (4) and (5) of Nielsen & Chuang, +Problem 4.3. Writing a Hamiltonian as a sum `H = Σᵢ Hᵢ` of Hamiltonians (each an `Observable`), +one approximates its propagator `exp(-i H Δ)` by the ordered product `∏ᵢ exp(-i Hᵢ Δ)` of the +component propagators: + +* **(4)** the first-order (per-step) error is `O(Δ²)`: + `‖(∏ᵢ exp(-i Hᵢ Δ)) - exp(-i H Δ)‖ ≤ C·Δ²`; +* **(5)** iterating `k` slices of size `Δ = 1/k` accumulates to an `O(1/k)` error: + `‖(∏ᵢ exp(-i Hᵢ /k))ᵏ - exp(-i H)‖ ≤ C/k`, so `[∏ᵢ exp(-i Hᵢ Δ)]ᵏ → exp(-i H) = U`. + +In this library the propagator is the `Evolution` `Observable.propagator H 1 0 t` +(`ℏ = 1`, from time `0` to `t`), whose operator is `exp(-i H.op t)` (N&C eq. 2.91, +`Observable.propagator_op`). Here `exp(-i H)` (`t = 1`) is the unitary `U` these formulas +approximate. + +## What this file provides + +* `Observable.propagator_op_one_zero` — the operator of the unit-`ℏ`, from-`0` propagator as a + Lie–Trotter-shaped exponential: `(H.propagator 1 0 t).op = exp(t • (-i • H.op))`. The bridge + from the physics propagator to the `exp(t • g)` form the Lie–Trotter lemmas are stated in. +* `Observable.exists_norm_prod_propagator_op_sub_propagator_op_le` — **Problem 4.3(4)**: for a + Hamiltonian decomposition `H = Σᵢ Hᵢ` there is `C ≥ 0` with + `‖(∏ᵢ (Hᵢ.propagator 1 0 Δ).op) - (H.propagator 1 0 Δ).op‖ ≤ C·Δ²` for every `Δ ∈ [0, 1]`. +* `Observable.exists_norm_prod_propagator_op_pow_sub_propagator_op_le` — **Problem 4.3(5)**: there + is `C ≥ 0` with `‖(∏ᵢ (Hᵢ.propagator 1 0 (1/k)).op)ᵏ - (H.propagator 1 0 1).op‖ ≤ C/k` for every + `k ≥ 1`; the right-hand propagator `(H.propagator 1 0 1).op = exp(-i H) = U`. + +## Design notes + +* **The operator algebra is itself the Banach algebra.** The continuous endomorphisms + `S.space →L[ℂ] S.space` form a Banach algebra, so the Lie–Trotter error bounds + (`NormedSpace.exists_norm_prod_exp_smul_sub_exp_smul_sum_le` and + `NormedSpace.exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le`, + `ToMathlib/Analysis/Normed/Algebra/LieTrotter.lean`) apply **directly** to the propagator + operators — no matrix transport is needed. Taking the ordered generators `gᵢ = -i • Hᵢ.op`, + the factor `exp(t • gᵢ)` is exactly `(Hᵢ.propagator 1 0 t).op` and `exp(t • Σ gᵢ)` is + `(H.propagator 1 0 t).op` (using `H.op = Σᵢ Hᵢ.op`), so the abstract bound becomes the physics + bound verbatim. +* **The trivial system.** A `QSystem` may have a zero-dimensional state space, in which case + `‖1‖ = 0` and those lemmas' `NormOneClass` hypothesis fails. That case is handled separately: + the operator ring `S.space →L[ℂ] S.space` is then a `Subsingleton`, every two operators are + equal, and the bound holds trivially with `C = 0`. +* **A general Hamiltonian sum, specialising to Pauli strings.** N&C write `H = Σ_g h_g g` over the + `4ⁿ` Pauli strings `g` and Trotterise that sum. The statements here take an *arbitrary* ordered + decomposition `H = Σᵢ Hᵢ` of the Hamiltonian into Hamiltonians — the faithful, reusable physics + content of (4)/(5) (Trotterising a Hamiltonian sum). N&C's literal form is the specialisation in + which the `Hᵢ` are the Pauli-string Hamiltonians `h_g g` of the part-(2) expansion + (`Observable.exists_real_pauliString_expansion`), so `H = i ln U` and the `4ⁿ` term count is + absorbed into `C` (N&C's `O(4ⁿ Δ²)`/`O(4ⁿ Δ)`). Building each `h_g g` as an `Observable` on + `qudit (2ⁿ)` from the matrix-level Pauli expansion (an operator↔matrix transport) is not + formalised here; it does not change the physics captured here. + +The statement of Problem 4.3 is in [upstream `AxQM/NC/Ch4/Problem4_3.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Problem4_3.lean). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- The operator of the unit-`ℏ`, from-time-`0` **propagator** written in Lie–Trotter form: +`(H.propagator 1 0 t).op = exp(t • (-i • H.op))`. Reading the physical exponent +`-i H.op (t - 0) / 1` (N&C eq. 2.91, `Observable.propagator_op`) as `t •` (a real scalar) times the +fixed generator `-i • H.op` puts the propagator into the `exp(t • g)` shape the Lie–Trotter +error bounds are stated in, which is what lets those bounds transfer to propagators verbatim. -/ +theorem Observable.propagator_op_one_zero (H : Observable S) (t : ℝ) : + (H.propagator 1 0 t).op = NormedSpace.exp (t • ((-Complex.I) • H.op)) := by + rw [Observable.propagator_op, ← Complex.coe_smul, smul_smul] + congr 2 + push_cast + ring + +/-- The **generators sum to the generator of the sum**: if a Hamiltonian is the ordered sum +`H = Σᵢ Hᵢ` (`H.op = (Hs.map Observable.op).sum`), then the Lie–Trotter generators `-i • Hᵢ.op` +sum to `-i • H.op`. This is the sum half of the bridge from a Hamiltonian decomposition to the +Lie–Trotter lemmas' `exp(t • Σᵢ gᵢ)`; both Trotter error bounds below use it to rewrite +`-i • H.op` as the sum of the generator list. -/ +theorem Observable.sum_map_neg_I_smul_op {H : Observable S} {Hs : List (Observable S)} + (hH : H.op = (Hs.map Observable.op).sum) : + (Hs.map fun Hᵢ => (-Complex.I) • Hᵢ.op).sum = (-Complex.I) • H.op := by + rw [hH, List.smul_sum, List.map_map]; rfl + +/-- The **list of component propagator operators equals the list of Lie–Trotter factors**: for every +time `t`, `(Hᵢ.propagator 1 0 t).op = exp(t • (-i • Hᵢ.op))` factor by factor +(`Observable.propagator_op_one_zero`), so the two mapped lists agree. This is the product half of +the bridge from a Hamiltonian decomposition to the Lie–Trotter lemmas' `∏ᵢ exp(t • gᵢ)`; both +Trotter error bounds below use it to identify the product of component propagators with the +Lie–Trotter product. -/ +theorem Observable.map_propagator_op_eq_map_exp_smul (Hs : List (Observable S)) (t : ℝ) : + (Hs.map fun Hᵢ => (Hᵢ.propagator 1 0 t).op) + = (Hs.map fun Hᵢ => (-Complex.I) • Hᵢ.op).map fun g => NormedSpace.exp (t • g) := by + rw [List.map_map] + exact List.map_congr_left fun Hᵢ _ => Hᵢ.propagator_op_one_zero t + +/-- **Nielsen & Chuang, Problem 4.3(4): first-order Trotter error of a propagator.** If a +Hamiltonian `H` is a sum `H = Σᵢ Hᵢ` of Hamiltonians (`H.op = (Hs.map Observable.op).sum`, in the +list's order), then splitting its propagator `exp(-i H Δ)` into the ordered product +`∏ᵢ exp(-i Hᵢ Δ)` of the component propagators incurs only a second-order error: there is a +constant `C ≥ 0` (depending on the `Hᵢ`) with +`‖(∏ᵢ (Hᵢ.propagator 1 0 Δ).op) - (H.propagator 1 0 Δ).op‖ ≤ C·Δ²` for every `Δ ∈ [0, 1]`, even when +the `Hᵢ` do not commute. + +This is the Banach-algebra bound +`NormedSpace.exists_norm_prod_exp_smul_sub_exp_smul_sum_le`, applied in the operator algebra +`S.space →L[ℂ] S.space` with generators `gᵢ = -i • Hᵢ.op`. Taking the `Hᵢ` to be the Pauli-string +Hamiltonians of N&C's part-(2) expansion recovers `exp(-iHΔ) = ∏_g exp(-i h_g g Δ) + O(4ⁿ Δ²)`. -/ +theorem Observable.exists_norm_prod_propagator_op_sub_propagator_op_le + (H : Observable S) (Hs : List (Observable S)) + (hH : H.op = (Hs.map Observable.op).sum) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ Δ : ℝ, 0 ≤ Δ → Δ ≤ 1 → + ‖(Hs.map fun Hᵢ => (Hᵢ.propagator 1 0 Δ).op).prod - (H.propagator 1 0 Δ).op‖ + ≤ C * Δ ^ 2 := by + by_cases hnt : Nontrivial S.space + · -- nontrivial space: `S.space →L[ℂ] S.space` is then a Banach algebra with `‖1‖ = 1` + have := hnt + obtain ⟨C, hC0, hC⟩ := + NormedSpace.exists_norm_prod_exp_smul_sub_exp_smul_sum_le + (Hs.map fun Hᵢ => (-Complex.I) • Hᵢ.op) + refine ⟨C, hC0, fun Δ hΔ0 hΔ1 => ?_⟩ + -- rewrite both sides into the Lie–Trotter shape via the shared bridge lemmas + rw [Observable.map_propagator_op_eq_map_exp_smul, Observable.propagator_op_one_zero, + ← Observable.sum_map_neg_I_smul_op hH] + exact hC Δ hΔ0 hΔ1 + · -- trivial space: every operator equals every other, so the difference vanishes + rw [not_nontrivial_iff_subsingleton] at hnt + have := hnt + refine ⟨0, le_rfl, fun Δ _ _ => ?_⟩ + rw [Subsingleton.elim (Hs.map fun Hᵢ => (Hᵢ.propagator 1 0 Δ).op).prod + (H.propagator 1 0 Δ).op, sub_self, norm_zero] + positivity + +/-- **Nielsen & Chuang, Problem 4.3(5): accumulated Trotter error of the `k`-fold splitting.** If a +Hamiltonian `H` is a sum `H = Σᵢ Hᵢ` of Hamiltonians (`H.op = (Hs.map Observable.op).sum`), then +`k` iterations of the ordered product of the component propagators at step `Δ = 1/k` converge to the +full propagator `exp(-i H) = U` at first order: there is a constant `C ≥ 0` (depending on the `Hᵢ`) +with `‖(∏ᵢ (Hᵢ.propagator 1 0 (1/k)).op)ᵏ - (H.propagator 1 0 1).op‖ ≤ C/k` for every `k ≥ 1`. + +This is the Banach-algebra bound +`NormedSpace.exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le`, applied in the operator algebra +`S.space →L[ℂ] S.space` with generators `gᵢ = -i • Hᵢ.op` (whose sum is `-i • H.op`, so +`exp(Σ gᵢ) = exp(-i H) = (H.propagator 1 0 1).op = U`). Taking the `Hᵢ` to be the Pauli-string +Hamiltonians of N&C's part-(2) expansion recovers `U = [∏_g exp(-i h_g g Δ)]ᵏ + O(4ⁿ Δ)`. -/ +theorem Observable.exists_norm_prod_propagator_op_pow_sub_propagator_op_le + (H : Observable S) (Hs : List (Observable S)) + (hH : H.op = (Hs.map Observable.op).sum) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ k : ℕ, 1 ≤ k → + ‖((Hs.map fun Hᵢ => (Hᵢ.propagator 1 0 (k : ℝ)⁻¹).op).prod) ^ k - (H.propagator 1 0 1).op‖ + ≤ C * (k : ℝ)⁻¹ := by + by_cases hnt : Nontrivial S.space + · have := hnt + obtain ⟨C, hC0, hC⟩ := + NormedSpace.exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le + (Hs.map fun Hᵢ => (-Complex.I) • Hᵢ.op) + refine ⟨C, hC0, fun k hk => ?_⟩ + -- rewrite both sides into the Lie–Trotter shape via the shared bridge lemmas + rw [Observable.map_propagator_op_eq_map_exp_smul, Observable.propagator_op_one_zero, one_smul, + ← Observable.sum_map_neg_I_smul_op hH] + exact hC k hk + · rw [not_nontrivial_iff_subsingleton] at hnt + have := hnt + refine ⟨0, le_rfl, fun k _ => ?_⟩ + rw [Subsingleton.elim (((Hs.map fun Hᵢ => (Hᵢ.propagator 1 0 (k : ℝ)⁻¹).op).prod) ^ k) + (H.propagator 1 0 1).op, sub_self, norm_zero] + positivity + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TypicalSubspace.lean b/LeanPool/AxQM/Postulates/API/TypicalSubspace.lean new file mode 100644 index 0000000000..5fb4d1144b --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TypicalSubspace.lean @@ -0,0 +1,292 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TensorPowState +public import LeanPool.AxQM.Postulates.API.MeasurementModel +public import LeanPool.AxQM.Postulates.API.EntropySpectral +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelityBound + +/-! +# AxQM.Postulates.API — the ε-typical subspace projector `P(n, ε)` (N&C Thm 12.5) + +This file concerns Nielsen & Chuang's **typical subspace theorem** (Theorem 12.5): the ε-typical +subspace projector `P(n, ε)`, its rank/trace identities, and its realization as a projective +measurement whose Born probability is the classical typicality probability. + +Fix a quantum state `ρ : State S` with spectral decomposition `ρ = ∑ₓ λ(x) |eₓ⟩⟨eₓ|` (eigenbasis +`e = ρ.isDensity.isSymmetric.eigenvectorBasis`, eigenvalue distribution `λ = ρ.eigenvalueDist`). The +eigenvalues `λ` are a probability distribution (`eigenvalueDist_nonneg`, +`eigenvalueDist_sum_eq_one`) with `H(λ) = S(ρ)` (`vonNeumannEntropy_eq_entropy_eigenvalueDist`), so +the classical notion of an +ε-typical sequence `κ : Fin n → Fin d` of eigenvalue indices — `κ ∈ Real.typicalSeq λ n ε` +(N&C's `|(1/n) log(1/∏ λ(κᵢ)) − S(ρ)| ≤ ε`, Eq. 12.41) — applies verbatim to the spectrum. + +* `State.typicalSubspaceProj ρ n ε` — the **ε-typical subspace projector** `P(n, ε)` (N&C Eq. + 12.42): the orthogonal projector onto the span of the product eigenvectors `|e_κ⟩` whose index + sequence `κ` is ε-typical, i.e. `InnerProductSpace.orthonormalProjector` of `ρ`'s product + eigenbasis (`State.tensorPowEigenbasis`) restricted to `Real.typicalSeq λ n ε`. +* `State.trace_typicalSubspaceProj_eq_card` — the **dimension identity** `tr(P(n, ε)) = |T(n, ε)|` + (N&C's `|T(n, ε)| = tr(P(n, ε))`): the trace of `P` is the number of ε-typical sequences. +* `State.typicalSubspaceMeasurement ρ n ε` — `P(n, ε)` packaged as the **two-outcome projective + measurement** `{P(n, ε), I − P(n, ε)}` (`Measurement.ofOrthonormalBasisFiber`, outcome `true` = + "found in the typical subspace"), with `typicalSubspaceMeasurement_op_true` identifying its + `true`-projector with `P(n, ε)`. +* `State.typicalSubspaceMeasurement_bornProb_true` — the **Born-probability identity** (N&C Eq. + 12.46): the probability of the outcome `true` on `ρ^⊗n` is the classical typicality probability + `tr(P(n, ε) ρ^⊗n) = ∑_{κ ∈ T(n, ε)} ∏ᵢ λ(κᵢ)`. + +Together these are the bridge that reduces the *quantum* typical subspace theorem to the *classical* +theorem of typical sequences (N&C Theorem 12.2, `ToMathlib.InformationTheory.TypicalSequence`) +applied +to the eigenvalue distribution `λ`. Part (1) of Theorem 12.5 (`tr(P ρ^⊗n) ≥ 1 − δ`) is the +`bornProb` identity fed into `Real.exists_le_sum_typicalSeq`; part (2) (the dimension bounds) is the +`trace = card` identity fed into `Real.exists_card_typicalSeq_bounds`. Those consequences are in +`LeanPool/AxQM/NC/Ch12/Theorem5.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-! ### The eigenvalue distribution of a state -/ + +/-- The **eigenvalue distribution** `λ : Fin d → ℝ` (`d = dim S.space`) of a quantum state `ρ`: the +spectrum of the density operator, indexed by `ρ`'s canonical eigenbasis +(`ρ.isDensity.isSymmetric.eigenvalues`). It is a genuine probability distribution +(`eigenvalueDist_nonneg`, `eigenvalueDist_sum_eq_one`) whose Shannon entropy is the von Neumann +entropy `S(ρ)` (`vonNeumannEntropy_eq_entropy_eigenvalueDist`) — the classical distribution N&C's +typical subspace theorem is reduced to. -/ +def State.eigenvalueDist (ρ : State S) : Fin (Module.finrank ℂ S.space) → ℝ := + ρ.isDensity.isSymmetric.eigenvalues rfl + +/-- The eigenvalues of a state are non-negative (the density operator is positive). -/ +theorem State.eigenvalueDist_nonneg (ρ : State S) (i : Fin (Module.finrank ℂ S.space)) : + 0 ≤ ρ.eigenvalueDist i := + ρ.isDensity.eigenvalues_nonneg rfl i + +/-- The eigenvalues of a state sum to one (the density operator has unit trace). -/ +theorem State.eigenvalueDist_sum_eq_one (ρ : State S) : ∑ i, ρ.eigenvalueDist i = 1 := + ρ.isDensity.eigenvalues_sum_eq_one rfl + +/-- **The entropy bridge** (N&C: `H(p(x)) = S(ρ)`): the Shannon entropy of a state's eigenvalue +distribution is its von Neumann entropy. This is what turns the classical typical-sequences bounds +(stated over `Real.entropy λ`) into the quantum `S(ρ)` bounds of the typical subspace theorem. -/ +theorem State.vonNeumannEntropy_eq_entropy_eigenvalueDist (ρ : State S) : + ρ.vonNeumannEntropy = Real.entropy ρ.eigenvalueDist := + ρ.vonNeumannEntropy_eq_entropy_of_isEigenbasis (ρ.isDensity.isSymmetric.eigenvectorBasis rfl) + (fun i => ρ.op_apply_eigenvectorBasis i) + +/-! ### The ε-typical subspace projector -/ + +/-- **The ε-typical subspace projector** `P(n, ε)` (Nielsen & Chuang, Theorem 12.5, Eq. 12.42): the +orthogonal projector onto the ε-typical subspace `T(n, ε)` of `ρ^⊗n`, spanned by the product +eigenvectors `|e_κ⟩ = ⨂ᵢ |e_{κᵢ}⟩` whose index sequence `κ` is ε-typical for the eigenvalue +distribution `λ = ρ.eigenvalueDist`. Formally the `InnerProductSpace.orthonormalProjector` of `ρ`'s +product eigenbasis (`State.tensorPowEigenbasis`) restricted to the classical ε-typical set +`Real.typicalSeq λ n ε`. -/ +def State.typicalSubspaceProj (ρ : State S) (n : ℕ) (ε : ℝ) : + (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space := + orthonormalProjector ℂ (⇑(ρ.tensorPowEigenbasis n)) (Real.typicalSeq ρ.eigenvalueDist n ε) + +/-- **The dimension of the typical subspace equals the number of typical sequences** (Nielsen & +Chuang, Theorem 12.5: `|T(n, ε)| = tr(P(n, ε))`): the trace of the ε-typical projector is the +cardinality of the classical ε-typical set. Immediate from the general projector-trace identity +`InnerProductSpace.trace_orthonormalProjector` (trace of `∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` is `|s|`), applied to +the product eigenbasis and the ε-typical index set. -/ +theorem State.trace_typicalSubspaceProj_eq_card (ρ : State S) (n : ℕ) (ε : ℝ) : + LinearMap.trace ℂ (S ^⊗ₛ n).space (ρ.typicalSubspaceProj n ε : _ →ₗ[ℂ] _) + = ((Real.typicalSeq ρ.eigenvalueDist n ε).card : ℂ) := by + rw [State.typicalSubspaceProj, trace_orthonormalProjector] + +/-- The **dimension of the ε-typical subspace** `|T(n, ε)|` (Nielsen & Chuang, Theorem 12.5, part +(2)): the number of ε-typical index sequences `κ ∈ Real.typicalSeq λ n ε`, equivalently the rank of +`P(n, ε)`. It is an `ℕ`-valued quantity, so the part-(2) dimension bounds can be stated over it +without the `LinearMap.trace`/`OrthonormalBasis` machinery. N&C's identity +`|T(n, ε)| = tr(P(n, ε))` is `trace_typicalSubspaceProj_eq_typicalSubspaceDim`. -/ +def State.typicalSubspaceDim (ρ : State S) (n : ℕ) (ε : ℝ) : ℕ := + (Real.typicalSeq ρ.eigenvalueDist n ε).card + +/-- **`|T(n, ε)| = tr(P(n, ε))`** (Nielsen & Chuang, Theorem 12.5, part (2)): the dimension of the +ε-typical subspace equals the trace of its projector. A restatement of +`trace_typicalSubspaceProj_eq_card` in terms of the dimension `typicalSubspaceDim` +(definitionally its cardinality), N&C's identity `|T(n, ε)| = tr(P(n, ε))`. -/ +theorem State.trace_typicalSubspaceProj_eq_typicalSubspaceDim (ρ : State S) (n : ℕ) (ε : ℝ) : + LinearMap.trace ℂ (S ^⊗ₛ n).space (ρ.typicalSubspaceProj n ε : _ →ₗ[ℂ] _) + = (ρ.typicalSubspaceDim n ε : ℂ) := + ρ.trace_typicalSubspaceProj_eq_card n ε + +/-! ### The typical subspace as a projective measurement -/ + +/-- **The typical/atypical projective measurement** `{P(n, ε), I − P(n, ε)}` (Nielsen & Chuang, +Theorem 12.5): the two-outcome von Neumann measurement asking whether `ρ^⊗n` lies in the ε-typical +subspace. Built as `Measurement.ofOrthonormalBasisFiber` of the product eigenbasis with the Boolean +fibre `κ ↦ (κ ∈ T(n, ε))`; outcome `true` is the ε-typical outcome, with projector `P(n, ε)` +(`typicalSubspaceMeasurement_op_true`). -/ +def State.typicalSubspaceMeasurement (ρ : State S) (n : ℕ) (ε : ℝ) : + Measurement Bool (S ^⊗ₛ n) := + Measurement.ofOrthonormalBasisFiber (ρ.tensorPowEigenbasis n) + (fun κ => decide (κ ∈ Real.typicalSeq ρ.eigenvalueDist n ε)) + +/-- The `true`-outcome projector of the typical subspace measurement is the ε-typical subspace +projector `P(n, ε)`: the fibre `{κ | (κ ∈ T(n, ε)) = true}` is exactly the typical set `T(n, ε)`. -/ +theorem State.typicalSubspaceMeasurement_op_true (ρ : State S) (n : ℕ) (ε : ℝ) : + (ρ.typicalSubspaceMeasurement n ε).op true = ρ.typicalSubspaceProj n ε := by + rw [State.typicalSubspaceMeasurement, Measurement.ofOrthonormalBasisFiber_op, + State.typicalSubspaceProj] + congr 1 + ext κ + simp only [Finset.mem_filter, Finset.mem_univ, true_and, decide_eq_true_eq] + +/-- **The Born probability of the typical subspace equals the classical typicality probability** +(Nielsen & Chuang, Theorem 12.5, Eq. 12.46): the probability of the ε-typical outcome on `ρ^⊗n` is +`tr(P(n, ε) ρ^⊗n) = ∑_{κ ∈ T(n, ε)} ∏ᵢ λ(κᵢ)`, the total probability the classical i.i.d. source +with distribution `λ` emits an ε-typical sequence. + +Proof: the Born probability is `re tr(P† P ρ^⊗n)` (`bornProb_eq_re_trace_postOp`, +`trace_postOp`), which collapses to `re tr(P ρ^⊗n)` since `P` is a self-adjoint idempotent. The +projector-trace lemma `InnerProductSpace.trace_orthonormalProjector_comp` restricts `tr(P ρ^⊗n)` to +the ε-typical diagonal `∑_{κ typical} ⟪e_κ, ρ^⊗n e_κ⟫`, and `ρ^⊗n` is diagonal there with eigenvalue +`∏ᵢ λ(κᵢ)` (`tensorPow_op_apply_tensorPowEigenbasis`), giving `∑_{κ typical} ∏ᵢ λ(κᵢ)`. -/ +theorem State.typicalSubspaceMeasurement_bornProb_true (ρ : State S) (n : ℕ) (ε : ℝ) : + (ρ.typicalSubspaceMeasurement n ε).bornProb (ρ.tensorPow n) true + = ∑ κ ∈ Real.typicalSeq ρ.eigenvalueDist n ε, ∏ i, ρ.eigenvalueDist (κ i) := by + rw [Measurement.bornProb_eq_re_trace_postOp, ContinuousLinearMap.trace_postOp, + State.typicalSubspaceMeasurement_op_true, State.typicalSubspaceProj, + ← ContinuousLinearMap.comp_assoc, + orthonormalProjector_adjoint_comp_self (ρ.tensorPowEigenbasis n).orthonormal, + trace_orthonormalProjector_comp] + -- The remaining sum runs over the typical eigenbasis diagonal `⟪e_κ, ρ^⊗n e_κ⟫ = ∏ᵢ λ(κᵢ)`. + have hterm : ∀ κ, + inner ℂ (ρ.tensorPowEigenbasis n κ) ((ρ.tensorPow n).op (ρ.tensorPowEigenbasis n κ)) + = ((∏ i, ρ.eigenvalueDist (κ i) : ℝ) : ℂ) := by + intro κ + rw [State.tensorPow_op_apply_tensorPowEigenbasis, inner_smul_right, + orthonormal_iff_ite.mp (ρ.tensorPowEigenbasis n).orthonormal, ite_eq_left rfl, mul_one] + rfl + rw [Finset.sum_congr rfl (fun κ _ => hterm κ), ← Complex.ofReal_sum] + exact Complex.ofReal_re _ + +/-- The ε-typical subspace projector `P(n, ε)` is **self-adjoint** (it is an orthonormal +projector). -/ +theorem State.typicalSubspaceProj_isSelfAdjoint (ρ : State S) (n : ℕ) (ε : ℝ) : + IsSelfAdjoint (ρ.typicalSubspaceProj n ε) := + isSelfAdjoint_orthonormalProjector _ _ + +/-- The ε-typical subspace projector `P(n, ε)` is **idempotent**, `P ∘ P = P` (it is an orthonormal +projector). -/ +theorem State.typicalSubspaceProj_idem (ρ : State S) (n : ℕ) (ε : ℝ) : + (ρ.typicalSubspaceProj n ε).comp (ρ.typicalSubspaceProj n ε) = ρ.typicalSubspaceProj n ε := + isIdempotentElem_orthonormalProjector (ρ.tensorPowEigenbasis n).orthonormal _ + +/-- **Born-rule bridge for the typical/atypical measurement**: on *any* state `τ` of `S ^⊗ₛ n`, the +ε-typical outcome probability is `re tr(P(n, ε) τ)`. (Generalizes the `ρ^⊗n`-specialized +`typicalSubspaceMeasurement_bornProb_true` to an arbitrary post-scheme state, as needed to certify +that a compressed output lands in the typical subspace.) Proof: `bornProb = re tr(P† P τ)` +(`bornProb_eq_re_trace_postOp`, `trace_postOp`), and `P† P = P` since `P` is a self-adjoint +idempotent. -/ +theorem State.typicalSubspaceMeasurement_bornProb_eq_re_trace (ρ : State S) (n : ℕ) (ε : ℝ) + (τ : State (S ^⊗ₛ n)) : + (ρ.typicalSubspaceMeasurement n ε).bornProb τ true + = RCLike.re ((LinearMap.trace ℂ (S ^⊗ₛ n).space) + ((ρ.typicalSubspaceProj n ε).comp τ.op)) := by + rw [Measurement.bornProb_eq_re_trace_postOp, ContinuousLinearMap.trace_postOp, + State.typicalSubspaceMeasurement_op_true, (ρ.typicalSubspaceProj_isSelfAdjoint n ε).adjoint_eq, + ← ContinuousLinearMap.comp_assoc, ρ.typicalSubspaceProj_idem n ε] + +/-! ### The small-subspace bound: arbitrary bounded-rank projectors -/ + +/-- The **dimension of the "true"-outcome subspace** of a two-outcome measurement `M` on +`S ^⊗ₛ n`: the rank (`finrank` of the range) of the projector `M.op true`. An `ℕ`-valued +quantity, so the small-subspace bound of the typical subspace theorem (Nielsen & Chuang, Theorem +12.5, part (3)), quantifying over "any subspace of dimension at most `2^{nR}`", can be stated over +it. For a *projective* `M` it equals +the trace of the projector (`Measurement.trace_op_true_eq_trueSubspaceDim`). -/ +def Measurement.trueSubspaceDim {n : ℕ} (M : Measurement Bool (S ^⊗ₛ n)) : ℕ := + Module.finrank ℂ (LinearMap.range (M.op true : (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space)) + +/-- For a **projective** two-outcome measurement, the trace of the `true`-outcome projector equals +the dimension of its subspace: `tr(M.op true) = trueSubspaceDim M`. A projector's trace is its rank +(`LinearMap.IsProj.trace`, via the idempotence of the star projection `M.op true`). -/ +theorem Measurement.trace_op_true_eq_trueSubspaceDim {n : ℕ} (M : Measurement Bool (S ^⊗ₛ n)) + (hM : M.IsProjective) : + LinearMap.trace ℂ (S ^⊗ₛ n) (M.op true : (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space) + = (M.trueSubspaceDim : ℂ) := by + have hidem : IsIdempotentElem (M.op true : (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space) := by + rw [IsIdempotentElem, ← ContinuousLinearMap.toLinearMap_mul, (hM true).isIdempotentElem] + rw [Measurement.trueSubspaceDim, + LinearMap.IsProj.trace (LinearMap.IsIdempotentElem.isProj_range _ hidem)] + +/-- **Small-subspace reduction** (Nielsen & Chuang, Theorem 12.5, part (3), the operator step). For +a *projective* two-outcome measurement `M` on `S ^⊗ₛ n`, the Born probability of the `true` outcome +on `ρ^⊗n` is a classical *weighted* mass `∑_κ w κ · ∏ᵢ λ(κᵢ)` of the eigenvalue distribution +`λ = ρ.eigenvalueDist`, where the weights `w κ = ‖(M.op true) e_κ‖²` are the eigenbasis-diagonal +matrix elements `⟨e_κ, (M.op true) e_κ⟩` of the projector `M.op true`. They satisfy `0 ≤ w κ ≤ 1` +(the diagonal of a star projection) with total weight `∑_κ w κ = tr(M.op true) = trueSubspaceDim M`. + +This is the bridge feeding the classical weighted small-set bound +(`Real.exists_sum_weighted_prod_le_of_sum_le_exp`): `bornProb true = re tr(M.op true · ρ^⊗n)` +(`bornProb_eq_re_trace_postOp`, `trace_postOp`, self-adjoint idempotence), expanded in the `ρ^⊗n` +eigenbasis (`LinearMap.trace_eq_sum_inner`), on which `ρ^⊗n` acts diagonally with eigenvalue +`∏ᵢ λ(κᵢ)` (`tensorPow_op_apply_tensorPowEigenbasis`). -/ +theorem State.exists_weights_bornProb_true (ρ : State S) (n : ℕ) + (M : Measurement Bool (S ^⊗ₛ n)) (hM : M.IsProjective) : + ∃ w : (Fin n → Fin (Module.finrank ℂ S.space)) → ℝ, + (∀ κ, 0 ≤ w κ) ∧ (∀ κ, w κ ≤ 1) ∧ (∑ κ, w κ = (M.trueSubspaceDim : ℝ)) ∧ + M.bornProb (ρ.tensorPow n) true = ∑ κ, w κ * ∏ i, ρ.eigenvalueDist (κ i) := by + -- The complex diagonal element of the star projection `M.op true` is the (real) squared norm, + -- `⟪e_κ, P e_κ⟫ = ‖P e_κ‖²` (`inner_self_of_isSelfAdjoint_of_isIdempotent`). + have hpe : ∀ κ, inner ℂ (ρ.tensorPowEigenbasis n κ) ((M.op true) (ρ.tensorPowEigenbasis n κ)) + = ((‖(M.op true) (ρ.tensorPowEigenbasis n κ)‖ ^ 2 : ℝ) : ℂ) := + fun κ => inner_self_of_isSelfAdjoint_of_isIdempotent + (hM true).isSelfAdjoint (hM true).isIdempotentElem (ρ.tensorPowEigenbasis n κ) + refine ⟨fun κ => ‖(M.op true) (ρ.tensorPowEigenbasis n κ)‖ ^ 2, fun κ => sq_nonneg _, ?_, ?_, ?_⟩ + · -- `w κ ≤ 1`: a star projection is a contraction (`IsStarProjection.norm_le`), and `‖e_κ‖ = 1`. + intro κ + have hnx : ‖ρ.tensorPowEigenbasis n κ‖ = 1 := (ρ.tensorPowEigenbasis n).orthonormal.1 κ + exact pow_le_one₀ (norm_nonneg _) + (((M.op true).le_opNorm _).trans (by rw [hnx, mul_one]; exact (hM true).norm_le)) + · -- `∑ κ, w κ = tr(M.op true) = trueSubspaceDim`. + have h1 : ((∑ κ, ‖(M.op true) (ρ.tensorPowEigenbasis n κ)‖ ^ 2 : ℝ) : ℂ) + = (M.trueSubspaceDim : ℂ) := by + rw [Complex.ofReal_sum, ← Measurement.trace_op_true_eq_trueSubspaceDim M hM, + LinearMap.trace_eq_sum_inner _ (ρ.tensorPowEigenbasis n)] + exact Finset.sum_congr rfl fun κ _ => (hpe κ).symm + exact_mod_cast h1 + · -- `bornProb true = ∑ κ, w κ · ∏ᵢ λ(κᵢ)`. + have hPadj : (ContinuousLinearMap.adjoint (M.op true)).comp (M.op true) = M.op true := by + rw [← ContinuousLinearMap.star_eq_adjoint, (hM true).isSelfAdjoint, + ← ContinuousLinearMap.mul_def] + exact (hM true).isIdempotentElem + rw [Measurement.bornProb_eq_re_trace_postOp, ContinuousLinearMap.trace_postOp, + ← ContinuousLinearMap.comp_assoc, hPadj, + LinearMap.trace_eq_sum_inner _ (ρ.tensorPowEigenbasis n)] + have hterm : ∀ κ, inner ℂ (ρ.tensorPowEigenbasis n κ) + (((M.op true).comp (ρ.tensorPow n).op : (S ^⊗ₛ n).space →ₗ[ℂ] (S ^⊗ₛ n).space) + (ρ.tensorPowEigenbasis n κ)) + = ((‖(M.op true) (ρ.tensorPowEigenbasis n κ)‖ ^ 2 * ∏ i, ρ.eigenvalueDist (κ i) : ℝ) + : ℂ) := by + intro κ + simp only [ContinuousLinearMap.coe_comp, ContinuousLinearMap.coe_coe, + Function.comp_apply] + rw [State.tensorPow_op_apply_tensorPowEigenbasis, map_smul, inner_smul_right, hpe κ] + simp only [State.eigenvalueDist] + push_cast; ring + rw [Finset.sum_congr rfl fun κ _ => hterm κ, ← Complex.ofReal_sum] + exact Complex.ofReal_re _ + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/TypicalSubspaceEquipartition.lean b/LeanPool/AxQM/Postulates/API/TypicalSubspaceEquipartition.lean new file mode 100644 index 0000000000..13f45ff408 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/TypicalSubspaceEquipartition.lean @@ -0,0 +1,180 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.TypicalSubspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# The equipartition operator bound of the typical subspace (N&C Thm 12.5 / HSW eq. (12.82)) + +The **maximum-eigenvalue half** of Nielsen & Chuang's asymptotic equipartition property for the +ε-typical subspace of `ρ^⊗n`. Where `Postulates.API.TypicalSubspace` records the *total mass* and +*dimension* of the typical subspace `T(n, ε)`, this file records how *small* the eigenvalues of +`ρ^⊗n` are **on** that subspace: writing `P = P(n, ε)` for the ε-typical subspace projector and +`S = S(ρ)` for the von Neumann entropy, the compression of `ρ^⊗n` to the typical subspace is bounded +above in the Loewner order by the exponentially small scalar `exp(-n (S - ε))`: + +`P ρ^⊗n P ≤ exp(-n (S - ε)) · 1` (Nielsen & Chuang, the operator inequality used at eq. (12.82), +in nats — N&C's base-`2` `P σ_bar^⊗n P ≤ 2^{-n(S(σ_bar)-ε)} I`). + +This is exactly the ingredient the achievability half of the **HSW theorem** (`χ(E) = C⁽¹⁾(E)`, +Theorem 12.8) uses to control the "false-decoding" term of the random-coding error estimate: with +`σ_bar = ∑ⱼ pⱼ E(ρⱼ)` the average channel output and `P` its ε-typical projector, +`tr(P σ_bar^⊗n P · Πⱼ) ≤ exp(-n(S(σ_bar)-ε)) · tr(Πⱼ)`, feeding the exponential decay of eq. +(12.82). + +## What this file provides + +* `AxQM.State.prod_eigenvalueDist_le_of_mem_typicalSeq` — the underlying **scalar** + equipartition bound: an ε-typical index sequence `κ` has product eigenvalue + `∏ᵢ λ(κᵢ) ≤ exp(-n (S(ρ) - ε))`. A restatement of the classical multiplicative typicality bound + (`Real.mem_typicalSeq`) through the entropy bridge `H(λ) = S(ρ)`. + +* `AxQM.State.typicalSubspaceProj_comp_tensorPow_op_comp_le` — the **operator** bound + `P ρ^⊗n P ≤ exp(-n (S(ρ) - ε)) · 1`. The proof diagonalises: since `ρ^⊗n` is diagonal in the + product eigenbasis `|e_κ⟩` with eigenvalue `∏ᵢ λ(κᵢ)` (`tensorPow_op_apply_tensorPowEigenbasis`) + and `P = ∑_{κ ∈ T(n,ε)} |e_κ⟩⟨e_κ|` (`orthonormalProjector_eq_sum`), the sandwich collapses to + `P ρ^⊗n P = ∑_{κ ∈ T(n,ε)} (∏ᵢ λ(κᵢ)) |e_κ⟩⟨e_κ|` (via `comp_rankOne`), whence + `exp(-n(S-ε))·P − P ρ^⊗n P = ∑_{κ ∈ T(n,ε)} (exp(-n(S-ε)) − ∏ᵢ λ(κᵢ)) |e_κ⟩⟨e_κ|` is a sum of + positive operators (each scalar is `≥ 0` by the scalar bound above), giving `P ρ^⊗n P ≤ c·P`; and + `c·P ≤ c·1` because `P ≤ 1` (`IsStarProjection.le_one`) and `c ≥ 0`. +-/ + +@[expose] public section + +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +/-- **The scalar equipartition bound** (Nielsen & Chuang, Theorem 12.5 / the multiplicative form of +Eq. 12.41): an ε-typical index sequence `κ ∈ T(n, ε)` of eigenvalue indices has product eigenvalue +`∏ᵢ λ(κᵢ) ≤ exp(-n (S(ρ) - ε))` (in nats). Immediate from the classical multiplicative typicality +bound `Real.mem_typicalSeq` for `λ = ρ.eigenvalueDist`, rewriting the Shannon entropy `H(λ)` to the +von Neumann entropy `S(ρ)` via the entropy bridge `vonNeumannEntropy_eq_entropy_eigenvalueDist`. -/ +theorem State.prod_eigenvalueDist_le_of_mem_typicalSeq (ρ : State S) {n : ℕ} {ε : ℝ} + {κ : Fin n → Fin (Module.finrank ℂ S.space)} + (hκ : κ ∈ Real.typicalSeq ρ.eigenvalueDist n ε) : + ∏ i, ρ.eigenvalueDist (κ i) ≤ Real.exp (-(n : ℝ) * (ρ.vonNeumannEntropy - ε)) := by + rw [ρ.vonNeumannEntropy_eq_entropy_eigenvalueDist] + exact (Real.mem_typicalSeq.mp hκ).2 + +/-- **The equipartition operator bound** (Nielsen & Chuang, Theorem 12.5 / the operator inequality +used at Eq. 12.82): the compression of `ρ^⊗n` to its ε-typical subspace is bounded above in the +Loewner order by the exponentially small scalar `exp(-n (S(ρ) - ε))`, + +`P(n, ε) · ρ^⊗n · P(n, ε) ≤ exp(-n (S(ρ) - ε)) · 1` + +(in nats; N&C's base-`2` `P σ_bar^⊗n P ≤ 2^{-n(S(σ_bar)-ε)} I`). This is the maximum-eigenvalue +half of +the asymptotic equipartition property, the ingredient the HSW achievability argument uses to make +the random-coding false-decoding term decay exponentially. + +The proof diagonalises in the product eigenbasis `|e_κ⟩` (`ρ.tensorPowEigenbasis n`): `ρ^⊗n` acts on +`|e_κ⟩` with eigenvalue `∏ᵢ λ(κᵢ)` (`tensorPow_op_apply_tensorPowEigenbasis`) and +`P = ∑_{κ ∈ T(n,ε)} |e_κ⟩⟨e_κ|` (`orthonormalProjector_eq_sum`), so the sandwich collapses to +`P ρ^⊗n P = ∑_{κ ∈ T(n,ε)} (∏ᵢ λ(κᵢ)) |e_κ⟩⟨e_κ|`. Hence +`c·P − P ρ^⊗n P = ∑_{κ ∈ T(n,ε)} (c − ∏ᵢ λ(κᵢ)) |e_κ⟩⟨e_κ|` (`c = exp(-n(S-ε))`) is a nonnegative +combination of rank-one projectors — each coefficient `≥ 0` by the scalar bound +`prod_eigenvalueDist_le_of_mem_typicalSeq` — so `P ρ^⊗n P ≤ c·P`; finally `c·P ≤ c·1` since `P ≤ 1` +(`IsStarProjection.le_one`) and `c ≥ 0`. -/ +theorem State.typicalSubspaceProj_comp_tensorPow_op_comp_le (ρ : State S) (n : ℕ) (ε : ℝ) : + (ρ.typicalSubspaceProj n ε).comp + ((ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε)) + ≤ (Real.exp (-(n : ℝ) * (ρ.vonNeumannEntropy - ε)) : ℝ) • + (1 : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space) := by + classical + set c : ℝ := Real.exp (-(n : ℝ) * (ρ.vonNeumannEntropy - ε)) with hc + set s := Real.typicalSeq ρ.eigenvalueDist n ε with hs + -- `P = ∑_{κ ∈ T(n,ε)} |e_κ⟩⟨e_κ|`. + have hP : ρ.typicalSubspaceProj n ε + = ∑ κ ∈ s, rankOne ℂ (ρ.tensorPowEigenbasis n κ) (ρ.tensorPowEigenbasis n κ) := by + rw [State.typicalSubspaceProj, orthonormalProjector_eq_sum] + -- The sandwich collapses to a diagonal sum (complex eigenvalue coefficients). + have key : (ρ.typicalSubspaceProj n ε).comp + ((ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε)) + = ∑ κ ∈ s, ((∏ i, ρ.eigenvalueDist (κ i) : ℝ) : ℂ) • + rankOne ℂ (ρ.tensorPowEigenbasis n κ) (ρ.tensorPowEigenbasis n κ) := by + have hAP : (ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε) + = ∑ κ ∈ s, ((∏ i, ρ.eigenvalueDist (κ i) : ℝ) : ℂ) • + rankOne ℂ (ρ.tensorPowEigenbasis n κ) (ρ.tensorPowEigenbasis n κ) := by + rw [hP, ContinuousLinearMap.comp_finsetSum] + refine Finset.sum_congr rfl fun κ _ => ?_ + rw [InnerProductSpace.comp_rankOne, State.tensorPow_op_apply_tensorPowEigenbasis, + map_smul, _root_.smul_apply] + rfl + rw [hAP, ContinuousLinearMap.comp_finsetSum] + refine Finset.sum_congr rfl fun κ hκ => ?_ + rw [ContinuousLinearMap.comp_smul, InnerProductSpace.comp_rankOne, State.typicalSubspaceProj, + orthonormalProjector_apply_eq_ite (ρ.tensorPowEigenbasis n).orthonormal, ite_eq_left hκ] + -- `P ρ^⊗n P ≤ c·P`, as `c·P − P ρ^⊗n P` is a nonnegative combination of `|e_κ⟩⟨e_κ|`. + have hstep : (ρ.typicalSubspaceProj n ε).comp + ((ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε)) + ≤ c • ρ.typicalSubspaceProj n ε := by + rw [← sub_nonneg, key, hP, Finset.smul_sum, ← Finset.sum_sub_distrib] + refine Finset.sum_nonneg fun κ hκ => ?_ + have hle : ∏ i, ρ.eigenvalueDist (κ i) ≤ c := + ρ.prod_eigenvalueDist_le_of_mem_typicalSeq hκ + have hpos : (0 : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space) ≤ + rankOne ℂ (ρ.tensorPowEigenbasis n κ) (ρ.tensorPowEigenbasis n κ) := + ContinuousLinearMap.nonneg_iff_isPositive.mpr (isPositive_rankOne_self _) + rw [Complex.coe_smul, ← sub_smul] + exact smul_nonneg (by linarith) hpos + -- `c·P ≤ c·1`, since `P ≤ 1` and `c ≥ 0`. + refine hstep.trans ?_ + refine smul_le_smul_of_nonneg_left ?_ (Real.exp_nonneg _) + rw [State.typicalSubspaceProj] + exact (isStarProjection_orthonormalProjector (ρ.tensorPowEigenbasis n).orthonormal s).le_one + +/-- **The false-decoding decay of the HSW random-coding error estimate** (Nielsen & Chuang, +eq. 12.82): the trace overlap of the equipartition-compressed `P ρ^⊗n P` with *any* positive +operator `Q` decays like the maximal typical eigenvalue, + +`re tr(P ρ^⊗n P · Q) ≤ exp(-n (S(ρ) - ε)) · re tr Q` + +(in nats; N&C's base-`2` `tr(P σ_bar^⊗n P Q) ≤ 2^{-n(S(σ_bar)-ε)} tr Q`). Immediate from the +equipartition operator bound `P ρ^⊗n P ≤ exp(-n(S-ε)) · 1` +(`typicalSubspaceProj_comp_tensorPow_op_comp_le`) fed +through the scalar trace bound `ContinuousLinearMap.re_trace_mul_le_smul_of_le_smul_one`. With +`ρ = σ_bar = ∑ⱼ pⱼ E(ρⱼ)` the average channel output and `Q = 𝔼(P₁)` the (expected) +conditional-typical +projector, this is exactly the term controlling the false-decoding contribution to the random-coding +average error in the HSW achievability argument. -/ +theorem State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le (ρ : State S) (n : ℕ) (ε : ℝ) + {Q : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space} (hQ : 0 ≤ Q) : + RCLike.re (LinearMap.trace ℂ (S ^⊗ₛ n).space + (((ρ.typicalSubspaceProj n ε).comp + ((ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε)) * Q : _ →L[ℂ] _) : _ →ₗ[ℂ] _)) + ≤ Real.exp (-(n : ℝ) * (ρ.vonNeumannEntropy - ε)) * + RCLike.re (LinearMap.trace ℂ (S ^⊗ₛ n).space (Q : _ →ₗ[ℂ] _)) := + ContinuousLinearMap.re_trace_mul_le_smul_of_le_smul_one + (ρ.typicalSubspaceProj_comp_tensorPow_op_comp_le n ε) hQ + +/-- The false-decoding decay bound specialised to a positive `Q` whose trace is dimension-bounded: +`re tr(P ρ^⊗n P · Q) ≤ exp(-n(S(ρ)-ε)) · D` whenever `re tr Q ≤ D`. With `Q = 𝔼(P₁)` and +`D = exp(n(S_bar+ε))` the expected conditional-typical dimension bound (N&C eq. 12.77, +`S_bar = ∑ⱼ pⱼ S(σⱼ)`), the two factors combine into the exponent `exp(-n(S(σ_bar) - S_bar - 2ε))` +of the HSW +error estimate (eq. 12.82). -/ +theorem State.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le_of_trace_le (ρ : State S) (n : ℕ) + (ε : ℝ) {Q : (S ^⊗ₛ n).space →L[ℂ] (S ^⊗ₛ n).space} (hQ : 0 ≤ Q) {D : ℝ} + (hD : RCLike.re (LinearMap.trace ℂ (S ^⊗ₛ n).space (Q : _ →ₗ[ℂ] _)) ≤ D) : + RCLike.re (LinearMap.trace ℂ (S ^⊗ₛ n).space + (((ρ.typicalSubspaceProj n ε).comp + ((ρ.tensorPow n).op.comp (ρ.typicalSubspaceProj n ε)) * Q : _ →L[ℂ] _) : _ →ₗ[ℂ] _)) + ≤ Real.exp (-(n : ℝ) * (ρ.vonNeumannEntropy - ε)) * D := + (ρ.re_trace_typicalSubspaceProj_tensorPow_comp_mul_le n ε hQ).trans + (mul_le_mul_of_nonneg_left hD (Real.exp_nonneg _)) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/Uhlmann.lean b/LeanPool/AxQM/Postulates/API/Uhlmann.lean new file mode 100644 index 0000000000..78b3e13c2e --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/Uhlmann.lean @@ -0,0 +1,67 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.Postulates.Composite +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Purification + +/-! +# AxQM.Postulates.API — the purification bridge for Uhlmann's theorem + +The bridge connecting the **physics** notion of a purification — a `PureState` +of a composite system `S ⊗ T` whose left marginal (`State.reducedLeft`, tracing out the ancilla +`T`) is a given state `ρ` — to the **abstract** predicate `TensorProduct.IsPurification` +over the density operator `ρ.op` and the vector `ψ.vec`. + +This is the bridge Nielsen–Chuang Theorem 9.4 (Uhlmann's theorem) needs to translate its +operator-level core (`TensorProduct.isGreatest_norm_inner_of_isPurification`) into a statement +about physical purifications. + +## Main statements + +* `PureState.reducedLeft_toState_eq_iff_isPurification` — a pure state `ψ` of `S ⊗ T` purifies + `ρ : State S` (its left marginal is `ρ`) iff `ψ.vec` is an abstract `IsPurification` of `ρ.op`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Physics purification ↔ abstract purification.** A pure state `ψ` of the composite system +`S ⊗ T` is a purification of `ρ : State S` — meaning its left marginal `ψ.toState.reducedLeft` +(the partial trace over the ancilla `T` of the rank-one projector `|ψ⟩⟨ψ|`) equals `ρ` — exactly +when its vector `ψ.vec` is an abstract `TensorProduct.IsPurification` of the density operator +`ρ.op`. + +Both sides trace out the right factor at `stdOrthonormalBasis ℂ T.space`, so once `reducedLeft` +and `toState` are unfolded (`State.reducedLeft_op`, `PureState.toState_op`) the two conditions are +the same partial-trace equation, related only by the finite-dimensional `LinearMap ↔ +ContinuousLinearMap` round-trip (`ContinuousLinearMap.toLinearMap_toContinuousLinearMap` / +`LinearMap.coe_toContinuousLinearMap`). It is the physical reading of +`TensorProduct.isPurification_iff_matricize_comp_adjoint`, feeding Uhlmann's theorem. -/ +theorem PureState.reducedLeft_toState_eq_iff_isPurification + (ψ : PureState (S ⊗ T)) (ρ : State S) : + ψ.toState.reducedLeft = ρ ↔ TensorProduct.IsPurification ρ.op ψ.vec := by + constructor + · intro h + rw [← congrArg State.op h, State.reducedLeft_op, PureState.toState_op] + exact (LinearMap.coe_toContinuousLinearMap _).symm + · intro h + apply State.ext + rw [State.reducedLeft_op, PureState.toState_op] + exact h ▸ ContinuousLinearMap.toLinearMap_toContinuousLinearMap ρ.op + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/UniformSuperposition.lean b/LeanPool/AxQM/Postulates/API/UniformSuperposition.lean new file mode 100644 index 0000000000..9a7ba8db79 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/UniformSuperposition.lean @@ -0,0 +1,74 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Qudit + +/-! +# AxQM.Postulates.API — the equal (uniform) superposition state + +The **equal superposition** `|s⟩ = N^(-1/2) ∑ₖ |k⟩` (`N = d`) of the qudit register `qudit d`, as a +pure state. It is the state obtained by giving every computational-basis vector the same amplitude +`N^(-1/2)`; for `d = 2ⁿ` it is `|+⟩^{⊗n} = H^{⊗n}|0…0⟩`, the standard starting state of the quantum +algorithms of Nielsen & Chuang, Chapters 5–6 (quantum Fourier transform, Deutsch–Jozsa, Grover, …). + +* `uniformSuperposition d` — the pure state with vector `N^(-1/2) ∑ₖ |k⟩`. Its normalisation is the + computation `‖N^(-1/2) ∑ₖ |k⟩‖ = N^(-1/2) · ‖∑ₖ |k⟩‖ = N^(-1/2) · √N = 1` (the all-ones vector + has norm + `√N`). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- The **equal (uniform) superposition** `|s⟩ = N^(-1/2) ∑ₖ |k⟩` (`N = d`) of the qudit register +`qudit d`, as a pure state: every computational-basis vector `|k⟩ = quditBasis k` gets the same +amplitude `N^(-1/2)`. It is normalised because `‖N^(-1/2) ∑ₖ |k⟩‖ = N^(-1/2) · √N = 1` (the +all-ones vector +`∑ₖ |k⟩` has norm `√N`). For `d = 2ⁿ` this is `|+⟩^{⊗n} = H^{⊗n}|0…0⟩`. -/ +def uniformSuperposition (d : ℕ) [NeZero d] : PureState (qudit d) where + vec := (Real.sqrt d : ℂ)⁻¹ • ∑ k : Fin d, (quditBasis k).vec + normalized := by + change ‖(Real.sqrt d : ℂ)⁻¹ • ∑ k : Fin d, EuclideanSpace.single k (1 : ℂ)‖ = 1 + have hd : (0 : ℝ) < d := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne d) + rw [norm_smul] + have h1 : ‖(Real.sqrt d : ℂ)⁻¹‖ = (Real.sqrt d)⁻¹ := by + rw [norm_inv, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (Real.sqrt_nonneg _)] + have hcoord : ∀ x : Fin d, (∑ k : Fin d, EuclideanSpace.single k (1 : ℂ)).ofLp x = 1 := by + intro x; rw [WithLp.ofLp_sum, Finset.sum_apply]; simp [PiLp.single_apply] + have h2 : ‖∑ k : Fin d, EuclideanSpace.single k (1 : ℂ)‖ = Real.sqrt d := by + rw [EuclideanSpace.norm_eq] + simp only [hcoord, norm_one, one_pow, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one] + rw [h1, h2, inv_mul_cancel₀ (Real.sqrt_ne_zero'.mpr hd)] + +/-- The underlying vector of `uniformSuperposition d` is `N^(-1/2) ∑ₖ |k⟩`. -/ +@[simp] +theorem uniformSuperposition_vec (d : ℕ) [NeZero d] : + (uniformSuperposition d).vec + = (Real.sqrt d : ℂ)⁻¹ • ∑ k : Fin d, (quditBasis k).vec := rfl + +/-- **Amplitude of the uniform superposition on a computational-basis state:** `⟨x, ψ⟩ = N^(-1/2)`. +Every basis state `|x⟩` has the same amplitude `N^(-1/2)` in `|ψ⟩ = uniformSuperposition d`, by +orthonormality of the computational basis (`quditBasis_inner`): `⟨x, N^(-1/2) ∑ₖ |k⟩⟩ = N^(-1/2) +∑ₖ δₓₖ = +N^(-1/2)`. -/ +theorem uniformSuperposition_inner_quditBasis (d : ℕ) [NeZero d] (x : Fin d) : + inner ℂ (quditBasis x).vec (uniformSuperposition d).vec = (Real.sqrt d : ℂ)⁻¹ := by + rw [uniformSuperposition_vec, inner_smul_right, inner_sum, + Finset.sum_congr rfl (fun y _ => quditBasis_inner x y), + Finset.sum_ite_eq Finset.univ x (fun _ => (1 : ℂ))] + simp + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/UnitaryBlochRotation.lean b/LeanPool/AxQM/Postulates/API/UnitaryBlochRotation.lean new file mode 100644 index 0000000000..82ccaa89ba --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/UnitaryBlochRotation.lean @@ -0,0 +1,193 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.Postulates.API.BlochState +public import LeanPool.AxQM.Postulates.API.BlochRotationGate +public import LeanPool.AxQM.Concrete.BlochUnitaryRotation +public import LeanPool.AxQM.Concrete.SpecialOrthogonalAxisAngle +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ToEuclideanCLMSingle + +/-! +# AxQM.Postulates.API — unitary gates rotate the Bloch sphere (N&C Exercise 8.13) + +This file promotes the concrete `SU(2) → SO(3)` core (`Concrete.BlochUnitaryRotation`, N&C +Exercise 8.13) to `Evolution`/`State`: a single-qubit unitary gate, acting on qubit states by +conjugation `ρ ↦ U ρ U†` (`Evolution.evolve`), rotates the Bloch vector by a *proper rotation* +`R ∈ SO(3)`. This is the grounded reading of Exercise 8.13 — *unitary transformations correspond to +rotations of the Bloch sphere* — as a statement about state evolution, not a bare matrix +conjugation. + +## What is formalized + +* `unitaryGate hU` — for a `2 × 2` unitary `U` (`hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ`), the + **gate** as an `Evolution qubit`, its operator the promotion `Matrix.toEuclideanCLM U` and its + unitarity transported from `hU` through the `⋆`-algebra isomorphism (exactly the `rotAxisGate` + pattern, but for an *arbitrary* single-qubit unitary — it ranges over the whole `SU(2)` cover). +* `unitaryGate_op` — a `simp` bridge exposing the underlying operator `Matrix.toEuclideanCLM U`. +* `unitaryGate_evolve_blochState` — **the worked identity**: evolving the Bloch state + `blochState r = ½(I + r·σ)` by `unitaryGate hU` gives the Bloch state of the rotated vector, + `(unitaryGate hU).evolve (blochState r) = blochState ((blochRotationOfUnitary U) r)`. The rotated + vector stays in the Bloch ball (`Concrete.blochRotationOfUnitary_mulVec_sq_sum`: a unitary + conjugation preserves the squared Bloch length), so the right-hand `blochState` is well defined. +* `exists_mem_specialOrthogonalGroup_unitaryGate_evolve_blochState` — **Exercise 8.13**: for any + single-qubit unitary gate there is a proper rotation `R ∈ SO(3)` such that its state evolution + sends `blochState r` to `blochState (R r)` — unitaries *are* rotations of the Bloch sphere. +* `exists_evolution_evolve_blochState_of_mem_specialOrthogonalGroup` — **the converse + (surjectivity of the `SU(2) → SO(3)` cover)**: *every* proper rotation `O ∈ SO(3)` is the + Bloch-sphere action of some qubit unitary conjugation `ρ ↦ U ρ U†`. Together with the forward + statement this shows the single-qubit unitary conjugations realise **exactly** the proper + rotations of the Bloch sphere. This is the ingredient of the qubit converse of **Nielsen & + Chuang, Problem 8.3** that turns the pre/post rotations `O₁, O₂` of a unital channel's + Bloch-matrix SVD `M = O₁ · diag d · O₂` into unitary conjugations. + +## Relation to other files + +The statement of Exercise 8.13 is in [upstream `AxQM/NC/Ch8/Exercise8_13.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_13.lean); compare Exercises 8.11 and +8.12 and Theorem 8.3. The mathematics — the `SU(2) → SO(3)` homomorphism and its norm preservation — +is entirely in `AxQM/Concrete/BlochUnitaryRotation.lean`; this file only *transports* the concrete +conjugation identity `Concrete.blochMatrix_conj_unitary` across `Matrix.toEuclideanCLM` to the +operator channel, matching it to `blochState`'s operator via `State.ext` (the same route as +[upstream `AxQM/NC/Ch4/Exercise4_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_6.lean); compare `rotAxisGate` / `BlochRotationGate`). + +## Design notes + +* **Gate over an arbitrary unitary, not an arbitrary `Evolution qubit`.** `unitaryGate` takes the + matrix `U` with its unitarity proof. Stating the exercise over a general `E : Evolution qubit` + (extracting `U := toEuclideanCLM.symm E.op`) is equally faithful but needs matrix-extraction + bridging; the `unitaryGate` form already ranges over *all* single-qubit unitaries and mirrors the + existing `rotAxisGate`, so it is the natural choice here. +* **Well-definedness certificate.** `blochState` requires the Bloch vector to lie in the closed unit + ball. `unitaryGate_evolve_blochState` supplies that bound for the rotated vector directly from + `Concrete.blochRotationOfUnitary_mulVec_sq_sum` (squared length preserved). In the existential + headline the caller supplies the (always satisfiable) bound `h'` for `R r`; by proof irrelevance + the resulting `State` does not depend on which proof is used. +-/ + +@[expose] public section + +noncomputable section + +namespace AxQM + +/-- The **single-qubit unitary gate** of a `2 × 2` unitary `U` (`hU : U ∈ Matrix.unitaryGroup +(Fin 2) ℂ`), as a closed-system `Evolution` of the `qubit` (N&C Exercise 8.13). Its operator is `U` +promoted through the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`; the `Evolution` unitarity +obligation is transported from `hU` by `Unitary.map_mem`. This is the general single-qubit unitary, +the `SU(2)`-cover analogue of the axis-specialised `rotAxisGate`. -/ +def unitaryGate {U : Matrix (Fin 2) (Fin 2) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + Evolution qubit where + op := Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) U + unitary := Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) hU + +@[simp] +theorem unitaryGate_op {U : Matrix (Fin 2) (Fin 2) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + (unitaryGate hU).op = Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) U := + rfl + +/-- **Unitary evolution rotates the Bloch vector.** Evolving the Bloch state `blochState r = +½(I + r·σ)` of the qubit by the unitary gate `unitaryGate hU` yields the Bloch state of the rotated +vector `(blochRotationOfUnitary U) r`: +`(unitaryGate hU).evolve (blochState r) = blochState ((blochRotationOfUnitary U).mulVec r)`. + +The rotated vector stays in the Bloch ball (`Concrete.blochRotationOfUnitary_mulVec_sq_sum`: unitary +conjugation preserves the squared Bloch length), so the right-hand `blochState` is well defined; +that bound is the second argument. The proof transports the concrete conjugation identity +`Concrete.blochMatrix_conj_unitary` (`U · blochMatrix r · U† = blochMatrix ((R U) r)`) through the +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM` to the operator channel `ρ ↦ U ρ U†` +(`Evolution.evolve`), matching it to `blochState`'s operator via `State.ext` — the exact route of +the axis-rotation identity `rotAxisGate_evolve_blochState` (N&C Exercise 4.6). -/ +theorem unitaryGate_evolve_blochState {U : Matrix (Fin 2) (Fin 2) ℂ} + (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) (r : Fin 3 → ℝ) + (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) : + (unitaryGate hU).evolve (blochState r h) + = blochState ((Concrete.blochRotationOfUnitary U).mulVec r) + ((Concrete.blochRotationOfUnitary_mulVec_sq_sum hU r).trans_le h) := by + apply State.ext + simp only [Evolution.evolve_op, unitaryGate_op, blochState_op] + rw [← Concrete.blochMatrix_conj_unitary hU, map_mul, map_mul, ← Matrix.star_eq_conjTranspose, + map_star, ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def, + ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_assoc] + -- both sides are now the operator conjugation `U · (r·σ) · U†`; the remaining `rfl` bridges the + -- `qubit.space ≡ EuclideanSpace ℂ (Fin 2)` defeq (unfolded only at default transparency). + rfl + +/-- **Nielsen & Chuang, Exercise 8.13 (physics headline) — unitary transformations correspond to +rotations of the Bloch sphere.** For any single-qubit unitary `U`, the state evolution +`ρ ↦ U ρ U†` (`unitaryGate hU |>.evolve`) acts on the Bloch state `blochState r = ½(I + r·σ)` as a +*proper rotation* of its Bloch vector: there is `R ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ` with +`(unitaryGate hU).evolve (blochState r) = blochState (R r)` for every Bloch vector `r`. The witness +is `blochRotationOfUnitary U`, the `SU(2) → SO(3)` image of `U`. + +The rotated vector `R r` is again in the Bloch ball (its squared length is preserved, +`Concrete.blochRotationOfUnitary_mulVec_sq_sum`), so `blochState (R r)` is always well defined; the +membership proof `h'` is a hypothesis the caller supplies, and by proof irrelevance the equated +`State` does not depend on it. -/ +theorem exists_mem_specialOrthogonalGroup_unitaryGate_evolve_blochState + {U : Matrix (Fin 2) (Fin 2) ℂ} (hU : U ∈ Matrix.unitaryGroup (Fin 2) ℂ) : + ∃ R ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ, + ∀ (r : Fin 3 → ℝ) (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) + (h' : (R.mulVec r) 0 ^ 2 + (R.mulVec r) 1 ^ 2 + (R.mulVec r) 2 ^ 2 ≤ 1), + (unitaryGate hU).evolve (blochState r h) = blochState (R.mulVec r) h' := + ⟨Concrete.blochRotationOfUnitary U, + Concrete.blochRotationOfUnitary_mem_specialOrthogonalGroup hU, + fun r h _ => by rw [unitaryGate_evolve_blochState hU r h]⟩ + +/-- **Surjectivity of the `SU(2) → SO(3)` cover — every proper rotation is a qubit unitary +conjugation (Nielsen & Chuang, Problem 8.3, qubit converse).** For every `O ∈ SO(3)` there is a +single-qubit unitary `Evolution U` of the `qubit` whose state conjugation `ρ ↦ U ρ U†` +(`Evolution.evolve`) acts on the Bloch sphere exactly as `O`: +`U.evolve (blochState r) = blochState (O r)` for every Bloch vector `r`. + +This is the **converse** of the forward headline +`exists_mem_specialOrthogonalGroup_unitaryGate_evolve_blochState` (Exercise 8.13): together they +say the single-qubit unitary conjugations realise *exactly* the proper rotations of the Bloch +sphere. In Problem 8.3's qubit direction a unital channel's Bloch matrix factors as +`M = O₁ · diag d · O₂` (`Concrete.exists_specialOrthogonalGroup_diagonal_factor`); this lemma turns +the outer rotations `O₁, O₂ ∈ SO(3)` into unitary conjugations, so the whole channel becomes a +composition of random-unitary channels. + +The witness is the axis rotation gate `rotAxisGate n̂ θ`, where `O = rot3D n̂ θ` is the axis–angle +decomposition of `O` (`Concrete.exists_rot3D_eq_mulVec_of_mem_specialOrthogonalGroup`, Euler's +theorem). Its Bloch action `(rotAxisGate n̂ θ).evolve (blochState r) = blochState (rot3D n̂ θ r)` is +the Exercise 4.6 identity `rotAxisGate_evolve_blochState` (reused from +`BlochRotationGate`); since `O r = rot3D n̂ θ r` the two rotated Bloch states coincide. The caller +supplies the (always satisfiable) membership proof `h'` for `O r`; by proof irrelevance the equated +`State` does not depend on it. -/ +theorem exists_evolution_evolve_blochState_of_mem_specialOrthogonalGroup + {O : Matrix (Fin 3) (Fin 3) ℝ} (hO : O ∈ Matrix.specialOrthogonalGroup (Fin 3) ℝ) : + ∃ U : Evolution qubit, + ∀ (r : Fin 3 → ℝ) (h : r 0 ^ 2 + r 1 ^ 2 + r 2 ^ 2 ≤ 1) + (h' : (O.mulVec r) 0 ^ 2 + (O.mulVec r) 1 ^ 2 + (O.mulVec r) 2 ^ 2 ≤ 1), + U.evolve (blochState r h) = blochState (O.mulVec r) h' := by + obtain ⟨n, θ, hn, hOv⟩ := Concrete.exists_rot3D_eq_mulVec_of_mem_specialOrthogonalGroup hO + refine ⟨rotAxisGate n θ, fun r h h' => ?_⟩ + -- The axis rotation gate's Bloch action (N&C Ex 4.6), reused from `BlochRotationGate`. + rw [rotAxisGate_evolve_blochState hn θ r h] + -- `O r = rot3D n̂ θ r`, so the rotated Bloch states coincide (proof irrelevance on the bound). + apply State.ext + simp only [blochState_op, hOv r] + rfl + +/-- **A general one-qubit `unitaryGate` acts as its matrix column.** On a computational-basis state +`|z⟩` the one-qubit gate `unitaryGate hM` (`M ∈ Matrix.unitaryGroup (Fin 2) ℂ`) produces the +superposition `∑_w M w z · |w⟩`, the `z`-th column of `M`. The general form of the gate-specific +`hadamardGate_evolvePure_qubitBasis_sum` / `rotZGate_evolvePure_qubitBasis_sum`, read off the column +action `Matrix.toEuclideanCLM_apply_single` through `unitaryGate_op` and `qubitBasis_vec`. This is +the single-wire factor a tower re-expression of a single-qubit register gate matches the register +two-term superposition against (e.g. `Core/PauliDiagWireTower`). -/ +theorem unitaryGate_evolvePure_qubitBasis_sum {M : Matrix (Fin 2) (Fin 2) ℂ} + (hM : M ∈ Matrix.unitaryGroup (Fin 2) ℂ) (z : Fin 2) : + ((unitaryGate hM).evolvePure (qubitBasis z)).vec = ∑ w : Fin 2, M w z • (qubitBasis w).vec := by + rw [Evolution.evolvePure_vec, unitaryGate_op, qubitBasis_vec] + refine (Matrix.toEuclideanCLM_apply_single M z).trans (Finset.sum_congr rfl fun w _ => ?_) + exact congrArg (M w z • ·) (qubitBasis_vec w).symm + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/UnitaryFreedom.lean b/LeanPool/AxQM/Postulates/API/UnitaryFreedom.lean new file mode 100644 index 0000000000..b24351a9a0 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/UnitaryFreedom.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Ensemble +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum + +/-! +# AxQM — unitary freedom in the ensemble + +This file contains the machinery behind **Nielsen–Chuang Theorem 2.6** ("unitary freedom +in the ensemble for density matrices"). The theorem answers: *which ensembles give rise to the same +density operator?* Following N&C, it is convenient to absorb the probabilities into the vectors, +working with the **subnormalized vectors** `|ψ_tildeᵢ⟩ = √pᵢ |ψᵢ⟩` (eq. between (2.165) and +(2.166)); an +ensemble `{pᵢ, |ψᵢ⟩}` then "generates" the density operator `ρ = ∑ᵢ |ψ_tildeᵢ⟩⟨ψ_tildeᵢ|`, since +`√pᵢ · conj(√pᵢ) = pᵢ`. + +The ensemble form of the theorem (N&C eq. (2.167)) is: two ensembles `e`, `f` **of the same size** +(the "padded" form — pad the smaller ensemble with probability-zero entries) generate the same +density operator iff their subnormalized vectors are related by a unitary matrix, +`√pᵢ|ψᵢ⟩ = ∑ⱼ uᵢⱼ √qⱼ|φⱼ⟩`. + +## Main definitions + +* `AxQM.Ensemble.tildeVec` — the subnormalized vectors `√pᵢ • |ψᵢ⟩` of an ensemble. +* `AxQM.Ensemble.UnitarilyRelated` — the relation "same size, and the subnormalized + vectors are related by a unitary coefficient matrix" (N&C eq. (2.167)). + +## Main results + +* `Ensemble.toState_op_eq_sum_rankOne_tildeVec` — the **bridge**: an ensemble's density operator is + the sum of the rank-one projectors of its subnormalized vectors, `ρ = ∑ᵢ |ψ_tildeᵢ⟩⟨ψ_tildeᵢ|`. +* `Ensemble.toState_op_eq_iff_unitarilyRelated` — Theorem 2.6, operator form over ensembles: two + equal-size ensembles have equal density operators iff they are `UnitarilyRelated`. + +The statement of Theorem 2.6, `Ensemble.toState_eq_iff_unitarilyRelated`, for ensembles and +states, is in `LeanPool/AxQM/NC/Ch2/Theorem6.lean`. + +The mathematical core — the vector-family biconditional +`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup` — lives in +`ToMathlib/Analysis/InnerProductSpace/RankOneSum.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open InnerProductSpace Finset + +noncomputable section + +namespace AxQM + +variable {S : QSystem} + +namespace Ensemble + +/-- The **subnormalized vectors** `|ψ_tildeᵢ⟩ = √pᵢ |ψᵢ⟩` of an ensemble `{pᵢ, |ψᵢ⟩}` +(Nielsen–Chuang, +between eqs. (2.165) and (2.166)): the pure-state vectors scaled by the square roots of their +probabilities. The ensemble's density operator `ρ = ∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` is exactly the sum of the +rank-one projectors of these vectors, `∑ᵢ |ψ_tildeᵢ⟩⟨ψ_tildeᵢ|` +(`toState_op_eq_sum_rankOne_tildeVec`), +because `√pᵢ · conj(√pᵢ) = pᵢ`. -/ +def tildeVec (e : Ensemble S) (i : Fin e.card) : S.space := + (Real.sqrt (e.prob i) : ℂ) • (e.states i).vec + +/-- **The density operator of an ensemble is the sum of rank-one projectors of its subnormalized +vectors**: `ρ = ∑ᵢ |ψ_tildeᵢ⟩⟨ψ_tildeᵢ|` with `|ψ_tildeᵢ⟩ = √pᵢ |ψᵢ⟩`. This is the bridge from the +probability-weighted form `∑ᵢ pᵢ |ψᵢ⟩⟨ψᵢ|` (`Ensemble.toState_op`) to the subnormalized-vector form +used by Nielsen–Chuang Theorem 2.6, using `rankOne (√pᵢ • v) (√pᵢ • v) = (√pᵢ · conj √pᵢ) • rankOne +v v = pᵢ • rankOne v v` (`InnerProductSpace.rankOne_smul_smul_self`, `Real.mul_self_sqrt`). -/ +theorem toState_op_eq_sum_rankOne_tildeVec (e : Ensemble S) : + e.toState.op = ∑ i, rankOne ℂ (e.tildeVec i) (e.tildeVec i) := by + rw [toState_op] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [tildeVec, rankOne_smul_smul_self, ← PureState.toState_op] + congr 1 + rw [starRingEnd_apply, Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, + Real.mul_self_sqrt (e.prob_nonneg i)] + +/-- **Unitary freedom relation** on ensembles (Nielsen–Chuang Theorem 2.6, eq. (2.167)): two +ensembles `e`, `f` are unitarily related when they have the **same size** (`e.card = f.card` — the +"padded" form: pad the smaller ensemble with probability-zero entries) and their subnormalized +vectors are related by a unitary coefficient matrix `u`, `√pᵢ|ψᵢ⟩ = ∑ⱼ uᵢⱼ √qⱼ|φⱼ⟩`. -/ +def UnitarilyRelated (e f : Ensemble S) : Prop := + ∃ (h : e.card = f.card) (u : Matrix (Fin e.card) (Fin e.card) ℂ), + u ∈ Matrix.unitaryGroup (Fin e.card) ℂ ∧ + ∀ i, e.tildeVec i = ∑ j, u i j • f.tildeVec (Fin.cast h j) + +/-- **Nielsen–Chuang Theorem 2.6, operator form over ensembles** (eq. (2.167)). Two ensembles `e`, +`f` of the same size (`e.card = f.card`, the padded form) have equal density operators +`e.toState.op = f.toState.op` **iff** they are `UnitarilyRelated`: their subnormalized vectors +`√pᵢ|ψᵢ⟩` are related by a unitary coefficient matrix. + +Via the bridge `toState_op_eq_sum_rankOne_tildeVec`, both density operators are sums of rank-one +projectors of subnormalized vectors; reindexing `f`'s sum along `Fin.cast` onto the common index +`Fin e.card`, the vector-family biconditional +`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup` gives exactly the unitary +coefficient matrix. -/ +theorem toState_op_eq_iff_unitarilyRelated {e f : Ensemble S} (hcard : e.card = f.card) : + e.toState.op = f.toState.op ↔ e.UnitarilyRelated f := by + have : CompleteSpace S.space := FiniteDimensional.completeSpace ℂ S.space + have hf : f.toState.op + = ∑ i : Fin e.card, + rankOne ℂ (f.tildeVec (Fin.cast hcard i)) (f.tildeVec (Fin.cast hcard i)) := by + rw [toState_op_eq_sum_rankOne_tildeVec] + exact (Equiv.sum_comp (finCongr hcard) + (fun j => rankOne ℂ (f.tildeVec j) (f.tildeVec j))).symm + rw [toState_op_eq_sum_rankOne_tildeVec e, hf, + sum_rankOne_self_eq_iff_exists_mem_unitaryGroup] + constructor + · rintro ⟨u, hu, hrel⟩ + exact ⟨hcard, u, hu, hrel⟩ + · rintro ⟨_, u, hu, hrel⟩ + exact ⟨u, hu, hrel⟩ + +end Ensemble + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/UnitarySquareRoot.lean b/LeanPool/AxQM/Postulates/API/UnitarySquareRoot.lean new file mode 100644 index 0000000000..a165c19bfc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/UnitarySquareRoot.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Concrete.UnitarySquareRoot +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.API.Qubit + +/-! +# AxQM.Postulates.API — the square root of a single-qubit gate + +Every single-qubit gate `U : Evolution qubit` has a *square-root gate* `V` with `V ∘ V = U`. This +is the gate-level (`Evolution`) form of the matrix square root `Concrete.exists_unitary_sq`, and it +is the input to Nielsen & Chuang's Figure 4.8 construction of `C²(U)` (Exercises 4.21/4.22): that +circuit is built from a `V` with `V² = U`, so the existence of such a `V` for an *arbitrary* gate +`U` is what makes the *"for any single-qubit unitary `U`"* statement of Exercise 4.22 faithful (no +weakening of the hypothesis). + +## What is formalised + +* `AxQM.Evolution.exists_comp_self_eq` — for every `U : Evolution qubit` there is a + `V : Evolution qubit` with `V.comp V = U`. + +## Design notes + +**Construction (lift through `toEuclideanCLM`).** It lifts the matrix square root through the +`⋆`-algebra isomorphism `Matrix.toEuclideanCLM`: `M := toEuclideanCLM⁻¹ U.op` is a unitary matrix +(`toEuclideanCLM` is a `⋆`-isomorphism, so it preserves and reflects unitarity), +`Concrete.exists_unitary_sq` gives a unitary `√M` with `√M * √M = M`, and `V := toEuclideanCLM √M` +is a gate with `V ∘ V = U` because `toEuclideanCLM` carries matrix multiplication to composition +(`map_mul`) and `toEuclideanCLM M = U.op` (`apply_symm_apply`). This is the same operator↔matrix +bridge used by `Evolution.exists_op_eq_phase_smul_rotAxisGate` (Exercise 4.8). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Every single-qubit gate has a square-root gate.** For any `U : Evolution qubit` there is a +`V : Evolution qubit` with `V.comp V = U` (i.e. `V² = U`). The witness is `toEuclideanCLM √M`, where +`√M` is a unitary square root (`Concrete.exists_unitary_sq`) of the matrix `M = toEuclideanCLM⁻¹ +U.op` of `U`; `V.comp V = U` follows because the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM` +carries matrix multiplication to operator composition. This supplies the `V` with `V² = U` required +by Nielsen & Chuang's Figure 4.8 construction of `C²(U)`. -/ +theorem Evolution.exists_comp_self_eq (U : Evolution qubit) : + ∃ V : Evolution qubit, V.comp V = U := by + obtain ⟨M, hMmem, hMsq⟩ := Concrete.exists_unitary_sq + (Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).symm U.unitary) + refine ⟨⟨Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) M, + Unitary.map_mem (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)) hMmem⟩, ?_⟩ + apply Evolution.ext + rw [Evolution.comp_op] + change (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) M).comp + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2) M) = U.op + rw [← ContinuousLinearMap.mul_def, ← map_mul, hMsq] + exact (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin 2)).apply_symm_apply U.op + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/UnreadMeasurement.lean b/LeanPool/AxQM/Postulates/API/UnreadMeasurement.lean new file mode 100644 index 0000000000..dd11e203cf --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/UnreadMeasurement.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.MeasurementOperation +public import LeanPool.AxQM.Postulates.API.ProjectiveMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# AxQM — the unread (non-selective) post-measurement state (N&C Exercise 4.32, part 1) + +When a measurement `m` (Postulate 3, `Measurement`) is performed but its outcome is **not learned**, +the state assigned to the system is the *non-selective* (unread) post-measurement state: the +ensemble of the collapsed branches weighted by their Born probabilities. At the operator level this +is the operator-sum (Kraus) map of the measurement operators applied to `ρ`, + + `ρ ↦ Σᵢ Mᵢ ρ Mᵢ†` (Nielsen–Chuang §2.4, Exercise 4.32, Eq. (4.40)), + +and it is again a genuine density operator: positive because each summand `Mᵢ ρ Mᵢ†` is positive, +and of trace one because `Σᵢ Mᵢ† Mᵢ = 1` (the measurement completeness relation, +`Measurement.complete`). + +This file defines the unread state and proves the operator identity of Exercise 4.32's **first** +claim; the **second** claim — that measuring one factor of a composite system leaves the other +factor's reduced state unchanged (`tr₂(ρ) = tr₂(ρ')`) — is the statement +`Measurement.unreadState_reducedLeft_onRight` in [upstream `AxQM/NC/Ch4/Exercise4_32.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch4/Exercise4_32.lean), proved from the +lemma `LinearMap.partialTraceRight_sum_conj_map_id`. + +## Contents + +* `Measurement.unreadState` — the unread/non-selective post-measurement state `ρ' = Σᵢ Mᵢ ρ Mᵢ†`, + as a genuine `State` (density operator), built on the Kraus map `ContinuousLinearMap.krausSumₗ`. +* `Measurement.unreadState_op_eq_sum_opElement` — **Exercise 4.32, Eq. (4.40):** the unread state is + the sum of the quantum operation elements, `ρ' = Σᵢ Eᵢ(ρ) = Σᵢ Mᵢ ρ Mᵢ†` (with `Eᵢ(ρ) = + Measurement.opElement`, N&C Eq. (8.5)). Each summand `Eᵢ(ρ) = pᵢ · ρᵢ` is the branch state `ρᵢ` + (`Measurement.postMeasurement`, the collapse) weighted by its Born probability `pᵢ` + (`postMeasurement_op_eq_bornProb_smul_opElement`), so `ρ'` is exactly the mixture assigned by an + observer who did not learn the result. +* `Measurement.IsProjective.unreadState_op` — the literal N&C form for a **projective** measurement + (`Mᵢ = Pᵢ` orthogonal projectors, so `Mᵢ† = Mᵢ`): `ρ' = Σᵢ Pᵢ ρ Pᵢ` (Eq. (4.40) with + `P₀ = |0⟩⟨0|`, `P₁ = |1⟩⟨1|` the special two-outcome case in the exercise text). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- The **unread (non-selective) post-measurement state** `ρ' = Σᵢ Mᵢ ρ Mᵢ†` (Nielsen–Chuang +Exercise 4.32, Eq. (4.40)): the state assigned after the measurement `m` when the outcome is *not* +learned — the Born-weighted mixture of the collapsed branches. It is a genuine density operator: +positivity is `krausSumₗ_isPositive` (each `Mᵢ ρ Mᵢ†` is positive), and trace one is +`trace_krausSumₗ` together with completeness `Σᵢ Mᵢ† Mᵢ = 1` (`m.complete`), which turns +`tr(Σᵢ Mᵢ ρ Mᵢ†) = tr((Σᵢ Mᵢ† Mᵢ) ρ)` into `tr(ρ) = 1`. -/ +def unreadState (m : Measurement ι S) (ρ : State S) : State S where + op := krausSumₗ m.op ρ.op + isDensity := by + refine ⟨krausSumₗ_isPositive m.op ρ.isPositive_op, ?_⟩ + rw [trace_krausSumₗ, m.complete, one_def, id_comp] + exact ρ.trace_op_eq_one + +/-- The operator of the unread post-measurement state is the Kraus map `Σᵢ Mᵢ ρ Mᵢ†`. -/ +@[simp] theorem unreadState_op (m : Measurement ι S) (ρ : State S) : + (m.unreadState ρ).op = krausSumₗ m.op ρ.op := rfl + +/-- **Nielsen–Chuang Exercise 4.32, Eq. (4.40).** The unread post-measurement state is the sum of +the measurement's quantum operation elements, `ρ' = Σᵢ Eᵢ(ρ) = Σᵢ Mᵢ ρ Mᵢ†`. Since each +`Eᵢ(ρ) = pᵢ · ρᵢ` is the collapsed branch `ρᵢ` weighted by its Born probability `pᵢ` +(`postMeasurement_op_eq_bornProb_smul_opElement`), this is the mixture assigned by an observer who +did not learn the measurement result. -/ +theorem unreadState_op_eq_sum_opElement (m : Measurement ι S) (ρ : State S) : + (m.unreadState ρ).op = ∑ i, m.opElement ρ i := by + rw [unreadState_op, krausSumₗ_apply] + simp only [opElement_eq_postOp, ContinuousLinearMap.postOp] + +/-- **Nielsen–Chuang Exercise 4.32, Eq. (4.40), projective form.** For a *projective* measurement — +one whose operators are orthogonal projectors `Mᵢ = Pᵢ` (`Measurement.IsProjective`), so `Mᵢ† = Mᵢ` +— the unread post-measurement state is `ρ' = Σᵢ Pᵢ ρ Pᵢ`, the literal statement of Eq. (4.40) (the +`P₀ = |0⟩⟨0|`, `P₁ = |1⟩⟨1|` two-outcome projective measurement of the exercise text is this special +case). -/ +theorem IsProjective.unreadState_op {m : Measurement ι S} (h : m.IsProjective) (ρ : State S) : + (m.unreadState ρ).op = ∑ i, (m.op i).comp (ρ.op.comp (m.op i)) := by + rw [unreadState_op_eq_sum_opElement] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [opElement_eq_postOp, ContinuousLinearMap.postOp, (h i).isSelfAdjoint.adjoint_eq] + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/WeakMonotonicity.lean b/LeanPool/AxQM/Postulates/API/WeakMonotonicity.lean new file mode 100644 index 0000000000..5873f728cc --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/WeakMonotonicity.lean @@ -0,0 +1,106 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ReducedStateTransport +public import LeanPool.AxQM.Postulates.API.PureMarginalEntropy +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM — purification-marginal reshaping toward weak monotonicity (N&C Exercise 11.24) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, **Exercise 11.24** (p. 521) asks to +derive the "form-1" strong-subadditivity inequality — **weak monotonicity** + +`S(A) + S(B) ≤ S(A,C) + S(B,C)` (N&C eq. (11.107)) + +as a *consequence* of strong subadditivity `S(A,B,C) + S(B) ≤ S(A,B) + S(B,C)` (eq. (11.108), +formalised faithfulness-free as `State.vonNeumannEntropy_add_le_add'`). N&C's derivation is the +mirror of the forward one: introduce a reference `R` **purifying** `ABC`, apply strong subadditivity +to the tripartite `(R, B, C)` marginal, + +`S(R,B,C) + S(B) ≤ S(R,B) + S(B,C)`, + +and rewrite the two `R`-terms by the pure-state complementary-subsystem identity +(`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`, N&C Theorem 11.8(3)): on the pure +four-party state `ABCR`, `S(R,B,C) = S(A)` and `S(R,B) = S(A,C)`, giving eq. (11.107). + +## What this file provides + +This file proves the **reference-pull reshape** and the **subsystem-`A` +purity identity** `S(A) = S(R,B,C)`. Concretely, for the purification `ρ.purify` on +`(A ⊗ (B ⊗ C)) ⊗ R`, the `R ⊗ (B ⊗ C)` marginal — the state to which strong subadditivity is +applied — is read off after the reshape `pullRefReshape`, and this file proves its entropy is +`S(A)`. The generic `reducedLeft` reshaping lemmas this rests on +(`State.reducedLeft_congr_tmul_refl`, `State.congr_trans`, +`State.reducedLeft_congr_assoc_symm`) are in `AxQM/Postulates/API/ReducedStateTransport.lean`. + +* `QSystem.pullRefReshape` — the reshape `(A ⊗ M) ⊗ R ≃ₛ A ⊗ (R ⊗ M)` bringing the reference `R` + beside `M` (used with `M := B ⊗ C`); +* `State.reducedLeft_congr_pullRefReshape` — the `A`-marginal of the `pullRefReshape` reshape is + the iterated `A`-marginal `reducedLeft.reducedLeft`; +* `PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape` — the purity identity + `S(A) = S(R ⊗ M-marginal)` for a pure state on `(A ⊗ M) ⊗ R`. + +The complementary `reducedRight`-side identities (`S(B,C)`, `S(B)`, `S(A,C) = S(R,B)`) require the +`partialTraceLeft` counterparts of the reassociation lemmas and are proved separately, in +`AxQM/Postulates/API/WeakMonotonicityReducedRight.lean` and +`AxQM/Postulates/API/WeakMonotonicitySecondComplement.lean`; weak monotonicity itself is assembled +in `LeanPool/AxQM/NC/Ch11/Exercise24.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C R : QSystem} + +/-- The **reference-pull reshape** `(A ⊗ M) ⊗ R ≃ₛ A ⊗ (R ⊗ M)`: re-bracket to `A ⊗ (M ⊗ R)`, then +swap the inner pair to bring the reference `R` beside `M`. For a purification on +`(A ⊗ (B ⊗ C)) ⊗ R` (with `M := B ⊗ C`) this exposes the `R ⊗ (B ⊗ C)` marginal — the tripartite +state to which strong subadditivity is applied in N&C Exercise 11.24 — as the `reducedRight` of the +reshape. -/ +def QSystem.pullRefReshape (A M R : QSystem) : ((A ⊗ M) ⊗ R) ≃ₛ (A ⊗ (R ⊗ M)) := + (QSystem.assoc A M R).symm.trans (QSystem.Iso.tmul (QSystem.Iso.refl A) (QSystem.Iso.comm M R)) + +/-- **`A`-marginal of the reference-pull reshape.** `(congr (pullRefReshape A M R) ρ).reducedLeft = +ρ.reducedLeft.reducedLeft`: the reshape only rearranges the non-`A` factors, so the `A`-marginal is +the iterated `A`-marginal of `ρ`. Combines `State.reducedLeft_congr_tmul_refl` (the swap leaves the +`A`-marginal alone) with `State.reducedLeft_congr_assoc_symm` (the re-bracketing) through +`State.congr_trans`. -/ +theorem State.reducedLeft_congr_pullRefReshape {A M R : QSystem} (ρ : State ((A ⊗ M) ⊗ R)) : + (State.congr (QSystem.pullRefReshape A M R) ρ).reducedLeft = ρ.reducedLeft.reducedLeft := by + rw [QSystem.pullRefReshape, State.congr_trans, State.reducedLeft_congr_tmul_refl, + State.reducedLeft_congr_assoc_symm] + +/-- **Subsystem-`A` purity identity** (N&C Exercise 11.24, the `S(R,B,C) = S(A)` step). For a pure +state `ψ` on `(A ⊗ M) ⊗ R`, the entropy of the subsystem `A` equals the entropy of the `R ⊗ M` +marginal (the complement of `A` in the pure four-party state): + +`S(A) = S(R ⊗ M-marginal)`, + +where `S(A) = S(ψ.reducedLeft.reducedLeft)` and the `R ⊗ M` marginal is read off as the +`reducedRight` of the `pullRefReshape` reshape. Immediate from the pure-state +complementary-subsystem identity `PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight` applied +to the reshaped pure state, whose `reducedLeft` is `S(A)` by +`State.reducedLeft_congr_pullRefReshape`. With `M := B ⊗ C` and `ψ := ρ.purify` this is the +`S(A) = S(R,B,C)` half of the derivation of weak monotonicity from strong subadditivity. -/ +theorem PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape {A M R : QSystem} + (ψ : PureState ((A ⊗ M) ⊗ R)) : + ψ.toState.reducedLeft.reducedLeft.vonNeumannEntropy = + (State.congr (QSystem.pullRefReshape A M R) ψ.toState).reducedRight.vonNeumannEntropy := by + have h := PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight + (PureState.congr (QSystem.pullRefReshape A M R) ψ) + rwa [PureState.congr_toState, State.reducedLeft_congr_pullRefReshape] at h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/WeakMonotonicityReducedRight.lean b/LeanPool/AxQM/Postulates/API/WeakMonotonicityReducedRight.lean new file mode 100644 index 0000000000..bcb3344341 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/WeakMonotonicityReducedRight.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.WeakMonotonicity +public import LeanPool.AxQM.Postulates.API.ReducedStateReshape +public import LeanPool.AxQM.Postulates.API.SubadditivityReformulations + +/-! +# AxQM — the `reducedRight`-side marginal crux for weak monotonicity (N&C Ex 11.24) + +Nielsen & Chuang **Exercise 11.24** (p. 521) derives weak monotonicity +`S(A) + S(B) ≤ S(A,C) + S(B,C)` from strong subadditivity by purifying `ρ` with a reference `R` and +applying strong subadditivity to the tripartite `R ⊗ (B ⊗ C)` marginal. The reduced-state reshaping +this needs splits into two halves along which factor is traced first: + +* the **`reducedLeft` half** — the subsystem-`A` purity identity `S(A) = S(R,B,C)` + (`PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape`, + `Postulates/API/WeakMonotonicity`); +* the **`reducedRight` half** (this file) — the *marginal-consistency* fact that the + `R ⊗ (B ⊗ C)` marginal `τ := (ρ.purify.congr (pullRefReshape ..)).reducedRight` has the *same* + `B ⊗ C`-marginal as `ρ` itself, so the `S(B)` and `S(B,C)` terms produced by strong subadditivity + on `τ` are `ρ`'s own marginals. + +## What this file provides + +* `State.reducedRight_reducedLeft_congr_assoc_symm` — trace out `A` then `R` (through the inverse + associator on `(A ⊗ M) ⊗ R`) equals trace out `R` then `A`; the reverse of + `State.reducedRight_reducedLeft_congr_assoc` (`Postulates/API/SubadditivityReformulations`), + obtained by the associator-cancellation trick (as for + `State.reducedLeft_reducedLeft_congr_assoc`): instantiate the forward lemma at + `ω.congr (assoc _ _ _).symm` and cancel `(assoc).symm.trans assoc = refl` (the transport-backbone + left-inverse law `QSystem.Iso.symm_trans_self`, `Postulates/API/ReducedStateTransport`), so no new + proof at the level of the density operator `.op` is needed. +* `State.reducedRight_reducedRight_congr_pullRefReshape` — the **crux**: for any state `ω` on + `(A ⊗ M) ⊗ R`, the `M`-marginal of the reference-pull marginal + `(ω.congr (QSystem.pullRefReshape A M R)).reducedRight` equals the `M`-marginal of + `ω.reducedLeft`. + With `M := B ⊗ C` and `ω := ρ.purify` (so `ω.reducedLeft = ρ` by `State.purify_reducedLeft_eq`), + this is exactly `τ.reducedRight = ρ.reducedRight`. + +It reuses the one-factor reshape quartet from `Postulates/API/ReducedStateReshape` — in particular +`State.reducedRight_congr_tmul_right` (reshaping the *kept* right factor conjugates the right +marginal), which peels the reference swap `id ⊗ comm` off the `reducedRight`. + +## Ingredients + +The proofs use the `partialTraceLeft` naturality (through the reshaping lemmas above). The +`reducedLeft ↔ reducedRight` swap it uses is `State.reducedLeft_congr_comm` +(`Postulates/API/ReducedStateComm`); the associator trace-commutation is +`State.reducedRight_reducedLeft_congr_assoc` (`Postulates/API/SubadditivityReformulations`). + +Weak monotonicity is assembled from this together with the `reducedLeft` half in +`LeanPool/AxQM/NC/Ch11/Exercise24.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A M R : QSystem} + +/-- **`A`-then-`R` marginal via the inverse associator equals `R`-then-`A`.** For a state `ω` on +the left-nested composite `(A ⊗ M) ⊗ R`, re-associating to `A ⊗ (M ⊗ R)`, tracing out `A` +(`reducedRight`), then tracing out `R` (`reducedLeft`) gives the same `M`-marginal as tracing out +`R` (`reducedLeft`) then `A` (`reducedRight`): + +`Tr_R (Tr_A (assoc⁻¹ ω)) = Tr_A (Tr_R ω)`. + +The reverse face of `State.reducedRight_reducedLeft_congr_assoc` (which applies the +trace-commutation `LinearMap.partialTraceLeft_partialTraceRight_assoc` once), obtained by cancelling +the associator against its inverse: instantiate the forward lemma at +`ω.congr (assoc A M R).symm` and rewrite `(assoc).symm.trans assoc = refl` +(`QSystem.Iso.symm_trans_self`). -/ +theorem State.reducedRight_reducedLeft_congr_assoc_symm (ω : State ((A ⊗ M) ⊗ R)) : + ((State.congr (QSystem.assoc A M R).symm ω).reducedRight).reducedLeft = + ω.reducedLeft.reducedRight := by + have h := State.reducedRight_reducedLeft_congr_assoc (State.congr (QSystem.assoc A M R).symm ω) + rw [← State.congr_trans, QSystem.Iso.symm_trans_self, State.congr_refl] at h + exact h.symm + +/-- **`M`-marginal consistency of the reference-pull marginal** (N&C Exercise 11.24). For any state +`ω` on `(A ⊗ M) ⊗ R`, the `M`-marginal of the reference-pull `R ⊗ M` marginal +`(ω.congr (QSystem.pullRefReshape A M R)).reducedRight` equals the `M`-marginal of `ω`'s `A ⊗ M` +marginal `ω.reducedLeft`: + +`((pullRefReshape ω)ʳ)ʳ = (ωˡ)ʳ`. + +Both trace out `A` and `R`, leaving `M`; the identity is that the order and the reference +re-bracketing do not matter. With `M := B ⊗ C` and `ω := ρ.purify` (whose left marginal is `ρ`, +`State.purify_reducedLeft_eq`) this is `τ.reducedRight = ρ.reducedRight`, so the `S(B,C)` term of +strong subadditivity applied to the reference marginal `τ` is `S(ρ.reducedRight)` and (one more +`reducedLeft`) the `S(B)` term is `S(ρ.reducedRight.reducedLeft)`. Peels the reference swap off the +`reducedRight` via `State.reducedRight_congr_tmul_right`, cancels it against +`State.reducedLeft_congr_comm`, and closes with +`State.reducedRight_reducedLeft_congr_assoc_symm`. -/ +theorem State.reducedRight_reducedRight_congr_pullRefReshape (ω : State ((A ⊗ M) ⊗ R)) : + ((State.congr (QSystem.pullRefReshape A M R) ω).reducedRight).reducedRight = + ω.reducedLeft.reducedRight := by + rw [QSystem.pullRefReshape, State.congr_trans, State.reducedRight_congr_tmul_right, + ← State.reducedLeft_congr_comm] + exact State.reducedRight_reducedLeft_congr_assoc_symm ω + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/WeakMonotonicitySecondComplement.lean b/LeanPool/AxQM/Postulates/API/WeakMonotonicitySecondComplement.lean new file mode 100644 index 0000000000..b010c0c21d --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/WeakMonotonicitySecondComplement.lean @@ -0,0 +1,106 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.ReducedStateReshape +public import LeanPool.AxQM.Postulates.API.WeakMonotonicity + +/-! +# AxQM — the second complementarity identity `S(A,B) = S(C,R)` for weak monotonicity + +Nielsen & Chuang **Exercise 11.24** (p. 521) derives weak monotonicity +`S(A) + S(C) ≤ S(A,B) + S(B,C)` (the "form-1" strong-subadditivity inequality, N&C eq. (11.107)) +from strong subadditivity by **purifying** `ρ` on `A ⊗ (B ⊗ C)` with a reference `R` to a pure +four-party state `ψ` on `(A ⊗ (B ⊗ C)) ⊗ R`, applying strong subadditivity to the `R ⊗ (C ⊗ B)` +marginal, and rewriting the reference terms by pure-state complementarity. That derivation needs two +complementary-subsystem entropy identities on the pure four-party state: + +* the **subsystem-`A` identity** `S(A) = S(R,B,C)` + (`PureState.vonNeumannEntropy_reducedLeft_reducedLeft_eq_pullRefReshape`, + `Postulates/API/WeakMonotonicity`, the `1‖3` split `A ‖ (R,B,C)`); +* the **`A⊗B` identity** `S(A,B) = S(C,R)` (this file, the balanced `2‖2` split + `(A,B) ‖ (C,R)`). + +## What this file provides + +For a pure state `ψ` on `(A ⊗ (B ⊗ C)) ⊗ R`, split the four factors into the complementary pairs +`{A, B}` and `{C, R}`. The reshape `QSystem.abcrReshape` regroups `(A ⊗ (B ⊗ C)) ⊗ R` into +`(A ⊗ B) ⊗ (C ⊗ R)`, exposing those two blocks as the left and right factors; pure-state +complementarity (`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight`, N&C Theorem 11.8(3)) +then equates their marginal entropies: + +`S(A,B) = S(C,R)`, + +where the `A ⊗ B` marginal is read off as `(ρ.congr (assoc A B C)).reducedLeft` with `ρ := ψ`'s +`A ⊗ (B ⊗ C)`-marginal (`State.reducedLeft_congr_abcrReshape`), and the `C ⊗ R` marginal is the +`reducedRight` of the reshape. + +* `QSystem.abcrReshape` — the reshape `(A ⊗ (B ⊗ C)) ⊗ R ≃ₛ (A ⊗ B) ⊗ (C ⊗ R)`; +* `State.reducedLeft_congr_abcrReshape` — the `A ⊗ B`-marginal of the reshape is the + `A ⊗ B`-marginal of the `A ⊗ (B ⊗ C)`-marginal `ψ.reducedLeft`; +* `PureState.vonNeumannEntropy_ab_eq_cr` — the balanced complementarity `S(A,B) = S(C,R)`. + +With `ψ := ρ.purify` (whose `A ⊗ (B ⊗ C)`-marginal is `ρ`, `State.purify_reducedLeft_eq`) this is +the `S(A,B) = S(R,C)` half of N&C Exercise 11.24. The reduced-state reshaping toolkit it uses is in +`ReducedStateReshape` and `ReducedStateTransport`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {A B C R : QSystem} + +/-- The **front-pair reshape** `(A ⊗ (B ⊗ C)) ⊗ R ≃ₛ (A ⊗ B) ⊗ (C ⊗ R)`: re-bracket the front +factor `A ⊗ (B ⊗ C)` to `(A ⊗ B) ⊗ C` and then de-associate the outer `⊗ R`, grouping the pair +`{A, B}` on the left and the complementary pair `{C, R}` on the right. On a purification of `ρ` +(with `R` the reference) this exposes both `ρ`'s `A ⊗ B` marginal and the complementary `C ⊗ R` +marginal of the pure four-party state — the two blocks whose entropies complementarity equates. -/ +def QSystem.abcrReshape (A B C R : QSystem) : + (((A ⊗ (B ⊗ C)) ⊗ R)) ≃ₛ ((A ⊗ B) ⊗ (C ⊗ R)) := + (QSystem.Iso.tmul (QSystem.assoc A B C) (QSystem.Iso.refl R)).trans + ((QSystem.assoc (A ⊗ B) C R).symm) + +/-- **`A ⊗ B`-marginal of the front-pair reshape.** For a state `ψ` on `(A ⊗ (B ⊗ C)) ⊗ R`, +`(ψ.congr (abcrReshape A B C R)).reducedLeft = (ψ.reducedLeft.congr (assoc A B C)).reducedLeft`: the +reshape only rearranges the non-`A⊗B` factors, so its `A ⊗ B`-marginal is the `A ⊗ B`-marginal of +`ψ`'s `A ⊗ (B ⊗ C)`-marginal. Combines `State.reducedLeft_congr_assoc_symm` (the outer +de-association leaves the left block alone) with `State.reducedLeft_congr_tmul_left` (the front +re-bracketing is carried through the trace) via `State.congr_trans`. -/ +theorem State.reducedLeft_congr_abcrReshape (ψ : State ((A ⊗ (B ⊗ C)) ⊗ R)) : + (State.congr (QSystem.abcrReshape A B C R) ψ).reducedLeft + = (State.congr (QSystem.assoc A B C) ψ.reducedLeft).reducedLeft := by + rw [QSystem.abcrReshape, State.congr_trans, State.reducedLeft_congr_assoc_symm, + State.reducedLeft_congr_tmul_left] + +/-- **Second complementarity identity `S(A,B) = S(C,R)`** (N&C Exercise 11.24, the `2‖2` half). For +a pure state `ψ` on `(A ⊗ (B ⊗ C)) ⊗ R`, the entropy of the `A ⊗ B` marginal equals the entropy of +the complementary `C ⊗ R` marginal of the pure four-party state: + +`S(A,B) = S(C,R)`, + +where `S(A,B) = S((ψ.reducedLeft.congr (assoc A B C)).reducedLeft)` (the `A ⊗ B`-marginal of `ψ`'s +`A ⊗ (B ⊗ C)`-marginal) and the `C ⊗ R` marginal is the `reducedRight` of the front-pair reshape +`QSystem.abcrReshape`. Immediate from pure-state complementarity +`PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight` (N&C Theorem 11.8(3)) applied to the +reshaped pure state, whose `reducedLeft` is the `A ⊗ B` marginal by +`State.reducedLeft_congr_abcrReshape`. With `ψ := ρ.purify` this is the `S(A,B) = S(R,C)` step in +the derivation of weak monotonicity from strong subadditivity. -/ +theorem PureState.vonNeumannEntropy_ab_eq_cr (ψ : PureState ((A ⊗ (B ⊗ C)) ⊗ R)) : + (State.congr (QSystem.assoc A B C) ψ.toState.reducedLeft).reducedLeft.vonNeumannEntropy + = (State.congr (QSystem.abcrReshape A B C R) ψ.toState).reducedRight.vonNeumannEntropy := by + have h := PureState.vonNeumannEntropy_reducedLeft_eq_reducedRight + (PureState.congr (QSystem.abcrReshape A B C R) ψ) + rwa [PureState.congr_toState, State.reducedLeft_congr_abcrReshape] at h + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/WireGatePlacement.lean b/LeanPool/AxQM/Postulates/API/WireGatePlacement.lean new file mode 100644 index 0000000000..bb81be4049 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/WireGatePlacement.lean @@ -0,0 +1,169 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.BlockGatePlacement +public import LeanPool.AxQM.Postulates.API.WirePermutation +public import LeanPool.AxQM.Postulates.API.Qubit + +/-! +# Placing a gate on an arbitrary set of wires (N&C Exercise 4.29) + +Nielsen & Chuang, Exercise 4.29 (p. 184), asks for a no-work-qubit `O(n²)` circuit implementing +`Cⁿ(X)`. Bottoming the multiply-controlled-`NOT` blocks of the tight `(n+1)`-wire circuit to +genuine two-control gates (`Toffoli`/`CNOT`/`NOT`) requires placing such a gate on a **chosen, +non-contiguous set of wires** of the register. This file combines `Evolution.onBlock` and +`Evolution.permWires` into a general arbitrary-wire placement gate. + +The two combinators do half the job each: + +* `Evolution.onBlock G b` places a gate `G : Evolution (S ^⊗ₛ a)` on the **first** `a` wires of + `S ^⊗ₛ (a+b)` (a contiguous block at the front); +* `Evolution.permWires σ` **relabels** the wires by a permutation `σ : Equiv.Perm (Fin (a+b))`. + +Conjugating the front-block gate by a wire permutation moves the block to any chosen wire set: +`Evolution.onWires G b σ := permWires σ ∘ onBlock G b ∘ permWires σ⁻¹` places `G` on exactly the +wires `σ 0, …, σ (a-1)` (the image of the front block under `σ`), leaving the rest untouched. This +is the construction "conjugate a contiguous gate by the wire permutation that gathers the chosen +wires". + +## What is formalised + +* `QSystem.tensorPowAdd_symm_tmul_piTensor` — the **block-reassembly dictionary**: the *inverse* + block-split isomorphism carries a pair of block product states `(⨂ᵢ |p i⟩) ⊗ (⨂ⱼ |q j⟩)` back + to the single product `⨂ₖ |(Fin.append p q) k⟩` on `S ^⊗ₛ (a+b)`. The fold that turns + `Evolution.onBlock`'s split output back into a product state so a further wire permutation can + act on it (the reverse of `QSystem.tensorPowAdd_congr_piTensor`). +* `Evolution.onWires G b σ` — the **arbitrary-wire placement gate** on `S ^⊗ₛ (a+b)`: the gate `G` + placed on the wires `σ 0, …, σ (a-1)`, built by conjugating `Evolution.onBlock G b` by + `Evolution.permWires σ`. +* `Evolution.onWires_evolvePure_qubitBasis` — its **computational-basis truth table for a classical + gate** on the qubit register `qubit ^⊗ₛ (a+b)`. When `G` is *classical* — it permutes the + computational basis, `G (⨂ᵢ |c i⟩) = ⨂ᵢ |γ c i⟩` for a classical bit-string action + `γ : (Fin a → Fin 2) → (Fin a → Fin 2)` (the case of a `Toffoli`/`CNOT`/`NOT`) — then + `Evolution.onWires G b σ` applies `γ` to the bits carried on the target wires + `σ (Fin.castAdd b ·)` and leaves the other wires unchanged, read back in the original wire layout + via `σ⁻¹`. This is the wire-addressed truth table for the `Cᵏ(X)`-block `Toffoli` reduction. + +## Design notes + +* **Why a computational-basis (not all-product-states) hypothesis.** A general gate `G` may + entangle, so `onWires G b σ` need not map an arbitrary product input to a product output — there + is no closed-form product action for superposition inputs. Crucially, a computational-basis + *permutation* is **not** the same as a product-preserving map: `Toffoli`/`CNOT` map every + computational-basis product to a computational-basis product, yet they **entangle** superposition + products (e.g. `CNOT |+⟩|0⟩ = (|00⟩+|11⟩)/√2`). So the correct, satisfiable hypothesis for the + `Toffoli`/`CNOT`/`NOT` gates the exercise places is basis-preservation on the `Fin 2`-indexed + computational basis (`hG` below), *not* preservation of every product pure state. Under it every + step of the conjugation keeps a computational-basis product a computational-basis product, giving + a clean bit-string truth table. Keeping `γ` an arbitrary bit-string function makes the lemma + reusable for every classical block gate. +* **Why conjugation, reusing existing dictionaries — not fresh `reindex` surgery.** + `Evolution.permWires`/`Evolution.onBlock` already come with their computational-basis + actions; conjugating reuses them (via the pre-existing `Evolution.evolvePure_comp`) and the group + law `Evolution.permWires` satisfies, keeping every step a one-line application of an existing + dictionary plus the reassembly fold. The inner permutation is written `σ.symm` (`= σ⁻¹` in + `Equiv.Perm`) so `permWires σ.symm` contributes `σ.symm.symm = σ` with a single `Equiv.symm_symm`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {a : ℕ} + +/-- **Block-reassembly dictionary for the inverse block isomorphism.** The inverse block-split +isomorphism `(QSystem.tensorPowAdd S a b).symm` carries a pair of block product states +`(⨂ᵢ |p i⟩) ⊗ (⨂ⱼ |q j⟩)` — the first `a` wires and the last `b` — back to the single product +state `⨂ₖ |(Fin.append p q) k⟩` on `S ^⊗ₛ (a+b)`. The reverse of +`QSystem.tensorPowAdd_congr_piTensor`, used to fold `Evolution.onBlock`'s split output back into a +product state so a further wire permutation can act on it. -/ +theorem QSystem.tensorPowAdd_symm_tmul_piTensor (a b : ℕ) + (p : Fin a → PureState S) (q : Fin b → PureState S) : + PureState.congr (QSystem.tensorPowAdd S a b).symm + (PureState.piTensor p ⊗ PureState.piTensor q) + = PureState.piTensor (Fin.append p q) := by + rw [← PureState.congr_symm_congr (QSystem.tensorPowAdd S a b) + (PureState.piTensor (Fin.append p q)), + QSystem.tensorPowAdd_congr_piTensor a b (Fin.append p q)] + congr 2 <;> simp only [Fin.append_left, Fin.append_right] <;> rfl + +/-- **The arbitrary-wire placement gate** on `S ^⊗ₛ (a+b)`: given a gate `G : Evolution (S ^⊗ₛ a)` +and a wire permutation `σ : Equiv.Perm (Fin (a+b))`, the closed-system `Evolution` that acts as `G` +on the wire set `σ 0, …, σ (a-1)` (the image of the front `a`-wire block under `σ`) and as the +identity on the remaining wires. It is the front-block gate `Evolution.onBlock G b` conjugated by +the wire permutation `Evolution.permWires σ` — relabel the target wires to the front, run `G` +there, then relabel back. Its computational-basis truth table for a classical `G` is +`Evolution.onWires_evolvePure_qubitBasis`. -/ +def Evolution.onWires (G : Evolution (S ^⊗ₛ a)) (b : ℕ) (σ : Equiv.Perm (Fin (a + b))) : + Evolution (S ^⊗ₛ (a + b)) := + (Evolution.permWires σ).comp ((G.onBlock b).comp (Evolution.permWires σ.symm)) + +/-- **The identity wire permutation places a gate on the front block.** Conjugating by the identity +permutation is trivial, so arbitrary-wire placement `Evolution.onWires` degenerates to the +contiguous front-block placement `Evolution.onBlock`: `G.onWires b 1 = G.onBlock b`. Both +conjugating factors `Evolution.permWires 1` are the identity evolution +(`Evolution.permWires_one`, using `Equiv.Perm.one_symm` for the inner `σ.symm`), and composing with +the identity is a no-op (`Evolution.id_comp`, `Evolution.comp_id`). The special case in which the +chosen wires already are the front `a`-wire block — used to read off the block-embedded form of a +gate placed on contiguous wires. -/ +theorem Evolution.onWires_one (G : Evolution (S ^⊗ₛ a)) (b : ℕ) : + G.onWires b (1 : Equiv.Perm (Fin (a + b))) = G.onBlock b := by + rw [Evolution.onWires, ← Equiv.Perm.inv_def 1, inv_one, Evolution.permWires_one, + Evolution.id_comp, + Evolution.comp_id] + +/-- **Computational-basis truth table of the arbitrary-wire placement gate for a classical gate.** +Let `G : Evolution (qubit ^⊗ₛ a)` be *classical*: it permutes the computational basis, +`G (⨂ᵢ |c i⟩) = ⨂ᵢ |γ c i⟩` for a classical bit-string action +`γ : (Fin a → Fin 2) → (Fin a → Fin 2)` (the case of a `Toffoli`/`CNOT`/`NOT`, which map every +computational-basis product to a computational-basis product — unlike an arbitrary product state, +which they may entangle). Then on the computational-basis input `⨂ₖ |c k⟩`, +`Evolution.onWires G b σ` applies `γ` to the bits `c` carries on the target wires +`σ (Fin.castAdd b ·)` and leaves the other wires' bits unchanged, the whole read back in the +original wire layout by `σ⁻¹`: +`onWires G b σ (⨂ₖ |c k⟩) = ⨂ₖ |Fin.append (γ (c ∘ σ ∘ castAdd)) (c ∘ σ ∘ natAdd) (σ⁻¹ k)⟩`. +The wire-addressed truth table the `Cᵏ(X)`-block `Toffoli` reduction consumes. Proved by evaluating +the conjugation `permWires σ ∘ onBlock G b ∘ permWires σ⁻¹` step by step +(`Evolution.evolvePure_comp`), each step carrying a computational-basis product to a +computational-basis product via the dictionary lemmas, and pulling `qubitBasis` through the final +`Fin.append`. -/ +theorem Evolution.onWires_evolvePure_qubitBasis {a : ℕ} (G : Evolution (qubit ^⊗ₛ a)) (b : ℕ) + (σ : Equiv.Perm (Fin (a + b))) + (γ : (Fin a → Fin 2) → (Fin a → Fin 2)) + (hG : ∀ c : Fin a → Fin 2, + G.evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => qubitBasis (γ c i)) + (c : Fin (a + b) → Fin 2) : + (G.onWires b σ).evolvePure (PureState.piTensor fun i => qubitBasis (c i)) + = PureState.piTensor fun i => + qubitBasis (Fin.append (γ fun j => c (σ (Fin.castAdd b j))) + (fun j => c (σ (Fin.natAdd a j))) (σ.symm i)) := by + -- `Fin.append` of two `qubitBasis` families is the `qubitBasis` of the appended bit-strings. + have happ : ∀ (u : Fin a → Fin 2) (w : Fin b → Fin 2), + (Fin.append (fun i => qubitBasis (u i)) fun j => qubitBasis (w j)) + = fun k => qubitBasis (Fin.append u w k) := by + intro u w + funext k + induction k using Fin.addCases with + | left i => simp only [Fin.append_left] + | right j => simp only [Fin.append_right] + let ψ0 : PureState (qubit ^⊗ₛ (a + b)) := PureState.piTensor fun i => qubitBasis (c i) + change (G.onWires b σ).evolvePure ψ0 = _ + rw [Evolution.onWires, Evolution.evolvePure_comp, Evolution.evolvePure_comp, + Evolution.permWires_evolvePure_piTensor] + simp only [Equiv.symm_symm] + rw [Evolution.onBlock_evolvePure_piTensor, hG, QSystem.tensorPowAdd_symm_tmul_piTensor, + Evolution.permWires_evolvePure_piTensor, happ] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/API/WirePermutation.lean b/LeanPool/AxQM/Postulates/API/WirePermutation.lean new file mode 100644 index 0000000000..ab810b9bb8 --- /dev/null +++ b/LeanPool/AxQM/Postulates/API/WirePermutation.lean @@ -0,0 +1,166 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.API.Evolution +public import LeanPool.AxQM.Postulates.PiTensor +public import LeanPool.AxQM.Postulates.PiTensorState + +/-! +# AxQM.Postulates.API — permuting the wires of an `n`-fold register + +An arbitrary permutation of the wires of an `n`-qubit (more generally `n`-copy) register +`S ^⊗ₛ n`, realised as a genuine closed-system `Evolution`. This is the general-`n` **SWAP +network**: the two-factor `Evolution.swap` is the `n = 2` transposition, and here every wire +permutation `σ : Equiv.Perm (Fin n)` becomes a unitary `Evolution.permWires σ` on the register. + +## What is formalised + +* `Evolution.permWires σ` — the **wire-permutation gate** on `S ^⊗ₛ n`: the closed-system + `Evolution` that relabels the tensor factors by `σ`. It is `Evolution.ofLinearIsometryEquiv` of + the factor-reindexing isometry `PiTensorProduct.reindexₗᵢ` along `σ`, so it is an `Evolution` + (Postulate 5) with unitarity inherited from that isometry — the same construction as + `Evolution.swap`. +* `Evolution.ext_tensorPow` — the reusable extensionality principle for evolutions of a tensor + power: two `Evolution (S ^⊗ₛ n)` are equal once their operators agree on every product state + `⨂ₜ i, f i` (product states span the register). +* `Evolution.permWires_op_tprod` — the **action on a product state**: + `permWires σ (⨂ᵢ |fᵢ⟩) = ⨂ᵢ |f_{σ⁻¹ i}⟩`, i.e. the factor sitting on wire `j` is moved to wire + `σ j`. This is the computational content — it lets any wire permutation's effect on a + computational-basis product input be read off directly. +* `Evolution.permWires_evolvePure_piTensor` — the **pure-state counterpart** of the above: + `permWires σ (⨂ₚ i, ψ i) = ⨂ₚ i, ψ (σ⁻¹ i)`, the `evolvePure` action on a product `PureState`, + the form a consumer evolving computational-basis states works with. +* `Evolution.permWires_one`, `Evolution.permWires_mul`, `Evolution.permWires_symm_comp`, + `Evolution.permWires_comp_symm` — the **group functoriality**: the identity permutation is the + identity gate, `permWires (σ * τ) = permWires σ · permWires τ` (a homomorphism from the symmetric + group to the gate composition monoid), and `permWires σ⁻¹` is the two-sided inverse of + `permWires σ`. These are exactly what makes `permWires` a *SWAP network*: any permutation + factors into transpositions, so any wire routing is built by composing swaps. + +## Design notes + +* **Why a general `Equiv.Perm (Fin n)` gate.** Placing a `Toffoli`/`CNOT` on *non-contiguous* + wires of an `(n+1)`-wire register — as Nielsen & Chuang Exercise 4.29 needs in order to + reduce the multiply-controlled-`NOT` blocks of the tight `Cⁿ(X)` circuit to genuine two-control + gates with no work qubit — is done by conjugating a contiguous gate by the wire permutation that + brings the chosen wires together. This needs an arbitrary wire permutation as a unitary + `Evolution`, which this file supplies in full generality (compare the fixed-3-wire `Gate3` and + the two-factor `Evolution.swap`). It applies well beyond Exercise 4.29 (SWAP/sorting networks, + symmetric-group actions on registers). +* **Why the `PiTensorProduct.reindexₗᵢ` route.** The register `S ^⊗ₛ n` is the *symmetric* n-ary + `PiTensorProduct` (`AxQM/Postulates/PiTensor.lean`), on which relabelling + the factors along `σ : Fin n ≃ Fin n` is exactly `PiTensorProduct.reindexₗᵢ`. Because `σ` + permutes a **constant** family (`fun _ : Fin n ↦ S.space`), the reindexed family + `fun i ↦ (fun _ ↦ S.space) (σ.symm i)` is definitionally the same family, so `reindexₗᵢ … σ` is + a genuine self-isometry-equivalence of `(S ^⊗ₛ n).space` — no associator/reindex bookkeeping, + unlike a right-nested binary tower. Its action on pure tensors is + `PiTensorProduct.reindexₗᵢ_tprod`. +-/ + +@[expose] public section + +open scoped TensorProduct + +noncomputable section + +namespace AxQM + +variable {S : QSystem} {n : ℕ} + +/-! ### The wire-permutation gate -/ + +/-- **The wire-permutation gate** on the `n`-fold register `S ^⊗ₛ n`: given a permutation +`σ : Equiv.Perm (Fin n)` of the wires, the closed-system `Evolution` that relabels the tensor +factors by `σ`. It is `Evolution.ofLinearIsometryEquiv` of the factor-reindexing isometry +`PiTensorProduct.reindexₗᵢ` along `σ`, so it is an `Evolution` with +unitarity inherited from that isometry (the general-`n` form of `Evolution.swap`). Its action on a +product state is `Evolution.permWires_op_tprod`. -/ +def Evolution.permWires (σ : Equiv.Perm (Fin n)) : Evolution (S ^⊗ₛ n) := + Evolution.ofLinearIsometryEquiv (PiTensorProduct.reindexₗᵢ ℂ (fun _ : Fin n => S.space) σ) + +/-- **Extensionality for evolutions of a tensor power:** two evolutions of `S ^⊗ₛ n` are equal once +their operators agree on every product state `⨂ₜ i, f i`. Product states span the register +(`PiTensorProduct.extₛₗ`), so agreement there is full agreement. The workhorse for proving +identities between `Evolution.permWires` gates. -/ +theorem Evolution.ext_tensorPow {A B : Evolution (S ^⊗ₛ n)} + (h : ∀ f : Fin n → S.space, A.op (⨂ₜ[ℂ] i, f i) = B.op (⨂ₜ[ℂ] i, f i)) : A = B := by + apply Evolution.ext + apply ContinuousLinearMap.coe_injective + exact PiTensorProduct.ext (MultilinearMap.ext h) + +/-- The underlying operator of the wire-permutation gate is the factor-reindexing isometry +`PiTensorProduct.reindexₗᵢ` along `σ`. The bridge from the `Evolution` gate to the +`PiTensorProduct.reindexₗᵢ` algebra. -/ +theorem Evolution.permWires_op_apply (σ : Equiv.Perm (Fin n)) (x : (S ^⊗ₛ n).space) : + (Evolution.permWires σ).op x + = PiTensorProduct.reindexₗᵢ ℂ (fun _ : Fin n => S.space) σ x := + Evolution.ofLinearIsometryEquiv_op_apply _ x + +/-- **Action of the wire-permutation gate on a product state:** +`permWires σ (⨂ᵢ |fᵢ⟩) = ⨂ᵢ |f_{σ⁻¹ i}⟩` — the factor on wire `j` is moved to wire `σ j`. The +computational content of the gate (from `PiTensorProduct.reindexₗᵢ_tprod`): the effect of any wire +permutation on a computational-basis product input is read off directly. + +(Not tagged `@[simp]`: on the tensor power `S ^⊗ₛ n` the unfolding simp lemma +`QSystem.tensorPow_space` rewrites inside this lemma's left-hand side, so it is not in +simp-normal form; use it as an explicit rewrite.) -/ +theorem Evolution.permWires_op_tprod (σ : Equiv.Perm (Fin n)) (f : Fin n → S.space) : + (Evolution.permWires σ).op (⨂ₜ[ℂ] i, f i) = ⨂ₜ[ℂ] i, f (σ.symm i) := by + erw [Evolution.permWires_op_apply, PiTensorProduct.reindexₗᵢ_tprod] + +/-- **Action of the wire-permutation gate on a product pure state:** +`permWires σ (⨂ₚ i, ψ i) = ⨂ₚ i, ψ (σ⁻¹ i)` — the factor on wire `j` is moved to wire `σ j`. The +`PureState`/`evolvePure` counterpart of the operator-level `Evolution.permWires_op_tprod`, obtained +by pushing both sides to their underlying vectors (`PureState.piTensor_vec`). It lets any wire +permutation's effect on a computational-basis product input be read off at the state level. -/ +theorem Evolution.permWires_evolvePure_piTensor (σ : Equiv.Perm (Fin n)) + (ψ : Fin n → PureState S) : + (Evolution.permWires σ).evolvePure (PureState.piTensor fun i => ψ i) + = PureState.piTensor fun i => ψ (σ.symm i) := by + apply PureState.ext + erw [Evolution.evolvePure_vec, PureState.piTensor_vec, Evolution.permWires_op_tprod, + PureState.piTensor_vec] + +/-! ### Group functoriality (the SWAP-network laws) -/ + +/-- **The identity permutation is the identity gate:** `permWires 1 = 1`. -/ +theorem Evolution.permWires_one : + Evolution.permWires (1 : Equiv.Perm (Fin n)) = Evolution.id (S := S ^⊗ₛ n) := by + apply Evolution.ext_tensorPow + intro f + rw [Evolution.permWires_op_tprod, Evolution.id_op] + erw [one_apply_eq_self] + rfl + +/-- **`Evolution.permWires` is a homomorphism** from the symmetric group to the gate-composition +monoid: `permWires (σ * τ) = permWires σ · permWires τ`. Composing wire permutations is composing +the gates — the law that lets any wire routing be assembled from transpositions (a SWAP network). -/ +theorem Evolution.permWires_mul (σ τ : Equiv.Perm (Fin n)) : + Evolution.permWires (S := S) (σ * τ) + = (Evolution.permWires σ).comp (Evolution.permWires τ) := by + apply Evolution.ext_tensorPow + intro f + rw [Evolution.comp_op] + erw [ContinuousLinearMap.comp_apply] + rw [Evolution.permWires_op_tprod, Evolution.permWires_op_tprod, Evolution.permWires_op_tprod] + rfl + +/-- **`permWires σ⁻¹` is a right inverse of `permWires σ`:** `permWires σ · permWires σ⁻¹ = 1`. +Undoing a wire permutation is applying the inverse permutation. -/ +theorem Evolution.permWires_symm_comp (σ : Equiv.Perm (Fin n)) : + (Evolution.permWires (S := S) σ).comp (Evolution.permWires σ⁻¹) = Evolution.id := by + rw [← Evolution.permWires_mul, mul_inv_cancel, Evolution.permWires_one] + +/-- **`permWires σ⁻¹` is a left inverse of `permWires σ`:** `permWires σ⁻¹ · permWires σ = 1`. -/ +theorem Evolution.permWires_comp_symm (σ : Equiv.Perm (Fin n)) : + (Evolution.permWires (S := S) σ⁻¹).comp (Evolution.permWires σ) = Evolution.id := by + rw [← Evolution.permWires_mul, inv_mul_cancel, Evolution.permWires_one] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/Composite.lean b/LeanPool/AxQM/Postulates/Composite.lean new file mode 100644 index 0000000000..1d8f60fa07 --- /dev/null +++ b/LeanPool/AxQM/Postulates/Composite.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.Postulates.Evolution +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Purification + +/-! +# AxQM — Postulate 6: composite systems + +The state space of a composite system `S ⊗ T` is the **tensor product** of the +component state spaces (`QSystem.compose`). This file constructs +joint states and evolutions from component ones (Nielsen–Chuang Postulate 4 / §2.2.8): + +* `PureState.tmul` (`ψ ⊗ φ`) — the product pure state on `S ⊗ T`. +* `State.tmul` (`ρ ⊗ σ`) — the product (density) state. +* `Evolution.tmul` (`U ⊗ V`) — the product unitary; `Evolution.onLeft`/`onRight` act with a + gate on one factor (`U ⊗ 1` / `1 ⊗ U`). +* `State.purify` (N&C §2.5) — the canonical purification of a state `ρ` to a pure state on + `S ⊗ QSystem.ofModel (EuclideanSpace ℂ (Fin S.dim))` (the doubled system, ancilla a copy of + `S`), with `State.purify_isPurification` / `State.purify_reducedLeft_eq` recovering `ρ` as its + left marginal (via `TensorProduct.canonicalPurification`). + +**Notation.** The circle-cross `⊗` is the uniform tensor: `S ⊗ T` (systems), +`ρ ⊗ σ` / `ψ ⊗ φ` (states), `U ⊗ V` (evolutions) — overloaded by argument type, scoped to +`AxQM`. Statements read `⊗`, never `tmul`; the tensor product of vectors is written `⊗ₜ`. + +`PureState.tmul`'s normalization is proved on +the explicit underlying space and closed into the bundled goal by defeq. +`State.purify`'s ancilla is named through the `QSystem.ofModel` wrapper, so the +purification lands on a genuine composite system `S ⊗ ·`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **Composite pure state** `ψ ⊗ φ`: the product state of two pure states, on `S ⊗ T`. -/ +def PureState.tmul (ψ : PureState S) (φ : PureState T) : PureState (S ⊗ T) where + vec := ψ.vec ⊗ₜ[ℂ] φ.vec + normalized := by + have h : ‖(ψ.vec ⊗ₜ[ℂ] φ.vec : S.space ⊗[ℂ] T.space)‖ = 1 := by + rw [TensorProduct.norm_tmul, ψ.normalized, φ.normalized, mul_one] + exact h + +@[inherit_doc] scoped infixr:70 " ⊗ " => PureState.tmul + +@[simp] +theorem PureState.tmul_vec (ψ : PureState S) (φ : PureState T) : + (ψ ⊗ φ).vec = ψ.vec ⊗ₜ[ℂ] φ.vec := rfl + +/-- **Composite state** `ρ ⊗ σ`: the product of two states, on `S ⊗ T`. A genuine `State`, +since the tensor of density operators is a density operator. -/ +def State.tmul (ρ : State S) (σ : State T) : State (S ⊗ T) where + op := TensorProduct.mapL ρ.op σ.op + isDensity := ContinuousLinearMap.IsDensityOp.mapL ρ.isDensity σ.isDensity + +@[inherit_doc] scoped infixr:70 " ⊗ " => State.tmul + +@[simp] +theorem State.tmul_op (ρ : State S) (σ : State T) : + (ρ ⊗ σ).op = TensorProduct.mapL ρ.op σ.op := rfl + +/-- **Composite evolution** `U ⊗ V`: the product unitary on `S ⊗ T` (the tensor of +unitaries is unitary, `TensorProduct.mapL_mem_unitary`). -/ +def Evolution.tmul (U : Evolution S) (V : Evolution T) : Evolution (S ⊗ T) where + op := TensorProduct.mapL U.op V.op + unitary := TensorProduct.mapL_mem_unitary U.unitary V.unitary + +@[inherit_doc] scoped infixr:70 " ⊗ " => Evolution.tmul + +@[simp] +theorem Evolution.tmul_op (U : Evolution S) (V : Evolution T) : + (U ⊗ V).op = TensorProduct.mapL U.op V.op := rfl + +/-- **A gate on the left factor**: `U ⊗ 1` acts as `U` on `S`, identity on `T`. -/ +def Evolution.onLeft (U : Evolution S) (T : QSystem) : Evolution (S ⊗ T) := U ⊗ Evolution.id + +/-- **A gate on the right factor**: `1 ⊗ V` acts as `V` on `T`, identity on `S`. -/ +def Evolution.onRight (V : Evolution T) (S : QSystem) : Evolution (S ⊗ T) := Evolution.id ⊗ V + +/-- **Canonical purification** of a state `ρ` (Nielsen–Chuang §2.5): a pure state on the +doubled system `S ⊗ QSystem.ofModel (EuclideanSpace ℂ (Fin S.dim))` — the ancilla is a copy +of `S`, named through the §3.2 model-space wrapper — whose left marginal is `ρ` +(`State.purify_reducedLeft_eq`). Grounds `TensorProduct.canonicalPurification` into the +postulate framework. The witness is `∑ᵢ √λᵢ • (eᵢ ⊗ fᵢ)` for the spectral data `(λᵢ, eᵢ)` +of `ρ`. -/ +def State.purify (ρ : State S) : + PureState (S ⊗ QSystem.ofModel (EuclideanSpace ℂ (Fin S.dim))) where + vec := TensorProduct.canonicalPurification ρ.isDensity (EuclideanSpace.basisFun _ ℂ) + normalized := TensorProduct.norm_canonicalPurification ρ.isDensity _ + +@[simp] +theorem State.purify_vec (ρ : State S) : + (ρ.purify).vec = + TensorProduct.canonicalPurification ρ.isDensity (EuclideanSpace.basisFun _ ℂ) := + rfl + +/-- **The canonical purification is a purification**: the right-partial-trace of +`|ρ.purify⟩⟨ρ.purify|` recovers `ρ.op`. The bridge to `TensorProduct.IsPurification`. -/ +theorem State.purify_isPurification (ρ : State S) : + TensorProduct.IsPurification ρ.op (ρ.purify).vec := + TensorProduct.isPurification_canonicalPurification ρ.isDensity _ + +/-- **The left marginal of the canonical purification is the state itself**: tracing out +the ancilla of `ρ.purify` recovers `ρ`. -/ +theorem State.purify_reducedLeft_eq (ρ : State S) : + (ρ.purify).toState.reducedLeft = ρ := by + ext1 + rw [State.reducedLeft_op, PureState.toState_op] + exact (congrArg LinearMap.toContinuousLinearMap ρ.purify_isPurification).trans + (ContinuousLinearMap.toLinearMap_toContinuousLinearMap _) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/Evolution.lean b/LeanPool/AxQM/Postulates/Evolution.lean new file mode 100644 index 0000000000..df88348ddd --- /dev/null +++ b/LeanPool/AxQM/Postulates/Evolution.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# AxQM — Postulate 5: time evolution (closed systems) + +Closed-system dynamics on a system `S`: an **evolution** is a unitary operator. It acts on +states by conjugation (`evolve`) and on pure states by application (`evolvePure`). + +`evolve` produces a genuine `State` because conjugation by a unitary preserves density +operators (`ContinuousLinearMap.IsDensityOp.conj_isometry`, since `U† U = 1`). The underlying +operator is `Evolution.op`. (`QSystem` bundles finite-dimensionality and hence completeness, so +no per-section instance bookkeeping is needed.) +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-- **Postulate 5 (evolution).** A closed-system **evolution** of the system `S` is a +unitary operator on its state space: `U† U = U U† = 1`. -/ +@[ext] +structure Evolution (S : QSystem) where + /-- The underlying unitary operator. -/ + op : S →L[ℂ] S + /-- The operator is unitary. -/ + unitary : op ∈ unitary (S →L[ℂ] S) + +variable {S : QSystem} + +namespace Evolution + +/-- The isometry identity `U† U = 1` extracted from unitarity. -/ +theorem adjoint_comp_self (U : Evolution S) : (adjoint U.op).comp U.op = 1 := by + have h := (Unitary.mem_iff.mp U.unitary).1 + rwa [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def] at h + +/-- A unitary preserves norms: `‖U x‖ = ‖x‖`. -/ +theorem norm_op_apply (U : Evolution S) (x : S) : ‖U.op x‖ = ‖x‖ := by + have hxx : ⟪x, x⟫_ℂ = ⟪U.op x, U.op x⟫_ℂ := by + calc ⟪x, x⟫_ℂ + = ⟪x, ((adjoint U.op).comp U.op) x⟫_ℂ := by rw [U.adjoint_comp_self]; rfl + _ = ⟪x, (adjoint U.op) (U.op x)⟫_ℂ := by rw [ContinuousLinearMap.comp_apply] + _ = ⟪U.op x, U.op x⟫_ℂ := ContinuousLinearMap.adjoint_inner_right U.op x (U.op x) + have h2 : ‖U.op x‖ ^ 2 = ‖x‖ ^ 2 := by + rw [← inner_self_eq_norm_sq (𝕜 := ℂ), ← inner_self_eq_norm_sq (𝕜 := ℂ), ← hxx] + rw [← Real.sqrt_sq (norm_nonneg (U.op x)), ← Real.sqrt_sq (norm_nonneg x), h2] + +/-- **Evolution of a pure state** (Schrödinger picture): `ψ ↦ U ψ`. -/ +def evolvePure (U : Evolution S) (ψ : PureState S) : PureState S where + vec := U.op ψ.vec + normalized := by rw [U.norm_op_apply, ψ.normalized] + +@[simp] +theorem evolvePure_vec (U : Evolution S) (ψ : PureState S) : + (U.evolvePure ψ).vec = U.op ψ.vec := rfl + +/-- The **identity evolution**, the unit unitary `1`. -/ +def id : Evolution S := ⟨1, one_mem _⟩ + +/-- The **composite evolution** `U ∘ V`, whose operator is `U.op ∘ V.op` (still +unitary, as the product of unitaries). -/ +def comp (U V : Evolution S) : Evolution S := + ⟨U.op.comp V.op, mul_mem U.unitary V.unitary⟩ + +@[simp] +theorem id_op : (Evolution.id : Evolution S).op = 1 := rfl + +@[simp] +theorem comp_op (U V : Evolution S) : (U.comp V).op = U.op.comp V.op := rfl + +@[simp] +theorem comp_id (U : Evolution S) : U.comp Evolution.id = U := by + ext1; rw [comp_op, id_op]; exact mul_one _ + +@[simp] +theorem id_comp (U : Evolution S) : Evolution.id.comp U = U := by + ext1; rw [comp_op, id_op]; exact one_mul _ + +theorem comp_assoc (U V W : Evolution S) : + (U.comp V).comp W = U.comp (V.comp W) := by + ext1; simp only [comp_op, ContinuousLinearMap.comp_assoc] + +/-- `Evolution S` is a monoid under composition `comp` with unit the identity evolution +`id`: the laws are `comp_assoc`, `id_comp`, `comp_id`. This packages the gate monoid so the +generic monoid API (e.g. `Finset.noncommProd`) applies; the rfl-bridges `mul_def` / `one_def` +identify `*`/`1` with `comp`/`id`. -/ +instance : Monoid (Evolution S) where + mul := Evolution.comp + one := Evolution.id + mul_assoc := comp_assoc + one_mul := id_comp + mul_one := comp_id + +@[simp] +theorem mul_def (U V : Evolution S) : U * V = U.comp V := rfl + +@[simp] +theorem one_def : (1 : Evolution S) = Evolution.id := rfl + +/-- Evolving a pure state by a composite is sequential evolution. -/ +theorem evolvePure_comp (U V : Evolution S) (ψ : PureState S) : + (U.comp V).evolvePure ψ = U.evolvePure (V.evolvePure ψ) := by + apply PureState.ext + simp [comp_op, ContinuousLinearMap.comp_apply] + +/-- **Evolution of a state**: `ρ ↦ U ρ U†`. A genuine `State`, since conjugation by a unitary +preserves density operators. -/ +def evolve (U : Evolution S) (ρ : State S) : State S where + op := U.op.comp (ρ.op.comp (adjoint U.op)) + isDensity := ContinuousLinearMap.IsDensityOp.conj_isometry U.adjoint_comp_self ρ.isDensity + +@[simp] +theorem evolve_op (U : Evolution S) (ρ : State S) : + (U.evolve ρ).op = U.op.comp (ρ.op.comp (adjoint U.op)) := rfl + +/-- Evolving a state by a composite is sequential evolution. -/ +theorem evolve_comp (U V : Evolution S) (ρ : State S) : + (U.comp V).evolve ρ = U.evolve (V.evolve ρ) := by + apply State.ext + simp only [evolve_op, comp_op, ContinuousLinearMap.adjoint_comp, + ContinuousLinearMap.comp_assoc] + +end Evolution + +end AxQM diff --git a/LeanPool/AxQM/Postulates/Measurement.lean b/LeanPool/AxQM/Postulates/Measurement.lean new file mode 100644 index 0000000000..1b4bb07f72 --- /dev/null +++ b/LeanPool/AxQM/Postulates/Measurement.lean @@ -0,0 +1,140 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PostMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVM + +/-! +# AxQM — Postulates 3 & 4: measurement, the Born rule, and collapse + +A **measurement** on a system `S` is a finite family of +*measurement operators* `Mᵢ` with the completeness relation `∑ᵢ Mᵢ† Mᵢ = 1` +(Nielsen–Chuang Postulate 3 / §2.2.3). This is the faithful general measurement — it +carries enough information for **both** the outcome probabilities (P3) and the state +update (P4), unlike a bare POVM (which records only the effects `Eᵢ = Mᵢ† Mᵢ`). + +* `toPOVM` — the induced POVM (effects `Mᵢ† Mᵢ`), used for the Born rule. +* `bornProb` (P3) — outcome probability `Tr(Mᵢ ρ Mᵢ†)`; `bornProb_nonneg`, + `sum_bornProb_eq_one`. +* `postMeasurement` (P4) — the normalized post-measurement `State` + `Mᵢ ρ Mᵢ† / p(i)`, a genuine state when the outcome is possible. + +The measurement operators are `Measurement.op`. (`QSystem` bundles finite-dimensionality +and hence completeness, so no per-section instance bookkeeping is needed.) +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Postulate 3 (measurement).** A **measurement** on the system `S` with outcome +set `ι` is a family of measurement operators `Mᵢ` satisfying the completeness +relation `∑ᵢ Mᵢ† Mᵢ = 1`. -/ +structure Measurement (ι : Type*) [Fintype ι] (S : QSystem) where + /-- The measurement operators. -/ + op : ι → (S →L[ℂ] S) + /-- Completeness: `∑ᵢ Mᵢ† Mᵢ = 1`. -/ + complete : ∑ i, (adjoint (op i)).comp (op i) = 1 + +variable {ι : Type*} [Fintype ι] {S : QSystem} + +namespace Measurement + +/-- The **induced POVM**: outcome `i` has effect `Eᵢ = Mᵢ† Mᵢ`. Used +for the Born rule; positivity from `isPositive_adjoint_comp_self`, completeness +from the measurement's `complete` field. -/ +def toPOVM (m : Measurement ι S) : POVM ι ℂ S where + elements i := (adjoint (m.op i)).comp (m.op i) + isPositive i := ContinuousLinearMap.isPositive_adjoint_comp_self (m.op i) + sum_eq_one := m.complete + +@[simp] +theorem toPOVM_elements (m : Measurement ι S) (i : ι) : + m.toPOVM.elements i = (adjoint (m.op i)).comp (m.op i) := rfl + +/-- The **projective measurement in an orthonormal basis** `b`: outcome `i` has measurement +operator the rank-one projector `Mᵢ = |bᵢ⟩⟨bᵢ|`. Completeness `∑ᵢ Mᵢ† Mᵢ = 1` is the +resolution of the identity (`OrthonormalBasis.sum_rankOne_eq_id`) composed with the +idempotence of each self-adjoint projector. The `Measurement` counterpart of +`POVM.ofOrthonormalBasis` (its induced POVM is `toPOVM_ofOrthonormalBasis`). -/ +def ofOrthonormalBasis (b : OrthonormalBasis ι ℂ S) : Measurement ι S where + op i := rankOne ℂ (b i) (b i) + complete := by + rw [ContinuousLinearMap.one_def, ← b.sum_rankOne_eq_id] + exact Finset.sum_congr rfl fun i _ ↦ adjoint_rankOne_comp_self (b.orthonormal.1 i) + +@[simp] +theorem ofOrthonormalBasis_op (b : OrthonormalBasis ι ℂ S) (i : ι) : + (ofOrthonormalBasis b).op i = rankOne ℂ (b i) (b i) := rfl + +/-- The POVM induced by the projective measurement `ofOrthonormalBasis b` is the rank-one +POVM `POVM.ofOrthonormalBasis b`: the measurement is *projective*, so each effect +`Eᵢ = Mᵢ† Mᵢ = Mᵢ = |bᵢ⟩⟨bᵢ|`. -/ +theorem toPOVM_ofOrthonormalBasis (b : OrthonormalBasis ι ℂ S) : + (ofOrthonormalBasis b).toPOVM = POVM.ofOrthonormalBasis b := by + refine POVM.ext (funext fun i ↦ ?_) + rw [toPOVM_elements, ofOrthonormalBasis_op, POVM.ofOrthonormalBasis_elements] + exact adjoint_rankOne_comp_self (b.orthonormal.1 i) + +/-- **Born rule (P3).** The probability of outcome `i` when measuring `m` on state +`ρ`: `Tr(Mᵢ ρ Mᵢ†) = Tr(Eᵢ ρ)`. -/ +def bornProb (m : Measurement ι S) (ρ : State S) (i : ι) : ℝ := m.toPOVM.toPMF ρ.op i + +/-- Born probabilities are non-negative. -/ +theorem bornProb_nonneg (m : Measurement ι S) (ρ : State S) (i : ι) : + 0 ≤ m.bornProb ρ i := + m.toPOVM.toPMF_nonneg ρ.isPositive_op i + +/-- **Born rule normalization.** The outcome probabilities sum to one. -/ +theorem sum_bornProb_eq_one (m : Measurement ι S) (ρ : State S) : + ∑ i, m.bornProb ρ i = 1 := + m.toPOVM.sum_toPMF_eq_one ρ.isDensity + +/-- Each outcome probability is at most one — it is bounded by the total mass `1`. -/ +theorem bornProb_le_one (m : Measurement ι S) (ρ : State S) (i : ι) : + m.bornProb ρ i ≤ 1 := + m.sum_bornProb_eq_one ρ ▸ + Finset.single_le_sum (fun j _ ↦ m.bornProb_nonneg ρ j) (Finset.mem_univ i) + +/-- The Born probability in post-measurement-operation form: `p(i) = re Tr(Mᵢ ρ Mᵢ†)`. +Bridges the POVM-effect form (`bornProb`) to the state-update normalization +(`ContinuousLinearMap.postOp`) via trace-cyclicity. -/ +theorem bornProb_eq_re_trace_postOp (m : Measurement ι S) (ρ : State S) (i : ι) : + m.bornProb ρ i = + RCLike.re (LinearMap.trace ℂ S (ContinuousLinearMap.postOp m.op ρ.op i : S →ₗ[ℂ] S)) := by + rw [bornProb, POVM.toPMF_eq, ContinuousLinearMap.trace_postOp] + rfl + +/-- **Postulate 4 (state update / collapse).** The normalized post-measurement +state for outcome `i`, when that outcome is possible (`bornProb ≠ 0`): +`ρ ↦ Mᵢ ρ Mᵢ† / p(i)`. A genuine `State`, since the normalized conjugation is again +a density operator. -/ +def postMeasurement (m : Measurement ι S) (ρ : State S) (i : ι) + (hp : m.bornProb ρ i ≠ 0) : State S where + op := ContinuousLinearMap.postState m.op ρ.op i + isDensity := + ContinuousLinearMap.postState_isDensityOp m.op ρ.isDensity i + (by rw [← bornProb_eq_re_trace_postOp]; exact hp) + +@[simp] +theorem postMeasurement_op (m : Measurement ι S) (ρ : State S) (i : ι) + (hp : m.bornProb ρ i ≠ 0) : + (m.postMeasurement ρ i hp).op = ContinuousLinearMap.postState m.op ρ.op i := rfl + +end Measurement + +end AxQM diff --git a/LeanPool/AxQM/Postulates/Observable.lean b/LeanPool/AxQM/Postulates/Observable.lean new file mode 100644 index 0000000000..73b3667791 --- /dev/null +++ b/LeanPool/AxQM/Postulates/Observable.lean @@ -0,0 +1,93 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum + +/-! +# AxQM — Postulate 2: observables + +An **observable** is a bundled self-adjoint operator on a system `S`. By the spectral theorem it +has an orthonormal eigenbasis with real eigenvalues — its possible measurement values. + +This file also defines the **expectation value** `⟪A⟫` for density operators +(`State.expectation`) and for pure states (`PureState.expectation`). The two agree on pure +states (`expectation_toState`). + +`QSystem` bundles a finite-dimensional complex Hilbert space, so completeness (for +the adjoint/star) and finite-dimensionality (for the spectral theorem) derive — no +per-section instance bookkeeping. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Postulate 2 (observable).** An **observable** on the system `S` is a +self-adjoint operator; its real spectrum is the set of possible measurement values. -/ +structure Observable (S : QSystem) where + /-- The underlying operator. -/ + op : S →L[ℂ] S + /-- The operator is self-adjoint. -/ + selfAdjoint : IsSelfAdjoint op + +variable {S : QSystem} + +namespace Observable + +/-- An observable, as a linear map, is symmetric — the bridge to the spectral +theorem. -/ +theorem isSymmetric (A : Observable S) : A.op.toLinearMap.IsSymmetric := + ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mp A.selfAdjoint + +end Observable + +/-! ## Expectation values -/ + +namespace PureState + +/-- The **expectation value** `⟪A⟫_ψ = ⟪ψ, A ψ⟫` of an observable `A` in the pure +state `ψ`. Real because `A` is self-adjoint. -/ +def expectation (ψ : PureState S) (A : Observable S) : ℝ := (⟪ψ.vec, A.op ψ.vec⟫_ℂ).re + +end PureState + +namespace State + +/-- The **expectation value** `⟪A⟫_ρ = Tr(ρ A)` of an observable `A` in the state +`ρ`. Real because `ρ`, `A` are self-adjoint. -/ +def expectation (ρ : State S) (A : Observable S) : ℝ := + (LinearMap.trace ℂ S ((ρ.op ∘L A.op : S →L[ℂ] S) : S →ₗ[ℂ] S)).re + +end State + +/-- **Spectral theorem for observables.** Every observable `A` has an orthonormal +eigenbasis `b` with **real** eigenvalues `lam`: `A (bᵢ) = lamᵢ • bᵢ`. -/ +theorem Observable.exists_eigenbasis (A : Observable S) {n : ℕ} + (hn : Module.finrank ℂ S.space = n) : + ∃ (b : OrthonormalBasis (Fin n) ℂ S.space) (lam : Fin n → ℝ), + ∀ i, A.op (b i) = (lam i : ℂ) • b i := by + have hsym := A.isSymmetric + exact ⟨hsym.eigenvectorBasis hn, hsym.eigenvalues hn, fun i ↦ hsym.apply_eigenvectorBasis hn i⟩ + +/-- **The two state tracks agree on pure states.** The density-operator expectation +`Tr(|ψ⟩⟨ψ| A)` equals the pure-state expectation `⟪ψ, A ψ⟫`. This is the bridge +that makes the `State`/`PureState` descriptions of a system coherent. -/ +theorem expectation_toState (ψ : PureState S) (A : Observable S) : + ψ.toState.expectation A = ψ.expectation A := by + simp only [State.expectation, PureState.expectation, PureState.toState_op, + InnerProductSpace.trace_rankOne_self_comp] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/PartialTrace.lean b/LeanPool/AxQM/Postulates/PartialTrace.lean new file mode 100644 index 0000000000..680cfa5ebd --- /dev/null +++ b/LeanPool/AxQM/Postulates/PartialTrace.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.QSystem +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.ReducedState + +/-! +# AxQM — reduced states (partial trace) + +The **reduced state** (marginal) of a bipartite state of a composite system `S ⊗ T`, +obtained by tracing out one factor (Nielsen–Chuang §2.4.3): + +* `State.reducedLeft ρ : State S` — the marginal on the left system `S`, + `ρ_A = Tr_T(ρ_{AB})`. +* `State.reducedRight ρ : State T` — the marginal on the right system `T`. + +The partial trace (`LinearMap.partialTraceLeft`/`partialTraceRight`) is +parametrized by an orthonormal basis on the traced-out factor, but is +basis-independent (`partialTraceLeft_eq_of_basis`). We canonicalize on +`stdOrthonormalBasis`, giving the definitions a basis-free signature; the +density-operator property transfers via `IsDensityOp.of_partialTrace{Left,Right}_eq`. + +The op is ascribed to the explicit underlying tensor `S.space ⊗[ℂ] T.space` so the +partial-trace API unifies through the composite coercion `↑(S ⊗ T)`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- The **reduced state on the left system**: `ρ_A = Tr_T(ρ_{AB})`, tracing out +the right factor. -/ +def State.reducedLeft (ρ : State (S ⊗ T)) : State S where + op := (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ T.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space)).toContinuousLinearMap + isDensity := + ρ.isDensity.of_partialTraceRight_eq (stdOrthonormalBasis ℂ T.space) + (by rw [LinearMap.coe_toContinuousLinearMap]) + +/-- The **reduced state on the right system**: `ρ_B = Tr_S(ρ_{AB})`, tracing out +the left factor. -/ +def State.reducedRight (ρ : State (S ⊗ T)) : State T where + op := (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ S.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space)).toContinuousLinearMap + isDensity := + ρ.isDensity.of_partialTraceLeft_eq (stdOrthonormalBasis ℂ S.space) + (by rw [LinearMap.coe_toContinuousLinearMap]) + +@[simp] +theorem State.reducedLeft_op (ρ : State (S ⊗ T)) : + ρ.reducedLeft.op = (LinearMap.partialTraceRight (stdOrthonormalBasis ℂ T.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space)).toContinuousLinearMap := + rfl + +@[simp] +theorem State.reducedRight_op (ρ : State (S ⊗ T)) : + ρ.reducedRight.op = (LinearMap.partialTraceLeft (stdOrthonormalBasis ℂ S.space) + (ρ.op.toLinearMap : S.space ⊗[ℂ] T.space →ₗ[ℂ] S.space ⊗[ℂ] T.space)).toContinuousLinearMap := + rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/PartialTraceTensor.lean b/LeanPool/AxQM/Postulates/PartialTraceTensor.lean new file mode 100644 index 0000000000..bb0598308b --- /dev/null +++ b/LeanPool/AxQM/Postulates/PartialTraceTensor.lean @@ -0,0 +1,50 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PartialTrace +public import LeanPool.AxQM.Postulates.Composite + +/-! +# AxQM — reduced states of a product state + +The marginals of a product state `ρ ⊗ σ` are its factors: `Tr_B(ρ ⊗ σ) = ρ` and +`Tr_A(ρ ⊗ σ) = σ`. The grounded API bridging `State.tmul` (P6) and the partial-trace +generators, via `partialTrace (A ⊗ B) = (tr A) • B` together with `tr = 1` for states. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {S T : QSystem} + +/-- **The right marginal of a product state is its right factor**: `Tr_A(ρ ⊗ σ) = σ`. -/ +theorem State.reducedRight_tmul (ρ : State S) (σ : State T) : + (ρ ⊗ σ).reducedRight = σ := by + ext1 + rw [State.reducedRight_op, State.tmul_op, TensorProduct.toLinearMap_mapL, + LinearMap.partialTraceLeft_tensorMap, ρ.trace_op_eq_one, one_smul] + apply ContinuousLinearMap.coe_injective + rw [LinearMap.coe_toContinuousLinearMap] + +/-- **The left marginal of a product state is its left factor**: `Tr_B(ρ ⊗ σ) = ρ`. -/ +theorem State.reducedLeft_tmul (ρ : State S) (σ : State T) : + (ρ ⊗ σ).reducedLeft = ρ := by + ext1 + rw [State.reducedLeft_op, State.tmul_op, TensorProduct.toLinearMap_mapL, + LinearMap.partialTraceRight_tensorMap, σ.trace_op_eq_one, one_smul] + apply ContinuousLinearMap.coe_injective + rw [LinearMap.coe_toContinuousLinearMap] + +end AxQM diff --git a/LeanPool/AxQM/Postulates/PiTensor.lean b/LeanPool/AxQM/Postulates/PiTensor.lean new file mode 100644 index 0000000000..9c69cc8dca --- /dev/null +++ b/LeanPool/AxQM/Postulates/PiTensor.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct +public import LeanPool.AxQM.Postulates.QSystem +public import LeanPool.AxQM.Postulates.SystemIso + +/-! +# AxQM.Postulates — indexed composite systems (`⨂ₛ i, S i`) + +Postulate 6 states that systems *compose* by the tensor product of their state spaces. +`QSystem.compose` (`S ⊗ T`, in `QSystem.lean`) is the binary form. This file introduces the +**indexed** form `QSystem.piTensor` (`⨂ₛ i, S i`), the composite of a whole finite family of +systems over the n-ary `PiTensorProduct`. + +The binary `S ⊗ T` is recovered as the two-factor case (up to a system isomorphism +`S ⊗ T ≃ₛ ⨂ₛ i : Fin 2, ![S, T] i`), not the other way around. The many-body constructions +(`⨂ₛ i : Fin n, S i`) then read directly off the index, with no associator/reindex bookkeeping +needed to state them. + +Like `QSystem.compose`, this builds the composite system from the Hilbert space +`⨂[ℂ] i, (S i).space`. The per-factor `NormedAddCommGroup`/`InnerProductSpace ℂ`/ +`FiniteDimensional ℂ` instances flow from each `S i`'s bundled instances, so the n-ary +inner-product-space structure (`ToMathlib.Analysis.InnerProductSpace.PiTensorProduct`) fires +automatically; finite-dimensionality comes from the tensor-product basis +(`Basis.piTensorProduct`). + +## Main definitions + +* `QSystem.piTensor` (`⨂ₛ i, S i`) — the indexed composite system of a finite family + `S : ι → QSystem`: the system whose state space is the n-ary tensor product `⨂[ℂ] i, (S i).space`. +* `QSystem.binaryPiEquiv` — the binary ↔ indexed bridge: the system isomorphism + `S ⊗ T ≃ₛ ⨂ₛ i : Fin 2, ![S, T] i`, exhibiting the binary `compose` as the two-factor + special case of the indexed `⨂ₛ`. +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace AxQM + +/-- **Indexed composite system** (Postulate 6, n-ary form): a finite family of systems +`S : ι → QSystem` composes to a system whose state space is the n-ary tensor product +`⨂[ℂ] i, (S i).space`. The binary `S ⊗ T` is the two-factor case. The physical content is the +*choice* of the tensor product; the mathematics (including finite-dimensionality, via the +tensor-product basis) is that of `PiTensorProduct`. -/ +noncomputable def QSystem.piTensor {ι : Type*} [Fintype ι] (S : ι → QSystem) : QSystem where + space := ⨂[ℂ] i, (S i).space + findim := Module.Basis.finiteDimensional_of_finite + (Basis.piTensorProduct fun i ↦ Module.finBasis ℂ (S i).space) + +@[inherit_doc QSystem.piTensor] +scoped notation3:100 "⨂ₛ "(...)", "r:67:(scoped f => QSystem.piTensor f) => r + +/-- The state space of an indexed composite is the n-ary tensor product of the factors' state +spaces — `QSystem.space` unfolds by definition. -/ +@[simp] theorem QSystem.piTensor_space {ι : Type*} [Fintype ι] (S : ι → QSystem) : + (⨂ₛ i, S i).space = ⨂[ℂ] i, (S i).space := rfl + +/-! ## Binary ↔ indexed bridge + +The binary composite `S ⊗ T` is the two-factor case of the indexed `⨂ₛ`: there is a system +isomorphism `S ⊗ T ≃ₛ ⨂ₛ i : Fin 2, ![S, T] i` (`QSystem.binaryPiEquiv`), so the binary +`compose` is *recovered* from `piTensor`, not the other way around. -/ + +/-- The two-factor family `Fin 1 ⊕ Fin 1 → QSystem` splitting `S` on the left and `T` on the +right. Its re-indexing along `finSumFinEquiv : Fin 1 ⊕ Fin 1 ≃ Fin 2` is `![S, T]` +(`QSystem.binaryFamily_finSumFinEquiv`), the shape that lets the head-split isometries +(`tmulEquivDepₗᵢ` / `subsingletonEquivₗᵢ` / `reindexₗᵢ`) assemble the bridge. -/ +def QSystem.binaryFamily (S T : QSystem) : Fin 1 ⊕ Fin 1 → QSystem := + Sum.elim (fun _ ↦ S) (fun _ ↦ T) + +/-- Re-indexing the two-factor `Sum` family along `finSumFinEquiv` recovers `![S, T]`. Checked +at the two concrete `Fin 2` indices (`finSumFinEquiv.symm 0 = .inl 0`, `.symm 1 = .inr 0`). -/ +theorem QSystem.binaryFamily_finSumFinEquiv (S T : QSystem) : + (fun i : Fin 2 ↦ binaryFamily S T (finSumFinEquiv.symm i)) = ![S, T] := by + funext i; fin_cases i <;> rfl + +/-- The isometry underlying `QSystem.binaryPiEquiv`: +`S.space ⊗[ℂ] T.space ≃ₗᵢ[ℂ] ⨂[ℂ] i : Fin 2, (![S, T] i).space`, splitting the index type +`Fin 2` as `Fin 1 ⊕ Fin 1`. `PiTensorProduct.tmulEquivDepₗᵢ` bridges the binary tensor of the +two single-factor tensor powers to the `Sum`-indexed tensor power, the `Fin 1` powers collapse +via `PiTensorProduct.subsingletonEquivₗᵢ`, and `PiTensorProduct.reindexₗᵢ` along `finSumFinEquiv` +recovers the `Fin 2` index (`binaryFamily_finSumFinEquiv`). -/ +noncomputable def QSystem.binaryPiIsometry (S T : QSystem) : + S.space ⊗[ℂ] T.space ≃ₗᵢ[ℂ] ⨂[ℂ] i : Fin 2, (![S, T] i).space := by + rw [← binaryFamily_finSumFinEquiv S T] + have split := PiTensorProduct.tmulEquivDepₗᵢ ℂ (fun i ↦ (binaryFamily S T i).space) + have collapse := TensorProduct.congrIsometry + (PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun i ↦ (binaryFamily S T (.inl i)).space) 0).symm + (PiTensorProduct.subsingletonEquivₗᵢ ℂ (fun i ↦ (binaryFamily S T (.inr i)).space) 0).symm + exact collapse.trans + (split.trans (PiTensorProduct.reindexₗᵢ ℂ (fun i ↦ (binaryFamily S T i).space) finSumFinEquiv)) + +/-- **Binary composition is the two-factor indexed tensor**: +the system isomorphism `S ⊗ T ≃ₛ ⨂ₛ i : Fin 2, ![S, T] i`, exhibiting binary `⊗` as the special +case of the indexed `⨂ₛ`. The underlying isometry is `QSystem.binaryPiIsometry`. -/ +noncomputable def QSystem.binaryPiEquiv (S T : QSystem) : (S ⊗ T) ≃ₛ QSystem.piTensor ![S, T] := + ⟨QSystem.binaryPiIsometry S T⟩ + +/-! ## The `n`-fold tensor power `S ^⊗ₛ n` -/ + +/-- **`n`-fold tensor power** of a system: `S ^⊗ₛ n = ⨂ₛ (_ : Fin n), S`, the composite of +`n` copies of `S`. The constant-family case of the indexed +composite `⨂ₛ` — `n` registers of the same system. -/ +noncomputable def QSystem.tensorPow (S : QSystem) (n : ℕ) : QSystem := ⨂ₛ _ : Fin n, S + +-- The subscript `ₛ` (system) is deliberate: bare `^⊗` is a global Mathlib notation for +-- `LinearMap.tensorPow` (`TensorPower/Endomorphism`, in this file's import closure). As a +-- `scoped` 3-glyph token, `^⊗ₛ` wins longest-match over `^⊗` wherever `AxQM` is +-- open/scoped (every intended use site); outside that scope it would fall back to `^⊗`. +@[inherit_doc QSystem.tensorPow] scoped infixr:75 " ^⊗ₛ " => QSystem.tensorPow + +/-- `S ^⊗ₛ n` is the indexed composite of the constant family `fun _ : Fin n ↦ S` — the +system-level unfold lemma (use in place of `unfold QSystem.tensorPow`). -/ +theorem QSystem.tensorPow_eq (S : QSystem) (n : ℕ) : + S ^⊗ₛ n = QSystem.piTensor (fun _ : Fin n ↦ S) := rfl + +/-- The state space of `S ^⊗ₛ n` is the `n`-ary tensor power of `S.space` — `QSystem.space` +unfolds by definition. -/ +@[simp] theorem QSystem.tensorPow_space (S : QSystem) (n : ℕ) : + (S ^⊗ₛ n).space = ⨂[ℂ] _ : Fin n, S.space := rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/PiTensorState.lean b/LeanPool/AxQM/Postulates/PiTensorState.lean new file mode 100644 index 0000000000..e1768c75e8 --- /dev/null +++ b/LeanPool/AxQM/Postulates/PiTensorState.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.PiTensor +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.Postulates.SystemIso +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductDensity + +/-! +# AxQM.Postulates — indexed product states (`⨂ₚ i, ψ i`) + +The state-level companion of the indexed composite system `⨂ₛ i, S i` +(`QSystem.piTensor`, `PiTensor.lean`). Given a finite family of *pure* states +`ψ : ∀ i, PureState (S i)`, their **indexed product state** `⨂ₚ i, ψ i` is the pure +state of `⨂ₛ i, S i` whose underlying vector is the n-ary elementary tensor +`⨂ₜ[ℂ] i, (ψ i).vec` — the n-ary form of the binary product pure state `ψ ⊗ φ` +(`PureState.tmul`, `Composite.lean`). + +Alongside it, `QSystem.piTensorReindex` re-indexes an indexed composite along an +index equivalence `e : ι ≃ κ` (a system isomorphism `⨂ₛ i, S i ≃ₛ ⨂ₛ j, S (e.symm j)`, +built on `PiTensorProduct.reindexₗᵢ`), and `PureState.piTensor_congr_piTensorReindex` +records its naturality: transporting a product state along the reindex is the product +state of the reindexed family. + +Normalization is proved on the explicit underlying space via the multiplicativity of the tensor +inner product (`PiTensorProduct.inner_tprod_tprod`) and closed into the bundled goal by defeq. + +## Main definitions + +* `PureState.piTensor` (`⨂ₚ i, ψ i`) — the indexed product pure state of a finite family + `ψ : ∀ i, PureState (S i)`, on `⨂ₛ i, S i`. +* `State.piTensor` (`⨂ₚ i, ρ i`) — the indexed product (mixed) state of a finite family + `ρ : ∀ i, State (S i)`, on `⨂ₛ i, S i`. +* `QSystem.piTensorReindex` — the reindexing system isomorphism + `⨂ₛ i, S i ≃ₛ ⨂ₛ j, S (e.symm j)` along `e : ι ≃ κ`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +noncomputable section + +namespace AxQM + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] {S : ι → QSystem} + +/-- **Indexed product pure state** `⨂ₚ i, ψ i`: the product of a finite family of pure +states `ψ : ∀ i, PureState (S i)`, on the indexed composite `⨂ₛ i, S i`. The n-ary form of +the binary product pure state `ψ ⊗ φ` (`PureState.tmul`). The underlying vector is the n-ary +elementary tensor `⨂ₜ[ℂ] i, (ψ i).vec`; it is a unit vector because the tensor inner product +is multiplicative (`PiTensorProduct.inner_tprod_tprod`). -/ +def PureState.piTensor (ψ : ∀ i, PureState (S i)) : PureState (⨂ₛ i, S i) where + vec := ⨂ₜ[ℂ] i, (ψ i).vec + normalized := by + have h : (inner ℂ (⨂ₜ[ℂ] i, (ψ i).vec) (⨂ₜ[ℂ] i, (ψ i).vec) : ℂ) = 1 := by + rw [PiTensorProduct.inner_tprod_tprod] + exact Finset.prod_eq_one fun i _ ↦ by + rw [inner_self_eq_norm_sq_to_K, (ψ i).normalized]; norm_num + have h2 : ‖(⨂ₜ[ℂ] i, (ψ i).vec)‖ ^ 2 = 1 := by + rw [← inner_self_eq_norm_sq (𝕜 := ℂ), h]; simp + calc ‖(⨂ₜ[ℂ] i, (ψ i).vec)‖ + = Real.sqrt (‖(⨂ₜ[ℂ] i, (ψ i).vec)‖ ^ 2) := (Real.sqrt_sq (norm_nonneg _)).symm + _ = 1 := by rw [h2, Real.sqrt_one] + +@[inherit_doc PureState.piTensor] +scoped notation3:100 "⨂ₚ "(...)", "r:67:(scoped f => PureState.piTensor f) => r + +@[simp] +theorem PureState.piTensor_vec (ψ : ∀ i, PureState (S i)) : + (⨂ₚ i, ψ i).vec = ⨂ₜ[ℂ] i, (ψ i).vec := rfl + +/-- **Indexed product (mixed) state** `⨂ₚ i, ρ i`: the product of a finite family of states +`ρ : ∀ i, State (S i)`, on the indexed composite `⨂ₛ i, S i`. The n-ary form of the binary +product state `ρ ⊗ σ` (`State.tmul`); a genuine `State` because the n-ary tensor of density +operators is a density operator (`PiTensorProduct.mapCLM_isDensityOp`). -/ +def State.piTensor (ρ : ∀ i, State (S i)) : State (⨂ₛ i, S i) where + op := PiTensorProduct.mapCLM fun i ↦ (ρ i).op + isDensity := PiTensorProduct.mapCLM_isDensityOp fun i ↦ (ρ i).isDensity + +@[inherit_doc State.piTensor] +scoped notation3:100 "⨂ₚ "(...)", "r:67:(scoped f => State.piTensor f) => r + +@[simp] +theorem State.piTensor_op (ρ : ∀ i, State (S i)) : + (⨂ₚ i, ρ i).op = PiTensorProduct.mapCLM fun i ↦ (ρ i).op := rfl + +/-! ## Reindexing an indexed composite -/ + +/-- **Reindexing an indexed composite** along an index equivalence `e : ι ≃ κ`: the system +isomorphism `⨂ₛ i, S i ≃ₛ ⨂ₛ j, S (e.symm j)`, built on the reindex isometry +`PiTensorProduct.reindexₗᵢ`. -/ +def QSystem.piTensorReindex (e : ι ≃ κ) (S : ι → QSystem) : + (⨂ₛ i, S i) ≃ₛ ⨂ₛ j, S (e.symm j) := + ⟨PiTensorProduct.reindexₗᵢ ℂ (fun i ↦ (S i).space) e⟩ + +@[simp] +theorem QSystem.piTensorReindex_toIsometry (e : ι ≃ κ) (S : ι → QSystem) : + (QSystem.piTensorReindex e S).toIsometry + = PiTensorProduct.reindexₗᵢ ℂ (fun i ↦ (S i).space) e := rfl + +/-- **Naturality of the product state under reindexing**: transporting `⨂ₚ i, ψ i` along +`QSystem.piTensorReindex e` is the product state of the reindexed family `fun j ↦ ψ (e.symm j)`. -/ +@[simp] +theorem PureState.piTensor_congr_piTensorReindex (e : ι ≃ κ) (ψ : ∀ i, PureState (S i)) : + (⨂ₚ i, ψ i).congr (QSystem.piTensorReindex e S) = ⨂ₚ j, ψ (e.symm j) := by + apply PureState.ext + rw [PureState.congr_vec, PureState.piTensor_vec, PureState.piTensor_vec] + exact PiTensorProduct.reindexₗᵢ_tprod e (fun i ↦ (ψ i).vec) + +/-- **Naturality of the product (mixed) state under reindexing**: transporting `⨂ₚ i, ρ i` +along `QSystem.piTensorReindex e` is the product state of the reindexed family +`fun j ↦ ρ (e.symm j)`. The `State` companion of `PureState.piTensor_congr_piTensorReindex`, +riding `PiTensorProduct.reindexₗᵢ_mapCLM`. -/ +@[simp] +theorem State.piTensor_congr_piTensorReindex (e : ι ≃ κ) (ρ : ∀ i, State (S i)) : + (⨂ₚ i, ρ i).congr (QSystem.piTensorReindex e S) = ⨂ₚ j, ρ (e.symm j) := by + apply State.ext + rw [State.congr_op, State.piTensor_op, State.piTensor_op, QSystem.piTensorReindex_toIsometry] + ext y + -- `(⨂ₛ i, S i).space` vs the plain `⨂[ℂ] i, (S i).space` diverge under `rw`'s syntactic + -- matching even though defeq; `erw` bridges it. + erw [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply] + -- term-mode `.trans`: a syntactic `rw`/`simp [reindexₗᵢ_mapCLM]` won't fire — the reindex + -- family `(S i).space` and `mapCLM`'s codomain `↥(S i)` (from `(ρ i).op`) are defeq but not + -- syntactically equal, so only the defeq-checking `exact`/`congrArg` route matches. + exact (PiTensorProduct.reindexₗᵢ_mapCLM e (fun i ↦ (ρ i).op) _).trans + (congrArg _ (LinearIsometryEquiv.apply_symm_apply _ y)) + +end AxQM diff --git a/LeanPool/AxQM/Postulates/QSystem.lean b/LeanPool/AxQM/Postulates/QSystem.lean new file mode 100644 index 0000000000..ed1482e58b --- /dev/null +++ b/LeanPool/AxQM/Postulates/QSystem.lean @@ -0,0 +1,90 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# AxQM.Postulates — quantum systems (Postulate 1) + +A **quantum system** is the physical object whose mathematical realization is a +finite-dimensional complex Hilbert space. This file introduces `QSystem`, the +*name* for that object, so that signatures can read `State S` / `S ⊗ T` rather than the raw +`EuclideanSpace`/`TensorProduct` mathematics. + +The underlying Hilbert space is `S.space`. + +States, observables, measurements and evolutions (`State`/`PureState`/`Observable`/ +`Measurement`/`Evolution`) are parameterized over `QSystem`, with `S` coercing to its space +`S.space`. `QSystem` bundles the standing assumptions +(finite-dimensional complex Hilbert space), so `CompleteSpace` and finite-dimensionality +derive everywhere and the per-section instance juggling is gone. The *concrete* systems +(`qubit`, `qudit d`, …) are defined in `AxQM/Postulates/API/` via `QSystem.ofModel`. + +## Main definitions + +* `QSystem` — a quantum system: a bundled finite-dimensional complex Hilbert space. +* `QSystem.compose` (`S ⊗ T`) — the composite system (Postulate 6): systems compose by + the tensor product of their state spaces. +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace AxQM + +/-- A **quantum system** (Postulate 1): the physical object whose +mathematical realization is a finite-dimensional complex Hilbert space `space`. Bundling the +instances lets typeclass resolution flow through `S.space` automatically. -/ +structure QSystem where + /-- The underlying Hilbert space. -/ + space : Type* + [norm : NormedAddCommGroup space] + [inner : InnerProductSpace ℂ space] + [findim : FiniteDimensional ℂ space] + +attribute [instance] QSystem.norm QSystem.inner QSystem.findim + +instance (S : QSystem) : CompleteSpace S.space := + FiniteDimensional.completeSpace ℂ S.space + +/-- A system **coerces to its state space**: `↑S` is `S.space`, so `S : QSystem` stands +in wherever a type/vector/operator is expected (`x : S`, `op : S →L[ℂ] S`). This is the +Mathlib bundled idiom (`Grp`/`ModuleCat`/`TopCat`): there is one fundamental definition, +`QSystem`, and the system/state-space distinction disappears at the surface. The coercion +unfolds to `QSystem.space`. -/ +instance : CoeSort QSystem (Type _) := ⟨QSystem.space⟩ + +/-- The **dimension** of a quantum system: the (finite) dimension of its state space. The +dimension `finrank ℂ S.space`, which lets statements such as `Real.log S.dim` name the +dimension without mentioning `.space`. -/ +noncomputable def QSystem.dim (S : QSystem) : ℕ := Module.finrank ℂ S.space + +/-- **Composite system** (Postulate 6; Nielsen–Chuang Postulate 4 / §2.2.8): two systems +compose to a system whose state space is the tensor product of the components'. The +physical content is the *choice* of the tensor product (over, say, a direct sum). -/ +noncomputable def QSystem.compose (S T : QSystem) : QSystem := + { space := S.space ⊗[ℂ] T.space } + +@[inherit_doc] scoped infixr:70 " ⊗ " => QSystem.compose + +/-- **A quantum system from a model Hilbert space**: wrap a finite-dimensional complex +Hilbert space `H` as the system whose state space is `H`. The general model-space +constructor — constructions that produce an *anonymous* system (e.g. the ancilla of a +purification, N&C §2.5) use `ofModel`. The concrete +named systems (`qubit`, …) are defined via `ofModel` of their standard model spaces. -/ +def QSystem.ofModel (H : Type*) [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [FiniteDimensional ℂ H] : QSystem := { space := H } + +@[simp] +theorem QSystem.ofModel_space (H : Type*) [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [FiniteDimensional ℂ H] : (QSystem.ofModel H).space = H := rfl + +end AxQM diff --git a/LeanPool/AxQM/Postulates/StateSpace.lean b/LeanPool/AxQM/Postulates/StateSpace.lean new file mode 100644 index 0000000000..1c123faa0c --- /dev/null +++ b/LeanPool/AxQM/Postulates/StateSpace.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.QSystem +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! +# AxQM — Postulate 1: state space and states + +The *state* of a quantum system. States are **bundled structures**, not +predicates on raw operators: a quantity defined for states takes a `State` +or `PureState`, so its definition is grounded in the postulate by its very type. + +States are indexed by a `QSystem` `S`; `S` coerces to its state space `S.space`, so the +state space appears as `S` (`op : S →L[ℂ] S`, `vec : S`). + +There are two descriptions, neither primary. +* `AxQM.State S` — a **density operator** (positive, trace one): the + general (possibly mixed) state. +* `AxQM.PureState S` — a **unit vector**: a pure state. +* `PureState.toState` — the rank-one projector `|ψ⟩⟨ψ|` relating the two. + +The underlying operator and vector are `State.op` and `PureState.vec`. Because `QSystem` +bundles a finite-dimensional complex +Hilbert space, completeness and finite-dimensionality derive automatically — no +per-section instance bookkeeping. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace AxQM + +/-- **Postulate 1 (state).** A quantum **state** of the system `S` is a density +operator: a positive operator of trace one. Subsumes pure and mixed states alike. +Built on `ContinuousLinearMap.IsDensityOp` from `ToMathlib`. -/ +@[ext] +structure State (S : QSystem) where + /-- The underlying density operator. -/ + op : S →L[ℂ] S + /-- The operator is a density operator: positive with trace one. -/ + isDensity : op.IsDensityOp + +/-- **Postulate 1 (pure state).** A **pure state** of the system `S` is a unit +vector, determined up to a global phase. -/ +@[ext] +structure PureState (S : QSystem) where + /-- The underlying unit vector. -/ + vec : S + /-- The vector is normalized: `‖vec‖ = 1`. -/ + normalized : ‖vec‖ = 1 + +variable {S : QSystem} + +namespace State + +/-- A state has trace one. -/ +theorem trace_op_eq_one (ρ : State S) : + LinearMap.trace ℂ S (ρ.op : S →ₗ[ℂ] S) = 1 := + ρ.isDensity.trace_eq_one + +/-- A state's operator is positive. -/ +theorem isPositive_op (ρ : State S) : ρ.op.IsPositive := ρ.isDensity.isPositive + +/-- **A state's operator is nonzero**: its trace is `1 ≠ 0`. -/ +theorem op_ne_zero (ρ : State S) : (ρ.op : S →ₗ[ℂ] S) ≠ 0 := fun h ↦ by + have := ρ.trace_op_eq_one + rw [h, map_zero] at this + exact one_ne_zero this.symm + +/-- **A state forces a nontrivial space**: the existence of a `State S` implies +`Nontrivial S.space`. A state's operator has trace `1 ≠ 0`, but on a subsingleton space +every operator is `0` (hence trace `0`). Lets bounds whose Mathlib lever needs +`[Nontrivial]` discharge the hypothesis from the state itself rather than assuming it. -/ +theorem nontrivial_space (ρ : State S) : Nontrivial S.space := + not_subsingleton_iff_nontrivial.mp fun _ ↦ + absurd ρ.trace_op_eq_one (by simp [Subsingleton.elim (ρ.op : S →ₗ[ℂ] S) 0]) + +end State + +namespace PureState + +/-- The state `|ψ⟩⟨ψ|` of a pure state `ψ` — the rank-one projector. This +relates pure states to density operators. -/ +def toState (ψ : PureState S) : State S where + op := InnerProductSpace.rankOne ℂ ψ.vec ψ.vec + isDensity := ContinuousLinearMap.isDensityOp_rankOne_self ψ.normalized + +@[simp] +theorem toState_op (ψ : PureState S) : + ψ.toState.op = InnerProductSpace.rankOne ℂ ψ.vec ψ.vec := rfl + +/-- A pure state coerces to its density-operator state `|ψ⟩⟨ψ|` — the ergonomic +direction of the relation between pure states and density operators. -/ +instance : Coe (PureState S) (State S) := ⟨toState⟩ + +end PureState + +end AxQM diff --git a/LeanPool/AxQM/Postulates/SystemIso.lean b/LeanPool/AxQM/Postulates/SystemIso.lean new file mode 100644 index 0000000000..192b726866 --- /dev/null +++ b/LeanPool/AxQM/Postulates/SystemIso.lean @@ -0,0 +1,170 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.Postulates.QSystem +public import LeanPool.AxQM.Postulates.StateSpace +public import LeanPool.AxQM.Postulates.Observable +public import LeanPool.AxQM.Postulates.Measurement +public import LeanPool.AxQM.Postulates.Evolution + +/-! +# AxQM — system isomorphisms (`S ≃ₛ T`) + +A **system isomorphism** `S ≃ₛ T` is an inner-product isometry of the state spaces, +`S.space ≃ₗᵢ[ℂ] T.space`. Every structural conversion (associator, swap, reindex, +flat↔structured, …) of tensor spaces is a `QSystem.Iso`, and **transport** of states, pure +states, observables, evolutions and measurements +(`State`/`PureState`/`Observable`/`Evolution`/`Measurement`) is proved once here, so each +named conversion inherits it. + +Transport uses the Mathlib construction `LinearIsometryEquiv.conjStarAlgEquiv` +(the ⋆-algebra equivalence `(S.space →L S.space) ≃⋆ₐ (T.space →L T.space)` induced by the +isometry): density / self-adjoint / unitary / completeness are preserved because it is a +unital ⋆-algebra equivalence. **Invariance** of quantities such as entropy, +expectation and fidelity under transport follows from the matching +`*_conjStarAlgEquiv` lemmas. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +namespace AxQM + +/-- A **system isomorphism**: an inner-product isometry between the state spaces of two +systems. It transports states, observables, evolutions and measurements between systems +regarded as the same up to reorganization. -/ +structure QSystem.Iso (S T : QSystem) where + /-- The underlying isometry of state spaces. -/ + toIsometry : S.space ≃ₗᵢ[ℂ] T.space + +@[inherit_doc] scoped infix:25 " ≃ₛ " => QSystem.Iso + +namespace QSystem.Iso + +variable {S T U : QSystem} + +instance : CoeFun (S ≃ₛ T) (fun _ ↦ S.space → T.space) := ⟨fun e ↦ e.toIsometry⟩ + +/-- The identity system isomorphism. -/ +def refl (S : QSystem) : S ≃ₛ S := ⟨LinearIsometryEquiv.refl ℂ S.space⟩ + +/-- The inverse system isomorphism. -/ +def symm (e : S ≃ₛ T) : T ≃ₛ S := ⟨e.toIsometry.symm⟩ + +/-- Composition of system isomorphisms. -/ +def trans (e : S ≃ₛ T) (f : T ≃ₛ U) : S ≃ₛ U := ⟨e.toIsometry.trans f.toIsometry⟩ + +end QSystem.Iso + +variable {S T : QSystem} + +/-- **Transport a state** along a system isomorphism: `ρ ↦ e ρ e⁻¹`. A genuine `State`, +since `conjStarAlgEquiv` preserves the density-operator property. -/ +def State.congr (e : S ≃ₛ T) (ρ : State S) : State T where + op := e.toIsometry.conjStarAlgEquiv ρ.op + isDensity := e.toIsometry.conjStarAlgEquiv_isDensityOp_iff.mpr ρ.isDensity + +@[simp] +theorem State.congr_op (e : S ≃ₛ T) (ρ : State S) : + (ρ.congr e).op = e.toIsometry.conjStarAlgEquiv ρ.op := rfl + +/-- **Transport a pure state** along a system isomorphism: `ψ ↦ e ψ`. Norm-preserving. -/ +def PureState.congr (e : S ≃ₛ T) (ψ : PureState S) : PureState T where + vec := e.toIsometry ψ.vec + normalized := by rw [LinearIsometryEquiv.norm_map, ψ.normalized] + +@[simp] +theorem PureState.congr_vec (e : S ≃ₛ T) (ψ : PureState S) : + (ψ.congr e).vec = e.toIsometry ψ.vec := rfl + +/-- **Transport an observable** along a system isomorphism. Self-adjointness is preserved +by `conjStarAlgEquiv`. -/ +def Observable.congr (e : S ≃ₛ T) (A : Observable S) : Observable T where + op := e.toIsometry.conjStarAlgEquiv A.op + selfAdjoint := e.toIsometry.conjStarAlgEquiv_isSelfAdjoint_iff.mpr A.selfAdjoint + +@[simp] +theorem Observable.congr_op (e : S ≃ₛ T) (A : Observable S) : + (A.congr e).op = e.toIsometry.conjStarAlgEquiv A.op := rfl + +-- `StarHomClass` for `≃⋆ₐ` now resolves through a low-priority generic instance; the default +-- heartbeat budget is too small to find it here. +/-- **Transport an evolution** along a system isomorphism. Unitarity is preserved because +`conjStarAlgEquiv` is a unital ⋆-algebra equivalence (`star`/`*`/`1` preserved). -/ +def Evolution.congr (e : S ≃ₛ T) (U : Evolution S) : Evolution T where + op := e.toIsometry.conjStarAlgEquiv U.op + unitary := by + have hU := Unitary.mem_iff.mp U.unitary + rw [Unitary.mem_iff] + refine ⟨?_, ?_⟩ + · rw [← map_star, ← map_mul, hU.1, map_one] + · rw [← map_star, ← map_mul, hU.2, map_one] + +@[simp] +theorem Evolution.congr_op (e : S ≃ₛ T) (U : Evolution S) : + (U.congr e).op = e.toIsometry.conjStarAlgEquiv U.op := rfl + +-- `StarHomClass` for `≃⋆ₐ` now resolves through a low-priority generic instance; the default +-- heartbeat budget is too small to find it here. +/-- **Transport a measurement** along a system isomorphism. Completeness `∑ Mᵢ† Mᵢ = 1` +is preserved because `conjStarAlgEquiv` is an additive unital ⋆-algebra equivalence. -/ +def Measurement.congr {ι : Type*} [Fintype ι] (e : S ≃ₛ T) (m : Measurement ι S) : + Measurement ι T where + op i := e.toIsometry.conjStarAlgEquiv (m.op i) + complete := by + have step : ∀ i, (adjoint (e.toIsometry.conjStarAlgEquiv (m.op i))).comp + (e.toIsometry.conjStarAlgEquiv (m.op i)) + = e.toIsometry.conjStarAlgEquiv ((adjoint (m.op i)).comp (m.op i)) := by + intro i + have hstar : adjoint (e.toIsometry.conjStarAlgEquiv (m.op i)) + = e.toIsometry.conjStarAlgEquiv (adjoint (m.op i)) := by + rw [← ContinuousLinearMap.star_eq_adjoint, ← map_star, + ContinuousLinearMap.star_eq_adjoint] + rw [hstar, ← ContinuousLinearMap.mul_def, ← map_mul, ContinuousLinearMap.mul_def] + simp_rw [step] + rw [← map_sum, m.complete, map_one] + +@[simp] +theorem Measurement.congr_op {ι : Type*} [Fintype ι] (e : S ≃ₛ T) (m : Measurement ι S) + (i : ι) : (m.congr e).op i = e.toIsometry.conjStarAlgEquiv (m.op i) := rfl + +/-! ## Coherence and invariance under transport + +The map from pure states to density operators commutes with transport, and expectation +values are invariant, by the matching `*_conjStarAlgEquiv` lemmas. -/ + +/-- Transport commutes with passing from a pure state to its density operator: +`|e ψ⟩⟨e ψ| = e |ψ⟩⟨ψ| e⁻¹`. -/ +@[simp] +theorem PureState.congr_toState (e : S ≃ₛ T) (ψ : PureState S) : + (ψ.congr e).toState = ψ.toState.congr e := by + apply State.ext + simp only [PureState.toState_op, State.congr_op, PureState.congr_vec, + InnerProductSpace.rankOne_conjStarAlgEquiv] + +/-- **Expectation is invariant under transport** (density operators): a system isomorphism does +not change `Tr(ρ A)`. Via `trace_conjStarAlgEquiv` and multiplicativity of the conjugation. -/ +theorem State.expectation_congr (e : S ≃ₛ T) (ρ : State S) (A : Observable S) : + (ρ.congr e).expectation (A.congr e) = ρ.expectation A := by + simp only [State.expectation, State.congr_op, Observable.congr_op, + ← ContinuousLinearMap.mul_def, ← map_mul, ContinuousLinearMap.trace_conjStarAlgEquiv] + +/-- **Expectation is invariant under transport** (pure states): reduces to the density +operator case via `|ψ⟩⟨ψ|`. -/ +theorem PureState.expectation_congr (e : S ≃ₛ T) (ψ : PureState S) (A : Observable S) : + (ψ.congr e).expectation (A.congr e) = ψ.expectation A := by + rw [← expectation_toState, PureState.congr_toState, State.expectation_congr] + exact expectation_toState ψ A + +end AxQM diff --git a/LeanPool/AxQM/ToMathlib/Algebra/BigOperators/Fin.lean b/LeanPool/AxQM/ToMathlib/Algebra/BigOperators/Fin.lean new file mode 100644 index 0000000000..b9580beea8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Algebra/BigOperators/Fin.lean @@ -0,0 +1,59 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Algebra.BigOperators.Fin + +/-! +# Additional `Fin`-indexed big-operator lemmas + +A Euclidean-decomposition reindexing lemma for products/sums over `range (m * r)`, and a +`Finset.univ`-splitting lemma for `Fin (a + b)`. +-/ + +public section + +open Finset + +variable {ι M : Type*} + +namespace Finset + +/-- Reindex a product over `range (m * r)` by the Euclidean decomposition `x = j + r * i` with +`i < m` and `j < r`. -/ +@[to_additive sum_range_mul_reindex /-- Reindex a sum over `range (m * r)` by the Euclidean +decomposition `x = j + r * i` with `i < m` and `j < r`. -/] +theorem prod_range_mul_reindex [CommMonoid M] (m r : ℕ) (g : ℕ → M) : + ∏ x ∈ Finset.range (m * r), g x = + ∏ i ∈ Finset.range m, ∏ j ∈ Finset.range r, g (j + r * i) := by + rw [← Fin.prod_univ_eq_prod_range g (m * r), + ← finProdFinEquiv.prod_comp (fun x : Fin (m * r) => g ↑x), + Fintype.prod_prod_type, + ← Fin.prod_univ_eq_prod_range (fun i => ∏ j ∈ Finset.range r, g (j + r * i)) m] + refine Finset.prod_congr rfl (fun i _ => ?_) + rw [← Fin.prod_univ_eq_prod_range (fun j => g (j + r * i.val)) r] + rfl + +end Finset + +namespace Fin + +/-- Multiset analogue of `Fin.sum_univ_add`: the underlying multiset of +`Finset.univ : Finset (Fin (a + b))` splits as the union of `Finset.univ`'s on `Fin a`/`Fin b` +under the `Fin.castAdd`/`Fin.natAdd` embeddings. -/ +theorem univ_val_add (a b : ℕ) : + (Finset.univ : Finset (Fin (a + b))).val = + (Finset.univ : Finset (Fin a)).val.map (castAdd b) + + (Finset.univ : Finset (Fin b)).val.map (natAdd a) := by + rw [← Multiset.map_univ_val_equiv finSumFinEquiv, ← Finset.univ_disjSum_univ, + Finset.val_disjSum, Multiset.disjSum, + Multiset.map_add, Multiset.map_map, Multiset.map_map] + simp [finSumFinEquiv] + +end Fin diff --git a/LeanPool/AxQM/ToMathlib/Algebra/Group/Subgroup/InvolutionClosure.lean b/LeanPool/AxQM/ToMathlib/Algebra/Group/Subgroup/InvolutionClosure.lean new file mode 100644 index 0000000000..18ee3f4e1f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Algebra/Group/Subgroup/InvolutionClosure.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic +public import Mathlib.Algebra.Group.Subgroup.Lattice +public import Mathlib.Data.ZMod.Basic + +/-! +# Subset-product normal form for a closure of commuting involutions + +In a commutative group `M`, the subgroup generated by a finite family of pairwise-commuting +involutions `f : Fin l → M` (each `f i ^ 2 = 1`) is an elementary abelian `2`-group: every element +is a *subset product* `∏ i, f i ^ (c i).val` indexed by a vector `c : Fin l → ZMod 2` (each +generator used `0` or `1` times, since `(c i).val ∈ {0, 1}`). + +This is the involution-specialised, `ZMod 2`-exponent form of `Subgroup.exists_of_mem_closure_range` +(`∃ a : ι → ℤ, x = ∏ i, f i ^ a i`, with general `ℤ` exponents). It is proved directly by +`Subgroup.closure_induction`: reducing the `ℤ`-exponent form to the parity `ZMod 2` form would +require an `orderOf`-mod reduction on `ℤ`-powers that is heavier than the direct induction, and the +`ZMod 2` exponents let the statement feed `ZMod 2`-linear-independence arguments directly (as in +stabilizer-formalism check-matrix computations). +-/ + +open scoped BigOperators + +public section + +/-- For an involution `x` (`x ^ 2 = 1`), the exponent may be reduced modulo `2`: reading +`a b : ZMod 2` as exponents in `{0, 1}` via `ZMod.val`, `x ^ (a.val + b.val) = x ^ (a + b).val`. +This is the fact making `c ↦ ∏ i, f i ^ (c i).val` respect `ZMod 2`-addition. -/ +theorem pow_zmod2_val_add {M : Type*} [Monoid M] {x : M} (hx : x ^ 2 = 1) (a b : ZMod 2) : + x ^ (a.val + b.val) = x ^ (a + b).val := by + conv_lhs => rw [← Nat.div_add_mod (a.val + b.val) 2] + rw [pow_add, pow_mul, hx, one_pow, one_mul, ZMod.val_add] + +namespace Subgroup + +/-- **Normal form for a closure of pairwise-commuting involutions.** In a commutative group `M`, if +each generator `f i` squares to `1`, then every element of `closure (Set.range f)` is a subset +product `∏ i, f i ^ (c i).val` of the generators, indexed by `c : Fin l → ZMod 2` (each generator +used `0` or `1` times). This is the involution-specialised form of +`Subgroup.exists_of_mem_closure_range` (which gives general `ℤ` exponents). The three closure cases +combine `c`-vectors by `𝔽₂`-addition (`pow_zmod2_val_add`); inverses reuse the same `c` because each +such product is itself an involution. -/ +theorem exists_zmod2_prod_of_mem_closure {M : Type*} [CommGroup M] {l : ℕ} + (f : Fin l → M) (hf : ∀ i, f i ^ 2 = 1) {x : M} + (hx : x ∈ closure (Set.range f)) : + ∃ c : Fin l → ZMod 2, x = ∏ i, f i ^ (c i).val := by + induction hx using closure_induction with + | mem x hx => + obtain ⟨j, rfl⟩ := hx + refine ⟨fun i => if i = j then 1 else 0, ?_⟩ + rw [Finset.prod_eq_single j (fun i _ hij => by simp [ite_eq_right hij]) + (fun h => absurd (Finset.mem_univ j) h)] + simp [ZMod.val_one] + | one => exact ⟨0, by simp⟩ + | mul x y _ _ hx hy => + obtain ⟨cx, rfl⟩ := hx + obtain ⟨cy, rfl⟩ := hy + refine ⟨cx + cy, ?_⟩ + rw [← Finset.prod_mul_distrib] + exact Finset.prod_congr rfl fun i _ => by + rw [← pow_add]; exact pow_zmod2_val_add (hf i) (cx i) (cy i) + | inv x _ hx => + obtain ⟨c, rfl⟩ := hx + refine ⟨c, ?_⟩ + have hsq : (∏ i, f i ^ (c i).val) ^ 2 = 1 := by + rw [← Finset.prod_pow] + exact Finset.prod_eq_one fun i _ => by + rw [← pow_mul, mul_comm, pow_mul, hf i, one_pow] + exact inv_eq_of_mul_eq_one_right (by rw [← pow_two]; exact hsq) + +end Subgroup diff --git a/LeanPool/AxQM/ToMathlib/Algebra/Ring/Equiv.lean b/LeanPool/AxQM/ToMathlib/Algebra/Ring/Equiv.lean new file mode 100644 index 0000000000..d23073d1c9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Algebra/Ring/Equiv.lean @@ -0,0 +1,43 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Algebra.Ring.Equiv +public import Mathlib.Algebra.Group.Units.Hom +public import Mathlib.Algebra.GroupWithZero.Units.Basic + +/-! +# Ring isomorphisms preserve `Ring.inverse` + +A ring isomorphism preserves `Ring.inverse`. +-/ + +@[expose] public section + +namespace RingEquiv + +variable {R S : Type*} [Semiring R] [Semiring S] + +section GroupPower + +/-- A ring isomorphism preserves `Ring.inverse`. -/ +protected theorem map_ringInverse (f : R ≃+* S) (x : R) : + f (Ring.inverse x) = Ring.inverse (f x) := by + by_cases h : IsUnit x + · refine (h.map (f : R →* S)).mul_right_cancel ?_ + change f (Ring.inverse x) * f x = Ring.inverse (f x) * f x + rw [← map_mul, Ring.inverse_mul_cancel x h, map_one, eq_comm, + Ring.inverse_mul_cancel (f x) (h.map (f : R →* S))] + · rw [Ring.inverse_non_unit _ h, + Ring.inverse_non_unit _ (fun hu ↦ h (f.symm_apply_apply x ▸ hu.map f.symm.toRingHom)), + map_zero] + +end GroupPower + +end RingEquiv diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ApproximateUnit.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ApproximateUnit.lean new file mode 100644 index 0000000000..14d1f1dc71 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ApproximateUnit.lean @@ -0,0 +1,78 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.ApproximateUnit +import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.RingInverseOrder + +/-! +# Concavity of `x ↦ 1 - (1 + x)⁻¹` under the continuous functional calculus + ++ `CFC.cfc_one_sub_one_add_inv_eq`: in a unital C⋆-algebra, + `cfc (1 - (1 + ·)⁻¹) c = 1 - Ring.inverse (1 + c)` for `0 ≤ c`. ++ `CFC.concaveOn_cfc_one_sub_one_add_inv`: `cfc (1 - (1 + ·)⁻¹)` is operator concave on the + nonnegative cone of a unital C⋆-algebra. ++ `CFC.concaveOn_one_sub_one_add_inv`, `CFC.concaveOn_one_sub_one_add_inv_real`: the + (possibly non-unital) `cfcₙ` versions. +-/ + +@[expose] public section + +variable {A : Type*} [NonUnitalCStarAlgebra A] + +open Unitization NNReal CStarAlgebra ComplexOrder + +variable [PartialOrder A] [StarOrderedRing A] + +section UnitalOneSubOneAddInv + +variable {B : Type*} [CStarAlgebra B] [PartialOrder B] [StarOrderedRing B] + +/-- In a unital C⋆-algebra, `cfc (1 - (1 + ·)⁻¹) c = 1 - Ring.inverse (1 + c)` for `0 ≤ c`. -/ +lemma CFC.cfc_one_sub_one_add_inv_eq (c : B) (hc : 0 ≤ c := by cfc_tac) : + cfc (fun x : ℝ≥0 ↦ 1 - (1 + x)⁻¹) c = 1 - Ring.inverse (1 + c) := by + have : IsStrictlyPositive (1 + c : B) := isStrictlyPositive_one.add_nonneg hc + rw [cfc_tsub _ _ _ (fun x _ ↦ by simp) (hg := by fun_prop (disch := intro _ _; positivity)), + cfc_const_one ℝ≥0 c, cfc_comp' (·⁻¹) (1 + ·) c ?_, cfc_add .., cfc_const_one ℝ≥0 c, + cfc_id' ℝ≥0 c, ← CFC.rpow_neg_one_eq_cfc_inv, ← inverse_eq_rpow_neg_one] + exact continuousOn_id.inv₀ (Set.forall_mem_image.mpr fun x _ ↦ by dsimp only [id]; positivity) + +/-- In a unital C⋆-algebra, `cfc (1 - (1 + ·)⁻¹)` is operator concave on the nonnegative cone. -/ +lemma CFC.concaveOn_cfc_one_sub_one_add_inv : + ConcaveOn ℝ (Set.Ici (0 : B)) (cfc (fun x : ℝ≥0 ↦ 1 - (1 + x)⁻¹)) := by + refine ⟨convex_Ici 0, fun a (ha : 0 ≤ a) b (hb : 0 ≤ b) α β hα hβ hαβ ↦ ?_⟩ + have hab : (0 : B) ≤ α • a + β • b := add_nonneg (smul_nonneg hα ha) (smul_nonneg hβ hb) + rw [cfc_one_sub_one_add_inv_eq a ha, cfc_one_sub_one_add_inv_eq b hb, + cfc_one_sub_one_add_inv_eq _ hab, smul_sub, smul_sub, sub_add_sub_comm, + show α • (1 : B) + β • 1 = 1 by rw [← add_smul, hαβ, one_smul], sub_le_sub_iff_left] + exact convexOn_ringInverse_one_add.2 ha hb hα hβ hαβ + +end UnitalOneSubOneAddInv + +/-- The function `x ↦ 1 - (1 + x)⁻¹` is operator concave on `Set.Ici (0 : A)`. -/ +lemma CFC.concaveOn_one_sub_one_add_inv : + ConcaveOn ℝ (Set.Ici (0 : A)) (cfcₙ (fun x : ℝ≥0 ↦ 1 - (1 + x)⁻¹)) := by + refine ⟨convex_Ici 0, fun a ha b hb α β hα hβ hαβ ↦ ?_⟩ + simp only [Set.mem_Ici] at ha hb + -- Lift the inequality to A⁺¹ via inr and use the unital helper. + rw [← inr_le_inr_iff] + simp only [Unitization.inr_add, Unitization.inr_smul] + rw [nnreal_cfcₙ_eq_cfc_inr a _, nnreal_cfcₙ_eq_cfc_inr b _, + nnreal_cfcₙ_eq_cfc_inr (α • a + β • b) _, Unitization.inr_add, + Unitization.inr_smul, Unitization.inr_smul] + rw [← inr_nonneg_iff] at ha hb + exact CFC.concaveOn_cfc_one_sub_one_add_inv.2 ha hb hα hβ hαβ + +/-- The function `x ↦ 1 - (1 + x)⁻¹` (real version) is operator concave on `Set.Ici (0 : A)`. -/ +lemma CFC.concaveOn_one_sub_one_add_inv_real : + ConcaveOn ℝ (Set.Ici (0 : A)) (cfcₙ (fun x : ℝ ↦ 1 - (1 + x)⁻¹)) := by + refine CFC.concaveOn_one_sub_one_add_inv.congr fun a (ha : 0 ≤ a) ↦ ?_ + rw [cfcₙ_nnreal_eq_real _ _ ha] + refine cfcₙ_congr fun x hx ↦ ?_ + simp [show 0 ≤ x by grind] diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Integral.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Integral.lean new file mode 100644 index 0000000000..bbfd7ddcc4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Integral.lean @@ -0,0 +1,54 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Integral + +/-! +# A joint integrability/commutation lemma for the non-unital continuous functional calculus + +Combines `integrableOn_cfcₙ` and `cfcₙ_setIntegral` into a single lemma, the typical +consumer pattern when establishing operator-valued integral representations. +-/ + +@[expose] public section + +open MeasureTheory Topology +open scoped ContinuousMapZero + +section nonunital + +open ContinuousMapZero + +variable {X : Type*} {𝕜 : Type*} {A : Type*} {p : A → Prop} [RCLike 𝕜] + [MeasurableSpace X] {μ : Measure X} [NonUnitalNormedRing A] [StarRing A] + [NormedSpace 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A] + [NonUnitalContinuousFunctionalCalculus 𝕜 A p] + [CompleteSpace A] + +open Function Set in +/-- Joint version of `integrableOn_cfcₙ` and `cfcₙ_setIntegral`: under the same hypotheses, +both the integrability of `fun x ↦ cfcₙ (f x) a` over `s` and the identity +`cfcₙ (fun r ↦ ∫ x in s, f x r ∂μ) a = ∫ x in s, cfcₙ (f x) a ∂μ` hold. This is the typical +consumer pattern when establishing operator-valued integral representations: callers want +both conclusions from a single setup. -/ +lemma integrableOn_and_cfcₙ_setIntegral [NormedSpace ℝ A] + [TopologicalSpace X] [OpensMeasurableSpace X] {s : Set X} + (hs : MeasurableSet s) (f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A) + [SecondCountableTopologyEither X C(quasispectrum 𝕜 a, 𝕜)] + (hf : ContinuousOn (uncurry f) (s ×ˢ quasispectrum 𝕜 a)) + (f_zero : ∀ᵐ x ∂(μ.restrict s), f x 0 = 0) + (bound_ge : ∀ᵐ x ∂(μ.restrict s), ∀ z ∈ quasispectrum 𝕜 a, ‖f x z‖ ≤ bound x) + (bound_int : HasFiniteIntegral bound (μ.restrict s)) (ha : p a := by cfc_tac) : + IntegrableOn (fun x ↦ cfcₙ (f x) a) s μ ∧ + cfcₙ (fun r ↦ ∫ x in s, f x r ∂μ) a = ∫ x in s, cfcₙ (f x) a ∂μ := + ⟨integrableOn_cfcₙ hs f bound a hf f_zero bound_ge bound_int, + cfcₙ_setIntegral hs f bound a hf f_zero bound_ge bound_int⟩ + +end nonunital diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Order.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Order.lean new file mode 100644 index 0000000000..7650546b46 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Order.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order + +/-! +# Extra CFC order lemmas + +Extends `Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order` with: + +* `cfc_mul_self_eq_self_of_mul_self_eqOn_id`, `cfc_real_sqrt_mul_self_of_nonneg`, + `cfc_real_sqrt_nonneg`: unital-CFC square-root facts. +* `IsStrictlyPositive.sum`, `isStrictlyPositive_add_smul_one`, `perturbedSeq` and its API: + building blocks for regularizing positive elements to strictly positive ones. +* `convex_isStrictlyPositive`: the set of strictly positive elements of a unital C⋆-algebra + is convex. +-/ + +public section + +section CStar_unital + +variable {A : Type*} [CStarAlgebra A] + +namespace CStarAlgebra + +variable [PartialOrder A] [StarOrderedRing A] + +omit [PartialOrder A] [StarOrderedRing A] in +/-- **CFC `f * f = id` composition identity**: if `f` satisfies `f x * f x = x` on +`spectrum ℝ a`, then `cfc f a * cfc f a = a`. The general form behind +`cfc_real_sqrt_mul_self_of_nonneg` (`f := Real.sqrt`) and similar identities such as +`f := · ⁻¹` on units, `f := -·` (where `(-x) * (-x) = x` requires `x = 0`), etc. -/ +theorem _root_.cfc_mul_self_eq_self_of_mul_self_eqOn_id {f : ℝ → ℝ} {a : A} + (hf : (spectrum ℝ a).EqOn (fun x ↦ f x * f x) id) + (hcont : ContinuousOn f (spectrum ℝ a) := by cfc_cont_tac) + (ha : IsSelfAdjoint a := by cfc_tac) : + cfc f a * cfc f a = a := by + rw [← cfc_mul _ _ a] + conv_rhs => rw [← cfc_id ℝ a] + exact cfc_congr hf + +/-- **Unital-CFC sibling of `CFC.sqrt_mul_sqrt_self`**: for a positive element `a` in a +unital C*-algebra, `cfc Real.sqrt a * cfc Real.sqrt a = a`. Whereas `CFC.sqrt` is built from +the non-unital `cfcₙ NNReal.sqrt`, this lemma uses the unital `cfc Real.sqrt` form, which is +the natural spelling whenever the consumer already has `0 ≤ a` and wants to stay in the +unital-CFC API. 1-line specialization of `cfc_mul_self_eq_self_of_mul_self_eqOn_id` to +`f := Real.sqrt` via `Real.mul_self_sqrt` on the nonneg spectrum. -/ +theorem _root_.cfc_real_sqrt_mul_self_of_nonneg {a : A} (ha : 0 ≤ a := by cfc_tac) : + cfc Real.sqrt a * cfc Real.sqrt a = a := + cfc_mul_self_eq_self_of_mul_self_eqOn_id fun x hx ↦ + Real.mul_self_sqrt (spectrum_nonneg_of_nonneg ha hx) + +/-- **CFC sqrt is always non-negative**: `0 ≤ cfc Real.sqrt a` for any `a`. Holds +unconditionally because `Real.sqrt _ ≥ 0` on all of ℝ (junk values for negative inputs are +also non-negative), and `cfc f a` inherits this pointwise property via `cfc_nonneg`. -/ +theorem _root_.cfc_real_sqrt_nonneg (a : A) : 0 ≤ cfc Real.sqrt a := + cfc_nonneg fun x _ ↦ Real.sqrt_nonneg x + +end CStarAlgebra + +section Inv + +variable [PartialOrder A] [StarOrderedRing A] + +namespace CStarAlgebra + +/-- **A sum of strictly positive elements over a nonempty `Finset` is strictly positive.** Peels +off one summand (strictly positive) and adds the nonnegative remainder via +`IsStrictlyPositive.add_nonneg`; the finite iterate of "strictly positive `+` nonnegative is +strictly positive". -/ +theorem _root_.IsStrictlyPositive.sum {ι : Type*} {f : ι → A} {t : Finset ι} (ht : t.Nonempty) + (hf : ∀ i ∈ t, IsStrictlyPositive (f i)) : IsStrictlyPositive (∑ i ∈ t, f i) := by + induction ht using Finset.Nonempty.cons_induction with + | singleton a => simpa using hf a (Finset.mem_singleton_self a) + | cons a v _ _ _ => + rw [Finset.sum_cons] + exact (hf a (Finset.mem_cons_self a v)).add_nonneg + (Finset.sum_nonneg fun i hi => (hf i (Finset.mem_cons_of_mem hi)).nonneg) + +/-- For `0 ≤ a` in a C*-algebra and `0 < c` in the scalar field, `a + c • 1` is strictly +positive. Composes `IsStrictlyPositive.nonneg_add` with `isStrictlyPositive_algebraMap` via +`Algebra.algebraMap_eq_smul_one`. The canonical "regularization" step for extending +strict-positivity-conditional results to general positive elements. -/ +theorem _root_.isStrictlyPositive_add_smul_one {𝕜 : Type*} [Semifield 𝕜] [PartialOrder 𝕜] + [Algebra 𝕜 A] [PosSMulMono 𝕜 A] {a : A} (ha : 0 ≤ a) {c : 𝕜} (hc : 0 < c) : + IsStrictlyPositive (a + c • 1) := by + refine IsStrictlyPositive.nonneg_add ha ?_ + rw [← Algebra.algebraMap_eq_smul_one] + exact isStrictlyPositive_algebraMap hc + +/-- The set of strictly positive elements of a unital C⋆-algebra is convex. -/ +@[grind ←] +lemma _root_.convex_isStrictlyPositive : + Convex ℝ {a : A | IsStrictlyPositive a} := by + grind [convex_iff_forall_pos] + +omit [PartialOrder A] [StarOrderedRing A] in +/-- **Perturbation sequence** `n ↦ a + (1/(n+1)) • 1`. Strictly positive when `0 ≤ a` +(`perturbedSeq_isStrictlyPositive`); converges to `a` as `n → ∞` (`tendsto_perturbedSeq`). +The canonical regularization for extending strict-positivity-conditional results to +general positive elements via compactness / continuity arguments. -/ +@[expose] noncomputable def _root_.perturbedSeq (a : A) (n : ℕ) : A := + a + (1 / ((n : ℝ) + 1)) • 1 + +omit [PartialOrder A] [StarOrderedRing A] in +@[simp] +theorem _root_.perturbedSeq_apply (a : A) (n : ℕ) : + perturbedSeq a n = a + (1 / ((n : ℝ) + 1)) • 1 := rfl + +/-- For `0 ≤ a`, every term in the perturbation sequence is strictly positive. -/ +theorem _root_.perturbedSeq_isStrictlyPositive {a : A} (ha : 0 ≤ a) (n : ℕ) : + IsStrictlyPositive (perturbedSeq a n) := + isStrictlyPositive_add_smul_one ha (by positivity) + +omit [PartialOrder A] [StarOrderedRing A] in +open Filter Topology in +/-- The perturbation sequence converges to `a` (via `1/(n+1) → 0`). -/ +theorem _root_.tendsto_perturbedSeq (a : A) : + Tendsto (perturbedSeq a) atTop (𝓝 a) := by + apply Tendsto.congr (fun n ↦ (perturbedSeq_apply a n).symm) + simpa using (tendsto_const_nhds (x := a) (f := atTop)).add + ((tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)).smul + (tendsto_const_nhds (x := (1 : A)) (f := atTop))) + +end CStarAlgebra + +end Inv + +end CStar_unital diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousLinearMap.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousLinearMap.lean new file mode 100644 index 0000000000..debc5f3f2c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ContinuousLinearMap.lean @@ -0,0 +1,36 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Basic +public import Mathlib.Analysis.CStarAlgebra.ContinuousLinearMap + +/-! +# Global continuous functional calculus instance for `E →L[ℂ] E` + +This file promotes the generic `IsStarNormal.instContinuousFunctionalCalculus` theorem (made +`local instance` only in `Mathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Basic.lean`, +presumably to avoid synthesis cost on arbitrary C⋆-algebras) to a global instance specifically +for `E →L[ℂ] E`. The `IsSelfAdjoint`-over-ℝ continuous functional calculus then fires +automatically via `IsSelfAdjoint.instIsometricContinuousFunctionalCalculus` and the generic +`IsSelfAdjoint.instContinuousFunctionalCalculus` chain. This makes `cfc f T` usable on +`T : E →L[ℂ] E` for `f : ℂ → ℂ` (under `IsStarNormal T`) and for `f : ℝ → ℝ` (under +`IsSelfAdjoint T`) directly, without manually invoking the local-instance attribute. +-/ + +@[expose] public section + +/-- The continuous functional calculus for star-normal continuous linear operators on a complex +Hilbert space. This is a global-instance promotion of the generic +`IsStarNormal.instContinuousFunctionalCalculus` theorem, specialized to the operator algebra +`E →L[ℂ] E`. -/ +instance ContinuousLinearMap.instContinuousFunctionalCalculus_isStarNormal + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] : + ContinuousFunctionalCalculus ℂ (E →L[ℂ] E) IsStarNormal := + IsStarNormal.instContinuousFunctionalCalculus diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Matrix.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Matrix.lean new file mode 100644 index 0000000000..c78bdb48d4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Matrix.lean @@ -0,0 +1,37 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.Matrix + +/-! +# `Matrix.toEuclideanCLM` intertwines conjugate transpose with the operator adjoint +-/ + +@[expose] public section + +open scoped Matrix + +namespace Matrix + +variable {𝕜 n : Type*} [RCLike 𝕜] +variable [Fintype n] [DecidableEq n] + +/-- `Matrix.toEuclideanCLM` intertwines conjugate transpose with the operator adjoint: +`toEuclideanCLM Aᴴ = (toEuclideanCLM A)†`. The continuous-linear-map (`⋆`-algebra-equivalence) +analogue of `Matrix.toEuclideanLin_conjTranspose_eq_adjoint`, using that `toEuclideanCLM` is a +`⋆`-isomorphism (`map_star`), the star on operators is the adjoint +(`ContinuousLinearMap.star_eq_adjoint`), and `star A = Aᴴ` on matrices +(`Matrix.star_eq_conjTranspose`). -/ +lemma toEuclideanCLM_conjTranspose_eq_adjoint (A : Matrix n n 𝕜) : + toEuclideanCLM (n := n) (𝕜 := 𝕜) Aᴴ + = ContinuousLinearMap.adjoint (toEuclideanCLM (n := n) (𝕜 := 𝕜) A) := by + rw [← ContinuousLinearMap.star_eq_adjoint, ← map_star, Matrix.star_eq_conjTranspose] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/MatrixToEuclideanCLM.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/MatrixToEuclideanCLM.lean new file mode 100644 index 0000000000..b34ef53c4d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/MatrixToEuclideanCLM.lean @@ -0,0 +1,79 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import TauCeti.Analysis.Matrix.EuclideanLin + +/-! +# Positivity, trace, and continuity of `Matrix.toEuclideanCLM` + +`Matrix.toEuclideanCLM` is the `⋆`-algebra equivalence sending a square matrix `A : Matrix n n 𝕜` +to the continuous linear endomorphism of `EuclideanSpace 𝕜 n` it represents in the standard +orthonormal basis. This file records several of its properties: + +* `Matrix.isPositive_toEuclideanCLM_iff` — `Matrix.toEuclideanCLM A` is a positive operator iff `A` + is positive semidefinite (the continuous-linear-map counterpart of the existing + `Matrix.isPositive_toEuclideanLin_iff`); +* `Matrix.trace_toEuclideanCLM` — the operator trace of `Matrix.toEuclideanCLM A` equals the matrix + trace `A.trace`. +* `Matrix.toEuclideanCLM_vecMulVec` — `Matrix.toEuclideanCLM (vecMulVec x (star y))` is the rank-one + operator `|x⟩⟨y|` (`InnerProductSpace.rankOne`); the continuous-linear-map counterpart of the + `Matrix.toEuclideanLin` identity `InnerProductSpace.symm_toEuclideanLin_rankOne`. +* `Matrix.continuous_toEuclideanCLM` — `Matrix.toEuclideanCLM` is continuous (as a map from + `Matrix n n 𝕜` with the product topology to the operators with the operator-norm topology). + +The first three (positivity, trace, outer product) are immediate from the coercion +`Matrix.coe_toEuclideanCLM_eq_toEuclideanLin` to `Matrix.toEuclideanLin`, together with the +corresponding facts for `toEuclideanLin` (`Matrix.isPositive_toEuclideanLin_iff` for positivity; +`Matrix.toEuclideanLin_eq_toLin_orthonormal` and `Matrix.trace_toLin_eq` for the trace; +`InnerProductSpace.symm_toEuclideanLin_rankOne` for the outer product). Continuity holds because a +`𝕜`-linear map out of a finite-dimensional space over a complete field is continuous +(`LinearMap.continuous_of_finiteDimensional`). +-/ + +open scoped InnerProductSpace ComplexOrder + +@[expose] public section + +namespace Matrix + +variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] [DecidableEq n] + +/-- **`Matrix.toEuclideanCLM A` is positive iff `A` is positive semidefinite.** The +continuous-linear-map counterpart of `Matrix.isPositive_toEuclideanLin_iff`: positivity of the +operator `A` represents on `EuclideanSpace 𝕜 n` is exactly positive semidefiniteness of `A`. -/ +theorem isPositive_toEuclideanCLM_iff (A : Matrix n n 𝕜) : + (Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := n) A).IsPositive ↔ A.PosSemidef := by + rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, coe_toEuclideanCLM_eq_toEuclideanLin, + isPositive_toEuclideanLin_iff] + +/-- **The operator trace of `Matrix.toEuclideanCLM A` is the matrix trace `A.trace`.** The operator +`Matrix.toEuclideanCLM A` is `A` in the standard orthonormal basis, so its +basis-independent trace agrees with `A.trace`. -/ +theorem trace_toEuclideanCLM (A : Matrix n n 𝕜) : + LinearMap.trace 𝕜 (EuclideanSpace 𝕜 n) ↑(Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := n) A) + = A.trace := by + rw [coe_toEuclideanCLM_eq_toEuclideanLin, toEuclideanLin_eq_toLin_orthonormal, trace_toLin_eq] + +/-- **`Matrix.toEuclideanCLM` of an outer product is the rank-one operator.** +`Matrix.toEuclideanCLM (vecMulVec x (star y)) = |x⟩⟨y|` (`InnerProductSpace.rankOne 𝕜 x y`), for +`x y : EuclideanSpace 𝕜 n`. The continuous-linear-map counterpart of the `Matrix.toEuclideanLin` +identity `InnerProductSpace.symm_toEuclideanLin_rankOne` +(`toEuclideanLin.symm (rankOne 𝕜 x y) = vecMulVec x (star y)`), transported across the coercion +`Matrix.coe_toEuclideanCLM_eq_toEuclideanLin`. -/ +theorem toEuclideanCLM_vecMulVec (x y : EuclideanSpace 𝕜 n) : + Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := n) (Matrix.vecMulVec x.ofLp (star y.ofLp)) + = InnerProductSpace.rankOne 𝕜 x y := by + apply ContinuousLinearMap.coe_injective + rw [coe_toEuclideanCLM_eq_toEuclideanLin, ← InnerProductSpace.symm_toEuclideanLin_rankOne, + LinearEquiv.apply_symm_apply] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ToEuclideanCLMSingle.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ToEuclideanCLMSingle.lean new file mode 100644 index 0000000000..469a665443 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/ToEuclideanCLMSingle.lean @@ -0,0 +1,42 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix + +/-! +# Action of `Matrix.toEuclideanCLM` on a standard basis vector + +`Matrix.toEuclideanCLM M` is the continuous linear operator on `EuclideanSpace 𝕜 n` corresponding to +a square matrix `M` (via the `⋆`-algebra isomorphism `Matrix.toEuclideanCLM`). This file records the +elementary fact that it sends the standard basis vector `|j⟩ = EuclideanSpace.single j 1` to the +`j`-th **column** of `M`, expressed as the superposition `∑ₖ Mₖⱼ |k⟩`. + +## Main statements + +* `Matrix.toEuclideanCLM_apply_single` : `toEuclideanCLM M |j⟩ = ∑ₖ Mₖⱼ |k⟩`. +-/ + +@[expose] public section + +namespace Matrix + +variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] [DecidableEq n] + +/-- **Action of `Matrix.toEuclideanCLM` on a standard basis vector:** the operator +`Matrix.toEuclideanCLM M` sends `|j⟩ = EuclideanSpace.single j 1` to the `j`-th column of `M`, +`∑ₖ Mₖⱼ |k⟩`. The `m`-th coordinate of the left side is the matrix-vector product +`(M *ᵥ eⱼ) m = Mₘⱼ` (`Matrix.ofLp_toEuclideanCLM`, `Pi.single_apply`), matching the right side. -/ +theorem toEuclideanCLM_apply_single (M : Matrix n n 𝕜) (j : n) : + Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := n) M (EuclideanSpace.single j (1 : 𝕜)) + = ∑ k : n, (M k j) • EuclideanSpace.single k (1 : 𝕜) := by + ext m + simp [Matrix.ofLp_toEuclideanCLM, Matrix.mulVec, dotProduct, Pi.single_apply] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/Exp.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/Exp.lean new file mode 100644 index 0000000000..dec0420f66 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/Exp.lean @@ -0,0 +1,123 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.CStarAlgebra.Unitary.Connected +public import Mathlib.Analysis.CStarAlgebra.CStarMatrix +public import Mathlib.LinearAlgebra.Eigenspace.Minpoly +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Basic + +/-! +# Every unitary matrix is the exponential of a Hermitian matrix + +For a unitary `u` in a unital C⋆-algebra `A`, Mathlib defines the selfadjoint element +`Unitary.argSelfAdjoint u = cfc arg u` (the "argument" `-i log u`), and proves +`selfAdjoint.expUnitary (argSelfAdjoint u) = u` — i.e. `exp (i • argSelfAdjoint u) = u` — but +**only** when `‖u - 1‖ < 2` (equivalently `-1 ∉ spectrum ℂ u`), which is what keeps `Complex.arg` +continuous on the spectrum (`expUnitary_argSelfAdjoint`). + +The single obstruction to dropping that hypothesis is the *continuity* of `Complex.arg` on +`spectrum ℂ u`. We isolate the general statement +`expUnitary_argSelfAdjoint_of_continuousOn_arg`, whose only hypothesis is that continuity, and +then discharge it unconditionally for **matrices**: a square matrix has a finite spectrum +(`Matrix.finite_spectrum`), and every function is continuous on a finite subset of a `T1Space` +(`Set.Finite.continuousOn`). + +The matrix results are phrased for `CStarMatrix n n ℂ`, i.e. `n × n` complex matrices carrying the +C⋆-algebra (operator) norm — the honest C⋆-algebra of matrices, and the setting in which the +`Unitary.argSelfAdjoint` / `selfAdjoint.expUnitary` machinery lives. Recall `selfAdjoint.expUnitary` +is by definition `x ↦ exp (i • x)` (`selfAdjoint.expUnitary_coe`), and a selfadjoint matrix is +exactly a Hermitian one, so these say precisely: **every unitary matrix `U` can be written as +`exp (i K)` for a Hermitian `K`** (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 2.56; `K = -i log U = argSelfAdjoint U`). + +## Main results + +* `expUnitary_argSelfAdjoint_of_continuousOn_arg`: in any unital C⋆-algebra, if `Complex.arg` is + continuous on `spectrum ℂ u` then `selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u`. This + generalises `expUnitary_argSelfAdjoint` by replacing `‖u - 1‖ < 2` with its sole + consequence used in the proof. +* `CStarMatrix.finite_spectrum`: the spectrum of a square C⋆-matrix over `ℂ` is finite. +* `CStarMatrix.expUnitary_argSelfAdjoint`: for every unitary matrix `u`, + `selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u`, with no restriction on the spectrum. +* `CStarMatrix.expUnitary_surjective`: `selfAdjoint.expUnitary` maps the selfadjoint (Hermitian) + matrices *onto* the unitary matrices. +* `CStarMatrix.exists_expUnitary_eq_of_mem_unitary`: every unitary matrix `U` equals + `selfAdjoint.expUnitary K = exp (i K)` for some Hermitian `K`. +-/ + +@[expose] public section + +open Complex NormedSpace selfAdjoint Unitary +open scoped ComplexOrder + +variable {A : Type*} [CStarAlgebra A] + +/-- **Recovery of a unitary from its argument.** In a unital C⋆-algebra, if the principal argument +`Complex.arg` is continuous on the spectrum of a unitary `u`, then +`selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u`, i.e. `exp (i • (-i log u)) = u`. + +This generalises `expUnitary_argSelfAdjoint`, which assumes `‖u - 1‖ < 2` +(equivalently `-1 ∉ spectrum ℂ u`); that hypothesis is used solely to obtain the continuity +required here. -/ +theorem expUnitary_argSelfAdjoint_of_continuousOn_arg {u : unitary A} + (hu : ContinuousOn Complex.arg (spectrum ℂ (u : A))) : + selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u := by + ext + have : ContinuousOn arg (spectrum ℂ (u : A)) := hu + rw [expUnitary_coe, argSelfAdjoint_coe, ← CFC.exp_eq_normedSpace_exp (𝕜 := ℂ), + ← cfc_comp_smul .., ← cfc_comp' ..] + conv_rhs => rw [← cfc_id' ℂ (u : A)] + refine cfc_congr fun y hy ↦ ?_ + have hy₁ : ‖y‖ = 1 := spectrum.norm_eq_one_of_unitary u.2 hy + have : Complex.I * y.arg = Complex.log y := + Complex.ext (by simp [Complex.log_re, spectrum.norm_eq_one_of_unitary u.2 hy]) + (by simp [Complex.log_im]) + simpa [← exp_eq_exp_ℂ, this] using Complex.exp_log (by aesop) + +variable {n : Type*} [Fintype n] [DecidableEq n] + +/-- The spectrum of a square C⋆-matrix over `ℂ` is finite: it is the finite spectrum of the +underlying `Matrix` (`Matrix.finite_spectrum`), transported along the star-algebra isomorphism +`CStarMatrix.ofMatrixStarAlgEquiv`. -/ +theorem CStarMatrix.finite_spectrum (u : CStarMatrix n n ℂ) : (spectrum ℂ u).Finite := by + have h := Matrix.finite_spectrum (CStarMatrix.ofMatrix.symm u) + have he : CStarMatrix.ofMatrixStarAlgEquiv.toAlgEquiv (CStarMatrix.ofMatrix.symm u) = u := + CStarMatrix.ofMatrix.apply_symm_apply u + rw [← he, AlgEquiv.spectrum_eq] + exact h + +/-- **Every unitary matrix is recovered from its argument.** For any unitary matrix `u`, +`selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u`, i.e. `exp (i • (-i log u)) = u`. + +Unlike the general C⋆-algebra statement `expUnitary_argSelfAdjoint`, no hypothesis on the +spectrum is needed: the spectrum of a matrix is finite, so `Complex.arg` is automatically continuous +on it. -/ +theorem CStarMatrix.expUnitary_argSelfAdjoint (u : unitary (CStarMatrix n n ℂ)) : + selfAdjoint.expUnitary (Unitary.argSelfAdjoint u) = u := + expUnitary_argSelfAdjoint_of_continuousOn_arg <| + (CStarMatrix.finite_spectrum (u : CStarMatrix n n ℂ)).continuousOn _ + +/-- **`exp (i •)` is surjective onto the unitary matrices.** The map `selfAdjoint.expUnitary`, +sending a selfadjoint (Hermitian) matrix `K` to the unitary `exp (i K)`, is surjective; a preimage +of `u` is `Unitary.argSelfAdjoint u = -i log u`. -/ +theorem CStarMatrix.expUnitary_surjective : + Function.Surjective + (selfAdjoint.expUnitary : selfAdjoint (CStarMatrix n n ℂ) → unitary (CStarMatrix n n ℂ)) := + fun u => ⟨Unitary.argSelfAdjoint u, CStarMatrix.expUnitary_argSelfAdjoint u⟩ + +/-- **Nielsen & Chuang, Exercise 2.56.** Every unitary matrix `U` can be written as `exp (i K)` for +some Hermitian matrix `K`. Here `K` ranges over `selfAdjoint (CStarMatrix n n ℂ)` (the Hermitian +matrices) and `selfAdjoint.expUnitary K` is `exp (i • K)` by `selfAdjoint.expUnitary_coe`; a witness +is `K = Unitary.argSelfAdjoint U = -i log U`. -/ +theorem CStarMatrix.exists_expUnitary_eq_of_mem_unitary + {U : CStarMatrix n n ℂ} (hU : U ∈ unitary (CStarMatrix n n ℂ)) : + ∃ K : selfAdjoint (CStarMatrix n n ℂ), (selfAdjoint.expUnitary K : CStarMatrix n n ℂ) = U := + ⟨Unitary.argSelfAdjoint ⟨U, hU⟩, + congrArg Subtype.val (CStarMatrix.expUnitary_argSelfAdjoint ⟨U, hU⟩)⟩ diff --git a/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/ExpEndomorphism.lean b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/ExpEndomorphism.lean new file mode 100644 index 0000000000..3e389a99a4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/CStarAlgebra/Unitary/ExpEndomorphism.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Unitary.Exp +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousLinearMap +public import Mathlib.Analysis.CStarAlgebra.Exponential +public import Mathlib.Analysis.Normed.Algebra.Exponential +public import Mathlib.Analysis.Normed.Operator.Banach +public import Mathlib.LinearAlgebra.Eigenspace.Minpoly + +/-! +# Every unitary endomorphism of a finite-dimensional Hilbert space is `exp (i • A)` + +`CStarMatrix.exists_expUnitary_eq_of_mem_unitary` (Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Exercise 2.56) states that every unitary `n × n` matrix is `exp (i K)` for a +Hermitian matrix `K`. This file gives the coordinate-free counterpart, for continuous linear +endomorphisms of a finite-dimensional complex Hilbert space: + +* `ContinuousLinearMap.exists_isSelfAdjoint_exp_smul_I_eq_of_mem_unitary` — for a + finite-dimensional complex inner product space `E`, every unitary `U : E →L[ℂ] E` equals + `exp (i • A)` for some self-adjoint `A : E →L[ℂ] E`. + +## Proof outline + +`E →L[ℂ] E` is itself a C⋆-algebra, so the general +`expUnitary_argSelfAdjoint_of_continuousOn_arg` applies: its only hypothesis is that +`Complex.arg` is continuous on `spectrum ℂ U`. That continuity is automatic here because the +spectrum is *finite* — the spectrum of `U` as a continuous linear map coincides with that of the +underlying linear map (`ContinuousLinearMap.spectrum_eq`), which is finite in finite dimensions +(`Module.End.finite_spectrum`). The witness is then `A = Unitary.argSelfAdjoint U` (`= -i log U`), +self-adjoint by construction. Unlike the general `expUnitary_argSelfAdjoint`, no `‖U - 1‖ < 2` +restriction is needed — finiteness of the spectrum supplies the continuity in full. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder + +namespace ContinuousLinearMap + +/-- **Every unitary endomorphism of a finite-dimensional complex Hilbert space is the exponential +of `i` times a self-adjoint operator.** The coordinate-free form of Nielsen & Chuang Exercise 2.56 +(`CStarMatrix.exists_expUnitary_eq_of_mem_unitary`): for a unitary `U : E →L[ℂ] E` there is a +self-adjoint `A : E →L[ℂ] E` with `exp (i • A) = U`. Physically, `A` is a Hamiltonian generating +the unitary `U` (up to sign, `A = -i log U`). + +The witness is `A = Unitary.argSelfAdjoint U`; the recovery `exp (i • A) = U` holds because a +finite-dimensional operator has finite spectrum, on which the principal argument is continuous +(`expUnitary_argSelfAdjoint_of_continuousOn_arg`). -/ +theorem exists_isSelfAdjoint_exp_smul_I_eq_of_mem_unitary + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {U : E →L[ℂ] E} (hU : U ∈ unitary (E →L[ℂ] E)) : + ∃ A : E →L[ℂ] E, IsSelfAdjoint A ∧ NormedSpace.exp (Complex.I • A) = U := by + let u : unitary (E →L[ℂ] E) := ⟨U, hU⟩ + -- A finite-dimensional operator has finite spectrum (that of its underlying linear map), so the + -- principal-argument function is continuous on it. + have hfin : (spectrum ℂ (u : E →L[ℂ] E)).Finite := by + rw [ContinuousLinearMap.spectrum_eq] + exact Module.End.finite_spectrum _ + -- The self-adjoint `A = -i log U` (`Unitary.argSelfAdjoint`) then satisfies `exp (i • A) = U`, + -- with no restriction on the spectrum: the `‖u - 1‖ < 2` hypothesis of + -- `expUnitary_argSelfAdjoint` is replaced by the continuity that finiteness supplies. + have hrec := expUnitary_argSelfAdjoint_of_continuousOn_arg (u := u) (hfin.continuousOn _) + refine ⟨(Unitary.argSelfAdjoint u : E →L[ℂ] E), + selfAdjoint.mem_iff.mp (Unitary.argSelfAdjoint u).2, ?_⟩ + rw [← selfAdjoint.expUnitary_coe, hrec] + +/-- **Every unitary endomorphism of a finite-dimensional complex Hilbert space is `exp (-i • A)` +for a self-adjoint `A` whose spectrum lies in `[0, 2π]`.** This refines +`exists_isSelfAdjoint_exp_smul_I_eq_of_mem_unitary` by fixing the branch of the logarithm: writing +`U = exp (-i A)`, the self-adjoint generator `A` can be chosen with every eigenvalue a real number +in `[0, 2π]` (`spectrum ℂ A ⊆ ℝ ∩ [0, 2π]`). This is the operator content of Nielsen & Chuang, +*Quantum Computation and Quantum Information*, Problem 4.3(1): `H = i log U` is Hermitian with +eigenvalues in the range `0` to `2π`. + +The witness is `A = cfc β U`, where `β z` is the unique argument in `[0, 2π)` for which +`exp (-i β z) = z` on the unit circle (`β z = -arg z` for `arg z ≤ 0`, else `2π - arg z`). +Self-adjointness holds since +`β` is real-valued; the spectral bound is the spectral mapping theorem (`cfc_map_spectrum`) together +with `β '' (unit circle) ⊆ [0, 2π)`; and the recovery `exp (-i • A) = U` reduces, via the continuous +functional calculus, to `exp (-i β z) = z` on the spectrum, where finiteness of the spectrum +supplies the continuity `β` needs. + +The spectral bound is phrased over `spectrum ℂ` (as `A`'s eigenvalues are real numbers lying in the +interval `[0, 2π]`) rather than `spectrum ℝ`, avoiding the auxiliary `Algebra ℝ`/`IsScalarTower` +scaffolding of the real functional calculus; for the self-adjoint `A`, `spectrum ℝ A` is the real +part of `spectrum ℂ A`, so the two formulations carry the same content. -/ +theorem exists_isSelfAdjoint_spectrum_Icc_exp_neg_smul_I_eq_of_mem_unitary + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {U : E →L[ℂ] E} (hU : U ∈ unitary (E →L[ℂ] E)) : + ∃ A : E →L[ℂ] E, IsSelfAdjoint A ∧ + spectrum ℂ A ⊆ Complex.ofReal '' Set.Icc 0 (2 * Real.pi) ∧ + NormedSpace.exp (-Complex.I • A) = U := by + classical + set u : unitary (E →L[ℂ] E) := ⟨U, hU⟩ with hu + have : IsStarNormal (u : E →L[ℂ] E) := isStarNormal_of_mem_unitary u.2 + -- The `[0, 2π)`-branch of `i log`: `β z` is the argument in `[0, 2π)` with `exp (-i β z) = z`. + set β : ℂ → ℂ := fun z => ((if z.arg ≤ 0 then -z.arg else 2 * Real.pi - z.arg : ℝ) : ℂ) with hβ + have hfin : (spectrum ℂ (u : E →L[ℂ] E)).Finite := by + rw [ContinuousLinearMap.spectrum_eq] + exact Module.End.finite_spectrum _ + have hcont : ContinuousOn β (spectrum ℂ (u : E →L[ℂ] E)) := hfin.continuousOn _ + have hsa : IsSelfAdjoint (cfc β (u : E →L[ℂ] E)) := by + change star (cfc β (u : E →L[ℂ] E)) = cfc β (u : E →L[ℂ] E) + rw [← cfc_star] + exact cfc_congr fun z _ => by simp [hβ, Complex.conj_ofReal] + refine ⟨cfc β (u : E →L[ℂ] E), hsa, ?_, ?_⟩ + · -- Spectral bound: `spectrum ℂ (cfc β u) = β '' spectrum ℂ u`, and `β z ∈ ofReal '' [0, 2π]`. + rw [cfc_map_spectrum β (u : E →L[ℂ] E)] + rintro _ ⟨z, _, rfl⟩ + have ha1 := Complex.neg_pi_lt_arg z + have ha2 := Complex.arg_le_pi z + have hpi := Real.pi_pos + refine ⟨if z.arg ≤ 0 then -z.arg else 2 * Real.pi - z.arg, ?_, by simp [hβ]⟩ + constructor <;> · split_ifs <;> linarith + · -- Recovery: `exp (-i • cfc β u) = cfc (fun z => exp (-i β z)) u = cfc id u = u`. + change NormedSpace.exp (-Complex.I • cfc β (u : E →L[ℂ] E)) = (u : E →L[ℂ] E) + rw [(cfc_smul (-Complex.I) β (u : E →L[ℂ] E)).symm, ← CFC.complex_exp_eq_normedSpace_exp, + ← cfc_comp' Complex.exp (fun z => -Complex.I • β z) (u : E →L[ℂ] E)] + conv_rhs => rw [← cfc_id' ℂ (u : E →L[ℂ] E)] + refine cfc_congr fun z hz => ?_ + have hz1 : ‖z‖ = 1 := spectrum.norm_eq_one_of_unitary u.2 hz + have hrec := Complex.norm_mul_exp_arg_mul_I z + rw [hz1] at hrec + simp only [hβ] + rcases le_or_gt z.arg 0 with h | h + · have he : -Complex.I • ((-z.arg : ℝ) : ℂ) = (z.arg : ℂ) * Complex.I := by + rw [smul_eq_mul]; push_cast; ring + rw [ite_eq_left h, he] + simpa using hrec + · have he : -Complex.I • ((2 * Real.pi - z.arg : ℝ) : ℂ) + = (z.arg : ℂ) * Complex.I - 2 * (Real.pi : ℂ) * Complex.I := by + rw [smul_eq_mul]; push_cast; ring + rw [ite_eq_right (not_le.mpr h), he, Complex.exp_sub, Complex.exp_two_pi_mul_I] + simpa using hrec + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Calculus/Deriv/RingInverse.lean b/LeanPool/AxQM/ToMathlib/Analysis/Calculus/Deriv/RingInverse.lean new file mode 100644 index 0000000000..98f9ad8c0b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Calculus/Deriv/RingInverse.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Calculus.FDeriv.Mul +public import Mathlib.Analysis.Calculus.Deriv.Comp +public import Mathlib.Analysis.Calculus.Deriv.Mul +public import Mathlib.Analysis.Calculus.Deriv.Add + +/-! +# Derivative of `Ring.inverse` composed with a differentiable function + +`Mathlib.Analysis.Calculus.FDeriv.Mul` provides `hasFDerivAt_ringInverse`, the Fréchet +derivative of the inversion map `Ring.inverse` at a unit `x` of a Banach algebra `R` +(one with summable geometric series), namely `h ↦ -x⁻¹ * h * x⁻¹`. This file records the +corresponding **chain rules**: the derivative of `y ↦ Ring.inverse (g y)` for a +differentiable `R`-valued map `g` whose value is a unit at the point of interest. + +Both the multivariable (`HasFDerivAt.ringInverse`) and one-dimensional +(`HasDerivAt.ringInverse`) forms are provided, in parallel with the existing +`Differentiable.inverse`. The one-dimensional form specialises to the derivative of the +**resolvent along an affine line** `t ↦ (a + t • b)⁻¹` (`hasDerivAt_ringInverse_add_smul`), +with the familiar "sandwich" derivative `-x⁻¹ * b * x⁻¹`; this is the elementary calculus +step underlying the parametric derivative of an operator resolvent, e.g. in the +integral-representation approach to differentiating an operator logarithm along a line. + +## Main results + +* `HasFDerivAt.ringInverse` — chain rule for `Ring.inverse` (Fréchet form). +* `HasDerivAt.ringInverse` — chain rule for `Ring.inverse` (one real/scalar variable). +* `hasDerivAt_ringInverse_add_smul` — the derivative of the resolvent `t ↦ (a + t • b)⁻¹` + along an affine line, `-(a + t₀ • b)⁻¹ * b * (a + t₀ • b)⁻¹`. +-/ + +@[expose] public section + +variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] +variable {R : Type*} [NormedRing R] [HasSummableGeomSeries R] [NormedAlgebra 𝕜 R] + +/-- **Chain rule for `Ring.inverse`, Fréchet form.** If `g` has Fréchet derivative `g'` at +`x` and `g x` is a unit, then `y ↦ Ring.inverse (g y)` has Fréchet derivative +`h ↦ -(g x)⁻¹ * (g' h) * (g x)⁻¹` at `x`. The derivative is written using the unit inverse +`↑hu.unit⁻¹` (which equals `Ring.inverse (g x)`). -/ +theorem HasFDerivAt.ringInverse {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] + {g : E → R} {g' : E →L[𝕜] R} {x : E} (hg : HasFDerivAt g g' x) (hu : IsUnit (g x)) : + HasFDerivAt (fun y => Ring.inverse (g y)) + (-((ContinuousLinearMap.mulLeftRight 𝕜 R ↑hu.unit⁻¹ ↑hu.unit⁻¹).comp g')) x := by + have hL := hasFDerivAt_ringInverse (𝕜 := 𝕜) hu.unit + rw [hu.unit_spec] at hL + exact hL.comp x hg + +/-- **Chain rule for `Ring.inverse`, one-variable form.** If `g : 𝕜 → R` has derivative `g'` +at `t₀` and `g t₀` is a unit, then `t ↦ Ring.inverse (g t)` has derivative +`-(g t₀)⁻¹ * g' * (g t₀)⁻¹` at `t₀`. -/ +theorem HasDerivAt.ringInverse {g : 𝕜 → R} {g' : R} {t₀ : 𝕜} + (hg : HasDerivAt g g' t₀) (hu : IsUnit (g t₀)) : + HasDerivAt (fun t => Ring.inverse (g t)) (-(↑hu.unit⁻¹ * g' * ↑hu.unit⁻¹)) t₀ := by + have hL := hasFDerivAt_ringInverse (𝕜 := 𝕜) hu.unit + rw [hu.unit_spec] at hL + have hC := hL.comp_hasDerivAt t₀ hg + simp only [neg_apply, ContinuousLinearMap.mulLeftRight_apply] at hC + exact hC + +/-- **Derivative of the resolvent along an affine line.** For `a b : R` with `a + t₀ • b` a +unit, the resolvent `t ↦ Ring.inverse (a + t • b)` has derivative +`-(a + t₀ • b)⁻¹ * b * (a + t₀ • b)⁻¹` at `t₀` (the "sandwich" formula). -/ +theorem hasDerivAt_ringInverse_add_smul {a b : R} {t₀ : 𝕜} (hu : IsUnit (a + t₀ • b)) : + HasDerivAt (fun t : 𝕜 => Ring.inverse (a + t • b)) (-(↑hu.unit⁻¹ * b * ↑hu.unit⁻¹)) t₀ := by + simpa using (((hasDerivAt_id t₀).smul_const b).const_add a).ringInverse hu diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Convex/Function.lean b/LeanPool/AxQM/ToMathlib/Analysis/Convex/Function.lean new file mode 100644 index 0000000000..f304aeef91 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Convex/Function.lean @@ -0,0 +1,37 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Convex.Function + +/-! +# Finite sums of convex/concave functions are convex/concave +-/ + +@[expose] public section + +variable {𝕜 E β ι : Type*} [Semiring 𝕜] [PartialOrder 𝕜] +variable [AddCommMonoid E] [AddCommMonoid β] [PartialOrder β] +variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} + +theorem ConvexOn.sum [IsOrderedAddMonoid β] {t : Finset ι} {f : ι → E → β} + (hs : Convex 𝕜 s) (h : ∀ i ∈ t, ConvexOn 𝕜 s (f i)) : + ConvexOn 𝕜 s (fun x ↦ ∑ i ∈ t, f i x) := by + classical + induction t using Finset.induction with + | empty => simpa using convexOn_const 0 hs + | @insert i t hi ih => + simp_rw [Finset.sum_insert hi] + exact (h i (Finset.mem_insert_self _ _)).add + (ih fun j hj ↦ h j (Finset.mem_insert_of_mem hj)) + +theorem ConcaveOn.sum [IsOrderedAddMonoid β] {t : Finset ι} {f : ι → E → β} + (hs : Convex 𝕜 s) (h : ∀ i ∈ t, ConcaveOn 𝕜 s (f i)) : + ConcaveOn 𝕜 s (fun x ↦ ∑ i ∈ t, f i x) := + ConvexOn.sum (β := βᵒᵈ) hs h diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Convex/FunctionTopology.lean b/LeanPool/AxQM/ToMathlib/Analysis/Convex/FunctionTopology.lean new file mode 100644 index 0000000000..ea45024a30 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Convex/FunctionTopology.lean @@ -0,0 +1,52 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Convex.FunctionTopology + +/-! +# Pointwise limits of convex/concave functions + +* `ConvexOn.of_tendsto_pointwise_on` / `ConcaveOn.of_tendsto_pointwise_on`: a pointwise-on-`s` + limit of eventually-convex (resp. concave) functions is convex (resp. concave) on `s`. +-/ + +@[expose] public section + +open scoped Topology +open Set + +variable {𝕜 α β : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [PartialOrder β] + [TopologicalSpace β] [OrderClosedTopology β] + [AddCommMonoid α] [AddCommMonoid β] + [SMul 𝕜 α] [SMul 𝕜 β] + [ContinuousConstSMul 𝕜 β] [ContinuousAdd β] + +/-- If a family of functions converges pointwise on `s` to `f`, and the family is eventually +convex on `s`, then `f` is convex on `s`. -/ +theorem ConvexOn.of_tendsto_pointwise_on {ι : Type*} {l : Filter ι} [l.NeBot] + {F : ι → α → β} {f : α → β} {s : Set α} (hs : Convex 𝕜 s) + (h_eventually : ∀ᶠ n in l, ConvexOn 𝕜 s (F n)) + (h_tendsto : ∀ x ∈ s, Filter.Tendsto (F · x) l (𝓝 (f x))) : + ConvexOn 𝕜 s f := + ⟨hs, fun _ hx _ hy _ _ ha hb hab => le_of_tendsto_of_tendsto + (h_tendsto _ (hs hx hy ha hb hab)) + (((h_tendsto _ hx).const_smul _).add ((h_tendsto _ hy).const_smul _)) + (h_eventually.mono fun _ hn => hn.2 hx hy ha hb hab)⟩ + +/-- If a family of functions converges pointwise on `s` to `f`, and the family is eventually +concave on `s`, then `f` is concave on `s`. -/ +theorem ConcaveOn.of_tendsto_pointwise_on {ι : Type*} {l : Filter ι} [l.NeBot] + {F : ι → α → β} {f : α → β} {s : Set α} (hs : Convex 𝕜 s) + (h_eventually : ∀ᶠ n in l, ConcaveOn 𝕜 s (F n)) + (h_tendsto : ∀ x ∈ s, Filter.Tendsto (F · x) l (𝓝 (f x))) : + ConcaveOn 𝕜 s f := by + have : ContinuousAdd βᵒᵈ := ‹ContinuousAdd β› + have : ContinuousConstSMul 𝕜 βᵒᵈ := ‹ContinuousConstSMul 𝕜 β› + exact ConvexOn.of_tendsto_pointwise_on (β := βᵒᵈ) hs h_eventually h_tendsto diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Convex/Majorization.lean b/LeanPool/AxQM/ToMathlib/Analysis/Convex/Majorization.lean new file mode 100644 index 0000000000..0db9e82707 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Convex/Majorization.lean @@ -0,0 +1,893 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Convex.Birkhoff +public import Mathlib.Data.Fin.Tuple.Sort +public import Mathlib.Algebra.Order.Rearrangement +public import Mathlib.Analysis.LocallyConvex.Separation +public import LeanPool.AxQM.ToMathlib.Data.Fintype.EquivOfMultisetMap + +/-! +# Majorization of real vectors + +Majorization is an order on real vectors capturing the idea that one vector is more spread out +(less "disordered") than another. For `x y : ι → ℝ` on a finite index type `ι` we say `x` is +*majorized* by `y`, `Majorize x y`, when the sum of the `k` largest entries of `x` is at most that +of `y` for every `k`, and the two total sums agree. + +The condition is recorded through `largestKSum x k`, the largest sum of any `k` entries of `x`, +defined as a supremum over `k`-element subsets so that no explicit sorting of the entries is +needed. This form pairs directly with `doublyStochastic` and Birkhoff's theorem +(`exists_eq_sum_perm_of_mem_doublyStochastic`), towards the representation theorem +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, Proposition 12.11) +`Majorize x y ↔ x = ∑ⱼ pⱼ Pⱼ y` for probabilities `pⱼ` and permutation matrices `Pⱼ`. + +## Main definitions + +* `largestKSum x k`: the maximum of `∑ i ∈ s, x i` over `k`-element subsets `s`. +* `Majorize x y`: `x` is majorized by `y`. +* `tailSum x t`: the tail/cut function `∑ i, max (x i - t) 0`, the Legendre-type conjugate of + `largestKSum x` used for the Exercise 12.17 characterisation. + +## Main statements + +* `Majorize.refl`, `Majorize.sum_eq`: basic properties. +* `majorize_iff_forall_largestKSum`: the definition matches the textbook "sum of the `k` largest + entries" formulation. +* `Majorize.comp_perm_left`, `Majorize.comp_perm_right`: majorization is unchanged when the entries + of either vector are permuted; in particular a permutation of `y` is majorized by `y`. +* `convex_setOf_majorize`: the set of vectors majorized by a fixed `y` is convex + (Nielsen–Chuang, Exercise 12.18). +* `majorize_sum_smul_permMatrix_mulVec`, `Majorize.of_mem_doublyStochastic`: a convex combination of + permutations of `y` — equivalently, `D *ᵥ y` for a doubly stochastic `D` — is majorized by `y` + (the easy direction of Proposition 12.11). +* `largestKSum_eq_sum_prefix_of_antitone`: for a decreasing vector the `k` largest entries are the + leading ones, so `largestKSum` is realised by the prefix sum. +* `Majorize.sum_mul_le_of_antitone`: the Hardy–Littlewood–Pólya inequality for decreasing vectors, + `∑ i, c i * x i ≤ ∑ i, c i * y i` when `x`, `y`, `c` are antitone and `Majorize x y` + (proved by summation by parts on the `largestKSum` sequence). +* `Majorize.exists_perm_sum_mul_le`: the coordinate-free consequence for an arbitrary weight vector + `c`, `∃ σ, ∑ i, c i * x i ≤ ∑ i, c i * y (σ i)`; this is the analytic input to the "hard" + direction of Proposition 12.11 (that `x ≺ y` implies `x = D *ᵥ y` for a doubly stochastic `D`). +* `Majorize.exists_doublyStochastic_mulVec`: the hard direction — `x ≺ y` implies `x = D *ᵥ y` for + some doubly stochastic `D` — proved by separating `x` from the compact convex set of such images + with a hyperplane (`geometric_hahn_banach_closed_point`). +* `majorize_iff_exists_doublyStochastic`: the Hardy–Littlewood–Pólya characterisation + `Majorize x y ↔ ∃ D ∈ doublyStochastic ℝ ι, D *ᵥ y = x`. +* `majorize_iff_exists_sum_perm`: **Nielsen–Chuang, Proposition 12.11** — `Majorize x y` holds iff + `x = ∑ⱼ pⱼ Pⱼ y` for a probability distribution `pⱼ` and permutation matrices `Pⱼ`. +* `majorize_iff_forall_tailSum`: **Nielsen–Chuang, Exercise 12.17** — `Majorize x y` holds iff + `∀ t, tailSum x t ≤ tailSum y t` together with equality of the total sums, via the conjugacy + `largestKSum_le_tailSum_add` / `exists_tailSum_add_eq_largestKSum` between `tailSum` and + `largestKSum`. + +## Tags + +majorization, doubly stochastic, Schur +-/ + +public section + +open Finset Function Matrix +open scoped BigOperators + +variable {ι : Type*} + +/-- `largestKSum x k` is the largest sum of `k` entries of `x`: the supremum of `∑ i ∈ s, x i` over +`k`-element subsets `s` of the index type. It equals `0` when `k` exceeds the dimension, since then +no such subset exists. -/ +noncomputable def largestKSum (x : ι → ℝ) (k : ℕ) : ℝ := + ⨆ s : {s : Finset ι // s.card = k}, ∑ i ∈ (s : Finset ι), x i + +private lemma bddAbove_range_subtype_sum [Finite ι] (x : ι → ℝ) (k : ℕ) : + BddAbove (Set.range fun s : {s : Finset ι // s.card = k} => ∑ i ∈ (s : Finset ι), x i) := by + have : Fintype ι := Fintype.ofFinite ι + exact Set.Finite.bddAbove (Set.finite_range _) + +/-- Any subset sum of `x` is at most the largest sum of that many entries of `x`. -/ +lemma sum_le_largestKSum [Finite ι] (x : ι → ℝ) (s : Finset ι) : + ∑ i ∈ s, x i ≤ largestKSum x s.card := + le_ciSup (bddAbove_range_subtype_sum x s.card) (⟨s, rfl⟩ : {t : Finset ι // t.card = s.card}) + +/-- The largest sum of `k` entries is at most `c` as soon as every `k`-subset sum is at most `c` +(and there is at least one `k`-subset, i.e. `k ≤ card ι`). -/ +lemma largestKSum_le [Fintype ι] {x : ι → ℝ} {k : ℕ} {c : ℝ} (hk : k ≤ Fintype.card ι) + (h : ∀ s : Finset ι, s.card = k → ∑ i ∈ s, x i ≤ c) : + largestKSum x k ≤ c := by + obtain ⟨t, _, ht⟩ := + Finset.exists_subset_card_eq (show k ≤ (univ : Finset ι).card by simpa using hk) + have : Nonempty {s : Finset ι // s.card = k} := ⟨t, ht⟩ + exact ciSup_le fun s => h s s.2 + +/-- Reindexing the entries of `x` along any equivalence `e : κ ≃ ι` leaves the largest sum of `k` +entries unchanged: the `k`-element subsets of the two index types are in bijection via `e`. -/ +lemma largestKSum_comp_equiv {κ : Type*} (x : ι → ℝ) (e : κ ≃ ι) (k : ℕ) : + largestKSum (x ∘ e) k = largestKSum x k := by + let E : {s : Finset κ // s.card = k} ≃ {s : Finset ι // s.card = k} := + (e.finsetCongr).subtypeEquiv (by intro t; simp [Equiv.finsetCongr_apply]) + have key : ∀ s : {s : Finset κ // s.card = k}, + ∑ i ∈ (s : Finset κ), (x ∘ e) i = ∑ i ∈ (E s : Finset ι), x i := by + intro s + simp only [E, Equiv.subtypeEquiv_apply, Equiv.finsetCongr_apply, Finset.sum_map, + Function.comp_apply, Equiv.coe_toEmbedding] + calc largestKSum (x ∘ e) k + = ⨆ s : {s : Finset κ // s.card = k}, ∑ i ∈ (E s : Finset ι), x i := iSup_congr key + _ = largestKSum x k := + Equiv.iSup_comp (g := fun t : {s : Finset ι // s.card = k} => ∑ i ∈ (t : Finset ι), x i) E + +/-- Reindexing the entries of `x` by a permutation leaves the largest sum of `k` entries +unchanged. -/ +lemma largestKSum_comp_perm (x : ι → ℝ) (σ : Equiv.Perm ι) (k : ℕ) : + largestKSum (x ∘ σ) k = largestKSum x k := + largestKSum_comp_equiv x σ k + +/-- `x` is *majorized* by `y` (written `x ≺ y` in the literature): the sum of the `k` largest +entries of `x` is at most the sum of the `k` largest entries of `y` for every `k`, and the total +sums agree. This is recorded compactly by requiring that every subset sum of `x` is bounded by the +largest equal-sized subset sum of `y`, together with equality of the total sums. -/ +def Majorize [Fintype ι] (x y : ι → ℝ) : Prop := + (∑ i, x i = ∑ i, y i) ∧ ∀ s : Finset ι, ∑ i ∈ s, x i ≤ largestKSum y s.card + +variable [Fintype ι] + +/-- Majorization preserves the total sum. -/ +lemma Majorize.sum_eq {x y : ι → ℝ} (h : Majorize x y) : ∑ i, x i = ∑ i, y i := h.1 + +/-- Majorization is reflexive. -/ +@[refl] +lemma Majorize.refl (x : ι → ℝ) : Majorize x x := + ⟨rfl, fun s => sum_le_largestKSum x s⟩ + +/-- Majorization is exactly the textbook condition: the sum of the `k` largest entries of `x` is at +most that of `y` for every `k`, together with equality of the total sums. -/ +lemma majorize_iff_forall_largestKSum {x y : ι → ℝ} : + Majorize x y ↔ (∑ i, x i = ∑ i, y i) ∧ ∀ k, largestKSum x k ≤ largestKSum y k := by + constructor + · rintro ⟨hsum, h⟩ + refine ⟨hsum, fun k => ?_⟩ + rcases le_or_gt k (Fintype.card ι) with hk | hk + · exact largestKSum_le hk fun s hs => hs ▸ h s + · have : IsEmpty {s : Finset ι // s.card = k} := ⟨fun s => by + have h1 : s.1.card ≤ Fintype.card ι := by simpa using Finset.card_le_card s.1.subset_univ + have h2 : s.1.card = k := s.2 + omega⟩ + have hz : ∀ z : ι → ℝ, largestKSum z k = 0 := fun z => Real.iSup_of_isEmpty _ + exact le_of_eq ((hz x).trans (hz y).symm) + · rintro ⟨hsum, h⟩ + exact ⟨hsum, fun s => (sum_le_largestKSum x s).trans (h s.card)⟩ + +/-- Majorization is unchanged when the entries of the smaller vector are permuted. -/ +lemma Majorize.comp_perm_left {x y : ι → ℝ} (σ : Equiv.Perm ι) : + Majorize (x ∘ σ) y ↔ Majorize x y := by + rw [majorize_iff_forall_largestKSum, majorize_iff_forall_largestKSum] + simp only [Function.comp_apply, Equiv.sum_comp, largestKSum_comp_perm] + +/-- Majorization is unchanged when the entries of the larger vector are permuted. -/ +lemma Majorize.comp_perm_right {x y : ι → ℝ} (σ : Equiv.Perm ι) : + Majorize x (y ∘ σ) ↔ Majorize x y := by + rw [majorize_iff_forall_largestKSum, majorize_iff_forall_largestKSum] + simp only [Function.comp_apply, Equiv.sum_comp, largestKSum_comp_perm] + +/-- Any permutation of `y` is majorized by `y`. -/ +lemma majorize_comp_perm_self (y : ι → ℝ) (σ : Equiv.Perm ι) : Majorize (y ∘ σ) y := + (Majorize.comp_perm_left σ).2 (Majorize.refl y) + +/-- Applying a permutation matrix to `y` produces a vector majorized by `y`. -/ +lemma majorize_permMatrix_mulVec_self [DecidableEq ι] (y : ι → ℝ) (σ : Equiv.Perm ι) : + Majorize (σ.permMatrix ℝ *ᵥ y) y := by + rw [Matrix.permMatrix_mulVec] + exact majorize_comp_perm_self y σ + +/-- Reindexing both vectors along a single equivalence `e : κ ≃ ι` preserves majorization: the +largest-`k`-sum characterization is invariant under a common bijective reindexing of the entries. -/ +lemma Majorize.comp_equiv {κ : Type*} [Fintype κ] (e : κ ≃ ι) {x y : ι → ℝ} : + Majorize (x ∘ e) (y ∘ e) ↔ Majorize x y := by + rw [majorize_iff_forall_largestKSum, majorize_iff_forall_largestKSum] + simp only [Function.comp_apply, Equiv.sum_comp, largestKSum_comp_equiv] + +/-- **Majorization depends only on the value-multisets.** If `x` and `x'` (resp. `y` and `y'`) have +the same multiset of values, then `x ≺ y ↔ x' ≺ y'`, even across different finite index types. This +transports a majorization statement to any reindexing of its two vectors — e.g. from an explicitly +sorted spectrum to a quantum state's canonical eigenvalue distribution. -/ +lemma majorize_congr_multiset {κ : Type*} [Fintype κ] {x y : ι → ℝ} {x' y' : κ → ℝ} + (hx : Multiset.map x Finset.univ.val = Multiset.map x' Finset.univ.val) + (hy : Multiset.map y Finset.univ.val = Multiset.map y' Finset.univ.val) : + Majorize x y ↔ Majorize x' y' := by + classical + obtain ⟨ex, hex⟩ := exists_equiv_of_map_univ_val_eq hx + obtain ⟨ey, hey⟩ := exists_equiv_of_map_univ_val_eq hy + have hxe : x = x' ∘ ex := funext fun i => (hex i).symm + have hye : y = y' ∘ ey := funext fun i => (hey i).symm + rw [hxe, hye] + have hrw : (y' ∘ ⇑ey) = (y' ∘ ⇑(ex.symm.trans ey)) ∘ ⇑ex := by funext i; simp + rw [hrw, Majorize.comp_equiv ex, Majorize.comp_perm_right (ex.symm.trans ey)] + +/-- The set of vectors majorized by a fixed `y` is convex (Nielsen–Chuang, Exercise 12.18). It is +cut out by the total-sum equation together with the half-space conditions +`∑ i ∈ s, x i ≤ largestKSum y s.card`, and each of these is preserved under convex combinations. -/ +lemma convex_setOf_majorize (y : ι → ℝ) : Convex ℝ {x | Majorize x y} := by + intro x₁ hx₁ x₂ hx₂ a b ha hb hab + obtain ⟨hs₁, hl₁⟩ := hx₁ + obtain ⟨hs₂, hl₂⟩ := hx₂ + refine ⟨?_, fun s => ?_⟩ + · calc ∑ i, (a • x₁ + b • x₂) i + = a * ∑ i, x₁ i + b * ∑ i, x₂ i := by + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.sum_add_distrib, + ← Finset.mul_sum] + _ = a * ∑ i, y i + b * ∑ i, y i := by rw [hs₁, hs₂] + _ = ∑ i, y i := by rw [← add_mul, hab, one_mul] + · calc ∑ i ∈ s, (a • x₁ + b • x₂) i + = a * ∑ i ∈ s, x₁ i + b * ∑ i ∈ s, x₂ i := by + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.sum_add_distrib, + ← Finset.mul_sum] + _ ≤ a * largestKSum y s.card + b * largestKSum y s.card := + add_le_add (mul_le_mul_of_nonneg_left (hl₁ s) ha) + (mul_le_mul_of_nonneg_left (hl₂ s) hb) + _ = largestKSum y s.card := by rw [← add_mul, hab, one_mul] + +/-- A convex combination of the permutations `σ.permMatrix ℝ *ᵥ y` of `y` is majorized by `y`. This +is the vector form of the "easy" direction of Nielsen–Chuang, Proposition 12.11: +`x = ∑ⱼ pⱼ Pⱼ y ⟹ x ≺ y`. -/ +lemma majorize_sum_smul_permMatrix_mulVec [DecidableEq ι] (y : ι → ℝ) + {w : Equiv.Perm ι → ℝ} (hw : ∀ σ, 0 ≤ w σ) (hw1 : ∑ σ, w σ = 1) : + Majorize (∑ σ : Equiv.Perm ι, w σ • (σ.permMatrix ℝ *ᵥ y)) y := + (convex_setOf_majorize y).sum_mem (fun σ _ => hw σ) hw1 + (fun σ _ => majorize_permMatrix_mulVec_self y σ) + +/-- Applying a doubly stochastic matrix `D` to `y` produces a vector majorized by `y`. Combined +with Birkhoff's theorem this is the easy direction of the representation theorem (Nielsen–Chuang, +Proposition 12.11): `D *ᵥ y ≺ y`. -/ +lemma Majorize.of_mem_doublyStochastic [DecidableEq ι] {D : Matrix ι ι ℝ} + (hD : D ∈ doublyStochastic ℝ ι) (y : ι → ℝ) : Majorize (D *ᵥ y) y := by + obtain ⟨w, hw, hw1, hwD⟩ := exists_eq_sum_perm_of_mem_doublyStochastic hD + rw [← hwD, Matrix.sum_mulVec] + simp only [Matrix.smul_mulVec] + exact majorize_sum_smul_permMatrix_mulVec y hw hw1 + +/-- **Majorization does not shrink the support of a nonnegative vector.** If `x` is majorized by a +nonnegative `y`, then `y` has at most as many nonzero entries as `x`: a more spread-out (majorized) +distribution `x ≺ y` is supported on at least as many coordinates as the more concentrated `y`. + +The proof rests on a single observation. Let `Sx` be the support of `x`. Because the entries off +`Sx` vanish, the mass on `Sx` is the whole of `∑ x = ∑ y`; majorization then bounds this by the +largest `|Sx|`-entry sum of `y`, `largestKSum y Sx.card`. Since `y ≥ 0`, that quantity is in turn +at most `∑ y`, so it *equals* `∑ y`: the `|Sx|` largest entries of `y` already carry all of its +mass. A maximizing `|Sx|`-element set `t₀` therefore satisfies `∑_{t₀} y = ∑ y`, forcing `y` to +vanish on its complement. So the support of `y` lies in `t₀`, whose cardinality is `|Sx|`. -/ +lemma Majorize.card_filter_ne_zero_le {x y : ι → ℝ} + (h : Majorize x y) (hy : ∀ i, 0 ≤ y i) : + (univ.filter fun i => y i ≠ 0).card ≤ (univ.filter fun i => x i ≠ 0).card := by + classical + -- If the `k` largest entries of the nonnegative `y` already sum to all of `∑ y`, then `y` is + -- supported on at most `k` coordinates. + have key : ∀ k : ℕ, k ≤ Fintype.card ι → largestKSum y k = ∑ i, y i → + (univ.filter fun i => y i ≠ 0).card ≤ k := by + intro k hk hmass + obtain ⟨t, _, ht⟩ := Finset.exists_subset_card_eq + (show k ≤ (univ : Finset ι).card by simpa using hk) + have : Nonempty {s : Finset ι // s.card = k} := ⟨t, ht⟩ + -- a `k`-subset `t₀` realising the largest `k`-entry sum + obtain ⟨t0, -, ht0⟩ := Finset.exists_max_image (univ : Finset {s : Finset ι // s.card = k}) + (fun s => ∑ i ∈ (s : Finset ι), y i) univ_nonempty + have hmax : largestKSum y k = ∑ i ∈ (t0 : Finset ι), y i := + le_antisymm (ciSup_le fun s => ht0 s (mem_univ s)) + (le_ciSup (bddAbove_range_subtype_sum y k) t0) + have ht0mass : ∑ i ∈ (t0 : Finset ι), y i = ∑ i, y i := hmax.symm.trans hmass + -- `y` carries all its mass on `t₀`, hence vanishes on the complement + have hcompl : ∑ i ∈ (t0 : Finset ι)ᶜ, y i = 0 := by + have hsplit := Finset.sum_add_sum_compl (t0 : Finset ι) y + rw [ht0mass] at hsplit; linarith + have hzero : ∀ i ∈ (t0 : Finset ι)ᶜ, y i = 0 := + (Finset.sum_eq_zero_iff_of_nonneg fun i _ => hy i).mp hcompl + have hsub : (univ.filter fun i => y i ≠ 0) ⊆ (t0 : Finset ι) := by + intro i hi + rw [mem_filter] at hi + by_contra hit0 + exact hi.2 (hzero i (Finset.mem_compl.mpr hit0)) + exact (Finset.card_le_card hsub).trans_eq t0.2 + refine key _ ?_ (le_antisymm ?_ ?_) + · simpa using Finset.card_filter_le (univ : Finset ι) _ + · -- `largestKSum y |supp x| ≤ ∑ y`: every subset sum of a nonnegative vector is at most the total + exact largestKSum_le (by simpa using Finset.card_filter_le (univ : Finset ι) _) + fun s _ => Finset.sum_le_sum_of_subset_of_nonneg (subset_univ s) fun i _ _ => hy i + · -- `∑ y ≤ largestKSum y |supp x|`: the support of `x` is a subset carrying all of `∑ x = ∑ y` + have hmassx : ∑ i ∈ univ.filter (fun i => x i ≠ 0), x i = ∑ i, y i := by + rw [← h.sum_eq] + refine Finset.sum_subset (filter_subset _ _) fun i _ hi => ?_ + by_contra hne + exact hi (mem_filter.mpr ⟨mem_univ i, hne⟩) + calc ∑ i, y i = ∑ i ∈ univ.filter (fun i => x i ≠ 0), x i := hmassx.symm + _ ≤ largestKSum y (univ.filter (fun i => x i ≠ 0)).card := h.2 _ + +/-! +### The Hardy–Littlewood–Pólya inequality + +The "hard" direction of Proposition 12.11 — that `x ≺ y` implies `x = D *ᵥ y` for a doubly +stochastic `D` — is proved geometrically by separating `x` from the (compact, convex) set of such +`D *ᵥ y` with a hyperplane. The analytic fact that rules out any separating hyperplane is +`Majorize.exists_perm_sum_mul_le`: for every weight vector `c`, `∑ i, c i * x i` is at most +`∑ i, c i * y (σ i)` for some permutation `σ`. It is established here through the classical +Hardy–Littlewood–Pólya inequality for decreasing vectors (`Majorize.sum_mul_le_of_antitone`), +combined with the rearrangement inequality. +-/ + +/-- When `k ≤ n`, exactly `k` of the indices in `Fin n` satisfy `(i : ℕ) < k`: the leading `k` +indices form the prefix `{0, …, k-1}`. -/ +private lemma card_filter_lt {n : ℕ} (k : ℕ) (hk : k ≤ n) : + (univ.filter (fun i : Fin n => (i : ℕ) < k)).card = k := by + rw [Finset.card_filter, Fin.sum_univ_eq_sum_range (fun i => if i < k then 1 else 0) n, + ← Finset.card_filter] + have : {i ∈ range n | i < k} = range k := by ext x; simp only [mem_filter, mem_range]; omega + rw [this, card_range] + +/-- For an antitone `z : Fin n → ℝ`, any `k`-element subset sum is at most the sum over the first +`k` indices. Since `z` is decreasing, its `k` largest entries are the leading ones; the pinch +below bounds the entries of `z` outside the prefix by those inside it. -/ +private lemma sum_le_sum_prefix_of_antitone {n : ℕ} {z : Fin n → ℝ} (hz : Antitone z) {k : ℕ} + (hk : k ≤ n) (s : Finset (Fin n)) (hs : s.card = k) : + ∑ i ∈ s, z i ≤ ∑ i ∈ univ.filter (fun i : Fin n => (i : ℕ) < k), z i := by + set P : Finset (Fin n) := univ.filter (fun i : Fin n => (i : ℕ) < k) with hP + have hPcard : P.card = k := by rw [hP]; exact card_filter_lt k hk + rcases Nat.eq_zero_or_pos k with hk0 | hk0 + · subst hk0; rw [Finset.card_eq_zero] at hs; subst hs; simp [Finset.card_eq_zero.mp hPcard] + rw [← Finset.sum_inter_add_sum_sdiff s P z, ← Finset.sum_inter_add_sum_sdiff P s z, + Finset.inter_comm P s] + have hcard : (s \ P).card = (P \ s).card := Finset.card_sdiff_comm (by rw [hs, hPcard]) + have hb : (k - 1) < n := by omega + set b : ℝ := z ⟨k - 1, hb⟩ with hbdef + have hBC : ∑ i ∈ s \ P, z i ≤ ∑ i ∈ P \ s, z i := by + calc ∑ i ∈ s \ P, z i ≤ (s \ P).card • b := by + apply Finset.sum_le_card_nsmul + intro i hi + simp only [Finset.mem_sdiff, hP, mem_filter, Finset.mem_univ, true_and, not_lt] at hi + exact hz (by simp only [Fin.le_def]; omega) + _ = (P \ s).card • b := by rw [hcard] + _ ≤ ∑ i ∈ P \ s, z i := by + apply Finset.card_nsmul_le_sum + intro j hj + simp only [Finset.mem_sdiff, hP, mem_filter, Finset.mem_univ, true_and] at hj + exact hz (by simp only [Fin.le_def]; omega) + linarith [hBC] + +/-- The largest sum of `k` entries of an antitone `z : Fin n → ℝ` (with `k ≤ n`) is realised by its +first `k` entries: for a decreasing vector the `k` largest entries are exactly the leading ones. -/ +lemma largestKSum_eq_sum_prefix_of_antitone {n : ℕ} {z : Fin n → ℝ} (hz : Antitone z) (k : ℕ) + (hk : k ≤ n) : + largestKSum z k = ∑ i ∈ univ.filter (fun i : Fin n => (i : ℕ) < k), z i := by + refine le_antisymm (largestKSum_le (by rw [Fintype.card_fin]; exact hk) + fun s hs => sum_le_sum_prefix_of_antitone hz hk s hs) ?_ + have hPcard : (univ.filter (fun i : Fin n => (i : ℕ) < k)).card = k := card_filter_lt k hk + have hle := sum_le_largestKSum z (univ.filter (fun i : Fin n => (i : ℕ) < k)) + rwa [hPcard] at hle + +/-- **Hardy–Littlewood–Pólya inequality (decreasing case).** If `x`, `y`, `c : Fin n → ℝ` are all +antitone and `Majorize x y`, then `∑ i, c i * x i ≤ ∑ i, c i * y i`. This is a summation by parts +on the `largestKSum` sequence: `M k := largestKSum y k - largestKSum x k` is nonnegative for every +`k` and vanishes at `k = 0, n`, and pairing its increments against the nonincreasing weights `c` +yields the inequality. -/ +lemma Majorize.sum_mul_le_of_antitone {n : ℕ} {x y c : Fin n → ℝ} (hx : Antitone x) + (hy : Antitone y) (hc : Antitone c) (h : Majorize x y) : + ∑ i, c i * x i ≤ ∑ i, c i * y i := by + rw [← sub_nonneg, ← Finset.sum_sub_distrib] + have ha : ∀ (z : Fin n → ℝ), Antitone z → ∀ i : Fin n, + largestKSum z (i.val + 1) - largestKSum z i.val = z i := by + intro z hz i + rw [largestKSum_eq_sum_prefix_of_antitone hz (i.val + 1) i.isLt, + largestKSum_eq_sum_prefix_of_antitone hz i.val i.isLt.le] + have hins : univ.filter (fun j : Fin n => (j : ℕ) < i.val + 1) + = insert i (univ.filter (fun j : Fin n => (j : ℕ) < i.val)) := by + ext j; simp only [mem_filter, mem_univ, true_and, mem_insert] + constructor + · intro hj; rcases Nat.lt_succ_iff_lt_or_eq.mp hj with hh | hh + · exact Or.inr hh + · exact Or.inl (Fin.ext hh) + · rintro (rfl | hj) <;> omega + rw [hins, Finset.sum_insert (by simp)]; ring + obtain ⟨_, hforall⟩ := majorize_iff_forall_largestKSum.mp h + set M : ℕ → ℝ := fun k => largestKSum y k - largestKSum x k with hMdef + set C : ℕ → ℝ := fun i => if hi : i < n then c ⟨i, hi⟩ else 0 with hCdef + have hconv : ∑ i, (c i * y i - c i * x i) + = ∑ i ∈ Finset.range n, C i • (M (i + 1) - M i) := by + rw [← Fin.sum_univ_eq_sum_range (fun j => C j • (M (j + 1) - M j)) n] + apply Finset.sum_congr rfl + intro i _ + rw [smul_eq_mul] + have hCi : C i.val = c i := by simp only [hCdef, i.isLt, dite_eq_left] + have hMi : M (i.val + 1) - M i.val = y i - x i := by + simp only [hMdef]; have h1 := ha y hy i; have h2 := ha x hx i; linarith + rw [hCi, hMi]; ring + rw [hconv, Finset.sum_range_by_parts C (fun j => M (j + 1) - M j) n] + have htel : ∀ m, ∑ j ∈ Finset.range m, (M (j + 1) - M j) = M m - M 0 := + fun m => Finset.sum_range_sub M m + have hM0 : M 0 = 0 := by + simp only [hMdef, largestKSum_eq_sum_prefix_of_antitone hx 0 (Nat.zero_le n), + largestKSum_eq_sum_prefix_of_antitone hy 0 (Nat.zero_le n)]; simp + have hMn : M n = 0 := by + simp only [hMdef] + have hfull : (univ.filter (fun j : Fin n => (j : ℕ) < n)) = univ := by ext j; simp + rw [largestKSum_eq_sum_prefix_of_antitone hx n le_rfl, + largestKSum_eq_sum_prefix_of_antitone hy n le_rfl, hfull, h.sum_eq]; ring + simp only [htel, hM0, hMn, sub_zero, smul_zero, zero_sub] + rw [neg_nonneg] + apply Finset.sum_nonpos + intro i hi + rw [Finset.mem_range] at hi + have hi1 : i + 1 < n := by omega + have hi0 : i < n := by omega + rw [smul_eq_mul] + apply mul_nonpos_of_nonpos_of_nonneg + · have hCle : C (i + 1) ≤ C i := by + simp only [hCdef, hi1, hi0, dite_eq_left] + exact hc (by simp only [Fin.le_def]; omega) + linarith + · simp only [hMdef]; linarith [hforall (i + 1)] + +/-- The `Fin n` case of `Majorize.exists_perm_sum_mul_le`: sorting `x`, `y`, `c` into decreasing +order (via `Tuple.sort` of their negations) reduces the claim to the decreasing Hardy–Littlewood– +Pólya inequality, with the rearrangement inequality supplying the bound `∑ c i * x i ≤` the +sorted-together pairing. -/ +private lemma exists_perm_sum_mul_le_fin {n : ℕ} {x y c : Fin n → ℝ} (h : Majorize x y) : + ∃ τ : Equiv.Perm (Fin n), ∑ i, c i * x i ≤ ∑ i, c i * y (τ i) := by + have hanti : ∀ (z : Fin n → ℝ), Antitone (z ∘ (Tuple.sort (fun i => - z i))) := by + intro z a b hab + have h2 := Tuple.monotone_sort (fun i => - z i) hab + simp only [Function.comp_apply] at h2 ⊢; linarith + set σc := Tuple.sort (fun i => - c i) + set σx := Tuple.sort (fun i => - x i) + set σy := Tuple.sort (fun i => - y i) + have hcA : Antitone (c ∘ σc) := hanti c + have hxA : Antitone (x ∘ σx) := hanti x + have hyA : Antitone (y ∘ σy) := hanti y + have hMsorted : Majorize (x ∘ σx) (y ∘ σy) := + (Majorize.comp_perm_left σx).mpr ((Majorize.comp_perm_right σy).mpr h) + have hI : ∑ i, (c ∘ σc) i * (x ∘ σx) i ≤ ∑ i, (c ∘ σc) i * (y ∘ σy) i := + Majorize.sum_mul_le_of_antitone hxA hyA hcA hMsorted + have hmono : Monovary (c ∘ σc) (x ∘ σx) := Antitone.monovary hcA hxA + have hA : ∑ i, c i * x i ≤ ∑ i, (c ∘ σc) i * (x ∘ σx) i := by + have key2 := Monovary.sum_mul_comp_perm_le_sum_mul hmono (σ := σc.trans σx.symm) + simp only [Function.comp_apply, Equiv.trans_apply, Equiv.apply_symm_apply] at key2 ⊢ + rw [← Equiv.sum_comp σc (fun j => c j * x j)] + exact key2 + refine ⟨σc.symm.trans σy, le_trans hA (le_trans hI (le_of_eq ?_))⟩ + rw [← Equiv.sum_comp σc (fun j => c j * y ((σc.symm.trans σy) j))] + apply Finset.sum_congr rfl + intro i _ + simp only [Function.comp_apply, Equiv.trans_apply, Equiv.symm_apply_apply] + +/-- For any weight vector `c`, the paired sum `∑ i, c i * x i` of a majorized vector `x` is at most +`∑ i, c i * y (σ i)` for some permutation `σ` of the (larger) vector `y`. Equivalently, `x` never +exceeds `y` against any linear functional once `y`'s entries may be permuted; this is the analytic +obstruction to separating `x` from the convex hull of the permutations of `y`, and hence the key +input to the representation theorem (Nielsen–Chuang, Proposition 12.11). -/ +lemma Majorize.exists_perm_sum_mul_le {x y : ι → ℝ} (h : Majorize x y) (c : ι → ℝ) : + ∃ σ : Equiv.Perm ι, ∑ i, c i * x i ≤ ∑ i, c i * y (σ i) := by + set e := Fintype.equivFin ι with he + have hM' : Majorize (x ∘ e.symm) (y ∘ e.symm) := by + rw [majorize_iff_forall_largestKSum] + refine ⟨?_, fun k => ?_⟩ + · simp only [Function.comp_apply] + rw [Equiv.sum_comp e.symm x, Equiv.sum_comp e.symm y]; exact h.sum_eq + · rw [largestKSum_comp_equiv x e.symm k, largestKSum_comp_equiv y e.symm k] + exact (majorize_iff_forall_largestKSum.mp h).2 k + obtain ⟨τ, hτ⟩ := exists_perm_sum_mul_le_fin (c := c ∘ e.symm) hM' + refine ⟨e.trans (τ.trans e.symm), ?_⟩ + have hLHS : ∑ j, c j * x j = ∑ i, (c ∘ e.symm) i * (x ∘ e.symm) i := + (Equiv.sum_comp e.symm (fun j => c j * x j)).symm + have hRHS : ∑ j, c j * y ((e.trans (τ.trans e.symm)) j) + = ∑ i, (c ∘ e.symm) i * (y ∘ e.symm) (τ i) := by + rw [← Equiv.sum_comp e.symm (fun j => c j * y ((e.trans (τ.trans e.symm)) j))] + apply Finset.sum_congr rfl; intro i _ + simp only [Function.comp_apply, Equiv.trans_apply, Equiv.apply_symm_apply] + rw [hLHS, hRHS]; exact hτ + +/-! +### The representation theorem (Proposition 12.11) + +Combining the analytic obstruction `Majorize.exists_perm_sum_mul_le` with the geometric +Hahn–Banach separation theorem yields the "hard" direction: a majorized vector `x` lies in the +(compact, convex) set of images `D *ᵥ y` of `y` under doubly stochastic matrices `D`. Together with +the easy direction (`Majorize.of_mem_doublyStochastic`) this gives the Hardy–Littlewood–Pólya +characterisation `Majorize x y ↔ ∃ D ∈ doublyStochastic ℝ ι, D *ᵥ y = x`, and — unwinding `D` into a +convex combination of permutation matrices via Birkhoff's theorem +(`exists_eq_sum_perm_of_mem_doublyStochastic`) — Nielsen–Chuang's Proposition 12.11 +`Majorize x y ↔ x = ∑ⱼ pⱼ Pⱼ y`. +-/ + +/-- **Hard direction of the representation theorem.** If `x` is majorized by `y`, then `x = D *ᵥ y` +for some doubly stochastic matrix `D`. + +The set `S = {D *ᵥ y | D ∈ doublyStochastic ℝ ι}` is the image of the doubly stochastic matrices +under the linear map `L : D ↦ D *ᵥ y`. It is convex (linear image of the convex set of doubly +stochastic matrices) and closed: by Birkhoff's theorem the doubly stochastic matrices are the convex +hull of the finitely many permutation matrices, so `S` is the convex hull of a finite set. Were +`x ∉ S`, `geometric_hahn_banach_closed_point` would give a continuous linear functional `f` with +`f a < u < f x` for all `a ∈ S`. Writing `c i := f (Pi.single i 1)`, we have +`f v = ∑ i, c i * v i`, +so for every permutation `σ` (as `σ.permMatrix ℝ *ᵥ y ∈ S`) this reads `∑ i, c i * y (σ i) < f x = +∑ i, c i * x i` — contradicting `Majorize.exists_perm_sum_mul_le`, which supplies a `σ` with +`∑ i, c i * x i ≤ ∑ i, c i * y (σ i)`. -/ +lemma Majorize.exists_doublyStochastic_mulVec [DecidableEq ι] {x y : ι → ℝ} (h : Majorize x y) : + ∃ D ∈ doublyStochastic ℝ ι, D *ᵥ y = x := by + classical + -- the linear map `D ↦ D *ᵥ y`, and the image `S` of the doubly stochastic matrices under it + let L : Matrix ι ι ℝ →ₗ[ℝ] (ι → ℝ) := + { toFun := fun D => D *ᵥ y + map_add' := fun A B => Matrix.add_mulVec A B y + map_smul' := fun a A => Matrix.smul_mulVec a A y } + set S : Set (ι → ℝ) := ⇑L '' ↑(doublyStochastic ℝ ι) with hSdef + suffices hxS : x ∈ S from hxS + by_contra hx + -- `S` is convex and closed + have hSconv : Convex ℝ S := convex_doublyStochastic.linear_image L + have hSclosed : IsClosed S := by + rw [hSdef, doublyStochastic_eq_convexHull_permMatrix, LinearMap.image_convexHull] + exact Set.Finite.isClosed_convexHull ℝ + (Set.Finite.image _ (Set.finite_range fun σ : Equiv.Perm ι => σ.permMatrix ℝ)) + -- separate `x` from `S` + obtain ⟨f, u, hfs, hfx⟩ := geometric_hahn_banach_closed_point hSconv hSclosed hx + -- represent `f` as a weighted coordinate sum with weights `c` + let c : ι → ℝ := fun i => f (Pi.single i 1 : ι → ℝ) + have hfrepr : ∀ v : ι → ℝ, f v = ∑ i, c i * v i := by + intro v + conv_lhs => rw [← Finset.univ_sum_single v] + rw [map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + have hsingle : Pi.single i (v i) = v i • (Pi.single i 1 : ι → ℝ) := by + ext j; simp [Pi.single_apply] + rw [hsingle, map_smul, smul_eq_mul, mul_comm] + -- the analytic obstruction contradicts the strict separation + obtain ⟨σ, hσ⟩ := h.exists_perm_sum_mul_le c + have hmem : (σ.permMatrix ℝ *ᵥ y) ∈ S := by + rw [hSdef]; exact ⟨σ.permMatrix ℝ, permMatrix_mem_doublyStochastic, rfl⟩ + have h1 : f (σ.permMatrix ℝ *ᵥ y) < u := hfs _ hmem + rw [hfrepr] at h1 hfx + simp only [Matrix.permMatrix_mulVec, Function.comp_apply] at h1 + linarith + +/-- **Hardy–Littlewood–Pólya characterisation.** `x` is majorized by `y` if and only if +`x = D *ᵥ y` for some doubly stochastic matrix `D`. The forward direction is +`Majorize.exists_doublyStochastic_mulVec`; the reverse is `Majorize.of_mem_doublyStochastic`. -/ +theorem majorize_iff_exists_doublyStochastic [DecidableEq ι] {x y : ι → ℝ} : + Majorize x y ↔ ∃ D ∈ doublyStochastic ℝ ι, D *ᵥ y = x := by + refine ⟨fun h => h.exists_doublyStochastic_mulVec, ?_⟩ + rintro ⟨D, hD, rfl⟩ + exact Majorize.of_mem_doublyStochastic hD y + +/-- **Nielsen–Chuang, Proposition 12.11.** `x` is majorized by `y` if and only if `x` is a convex +combination of permutations of `y`: there is a probability distribution `w` over permutations `σ` +with `x = ∑ σ, w σ • (σ.permMatrix ℝ *ᵥ y) = ∑ⱼ pⱼ Pⱼ y`. This packages the doubly stochastic +characterisation `majorize_iff_exists_doublyStochastic` with Birkhoff's theorem +(`exists_eq_sum_perm_of_mem_doublyStochastic`), which resolves a doubly stochastic `D` into such a +convex combination of permutation matrices. -/ +theorem majorize_iff_exists_sum_perm [DecidableEq ι] {x y : ι → ℝ} : + Majorize x y ↔ ∃ w : Equiv.Perm ι → ℝ, (∀ σ, 0 ≤ w σ) ∧ ∑ σ, w σ = 1 ∧ + x = ∑ σ : Equiv.Perm ι, w σ • (σ.permMatrix ℝ *ᵥ y) := by + constructor + · intro h + obtain ⟨D, hD, hDx⟩ := h.exists_doublyStochastic_mulVec + obtain ⟨w, hw, hw1, hwD⟩ := exists_eq_sum_perm_of_mem_doublyStochastic hD + refine ⟨w, hw, hw1, ?_⟩ + rw [← hDx, ← hwD, Matrix.sum_mulVec] + simp only [Matrix.smul_mulVec] + · rintro ⟨w, hw, hw1, rfl⟩ + exact majorize_sum_smul_permMatrix_mulVec y hw hw1 + +/-! +### The tail-sum characterisation (Nielsen–Chuang, Exercise 12.17) + +Exercise 12.17 characterises majorization through the *cut* (or *tail*) functions +`tailSum x t = ∑ⱼ max (xⱼ - t) 0`: `x ≺ y` iff `tailSum x t ≤ tailSum y t` for every threshold `t` +and the total sums agree. The functions `a ↦ max (a - t) 0` are a spanning family of convex +"angle" functions, so this is the instance of the Hardy–Littlewood–Pólya principle "`∑ φ(xⱼ) ≤ +∑ φ(yⱼ)` for all convex `φ`" carrying exactly enough information to recover majorization. + +The proof is a Legendre-type conjugacy between `tailSum` and `largestKSum`: +`largestKSum x k - k · t ≤ tailSum x t` always (`largestKSum_le_tailSum_add`), with equality at the +threshold `t = ` the `k`-th largest entry (`exists_tailSum_add_eq_largestKSum`, obtained from a +maximising `k`-subset by an exchange argument). Combined with the largest-`k`-sum form of +majorization (`majorize_iff_forall_largestKSum`) this yields both directions without any sorting. +-/ + +/-- `tailSum x t = ∑ i, max (x i - t) 0` is the *tail* (or *cut*) function of `x` at threshold `t`: +the sum of the positive parts of the shifted entries `x i - t`. As a function of `t` it is the +Legendre-type conjugate of `largestKSum x`; Nielsen–Chuang, Exercise 12.17 characterises +majorization through it. -/ +noncomputable def tailSum (x : ι → ℝ) (t : ℝ) : ℝ := ∑ i, max (x i - t) 0 + +/-- The tail function is the sum, over the entries strictly above the threshold, of the shifted +entries `x i - t`: the entries at or below `t` contribute a zero positive part. -/ +lemma tailSum_eq_sum_filter (x : ι → ℝ) (t : ℝ) : + tailSum x t = ∑ i ∈ univ.filter (fun i => t < x i), (x i - t) := by + rw [tailSum, Finset.sum_filter] + refine Finset.sum_congr rfl fun i _ => ?_ + by_cases h : t < x i + · rw [ite_eq_left h, max_eq_left (by linarith)] + · rw [ite_eq_right h, max_eq_right (by linarith [not_lt.mp h])] + +/-- The largest sum of `k` entries never exceeds `tailSum x t + k · t`: every `k`-subset sum +`∑ i ∈ s, x i = ∑ i ∈ s, (x i - t) + k · t` is bounded by `tailSum x t + k · t`, since each shifted +entry `x i - t` is at most its positive part `max (x i - t) 0` and these are nonnegative. This is +the "easy" half of the conjugacy between `largestKSum` and `tailSum`. -/ +lemma largestKSum_le_tailSum_add (x : ι → ℝ) (t : ℝ) {k : ℕ} (hk : k ≤ Fintype.card ι) : + largestKSum x k ≤ tailSum x t + k * t := by + refine largestKSum_le hk fun s hs => ?_ + have hle : ∑ i ∈ s, (x i - t) ≤ tailSum x t := by + rw [tailSum] + exact (Finset.sum_le_sum fun i _ => le_max_left _ _).trans + (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ s) fun i _ _ => le_max_right _ _) + have hsplit : ∑ i ∈ s, x i = ∑ i ∈ s, (x i - t) + s.card * t := by + rw [Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul]; ring + rw [hsplit, hs] + linarith + +omit [Fintype ι] in +/-- The largest sum of `0` entries is `0`: the empty subset is the only `0`-element subset. -/ +lemma largestKSum_zero [Finite ι] (x : ι → ℝ) : largestKSum x 0 = 0 := by + have : Nonempty {s : Finset ι // s.card = 0} := ⟨⟨∅, Finset.card_empty⟩⟩ + refine le_antisymm (ciSup_le fun s => ?_) ?_ + · rw [Finset.card_eq_zero.mp s.2]; simp + · simpa using sum_le_largestKSum x (∅ : Finset ι) + +/-- The largest sum of `k` entries is `0` once `k` exceeds the dimension, since no `k`-subset +exists. -/ +lemma largestKSum_eq_zero (x : ι → ℝ) {k : ℕ} (h : Fintype.card ι < k) : + largestKSum x k = 0 := by + have : IsEmpty {s : Finset ι // s.card = k} := ⟨fun s => by + have h1 : s.1.card ≤ Fintype.card ι := by simpa using Finset.card_le_card s.1.subset_univ + have h2 : s.1.card = k := s.2 + omega⟩ + exact Real.iSup_of_isEmpty _ + +/-- The largest sum of `k` entries is *attained*: when `k ≤ card ι` there is an actual +`k`-element subset whose entry-sum equals `largestKSum x k`. -/ +lemma largestKSum_attained (x : ι → ℝ) {k : ℕ} (hk : k ≤ Fintype.card ι) : + ∃ s : Finset ι, s.card = k ∧ largestKSum x k = ∑ i ∈ s, x i := by + classical + obtain ⟨t0, -, ht0⟩ := + Finset.exists_subset_card_eq (show k ≤ (univ : Finset ι).card by simpa using hk) + have : Nonempty {s : Finset ι // s.card = k} := ⟨t0, ht0⟩ + obtain ⟨s0, hs0max⟩ := + Finite.exists_max (fun s : {s : Finset ι // s.card = k} => ∑ i ∈ (s : Finset ι), x i) + exact ⟨s0, s0.2, le_antisymm (ciSup_le fun s => hs0max s) + (le_ciSup (bddAbove_range_subtype_sum x k) s0)⟩ + +/-- The conjugacy is *tight*: for `1 ≤ k ≤ card`, the bound +`largestKSum y k ≤ tailSum y t + k · t` is attained at the threshold `t = ` the `k`-th largest +entry of `y`. Concretely, take a maximising `k`-subset `S` (`largestKSum y k = ∑ i ∈ S, y i`) and +let `t` be its smallest entry `y i₀`; an exchange argument shows every entry outside `S` is `≤ t`, +so `tailSum y t` collapses to `∑ i ∈ S, (y i - t) = largestKSum y k - k · t`. -/ +lemma exists_tailSum_add_eq_largestKSum {y : ι → ℝ} {k : ℕ} + (hk1 : 1 ≤ k) (hk : k ≤ Fintype.card ι) : + ∃ t : ℝ, tailSum y t + k * t = largestKSum y k := by + classical + obtain ⟨S, hScard, hSsum⟩ := largestKSum_attained y hk + have hSne : S.Nonempty := by rw [← Finset.card_pos, hScard]; omega + obtain ⟨i0, hi0S, hi0min⟩ := S.exists_min_image y hSne + refine ⟨y i0, ?_⟩ + -- exchange: every entry outside the maximising set is at most the set's smallest entry `y i₀` + have hout : ∀ j, j ∉ S → y j ≤ y i0 := by + intro j hj + have hjE : j ∉ S.erase i0 := fun h => hj (Finset.mem_of_mem_erase h) + have hcard' : (insert j (S.erase i0)).card = k := by + rw [Finset.card_insert_of_notMem hjE, Finset.card_erase_of_mem hi0S, hScard]; omega + have hle : ∑ i ∈ insert j (S.erase i0), y i ≤ ∑ i ∈ S, y i := by + have hb := sum_le_largestKSum y (insert j (S.erase i0)) + rw [hcard', hSsum] at hb; exact hb + rw [Finset.sum_insert hjE] at hle + have hea := S.sum_erase_add y hi0S + linarith + -- evaluate the tail function at the threshold `t = y i₀` + have hzero : ∀ i ∈ (univ : Finset ι), i ∉ S → max (y i - y i0) 0 = 0 := + fun i _ hiS => max_eq_right (by linarith [hout i hiS]) + have htail : tailSum y (y i0) = ∑ i ∈ S, (y i - y i0) := by + rw [tailSum, ← Finset.sum_subset (Finset.subset_univ S) hzero] + exact Finset.sum_congr rfl fun i hi => max_eq_left (by linarith [hi0min i hi]) + rw [htail, hSsum, Finset.sum_sub_distrib, Finset.sum_const, hScard, nsmul_eq_mul]; ring + +/-- **Nielsen–Chuang, Exercise 12.17.** `x` is majorized by `y` if and only if the tail functions +are pointwise ordered, `tailSum x t ≤ tailSum y t` for every threshold `t`, together with equality +of the total sums. + +Forward: `a ↦ max (a - t) 0` is convex, so `tailSum x t = ∑ i ∈ S, (x i - t)` over the entries +above `t` is bounded, via `largestKSum x ≤ largestKSum y`, by `tailSum y t`. Reverse: for each `k` +the +tail hypothesis at the tight threshold `t` (`exists_tailSum_add_eq_largestKSum` for `y`) gives +`largestKSum x k ≤ tailSum x t + k · t ≤ tailSum y t + k · t = largestKSum y k`, which is the +largest-`k`-sum form of majorization. -/ +theorem majorize_iff_forall_tailSum {x y : ι → ℝ} : + Majorize x y ↔ (∀ t : ℝ, tailSum x t ≤ tailSum y t) ∧ ∑ i, x i = ∑ i, y i := by + constructor + · intro h + obtain ⟨hsum, hlarge⟩ := majorize_iff_forall_largestKSum.mp h + refine ⟨fun t => ?_, hsum⟩ + obtain ⟨s, hs_card, hxeq⟩ : ∃ s : Finset ι, s.card ≤ Fintype.card ι ∧ + tailSum x t = (∑ i ∈ s, x i) - s.card * t := by + refine ⟨univ.filter (fun i => t < x i), ?_, ?_⟩ + · rw [← Finset.card_univ]; exact Finset.card_le_card (Finset.subset_univ _) + · rw [tailSum_eq_sum_filter, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul] + have h1 : ∑ i ∈ s, x i ≤ largestKSum y s.card := + (sum_le_largestKSum x s).trans (hlarge s.card) + have h2 : largestKSum y s.card ≤ tailSum y t + s.card * t := + largestKSum_le_tailSum_add y t hs_card + rw [hxeq]; linarith + · rintro ⟨htail, hsum⟩ + rw [majorize_iff_forall_largestKSum] + refine ⟨hsum, fun k => ?_⟩ + rcases Nat.eq_zero_or_pos k with hk0 | hk0 + · subst hk0 + exact le_of_eq (by rw [largestKSum_zero x, largestKSum_zero y]) + · rcases le_or_gt k (Fintype.card ι) with hk | hk + · obtain ⟨t, ht⟩ := exists_tailSum_add_eq_largestKSum hk0 hk + calc largestKSum x k ≤ tailSum x t + k * t := largestKSum_le_tailSum_add x t hk + _ ≤ tailSum y t + k * t := by linarith [htail t] + _ = largestKSum y k := ht + · exact le_of_eq (by rw [largestKSum_eq_zero x hk, largestKSum_eq_zero y hk]) + +/-! +### The inductive step of Proposition 12.11 (Nielsen–Chuang, Exercise 12.19) + +Nielsen–Chuang prove the representation theorem `majorize_iff_exists_sum_perm` (Proposition 12.11) +by an induction on the dimension using *T-transforms*. In the inductive step one has decreasing +vectors `x y : Fin (n + 1) → ℝ` with `x ≺ y`, so in particular `x 0 ≤ y 0`; one picks a pivot index +`p ≠ 0` with `y p ≤ x 0 ≤ y (p - 1)` and a weight `t ∈ [0, 1]` with `x 0 = t * y 0 + (1 - t) * y p`, +and mixes entries `0` and `p` of `y` with the doubly stochastic combination `t • 1 + (1 - t) • T` +(`T` the transposition of `0` and `p`). The image `D y` then has `(D y) 0 = x 0`, and dropping the +leading coordinate of both vectors gives `x' = Fin.tail x` and `y' = Fin.tail (D y)`. Since `D` +changes only entry `p` of `y` (to `(1 - t) * y 0 + t * y p`) and the discarded entry `0`, +`y' = Fin.tail (Function.update y p ((1 - t) * y 0 + t * y p))`. Exercise 12.19 asks to verify +`x' ≺ y'`, which then feeds the inductive hypothesis. + +`majorize_tail_update_of_antitone` records this verification. The library establishes Proposition +12.11 itself by the equivalent separating-hyperplane route +(`Majorize.exists_doublyStochastic_mulVec`), so this lemma is not on that path; it is the faithful +formalisation of the exercise. +-/ + +/-- Reindexing lemma: a prefix sum of `Fin.tail f` — over the first `k` indices of `Fin n` — equals +the sum of `f` over the indices `1, …, k` of `Fin (n + 1)`, the successor map `i ↦ i.succ` being a +bijection between the two index sets. -/ +private lemma sum_prefix_filter_tail {n : ℕ} (f : Fin (n + 1) → ℝ) (k : ℕ) : + ∑ i ∈ univ.filter (fun i : Fin n => (i : ℕ) < k), Fin.tail f i + = ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), f i := by + refine Finset.sum_bij (fun (a : Fin n) (_ : a ∈ _) => a.succ) ?_ ?_ ?_ ?_ + · intro a ha + simp only [mem_filter, mem_univ, true_and, Fin.val_succ] at ha ⊢ + omega + · intro a₁ _ a₂ _ h + exact Fin.succ_injective n h + · intro b hb + simp only [mem_filter, mem_univ, true_and] at hb + have hb0 : b ≠ 0 := by rintro rfl; simp at hb + refine ⟨b.pred hb0, ?_, Fin.succ_pred b hb0⟩ + simp only [mem_filter, mem_univ, true_and, Fin.val_pred] + omega + · intro a _; rfl + +/-- For a decreasing `z : Fin (n + 1) → ℝ` and `k ≤ n`, the sum of `z` over the indices `1, …, k` +equals the largest-`(k+1)`-entry sum minus the leading entry `z 0`: since `z` is decreasing, its +`k + 1` largest entries are the leading block `0, …, k`; removing index `0` leaves `1, …, k`. -/ +private lemma sum_filter_one_le_eq_largestKSum_sub {n : ℕ} {z : Fin (n + 1) → ℝ} (hz : Antitone z) + {k : ℕ} (hk : k ≤ n) : + ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), z i + = largestKSum z (k + 1) - z 0 := by + rw [largestKSum_eq_sum_prefix_of_antitone hz (k + 1) (by omega)] + have hins : univ.filter (fun i : Fin (n + 1) => (i : ℕ) < k + 1) + = insert 0 (univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1)) := by + ext i + simp only [mem_filter, mem_univ, true_and, mem_insert] + constructor + · intro hi + rcases Nat.eq_zero_or_pos (i : ℕ) with h0 | h0 + · exact Or.inl (Fin.ext (by simpa using h0)) + · exact Or.inr ⟨h0, hi⟩ + · rintro (rfl | ⟨_, hi⟩) + · simp + · exact hi + rw [hins, Finset.sum_insert (by simp)] + ring + +/-- **Nielsen–Chuang, Exercise 12.19** (the inductive step of Proposition 12.11). Let +`x y : Fin (n + 1) → ℝ` be decreasing (`Antitone`) with `x` majorized by `y`. Fix a pivot `p ≠ 0` +with `y p ≤ x 0 ≤ y (p - 1)` and a weight `t ∈ [0, 1]` with `x 0 = t * y 0 + (1 - t) * y p`. Form +`y'` by replacing the `p`-th entry of `y` with the complementary convex combination +`(1 - t) * y 0 + t * y p` and dropping the leading coordinate, and drop the leading coordinate of +`x` to form `x'`. Then `x'` is majorized by `y'`. + +N&C's inductive step additionally assumes `0 ≤ t ≤ 1` and `y p ≤ x 0`, which make the replacement a +genuine convex combination (keeping `y'` a doubly stochastic image of `y` for the surrounding +induction). Those bounds are not needed for `x' ≺ y'` — only `x 0 ≤ y (p - 1)`, together with the +orderings and `x ≺ y`, is used — so they are dropped here for a minimal statement; the lemma then +covers N&C's case a fortiori. -/ +theorem majorize_tail_update_of_antitone {n : ℕ} {x y : Fin (n + 1) → ℝ} (hx : Antitone x) + (hy : Antitone y) (hxy : Majorize x y) {p : Fin (n + 1)} (hp : p ≠ 0) {t : ℝ} + (hhi : x 0 ≤ y (p - 1)) (hx0 : x 0 = t * y 0 + (1 - t) * y p) : + Majorize (Fin.tail x) (Fin.tail (Function.update y p ((1 - t) * y 0 + t * y p))) := by + classical + set w : ℝ := (1 - t) * y 0 + t * y p with hw + set yD : Fin (n + 1) → ℝ := Function.update y p w with hyD + -- algebraic identity relating the mixed entry `w` to the pivot data + have hwx : w + x 0 = y 0 + y p := by rw [hw, hx0]; ring + -- the pivot index is positive + have hp_pos : 0 < (p : ℕ) := by + rcases Nat.eq_zero_or_pos (p : ℕ) with h | h + · exact absurd (Fin.ext (by simpa using h)) hp + · exact h + -- `x' = Fin.tail x` is decreasing + have hxtail : Antitone (Fin.tail x) := by + intro a b hab + have hsucc : a.succ ≤ b.succ := by + simp only [Fin.le_def, Fin.val_succ] at hab ⊢; omega + exact hx hsucc + -- the leading entry of `yD` is unchanged + have hyD0 : yD 0 = y 0 := by rw [hyD]; exact Function.update_of_ne (Ne.symm hp) _ _ + -- equal total sums for `x'` and `y'` + have hsum : ∑ i, Fin.tail x i = ∑ i, Fin.tail yD i := by + have hAx : ∑ i, x i = x 0 + ∑ i, Fin.tail x i := Fin.sum_univ_succ x + have hAy : ∑ i, yD i = yD 0 + ∑ i, Fin.tail yD i := Fin.sum_univ_succ yD + have hD : ∑ i, yD i = w + ((∑ i, y i) - y p) := by + rw [hyD, Finset.sum_update_of_mem (mem_univ p) y w, + Finset.sum_sdiff_eq_sub (Finset.subset_univ _), Finset.sum_singleton] + have hE : ∑ i, x i = ∑ i, y i := hxy.sum_eq + linarith [hAx, hAy, hyD0, hD, hE, hwx] + -- majorization via the largest-`k`-sum characterisation + rw [majorize_iff_forall_largestKSum] + refine ⟨hsum, fun k => ?_⟩ + rcases Nat.eq_zero_or_pos k with hk0 | hk0 + · exact le_of_eq (by rw [hk0, largestKSum_zero, largestKSum_zero]) + rcases le_or_gt k n with hk | hk + · -- the substantive range `1 ≤ k ≤ n` + have hcardP : (univ.filter (fun i : Fin n => (i : ℕ) < k)).card = k := card_filter_lt k hk + -- the core inequality over the index block `1, …, k` of `Fin (n + 1)` + have hcore : + ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), x i + ≤ ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), yD i := by + by_cases hpin : p ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1) + · -- Case A: the pivot lies in the block + have hAsum : + ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), yD i + = w + ((∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), y i) + - y p) := by + rw [hyD, Finset.sum_update_of_mem hpin y w, + Finset.sum_sdiff_eq_sub (Finset.singleton_subset_iff.mpr hpin), Finset.sum_singleton] + have hQx := sum_filter_one_le_eq_largestKSum_sub hx hk + have hQy := sum_filter_one_le_eq_largestKSum_sub hy hk + have hmaj : largestKSum x (k + 1) ≤ largestKSum y (k + 1) := + (majorize_iff_forall_largestKSum.mp hxy).2 (k + 1) + rw [hAsum, hQx, hQy]; linarith [hwx] + · -- Case B: the pivot lies beyond the block, so entries are unchanged there + have hpk : k + 1 ≤ (p : ℕ) := by + by_contra hcon + exact hpin (by simp only [mem_filter, mem_univ, true_and]; omega) + have hBsum : + ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), yD i + = ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), y i := by + rw [hyD]; refine Finset.sum_congr rfl fun i hi => ?_ + exact Function.update_of_ne (by rintro rfl; exact hpin hi) _ _ + rw [hBsum] + refine Finset.sum_le_sum fun i hi => ?_ + simp only [mem_filter, mem_univ, true_and] at hi + have hi_le : (i : ℕ) ≤ ((p - 1 : Fin (n + 1)) : ℕ) := by + rw [Fin.coe_sub_one, ite_eq_right hp]; omega + calc x i ≤ x 0 := hx (Fin.zero_le i) + _ ≤ y (p - 1) := hhi + _ ≤ y i := hy (Fin.le_def.mpr hi_le) + calc largestKSum (Fin.tail x) k + = ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), x i := by + rw [largestKSum_eq_sum_prefix_of_antitone hxtail k hk]; exact sum_prefix_filter_tail x k + _ ≤ ∑ i ∈ univ.filter (fun i : Fin (n + 1) => 0 < (i : ℕ) ∧ (i : ℕ) < k + 1), yD i := hcore + _ = ∑ i ∈ univ.filter (fun i : Fin n => (i : ℕ) < k), Fin.tail yD i := + (sum_prefix_filter_tail yD k).symm + _ ≤ largestKSum (Fin.tail yD) k := by + have h := sum_le_largestKSum (Fin.tail yD) (univ.filter (fun i : Fin n => (i : ℕ) < k)) + rwa [hcardP] at h + · -- `k > n`: both largest sums vanish (no `k`-subset of `Fin n`) + have hcard : Fintype.card (Fin n) < k := by rw [Fintype.card_fin]; exact hk + exact le_of_eq (by rw [largestKSum_eq_zero (Fin.tail x) hcard, + largestKSum_eq_zero (Fin.tail yD) hcard]) diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Convex/SierpinskiMidpoint.lean b/LeanPool/AxQM/ToMathlib/Analysis/Convex/SierpinskiMidpoint.lean new file mode 100644 index 0000000000..908e2f3a04 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Convex/SierpinskiMidpoint.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Convex.Topology +public import Mathlib.LinearAlgebra.AffineSpace.Midpoint +public import Mathlib.Topology.Algebra.Affine +public import Mathlib.Topology.MetricSpace.Basic +public import Mathlib.Analysis.SpecificLimits.Basic +public import Mathlib.Algebra.CharP.Invertible +import Mathlib.Tactic.IntervalCases + +/-! +# Sierpinski's midpoint-convex theorem (set version) + +A closed subset of a real topological vector space that is closed under midpoints is convex. +This is the set version of Sierpinski's classical theorem; the proof proceeds by dyadic-rational +approximation in `[0, 1]`. + +## Main results + +* `Convex.of_isClosed_of_midpoint_mem` — closed + midpoint-stable ⇒ convex. +-/ + +@[expose] public section + +open Set + +/-- The dyadic combinations of `0` and `1` lie in any midpoint-stable subset of `ℝ` containing +both endpoints: `(k : ℝ) / 2^n ∈ T` for every `k ≤ 2^n`. -/ +private lemma div_pow_two_mem_of_midpoint_mem {T : Set ℝ} + (h0 : (0 : ℝ) ∈ T) (h1 : (1 : ℝ) ∈ T) + (h_mid : ∀ ⦃u⦄, u ∈ T → ∀ ⦃v⦄, v ∈ T → midpoint ℝ u v ∈ T) : + ∀ (n k : ℕ), k ≤ 2 ^ n → ((k : ℝ) / 2 ^ n) ∈ T := by + intro n + induction n with + | zero => intro k hk; interval_cases k <;> simpa + | succ n ih => + intro k hk + rcases Nat.even_or_odd' k with ⟨j, rfl | rfl⟩ + · have : ((2 * j : ℕ) : ℝ) / 2 ^ (n + 1) = (j : ℝ) / 2 ^ n := by + push_cast; field_simp; ring + rw [this]; exact ih j (by rw [pow_succ] at hk; omega) + · have : ((2 * j + 1 : ℕ) : ℝ) / 2 ^ (n + 1) = + midpoint ℝ ((j : ℝ) / 2 ^ n) ((j + 1 : ℕ) / 2 ^ n) := by + rw [midpoint_eq_smul_add, smul_eq_mul, invOf_eq_inv] + push_cast; field_simp; ring + rw [pow_succ] at hk + rw [this]; exact h_mid (ih j (by omega)) (ih (j + 1) (by omega)) + +/-- The dyadic approximation `⌊t · 2^n⌋ / 2^n` of a nonneg real is within `1 / 2^n` of `t`. -/ +private lemma abs_sub_floor_div_pow_two_le (t : ℝ) (ht : 0 ≤ t) (n : ℕ) : + |t - (⌊t * 2 ^ n⌋₊ : ℝ) / 2 ^ n| ≤ 1 / 2 ^ n := by + have h2pos : (0 : ℝ) < 2 ^ n := by positivity + have hlb : (⌊t * 2 ^ n⌋₊ : ℝ) / 2 ^ n ≤ t := + (div_le_iff₀ h2pos).mpr (Nat.floor_le (mul_nonneg ht h2pos.le)) + have hub : t < ((⌊t * 2 ^ n⌋₊ : ℝ) + 1) / 2 ^ n := + (lt_div_iff₀ h2pos).mpr (Nat.lt_floor_add_one _) + have hgap : ((⌊t * 2 ^ n⌋₊ : ℝ) + 1) / 2 ^ n - (⌊t * 2 ^ n⌋₊ : ℝ) / 2 ^ n = 1 / 2 ^ n := by ring + rw [abs_le]; constructor <;> linarith + +/-- A closed subset of `ℝ` containing `0` and `1` and closed under midpoints contains `[0, 1]`. +This is the one-dimensional set version of Sierpinski's theorem, the inductive core of +`Convex.of_isClosed_of_midpoint_mem`. -/ +private lemma Icc_zero_one_subset_of_isClosed_of_midpoint_mem {T : Set ℝ} + (hT : IsClosed T) (h0 : (0 : ℝ) ∈ T) (h1 : (1 : ℝ) ∈ T) + (h_mid : ∀ ⦃u⦄, u ∈ T → ∀ ⦃v⦄, v ∈ T → midpoint ℝ u v ∈ T) : + Set.Icc (0 : ℝ) 1 ⊆ T := fun t ht ↦ by + refine (Metric.mem_of_closed' hT).mpr fun ε hε ↦ ?_ + obtain ⟨n, hn⟩ := exists_pow_lt_of_lt_one hε (by norm_num : (1 / 2 : ℝ) < 1) + have h2pos : (0 : ℝ) < 2 ^ n := by positivity + have hk_le : ⌊t * 2 ^ n⌋₊ ≤ 2 ^ n := + Nat.floor_le_of_le (by simpa using mul_le_mul_of_nonneg_right ht.2 h2pos.le) + have hpow : (1 / 2 : ℝ) ^ n = 1 / 2 ^ n := by rw [div_pow]; simp + refine ⟨(⌊t * 2 ^ n⌋₊ : ℝ) / 2 ^ n, + div_pow_two_mem_of_midpoint_mem h0 h1 h_mid n _ hk_le, ?_⟩ + rw [Real.dist_eq] + exact (abs_sub_floor_div_pow_two_le t ht.1 n).trans_lt (by linarith [hpow ▸ hn]) + +variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] + [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] + +/-- **Sierpinski's theorem (set version)**: a closed subset of a real topological vector space +that is closed under midpoints is convex. The dyadic-rational density of `[0, 1]` plus +topological closedness upgrades pairwise-midpoint stability to full convex-combination +closedness. -/ +theorem Convex.of_isClosed_of_midpoint_mem {s : Set E} (hs : IsClosed s) + (h_mid : ∀ ⦃u⦄, u ∈ s → ∀ ⦃v⦄, v ∈ s → midpoint ℝ u v ∈ s) : Convex ℝ s := by + intro x hx y hy a b ha hb hab + have hb_in : (AffineMap.lineMap x y : ℝ →ᵃ[ℝ] E) b ∈ s := by + refine Icc_zero_one_subset_of_isClosed_of_midpoint_mem + (hs.preimage AffineMap.lineMap_continuous) + (by simpa using hx) (by simpa using hy) + (fun u hu v hv ↦ ?_) ⟨hb, by linarith⟩ + rw [Set.mem_preimage, AffineMap.map_midpoint] + exact h_mid hu hv + rwa [AffineMap.lineMap_apply_module, show 1 - b = a from by linarith] at hb_in diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Convex/SupportReduction.lean b/LeanPool/AxQM/ToMathlib/Analysis/Convex/SupportReduction.lean new file mode 100644 index 0000000000..70e20e3b08 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Convex/SupportReduction.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Dimension.Finite +public import Mathlib.LinearAlgebra.LinearIndependent.Defs +public import Mathlib.Data.Finset.Max +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.Linarith + +/-! +# Support reduction of a nonnegative combination minimizing a linear objective + +Let `V` be a finite-dimensional real vector space and `v : ι → V` a finite family of points all +lying on the affine hyperplane `{x | φ x = 1}` for a fixed linear functional `φ : V →ₗ[ℝ] ℝ` (think +of `V` as the self-adjoint operators, `φ` the trace, and each `v i` a rank-one projection +`|ψᵢ⟩⟨ψᵢ|`). Given nonnegative weights `w : ι → ℝ` and an auxiliary linear objective +`∑ i, w i * t i`, one can always replace `w` by nonnegative weights `w'` with the **same** weighted +barycenter `∑ i, w' i • v i`, the **same** total weight `∑ i, w' i`, an objective +`∑ i, w' i * t i` that is **no larger**, and support of size at most `finrank ℝ V`. + +This is the constructive core of Carathéodory's theorem refined to *simultaneously* minimize a +linear objective (the refinement usually attributed to Fenchel–Eggleston, phrased here for a fixed +hyperplane rather than via boundary points). Because the points lie on `{φ = 1}`, a linear +dependence among more than `finrank ℝ V` of them automatically has coefficients summing to zero +(apply `φ`), so one point can be eliminated while preserving *both* the barycenter and the total +weight; the sign of the elimination direction is chosen to keep the objective from increasing. +Iterating removes points until at most `finrank ℝ V` remain. In the quantum-information application +this yields the `d²` bound on the number of pure states needed to attain the Holevo χ of a channel +(Nielsen & Chuang, Exercise 12.11). + +## Main statement + +* `exists_reduced_weights_le_finrank`: the reduction described above. +-/ + +public section + +open Finset + +variable {V : Type*} [AddCommGroup V] [Module ℝ V] +variable {ι : Type*} [Fintype ι] + +/-- One elimination step for `exists_reduced_weights_le_finrank`: given a nontrivial affine +dependence `c` (coefficients summing to zero, weighted `v`-sum zero) supported inside the support of +`w`, with a strictly negative coefficient and a non-increasing effect on the objective +(`∑ i, c i * t i ≤ 0`), moving `w` along `c` until a weight vanishes yields nonnegative weights with +the same barycenter and total, an objective no larger, and strictly smaller support. -/ +private lemma reduceWeights_step {v : ι → V} (t : ι → ℝ) {w : ι → ℝ} (hw : ∀ i, 0 ≤ w i) + {c : ι → ℝ} (hcv : ∑ i, c i • v i = 0) (hcsum : ∑ i, c i = 0) + (hcsupp : ∀ i, c i ≠ 0 → w i ≠ 0) (hneg : ∃ i, c i < 0) (hobj : ∑ i, c i * t i ≤ 0) : + ∃ w' : ι → ℝ, (∀ i, 0 ≤ w' i) ∧ (∑ i, w' i • v i = ∑ i, w i • v i) ∧ + (∑ i, w' i = ∑ i, w i) ∧ (∑ i, w' i * t i ≤ ∑ i, w i * t i) ∧ + (univ.filter fun i => w' i ≠ 0).card < (univ.filter fun i => w i ≠ 0).card := by + classical + set N := univ.filter (fun i => c i < 0) with hN + have hNne : N.Nonempty := by + obtain ⟨i, hi⟩ := hneg; exact ⟨i, mem_filter.2 ⟨mem_univ i, hi⟩⟩ + obtain ⟨i₁, hi₁N, hi₁min⟩ := Finset.exists_min_image N (fun i => w i / (-c i)) hNne + have hci₁ : c i₁ < 0 := (mem_filter.1 hi₁N).2 + have hwi₁ : 0 < w i₁ := (hw i₁).lt_of_ne (Ne.symm (hcsupp i₁ (ne_of_lt hci₁))) + set θ := w i₁ / (-c i₁) with hθ + have hθpos : 0 < θ := by rw [hθ]; exact div_pos hwi₁ (neg_pos.2 hci₁) + set w' : ι → ℝ := fun i => w i + θ * c i with hw' + -- the freed coordinate `i₁` is zeroed out + have hw'i₁ : w' i₁ = 0 := by + have hnc0 : -c i₁ ≠ 0 := neg_ne_zero.2 (ne_of_lt hci₁) + have hkey : θ * c i₁ = -w i₁ := by rw [hθ, div_mul_eq_mul_div, div_eq_iff hnc0]; ring + simp only [hw']; rw [hkey]; ring + -- the new weights are nonnegative + have hnonneg : ∀ i, 0 ≤ w' i := by + intro i + by_cases hci : 0 ≤ c i + · have : 0 ≤ θ * c i := mul_nonneg hθpos.le hci + simp only [hw']; linarith [hw i] + · rw [not_le] at hci + have hiN : i ∈ N := mem_filter.2 ⟨mem_univ i, hci⟩ + have hri : θ ≤ w i / (-c i) := hi₁min i hiN + have hpos : (0 : ℝ) < -c i := neg_pos.2 hci + have hmul : θ * (-c i) ≤ w i := by + have h := mul_le_mul_of_nonneg_right hri hpos.le + rwa [div_mul_cancel₀ (w i) hpos.ne'] at h + have hid : θ * c i = -(θ * (-c i)) := by ring + simp only [hw']; linarith [hmul, hid] + -- the barycenter is unchanged + have hbary : ∑ i, w' i • v i = ∑ i, w i • v i := by + simp only [hw', add_smul, mul_smul] + rw [Finset.sum_add_distrib, ← Finset.smul_sum, hcv, smul_zero, add_zero] + -- the total weight is unchanged + have htot : ∑ i, w' i = ∑ i, w i := by + simp only [hw'] + rw [Finset.sum_add_distrib, ← Finset.mul_sum, hcsum, mul_zero, add_zero] + -- the objective does not increase + have hobj' : ∑ i, w' i * t i ≤ ∑ i, w i * t i := by + have heq : ∑ i, w' i * t i = ∑ i, w i * t i + θ * ∑ i, c i * t i := by + simp only [hw', add_mul, mul_assoc] + rw [Finset.sum_add_distrib, ← Finset.mul_sum] + have hprod : θ * ∑ i, c i * t i ≤ 0 := by + nlinarith [mul_nonneg hθpos.le (neg_nonneg.2 hobj)] + rw [heq]; linarith + -- the support strictly shrinks: it lies inside the old support and loses `i₁` + have hsub : (univ.filter fun i => w' i ≠ 0) ⊆ (univ.filter fun i => w i ≠ 0) := by + intro i hi + rw [mem_filter] at hi ⊢ + refine ⟨mem_univ i, ?_⟩ + intro hwi + apply hi.2 + have hci : c i = 0 := by by_contra hcine; exact hcsupp i hcine hwi + simp only [hw', hwi, hci, mul_zero, add_zero] + have hi₁mem : i₁ ∈ (univ.filter fun i => w i ≠ 0) := mem_filter.2 ⟨mem_univ i₁, ne_of_gt hwi₁⟩ + have hi₁nmem : i₁ ∉ (univ.filter fun i => w' i ≠ 0) := by + simp only [mem_filter, mem_univ, true_and, not_not]; exact hw'i₁ + exact ⟨w', hnonneg, hbary, htot, hobj', + Finset.card_lt_card ((Finset.ssubset_iff_of_subset hsub).2 ⟨i₁, hi₁mem, hi₁nmem⟩)⟩ + +/-- **Support reduction minimizing a linear objective** (a hyperplane-refined Carathéodory theorem). +Let `V` be a finite-dimensional real vector space, `φ : V →ₗ[ℝ] ℝ` a linear functional, and +`v : ι → V` a finite family of points all lying on the affine hyperplane `{x | φ x = 1}` +(`hv : ∀ i, φ (v i) = 1`). For nonnegative weights `w` and any `t : ι → ℝ`, there are nonnegative +weights `w'` with the same weighted barycenter `∑ i, w' i • v i`, the same total `∑ i, w' i`, an +objective `∑ i, w' i * t i` no larger than `∑ i, w i * t i`, and support — realized as a finite set +`s` with `w' i ≠ 0 ↔ i ∈ s` — of cardinality at most `finrank ℝ V` (the bound is on the actual +support; the `↔` keeps the statement free of a decidability instance). + +Applied to the self-adjoint operators with `φ` the trace and `v i = |ψᵢ⟩⟨ψᵢ|` rank-one projections, +this is the convex-geometry heart of the `d²` bound on the ensemble size attaining a channel's +Holevo χ quantity (Nielsen & Chuang, Exercise 12.11). -/ +theorem exists_reduced_weights_le_finrank [Module.Finite ℝ V] (φ : V →ₗ[ℝ] ℝ) {v : ι → V} + (hv : ∀ i, φ (v i) = 1) (t : ι → ℝ) {w : ι → ℝ} (hw : ∀ i, 0 ≤ w i) : + ∃ w' : ι → ℝ, (∀ i, 0 ≤ w' i) ∧ (∑ i, w' i • v i = ∑ i, w i • v i) ∧ + (∑ i, w' i = ∑ i, w i) ∧ (∑ i, w' i * t i ≤ ∑ i, w i * t i) ∧ + ∃ s : Finset ι, (∀ i, w' i ≠ 0 ↔ i ∈ s) ∧ s.card ≤ Module.finrank ℝ V := by + classical + -- induct on a cardinality bound for the support of `w` + suffices H : ∀ N : ℕ, ∀ w : ι → ℝ, (∀ i, 0 ≤ w i) → + (univ.filter fun i => w i ≠ 0).card ≤ N → + ∃ w' : ι → ℝ, (∀ i, 0 ≤ w' i) ∧ (∑ i, w' i • v i = ∑ i, w i • v i) ∧ + (∑ i, w' i = ∑ i, w i) ∧ (∑ i, w' i * t i ≤ ∑ i, w i * t i) ∧ + (univ.filter fun i => w' i ≠ 0).card ≤ Module.finrank ℝ V by + obtain ⟨w', h1, h2, h3, h4, h5⟩ := H _ w hw le_rfl + exact ⟨w', h1, h2, h3, h4, univ.filter (fun i => w' i ≠ 0), + fun i => ⟨fun hi => mem_filter.2 ⟨mem_univ i, hi⟩, fun hi => (mem_filter.1 hi).2⟩, h5⟩ + intro N + induction N with + | zero => + intro w hw hcard + exact ⟨w, hw, rfl, rfl, le_rfl, le_trans hcard (Nat.zero_le _)⟩ + | succ N ih => + intro w hw hcard + by_cases hle : (univ.filter fun i => w i ≠ 0).card ≤ Module.finrank ℝ V + · exact ⟨w, hw, rfl, rfl, le_rfl, hle⟩ + · rw [not_le] at hle + set s := univ.filter (fun i => w i ≠ 0) with hs + -- more than `finrank` of the `v i` over the support are linearly dependent + have hdep : ¬ LinearIndependent ℝ (fun i : s => v i) := by + intro hli + have hcard2 : Fintype.card (s : Type _) ≤ Module.finrank ℝ V := hli.fintype_card_le_finrank + rw [Fintype.card_coe] at hcard2 + exact absurd hcard2 (not_le.2 hle) + rw [Fintype.not_linearIndependent_iff] at hdep + obtain ⟨g, hg0, i₀, hgi₀⟩ := hdep + -- extend the dependence by zero outside the support + set c : ι → ℝ := fun i => if h : i ∈ s then g ⟨i, h⟩ else 0 with hc + have hgc : ∀ i : s, g i • v ↑i = c ↑i • v ↑i := fun i => by + simp only [hc, dite_eq_left i.2, Subtype.coe_eta] + have hcsupp : ∀ i, c i ≠ 0 → w i ≠ 0 := by + intro i hci hwi + have hins : i ∉ s := by + simp only [hs, mem_filter, mem_univ, true_and, not_not]; exact hwi + exact hci (by simp only [hc, dite_eq_right hins]) + have hcv : ∑ i, c i • v i = 0 := by + have e1 : ∑ i, c i • v i = ∑ i ∈ s, c i • v i := by + refine (Finset.sum_subset (subset_univ s) ?_).symm + intro i _ hnotin + simp only [hc, dite_eq_right hnotin, zero_smul] + rw [e1, ← Finset.sum_coe_sort s (fun i => c i • v i), ← hg0] + exact Finset.sum_congr rfl fun i _ => (hgc i).symm + have hcsum : ∑ i, c i = 0 := by + have key : ∑ i, c i = φ (∑ i, c i • v i) := by + rw [map_sum] + exact Finset.sum_congr rfl fun i _ => by rw [map_smul, hv i, smul_eq_mul, mul_one] + rw [key, hcv, map_zero] + have hcne : ∃ i, c i ≠ 0 := + ⟨↑i₀, by simp only [hc, dite_eq_left i₀.2, Subtype.coe_eta]; exact hgi₀⟩ + -- from `∑ c = 0` and `c ≠ 0`, coefficients of both signs occur + have hcneg : ∃ i, c i < 0 := by + by_contra h; rw [not_exists] at h + obtain ⟨j, hj⟩ := hcne + have hnn : ∀ i, 0 ≤ c i := fun i => not_lt.1 (h i) + exact hj ((Finset.sum_eq_zero_iff_of_nonneg fun i _ => hnn i).1 hcsum j (mem_univ j)) + have hcpos : ∃ i, 0 < c i := by + by_contra h; rw [not_exists] at h + obtain ⟨j, hj⟩ := hcne + have hnp : ∀ i, c i ≤ 0 := fun i => not_lt.1 (h i) + have hsum' : ∑ i, -c i = 0 := by rw [Finset.sum_neg_distrib, hcsum, neg_zero] + have hz := (Finset.sum_eq_zero_iff_of_nonneg fun i _ => neg_nonneg.2 (hnp i)).1 hsum' j + (mem_univ j) + exact hj (by linarith [hz]) + -- choose the elimination direction so that the objective does not increase + by_cases hobjle : ∑ i, c i * t i ≤ 0 + · obtain ⟨w'', h1, h2, h3, h4, h5⟩ := reduceWeights_step t hw hcv hcsum hcsupp hcneg hobjle + rw [← hs] at h5 + obtain ⟨w', k1, k2, k3, k4, k5⟩ := ih w'' h1 (Nat.lt_succ_iff.mp (lt_of_lt_of_le h5 hcard)) + exact ⟨w', k1, k2.trans h2, k3.trans h3, k4.trans h4, k5⟩ + · rw [not_le] at hobjle + have hcv' : ∑ i, (-c i) • v i = 0 := by + simp only [neg_smul, Finset.sum_neg_distrib, hcv, neg_zero] + have hcsum' : ∑ i, -c i = 0 := by rw [Finset.sum_neg_distrib, hcsum, neg_zero] + have hcsupp' : ∀ i, -c i ≠ 0 → w i ≠ 0 := fun i hi => hcsupp i (neg_ne_zero.mp hi) + have hcneg' : ∃ i, -c i < 0 := by obtain ⟨i, hi⟩ := hcpos; exact ⟨i, by linarith⟩ + have hobjle' : ∑ i, (-c i) * t i ≤ 0 := by + have h : ∑ i, (-c i) * t i = -(∑ i, c i * t i) := by + simp only [neg_mul, Finset.sum_neg_distrib] + rw [h]; linarith + obtain ⟨w'', h1, h2, h3, h4, h5⟩ := + reduceWeights_step t hw hcv' hcsum' hcsupp' hcneg' hobjle' + rw [← hs] at h5 + obtain ⟨w', k1, k2, k3, k4, k5⟩ := ih w'' h1 (Nat.lt_succ_iff.mp (lt_of_lt_of_le h5 hcard)) + exact ⟨w', k1, k2.trans h2, k3.trans h3, k4.trans h4, k5⟩ diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Adjoint.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Adjoint.lean new file mode 100644 index 0000000000..6b39809c51 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Adjoint.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# Additions to `LinearMap.adjoint` / `ContinuousLinearMap.adjoint` + +New lemmas about adjoints and star projections: a partial-isometry criterion for +`U† ∘L U` to be a star projection, a self-projection identity for rank-one operators, +a CLM-input form of the `LinearMap.adjoint`/`ContinuousLinearMap.adjoint` bridge, a +scaling law for the Gram operator, the range/kernel-orthogonal-complement dual of +`LinearMap.orthogonal_ker` for symmetric operators, conjugation by a (possibly +non-surjective) isometry as a non-unital star homomorphism, and transport lemmas for +`LinearIsometryEquiv.conjStarAlgEquiv`. +-/ + +@[expose] public section + +noncomputable section + +open Module RCLike InnerProductSpace +open scoped ComplexConjugate + +variable {𝕜 E F : Type*} [RCLike 𝕜] +variable [NormedAddCommGroup E] [NormedAddCommGroup F] +variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] + +namespace ContinuousLinearMap + +variable [CompleteSpace E] [CompleteSpace F] + +/-- The "initial-space projection" of a partial isometry: for `U : E →L[𝕜] F` satisfying +the partial-isometry equation `U U† U = U`, the endomorphism `U† ∘ U : E →L[𝕜] E` is a +star projection (idempotent and self-adjoint). The dual statement (`U U† : F →L[𝕜] F` is a +star projection, the "final-space projection") follows by applying this lemma to `U†`. -/ +theorem isStarProjection_adjoint_comp_self_of_partialIsometry + {U : E →L[𝕜] F} (hU : U ∘L U.adjoint ∘L U = U) : + IsStarProjection (U.adjoint ∘L U) where + isIdempotentElem := + calc (U.adjoint ∘L U) * (U.adjoint ∘L U) + = U.adjoint ∘L (U ∘L U.adjoint ∘L U) := by + simp [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_assoc] + _ = U.adjoint ∘L U := by rw [hU] + isSelfAdjoint := by + rw [isSelfAdjoint_iff, star_eq_adjoint, adjoint_comp, adjoint_adjoint] + +/-- A rank-one self-projector is its own measurement effect: for a unit vector `x`, +`(rankOne x x)† ∘ (rankOne x x) = rankOne x x`. -/ +theorem _root_.InnerProductSpace.adjoint_rankOne_comp_self {x : E} (hx : ‖x‖ = 1) : + adjoint (rankOne 𝕜 x x) ∘L rankOne 𝕜 x x = rankOne 𝕜 x x := by + rw [adjoint_rankOne] + exact (isStarProjection_rankOne_self hx).isIdempotentElem + +/-- **Conjugation by an isometry as a non-unital star-algebra homomorphism.** For `V : E →L[𝕜] F` +with `V† ∘L V = 1` (an isometry, possibly non-surjective), the map `A ↦ V ∘L A ∘L V†` is a +non-unital `⋆`-algebra homomorphism `(E →L[𝕜] E) →⋆ₙₐ[𝕜] (F →L[𝕜] F)`. Multiplicativity +`V (A B) V† = (V A V†)(V B V†)` consumes `V† V = 1`; it is *non*-unital precisely because +`V V† ≠ 1` for non-surjective `V`. The non-surjective analogue of +`LinearIsometryEquiv.conjStarAlgEquiv`; the vehicle for transporting the continuous functional +calculus across `V` (`cfc_conj_isometry`). -/ +noncomputable def conjIsometryₙ {V : E →L[𝕜] F} (hV : V.adjoint ∘L V = 1) : + (E →L[𝕜] E) →⋆ₙₐ[𝕜] (F →L[𝕜] F) where + toFun A := V ∘L A ∘L V.adjoint + map_add' A B := by simp [comp_add, add_comp] + map_zero' := by simp + map_smul' c A := by simp + map_mul' A B := by + ext x + simp only [mul_def, comp_apply] + rw [← comp_apply V.adjoint V, hV, one_apply_eq_self] + map_star' A := by + simp only [star_eq_adjoint, adjoint_comp, adjoint_adjoint, comp_assoc] + +@[simp] +theorem conjIsometryₙ_apply {V : E →L[𝕜] F} (hV : V.adjoint ∘L V = 1) (A : E →L[𝕜] E) : + conjIsometryₙ hV A = V ∘L A ∘L V.adjoint := rfl + +end ContinuousLinearMap + +namespace LinearMap + +variable [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + +/-- The CLM-input form of the `LinearMap.adjoint` / `ContinuousLinearMap.adjoint` bridge: the +linear-map coercion of the adjoint of a continuous linear map `T` is the adjoint of its linear-map +coercion. Upstream's `ContinuousLinearMap.adjoint_toLinearMap` states the other orientation and +derives completeness from finite-dimensionality inside the statement; this version takes +`[CompleteSpace E] [CompleteSpace F]` as instance arguments, so it applies with whichever +completeness instances are in scope. -/ +theorem _root_.ContinuousLinearMap.adjoint_toLinearMap_of_completeSpace [CompleteSpace E] + [CompleteSpace F] (T : E →L[𝕜] F) : + (T.adjoint : F →L[𝕜] E).toLinearMap = LinearMap.adjoint T.toLinearMap := + rfl + +/-- The Gram operator scales by the squared norm under scalar multiplication of the operator: +`(c • T)† ∘ₗ (c • T) = ‖c‖² • (T† ∘ₗ T)`. The two scalar factors `c` and `conj c` combine to +`‖c‖²` via the C*-identity `conj c * c = ‖c‖²`. -/ +theorem adjoint_comp_self_smul (c : 𝕜) (T : E →ₗ[𝕜] F) : + (c • T).adjoint ∘ₗ (c • T) = ((‖c‖ ^ 2 : ℝ) : 𝕜) • (T.adjoint ∘ₗ T) := by + ext x + refine ext_inner_left 𝕜 fun y => ?_ + rw [comp_apply, adjoint_inner_right, LinearMap.smul_apply, LinearMap.smul_apply, + inner_smul_right, inner_smul_left, LinearMap.smul_apply, comp_apply, inner_smul_right, + adjoint_inner_right, RCLike.ofReal_pow, ← RCLike.conj_mul] + ring + +/-- For a symmetric operator on a finite-dimensional inner product space, the orthogonal +complement of the kernel equals the range. The companion to `IsSymmetric.orthogonal_range` +(which states `(range T)ᗮ = ker T`); this is the dual statement obtained by applying +`orthogonal_ker` to the symmetric operator. -/ +theorem IsSymmetric.range_eq_orthogonal_ker {T : E →ₗ[𝕜] E} (hT : LinearMap.IsSymmetric T) : + LinearMap.range T = (LinearMap.ker T)ᗮ := by + rw [LinearMap.orthogonal_ker, hT.adjoint_eq] + +end LinearMap + +section linearIsometryEquiv + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [CompleteSpace H] +variable {K : Type*} [NormedAddCommGroup K] [InnerProductSpace 𝕜 K] [CompleteSpace K] + +namespace LinearIsometryEquiv + +/-- The LinearMap coercion of `e.conjStarAlgEquiv T` is the `LinearEquiv.conj` form of +the LinearMap coercion of `T`. Definitional bridge from the CLM-level StarAlgEquiv to the +LM-level conjugation. -/ +@[simp] +theorem conjStarAlgEquiv_toLinearMap (e : H ≃ₗᵢ[𝕜] K) (T : H →L[𝕜] H) : + ((e.conjStarAlgEquiv T : K →L[𝕜] K) : K →ₗ[𝕜] K) = + e.toLinearEquiv.conj (T : H →ₗ[𝕜] H) := rfl + +/-- Conjugating a rank-one operator by a linear isometry equivalence is the same as +applying the isometry to both factors: `e.conjStarAlgEquiv (rankOne x y) = rankOne (e x) (e y)`. +The structural transport identity behind moving a rank-one operator between two Hilbert +spaces related by a linear isometry. -/ +@[simp] theorem _root_.InnerProductSpace.rankOne_conjStarAlgEquiv (e : H ≃ₗᵢ[𝕜] K) + (x y : H) : e.conjStarAlgEquiv (InnerProductSpace.rankOne 𝕜 x y) = + InnerProductSpace.rankOne 𝕜 (e x) (e y) := by + ext z + simp [InnerProductSpace.rankOne_apply, ← e.inner_map_map y (e.symm z)] + +/-- An operator on `H` is self-adjoint iff its image under conjugation by a linear isometry +equivalence is self-adjoint on `K`. The forward direction follows from the `StarAlgEquiv` +preserving `star`; the reverse from injectivity. -/ +@[simp] +theorem conjStarAlgEquiv_isSelfAdjoint_iff (e : H ≃ₗᵢ[𝕜] K) {T : H →L[𝕜] H} : + IsSelfAdjoint (e.conjStarAlgEquiv T) ↔ IsSelfAdjoint T := by + simp only [_root_.IsSelfAdjoint, ← map_star e.conjStarAlgEquiv, + EmbeddingLike.apply_eq_iff_eq] + +end LinearIsometryEquiv + +end linearIsometryEquiv + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFC.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFC.lean new file mode 100644 index 0000000000..398a9722af --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFC.lean @@ -0,0 +1,535 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousLinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import Mathlib.Analysis.InnerProductSpace.StarOrder +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# Closed-form continuous functional calculus on a finite-dimensional inner product space + +For a self-adjoint continuous linear operator `T : E →L[ℂ] E` on a finite-dimensional complex +inner product space, the continuous functional calculus has a closed-form expansion in terms +of the rank-one operators along the orthonormal eigenbasis of `T`: + +`cfc f T = ∑ i, (f (λᵢ) : ℂ) • rankOne ℂ eᵢ eᵢ` + +where `λᵢ` and `eᵢ` are the (real) eigenvalues and orthonormal eigenvectors of `T`. + +The proof proceeds by extensionality: we show both sides agree on each eigenvector `eⱼ`. For the +right-hand side, orthonormality collapses the sum to a single term `f(λⱼ) • eⱼ`. For the +left-hand side, `cfc_apply_of_polynomial` plus density (via the closed embedding of `cfcHom`) +gives the same result. + +## Main results + +- `IsSelfAdjoint.eigenvalues_mem_spectrum_real`: eigenvalues are in the real spectrum (⊇). +- `IsSelfAdjoint.spectrum_real_eq_range_eigenvalues`: real spectrum = range of eigenvalues + (CLM-level analog of `Matrix.IsHermitian.spectrum_real_eq_range_eigenvalues`). +- `IsSelfAdjoint.zero_notMem_spectrum_real_of_eigenvalues_pos`: corollary used to discharge + continuity premises like `ContinuousOn Real.log (spectrum ℝ T)` from positivity assumptions + on the eigenvalues. +- `IsSelfAdjoint.cfc_eq_sum_rankOne`: `cfc f T = ∑ i, (f λᵢ : ℂ) • rankOne ℂ eᵢ eᵢ`. +- `IsSelfAdjoint.cfc_sqrt_eq_sum_rankOne`, `cfc_exp_eq_sum_rankOne`, + `cfc_log_eq_sum_rankOne`: closed forms for `Real.sqrt`, `Real.exp`, and + (for `T` whose spectrum avoids `0`) `Real.log`. +- `IsSelfAdjoint.cfc_inner_self_eq_sum`: quadratic-form expansion + `⟨x, cfc f T x⟩ = ∑ i, f(λᵢ) * ‖⟨eᵢ, x⟩‖²`. +- `IsSelfAdjoint.trace_comp_cfc_eq_double_sum`: trace double-sum expansion + `tr((cfc f U) ∘ T) = ∑ᵢ λᵢ * ∑ⱼ f(μⱼ) * ‖⟨fⱼ, eᵢ⟩‖²` for symmetric `T, U`. Foundational + for operator Klein's inequality (Nielsen–Chuang Theorem 11.7). +-/ + +@[expose] public section + +open InnerProductSpace ContinuousFunctionalCalculus Module.End + +namespace IsSelfAdjoint + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} {n : ℕ} + +/-- The eigenvalues of a self-adjoint operator are in its real spectrum. -/ +theorem eigenvalues_mem_spectrum_real (hT : IsSelfAdjoint T) (hn : Module.finrank ℂ E = n) + (i : Fin n) : (hT.isSymmetric.eigenvalues hn i : ℝ) ∈ spectrum ℝ T := by + rw [← IsSelfAdjoint.coe_mem_spectrum_complex hT, ContinuousLinearMap.spectrum_eq] + exact (hT.isSymmetric.hasEigenvalue_eigenvalues hn i).mem_spectrum + +/-- The real spectrum of a self-adjoint operator on a finite-dimensional inner product space +equals the range of its eigenvalue function. CLM-level analog of +`Matrix.IsHermitian.spectrum_real_eq_range_eigenvalues`; the `⊇` direction is +`eigenvalues_mem_spectrum_real`, the `⊆` direction uses `IsSelfAdjoint.coe_mem_spectrum_complex` +to lift to the ℂ-spectrum + `Module.End.HasEigenvalue.of_mem_spectrum` to extract an +eigenvalue + `LinearMap.IsSymmetric.exists_eigenvalues_eq` to identify the index. -/ +theorem spectrum_real_eq_range_eigenvalues (hT : IsSelfAdjoint T) + (hn : Module.finrank ℂ E = n) : + spectrum ℝ T = Set.range (hT.isSymmetric.eigenvalues hn) := by + refine Set.Subset.antisymm (fun μ hμ ↦ ?_) ?_ + · have hμℂ : (μ : ℂ) ∈ spectrum ℂ T := (IsSelfAdjoint.coe_mem_spectrum_complex hT).mpr hμ + rw [ContinuousLinearMap.spectrum_eq] at hμℂ + obtain ⟨i, hi⟩ := hT.isSymmetric.exists_eigenvalues_eq hn + (Module.End.HasEigenvalue.of_mem_spectrum hμℂ) + exact ⟨i, Complex.ofReal_inj.mp hi⟩ + · rintro _ ⟨i, rfl⟩ + exact hT.eigenvalues_mem_spectrum_real hn i + +/-- For a self-adjoint operator on a finite-dimensional inner product space whose eigenvalues +are all strictly positive, zero is not in the real spectrum. Corollary of +`spectrum_real_eq_range_eigenvalues`; foundational for establishing continuity premises like +`ContinuousOn Real.log (spectrum ℝ T)` (since `Real.log` is continuous on `{0}ᶜ`). -/ +theorem zero_notMem_spectrum_real_of_eigenvalues_pos (hT : IsSelfAdjoint T) + (hn : Module.finrank ℂ E = n) (h_pos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) : + (0 : ℝ) ∉ spectrum ℝ T := fun h ↦ by + obtain ⟨i, hi⟩ := (hT.spectrum_real_eq_range_eigenvalues hn).symm ▸ h + exact (h_pos i).ne' hi + +/-- For a self-adjoint operator with strictly positive eigenvalues, `Real.log` is continuous on +its spectrum. Direct continuity composition with the absent-zero-spectrum bridge. -/ +theorem continuousOn_log_spectrum_of_eigenvalues_pos (hT : IsSelfAdjoint T) + (hn : Module.finrank ℂ E = n) (h_pos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) : + ContinuousOn Real.log (spectrum ℝ T) := + Real.continuousOn_log.mono fun _ hx h ↦ + hT.zero_notMem_spectrum_real_of_eigenvalues_pos hn h_pos (h ▸ hx) + +/-- **Any** real function is continuous on the spectrum of a self-adjoint operator on a +finite-dimensional inner product space: the real spectrum is the (finite) range of the eigenvalue +function (`spectrum_real_eq_range_eigenvalues`), hence discrete, so every function is continuous on +it. The discharge for the `cfc` continuity premise regardless of the function (`Real.log`, +`Set.indicator {0} 1`, …). -/ +theorem continuousOn_spectrum (hT : IsSelfAdjoint T) (f : ℝ → ℝ) : + ContinuousOn f (spectrum ℝ T) := by + rw [hT.spectrum_real_eq_range_eigenvalues rfl] + exact (Set.finite_range _).continuousOn f + +/-- **Any** real function is continuous on the *quasi*spectrum of a self-adjoint operator on a +finite-dimensional inner product space. The quasispectrum is `spectrum ∪ {0}` +(`quasispectrum_eq_spectrum_union_zero`), still a finite set, hence discrete. The discharge for the +`cfcₙ` (non-unital CFC) continuity premise — the non-unital analogue of `continuousOn_spectrum`. -/ +theorem continuousOn_quasispectrum (hT : IsSelfAdjoint T) (f : ℝ → ℝ) : + ContinuousOn f (quasispectrum ℝ T) := by + rw [quasispectrum_eq_spectrum_union_zero ℝ T, hT.spectrum_real_eq_range_eigenvalues rfl] + exact ((Set.finite_range _).union (Set.finite_singleton 0)).continuousOn f + +/-- `Real.log` is continuous on the spectrum of **any** self-adjoint operator on a +finite-dimensional inner product space — no positivity needed. Specialization of +`continuousOn_spectrum`; `0` may lie in the spectrum, where `Real.log 0 = 0` is harmless. -/ +theorem continuousOn_log_spectrum (hT : IsSelfAdjoint T) : + ContinuousOn Real.log (spectrum ℝ T) := + hT.continuousOn_spectrum Real.log + +/-- For a self-adjoint operator with strictly positive eigenvalues, the real power function +`· ^ y` is continuous on its spectrum for any exponent `y : ℝ`. Direct continuity composition +with the absent-zero-spectrum bridge. -/ +theorem continuousOn_rpow_const_spectrum_of_eigenvalues_pos (hT : IsSelfAdjoint T) + (hn : Module.finrank ℂ E = n) (h_pos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) (y : ℝ) : + ContinuousOn (fun x : ℝ ↦ x ^ y) (spectrum ℝ T) := + fun x hx ↦ (Real.continuousAt_rpow_const x y <| Or.inl fun h ↦ + hT.zero_notMem_spectrum_real_of_eigenvalues_pos hn h_pos (h ▸ hx)).continuousWithinAt + +/-- CLM-cast of `LinearMap.IsSymmetric.apply_eigenvectorBasis`: the action of a self-adjoint +operator on its eigenbasis vector with the ℝ → ℂ coercion applied to the eigenvalue. -/ +theorem apply_eigenvectorBasis_cast (hT : IsSelfAdjoint T) (hn : Module.finrank ℂ E = n) + (i : Fin n) : + T (hT.isSymmetric.eigenvectorBasis hn i) = + ((hT.isSymmetric.eigenvalues hn i : ℝ) : ℂ) • hT.isSymmetric.eigenvectorBasis hn i := by + exact_mod_cast hT.isSymmetric.apply_eigenvectorBasis hn i + +omit [FiniteDimensional ℂ E] in +/-- **Eigenvectors of a self-adjoint operator with nonzero overlap must have equal eigenvalues**: +the contrapositive of `LinearMap.IsSymmetric.orthogonalFamily_eigenspaces` in the per-vector +form. If `T x = μ • x` and `T e = λ • e` and `⟪e, x⟫ ≠ 0`, then `λ = μ`. -/ +theorem eigenvalue_eq_of_inner_ne_zero (hT : IsSelfAdjoint T) + {x e : E} {μ lam : ℝ} (hμ : T x = (μ : ℂ) • x) (hlam : T e = (lam : ℂ) • e) + (h_inner : ⟪e, x⟫_ℂ ≠ 0) : lam = μ := by + have h_eq : (μ : ℂ) * ⟪e, x⟫_ℂ = (lam : ℂ) * ⟪e, x⟫_ℂ := calc + _ = ⟪e, T x⟫_ℂ := by rw [hμ, inner_smul_right] + _ = ⟪T e, x⟫_ℂ := (hT.isSymmetric e x).symm + _ = _ := by rw [hlam, inner_smul_left, Complex.conj_ofReal] + exact_mod_cast (mul_right_cancel₀ h_inner h_eq).symm + +section cfcAuxOp + +variable (hT : IsSelfAdjoint T) (hn : Module.finrank ℂ E = n) + +/-- Abbreviation for the rank-one projector along the `i`-th eigenvector. -/ +noncomputable abbrev P (i : Fin n) : E →L[ℂ] E := + InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) + +@[simp] private lemma P_apply (i : Fin n) : + hT.P hn i = InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := rfl + +private lemma P_mul_P_of_ne {i j : Fin n} (hij : i ≠ j) : hT.P hn i * hT.P hn j = 0 := by + simp only [P_apply, ContinuousLinearMap.mul_def, InnerProductSpace.rankOne_comp_rankOne, + (hT.isSymmetric.eigenvectorBasis hn).orthonormal.2 hij, zero_smul] + +private lemma P_mul_P_self (i : Fin n) : hT.P hn i * hT.P hn i = hT.P hn i := by + simp only [P_apply, ContinuousLinearMap.mul_def, InnerProductSpace.rankOne_comp_rankOne, + inner_self_eq_norm_sq_to_K, (hT.isSymmetric.eigenvectorBasis hn).orthonormal.1 i] + norm_num + +private lemma star_P (i : Fin n) : star (hT.P hn i) = hT.P hn i := by + simp only [P_apply, ContinuousLinearMap.star_eq_adjoint, InnerProductSpace.adjoint_rankOne] + +private lemma sum_P_eq_one : ∑ i, hT.P hn i = 1 := + (hT.isSymmetric.eigenvectorBasis hn).sum_rankOne_eq_id + +/-- The auxiliary star-algebra hom whose closed-form image is shown to equal `cfc f T`. +Sends `g : C(spectrum ℝ T, ℝ)` to the rank-one expansion +`∑ i, (g(λᵢ) : ℂ) • rankOne ℂ eᵢ eᵢ`. -/ +noncomputable def cfcAuxOp : C(spectrum ℝ T, ℝ) →⋆ₐ[ℝ] (E →L[ℂ] E) where + toFun g := ∑ i, (g ⟨hT.isSymmetric.eigenvalues hn i, + IsSelfAdjoint.eigenvalues_mem_spectrum_real hT hn i⟩ : ℂ) • + IsSelfAdjoint.P hT hn i + map_zero' := by simp + map_one' := by + simp only [ContinuousMap.one_apply, Complex.ofReal_one, one_smul] + exact hT.sum_P_eq_one hn + map_add' f g := by + simp only [ContinuousMap.coe_add, Pi.add_apply, Complex.ofReal_add, add_smul, + Finset.sum_add_distrib] + map_mul' f g := by + simp only [ContinuousMap.coe_mul, Pi.mul_apply, Complex.ofReal_mul] + rw [Finset.sum_mul_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [(Finset.sum_eq_single i (fun j _ hj ↦ ?_) + (fun h ↦ absurd (Finset.mem_univ _) h))] + · rw [smul_mul_smul_comm, hT.P_mul_P_self hn] + · rw [smul_mul_smul_comm, hT.P_mul_P_of_ne hn (Ne.symm hj), smul_zero] + map_star' f := by + simp only [star_trivial] + rw [star_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [star_smul, hT.star_P, RCLike.star_def, Complex.conj_ofReal] + commutes' r := by + simp only [Algebra.algebraMap_eq_smul_one, ContinuousMap.coe_smul, Pi.smul_apply, + ContinuousMap.coe_one, Pi.one_apply, smul_eq_mul, mul_one] + rw [← Finset.smul_sum, hT.sum_P_eq_one hn, Complex.coe_smul] + +@[simp] lemma cfcAuxOp_apply (g : C(spectrum ℝ T, ℝ)) : + hT.cfcAuxOp hn g = ∑ i, (g ⟨hT.isSymmetric.eigenvalues hn i, + hT.eigenvalues_mem_spectrum_real hn i⟩ : ℂ) • hT.P hn i := rfl + +/-- `cfcAuxOp` sends the spectrum's identity function to `T`, by spectral expansion. -/ +lemma cfcAuxOp_id : hT.cfcAuxOp hn + ((ContinuousMap.id ℝ).restrict (spectrum ℝ T)) = T := by + simp only [cfcAuxOp_apply] + exact (hT.spectral_sum hn).symm + +/-- `cfcAuxOp` is continuous: it is a finite sum of pointwise-evaluation-then-smul terms, +each of which is continuous. -/ +lemma continuous_cfcAuxOp : Continuous (hT.cfcAuxOp hn) := + (continuous_finsetSum _ fun _ _ ↦ + (Complex.continuous_ofReal.comp (ContinuousMap.evalCLM ℝ _).continuous).smul + continuous_const).congr fun g ↦ (cfcAuxOp_apply hT hn g).symm + +/-- **Closed-form continuous functional calculus**: for a self-adjoint operator `T` on a +finite-dimensional complex inner product space, the continuous functional calculus has +closed-form expansion in terms of the rank-one projectors along the orthonormal eigenbasis. -/ +theorem cfc_eq_sum_rankOne (f : ℝ → ℝ) (hf : ContinuousOn f (spectrum ℝ T)) : + cfc f T = ∑ i, ((f (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) • + InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := by + simp [cfc_apply f T hT hf, + cfcHom_eq_of_continuous_of_map_id hT (hT.cfcAuxOp hn) (hT.continuous_cfcAuxOp hn) + (hT.cfcAuxOp_id hn)] + +/-- **Trace of `(cfc f T) ∘ M` as a single sum over `T`'s eigenbasis** (the basic, +complex-valued form): `tr((cfc f T) ∘ M) = ∑ᵢ f(λᵢ) · ⟪eᵢ, M eᵢ⟫`. Expanding +`cfc f T = ∑ᵢ f(λᵢ) • rankOne eᵢ eᵢ` keeps everything in `T`'s *fixed* eigenbasis (the `eᵢ` are +`T`'s eigenvectors, not `M`'s), with `M` an arbitrary operator — the form needed to take an `ε → 0` +limit where `M = ρ_ε` varies but `T = σ` is fixed. The `re`-version `re_trace_cfc_comp_eq_sum` is an +immediate corollary. (The double-sum `trace_comp_cfc_eq_double_sum` is a *different* expansion — cfc +on `U`, basis on a second operator `T` — so it routes through the general +`trace_comp_eq_sum_eigenvalues_inner`, not this lemma.) -/ +theorem trace_cfc_comp_eq_sum (hT : IsSelfAdjoint T) (hn : Module.finrank ℂ E = n) + (f : ℝ → ℝ) (hf : ContinuousOn f (spectrum ℝ T)) (M : E →L[ℂ] E) : + LinearMap.trace ℂ E ((cfc f T).toLinearMap ∘ₗ M.toLinearMap) + = ∑ i, (f (hT.isSymmetric.eigenvalues hn i) : ℂ) + * ⟪hT.isSymmetric.eigenvectorBasis hn i, + M (hT.isSymmetric.eigenvectorBasis hn i)⟫_ℂ := by + set v := hT.isSymmetric.eigenvectorBasis hn + rw [hT.cfc_eq_sum_rankOne hn f hf] + have hdist : (↑(∑ i, (↑(f (hT.isSymmetric.eigenvalues hn i)) : ℂ) • rankOne ℂ (v i) (v i)) : + E →ₗ[ℂ] E) ∘ₗ M.toLinearMap + = ∑ i, (((↑(f (hT.isSymmetric.eigenvalues hn i)) : ℂ) • rankOne ℂ (v i) (v i)) : + E →L[ℂ] E).toLinearMap ∘ₗ M.toLinearMap := by + rw [ContinuousLinearMap.toLinearMap_sum]; ext x; simp [LinearMap.sum_apply] + rw [hdist, map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [ContinuousLinearMap.toLinearMap_smul, LinearMap.smul_comp, map_smul, smul_eq_mul, + LinearMap.trace_comp_comm', ← ContinuousLinearMap.toLinearMap_comp, + InnerProductSpace.comp_rankOne, InnerProductSpace.trace_rankOne] + +/-- **Trace of `(cfc f T) ∘ M`, real part** (`re`-corollary of `trace_cfc_comp_eq_sum`): +`re tr((cfc f T) ∘ M) = ∑ᵢ f(λᵢ) · re ⟪eᵢ, M eᵢ⟫`, using that `f λᵢ` is real. -/ +theorem re_trace_cfc_comp_eq_sum (hT : IsSelfAdjoint T) (hn : Module.finrank ℂ E = n) + (f : ℝ → ℝ) (hf : ContinuousOn f (spectrum ℝ T)) (M : E →L[ℂ] E) : + RCLike.re (LinearMap.trace ℂ E ((cfc f T).toLinearMap ∘ₗ M.toLinearMap)) + = ∑ i, f (hT.isSymmetric.eigenvalues hn i) + * RCLike.re ⟪hT.isSymmetric.eigenvectorBasis hn i, + M (hT.isSymmetric.eigenvectorBasis hn i)⟫_ℂ := by + rw [hT.trace_cfc_comp_eq_sum hn f hf M, map_sum] + exact Finset.sum_congr rfl fun i _ ↦ RCLike.re_ofReal_mul _ _ + +/-- Closed-form `cfc Real.sqrt T` for any self-adjoint `T`. (Junk on negative eigenvalues +since `Real.sqrt` is `0` outside `[0, ∞)`.) -/ +theorem cfc_sqrt_eq_sum_rankOne : + cfc Real.sqrt T = ∑ i, ((Real.sqrt (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) • + InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := + hT.cfc_eq_sum_rankOne hn Real.sqrt Real.continuous_sqrt.continuousOn + +/-- Closed-form `cfc Real.exp T` for any self-adjoint `T`. -/ +theorem cfc_exp_eq_sum_rankOne : + cfc Real.exp T = ∑ i, ((Real.exp (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) • + InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := + hT.cfc_eq_sum_rankOne hn Real.exp Real.continuous_exp.continuousOn + +/-- Closed-form `cfc Real.log T` for a self-adjoint `T` whose spectrum avoids `0`. -/ +theorem cfc_log_eq_sum_rankOne (h0 : (0 : ℝ) ∉ spectrum ℝ T) : + cfc Real.log T = ∑ i, ((Real.log (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) • + InnerProductSpace.rankOne ℂ (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := + hT.cfc_eq_sum_rankOne hn Real.log <| + Real.continuousOn_log.mono fun _ hx h ↦ h0 (h ▸ hx) + +/-- **Spectral quadratic-form expansion**: for self-adjoint `T` with eigenvalues `λᵢ` and +orthonormal eigenbasis `eᵢ`, and continuous `f` on `spectrum ℝ T`, the inner-product +`⟨x, cfc f T x⟩` decomposes pointwise as `∑ i, f(λᵢ) * ‖⟨eᵢ, x⟩‖²` for any vector `x`. The +quadratic-form sibling of `IsSelfAdjoint.cfc_eq_sum_rankOne`. -/ +theorem cfc_inner_self_eq_sum (f : ℝ → ℝ) (hf : ContinuousOn f (spectrum ℝ T)) (x : E) : + ⟪x, (cfc f T) x⟫_ℂ = ∑ i, ((f (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) * + ((‖⟪hT.isSymmetric.eigenvectorBasis hn i, x⟫_ℂ‖ : ℂ) ^ 2) := by + rw [hT.cfc_eq_sum_rankOne hn f hf, _root_.sum_apply, inner_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [_root_.smul_apply, inner_smul_right, + InnerProductSpace.rankOne_apply, inner_smul_right] + -- Goal: (f λᵢ) * (⟨eᵢ, x⟩ * ⟨x, eᵢ⟩) = (f λᵢ) * ‖⟨eᵢ, x⟩‖² + congr 1 + rw [← inner_conj_symm x (hT.isSymmetric.eigenvectorBasis hn i), RCLike.mul_conj] + norm_cast + +end cfcAuxOp + +/-- **Trace double-sum expansion of `tr((cfc f U) ∘ T)`**: for self-adjoint `T, U` with +respective eigenvalues `λᵢ, μⱼ` and orthonormal eigenbases `eᵢ, fⱼ`, and continuous `f` on +`spectrum ℝ U`, the trace factors as +`∑ᵢ λᵢ * ∑ⱼ f(μⱼ) * ‖⟨fⱼ, eᵢ⟩‖²`. + +Foundational for operator Klein's inequality (Nielsen–Chuang Theorem 11.7): when `T := ρ` +(density) and `U := σ` (positive density), the formula expresses `tr(ρ log σ)` as a double +sum that Jensen's inequality on `log` then bounds by the classical Gibbs/Klein expression. -/ +theorem trace_comp_cfc_eq_double_sum + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T U : E →L[ℂ] E} (hT : IsSelfAdjoint T) (hU : IsSelfAdjoint U) + {n : ℕ} (hn : Module.finrank ℂ E = n) + (f : ℝ → ℝ) (hf : ContinuousOn f (spectrum ℝ U)) : + LinearMap.trace ℂ E ((cfc f U).toLinearMap ∘ₗ T.toLinearMap) = + ∑ i, (hT.isSymmetric.eigenvalues hn i : ℂ) * + ∑ j, ((f (hU.isSymmetric.eigenvalues hn j) : ℝ) : ℂ) * + ((‖⟪hU.isSymmetric.eigenvectorBasis hn j, + hT.isSymmetric.eigenvectorBasis hn i⟫_ℂ‖ : ℂ) ^ 2) := by + rw [LinearMap.IsSymmetric.trace_comp_eq_sum_eigenvalues_inner hT.isSymmetric hn] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + congr 1 + exact hU.cfc_inner_self_eq_sum hn f hf _ + +/-- **Spectral mapping on eigenvectors**: for a self-adjoint operator `T` on a finite-dimensional +complex inner product space, if `x` is an eigenvector of `T` with real eigenvalue `μ` and `f` is +continuous on the spectrum of `T`, then `cfc f T x = (f μ : ℂ) • x`. + +Proof: expand `cfc f T x = ∑ i (f λᵢ : ℂ) • ⟨eᵢ, x⟩ • eᵢ` via `cfc_eq_sum_rankOne`. For each `i`, +either `⟨eᵢ, x⟩ = 0` (term vanishes) or `λᵢ = μ` (so `f λᵢ = f μ`) — both follow from comparing +`⟪eᵢ, T x⟫` computed via `hμ` and via the eigenvector equation for `eᵢ`. Pull `(f μ : ℂ)` out +and apply Parseval (`OrthonormalBasis.sum_repr'`). -/ +theorem cfc_apply_smul_of_apply_eq_smul + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {n : ℕ} + (hn : Module.finrank ℂ E = n) {f : ℝ → ℝ} (hf : ContinuousOn f (spectrum ℝ T)) + {x : E} {μ : ℝ} (hμ : T x = (μ : ℂ) • x) : + cfc f T x = (f μ : ℂ) • x := by + set e := hT.isSymmetric.eigenvectorBasis hn + set lams := hT.isSymmetric.eigenvalues hn with hlams_def + -- Each term either vanishes (`⟪eᵢ, x⟫ = 0`) or has matching scalar (`λᵢ = μ`, so `f λᵢ = f μ`). + have hterm : ∀ i, ((f (lams i) : ℝ) : ℂ) • ⟪e i, x⟫_ℂ • e i = + ((f μ : ℝ) : ℂ) • ⟪e i, x⟫_ℂ • e i := fun i ↦ by + by_cases h_inner : ⟪e i, x⟫_ℂ = 0 + · simp [h_inner] + · rw [hlams_def, hT.eigenvalue_eq_of_inner_ne_zero hμ + (hT.apply_eigenvectorBasis_cast hn i) h_inner] + rw [hT.cfc_eq_sum_rankOne hn f hf] + simp only [_root_.sum_apply, _root_.smul_apply, + InnerProductSpace.rankOne_apply] + rw [Finset.sum_congr rfl fun i _ ↦ hterm i, ← Finset.smul_sum, e.sum_repr' x] + +/-- **Trace of `(cfc f T) ∘ M` in an arbitrary eigenbasis of `T`** — the arbitrary-basis +generalization of `re_trace_cfc_comp_eq_sum`, which pins the basis to the canonical +`hT.isSymmetric.eigenvectorBasis`. For *any* orthonormal basis `b` of eigenvectors of a self-adjoint +`T` (`T (b i) = μ i • b i`) and `f` continuous on the spectrum of `T`, +`re tr((cfc f T) ∘ M) = ∑ᵢ f(μ i) · re⟨b i, M (b i)⟩` for any operator `M`. + +The freedom to pick `b` is essential when two self-adjoint operators must be diagonalized in a +*shared* basis — e.g. `T` and an identity shift `T + ε • 1`, which have the same eigenvectors but +distinct canonical eigenbases. Trace cyclicity (`LinearMap.trace_mul_comm`) moves `cfc f T` to the +right of `M`; in the eigenbasis of `T` it acts diagonally as `f(μ i)` +(`cfc_apply_smul_of_apply_eq_smul`), reducing the trace to the eigenvalue-weighted sum of the +diagonal matrix elements `⟨b i, M (b i)⟩` of `M`. No positivity or self-adjointness of `M` is +needed. -/ +theorem re_trace_cfc_comp_eq_sum_of_apply_eq_smul + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {ι : Type*} [Fintype ι] + (b : OrthonormalBasis ι ℂ E) {μ : ι → ℝ} (hTb : ∀ i, T (b i) = (μ i : ℂ) • b i) + {f : ℝ → ℝ} (hf : ContinuousOn f (spectrum ℝ T)) (M : E →L[ℂ] E) : + RCLike.re (LinearMap.trace ℂ E ((cfc f T).toLinearMap ∘ₗ M.toLinearMap)) + = ∑ i, f (μ i) * RCLike.re (inner ℂ (b i) (M (b i))) := by + classical + have hdiag : ∀ i, (cfc f T) (b i) = (f (μ i) : ℂ) • b i := fun i => + hT.cfc_apply_smul_of_apply_eq_smul rfl hf (hTb i) + have hcomm : (LinearMap.trace ℂ E) ((cfc f T).toLinearMap ∘ₗ M.toLinearMap) + = (LinearMap.trace ℂ E) (M.toLinearMap ∘ₗ (cfc f T).toLinearMap) := + LinearMap.trace_mul_comm ℂ _ _ + rw [hcomm, LinearMap.trace_eq_sum_inner _ b, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [LinearMap.comp_apply, ContinuousLinearMap.coe_coe, ContinuousLinearMap.coe_coe, hdiag i, + map_smul, inner_smul_right] + simp + +/-- **Spectral mapping for `Real.log` on eigenvectors of a positive-spectrum self-adjoint +operator**: combines `cfc_apply_smul_of_apply_eq_smul` (the generic spectral mapping) with +`continuousOn_log_spectrum_of_eigenvalues_pos` (the continuity-of-log discharge). -/ +theorem cfc_log_apply_smul_of_apply_eq_smul + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {n : ℕ} + (hn : Module.finrank ℂ E = n) (hpos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) + {x : E} {μ : ℝ} (hμ : T x = (μ : ℂ) • x) : + cfc Real.log T x = ((Real.log μ : ℝ) : ℂ) • x := + hT.cfc_apply_smul_of_apply_eq_smul hn (hT.continuousOn_log_spectrum_of_eigenvalues_pos hn hpos) hμ + +/-- **`cfc Real.log` on a basis eigenvector** of a positive-spectrum self-adjoint operator: +the result is the log of the eigenvalue times the eigenvector. -/ +theorem cfc_log_apply_eigenvectorBasis + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {n : ℕ} + (hn : Module.finrank ℂ E = n) (hpos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) (i : Fin n) : + cfc Real.log T (hT.isSymmetric.eigenvectorBasis hn i) = + ((Real.log (hT.isSymmetric.eigenvalues hn i) : ℝ) : ℂ) • + hT.isSymmetric.eigenvectorBasis hn i := + hT.cfc_log_apply_smul_of_apply_eq_smul hn hpos (hT.apply_eigenvectorBasis_cast hn i) + +/-- **Spectral mapping for `· ^ y` (real rpow with constant exponent) on eigenvectors of a +positive-spectrum self-adjoint operator**: sibling of `cfc_log_apply_smul_of_apply_eq_smul`, +combining `cfc_apply_smul_of_apply_eq_smul` with +`continuousOn_rpow_const_spectrum_of_eigenvalues_pos`. -/ +theorem cfc_rpow_const_apply_smul_of_apply_eq_smul + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {n : ℕ} + (hn : Module.finrank ℂ E = n) (hpos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) (y : ℝ) + {x : E} {μ : ℝ} (hμ : T x = (μ : ℂ) • x) : + cfc (fun x : ℝ ↦ x ^ y) T x = ((μ ^ y : ℝ) : ℂ) • x := + hT.cfc_apply_smul_of_apply_eq_smul hn + (hT.continuousOn_rpow_const_spectrum_of_eigenvalues_pos hn hpos y) hμ + +/-- **`cfc (· ^ y)` on a basis eigenvector** of a positive-spectrum self-adjoint operator: the +result is the `y`-th power of the eigenvalue times the eigenvector. Sibling of +`cfc_log_apply_eigenvectorBasis`. -/ +theorem cfc_rpow_const_apply_eigenvectorBasis + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + [FiniteDimensional ℂ E] {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) {n : ℕ} + (hn : Module.finrank ℂ E = n) (hpos : ∀ i, 0 < hT.isSymmetric.eigenvalues hn i) (y : ℝ) + (i : Fin n) : + cfc (fun x : ℝ ↦ x ^ y) T (hT.isSymmetric.eigenvectorBasis hn i) = + (((hT.isSymmetric.eigenvalues hn i) ^ y : ℝ) : ℂ) • + hT.isSymmetric.eigenvectorBasis hn i := + hT.cfc_rpow_const_apply_smul_of_apply_eq_smul hn hpos y (hT.apply_eigenvectorBasis_cast hn i) + +/-- `(cfc f T) · T = cfc (t ↦ f t · t) T`: the product of `cfc f T` with `T` collapses to a single +`cfc`, recombining via `cfc_mul` and `cfc_id` (continuity of `f` on the finite spectrum is free, +via `continuousOn_spectrum`). Captures the shared "rewrite `T` as `cfc id T`, recombine" move. Pure +functional calculus — a candidate for upstream Mathlib. -/ +theorem cfc_mul_id (hT : IsSelfAdjoint T) (f : ℝ → ℝ) : + cfc f T * T = cfc (fun t : ℝ ↦ f t * t) T := by + nth_rw 2 [← cfc_id ℝ T] + rw [← cfc_mul _ _ _ (hT.continuousOn_spectrum _) (hT.continuousOn_spectrum _)] + rfl + +/-- `T · (cfc g T) = cfc (t ↦ t · g t) T`: the left-product mirror of `cfc_mul_id`. -/ +theorem cfc_id_mul (hT : IsSelfAdjoint T) (g : ℝ → ℝ) : + T * cfc g T = cfc (fun t : ℝ ↦ t * g t) T := by + nth_rw 1 [← cfc_id ℝ T] + rw [← cfc_mul _ _ _ (hT.continuousOn_spectrum _) (hT.continuousOn_spectrum _)] + rfl + +/-- A self-adjoint operator annihilates the spectral projection onto its zero-eigenspace +`cfc 1_{{0}} T` (the projection onto `ker T`): `T * cfc 1_{{0}} T = 0`, since `t · 1_{{0}}(t) = 0` +for every `t` (at `t = 0` the first factor vanishes, elsewhere the indicator does). Foundational for +the `ker σ`-block of the relative-entropy continuity limit. -/ +theorem self_mul_cfc_indicator_zero (hT : IsSelfAdjoint T) : + T * cfc (Set.indicator {0} (1 : ℝ → ℝ)) T = 0 := by + have hfun : (fun t : ℝ ↦ t * Set.indicator {0} (1 : ℝ → ℝ) t) = 0 := by + ext t; by_cases ht : t = 0 <;> simp [ht] + rw [hT.cfc_id_mul, hfun, cfc_zero] + +/-- **Entropy-term reduction**: `(cfc log T) · T = cfc (t ↦ t log t) T`. The product `cfc log T · T` +becomes a single `cfc` of the continuous function `t ↦ t log t` (removable singularity at `0`, +`Real.continuous_mul_log`), which — unlike `cfc log T` alone — is continuous in `T`. The reduction +that makes the entropy term `tr((cfc log ρ) · ρ)` continuous in `ρ` across the kernel. -/ +theorem cfc_log_mul_self (hT : IsSelfAdjoint T) : + cfc Real.log T * T = cfc (fun t : ℝ ↦ t * Real.log t) T := + (hT.cfc_mul_id Real.log).trans (cfc_congr fun _ _ ↦ mul_comm _ _) + +end IsSelfAdjoint + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +open scoped ComplexOrder in +/-- **Uniqueness of the positive square root**: for a positive operator `x`, the CFC sqrt of +`x * x` recovers `x`. Equivalently, two positive operators with equal squares are equal — +applying this lemma to both sides of `A * A = B * B` (`0 ≤ A`, `0 ≤ B`) gives +`A = cfc Real.sqrt (A * A) = cfc Real.sqrt (B * B) = B`. Proved via `cfc_comp_pow` + +`cfc_id` + `Real.sqrt_sq` on the spectrum. -/ +theorem cfc_real_sqrt_mul_self_eq_self_of_nonneg + {x : E →L[ℂ] E} (hx : 0 ≤ x) : + cfc Real.sqrt (x * x) = x := by + conv_rhs => rw [← cfc_id ℝ x] + rw [← sq, ← cfc_comp_pow (R := ℝ) Real.sqrt 2 x] + exact cfc_congr fun y hy ↦ Real.sqrt_sq (spectrum_nonneg_of_nonneg hx hy) + +/-- **CFC commutes with conjugation by an isometry**, for functions vanishing at `0`. For +`V : E →L[ℂ] H` an isometry (`V† V = 1`), self-adjoint `ρ`, and `f` with `f 0 = 0`, +`cfc f (V ρ V†) = V (cfc f ρ) V†`. The `f 0 = 0` hypothesis is essential: it kills the contribution +of the zero eigenspace `(ran V)ᗮ` of `V ρ V†`, on which the unital `cfc` would otherwise place +`f 0`. Routes through the non-unital `cfcₙ` (which builds in `f 0 = 0`) and its naturality under the +non-unital `⋆`-hom `conjIsometryₙ` (`NonUnitalStarAlgHom.map_cfcₙ`). The non-equiv companion to +`LinearIsometryEquiv.conjStarAlgEquiv_cfc_real_log`. -/ +theorem cfc_conj_isometry [FiniteDimensional ℂ E] [IsScalarTower ℝ ℂ (E →L[ℂ] E)] + {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] + [CompleteSpace H] [IsScalarTower ℝ ℂ (H →L[ℂ] H)] + {V : E →L[ℂ] H} (hV : V.adjoint ∘L V = 1) {ρ : E →L[ℂ] E} + (hρ : IsSelfAdjoint ρ) {f : ℝ → ℝ} (hf0 : f 0 = 0) : + cfc f (V ∘L ρ ∘L V.adjoint) = V ∘L (cfc f ρ) ∘L V.adjoint := by + have hVρ : IsSelfAdjoint (conjIsometryₙ hV ρ) := by + change star (conjIsometryₙ hV ρ) = conjIsometryₙ hV ρ + rw [← map_star, hρ.star_eq] + have hφ : Continuous ⇑(conjIsometryₙ hV) := by + change Continuous fun A : E →L[ℂ] E ↦ V ∘L A ∘L V.adjoint + fun_prop + have hqρ := IsSelfAdjoint.continuousOn_quasispectrum hρ f + rw [← conjIsometryₙ_apply hV ρ, ← conjIsometryₙ_apply hV (cfc f ρ), + ← cfcₙ_eq_cfc (hf := IsSelfAdjoint.continuousOn_quasispectrum hVρ f) (hf0 := hf0), + ← cfcₙ_eq_cfc (a := ρ) (hf := hqρ) (hf0 := hf0)] + exact ((conjIsometryₙ hV).map_cfcₙ f ρ hqρ hf0 hφ hρ hVρ).symm + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamily.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamily.lean new file mode 100644 index 0000000000..0111494bcd --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamily.lean @@ -0,0 +1,228 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiKraus +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# The codeword-family form of the pretty-good-measurement error estimate + +Nielsen & Chuang's Box 12.5 "calculating the spurs" step (eqs. (12.92)–(12.94)) evaluates the +right-hand side of the trace form of the square-root operator inequality at the concrete +apparatus of the achievability proof: the (typical-subspace–compressed) codeword eigenvectors +`|E_tilde_c⟩` assembled columnwise into an operator `V = synthesisMap ψ`, with **total operator** +`S = V ∘ V⋆ = ∑ c, |ψ_c⟩⟨ψ_c|` and **Gram operator** `Γ = V⋆ ∘ V` (entries `⟪ψ_c, ψ_{c'}⟫`), +and the diagonal weight `Λ = ∑ c, λ_c |e_c⟩⟨e_c|` of the eigenvalues `λ_c`. + +Feeding this instantiation into the abstract Gram-trace bound +`ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_gram_le` (N&C eq. (12.94)) turns each of the +three physical traces into a concrete sum over the family `ψ`, giving the decoding-deficit bound in +Nielsen & Chuang's own "sum over codewords" form: + +`2·∑_c λ_c (1 − re⟪e_c, √Γ e_c⟫) ≤ 2·∑_c λ_c − 3·∑_c λ_c‖ψ_c‖² + ∑_c ∑_{c'} λ_c |⟪ψ_c, ψ_{c'}⟫|²`, + +where `√Γ = cfc Real.sqrt Γ` and `α_c = re⟪e_c, √Γ e_c⟫` is exactly Nielsen & Chuang's diagonal +decoding overlap `α_{(M,K),(M,K)}` (Box 12.5, `Γ^{1/2} = [α]`). This is the achievability half of +the **Holevo–Schumacher–Westmoreland theorem** (`χ(E) = C⁽¹⁾(E)`, N&C Theorem 12.8): once `ψ` is the +codeword-eigenvector family and `λ` the eigenvalues, the left side is the `2·∑ λ(1−α)` term of +eq. (12.88) and the three right-hand sums are the physical error terms `tr(σ_M(I−P))`, +`tr(P σ_M P P_{M'})`, `tr(σ_M(I−P_M))` of the random-coding error estimate (12.79). + +## What this file provides + +* `InnerProductSpace.trace_sum_smul_rankOne_self` / + `InnerProductSpace.trace_comp_sum_smul_rankOne_self` — the reusable trace-evaluation core: + `tr(∑_c c_c |v_c⟩⟨v_c|) = ∑_c c_c ⟪v_c, v_c⟫` and, against a further operator `A`, + `tr(A · ∑_c c_c |v_c⟩⟨v_c|) = ∑_c c_c ⟪v_c, A v_c⟫`. +* `InnerProductSpace.synthesisMap_comp_diagWeight_comp_adjoint` — the conjugation identity + `V · (∑_c c_c |e_c⟩⟨e_c|) · V⋆ = ∑_c c_c |ψ_c⟩⟨ψ_c|`: the synthesis operator carries the + coordinate-space diagonal weight to the eigenvalue-weighted frame operator on the ambient space. +* `InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` — the **headline** codeword-sum + bound (N&C eq. (12.94)), the abstract Gram-trace inequality with all three spurs evaluated as + concrete sums over the family `ψ` and the diagonal eigenvalue weight `λ`. + +The abstract Gram-trace bound used here is in +`ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramTrace`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace InnerProductSpace + +section Trace + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] {ι : Type*} [Fintype ι] + +omit [Fintype ι] in +/-- **Trace of an operator against a weighted family of rank-one self-projectors.** For an operator +`A : E →L[𝕜] E`, a family `v : ι → E`, scalar weights `c : ι → 𝕜`, and a finite index set +`s : Finset ι`, + +`tr(A · ∑_{i ∈ s} c_i |v_i⟩⟨v_i|) = ∑_{i ∈ s} c_i ⟪v_i, A v_i⟫`. + +Distributing the composition over the sum and each scalar, `A · |v_i⟩⟨v_i| = |A v_i⟩⟨v_i|` +(`comp_rankOne`) and `tr(|A v_i⟩⟨v_i|) = ⟪v_i, A v_i⟫` (`trace_rankOne`). Stated over an arbitrary +`Finset` (the whole-`Fintype` case is `s = Finset.univ`), so it evaluates traces against partial +rank-one sums such as an eigenbasis restricted to a typical index set. -/ +theorem trace_comp_sum_smul_rankOne_self (A : E →L[𝕜] E) (v : ι → E) (c : ι → 𝕜) (s : Finset ι) : + LinearMap.trace 𝕜 E + ((A.comp (∑ i ∈ s, c i • rankOne 𝕜 (v i) (v i)) : E →L[𝕜] E) : E →ₗ[𝕜] E) + = ∑ i ∈ s, c i * inner 𝕜 (v i) (A (v i)) := by + rw [ContinuousLinearMap.comp_finsetSum] + simp_rw [ContinuousLinearMap.comp_smul, comp_rankOne] + rw [ContinuousLinearMap.toLinearMap_sum, map_sum] + simp_rw [ContinuousLinearMap.toLinearMap_smul, map_smul, trace_rankOne, smul_eq_mul] + +/-- **Trace of a weighted family of rank-one self-projectors.** For a family `v : ι → E` and +scalar weights `c : ι → 𝕜`, + +`tr(∑_i c_i |v_i⟩⟨v_i|) = ∑_i c_i ⟪v_i, v_i⟫`. + +The `A = 1` case of `trace_comp_sum_smul_rankOne_self`. -/ +theorem trace_sum_smul_rankOne_self (v : ι → E) (c : ι → 𝕜) : + LinearMap.trace 𝕜 E ((∑ i, c i • rankOne 𝕜 (v i) (v i) : E →L[𝕜] E) : E →ₗ[𝕜] E) + = ∑ i, c i * inner 𝕜 (v i) (v i) := by + rw [ContinuousLinearMap.toLinearMap_sum, map_sum] + simp_rw [ContinuousLinearMap.toLinearMap_smul, map_smul, trace_rankOne, smul_eq_mul] + +end Trace + +section Family + +variable {ι : Type*} [Fintype ι] {G : Type*} + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +omit [FiniteDimensional ℂ G] in +/-- **The synthesis operator carries the coordinate diagonal weight to the family frame weight.** +For a family `ψ : ι → G` with synthesis operator `V = synthesisMap ψ` and scalar weights +`c : ι → ℂ`, + +`V · (∑_i c_i |e_i⟩⟨e_i|) · V⋆ = ∑_i c_i |ψ_i⟩⟨ψ_i|`, + +where `e_i` are the standard basis vectors of `EuclideanSpace ℂ ι`. Termwise +`V · |e_i⟩⟨e_i| · V⋆ = |V e_i⟩⟨V e_i| = |ψ_i⟩⟨ψ_i|` (`comp_rankOne_self_comp_adjoint`, +`synthesisMap_basisFun`). -/ +theorem synthesisMap_comp_diagWeight_comp_adjoint (ψ : ι → G) (c : ι → ℂ) : + (synthesisMap ψ).comp + ((∑ i, c i • rankOne ℂ (EuclideanSpace.basisFun ι ℂ i) (EuclideanSpace.basisFun ι ℂ i)).comp + (adjoint (synthesisMap ψ))) + = ∑ i, c i • rankOne ℂ (ψ i) (ψ i) := by + rw [ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.comp_finsetSum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, + comp_rankOne_self_comp_adjoint] + simp only [synthesisMap_basisFun] + +/-- **The codeword-family form of the pretty-good-measurement error estimate** +(Nielsen & Chuang, Box 12.5, eq. (12.94)). For a finite family `ψ : ι → G` with synthesis operator +`V = synthesisMap ψ`, Gram operator `Γ = V⋆ · V`, and nonnegative real weights `λ : ι → ℝ`, + +`2 · ∑_i λ_i (1 − re⟪e_i, √Γ e_i⟫) ≤ 2·∑_i λ_i − 3·∑_i λ_i‖ψ_i‖² + ∑_i ∑_j λ_i |⟪ψ_i, ψ_j⟫|²`, + +where `e_i` are the standard basis vectors of `EuclideanSpace ℂ ι` and `√Γ = cfc Real.sqrt Γ`. The +diagonal `α_i = re⟪e_i, √Γ e_i⟫` is Nielsen & Chuang's decoding overlap `α_{(M,K),(M,K)}` +(Box 12.5, `Γ^{1/2} = [α]`). + +This is the abstract Gram-trace bound +`ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_gram_le` at `V = synthesisMap ψ` and the +diagonal eigenvalue weight `Λ = ∑_i λ_i |e_i⟩⟨e_i|`, with each of its three physical traces +`tr Λ`, `tr(V Λ V⋆)`, `tr(S · V Λ V⋆)` evaluated into concrete sums over `ψ` and `λ` +(`trace_sum_smul_rankOne_self`, `trace_comp_sum_smul_rankOne_self`, +`synthesisMap_comp_diagWeight_comp_adjoint`, `sum_rankOne_self_eq_synthesisMap_comp_adjoint`). Once +`ψ` is the codeword-eigenvector family and `λ` the eigenvalues, the left side is the `2·∑ λ(1−α)` +term of N&C eq. (12.88) and the three right-hand sums are the error terms of the random-coding +estimate (12.79). -/ +theorem two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le (ψ : ι → G) (lam : ι → ℝ) + (hlam : ∀ i, 0 ≤ lam i) : + 2 * ∑ i, lam i * (1 - RCLike.re (inner ℂ (EuclideanSpace.basisFun ι ℂ i) + ((cfc Real.sqrt ((adjoint (synthesisMap ψ)).comp (synthesisMap ψ))) + (EuclideanSpace.basisFun ι ℂ i)))) + ≤ 2 * ∑ i, lam i + - 3 * ∑ i, lam i * ‖ψ i‖ ^ 2 + + ∑ i, ∑ j, lam i * ‖inner ℂ (ψ i) (ψ j)‖ ^ 2 := by + classical + set Λ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι := + ∑ i, (lam i : ℂ) • rankOne ℂ (EuclideanSpace.basisFun ι ℂ i) (EuclideanSpace.basisFun ι ℂ i) + with hΛdef + -- `⟪e_i, e_i⟫ = 1` for the standard basis vectors. + have hbb : ∀ i, (inner ℂ (EuclideanSpace.basisFun ι ℂ i) + (EuclideanSpace.basisFun ι ℂ i) : ℂ) = 1 := fun i => by + rw [EuclideanSpace.basisFun_inner, EuclideanSpace.basisFun_apply, PiLp.single_apply, + ite_eq_left rfl] + -- The diagonal weight is positive. + have hΛ : 0 ≤ Λ := by + rw [hΛdef] + refine Finset.sum_nonneg fun i _ => ?_ + exact nonneg_iff_isPositive.mpr + ((isPositive_rankOne_self (EuclideanSpace.basisFun ι ℂ i)).smul_of_nonneg + (by exact_mod_cast hlam i)) + have h := ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_gram_le (synthesisMap ψ) hΛ + -- Evaluate `tr Λ = ∑ λ_i`. + have htrΛ : LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (Λ : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι) + = ∑ i, (lam i : ℂ) := by + rw [hΛdef, trace_sum_smul_rankOne_self] + exact Finset.sum_congr rfl fun i _ => by rw [hbb i, mul_one] + -- Evaluate `tr(V Λ V⋆) = ∑ λ_i ‖ψ_i‖²`. + have htrT : LinearMap.trace ℂ G + ((( synthesisMap ψ).comp (Λ.comp (adjoint (synthesisMap ψ))) : G →L[ℂ] G) : G →ₗ[ℂ] G) + = ∑ i, (lam i : ℂ) * (‖ψ i‖ ^ 2 : ℝ) := by + rw [hΛdef, synthesisMap_comp_diagWeight_comp_adjoint, trace_sum_smul_rankOne_self] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [inner_self_eq_norm_sq_to_K]; simp + -- Evaluate `tr(S · V Λ V⋆) = ∑_i ∑_j λ_i |⟪ψ_i, ψ_j⟫|²`. + have htrS : LinearMap.trace ℂ G + ((((synthesisMap ψ).comp (adjoint (synthesisMap ψ))).comp + ((synthesisMap ψ).comp (Λ.comp (adjoint (synthesisMap ψ)))) : G →L[ℂ] G) : G →ₗ[ℂ] G) + = ∑ i, ∑ j, (lam i : ℂ) * (‖inner ℂ (ψ i) (ψ j)‖ ^ 2 : ℝ) := by + rw [hΛdef, synthesisMap_comp_diagWeight_comp_adjoint, trace_comp_sum_smul_rankOne_self] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← sum_rankOne_self_eq_synthesisMap_comp_adjoint, _root_.sum_apply, inner_sum, + Finset.mul_sum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [rankOne_apply, inner_smul_right, ← inner_conj_symm (ψ j) (ψ i), RCLike.conj_mul]; simp + -- Evaluate `re tr((1 - √Γ) Λ) = ∑ λ_i (1 - re⟪e_i, √Γ e_i⟫)`. + have htrLHS : RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (((1 - cfc Real.sqrt ((adjoint (synthesisMap ψ)).comp (synthesisMap ψ))) * Λ : + EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι)) + = ∑ i, lam i * (1 - RCLike.re (inner ℂ (EuclideanSpace.basisFun ι ℂ i) + ((cfc Real.sqrt ((adjoint (synthesisMap ψ)).comp (synthesisMap ψ))) + (EuclideanSpace.basisFun ι ℂ i)))) := by + rw [ContinuousLinearMap.mul_def, hΛdef, trace_comp_sum_smul_rankOne_self, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [_root_.sub_apply, one_apply_eq_self, inner_sub_right, hbb i] + simp [mul_sub] + -- Real parts of the codeword sums. + have hre1 : RCLike.re (∑ i, (lam i : ℂ)) = ∑ i, lam i := by + rw [map_sum]; exact Finset.sum_congr rfl fun x _ => RCLike.ofReal_re _ + have hre2 : RCLike.re (∑ i, (lam i : ℂ) * (‖ψ i‖ ^ 2 : ℝ)) = ∑ i, lam i * ‖ψ i‖ ^ 2 := by + rw [map_sum] + exact Finset.sum_congr rfl fun x _ => by rw [← Complex.ofReal_mul]; exact RCLike.ofReal_re _ + have hre3 : RCLike.re (∑ i, ∑ j, (lam i : ℂ) * (‖inner ℂ (ψ i) (ψ j)‖ ^ 2 : ℝ)) + = ∑ i, ∑ j, lam i * ‖inner ℂ (ψ i) (ψ j)‖ ^ 2 := by + rw [map_sum] + refine Finset.sum_congr rfl fun x _ => ?_ + rw [map_sum] + exact Finset.sum_congr rfl fun y _ => by rw [← Complex.ofReal_mul]; exact RCLike.ofReal_re _ + rw [htrΛ, htrT, htrS, hre1, hre2, hre3, htrLHS] at h + exact h + +end Family + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamilySigma.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamilySigma.lean new file mode 100644 index 0000000000..9c4ea190a8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramFamilySigma.lean @@ -0,0 +1,140 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamily + +/-! +# The message-grouped form of the pretty-good-measurement error estimate + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability), the pretty-good decoder acts on the whole codebook at once: its Gram +operator is built from the **global** family of typical codeword eigenvectors, indexed by the pair +`c = (M, κ)` of a message `M` and a conditional-typical eigenindex `κ ∈ T_M`. The codeword-family +error bound `InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` (N&C eq. (12.94)) +therefore fires at this global index and bounds the total decoding deficit + +`2·∑_c λ_c (1 − α_c)`, `α_c = re⟪e_c, √Γ e_c⟫`, `Γ = V⋆·V`, `V = synthesisMap ψ`, + +by three right-hand frame sums over the global family. + +To feed each of those sums into the *per-message* physical trace identities of the achievability +proof (`3·tr(σ_M(1−P))`, `∑_{M'≠M} tr(P σ_M P P_{M'})`, `tr(σ_M(1−P_M))`, N&C eqs. (12.95), +(12.79)), the global sums must be **grouped by the message** `M`, and the double sum +`∑_c ∑_{c'} λ_c |⟪ψ_c, ψ_{c'}⟫|²` split — for each block `M` — into the **same-message diagonal** +`M' = M` (matched by the same-message spur bound) plus the **cross-message** off-diagonal `M' ≠ M` +(matched by the confusion bound). + +## What this file provides + +* `InnerProductSpace.two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma` — the codeword-family + error bound `two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` restated over a **sigma index** + `Σ a, γ a` + (the block index `a` being the message `M`, and `γ a` the block's eigenindex set `T_M`), with its + right-hand side regrouped by the block `a`: the eigenvalue mass and the diagonal `‖ψ_c‖²` weight + collect per block, and the frame double sum splits into the same-block part + `∑_{κ,κ' in block a} λ |⟪ψ_{a,κ}, ψ_{a,κ'}⟫|²` and the off-block part + `∑_{a'≠a} ∑_{κ in a, κ' in a'} λ |⟪ψ_{a,κ}, ψ_{a',κ'}⟫|²`. + + The left-hand side is unchanged (the total deficit `2·∑_c λ_c (1 − α_c)` over the sigma index; + regroup it as `∑_a ∑_κ` with `Fintype.sum_sigma` at the point of use). + +## Proof + +Purely the block-grouping of the flat bound `two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le`. Each +of its three right-hand sums is turned into a sum over the block index by `Fintype.sum_sigma`; the +`2·` and `−3·` scalars distribute into the block sum (`Finset.mul_sum`) and the three block sums +recombine into one (`Finset.sum_sub_distrib`, `Finset.sum_add_distrib`). Inside a block, the inner +factor `∑_{c'} λ_{a,κ} |⟪ψ_{a,κ}, ψ_{c'}⟫|²` is likewise `Fintype.sum_sigma`'d and its outer block +sum split off the diagonal term with `Finset.add_sum_erase`; a `Finset.sum_comm` moves the block +sum outside the eigenindex sum, and `ring` reassembles the block term. + +The flat codeword-family bound it regroups is in +`ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamily`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + Theorem 12.8, Box 12.5, eqs. (12.94), (12.95), (12.79). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace InnerProductSpace + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {γ : ι → Type*} [∀ a, Fintype (γ a)] + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] + [CompleteSpace G] + +/-- **The message-grouped codeword-family form of the pretty-good-measurement error estimate** +(Nielsen & Chuang, Box 12.5, eqs. (12.94)→(12.95), block-grouped by message). For a family +`ψ : (Σ a, γ a) → G` over a sigma index — the block index `a` being Nielsen & Chuang's message `M` +and `γ a` the block's conditional-typical eigenindex set `T_M` — with synthesis operator +`V = synthesisMap ψ`, Gram operator `Γ = V⋆·V`, and nonnegative real weights `λ : (Σ a, γ a) → ℝ`, + +`2·∑_c λ_c (1 − re⟪e_c, √Γ e_c⟫)` +` ≤ ∑_a [ (2·∑_κ λ_{a,κ} − 3·∑_κ λ_{a,κ}‖ψ_{a,κ}‖² + ∑_κ λ_{a,κ} ∑_{κ'} |⟪ψ_{a,κ}, ψ_{a,κ'}⟫|²)` +` + ∑_{a'≠a} ∑_κ λ_{a,κ} ∑_{κ'} |⟪ψ_{a,κ}, ψ_{a',κ'}⟫|² ]`, + +where `c = (a, κ)` ranges over the sigma index, `e_c` are the standard basis vectors of +`EuclideanSpace ℂ (Σ a, γ a)`, `√Γ = cfc Real.sqrt Γ`, and `α_c = re⟪e_c, √Γ e_c⟫` is Nielsen & +Chuang's diagonal decoding overlap `α_{(M,K),(M,K)}` (Box 12.5, `Γ^{1/2} = [α]`). + +This is `two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` at the sigma-indexed family, with the three +right-hand frame sums grouped by the block `a`. The bracketed per-block term separates the +**same-message** part (the diagonal `a' = a`, whose three sums are bounded by the same-message spur +bound at codeword `σ_M`) from the **cross-message** part (`a' ≠ a`, whose off-diagonal frame double +sum is bounded, per pair `(M, M')`, by the confusion bound). The left-hand side is the total +decoding deficit `2·∑_c λ_c(1 − α_c)`; regroup it as `∑_a ∑_κ` with `Fintype.sum_sigma` where the +per-message left-hand side is wanted. -/ +theorem two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le_sigma + (ψ : (Σ a, γ a) → G) (lam : (Σ a, γ a) → ℝ) (hlam : ∀ p, 0 ≤ lam p) : + 2 * ∑ p, lam p * (1 - RCLike.re (inner ℂ (EuclideanSpace.basisFun (Σ a, γ a) ℂ p) + ((cfc Real.sqrt ((adjoint (synthesisMap ψ)).comp (synthesisMap ψ))) + (EuclideanSpace.basisFun (Σ a, γ a) ℂ p)))) + ≤ ∑ a, ((2 * ∑ κ : γ a, lam ⟨a, κ⟩ + - 3 * ∑ κ : γ a, lam ⟨a, κ⟩ * ‖ψ ⟨a, κ⟩‖ ^ 2 + + ∑ κ : γ a, lam ⟨a, κ⟩ * ∑ κ' : γ a, ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a, κ'⟩)‖ ^ 2) + + ∑ a' ∈ Finset.univ.erase a, ∑ κ : γ a, lam ⟨a, κ⟩ + * ∑ κ' : γ a', ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a', κ'⟩)‖ ^ 2) := by + refine (two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le ψ lam hlam).trans (le_of_eq ?_) + -- Group each of the three right-hand sums of the flat bound by the block index `a`. + rw [Fintype.sum_sigma (fun p => lam p), Fintype.sum_sigma (fun p => lam p * ‖ψ p‖ ^ 2), + Fintype.sum_sigma (fun p => ∑ q, lam p * ‖inner ℂ (ψ p) (ψ q)‖ ^ 2), + Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun a _ => ?_ + -- Split the block's frame double sum into its same-block diagonal and off-block parts. + have hthird : (∑ κ : γ a, ∑ q, lam ⟨a, κ⟩ * ‖inner ℂ (ψ ⟨a, κ⟩) (ψ q)‖ ^ 2) + = (∑ κ : γ a, lam ⟨a, κ⟩ * ∑ κ' : γ a, ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a, κ'⟩)‖ ^ 2) + + ∑ a' ∈ Finset.univ.erase a, ∑ κ : γ a, lam ⟨a, κ⟩ + * ∑ κ' : γ a', ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a', κ'⟩)‖ ^ 2 := by + have hperκ : ∀ κ : γ a, (∑ q, lam ⟨a, κ⟩ * ‖inner ℂ (ψ ⟨a, κ⟩) (ψ q)‖ ^ 2) + = lam ⟨a, κ⟩ * ∑ κ' : γ a, ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a, κ'⟩)‖ ^ 2 + + lam ⟨a, κ⟩ * ∑ a' ∈ Finset.univ.erase a, + ∑ κ' : γ a', ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a', κ'⟩)‖ ^ 2 := fun κ => by + rw [← Finset.mul_sum, Fintype.sum_sigma (fun q => ‖inner ℂ (ψ ⟨a, κ⟩) (ψ q)‖ ^ 2), + ← Finset.add_sum_erase Finset.univ + (fun a' => ∑ κ' : γ a', ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a', κ'⟩)‖ ^ 2) (Finset.mem_univ a), + mul_add] + rw [Finset.sum_congr rfl (fun κ _ => hperκ κ), Finset.sum_add_distrib] + congr 1 + -- Move the off-block sum outside the eigenindex sum. + rw [Finset.sum_congr rfl fun κ (_ : κ ∈ Finset.univ) => + Finset.mul_sum (Finset.univ.erase a) + (fun a' => ∑ κ' : γ a', ‖inner ℂ (ψ ⟨a, κ⟩) (ψ ⟨a', κ'⟩)‖ ^ 2) (lam ⟨a, κ⟩), + Finset.sum_comm] + rw [hthird]; ring + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramTrace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramTrace.lean new file mode 100644 index 0000000000..daa097aef8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtGramTrace.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtTraceInequality + +/-! +# The Gram-operator trace form of the pretty-good-measurement error estimate + +For a continuous linear map `V : F →L[ℂ] G` between finite-dimensional complex Hilbert spaces — +whose columns are the (typical-subspace–compressed) codeword eigenvectors `|E_tilde_c⟩` of Nielsen & +Chuang's Box 12.5 — with **total operator** `S = V ∘ V⋆` on `G` and **Gram operator** +`Γ = V⋆ ∘ V` on `F`, this file evaluates the two "spurs" on the right-hand side of the trace form +of the square-root operator inequality (`CFCSqrtTraceInequality`, N&C eqs. (12.92)–(12.93)) as +**physical traces** of `S` and of the eigenvalue-weighted operator `T = V ∘ Λ ∘ V⋆` on `G`. + +Writing `sp = tr_F` for the trace on the index space `F` (Nielsen & Chuang's "spur") and `tr = tr_G` +for the trace on the ambient (physical) space `G`, and `Λ ≥ 0` for the diagonal eigenvalue-weight +operator on `F`, cross-space trace cyclicity (`LinearMap.trace_comp_comm'`) gives + +`sp(Λ(1 - Γ)) = tr_F Λ − tr(V Λ V⋆)`, +`sp(Λ(1 - Γ)²) = tr_F Λ − 2·tr(V Λ V⋆) + tr(S · V Λ V⋆)`, + +so, feeding these into the trace inequality `2·sp(Λ(1 - √Γ)) ≤ sp(Λ(1 - Γ)²) + sp(Λ(1 - Γ))` +(`ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace`), the decoding deficit +`sp(Λ(1 - √Γ))` of the pretty-good (square-root) POVM is bounded by physical traces: + +`2·re sp(Λ(1 - √Γ)) ≤ 2·re tr_F Λ − 3·re tr(V Λ V⋆) + re tr(S · V Λ V⋆)`. + +This is the operator-trace form of the "calculating the spurs" step of **Nielsen & Chuang's Box +12.5** (eq. (12.94)), the achievability half of the **Holevo–Schumacher–Westmoreland theorem** +(`χ(E) = C⁽¹⁾(E)`, N&C Theorem 12.8): each of the three physical traces `tr_F Λ`, `tr(V Λ V⋆)`, +`tr(S · V Λ V⋆)` becomes — once `V`, `Λ` are instantiated to the concrete codeword-eigenvector +apparatus — one of the physical error terms `tr(σ_M(I − P))`, `tr(P σ_M P P_{M'})`, +`tr(σ_M(I − P_M))` of the random-coding error estimate (12.79). + +## What this file provides + +* `ContinuousLinearMap.trace_gram_mul` — the cross-space cyclicity core + `tr_F((V⋆·V)·A) = tr_G(V·A·V⋆)`: pairing the Gram operator `Γ = V⋆·V` against any `A` on `F` + equals pairing `A` conjugated by `V` (i.e. `V·A·V⋆`) on `G`. +* `ContinuousLinearMap.trace_one_sub_gram_mul` — the **linear spur** + `tr_F((1 - Γ)·Λ) = tr_F Λ − tr_G(V·Λ·V⋆)` (N&C `sp(Λ(E − Γ))`). +* `ContinuousLinearMap.trace_one_sub_gram_sq_mul` — the **quadratic spur** + `tr_F((1 - Γ)²·Λ) = tr_F Λ − 2·tr_G(V·Λ·V⋆) + tr_G(S·(V·Λ·V⋆))` (N&C `sp(Λ(E − Γ)²)`). +* `ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_gram_le` — the **headline bound** + `2·re tr_F((1 - √Γ)·Λ) ≤ 2·re tr_F Λ − 3·re tr_G(V·Λ·V⋆) + re tr_G(S·(V·Λ·V⋆))` (N&C eq. (12.94)), + the trace inequality with its right-hand side evaluated into physical traces. + +## Proof + +The two spur identities are cross-space trace cyclicity: `Γ·A = V⋆·(V·A)` and +`tr_F(V⋆·(V·A)) = tr_G((V·A)·V⋆) = tr_G(V·A·V⋆)` (`LinearMap.trace_comp_comm'`); expanding +`(1 - Γ)·Λ` and `(1 - Γ)²·Λ` (`noncomm_ring`) and applying this to each `Γ`-power term, together +with the linearity of the trace, gives the identities. The headline bound rewrites the spurs of the +trace inequality `two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace` (whose hypothesis +`0 ≤ Γ = V⋆·V` is automatic, `isPositive_self_comp_adjoint`) and collects the real parts. + +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace ContinuousLinearMap + +variable {F G : Type*} + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +/-- **Cyclicity against the Gram operator.** For `V : F →L[ℂ] G` with Gram operator +`Γ = V⋆ ∘ V` on `F`, and any `A : F →L[ℂ] F`, + +`tr_F(Γ · A) = tr_G(V · A · V⋆)`, + +i.e. pairing the Gram operator against `A` on the index space `F` equals the trace of `A` +conjugated by `V` on the ambient space `G`. Immediate from the cyclicity identity +`ContinuousLinearMap.trace_conj_adjoint` (`tr_G(V·A·V⋆) = tr_F(V⋆·V·A)`) after folding +`Γ · A = V⋆ · (V · A)`. -/ +theorem trace_gram_mul (V : F →L[ℂ] G) (A : F →L[ℂ] F) : + LinearMap.trace ℂ F ((((adjoint V).comp V) * A : F →L[ℂ] F) : F →ₗ[ℂ] F) + = LinearMap.trace ℂ G ((V.comp (A.comp (adjoint V)) : G →L[ℂ] G) : G →ₗ[ℂ] G) := by + have h : (((adjoint V).comp V) * A : F →L[ℂ] F) = (adjoint V).comp (V.comp A) := by + rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_assoc] + rw [h] + exact (ContinuousLinearMap.trace_conj_adjoint V A).symm + +/-- **The linear spur of the Gram trace form** (Nielsen & Chuang, Box 12.5, `sp(Λ(E − Γ))`). For +`V : F →L[ℂ] G` with Gram operator `Γ = V⋆ ∘ V`, and `Λ : F →L[ℂ] F`, + +`tr_F((1 - Γ)·Λ) = tr_F Λ − tr_G(V·Λ·V⋆)`. + +The `1`-term of the trace is `tr_F Λ`; the `Γ`-term is carried to the ambient space by +`trace_gram_mul`. -/ +theorem trace_one_sub_gram_mul (V : F →L[ℂ] G) (Λ : F →L[ℂ] F) : + LinearMap.trace ℂ F (((1 - (adjoint V).comp V) * Λ : F →L[ℂ] F) : F →ₗ[ℂ] F) + = LinearMap.trace ℂ F (Λ : F →ₗ[ℂ] F) + - LinearMap.trace ℂ G ((V.comp (Λ.comp (adjoint V)) : G →L[ℂ] G) : G →ₗ[ℂ] G) := by + have hexp : ((1 - (adjoint V).comp V) * Λ : F →L[ℂ] F) + = Λ - ((adjoint V).comp V) * Λ := by noncomm_ring + rw [hexp, ContinuousLinearMap.toLinearMap_sub, map_sub, trace_gram_mul] + +/-- **The quadratic spur of the Gram trace form** (Nielsen & Chuang, Box 12.5, `sp(Λ(E − Γ)²)`). +For `V : F →L[ℂ] G` with total operator `S = V ∘ V⋆`, Gram operator `Γ = V⋆ ∘ V`, and +`Λ : F →L[ℂ] F`, + +`tr_F((1 - Γ)²·Λ) = tr_F Λ − 2·tr_G(V·Λ·V⋆) + tr_G(S·(V·Λ·V⋆))`. + +Expanding `(1 - Γ)²·Λ = Λ − Γ·Λ − Γ·Λ + Γ·(Γ·Λ)` (`noncomm_ring`), the two `Γ·Λ` terms are each +`trace_gram_mul` (giving `tr_G(V·Λ·V⋆)`), and the `Γ·(Γ·Λ)` term is `trace_gram_mul` applied to +`A = Γ·Λ`, whose conjugation `V·(Γ·Λ)·V⋆` folds to `S·(V·Λ·V⋆)`. -/ +theorem trace_one_sub_gram_sq_mul (V : F →L[ℂ] G) (Λ : F →L[ℂ] F) : + LinearMap.trace ℂ F (((1 - (adjoint V).comp V) ^ 2 * Λ : F →L[ℂ] F) : F →ₗ[ℂ] F) + = LinearMap.trace ℂ F (Λ : F →ₗ[ℂ] F) + - LinearMap.trace ℂ G ((V.comp (Λ.comp (adjoint V)) : G →L[ℂ] G) : G →ₗ[ℂ] G) + - LinearMap.trace ℂ G ((V.comp (Λ.comp (adjoint V)) : G →L[ℂ] G) : G →ₗ[ℂ] G) + + LinearMap.trace ℂ G + (((V.comp (adjoint V)).comp (V.comp (Λ.comp (adjoint V))) : G →L[ℂ] G) + : G →ₗ[ℂ] G) := by + have hexp : ((1 - (adjoint V).comp V) ^ 2 * Λ : F →L[ℂ] F) + = Λ - ((adjoint V).comp V) * Λ - ((adjoint V).comp V) * Λ + + ((adjoint V).comp V) * (((adjoint V).comp V) * Λ) := by noncomm_ring + -- the folding of the conjugated double-Gram term to `S · (V·Λ·V⋆)` + have hfold : V.comp ((((adjoint V).comp V) * Λ).comp (adjoint V)) + = (V.comp (adjoint V)).comp (V.comp (Λ.comp (adjoint V))) := by + simp only [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_assoc] + rw [hexp, ContinuousLinearMap.toLinearMap_add, ContinuousLinearMap.toLinearMap_sub, + ContinuousLinearMap.toLinearMap_sub, + map_add, map_sub, map_sub, trace_gram_mul, trace_gram_mul (A := ((adjoint V).comp V) * Λ), + hfold] + +/-- **The Gram-operator trace form of the pretty-good-measurement error estimate** +(Nielsen & Chuang, Box 12.5, eq. (12.94)). For `V : F →L[ℂ] G` with total operator `S = V ∘ V⋆`, +Gram operator `Γ = V⋆ ∘ V`, and a positive weight `Λ ≥ 0` on `F`, + +`2·re tr_F((1 - √Γ)·Λ) ≤ 2·re tr_F Λ − 3·re tr_G(V·Λ·V⋆) + re tr_G(S·(V·Λ·V⋆))`, + +where `√Γ = cfc Real.sqrt Γ`. This is the trace inequality +`2·re tr_F((1 - √Γ)·Λ) ≤ re tr_F((1 - Γ)²·Λ) + re tr_F((1 - Γ)·Λ)` +(`two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace`, whose hypothesis `0 ≤ Γ = V⋆·V` is +automatic) with its right-hand-side spurs evaluated as physical traces of `S` and `T = V·Λ·V⋆` +(`trace_one_sub_gram_sq_mul`, `trace_one_sub_gram_mul`). The decoding deficit `sp(Λ(1 - √Γ))` of +the pretty-good (square-root) POVM is thereby bounded by physical operator traces, ready for the +concrete codeword-eigenvector instantiation of the random-coding error estimate (12.79). -/ +theorem two_mul_re_trace_one_sub_cfc_sqrt_gram_le (V : F →L[ℂ] G) {Λ : F →L[ℂ] F} (hΛ : 0 ≤ Λ) : + 2 * RCLike.re (LinearMap.trace ℂ F + (((1 - cfc Real.sqrt ((adjoint V).comp V)) * Λ : F →L[ℂ] F) : F →ₗ[ℂ] F)) + ≤ 2 * RCLike.re (LinearMap.trace ℂ F (Λ : F →ₗ[ℂ] F)) + - 3 * RCLike.re (LinearMap.trace ℂ G ((V.comp (Λ.comp (adjoint V)) : G →L[ℂ] G) + : G →ₗ[ℂ] G)) + + RCLike.re (LinearMap.trace ℂ G + (((V.comp (adjoint V)).comp (V.comp (Λ.comp (adjoint V))) : G →L[ℂ] G) + : G →ₗ[ℂ] G)) := by + have hΓ : 0 ≤ (adjoint V).comp V := by + have h := isPositive_self_comp_adjoint (adjoint V) + rw [adjoint_adjoint] at h + exact nonneg_iff_isPositive.mpr h + have h := two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace hΓ hΛ + rw [trace_one_sub_gram_sq_mul, trace_one_sub_gram_mul] at h + simp only [map_add, map_sub] at h + linarith + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtInequality.lean new file mode 100644 index 0000000000..b47095144b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtInequality.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC + +/-! +# The square-root operator inequality of the pretty-good-measurement error estimate + +For a positive operator `A ≥ 0` on a complex Hilbert space, this file records the +functional-calculus operator inequality + +`2 • (1 - √A) ≤ (1 - A)² + (1 - A)` + +(with `√A = cfc Real.sqrt A` the operator square root). It is the crux operator inequality of the +error estimate for the **pretty-good (square-root) measurement** — Nielsen & Chuang's Box 12.5, +eqs. (12.89)–(12.91), used to bound the average decoding error in the achievability half of the +**Holevo–Schumacher–Westmoreland theorem** (`χ(E) = C⁽¹⁾(E)`, N&C Theorem 12.8). There it is +applied to the Gram operator `Γ` of the (typical-subspace–compressed) codeword eigenvectors: the +diagonal decoding overlap `α_{(M,K),(M,K)}` is `⟨E_tilde| Γ^{-1/2} |E_tilde⟩`-shaped, and +controlling `1 - α` +reduces — via `2(1 - √Γ) ≤ (1 - Γ)² + (1 - Γ)` — to the "false-decoding" cross terms that the +random-coding average then makes decay. + +## What this file provides + +* `ContinuousLinearMap.two_smul_one_sub_cfc_sqrt_le` — the operator inequality + `2 • (1 - √A) ≤ (1 - A)² + (1 - A)` for `0 ≤ A`. + +## Proof + +Both sides are continuous-functional-calculus images of `A`, so the operator inequality follows from +the **scalar** inequality `2(1 - √x) ≤ (1 - x)² + (1 - x)` on the (nonnegative) spectrum of `A` by +`cfc_mono`. The scalar inequality is the nonnegativity, for `x ≥ 0`, of + +`(1 - x)² + (1 - x) - 2(1 - √x) = √x · (√x - 1)² · (√x + 2) = x² - 3x + 2√x ≥ 0` + +(writing `s = √x`, the difference is `s⁴ - 3s² + 2s = s (s - 1)² (s + 2)`). This sidesteps +Nielsen & Chuang's algebraic route through `(1 + √Γ)⁻²` entirely: `cfc_mono` needs only the +pointwise scalar bound, and continuity on the spectrum is automatic (the functions are continuous +on all of `ℝ`). + +-/ + +@[expose] public section + +open ContinuousFunctionalCalculus + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +/-- **The square-root operator inequality of the pretty-good-measurement error estimate** +(Nielsen & Chuang, Box 12.5, eqs. (12.89)–(12.91)): for a positive operator `A ≥ 0`, + +`2 • (1 - √A) ≤ (1 - A)² + (1 - A)`, + +where `√A = cfc Real.sqrt A`. It is the operator inequality that turns the diagonal decoding +overlap `1 - α` of the pretty-good (square-root) measurement into the "false-decoding" cross terms +of the HSW random-coding error bound. + +The proof lifts the scalar inequality `2(1 - √x) ≤ (1 - x)² + (1 - x)` (valid for every `x ≥ 0`, +since the difference is `√x · (√x - 1)² · (√x + 2) = x² - 3x + 2√x ≥ 0`) through `cfc_mono`: the +spectrum of `A ≥ 0` is nonnegative (`spectrum_nonneg_of_nonneg`), and continuity on the spectrum is +free (the functions are continuous on all of `ℝ`). Both `cfc` images are then rewritten to closed +operator form via the `cfc` ring homomorphism lemmas. -/ +theorem two_smul_one_sub_cfc_sqrt_le {A : E →L[ℂ] E} (hA : 0 ≤ A) : + (2 : ℝ) • (1 - cfc Real.sqrt A) ≤ (1 - A) ^ 2 + (1 - A) := by + -- The scalar inequality `2(1 - √x) ≤ (1 - x)² + (1 - x)` on the nonnegative spectrum of `A`. + have hscal : ∀ x ∈ spectrum ℝ A, 2 * (1 - Real.sqrt x) ≤ (1 - x) ^ 2 + (1 - x) := fun x hx => by + have hx0 : 0 ≤ x := spectrum_nonneg_of_nonneg hA hx + have hs : Real.sqrt x ^ 2 = x := Real.sq_sqrt hx0 + have hsnn : 0 ≤ Real.sqrt x := Real.sqrt_nonneg x + -- The difference is `√x · (√x - 1)² · (√x + 2)`: multiply the hint `(√x - 1)²(√x + 2) ≥ 0` + -- by `√x ≥ 0`. + nlinarith [mul_nonneg (sq_nonneg (Real.sqrt x - 1)) (by linarith : (0 : ℝ) ≤ Real.sqrt x + 2), + hs, hsnn] + -- Lift to operators by CFC monotonicity; the functions are continuous on all of `ℝ`. + have key := cfc_mono (a := A) (f := fun x => 2 * (1 - Real.sqrt x)) + (g := fun x => (1 - x) ^ 2 + (1 - x)) hscal + ((continuous_const.mul (continuous_const.sub Real.continuous_sqrt)).continuousOn) + (by fun_prop) + -- Translate both `cfc` images to closed operator form. + have h1sub : cfc (fun x : ℝ => 1 - x) A = 1 - A := by + rw [cfc_sub (fun _ => (1 : ℝ)) (fun x => x) A (by fun_prop) (by fun_prop), + cfc_const 1 A, map_one, cfc_id' ℝ A] + have hL : cfc (fun x : ℝ => 2 * (1 - Real.sqrt x)) A = (2 : ℝ) • (1 - cfc Real.sqrt A) := by + rw [cfc_const_mul (2 : ℝ) (fun x => 1 - Real.sqrt x) A + ((continuous_const.sub Real.continuous_sqrt).continuousOn)] + congr 1 + rw [cfc_sub (fun _ => (1 : ℝ)) Real.sqrt A (by fun_prop) Real.continuous_sqrt.continuousOn, + cfc_const 1 A, map_one] + have hR : cfc (fun x : ℝ => (1 - x) ^ 2 + (1 - x)) A = (1 - A) ^ 2 + (1 - A) := by + rw [cfc_add A (fun x => (1 - x) ^ 2) (fun x => 1 - x) (by fun_prop) (by fun_prop), + cfc_pow (fun x => 1 - x) 2 A (by fun_prop), h1sub] + rw [hL, hR] at key + exact key + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtTraceInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtTraceInequality.lean new file mode 100644 index 0000000000..e8c8ea7ce6 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCSqrtTraceInequality.lean @@ -0,0 +1,117 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# The trace form of the pretty-good-measurement square-root operator inequality + +For positive operators `Γ ≥ 0` and `Λ ≥ 0` on a finite-dimensional complex Hilbert space, this file +records the **weighted-trace** consequence of the square-root operator inequality +`2 • (1 - √Γ) ≤ (1 - Γ)² + (1 - Γ)` (`ContinuousLinearMap.two_smul_one_sub_cfc_sqrt_le`): + +`2 · re tr((1 - √Γ)·Λ) ≤ re tr(((1 - Γ)² + (1 - Γ))·Λ)` + +(with `√Γ = cfc Real.sqrt Γ` the operator square root). It is the trace step of the error estimate +for the **pretty-good (square-root) measurement** — Nielsen & Chuang's Box 12.5, the transition from +the operator inequality (12.89)–(12.91) to the trace inequality (12.92)–(12.93), used to bound the +average decoding error in the achievability half of the +**Holevo–Schumacher–Westmoreland theorem** (`χ(E) = C⁽¹⁾(E)`, N&C Theorem 12.8). + +There the operator `Γ` is the Gram operator of the (typical-subspace–compressed) codeword +eigenvectors `|E_tilde_c⟩`, `Λ = diag(λ_c) ≥ 0` is the diagonal of codeword eigenvalue weights, +and the +"correct-decoding deficit" of the square-root POVM is `∑_c λ_c(1 - α_{cc}) = sp(Λ(1 - Γ^{1/2}))` +where `α = Γ^{1/2}`. The inequality below is N&C's + +`2 · sp(Λ(E - Γ^{1/2})) ≤ sp(Λ(E - Γ)²) + sp(Λ(E - Γ))` (N&C eqs. (12.92)–(12.93)), + +now with a *general* positive weight `Λ` in place of a diagonal one, and the "spur" `sp` read as +`re tr` on the ambient Hilbert space (by trace cyclicity, `re tr((1 - √Γ)·Λ) = re tr(Λ·(1 - √Γ))`, +so the weight may be placed on either side). + +## What this file provides + +* `ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_mul_le` — the trace inequality + `2 · re tr((1 - √Γ)·Λ) ≤ re tr(((1 - Γ)² + (1 - Γ))·Λ)` (eqs. (12.92)–(12.93), combined RHS). + +* `ContinuousLinearMap.two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace` — the same bound with + the right-hand side split into the two separate traces `re tr((1 - Γ)²·Λ) + re tr((1 - Γ)·Λ)`, as + N&C write it at (12.93); this is the directly-consumable form (each trace becomes one of the + physical terms `tr(σ_M(I - P))`, `tr(P σ_M P P_{M'})`, … of the error estimate (12.79)). + +## Proof + +Both are one step of trace monotonicity on top of the operator inequality. Pairing against a +positive operator `Λ` is monotone in the Loewner order (`re_trace_mul_mono_left`: +`A ≤ B`, `0 ≤ Λ` ⟹ `re tr(A·Λ) ≤ re tr(B·Λ)`), so applying it to +`two_smul_one_sub_cfc_sqrt_le` with `A = 2 • (1 - √Γ)` and `B = (1 - Γ)² + (1 - Γ)` gives +`re tr((2 • (1 - √Γ))·Λ) ≤ re tr(((1 - Γ)² + (1 - Γ))·Λ)`. Unfolding `2 • x = x + x` +(`two_smul`) and distributing the trace and the real part (`map_add`) turns the left-hand side into +`2 · re tr((1 - √Γ)·Λ)`. The split form distributes the trace over the sum `(1 - Γ)² + (1 - Γ)` +once more. + +-/ + +@[expose] public section + +open scoped InnerProductSpace + +noncomputable section + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **The trace form of the pretty-good-measurement square-root operator inequality** +(Nielsen & Chuang, Box 12.5, eqs. (12.92)–(12.93)): for positive operators `Γ ≥ 0` and `Λ ≥ 0`, + +`2 · re tr((1 - √Γ)·Λ) ≤ re tr(((1 - Γ)² + (1 - Γ))·Λ)`, + +where `√Γ = cfc Real.sqrt Γ`. It is the weighted trace of the square-root operator inequality +`2 • (1 - √Γ) ≤ (1 - Γ)² + (1 - Γ)` (`two_smul_one_sub_cfc_sqrt_le`), the step that turns the +correct-decoding deficit `sp(Λ(E - Γ^{1/2}))` of the pretty-good (square-root) POVM into the +"false-decoding" cross terms of the HSW random-coding error estimate. + +Proof: pairing against `Λ ≥ 0` is monotone in the Loewner order (`re_trace_mul_mono_left`), so it +carries `two_smul_one_sub_cfc_sqrt_le` to `re tr((2 • (1 - √Γ))·Λ) ≤ re tr(((1 - Γ)² + (1 - Γ))·Λ)`; +`two_smul` and the additivity of the trace and the real part then rewrite the left-hand side as +`2 · re tr((1 - √Γ)·Λ)`. -/ +theorem two_mul_re_trace_one_sub_cfc_sqrt_mul_le {Γ Λ : E →L[ℂ] E} (hΓ : 0 ≤ Γ) (hΛ : 0 ≤ Λ) : + 2 * RCLike.re (LinearMap.trace ℂ E (((1 - cfc Real.sqrt Γ) * Λ : E →L[ℂ] E) : E →ₗ[ℂ] E)) + ≤ RCLike.re (LinearMap.trace ℂ E + ((((1 - Γ) ^ 2 + (1 - Γ)) * Λ : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + have hmono := re_trace_mul_mono_left (two_smul_one_sub_cfc_sqrt_le hΓ) hΛ + rw [two_smul, add_mul, ContinuousLinearMap.toLinearMap_add, map_add, map_add] at hmono + linarith [hmono] + +/-- **The trace form of the pretty-good-measurement square-root operator inequality, split +right-hand side** (Nielsen & Chuang, Box 12.5, eq. (12.93)): for positive operators `Γ ≥ 0` and +`Λ ≥ 0`, + +`2 · re tr((1 - √Γ)·Λ) ≤ re tr((1 - Γ)²·Λ) + re tr((1 - Γ)·Λ)`. + +The right-hand side of `two_mul_re_trace_one_sub_cfc_sqrt_mul_le` split into its two summands +`sp(Λ(E - Γ)²)` and `sp(Λ(E - Γ))`, as N&C write it — the form in which each trace becomes a single +physical term of the random-coding error estimate. Immediate from +`two_mul_re_trace_one_sub_cfc_sqrt_mul_le` by distributing the trace and the real part over the sum +`(1 - Γ)² + (1 - Γ)`. -/ +theorem two_mul_re_trace_one_sub_cfc_sqrt_mul_le_add_re_trace {Γ Λ : E →L[ℂ] E} (hΓ : 0 ≤ Γ) + (hΛ : 0 ≤ Λ) : + 2 * RCLike.re (LinearMap.trace ℂ E (((1 - cfc Real.sqrt Γ) * Λ : E →L[ℂ] E) : E →ₗ[ℂ] E)) + ≤ RCLike.re (LinearMap.trace ℂ E (((1 - Γ) ^ 2 * Λ : E →L[ℂ] E) : E →ₗ[ℂ] E)) + + RCLike.re (LinearMap.trace ℂ E (((1 - Γ) * Λ : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + have h := two_mul_re_trace_one_sub_cfc_sqrt_mul_le hΓ hΛ + rw [add_mul, ContinuousLinearMap.toLinearMap_add, map_add, map_add] at h + linarith [h] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCTensor.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCTensor.lean new file mode 100644 index 0000000000..472417f3ab --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/CFCTensor.lean @@ -0,0 +1,264 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorPower +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.GeometricMean +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.ConjSqrt +public import TauCeti.Analysis.InnerProductSpace.CourantFischer + +/-! +# CFC functions distribute over the tensor product (log, sqrt, conjSqrt, geometric mean) + +This file collects identities expressing how Continuous Functional Calculus operations on +operators distribute over `TensorProduct.mapL` on a finite-dim complex Hilbert space: + +* `log(A ⊗ B) = log A ⊗ I + I ⊗ log B` for strictly positive `A, B` (`cfc_log_tensorMap`). + The log identity requires spectral decomposition. +* `(A ⊗ B)^y = A^y ⊗ B^y` for strictly positive `A, B` (`cfc_rpow_const_tensorMap`). + Also spectral; uses `Real.mul_rpow` as the eigenvalue-level identity. +* `sqrt(A ⊗ B) = sqrt A ⊗ sqrt B` for `0 ≤ A, B` (`sqrt_mapL`). +* `conjSqrt(A ⊗ B, C ⊗ D) = conjSqrt A C ⊗ conjSqrt B D` for `0 ≤ A, B` (`conjSqrt_mapL`). +* `M₀(A₁ ⊗ A₂, B₁ ⊗ B₂) = M₀(A₁, B₁) ⊗ M₀(A₂, B₂)` for strictly positive `A_i`, nonneg + `B_i` (`geometricMean_mapL`). + +Plus the supporting algebraic facts: `mapL` preserves nonnegativity (`mapL_nonneg`), +positivity (`mapL_isPositive`), strict positivity (`mapL_isStrictlyPositive`), +invertibility (`isUnit_mapL`), and ring-inverse (`ringInverse_mapL`). + +## Main results + +- `IsSelfAdjoint.tensorMapL`: CLM-level analog of `IsSelfAdjoint.tensorMap` (LM-level). +- `IsSelfAdjoint.cfc_log_tensorMap`: the log additivity identity. +- `IsSelfAdjoint.cfc_rpow_const_tensorMap`: the rpow multiplicativity identity. +- `TensorProduct.geometricMean_mapL`: tensor distributivity of the operator geometric mean. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +/-! ### CLM-level self-adjointness of `TensorProduct.mapL` -/ + +/-- **CLM-level analog of `IsSelfAdjoint.tensorMap`** (LM-level): the tensor product of +self-adjoint continuous linear maps is self-adjoint. Restricted to `ℂ`-scalar because the CLM +`Star` instance `Star (E →L[𝕜] E)` only synthesizes for `𝕜 = ℂ` in current Mathlib. + +`(TensorProduct.mapL A B).toLinearMap` is no longer definitionally `TensorProduct.map ↑A ↑B` +(only propositionally, via the `@[simp]`-but-not-`rfl` `TensorProduct.toLinearMap_mapL`), so +naively applying `ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mpr` to a proof about +`TensorProduct.map ↑A ↑B` makes the elaborator try (and time out) unifying the two forms; +`rw`-ing the goal through `toLinearMap_mapL` first avoids that unification entirely. -/ +theorem IsSelfAdjoint.tensorMapL {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + {A : E →L[ℂ] E} {B : F →L[ℂ] F} (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) : + IsSelfAdjoint (TensorProduct.mapL A B) := by + rw [ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric, TensorProduct.toLinearMap_mapL] + exact LinearMap.IsSymmetric.tensorMap hA.isSymmetric hB.isSymmetric + +/-! ### Abstract `cfc_log_tensorMap` -/ + +namespace IsSelfAdjoint + +variable {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + +/-- **Operator log on a tensor product factors additively** (abstract): for positive +self-adjoint operators `A, B` (with strictly positive eigenvalues) on finite-dim complex +Hilbert spaces, `log(A ⊗ B) = log A ⊗ I + I ⊗ log B`. The identity follows from spectral +decomposition: on the joint eigenbasis `eA i ⊗ₜ eB j`, the LHS has eigenvalues `log(λᵢμⱼ)` +and the RHS has `log λᵢ + log μⱼ`, which agree by `Real.log_mul`. -/ +theorem cfc_log_tensorMap + {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) + {dE dF : ℕ} + (hdE : Module.finrank ℂ E = dE) (hdF : Module.finrank ℂ F = dF) + (hA_pos : ∀ i, 0 < hA.isSymmetric.eigenvalues hdE i) + (hB_pos : ∀ j, 0 < hB.isSymmetric.eigenvalues hdF j) : + cfc Real.log (TensorProduct.mapL A B) = + TensorProduct.mapL (cfc Real.log A) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log B) := by + have hev : (hA.tensorMapL hB).isSymmetric.eigenvalues + (rfl : Module.finrank ℂ (E ⊗[ℂ] F) = Module.finrank ℂ (E ⊗[ℂ] F)) = + (LinearMap.IsSymmetric.tensorMap hA.isSymmetric hB.isSymmetric).eigenvalues rfl := + LinearMap.IsSymmetric.eigenvalues_congr (TensorProduct.toLinearMap_mapL A B) _ _ _ + refine ContinuousLinearMap.coe_injective + ((OrthonormalBasis.tensorProduct (hA.isSymmetric.eigenvectorBasis hdE) + (hB.isSymmetric.eigenvectorBasis hdF)).toBasis.ext fun ⟨i, j⟩ ↦ ?_) + simp only [OrthonormalBasis.coe_toBasis, OrthonormalBasis.tensorProduct_apply, + ContinuousLinearMap.coe_coe] + have hmu : (TensorProduct.mapL A B) + (hA.isSymmetric.eigenvectorBasis hdE i ⊗ₜ[ℂ] hB.isSymmetric.eigenvectorBasis hdF j) = + ((hA.isSymmetric.eigenvalues hdE i * hB.isSymmetric.eigenvalues hdF j : ℝ) : ℂ) • + (hA.isSymmetric.eigenvectorBasis hdE i ⊗ₜ[ℂ] hB.isSymmetric.eigenvectorBasis hdF j) := by + rw [← ContinuousLinearMap.coe_coe, TensorProduct.toLinearMap_mapL] + exact LinearMap.IsSymmetric.tensorMap_apply_eigenvectorBasis_smul + hA.isSymmetric hB.isSymmetric hdE hdF i j + rw [(hA.tensorMapL hB).cfc_log_apply_smul_of_apply_eq_smul (n := Module.finrank ℂ (E ⊗[ℂ] F)) rfl + (fun k ↦ hev ▸ LinearMap.IsSymmetric.tensorMap_eigenvalues_pos + hA.isSymmetric hB.isSymmetric hdE hdF rfl hA_pos hB_pos k) hmu, + add_apply, TensorProduct.mapL_tmul, TensorProduct.mapL_tmul, + one_apply_eq_self, one_apply_eq_self, + hA.cfc_log_apply_eigenvectorBasis hdE hA_pos i, + hB.cfc_log_apply_eigenvectorBasis hdF hB_pos j, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, ← add_smul] + congr 1 + exact_mod_cast Real.log_mul (hA_pos i).ne' (hB_pos j).ne' + +/-- **Operator real-power on a tensor product factors multiplicatively** (abstract): for +positive self-adjoint operators `A, B` (with strictly positive eigenvalues) on finite-dim +complex Hilbert spaces and any exponent `y : ℝ`, `(A ⊗ B)^y = A^y ⊗ B^y`. The identity follows +from spectral decomposition: on the joint eigenbasis `eA i ⊗ₜ eB j`, the LHS has eigenvalues +`(λᵢμⱼ)^y` and the RHS has `λᵢ^y · μⱼ^y`, which agree by `Real.mul_rpow`. + +For the `^`-notation (`CFC.rpow`) form, bridge via `CFC.rpow_eq_cfc_real` (which rewrites +`a ^ y` to `cfc (fun x : ℝ ↦ x ^ y) a` for `0 ≤ a`). -/ +theorem cfc_rpow_const_tensorMap + {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) + {dE dF : ℕ} + (hdE : Module.finrank ℂ E = dE) (hdF : Module.finrank ℂ F = dF) + (hA_pos : ∀ i, 0 < hA.isSymmetric.eigenvalues hdE i) + (hB_pos : ∀ j, 0 < hB.isSymmetric.eigenvalues hdF j) (y : ℝ) : + cfc (fun x : ℝ ↦ x ^ y) (TensorProduct.mapL A B) = + TensorProduct.mapL (cfc (fun x : ℝ ↦ x ^ y) A) (cfc (fun x : ℝ ↦ x ^ y) B) := by + have hev : (hA.tensorMapL hB).isSymmetric.eigenvalues + (rfl : Module.finrank ℂ (E ⊗[ℂ] F) = Module.finrank ℂ (E ⊗[ℂ] F)) = + (LinearMap.IsSymmetric.tensorMap hA.isSymmetric hB.isSymmetric).eigenvalues rfl := + LinearMap.IsSymmetric.eigenvalues_congr (TensorProduct.toLinearMap_mapL A B) _ _ _ + refine ContinuousLinearMap.coe_injective + ((OrthonormalBasis.tensorProduct (hA.isSymmetric.eigenvectorBasis hdE) + (hB.isSymmetric.eigenvectorBasis hdF)).toBasis.ext fun ⟨i, j⟩ ↦ ?_) + simp only [OrthonormalBasis.coe_toBasis, OrthonormalBasis.tensorProduct_apply, + ContinuousLinearMap.coe_coe] + have hmu : (TensorProduct.mapL A B) + (hA.isSymmetric.eigenvectorBasis hdE i ⊗ₜ[ℂ] hB.isSymmetric.eigenvectorBasis hdF j) = + ((hA.isSymmetric.eigenvalues hdE i * hB.isSymmetric.eigenvalues hdF j : ℝ) : ℂ) • + (hA.isSymmetric.eigenvectorBasis hdE i ⊗ₜ[ℂ] hB.isSymmetric.eigenvectorBasis hdF j) := by + rw [← ContinuousLinearMap.coe_coe, TensorProduct.toLinearMap_mapL] + exact LinearMap.IsSymmetric.tensorMap_apply_eigenvectorBasis_smul + hA.isSymmetric hB.isSymmetric hdE hdF i j + rw [(hA.tensorMapL hB).cfc_rpow_const_apply_smul_of_apply_eq_smul + (n := Module.finrank ℂ (E ⊗[ℂ] F)) rfl + (fun k ↦ hev ▸ LinearMap.IsSymmetric.tensorMap_eigenvalues_pos + hA.isSymmetric hB.isSymmetric hdE hdF rfl hA_pos hB_pos k) y hmu, + TensorProduct.mapL_tmul, + hA.cfc_rpow_const_apply_eigenvectorBasis hdE hA_pos y i, + hB.cfc_rpow_const_apply_eigenvectorBasis hdF hB_pos y j, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, smul_smul] + congr 1 + exact_mod_cast Real.mul_rpow (hA_pos i).le (hB_pos j).le + +end IsSelfAdjoint + +/-! ### `TensorProduct.mapL`-nonneg + CFC-tensor distributivity (sqrt, ringInverse, conjSqrt, M₀) -/ + +namespace TensorProduct + +variable {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + +omit [FiniteDimensional ℂ E] [FiniteDimensional ℂ F] in +/-- The tensor product preserves invertibility: `IsUnit (mapL A B)` for invertible `A, B`, +with explicit inverse `mapL (Ring.inverse A) (Ring.inverse B)`. -/ +theorem isUnit_mapL {A : E →L[ℂ] E} {B : F →L[ℂ] F} (hA : IsUnit A) (hB : IsUnit B) : + IsUnit (mapL A B) := + ⟨⟨mapL A B, mapL (Ring.inverse A) (Ring.inverse B), + by simp [← mapL_mul, Ring.mul_inverse_cancel _ hA, Ring.mul_inverse_cancel _ hB], + by simp [← mapL_mul, Ring.inverse_mul_cancel _ hA, Ring.inverse_mul_cancel _ hB]⟩, rfl⟩ + +omit [FiniteDimensional ℂ E] [FiniteDimensional ℂ F] in +/-- The tensor product distributes over `Ring.inverse`: for invertible `A, B`, +`Ring.inverse (mapL A B) = mapL (Ring.inverse A) (Ring.inverse B)`. -/ +theorem ringInverse_mapL {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : IsUnit A) (hB : IsUnit B) : + Ring.inverse (mapL A B) = mapL (Ring.inverse A) (Ring.inverse B) := by + refine (isUnit_mapL hA hB).mul_right_cancel ?_ + simp [Ring.inverse_mul_cancel _ (isUnit_mapL hA hB), ← mapL_mul, + Ring.inverse_mul_cancel _ hA, Ring.inverse_mul_cancel _ hB] + +variable [CompleteSpace E] [CompleteSpace F] + +/-- The tensor product of nonneg operators is nonneg. Proof: `mapL A B = (mapL √A √B) * +(mapL √A √B)`, and the latter is `IsSelfAdjoint.mul_self_nonneg`. -/ +theorem mapL_nonneg {A : E →L[ℂ] E} {B : F →L[ℂ] F} (hA : 0 ≤ A) (hB : 0 ≤ B) : + 0 ≤ mapL A B := by + rw [← CFC.sqrt_mul_sqrt_self A hA, ← CFC.sqrt_mul_sqrt_self B hB, mapL_mul] + exact ((CFC.sqrt_nonneg A).isSelfAdjoint.tensorMapL + (CFC.sqrt_nonneg B).isSelfAdjoint).mul_self_nonneg + +/-- **N&C Exercise 2.31**: the tensor product of two *positive operators* is positive. +`mapL A B` is a positive operator (`ContinuousLinearMap.IsPositive`, i.e. symmetric with +`0 ≤ re ⟪·, ·⟫` — N&C's defining property of a positive operator) whenever both `A` and `B` are. +The `IsPositive`-phrased companion of `mapL_nonneg`, bridged by `nonneg_iff_isPositive`. -/ +theorem mapL_isPositive {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : A.IsPositive) (hB : B.IsPositive) : + (mapL A B).IsPositive := + ContinuousLinearMap.nonneg_iff_isPositive.mp + (mapL_nonneg (ContinuousLinearMap.nonneg_iff_isPositive.mpr hA) + (ContinuousLinearMap.nonneg_iff_isPositive.mpr hB)) + +/-- The tensor product preserves strict positivity: `mapL A B` is strictly positive whenever +both `A` and `B` are. Combination of `mapL_nonneg` and `isUnit_mapL`. -/ +@[aesop safe apply] +theorem mapL_isStrictlyPositive {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : IsStrictlyPositive A) (hB : IsStrictlyPositive B) : + IsStrictlyPositive (mapL A B) := + ⟨mapL_nonneg hA.nonneg hB.nonneg, isUnit_mapL hA.isUnit hB.isUnit⟩ + +/-- The tensor product distributes over `CFC.sqrt`: `sqrt (mapL A B) = mapL (sqrt A) (sqrt B)` +for nonneg `A, B`. Via `sqrt_unique`: `(mapL √A √B)² = mapL A B` (by `mapL_mul` and +`sqrt_mul_sqrt_self`), and `0 ≤ mapL √A √B` (by `mapL_nonneg`). -/ +theorem sqrt_mapL {A : E →L[ℂ] E} {B : F →L[ℂ] F} (hA : 0 ≤ A) (hB : 0 ≤ B) : + CFC.sqrt (mapL A B) = mapL (CFC.sqrt A) (CFC.sqrt B) := by + refine CFC.sqrt_unique ?_ (mapL_nonneg (CFC.sqrt_nonneg A) (CFC.sqrt_nonneg B)) + rw [← mapL_mul, CFC.sqrt_mul_sqrt_self A hA, CFC.sqrt_mul_sqrt_self B hB] + +/-- The tensor product distributes over `CFC.conjSqrt`: `conjSqrt (mapL A B) (mapL C D) += mapL (conjSqrt A C) (conjSqrt B D)` for nonneg `A, B`. -/ +theorem conjSqrt_mapL {A : E →L[ℂ] E} {B : F →L[ℂ] F} + (hA : 0 ≤ A) (hB : 0 ≤ B) (C : E →L[ℂ] E) (D : F →L[ℂ] F) : + CFC.conjSqrt (mapL A B) (mapL C D) = mapL (CFC.conjSqrt A C) (CFC.conjSqrt B D) := by + rw [CFC.conjSqrt_apply, CFC.conjSqrt_apply, CFC.conjSqrt_apply, sqrt_mapL hA hB, + ← mapL_mul, ← mapL_mul] + +/-- **Tensor distributivity of the operator geometric mean**: for strictly positive `A₁ : E →L E` +and `A₂ : F →L F`, and nonneg `B₁, B₂`, `M₀(A₁ ⊗ A₂, B₁ ⊗ B₂) = M₀(A₁, B₁) ⊗ M₀(A₂, B₂)`. +Consumed by the midpoint identity `mapL_rpow_midpoint_eq_geometricMean`. -/ +theorem geometricMean_mapL {A₁ : E →L[ℂ] E} {A₂ : F →L[ℂ] F} {B₁ : E →L[ℂ] E} {B₂ : F →L[ℂ] F} + (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) (hB₁ : 0 ≤ B₁) (hB₂ : 0 ≤ B₂) : + CFC.geometricMean (mapL A₁ A₂) (mapL B₁ B₂) = + mapL (CFC.geometricMean A₁ B₁) (CFC.geometricMean A₂ B₂) := by + simp only [CFC.geometricMean_def, ringInverse_mapL hA₁.isUnit hA₂.isUnit, + conjSqrt_mapL hA₁.ringInverse.nonneg hA₂.ringInverse.nonneg, + sqrt_mapL (CFC.conjSqrt_nonneg _ hB₁) (CFC.conjSqrt_nonneg _ hB₂), + conjSqrt_mapL hA₁.nonneg hA₂.nonneg] + +/-- **Midpoint identity for `mapL`-of-rpow**: for strictly positive `X, Y` and any real +exponents `q₁, q₂, r₁, r₂`, + + `mapL (X ^ ((q₁+q₂)/2)) (Y ^ ((r₁+r₂)/2)) = M₀(mapL (X^q₁) (Y^r₁), mapL (X^q₂) (Y^r₂))`. + +Direct combination of `geometricMean_rpow_rpow` (same-base GM) and `geometricMean_mapL` +(β.5 tensor distributivity). Key step in Carlen §6.1's midpoint-closure of the Lieb T1 joint +concavity property. -/ +theorem mapL_rpow_midpoint_eq_geometricMean + {X : E →L[ℂ] E} (hX : IsStrictlyPositive X) + {Y : F →L[ℂ] F} (hY : IsStrictlyPositive Y) (q₁ q₂ r₁ r₂ : ℝ) : + mapL (X ^ ((q₁ + q₂) / 2)) (Y ^ ((r₁ + r₂) / 2)) = + CFC.geometricMean (mapL (X ^ q₁) (Y ^ r₁)) (mapL (X ^ q₂) (Y ^ r₂)) := by + rw [← CFC.geometricMean_rpow_rpow hX q₁ q₂, ← CFC.geometricMean_rpow_rpow hY r₁ r₂] + exact (geometricMean_mapL (hX.rpow X q₁) (hY.rpow Y r₁) + (hX.rpow X q₂).nonneg (hY.rpow Y r₂).nonneg).symm + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Density.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Density.lean new file mode 100644 index 0000000000..fcedcf54bd --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Density.lean @@ -0,0 +1,409 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import Mathlib.Analysis.InnerProductSpace.StarOrder +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! + +# Density operators + +A **density operator** on a finite-dimensional inner product space `E` is a positive +continuous linear operator `T : E →L[𝕜] E` whose trace equals one. Density operators +form a convex set whose extreme points are the rank-one self-projectors (see +`IdempotentDensityOp.lean`). + +## Choice of operator type + +We use `T : E →L[𝕜] E` (continuous linear maps) rather than `T : E →ₗ[𝕜] E` (linear +maps). Density operators interact natively with `cfc`, `rankOne`, and the +Hilbert–Schmidt inner product, all of which are CLM-flavored. The cost is one extra +coercion `(T : E →ₗ[𝕜] E)` whenever the LinearMap-side eigenvalue API +(`IsSymmetric.eigenvalues`, `LinearMap.trace`) is needed. + +The latter half of the file gathers the CLM-level CFC sqrt + Hilbert–Schmidt pairing +machinery whose primary consumer is density-operator API (`fidelity`, POVM Born +probabilities, sqrt-sandwich identities). The CFC sqrt × HS-pairing × trace identities +are stated for arbitrary positive `x : E →L[ℂ] E` rather than just density operators, +since the proofs go through `cfc_real_sqrt_mul_self_of_nonneg` and don't need +`trace = 1`. + +## Main definitions + +* `ContinuousLinearMap.IsDensityOp T`: `T.IsPositive ∧ trace T = 1`. + +## Main results + +* `IsDensityOp.isPositive`, `IsDensityOp.nonneg`, `IsDensityOp.isSymmetric`, + `IsDensityOp.trace_eq_one`: unpacking lemmas. +* `IsDensityOp.isStrictlyPositive`: a full-rank (`IsUnit`) density operator is strictly positive. +* `IsDensityOp.eigenvalues_nonneg`: the eigenvalues of a density operator are + non-negative (via E1 / `LinearMap.IsSymmetric.isPositive_iff_eigenvalues_nonneg`). +* `IsDensityOp.eigenvalues_sum_eq_one`: the eigenvalues sum to 1 (combining + `trace_eq_one` and `IsSymmetric.trace_eq_sum_eigenvalues`). +* `IsDensityOp.eigenvalues_le_one`: each eigenvalue is at most 1 (corollary of + non-negativity + sum = 1). +* `IsDensityOp.convex_combination`: the set of density operators is convex. +* `cfc_sqrt_adjoint_comp_comp_cfc_sqrt_comp_eq`: bilinear sqrt-sandwich + `(√x Y)† (√x Z) = Y† x Z`. +* `trace_cfc_sqrt_sandwich_eq_trace_mul`: `tr(√x · S · √x) = tr(S · x)` for `0 ≤ x`. +* `re_hsPairing_cfc_sqrt_self_eq_re_trace_of_nonneg`: HS-norm² of `√x` equals + `re tr x` for `0 ≤ x`. +* `IsDensityOp.re_hsPairing_cfc_sqrt_self_eq_one`: trace-1 specialization; + `re hsPairing (√ρ) (√ρ) = 1` for density `ρ`. + +-/ + +@[expose] public section + +open Module +open scoped ComplexOrder InnerProductSpace + +namespace ContinuousLinearMap + +section +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +/-- A **density operator** is a positive continuous linear operator with trace 1. -/ +def IsDensityOp (T : E →L[𝕜] E) : Prop := + T.IsPositive ∧ LinearMap.trace 𝕜 E (T : E →ₗ[𝕜] E) = 1 + +omit [FiniteDimensional 𝕜 E] in +/-- Logical form of `IsDensityOp`: positivity and unit trace, as an `Iff`. -/ +theorem isDensityOp_iff {T : E →L[𝕜] E} : + T.IsDensityOp ↔ T.IsPositive ∧ LinearMap.trace 𝕜 E (T : E →ₗ[𝕜] E) = 1 := Iff.rfl + +end + +namespace IsDensityOp + +section +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] +variable {T S : E →L[𝕜] E} + +protected theorem isPositive (h : T.IsDensityOp) : T.IsPositive := h.1 + +protected theorem nonneg (h : T.IsDensityOp) : 0 ≤ T := + ContinuousLinearMap.nonneg_iff_isPositive.mpr h.isPositive + +/-- A density operator that is invertible (full-rank) is strictly positive. The bridge from the +quantum-state hypotheses (`IsDensityOp` + `IsUnit`) to strict-positivity API. -/ +protected theorem isStrictlyPositive (h : T.IsDensityOp) (hu : IsUnit T) : IsStrictlyPositive T := + ⟨h.nonneg, hu⟩ + +protected theorem trace_eq_one (h : T.IsDensityOp) : + LinearMap.trace 𝕜 E (T : E →ₗ[𝕜] E) = 1 := h.2 + +protected theorem isSymmetric (h : T.IsDensityOp) : (T : E →ₗ[𝕜] E).IsSymmetric := + h.isPositive.isSymmetric + +/-- The set of density operators is convex: a convex combination of density operators +is itself a density operator. -/ +theorem convex_combination (hT : T.IsDensityOp) (hS : S.IsDensityOp) + {t s : 𝕜} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + (t • T + s • S).IsDensityOp := by + refine ⟨(hT.isPositive.smul_of_nonneg ht).add (hS.isPositive.smul_of_nonneg hs), ?_⟩ + rw [toLinearMap_add, toLinearMap_smul, toLinearMap_smul, map_add, map_smul, map_smul, + hT.trace_eq_one, hS.trace_eq_one, smul_eq_mul, smul_eq_mul, mul_one, mul_one, hts] + +/-- **Transport of density operators.** The `IsDensityOp` property is invariant +under conjugation by a linear isometry equivalence: positivity is preserved by +`conjStarAlgEquiv` (via `LinearIsometryEquiv.conjStarAlgEquiv_isPositive_iff`) and the +trace is preserved by `LinearMap.trace_conj'`. Lets density operators on abstract `E` +be transported to / from `EuclideanSpace 𝕜 (Fin (finrank 𝕜 E))` via +`(stdOrthonormalBasis 𝕜 E).repr`. -/ +@[simp] +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_isDensityOp_iff [CompleteSpace E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [CompleteSpace F] (e : E ≃ₗᵢ[𝕜] F) : + (e.conjStarAlgEquiv T).IsDensityOp ↔ T.IsDensityOp := by + rw [ContinuousLinearMap.isDensityOp_iff, ContinuousLinearMap.isDensityOp_iff, + LinearIsometryEquiv.conjStarAlgEquiv_isPositive_iff, + ContinuousLinearMap.trace_conjStarAlgEquiv] + +/-- **Density operators are preserved by conjugation by a (possibly non-surjective) isometry.** For +`V : E →L[𝕜] F` with `V† V = 1`, `V T V†` is a density operator whenever `T` is: positivity via +`ContinuousLinearMap.IsPositive.conj_adjoint`, trace-preservation via +`ContinuousLinearMap.trace_conj_isometry`. The non-equiv companion to +`conjStarAlgEquiv_isDensityOp_iff` (only the forward direction holds for non-surjective `V`). -/ +theorem conj_isometry [FiniteDimensional 𝕜 E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] [CompleteSpace F] {V : E →L[𝕜] F} + (hV : V.adjoint ∘L V = 1) (h : T.IsDensityOp) : + (V ∘L T ∘L V.adjoint).IsDensityOp := + ⟨h.isPositive.conj_adjoint V, by + rw [ContinuousLinearMap.trace_conj_isometry hV, h.trace_eq_one]⟩ + +end + +section +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] +variable {T : E →L[𝕜] E} + +/-- The eigenvalues of a density operator are non-negative. -/ +theorem eigenvalues_nonneg (h : T.IsDensityOp) {n : ℕ} (hn : finrank 𝕜 E = n) + (i : Fin n) : 0 ≤ h.isSymmetric.eigenvalues hn i := + h.isPositive.toLinearMap.nonneg_eigenvalues hn i + +/-- The eigenvalues of a density operator sum to 1. -/ +theorem eigenvalues_sum_eq_one (h : T.IsDensityOp) {n : ℕ} (hn : finrank 𝕜 E = n) : + ∑ i, h.isSymmetric.eigenvalues hn i = 1 := by + have := h.isSymmetric.re_trace_eq_sum_eigenvalues hn + rw [← this, h.trace_eq_one, RCLike.one_re] + +/-- Each eigenvalue of a density operator is at most 1. -/ +theorem eigenvalues_le_one (h : T.IsDensityOp) {n : ℕ} (hn : finrank 𝕜 E = n) + (i : Fin n) : h.isSymmetric.eigenvalues hn i ≤ 1 := + (Finset.single_le_sum (fun j _ ↦ h.eigenvalues_nonneg hn j) (Finset.mem_univ i)).trans + (h.eigenvalues_sum_eq_one hn).le + +end + +end IsDensityOp + +section +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +/-- A normalized rank-one self-projector `rankOne 𝕜 v v` is a density operator. -/ +theorem isDensityOp_rankOne_self {v : E} (hv : ‖v‖ = 1) : + (InnerProductSpace.rankOne 𝕜 v v).IsDensityOp := by + refine ⟨InnerProductSpace.isPositive_rankOne_self v, ?_⟩ + rw [InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq_to_K, hv] + simp + +end + +/-! ## CFC sqrt × Hilbert–Schmidt pairing × trace identities + +The lemmas below are CLM-level identities about `cfc Real.sqrt` of positive operators +on a complex inner product space, gathered here because their primary consumers are +density-operator API (fidelity, POVM Born probabilities, trace-distance monotonicity). +The statements are ℂ-only because the unital-CFC chain for `E →L[ℂ] E` lands in tree +at ℂ; for arbitrary RCLike, the non-unital `cfcₙ NNReal.sqrt` chain would route +through `Mathlib/Analysis/CStarAlgebra/ContinuousLinearMap.lean`. +-/ + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +/-- **A strictly positive operator is positive-definite.** For `ρ` strictly positive (positive and +invertible) and `z ≠ 0`, the quadratic form `re ⟪ρ z, z⟫` is strictly positive. Proved via the CFC +square root `R = √ρ`: `re ⟪ρ z, z⟫ = ‖R z‖²`, and `R` is injective (`IsUnit R`, since +`ρ = R * R` is a unit), so `R z ≠ 0`. -/ +theorem _root_.IsStrictlyPositive.re_inner_self_pos {ρ : E →L[ℂ] E} (hρ : IsStrictlyPositive ρ) + {z : E} (hz : z ≠ 0) : 0 < RCLike.re (⟪ρ z, z⟫_ℂ) := by + obtain ⟨hsqrtU, hρeq⟩ := + (CStarAlgebra.isStrictlyPositive_iff_isUnit_sqrt_and_eq_sqrt_mul_sqrt).mp hρ + have hRz : CFC.sqrt ρ z ≠ 0 := + fun h ↦ hz ((ContinuousLinearMap.isUnit_iff_bijective.mp hsqrtU).1 (by rw [h, map_zero])) + rw [hρeq, mul_apply_eq_comp, ← ContinuousLinearMap.adjoint_inner_right, + (CFC.sqrt_nonneg ρ).isSelfAdjoint.adjoint_eq, inner_self_eq_norm_sq_to_K, + ← RCLike.ofReal_pow, RCLike.ofReal_re] + exact pow_pos (norm_pos_iff.mpr hRz) 2 + +/-- **Positive-definiteness criterion for strict positivity.** A positive operator whose quadratic +form `re ⟪x, ρ x⟫` is strictly positive on every nonzero `x` is strictly positive: positive-definite +⟹ injective ⟹ (finite-dimensional) invertible. The converse to +`IsStrictlyPositive.re_inner_self_pos`. -/ +theorem isStrictlyPositive_of_re_inner_self_pos [FiniteDimensional ℂ E] {ρ : E →L[ℂ] E} + (hpos : 0 ≤ ρ) (hdef : ∀ x : E, x ≠ 0 → 0 < RCLike.re (⟪x, ρ x⟫_ℂ)) : + IsStrictlyPositive ρ := by + refine ⟨hpos, ?_⟩ + rw [ContinuousLinearMap.isUnit_iff_bijective] + have hinj : Function.Injective ρ := by + rw [injective_iff_map_eq_zero] + intro x hx + by_contra hx0 + have hd := hdef x hx0 + rw [hx, inner_zero_right, map_zero] at hd + exact lt_irrefl 0 hd + exact ⟨hinj, (LinearMap.injective_iff_surjective (K := ℂ)).mp hinj⟩ + +/-- **A positive operator annihilates the vectors on which its quadratic form vanishes.** For `ρ` +positive and `re ⟪x, ρ x⟫ = 0`, we have `ρ x = 0`: writing `ρ = √ρ * √ρ` gives +`re ⟪x, ρ x⟫ = ‖√ρ x‖²`, so `√ρ x = 0` and hence `ρ x = √ρ (√ρ x) = 0`. The non-strict companion +to `IsStrictlyPositive.re_inner_self_pos` (which gives strict positivity for `x ≠ 0`). -/ +theorem apply_eq_zero_of_re_inner_self_eq_zero {ρ : E →L[ℂ] E} (hρ : 0 ≤ ρ) {x : E} + (hx : RCLike.re (⟪x, ρ x⟫_ℂ) = 0) : ρ x = 0 := by + have hsqrt : cfc Real.sqrt ρ * cfc Real.sqrt ρ = ρ := cfc_real_sqrt_mul_self_of_nonneg hρ + have hsx : cfc Real.sqrt ρ x = 0 := by + rw [← norm_eq_zero, ← sq_eq_zero_iff] + rw [← hsqrt, mul_apply_eq_comp, ← ContinuousLinearMap.adjoint_inner_left, + (IsSelfAdjoint.cfc (a := ρ)).adjoint_eq, inner_self_eq_norm_sq_to_K, + ← RCLike.ofReal_pow, RCLike.ofReal_re] at hx + exact hx + rw [← hsqrt, mul_apply_eq_comp, hsx, map_zero] + +/-- For a positive CLM `ρ`, `√ρ ∘L (√ρ)† = ρ`. Canonical factorization of a positive +operator via its CFC square root, comp-adjoint form. Combines self-adjointness of the +CFC square root with `cfc_real_sqrt_mul_self_of_nonneg`. -/ +theorem cfc_sqrt_comp_adjoint_eq_self_of_nonneg + {ρ : E →L[ℂ] E} (hρ : 0 ≤ ρ) : + (cfc Real.sqrt ρ).comp (cfc Real.sqrt ρ).adjoint = ρ := by + rw [IsSelfAdjoint.cfc.adjoint_eq, ← ContinuousLinearMap.mul_def, + cfc_real_sqrt_mul_self_of_nonneg hρ] + +/-- **Unitary-postcomposed canonical factorization**: `(√ρ ∘L W) ∘L (√ρ ∘L W)† = ρ` for +any cross-space `W : F ≃ₗᵢ[ℂ] E` and `0 ≤ ρ`. The unitary `W` cancels against its adjoint +(= `W.symm`) in the middle, reducing to `cfc_sqrt_comp_adjoint_eq_self_of_nonneg`. Consumed +by Uhlmann's optimal-purification construction (any operator of the form `√ρ ∘ unitary` is +a "square root" of `ρ` in the comp-adjoint sense). The same-space case is `F = E`. -/ +theorem cfc_sqrt_compL_isometryEquiv_comp_adjoint_eq_self_of_nonneg + {ρ : E →L[ℂ] E} (hρ : 0 ≤ ρ) {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] (W : F ≃ₗᵢ[ℂ] E) : + (cfc Real.sqrt ρ ∘L (W : F →L[ℂ] E)) ∘L + (cfc Real.sqrt ρ ∘L (W : F →L[ℂ] E)).adjoint = ρ := by + rw [ContinuousLinearMap.adjoint_comp, LinearIsometryEquiv.adjoint_eq_symm, + (IsSelfAdjoint.cfc (a := ρ)).adjoint_eq, + ← ContinuousLinearMap.comp_assoc, ContinuousLinearMap.comp_assoc (cfc Real.sqrt ρ), + LinearIsometryEquiv.toContinuousLinearEquiv_symm, + W.toContinuousLinearEquiv.coe_comp_coe_symm, ContinuousLinearMap.comp_id, + ← ContinuousLinearMap.mul_def, cfc_real_sqrt_mul_self_of_nonneg hρ] + +/-- **CFC sqrt commutes with `conjStarAlgEquiv` on positive operators.** For an isometric +equivalence `e : E ≃ₗᵢ[ℂ] F` and `0 ≤ x : E →L[ℂ] E`, +`cfc Real.sqrt (e.conjStarAlgEquiv x) = e.conjStarAlgEquiv (cfc Real.sqrt x)`. Proved via +uniqueness of the positive square root: `e.conjStarAlgEquiv (cfc √x)` is positive (image +of a positive operator under a positivity-preserving StarAlgEquiv) and squares to +`e.conjStarAlgEquiv x` (`map_mul` + `cfc_real_sqrt_mul_self_of_nonneg`), so it IS the +CFC square root of `e.conjStarAlgEquiv x` (by `cfc_real_sqrt_mul_self_eq_self_of_nonneg`). +Avoids `StarAlgHomClass.map_cfc` which trips on the foundational +`IsScalarTower ℝ ℂ (E →L[ℂ] E)` synthesis gap. -/ +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_cfc_real_sqrt + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] [CompleteSpace F] + (e : E ≃ₗᵢ[ℂ] F) {x : E →L[ℂ] E} (hx : 0 ≤ x) : + cfc Real.sqrt (e.conjStarAlgEquiv x) = e.conjStarAlgEquiv (cfc Real.sqrt x) := by + rw [← cfc_real_sqrt_mul_self_eq_self_of_nonneg + (e.conjStarAlgEquiv_nonneg_iff.mpr (cfc_real_sqrt_nonneg _)), + ← map_mul, cfc_real_sqrt_mul_self_of_nonneg hx] + +/-- **CFC log commutes with `conjStarAlgEquiv`.** Companion to `conjStarAlgEquiv_cfc_real_sqrt`: +for a unitary `e : E ≃ₗᵢ[ℂ] E` and self-adjoint `τ` whose spectrum avoids `0`, +`cfc Real.log (e.conjStarAlgEquiv τ) = e.conjStarAlgEquiv (cfc Real.log τ)`. Unlike sqrt (pinned by +√-uniqueness), `log` has no algebraic characterization, so this routes through `StarAlgHom.map_cfc` +and hence needs `[IsScalarTower ℝ ℂ (E →L[ℂ] E)]` as an instance binder (the §3.5 gap documented +above; it synthesizes for the concrete `EuclideanSpace` consumers). Continuity of the conjugation +via `continuous_of_finiteDimensional`; self-adjointness preserved by +`conjStarAlgEquiv_isSelfAdjoint_iff`. -/ +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_cfc_real_log [FiniteDimensional ℂ E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] [IsScalarTower ℝ ℂ (E →L[ℂ] E)] [IsScalarTower ℝ ℂ (F →L[ℂ] F)] + (e : E ≃ₗᵢ[ℂ] F) {τ : E →L[ℂ] E} + (h : IsSelfAdjoint τ) (hc : ContinuousOn Real.log (spectrum ℝ τ)) : + cfc Real.log (e.conjStarAlgEquiv τ) = e.conjStarAlgEquiv (cfc Real.log τ) := + (StarAlgHom.map_cfc (e.conjStarAlgEquiv.toStarAlgHom) Real.log τ hc + (e.conjStarAlgEquiv.toAlgEquiv.toLinearEquiv.toLinearMap).continuous_of_finiteDimensional h + (e.conjStarAlgEquiv_isSelfAdjoint_iff.mpr h)).symm + +/-- **Bilinear sqrt-sandwich** at the CLM level: for `0 ≤ x` and any `Y`, `Z`, +`(√x ∘ Y)† ∘ (√x ∘ Z) = Y† ∘ x ∘ Z`. The two square-root factors absorb into the middle +positive operator `x`. Recurs across POVM / fidelity / channel-bound proofs that +factor `E_m = √E_m · √E_m`. -/ +theorem cfc_sqrt_adjoint_comp_comp_cfc_sqrt_comp_eq + {x : E →L[ℂ] E} (hx : 0 ≤ x) (Y Z : E →L[ℂ] E) : + (cfc Real.sqrt x ∘L Y).adjoint ∘L (cfc Real.sqrt x ∘L Z) = Y.adjoint ∘L x ∘L Z := by + rw [adjoint_comp, (IsSelfAdjoint.cfc (a := x)).adjoint_eq, + comp_assoc Y.adjoint, + ← comp_assoc (cfc Real.sqrt x) (cfc Real.sqrt x) Z, + ← mul_def (cfc Real.sqrt x) (cfc Real.sqrt x), + cfc_real_sqrt_mul_self_of_nonneg hx] + +end + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + +omit [FiniteDimensional ℂ E] in +/-- **Sqrt-sandwich trace cyclicity**: for a positive operator `x` and any operator `S`, +`tr(√x * S * √x) = tr(S * x)`. Canonical form for Born-rule trace computations (POVM +probabilities, fidelity formulas, partial-trace bounds). Combines trace cyclicity with +`cfc_real_sqrt_mul_self_of_nonneg`. -/ +theorem trace_cfc_sqrt_sandwich_eq_trace_mul {x : E →L[ℂ] E} (hx : 0 ≤ x) (S : E →L[ℂ] E) : + LinearMap.trace ℂ E + ((cfc Real.sqrt x * S * cfc Real.sqrt x : E →L[ℂ] E) : E →ₗ[ℂ] E) = + LinearMap.trace ℂ E ((S * x : E →L[ℂ] E) : E →ₗ[ℂ] E) := by + rw [mul_assoc, ContinuousLinearMap.toLinearMap_mul, LinearMap.trace_mul_comm, + ← ContinuousLinearMap.toLinearMap_mul, mul_assoc, + cfc_real_sqrt_mul_self_of_nonneg hx] + +/-- **HS-norm squared of the CFC square root** equals `re tr x` for a positive operator +`x`. Direct corollary of `re_hsPairing_self_eq_re_trace_sq_of_isSelfAdjoint` and +`cfc_real_sqrt_mul_self_of_nonneg`. -/ +theorem re_hsPairing_cfc_sqrt_self_eq_re_trace_of_nonneg + {x : E →L[ℂ] E} (hx : 0 ≤ x) : + RCLike.re ((cfc Real.sqrt x).hsPairing (cfc Real.sqrt x)) = + RCLike.re (LinearMap.trace ℂ E x.toLinearMap) := by + rw [re_hsPairing_self_eq_re_trace_sq_of_isSelfAdjoint IsSelfAdjoint.cfc, + cfc_real_sqrt_mul_self_of_nonneg hx] + +/-- **Cross HS pairing of two `√x`-multiplied operators**: for a positive operator `x`, +`⟨X · √x, Y · √x⟩_HS = tr(Y† · X · x)`. The two square-root factors absorb into the middle +positive operator `x` by the sqrt-sandwich trace identity +(`trace_cfc_sqrt_sandwich_eq_trace_mul`). This is the off-diagonal companion of +`re_hsPairing_cfc_sqrt_self_eq_re_trace_of_nonneg` (its `X = Y = 1` diagonal, up to `re`), and is +the crux of entanglement-fidelity Cauchy–Schwarz estimates that split `ρ = √ρ · √ρ`. -/ +theorem hsPairing_mul_cfc_sqrt_eq_trace {x : E →L[ℂ] E} (hx : 0 ≤ x) (X Y : E →L[ℂ] E) : + (X * cfc Real.sqrt x).hsPairing (Y * cfc Real.sqrt x) + = LinearMap.trace ℂ E + ((ContinuousLinearMap.adjoint Y * X * x : E →L[ℂ] E) : E →ₗ[ℂ] E) := by + have hadj : ContinuousLinearMap.adjoint (Y * cfc Real.sqrt x) + = cfc Real.sqrt x * ContinuousLinearMap.adjoint Y := by + rw [← ContinuousLinearMap.star_eq_adjoint, star_mul, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.star_eq_adjoint, (IsSelfAdjoint.cfc (a := x)).adjoint_eq] + rw [ContinuousLinearMap.hsPairing_eq, ← ContinuousLinearMap.mul_def, hadj, + show (cfc Real.sqrt x * ContinuousLinearMap.adjoint Y) * (X * cfc Real.sqrt x) + = cfc Real.sqrt x * (ContinuousLinearMap.adjoint Y * X) * cfc Real.sqrt x + by simp only [mul_assoc], trace_cfc_sqrt_sandwich_eq_trace_mul hx] + +/-- For a density operator `x`, the HS-norm squared of `cfc Real.sqrt x` equals `1`. -/ +theorem IsDensityOp.re_hsPairing_cfc_sqrt_self_eq_one + {x : E →L[ℂ] E} (hx : x.IsDensityOp) : + RCLike.re ((cfc Real.sqrt x).hsPairing (cfc Real.sqrt x)) = 1 := by + rw [re_hsPairing_cfc_sqrt_self_eq_re_trace_of_nonneg hx.nonneg, hx.trace_eq_one, RCLike.one_re] + +end + +section MaximallyMixed + +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + [CompleteSpace F] + +omit [CompleteSpace F] in +/-- The **maximally mixed state** `(1/d) • 1` (where `d = dim F`) is a density operator. -/ +theorem isDensityOp_finrank_inv_smul_one [Nontrivial F] : + IsDensityOp ((Module.finrank ℂ F : ℂ)⁻¹ • (1 : F →L[ℂ] F)) := by + have hd : (Module.finrank ℂ F : ℂ) ≠ 0 := by + exact_mod_cast (Module.finrank_pos (R := ℂ) (M := F)).ne' + have hnn : (0 : ℂ) ≤ (Module.finrank ℂ F : ℂ)⁻¹ := by + rw [← RCLike.ofReal_natCast, ← RCLike.ofReal_inv] + exact RCLike.ofReal_nonneg.mpr (by positivity) + refine ⟨isPositive_one.smul_of_nonneg hnn, ?_⟩ + rw [ContinuousLinearMap.toLinearMap_smul, map_smul, ContinuousLinearMap.toLinearMap_one, + LinearMap.trace_one, + smul_eq_mul, inv_mul_cancel₀ hd] + +/-- The **maximally mixed state** `(1/d) • 1` (where `d = dim F`) is strictly positive. -/ +theorem isStrictlyPositive_finrank_inv_smul_one [Nontrivial F] : + IsStrictlyPositive ((Module.finrank ℂ F : ℂ)⁻¹ • (1 : F →L[ℂ] F)) := by + refine IsStrictlyPositive.smul ?_ isStrictlyPositive_one + have : (0 : ℝ) < (Module.finrank ℂ F : ℝ) := by exact_mod_cast Module.finrank_pos + rw [← Complex.ofReal_natCast, ← Complex.ofReal_inv, Complex.zero_lt_real] + positivity + +end MaximallyMixed + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DensitySubunital.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DensitySubunital.lean new file mode 100644 index 0000000000..d64b2accf0 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DensitySubunital.lean @@ -0,0 +1,81 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# A density operator is subunital, and its overlaps are trace-bounded + +For a density operator `ρ` on a finite-dimensional complex Hilbert space, this file records two +elementary order/trace facts about the neighbouring density-operator API: + +* `ContinuousLinearMap.IsDensityOp.le_one` — `ρ ≤ 1` in the Loewner order: a density operator is + **subunital**. Obtained from `‖ρ‖ ≤ ‖ρ‖₁ = 1` and the C*-algebra bound + `a ≤ ‖a‖ • 1` for a self-adjoint `a`. +* `ContinuousLinearMap.IsDensityOp.re_trace_comp_le` — for any positive operator `A`, + `re tr(A ρ) ≤ re tr A`: an expectation-style overlap never exceeds the total weight `tr A`. The + gap is `re tr(A (1 − ρ)) ≥ 0`, positive because `1 − ρ ≥ 0` (subunitality) and `A ≥ 0` + (`re_trace_mul_nonneg_of_nonneg`). + +## Generality + +Both are stated over `ℂ`, matching the ℂ generality of the neighbouring density-operator trace API +(`ContinuousLinearMap.IsDensityOp.re_trace_mul_self_le_one`, +`ContinuousLinearMap.IsDensityOp.re_trace_depolarize_pow_le`). The `ℂ` is genuinely forced: +`le_one` uses `IsSelfAdjoint.le_algebraMap_norm_self`, whose `CStarAlgebra` hypothesis is a +`ℂ`-algebra structure, and `re_trace_comp_le` additionally uses the `ℂ`-only +`ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace ContinuousLinearMap.IsDensityOp + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **A density operator is subunital**: `ρ ≤ 1` in the Loewner order. Its operator norm is bounded +by its trace norm `‖ρ‖ ≤ ‖ρ‖₁`, which equals `re tr ρ = 1` for a density operator; then the +C*-algebra bound `ρ ≤ ‖ρ‖ • 1` (`IsSelfAdjoint.le_algebraMap_norm_self`) combined with `‖ρ‖ ≤ 1` +gives `ρ ≤ 1`. -/ +theorem le_one {ρ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) : ρ ≤ 1 := by + have hnorm : ‖ρ‖ ≤ 1 := by + calc ‖ρ‖ ≤ ρ.traceNorm := ContinuousLinearMap.opNorm_le_traceNorm ρ + _ = RCLike.re (LinearMap.trace ℂ E (ρ : E →ₗ[ℂ] E)) := + ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive hρ.isPositive + _ = 1 := by rw [hρ.trace_eq_one]; simp + calc ρ ≤ algebraMap ℝ (E →L[ℂ] E) ‖ρ‖ := hρ.isPositive.isSelfAdjoint.le_algebraMap_norm_self + _ = ‖ρ‖ • (1 : E →L[ℂ] E) := Algebra.algebraMap_eq_smul_one _ + _ ≤ (1 : ℝ) • (1 : E →L[ℂ] E) := smul_le_smul_of_nonneg_right hnorm zero_le_one + _ = 1 := one_smul ℝ 1 + +/-- **A positive operator's overlap with a density operator is trace-bounded**: +`re tr(A ρ) ≤ re tr A` for a positive operator `A` and a density operator `ρ`. The difference is +`re tr(A (1 − ρ)) ≥ 0`, which is nonnegative because `1 − ρ ≥ 0` (a density operator is subunital, +`le_one`) and `A ≥ 0`, via `re_trace_mul_nonneg_of_nonneg`. (Applied with `A` a POVM effect, this is +the per-outcome bound `bornProb ρ i ≤ tr(Eᵢ)`.) -/ +theorem re_trace_comp_le {A ρ : E →L[ℂ] E} (hA : 0 ≤ A) (hρ : ρ.IsDensityOp) : + RCLike.re (LinearMap.trace ℂ E (A.comp ρ : E →ₗ[ℂ] E)) ≤ + RCLike.re (LinearMap.trace ℂ E (A : E →ₗ[ℂ] E)) := by + have hpos : (0 : E →L[ℂ] E) ≤ 1 - ρ := sub_nonneg.mpr hρ.le_one + have key : 0 ≤ RCLike.re (LinearMap.trace ℂ E (↑(A * (1 - ρ)) : E →ₗ[ℂ] E)) := + ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg hA hpos + have hsplit : RCLike.re (LinearMap.trace ℂ E (↑(A * (1 - ρ)) : E →ₗ[ℂ] E)) + = RCLike.re (LinearMap.trace ℂ E (A : E →ₗ[ℂ] E)) + - RCLike.re (LinearMap.trace ℂ E (A.comp ρ : E →ₗ[ℂ] E)) := by + have hcomp : A * (1 - ρ) = A - A.comp ρ := by + rw [mul_sub, mul_one, ContinuousLinearMap.mul_def] + rw [hcomp]; simp only [ContinuousLinearMap.toLinearMap_sub, map_sub] + rw [hsplit] at key; linarith + +end ContinuousLinearMap.IsDensityOp diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingPartialTrace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingPartialTrace.lean new file mode 100644 index 0000000000..e0e0599d3c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingPartialTrace.lean @@ -0,0 +1,168 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DepolarizingTwirl +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract +public import Mathlib.LinearAlgebra.Contraction + +/-! +# The depolarizing twirl on the traced factor is `partialTrace ⊗ I/d` + +Fix finite-dimensional complex inner product spaces `E`, `F`, an orthonormal basis +`b = {bᵢ}` of `F` of dimension `d = |ι|`, and the depolarizing `1`-design unitaries +`Uⱼ = Pσ Sε` on `F` (`OrthonormalBasis.depolarizingUnitary`). Twirling an operator +`T : E ⊗ F →L[ℂ] E ⊗ F` by the unitaries `I_E ⊗ Uⱼ` — i.e. leaving the `E` factor alone and +running the completely depolarizing channel on the `F` factor — collapses `T` to its `E`-marginal +tensored with the maximally mixed state on `F`: + +`(2^d d!)⁻¹ • ∑_{ε, σ} (I ⊗ Uⱼ) T (I ⊗ Uⱼ)† = (Tr_F T) ⊗ (I_F / d)`. + +This is the bipartite form of the finite unitary `1`-design of Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 11.19 +(`OrthonormalBasis.sum_conjStarAlgEquiv_depolarizingUnitary`): the completely depolarizing +partial-trace channel `T ↦ (Tr_F T) ⊗ I/d` is a **uniform mixed-unitary average**. Feeding this +into the mixed-unitary monotonicity of the quantum relative entropy +(`ContinuousLinearMap.quantumRelativeEntropy_sum_conjStarAlgEquiv_le`) yields the monotonicity of +the relative entropy under partial trace — the bridge to the strong subadditivity of the von +Neumann entropy (N&C Theorem 11.14). + +## Main results + +* `OrthonormalBasis.sum_depolarizingUnitary_conj_toLinearMap` — the `LinearMap`-level restatement + of the single-space depolarizing twirl (Ex 11.19), used in the reduction to product operators. +* `OrthonormalBasis.sum_conjStarAlgEquiv_congrIsometry_depolarizingUnitary` — the headline + bipartite twirl identity `∑ⱼ pⱼ (I ⊗ Uⱼ) T (I ⊗ Uⱼ)† = (Tr_F T) ⊗ (I_F/d)`. +-/ + +@[expose] public section + +open Module InnerProductSpace ContinuousLinearMap +open scoped TensorProduct + +namespace OrthonormalBasis + +-- `[CompleteSpace F]` is mathematically implied by `[FiniteDimensional ℂ F]`, but it is kept +-- explicit deliberately: dropping it forces the `CompleteSpace F` / `CompleteSpace (E ⊗ F)` +-- instances (needed by `conjStarAlgEquiv` / `depolarizingUnitary`) to be re-synthesized +-- non-canonically inside the `homTensorHomEquiv` induction of +-- `sum_conjStarAlgEquiv_congrIsometry_depolarizingUnitary`, which desyncs the `conjStarAlgEquiv` +-- terms (the `hterm` rewrite stops firing) and blows the heartbeat budget (`isDefEq` timeout). +-- The explicit binder pins one canonical instance and keeps the proof fast. +variable {ι E F : Type*} [Fintype ι] [DecidableEq ι] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + +/-- **`LinearMap` form of the single-space depolarizing twirl** (Nielsen & Chuang, Exercise 11.19). +Averaging the conjugations `Uⱼ B Uⱼ⁻¹` of a linear operator `B : F →ₗ[ℂ] F` by the `1`-design +unitaries `Uⱼ = Pσ Sε` gives `(Tr B / d) • id`, where `d = |ι|`. This is +`sum_conjStarAlgEquiv_depolarizingUnitary` transported from continuous linear maps to plain linear +maps, so it can be used inside a reduction to product operators `TensorProduct.map A B`. -/ +theorem sum_depolarizingUnitary_conj_toLinearMap [Nonempty ι] (b : OrthonormalBasis ι ℂ F) + (B : F →ₗ[ℂ] F) : + ∑ p : (ι → Bool) × Equiv.Perm ι, + (((2 : ℂ) ^ Fintype.card ι * (Fintype.card ι).factorial)⁻¹) • + ((b.depolarizingUnitary p).toLinearMap ∘ₗ B ∘ₗ (b.depolarizingUnitary p).symm.toLinearMap) + = (LinearMap.trace ℂ F B / (Fintype.card ι : ℂ)) • LinearMap.id := by + apply LinearMap.ext + intro x + have h := DFunLike.congr_fun + (b.sum_conjStarAlgEquiv_depolarizingUnitary (LinearMap.toContinuousLinearMap B)) x + simp only [_root_.sum_apply, _root_.smul_apply, + LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, LinearMap.coe_toContinuousLinearMap', + LinearMap.coe_toContinuousLinearMap, one_apply_eq_self] at h + simpa only [LinearMap.sum_apply, LinearMap.smul_apply, LinearMap.comp_apply, + LinearMap.id_apply, LinearEquiv.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv] + using h + +/-- **The bipartite depolarizing twirl equals `partialTrace ⊗ I/d`** (Nielsen & Chuang, Exercise +11.19, bipartite form). For an operator `T : E ⊗ F →L[ℂ] E ⊗ F` and an orthonormal basis `b` of `F` +of dimension `d = |ι|`, the uniform average of the conjugations by the depolarizing unitaries +`I_E ⊗ Uⱼ` (twirling only the `F` factor) equals the `E`-marginal of `T` tensored with the +maximally mixed state `I_F / d`: + +`(2^d d!)⁻¹ • ∑ⱼ (I ⊗ Uⱼ) T (I ⊗ Uⱼ)† = (Tr_F T) ⊗ (I_F / d)`. + +Both sides are `ℂ`-linear in `T`; the operators `TensorProduct.map A B` span `E ⊗ F →ₗ[ℂ] E ⊗ F` +(via `homTensorHomEquiv`), so it suffices to check the identity on product operators, where it +reduces to the single-space twirl on the `F` factor +(`sum_depolarizingUnitary_conj_toLinearMap`) and `partialTraceRight_tensorMap`. This exhibits the +completely depolarizing partial-trace channel as a mixed-unitary average, feeding the mixed-unitary +data-processing inequality for the quantum relative entropy. -/ +theorem sum_conjStarAlgEquiv_congrIsometry_depolarizingUnitary [Nonempty ι] + (b : OrthonormalBasis ι ℂ F) (T : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : + ∑ p : (ι → Bool) × Equiv.Perm ι, + (((2 : ℂ) ^ Fintype.card ι * (Fintype.card ι).factorial)⁻¹) • + (TensorProduct.congrIsometry (.refl ℂ E) (b.depolarizingUnitary p)).conjStarAlgEquiv T + = TensorProduct.mapL + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (T : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + ((Fintype.card ι : ℂ)⁻¹ • 1) := by + set w : ℂ := (((2 : ℂ) ^ Fintype.card ι * (Fintype.card ι).factorial)⁻¹) with hw + -- Rewrite each twirl term's underlying linear map as `(I ⊗ Uⱼ) ∘ S ∘ (I ⊗ Uⱼ⁻¹)`. + have hterm : ∀ p : (ι → Bool) × Equiv.Perm ι, + ((TensorProduct.congrIsometry (.refl ℂ E) (b.depolarizingUnitary p)).conjStarAlgEquiv + T).toLinearMap = + TensorProduct.map LinearMap.id (b.depolarizingUnitary p).toLinearMap ∘ₗ + T.toLinearMap ∘ₗ + TensorProduct.map LinearMap.id (b.depolarizingUnitary p).symm.toLinearMap := by + intro p + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap, LinearEquiv.conj_apply, + TensorProduct.toLinearEquiv_congrIsometry] + simp only [TensorProduct.congr_symm, TensorProduct.toLinearMap_congr] + rfl + -- Reduce the CLM identity to a LinearMap identity. + refine ContinuousLinearMap.coe_injective ?_ + rw [ContinuousLinearMap.toLinearMap_sum] + simp only [ContinuousLinearMap.toLinearMap_smul, hterm, TensorProduct.toLinearMap_mapL, + LinearMap.coe_toContinuousLinearMap, ContinuousLinearMap.toLinearMap_one] + -- It suffices to prove the LinearMap identity for an arbitrary operator `S`. + suffices H : ∀ S : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F, + (∑ p : (ι → Bool) × Equiv.Perm ι, w • + (TensorProduct.map LinearMap.id (b.depolarizingUnitary p).toLinearMap ∘ₗ S ∘ₗ + TensorProduct.map LinearMap.id (b.depolarizingUnitary p).symm.toLinearMap)) + = TensorProduct.map (LinearMap.partialTraceRight b S) + ((Fintype.card ι : ℂ)⁻¹ • LinearMap.id) by + exact H _ + intro S + obtain ⟨X, rfl⟩ := (homTensorHomEquiv ℂ E F E F).surjective S + induction X using TensorProduct.inductionOn with + | tmul A B => + rw [homTensorHomEquiv_apply, TensorProduct.homTensorHomMap_apply, + LinearMap.partialTraceRight_tensorMap] + -- Product-operator case: the twirl acts only on the `F` factor. + have hstep : ∀ p : (ι → Bool) × Equiv.Perm ι, + TensorProduct.map LinearMap.id (b.depolarizingUnitary p).toLinearMap ∘ₗ + TensorProduct.map A B ∘ₗ + TensorProduct.map LinearMap.id (b.depolarizingUnitary p).symm.toLinearMap + = TensorProduct.map A + ((b.depolarizingUnitary p).toLinearMap ∘ₗ B ∘ₗ + (b.depolarizingUnitary p).symm.toLinearMap) := by + intro p + rw [← TensorProduct.map_comp, ← TensorProduct.map_comp] + simp + simp_rw [hstep] + -- Pull the fixed `map A` factor out of the average, then apply the single-space twirl. + have hpull : (∑ p : (ι → Bool) × Equiv.Perm ι, w • TensorProduct.map A + ((b.depolarizingUnitary p).toLinearMap ∘ₗ B ∘ₗ + (b.depolarizingUnitary p).symm.toLinearMap)) + = TensorProduct.map A (∑ p : (ι → Bool) × Equiv.Perm ι, w • + ((b.depolarizingUnitary p).toLinearMap ∘ₗ B ∘ₗ + (b.depolarizingUnitary p).symm.toLinearMap)) := by + simp only [← TensorProduct.mapBilinear_apply, map_sum, map_smul] + rw [hpull, hw, b.sum_depolarizingUnitary_conj_toLinearMap B, + TensorProduct.map_smul_right, TensorProduct.map_smul_left, + TensorProduct.map_smul_right, smul_smul, div_eq_mul_inv] + | add X Y ihX ihY => + rw [map_add] + simp only [LinearMap.comp_add, LinearMap.add_comp, smul_add, Finset.sum_add_distrib] + simp only [ihX, ihY, ← LinearMap.partialTraceRightLM_apply, map_add, + TensorProduct.map_add_left] + +end OrthonormalBasis diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingTwirl.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingTwirl.lean new file mode 100644 index 0000000000..df8b761a30 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DepolarizingTwirl.lean @@ -0,0 +1,276 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryTwirl +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.Data.Fintype.Perm + +/-! +# The depolarizing twirl: a finite unitary `1`-design + +Fix an orthonormal basis `b = {bᵢ}` of a finite-dimensional inner product space `E` of dimension +`d = |ι|`. Averaging an operator `A` over the unitary conjugations by the `2^d · d!` composites +`Pσ ∘ Sε` — where `Sε` is a **sign-diagonal** unitary (`ε : ι → Bool`) and `Pσ` is a **basis +permutation** unitary (`σ : Equiv.Perm ι`) — reproduces the **completely depolarizing channel** + +`(2^d · d!)⁻¹ · ∑_{ε, σ} (Pσ Sε) A (Pσ Sε)† = (tr A / d) · I`. + +This is the operator content of Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 11.19: there is a finite family of unitaries `Uⱼ` and a probability distribution `pⱼ` +(here uniform, `pⱼ = (2^d d!)⁻¹`) with `∑ⱼ pⱼ Uⱼ A Uⱼ† = tr(A)·I/d`, i.e. the collection +`{Uⱼ}` is a unitary `1`-design. + +The proof composes two averages. The sign average +(`OrthonormalBasis.sum_signDiagonal_conj`, the *dephasing twirl*) projects `A` onto its +basis-diagonal `∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|`; the permutation average then equalises that diagonal to +its mean `(tr A / d)` on the identity, because conjugating a diagonal operator by a basis +permutation permutes its diagonal entries and averaging a permuted family over the whole symmetric +group is coordinate-independent. Everything is phrased with linear isometry equivalences +(`E ≃ₗᵢ[𝕜] E`) and their conjugation `LinearIsometryEquiv.conjStarAlgEquiv`, so the result feeds +directly into the mixed-unitary monotonicity of the quantum relative entropy +(`ContinuousLinearMap.quantumRelativeEntropy_sum_conjStarAlgEquiv_le`) — the route to monotonicity +of the relative entropy under partial trace and hence to the strong subadditivity of the von +Neumann entropy (N&C Theorem 11.14). + +## Main definitions + +* `OrthonormalBasis.signDiagonalEquiv` — the sign-diagonal unitary as a `LinearIsometryEquiv`. +* `OrthonormalBasis.depolarizingUnitary` — the family `Pσ ∘ Sε` of `1`-design unitaries. + +## Main results + +* `OrthonormalBasis.equiv_conjStarAlgEquiv_diagonalOperator` — a basis permutation conjugates a + diagonal operator to the diagonal operator with permuted entries. +* `OrthonormalBasis.sum_equiv_conjStarAlgEquiv_diagonalOperator` — averaging a diagonal operator + over all basis permutations yields `(d! / d · ∑ w) • I`. +* `OrthonormalBasis.sum_conjStarAlgEquiv_depolarizingUnitary` — the depolarizing `1`-design + identity `(2^d d!)⁻¹ • ∑ Uⱼ A Uⱼ† = (tr A / d) • I` (N&C Ex 11.19). +-/ + +@[expose] public section + +open Module InnerProductSpace ContinuousLinearMap + +namespace OrthonormalBasis + +variable {ι 𝕜 E : Type*} [RCLike 𝕜] [Fintype ι] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] (b : OrthonormalBasis ι 𝕜 E) + +/-- A diagonal operator with **constant** diagonal `c` is `c` times the identity: +`∑ᵢ c • |bᵢ⟩⟨bᵢ| = c • I`. -/ +theorem diagonalOperator_const (c : 𝕜) : + b.diagonalOperator (fun _ => c) = c • (1 : E →L[𝕜] E) := by + rw [diagonalOperator, ← b.diagonalOperator_one, diagonalOperator, Finset.smul_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + simp + +section CompleteSpace + +variable [CompleteSpace E] + +/-- **A basis permutation conjugates a diagonal operator to a diagonal operator with permuted +entries.** For `σ : Equiv.Perm ι`, conjugating `∑ᵢ wᵢ |bᵢ⟩⟨bᵢ|` by the permutation unitary +`b.equiv b σ` gives `∑ⱼ w(σ⁻¹ j) |bⱼ⟩⟨bⱼ|`. -/ +theorem equiv_conjStarAlgEquiv_diagonalOperator (σ : Equiv.Perm ι) (w : ι → 𝕜) : + (b.equiv b σ).conjStarAlgEquiv (b.diagonalOperator w) + = b.diagonalOperator (fun j => w (σ⁻¹ j)) := by + rw [diagonalOperator, map_sum] + simp_rw [map_smul, rankOne_conjStarAlgEquiv, equiv_apply_basis] + rw [diagonalOperator, ← Equiv.sum_comp σ fun j => w (σ⁻¹ j) • ((rankOne 𝕜) (b j)) (b j)] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [show σ⁻¹ (σ i) = i from Equiv.symm_apply_apply σ i] + +/-- **The permutation average of a diagonal operator is a scalar.** Averaging `∑ᵢ wᵢ |bᵢ⟩⟨bᵢ|` +over all `d!` basis permutations equalises the diagonal to its mean: +`∑_σ Pσ (diag w) Pσ† = (d! / d · ∑ᵢ wᵢ) • I`, where `d = |ι|`. The value is computed from the +coordinate-independence of the permuted diagonal (`Equiv.mulLeft` by a transposition) and the total +`∑ⱼ ∑_σ w(σ⁻¹ j) = d! · ∑ᵢ wᵢ`. -/ +theorem sum_equiv_conjStarAlgEquiv_diagonalOperator [Nonempty ι] [DecidableEq ι] (w : ι → 𝕜) : + ∑ σ : Equiv.Perm ι, (b.equiv b σ).conjStarAlgEquiv (b.diagonalOperator w) + = (((Fintype.card ι).factorial : 𝕜) / (Fintype.card ι : 𝕜) * ∑ i, w i) • + (1 : E →L[𝕜] E) := by + -- The permuted diagonal weight `∑_σ w(σ⁻¹ j)` does not depend on `j`. + have hconst : ∀ j k : ι, (∑ σ : Equiv.Perm ι, w (σ⁻¹ j)) = ∑ σ : Equiv.Perm ι, w (σ⁻¹ k) := by + intro j k + rw [← Equiv.sum_comp (Equiv.mulLeft (Equiv.swap j k)) fun σ => w (σ⁻¹ j)] + refine Finset.sum_congr rfl fun ρ _ => ?_ + congr 1 + rw [Equiv.coe_mulLeft, mul_inv_rev, Equiv.swap_inv, Equiv.Perm.mul_apply, + Equiv.swap_apply_left] + -- Its total over all coordinates is `d! · ∑ᵢ wᵢ`. + have hsum : (∑ j, ∑ σ : Equiv.Perm ι, w (σ⁻¹ j)) + = ((Fintype.card ι).factorial : 𝕜) * ∑ i, w i := by + rw [Finset.sum_comm] + have hσ : ∀ σ : Equiv.Perm ι, (∑ j, w (σ⁻¹ j)) = ∑ i, w i := fun σ => + Equiv.sum_comp (σ⁻¹ : Equiv.Perm ι) w + simp_rw [hσ] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_perm, nsmul_eq_mul] + -- The permutation sum is the diagonal operator of the (constant) permuted weight. + have hdiag : ∑ σ : Equiv.Perm ι, (b.equiv b σ).conjStarAlgEquiv (b.diagonalOperator w) + = b.diagonalOperator (fun j => ∑ σ : Equiv.Perm ι, w (σ⁻¹ j)) := by + simp_rw [equiv_conjStarAlgEquiv_diagonalOperator, diagonalOperator] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Finset.sum_smul] + rw [hdiag] + have j₀ : ι := Classical.arbitrary ι + have hn : (Fintype.card ι : 𝕜) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hgval : (∑ σ : Equiv.Perm ι, w (σ⁻¹ j₀)) + = ((Fintype.card ι).factorial : 𝕜) / (Fintype.card ι : 𝕜) * ∑ i, w i := by + have hcard : (Fintype.card ι : 𝕜) * (∑ σ : Equiv.Perm ι, w (σ⁻¹ j₀)) + = ((Fintype.card ι).factorial : 𝕜) * ∑ i, w i := by + rw [← hsum, Finset.sum_congr rfl (fun j _ => hconst j j₀), Finset.sum_const, + Finset.card_univ, nsmul_eq_mul] + field_simp + linear_combination hcard + rw [show (fun j => ∑ σ : Equiv.Perm ι, w (σ⁻¹ j)) + = (fun _ : ι => ∑ σ : Equiv.Perm ι, w (σ⁻¹ j₀)) from funext fun j => hconst j j₀, + diagonalOperator_const, hgval] + +/-- The **sign-diagonal unitary** `Sε = ∑ᵢ (-1)^{ε i} |bᵢ⟩⟨bᵢ|` packaged as a +`LinearIsometryEquiv`, via `Unitary.linearIsometryEquiv` on the self-adjoint unitary +`OrthonormalBasis.signDiagonal`. -/ +noncomputable def signDiagonalEquiv (ε : ι → Bool) : E ≃ₗᵢ[𝕜] E := + Unitary.linearIsometryEquiv ⟨b.signDiagonal ε, b.signDiagonal_mem_unitary ε⟩ + +@[simp] +theorem coe_signDiagonalEquiv (ε : ι → Bool) : + ⇑(b.signDiagonalEquiv ε) = ⇑(b.signDiagonal ε) := by + have h : ((b.signDiagonalEquiv ε).toContinuousLinearEquiv : E →L[𝕜] E) = b.signDiagonal ε := + Unitary.coe_linearIsometryEquiv_apply ⟨b.signDiagonal ε, b.signDiagonal_mem_unitary ε⟩ + ext x + rw [← LinearIsometryEquiv.coe_toContinuousLinearEquiv, ← ContinuousLinearEquiv.coe_coe, h] + +omit [CompleteSpace E] in +/-- The sign-diagonal operator squares to the identity (`(±1)² = 1`). -/ +theorem signDiagonal_comp_self (ε : ι → Bool) : + (b.signDiagonal ε).comp (b.signDiagonal ε) = 1 := by + rw [signDiagonal, diagonalOperator_comp, ← b.diagonalOperator_one] + congr 1 + funext i + simp only [Pi.mul_apply, Pi.one_apply] + cases ε i <;> norm_num + +theorem coe_signDiagonalEquiv_symm (ε : ι → Bool) : + ⇑(b.signDiagonalEquiv ε).symm = ⇑(b.signDiagonal ε) := by + ext x + apply (b.signDiagonalEquiv ε).injective + rw [LinearIsometryEquiv.apply_symm_apply, coe_signDiagonalEquiv, ← ContinuousLinearMap.comp_apply, + signDiagonal_comp_self, one_apply_eq_self] + +/-- **Conjugation by the sign-diagonal unitary** as `conjStarAlgEquiv` agrees with the raw +composition `Sε ∘ A ∘ Sε`, bridging `OrthonormalBasis.sum_signDiagonal_conj_self` to the +`LinearIsometryEquiv` form. -/ +theorem signDiagonalEquiv_conjStarAlgEquiv (ε : ι → Bool) (A : E →L[𝕜] E) : + (b.signDiagonalEquiv ε).conjStarAlgEquiv A + = (b.signDiagonal ε).comp (A.comp (b.signDiagonal ε)) := by + ext y + rw [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, coe_signDiagonalEquiv_symm, + coe_signDiagonalEquiv] + simp only [ContinuousLinearMap.comp_apply] + +variable [DecidableEq ι] + +/-- The **depolarizing `1`-design unitaries**: the composites `Pσ ∘ Sε` of a sign-diagonal unitary +`Sε` and a basis permutation `Pσ`, indexed by `(ε, σ) : (ι → Bool) × Equiv.Perm ι`. Their uniform +average of conjugations is the completely depolarizing channel +(`sum_conjStarAlgEquiv_depolarizingUnitary`). -/ +noncomputable def depolarizingUnitary (p : (ι → Bool) × Equiv.Perm ι) : E ≃ₗᵢ[𝕜] E := + (b.signDiagonalEquiv p.1).trans (b.equiv b p.2) + +/-- **The completely depolarizing channel as a finite unitary `1`-design** (Nielsen & Chuang, +Exercise 11.19). The uniform average of the `2^d · d!` conjugations of `A` by the depolarizing +unitaries `Pσ Sε` equals `(tr A / d) · I`, where `d = |ι|` is the dimension: + +`(2^d d!)⁻¹ • ∑_{ε, σ} (Pσ Sε) A (Pσ Sε)† = (tr A / d) • I`. + +Conjugating by `Pσ Sε` first dephases `A` to its basis-diagonal (summing over `ε`, +`sum_signDiagonal_conj_self`) and then uniformises that diagonal (averaging over `σ`, +`sum_equiv_conjStarAlgEquiv_diagonalOperator`); the mean of the diagonal entries is the trace over +the dimension. Since the weights `(2^d d!)⁻¹` are a (uniform) probability distribution and each +conjugation is unitary, this exhibits the depolarizing channel as a mixed-unitary channel. -/ +theorem sum_conjStarAlgEquiv_depolarizingUnitary [Nonempty ι] (A : E →L[𝕜] E) : + ∑ p : (ι → Bool) × Equiv.Perm ι, + (((2 : 𝕜) ^ Fintype.card ι * (Fintype.card ι).factorial)⁻¹) • + (b.depolarizingUnitary p).conjStarAlgEquiv A + = (LinearMap.trace 𝕜 E (A : E →ₗ[𝕜] E) / (Fintype.card ι : 𝕜)) • (1 : E →L[𝕜] E) := by + rw [← Finset.smul_sum] + -- Reduce the double average to the permutation average of the dephased (diagonal) operator. + have hbody : ∑ p : (ι → Bool) × Equiv.Perm ι, (b.depolarizingUnitary p).conjStarAlgEquiv A + = (2 : 𝕜) ^ Fintype.card ι • + ∑ σ : Equiv.Perm ι, (b.equiv b σ).conjStarAlgEquiv + (b.diagonalOperator (fun i => inner 𝕜 (b i) (A (b i)))) := by + rw [Fintype.sum_prod_type, Finset.sum_comm, Finset.smul_sum] + refine Finset.sum_congr rfl fun σ _ => ?_ + have hstep : ∀ ε : ι → Bool, (b.depolarizingUnitary (ε, σ)).conjStarAlgEquiv A + = (b.equiv b σ).conjStarAlgEquiv + ((b.signDiagonal ε).comp (A.comp (b.signDiagonal ε))) := fun ε => by + simp only [depolarizingUnitary, LinearIsometryEquiv.conjStarAlgEquiv_trans, + StarAlgEquiv.trans_apply, signDiagonalEquiv_conjStarAlgEquiv] + simp_rw [hstep] + rw [← map_sum, sum_signDiagonal_conj_self, map_smul] + rw [hbody, sum_equiv_conjStarAlgEquiv_diagonalOperator, smul_smul, smul_smul, + LinearMap.trace_eq_sum_inner (A : E →ₗ[𝕜] E) b] + simp only [ContinuousLinearMap.coe_coe] + have hn : (Fintype.card ι : 𝕜) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hfac : ((Fintype.card ι).factorial : 𝕜) ≠ 0 := + Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) + have h2 : (2 : 𝕜) ^ Fintype.card ι ≠ 0 := pow_ne_zero _ two_ne_zero + congr 1 + field_simp + +end CompleteSpace + +end OrthonormalBasis + +namespace LinearIsometryEquiv + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] [CompleteSpace E] + +/-- **There is a finite unitary `1`-design realising the completely depolarizing channel** +(Nielsen & Chuang, Exercise 11.19, existential form). On any nontrivial finite-dimensional inner +product space of dimension `d = finrank 𝕜 E`, there exist a finite family of unitaries +`Uⱼ : E ≃ₗᵢ[𝕜] E` and a probability distribution `pⱼ` such that for **every** operator `A`, + +`∑ⱼ pⱼ Uⱼ A Uⱼ† = (tr A / d) • I`. + +This is the "show that there exists a set of unitary matrices `Uⱼ` and a probability distribution +`pⱼ` such that `∑ⱼ pⱼ Uⱼ A Uⱼ† = tr(A) I/d`" of the exercise. The witness is the depolarizing +`1`-design `{Pσ Sε}` of `OrthonormalBasis.sum_conjStarAlgEquiv_depolarizingUnitary` for the standard +orthonormal basis, with the uniform weights `pⱼ = (2^d d!)⁻¹`. -/ +theorem exists_conjStarAlgEquiv_oneDesign [Nontrivial E] : + ∃ (ι : Type) (_ : Fintype ι) (U : ι → (E ≃ₗᵢ[𝕜] E)) (p : ι → ℝ), + (∀ i, 0 ≤ p i) ∧ (∑ i, p i = 1) ∧ + ∀ A : E →L[𝕜] E, ∑ i, (p i : 𝕜) • (U i).conjStarAlgEquiv A + = (LinearMap.trace 𝕜 E (A : E →ₗ[𝕜] E) / (Module.finrank 𝕜 E : 𝕜)) • (1 : E →L[𝕜] E) := by + classical + set d := Module.finrank 𝕜 E with hd + have hpos : 0 < d := Module.finrank_pos + have : Nonempty (Fin d) := ⟨⟨0, hpos⟩⟩ + set b := stdOrthonormalBasis 𝕜 E with hb + have hcard : Fintype.card ((Fin d → Bool) × Equiv.Perm (Fin d)) = 2 ^ d * d.factorial := by + simp [Fintype.card_perm] + refine ⟨(Fin d → Bool) × Equiv.Perm (Fin d), inferInstance, b.depolarizingUnitary, + fun _ => ((2 : ℝ) ^ d * d.factorial)⁻¹, fun _ => by positivity, ?_, ?_⟩ + · rw [Finset.sum_const, Finset.card_univ, hcard, nsmul_eq_mul] + have : ((2 : ℝ) ^ d * d.factorial) ≠ 0 := by positivity + push_cast + field_simp + · intro A + have htw := b.sum_conjStarAlgEquiv_depolarizingUnitary A + rw [Fintype.card_fin] at htw + rw [← htw] + refine Finset.sum_congr rfl fun i _ => ?_ + congr 1 + push_cast + ring + +end LinearIsometryEquiv diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DiagonalOperatorEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DiagonalOperatorEntropy.lean new file mode 100644 index 0000000000..10e148832e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/DiagonalOperatorEntropy.lean @@ -0,0 +1,94 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryTwirl + +/-! +# Von Neumann entropy of a diagonal density operator + +Fix an orthonormal basis `b` of a finite-dimensional inner product space `E` over `𝕜` and a +*real* weight vector `p : ι → ℝ`. The operator diagonal in `b`, +`b.diagonalOperator (fun i ↦ (p i : 𝕜)) = ∑ᵢ pᵢ • |bᵢ⟩⟨bᵢ|`, is self-adjoint, and this file +relates its operator-level data to the classical distribution `p`: + +* `OrthonormalBasis.trace_diagonalOperator`: its trace is `∑ᵢ wᵢ`; +* `OrthonormalBasis.diagonalOperator_isDensityOp`: it is a **density operator** when `p` is a + probability distribution (nonnegative, summing to one); +* `OrthonormalBasis.diagonalOperator_vonNeumannEntropy`: its **von Neumann entropy is the + Shannon entropy of `p`**, `S(∑ᵢ pᵢ |bᵢ⟩⟨bᵢ|) = H(p)`. + +This is the bridge between the operator (quantum) and distribution (classical) notions of +entropy: it realises any classical distribution `p` as the eigenvalue spectrum of a diagonal +density operator, so operator-level entropy facts specialise to the Shannon entropy. In +particular it is the key step in deducing concavity of the Shannon entropy from concavity of the +von Neumann entropy (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 11.21). + +## Main results + +* `OrthonormalBasis.trace_diagonalOperator` +* `OrthonormalBasis.diagonalOperator_isDensityOp` +* `OrthonormalBasis.diagonalOperator_vonNeumannEntropy` +-/ + +@[expose] public section + +namespace OrthonormalBasis + +variable {ι 𝕜 E : Type*} [RCLike 𝕜] [Fintype ι] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **Trace of a diagonal operator**: `tr(∑ᵢ wᵢ |bᵢ⟩⟨bᵢ|) = ∑ᵢ wᵢ`. The trace is the sum of the +diagonal inner products `⟪bᵢ, (diag w) bᵢ⟫ = wᵢ` over the orthonormal basis. -/ +theorem trace_diagonalOperator (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) : + LinearMap.trace 𝕜 E ↑(b.diagonalOperator w) = ∑ i, w i := by + classical + rw [LinearMap.trace_eq_sum_inner (↑(b.diagonalOperator w) : E →ₗ[𝕜] E) b] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.coe_coe, b.inner_diagonalOperator w i (b i), + orthonormal_iff_ite.mp b.orthonormal i i, ite_eq_left rfl, mul_one] + +/-- A diagonal operator whose (real) diagonal `p` is a **probability distribution** — nonnegative +with `∑ᵢ pᵢ = 1` — is a **density operator**: positive (`diagonalOperator_isPositive_of_nonneg`) +with unit trace (`trace_diagonalOperator`). -/ +theorem diagonalOperator_isDensityOp (b : OrthonormalBasis ι 𝕜 E) {p : ι → ℝ} + (hp : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + (b.diagonalOperator fun i => (p i : 𝕜)).IsDensityOp := by + rw [ContinuousLinearMap.isDensityOp_iff] + refine ⟨b.diagonalOperator_isPositive_of_nonneg _ fun i => RCLike.ofReal_nonneg.mpr (hp i), ?_⟩ + rw [trace_diagonalOperator, ← RCLike.ofReal_sum, hsum, RCLike.ofReal_one] + +/-- **Von Neumann entropy of a diagonal operator is the Shannon entropy of its diagonal**: +`S(∑ᵢ pᵢ |bᵢ⟩⟨bᵢ|) = H(p)` for a real diagonal `p : ι → ℝ`. + +The operator `T = ∑ᵢ pᵢ |bᵢ⟩⟨bᵢ|` is self-adjoint (its adjoint replaces the diagonal by its +`star`, which fixes the real entries), so its underlying linear map is symmetric. Its von Neumann +entropy is therefore the Shannon entropy of its canonical eigenvalue spectrum +(`ContinuousLinearMap.vonNeumannEntropy_of_isSymmetric`); the orthonormal basis `b` is an +eigenbasis with eigenvalues `p` (`diagonalOperator_apply_self`), so the eigenvalue-recognition +theorem identifies the two spectra up to a permutation, and Shannon entropy depends only on the +multiset of values (`Real.entropy_eq_of_multiset_map_eq`). -/ +theorem diagonalOperator_vonNeumannEntropy [FiniteDimensional 𝕜 E] [CompleteSpace E] + (b : OrthonormalBasis ι 𝕜 E) (p : ι → ℝ) : + (b.diagonalOperator fun i => (p i : 𝕜)).vonNeumannEntropy = Real.entropy p := by + have hsa : IsSelfAdjoint (b.diagonalOperator fun i => (p i : 𝕜)) := by + rw [isSelfAdjoint_iff, ContinuousLinearMap.star_eq_adjoint, b.diagonalOperator_adjoint] + congr 1 + funext i + simp only [Pi.star_apply, RCLike.star_def, RCLike.conj_ofReal] + have hsymm := ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mp hsa + rw [ContinuousLinearMap.vonNeumannEntropy_of_isSymmetric hsymm] + refine Real.entropy_eq_of_multiset_map_eq ?_ + refine (LinearMap.IsSymmetric.eigenvalues_multiset_map_eq_of_eigenbasis hsymm rfl b.toBasis + fun i => ?_).symm + have h := b.diagonalOperator_apply_self (fun j => (p j : 𝕜)) i + simpa only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe] using h + +end OrthonormalBasis diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Dual.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Dual.lean new file mode 100644 index 0000000000..76d67973e7 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Dual.lean @@ -0,0 +1,34 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Dual + +/-! +# The range of a rank-one operator has dimension at most one +-/ + +public section + +namespace InnerProductSpace + +/-- The range of a rank-one operator has dimension at most one. -/ +lemma finrank_range_rankOne_le_one {𝕜 : Type*} [RCLike 𝕜] {E F : Type*} + [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + (x : E) (y : F) : + Module.finrank 𝕜 (LinearMap.range (rankOne 𝕜 x y : F →L[𝕜] E).toLinearMap) ≤ 1 := by + have hx1 : Module.finrank 𝕜 (𝕜 ∙ x) ≤ 1 := by + rcases eq_or_ne x 0 with rfl | hx + · rw [Submodule.span_singleton_eq_bot.mpr rfl, finrank_bot]; exact zero_le_one + · exact (finrank_span_singleton hx).le + refine (Submodule.finrank_mono ?_).trans hx1 + rintro _ ⟨z, rfl⟩ + exact Submodule.smul_mem _ _ (Submodule.mem_span_singleton_self _) + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EigenvalueMonotone.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EigenvalueMonotone.lean new file mode 100644 index 0000000000..4a27105f13 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EigenvalueMonotone.lean @@ -0,0 +1,186 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive + +/-! +# Weyl's monotonicity theorem for eigenvalues of symmetric operators + +For self-adjoint (symmetric) operators on a finite-dimensional inner product space, the sorted +eigenvalue function `LinearMap.IsSymmetric.eigenvalues` (decreasing, indexed by `Fin n`) is +monotone with respect to the quadratic-form order: if `A ≤ B` in the sense that +`re ⟪A x, x⟫ ≤ re ⟪B x, x⟫` for all `x`, then `λᵢ(A) ≤ λᵢ(B)` for every index `i`, where the +eigenvalues are paired in the common sorted order. + +This is **Weyl's monotonicity theorem**, the special case of the Courant–Fischer min–max +principle needed for eigenvalue perturbation. The proof is the standard dimension-counting +argument: the top-`(i+1)` eigenspace of `A` (dimension `i+1`) and the bottom-`(n-i)` eigenspace +of `B` (dimension `n-i`) have dimensions summing to `n+1 > n`, hence intersect in a nonzero +vector `x`; the Rayleigh quotient of `A` on `x` is `≥ λᵢ(A)`, that of `B` is `≤ λᵢ(B)`, and the +order hypothesis chains them. + +## Main results + +* `LinearMap.IsSymmetric.re_inner_apply_self_eq_sum`: the Rayleigh decomposition + `re ⟪T x, x⟫ = ∑ⱼ λⱼ · ‖⟪bⱼ, x⟫‖²` in an orthonormal eigenbasis `b`. +* `LinearMap.IsSymmetric.eigenvalues_mono`: Weyl's monotonicity theorem in quadratic-form order. +* `LinearMap.IsSymmetric.eigenvalues_mono_of_sub_isPositive`: the corollary phrased via + `(B - A).IsPositive` (the operator `B - A` is positive semidefinite). + +These are the operator-analysis input to the eigenvalue/trace-norm bound `∑ᵢ|λᵢ(A) − λᵢ(B)| ≤ +‖A − B‖₁` (Mirsky's inequality), itself the spectral core of Fannes' inequality +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.6, eq. (11.46)). +-/ + +@[expose] public section + +open RCLike + +namespace OrthonormalBasis + +variable {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- If `x` lies in the span of the sub-family `{b j | p j}` of an orthonormal basis `b`, then the +coordinate `⟪b k, x⟫` of `x` along any basis vector `b k` whose index fails `p` vanishes. This is +the coordinate form of "`x` is orthogonal to the complementary eigenspace". -/ +theorem inner_eq_zero_of_mem_span_subtype {ι : Type*} [Fintype ι] (b : OrthonormalBasis ι 𝕜 E) + {p : ι → Prop} {x : E} {k : ι} + (hx : x ∈ Submodule.span 𝕜 (Set.range fun j : {j // p j} => b j.1)) (hk : ¬ p k) : + inner 𝕜 (b k) x = 0 := by + classical + rw [Submodule.mem_span_range_iff_exists_fun] at hx + obtain ⟨c, rfl⟩ := hx + rw [inner_sum] + refine Finset.sum_eq_zero fun j _ => ?_ + have hkj : k ≠ (j : ι) := by rintro rfl; exact hk j.2 + rw [inner_smul_right, b.orthonormal.2 hkj, mul_zero] + +end OrthonormalBasis + +namespace LinearMap.IsSymmetric + +variable {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] {T : E →ₗ[𝕜] E} {n : ℕ} + +/-- **Rayleigh decomposition**: in the orthonormal eigenbasis of a symmetric operator `T`, the +real Rayleigh quantity `re ⟪T x, x⟫` is the eigenvalue-weighted sum of squared coordinate norms, +`∑ⱼ λⱼ · ‖⟪bⱼ, x⟫‖²`. -/ +theorem re_inner_apply_self_eq_sum (hT : T.IsSymmetric) (hn : Module.finrank 𝕜 E = n) (x : E) : + re (inner 𝕜 (T x) x) = + ∑ j, hT.eigenvalues hn j * ‖inner 𝕜 (hT.eigenvectorBasis hn j) x‖ ^ 2 := by + have key : inner 𝕜 (T x) x = + ((∑ j, hT.eigenvalues hn j * ‖inner 𝕜 (hT.eigenvectorBasis hn j) x‖ ^ 2 : ℝ) : 𝕜) := by + rw [hT.spectral_sum_apply hn x, sum_inner, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [smul_smul, inner_smul_left, map_mul (starRingEnd 𝕜), RCLike.conj_ofReal, mul_assoc, + RCLike.conj_mul] + push_cast + ring + rw [key, RCLike.ofReal_re] + +/-- **Rayleigh lower bound on a top eigenspace.** If every coordinate of `x` whose eigenvalue is +`< c` vanishes, then `c ‖x‖² ≤ re ⟪T x, x⟫`. Applied with `c = λᵢ(T)` and `x` in the span of the +top `i+1` eigenvectors, this lower-bounds the Rayleigh quotient by `λᵢ`. -/ +theorem le_re_inner_of_coord_vanish (hT : T.IsSymmetric) (hn : Module.finrank 𝕜 E = n) {x : E} + {c : ℝ} (hx : ∀ j, hT.eigenvalues hn j < c → inner 𝕜 (hT.eigenvectorBasis hn j) x = 0) : + c * ‖x‖ ^ 2 ≤ re (inner 𝕜 (T x) x) := by + rw [hT.re_inner_apply_self_eq_sum hn x, ← (hT.eigenvectorBasis hn).sum_sq_norm_inner_right x, + Finset.mul_sum] + refine Finset.sum_le_sum fun j _ => ?_ + by_cases h : hT.eigenvalues hn j < c + · rw [hx j h]; simp + · exact mul_le_mul_of_nonneg_right (not_lt.mp h) (sq_nonneg _) + +/-- **Rayleigh upper bound on a bottom eigenspace.** If every coordinate of `x` whose eigenvalue +is `> c` vanishes, then `re ⟪T x, x⟫ ≤ c ‖x‖²`. Applied with `c = λᵢ(T)` and `x` in the span of +the bottom `n - i` eigenvectors, this upper-bounds the Rayleigh quotient by `λᵢ`. -/ +theorem re_inner_le_of_coord_vanish (hT : T.IsSymmetric) (hn : Module.finrank 𝕜 E = n) {x : E} + {c : ℝ} (hx : ∀ j, c < hT.eigenvalues hn j → inner 𝕜 (hT.eigenvectorBasis hn j) x = 0) : + re (inner 𝕜 (T x) x) ≤ c * ‖x‖ ^ 2 := by + rw [hT.re_inner_apply_self_eq_sum hn x, ← (hT.eigenvectorBasis hn).sum_sq_norm_inner_right x, + Finset.mul_sum] + refine Finset.sum_le_sum fun j _ => ?_ + by_cases h : c < hT.eigenvalues hn j + · rw [hx j h]; simp + · exact mul_le_mul_of_nonneg_right (not_lt.mp h) (sq_nonneg _) + +/-- **Weyl's monotonicity theorem** (quadratic-form order). For symmetric operators `A, B` on a +finite-dimensional inner product space with `re ⟪A x, x⟫ ≤ re ⟪B x, x⟫` for all `x`, the sorted +eigenvalues (decreasing, paired by index) satisfy `λᵢ(A) ≤ λᵢ(B)` for every `i`. + +Proof: the span `U` of the top `i+1` eigenvectors of `A` has dimension `i+1`, the span `W` of the +bottom `n-i` eigenvectors of `B` has dimension `n-i`, so `dim U + dim W = n+1 > n` forces a +nonzero `x ∈ U ⊓ W`. On `U`, `λᵢ(A) ‖x‖² ≤ re ⟪A x, x⟫`; on `W`, `re ⟪B x, x⟫ ≤ λᵢ(B) ‖x‖²`; the +hypothesis chains these, and `‖x‖² > 0` cancels. -/ +theorem eigenvalues_mono {A B : E →ₗ[𝕜] E} (hA : A.IsSymmetric) (hB : B.IsSymmetric) + (hle : ∀ x, re (inner 𝕜 (A x) x) ≤ re (inner 𝕜 (B x) x)) (hn : Module.finrank 𝕜 E = n) + (i : Fin n) : hA.eigenvalues hn i ≤ hB.eigenvalues hn i := by + set U := Submodule.span 𝕜 (Set.range fun j : {j : Fin n // j ≤ i} => hA.eigenvectorBasis hn j.1) + with hU + set W := Submodule.span 𝕜 (Set.range fun j : {j : Fin n // i ≤ j} => hB.eigenvectorBasis hn j.1) + with hW + -- The two eigenspaces have dimensions `i+1` and `n-i` respectively. + have hUfr : Module.finrank 𝕜 U = Fintype.card {j : Fin n // j ≤ i} := + finrank_span_eq_card + ((hA.eigenvectorBasis hn).orthonormal.comp _ Subtype.val_injective).linearIndependent + have hWfr : Module.finrank 𝕜 W = Fintype.card {j : Fin n // i ≤ j} := + finrank_span_eq_card + ((hB.eigenvectorBasis hn).orthonormal.comp _ Subtype.val_injective).linearIndependent + -- Their dimensions sum to `n + 1`. + have hcard : Fintype.card {j : Fin n // j ≤ i} + Fintype.card {j : Fin n // i ≤ j} = n + 1 := by + rw [Fintype.card_subtype, Fintype.card_subtype, ← Finset.card_union_add_card_inter] + have hu : Finset.univ.filter (· ≤ i) ∪ Finset.univ.filter (i ≤ ·) + = (Finset.univ : Finset (Fin n)) := by + rw [← Finset.filter_or] + exact Finset.filter_true_of_mem fun x _ => le_total x i + have hin : Finset.univ.filter (· ≤ i) ∩ Finset.univ.filter (i ≤ ·) = {i} := by + rw [← Finset.filter_and] + ext j + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] + exact ⟨fun ⟨h1, h2⟩ => le_antisymm h1 h2, fun h => h ▸ ⟨le_refl _, le_refl _⟩⟩ + rw [hu, hin, Finset.card_univ, Fintype.card_fin, Finset.card_singleton] + -- Dimension counting: `U` and `W` cannot be disjoint. + have hne : U ⊓ W ≠ ⊥ := by + intro hbot + have hle2 := Submodule.finrank_add_finrank_le_of_disjoint (disjoint_iff.mpr hbot) + rw [hUfr, hWfr, hcard, hn] at hle2 + omega + obtain ⟨x, hxUW, hx0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hne + rw [Submodule.mem_inf] at hxUW + obtain ⟨hxU, hxW⟩ := hxUW + have hxpos : 0 < ‖x‖ := norm_pos_iff.mpr hx0 + have hxnorm : 0 < ‖x‖ ^ 2 := by positivity + -- On `U`, the Rayleigh quotient of `A` is at least `λᵢ(A)`. + have hlow : hA.eigenvalues hn i * ‖x‖ ^ 2 ≤ re (inner 𝕜 (A x) x) := by + refine hA.le_re_inner_of_coord_vanish hn fun j hj => ?_ + refine (hA.eigenvectorBasis hn).inner_eq_zero_of_mem_span_subtype hxU fun hji => ?_ + exact absurd (hA.eigenvalues_antitone hn hji) (not_le.mpr hj) + -- On `W`, the Rayleigh quotient of `B` is at most `λᵢ(B)`. + have hupp : re (inner 𝕜 (B x) x) ≤ hB.eigenvalues hn i * ‖x‖ ^ 2 := by + refine hB.re_inner_le_of_coord_vanish hn fun j hj => ?_ + refine (hB.eigenvectorBasis hn).inner_eq_zero_of_mem_span_subtype hxW fun hij => ?_ + exact absurd (hB.eigenvalues_antitone hn hij) (not_le.mpr hj) + have hchain : hA.eigenvalues hn i * ‖x‖ ^ 2 ≤ hB.eigenvalues hn i * ‖x‖ ^ 2 := + hlow.trans ((hle x).trans hupp) + exact le_of_mul_le_mul_right hchain hxnorm + +/-- **Weyl's monotonicity theorem** (positivity form). If `A, B` are symmetric and `B - A` is a +positive semidefinite operator, then `λᵢ(A) ≤ λᵢ(B)` for every index `i` (sorted eigenvalues, +paired by index). -/ +theorem eigenvalues_mono_of_sub_isPositive {A B : E →ₗ[𝕜] E} (hA : A.IsSymmetric) + (hB : B.IsSymmetric) (hP : (B - A).IsPositive) (hn : Module.finrank 𝕜 E = n) (i : Fin n) : + hA.eigenvalues hn i ≤ hB.eigenvalues hn i := by + refine hA.eigenvalues_mono hB (fun x => ?_) hn i + have hnn := hP.re_inner_nonneg_left x + rw [LinearMap.sub_apply, inner_sub_left, map_sub] at hnn + linarith + +end LinearMap.IsSymmetric diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelity.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelity.lean new file mode 100644 index 0000000000..b0582d0388 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelity.lean @@ -0,0 +1,224 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum + +/-! # The entanglement fidelity of a quantum operation and its concentration in one element + +For a finite family of operation elements `E : ι → (H →L[ℂ] H)` — the Kraus operators of a +trace-preserving quantum operation `E(ρ) = Σᵢ Eᵢ ρ Eᵢ†` — the **entanglement fidelity** of a state +`ρ` is the real number +`F(ρ, E) = Σᵢ |tr(ρ Eᵢ)|²` +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, Eq. (9.135)). This is the +computational formula for the intrinsic entanglement fidelity `F(ρ, E) = ⟨RQ|(I ⊗ E)(|RQ⟩⟨RQ|)|RQ⟩` +(Eqs. (9.128)–(9.135)) obtained from any operator-sum representation of the operation. + +This file records the quantity and the two facts about it that require the unitary-freedom theorem +(`ContinuousLinearMap.krausSumₗ_eq_iff_exists_mem_unitaryGroup`, N&C Theorem 8.2): + +* `ContinuousLinearMap.entanglementFidelity` — the sum `Σᵢ |tr(ρ Eᵢ)|²`. +* `ContinuousLinearMap.entanglementFidelity_eq_of_krausSumₗ_eq` — **well-definedness**: the sum + depends on the operation elements only through the operator-sum map `krausSumₗ E` they generate, + so `F(ρ, E)` is genuinely a function of the operation `E` (not of the chosen elements). This is + what licenses the notation `F(ρ, E)` on the intrinsic quantity in Eq. (9.135). +* `ContinuousLinearMap.exists_krausSumₗ_eq_entanglementFidelity_eq_normSq_trace` — **Nielsen & + Chuang, Problem 9.2**: for each `ρ` there is a set of operation elements `F` *for the same + operation* (`krausSumₗ F = krausSumₗ E`) in which the whole fidelity is carried by the first + element — every other `tr(ρ Fᵢ)` vanishes and + `F(ρ, E) = |tr(ρ F₀)|²` (Eq. (9.146)). + +## Method + +Writing `vᵢ = tr(ρ Eᵢ)`, the fidelity is `‖v‖²` for the Euclidean vector `v ∈ ℂ^ι`. A change of +operation elements `Eᵢ = Σⱼ uᵢⱼ Fⱼ` by a unitary `u` (Theorem 8.2) transforms the trace vector by +the same unitary, and a unitary preserves the `ℓ²` norm — giving well-definedness +(`Matrix.sum_normSq_mulVec_eq_of_mem_unitaryGroup`). For Problem 9.2, choosing `u` to be a unitary +matrix whose zeroth row is the unit vector `conj v / ‖v‖` (built from a single unit vector by +`EuclideanSpace.exists_mem_unitaryGroup_row_zero_eq`) rotates all of `v`'s length into the zeroth +coordinate: `tr(ρ F₀) = ‖v‖` and `tr(ρ Fᵢ) = 0` for `i ≠ 0`, so `‖v‖² = |tr(ρ F₀)|²`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §9.3 (Eqs. (9.135), (9.146); Problem 9.2). +-/ + +open scoped InnerProductSpace ComplexConjugate + +@[expose] public section + +/-- **A unitary matrix acting on a vector preserves the `ℓ²` sum of squared norms:** +`Σᵢ |Σⱼ uᵢⱼ wⱼ|² = Σⱼ |wⱼ|²` for `u ∈ Matrix.unitaryGroup ι ℂ`. The row `i ↦ Σⱼ uᵢⱼ wⱼ` is +`u.mulVec w i`; the identity is the coordinate form of the fact that a unitary matrix is an +isometry of `EuclideanSpace ℂ ι`. The proof casts to `ℂ`, expands each squared norm as `conj · ·`, +and collapses the double sum through the unitarity relation `Σᵢ conj(uᵢⱼ) uᵢₖ = (u⋆u)ⱼₖ = δⱼₖ`. -/ +theorem Matrix.sum_normSq_mulVec_eq_of_mem_unitaryGroup {ι : Type*} [Fintype ι] [DecidableEq ι] + {u : Matrix ι ι ℂ} (hu : u ∈ Matrix.unitaryGroup ι ℂ) (w : ι → ℂ) : + ∑ i, ‖∑ j, u i j * w j‖ ^ 2 = ∑ j, ‖w j‖ ^ 2 := by + have key : ∀ j k : ι, (∑ i, conj (u i j) * u i k) = if j = k then (1 : ℂ) else 0 := by + intro j k + have h1 : (star u * u : Matrix ι ι ℂ) = 1 := Matrix.mem_unitaryGroup_iff'.mp hu + have h2 := congrFun (congrFun h1 j) k + rw [Matrix.mul_apply, Matrix.one_apply] at h2 + rw [← h2] + simp only [Matrix.star_apply, starRingEnd_apply] + apply Complex.ofReal_injective + push_cast + have hL : ∀ i, ((‖∑ j, u i j * w j‖ : ℝ) : ℂ) ^ 2 + = ∑ j, ∑ k, conj (u i j) * u i k * (conj (w j) * w k) := by + intro i + have e1 : conj (∑ j, u i j * w j) * (∑ j, u i j * w j) + = ((‖∑ j, u i j * w j‖ : ℝ) : ℂ) ^ 2 := by + rw [mul_comm, Complex.mul_conj, Complex.normSq_eq_norm_sq, Complex.ofReal_pow] + rw [← e1, map_sum, Finset.sum_mul_sum] + exact Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun k _ => by + rw [map_mul]; ring + rw [Finset.sum_congr rfl (fun i _ => hL i), Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul, key] + simp only [ite_mul, one_mul, zero_mul, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + rw [mul_comm, Complex.mul_conj, Complex.normSq_eq_norm_sq, Complex.ofReal_pow] + +namespace ContinuousLinearMap + +variable {H : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + {ι : Type*} [Fintype ι] + +/-- The **entanglement fidelity** `F(ρ, E) = Σᵢ |tr(ρ Eᵢ)|²` of a state `ρ` under the +trace-preserving quantum operation with operation elements `E : ι → (H →L[ℂ] H)`, i.e. +`E(ρ) = Σᵢ Eᵢ ρ Eᵢ†` (Nielsen & Chuang, Eq. (9.135)). It is a function of `ρ` and the operation +only — see `entanglementFidelity_eq_of_krausSumₗ_eq`. -/ +noncomputable def entanglementFidelity (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) : ℝ := + ∑ i, ‖LinearMap.trace ℂ H ((ρ * E i : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 + +omit [FiniteDimensional ℂ H] [CompleteSpace H] in +/-- The entanglement fidelity `F(ρ, E) = Σᵢ |tr(ρ Eᵢ)|²` is nonnegative, being a sum of squared +norms. -/ +theorem entanglementFidelity_nonneg (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) : + 0 ≤ entanglementFidelity ρ E := + Finset.sum_nonneg fun _ _ => sq_nonneg _ + +omit [FiniteDimensional ℂ H] [CompleteSpace H] in +/-- Linearity of the trace in the operation-element argument: +`tr(ρ · Σⱼ uⱼ Eⱼ) = Σⱼ uⱼ tr(ρ Eⱼ)`. -/ +theorem trace_mul_sum_smul (ρ : H →L[ℂ] H) (u : ι → ℂ) (E : ι → H →L[ℂ] H) : + LinearMap.trace ℂ H ((ρ * (∑ j, u j • E j) : H →L[ℂ] H) : H →ₗ[ℂ] H) + = ∑ j, u j * LinearMap.trace ℂ H ((ρ * E j : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [Finset.mul_sum, ContinuousLinearMap.toLinearMap_sum, map_sum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [mul_smul_comm, ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul] + +/-- **The entanglement fidelity depends only on the operation, not on the choice of operation +elements** (well-definedness of Nielsen & Chuang Eq. (9.135)). If two families `E`, `F` generate +the same operator-sum map, `krausSumₗ E = krausSumₗ F`, then `F(ρ, E) = F(ρ, F)`. By unitary +freedom (Theorem 8.2) the elements are related by a unitary coefficient matrix, which acts on the +trace vector `i ↦ tr(ρ Eᵢ)`; a unitary preserves its `ℓ²` norm +(`Matrix.sum_normSq_mulVec_eq_of_mem_unitaryGroup`). -/ +theorem entanglementFidelity_eq_of_krausSumₗ_eq (ρ : H →L[ℂ] H) {E F : ι → H →L[ℂ] H} + (h : krausSumₗ E = krausSumₗ F) : entanglementFidelity ρ E = entanglementFidelity ρ F := by + classical + obtain ⟨u, hu, hEF⟩ := krausSumₗ_eq_iff_exists_mem_unitaryGroup.mp h + have htr : ∀ i, LinearMap.trace ℂ H ((ρ * E i : H →L[ℂ] H) : H →ₗ[ℂ] H) + = ∑ j, u i j * LinearMap.trace ℂ H ((ρ * F j : H →L[ℂ] H) : H →ₗ[ℂ] H) := fun i => by + rw [hEF i]; exact trace_mul_sum_smul ρ (u i) F + simp only [entanglementFidelity] + simp only [htr] + exact Matrix.sum_normSq_mulVec_eq_of_mem_unitaryGroup hu _ + +omit [FiniteDimensional ℂ H] in +/-- **Nielsen & Chuang, Problem 9.2.** For every state `ρ` and every trace-preserving quantum +operation — presented by operation elements `E : Fin n → (H →L[ℂ] H)` — there is a set of operation +elements `F` *for the same operation* (`krausSumₗ F = krausSumₗ E`) in which all the entanglement +fidelity is carried by the first element: `tr(ρ Fᵢ) = 0` for every `i ≠ 0`, and +`F(ρ, E) = |tr(ρ F₀)|²` (Eq. (9.146)). + +Let `vᵢ = tr(ρ Eᵢ)`, so `F(ρ, E) = ‖v‖²`. If `v = 0` the original elements already work. Otherwise +`EuclideanSpace.exists_mem_unitaryGroup_row_zero_eq` gives a unitary matrix `u` whose zeroth row is +the unit vector `conj v / ‖v‖`; setting `Fᵢ = Σⱼ uᵢⱼ Eⱼ` keeps the operation fixed (unitary freedom, +Theorem 8.2) while `tr(ρ Fᵢ) = Σⱼ uᵢⱼ vⱼ` rotates `v` into its zeroth coordinate — `tr(ρ F₀) = ‖v‖` +and, by orthonormality of the rows of `u`, `tr(ρ Fᵢ) = 0` for `i ≠ 0`. -/ +theorem exists_krausSumₗ_eq_entanglementFidelity_eq_normSq_trace + {n : ℕ} [NeZero n] (ρ : H →L[ℂ] H) (E : Fin n → H →L[ℂ] H) : + ∃ F : Fin n → H →L[ℂ] H, krausSumₗ F = krausSumₗ E ∧ + (∀ i, i ≠ 0 → LinearMap.trace ℂ H ((ρ * F i : H →L[ℂ] H) : H →ₗ[ℂ] H) = 0) ∧ + entanglementFidelity ρ E + = ‖LinearMap.trace ℂ H ((ρ * F 0 : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 := by + set trc : Fin n → ℂ := fun i => LinearMap.trace ℂ H ((ρ * E i : H →L[ℂ] H) : H →ₗ[ℂ] H) + with htrc + have hentE : entanglementFidelity ρ E = ∑ i, ‖trc i‖ ^ 2 := rfl + by_cases hS : entanglementFidelity ρ E = 0 + · -- `v = 0`: the original operation elements already carry no fidelity. + have hz : ∀ i, trc i = 0 := by + rw [hentE] at hS + have h := (Finset.sum_eq_zero_iff_of_nonneg (fun i _ => sq_nonneg _)).mp hS + intro i + have h2 : ‖trc i‖ ^ 2 = 0 := h i (Finset.mem_univ i) + simpa using h2 + refine ⟨E, rfl, fun i _ => hz i, ?_⟩ + rw [hS, show LinearMap.trace ℂ H ((ρ * E 0 : H →L[ℂ] H) : H →ₗ[ℂ] H) = trc 0 from rfl, hz 0] + simp + · -- `v ≠ 0`: rotate all of `v`'s length into the zeroth coordinate. + have hSnonneg : 0 ≤ entanglementFidelity ρ E := by + rw [hentE]; exact Finset.sum_nonneg fun i _ => sq_nonneg _ + have hSpos : 0 < entanglementFidelity ρ E := lt_of_le_of_ne hSnonneg (Ne.symm hS) + set N : ℝ := Real.sqrt (entanglementFidelity ρ E) with hNdef + have hNpos : 0 < N := Real.sqrt_pos.mpr hSpos + have hNsq : N ^ 2 = entanglementFidelity ρ E := Real.sq_sqrt hSnonneg + have hNC : (N : ℂ) ≠ 0 := by exact_mod_cast hNpos.ne' + -- the unit vector `conj v / ‖v‖` + set w' : EuclideanSpace ℂ (Fin n) := + (WithLp.equiv 2 (Fin n → ℂ)).symm (fun j => conj (trc j) / (N : ℂ)) with hw' + have hw'coord : ∀ j, w'.ofLp j = conj (trc j) / (N : ℂ) := fun j => rfl + have hw'norm : ‖w'‖ = 1 := by + have hsq : ‖w'‖ ^ 2 = 1 := by + rw [EuclideanSpace.norm_sq_eq] + have hterm : ∀ j, ‖w'.ofLp j‖ ^ 2 = ‖trc j‖ ^ 2 / N ^ 2 := fun j => by + rw [hw'coord j, norm_div, Complex.norm_conj, Complex.norm_real, + Real.norm_of_nonneg hNpos.le, div_pow] + rw [Finset.sum_congr rfl (fun j _ => hterm j), ← Finset.sum_div, ← hentE, hNsq, + div_self hS] + rw [← Real.sqrt_sq (norm_nonneg w'), hsq, Real.sqrt_one] + obtain ⟨u, hu, hurow⟩ := EuclideanSpace.exists_mem_unitaryGroup_row_zero_eq w' hw'norm + have hu0 : ∀ j, u 0 j = conj (trc j) / (N : ℂ) := fun j => by rw [hurow j, hw'coord j] + have hstar : ∀ j, (star u) j 0 = trc j / (N : ℂ) := fun j => by + rw [Matrix.star_apply, hu0 j, star_div₀, starRingEnd_apply, star_star, Complex.star_def, + Complex.conj_ofReal] + set F : Fin n → H →L[ℂ] H := fun i => ∑ j, u i j • E j with hF + have hFtr : ∀ i, LinearMap.trace ℂ H ((ρ * F i : H →L[ℂ] H) : H →ₗ[ℂ] H) + = ∑ j, u i j * trc j := fun i => trace_mul_sum_smul ρ (u i) E + refine ⟨F, krausSumₗ_eq_of_mem_unitaryGroup hu (fun i => rfl), ?_, ?_⟩ + · -- off-diagonal traces vanish: `(u · uᴴ)ᵢ₀ = 0` for `i ≠ 0` + intro i hi + rw [hFtr i] + have hmul : ∑ j, u i j * (star u) j 0 = 0 := by + have h2 := congrFun (congrFun (Matrix.mem_unitaryGroup_iff.mp hu) i) 0 + rwa [Matrix.mul_apply, Matrix.one_apply, ite_eq_right hi] at h2 + simp only [hstar, ← mul_div_assoc] at hmul + rw [← Finset.sum_div] at hmul + exact (div_eq_zero_iff.mp hmul).resolve_right hNC + · -- the zeroth element carries the whole fidelity: `tr(ρ F₀) = ‖v‖` + rw [hFtr 0] + have hval : ∑ j, u 0 j * trc j = (N : ℂ) := by + have hterm : ∀ j, u 0 j * trc j = conj (trc j) * trc j / (N : ℂ) := fun j => by + rw [hu0 j]; ring + rw [Finset.sum_congr rfl (fun j _ => hterm j), ← Finset.sum_div] + have hsum : ∑ j, conj (trc j) * trc j = ((entanglementFidelity ρ E : ℝ) : ℂ) := by + rw [hentE, Complex.ofReal_sum] + exact Finset.sum_congr rfl fun j _ => by + rw [mul_comm, Complex.mul_conj, Complex.normSq_eq_norm_sq] + rw [hsum, ← hNsq] + push_cast + rw [sq, mul_div_assoc, div_self hNC, mul_one] + rw [hval, Complex.norm_real, Real.norm_of_nonneg hNpos.le, hNsq] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelityBound.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelityBound.lean new file mode 100644 index 0000000000..40f37fe71b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntanglementFidelityBound.lean @@ -0,0 +1,467 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneTrace + +/-! # The entanglement infidelity as a sum of operation-element variances + +For a trace-preserving quantum operation with operation elements `E : ι → (H →L[ℂ] H)` (the Kraus +operators, `E(ρ) = Σᵢ Eᵢ ρ Eᵢ†`, `Σᵢ Eᵢ† Eᵢ = 1`), the entanglement fidelity is +`F(ρ, E) = Σᵢ |tr(ρ Eᵢ)|²` (`ContinuousLinearMap.entanglementFidelity`; Nielsen–Chuang, *Quantum +Computation and Quantum Information*, Eq. (9.135)). This file records the exact **variance +decomposition of the infidelity** `1 − F(ρ, E)`, the reduction step at the heart of Nielsen & +Chuang's *Problem 9.3* (fact (5): if `⟨ψ|E(|ψ⟩⟨ψ|)|ψ⟩ ≥ 1 − η` on the support of `ρ` then +`F(ρ, E) ≥ 1 − 3η/2`). + +Writing `⟨A⟩_ρ = tr(ρ A)`, the **operator variance** of an operation element `E` in the state `ρ` +is `Var_ρ(E) = ⟨E† E⟩_ρ − |⟨E⟩_ρ|²` (`ContinuousLinearMap.opVariance`; a Cauchy–Schwarz-nonnegative +quantity). The two identities below say that the entanglement infidelity is the *total* operator +variance of the Kraus family, in the two forms Problem 9.3 needs — the mixed-state form and the +pure-state form: + +* `ContinuousLinearMap.one_sub_entanglementFidelity_eq_sum_opVariance` — for a trace-preserving + family (`Σᵢ Eᵢ† Eᵢ = 1`) and a unit-trace `ρ`, + `1 − F(ρ, E) = Σᵢ Var_ρ(Eᵢ)`. Purely the linearity of the trace and the completeness relation; + no positivity is used, so it holds for any unit-trace `ρ`. +* `ContinuousLinearMap.re_inner_krausSumₗ_rankOne_self` — the **physical reading** of the pure-state + hypothesis: `⟨ψ| E(|ψ⟩⟨ψ|) |ψ⟩ = Σᵢ |⟨ψ, Eᵢ ψ⟩|²`, so the fidelity of the pure input `|ψ⟩⟨ψ|` is + computed from the operation elements exactly as Eq. (9.135) prescribes. +* `ContinuousLinearMap.one_sub_sum_normSq_inner_eq_sum` — the pure-state form of the decomposition: + for a unit vector `ψ` and a trace-preserving family, + `1 − Σᵢ |⟨ψ, Eᵢ ψ⟩|² = Σᵢ (‖Eᵢ ψ‖² − |⟨ψ, Eᵢ ψ⟩|²)`, each summand `≥ 0` + (`ContinuousLinearMap.normSq_inner_le_normSq_apply`). This is `Σᵢ Var_{|ψ⟩⟨ψ|}(Eᵢ)`, so combined + with the physical reading it says `1 − ⟨ψ|E(|ψ⟩⟨ψ|)|ψ⟩ = Σᵢ Var_{|ψ⟩⟨ψ|}(Eᵢ)`. + +This file also records the elementary combinatorial bound behind the *tight* `3η/2` constant of +fact (5), `weighted_offDiag_sum_le_half`: for a probability vector `p` and a nonnegative array `M` +whose every column has off-diagonal total `≤ η`, the doubly `p`-weighted off-diagonal sum is +`≤ η / 2`. Instantiated at `M a b = Σᵢ ‖⟨a, Eᵢ b⟩‖²` over an eigenbasis of `ρ`, this bounds the +off-diagonal "coherence" term of the entanglement infidelity; the `η / 2` (rather than `η`) is what +separates the true `F(ρ, E) ≥ 1 − 3η/2` from the weaker `1 − 2η`. + +Finally, this file assembles the two **eigenbasis ingredients** of fact (5) — the pieces that a +state `ρ = Σₐ pₐ |eₐ⟩⟨eₐ|` in a spectral eigenbasis contributes to the entanglement infidelity: + +* `ContinuousLinearMap.entanglementFidelity_sum_rankOne` — the *diagonal* ingredient: + `F(ρ, E) = Σⱼ |Σₐ pₐ ⟨eₐ, Eⱼ eₐ⟩|²`, i.e. the entanglement fidelity reads off the diagonal matrix + elements `⟨eₐ, Eⱼ eₐ⟩` (linearity of the trace + `trace_rankOne_self_comp`). +* `ContinuousLinearMap.offDiagCoherenceSum` and `ContinuousLinearMap.offDiagCoherenceSum_le` — the + *off-diagonal* ingredient: the coherence sum `S_off = Σ_{a≠b} pₐ p_b Σⱼ |⟨eₐ, Eⱼ e_b⟩|²`, and the + bound `S_off ≤ η / 2` obtained by feeding the per-column budget `sum_offDiag_normSq_inner_le` + (Parseval + completeness + the pure-state deficit at each eigenvector) into + `weighted_offDiag_sum_le_half`. + +Combined with the phase-diagonal-twirl reduction `1 − F(ρ, E) ≤ η + S_off` (a subsequent step), +these give fact (5): `F(ρ, E) ≥ 1 − η − S_off ≥ 1 − 3η/2`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §9.3 (Eq. (9.135); Problem 9.3, fact (5)). +-/ + +open scoped InnerProductSpace ComplexConjugate + +open InnerProductSpace + +@[expose] public section + +/-- **Diagonal of a self-adjoint idempotent operator (an orthogonal projector).** For a +self-adjoint idempotent continuous linear operator `P` — a star projection — and any vector `x`, the +diagonal inner product `⟪x, P x⟫` is the squared norm of the projection, a nonnegative real: +`⟪x, P x⟫ = ‖P x‖²`. Indeed `⟪x, P x⟫ = ⟪x, P (P x)⟫ = ⟪P x, P x⟫ = ‖P x‖²`, using idempotence +(`P ∘ P = P`) and self-adjointness (`P† = P`). + +A general Hilbert-space fact reused by the projection–reset compression channel's fidelity bound +(Nielsen & Chuang Exercise 12.8) and the Grover marked-projection lower bound. -/ +theorem inner_self_of_isSelfAdjoint_of_isIdempotent {𝕜 : Type*} {E : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] {P : E →L[𝕜] E} + (hsa : IsSelfAdjoint P) (hidem : IsIdempotentElem P) (x : E) : + inner 𝕜 x (P x) = ((‖P x‖ ^ 2 : ℝ) : 𝕜) := by + have hPP : P (P x) = P x := by + have := DFunLike.congr_fun hidem x + simpa [mul_apply_eq_comp] using this + have h := ContinuousLinearMap.adjoint_inner_right P x (P x) + rw [hsa.adjoint_eq, hPP] at h + rw [h, inner_self_eq_norm_sq_to_K] + norm_cast + +/-- **Weighted off-diagonal sum bound.** Let `p` be a probability vector on a finite type +(`0 ≤ p`, `∑ p = 1`) and `M ≥ 0` a nonnegative "coherence" array whose every column has bounded +off-diagonal total, `∑_{a ≠ b} M a b ≤ η`. Then the doubly `p`-weighted off-diagonal sum obeys +`∑_{a ≠ b} p a * p b * M a b ≤ η / 2`. + +This is the combinatorial heart of the tight `3η/2` constant in Nielsen & Chuang's *Problem 9.3* +(fact (5)): taking `M a b = ∑ᵢ ‖⟨a, Eᵢ b⟩‖²` over an eigenbasis of `ρ = ∑ₐ pₐ |a⟩⟨a|`, each column +budget is the pure-state variance deficit `∑ᵢ Var_{|b⟩}(Eᵢ) ≤ η` at the eigenvector `|b⟩`, and the +weighted off-diagonal sum is exactly the off-diagonal "coherence" term of the entanglement +infidelity. The constant `η / 2` — not `η`, and decisive for reaching `1 − 3η/2` rather than the +weaker `1 − 2η` — is the extremal value of `2 m (1 - m)` at `m = maxₐ pₐ`, attained by the balanced +two-point distribution: bounding each column by its largest weight and treating the maximizing +index separately gives `∑_b p_b · maxₐ_{≠b} pₐ ≤ 2 m (1 - m) ≤ 1/2`. -/ +theorem weighted_offDiag_sum_le_half {ι : Type*} [Fintype ι] [DecidableEq ι] + {p : ι → ℝ} (hp : ∀ i, 0 ≤ p i) (hp1 : ∑ i, p i = 1) + {M : ι → ι → ℝ} (hM : ∀ a b, 0 ≤ M a b) {η : ℝ} + (hcol : ∀ b, ∑ a ∈ Finset.univ.erase b, M a b ≤ η) : + ∑ b, ∑ a ∈ Finset.univ.erase b, p a * p b * M a b ≤ η / 2 := by + classical + have hNE : Nonempty ι := by + by_contra h + rw [not_nonempty_iff] at h + simp only [Finset.univ_eq_empty, Finset.sum_empty] at hp1 + exact absurd hp1 (by norm_num) + obtain ⟨as, hmax⟩ := Finite.exists_max p + set m := p as with hm_def + have hm0 : 0 ≤ m := hp as + have hm1 : m ≤ 1 := by + calc m = p as := hm_def + _ ≤ ∑ i, p i := Finset.single_le_sum (fun i _ => hp i) (Finset.mem_univ as) + _ = 1 := hp1 + have hη0 : 0 ≤ η := le_trans (Finset.sum_nonneg (fun a _ => hM a as)) (hcol as) + have hp_erase : ∀ a ∈ Finset.univ.erase as, p a ≤ 1 - m := by + intro a ha + calc p a ≤ ∑ i ∈ Finset.univ.erase as, p i := Finset.single_le_sum (fun i _ => hp i) ha + _ = 1 - m := by rw [Finset.sum_erase_eq_sub (Finset.mem_univ as), hp1, hm_def] + have hrw : ∀ b, ∑ a ∈ Finset.univ.erase b, p a * p b * M a b + = p b * ∑ a ∈ Finset.univ.erase b, p a * M a b := by + intro b; rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun a _ => by ring) + -- Each column's `p`-weighted sum is bounded by any uniform bound `c` on its weights, times `η`: + -- pointwise `p a ≤ c`, then `mul_sum`, then the column budget `hcol`. The asymmetric bounds + -- `c = 1 - m` (at `as`) and `c = m` (elsewhere) are what deliver `2 m (1 - m) ≤ 1/2` below. + have key : ∀ (b : ι) (c : ℝ), 0 ≤ c → (∀ a ∈ Finset.univ.erase b, p a ≤ c) → + ∑ a ∈ Finset.univ.erase b, p a * M a b ≤ c * η := by + intro b c hc0 hc + calc ∑ a ∈ Finset.univ.erase b, p a * M a b + ≤ ∑ a ∈ Finset.univ.erase b, c * M a b := + Finset.sum_le_sum (fun a ha => mul_le_mul_of_nonneg_right (hc a ha) (hM a b)) + _ = c * ∑ a ∈ Finset.univ.erase b, M a b := by rw [Finset.mul_sum] + _ ≤ c * η := mul_le_mul_of_nonneg_left (hcol b) hc0 + have h_inner_as := key as (1 - m) (by linarith) hp_erase + have h_inner_gen : ∀ b, (∑ a ∈ Finset.univ.erase b, p a * M a b) ≤ m * η := + fun b => key b m hm0 (fun a _ => hmax a) + have hsum_erase : ∑ b ∈ Finset.univ.erase as, p b = 1 - m := by + rw [Finset.sum_erase_eq_sub (Finset.mem_univ as), hp1, hm_def] + have hS : ∑ b, ∑ a ∈ Finset.univ.erase b, p a * p b * M a b + = p as * (∑ a ∈ Finset.univ.erase as, p a * M a as) + + ∑ b ∈ Finset.univ.erase as, p b * (∑ a ∈ Finset.univ.erase b, p a * M a b) := by + simp_rw [hrw] + exact (Finset.add_sum_erase Finset.univ + (fun b => p b * ∑ a ∈ Finset.univ.erase b, p a * M a b) (Finset.mem_univ as)).symm + rw [hS] + have hb1 : p as * (∑ a ∈ Finset.univ.erase as, p a * M a as) ≤ m * ((1 - m) * η) := by + rw [hm_def]; exact mul_le_mul_of_nonneg_left h_inner_as (hp as) + have hb2 : ∑ b ∈ Finset.univ.erase as, p b * (∑ a ∈ Finset.univ.erase b, p a * M a b) + ≤ (1 - m) * (m * η) := by + calc ∑ b ∈ Finset.univ.erase as, p b * (∑ a ∈ Finset.univ.erase b, p a * M a b) + ≤ ∑ b ∈ Finset.univ.erase as, p b * (m * η) := + Finset.sum_le_sum (fun b _ => mul_le_mul_of_nonneg_left (h_inner_gen b) (hp b)) + _ = (1 - m) * (m * η) := by rw [← Finset.sum_mul, hsum_erase] + nlinarith [hb1, hb2, mul_nonneg hη0 (sq_nonneg (2 * m - 1))] + +namespace ContinuousLinearMap + +variable {H : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + {ι : Type*} [Fintype ι] + +/-- The **operator variance** `Var_ρ(E) = tr(ρ E† E) − |tr(ρ E)|²` of an operator `E` in a state +`ρ` — the second moment of `E` minus its squared mean, both taken in the (generally mixed) state +`ρ`. For a density operator `ρ` this is `≥ 0` by the Cauchy–Schwarz inequality for the +`ρ`-weighted form `⟨X, Y⟩_ρ = tr(ρ X† Y)`. The entanglement infidelity `1 − F(ρ, E)` is the total +operator variance of the Kraus family (`one_sub_entanglementFidelity_eq_sum_opVariance`). -/ +noncomputable def opVariance (ρ E : H →L[ℂ] H) : ℝ := + RCLike.re (LinearMap.trace ℂ H ((ρ * (adjoint E * E) : H →L[ℂ] H) : H →ₗ[ℂ] H)) + - ‖LinearMap.trace ℂ H ((ρ * E : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 + +omit [FiniteDimensional ℂ H] in +/-- **The entanglement infidelity is the total operator variance of the Kraus family.** For a +trace-preserving family of operation elements (`Σᵢ Eᵢ† Eᵢ = 1`) and any unit-trace operator `ρ`, +`1 − F(ρ, E) = Σᵢ Var_ρ(Eᵢ)` (Nielsen & Chuang, Eq. (9.135); the reduction underlying Problem 9.3). + +The proof uses only linearity of the trace and the completeness relation: `Σᵢ tr(ρ Eᵢ† Eᵢ) += tr(ρ · Σᵢ Eᵢ† Eᵢ) = tr ρ = 1`, so `Σᵢ re tr(ρ Eᵢ† Eᵢ) = 1`, and `F(ρ, E) = Σᵢ |tr(ρ Eᵢ)|²` +by definition. No positivity of `ρ` is needed. -/ +theorem one_sub_entanglementFidelity_eq_sum_opVariance + (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) + (hE : ∑ i, adjoint (E i) * E i = 1) + (htr : LinearMap.trace ℂ H (ρ : H →ₗ[ℂ] H) = 1) : + 1 - entanglementFidelity ρ E = ∑ i, opVariance ρ (E i) := by + -- `Σᵢ tr(ρ Eᵢ† Eᵢ) = tr(ρ · Σᵢ Eᵢ† Eᵢ) = tr(ρ · 1) = tr ρ = 1`. + have hq : ∑ i, LinearMap.trace ℂ H + ((ρ * (adjoint (E i) * E i) : H →L[ℂ] H) : H →ₗ[ℂ] H) = 1 := by + rw [← htr, ← map_sum, ← ContinuousLinearMap.toLinearMap_sum, ← Finset.mul_sum, hE, mul_one] + -- take real parts: `Σᵢ re tr(ρ Eᵢ† Eᵢ) = re 1 = 1`. + have hre : ∑ i, RCLike.re (LinearMap.trace ℂ H + ((ρ * (adjoint (E i) * E i) : H →L[ℂ] H) : H →ₗ[ℂ] H)) = 1 := by + have h := congrArg RCLike.re hq + rwa [map_sum, RCLike.one_re] at h + simp only [entanglementFidelity, opVariance] + rw [Finset.sum_sub_distrib, hre] + +omit [FiniteDimensional ℂ H] in +/-- **The physical reading of the pure-state fidelity.** For a pure input `|ψ⟩⟨ψ|` and any family of +operation elements `E`, the "diagonal matrix element" of the output equals the sum of squared +overlaps of the operation elements: +`⟨ψ| E(|ψ⟩⟨ψ|) |ψ⟩ = Σᵢ |⟨ψ, Eᵢ ψ⟩|²`, here recorded as the complex equation +`⟨ψ, (krausSumₗ E |ψ⟩⟨ψ|) ψ⟩ = ↑(Σᵢ ‖⟨ψ, Eᵢ ψ⟩‖²)` (Nielsen & Chuang, Eq. (9.135) for the pure +input `|ψ⟩⟨ψ|`, whose only purification is itself; the value is real, as the coercion makes clear). +Each summand `⟨ψ, Eᵢ (|ψ⟩⟨ψ| Eᵢ† ψ)⟩ = ⟨E_i ψ, ψ⟩ ⟨ψ, Eᵢ ψ⟩ = |⟨ψ, Eᵢ ψ⟩|²`. -/ +theorem inner_krausSumₗ_rankOne_self (ψ : H) (E : ι → H →L[ℂ] H) : + inner ℂ ψ ((krausSumₗ E (rankOne ℂ ψ ψ)) ψ) = ((∑ i, ‖inner ℂ ψ (E i ψ)‖ ^ 2 : ℝ) : ℂ) := by + rw [krausSumₗ_apply] + simp only [_root_.sum_apply, ContinuousLinearMap.comp_apply, inner_sum, + rankOne_apply, ContinuousLinearMap.map_smul, inner_smul_right, adjoint_inner_right] + push_cast + refine Finset.sum_congr rfl fun i _ => ?_ + -- summand: `⟪E i ψ, ψ⟫ * ⟪ψ, E i ψ⟫ = (↑‖⟪ψ, E i ψ⟫‖)²` + rw [← inner_conj_symm (E i ψ) ψ, ← Complex.normSq_eq_conj_mul_self, Complex.normSq_eq_norm_sq] + push_cast + ring + +omit [FiniteDimensional ℂ H] in +/-- The **pure-state fidelity is real and equals the sum of squared overlaps** — the `re` form of +`inner_krausSumₗ_rankOne_self`: `re ⟨ψ| E(|ψ⟩⟨ψ|) |ψ⟩ = Σᵢ |⟨ψ, Eᵢ ψ⟩|²`. -/ +theorem re_inner_krausSumₗ_rankOne_self (ψ : H) (E : ι → H →L[ℂ] H) : + RCLike.re (inner ℂ ψ ((krausSumₗ E (rankOne ℂ ψ ψ)) ψ)) = ∑ i, ‖inner ℂ ψ (E i ψ)‖ ^ 2 := by + rw [inner_krausSumₗ_rankOne_self] + exact Complex.ofReal_re _ + +omit [FiniteDimensional ℂ H] [CompleteSpace H] in +/-- **The Cauchy–Schwarz bound for a single operation element on a unit vector:** +`|⟨ψ, Eᵢ ψ⟩|² ≤ ‖Eᵢ ψ‖²` when `‖ψ‖ = 1`. Each pure-state operator-variance summand is `≥ 0`. -/ +theorem normSq_inner_le_normSq_apply {ψ : H} (hψ : ‖ψ‖ = 1) (E : H →L[ℂ] H) : + ‖inner ℂ ψ (E ψ)‖ ^ 2 ≤ ‖E ψ‖ ^ 2 := by + have h := norm_inner_le_norm (𝕜 := ℂ) ψ (E ψ) + rw [hψ, one_mul] at h + exact pow_le_pow_left₀ (norm_nonneg _) h 2 + +omit [FiniteDimensional ℂ H] in +/-- **The pure-state form of the variance decomposition.** For a unit vector `ψ` and a +trace-preserving family of operation elements (`Σᵢ Eᵢ† Eᵢ = 1`), +`1 − Σᵢ |⟨ψ, Eᵢ ψ⟩|² = Σᵢ (‖Eᵢ ψ‖² − |⟨ψ, Eᵢ ψ⟩|²)`, each summand `≥ 0` +(`normSq_inner_le_normSq_apply`). Combined with `re_inner_krausSumₗ_rankOne_self` this is +`1 − ⟨ψ|E(|ψ⟩⟨ψ|)|ψ⟩ = Σᵢ Var_{|ψ⟩⟨ψ|}(Eᵢ)`. The `1` comes from completeness: +`Σᵢ ‖Eᵢ ψ‖² = ⟨ψ, (Σᵢ Eᵢ† Eᵢ) ψ⟩ = ‖ψ‖² = 1`. -/ +theorem one_sub_sum_normSq_inner_eq_sum {ψ : H} (hψ : ‖ψ‖ = 1) (E : ι → H →L[ℂ] H) + (hE : ∑ i, adjoint (E i) * E i = 1) : + 1 - ∑ i, ‖inner ℂ ψ (E i ψ)‖ ^ 2 = ∑ i, (‖E i ψ‖ ^ 2 - ‖inner ℂ ψ (E i ψ)‖ ^ 2) := by + have hsum : ∑ i, ‖E i ψ‖ ^ 2 = 1 := by + rw [sum_normSq_apply_of_sum_adjoint_mul_self_eq_one E hE, hψ, one_pow] + rw [Finset.sum_sub_distrib, hsum] + +omit [FiniteDimensional ℂ H] in +/-- **The pure-state fidelity of a unit vector is at most `1`:** for a unit vector `ψ` and a +trace-preserving family of operation elements (`Σᵢ Eᵢ† Eᵢ = 1`), +`Σᵢ |⟨ψ, Eᵢ ψ⟩|² ≤ 1`. Each summand is bounded by `‖Eᵢ ψ‖²` (`normSq_inner_le_normSq_apply`) and +completeness collapses `Σᵢ ‖Eᵢ ψ‖² = ‖ψ‖² = 1`. In particular the deficit `η` in a fidelity bound +`1 − η ≤ Σᵢ |⟨ψ, Eᵢ ψ⟩|²` is nonnegative. -/ +theorem sum_normSq_inner_self_le_one {ψ : H} (hψ : ‖ψ‖ = 1) (E : ι → H →L[ℂ] H) + (hE : ∑ i, adjoint (E i) * E i = 1) : + ∑ i, ‖inner ℂ ψ (E i ψ)‖ ^ 2 ≤ 1 := by + calc ∑ i, ‖inner ℂ ψ (E i ψ)‖ ^ 2 + ≤ ∑ i, ‖E i ψ‖ ^ 2 := Finset.sum_le_sum fun i _ => normSq_inner_le_normSq_apply hψ (E i) + _ = 1 := by rw [sum_normSq_apply_of_sum_adjoint_mul_self_eq_one E hE, hψ, one_pow] + +end ContinuousLinearMap + +namespace ContinuousLinearMap + +section Eigenbasis + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [FiniteDimensional ℂ H] [CompleteSpace H] + {ι : Type*} [Fintype ι] [DecidableEq ι] {κ : Type*} [Fintype κ] + +omit [CompleteSpace H] [DecidableEq ι] in +/-- **The entanglement fidelity in a spectral eigenbasis.** For a state written in an eigenbasis +`ρ = Σₐ pₐ |eₐ⟩⟨eₐ|` (`e : ι → H`, real weights `p`), the entanglement fidelity is computed from the +*diagonal* matrix elements of the operation elements, +`F(ρ, E) = Σⱼ |Σₐ pₐ ⟨eₐ, Eⱼ eₐ⟩|²` (Nielsen & Chuang, Eq. (9.135), via +`tr(ρ Eⱼ) = Σₐ pₐ ⟨eₐ, Eⱼ eₐ⟩`). + +Each `tr(ρ Eⱼ) = Σₐ pₐ tr(|eₐ⟩⟨eₐ| Eⱼ) = Σₐ pₐ ⟨eₐ, Eⱼ eₐ⟩` by linearity of the trace and +`InnerProductSpace.trace_rankOne_self_comp`; neither orthonormality of `e` nor normalisation of `p` +is used. This is the diagonal ingredient of Nielsen & Chuang's *Problem 9.3* (fact (5)). -/ +theorem entanglementFidelity_sum_rankOne (e : ι → H) (p : ι → ℝ) (E : κ → H →L[ℂ] H) : + entanglementFidelity (∑ a, (p a : ℂ) • rankOne ℂ (e a) (e a)) E + = ∑ j, ‖∑ a, (p a : ℂ) * inner ℂ (e a) (E j (e a))‖ ^ 2 := by + simp only [entanglementFidelity] + refine Finset.sum_congr rfl fun j _ => ?_ + have h : (LinearMap.trace ℂ H) ↑((∑ a, (p a : ℂ) • rankOne ℂ (e a) (e a)) * E j) + = ∑ a, (p a : ℂ) * inner ℂ (e a) (E j (e a)) := by + rw [Finset.sum_mul, ContinuousLinearMap.toLinearMap_sum, map_sum] + refine Finset.sum_congr rfl fun a _ => ?_ + rw [smul_mul_assoc, ContinuousLinearMap.toLinearMap_smul, map_smul, + ContinuousLinearMap.mul_def, + InnerProductSpace.trace_rankOne_self_comp, smul_eq_mul] + rw [h] + +omit [DecidableEq ι] in +/-- **The entanglement fidelity of a pure-state mixture is at most `1`** (unit-vector form). For any +probability mixture of pure states `ρ = Σₐ pₐ |eₐ⟩⟨eₐ|` — a family `e : ι → H` of **unit vectors** +(`‖eₐ‖ = 1`, *not* required orthonormal) weighted by a probability vector `p` (`0 ≤ p`, `Σ p = 1`) — +and any trace-preserving family of operation elements (`Σⱼ Eⱼ† Eⱼ = 1`), the entanglement fidelity +satisfies `F(ρ, E) ≤ 1`. + +By `entanglementFidelity_sum_rankOne` the fidelity reads off the diagonal matrix elements, +`F(ρ, E) = Σⱼ |Σₐ pₐ ⟨eₐ, Eⱼ eₐ⟩|²`. The probability-weighted Jensen bound +`‖Σₐ pₐ wₐ‖² ≤ Σₐ pₐ ‖wₐ‖²` (triangle inequality followed by the Cauchy–Schwarz sum inequality, +using `Σ pₐ = 1`) moves the weights inside each squared modulus, and swapping the order of summation +leaves `Σₐ pₐ (Σⱼ |⟨eₐ, Eⱼ eₐ⟩|²) ≤ Σₐ pₐ · 1 = 1`, the inner bound being the pure-state fidelity +bound `sum_normSq_inner_self_le_one` at the unit vector `eₐ` (only `‖eₐ‖ = 1` is used, not +orthogonality). This is the upper half of the `0 ≤ F(ρ, E) ≤ 1` range of the entanglement fidelity +(Nielsen & Chuang, §9.3). -/ +theorem entanglementFidelity_le_one_of_sum_rankOne (e : ι → H) (he : ∀ a, ‖e a‖ = 1) (p : ι → ℝ) + (hp0 : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) (E : κ → H →L[ℂ] H) + (hE : ∑ j, adjoint (E j) * E j = 1) : + entanglementFidelity (∑ a, (p a : ℂ) • rankOne ℂ (e a) (e a)) E ≤ 1 := by + -- Probability-weighted Jensen: `‖Σₐ pₐ wₐ‖² ≤ Σₐ pₐ ‖wₐ‖²`. + have jensen : ∀ w : ι → ℂ, ‖∑ a, (p a : ℂ) * w a‖ ^ 2 ≤ ∑ a, p a * ‖w a‖ ^ 2 := by + intro w + have h1 : ‖∑ a, (p a : ℂ) * w a‖ ≤ ∑ a, p a * ‖w a‖ := + (norm_sum_le _ _).trans <| le_of_eq <| Finset.sum_congr rfl fun a _ => by + rw [norm_mul, Complex.norm_real, Real.norm_of_nonneg (hp0 a)] + have hCS := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun a => Real.sqrt (p a)) (fun a => Real.sqrt (p a) * ‖w a‖) + have e1 : (∑ a, Real.sqrt (p a) * (Real.sqrt (p a) * ‖w a‖)) = ∑ a, p a * ‖w a‖ := + Finset.sum_congr rfl fun a _ => by rw [← mul_assoc, Real.mul_self_sqrt (hp0 a)] + have e2 : (∑ a, Real.sqrt (p a) ^ 2) = 1 := by + rw [Finset.sum_congr rfl fun a _ => Real.sq_sqrt (hp0 a), hp1] + have e3 : (∑ a, (Real.sqrt (p a) * ‖w a‖) ^ 2) = ∑ a, p a * ‖w a‖ ^ 2 := + Finset.sum_congr rfl fun a _ => by rw [mul_pow, Real.sq_sqrt (hp0 a)] + rw [e1, e2, e3, one_mul] at hCS + exact (pow_le_pow_left₀ (norm_nonneg _) h1 2).trans hCS + rw [entanglementFidelity_sum_rankOne] + calc ∑ j, ‖∑ a, (p a : ℂ) * inner ℂ (e a) (E j (e a))‖ ^ 2 + ≤ ∑ j, ∑ a, p a * ‖inner ℂ (e a) (E j (e a))‖ ^ 2 := + Finset.sum_le_sum fun j _ => jensen _ + _ = ∑ a, p a * ∑ j, ‖inner ℂ (e a) (E j (e a))‖ ^ 2 := by + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun a _ => (Finset.mul_sum _ _ _).symm + _ ≤ ∑ a, p a * 1 := + Finset.sum_le_sum fun a _ => + mul_le_mul_of_nonneg_left (sum_normSq_inner_self_le_one (he a) E hE) (hp0 a) + _ = 1 := by simp only [mul_one]; exact hp1 + +/-- **The entanglement fidelity of a density operator is at most `1`** (Nielsen & Chuang, §9.3): for +any density operator `ρ` (`ρ.IsDensityOp`, i.e. positive with `tr ρ = 1`) and any trace-preserving +family of operation elements (`Σⱼ Eⱼ† Eⱼ = 1`), `F(ρ, E) ≤ 1`. + +Together with `entanglementFidelity_nonneg` this places the entanglement fidelity in `[0, 1]`. The +proof is the spectral theorem plus the pure-state-mixture bound +`entanglementFidelity_le_one_of_sum_rankOne`: +writing `ρ = Σᵢ λᵢ |eᵢ⟩⟨eᵢ|` in its orthonormal eigenbasis (`IsSelfAdjoint.spectral_sum`), the +eigenvectors are unit vectors and the eigenvalues `λᵢ` are a probability vector +(`IsDensityOp.eigenvalues_nonneg` / `IsDensityOp.eigenvalues_sum_eq_one`), so that bound applies. -/ +theorem entanglementFidelity_le_one {ρ : H →L[ℂ] H} (hρ : ρ.IsDensityOp) (E : κ → H →L[ℂ] H) + (hE : ∑ j, adjoint (E j) * E j = 1) : entanglementFidelity ρ E ≤ 1 := by + have hsa : IsSelfAdjoint ρ := hρ.isPositive.isSelfAdjoint + rw [hsa.spectral_sum (rfl : Module.finrank ℂ H = Module.finrank ℂ H)] + exact entanglementFidelity_le_one_of_sum_rankOne _ + (fun a => (hsa.isSymmetric.eigenvectorBasis rfl).orthonormal.1 a) _ + (fun a => hρ.eigenvalues_nonneg rfl a) (hρ.eigenvalues_sum_eq_one rfl) E hE + +/-- **The off-diagonal coherence sum** `S_off = Σ_{a≠b} pₐ p_b Σⱼ |⟨eₐ, Eⱼ e_b⟩|²` of a family of +operation elements `E` in the eigenbasis `{eₐ}` weighted by `p`. This is the off-diagonal +("coherence") part of the entanglement infidelity `1 − F(ρ, E)` for `ρ = Σₐ pₐ |eₐ⟩⟨eₐ|` — the term +the phase-diagonal twirl isolates in Nielsen & Chuang's *Problem 9.3* (fact (5)). It is bounded by +`η / 2` (`offDiagCoherenceSum_le`), the estimate separating the tight `F ≥ 1 − 3η/2` from the weaker +`1 − 2η`. The summation order matches `weighted_offDiag_sum_le_half`: outer over the column `b`, +inner over the off-diagonal rows `a ≠ b`. -/ +noncomputable def offDiagCoherenceSum (e : ι → H) (p : ι → ℝ) (E : κ → H →L[ℂ] H) : ℝ := + ∑ y, ∑ x ∈ Finset.univ.erase y, p x * p y * ∑ j, ‖inner ℂ (e x) (E j (e y))‖ ^ 2 + +omit [FiniteDimensional ℂ H] in +/-- **The per-column coherence budget.** In an orthonormal basis `b`, the off-diagonal weight of the +`i₀`-th column, `Σ_{a≠i₀} Σⱼ |⟨bₐ, Eⱼ b_{i₀}⟩|²`, is at most `η` whenever the pure-state fidelity of +the eigenvector `b_{i₀}` is at least `1 − η` (`1 − η ≤ Σⱼ |⟨b_{i₀}, Eⱼ b_{i₀}⟩|²`) and the family is +trace preserving (`Σⱼ Eⱼ† Eⱼ = 1`). + +By Parseval (`OrthonormalBasis.sum_sq_norm_inner_right`) `Σₐ |⟨bₐ, Eⱼ b_{i₀}⟩|² = ‖Eⱼ b_{i₀}‖²`, and +by completeness `Σⱼ ‖Eⱼ b_{i₀}‖² = ‖b_{i₀}‖² = 1`, so the off-diagonal weight equals the pure-state +variance deficit `1 − Σⱼ |⟨b_{i₀}, Eⱼ b_{i₀}⟩|² ≤ η` (cf. `one_sub_sum_normSq_inner_eq_sum`). This +is the column budget consumed by `weighted_offDiag_sum_le_half` in `offDiagCoherenceSum_le`. -/ +theorem sum_offDiag_normSq_inner_le (b : OrthonormalBasis ι ℂ H) (E : κ → H →L[ℂ] H) + (hE : ∑ j, adjoint (E j) * E j = 1) {η : ℝ} (i₀ : ι) + (hfid : 1 - η ≤ ∑ j, ‖inner ℂ (b i₀) (E j (b i₀))‖ ^ 2) : + ∑ a ∈ Finset.univ.erase i₀, ∑ j, ‖inner ℂ (b a) (E j (b i₀))‖ ^ 2 ≤ η := by + rw [Finset.sum_comm] + simp_rw [Finset.sum_erase_eq_sub (Finset.mem_univ i₀), b.sum_sq_norm_inner_right] + rw [Finset.sum_sub_distrib, + ContinuousLinearMap.sum_normSq_apply_of_sum_adjoint_mul_self_eq_one E hE (b i₀), + b.orthonormal.1 i₀, one_pow] + linarith [hfid] + +omit [FiniteDimensional ℂ H] in +/-- **The off-diagonal coherence is at most `η / 2` — support-aware form.** If `ρ = Σₐ pₐ |bₐ⟩⟨bₐ|` +is a density operator in the orthonormal eigenbasis `b` (`p` a probability vector) and every +*positive-weight* eigenvector `bₐ` (`0 < pₐ`, hence `bₐ ∈ supp ρ`) has pure-state fidelity `≥ 1 − η` +under the trace-preserving family `E`, then `offDiagCoherenceSum b p E ≤ η / 2`. + +Unlike `offDiagCoherenceSum_le`, only columns with `pₐ > 0` need a fidelity budget: the doubly +`p`-weighted off-diagonal sum `S_off = Σ_{a≠c} pₐ p_c Σⱼ |⟨bₐ, Eⱼ b_c⟩|²` annihilates every column +with `p_c = 0`. Formally, `S_off` is unchanged if the coherence array is *capped* to `0` on +zero-weight columns, and the capped array meets the per-column budget of +`weighted_offDiag_sum_le_half` — `≤ η` on positive columns (`sum_offDiag_normSq_inner_le`) and `≤ η` +trivially (`= 0 ≤ η`) on the capped ones. This is the shape Nielsen & Chuang's *Problem 9.3* support +hypothesis supplies, since eigenvectors with `pₐ = 0` are outside `supp ρ`. -/ +theorem offDiagCoherenceSum_le_of_pos (b : OrthonormalBasis ι ℂ H) (p : ι → ℝ) + (hp0 : ∀ i, 0 ≤ p i) (hp1 : ∑ i, p i = 1) (E : κ → H →L[ℂ] H) + (hE : ∑ j, adjoint (E j) * E j = 1) {η : ℝ} (hη : 0 ≤ η) + (hfid : ∀ i, 0 < p i → 1 - η ≤ ∑ j, ‖inner ℂ (b i) (E j (b i))‖ ^ 2) : + offDiagCoherenceSum (⇑b) p E ≤ η / 2 := by + classical + -- Cap the coherence array to `0` on zero-weight columns; `S_off` is unchanged. + have heq : offDiagCoherenceSum (⇑b) p E + = ∑ c, ∑ a ∈ Finset.univ.erase c, p a * p c * + (if 0 < p c then ∑ j, ‖inner ℂ (b a) (E j (b c))‖ ^ 2 else 0) := by + rw [offDiagCoherenceSum] + refine Finset.sum_congr rfl fun c _ => Finset.sum_congr rfl fun a _ => ?_ + by_cases hpc : 0 < p c + · rw [ite_eq_left hpc] + · rw [ite_eq_right hpc, le_antisymm (not_lt.mp hpc) (hp0 c)]; ring + rw [heq] + refine weighted_offDiag_sum_le_half hp0 hp1 (fun a c => ?_) (fun c => ?_) + · by_cases hpc : 0 < p c + · simp only [ite_eq_left hpc]; positivity + · simp only [ite_eq_right hpc, le_refl] + · by_cases hpc : 0 < p c + · simp only [ite_eq_left hpc] + exact sum_offDiag_normSq_inner_le b E hE c (hfid c hpc) + · simp only [ite_eq_right hpc, Finset.sum_const_zero]; exact hη + +omit [FiniteDimensional ℂ H] in +/-- **The off-diagonal coherence is at most `η / 2`.** If `ρ = Σₐ pₐ |bₐ⟩⟨bₐ|` is a density operator +in the orthonormal eigenbasis `b` (`p` a probability vector: `0 ≤ p`, `Σ p = 1`) whose every +eigenvector has pure-state fidelity `≥ 1 − η` under the trace-preserving family `E`, then +`offDiagCoherenceSum b p E ≤ η / 2`. + +The all-columns corollary of `offDiagCoherenceSum_le_of_pos` (which needs a budget only on the +positive-weight columns): every column meets the hypothesis, and `η ≥ 0` follows because a +pure-state fidelity is `≤ 1` (`sum_normSq_inner_self_le_one`, at any eigenvector — `ι` is nonempty +as `∑ p = 1`). The `η / 2` — rather than `η` — is the estimate that yields Nielsen & Chuang's tight +`F(ρ, E) ≥ 1 − 3η/2` for *Problem 9.3* (fact (5)). -/ +theorem offDiagCoherenceSum_le (b : OrthonormalBasis ι ℂ H) (p : ι → ℝ) + (hp0 : ∀ i, 0 ≤ p i) (hp1 : ∑ i, p i = 1) (E : κ → H →L[ℂ] H) + (hE : ∑ j, adjoint (E j) * E j = 1) {η : ℝ} + (hfid : ∀ i, 1 - η ≤ ∑ j, ‖inner ℂ (b i) (E j (b i))‖ ^ 2) : + offDiagCoherenceSum (⇑b) p E ≤ η / 2 := by + obtain ⟨i₀⟩ : Nonempty ι := by + by_contra h + rw [not_nonempty_iff] at h + rw [Finset.univ_eq_empty, Finset.sum_empty] at hp1 + exact absurd hp1 (by norm_num) + refine offDiagCoherenceSum_le_of_pos b p hp0 hp1 E hE ?_ (fun i _ => hfid i) + linarith [hfid i₀, sum_normSq_inner_self_le_one (b.orthonormal.1 i₀) E hE] + +end Eigenbasis + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntropyExchange.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntropyExchange.lean new file mode 100644 index 0000000000..1fd065eea0 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EntropyExchange.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyGram +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorGram +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Uhlmann +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order + +/-! # Entropy exchange `S(ρ, E)` and the reference-system output state + +For a state `ρ` (a density operator on a `d`-dimensional complex inner product space `H`) and a +finite family of operation elements `E : ι → (H →L[ℂ] H)` of a trace-preserving quantum operation, +Nielsen & Chuang define the **entropy exchange** (Nielsen & Chuang, *Quantum Computation and +Quantum Information*, §12.4.1, eqs. (12.107)–(12.110)) by +`S(ρ, E) := S(R', Q') = S(W)`, +where `Wⱼₖ = tr(Eⱼ ρ Eₖ†)` is the **`w`-matrix** — the density operator of the environment in the +Stinespring dilation, in the operation-element basis (eq. (12.109)) — and `S(W) = -tr(W log W)` is +its von Neumann entropy (eq. (12.110)). + +This file supplies the `w`-matrix, the entropy-exchange quantity `S(ρ, E) = S(W)`, and the +identification of `S(W)` with the entropy of the reference-plus-system output state +`ρ_{R'Q'} = Σᵢ |E_i √ρ⟩⟨E_i √ρ|` — realized here in the Hilbert–Schmidt space `H ⊗ H` (of dimension +`d²`) as the frame operator of the vectorized family `√ρ Eᵢ†`. This is the operator content of the +quantum Fano inequality (N&C Theorem 12.9): its proof (`QuantumFanoInequality`) applies the +density-operator Fano bound +`S(ρ_{R'Q'}) ≤ H(⟨√ρ, ρ_{R'Q'} √ρ⟩) + (1 - ⟨√ρ, ρ_{R'Q'} √ρ⟩) · log(d² - 1)` to `ρ_{R'Q'}` with +the (unit) Hilbert–Schmidt vector `√ρ`. + +## Main definitions + +* `ContinuousLinearMap.wMatrix` — the `w`-matrix `Wⱼₖ = tr(Eⱼ ρ Eₖ†)` (N&C eq. (12.109)–(12.110)). +* `ContinuousLinearMap.entropyExchange` — the entropy exchange `S(ρ, E) = S(W)` (N&C eq. (12.110)). +* `ContinuousLinearMap.entropyExchangeState` — the reference-plus-system output density operator + `ρ_{R'Q'} = Σᵢ |vec(√ρ Eᵢ†)⟩⟨vec(√ρ Eᵢ†)|` on `H ⊗ H`. + +## Main results + +* `ContinuousLinearMap.entropyExchange_eq_vonNeumannEntropy_entropyExchangeState` — the entropy + exchange is the von Neumann entropy of `ρ_{R'Q'}`, `S(ρ, E) = S(ρ_{R'Q'})`, because `W` is the + Gram matrix of the family `√ρ Eᵢ†` (the Gram / sum-of-rank-ones entropy equality + `vonNeumannEntropy_sum_rankOne_self_eq_gram`). +* `ContinuousLinearMap.re_inner_entropyExchangeState_sqrt_eq_entanglementFidelity` — the diagonal + entry `⟨√ρ, ρ_{R'Q'} √ρ⟩ = Σᵢ |tr(ρ Eᵢ)|² = F(ρ, E)` is the entanglement fidelity. +* `ContinuousLinearMap.entropyExchangeState_isDensityOp` — `ρ_{R'Q'}` is a density operator (trace + `1`, from the completeness relation `Σᵢ Eᵢ† Eᵢ = 1`). +* `ContinuousLinearMap.norm_matricize_symm_cfc_sqrt` — `√ρ` is a unit Hilbert–Schmidt vector. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.4.1 (eqs. (12.107)–(12.110), Theorem 12.9); §9.3 (Eq. (9.135)). +-/ + +open scoped InnerProductSpace TensorProduct ComplexConjugate +open InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + {ιb ι : Type*} [Fintype ιb] + +/-- The **`w`-matrix** `Wⱼₖ = tr(Eⱼ ρ Eₖ†)` of a state `ρ` and a family of operation elements +`E : ι → (H →L[ℂ] H)` (Nielsen & Chuang, *Quantum Computation and Quantum Information*, eqs. +(12.109)–(12.110)). It is the matrix of the environment's density operator `ρ_{E'}` in the +operation-element basis of the Stinespring dilation; its von Neumann entropy is the entropy +exchange. -/ +noncomputable def wMatrix (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) : Matrix ι ι ℂ := + fun j k => LinearMap.trace ℂ H ((E j * ρ * adjoint (E k) : H →L[ℂ] H) : H →ₗ[ℂ] H) + +/-- The **entropy exchange** `S(ρ, E) = S(W) = -tr(W log W)` of a state `ρ` under a quantum +operation with operation elements `E` (Nielsen & Chuang, eq. (12.110)). Defined as the von Neumann +entropy of the operator on `EuclideanSpace ℂ ι` represented by the `w`-matrix `W = wMatrix ρ E`. -/ +noncomputable def entropyExchange [Fintype ι] [DecidableEq ι] (ρ : H →L[ℂ] H) + (E : ι → H →L[ℂ] H) : ℝ := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι) (wMatrix ρ E)).vonNeumannEntropy + +/-- The **reference-plus-system output density operator** `ρ_{R'Q'}` (Nielsen & Chuang, eq. +(12.107)), realized in the Hilbert–Schmidt space `H ⊗ H` as the frame operator +`Σᵢ |vec(√ρ Eᵢ†)⟩⟨vec(√ρ Eᵢ†)|` of the vectorized family `√ρ Eᵢ†`, where `vec` is the inverse +matricization `(matricize b).symm` for an orthonormal basis `b` of `H`. Its von Neumann entropy is +the entropy exchange `S(ρ, E)` and its diagonal entry against `vec √ρ` is the entanglement +fidelity. -/ +noncomputable def entropyExchangeState [Fintype ι] (b : OrthonormalBasis ιb ℂ H) + (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H) := + ∑ i, InnerProductSpace.rankOne ℂ + ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i))) + ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i))) + +/-- The Hilbert–Schmidt inner product of vectorized operators is the operator trace pairing: +`⟨vec A, vec B⟩ = tr(A† B)`, where `vec = (matricize b).symm`. The matricization bridge +`TensorProduct.matricize_inner_eq_trace_adjoint_comp` restated on inverse matricizations. -/ +theorem inner_matricize_symm (b : OrthonormalBasis ιb ℂ H) (A B : H →L[ℂ] H) : + inner ℂ ((TensorProduct.matricize b).symm A) ((TensorProduct.matricize b).symm B) + = LinearMap.trace ℂ H ((adjoint A * B : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [TensorProduct.matricize_inner_eq_trace_adjoint_comp b, LinearEquiv.apply_symm_apply, + LinearEquiv.apply_symm_apply, ContinuousLinearMap.toLinearMap_mul, Module.End.mul_eq_comp] + +omit [FiniteDimensional ℂ H] in +/-- The adjoint of the vectorization factor `(√ρ Eᵢ†)† = Eᵢ √ρ`, from anti-multiplicativity of the +adjoint and self-adjointness of `√ρ` (`adjoint_cfc_real_sqrt`). -/ +theorem adjoint_sqrt_mul_adjoint (ρ : H →L[ℂ] H) (E : ι → H →L[ℂ] H) (i : ι) : + adjoint (cfc Real.sqrt ρ * adjoint (E i)) = E i * cfc Real.sqrt ρ := by + simp only [← ContinuousLinearMap.star_eq_adjoint, star_mul, star_star] + rw [ContinuousLinearMap.star_eq_adjoint, adjoint_cfc_real_sqrt] + +omit [FiniteDimensional ℂ H] in +/-- The composed operator `(√ρ Eⱼ†)† (√ρ Eₖ†) = Eⱼ ρ Eₖ†`, the algebraic core linking the Gram +matrix of the family `√ρ Eᵢ†` to the `w`-matrix. Uses `(√ρ Eⱼ†)† = Eⱼ √ρ` +(`adjoint_sqrt_mul_adjoint`) and `√ρ √ρ = ρ` (`cfc_real_sqrt_mul_self`). -/ +theorem adjoint_sqrt_mul_sqrt {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) (E : ι → H →L[ℂ] H) (j k : ι) : + adjoint (cfc Real.sqrt ρ * adjoint (E j)) * (cfc Real.sqrt ρ * adjoint (E k)) + = E j * ρ * adjoint (E k) := by + rw [adjoint_sqrt_mul_adjoint, mul_assoc (E j), ← mul_assoc (cfc Real.sqrt ρ), + cfc_real_sqrt_mul_self_of_nonneg hρ, ← mul_assoc] + +/-- The `w`-matrix is the Gram matrix of the vectorized family `√ρ Eᵢ†`: `W = krausGram b (√ρ E†)`. +Entry-wise, `Wⱼₖ = tr(Eⱼ ρ Eₖ†) = tr((√ρ Eⱼ†)† (√ρ Eₖ†))` (`adjoint_sqrt_mul_sqrt`). -/ +theorem wMatrix_eq_krausGram (b : OrthonormalBasis ιb ℂ H) {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) + (E : ι → H →L[ℂ] H) : + wMatrix ρ E = krausGram b (fun i => cfc Real.sqrt ρ * adjoint (E i)) := by + ext j k + rw [wMatrix, krausGram_apply, ← Module.End.mul_eq_comp, ← ContinuousLinearMap.toLinearMap_mul, + adjoint_sqrt_mul_sqrt hρ] + +/-- **The entropy exchange is the von Neumann entropy of the reference-plus-system state**, +`S(ρ, E) = S(ρ_{R'Q'})` (Nielsen & Chuang, eqs. (12.107), (12.110)). The `w`-matrix `W` is the Gram +matrix of the family `√ρ Eᵢ†` (`wMatrix_eq_krausGram`), so `S(W)` — the von Neumann entropy of the +`ι × ι` matrix — equals the entropy of the frame operator `Σᵢ |vec(√ρ Eᵢ†)⟩⟨vec(√ρ Eᵢ†)|` on the +`d²`-dimensional Hilbert–Schmidt space, by the Gram / sum-of-rank-ones entropy equality +`vonNeumannEntropy_sum_rankOne_self_eq_gram`. -/ +theorem entropyExchange_eq_vonNeumannEntropy_entropyExchangeState [Fintype ι] [DecidableEq ι] + (b : OrthonormalBasis ιb ℂ H) {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) (E : ι → H →L[ℂ] H) : + entropyExchange ρ E = (entropyExchangeState b ρ E).vonNeumannEntropy := by + unfold entropyExchange entropyExchangeState + rw [wMatrix_eq_krausGram b hρ, + vonNeumannEntropy_sum_rankOne_self_eq_gram + (fun i => (TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i)))] + rfl + +/-- **The diagonal entry of `ρ_{R'Q'}` against `vec √ρ` is the entanglement fidelity**, +`⟨√ρ, ρ_{R'Q'} √ρ⟩ = Σᵢ |tr(ρ Eᵢ)|² = F(ρ, E)` (Nielsen & Chuang, eqs. (9.135), (12.113)). Each +overlap `⟨vec(√ρ Eᵢ†), vec √ρ⟩ = tr(Eᵢ ρ) = tr(ρ Eᵢ)` by the Hilbert–Schmidt bridge, so the sum of +squared overlaps is the entanglement fidelity. -/ +theorem re_inner_entropyExchangeState_sqrt_eq_entanglementFidelity [Fintype ι] + (b : OrthonormalBasis ιb ℂ H) {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) (E : ι → H →L[ℂ] H) : + RCLike.re (inner ℂ ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ)) + (entropyExchangeState b ρ E ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ)))) + = entanglementFidelity ρ E := by + set Ω := (TensorProduct.matricize b).symm (cfc Real.sqrt ρ) with hΩ + have key : inner ℂ Ω (entropyExchangeState b ρ E Ω) = (entanglementFidelity ρ E : ℂ) := by + simp only [entropyExchangeState, _root_.sum_apply, inner_sum] + rw [entanglementFidelity, Complex.ofReal_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + set φ := (TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i)) with hφ + have hv : inner ℂ φ Ω = LinearMap.trace ℂ H ((ρ * E i : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [hφ, hΩ, inner_matricize_symm, adjoint_sqrt_mul_adjoint, mul_assoc, + cfc_real_sqrt_mul_self_of_nonneg hρ, ContinuousLinearMap.toLinearMap_mul, + ContinuousLinearMap.toLinearMap_mul, LinearMap.trace_mul_comm] + rw [InnerProductSpace.rankOne_apply, inner_smul_right, ← inner_conj_symm Ω φ, hv, + Complex.mul_conj, Complex.normSq_eq_norm_sq] + rw [key] + simp + +/-- The Hilbert–Schmidt vector `√ρ` (i.e. `vec √ρ`) is a unit vector: `‖vec √ρ‖ = 1`, since +`‖vec √ρ‖² = tr(√ρ √ρ) = tr ρ = 1` for a density operator `ρ`. -/ +theorem norm_matricize_symm_cfc_sqrt (b : OrthonormalBasis ιb ℂ H) {ρ : H →L[ℂ] H} + (hρ : ρ.IsDensityOp) : ‖(TensorProduct.matricize b).symm (cfc Real.sqrt ρ)‖ = 1 := by + set Ω := (TensorProduct.matricize b).symm (cfc Real.sqrt ρ) with hΩ + have h : inner ℂ Ω Ω = (1 : ℂ) := by + rw [hΩ, inner_matricize_symm, adjoint_cfc_real_sqrt, cfc_real_sqrt_mul_self_of_nonneg hρ.nonneg] + exact hρ.trace_eq_one + have h2 : ‖Ω‖ ^ 2 = 1 := by rw [← inner_self_eq_norm_sq (𝕜 := ℂ), h, RCLike.one_re] + rw [← Real.sqrt_one, ← h2, Real.sqrt_sq (norm_nonneg _)] + +/-- **The reference-plus-system state `ρ_{R'Q'}` is a density operator** (Nielsen & Chuang, eq. +(12.107)). It is a sum of rank-one self-projections, hence positive; its trace is +`Σᵢ tr(Eᵢ ρ Eᵢ†) = tr((Σᵢ Eᵢ† Eᵢ) ρ) = tr ρ = 1` by the completeness relation `Σᵢ Eᵢ† Eᵢ = 1` of a +trace-preserving operation. -/ +theorem entropyExchangeState_isDensityOp [Fintype ι] (b : OrthonormalBasis ιb ℂ H) + {ρ : H →L[ℂ] H} (hρ : ρ.IsDensityOp) {E : ι → H →L[ℂ] H} + (htp : ∑ i, adjoint (E i) * E i = 1) : (entropyExchangeState b ρ E).IsDensityOp := by + refine ⟨?_, ?_⟩ + · rw [entropyExchangeState] + exact ContinuousLinearMap.isPositive_sum _ fun i _ => + InnerProductSpace.isPositive_rankOne_self _ + · rw [entropyExchangeState, ContinuousLinearMap.toLinearMap_sum, map_sum] + have hterm : ∀ i, LinearMap.trace ℂ (H ⊗[ℂ] H) + ((InnerProductSpace.rankOne ℂ + ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i))) + ((TensorProduct.matricize b).symm (cfc Real.sqrt ρ * adjoint (E i))) : + (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) : (H ⊗[ℂ] H) →ₗ[ℂ] (H ⊗[ℂ] H)) + = LinearMap.trace ℂ H ((adjoint (E i) * E i * ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + intro i + rw [InnerProductSpace.trace_rankOne, inner_matricize_symm, + adjoint_sqrt_mul_sqrt hρ.nonneg E i i, ContinuousLinearMap.toLinearMap_mul, + LinearMap.trace_mul_comm, ← ContinuousLinearMap.toLinearMap_mul, ← mul_assoc] + rw [Finset.sum_congr rfl fun i _ => hterm i, ← map_sum] + have hsum : ∑ i, ((adjoint (E i) * E i * ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) + = ((ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [← ContinuousLinearMap.toLinearMap_sum, ← Finset.sum_mul, htp, one_mul] + rw [hsum] + exact hρ.trace_eq_one + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EuclideanConjVec.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EuclideanConjVec.lean new file mode 100644 index 0000000000..5889c9200a --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/EuclideanConjVec.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 + +/-! +# Componentwise conjugation on `EuclideanSpace` + +`EuclideanSpace.conjVec`: componentwise complex conjugation on `EuclideanSpace 𝕜 ι`, +antilinear over `𝕜` for `𝕜 = ℂ`, norm-preserving and involutive. Reduces to the identity +for real `𝕜`. Used in the abstract Schmidt decomposition's reconstruction formula to +absorb the antilinearity of `inner` in the SVD identity `T φ = ∑ σᵢ • ⟨svdRight i, φ⟩ • +svdLeft i`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +variable {𝕜 : Type*} [RCLike 𝕜] {ι : Type*} + +namespace EuclideanSpace + +/-- Componentwise complex conjugation on `EuclideanSpace 𝕜 ι`. Antilinear over `𝕜` +(for `𝕜 = ℂ`), norm-preserving, and sesquilinear-conjugate on inner products. For real +`𝕜`, this reduces to the identity. + +Used as a building block for the "matrix transpose" of a linear endomorphism on +`EuclideanSpace 𝕜 ι`: for `T : EuclideanSpace 𝕜 ι →ₗ[𝕜] EuclideanSpace 𝕜 ι`, the +composition `conjVec ∘ T.adjoint ∘ conjVec` is a `𝕜`-linear endomorphism whose matrix +in the canonical basis is the transpose (no conjugation) of `T`'s matrix. -/ +def conjVec (v : EuclideanSpace 𝕜 ι) : EuclideanSpace 𝕜 ι := + WithLp.toLp 2 (fun j ↦ star (v j)) + +@[simp] +theorem conjVec_apply (v : EuclideanSpace 𝕜 ι) (j : ι) : + conjVec v j = star (v j) := by + simp [conjVec] + +/-- Componentwise conjugation on the coordinate track: `(conjVec v).ofLp = star v.ofLp`. -/ +@[simp] +theorem ofLp_conjVec (v : EuclideanSpace 𝕜 ι) : (conjVec v).ofLp = star v.ofLp := by + funext j; rw [conjVec_apply]; rfl + +theorem norm_conjVec [Fintype ι] (v : EuclideanSpace 𝕜 ι) : ‖conjVec v‖ = ‖v‖ := by + rw [EuclideanSpace.norm_eq, EuclideanSpace.norm_eq] + congr 1 + refine Finset.sum_congr rfl fun j _ ↦ ?_ + rw [conjVec_apply, ← RCLike.norm_conj, RCLike.star_def, RCLike.conj_conj] + +theorem inner_conjVec [Fintype ι] (u v : EuclideanSpace 𝕜 ι) : + inner 𝕜 (conjVec u) (conjVec v) = star (inner 𝕜 u v) := by + simp only [PiLp.inner_apply, conjVec_apply, RCLike.inner_apply', star_sum] + refine Finset.sum_congr rfl fun j _ ↦ ?_ + simp only [← RCLike.star_def, star_mul, star_star] + ring + +theorem orthonormal_conjVec_comp [Fintype ι] {ι' : Type*} + {v : ι' → EuclideanSpace 𝕜 ι} (hv : Orthonormal 𝕜 v) : + Orthonormal 𝕜 (conjVec ∘ v) := by + refine ⟨fun i ↦ ?_, fun i j hij ↦ ?_⟩ + · simpa [Function.comp_apply, norm_conjVec] using hv.norm_eq_one i + · simp only [Function.comp_apply, inner_conjVec] + rw [hv.inner_eq_zero hij, star_zero] + +@[simp] theorem conjVec_conjVec (v : EuclideanSpace 𝕜 ι) : conjVec (conjVec v) = v := by + ext j; simp + +/-- Sliding `conjVec` across an inner product: `⟪conjVec a, b⟫ = (⟪a, conjVec b⟫)⋆`. -/ +theorem conjVec_inner [Fintype ι] (a b : EuclideanSpace 𝕜 ι) : + inner 𝕜 (conjVec a) b = star (inner 𝕜 a (conjVec b)) := by + conv_lhs => rw [← conjVec_conjVec b] + rw [inner_conjVec] + +@[simp] theorem conjVec_add (u v : EuclideanSpace 𝕜 ι) : + conjVec (u + v) = conjVec u + conjVec v := by + ext j; simp + +@[simp] theorem conjVec_sub (u v : EuclideanSpace 𝕜 ι) : + conjVec (u - v) = conjVec u - conjVec v := by + ext j; simp + +/-- Componentwise conjugation is conjugate-linear: `conjVec (c • v) = star c • conjVec v`. -/ +@[simp] theorem conjVec_smul (c : 𝕜) (v : EuclideanSpace 𝕜 ι) : + conjVec (c • v) = star c • conjVec v := by + ext j; simp + +theorem conjVec_sum {ι' : Type*} (s : Finset ι') (g : ι' → EuclideanSpace 𝕜 ι) : + conjVec (∑ k ∈ s, g k) = ∑ k ∈ s, conjVec (g k) := by + ext j; simp [conjVec_apply, Finset.sum_apply, star_sum] + +end EuclideanSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/FidelityMonotone.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/FidelityMonotone.lean new file mode 100644 index 0000000000..f1112fe3d3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/FidelityMonotone.lean @@ -0,0 +1,188 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UhlmannAncilla +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumDilation + +/-! +# Monotonicity of the fidelity trace norm under an operator sum (Nielsen–Chuang Theorem 9.6) + +The **fidelity** of two positive operators `ρ, σ` is `F(ρ, σ) = ‖√ρ √σ‖₁` (the Schatten-1 form, +`State.fidelity_eq_traceNorm`). Nielsen–Chuang Theorem 9.6 states that a trace-preserving quantum +operation never decreases the fidelity: `F(E(ρ), E(σ)) ≥ F(ρ, σ)`. This file proves the +**operator-level heart** of that statement — the inequality between the two fidelity trace norms — +for the operator-sum (Kraus) form of the channel. The statement of the theorem for +`AxQM.IsChannel` / `State.fidelity` is in `LeanPool/AxQM/NC/Ch9/Theorem6.lean`. + +## Main results + +* `ContinuousLinearMap.traceNorm_cfc_sqrt_mul_le_krausSum` — for a **complete** Kraus family + `E : ι → (H →L H)` (`∑ₖ Eₖ† Eₖ = 1`) and positive `ρ, σ`, + `‖√ρ √σ‖₁ ≤ ‖√(∑ₖ Eₖ ρ Eₖ†) √(∑ₖ Eₖ σ Eₖ†)‖₁ = ‖√(E(ρ)) √(E(σ))‖₁`. + +## Proof + +Uhlmann's theorem (`TensorProduct.isGreatest_norm_inner_of_isPurification`, N&C Thm 9.4) supplies +purifications `Ψ₀, Φ₀ ∈ H ⊗ H` of `ρ, σ` **achieving** `‖√ρ √σ‖₁ = ‖⟪Ψ₀, Φ₀⟫‖`; matricizing them +gives square operators `M₀ = matricize Ψ₀`, `N₀ = matricize Φ₀` with `M₀ M₀† = ρ`, `N₀ N₀† = σ` and +`‖√ρ √σ‖₁ = ‖N₀.hsPairing M₀‖` (`matricize_inner_eq_hsPairing`). + +The channel is dilated into the environment `F = ℂ^ι`: `krausDilation` assembles the isometry-shaped +column operators, and we take +`M := (√ρ-side dilation)†`, `N := (√σ-side dilation)† : (H ⊗ F) →L H`, built from the Kraus family +`{(Eₖ M₀)†}` / `{(Eₖ N₀)†}`. Then + +* `M M† = ∑ₖ (Eₖ M₀)(Eₖ M₀)† = ∑ₖ Eₖ ρ Eₖ† = krausSumₗ E ρ`, and likewise `N N† = krausSumₗ E σ`, + from `adjoint_krausDilation_comp_self` and `M₀ M₀† = ρ`; +* `N.hsPairing M = ∑ₖ tr(Eₖ N₀ M₀† Eₖ†) = tr((∑ₖ Eₖ† Eₖ) N₀ M₀†) = tr(N₀ M₀†) = N₀.hsPairing M₀`, + using `trace_conj_adjoint` (cyclicity) and the **completeness** `∑ₖ Eₖ† Eₖ = 1`. + +Feeding `M, N` to the arbitrary-ancilla Uhlmann upper bound +(`norm_hsPairing_le_traceNorm_cfc_sqrt_mul`, the operator form for the enlarged ancilla `H ⊗ F`) +gives `‖N.hsPairing M‖ ≤ ‖√(krausSumₗ E ρ) √(krausSumₗ E σ)‖₁`, and the two hsPairings coincide, so +`‖√ρ √σ‖₁ = ‖N₀.hsPairing M₀‖ = ‖N.hsPairing M‖ ≤ ‖√(E(ρ)) √(E(σ))‖₁`. + +-/ + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +@[expose] public section + +noncomputable section + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {Hin : Type*} [NormedAddCommGroup Hin] [InnerProductSpace 𝕜 Hin] [FiniteDimensional 𝕜 Hin] + {Eout : Type*} [NormedAddCommGroup Eout] [InnerProductSpace 𝕜 Eout] [FiniteDimensional 𝕜 Eout] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- **Cross-family contraction of two Kraus dilations.** For families `A B : ι → Hin →ₗ Eout`, +`(krausDilation b B)† ∘ₗ (krausDilation b A) = ∑ₖ (B k)† ∘ₗ A k`. Generalises +`adjoint_krausDilation_comp_self` (the `A = B` case): expanding +`(krausDilation b B)† = ∑ₖ (B k)† ∘ₗ restrictRight b k` and +`krausDilation b A = ∑ⱼ embedRight b j ∘ₗ A j` and using the delta-orthogonality +`restrictRight b k ∘ₗ embedRight b j = δₖⱼ` collapses the double sum. -/ +theorem adjoint_krausDilation_comp_krausDilation (b : OrthonormalBasis ι 𝕜 F) + (A B : ι → Hin →ₗ[𝕜] Eout) : + adjoint (krausDilation b B) ∘ₗ krausDilation b A = ∑ k, adjoint (B k) ∘ₗ A k := by + classical + ext x + simp only [LinearMap.comp_apply, krausDilation_apply, adjoint_krausDilation, + map_sum, LinearMap.sum_apply, restrictRight_tmul, b.inner_eq_ite] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [Finset.sum_eq_single k] + · rw [ite_eq_left rfl, one_smul] + · intro j _ hjk + split_ifs with h + · simp_all + · rw [zero_smul, map_zero] + · intro h; exact absurd (Finset.mem_univ k) h + +end LinearMap + +namespace ContinuousLinearMap + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [FiniteDimensional ℂ H] [CompleteSpace H] + +/-- **Monotonicity of the fidelity trace norm under an operator sum** (the operator-level core of +Nielsen–Chuang Theorem 9.6). For a complete Kraus family `E : ι → (H →L H)` (`∑ₖ Eₖ† Eₖ = 1`) and +positive operators `ρ, σ`, the fidelity trace norm does not decrease: + + `‖√ρ √σ‖₁ ≤ ‖√(∑ₖ Eₖ ρ Eₖ†) √(∑ₖ Eₖ σ Eₖ†)‖₁`. + +See the module docstring for the Uhlmann-plus-dilation argument. -/ +theorem traceNorm_cfc_sqrt_mul_le_krausSum {ι : Type*} [Fintype ι] + (E : ι → H →L[ℂ] H) (hE : ∑ i, (adjoint (E i)).comp (E i) = 1) + {ρ σ : H →L[ℂ] H} (hρ : 0 ≤ ρ) (hσ : 0 ≤ σ) : + (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm + ≤ (cfc Real.sqrt (krausSumₗ E ρ) * cfc Real.sqrt (krausSumₗ E σ)).traceNorm := by + classical + -- Uhlmann achievement in `H ⊗ H`. + obtain ⟨Ψ₀, Φ₀, hΨ₀, hΦ₀, hval⟩ := + (TensorProduct.isGreatest_norm_inner_of_isPurification hρ hσ).1 + set b := stdOrthonormalBasis ℂ H with hb + set M₀ : H →L[ℂ] H := TensorProduct.matricize b Ψ₀ with hM₀ + set N₀ : H →L[ℂ] H := TensorProduct.matricize b Φ₀ with hN₀ + rw [TensorProduct.isPurification_iff_matricize_comp_adjoint b, ← hM₀] at hΨ₀ + rw [TensorProduct.isPurification_iff_matricize_comp_adjoint b, ← hN₀] at hΦ₀ + -- Environment `F = ℂ^ι`. + set c : OrthonormalBasis ι ℂ (EuclideanSpace ℂ ι) := EuclideanSpace.basisFun ι ℂ with hc + set Am : ι → (H →ₗ[ℂ] H) := fun k => (adjoint ((E k).comp M₀) : H →L[ℂ] H).toLinearMap with hAm + set An : ι → (H →ₗ[ℂ] H) := fun k => (adjoint ((E k).comp N₀) : H →L[ℂ] H).toLinearMap with hAn + set Vm : H →ₗ[ℂ] (H ⊗[ℂ] EuclideanSpace ℂ ι) := LinearMap.krausDilation c Am with hVm + set Vn : H →ₗ[ℂ] (H ⊗[ℂ] EuclideanSpace ℂ ι) := LinearMap.krausDilation c An with hVn + set M : (H ⊗[ℂ] EuclideanSpace ℂ ι) →L[ℂ] H := (LinearMap.adjoint Vm).toContinuousLinearMap + with hMdef + set N : (H ⊗[ℂ] EuclideanSpace ℂ ι) →L[ℂ] H := (LinearMap.adjoint Vn).toContinuousLinearMap + with hNdef + -- `adjoint M = Vm`, `adjoint N = Vn` (as CLM). + have hadjM : adjoint M = Vm.toContinuousLinearMap := by + rw [hMdef, ← LinearMap.adjoint_toContinuousLinearMap, LinearMap.adjoint_adjoint] + have hadjN : adjoint N = Vn.toContinuousLinearMap := by + rw [hNdef, ← LinearMap.adjoint_toContinuousLinearMap, LinearMap.adjoint_adjoint] + -- The shared linear-map identity `∑ₖ (Eₖ Y)(Eₖ X)† = krausSumₗ E (Y X†)` behind `M M†`, `N N†`, + -- and the cross term of the pairing below. + have hgen : ∀ X Y : H →L[ℂ] H, + (∑ k, LinearMap.adjoint ((adjoint ((E k).comp Y) : H →L[ℂ] H) : H →ₗ[ℂ] H) + ∘ₗ ((adjoint ((E k).comp X) : H →L[ℂ] H) : H →ₗ[ℂ] H)) + = ((krausSumₗ E (Y.comp (adjoint X)) : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + intro X Y + rw [krausSumₗ_apply, ContinuousLinearMap.toLinearMap_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [ContinuousLinearMap.adjoint_toLinearMap, ContinuousLinearMap.adjoint_adjoint, + ← ContinuousLinearMap.toLinearMap_comp] + congr 1 + rw [ContinuousLinearMap.adjoint_comp] + simp only [ContinuousLinearMap.comp_assoc] + -- `M M† = krausSumₗ E ρ`, `N N† = krausSumₗ E σ`. + have hMM : M.comp (adjoint M) = krausSumₗ E ρ := by + apply ContinuousLinearMap.coe_injective + rw [ContinuousLinearMap.toLinearMap_comp, hadjM, hMdef] + simp only [LinearMap.coe_toContinuousLinearMap] + rw [hVm, LinearMap.adjoint_krausDilation_comp_self, ← hΨ₀] + exact hgen M₀ M₀ + have hNN : N.comp (adjoint N) = krausSumₗ E σ := by + apply ContinuousLinearMap.coe_injective + rw [ContinuousLinearMap.toLinearMap_comp, hadjN, hNdef] + simp only [LinearMap.coe_toContinuousLinearMap] + rw [hVn, LinearMap.adjoint_krausDilation_comp_self, ← hΦ₀] + exact hgen N₀ N₀ + -- `N.hsPairing M = N₀.hsPairing M₀`. + have hpair : N.hsPairing M = N₀.hsPairing M₀ := by + -- The cross-term dilation sum is the operator sum of `N₀ M₀†` — collapsed by completeness. + have hsum : (∑ k, LinearMap.adjoint (An k) ∘ₗ Am k) + = ((krausSumₗ E (N₀.comp (adjoint M₀)) : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + simp only [hAn, hAm]; exact hgen M₀ N₀ + have hLHS : N.hsPairing M + = LinearMap.trace ℂ H ((N₀.comp (adjoint M₀) : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [← ContinuousLinearMap.hsPairing_toLinearMap N M, LinearMap.hsPairing_eq, hMdef, hNdef] + simp only [LinearMap.coe_toContinuousLinearMap, LinearMap.adjoint_adjoint] + rw [hVm, hVn, LinearMap.trace_comp_comm', + LinearMap.adjoint_krausDilation_comp_krausDilation, hsum, trace_krausSumₗ, hE, + ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp] + have hRHS : N₀.hsPairing M₀ + = LinearMap.trace ℂ H ((N₀.comp (adjoint M₀) : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [← ContinuousLinearMap.hsPairing_toLinearMap N₀ M₀, LinearMap.hsPairing_eq, + ContinuousLinearMap.adjoint_toLinearMap, LinearMap.trace_comp_comm', + ← ContinuousLinearMap.toLinearMap_comp] + rw [hLHS, hRHS] + -- Assemble. + have key := norm_hsPairing_le_traceNorm_cfc_sqrt_mul hMM hNN + rw [hpair] at key + calc (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm + = ‖(N₀.hsPairing M₀ : ℂ)‖ := by + rw [hval, TensorProduct.matricize_inner_eq_hsPairing b Ψ₀ Φ₀, ← hM₀, ← hN₀] + _ ≤ _ := key + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedInverseSqrt.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedInverseSqrt.lean new file mode 100644 index 0000000000..a3a15c0851 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedInverseSqrt.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC + +/-! +# The generalized inverse square root and the pretty-good-measurement completeness bound + +For a positive operator `A ≥ 0` on a finite-dimensional complex inner product space, this file +defines the **generalized inverse square root** + +`A^(-1/2) := cfc (fun x => (√x)⁻¹) A` + +— the operator inverting `√A` on the support of `A` and vanishing on its kernel — and records the +completeness bound of the **pretty-good (square-root) measurement**. The generalized inverse is +built directly through the continuous functional calculus with the (globally discontinuous) +function `x ↦ (√x)⁻¹`; in Lean's convention `(√0)⁻¹ = 0⁻¹ = 0`, so this single formula already +inverts the nonzero eigenvalues and kills the zero eigenvalue, and continuity on the (finite) real +spectrum is automatic (`IsSelfAdjoint.continuousOn_spectrum`). + +## What this file provides + +* `ContinuousLinearMap.genInvSqrt` — the generalized inverse square root `A^(-1/2)`. +* `ContinuousLinearMap.genInvSqrt_nonneg`, `ContinuousLinearMap.isSelfAdjoint_genInvSqrt` — it is a + positive (hence self-adjoint) operator when `A ≥ 0`. +* `ContinuousLinearMap.genInvSqrt_mul_self_mul_genInvSqrt_le_one` — the **support-projection bound** + `A^(-1/2) · A · A^(-1/2) ≤ 1`: the composite is the orthogonal projection onto the range of `A`, + so it + is a sub-identity. +* `ContinuousLinearMap.sum_genInvSqrt_conjugate_le_one` — the **completeness bound of the + pretty-good measurement**: for a finite family of positive operators `A i` with total + `S = ∑ i, A i`, the pretty-good effects `E i = S^(-1/2) · A i · S^(-1/2)` satisfy `∑ i, E i ≤ + 1`, so + `E₀ = 1 - ∑ i, E i ≥ 0` completes them to a POVM. + +This is the operator content that turns the square-root decoder `E_M = (∑ P Pₘ P)^(-1/2) P Pₘ P +(∑ P Pₘ P)^(-1/2)` of the **Holevo–Schumacher–Westmoreland theorem** (Nielsen & Chuang, Box 12.5, +eq. (12.78)) into a genuine (sub-)POVM: `∑_M E_M ≤ 1` is exactly `sum_genInvSqrt_conjugate_le_one` +applied to `A_M = P Pₘ P ≥ 0`. + +## Proof + +`A^(-1/2) · A · A^(-1/2)` is a triple product of continuous-functional-calculus images of `A`, so +`cfc_mul` folds it to `cfc h A` with `h x = (√x)⁻¹ · x · (√x)⁻¹`. On the (nonnegative) spectrum +`h x = x · x⁻¹ ∈ {0, 1}`, whence `cfc h A ≤ 1` by `cfc_le_one`. The completeness bound distributes +the outer factors over the sum, `∑ i, S^(-1/2) · A i · S^(-1/2) = S^(-1/2) · S · S^(-1/2)`, and +applies the +support-projection bound to the (positive) total `S`. + +-/ + +@[expose] public section + +noncomputable section + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **The generalized inverse square root** `A^(-1/2)` of an operator: the continuous-functional- +calculus image of `x ↦ (√x)⁻¹`. For a positive operator this inverts `√A` on the support of `A` +and vanishes on its kernel (Lean's `(√0)⁻¹ = 0` supplies the kernel behaviour automatically). -/ +def genInvSqrt (A : E →L[ℂ] E) : E →L[ℂ] E := cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A + +omit [FiniteDimensional ℂ E] in +/-- The generalized inverse square root of a positive operator is positive. -/ +theorem genInvSqrt_nonneg {A : E →L[ℂ] E} (hA : 0 ≤ A) : 0 ≤ genInvSqrt A := by + refine cfc_nonneg (fun x hx => ?_) + have hx0 : 0 ≤ x := spectrum_nonneg_of_nonneg hA hx + positivity + +omit [FiniteDimensional ℂ E] in +/-- The generalized inverse square root of a positive operator is self-adjoint. -/ +theorem isSelfAdjoint_genInvSqrt {A : E →L[ℂ] E} (hA : 0 ≤ A) : + IsSelfAdjoint (genInvSqrt A) := by + have : IsSelfAdjoint A := hA.isSelfAdjoint + exact cfc_predicate _ _ + +/-- **The support-projection bound** `A^(-1/2) · A · A^(-1/2) ≤ 1` for a positive operator `A ≥ +0`. The +composite is the orthogonal projection onto the range of `A`, so it is a sub-identity. This is the +completeness step of the pretty-good (square-root) measurement: with `A = ∑ Aᵢ` the total operator, +`A^(-1/2) · A · A^(-1/2)` is the sum of the pretty-good effects. + +Folding the triple product of functional-calculus images (`cfc_mul`) to `cfc h A` with +`h x = (√x)⁻¹ · x · (√x)⁻¹`, the pointwise bound `h x ≤ 1` on the nonnegative spectrum (where +`(√x)⁻¹ · x · (√x)⁻¹ = x · x⁻¹ ∈ {0, 1}`) gives `cfc h A ≤ 1` by `cfc_le_one`. -/ +theorem genInvSqrt_mul_self_mul_genInvSqrt_le_one {A : E →L[ℂ] E} (hA : 0 ≤ A) : + genInvSqrt A * A * genInvSqrt A ≤ 1 := by + have hsa : IsSelfAdjoint A := hA.isSelfAdjoint + have hc : ∀ f : ℝ → ℝ, ContinuousOn f (spectrum ℝ A) := fun f => hsa.continuousOn_spectrum f + -- fold the triple product of functional-calculus images into a single `cfc` + have hfold : genInvSqrt A * A * genInvSqrt A + = cfc (fun x => (Real.sqrt x)⁻¹ * x * (Real.sqrt x)⁻¹) A := by + have hmid : genInvSqrt A * A * genInvSqrt A + = cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A * cfc (id : ℝ → ℝ) A + * cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A := by + rw [cfc_id ℝ A]; rfl + rw [hmid, ← cfc_mul _ _ A (hc _) (hc _), ← cfc_mul _ _ A (hc _) (hc _)] + simp only [id_eq] + rw [hfold] + refine cfc_le_one _ A (fun x hx => ?_) + have hx0 : 0 ≤ x := spectrum_nonneg_of_nonneg hA hx + rcases eq_or_lt_of_le hx0 with h | h + · simp [← h] + · -- on a positive eigenvalue `(√x)⁻¹ · x · (√x)⁻¹ = x⁻¹ · x = 1` + rw [mul_right_comm, ← mul_inv, Real.mul_self_sqrt hx0, inv_mul_cancel₀ (ne_of_gt h)] + +/-- **The completeness bound of the pretty-good (square-root) measurement.** For a finite family of +positive operators `A : ι → E →L[ℂ] E` with total `S = ∑ i, A i`, the pretty-good effects +`E i = S^(-1/2) · A i · S^(-1/2)` sum to a sub-identity: + +`∑ i, S^(-1/2) · A i · S^(-1/2) ≤ 1`. + +Hence `E₀ = 1 - ∑ i, E i ≥ 0` completes `{E i}` to a POVM. This is the operator core making the +Nielsen–Chuang square-root decoder (Box 12.5, eq. (12.78)) a genuine (sub-)POVM. The outer factors +distribute over the sum, `∑ i, S^(-1/2) · A i · S^(-1/2) = S^(-1/2) · S · S^(-1/2)`, and the +support-projection +bound `genInvSqrt_mul_self_mul_genInvSqrt_le_one` applies to the positive total `S`. -/ +theorem sum_genInvSqrt_conjugate_le_one {ι : Type*} [Fintype ι] (A : ι → E →L[ℂ] E) + (hA : ∀ i, 0 ≤ A i) : + ∑ i, genInvSqrt (∑ j, A j) * A i * genInvSqrt (∑ j, A j) ≤ 1 := by + rw [← Finset.sum_mul, ← Finset.mul_sum] + exact genInvSqrt_mul_self_mul_genInvSqrt_le_one (Finset.sum_nonneg fun i _ => hA i) + +omit [FiniteDimensional ℂ E] in +/-- Each pretty-good effect `S^(-1/2) · Aᵢ · S^(-1/2)` is a positive operator (conjugation of the +positive +`Aᵢ` by the self-adjoint `S^(-1/2)`), the second half of the POVM datum. -/ +theorem genInvSqrt_conjugate_nonneg {ι : Type*} [Fintype ι] (A : ι → E →L[ℂ] E) + (hA : ∀ i, 0 ≤ A i) (i : ι) : + 0 ≤ genInvSqrt (∑ j, A j) * A i * genInvSqrt (∑ j, A j) := + IsSelfAdjoint.conjugate_nonneg (hA i) + (isSelfAdjoint_genInvSqrt (Finset.sum_nonneg fun i _ => hA i)) + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedKleinInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedKleinInequality.lean new file mode 100644 index 0000000000..01ced54cd2 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedKleinInequality.lean @@ -0,0 +1,552 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import Mathlib.Analysis.Convex.Deriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.NegMulLog + +/-! +# Generalized Klein's inequality + +For self-adjoint operators `A, B : E →L[ℂ] E` on a finite-dimensional complex inner product +space and a function `f : ℝ → ℝ` convex on a set `S` containing the spectra of `A` and `B`, +with derivative `f'` at each eigenvalue of `B`, the **generalized Klein inequality** +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, Problem 11.1) states + +`tr(f(A) - f(B)) ≥ tr((A - B) f'(B))`, + +where `f(A)`, `f(B)`, `f'(B)` are the continuous functional calculi. In the trace-real, +`cfc`-on-the-left convention used throughout this file (matching +`ContinuousLinearMap.quantumRelativeEntropy`), and using that trace is cyclic, this reads + +`re tr((cfc f' B) ∘ (A - B)) ≤ re tr(cfc f A) - re tr(cfc f B)`. + +## Proof outline + +Diagonalising `A` and `B` with orthonormal eigenbases `eᴬ`, `eᴮ` and eigenvalues `a`, `b`, the +matrix `Wᵢⱼ := ‖⟪eᴬᵢ, eᴮⱼ⟫‖²` is doubly stochastic (Parseval). Expanding the four traces via +`IsSelfAdjoint.re_trace_cfc_comp_eq_sum` reduces the inequality to the scalar bound + +`∑ⱼ f(bⱼ) + ∑ⱼ f'(bⱼ)·((∑ᵢ Wᵢⱼ aᵢ) - bⱼ) ≤ ∑ᵢ f(aᵢ)`, + +which follows term-by-term from the tangent-line inequality +`f(bⱼ) + f'(bⱼ)·(aᵢ - bⱼ) ≤ f(aᵢ)` (convexity of `f`) weighted by `Wᵢⱼ ≥ 0`. + +## Main results + +- `ConvexOn.add_deriv_mul_sub_le`: tangent-line inequality — a convex function lies above its + tangent line at a point of differentiability. +- `ConvexOn.sum_deriv_doublyStochastic_le`: the scalar generalized-Klein (doubly-stochastic + convex) bound, the general-`f` analogue of + `Real.sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic`. +- `IsSelfAdjoint.re_trace_cfc_eq_sum`: `re tr(cfc f T) = ∑ᵢ f(λᵢ)` for self-adjoint `T`. +- `generalized_klein_inequality`: the operator inequality above. +- `ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_nonneg_of_generalizedKlein`: + **Problem 11.1's deduction** — non-negativity of the quantum relative entropy obtained from + the generalized Klein inequality with `f = x·log x` (cf. + `ContinuousLinearMap.IsDensityOp.quantumRelativeEntropy_nonneg`, the direct log-route proof). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +/-- **Tangent-line inequality**: a convex function lies above its tangent line. If `f` is convex +on `S` and differentiable at `y ∈ S` with derivative `d`, then `f y + d·(x - y) ≤ f x` for every +`x ∈ S`. -/ +theorem ConvexOn.add_deriv_mul_sub_le {S : Set ℝ} {f : ℝ → ℝ} {y d : ℝ} + (hf : ConvexOn ℝ S f) {x : ℝ} (hx : x ∈ S) (hy : y ∈ S) + (hd : HasDerivAt f d y) : f y + d * (x - y) ≤ f x := by + rcases lt_trichotomy x y with hlt | heq | hgt + · have h := hf.slope_le_of_hasDerivAt hx hy hlt hd + rw [slope_def_field, div_le_iff₀ (by linarith)] at h; linarith + · subst heq; simp + · have h := hf.le_slope_of_hasDerivAt hy hx hgt hd + rw [slope_def_field, le_div_iff₀ (by linarith)] at h; linarith + +/-- **Strict tangent-line inequality**: a strictly convex function lies *strictly* above its +tangent line away from the point of tangency. If `f` is strictly convex on `S` and differentiable +at `y ∈ S` with derivative `d`, then `f y + d·(x - y) < f x` for every `x ∈ S` with `x ≠ y`. The +strict-convexity companion of `ConvexOn.add_deriv_mul_sub_le`. -/ +theorem StrictConvexOn.add_deriv_mul_sub_lt {S : Set ℝ} {f : ℝ → ℝ} {y d : ℝ} + (hf : StrictConvexOn ℝ S f) {x : ℝ} (hx : x ∈ S) (hy : y ∈ S) (hne : x ≠ y) + (hd : HasDerivAt f d y) : f y + d * (x - y) < f x := by + rcases lt_or_gt_of_ne hne with hlt | hgt + · have h := hf.slope_lt_of_hasDerivAt hx hy hlt hd + rw [slope_def_field, div_lt_iff₀ (by linarith)] at h + have key : d * (x - y) = -(d * (y - x)) := by ring + linarith [key, h] + · have h := hf.lt_slope_of_hasDerivAt hy hx hgt hd + rw [slope_def_field, lt_div_iff₀ (by linarith)] at h + linarith [h] + +/-- **Equality case of the strict tangent-line inequality**: for a strictly convex `f` +differentiable at `y ∈ S`, the tangent line at `y` meets the graph only at `y`. Hence if +`f y + d·(x - y) = f x` for `x ∈ S`, then `x = y`. The engine of the equality condition of +Klein's inequality. -/ +theorem StrictConvexOn.eq_of_add_deriv_mul_sub_eq {S : Set ℝ} {f : ℝ → ℝ} {y d : ℝ} + (hf : StrictConvexOn ℝ S f) {x : ℝ} (hx : x ∈ S) (hy : y ∈ S) + (hd : HasDerivAt f d y) (heq : f y + d * (x - y) = f x) : x = y := by + by_contra hne + exact absurd heq (ne_of_lt (hf.add_deriv_mul_sub_lt hx hy hne hd)) + +/-- **Doubly-stochastic residual identity**: the slack in the generalized-Klein bound +`ConvexOn.sum_deriv_doublyStochastic_le` is exactly the doubly-stochastic average of the +tangent-line gaps. For values `a : ι → ℝ`, `b : κ → ℝ`, a doubly-stochastic matrix `W`, and *any* +`f, f' : ℝ → ℝ`, + +`(∑ᵢ f(aᵢ)) − ((∑ⱼ f(bⱼ)) + ∑ⱼ f'(bⱼ)·((∑ᵢ Wᵢⱼ aᵢ) − bⱼ)) + = ∑ᵢ ∑ⱼ Wᵢⱼ·(f(aᵢ) − f(bⱼ) − f'(bⱼ)·(aᵢ − bⱼ))`. + +A pure algebraic identity (no convexity is used). It is the single source of truth for both the +generalized-Klein bound (`ConvexOn.sum_deriv_doublyStochastic_le`, whose slack is this nonnegative +average when `f` is convex) and — combined with the strict tangent-line inequality — the equality +condition of Klein's inequality. -/ +theorem sum_deriv_doublyStochastic_residual_eq {ι κ : Type*} [Fintype ι] [Fintype κ] + {f f' : ℝ → ℝ} {a : ι → ℝ} {b : κ → ℝ} {W : ι → κ → ℝ} + (hrow : ∀ i, ∑ j, W i j = 1) (hcol : ∀ j, ∑ i, W i j = 1) : + (∑ i, f (a i)) - ((∑ j, f (b j)) + ∑ j, f' (b j) * ((∑ i, W i j * a i) - b j)) + = ∑ i, ∑ j, W i j * (f (a i) - f (b j) - f' (b j) * (a i - b j)) := by + have hR : ∑ i, ∑ j, W i j * f (a i) = ∑ i, f (a i) := + Finset.sum_congr rfl fun i _ => by rw [← Finset.sum_mul, hrow i, one_mul] + have hL : ∑ i, ∑ j, W i j * (f (b j) + f' (b j) * (a i - b j)) = + (∑ j, f (b j)) + ∑ j, f' (b j) * ((∑ i, W i j * a i) - b j) := by + rw [Finset.sum_comm, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun j _ => ?_ + have step : ∀ i, W i j * (f (b j) + f' (b j) * (a i - b j)) + = W i j * f (b j) + (f' (b j) * (W i j * a i) - f' (b j) * b j * W i j) := fun i => by ring + rw [Finset.sum_congr rfl fun i _ => step i, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.sum_mul, ← Finset.mul_sum, ← Finset.mul_sum, hcol j] + ring + have expand : ∑ i, ∑ j, W i j * (f (a i) - f (b j) - f' (b j) * (a i - b j)) + = (∑ i, ∑ j, W i j * f (a i)) - ∑ i, ∑ j, W i j * (f (b j) + f' (b j) * (a i - b j)) := by + rw [← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← Finset.sum_sub_distrib] + exact Finset.sum_congr rfl fun j _ => by ring + rw [expand, hR, hL] + +/-- **Doubly-stochastic convex (generalized Klein) bound**, scalar form. For a convex `f` with +derivative `f'`, values `a : ι → ℝ` and `b : κ → ℝ` in `S`, and a doubly-stochastic matrix +`W : ι → κ → ℝ` (nonnegative entries, all row sums and column sums equal to `1`), + +`(∑ⱼ f(bⱼ)) + ∑ⱼ f'(bⱼ)·((∑ᵢ Wᵢⱼ aᵢ) - bⱼ) ≤ ∑ᵢ f(aᵢ)`. + +This is the general-`f` sibling of `Real.sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic`, +and the classical input to the operator generalized Klein inequality via spectral decomposition. +It is the `sum_deriv_doublyStochastic_residual_eq` identity read as an inequality: the residual +`∑ᵢⱼ Wᵢⱼ·(f(aᵢ) − f(bⱼ) − f'(bⱼ)(aᵢ − bⱼ))` is a nonnegative combination of tangent-line gaps +(each `≥ 0` by convexity, each `Wᵢⱼ ≥ 0`). -/ +theorem ConvexOn.sum_deriv_doublyStochastic_le {ι κ : Type*} [Fintype ι] [Fintype κ] + {S : Set ℝ} {f f' : ℝ → ℝ} {a : ι → ℝ} {b : κ → ℝ} {W : ι → κ → ℝ} + (hf : ConvexOn ℝ S f) (haS : ∀ i, a i ∈ S) (hbS : ∀ j, b j ∈ S) + (hderiv : ∀ j, HasDerivAt f (f' (b j)) (b j)) + (hW : ∀ i j, 0 ≤ W i j) (hrow : ∀ i, ∑ j, W i j = 1) (hcol : ∀ j, ∑ i, W i j = 1) : + (∑ j, f (b j)) + ∑ j, f' (b j) * ((∑ i, W i j * a i) - b j) ≤ ∑ i, f (a i) := by + have hres := sum_deriv_doublyStochastic_residual_eq (f := f) (f' := f') (a := a) (b := b) + (W := W) hrow hcol + have hnn : 0 ≤ ∑ i, ∑ j, W i j * (f (a i) - f (b j) - f' (b j) * (a i - b j)) := + Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => + mul_nonneg (hW i j) (by linarith [hf.add_deriv_mul_sub_le (haS i) (hbS j) (hderiv j)]) + linarith [hres, hnn] + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **Trace of `cfc f T`, real part**: for self-adjoint `T` with eigenvalues `λᵢ`, +`re tr(cfc f T) = ∑ᵢ f(λᵢ)`. The single-operator specialization of +`IsSelfAdjoint.re_trace_cfc_comp_eq_sum` (composition with the identity, whose diagonal entries +in `T`'s orthonormal eigenbasis are all `1`). -/ +theorem IsSelfAdjoint.re_trace_cfc_eq_sum {A : E →L[ℂ] E} (hA : IsSelfAdjoint A) (f : ℝ → ℝ) : + RCLike.re (LinearMap.trace ℂ E (cfc f A).toLinearMap) = + ∑ i, f (hA.isSymmetric.eigenvalues rfl i) := by + set eA := hA.isSymmetric.eigenvectorBasis rfl with heA + have h := hA.re_trace_cfc_comp_eq_sum rfl f (hA.continuousOn_spectrum f) 1 + simp only [ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, LinearMap.comp_id, + one_apply_eq_self, ← heA] at h + rw [h] + refine Finset.sum_congr rfl fun i _ => ?_ + have h1 : inner ℂ (eA i) (eA i) = (1 : ℂ) := by + rw [(orthonormal_iff_ite (𝕜 := ℂ)).mp eA.orthonormal, ite_eq_left rfl] + rw [h1]; simp + +/-- **Generalized-Klein residual identity** (operator form). For self-adjoint `A, B` and *any* +`f, f' : ℝ → ℝ`, the slack in the generalized Klein inequality equals the doubly-stochastic +average of the tangent-line gaps of `f`: + +`re tr(cfc f A) − re tr(cfc f B) − re tr((cfc f' B) ∘ (A − B)) + = ∑ᵢ ∑ⱼ Wᵢⱼ·(f(aᵢ) − f(bⱼ) − f'(bⱼ)·(aᵢ − bⱼ))`, + +where `aᵢ`, `bⱼ` are the eigenvalues of `A`, `B` and `Wᵢⱼ = ‖⟪eᴬᵢ, eᴮⱼ⟫‖²` is the doubly-stochastic +overlap matrix of their orthonormal eigenbases (Parseval). This is the single source of truth for +the operator generalized Klein inequality: `generalized_klein_inequality` reads it as a lower +bound (each gap `≥ 0` by convexity), while the equality case of Klein's inequality reads it as an +exact residual — every gap with a nonzero overlap must vanish. No convexity or differentiability of +`f`/`f'` is required here; it is the spectral expansion of the four traces followed by the +algebraic `sum_deriv_doublyStochastic_residual_eq`. -/ +theorem generalized_klein_residual_eq {A B : E →L[ℂ] E} (hA : IsSelfAdjoint A) + (hB : IsSelfAdjoint B) (f f' : ℝ → ℝ) : + RCLike.re (LinearMap.trace ℂ E (cfc f A).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E (cfc f B).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E ((cfc f' B).toLinearMap ∘ₗ (A - B).toLinearMap)) = + ∑ i, ∑ j, ‖inner ℂ (hA.isSymmetric.eigenvectorBasis rfl i) + (hB.isSymmetric.eigenvectorBasis rfl j)‖ ^ 2 * + (f (hA.isSymmetric.eigenvalues rfl i) - f (hB.isSymmetric.eigenvalues rfl j) - + f' (hB.isSymmetric.eigenvalues rfl j) * + (hA.isSymmetric.eigenvalues rfl i - hB.isSymmetric.eigenvalues rfl j)) := by + set eA := hA.isSymmetric.eigenvectorBasis rfl with heA + set eB := hB.isSymmetric.eigenvectorBasis rfl with heB + have hT3 := hB.re_trace_cfc_comp_eq_sum rfl f' (hB.continuousOn_spectrum f') (A - B) + rw [← heB] at hT3 + -- diagonal of `A - B` in `B`'s eigenbasis, weighted by the doubly-stochastic overlaps + have hAB : ∀ j, RCLike.re (inner ℂ (eB j) ((A - B) (eB j))) = + (∑ i, ‖inner ℂ (eA i) (eB j)‖ ^ 2 * hA.isSymmetric.eigenvalues rfl i) + - hB.isSymmetric.eigenvalues rfl j := by + intro j + rw [sub_apply, inner_sub_right, map_sub] + congr 1 + · have hsum := hA.cfc_inner_self_eq_sum rfl (id : ℝ → ℝ) (hA.continuousOn_spectrum id) (eB j) + rw [cfc_id ℝ A] at hsum + rw [hsum, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [id_eq, ← Complex.ofReal_pow, mul_comm, ← Complex.ofReal_mul] + exact Complex.ofReal_re _ + · rw [hB.apply_eigenvectorBasis_cast rfl j, inner_smul_right] + have h1 : inner ℂ (eB j) (eB j) = (1 : ℂ) := by + rw [(orthonormal_iff_ite (𝕜 := ℂ)).mp eB.orthonormal, ite_eq_left rfl] + rw [h1, mul_one]; exact Complex.ofReal_re _ + rw [hA.re_trace_cfc_eq_sum f, hB.re_trace_cfc_eq_sum f, hT3] + simp_rw [hAB] + rw [sub_sub] + exact sum_deriv_doublyStochastic_residual_eq + (fun i => by rw [eB.sum_sq_norm_inner_left (eA i), eA.orthonormal.1 i, one_pow]) + (fun j => by rw [eA.sum_sq_norm_inner_right (eB j), eB.orthonormal.1 j, one_pow]) + +/-- **Generalized Klein's inequality** (Nielsen–Chuang, Problem 11.1). For self-adjoint +`A, B : E →L[ℂ] E`, a function `f` convex on a set `S` containing the real spectra of `A` and +`B`, with derivative `f'` at each eigenvalue of `B`, + +`re tr((cfc f' B) ∘ (A - B)) ≤ re tr(cfc f A) - re tr(cfc f B)`, + +i.e. `tr(f(A) - f(B)) ≥ tr((A - B) f'(B))` in N&C's notation (the left-hand trace `tr((cfc f' B) +∘ (A - B))` equals `tr((A - B) f'(B))` by cyclicity of the trace). + +Requiring `f` convex only on `S ⊇ spectrum A ∪ spectrum B` (rather than on all of `ℝ`) is the +faithful generality: it accommodates functions such as `x ↦ x·log x`, convex only on `[0, ∞)`, +that drive the entropy corollary below. It is `generalized_klein_residual_eq` read as a lower +bound: the residual is a sum of tangent-line gaps, each `≥ 0` by convexity, weighted by the +nonnegative overlaps `Wᵢⱼ ≥ 0`. -/ +theorem generalized_klein_inequality {A B : E →L[ℂ] E} (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) + {S : Set ℝ} {f f' : ℝ → ℝ} (hf : ConvexOn ℝ S f) + (hAS : spectrum ℝ A ⊆ S) (hBS : spectrum ℝ B ⊆ S) + (hderiv : ∀ b ∈ spectrum ℝ B, HasDerivAt f (f' b) b) : + RCLike.re (LinearMap.trace ℂ E ((cfc f' B).toLinearMap ∘ₗ (A - B).toLinearMap)) ≤ + RCLike.re (LinearMap.trace ℂ E (cfc f A).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E (cfc f B).toLinearMap) := by + have hnn : 0 ≤ RCLike.re (LinearMap.trace ℂ E (cfc f A).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E (cfc f B).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E ((cfc f' B).toLinearMap ∘ₗ (A - B).toLinearMap)) := by + rw [generalized_klein_residual_eq hA hB f f'] + exact Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => + mul_nonneg (sq_nonneg _) + (by linarith [hf.add_deriv_mul_sub_le (hAS (hA.eigenvalues_mem_spectrum_real rfl i)) + (hBS (hB.eigenvalues_mem_spectrum_real rfl j)) + (hderiv _ (hB.eigenvalues_mem_spectrum_real rfl j))]) + linarith [hnn] + +namespace ContinuousLinearMap.IsDensityOp + +/-- **The generalized-Klein slack at `f = x·log x` is the quantum relative entropy.** For density +operators `ρ, σ`, + +`re tr(cfc (x·log x) ρ) − re tr(cfc (x·log x) σ) − re tr((cfc (fun x => log x + 1) σ) ∘ (ρ − σ)) + = D(ρ ‖ σ)`. + +The shared slack→`D` reduction consumed by both the non-negativity route +(`quantumRelativeEntropy_nonneg_of_generalizedKlein`) and the equality condition +(`quantumRelativeEntropy_eq_zero_iff`): `cfc_log_mul_self` turns each `x·log x` entropy trace into a +`(cfc log ·) ∘ ·` trace, and the `+1` in `f' = log · + 1` contributes `tr(ρ − σ) = 0` (both states +have unit trace), leaving `re tr((cfc log ρ)∘ρ) − re tr((cfc log σ)∘ρ)`, which is +`quantumRelativeEntropy` by definition. Needs only that `ρ, σ` are density operators (no +faithfulness). -/ +private theorem quantumRelativeEntropy_eq_generalizedKlein_slack {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) : + RCLike.re (LinearMap.trace ℂ E (cfc (fun x => x * Real.log x) ρ).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E (cfc (fun x => x * Real.log x) σ).toLinearMap) - + RCLike.re (LinearMap.trace ℂ E + ((cfc (fun x => Real.log x + 1) σ).toLinearMap ∘ₗ (ρ - σ).toLinearMap)) = + ρ.quantumRelativeEntropy σ := by + have hBsa := hσ.isPositive.isSelfAdjoint + -- `tr(cfc (x·log x) T) = tr((cfc log T) ∘ T)`, the entropy-term reduction. + have hEred : ∀ (T : E →L[ℂ] E), IsSelfAdjoint T → + RCLike.re (LinearMap.trace ℂ E (cfc (fun x => x * Real.log x) T).toLinearMap) = + RCLike.re (LinearMap.trace ℂ E ((cfc Real.log T).toLinearMap ∘ₗ T.toLinearMap)) := by + intro T hT; rw [← hT.cfc_log_mul_self, ContinuousLinearMap.toLinearMap_mul]; rfl + -- `f'(σ) = log σ + 1`. + have hf'cfc : cfc (fun x => Real.log x + 1) σ = cfc Real.log σ + 1 := by + rw [cfc_add σ Real.log (fun _ => 1) (hBsa.continuousOn_spectrum _) + (hBsa.continuousOn_spectrum _), cfc_const_one ℝ σ] + have hρtr : RCLike.re (LinearMap.trace ℂ E ρ.toLinearMap) = 1 := by rw [hρ.trace_eq_one]; simp + have hσtr : RCLike.re (LinearMap.trace ℂ E σ.toLinearMap) = 1 := by rw [hσ.trace_eq_one]; simp + have op_eq : (cfc (fun x => Real.log x + 1) σ).toLinearMap ∘ₗ (ρ - σ).toLinearMap = + ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap + - (cfc Real.log σ).toLinearMap ∘ₗ σ.toLinearMap) + (ρ.toLinearMap - σ.toLinearMap) := by + rw [hf'cfc, ContinuousLinearMap.toLinearMap_add, ContinuousLinearMap.toLinearMap_one, + ContinuousLinearMap.toLinearMap_sub, LinearMap.add_comp, Module.End.one_eq_id, + LinearMap.id_comp, + LinearMap.comp_sub] + -- The `+1` contributes `tr(ρ − σ) = 0`. + have E3 : RCLike.re (LinearMap.trace ℂ E + ((cfc (fun x => Real.log x + 1) σ).toLinearMap ∘ₗ (ρ - σ).toLinearMap)) = + RCLike.re (LinearMap.trace ℂ E ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap)) + - RCLike.re (LinearMap.trace ℂ E ((cfc Real.log σ).toLinearMap ∘ₗ σ.toLinearMap)) := by + rw [op_eq]; simp only [map_add, map_sub]; rw [hρtr, hσtr]; ring + rw [hEred ρ hρ.isPositive.isSelfAdjoint, hEred σ hBsa, E3, + ContinuousLinearMap.quantumRelativeEntropy_def] + ring + +/-! ### Non-faithful Klein's inequality under the support condition + +Klein's inequality `D(ρ ‖ σ) ≥ 0` (and its equality condition `= 0 ↔ ρ = σ`) needs only the +**support condition** `supp ρ ⊆ supp σ` (`HasSupportLE ρ σ`, i.e. `ker σ ≤ ker ρ`) on `σ`, *not* +full faithfulness (`IsStrictlyPositive σ`). Faithfulness (`hσ_pos`) is used in exactly one place: to +get the tangent-line inequality of `x ↦ x·log x` at each eigenvalue `bⱼ` of `σ` (`x·log x` is not +differentiable at `0`). So we prove the support-condition versions here and recover the faithful +`quantumRelativeEntropy_nonneg_of_generalizedKlein` / `quantumRelativeEntropy_eq_zero_iff` (N&C +Problem 11.1 / Theorem 11.7) below as one-line corollaries. The residual identity +`generalized_klein_residual_eq` +holds with no faithfulness at all, writing `D(ρ ‖ σ) = Σᵢⱼ Wᵢⱼ·gapᵢⱼ` for the tangent-line gaps +`gapᵢⱼ`. The support condition kills exactly the ill-defined `bⱼ = 0` terms: if `bⱼ = 0` and the +overlap `⟪eᵨᵢ, eₛⱼ⟫ ≠ 0`, then `eₛⱼ ∈ ker σ ⊆ ker ρ`, so `ρ (eₛⱼ) = 0` forces `aᵢ = 0 = bⱼ` and the +gap vanishes; elsewhere (`bⱼ > 0`) the tangent-line inequality applies as before. This is the exact +generality Nielsen & Chuang need for Theorem 11.9, whose pinched state `Σᵢ Pᵢ ρ Pᵢ` is generally +rank-deficient but always satisfies the support condition. -/ + +/-- **The support condition kills the zero-eigenvalue block.** If `HasSupportLE ρ σ` and `bⱼ = 0` +is a zero eigenvalue of `σ` whose eigenvector `eₛⱼ` overlaps `ρ`'s eigenvector `eᵨᵢ` +(`⟪eᵨᵢ, eₛⱼ⟫ ≠ 0`), then the corresponding eigenvalue `aᵢ` of `ρ` vanishes. Since `bⱼ = 0` means +`eₛⱼ ∈ ker σ ⊆ ker ρ`, we have `ρ (eₛⱼ) = 0`; pairing with `eᵨᵢ` (using `ρ (eᵨᵢ) = aᵢ eᵨᵢ` and +self-adjointness) gives `aᵢ ⟪eᵨᵢ, eₛⱼ⟫ = 0`, so `aᵢ = 0`. -/ +private theorem eigenvalue_eq_zero_of_hasSupportLE {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) (hsupp : HasSupportLE ρ σ) + {i j : Fin (Module.finrank ℂ E)} + (hbj : hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl j = 0) + (hij : inner ℂ (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl i) + (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j) ≠ 0) : + hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i = 0 := by + -- `eₛⱼ ∈ ker σ ⊆ ker ρ`, so `ρ (eₛⱼ) = 0`. + have hker : hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j + ∈ LinearMap.ker (σ : E →ₗ[ℂ] E) := by + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe, + hσ.isPositive.isSelfAdjoint.apply_eigenvectorBasis_cast rfl j, hbj] + simp + have hρ0 : ρ (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j) = 0 := by + have h := hsupp hker + rwa [LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at h + -- `aᵢ · ⟪eᵨᵢ, eₛⱼ⟫ = ⟪eᵨᵢ, ρ (eₛⱼ)⟫ = 0`. + have hcoef : (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i : ℂ) * + inner ℂ (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl i) + (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j) = 0 := by + have h1 := ContinuousLinearMap.adjoint_inner_left ρ + (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j) + (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl i) + rw [hρ.isPositive.isSelfAdjoint.adjoint_eq, + hρ.isPositive.isSelfAdjoint.apply_eigenvectorBasis_cast rfl i, inner_smul_left, + Complex.conj_ofReal, hρ0, inner_zero_right] at h1 + exact h1 + rcases mul_eq_zero.mp hcoef with h | h + · exact_mod_cast h + · exact absurd h hij + +/-- **Each generalized-Klein term is nonnegative under the support condition.** For density +operators `ρ, σ` with `HasSupportLE ρ σ`, every summand `Wᵢⱼ·gapᵢⱼ` of the residual sum +`generalized_klein_residual_eq` (at `f = x·log x`, `f' = log x + 1`) is `≥ 0`: where `bⱼ > 0` the +tangent-line inequality gives `gapᵢⱼ ≥ 0` (`ConvexOn.add_deriv_mul_sub_le`); where `bⱼ = 0` the +support condition forces the term to vanish (`eigenvalue_eq_zero_of_hasSupportLE`). -/ +private theorem gap_term_nonneg {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) (hsupp : HasSupportLE ρ σ) + (i j : Fin (Module.finrank ℂ E)) : + 0 ≤ ‖inner ℂ (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl i) + (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl j)‖ ^ 2 * + (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i * + Real.log (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i) - + hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl j * + Real.log (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl j) - + (Real.log (hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl j) + 1) * + (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i - + hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl j)) := by + set a := hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl with ha + set b := hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl with hb + set eA := hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl with heA + set eB := hσ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl with heB + have hbnn : (0 : ℝ) ≤ b j := hσ.eigenvalues_nonneg rfl j + rcases eq_or_lt_of_le hbnn with hb0 | hbpos + · -- `bⱼ = 0`: either the overlap vanishes, or `aᵢ = 0` and the whole gap collapses. + rcases eq_or_ne (inner ℂ (eA i) (eB j)) 0 with hw | hw + · rw [hw]; simp + · have hai : a i = 0 := eigenvalue_eq_zero_of_hasSupportLE hρ hσ hsupp hb0.symm hw + rw [hai, ← hb0]; simp + · -- `bⱼ > 0`: the tangent-line inequality of `x·log x` at `bⱼ`. + refine mul_nonneg (sq_nonneg _) ?_ + have hann : (0 : ℝ) ≤ a i := hρ.eigenvalues_nonneg rfl i + have htan := Real.strictConvexOn_mul_log.convexOn.add_deriv_mul_sub_le + (Set.mem_Ici.mpr hann) (Set.mem_Ici.mpr hbpos.le) (Real.hasDerivAt_mul_log hbpos.ne') + beta_reduce at htan + linarith [htan] + +/-- **Klein's inequality under the support condition** (non-faithful `σ`). For density operators +`ρ, σ : E →L[ℂ] E` with the support condition `supp ρ ⊆ supp σ` (`HasSupportLE ρ σ`, i.e. +`ker σ ≤ ker ρ`), the quantum relative entropy is non-negative: + +`0 ≤ D(ρ ‖ σ)`, + +even when `σ` is rank-deficient. This is the exact generality behind Nielsen & Chuang's Theorem 11.9 +(projective measurements increase entropy), where `σ = Σᵢ Pᵢ ρ Pᵢ` is generally not faithful. + +The full-faithfulness version `quantumRelativeEntropy_nonneg_of_generalizedKlein` is the special +case `ker σ = ⊥`. The proof is the residual identity `generalized_klein_residual_eq` (via the shared +slack reduction `quantumRelativeEntropy_eq_generalizedKlein_slack`) with every term nonnegative +(`gap_term_nonneg`); the support condition, rather than faithfulness, discharges the zero-eigenvalue +block. -/ +theorem quantumRelativeEntropy_nonneg_of_hasSupportLE {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) (hsupp : HasSupportLE ρ σ) : + 0 ≤ ρ.quantumRelativeEntropy σ := by + rw [← quantumRelativeEntropy_eq_generalizedKlein_slack hρ hσ, + generalized_klein_residual_eq hρ.isPositive.isSelfAdjoint hσ.isPositive.isSelfAdjoint + (fun x => x * Real.log x) (fun x => Real.log x + 1)] + exact Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => gap_term_nonneg hρ hσ hsupp i j + +/-- **Klein's inequality, equality condition, under the support condition** (non-faithful `σ`; +Nielsen & Chuang Theorem 11.7 relaxed as needed for Theorem 11.9). For density operators `ρ, σ` with +`supp ρ ⊆ supp σ` (`HasSupportLE ρ σ`), + +`D(ρ ‖ σ) = 0 ↔ ρ = σ`. + +The full-faithfulness version `quantumRelativeEntropy_eq_zero_iff` is the special case `ker σ = ⊥`; +this replaces faithfulness of `σ` by the support condition. The reverse direction is +`quantumRelativeEntropy_self`. Forward: the residual identity writes `D(ρ ‖ σ)` as the +doubly-stochastic average `Σᵢⱼ Wᵢⱼ·gapᵢⱼ ≥ 0` of the tangent-line gaps; `D = 0` with the nonnegative +terms (`gap_term_nonneg`) forces each `Wᵢⱼ·gapᵢⱼ = 0`. Where the overlap `⟪eᵨᵢ, eₛⱼ⟫ ≠ 0`: if +`bⱼ > 0` the strict tangent-line inequality gives `aᵢ = bⱼ`, and if `bⱼ = 0` the support condition +gives `aᵢ = 0 = bⱼ` (`eigenvalue_eq_zero_of_hasSupportLE`). Either way `aᵢ = bⱼ` on the nonzero +overlaps, so `ρ` and `σ` agree on `σ`'s eigenbasis, hence `ρ = σ`. -/ +theorem quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) (hsupp : HasSupportLE ρ σ) : + ρ.quantumRelativeEntropy σ = 0 ↔ ρ = σ := by + refine ⟨fun hzero => ?_, fun h => h ▸ ContinuousLinearMap.quantumRelativeEntropy_self ρ⟩ + have hAsa := hρ.isPositive.isSelfAdjoint + have hBsa := hσ.isPositive.isSelfAdjoint + -- The residual sum vanishes (`D = 0` via the shared slack reduction + residual identity). + have hZ : ∑ i, ∑ j, ‖inner ℂ (hAsa.isSymmetric.eigenvectorBasis rfl i) + (hBsa.isSymmetric.eigenvectorBasis rfl j)‖ ^ 2 * + (hAsa.isSymmetric.eigenvalues rfl i * Real.log (hAsa.isSymmetric.eigenvalues rfl i) - + hBsa.isSymmetric.eigenvalues rfl j * Real.log (hBsa.isSymmetric.eigenvalues rfl j) - + (Real.log (hBsa.isSymmetric.eigenvalues rfl j) + 1) * + (hAsa.isSymmetric.eigenvalues rfl i - hBsa.isSymmetric.eigenvalues rfl j)) = 0 := by + have hres := generalized_klein_residual_eq hAsa hBsa + (fun x => x * Real.log x) (fun x => Real.log x + 1) + have hSL0 := (quantumRelativeEntropy_eq_generalizedKlein_slack hρ hσ).trans hzero + rw [hres] at hSL0 + exact hSL0 + set eA := hAsa.isSymmetric.eigenvectorBasis rfl with heA + set eB := hBsa.isSymmetric.eigenvectorBasis rfl with heB + set a := hAsa.isSymmetric.eigenvalues rfl with ha + set b := hBsa.isSymmetric.eigenvalues rfl with hb + -- Each term of the nonnegative residual sum vanishes. + have hterms : ∀ i j, ‖inner ℂ (eA i) (eB j)‖ ^ 2 * + (a i * Real.log (a i) - b j * Real.log (b j) - (Real.log (b j) + 1) * (a i - b j)) = 0 := by + have hnn : ∀ i ∈ Finset.univ, 0 ≤ ∑ j, ‖inner ℂ (eA i) (eB j)‖ ^ 2 * + (a i * Real.log (a i) - b j * Real.log (b j) - (Real.log (b j) + 1) * (a i - b j)) := + fun i _ => Finset.sum_nonneg fun j _ => gap_term_nonneg hρ hσ hsupp i j + intro i j + have h1 := (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hZ i (Finset.mem_univ i) + exact (Finset.sum_eq_zero_iff_of_nonneg + (fun j _ => gap_term_nonneg hρ hσ hsupp i j)).mp h1 j (Finset.mem_univ j) + -- Where the overlap is nonzero the eigenvalues coincide (strict convexity or support condition). + have heq_val : ∀ i j, inner ℂ (eA i) (eB j) ≠ (0 : ℂ) → a i = b j := by + intro i j hij + rcases eq_or_lt_of_le (show (0 : ℝ) ≤ b j from hσ.eigenvalues_nonneg rfl j) with hb0 | hbpos + · rw [← hb0] + exact eigenvalue_eq_zero_of_hasSupportLE hρ hσ hsupp hb0.symm hij + · have hW : ‖inner ℂ (eA i) (eB j)‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.mpr hij) + have hgap0 : a i * Real.log (a i) - b j * Real.log (b j) + - (Real.log (b j) + 1) * (a i - b j) = 0 := + (mul_eq_zero.mp (hterms i j)).resolve_left hW + exact Real.strictConvexOn_mul_log.eq_of_add_deriv_mul_sub_eq + (Set.mem_Ici.mpr (show (0 : ℝ) ≤ a i from hρ.eigenvalues_nonneg rfl i)) + (Set.mem_Ici.mpr hbpos.le) (Real.hasDerivAt_mul_log hbpos.ne') + (by linear_combination -hgap0) + -- `ρ` and `σ` agree on the eigenbasis `eB`, hence coincide. + have hagree : ∀ j, ρ (eB j) = σ (eB j) := by + intro j + have hσj : σ (eB j) = (b j : ℂ) • eB j := hBsa.apply_eigenvectorBasis_cast rfl j + have hρj : (ρ : E →ₗ[ℂ] E) (eB j) = ∑ i, (a i : ℂ) • inner ℂ (eA i) (eB j) • eA i := + hAsa.isSymmetric.spectral_sum_apply rfl (eB j) + have hterm : ∀ i, (a i : ℂ) • inner ℂ (eA i) (eB j) • eA i + = (b j : ℂ) • inner ℂ (eA i) (eB j) • eA i := by + intro i + by_cases hz : inner ℂ (eA i) (eB j) = (0 : ℂ) + · rw [hz]; simp + · rw [heq_val i j hz] + calc ρ (eB j) = (ρ : E →ₗ[ℂ] E) (eB j) := rfl + _ = ∑ i, (a i : ℂ) • inner ℂ (eA i) (eB j) • eA i := hρj + _ = ∑ i, (b j : ℂ) • inner ℂ (eA i) (eB j) • eA i := Finset.sum_congr rfl fun i _ => hterm i + _ = (b j : ℂ) • ∑ i, inner ℂ (eA i) (eB j) • eA i := by rw [Finset.smul_sum] + _ = (b j : ℂ) • eB j := by + congr 1 + simp_rw [← OrthonormalBasis.repr_apply_apply] + exact eA.sum_repr (eB j) + _ = σ (eB j) := hσj.symm + exact ContinuousLinearMap.coe_injective + (Module.Basis.ext eB.toBasis fun j => by simpa using hagree j) + +/-- The support condition holds unconditionally for a faithful `σ`: full-rank (`hσ_pos`) means +`σ` is invertible (`0 ∉ spectrum ℝ σ`), hence strictly positive, hence `ker σ = ⊥ ≤ ker ρ`. The +bridge specializing the support-condition Klein lemmas to the faithful case. -/ +private theorem hasSupportLE_of_eigenvalues_pos {ρ σ : E →L[ℂ] E} (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : HasSupportLE ρ σ := + HasSupportLE.of_isStrictlyPositive (hσ.isStrictlyPositive + ((spectrum.zero_notMem_iff ℝ).mp + (hσ.isPositive.isSelfAdjoint.zero_notMem_spectrum_real_of_eigenvalues_pos rfl hσ_pos))) + +/-- **Non-negativity of the quantum relative entropy, via the generalized Klein inequality** +(Nielsen–Chuang, Problem 11.1: *"use this result to show that the relative entropy is +non-negative"*). For density operators `ρ, σ` with `σ`'s eigenvalues all positive, `0 ≤ D(ρ ‖ σ)`. + +The faithful special case of `quantumRelativeEntropy_nonneg_of_hasSupportLE`: a faithful `σ` has +trivial kernel, so the support condition holds unconditionally (`hasSupportLE_of_eigenvalues_pos`). +Statement-identical to the direct log-route `quantumRelativeEntropy_nonneg`; kept as the explicit +generalized-Klein derivation (Problem 11.1). -/ +theorem quantumRelativeEntropy_nonneg_of_generalizedKlein {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + 0 ≤ ρ.quantumRelativeEntropy σ := + quantumRelativeEntropy_nonneg_of_hasSupportLE hρ hσ (hasSupportLE_of_eigenvalues_pos hσ hσ_pos) + +/-- **Klein's inequality, equality condition** (Nielsen–Chuang, Theorem 11.7). For density +operators `ρ, σ` with `σ` faithful (all eigenvalues of `σ` strictly positive), the quantum relative +entropy vanishes iff the states coincide: + +`D(ρ ‖ σ) = 0 ↔ ρ = σ`. + +Together with `quantumRelativeEntropy_nonneg` this is the full content of Klein's inequality: +`D(ρ ‖ σ) ≥ 0`, with equality iff `ρ = σ`. + +The faithful special case of `quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE`: a faithful `σ` +has trivial kernel, so the support condition holds unconditionally +(`hasSupportLE_of_eigenvalues_pos`). Only `σ` need be faithful; `ρ` may be rank-deficient. -/ +theorem quantumRelativeEntropy_eq_zero_iff {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + ρ.quantumRelativeEntropy σ = 0 ↔ ρ = σ := + quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE hρ hσ + (hasSupportLE_of_eigenvalues_pos hσ hσ_pos) + +end ContinuousLinearMap.IsDensityOp diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedRelativeEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedRelativeEntropy.lean new file mode 100644 index 0000000000..d9ba484d55 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeneralizedRelativeEntropy.lean @@ -0,0 +1,615 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyConvexNonfaithful +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# Generalized relative entropy for positive operators (Nielsen & Chuang, Problem 11.2) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Problem 11.2 extends the +(Umegaki) relative entropy `S(r ‖ s) = tr(r log r) - tr(r log s)` to arbitrary positive +operators and asks for four properties. This file proves all four for strictly positive +operators on a finite-dimensional complex Euclidean space. + +The relative entropy itself is `ContinuousLinearMap.quantumRelativeEntropy` from +`ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy`, whose definition +`re tr(ρ log ρ) - re tr(ρ log σ)` (with `log` the operator logarithm via the continuous functional +calculus) is exactly N&C's generalized definition (11.131). + +## Main results + +- `ContinuousLinearMap.quantumRelativeEntropy_smul_smul`: **scaling** (N&C 11.132), + `S(c • r ‖ d • s) = c · S(r ‖ s) + c · tr(r) · log(c / d)`. +- `ContinuousLinearMap.quantumRelativeEntropy_subadditive_of_jointConvex`: **(11.133) via joint + convexity** — joint convexity of the relative entropy implies its subadditivity. +- `ContinuousLinearMap.quantumRelativeEntropy_subadditive`: **subadditivity** (11.133), + `S(r₁ + r₂ ‖ s₁ + s₂) ≤ S(r₁ ‖ s₁) + S(r₂ ‖ s₂)`, the concrete instance obtained from Lindblad + joint convexity (`quantumRelativeEntropy_jointly_convex`). +- `ContinuousLinearMap.quantumRelativeEntropy_jointConvex_of_subadditive`: **the converse** — + subadditivity implies joint convexity, closing the equivalence `subadditivity ↔ joint convexity` + from parts (2) and (3). +- `ContinuousLinearMap.quantumRelativeEntropy_sum_le_sum`: **n-ary subadditivity** — + `S(∑ᵢ rᵢ ‖ ∑ᵢ sᵢ) ≤ ∑ᵢ S(rᵢ ‖ sᵢ)` over a nonempty index `Finset`, the finite iterate of the + binary subadditivity used by part (4). +- `ContinuousLinearMap.quantumRelativeEntropy_sum_smul_smul_le`: **the mixture bound** (N&C 11.134), + `S(∑ᵢ pᵢ • rᵢ ‖ ∑ᵢ qᵢ • sᵢ) ≤ ∑ᵢ pᵢ · S(rᵢ ‖ sᵢ) + ∑ᵢ pᵢ · tr(rᵢ) · log(pᵢ / qᵢ)`. +- `ContinuousLinearMap.quantumRelativeEntropy_sum_smul_smul_le_relativeEntropy`: **the "pretty + formula"** (N&C 11.135), the density-operator (`tr(rᵢ) = 1`) specialization in which the + correction term collapses to the classical relative entropy + `Real.relativeEntropy p q = ∑ᵢ pᵢ log(pᵢ / qᵢ)`. + +N&C states the problem for *any two positive operators*, not only strictly positive ones. The +strictly-positive results above therefore carry **faithful strengthenings** on the finite branch +(the support condition `supp r ⊆ supp s`, `HasSupportLE r s`, on which the `cfc`-based `D` equals +the true relative entropy — the domain of the faithful joint convexity, N&C Theorem 11.12 +`quantumRelativeEntropy_jointly_convex_of_hasSupportLE`); the strict forms are their special case +`HasSupportLE.of_isStrictlyPositive`: + +- `ContinuousLinearMap.quantumRelativeEntropy_smul_smul_of_hasSupportLE`: **scaling** (11.132) for + positive `r, s` with `r.HasSupportLE s`. +- `ContinuousLinearMap.quantumRelativeEntropy_subadditive_of_hasSupportLE`: **subadditivity** + (11.133) for positive `r₁, r₂, s₁, s₂` with `rᵢ.HasSupportLE sᵢ`, via the faithful joint + convexity, with `quantumRelativeEntropy_subadditive_of_jointConvex_of_hasSupportLE` its + joint-convexity hypothesis form (part (2)). +- `ContinuousLinearMap.quantumRelativeEntropy_jointConvex_of_subadditive_of_hasSupportLE`: **the + converse** (part (3)) — faithful subadditivity implies faithful joint convexity, closing the + equivalence for positive operators on the finite branch. +- `ContinuousLinearMap.quantumRelativeEntropy_sum_le_sum_of_hasSupportLE`: **n-ary subadditivity** + for positive families on the finite branch, the engine of part (4). +- `ContinuousLinearMap.quantumRelativeEntropy_sum_smul_smul_le_of_hasSupportLE`: **the mixture + bound** (11.134) for positive `rᵢ, sᵢ` with `rᵢ.HasSupportLE sᵢ` and positive weights `pᵢ, qᵢ`. +- `ContinuousLinearMap.quantumRelativeEntropy_sum_smul_smul_le_relativeEntropy_of_hasSupportLE`: + **the "pretty formula"** (11.135), its density-operator (`re tr(rᵢ) = 1`) specialization. + +The per-term support-condition transport `ContinuousLinearMap.hasSupportLE_smul_smul` +(`rᵢ.HasSupportLE sᵢ ⟹ (pᵢ • rᵢ).HasSupportLE (qᵢ • sᵢ)`) feeds the mixture bound. + +## Implementation notes + +N&C states the problem for "any two positive operators". The definition `S(r ‖ s)` is finite only +under the support condition `supp r ⊆ supp s`; we take the uniformly-clean representative +`IsStrictlyPositive` (spectrum `⊆ (0, ∞)`), where the `Real.log 0 = 0` junk value never appears and +which is also the exact domain of the library joint-convexity theorem (Lindblad, +`convexOn_quantumRelativeEntropy`) that parts (2)–(4) invoke. The scaling identity (part 1) already +needs this hypothesis: the cross term `tr(r log(d • s))` picks up a `log d · tr(r · P_{ker s})` +discrepancy off the support of `s`. We work on `EuclideanSpace ℂ ι` (every finite-dimensional +complex Hilbert space is isometric to one) so as to reuse the `re_trace_*` trace-linearity helpers +and the binary `quantumRelativeEntropy_jointly_convex` directly. + +For the mixture bound (part 4) N&C takes `pᵢ, qᵢ` to be probability distributions. The inequality +(11.134) in fact needs only `0 < pᵢ` and `0 < qᵢ` (each `pᵢ • rᵢ`, `qᵢ • sᵢ` strictly positive, so +that finite subadditivity and the scaling law apply term by term); the normalization +`∑ pᵢ = ∑ qᵢ = 1` is used nowhere in the bound. We therefore state the (stronger, more reusable) +positive-weight form. Normalization re-enters only for N&C's "pretty formula" (11.135): with +`tr(rᵢ) = 1` the correction term is `∑ᵢ pᵢ log(pᵢ / qᵢ)`, which is the classical relative entropy +`Real.relativeEntropy p q` — a `Fintype`-wide sum, so the (11.135) specialization is stated over +`Finset.univ`. +-/ + +@[expose] public section + +open scoped ComplexOrder + +namespace ContinuousLinearMap + +variable {ι : Type*} [Fintype ι] + +/-- **Operator logarithm of a positive scalar multiple.** For a strictly positive operator `W` and +`0 < c`, `log (c • W) = (log c) • 1 + log W`, where `log` is the operator real logarithm via the +continuous functional calculus. (The `Real.log 0 = 0` junk value never appears: `W`, hence `c • W`, +has spectrum in `(0, ∞)`.) The operator form of `CFC.log_smul'`, phrased for the `cfc Real.log` +occurring in `quantumRelativeEntropy`. -/ +theorem cfc_log_smul {W : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hW : IsStrictlyPositive W) {c : ℝ} (hc : 0 < c) : + cfc Real.log (c • W) = + Real.log c • (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + cfc Real.log W := by + have h := CFC.log_smul' (A := EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) W hc hW + rwa [Algebra.algebraMap_eq_smul_one] at h + +/-- **Log-scaling of a trace term.** For strictly positive `W`, `0 < c`, and any operator `M`, +`re tr(log(c • W) ∘ M) = log c · re tr M + re tr(log W ∘ M)`. The single-term engine of the scaling +law: the operator identity `cfc_log_smul` splits `log(c • W)`, and the split trace is collapsed by +the operator-level `re_trace_add_smul`. -/ +theorem re_trace_cfc_log_smul_comp {W M : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hW : IsStrictlyPositive W) {c : ℝ} (hc : 0 < c) : + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((cfc Real.log (c • W)).toLinearMap ∘ₗ M.toLinearMap)) = + Real.log c * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) M.toLinearMap) + + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((cfc Real.log W).toLinearMap ∘ₗ M.toLinearMap)) := by + have key : cfc Real.log (c • W) * M + = Real.log c • M + (1 : ℝ) • (cfc Real.log W * M) := by + rw [cfc_log_smul hW hc, add_mul, smul_mul_assoc, one_mul, one_smul] + rw [← ContinuousLinearMap.toLinearMap_comp, ← ContinuousLinearMap.mul_def, key, + re_trace_add_smul, one_mul, ContinuousLinearMap.mul_def, ContinuousLinearMap.toLinearMap_comp] + +/-- **Pulling a scalar out of the right factor of a trace term.** +`re tr(A ∘ (c • N)) = c · re tr(A ∘ N)`. -/ +theorem re_trace_comp_smul_right {H : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] + [NormedSpace ℝ H] [IsScalarTower ℝ ℂ H] (A N : H →L[ℂ] H) (c : ℝ) : + RCLike.re (LinearMap.trace ℂ H (A.toLinearMap ∘ₗ (c • N).toLinearMap)) = + c * RCLike.re (LinearMap.trace ℂ H (A.toLinearMap ∘ₗ N.toLinearMap)) := by + rw [← ContinuousLinearMap.toLinearMap_comp, ← ContinuousLinearMap.mul_def, mul_smul_comm, + re_trace_smul, ContinuousLinearMap.mul_def, ContinuousLinearMap.toLinearMap_comp] + +-- The `ring` finish accumulates CFC `whnf` reductions on the operator-trace atoms. +/-- **Scaling of the generalized relative entropy** (N&C Problem 11.2(1), eq. (11.132)). For +strictly positive operators `r, s` and positive scalars `c, d`, +`S(c • r ‖ d • s) = c · S(r ‖ s) + c · tr(r) · log(c / d)`, where `tr(r)` is `re tr r`. Both +`log`-terms of `S(c • r ‖ d • s)` split via `re_trace_cfc_log_smul_comp`; the residual `c • r` +factors pull out by `re_trace_smul` / `re_trace_comp_smul_right`, and `log c - log d = log(c / d)`. +-/ +theorem quantumRelativeEntropy_smul_smul + {ρ σ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hρ : IsStrictlyPositive ρ) (hσ : IsStrictlyPositive σ) {c d : ℝ} (hc : 0 < c) (hd : 0 < d) : + quantumRelativeEntropy (c • ρ) (d • σ) = + c * quantumRelativeEntropy ρ σ + + c * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) ρ.toLinearMap) * + Real.log (c / d) := by + rw [quantumRelativeEntropy_def, quantumRelativeEntropy_def, + re_trace_cfc_log_smul_comp hρ hc, re_trace_cfc_log_smul_comp hσ hd, re_trace_smul, + re_trace_comp_smul_right, re_trace_comp_smul_right, Real.log_div (ne_of_gt hc) (ne_of_gt hd)] + ring + +-- Rewriting with `quantumRelativeEntropy_smul_smul` in `h` reduces CFC operator terms via `whnf`. +/-- **Joint convexity implies subadditivity** (N&C Problem 11.2(2), the forward direction of the +`subadditivity ↔ joint convexity` equivalence, eq. (11.133)). Given the joint convexity of the +relative entropy (as the hypothesis `hJC`), for strictly positive `r₁, r₂, s₁, s₂`, +`S(r₁ + r₂ ‖ s₁ + s₂) ≤ S(r₁ ‖ s₁) + S(r₂ ‖ s₂)`. Apply `hJC` at the midpoint `t = s = ½`; the +left-hand side is `S(½ • (r₁ + r₂) ‖ ½ • (s₁ + s₂))`, which by `quantumRelativeEntropy_smul_smul` +equals `½ · S(r₁ + r₂ ‖ s₁ + s₂)` since `log(½ / ½) = log 1 = 0`. -/ +theorem quantumRelativeEntropy_subadditive_of_jointConvex + (hJC : ∀ {a₁ a₂ b₁ b₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι}, + IsStrictlyPositive a₁ → IsStrictlyPositive a₂ → IsStrictlyPositive b₁ → + IsStrictlyPositive b₂ → ∀ {t s : ℝ}, 0 ≤ t → 0 ≤ s → t + s = 1 → + quantumRelativeEntropy (t • a₁ + s • a₂) (t • b₁ + s • b₂) ≤ + t * quantumRelativeEntropy a₁ b₁ + s * quantumRelativeEntropy a₂ b₂) + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : IsStrictlyPositive r₁) (hr₂ : IsStrictlyPositive r₂) + (hs₁ : IsStrictlyPositive s₁) (hs₂ : IsStrictlyPositive s₂) : + quantumRelativeEntropy (r₁ + r₂) (s₁ + s₂) ≤ + quantumRelativeEntropy r₁ s₁ + quantumRelativeEntropy r₂ s₂ := by + have h := hJC hr₁ hr₂ hs₁ hs₂ (by norm_num : (0:ℝ) ≤ 2⁻¹) (by norm_num : (0:ℝ) ≤ 2⁻¹) + (by norm_num : (2:ℝ)⁻¹ + 2⁻¹ = 1) + rw [← smul_add, ← smul_add, + quantumRelativeEntropy_smul_smul (IsStrictlyPositive.nonneg_add hr₁.nonneg hr₂) + (IsStrictlyPositive.nonneg_add hs₁.nonneg hs₂) (by norm_num) (by norm_num), + div_self (by norm_num : (2:ℝ)⁻¹ ≠ 0), Real.log_one, mul_zero, add_zero] at h + linarith + +/-- **Subadditivity of the generalized relative entropy** (N&C Problem 11.2(2), eq. (11.133)). For +strictly positive `r₁, r₂, s₁, s₂`, +`S(r₁ + r₂ ‖ s₁ + s₂) ≤ S(r₁ ‖ s₁) + S(r₂ ‖ s₂)`. The concrete instance of +`quantumRelativeEntropy_subadditive_of_jointConvex` obtained by discharging the joint-convexity +hypothesis with Lindblad's theorem (`quantumRelativeEntropy_jointly_convex`). -/ +theorem quantumRelativeEntropy_subadditive + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : IsStrictlyPositive r₁) (hr₂ : IsStrictlyPositive r₂) + (hs₁ : IsStrictlyPositive s₁) (hs₂ : IsStrictlyPositive s₂) : + quantumRelativeEntropy (r₁ + r₂) (s₁ + s₂) ≤ + quantumRelativeEntropy r₁ s₁ + quantumRelativeEntropy r₂ s₂ := + quantumRelativeEntropy_subadditive_of_jointConvex + quantumRelativeEntropy_jointly_convex hr₁ hr₂ hs₁ hs₂ + +-- The `IsStrictlyPositive.smul` applications need the `PosSMulMono ℝ (E →L[ℂ] E)` instance, whose +-- synthesis on the operator algebra exceeds the default `synthInstance` budget. +/-- **Subadditivity implies joint convexity** (N&C Problem 11.2(3), the converse direction of the +`subadditivity ↔ joint convexity` equivalence). Given the subadditivity of the relative entropy +(as the hypothesis `hSub`), for strictly positive `r₁, r₂, s₁, s₂` and convex weights `t + u = 1`, +`S(t • r₁ + u • r₂ ‖ t • s₁ + u • s₂) ≤ t · S(r₁ ‖ s₁) + u · S(r₂ ‖ s₂)`. The boundary weights +`t = 0` / `u = 0` are trivial; on the interior apply `hSub` to `t • r₁, u • r₂, t • s₁, u • s₂` and +rescale each summand via `quantumRelativeEntropy_smul_smul` (with `log(t / t) = log 1 = 0`). -/ +theorem quantumRelativeEntropy_jointConvex_of_subadditive + (hSub : ∀ {a₁ a₂ b₁ b₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι}, + IsStrictlyPositive a₁ → IsStrictlyPositive a₂ → IsStrictlyPositive b₁ → + IsStrictlyPositive b₂ → + quantumRelativeEntropy (a₁ + a₂) (b₁ + b₂) ≤ + quantumRelativeEntropy a₁ b₁ + quantumRelativeEntropy a₂ b₂) + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : IsStrictlyPositive r₁) (hr₂ : IsStrictlyPositive r₂) + (hs₁ : IsStrictlyPositive s₁) (hs₂ : IsStrictlyPositive s₂) + {t u : ℝ} (ht : 0 ≤ t) (hu : 0 ≤ u) (htu : t + u = 1) : + quantumRelativeEntropy (t • r₁ + u • r₂) (t • s₁ + u • s₂) ≤ + t * quantumRelativeEntropy r₁ s₁ + u * quantumRelativeEntropy r₂ s₂ := by + rcases eq_or_lt_of_le ht with rfl | ht0 + · have hu1 : u = 1 := by linarith + subst hu1; simp + rcases eq_or_lt_of_le hu with rfl | hu0 + · have ht1 : t = 1 := by linarith + subst ht1; simp + have h := hSub (hr₁.smul ht0) (hr₂.smul hu0) (hs₁.smul ht0) (hs₂.smul hu0) + rw [quantumRelativeEntropy_smul_smul hr₁ hs₁ ht0 ht0, + quantumRelativeEntropy_smul_smul hr₂ hs₂ hu0 hu0] at h + simp only [div_self ht0.ne', div_self hu0.ne', Real.log_one, mul_zero, add_zero] at h + exact h + +/-- **n-ary subadditivity of the generalized relative entropy.** For a nonempty index `Finset t` +and strictly positive families `r, s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι`, +`S(∑ᵢ rᵢ ‖ ∑ᵢ sᵢ) ≤ ∑ᵢ S(rᵢ ‖ sᵢ)`. The finite iterate of the binary subadditivity +`quantumRelativeEntropy_subadditive`, proved by induction on `t` +(`Finset.Nonempty.cons_induction`): the singleton case is reflexivity, and the cons step splits off +one summand with binary subadditivity — the tail sum stays strictly positive by +`IsStrictlyPositive.sum` — then finishes with the inductive hypothesis. This is the engine of the +mixture bound (part 4). -/ +theorem quantumRelativeEntropy_sum_le_sum {κ : Type*} {t : Finset κ} (ht : t.Nonempty) + {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr : ∀ i ∈ t, IsStrictlyPositive (r i)) (hs : ∀ i ∈ t, IsStrictlyPositive (s i)) : + quantumRelativeEntropy (∑ i ∈ t, r i) (∑ i ∈ t, s i) ≤ + ∑ i ∈ t, quantumRelativeEntropy (r i) (s i) := by + induction ht using Finset.Nonempty.cons_induction with + | singleton a => simp + | cons a u _ hu ih => + rw [Finset.sum_cons, Finset.sum_cons, Finset.sum_cons] + have hru : ∀ i ∈ u, IsStrictlyPositive (r i) := fun i hi => hr i (Finset.mem_cons_of_mem hi) + have hsu : ∀ i ∈ u, IsStrictlyPositive (s i) := fun i hi => hs i (Finset.mem_cons_of_mem hi) + calc quantumRelativeEntropy (r a + ∑ i ∈ u, r i) (s a + ∑ i ∈ u, s i) + ≤ quantumRelativeEntropy (r a) (s a) + + quantumRelativeEntropy (∑ i ∈ u, r i) (∑ i ∈ u, s i) := + quantumRelativeEntropy_subadditive (hr a (Finset.mem_cons_self a u)) + (IsStrictlyPositive.sum hu hru) (hs a (Finset.mem_cons_self a u)) + (IsStrictlyPositive.sum hu hsu) + _ ≤ quantumRelativeEntropy (r a) (s a) + ∑ i ∈ u, quantumRelativeEntropy (r i) (s i) := by + have := ih hru hsu; linarith + +-- The `IsStrictlyPositive.smul` applications need the `PosSMulMono ℝ (E →L[ℂ] E)` instance, whose +-- synthesis on the operator algebra exceeds the default `synthInstance` budget. +/-- **Mixture bound for the generalized relative entropy** (N&C Problem 11.2(4), eq. (11.134)). For +strictly positive families `r, s`, positive weights `p, q` (`0 < pᵢ`, `0 < qᵢ`) on a nonempty index +`Finset t`, +`S(∑ᵢ pᵢ • rᵢ ‖ ∑ᵢ qᵢ • sᵢ) ≤ ∑ᵢ pᵢ · S(rᵢ ‖ sᵢ) + ∑ᵢ pᵢ · tr(rᵢ) · log(pᵢ / qᵢ)`, +where `tr(rᵢ)` is `re tr(rᵢ)`. n-ary subadditivity (`quantumRelativeEntropy_sum_le_sum`) applied to +the strictly positive `pᵢ • rᵢ`, `qᵢ • sᵢ` bounds the left-hand side by `∑ᵢ S(pᵢ • rᵢ ‖ qᵢ • sᵢ)`, +and the scaling law (`quantumRelativeEntropy_smul_smul`) rewrites each summand. + +N&C phrases part (4) for probability distributions `p, q`; the bound needs only their positivity +(the normalization `∑ pᵢ = ∑ qᵢ = 1` is unused), so this is the stronger positive-weight form. -/ +theorem quantumRelativeEntropy_sum_smul_smul_le {κ : Type*} {t : Finset κ} (ht : t.Nonempty) + {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} {p q : κ → ℝ} + (hr : ∀ i ∈ t, IsStrictlyPositive (r i)) (hs : ∀ i ∈ t, IsStrictlyPositive (s i)) + (hp : ∀ i ∈ t, 0 < p i) (hq : ∀ i ∈ t, 0 < q i) : + quantumRelativeEntropy (∑ i ∈ t, p i • r i) (∑ i ∈ t, q i • s i) ≤ + (∑ i ∈ t, p i * quantumRelativeEntropy (r i) (s i)) + + ∑ i ∈ t, p i * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) (r i).toLinearMap) * + Real.log (p i / q i) := by + refine (quantumRelativeEntropy_sum_le_sum ht (fun i hi => (hr i hi).smul (hp i hi)) + (fun i hi => (hs i hi).smul (hq i hi))).trans (le_of_eq ?_) + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i hi => + quantumRelativeEntropy_smul_smul (hr i hi) (hs i hi) (hp i hi) (hq i hi) + +/-- **The "pretty formula" for the mixture bound** (N&C Problem 11.2(4), eq. (11.135)). When the +`rᵢ` are density operators (`re tr(rᵢ) = 1`), the mixture-bound correction term collapses to the +classical relative entropy (Kullback–Leibler divergence) `Real.relativeEntropy p q = ∑ᵢ pᵢ log(pᵢ / +qᵢ)` of the weight distributions: +`S(∑ᵢ pᵢ • rᵢ ‖ ∑ᵢ qᵢ • sᵢ) ≤ ∑ᵢ pᵢ · S(rᵢ ‖ sᵢ) + D(p ‖ q)`. +Stated over `Finset.univ` of a nonempty `Fintype κ`, matching the index range of +`Real.relativeEntropy`; per-term, `re tr(rᵢ) = 1` and `log(pᵢ / qᵢ) = log pᵢ - log qᵢ` +(`Real.log_div`, valid since `pᵢ, qᵢ > 0`) turn the correction into `∑ᵢ pᵢ (log pᵢ - log qᵢ)`. -/ +theorem quantumRelativeEntropy_sum_smul_smul_le_relativeEntropy {κ : Type*} [Fintype κ] [Nonempty κ] + {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} {p q : κ → ℝ} + (hr : ∀ i, IsStrictlyPositive (r i)) (hs : ∀ i, IsStrictlyPositive (s i)) + (hp : ∀ i, 0 < p i) (hq : ∀ i, 0 < q i) + (htr : ∀ i, RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) (r i).toLinearMap) = 1) : + quantumRelativeEntropy (∑ i, p i • r i) (∑ i, q i • s i) ≤ + (∑ i, p i * quantumRelativeEntropy (r i) (s i)) + Real.relativeEntropy p q := by + refine (quantumRelativeEntropy_sum_smul_smul_le Finset.univ_nonempty + (fun i _ => hr i) (fun i _ => hs i) (fun i _ => hp i) (fun i _ => hq i)).trans (le_of_eq ?_) + rw [Real.relativeEntropy_eq] + congr 1 + exact Finset.sum_congr rfl fun i _ => by + rw [htr i, mul_one, Real.log_div (hp i).ne' (hq i).ne'] + +/-! ### Faithful (support-condition) forms for arbitrary positive operators + +Nielsen & Chuang Problem 11.2 is stated for *any two positive operators*, not only strictly +positive ones. The `cfc`-based `D` equals the true relative entropy precisely on the **finite +branch**, the support condition `supp r ⊆ supp s` (`HasSupportLE r s`, i.e. `ker s ≤ ker r`); this +is the domain of the faithful joint convexity +`quantumRelativeEntropy_jointly_convex_of_hasSupportLE` (N&C Theorem 11.12, N&C's literal +statement). All four parts of Problem 11.2 go through on that branch for `IsPositive` operators; the +strictly-positive statements above are the special case `HasSupportLE.of_isStrictlyPositive`. This +section develops parts (1)–(3): the scaling law, and the subadditivity ↔ joint convexity +equivalence. -/ + +/-- **Kernel invariance of the support condition under nonzero real scaling.** For `c ≠ 0`, scaling +the first operator by `c` leaves its kernel unchanged, so `ρ.HasSupportLE σ` upgrades to +`(c • ρ).HasSupportLE σ`. The step that turns a per-pair support condition on `ρᵢ, σᵢ` into one on +the scaled `c • ρᵢ`, as used by the scaling law and the mixture bound. -/ +theorem hasSupportLE_smul_left {ρ σ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + {c : ℝ} (hc : c ≠ 0) (h : ρ.HasSupportLE σ) : (c • ρ).HasSupportLE σ := by + have hker : (↑(c • ρ) : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι).ker + = (↑ρ : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι).ker := by + rw [← Complex.coe_smul c ρ] + ext x + simp only [LinearMap.mem_ker, ContinuousLinearMap.toLinearMap_smul, LinearMap.smul_apply, + ContinuousLinearMap.coe_coe, smul_eq_zero, Complex.ofReal_eq_zero] + tauto + unfold ContinuousLinearMap.HasSupportLE at h ⊢ + rwa [hker] + +-- The eigenbasis spectral computation (three `re_trace_cfc_comp_eq_sum_of_apply_eq_smul` unfoldings +-- plus the `cfc` `whnf` reductions on the operator-trace atoms) exceeds the default budget. +/-- **Log-scaling of a trace term under the support condition.** For a self-adjoint `W`, `0 < c`, +and any `M` supported inside `W` (`M.HasSupportLE W`, i.e. `ker W ≤ ker M`), +`re tr(log(c • W) ∘ M) = log c · re tr M + re tr(log W ∘ M)`. The support-condition generalisation +of `re_trace_cfc_log_smul_comp`, which needs strict positivity (the operator identity +`log(c • W) = log c • 1 + log W` fails on the kernel of `W`, where `log 0 = 0` is a junk value). +Computing all three traces in a common eigenbasis `b` of `W` +(`re_trace_cfc_comp_eq_sum_of_apply_eq_smul`, whose `ContinuousOn Real.log` premise is discharged by +`continuousOn_log_spectrum` since the finite spectrum is discrete), the identity is the termwise +`log(c μᵢ) aᵢ = (log c + log μᵢ) aᵢ` with `aᵢ = re⟨bᵢ, M bᵢ⟩`; on the kernel of `W` (`μᵢ = 0`) the +support condition forces `M bᵢ = 0`, hence `aᵢ = 0`, so the junk value never contributes. -/ +theorem re_trace_cfc_log_smul_comp_of_hasSupportLE + {W M : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hW : IsSelfAdjoint W) (hMW : M.HasSupportLE W) {c : ℝ} (hc : 0 < c) : + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((cfc Real.log (c • W)).toLinearMap ∘ₗ M.toLinearMap)) = + Real.log c * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) M.toLinearMap) + + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((cfc Real.log W).toLinearMap ∘ₗ M.toLinearMap)) := by + have hn : Module.finrank ℂ (EuclideanSpace ℂ ι) = Module.finrank ℂ (EuclideanSpace ℂ ι) := rfl + set b := hW.isSymmetric.eigenvectorBasis hn with hb + set μ := hW.isSymmetric.eigenvalues hn with hμdef + have hWb : ∀ i, W (b i) = (μ i : ℂ) • b i := fun i => hW.apply_eigenvectorBasis_cast hn i + have hcW : IsSelfAdjoint (c • W) := IsSelfAdjoint.smul (IsSelfAdjoint.all c) hW + have hcWb : ∀ i, (c • W) (b i) = ((c * μ i : ℝ) : ℂ) • b i := fun i => by + rw [← Complex.coe_smul c W, _root_.smul_apply, hWb i, smul_smul, + ← Complex.ofReal_mul] + have hsum_cW := hcW.re_trace_cfc_comp_eq_sum_of_apply_eq_smul b hcWb + hcW.continuousOn_log_spectrum M + have hsum_W := hW.re_trace_cfc_comp_eq_sum_of_apply_eq_smul b hWb hW.continuousOn_log_spectrum M + have htrM : RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) M.toLinearMap) + = ∑ i, RCLike.re (inner ℂ (b i) (M (b i))) := by + rw [LinearMap.trace_eq_sum_inner M.toLinearMap b, map_sum] + simp only [ContinuousLinearMap.coe_coe] + rw [hsum_cW, hsum_W, htrM, Finset.mul_sum, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun i _ => ?_ + rcases eq_or_ne (μ i) 0 with hμ0 | hμ0 + · have hker : b i ∈ LinearMap.ker (W : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι) := by + rw [LinearMap.mem_ker] + change W (b i) = 0 + rw [hWb i, hμ0]; simp + have hMbi : M (b i) = 0 := by + have := hMW hker + rwa [LinearMap.mem_ker] at this + rw [hMbi]; simp + · rw [Real.log_mul hc.ne' hμ0]; ring + +-- The `ring` finish accumulates CFC `whnf` reductions on the operator-trace atoms. +/-- **Scaling of the generalized relative entropy for positive operators** (N&C Problem 11.2(1), eq. +(11.132), faithful form). For positive operators `r, s` on the finite branch `r.HasSupportLE s` +(`supp r ⊆ supp s`) and positive scalars `c, d`, +`S(c • r ‖ d • s) = c · S(r ‖ s) + c · tr(r) · log(c / d)`, where `tr(r)` is `re tr r`. Both +`log`-terms split via `re_trace_cfc_log_smul_comp_of_hasSupportLE`; for the cross term, the support +condition (transported to `(c • r).HasSupportLE s` by `hasSupportLE_smul_left`) is what discards the +`log d · tr(r · P_{ker s})` discrepancy off the support of `s` that would otherwise appear. The +residual `c • r` factors pull out by `re_trace_smul` / `re_trace_comp_smul_right`, and +`log c − log d = log(c / d)`. Strengthens `quantumRelativeEntropy_smul_smul` from strict positivity +to the full positive-operator finite branch. -/ +theorem quantumRelativeEntropy_smul_smul_of_hasSupportLE + {ρ σ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hρ : ρ.IsPositive) (hσ : σ.IsPositive) (hρσ : ρ.HasSupportLE σ) {c d : ℝ} + (hc : 0 < c) (hd : 0 < d) : + quantumRelativeEntropy (c • ρ) (d • σ) = + c * quantumRelativeEntropy ρ σ + + c * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) ρ.toLinearMap) * + Real.log (c / d) := by + rw [quantumRelativeEntropy_def, quantumRelativeEntropy_def, + re_trace_cfc_log_smul_comp_of_hasSupportLE hρ.isSelfAdjoint + (hasSupportLE_smul_left hc.ne' (le_refl _)) hc, + re_trace_cfc_log_smul_comp_of_hasSupportLE hσ.isSelfAdjoint + (hasSupportLE_smul_left hc.ne' hρσ) hd, re_trace_smul, + re_trace_comp_smul_right, re_trace_comp_smul_right, Real.log_div (ne_of_gt hc) (ne_of_gt hd)] + ring + +/-- **Joint convexity implies subadditivity, faithful form** (N&C Problem 11.2(2), the forward +direction of the `subadditivity ↔ joint convexity` equivalence, eq. (11.133), for positive operators +on the finite branch). Given the faithful joint convexity of the relative entropy (as the hypothesis +`hJC`, for positive operators with the support condition), for positive `r₁, r₂, s₁, s₂` with +`r₁.HasSupportLE s₁`, `r₂.HasSupportLE s₂`, +`S(r₁ + r₂ ‖ s₁ + s₂) ≤ S(r₁ ‖ s₁) + S(r₂ ‖ s₂)`. Apply `hJC` at the midpoint `t = s = ½`; the +left-hand side is `S(½ • (r₁ + r₂) ‖ ½ • (s₁ + s₂))`, which by +`quantumRelativeEntropy_smul_smul_of_hasSupportLE` (using `(r₁ + r₂).HasSupportLE (s₁ + s₂)` from +`hasSupportLE_add`) equals `½ · S(r₁ + r₂ ‖ s₁ + s₂)` since `log(½ / ½) = log 1 = 0`. Strengthens +`quantumRelativeEntropy_subadditive_of_jointConvex` from strict positivity to the full +positive-operator finite branch. -/ +theorem quantumRelativeEntropy_subadditive_of_jointConvex_of_hasSupportLE + (hJC : ∀ {a₁ a₂ b₁ b₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι}, + a₁.IsPositive → a₂.IsPositive → b₁.IsPositive → b₂.IsPositive → + a₁.HasSupportLE b₁ → a₂.HasSupportLE b₂ → ∀ {t s : ℝ}, 0 ≤ t → 0 ≤ s → t + s = 1 → + quantumRelativeEntropy (t • a₁ + s • a₂) (t • b₁ + s • b₂) ≤ + t * quantumRelativeEntropy a₁ b₁ + s * quantumRelativeEntropy a₂ b₂) + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : r₁.IsPositive) (hr₂ : r₂.IsPositive) (hs₁ : s₁.IsPositive) (hs₂ : s₂.IsPositive) + (hsup₁ : r₁.HasSupportLE s₁) (hsup₂ : r₂.HasSupportLE s₂) : + quantumRelativeEntropy (r₁ + r₂) (s₁ + s₂) ≤ + quantumRelativeEntropy r₁ s₁ + quantumRelativeEntropy r₂ s₂ := by + have h := hJC hr₁ hr₂ hs₁ hs₂ hsup₁ hsup₂ (by norm_num : (0:ℝ) ≤ 2⁻¹) (by norm_num : (0:ℝ) ≤ 2⁻¹) + (by norm_num : (2:ℝ)⁻¹ + 2⁻¹ = 1) + rw [← smul_add, ← smul_add, + quantumRelativeEntropy_smul_smul_of_hasSupportLE (hr₁.add hr₂) (hs₁.add hs₂) + (hasSupportLE_add hs₁ hs₂ hsup₁ hsup₂) (by norm_num) (by norm_num), + div_self (by norm_num : (2:ℝ)⁻¹ ≠ 0), Real.log_one, mul_zero, add_zero] at h + linarith + +/-- **Subadditivity of the generalized relative entropy for positive operators** (N&C Problem +11.2(2), eq. (11.133), faithful form). For positive `r₁, r₂, s₁, s₂` on the finite branch +`r₁.HasSupportLE s₁`, `r₂.HasSupportLE s₂`, +`S(r₁ + r₂ ‖ s₁ + s₂) ≤ S(r₁ ‖ s₁) + S(r₂ ‖ s₂)`. The concrete instance of +`quantumRelativeEntropy_subadditive_of_jointConvex_of_hasSupportLE` obtained by discharging the +joint-convexity hypothesis with the faithful Lindblad theorem (N&C Theorem 11.12, +`quantumRelativeEntropy_jointly_convex_of_hasSupportLE`). Strengthens +`quantumRelativeEntropy_subadditive` from strict positivity to the full positive-operator finite +branch. -/ +theorem quantumRelativeEntropy_subadditive_of_hasSupportLE + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : r₁.IsPositive) (hr₂ : r₂.IsPositive) (hs₁ : s₁.IsPositive) (hs₂ : s₂.IsPositive) + (hsup₁ : r₁.HasSupportLE s₁) (hsup₂ : r₂.HasSupportLE s₂) : + quantumRelativeEntropy (r₁ + r₂) (s₁ + s₂) ≤ + quantumRelativeEntropy r₁ s₁ + quantumRelativeEntropy r₂ s₂ := + quantumRelativeEntropy_subadditive_of_jointConvex_of_hasSupportLE + quantumRelativeEntropy_jointly_convex_of_hasSupportLE hr₁ hr₂ hs₁ hs₂ hsup₁ hsup₂ + +/-- **Subadditivity implies joint convexity, faithful form** (N&C Problem 11.2(3), the converse +direction of the `subadditivity ↔ joint convexity` equivalence, for positive operators on the finite +branch). Given the faithful subadditivity of the relative entropy (as the hypothesis `hSub`), for +positive `r₁, r₂, s₁, s₂` with `r₁.HasSupportLE s₁`, `r₂.HasSupportLE s₂` and convex weights +`t + u = 1`, +`S(t • r₁ + u • r₂ ‖ t • s₁ + u • s₂) ≤ t · S(r₁ ‖ s₁) + u · S(r₂ ‖ s₂)`. The boundary weights +`t = 0` / `u = 0` are trivial; on the interior apply `hSub` to the positive +`t • r₁, u • r₂, t • s₁, u • s₂` +(support conditions transported by `hasSupportLE_smul`) and rescale each summand via +`quantumRelativeEntropy_smul_smul_of_hasSupportLE` (with `log(t / t) = log 1 = 0`). Strengthens +`quantumRelativeEntropy_jointConvex_of_subadditive` from strict positivity to the full +positive-operator finite branch. -/ +theorem quantumRelativeEntropy_jointConvex_of_subadditive_of_hasSupportLE + (hSub : ∀ {a₁ a₂ b₁ b₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι}, + a₁.IsPositive → a₂.IsPositive → b₁.IsPositive → b₂.IsPositive → + a₁.HasSupportLE b₁ → a₂.HasSupportLE b₂ → + quantumRelativeEntropy (a₁ + a₂) (b₁ + b₂) ≤ + quantumRelativeEntropy a₁ b₁ + quantumRelativeEntropy a₂ b₂) + {r₁ r₂ s₁ s₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr₁ : r₁.IsPositive) (hr₂ : r₂.IsPositive) (hs₁ : s₁.IsPositive) (hs₂ : s₂.IsPositive) + (hsup₁ : r₁.HasSupportLE s₁) (hsup₂ : r₂.HasSupportLE s₂) + {t u : ℝ} (ht : 0 ≤ t) (hu : 0 ≤ u) (htu : t + u = 1) : + quantumRelativeEntropy (t • r₁ + u • r₂) (t • s₁ + u • s₂) ≤ + t * quantumRelativeEntropy r₁ s₁ + u * quantumRelativeEntropy r₂ s₂ := by + rcases eq_or_lt_of_le ht with rfl | ht0 + · have hu1 : u = 1 := by linarith + subst hu1; simp + rcases eq_or_lt_of_le hu with rfl | hu0 + · have ht1 : t = 1 := by linarith + subst ht1; simp + have h := hSub (hr₁.smul_real_of_nonneg ht0.le) (hr₂.smul_real_of_nonneg hu0.le) + (hs₁.smul_real_of_nonneg ht0.le) (hs₂.smul_real_of_nonneg hu0.le) + (hasSupportLE_smul ht0.ne' hsup₁) (hasSupportLE_smul hu0.ne' hsup₂) + rw [quantumRelativeEntropy_smul_smul_of_hasSupportLE hr₁ hs₁ hsup₁ ht0 ht0, + quantumRelativeEntropy_smul_smul_of_hasSupportLE hr₂ hs₂ hsup₂ hu0 hu0] at h + simp only [div_self ht0.ne', div_self hu0.ne', Real.log_one, mul_zero, add_zero] at h + exact h + +/-! #### The mixture bound for arbitrary positive operators (part (4)) + +The last part of Problem 11.2 — the finite subadditivity, the mixture bound (11.134), and the +"pretty formula" (11.135) — likewise goes through on the finite branch for positive operators. -/ + +/-- **Nonzero scaling of the two operators by (possibly different) real scalars preserves the +support condition.** For `c ≠ 0`, `d ≠ 0`, scaling leaves both kernels unchanged +(`ker (e • τ) = ker τ` for `e ≠ 0`, since `(e : ℂ) ≠ 0`), so `ρ.HasSupportLE σ` upgrades to +`(c • ρ).HasSupportLE (d • σ)`. The +per-term support-condition input to the mixture bound: from `rᵢ.HasSupportLE sᵢ` it produces +`(pᵢ • rᵢ).HasSupportLE (qᵢ • sᵢ)`. Generalises `hasSupportLE_smul_left` (the `d = 1` case) to an +independent right scalar; cf. the equal-scalar `hasSupportLE_smul`. -/ +theorem hasSupportLE_smul_smul {ρ σ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} {c d : ℝ} + (hc : c ≠ 0) (hd : d ≠ 0) (h : ρ.HasSupportLE σ) : (c • ρ).HasSupportLE (d • σ) := by + have hker : ∀ (e : ℝ), e ≠ 0 → ∀ τ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι, + (↑(e • τ) : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι).ker + = (↑τ : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι).ker := fun e he τ => by + rw [← Complex.coe_smul e τ, ContinuousLinearMap.toLinearMap_smul, + LinearMap.ker_smul _ _ (by exact_mod_cast he : (e : ℂ) ≠ 0)] + unfold ContinuousLinearMap.HasSupportLE at h ⊢ + rwa [hker c hc ρ, hker d hd σ] + +/-- **n-ary subadditivity of the generalized relative entropy for positive operators** (faithful +form). For a nonempty index `Finset t` and positive families +`r, s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι` on the finite branch +`(r i).HasSupportLE (s i)`, `S(∑ᵢ rᵢ ‖ ∑ᵢ sᵢ) ≤ ∑ᵢ S(rᵢ ‖ sᵢ)`. The finite iterate of the binary +faithful subadditivity `quantumRelativeEntropy_subadditive_of_hasSupportLE`, proved by induction on +`t` (`Finset.Nonempty.cons_induction`): the singleton case is reflexivity; the cons step splits off +one summand with binary subadditivity — the tail sum stays positive by `isPositive_sum` and inherits +the support condition by `hasSupportLE_sum_smul` (weights `1`) — then finishes with the inductive +hypothesis. Strengthens `quantumRelativeEntropy_sum_le_sum` from strict positivity to the full +positive-operator finite branch; the engine of the mixture bound (part 4). -/ +theorem quantumRelativeEntropy_sum_le_sum_of_hasSupportLE {κ : Type*} {t : Finset κ} + (ht : t.Nonempty) {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hr : ∀ i ∈ t, (r i).IsPositive) (hs : ∀ i ∈ t, (s i).IsPositive) + (hsup : ∀ i ∈ t, (r i).HasSupportLE (s i)) : + quantumRelativeEntropy (∑ i ∈ t, r i) (∑ i ∈ t, s i) ≤ + ∑ i ∈ t, quantumRelativeEntropy (r i) (s i) := by + induction ht using Finset.Nonempty.cons_induction with + | singleton a => simp + | cons a u _ _ ih => + rw [Finset.sum_cons, Finset.sum_cons, Finset.sum_cons] + have hru : ∀ i ∈ u, (r i).IsPositive := fun i hi => hr i (Finset.mem_cons_of_mem hi) + have hsu : ∀ i ∈ u, (s i).IsPositive := fun i hi => hs i (Finset.mem_cons_of_mem hi) + have hsupu : ∀ i ∈ u, (r i).HasSupportLE (s i) := fun i hi => hsup i (Finset.mem_cons_of_mem hi) + have hsupU : (∑ i ∈ u, r i).HasSupportLE (∑ i ∈ u, s i) := by + simpa only [one_smul] using + hasSupportLE_sum_smul (w := fun _ => (1 : ℝ)) u hsu hsupu fun i _ => zero_le_one + calc quantumRelativeEntropy (r a + ∑ i ∈ u, r i) (s a + ∑ i ∈ u, s i) + ≤ quantumRelativeEntropy (r a) (s a) + + quantumRelativeEntropy (∑ i ∈ u, r i) (∑ i ∈ u, s i) := + quantumRelativeEntropy_subadditive_of_hasSupportLE (hr a (Finset.mem_cons_self a u)) + (isPositive_sum u hru) (hs a (Finset.mem_cons_self a u)) (isPositive_sum u hsu) + (hsup a (Finset.mem_cons_self a u)) hsupU + _ ≤ quantumRelativeEntropy (r a) (s a) + ∑ i ∈ u, quantumRelativeEntropy (r i) (s i) := by + have := ih hru hsu hsupu; linarith + +/-- **Mixture bound for the generalized relative entropy for positive operators** (N&C Problem +11.2(4), eq. (11.134), faithful form). For positive families `r, s` on the finite branch +`(r i).HasSupportLE (s i)`, positive weights `p, q` (`0 < pᵢ`, `0 < qᵢ`) on a nonempty index +`Finset t`, +`S(∑ᵢ pᵢ • rᵢ ‖ ∑ᵢ qᵢ • sᵢ) ≤ ∑ᵢ pᵢ · S(rᵢ ‖ sᵢ) + ∑ᵢ pᵢ · tr(rᵢ) · log(pᵢ / qᵢ)`, +where `tr(rᵢ)` is `re tr(rᵢ)`. Faithful n-ary subadditivity +(`quantumRelativeEntropy_sum_le_sum_of_hasSupportLE`) applied to the positive `pᵢ • rᵢ`, `qᵢ • sᵢ` +(each `(pᵢ • rᵢ).HasSupportLE (qᵢ • sᵢ)` from `hasSupportLE_smul_smul`) bounds the left-hand side by +`∑ᵢ S(pᵢ • rᵢ ‖ qᵢ • sᵢ)`, and the faithful scaling law +(`quantumRelativeEntropy_smul_smul_of_hasSupportLE`) rewrites each summand. Strengthens +`quantumRelativeEntropy_sum_smul_smul_le` from strict positivity to the full positive-operator +finite branch. As there, the bound needs only `pᵢ, qᵢ > 0`, not the normalization +`∑ pᵢ = ∑ qᵢ = 1`, so this is the stronger positive-weight form. -/ +theorem quantumRelativeEntropy_sum_smul_smul_le_of_hasSupportLE {κ : Type*} {t : Finset κ} + (ht : t.Nonempty) {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} {p q : κ → ℝ} + (hr : ∀ i ∈ t, (r i).IsPositive) (hs : ∀ i ∈ t, (s i).IsPositive) + (hsup : ∀ i ∈ t, (r i).HasSupportLE (s i)) + (hp : ∀ i ∈ t, 0 < p i) (hq : ∀ i ∈ t, 0 < q i) : + quantumRelativeEntropy (∑ i ∈ t, p i • r i) (∑ i ∈ t, q i • s i) ≤ + (∑ i ∈ t, p i * quantumRelativeEntropy (r i) (s i)) + + ∑ i ∈ t, p i * RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) (r i).toLinearMap) * + Real.log (p i / q i) := by + refine (quantumRelativeEntropy_sum_le_sum_of_hasSupportLE ht + (fun i hi => (hr i hi).smul_real_of_nonneg (hp i hi).le) + (fun i hi => (hs i hi).smul_real_of_nonneg (hq i hi).le) + (fun i hi => hasSupportLE_smul_smul (hp i hi).ne' (hq i hi).ne' (hsup i hi))).trans + (le_of_eq ?_) + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i hi => + quantumRelativeEntropy_smul_smul_of_hasSupportLE (hr i hi) (hs i hi) (hsup i hi) + (hp i hi) (hq i hi) + +/-- **The "pretty formula" for the mixture bound, faithful form** (N&C Problem 11.2(4), eq. +(11.135)). When the `rᵢ` are density operators (`re tr(rᵢ) = 1`), the mixture-bound correction term +collapses to the classical relative entropy (Kullback–Leibler divergence) +`Real.relativeEntropy p q = ∑ᵢ pᵢ log(pᵢ / qᵢ)` of the weight distributions: +`S(∑ᵢ pᵢ • rᵢ ‖ ∑ᵢ qᵢ • sᵢ) ≤ ∑ᵢ pᵢ · S(rᵢ ‖ sᵢ) + D(p ‖ q)`, for positive families on the finite +branch `(r i).HasSupportLE (s i)`. Stated over `Finset.univ` of a nonempty `Fintype κ`, matching the +index range of `Real.relativeEntropy`; per-term, `re tr(rᵢ) = 1` and +`log(pᵢ / qᵢ) = log pᵢ − log qᵢ` (`Real.log_div`, valid since `pᵢ, qᵢ > 0`) turn the correction into +`∑ᵢ pᵢ (log pᵢ − log qᵢ)`. Strengthens +`quantumRelativeEntropy_sum_smul_smul_le_relativeEntropy` to the full positive-operator finite +branch. -/ +theorem quantumRelativeEntropy_sum_smul_smul_le_relativeEntropy_of_hasSupportLE {κ : Type*} + [Fintype κ] [Nonempty κ] {r s : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} {p q : κ → ℝ} + (hr : ∀ i, (r i).IsPositive) (hs : ∀ i, (s i).IsPositive) + (hsup : ∀ i, (r i).HasSupportLE (s i)) (hp : ∀ i, 0 < p i) (hq : ∀ i, 0 < q i) + (htr : ∀ i, RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) (r i).toLinearMap) = 1) : + quantumRelativeEntropy (∑ i, p i • r i) (∑ i, q i • s i) ≤ + (∑ i, p i * quantumRelativeEntropy (r i) (s i)) + Real.relativeEntropy p q := by + refine (quantumRelativeEntropy_sum_smul_smul_le_of_hasSupportLE Finset.univ_nonempty + (fun i _ => hr i) (fun i _ => hs i) (fun i _ => hsup i) (fun i _ => hp i) + (fun i _ => hq i)).trans (le_of_eq ?_) + rw [Real.relativeEntropy_eq] + congr 1 + exact Finset.sum_congr rfl fun i _ => by + rw [htr i, mul_one, Real.log_div (hp i).ne' (hq i).ne'] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeometricMeanMaximality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeometricMeanMaximality.lean new file mode 100644 index 0000000000..6af345ce7b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GeometricMeanMaximality.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.GeometricMean +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.ConjSqrt +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Order +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchurComplement +public import Mathlib.Analysis.InnerProductSpace.StarOrder +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousLinearMap +public import LeanPool.AxQM.ToMathlib.Topology.Algebra.Module.FiniteDimension + +/-! +# Maximality and joint concavity of the operator geometric mean + +For strictly positive operators `A, B` on a finite-dimensional complex inner product space, +the operator geometric mean `M₀(A, B) := A^{1/2} (A^{-1/2} B A^{-1/2})^{1/2} A^{1/2}` is the +**largest** self-adjoint operator `X` satisfying the block-PSD condition `[[A, X], [X, B]] ≥ 0`. +This file proves the two halves of maximality, and derives joint concavity of `M₀` as a +consequence. + +## Main results + +* `CFC.geometricMean_block_quadForm_nonneg` — `M₀(A, B)` is in the witness set: the block + quadratic form `⟨x, Ax⟩ + ⟨x, M₀ y⟩ + ⟨y, M₀ x⟩ + ⟨y, By⟩ ≥ 0` for all `x, y`. +* `CFC.le_geometricMean_of_block_quadForm_nonneg` — every `X` in the witness set is bounded + above by `M₀(A, B)`. +* `CFC.geometricMean_concave` — `(A, B) ↦ M₀(A, B)` is jointly operator-concave on strictly + positive × nonneg operators (consequence of maximality + convexity of the witness set). +-/ + +namespace CFC + +open Ring RCLike + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +@[expose] public section Maximality + +/-- **Membership**: for strictly positive `A` and nonnegative `B`, the geometric mean +`M₀(A, B)` is in the witness set, i.e., the block `[[A, M₀], [M₀, B]]` is positive semidefinite +as a quadratic form on `E × E`. Carlen Theorem 3.7 first half. -/ +theorem geometricMean_block_quadForm_nonneg + {A B : E →L[ℂ] E} (hA : IsStrictlyPositive A) (hB : 0 ≤ B) (x y : E) : + 0 ≤ re (inner ℂ x (A x) + inner ℂ x ((geometricMean A B) y) + + inner ℂ y ((geometricMean A B) x) + inner ℂ y (B y)) := by + -- Block quadratic form equals `⟨v, v⟩` for `v := √A x + √(conjSqrt A⁻¹ B) (√A y)`, + -- after pushing self-adjoints across via `IsSymmetric.apply_clm` and using + -- `√A · conjSqrt A⁻¹ B · √A = B` (the `conjSqrt` round-trip). + have hZ : 0 ≤ conjSqrt (Ring.inverse A) B := conjSqrt_nonneg _ hB + have hAA (u : E) : sqrt A (sqrt A u) = A u := + DFunLike.congr_fun (sqrt_mul_sqrt_self A hA.nonneg) u + have hBB (u : E) : sqrt A (sqrt (conjSqrt (Ring.inverse A) B) + (sqrt (conjSqrt (Ring.inverse A) B) (sqrt A u))) = B u := + DFunLike.congr_fun + ((sqrt_mul_sqrt_self _ hZ).symm ▸ conjSqrt_conjSqrt_ringInverse A B hA) u + suffices h : inner ℂ x (A x) + inner ℂ x ((geometricMean A B) y) + + inner ℂ y ((geometricMean A B) x) + inner ℂ y (B y) = + inner ℂ (sqrt A x + sqrt (conjSqrt (Ring.inverse A) B) (sqrt A y)) + (sqrt A x + sqrt (conjSqrt (Ring.inverse A) B) (sqrt A y)) by + rw [h]; exact inner_self_nonneg + simp only [inner_add_left, inner_add_right, + (sqrt_nonneg A).isSelfAdjoint.isSymmetric.apply_clm, + (sqrt_nonneg (conjSqrt (Ring.inverse A) B)).isSelfAdjoint.isSymmetric.apply_clm, + geometricMean_eq_mul, mul_apply_eq_comp, hAA, hBB] + ring + +variable [FiniteDimensional ℂ E] + +/-- **Le-direction (maximality)**: every `X` in the block-PSD witness set is bounded above by +`M₀(A, B)`. Together with `geometricMean_block_quadForm_nonneg`, this is Carlen Theorem 3.7. + +The argument: rewrite `X = conjSqrt A (conjSqrt A⁻¹ X)` (`conjSqrt` round-trip), then apply +`conjSqrt`-monotonicity twice — once with the abs-detour `Y ≤ √(Y²)`, once with the conjugated +Schur bound `(conjSqrt A⁻¹ X)² = conjSqrt A⁻¹ (X · A⁻¹ · X) ≤ conjSqrt A⁻¹ B`. -/ +theorem le_geometricMean_of_block_quadForm_nonneg + {A B X : E →L[ℂ] E} (hA : IsStrictlyPositive A) (hB : 0 ≤ B) (hX : IsSelfAdjoint X) + (h_block : ∀ x y : E, + 0 ≤ re (inner ℂ x (A x) + inner ℂ x (X y) + inner ℂ y (X x) + inner ℂ y (B y))) : + X ≤ geometricMean A B := + calc X + = conjSqrt A (conjSqrt (Ring.inverse A) X) := (conjSqrt_conjSqrt_ringInverse A X hA).symm + _ ≤ conjSqrt A (sqrt (conjSqrt (Ring.inverse A) B)) := by + refine conjSqrt_monotone (CFC.le_sqrt_of_mul_self_le + (hX.conjugate_self (sqrt_nonneg _).isSelfAdjoint) ?_) + rw [CFC.conjSqrt_mul_self (Ring.inverse A) X hA.ringInverse.nonneg] + exact conjSqrt_monotone (sub_nonneg.mp + (ContinuousLinearMap.schurComplement_nonneg_of_block_quadForm_nonneg + hA.isUnit hA.isSelfAdjoint hX hB.isSelfAdjoint h_block)) + _ = geometricMean A B := (geometricMean_def A B).symm + +/-- **Joint operator concavity** of the geometric mean. For strictly positive `A₁, A₂` and +nonneg `B₁, B₂`, and `t, s : ℝ` with `0 ≤ t`, `0 ≤ s`, `t + s = 1`: +`t • M₀(A₁, B₁) + s • M₀(A₂, B₂) ≤ M₀(t • A₁ + s • A₂, t • B₁ + s • B₂)`. + +Proof via maximality: `t • M₀(A₁, B₁) + s • M₀(A₂, B₂)` is in the block-PSD witness set for +the convex-combined `(t • A₁ + s • A₂, t • B₁ + s • B₂)` (linear combination of nonneg block +quadratic forms is nonneg); the le-direction `le_geometricMean_of_block_quadForm_nonneg` +discharges. -/ +theorem geometricMean_concave + {A₁ A₂ B₁ B₂ : E →L[ℂ] E} (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) + (hB₁ : 0 ≤ B₁) (hB₂ : 0 ≤ B₂) {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + t • geometricMean A₁ B₁ + s • geometricMean A₂ B₂ ≤ + geometricMean (t • A₁ + s • A₂) (t • B₁ + s • B₂) := by + refine le_geometricMean_of_block_quadForm_nonneg ?_ ?_ ?_ fun x y ↦ ?_ + · -- `t • A₁ + s • A₂` strictly positive: convex combination of strictly positives. + exact convex_isStrictlyPositive hA₁ hA₂ ht hs hts + · -- `t • B₁ + s • B₂` nonneg: nonneg + nonneg scaled by nonneg. + exact add_nonneg (smul_nonneg ht hB₁) (smul_nonneg hs hB₂) + · -- `t • M₀(A₁, B₁) + s • M₀(A₂, B₂)` self-adjoint: real-smul + sum of self-adjoints. + exact ((IsSelfAdjoint.all t).smul (geometricMean_nonneg A₁ B₁).isSelfAdjoint).add + ((IsSelfAdjoint.all s).smul (geometricMean_nonneg A₂ B₂).isSelfAdjoint) + -- Block-quadratic form: linear combination of the two β.2 membership hypotheses. + have h₁ := geometricMean_block_quadForm_nonneg hA₁ hB₁ x y + have h₂ := geometricMean_block_quadForm_nonneg hA₂ hB₂ x y + -- `T ↦ re ⟨z, T w⟩` is ℝ-linear in T (used 4× below). + have key : ∀ (T₁ T₂ : E →L[ℂ] E) (z w : E), + re (inner ℂ z ((t • T₁ + s • T₂) w)) = + t * re (inner ℂ z (T₁ w)) + s * re (inner ℂ z (T₂ w)) := fun T₁ T₂ z w ↦ by + change re (inner ℂ z ((t : ℂ) • T₁ w + (s : ℂ) • T₂ w)) = _ + rw [inner_add_right, map_add, inner_smul_right, inner_smul_right, mul_re, mul_re] + simp + rw [map_add, map_add, map_add] at h₁ h₂ + rw [map_add, map_add, map_add, key, key, key, key] + nlinarith [mul_nonneg ht h₁, mul_nonneg hs h₂] + +/-- **Monotonicity of the operator geometric mean**. For strictly positive `A ≤ A'` and +nonneg `B ≤ B'`, `M₀(A, B) ≤ M₀(A', B')`. Proof via maximality: `M₀(A, B)` is in the block-PSD +witness set for `(A, B)` (by `geometricMean_block_quadForm_nonneg`), and adding the nonneg +differences `re ⟨x, (A'-A)x⟩` and `re ⟨y, (B'-B)y⟩` keeps the block form nonneg at `(A', B')`; +`le_geometricMean_of_block_quadForm_nonneg` discharges. -/ +theorem geometricMean_mono + {A A' B B' : E →L[ℂ] E} (hA : IsStrictlyPositive A) (hA' : IsStrictlyPositive A') + (hB : 0 ≤ B) (hB' : 0 ≤ B') (hAA' : A ≤ A') (hBB' : B ≤ B') : + geometricMean A B ≤ geometricMean A' B' := by + refine le_geometricMean_of_block_quadForm_nonneg hA' hB' + (geometricMean_nonneg A B).isSelfAdjoint fun x y ↦ ?_ + have hAdiff : (A' - A).IsPositive := + ContinuousLinearMap.nonneg_iff_isPositive.mp (sub_nonneg.mpr hAA') + have hBdiff : (B' - B).IsPositive := + ContinuousLinearMap.nonneg_iff_isPositive.mp (sub_nonneg.mpr hBB') + have hA_eq : A' = A + (A' - A) := (add_sub_cancel A A').symm + have hB_eq : B' = B + (B' - B) := (add_sub_cancel B B').symm + have h_base := geometricMean_block_quadForm_nonneg hA hB x y + rw [map_add, map_add, map_add] at h_base + conv_rhs => + rw [hA_eq, hB_eq, add_apply, add_apply, + inner_add_right, inner_add_right, map_add, map_add, map_add, map_add, map_add] + linarith [hAdiff.re_inner_nonneg_right x, hBdiff.re_inner_nonneg_right y] + +end Maximality + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramMatrix.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramMatrix.lean new file mode 100644 index 0000000000..dfbedd7726 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramMatrix.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.GramMatrix +public import Mathlib.LinearAlgebra.Matrix.Rank + +/-! +# Additional facts about Gram matrices + +Congruence of the Gram matrix under a linear recombination of the family, and a bound on its +rank by the dimension of the ambient space. +-/ + +open RCLike Real Matrix + +open scoped InnerProductSpace ComplexOrder ComplexConjugate + +@[expose] public section + +variable {E n α 𝕜 : Type*} + +namespace Matrix + +variable [RCLike 𝕜] + +section SemiInnerProductSpace + +variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **The Gram matrix transforms by congruence under a linear recombination of the family.** If a +new family `wⱼ = ∑ᵢ Mᵢⱼ • vᵢ` is formed by recombining `v : n → E` with the columns of a matrix +`M : Matrix n m 𝕜`, its Gram matrix is `Mᴴ * gram 𝕜 v * M`. Immediate from the sesquilinearity of +the inner product; the `Mᴴ` on the left carries the conjugate coming from the first slot. -/ +theorem gram_smul_sum [Fintype n] {m : Type*} (M : Matrix n m 𝕜) (v : n → E) : + gram 𝕜 (fun j => ∑ i, M i j • v i) = Mᴴ * gram 𝕜 v * M := by + ext j k + simp only [gram_apply, sum_inner, inner_sum, inner_smul_left, inner_smul_right, + Matrix.mul_apply, Matrix.conjTranspose_apply, RCLike.star_def, Finset.sum_mul, Finset.mul_sum, + mul_assoc] + refine Finset.sum_congr rfl fun x _ => Finset.sum_congr rfl fun y _ => ?_ + ring + +end SemiInnerProductSpace + +section NormedInnerProductSpace + +variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **The rank of a Gram matrix is at most the dimension of the ambient space.** For a finite family +`v : n → E` in a finite-dimensional inner product space `E`, `rank (gram 𝕜 v) ≤ dim E`. + +Writing `gram 𝕜 v = mᴴ * m` for the coordinate matrix `m` of `v` in an orthonormal basis +(`gram_eq_conjTranspose_mul`), `rank (mᴴ * m) ≤ rank m` (`rank_mul_le_right`), and `rank m` is at +most its number of rows, `dim E`. -/ +theorem rank_gram_le [FiniteDimensional 𝕜 E] [Finite n] (v : n → E) : + (gram 𝕜 v).eRank.toNat ≤ Module.finrank 𝕜 E := by + classical + let := Fintype.ofFinite n + rw [eRank_toNat_eq_rank] + let b := stdOrthonormalBasis 𝕜 E + rw [gram_eq_conjTranspose_mul b v] + refine (rank_mul_le_right _ _).trans ?_ + refine (rank_le_card_height _).trans_eq ?_ + exact (Module.finrank_eq_card_basis b.toBasis).symm + +end NormedInnerProductSpace + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramSquareRoot.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramSquareRoot.lean new file mode 100644 index 0000000000..4829c5280b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/GramSquareRoot.lean @@ -0,0 +1,290 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedInverseSqrt +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Commute + +/-! +# The square root of a Gram operator via the generalized inverse square root + +For a continuous linear map `V : F →L[ℂ] G` between finite-dimensional complex Hilbert spaces, with +total operator `S = V ∘ V⋆` on `G` and Gram operator `Γ = V⋆ ∘ V` on `F`, this file proves the +**Gram square-root identity** + +`V⋆ · S^(-1/2) · V = √Γ` (`√Γ = cfc Real.sqrt Γ`, `S^(-1/2) = S.genInvSqrt`), + +i.e. conjugating the generalized inverse square root of `S = V V⋆` by `V` yields the *ordinary* +operator square root of the Gram operator `Γ = V⋆ V`. + +## Motivation + +This is the operator content of **Nielsen & Chuang's Box 12.5**, the achievability half of the +**Holevo–Schumacher–Westmoreland theorem** (`χ(E) = C⁽¹⁾(E)`, N&C Theorem 12.8). There the columns +of `V` are the typical-subspace–compressed codeword eigenvectors `|E_tilde_c⟩ = P |E^M_K⟩` +(indexed by +`c = (M, K)` with `K` in the conditional-typical set), so `Γ` is their Gram matrix +`γ_{c,c'} = ⟨E_tilde_c | E_tilde_{c'}⟩` and `S = ∑_M P Pₘ P` is the total operator of the +pretty-good decoder. +The coefficients `α_{c,c'} = ⟨E_tilde_c | S^(-1/2) | E_tilde_{c'}⟩` that N&C introduce between +eqs. (12.85) and +(12.86) are exactly the entries of the operator `V⋆ · S^(-1/2) · V`, and their identity `α = +Γ^{1/2}` +— the hinge that makes the diagonal decoding overlap `α_{c,c}` bounded by `1`, so the square-root +operator inequality (12.89)–(12.91) controls the decoding error — is precisely the theorem below. + +## What this file provides + +* `ContinuousLinearMap.genInvSqrt_mul_self_mul_genInvSqrt_mul_self` — the **support-projection + identity** `A^(-1/2) · A · A^(-1/2) · A = A` for `0 ≤ A`: the support projection of `A` fixes `A`. +* `ContinuousLinearMap.genInvSqrt_supportProj_comp_self` — `S^(-1/2) · S · S^(-1/2) · V = V` for + `S = V ∘ V⋆`: the support projection of `S = V V⋆` fixes the range of `V`. +* `ContinuousLinearMap.adjoint_comp_genInvSqrt_comp_self_mul_self` — `α² = Γ`, i.e. + `(V⋆ · S^(-1/2) · V) · (V⋆ · S^(-1/2) · V) = V⋆ · V`. +* `ContinuousLinearMap.adjoint_comp_genInvSqrt_comp_self` — the **Gram square-root identity** + `V⋆ · S^(-1/2) · V = √(V⋆ · V)`. + +## Proof + +Writing `α = V⋆ · S^(-1/2) · V`, positivity of `α` is the conjugation of the positive `S^(-1/2)` +by `V`. +For `α² = Γ`: the support projection `P = S^(-1/2) · S · S^(-1/2)` of the positive `S` fixes the +range of +`V` (`P · V = V`), because the "defect" `W = (1 - P) · V` has `W · W⋆ = (1 - P) · S · (1 - P) = 0` +(as `(1 - P) · S = 0`, folding the triple product of functional-calculus images to +`cfc (x ↦ (√x)⁻¹ · x · (√x)⁻¹ · x) S = cfc id S = S`), hence `W = 0`. Then + +`α² = V⋆ · S^(-1/2) · (V · V⋆) · S^(-1/2) · V = V⋆ · (S^(-1/2) · S · S^(-1/2)) · V = V⋆ · P · V = +V⋆ · V = Γ`. + +Finally, a positive operator with square `Γ` is the operator square root of `Γ`: `α = √Γ` by +`cfc_real_sqrt_mul_self_eq_self_of_nonneg` (`0 ≤ α ⟹ √(α · α) = α`). + +-/ + +@[expose] public section + +open scoped ComplexOrder + +noncomputable section + +namespace ContinuousLinearMap + +variable {E F G : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + [CompleteSpace F] [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] + [CompleteSpace G] + +/-- **The support projection of a positive operator fixes the operator.** For `A ≥ 0`, + +`A^(-1/2) · A · A^(-1/2) · A = A`, + +where `A^(-1/2) = A.genInvSqrt`. The composite `A^(-1/2) · A · A^(-1/2)` is the orthogonal +projection onto +the range of `A`, which acts as the identity on `A`. Proved by folding the four functional-calculus +images of `A` to a single `cfc` whose symbol `(√x)⁻¹ · x · (√x)⁻¹ · x` equals `x` on the +(nonnegative) spectrum. -/ +theorem genInvSqrt_mul_self_mul_genInvSqrt_mul_self {A : E →L[ℂ] E} (hA : 0 ≤ A) : + A.genInvSqrt * A * A.genInvSqrt * A = A := by + have hsa : IsSelfAdjoint A := hA.isSelfAdjoint + have hc : ∀ f : ℝ → ℝ, ContinuousOn f (spectrum ℝ A) := fun f => hsa.continuousOn_spectrum f + have hfold : A.genInvSqrt * A * A.genInvSqrt * A + = cfc (fun x => (Real.sqrt x)⁻¹ * x * (Real.sqrt x)⁻¹ * x) A := by + have hmid : A.genInvSqrt * A * A.genInvSqrt * A + = cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A * cfc (id : ℝ → ℝ) A + * cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A * cfc (id : ℝ → ℝ) A := by + rw [cfc_id ℝ A]; rfl + rw [hmid, ← cfc_mul _ _ A (hc _) (hc _), ← cfc_mul _ _ A (hc _) (hc _), + ← cfc_mul _ _ A (hc _) (hc _)] + simp only [id_eq] + rw [hfold] + conv_rhs => rw [← cfc_id ℝ A] + refine cfc_congr (fun x hx => ?_) + have hx0 : 0 ≤ x := spectrum_nonneg_of_nonneg hA hx + rcases eq_or_lt_of_le hx0 with h | h + · simp [← h] + · rw [id_eq] + have hxx : Real.sqrt x * Real.sqrt x = x := Real.mul_self_sqrt hx0 + have hsx : Real.sqrt x ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr h) + field_simp + nlinarith [hxx, Real.sq_sqrt hx0] + +/-- **The support projection of a positive operator fixes its generalized inverse square root.** +For `A ≥ 0`, + +`A^(-1/2) · (A^(-1/2) · A · A^(-1/2)) = A^(-1/2)`, + +where `A^(-1/2) = A.genInvSqrt` and the composite `A^(-1/2) · A · A^(-1/2)` is the orthogonal +projection onto +the range of `A`. The left-of-`A^(-1/2)` companion of `genInvSqrt_mul_self_mul_genInvSqrt_mul_self` +(which fixes `A` instead): the support projection acts as the identity on `A^(-1/2)`. Proved by +folding the four functional-calculus images of `A` to a single `cfc` whose symbol +`(√x)⁻¹ · (√x)⁻¹ · x · (√x)⁻¹` equals `(√x)⁻¹` on the (nonnegative) spectrum. -/ +theorem genInvSqrt_mul_genInvSqrt_mul_self_mul_genInvSqrt {A : E →L[ℂ] E} (hA : 0 ≤ A) : + A.genInvSqrt * (A.genInvSqrt * A * A.genInvSqrt) = A.genInvSqrt := by + have hsa : IsSelfAdjoint A := hA.isSelfAdjoint + have hc : ∀ f : ℝ → ℝ, ContinuousOn f (spectrum ℝ A) := fun f => hsa.continuousOn_spectrum f + have hmid : A.genInvSqrt * (A.genInvSqrt * A * A.genInvSqrt) + = cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A * cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A + * cfc (id : ℝ → ℝ) A * cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A := by + rw [cfc_id ℝ A]; rfl + rw [hmid, ← cfc_mul _ _ A (hc _) (hc _), ← cfc_mul _ _ A (hc _) (hc _), + ← cfc_mul _ _ A (hc _) (hc _)] + simp only [id_eq] + conv_rhs => rw [show A.genInvSqrt = cfc (fun x : ℝ => (Real.sqrt x)⁻¹) A from rfl] + refine cfc_congr (fun x hx => ?_) + have hx0 : 0 ≤ x := spectrum_nonneg_of_nonneg hA hx + rcases eq_or_lt_of_le hx0 with h | h + · simp [← h] + · have hxx : Real.sqrt x * Real.sqrt x = x := Real.mul_self_sqrt hx0 + have hsx : Real.sqrt x ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr h) + field_simp + nlinarith [hxx, Real.sq_sqrt hx0] + +omit [FiniteDimensional ℂ F] in +/-- **The support projection of `S = V V⋆` fixes the range of `V`.** For `V : F →L[ℂ] G` with +`S = V ∘ V⋆`, + +`S^(-1/2) · S · S^(-1/2) · V = V`. + +The support projection `P = S^(-1/2) · S · S^(-1/2)` of `S` projects onto the range of `S = V V⋆`, +which +is the range of `V`; hence `P` fixes `V`. Concretely, the defect `W = (1 - P) · V` satisfies +`W · W⋆ = (1 - P) · S · (1 - P) = 0` (since `(1 - P) · S = 0` by +`genInvSqrt_mul_self_mul_genInvSqrt_mul_self`), so `W = 0`. -/ +theorem genInvSqrt_supportProj_comp_self (V : F →L[ℂ] G) : + ((V.comp (adjoint V)).genInvSqrt * (V.comp (adjoint V)) * + (V.comp (adjoint V)).genInvSqrt).comp V = V := by + set S := V.comp (adjoint V) with hS + have hSnn : 0 ≤ S := nonneg_iff_isPositive.mpr (isPositive_self_comp_adjoint V) + set P := S.genInvSqrt * S * S.genInvSqrt with hP + have h1V : (1 : G →L[ℂ] G).comp V = V := by ext x; simp + -- `P` is self-adjoint (conjugation of the self-adjoint `S` by the self-adjoint `S^(-1/2)`). + have hPsa : IsSelfAdjoint P := by + rw [hP] + simpa [(isSelfAdjoint_genInvSqrt hSnn).star_eq] using hSnn.isSelfAdjoint.conjugate S.genInvSqrt + have hadj1P : adjoint ((1 : G →L[ℂ] G) - P) = 1 - P := by + rw [← star_eq_adjoint, star_sub, star_one, hPsa.star_eq] + -- `(1 - P) · S = 0` from the support-projection identity `P · S = S`. + have hPS : P * S = S := by rw [hP]; exact genInvSqrt_mul_self_mul_genInvSqrt_mul_self hSnn + have h1PS : (1 - P) * S = 0 := by rw [sub_mul, one_mul, hPS, sub_self] + -- The defect `W = (1 - P) · V` satisfies `W · W⋆ = (1 - P) · S · (1 - P) = 0`, hence `W = 0`. + set W := ((1 : G →L[ℂ] G) - P).comp V with hW + have hWadj : adjoint W = (adjoint V).comp (1 - P) := by + rw [hW, adjoint_comp, hadj1P] + have hWW : W.comp (adjoint W) = 0 := by + have e1 : W.comp (adjoint W) = (1 - P).comp (S.comp (1 - P)) := by + rw [hW, hWadj, comp_assoc, ← comp_assoc V (adjoint V) (1 - P), ← hS] + rw [e1, show (1 - P).comp (S.comp (1 - P)) = ((1 - P) * S) * (1 - P) by rw [← comp_assoc]; rfl, + h1PS, zero_mul] + have hW0 : W = 0 := by + have hadjW : adjoint W = 0 := + (adjoint_comp_self_eq_zero_iff (A := adjoint W)).mp (by rw [adjoint_adjoint]; exact hWW) + rw [← adjoint_adjoint W, hadjW, map_zero] + -- `(1 - P) · V = 0` unfolds to `P · V = V`. + have hfin : ((1 : G →L[ℂ] G) - P).comp V = 0 := hW0 + rw [sub_comp, h1V, sub_eq_zero] at hfin + exact hfin.symm + +omit [FiniteDimensional ℂ F] in +/-- **The conjugated generalized inverse square root squares to the Gram operator** (`α² = Γ`). For +`V : F →L[ℂ] G` with `S = V ∘ V⋆` and `α = V⋆ · S^(-1/2) · V`, + +`α · α = V⋆ · V`. + +This is the algebraic heart of N&C's `α = Γ^{1/2}` (Box 12.5): expanding `α²` collapses the middle +`S^(-1/2) · (V V⋆) · S^(-1/2) = S^(-1/2) · S · S^(-1/2)` to the support projection of `S`, which +fixes `V` +(`genInvSqrt_supportProj_comp_self`), leaving `V⋆ · V`. -/ +theorem adjoint_comp_genInvSqrt_comp_self_mul_self (V : F →L[ℂ] G) : + ((adjoint V).comp (((V.comp (adjoint V)).genInvSqrt).comp V)) + * ((adjoint V).comp (((V.comp (adjoint V)).genInvSqrt).comp V)) + = (adjoint V).comp V := by + set S := V.comp (adjoint V) with hS + have hkey := genInvSqrt_supportProj_comp_self V + rw [← hS] at hkey + rw [ContinuousLinearMap.mul_def] + have hrw : ((adjoint V).comp (S.genInvSqrt.comp V)).comp ((adjoint V).comp (S.genInvSqrt.comp V)) + = (adjoint V).comp ((S.genInvSqrt * S * S.genInvSqrt).comp V) := by + simp only [ContinuousLinearMap.comp_assoc, ContinuousLinearMap.mul_def] + rw [← comp_assoc V (adjoint V) (S.genInvSqrt.comp V), ← hS] + rw [hrw, hkey] + +omit [FiniteDimensional ℂ F] in +/-- **The Gram square-root identity** (Nielsen & Chuang, Box 12.5, the identity `α = Γ^{1/2}` +between eqs. (12.85) and (12.86)). For `V : F →L[ℂ] G` with total operator `S = V ∘ V⋆` on `G` +and Gram operator `Γ = V⋆ ∘ V` on `F`, + +`V⋆ · S^(-1/2) · V = √Γ`, + +where `S^(-1/2) = S.genInvSqrt` is the generalized inverse square root and `√Γ = cfc Real.sqrt Γ` is +the ordinary operator square root. Conjugating the generalized inverse square root of `S = V V⋆` by +`V` yields the operator square root of the Gram operator `Γ = V⋆ V`. + +The operator `α = V⋆ · S^(-1/2) · V` is positive (a conjugation of the positive `S^(-1/2)`) and +squares to +`Γ` (`adjoint_comp_genInvSqrt_comp_self_mul_self`); a positive operator with square `Γ` is the +operator square root of `Γ`, so `α = √Γ` (`cfc_real_sqrt_mul_self_eq_self_of_nonneg`). -/ +theorem adjoint_comp_genInvSqrt_comp_self (V : F →L[ℂ] G) : + (adjoint V).comp (((V.comp (adjoint V)).genInvSqrt).comp V) + = cfc Real.sqrt ((adjoint V).comp V) := by + have hSnn : 0 ≤ V.comp (adjoint V) := + nonneg_iff_isPositive.mpr (isPositive_self_comp_adjoint V) + -- `α = V⋆ · S^(-1/2) · V` is positive: a conjugation of the positive `S^(-1/2)` by `V`. + have hαnn : 0 ≤ (adjoint V).comp (((V.comp (adjoint V)).genInvSqrt).comp V) := by + have h := (nonneg_iff_isPositive.mp (genInvSqrt_nonneg hSnn)).conj_adjoint (adjoint V) + rw [adjoint_adjoint] at h + exact nonneg_iff_isPositive.mpr h + -- `α` is positive with `α · α = Γ`, so `α = √Γ` (`cfc_real_sqrt_mul_self_eq_self_of_nonneg`). + rw [← adjoint_comp_genInvSqrt_comp_self_mul_self V] + exact (cfc_real_sqrt_mul_self_eq_self_of_nonneg hαnn).symm + +/-- **A projection fixing a positive operator also fixes its generalized inverse square root.** For +`A ≥ 0` and an operator `P` that fixes `A` on both sides (`A · P = A` and `P · A = A` — e.g. `P` the +orthogonal projection onto a subspace containing the range of `A`, or any `A = P · B · P`), + +`A^(-1/2) · P = A^(-1/2)`, + +where `A^(-1/2) = A.genInvSqrt`. Since `A^(-1/2) = cfc (√·)⁻¹ A` is a functional-calculus image +of `A`, +it inherits the support of `A`; the hypotheses say `P` is the identity there, so `P` is absorbed. + +Concretely, `P` commutes with `A^(-1/2)` (as it commutes with `A`, `Commute.cfc_real`), and the +support +projection `Π = A^(-1/2) · A · A^(-1/2)` of `A` absorbs `P` on the right (`Π · P = Π`, moving `P` +past +`A^(-1/2)` by commutation and using `A · P = A`); since `A^(-1/2) · Π = A^(-1/2)` +(`genInvSqrt_mul_genInvSqrt_mul_self_mul_genInvSqrt`), `A^(-1/2) · P = A^(-1/2) · Π · P = A^(-1/2) +· Π += A^(-1/2)`. -/ +theorem genInvSqrt_mul_of_mul_eq_self {A : E →L[ℂ] E} (hA : 0 ≤ A) {P : E →L[ℂ] E} + (hAP : A * P = A) (hPA : P * A = A) : + A.genInvSqrt * P = A.genInvSqrt := by + -- The support projection `Π = A^(-1/2) · A · A^(-1/2)` of `A` fixes `A^(-1/2)`: `A^(-1/2) · Π + -- = A^(-1/2)`. + have hB := genInvSqrt_mul_genInvSqrt_mul_self_mul_genInvSqrt hA + -- `P` commutes with `A^(-1/2) = cfc (√·)⁻¹ A` because it commutes with `A`. + have hcomm : Commute A P := hAP.trans hPA.symm + have hcommG : A.genInvSqrt * P = P * A.genInvSqrt := + Commute.cfc_real hcomm (fun x : ℝ => (Real.sqrt x)⁻¹) + -- The support projection absorbs `P` on the right: `Π · P = Π`. + have hsuppP : (A.genInvSqrt * A * A.genInvSqrt) * P = A.genInvSqrt * A * A.genInvSqrt := by + calc (A.genInvSqrt * A * A.genInvSqrt) * P + = A.genInvSqrt * A * (A.genInvSqrt * P) := by rw [mul_assoc] + _ = A.genInvSqrt * A * (P * A.genInvSqrt) := by rw [hcommG] + _ = A.genInvSqrt * (A * P) * A.genInvSqrt := by rw [mul_assoc, mul_assoc, mul_assoc] + _ = A.genInvSqrt * A * A.genInvSqrt := by rw [hAP] + calc A.genInvSqrt * P + = (A.genInvSqrt * (A.genInvSqrt * A * A.genInvSqrt)) * P := by rw [hB] + _ = A.genInvSqrt * ((A.genInvSqrt * A * A.genInvSqrt) * P) := by rw [mul_assoc] + _ = A.genInvSqrt * (A.genInvSqrt * A * A.genInvSqrt) := by rw [hsuppP] + _ = A.genInvSqrt := hB + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/HSPairing.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/HSPairing.lean new file mode 100644 index 0000000000..a10d5a0c99 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/HSPairing.lean @@ -0,0 +1,374 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import TauCeti.Analysis.InnerProductSpace.Trace.Free +public import LeanPool.AxQM.ToMathlib.Topology.Algebra.Module.FiniteDimension + +/-! +# Hilbert–Schmidt pairing of linear maps + +For two linear maps `T, U : E →ₗ[𝕜] F` between finite-dimensional inner product spaces over +`𝕜` (where `𝕜` is `ℝ` or `ℂ`), the **Hilbert–Schmidt pairing** is + +`hsPairing T U := trace (U† ∘ T)` + +where `U†` is the (finite-dimensional) adjoint of `U`. This is the bilinear (sesquilinear) +form underlying the Hilbert–Schmidt inner product on operators. + +The existing `HilbertSchmidt.hsInner` provides the same pairing on the bundled +`HilbertSchmidt 𝕜 E` type of endomorphisms; this file gives the unbundled function form for +general `E →ₗ[𝕜] F` so that the variational characterization of the trace norm +(`traceNorm T = ⨆_{‖W‖_op ≤ 1} re (hsPairing T W)`) can be stated cleanly at the LM/CLM +level without committing to the bundled type. + +## Main definitions + +- `LinearMap.hsPairing` — the function `(T, U) ↦ trace (U† ∘ T)`. +- `ContinuousLinearMap.hsPairing` — the CLM sibling. + +## Main results + +- `hsPairing_add_left` / `_right`, `hsPairing_sub_left` / `_right`, + `hsPairing_neg_left` / `_right`, `hsPairing_smul_left` / `_right`, + `hsPairing_zero_left` / `_right`: bilinearity (sesquilinear in the right slot). +- `hsPairing_conj`: conjugate symmetry `star (hsPairing T U) = hsPairing U T`. +- `hsPairing_self_star_eq_self`: the self-pairing `hsPairing T T` is fixed by `star` + (equivalently, real-valued). +- `hsPairing_comp_left` / `_right`: the "move-adjoint" identities for compositions. +- `re_hsPairing_self_eq_sum_norm_sq`: the basis-sum form of the HS-norm squared, + `re (hsPairing T T) = ∑ ‖T (b i)‖²`. +- `re_hsPairing_self_eq_re_trace_comp_self_of_isSymmetric` (LM) / + `re_hsPairing_self_eq_re_trace_sq_of_isSelfAdjoint` (CLM): for a symmetric/self-adjoint + endomorphism, the HS self-pairing reduces to the trace of `T ∘ₗ T` (resp. `T * T`). +- `norm_hsPairing_sq_le`: the Cauchy–Schwarz inequality + `‖hsPairing T U‖² ≤ re (hsPairing T T) · re (hsPairing U U)`. +- `re_hsPairing_self_comp_le`: HS-norm sub-multiplicativity, + `re (hsPairing (S ∘ T) (S ∘ T)) ≤ ‖S‖_op² · re (hsPairing T T)`. + +## Implementation notes + +The pairing uses `LinearMap.adjoint` (the finite-dim-specific RCLike-clean definition); no +`[CompleteSpace _]` premises propagate. The CLM sibling defers to the LM version via +`toLinearMap`, mirroring the pattern in `TraceNorm.lean`. +-/ + +@[expose] public section + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The **Hilbert–Schmidt pairing** of two linear maps: `trace (U† ∘ T)`. -/ +noncomputable def hsPairing (T U : E →ₗ[𝕜] F) : 𝕜 := + LinearMap.trace 𝕜 E (U.adjoint ∘ₗ T) + +theorem hsPairing_eq (T U : E →ₗ[𝕜] F) : + T.hsPairing U = LinearMap.trace 𝕜 E (U.adjoint ∘ₗ T) := rfl + +@[simp] +theorem hsPairing_zero_left (U : E →ₗ[𝕜] F) : hsPairing (0 : E →ₗ[𝕜] F) U = 0 := by + simp [hsPairing_eq] + +@[simp] +theorem hsPairing_zero_right (T : E →ₗ[𝕜] F) : T.hsPairing 0 = 0 := by + simp [hsPairing_eq] + +theorem hsPairing_add_left (T T' U : E →ₗ[𝕜] F) : + (T + T').hsPairing U = T.hsPairing U + T'.hsPairing U := by + simp [hsPairing_eq, LinearMap.comp_add, map_add] + +theorem hsPairing_sub_left (T T' U : E →ₗ[𝕜] F) : + (T - T').hsPairing U = T.hsPairing U - T'.hsPairing U := by + simp [hsPairing_eq, LinearMap.comp_sub, map_sub] + +theorem hsPairing_neg_left (T U : E →ₗ[𝕜] F) : + (-T).hsPairing U = - T.hsPairing U := by + simp [hsPairing_eq, LinearMap.comp_neg, map_neg] + +theorem hsPairing_add_right (T U U' : E →ₗ[𝕜] F) : + T.hsPairing (U + U') = T.hsPairing U + T.hsPairing U' := by + simp [hsPairing_eq, map_add, LinearMap.add_comp] + +theorem hsPairing_sub_right (T U U' : E →ₗ[𝕜] F) : + T.hsPairing (U - U') = T.hsPairing U - T.hsPairing U' := by + simp [hsPairing_eq, map_sub, LinearMap.sub_comp] + +theorem hsPairing_neg_right (T U : E →ₗ[𝕜] F) : + T.hsPairing (-U) = - T.hsPairing U := by + simp [hsPairing_eq, map_neg, LinearMap.neg_comp] + +theorem hsPairing_sum_left {ι : Type*} (s : Finset ι) (T : ι → E →ₗ[𝕜] F) + (U : E →ₗ[𝕜] F) : + (∑ i ∈ s, T i).hsPairing U = ∑ i ∈ s, (T i).hsPairing U := by + classical + induction s using Finset.induction with + | empty => simp + | insert i t hi ih => + rw [Finset.sum_insert hi, hsPairing_add_left, ih, Finset.sum_insert hi] + +theorem hsPairing_sum_right {ι : Type*} (T : E →ₗ[𝕜] F) (s : Finset ι) + (U : ι → E →ₗ[𝕜] F) : + T.hsPairing (∑ i ∈ s, U i) = ∑ i ∈ s, T.hsPairing (U i) := by + classical + induction s using Finset.induction with + | empty => simp + | insert i t hi ih => + rw [Finset.sum_insert hi, hsPairing_add_right, ih, Finset.sum_insert hi] + +theorem hsPairing_smul_left (c : 𝕜) (T U : E →ₗ[𝕜] F) : + (c • T).hsPairing U = c * T.hsPairing U := by + simp [hsPairing_eq, LinearMap.comp_smul, map_smul] + +theorem hsPairing_smul_right (c : 𝕜) (T U : E →ₗ[𝕜] F) : + T.hsPairing (c • U) = star c * T.hsPairing U := by + rw [hsPairing_eq, hsPairing_eq, LinearMap.adjoint.map_smulₛₗ, LinearMap.smul_comp, map_smul, + smul_eq_mul, RCLike.star_def] + +/-- **Conjugate symmetry** of the HS pairing: `star (hsPairing T U) = hsPairing U T`. The +proof uses `trace_adjoint` to move the star inside the trace, then `adjoint_comp` + +`adjoint_adjoint` to expand. -/ +theorem hsPairing_conj (T U : E →ₗ[𝕜] F) : + star (T.hsPairing U) = U.hsPairing T := by + rw [hsPairing_eq, hsPairing_eq, RCLike.star_def, ← LinearMap.trace_adjoint, + adjoint_comp, adjoint_adjoint] + +/-- The HS self-pairing `hsPairing T T` is fixed by `star` (equivalently, real-valued). -/ +theorem hsPairing_self_star_eq_self (T : E →ₗ[𝕜] F) : + star (T.hsPairing T) = T.hsPairing T := + hsPairing_conj T T + +section MoveAdjoint +variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + +/-- **Move-adjoint identity, left form**: for `T : E →ₗ[𝕜] F`, `S : F →ₗ[𝕜] G`, +`W : E →ₗ[𝕜] G`, we have `hsPairing (S ∘ₗ T) W = hsPairing T (S.adjoint ∘ₗ W)`. The factor +`S` can be moved from the first slot to the (adjoint of the) second slot. Proof: unfold +`hsPairing`, expand `adjoint (S.adjoint ∘ₗ W)` via `adjoint_comp` + `adjoint_adjoint`, then +collect by `comp_assoc`. -/ +theorem hsPairing_comp_left (T : E →ₗ[𝕜] F) (S : F →ₗ[𝕜] G) (W : E →ₗ[𝕜] G) : + (S ∘ₗ T).hsPairing W = T.hsPairing (S.adjoint ∘ₗ W) := by + rw [hsPairing_eq, hsPairing_eq, LinearMap.adjoint_comp, LinearMap.adjoint_adjoint, + LinearMap.comp_assoc] + +/-- **Move-adjoint identity, right form**: for `T : E →ₗ[𝕜] F`, `S : F →ₗ[𝕜] G`, +`W : E →ₗ[𝕜] G`, we have `hsPairing (S ∘ₗ T) W = hsPairing S (W ∘ₗ T.adjoint)`. The factor +`T` can be moved from the first slot to the (adjoint of the) second slot. Proof: unfold, +expand `adjoint`, then apply `trace_comp_comm'` to swap the trace from `End E` to `End F`. -/ +theorem hsPairing_comp_right (T : E →ₗ[𝕜] F) (S : F →ₗ[𝕜] G) (W : E →ₗ[𝕜] G) : + (S ∘ₗ T).hsPairing W = S.hsPairing (W ∘ₗ T.adjoint) := by + rw [hsPairing_eq, hsPairing_eq, LinearMap.adjoint_comp, LinearMap.adjoint_adjoint] + exact LinearMap.trace_comp_comm' T (LinearMap.adjoint W ∘ₗ S) + +end MoveAdjoint + +/-- The real part of the HS self-pairing `hsPairing T T` is the HS-norm squared: it equals +`∑ ‖T (b i)‖²` over any orthonormal basis. (The expression is basis-independent because +the trace is.) -/ +theorem re_hsPairing_self_eq_sum_norm_sq {ι : Type*} [Fintype ι] + (T : E →ₗ[𝕜] F) (b : OrthonormalBasis ι 𝕜 E) : + RCLike.re (T.hsPairing T) = ∑ i, ‖T (b i)‖ ^ 2 := by + rw [hsPairing_eq, LinearMap.trace_eq_sum_inner _ b, map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [LinearMap.comp_apply, LinearMap.adjoint_inner_right, inner_self_eq_norm_sq] + +/-- For a symmetric endomorphism `T`, the HS self-pairing reduces to the trace of `T ∘ₗ T`: +`re (hsPairing T T) = re (trace (T ∘ₗ T))`. The adjoint in the HS pairing collapses via +`IsSymmetric.adjoint_eq`. -/ +theorem re_hsPairing_self_eq_re_trace_comp_self_of_isSymmetric + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) : + RCLike.re (T.hsPairing T) = RCLike.re (LinearMap.trace 𝕜 E (T ∘ₗ T)) := by + rw [hsPairing_eq, hT.adjoint_eq] + +/-- **HS-norm sub-multiplicativity** in the operator-norm sense: composing on the left by +`S` scales the HS norm of `T` by at most `‖S‖_op`. Stated in terms of the (real-valued, +non-negative) `re hsPairing _ _` form: +`re (hsPairing (S ∘ T) (S ∘ T)) ≤ ‖S‖_op² · re (hsPairing T T)`. -/ +theorem re_hsPairing_self_comp_le {G : Type*} + [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + (S : F →ₗ[𝕜] G) (T : E →ₗ[𝕜] F) : + RCLike.re ((S ∘ₗ T).hsPairing (S ∘ₗ T)) ≤ + ‖S.toContinuousLinearMap‖ ^ 2 * RCLike.re (T.hsPairing T) := by + obtain ⟨b⟩ : Nonempty (OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E) := + ⟨stdOrthonormalBasis 𝕜 E⟩ + rw [re_hsPairing_self_eq_sum_norm_sq _ b, re_hsPairing_self_eq_sum_norm_sq _ b, + Finset.mul_sum] + refine Finset.sum_le_sum fun i _ ↦ ?_ + rw [LinearMap.comp_apply] + calc ‖S (T (b i))‖ ^ 2 + ≤ (‖S.toContinuousLinearMap‖ * ‖T (b i)‖) ^ 2 := by + gcongr + exact S.toContinuousLinearMap.le_opNorm _ + _ = ‖S.toContinuousLinearMap‖ ^ 2 * ‖T (b i)‖ ^ 2 := by ring + +/-- **Cauchy–Schwarz inequality for the HS pairing.** The HS pairing satisfies the usual +inner-product Cauchy–Schwarz bound: `‖hsPairing T U‖² ≤ re (hsPairing T T) · re (hsPairing U U)`. +The right-hand side is the product of the (real-valued, non-negative) HS-norm squares +(`re_hsPairing_self_eq_sum_norm_sq`). Proof: expand the pairings on a basis, bound +`‖hsPairing T U‖` by `∑ ‖U (b i)‖ * ‖T (b i)‖` via the triangle inequality and per-term +`norm_inner_le_norm`, then apply the finset Cauchy–Schwarz `Finset.sum_mul_sq_le_sq_mul_sq`. -/ +theorem norm_hsPairing_sq_le (T U : E →ₗ[𝕜] F) : + ‖T.hsPairing U‖ ^ 2 ≤ RCLike.re (T.hsPairing T) * RCLike.re (U.hsPairing U) := by + obtain ⟨b⟩ : Nonempty (OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E) := + ⟨stdOrthonormalBasis 𝕜 E⟩ + have hTU_norm : ‖T.hsPairing U‖ ≤ ∑ i, ‖U (b i)‖ * ‖T (b i)‖ := by + rw [hsPairing_eq, LinearMap.trace_eq_sum_inner _ b] + refine (norm_sum_le _ _).trans (Finset.sum_le_sum fun i _ ↦ ?_) + rw [LinearMap.comp_apply, LinearMap.adjoint_inner_right] + exact norm_inner_le_norm _ _ + rw [re_hsPairing_self_eq_sum_norm_sq T b, re_hsPairing_self_eq_sum_norm_sq U b] + calc ‖T.hsPairing U‖ ^ 2 + ≤ (∑ i, ‖U (b i)‖ * ‖T (b i)‖) ^ 2 := by gcongr + _ ≤ (∑ i, ‖U (b i)‖ ^ 2) * (∑ i, ‖T (b i)‖ ^ 2) := + Finset.sum_mul_sq_le_sq_mul_sq _ _ _ + _ = (∑ i, ‖T (b i)‖ ^ 2) * (∑ i, ‖U (b i)‖ ^ 2) := mul_comm _ _ + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The HS pairing of two continuous linear maps, defined as the HS pairing of their +underlying linear maps. -/ +noncomputable def hsPairing (T U : E →L[𝕜] F) : 𝕜 := + T.toLinearMap.hsPairing U.toLinearMap + +@[simp] +theorem hsPairing_toLinearMap (T U : E →L[𝕜] F) : + T.toLinearMap.hsPairing U.toLinearMap = T.hsPairing U := rfl + +/-- CLM-level unfold of the HS pairing as a trace, sibling of `LinearMap.hsPairing_eq`. -/ +theorem hsPairing_eq [CompleteSpace E] [CompleteSpace F] (T U : E →L[𝕜] F) : + T.hsPairing U = LinearMap.trace 𝕜 E ((U.adjoint ∘L T : E →L[𝕜] E) : E →ₗ[𝕜] E) := rfl + +@[simp] +theorem hsPairing_zero_left (U : E →L[𝕜] F) : hsPairing (0 : E →L[𝕜] F) U = 0 := + LinearMap.hsPairing_zero_left _ + +@[simp] +theorem hsPairing_zero_right (T : E →L[𝕜] F) : T.hsPairing 0 = 0 := + LinearMap.hsPairing_zero_right _ + +theorem hsPairing_add_left (T T' U : E →L[𝕜] F) : + (T + T').hsPairing U = T.hsPairing U + T'.hsPairing U := + LinearMap.hsPairing_add_left _ _ _ + +theorem hsPairing_sub_left (T T' U : E →L[𝕜] F) : + (T - T').hsPairing U = T.hsPairing U - T'.hsPairing U := + LinearMap.hsPairing_sub_left _ _ _ + +theorem hsPairing_neg_left (T U : E →L[𝕜] F) : + (-T).hsPairing U = - T.hsPairing U := + LinearMap.hsPairing_neg_left _ _ + +theorem hsPairing_add_right (T U U' : E →L[𝕜] F) : + T.hsPairing (U + U') = T.hsPairing U + T.hsPairing U' := + LinearMap.hsPairing_add_right _ _ _ + +theorem hsPairing_sub_right (T U U' : E →L[𝕜] F) : + T.hsPairing (U - U') = T.hsPairing U - T.hsPairing U' := + LinearMap.hsPairing_sub_right _ _ _ + +theorem hsPairing_neg_right (T U : E →L[𝕜] F) : + T.hsPairing (-U) = - T.hsPairing U := + LinearMap.hsPairing_neg_right _ _ + +theorem hsPairing_sum_left {ι : Type*} (s : Finset ι) (T : ι → E →L[𝕜] F) + (U : E →L[𝕜] F) : + (∑ i ∈ s, T i).hsPairing U = ∑ i ∈ s, (T i).hsPairing U := by + simp only [← hsPairing_toLinearMap, ContinuousLinearMap.toLinearMap_sum, + LinearMap.hsPairing_sum_left] + +theorem hsPairing_sum_right {ι : Type*} (T : E →L[𝕜] F) (s : Finset ι) + (U : ι → E →L[𝕜] F) : + T.hsPairing (∑ i ∈ s, U i) = ∑ i ∈ s, T.hsPairing (U i) := by + simp only [← hsPairing_toLinearMap, ContinuousLinearMap.toLinearMap_sum, + LinearMap.hsPairing_sum_right] + +theorem hsPairing_smul_left (c : 𝕜) (T U : E →L[𝕜] F) : + (c • T).hsPairing U = c * T.hsPairing U := + LinearMap.hsPairing_smul_left _ _ _ + +theorem hsPairing_smul_right (c : 𝕜) (T U : E →L[𝕜] F) : + T.hsPairing (c • U) = star c * T.hsPairing U := + LinearMap.hsPairing_smul_right _ _ _ + +theorem hsPairing_conj (T U : E →L[𝕜] F) : + star (T.hsPairing U) = U.hsPairing T := + LinearMap.hsPairing_conj _ _ + +theorem hsPairing_self_star_eq_self (T : E →L[𝕜] F) : + star (T.hsPairing T) = T.hsPairing T := + LinearMap.hsPairing_self_star_eq_self _ + +section MoveAdjoint +variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + +/-- CLM sibling of `LinearMap.hsPairing_comp_left`. -/ +theorem hsPairing_comp_left [CompleteSpace F] [CompleteSpace G] + (T : E →L[𝕜] F) (S : F →L[𝕜] G) (W : E →L[𝕜] G) : + (S ∘L T).hsPairing W = T.hsPairing (S.adjoint ∘L W) := by + have hS : (S.adjoint : G →L[𝕜] F).toLinearMap = LinearMap.adjoint S.toLinearMap := + (ContinuousLinearMap.adjoint_toLinearMap S).symm + simpa [← hsPairing_toLinearMap, coe_comp, hS] + using LinearMap.hsPairing_comp_left T.toLinearMap S.toLinearMap W.toLinearMap + +/-- CLM sibling of `LinearMap.hsPairing_comp_right`. -/ +theorem hsPairing_comp_right [CompleteSpace E] [CompleteSpace F] + (T : E →L[𝕜] F) (S : F →L[𝕜] G) (W : E →L[𝕜] G) : + (S ∘L T).hsPairing W = S.hsPairing (W ∘L T.adjoint) := by + have hT : (T.adjoint : F →L[𝕜] E).toLinearMap = LinearMap.adjoint T.toLinearMap := + (ContinuousLinearMap.adjoint_toLinearMap T).symm + simpa [← hsPairing_toLinearMap, coe_comp, hT] + using LinearMap.hsPairing_comp_right T.toLinearMap S.toLinearMap W.toLinearMap + +end MoveAdjoint + +/-- **Cauchy–Schwarz inequality for the HS pairing**, CLM sibling of +`LinearMap.norm_hsPairing_sq_le`. -/ +theorem norm_hsPairing_sq_le (T U : E →L[𝕜] F) : + ‖T.hsPairing U‖ ^ 2 ≤ RCLike.re (T.hsPairing T) * RCLike.re (U.hsPairing U) := by + simpa using LinearMap.norm_hsPairing_sq_le T.toLinearMap U.toLinearMap + +/-- The real part of the HS self-pairing `re ‖T‖²_HS` is nonnegative: it is a sum of squared +norms over an orthonormal basis (`LinearMap.re_hsPairing_self_eq_sum_norm_sq`). This is the +nonnegativity companion of `norm_hsPairing_sq_le`. -/ +theorem re_hsPairing_self_nonneg (T : E →L[𝕜] F) : 0 ≤ RCLike.re (T.hsPairing T) := by + rw [← hsPairing_toLinearMap, + LinearMap.re_hsPairing_self_eq_sum_norm_sq _ (stdOrthonormalBasis 𝕜 E)] + positivity + +/-- **HS-norm sub-multiplicativity** in the operator-norm sense, CLM sibling of +`LinearMap.re_hsPairing_self_comp_le`. -/ +theorem re_hsPairing_self_comp_le {G : Type*} + [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + (S : F →L[𝕜] G) (T : E →L[𝕜] F) : + RCLike.re ((S ∘L T).hsPairing (S ∘L T)) ≤ ‖S‖ ^ 2 * RCLike.re (T.hsPairing T) := by + have h := LinearMap.re_hsPairing_self_comp_le S.toLinearMap T.toLinearMap + rwa [ContinuousLinearMap.toLinearMap_toContinuousLinearMap, + ← ContinuousLinearMap.toLinearMap_comp, + hsPairing_toLinearMap, hsPairing_toLinearMap] at h + +/-- CLM sibling of `LinearMap.re_hsPairing_self_eq_re_trace_comp_self_of_isSymmetric`: for a +self-adjoint operator `T`, `re (hsPairing T T) = re (trace (T * T))`. The CLM multiplication +`T * T : E →L[𝕜] E` coerces to `T.toLinearMap ∘ₗ T.toLinearMap`. -/ +theorem re_hsPairing_self_eq_re_trace_sq_of_isSelfAdjoint [CompleteSpace E] + {T : E →L[𝕜] E} (hT : IsSelfAdjoint T) : + RCLike.re (T.hsPairing T) = + RCLike.re (LinearMap.trace 𝕜 E ((T * T : E →L[𝕜] E) : E →ₗ[𝕜] E)) := by + rw [← hsPairing_toLinearMap] + exact (LinearMap.re_hsPairing_self_eq_re_trace_comp_self_of_isSymmetric hT.isSymmetric).trans + rfl + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/IdempotentDensityOp.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/IdempotentDensityOp.lean new file mode 100644 index 0000000000..c10b303cb5 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/IdempotentDensityOp.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum + +/-! + +# Idempotent density operators + +A density operator on a finite-dimensional inner product space that is also idempotent +equals a rank-one self-projector `rankOne 𝕜 v v` for some unit vector `v`. This file +proves the biconditional: + +`ρ.IsDensityOp → (IsIdempotentElem ρ ↔ ∃ v, ‖v‖ = 1 ∧ ρ = rankOne 𝕜 v v)` + +The forward direction uses the spectral expansion of `ρ` (positive ⇒ self-adjoint, so +diagonalizable with real eigenvalues): combined with `ρ² = ρ`, each eigenvalue squares to +itself and is therefore in `{0, 1}`; combined with `trace ρ = 1` and non-negativity, exactly +one eigenvalue is `1` and the rest are `0`; the spectral sum then collapses to a single +`rankOne 𝕜 (b i₀) (b i₀)` term. + +The reverse direction is the existing `isIdempotentElem_rankOne_self`. + +## Main results + +* `ContinuousLinearMap.IsDensityOp.isIdempotentElem_iff`: the biconditional. +* `ContinuousLinearMap.IsDensityOp.exists_eq_rankOne_of_idempotent`: the forward + direction, unpacked. + +The supporting lemmas about eigenvalues of symmetric idempotents +(`IsIdempotentElem.eigenvalues_sq_eq_self`, `IsIdempotentElem.eigenvalues_zero_or_one`) +live in [`Spectrum.lean`](../Mathlib/Analysis/InnerProductSpace/Spectrum.lean) — they +characterize the spectrum of orthogonal projections and have no density-operator +dependency. + +-/ + +@[expose] public section + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] [CompleteSpace E] + +open Module InnerProductSpace +open scoped ComplexOrder + +namespace ContinuousLinearMap + +namespace IsDensityOp + +variable {ρ : E →L[𝕜] E} + +/-- A density operator that is idempotent equals a rank-one self-projector for some +unit vector. -/ +theorem exists_eq_rankOne_of_idempotent (hρ : ρ.IsDensityOp) (hidem : IsIdempotentElem ρ) : + ∃ v : E, ‖v‖ = 1 ∧ ρ = rankOne 𝕜 v v := by + have hn : finrank 𝕜 E = finrank 𝕜 E := rfl + have hsa : IsSelfAdjoint ρ := hρ.isPositive.isSelfAdjoint + set b := hsa.isSymmetric.eigenvectorBasis hn + set lam := fun i ↦ hsa.isSymmetric.eigenvalues hn i + have hbool : ∀ i, lam i = 0 ∨ lam i = 1 := + fun i ↦ (ContinuousLinearMap.IsIdempotentElem.toLinearMap hidem).eigenvalues_zero_or_one + hsa.isSymmetric hn i + have hsum : ∑ i, lam i = 1 := hρ.eigenvalues_sum_eq_one hn + have hnn : ∀ i, 0 ≤ lam i := fun i ↦ hρ.eigenvalues_nonneg hn i + -- Exactly one eigenvalue is 1; the rest are 0. + obtain ⟨i₀, hi₀, h_others⟩ : ∃ i₀, lam i₀ = 1 ∧ ∀ i, i ≠ i₀ → lam i = 0 := by + obtain ⟨i₀, hi₀⟩ : ∃ i₀, lam i₀ = 1 := by + by_contra h; push Not at h + exact one_ne_zero <| hsum.symm.trans <| + Finset.sum_eq_zero fun i _ ↦ (hbool i).resolve_right (h i) + refine ⟨i₀, hi₀, fun i hi ↦ ?_⟩ + have h_zero_sum : ∑ j ∈ Finset.univ.erase i₀, lam j = 0 := by + have := Finset.add_sum_erase _ lam (Finset.mem_univ i₀); linarith + exact (Finset.sum_eq_zero_iff_of_nonneg fun j _ ↦ hnn j).mp h_zero_sum i + (Finset.mem_erase.mpr ⟨hi, Finset.mem_univ i⟩) + -- Spectral expansion collapses to a single rankOne term (cast to 𝕜 for the smul). + refine ⟨b i₀, b.orthonormal.1 i₀, ?_⟩ + have hi₀' : (hsa.isSymmetric.eigenvalues hn i₀ : 𝕜) = 1 := by exact_mod_cast hi₀ + have h_others' : ∀ j, j ≠ i₀ → (hsa.isSymmetric.eigenvalues hn j : 𝕜) = 0 := + fun j hj ↦ by exact_mod_cast h_others j hj + rw [hsa.spectral_sum hn, Finset.sum_eq_single i₀ (fun j _ hji ↦ ?_) (by simp)] + · rw [hi₀', one_smul] + · rw [h_others' j hji, zero_smul] + +/-- A density operator is a rank-one self-projector for some unit vector iff it is +idempotent. -/ +theorem isIdempotentElem_iff (hρ : ρ.IsDensityOp) : + IsIdempotentElem ρ ↔ ∃ v : E, ‖v‖ = 1 ∧ ρ = rankOne 𝕜 v v := by + refine ⟨exists_eq_rankOne_of_idempotent hρ, ?_⟩ + rintro ⟨v, hv, rfl⟩ + exact isIdempotentElem_rankOne_self hv + +omit [CompleteSpace E] in +/-- **Purity as a sum of squared eigenvalues.** For a density operator `ρ`, the real part of +`tr(ρ²)` equals the sum of the squares of its eigenvalues. Combines the Hilbert–Schmidt identity +`re (hsPairing T T) = re tr(T ∘ₗ T)` with `re (hsPairing T T) = ∑ ‖T (bᵢ)‖²` over the eigenvector +basis, where `‖ρ (bᵢ)‖² = λᵢ²`. -/ +theorem re_trace_mul_self_eq_sum_eigenvalues_sq (hρ : ρ.IsDensityOp) {n : ℕ} + (hn : finrank 𝕜 E = n) : + RCLike.re (LinearMap.trace 𝕜 E ((ρ * ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) = + ∑ i, (hρ.isSymmetric.eigenvalues hn i) ^ 2 := by + have hcoe : ((ρ * ρ : E →L[𝕜] E) : E →ₗ[𝕜] E) + = (ρ : E →ₗ[𝕜] E) ∘ₗ (ρ : E →ₗ[𝕜] E) := rfl + rw [hcoe, ← LinearMap.re_hsPairing_self_eq_re_trace_comp_self_of_isSymmetric hρ.isSymmetric, + LinearMap.re_hsPairing_self_eq_sum_norm_sq (ρ : E →ₗ[𝕜] E) (hρ.isSymmetric.eigenvectorBasis hn)] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [hρ.isSymmetric.apply_eigenvectorBasis hn i, norm_smul, RCLike.norm_ofReal, + (hρ.isSymmetric.eigenvectorBasis hn).orthonormal.1 i, mul_one, sq_abs] + +omit [CompleteSpace E] in +/-- **Purity is at most one** (N&C Exercise 2.71, the bound). For a density operator `ρ`, +`re tr(ρ²) ≤ 1`: writing `tr(ρ²) = ∑ λᵢ²` and using `0 ≤ λᵢ ≤ 1` gives `λᵢ² ≤ λᵢ`, so +`∑ λᵢ² ≤ ∑ λᵢ = 1`. -/ +theorem re_trace_mul_self_le_one (hρ : ρ.IsDensityOp) : + RCLike.re (LinearMap.trace 𝕜 E ((ρ * ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) ≤ 1 := by + have hn : finrank 𝕜 E = finrank 𝕜 E := rfl + rw [re_trace_mul_self_eq_sum_eigenvalues_sq hρ hn] + refine (Finset.sum_le_sum fun i _ => ?_).trans (le_of_eq (hρ.eigenvalues_sum_eq_one hn)) + nlinarith [hρ.eigenvalues_nonneg hn i, hρ.eigenvalues_le_one hn i] + +omit [CompleteSpace E] in +/-- **Purity equals one iff idempotent** (N&C Exercise 2.71, the equality case). For a density +operator `ρ`, `re tr(ρ²) = 1` iff `ρ` is idempotent. Forward: `∑ λᵢ² = 1 = ∑ λᵢ` with `0 ≤ λᵢ ≤ 1` +forces `λᵢ² = λᵢ`, and a self-adjoint operator whose eigenvalues each satisfy `λ² = λ` agrees with +`ρ²` on its eigenbasis, so `ρ² = ρ`. Reverse: `ρ² = ρ` gives `tr(ρ²) = tr ρ = 1`. -/ +theorem re_trace_mul_self_eq_one_iff_isIdempotentElem (hρ : ρ.IsDensityOp) : + RCLike.re (LinearMap.trace 𝕜 E ((ρ * ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) = 1 + ↔ IsIdempotentElem ρ := by + have hn : finrank 𝕜 E = finrank 𝕜 E := rfl + constructor + · intro h + rw [re_trace_mul_self_eq_sum_eigenvalues_sq hρ hn] at h + have hsum : ∑ i, hρ.isSymmetric.eigenvalues hn i = 1 := hρ.eigenvalues_sum_eq_one hn + have hkey : ∀ i, (hρ.isSymmetric.eigenvalues hn i) ^ 2 = hρ.isSymmetric.eigenvalues hn i := by + have hnonneg : ∀ i ∈ Finset.univ, + 0 ≤ hρ.isSymmetric.eigenvalues hn i - (hρ.isSymmetric.eigenvalues hn i) ^ 2 := + fun i _ => by nlinarith [hρ.eigenvalues_nonneg hn i, hρ.eigenvalues_le_one hn i] + have hz : ∑ i, (hρ.isSymmetric.eigenvalues hn i + - (hρ.isSymmetric.eigenvalues hn i) ^ 2) = 0 := by + rw [Finset.sum_sub_distrib, hsum, h]; ring + intro i + have := (Finset.sum_eq_zero_iff_of_nonneg hnonneg).mp hz i (Finset.mem_univ i) + linarith + set b := hρ.isSymmetric.eigenvectorBasis hn with hb + have happ : ∀ i, (ρ : E →ₗ[𝕜] E) (b i) = (hρ.isSymmetric.eigenvalues hn i : 𝕜) • b i := + fun i => hρ.isSymmetric.apply_eigenvectorBasis hn i + change (ρ * ρ : E →L[𝕜] E) = ρ + apply ContinuousLinearMap.coe_injective + change (ρ : E →ₗ[𝕜] E) ∘ₗ (ρ : E →ₗ[𝕜] E) = (ρ : E →ₗ[𝕜] E) + refine b.toBasis.ext fun i => ?_ + simp only [OrthonormalBasis.coe_toBasis] + rw [LinearMap.comp_apply, happ i, map_smul, happ i, smul_smul, ← RCLike.ofReal_mul, + ← pow_two, hkey i] + · intro hidem + rw [show (ρ * ρ : E →L[𝕜] E) = ρ from hidem, hρ.trace_eq_one, RCLike.one_re] + +/-- **Purity criterion for pure states** (N&C Exercise 2.71). For a density operator `ρ`, +`re tr(ρ²) = 1` iff `ρ` is a rank-one self-projector `|v⟩⟨v|` for some unit vector `v` — i.e. a +pure state. Combines `re_trace_mul_self_eq_one_iff_isIdempotentElem` with the idempotent-density +characterization `isIdempotentElem_iff`. -/ +theorem re_trace_mul_self_eq_one_iff_exists_rankOne (hρ : ρ.IsDensityOp) : + RCLike.re (LinearMap.trace 𝕜 E ((ρ * ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) = 1 + ↔ ∃ v : E, ‖v‖ = 1 ∧ ρ = rankOne 𝕜 v v := + (re_trace_mul_self_eq_one_iff_isIdempotentElem hρ).trans hρ.isIdempotentElem_iff + +end IsDensityOp + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/InvolutionRotation.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/InvolutionRotation.lean new file mode 100644 index 0000000000..4d0f624b7a --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/InvolutionRotation.lean @@ -0,0 +1,253 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import Mathlib.Analysis.SpecialFunctions.Complex.Circle +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds + +/-! +# Rotations generated by a self-adjoint involution and the operator-norm distance between them + +Let `A` be a self-adjoint involution on a complex Hilbert space `E` (`star A = A` and `A * A = 1`). +For a real angle `θ` the operator +`rotOfInvol A θ = cos(θ/2) • 1 − (sin(θ/2) · i) • A` +is the closed form of `exp(−i(θ/2)A)`: because `A² = 1`, the exponential series folds into the +cosine/sine of `θ/2`. It is a one-parameter family of unitaries — the abstract shape of a Bloch +rotation `R_n̂(θ)`, whose generator is the self-adjoint involution `n·σ`. + +The point of the file is the distance between two such rotations about the *same* axis: + +* `ContinuousLinearMap.norm_sub_rotOfInvol` — **the main identity**: on a nontrivial space, + `‖rotOfInvol A α − rotOfInvol A (α+β)‖ = ‖1 − exp(iβ/2)‖`, where the left-hand norm is the + operator norm `max_{‖ψ‖=1} ‖(U−V)ψ‖`. The mismatch angle `α` drops out entirely: only the + *difference* `β` matters. This is Nielsen & Chuang, *Quantum Computation and Quantum + Information*, Exercise 4.40, eq. (4.77) in maximal generality. +* `ContinuousLinearMap.norm_sub_rotOfInvol_apply` — the pointwise form + `‖(rotOfInvol A α − rotOfInvol A (α+β)) x‖ = ‖1 − exp(iβ/2)‖ · ‖x‖`: the difference is a scalar + multiple of an isometry, so *every* unit vector attains the operator norm (the maximiser in + eq. (4.61) is arbitrary). +* `ContinuousLinearMap.norm_sub_rotOfInvol_le_sub_int_mul_four_pi` — the **`4π`-periodic** bound + `‖…‖ ≤ |β − 4π·m|/2` for every integer `m`. Because the error is `‖1 − exp(iβ/2)‖`, it is a + function of `β` **only modulo `4π`** (the half-angle makes the period `4π`, not `2π`); the bound + records that it is small exactly when `β` is close to a multiple of `4π`. This is the correct + bridge to eq. (4.76): once an iterate `R_n̂(θ)^n = R_n̂(nθ)` lands within `δ` of the target angle + `α` **modulo `4π`**, the operator error is `≤ δ/2` and hence arbitrarily small. (The naive raw + bound `|nθ − α|/2` is useless: `{nθ}` is discrete and unbounded in `ℝ`, so `|nθ − α|` cannot be + driven to `0`; it is the residue mod `4π` that the density of `{nθ mod 4π}` controls.) + +The proof avoids spectral theory: writing `D = rotOfInvol A α − rotOfInvol A (α+β)` as +`p • 1 + q • A` with `p` real and `q` imaginary, self-adjointness kills the cross term and `A² = 1` +collapses the square, giving `star D * D = (2 − 2cos(β/2)) • 1` — a nonnegative scalar times the +identity. Thus `‖D x‖² = (2 − 2cos(β/2)) ‖x‖²` for every `x`, and +`2 − 2cos(β/2) = ‖1 − exp(iβ/2)‖²`. +-/ + +open Complex + +@[expose] public section + +namespace Complex + +/-- `‖1 − exp(iθ)‖² = 2 − 2cos θ`: the squared chord length between `1` and `exp(iθ)` on the unit +circle, from `Complex.norm_sub_one_sq_eqOn_sphere` and `exp(iθ).re = cos θ`. -/ +theorem norm_one_sub_exp_ofReal_mul_I_sq (θ : ℝ) : + ‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ ^ 2 = 2 - 2 * Real.cos θ := by + have hmem : Complex.exp ((θ : ℝ) * Complex.I) ∈ Metric.sphere (0 : ℂ) 1 := by + simp [Complex.norm_exp_ofReal_mul_I] + have h := Complex.norm_sub_one_sq_eqOn_sphere hmem + simp only [Complex.exp_ofReal_mul_I_re] at h + rw [norm_sub_rev, h]; ring + +/-- The chord bound `‖1 − exp(iθ)‖ ≤ |θ|` (a unit-circle arc is at least as long as its chord), +from the library's `Real.norm_exp_I_mul_ofReal_sub_one_le`. -/ +theorem norm_one_sub_exp_ofReal_mul_I_le (θ : ℝ) : + ‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ ≤ |θ| := by + rw [norm_sub_rev, mul_comm] + simpa [Real.norm_eq_abs] using Real.norm_exp_I_mul_ofReal_sub_one_le (x := θ) + +/-- **The reverse chord bound** `(2/π)·|θ| ≤ ‖1 − exp(iθ)‖`, valid on the arc `|θ| ≤ π`: there the +chord from `1` to `exp(iθ)` is at least `2/π` times the subtended angle. This is the companion lower +bound to `norm_one_sub_exp_ofReal_mul_I_le` (`‖…‖ ≤ |θ|`); together they pin the chord length +between `2|θ|/π` and `|θ|`. Proved from `‖1 − exp(iθ)‖² = 2 − 2cos θ = 4 sin²(θ/2)` and Jordan's +inequality `(2/π)·|θ/2| ≤ |sin(θ/2)|` (`Real.mul_abs_le_abs_sin`, since `|θ/2| ≤ π/2`). It is the +geometric estimate behind Nielsen & Chuang's phase-estimation accuracy bound (eq. (5.29)): the +read-out amplitude's denominator `1 − exp(iθ)` cannot be too small near a bin. -/ +theorem two_div_pi_mul_abs_le_norm_one_sub_exp_ofReal_mul_I {θ : ℝ} (hθ : |θ| ≤ Real.pi) : + 2 / Real.pi * |θ| ≤ ‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ := by + have hjordan : |θ| / Real.pi ≤ |Real.sin (θ / 2)| := by + have hx : |θ / 2| ≤ Real.pi / 2 := by rw [abs_div, abs_two]; linarith + have hj := Real.mul_abs_le_abs_sin hx + rw [abs_div, abs_two] at hj + calc |θ| / Real.pi = 2 / Real.pi * (|θ| / 2) := by ring + _ ≤ |Real.sin (θ / 2)| := hj + have hsq : (2 / Real.pi * |θ|) ^ 2 ≤ ‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ ^ 2 := by + rw [Complex.norm_one_sub_exp_ofReal_mul_I_sq] + have hid : (2 : ℝ) - 2 * Real.cos θ = 4 * Real.sin (θ / 2) ^ 2 := by + have hc2 : Real.cos θ = 2 * Real.cos (θ / 2) ^ 2 - 1 := by + have h := Real.cos_two_mul (θ / 2) + rwa [show 2 * (θ / 2) = θ by ring] at h + have hpyth := Real.sin_sq_add_cos_sq (θ / 2) + linarith + have hsin : (|θ| / Real.pi) ^ 2 ≤ Real.sin (θ / 2) ^ 2 := by + rw [← sq_abs (Real.sin (θ / 2)), pow_two, pow_two] + exact mul_self_le_mul_self (by positivity) hjordan + rw [hid, show (2 / Real.pi * |θ|) ^ 2 = 4 * (|θ| / Real.pi) ^ 2 from by ring] + linarith + have h0 : (0 : ℝ) ≤ 2 / Real.pi * |θ| := by positivity + calc 2 / Real.pi * |θ| = Real.sqrt ((2 / Real.pi * |θ|) ^ 2) := (Real.sqrt_sq h0).symm + _ ≤ Real.sqrt (‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ ^ 2) := Real.sqrt_le_sqrt hsq + _ = ‖(1 : ℂ) - Complex.exp (θ * Complex.I)‖ := Real.sqrt_sq (norm_nonneg _) + +/-- `exp(iθ)` is `2π`-periodic in `θ`: adding `2π·m` (integer `m`) to the angle leaves it — hence +the chord `‖1 − exp(iθ)‖` — unchanged. -/ +theorem exp_ofReal_mul_I_add_int_mul_two_pi (θ : ℝ) (m : ℤ) : + Complex.exp ((θ + 2 * Real.pi * m : ℝ) * Complex.I) = Complex.exp (θ * Complex.I) := by + rw [show ((θ + 2 * Real.pi * m : ℝ) : ℂ) * Complex.I + = (θ : ℝ) * Complex.I + (m : ℂ) * (2 * (Real.pi : ℝ) * Complex.I) by push_cast; ring] + exact Complex.exp_periodic.int_mul m ((θ : ℝ) * Complex.I) + +end Complex + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +/-- The **rotation generated by a self-adjoint involution** `A` through angle `θ`: +`rotOfInvol A θ = cos(θ/2) • 1 − (sin(θ/2)·i) • A`. When `A² = 1` this is the closed form of +`exp(−i(θ/2)A)`; the running example is a Bloch rotation `R_n̂(θ)` with `A = n·σ`. -/ +noncomputable def rotOfInvol (A : E →L[ℂ] E) (θ : ℝ) : E →L[ℂ] E := + (Real.cos (θ / 2) : ℂ) • 1 - ((Real.sin (θ / 2) : ℂ) * Complex.I) • A + +omit [CompleteSpace E] in +@[simp] +theorem rotOfInvol_apply (A : E →L[ℂ] E) (θ : ℝ) (x : E) : + rotOfInvol A θ x = (Real.cos (θ / 2) : ℂ) • x - ((Real.sin (θ / 2) : ℂ) * Complex.I) • A x := by + simp only [rotOfInvol, _root_.sub_apply, _root_.smul_apply, + one_apply_eq_self] + +omit [CompleteSpace E] in +/-- The zero rotation is the identity: `rotOfInvol A 0 = 1`. -/ +@[simp] +theorem rotOfInvol_zero (A : E →L[ℂ] E) : rotOfInvol A 0 = 1 := by + simp [rotOfInvol] + +/-- The key operator identity behind eq. (4.77): for a self-adjoint involution `A`, +`star D * D = (2 − 2cos(β/2)) • 1` where `D = rotOfInvol A α − rotOfInvol A (α+β)`. The angle `α` +cancels; self-adjointness kills the `A`-term and `A² = 1` collapses the `A²`-term. -/ +theorem star_sub_rotOfInvol_mul_sub_rotOfInvol (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) + (hA2 : A * A = 1) (α β : ℝ) : + star (rotOfInvol A α - rotOfInvol A (α + β)) * (rotOfInvol A α - rotOfInvol A (α + β)) + = ((2 - 2 * Real.cos (β / 2) : ℝ) : ℂ) • (1 : E →L[ℂ] E) := by + set p : ℂ := (Real.cos (α / 2) : ℂ) - (Real.cos ((α + β) / 2) : ℂ) with hp + set q : ℂ := ((Real.sin ((α + β) / 2) : ℂ) - (Real.sin (α / 2) : ℂ)) * Complex.I with hq + have hD : rotOfInvol A α - rotOfInvol A (α + β) = p • 1 + q • A := by + simp only [rotOfInvol, hp, hq] + match_scalars <;> ring + have hsp : star p = p := by + rw [hp] + simp only [← starRingEnd_apply, map_sub, Complex.conj_ofReal] + have hsq : star q = -q := by + rw [hq] + simp only [← starRingEnd_apply, map_mul, map_sub, Complex.conj_ofReal, Complex.conj_I] + ring + rw [hD, star_add, star_smul, star_smul, star_one, hA.star_eq, hsp, hsq] + have key : (p • (1 : E →L[ℂ] E) + (-q) • A) * (p • 1 + q • A) + = (p * p - q * q) • 1 + (p * q - q * p) • A := by + simp only [add_mul, mul_add, smul_mul_smul_comm, mul_one, one_mul, hA2] + match_scalars <;> ring + rw [key] + have hAcoeff : p * q - q * p = 0 := by ring + have hreal : (Real.cos (α / 2) - Real.cos ((α + β) / 2)) ^ 2 + + (Real.sin ((α + β) / 2) - Real.sin (α / 2)) ^ 2 = 2 - 2 * Real.cos (β / 2) := by + have hcos : Real.cos (α / 2) * Real.cos ((α + β) / 2) + + Real.sin (α / 2) * Real.sin ((α + β) / 2) = Real.cos (β / 2) := by + rw [← Real.cos_sub, show α / 2 - (α + β) / 2 = -(β / 2) by ring, Real.cos_neg] + nlinarith [hcos, Real.sin_sq_add_cos_sq (α / 2), Real.sin_sq_add_cos_sq ((α + β) / 2)] + have hpp : p * p = (((Real.cos (α / 2) - Real.cos ((α + β) / 2)) ^ 2 : ℝ) : ℂ) := by + rw [hp]; push_cast [-Complex.ofReal_cos]; ring + have hqq : q * q = -(((Real.sin ((α + β) / 2) - Real.sin (α / 2)) ^ 2 : ℝ) : ℂ) := by + rw [hq, mul_mul_mul_comm, Complex.I_mul_I]; push_cast [-Complex.ofReal_sin]; ring + rw [hAcoeff, zero_smul, add_zero, hpp, hqq, sub_neg_eq_add, ← Complex.ofReal_add, hreal] + +/-- A homothety criterion: if `star D * D = c • 1` with `c ≥ 0` real, then `D` scales every vector +by `√c`, i.e. `‖D x‖ = √c · ‖x‖`. (When `c > 0`, `D` is `√c` times a unitary.) -/ +theorem norm_apply_of_star_mul_self_eq_smul_one {D : E →L[ℂ] E} {c : ℝ} (hc : 0 ≤ c) + (h : star D * D = (c : ℂ) • 1) (x : E) : ‖D x‖ = Real.sqrt c * ‖x‖ := by + have hi : inner ℂ (D x) (D x) = (c : ℂ) * inner ℂ x x := by + rw [← ContinuousLinearMap.adjoint_inner_right, ← mul_apply_eq_comp, + ← ContinuousLinearMap.star_eq_adjoint, h, _root_.smul_apply, + one_apply_eq_self, inner_smul_right] + have hsq : ‖D x‖ ^ 2 = c * ‖x‖ ^ 2 := by + rw [← inner_self_eq_norm_sq (𝕜 := ℂ) (D x), ← inner_self_eq_norm_sq (𝕜 := ℂ) x, hi] + simp + have hnn : 0 ≤ Real.sqrt c * ‖x‖ := by positivity + calc ‖D x‖ = Real.sqrt (‖D x‖ ^ 2) := (Real.sqrt_sq (norm_nonneg _)).symm + _ = Real.sqrt ((Real.sqrt c * ‖x‖) ^ 2) := by + rw [hsq]; rw [mul_pow, Real.sq_sqrt hc] + _ = Real.sqrt c * ‖x‖ := Real.sqrt_sq hnn + +/-- **Pointwise form of eq. (4.77).** For a self-adjoint involution `A`, the difference of two +rotations about its axis is a homothety: `‖(rotOfInvol A α − rotOfInvol A (α+β)) x‖ = +‖1 − exp(iβ/2)‖ · ‖x‖` for every `x`. Only the angle difference `β` matters. -/ +theorem norm_sub_rotOfInvol_apply (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) (hA2 : A * A = 1) + (α β : ℝ) (x : E) : + ‖(rotOfInvol A α - rotOfInvol A (α + β)) x‖ + = ‖(1 : ℂ) - Complex.exp ((β / 2 : ℝ) * Complex.I)‖ * ‖x‖ := by + have hc : (0 : ℝ) ≤ 2 - 2 * Real.cos (β / 2) := by nlinarith [Real.cos_le_one (β / 2)] + rw [norm_apply_of_star_mul_self_eq_smul_one hc + (star_sub_rotOfInvol_mul_sub_rotOfInvol A hA hA2 α β) x] + congr 1 + rw [← Complex.norm_one_sub_exp_ofReal_mul_I_sq (β / 2), Real.sqrt_sq (norm_nonneg _)] + +/-- **Nielsen & Chuang, Exercise 4.40, eq. (4.77), general form.** On a nontrivial complex Hilbert +space, the operator-norm distance (the error `E(U,V) = max_{‖ψ‖=1} ‖(U−V)ψ‖` of eq. (4.61)) between +two rotations `rotOfInvol A α` and `rotOfInvol A (α+β)` about a self-adjoint-involution axis `A` is +`‖1 − exp(iβ/2)‖`, depending only on the angle difference `β`. -/ +theorem norm_sub_rotOfInvol [Nontrivial E] (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) (hA2 : A * A = 1) + (α β : ℝ) : + ‖rotOfInvol A α - rotOfInvol A (α + β)‖ + = ‖(1 : ℂ) - Complex.exp ((β / 2 : ℝ) * Complex.I)‖ := by + refine le_antisymm (opNorm_le_bound _ (norm_nonneg _) fun x => ?_) ?_ + · exact le_of_eq (norm_sub_rotOfInvol_apply A hA hA2 α β x) + · obtain ⟨x, hx⟩ := exists_ne (0 : E) + have hxp : 0 < ‖x‖ := norm_pos_iff.mpr hx + have hle := ContinuousLinearMap.le_opNorm (rotOfInvol A α - rotOfInvol A (α + β)) x + rw [norm_sub_rotOfInvol_apply A hA hA2 α β x] at hle + exact le_of_mul_le_mul_right hle hxp + +/-- **The vanishing bound.** The operator error between rotations whose angles differ by `β` is at +most `|β|/2`, so it can be driven below any `ε > 0` by making the angle mismatch small. -/ +theorem norm_sub_rotOfInvol_le [Nontrivial E] (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) + (hA2 : A * A = 1) (α β : ℝ) : ‖rotOfInvol A α - rotOfInvol A (α + β)‖ ≤ |β| / 2 := by + rw [norm_sub_rotOfInvol A hA hA2 α β] + calc ‖(1 : ℂ) - Complex.exp ((β / 2 : ℝ) * Complex.I)‖ + ≤ |β / 2| := Complex.norm_one_sub_exp_ofReal_mul_I_le (β / 2) + _ = |β| / 2 := by rw [abs_div]; norm_num + +/-- **The `4π`-periodic bound justifying eq. (4.76).** Because the error is `‖1 − exp(iβ/2)‖`, a +function of `β` only modulo `4π`, the operator distance is `≤ |β − 4π·m|/2` for *every* integer `m`. +Choosing `m` to minimise `|β − 4π·m|` shows the error is small exactly when `β` is near a multiple +of `4π` — what the density of `{nθ mod 4π}` supplies in eq. (4.76), unlike the raw `|β|`. -/ +theorem norm_sub_rotOfInvol_le_sub_int_mul_four_pi [Nontrivial E] (A : E →L[ℂ] E) + (hA : IsSelfAdjoint A) (hA2 : A * A = 1) (α β : ℝ) (m : ℤ) : + ‖rotOfInvol A α - rotOfInvol A (α + β)‖ ≤ |β - 4 * Real.pi * m| / 2 := by + rw [norm_sub_rotOfInvol A hA hA2 α β] + have hper : Complex.exp ((β / 2 : ℝ) * Complex.I) + = Complex.exp (((β - 4 * Real.pi * m) / 2 : ℝ) * Complex.I) := by + rw [← Complex.exp_ofReal_mul_I_add_int_mul_two_pi ((β - 4 * Real.pi * m) / 2) m] + congr 1 + push_cast; ring + rw [hper] + calc ‖(1 : ℂ) - Complex.exp (((β - 4 * Real.pi * m) / 2 : ℝ) * Complex.I)‖ + ≤ |(β - 4 * Real.pi * m) / 2| := + Complex.norm_one_sub_exp_ofReal_mul_I_le ((β - 4 * Real.pi * m) / 2) + _ = |β - 4 * Real.pi * m| / 2 := by rw [abs_div]; norm_num + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/JointEigenspace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/JointEigenspace.lean new file mode 100644 index 0000000000..6411e86b31 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/JointEigenspace.lean @@ -0,0 +1,166 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.JointEigenspace +public import Mathlib.Analysis.InnerProductSpace.PiL2 +public import Mathlib.LinearAlgebra.Eigenspace.Minpoly + +/-! ### Simultaneous diagonalization by a common orthonormal basis + +The internal-direct-sum results of `Mathlib.Analysis.InnerProductSpace.JointEigenspace` are +repackaged here in the form usually quoted in physics (Nielsen & Chuang, *Quantum Computation +and Quantum Information*, Theorem 2.2): two symmetric operators commute if and only if they are +diagonal in a common orthonormal basis, i.e. share an orthonormal basis of eigenvectors. This is +generalized to a finite pairwise-commuting family of symmetric operators sharing a single +orthonormal eigenbasis. +-/ + +@[expose] public section + +namespace Module.End + +variable {R M ι : Type*} [CommRing R] [AddCommGroup M] [Module R M] + +/-- If every vector of a basis `b` is an eigenvector of both endomorphisms `f` and `g` — that is, +if `f` and `g` are simultaneously diagonal in `b` — then `f` and `g` commute. This is the easy +direction of the simultaneous diagonalization theorem, and holds over any commutative ring with no +extra structure. -/ +theorem commute_of_forall_apply_basis_eq_smul {f g : Module.End R M} (b : Module.Basis ι R M) + (hf : ∀ i, ∃ μ : R, f (b i) = μ • b i) (hg : ∀ i, ∃ ν : R, g (b i) = ν • b i) : + Commute f g := by + refine b.ext fun i => ?_ + obtain ⟨μ, hμ⟩ := hf i + obtain ⟨ν, hν⟩ := hg i + simp only [mul_apply_eq_comp, hμ, hν, map_smul, smul_smul, mul_comm] + +end Module.End + +namespace LinearMap.IsSymmetric + +open Module.End Submodule + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] {A B : E →ₗ[𝕜] E} + +/-- **Simultaneous diagonalization, existence half.** Two commuting symmetric operators on a +finite-dimensional inner product space share an orthonormal eigenbasis: there is an orthonormal +basis `b` and scalar functions `μ ν` with `A (b i) = μ i • b i` and `B (b i) = ν i • b i` for all +`i` — a basis with respect to which both `A` and `B` are diagonal. + +The joint eigenspaces `eigenspace A i.2 ⊓ eigenspace B i.1` form an orthogonal family +(`orthogonalFamily_eigenspace_inf_eigenspace`) and span the whole space +(`iSup_iSup_eigenspace_inf_eigenspace_eq_top_of_commute`). Reindexing along the *actual* eigenvalue +pairs `Eigenvalues B × Eigenvalues A` (a finite type) makes the index a `Fintype`, so +`subordinateOrthonormalBasis` collects an orthonormal basis subordinate to that decomposition; each +of its vectors lies in a single joint eigenspace, hence is a common eigenvector of `A` and `B`. + +This is the shared construction behind the spectral theorem for normal operators +(`IsStarNormal.exists_orthonormalBasis_forall_apply_eq_smul`) and the simultaneous diagonalization +theorem `commute_iff_exists_orthonormalBasis_forall_apply_eq_smul` below. -/ +theorem exists_orthonormalBasis_forall_apply_eq_smul_of_commute + (hA : A.IsSymmetric) (hB : B.IsSymmetric) (hAB : Commute A B) : + ∃ (b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E) + (μ ν : Fin (Module.finrank 𝕜 E) → 𝕜), ∀ i, A (b i) = μ i • b i ∧ B (b i) = ν i • b i := by + classical + -- The joint eigenspaces of `A` and `B` form an orthogonal family and span the whole space. + set V : 𝕜 × 𝕜 → Submodule 𝕜 E := fun i => eigenspace A i.2 ⊓ eigenspace B i.1 with hVdef + have hof : OrthogonalFamily 𝕜 (fun i => (V i)) (fun i => (V i).subtypeₗᵢ) := + orthogonalFamily_eigenspace_inf_eigenspace hA hB + -- Reindex along the (finite) set of eigenvalue pairs so that the index type is a `Fintype`. + set f : Eigenvalues B × Eigenvalues A → 𝕜 × 𝕜 := fun q => (q.1, q.2) with hfdef + have hf : Function.Injective f := by + rintro ⟨b1, a1⟩ ⟨b2, a2⟩ h + simp only [hfdef, Prod.mk.injEq] at h + exact Prod.ext (Subtype.ext h.1) (Subtype.ext h.2) + have hof' := hof.comp hf + have hspan : ⨆ q, V (f q) = ⊤ := by + refine top_le_iff.mp ?_ + rw [← iSup_iSup_eigenspace_inf_eigenspace_eq_top_of_commute hA hB hAB] + refine iSup_le fun α => iSup_le fun γ => ?_ + by_cases h : eigenspace A α ⊓ eigenspace B γ = ⊥ + · rw [h]; exact bot_le + · have hα : eigenspace A α ≠ ⊥ := fun he => h (by rw [he, bot_inf_eq]) + have hγ : eigenspace B γ ≠ ⊥ := fun he => h (by rw [he, inf_bot_eq]) + exact le_iSup (fun q => V (f q)) (⟨γ, hγ⟩, ⟨α, hα⟩) + have hInt : DirectSum.IsInternal (fun q => V (f q)) := by + rw [hof'.isInternal_iff, hspan] + exact Submodule.top_orthogonal_eq_bot + -- A subordinate orthonormal basis consists of common eigenvectors of `A` and `B`. + refine ⟨hInt.subordinateOrthonormalBasis rfl hof', + fun i => ((hInt.subordinateOrthonormalBasisIndex rfl i hof').2 : 𝕜), + fun i => ((hInt.subordinateOrthonormalBasisIndex rfl i hof').1 : 𝕜), fun i => ?_⟩ + have hmem := hInt.subordinateOrthonormalBasis_subordinate rfl i hof' + simp only [hVdef, hfdef, Submodule.mem_inf, Module.End.mem_eigenspace_iff] at hmem + exact hmem + +/-- **Simultaneous diagonalization theorem** (Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 2.2). Two symmetric operators `A` and `B` on a finite-dimensional inner +product space commute if and only if there is an orthonormal basis of common eigenvectors — an +orthonormal basis with respect to which both `A` and `B` are diagonal. (Over `𝕜 = ℂ`, `IsSymmetric` +is Hermiticity, recovering the textbook statement.) -/ +theorem commute_iff_exists_orthonormalBasis_forall_apply_eq_smul + (hA : A.IsSymmetric) (hB : B.IsSymmetric) : + Commute A B ↔ ∃ b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E, + (∀ i, ∃ μ : 𝕜, A (b i) = μ • b i) ∧ ∀ i, ∃ ν : 𝕜, B (b i) = ν • b i := + ⟨fun hAB => by + obtain ⟨b, μ, ν, h⟩ := exists_orthonormalBasis_forall_apply_eq_smul_of_commute hA hB hAB + exact ⟨b, fun i => ⟨μ i, (h i).1⟩, fun i => ⟨ν i, (h i).2⟩⟩, + fun ⟨b, hbA, hbB⟩ => + Module.End.commute_of_forall_apply_basis_eq_smul b.toBasis + (fun i => by simpa only [OrthonormalBasis.coe_toBasis] using hbA i) + (fun i => by simpa only [OrthonormalBasis.coe_toBasis] using hbB i)⟩ + +/-- **Simultaneous diagonalization for a commuting family, existence half** — the `n`-operator +generalization of `exists_orthonormalBasis_forall_apply_eq_smul_of_commute`. A finite family `T` of +pairwise-commuting symmetric operators on a finite-dimensional inner product space shares an +orthonormal eigenbasis: there is an orthonormal basis `b` and scalar functions `μ` with +`T j (b i) = μ j i • b i` for every operator index `j` and basis index `i` — a single basis with +respect to which every `T j` is diagonal. + +The joint eigenspaces `⨅ j, eigenspace (T j) (χ j)` form an orthogonal family +(`orthogonalFamily_iInf_eigenspaces`) and span the whole space (`iSup_iInf_eq_top_of_commute`). +Reindexing along the *actual* eigenvalue tuples `∀ j, Eigenvalues (T j)` (a finite type) makes the +index a `Fintype`, so `subordinateOrthonormalBasis` collects an orthonormal basis subordinate to +that decomposition; each of its vectors lies in a single joint eigenspace, hence is a common +eigenvector of every `T j`. -/ +theorem exists_orthonormalBasis_forall_apply_eq_smul_of_pairwise_commute + {ι : Type*} [Finite ι] {T : ι → E →ₗ[𝕜] E} + (hT : ∀ j, (T j).IsSymmetric) (hC : Pairwise (Function.onFun Commute T)) : + ∃ (b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E) + (μ : ι → Fin (Module.finrank 𝕜 E) → 𝕜), ∀ j i, T j (b i) = μ j i • b i := by + classical + have : Fintype ι := Fintype.ofFinite ι + set V : (ι → 𝕜) → Submodule 𝕜 E := fun χ => ⨅ j, eigenspace (T j) (χ j) with hVdef + have hof : OrthogonalFamily 𝕜 (fun χ => (V χ)) (fun χ => (V χ).subtypeₗᵢ) := + orthogonalFamily_iInf_eigenspaces hT + -- Reindex the joint eigenspaces along the *actual* eigenvalue tuples, a `Fintype`. + set f : (∀ j, Eigenvalues (T j)) → (ι → 𝕜) := fun q j => (q j : 𝕜) with hfdef + have hf : Function.Injective f := fun q1 q2 h => funext fun j => Subtype.ext (congrFun h j) + have hof' := hof.comp hf + have hspan : ⨆ q, V (f q) = ⊤ := by + refine top_le_iff.mp ?_ + rw [← iSup_iInf_eq_top_of_commute hT hC] + refine iSup_le fun χ => ?_ + by_cases h : (⨅ j, eigenspace (T j) (χ j)) = ⊥ + · rw [h]; exact bot_le + · -- a nonzero joint eigenspace forces each coordinate `χ j` to be an eigenvalue of `T j` + have hqj : ∀ j, HasEigenvalue (T j) (χ j) := fun j => by + rw [hasEigenvalue_iff] + exact fun he => h (le_bot_iff.mp ((iInf_le _ j).trans he.le)) + exact le_iSup (fun q => V (f q)) (fun j => ⟨χ j, hqj j⟩) + have hInt : DirectSum.IsInternal (fun q => V (f q)) := by + rw [hof'.isInternal_iff, hspan]; exact Submodule.top_orthogonal_eq_bot + refine ⟨hInt.subordinateOrthonormalBasis rfl hof', + fun j i => ((hInt.subordinateOrthonormalBasisIndex rfl i hof') j : 𝕜), fun j i => ?_⟩ + have hmem := hInt.subordinateOrthonormalBasis_subordinate rfl i hof' + simp only [hVdef, hfdef, Submodule.mem_iInf, mem_eigenspace_iff] at hmem + exact hmem j + +end LinearMap.IsSymmetric diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityRpow.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityRpow.lean new file mode 100644 index 0000000000..0d48a04e5d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityRpow.lean @@ -0,0 +1,351 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCTensor +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeometricMeanMaximality +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.SierpinskiMidpoint +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Isometric + +/-! +# Joint operator concavity of `(A, B) ↦ A^q ⊗ B^r` (Lieb's Theorem 1, tensor form) + +For strictly positive operators `A : E →L[ℂ] E` and `B : F →L[ℂ] F` on finite-dim complex +Hilbert spaces, the map `(A, B) ↦ A^q ⊗ B^r` is jointly operator-concave whenever `(q, r)` lies +in the Lieb simplex `{(q, r) | 0 ≤ q, 0 ≤ r, q + r ≤ 1}` — Carlen §6.1 / Lieb's Theorem 1. + +## Proof structure (Carlen §6.1) + +Define `ConcaveAt q r ⊂ Prop` as the predicate that the joint concavity inequality holds at +the exponent pair `(q, r)`. + +1. **Base cases**: `ConcaveAt 0 0`, `ConcaveAt 1 0`, `ConcaveAt 0 1`. Each follows + from `mapL`'s bilinearity. +2. **Midpoint closure**: if `ConcaveAt q₁ r₁` and `ConcaveAt q₂ r₂`, + then `ConcaveAt ((q₁+q₂)/2) ((r₁+r₂)/2)`. Via the GM-reduction identity + GM concavity + + GM monotonicity. +3. **Topological closedness**: `{(q, r) | ConcaveAt q r}` is closed in `ℝ × ℝ` + via joint continuity `Continuous.mapL` + `continuous_const_rpow`. +4. **Sierpinski lift** (via `Convex.of_isClosed_of_midpoint_mem`): closed + midpoint-stable + ⇒ convex. +5. **Simplex identification**: the convex hull of `{(0,0), (1,0), (0,1)}` is the + Lieb simplex; combined with convexity of the concavity-set, gives the headline. + +## Main results + +- `LiebTensor.concaveAt_zero_zero`, `concaveAt_one_zero`, `concaveAt_zero_one`: base cases. +- `LiebTensor.concaveAt_midpoint`: midpoint-closure. +- `LiebTensor.concaveAt_isClosed`: topological closedness. +- `LiebTensor.concaveAt_of_mem_simplex`: joint concavity on the Lieb simplex (headline). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace ContinuousLinearMap + +/-- The "inner-product against `v`" functional `M ↦ re ⟨v, M v⟩` on a complex Hilbert space +`H`, packaged as a `PositiveLinearMap` over `ℝ`. Real-linear because the inner-product +distributes over `+` and the ℝ-smul on `H` is defeq to the ℂ-smul via `Module.compHom` (the +`change` step in `map_smul'`); Loewner-monotone via `IsPositive.re_inner_nonneg_right` on the +difference `N - M`. + +Consumed by `LiebTensor.concaveAt_inner_mapL` (specializing `H := E ⊗[ℂ] F`) to lift γ.1c's +tensor-form Lieb T1 to the v-form. More generally, this is the real part of the vector-state +functional `M ↦ ⟨v, M v⟩`, fundamental in operator-theoretic concavity arguments. -/ +noncomputable def innerSelfFunctional {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (v : H) : (H →L[ℂ] H) →ₚ[ℝ] ℝ where + toFun M := RCLike.re ⟪v, M v⟫_ℂ + map_add' M N := by + rw [_root_.add_apply, inner_add_right, map_add] + map_smul' c M := by + -- ℝ-smul on `H` is defeq to ℂ-smul via `(c : ℂ)`-cast (`Module.compHom`). + -- `change` bridges so `inner_smul_right` (ℂ-form) fires; `simp [smul_eq_mul]` + -- collapses `↑c * z` and `c • re z` to the common form. + change RCLike.re ⟪v, ((c : ℂ) • M v : H)⟫_ℂ = c • RCLike.re ⟪v, M v⟫_ℂ + rw [inner_smul_right] + simp [smul_eq_mul] + monotone' M N hMN := by + -- `M ≤ N → (N - M).IsPositive → 0 ≤ re ⟨v, (N - M) v⟩ → re ⟨v, M v⟩ ≤ re ⟨v, N v⟩`. + have h_re := (ContinuousLinearMap.le_def.mp hMN).re_inner_nonneg_right v + rw [_root_.sub_apply, inner_sub_right, map_sub, sub_nonneg] at h_re + exact h_re + +variable {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + +namespace LiebTensor + +/-- The joint operator concavity inequality at the exponent pair `(q, r) : ℝ × ℝ`: for any +strictly positive `A₁, A₂ : E →L[ℂ] E` and `B₁, B₂ : F →L[ℂ] F`, and any convex coefficients +`t, s ≥ 0` with `t + s = 1`, + + `t • mapL (A₁^q) (B₁^r) + s • mapL (A₂^q) (B₂^r) ≤ mapL ((t•A₁ + s•A₂)^q) ((t•B₁ + s•B₂)^r)`. + +The set `{(q, r) | ConcaveAt q r}` will be shown to equal the Lieb simplex +`{(q, r) | 0 ≤ q, 0 ≤ r, q + r ≤ 1}`. -/ +def ConcaveAt (q r : ℝ) : Prop := + ∀ {A₁ A₂ : E →L[ℂ] E} (_ : IsStrictlyPositive A₁) (_ : IsStrictlyPositive A₂) + {B₁ B₂ : F →L[ℂ] F} (_ : IsStrictlyPositive B₁) (_ : IsStrictlyPositive B₂) + {t s : ℝ} (_ : 0 ≤ t) (_ : 0 ≤ s) (_ : t + s = 1), + t • TensorProduct.mapL (A₁ ^ q) (B₁ ^ r) + s • TensorProduct.mapL (A₂ ^ q) (B₂ ^ r) ≤ + TensorProduct.mapL ((t • A₁ + s • A₂) ^ q) ((t • B₁ + s • B₂) ^ r) + +/-- Base case `(0, 0)`: both sides equal `mapL 1 1`. -/ +theorem concaveAt_zero_zero : ConcaveAt (E := E) (F := F) 0 0 := by + intro A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + rw [CFC.rpow_zero _ hA₁.nonneg, CFC.rpow_zero _ hA₂.nonneg, + CFC.rpow_zero _ hB₁.nonneg, CFC.rpow_zero _ hB₂.nonneg, + CFC.rpow_zero _ (convex_isStrictlyPositive hA₁ hA₂ ht hs hts).nonneg, + CFC.rpow_zero _ (convex_isStrictlyPositive hB₁ hB₂ ht hs hts).nonneg, + ← add_smul, hts, one_smul] + +/-- Base case `(1, 0)`: both sides equal `mapL (t•A₁ + s•A₂) 1` by `mapL`-bilinearity in the +first argument. The `change` bridges ℝ-smul on the ℂ-CLM to ℂ-smul (defeq via the algebra +tower, but `IsScalarTower ℝ ℂ (E →L[ℂ] E)` isn't auto-synthesized for `mapL_smul_left` to fire +on ℝ-smul; per memory `feedback_smul_coercion_change_workaround`). -/ +theorem concaveAt_one_zero : ConcaveAt (E := E) (F := F) 1 0 := by + intro A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + refine le_of_eq ?_ + rw [CFC.rpow_one _ hA₁.nonneg, CFC.rpow_one _ hA₂.nonneg, + CFC.rpow_one _ (convex_isStrictlyPositive hA₁ hA₂ ht hs hts).nonneg, + CFC.rpow_zero _ hB₁.nonneg, CFC.rpow_zero _ hB₂.nonneg, + CFC.rpow_zero _ (convex_isStrictlyPositive hB₁ hB₂ ht hs hts).nonneg] + change (t : ℂ) • TensorProduct.mapL A₁ 1 + (s : ℂ) • TensorProduct.mapL A₂ 1 = + TensorProduct.mapL ((t : ℂ) • A₁ + (s : ℂ) • A₂) 1 + rw [TensorProduct.mapL_add_left, TensorProduct.mapL_smul_left, + TensorProduct.mapL_smul_left] + +/-- Base case `(0, 1)`: both sides equal `mapL 1 (t•B₁ + s•B₂)` by `mapL`-bilinearity in the +second argument. Mirror of `concaveAt_one_zero`. -/ +theorem concaveAt_zero_one : ConcaveAt (E := E) (F := F) 0 1 := by + intro A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + refine le_of_eq ?_ + rw [CFC.rpow_zero _ hA₁.nonneg, CFC.rpow_zero _ hA₂.nonneg, + CFC.rpow_zero _ (convex_isStrictlyPositive hA₁ hA₂ ht hs hts).nonneg, + CFC.rpow_one _ hB₁.nonneg, CFC.rpow_one _ hB₂.nonneg, + CFC.rpow_one _ (convex_isStrictlyPositive hB₁ hB₂ ht hs hts).nonneg] + change (t : ℂ) • TensorProduct.mapL (1 : E →L[ℂ] E) B₁ + + (s : ℂ) • TensorProduct.mapL (1 : E →L[ℂ] E) B₂ = + TensorProduct.mapL (1 : E →L[ℂ] E) ((t : ℂ) • B₁ + (s : ℂ) • B₂) + rw [TensorProduct.mapL_add_right, TensorProduct.mapL_smul_right, + TensorProduct.mapL_smul_right] + +/-- **Midpoint-closure of the joint-concavity property** (Carlen §6.1 key step). If joint +operator concavity of `(A, B) ↦ A^q ⊗ B^r` holds at `(q₁, r₁)` and `(q₂, r₂)`, then it holds +at their midpoint. Chain: +1. Rewrite both sides via the midpoint identity `mapL (X^q) (Y^r) = M₀(mapL X^{q₁} Y^{r₁}, + mapL X^{q₂} Y^{r₂})` (`TensorProduct.mapL_rpow_midpoint_eq_geometricMean`). +2. `geometricMean_concave` (β.4) commutes the convex combination past `M₀`. +3. `geometricMean_mono` invokes the `(q₁, r₁)` and `(q₂, r₂)` concavity hypotheses to bound + each argument by the convex-combined RHS. -/ +theorem concaveAt_midpoint {q₁ r₁ q₂ r₂ : ℝ} + (h₁ : ConcaveAt (E := E) (F := F) q₁ r₁) (h₂ : ConcaveAt (E := E) (F := F) q₂ r₂) : + ConcaveAt (E := E) (F := F) ((q₁ + q₂) / 2) ((r₁ + r₂) / 2) := by + intro A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + have htA := convex_isStrictlyPositive hA₁ hA₂ ht hs hts + have htB := convex_isStrictlyPositive hB₁ hB₂ ht hs hts + -- Strict-positivity shortcut: `mapL (X^q) (Y^r)` strict for `X, Y` strict + -- (`mapL_isStrictlyPositive` + `IsStrictlyPositive.rpow`, both `@[aesop safe apply]`). + have hmapL : ∀ {X : E →L[ℂ] E} (_ : IsStrictlyPositive X) + {Y : F →L[ℂ] F} (_ : IsStrictlyPositive Y) (q r : ℝ), + IsStrictlyPositive (TensorProduct.mapL (X ^ q) (Y ^ r)) := fun _ _ _ _ ↦ by aesop + rw [TensorProduct.mapL_rpow_midpoint_eq_geometricMean hA₁ hB₁, + TensorProduct.mapL_rpow_midpoint_eq_geometricMean hA₂ hB₂, + TensorProduct.mapL_rpow_midpoint_eq_geometricMean htA htB] + -- Two-step bound: `geometricMean_concave` (β.4) commutes the convex combo past `M₀`; + -- then `geometricMean_mono` invokes the `(qᵢ, rᵢ)` concavity on each argument. + refine le_trans (b := CFC.geometricMean + (t • TensorProduct.mapL (A₁ ^ q₁) (B₁ ^ r₁) + s • TensorProduct.mapL (A₂ ^ q₁) (B₂ ^ r₁)) + (t • TensorProduct.mapL (A₁ ^ q₂) (B₁ ^ r₂) + s • TensorProduct.mapL (A₂ ^ q₂) (B₂ ^ r₂))) + ?_ ?_ + · -- Convex-combo commutes past `M₀`: strict-pos at `(q₁, r₁)` for the LHS args, + -- non-negativity at `(q₂, r₂)` for the RHS args. + refine CFC.geometricMean_concave ?_ ?_ ?_ ?_ ht hs hts + · exact hmapL hA₁ hB₁ q₁ r₁ + · exact hmapL hA₂ hB₂ q₁ r₁ + · exact (hmapL hA₁ hB₁ q₂ r₂).nonneg + · exact (hmapL hA₂ hB₂ q₂ r₂).nonneg + · -- Monotonicity in each `M₀` argument from `(q₁, r₁)` / `(q₂, r₂)` concavity. + refine CFC.geometricMean_mono ?_ ?_ ?_ ?_ ?_ ?_ + · -- LHS-arg-1 strict-pos via convex-combo of `(q₁, r₁)`-strict. + exact convex_isStrictlyPositive (hmapL hA₁ hB₁ q₁ r₁) (hmapL hA₂ hB₂ q₁ r₁) ht hs hts + · -- RHS-arg-1 strict-pos via `mapL_isStrictlyPositive` on the combined base. + exact hmapL htA htB q₁ r₁ + · -- LHS-arg-2 nonneg via add+smul of `(q₂, r₂)`-strict.nonneg. + exact add_nonneg (smul_nonneg ht (hmapL hA₁ hB₁ q₂ r₂).nonneg) + (smul_nonneg hs (hmapL hA₂ hB₂ q₂ r₂).nonneg) + · -- RHS-arg-2 nonneg. + exact (hmapL htA htB q₂ r₂).nonneg + · -- Arg-1 inequality: invoke `(q₁, r₁)` concavity. + exact h₁ hA₁ hA₂ hB₁ hB₂ ht hs hts + · -- Arg-2 inequality: invoke `(q₂, r₂)` concavity. + exact h₂ hA₁ hA₂ hB₁ hB₂ ht hs hts + +/-- **Topological closedness**: the set `{(q, r) | ConcaveAt q r}` is closed in `ℝ × ℝ`. +For each fixed `(A₁, A₂, B₁, B₂, t, s)`, the inequality `LHS(q,r) ≤ RHS(q,r)` defines a closed +set via `isClosed_le` (both sides continuous in `(q, r)` via `Continuous.mapL` + +`CFC.continuous_const_rpow`). Sequential closedness then suffices in the first-countable +space `ℝ × ℝ`. -/ +theorem concaveAt_isClosed : IsClosed {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := by + apply IsSeqClosed.isClosed + intro p_n p hp_in hp_lim A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + refine le_of_tendsto_of_tendsto' (b := Filter.atTop) + (h := fun n ↦ hp_in n hA₁ hA₂ hB₁ hB₂ ht hs hts) ?_ ?_ + -- Both sides: `refine Tendsto.comp (g := ) ?_ hp_lim` pins the outer function + -- explicitly (Lean's eta-unification can't recover it from a bare `?_ ∘ p_n`); then + -- `Continuous.tendsto _ p` lifts a `Continuous` proof, built via `Continuous.mapL` + -- and `CFC.continuous_const_rpow`. + · -- LHS: sum of two `t • mapL (A_i ^ ·) (B_i ^ ·)` summands. + refine Filter.Tendsto.comp (g := fun pp : ℝ × ℝ ↦ + t • TensorProduct.mapL (A₁ ^ pp.1) (B₁ ^ pp.2) + + s • TensorProduct.mapL (A₂ ^ pp.1) (B₂ ^ pp.2)) ?_ hp_lim + apply Continuous.tendsto _ p + refine Continuous.add ?_ ?_ + · exact (((CFC.continuous_const_rpow hA₁).comp continuous_fst).mapL + ((CFC.continuous_const_rpow hB₁).comp continuous_snd)).const_smul t + · exact (((CFC.continuous_const_rpow hA₂).comp continuous_fst).mapL + ((CFC.continuous_const_rpow hB₂).comp continuous_snd)).const_smul s + · -- RHS: single `mapL ((t•A₁+s•A₂) ^ ·) ((t•B₁+s•B₂) ^ ·)`. + refine Filter.Tendsto.comp (g := fun pp : ℝ × ℝ ↦ + TensorProduct.mapL ((t • A₁ + s • A₂) ^ pp.1) ((t • B₁ + s • B₂) ^ pp.2)) + ?_ hp_lim + apply Continuous.tendsto _ p + refine Continuous.mapL ?_ ?_ + · exact (CFC.continuous_const_rpow (convex_isStrictlyPositive hA₁ hA₂ ht hs hts)).comp + continuous_fst + · exact (CFC.continuous_const_rpow (convex_isStrictlyPositive hB₁ hB₂ ht hs hts)).comp + continuous_snd + +/-- **Sierpinski lift** (γ.0 application): the set `{(q, r) | ConcaveAt q r}` is convex in +`ℝ × ℝ`. Combines `concaveAt_isClosed` + midpoint-closure (`concaveAt_midpoint`) via +`Convex.of_isClosed_of_midpoint_mem`. -/ +theorem concaveAt_convex : Convex ℝ {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := by + apply Convex.of_isClosed_of_midpoint_mem concaveAt_isClosed + intro u hu v hv + have h_mid : midpoint ℝ u v = ((u.1 + v.1) / 2, (u.2 + v.2) / 2) := by + ext <;> simp [midpoint, AffineMap.lineMap_apply_module] <;> ring + rw [h_mid] + -- Unfold `ConcaveAt` via `intro`, then apply `concaveAt_midpoint` fully expanded. + intro A₁ A₂ hA₁ hA₂ B₁ B₂ hB₁ hB₂ t s ht hs hts + exact concaveAt_midpoint hu hv hA₁ hA₂ hB₁ hB₂ ht hs hts + +/-- **Lieb's Theorem 1 (tensor form)**: for strictly positive `A_i : E →L[ℂ] E` and +`B_i : F →L[ℂ] F`, the function `(A, B) ↦ A^q ⊗ B^r` is jointly operator-concave whenever +`(q, r)` lies in the Lieb simplex `{(q, r) | 0 ≤ q, 0 ≤ r, q + r ≤ 1}`. Carlen §6.1 / Lieb's +Theorem 1. + +Proof: the concavity set is convex (`concaveAt_convex`, via Sierpinski) and contains the three +simplex vertices `(0, 0)`, `(1, 0)`, `(0, 1)` (the base cases). Any `(q, r)` in the simplex +factors as a convex combination of the three vertices. -/ +theorem concaveAt_of_mem_simplex {q r : ℝ} (hq : 0 ≤ q) (hr : 0 ≤ r) (hqr : q + r ≤ 1) : + ConcaveAt (E := E) (F := F) q r := by + -- Two-step convex combination using the three γ.1b base cases. Case-split on `q + r = 0`: + -- the inner combo needs `q + r > 0` for the normalized weights `q/(q+r)`, `r/(q+r)`. The + -- three vertex memberships AND the inner-combo result each carry an explicit + -- `(... ∈ {p | ConcaveAt p.1 p.2})` ascription via separate `have`s. The ascriptions stop + -- the elaborator from η-expanding the strict-implicit `⦃x ∈ s⦄` binders of `Convex` — + -- which would propagate metavariables through `ConcaveAt`'s `∀ {A B}` and trigger + -- weight-arg misalignment. Inlining the vertex haves OR nesting the two combos inline + -- both reproduce this; the explicit have-stack is the cheapest workaround. + change ((q, r) : ℝ × ℝ) ∈ {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} + by_cases hqr0 : q + r = 0 + · obtain ⟨rfl, rfl⟩ : q = 0 ∧ r = 0 := ⟨by linarith, by linarith⟩ + exact concaveAt_zero_zero + have hqr_pos : 0 < q + r := lt_of_le_of_ne (by linarith) (Ne.symm hqr0) + have h_v10 : ((1, 0) : ℝ × ℝ) ∈ {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := + concaveAt_one_zero + have h_v01 : ((0, 1) : ℝ × ℝ) ∈ {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := + concaveAt_zero_one + have h_v00 : ((0, 0) : ℝ × ℝ) ∈ {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := + concaveAt_zero_zero + have h_inner : + (q / (q + r)) • ((1, 0) : ℝ × ℝ) + (r / (q + r)) • ((0, 1) : ℝ × ℝ) ∈ + {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := + concaveAt_convex h_v10 h_v01 (div_nonneg hq hqr_pos.le) (div_nonneg hr hqr_pos.le) + (by rw [← add_div, div_self hqr_pos.ne']) + have h_outer : + (q + r) • ((q / (q + r)) • ((1, 0) : ℝ × ℝ) + (r / (q + r)) • ((0, 1) : ℝ × ℝ)) + + (1 - (q + r)) • ((0, 0) : ℝ × ℝ) ∈ + {p : ℝ × ℝ | ConcaveAt (E := E) (F := F) p.1 p.2} := + concaveAt_convex h_inner h_v00 hqr_pos.le (by linarith) (by ring) + have h_simp : (q + r) • ((q / (q + r)) • ((1, 0) : ℝ × ℝ) + (r / (q + r)) • (0, 1)) + + (1 - (q + r)) • ((0, 0) : ℝ × ℝ) = (q, r) := by + ext <;> simp <;> field_simp + rw [h_simp] at h_outer + exact h_outer + +/-! ## Lieb's Theorem 1, trace-form preliminary (v-form) + +The trace-form Lieb T1 — that `(A, B) ↦ Tr(K† A^q K B^r)` is jointly concave — reduces, via +Carlen's Theorem 5.12 (Ando's identity), to the **vector form** `(A, B) ↦ re ⟨v, mapL(A^q, B^r) +v⟩` jointly concave for any fixed `v ∈ E ⊗ F`. The K-version specialization through a +basis-dependent Choi-Jamiolkowski vector + transpose-of-B reconciliation is +`TensorProduct.concaveAt_trace` in `ToMathlib/Analysis/InnerProductSpace/LiebConcavityTrace.lean`. + +The reduction from `ConcaveAt` (operator-concavity of `mapL(A^q, B^r)`) to real-valued concavity +is via a **`PositiveLinearMap ℝ`**: a real-linear Loewner-monotone functional `Φ` on the CLM +space carries operator concavity through to real concavity. The v-form is the specialization +`Φ_v M := re ⟨v, M v⟩` = `ContinuousLinearMap.innerSelfFunctional v` (defined above at the +generic Hilbert-space level), which is real-linear (inner-product distributivity) and +Loewner-monotone (`IsPositive.re_inner_nonneg_right`). The bundle matches Mathlib's +`LinearMap.tracePositiveLinearMap` precedent for trace-as-PSD-monotone. -/ + +/-- **Abstract `ConcaveAt`-via-PSD-functional**: a `PositiveLinearMap` `Φ` over `ℝ` (i.e. +real-linear + Loewner-monotone) carries the operator-concavity inequality of `ConcaveAt q r` +through to a real-concavity inequality on the values `Φ (mapL (Aᵢ^q) (Bᵢ^r))`. + +This is the bridge from γ.1c's tensor-form Lieb T1 (operator-concavity of +`(A, B) ↦ mapL(A^q, B^r)`) to scalar-concavity statements via Φ. Bundling +`LinearMap` + `Monotone` as a single `PositiveLinearMap` matches Mathlib's +`LinearMap.tracePositiveLinearMap` precedent for trace-as-PSD-monotone. -/ +theorem ConcaveAt.concave_via_PSDFunctional {q r : ℝ} (hqr : ConcaveAt (E := E) (F := F) q r) + (Φ : (E ⊗[ℂ] F →L[ℂ] E ⊗[ℂ] F) →ₚ[ℝ] ℝ) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) + {B₁ B₂ : F →L[ℂ] F} (hB₁ : IsStrictlyPositive B₁) (hB₂ : IsStrictlyPositive B₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + t • Φ (TensorProduct.mapL (A₁ ^ q) (B₁ ^ r)) + + s • Φ (TensorProduct.mapL (A₂ ^ q) (B₂ ^ r)) ≤ + Φ (TensorProduct.mapL ((t • A₁ + s • A₂) ^ q) ((t • B₁ + s • B₂) ^ r)) := by + rw [← map_smul Φ, ← map_smul Φ, ← map_add Φ] + exact Φ.monotone' (hqr hA₁ hA₂ hB₁ hB₂ ht hs hts) + +/-- **v-form Lieb T1**: for any fixed `v : E ⊗ F` and `(q, r)` in the Lieb simplex +`{(q, r) | 0 ≤ q, 0 ≤ r, q + r ≤ 1}`, the real-valued function +`(A, B) ↦ re ⟨v, mapL (A^q) (B^r) v⟩` +is jointly concave on strictly positive `A : E →L[ℂ] E`, `B : F →L[ℂ] F`. + +The functional `M ↦ re ⟨v, M v⟩` is real-linear (inner-product distributivity) and +Loewner-monotone (`ContinuousLinearMap.IsPositive.re_inner_nonneg_right` on `N - M`); the +proof composes this with `ConcaveAt.concave_via_PSDFunctional` and γ.1c's +`concaveAt_of_mem_simplex`. + +This is the operator-concavity-to-scalar-concavity bridge used to derive Carlen's trace-form +Lieb T1 (Theorem 5.12 + §6.1). The full Carlen statement `(A, B) ↦ re Tr(K† A^q K B^r)` for +arbitrary `K : F →L[ℂ] E` follows via `v := choiVec K` for a basis-dependent Choi-Jamiolkowski +vector (not done here). -/ +theorem concaveAt_inner_mapL (v : E ⊗[ℂ] F) {q r : ℝ} + (hq : 0 ≤ q) (hr : 0 ≤ r) (hqr : q + r ≤ 1) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) + {B₁ B₂ : F →L[ℂ] F} (hB₁ : IsStrictlyPositive B₁) (hB₂ : IsStrictlyPositive B₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + t • RCLike.re ⟪v, TensorProduct.mapL (A₁ ^ q) (B₁ ^ r) v⟫_ℂ + + s • RCLike.re ⟪v, TensorProduct.mapL (A₂ ^ q) (B₂ ^ r) v⟫_ℂ ≤ + RCLike.re ⟪v, + TensorProduct.mapL ((t • A₁ + s • A₂) ^ q) ((t • B₁ + s • B₂) ^ r) v⟫_ℂ := + -- Apply `ConcaveAt.concave_via_PSDFunctional` with the bundled `innerSelfFunctional v`. FQN + -- form (not dot notation) avoids η-expansion of `ConcaveAt`'s `∀ {A B}` implicit binders. + ConcaveAt.concave_via_PSDFunctional (concaveAt_of_mem_simplex hq hr hqr) + (innerSelfFunctional v) hA₁ hA₂ hB₁ hB₂ ht hs hts + +end LiebTensor + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityTrace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityTrace.lean new file mode 100644 index 0000000000..b0ef7c8285 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LiebConcavityTrace.lean @@ -0,0 +1,335 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LiebConcavityRpow +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Transpose +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization + +/-! +# Lieb's Theorem 1, trace form (Choi–Jamiołkowski bridge) + +The trace-form Lieb T1 `(A, B) ↦ re Tr(K† A^q K B^r)` is jointly concave on the Lieb simplex +(`concaveAt_trace`), derived from the v-form (`concaveAt_inner_mapL`) via the Choi–Jamiołkowski +bridge. The Choi vector is `TensorProduct.matricize.symm` and the inner-product↔trace bridge is +`matricize_inner_eq_hsPairing` + `hsPairing_eq` (both pre-existing). The crux is `matricize_mapL` +— how `mapL` acts on a matricized tensor — where γ.2.b.₁'s `EuclideanSpace.transposeOp` enters. + +## Main results + +- `TensorProduct.matricize_mapL`: `matricize (mapL A B Ψ) = A ∘L matricize Ψ ∘L transposeOp B`. +- `TensorProduct.inner_mapL_matricize_symm`: the Choi–Jamiołkowski trace bridge. +- `TensorProduct.transposeOp_rpow`: `(transposeOp B) ^ r = transposeOp (B ^ r)`. +- `TensorProduct.concaveAt_trace`: Lieb's Theorem 1, trace form (strictly positive operators). +- `CFC.tendsto_rpow_add_smul_one` (in `…ContinuousFunctionalCalculus/Rpow/Isometric.lean`): the + regularization limit `(a + ε • 1) ^ p → a ^ p` (`ε → 0⁺`) — the analytic input for the PSD case. +- `TensorProduct.concaveAt_trace_isPositive`: Lieb's Theorem 1, trace form, for **positive + semidefinite** operators — the full-generality statement, obtained from `concaveAt_trace` by the + regularization limit. +- `TensorProduct.concaveAt_trace_one_sub`, `concaveAt_trace_one_sub_isPositive`, + `concaveOn_trace_one_sub_isPositive`: the single-parameter `(t, 1 - t)` N&C form (Theorem 11.11), + for strictly positive and for positive semidefinite operators, the latter both pointwise and + bundled as `ConcaveOn`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace TensorProduct + +variable {ι : Type*} [Fintype ι] + +local notation "𝒞" => EuclideanSpace.conjVec +local notation "e!" => EuclideanSpace.basisFun ι ℂ + +/-- The matricize bilinear coefficient as a `conjVec`-inner product: +`∑ k, ⟪eₖ, x⟫ * ⟪eₖ, y⟫ = ⟪conjVec x, y⟫` in the canonical basis of `EuclideanSpace ℂ ι`. -/ +theorem sum_inner_basisFun_mul (x y : EuclideanSpace ℂ ι) : + ∑ k, ⟪e! k, x⟫_ℂ * ⟪e! k, y⟫_ℂ = ⟪𝒞 x, y⟫_ℂ := by + rw [PiLp.inner_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [EuclideanSpace.basisFun_inner, EuclideanSpace.basisFun_inner, RCLike.inner_apply, + EuclideanSpace.conjVec_apply, starRingEnd_apply, star_star] + ring + +/-- Conjugation intertwines `transposeOp` with the adjoint: +`conjVec (transposeOp B φ) = B† (conjVec φ)` (from `transposeOp = conjVec ∘ star ∘ conjVec`). -/ +theorem conjVec_transposeOp (B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (φ : EuclideanSpace ℂ ι) : 𝒞 (EuclideanSpace.transposeOp B φ) = star B (𝒞 φ) := by + rw [EuclideanSpace.transposeOp_apply, EuclideanSpace.conjVec_conjVec] + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [FiniteDimensional ℂ E] in +/-- **The action of `mapL` on a matricized tensor** (the Choi-bridge crux): `mapL A B` acts on +`matricize Ψ : EuclideanSpace ℂ ι →L E` by post-composing with `A` and pre-composing with the +**transpose** `EuclideanSpace.transposeOp B` (NOT `B` — the transpose is intrinsic to the Choi +pairing). `matricize (mapL A B Ψ) = A ∘L (matricize Ψ) ∘L transposeOp B`. -/ +theorem matricize_mapL (A : E →L[ℂ] E) (B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (Ψ : E ⊗[ℂ] EuclideanSpace ℂ ι) : + matricize e! (mapL A B Ψ) = A ∘L matricize e! Ψ ∘L EuclideanSpace.transposeOp B := by + induction Ψ using TensorProduct.inductionOn with + | add x y hx hy => + simp only [map_add, hx, hy, ContinuousLinearMap.comp_add, ContinuousLinearMap.add_comp] + | tmul f g => + ext φ + rw [mapL_tmul, matricize_apply, ContinuousLinearMap.comp_apply, + ContinuousLinearMap.comp_apply, matricize_apply] + simp only [LinearMap.restrictRight_tmul, smul_smul, ← Finset.sum_smul, map_smul] + congr 1 + rw [sum_inner_basisFun_mul, sum_inner_basisFun_mul, conjVec_transposeOp, + ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_left] + +variable [CompleteSpace E] + +/-- **Choi–Jamiołkowski trace bridge**: pairing the Choi vector `matricize.symm K` through +`mapL A B` is the Frobenius/Hadamard trace `Tr(K† A K · transposeOp B)`. Assembled from +`matricize_inner_eq_hsPairing` (inner product = HS pairing), `matricize_mapL` (the `mapL` action), +and `hsPairing_eq` (HS pairing = trace of adjoint-composition). -/ +theorem inner_mapL_matricize_symm (A : E →L[ℂ] E) + (B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (K : EuclideanSpace ℂ ι →L[ℂ] E) : + ⟪(matricize e!).symm K, mapL A B ((matricize e!).symm K)⟫_ℂ = + LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L A ∘L K ∘L EuclideanSpace.transposeOp B) := by + rw [matricize_inner_eq_hsPairing e!, matricize_mapL, LinearEquiv.apply_symm_apply, + ContinuousLinearMap.hsPairing_eq] + +/-- **`transposeOp` commutes with operator `rpow`** on strictly positive operators: +`(transposeOp B) ^ r = transposeOp (B ^ r)` — the rpow specialization of `cfc_transposeOp`. -/ +theorem transposeOp_rpow {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hB : IsStrictlyPositive B) (r : ℝ) : + EuclideanSpace.transposeOp B ^ r = EuclideanSpace.transposeOp (B ^ r) := by + rw [CFC.rpow_eq_cfc_real (EuclideanSpace.transposeOp_nonneg hB.nonneg), + CFC.rpow_eq_cfc_real hB.nonneg] + refine EuclideanSpace.cfc_transposeOp hB.nonneg.isSelfAdjoint fun x hx ↦ ?_ + refine (Real.continuousAt_rpow_const x r (Or.inl ?_)).continuousWithinAt + rintro rfl + exact spectrum.not_isUnit_of_zero_mem ℝ hx hB.isUnit + +/-- `transposeOp` is ℝ-linear under scalar multiplication (via the `ℂ`-linearity + coercion). -/ +theorem transposeOp_smul_real (t : ℝ) (X : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace.transposeOp (t • X) = t • EuclideanSpace.transposeOp X := by + rw [← Complex.coe_smul, EuclideanSpace.transposeOp_smul, Complex.coe_smul] + +/-- **Lieb's Theorem 1, trace form** (Carlen §6.1): for `K : EuclideanSpace ℂ ι →L E`, strictly +positive `Aᵢ, Bᵢ`, and `(q, r)` in the Lieb simplex, `(A, B) ↦ re Tr(K† A^q K B^r)` is jointly +concave. Derived from the v-form `concaveAt_inner_mapL` at `v = matricize.symm K`, reparametrized +along `B ↦ transposeOp B`: the Choi pairing `⟨v, mapL(A^q, (transposeOp B)^r) v⟩` equals +`Tr(K† A^q K · transposeOp((transposeOp B)^r)) = Tr(K† A^q K B^r)` (`inner_mapL_matricize_symm` ++ `transposeOp_rpow` + involution). -/ +theorem concaveAt_trace (K : EuclideanSpace ℂ ι →L[ℂ] E) {q r : ℝ} + (hq : 0 ≤ q) (hr : 0 ≤ r) (hqr : q + r ≤ 1) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) + {B₁ B₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hB₁ : IsStrictlyPositive B₁) (hB₂ : IsStrictlyPositive B₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + t • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₁ ^ q) ∘L K ∘L (B₁ ^ r))) + + s • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₂ ^ q) ∘L K ∘L (B₂ ^ r))) ≤ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((t • A₁ + s • A₂) ^ q) ∘L K ∘L + ((t • B₁ + s • B₂) ^ r))) := by + have key := ContinuousLinearMap.LiebTensor.concaveAt_inner_mapL ((matricize e!).symm K) + hq hr hqr hA₁ hA₂ (EuclideanSpace.transposeOp_isStrictlyPositive hB₁) + (EuclideanSpace.transposeOp_isStrictlyPositive hB₂) ht hs hts + rw [inner_mapL_matricize_symm, inner_mapL_matricize_symm, inner_mapL_matricize_symm, + transposeOp_rpow hB₁, EuclideanSpace.transposeOp_transposeOp, + transposeOp_rpow hB₂, EuclideanSpace.transposeOp_transposeOp, + ← transposeOp_smul_real, ← transposeOp_smul_real, ← EuclideanSpace.transposeOp_add, + transposeOp_rpow (convex_isStrictlyPositive hB₁ hB₂ ht hs hts), + EuclideanSpace.transposeOp_transposeOp] at key + exact key + +/-- **Lieb's Theorem (Nielsen & Chuang, Theorem 11.11), trace form.** For a matrix +`K : EuclideanSpace ℂ ι →L E` and an exponent `t ∈ [0, 1]`, the function +`f(A, B) = re Tr(K† Aᵗ K B¹⁻ᵗ)` is jointly concave in the strictly positive operators `A, B`. +This is the single-parameter `(t, 1 - t)` special case of the general two-exponent +`concaveAt_trace` (the point `(t, 1 - t)` lies on the upper edge `q + r = 1` of the Lieb simplex), +stated in the exact shape of N&C's definition of joint concavity (11.96). -/ +theorem concaveAt_trace_one_sub (K : EuclideanSpace ℂ ι →L[ℂ] E) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : IsStrictlyPositive A₁) (hA₂ : IsStrictlyPositive A₂) + {B₁ B₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hB₁ : IsStrictlyPositive B₁) (hB₂ : IsStrictlyPositive B₂) + {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : + a • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₁ ^ t) ∘L K ∘L (B₁ ^ (1 - t)))) + + b • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₂ ^ t) ∘L K ∘L (B₂ ^ (1 - t)))) ≤ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((a • A₁ + b • A₂) ^ t) ∘L K ∘L + ((a • B₁ + b • B₂) ^ (1 - t)))) := + concaveAt_trace K ht0 (by linarith) (by linarith) hA₁ hA₂ hB₁ hB₂ ha hb hab + +/-- **Lieb's Theorem (N&C Theorem 11.11), packaged as `ConcaveOn`.** The trace form +`f(A, B) = re Tr(K† Aᵗ K B¹⁻ᵗ)` (`t ∈ [0, 1]`) is jointly concave on the product of the two cones +of strictly positive operators. This is `concaveAt_trace_one_sub` bundled as the idiomatic +`ConcaveOn` predicate: joint concavity in the sense of N&C (11.96) is exactly `ConcaveOn ℝ` +over the (convex, by `convex_isStrictlyPositive`) domain of strictly positive `(A, B)`. -/ +theorem concaveOn_trace_one_sub (K : EuclideanSpace ℂ ι →L[ℂ] E) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + ConcaveOn ℝ ({A : E →L[ℂ] E | IsStrictlyPositive A} ×ˢ + {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι | IsStrictlyPositive B}) + (fun X => RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (X.1 ^ t) ∘L K ∘L (X.2 ^ (1 - t))))) := by + refine ⟨convex_isStrictlyPositive.prod convex_isStrictlyPositive, ?_⟩ + rintro ⟨A₁, B₁⟩ ⟨hA₁, hB₁⟩ ⟨A₂, B₂⟩ ⟨hA₂, hB₂⟩ a b ha hb hab + exact concaveAt_trace_one_sub K ht0 ht1 hA₁ hA₂ hB₁ hB₂ ha hb hab + +end TensorProduct + +/-! ## Extension to positive semidefinite operators (Nielsen & Chuang's full statement) + +Nielsen & Chuang state Theorem 11.11 for **positive** — i.e. positive semidefinite — matrices `A`, +`B`; their Appendix 6 proof (Lemma A6.2) assumes the operators invertible "for convenience" and +leaves the singular case as a "minor technical modification … left as an exercise". The +strictly-positive results above (`concaveAt_trace`, `concaveAt_trace_one_sub`) are the operative +engine; the statements in this section discharge that singular case and recover N&C's full +generality, by the standard regularization limit `A ↦ A + ε • 1`, `ε → 0⁺`. This is the same +perturbation-and-limit device by which the rest of the Chapter-11 entropy development removes its +faithfulness hypotheses (e.g. `AxQM.State.vonNeumannEntropy_add_le_add'`). The analytic +input is the continuity of the operator real power along the regularizing path, +`CFC.tendsto_rpow_add_smul_one` (a general C⋆-algebra CFC-continuity lemma, in +`ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Isometric.lean`, extending +the upstream file that holds the strictly-positive `CFC.continuousOn_rpow`). -/ + +open Filter Topology + +namespace TensorProduct + +variable {ι : Type*} [Fintype ι] {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + +omit [FiniteDimensional ℂ E] in +/-- **Joint continuity of the Lieb trace functional.** If `P x → P₀` and `Q x → Q₀` along a filter, +then `re Tr(K† (P x) K (Q x)) → re Tr(K† P₀ K Q₀)`: the map `(P, Q) ↦ re Tr(K† P K Q)` is jointly +continuous, being `ContinuousLinearMap.continuous_trace` (finite dimensions) composed with the +continuous operator composition. This is the vehicle by which the strictly-positive Lieb inequality +passes to the regularization limit `ε → 0⁺`. -/ +theorem tendsto_reTrace_comp {X : Type*} {l : Filter X} (K : EuclideanSpace ℂ ι →L[ℂ] E) + {P : X → (E →L[ℂ] E)} {P₀ : E →L[ℂ] E} (hP : Tendsto P l (𝓝 P₀)) + {Q : X → (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)} + {Q₀ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hQ : Tendsto Q l (𝓝 Q₀)) : + Tendsto (fun x => RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L P x ∘L K ∘L Q x))) l + (𝓝 (RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L P₀ ∘L K ∘L Q₀)))) := by + have hFcont : Continuous (fun pq : (E →L[ℂ] E) × (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) => + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L pq.1 ∘L K ∘L pq.2))) := + RCLike.continuous_re.comp (ContinuousLinearMap.continuous_trace.comp + (continuous_const.clm_comp + (continuous_fst.clm_comp (continuous_const.clm_comp continuous_snd)))) + -- The natural type of the composite is `re Tr` applied to a pair; `congr` folds the + -- `Prod.fst`/`Prod.snd` projections pointwise (a cheap `rfl` each) rather than forcing the + -- unifier to `whnf` the trace against the ascription. + exact ((hFcont.tendsto (P₀, Q₀)).comp (hP.prodMk_nhds hQ)).congr (fun _ => rfl) + +/-- **Lieb's Theorem 1, trace form, for positive semidefinite operators** — the full-generality form +of `concaveAt_trace`. For `K : EuclideanSpace ℂ ι →L E`, `(q, r)` in the Lieb simplex, and merely +**positive** (positive semidefinite, `0 ≤ ·`) operators `Aᵢ, Bᵢ`, the map +`(A, B) ↦ re Tr(K† A^q K B^r)` satisfies the joint-concavity inequality. Proof: apply the +strictly-positive `concaveAt_trace` to the regularizations `Aᵢ + ε • 1`, `Bᵢ + ε • 1` (strictly +positive by `isStrictlyPositive_add_smul_one`), then let `ε → 0⁺`; both sides converge by +`tendsto_reTrace_comp` fed with `CFC.tendsto_rpow_add_smul_one`, and the inequality is preserved +in the limit (`le_of_tendsto_of_tendsto`). The convex combination `t • (Aᵢ + ε•1) + s • (Aⱼ + ε•1)` +on the right equals `(t • Aᵢ + s • Aⱼ) + ε • 1` because `t + s = 1` (`baseA`/`baseB`). -/ +theorem concaveAt_trace_isPositive (K : EuclideanSpace ℂ ι →L[ℂ] E) {q r : ℝ} + (hq : 0 ≤ q) (hr : 0 ≤ r) (hqr : q + r ≤ 1) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : 0 ≤ A₁) (hA₂ : 0 ≤ A₂) + {B₁ B₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hB₁ : 0 ≤ B₁) (hB₂ : 0 ≤ B₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + t • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₁ ^ q) ∘L K ∘L (B₁ ^ r))) + + s • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₂ ^ q) ∘L K ∘L (B₂ ^ r))) ≤ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((t • A₁ + s • A₂) ^ q) ∘L K ∘L + ((t • B₁ + s • B₂) ^ r))) := by + have hAsum : 0 ≤ t • A₁ + s • A₂ := add_nonneg (smul_nonneg ht hA₁) (smul_nonneg hs hA₂) + have hBsum : 0 ≤ t • B₁ + s • B₂ := add_nonneg (smul_nonneg ht hB₁) (smul_nonneg hs hB₂) + have baseA : ∀ ε : ℝ, t • A₁ + s • A₂ + ε • 1 = t • (A₁ + ε • 1) + s • (A₂ + ε • 1) := by + intro ε + have expand : t • (A₁ + ε • 1) + s • (A₂ + ε • 1) + = t • A₁ + s • A₂ + (t + s) • (ε • (1 : E →L[ℂ] E)) := by module + rw [expand, hts, one_smul] + have baseB : ∀ ε : ℝ, t • B₁ + s • B₂ + ε • 1 = t • (B₁ + ε • 1) + s • (B₂ + ε • 1) := by + intro ε + have expand : t • (B₁ + ε • 1) + s • (B₂ + ε • 1) + = t • B₁ + s • B₂ + (t + s) • (ε • (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)) := by + module + rw [expand, hts, one_smul] + -- Regularized joint-concavity inequality (strictly-positive `concaveAt_trace` at `Aᵢ + ε • 1`). + have hstep : ∀ᶠ ε : ℝ in 𝓝[>] (0 : ℝ), + t • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((A₁ + ε • 1) ^ q) ∘L K ∘L ((B₁ + ε • 1) ^ r))) + + s • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((A₂ + ε • 1) ^ q) ∘L K ∘L ((B₂ + ε • 1) ^ r))) ≤ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((t • (A₁ + ε • 1) + s • (A₂ + ε • 1)) ^ q) ∘L K ∘L + ((t • (B₁ + ε • 1) + s • (B₂ + ε • 1)) ^ r))) := by + filter_upwards [self_mem_nhdsWithin] with ε hε + exact concaveAt_trace K hq hr hqr (isStrictlyPositive_add_smul_one hA₁ hε) + (isStrictlyPositive_add_smul_one hA₂ hε) (isStrictlyPositive_add_smul_one hB₁ hε) + (isStrictlyPositive_add_smul_one hB₂ hε) ht hs hts + -- Both sides converge as `ε → 0⁺`; the right-hand base is rewritten via `baseA`/`baseB`. + have hL := ((tendsto_reTrace_comp K (CFC.tendsto_rpow_add_smul_one hA₁ hq) + (CFC.tendsto_rpow_add_smul_one hB₁ hr)).const_smul t).add + ((tendsto_reTrace_comp K (CFC.tendsto_rpow_add_smul_one hA₂ hq) + (CFC.tendsto_rpow_add_smul_one hB₂ hr)).const_smul s) + have hR := tendsto_reTrace_comp K + ((CFC.tendsto_rpow_add_smul_one hAsum hq).congr (fun ε => congrArg (· ^ q) (baseA ε))) + ((CFC.tendsto_rpow_add_smul_one hBsum hr).congr (fun ε => congrArg (· ^ r) (baseB ε))) + exact le_of_tendsto_of_tendsto hL hR hstep + +/-- **Lieb's Theorem (Nielsen & Chuang, Theorem 11.11), trace form, for positive matrices.** For a +matrix `K : EuclideanSpace ℂ ι →L E` and exponent `t ∈ [0, 1]`, the function +`f(A, B) = re Tr(K† Aᵗ K B¹⁻ᵗ)` is jointly concave in the **positive semidefinite** operators +`A, B` — N&C's statement verbatim, stated in the exact shape of N&C's definition of joint concavity +(11.96). The single-parameter `(t, 1 - t)` special case of `concaveAt_trace_isPositive`; unlike +`concaveAt_trace_one_sub`, it requires no strict-positivity hypothesis. -/ +theorem concaveAt_trace_one_sub_isPositive (K : EuclideanSpace ℂ ι →L[ℂ] E) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) + {A₁ A₂ : E →L[ℂ] E} (hA₁ : 0 ≤ A₁) (hA₂ : 0 ≤ A₂) + {B₁ B₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hB₁ : 0 ≤ B₁) (hB₂ : 0 ≤ B₂) + {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : + a • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₁ ^ t) ∘L K ∘L (B₁ ^ (1 - t)))) + + b • RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (A₂ ^ t) ∘L K ∘L (B₂ ^ (1 - t)))) ≤ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L ((a • A₁ + b • A₂) ^ t) ∘L K ∘L + ((a • B₁ + b • B₂) ^ (1 - t)))) := + concaveAt_trace_isPositive K ht0 (by linarith) (by linarith) hA₁ hA₂ hB₁ hB₂ ha hb hab + +/-- **Lieb's Theorem (N&C Theorem 11.11), positive matrices, packaged as `ConcaveOn`.** The trace +form `f(A, B) = re Tr(K† Aᵗ K B¹⁻ᵗ)` (`t ∈ [0, 1]`) is jointly concave on the product of the two +**positive semidefinite** cones — the positive-matrices sharpening of `concaveOn_trace_one_sub`. +Pointwise concavity is `concaveAt_trace_one_sub_isPositive`; the domain is convex because the +positive cone is closed under nonnegative combinations. (`convex_Ici 0` would state the latter, but +it is not usable here: matching its `Set.Ici 0` against `{· | 0 ≤ ·}` on the +`EuclideanSpace ℂ ι →L …` operator algebra sends the elaborator into a `whnf` timeout on the +`ℝ`-module instance diamond, so the cone convexity is discharged directly.) -/ +theorem concaveOn_trace_one_sub_isPositive (K : EuclideanSpace ℂ ι →L[ℂ] E) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + ConcaveOn ℝ ({A : E →L[ℂ] E | 0 ≤ A} ×ˢ + {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι | 0 ≤ B}) + (fun X => RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (ContinuousLinearMap.adjoint K ∘L (X.1 ^ t) ∘L K ∘L (X.2 ^ (1 - t))))) := by + refine ⟨?_, ?_⟩ + · rintro ⟨A₁, B₁⟩ ⟨hA₁, hB₁⟩ ⟨A₂, B₂⟩ ⟨hA₂, hB₂⟩ a b ha hb - + simp only [Set.mem_ofPred_eq] at hA₁ hB₁ hA₂ hB₂ + exact ⟨add_nonneg (smul_nonneg ha hA₁) (smul_nonneg hb hA₂), + add_nonneg (smul_nonneg ha hB₁) (smul_nonneg hb hB₂)⟩ + · rintro ⟨A₁, B₁⟩ ⟨hA₁, hB₁⟩ ⟨A₂, B₂⟩ ⟨hA₂, hB₂⟩ a b ha hb hab + exact concaveAt_trace_one_sub_isPositive K ht0 ht1 hA₁ hA₂ hB₁ hB₂ ha hb hab + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LinearMap.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LinearMap.lean new file mode 100644 index 0000000000..0fbd080699 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/LinearMap.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.LinearMap + +/-! +# Additional API for `reApplyInnerSelf` and `rankOne` + +Extra lemmas about `ContinuousLinearMap.reApplyInnerSelf` (scaling by a real scalar, additivity +over finite sums, and its value on a rank-one self-projector) and about `InnerProductSpace.rankOne` +(sesquilinearity, absorbing scalars, a sum/difference cross-term identity, and bilinearity/ +additivity over finite sums). +-/ + +@[expose] public section + +open RCLike Real ComplexConjugate + +variable {𝕜 E F : Type*} [RCLike 𝕜] + +section ReApplyInnerSelf_Seminormed + +variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +theorem ContinuousLinearMap.reApplyInnerSelf_ofReal_smul (T : E →L[𝕜] E) (x : E) (r : ℝ) : + ((r : 𝕜) • T).reApplyInnerSelf x = r * T.reApplyInnerSelf x := by + simp only [ContinuousLinearMap.reApplyInnerSelf_apply, _root_.smul_apply, + inner_smul_left, conj_ofReal, re_ofReal_mul] + +theorem ContinuousLinearMap.reApplyInnerSelf_sum {ι : Type*} (s : Finset ι) + (T : ι → E →L[𝕜] E) (x : E) : + (∑ i ∈ s, T i).reApplyInnerSelf x = ∑ i ∈ s, (T i).reApplyInnerSelf x := by + simp only [ContinuousLinearMap.reApplyInnerSelf_apply, _root_.sum_apply, + sum_inner, map_sum] + +end ReApplyInnerSelf_Seminormed + +namespace InnerProductSpace + +variable {G : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] + [SeminormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [SeminormedAddCommGroup G] [InnerProductSpace 𝕜 G] + +open ContinuousLinearMap + +/-- Sesquilinearity of `rankOne` in both arguments: scalars on the left factor through linearly, +scalars on the right factor through conjugate-linearly. -/ +lemma rankOne_smul_smul (s t : 𝕜) (x : E) (y : F) : + rankOne 𝕜 (s • x) (t • y) = (s * starRingEnd 𝕜 t) • rankOne 𝕜 x y := by + ext z + simp [rankOne_apply, smul_smul, mul_assoc] + +/-- Same scalar in both arguments: +`rankOne 𝕜 (s • x) (s • x) = (s * star s) • rankOne 𝕜 x x`. -/ +lemma rankOne_smul_smul_self (s : 𝕜) (x : F) : + rankOne 𝕜 (s • x) (s • x) = (s * starRingEnd 𝕜 s) • rankOne 𝕜 x x := + rankOne_smul_smul s s x x + +/-- A scalar on the rank-one operator absorbs into the left (linear) factor: +`c • rankOne 𝕜 x y = rankOne 𝕜 (c • x) y`. -/ +lemma smul_rankOne (c : 𝕜) (x : E) (y : F) : + c • rankOne 𝕜 x y = rankOne 𝕜 (c • x) y := by + ext z; simp [rankOne_apply, smul_smul] + +/-- Absorbing a real square root scalar into a rank-one self-projector picks up the squared scalar. +Used to identify `rankOne 𝕜 (√r • x) (√r • x)` with `r • rankOne 𝕜 x x` for `0 ≤ r`. -/ +lemma rankOne_real_sqrt_smul_self {r : ℝ} (hr : 0 ≤ r) (x : F) : + rankOne 𝕜 ((Real.sqrt r : 𝕜) • x) ((Real.sqrt r : 𝕜) • x) + = (r : 𝕜) • rankOne 𝕜 x x := by + rw [rankOne_smul_smul_self, RCLike.conj_ofReal, ← RCLike.ofReal_mul, Real.mul_self_sqrt hr] + +/-- **Cross-term cancellation for a normalised sum/difference pair.** The sum of the rank-one +projectors onto the two normalised combinations `(x ± y)/√2` equals the sum of the projectors onto +`x` and `y`: `|(x+y)/√2⟩⟨(x+y)/√2| + |(x−y)/√2⟩⟨(x−y)/√2| = |x⟩⟨x| + |y⟩⟨y|`, the `|x⟩⟨y|`, `|y⟩⟨x|` +cross terms cancelling between the two. (Two orthonormal states differing only by a sign span the +same subspace as the two states they superpose.) -/ +theorem rankOne_sqrtTwoInv_add_sub_self (x y : F) : + rankOne 𝕜 ((Real.sqrt 2 : 𝕜)⁻¹ • (x + y)) ((Real.sqrt 2 : 𝕜)⁻¹ • (x + y)) + + rankOne 𝕜 ((Real.sqrt 2 : 𝕜)⁻¹ • (x - y)) ((Real.sqrt 2 : 𝕜)⁻¹ • (x - y)) + = rankOne 𝕜 x x + rankOne 𝕜 y y := by + have hc : (Real.sqrt 2 : 𝕜)⁻¹ * (starRingEnd 𝕜) ((Real.sqrt 2 : 𝕜)⁻¹) = (1 / 2 : 𝕜) := by + rw [map_inv₀, RCLike.conj_ofReal, ← mul_inv, ← RCLike.ofReal_mul, + Real.mul_self_sqrt (by norm_num : (0 : ℝ) ≤ 2), RCLike.ofReal_ofNat] + norm_num + rw [rankOne_smul_smul, rankOne_smul_smul, hc] + ext z + simp only [_root_.add_apply, _root_.smul_apply, rankOne_apply, + inner_add_left, inner_sub_left, smul_add, smul_sub, smul_smul] + module + +/-- **Bilinearity of `rankOne` over finite sums of smul-combinations**: distributing both +arguments of `rankOne` as linear combinations produces a double sum, with the antilinearity +in the second argument appearing as `star (d j)` on the scalar: +`rankOne 𝕜 (∑ i, c i • a i) (∑ j, d j • b j)` + `= ∑ i, ∑ j, (c i * star (d j)) • rankOne 𝕜 (a i) (b j)`. -/ +lemma rankOne_sum_smul_sum_smul {ι ι' : Type*} (s : Finset ι) (s' : Finset ι') + (a : ι → E) (b : ι' → F) (c : ι → 𝕜) (d : ι' → 𝕜) : + rankOne 𝕜 (∑ i ∈ s, c i • a i) (∑ j ∈ s', d j • b j) = + ∑ i ∈ s, ∑ j ∈ s', (c i * starRingEnd 𝕜 (d j)) • rankOne 𝕜 (a i) (b j) := by + ext z + simp only [rankOne_apply, sum_inner, inner_smul_left, + _root_.sum_apply, _root_.smul_apply, + Finset.smul_sum, Finset.sum_mul, Finset.sum_smul, smul_smul] + exact Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ by ring_nf + +/-- **Bi-additivity of `rankOne` over finite sums.** The rank-one operator of two finite sums is the +double sum of the rank-one operators of the summands: `|∑ₖ uₖ⟩⟨∑ₗ vₗ| = ∑ₖ ∑ₗ |uₖ⟩⟨vₗ|`. The +coefficient-free special case of `rankOne_sum_smul_sum_smul` (both scalar families constantly +`1`). -/ +lemma rankOne_sum_sum {W : Type*} [SeminormedAddCommGroup W] [InnerProductSpace 𝕜 W] + {ι : Type*} [Fintype ι] (u v : ι → W) : + (rankOne 𝕜 (∑ k, u k) (∑ l, v l) : W →L[𝕜] W) = ∑ k, ∑ l, rankOne 𝕜 (u k) (v l) := by + have h := rankOne_sum_smul_sum_smul (𝕜 := 𝕜) Finset.univ Finset.univ u v + (fun _ => (1 : 𝕜)) (fun _ => (1 : 𝕜)) + simpa only [one_smul, starRingEnd_apply, star_one, one_mul] using h + +end InnerProductSpace + +namespace ContinuousLinearMap + +open InnerProductSpace + +variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- The `reApplyInnerSelf` of a rank-one self projector `|d⟩⟨d|`: the real part of +`⟪|d⟩⟨d| x, x⟫` is `‖⟪d, x⟫‖²`. -/ +theorem reApplyInnerSelf_rankOne_self (d x : E) : + (rankOne 𝕜 d d).reApplyInnerSelf x = ‖inner 𝕜 d x‖ ^ 2 := by + rw [reApplyInnerSelf_apply, rankOne_apply, inner_smul_left, RCLike.conj_mul] + simp + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Matricization.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Matricization.lean new file mode 100644 index 0000000000..f6f85d9c09 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Matricization.lean @@ -0,0 +1,277 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# Matricization (vectorization) on a tensor product + +The vectorization isomorphism `matricize b : E ⊗[𝕜] F ≃ₗ[𝕜] (F →L[𝕜] E)`, +parametrized by an orthonormal basis `b` on the right factor `F`. It reshapes a bipartite +vector `Ψ : E ⊗[𝕜] F` into a continuous linear map by +`matricize b Ψ φ = ∑ k, ⟪b k, φ⟫_𝕜 • restrictRight b k Ψ`. The canonical bridge between +Schmidt decomposition (a "vectorized" state on the bipartite space) and the SVD of an +operator (the same data viewed as a linear map). + +The inner product of bipartite vectors equals the **Hilbert–Schmidt** pairing of their +matricizations (`matricize_inner_eq_trace_adjoint_comp`). The map is therefore an +isometry for the HS-norm but a `LinearEquiv` (rather than a `LinearIsometryEquiv`) at +the CLM-with-operator-norm level. + +## Main definitions + +- `TensorProduct.matricize` : the basis-parametric `LinearEquiv` + `E ⊗[𝕜] F ≃ₗ[𝕜] (F →L[𝕜] E)`. + +## Main results + +- `TensorProduct.matricize_apply` / `TensorProduct.matricize_symm_apply` : the + defining apply forms. +- `TensorProduct.matricize_inner_eq_trace_adjoint_comp` : the Hilbert–Schmidt bridge, + `⟪Ψ₁, Ψ₂⟫ = trace ((matricize b Ψ₁)† ∘ matricize b Ψ₂)`. +-/ + +@[expose] public section + +/-! ## Orthonormal-basis collapse helpers + +Two general lemmas used in the abstract matricize construction below: they package +the basis-orthonormality `δ`-collapse in both inner-product orientations. +(Basis decomposition `∑ ℓ, ⟪b ℓ, φ⟫ • b ℓ = φ` is already in Mathlib as +`OrthonormalBasis.sum_repr'`.) -/ + +namespace OrthonormalBasis + +open scoped InnerProductSpace + +variable {ι : Type*} [Fintype ι] + {𝕜 : Type*} [RCLike 𝕜] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + +/-- Basis-orthonormality `δ`-collapse (summed-index on the LEFT of the inner product): +`∑ k, ⟪b k, b ℓ⟫_𝕜 • f k = f ℓ`. -/ +theorem sum_inner_basis_smul_left {G : Type*} [AddCommMonoid G] [Module 𝕜 G] + (b : OrthonormalBasis ι 𝕜 F) (f : ι → G) (ℓ : ι) : + ∑ k, ⟪b k, b ℓ⟫_𝕜 • f k = f ℓ := by + classical + rw [Finset.sum_eq_single ℓ (fun k _ hk ↦ by rw [b.inner_eq_ite, ite_eq_right hk, zero_smul]) + (fun h ↦ absurd (Finset.mem_univ ℓ) h), b.inner_eq_ite, ite_eq_left rfl, one_smul] + +/-- Basis-orthonormality `δ`-collapse (summed-index on the RIGHT of the inner product): +`∑ k, ⟪b ℓ, b k⟫_𝕜 • f k = f ℓ`. -/ +theorem sum_inner_basis_smul_right {G : Type*} [AddCommMonoid G] [Module 𝕜 G] + (b : OrthonormalBasis ι 𝕜 F) (f : ι → G) (ℓ : ι) : + ∑ k, ⟪b ℓ, b k⟫_𝕜 • f k = f ℓ := by + classical + rw [Finset.sum_eq_single ℓ + (fun k _ hk ↦ by rw [b.inner_eq_ite, ite_eq_right (Ne.symm hk), zero_smul]) + (fun h ↦ absurd (Finset.mem_univ ℓ) h), b.inner_eq_ite, ite_eq_left rfl, one_smul] + +end OrthonormalBasis + +/-! ## Matricization on `E ⊗[𝕜] F` + +Basis-parametric `LinearEquiv` `E ⊗[𝕜] F ≃ₗ[𝕜] (F →L[𝕜] E)` for inner-product spaces +`E, F` over `RCLike 𝕜` and an orthonormal basis `b` on the right factor `F`. +Finite-dimensionality of `F` is a consequence of carrying a basis indexed by +`[Fintype ι]`, not a declared instance; `E` is unconstrained beyond the inner-product +structure. -/ + +namespace TensorProduct + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + {ι : Type*} [Fintype ι] + +open scoped InnerProductSpace + +/-- The forward `LinearMap` of `TensorProduct.matricize`. See `matricize` for the bundled +`LinearEquiv` and the math docstring. -/ +noncomputable def matricizeToCLM (b : OrthonormalBasis ι 𝕜 F) : + E ⊗[𝕜] F →ₗ[𝕜] (F →L[𝕜] E) where + toFun Ψ := ∑ k : ι, (innerSL 𝕜 (b k)).smulRight (LinearMap.restrictRight b k Ψ) + map_add' Ψ₁ Ψ₂ := by + ext φ + simp [ContinuousLinearMap.smulRight_apply, + innerSL_apply_apply, Finset.sum_add_distrib, smul_add] + map_smul' c Ψ := by + ext φ + simp [ContinuousLinearMap.smulRight_apply, + innerSL_apply_apply, Finset.smul_sum, smul_smul, mul_comm] + +@[simp] +theorem matricizeToCLM_apply (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) (φ : F) : + matricizeToCLM b Ψ φ = ∑ k : ι, ⟪b k, φ⟫_𝕜 • LinearMap.restrictRight b k Ψ := by + simp [matricizeToCLM, ContinuousLinearMap.smulRight_apply, + innerSL_apply_apply] + +/-- The inverse `LinearMap` of `TensorProduct.matricize`: `T ↦ ∑ k, T (b k) ⊗ₜ b k`. -/ +noncomputable def matricizeFromCLM (b : OrthonormalBasis ι 𝕜 F) : + (F →L[𝕜] E) →ₗ[𝕜] E ⊗[𝕜] F where + toFun T := ∑ k : ι, T (b k) ⊗ₜ[𝕜] b k + map_add' T₁ T₂ := by simp [TensorProduct.add_tmul, Finset.sum_add_distrib] + map_smul' c T := by simp [TensorProduct.smul_tmul', Finset.smul_sum] + +@[simp] +theorem matricizeFromCLM_apply (b : OrthonormalBasis ι 𝕜 F) (T : F →L[𝕜] E) : + matricizeFromCLM b T = ∑ k : ι, T (b k) ⊗ₜ[𝕜] b k := + rfl + +/-- `matricizeToCLM b` post-composed with `matricizeFromCLM b` is the identity on +`F →L[𝕜] E`. The right-inverse half of `TensorProduct.matricize` below. -/ +theorem matricizeToCLM_comp_matricizeFromCLM (b : OrthonormalBasis ι 𝕜 F) : + (matricizeToCLM (E := E) b).comp (matricizeFromCLM b) = LinearMap.id := + LinearMap.ext fun T ↦ ContinuousLinearMap.ext fun φ ↦ by + have inner_collapse : ∀ ℓ, LinearMap.restrictRight b ℓ (∑ k, T (b k) ⊗ₜ[𝕜] b k) + = T (b ℓ) := fun ℓ ↦ by + rw [map_sum] + simp_rw [LinearMap.restrictRight_tmul] + exact b.sum_inner_basis_smul_right (T ∘ b) ℓ + simp only [LinearMap.coe_comp, Function.comp_apply, matricizeFromCLM_apply, + matricizeToCLM_apply, LinearMap.id_coe, id_eq] + simp_rw [inner_collapse, ← T.map_smul, ← map_sum, b.sum_repr'] + +/-- `matricizeFromCLM b` post-composed with `matricizeToCLM b` is the identity on +`E ⊗[𝕜] F`. The left-inverse half of `TensorProduct.matricize` below. -/ +theorem matricizeFromCLM_comp_matricizeToCLM (b : OrthonormalBasis ι 𝕜 F) : + (matricizeFromCLM b).comp (matricizeToCLM (E := E) b) = LinearMap.id := + LinearMap.ext fun Ψ ↦ by + simp only [LinearMap.coe_comp, Function.comp_apply, matricizeFromCLM_apply, + matricizeToCLM_apply, LinearMap.id_coe, id_eq] + conv_rhs => rw [← LinearMap.sum_embedRight_restrictRight_eq_self b Ψ] + exact Finset.sum_congr rfl fun k _ ↦ by + rw [LinearMap.embedRight_apply, + b.sum_inner_basis_smul_left (LinearMap.restrictRight b · Ψ)] + +/-- **Abstract matricization (bra-ket isomorphism)**, basis-parametric on the F-side. +For an orthonormal basis `b : OrthonormalBasis ι 𝕜 F`, this `LinearEquiv` identifies +`Ψ : E ⊗[𝕜] F` with the continuous linear map `F →L[𝕜] E` characterized by + + `matricize b Ψ φ = ∑ k, ⟪b k, φ⟫_𝕜 • restrictRight b k Ψ`, + +i.e., the basis-defined bilinear pairing on `F` (the inner product is sesquilinear, but +indexing by the orthonormal basis turns it into a linear pairing on coordinates) applied +slot-by-slot. The inverse sends a CLM `T : F →L[𝕜] E` to the bipartite vector +`∑ k, T (b k) ⊗ₜ b k`. + +On the construction route: Riesz is conjugate-linear and not viable; direct bilinear extension via +`ContinuousLinearMap.smulRight` + sum is the chosen route. + +cf. `dualTensorHomEquivOfBasis` for the algebraic dual-space analog `M* ⊗ N ≃ M →ₗ N` +on any free module: that variant is `Module.Dual`-based and produces `LinearMap`-valued +output; ours is inner-product / orthonormal-basis-parametric and `ContinuousLinearMap`- +valued, which is what lets Route 2 sidestep the Riesz conjugate-linearity. -/ +noncomputable def matricize (b : OrthonormalBasis ι 𝕜 F) : + E ⊗[𝕜] F ≃ₗ[𝕜] (F →L[𝕜] E) := + LinearEquiv.ofLinearMap (matricizeToCLM b) (matricizeFromCLM b) + (matricizeToCLM_comp_matricizeFromCLM b) + (matricizeFromCLM_comp_matricizeToCLM b) + +theorem matricize_apply (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) (φ : F) : + matricize b Ψ φ = ∑ k : ι, ⟪b k, φ⟫_𝕜 • LinearMap.restrictRight b k Ψ := + matricizeToCLM_apply b Ψ φ + +/-- Symm-apply form of `TensorProduct.matricize`: +`(matricize b).symm T = ∑ k, T (b k) ⊗ₜ b k`. -/ +@[simp] +theorem matricize_symm_apply (b : OrthonormalBasis ι 𝕜 F) (T : F →L[𝕜] E) : + (matricize b).symm T = ∑ k : ι, T (b k) ⊗ₜ[𝕜] b k := + rfl + +/-- **Matricize evaluated on a basis vector** equals the right-restriction: +`matricize b Ψ (b k) = restrictRight b k Ψ`. Specialization of `matricize_apply` +with `φ = b k`; the sum on the RHS collapses by orthonormality. -/ +@[simp] +theorem matricize_basis_apply (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) (k : ι) : + matricize b Ψ (b k) = LinearMap.restrictRight b k Ψ := by + rw [matricize_apply, b.sum_inner_basis_smul_left] + +/-! ### Adjoint of `matricize` and the Hilbert–Schmidt pairing bridge + +Coordinate-form characterization of `(matricize b Ψ).adjoint` and the Hilbert–Schmidt +bridge: the inner product on `E ⊗[𝕜] F` equals the Hilbert–Schmidt pairing of the +matricizations. The adjoint and trace operations require `[CompleteSpace _]` +(CLM-adjoint) and `[FiniteDimensional 𝕜 F]` (trace), so this section declares those +instances. -/ + +section Adjoint + +variable [CompleteSpace E] [CompleteSpace F] + +/-- **Coordinate form of `matricize`-adjoint**: the `k`-th basis coefficient of +`(matricize b Ψ).adjoint x` is the inner product of `restrictRight b k Ψ` with `x`. +Direct consequence of `ContinuousLinearMap.adjoint_inner_left` + the apply form +`matricize_apply` evaluated at the basis vector `b k`. -/ +theorem matricize_adjoint_apply (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) + (x : E) (k : ι) : + ⟪b k, (matricize b Ψ).adjoint x⟫_𝕜 = ⟪LinearMap.restrictRight b k Ψ, x⟫_𝕜 := by + rw [ContinuousLinearMap.adjoint_inner_right, matricize_apply, + b.sum_inner_basis_smul_left (fun ℓ ↦ LinearMap.restrictRight b ℓ Ψ)] + +variable [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + +/-- **Hilbert–Schmidt bridge**: the inner product on `E ⊗[𝕜] F` equals the trace +pairing of the matricizations, +`⟪Ψ₁, Ψ₂⟫ = trace ((matricize Ψ₁)† ∘ matricize Ψ₂)`. + +Used in the Phase B abstract Uhlmann saturation proof +(`matricize_compose_optimal_eq_*`-style identities) where the inner-product-as-HS-trace +identity is the load-bearing step. + +Proof: decompose `Ψ₂ = ∑ k, embedRight b k (restrictRight b k Ψ₂)`, distribute the +inner product through the sum, use `adjoint_embedRight` to turn each +`⟪Ψ₁, embedRight b k _⟫` into `⟪restrictRight b k Ψ₁, _⟫`, then match with +`LinearMap.trace_eq_sum_inner` of the RHS evaluated on the basis. -/ +theorem matricize_inner_eq_trace_adjoint_comp (b : OrthonormalBasis ι 𝕜 F) + (Ψ₁ Ψ₂ : E ⊗[𝕜] F) : + inner 𝕜 Ψ₁ Ψ₂ = LinearMap.trace 𝕜 _ + ((matricize b Ψ₁).adjoint.toLinearMap ∘ₗ (matricize b Ψ₂).toLinearMap) := by + rw [LinearMap.trace_eq_sum_inner _ b] + simp_rw [LinearMap.coe_comp, Function.comp_apply, ContinuousLinearMap.coe_coe, + matricize_basis_apply, matricize_adjoint_apply] + conv_lhs => rw [← LinearMap.sum_embedRight_restrictRight_eq_self b Ψ₂] + rw [inner_sum] + exact Finset.sum_congr rfl fun k _ ↦ by + rw [← LinearMap.adjoint_inner_left, LinearMap.adjoint_embedRight] + +/-- **Matricize-side HS-pairing form** of the bipartite inner product (abstract): +`⟪Ψ₁, Ψ₂⟫ = (matricize Ψ₂).hsPairing (matricize Ψ₁)`. Direct from +`matricize_inner_eq_trace_adjoint_comp` + `ContinuousLinearMap.hsPairing_eq`. -/ +theorem matricize_inner_eq_hsPairing (b : OrthonormalBasis ι 𝕜 F) (Ψ₁ Ψ₂ : E ⊗[𝕜] F) : + inner 𝕜 Ψ₁ Ψ₂ = (matricize b Ψ₂).hsPairing (matricize b Ψ₁) := by + rw [matricize_inner_eq_trace_adjoint_comp b, ContinuousLinearMap.hsPairing_eq, + ContinuousLinearMap.toLinearMap_comp] + +/-- **Purification identity**: the right-partial-trace of the rank-one self-projection +onto `Ψ` factors as `matricize b Ψ ∘ (matricize b Ψ)†`, basis-parametric on `b`. + +Structural identity behind the purification construction: the reduced density matrix +on the first factor of a bipartite pure state is the outer-product expansion of the +columns of the matricization. -/ +theorem partialTraceRight_rankOne_self (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) : + LinearMap.partialTraceRight b ((InnerProductSpace.rankOne 𝕜 Ψ Ψ).toLinearMap) = + ((matricize b Ψ).comp (matricize b Ψ).adjoint).toLinearMap := by + ext x + simp only [LinearMap.partialTraceRight_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, LinearMap.map_smul, + Function.comp_apply, ContinuousLinearMap.coe_comp, matricize_apply, + matricize_adjoint_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [← LinearMap.embedRight_apply b, ← LinearMap.adjoint_inner_left, + LinearMap.adjoint_embedRight] + +end Adjoint + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MatricizationRank.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MatricizationRank.lean new file mode 100644 index 0000000000..a64b8da82d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MatricizationRank.lean @@ -0,0 +1,195 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas + +/-! +# Rank bounds: sub/triangle inequalities, and the rank of matricized/diagonalised operators + +Six finite-dimensional rank facts, used to compute the Schmidt number of a bipartite pure state. +Three **bound** it: by the number of terms in a product decomposition (Nielsen–Chuang, Problem +2.2(2)), and — via the rank triangle inequality — by the Schmidt numbers of a superposition's +summands (Problem 2.2(3)). Two **characterise simplicity**: a matricized elementary tensor is +rank `≤ 1`, and conversely a rank-`≤ 1` matricization comes from an elementary tensor (the +Schmidt-number-`1` ⇔ product-state core, Exercise 2.78). One **reads a rank off a diagonalisation**: +the rank of a spectral sum `∑ᵢ cᵢ |vᵢ⟩⟨vᵢ|` over an orthonormal family is the number of non-zero +coefficients (used for the rank of a reduced density operator). + +## Main results + +* `LinearMap.finrank_range_sum_le` — **subadditivity of rank over a finite sum**: the rank + (`finrank` of the range) of a finite sum `∑ i ∈ s, f i` of linear maps into a + finite-dimensional space is at most the sum of the ranks of the summands. This is the + `finrank`-valued analogue of `LinearMap.rank_finset_sum_le` (which is `Cardinal`-valued). +* `LinearMap.finrank_range_add_le` — **binary subadditivity of rank**: `finrank (range (f + g)) + ≤ finrank (range f) + finrank (range g)`. The binary form of `finrank_range_sum_le`; the + `finrank`-valued analogue of `LinearMap.rank_add_le`. +* `LinearMap.finrank_range_le_finrank_range_add_add` — the **rank triangle inequality**: + `finrank (range f) ≤ finrank (range (f + g)) + finrank (range g)`. Applied with the two + summands exchanged it yields the reverse-triangle bound `|rank f − rank g| ≤ rank (f + g)`. +* `TensorProduct.finrank_range_matricize_tmul_le_one` — the matricization + `matricize b (x ⊗ₜ y)` of an elementary tensor is a **rank-`≤ 1` operator**: its range is + contained in the line `𝕜 ∙ x` (each column is a scalar multiple of `x`), so its rank is + at most one. +* `TensorProduct.exists_tmul_of_finrank_range_matricize_le_one` — the **converse**: a tensor + whose matricization has rank `≤ 1` is an elementary tensor `x ⊗ₜ y`. Together the two say a + bipartite tensor is simple iff its matricization is rank `≤ 1`. +* `InnerProductSpace.finrank_range_sum_smul_rankOne_self` — the rank of a spectral sum + `∑ᵢ cᵢ |vᵢ⟩⟨vᵢ|` of rank-one self-projectors over an orthonormal family, with `cᵢ ≠ 0`, is the + number of terms. Reads the rank off a diagonalised (reduced) density operator. +-/ + +open scoped InnerProductSpace TensorProduct + +@[expose] public section + +namespace LinearMap + +variable {K : Type*} {V V' : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + [AddCommGroup V'] [Module K V'] [FiniteDimensional K V'] + +/-- **Subadditivity of rank over a finite sum**: the rank (`finrank` of the range) of a +finite sum `∑ i ∈ s, f i` of linear maps into a finite-dimensional space is at most the sum +of the ranks of the summands. The `finrank`-valued form of `LinearMap.rank_finset_sum_le`. -/ +theorem finrank_range_sum_le {ι : Type*} (s : Finset ι) (f : ι → V →ₗ[K] V') : + Module.finrank K ↥(LinearMap.range (∑ i ∈ s, f i)) + ≤ ∑ i ∈ s, Module.finrank K ↥(LinearMap.range (f i)) := by + classical + induction s using Finset.induction_on with + | empty => rw [Finset.sum_empty, Finset.sum_empty, LinearMap.range_zero, finrank_bot] + | @insert a s ha ih => + rw [Finset.sum_insert ha, Finset.sum_insert ha] + refine (Submodule.finrank_mono (LinearMap.range_add_le _ _)).trans ?_ + exact (Submodule.finrank_add_le_finrank_add_finrank _ _).trans (Nat.add_le_add_left ih _) + +/-- **Binary subadditivity of rank**: the rank (`finrank` of the range) of a sum of two +linear maps into a finite-dimensional space is at most the sum of their ranks. The binary +form of `LinearMap.finrank_range_sum_le`; the `finrank`-valued analogue of the two-argument +`LinearMap.rank_add_le`. -/ +theorem finrank_range_add_le (f g : V →ₗ[K] V') : + Module.finrank K ↥(LinearMap.range (f + g)) + ≤ Module.finrank K ↥(LinearMap.range f) + Module.finrank K ↥(LinearMap.range g) := + (Submodule.finrank_mono (LinearMap.range_add_le f g)).trans + (Submodule.finrank_add_le_finrank_add_finrank _ _) + +/-- **Rank triangle inequality** (one side): the rank of `f` is bounded above by the rank of +the sum `f + g` plus the rank of `g`, because `f = (f + g) + (-g)` and rank is subadditive +(`finrank_range_add_le`) and negation-invariant (`LinearMap.range_neg`). Applying this with the +two summands exchanged yields `|rank f − rank g| ≤ rank (f + g)`, the reverse-triangle bound +that pins a rank below by the rank of a perturbation of it. -/ +theorem finrank_range_le_finrank_range_add_add (f g : V →ₗ[K] V') : + Module.finrank K ↥(LinearMap.range f) + ≤ Module.finrank K ↥(LinearMap.range (f + g)) + + Module.finrank K ↥(LinearMap.range g) := + calc Module.finrank K ↥(LinearMap.range f) + = Module.finrank K ↥(LinearMap.range ((f + g) + -g)) := by rw [add_neg_cancel_right] + _ ≤ Module.finrank K ↥(LinearMap.range (f + g)) + + Module.finrank K ↥(LinearMap.range (-g)) := finrank_range_add_le _ _ + _ = Module.finrank K ↥(LinearMap.range (f + g)) + + Module.finrank K ↥(LinearMap.range g) := by rw [LinearMap.range_neg] + +end LinearMap + +namespace TensorProduct + +variable {𝕜 : Type*} {E F ι : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [Fintype ι] + +/-- The matricization `matricize b (x ⊗ₜ y)` of an elementary tensor is a **rank-`≤ 1` +operator**: every value `matricize b (x ⊗ₜ y) φ = ∑ k, ⟪b k, φ⟫ • ⟪b k, y⟫ • x` is a scalar +multiple of `x`, so its range lies in the line `𝕜 ∙ x` and its rank is at most one. -/ +theorem finrank_range_matricize_tmul_le_one (b : OrthonormalBasis ι 𝕜 F) (x : E) (y : F) : + Module.finrank 𝕜 ↥(LinearMap.range (matricize b (x ⊗ₜ[𝕜] y)).toLinearMap) ≤ 1 := by + have hle : Module.finrank 𝕜 ↥(𝕜 ∙ x) ≤ 1 := by + rcases eq_or_ne x 0 with hx | hx + · subst hx + rw [Submodule.span_singleton_eq_bot.mpr rfl, finrank_bot] + norm_num + · simp [finrank_span_singleton hx] + refine (Submodule.finrank_mono ?_).trans hle + intro w hw + obtain ⟨z, rfl⟩ := hw + rw [ContinuousLinearMap.coe_coe, matricize_apply] + refine Submodule.sum_mem _ fun k _ => ?_ + rw [LinearMap.restrictRight_tmul, smul_smul] + exact Submodule.smul_mem _ _ (Submodule.mem_span_singleton_self x) + +/-- **Converse of `finrank_range_matricize_tmul_le_one`**: a bipartite tensor whose +matricization is a **rank-`≤ 1` operator is an elementary tensor**. If the range of +`matricize b Ψ` is at most one-dimensional it is a line `𝕜 ∙ x` (`finrank_le_one_iff_isPrincipal`), +so each column `matricize b Ψ (b k) = cₖ • x` is a multiple of `x`; reconstructing `Ψ` from its +columns (`matricize_symm_apply`) then factors `x` out of every term, +`Ψ = ∑ k, (cₖ • x) ⊗ₜ b k = x ⊗ₜ (∑ k, cₖ • b k)`. Together with the forward bound this makes +"`Ψ` is a simple tensor" equivalent to "`matricize b Ψ` has rank `≤ 1`" — the linear-algebra core +of the Schmidt-number-`1` characterisation of product states (Nielsen–Chuang, Exercise 2.78). -/ +theorem exists_tmul_of_finrank_range_matricize_le_one [FiniteDimensional 𝕜 E] + (Ψ : E ⊗[𝕜] F) (b : OrthonormalBasis ι 𝕜 F) + (h : Module.finrank 𝕜 ↥(LinearMap.range (matricize b Ψ).toLinearMap) ≤ 1) : + ∃ (x : E) (y : F), Ψ = x ⊗ₜ[𝕜] y := by + classical + have hprin : (LinearMap.range (matricize b Ψ).toLinearMap).IsPrincipal := + (Submodule.finrank_le_one_iff_isPrincipal _).mp h + obtain ⟨x, hx⟩ := hprin.principal + have hmem : ∀ k, (matricize b Ψ) (b k) ∈ Submodule.span 𝕜 {x} := by + intro k; rw [← hx]; exact LinearMap.mem_range_self _ (b k) + choose c hc using fun k => Submodule.mem_span_singleton.mp (hmem k) + refine ⟨x, ∑ k, c k • b k, ?_⟩ + have hsymm : Ψ = ∑ k : ι, (matricize b Ψ) (b k) ⊗ₜ[𝕜] b k := by + conv_lhs => rw [← (matricize b).symm_apply_apply Ψ] + rw [matricize_symm_apply] + rw [hsymm, tmul_sum] + exact Finset.sum_congr rfl fun k _ => by rw [← hc k, smul_tmul] + +end TensorProduct + +namespace InnerProductSpace + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- The **rank of a spectral sum of rank-one self-projectors** `∑ᵢ cᵢ |vᵢ⟩⟨vᵢ|` over an +orthonormal family `v : Fin n → E` with all coefficients `cᵢ ≠ 0` is exactly `n`. The operator +has the `vᵢ` as eigenvectors (eigenvalue `cᵢ`), so its range is the `n`-dimensional span of the +orthonormal family: each `vⱼ = P (cⱼ⁻¹ • vⱼ)` lies in the range, and every value is a combination +of the `vᵢ`. Used to read the Schmidt number off the diagonalised reduced density operator +`ρ = ∑ᵢ λᵢ² |iᴬ⟩⟨iᴬ|` (Nielsen–Chuang §2.5). -/ +theorem finrank_range_sum_smul_rankOne_self {n : ℕ} (v : Fin n → E) (c : Fin n → 𝕜) + (hv : Orthonormal 𝕜 v) (hc : ∀ i, c i ≠ 0) : + Module.finrank 𝕜 (LinearMap.range + (∑ i, c i • (InnerProductSpace.rankOne 𝕜 (v i) (v i)).toLinearMap)) = n := by + classical + have hrange : LinearMap.range + (∑ i, c i • (InnerProductSpace.rankOne 𝕜 (v i) (v i)).toLinearMap) + = Submodule.span 𝕜 (Set.range v) := by + apply le_antisymm + · rw [LinearMap.range_le_iff_comap, eq_top_iff] + intro x _ + rw [Submodule.mem_comap, LinearMap.sum_apply] + refine Submodule.sum_mem _ fun i _ => ?_ + simp only [LinearMap.smul_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, smul_smul] + exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨i, rfl⟩) + · rw [Submodule.span_le] + rintro _ ⟨j, rfl⟩ + refine ⟨(c j)⁻¹ • v j, ?_⟩ + rw [LinearMap.sum_apply, Finset.sum_eq_single j] + · simp only [LinearMap.smul_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, inner_smul_right, orthonormal_iff_ite.mp hv, smul_smul, + ite_true, mul_one] + rw [mul_inv_cancel₀ (hc j), one_smul] + · intro i _ hij + simp only [LinearMap.smul_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, inner_smul_right, orthonormal_iff_ite.mp hv, + ite_eq_right hij, mul_zero, zero_smul, smul_zero] + · intro h; exact absurd (Finset.mem_univ j) h + rw [hrange, finrank_span_eq_card hv.linearIndependent, Fintype.card_fin] + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MinimalOperatorSum.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MinimalOperatorSum.lean new file mode 100644 index 0000000000..cd8b18c220 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MinimalOperatorSum.lean @@ -0,0 +1,172 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumFreedom +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization + +/-! # The minimal operator-sum representation: at most `d²` operation elements + +For a finite family of operation elements `E : ι → (H →L[ℂ] G)`, the **operator-sum map** +`ContinuousLinearMap.krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` may be indexed by an arbitrarily large `ι`. +This file proves that it can always be re-expressed with at most `dim G · dim H` operation +elements — and, in the square case `G = H`, at most `d²` where `d = dim H`. This is +Nielsen & Chuang, *Quantum Computation and Quantum Information*, **Theorem 8.3** (the square +case, `exists_krausSumₗ_eq_fin_finrank_sq`), together with its `d`-to-`d′` generalization, +**Exercise 8.11** (`exists_krausSumₗ_eq_fin_finrank`). + +## Main results + +* `ContinuousLinearMap.krausSumₗ_eq_of_choi_eq` — **the Choi operator determines the operator-sum + map**: if the vectorized (Choi) rank-one sums agree, + `Σᵢ |vec Eᵢ⟩⟨vec Eᵢ| = Σₖ |vec Fₖ⟩⟨vec Fₖ|` on `G ⊗ H` (`vec = (matricize b).symm`), even over + *different* index sets, then `krausSumₗ E = krausSumₗ F`. +* `ContinuousLinearMap.exists_krausSumₗ_eq_fin_finrank` — **Exercise 8.11**: every operator-sum + map on a `d`-input, `d′`-output space has an equal operator-sum map indexed by + `Fin (dim G · dim H)`. +* `ContinuousLinearMap.exists_krausSumₗ_eq_fin_finrank_sq` — **Theorem 8.3**: on a `d`-dimensional + system (`G = H`), an equal operator-sum map indexed by `Fin (d²)`. + +## Implementation notes + +The engine is the linear-algebra reduction +`InnerProductSpace.exists_sum_rankOne_self_eq_fin_finrank` (the sum of rank-one projectors of any +finite family equals one over `Fin (finrank)`), applied to the **Choi vectors** +`vec Eᵢ = (TensorProduct.matricize b).symm Eᵢ ∈ G ⊗ H`, whose ambient space has +`finrank = dim G · dim H`. Un-vectorizing the reduced family `Wₖ` by `matricize b` yields the +operation elements `Fₖ`, whose Choi operator equals that of `E` by construction; the two +operator-sum maps then agree by `krausSumₗ_eq_of_choi_eq`, and reindexing to the dimension bound is +`ContinuousLinearMap.krausSumₗ_comp_equiv`. + +The Choi-determines-map step is self-contained via the general operator-sum "freedom" API of +`ToMathlib.Analysis.InnerProductSpace.OperatorSumFreedom`: equal Choi operators over the (possibly +distinct) index sets `ι` and `κ` are padded to a common index `ι ⊕ κ` (appending zero operators — +`krausSumₗ_sumElim_zero_left`/`_right` — changes neither the Choi operator nor the operator-sum +map), where the vector form of Nielsen & Chuang Theorem 2.6 +(`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup`) supplies the relating unitary; +transporting it back through `matricize` and applying `krausSumₗ_eq_of_unitary_smul` gives the equal +operator-sum maps. In particular this route uses only the vectorization `TensorProduct.matricize` +and the rank-one reduction; it does not require the full Choi–Jamiołkowski correspondence. + +The bound `Fin (dim G · dim H)` (resp. `Fin d²`) is N&C's "at most `M`" with `1 ≤ M ≤ d²` in padded +form: the produced family has exactly `dim G · dim H` slots, some of which may be the zero operator +(a zero operation element contributes nothing to the operator-sum map). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +/-- **The Choi operator determines the operator-sum map.** Fix an orthonormal basis `b` of the input +space `H` and vectorize operation elements by `vec = (TensorProduct.matricize b).symm : (H →L G) → +(G ⊗ H)`. If two families `E : ι → (H →L[ℂ] G)` and `F : κ → (H →L[ℂ] G)` — over possibly +*different* finite index sets — have equal **Choi operators** +`Σᵢ |vec Eᵢ⟩⟨vec Eᵢ| = Σₖ |vec Fₖ⟩⟨vec Fₖ|` on `G ⊗ H`, then they induce the same operator-sum map, +`krausSumₗ E = krausSumₗ F`. + +Pad both families to the common index `ι ⊕ κ` by appending zero operators (which changes neither the +Choi operator nor, by `krausSumₗ_sumElim_zero_left`/`_right`, the operator-sum map). The equal Choi +operators over `ι ⊕ κ` are equal sums of rank-one projectors of the two vectorized families, so the +vector form of Nielsen & Chuang Theorem 2.6 +(`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup`) yields a unitary `u` with +`vec (padE a) = Σ_b uₐ_b • vec (padF b)`; applying the linear equivalence `matricize b` transports +this to the operation elements, `padE a = Σ_b uₐ_b • padF b`, and `krausSumₗ_eq_of_unitary_smul` +finishes. -/ +theorem krausSumₗ_eq_of_choi_eq {ιb : Type*} [Fintype ιb] (b : OrthonormalBasis ιb ℂ H) + {ι κ : Type*} [Fintype ι] [Fintype κ] {E : ι → H →L[ℂ] G} {F : κ → H →L[ℂ] G} + (h : ∑ i, InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm (E i)) + ((TensorProduct.matricize b).symm (E i)) + = ∑ k, InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm (F k)) + ((TensorProduct.matricize b).symm (F k))) : + krausSumₗ E = krausSumₗ F := by + classical + have : CompleteSpace (G ⊗[ℂ] H) := FiniteDimensional.completeSpace ℂ _ + set padE : ι ⊕ κ → G ⊗[ℂ] H := + Sum.elim (fun i => (TensorProduct.matricize b).symm (E i)) (fun _ => 0) with hpadE + set padF : ι ⊕ κ → G ⊗[ℂ] H := + Sum.elim (fun _ => 0) (fun k => (TensorProduct.matricize b).symm (F k)) with hpadF + have hchoi : ∑ a, InnerProductSpace.rankOne ℂ (padE a) (padE a) + = ∑ a, InnerProductSpace.rankOne ℂ (padF a) (padF a) := by + simp only [hpadE, hpadF, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + map_zero, Finset.sum_const_zero, add_zero, zero_add] + exact h + obtain ⟨u, hu, hrel⟩ := + (InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup padE padF).mp hchoi + set EE : ι ⊕ κ → H →L[ℂ] G := Sum.elim E (fun _ => 0) with hEE + set FF : ι ⊕ κ → H →L[ℂ] G := Sum.elim (fun _ => 0) F with hFF + have hmapE : ∀ a, TensorProduct.matricize b (padE a) = EE a := by + rintro (i | k) + · simp only [hpadE, hEE, Sum.elim_inl, LinearEquiv.apply_symm_apply] + · simp only [hpadE, hEE, Sum.elim_inr, map_zero] + have hmapF : ∀ a, TensorProduct.matricize b (padF a) = FF a := by + rintro (i | k) + · simp only [hpadF, hFF, Sum.elim_inl, map_zero] + · simp only [hpadF, hFF, Sum.elim_inr, LinearEquiv.apply_symm_apply] + have hrel' : ∀ a, EE a = ∑ b', u a b' • FF b' := by + intro a + rw [← hmapE a, hrel a, map_sum] + exact Finset.sum_congr rfl fun b' _ => by rw [map_smul, hmapF b'] + have hEEFF : krausSumₗ EE = krausSumₗ FF := krausSumₗ_eq_of_unitary_smul hu hrel' + rw [hEE, hFF] at hEEFF + rwa [krausSumₗ_sumElim_zero_right, krausSumₗ_sumElim_zero_left] at hEEFF + +/-- **Minimal operator-sum representation, `d`-to-`d′` form** (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 8.11). Any operator-sum map `krausSumₗ E` of a family +`E : ι → (H →L[ℂ] G)` over an arbitrarily large finite index has an equal operator-sum map +`krausSumₗ F` whose family `F` is indexed by `Fin (dim G · dim H)`: +`∃ F : Fin (finrank ℂ G · finrank ℂ H) → (H →L[ℂ] G), krausSumₗ F = krausSumₗ E`. + +Reduce the Choi operator `Σᵢ |vec Eᵢ⟩⟨vec Eᵢ|` on `G ⊗ H` (which has `finrank = dim G · dim H`) to +at most `finrank (G ⊗ H)` rank-one terms `Σₖ |Wₖ⟩⟨Wₖ|` by +`InnerProductSpace.exists_sum_rankOne_self_eq_fin_finrank`; un-vectorize `Fₖ = matricize b Wₖ`, so +its Choi operator equals that of `E`, and conclude by `krausSumₗ_eq_of_choi_eq`. The index is +reshaped from `Fin (finrank (G ⊗ H))` to `Fin (finrank G · finrank H)` via +`Module.finrank_tensorProduct` and `krausSumₗ_comp_equiv`. -/ +theorem exists_krausSumₗ_eq_fin_finrank {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) : + ∃ F : Fin (Module.finrank ℂ G * Module.finrank ℂ H) → (H →L[ℂ] G), + krausSumₗ F = krausSumₗ E := by + classical + set b := stdOrthonormalBasis ℂ H with hb + have : FiniteDimensional ℂ (G ⊗[ℂ] H) := inferInstance + obtain ⟨W, hW⟩ := InnerProductSpace.exists_sum_rankOne_self_eq_fin_finrank (𝕜 := ℂ) + (fun i => (TensorProduct.matricize b).symm (E i)) + have hdim : Module.finrank ℂ (G ⊗[ℂ] H) = Module.finrank ℂ G * Module.finrank ℂ H := by + rw [Module.finrank_tensorProduct] + set F' : Fin (Module.finrank ℂ (G ⊗[ℂ] H)) → (H →L[ℂ] G) := + fun j => TensorProduct.matricize b (W j) with hF' + have hEF' : krausSumₗ E = krausSumₗ F' := by + refine krausSumₗ_eq_of_choi_eq b ?_ + rw [hW] + refine Finset.sum_congr rfl fun j _ => ?_ + simp only [hF', LinearEquiv.symm_apply_apply] + exact ⟨F' ∘ finCongr hdim.symm, by rw [krausSumₗ_comp_equiv]; exact hEF'.symm⟩ + +/-- **Minimal operator-sum representation on a `d`-dimensional system** (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Theorem 8.3). Any operator-sum map `krausSumₗ E` on a system +of dimension `d = finrank ℂ H` (input and output space both `H`) has an equal operator-sum map +`krausSumₗ F` whose family `F` is indexed by `Fin (d²)`: +`∃ F : Fin (finrank ℂ H ^ 2) → (H →L[ℂ] H), krausSumₗ F = krausSumₗ E`. + +The `G = H` specialization of `exists_krausSumₗ_eq_fin_finrank`, with the index reshaped from +`Fin (d · d)` to `Fin (d²)` via `krausSumₗ_comp_equiv`. -/ +theorem exists_krausSumₗ_eq_fin_finrank_sq {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] H) : + ∃ F : Fin (Module.finrank ℂ H ^ 2) → (H →L[ℂ] H), krausSumₗ F = krausSumₗ E := by + obtain ⟨F, hF⟩ := exists_krausSumₗ_eq_fin_finrank E + have hsq : Module.finrank ℂ H ^ 2 = Module.finrank ℂ H * Module.finrank ℂ H := pow_two _ + exact ⟨F ∘ finCongr hsq, by rw [krausSumₗ_comp_equiv]; exact hF⟩ + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MirskyInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MirskyInequality.lean new file mode 100644 index 0000000000..53cb5952b7 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/MirskyInequality.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EigenvalueMonotone +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PosNegPart +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# Mirsky's inequality: the trace-norm bound on sorted eigenvalue differences + +For self-adjoint operators `A, B` on a finite-dimensional complex inner product space, the +`ℓ¹` distance between their sorted eigenvalue spectra is bounded by the trace norm of their +difference: +`∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ ‖A − B‖₁`, +where `λᵢ` denotes the eigenvalues in the common decreasing order +(`LinearMap.IsSymmetric.eigenvalues`) and `‖·‖₁` is `ContinuousLinearMap.traceNorm`. + +This is **Mirsky's inequality**; it is the spectral ingredient of Fannes' inequality +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.6, eq. (11.46)), +where it turns a trace-distance bound between two density operators into a bound on the `ℓ¹` +distance between their eigenvalue spectra, from which continuity of the von Neumann entropy +follows. + +## Proof + +Following Nielsen & Chuang: write `A − B = Q − R` with `Q = (A−B)⁺`, `R = (A−B)⁻` the positive +and negative parts (both positive operators). The operator `V := A + R = B + Q` dominates both +`A` and `B` in the quadratic-form order (`V − A = R ≥ 0`, `V − B = Q ≥ 0`), so by Weyl's +monotonicity theorem its sorted eigenvalues `tᵢ := λᵢ(V)` satisfy `tᵢ ≥ λᵢ(A)` and +`tᵢ ≥ λᵢ(B)`; hence `2tᵢ ≥ λᵢ(A) + λᵢ(B) + |λᵢ(A) − λᵢ(B)|`. Summing and using +`∑ᵢ λᵢ = re tr` gives +`∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ 2 tr V − tr A − tr B = tr Q + tr R = ‖A − B‖₁`, +the last equality being the trace-norm Jordan split +(`IsSelfAdjoint.traceNorm_eq_re_trace_posPart_add`). + +## Main results + +* `LinearMap.IsSymmetric.sum_abs_eigenvalues_sub_le`: the eigenvalue core — if a + symmetric `V` dominates symmetric `A, B` in quadratic-form order, then + `∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ 2 ∑ᵢ λᵢ(V) − ∑ᵢ λᵢ(A) − ∑ᵢ λᵢ(B)`. +* `IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm`: Mirsky's inequality itself, + `∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ ‖A − B‖₁`. +-/ + +@[expose] public section + +open RCLike +open scoped InnerProductSpace + +namespace LinearMap.IsSymmetric + +variable {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] {n : ℕ} + +/-- **Eigenvalue core of Mirsky's inequality.** If a symmetric operator `V` dominates the +symmetric operators `A` and `B` in the quadratic-form order (`V − A` and `V − B` are positive), +then the `ℓ¹` distance between the sorted spectra of `A` and `B` is controlled by the traces: +`∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ 2 ∑ᵢ λᵢ(V) − ∑ᵢ λᵢ(A) − ∑ᵢ λᵢ(B)`. + +For each index `i`, Weyl's monotonicity theorem gives `λᵢ(A) ≤ λᵢ(V)` and `λᵢ(B) ≤ λᵢ(V)`, and +the pointwise inequality `|a − b| ≤ 2t − a − b` holds whenever `a ≤ t` and `b ≤ t`. -/ +theorem sum_abs_eigenvalues_sub_le {A B V : E →ₗ[𝕜] E} + (hA : A.IsSymmetric) (hB : B.IsSymmetric) (hV : V.IsSymmetric) + (hn : Module.finrank 𝕜 E = n) + (hVA : (V - A).IsPositive) (hVB : (V - B).IsPositive) : + ∑ i, |hA.eigenvalues hn i - hB.eigenvalues hn i| + ≤ 2 * ∑ i, hV.eigenvalues hn i - ∑ i, hA.eigenvalues hn i - ∑ i, hB.eigenvalues hn i := by + rw [Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib] + refine Finset.sum_le_sum fun i _ => ?_ + have hAV : hA.eigenvalues hn i ≤ hV.eigenvalues hn i := + hA.eigenvalues_mono_of_sub_isPositive hV hVA hn i + have hBV : hB.eigenvalues hn i ≤ hV.eigenvalues hn i := + hB.eigenvalues_mono_of_sub_isPositive hV hVB hn i + rcases abs_cases (hA.eigenvalues hn i - hB.eigenvalues hn i) with ⟨h, _⟩ | ⟨h, _⟩ <;> + rw [h] <;> linarith + +end LinearMap.IsSymmetric + +section Complex + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **Mirsky's inequality** (Nielsen & Chuang, Theorem 11.6, eq. (11.46)). For self-adjoint +operators `A, B` on a finite-dimensional complex inner product space, the `ℓ¹` distance between +their sorted eigenvalue spectra is bounded by the trace norm of their difference: +`∑ᵢ |λᵢ(A) − λᵢ(B)| ≤ ‖A − B‖₁`. + +The dominating operator is `V := A + (A−B)⁻`; then `V − A = (A−B)⁻ ≥ 0` and +`V − B = (A−B)⁺ ≥ 0`, so `V` dominates `A` and `B`, and `2 tr V − tr A − tr B` collapses to +`re tr (A−B)⁺ + re tr (A−B)⁻ = ‖A − B‖₁`. -/ +theorem IsSelfAdjoint.sum_abs_eigenvalues_sub_le_traceNorm {A B : E →L[ℂ] E} + (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) {n : ℕ} (hn : Module.finrank ℂ E = n) : + ∑ i, |hA.isSymmetric.eigenvalues hn i - hB.isSymmetric.eigenvalues hn i| + ≤ (A - B).traceNorm := by + have hM : IsSelfAdjoint (A - B) := hA.sub hB + set Q : E →L[ℂ] E := (A - B)⁺ with hQ_def + set R : E →L[ℂ] E := (A - B)⁻ with hR_def + have hQpos : Q.IsPositive := ContinuousLinearMap.isPositive_posPart (A - B) + have hRpos : R.IsPositive := ContinuousLinearMap.isPositive_negPart (A - B) + have hMdecomp : A - B = Q - R := (CFC.posPart_sub_negPart (A - B) hM).symm + set V : E →L[ℂ] E := A + R with hV_def + have hVsa : IsSelfAdjoint V := hA.add hRpos.isSelfAdjoint + -- `V` dominates `A` and `B`: `V − A = R`, `V − B = Q`. + have hVA_eq : V - A = R := by rw [hV_def]; abel + have hVB_eq : V - B = Q := by rw [hV_def, add_sub_right_comm, hMdecomp]; abel + have hVApos : ((V : E →ₗ[ℂ] E) - (A : E →ₗ[ℂ] E)).IsPositive := by + rw [← ContinuousLinearMap.toLinearMap_sub, hVA_eq]; exact hRpos.toLinearMap + have hVBpos : ((V : E →ₗ[ℂ] E) - (B : E →ₗ[ℂ] E)).IsPositive := by + rw [← ContinuousLinearMap.toLinearMap_sub, hVB_eq]; exact hQpos.toLinearMap + -- The eigenvalue core, applied to the coerced linear maps. + have hcore := LinearMap.IsSymmetric.sum_abs_eigenvalues_sub_le + hA.isSymmetric hB.isSymmetric hVsa.isSymmetric hn hVApos hVBpos + refine hcore.trans (le_of_eq ?_) + -- Convert eigenvalue sums to real traces and collapse via the trace-norm Jordan split. + have e1 : RCLike.re (LinearMap.trace ℂ E (V : E →ₗ[ℂ] E)) + = RCLike.re (LinearMap.trace ℂ E (A : E →ₗ[ℂ] E)) + + RCLike.re (LinearMap.trace ℂ E (R : E →ₗ[ℂ] E)) := by + rw [hV_def, ContinuousLinearMap.toLinearMap_add, map_add, map_add] + have e2 : RCLike.re (LinearMap.trace ℂ E (A : E →ₗ[ℂ] E)) + - RCLike.re (LinearMap.trace ℂ E (B : E →ₗ[ℂ] E)) + = RCLike.re (LinearMap.trace ℂ E (Q : E →ₗ[ℂ] E)) + - RCLike.re (LinearMap.trace ℂ E (R : E →ₗ[ℂ] E)) := by + have hcoe : (A : E →ₗ[ℂ] E) - (B : E →ₗ[ℂ] E) = (Q : E →ₗ[ℂ] E) - (R : E →ₗ[ℂ] E) := by + rw [← ContinuousLinearMap.toLinearMap_sub, ← ContinuousLinearMap.toLinearMap_sub, hMdecomp] + have := congrArg (fun T => RCLike.re (LinearMap.trace ℂ E T)) hcoe + simpa [map_sub] using this + rw [← hVsa.isSymmetric.re_trace_eq_sum_eigenvalues hn, + ← hA.isSymmetric.re_trace_eq_sum_eigenvalues hn, + ← hB.isSymmetric.re_trace_eq_sum_eigenvalues hn, + IsSelfAdjoint.traceNorm_eq_re_trace_posPart_add (A - B) hM] + linarith [e1, e2] + +end Complex diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/NormalOperator.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/NormalOperator.lean new file mode 100644 index 0000000000..c758693b26 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/NormalOperator.lean @@ -0,0 +1,128 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.JointEigenspace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import Mathlib.Analysis.InnerProductSpace.Projection.FiniteDimensional + +/-! +# The spectral theorem for normal operators + +An operator `T` on a finite-dimensional complex inner product space is *normal* when it commutes +with its adjoint. Mathlib spells this with the `IsStarNormal` predicate (`Commute (star T) T`); +for `T : E →ₗ[ℂ] E` the `star` is `LinearMap.adjoint` (`LinearMap.star_eq_adjoint`), so +`IsStarNormal T` is exactly `Tᴴ * T = T * Tᴴ`. This file proves the **spectral theorem** for +such operators: `T` is normal if and only if it is diagonal with respect to some orthonormal +basis, i.e. there is an orthonormal eigenbasis. + +The forward direction is obtained from the simultaneous diagonalisation of the two commuting +self-adjoint operators `A = ℜ T` (`realPart T`, i.e. `½ (T + Tᴴ)`) and `B = ℑ T` +(`imaginaryPart T`, i.e. `½ i (Tᴴ - T)`), for which `T = A + i • B` +(`realPart_add_I_smul_imaginaryPart`). Normality of `T` is exactly `Commute A B` +(`isStarNormal_iff_commute_realPart_imaginaryPart`), so +`LinearMap.IsSymmetric.iSup_iSup_eigenspace_inf_eigenspace_eq_top_of_commute` shows that the joint +eigenspaces of `A` and `B` span the whole space. Each such joint eigenspace lies inside an +eigenspace of `T`, and the joint eigenspaces form an orthogonal family, so reindexing along the +(finite) set of eigenvalue pairs and taking a subordinate orthonormal basis produces an +orthonormal eigenbasis for `T`. The converse is a direct computation over any `RCLike` field: a +diagonal operator's adjoint is diagonal (with conjugated entries) in the same basis, and diagonal +operators commute. + +Working over `ℂ` (rather than a general `RCLike` field) is essential for the forward direction: +over `ℝ` a normal operator such as a rotation need not be diagonalisable, and the Cartesian +decomposition `T = A + i • B` uses `Complex.I` in an irreducible way. The converse half holds over +any `RCLike` field. + +## Main results + +* `IsStarNormal.exists_orthonormalBasis_forall_apply_eq_smul`: a normal operator has an + orthonormal eigenbasis (the existence half). +* `LinearMap.adjoint_apply_of_forall_apply_eq_smul`: the adjoint of an operator diagonal in an + orthonormal basis is diagonal in the same basis with the conjugated eigenvalues. +* `LinearMap.isStarNormal_of_forall_apply_eq_smul`: an operator that is diagonal in an orthonormal + basis is normal (the converse half; over any `RCLike` field). +* `LinearMap.isStarNormal_iff_exists_orthonormalBasis`: the spectral theorem, packaging the two + halves as an equivalence. +-/ + +public section + +namespace LinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +/-- **Spectral theorem for normal operators** (existence half): a normal operator `T` on a +finite-dimensional complex inner product space, i.e. one satisfying `IsStarNormal T` +(`Tᴴ * T = T * Tᴴ`), is diagonal with respect to some orthonormal basis. Concretely, there is an +orthonormal basis `b` and scalars `μ` with `T (b i) = μ i • b i` for all `i`. -/ +theorem _root_.IsStarNormal.exists_orthonormalBasis_forall_apply_eq_smul + {T : E →ₗ[ℂ] E} (hT : IsStarNormal T) : + ∃ (b : OrthonormalBasis (Fin (Module.finrank ℂ E)) ℂ E) (μ : Fin (Module.finrank ℂ E) → ℂ), + ∀ i, T (b i) = μ i • b i := by + classical + -- `A` and `B` are the self-adjoint real and imaginary parts of `T`, with `T = A + i • B`. + set A : E →ₗ[ℂ] E := ↑(realPart T) + set B : E →ₗ[ℂ] E := ↑(imaginaryPart T) + have hAsymm : A.IsSymmetric := (LinearMap.isSymmetric_iff_isSelfAdjoint _).2 (realPart T).2 + have hBsymm : B.IsSymmetric := (LinearMap.isSymmetric_iff_isSelfAdjoint _).2 (imaginaryPart T).2 + -- Normality of `T` is exactly commutativity of its real and imaginary parts. + have hAB : Commute A B := isStarNormal_iff_commute_realPart_imaginaryPart.1 hT + have hTAB : T = A + Complex.I • B := (realPart_add_I_smul_imaginaryPart T).symm + -- Simultaneously diagonalise `A` and `B`; then `T = A + i·B` is diagonal in the same basis. + obtain ⟨b, μ, ν, h⟩ := hAsymm.exists_orthonormalBasis_forall_apply_eq_smul_of_commute hBsymm hAB + refine ⟨b, fun i => μ i + Complex.I * ν i, fun i => ?_⟩ + obtain ⟨hA', hB'⟩ := h i + simp only [hTAB, LinearMap.add_apply, LinearMap.smul_apply, hA', hB', smul_smul, add_smul] + +/-- If a linear map `T` is diagonal in an orthonormal basis `b` with eigenvalues `μ`, then its +adjoint is diagonal in the same basis with the conjugated eigenvalues. -/ +theorem adjoint_apply_of_forall_apply_eq_smul + {𝕜 : Type*} [RCLike 𝕜] {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [FiniteDimensional 𝕜 F] {ι : Type*} [Fintype ι] {T : F →ₗ[𝕜] F} + (b : OrthonormalBasis ι 𝕜 F) (μ : ι → 𝕜) (h : ∀ i, T (b i) = μ i • b i) (k : ι) : + adjoint T (b k) = (starRingEnd 𝕜) (μ k) • b k := by + classical + refine InnerProductSpace.ext_inner_left_basis b.toBasis (fun i => ?_) + simp only [OrthonormalBasis.coe_toBasis] + rw [adjoint_inner_right, h i, inner_smul_left, inner_smul_right] + rcases eq_or_ne i k with rfl | hik + · rfl + · rw [orthonormal_iff_ite.mp b.orthonormal i k, ite_eq_right hik, mul_zero, mul_zero] + +/-- **Spectral theorem for normal operators** (converse half): an operator that is diagonal with +respect to some orthonormal basis is normal. If `T (b i) = μ i • b i` for an orthonormal basis +`b`, then `T` commutes with its adjoint, i.e. `IsStarNormal T`. This half holds over any `RCLike` +field (unlike the forward direction, which genuinely requires `ℂ`). -/ +theorem isStarNormal_of_forall_apply_eq_smul + {𝕜 : Type*} [RCLike 𝕜] {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [FiniteDimensional 𝕜 F] {ι : Type*} [Fintype ι] {T : F →ₗ[𝕜] F} + (b : OrthonormalBasis ι 𝕜 F) (μ : ι → 𝕜) + (h : ∀ i, T (b i) = μ i • b i) : IsStarNormal T := by + classical + -- Both `adjoint T * T` and `T * adjoint T` act as `|μ i|² • b i`, hence agree. + have hcomm : Commute (adjoint T) T := by + refine b.toBasis.ext (fun i => ?_) + rw [OrthonormalBasis.coe_toBasis, mul_apply_eq_comp, mul_apply_eq_comp, h i, map_smul, + adjoint_apply_of_forall_apply_eq_smul b μ h i, map_smul, h i, smul_smul, smul_smul, mul_comm] + exact ⟨hcomm⟩ + +/-- **Spectral theorem for normal operators.** An operator `T` on a finite-dimensional complex +inner product space is normal (`IsStarNormal T`, i.e. it commutes with its adjoint) if and only if +it is diagonal with respect to some orthonormal basis. -/ +theorem isStarNormal_iff_exists_orthonormalBasis {T : E →ₗ[ℂ] E} : + IsStarNormal T ↔ + ∃ (b : OrthonormalBasis (Fin (Module.finrank ℂ E)) ℂ E) (μ : Fin (Module.finrank ℂ E) → ℂ), + ∀ i, T (b i) = μ i • b i := + ⟨fun hT => hT.exists_orthonormalBasis_forall_apply_eq_smul, + fun ⟨b, μ, h⟩ => isStarNormal_of_forall_apply_eq_smul b μ h⟩ + +end LinearMap + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorBlockRow.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorBlockRow.lean new file mode 100644 index 0000000000..9a8b0ed2a7 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorBlockRow.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# Block-row operators on a tensor product + +Given a finite family of operators `M : ι → (E →L[𝕜] E)` and an orthonormal basis `b` of an +ancilla `F`, the **block-row operator** is the map `E ⊗[𝕜] F →L[𝕜] E` + + `blockRow b M = ∑ j, M j ∘L restrictRightL b j`, `blockRow b M (x ⊗ b k) = M k x`, + +i.e. the operator whose `k`-th "column" (the block `E ⊗ ⟨b k⟩`) acts as `M k`. Here +`restrictRightL b k` is the continuous packaging of `LinearMap.restrictRight b k` +(`x ⊗ y ↦ ⟪b k, y⟫ • x`), automatic in finite dimension. + +The two structural identities that make block-rows useful are consequences of the +delta-orthogonality of the columns (`restrictRightL b i ∘L (restrictRightL b j)† = δᵢⱼ`): + +* `blockRow_comp_adjoint` — the self-outer-product is the sum of the component outer-products, + `(blockRow b M)(blockRow b M)† = ∑ j, M j (M j)†` (all cross terms vanish); +* `hsPairing_blockRow` — the Hilbert–Schmidt pairing of two block-rows collapses to the diagonal, + `(blockRow b N).hsPairing (blockRow b M) = ∑ i, (N i).hsPairing (M i)`. + +These package the "stack the `Mⱼ` into orthogonal columns" construction reused, e.g., in the proof +of the strong concavity of the fidelity (Nielsen–Chuang Theorem 9.7), where `M M†` recovers a +probabilistic mixture `∑ⱼ pⱼ ρⱼ` and the pairing recovers a diagonal overlap sum. + +## Main definitions + +* `ContinuousLinearMap.restrictRightL` — the continuous right-restriction `E ⊗[𝕜] F →L[𝕜] E`. +* `ContinuousLinearMap.blockRow` — the block-row operator assembled from a family and a basis. + +## Main results + +* `ContinuousLinearMap.restrictRightL_tmul`, `blockRow_apply`, `blockRow_tmul` — the defining + application formulas. +* `ContinuousLinearMap.adjoint_restrictRightL`, `restrictRightL_comp_adjoint_restrictRightL` — the + adjoint of a column and the column delta-orthogonality. +* `ContinuousLinearMap.blockRow_comp_adjoint`, `hsPairing_blockRow` — the two structural identities. +-/ + +open scoped InnerProductSpace TensorProduct + +@[expose] public section + +noncomputable section + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- The **continuous** right-restriction `E ⊗[𝕜] F →L[𝕜] E`, `x ⊗ y ↦ ⟪b k, y⟫ • x`: the +`ContinuousLinearMap` packaging of `LinearMap.restrictRight b k` (automatic in finite dimension). -/ +noncomputable def restrictRightL (b : OrthonormalBasis ι 𝕜 F) (k : ι) : + (E ⊗[𝕜] F) →L[𝕜] E := + (LinearMap.restrictRight b k).toContinuousLinearMap + +/-- Application of `restrictRightL` on a pure tensor: +`restrictRightL b k (x ⊗ y) = ⟪b k, y⟫ • x`. -/ +@[simp] +theorem restrictRightL_tmul (b : OrthonormalBasis ι 𝕜 F) (k : ι) (x : E) (y : F) : + restrictRightL b k (x ⊗ₜ[𝕜] y) = ⟪b k, y⟫_𝕜 • x := by + simp only [restrictRightL, LinearMap.coe_toContinuousLinearMap', LinearMap.restrictRight_tmul] + +/-- The **block-row operator** assembled from a family `M : ι → (E →L[𝕜] E)` and an orthonormal +basis `b` of the ancilla `F`: `blockRow b M = ∑ j, M j ∘L restrictRightL b j`, the map +`E ⊗[𝕜] F →L[𝕜] E` sending `x ⊗ b k ↦ M k x`. -/ +noncomputable def blockRow (b : OrthonormalBasis ι 𝕜 F) (M : ι → E →L[𝕜] E) : + (E ⊗[𝕜] F) →L[𝕜] E := + ∑ j, (M j) ∘L restrictRightL b j + +/-- Application of `blockRow` on a general element: +`blockRow b M z = ∑ j, M j (restrictRightL b j z)`. -/ +theorem blockRow_apply (b : OrthonormalBasis ι 𝕜 F) (M : ι → E →L[𝕜] E) (z : E ⊗[𝕜] F) : + blockRow b M z = ∑ j, M j (restrictRightL b j z) := by + rw [blockRow, _root_.sum_apply] + simp only [ContinuousLinearMap.comp_apply] + +/-- Application of `blockRow` on a pure tensor: `blockRow b M (x ⊗ y) = ∑ j, ⟪b j, y⟫ • M j x`. On a +basis vector `y = b k` this collapses (by orthonormality) to the defining `M k x`. -/ +theorem blockRow_tmul (b : OrthonormalBasis ι 𝕜 F) (M : ι → E →L[𝕜] E) (x : E) (y : F) : + blockRow b M (x ⊗ₜ[𝕜] y) = ∑ j, ⟪b j, y⟫_𝕜 • M j x := by + rw [blockRow_apply] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [restrictRightL_tmul, map_smul] + +section Adjoint + +variable [CompleteSpace E] [CompleteSpace (E ⊗[𝕜] F)] + +/-- The adjoint of the continuous right-restriction is the continuous right-embedding +`x ↦ x ⊗ b k` (`LinearMap.embedRight b k`), via `LinearMap.adjoint_restrictRight`. -/ +theorem adjoint_restrictRightL (b : OrthonormalBasis ι 𝕜 F) (k : ι) : + adjoint (restrictRightL (E := E) b k) = (LinearMap.embedRight b k).toContinuousLinearMap := by + rw [restrictRightL, ← LinearMap.adjoint_toContinuousLinearMap, LinearMap.adjoint_restrictRight] + +/-- **Delta-orthogonality of the block columns** (continuous form): +`restrictRightL b i ∘L (restrictRightL b j)† = if i = j then 1 else 0`. The two restrictions live +on orthogonal `b`-columns of the ancilla, so the composite is the identity when `i = j` and zero +otherwise (`LinearMap.restrictRight_comp_embedRight`). -/ +theorem restrictRightL_comp_adjoint_restrictRightL [DecidableEq ι] + (b : OrthonormalBasis ι 𝕜 F) (i j : ι) : + (restrictRightL (E := E) b i) ∘L adjoint (restrictRightL b j) = if i = j then 1 else 0 := by + rw [adjoint_restrictRightL, restrictRightL] + apply ContinuousLinearMap.coe_injective + rw [ContinuousLinearMap.toLinearMap_comp, LinearMap.coe_toContinuousLinearMap, + LinearMap.coe_toContinuousLinearMap, LinearMap.restrictRight_comp_embedRight] + split_ifs <;> simp [Module.End.one_eq_id] + +/-- **The self-outer-product of a block-row is the sum of the component outer-products:** +`(blockRow b M)(blockRow b M)† = ∑ j, M j (M j)†`. The columns of `blockRow b M` sit on orthogonal +`b`-slots of the ancilla, so all cross terms `i ≠ j` vanish +(`restrictRightL_comp_adjoint_restrictRightL`), leaving the diagonal sum. -/ +theorem blockRow_comp_adjoint (b : OrthonormalBasis ι 𝕜 F) (M : ι → E →L[𝕜] E) : + (blockRow b M) ∘L adjoint (blockRow b M) = ∑ j, (M j) ∘L adjoint (M j) := by + classical + have hadj : adjoint (blockRow b M) + = ∑ j, adjoint (restrictRightL b j) ∘L adjoint (M j) := by + rw [blockRow, map_sum] + exact Finset.sum_congr rfl fun j _ => adjoint_comp _ _ + rw [hadj, blockRow, ContinuousLinearMap.finsetSum_comp] + refine Finset.sum_congr rfl fun i _ => ?_ + -- Peel the inner sum: only the `j = i` column survives. + rw [ContinuousLinearMap.comp_finsetSum, Finset.sum_eq_single i] + · rw [comp_assoc, ← comp_assoc (restrictRightL b i), + restrictRightL_comp_adjoint_restrictRightL, ite_eq_left rfl, one_def, id_comp] + · intro j _ hji + rw [comp_assoc, ← comp_assoc (restrictRightL b i), + restrictRightL_comp_adjoint_restrictRightL, ite_eq_right (Ne.symm hji), zero_comp, comp_zero] + · intro h; exact absurd (Finset.mem_univ i) h + +/-- **Scaling each block-row column by `r i` scales the self-outer-product:** +`blockRow b (r · • M ·) (blockRow b (r · • M ·))† = ∑ i, (r i * conj (r i)) • (M i (M i)†)`. The +per-column scalar `r i` factors out of the `i`-th self-outer-product term as `r i * star (r i)` +(`= |r i|²`). Specialised to `r i = √(weight i)` this turns a block-row of scaled columns into a +scaled mixture, the shape used in the strong concavity of the fidelity (N&C Theorem 9.7). -/ +theorem blockRow_smul_comp_adjoint (b : OrthonormalBasis ι 𝕜 F) (r : ι → 𝕜) + (M : ι → E →L[𝕜] E) : + blockRow b (fun i => r i • M i) ∘L adjoint (blockRow b (fun i => r i • M i)) + = ∑ i, (r i * star (r i)) • (M i ∘L adjoint (M i)) := by + rw [blockRow_comp_adjoint] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← star_eq_adjoint, star_smul, star_eq_adjoint, smul_comp, comp_smul, smul_smul] + +/-- **The Hilbert–Schmidt pairing of two block-rows collapses to the diagonal:** +`(blockRow b N).hsPairing (blockRow b M) = ∑ i, (N i).hsPairing (M i)`. Bilinearity expands the +pairing over the two sums; `hsPairing_comp_right` moves each ancilla restriction to the other slot, +where delta-orthogonality (`restrictRightL_comp_adjoint_restrictRightL`) kills the off-diagonal +`i ≠ j` terms. -/ +theorem hsPairing_blockRow (b : OrthonormalBasis ι 𝕜 F) (M N : ι → E →L[𝕜] E) : + (blockRow b N).hsPairing (blockRow b M) = ∑ i, (N i).hsPairing (M i) := by + classical + rw [blockRow, blockRow, hsPairing_sum_left] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [hsPairing_sum_right, Finset.sum_eq_single j] + · rw [hsPairing_comp_right, comp_assoc, restrictRightL_comp_adjoint_restrictRightL, + ite_eq_left rfl, one_def, comp_id] + · intro i _ hij + rw [hsPairing_comp_right, comp_assoc, restrictRightL_comp_adjoint_restrictRightL, + ite_eq_right hij, comp_zero, hsPairing_zero_right] + · intro h; exact absurd (Finset.mem_univ j) h + +end Adjoint + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorGram.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorGram.lean new file mode 100644 index 0000000000..46544697e9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorGram.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GramMatrix +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.MinimalOperatorSum +public import Mathlib.Analysis.Matrix.Spectrum +public import Mathlib.LinearAlgebra.Matrix.Rank + +/-! # The operation-element Gram matrix `Wⱼₖ = tr(Eⱼ† Eₖ)` and the minimal orthogonal family + +This file carries out Nielsen & Chuang's **Exercise 8.10** route to Theorem 8.3 (the minimal +operator-sum representation). Given a finite family of operation elements `E : ι → (H →L[ℂ] G)`, +N&C define the matrix + + `Wⱼₖ ≡ tr(Eⱼ† Eₖ)`, + +observe that `W` is Hermitian of rank at most `d²` (on a `d`-dimensional system `G = H`), and +diagonalize it — `u W u†` diagonal for some unitary `u` — to produce at most `d²` non-zero +operation elements `{Fⱼ}` for the *same* quantum operation. This file supplies the `W` matrix, its +Hermitian/rank facts, and the diagonalized family with all three of N&C's properties. + +The entries `tr(Eⱼ† Eₖ)` are the **Hilbert–Schmidt inner products** of the operation elements. +Rather than equip `H →L[ℂ] G` with the HS inner product directly, `W` is defined as the ordinary +Gram matrix (`Matrix.gram`) of the **Choi vectors** `vec Eⱼ = (matricize b).symm Eⱼ ∈ G ⊗ H`, whose +inner product is the HS pairing `tr(Eⱼ† Eₖ)` by the matricization bridge +(`TensorProduct.matricize_inner_eq_trace_adjoint_comp`). This reuses the Gram-matrix API +(`Matrix.isHermitian_gram`) for free, and turns the rank bound into a statement about the ambient +space `G ⊗ H`, of dimension `dim G · dim H` (`= d²` when `G = H`). The diagonalized family is +obtained by recombining `E` with the eigenvector unitary `u` of `W`, +`Fₐ = ∑ᵢ uᵢₐ • Eᵢ`; its Gram matrix is then `u† W u`, the diagonal matrix of `W`'s eigenvalues +(the general congruence identity `Matrix.gram_smul_sum` reduces this to the matrix spectral theorem +`Matrix.IsHermitian.conjStarAlgAut_star_eigenvectorUnitary`). + +## Main definitions + +* `ContinuousLinearMap.krausGram` — the operation-element Gram matrix `Wⱼₖ = tr(Eⱼ† Eₖ)`. +* `ContinuousLinearMap.krausDiagonalize` — the Gram-diagonalized family `{Fⱼ}` of operation + elements, `Fₐ = ∑ᵢ uᵢₐ • Eᵢ`. + +## Main results + +* `ContinuousLinearMap.krausGram_apply` — `W`'s entries are the Hilbert–Schmidt traces + `Wⱼₖ = tr(Eⱼ† Eₖ)` (N&C's defining formula). +* `ContinuousLinearMap.krausGram_isHermitian` — `W` is Hermitian, being a Gram matrix. +* `ContinuousLinearMap.krausGram_rank_le` — `rank W ≤ dim G · dim H`, and + `ContinuousLinearMap.krausGram_rank_le_sq` — on a `d`-dimensional system (`G = H`), + `rank W ≤ d²`: **N&C Exercise 8.10's rank bound.** The rank step is the general Gram-matrix fact + `Matrix.rank_gram_le` (`rank (Matrix.gram 𝕜 v) ≤ dim E`, in `GramMatrix`). +* `ContinuousLinearMap.krausGram_krausDiagonalize` — the Gram matrix of the diagonalized family is + diagonal (the eigenvalues of `W`): **the `u W u†` diagonal step**. +* `ContinuousLinearMap.krausSumₗ_krausDiagonalize` — the diagonalized family induces the *same* + operator-sum map as `E` (unitary freedom, N&C Theorem 8.2). +* `ContinuousLinearMap.krausDiagonalize_trace_orthogonal` — the `{Fⱼ}` are Hilbert–Schmidt + **orthogonal**, `tr(Fⱼ† Fₖ) = 0` for `j ≠ k`. +* `ContinuousLinearMap.krausDiagonalize_card_ne_zero_le_sq` — at most `d²` of the `{Fⱼ}` are + non-zero (with `krausDiagonalize_card_ne_zero_le` the `dim G · dim H` form, N&C Exercise 8.11): + **completing N&C's Exercise 8.10 proof of Theorem 8.3.** +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] + {ιb ι : Type*} [Fintype ιb] [Fintype ι] + +/-- **The operation-element Gram matrix** of a finite family of operation elements +`E : ι → (H →L[ℂ] G)`, with entries the Hilbert–Schmidt inner products `Wⱼₖ = tr(Eⱼ† Eₖ)` — the +matrix `W` of Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 8.10. + +Defined as the Gram matrix (`Matrix.gram`) of the Choi vectors `vec Eⱼ = (matricize b).symm Eⱼ` in +`G ⊗ H`, for an orthonormal basis `b` of the input space `H`; `krausGram_apply` identifies the +entries with the operator traces `tr(Eⱼ† Eₖ)`. -/ +noncomputable def krausGram (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : Matrix ι ι ℂ := + Matrix.gram ℂ (fun j => (TensorProduct.matricize b).symm (E j)) + +omit [Fintype ι] in +/-- **The Gram matrix entries are the Hilbert–Schmidt traces** `Wⱼₖ = tr(Eⱼ† Eₖ)` — Nielsen & +Chuang's defining formula for `W` (Exercise 8.10). The Choi vectors `vec Eⱼ` have inner product +`⟪vec Eⱼ, vec Eₖ⟫ = tr(Eⱼ† Eₖ)` by the matricization bridge +(`TensorProduct.matricize_inner_eq_trace_adjoint_comp`). -/ +theorem krausGram_apply [CompleteSpace H] [CompleteSpace G] + (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) (j k : ι) : + krausGram b E j k + = LinearMap.trace ℂ H ((adjoint (E j)).toLinearMap ∘ₗ (E k).toLinearMap) := by + rw [krausGram, Matrix.gram_apply, TensorProduct.matricize_inner_eq_trace_adjoint_comp b, + LinearEquiv.apply_symm_apply, LinearEquiv.apply_symm_apply] + +omit [Fintype ι] [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- **The operation-element Gram matrix is Hermitian** (N&C Exercise 8.10): `W† = W`, since +`Wₖⱼ = tr(Eₖ† Eⱼ) = conj (tr(Eⱼ† Eₖ)) = conj Wⱼₖ`. A special case of `Matrix.isHermitian_gram`. -/ +theorem krausGram_isHermitian (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + (krausGram b E).IsHermitian := + Matrix.isHermitian_gram ℂ _ + +/-- **The rank of the operation-element Gram matrix is at most `dim G · dim H`.** The Choi vectors +`vec Eⱼ` live in `G ⊗ H`, of dimension `dim G · dim H`, so the Gram matrix has rank at most that +(`Matrix.rank_gram_le`, `Module.finrank_tensorProduct`). -/ +theorem krausGram_rank_le (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + (krausGram b E).rank ≤ Module.finrank ℂ G * Module.finrank ℂ H := by + rw [krausGram, ← Module.finrank_tensorProduct, ← Matrix.eRank_toNat_eq_rank] + exact Matrix.rank_gram_le _ + +/-- **The rank of the operation-element Gram matrix on a `d`-dimensional system is at most `d²`** +(Nielsen & Chuang, Exercise 8.10). For operation elements `E : ι → (H →L[ℂ] H)` with input and +output space both `H`, `rank W ≤ (dim H)²` — the bound that, after diagonalizing `W`, yields the +`≤ d²` operation elements of Theorem 8.3. -/ +theorem krausGram_rank_le_sq (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] H) : + (krausGram b E).rank ≤ Module.finrank ℂ H ^ 2 := by + rw [pow_two] + exact krausGram_rank_le b E + +variable [DecidableEq ι] + +/-- **The Gram-diagonalized family of operation elements** `{Fₐ}` of Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 8.10. Diagonalize the Hermitian Gram matrix +`W = krausGram b E` by its eigenvector unitary `u` (`Matrix.IsHermitian.eigenvectorUnitary`, so +`u† W u` is diagonal), and define the recombined operation elements + + `Fₐ ≡ ∑ᵢ uᵢₐ • Eᵢ`. + +These are N&C's "new set of operation elements `{Fⱼ}`" obtained from `u`: they induce the *same* +operator-sum map as `E` (`krausSumₗ_krausDiagonalize`), are Hilbert–Schmidt **orthogonal** +(`tr(Fₐ† F_c) = 0` for `a ≠ c`, `krausDiagonalize_trace_orthogonal`), and at most `rank W ≤ d²` of +them are non-zero (`krausDiagonalize_card_ne_zero_le`), completing the Exercise 8.10 route to +Theorem 8.3. -/ +noncomputable def krausDiagonalize (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + ι → H →L[ℂ] G := + fun a => ∑ i, ((krausGram_isHermitian b E).eigenvectorUnitary : Matrix ι ι ℂ) i a • E i + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- **Diagonalizing `W` orthogonalizes the operation elements** (Nielsen & Chuang, Exercise 8.10). +The Gram matrix of the diagonalized family `krausDiagonalize b E` is the diagonal matrix of the +(real) eigenvalues of `W = krausGram b E`. This is the statement that `u† W u` is diagonal +(`Matrix.IsHermitian.conjStarAlgAut_star_eigenvectorUnitary`), transported to the Gram matrix of the +recombined family via the general congruence identity `Matrix.gram_smul_sum` +(`gram (fun a => ∑ᵢ uᵢₐ • vᵢ) = uᴴ * gram v * u`). -/ +theorem krausGram_krausDiagonalize (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + krausGram b (krausDiagonalize b E) + = Matrix.diagonal (RCLike.ofReal ∘ (krausGram_isHermitian b E).eigenvalues) := by + rw [← (krausGram_isHermitian b E).conjStarAlgAut_star_eigenvectorUnitary, + Unitary.conjStarAlgAut_star_apply] + simp only [krausGram, krausDiagonalize, map_sum, map_smul] + rw [Matrix.gram_smul_sum, Matrix.star_eq_conjTranspose] + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- **The diagonalized family induces the same operator-sum map** (Nielsen & Chuang, Exercise 8.10): +`krausSumₗ (krausDiagonalize b E) = krausSumₗ E`, so `{Fⱼ}` is a set of operation elements for the +*same* quantum operation `E`. Since `Fₐ = ∑ᵢ uᵢₐ • Eᵢ` with `u` unitary (hence `uᵀ` unitary, +`Matrix.transpose_mem_unitaryGroup_iff`), this is the unitary freedom in the operator-sum +representation (`ContinuousLinearMap.krausSumₗ_eq_of_unitary_smul`, N&C Theorem 8.2). -/ +theorem krausSumₗ_krausDiagonalize [CompleteSpace H] [CompleteSpace G] + (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + krausSumₗ (krausDiagonalize b E) = krausSumₗ E := by + refine krausSumₗ_eq_of_unitary_smul + (u := ((krausGram_isHermitian b E).eigenvectorUnitary : Matrix ι ι ℂ).transpose) + (Matrix.transpose_mem_unitaryGroup_iff.mpr (SetLike.coe_mem _)) (fun a => ?_) + simp only [krausDiagonalize, Matrix.transpose_apply] + +/-- **The diagonalized operation elements are Hilbert–Schmidt orthogonal** (Nielsen & Chuang, +Exercise 8.10): `tr(Fₐ† F_c) = 0` for `a ≠ c`. The off-diagonal entries of their Gram matrix vanish, +since it is diagonal (`krausGram_krausDiagonalize`). -/ +theorem krausDiagonalize_trace_orthogonal [CompleteSpace H] [CompleteSpace G] + (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) {a c : ι} (hac : a ≠ c) : + LinearMap.trace ℂ H + ((adjoint (krausDiagonalize b E a)).toLinearMap ∘ₗ (krausDiagonalize b E c).toLinearMap) + = 0 := by + rw [← krausGram_apply b (krausDiagonalize b E) a c, krausGram_krausDiagonalize, + Matrix.diagonal_apply_ne _ hac] + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- A diagonalized operation element `Fₐ` is non-zero exactly when the corresponding eigenvalue of +`W = krausGram b E` is non-zero: its squared Hilbert–Schmidt norm is `⟪vec Fₐ, vec Fₐ⟫ = λₐ`. -/ +theorem krausDiagonalize_ne_zero_iff (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) (a : ι) : + krausDiagonalize b E a ≠ 0 ↔ (krausGram_isHermitian b E).eigenvalues a ≠ 0 := by + have hnorm : (⟪(TensorProduct.matricize b).symm (krausDiagonalize b E a), + (TensorProduct.matricize b).symm (krausDiagonalize b E a)⟫_ℂ) + = RCLike.ofReal ((krausGram_isHermitian b E).eigenvalues a) := by + have hg : krausGram b (krausDiagonalize b E) a a + = ⟪(TensorProduct.matricize b).symm (krausDiagonalize b E a), + (TensorProduct.matricize b).symm (krausDiagonalize b E a)⟫_ℂ := by + rw [krausGram, Matrix.gram_apply] + rw [← hg, krausGram_krausDiagonalize, Matrix.diagonal_apply_eq, Function.comp_apply] + refine not_congr ?_ + rw [← (TensorProduct.matricize b).symm.map_eq_zero_iff, ← inner_self_eq_zero (𝕜 := ℂ), hnorm, + RCLike.ofReal_eq_zero] + +/-- **At most `dim G · dim H` of the diagonalized operation elements are non-zero** (Nielsen & +Chuang, Exercise 8.11, the `d`-to-`d′` form). The number of non-zero `Fₐ` equals the number of +non-zero eigenvalues of `W`, which is `rank W` (`Matrix.IsHermitian.rank_eq_card_non_zero_eigs`), at +most `dim G · dim H` (`krausGram_rank_le`). -/ +theorem krausDiagonalize_card_ne_zero_le (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] G) : + Nat.card {a // krausDiagonalize b E a ≠ 0} ≤ Module.finrank ℂ G * Module.finrank ℂ H := by + rw [Nat.card_congr (Equiv.subtypeEquivRight (krausDiagonalize_ne_zero_iff b E)), + Nat.card_eq_fintype_card, ← (krausGram_isHermitian b E).rank_eq_card_non_zero_eigs] + exact krausGram_rank_le b E + +/-- **At most `d²` diagonalized operation elements are non-zero, on a `d`-dimensional system** +(Nielsen & Chuang, Exercise 8.10): the count of non-zero `Fₐ` is `rank W ≤ d²`. Together with +`krausSumₗ_krausDiagonalize` (same operation) and `krausDiagonalize_trace_orthogonal` +(orthogonality), this exhibits N&C's "at most `d²` non-zero operation elements `{Fⱼ}` for `E`", +proving Theorem 8.3 via the Gram-matrix route. -/ +theorem krausDiagonalize_card_ne_zero_le_sq (b : OrthonormalBasis ιb ℂ H) (E : ι → H →L[ℂ] H) : + Nat.card {a // krausDiagonalize b E a ≠ 0} ≤ Module.finrank ℂ H ^ 2 := by + rw [pow_two] + exact krausDiagonalize_card_ne_zero_le b E + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSum.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSum.lean new file mode 100644 index 0000000000..31a9b9cd04 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSum.lean @@ -0,0 +1,849 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PostMeasurement +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# The operator-sum (Kraus) map, and unitary freedom in its representation + +For a finite family of operators `E : ι → (H →L[ℂ] G)` — each mapping an input +space `H` to an output space `G` — the **operator-sum map** sends an operator `ρ` +on `H` to +`Σᵢ Eᵢ ρ Eᵢ†` +on `G`. This is the algebraic core of the operator-sum (Kraus) representation of a +quantum operation (Nielsen–Chuang §8.2, Theorem 8.1): a quantum operation admits +the form `E(ρ) = Σᵢ Eᵢ ρ Eᵢ†` with `Σᵢ Eᵢ† Eᵢ ≤ 1`. + +This file introduces the map as a `ℂ`-linear map `krausSumₗ` in the operator +argument and records the structural properties the representation rests on: + +* `ContinuousLinearMap.krausSumₗ_isPositive` — the map sends positive operators to + positive operators, each summand `Eᵢ ρ Eᵢ†` being a conjugate of `ρ`; +* `ContinuousLinearMap.trace_krausSumₗ` — the trace identity + `tr(Σᵢ Eᵢ ρ Eᵢ†) = tr((Σᵢ Eᵢ† Eᵢ) ρ)`, + the cyclicity computation behind the operator-sum trace condition + `Σᵢ Eᵢ† Eᵢ ≤ 1` (which controls `tr[E(ρ)]`, N&C axiom A1); +* `ContinuousLinearMap.re_trace_krausSumₗ_le` — **axiom A1**: under the trace condition + `Σᵢ Eᵢ† Eᵢ ≤ 1` the map is trace-non-increasing on positive operators, + `re tr(Σᵢ Eᵢ ρ Eᵢ†) ≤ re tr ρ`, obtained from the trace identity and the general fact + `ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg` that `re tr(A B) ≥ 0` for positive `A, B`. + +The single-summand building block `Eₘ(ρ) = Mₘ ρ Mₘ†` (with equal input/output +space) is `ContinuousLinearMap.postOp`; this file is its finite-sum, possibly +space-changing, generalization. + +## Unitary freedom in the operator-sum representation (Theorem 8.2) + +Two equal-size families `E`, `F` of operation elements on a *single* space `H` (the +"padded" form — pad the shorter list with zero operators so both are indexed by the common +`ι`) give **the same operator-sum map** iff their elements are related by a unitary coefficient +matrix — Nielsen & Chuang, **Theorem 8.2**: + +* `ContinuousLinearMap.krausSumₗ_eq_iff_exists_mem_unitaryGroup` — **the theorem**: + `krausSumₗ E = krausSumₗ F ↔ ∃ u ∈ Matrix.unitaryGroup ι ℂ, ∀ i, Eᵢ = ∑ j, uᵢⱼ • Fⱼ`. +* `ContinuousLinearMap.krausSumₗ_eq_of_mem_unitaryGroup` — the `⇐` direction on its own: a + unitary mixing of the operation elements leaves the operator-sum map unchanged. + +The proof reduces Theorem 8.2 to its ensemble analogue **Theorem 2.6** +(`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup`) through the **Choi / +vectorization bridge**. Vectorizing an operator against an orthonormal basis via the +matricization isomorphism, `vec A = (TensorProduct.matricize b).symm A = ∑ₖ (A bₖ) ⊗ bₖ`, the +Choi operator `∑ᵢ |vec Eᵢ⟩⟨vec Eᵢ|` on `H ⊗ H` is a fixed linear function of the operator-sum +map's values on the basis rank-one operators +(`ContinuousLinearMap.sum_rankOne_matricizeSymm_eq`), so equal operator-sum maps give equal +Choi operators; Theorem 2.6 supplies the relating unitary, and applying the linear equivalence +`matricize` transports it back to the operation elements. The converse is a direct star-algebra +computation collapsing `∑ᵢ uᵢⱼ conj uᵢₖ = δⱼₖ` by unitarity. The tensor-side building blocks are +the general lemmas `InnerProductSpace.rankOne_tmul_tmul` (beside `rankOne_tmul_self` in +`Mathlib.Analysis.InnerProductSpace.TensorProduct`) and `InnerProductSpace.rankOne_sum_sum` (beside +`rankOne_sum_smul_sum_smul` in `Mathlib.Analysis.InnerProductSpace.LinearMap`). + +## Operator-sum from a dilation isometry (`LinearMap`) + +Where the map above *packages* given operation elements, `LinearMap.krausOp` *produces* them from a +dilation `V : Hin →ₗ[𝕜] E ⊗ F` and an orthonormal basis `b` of the factor `F` to be traced out: +`krausOp b V k = ⟨b k| V`. Then `LinearMap.partialTraceRight_conj_eq_sum_krausOp` recovers the +operator sum `partialTraceRight b (V ρ V†) = ∑ₖ Eₖ ρ Eₖ†` (N&C Eqs. (8.9)–(8.10)), and, when `V` is +an isometry, `LinearMap.sum_adjoint_krausOp_comp_krausOp` gives the completeness relation +`∑ₖ Eₖ† Eₖ = 1` (N&C Eq. (8.14)) — the different-input/output-space form (Exercise 8.3). + +## Operator-sum from an ancilla in a fixed pure state (`LinearMap`) + +Where the dilation half takes the isometry `V` as given, this last half *produces the dilation* from +the physical ingredients: an environment (ancilla) prepared in a fixed pure state `ω` and a joint +unitary interaction. The **ancilla embedding** `tmulRightVec ω = (x ↦ x ⊗ₜ ω) : E →ₗ E ⊗ F` is the +general-vector analogue of `embedRight` (`embedRight b k = tmulRightVec (b k)`), with contraction +adjoint `contractRightVec ω = (x ⊗ₜ y ↦ ⟪ω, y⟫ • x)`. + +* `LinearMap.adjoint_tmulRightVec` — `(tmulRightVec ω)† = contractRightVec ω`; +* `LinearMap.adjoint_tmulRightVec_comp_self` — `(tmulRightVec ω)† ∘ₗ tmulRightVec ω = 1` for a unit + vector `ω` (the ancilla embedding is an isometry); +* `LinearMap.map_rankOne_eq_conj_tmulRightVec` — the key **ancilla-conjugation identity** + `map A |ω⟩⟨ω| = tmulRightVec ω ∘ₗ A ∘ₗ (tmulRightVec ω)†`: preparing the environment in `|ω⟩` and + tensoring is a conjugation by the single map `tmulRightVec ω`, which is what introduces the + dilation `V`. + +Assembling these with the dilation half gives the **environment-model operator-sum representation** +for a joint map `W : Hin ⊗ Anc →ₗ Eout ⊗ Fdisc` (the unitary interaction composed with any +reindexing of the enlarged space into a kept factor `Eout` and a discarded factor `Fdisc`), with +dilation `V = W ∘ₗ tmulRightVec ω`: + +* `LinearMap.partialTraceRight_conj_map_rankOne_eq_sum_krausOp` — discarding `Fdisc` from + `W (ρ ⊗ |ω⟩⟨ω|) W†` returns `∑ₖ Eₖ ρ Eₖ†` with `Eₖ = krausOp b (W ∘ₗ tmulRightVec ω)` (any `W`); +* `LinearMap.partialTraceRight_conj_map_sum_rankOne_eq_sum_krausOp` — the mixed-environment + generalization (Nielsen–Chuang Eqs. (8.33)–(8.35)): for an ancilla operator `∑ⱼ |wⱼ⟩⟨wⱼ|` the + result is the double sum `∑ⱼ ∑ₖ Eⱼₖ ρ Eⱼₖ†` with `Eⱼₖ = krausOp b (W ∘ₗ tmulRightVec (wⱼ))`; +* `LinearMap.sum_adjoint_krausOp_tmulRightVec_comp_krausOp` — `∑ₖ Eₖ† Eₖ = 1` when `W` is an + isometry and `‖ω‖ = 1`. + +Input space `Hin` and output space `Eout` need not agree, so this is exactly the different +input/output space operator-sum derivation of Nielsen–Chuang Exercise 8.3. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §8.2 (Theorems 8.1, 8.2; Exercise 8.3). +-/ + +open scoped InnerProductSpace TensorProduct + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + {ι : Type*} [Fintype ι] + +/-- The **operator-sum (Kraus) map** of a finite family `E : ι → (H →L[ℂ] G)`, as a +`ℂ`-linear map in the operator argument: `ρ ↦ Σᵢ Eᵢ ρ Eᵢ†`. The individual summand +`Eᵢ ρ Eᵢ†` is `ContinuousLinearMap.postOp` in the equal-space case. -/ +noncomputable def krausSumₗ (E : ι → H →L[ℂ] G) : + (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G) where + toFun ρ := ∑ i, (E i) ∘L ρ ∘L adjoint (E i) + map_add' ρ σ := by + simp only [add_comp, comp_add, Finset.sum_add_distrib] + map_smul' c ρ := by + simp only [smul_comp, comp_smul, RingHom.id_apply, Finset.smul_sum] + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +@[simp] +theorem krausSumₗ_apply (E : ι → H →L[ℂ] G) (ρ : H →L[ℂ] H) : + krausSumₗ E ρ = ∑ i, (E i) ∘L ρ ∘L adjoint (E i) := rfl + +omit [FiniteDimensional ℂ H] in +/-- The operator-sum map written with the C⋆-algebra product and star on `H →L[ℂ] H` (composition +`*` and adjoint `star`): `krausSumₗ E ρ = Σᵢ Eᵢ ρ Eᵢ⋆`. The `*`/`star` form of `krausSumₗ_apply`, +convenient for operator-algebra manipulations of the Kraus sum (e.g. quantum error-correction). -/ +theorem krausSumₗ_eq_sum_mul_star (E : ι → H →L[ℂ] H) (ρ : H →L[ℂ] H) : + krausSumₗ E ρ = ∑ i, E i * ρ * star (E i) := by + rw [krausSumₗ_apply] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [star_eq_adjoint, ← mul_def, ← mul_def, mul_assoc] + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- The operator-sum map preserves positivity: `ρ ≥ 0 ⟹ Σᵢ Eᵢ ρ Eᵢ† ≥ 0`, each +summand being the conjugate `Eᵢ ρ Eᵢ†` of the positive operator `ρ` +(`ContinuousLinearMap.IsPositive.conj_adjoint`). -/ +theorem krausSumₗ_isPositive (E : ι → H →L[ℂ] G) {ρ : H →L[ℂ] H} + (hρ : ρ.IsPositive) : (krausSumₗ E ρ).IsPositive := by + rw [krausSumₗ_apply] + exact isPositive_sum Finset.univ fun i _ => hρ.conj_adjoint (E i) + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- The operator-sum map preserves positivity, stated in the Loewner order: +`0 ≤ ρ ⟹ 0 ≤ Σᵢ Eᵢ ρ Eᵢ†`. The `0 ≤ ·` form of `krausSumₗ_isPositive`, matching the +order used for the operator-sum trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`. -/ +theorem krausSumₗ_nonneg (E : ι → H →L[ℂ] G) {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) : + 0 ≤ krausSumₗ E ρ := + nonneg_iff_isPositive.2 (krausSumₗ_isPositive E (nonneg_iff_isPositive.1 hρ)) + +/-- Cyclicity of the trace for a single summand: `tr(E ρ E†) = tr(E† E ρ)`, moving +the output-space factor `E` around the cycle back to the input space. -/ +theorem trace_conj_adjoint (E : H →L[ℂ] G) (ρ : H →L[ℂ] H) : + LinearMap.trace ℂ G ((E ∘L ρ ∘L adjoint E : G →L[ℂ] G) : G →ₗ[ℂ] G) + = LinearMap.trace ℂ H ((adjoint E ∘L E ∘L ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + simp only [ContinuousLinearMap.toLinearMap_comp] + rw [LinearMap.trace_comp_comm', LinearMap.comp_assoc, LinearMap.trace_comp_comm', + LinearMap.comp_assoc] + +/-- **The operator-sum trace identity.** The trace of `Σᵢ Eᵢ ρ Eᵢ†` on the output +space equals the trace of `(Σᵢ Eᵢ† Eᵢ) ρ` on the input space: +`tr(Σᵢ Eᵢ ρ Eᵢ†) = tr((Σᵢ Eᵢ† Eᵢ) ρ)`. This is the algebraic content behind the +operator-sum trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`: it recasts `tr[E(ρ)]` as the pairing +of `ρ` with `Σᵢ Eᵢ† Eᵢ`. -/ +theorem trace_krausSumₗ (E : ι → H →L[ℂ] G) (ρ : H →L[ℂ] H) : + LinearMap.trace ℂ G ((krausSumₗ E ρ : G →L[ℂ] G) : G →ₗ[ℂ] G) + = LinearMap.trace ℂ H + (((∑ i, adjoint (E i) ∘L E i) ∘L ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + rw [krausSumₗ_apply, ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.toLinearMap_sum, + map_sum, ContinuousLinearMap.toLinearMap_sum, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [trace_conj_adjoint (E i) ρ, ← ContinuousLinearMap.comp_assoc] + +/-- **The Kraus map of a completeness-satisfying family sends density operators to density +operators.** If `∑ᵢ Eᵢ† Eᵢ = I` and `ρ` is a density operator, then `∑ᵢ Eᵢ ρ Eᵢ†` is again a +density operator: positivity is `krausSumₗ_isPositive`, and the trace is +`tr(∑ᵢ Eᵢ ρ Eᵢ†) = tr((∑ᵢ Eᵢ† Eᵢ) ρ) = tr ρ = 1` (`trace_krausSumₗ` with the completeness +relation). This is the density-operator core of the trace-preserving (`∑ᵢ Eᵢ† Eᵢ = I`) case of the +operator-sum (Kraus) representation (Nielsen & Chuang, Theorem 8.1). -/ +theorem isDensityOp_krausSumₗ (E : ι → H →L[ℂ] H) + (hE : ∑ i, adjoint (E i) ∘L E i = 1) {ρ : H →L[ℂ] H} (hρ : ρ.IsDensityOp) : + (krausSumₗ E ρ).IsDensityOp := by + rw [isDensityOp_iff] + refine ⟨krausSumₗ_isPositive E hρ.isPositive, ?_⟩ + rw [trace_krausSumₗ, hE, ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp] + exact hρ.trace_eq_one + +/-- **The trace of a product of positive operators has nonnegative real part.** For positive +operators `A, B` on a finite-dimensional complex Hilbert space, `0 ≤ re tr(A B)`. Writing +`tr(A B) = tr(√B · A · √B)` by sqrt-sandwich cyclicity (`trace_cfc_sqrt_sandwich_eq_trace_mul`), +the sandwich `√B · A · √B` is the conjugate of the positive operator `A` by the self-adjoint +`√B`, hence positive (`IsPositive.conj_adjoint`), so its trace has nonnegative real part +(the trace norm of a positive operator, `traceNorm_eq_re_trace_of_isPositive`). This is the +algebraic sign fact behind the operator-sum trace bound (N&C axiom A1). -/ +theorem re_trace_mul_nonneg_of_nonneg {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] {A B : E →L[ℂ] E} (hA : 0 ≤ A) (hB : 0 ≤ B) : + 0 ≤ RCLike.re (LinearMap.trace ℂ E ((A * B : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + rw [← trace_cfc_sqrt_sandwich_eq_trace_mul hB A] + have hApos : A.IsPositive := nonneg_iff_isPositive.mp hA + have hpos : (cfc Real.sqrt B * A * cfc Real.sqrt B : E →L[ℂ] E).IsPositive := by + have h := hApos.conj_adjoint (cfc Real.sqrt B) + rw [(IsSelfAdjoint.cfc (a := B)).adjoint_eq, ← comp_assoc] at h + simpa only [← mul_def] using h + rw [← traceNorm_eq_re_trace_of_isPositive hpos] + exact traceNorm_nonneg _ + +/-- **Trace monotonicity of the pairing against a positive operator.** For operators `A ≤ B` and a +positive operator `Q` on a finite-dimensional complex Hilbert space, `re tr(A Q) ≤ re tr(B Q)`: +pairing against `Q ≥ 0` is monotone in the Loewner order. The gap `re tr((B − A) Q) ≥ 0` is +nonnegative because `B − A ≥ 0` and `Q ≥ 0` (`re_trace_mul_nonneg_of_nonneg`), and the trace of the +difference splits by linearity. -/ +theorem re_trace_mul_mono_left {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] {A B Q : E →L[ℂ] E} (hAB : A ≤ B) (hQ : 0 ≤ Q) : + RCLike.re (LinearMap.trace ℂ E ((A * Q : E →L[ℂ] E) : E →ₗ[ℂ] E)) ≤ + RCLike.re (LinearMap.trace ℂ E ((B * Q : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + rw [← sub_nonneg, ← map_sub, ← map_sub, ← ContinuousLinearMap.toLinearMap_sub, ← sub_mul] + exact re_trace_mul_nonneg_of_nonneg (sub_nonneg.mpr hAB) hQ + +/-- **Cyclicity of the operator trace on continuous linear maps.** For operators `X, Y` on a +finite-dimensional complex inner product space, `tr(X Y) = tr(Y X)` — the `ContinuousLinearMap` +wrapper of `LinearMap.trace_mul_comm`, so trace-cyclicity can be cited directly on `→L[ℂ]` +operators (the `re`-part follows by `congrArg RCLike.re`). -/ +theorem trace_mul_comm {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (X Y : E →L[ℂ] E) : + LinearMap.trace ℂ E ((X * Y : E →L[ℂ] E) : E →ₗ[ℂ] E) + = LinearMap.trace ℂ E ((Y * X : E →L[ℂ] E) : E →ₗ[ℂ] E) := by + rw [ContinuousLinearMap.toLinearMap_mul, LinearMap.trace_mul_comm, + ← ContinuousLinearMap.toLinearMap_mul] + +/-- **Cyclicity of the real operator trace.** The `re`-part of `trace_mul_comm`: +`re tr(X Y) = re tr(Y X)` for operators `X, Y` on a finite-dimensional complex inner product +space. -/ +theorem re_trace_mul_comm {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (X Y : E →L[ℂ] E) : + RCLike.re (LinearMap.trace ℂ E ((X * Y : E →L[ℂ] E) : E →ₗ[ℂ] E)) + = RCLike.re (LinearMap.trace ℂ E ((Y * X : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + rw [ContinuousLinearMap.trace_mul_comm] + +/-- **Trace of `(1 − X)·A` splits as `tr A − tr(X·A)`** (real part), the "error term = `1 −` +fidelity" decomposition: `(1 − X)·A = A − X·A`, and both `LinearMap.trace` and `RCLike.re` are +additive. -/ +theorem re_trace_one_sub_mul {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (X A : E →L[ℂ] E) : + RCLike.re (LinearMap.trace ℂ E (↑((1 - X) * A) : E →ₗ[ℂ] E)) + = RCLike.re (LinearMap.trace ℂ E (↑A : E →ₗ[ℂ] E)) + - RCLike.re (LinearMap.trace ℂ E (↑(X * A) : E →ₗ[ℂ] E)) := by + rw [show ((1 - X) * A) = A - X * A from by rw [sub_mul, one_mul], + ContinuousLinearMap.toLinearMap_sub, map_sub, map_sub] + +/-- **A self-adjoint idempotent (an orthogonal projection) is `≤ 1`** in the Loewner order. +`1 − P` is again a self-adjoint idempotent, hence positive +(`IsIdempotentElem.isPositive_iff_isSelfAdjoint`), so `0 ≤ 1 − P`, i.e. `P ≤ 1`. -/ +theorem IsIdempotentElem.le_one {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [CompleteSpace E] {P : E →L[ℂ] E} (hP : IsIdempotentElem P) + (hPsa : IsSelfAdjoint P) : P ≤ 1 := by + have hsa : IsSelfAdjoint (1 - P) := by + change star (1 - P) = 1 - P; rw [star_sub, star_one, hPsa.star_eq] + have hpos : (1 - P).IsPositive := + (ContinuousLinearMap.IsIdempotentElem.isPositive_iff_isSelfAdjoint hP.one_sub).mpr hsa + exact sub_nonneg.mp (nonneg_iff_isPositive.mpr hpos) + +/-- **A scalar Loewner bound gives a scalar trace bound.** If `A ≤ c • 1` and `Q ≥ 0` then +`re tr(A Q) ≤ c · re tr Q`. Immediate from `re_trace_mul_mono_left` (with `B = c • 1`) together with +`(c • 1) Q = c • Q` and `re tr(c • Q) = c · re tr Q`. Applied with `A = P ρ^⊗ⁿ P` the +equipartition-bounded compression of `ρ^⊗ⁿ` to its typical subspace, this is the false-decoding +decay `tr(P σ_bar^⊗ⁿ P · Q) ≤ 2^{−n(S−ε)} tr Q` of the HSW random-coding error estimate +(Nielsen & Chuang, eq. 12.82). -/ +theorem re_trace_mul_le_smul_of_le_smul_one {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] {A Q : E →L[ℂ] E} {c : ℝ} + (hA : A ≤ c • (1 : E →L[ℂ] E)) (hQ : 0 ≤ Q) : + RCLike.re (LinearMap.trace ℂ E ((A * Q : E →L[ℂ] E) : E →ₗ[ℂ] E)) ≤ + c * RCLike.re (LinearMap.trace ℂ E ((Q : E →L[ℂ] E) : E →ₗ[ℂ] E)) := by + refine (re_trace_mul_mono_left hA hQ).trans ?_ + rw [smul_mul_assoc, one_mul, ← Complex.coe_smul, ContinuousLinearMap.toLinearMap_smul, map_smul, + smul_eq_mul] + exact (RCLike.re_ofReal_mul c _).le + +/-- **A sub-unital positive operator is below its own square root.** For `0 ≤ A ≤ 1` on a +complex Hilbert space, `A ≤ √A` (with `√· = cfc Real.sqrt ·`). Since `A` and +`√A` are both functions of `A` (hence commute), the Loewner order between them is the pointwise +order of the underlying scalar functions on `spectrum ℝ A`, and `x ≤ √x` holds on `[0, 1]` +(`Real.le_sqrt_of_sq_le`, reducing to `x² ≤ x` for `0 ≤ x ≤ 1`). The spectral hypotheses are `0 ≤ x` +(`spectrum_nonneg_of_nonneg`) and `x ≤ 1` (`le_algebraMap_iff_spectrum_le`, from `A ≤ 1`), and the +lift is `cfc_mono` against `cfc_id`. -/ +theorem le_cfc_real_sqrt_of_le_one {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [CompleteSpace E] {A : E →L[ℂ] E} (hA : 0 ≤ A) (hA1 : A ≤ 1) : + A ≤ cfc Real.sqrt A := by + have hspec_le : ∀ x ∈ spectrum ℝ A, x ≤ 1 := + (le_algebraMap_iff_spectrum_le (R := ℝ) (A := E →L[ℂ] E) (r := 1) (a := A)).mp + (by simpa using hA1) + have hpt : ∀ x ∈ spectrum ℝ A, (id x : ℝ) ≤ Real.sqrt x := by + intro x hx + simp only [id_eq] + exact Real.le_sqrt_of_sq_le (by nlinarith [spectrum_nonneg_of_nonneg hA hx, hspec_le x hx]) + calc A = cfc id A := (cfc_id ℝ A).symm + _ ≤ cfc Real.sqrt A := cfc_mono hpt + +/-- **The Hilbert–Schmidt overlap of two sub-unital positive operators is at most their affinity.** +For `0 ≤ A ≤ 1` and `0 ≤ B ≤ 1` on a finite-dimensional complex Hilbert space, +`re tr(A B) ≤ re tr(√A √B)` (with `√· = cfc Real.sqrt ·`). Each operator is below its own square +root (`le_cfc_real_sqrt_of_le_one`, as `A, B ≤ 1`), so pairing against the positive `B` and then +against the positive `√A` and applying trace monotonicity (`re_trace_mul_mono_left`) twice — with +`re_trace_mul_comm` cycling the second pairing to the correct side — replaces `A` by `√A` and `B` by +`√B` in turn: +`re tr(A B) ≤ re tr(√A B) = re tr(B √A) ≤ re tr(√B √A) = re tr(√A √B)`. +Applied to two density operators (each `≤ 1`, `IsDensityOp.le_one`), this is the statement that the +Hilbert–Schmidt overlap `tr(ρ σ)` is dominated by the quantum affinity `tr(√ρ √σ)`. -/ +theorem re_trace_mul_le_re_trace_cfc_sqrt_mul {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] {A B : E →L[ℂ] E} + (hA : 0 ≤ A) (hA1 : A ≤ 1) (hB : 0 ≤ B) (hB1 : B ≤ 1) : + RCLike.re (LinearMap.trace ℂ E ((A * B : E →L[ℂ] E) : E →ₗ[ℂ] E)) ≤ + RCLike.re (LinearMap.trace ℂ E + ((cfc Real.sqrt A * cfc Real.sqrt B : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + calc RCLike.re (LinearMap.trace ℂ E ((A * B : E →L[ℂ] E) : E →ₗ[ℂ] E)) + ≤ RCLike.re (LinearMap.trace ℂ E ((cfc Real.sqrt A * B : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + re_trace_mul_mono_left (le_cfc_real_sqrt_of_le_one hA hA1) hB + _ = RCLike.re (LinearMap.trace ℂ E ((B * cfc Real.sqrt A : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + re_trace_mul_comm _ _ + _ ≤ RCLike.re (LinearMap.trace ℂ E + ((cfc Real.sqrt B * cfc Real.sqrt A : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + re_trace_mul_mono_left (le_cfc_real_sqrt_of_le_one hB hB1) (cfc_real_sqrt_nonneg A) + _ = RCLike.re (LinearMap.trace ℂ E + ((cfc Real.sqrt A * cfc Real.sqrt B : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + re_trace_mul_comm _ _ + +/-- **Operator-sum trace bound — Nielsen–Chuang axiom A1.** If the operator-sum trace condition +`Σᵢ Eᵢ† Eᵢ ≤ 1` holds and `ρ` is positive, then the operator-sum map is trace-non-increasing: +`re tr(Σᵢ Eᵢ ρ Eᵢ†) ≤ re tr ρ`. Together with `tr ρ ≤ 1` this yields the physical bound +`tr[E(ρ)] ≤ 1`. Proof: `trace_krausSumₗ` recasts the left-hand trace as `tr((Σᵢ Eᵢ† Eᵢ) ρ)`; +with `A = Σᵢ Eᵢ† Eᵢ`, the operators `A ρ` and `(1 − A) ρ` sum to `ρ`, and `re tr((1 − A) ρ) ≥ 0` +by `re_trace_mul_nonneg_of_nonneg` (as `1 − A ≥ 0`), so `re tr(A ρ) ≤ re tr ρ`. -/ +theorem re_trace_krausSumₗ_le (E : ι → H →L[ℂ] G) {ρ : H →L[ℂ] H} (hρ : 0 ≤ ρ) + (hE : ∑ i, adjoint (E i) ∘L E i ≤ 1) : + RCLike.re (LinearMap.trace ℂ G ((krausSumₗ E ρ : G →L[ℂ] G) : G →ₗ[ℂ] G)) + ≤ RCLike.re (LinearMap.trace ℂ H ((ρ : H →L[ℂ] H) : H →ₗ[ℂ] H)) := by + rw [trace_krausSumₗ] + set A := ∑ i, adjoint (E i) ∘L E i + rw [← mul_def] + have hcrux : 0 ≤ RCLike.re (LinearMap.trace ℂ H (((1 - A) * ρ : H →L[ℂ] H) : H →ₗ[ℂ] H)) := + re_trace_mul_nonneg_of_nonneg (sub_nonneg.mpr hE) hρ + have hsum : (A * ρ + (1 - A) * ρ : H →L[ℂ] H) = ρ := by noncomm_ring + have htr : RCLike.re (LinearMap.trace ℂ H ((A * ρ : H →L[ℂ] H) : H →ₗ[ℂ] H)) + + RCLike.re (LinearMap.trace ℂ H (((1 - A) * ρ : H →L[ℂ] H) : H →ₗ[ℂ] H)) + = RCLike.re (LinearMap.trace ℂ H ((ρ : H →L[ℂ] H) : H →ₗ[ℂ] H)) := by + rw [← map_add, ← map_add, ← ContinuousLinearMap.toLinearMap_add, hsum] + linarith [hcrux, htr] + +omit [FiniteDimensional ℂ H] in +/-- **A trace-preserving Kraus family preserves the squared norm of every vector.** If the +operation elements satisfy the completeness relation `Σᵢ Eᵢ† Eᵢ = 1`, then `Σᵢ ‖Eᵢ ψ‖² = ‖ψ‖²`. +Each summand is `‖Eᵢ ψ‖² = re ⟪ψ, (Eᵢ† Eᵢ) ψ⟫` (`apply_norm_sq_eq_inner_adjoint_right`), and the +completeness relation collapses the sum to `re ⟪ψ, ψ⟫ = ‖ψ‖²`. -/ +theorem sum_normSq_apply_of_sum_adjoint_mul_self_eq_one + (E : ι → H →L[ℂ] H) (hE : ∑ i, adjoint (E i) * E i = 1) (ψ : H) : + ∑ i, ‖E i ψ‖ ^ 2 = ‖ψ‖ ^ 2 := by + have key : ∑ i, ‖E i ψ‖ ^ 2 = RCLike.re (inner ℂ ψ ((∑ i, adjoint (E i) * E i) ψ)) := by + rw [sum_apply, inner_sum, map_sum] + exact Finset.sum_congr rfl fun i _ => apply_norm_sq_eq_inner_adjoint_right (E i) ψ + rw [key, hE, one_apply_eq_self, inner_self_eq_norm_sq] + +/-! ### Unitary freedom in the operator-sum representation (Nielsen–Chuang Theorem 8.2) + +The results below are on a **single** space (`G = H`): two equal-size Kraus families give the same +operator-sum map iff they are unitarily related. -/ + +omit [FiniteDimensional ℂ H] [CompleteSpace H] in +/-- **Choi expansion of a vectorized rank-one operator.** For an operator `A` and an orthonormal +basis `b`, the rank-one projector of the vectorization `vec A = (matricize b).symm A = ∑ₖ (A bₖ) ⊗ +bₖ` expands, by bi-additivity and the tensor rank-one factorization, into a double sum of +tensor-product maps `∑ₖ ∑ₗ mapL |A bₖ⟩⟨A bₗ| |bₖ⟩⟨bₗ|`. -/ +theorem rankOne_matricizeSymm_eq {κ : Type*} [Fintype κ] (b : OrthonormalBasis κ ℂ H) + (A : H →L[ℂ] H) : + (InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm A) + ((TensorProduct.matricize b).symm A) : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) + = ∑ k, ∑ l, TensorProduct.mapL (InnerProductSpace.rankOne ℂ (A (b k)) (A (b l))) + (InnerProductSpace.rankOne ℂ (b k) (b l)) := by + rw [TensorProduct.matricize_symm_apply, InnerProductSpace.rankOne_sum_sum] + exact Finset.sum_congr rfl fun k _ => Finset.sum_congr rfl fun l _ => + InnerProductSpace.rankOne_tmul_tmul (A (b k)) (A (b l)) (b k) (b l) + +omit [FiniteDimensional ℂ H] in +/-- **The Choi operator of a Kraus family in terms of its operator-sum map.** Summing the rank-one +projectors of the vectorized operation elements produces the Choi operator on `H ⊗ H`, which equals +a fixed linear function of the operator-sum map evaluated on the basis rank-one operators: +`∑ᵢ |vec Eᵢ⟩⟨vec Eᵢ| = ∑ₖ ∑ₗ mapL (krausSumₗ E |bₖ⟩⟨bₗ|) |bₖ⟩⟨bₗ|`. This is the bridge that +makes the Choi operator depend on `E` **only through** its operator-sum map, so equal operator-sum +maps give equal Choi operators. -/ +theorem sum_rankOne_matricizeSymm_eq {κ : Type*} [Fintype κ] (b : OrthonormalBasis κ ℂ H) + (E : ι → H →L[ℂ] H) : + (∑ i, InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm (E i)) + ((TensorProduct.matricize b).symm (E i)) : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) + = ∑ k, ∑ l, TensorProduct.mapL (krausSumₗ E (InnerProductSpace.rankOne ℂ (b k) (b l))) + (InnerProductSpace.rankOne ℂ (b k) (b l)) := by + have hpost : ∀ (i : ι) (k l : κ), + (E i) ∘L (InnerProductSpace.rankOne ℂ (b k) (b l)) ∘L adjoint (E i) + = InnerProductSpace.rankOne ℂ (E i (b k)) (E i (b l)) := fun i k l => by + simp only [InnerProductSpace.comp_rankOne, InnerProductSpace.rankOne_comp, + ContinuousLinearMap.adjoint_adjoint] + simp only [rankOne_matricizeSymm_eq, krausSumₗ_apply, TensorProduct.mapL_sum_left, hpost] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun k _ => by rw [Finset.sum_comm] + +omit [FiniteDimensional ℂ H] in +/-- **Unitary freedom, `⇐` direction (Nielsen & Chuang Theorem 8.2).** If the operation elements of +`E` are a unitary mixing of those of `F`, `Eᵢ = ∑ⱼ uᵢⱼ Fⱼ` for `u ∈ Matrix.unitaryGroup ι ℂ`, then +`E` and `F` have the same operator-sum map, `krausSumₗ E = krausSumₗ F`. Direct star-algebra +computation: expanding `∑ᵢ Eᵢ ρ Eᵢ†` bilinearly gives `∑ⱼ ∑ₖ (∑ᵢ uᵢⱼ conj uᵢₖ) • Fⱼ ρ Fₖ†`, and +`∑ᵢ uᵢⱼ conj uᵢₖ = (u⋆ u)ₖⱼ = δₖⱼ` by unitarity, leaving `∑ⱼ Fⱼ ρ Fⱼ†`. The operator analogue of +`sum_rankOne_self_eq_of_mem_unitaryGroup`. -/ +theorem krausSumₗ_eq_of_mem_unitaryGroup [DecidableEq ι] {u : Matrix ι ι ℂ} + (hu : u ∈ Matrix.unitaryGroup ι ℂ) {E F : ι → H →L[ℂ] H} + (hEF : ∀ i, E i = ∑ j, u i j • F j) : + krausSumₗ E = krausSumₗ F := by + have key : ∀ j k : ι, + (∑ i, u i j * (starRingEnd ℂ) (u i k)) = if k = j then (1 : ℂ) else 0 := by + intro j k + have h1 : (star u * u : Matrix ι ι ℂ) = 1 := Matrix.mem_unitaryGroup_iff'.mp hu + have h2 := congrFun (congrFun h1 k) j + rw [Matrix.mul_apply, Matrix.one_apply] at h2 + rw [← h2] + exact Finset.sum_congr rfl fun i _ => by rw [Matrix.star_apply, starRingEnd_apply]; ring + refine LinearMap.ext fun ρ => ?_ + have hcomp : ∀ f : H →L[ℂ] H, f.comp (ρ.comp (adjoint f)) = f * ρ * star f := + fun f => by rw [star_eq_adjoint]; rfl + calc krausSumₗ E ρ + = ∑ i, (∑ j, u i j • F j) * ρ * star (∑ j, u i j • F j) := by + simp only [krausSumₗ_apply, hcomp, hEF] + _ = ∑ i, ∑ j, ∑ k, (u i j * (starRingEnd ℂ) (u i k)) • (F j * ρ * star (F k)) := by + refine Finset.sum_congr rfl fun i _ => ?_ + rw [star_sum] + simp only [Finset.sum_mul, Finset.mul_sum, star_smul, RCLike.star_def, smul_mul_assoc, + mul_smul_comm, Finset.smul_sum, smul_smul] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun k _ => by rw [mul_comm] + _ = ∑ j, ∑ k, ∑ i, (u i j * (starRingEnd ℂ) (u i k)) • (F j * ρ * star (F k)) := by + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun j _ => Finset.sum_comm + _ = ∑ j, ∑ k, (∑ i, u i j * (starRingEnd ℂ) (u i k)) • (F j * ρ * star (F k)) := by + simp only [Finset.sum_smul] + _ = ∑ j, ∑ k, (if k = j then (1 : ℂ) else 0) • (F j * ρ * star (F k)) := by simp only [key] + _ = ∑ i, F i * ρ * star (F i) := by + simp only [ite_smul, one_smul, zero_smul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + _ = krausSumₗ F ρ := by simp only [krausSumₗ_apply, hcomp] + +/-- **Unitary freedom in the operator-sum representation** (Nielsen & Chuang, *Quantum Computation +and Quantum Information*, **Theorem 8.2**). Two equal-size families `E`, `F` of operation elements +on a single finite-dimensional complex inner product space (the "padded" form — pad the shorter +list with zero operators so both are indexed by the common `ι`) give **the same operator-sum map**, +`krausSumₗ E = krausSumₗ F` (i.e. `∀ ρ, ∑ᵢ Eᵢ ρ Eᵢ† = ∑ⱼ Fⱼ ρ Fⱼ†`), **iff** their operation +elements are related by a unitary coefficient matrix `u ∈ Matrix.unitaryGroup ι ℂ`: +`Eᵢ = ∑ⱼ uᵢⱼ Fⱼ`. + +The `⇐` direction is `krausSumₗ_eq_of_mem_unitaryGroup`. For `⟹`: the Choi operators +`∑ᵢ |vec Eᵢ⟩⟨vec Eᵢ|` and `∑ⱼ |vec Fⱼ⟩⟨vec Fⱼ|` on `H ⊗ H` (with `vec = (matricize b).symm` against +`b := stdOrthonormalBasis ℂ H`) are equal, since by `sum_rankOne_matricizeSymm_eq` each is the same +linear function of the (equal) operator-sum maps; the vector form of Theorem 2.6 +(`InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup`) then yields a unitary `u` with +`vec Eᵢ = ∑ⱼ uᵢⱼ vec Fⱼ`, and applying the linear equivalence `matricize b` gives +`Eᵢ = ∑ⱼ uᵢⱼ Fⱼ`. -/ +theorem krausSumₗ_eq_iff_exists_mem_unitaryGroup [DecidableEq ι] {E F : ι → H →L[ℂ] H} : + krausSumₗ E = krausSumₗ F ↔ + ∃ u ∈ Matrix.unitaryGroup ι ℂ, ∀ i, E i = ∑ j, u i j • F j := by + refine ⟨fun h => ?_, fun ⟨u, hu, hEF⟩ => krausSumₗ_eq_of_mem_unitaryGroup hu hEF⟩ + have : CompleteSpace (H ⊗[ℂ] H) := FiniteDimensional.completeSpace ℂ _ + set b := stdOrthonormalBasis ℂ H with hb + have hchoi : (∑ i, InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm (E i)) + ((TensorProduct.matricize b).symm (E i)) : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) + = ∑ i, InnerProductSpace.rankOne ℂ ((TensorProduct.matricize b).symm (F i)) + ((TensorProduct.matricize b).symm (F i)) := by + rw [sum_rankOne_matricizeSymm_eq b E, sum_rankOne_matricizeSymm_eq b F, h] + obtain ⟨u, hu, hrel⟩ := + (InnerProductSpace.sum_rankOne_self_eq_iff_exists_mem_unitaryGroup _ _).mp hchoi + refine ⟨u, hu, fun i => ?_⟩ + refine (TensorProduct.matricize b).symm.injective ?_ + rw [map_sum] + simp only [map_smul] + exact hrel i + +end ContinuousLinearMap + +namespace LinearMap + +section KrausFromDilation + +variable {𝕜 Hin E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup Hin] [InnerProductSpace 𝕜 Hin] [FiniteDimensional 𝕜 Hin] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- The `k`-th **operation element** (Kraus operator) of a dilation `V : Hin →ₗ E ⊗ F` relative to +an orthonormal basis `b` of the traced-out factor `F`: `Eₖ = ⟨b k| V`, that is +`restrictRight b k ∘ₗ V : Hin →ₗ E`, the map `V` followed by contracting the `F`-slot against `b k`. +Its input space `Hin` and output space `E` need not agree. -/ +noncomputable def krausOp (b : OrthonormalBasis ι 𝕜 F) (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (k : ι) : + Hin →ₗ[𝕜] E := + restrictRight b k ∘ₗ V + +omit [FiniteDimensional 𝕜 Hin] [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +@[simp] +theorem krausOp_apply (b : OrthonormalBasis ι 𝕜 F) (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (k : ι) (x : Hin) : + krausOp b V k x = restrictRight b k (V x) := rfl + +/-- The adjoint of the `k`-th operation element: `Eₖ† = V† ∘ₗ embedRight b k`. Since `restrictRight` +and `embedRight` are mutual adjoints (`adjoint_restrictRight`), `Eₖ† = (restrictRight b k ∘ₗ V)†` +distributes to `V† ∘ₗ (restrictRight b k)† = V† ∘ₗ embedRight b k`. -/ +theorem adjoint_krausOp (b : OrthonormalBasis ι 𝕜 F) (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (k : ι) : + adjoint (krausOp b V k) = adjoint V ∘ₗ embedRight b k := by + rw [krausOp, adjoint_comp, adjoint_restrictRight] + +/-- **Operator-sum representation from a dilation** (Nielsen–Chuang Eqs. (8.9)–(8.10)). Tracing out +the factor `F` from the conjugation `V ρ V†` returns the operator sum `∑ₖ Eₖ ρ Eₖ†` over the +operation elements `Eₖ = krausOp b V k`: +`partialTraceRight b (V ∘ₗ ρ ∘ₗ V†) = ∑ k, krausOp b V k ∘ₗ ρ ∘ₗ (krausOp b V k)†`. +No hypothesis on `V` is required. Unfolding `partialTraceRight` as +`∑ k, restrictRight b k ∘ₗ · ∘ₗ embedRight b k`, each summand is `Eₖ ρ Eₖ†` after re-associating and +rewriting `V† ∘ₗ embedRight b k` as `Eₖ†` via `adjoint_krausOp`. -/ +theorem partialTraceRight_conj_eq_sum_krausOp (b : OrthonormalBasis ι 𝕜 F) + (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (ρ : Hin →ₗ[𝕜] Hin) : + partialTraceRight b (V ∘ₗ ρ ∘ₗ adjoint V) = + ∑ k, krausOp b V k ∘ₗ ρ ∘ₗ adjoint (krausOp b V k) := by + rw [partialTraceRight_eq_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [adjoint_krausOp, krausOp] + simp only [comp_assoc] + +/-- **Completeness relation** (Nielsen–Chuang Eq. (8.14)). If the dilation `V` is an isometry +(`V† ∘ₗ V = 1`) then the operation elements satisfy `∑ₖ Eₖ† Eₖ = 1`; this is precisely the condition +that makes `ρ ↦ partialTraceRight b (V ρ V†)` trace preserving. Writing `Eₖ† Eₖ = +V† ∘ₗ (embedRight b k ∘ₗ restrictRight b k) ∘ₗ V` and summing, the resolution of identity +`∑ k, embedRight b k ∘ₗ restrictRight b k = 1` (`sum_embedRight_restrictRight_eq_self`) collapses +the middle factor, leaving `V† ∘ₗ V = 1`. -/ +theorem sum_adjoint_krausOp_comp_krausOp (b : OrthonormalBasis ι 𝕜 F) + (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (hV : adjoint V ∘ₗ V = id) : + ∑ k, adjoint (krausOp b V k) ∘ₗ krausOp b V k = id := by + simp only [krausOp, adjoint_comp, adjoint_restrictRight] + ext x + simp only [LinearMap.sum_apply, comp_apply, id_apply] + rw [← map_sum, sum_embedRight_restrictRight_eq_self] + exact LinearMap.congr_fun hV x + +/-! ### The projected environment operator-sum (block-selected operation elements) + +Refining `partialTraceRight_conj_eq_sum_krausOp`: conjugating `V ρ V†` by an *environment block +projector* `P_S = ∑_{σ∈S} |b σ⟩⟨b σ|` (as `1 ⊗ P_S`) before tracing out the environment selects +exactly the operation elements indexed by a subset `S ⊆ ι`, `∑_{σ∈S} Eₖ ρ Eₖ†`. This is the +algebraic content of *measuring the block projector `P_S` on the environment, then discarding it* +(Nielsen–Chuang Exercise 8.9). The dilation `krausDilation` that assembles `V` from a prescribed +Kraus family — the converse construction shared with Exercise 8.8 — lives in +`ToMathlib.Analysis.InnerProductSpace.OperatorSumDilation`. -/ + +omit [FiniteDimensional 𝕜 Hin] [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +/-- **Contracting a block projector against a basis vector.** For the environment block projector +`P_S = ∑_{σ∈S} embedRight b σ ∘ₗ restrictRight b σ` (i.e. `1 ⊗ ∑_{σ∈S} |b σ⟩⟨b σ|`), +`restrictRight b τ ∘ₗ P_S = restrictRight b τ` when `τ ∈ S` and `0` otherwise. Each summand +`restrictRight b τ ∘ₗ embedRight b σ ∘ₗ restrictRight b σ` collapses to `if τ = σ then restrictRight +b τ else 0` (`restrictRight_comp_embedRight`), and summing over `σ ∈ S` keeps only `σ = τ`. -/ +theorem restrictRight_comp_proj [DecidableEq ι] (b : OrthonormalBasis ι 𝕜 F) (S : Finset ι) + (τ : ι) : + (restrictRight b τ : E ⊗[𝕜] F →ₗ[𝕜] E) ∘ₗ (∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ) + = if τ ∈ S then restrictRight b τ else 0 := by + refine LinearMap.ext fun w => ?_ + rw [comp_apply, LinearMap.sum_apply, map_sum] + simp only [comp_apply] + have hterm : ∀ σ, restrictRight b τ (embedRight b σ (restrictRight b σ w)) + = if τ = σ then restrictRight b τ w else 0 := by + intro σ + rw [← comp_apply (restrictRight b τ) (embedRight b σ), restrictRight_comp_embedRight] + by_cases h : τ = σ <;> simp [h] + rw [Finset.sum_congr rfl (fun σ _ => hterm σ), Finset.sum_ite_eq] + by_cases hτ : τ ∈ S <;> simp [hτ] + +omit [FiniteDimensional 𝕜 Hin] [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +/-- **The block-diagonal environment projector as a tensor map.** The summand +`embedRight b σ ∘ₗ restrictRight b σ` is `1 ⊗ |b σ⟩⟨b σ|`, i.e. +`TensorProduct.map id (rankOne 𝕜 (b σ) (b σ))`. The bridge from the `embedRight`/`restrictRight` +form used here to the `TensorProduct.map`/rank-one form a physical measurement operator takes. -/ +theorem embedRight_comp_restrictRight_eq_map_rankOne (b : OrthonormalBasis ι 𝕜 F) (σ : ι) : + (embedRight b σ ∘ₗ restrictRight b σ : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) + = TensorProduct.map LinearMap.id (InnerProductSpace.rankOne 𝕜 (b σ) (b σ)).toLinearMap := by + refine TensorProduct.ext' fun x y => ?_ + simp only [comp_apply, restrictRight_tmul, map_smul, embedRight_apply, TensorProduct.map_tmul, + id_coe, id_eq, ContinuousLinearMap.coe_coe, InnerProductSpace.rankOne_apply, + TensorProduct.tmul_smul] + +/-- **The environment block projector is self-adjoint.** For the block projector +`P_S = ∑_{σ∈S} embedRight b σ ∘ₗ restrictRight b σ` (`= 1 ⊗ ∑_{σ∈S} |b σ⟩⟨b σ|`), `P_S† = P_S`. +Each block `embedRight b σ ∘ₗ restrictRight b σ = 1 ⊗ |b σ⟩⟨b σ|` is a self-adjoint rank-one +projector on the environment factor (`embedRight`/`restrictRight` are mutual adjoints, +`adjoint_restrictRight`), and adjoint distributes over the sum. -/ +theorem adjoint_sum_embedRight_comp_restrictRight (b : OrthonormalBasis ι 𝕜 F) (S : Finset ι) : + adjoint (∑ σ ∈ S, (embedRight b σ ∘ₗ restrictRight b σ : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F)) + = ∑ σ ∈ S, (embedRight b σ ∘ₗ restrictRight b σ : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) := by + rw [map_sum] + refine Finset.sum_congr rfl fun σ _ => ?_ + rw [adjoint_comp, adjoint_restrictRight, ← adjoint_restrictRight b σ, adjoint_adjoint] + +/-- **Projected environment operator-sum** (Nielsen–Chuang Exercise 8.9). Conjugating `V ρ V†` by +the environment block projector `P_S = ∑_{σ∈S} embedRight b σ ∘ₗ restrictRight b σ` +(`= 1 ⊗ ∑_{σ∈S} |b σ⟩⟨b σ|`) on both sides and tracing out the environment returns the operator sum +over the *selected* operation elements only: +`partialTraceRight b (P_S (V ρ V†) P_S) = ∑_{σ∈S} Eₖ ρ Eₖ†` with `Eₖ = krausOp b V σ`. This is what +"measure the block projector `P_S`, then discard the environment" computes. Proof: `P_S` is +self-adjoint, so `P_S (V ρ V†) P_S = (P_S V) ρ (P_S V)†`; the operation elements of `P_S V` are +`if σ ∈ S then krausOp b V σ else 0` (`restrictRight_comp_proj`), so +`partialTraceRight_conj_eq_sum_krausOp` yields the sum over all `σ` of the block-restricted +elements, and the `σ ∉ S` terms vanish. -/ +theorem partialTraceRight_conj_sum_proj_eq_sum_krausOp + (b : OrthonormalBasis ι 𝕜 F) (V : Hin →ₗ[𝕜] E ⊗[𝕜] F) (ρ : Hin →ₗ[𝕜] Hin) (S : Finset ι) : + partialTraceRight b + ((∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ) ∘ₗ (V ∘ₗ ρ ∘ₗ adjoint V) ∘ₗ + (∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ)) + = ∑ σ ∈ S, krausOp b V σ ∘ₗ ρ ∘ₗ adjoint (krausOp b V σ) := by + classical + set P : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F := ∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ with hP + have hPsa : adjoint P = P := hP ▸ adjoint_sum_embedRight_comp_restrictRight b S + have hkraus : ∀ τ, krausOp b (P ∘ₗ V) τ = if τ ∈ S then krausOp b V τ else 0 := fun τ => by + rw [krausOp, ← comp_assoc, hP, restrictRight_comp_proj] + by_cases hτ : τ ∈ S <;> simp [hτ, krausOp] + have hconj : P ∘ₗ (V ∘ₗ ρ ∘ₗ adjoint V) ∘ₗ P = (P ∘ₗ V) ∘ₗ ρ ∘ₗ adjoint (P ∘ₗ V) := by + rw [adjoint_comp, hPsa]; simp only [comp_assoc] + rw [hconj, partialTraceRight_conj_eq_sum_krausOp] + have hpush : ∀ τ, krausOp b (P ∘ₗ V) τ ∘ₗ ρ ∘ₗ adjoint (krausOp b (P ∘ₗ V) τ) + = if τ ∈ S then krausOp b V τ ∘ₗ ρ ∘ₗ adjoint (krausOp b V τ) else 0 := fun τ => by + rw [hkraus τ]; by_cases hτ : τ ∈ S <;> simp [hτ] + rw [Finset.sum_congr rfl (fun τ _ => hpush τ), Finset.sum_ite_mem, Finset.univ_inter] + +end KrausFromDilation + +section AncillaDilation + +/-! ### The dilation from an ancilla in a fixed pure state + +The dilation `V` of the operator-sum representation arises physically from an ancilla (environment) +prepared in a fixed pure state `|ω⟩` and a joint unitary. This subsection isolates the two +facts that turn "conjugate by a joint isometry, with the ancilla slot occupied by `|ω⟩⟨ω|`" into the +dilation form `V ρ V†` of `KrausFromDilation`: the ancilla embedding `x ↦ x ⊗ₜ ω` and its +conjugation identity. +-/ + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The **ancilla embedding**: tensoring with a fixed vector `ω : F`, `x ↦ x ⊗ₜ ω`, as a linear map +`E →ₗ E ⊗ F`. The general-vector analogue of `embedRight` (`embedRight b k = tmulRightVec (b k)`): +it packages a fixed environment state `ω` alongside the principal input. -/ +noncomputable def tmulRightVec (ω : F) : E →ₗ[𝕜] E ⊗[𝕜] F := + (TensorProduct.mk 𝕜 E F).flip ω + +omit [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +@[simp] +theorem tmulRightVec_apply (ω : F) (x : E) : tmulRightVec ω x = x ⊗ₜ[𝕜] ω := rfl + +/-- The **contraction against a fixed vector** `ω : F`, `x ⊗ₜ y ↦ ⟪ω, y⟫ • x`, as a linear map +`E ⊗ F →ₗ E`. The general-vector analogue of `restrictRight`; it is the adjoint of `tmulRightVec ω` +(`adjoint_tmulRightVec`). -/ +noncomputable def contractRightVec (ω : F) : E ⊗[𝕜] F →ₗ[𝕜] E := + (TensorProduct.rid 𝕜 E).toLinearMap ∘ₗ TensorProduct.map LinearMap.id (innerSL 𝕜 ω).toLinearMap + +omit [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +@[simp] +theorem contractRightVec_tmul (ω : F) (x : E) (y : F) : + contractRightVec ω (x ⊗ₜ[𝕜] y) = ⟪ω, y⟫_𝕜 • x := rfl + +/-- **Adjoint of the ancilla embedding** is the contraction: +`(tmulRightVec ω)† = contractRightVec ω`. Mirrors `adjoint_embedRight`; proved by the inner-product +characterization on pure tensors, `⟪x ⊗ₜ ω, a ⊗ₜ b⟫ = ⟪x, ⟪ω, b⟫ • a⟫`. -/ +theorem adjoint_tmulRightVec (ω : F) : + adjoint (tmulRightVec ω : E →ₗ[𝕜] E ⊗[𝕜] F) = contractRightVec ω := by + rw [eq_comm, LinearMap.eq_adjoint_iff] + intro v u + refine v.inductionOn ?_ ?_ + · intro x y + simp [tmulRightVec_apply, contractRightVec_tmul, TensorProduct.inner_tmul, inner_smul_left, + mul_comm] + · intro a b ha hb + simp [inner_add_left, map_add, ha, hb] + +/-- **The ancilla embedding is an isometry** when `ω` is a unit vector: +`(tmulRightVec ω)† ∘ₗ tmulRightVec ω = 1`. This is what makes the assembled dilation `V` an +isometry, hence the operation elements complete +(`sum_adjoint_krausOp_tmulRightVec_comp_krausOp`). -/ +theorem adjoint_tmulRightVec_comp_self {ω : F} (hω : ‖ω‖ = 1) : + adjoint (tmulRightVec ω : E →ₗ[𝕜] E ⊗[𝕜] F) ∘ₗ tmulRightVec ω = LinearMap.id := by + rw [adjoint_tmulRightVec] + ext x + simp only [coe_comp, Function.comp_apply, tmulRightVec_apply, contractRightVec_tmul, id_coe, + id_eq] + rw [inner_self_eq_norm_sq_to_K, hω] + simp + +/-- **Ancilla conjugation as a dilation.** Tensoring an operator `A` on `E` with the rank-one +projector `|ω⟩⟨ω|` on the ancilla factor `F` equals conjugation of `A` by the ancilla embedding: +`map A |ω⟩⟨ω| = tmulRightVec ω ∘ₗ A ∘ₗ (tmulRightVec ω)†`. Preparing the environment in the fixed +pure state `|ω⟩` and conjugating is therefore a conjugation by the single map `tmulRightVec ω` — the +algebraic step that introduces the dilation `V`. Proved by evaluation on pure tensors. -/ +theorem map_rankOne_eq_conj_tmulRightVec (A : E →ₗ[𝕜] E) (ω : F) : + TensorProduct.map A (InnerProductSpace.rankOne 𝕜 ω ω).toLinearMap + = tmulRightVec ω ∘ₗ A ∘ₗ adjoint (tmulRightVec ω) := by + rw [adjoint_tmulRightVec] + refine TensorProduct.ext' fun x y ↦ ?_ + simp only [TensorProduct.map_tmul, ContinuousLinearMap.coe_coe, InnerProductSpace.rankOne_apply, + coe_comp, Function.comp_apply, contractRightVec_tmul, map_smul, tmulRightVec_apply, + TensorProduct.tmul_smul] + +end AncillaDilation + +section EnvironmentModel + +/-! ### The environment-model operator-sum representation + +Combining the ancilla embedding with `KrausFromDilation`: for a joint map +`W : Hin ⊗ Anc →ₗ Eout ⊗ Fdisc` (the unitary interaction followed by any reindexing of the enlarged +space into a "kept" factor `Eout` and a "discarded" factor `Fdisc`) and an environment prepared in a +fixed pure state `ω : Anc`, the dilation is `V = W ∘ₗ tmulRightVec ω : Hin →ₗ Eout ⊗ Fdisc`. Input +space `Hin` and output space `Eout` need not agree — the general operator-sum derivation of +Nielsen–Chuang §8.2 / Exercise 8.3. +-/ + +variable {𝕜 Hin Anc Eout Fdisc : Type*} [RCLike 𝕜] + [NormedAddCommGroup Hin] [InnerProductSpace 𝕜 Hin] [FiniteDimensional 𝕜 Hin] + [NormedAddCommGroup Anc] [InnerProductSpace 𝕜 Anc] [FiniteDimensional 𝕜 Anc] + [NormedAddCommGroup Eout] [InnerProductSpace 𝕜 Eout] [FiniteDimensional 𝕜 Eout] + [NormedAddCommGroup Fdisc] [InnerProductSpace 𝕜 Fdisc] [FiniteDimensional 𝕜 Fdisc] + {ι : Type*} [Fintype ι] + +/-- **Operator-sum representation of the environment model** (Nielsen–Chuang Eqs. (8.9)–(8.10), the +different input/output space case). Discarding the factor `Fdisc` from the conjugation of the +ancilla-extended input `ρ ⊗ |ω⟩⟨ω|` by a joint map `W : Hin ⊗ Anc →ₗ Eout ⊗ Fdisc` returns the +operator sum over the operation elements `Eₖ = krausOp b (W ∘ₗ tmulRightVec ω)`: +`partialTraceRight b (W (map ρ |ω⟩⟨ω|) W†) = ∑ₖ Eₖ ρ Eₖ†`. No hypothesis on `W` or `ω`. Folds the +ancilla conjugation into `V = W ∘ₗ tmulRightVec ω` via `map_rankOne_eq_conj_tmulRightVec`, then +applies `partialTraceRight_conj_eq_sum_krausOp`. -/ +theorem partialTraceRight_conj_map_rankOne_eq_sum_krausOp + (b : OrthonormalBasis ι 𝕜 Fdisc) (W : (Hin ⊗[𝕜] Anc) →ₗ[𝕜] Eout ⊗[𝕜] Fdisc) + (ω : Anc) (ρ : Hin →ₗ[𝕜] Hin) : + partialTraceRight b + (W ∘ₗ TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 ω ω).toLinearMap ∘ₗ adjoint W) + = ∑ k, krausOp b (W ∘ₗ tmulRightVec ω) k ∘ₗ ρ ∘ₗ + adjoint (krausOp b (W ∘ₗ tmulRightVec ω) k) := by + rw [← partialTraceRight_conj_eq_sum_krausOp] + congr 1 + rw [map_rankOne_eq_conj_tmulRightVec, adjoint_comp] + simp only [comp_assoc] + +/-- **Projected environment-model operator-sum** (Nielsen–Chuang Exercise 8.9): the block-selected +(`partialTraceRight_conj_sum_proj_eq_sum_krausOp`) *and* ancilla-prepared +(`partialTraceRight_conj_map_rankOne_eq_sum_krausOp`) form. Prepare the ancilla in the fixed pure +state `|ω⟩`, conjugate the ancilla-extended input `ρ ⊗ |ω⟩⟨ω|` by a joint map +`W : Hin ⊗ Anc →ₗ Eout ⊗ Fdisc`, then measure the environment block projector +`P_S = ∑_{σ∈S} embedRight b σ ∘ₗ restrictRight b σ` (`= 1 ⊗ ∑_{σ∈S} |b σ⟩⟨b σ|`) and discard +`Fdisc`; this returns the operator sum over exactly the *selected* operation elements +`Eₖ = krausOp b (W ∘ₗ tmulRightVec ω)`: +`partialTraceRight b (P_S (W (ρ ⊗ |ω⟩⟨ω|) W†) P_S) = ∑_{σ∈S} E_σ ρ E_σ†`. No hypothesis on `W`/`ω`. +Folds the ancilla conjugation into the dilation `V = W ∘ₗ tmulRightVec ω` +(`map_rankOne_eq_conj_tmulRightVec`), then applies the projected dilation lemma +`partialTraceRight_conj_sum_proj_eq_sum_krausOp`. This is the tool behind Exercise 8.9's +measurement model: "perform `U` on `ρ ⊗ |e₀⟩⟨e₀|`, then measure the environment projector `Pₘ`". -/ +theorem partialTraceRight_conj_sum_proj_map_rankOne_eq_sum_krausOp + (b : OrthonormalBasis ι 𝕜 Fdisc) (W : (Hin ⊗[𝕜] Anc) →ₗ[𝕜] Eout ⊗[𝕜] Fdisc) + (ω : Anc) (ρ : Hin →ₗ[𝕜] Hin) (S : Finset ι) : + partialTraceRight b + ((∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ) ∘ₗ + (W ∘ₗ TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 ω ω).toLinearMap ∘ₗ adjoint W) ∘ₗ + (∑ σ ∈ S, embedRight b σ ∘ₗ restrictRight b σ)) + = ∑ σ ∈ S, krausOp b (W ∘ₗ tmulRightVec ω) σ ∘ₗ ρ ∘ₗ + adjoint (krausOp b (W ∘ₗ tmulRightVec ω) σ) := by + have hmix : + W ∘ₗ TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 ω ω).toLinearMap ∘ₗ adjoint W + = (W ∘ₗ tmulRightVec ω) ∘ₗ ρ ∘ₗ adjoint (W ∘ₗ tmulRightVec ω) := by + rw [map_rankOne_eq_conj_tmulRightVec, adjoint_comp] + simp only [comp_assoc] + rw [hmix, partialTraceRight_conj_sum_proj_eq_sum_krausOp] + +/-- **Operator-sum representation of the environment model for a mixed environment state** +(Nielsen–Chuang Eqs. (8.33)–(8.35)). The mixed generalization of +`partialTraceRight_conj_map_rankOne_eq_sum_krausOp`: when the environment carries a positive +operator written as a finite sum of rank-one terms `∑ⱼ |wⱼ⟩⟨wⱼ|` (an ensemble decomposition of the +density operator, with the weights `√qⱼ` absorbed into the `wⱼ`), discarding `Fdisc` from the +conjugation of `ρ ⊗ (∑ⱼ |wⱼ⟩⟨wⱼ|)` by a joint map `W : Hin ⊗ Anc →ₗ Eout ⊗ Fdisc` returns the double +operator sum over the operation elements `Eⱼₖ = krausOp b (W ∘ₗ tmulRightVec (wⱼ))`: +`partialTraceRight b (W (map ρ (∑ⱼ |wⱼ⟩⟨wⱼ|)) W†) = ∑ⱼ ∑ₖ Eⱼₖ ρ Eⱼₖ†`. No hypothesis on `W` or the +`wⱼ`. Distributes the sum through `TensorProduct.map`, the outer conjugation, and the (linear) +partial trace, then applies the pure-state case termwise. -/ +theorem partialTraceRight_conj_map_sum_rankOne_eq_sum_krausOp {κ : Type*} [Fintype κ] + (b : OrthonormalBasis ι 𝕜 Fdisc) (W : (Hin ⊗[𝕜] Anc) →ₗ[𝕜] Eout ⊗[𝕜] Fdisc) + (w : κ → Anc) (ρ : Hin →ₗ[𝕜] Hin) : + partialTraceRight b + (W ∘ₗ TensorProduct.map ρ (∑ j, (InnerProductSpace.rankOne 𝕜 (w j) (w j)).toLinearMap) + ∘ₗ adjoint W) + = ∑ j, ∑ k, krausOp b (W ∘ₗ tmulRightVec (w j)) k ∘ₗ ρ + ∘ₗ adjoint (krausOp b (W ∘ₗ tmulRightVec (w j)) k) := by + rw [← partialTraceRightLM_apply] + have hcomp : W ∘ₗ TensorProduct.map ρ (∑ j, (InnerProductSpace.rankOne 𝕜 (w j) (w j)).toLinearMap) + ∘ₗ adjoint W + = ∑ j, (W ∘ₗ TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 (w j) (w j)).toLinearMap + ∘ₗ adjoint W) := by + have hmap : TensorProduct.map ρ (∑ j, (InnerProductSpace.rankOne 𝕜 (w j) (w j)).toLinearMap) + = ∑ j, TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 (w j) (w j)).toLinearMap := by + simp only [← TensorProduct.mapBilinear_apply, map_sum] + rw [hmap] + ext x + simp [LinearMap.sum_apply, map_sum] + rw [hcomp, map_sum] + simp only [partialTraceRightLM_apply, partialTraceRight_conj_map_rankOne_eq_sum_krausOp] + +/-- **Completeness relation for the environment model** (Nielsen–Chuang Eq. (8.14)). When the joint +map `W` is an isometry (`W† ∘ₗ W = 1`) and the environment state `ω` is a unit vector, the operation +elements `Eₖ = krausOp b (W ∘ₗ tmulRightVec ω)` satisfy `∑ₖ Eₖ† Eₖ = 1`, so the environment-model +map `ρ ↦ partialTraceRight b (W (ρ ⊗ |ω⟩⟨ω|) W†)` is trace preserving. The dilation +`V = W ∘ₗ tmulRightVec ω` is an isometry (a composition of the isometries `W` and `tmulRightVec ω`), +whence `sum_adjoint_krausOp_comp_krausOp`. -/ +theorem sum_adjoint_krausOp_tmulRightVec_comp_krausOp + (b : OrthonormalBasis ι 𝕜 Fdisc) (W : (Hin ⊗[𝕜] Anc) →ₗ[𝕜] Eout ⊗[𝕜] Fdisc) + {ω : Anc} (hW : adjoint W ∘ₗ W = LinearMap.id) (hω : ‖ω‖ = 1) : + ∑ k, adjoint (krausOp b (W ∘ₗ tmulRightVec ω) k) ∘ₗ krausOp b (W ∘ₗ tmulRightVec ω) k + = LinearMap.id := by + refine sum_adjoint_krausOp_comp_krausOp b _ ?_ + have h : adjoint (W ∘ₗ tmulRightVec ω) ∘ₗ (W ∘ₗ tmulRightVec ω) + = adjoint (tmulRightVec ω) ∘ₗ (adjoint W ∘ₗ W) ∘ₗ tmulRightVec ω := by + rw [adjoint_comp]; simp only [comp_assoc] + rw [h, hW, id_comp, adjoint_tmulRightVec_comp_self hω] + +end EnvironmentModel + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumCP.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumCP.lean new file mode 100644 index 0000000000..baa2a462e3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumCP.lean @@ -0,0 +1,293 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import Mathlib.LinearAlgebra.Contraction +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +-- `TensorProduct` is re-imported LAST on purpose: it re-asserts the inner-product-space +-- normed structure on `E ⊗[𝕜] F` as the resolution-priority `AddCommMonoid`/`Module` instance +-- over the bare algebraic `TensorProduct.instModule`. Without this, a tensor operator built with +-- `homTensorHomEquiv`/`TensorProduct.map` (algebraic module) fails to unify with the normed module +-- that `ContinuousLinearMap`/`LinearMap.IsPositive` require, even though the two are defeq. +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Complete positivity and the forward direction of the operator-sum theorem + +The **ampliation** of a superoperator `Φ` (a linear map on operators) by a reference space `R` is +the map `id_{B(R)} ⊗ Φ` acting on operators of `R ⊗ H`, characterised by +`(id_{B(R)} ⊗ Φ)(B ⊗ M) = B ⊗ Φ(M)`. A superoperator is **completely positive** when every such +ampliation preserves positivity — Nielsen–Chuang's axiom **A3** (*Quantum Computation and Quantum +Information*, §8.2.4). This file introduces the ampliation and complete positivity for operators on +finite-dimensional inner product spaces, packages the three N&C axioms into +`SatisfiesOperationAxioms`, and proves the **forward direction of the operator-sum representation +theorem (N&C Theorem 8.1)**: an operator-sum (Kraus) map `krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` with +`Σᵢ Eᵢ† Eᵢ ≤ 1` satisfies axioms A1, A2, A3. + +## Main definitions + +* `ContinuousLinearMap.superopAmpliationₗ R Φ` — the **ampliation** `id_{B(R)} ⊗ Φ` of a + `LinearMap`-superoperator `Φ : (H →ₗ[𝕜] H) →ₗ[𝕜] (G →ₗ[𝕜] G)`, built from `homTensorHomEquiv` + and `LinearMap.lTensor`. Its defining property is `superopAmpliationₗ_map`. (The `ₗ` subscript + marks the bundled-`LinearMap` form, matching `krausSumₗ`.) +* `ContinuousLinearMap.toLMSuperop Φ` — a `ContinuousLinearMap`-superoperator + `Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)` reinterpreted on the underlying linear maps, so that its + ampliation and complete positivity are expressible. +* `ContinuousLinearMap.IsCompletelyPositive Φ` — **complete positivity** (N&C axiom A3): for every + finite-dimensional reference space `R`, the ampliation `id_{B(R)} ⊗ Φ` sends positive operators + on `R ⊗ H` to positive operators on `R ⊗ G`. +* `ContinuousLinearMap.IsTraceNonIncreasing Φ` — **axiom A1**: `re tr(Φ ρ) ≤ re tr ρ` for every + positive `ρ` (the scaling-invariant form of `tr[Φ ρ] ≤ 1` on states). +* `ContinuousLinearMap.SatisfiesOperationAxioms Φ` — the **three axioms A1, A2, A3** bundled: + completely positive and trace-non-increasing (A2 is subsumed by `Φ` being a linear map). +* `ContinuousLinearMap.IsOperatorSum E Φ` — `Φ` has the **operator-sum form** `Φ = krausSumₗ E` + with `Σᵢ Eᵢ† Eᵢ ≤ 1` (the right-hand side of Theorem 8.1). + +## Main results + +* `ContinuousLinearMap.superopAmpliationₗ_map` — the ampliation acts on product operators by + `(id_{B(R)} ⊗ Φ)(B ⊗ M) = B ⊗ Φ(M)`. +* `ContinuousLinearMap.superopAmpliationₗ_krausSumₗ` — the ampliation of the operator-sum map is the + finite sum of conjugations by the ampliated Kraus operators, + `(id_{B(R)} ⊗ krausSumₗ E)(A) = Σᵢ (1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†` (N&C eqs 8.51–8.53). +* `ContinuousLinearMap.krausSumₗ_isCompletelyPositive` — the operator-sum map `krausSumₗ E` is + completely positive (axiom A3). Each ampliated summand `(1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†` is positive for + positive `A` (`krausSumₗ_isPositive` on the ampliated Kraus operators `1_R ⊗ Eᵢ`), so the sum is + too. +* `ContinuousLinearMap.IsOperatorSum.satisfiesAxioms` — **N&C Theorem 8.1, forward direction + (`⇐`):** a superoperator with an operator-sum representation `IsOperatorSum E Φ` satisfies the + operation axioms `SatisfiesOperationAxioms Φ`, combining `krausSumₗ_isCompletelyPositive` (A3) and + `krausSumₗ_isTraceNonIncreasing` (A1, from `re_trace_krausSumₗ_le`). + +## Relation to `CompletelyPositiveMap` + +Mathlib already has complete positivity for C*-algebras — `CompletelyPositiveMap` / +`CompletelyPositiveMapClass`, defined by entrywise positivity of the `CStarMatrix (Fin k) (Fin k)` +(i.e. `M_k`) ampliations — and `H →L[ℂ] H` is a `CStarAlgebra` +(`instCStarAlgebraContinuousLinearMapComplexIdOfCompleteSpace`), so +`CompletelyPositiveMap (H →L[ℂ] H) (G →L[ℂ] G)` is type-applicable. `IsCompletelyPositive` here is +the *same notion* in a different encoding: the reference-Hilbert-space tensor ampliation +`id_{B(R)} ⊗ Φ` in place of the `M_k`-matrix ampliation. The tensor form is used deliberately — +(i) it is Nielsen–Chuang's axiom A3 verbatim (a reference system `R` of arbitrary dimension), and +(ii) the reverse direction of Theorem 8.1 forms the Choi operator `σ = (id_R ⊗ Φ)(|α⟩⟨α|)` on a +maximally entangled state, which lives in exactly this reference-tensor ampliation and not the +matrix one. A bridge `IsCompletelyPositive Φ ↔ CompletelyPositiveMapClass …` — the standard +equivalence of the two CP characterisations — is not formalised here; it is not needed +for Theorem 8.1. + +## Implementation notes + +The complete-positivity predicate quantifies over reference spaces `R : Type` (universe `0`). This +is not a weakening of N&C's "reference system of arbitrary dimension": complete positivity depends +only on the *dimension* of the reference, every finite dimension is realised by a space in `Type 0` +(e.g. `EuclideanSpace 𝕜 (Fin n)`), and positivity is preserved under isometric isomorphism. + +Positivity of operators on `R ⊗ G` is stated with `LinearMap.IsPositive` on the underlying linear +maps (equivalently `ContinuousLinearMap.IsPositive`, by `isPositive_toLinearMap_iff`). + +The general ampliation, its computation rule, and the complete-positivity predicate are stated over +a general `RCLike` field `𝕜`; the operator-sum results specialise to `ℂ` (inherited from +`krausSumₗ`). +-/ + +open scoped TensorProduct +open ContinuousLinearMap + +noncomputable section + +@[expose] public section + +namespace ContinuousLinearMap + +section General + +variable {𝕜 H G : Type*} [RCLike 𝕜] + [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [FiniteDimensional 𝕜 H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] [CompleteSpace G] + +/-- A **`ContinuousLinearMap`-superoperator** `Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)` reinterpreted as a +`LinearMap`-superoperator on the underlying linear maps, via the finite-dimensional identification +`LinearMap.toContinuousLinearMap`. This is the form on which the ampliation `superopAmpliationₗ` +(hence complete positivity) is stated. -/ +def toLMSuperop (Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)) : (H →ₗ[𝕜] H) →ₗ[𝕜] (G →ₗ[𝕜] G) := + (LinearMap.toContinuousLinearMap (𝕜 := 𝕜) (E := G)).symm.toLinearMap ∘ₗ Φ ∘ₗ + (LinearMap.toContinuousLinearMap (𝕜 := 𝕜) (E := H)).toLinearMap + +omit [CompleteSpace H] [CompleteSpace G] in +@[simp] +theorem toLMSuperop_apply (Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)) (M : H →ₗ[𝕜] H) : + toLMSuperop Φ M = (Φ (LinearMap.toContinuousLinearMap M) : G →ₗ[𝕜] G) := rfl + +/-- The **ampliation** `id_{B(R)} ⊗ Φ` of a `LinearMap`-superoperator `Φ` by a reference space `R`: +the linear map on operators sending `A : R ⊗ H →ₗ[𝕜] R ⊗ H` to the operator on `R ⊗ G` that applies +`Φ` to the `H`-factor while leaving the `R`-factor untouched. Built from the operator–tensor +identification `homTensorHomEquiv` and `LinearMap.lTensor`; its characterising action on product +operators is `superopAmpliationₗ_map`. The `ₗ` subscript marks the bundled-`LinearMap` form. -/ +def superopAmpliationₗ (R : Type*) [NormedAddCommGroup R] [InnerProductSpace 𝕜 R] + [FiniteDimensional 𝕜 R] + (Φ : (H →ₗ[𝕜] H) →ₗ[𝕜] (G →ₗ[𝕜] G)) : + (R ⊗[𝕜] H →ₗ[𝕜] R ⊗[𝕜] H) →ₗ[𝕜] (R ⊗[𝕜] G →ₗ[𝕜] R ⊗[𝕜] G) := + (homTensorHomEquiv 𝕜 R G R G).toLinearMap ∘ₗ + (LinearMap.lTensor (R →ₗ[𝕜] R) Φ) ∘ₗ + (homTensorHomEquiv 𝕜 R H R H).symm.toLinearMap + +omit [CompleteSpace H] [CompleteSpace G] in +/-- **The ampliation acts on product operators factor-wise:** `(id_{B(R)} ⊗ Φ)(B ⊗ M) = B ⊗ Φ(M)`. +This is the defining property that pins down `superopAmpliationₗ`. -/ +theorem superopAmpliationₗ_map (R : Type*) [NormedAddCommGroup R] [InnerProductSpace 𝕜 R] + [FiniteDimensional 𝕜 R] + (Φ : (H →ₗ[𝕜] H) →ₗ[𝕜] (G →ₗ[𝕜] G)) (B : R →ₗ[𝕜] R) (M : H →ₗ[𝕜] H) : + superopAmpliationₗ R Φ (TensorProduct.map B M) = TensorProduct.map B (Φ M) := by + have hrw : TensorProduct.map B M = homTensorHomEquiv 𝕜 R H R H (B ⊗ₜ[𝕜] M) := by + rw [homTensorHomEquiv_apply, TensorProduct.homTensorHomMap_apply] + simp only [superopAmpliationₗ, LinearMap.comp_apply, LinearEquiv.coe_coe] + rw [hrw, (homTensorHomEquiv 𝕜 R H R H).symm_apply_apply, LinearMap.lTensor_tmul, + homTensorHomEquiv_apply, TensorProduct.homTensorHomMap_apply] + +/-- **Complete positivity of a superoperator `Φ` (Nielsen–Chuang axiom A3).** For every +finite-dimensional reference space `R`, the ampliation `id_{B(R)} ⊗ Φ` sends positive +operators on `R ⊗ H` to positive operators on `R ⊗ G`. (The reference ranges over `Type 0`; see the +module implementation notes on why this captures "arbitrary dimension".) -/ +def IsCompletelyPositive (Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)) : Prop := + ∀ (R : Type) [NormedAddCommGroup R] [InnerProductSpace 𝕜 R] [FiniteDimensional 𝕜 R] + (A : R ⊗[𝕜] H →ₗ[𝕜] R ⊗[𝕜] H), A.IsPositive → + (superopAmpliationₗ R (toLMSuperop Φ) A).IsPositive + +/-- **Trace-non-increasing — Nielsen–Chuang axiom A1.** A superoperator `Φ` is +*trace-non-increasing* when `re tr(Φ ρ) ≤ re tr ρ` for every positive operator `ρ`. For a state +`ρ` (trace one), this reads `tr[Φ ρ] ≤ 1`; the scaling-invariant form over all positive `ρ` is +equivalent and is exactly N&C's requirement that `tr[E(ρ)]` be a probability, `0 ≤ tr[E(ρ)] ≤ 1` +(the lower bound `0 ≤ re tr(Φ ρ)` being a consequence of positivity, hence of axiom A3). The trace +is taken via the underlying `LinearMap`; positivity makes it real, so `RCLike.re` extracts its +value. -/ +def IsTraceNonIncreasing (Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)) : Prop := + ∀ ρ : H →L[𝕜] H, 0 ≤ ρ → + RCLike.re (LinearMap.trace 𝕜 G ((Φ ρ : G →L[𝕜] G) : G →ₗ[𝕜] G)) + ≤ RCLike.re (LinearMap.trace 𝕜 H ((ρ : H →L[𝕜] H) : H →ₗ[𝕜] H)) + +/-- **A quantum operation (the Nielsen–Chuang axioms A1, A2, A3).** A superoperator `Φ` satisfies +the operation axioms when it is completely positive (axiom A3, `IsCompletelyPositive`) and +trace-non-increasing (axiom A1, `IsTraceNonIncreasing`). Axiom A2 (convex-linearity on density +operators) is *subsumed by the type*: `Φ` is modelled as a genuine `𝕜`-linear map on operators, the +unique linear extension of a convex-linear map on density operators (which spans the operator +space), so linearity — hence convex-linearity — holds by construction. This bundled predicate is +the left-hand side of the operator-sum representation theorem (N&C Theorem 8.1). -/ +def SatisfiesOperationAxioms (Φ : (H →L[𝕜] H) →ₗ[𝕜] (G →L[𝕜] G)) : Prop := + IsCompletelyPositive Φ ∧ IsTraceNonIncreasing Φ + +end General + +section Complex + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +/-- **The ampliation of the operator-sum map is the sum of conjugations by the ampliated Kraus +operators** (N&C eqs 8.51–8.53). For the operator-sum map `krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†`, the +ampliation `id_{B(R)} ⊗ krausSumₗ E` applied to `A : R ⊗ H →ₗ[ℂ] R ⊗ H` equals +`Σᵢ (1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†`. Proved by reducing to product operators `B ⊗ M` (via +`homTensorHomEquiv` and `TensorProduct.induction_on`), where it follows from +`superopAmpliationₗ_map` and bilinearity of the tensor. -/ +theorem superopAmpliationₗ_krausSumₗ (R : Type*) [NormedAddCommGroup R] [InnerProductSpace ℂ R] + [FiniteDimensional ℂ R] {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) + (A : R ⊗[ℂ] H →ₗ[ℂ] R ⊗[ℂ] H) : + superopAmpliationₗ R (toLMSuperop (krausSumₗ E)) A + = ∑ i, (TensorProduct.map LinearMap.id (↑(E i) : H →ₗ[ℂ] G)) ∘ₗ A ∘ₗ + (TensorProduct.map LinearMap.id (↑(adjoint (E i)) : G →ₗ[ℂ] H)) := by + obtain ⟨X, rfl⟩ := (homTensorHomEquiv ℂ R H R H).surjective A + induction X using TensorProduct.inductionOn with + | tmul B M => + rw [homTensorHomEquiv_apply, TensorProduct.homTensorHomMap_apply, superopAmpliationₗ_map] + simp only [toLMSuperop_apply, krausSumₗ_apply, ContinuousLinearMap.toLinearMap_sum, + ] + rw [← TensorProduct.mapBilinear_apply, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [TensorProduct.mapBilinear_apply, ← TensorProduct.map_comp, ← TensorProduct.map_comp] + simp + | add X Y ihX ihY => + simp only [map_add, LinearMap.add_comp, LinearMap.comp_add, Finset.sum_add_distrib, ihX, ihY] + +/-- **The operator-sum (Kraus) map is completely positive** — Nielsen–Chuang Theorem 8.1, forward +direction (axiom A3). For any finite family `E : ι → (H →L[ℂ] G)`, the operator-sum map +`krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` is completely positive: for a positive operator `A` on `R ⊗ H`, the +ampliation `Σᵢ (1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†` is a finite sum of the positive operators +`(1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†` — the operator-sum map of the ampliated Kraus operators `1_R ⊗ Eᵢ` +applied to `A` — hence positive (`krausSumₗ_isPositive`). -/ +theorem krausSumₗ_isCompletelyPositive {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) : + IsCompletelyPositive (krausSumₗ E) := by + intro R _ _ _ A hA + have : CompleteSpace R := FiniteDimensional.completeSpace ℂ R + rw [superopAmpliationₗ_krausSumₗ] + -- Recast the ampliated sum `Σᵢ (1_R ⊗ Eᵢ) A (1_R ⊗ Eᵢ)†` as the operator-sum map of the + -- ampliated Kraus operators `1_R ⊗ Eᵢ` applied to `A`; positivity is `krausSumₗ_isPositive`. + have hadj1 : ContinuousLinearMap.adjoint (1 : R →L[ℂ] R) = 1 := by + rw [ContinuousLinearMap.one_def, ContinuousLinearMap.adjoint_id] + have key : (∑ i, TensorProduct.map LinearMap.id (↑(E i) : H →ₗ[ℂ] G) ∘ₗ A ∘ₗ + TensorProduct.map LinearMap.id (↑(adjoint (E i)) : G →ₗ[ℂ] H)) + = (krausSumₗ (fun i => TensorProduct.mapL (1 : R →L[ℂ] R) (E i)) + (LinearMap.toContinuousLinearMap A)).toLinearMap := by + rw [krausSumₗ_apply, ContinuousLinearMap.toLinearMap_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + have e1 : (TensorProduct.map LinearMap.id (↑(E i) : H →ₗ[ℂ] G)) + = (TensorProduct.mapL (1 : R →L[ℂ] R) (E i)).toLinearMap := by + rw [TensorProduct.toLinearMap_mapL, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id] + have e2 : (TensorProduct.map LinearMap.id (↑(adjoint (E i)) : G →ₗ[ℂ] H)) + = (ContinuousLinearMap.adjoint (TensorProduct.mapL (1 : R →L[ℂ] R) (E i))).toLinearMap := by + rw [TensorProduct.adjoint_mapL, hadj1, TensorProduct.toLinearMap_mapL, + ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id] + rw [e1, e2, ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + LinearMap.coe_toContinuousLinearMap] + rw [key] + refine (krausSumₗ_isPositive _ ?_).toLinearMap + rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, LinearMap.coe_toContinuousLinearMap] + exact hA + +/-- **An operator-sum (Kraus) representation of a superoperator `Φ`.** A family of operation +elements `E : ι → H →L[ℂ] G` represents `Φ` when `Φ` *is* the operator-sum map of `E`, +`Φ = krausSumₗ E` (i.e. `Φ ρ = Σᵢ Eᵢ ρ Eᵢ†` for all `ρ`), and the operation elements obey the trace +condition `Σᵢ Eᵢ† Eᵢ ≤ 1`. This is the right-hand side of the operator-sum representation theorem +(N&C Theorem 8.1): `Φ` satisfies the operation axioms iff some finite family `E` gives +`IsOperatorSum E Φ`. -/ +def IsOperatorSum {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) + (Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)) : Prop := + Φ = krausSumₗ E ∧ ∑ i, adjoint (E i) ∘L E i ≤ 1 + +/-- **The operator-sum map is trace-non-increasing (axiom A1)** under the trace condition +`Σᵢ Eᵢ† Eᵢ ≤ 1`. Immediate from `re_trace_krausSumₗ_le`. -/ +theorem krausSumₗ_isTraceNonIncreasing {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) + (hE : ∑ i, adjoint (E i) ∘L E i ≤ 1) : + IsTraceNonIncreasing (krausSumₗ E) := + fun _ hρ => re_trace_krausSumₗ_le E hρ hE + +/-- **The operator-sum map satisfies the operation axioms (N&C Theorem 8.1, forward direction).** +Under the trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`, the map `krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` is completely +positive (axiom A3, `krausSumₗ_isCompletelyPositive`) and trace-non-increasing (axiom A1, +`krausSumₗ_isTraceNonIncreasing`); axiom A2 holds as `krausSumₗ E` is a linear map. -/ +theorem krausSumₗ_satisfiesOperationAxioms {ι : Type*} [Fintype ι] (E : ι → H →L[ℂ] G) + (hE : ∑ i, adjoint (E i) ∘L E i ≤ 1) : + SatisfiesOperationAxioms (krausSumₗ E) := + ⟨krausSumₗ_isCompletelyPositive E, krausSumₗ_isTraceNonIncreasing E hE⟩ + +/-- **Theorem 8.1, forward direction (`⇐`): an operator-sum map is a quantum operation.** If a +superoperator `Φ` has an operator-sum representation `IsOperatorSum E Φ` — i.e. `Φ = krausSumₗ E` +with `Σᵢ Eᵢ† Eᵢ ≤ 1` — then `Φ` satisfies the operation axioms A1, A2, A3 +(`SatisfiesOperationAxioms`). Rewriting `Φ` as `krausSumₗ E`, this is +`krausSumₗ_satisfiesOperationAxioms`. -/ +theorem IsOperatorSum.satisfiesAxioms {ι : Type*} [Fintype ι] {E : ι → H →L[ℂ] G} + {Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)} (h : IsOperatorSum E Φ) : + SatisfiesOperationAxioms Φ := by + obtain ⟨hΦ, hE⟩ := h + rw [hΦ] + exact krausSumₗ_satisfiesOperationAxioms E hE + +end Complex + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoi.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoi.lean new file mode 100644 index 0000000000..a2285acc8e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoi.lean @@ -0,0 +1,240 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumCP +-- `TensorProduct` is re-imported LAST on purpose (mirroring `OperatorSumCP`): it re-asserts the +-- inner-product-space normed structure on `E ⊗[𝕜] F` as the resolution-priority module instance +-- over the bare algebraic one, so operators built with `TensorProduct.map`/`homTensorHomEquiv` +-- unify with the normed module that `rankOne`/`IsPositive` require. +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# The Choi operator and the recovery identity (reverse direction of Theorem 8.1) + +This file builds the **Choi–Jamiołkowski** construction used in the reverse direction of the +operator-sum representation theorem (Nielsen–Chuang Theorem 8.1, *Quantum Computation and Quantum +Information*, §8.2.4, Eqs. (8.54)–(8.59)): given a superoperator `Φ`, form the **Choi operator** +`σ = (id_R ⊗ Φ)(|α⟩⟨α|)` on a maximally entangled reference state `|α⟩`, and recover `Φ` on pure +states by contracting `σ` against the conjugate vector `|ψ_tilde⟩`. + +## Main definitions + +* `LinearMap.tmulLeftVec ω` — the **left-factor** vector embedding `g ↦ ω ⊗ g` (the left analogue of + `LinearMap.tmulRightVec`), used together with the pre-existing left-factor contraction + `TensorProduct.contractFst ω` (`x ⊗ g ↦ ⟪ω, x⟫ • g`, its adjoint) to sandwich an operator on + `H ⊗ G` against a fixed reference vector on the `H`-factor. +* `OrthonormalBasis.maxEntVec b` — the (unnormalized) **maximally entangled vector** + `|α⟩ = Σᵢ |i⟩ ⊗ |i⟩` for the basis `b`. +* `OrthonormalBasis.conjVec b ψ` — the **conjugate vector** `|ψ_tilde⟩ = Σⱼ conj(ψⱼ) |j⟩`, written + as + `Σⱼ ⟪ψ, b j⟫ • b j` (since `⟪ψ, b j⟫ = conj ⟪b j, ψ⟫ = conj(ψⱼ)`). +* `ContinuousLinearMap.choiOp b Φ` — the **Choi operator** `σ = (id_R ⊗ Φ)(|α⟩⟨α|)` on `H ⊗ G`, + with `R = H` and `|α⟩ = maxEntVec b`, via the ampliation `superopAmpliationₗ`. + +## Main results + +* `LinearMap.contractFst_comp_map_comp_tmulLeftVec` — the sandwich identity + `contractFst ω ∘ (B ⊗ N) ∘ tmulLeftVec ω = ⟪ω, B ω⟫ • N`, the computational core of the recovery. +* `ContinuousLinearMap.choiRecovery` — **the recovery identity** (N&C Eqs. (8.54)–(8.59)): + contracting `σ` against `|ψ_tilde⟩` on the reference factor recovers `Φ` on the pure state + `|ψ⟩⟨ψ|`, + `contractFst ψ_tilde ∘ σ ∘ tmulLeftVec ψ_tilde = Φ(|ψ⟩⟨ψ|)`. The rank-one tensor factorisation + it uses, + `|a ⊗ b⟩⟨c ⊗ d| = |a⟩⟨c| ⊗ |b⟩⟨d|`, is the pre-existing `InnerProductSpace.rankOne_tmul_tmul`. + +Positivity of the Choi operator when `Φ` is completely positive is not proved here: +`IsCompletelyPositive` quantifies its reference over `Type 0`, so instantiating it at `R = H` +(arbitrary universe) needs a universe transport. The recovery identity here is fully +universe-polymorphic. + +## Design notes + +The reference system `R` is taken to be the input space `H` itself (identified with it via the +basis `b`), so `σ` lives on `H ⊗ G` with the reference on the **left** factor — matching the +convention of `superopAmpliationₗ R Φ`, which ampliates on the left (`R ⊗ H → R ⊗ G`). This is why +the contraction uses the left-factor `TensorProduct.contractFst` and the embedding `tmulLeftVec`. + +`choiOp` is deliberately the Choi **operator** `σ` (not a curried sandwich `⟨v|σ|w⟩`): the PSD +decomposition of the reverse direction spectrally decomposes `σ` itself, so it must be a named +operator. The recovery identity is then stated as an explicit sandwich composition. +-/ + +open scoped TensorProduct InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +@[expose] public section + +namespace LinearMap + +section LeftVec + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + +/-- The **left-factor vector embedding**: tensoring on the left with a fixed vector `ω : E`, +`y ↦ ω ⊗ y`, as a linear map `F →ₗ E ⊗ F`. The left analogue of `LinearMap.tmulRightVec`; it +packages a fixed reference state `ω` on the left factor. Definitionally `TensorProduct.mk 𝕜 E F ω`; +its adjoint contraction is the pre-existing `TensorProduct.contractFst ω`. -/ +noncomputable def tmulLeftVec (ω : E) : F →ₗ[𝕜] E ⊗[𝕜] F := + TensorProduct.mk 𝕜 E F ω + +@[simp] +theorem tmulLeftVec_apply (ω : E) (y : F) : tmulLeftVec ω y = ω ⊗ₜ[𝕜] y := rfl + +/-- **Sandwiching a product operator between two left-factor vectors.** For `B` on `E`, `N` on `F`, +`contractFst ω' ∘ (B ⊗ N) ∘ tmulLeftVec ω = ⟪ω', B ω⟫ • N`: the left factor `B` is applied to `ω` +(the vector the right factor is embedded along by `tmulLeftVec`) and contracted against `ω'` (by the +pre-existing `TensorProduct.contractFst`) to the scalar `⟪ω', B ω⟫`, and the right factor `N` +survives. This is the computational heart of the recovery identity (used with `ω' = ω`). -/ +theorem contractFst_comp_map_comp_tmulLeftVec (ω' ω : E) (B : E →ₗ[𝕜] E) (N : F →ₗ[𝕜] F) : + TensorProduct.contractFst ω' ∘ₗ TensorProduct.map B N ∘ₗ tmulLeftVec ω = ⟪ω', B ω⟫_𝕜 • N := by + ext y + simp only [LinearMap.comp_apply, tmulLeftVec_apply, TensorProduct.map_tmul, + TensorProduct.contractFst_tmul, LinearMap.smul_apply] + +end LeftVec + +end LinearMap + +namespace OrthonormalBasis + +variable {𝕜 E : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {ι : Type*} [Fintype ι] + +/-- The (unnormalized) **maximally entangled vector** `|α⟩ = Σᵢ |i⟩ ⊗ |i⟩` of an orthonormal basis +`b`, an element of `E ⊗ E`. -/ +noncomputable def maxEntVec (b : OrthonormalBasis ι 𝕜 E) : E ⊗[𝕜] E := + ∑ i, b i ⊗ₜ[𝕜] b i + +/-- The **conjugate vector** `|ψ_tilde⟩ = Σⱼ conj(ψⱼ) |j⟩` of `ψ` relative to the basis `b`, +written as +`Σⱼ ⟪ψ, b j⟫ • b j` (using `⟪ψ, b j⟫ = conj ⟪b j, ψ⟫`). It is the vector whose coordinates are the +complex conjugates of those of `ψ`; `conjVec` is conjugate-linear in `ψ`. -/ +noncomputable def conjVec (b : OrthonormalBasis ι 𝕜 E) (ψ : E) : E := + ∑ j, ⟪ψ, b j⟫_𝕜 • b j + +omit [FiniteDimensional 𝕜 E] in +/-- `⟪ψ_tilde, b i⟫ = ⟪b i, ψ⟫`: the conjugate vector pairs with a basis ket to give the +(un-conjugated) +coordinate of `ψ`. -/ +theorem inner_conjVec_left (b : OrthonormalBasis ι 𝕜 E) (ψ : E) (i : ι) : + ⟪b.conjVec ψ, b i⟫_𝕜 = ⟪b i, ψ⟫_𝕜 := by + classical + simp only [conjVec, sum_inner, inner_smul_left] + rw [Finset.sum_eq_single i] + · rw [orthonormal_iff_ite.mp b.orthonormal] + simp [inner_conj_symm] + · intro j _ hj + rw [orthonormal_iff_ite.mp b.orthonormal] + simp [hj] + · intro h; exact absurd (Finset.mem_univ i) h + +omit [FiniteDimensional 𝕜 E] in +/-- `⟪b i, ψ_tilde⟩ = ⟪ψ, b i⟫`: the conjugate vector paired on the right with a basis ket. -/ +theorem inner_conjVec_right (b : OrthonormalBasis ι 𝕜 E) (ψ : E) (i : ι) : + ⟪b i, b.conjVec ψ⟫_𝕜 = ⟪ψ, b i⟫_𝕜 := by + classical + simp only [conjVec, inner_sum, inner_smul_right] + rw [Finset.sum_eq_single i] + · rw [orthonormal_iff_ite.mp b.orthonormal] + simp + · intro j _ hj + rw [orthonormal_iff_ite.mp b.orthonormal] + simp [Ne.symm hj] + · intro h; exact absurd (Finset.mem_univ i) h + +end OrthonormalBasis + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + {ι : Type*} [Fintype ι] + +/-- The **Choi operator** `σ = (id_R ⊗ Φ)(|α⟩⟨α|)` of a superoperator +`Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)`, with reference `R = H` and the maximally entangled input +`|α⟩ = maxEntVec b`. An operator on `H ⊗ G`, built via the ampliation `superopAmpliationₗ`. -/ +noncomputable def choiOp (b : OrthonormalBasis ι ℂ H) (Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)) : + (H ⊗[ℂ] G) →ₗ[ℂ] (H ⊗[ℂ] G) := + superopAmpliationₗ H (toLMSuperop Φ) + ((rankOne ℂ b.maxEntVec b.maxEntVec : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) : + (H ⊗[ℂ] H) →ₗ[ℂ] (H ⊗[ℂ] H)) + +omit [CompleteSpace G] in +/-- **The recovery identity** (Nielsen–Chuang Eqs. (8.54)–(8.59)). Contracting the Choi operator +`σ = choiOp b Φ` against the conjugate vector `|ψ_tilde⟩` on the reference (left) factor recovers +`Φ` on +the pure state `|ψ⟩⟨ψ|`: +`contractFst ψ_tilde ∘ σ ∘ tmulLeftVec ψ_tilde = Φ(|ψ⟩⟨ψ|)`. +The proof expands `|α⟩⟨α| = Σᵢⱼ |i⟩⟨j| ⊗ |i⟩⟨j|` over the basis (`rankOne_tmul_tmul`), pushes it +through the ampliation (`superopAmpliationₗ_map`, giving `Σᵢⱼ |i⟩⟨j| ⊗ Φ(|i⟩⟨j|)`), and contracts +each product summand (`contractFst_comp_map_comp_tmulLeftVec`), producing +`Σᵢⱼ ⟪ψ, b j⟫ ⟪b i, ψ⟫ • Φ(|i⟩⟨j|) = Φ(Σᵢⱼ ⟪b i, ψ⟫ conj⟪b j, ψ⟫ • |i⟩⟨j|) = Φ(|ψ⟩⟨ψ|)`. -/ +theorem choiRecovery (b : OrthonormalBasis ι ℂ H) (Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)) (ψ : H) : + TensorProduct.contractFst (b.conjVec ψ) ∘ₗ choiOp b Φ ∘ₗ LinearMap.tmulLeftVec (b.conjVec ψ) + = (Φ (rankOne ℂ ψ ψ) : G →ₗ[ℂ] G) := by + -- Sandwiching the ampliation of a *product* operator `M ⊗ N` (N&C 8.51–8.53 at one term). + have key : ∀ M N : H →ₗ[ℂ] H, + TensorProduct.contractFst (b.conjVec ψ) ∘ₗ + superopAmpliationₗ H (toLMSuperop Φ) (TensorProduct.map M N) ∘ₗ + LinearMap.tmulLeftVec (b.conjVec ψ) + = ⟪b.conjVec ψ, M (b.conjVec ψ)⟫_ℂ • + (↑(Φ (LinearMap.toContinuousLinearMap N)) : G →ₗ[ℂ] G) := by + intro M N + rw [superopAmpliationₗ_map, LinearMap.contractFst_comp_map_comp_tmulLeftVec, + toLMSuperop_apply] + -- The sandwich distributes over a double sum of ampliated operators (linearity of everything). + have sand : ∀ X : ι → ι → ((H ⊗[ℂ] H) →ₗ[ℂ] (H ⊗[ℂ] H)), + TensorProduct.contractFst (b.conjVec ψ) ∘ₗ + superopAmpliationₗ H (toLMSuperop Φ) (∑ i, ∑ j, X i j) ∘ₗ + LinearMap.tmulLeftVec (b.conjVec ψ) + = ∑ i, ∑ j, TensorProduct.contractFst (b.conjVec ψ) ∘ₗ + superopAmpliationₗ H (toLMSuperop Φ) (X i j) ∘ₗ + LinearMap.tmulLeftVec (b.conjVec ψ) := by + intro X + ext g + simp only [LinearMap.comp_apply, map_sum, LinearMap.sum_apply] + -- Expand `|α⟩⟨α|` over the basis into a double sum of product rank-one operators. + have hα : ((rankOne ℂ b.maxEntVec b.maxEntVec : (H ⊗[ℂ] H) →L[ℂ] (H ⊗[ℂ] H)) : + (H ⊗[ℂ] H) →ₗ[ℂ] (H ⊗[ℂ] H)) + = ∑ i, ∑ j, TensorProduct.map (↑(rankOne ℂ (b i) (b j)) : H →ₗ[ℂ] H) + (↑(rankOne ℂ (b i) (b j)) : H →ₗ[ℂ] H) := by + rw [OrthonormalBasis.maxEntVec] + simp only [map_sum, _root_.sum_apply, rankOne_tmul_tmul, + ContinuousLinearMap.toLinearMap_sum, TensorProduct.toLinearMap_mapL] + rw [Finset.sum_comm] + -- Expand `|ψ⟩⟨ψ|` over the basis with the matching coefficients `⟪ψ_tilde, |i⟩⟨j| ψ_tilde⟫`. + have hψ : rankOne ℂ ψ ψ = ∑ i, ∑ j, + (⟪b.conjVec ψ, (↑(rankOne ℂ (b i) (b j)) : H →ₗ[ℂ] H) (b.conjVec ψ)⟫_ℂ) • + rankOne ℂ (b i) (b j) := by + have e : ψ = ∑ i, ⟪b i, ψ⟫_ℂ • b i := by + conv_lhs => rw [← b.sum_repr ψ] + simp only [OrthonormalBasis.repr_apply_apply] + conv_lhs => rw [e] + simp only [map_sum, _root_.sum_apply, map_smul, _root_.smul_apply, + map_smulₛₗ, Finset.smul_sum, smul_smul] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => ?_ + congr 1 + rw [ContinuousLinearMap.coe_coe, rankOne_apply, inner_smul_right, + OrthonormalBasis.inner_conjVec_right, OrthonormalBasis.inner_conjVec_left, inner_conj_symm, + mul_comm] + rw [choiOp, hα, sand] + simp only [key, toLinearMap_toContinuousLinearMap] + rw [hψ] + simp only [map_sum, map_smul, ContinuousLinearMap.toLinearMap_sum, + ContinuousLinearMap.toLinearMap_smul] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiKraus.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiKraus.lean new file mode 100644 index 0000000000..cd9e40e67c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiKraus.lean @@ -0,0 +1,240 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiPositive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum +-- `TensorProduct` is re-imported LAST on purpose (mirroring `OperatorSumChoiPositive`): it +-- re-asserts the inner-product-space normed structure on `E ⊗[𝕜] F` as the resolution-priority +-- module instance over the bare algebraic one, so operators built with `TensorProduct.map`, +-- `rankOne` and `contractFst` unify with the normed module the positivity / decomposition API uses. +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Kraus operators from the Choi decomposition (reverse direction of Theorem 8.1) + +This file performs the third and central step of the reverse direction of the operator-sum +representation theorem (Nielsen–Chuang Theorem 8.1, *Quantum Computation and Quantum Information*, +§8.2.4, Eqs. (8.60)–(8.64)). Its two predecessors have established, for a **completely positive** +superoperator `Φ`, the Choi operator `σ = choiOp b Φ` together with + +* the **recovery identity** `contractFst ψ_tilde ∘ σ ∘ tmulLeftVec ψ_tilde = Φ(|ψ⟩⟨ψ|)` + (`ContinuousLinearMap.choiRecovery`), and +* **positivity** `σ ≥ 0` (`ContinuousLinearMap.choiOp_isPositive`). + +Positivity lets us decompose `σ = Σᵢ |sᵢ⟩⟨sᵢ|` into rank-one self-projectors (N&C Eq. (8.60), +`ContinuousLinearMap.IsPositive.exists_sum_rankOne_fin_finrank`). Feeding this decomposition through +the recovery identity reads off a finite family of **operation elements** `Eᵢ : H →L[ℂ] G` with +`Φ(|ψ⟩⟨ψ|) = Σᵢ Eᵢ |ψ⟩⟨ψ| Eᵢ†` on every pure state (N&C Eqs. (8.61)–(8.64)) — the operator-sum +representation of `Φ` on the pure states, which the assembly of the reverse direction then extends +to all operators by convex-linearity. + +## Main definitions + +* `LinearMap.adjoint_tmulLeftVec` — the adjoint of the left-factor embedding `tmulLeftVec ω` + (`g ↦ ω ⊗ g`) is the left-factor contraction `contractFst ω` (`x ⊗ y ↦ ⟪ω, x⟫ • y`); mirrors + `LinearMap.adjoint_tmulRightVec`. +* `ContinuousLinearMap.krausOfChoi b s` — the **operation element read off a Choi vector** + `s ∈ H ⊗ G` and orthonormal basis `b` of `H`: `Eₛ ψ = ⟨ψ_tilde|s⟩` (N&C Eq. (8.60)), the + contraction of + `s` against the conjugate vector `ψ_tilde` on the reference (`H`) factor. Packaged as the + manifestly + `ℂ`-linear sum `∑ⱼ |contractFst (bⱼ) s⟩⟨bⱼ|`. + +## Main results + +* `ContinuousLinearMap.krausOfChoi_apply` — `krausOfChoi b s ψ = contractFst ψ_tilde s`, + connecting the + bundled definition to N&C's `⟨ψ_tilde|s⟩`. +* `ContinuousLinearMap.contractFst_rankOne_comp_tmulLeftVec` — sandwiching a rank-one projector + `|s⟩⟨s|` between `contractFst ω` and `tmulLeftVec ω` contracts it to the rank-one projector + `|contractFst ω s⟩⟨contractFst ω s|` on the surviving factor. +* `ContinuousLinearMap.IsCompletelyPositive.exists_krausSumₗ_apply_rankOne` — **the main result** + (N&C Eqs. (8.60)–(8.64)): a completely positive `Φ` admits a finite family of operation elements + `E : Fin (d²) → (H →L[ℂ] G)` (with `d² = finrank ℂ (H ⊗ G)`) such that + `Φ(|ψ⟩⟨ψ|) = krausSumₗ E (|ψ⟩⟨ψ|)` for every pure state `|ψ⟩` — the operator-sum representation of + `Φ` on the pure states. +-/ + +open scoped TensorProduct InnerProductSpace ComplexConjugate +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +@[expose] public section + +namespace LinearMap + +section AdjointLeftVec + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- **Adjoint of the left-factor embedding** is the left-factor contraction: +`(tmulLeftVec ω)† = contractFst ω`. The left analogue of `LinearMap.adjoint_tmulRightVec`; proved +by the inner-product characterization on pure tensors, `⟪ω ⊗ y, a ⊗ b⟫ = ⟪⟪ω, a⟫ • y, b⟫`. -/ +theorem adjoint_tmulLeftVec (ω : E) : + adjoint (tmulLeftVec ω : F →ₗ[𝕜] E ⊗[𝕜] F) = TensorProduct.contractFst ω := by + rw [eq_comm, LinearMap.eq_adjoint_iff] + intro v u + induction v using TensorProduct.inductionOn with + | tmul x y => + simp [tmulLeftVec_apply, TensorProduct.contractFst_tmul, TensorProduct.inner_tmul, + inner_smul_left] + | add a b ha hb => + simp [inner_add_left, map_add, ha, hb] + +end AdjointLeftVec + +end LinearMap + +namespace TensorProduct + +section ContractSumSmul + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + {κ : Type*} [Fintype κ] + +/-- **Conjugate-linearity of the left-factor contraction in its reference vector.** Contracting `s` +against a linear combination `∑ₖ cₖ • vₖ` on the left factor scales each term by the *conjugate* +`conj cₖ`: `contractFst (∑ₖ cₖ • vₖ) s = ∑ₖ conj cₖ • contractFst (vₖ) s`. (The contraction pairs +the reference with the left factor via `⟪·, ·⟫`, conjugate-linear in the first slot.) -/ +theorem contractFst_sum_smul_left (c : κ → 𝕜) (v : κ → E) (s : E ⊗[𝕜] F) : + contractFst (∑ k, c k • v k) s = ∑ k, conj (c k) • contractFst (v k) s := by + induction s using TensorProduct.inductionOn with + | tmul x y => + simp only [contractFst_tmul, sum_inner, inner_smul_left, Finset.sum_smul, smul_smul] + | add a b ha hb => simp [map_add, ha, hb, Finset.sum_add_distrib] + +end ContractSumSmul + +end TensorProduct + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + {ι : Type*} [Fintype ι] + +/-- **The operation element read off a Choi vector `s`** relative to an orthonormal basis `b` of the +input space `H`. Nielsen–Chuang Eq. (8.60) defines it by `Eₛ|ψ⟩ = ⟨ψ_tilde|s⟩`, where `ψ_tilde` is +the +conjugate vector of `ψ` and `⟨ψ_tilde|` contracts the reference (`H`) factor of `s ∈ H ⊗ G`, +leaving a +vector of `G`. We package it as `∑ⱼ |contractFst (bⱼ) s⟩⟨bⱼ|`, a finite sum of rank-one operators, +so that it is **manifestly `ℂ`-linear and continuous**; `krausOfChoi_apply` recovers the +`⟨ψ_tilde|s⟩` +action. -/ +noncomputable def krausOfChoi (b : OrthonormalBasis ι ℂ H) (s : H ⊗[ℂ] G) : H →L[ℂ] G := + ∑ j, rankOne ℂ (TensorProduct.contractFst (b j) s) (b j) + +omit [FiniteDimensional ℂ H] [CompleteSpace H] [FiniteDimensional ℂ G] [CompleteSpace G] in +/-- The operation element `krausOfChoi b s` acts by contracting `s` against the conjugate vector +`ψ_tilde` on the reference factor: `krausOfChoi b s ψ = contractFst ψ_tilde s` (Nielsen–Chuang's +`⟨ψ_tilde|s⟩`, Eq. +(8.60)). Both sides expand to `∑ⱼ ⟪bⱼ, ψ⟫ • contractFst (bⱼ) s`, the rank-one sum directly and the +contraction via conjugate-linearity of `contractFst` in its reference +(`contractFst_sum_smul_left`, using `conj ⟪ψ, bⱼ⟫ = ⟪bⱼ, ψ⟫`). -/ +theorem krausOfChoi_apply (b : OrthonormalBasis ι ℂ H) (s : H ⊗[ℂ] G) (ψ : H) : + krausOfChoi b s ψ = TensorProduct.contractFst (b.conjVec ψ) s := by + rw [krausOfChoi, _root_.sum_apply, OrthonormalBasis.conjVec, + TensorProduct.contractFst_sum_smul_left] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [rankOne_apply, inner_conj_symm] + +omit [CompleteSpace H] [CompleteSpace G] in +/-- **Sandwiching a rank-one projector by a fixed left-factor reference `ω`.** Between the embedding +`tmulLeftVec ω` and the contraction `contractFst ω`, the rank-one projector `|s⟩⟨s|` on `H ⊗ G` +contracts to the rank-one projector `|contractFst ω s⟩⟨contractFst ω s|` on the surviving factor +`G`: `contractFst ω ∘ |s⟩⟨s| ∘ tmulLeftVec ω = |contractFst ω s⟩⟨contractFst ω s|`. The scalar +bookkeeping is the adjoint relation `⟪contractFst ω s, g⟫ = ⟪s, ω ⊗ g⟫` (`adjoint_tmulLeftVec`). +This is the per-term step that turns the Choi decomposition `σ = Σᵢ |sᵢ⟩⟨sᵢ|` into the operator +sum. -/ +theorem contractFst_rankOne_comp_tmulLeftVec (ω : H) (s : H ⊗[ℂ] G) : + TensorProduct.contractFst ω ∘ₗ (↑(rankOne ℂ s s) : (H ⊗[ℂ] G) →ₗ[ℂ] (H ⊗[ℂ] G)) ∘ₗ + LinearMap.tmulLeftVec ω + = (↑(rankOne ℂ (TensorProduct.contractFst ω s) (TensorProduct.contractFst ω s)) + : G →ₗ[ℂ] G) := by + have inner_key : ∀ g : G, + ⟪TensorProduct.contractFst ω s, g⟫_ℂ = ⟪s, ω ⊗ₜ[ℂ] g⟫_ℂ := by + intro g + rw [← LinearMap.adjoint_tmulLeftVec ω, LinearMap.adjoint_inner_left, + LinearMap.tmulLeftVec_apply] + ext g + simp only [LinearMap.comp_apply, LinearMap.tmulLeftVec_apply, ContinuousLinearMap.coe_coe, + rankOne_apply, map_smul] + rw [inner_key] + +omit [FiniteDimensional ℂ H] [FiniteDimensional ℂ G] in +/-- **Conjugating a rank-one self-projector by an operator.** For `f : H →L[ℂ] G`, +`f ∘ |ψ⟩⟨ψ| ∘ f† = |f ψ⟩⟨f ψ|` — the single-summand operator-sum action. This is the composition +of `comp_rankOne`, `rankOne_comp` and `adjoint_adjoint`. -/ +theorem comp_rankOne_self_comp_adjoint (f : H →L[ℂ] G) (ψ : H) : + f ∘L rankOne ℂ ψ ψ ∘L adjoint f = rankOne ℂ (f ψ) (f ψ) := by + simp only [rankOne_comp, comp_rankOne, adjoint_adjoint] + +/-- **Operator-sum representation of a completely positive map on the pure states** (Nielsen–Chuang +Theorem 8.1, reverse direction, Eqs. (8.60)–(8.64)). A completely positive superoperator `Φ` admits +a finite family of operation elements `E : Fin (finrank ℂ (H ⊗ G)) → (H →L[ℂ] G)` — at most `d²` +of them, `d = dim H` (for `G = H`) — with `Φ(|ψ⟩⟨ψ|) = krausSumₗ E (|ψ⟩⟨ψ|) = Σᵢ Eᵢ |ψ⟩⟨ψ| Eᵢ†` +on every pure state `|ψ⟩`. + +The elements are read off the Choi operator `σ = choiOp b Φ`: `σ` is positive +(`choiOp_isPositive`), hence decomposes as `σ = Σᵢ |uᵢ⟩⟨uᵢ|` +(`IsPositive.exists_sum_rankOne_fin_finrank`), and `Eᵢ` is the Choi vector `uᵢ` read off by +`krausOfChoi b uᵢ`. Feeding the decomposition through the recovery identity (`choiRecovery`) and +contracting each rank-one term (`contractFst_rankOne_comp_tmulLeftVec`) matches, summand by summand, +the operator sum `krausSumₗ E (|ψ⟩⟨ψ|)` (`comp_rankOne_self_comp_adjoint`). The extension to all +operators by convex-linearity, and the trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`, are not proved here. -/ +theorem IsCompletelyPositive.exists_krausSumₗ_apply_rankOne (b : OrthonormalBasis ι ℂ H) + {Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)} (hΦ : IsCompletelyPositive Φ) : + ∃ E : Fin (Module.finrank ℂ (H ⊗[ℂ] G)) → (H →L[ℂ] G), + ∀ ψ : H, Φ (rankOne ℂ ψ ψ) = krausSumₗ E (rankOne ℂ ψ ψ) := by + -- The Choi operator `σ = choiOp b Φ` is positive; bridge to a CLM and decompose it. + have hpos : (choiOp b Φ).IsPositive := choiOp_isPositive b hΦ + have hposC : (LinearMap.toContinuousLinearMap (choiOp b Φ)).IsPositive := by + rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, LinearMap.coe_toContinuousLinearMap] + exact hpos + obtain ⟨u, hu⟩ := hposC.exists_sum_rankOne_fin_finrank + -- `σ = Σᵢ |uᵢ⟩⟨uᵢ|` as a linear map (N&C Eq. (8.60)). + have hσ : (choiOp b Φ) + = ∑ i, (↑(rankOne ℂ (u i) (u i)) : (H ⊗[ℂ] G) →ₗ[ℂ] (H ⊗[ℂ] G)) := by + rw [← LinearMap.coe_toContinuousLinearMap (choiOp b Φ), hu, ContinuousLinearMap.toLinearMap_sum] + refine ⟨fun i => krausOfChoi b (u i), fun ψ => ?_⟩ + apply ContinuousLinearMap.coe_injective + -- The operator sum, summand by summand: `Eᵢ |ψ⟩⟨ψ| Eᵢ† = |Eᵢ ψ⟩⟨Eᵢ ψ|`. + have rhs_eq : + (↑(krausSumₗ (fun i => krausOfChoi b (u i)) (rankOne ℂ ψ ψ)) : G →ₗ[ℂ] G) + = ∑ i, (↑(rankOne ℂ (krausOfChoi b (u i) ψ) (krausOfChoi b (u i) ψ)) + : G →ₗ[ℂ] G) := by + rw [krausSumₗ_apply, ContinuousLinearMap.toLinearMap_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [comp_rankOne_self_comp_adjoint] + -- The recovery side: distribute the Choi decomposition through `contractFst · ∘ tmulLeftVec ·`. + have lhs_eq : (Φ (rankOne ℂ ψ ψ) : G →ₗ[ℂ] G) + = ∑ i, (↑(rankOne ℂ (krausOfChoi b (u i) ψ) (krausOfChoi b (u i) ψ)) + : G →ₗ[ℂ] G) := by + have dist : TensorProduct.contractFst (b.conjVec ψ) ∘ₗ choiOp b Φ ∘ₗ + LinearMap.tmulLeftVec (b.conjVec ψ) + = ∑ i, (TensorProduct.contractFst (b.conjVec ψ) ∘ₗ + (↑(rankOne ℂ (u i) (u i)) : (H ⊗[ℂ] G) →ₗ[ℂ] (H ⊗[ℂ] G)) ∘ₗ + LinearMap.tmulLeftVec (b.conjVec ψ)) := by + rw [hσ] + ext g + simp only [LinearMap.comp_apply, LinearMap.sum_apply, map_sum] + rw [← choiRecovery b Φ ψ, dist] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [contractFst_rankOne_comp_tmulLeftVec, krausOfChoi_apply] + exact lhs_eq.trans rhs_eq.symm + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiPositive.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiPositive.lean new file mode 100644 index 0000000000..7b8386b4ca --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumChoiPositive.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoi +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.TensorProduct.Map +-- `TensorProduct` is re-imported LAST on purpose (mirroring `OperatorSumChoi`/`OperatorSumCP`): it +-- re-asserts the inner-product-space normed structure on `E ⊗[𝕜] F` as the resolution-priority +-- module instance over the bare algebraic one, so operators built with `TensorProduct.map` unify +-- with the normed module that `LinearMap.IsPositive`/`rankOne`/`rTensor` require. +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Positivity of the Choi operator (reverse direction of Theorem 8.1) + +Building on `ToMathlib.Analysis.InnerProductSpace.OperatorSumChoi`, the **Choi operator** +`σ = choiOp b Φ` of a **completely positive** superoperator `Φ` is a *positive* operator, `σ ≥ 0` +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, §8.2.4, Eq. (8.60)). This is the +input to the spectral (PSD) decomposition `σ = Σᵢ |sᵢ⟩⟨sᵢ|` from which the operation elements of the +reverse direction of Theorem 8.1 are read off. + +## The universe obstacle, and how it is resolved + +Complete positivity (`ContinuousLinearMap.IsCompletelyPositive`) quantifies its reference system +`R` over `Type` (universe `0`) — this is not a weakening, since complete positivity depends only on +the reference's *dimension* and every finite dimension is realised in `Type 0`. But the Choi +operator `σ = (id_H ⊗ Φ)(|α⟩⟨α|)` is built with the reference taken to be the input space `H` +itself (via `choiOp`), which lives in an arbitrary universe. Concluding `σ ≥ 0` directly from +`IsCompletelyPositive Φ` therefore needs a **universe transport**: transfer positivity of the +ampliation with reference `H` to positivity of the ampliation with reference +`R₀ = EuclideanSpace ℂ (Fin (dim H))` (a `Type 0` space isometric to `H`), where complete positivity +applies. + +The transport rests on the **naturality of the ampliation in its reference**: for a linear isometry +`e : H ≃ₗᵢ R`, conjugating `superopAmpliationₗ H Φ` by the reference-factor isometry +`rTensor _ e = e ⊗ id` equals `superopAmpliationₗ R Φ` of the conjugated argument. On product +operators `B ⊗ C` this is immediate from `superopAmpliationₗ_map` (the reference factor `B` is +carried through untouched by `Φ`, so conjugating it by `e` on both sides agrees — the underlying +purely-algebraic fact `LinearEquiv.rTensor_comp_map_comp_symm`); the general case follows by +linearity. + +## Main results + +* `ContinuousLinearMap.superopAmpliationₗ_conj_rTensor` — **naturality of the ampliation in its + reference**: `superopAmpliationₗ R Φ (rTensor H e · rTensor H e⁻¹) = + rTensor G e · (superopAmpliationₗ H Φ ·) · rTensor G e⁻¹`. +* `ContinuousLinearMap.IsCompletelyPositive.superopAmpliationₗ_isPositive` — the **universe + transport**: a completely positive `Φ` has *every* ampliation + `superopAmpliationₗ H (toLMSuperop Φ)` (reference `H` of arbitrary universe) + positivity-preserving, not merely the `Type 0` references of `IsCompletelyPositive`. +* `ContinuousLinearMap.choiOp_isPositive` — **the Choi operator of a completely positive map is + positive** (N&C Eq. (8.60)): `σ = choiOp b Φ ≥ 0`, since `σ` is the ampliation of the positive + operator `|α⟩⟨α|` (`isPositive_rankOne_self`). + +Everything here is general finite-dimensional complex Hilbert-space operator mathematics. +-/ + +open scoped TensorProduct InnerProductSpace +open ContinuousLinearMap + +noncomputable section + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +omit [CompleteSpace H] [CompleteSpace G] in +/-- **Naturality of the ampliation in its reference system.** For a linear isometry +`e : H ≃ₗᵢ R` between (finite-dimensional) reference spaces, conjugating the ampliation +`superopAmpliationₗ H Φ` by the reference-factor isometry `rTensor _ e` equals the ampliation +`superopAmpliationₗ R Φ` of the conjugated argument: +`superopAmpliationₗ R Φ (rTensor H e ∘ A ∘ (rTensor H e)⁻¹) + = rTensor G e ∘ superopAmpliationₗ H Φ A ∘ (rTensor G e)⁻¹`. +Reducing `A` to product operators `B ⊗ C` (via `homTensorHomEquiv` surjectivity), each side becomes +`(e B e⁻¹) ⊗ Φ C` by `superopAmpliationₗ_map` and the general algebraic conjugation lemma +`LinearEquiv.rTensor_comp_map_comp_symm` (after normalising the isometry `rTensor` to the underlying +`LinearEquiv.rTensor` via `LinearIsometryEquiv.toLinearEquiv_rTensor`). -/ +theorem superopAmpliationₗ_conj_rTensor {R : Type*} [NormedAddCommGroup R] [InnerProductSpace ℂ R] + [FiniteDimensional ℂ R] (e : H ≃ₗᵢ[ℂ] R) (Φ : (H →ₗ[ℂ] H) →ₗ[ℂ] (G →ₗ[ℂ] G)) + (A : H ⊗[ℂ] H →ₗ[ℂ] H ⊗[ℂ] H) : + superopAmpliationₗ R Φ + ((↑(LinearIsometryEquiv.rTensor H e).toLinearEquiv : H ⊗[ℂ] H →ₗ[ℂ] R ⊗[ℂ] H) ∘ₗ A ∘ₗ + (↑(LinearIsometryEquiv.rTensor H e).symm.toLinearEquiv : R ⊗[ℂ] H →ₗ[ℂ] H ⊗[ℂ] H)) + = (↑(LinearIsometryEquiv.rTensor G e).toLinearEquiv : H ⊗[ℂ] G →ₗ[ℂ] R ⊗[ℂ] G) ∘ₗ + superopAmpliationₗ H Φ A ∘ₗ + (↑(LinearIsometryEquiv.rTensor G e).symm.toLinearEquiv : R ⊗[ℂ] G →ₗ[ℂ] H ⊗[ℂ] G) := by + obtain ⟨X, rfl⟩ := (homTensorHomEquiv ℂ H H H H).surjective A + induction X using TensorProduct.inductionOn with + | tmul B C => + -- Normalise the isometry reference factor `rTensor _ e` to the underlying + -- `LinearEquiv.rTensor` of `e.toLinearEquiv`, so the general algebraic + -- `LinearEquiv.rTensor_comp_map_comp_symm` applies. + rw [homTensorHomEquiv_apply, TensorProduct.homTensorHomMap_apply] + simp only [LinearIsometryEquiv.toLinearEquiv_symm, LinearIsometryEquiv.toLinearEquiv_rTensor] + rw [LinearEquiv.rTensor_comp_map_comp_symm, superopAmpliationₗ_map, superopAmpliationₗ_map, + LinearEquiv.rTensor_comp_map_comp_symm] + | add X Y ihX ihY => + simp only [map_add, LinearMap.comp_add, LinearMap.add_comp, ihX, ihY] + +omit [CompleteSpace H] [CompleteSpace G] in +/-- **Universe transport of complete positivity to an arbitrary-universe reference.** A completely +positive superoperator `Φ` has *every* reference ampliation `superopAmpliationₗ H (toLMSuperop Φ)` +positivity-preserving — including the reference `H` itself, which need not live in `Type 0`. The +`IsCompletelyPositive` predicate only asserts this for references `R : Type 0`; we transport along +the linear isometry `e : H ≃ₗᵢ EuclideanSpace ℂ (Fin (dim H))` to a `Type 0` reference, using the +reference naturality `superopAmpliationₗ_conj_rTensor` and invariance of positivity under isometric +conjugation (`isPositive_linearIsometryEquiv_conj_iff`). -/ +theorem IsCompletelyPositive.superopAmpliationₗ_isPositive + {Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)} (hΦ : IsCompletelyPositive Φ) + {A : H ⊗[ℂ] H →ₗ[ℂ] H ⊗[ℂ] H} (hA : A.IsPositive) : + (superopAmpliationₗ H (toLMSuperop Φ) A).IsPositive := by + set e : H ≃ₗᵢ[ℂ] EuclideanSpace ℂ (Fin (Module.finrank ℂ H)) := (stdOrthonormalBasis ℂ H).repr + with he + -- Transport `A ≥ 0` to a positive operator on the `Type 0` reference `R₀ ⊗ H`. + have hA' : ((↑(LinearIsometryEquiv.rTensor H e).toLinearEquiv : + H ⊗[ℂ] H →ₗ[ℂ] EuclideanSpace ℂ (Fin (Module.finrank ℂ H)) ⊗[ℂ] H) ∘ₗ A ∘ₗ + (↑(LinearIsometryEquiv.rTensor H e).symm.toLinearEquiv : + EuclideanSpace ℂ (Fin (Module.finrank ℂ H)) ⊗[ℂ] H →ₗ[ℂ] H ⊗[ℂ] H)).IsPositive := + (LinearMap.isPositive_linearIsometryEquiv_conj_iff (LinearIsometryEquiv.rTensor H e)).mpr hA + -- Complete positivity applies at the `Type 0` reference `R₀ = EuclideanSpace ℂ (Fin (dim H))`. + have hCP := hΦ (EuclideanSpace ℂ (Fin (Module.finrank ℂ H))) _ hA' + rw [superopAmpliationₗ_conj_rTensor] at hCP + exact (LinearMap.isPositive_linearIsometryEquiv_conj_iff (LinearIsometryEquiv.rTensor G e)).mp hCP + +omit [CompleteSpace H] [CompleteSpace G] in +/-- **The Choi operator of a completely positive map is positive** (Nielsen–Chuang Eq. (8.60)). For +a completely positive superoperator `Φ`, the Choi operator `σ = choiOp b Φ = (id_H ⊗ Φ)(|α⟩⟨α|)` is +a positive operator on `H ⊗ G`. Indeed `σ` is the ampliation (reference `H`) of the maximally +entangled projector `|α⟩⟨α|`, which is positive (`isPositive_rankOne_self`); positivity of the +ampliation is `IsCompletelyPositive.superopAmpliationₗ_isPositive`. This `σ ≥ 0` is the input to the +PSD decomposition `σ = Σᵢ |sᵢ⟩⟨sᵢ|` of the reverse direction of Theorem 8.1. -/ +theorem choiOp_isPositive {ι : Type*} [Fintype ι] (b : OrthonormalBasis ι ℂ H) + {Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)} (hΦ : IsCompletelyPositive Φ) : + (choiOp b Φ).IsPositive := by + rw [choiOp] + refine hΦ.superopAmpliationₗ_isPositive ?_ + rw [ContinuousLinearMap.isPositive_toLinearMap_iff] + exact InnerProductSpace.isPositive_rankOne_self b.maxEntVec + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumComposition.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumComposition.lean new file mode 100644 index 0000000000..4b69eeded8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumComposition.lean @@ -0,0 +1,187 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumCP + +/-! +# Composition of operator-sum (Kraus) maps — Nielsen–Chuang Exercise 8.6 + +The **composition** of two quantum operations is again a quantum operation. Concretely, if `E` +has operator-sum (Kraus) representation `E(ρ) = Σᵢ Eᵢ ρ Eᵢ†` and `F` has representation +`F(σ) = Σⱼ Fⱼ σ Fⱼ†`, then the composite `(F ∘ E)(ρ) = Σⱼ Σᵢ Fⱼ Eᵢ ρ Eᵢ† Fⱼ†` is itself an +operator-sum map, with operation elements the products `{Fⱼ Eᵢ}`. This is Nielsen–Chuang +*Quantum Computation and Quantum Information*, **Exercise 8.6** (§8.2, p. 362). + +The input and output spaces need not agree: `E` maps operators on `H` to operators on `G`, `F` +maps operators on `G` to operators on `K`, and the composite maps operators on `H` to operators on +`K`, with operation elements `Fⱼ Eᵢ : H →L[ℂ] K`. This is the space-changing extension the exercise +asks for; the "same quantum system" case is the specialisation `H = G = K`. + +## Main results + +* `ContinuousLinearMap.krausSumₗ_comp` — the composite of two operator-sum maps is the operator-sum + map of the product family: `(krausSumₗ F).comp (krausSumₗ E) = krausSumₗ (fun (j, i) ↦ Fⱼ ∘ Eᵢ)`. +* `ContinuousLinearMap.sum_adjoint_comp_comp_le_one` — the composite family inherits the trace + condition: if `Σᵢ Eᵢ† Eᵢ ≤ 1` and `Σⱼ Fⱼ† Fⱼ ≤ 1` then `Σ_{j,i} (Fⱼ Eᵢ)† (Fⱼ Eᵢ) ≤ 1`. +* `ContinuousLinearMap.IsOperatorSum.comp` — **Exercise 8.6:** if `Φ` and `Ψ` have operator-sum + representations (`IsOperatorSum E Φ`, `IsOperatorSum F Ψ`) then the composite `Ψ ∘ Φ` has the + operator-sum representation given by the product family `{Fⱼ Eᵢ}`. +* `ContinuousLinearMap.IsOperatorSum.comp_satisfiesAxioms` — the composite is therefore a quantum + operation: `SatisfiesOperationAxioms (Ψ ∘ Φ)` (via the forward direction of N&C Theorem 8.1, + `IsOperatorSum.satisfiesAxioms`). + +## Design notes + +The algebraic identity `krausSumₗ_comp` reindexes the double sum by the product type `κ × ι`, so the +composite operation elements are literally `fun p : κ × ι => (F p.1).comp (E p.2)`; the reindexing +freedom of the representation (`krausSumₗ_comp_equiv`) means any bijection with `κ × ι` gives the +same map, so this choice of index is immaterial. The trace-condition inheritance factors the double +sum as `Σᵢ Eᵢ† (Σⱼ Fⱼ† Fⱼ) Eᵢ` and bounds the inner conjugation by monotonicity of `X ↦ Eᵢ† X Eᵢ` +in the Loewner order (from `IsPositive.conj_adjoint`): with `B := Σⱼ Fⱼ† Fⱼ ≤ 1`, each summand is +`≤ Eᵢ† Eᵢ`, so the total is `≤ Σᵢ Eᵢ† Eᵢ ≤ 1`. + +This mirrors the algebraic level of Nielsen–Chuang §8.2 (Theorems 8.1–8.3), whose formal content is +operator/Hilbert-space linear algebra over `H →L[ℂ] G`; compare `OperatorSum.lean` (Theorem 8.2) +and `MinimalOperatorSum.lean` (Theorem 8.3). The statement of Exercise 8.6 is in +[upstream `AxQM/NC/Ch8/Exercise8_6.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch8/Exercise8_6.lean). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §8.2 (Exercise 8.6). +-/ + +@[expose] public section + +namespace ContinuousLinearMap + +section + +variable {H G K : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [CompleteSpace G] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] [CompleteSpace K] + {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- **The composite of two operator-sum (Kraus) maps is the operator-sum map of the product family** +(Nielsen–Chuang Exercise 8.6). For families `E : ι → (H →L[ℂ] G)` and `F : κ → (G →L[ℂ] K)`, the +composition of the operator-sum maps `krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` and `krausSumₗ F : σ ↦ Σⱼ Fⱼ σ +Fⱼ†` equals the single operator-sum map of the product family `(j, i) ↦ Fⱼ ∘ Eᵢ`: +`(krausSumₗ F) ∘ (krausSumₗ E) = krausSumₗ (fun p : κ × ι => Fₚ₁ ∘ Eₚ₂)`. +Expanding the composition gives `Σⱼ Σᵢ Fⱼ (Eᵢ ρ Eᵢ†) Fⱼ†`, and `adjoint (Fⱼ ∘ Eᵢ) = Eᵢ† ∘ Fⱼ†` with +associativity recasts each summand as `(Fⱼ Eᵢ) ρ (Fⱼ Eᵢ)†`; reindexing the double sum by `κ × ι` +completes the identity. -/ +theorem krausSumₗ_comp (E : ι → H →L[ℂ] G) (F : κ → G →L[ℂ] K) : + (krausSumₗ F).comp (krausSumₗ E) + = krausSumₗ (fun p : κ × ι => (F p.1).comp (E p.2)) := by + refine LinearMap.ext fun ρ => ?_ + rw [LinearMap.comp_apply, krausSumₗ_apply E, map_sum] + rw [krausSumₗ_apply, Fintype.sum_prod_type, Finset.sum_comm] + refine Finset.sum_congr rfl fun j _ => Finset.sum_congr rfl fun i _ => ?_ + simp only [adjoint_comp, comp_assoc] + +/-- **Factorization of the composite-family completeness sum** (Nielsen–Chuang Exercise 8.6). For +families `E : ι → (H →L[ℂ] G)` and `F : κ → (G →L[ℂ] K)`, the completeness sum of the product family +`(j, i) ↦ Fⱼ ∘ Eᵢ` reassociates as `Σ_{j,i} (Fⱼ Eᵢ)† (Fⱼ Eᵢ) = Σᵢ Eᵢ† (Σⱼ Fⱼ† Fⱼ) Eᵢ`: summing over +`κ` first and using `adjoint (Fⱼ Eᵢ) = Eᵢ† Fⱼ†` with associativity pulls the inner block `Σⱼ Fⱼ† Fⱼ` +between `Eᵢ†` and `Eᵢ`. This is the shared algebraic core of both the `≤ 1` and `= 1` composite +trace conditions (`sum_adjoint_comp_comp_le_one`, `sum_adjoint_comp_comp_eq_one`). -/ +theorem sum_adjoint_comp_comp_eq_sum (E : ι → H →L[ℂ] G) (F : κ → G →L[ℂ] K) : + ∑ p : κ × ι, adjoint ((F p.1).comp (E p.2)) ∘L (F p.1).comp (E p.2) + = ∑ i, adjoint (E i) ∘L (∑ j, adjoint (F j) ∘L F j) ∘L E i := by + rw [Fintype.sum_prod_type, Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [finsetSum_comp, comp_finsetSum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [adjoint_comp] + simp only [comp_assoc] + +/-- **The product family inherits the operator-sum trace condition** (Nielsen–Chuang Exercise 8.6). +If `Σᵢ Eᵢ† Eᵢ ≤ 1` and `Σⱼ Fⱼ† Fⱼ ≤ 1`, then the product family `(j, i) ↦ Fⱼ ∘ Eᵢ` satisfies +`Σ_{j,i} (Fⱼ Eᵢ)† (Fⱼ Eᵢ) ≤ 1`. Factoring the double sum as `Σᵢ Eᵢ† (Σⱼ Fⱼ† Fⱼ) Eᵢ` +(`sum_adjoint_comp_comp_eq_sum`) and writing `B := Σⱼ Fⱼ† Fⱼ`, monotonicity of `X ↦ Eᵢ† X Eᵢ` in the +Loewner order (`IsPositive.conj_adjoint` applied to `1 - B ≥ 0`) bounds each summand by `Eᵢ† Eᵢ`, so +the total is `≤ Σᵢ Eᵢ† Eᵢ ≤ 1`. This is the trace condition for the composite quantum operation. -/ +theorem sum_adjoint_comp_comp_le_one (E : ι → H →L[ℂ] G) (F : κ → G →L[ℂ] K) + (hE : ∑ i, adjoint (E i) ∘L E i ≤ 1) (hF : ∑ j, adjoint (F j) ∘L F j ≤ 1) : + ∑ p : κ × ι, adjoint ((F p.1).comp (E p.2)) ∘L (F p.1).comp (E p.2) ≤ 1 := by + rw [sum_adjoint_comp_comp_eq_sum] + set B := ∑ j, adjoint (F j) ∘L F j + refine le_trans (Finset.sum_le_sum fun i _ => ?_) hE + -- `Eᵢ† B Eᵢ ≤ Eᵢ† Eᵢ`, since `B ≤ 1` and conjugation is Loewner-monotone. + have hp := nonneg_iff_isPositive.mp (sub_nonneg.mpr hF) + have hcj := hp.conj_adjoint (adjoint (E i)) + rw [adjoint_adjoint] at hcj + have h2 := nonneg_iff_isPositive.mpr hcj + have hexp : adjoint (E i) ∘L (1 - B) ∘L E i + = adjoint (E i) ∘L E i - adjoint (E i) ∘L B ∘L E i := by + rw [sub_comp, comp_sub, one_def, id_comp] + rw [hexp] at h2 + exact sub_nonneg.mp h2 + +/-- **The product family inherits operator-sum trace-preservation** — the equality (exact, +trace-preserving) companion of `sum_adjoint_comp_comp_le_one` (Nielsen–Chuang Exercise 8.6). If +`Σᵢ Eᵢ† Eᵢ = 1` and `Σⱼ Fⱼ† Fⱼ = 1`, then the product family `(j, i) ↦ Fⱼ ∘ Eᵢ` is trace-preserving: +`Σ_{j,i} (Fⱼ Eᵢ)† (Fⱼ Eᵢ) = 1`. Factoring the double sum as `Σᵢ Eᵢ† (Σⱼ Fⱼ† Fⱼ) Eᵢ` and +substituting `Σⱼ Fⱼ† Fⱼ = 1` collapses each summand to `Eᵢ† Eᵢ`, summing to `1` by the `E` +hypothesis. This is the trace-preservation of the composite `Ψ ∘ Φ` of two trace-preserving +operations, used in Nielsen & Chuang's converse to Theorem 12.6 (Eq. (12.58)). -/ +theorem sum_adjoint_comp_comp_eq_one (E : ι → H →L[ℂ] G) (F : κ → G →L[ℂ] K) + (hE : ∑ i, adjoint (E i) ∘L E i = 1) (hF : ∑ j, adjoint (F j) ∘L F j = 1) : + ∑ p : κ × ι, adjoint ((F p.1).comp (E p.2)) ∘L (F p.1).comp (E p.2) = 1 := by + rw [sum_adjoint_comp_comp_eq_sum, hF] + simp only [one_def, id_comp] + exact hE + +/-- **The composition of quantum operations is a quantum operation** (Nielsen–Chuang, *Quantum +Computation and Quantum Information*, **Exercise 8.6**). If superoperators `Φ` and `Ψ` have +operator-sum (Kraus) representations — `IsOperatorSum E Φ` (i.e. `Φ = krausSumₗ E` with +`Σᵢ Eᵢ† Eᵢ ≤ 1`) and `IsOperatorSum F Ψ` — then their composite `Ψ ∘ Φ` has the operator-sum +representation given by the product family `(j, i) ↦ Fⱼ ∘ Eᵢ`, `IsOperatorSum (fun p ↦ Fₚ₁ ∘ Eₚ₂) +(Ψ ∘ Φ)`. The map equality is `krausSumₗ_comp` and the trace condition is +`sum_adjoint_comp_comp_le_one`. + +The spaces need not coincide (`E : ι → H →L[ℂ] G`, `F : κ → G →L[ℂ] K`), so this is the +space-changing extension the exercise asks for, with the "same quantum system" case the +specialisation `H = G = K`. -/ +theorem IsOperatorSum.comp {E : ι → H →L[ℂ] G} {F : κ → G →L[ℂ] K} + {Φ : (H →L[ℂ] H) →ₗ[ℂ] G →L[ℂ] G} {Ψ : (G →L[ℂ] G) →ₗ[ℂ] K →L[ℂ] K} + (hE : IsOperatorSum E Φ) (hF : IsOperatorSum F Ψ) : + IsOperatorSum (fun p : κ × ι => (F p.1).comp (E p.2)) (Ψ.comp Φ) := by + obtain ⟨hΦ, hEcond⟩ := hE + obtain ⟨hΨ, hFcond⟩ := hF + refine ⟨?_, sum_adjoint_comp_comp_le_one E F hEcond hFcond⟩ + rw [hΦ, hΨ, krausSumₗ_comp] + +end + +section + +variable {H G K : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [CompleteSpace G] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] [FiniteDimensional ℂ K] [CompleteSpace K] + {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- **The composite of two quantum operations satisfies the operation axioms** (Nielsen–Chuang +Exercise 8.6, together with Theorem 8.1). If `Φ` and `Ψ` have operator-sum representations, then the +composite `Ψ ∘ Φ` satisfies the Nielsen–Chuang quantum-operation axioms A1, A2, A3 +(`SatisfiesOperationAxioms`): the composite has an operator-sum representation +(`IsOperatorSum.comp`) and any operator-sum map is a quantum operation +(`IsOperatorSum.satisfiesAxioms`, the forward direction of Theorem 8.1). -/ +theorem IsOperatorSum.comp_satisfiesAxioms {E : ι → H →L[ℂ] G} {F : κ → G →L[ℂ] K} + {Φ : (H →L[ℂ] H) →ₗ[ℂ] G →L[ℂ] G} {Ψ : (G →L[ℂ] G) →ₗ[ℂ] K →L[ℂ] K} + (hE : IsOperatorSum E Φ) (hF : IsOperatorSum F Ψ) : + SatisfiesOperationAxioms (Ψ.comp Φ) := + (hE.comp hF).satisfiesAxioms + +end + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumDilation.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumDilation.lean new file mode 100644 index 0000000000..28020f4fe9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumDilation.lean @@ -0,0 +1,281 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UnitaryExtension + +/-! +# The converse system–environment construction: a unitary dilation from a Kraus family + +The file `OperatorSum.lean` builds the **forward** system–environment story: from a dilation +`V : Hin →ₗ E ⊗ F` (physically, a joint unitary acting on the principal system tensored with an +environment prepared in a fixed pure state), tracing out the environment factor `F` produces the +operator sum `ρ ↦ Σₖ Eₖ ρ Eₖ†` with operation elements `Eₖ = krausOp b V k` (Nielsen–Chuang +Eqs. (8.9)–(8.10)), and the elements are complete (`Σₖ Eₖ† Eₖ = 1`) exactly when `V` is an +isometry (Eq. (8.14)). + +This file supplies the **converse** — Nielsen–Chuang §8.2, "System–environment models for any +operator-sum representation" (Eqs. (8.36)–(8.41)): **given** a finite family of operation elements +`E : ι → Hin →ₗ Eout`, assemble the dilation +`V |ψ⟩ = Σₖ Eₖ |ψ⟩ ⊗ |eₖ⟩` (Eq. (8.37)) +whose operation elements *are* the `Eₖ`, so `ρ ↦ tr_F(V ρ V†)` realises the operator sum, and — when +the family is **complete** (`Σₖ Eₖ† Eₖ = 1`) — `V` is an isometry that **extends to a unitary** `U` +on the joint space with `U(ψ ⊗ ω) = V ψ` (Eq. (8.36)). This is the construction N&C uses to show +that *any* operator-sum representation arises from a reasonable environmental model, and the +starting point for Exercise 8.8 (its non-trace-preserving extension) and Exercise 8.9 (its +measurement-model extension). + +## Main definitions and results + +* `LinearMap.krausDilation b E` — the dilation `V = Σₖ embedRight b k ∘ₗ Eₖ`, i.e. + `V ψ = Σₖ Eₖ ψ ⊗ b k` (Eq. (8.37)). +* `LinearMap.krausOp_krausDilation` — the assembled dilation has the prescribed operation elements: + `krausOp b (krausDilation b E) k = Eₖ` (Eq. (8.41), the block-column reading of `U`). +* `LinearMap.adjoint_krausDilation_comp_self` — `V† V = Σₖ Eₖ† Eₖ`; hence `V` is an isometry **iff** + the family is complete (`Σₖ Eₖ† Eₖ = 1`, Eq. (8.38)). +* `LinearMap.partialTraceRight_krausDilation_conj` — the operator-sum recovery (Eq. (8.39)): + `tr_F(V ρ V†) = Σₖ Eₖ ρ Eₖ†`. +* `LinearMap.exists_unitary_krausDilation` — **the unitary (Eq. (8.36))**: for a complete family and + a unit environment state `ω`, there is a unitary `U : (H ⊗ F) ≃ₗᵢ (H ⊗ F)` with + `U (ψ ⊗ ω) = krausDilation b E ψ`, obtained by extending the isometry `V` (N&C Exercise 2.67, + `LinearMap.unitaryExtend`). +* `LinearMap.partialTraceRight_conj_tmulRightVec_krausDilation` — the model realises the operation: + `tr_F(U (ρ ⊗ |ω⟩⟨ω|) U†) = Σₖ Eₖ ρ Eₖ†`. + +## Design notes + +The construction is stated at the `LinearMap` (`→ₗ`) level, matching the existing `krausOp` dilation +API (`OperatorSum.lean`): `krausOp_krausDilation` is then the exact inverse of the forward theorem +`sum_adjoint_krausOp_comp_krausOp`, and the recovery `partialTraceRight_krausDilation_conj` is a +one-line corollary of `partialTraceRight_conj_eq_sum_krausOp` composed with it. The dilation and its +Kraus-recovery keep the input space `Hin` and output space `Eout` distinct (as `krausOp` does), so +the algebra is reusable for space-changing operations; the *unitary* results specialise to the +physical square case `Hin = Eout = H`, since a unitary on the joint space acts on one space `H ⊗ F` +and its input `ψ ⊗ ω` must live there too. + +The unitary is produced by `LinearMap.unitaryExtend` (N&C Exercise 2.67): the isometry `V` +restricted to the subspace `{ψ ⊗ ω}` of `H ⊗ F` is inner-product preserving, and any such map on a +subspace of +a finite-dimensional space extends to a unitary of the whole space. The determination of `U` off the +`ψ ⊗ ω` subspace is exactly the "the rest of the block matrix is our choice" freedom of N&C's +Box 8.1. + +Like the rest of §8.2's operator-sum development, the content is operator/Hilbert-space linear +algebra over `H →ₗ[𝕜] G`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §8.2 (System–environment models; Box 8.1; Exercises 8.8, 8.9). +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace LinearMap + +section KrausDilation + +variable {𝕜 Hin Eout F : Type*} [RCLike 𝕜] + [NormedAddCommGroup Hin] [InnerProductSpace 𝕜 Hin] [FiniteDimensional 𝕜 Hin] + [NormedAddCommGroup Eout] [InnerProductSpace 𝕜 Eout] [FiniteDimensional 𝕜 Eout] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- The **dilation assembled from a Kraus family** `E : ι → Hin →ₗ Eout` relative to an orthonormal +basis `b` of the environment factor `F`: `V = Σₖ embedRight b k ∘ₗ Eₖ`, that is +`V ψ = Σₖ Eₖ ψ ⊗ b k` (Nielsen–Chuang Eq. (8.37)). This is the map whose operation elements +(`krausOp`) are exactly the `Eₖ` (`krausOp_krausDilation`). -/ +noncomputable def krausDilation (b : OrthonormalBasis ι 𝕜 F) (E : ι → Hin →ₗ[𝕜] Eout) : + Hin →ₗ[𝕜] Eout ⊗[𝕜] F := + ∑ k, embedRight b k ∘ₗ E k + +omit [FiniteDimensional 𝕜 Hin] [FiniteDimensional 𝕜 Eout] [FiniteDimensional 𝕜 F] in +/-- The assembled dilation acts by `V ψ = Σₖ Eₖ ψ ⊗ b k` (Nielsen–Chuang Eq. (8.37)). -/ +theorem krausDilation_apply (b : OrthonormalBasis ι 𝕜 F) (E : ι → Hin →ₗ[𝕜] Eout) (x : Hin) : + krausDilation b E x = ∑ k, E k x ⊗ₜ[𝕜] b k := by + simp only [krausDilation, LinearMap.sum_apply, LinearMap.comp_apply, embedRight_apply] + +omit [FiniteDimensional 𝕜 Hin] [FiniteDimensional 𝕜 Eout] [FiniteDimensional 𝕜 F] in +/-- **The assembled dilation recovers the operation elements** (Nielsen–Chuang Eq. (8.41)): the +`k`-th Kraus operator of `krausDilation b E` is `Eₖ`. By delta-orthogonality of the embed/restrict +maps (`restrictRight_comp_embedRight`), contracting `V = Σⱼ embedRight b j ∘ₗ Eⱼ` against `b k` +keeps only the `j = k` term. -/ +theorem krausOp_krausDilation (b : OrthonormalBasis ι 𝕜 F) (E : ι → Hin →ₗ[𝕜] Eout) (k : ι) : + krausOp b (krausDilation b E) k = E k := by + classical + ext x + simp only [krausOp, LinearMap.comp_apply, krausDilation, LinearMap.sum_apply, map_sum, + embedRight_apply, restrictRight_tmul, b.inner_eq_ite] + rw [Finset.sum_eq_single k] + · simp + · intro j _ hjk + rw [ite_eq_right (Ne.symm hjk), zero_smul] + · intro h; exact absurd (Finset.mem_univ k) h + +/-- The adjoint of the assembled dilation: `V† = Σₖ Eₖ† ∘ₗ restrictRight b k`. Distributes the +adjoint over the sum and uses `adjoint_embedRight` (`(embedRight b k)† = restrictRight b k`). -/ +theorem adjoint_krausDilation (b : OrthonormalBasis ι 𝕜 F) (E : ι → Hin →ₗ[𝕜] Eout) : + adjoint (krausDilation b E) = ∑ k, adjoint (E k) ∘ₗ restrictRight b k := by + rw [krausDilation, map_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [adjoint_comp, adjoint_embedRight] + +/-- **General Kraus identity**: for *any* dilation `V`, +`Σₖ (krausOp b V k)† (krausOp b V k) = V† V`. +Writing `Eₖ† Eₖ = V† ∘ₗ (embedRight b k ∘ₗ restrictRight b k) ∘ₗ V` and summing, the resolution of +identity `Σₖ embedRight b k ∘ₗ restrictRight b k = 1` collapses the middle factor. Specialising to a +`V` with `V† V = 1` recovers the completeness relation `sum_adjoint_krausOp_comp_krausOp`. -/ +theorem sum_adjoint_krausOp_comp_krausOp_eq (b : OrthonormalBasis ι 𝕜 F) + (V : Hin →ₗ[𝕜] Eout ⊗[𝕜] F) : + ∑ k, adjoint (krausOp b V k) ∘ₗ krausOp b V k = adjoint V ∘ₗ V := by + ext x + simp only [LinearMap.sum_apply, krausOp, adjoint_comp, adjoint_restrictRight, + LinearMap.comp_apply] + rw [← map_sum] + congr 1 + calc ∑ k, embedRight b k (restrictRight b k (V x)) + = (∑ k, embedRight b k ∘ₗ restrictRight b k) (V x) := by + simp only [LinearMap.sum_apply, LinearMap.comp_apply] + _ = V x := by rw [sum_embedRight_comp_restrictRight, LinearMap.id_apply] + +/-- **`V† V = Σₖ Eₖ† Eₖ`** for the assembled dilation `V = krausDilation b E`. Consequently `V` is +an **isometry** (`V† V = 1`) **iff** the family is **complete** (`Σₖ Eₖ† Eₖ = 1`) — Nielsen–Chuang +Eq. (8.38). Immediate from `sum_adjoint_krausOp_comp_krausOp_eq` and `krausOp_krausDilation`. -/ +theorem adjoint_krausDilation_comp_self (b : OrthonormalBasis ι 𝕜 F) (E : ι → Hin →ₗ[𝕜] Eout) : + adjoint (krausDilation b E) ∘ₗ krausDilation b E = ∑ k, adjoint (E k) ∘ₗ E k := by + rw [← sum_adjoint_krausOp_comp_krausOp_eq b (krausDilation b E)] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [krausOp_krausDilation] + +/-- **The assembled dilation is an isometry when the family is complete** (`Σₖ Eₖ† Eₖ = 1`): then +`V† V = 1`. This is the hypothesis that lets `V` extend to a unitary +(`exists_unitary_krausDilation`). -/ +theorem adjoint_krausDilation_comp_self_eq_id (b : OrthonormalBasis ι 𝕜 F) + (E : ι → Hin →ₗ[𝕜] Eout) (hE : ∑ k, adjoint (E k) ∘ₗ E k = LinearMap.id) : + adjoint (krausDilation b E) ∘ₗ krausDilation b E = LinearMap.id := by + rw [adjoint_krausDilation_comp_self, hE] + +/-- **Operator-sum recovery from the assembled dilation** (Nielsen–Chuang Eq. (8.39)): tracing out +the environment factor from the conjugation `V ρ V†` returns the operator sum with the prescribed +operation elements, `tr_F(V ρ V†) = Σₖ Eₖ ρ Eₖ†`. No completeness hypothesis is needed. Combines the +forward theorem `partialTraceRight_conj_eq_sum_krausOp` with `krausOp_krausDilation`. -/ +theorem partialTraceRight_krausDilation_conj (b : OrthonormalBasis ι 𝕜 F) + (E : ι → Hin →ₗ[𝕜] Eout) (ρ : Hin →ₗ[𝕜] Hin) : + partialTraceRight b (krausDilation b E ∘ₗ ρ ∘ₗ adjoint (krausDilation b E)) = + ∑ k, E k ∘ₗ ρ ∘ₗ adjoint (E k) := by + rw [partialTraceRight_conj_eq_sum_krausOp] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [krausOp_krausDilation] + +/-- **The system–environment model realises the operation** (Nielsen–Chuang Eq. (8.36), the +recovery identity). If a joint map `U` intertwines the ancilla embedding with the dilation — +`U ∘ₗ tmulRightVec ω = krausDilation b E`, i.e. `U (ψ ⊗ ω) = V ψ` — then discarding the environment +factor from the conjugation of `ρ ⊗ |ω⟩⟨ω|` by `U` returns the operator sum, +`tr_F(U (ρ ⊗ |ω⟩⟨ω|) U†) = Σₖ Eₖ ρ Eₖ†`. The recovery needs no unitarity of `U`; the *physical* +model additionally takes `U` unitary (`exists_unitary_krausDilation`). Reuses the environment-model +recovery `partialTraceRight_conj_map_rankOne_eq_sum_krausOp` (with the joint map `W = U`), whose +operation elements `krausOp b (U ∘ₗ tmulRightVec ω) k` become the `Eₖ` after rewriting by `hU` and +`krausOp_krausDilation`. -/ +theorem partialTraceRight_conj_tmulRightVec_krausDilation (b : OrthonormalBasis ι 𝕜 F) + (E : ι → Hin →ₗ[𝕜] Eout) (U : Hin ⊗[𝕜] F →ₗ[𝕜] Eout ⊗[𝕜] F) {ω : F} + (hU : U ∘ₗ tmulRightVec ω = krausDilation b E) (ρ : Hin →ₗ[𝕜] Hin) : + partialTraceRight b + (U ∘ₗ TensorProduct.map ρ (InnerProductSpace.rankOne 𝕜 ω ω).toLinearMap ∘ₗ adjoint U) + = ∑ k, E k ∘ₗ ρ ∘ₗ adjoint (E k) := by + rw [partialTraceRight_conj_map_rankOne_eq_sum_krausOp] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [hU, krausOp_krausDilation] + +end KrausDilation + +section Unitary + +variable {𝕜 H F : Type*} [RCLike 𝕜] + [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [FiniteDimensional 𝕜 H] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- **The system–environment unitary** (Nielsen–Chuang Eq. (8.36)). For a **complete** family +`E : ι → H →ₗ H` (`Σₖ Eₖ† Eₖ = 1`) and a **unit** environment state `ω`, the assembled dilation +`V = krausDilation b E : H →ₗ H ⊗ F` — an isometry — **extends to a unitary** `U` on the joint space +`H ⊗ F`, agreeing with `V` on the input subspace: `U (ψ ⊗ ω) = V ψ` for every `ψ`. This is N&C's +statement that "the operator `U` can be extended to a unitary operator acting on the entire joint +state space" — the construction of Box 8.1, whose remaining block-matrix entries are our free +choice. Built from `LinearMap.unitaryExtend` (N&C Exercise 2.67) applied to the subspace +`{ψ ⊗ ω} = range (tmulRightVec ω)`: the map `ψ ⊗ ω ↦ V ψ` there is inner-product preserving because +`V` is an isometry (`adjoint_krausDilation_comp_self_eq_id`) and `ω` is a unit vector. -/ +theorem exists_unitary_krausDilation (b : OrthonormalBasis ι 𝕜 F) (E : ι → H →ₗ[𝕜] H) + (hE : ∑ k, adjoint (E k) ∘ₗ E k = LinearMap.id) {ω : F} (hω : ‖ω‖ = 1) : + ∃ U : (H ⊗[𝕜] F) ≃ₗᵢ[𝕜] (H ⊗[𝕜] F), ∀ ψ : H, U (ψ ⊗ₜ[𝕜] ω) = krausDilation b E ψ := by + set V := krausDilation b E with hVdef + have hViso : ∀ x y : H, ⟪V x, V y⟫_𝕜 = ⟪x, y⟫_𝕜 := by + intro x y + rw [← adjoint_inner_right, ← LinearMap.comp_apply, + adjoint_krausDilation_comp_self_eq_id b E hE, LinearMap.id_apply] + have hωω : ⟪ω, ω⟫_𝕜 = 1 := by rw [inner_self_eq_norm_sq_to_K, hω]; simp + set W : Submodule 𝕜 (H ⊗[𝕜] F) := LinearMap.range (tmulRightVec ω) with hWdef + set g₀ : (H ⊗[𝕜] F) →ₗ[𝕜] (H ⊗[𝕜] F) := V ∘ₗ contractRightVec ω with hg₀def + have hg₀ : ∀ ψ : H, g₀ (ψ ⊗ₜ[𝕜] ω) = V ψ := by + intro ψ + simp only [hg₀def, LinearMap.comp_apply, contractRightVec_tmul, hωω, one_smul] + set g : ↥W →ₗ[𝕜] (H ⊗[𝕜] F) := g₀.domRestrict W with hgdef + have hg : ∀ w₁ w₂ : ↥W, ⟪g w₁, g w₂⟫_𝕜 = ⟪w₁, w₂⟫_𝕜 := by + intro w₁ w₂ + obtain ⟨ψ₁, hψ₁⟩ := LinearMap.mem_range.mp w₁.2 + obtain ⟨ψ₂, hψ₂⟩ := LinearMap.mem_range.mp w₂.2 + have e₁ : (↑w₁ : H ⊗[𝕜] F) = ψ₁ ⊗ₜ[𝕜] ω := by rw [← hψ₁, tmulRightVec_apply] + have e₂ : (↑w₂ : H ⊗[𝕜] F) = ψ₂ ⊗ₜ[𝕜] ω := by rw [← hψ₂, tmulRightVec_apply] + rw [hgdef, LinearMap.domRestrict_apply, LinearMap.domRestrict_apply, e₁, e₂, hg₀, hg₀, hViso, + Submodule.coe_inner, e₁, e₂, TensorProduct.inner_tmul, hωω, mul_one] + refine ⟨g.unitaryExtend hg, fun ψ => ?_⟩ + have hmem : ψ ⊗ₜ[𝕜] ω ∈ W := LinearMap.mem_range.mpr ⟨ψ, tmulRightVec_apply ω ψ⟩ + calc (g.unitaryExtend hg) (ψ ⊗ₜ[𝕜] ω) + = g ⟨ψ ⊗ₜ[𝕜] ω, hmem⟩ := g.unitaryExtend_apply hg ⟨ψ ⊗ₜ[𝕜] ω, hmem⟩ + _ = g₀ (ψ ⊗ₜ[𝕜] ω) := by rw [hgdef, LinearMap.domRestrict_apply] + _ = V ψ := hg₀ ψ + +end Unitary + +end LinearMap + +namespace ContinuousLinearMap + +-- Both instance families are load-bearing; neither is redundant here. `ContinuousLinearMap.adjoint` +-- (in the hypothesis) needs `[CompleteSpace _]`, which is *not* synthesized from +-- `[FiniteDimensional ℂ _]` in this module: `FiniteDimensional.completeSpace` is deliberately not a +-- global instance (`Normed/Module/FiniteDimension.lean`), so dropping `[CompleteSpace _]` fails +-- elaboration with a `CompleteSpace` synthesis error. `LinearMap.adjoint` (in the conclusion) +-- needs `[FiniteDimensional ℂ _]`. The explicit `[CompleteSpace _]` matches the sibling +-- `ContinuousLinearMap.sum_adjoint_comp_comp_le_one`. +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + {ι : Type*} [Fintype ι] + +/-- **The `LinearMap`-level completeness relation from the `ContinuousLinearMap` one.** For an +operator family `E : ι → H →L[ℂ] G`, the completeness relation `∑ᵢ Eᵢ† Eᵢ = 1` (in the +`ContinuousLinearMap` algebra) transports along the `→ₗ` coercion to the `LinearMap` form +`∑ᵢ (Eᵢ†)ₗ ∘ₗ (Eᵢ)ₗ = 1ₗ`. This is the bridge that lets a caller holding the physical +`ContinuousLinearMap` completeness relation feed the `LinearMap`-stated dilation API +(`LinearMap.krausDilation`, `LinearMap.exists_unitary_krausDilation`), whose isometry hypothesis is +`∑ₖ (Eₖ)ₗ† ∘ₗ (Eₖ)ₗ = LinearMap.id`. Termwise: `↑(Eᵢ† ∘ Eᵢ) = (Eᵢ†)ₗ ∘ₗ (Eᵢ)ₗ` via `coe_comp` and +`adjoint_toLinearMap`. -/ +theorem sum_adjoint_comp_toLinearMap_eq_id (E : ι → H →L[ℂ] G) + (hE : ∑ i, adjoint (E i) ∘L E i = 1) : + ∑ i, LinearMap.adjoint ((E i).toLinearMap) ∘ₗ (E i).toLinearMap = LinearMap.id := by + ext x + have h := congrArg (fun T : H →L[ℂ] H => T x) hE + simpa only [toLinearMap_sum, sum_apply, comp_apply, one_apply_eq_self, LinearMap.coe_sum, + Finset.sum_apply, LinearMap.comp_apply, coe_coe, adjoint_toLinearMap, + LinearMap.id_apply] using h + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumFreedom.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumFreedom.lean new file mode 100644 index 0000000000..b91c6f54b2 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumFreedom.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import Mathlib.LinearAlgebra.UnitaryGroup + +/-! # Freedom in the operator-sum representation + +General API for the operator-sum (Kraus) map `ContinuousLinearMap.krausSumₗ E : ρ ↦ Σᵢ Eᵢ ρ Eᵢ†` +(defined in `ToMathlib.Analysis.InnerProductSpace.OperatorSum`) describing how the map behaves under +the natural reshapings of its family of operation elements. These are the structural facts behind +the "freedom in the operator-sum representation" of a quantum operation +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, §8.2): + +* `ContinuousLinearMap.krausSumₗ_comp_equiv` — **reindexing invariance**: reindexing the family by a + bijection leaves the operator-sum map unchanged, `krausSumₗ (F ∘ e) = krausSumₗ F`. +* `ContinuousLinearMap.krausSumₗ_sumElim` — **additivity**: the operator-sum map of a concatenated + family is the sum, `krausSumₗ (Sum.elim E F) = krausSumₗ E + krausSumₗ F`. +* `ContinuousLinearMap.krausSumₗ_const_zero` — the all-zero family induces the zero map, and its + corollaries `krausSumₗ_sumElim_zero_right` / `_left` — appending zero operators is neutral (the + "append zeros" padding used to bring two families to a common index). +* `ContinuousLinearMap.krausSumₗ_eq_of_unitary_smul` — **unitary freedom** (the "⇐" direction of + Nielsen & Chuang Theorem 8.2): two families over a common index related by a unitary coefficient + matrix, `Eₐ = Σ_b uₐ_b • F_b`, induce the same operator-sum map. + +## Implementation notes + +This general `krausSumₗ` API is kept in its own file, imported by consumers such as the minimal +operator-sum representation (`ToMathlib.Analysis.InnerProductSpace.MinimalOperatorSum`, Nielsen & +Chuang Theorem 8.3), rather than in the definitional file `OperatorSum.lean`. The full +characterization of Nielsen & Chuang Theorem 8.2 (both directions of the unitary-freedom `iff`) is a +separate development, `OperatorSum.krausSumₗ_eq_iff_exists_mem_unitaryGroup`, whose "⇐" direction +`krausSumₗ_eq_of_mem_unitaryGroup` is stated for a **same input/output** space (`H →L[ℂ] H`). The +`krausSumₗ_eq_of_unitary_smul` here is its input≠output generalization (`H →L[ℂ] G`), needed for the +`d`-to-`d′` minimal representation (Exercise 8.11); it is kept — not folded away — precisely because +it is strictly more general. +-/ + +@[expose] public section + +open scoped InnerProductSpace +open ContinuousLinearMap + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [CompleteSpace G] + +/-- **Reindexing invariance of the operator-sum map.** Reindexing a family of operation elements by +a bijection `e : κ ≃ ι` leaves its operator-sum map unchanged: `krausSumₗ (F ∘ e) = krausSumₗ F`. +The operator-sum map is a sum over the index, so `Equiv.sum_comp e` re-labels the summands. -/ +theorem krausSumₗ_comp_equiv {ι κ : Type*} [Fintype ι] [Fintype κ] (e : κ ≃ ι) + (F : ι → H →L[ℂ] G) : krausSumₗ (F ∘ e) = krausSumₗ F := by + refine LinearMap.ext fun ρ => ?_ + simp only [krausSumₗ_apply, Function.comp_apply] + exact Equiv.sum_comp e (fun j => F j ∘L ρ ∘L adjoint (F j)) + +/-- **Additivity of the operator-sum map over concatenation.** The operator-sum map of the +concatenated family `Sum.elim E F` (over the index `ι ⊕ κ`) is the sum of the two operator-sum maps: +`krausSumₗ (Sum.elim E F) = krausSumₗ E + krausSumₗ F`. Immediate from splitting the sum over +`ι ⊕ κ` (`Fintype.sum_sum_type`). -/ +theorem krausSumₗ_sumElim {ι κ : Type*} [Fintype ι] [Fintype κ] (E : ι → H →L[ℂ] G) + (F : κ → H →L[ℂ] G) : krausSumₗ (Sum.elim E F) = krausSumₗ E + krausSumₗ F := by + refine LinearMap.ext fun ρ => ?_ + simp only [krausSumₗ_apply, LinearMap.add_apply, Fintype.sum_sum_type, Sum.elim_inl, + Sum.elim_inr] + +/-- The all-zero family of operation elements induces the zero operator-sum map: +`krausSumₗ (fun _ => 0) = 0`. Each summand `0 ρ 0† = 0`. -/ +theorem krausSumₗ_const_zero {ι : Type*} [Fintype ι] : + krausSumₗ (fun _ : ι => (0 : H →L[ℂ] G)) = 0 := by + refine LinearMap.ext fun ρ => ?_ + simp [krausSumₗ_apply] + +/-- Appending zero operation elements on the right of a family does not change its operator-sum map: +`krausSumₗ (Sum.elim E 0) = krausSumₗ E`. The `F = 0` case of additivity (`krausSumₗ_sumElim`). -/ +theorem krausSumₗ_sumElim_zero_right {ι κ : Type*} [Fintype ι] [Fintype κ] (E : ι → H →L[ℂ] G) : + krausSumₗ (Sum.elim E (fun _ : κ => (0 : H →L[ℂ] G))) = krausSumₗ E := by + rw [krausSumₗ_sumElim, krausSumₗ_const_zero, add_zero] + +/-- Appending zero operation elements on the left of a family does not change its operator-sum map: +`krausSumₗ (Sum.elim 0 F) = krausSumₗ F`. The `E = 0` case of additivity (`krausSumₗ_sumElim`). -/ +theorem krausSumₗ_sumElim_zero_left {ι κ : Type*} [Fintype ι] [Fintype κ] (F : κ → H →L[ℂ] G) : + krausSumₗ (Sum.elim (fun _ : ι => (0 : H →L[ℂ] G)) F) = krausSumₗ F := by + rw [krausSumₗ_sumElim, krausSumₗ_const_zero, zero_add] + +/-- **Unitary freedom in the operator-sum representation** (Nielsen & Chuang, *Quantum Computation +and Quantum Information*, Theorem 8.2, "⇐" direction). If two finite families of operation elements +`E F : J → (H →L[ℂ] G)` over a common index are related by a unitary coefficient matrix +`u ∈ Matrix.unitaryGroup J ℂ`, `Eₐ = Σ_b uₐ_b • F_b`, then they induce the same operator-sum map: +`krausSumₗ E = krausSumₗ F`. + +Expanding `Eₐ ρ Eₐ†` bilinearly gives `Σ_b Σ_c (uₐ_b · conj uₐ_c) • (F_b ρ F_c†)`; summing over `a` +collapses the coefficient `Σₐ conj uₐ_c · uₐ_b = (u⋆ u)_c_b = δ_c_b` by unitarity, leaving +`Σ_b F_b ρ F_b†`. This generalizes `ContinuousLinearMap.krausSumₗ_eq_of_mem_unitaryGroup` from the +same input/output space `H →L[ℂ] H` to an arbitrary output space `H →L[ℂ] G`. -/ +theorem krausSumₗ_eq_of_unitary_smul {J : Type*} [Fintype J] [DecidableEq J] + {u : Matrix J J ℂ} (hu : u ∈ Matrix.unitaryGroup J ℂ) {E F : J → H →L[ℂ] G} + (hEF : ∀ a, E a = ∑ b, u a b • F b) : + krausSumₗ E = krausSumₗ F := by + have key : ∀ b c : J, (∑ a, (starRingEnd ℂ) (u a c) * u a b) = if c = b then (1 : ℂ) else 0 := by + intro b c + have h1 : (star u * u : Matrix J J ℂ) = 1 := Matrix.mem_unitaryGroup_iff'.mp hu + have h2 := congrFun (congrFun h1 c) b + rw [Matrix.mul_apply, Matrix.one_apply] at h2 + rw [← h2] + refine Finset.sum_congr rfl fun a _ => ?_ + rw [Matrix.star_apply, starRingEnd_apply] + refine LinearMap.ext fun ρ => ?_ + simp only [krausSumₗ_apply, hEF, map_sum, map_smulₛₗ, ContinuousLinearMap.finsetSum_comp, + ContinuousLinearMap.comp_finsetSum, ContinuousLinearMap.smul_comp, + ContinuousLinearMap.comp_smul, Finset.smul_sum, smul_smul] + calc ∑ a, ∑ c, ∑ b, ((starRingEnd ℂ) (u a c) * u a b) • ((F b).comp (ρ.comp (adjoint (F c)))) + = ∑ c, ∑ b, ∑ a, ((starRingEnd ℂ) (u a c) * u a b) • + ((F b).comp (ρ.comp (adjoint (F c)))) := by + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun c _ => Finset.sum_comm + _ = ∑ c, ∑ b, (∑ a, (starRingEnd ℂ) (u a c) * u a b) • + ((F b).comp (ρ.comp (adjoint (F c)))) := by + simp only [Finset.sum_smul] + _ = ∑ c, ∑ b, (if c = b then (1 : ℂ) else 0) • ((F b).comp (ρ.comp (adjoint (F c)))) := by + simp only [key] + _ = ∑ b, (F b).comp (ρ.comp (adjoint (F b))) := by + simp only [ite_smul, one_smul, zero_smul, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumReverse.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumReverse.lean new file mode 100644 index 0000000000..cc3b1cae5b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumReverse.lean @@ -0,0 +1,248 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiKraus + +/-! +# Assembling the reverse direction of the operator-sum theorem (Theorem 8.1) + +This file completes the reverse direction of the operator-sum representation theorem +(Nielsen–Chuang Theorem 8.1, *Quantum Computation and Quantum Information*, §8.2.4, Eqs. +(8.64)–(8.65)). Its predecessor `ToMathlib.Analysis.InnerProductSpace.OperatorSumChoiKraus` +established, for a **completely positive** superoperator `Φ`, a finite family of operation elements +`E` such that `Φ(|ψ⟩⟨ψ|) = Σᵢ Eᵢ |ψ⟩⟨ψ| Eᵢ†` holds on every **pure** state +(`ContinuousLinearMap.IsCompletelyPositive.exists_krausSumₗ_apply_rankOne`). Two steps remain, and +this file supplies both: + +* **Extension to all operators (N&C Eq. (8.65), "by convex-linearity").** Two `ℂ`-linear + superoperators that agree on all rank-one self-projectors `|ψ⟩⟨ψ|` agree everywhere, since the + `|ψ⟩⟨ψ|` span the whole operator space. The spanning is a **polarization identity** + (`InnerProductSpace.rankOne_eq_inv_four_smul_sum`): every rank-one operator `|x⟩⟨y|` is a + `ℂ`-combination of four self-projectors `|x + iᵏy⟩⟨x + iᵏy|`, and every operator is a sum of + rank-one operators over a basis. This upgrades the pure-state equality to `Φ = krausSumₗ E`. +* **The trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1` (N&C axiom A1).** From trace-non-increasing + (`IsTraceNonIncreasing (krausSumₗ E)`), testing against the state `|x⟩⟨x|` and using the trace + identity `tr(krausSumₗ E |x⟩⟨x|) = ⟪x, (Σᵢ Eᵢ† Eᵢ) x⟫` gives `re⟪x, (Σᵢ Eᵢ† Eᵢ) x⟫ ≤ ‖x‖²` for + all `x`, i.e. `1 − Σᵢ Eᵢ† Eᵢ ≥ 0`. + +## Main results + +* `InnerProductSpace.rankOne_add_smul_self` — the bilinear expansion + `|x + c y⟩⟨x + c y| = |x⟩⟨x| + c_bar |x⟩⟨y| + c |y⟩⟨x| + |c|² |y⟩⟨y|`. +* `InnerProductSpace.rankOne_eq_inv_four_smul_sum` — the **polarization identity** + `|x⟩⟨y| = ¼ Σ_{k<4} iᵏ |x + iᵏ y⟩⟨x + iᵏ y|`, writing a rank-one operator as a `ℂ`-combination of + rank-one self-projectors. +* `InnerProductSpace.superop_ext_of_forall_rankOne_self` — a `ℂ`-linear map out of the operator + space `H →L[ℂ] H` is determined by its values on the self-projectors `|ψ⟩⟨ψ|`. +* `ContinuousLinearMap.sum_adjoint_comp_le_one_of_isTraceNonIncreasing` — a trace-non-increasing + operator-sum map `krausSumₗ E` satisfies the trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`. +* `ContinuousLinearMap.SatisfiesOperationAxioms.isOperatorSum` — **N&C Theorem 8.1, reverse + direction (`⇒`):** a superoperator satisfying the operation axioms A1, A2, A3 admits an + operator-sum (Kraus) representation `IsOperatorSum E Φ` with at most `d²` operation elements. + +Everything here is general finite-dimensional complex Hilbert-space operator mathematics (the +Choi–Kraus theorem). +-/ + +open scoped TensorProduct InnerProductSpace ComplexConjugate +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +@[expose] public section + +namespace InnerProductSpace + +section Polarization + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +/-- **Bilinear expansion of a rank-one self-projector along a shifted vector.** Expanding +`|x + c y⟩⟨x + c y|` by the (conjugate-)bilinearity of `rankOne` gives +`|x⟩⟨x| + c_bar |x⟩⟨y| + c |y⟩⟨x| + (c c_bar) |y⟩⟨y|`, the conjugate `c_bar` appearing on the second +(ket-conjugate) slot. This is the per-term building block of the polarization identity. -/ +theorem rankOne_add_smul_self (x y : H) (c : ℂ) : + rankOne ℂ (x + c • y) (x + c • y) + = rankOne ℂ x x + (starRingEnd ℂ c) • rankOne ℂ x y + c • rankOne ℂ y x + + (c * starRingEnd ℂ c) • rankOne ℂ y y := by + simp only [map_add, map_smul, map_smulₛₗ, _root_.add_apply, + _root_.smul_apply] + module + +/-- **Polarization identity for rank-one operators** (Nielsen–Chuang §8.2.4, the algebraic content +of "by convex-linearity", Eq. (8.65)). Every rank-one operator `|x⟩⟨y|` is a `ℂ`-linear combination +of the four rank-one self-projectors `|x + iᵏ y⟩⟨x + iᵏ y|`: +`|x⟩⟨y| = ¼ Σ_{k<4} iᵏ |x + iᵏ y⟩⟨x + iᵏ y|`. +In particular the self-projectors `|ψ⟩⟨ψ|` span the whole operator space. Proved by expanding each +diagonal term with `rankOne_add_smul_self` and collecting the four complex coefficients +(`Σ iᵏ = 0`, `Σ iᵏ · i_barᵏ = 4`, `Σ i²ᵏ = 0`). -/ +theorem rankOne_eq_inv_four_smul_sum (x y : H) : + rankOne ℂ x y = (4⁻¹ : ℂ) • + (rankOne ℂ (x + y) (x + y) + + Complex.I • rankOne ℂ (x + Complex.I • y) (x + Complex.I • y) + - rankOne ℂ (x - y) (x - y) + - Complex.I • rankOne ℂ (x - Complex.I • y) (x - Complex.I • y)) := by + have e1 : x + y = x + (1 : ℂ) • y := by rw [one_smul] + have e2 : x - y = x + (-1 : ℂ) • y := by rw [neg_one_smul, ← sub_eq_add_neg] + have e3 : x - Complex.I • y = x + (-Complex.I) • y := by rw [neg_smul, ← sub_eq_add_neg] + rw [e1, e2, e3, rankOne_add_smul_self, rankOne_add_smul_self, rankOne_add_smul_self, + rankOne_add_smul_self] + simp only [map_one, map_neg, Complex.conj_I, smul_add, smul_smul, mul_one, mul_neg, + neg_mul, Complex.I_mul_I, neg_neg] + module + +end Polarization + +section Extension + +variable {H X : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] + [AddCommGroup X] [Module ℂ X] + +/-- **A superoperator is determined by its values on pure states.** Two `ℂ`-linear maps +`Φ, Ψ : (H →L[ℂ] H) →ₗ[ℂ] X` out of the operator space that agree on every rank-one self-projector +`|ψ⟩⟨ψ|` are equal. This is the "extension by convex-linearity" of Nielsen–Chuang Eq. (8.65): +polarization (`rankOne_eq_inv_four_smul_sum`) lifts the agreement from self-projectors to all +rank-one operators `|x⟩⟨y|`, and every operator `ρ` is the basis sum `Σₖ |ρ eₖ⟩⟨eₖ|` +(`OrthonormalBasis.sum_rankOne_eq_id` composed with `ρ`, via `comp_rankOne`). -/ +theorem superop_ext_of_forall_rankOne_self {Φ Ψ : (H →L[ℂ] H) →ₗ[ℂ] X} + (h : ∀ ψ : H, Φ (rankOne ℂ ψ ψ) = Ψ (rankOne ℂ ψ ψ)) : + Φ = Ψ := by + -- Step 1: `Φ` and `Ψ` agree on every rank-one operator, by polarization. The four self-projectors + -- are `set` first so that `map_add`/`map_smul` distribute `Φ`, `Ψ` over the polarization + -- combination without expanding the (linear) `rankOne` in its argument. + have key : ∀ x y : H, Φ (rankOne ℂ x y) = Ψ (rankOne ℂ x y) := by + intro x y + rw [rankOne_eq_inv_four_smul_sum x y] + set t0 := rankOne ℂ (x + y) (x + y) with ht0 + set t1 := rankOne ℂ (x + Complex.I • y) (x + Complex.I • y) with ht1 + set t2 := rankOne ℂ (x - y) (x - y) with ht2 + set t3 := rankOne ℂ (x - Complex.I • y) (x - Complex.I • y) with ht3 + have e0 : Φ t0 = Ψ t0 := by rw [ht0]; exact h (x + y) + have e1 : Φ t1 = Ψ t1 := by rw [ht1]; exact h (x + Complex.I • y) + have e2 : Φ t2 = Ψ t2 := by rw [ht2]; exact h (x - y) + have e3 : Φ t3 = Ψ t3 := by rw [ht3]; exact h (x - Complex.I • y) + simp only [map_smul, map_add, map_sub, e0, e1, e2, e3] + -- Step 2: extend to every operator `ρ`, written as a basis sum of rank-one operators. + ext ρ + set b := stdOrthonormalBasis ℂ H with hb + have hρ : ρ = ∑ i, rankOne ℂ (ρ (b i)) (b i) := by + calc ρ = ρ.comp (ContinuousLinearMap.id ℂ H) := (ρ.comp_id).symm + _ = ρ.comp (∑ i, rankOne ℂ (b i) (b i)) := by rw [b.sum_rankOne_eq_id] + _ = ∑ i, ρ.comp (rankOne ℂ (b i) (b i)) := by rw [ContinuousLinearMap.comp_finsetSum] + _ = ∑ i, rankOne ℂ (ρ (b i)) (b i) := + Finset.sum_congr rfl fun i _ => InnerProductSpace.comp_rankOne (b i) (b i) ρ + rw [hρ, map_sum, map_sum] + exact Finset.sum_congr rfl fun i _ => key _ _ + +end Extension + +end InnerProductSpace + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + {ι : Type*} [Fintype ι] + +/-- **The operator-sum trace condition from trace-non-increasing (Nielsen–Chuang axiom A1).** If the +operator-sum map `krausSumₗ E` is trace-non-increasing (`re tr(Σᵢ Eᵢ ρ Eᵢ†) ≤ re tr ρ` for every +positive `ρ`), then its operation elements satisfy the trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1`. The converse +of `krausSumₗ_isTraceNonIncreasing`. Testing at the positive operator `ρ = |x⟩⟨x|`, the trace +identity `trace_krausSumₗ` and `comp_rankOne`/`trace_rankOne` recast the hypothesis as +`re⟪x, (Σᵢ Eᵢ† Eᵢ) x⟫ ≤ re⟪x, x⟫` for all `x`; with `A := Σᵢ Eᵢ† Eᵢ` positive (hence self-adjoint), +`1 − A` is self-adjoint with `reApplyInnerSelf (1 − A) x = re⟪x, x⟫ − re⟪x, A x⟫ ≥ 0`, so +`(1 − A).IsPositive`, i.e. `A ≤ 1`. -/ +theorem sum_adjoint_comp_le_one_of_isTraceNonIncreasing (E : ι → H →L[ℂ] G) + (h : IsTraceNonIncreasing (krausSumₗ E)) : + ∑ i, adjoint (E i) ∘L E i ≤ 1 := by + set A : H →L[ℂ] H := ∑ i, adjoint (E i) ∘L E i with hA + have hApos : A.IsPositive := + isPositive_sum _ fun i _ => isPositive_adjoint_comp_self (E i) + -- The pairing bound `re⟪x, A x⟫ ≤ re⟪x, x⟫`, obtained by testing A1 at the state `|x⟩⟨x|`. + have hbound : ∀ x : H, RCLike.re ⟪x, A x⟫_ℂ ≤ RCLike.re ⟪x, x⟫_ℂ := by + intro x + have hpos : (0 : H →L[ℂ] H) ≤ rankOne ℂ x x := + nonneg_iff_isPositive.2 (isPositive_rankOne_self x) + have h1 := h (rankOne ℂ x x) hpos + rw [trace_krausSumₗ, ← hA] at h1 + -- `A ∘L |x⟩⟨x| = |A x⟩⟨x|`, whose trace is `⟪x, A x⟫`; and `tr|x⟩⟨x| = ⟪x, x⟫`. + rw [comp_rankOne x x A, InnerProductSpace.trace_rankOne, InnerProductSpace.trace_rankOne] at h1 + exact h1 + -- `A ≤ 1`, i.e. `(1 - A).IsPositive`. + rw [ContinuousLinearMap.le_def, ContinuousLinearMap.isPositive_def] + refine ⟨?_, fun x => ?_⟩ + · rw [← ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric] + exact (IsSelfAdjoint.one (H →L[ℂ] H)).sub + ((ContinuousLinearMap.isPositive_iff' A).mp hApos).1 + · have hre : (1 - A).reApplyInnerSelf x = RCLike.re ⟪x, x⟫_ℂ - RCLike.re ⟪x, A x⟫_ℂ := by + simp only [ContinuousLinearMap.reApplyInnerSelf, _root_.sub_apply, + one_apply_eq_self, inner_sub_left, map_sub] + rw [← inner_conj_symm x (A x), RCLike.conj_re] + rw [hre] + linarith [hbound x] + +/-- **The operator-sum completeness relation from trace preservation (Nielsen–Chuang Eq. (8.33)).** +If the operator-sum map `krausSumₗ E` is *trace-preserving* (`tr(Σᵢ Eᵢ ρ Eᵢ†) = tr ρ` for every +operator `ρ`), then its operation elements obey the **completeness relation** `Σᵢ Eᵢ† Eᵢ = 1` — the +equality sharpening of `sum_adjoint_comp_le_one_of_isTraceNonIncreasing` (`≤`) available when the +channel is deterministic. Testing at `ρ = |x⟩⟨x|`, the trace identity `trace_krausSumₗ` with +`comp_rankOne`/`trace_rankOne` recasts the hypothesis as `⟪x, (Σᵢ Eᵢ† Eᵢ) x⟫ = ⟪x, x⟫` for every +`x`; hence `⟪(A − 1) x, x⟫ = 0` for `A := Σᵢ Eᵢ† Eᵢ` (using conjugate symmetry), so `A − 1 = 0` by +nondegeneracy of the inner product (`inner_map_self_eq_zero`). -/ +theorem sum_adjoint_comp_eq_one_of_trace_krausSumₗ_eq (E : ι → H →L[ℂ] G) + (h : ∀ ρ : H →L[ℂ] H, + LinearMap.trace ℂ G ↑(krausSumₗ E ρ) = LinearMap.trace ℂ H ↑ρ) : + ∑ i, adjoint (E i) ∘L E i = 1 := by + set A : H →L[ℂ] H := ∑ i, adjoint (E i) ∘L E i with hA + -- `⟪x, A x⟫ = ⟪x, x⟫` for all `x`, by testing trace preservation at the state `|x⟩⟨x|`. + have hpair : ∀ x : H, (⟪x, A x⟫_ℂ : ℂ) = ⟪x, x⟫_ℂ := by + intro x + have h1 := h (rankOne ℂ x x) + rwa [trace_krausSumₗ, ← hA, comp_rankOne x x A, InnerProductSpace.trace_rankOne, + InnerProductSpace.trace_rankOne] at h1 + -- Its conjugate form `⟪A x, x⟫ = ⟪x, x⟫`. + have hpair2 : ∀ x : H, (⟪A x, x⟫_ℂ : ℂ) = ⟪x, x⟫_ℂ := by + intro x + rw [← inner_conj_symm (A x) x, hpair x, inner_conj_symm] + -- `A - 1 = 0`, so `A = 1`. + have hLM : ((A - 1 : H →L[ℂ] H) : H →ₗ[ℂ] H) = 0 := by + rw [← inner_map_self_eq_zero] + intro x + have hx : ((A - 1 : H →L[ℂ] H) x) = A x - x := by + rw [_root_.sub_apply, one_apply_eq_self] + rw [ContinuousLinearMap.coe_coe, hx, inner_sub_left, hpair2 x, sub_self] + rw [ContinuousLinearMap.toLinearMap_sub, sub_eq_zero] at hLM + exact ContinuousLinearMap.coe_injective hLM + +/-- **Nielsen–Chuang Theorem 8.1, reverse direction (`⇒`): a quantum operation admits an +operator-sum representation.** A superoperator `Φ` satisfying the operation axioms A1, A2, A3 +(`SatisfiesOperationAxioms`) has an operator-sum (Kraus) representation `IsOperatorSum E Φ` — a +finite family of at most `d² = finrank ℂ (H ⊗ G)` operation elements `E` with `Φ = krausSumₗ E` and +`Σᵢ Eᵢ† Eᵢ ≤ 1`. + +Complete positivity provides, via the Choi construction, a family agreeing with `Φ` on the pure +states (`IsCompletelyPositive.exists_krausSumₗ_apply_rankOne`); `superop_ext_of_forall_rankOne_self` +upgrades this to the map equality `Φ = krausSumₗ E`, and +`sum_adjoint_comp_le_one_of_isTraceNonIncreasing` derives the trace condition from axiom A1. +Together with the forward direction `IsOperatorSum.satisfiesAxioms` this is the full equivalence +of Theorem 8.1. -/ +theorem SatisfiesOperationAxioms.isOperatorSum {Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)} + (hΦ : SatisfiesOperationAxioms Φ) : + ∃ E : Fin (Module.finrank ℂ (H ⊗[ℂ] G)) → (H →L[ℂ] G), IsOperatorSum E Φ := by + obtain ⟨hCP, hTNI⟩ := hΦ + obtain ⟨E, hE⟩ := hCP.exists_krausSumₗ_apply_rankOne (stdOrthonormalBasis ℂ H) + have heq : Φ = krausSumₗ E := InnerProductSpace.superop_ext_of_forall_rankOne_self hE + refine ⟨E, heq, ?_⟩ + rw [heq] at hTNI + exact sum_adjoint_comp_le_one_of_isTraceNonIncreasing E hTNI + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumTheorem.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumTheorem.lean new file mode 100644 index 0000000000..d4540b858f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/OperatorSumTheorem.lean @@ -0,0 +1,81 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumReverse + +/-! +# The operator-sum representation theorem (Nielsen–Chuang Theorem 8.1) + +This file assembles the two directions established by the `OperatorSum*` development into the single +equivalence that is Nielsen & Chuang **Theorem 8.1** (*Quantum Computation and Quantum Information*, +§8.2.4, Box 8.1, Eq. (8.50)): + +a map `E` satisfies the operation axioms A1–A3 exactly when it has an operator-sum form +`E(ρ) = Σᵢ Eᵢ ρ Eᵢ†`, with operators `Eᵢ` from the input to the output space and `Σᵢ Eᵢ† Eᵢ ≤ I`. + +At the abstract operator level the left-hand side is +`ContinuousLinearMap.SatisfiesOperationAxioms Φ` +(complete positivity `IsCompletelyPositive`, axiom A3, together with trace-non-increasing +`IsTraceNonIncreasing`, axiom A1; axiom A2 — convex-linearity — is subsumed by modelling `Φ` as a +genuine `ℂ`-linear superoperator), and the right-hand side is the existence of a finite family `E` +with `ContinuousLinearMap.IsOperatorSum E Φ` (`Φ = krausSumₗ E` and `Σᵢ Eᵢ† Eᵢ ≤ 1`). The two +operators `Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)` carry independent input space `H` and output space +`G`, exactly matching N&C's "operators which map the input Hilbert space to the output Hilbert +space". + +## Main results + +* `ContinuousLinearMap.satisfiesOperationAxioms_iff_isOperatorSum` — **N&C Theorem 8.1**: a + superoperator `Φ` satisfies the operation axioms A1, A2, A3 iff it has an operator-sum (Kraus) + representation. The forward (`⇐`) direction is `IsOperatorSum.satisfiesAxioms`; the reverse + (`⇒`) direction is `SatisfiesOperationAxioms.isOperatorSum`. + +This is general finite-dimensional complex Hilbert-space operator mathematics. The physics +reading — a *quantum operation on a quantum system* — is +`AxQM.isQuantumOperation_iff_isOperatorSum`, which states this equivalence for quantum operations. +-/ + +open scoped TensorProduct + +noncomputable section + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H G : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +/-- **Nielsen–Chuang Theorem 8.1 (operator-sum representation theorem).** A superoperator +`Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)` satisfies the quantum-operation axioms A1, A2, A3 +(`SatisfiesOperationAxioms`: completely positive and trace-non-increasing) **iff** it has an +operator-sum (Kraus) representation — a finite family of operation elements `E : ι → (H →L[ℂ] G)` +with `Φ = krausSumₗ E` (i.e. `Φ ρ = Σᵢ Eᵢ ρ Eᵢ†`) and the trace condition `Σᵢ Eᵢ† Eᵢ ≤ 1` +(`IsOperatorSum E Φ`). + +The forward (`⇐`) direction — an operator sum is a quantum operation — is +`IsOperatorSum.satisfiesAxioms` (complete positivity of `krausSumₗ`, and the trace bound from +`Σᵢ Eᵢ† Eᵢ ≤ 1`). The reverse (`⇒`) direction — a quantum operation is an operator sum — is +`SatisfiesOperationAxioms.isOperatorSum` (the Choi construction, extended to all operators by +convex-linearity); it in fact yields a representation with at most `finrank ℂ (H ⊗ G)` operation +elements. -/ +theorem satisfiesOperationAxioms_iff_isOperatorSum + (Φ : (H →L[ℂ] H) →ₗ[ℂ] (G →L[ℂ] G)) : + SatisfiesOperationAxioms Φ ↔ + ∃ (ι : Type) (_ : Fintype ι) (E : ι → H →L[ℂ] G), IsOperatorSum E Φ := by + constructor + · intro hΦ + obtain ⟨E, hE⟩ := hΦ.isOperatorSum + exact ⟨_, inferInstance, E, hE⟩ + · rintro ⟨ι, _, E, hE⟩ + exact hE.satisfiesAxioms + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Orthonormal.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Orthonormal.lean new file mode 100644 index 0000000000..9557bd82a4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Orthonormal.lean @@ -0,0 +1,40 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Orthonormal + +/-! +# Orthonormal sets: the Pythagorean theorem + +Extends `Mathlib.Analysis.InnerProductSpace.Orthonormal` with the smul form of the Pythagorean +theorem for a finite linear combination over an orthonormal family. +-/ + +@[expose] public section + +noncomputable section + +open RCLike ComplexConjugate + +variable {𝕜 E ι : Type*} [RCLike 𝕜] [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **Pythagorean theorem (orthonormal-smul form)**: the squared norm of a finite linear +combination over an orthonormal family equals the sum of squared coefficient norms. + +The same fact is also available as a specialization of `OrthogonalFamily.norm_sum` +applied to `Orthonormal.orthogonalFamily` (in `InnerProductSpace.Subspace`), but via the +`LinearIsometry.toSpanSingleton` coercion which obscures the natural smul pattern. This +file-local proof goes directly through `Orthonormal.inner_sum`. -/ +protected theorem Orthonormal.norm_sum_smul_sq {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) + (s : Finset ι) : ‖∑ i ∈ s, l i • v i‖ ^ 2 = ∑ i ∈ s, ‖l i‖ ^ 2 := by + rw [← @inner_self_eq_norm_sq 𝕜, hv.inner_sum l l, map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [RCLike.conj_mul] + norm_cast diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVM.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVM.lean new file mode 100644 index 0000000000..c1d41b2307 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVM.lean @@ -0,0 +1,355 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm +public import LeanPool.AxQM.ToMathlib.Analysis.RCLike.Basic + +/-! +# Positive operator-valued measures (POVMs) + +A **POVM** on a finite-dimensional inner product space `E` over `𝕜` (`ℝ` or `ℂ`) with +finite outcome index `ι` is a family of positive operators `M.elements i : E →L[𝕜] E` +indexed by `i : ι`, satisfying `∑ i, M.elements i = 1`. POVMs generalize projective +measurements: each `M.elements i` is a "soft" positive operator with the closure-to- +identity replacing idempotence. + +Per Nielsen–Chuang §2.2.6, POVMs encode the most general form of quantum measurement +consistent with the Born rule: +`Pr(outcome = i | state ρ) = tr(M.elements i ∘L ρ)`. + +## Main definitions + +- `POVM ι 𝕜 E`: a POVM on `E` over `𝕜` with outcome index `ι`. + +## Main results + +- `POVM.isPositive`, `POVM.sum_eq_one`: unpacking lemmas. +- `POVM.isSymmetric`: each `M.elements i` is symmetric (via positivity). +- `POVM.reApplyInnerSelf_nonneg`: each `M.elements i` satisfies + `0 ≤ re ⟪M.elements i ψ, ψ⟫`. + +## Constructors + +- `POVM.ofOrthonormalBasis`: the rank-one POVM associated to an orthonormal basis, with + `elements i := rankOne (b i) (b i)`. The canonical "projective measurement in basis `b`" + and the building block for the Fuchs–Caves canonical POVM (Nielsen–Chuang §9.2.2). +- `POVM.toPMF_ofOrthonormalBasis`: `toPMF (ofOrthonormalBasis b) ρ i = re ⟪b i, ρ (b i)⟫`. + +## Implementation notes + +The structure is RCLike-generic (`[RCLike 𝕜]`), matching `IsDensityOp` and `IsPositive` +conventions. Type parameter order `(ι 𝕜 E)` matches `OrthonormalBasis`. + +The minimal API surface is: structure definition + unpacking lemmas + the inner-product +positivity helper. Constructors (rank-one projective measurements, orthonormal-basis- +derived POVMs), measurement probabilities, and the Naimark dilation theorem are left +to the files that need them. + +## References + +Nielsen, M. A., & Chuang, I. L. (2010). *Quantum Computation and Quantum Information* +(10th anniv. ed.). Cambridge University Press. §2.2.6. +-/ + +@[expose] public section + +/-- A **positive operator-valued measure (POVM)** on a finite-dim inner product space +`E` over `𝕜` with finite outcome index `ι`: a family of positive operators summing to +the identity. -/ +@[ext] +structure POVM (ι : Type*) [Fintype ι] (𝕜 : Type*) [RCLike 𝕜] + (E : Type*) [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] where + /-- The operator-valued measure: outcome `i` corresponds to `elements i`. -/ + elements : ι → E →L[𝕜] E + /-- Each element is positive. -/ + isPositive : ∀ i, (elements i).IsPositive + /-- The elements sum to the identity. -/ + sum_eq_one : ∑ i, elements i = 1 + +namespace POVM + +variable {ι : Type*} [Fintype ι] + {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- Each element of a POVM is symmetric (immediate from positivity). -/ +theorem isSymmetric (M : POVM ι 𝕜 E) (i : ι) : + (M.elements i).IsSymmetric := + (M.isPositive i).isSymmetric + +/-- Each element of a POVM has non-negative real-part inner product with any vector: +`0 ≤ re ⟪M.elements i ψ, ψ⟫`. -/ +theorem reApplyInnerSelf_nonneg (M : POVM ι 𝕜 E) (i : ι) (ψ : E) : + 0 ≤ (M.elements i).reApplyInnerSelf ψ := + (M.isPositive i).reApplyInnerSelf_nonneg ψ + +/-- The pointwise sum identity: applying all POVM elements to a fixed vector `ψ` and +summing recovers `ψ`. -/ +@[simp] +theorem sum_apply_eq_self (M : POVM ι 𝕜 E) (ψ : E) : + ∑ i, M.elements i ψ = ψ := by + rw [← sum_apply, M.sum_eq_one, one_apply_eq_self] + +/-- **Born rule**: the probability of measurement outcome `i` for state `ρ` under POVM +`M`, defined as `Re tr(M.elements i ∘L ρ)`. Real-valued (the imaginary parts of the +trace cancel for self-adjoint operands). -/ +noncomputable def toPMF + (M : POVM ι 𝕜 E) (ρ : E →L[𝕜] E) (i : ι) : ℝ := + RCLike.re (LinearMap.trace 𝕜 E ((M.elements i ∘L ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) + +theorem toPMF_eq + (M : POVM ι 𝕜 E) (ρ : E →L[𝕜] E) (i : ι) : + M.toPMF ρ i = + RCLike.re (LinearMap.trace 𝕜 E ((M.elements i ∘L ρ : E →L[𝕜] E) : E →ₗ[𝕜] E)) := + rfl + +variable [FiniteDimensional 𝕜 E] + +/-- **Born probability on a pure state.** For a POVM `M` and a vector `ψ`, the Born-rule +probability of outcome `i` on the pure state `|ψ⟩⟨ψ|` (`InnerProductSpace.rankOne 𝕜 ψ ψ`) equals +`(M.elements i).reApplyInnerSelf ψ = re ⟪(M.elements i) ψ, ψ⟫`. -/ +theorem toPMF_rankOne_self (M : POVM ι 𝕜 E) (ψ : E) (i : ι) : + M.toPMF (InnerProductSpace.rankOne 𝕜 ψ ψ) i = (M.elements i).reApplyInnerSelf ψ := by + rw [toPMF_eq, InnerProductSpace.comp_rankOne, InnerProductSpace.trace_rankOne, + ContinuousLinearMap.reApplyInnerSelf_apply, ← inner_conj_symm (M.elements i ψ) ψ, + RCLike.conj_re] + +/-- **Non-negativity** of measurement probabilities: for a positive operator `ρ` (in +particular, a density operator), each outcome probability is non-negative. Proof: expand +`trace (M_i ρ)` in the spectral basis of `ρ`; each summand is `λ_j · re ⟪b_j, M_i b_j⟫` +with `λ_j ≥ 0` (positive operator's eigenvalue) and `re ⟪b_j, M_i b_j⟫ ≥ 0` (positivity +of `M_i`). -/ +theorem toPMF_nonneg (M : POVM ι 𝕜 E) {ρ : E →L[𝕜] E} + (hρ : ρ.IsPositive) (i : ι) : + 0 ≤ M.toPMF ρ i := by + rw [toPMF_eq, ContinuousLinearMap.toLinearMap_comp, + hρ.toLinearMap.isSymmetric.trace_comp_eq_sum_eigenvalues_inner rfl _, map_sum RCLike.re] + refine Finset.sum_nonneg fun j _ ↦ ?_ + rw [RCLike.re_ofReal_mul] + refine mul_nonneg (hρ.toLinearMap.nonneg_eigenvalues rfl j) ?_ + rw [← (M.isPositive i).toLinearMap.isSymmetric (_ : E) (_ : E)] + exact (M.isPositive i).toLinearMap.re_inner_nonneg_left _ + +omit [FiniteDimensional 𝕜 E] in +/-- For a POVM `M` and any operator `T`, summing the traces of `(M.elements i) ∘L T` +over outcomes recovers the trace of `T`. Direct consequence of trace linearity and +`M.sum_eq_one`. -/ +theorem sum_trace_elements_comp (M : POVM ι 𝕜 E) (T : E →L[𝕜] E) : + ∑ i, LinearMap.trace 𝕜 E ((M.elements i ∘L T : E →L[𝕜] E) : E →ₗ[𝕜] E) = + LinearMap.trace 𝕜 E T.toLinearMap := by + rw [← map_sum (LinearMap.trace 𝕜 E) _ Finset.univ, + ← ContinuousLinearMap.toLinearMap_sum, + ← ContinuousLinearMap.finsetSum_comp _ _, M.sum_eq_one, + ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_one, + Module.End.one_eq_id, LinearMap.id_comp] + +omit [FiniteDimensional 𝕜 E] in +/-- **Sums-to-one**: for a density operator `ρ`, the outcome probabilities form a +probability distribution. Proof: linearity of trace + `M.sum_eq_one` + `tr ρ = 1`. -/ +theorem sum_toPMF_eq_one (M : POVM ι 𝕜 E) {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) : + ∑ i, M.toPMF ρ i = 1 := by + simp_rw [toPMF_eq] + rw [← map_sum RCLike.re, M.sum_trace_elements_comp, hρ.trace_eq_one, RCLike.one_re] + +/-- **Born rule = real part of HS pairing**: for any operator `ρ` and POVM element +`M.elements i`, the Born-rule probability `M.toPMF ρ i` equals the real part of the +Hilbert-Schmidt pairing of `ρ` with `M.elements i`. Bridges the trace-distance variational +form (`traceNorm_eq_iSup` over the HS pairing) to the POVM probabilities. -/ +theorem re_hsPairing_elements_eq_toPMF [CompleteSpace E] (M : POVM ι 𝕜 E) + (ρ : E →L[𝕜] E) (i : ι) : + RCLike.re (ρ.hsPairing (M.elements i)) = M.toPMF ρ i := by + rw [ContinuousLinearMap.hsPairing_eq, + ContinuousLinearMap.isSelfAdjoint_iff'.mp (M.isPositive i).isSelfAdjoint, ← toPMF_eq] + +/-- The **signed Born-rule difference** in terms of the HS pairing: for any pair of +operators `ρ, σ`, the difference of Born-rule probabilities under a POVM `M` equals the +real part of the HS pairing of `ρ - σ` with the POVM element. Corollary of +`re_hsPairing_elements_eq_toPMF` via linearity of HS pairing in the first argument. -/ +theorem re_hsPairing_elements_sub_eq_toPMF_sub [CompleteSpace E] (M : POVM ι 𝕜 E) + (ρ σ : E →L[𝕜] E) (i : ι) : + RCLike.re ((ρ - σ).hsPairing (M.elements i)) = M.toPMF ρ i - M.toPMF σ i := by + rw [ContinuousLinearMap.hsPairing_sub_left, map_sub, + M.re_hsPairing_elements_eq_toPMF, M.re_hsPairing_elements_eq_toPMF] + +omit [FiniteDimensional 𝕜 E] in +/-- For a POVM `M` and a real-valued function `r : ι → ℝ` with `|r i| ≤ 1` for all `i`, +the operator norm of the signed combination `∑ i, (r i : 𝕜) • M.elements i` is bounded +by `1`. Used in the proof of trace-distance monotonicity under POVM measurement: the +signed combination is the witness operator in the variational form of `traceNorm`. -/ +theorem opNorm_sum_real_smul_le_one [CompleteSpace E] (M : POVM ι 𝕜 E) (r : ι → ℝ) + (hr : ∀ i, |r i| ≤ 1) : + ‖∑ i, (r i : 𝕜) • M.elements i‖ ≤ 1 := by + set W : E →L[𝕜] E := ∑ i, (r i : 𝕜) • M.elements i with hW_def + have hW_symm : W.IsSymmetric := IsSelfAdjoint.isSymmetric <| hW_def ▸ + isSelfAdjoint_sum Finset.univ fun i _ ↦ + (RCLike.isSelfAdjoint_ofReal (r i)).smul (M.isPositive i).isSelfAdjoint + rw [ContinuousLinearMap.norm_eq_iSup_rayleighQuotient _ hW_symm] + refine ciSup_le fun x ↦ ?_ + by_cases hx : x = 0 + · simp [hx, ContinuousLinearMap.rayleighQuotient, + ContinuousLinearMap.reApplyInnerSelf] + rw [ContinuousLinearMap.rayleighQuotient, abs_div, abs_sq, + div_le_iff₀ (by positivity), one_mul] + -- Decompose `W.reApplyInnerSelf x = ∑ r_i (M.elements i).reApplyInnerSelf x`, then bound. + calc |W.reApplyInnerSelf x| + = |∑ i, r i * (M.elements i).reApplyInnerSelf x| := by + rw [hW_def, ContinuousLinearMap.reApplyInnerSelf_sum] + simp_rw [ContinuousLinearMap.reApplyInnerSelf_ofReal_smul] + _ ≤ ∑ i, |r i * (M.elements i).reApplyInnerSelf x| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ i, |r i| * (M.elements i).reApplyInnerSelf x := + Finset.sum_congr rfl fun i _ ↦ by + rw [abs_mul, abs_of_nonneg ((M.isPositive i).reApplyInnerSelf_nonneg _)] + _ ≤ ∑ i, (M.elements i).reApplyInnerSelf x := + Finset.sum_le_sum fun i _ ↦ + mul_le_of_le_one_left ((M.isPositive i).reApplyInnerSelf_nonneg _) (hr i) + _ = (1 : E →L[𝕜] E).reApplyInnerSelf x := by + rw [← M.sum_eq_one, ContinuousLinearMap.reApplyInnerSelf_sum] + _ = ‖x‖ ^ 2 := by + rw [ContinuousLinearMap.reApplyInnerSelf_apply, one_apply_eq_self, + inner_self_eq_norm_sq] + +/-! ## The rank-one POVM associated to an orthonormal basis -/ + +omit [FiniteDimensional 𝕜 E] in +/-- The **rank-one POVM** built from an orthonormal basis `b`: outcome `i` corresponds to +the rank-one projector `rankOne 𝕜 (b i) (b i)`. The resolution of identity +(`OrthonormalBasis.sum_rankOne_eq_id`) supplies the `sum_eq_one` field; positivity comes +from `isPositive_rankOne_self`. This is the canonical "projective measurement in basis +`b`" and the building block for the Fuchs–Caves canonical POVM (Nielsen–Chuang §9.2.2). -/ +noncomputable def ofOrthonormalBasis (b : OrthonormalBasis ι 𝕜 E) : POVM ι 𝕜 E where + elements i := InnerProductSpace.rankOne 𝕜 (b i) (b i) + isPositive _ := InnerProductSpace.isPositive_rankOne_self _ + sum_eq_one := b.sum_rankOne_eq_id + +omit [FiniteDimensional 𝕜 E] in +@[simp] +theorem ofOrthonormalBasis_elements (b : OrthonormalBasis ι 𝕜 E) (i : ι) : + (ofOrthonormalBasis b).elements i = InnerProductSpace.rankOne 𝕜 (b i) (b i) := + rfl + +/-- The **Born-rule probability** of outcome `i` under the projective measurement +`ofOrthonormalBasis b` on state `ρ` equals `re ⟪b i, ρ (b i)⟫`: the (real-part) diagonal +matrix element of `ρ` in basis `b`. Proof: trace-cyclicity + `comp_rankOne` reduce the +trace of `rankOne (b i) (b i) ∘L ρ` to `trace (rankOne (ρ (b i)) (b i)) = ⟪b i, ρ (b i)⟫`. -/ +theorem toPMF_ofOrthonormalBasis (b : OrthonormalBasis ι 𝕜 E) (ρ : E →L[𝕜] E) (i : ι) : + (ofOrthonormalBasis b).toPMF ρ i = RCLike.re (inner 𝕜 (b i) (ρ (b i))) := by + rw [toPMF_eq, ofOrthonormalBasis_elements, ContinuousLinearMap.toLinearMap_comp, + LinearMap.trace_comp_comm', ← ContinuousLinearMap.toLinearMap_comp, + InnerProductSpace.comp_rankOne, InnerProductSpace.trace_rankOne] + +/-- `toPMF M ρ i` is continuous in `ρ` for fixed `M : POVM ι 𝕜 E` and `i : ι`. -/ +@[fun_prop] +theorem _root_.Continuous.toPMF {X : Type*} [TopologicalSpace X] (M : POVM ι 𝕜 E) (i : ι) + {ρ : X → E →L[𝕜] E} (hρ : Continuous ρ) : + Continuous (fun x ↦ M.toPMF (ρ x) i) := + RCLike.continuous_re.comp <| ContinuousLinearMap.continuous_trace.comp <| + (ContinuousLinearMap.compL 𝕜 E E E (M.elements i)).continuous.comp hρ + +open Filter Topology in +/-- Joint Tendsto-form of `Continuous.toPMF`: given convergence of the POVM elements +`(M x).elements i → (M₀).elements i` and `ρ x → ρ₀`, `(M x).toPMF (ρ x) i → M₀.toPMF ρ₀ i`. +Used by the saturation extension proof to pass an equality through the limit +when both the POVM sequence and the perturbation sequence vary together. -/ +theorem _root_.Filter.Tendsto.toPMF {X : Type*} {l : Filter X} + {M : X → POVM ι 𝕜 E} {M₀ : POVM ι 𝕜 E} {ρ : X → E →L[𝕜] E} {ρ₀ : E →L[𝕜] E} {i : ι} + (hM : Tendsto (fun x ↦ (M x).elements i) l (𝓝 (M₀.elements i))) + (hρ : Tendsto ρ l (𝓝 ρ₀)) : + Tendsto (fun x ↦ (M x).toPMF (ρ x) i) l (𝓝 (M₀.toPMF ρ₀ i)) := + (RCLike.continuous_re.tendsto _).comp <| + (ContinuousLinearMap.continuous_trace.tendsto _).comp <| + ((ContinuousLinearMap.compL 𝕜 E E E).continuous₂.tendsto (M₀.elements i, ρ₀)).comp + (hM.prodMk_nhds hρ) + +end POVM + +/-- The underlying-tuple view of POVMs: tuples `f : ι → E →L[𝕜] E` satisfying the positivity +and sum-to-one axioms. Defined as an intersection so closedness/compactness arguments don't +have to unfold the predicate form. Useful for topological arguments (closedness, compactness, +subsequence extraction) where the flat `POVM` structure is awkward. -/ +def POVMSet (ι : Type*) [Fintype ι] (𝕜 : Type*) [RCLike 𝕜] (E : Type*) + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] : Set (ι → E →L[𝕜] E) := + (⋂ i, {f | (f i).IsPositive}) ∩ {f | ∑ i, f i = 1} + +namespace POVM + +variable {ι : Type*} [Fintype ι] + {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- A POVM's elements are a tuple in `POVMSet`. -/ +theorem elements_mem_POVMSet (M : POVM ι 𝕜 E) : M.elements ∈ POVMSet ι 𝕜 E := + ⟨Set.mem_iInter.mpr M.isPositive, M.sum_eq_one⟩ + +/-- Reconstruct a POVM from a tuple in `POVMSet`. -/ +@[simps] +def ofMemPOVMSet {f : ι → E →L[𝕜] E} (hf : f ∈ POVMSet ι 𝕜 E) : POVM ι 𝕜 E where + elements := f + isPositive := Set.mem_iInter.mp hf.1 + sum_eq_one := hf.2 + +/-- `POVMSet ι 𝕜 E` is closed in the operator-norm topology. -/ +theorem POVMSet_isClosed [CompleteSpace E] : IsClosed (POVMSet ι 𝕜 E) := + .inter + (isClosed_iInter fun i ↦ ContinuousLinearMap.isClosed_setOf_isPositive.preimage + (continuous_apply (A := fun _ : ι ↦ E →L[𝕜] E) i)) + (isClosed_singleton.preimage (by fun_prop)) + +/-- Each POVM element has operator norm bounded by `(finrank 𝕜 E : ℝ)`, since for positive `M_i` +with `∑ M_j = 1`, `‖M_i‖_op ≤ M_i.traceNorm = re tr M_i ≤ ∑ re tr M_j = re tr 1 = finrank 𝕜 E`. -/ +theorem POVMSet_opNorm_le [FiniteDimensional 𝕜 E] {f : ι → E →L[𝕜] E} + (hf : f ∈ POVMSet ι 𝕜 E) (i : ι) : ‖f i‖ ≤ (Module.finrank 𝕜 E : ℝ) := by + obtain ⟨hf_pos_inter, hf_sum⟩ := hf + have hf_pos := Set.mem_iInter.mp hf_pos_inter + have h_tr_eq : ∀ j, RCLike.re (LinearMap.trace 𝕜 E ((f j : E →L[𝕜] E) : E →ₗ[𝕜] E)) = + (f j).traceNorm := + fun j ↦ (ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive (hf_pos j)).symm + calc ‖f i‖ + ≤ (f i).traceNorm := (f i).opNorm_le_traceNorm + _ = RCLike.re (LinearMap.trace 𝕜 E ((f i : E →L[𝕜] E) : E →ₗ[𝕜] E)) := (h_tr_eq i).symm + _ ≤ ∑ j, RCLike.re (LinearMap.trace 𝕜 E ((f j : E →L[𝕜] E) : E →ₗ[𝕜] E)) := + Finset.single_le_sum (f := fun j ↦ RCLike.re _) + (fun j _ ↦ (h_tr_eq j).symm ▸ ContinuousLinearMap.traceNorm_nonneg _) + (Finset.mem_univ i) + _ = RCLike.re (LinearMap.trace 𝕜 E ((1 : E →L[𝕜] E) : E →ₗ[𝕜] E)) := by + rw [← map_sum RCLike.re, ← map_sum, ← ContinuousLinearMap.toLinearMap_sum, hf_sum] + _ = (Module.finrank 𝕜 E : ℝ) := by + rw [ContinuousLinearMap.toLinearMap_one, LinearMap.trace_one, RCLike.natCast_re] + +/-- `POVMSet ι 𝕜 E` is bounded in the operator-norm topology. -/ +theorem POVMSet_isBounded [FiniteDimensional 𝕜 E] : + Bornology.IsBounded (POVMSet ι 𝕜 E) := by + rw [Metric.isBounded_iff_subset_closedBall 0] + refine ⟨(Module.finrank 𝕜 E : ℝ), fun f hf ↦ ?_⟩ + rw [Metric.mem_closedBall, dist_zero_right, + pi_norm_le_iff_of_nonneg (Nat.cast_nonneg _)] + exact POVMSet_opNorm_le hf + +/-- `POVMSet ι 𝕜 E` is compact in finite dimensions (Heine-Borel: closed + bounded). -/ +theorem POVMSet_isCompact [FiniteDimensional 𝕜 E] : + IsCompact (POVMSet ι 𝕜 E) := by + have : CompleteSpace E := FiniteDimensional.completeSpace 𝕜 E + have : ProperSpace (ι → E →L[𝕜] E) := FiniteDimensional.proper_rclike 𝕜 _ + exact Metric.isCompact_iff_isClosed_bounded.mpr ⟨POVMSet_isClosed, POVMSet_isBounded⟩ + +open Filter Topology in +/-- A sequence of POVMs admits a subsequence whose elements converge to those of some +POVM. Corollary of `POVMSet_isCompact.tendsto_subseq` bundled via `ofMemPOVMSet`. -/ +theorem exists_tendsto_elements_subseq [FiniteDimensional 𝕜 E] (M : ℕ → POVM ι 𝕜 E) : + ∃ (M_star : POVM ι 𝕜 E) (φ : ℕ → ℕ), StrictMono φ ∧ + Tendsto (fun k ↦ (M (φ k)).elements) atTop (𝓝 M_star.elements) := by + obtain ⟨_, hf_mem, φ, hφ_mono, hφ_tendsto⟩ := + POVMSet_isCompact.tendsto_subseq fun n ↦ (M n).elements_mem_POVMSet + exact ⟨ofMemPOVMSet hf_mem, φ, hφ_mono, hφ_tendsto⟩ + +end POVM diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVMMap.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVMMap.lean new file mode 100644 index 0000000000..754b138b98 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/POVMMap.lean @@ -0,0 +1,76 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVM + +/-! +# Pushforward (coarse-graining) of a POVM along a function on outcomes + +Given a POVM `M : POVM ι 𝕜 E` and a function `g : ι → κ` on the outcome index, the **pushforward** +`M.map g : POVM κ 𝕜 E` is the POVM whose effect at `k` groups (sums) the effects of all original +outcomes lying over `k`: + +`(M.map g).elements k = ∑_{i : g i = k} M.elements i`. + +This is the measure-theoretic pushforward specialised to a POVM: it is again a POVM (each grouped +effect is a finite sum of positive operators, hence positive; the grouped effects still sum to `1` +because the fibres of `g` partition `ι`, `Finset.sum_fiberwise`), and its Born rule is the grouped +Born rule `(M.map g).toPMF ρ k = ∑_{i : g i = k} M.toPMF ρ i`. + +When `g` is injective this is a mere relabelling; when `g` is not injective it is a genuine +**coarse-graining** — several outcomes are combined into one, their probabilities adding. It is the +operation behind "declaring several measurement outcomes equivalent", used e.g. to fold the +non-selected decoding outcomes of a code into a single inconclusive outcome. + +## Main definitions / results + +* `POVM.map` — the pushforward POVM along `g : ι → κ`. +* `POVM.map_elements` — its effects, `(M.map g).elements k = ∑_{g i = k} M.elements i`. +* `POVM.map_toPMF` — its Born rule, `(M.map g).toPMF ρ k = ∑_{g i = k} M.toPMF ρ i`. +-/ + +@[expose] public section + +open scoped BigOperators + +namespace POVM + +variable {ι : Type*} [Fintype ι] {κ : Type*} [Fintype κ] [DecidableEq κ] + {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **Pushforward of a POVM along a function on outcomes.** For a POVM `M : POVM ι 𝕜 E` and a +function `g : ι → κ`, `M.map g` is the POVM on the outcome set `κ` whose effect at `k` is the sum of +the effects of the original outcomes in the fibre `g⁻¹{k}`: +`(M.map g).elements k = ∑_{i : g i = k} M.elements i`. Each fibre-sum of positive operators is +positive (`ContinuousLinearMap.isPositive_sum`), and the fibre-sums recombine to the identity +because the fibres of `g` partition `ι` (`Finset.sum_fiberwise`). Injective `g` gives a relabelling; +general `g` a coarse-graining that merges outcomes. -/ +noncomputable def map (M : POVM ι 𝕜 E) (g : ι → κ) : POVM κ 𝕜 E where + elements k := ∑ i ∈ Finset.univ.filter (fun i => g i = k), M.elements i + isPositive k := ContinuousLinearMap.isPositive_sum _ fun i _ => M.isPositive i + sum_eq_one := by + rw [Finset.sum_fiberwise Finset.univ g M.elements]; exact M.sum_eq_one + +@[simp] +theorem map_elements (M : POVM ι 𝕜 E) (g : ι → κ) (k : κ) : + (M.map g).elements k = ∑ i ∈ Finset.univ.filter (fun i => g i = k), M.elements i := rfl + +/-- **Born rule of the pushforward POVM.** The probability the coarse-grained POVM `M.map g` assigns +to the merged outcome `k` on a state `ρ` is the sum of the probabilities `M` assigns to the original +outcomes lying over `k`: `(M.map g).toPMF ρ k = ∑_{i : g i = k} M.toPMF ρ i`. Immediate from +linearity of the trace over the fibre-sum defining the grouped effect. -/ +theorem map_toPMF (M : POVM ι 𝕜 E) (g : ι → κ) (ρ : E →L[𝕜] E) (k : κ) : + (M.map g).toPMF ρ k = ∑ i ∈ Finset.univ.filter (fun i => g i = k), M.toPMF ρ i := by + simp only [toPMF_eq, map_elements] + rw [← RCLike.re_sum, ← map_sum (LinearMap.trace 𝕜 E), ← ContinuousLinearMap.toLinearMap_sum, + ← ContinuousLinearMap.finsetSum_comp] + +end POVM diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceAbstract.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceAbstract.lean new file mode 100644 index 0000000000..1d9280bca1 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceAbstract.lean @@ -0,0 +1,1238 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# Abstract partial trace on a tensor product + +For finite-dim inner product spaces `E`, `F` over `RCLike 𝕜`, given an orthonormal basis +`b : OrthonormalBasis ι 𝕜 F` on the right factor, the partial trace over `F` of a linear +operator `T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F` is the operator `partialTraceRight b T : E →ₗ[𝕜] E` +defined by + + `partialTraceRight b T = ∑ k : ι, (rid ∘ map id (innerSL (b k))) ∘ₗ T ∘ₗ (· ⊗ₜ b k)` + +i.e. summing over the OB the composition of "embed-into-k-th-slice", `T`, and +"restrict-at-k-th-slice via inner product". + +Symmetric definition for the left factor. + +Basis-independence (the partial trace doesn't depend on the choice of OB) is established +via `partialTraceRight_eq_of_basis` (§2.37.P4.d.basis-indep). + +## Main definitions + +* `LinearMap.embedRight`, `LinearMap.restrictRight`: the basis-aware embed/restrict maps. +* `LinearMap.partialTraceRight`: partial trace over the right factor (basis-parametric). +* Symmetric `*Left` versions. + +## Main results + +* `LinearMap.partialTraceRight_apply`: point-applied form of `partialTraceRight`. +* `LinearMap.partialTraceRight_tensorMap`: the canonical identity + `partialTraceRight b (TensorProduct.map A B) = (LinearMap.trace 𝕜 _ B) • A` for an OB `b` on F. +* `LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight` (and the `…Left` analogue): + the trace-level partial-trace duality + `trace (map V id ∘ₗ T) = trace (V ∘ₗ partialTraceRight b T)`. +* `LinearMap.partialTraceRight_eq_of_basis` (and the `…Left` analogue): basis-independence of the + partial trace. +-/ + +@[expose] public section + +open scoped TensorProduct InnerProductSpace + +namespace LinearMap + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + +/-! ### Embed / restrict for the right factor -/ + +variable {ι₂ : Type*} [Fintype ι₂] + +/-- The "embed into the right factor at `b k`" map: `x ↦ x ⊗ₜ b k`. -/ +noncomputable def embedRight (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) : E →ₗ[𝕜] E ⊗[𝕜] F := + (TensorProduct.mk 𝕜 E F).flip (b k) + +@[simp] +theorem embedRight_apply (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) (x : E) : + embedRight b k x = x ⊗ₜ[𝕜] b k := rfl + +/-- The "restrict at the `b k` slot of the right factor" map: +`x ⊗ₜ y ↦ ⟨b k, y⟩_F • x`, extended linearly. -/ +noncomputable def restrictRight (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) : + E ⊗[𝕜] F →ₗ[𝕜] E := + (TensorProduct.rid 𝕜 E).toLinearMap ∘ₗ + TensorProduct.map LinearMap.id (innerSL 𝕜 (b k)).toLinearMap + +@[simp] +theorem restrictRight_tmul (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) (x : E) (y : F) : + restrictRight b k (x ⊗ₜ[𝕜] y) = ⟪b k, y⟫_𝕜 • x := rfl + +/-! ### Partial trace over the right factor -/ + +/-- The partial trace of `T : E ⊗ F →ₗ E ⊗ F` over the right factor, parametrized by an OB +on `F`. Defined as `∑ k, restrictRight b k ∘ₗ T ∘ₗ embedRight b k`. -/ +noncomputable def partialTraceRight (b : OrthonormalBasis ι₂ 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : E →ₗ[𝕜] E := + ∑ k : ι₂, restrictRight b k ∘ₗ T ∘ₗ embedRight b k + +theorem partialTraceRight_eq_sum (b : OrthonormalBasis ι₂ 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b T = ∑ k : ι₂, restrictRight b k ∘ₗ T ∘ₗ embedRight b k := + rfl + +theorem partialTraceRight_apply (b : OrthonormalBasis ι₂ 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) (x : E) : + partialTraceRight b T x = ∑ k : ι₂, restrictRight b k (T (x ⊗ₜ[𝕜] b k)) := by + simp [partialTraceRight_eq_sum, LinearMap.sum_apply, LinearMap.comp_apply] + +/-- **Headline identity**: the partial trace of `TensorProduct.map A B` over the right factor +equals `(trace B) • A`. -/ +theorem partialTraceRight_tensorMap + (b : OrthonormalBasis ι₂ 𝕜 F) (A : E →ₗ[𝕜] E) (B : F →ₗ[𝕜] F) : + partialTraceRight b (TensorProduct.map A B) = (LinearMap.trace 𝕜 _ B) • A := by + ext x + simp only [partialTraceRight_apply, TensorProduct.map_tmul, restrictRight_tmul, + LinearMap.smul_apply, ← Finset.sum_smul] + rw [← LinearMap.trace_eq_sum_inner B b] + +/-- **Partial trace of the identity** (right factor): tracing out `F` sends the identity on `E ⊗ F` +to `(dim F) • 1` on `E`. The `1 = 1 ⊗ 1` corollary of the headline `partialTraceRight_tensorMap` +(`Tr_F 1 = (tr 1_F) • 1_E = (dim F) • 1_E`, since `tr 1_F = dim F`). -/ +theorem partialTraceRight_one [FiniteDimensional 𝕜 F] (b : OrthonormalBasis ι₂ 𝕜 F) : + partialTraceRight b (1 : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) + = (Module.finrank 𝕜 F : 𝕜) • (1 : E →ₗ[𝕜] E) := by + rw [Module.End.one_eq_id, ← TensorProduct.map_id, partialTraceRight_tensorMap, + LinearMap.trace_id, ← Module.End.one_eq_id] + +/-- **Bundled `partialTraceRight` as a `LinearMap`**: the partial trace over the right +factor, viewed as a linear map `(E ⊗ F →ₗ E ⊗ F) →ₗ (E →ₗ E)`. Use to derive linearity-style +distribution lemmas (`map_sum`, `map_smul`, `map_sub`) as one-liners. -/ +noncomputable def partialTraceRightLM (b : OrthonormalBasis ι₂ 𝕜 F) : + (E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) →ₗ[𝕜] (E →ₗ[𝕜] E) where + toFun := partialTraceRight b + map_add' T₁ T₂ := by + simp only [partialTraceRight_eq_sum, LinearMap.add_comp, LinearMap.comp_add, + Finset.sum_add_distrib] + map_smul' c T := by + simp only [partialTraceRight_eq_sum, RingHom.id_apply, LinearMap.smul_comp, + LinearMap.comp_smul, Finset.smul_sum] + +@[simp] +theorem partialTraceRightLM_apply (b : OrthonormalBasis ι₂ 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRightLM b T = partialTraceRight b T := rfl + +/-- **`partialTraceRight` is compatible with scalar multiplication:** +`partialTraceRight b (c • T) = c • partialTraceRight b T`. The `map_smul` of the bundled +`partialTraceRightLM`. -/ +@[simp] +theorem partialTraceRight_smul (b : OrthonormalBasis ι₂ 𝕜 F) (c : 𝕜) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b (c • T) = c • partialTraceRight b T := by + rw [← partialTraceRightLM_apply, map_smul, partialTraceRightLM_apply] + +/-! ### Partial trace of `rankOne` on pure tensors -/ + +/-- **Partial-trace-of-rank-one-pure-tensor identity** (right slot, abstract): for any +pure-tensor inputs `a₁ ⊗ b₁` and `a₂ ⊗ b₂` in `E ⊗ F`, +`partialTraceRight b (rankOne (a₁ ⊗ b₁) (a₂ ⊗ b₂)) = ⟪b₂, b₁⟫ • rankOne a₁ a₂`. +The right-slot ket factor of the second tensor supplies the bra factor of the inner product, +collapsing the second tensor's right-slot information into a scalar weight on the abstract +rank-one on `E`. -/ +theorem partialTraceRight_rankOne_tmul (b : OrthonormalBasis ι₂ 𝕜 F) + (a₁ a₂ : E) (b₁ b₂ : F) : + partialTraceRight b ((InnerProductSpace.rankOne 𝕜 (a₁ ⊗ₜ[𝕜] b₁ : E ⊗[𝕜] F) + (a₂ ⊗ₜ[𝕜] b₂)).toLinearMap) = + ⟪b₂, b₁⟫_𝕜 • ((InnerProductSpace.rankOne 𝕜 a₁ a₂).toLinearMap : E →ₗ[𝕜] E) := by + refine LinearMap.ext fun x ↦ ?_ + simp only [partialTraceRight_apply, LinearMap.smul_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, + TensorProduct.inner_tmul, map_smul, restrictRight_tmul] + simp_rw [mul_smul, smul_smul, ← Finset.sum_smul, ← Finset.mul_sum] + rw [b.sum_inner_mul_inner b₂ b₁] + ring_nf + +/-- **Spectral form of the reduced density matrix from Schmidt decomposition** (abstract). +When the bipartite state `Ψ : E ⊗ F` has a Schmidt-form decomposition +`Ψ = ∑ σᵢ • (eᵢ ⊗ fᵢ)` with `f` orthonormal, the reduced density matrix is the diagonal +operator `∑ σᵢ² • rankOne eᵢ eᵢ`. Orthonormality of `f` collapses the off-diagonal +cross-terms; no orthogonality is required of `e`. -/ +theorem partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt (b : OrthonormalBasis ι₂ 𝕜 F) + {n : ℕ} {Ψ : E ⊗[𝕜] F} + (σs : Fin n → ℝ) (e : Fin n → E) (f : Fin n → F) + (hf : Orthonormal 𝕜 f) + (hΨ : Ψ = ∑ i, (σs i : 𝕜) • (e i ⊗ₜ[𝕜] f i)) : + partialTraceRight b ((InnerProductSpace.rankOne 𝕜 Ψ Ψ).toLinearMap) = + ∑ i, ((σs i : 𝕜) ^ 2) • + ((InnerProductSpace.rankOne 𝕜 (e i) (e i)).toLinearMap : E →ₗ[𝕜] E) := by + rw [hΨ, InnerProductSpace.rankOne_sum_smul_sum_smul] + simp_rw [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul, + RCLike.conj_ofReal, + ← partialTraceRightLM_apply b, map_sum, map_smul, partialTraceRightLM_apply, + partialTraceRight_rankOne_tmul] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + simp only [orthonormal_iff_ite.mp hf, smul_ite, smul_zero, ite_smul, zero_smul, one_smul] + rw [Finset.sum_ite_eq' Finset.univ i, ite_eq_left (Finset.mem_univ _), sq] + +/-! ### Embed/restrict resolution-of-identity and equivariance lemmas (right) -/ + +/-- **Delta-orthogonality**: `restrictRight b k ∘ embedRight b k' = if k = k' then id else 0`. -/ +theorem restrictRight_comp_embedRight [DecidableEq ι₂] + (b : OrthonormalBasis ι₂ 𝕜 F) (k k' : ι₂) : + (restrictRight b k : E ⊗[𝕜] F →ₗ[𝕜] E) ∘ₗ embedRight b k' = + if k = k' then LinearMap.id else 0 := by + ext x + simp only [LinearMap.comp_apply, embedRight_apply, restrictRight_tmul, b.inner_eq_ite] + split_ifs <;> simp + +/-- **Resolution of identity** (right slot): `∑ k, embedRight b k ∘ restrictRight b k = id`. +The key step is the OB completeness identity `∑ k, ⟪b k, y⟫ • b k = y`. -/ +theorem sum_embedRight_comp_restrictRight (b : OrthonormalBasis ι₂ 𝕜 F) : + ∑ k : ι₂, (embedRight b k : E →ₗ[𝕜] E ⊗[𝕜] F) ∘ₗ restrictRight b k = LinearMap.id := by + refine TensorProduct.ext' fun x y ↦ ?_ + simp only [LinearMap.sum_apply, LinearMap.comp_apply, restrictRight_tmul, embedRight_apply, + LinearMap.id_apply, TensorProduct.smul_tmul] + rw [← TensorProduct.tmul_sum] + congr 1 + simpa [b.repr_apply_apply] using b.sum_repr y + +/-- **Right-equivariance of restrict**: +`restrictRight b k ∘ tensorMap A id = A ∘ restrictRight b k`. Stated for a map `A : E →ₗ E'` that +may change the left space; the endomorphism case `E' = E` is the common instance. The proof is +space-agnostic (it goes through `restrictRight_tmul` / `map_tmul` only). -/ +theorem restrictRight_comp_tensorMap_id {E' : Type*} [NormedAddCommGroup E'] + [InnerProductSpace 𝕜 E'] (b : OrthonormalBasis ι₂ 𝕜 F) (A : E →ₗ[𝕜] E') (k : ι₂) : + (restrictRight b k : E' ⊗[𝕜] F →ₗ[𝕜] E') ∘ₗ TensorProduct.map A LinearMap.id = + A ∘ₗ (restrictRight b k : E ⊗[𝕜] F →ₗ[𝕜] E) := by + refine TensorProduct.ext' fun x y ↦ ?_ + simp [restrictRight_tmul, TensorProduct.map_tmul] + +/-- **Right-equivariance of embed**: `tensorMap A id ∘ embedRight b k = embedRight b k ∘ A`. -/ +theorem tensorMap_id_comp_embedRight (b : OrthonormalBasis ι₂ 𝕜 F) + (A : E →ₗ[𝕜] E) (k : ι₂) : + TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F) ∘ₗ + (embedRight b k : E →ₗ[𝕜] E ⊗[𝕜] F) = + embedRight b k ∘ₗ A := by + ext x + simp [embedRight_apply, TensorProduct.map_tmul] + +/-- **Left-action equivariance** (right partial trace): partial trace commutes with left +`tensorMap _ id` composition. -/ +theorem partialTraceRight_tensorMap_id_comp (b : OrthonormalBasis ι₂ 𝕜 F) + (A : E →ₗ[𝕜] E) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b (TensorProduct.map A LinearMap.id ∘ₗ T) = + A ∘ₗ partialTraceRight b T := by + refine LinearMap.ext fun x ↦ ?_ + rw [partialTraceRight_apply, LinearMap.comp_apply, partialTraceRight_apply, map_sum A] + exact Finset.sum_congr rfl fun k _ ↦ + LinearMap.congr_fun (restrictRight_comp_tensorMap_id b A k) (T (embedRight b k x)) + +/-- **Right-action equivariance** (right partial trace): partial trace commutes with right +`tensorMap _ id` composition. -/ +theorem partialTraceRight_comp_tensorMap_id (b : OrthonormalBasis ι₂ 𝕜 F) + (A : E →ₗ[𝕜] E) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b (T ∘ₗ TensorProduct.map A LinearMap.id) = + partialTraceRight b T ∘ₗ A := by + refine LinearMap.ext fun x ↦ ?_ + rw [partialTraceRight_apply, LinearMap.comp_apply, partialTraceRight_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + exact congrArg _ (congrArg T (LinearMap.congr_fun (tensorMap_id_comp_embedRight b A k) x)) + +/-! ### Norm and Pythagorean identities for embed/restrict (right) -/ + +/-- **Embed is norm-preserving** (right): `‖embedRight b k v‖ = ‖v‖`. Since `b k` is a unit +vector, `‖v ⊗ b k‖ = ‖v‖ ⋅ ‖b k‖ = ‖v‖`. -/ +theorem norm_embedRight (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) (v : E) : + ‖embedRight b k v‖ = ‖v‖ := by + have h_bk : ⟪b k, b k⟫_𝕜 = 1 := + inner_self_eq_norm_sq_to_K (𝕜 := 𝕜) (b k) ▸ by simp [b.orthonormal.norm_eq_one] + rw [@norm_eq_sqrt_re_inner 𝕜, embedRight_apply, TensorProduct.inner_tmul, + @norm_eq_sqrt_re_inner 𝕜, h_bk] + simp + +/-- **Embed inner-product delta** (right): the inner product of two `embedRight` images is +`⟪v, v'⟫` on-diagonal and `0` off-diagonal. -/ +theorem inner_embedRight_embedRight [DecidableEq ι₂] + (b : OrthonormalBasis ι₂ 𝕜 F) (k k' : ι₂) (v v' : E) : + ⟪embedRight b k v, embedRight b k' v'⟫_𝕜 = if k = k' then ⟪v, v'⟫_𝕜 else 0 := by + rw [embedRight_apply, embedRight_apply, TensorProduct.inner_tmul, b.inner_eq_ite] + split_ifs <;> simp + +/-- **Pythagorean identity for `embedRight` decompositions** (right): the squared norm of +a finite sum `∑ k, embedRight b k (a k)` is the sum of squared norms `∑ k, ‖a k‖²`. +Follows from `inner_embedRight_embedRight` together with `inner_self_eq_norm_sq`. -/ +theorem norm_sum_embedRight_sq (b : OrthonormalBasis ι₂ 𝕜 F) (a : ι₂ → E) : + ‖∑ k, embedRight b k (a k)‖ ^ 2 = ∑ k, ‖a k‖ ^ 2 := by + classical + rw [← @inner_self_eq_norm_sq 𝕜, sum_inner, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [inner_sum] + simp_rw [inner_embedRight_embedRight] + rw [Finset.sum_ite_eq _ _ (fun _ ↦ _), ite_eq_left (Finset.mem_univ k), inner_self_eq_norm_sq] + +/-- **Identity-decomposition via right-slot slicing** (apply form of +`sum_embedRight_comp_restrictRight`): every `w : E ⊗ F` decomposes as +`w = ∑ k, embedRight b k (restrictRight b k w)`. -/ +theorem sum_embedRight_restrictRight_eq_self (b : OrthonormalBasis ι₂ 𝕜 F) + (w : E ⊗[𝕜] F) : ∑ k : ι₂, embedRight b k (restrictRight b k w) = w := by + have := LinearMap.congr_fun (sum_embedRight_comp_restrictRight (𝕜 := 𝕜) (E := E) b) w + simpa [LinearMap.sum_apply, LinearMap.comp_apply] using this + +/-- **Norm-squared decomposition via right-slot Pythagorean**: +`‖w‖² = ∑ k, ‖restrictRight b k w‖²`. Combines +`sum_embedRight_restrictRight_eq_self` with `norm_sum_embedRight_sq`. -/ +theorem norm_sq_eq_sum_norm_restrictRight_sq (b : OrthonormalBasis ι₂ 𝕜 F) + (w : E ⊗[𝕜] F) : ‖w‖ ^ 2 = ∑ k, ‖restrictRight b k w‖ ^ 2 := by + conv_lhs => rw [← sum_embedRight_restrictRight_eq_self b w, norm_sum_embedRight_sq] + +/-- **`tensorMap A id` decomposes through right-slot embed/restrict**: +`(TensorProduct.map A id) w = ∑ k, embedRight b k (A (restrictRight b k w))`. +Direct consequence of `sum_embedRight_restrictRight_eq_self` + +`tensorMap_id_comp_embedRight`. -/ +theorem tensorMap_id_apply (b : OrthonormalBasis ι₂ 𝕜 F) + (A : E →ₗ[𝕜] E) (w : E ⊗[𝕜] F) : + (TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F)) w = + ∑ k, embedRight b k (A (restrictRight b k w)) := by + conv_lhs => rw [← sum_embedRight_restrictRight_eq_self b w, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + exact LinearMap.congr_fun (tensorMap_id_comp_embedRight b A k) (restrictRight b k w) + +/-! ### Operator-norm bound for `TensorProduct.map A id` (right slot) -/ + +/-- **Pointwise upper bound**: `‖(TensorProduct.map A id) w‖ ≤ ‖A.toCLM‖ ⋅ ‖w‖`. Uses the +right-slot Pythagorean decomposition (`tensorMap_id_apply` + `norm_sum_embedRight_sq`) +plus per-slot `ContinuousLinearMap.le_opNorm`, summed against +`norm_sq_eq_sum_norm_restrictRight_sq`. -/ +theorem norm_tensorMap_id_apply_le [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (A : E →ₗ[𝕜] E) (w : E ⊗[𝕜] F) : + ‖(TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F)) w‖ ≤ + ‖A.toContinuousLinearMap‖ * ‖w‖ := by + set b : OrthonormalBasis (Fin (Module.finrank 𝕜 F)) 𝕜 F := stdOrthonormalBasis 𝕜 F + rw [← pow_le_pow_iff_left₀ (norm_nonneg _) + (by positivity : (0 : ℝ) ≤ ‖A.toContinuousLinearMap‖ * ‖w‖) two_ne_zero, + tensorMap_id_apply b, norm_sum_embedRight_sq, mul_pow, + norm_sq_eq_sum_norm_restrictRight_sq b, Finset.mul_sum] + exact Finset.sum_le_sum fun k _ ↦ by + rw [← mul_pow]; gcongr; exact A.toContinuousLinearMap.le_opNorm _ + +/-- **Operator-norm bound**: `‖(TensorProduct.map A id).toCLM‖ ≤ ‖A.toCLM‖`. CLM-form of +`norm_tensorMap_id_apply_le` via `opNorm_le_bound`. -/ +theorem norm_tensorMap_id_le [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (A : E →ₗ[𝕜] E) : + ‖(TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F) : + E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).toContinuousLinearMap‖ ≤ + ‖A.toContinuousLinearMap‖ := + ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) (norm_tensorMap_id_apply_le A) + +/-- **Operator norm of `TensorProduct.map A id` equals operator norm of `A`** (right slot). +"Tensoring with identity on the right factor" is operator-norm preserving when `F` is +nontrivial. Upper bound is `norm_tensorMap_id_le`; lower bound takes the witness +`embedRight b k₀ ψ` for a default basis on `F` and an arbitrary unit `ψ`, using +`tensorMap_id_comp_embedRight` to commute the action across the embedding and +`norm_embedRight` to preserve norms. -/ +theorem norm_tensorMap_id [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [Nontrivial F] + (A : E →ₗ[𝕜] E) : + ‖(TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F) : + E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).toContinuousLinearMap‖ = + ‖A.toContinuousLinearMap‖ := by + set b_F := stdOrthonormalBasis 𝕜 F + have : Nonempty (Fin (Module.finrank 𝕜 F)) := + Fin.pos_iff_nonempty.mp Module.finrank_pos + set k₀ := Classical.arbitrary (Fin (Module.finrank 𝕜 F)) + set T := TensorProduct.map A (LinearMap.id : F →ₗ[𝕜] F) + refine le_antisymm (norm_tensorMap_id_le A) + (ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun ψ ↦ ?_) + have h_commute : T (embedRight b_F k₀ ψ) = embedRight b_F k₀ (A ψ) := + LinearMap.congr_fun (tensorMap_id_comp_embedRight b_F A k₀) ψ + calc ‖A.toContinuousLinearMap ψ‖ + = ‖T (embedRight b_F k₀ ψ)‖ := by + rw [LinearMap.coe_toContinuousLinearMap', h_commute, norm_embedRight] + _ ≤ ‖T.toContinuousLinearMap‖ * ‖ψ‖ := + (T.toContinuousLinearMap.le_opNorm _).trans_eq (by rw [norm_embedRight]) + +/-! ### Trace identity of the right partial trace -/ + +/-- **Trace identity**: the trace of `partialTraceRight b T` equals the trace of `T`. +Cyclically reduces the per-summand trace via `trace_comp_comm'` and assembles via the +resolution of identity `sum_embedRight_comp_restrictRight`. -/ +theorem trace_partialTraceRight [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (b : OrthonormalBasis ι₂ 𝕜 F) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + LinearMap.trace 𝕜 _ (partialTraceRight b T) = LinearMap.trace 𝕜 _ T := by + rw [partialTraceRight_eq_sum, map_sum] + simp_rw [← LinearMap.comp_assoc, + LinearMap.trace_comp_comm' (R := 𝕜) (embedRight b _) _, + ← LinearMap.comp_assoc] + rw [← map_sum] + congr 1 + refine LinearMap.ext fun x ↦ ?_ + simp only [LinearMap.sum_apply, LinearMap.comp_apply] + simpa using LinearMap.congr_fun (sum_embedRight_comp_restrictRight b) (T x) + +/-- **Abstract trace-level partial-trace duality.** For any `V` on the kept factor `E` +and any `T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F`, +`trace (TensorProduct.map V id ∘ₗ T) = trace (V ∘ₗ partialTraceRight b T)`, +where `b` is an orthonormal basis on the traced-out factor `F`. The defining duality of the partial +trace (`tr((V ⊗ 1) T) = tr(V · Tr_F T)`). + +Two-step proof: `← trace_partialTraceRight` lifts `trace X` to `trace (partialTraceRight X)`; +`partialTraceRight_tensorMap_id_comp` simplifies the inner partial trace to +`V ∘ partialTraceRight T`. -/ +theorem trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] (b : OrthonormalBasis ι₂ 𝕜 F) (V : E →ₗ[𝕜] E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + LinearMap.trace 𝕜 _ (TensorProduct.map V LinearMap.id ∘ₗ T) = + LinearMap.trace 𝕜 _ (V ∘ₗ partialTraceRight b T) := by + conv_lhs => rw [← trace_partialTraceRight b, partialTraceRight_tensorMap_id_comp] + +/-! ### Basis-independence of the right partial trace + +The right partial trace `partialTraceRight b T` does not depend +on the choice of orthonormal basis `b` on the traced-out factor. The proof goes via the +trace-pairing characterization: `trace (A ∘ₗ partialTraceRight b T) = trace (map A id ∘ₗ T)` +(from `partialTraceRight_tensorMap_id_comp` + `trace_partialTraceRight`), so every basis +choice gives the same trace pairing with every `A`, and non-degeneracy of the HS inner +product on `E →ₗ F` (`eq_zero_of_trace_adjoint_comp_self_eq_zero`) finishes. +-/ + +/-- **Basis-independence of the right partial trace**. For any two orthonormal bases on +the traced-out factor `F` (possibly with different index types), the partial trace of +`T : E ⊗ F →ₗ E ⊗ F` over the right factor is the same operator on `E`. + +Proof: the difference `Δ := partialTraceRight b T - partialTraceRight b' T` satisfies +`trace (Δ.adjoint ∘ₗ Δ) = 0`, since the duality identity +`trace (Δ.adjoint ∘ₗ partialTraceRight b'' T) = trace (map Δ.adjoint id ∘ₗ T)` +(via `partialTraceRight_tensorMap_id_comp` + `trace_partialTraceRight`) makes the trace +pairing basis-independent. Conclude `Δ = 0` via +`eq_zero_of_trace_adjoint_comp_self_eq_zero` (non-degeneracy of HS pairing). -/ +theorem partialTraceRight_eq_of_basis [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + {ι₂' : Type*} [Fintype ι₂'] + (b : OrthonormalBasis ι₂ 𝕜 F) (b' : OrthonormalBasis ι₂' 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b T = partialTraceRight b' T := by + refine sub_eq_zero.mp <| eq_zero_of_trace_adjoint_comp_self_eq_zero _ ?_ + set Δ := partialTraceRight b T - partialTraceRight b' T with hΔ + rw [hΔ, LinearMap.comp_sub, map_sub, sub_eq_zero, + (trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight b Δ.adjoint T).symm, + (trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight b' Δ.adjoint T).symm] + +/-! ### Naturality of the partial trace under a unitary on the traced factor -/ + +section ConjIsometry + +variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] + +/-- **The partial trace is invariant under conjugating the traced factor by a unitary.** For an +isometry `eF : F ≃ₗᵢ[𝕜] G` and orthonormal basis `b` of `F`, + + `Tr_G((I ⊗ eF) T (I ⊗ eF)†) = Tr_F T` + +(taken over the `eF`-image basis `b.map eF` of `G`). The `G`-marginal of the `F`-twirled operator +is the `F`-marginal of `T`; combined with `partialTraceRight_eq_of_basis` this transports a reduced +state across a change of the traced subsystem. -/ +theorem partialTraceRight_conjIsometry (b : OrthonormalBasis ι₂ 𝕜 F) (eF : F ≃ₗᵢ[𝕜] G) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight (b.map eF) (TensorProduct.map LinearMap.id eF.toLinearMap ∘ₗ T ∘ₗ + TensorProduct.map LinearMap.id eF.symm.toLinearMap) = partialTraceRight b T := by + ext x + rw [partialTraceRight_apply, partialTraceRight_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + have hmap : (TensorProduct.map LinearMap.id eF.symm.toLinearMap) (x ⊗ₜ[𝕜] (b.map eF) k) + = x ⊗ₜ[𝕜] b k := by simp [OrthonormalBasis.map_apply] + have hr : ∀ w : E ⊗[𝕜] F, + restrictRight (b.map eF) k ((TensorProduct.map LinearMap.id eF.toLinearMap) w) + = restrictRight b k w := fun w ↦ by + induction w using TensorProduct.inductionOn with + | tmul u v => simp [OrthonormalBasis.map_apply, eF.inner_map_map] + | add a c ha hc => simp [ha, hc] + rw [comp_apply, comp_apply, hmap, hr] + +/-- The `⋆`-algebra-equivalence form of `partialTraceRight_conjIsometry`: conjugating by the unitary +`I_E ⊗ eF` (as `conjStarAlgEquiv`) leaves the `E`-marginal unchanged, taken over the `eF`-image +basis of `G`. -/ +theorem partialTraceRight_conjStarAlgEquiv_congrIsometry [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] (b : OrthonormalBasis ι₂ 𝕜 F) + (eF : F ≃ₗᵢ[𝕜] G) (τ : (E ⊗[𝕜] F) →L[𝕜] (E ⊗[𝕜] F)) : + partialTraceRight (b.map eF) + ((TensorProduct.congrIsometry (.refl 𝕜 E) eF).conjStarAlgEquiv τ).toLinearMap = + partialTraceRight b τ.toLinearMap := by + have hcoe : ((TensorProduct.congrIsometry (.refl 𝕜 E) eF).conjStarAlgEquiv τ).toLinearMap = + TensorProduct.map LinearMap.id eF.toLinearMap ∘ₗ τ.toLinearMap ∘ₗ + TensorProduct.map LinearMap.id eF.symm.toLinearMap := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap, LinearEquiv.conj_apply, + TensorProduct.toLinearEquiv_congrIsometry] + simp only [TensorProduct.congr_symm, TensorProduct.toLinearMap_congr]; rfl + rw [hcoe, partialTraceRight_conjIsometry] + +end ConjIsometry + +/-! ### Embed / restrict / partial trace for the left factor -/ + +variable {ι₁ : Type*} [Fintype ι₁] + +/-- The "embed into the left factor at `b k`" map: `y ↦ b k ⊗ₜ y`. -/ +noncomputable def embedLeft (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) : F →ₗ[𝕜] E ⊗[𝕜] F := + TensorProduct.mk 𝕜 E F (b k) + +@[simp] +theorem embedLeft_apply (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) (y : F) : + embedLeft b k y = b k ⊗ₜ[𝕜] y := rfl + +/-- The "restrict at the `b k` slot of the left factor" map: +`x ⊗ₜ y ↦ ⟨b k, x⟩_E • y`, extended linearly. -/ +noncomputable def restrictLeft (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) : + E ⊗[𝕜] F →ₗ[𝕜] F := + (TensorProduct.lid 𝕜 F).toLinearMap ∘ₗ + TensorProduct.map (innerSL 𝕜 (b k)).toLinearMap LinearMap.id + +@[simp] +theorem restrictLeft_tmul (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) (x : E) (y : F) : + restrictLeft b k (x ⊗ₜ[𝕜] y) = ⟪b k, x⟫_𝕜 • y := rfl + +/-- The partial trace of `T : E ⊗ F →ₗ E ⊗ F` over the left factor, parametrized by an OB +on `E`. -/ +noncomputable def partialTraceLeft (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : F →ₗ[𝕜] F := + ∑ k : ι₁, restrictLeft b k ∘ₗ T ∘ₗ embedLeft b k + +theorem partialTraceLeft_eq_sum (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b T = ∑ k : ι₁, restrictLeft b k ∘ₗ T ∘ₗ embedLeft b k := + rfl + +theorem partialTraceLeft_apply (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) (y : F) : + partialTraceLeft b T y = ∑ k : ι₁, restrictLeft b k (T (b k ⊗ₜ[𝕜] y)) := by + simp [partialTraceLeft_eq_sum, LinearMap.sum_apply, LinearMap.comp_apply] + +/-- **Bundled `partialTraceLeft` as a `LinearMap`**: the partial trace over the left factor, +viewed as a linear map `(E ⊗ F →ₗ E ⊗ F) →ₗ (F →ₗ F)`. Use to derive linearity-style +distribution lemmas (`map_sum`, `map_smul`, `map_sub`) as one-liners. -/ +noncomputable def partialTraceLeftLM (b : OrthonormalBasis ι₁ 𝕜 E) : + (E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) →ₗ[𝕜] (F →ₗ[𝕜] F) where + toFun := partialTraceLeft b + map_add' T₁ T₂ := by + simp only [partialTraceLeft_eq_sum, LinearMap.add_comp, LinearMap.comp_add, + Finset.sum_add_distrib] + map_smul' c T := by + simp only [partialTraceLeft_eq_sum, RingHom.id_apply, LinearMap.smul_comp, + LinearMap.comp_smul, Finset.smul_sum] + +@[simp] +theorem partialTraceLeftLM_apply (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeftLM b T = partialTraceLeft b T := rfl + +/-- **`partialTraceLeft` is compatible with scalar multiplication:** +`partialTraceLeft b (c • T) = c • partialTraceLeft b T`. The `map_smul` of the bundled +`partialTraceLeftLM`; mirror of `partialTraceRight_smul`. -/ +@[simp] +theorem partialTraceLeft_smul (b : OrthonormalBasis ι₁ 𝕜 E) (c : 𝕜) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b (c • T) = c • partialTraceLeft b T := by + rw [← partialTraceLeftLM_apply, map_smul, partialTraceLeftLM_apply] + +/-- **Partial-trace-of-rank-one-pure-tensor identity** (left slot, abstract): for any +pure-tensor inputs `a₁ ⊗ b₁` and `a₂ ⊗ b₂` in `E ⊗ F`, +`partialTraceLeft b (rankOne (a₁ ⊗ b₁) (a₂ ⊗ b₂)) = ⟪a₂, a₁⟫ • rankOne b₁ b₂`. +The left-slot ket factor of the second tensor supplies the bra factor of the inner product, +collapsing the second tensor's left-slot information into a scalar weight on the abstract +rank-one on `F`. -/ +theorem partialTraceLeft_rankOne_tmul (b : OrthonormalBasis ι₁ 𝕜 E) + (a₁ a₂ : E) (b₁ b₂ : F) : + partialTraceLeft b ((InnerProductSpace.rankOne 𝕜 (a₁ ⊗ₜ[𝕜] b₁ : E ⊗[𝕜] F) + (a₂ ⊗ₜ[𝕜] b₂)).toLinearMap) = + ⟪a₂, a₁⟫_𝕜 • ((InnerProductSpace.rankOne 𝕜 b₁ b₂).toLinearMap : F →ₗ[𝕜] F) := by + refine LinearMap.ext fun y ↦ ?_ + simp only [partialTraceLeft_apply, LinearMap.smul_apply, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, + TensorProduct.inner_tmul, map_smul, restrictLeft_tmul] + simp_rw [mul_smul, smul_smul] + rw [← Finset.sum_smul] + congr 2 + rw [← b.sum_inner_mul_inner a₂ a₁, Finset.sum_mul] + exact Finset.sum_congr rfl fun k _ ↦ by ring + +/-- **Spectral form of the reduced density matrix from Schmidt decomposition** (abstract, +left slot). When the bipartite state `Ψ : E ⊗ F` has a Schmidt-form decomposition +`Ψ = ∑ σᵢ • (eᵢ ⊗ fᵢ)`, the partial trace over the *left* factor is the diagonal operator +`∑ σᵢ² • rankOne fᵢ fᵢ` on `F`. Only orthonormality of `e` *on the support* `{i | σᵢ ≠ 0}` is +needed — off-support cross-terms vanish through the singular-value weights; no orthogonality is +required of `f`. Left-slot analog of `partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt` +(which is stated with full orthonormality of `f`). -/ +theorem partialTraceLeft_rankOne_eq_sum_rankOne_of_schmidt (b : OrthonormalBasis ι₁ 𝕜 E) + {n : ℕ} {Ψ : E ⊗[𝕜] F} + (σs : Fin n → ℝ) (e : Fin n → E) (f : Fin n → F) + (he : ∀ i j, σs i ≠ 0 → σs j ≠ 0 → ⟪e i, e j⟫_𝕜 = if i = j then 1 else 0) + (hΨ : Ψ = ∑ i, (σs i : 𝕜) • (e i ⊗ₜ[𝕜] f i)) : + partialTraceLeft b ((InnerProductSpace.rankOne 𝕜 Ψ Ψ).toLinearMap) = + ∑ i, ((σs i : 𝕜) ^ 2) • + ((InnerProductSpace.rankOne 𝕜 (f i) (f i)).toLinearMap : F →ₗ[𝕜] F) := by + classical + rw [hΨ, InnerProductSpace.rankOne_sum_smul_sum_smul] + simp_rw [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul, + RCLike.conj_ofReal, + ← partialTraceLeftLM_apply b, map_sum, map_smul, partialTraceLeftLM_apply, + partialTraceLeft_rankOne_tmul] + refine Finset.sum_congr rfl fun i _ ↦ + (Finset.sum_eq_single i (fun j _ hji ↦ ?_) (by simp)).trans ?_ + · -- Off-diagonal `j ≠ i` term vanishes: either a zero singular value, or `⟪eⱼ, eᵢ⟫ = 0`. + rcases eq_or_ne (σs i) 0 with hi | hi + · simp [hi] + · rcases eq_or_ne (σs j) 0 with hj | hj + · simp [hj] + · rw [he j i hj hi, ite_eq_right hji]; simp + · -- Diagonal term: `(σᵢ * σᵢ) • ⟪eᵢ, eᵢ⟫ • rankOne fᵢ fᵢ = σᵢ² • rankOne fᵢ fᵢ`. + rcases eq_or_ne (σs i) 0 with hi | hi + · simp [hi, zero_pow two_ne_zero] + · rw [he i i hi hi, ite_eq_left rfl, smul_smul, mul_one, ← sq] + +/-- **Partial trace of a non-orthogonal bipartite sum** (left slot, abstract). For a bipartite +vector `Ψ = ∑ᵢ cᵢ • (aᵢ ⊗ fᵢ)` — with **no** orthogonality assumed on either family `a` or `f` — +the partial trace over the left factor of `|Ψ⟩⟨Ψ|` is the double sum + +`partialTraceLeft b |Ψ⟩⟨Ψ| = ∑ᵢ ∑ⱼ (cᵢ · conj cⱼ · ⟪aⱼ, aᵢ⟫) • |fᵢ⟩⟨fⱼ|`, + +the **Gram operator** of the right-factor vectors `f` weighted by the left-factor overlaps +`⟪aⱼ, aᵢ⟫`. Off-diagonal cross terms survive precisely because `a` is not orthonormal — the +general form behind `partialTraceLeft_rankOne_eq_sum_rankOne_of_schmidt`, which recovers the +diagonal single sum when `a` is orthonormal on its support. -/ +theorem partialTraceLeft_rankOne_sum_smul_tmul (b : OrthonormalBasis ι₁ 𝕜 E) + {ι : Type*} [Fintype ι] (c : ι → 𝕜) (a : ι → E) (f : ι → F) {Ψ : E ⊗[𝕜] F} + (hΨ : Ψ = ∑ i, c i • (a i ⊗ₜ[𝕜] f i)) : + partialTraceLeft b ((InnerProductSpace.rankOne 𝕜 Ψ Ψ).toLinearMap) = + ∑ i, ∑ j, (c i * starRingEnd 𝕜 (c j) * ⟪a j, a i⟫_𝕜) • + ((InnerProductSpace.rankOne 𝕜 (f i) (f j)).toLinearMap : F →ₗ[𝕜] F) := by + rw [hΨ, InnerProductSpace.rankOne_sum_smul_sum_smul] + simp_rw [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul, + ← partialTraceLeftLM_apply b, map_sum, map_smul, partialTraceLeftLM_apply, + partialTraceLeft_rankOne_tmul, smul_smul] + +/-- **Headline identity** (left): the partial trace of `TensorProduct.map A B` over the left +factor equals `(trace A) • B`. -/ +theorem partialTraceLeft_tensorMap + (b : OrthonormalBasis ι₁ 𝕜 E) (A : E →ₗ[𝕜] E) (B : F →ₗ[𝕜] F) : + partialTraceLeft b (TensorProduct.map A B) = (LinearMap.trace 𝕜 _ A) • B := by + ext y + simp only [partialTraceLeft_apply, TensorProduct.map_tmul, restrictLeft_tmul, + LinearMap.smul_apply, ← Finset.sum_smul] + rw [← LinearMap.trace_eq_sum_inner A b] + +/-! ### Embed/restrict resolution-of-identity and equivariance lemmas (left) -/ + +/-- **Delta-orthogonality** (left): +`restrictLeft b k ∘ embedLeft b k' = if k = k' then id else 0`. -/ +theorem restrictLeft_comp_embedLeft [DecidableEq ι₁] + (b : OrthonormalBasis ι₁ 𝕜 E) (k k' : ι₁) : + (restrictLeft b k : E ⊗[𝕜] F →ₗ[𝕜] F) ∘ₗ embedLeft b k' = + if k = k' then LinearMap.id else 0 := by + ext y + simp only [LinearMap.comp_apply, embedLeft_apply, restrictLeft_tmul, b.inner_eq_ite] + split_ifs <;> simp + +/-- **Resolution of identity** (left slot): `∑ k, embedLeft b k ∘ restrictLeft b k = id`. -/ +theorem sum_embedLeft_comp_restrictLeft (b : OrthonormalBasis ι₁ 𝕜 E) : + ∑ k : ι₁, (embedLeft b k : F →ₗ[𝕜] E ⊗[𝕜] F) ∘ₗ restrictLeft b k = LinearMap.id := by + refine TensorProduct.ext' fun x y ↦ ?_ + simp only [LinearMap.sum_apply, LinearMap.comp_apply, restrictLeft_tmul, embedLeft_apply, + LinearMap.id_apply] + simp_rw [← TensorProduct.smul_tmul, ← TensorProduct.sum_tmul] + congr 1 + simpa [b.repr_apply_apply] using b.sum_repr x + +/-- **Left-equivariance of restrict** (left partial trace): +`restrictLeft b k ∘ tensorMap id B = B ∘ restrictLeft b k`. -/ +theorem restrictLeft_comp_tensorMap_id (b : OrthonormalBasis ι₁ 𝕜 E) + (B : F →ₗ[𝕜] F) (k : ι₁) : + (restrictLeft b k : E ⊗[𝕜] F →ₗ[𝕜] F) ∘ₗ TensorProduct.map LinearMap.id B = + B ∘ₗ restrictLeft b k := by + refine TensorProduct.ext' fun x y ↦ ?_ + simp [restrictLeft_tmul, TensorProduct.map_tmul] + +/-- **Left-equivariance of embed** (left partial trace): +`tensorMap id B ∘ embedLeft b k = embedLeft b k ∘ B`. -/ +theorem tensorMap_id_comp_embedLeft (b : OrthonormalBasis ι₁ 𝕜 E) + (B : F →ₗ[𝕜] F) (k : ι₁) : + TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B ∘ₗ + (embedLeft b k : F →ₗ[𝕜] E ⊗[𝕜] F) = + embedLeft b k ∘ₗ B := by + ext y + simp [embedLeft_apply, TensorProduct.map_tmul] + +/-- **Right-action equivariance** (left partial trace): partial trace commutes with right +`tensorMap id _` composition. -/ +theorem partialTraceLeft_tensorMap_id_comp (b : OrthonormalBasis ι₁ 𝕜 E) + (B : F →ₗ[𝕜] F) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b (TensorProduct.map LinearMap.id B ∘ₗ T) = + B ∘ₗ partialTraceLeft b T := by + refine LinearMap.ext fun y ↦ ?_ + rw [partialTraceLeft_apply, LinearMap.comp_apply, partialTraceLeft_apply, map_sum B] + exact Finset.sum_congr rfl fun k _ ↦ + LinearMap.congr_fun (restrictLeft_comp_tensorMap_id b B k) (T (embedLeft b k y)) + +/-- **Left-action equivariance** (left partial trace): partial trace commutes with left +`tensorMap id _` composition. -/ +theorem partialTraceLeft_comp_tensorMap_id (b : OrthonormalBasis ι₁ 𝕜 E) + (B : F →ₗ[𝕜] F) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b (T ∘ₗ TensorProduct.map LinearMap.id B) = + partialTraceLeft b T ∘ₗ B := by + refine LinearMap.ext fun y ↦ ?_ + rw [partialTraceLeft_apply, LinearMap.comp_apply, partialTraceLeft_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + exact congrArg _ (congrArg T (LinearMap.congr_fun (tensorMap_id_comp_embedLeft b B k) y)) + +/-! ### Norm and Pythagorean identities for embed/restrict (left) -/ + +/-- **Embed is norm-preserving** (left): `‖embedLeft b k v‖ = ‖v‖`. -/ +theorem norm_embedLeft (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) (v : F) : + ‖embedLeft b k v‖ = ‖v‖ := by + have h_bk : ⟪b k, b k⟫_𝕜 = 1 := + inner_self_eq_norm_sq_to_K (𝕜 := 𝕜) (b k) ▸ by simp [b.orthonormal.norm_eq_one] + rw [@norm_eq_sqrt_re_inner 𝕜, embedLeft_apply, TensorProduct.inner_tmul, + @norm_eq_sqrt_re_inner 𝕜, h_bk] + simp + +/-- **Embed inner-product delta** (left): the inner product of two `embedLeft` images is +`⟪v, v'⟫` on-diagonal and `0` off-diagonal. -/ +theorem inner_embedLeft_embedLeft [DecidableEq ι₁] + (b : OrthonormalBasis ι₁ 𝕜 E) (k k' : ι₁) (v v' : F) : + ⟪embedLeft b k v, embedLeft b k' v'⟫_𝕜 = if k = k' then ⟪v, v'⟫_𝕜 else 0 := by + rw [embedLeft_apply, embedLeft_apply, TensorProduct.inner_tmul, b.inner_eq_ite] + split_ifs <;> simp + +/-- **Pythagorean identity for `embedLeft` decompositions** (left). -/ +theorem norm_sum_embedLeft_sq (b : OrthonormalBasis ι₁ 𝕜 E) (a : ι₁ → F) : + ‖∑ k, embedLeft b k (a k)‖ ^ 2 = ∑ k, ‖a k‖ ^ 2 := by + classical + rw [← @inner_self_eq_norm_sq 𝕜, sum_inner, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [inner_sum] + simp_rw [inner_embedLeft_embedLeft] + rw [Finset.sum_ite_eq _ _ (fun _ ↦ _), ite_eq_left (Finset.mem_univ k), inner_self_eq_norm_sq] + +/-- **Identity-decomposition via left-slot slicing** (apply form of +`sum_embedLeft_comp_restrictLeft`). -/ +theorem sum_embedLeft_restrictLeft_eq_self (b : OrthonormalBasis ι₁ 𝕜 E) + (w : E ⊗[𝕜] F) : ∑ k : ι₁, embedLeft b k (restrictLeft b k w) = w := by + have := LinearMap.congr_fun (sum_embedLeft_comp_restrictLeft (𝕜 := 𝕜) (F := F) b) w + simpa [LinearMap.sum_apply, LinearMap.comp_apply] using this + +/-- **Norm-squared decomposition via left-slot Pythagorean**. -/ +theorem norm_sq_eq_sum_norm_restrictLeft_sq (b : OrthonormalBasis ι₁ 𝕜 E) + (w : E ⊗[𝕜] F) : ‖w‖ ^ 2 = ∑ k, ‖restrictLeft b k w‖ ^ 2 := by + conv_lhs => rw [← sum_embedLeft_restrictLeft_eq_self b w, norm_sum_embedLeft_sq] + +/-- **`tensorMap id B` decomposes through left-slot embed/restrict** (left). -/ +theorem tensorMap_id_apply_left (b : OrthonormalBasis ι₁ 𝕜 E) + (B : F →ₗ[𝕜] F) (w : E ⊗[𝕜] F) : + (TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B) w = + ∑ k, embedLeft b k (B (restrictLeft b k w)) := by + conv_lhs => rw [← sum_embedLeft_restrictLeft_eq_self b w, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + exact LinearMap.congr_fun (tensorMap_id_comp_embedLeft b B k) (restrictLeft b k w) + +/-! ### Operator-norm bound for `TensorProduct.map id B` (left slot) -/ + +/-- **Pointwise upper bound** (left): `‖(TensorProduct.map id B) w‖ ≤ ‖B.toCLM‖ ⋅ ‖w‖`. -/ +theorem norm_tensorMap_id_left_apply_le [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (B : F →ₗ[𝕜] F) (w : E ⊗[𝕜] F) : + ‖(TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B) w‖ ≤ + ‖B.toContinuousLinearMap‖ * ‖w‖ := by + set b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E := stdOrthonormalBasis 𝕜 E + rw [← pow_le_pow_iff_left₀ (norm_nonneg _) + (by positivity : (0 : ℝ) ≤ ‖B.toContinuousLinearMap‖ * ‖w‖) two_ne_zero, + tensorMap_id_apply_left b, norm_sum_embedLeft_sq, mul_pow, + norm_sq_eq_sum_norm_restrictLeft_sq b, Finset.mul_sum] + exact Finset.sum_le_sum fun k _ ↦ by + rw [← mul_pow]; gcongr; exact B.toContinuousLinearMap.le_opNorm _ + +/-- **Operator-norm bound** (left): `‖(TensorProduct.map id B).toCLM‖ ≤ ‖B.toCLM‖`. -/ +theorem norm_tensorMap_id_left_le [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (B : F →ₗ[𝕜] F) : + ‖(TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B : + E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).toContinuousLinearMap‖ ≤ + ‖B.toContinuousLinearMap‖ := + ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) (norm_tensorMap_id_left_apply_le B) + +/-- **Operator norm of `TensorProduct.map id B` equals operator norm of `B`** (left slot, +under `[Nontrivial E]`). -/ +theorem norm_tensorMap_id_left [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [Nontrivial E] + (B : F →ₗ[𝕜] F) : + ‖(TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B : + E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).toContinuousLinearMap‖ = + ‖B.toContinuousLinearMap‖ := by + set b_E := stdOrthonormalBasis 𝕜 E + have : Nonempty (Fin (Module.finrank 𝕜 E)) := + Fin.pos_iff_nonempty.mp Module.finrank_pos + set k₀ := Classical.arbitrary (Fin (Module.finrank 𝕜 E)) + set T := TensorProduct.map (LinearMap.id : E →ₗ[𝕜] E) B + refine le_antisymm (norm_tensorMap_id_left_le B) + (ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun ψ ↦ ?_) + have h_commute : T (embedLeft b_E k₀ ψ) = embedLeft b_E k₀ (B ψ) := + LinearMap.congr_fun (tensorMap_id_comp_embedLeft b_E B k₀) ψ + calc ‖B.toContinuousLinearMap ψ‖ + = ‖T (embedLeft b_E k₀ ψ)‖ := by + rw [LinearMap.coe_toContinuousLinearMap', h_commute, norm_embedLeft] + _ ≤ ‖T.toContinuousLinearMap‖ * ‖ψ‖ := + (T.toContinuousLinearMap.le_opNorm _).trans_eq (by rw [norm_embedLeft]) + +/-! ### Trace identity of the left partial trace -/ + +/-- **Trace identity** (left): the trace of `partialTraceLeft b T` equals the trace of `T`. -/ +theorem trace_partialTraceLeft [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (b : OrthonormalBasis ι₁ 𝕜 E) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + LinearMap.trace 𝕜 _ (partialTraceLeft b T) = LinearMap.trace 𝕜 _ T := by + rw [partialTraceLeft_eq_sum, map_sum] + simp_rw [← LinearMap.comp_assoc, + LinearMap.trace_comp_comm' (R := 𝕜) (embedLeft b _) _, + ← LinearMap.comp_assoc] + rw [← map_sum] + congr 1 + refine LinearMap.ext fun y ↦ ?_ + simp only [LinearMap.sum_apply, LinearMap.comp_apply] + simpa using LinearMap.congr_fun (sum_embedLeft_comp_restrictLeft b) (T y) + +/-- **Abstract trace-level partial-trace duality (left).** Symmetric to +`trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight`: +`trace (TensorProduct.map id V ∘ₗ T) = trace (V ∘ₗ partialTraceLeft b T)`, +parametric in `b : OrthonormalBasis ι 𝕜 E` on the traced-out left factor. -/ +theorem trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] (b : OrthonormalBasis ι₁ 𝕜 E) (V : F →ₗ[𝕜] F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + LinearMap.trace 𝕜 _ (TensorProduct.map LinearMap.id V ∘ₗ T) = + LinearMap.trace 𝕜 _ (V ∘ₗ partialTraceLeft b T) := by + conv_lhs => rw [← trace_partialTraceLeft b, partialTraceLeft_tensorMap_id_comp] + +/-- **Basis-independence of the left partial trace**. Symmetric to +`partialTraceRight_eq_of_basis`: any two orthonormal bases on the traced-out left factor +(possibly with different index types) yield the same partial trace. -/ +theorem partialTraceLeft_eq_of_basis [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + {ι₁' : Type*} [Fintype ι₁'] + (b : OrthonormalBasis ι₁ 𝕜 E) (b' : OrthonormalBasis ι₁' 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b T = partialTraceLeft b' T := by + refine sub_eq_zero.mp <| eq_zero_of_trace_adjoint_comp_self_eq_zero _ ?_ + set Δ := partialTraceLeft b T - partialTraceLeft b' T with hΔ + rw [hΔ, LinearMap.comp_sub, map_sub, sub_eq_zero, + (trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft b Δ.adjoint T).symm, + (trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft b' Δ.adjoint T).symm] + +/-! ### Adjoint identities for embed/restrict -/ + +section Adjoint + +variable [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + +/-- **Adjoint of right-embed**: `(embedRight b k).adjoint = restrictRight b k`. -/ +theorem adjoint_embedRight (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) : + LinearMap.adjoint (embedRight b k : E →ₗ[𝕜] E ⊗[𝕜] F) = restrictRight b k := by + rw [eq_comm, LinearMap.eq_adjoint_iff] + intro v u + refine v.inductionOn ?_ ?_ + · intro x y + simp [embedRight_apply, restrictRight_tmul, TensorProduct.inner_tmul, inner_smul_left, + mul_comm] + · intro a b ha hb + simp [inner_add_left, map_add, ha, hb] + +/-- **Adjoint of right-restrict**: `(restrictRight b k).adjoint = embedRight b k`. -/ +theorem adjoint_restrictRight (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) : + LinearMap.adjoint (restrictRight b k : E ⊗[𝕜] F →ₗ[𝕜] E) = embedRight b k := by + rw [← adjoint_embedRight, LinearMap.adjoint_adjoint] + +/-- **Adjoint of left-embed**: `(embedLeft b k).adjoint = restrictLeft b k`. -/ +theorem adjoint_embedLeft (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) : + LinearMap.adjoint (embedLeft b k : F →ₗ[𝕜] E ⊗[𝕜] F) = restrictLeft b k := by + rw [eq_comm, LinearMap.eq_adjoint_iff] + intro v u + refine v.inductionOn ?_ ?_ + · intro x y + simp [embedLeft_apply, restrictLeft_tmul, TensorProduct.inner_tmul, inner_smul_left] + · intro a b ha hb + simp [inner_add_left, map_add, ha, hb] + +/-- **Adjoint of left-restrict**: `(restrictLeft b k).adjoint = embedLeft b k`. -/ +theorem adjoint_restrictLeft (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) : + LinearMap.adjoint (restrictLeft b k : E ⊗[𝕜] F →ₗ[𝕜] F) = embedLeft b k := by + rw [← adjoint_embedLeft, LinearMap.adjoint_adjoint] + +/-! ### Self-adjointness and positivity transfer through partial trace -/ + +/-- **Self-adjointness transfer** (right): if `T` is self-adjoint, so is `partialTraceRight b T`. -/ +theorem partialTraceRight_isSelfAdjoint (b : OrthonormalBasis ι₂ 𝕜 F) + {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : IsSelfAdjoint T) : + IsSelfAdjoint (partialTraceRight b T) := by + rw [isSelfAdjoint_iff, LinearMap.star_eq_adjoint, partialTraceRight_eq_sum, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + simp only [LinearMap.adjoint_comp, adjoint_restrictRight, adjoint_embedRight] + rw [← LinearMap.star_eq_adjoint, hT.star_eq, LinearMap.comp_assoc] + +/-- **Self-adjointness transfer** (left): if `T` is self-adjoint, so is `partialTraceLeft b T`. -/ +theorem partialTraceLeft_isSelfAdjoint (b : OrthonormalBasis ι₁ 𝕜 E) + {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : IsSelfAdjoint T) : + IsSelfAdjoint (partialTraceLeft b T) := by + rw [isSelfAdjoint_iff, LinearMap.star_eq_adjoint, partialTraceLeft_eq_sum, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + simp only [LinearMap.adjoint_comp, adjoint_restrictLeft, adjoint_embedLeft] + rw [← LinearMap.star_eq_adjoint, hT.star_eq, LinearMap.comp_assoc] + +/-- **Positivity transfer** (right): if `T` is positive, so is `partialTraceRight b T`. -/ +theorem partialTraceRight_isPositive (b : OrthonormalBasis ι₂ 𝕜 F) + {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : T.IsPositive) : + (partialTraceRight b T).IsPositive := by + rw [partialTraceRight_eq_sum] + apply LinearMap.isPositive_sum + intro k _ + rw [← adjoint_embedRight] + exact hT.adjoint_conj _ + +/-- **Positivity transfer** (left): if `T` is positive, so is `partialTraceLeft b T`. -/ +theorem partialTraceLeft_isPositive (b : OrthonormalBasis ι₁ 𝕜 E) + {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : T.IsPositive) : + (partialTraceLeft b T).IsPositive := by + rw [partialTraceLeft_eq_sum] + apply LinearMap.isPositive_sum + intro k _ + rw [← adjoint_embedLeft] + exact hT.adjoint_conj _ + +/-- **Quadratic form of the right partial trace** as a sum of slice quadratic forms: +`⟪x, (Tr_F T) x⟫ = ∑ k, ⟪x ⊗ b k, T (x ⊗ b k)⟫`. The `E`-marginal pairs `x` against the +`b k`-slices of `T`. -/ +theorem inner_partialTraceRight_self (b : OrthonormalBasis ι₂ 𝕜 F) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) (x : E) : + ⟪x, partialTraceRight b T x⟫_𝕜 = ∑ k, ⟪x ⊗ₜ[𝕜] b k, T (x ⊗ₜ[𝕜] b k)⟫_𝕜 := by + rw [partialTraceRight_apply, inner_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [← adjoint_embedRight b k, LinearMap.adjoint_inner_right, embedRight_apply] + +/-- **Quadratic form of the left partial trace** as a sum of slice quadratic forms: +`⟪y, (Tr_E T) y⟫ = ∑ k, ⟪b k ⊗ y, T (b k ⊗ y)⟫`. -/ +theorem inner_partialTraceLeft_self (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) (y : F) : + ⟪y, partialTraceLeft b T y⟫_𝕜 = ∑ k, ⟪b k ⊗ₜ[𝕜] y, T (b k ⊗ₜ[𝕜] y)⟫_𝕜 := by + rw [partialTraceLeft_apply, inner_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [← adjoint_embedLeft b k, LinearMap.adjoint_inner_right, embedLeft_apply] + +/-- **Marginal-support vanishing** (right): for a positive `T`, if the `E`-marginal quadratic form +vanishes at `x` (`⟪x, (Tr_F T) x⟫ = 0`), then every slice `⟪x ⊗ b k, T (x ⊗ b k)⟫` has zero real +part. Each slice is a nonnegative summand of the marginal form (`inner_partialTraceRight_self`), so +a zero marginal form forces every slice to vanish — `x ∈ ker(Tr_F T)` puts `x ⊗ ·` in the kernel of +`T`'s quadratic form. -/ +theorem IsPositive.re_inner_tmul_eq_zero_of_inner_partialTraceRight_eq_zero + (b : OrthonormalBasis ι₂ 𝕜 F) {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : T.IsPositive) + {x : E} (hx : ⟪x, partialTraceRight b T x⟫_𝕜 = 0) (k : ι₂) : + RCLike.re ⟪x ⊗ₜ[𝕜] b k, T (x ⊗ₜ[𝕜] b k)⟫_𝕜 = 0 := by + have hsum : ∑ k, RCLike.re ⟪x ⊗ₜ[𝕜] b k, T (x ⊗ₜ[𝕜] b k)⟫_𝕜 = 0 := by + rw [← map_sum, ← inner_partialTraceRight_self b T x, hx, map_zero] + exact (Finset.sum_eq_zero_iff_of_nonneg fun k _ ↦ hT.re_inner_nonneg_right _).mp hsum k + (Finset.mem_univ k) + +/-- **Marginal-support vanishing** (left): for a positive `T`, if the `F`-marginal quadratic form +vanishes at `y` (`⟪y, (Tr_E T) y⟫ = 0`), then every slice `⟪b k ⊗ y, T (b k ⊗ y)⟫` has zero real +part. (Left analog of `IsPositive.re_inner_tmul_eq_zero_of_inner_partialTraceRight_eq_zero`.) -/ +theorem IsPositive.re_inner_tmul_eq_zero_of_inner_partialTraceLeft_eq_zero + (b : OrthonormalBasis ι₁ 𝕜 E) {T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F} (hT : T.IsPositive) + {y : F} (hy : ⟪y, partialTraceLeft b T y⟫_𝕜 = 0) (k : ι₁) : + RCLike.re ⟪b k ⊗ₜ[𝕜] y, T (b k ⊗ₜ[𝕜] y)⟫_𝕜 = 0 := by + have hsum : ∑ k, RCLike.re ⟪b k ⊗ₜ[𝕜] y, T (b k ⊗ₜ[𝕜] y)⟫_𝕜 = 0 := by + rw [← map_sum, ← inner_partialTraceLeft_self b T y, hy, map_zero] + exact (Finset.sum_eq_zero_iff_of_nonneg fun k _ ↦ hT.re_inner_nonneg_right _).mp hsum k + (Finset.mem_univ k) + +end Adjoint + +/-! ### Partial-trace tower under re-association + +For a tripartite operator on `E ⊗ (F ⊗ G)`, tracing out a composite factor (`F ⊗ G`) or the inner +factor (`G`) reduces to iterated single-factor partial traces after re-associating via +`TensorProduct.assoc`. These are the structural lemmas behind strong subadditivity, where the same +`E`-marginal / `F`-marginal must be read off from two different groupings of the three subsystems. + +Throughout, `(TensorProduct.assoc 𝕜 E F G).symm.conj T` is the operator on `(E ⊗ F) ⊗ G` obtained by +re-associating `T : E ⊗ (F ⊗ G) →ₗ E ⊗ (F ⊗ G)`. -/ + +section Tower + +variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] + {ιE ιF ιG : Type*} [Fintype ιE] [Fintype ιF] [Fintype ιG] + +/-- The associator-conjugation `(assoc.symm.conj T)` acts on a pure tensor by re-associating: +`(assoc.symm.conj T) ((x ⊗ y) ⊗ z) = assoc.symm (T (x ⊗ (y ⊗ z)))`. -/ +theorem conj_assoc_symm_tmul (T : E ⊗[𝕜] (F ⊗[𝕜] G) →ₗ[𝕜] E ⊗[𝕜] (F ⊗[𝕜] G)) + (x : E) (y : F) (z : G) : + (TensorProduct.assoc 𝕜 E F G).symm.conj T ((x ⊗ₜ[𝕜] y) ⊗ₜ[𝕜] z) = + (TensorProduct.assoc 𝕜 E F G).symm (T (x ⊗ₜ[𝕜] (y ⊗ₜ[𝕜] z))) := by + rw [LinearEquiv.conj_apply, LinearEquiv.symm_symm] + simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, TensorProduct.assoc_tmul] + +/-- `restrictRight` over the composite factor `F ⊗ G` factors as iterated `restrictRight`s after +re-association: pairing out the `bF j ⊗ bG k` slot equals pairing out `bG k` then `bF j`. -/ +private theorem restrictRight_restrictRight_assoc_symm (bF : OrthonormalBasis ιF 𝕜 F) + (bG : OrthonormalBasis ιG 𝕜 G) (j : ιF) (k : ιG) (w : E ⊗[𝕜] (F ⊗[𝕜] G)) : + restrictRight bF j (restrictRight bG k ((TensorProduct.assoc 𝕜 E F G).symm w)) = + restrictRight (bF.tensorProduct bG) (j, k) w := by + induction w using TensorProduct.inductionOn with + | tmul u z => + induction z using TensorProduct.inductionOn with + | tmul v g => + simp only [TensorProduct.assoc_symm_tmul, restrictRight_tmul, map_smul, + OrthonormalBasis.tensorProduct_apply, TensorProduct.inner_tmul, mul_smul] + rw [smul_comm] + | add z₁ z₂ h₁ h₂ => simp [TensorProduct.tmul_add, h₁, h₂] + | add w₁ w₂ h₁ h₂ => simp [h₁, h₂] + +/-- Restricting the left factor `E` and the inner-right factor `G` commute (the `E`- and `G`-slots +are independent), modulo the re-association `(E ⊗ F) ⊗ G ≃ E ⊗ (F ⊗ G)`. -/ +private theorem restrictLeft_restrictRight_assoc_symm (bE : OrthonormalBasis ιE 𝕜 E) + (bG : OrthonormalBasis ιG 𝕜 G) (e : ιE) (k : ιG) (w : E ⊗[𝕜] (F ⊗[𝕜] G)) : + restrictLeft bE e (restrictRight bG k ((TensorProduct.assoc 𝕜 E F G).symm w)) = + restrictRight bG k (restrictLeft bE e w) := by + induction w using TensorProduct.inductionOn with + | tmul u z => + induction z using TensorProduct.inductionOn with + | tmul v g => simp [smul_smul, mul_comm] + | add z₁ z₂ h₁ h₂ => simp [TensorProduct.tmul_add, h₁, h₂] + | add w₁ w₂ h₁ h₂ => simp [h₁, h₂] + +/-- `restrictRight` over `G` slides through the left tensor factor under re-association: +`restrictRight bG k (assoc.symm (a ⊗ m)) = a ⊗ restrictRight bG k m`. -/ +private theorem restrictRight_assoc_symm_tmul (bG : OrthonormalBasis ιG 𝕜 G) (k : ιG) (a : E) + (m : F ⊗[𝕜] G) : + restrictRight bG k ((TensorProduct.assoc 𝕜 E F G).symm (a ⊗ₜ[𝕜] m)) = + a ⊗ₜ[𝕜] restrictRight bG k m := by + induction m using TensorProduct.inductionOn with + | tmul v g => simp + | add m₁ m₂ h₁ h₂ => simp [TensorProduct.tmul_add, h₁, h₂] + +/-- **Tower (`E`-marginal).** Tracing out the composite factor `F ⊗ G` (over the product basis +`bF.tensorProduct bG`) equals re-associating, then tracing out `G`, then `F`: +`Tr_{F⊗G} T = Tr_F (Tr_G (assoc.symm.conj T))`. The two ways of reading off the `E`-marginal of a +tripartite state — directly as `Tr_{F⊗G}`, or iteratively as `Tr_F ∘ Tr_G` — agree. -/ +theorem partialTraceRight_tensorProduct_basis (bF : OrthonormalBasis ιF 𝕜 F) + (bG : OrthonormalBasis ιG 𝕜 G) (T : E ⊗[𝕜] (F ⊗[𝕜] G) →ₗ[𝕜] E ⊗[𝕜] (F ⊗[𝕜] G)) : + partialTraceRight (bF.tensorProduct bG) T = + partialTraceRight bF (partialTraceRight bG ((TensorProduct.assoc 𝕜 E F G).symm.conj T)) := by + ext x + rw [partialTraceRight_apply, Fintype.sum_prod_type, partialTraceRight_apply] + refine Finset.sum_congr rfl fun j _ ↦ ?_ + rw [partialTraceRight_apply, map_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [OrthonormalBasis.tensorProduct_apply, conj_assoc_symm_tmul] + exact (restrictRight_restrictRight_assoc_symm bF bG j k _).symm + +/-- **Tower (`F`-marginal / commutation).** Tracing out `E` then `G` equals tracing out `G` then +`E` (modulo re-association): `Tr_E (Tr_G (assoc.symm.conj T)) = Tr_G (Tr_E T)`. Both compute the +`F`-marginal `Tr_{EG}` of a tripartite state. -/ +theorem partialTraceLeft_partialTraceRight_assoc (bE : OrthonormalBasis ιE 𝕜 E) + (bG : OrthonormalBasis ιG 𝕜 G) (T : E ⊗[𝕜] (F ⊗[𝕜] G) →ₗ[𝕜] E ⊗[𝕜] (F ⊗[𝕜] G)) : + partialTraceLeft bE (partialTraceRight bG ((TensorProduct.assoc 𝕜 E F G).symm.conj T)) = + partialTraceRight bG (partialTraceLeft bE T) := by + ext y + simp only [partialTraceLeft_apply, partialTraceRight_apply, map_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun k _ ↦ Finset.sum_congr rfl fun e _ ↦ ?_ + rw [conj_assoc_symm_tmul] + exact restrictLeft_restrictRight_assoc_symm bE bG e k _ + +/-- **Product marginal across the associator.** For a product operator `map A B` on `E ⊗ (F ⊗ G)`, +re-associating and tracing out `G` keeps `A` on `E` and traces `B` over `G`: +`Tr_G (assoc.symm.conj (map A B)) = map A (Tr_G B)`. Specialized to a product state `ρ_E ⊗ ρ_{FG}` +this computes the data-processing target `ρ_E ⊗ Tr_G ρ_{FG} = ρ_E ⊗ ρ_F`. -/ +theorem partialTraceRight_assoc_conj_map (bG : OrthonormalBasis ιG 𝕜 G) (A : E →ₗ[𝕜] E) + (B : (F ⊗[𝕜] G) →ₗ[𝕜] (F ⊗[𝕜] G)) : + partialTraceRight bG ((TensorProduct.assoc 𝕜 E F G).symm.conj (TensorProduct.map A B)) = + TensorProduct.map A (partialTraceRight bG B) := by + refine TensorProduct.ext' fun u v ↦ ?_ + rw [partialTraceRight_apply, TensorProduct.map_tmul, partialTraceRight_apply, + TensorProduct.tmul_sum] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [conj_assoc_symm_tmul] + simp only [TensorProduct.map_tmul, restrictRight_assoc_symm_tmul] + +/-- The `LinearMap`-level form of the associator-conjugation `assocIsometry.symm`: conjugating a +continuous operator `T` on `E ⊗ (F ⊗ G)` by the re-association isometry and forgetting continuity +equals the plain `LinearEquiv.conj` of `(TensorProduct.assoc 𝕜 E F G).symm` on `T.toLinearMap`. The +bridge between the `ContinuousLinearMap`-level `conjStarAlgEquiv` (used to transport density / +strict-positivity / relative entropy across the re-association) and the `LinearMap`-level tower +lemmas above. -/ +theorem assocIsometry_symm_conjStarAlgEquiv_toLinearMap [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (T : (E ⊗[𝕜] (F ⊗[𝕜] G)) →L[𝕜] (E ⊗[𝕜] (F ⊗[𝕜] G))) : + ((TensorProduct.assocIsometry 𝕜 E F G).symm.conjStarAlgEquiv T).toLinearMap = + (TensorProduct.assoc 𝕜 E F G).symm.conj T.toLinearMap := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap] + congr 1 + +/-- **Tower (`E`-marginal), `conjStarAlgEquiv` form.** The `ContinuousLinearMap`-level reading of +`partialTraceRight_tensorProduct_basis`: tracing out `G` from the re-associated operator +`assocIsometry.symm.conjStarAlgEquiv T` and then `F` recovers the `E`-marginal `Tr_{F⊗G} T`. This is +the form a tripartite consumer threads (the `E`-marginal of the `E⊗F`-reduced state agrees with the +`E`-marginal of `T` directly): combine with `partialTraceRight_eq_of_basis` hypotheses for the two +reduced states to relate them in one rewrite. -/ +theorem partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv + [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (bF : OrthonormalBasis ιF 𝕜 F) (bG : OrthonormalBasis ιG 𝕜 G) + (T : (E ⊗[𝕜] (F ⊗[𝕜] G)) →L[𝕜] (E ⊗[𝕜] (F ⊗[𝕜] G))) : + partialTraceRight bF (partialTraceRight bG + ((TensorProduct.assocIsometry 𝕜 E F G).symm.conjStarAlgEquiv T).toLinearMap) = + partialTraceRight (bF.tensorProduct bG) T.toLinearMap := by + rw [assocIsometry_symm_conjStarAlgEquiv_toLinearMap, ← partialTraceRight_tensorProduct_basis] + +/-- **`E`-marginal consistency for a tripartite reduced state.** If `ρ_EF` is the `G`-trace of the +re-associated `T` (`hρEF`) and `ρ_E` is the `F ⊗ G`-trace of `T` (`hρE`), then `ρ_E` is the +`F`-trace of `ρ_EF`. The hypothesis-bundled consumer form of +`partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv`, dissolving the recurring +`rw [← hρEF, …, hρE]` glue threaded by the tripartite mutual-information theorems +(`quantumMutualInformation_monotone`, strong subadditivity, the MI chain rule). -/ +theorem partialTraceRight_eq_of_partialTraceRight_assocIsometry + [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (bF : OrthonormalBasis ιF 𝕜 F) (bG : OrthonormalBasis ιG 𝕜 G) + {T : (E ⊗[𝕜] (F ⊗[𝕜] G)) →L[𝕜] (E ⊗[𝕜] (F ⊗[𝕜] G))} + {ρEF : (E ⊗[𝕜] F) →L[𝕜] (E ⊗[𝕜] F)} {ρE : E →L[𝕜] E} + (hρEF : partialTraceRight bG + ((TensorProduct.assocIsometry 𝕜 E F G).symm.conjStarAlgEquiv T).toLinearMap = ρEF.toLinearMap) + (hρE : partialTraceRight (bF.tensorProduct bG) T.toLinearMap = ρE.toLinearMap) : + partialTraceRight bF ρEF.toLinearMap = ρE.toLinearMap := by + rw [← hρEF, partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv, hρE] + +/-! ### Forward associator: tracing out the left factor of an appended-ancilla product + +The tower lemmas above compute a marginal obtained by *tracing out the inner-right factor* `G`, +using the backward re-association `(TensorProduct.assoc 𝕜 E F G).symm.conj`. The lemmas here are the +*forward* companion: for a product operator `T ⊗ C` on `(E ⊗ F) ⊗ G` (the left two factors carry a +possibly-correlated `T`, the outer factor a `C`), re-associating *forward* to `E ⊗ (F ⊗ G)` and +tracing out the *left* factor `E` keeps `C` untouched and traces `T` over `E`: +`Tr_E (assoc.conj (T ⊗ C)) = (Tr_E T) ⊗ C`. Specialized to an appended pure ancilla `T = ρ_{EF}`, +`C = ω`, this is the `F ⊗ G`-marginal `ρ_F ⊗ ω` of the ancilla-adjoined state — the ingredient for +"appending a pure product ancilla leaves the quantum mutual information unchanged" (N&C +Theorem 11.15(3)). -/ + +/-- `restrictLeft` slides through the forward associator on the outer tensor factor: +`restrictLeft bE e (assoc (q ⊗ g)) = restrictLeft bE e q ⊗ g` for `q : E ⊗ F`, `g : G`. The +`restrictLeft`/forward-`assoc` companion of `restrictRight_assoc_symm_tmul`. -/ +private theorem restrictLeft_assoc_tmul (bE : OrthonormalBasis ιE 𝕜 E) (e : ιE) (q : E ⊗[𝕜] F) + (g : G) : + restrictLeft bE e ((TensorProduct.assoc 𝕜 E F G) (q ⊗ₜ[𝕜] g)) = + restrictLeft bE e q ⊗ₜ[𝕜] g := by + induction q using TensorProduct.inductionOn with + | tmul x y => simp [TensorProduct.smul_tmul'] + | add q₁ q₂ h₁ h₂ => simp [TensorProduct.add_tmul, h₁, h₂] + +/-- **Product marginal across the forward associator (left trace).** For a product operator `T ⊗ C` +on `(E ⊗ F) ⊗ G`, re-associating forward and tracing out the left factor `E` keeps `C` on `G` and +traces `T` over `E`: `Tr_E (assoc.conj (T ⊗ C)) = (Tr_E T) ⊗ C`. The forward/left-trace companion of +`partialTraceRight_assoc_conj_map`. Specialized to an appended pure ancilla `ρ_{EF} ⊗ ω` this +computes the `F ⊗ G`-marginal `ρ_F ⊗ ω`. -/ +theorem partialTraceLeft_assoc_conj_map (bE : OrthonormalBasis ιE 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) (C : G →ₗ[𝕜] G) : + partialTraceLeft bE ((TensorProduct.assoc 𝕜 E F G).conj (TensorProduct.map T C)) = + TensorProduct.map (partialTraceLeft bE T) C := by + refine TensorProduct.ext' fun m g ↦ ?_ + rw [TensorProduct.map_tmul, partialTraceLeft_apply, partialTraceLeft_apply, + TensorProduct.sum_tmul] + refine Finset.sum_congr rfl fun e _ ↦ ?_ + rw [LinearEquiv.conj_apply, LinearMap.comp_apply, LinearMap.comp_apply] + simp only [LinearEquiv.coe_coe] + rw [TensorProduct.assoc_symm_tmul, TensorProduct.map_tmul, restrictLeft_assoc_tmul] + +/-- The `LinearMap`-level form of the *forward* associator-conjugation `assocIsometry`: conjugating +a continuous operator `T` on `(E ⊗ F) ⊗ G` by the re-association isometry and forgetting continuity +equals the plain `LinearEquiv.conj` of `TensorProduct.assoc 𝕜 E F G` on `T.toLinearMap`. The forward +companion of `assocIsometry_symm_conjStarAlgEquiv_toLinearMap`. -/ +theorem assocIsometry_conjStarAlgEquiv_toLinearMap [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (T : ((E ⊗[𝕜] F) ⊗[𝕜] G) →L[𝕜] ((E ⊗[𝕜] F) ⊗[𝕜] G)) : + ((TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv T).toLinearMap = + (TensorProduct.assoc 𝕜 E F G).conj T.toLinearMap := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap] + congr 1 + +/-- **Appended-ancilla `F ⊗ G`-marginal, `conjStarAlgEquiv` form.** The `ContinuousLinearMap`-level +reading of `partialTraceLeft_assoc_conj_map`: for a product density operator `ρ ⊗ ω` (with `ρ` on +`E ⊗ F`, `ω` on `G`), re-associating forward via `assocIsometry` and tracing out the left factor `E` +gives `(Tr_E ρ) ⊗ ω`. This is the `F ⊗ G`-marginal of the ancilla-adjoined state; combined with the +appended ancilla's purity it yields the mutual-information invariance under appending a pure product +ancilla. -/ +theorem partialTraceLeft_assocIsometry_conjStarAlgEquiv_map [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] (bE : OrthonormalBasis ιE 𝕜 E) + (T : (E ⊗[𝕜] F) →L[𝕜] (E ⊗[𝕜] F)) (C : G →L[𝕜] G) : + partialTraceLeft bE ((TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv + (TensorProduct.mapL T C)).toLinearMap = + TensorProduct.map (partialTraceLeft bE T.toLinearMap) C.toLinearMap := by + rw [assocIsometry_conjStarAlgEquiv_toLinearMap, TensorProduct.toLinearMap_mapL, + partialTraceLeft_assoc_conj_map] + +/-- **Associator naturality for `mapL`.** Conjugating a left-nested tensor operator +`mapL (mapL f g) h` (on `(E ⊗ F) ⊗ G`) by the forward re-association isometry produces the +right-nested `mapL f (mapL g h)` (on `E ⊗ (F ⊗ G)`) — the `ContinuousLinearMap` reading of the +associator's naturality with respect to `TensorProduct.map` (`map_map_comp_assoc_symm_eq`). Proved +at the `LinearMap` level through `assocIsometry_conjStarAlgEquiv_toLinearMap`, so it avoids the +`≃⋆ₐ`-over-operators instance search. The `mapL` companion of the `_toLinearMap` bridge, in the +`assocIsometry.conjStarAlgEquiv` family. -/ +theorem assocIsometry_conjStarAlgEquiv_mapL_mapL [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (f : E →L[𝕜] E) (g : F →L[𝕜] F) (h : G →L[𝕜] G) : + (TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv + (TensorProduct.mapL (TensorProduct.mapL f g) h) + = TensorProduct.mapL f (TensorProduct.mapL g h) := by + apply ContinuousLinearMap.coe_injective + rw [assocIsometry_conjStarAlgEquiv_toLinearMap] + simp only [TensorProduct.toLinearMap_mapL] + rw [LinearEquiv.conj_apply, LinearMap.comp_assoc, + TensorProduct.map_map_comp_assoc_symm_eq, ← LinearMap.comp_assoc] + simp + +/-- **Inverse re-association naturality of `conjStarAlgEquiv`, `mapL` form.** Conjugating the +product operator `mapL f (mapL g h)` (with `f` on `E`, `g` on `F`, `h` on `G`, grouped +`E ⊗ (F ⊗ G)`) by the *inverse* associator isometry regroups it to `mapL (mapL f g) h` on +`(E ⊗ F) ⊗ G`. The `symm` companion of `assocIsometry_conjStarAlgEquiv_mapL_mapL`, proved on pure +tensors through the forward / inverse associator tensor actions. -/ +theorem assocIsometry_symm_conjStarAlgEquiv_mapL_mapL [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (f : E →L[𝕜] E) (g : F →L[𝕜] F) (h : G →L[𝕜] G) : + (TensorProduct.assocIsometry 𝕜 E F G).symm.conjStarAlgEquiv + (TensorProduct.mapL f (TensorProduct.mapL g h)) + = TensorProduct.mapL (TensorProduct.mapL f g) h := by + apply ContinuousLinearMap.coe_injective + rw [assocIsometry_symm_conjStarAlgEquiv_toLinearMap, LinearEquiv.conj_apply] + simp only [TensorProduct.toLinearMap_mapL] + refine TensorProduct.ext_threefold fun x y z => ?_ + simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.symm_symm, + TensorProduct.assoc_tmul, TensorProduct.map_tmul, TensorProduct.assoc_symm_tmul] + +/-- **The associator conjugation is additive.** `conjStarAlgEquiv (X + Y) = conjStarAlgEquiv X + +conjStarAlgEquiv Y` for the forward re-association isometry. Proved at the `LinearMap` level (where +the conjugation is `LinearEquiv.conj`, additive by `LinearMap.comp_add`/`add_comp`), which sidesteps +the `≃⋆ₐ`-over-operators `map_add` instance search that stalls on tensor-of-operator types. The +additivity companion in the `assocIsometry.conjStarAlgEquiv` family, used to split a block-diagonal +operator (`|0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ U`) before reshaping each summand. -/ +theorem assocIsometry_conjStarAlgEquiv_add [FiniteDimensional 𝕜 E] + [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (X Y : ((E ⊗[𝕜] F) ⊗[𝕜] G) →L[𝕜] ((E ⊗[𝕜] F) ⊗[𝕜] G)) : + (TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv (X + Y) + = (TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv X + + (TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv Y := by + apply ContinuousLinearMap.coe_injective + rw [ContinuousLinearMap.toLinearMap_add, assocIsometry_conjStarAlgEquiv_toLinearMap, + assocIsometry_conjStarAlgEquiv_toLinearMap, assocIsometry_conjStarAlgEquiv_toLinearMap, + ContinuousLinearMap.toLinearMap_add, LinearEquiv.conj_apply, LinearEquiv.conj_apply, + LinearEquiv.conj_apply, LinearMap.comp_add, LinearMap.add_comp] + +end Tower + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceComm.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceComm.lean new file mode 100644 index 0000000000..17951f7f2d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceComm.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# The partial trace over the left factor is the partial trace over the right factor after a swap + +The two partial traces `LinearMap.partialTraceLeft` (over the left factor) and +`LinearMap.partialTraceRight` (over the right factor) are the two faces of one operation, related by +the factor-swap `TensorProduct.comm`. This file records that bridge: + +`Tr_E T = Tr_E (comm ∘ T ∘ comm)` — tracing out the left factor `E` of `E ⊗ F` equals swapping the +factors and tracing out the (now right) factor `E` of `F ⊗ E`. + +The point is economy: the naturality API for `partialTraceRight` (invariance under a unitary on the +traced factor, associator commutation, …) then transfers to `partialTraceLeft` for free by +conjugating with `comm`, instead of re-proving each fact from scratch on the left. The reduced-state +generator `State.reducedRight` (which is a `partialTraceLeft`) inherits this in +`AxQM/Postulates/API/ReducedStateComm.lean`. + +## Main results + +* `LinearMap.restrictRight_comm` / `LinearMap.restrictLeft_comm` — the slot-restriction maps swap: + `restrictRight b k (comm w) = restrictLeft b k w` and its mirror. +* `LinearMap.partialTraceLeft_eq_partialTraceRight_comm` / + `LinearMap.partialTraceRight_eq_partialTraceLeft_comm` — the partial-trace bridge, in both + directions. +-/ + +@[expose] public section + +open scoped TensorProduct InnerProductSpace + +namespace LinearMap + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + {ι₁ : Type*} [Fintype ι₁] + +/-- **The slot-restriction maps swap under `comm`.** Restricting the right factor at `b k` after +swapping factors is restricting the left factor at `b k`: for `w : E ⊗ F` and an orthonormal basis +`b` of `E`, + + `restrictRight b k (comm w) = restrictLeft b k w`. + +On a simple tensor `x ⊗ₜ y` both sides are `⟪b k, x⟫ • y` (the swap sends `x ⊗ₜ y ↦ y ⊗ₜ x`, whose +right factor is the original left factor `x`); extended linearly. -/ +theorem restrictRight_comm (b : OrthonormalBasis ι₁ 𝕜 E) (k : ι₁) (w : E ⊗[𝕜] F) : + restrictRight b k ((TensorProduct.comm 𝕜 E F) w) = restrictLeft b k w := by + induction w using TensorProduct.inductionOn with + | tmul x y => rw [TensorProduct.comm_tmul, restrictRight_tmul, restrictLeft_tmul] + | add a c ha hc => simp only [map_add, ha, hc] + +/-- **Left partial trace = right partial trace after a swap.** For `T : E ⊗ F →ₗ E ⊗ F` and an +orthonormal basis `b` of the traced factor `E`, + + `Tr_E T = Tr_E (comm ∘ T ∘ comm)`, + +i.e. tracing out the left factor of `E ⊗ F` equals conjugating by the factor-swap +`comm : E ⊗ F ≃ F ⊗ E` and tracing out the (now right) factor `E` of `F ⊗ E`. This is the bridge +that transfers the `partialTraceRight` naturality API to `partialTraceLeft`. Proved termwise from +the `partialTrace{Left,Right}_apply` sum formulas via `restrictRight_comm`. -/ +theorem partialTraceLeft_eq_partialTraceRight_comm (b : OrthonormalBasis ι₁ 𝕜 E) + (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceLeft b T = + partialTraceRight b ((TensorProduct.comm 𝕜 E F).toLinearMap ∘ₗ T ∘ₗ + (TensorProduct.comm 𝕜 F E).toLinearMap) := by + ext y + rw [partialTraceLeft_apply, partialTraceRight_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + simp only [LinearMap.comp_apply, LinearEquiv.coe_toLinearMap, TensorProduct.comm_tmul, + restrictRight_comm] + +/-- **The slot-restriction maps swap under `comm`** (mirror of `restrictRight_comm`). For a vector +`w : E ⊗ F` and an orthonormal basis `b` of `F`, + + `restrictLeft b k (comm w) = restrictRight b k w`. + +On a simple tensor `x ⊗ₜ y` both sides are `⟪b k, y⟫ • x`. -/ +theorem restrictLeft_comm {ι₂ : Type*} [Fintype ι₂] (b : OrthonormalBasis ι₂ 𝕜 F) (k : ι₂) + (w : E ⊗[𝕜] F) : + restrictLeft b k ((TensorProduct.comm 𝕜 E F) w) = restrictRight b k w := by + induction w using TensorProduct.inductionOn with + | tmul x y => rw [TensorProduct.comm_tmul, restrictLeft_tmul, restrictRight_tmul] + | add a c ha hc => simp only [map_add, ha, hc] + +/-- **Right partial trace = left partial trace after a swap** (mirror of +`partialTraceLeft_eq_partialTraceRight_comm`). For `T : E ⊗ F →ₗ E ⊗ F` and an orthonormal basis `b` +of the traced factor `F`, + + `Tr_F T = Tr_F (comm ∘ T ∘ comm)`, + +tracing out the right factor of `E ⊗ F` equals swapping and tracing out the (now left) factor `F` of +`F ⊗ E`. Transfers the `partialTraceLeft` naturality API to `partialTraceRight`. -/ +theorem partialTraceRight_eq_partialTraceLeft_comm {ι₂ : Type*} [Fintype ι₂] + (b : OrthonormalBasis ι₂ 𝕜 F) (T : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F) : + partialTraceRight b T = + partialTraceLeft b ((TensorProduct.comm 𝕜 E F).toLinearMap ∘ₗ T ∘ₗ + (TensorProduct.comm 𝕜 F E).toLinearMap) := by + ext x + rw [partialTraceRight_apply, partialTraceLeft_apply] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + simp only [LinearMap.comp_apply, LinearEquiv.coe_toLinearMap, TensorProduct.comm_tmul, + restrictLeft_comm] + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceLeftBlock.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceLeftBlock.lean new file mode 100644 index 0000000000..d23f951957 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PartialTraceLeftBlock.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# Tracing out a composite *left* factor of a tripartite operator + +For an operator `T` on `(E ⊗ F) ⊗ G`, tracing out the composite **left** factor `E ⊗ F` equals +re-associating *forward* to `E ⊗ (F ⊗ G)` and tracing out `E` then `F`. These are the left-block +mirror of the `partialTraceRight_tensorProduct_basis` / +`partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv` tower lemmas in +`ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract`, which trace out the composite **right** +factor. + +The `G`-marginal of a tripartite state must sometimes be read off from two different groupings of +the three subsystems — directly as `Tr_{E⊗F}`, or iteratively as `Tr_F ∘ Tr_E` after +re-association. These lemmas witness that the two agree; they are the operator-level content behind +the `reducedRight`-analogue of `State.reducedLeft_congr_assoc_symm` (tracing out a composite left +factor of a quantum state). + +## Main results + +* `LinearMap.partialTraceLeft_tensorProduct_basis` — `Tr_{E⊗F} T = Tr_F (Tr_E (assoc.conj T))`. +* `LinearMap.partialTraceLeft_partialTraceLeft_assocIsometry_conjStarAlgEquiv` — its + `ContinuousLinearMap` / `conjStarAlgEquiv` reading. +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace LinearMap + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] + {ιE ιF : Type*} [Fintype ιE] [Fintype ιF] + +/-- The forward associator-conjugation `(assoc.conj T)` acts on a pure tensor by re-associating: +`(assoc.conj T) (x ⊗ (y ⊗ z)) = assoc (T ((x ⊗ y) ⊗ z))`. The forward companion of +`LinearMap.conj_assoc_symm_tmul`. -/ +theorem conj_assoc_tmul (T : (E ⊗[𝕜] F) ⊗[𝕜] G →ₗ[𝕜] (E ⊗[𝕜] F) ⊗[𝕜] G) + (x : E) (y : F) (z : G) : + (TensorProduct.assoc 𝕜 E F G).conj T (x ⊗ₜ[𝕜] (y ⊗ₜ[𝕜] z)) = + (TensorProduct.assoc 𝕜 E F G) (T ((x ⊗ₜ[𝕜] y) ⊗ₜ[𝕜] z)) := by + rw [LinearEquiv.conj_apply] + simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, TensorProduct.assoc_symm_tmul] + +/-- `restrictLeft` over the composite factor `E ⊗ F` factors as iterated `restrictLeft`s after +re-association: pairing out the `bE i ⊗ bF j` slot equals pairing out `bE i` then `bF j`. The +left-block companion of `restrictRight_restrictRight_assoc_symm`. -/ +private theorem restrictLeft_restrictLeft_assoc (bE : OrthonormalBasis ιE 𝕜 E) + (bF : OrthonormalBasis ιF 𝕜 F) (i : ιE) (j : ιF) (w : (E ⊗[𝕜] F) ⊗[𝕜] G) : + restrictLeft bF j (restrictLeft bE i ((TensorProduct.assoc 𝕜 E F G) w)) = + restrictLeft (bE.tensorProduct bF) (i, j) w := by + induction w using TensorProduct.inductionOn with + | tmul u g => + induction u using TensorProduct.inductionOn with + | tmul x y => + simp only [TensorProduct.assoc_tmul, restrictLeft_tmul, map_smul, + OrthonormalBasis.tensorProduct_apply, TensorProduct.inner_tmul, mul_smul] + | add u₁ u₂ h₁ h₂ => simp [TensorProduct.add_tmul, h₁, h₂] + | add w₁ w₂ h₁ h₂ => simp [h₁, h₂] + +/-- **Tower (`G`-marginal, left block).** Tracing out the composite factor `E ⊗ F` (over the product +basis `bE.tensorProduct bF`) equals re-associating forward, then tracing out `E`, then `F`: +`Tr_{E⊗F} T = Tr_F (Tr_E (assoc.conj T))`. The left-block mirror of +`partialTraceRight_tensorProduct_basis`. -/ +theorem partialTraceLeft_tensorProduct_basis (bE : OrthonormalBasis ιE 𝕜 E) + (bF : OrthonormalBasis ιF 𝕜 F) (T : (E ⊗[𝕜] F) ⊗[𝕜] G →ₗ[𝕜] (E ⊗[𝕜] F) ⊗[𝕜] G) : + partialTraceLeft (bE.tensorProduct bF) T = + partialTraceLeft bF (partialTraceLeft bE ((TensorProduct.assoc 𝕜 E F G).conj T)) := by + ext z + rw [partialTraceLeft_apply, Fintype.sum_prod_type, Finset.sum_comm, partialTraceLeft_apply] + refine Finset.sum_congr rfl fun j _ ↦ ?_ + rw [partialTraceLeft_apply, map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [OrthonormalBasis.tensorProduct_apply, conj_assoc_tmul] + exact (restrictLeft_restrictLeft_assoc bE bF i j _).symm + +/-- **Tower (`G`-marginal, left block), `conjStarAlgEquiv` form.** The `ContinuousLinearMap`-level +reading of `partialTraceLeft_tensorProduct_basis`: tracing out `E` then `F` from the re-associated +operator `assocIsometry.conjStarAlgEquiv T` recovers the `G`-marginal `Tr_{E⊗F} T`. The left-block +mirror of `partialTraceRight_partialTraceRight_assocIsometry_symm_conjStarAlgEquiv`. -/ +theorem partialTraceLeft_partialTraceLeft_assocIsometry_conjStarAlgEquiv + [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + (bE : OrthonormalBasis ιE 𝕜 E) (bF : OrthonormalBasis ιF 𝕜 F) + (T : ((E ⊗[𝕜] F) ⊗[𝕜] G) →L[𝕜] ((E ⊗[𝕜] F) ⊗[𝕜] G)) : + partialTraceLeft bF (partialTraceLeft bE + ((TensorProduct.assocIsometry 𝕜 E F G).conjStarAlgEquiv T).toLinearMap) = + partialTraceLeft (bE.tensorProduct bF) T.toLinearMap := by + rw [assocIsometry_conjStarAlgEquiv_toLinearMap, ← partialTraceLeft_tensorProduct_basis] + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiL2.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiL2.lean new file mode 100644 index 0000000000..74ed99da60 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiL2.lean @@ -0,0 +1,181 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.PiL2 + +/-! +# Additions to `EuclideanSpace` and `OrthonormalBasis` + +Reindexing isometries `EuclideanSpace 𝕜 (Fin m ⊕ Fin n) ≃ₗᵢ EuclideanSpace 𝕜 (Fin (m + n))` and +`EuclideanSpace 𝕜 (Fin m × Fin n) ≃ₗᵢ EuclideanSpace 𝕜 (Fin (m * n))`, a nonvanishing lemma for +orthonormal basis vectors, a `single`-expansion of a Euclidean-space vector against `basisFun`, +and a cross-space generalization of `LinearIsometry.extend` to isometries landing in a +different (but equidimensional) finite-dimensional inner product space. +-/ + +@[expose] public section + +noncomputable section + +open Module + +section reindexEuclideanSpace + +variable {𝕜 : Type*} [RCLike 𝕜] + +/-- Reindex `EuclideanSpace 𝕜 (Fin m ⊕ Fin n)` to `EuclideanSpace 𝕜 (Fin (m + n))` as a linear +isometric equivalence, via `finSumFinEquiv`. -/ +def EuclideanSpace.reindexFinSumEquiv (m n : ℕ) : + EuclideanSpace 𝕜 (Fin m ⊕ Fin n) ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 (Fin (m + n)) := + LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 finSumFinEquiv + +@[simp] +theorem EuclideanSpace.reindexFinSumEquiv_apply (m n : ℕ) + (x : EuclideanSpace 𝕜 (Fin m ⊕ Fin n)) : + (reindexFinSumEquiv m n x : Fin (m + n) → 𝕜) = + Equiv.piCongrLeft' (fun _ => 𝕜) finSumFinEquiv x := + rfl + +theorem EuclideanSpace.reindexFinSumEquiv_symm (m n : ℕ) : + (reindexFinSumEquiv (𝕜 := 𝕜) m n).symm = + LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 finSumFinEquiv.symm := by + simp [reindexFinSumEquiv] + +@[simp] +theorem EuclideanSpace.reindexFinSumEquiv_single (m n : ℕ) + (i : Fin m ⊕ Fin n) (v : 𝕜) : + reindexFinSumEquiv m n (EuclideanSpace.single i v) = + EuclideanSpace.single (finSumFinEquiv i) v := + EuclideanSpace.piLpCongrLeft_single finSumFinEquiv i v + +/-- Reindex `EuclideanSpace 𝕜 (Fin m × Fin n)` to `EuclideanSpace 𝕜 (Fin (m * n))` as a linear +isometric equivalence, via `finProdFinEquiv`. -/ +def EuclideanSpace.reindexFinProdEquiv (m n : ℕ) : + EuclideanSpace 𝕜 (Fin m × Fin n) ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 (Fin (m * n)) := + LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 finProdFinEquiv + +@[simp] +theorem EuclideanSpace.reindexFinProdEquiv_apply (m n : ℕ) + (x : EuclideanSpace 𝕜 (Fin m × Fin n)) : + (reindexFinProdEquiv m n x : Fin (m * n) → 𝕜) = + Equiv.piCongrLeft' (fun _ => 𝕜) finProdFinEquiv x := + rfl + +theorem EuclideanSpace.reindexFinProdEquiv_symm (m n : ℕ) : + (reindexFinProdEquiv (𝕜 := 𝕜) m n).symm = + LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 finProdFinEquiv.symm := by + simp [reindexFinProdEquiv] + +@[simp] +theorem EuclideanSpace.reindexFinProdEquiv_single (m n : ℕ) (i : Fin m × Fin n) (v : 𝕜) : + reindexFinProdEquiv m n (EuclideanSpace.single i v) = + EuclideanSpace.single (finProdFinEquiv i) v := + EuclideanSpace.piLpCongrLeft_single finProdFinEquiv i v + +end reindexEuclideanSpace + +variable {ι 𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +lemma OrthonormalBasis.ne_zero [Fintype ι] (b : OrthonormalBasis ι 𝕜 E) (i : ι) : b i ≠ 0 := + b.orthonormal.ne_zero i + +/-- A Euclidean-space vector is the sum of its coordinates against the standard basis vectors: +`∑ i, x.ofLp i • single i 1 = x`. The `single`-form companion of `OrthonormalBasis.sum_repr` +for `basisFun`, convenient for expanding an operator applied to a basis vector. -/ +theorem EuclideanSpace.sum_single_ofLp_eq {𝕜 ι : Type*} [RCLike 𝕜] [Fintype ι] [DecidableEq ι] + (x : EuclideanSpace 𝕜 ι) : + ∑ i, x.ofLp i • EuclideanSpace.single i (1 : 𝕜) = x := by + simpa only [EuclideanSpace.basisFun_repr, EuclideanSpace.basisFun_apply] using + OrthonormalBasis.sum_repr (EuclideanSpace.basisFun ι 𝕜) x + +section + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace 𝕜 V] [FiniteDimensional 𝕜 V] +variable {S : Submodule 𝕜 V} +variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace 𝕜 W] [FiniteDimensional 𝕜 W] + +local notation "⟪" x ", " y "⟫" => inner 𝕜 x y + +namespace LinearIsometry + +/-- Dimension equality of orthogonal complements when `dim V = dim W` and `L : S →ₗᵢ W` is +an isometric embedding: `dim (range L)ᗮ = dim Sᗮ` (both equal `dim V - dim S`). -/ +theorem finrank_orthogonal_range_eq_finrank_orthogonal_of_eq_finrank + (hdim : finrank 𝕜 V = finrank 𝕜 W) (L : S →ₗᵢ[𝕜] W) : + finrank 𝕜 (LinearMap.range L.toLinearMap)ᗮ = finrank 𝕜 Sᗮ := + Submodule.finrank_add_finrank_orthogonal' <| by + rw [LinearMap.finrank_range_of_inj L.injective, S.finrank_add_finrank_orthogonal, hdim] + +/-- **Canonical orthogonal-complement isometry** `Sᗮ ≃ₗᵢ (range L)ᗮ`, derived from +`stdOrthonormalBasis` on both subspaces and `finCongr` on the matching dimensions. -/ +noncomputable def extendCrossOrthogonalIsometry + (hdim : finrank 𝕜 V = finrank 𝕜 W) (L : S →ₗᵢ[𝕜] W) : + Sᗮ ≃ₗᵢ[𝕜] (LinearMap.range L.toLinearMap)ᗮ := + (stdOrthonormalBasis 𝕜 Sᗮ).repr.trans + ((stdOrthonormalBasis 𝕜 (LinearMap.range L.toLinearMap)ᗮ).reindex <| + finCongr (finrank_orthogonal_range_eq_finrank_orthogonal_of_eq_finrank hdim L)).repr.symm + +/-- **Underlying linear map of `LinearIsometry.extendCross`**: extends `L` to `V →ₗ[𝕜] W` +via the canonical decomposition `V = S ⊕ Sᗮ`, mapping `S` by `L` and `Sᗮ` isometrically +onto `(range L)ᗮ` via `extendCrossOrthogonalIsometry`. -/ +noncomputable def extendCrossToLinearMap + (hdim : finrank 𝕜 V = finrank 𝕜 W) (L : S →ₗᵢ[𝕜] W) : V →ₗ[𝕜] W := + haveI : CompleteSpace S := FiniteDimensional.completeSpace 𝕜 S + haveI : CompleteSpace V := FiniteDimensional.completeSpace 𝕜 V + L.toLinearMap.comp S.orthogonalProjectionOnto.toLinearMap + + ((LinearMap.range L.toLinearMap)ᗮ.subtypeₗᵢ.comp + (extendCrossOrthogonalIsometry hdim L).toLinearIsometry).toLinearMap.comp + Sᗮ.orthogonalProjectionOnto.toLinearMap + +/-- Norm-preservation of `extendCrossToLinearMap`: by Pythagoras on the `S ⊕ Sᗮ` +decomposition of `x`, with the `S`-part mapped isometrically by `L` and the `Sᗮ`-part +mapped isometrically into the orthogonal complement of `range L`. -/ +theorem norm_extendCrossToLinearMap_apply (hdim : finrank 𝕜 V = finrank 𝕜 W) + (L : S →ₗᵢ[𝕜] W) (x : V) : + ‖extendCrossToLinearMap hdim L x‖ = ‖x‖ := by + have : CompleteSpace S := FiniteDimensional.completeSpace 𝕜 S + have : CompleteSpace V := FiniteDimensional.completeSpace 𝕜 V + set p1 : V →ₗ[𝕜] S := S.orthogonalProjectionOnto.toLinearMap + set p2 : V →ₗ[𝕜] Sᗮ := Sᗮ.orthogonalProjectionOnto.toLinearMap + set L3 : Sᗮ →ₗᵢ[𝕜] W := ((LinearMap.range L.toLinearMap)ᗮ).subtypeₗᵢ.comp + (extendCrossOrthogonalIsometry hdim L).toLinearIsometry + have Mx_decomp : extendCrossToLinearMap hdim L x = L (p1 x) + L3 (p2 x) := by + simp [extendCrossToLinearMap, p1, p2, L3] + have Mx_orth : ⟪L (p1 x), L3 (p2 x)⟫ = 0 := + Submodule.inner_right_of_mem_orthogonal (LinearMap.mem_range_self L.toLinearMap (p1 x)) + ((extendCrossOrthogonalIsometry hdim L) (p2 x)).property + rw [← sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _), S.norm_sq_eq_add_norm_sq_projection x] + simp only [sq, Mx_decomp] + rw [norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (L (p1 x)) (L3 (p2 x)) Mx_orth] + simp only [p1, p2, L3, LinearIsometry.norm_map, + ContinuousLinearMap.coe_coe, ← Submodule.norm_coe] + +/-- **Cross-space extension**: a linear isometry `L : S →ₗᵢ[𝕜] W` from a subspace of a +finite-dimensional inner product space `V` into a finite-dimensional inner product space +`W` of the same dimension extends to a full isometry `V →ₗᵢ[𝕜] W`. + +Cross-space generalization of `LinearIsometry.extend`; the same-space form is the special +case `W = V`, `hdim = rfl`. -/ +noncomputable def extendCross (hdim : finrank 𝕜 V = finrank 𝕜 W) + (L : S →ₗᵢ[𝕜] W) : V →ₗᵢ[𝕜] W where + toLinearMap := extendCrossToLinearMap hdim L + norm_map' := norm_extendCrossToLinearMap_apply hdim L + +theorem extendCross_apply (hdim : finrank 𝕜 V = finrank 𝕜 W) (L : S →ₗᵢ[𝕜] W) (s : S) : + L.extendCross hdim s = L s := by + have : CompleteSpace S := FiniteDimensional.completeSpace 𝕜 S + have : CompleteSpace V := FiniteDimensional.completeSpace 𝕜 V + simp [extendCross, extendCrossToLinearMap] + +end LinearIsometry + +end + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProduct.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProduct.lean new file mode 100644 index 0000000000..d71b753455 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProduct.lean @@ -0,0 +1,654 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct +public import Mathlib.LinearAlgebra.PiTensorProduct.Dual +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.PiTensorProduct.Finiteness + +/-! + +# Inner product space structure on `PiTensorProduct` + +This file provides the inner product space structure on the n-ary tensor product +`⨂[𝕜] i, s i` of inner product spaces, mirroring the binary +`Mathlib/Analysis/InnerProductSpace/TensorProduct.lean`. + +The inner product on `⨂[𝕜] i, s i` is defined so that on pure tensors +`⟪⨂ₜ a_i, ⨂ₜ b_i⟫ = ∏ i, ⟪a_i, b_i⟫`. + +## Main definitions + +* `PiTensorProduct.instNormedAddCommGroup`: the normed additive group structure on the n-ary + tensor product, induced by the inner product. +* `PiTensorProduct.instInnerProductSpace`: the inner product space structure on the n-ary + tensor product, where `⟪⨂ₜ a_i, ⨂ₜ b_i⟫ = ∏ i, ⟪a_i, b_i⟫`. +* `PiTensorProduct.reindexₗᵢ`: the linear isometry equivalence version of + `PiTensorProduct.reindex`, re-indexing the tensor factors along an index equivalence. +* `PiTensorProduct.tmulEquivₗᵢ`, `PiTensorProduct.subsingletonEquivₗᵢ`: the linear isometry + equivalence versions of `PiTensorProduct.tmulEquiv` (splitting the index type along `ι ⊕ ι₂`) + and `PiTensorProduct.subsingletonEquiv` (a tensor power over a subsingleton index). +* `PiTensorProduct.tmulEquivDepₗᵢ`: the linear isometry equivalence version of + `PiTensorProduct.tmulEquivDep` (splitting the index type along `ι ⊕ ι₂`), for a dependent + family `N : ι ⊕ ι₂ → Type*` of inner product spaces. +* `PiTensorProduct.consEquivₗᵢ`: the linear isometry equivalence peeling the head factor off a + tensor power `⨂[𝕜] (_ : Fin (n + 1)), M ≃ₗᵢ M ⊗[𝕜] (⨂[𝕜] (_ : Fin n), M)`. + +## Implementation notes + +The inner product is built from `PiTensorProduct.dualDistrib` (in +`Mathlib/LinearAlgebra/PiTensorProduct/Dual.lean`) composed with the σ-semilinear +`PiTensorProduct.map (innerₛₗ 𝕜)` (the n-ary semilinear `map`, built by hand below as +`innerMultilinear`). +Positive-definiteness is proved by reducing each element to a finite-dimensional +sub-`PiTensorProduct` via `PiTensorProduct.exists_finite_submodule_of_setFinite` +(`ToMathlib/LinearAlgebra/PiTensorProduct/Finiteness.lean`), then expanding in the +orthonormal basis on the sub-`PiTensorProduct` from `Basis.piTensorProduct`. + +-/ + +@[expose] public section + +variable {ι : Type*} [Finite ι] {𝕜 : Type*} [RCLike 𝕜] {s : ι → Type*} + [∀ i, NormedAddCommGroup (s i)] [∀ i, InnerProductSpace 𝕜 (s i)] + +open scoped TensorProduct ComplexOrder +open Module + +namespace PiTensorProduct + +/- `PiTensorProduct.map`/`PiTensorProduct.lift` have not (yet) been generalised to accept a +family of `σ`-semilinear maps the way the binary `TensorProduct.map`/`TensorProduct.mapBilinear` +have (upstream Mathlib generalised `MultilinearMap` and the binary `TensorProduct.map` to be +`σ`-semilinear, but did not touch `PiTensorProduct.map`/`lift`, which both remain hard-coded to +`RingHom.id`). So `dualDistrib ∘ₛₗ map (fun _ ↦ innerₛₗ 𝕜)` no longer type-checks: `map` demands a +family of plain (`RingHom.id`-)linear maps, but `innerₛₗ 𝕜` is `starRingEnd 𝕜`-semilinear. + +We instead build the "n-ary semilinear map" `innerMultilinear` by hand: +`MultilinearMap.compLinearMap` +*has* already been generalised to accept a semilinear family `f : ∀ i, M₁ i →ₛₗ[σ] M₂ i`, giving a +genuinely `σ`-semilinear `MultilinearMap σ s (⨂[𝕜] i, Dual 𝕜 (s i))` when composed with the +(`RingHom.id`-linear) `tprod`. We then use the low-level `PiTensorProduct.liftAddHom` (which only +ever demanded plain `AddMonoidHom`-style compatibility, never `RingHom.id`-linearity) to extend +this pointwise assignment `a ↦ innerAux a` to a `σ`-semilinear map on the whole of `⨂[𝕜] i, s i`, +bypassing the missing semilinear `map`/`lift` entirely. -/ + +/-- The "n-ary semilinear `tprod`", contracting each tensor factor `a i` against the +conjugate-linear functional `innerₛₗ 𝕜 : s i →ₗ⋆[𝕜] Dual 𝕜 (s i)`. -/ +noncomputable def innerMultilinear : + MultilinearMap (starRingEnd 𝕜) s (⨂[𝕜] i, Dual 𝕜 (s i)) := + (tprod 𝕜).compLinearMap (fun _i ↦ innerₛₗ 𝕜) + +/-- The tensor product of the inner-product functionals of the components of `a`. -/ +noncomputable def innerAux (a : Π i, s i) : Dual 𝕜 (⨂[𝕜] i, s i) := + dualDistrib (innerMultilinear (𝕜 := 𝕜) (s := s) a) + +private theorem innerAux_apply_tprod [Fintype ι] (a b : Π i, s i) : + innerAux a (⨂ₜ[𝕜] i, b i) = ∏ i, inner 𝕜 (a i) (b i) := by + simp [innerAux, innerMultilinear, dualDistrib_apply, innerₛₗ_apply_apply] + +private theorem innerAux_eq_zero_of_eq_zero (f : Π i, s i) (i : ι) (hf : f i = 0) : + innerAux (𝕜 := 𝕜) f = 0 := by + simp [innerAux, innerMultilinear.map_coord_zero i hf] + +private theorem innerAux_update_add [DecidableEq ι] (f : Π i, s i) (i : ι) (m₁ m₂ : s i) : + innerAux (𝕜 := 𝕜) (Function.update f i m₁) + innerAux (Function.update f i m₂) = + innerAux (Function.update f i (m₁ + m₂)) := by + simp only [innerAux, ← map_add dualDistrib, innerMultilinear.map_update_add] + +private theorem innerAux_update_smul [DecidableEq ι] (f : Π i, s i) (i : ι) (r : 𝕜) : + innerAux (𝕜 := 𝕜) (Function.update f i (r • f i)) = (starRingEnd 𝕜) r • innerAux f := by + rw [innerAux, innerMultilinear.map_update_smul, Function.update_eq_self, map_smul, innerAux] + +/-- The "n-ary semilinear lift" of `innerAux`, constructed directly via `liftAddHom` (rather than +through a semilinear `PiTensorProduct.map`/`lift`, which don't exist upstream): conjugate-additive +and conjugate-homogeneous in its argument, matching `innerAux` on the generators `tprodCoeff`. -/ +noncomputable def innerLiftAddHom : (⨂[𝕜] i, s i) →+ Dual 𝕜 (⨂[𝕜] i, s i) := + liftAddHom (fun p : 𝕜 × Π i, s i ↦ (starRingEnd 𝕜) p.1 • innerAux p.2) + (fun r f i hf ↦ by rw [innerAux_eq_zero_of_eq_zero f i hf, smul_zero]) + (fun f ↦ by rw [map_zero, zero_smul]) + (fun z f i m₁ m₂ ↦ by rw [← innerAux_update_add, smul_add]) + (fun r r' f ↦ by rw [← add_smul, map_add]) + (fun r f i r' ↦ by rw [innerAux_update_smul, smul_smul, map_mul, mul_comm]) + +private theorem innerLiftAddHom_tprodCoeff (z : 𝕜) (f : Π i, s i) : + innerLiftAddHom (tprodCoeff 𝕜 z f) = (starRingEnd 𝕜) z • innerAux f := rfl + +private theorem innerLiftAddHom_smul (r : 𝕜) (x : ⨂[𝕜] i, s i) : + innerLiftAddHom (r • x) = (starRingEnd 𝕜) r • innerLiftAddHom x := by + refine PiTensorProduct.induction_on' x ?_ ?_ + · intro z f + rw [smul_tprodCoeff' r z f, smul_eq_mul, innerLiftAddHom_tprodCoeff, + innerLiftAddHom_tprodCoeff, map_mul, mul_smul] + · intro y z ihy ihz + rw [smul_add, innerLiftAddHom.map_add, ihy, ihz, innerLiftAddHom.map_add, smul_add] + +/-- Sesquilinear map for the inner product on `⨂[𝕜] i, s i`. +On pure tensors: `innerSesquilinear (⨂ₜ a_i) (⨂ₜ b_i) = ∏ i, ⟪a_i, b_i⟫`. -/ +noncomputable def innerSesquilinear : (⨂[𝕜] i, s i) →ₗ⋆[𝕜] (⨂[𝕜] i, s i) →ₗ[𝕜] 𝕜 where + toFun x := innerLiftAddHom x + map_add' := innerLiftAddHom.map_add + map_smul' r x := by exact innerLiftAddHom_smul r x + +noncomputable instance instInner : Inner 𝕜 (⨂[𝕜] i, s i) := ⟨fun x y ↦ innerSesquilinear x y⟩ + +lemma inner_def (x y : ⨂[𝕜] i, s i) : inner 𝕜 x y = innerSesquilinear x y := rfl + +variable (𝕜) in +@[simp] theorem inner_tprod_tprod [Fintype ι] (a b : Π i, s i) : + inner 𝕜 (⨂ₜ[𝕜] i, a i) (⨂ₜ[𝕜] i, b i) = ∏ i, inner 𝕜 (a i) (b i) := by + change innerLiftAddHom (⨂ₜ[𝕜] i, a i) (⨂ₜ[𝕜] i, b i) = ∏ i, inner 𝕜 (a i) (b i) + rw [tprod_eq_tprodCoeff_one, innerLiftAddHom_tprodCoeff, map_one, one_smul] + exact innerAux_apply_tprod a b + +private theorem conj_inner_symm_aux (x y : ⨂[𝕜] i, s i) : + (starRingEnd 𝕜) (inner 𝕜 x y) = inner 𝕜 y x := by + have := Fintype.ofFinite ι + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod r' b => + rw [inner_def, inner_def] + simp only [map_smulₛₗ, LinearMap.smul_apply, RingHom.id_apply, smul_eq_mul] + simp_rw [← inner_def] + rw [inner_tprod_tprod, inner_tprod_tprod] + simp only [map_mul, map_prod, starRingEnd_self_apply] + simp_rw [← inner_conj_symm (𝕜 := 𝕜) (a _) (b _)] + simp only [starRingEnd_self_apply] + ring + | add u v hu hv => + simp only [inner_def, map_add, LinearMap.add_apply] at hu hv ⊢ + rw [hu, hv] + | add u v hu hv => + simp only [inner_def, map_add, LinearMap.add_apply] at hu hv ⊢ + rw [hu, hv] + +/-- Helper: expand `inner 𝕜 x x` for a vector `x = mapIncl M' y` lying in the image of +a finite-dimensional sub-`PiTensorProduct`, in terms of an orthonormal basis on each `M' i`. -/ +private theorem inner_self_eq_basis_sum [Fintype ι] [DecidableEq ι] {κ : ι → Type*} + [∀ i, Fintype (κ i)] (M' : Π i, Submodule 𝕜 (s i)) + (b : Π i, OrthonormalBasis (κ i) 𝕜 (M' i)) (y : ⨂[𝕜] i, M' i) : + inner 𝕜 (mapIncl M' y) (mapIncl M' y) = + ∑ p : Π i, κ i, ‖(Basis.piTensorProduct fun i ↦ (b i).toBasis).repr y p‖ ^ 2 := by + set B := Basis.piTensorProduct (fun i ↦ (b i).toBasis) with hB + have hy : y = ∑ p : Π i, κ i, B.repr y p • B p := (B.sum_repr y).symm + conv_lhs => rw [hy] + rw [inner_def, map_sum] + simp only [LinearMap.sum_apply, map_sum, map_smulₛₗ, LinearMap.smul_apply, + RingHom.id_apply, smul_eq_mul] + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun p _ ↦ ?_ + have hsq : (algebraMap ℝ 𝕜) (‖B.repr y p‖ ^ 2) = + B.repr y p * (starRingEnd 𝕜) (B.repr y p) := by + rw [RCLike.algebraMap_eq_ofReal, RCLike.ofReal_pow] + exact (RCLike.mul_conj (B.repr y p)).symm + rw [hsq] + classical + have hBp : (mapIncl M') (B p) = ⨂ₜ[𝕜] i, ((b i) (p i) : s i) := by + rw [hB, mapIncl, Basis.piTensorProduct_apply, map_tprod]; simp + have hinner : ∀ q, innerSesquilinear ((mapIncl M') (B p)) ((mapIncl M') (B q)) = + if p = q then 1 else 0 := by + intro q + have hBq : (mapIncl M') (B q) = ⨂ₜ[𝕜] i, ((b i) (q i) : s i) := by + rw [hB, mapIncl, Basis.piTensorProduct_apply, map_tprod]; simp + rw [← inner_def, hBp, hBq, inner_tprod_tprod] + simp_rw [← Submodule.coe_inner, OrthonormalBasis.inner_eq_ite] + rw [Fintype.prod_ite_zero] + simp only [Finset.prod_const_one] + congr 1 + exact propext (funext_iff (f := p) (g := q)).symm + simp_rw [hinner, mul_ite, mul_one, mul_zero] + rw [Finset.sum_ite_eq, ite_eq_left (Finset.mem_univ p)] + +private theorem inner_definite (x : ⨂[𝕜] i, s i) (hx : inner 𝕜 x x = 0) : x = 0 := by + have := Fintype.ofFinite ι + classical + obtain ⟨M', hM', hsub⟩ := + exists_finite_submodule_of_setFinite {x} (Set.finite_singleton x) + obtain ⟨y, rfl⟩ := Set.singleton_subset_iff.mp hsub + have : ∀ i, FiniteDimensional 𝕜 (M' i) := hM' + let b : Π i, OrthonormalBasis (Fin (Module.finrank 𝕜 (M' i))) 𝕜 (M' i) := + fun i ↦ stdOrthonormalBasis 𝕜 (M' i) + set B := Basis.piTensorProduct (fun i ↦ (b i).toBasis) with hB + rw [inner_self_eq_basis_sum M' b y, ← hB, RCLike.ofReal_eq_zero, + Finset.sum_eq_zero_iff_of_nonneg fun _ _ ↦ sq_nonneg _] at hx + have hzero : ∀ p, B.repr y p = 0 := fun p ↦ by + have := hx p (Finset.mem_univ p) + simpa [pow_eq_zero_iff] using this + have hy : y = 0 := by simp [B.ext_elem_iff, hzero] + rw [hy, map_zero] + +private theorem re_inner_self_nonneg (x : ⨂[𝕜] i, s i) : + 0 ≤ RCLike.re (inner 𝕜 x x) := by + have := Fintype.ofFinite ι + classical + obtain ⟨M', hM', hsub⟩ := + exists_finite_submodule_of_setFinite {x} (Set.finite_singleton x) + obtain ⟨y, rfl⟩ := Set.singleton_subset_iff.mp hsub + have : ∀ i, FiniteDimensional 𝕜 (M' i) := hM' + let b : Π i, OrthonormalBasis (Fin (Module.finrank 𝕜 (M' i))) 𝕜 (M' i) := + fun i ↦ stdOrthonormalBasis 𝕜 (M' i) + rw [inner_self_eq_basis_sum M' b y, RCLike.ofReal_re] + exact Finset.sum_nonneg fun _ _ ↦ sq_nonneg _ + +noncomputable instance instNormedAddCommGroup : NormedAddCommGroup (⨂[𝕜] i, s i) := + letI : InnerProductSpace.Core 𝕜 (⨂[𝕜] i, s i) := + { conj_inner_symm x y := by exact conj_inner_symm_aux y x + add_left _ _ _ := LinearMap.map_add₂ _ _ _ _ + smul_left _ _ _ := LinearMap.map_smulₛₗ₂ _ _ _ _ + definite x hx := by exact inner_definite x hx + re_inner_nonneg x := by exact re_inner_self_nonneg x } + this.toNormedAddCommGroup + +noncomputable instance instInnerProductSpace : InnerProductSpace 𝕜 (⨂[𝕜] i, s i) := .ofCore _ + +section Reindex + +variable {ι₂ : Type*} [Finite ι₂] + +/-- Re-indexing the tensor factors along `e : ι ≃ ι₂` preserves the inner product: +`⟪reindex e x, reindex e y⟫ = ⟪x, y⟫`. -/ +theorem inner_reindex_reindex (e : ι ≃ ι₂) (x y : ⨂[𝕜] i, s i) : + inner 𝕜 (reindex 𝕜 s e x) (reindex 𝕜 s e y) = inner 𝕜 x y := by + have := Fintype.ofFinite ι + have := Fintype.ofFinite ι₂ + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod r' b => + simp only [map_smul, inner_smul_left, inner_smul_right, reindex_tprod, + inner_tprod_tprod] + congr 2 + exact Equiv.prod_comp e.symm fun i ↦ inner 𝕜 (a i) (b i) + | add u v hu hv => + simp only [map_add, inner_add_right] at hu hv ⊢ + rw [hu, hv] + | add u v hu hv => + simp only [map_add, inner_add_left] at hu hv ⊢ + rw [hu, hv] + +variable (𝕜 s) in +/-- Re-indexing the tensor factors along `e : ι ≃ ι₂` as a linear isometry equivalence. +This is the `≃ₗᵢ` version of the linear `PiTensorProduct.reindex`. -/ +noncomputable def reindexₗᵢ (e : ι ≃ ι₂) : + (⨂[𝕜] i, s i) ≃ₗᵢ[𝕜] ⨂[𝕜] i, s (e.symm i) := + (reindex 𝕜 s e).isometryOfInner (inner_reindex_reindex e) + +@[simp] theorem reindexₗᵢ_toLinearEquiv (e : ι ≃ ι₂) : + (reindexₗᵢ 𝕜 s e).toLinearEquiv = reindex 𝕜 s e := rfl + +@[simp] theorem coe_reindexₗᵢ (e : ι ≃ ι₂) : + ⇑(reindexₗᵢ 𝕜 s e) = reindex 𝕜 s e := rfl + +@[simp] theorem reindexₗᵢ_tprod (e : ι ≃ ι₂) (f : Π i, s i) : + reindexₗᵢ 𝕜 s e (⨂ₜ[𝕜] i, f i) = ⨂ₜ[𝕜] i, f (e.symm i) := + reindex_tprod e f + +@[simp] theorem reindexₗᵢ_symm_toLinearEquiv (e : ι ≃ ι₂) : + (reindexₗᵢ 𝕜 s e).symm.toLinearEquiv = (reindex 𝕜 s e).symm := rfl + +theorem reindexₗᵢ_symm_const {M : Type*} [NormedAddCommGroup M] [InnerProductSpace 𝕜 M] + (e : ι ≃ ι₂) : (reindexₗᵢ 𝕜 (fun _ ↦ M) e).symm = reindexₗᵢ 𝕜 (fun _ ↦ M) e.symm := by + apply LinearIsometryEquiv.toLinearEquiv_injective + rw [reindexₗᵢ_symm_toLinearEquiv, reindexₗᵢ_toLinearEquiv] + exact reindex_symm e + +end Reindex + +section TmulEquiv + +variable {ι₂ : Type*} [Finite ι₂] (M : Type*) [NormedAddCommGroup M] [InnerProductSpace 𝕜 M] + +/-- Splitting the index type along `ι ⊕ ι₂` preserves the inner product: +`⟪tmulEquiv (a ⊗ b), tmulEquiv (c ⊗ d)⟫ = ⟪a ⊗ b, c ⊗ d⟫` on the `TensorProduct` of tensor +powers. -/ +theorem inner_tmulEquiv_tmulEquiv (x y : (⨂[𝕜] (_ : ι), M) ⊗[𝕜] (⨂[𝕜] (_ : ι₂), M)) : + inner 𝕜 (tmulEquiv 𝕜 M x) (tmulEquiv 𝕜 M y) = inner 𝕜 x y := by + have := Fintype.ofFinite ι + have := Fintype.ofFinite ι₂ + induction x using TensorProduct.inductionOn with + | add u v hu hv => simp only [map_add, inner_add_left, hu, hv] + | tmul xι xι₂ => + induction y using TensorProduct.inductionOn with + | add u v hu hv => simp only [map_add, inner_add_right, hu, hv] + | tmul yι yι₂ => + induction xι using PiTensorProduct.induction_on with + | smul_tprod r a => + induction xι₂ using PiTensorProduct.induction_on with + | smul_tprod r' b => + induction yι using PiTensorProduct.induction_on with + | smul_tprod t c => + induction yι₂ using PiTensorProduct.induction_on with + | smul_tprod t' d => + simp only [← TensorProduct.smul_tmul', TensorProduct.tmul_smul, map_smul, + inner_smul_left, inner_smul_right, tmulEquiv_apply, inner_tprod_tprod, + _root_.TensorProduct.inner_tmul, Fintype.prod_sum_type, Sum.elim_inl, Sum.elim_inr] + | add u v hu hv => simp only [TensorProduct.tmul_add, map_add, inner_add_right, hu, hv] + | add u v hu hv => simp only [TensorProduct.add_tmul, map_add, inner_add_right, hu, hv] + | add u v hu hv => simp only [TensorProduct.tmul_add, map_add, inner_add_left, hu, hv] + | add u v hu hv => simp only [TensorProduct.add_tmul, map_add, inner_add_left, hu, hv] + +variable (𝕜) in +/-- Splitting the index type along `ι ⊕ ι₂` as a linear isometry equivalence. +This is the `≃ₗᵢ` version of the linear `PiTensorProduct.tmulEquiv` for a constant family. -/ +noncomputable def tmulEquivₗᵢ : + (⨂[𝕜] (_ : ι), M) ⊗[𝕜] (⨂[𝕜] (_ : ι₂), M) ≃ₗᵢ[𝕜] ⨂[𝕜] (_ : ι ⊕ ι₂), M where + toLinearEquiv := tmulEquiv 𝕜 M + norm_map' x := by + rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜), norm_eq_sqrt_re_inner (𝕜 := 𝕜), + inner_tmulEquiv_tmulEquiv M x x] + +@[simp] theorem tmulEquivₗᵢ_toLinearEquiv : + (tmulEquivₗᵢ 𝕜 M (ι := ι) (ι₂ := ι₂)).toLinearEquiv = tmulEquiv 𝕜 M := rfl + +@[simp] theorem coe_tmulEquivₗᵢ : + ⇑(tmulEquivₗᵢ 𝕜 M (ι := ι) (ι₂ := ι₂)) = tmulEquiv 𝕜 M := rfl + +@[simp] theorem tmulEquivₗᵢ_tprod (a : ι → M) (b : ι₂ → M) : + tmulEquivₗᵢ 𝕜 M ((⨂ₜ[𝕜] i, a i) ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, b i)) = ⨂ₜ[𝕜] i, Sum.elim a b i := + tmulEquiv_apply 𝕜 M a b + +@[simp] theorem tmulEquivₗᵢ_symm_tprod (a : ι ⊕ ι₂ → M) : + (tmulEquivₗᵢ 𝕜 M).symm (⨂ₜ[𝕜] i, a i) = + (⨂ₜ[𝕜] i, a (Sum.inl i)) ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, a (Sum.inr i)) := + tmulEquiv_symm_apply 𝕜 M a + +end TmulEquiv + +section TmulEquivDep + +variable {ι₂ : Type*} [Finite ι₂] (N : ι ⊕ ι₂ → Type*) + [∀ i, NormedAddCommGroup (N i)] [∀ i, InnerProductSpace 𝕜 (N i)] + +/-- Splitting the index type along `ι ⊕ ι₂` preserves the inner product, for a dependent family: +`⟪tmulEquivDep (a ⊗ b), tmulEquivDep (c ⊗ d)⟫ = ⟪a ⊗ b, c ⊗ d⟫` on the `TensorProduct` of tensor +powers over `N ∘ Sum.inl` and `N ∘ Sum.inr`. -/ +theorem inner_tmulEquivDep_tmulEquivDep + (x y : (⨂[𝕜] i, N (.inl i)) ⊗[𝕜] (⨂[𝕜] i, N (.inr i))) : + inner 𝕜 (tmulEquivDep 𝕜 N x) (tmulEquivDep 𝕜 N y) = inner 𝕜 x y := by + have := Fintype.ofFinite ι + have := Fintype.ofFinite ι₂ + induction x using TensorProduct.inductionOn with + | add u v hu hv => simp only [map_add, inner_add_left, hu, hv] + | tmul xι xι₂ => + induction y using TensorProduct.inductionOn with + | add u v hu hv => simp only [map_add, inner_add_right, hu, hv] + | tmul yι yι₂ => + induction xι using PiTensorProduct.induction_on with + | smul_tprod r a => + induction xι₂ using PiTensorProduct.induction_on with + | smul_tprod r' b => + induction yι using PiTensorProduct.induction_on with + | smul_tprod t c => + induction yι₂ using PiTensorProduct.induction_on with + | smul_tprod t' d => + rw [TensorProduct.inner_tmul, TensorProduct.smul_tmul_smul, + TensorProduct.smul_tmul_smul] + simp only [map_smul, map_mul, inner_smul_left, inner_smul_right, + tmulEquivDep_apply, inner_tprod_tprod, Fintype.prod_sum_type] + ring + | add u v hu hv => simp only [TensorProduct.tmul_add, map_add, inner_add_right, hu, hv] + | add u v hu hv => simp only [TensorProduct.add_tmul, map_add, inner_add_right, hu, hv] + | add u v hu hv => simp only [TensorProduct.tmul_add, map_add, inner_add_left, hu, hv] + | add u v hu hv => simp only [TensorProduct.add_tmul, map_add, inner_add_left, hu, hv] + +variable (𝕜) in +/-- Splitting the index type along `ι ⊕ ι₂` as a linear isometry equivalence, for a dependent +family `N : ι ⊕ ι₂ → Type*`. This is the `≃ₗᵢ` version of the linear +`PiTensorProduct.tmulEquivDep`. For a constant family use `PiTensorProduct.tmulEquivₗᵢ`. + +Built as a record (rather than via `LinearEquiv.isometryOfInner`) to keep the underlying +`tmulEquivDep` opaque: `isometryOfInner` would unfold the large `ofLinear` body during defeq +checking. -/ +noncomputable def tmulEquivDepₗᵢ : + (⨂[𝕜] i, N (.inl i)) ⊗[𝕜] (⨂[𝕜] i, N (.inr i)) ≃ₗᵢ[𝕜] ⨂[𝕜] i, N i where + toLinearEquiv := tmulEquivDep 𝕜 N + norm_map' x := by + rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜), norm_eq_sqrt_re_inner (𝕜 := 𝕜), + inner_tmulEquivDep_tmulEquivDep N x x] + +@[simp] theorem tmulEquivDepₗᵢ_toLinearEquiv : + (tmulEquivDepₗᵢ 𝕜 N).toLinearEquiv = tmulEquivDep 𝕜 N := rfl + +@[simp] theorem coe_tmulEquivDepₗᵢ : + ⇑(tmulEquivDepₗᵢ 𝕜 N) = tmulEquivDep 𝕜 N := rfl + +@[simp] theorem tmulEquivDepₗᵢ_tprod (a : Π i, N (.inl i)) (b : Π i, N (.inr i)) : + tmulEquivDepₗᵢ 𝕜 N ((⨂ₜ[𝕜] i, a i) ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, b i)) = ⨂ₜ[𝕜] i, Sum.rec a b i := + tmulEquivDep_apply 𝕜 N a b + +@[simp] theorem tmulEquivDepₗᵢ_symm_tprod (f : Π i, N i) : + (tmulEquivDepₗᵢ 𝕜 N).symm (⨂ₜ[𝕜] i, f i) = + (⨂ₜ[𝕜] i, f (.inl i)) ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, f (.inr i)) := + tmulEquivDep_symm_apply 𝕜 N f + +end TmulEquivDep + +section Subsingleton + +variable [Subsingleton ι] (i₀ : ι) + +/-- On a subsingleton index type, the single-factor inner product is preserved: +`⟪subsingletonEquiv i₀ x, subsingletonEquiv i₀ y⟫ = ⟪x, y⟫`. -/ +theorem inner_subsingletonEquiv_subsingletonEquiv (x y : ⨂[𝕜] i, s i) : + inner 𝕜 (subsingletonEquiv i₀ x) (subsingletonEquiv i₀ y) = inner 𝕜 x y := by + have := Fintype.ofFinite ι + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod r' b => + simp only [map_smul, inner_smul_left, inner_smul_right, subsingletonEquiv_apply_tprod, + inner_tprod_tprod, Fintype.prod_subsingleton _ i₀] + | add u v hu hv => simp only [map_add, inner_add_right, hu, hv] + | add u v hu hv => simp only [map_add, inner_add_left, hu, hv] + +variable (𝕜 s) in +/-- The tensor power over a subsingleton index type, as a linear isometry equivalence to the single +factor `s i₀`. This is the `≃ₗᵢ` version of the linear `PiTensorProduct.subsingletonEquiv`. -/ +noncomputable def subsingletonEquivₗᵢ : (⨂[𝕜] i, s i) ≃ₗᵢ[𝕜] s i₀ := + (subsingletonEquiv i₀).isometryOfInner (inner_subsingletonEquiv_subsingletonEquiv i₀) + +@[simp] theorem subsingletonEquivₗᵢ_toLinearEquiv : + (subsingletonEquivₗᵢ 𝕜 s i₀).toLinearEquiv = subsingletonEquiv i₀ := rfl + +@[simp] theorem coe_subsingletonEquivₗᵢ : + ⇑(subsingletonEquivₗᵢ 𝕜 s i₀) = subsingletonEquiv i₀ := rfl + +@[simp] theorem subsingletonEquivₗᵢ_tprod (f : Π i, s i) : + subsingletonEquivₗᵢ 𝕜 s i₀ (⨂ₜ[𝕜] i, f i) = f i₀ := + subsingletonEquiv_apply_tprod i₀ f + +end Subsingleton + +section Congr + +variable {t : ι → Type*} [∀ i, NormedAddCommGroup (t i)] [∀ i, InnerProductSpace 𝕜 (t i)] + +/-- Applying a family of linear isometry equivalences factor-wise preserves the inner product: +`⟪congr e x, congr e y⟫ = ⟪x, y⟫`. -/ +theorem inner_congr_congr (e : ∀ i, s i ≃ₗᵢ[𝕜] t i) (x y : ⨂[𝕜] i, s i) : + inner 𝕜 (congr (fun i ↦ (e i).toLinearEquiv) x) (congr (fun i ↦ (e i).toLinearEquiv) y) + = inner 𝕜 x y := by + have := Fintype.ofFinite ι + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod r' b => + simp only [map_smul, inner_smul_left, inner_smul_right, congr_tprod, inner_tprod_tprod] + congr 2 + exact Finset.prod_congr rfl fun i _ ↦ (e i).inner_map_map (a i) (b i) + | add u v hu hv => + simp only [map_add, inner_add_right] at hu hv ⊢ + rw [hu, hv] + | add u v hu hv => + simp only [map_add, inner_add_left] at hu hv ⊢ + rw [hu, hv] + +variable (𝕜) in +/-- Applying a family of linear isometry equivalences factor-wise, as a linear isometry +equivalence `⨂[𝕜] i, s i ≃ₗᵢ ⨂[𝕜] i, t i`. The `≃ₗᵢ` version of `PiTensorProduct.congr`. -/ +noncomputable def congrₗᵢ (e : ∀ i, s i ≃ₗᵢ[𝕜] t i) : + (⨂[𝕜] i, s i) ≃ₗᵢ[𝕜] ⨂[𝕜] i, t i := + (congr (fun i ↦ (e i).toLinearEquiv)).isometryOfInner (inner_congr_congr e) + +@[simp] theorem congrₗᵢ_toLinearEquiv (e : ∀ i, s i ≃ₗᵢ[𝕜] t i) : + (congrₗᵢ 𝕜 e).toLinearEquiv = congr (fun i ↦ (e i).toLinearEquiv) := rfl + +@[simp] theorem coe_congrₗᵢ (e : ∀ i, s i ≃ₗᵢ[𝕜] t i) : + ⇑(congrₗᵢ 𝕜 e) = congr (fun i ↦ (e i).toLinearEquiv) := rfl + +@[simp] theorem congrₗᵢ_tprod (e : ∀ i, s i ≃ₗᵢ[𝕜] t i) (f : ∀ i, s i) : + congrₗᵢ 𝕜 e (⨂ₜ[𝕜] i, f i) = ⨂ₜ[𝕜] i, e i (f i) := by + simp only [congrₗᵢ, LinearEquiv.coe_isometryOfInner, congr_tprod, + LinearIsometryEquiv.coe_toLinearEquiv] + +end Congr + +section Cons + +variable {M : Type*} [NormedAddCommGroup M] [InnerProductSpace 𝕜 M] (n : ℕ) + +/-- The index equivalence `Fin (n + 1) ≃ Fin 1 ⊕ Fin n` sending `0` to the left factor and each +`Fin.succ i` to the right factor. Used to peel the head factor off a tensor power. -/ +def consSumEquiv : Fin (n + 1) ≃ Fin 1 ⊕ Fin n := + (finCongr (Nat.add_comm n 1)).trans finSumFinEquiv.symm + +@[simp] theorem consSumEquiv_symm_inl (i : Fin 1) : (consSumEquiv n).symm (Sum.inl i) = 0 := by + simp [consSumEquiv, Fin.ext_iff] + +@[simp] theorem consSumEquiv_symm_inr (i : Fin n) : + (consSumEquiv n).symm (Sum.inr i) = i.succ := by + simp [consSumEquiv, finSumFinEquiv, Fin.succ] + +variable (𝕜 M) in +/-- **Head-peel isometry**: peeling the first factor off a tensor power over `Fin (n + 1)`, +as a linear isometry equivalence +`⨂[𝕜] (_ : Fin (n + 1)), M ≃ₗᵢ M ⊗[𝕜] (⨂[𝕜] (_ : Fin n), M)`. +On pure tensors: `⨂ₜ f ↦ f 0 ⊗ₜ ⨂ₜ (f ∘ Fin.succ)`. -/ +noncomputable def consEquivₗᵢ : + (⨂[𝕜] (_ : Fin (n + 1)), M) ≃ₗᵢ[𝕜] M ⊗[𝕜] (⨂[𝕜] (_ : Fin n), M) := + (reindexₗᵢ 𝕜 (fun _ ↦ M) (consSumEquiv n)).trans + ((tmulEquivₗᵢ 𝕜 M (ι := Fin 1) (ι₂ := Fin n)).symm.trans + ((subsingletonEquivₗᵢ 𝕜 (fun _ ↦ M) (0 : Fin 1)).rTensor (⨂[𝕜] (_ : Fin n), M))) + +@[simp] theorem consEquivₗᵢ_tprod (f : Fin (n + 1) → M) : + consEquivₗᵢ 𝕜 M n (⨂ₜ[𝕜] i, f i) = f 0 ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, f i.succ) := by + simp only [consEquivₗᵢ, LinearIsometryEquiv.trans_apply, coe_reindexₗᵢ, reindex_tprod, + tmulEquivₗᵢ_symm_tprod, LinearIsometryEquiv.rTensor_apply, LinearEquiv.rTensor_tmul, + subsingletonEquivₗᵢ_toLinearEquiv, subsingletonEquiv_apply_tprod, consSumEquiv_symm_inl, + consSumEquiv_symm_inr] + +@[simp] theorem consEquivₗᵢ_symm_tmul (m : M) (g : Fin n → M) : + (consEquivₗᵢ 𝕜 M n).symm (m ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, g i)) = + ⨂ₜ[𝕜] i, (Fin.cons m g : Fin (n + 1) → M) i := by + apply (consEquivₗᵢ 𝕜 M n).injective + rw [LinearIsometryEquiv.apply_symm_apply, consEquivₗᵢ_tprod, Fin.cons_zero] + simp [Fin.cons_succ] + +/-- Transport a factor along an index equality, as a linear isometry equivalence. Bridges the +non-defeq codomain families in `consEquivDepₗᵢ` (`consSumEquiv_symm_inl`/`_inr` are not `rfl`). -/ +noncomputable def indexCastₗᵢ {ι' : Type*} {P : ι' → Type*} + [∀ i, NormedAddCommGroup (P i)] [∀ i, InnerProductSpace 𝕜 (P i)] {a b : ι'} (h : a = b) : + P a ≃ₗᵢ[𝕜] P b := + h ▸ LinearIsometryEquiv.refl 𝕜 (P a) + +variable {N : Fin (n + 1) → Type*} [∀ i, NormedAddCommGroup (N i)] + [∀ i, InnerProductSpace 𝕜 (N i)] + +variable (𝕜 N) in +/-- **Dependent head-peel isometry**: peeling the first factor off a tensor power over +`Fin (n + 1)` for a dependent family `N`, as a linear isometry equivalence +`⨂[𝕜] (i : Fin (n + 1)), N i ≃ₗᵢ N 0 ⊗[𝕜] (⨂[𝕜] (i : Fin n), N i.succ)`. +The dependent-family analogue of `consEquivₗᵢ`; the non-defeq codomain factor families (arising +because `consSumEquiv_symm_inl`/`_inr` are not `rfl`) are bridged by `indexCastₗᵢ` / `congrₗᵢ`. -/ +noncomputable def consEquivDepₗᵢ : + (⨂[𝕜] (i : Fin (n + 1)), N i) ≃ₗᵢ[𝕜] N 0 ⊗[𝕜] (⨂[𝕜] (i : Fin n), N i.succ) := + (reindexₗᵢ 𝕜 N (consSumEquiv n)).trans + ((tmulEquivDepₗᵢ 𝕜 (fun j ↦ N ((consSumEquiv n).symm j))).symm.trans + (TensorProduct.congrIsometry + ((subsingletonEquivₗᵢ 𝕜 (fun j ↦ N ((consSumEquiv n).symm (Sum.inl j))) 0).trans + (indexCastₗᵢ (consSumEquiv_symm_inl n 0))) + (congrₗᵢ 𝕜 (fun i ↦ indexCastₗᵢ (consSumEquiv_symm_inr n i))))) + +@[simp] theorem indexCastₗᵢ_apply {ι' : Type*} {P : ι' → Type*} + [∀ i, NormedAddCommGroup (P i)] [∀ i, InnerProductSpace 𝕜 (P i)] {a b : ι'} (h : a = b) + (g : ∀ i, P i) : indexCastₗᵢ (𝕜 := 𝕜) h (g a) = g b := by subst h; rfl + +variable (𝕜 N) in +@[simp] theorem consEquivDepₗᵢ_tprod (f : ∀ i, N i) : + consEquivDepₗᵢ 𝕜 n N (⨂ₜ[𝕜] i, f i) = f 0 ⊗ₜ[𝕜] (⨂ₜ[𝕜] (i : Fin n), f i.succ) := by + simp only [consEquivDepₗᵢ, LinearIsometryEquiv.trans_apply, coe_reindexₗᵢ, reindex_tprod, + tmulEquivDepₗᵢ_symm_tprod, TensorProduct.congrIsometry_tmul, subsingletonEquivₗᵢ_tprod, + congrₗᵢ_tprod, indexCastₗᵢ_apply] + +variable (𝕜 N) in +@[simp] theorem consEquivDepₗᵢ_symm_tmul (m : N 0) (g : ∀ i : Fin n, N i.succ) : + (consEquivDepₗᵢ 𝕜 n N).symm (m ⊗ₜ[𝕜] (⨂ₜ[𝕜] i, g i)) = + ⨂ₜ[𝕜] i, (Fin.cons m g : ∀ i, N i) i := by + apply (consEquivDepₗᵢ 𝕜 n N).injective + rw [LinearIsometryEquiv.apply_symm_apply, consEquivDepₗᵢ_tprod, Fin.cons_zero] + simp [Fin.cons_succ] + +end Cons + +end PiTensorProduct + +section OrthonormalBasis + +variable {κ : ι → Type*} + +/-- The n-ary tensor of orthonormal families is orthonormal. -/ +theorem Orthonormal.tprod {b : Π i, κ i → s i} (hb : ∀ i, Orthonormal 𝕜 (b i)) : + Orthonormal 𝕜 fun p : Π i, κ i ↦ ⨂ₜ[𝕜] i, b i (p i) := by + classical + have := Fintype.ofFinite ι + rw [orthonormal_iff_ite] + intro p q + rw [PiTensorProduct.inner_tprod_tprod] + simp_rw [orthonormal_iff_ite.mp (hb _)] + simp [Fintype.prod_ite_zero, ← funext_iff] + +/-- The n-ary tensor of orthonormal bases gives an orthonormal family on the +`PiTensorProduct`. -/ +theorem Orthonormal.basisPiTensorProduct {b : Π i, Basis (κ i) 𝕜 (s i)} + (hb : ∀ i, Orthonormal 𝕜 (b i)) : Orthonormal 𝕜 (Basis.piTensorProduct b) := by + have := Fintype.ofFinite ι + convert Orthonormal.tprod hb using 1 + exact funext fun p ↦ Basis.piTensorProduct_apply b p + +namespace OrthonormalBasis + +variable [Fintype ι] [DecidableEq ι] [∀ i, Fintype (κ i)] + +/-- The orthonormal basis of `⨂[𝕜] i, s i` from a family of orthonormal bases. -/ +protected noncomputable def piTensorProduct (b : Π i, OrthonormalBasis (κ i) 𝕜 (s i)) : + OrthonormalBasis (Π i, κ i) 𝕜 (⨂[𝕜] i, s i) := + (Basis.piTensorProduct (fun i ↦ (b i).toBasis)).toOrthonormalBasis + (Orthonormal.basisPiTensorProduct (fun i ↦ (b i).orthonormal)) + +theorem piTensorProduct_eq (b : Π i, OrthonormalBasis (κ i) 𝕜 (s i)) : + OrthonormalBasis.piTensorProduct b = + (Basis.piTensorProduct (fun i ↦ (b i).toBasis)).toOrthonormalBasis + (Orthonormal.basisPiTensorProduct (fun i ↦ (b i).orthonormal)) := rfl + +@[simp] +lemma piTensorProduct_apply (b : Π i, OrthonormalBasis (κ i) 𝕜 (s i)) (p : Π i, κ i) : + OrthonormalBasis.piTensorProduct b p = ⨂ₜ[𝕜] i, b i (p i) := by + simp [piTensorProduct_eq, Module.Basis.coe_toOrthonormalBasis, Basis.piTensorProduct_apply] + +@[simp] +lemma toBasis_piTensorProduct (b : Π i, OrthonormalBasis (κ i) 𝕜 (s i)) : + (OrthonormalBasis.piTensorProduct b).toBasis = + Basis.piTensorProduct (fun i ↦ (b i).toBasis) := by + rw [piTensorProduct_eq, Module.Basis.toBasis_toOrthonormalBasis] + +end OrthonormalBasis + +end OrthonormalBasis diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductDensity.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductDensity.lean new file mode 100644 index 0000000000..6102457df4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductDensity.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! +# The n-ary tensor map preserves positivity and density operators + +For a finite family of positive (resp. density) operators, the n-ary tensor map +`PiTensorProduct.mapCLM` produces a positive (resp. density) operator. + +## Main results + +* `PiTensorProduct.mapCLM_isPositive` / `PiTensorProduct.mapCLM_nonneg` +* `PiTensorProduct.mapCLM_isDensityOp` — `⨂ᵢ ρᵢ` is a density operator when each `ρᵢ` is. +-/ + +@[expose] public section + +namespace PiTensorProduct + +variable {ι : Type*} [Finite ι] + {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, InnerProductSpace ℂ (E i)] + [∀ i, FiniteDimensional ℂ (E i)] [∀ i, CompleteSpace (E i)] + +/-- **The n-ary tensor map preserves positivity**: if each `f i` is positive, so is `mapCLM f`. +Via `f i = (√(f i))† ∘ √(f i)` (CFC square root), `mapCLM` functoriality/adjoint compatibility, +and `S† ∘ S ≥ 0`. -/ +theorem mapCLM_isPositive {f : ∀ i, E i →L[ℂ] E i} (h : ∀ i, (f i).IsPositive) : + (mapCLM f).IsPositive := by + have key : mapCLM f = + (ContinuousLinearMap.adjoint (mapCLM fun i ↦ CFC.sqrt (f i))).comp + (mapCLM fun i ↦ CFC.sqrt (f i)) := by + rw [mapCLM_adjoint, ← mapCLM_comp] + congr 1 + funext i + have hnn : (0 : E i →L[ℂ] E i) ≤ f i := (ContinuousLinearMap.nonneg_iff_isPositive).mpr (h i) + have hadj : ContinuousLinearMap.adjoint (CFC.sqrt (f i)) = CFC.sqrt (f i) := by + rw [← ContinuousLinearMap.star_eq_adjoint] + exact ((ContinuousLinearMap.nonneg_iff_isPositive).mp (CFC.sqrt_nonneg (f i))).isSelfAdjoint + rw [hadj, ← ContinuousLinearMap.mul_def] + exact (CFC.sqrt_mul_sqrt_self (f i) hnn).symm + rw [key] + exact ContinuousLinearMap.isPositive_adjoint_comp_self _ + +/-- **The n-ary tensor map preserves the Loewner order at `0`**: `0 ≤ mapCLM f` when each +`0 ≤ f i`. The order-form companion of `mapCLM_isPositive` (cf. `TensorProduct.mapL_nonneg`). -/ +theorem mapCLM_nonneg {f : ∀ i, E i →L[ℂ] E i} (h : ∀ i, 0 ≤ f i) : 0 ≤ mapCLM f := + (ContinuousLinearMap.nonneg_iff_isPositive).mpr + (mapCLM_isPositive fun i ↦ (ContinuousLinearMap.nonneg_iff_isPositive).mp (h i)) + +/-- **The n-ary tensor map preserves density operators**: `⨂ᵢ ρᵢ` is a density operator when +each `ρ i` is. Positivity from `mapCLM_isPositive`; trace `1` from `mapCLM_trace` +(`Tr (⨂ ρᵢ) = ∏ Tr ρᵢ = ∏ 1 = 1`). -/ +theorem mapCLM_isDensityOp {f : ∀ i, E i →L[ℂ] E i} (h : ∀ i, (f i).IsDensityOp) : + (mapCLM f).IsDensityOp := by + have := Fintype.ofFinite ι + refine ⟨mapCLM_isPositive fun i ↦ (h i).1, ?_⟩ + rw [mapCLM_trace] + exact Finset.prod_eq_one fun i _ ↦ (h i).2 + +end PiTensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductMap.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductMap.lean new file mode 100644 index 0000000000..e42ff78ce3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PiTensorProductMap.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace + +/-! +# The n-ary tensor map on inner product spaces and its adjoint + +For a finite family of continuous linear maps `f i : E i →L[𝕜] E' i` between finite-dimensional +inner product spaces, `PiTensorProduct.mapCLM f : (⨂ᵢ Eᵢ) →L[𝕜] ⨂ᵢ E'ᵢ` is the induced +continuous linear map, `⨂ aᵢ ↦ ⨂ (f i) aᵢ`. + +This is the **inner-product-native** companion of `PiTensorProduct.mapL` (which lives on the +projective-seminorm normed structure): built as the finite-dimensional `.toContinuousLinearMap` +of the algebraic `PiTensorProduct.map`, it lands on the inner-product `NormedAddCommGroup` +instance, so it is compatible with `ContinuousLinearMap.adjoint` / the tensor inner product — +avoiding the norm-instance diamond between the two structures. + +## Main results + +* `PiTensorProduct.mapCLM` — the induced continuous linear map. +* `PiTensorProduct.mapCLM_adjoint` — `(mapCLM f)† = mapCLM (fun i ↦ (f i)†)`. +* `PiTensorProduct.mapCLM_trace` — `Tr (mapCLM f) = ∏ᵢ Tr (f i)`. +* `PiTensorProduct.reindexₗᵢ_mapCLM` — naturality of `mapCLM` under reindexing. +-/ + +@[expose] public section + +namespace PiTensorProduct + +open scoped TensorProduct InnerProductSpace + +variable {ι : Type*} [Finite ι] {𝕜 : Type*} [RCLike 𝕜] + {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, InnerProductSpace 𝕜 (E i)] + [∀ i, FiniteDimensional 𝕜 (E i)] + +instance instFiniteDimensionalPiTensor : FiniteDimensional 𝕜 (⨂[𝕜] i, E i) := + Module.Basis.finiteDimensional_of_finite (Basis.piTensorProduct fun i ↦ Module.finBasis 𝕜 (E i)) + +instance instCompleteSpacePiTensor : CompleteSpace (⨂[𝕜] i, E i) := + FiniteDimensional.completeSpace 𝕜 _ + +variable {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] [∀ i, InnerProductSpace 𝕜 (E' i)] + [∀ i, FiniteDimensional 𝕜 (E' i)] + +/-- **The n-ary tensor map** `⨂ aᵢ ↦ ⨂ (f i) aᵢ` as a continuous linear map on the +inner-product tensor products. The finite-dimensional `.toContinuousLinearMap` of the algebraic +`PiTensorProduct.map`; lives on the inner-product normed structure (unlike `PiTensorProduct.mapL`, +which uses the projective seminorm). -/ +noncomputable def mapCLM (f : ∀ i, E i →L[𝕜] E' i) : (⨂[𝕜] i, E i) →L[𝕜] ⨂[𝕜] i, E' i := + LinearMap.toContinuousLinearMap (PiTensorProduct.map fun i ↦ (f i : E i →ₗ[𝕜] E' i)) + +omit [∀ i, FiniteDimensional 𝕜 (E' i)] in +@[simp] +theorem mapCLM_tprod (f : ∀ i, E i →L[𝕜] E' i) (x : ∀ i, E i) : + mapCLM f (⨂ₜ[𝕜] i, x i) = ⨂ₜ[𝕜] i, f i (x i) := by + simp [mapCLM, PiTensorProduct.map_tprod] + +@[simp] +theorem mapCLM_id : + mapCLM (fun i ↦ ContinuousLinearMap.id 𝕜 (E i)) = ContinuousLinearMap.id 𝕜 (⨂[𝕜] i, E i) := by + ext x + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => simp + | add x y hx hy => simp [hx, hy] + +/-- **The adjoint of the n-ary tensor map is the n-ary tensor map of the adjoints:** +`(mapCLM f)† = mapCLM (fun i ↦ (f i)†)`. Verified on elementary tensors via the multiplicativity +of the tensor inner product (`inner_tprod_tprod`) and the defining property of each factor's +adjoint. -/ +theorem mapCLM_adjoint [∀ i, CompleteSpace (E i)] [∀ i, CompleteSpace (E' i)] + (f : ∀ i, E i →L[𝕜] E' i) : + ContinuousLinearMap.adjoint (mapCLM f) = + mapCLM (fun i ↦ ContinuousLinearMap.adjoint (f i)) := by + have := Fintype.ofFinite ι + symm + refine (ContinuousLinearMap.eq_adjoint_iff _ _).mpr fun x y ↦ ?_ + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod s b => + simp only [map_smul, inner_smul_left, inner_smul_right, mapCLM_tprod, inner_tprod_tprod] + congr 2 + exact Finset.prod_congr rfl fun i _ ↦ + ContinuousLinearMap.adjoint_inner_left (f i) (b i) (a i) + | add y₁ y₂ hy₁ hy₂ => simp only [map_add, inner_add_right, hy₁, hy₂] + | add x₁ x₂ hx₁ hx₂ => simp only [map_add, inner_add_left, hx₁, hx₂] + +/-- **The trace of the n-ary tensor map is the product of the factor traces:** +`Tr (mapCLM f) = ∏ᵢ Tr (f i)`. Computed in the tensor-product orthonormal basis +(`OrthonormalBasis.piTensorProduct`) via `inner_tprod_tprod` and the product-of-sums expansion +`Finset.prod_univ_sum`. -/ +-- `[Fintype ι]` (rather than the file's `[Finite ι]` + `Fintype.ofFinite ι`): the `∏ i` in the +-- statement needs it at elaboration time, and the `Fintype.ofFinite` route yields a noncomputable +-- `Fintype` that blocks synthesis of `DecidableEq ι` / `Fintype (∀ i, Fin _)` in the proof. +theorem mapCLM_trace [Fintype ι] (f : ∀ i, E i →L[𝕜] E i) : + LinearMap.trace 𝕜 (⨂[𝕜] i, E i) (mapCLM f).toLinearMap = + ∏ i, LinearMap.trace 𝕜 (E i) (f i).toLinearMap := by + classical + rw [LinearMap.trace_eq_sum_inner _ + (OrthonormalBasis.piTensorProduct fun i ↦ stdOrthonormalBasis 𝕜 (E i))] + simp_rw [fun i ↦ LinearMap.trace_eq_sum_inner (f i).toLinearMap (stdOrthonormalBasis 𝕜 (E i))] + rw [Finset.prod_univ_sum] + refine Finset.sum_congr Fintype.piFinset_univ.symm fun p _ ↦ ?_ + rw [OrthonormalBasis.piTensorProduct_apply, ContinuousLinearMap.coe_coe, mapCLM_tprod, + inner_tprod_tprod] + simp only [ContinuousLinearMap.coe_coe] + +omit [∀ i, FiniteDimensional 𝕜 (E' i)] in +/-- **Naturality of `mapCLM` under reindexing**: reindexing the tensor factors intertwines the +tensor maps, `reindexₗᵢ e (mapCLM f x) = mapCLM (fun j ↦ f (e.symm j)) (reindexₗᵢ e x)`. The +inner-product-native (`mapCLM`/`reindexₗᵢ`) analogue of the algebraic +`PiTensorProduct.map_comp_reindex_eq`. -/ +theorem reindexₗᵢ_mapCLM {κ : Type*} [Finite κ] (e : ι ≃ κ) (f : ∀ i, E i →L[𝕜] E' i) + (x : ⨂[𝕜] i, E i) : + reindexₗᵢ 𝕜 E' e (mapCLM f x) = mapCLM (fun j ↦ f (e.symm j)) (reindexₗᵢ 𝕜 E e x) := by + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + simp only [map_smul, PiTensorProduct.reindexₗᵢ_tprod, mapCLM_tprod] + | add x y hx hy => simp only [map_add, hx, hy] + +variable {E'' : ι → Type*} [∀ i, NormedAddCommGroup (E'' i)] [∀ i, InnerProductSpace 𝕜 (E'' i)] + [∀ i, FiniteDimensional 𝕜 (E'' i)] + +omit [∀ i, FiniteDimensional 𝕜 (E'' i)] in +theorem mapCLM_comp (g : ∀ i, E' i →L[𝕜] E'' i) (f : ∀ i, E i →L[𝕜] E' i) : + mapCLM (fun i ↦ (g i).comp (f i)) = (mapCLM g).comp (mapCLM f) := by + ext x + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => simp + | add x y hx hy => simp [hx, hy] + +end PiTensorProduct + +namespace ContinuousLinearMap + +open scoped TensorProduct InnerProductSpace + +variable {ι : Type*} [Finite ι] {𝕜 : Type*} [RCLike 𝕜] + {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, InnerProductSpace 𝕜 (E i)] + [∀ i, FiniteDimensional 𝕜 (E i)] + {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] + +omit [∀ i, FiniteDimensional 𝕜 (E i)] in +/-- **Extensionality via elementary tensors for continuous linear maps out of a pi-tensor product.** +Two continuous linear maps `f g : (⨂[𝕜] i, E i) →L[𝕜] F` out of a finite tensor product of inner +product spaces are equal as soon as they agree on every elementary tensor `⨂ₜ[𝕜] i, x i`. The +elementary tensors span the tensor product and a continuous linear map is determined by its +underlying linear map (`ContinuousLinearMap.coe_injective`, `PiTensorProduct.ext`). -/ +theorem ext_tprod {f g : (⨂[𝕜] i, E i) →L[𝕜] F} + (h : ∀ x : ∀ i, E i, f (⨂ₜ[𝕜] i, x i) = g (⨂ₜ[𝕜] i, x i)) : f = g := by + apply ContinuousLinearMap.coe_injective + apply PiTensorProduct.ext + apply MultilinearMap.ext + intro x + simp only [LinearMap.compMultilinearMap_apply] + exact h x + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Polar.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Polar.lean new file mode 100644 index 0000000000..0cfaa1bc7c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Polar.lean @@ -0,0 +1,417 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive + +/-! + +# Polar decomposition of a finite-dimensional operator + +For `T : E →L[𝕜] F` a continuous linear map between finite-dimensional inner product spaces +(possibly with `E ≠ F`), this file constructs the **polar decomposition** `T = U |T|`, where: + +* `T.absoluteValue : E →L[𝕜] E` is the positive operator `|T|` on the source space such + that `|T|² = T† ∘ T`. +* `T.polarPart : E →L[𝕜] F` is the operator `U` (a partial isometry) satisfying + `T = U ∘L |T|`. + +The construction uses the singular value decomposition `T = ∑ σᵢ • rankOne vᵢ uᵢ` +(`LinearMap.svd_apply`): +* `|T| := ∑ σᵢ • rankOne uᵢ uᵢ` (using only the right singular vectors `uᵢ ∈ E`). +* `U := ∑ rankOne vᵢ uᵢ` (sending each right singular vector `uᵢ ∈ E` to the + corresponding left singular vector `vᵢ ∈ F`). + +## Main results + +* `ContinuousLinearMap.polar_decomposition`: `T = T.polarPart ∘L T.absoluteValue`. +* `ContinuousLinearMap.absoluteValue_isPositive`: `T.absoluteValue.IsPositive`. +* `ContinuousLinearMap.absoluteValue_nonneg`: `0 ≤ T.absoluteValue`. +* `ContinuousLinearMap.absoluteValue_sq`: `T.absoluteValue ∘L T.absoluteValue = T† ∘L T`, + the canonical characterization of `|T|`. +* `ContinuousLinearMap.polarPart_isPartialIsometry`: `polarPart T ∘L (polarPart T)† ∘L + polarPart T = polarPart T`, the partial-isometry characterization. +* `ContinuousLinearMap.polar_decomposition_unique`: if `T = U' ∘L P'` with `P'` positive, + `U'` a partial isometry, and `kernel U' = kernel P'`, then `P' = absoluteValue T` and + `U' = polarPart T`. + +The square case `E = F` is the most common in textbook references; the general rectangular +case `E ≠ F` arises in SVD-via-polar applications and operator algebras over inhomogeneous +Hilbert spaces. + +-/ + +@[expose] public section + +variable {𝕜 E F : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +open Module InnerProductSpace +open scoped InnerProduct + +namespace ContinuousLinearMap + +variable (T : E →L[𝕜] F) + +/-- The **absolute value** `|T|` of an operator `T`, constructed from the singular +value decomposition as `∑ σᵢ • rankOne uᵢ uᵢ` where `uᵢ` are the right singular +vectors. Lives on the source space `E` since `|T| = sqrt(T† ∘ T)`. -/ +noncomputable def absoluteValue : E →L[𝕜] E := + ∑ i : Fin (finrank 𝕜 E), (T.toLinearMap.singularValues i.val : 𝕜) • + rankOne 𝕜 (T.toLinearMap.svdRight i) (T.toLinearMap.svdRight i) + +/-- The **polar part** `U` of an operator `T : E →L[𝕜] F`, constructed from the singular value +decomposition as `∑ rankOne vᵢ uᵢ` sending each right singular vector `uᵢ ∈ E` to the +corresponding left singular vector `vᵢ ∈ F`. -/ +noncomputable def polarPart : E →L[𝕜] F := + ∑ i : Fin (finrank 𝕜 E), + rankOne 𝕜 (T.toLinearMap.svdLeft i) (T.toLinearMap.svdRight i) + +theorem absoluteValue_eq_sum : T.absoluteValue = + ∑ i : Fin (finrank 𝕜 E), (T.toLinearMap.singularValues i.val : 𝕜) • + rankOne 𝕜 (T.toLinearMap.svdRight i) (T.toLinearMap.svdRight i) := rfl + +theorem polarPart_eq_sum : T.polarPart = + ∑ i : Fin (finrank 𝕜 E), + rankOne 𝕜 (T.toLinearMap.svdLeft i) (T.toLinearMap.svdRight i) := rfl + +/-- `|T|` diagonalizes the right singular vectors with eigenvalue `σᵢ`. -/ +@[simp] theorem absoluteValue_apply_svdRight (i : Fin (finrank 𝕜 E)) : + T.absoluteValue (T.toLinearMap.svdRight i) = + (T.toLinearMap.singularValues i.val : 𝕜) • T.toLinearMap.svdRight i := by + classical + simp only [absoluteValue_eq_sum, sum_apply, _root_.smul_apply, rankOne_apply] + rw [Finset.sum_eq_single i (fun j _ hji ↦ ?_) (by simp)] + · rw [orthonormal_iff_ite.mp T.toLinearMap.svdRight.orthonormal i i, ite_eq_left rfl, + smul_smul, mul_one] + · rw [orthonormal_iff_ite.mp T.toLinearMap.svdRight.orthonormal j i, ite_eq_right hji, + zero_smul, smul_zero] + +/-- The polar part `U` sends each right singular vector to the corresponding left +singular vector. -/ +@[simp] theorem polarPart_apply_svdRight (i : Fin (finrank 𝕜 E)) : + T.polarPart (T.toLinearMap.svdRight i) = T.toLinearMap.svdLeft i := by + classical + simp only [polarPart_eq_sum, sum_apply, rankOne_apply] + rw [Finset.sum_eq_single i (fun j _ hji ↦ ?_) (by simp)] + · rw [orthonormal_iff_ite.mp T.toLinearMap.svdRight.orthonormal i i, ite_eq_left rfl, one_smul] + · rw [orthonormal_iff_ite.mp T.toLinearMap.svdRight.orthonormal j i, ite_eq_right hji, zero_smul] + +/-- The polar decomposition: `T = polarPart T ∘L absoluteValue T`. -/ +theorem polar_decomposition : T = T.polarPart ∘L T.absoluteValue := by + ext x + have hx : x = ∑ i, ⟪T.toLinearMap.svdRight i, x⟫_𝕜 • T.toLinearMap.svdRight i := + (T.toLinearMap.svdRight.sum_repr' x).symm + have hT : T x = T.toLinearMap x := rfl + conv_rhs => rw [hx] + simp only [coe_comp, Function.comp_apply, map_sum, map_smul, + absoluteValue_apply_svdRight, polarPart_apply_svdRight, smul_smul] + rw [hT, T.toLinearMap.svd_apply x] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [smul_smul, mul_comm] + +/-- `|T|` is a positive operator. -/ +theorem absoluteValue_isPositive : T.absoluteValue.IsPositive := by + rw [absoluteValue_eq_sum] + refine isPositive_sum _ fun i _ ↦ ?_ + apply IsPositive.smul_of_nonneg + · exact isPositive_rankOne_self _ + · exact_mod_cast T.toLinearMap.singularValues_nonneg i.val + +/-- `0 ≤ |T|` as a CLM. -/ +theorem absoluteValue_nonneg : 0 ≤ T.absoluteValue := + ContinuousLinearMap.nonneg_iff_isPositive.mpr T.absoluteValue_isPositive + +/-- `|T|` is self-adjoint: `|T|† = |T|`. The absolute value is a positive operator +(`absoluteValue_isPositive`), hence self-adjoint. -/ +theorem adjoint_absoluteValue [CompleteSpace E] : adjoint T.absoluteValue = T.absoluteValue := + T.absoluteValue_isPositive.isSelfAdjoint.adjoint_eq + +/-- The canonical characterization of `|T|`: `|T|² = T† ∘L T`. -/ +theorem absoluteValue_sq [CompleteSpace E] [CompleteSpace F] : + T.absoluteValue ∘L T.absoluteValue = T† ∘L T := by + ext x + have hx : x = ∑ i, ⟪T.toLinearMap.svdRight i, x⟫_𝕜 • T.toLinearMap.svdRight i := + (T.toLinearMap.svdRight.sum_repr' x).symm + conv_lhs => rw [hx] + conv_rhs => rw [hx] + simp only [coe_comp, Function.comp_apply, map_sum, map_smul, + absoluteValue_apply_svdRight, adjoint_comp_self_apply_svdRight, smul_smul] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + ring_nf + +/-- Comp-adjoint sibling of `absoluteValue_sq`: `|T†| ∘L |T†|† = T ∘L T†`. Combines +self-adjointness of the absolute value with `absoluteValue_sq` applied to `T†`. -/ +theorem absoluteValue_adjoint_comp_adjoint_eq [CompleteSpace E] [CompleteSpace F] : + T.adjoint.absoluteValue.comp T.adjoint.absoluteValue.adjoint = T.comp T.adjoint := by + rw [T.adjoint.absoluteValue_isPositive.isSelfAdjoint.adjoint_eq, + T.adjoint.absoluteValue_sq, ContinuousLinearMap.adjoint_adjoint] + +/-- `|T| = cfc Real.sqrt (T† ∘L T)`, the canonical CFC characterization of the absolute +value: both are the unique positive square root of `T† ∘L T`. -/ +theorem absoluteValue_eq_cfc_sqrt {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] (T : E →L[ℂ] E) : + T.absoluteValue = cfc Real.sqrt (T.adjoint ∘L T) := by + rw [← T.absoluteValue_sq, ← ContinuousLinearMap.mul_def, + ContinuousLinearMap.cfc_real_sqrt_mul_self_eq_self_of_nonneg T.absoluteValue_nonneg] + +section PartialIsometry + +variable [CompleteSpace E] [CompleteSpace F] + +/-- The adjoint of `polarPart T` swaps the rank-one factors: +`(polarPart T)† = ∑ rankOne (svdRight i) (svdLeft i)`. -/ +theorem polarPart_adjoint_eq_sum : T.polarPart.adjoint = + ∑ i : Fin (finrank 𝕜 E), + rankOne 𝕜 (T.toLinearMap.svdRight i) (T.toLinearMap.svdLeft i) := by + rw [polarPart_eq_sum, map_sum] + exact Finset.sum_congr rfl fun i _ ↦ InnerProductSpace.adjoint_rankOne _ _ + +/-- The adjoint of the polar part sends each left singular vector back to the corresponding +right singular vector when `σⱼ ≠ 0`, and to zero otherwise (in which case `svdLeft j = 0` +already). This is the per-basis-vector witness that `polarPart T` is a partial isometry +with initial space `span {svdRight i : σᵢ ≠ 0} = closure (range |T|)`. -/ +theorem polarPart_adjoint_apply_svdLeft (j : Fin (finrank 𝕜 E)) : + T.polarPart.adjoint (T.toLinearMap.svdLeft j) = + if T.toLinearMap.singularValues j.val = 0 then 0 else T.toLinearMap.svdRight j := by + classical + rw [polarPart_adjoint_eq_sum, sum_apply] + by_cases hj : T.toLinearMap.singularValues j.val = 0 + · rw [ite_eq_left hj, T.toLinearMap.svdLeft_eq_zero_of_singularValues_eq_zero j hj] + simp + · rw [ite_eq_right hj, Finset.sum_eq_single j ?_ (by simp)] + · simp only [rankOne_apply] + rw [T.toLinearMap.inner_svdLeft_svdLeft_full j j, ite_eq_left ⟨rfl, hj⟩, one_smul] + · intro i _ hij + rw [rankOne_apply, T.toLinearMap.inner_svdLeft_svdLeft_full i j, + ite_eq_right (fun ⟨h, _⟩ ↦ hij h), zero_smul] + +/-- **`polarPart T` is a partial isometry**: `U U† U = U`. This is the key +characterization that distinguishes the polar decomposition `T = U|T|` from arbitrary +factorizations — `polarPart T` acts as an isometry on the orthogonal complement of its +kernel, and is zero on its kernel. -/ +theorem polarPart_isPartialIsometry : + T.polarPart ∘L T.polarPart.adjoint ∘L T.polarPart = T.polarPart := by + ext x + have hx : x = ∑ i, ⟪T.toLinearMap.svdRight i, x⟫_𝕜 • T.toLinearMap.svdRight i := + (T.toLinearMap.svdRight.sum_repr' x).symm + conv_lhs => rw [hx] + conv_rhs => rw [hx] + simp only [coe_comp, Function.comp_apply, map_sum, map_smul, polarPart_apply_svdRight] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [polarPart_adjoint_apply_svdLeft] + by_cases hi : T.toLinearMap.singularValues i.val = 0 + · rw [ite_eq_left hi, map_zero, T.toLinearMap.svdLeft_eq_zero_of_singularValues_eq_zero i hi] + · rw [ite_eq_right hi, polarPart_apply_svdRight] + +/-- **The polar part has operator norm ≤ 1**: partial isometries are contractions. +Proof via the `IsStarProjection` route: `polarPart† ∘ polarPart` is a star projection +(by `isStarProjection_adjoint_comp_self_of_partialIsometry` applied to +`polarPart_isPartialIsometry`), so its operator norm is ≤ 1; then the C*-property +`‖A‖² = ‖A† ∘ A‖` gives the bound on `‖polarPart‖`. -/ +theorem polarPart_opNorm_le_one (T : E →L[𝕜] F) : ‖T.polarPart‖ ≤ 1 := by + have hsq : ‖T.polarPart‖ ^ 2 ≤ 1 := by + rw [sq, ← T.polarPart.norm_adjoint_comp_self] + exact (isStarProjection_adjoint_comp_self_of_partialIsometry + T.polarPart_isPartialIsometry).norm_le + nlinarith [norm_nonneg T.polarPart] + +end PartialIsometry + +section UniquenessFoundations + +variable [CompleteSpace E] [CompleteSpace F] + +/-- For a partial isometry `U` (`U ∘ U† ∘ U = U`), the operator `U† ∘ U` acts as the identity +on `(ker U)ᗮ`. This is the fixed-point form of the partial-isometry projection property: +`U† ∘ U` is the orthogonal projection onto `(ker U)ᗮ`. The proof: take adjoint of the partial- +isometry equation to get `U† ∘ U ∘ U† = U†`; in finite-dim, `(ker U)ᗮ = range U†`, so +`y = U† z` for some `z`, and `U† U y = (U† U U†) z = U† z = y`. -/ +theorem adjoint_apply_apply_of_partialIsometry_of_mem_orthogonal_ker + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + [CompleteSpace G] {U : E →L[𝕜] G} (hU : U ∘L U.adjoint ∘L U = U) {y : E} + (hy : y ∈ (LinearMap.ker U.toLinearMap)ᗮ) : + U.adjoint (U y) = y := by + have hUd : U.adjoint ∘L U ∘L U.adjoint = U.adjoint := by + have h := congr_arg ContinuousLinearMap.adjoint hU + simpa [adjoint_comp, ContinuousLinearMap.comp_assoc] using h + rw [LinearMap.orthogonal_ker] at hy + obtain ⟨z, hz⟩ := hy + -- LinearMap.adjoint U.toLinearMap and ContinuousLinearMap.adjoint U agree on application. + have hz' : U.adjoint z = y := hz + rw [← hz'] + have heq : (U.adjoint ∘L U ∘L U.adjoint) z = U.adjoint z := by rw [hUd] + simpa [coe_comp, Function.comp_apply] using heq + +/-- Specialization of the partial-isometry projection property to `polarPart T`: +`(polarPart T)† ((polarPart T) y) = y` for `y ∈ (ker (polarPart T))ᗮ`. -/ +theorem polarPart_adjoint_apply_apply_of_mem_orthogonal_ker {y : E} + (hy : y ∈ (LinearMap.ker T.polarPart.toLinearMap)ᗮ) : + T.polarPart.adjoint (T.polarPart y) = y := + adjoint_apply_apply_of_partialIsometry_of_mem_orthogonal_ker T.polarPart_isPartialIsometry hy + +/-- The kernel of the absolute value `|T|` equals the kernel of `T`. Proof chain: +`ker |T| = ker (|T|† ∘ |T|) = ker (|T| ∘ |T|) = ker (T† ∘ T) = ker T`, using self-adjointness +of `|T|`, the existing identity `|T|² = T† ∘ T`, and `ker_adjoint_comp_self`. -/ +theorem ker_absoluteValue : T.absoluteValue.ker = T.ker := by + have hself : T.absoluteValue.adjoint = T.absoluteValue := + T.absoluteValue_isPositive.isSelfAdjoint.adjoint_eq + rw [← T.absoluteValue.ker_adjoint_comp_self, hself, T.absoluteValue_sq, T.ker_adjoint_comp_self] + +omit [CompleteSpace E] [CompleteSpace F] in +/-- For `x ∈ ker (absoluteValue T)` and `i` a non-zero-singular-value index, +`⟪svdRight i, x⟫ = 0`. The right singular vectors with non-zero singular values are orthogonal +to the kernel of `|T|`. Proof: `0 = ⟪svdRight i, |T| x⟫ = ⟨|T| (svdRight i), x⟩ += σᵢ ⟨svdRight i, x⟩` via self-adjointness of `|T|` and `absoluteValue_apply_svdRight`; +cancel `σᵢ ≠ 0`. -/ +theorem inner_svdRight_eq_zero_of_absoluteValue_apply_eq_zero + {x : E} (hx : T.absoluteValue x = 0) {i : Fin (finrank 𝕜 E)} + (hσ : T.toLinearMap.singularValues i.val ≠ 0) : + ⟪T.toLinearMap.svdRight i, x⟫_𝕜 = 0 := by + have h0 : ⟪T.toLinearMap.svdRight i, T.absoluteValue x⟫_𝕜 = 0 := by + rw [hx, inner_zero_right] + rw [← T.absoluteValue_isPositive.inner_left_eq_inner_right, absoluteValue_apply_svdRight, + inner_smul_left, RCLike.conj_ofReal] at h0 + rcases mul_eq_zero.mp h0 with hσ' | h + · exact absurd (by exact_mod_cast hσ' : T.toLinearMap.singularValues i.val = 0) hσ + · exact h + +omit [CompleteSpace E] [CompleteSpace F] in +/-- The polar part vanishes on the kernel of the absolute value: `|T| x = 0 → polarPart T x = 0`. +Per-summand vanishing of `polarPart T x = ∑ ⟪svdRight i, x⟫ • svdLeft i`: for `σᵢ = 0` the left +singular vector is zero; for `σᵢ ≠ 0` the inner product is zero +(`inner_svdRight_eq_zero_of_absoluteValue_apply_eq_zero`). -/ +theorem polarPart_apply_eq_zero_of_absoluteValue_apply_eq_zero + {x : E} (hx : T.absoluteValue x = 0) : T.polarPart x = 0 := by + rw [polarPart_eq_sum, _root_.sum_apply] + apply Finset.sum_eq_zero + intro i _ + rw [rankOne_apply] + by_cases hσ : T.toLinearMap.singularValues i.val = 0 + · rw [T.toLinearMap.svdLeft_eq_zero_of_singularValues_eq_zero i hσ, smul_zero] + · rw [T.inner_svdRight_eq_zero_of_absoluteValue_apply_eq_zero hx hσ, zero_smul] + +omit [CompleteSpace E] [CompleteSpace F] in +/-- For any factorization `T = U ∘L absoluteValue T`, the action on right singular vectors is +`T (svdRight i) = σᵢ • U (svdRight i)`. Routes through `absoluteValue_apply_svdRight`: +`T (svdRight i) = U (|T| (svdRight i)) = U (σᵢ • svdRight i) = σᵢ • U (svdRight i)`. -/ +theorem apply_svdRight_of_eq_comp_absoluteValue {U : E →L[𝕜] F} + (hU : T = U ∘L T.absoluteValue) (i : Fin (finrank 𝕜 E)) : + T (T.toLinearMap.svdRight i) = + (T.toLinearMap.singularValues i.val : 𝕜) • U (T.toLinearMap.svdRight i) := by + have h := DFunLike.congr_fun hU (T.toLinearMap.svdRight i) + rwa [ContinuousLinearMap.comp_apply, T.absoluteValue_apply_svdRight, + ContinuousLinearMap.map_smul] at h + +/-- **Uniqueness of the positive square root of `T† ∘L T`**: a positive operator `P` with +`P ∘L P = T† ∘L T` equals `|T| = absoluteValue T`. Both `P` and `|T|` are positive with the same +square, so they agree on the right-singular-vector eigenbasis of `|T|` (via +`IsPositive.apply_eq_of_isPositive_sq_apply_eq`), hence coincide. This is the canonical +characterisation used wherever a positive-times-(partial)isometry factorisation is shown to be the +polar decomposition. -/ +theorem absoluteValue_eq_of_isPositive_sq {P : E →L[𝕜] E} (hP : P.IsPositive) + (h : P ∘L P = T.adjoint ∘L T) : P = T.absoluteValue := by + apply ContinuousLinearMap.coe_injective + apply Basis.ext T.toLinearMap.svdRight.toBasis + intro i + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe] + have h_sq : T.absoluteValue ∘L T.absoluteValue = P ∘L P := T.absoluteValue_sq.trans h.symm + rw [hP.apply_eq_of_isPositive_sq_apply_eq h_sq (T.toLinearMap.singularValues_nonneg i.val) + (T.absoluteValue_apply_svdRight i), ← T.absoluteValue_apply_svdRight i] + +/-- **Polar decomposition uniqueness**: if `T = U' ∘L P'` with `P'` positive, `U'` a partial +isometry, and `kernel U' = kernel P'`, then `P' = absoluteValue T` and `U' = polarPart T`. The +uniqueness theorem characterizes our construction as canonical: any factorization of `T` into a +positive-times-partial-isometry with matching kernels must be the polar decomposition. -/ +theorem polar_decomposition_unique {P' : E →L[𝕜] E} {U' : E →L[𝕜] F} + (hT : T = U' ∘L P') (hP' : P'.IsPositive) + (hU' : U' ∘L U'.adjoint ∘L U' = U') + (hker : LinearMap.ker U'.toLinearMap = LinearMap.ker P'.toLinearMap) : + P' = T.absoluteValue ∧ U' = T.polarPart := by + -- Step 1: T† ∘L T = P' ∘L P' (using partial-isometry on range P'). + have hTT : T.adjoint ∘L T = P' ∘L P' := by + rw [hT, ContinuousLinearMap.adjoint_comp, hP'.isSelfAdjoint.adjoint_eq] + ext y + simp only [ContinuousLinearMap.comp_apply] + have hP'y : P' y ∈ (LinearMap.ker U'.toLinearMap)ᗮ := by + rw [hker, ← hP'.isSymmetric.range_eq_orthogonal_ker] + exact ⟨y, rfl⟩ + rw [adjoint_apply_apply_of_partialIsometry_of_mem_orthogonal_ker hU' hP'y] + -- Step 2: P' = absoluteValue T (uniqueness of the positive square root of `T† ∘L T`). + have habs : P' = T.absoluteValue := T.absoluteValue_eq_of_isPositive_sq hP' hTT.symm + -- Step 3: U' = polarPart T (using ker U' = ker P' = ker absoluteValue T = ker polarPart T). + have hU : U' = T.polarPart := by + apply ContinuousLinearMap.coe_injective + apply Basis.ext T.toLinearMap.svdRight.toBasis + intro i + simp only [OrthonormalBasis.coe_toBasis, ContinuousLinearMap.coe_coe] + by_cases hσ : T.toLinearMap.singularValues i.val = 0 + · -- σᵢ = 0: both U' and polarPart T vanish on svdRight i (via ker chain). + have habs_z : T.absoluteValue (T.toLinearMap.svdRight i) = 0 := by + rw [T.absoluteValue_apply_svdRight i, hσ, RCLike.ofReal_zero, zero_smul] + -- ker chain: T.absoluteValue → P' (via habs) → U' (via hker). + have hU'_z : U' (T.toLinearMap.svdRight i) = 0 := by + have hmem : T.toLinearMap.svdRight i ∈ LinearMap.ker P'.toLinearMap := by + rw [habs]; exact LinearMap.mem_ker.mpr habs_z + exact LinearMap.mem_ker.mp (hker ▸ hmem) + rw [hU'_z, T.polarPart_apply_eq_zero_of_absoluteValue_apply_eq_zero habs_z] + · -- σᵢ ≠ 0: T u = σᵢ • U' u = σᵢ • polarPart T u via apply_svdRight_of_eq_comp_absoluteValue. + have hT_apply := T.apply_svdRight_of_eq_comp_absoluteValue (habs ▸ hT) i + have hT_apply' := T.apply_svdRight_of_eq_comp_absoluteValue T.polar_decomposition i + have hσ' : (T.toLinearMap.singularValues i.val : 𝕜) ≠ 0 := by exact_mod_cast hσ + exact smul_right_injective F hσ' (hT_apply.symm.trans hT_apply') + exact ⟨habs, hU⟩ + +end UniquenessFoundations + +end ContinuousLinearMap + +namespace LinearMap + +variable (T : E →ₗ[𝕜] F) + +/-- **LM-level dual of `ContinuousLinearMap.absoluteValue`**: the absolute value `|T|` of +an LM operator. In finite dimensions, defined as the round-trip +`T.toContinuousLinearMap.absoluteValue.toLinearMap`; the CLM↔LM equivalence +(`coe_toContinuousLinearMap`) makes this the natural LM-side companion to the CLM def. -/ +noncomputable def absoluteValue : E →ₗ[𝕜] E := + T.toContinuousLinearMap.absoluteValue.toLinearMap + +/-- **LM-level dual of `ContinuousLinearMap.polarPart`**: the polar part `U` of an LM +operator `T : E →ₗ[𝕜] F`. -/ +noncomputable def polarPart : E →ₗ[𝕜] F := + T.toContinuousLinearMap.polarPart.toLinearMap + +/-- **LM-level polar decomposition**: `T = T.polarPart ∘ₗ T.absoluteValue`. Dual to the +CLM-level `ContinuousLinearMap.polar_decomposition` via the LM↔CLM round-trip +(`coe_toContinuousLinearMap`). -/ +theorem polar_decomposition : T = T.polarPart ∘ₗ T.absoluteValue := + congrArg ContinuousLinearMap.toLinearMap T.toContinuousLinearMap.polar_decomposition + +end LinearMap + +namespace ContinuousLinearMap + +variable (T : E →L[𝕜] F) + +/-- **CLM ↔ LM bridge** for `absoluteValue`: the `toLinearMap` of the CLM-level +`absoluteValue` equals the LM-level `absoluteValue` of the coerced LM. -/ +@[simp] +theorem toLinearMap_absoluteValue : + T.absoluteValue.toLinearMap = (T : E →ₗ[𝕜] F).absoluteValue := rfl + +/-- **CLM ↔ LM bridge** for `polarPart`. -/ +@[simp] +theorem toLinearMap_polarPart : + T.polarPart.toLinearMap = (T : E →ₗ[𝕜] F).polarPart := rfl + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarNormal.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarNormal.lean new file mode 100644 index 0000000000..d3745fae99 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarNormal.lean @@ -0,0 +1,267 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarUnitary +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.NormalOperator + +/-! + +# Polar decomposition of a normal operator in outer-product form + +For a *normal* operator `A` on a finite-dimensional complex inner product space, the spectral +theorem writes `A` diagonally in an orthonormal eigenbasis `{bᵢ}`: + +`A = ∑ᵢ μᵢ • |bᵢ⟩⟨bᵢ|` (`ToMathlib.Analysis.InnerProductSpace.NormalOperator`). + +This file expresses the polar decomposition `A = U J = J U` (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Theorem 2.3) of such an `A` in this **outer-product +representation** (N&C Exercise 2.49): both polar factors are diagonal in the *same* eigenbasis, + +`J = |A| = ∑ᵢ ‖μᵢ‖ • |bᵢ⟩⟨bᵢ|`, `U = ∑ᵢ phase(μᵢ) • |bᵢ⟩⟨bᵢ|`, + +where each eigenvalue is split into modulus and phase, `μᵢ = ‖μᵢ‖ · phase(μᵢ)`. Because `J` +and `U` share `A`'s eigenbasis they commute, so the left and right polar decompositions +`A = U J` and `A = J U` coincide — the special feature of the normal case. + +## The diagonal operator + +The reusable vehicle is `OrthonormalBasis.diagonalOperator b w = ∑ᵢ wᵢ • |bᵢ⟩⟨bᵢ|`, the operator +diagonal in an orthonormal basis `b` with prescribed diagonal entries `w`. Its algebra makes the +polar decomposition immediate: + +* `OrthonormalBasis.diagonalOperator_comp`: `diag w ∘L diag w' = diag (w * w')` — composition is + pointwise multiplication of diagonals; +* `OrthonormalBasis.diagonalOperator_adjoint`: `(diag w)† = diag (star w)`; +* `OrthonormalBasis.diagonalOperator_one`: `diag 1 = 1`; +* `OrthonormalBasis.diagonalOperator_mem_unitary`: `diag w` is unitary when `‖wᵢ‖ = 1`; +* `OrthonormalBasis.diagonalOperator_isPositive_of_nonneg`: `diag w` is positive when `0 ≤ wᵢ`; +* `OrthonormalBasis.diagonalOperator_isStarNormal`: every `diag w` is normal. + +## Main results (N&C Exercise 2.49) + +For `A = b.diagonalOperator μ`: + +* `OrthonormalBasis.diagonalOperator_eq_phase_comp_norm`: `A = U ∘L J` (left polar decomposition); +* `OrthonormalBasis.diagonalOperator_eq_norm_comp_phase`: `A = J ∘L U` (right polar decomposition); +* `OrthonormalBasis.diagonalOperator_phase_mem_unitary`: `U` is unitary; +* `OrthonormalBasis.diagonalOperator_norm_isPositive`: `J` is positive; +* `OrthonormalBasis.diagonalOperator_norm_eq_absoluteValue`: `J = |A| = √(A† A)`, identifying the + positive factor with the canonical one of N&C Theorem 2.3 (via + `ContinuousLinearMap.absoluteValue_eq_of_unitary_comp`). + +`OrthonormalBasis.diagonalOperator_isStarNormal` supplies the converse half — that these +diagonal operators are exactly the normal ones — so the forward spectral theorem +`IsStarNormal.exists_orthonormalBasis_forall_apply_eq_smul` places every normal operator in this +outer-product form. + +-/ + +@[expose] public section + +open Module InnerProductSpace ContinuousLinearMap +open scoped ComplexConjugate ComplexOrder + +namespace RCLike + +variable {𝕜 : Type*} [RCLike 𝕜] + +/-- The **phase** (unit-modulus part) of a scalar: `phase z = z / ‖z‖` for `z ≠ 0`, and +`phase 0 = 1`. It satisfies `‖phase z‖ = 1` (`RCLike.norm_phase`) and recovers `z` from its +modulus, `phase z · ‖z‖ = z` (`RCLike.phase_mul_norm`); together these give the polar form +`z = ‖z‖ · phase z` of a complex number. -/ +noncomputable def phase (z : 𝕜) : 𝕜 := if z = 0 then 1 else (‖z‖ : 𝕜)⁻¹ * z + +@[simp] theorem phase_zero : phase (0 : 𝕜) = 1 := by simp [phase] + +/-- The phase of a scalar has unit modulus. -/ +theorem norm_phase (z : 𝕜) : ‖phase z‖ = 1 := by + rw [phase] + split_ifs with h + · simp + · rw [norm_mul, norm_inv, norm_ofReal, abs_norm, inv_mul_cancel₀ (norm_ne_zero_iff.mpr h)] + +/-- Recovering a scalar from its modulus and phase: `phase z · ‖z‖ = z`. -/ +theorem phase_mul_norm (z : 𝕜) : phase z * (‖z‖ : 𝕜) = z := by + rw [phase] + split_ifs with h + · subst h; simp + · have hz : (‖z‖ : 𝕜) ≠ 0 := ofReal_ne_zero.mpr (norm_ne_zero_iff.mpr h) + rw [mul_right_comm, inv_mul_cancel₀ hz, one_mul] + +/-- Recovering a scalar from its modulus and phase: `‖z‖ · phase z = z`. -/ +theorem norm_mul_phase (z : 𝕜) : (‖z‖ : 𝕜) * phase z = z := by + rw [mul_comm]; exact phase_mul_norm z + +end RCLike + +namespace OrthonormalBasis + +variable {ι 𝕜 E : Type*} [RCLike 𝕜] [Fintype ι] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- The operator **diagonal in an orthonormal basis** `b` with diagonal entries `w`: +`diagonalOperator b w = ∑ᵢ wᵢ • |bᵢ⟩⟨bᵢ|`. Conjugating any operator diagonal in `b` reduces to +manipulating its scalar diagonal `w`; the spectral decomposition of a normal operator is exactly +`A = b.diagonalOperator μ` for its eigenvalues `μ`. -/ +noncomputable def diagonalOperator (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) : E →L[𝕜] E := + ∑ i, w i • rankOne 𝕜 (b i) (b i) + +/-- The diagonal operator with all-ones diagonal is the identity. -/ +@[simp] theorem diagonalOperator_one (b : OrthonormalBasis ι 𝕜 E) : + b.diagonalOperator 1 = 1 := by + simp only [diagonalOperator, Pi.one_apply, one_smul] + exact b.sum_rankOne_eq_id + +/-- **Composition of diagonal operators is pointwise multiplication of their diagonals**: +`diag w ∘L diag w' = diag (w * w')`. -/ +theorem diagonalOperator_comp (b : OrthonormalBasis ι 𝕜 E) (w w' : ι → 𝕜) : + b.diagonalOperator w ∘L b.diagonalOperator w' = b.diagonalOperator (w * w') := by + simp only [diagonalOperator] + rw [ContinuousLinearMap.finsetSum_comp] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_finsetSum, Finset.smul_sum, + Finset.sum_eq_single i] + · rw [ContinuousLinearMap.comp_smul, rankOne_comp_rankOne, b.inner_eq_one i, one_smul, + smul_smul, Pi.mul_apply] + · intro j _ hji + rw [ContinuousLinearMap.comp_smul, rankOne_comp_rankOne, b.orthonormal.inner_eq_zero + (Ne.symm hji), zero_smul, smul_zero, smul_zero] + · intro h; exact absurd (Finset.mem_univ i) h + +/-- **N&C Exercise 2.49 — left polar decomposition in outer-product form.** For a normal operator +`A = ∑ᵢ μᵢ • |bᵢ⟩⟨bᵢ|`, the left polar decomposition `A = U J` has unitary factor +`U = ∑ᵢ phase(μᵢ) • |bᵢ⟩⟨bᵢ|` and positive factor `J = ∑ᵢ ‖μᵢ‖ • |bᵢ⟩⟨bᵢ|`, both diagonal in +`A`'s eigenbasis. -/ +theorem diagonalOperator_eq_phase_comp_norm (b : OrthonormalBasis ι 𝕜 E) (μ : ι → 𝕜) : + b.diagonalOperator μ = + b.diagonalOperator (fun i => RCLike.phase (μ i)) ∘L + b.diagonalOperator (fun i => (‖μ i‖ : 𝕜)) := by + rw [diagonalOperator_comp] + congr 1 + ext i + rw [Pi.mul_apply, RCLike.phase_mul_norm] + +/-- **N&C Exercise 2.49 — right polar decomposition in outer-product form.** Since the two factors +share `A`'s eigenbasis they commute, so `A = J U` also holds with the same `U`, `J`. -/ +theorem diagonalOperator_eq_norm_comp_phase (b : OrthonormalBasis ι 𝕜 E) (μ : ι → 𝕜) : + b.diagonalOperator μ = + b.diagonalOperator (fun i => (‖μ i‖ : 𝕜)) ∘L + b.diagonalOperator (fun i => RCLike.phase (μ i)) := by + rw [diagonalOperator_comp] + congr 1 + ext i + rw [Pi.mul_apply, RCLike.norm_mul_phase] + +variable [CompleteSpace E] + +/-- The adjoint of a diagonal operator is diagonal with conjugated entries: +`(diag w)† = diag (star w)`. -/ +theorem diagonalOperator_adjoint (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) : + adjoint (b.diagonalOperator w) = b.diagonalOperator (star w) := by + simp only [diagonalOperator, map_sum, map_smulₛₗ, InnerProductSpace.adjoint_rankOne, + Pi.star_apply, RCLike.star_def] + +/-- A diagonal operator with unit-modulus diagonal is **unitary**. -/ +theorem diagonalOperator_mem_unitary (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) + (hw : ∀ i, ‖w i‖ = 1) : b.diagonalOperator w ∈ unitary (E →L[𝕜] E) := by + have hl : star w * w = 1 := by + ext i; simp only [Pi.mul_apply, Pi.star_apply, Pi.one_apply, RCLike.star_def] + rw [RCLike.conj_mul, hw i]; norm_num + have hr : w * star w = 1 := by + ext i; simp only [Pi.mul_apply, Pi.star_apply, Pi.one_apply, RCLike.star_def] + rw [RCLike.mul_conj, hw i]; norm_num + rw [Unitary.mem_iff, ContinuousLinearMap.star_eq_adjoint, diagonalOperator_adjoint, + ContinuousLinearMap.mul_def, ContinuousLinearMap.mul_def, diagonalOperator_comp, + diagonalOperator_comp, hl, hr, diagonalOperator_one] + exact ⟨rfl, rfl⟩ + +omit [CompleteSpace E] in +/-- A diagonal operator with nonnegative diagonal is **positive**. -/ +theorem diagonalOperator_isPositive_of_nonneg (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) + (hw : ∀ i, 0 ≤ w i) : (b.diagonalOperator w).IsPositive := by + rw [diagonalOperator] + refine isPositive_sum _ fun i _ => ?_ + exact (InnerProductSpace.isPositive_rankOne_self _).smul_of_nonneg (hw i) + +/-- Every operator diagonal in an orthonormal basis is **normal**: it commutes with its adjoint. -/ +theorem diagonalOperator_isStarNormal (b : OrthonormalBasis ι 𝕜 E) (w : ι → 𝕜) : + IsStarNormal (b.diagonalOperator w) := by + refine ⟨?_⟩ + change star (b.diagonalOperator w) * b.diagonalOperator w + = b.diagonalOperator w * star (b.diagonalOperator w) + rw [ContinuousLinearMap.star_eq_adjoint, diagonalOperator_adjoint, ContinuousLinearMap.mul_def, + ContinuousLinearMap.mul_def, diagonalOperator_comp, diagonalOperator_comp, mul_comm (star w) w] + +/-- The phase factor `U = ∑ᵢ phase(μᵢ) • |bᵢ⟩⟨bᵢ|` is unitary. -/ +theorem diagonalOperator_phase_mem_unitary (b : OrthonormalBasis ι 𝕜 E) (μ : ι → 𝕜) : + b.diagonalOperator (fun i => RCLike.phase (μ i)) ∈ unitary (E →L[𝕜] E) := + b.diagonalOperator_mem_unitary _ fun i => RCLike.norm_phase (μ i) + +omit [CompleteSpace E] in +/-- The positive factor `J = ∑ᵢ ‖μᵢ‖ • |bᵢ⟩⟨bᵢ|` is positive. -/ +theorem diagonalOperator_norm_isPositive (b : OrthonormalBasis ι 𝕜 E) (μ : ι → 𝕜) : + (b.diagonalOperator (fun i => (‖μ i‖ : 𝕜))).IsPositive := + b.diagonalOperator_isPositive_of_nonneg _ fun i => RCLike.ofReal_nonneg.mpr (norm_nonneg (μ i)) + +/-- **The positive factor is the canonical one:** `J = |A| = √(A† A)`. This identifies the +outer-product positive factor `∑ᵢ ‖μᵢ‖ • |bᵢ⟩⟨bᵢ|` with the absolute value `|A|` of N&C +Theorem 2.3, via uniqueness of the positive factor +(`ContinuousLinearMap.absoluteValue_eq_of_unitary_comp`). -/ +theorem diagonalOperator_norm_eq_absoluteValue [FiniteDimensional 𝕜 E] + (b : OrthonormalBasis ι 𝕜 E) (μ : ι → 𝕜) : + b.diagonalOperator (fun i => (‖μ i‖ : 𝕜)) = (b.diagonalOperator μ).absoluteValue := + absoluteValue_eq_of_unitary_comp (b.diagonalOperator μ) + (b.diagonalOperator_phase_mem_unitary μ) (b.diagonalOperator_norm_isPositive μ) + (b.diagonalOperator_eq_phase_comp_norm μ) + +end OrthonormalBasis + +/-- **Normality transfers to the underlying linear map:** a normal continuous linear map on a +complete inner product space coerces to a normal `E →ₗ[𝕜] E`. This bridges the `→L` polar/spectral +API to the `→ₗ`-stated spectral theorem for normal operators. -/ +theorem ContinuousLinearMap.isStarNormal_toLinearMap {𝕜 E : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] [CompleteSpace E] + {A : E →L[𝕜] E} (hA : IsStarNormal A) : IsStarNormal (A : E →ₗ[𝕜] E) := by + refine ⟨?_⟩ + have hstar : star (A : E →ₗ[𝕜] E) = ((star A : E →L[𝕜] E) : E →ₗ[𝕜] E) := by + rw [LinearMap.star_eq_adjoint, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_toLinearMap] + rw [hstar] + change ((star A : E →L[𝕜] E) : E →ₗ[𝕜] E) * (A : E →ₗ[𝕜] E) + = (A : E →ₗ[𝕜] E) * ((star A : E →L[𝕜] E) : E →ₗ[𝕜] E) + rw [← ContinuousLinearMap.toLinearMap_mul, ← ContinuousLinearMap.toLinearMap_mul, + hA.star_comm_self.eq] + +section Normal + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +open Module + +/-- **Every normal operator is diagonal in an orthonormal eigenbasis, in outer-product form.** +The forward half of the spectral theorem (N&C Theorem 2.1) recast as +`A = ∑ᵢ μᵢ • |bᵢ⟩⟨bᵢ| = b.diagonalOperator μ`. Combined with the `diagonalOperator` polar +decomposition above, this places the polar decomposition of *any* normal operator `A` in the +outer-product representation of N&C Exercise 2.49: `A = U J = J U` with +`U = ∑ᵢ phase(μᵢ) • |bᵢ⟩⟨bᵢ|` and `J = |A| = ∑ᵢ ‖μᵢ‖ • |bᵢ⟩⟨bᵢ|`. -/ +theorem IsStarNormal.exists_eq_diagonalOperator {A : E →L[ℂ] E} (hA : IsStarNormal A) : + ∃ (b : OrthonormalBasis (Fin (finrank ℂ E)) ℂ E) (μ : Fin (finrank ℂ E) → ℂ), + A = b.diagonalOperator μ := by + obtain ⟨b, μ, hbμ⟩ := + (ContinuousLinearMap.isStarNormal_toLinearMap hA).exists_orthonormalBasis_forall_apply_eq_smul + refine ⟨b, μ, ?_⟩ + conv_lhs => rw [← ContinuousLinearMap.comp_id A, ← b.sum_rankOne_eq_id] + rw [ContinuousLinearMap.comp_finsetSum, OrthonormalBasis.diagonalOperator] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [comp_rankOne, show A (b i) = μ i • b i from hbμ i, ← smul_rankOne] + +end Normal diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarUnitary.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarUnitary.lean new file mode 100644 index 0000000000..76d123eda6 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PolarUnitary.lean @@ -0,0 +1,260 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar + +/-! + +# Unitary polar decomposition of a square operator + +For a continuous linear operator `A : E →L[𝕜] E` on a finite-dimensional inner product space +(the *square* case `E = E`), this file upgrades the partial-isometry polar decomposition +`ToMathlib.Analysis.InnerProductSpace.Polar` (`A = A.polarPart ∘L A.absoluteValue`, where +`A.polarPart` is only a partial isometry) to the classical **unitary** polar decomposition + +`A = U J = K U`, + +where `U` is *unitary* (not merely a partial isometry), `J = |A| = √(A† A)` and +`K = √(A A†)` are positive operators, `J` and `K` are the *unique* positive operators +satisfying these equations, and `U` is unique when `A` is invertible. This is the statement +of the polar decomposition found in most textbooks (e.g. Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Theorem 2.3): for a square operator one can always +complete the partial isometry to a genuine unitary. + +## Main results + +* `ContinuousLinearMap.norm_apply_eq_norm_absoluteValue_apply`: `‖A x‖ = ‖|A| x‖`, i.e. `A` + and its absolute value `|A|` have the same action on norms. This is the isometry that, + after extension to the whole space, yields the unitary factor. +* `ContinuousLinearMap.exists_mem_unitary_eq_comp_absoluteValue`: there is a unitary `U` + with `A = U ∘L |A|`. The construction restricts `A.polarPart` to `range |A|` — where it + is an isometry — and extends it to a full isometry of `E` via `LinearIsometry.extend`, + which in the square finite-dimensional case is a unitary. +* `ContinuousLinearMap.exists_unitary_isPositive_polar`: the full two-sided decomposition + `A = U J = K U` with `U` unitary and `J`, `K` positive satisfying `J² = A† A`, + `K² = A A†` (so `J = √(A† A)` and `K = √(A A†)` are the unique positive square roots). +* `ContinuousLinearMap.absoluteValue_eq_of_unitary_comp` / + `ContinuousLinearMap.adjoint_absoluteValue_eq_of_comp_unitary`: **uniqueness of `J`, `K`** — + any positive operator appearing as the right (resp. left) factor of a unitary factorisation + of `A` equals `|A|` (resp. `|A†|`). +* `ContinuousLinearMap.unitary_factor_unique_of_isUnit`: **uniqueness of `U`** when `A` is + invertible. + +The right factor is `K = U J U†`; it is positive as a unitary conjugate of the positive +`J`, and `K U = U J U† U = U J = A`. + +-/ + +@[expose] public section + +variable {𝕜 E : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] [CompleteSpace E] + +open Module InnerProductSpace +open scoped InnerProduct + +namespace ContinuousLinearMap + +omit [FiniteDimensional 𝕜 E] in +/-- **Adjoint of a factorisation with a self-adjoint right factor**: if `A = U ∘L P` with `P` +self-adjoint, then `A† = P ∘L U†` (writing `U† = star U`). A foundational rewrite for the polar +decomposition, where the right factor `|A|` (or the positive `J`) is self-adjoint. -/ +theorem adjoint_eq_comp_star_of_isSelfAdjoint {A U P : E →L[𝕜] E} + (hP : IsSelfAdjoint P) (h : A = U ∘L P) : A.adjoint = P ∘L star U := by + rw [h, ContinuousLinearMap.adjoint_comp, ← ContinuousLinearMap.star_eq_adjoint, + ← ContinuousLinearMap.star_eq_adjoint, hP.star_eq] + +variable (A : E →L[𝕜] E) + +/-- The operator `A` and its absolute value `|A| = √(A† A)` are equinorm on every vector: +`‖A x‖ = ‖|A| x‖`. Indeed `⟪A x, A x⟫ = ⟪x, (A† ∘L A) x⟫ = ⟪x, |A|² x⟫ = ⟪|A| x, |A| x⟫` +using `absoluteValue_sq` and self-adjointness of `|A|`. This equality is exactly what makes +`A.polarPart` an isometry on `range |A|`, the fact used to build the unitary factor. -/ +theorem norm_apply_eq_norm_absoluteValue_apply (x : E) : ‖A x‖ = ‖A.absoluteValue x‖ := by + have hsa : A.absoluteValue.adjoint = A.absoluteValue := + A.absoluteValue_isPositive.isSelfAdjoint.adjoint_eq + have h : ⟪A x, A x⟫_𝕜 = ⟪A.absoluteValue x, A.absoluteValue x⟫_𝕜 := by + rw [← adjoint_inner_right A x (A x), + ← adjoint_inner_right A.absoluteValue x (A.absoluteValue x), hsa, + ← comp_apply, ← comp_apply, A.absoluteValue_sq] + have hre := congrArg RCLike.re h + rwa [inner_self_eq_norm_sq, inner_self_eq_norm_sq, sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)] + at hre + +/-- **Left unitary polar decomposition (existence)**: for a square operator `A` there is a +*unitary* `U` with `A = U ∘L |A|`. + +The construction: `A.polarPart` restricted to `S := range |A|` is an isometry (its norm- +preservation there is `norm_apply_eq_norm_absoluteValue_apply` composed with +`polar_decomposition`), so it defines `L : ↥S →ₗᵢ[𝕜] E`. Extending `L` to a full isometry +of `E` (`LinearIsometry.extend`) and upgrading to a `LinearIsometryEquiv` (equal dimension, +same space) yields a unitary `U` that agrees with `A.polarPart` on `range |A|`; hence +`U (|A| x) = A.polarPart (|A| x) = A x`. -/ +theorem exists_mem_unitary_eq_comp_absoluteValue : + ∃ U ∈ unitary (E →L[𝕜] E), A = U ∘L A.absoluteValue := by + classical + have hpd : ∀ x : E, A.polarPart (A.absoluteValue x) = A x := by + intro x + have hd := A.polar_decomposition + conv_rhs => rw [hd] + rfl + set S : Submodule 𝕜 E := LinearMap.range (A.absoluteValue : E →ₗ[𝕜] E) with hS + have hnm : ∀ s : ↥S, ‖A.polarPart (s : E)‖ = ‖(s : E)‖ := by + rintro ⟨y, x, hx⟩ + have hyx : y = A.absoluteValue x := hx.symm + subst hyx + rw [hpd, A.norm_apply_eq_norm_absoluteValue_apply x] + let L : ↥S →ₗᵢ[𝕜] E := + { toLinearMap := A.polarPart.toLinearMap.domRestrict S + norm_map' := hnm } + set W : E ≃ₗᵢ[𝕜] E := (L.extend).toLinearIsometryEquiv rfl with hW + refine ⟨Unitary.linearIsometryEquiv.symm W, (Unitary.linearIsometryEquiv.symm W).2, ?_⟩ + have hkey : ∀ x : E, + (Unitary.linearIsometryEquiv.symm W : E →L[𝕜] E) (A.absoluteValue x) = A x := by + intro x + rw [Unitary.coe_symm_linearIsometryEquiv_apply] + have hmem : A.absoluteValue x ∈ S := ⟨x, rfl⟩ + change W (A.absoluteValue x) = A x + rw [hW, LinearIsometry.coe_toLinearIsometryEquiv, + show A.absoluteValue x = ((⟨A.absoluteValue x, hmem⟩ : ↥S) : E) from rfl, + LinearIsometry.extend_apply] + exact hpd x + ext x + simp only [ContinuousLinearMap.comp_apply] + exact (hkey x).symm + +/-- **Polar decomposition — existence** (Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 2.3). For a square operator `A : E →L[𝕜] E` there exist a unitary `U` +and positive operators `J`, `K` with + +`A = U ∘L J = K ∘L U`, `J ∘L J = A† ∘L A`, `K ∘L K = A ∘L A†`. + +The last two identities pin down `J = √(A† A) = |A|` and `K = √(A A†)` as the unique +positive square roots. Here `J = A.absoluteValue` and `K = U ∘L |A| ∘L U†`, positive as a +unitary conjugate of `|A|` (`IsPositive.conj_adjoint`). Uniqueness of `J`, `K`, and of `U` +(for invertible `A`) is `absoluteValue_eq_of_unitary_comp`, +`adjoint_absoluteValue_eq_of_comp_unitary`, and `unitary_factor_unique_of_isUnit`. -/ +theorem exists_unitary_isPositive_polar : + ∃ U ∈ unitary (E →L[𝕜] E), ∃ J K : E →L[𝕜] E, + J.IsPositive ∧ K.IsPositive ∧ A = U ∘L J ∧ A = K ∘L U ∧ + J ∘L J = A.adjoint ∘L A ∧ K ∘L K = A ∘L A.adjoint := by + obtain ⟨U, hU, hAU⟩ := A.exists_mem_unitary_eq_comp_absoluteValue + have hstar_mul : star U * U = 1 := by simpa using Unitary.coe_star_mul_self ⟨U, hU⟩ + have hsa : IsSelfAdjoint A.absoluteValue := A.absoluteValue_isPositive.isSelfAdjoint + refine ⟨U, hU, A.absoluteValue, U ∘L A.absoluteValue ∘L star U, + A.absoluteValue_isPositive, ?_, hAU, ?_, A.absoluteValue_sq, ?_⟩ + · -- `K = U |A| U†` is positive: a unitary conjugate of the positive `|A|` + -- (`star U` is defeq to `U.adjoint`). + exact A.absoluteValue_isPositive.conj_adjoint U + · -- `A = K U`: cancel `U† U = 1`. + have hAU_mul : A = U * A.absoluteValue := hAU + simp only [← ContinuousLinearMap.mul_def] + rw [mul_assoc, mul_assoc, hstar_mul, mul_one, ← hAU_mul] + · -- `K² = A A†`: both sides equal `U |A|² U†`. + have hAadj : A.adjoint = A.absoluteValue ∘L star U := + adjoint_eq_comp_star_of_isSelfAdjoint hsa hAU + have hLHS : (U ∘L A.absoluteValue ∘L star U) ∘L (U ∘L A.absoluteValue ∘L star U) + = U * A.absoluteValue * A.absoluteValue * star U := by + simp only [← ContinuousLinearMap.mul_def] + rw [show U * (A.absoluteValue * star U) * (U * (A.absoluteValue * star U)) + = U * A.absoluteValue * (star U * U) * A.absoluteValue * star U by noncomm_ring, + hstar_mul, mul_one] + have hRHS : A ∘L A.adjoint = U * A.absoluteValue * A.absoluteValue * star U := by + rw [hAadj] + nth_rewrite 1 [hAU] + simp only [← ContinuousLinearMap.mul_def] + noncomm_ring + rw [hLHS, hRHS] + +/-- **Polar decomposition conjugates `A Aᴴ` to `Aᴴ A`.** There is a unitary `U` with +`A† A = U† (A A†) U`, stated as `star A * A = star U * (A * star A) * U`. From the polar +decomposition `A = U ∘L J` (`U` unitary, `J = |A|` positive with `J ∘L J = A† ∘L A`) one gets +`A A† = U (A† A) U†`, which rearranges to the claimed identity. Together with +`exists_unitary_isPositive_polar` this is the standard fact that `A† A` and `A A†` are unitarily +equivalent. -/ +theorem exists_unitary_star_mul_self_eq_conj : + ∃ U ∈ unitary (E →L[𝕜] E), star A * A = star U * (A * star A) * U := by + obtain ⟨U, hU, J, -, hJ, -, hAUJ, -, hJ2, -⟩ := A.exists_unitary_isPositive_polar + refine ⟨U, hU, ?_⟩ + have hstarUU : star U * U = 1 := by simpa using Unitary.coe_star_mul_self ⟨U, hU⟩ + have hJsa : star J = J := by rw [ContinuousLinearMap.star_eq_adjoint]; exact hJ.isSelfAdjoint + have hAUJ' : A = U * J := by rwa [← ContinuousLinearMap.mul_def] at hAUJ + have hJ2' : J * J = star A * A := by + rw [ContinuousLinearMap.star_eq_adjoint] + simpa only [← ContinuousLinearMap.mul_def] using hJ2 + -- `A A† = U (A† A) U†`. + have hAAstar : A * star A = U * (star A * A) * star U := by + rw [← hJ2', hAUJ', star_mul, hJsa] + simp only [mul_assoc] + rw [hAAstar] + -- conjugating back by `U` (unitary) recovers `A† A`. + have hcollapse : star U * (U * (star A * A) * star U) * U = star A * A := by + have e : star U * (U * (star A * A) * star U) * U + = (star U * U) * (star A * A) * (star U * U) := by simp only [mul_assoc] + rw [e]; simp only [hstarUU, one_mul, mul_one] + exact hcollapse.symm + +/-- **Uniqueness of the positive right factor `J`.** If `A = U' ∘L J'` with `U'` unitary and +`J'` positive, then `J' = |A| = √(A† A)`. Indeed `A† ∘L A = J' ∘L U'† ∘L U' ∘L J' = J' ∘L J'` +(as `U'† ∘L U' = 1`), so `J'` is a positive square root of `A† A`; the shared uniqueness lemma +`absoluteValue_eq_of_isPositive_sq` then gives `J' = |A|`. -/ +theorem absoluteValue_eq_of_unitary_comp {U' J' : E →L[𝕜] E} + (hU' : U' ∈ unitary (E →L[𝕜] E)) (hJ' : J'.IsPositive) (h : A = U' ∘L J') : + J' = A.absoluteValue := by + have hstarU' : star U' * U' = 1 := by simpa using Unitary.coe_star_mul_self ⟨U', hU'⟩ + have hJ'sa : IsSelfAdjoint J' := hJ'.isSelfAdjoint + have hAA : A.adjoint ∘L A = J' ∘L J' := by + have hAadj : A.adjoint = J' ∘L star U' := adjoint_eq_comp_star_of_isSelfAdjoint hJ'sa h + rw [hAadj] + nth_rewrite 1 [h] + simp only [← ContinuousLinearMap.mul_def] + rw [show J' * star U' * (U' * J') = J' * (star U' * U') * J' by noncomm_ring, hstarU', + mul_one] + exact A.absoluteValue_eq_of_isPositive_sq hJ' hAA.symm + +/-- **Uniqueness of the positive left factor `K`.** If `A = K' ∘L U'` with `U'` unitary and +`K'` positive, then `K' = |A†| = √(A A†)`. This is `absoluteValue_eq_of_unitary_comp` applied +to `A†`: from `A = K' ∘L U'` we get `A† = (star U') ∘L K'` with `star U'` unitary, so `K'` is +the unique positive right factor of `A†`, namely `|A†|`. -/ +theorem adjoint_absoluteValue_eq_of_comp_unitary {U' K' : E →L[𝕜] E} + (hU' : U' ∈ unitary (E →L[𝕜] E)) (hK' : K'.IsPositive) (h : A = K' ∘L U') : + K' = A.adjoint.absoluteValue := by + have hsU' : star U' ∈ unitary (E →L[𝕜] E) := Unitary.star_mem hU' + have hAadj : A.adjoint = star U' ∘L K' := by + rw [h, ContinuousLinearMap.adjoint_comp, hK'.isSelfAdjoint.adjoint_eq, + ← ContinuousLinearMap.star_eq_adjoint] + exact A.adjoint.absoluteValue_eq_of_unitary_comp hsU' hK' hAadj + +/-- **Uniqueness of the unitary factor `U` for invertible `A`.** If `A` is invertible and +`A = U₁ ∘L J₁ = U₂ ∘L J₂` are two unitary–positive factorisations, then `U₁ = U₂`. By +`absoluteValue_eq_of_unitary_comp` both `J₁` and `J₂` equal `|A|`, and `A` invertible forces +`|A|` invertible (`|A| = U₁† ∘L A`, a product of units), so `U₁ = U₂` by right-cancelling +`|A|` in `U₁ ∘L |A| = A = U₂ ∘L |A|`. -/ +theorem unitary_factor_unique_of_isUnit {U₁ U₂ J₁ J₂ : E →L[𝕜] E} (hA : IsUnit A) + (hU₁ : U₁ ∈ unitary (E →L[𝕜] E)) (hU₂ : U₂ ∈ unitary (E →L[𝕜] E)) + (hJ₁ : J₁.IsPositive) (hJ₂ : J₂.IsPositive) + (h₁ : A = U₁ ∘L J₁) (h₂ : A = U₂ ∘L J₂) : U₁ = U₂ := by + obtain rfl : J₁ = A.absoluteValue := A.absoluteValue_eq_of_unitary_comp hU₁ hJ₁ h₁ + obtain rfl : J₂ = A.absoluteValue := A.absoluteValue_eq_of_unitary_comp hU₂ hJ₂ h₂ + have hstarU₁ : IsUnit (star U₁) := + ⟨⟨star U₁, U₁, by simpa using Unitary.coe_star_mul_self ⟨U₁, hU₁⟩, + by simpa using Unitary.coe_mul_star_self ⟨U₁, hU₁⟩⟩, rfl⟩ + have hstar_mul : star U₁ * U₁ = 1 := by simpa using Unitary.coe_star_mul_self ⟨U₁, hU₁⟩ + have habs_eq : A.absoluteValue = star U₁ * A := by + conv_rhs => rw [h₁] + simp only [← ContinuousLinearMap.mul_def] + rw [← mul_assoc, hstar_mul, one_mul] + have habs_unit : IsUnit A.absoluteValue := habs_eq ▸ hstarU₁.mul hA + have heq : U₁ * A.absoluteValue = U₂ * A.absoluteValue := by + simp only [← ContinuousLinearMap.mul_def] at h₁ h₂ + rw [← h₁, ← h₂] + exact habs_unit.mul_left_injective heq + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PosNegPart.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PosNegPart.lean new file mode 100644 index 0000000000..8f15ee891a --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PosNegPart.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.StarOrder +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic +public import Mathlib.Analysis.InnerProductSpace.Orthogonal +public import Mathlib.Analysis.CStarAlgebra.ContinuousLinearMap + +/-! +# Positive/negative-part decomposition of a self-adjoint operator + +Every self-adjoint operator `A` on a complex Hilbert space is the difference `A = Q - R` of +two positive operators `Q, R` whose supports (ranges) are orthogonal subspaces. This is the +operator form of the Jordan–Hahn decomposition, and the ingredient Nielsen & Chuang use in +Exercise 9.7 (p. 405) to write a difference of density operators `ρ - σ = Q - R` with `Q, R` +positive on orthogonal supports. + +The witnesses are the continuous-functional-calculus **positive and negative parts** `A⁺` and +`A⁻` (`CFC.posPart` / `CFC.negPart`), for which Mathlib already proves `A⁺ - A⁻ = A` +(`CFC.posPart_sub_negPart`, needing self-adjointness) and `A⁺ * A⁻ = 0` +(`CFC.posPart_mul_negPart`). The genuinely new content here is the bridge from the C⋆-order +`0 ≤ A⁺` (which the CFC delivers) to the operator-theoretic `A⁺.IsPositive` +(`ContinuousLinearMap.nonneg_iff_isPositive`), and the passage from the product identity +`Q * R = 0` to the orthogonality of the ranges of two self-adjoint operators. + +The orthogonal-supports fact `isOrtho_range_of_isSelfAdjoint_of_mul_eq_zero` is elementary +adjoint algebra and holds over any `RCLike` field. The positivity of the parts and the +decomposition itself are stated over `ℂ`, because the continuous functional calculus +`ContinuousFunctionalCalculus ℝ (E →L[𝕜] E) IsSelfAdjoint` — and hence `CFC.posPart` on +operators — is currently available in Mathlib only for `𝕜 = ℂ`. + +## Main results + +* `ContinuousLinearMap.isOrtho_range_of_isSelfAdjoint_of_mul_eq_zero` — if `Q` is self-adjoint + and `Q * R = 0` then `range Q ⟂ range R`; the general fact (over any `RCLike` field) that a + vanishing product forces orthogonal ranges (the operator form of "orthogonal supports"). +* `ContinuousLinearMap.isPositive_posPart` / `ContinuousLinearMap.isPositive_negPart` — the + positive and negative parts `A⁺`, `A⁻` of an operator are positive operators. +* `ContinuousLinearMap.exists_isPositive_sub_of_isSelfAdjoint` — the decomposition itself: a + self-adjoint `A` is `Q - R` with `Q, R` positive, `Q * R = 0`, and `range Q ⟂ range R`. +-/ + +open scoped InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap + +section RCLike + +variable {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [CompleteSpace E] + +/-- **A vanishing product forces orthogonal ranges.** If `Q` is self-adjoint and `Q * R = 0`, +then the range of `Q` is orthogonal to the range of `R`. Indeed for `a b`, +`⟪Q a, R b⟫ = ⟪a, Q (R b)⟫ = ⟪a, (Q * R) b⟫ = 0` using self-adjointness of `Q`. For two positive +operators this is the operator expression of having supports on orthogonal subspaces. Pure +adjoint algebra, so it holds over any `RCLike` field. -/ +theorem isOrtho_range_of_isSelfAdjoint_of_mul_eq_zero {Q R : E →L[𝕜] E} + (hQ : IsSelfAdjoint Q) (h : Q * R = 0) : + LinearMap.range (Q : E →ₗ[𝕜] E) ⟂ LinearMap.range (R : E →ₗ[𝕜] E) := by + rw [Submodule.isOrtho_iff_inner_eq] + rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ + have hcomp : inner 𝕜 ((Q : E →ₗ[𝕜] E) a) ((R : E →ₗ[𝕜] E) b) = inner 𝕜 a ((Q * R) b) := by + rw [ContinuousLinearMap.coe_coe, ContinuousLinearMap.coe_coe, + ← ContinuousLinearMap.adjoint_inner_right, ← ContinuousLinearMap.star_eq_adjoint, hQ] + rfl + rw [hcomp, h] + simp + +end RCLike + +section Complex + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +/-- The **positive part** `A⁺` of an operator is a positive operator. The continuous functional +calculus makes `A⁺` nonnegative in the C⋆-order (`CFC.posPart_nonneg`), which for operators is +exactly `IsPositive` (`ContinuousLinearMap.nonneg_iff_isPositive`). -/ +theorem isPositive_posPart (A : E →L[ℂ] E) : (A⁺).IsPositive := + nonneg_iff_isPositive.mp (CFC.posPart_nonneg A) + +/-- The **negative part** `A⁻` of an operator is a positive operator (the negative part is a +*positive* operator whose subtraction recovers `A`). Dual to `isPositive_posPart`. -/ +theorem isPositive_negPart (A : E →L[ℂ] E) : (A⁻).IsPositive := + nonneg_iff_isPositive.mp (CFC.negPart_nonneg A) + +/-- **Positive/negative-part decomposition of a self-adjoint operator** (the operator form of +the Jordan–Hahn decomposition; Nielsen & Chuang Exercise 9.7). A self-adjoint operator `A` on a +complex Hilbert space can be written `A = Q - R` with `Q` and `R` positive operators whose +supports are orthogonal: `Q * R = 0` and `range Q ⟂ range R`. The witnesses are the positive and +negative parts `A⁺`, `A⁻`. -/ +theorem exists_isPositive_sub_of_isSelfAdjoint (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) : + ∃ Q R : E →L[ℂ] E, Q.IsPositive ∧ R.IsPositive ∧ A = Q - R ∧ Q * R = 0 ∧ + LinearMap.range (Q : E →ₗ[ℂ] E) ⟂ LinearMap.range (R : E →ₗ[ℂ] E) := + ⟨A⁺, A⁻, isPositive_posPart A, isPositive_negPart A, + (CFC.posPart_sub_negPart A hA).symm, CFC.posPart_mul_negPart A, + isOrtho_range_of_isSelfAdjoint_of_mul_eq_zero (isPositive_posPart A).isSelfAdjoint + (CFC.posPart_mul_negPart A)⟩ + +end Complex + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Positive.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Positive.lean new file mode 100644 index 0000000000..8727fe01f8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Positive.lean @@ -0,0 +1,328 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Positive +public import Mathlib.Algebra.Algebra.StrictPositivity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum + +/-! +# Positive operators: additional API + +This file collects additional facts about positive operators on (finite-dimensional) Hilbert +spaces beyond `Mathlib.Analysis.InnerProductSpace.Positive`: + +* A spectral characterisation of positivity for symmetric operators + (`LinearMap.IsSymmetric.isPositive_iff_eigenvalues_nonneg`), the squared-eigenvalue formula + `LinearMap.IsPositive.eigenvalues_sq`, and the operator-norm-equals-top-eigenvalue formulas + `LinearMap.IsSymmetric.norm_eq_iSup_eigenvalues_abs` / + `LinearMap.IsPositive.norm_eq_eigenvalues_zero`. +* Topological closedness of the set of positive continuous endomorphisms + (`ContinuousLinearMap.isClosed_setOf_isPositive`). +* Uniqueness-of-square-root style eigenvector lemmas for positive operators + (`ContinuousLinearMap.IsPositive.apply_eq_zero_of_apply_apply_eq_zero`, + `ContinuousLinearMap.IsPositive.apply_eq_of_isPositive_sq_apply_eq`). +* Invariance of positivity, non-negativity, and strict positivity under conjugation by a linear + isometry equivalence, and consequences of strict positivity for the operator kernel and its + eigenvalues, together with the `HasSupportLE` support-inclusion relation used to state + preconditions for the quantum relative entropy. +-/ + +@[expose] public section + +open InnerProductSpace RCLike LinearMap ContinuousLinearMap + +open scoped InnerProduct ComplexConjugate ComplexOrder + +variable {𝕜 E F : Type*} [RCLike 𝕜] +variable [NormedAddCommGroup E] [NormedAddCommGroup F] +variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] + +namespace LinearMap + +/-- Reverse of `IsPositive.nonneg_eigenvalues`: a symmetric operator with all-nonnegative +eigenvalues is positive. -/ +theorem IsSymmetric.isPositive_of_eigenvalues_nonneg [FiniteDimensional 𝕜 E] + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) + (h : ∀ i, 0 ≤ hT.eigenvalues hn i) : T.IsPositive := by + refine ⟨hT, fun x ↦ ?_⟩ + rw [hT.spectral_sum_apply hn, sum_inner, map_sum] + refine Finset.sum_nonneg fun i _ ↦ ?_ + rw [smul_smul, inner_smul_left, (starRingEnd 𝕜).map_mul, RCLike.conj_ofReal, mul_assoc, + RCLike.conj_mul, ← RCLike.ofReal_pow, ← RCLike.ofReal_mul, RCLike.ofReal_re] + exact mul_nonneg (h i) (by positivity) + +/-- **Spectral characterisation of positive operators**: a symmetric operator on a +finite-dimensional inner product space is positive iff its eigenvalues are all nonnegative. -/ +theorem IsSymmetric.isPositive_iff_eigenvalues_nonneg [FiniteDimensional 𝕜 E] + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) : + T.IsPositive ↔ ∀ i, 0 ≤ hT.eigenvalues hn i := + ⟨fun hP ↦ hP.nonneg_eigenvalues hn, hT.isPositive_of_eigenvalues_nonneg hn⟩ + +/-- For positive `T`, the eigenvalues of `T * T` are pointwise the squares of the eigenvalues of +`T`. The eigenbasis of `T` is also an eigenbasis of `T * T` with squared eigenvalues; for positive +`T` both eigenvalue sequences are antitone (nonneg + sorted nonincreasingly), so multiset +equality upgrades to pointwise equality. -/ +theorem IsPositive.eigenvalues_sq [FiniteDimensional 𝕜 E] + {T : E →ₗ[𝕜] E} (hT : T.IsPositive) {n : ℕ} (hn : Module.finrank 𝕜 E = n) + (h2_sym : (T * T).IsSymmetric) : + h2_sym.eigenvalues hn = hT.isSymmetric.eigenvalues hn ^ 2 := by + symm + apply antitone_eq_of_multiset_map_eq (g := h2_sym.eigenvalues hn) + · intro i j hij + exact pow_le_pow_left₀ (hT.nonneg_eigenvalues hn j) + (hT.isSymmetric.eigenvalues_antitone hn hij) 2 + · exact h2_sym.eigenvalues_antitone hn + · exact IsSymmetric.eigenvalues_multiset_map_eq_of_eigenbasis h2_sym hn + (hT.isSymmetric.eigenvectorBasis hn).toBasis fun i ↦ by + simp only [OrthonormalBasis.coe_toBasis, Pi.pow_apply] + rw [mul_apply_eq_comp, hT.isSymmetric.apply_eigenvectorBasis hn i, + LinearMap.map_smul, hT.isSymmetric.apply_eigenvectorBasis hn i, smul_smul] + push_cast + ring_nf + +/-- The norm of a symmetric operator applied to its `i`-th eigenvector equals the absolute +value of the `i`-th eigenvalue. Direct corollary of `apply_eigenvectorBasis`. -/ +theorem IsSymmetric.norm_apply_eigenvectorBasis [FiniteDimensional 𝕜 E] + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) + (i : Fin n) : ‖T (hT.eigenvectorBasis hn i)‖ = |hT.eigenvalues hn i| := by + rw [hT.apply_eigenvectorBasis hn, norm_smul, RCLike.norm_ofReal, + (hT.eigenvectorBasis hn).orthonormal.1, mul_one] + +/-- **Spectral identity for `‖T v‖²`**: for symmetric `T` on a finite-dimensional inner +product space, `‖T v‖² = ∑ i, eigenvalues_i² · ‖⟨eigenvectorBasis i, v⟩‖²`. The key +quantitative fact behind `norm_eq_iSup_eigenvalues_abs` and any spectral perturbation +argument; stated as a named identity for reuse. -/ +theorem IsSymmetric.norm_apply_sq_eq [FiniteDimensional 𝕜 E] + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) (v : E) : + ‖T v‖ ^ 2 = ∑ i, hT.eigenvalues hn i ^ 2 * ‖⟪hT.eigenvectorBasis hn i, v⟫_𝕜‖ ^ 2 := by + rw [hT.spectral_sum_apply hn v] + simp_rw [smul_smul] + rw [← @inner_self_eq_norm_sq 𝕜, + (hT.eigenvectorBasis hn).orthonormal.inner_sum + (fun i => (hT.eigenvalues hn i : 𝕜) * ⟪hT.eigenvectorBasis hn i, v⟫_𝕜) + (fun i => (hT.eigenvalues hn i : 𝕜) * ⟪hT.eigenvectorBasis hn i, v⟫_𝕜) Finset.univ, + map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [RCLike.conj_mul, ← RCLike.ofReal_pow, RCLike.ofReal_re, norm_mul, RCLike.norm_ofReal, + mul_pow, sq_abs] + +/-- **Operator norm of a symmetric operator on a finite-dimensional inner product space +equals the maximum absolute eigenvalue.** This is the spectral-radius-equals-norm fact +specialized to the finite-dimensional self-adjoint case. -/ +theorem IsSymmetric.norm_eq_iSup_eigenvalues_abs [FiniteDimensional 𝕜 E] [Nontrivial E] + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) : + ‖T.toContinuousLinearMap‖ = ⨆ i : Fin (Module.finrank 𝕜 E), |hT.eigenvalues rfl i| := by + have : NeZero (Module.finrank 𝕜 E) := ⟨Module.finrank_pos.ne'⟩ + set b := hT.eigenvectorBasis (rfl : Module.finrank 𝕜 E = Module.finrank 𝕜 E) + set f : Fin (Module.finrank 𝕜 E) → ℝ := fun i ↦ |hT.eigenvalues rfl i| + have hbdd : BddAbove (Set.range f) := Set.Finite.bddAbove (Set.finite_range _) + have h_le_iSup : ∀ i, f i ≤ ⨆ j, f j := fun i ↦ le_ciSup hbdd i + have h_iSup_nonneg : 0 ≤ ⨆ j, f j := + (abs_nonneg _).trans (h_le_iSup ⟨0, Module.finrank_pos⟩) + refine le_antisymm ?_ ?_ + · -- Upper bound: ‖T v‖² ≤ (⨆ |λᵢ|)² · ‖v‖² via the spectral identity for ‖T v‖². + refine T.toContinuousLinearMap.opNorm_le_bound h_iSup_nonneg fun v ↦ ?_ + simp only [LinearMap.coe_toContinuousLinearMap'] + have hnorm_sq : ‖T v‖ ^ 2 ≤ ((⨆ j, f j) * ‖v‖) ^ 2 := by + rw [hT.norm_apply_sq_eq rfl v, mul_pow] + have h_sq : ∀ i, hT.eigenvalues rfl i ^ 2 ≤ (⨆ j, f j) ^ 2 := fun i ↦ by + rw [← sq_abs (hT.eigenvalues rfl i)] + exact pow_le_pow_left₀ (abs_nonneg _) (h_le_iSup i) 2 + calc ∑ i, hT.eigenvalues rfl i ^ 2 * ‖⟪b i, v⟫_𝕜‖ ^ 2 + ≤ ∑ i, (⨆ j, f j) ^ 2 * ‖⟪b i, v⟫_𝕜‖ ^ 2 := Finset.sum_le_sum fun i _ ↦ + mul_le_mul_of_nonneg_right (h_sq i) (sq_nonneg _) + _ = (⨆ j, f j) ^ 2 * ‖v‖ ^ 2 := by rw [← Finset.mul_sum, b.sum_sq_norm_inner_right] + exact (abs_le_of_sq_le_sq' hnorm_sq (mul_nonneg h_iSup_nonneg (norm_nonneg v))).2 + · -- Lower bound: ‖T (b i)‖ = |λᵢ| ≤ ‖T‖_op; take iSup. + refine ciSup_le fun i ↦ ?_ + have := T.toContinuousLinearMap.le_opNorm (b i) + simp only [LinearMap.coe_toContinuousLinearMap'] at this + rw [hT.norm_apply_eigenvectorBasis rfl i, b.orthonormal.1, mul_one] at this + exact this + +/-- For a positive symmetric operator on a finite-dimensional inner product space (with +nontrivial domain so the eigenvalue list is nonempty), the operator norm equals the +largest eigenvalue (at index `0`, since eigenvalues are sorted descending). Corollary +of `IsSymmetric.norm_eq_iSup_eigenvalues_abs`: for positive operators all eigenvalues are +non-negative, so `|λᵢ| = λᵢ` and the iSup is attained at the antitone-sorted top. -/ +theorem IsPositive.norm_eq_eigenvalues_zero [FiniteDimensional 𝕜 E] [Nontrivial E] + {T : E →ₗ[𝕜] E} (hT : T.IsPositive) : + ‖T.toContinuousLinearMap‖ = + hT.isSymmetric.eigenvalues rfl ⟨0, Module.finrank_pos⟩ := by + have : NeZero (Module.finrank 𝕜 E) := ⟨Module.finrank_pos.ne'⟩ + rw [hT.isSymmetric.norm_eq_iSup_eigenvalues_abs] + simp_rw [abs_of_nonneg (hT.nonneg_eigenvalues rfl _)] + exact le_antisymm + (ciSup_le fun i ↦ hT.isSymmetric.eigenvalues_antitone rfl (Fin.zero_le _)) + (le_ciSup (Set.Finite.bddAbove (Set.finite_range _)) _) + +end LinearMap + +namespace ContinuousLinearMap + +theorem IsPositive.reApplyInnerSelf_nonneg {T : E →L[𝕜] E} (hT : T.IsPositive) (x : E) : + 0 ≤ T.reApplyInnerSelf x := hT.2 x + +/-- The set of positive continuous endomorphisms is closed in the operator-norm topology: +its defining conditions are self-adjointness (closed by isometry of `adjoint`) and pointwise +non-negativity of `reApplyInnerSelf` (closed by `fun_prop` continuity of the map). -/ +theorem isClosed_setOf_isPositive [CompleteSpace E] : + IsClosed {T : E →L[𝕜] E | T.IsPositive} := by + simp_rw [isPositive_def', Set.ofPred_and, Set.ofPred_forall, reApplyInnerSelf_apply] + refine IsClosed.inter ?_ (isClosed_iInter fun x ↦ ?_) + · exact isClosed_eq ContinuousLinearMap.adjoint.isometry.continuous continuous_id + · exact isClosed_le continuous_const (by fun_prop) + +/-- For a positive operator `B` (which is in particular self-adjoint), `B (B x) = 0 → B x = 0`. +Equivalent to `ker (B ∘L B) = ker B`, which for self-adjoint `B` follows from +`ker_adjoint_comp_self` since `B† ∘L B = B ∘L B`. -/ +theorem IsPositive.apply_eq_zero_of_apply_apply_eq_zero [CompleteSpace E] {B : E →L[𝕜] E} + (hB : B.IsPositive) {x : E} (hBBx : B (B x) = 0) : B x = 0 := by + have hmem : x ∈ (B† ∘L B).ker := by + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe, ContinuousLinearMap.comp_apply, + hB.isSelfAdjoint.adjoint_eq] + exact hBBx + rwa [B.ker_adjoint_comp_self, LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at hmem + +/-- **Uniqueness of positive square root, eigenvector form**: for two positive operators +`A, B` with `A ∘L A = B ∘L B`, if `A x = c • x` for nonneg real `c`, then `B x = c • x`. +The proof uses `v := B x - c • x`: a calculation shows `B v = -c • v`, so +`re ⟨B v, v⟩ = -c ‖v‖²`. Combined with `re ⟨B v, v⟩ ≥ 0` (positivity of `B`) and `c ≥ 0`, +this forces `c · ‖v‖² = 0`, giving `c = 0` or `v = 0`; both cases yield `B x = c • x`. -/ +theorem IsPositive.apply_eq_of_isPositive_sq_apply_eq [CompleteSpace E] {A B : E →L[𝕜] E} + (hB : B.IsPositive) (hAB : A ∘L A = B ∘L B) + {c : ℝ} (hc : 0 ≤ c) {x : E} (hAx : A x = (c : 𝕜) • x) : B x = (c : 𝕜) • x := by + set v := B x - (c : 𝕜) • x with hv_def + have hBsq_x : B (B x) = ((c : 𝕜) * c) • x := by + have h1 : (A ∘L A) x = ((c : 𝕜) * c) • x := by + rw [ContinuousLinearMap.comp_apply, hAx, ContinuousLinearMap.map_smul, hAx, smul_smul] + rwa [hAB] at h1 + have hBv : B v = -((c : 𝕜)) • v := by + rw [hv_def, ContinuousLinearMap.map_sub, ContinuousLinearMap.map_smul, hBsq_x] + module + have h_re : RCLike.re ⟪B v, v⟫_𝕜 = -c * ‖v‖ ^ 2 := by + rw [hBv, inner_smul_left, ← inner_self_eq_norm_sq (𝕜 := 𝕜)] + simp [map_neg, RCLike.conj_ofReal, neg_mul] + have h_nn : 0 ≤ RCLike.re ⟪B v, v⟫_𝕜 := hB.2 v + have hzero : c * ‖v‖ ^ 2 = 0 := by + have h1 : 0 ≤ -c * ‖v‖ ^ 2 := h_re ▸ h_nn + have h2 : 0 ≤ c * ‖v‖ ^ 2 := mul_nonneg hc (sq_nonneg _) + linarith + rcases mul_eq_zero.mp hzero with hc0 | hv0 + · subst hc0 + rw [hB.apply_eq_zero_of_apply_apply_eq_zero (by simpa using hBsq_x), + RCLike.ofReal_zero, zero_smul] + · have hv : v = 0 := norm_eq_zero.mp (pow_eq_zero_iff (by norm_num : 2 ≠ 0) |>.mp hv0) + exact sub_eq_zero.mp hv + +/-- Positivity of an operator is preserved under conjugation by a linear isometry equivalence. +CLM-level corollary of the more general LM-level +`LinearMap.isPositive_linearIsometryEquiv_conj_iff`; routes through +`isPositive_toLinearMap_iff` + `conjStarAlgEquiv_apply`. -/ +@[simp] +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_isPositive_iff + [CompleteSpace E] [CompleteSpace F] (e : E ≃ₗᵢ[𝕜] F) {T : E →L[𝕜] E} : + (e.conjStarAlgEquiv T).IsPositive ↔ T.IsPositive := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_apply, ← isPositive_toLinearMap_iff, + ← isPositive_toLinearMap_iff T] + have heq : ((e ∘L T ∘L (e.symm : F →L[𝕜] E) : F →L[𝕜] F) : F →ₗ[𝕜] F) = + e.toLinearMap ∘ₗ (T : E →ₗ[𝕜] E) ∘ₗ e.symm.toLinearMap := by + ext x; simp + rw [heq] + exact LinearMap.isPositive_linearIsometryEquiv_conj_iff (T := T.toLinearMap) e + +/-- CLM-nonneg sibling of `LinearIsometryEquiv.conjStarAlgEquiv_isPositive_iff`: the +order `0 ≤ T` is preserved by conjugation by a linear isometry equivalence. Bridges +the `IsPositive` form through `nonneg_iff_isPositive`. -/ +@[simp] +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_nonneg_iff + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [CompleteSpace E] [CompleteSpace F] (e : E ≃ₗᵢ[𝕜] F) {T : E →L[𝕜] E} : + 0 ≤ e.conjStarAlgEquiv T ↔ 0 ≤ T := by + rw [nonneg_iff_isPositive, nonneg_iff_isPositive, + LinearIsometryEquiv.conjStarAlgEquiv_isPositive_iff] + +/-- Strict positivity is preserved under conjugation by a linear isometry equivalence. The +strict-positivity sibling of `conjStarAlgEquiv_isPositive_iff` / `conjStarAlgEquiv_nonneg_iff`. -/ +@[simp] +theorem _root_.LinearIsometryEquiv.conjStarAlgEquiv_isStrictlyPositive_iff + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [CompleteSpace E] [CompleteSpace F] (e : E ≃ₗᵢ[𝕜] F) {T : E →L[𝕜] E} : + IsStrictlyPositive (e.conjStarAlgEquiv T) ↔ IsStrictlyPositive T := by + rw [IsStrictlyPositive, IsStrictlyPositive, nonneg_iff_isPositive, nonneg_iff_isPositive, + e.conjStarAlgEquiv_isPositive_iff] + refine and_congr_right fun _ ↦ ⟨fun h ↦ ?_, fun h ↦ h.map e.conjStarAlgEquiv⟩ + have := h.map e.conjStarAlgEquiv.symm + rwa [StarAlgEquiv.symm_apply_apply] at this + +/-- A strictly positive operator is a unit, hence bijective, hence injective: its kernel is +trivial. -/ +theorem _root_.IsStrictlyPositive.ker_eq_bot [CompleteSpace E] {T : E →L[𝕜] E} + (h : IsStrictlyPositive T) : LinearMap.ker (T : E →ₗ[𝕜] E) = ⊥ := by + rw [LinearMap.ker_eq_bot] + exact (ContinuousLinearMap.isUnit_iff_bijective.mp h.2).injective + +/-- The **support condition** `supp ρ ⊆ supp σ` for the relative entropy `D(ρ ‖ σ)`, in the +operator-kernel form `ker σ ≤ ker ρ` (for positive operators `supp = (ker)ᗮ`, so the support +inclusion reverses on kernels). The precondition under which the `cfc`-based `D` is meaningful. +(Placed here, below both `QuantumRelativeEntropy` and `ReducedState`, so the +`HasSupportLE.of_partialTraceRight` marginal-preservation lemma can live beside its +`of_partialTraceRight_eq` siblings.) -/ +def HasSupportLE (ρ σ : E →L[𝕜] E) : Prop := + LinearMap.ker (σ : E →ₗ[𝕜] E) ≤ LinearMap.ker (ρ : E →ₗ[𝕜] E) + +theorem hasSupportLE_iff {ρ σ : E →L[𝕜] E} : + HasSupportLE ρ σ ↔ LinearMap.ker (σ : E →ₗ[𝕜] E) ≤ LinearMap.ker (ρ : E →ₗ[𝕜] E) := + Iff.rfl + +/-- A faithful (strictly positive) `σ` dominates the support of every `ρ`: its kernel is trivial, +so the support condition holds unconditionally. -/ +theorem HasSupportLE.of_isStrictlyPositive [CompleteSpace E] {ρ σ : E →L[𝕜] E} + (h : IsStrictlyPositive σ) : HasSupportLE ρ σ := by + rw [hasSupportLE_iff, IsStrictlyPositive.ker_eq_bot h] + exact bot_le + +/-- **The eigenvalues of a strictly positive operator are strictly positive.** Strengthens +`LinearMap.IsPositive.nonneg_eigenvalues` (which gives only `0 ≤`) using invertibility: `0` cannot +be an eigenvalue of a unit, so the nonnegative eigenvalues are in fact positive. Stated against an +explicit symmetry witness `hsym` so it matches a consumer's chosen `eigenvalues` term (the value is +independent of the proof by proof irrelevance). -/ +theorem _root_.IsStrictlyPositive.eigenvalues_pos [FiniteDimensional 𝕜 E] {T : E →L[𝕜] E} + (hT : IsStrictlyPositive T) (hsym : (T : E →ₗ[𝕜] E).IsSymmetric) {n : ℕ} + (hn : Module.finrank 𝕜 E = n) (i : Fin n) : 0 < hsym.eigenvalues hn i := by + refine lt_of_le_of_ne (((isPositive_toLinearMap_iff T).mpr + (nonneg_iff_isPositive.mp hT.nonneg)).nonneg_eigenvalues hn i) (Ne.symm fun h0 ↦ ?_) + refine spectrum.not_isUnit_of_zero_mem 𝕜 ?_ + (hT.isUnit.map (ContinuousLinearMap.toLinearMapRingHom (R₁ := 𝕜) (M₁ := E))) + simpa [h0] using (hsym.hasEigenvalue_eigenvalues hn i).mem_spectrum + +/-- **Vanishing propagates along the support condition.** If `ρ.HasSupportLE σ` (`ker σ ≤ ker ρ`) +and `σ x = 0`, then `ρ x = 0`: the vector `x` lies in `ker σ`, hence in `ker ρ`. The pointwise form +of the support condition, the reusable consequence behind support-condition arguments. -/ +theorem HasSupportLE.apply_eq_zero {ρ σ : E →L[𝕜] E} (h : ρ.HasSupportLE σ) {x : E} + (hx : σ x = 0) : ρ x = 0 := + LinearMap.mem_ker.mp (h (LinearMap.mem_ker.mpr hx)) + +section Complex + +variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace ℂ E'] + +/-- **Positivity is preserved under nonnegative real scaling.** For a positive operator `T` and a +nonnegative real scalar `c` (`0 ≤ c`), the real scalar multiple `c • T` is positive. The +real-scalar companion of `IsPositive.smul_of_nonneg` (which takes a `ℂ`-scalar): `c • T` is +rewritten to `(↑c : ℂ) • T` via `Complex.coe_smul`, with `0 ≤ (↑c : ℂ)`. -/ +theorem IsPositive.smul_real_of_nonneg {T : E' →L[ℂ] E'} (hT : T.IsPositive) {c : ℝ} + (hc : 0 ≤ c) : (c • T).IsPositive := by + rw [← Complex.coe_smul c T] + exact hT.smul_of_nonneg (RCLike.nonneg_iff_exists_ofReal.mpr ⟨c, hc, rfl⟩) + +end Complex + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PostMeasurement.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PostMeasurement.lean new file mode 100644 index 0000000000..92341bbcc6 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PostMeasurement.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum + +/-! +# The post-measurement operation + +Operator algebra underlying measurement state-update (Nielsen–Chuang Eq. (8.5)). +For a family of measurement operators `M` and an operator `ρ`, the +**post-measurement operation** `Eₘ(ρ) = Mₘ ρ Mₘ†` is positive when `ρ` is; its +normalization `Eₘ(ρ)/tr(Eₘ(ρ))` is a density operator when `ρ` is and the outcome +is possible. +-/ + +open scoped InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + {ι : Type*} [fin : FiniteDimensional ℂ H] + +/-- The **post-measurement operation** of outcome `m`: `Eₘ(ρ) = Mₘ ρ Mₘ†`. -/ +noncomputable def postOp (M : ι → H →L[ℂ] H) (ρ : H →L[ℂ] H) (m : ι) : H →L[ℂ] H := + (M m) ∘L ρ ∘L (adjoint (M m)) + +omit fin in +/-- `Eₘ(ρ) = Mₘ ρ Mₘ†` is positive when `ρ` is positive. -/ +theorem postOp_isPositive (M : ι → H →L[ℂ] H) {ρ : H →L[ℂ] H} + (hρ : ρ.IsPositive) (m : ι) : (postOp M ρ m).IsPositive := + hρ.conj_adjoint (M m) + +/-- `tr(Mₘ ρ Mₘ†) = tr(Mₘ† Mₘ ρ)` (cyclicity of the trace). -/ +theorem trace_postOp (M : ι → H →L[ℂ] H) (ρ : H →L[ℂ] H) (m : ι) : + LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H) + = LinearMap.trace ℂ H + (((adjoint (M m)) ∘L (M m) ∘L ρ : H →L[ℂ] H) : H →ₗ[ℂ] H) := by + simp only [postOp, ContinuousLinearMap.toLinearMap_comp] + rw [LinearMap.trace_comp_comm', LinearMap.comp_assoc, LinearMap.trace_comp_comm', + LinearMap.comp_assoc] + +include fin in +/-- For positive `ρ`, the trace of the post-measurement operation is a non-negative +real. -/ +theorem trace_postOp_eq_ofReal_re (M : ι → H →L[ℂ] H) {ρ : H →L[ℂ] H} + (hρ : ρ.IsPositive) (m : ι) : + LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H) + = ((RCLike.re (LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H)) : ℝ) : ℂ) := by + have hsym := (postOp_isPositive M hρ m).toLinearMap.isSymmetric + rw [hsym.re_trace_eq_sum_eigenvalues rfl, hsym.trace_eq_sum_eigenvalues rfl] + push_cast + rfl + +/-- The **normalized post-measurement state** of outcome `m`: +`Eₘ(ρ)/tr(Eₘ(ρ)) = (re tr(Eₘ(ρ)))⁻¹ • Eₘ(ρ)`. -/ +noncomputable def postState (M : ι → H →L[ℂ] H) (ρ : H →L[ℂ] H) (m : ι) : H →L[ℂ] H := + ((RCLike.re (LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H)) : ℝ)⁻¹ : ℂ) • postOp M ρ m + +include fin in +/-- When `ρ` is a density operator and outcome `m` is possible (`tr(Eₘ(ρ)) ≠ 0`), +the normalized post-measurement operator is again a density operator. -/ +theorem postState_isDensityOp (M : ι → H →L[ℂ] H) {ρ : H →L[ℂ] H} (hρ : ρ.IsDensityOp) + (m : ι) + (hne : RCLike.re (LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H)) ≠ 0) : + (postState M ρ m).IsDensityOp := by + have hEpos : (postOp M ρ m).IsPositive := postOp_isPositive M hρ.isPositive m + have hpnn : 0 ≤ RCLike.re (LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H)) := + (RCLike.nonneg_iff.mp hEpos.toLinearMap.trace_nonneg).1 + refine ⟨?_, ?_⟩ + · rw [postState] + refine hEpos.smul_of_nonneg ?_ + rw [RCLike.le_iff_re_im] + refine ⟨?_, ?_⟩ + · simpa using inv_nonneg.mpr hpnn + · simp + · rw [postState, ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul] + nth_rewrite 2 [trace_postOp_eq_ofReal_re M hρ.isPositive m] + rw [← Complex.ofReal_inv, ← Complex.ofReal_mul, Complex.ofReal_eq_one, + inv_mul_cancel₀ hne] + +omit fin in +/-- The post-measurement operation `Eₘ(ρ) = Mₘ ρ Mₘ†` is `ℂ`-linear in the operator argument: +`Eₘ(c ρ) = c Eₘ(ρ)`. -/ +theorem postOp_smul (M : ι → H →L[ℂ] H) (c : ℂ) (ρ : H →L[ℂ] H) (m : ι) : + postOp M (c • ρ) m = c • postOp M ρ m := by + simp only [postOp, smul_comp, comp_smul] + +omit fin in +/-- The normalized post-measurement state is invariant under rescaling the input operator by a +nonzero real: `postState M ((c : ℂ) • ρ) m = postState M ρ m` for `c ≠ 0`. The normalization +`Eₘ(c ρ)/tr(Eₘ(c ρ))` cancels the factor `c`. -/ +theorem postState_smul (M : ι → H →L[ℂ] H) (ρ : H →L[ℂ] H) (m : ι) {c : ℝ} (hc : c ≠ 0) : + postState M ((c : ℂ) • ρ) m = postState M ρ m := by + have hcC : (c : ℂ) ≠ 0 := by exact_mod_cast hc + -- `re tr(c • Eₘ(ρ)) = c · re tr(Eₘ(ρ))`, so the normalization factor cancels the extra `c`. + have hre : RCLike.re (LinearMap.trace ℂ H + (((c : ℂ) • postOp M ρ m : H →L[ℂ] H) : H →ₗ[ℂ] H)) + = c * RCLike.re (LinearMap.trace ℂ H (postOp M ρ m : H →ₗ[ℂ] H)) := by + rw [ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul]; simp + rw [postState, postState, postOp_smul, hre, smul_smul] + congr 1 + rw [Complex.ofReal_mul, mul_inv, mul_right_comm, inv_mul_cancel₀ hcC, one_mul] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurement.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurement.lean new file mode 100644 index 0000000000..7238ff7b87 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurement.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.POVM +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedInverseSqrt + +/-! +# The pretty-good (square-root) POVM of a positive family + +Given a finite family of positive operators `A : ι → E →L[ℂ] E` on a finite-dimensional complex +inner product space, this file assembles the **pretty-good (square-root) measurement** into a +genuine `POVM` over the outcome set `Option ι`. With total operator `S = ∑ⱼ A j`, the effects are + +`E i = S^(-1/2) · A i · S^(-1/2)` (`some i`), `E₀ = 1 - ∑ᵢ E i` (`none`, the +"inconclusive"/junk +outcome), + +where `S^(-1/2)` is the generalized inverse square root (`ContinuousLinearMap.genInvSqrt`). Each +`E i` +is positive (conjugation of `A i ≥ 0` by the self-adjoint `S^(-1/2)`, +`ContinuousLinearMap.genInvSqrt_conjugate_nonneg`), the completeness bound +`ContinuousLinearMap.sum_genInvSqrt_conjugate_le_one` gives `∑ᵢ E i ≤ 1` so the junk effect +`E₀ ≥ 0`, and the two together sum to `1` by construction — the three `POVM` obligations. + +## What this file provides + +* `POVM.prettyGood` — the pretty-good POVM `POVM (Option ι) ℂ E` of a positive family `A`. +* `POVM.prettyGood_elements_some`, `POVM.prettyGood_elements_none` — the effect formulas. + +## Motivation + +This is the "square-root measurement" / pretty-good measurement, the decoding POVM at the heart of +the achievability direction of the **Holevo–Schumacher–Westmoreland theorem** (Nielsen & Chuang, +Box 12.5, eq. (12.78)): Bob's decoder is exactly `POVM.prettyGood` applied to the family +`A_M = P · P_M · P` built from the typical projector `P` of the average output `σ_bar⊗ⁿ` and the +conditional-typical projectors `P_M` of the codewords, with the junk element `E₀` collecting the +inconclusive outcome. The construction is stated generally (for any positive family) because it is +the standard reusable object; the physics-specific instantiation is a one-liner in the consumer. + +The statements involve only `POVM`, operators `A : E →L[ℂ] E`, the identity `1`, the generalized +inverse square root, and `Finset.sum`; they extend the `POVM` API +(`ToMathlib.Analysis.InnerProductSpace.POVM`) with the completeness core of +`ToMathlib.Analysis.InnerProductSpace.GeneralizedInverseSqrt`. +-/ + +@[expose] public section + +noncomputable section + +namespace POVM + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {ι : Type*} [Fintype ι] + +open ContinuousLinearMap in +/-- **The pretty-good (square-root) POVM of a positive family** `A : ι → E →L[ℂ] E`. With total +operator `S = ∑ⱼ A j`, the effect at outcome `some i` is the conjugation `S^(-1/2) · A i · +S^(-1/2)`, and +the effect at `none` is the "inconclusive" junk operator `E₀ = 1 - ∑ᵢ S^(-1/2) · A i · S^(-1/2)`. + +The three POVM obligations are exactly the results of `GeneralizedInverseSqrt`: +* each `some`-effect is positive by `genInvSqrt_conjugate_nonneg` (conjugation of the positive `A i` + by the self-adjoint `S^(-1/2)`); +* the `none`-effect is positive because `∑ᵢ E i ≤ 1` (`sum_genInvSqrt_conjugate_le_one`), so + `1 - ∑ᵢ E i ≥ 0`; +* the effects sum to `1` by `1 - ∑ᵢ E i` cancelling `∑ᵢ E i`. + +This is the decoding POVM of the HSW theorem (Nielsen & Chuang, Box 12.5, eq. (12.78)) once `A i` is +instantiated to `P · Pᵢ · P`. -/ +def prettyGood (A : ι → E →L[ℂ] E) (hA : ∀ i, 0 ≤ A i) : POVM (Option ι) ℂ E where + elements := fun o => o.rec + (1 - ∑ i, (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt) + (fun i => (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt) + isPositive := by + rintro (_ | i) + · exact nonneg_iff_isPositive.mp + (sub_nonneg.mpr (sum_genInvSqrt_conjugate_le_one A hA)) + · exact nonneg_iff_isPositive.mp (genInvSqrt_conjugate_nonneg A hA i) + sum_eq_one := by + rw [Fintype.sum_option] + change (1 - ∑ i, (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt) + + ∑ i, (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt = 1 + abel + +open ContinuousLinearMap in +/-- The pretty-good POVM effect at a genuine outcome `some i` is the conjugation +`S^(-1/2) · A i · S^(-1/2)` (`S = ∑ⱼ A j`). -/ +@[simp] +theorem prettyGood_elements_some (A : ι → E →L[ℂ] E) (hA : ∀ i, 0 ≤ A i) (i : ι) : + (prettyGood A hA).elements (some i) + = (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt := + rfl + +open ContinuousLinearMap in +/-- The pretty-good POVM junk effect at the inconclusive outcome `none` is +`E₀ = 1 - ∑ᵢ S^(-1/2) · A i · S^(-1/2)`. -/ +@[simp] +theorem prettyGood_elements_none (A : ι → E →L[ℂ] E) (hA : ∀ i, 0 ≤ A i) : + (prettyGood A hA).elements none + = 1 - ∑ i, (∑ j, A j).genInvSqrt * A i * (∑ j, A j).genInvSqrt := + rfl + +end POVM diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurementError.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurementError.lean new file mode 100644 index 0000000000..0204e9e7ea --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/PrettyGoodMeasurementError.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCSqrtGramFamily + +/-! +# The decoder-error reduction of the pretty-good measurement (N&C Box 12.5, eqs. (12.86)→(12.88)) + +In Nielsen & Chuang's random-coding proof of the Holevo–Schumacher–Westmoreland theorem +(Theorem 12.8, achievability), the average error of the pretty-good (square-root) decoder is +reduced, message by message, to a sum over the codeword's diagonal *decoding overlaps* before the +"calculating the spurs" step evaluates those overlaps as physical traces. Concretely (Box 12.5, +eqs. (12.84)–(12.88)), for the true message `M` with codeword `σ_M = ∑_κ λ^M_κ |E^M_κ⟩⟨E^M_κ|` and +pretty-good effect `E_M = S^(-1/2) · (∑_{κ∈T_M} |E_tilde^M_κ⟩⟨E_tilde^M_κ|) · S^(-1/2)` +(`E_tilde^M_κ = P|E^M_κ⟩`, `S = ∑_{M',κ'∈T_{M'}} |E_tilde^{M'}_{κ'}⟩⟨E_tilde^{M'}_{κ'}|`), the +deficit is + +`1 − tr(σ_M E_M) + = 1 − ∑_κ ∑_{κ'∈T_M} λ^M_κ |α_{(M,κ),(M,κ')}|²` (eq. (12.86)) +` ≤ 2·∑_{κ∈T_M} λ^M_κ (1 − α_{(M,κ),(M,κ)}) + ∑_{κ∉T_M} λ^M_κ` (eq. (12.88)), + +where `α_{(M,κ),(M,κ')} = ⟨E_tilde^M_κ, S^(-1/2) E_tilde^M_{κ'}⟩` is the decoding overlap (the +entries of `√Γ`, +`Γ = V⋆·V` the Gram operator). + +This file provides that reduction in **operator form**, decoupled from the physical +apparatus: the codeword eigenbasis is an arbitrary spectral family `φ`, the compressed frame vectors +an arbitrary family `ψ`, the generalized inverse square root an arbitrary self-adjoint operator `T`, +and the typical set an arbitrary `Finset`. The instantiation `T = S^(-1/2)`, `φ = ` codeword +eigenbasis, `ψ = P ∘ φ`, `T_M = ` conditional typical set (which identifies the overlap +`re⟨ψ_κ, T φ_κ⟩` with the `√Γ` diagonal `re⟨e_κ, √Γ e_κ⟩` of `two_mul_sum_one_sub_re_inner_cfc_sqrt` +`_gram_le` via `P`-absorption) is carried out in +`AxQM/Postulates/API/CondTypicalSubspaceDecoder.lean`. + +## Main result + +* `InnerProductSpace.one_sub_re_trace_selfAdjoint_conj_frame_le` — for a self-adjoint `T`, a + spectral family `φ` with nonnegative weights `λ` summing to `1`, a frame family `ψ`, and a + typical `Finset J`, + + `1 − re tr((∑_k λ_k |φ_k⟩⟨φ_k|) · T · (∑_{j∈J} |ψ_j⟩⟨ψ_j|) · T) + ≤ 2·∑_{k∈J} λ_k (1 − re⟨ψ_k, T φ_k⟩) + ∑_{k∉J} λ_k`. + +## Proof + +Writing `α_k = re⟨ψ_k, T φ_k⟩` (the decoding overlap) and `β_k = ∑_{j∈J} ‖⟨ψ_j, T φ_k⟩‖²` (the +per-eigenvector kept overlap mass), the trace evaluates to `∑_k λ_k β_k`: trace cyclicity +(`LinearMap.trace_mul_comm`) plus `trace_comp_sum_smul_rankOne_self` turn it into +`∑_k λ_k ⟨φ_k, T (∑_{j∈J}|ψ_j⟩⟨ψ_j|) T φ_k⟩`, and self-adjointness of `T` +(`adjoint_inner_left`) with the frame expansion gives `⟨φ_k, T B T φ_k⟩ = β_k`. Since +`∑_k λ_k = 1`, the deficit is `∑_k λ_k (1 − β_k)`. Splitting `univ = J ∪ Jᶜ`: for `k ∈ Jᶜ` the +diagonal drops non-positively, `1 − β_k ≤ 1` (`0 ≤ β_k`); for `k ∈ J` the diagonal `j = k` term +gives `β_k ≥ α_k²`, whence `1 − β_k ≤ 1 − α_k² ≤ 2(1 − α_k)` (the last step is `0 ≤ (α_k − 1)²`, so +**no** bound on `α_k` is needed — N&C's `0 ≤ α ≤ 1` from the diagonal Cauchy–Schwarz estimate is not +required for the reduction itself). + +The statement involves only `rankOne`, `LinearMap.trace`, `ContinuousLinearMap.adjoint` (via +`IsSelfAdjoint`), `inner`, and `Finset.sum`. Its trace-side companion is +`two_mul_sum_one_sub_re_inner_cfc_sqrt_gram_le` (`CFCSqrtGramFamily`), which bounds the +`2·∑ λ(1−α)` term it produces. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +open ContinuousLinearMap InnerProductSpace + +noncomputable section + +namespace InnerProductSpace + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {κ : Type*} [Fintype κ] [DecidableEq κ] + +/-- **The decoder-error reduction of the pretty-good measurement** (Nielsen & Chuang, Theorem 12.8, +Box 12.5, eqs. (12.86)→(12.88)). For a self-adjoint operator `T` (the generalized inverse square +root `S^(-1/2)`), a spectral family `φ` (the codeword eigenbasis) with nonnegative weights `λ` +summing +to `1` (the eigenvalue distribution), a frame family `ψ` (the compressed typical eigenvectors +`E_tilde = P E`), and a typical index set `J` (the conditional typical set `T_M`), the deficit of +the +square-root ("pretty-good") decoding overlap satisfies + +`1 − re tr((∑_k λ_k |φ_k⟩⟨φ_k|) · T · (∑_{j∈J} |ψ_j⟩⟨ψ_j|) · T) + ≤ 2·∑_{k∈J} λ_k (1 − re⟨ψ_k, T φ_k⟩) + ∑_{k∉J} λ_k`, + +where the operator `T · (∑_{j∈J} |ψ_j⟩⟨ψ_j|) · T = S^(-1/2) · (∑_{κ∈T_M} |E_tilde_κ⟩⟨E_tilde_κ|) · +S^(-1/2)` is the +pretty-good decoder effect for the true message, and `α_k = re⟨ψ_k, T φ_k⟩` is Nielsen & Chuang's +diagonal decoding overlap `α_{(M,κ),(M,κ)}`. + +The trace evaluates to `∑_k λ_k β_k` with `β_k = ∑_{j∈J} ‖⟨ψ_j, T φ_k⟩‖²` (trace cyclicity +`LinearMap.trace_mul_comm`, `trace_comp_sum_smul_rankOne_self`, self-adjointness of `T`, and the +frame expansion), so the deficit is `∑_k λ_k (1 − β_k)`; on the typical set `β_k ≥ α_k²` (its +`j = k` diagonal term) gives `1 − β_k ≤ 1 − α_k² ≤ 2(1 − α_k)` via `0 ≤ (α_k − 1)²`, and off it +`1 − β_k ≤ 1` via `0 ≤ β_k`. No bound on `α_k` is needed for the reduction. -/ +theorem one_sub_re_trace_selfAdjoint_conj_frame_le + (T : E →L[ℂ] E) (hT : IsSelfAdjoint T) + (φ ψ : κ → E) (lam : κ → ℝ) (J : Finset κ) + (hlam : ∀ k, 0 ≤ lam k) (hsum : ∑ k, lam k = 1) : + 1 - RCLike.re (LinearMap.trace ℂ E + (((∑ k, (lam k : ℂ) • rankOne ℂ (φ k) (φ k)).comp + (T.comp ((∑ j ∈ J, rankOne ℂ (ψ j) (ψ j)).comp T))) : E →ₗ[ℂ] E)) + ≤ 2 * ∑ k ∈ J, lam k * (1 - RCLike.re (inner ℂ (ψ k) (T (φ k)))) + ∑ k ∈ Jᶜ, lam k := by + classical + set B : E →L[ℂ] E := ∑ j ∈ J, rankOne ℂ (ψ j) (ψ j) with hBdef + set α : κ → ℝ := fun k => RCLike.re (inner ℂ (ψ k) (T (φ k))) with hαdef + set β : κ → ℝ := fun k => ∑ j ∈ J, ‖inner ℂ (ψ j) (T (φ k))‖ ^ 2 with hβdef + have hadj : ContinuousLinearMap.adjoint T = T := by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact hT + -- The eigenvector-diagonal identity `⟨φ_k, T B T φ_k⟩ = β_k`. + have hkey : ∀ k, inner ℂ (φ k) ((T.comp (B.comp T)) (φ k)) = ((β k : ℝ) : ℂ) := by + intro k + rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply, + ← ContinuousLinearMap.adjoint_inner_left T (B (T (φ k))) (φ k), hadj, hBdef, hβdef, + _root_.sum_apply, inner_sum, Complex.ofReal_sum] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [rankOne_apply, inner_smul_right, ← inner_conj_symm (T (φ k)) (ψ j), RCLike.mul_conj] + norm_cast + -- The decoding overlap trace is `∑_k λ_k β_k`. + have htr : RCLike.re (LinearMap.trace ℂ E + (((∑ k, (lam k : ℂ) • rankOne ℂ (φ k) (φ k)).comp (T.comp (B.comp T))) : E →ₗ[ℂ] E)) + = ∑ k, lam k * β k := by + rw [ContinuousLinearMap.toLinearMap_comp, LinearMap.trace_comp_comm', + ← ContinuousLinearMap.toLinearMap_comp, trace_comp_sum_smul_rankOne_self] + simp_rw [hkey, ← Complex.ofReal_mul, ← Complex.ofReal_sum] + exact Complex.ofReal_re _ + rw [htr] + have hβnn : ∀ k, 0 ≤ β k := fun k => Finset.sum_nonneg fun _ _ => sq_nonneg _ + -- On the typical set, the diagonal `j = k` term forces `β_k ≥ α_k²`. + have hdiag : ∀ k ∈ J, α k ^ 2 ≤ β k := by + intro k hk + have hle : α k ^ 2 ≤ ‖inner ℂ (ψ k) (T (φ k))‖ ^ 2 := by + rw [hαdef, ← sq_abs] + exact pow_le_pow_left₀ (abs_nonneg _) (RCLike.abs_re_le_norm _) 2 + exact hle.trans (Finset.single_le_sum + (f := fun j => ‖inner ℂ (ψ j) (T (φ k))‖ ^ 2) (fun j _ => sq_nonneg _) hk) + have hrw : ∑ k, lam k * (1 - β k) = 1 - ∑ k, lam k * β k := by + simp_rw [mul_one_sub]; rw [Finset.sum_sub_distrib, hsum] + rw [← hrw, ← Finset.sum_add_sum_compl J] + gcongr ?_ + ?_ + · -- typical block: `λ_k (1 − β_k) ≤ 2 λ_k (1 − α_k)` since `1 − α² ≤ 2(1 − α)`. + rw [Finset.mul_sum] + refine Finset.sum_le_sum fun k hk => ?_ + have h1 : 1 - β k ≤ 2 * (1 - α k) := by nlinarith [hdiag k hk, sq_nonneg (α k - 1)] + calc lam k * (1 - β k) ≤ lam k * (2 * (1 - α k)) := + mul_le_mul_of_nonneg_left h1 (hlam k) + _ = 2 * (lam k * (1 - α k)) := by ring + · -- atypical block: `λ_k (1 − β_k) ≤ λ_k` since `0 ≤ β_k`. + refine Finset.sum_le_sum fun k _ => ?_ + have h2 : (1 : ℝ) - β k ≤ 1 := by linarith [hβnn k] + calc lam k * (1 - β k) ≤ lam k * 1 := mul_le_mul_of_nonneg_left h2 (hlam k) + _ = lam k := mul_one _ + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Purification.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Purification.lean new file mode 100644 index 0000000000..cc99a547dc --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Purification.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract + +/-! +# Purification — partial trace of a rank-one projection (Nielsen–Chuang §2.5) + +A bipartite pure state `Ψ : E ⊗[𝕜] F` is a **purification** of an operator `ρ : E →L[𝕜] E` +when the partial trace of its rank-one self-projection over the ancilla factor `F` +recovers `ρ`. The right-hand side `matricize b Ψ ∘L (matricize b Ψ).adjoint` is the +"outer-product" form of the reduced density matrix (for any orthonormal basis `b` on `F`). + +## Main results + +- `TensorProduct.IsPurification` : abstract purification predicate, parametric in an + ancilla `F`. +- `TensorProduct.canonicalPurification` : the canonical doubled purification on + `E ⊗ EuclideanSpace 𝕜 (Fin n)` (n = `Module.finrank 𝕜 E`). +- `TensorProduct.norm_canonicalPurification` / `isPurification_canonicalPurification` + / `exists_purification` : the abstract characterizations + existence corollary. +-/ + +@[expose] public section + +namespace TensorProduct + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [CompleteSpace E] + +/-- **Purification predicate**: `Ψ : E ⊗[𝕜] F` is a purification of `ρ` if the +right-partial-trace at `stdOrthonormalBasis 𝕜 F` of `rankOne Ψ Ψ` equals `ρ` at LM level. -/ +def IsPurification {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [FiniteDimensional 𝕜 F] + (ρ : E →L[𝕜] E) (Ψ : E ⊗[𝕜] F) : Prop := + LinearMap.partialTraceRight (stdOrthonormalBasis 𝕜 F) + ((InnerProductSpace.rankOne 𝕜 Ψ Ψ).toLinearMap) = ρ.toLinearMap + +/-- **Basis-parametric matricize characterization of `IsPurification`** (abstract). +`Ψ` is a purification of `ρ` iff the matricize-square `matricize Ψ ∘ (matricize Ψ)†` +recovers `ρ`, **for any** orthonormal basis `b` on the ancilla `F`. The basis +independence comes from `LinearMap.partialTraceRight_eq_of_basis`. + +This is the CLM-level identity that allows the +purification predicate to be checked / produced via any natural ancilla basis without +threading `stdOrthonormalBasis` through the proof. -/ +theorem isPurification_iff_matricize_comp_adjoint + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + [CompleteSpace F] {ι : Type*} [Fintype ι] + (b : OrthonormalBasis ι 𝕜 F) (ρ : E →L[𝕜] E) (Ψ : E ⊗[𝕜] F) : + IsPurification ρ Ψ ↔ (matricize b Ψ).comp (matricize b Ψ).adjoint = ρ := by + rw [IsPurification, LinearMap.partialTraceRight_eq_of_basis _ b, + partialTraceRight_rankOne_self] + exact ContinuousLinearMap.coe_inj + +omit [CompleteSpace E] in +/-- **Every purification of a density operator has unit norm** (abstract). For any +ancilla `F` and any `Ψ : E ⊗[𝕜] F` purifying a density operator `ρ`, `‖Ψ‖ = 1`. + +Proof: the partial trace preserves trace (`trace_partialTraceRight`), so +`‖Ψ‖² = ⟨Ψ, Ψ⟩ = trace (rankOne Ψ Ψ) = trace (partialTraceRight (rankOne Ψ Ψ)) = trace ρ = 1`. -/ +theorem norm_eq_one_of_isPurification {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) + {Ψ : E ⊗[𝕜] F} (hΨ : IsPurification ρ Ψ) : + ‖Ψ‖ = 1 := by + suffices h : ‖Ψ‖ ^ 2 = 1 by + rw [← Real.sqrt_sq (norm_nonneg _), h, Real.sqrt_one] + have htr : (LinearMap.trace 𝕜 _) ((InnerProductSpace.rankOne 𝕜 Ψ Ψ : + _ →L[𝕜] _).toLinearMap) = 1 := by + rw [← LinearMap.trace_partialTraceRight (stdOrthonormalBasis 𝕜 F), hΨ, hρ.trace_eq_one] + rw [InnerProductSpace.trace_rankOne, inner_self_eq_norm_sq_to_K] at htr + exact_mod_cast htr + +/-- **Canonical doubled purification of a density operator** (abstract, basis-parametric). +For a density operator `ρ : E →L[𝕜] E` and any orthonormal basis `b` on the ancilla `F` +indexed by `Fin (Module.finrank 𝕜 E)`, the canonical purification on `E ⊗[𝕜] F` is built +from `ρ`'s spectral decomposition: + + `canonicalPurification hρ b = ∑ i, (√λᵢ : 𝕜) • (eᵢ ⊗ₜ b i)` + +where `λᵢ, eᵢ` are the eigenvalues and eigenvectors of `ρ` (via `IsSymmetric.eigenvalues` / +`IsSymmetric.eigenvectorBasis`). Setting `F := EuclideanSpace 𝕜 (Fin (Module.finrank 𝕜 E))` +and `b := EuclideanSpace.basisFun _ 𝕜` recovers the original concrete-ancilla form. -/ +noncomputable def canonicalPurification {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] + {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) + (b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 F) : E ⊗[𝕜] F := + ∑ i, (Real.sqrt (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvalues rfl i) : 𝕜) • + (hρ.isPositive.isSelfAdjoint.isSymmetric.eigenvectorBasis rfl i ⊗ₜ[𝕜] b i) + +/-- **The canonical purification's right-partial-trace recovers `ρ`.** Spectral form via +`partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt` reduces the LHS to `∑ i, λᵢ • rankOne eᵢ eᵢ`, +which is the spectral decomposition of `ρ` via `IsSelfAdjoint.spectral_sum`. -/ +theorem isPurification_canonicalPurification {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) + (b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 F) : + IsPurification ρ (canonicalPurification hρ b) := by + have hSA : IsSelfAdjoint ρ := hρ.isPositive.isSelfAdjoint + have hSym := hSA.isSymmetric + rw [IsPurification, + LinearMap.partialTraceRight_rankOne_eq_sum_rankOne_of_schmidt + (stdOrthonormalBasis 𝕜 F) + (Ψ := canonicalPurification hρ b) + (fun i ↦ Real.sqrt (hSym.eigenvalues rfl i)) + (fun i ↦ hSym.eigenvectorBasis rfl i) + (fun i ↦ b i) + b.orthonormal rfl] + conv_rhs => rw [hSA.spectral_sum rfl] + simp only [ContinuousLinearMap.toLinearMap_sum, ContinuousLinearMap.toLinearMap_smul] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [← RCLike.ofReal_pow, Real.sq_sqrt (hρ.eigenvalues_nonneg rfl i)] + +/-- **The canonical doubled purification has unit norm.** Direct corollary of the general +`norm_eq_one_of_isPurification` applied to `isPurification_canonicalPurification`. -/ +theorem norm_canonicalPurification {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) + (b : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 F) : + ‖canonicalPurification hρ b‖ = 1 := + norm_eq_one_of_isPurification hρ (isPurification_canonicalPurification hρ b) + +/-- **Abstract purification existence**: every density operator on a finite-dimensional +inner product space admits a purification on `E ⊗ EuclideanSpace 𝕜 (Fin n)`. Abstract +analog of `ContinuousLinearMap.IsDensityOp.exists_purification`. -/ +theorem exists_purification {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) : + ∃ Ψ : E ⊗[𝕜] EuclideanSpace 𝕜 (Fin (Module.finrank 𝕜 E)), + ‖Ψ‖ = 1 ∧ IsPurification ρ Ψ := + ⟨canonicalPurification hρ (EuclideanSpace.basisFun _ 𝕜), + norm_canonicalPurification hρ _, isPurification_canonicalPurification hρ _⟩ + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumConditionalEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumConditionalEntropy.lean new file mode 100644 index 0000000000..c7665e6d3d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumConditionalEntropy.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumStrongSubadditivity + +/-! +# The conditional entropy as a relative entropy against a maximally mixed factor + +For a strictly positive density operator `ρ` on `E ⊗ F` with `F`-marginal `ρ_F = Tr_E ρ`, the +quantum relative entropy against the product of the **maximally mixed** state on `E` with `ρ_F` is + +`D(ρ ‖ (I/d_E) ⊗ ρ_F) = log d_E + S(ρ_F) - S(ρ)`, `d_E = dim E`. + +Since the conditional entropy of `ρ` (in the Nielsen & Chuang convention `S(A|B) = S(A,B) - S(B)`, +with `A = E`, `B = F`) is `S(ρ) - S(ρ_F)`, this rearranges to `D(ρ ‖ (I/d_E) ⊗ ρ_F) = log d_E - +S(A|B)`, i.e. `S(A|B) = log d_E - D(ρ ‖ (I/d_E) ⊗ ρ_F)`. Because `(I/d_E) ⊗ ρ_F` is an **affine** +function of `ρ` (the maximally mixed factor is constant, and `ρ_F = Tr_E ρ` is linear), the joint +convexity of the relative entropy (Lindblad's theorem) transfers to the **concavity** of the +conditional entropy — this is the operator-level argument behind Nielsen & Chuang Corollary 11.13. + +## Proof + +The identity is the maximally-mixed companion of the mutual-information identity +`ContinuousLinearMap.quantumRelativeEntropy_mapL_partialTrace_eq` and is proved by the same +mechanism: the additive factorization of the operator logarithm on a tensor product +(`IsSelfAdjoint.cfc_log_tensorMap`), the partial-trace/trace duality +(`LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft`), and the self-trace formula +`re tr(ρ log ρ) = -S(ρ)`. The only new ingredient is that the logarithm of the maximally mixed +operator `(1/d_E) • 1` is the scalar `-log d_E • 1` (via `cfc_algebraMap`), so the `E`-factor trace +term collapses to `-log d_E` without reference to the `E`-marginal. + +The two `Finset.sum` distributivity helpers `LinearMap.partialTraceLeft_sum_smul` and +`TensorProduct.mapL_sum_smul_right` (the partial trace and the tensor map commute with a finite +`𝕜`-linear combination) support the physics-layer transfer of joint convexity to concavity, where +the mixture `∑ᵢ wᵢ ρᵢ` and its marginal must be threaded through both operations. They are one-line +consequences of the bundled `LinearMap.partialTraceLeftLM` and of `TensorProduct.mapL_sum_right`. + +## Main results + +* `ContinuousLinearMap.quantumRelativeEntropy_mapL_maximallyMixed_left_eq` — the identity above. +* `LinearMap.partialTraceLeft_sum_smul` / `TensorProduct.mapL_sum_smul_right` — the sum helpers. +-/ + +@[expose] public section + +open Module InnerProductSpace +open scoped TensorProduct + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + +/-- **The partial trace over the left factor commutes with a finite linear combination**: +`Tr_E (∑ᵢ cᵢ • Tᵢ) = ∑ᵢ cᵢ • Tr_E Tᵢ`. A one-line consequence of the `𝕜`-linearity of the bundled +`LinearMap.partialTraceLeftLM`, used to push a mixture `∑ᵢ wᵢ ρᵢ` through the reduced-state +construction. -/ +theorem partialTraceLeft_sum_smul {ι₁ : Type*} [Fintype ι₁] (bE : OrthonormalBasis ι₁ 𝕜 E) + {ι : Type*} [Fintype ι] (c : ι → 𝕜) (T : ι → (E ⊗[𝕜] F) →ₗ[𝕜] (E ⊗[𝕜] F)) : + LinearMap.partialTraceLeft bE (∑ i, c i • T i) + = ∑ i, c i • LinearMap.partialTraceLeft bE (T i) := by + simp only [← LinearMap.partialTraceLeftLM_apply, map_sum, map_smul] + +/-- **The partial trace over the right factor commutes with a finite linear combination**: +`Tr_F (∑ᵢ cᵢ • Tᵢ) = ∑ᵢ cᵢ • Tr_F Tᵢ`. The `partialTraceRight` companion of +`partialTraceLeft_sum_smul`, a one-line consequence of the `𝕜`-linearity of the bundled +`LinearMap.partialTraceRightLM`. -/ +theorem partialTraceRight_sum_smul {ι₂ : Type*} [Fintype ι₂] (bF : OrthonormalBasis ι₂ 𝕜 F) + {ι : Type*} [Fintype ι] (c : ι → 𝕜) (T : ι → (E ⊗[𝕜] F) →ₗ[𝕜] (E ⊗[𝕜] F)) : + LinearMap.partialTraceRight bF (∑ i, c i • T i) + = ∑ i, c i • LinearMap.partialTraceRight bF (T i) := by + simp only [← LinearMap.partialTraceRightLM_apply, map_sum, map_smul] + +end LinearMap + +namespace TensorProduct + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + +/-- **The tensor map commutes with a finite linear combination in its second argument**: +`M ⊗ (∑ᵢ cᵢ • gᵢ) = ∑ᵢ cᵢ • (M ⊗ gᵢ)`. A one-line consequence of distributivity over sums +(`TensorProduct.mapL_sum_right`) and homogeneity (`TensorProduct.mapL_smul_right`) in the second +argument, used to push a mixed marginal through the `(I/d) ⊗ ·` construction. -/ +theorem mapL_sum_smul_right (M : E →L[𝕜] E) {ι : Type*} [Fintype ι] (c : ι → 𝕜) + (g : ι → F →L[𝕜] F) : + TensorProduct.mapL M (∑ i, c i • g i) = ∑ i, c i • TensorProduct.mapL M (g i) := by + simp only [TensorProduct.mapL_sum_right, TensorProduct.mapL_smul_right] + +end TensorProduct + +namespace ContinuousLinearMap + +variable {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + +omit [FiniteDimensional ℂ E] in +/-- **The operator logarithm of the maximally mixed operator is a scalar**: for the maximally +mixed operator `I/d = (finrank ℂ E : ℂ)⁻¹ • 1` on `E`, `log(I/d) = -log d • 1`. A companion of +the `*_finrank_inv_smul_one` family (`isDensityOp_`/`isStrictlyPositive_`/`vonNeumannEntropy_`), +computed from `cfc_algebraMap` — the operator is the real scalar `algebraMap ℝ _ ((finrank ℂ E)⁻¹)` +times the identity. -/ +theorem cfc_log_finrank_inv_smul_one : + cfc Real.log ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)) + = ((- Real.log (Module.finrank ℂ E) : ℝ) : ℂ) • (1 : E →L[ℂ] E) := by + have : NormedSpace ℝ (E →L[ℂ] E) := NormedSpace.complexToReal + have : IsScalarTower ℝ ℂ (E →L[ℂ] E) := IsScalarTower.of_algebraMap_smul fun _ _ => rfl + have hM : ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)) + = algebraMap ℝ (E →L[ℂ] E) ((Module.finrank ℂ E : ℝ)⁻¹) := by + rw [IsScalarTower.algebraMap_apply ℝ ℂ (E →L[ℂ] E), Algebra.algebraMap_eq_smul_one] + norm_num + rw [hM, cfc_algebraMap, Real.log_inv, IsScalarTower.algebraMap_apply ℝ ℂ (E →L[ℂ] E), + Algebra.algebraMap_eq_smul_one] + norm_num + +/-- **Relative entropy against a maximally mixed factor computes the conditional entropy.** +For a strictly positive density operator `ρ` on `E ⊗ F` with `F`-marginal `ρ_F = Tr_E ρ`, + +`D(ρ ‖ (I/d_E) ⊗ ρ_F) = log d_E + S(ρ_F) - S(ρ)`, `d_E = dim E`, + +where `I/d_E = (finrank ℂ E : ℂ)⁻¹ • 1` is the maximally mixed operator on `E`. Rearranged, this is +`S(ρ) - S(ρ_F) = log d_E - D(ρ ‖ (I/d_E) ⊗ ρ_F)`: the conditional entropy `S(A|B) = S(A,B) - S(B)` +(N&C convention, `A = E`, `B = F`) is an affine image of the relative entropy, whence the joint +convexity of the latter yields the concavity of the former (N&C Corollary 11.13). + +The `F`-marginal is supplied as a hypothesis (`hρF`) so a bundled reduced state threads directly. +Faithfulness (`IsStrictlyPositive ρ`) is the finite-branch hypothesis of the relative-entropy +engine; it makes `ρ_F` strictly positive, so `log((I/d_E) ⊗ ρ_F)` factors additively. -/ +theorem quantumRelativeEntropy_mapL_maximallyMixed_left_eq [Nontrivial E] + {ιE : Type*} [Fintype ιE] [Nonempty ιE] (bE : OrthonormalBasis ιE ℂ E) + {ρ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {ρF : F →L[ℂ] F} + (hρ : ρ.IsDensityOp) (hρs : IsStrictlyPositive ρ) + (hρF : LinearMap.partialTraceLeft bE ρ.toLinearMap = ρF.toLinearMap) : + ρ.quantumRelativeEntropy + (TensorProduct.mapL ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)) ρF) = + Real.log (Module.finrank ℂ E) + ρF.vonNeumannEntropy - ρ.vonNeumannEntropy := by + have hMd0 : ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)).IsDensityOp := + isDensityOp_finrank_inv_smul_one + have hMs0 : IsStrictlyPositive ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)) := + isStrictlyPositive_finrank_inv_smul_one + set M : E →L[ℂ] E := (Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E) with hMdef + have hMsa : IsSelfAdjoint M := hMd0.isPositive.isSelfAdjoint + have hρFd : ρF.IsDensityOp := hρ.of_partialTraceLeft_eq bE hρF + have hρFs : IsStrictlyPositive ρF := hρs.of_partialTraceLeft_eq bE hρF + have hEpos := fun i => hMs0.eigenvalues_pos hMsa.isSymmetric rfl i + have hFpos := fun j => hρFs.eigenvalues_pos hρFd.isPositive.isSelfAdjoint.isSymmetric rfl j + -- The operator logarithm factors additively over the tensor product. + have hlog : cfc Real.log (TensorProduct.mapL M ρF) = + TensorProduct.mapL (cfc Real.log M) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log ρF) := + IsSelfAdjoint.cfc_log_tensorMap hMsa hρFd.isPositive.isSelfAdjoint rfl rfl hEpos hFpos + -- The `E`-factor trace term collapses to `-log d_E` (as `tr ρ = 1`), using + -- `log(I/d) = -log d • 1` (`cfc_log_finrank_inv_smul_one`). + have ht1 : LinearMap.trace ℂ (E ⊗[ℂ] F) + ((TensorProduct.mapL (cfc Real.log M) (1 : F →L[ℂ] F)).toLinearMap ∘ₗ ρ.toLinearMap) + = ((- Real.log (Module.finrank ℂ E) : ℝ) : ℂ) := by + rw [hMdef, cfc_log_finrank_inv_smul_one, TensorProduct.mapL_smul_left, TensorProduct.mapL_one, + ContinuousLinearMap.toLinearMap_smul, LinearMap.smul_comp, map_smul, + ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, LinearMap.id_comp, hρ.2] + simp + -- The `F`-factor trace term is `-S(ρ_F)` via partial-trace duality. + have ht2 : LinearMap.trace ℂ (E ⊗[ℂ] F) + ((TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log ρF)).toLinearMap ∘ₗ ρ.toLinearMap) = + LinearMap.trace ℂ F ((cfc Real.log ρF).toLinearMap ∘ₗ ρF.toLinearMap) := by + rw [TensorProduct.toLinearMap_mapL, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, + LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft bE, hρF] + have hre : RCLike.re ((↑(- Real.log (Module.finrank ℂ E)) : ℂ)) + = - Real.log (Module.finrank ℂ E) := RCLike.ofReal_re _ + rw [hρ.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub, hlog, + ContinuousLinearMap.toLinearMap_add, LinearMap.add_comp, map_add, ht1, ht2, map_add, + hρFd.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy, hre] + ring + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumDataCompression.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumDataCompression.lean new file mode 100644 index 0000000000..6057ef76cc --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumDataCompression.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumComposition +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProductMap + +/-! # Quantum data compression: schemes, entanglement fidelity, and reliability + +This file sets up the operational framework for Schumacher's quantum noiseless channel coding +theorem (Nielsen–Chuang, *Quantum Computation and Quantum Information*, §12.2.2): the notion of a +**rate-`R` quantum compression scheme** for an i.i.d. quantum source `{H, ρ}`, the **entanglement +fidelity** through such a scheme, and the resulting **reliability** predicate. It is the quantum +analogue of the classical compression model in `ToMathlib/InformationTheory/NoiselessCoding.lean` +(N&C Theorem 12.4), and the target it works towards is +`ReliablyCompressible ρ R ↔ S(ρ) < R` (Theorem 12.6). + +## The model + +Following N&C §12.2.2, a compression scheme at block length `n` is a pair of quantum operations: +a **compression** `Cₙ` taking states on `H^⊗n` into a `2^{nR}`-dimensional *compressed space*, and +a **decompression** `Dₙ` back to `H^⊗n`. N&C's own analysis of both directions (the direct part's +projection–reset encoder, Eq. (12.50), and the converse, Eqs. (12.54)–(12.55)) realises `Cₙ` as a +quantum operation *on `H^⊗n`* whose operation elements `Cⱼ` all factor through a projector `S(n)` +onto a subspace of dimension `≤ 2^{nR}` (`Cⱼ = S(n) Cⱼ`). We take that as the definition, so a +scheme is `QuantumCompressionScheme K numBits` for a Hilbert space `K` (standing for `H^⊗n`) and a +qubit budget `numBits` (standing for `⌊nR⌋`): + +* Kraus families `encode : Fin encCard → K →L[ℂ] K` and `decode : Fin decCard → K →L[ℂ] K`, each + trace-preserving (`∑ Eᵢ† Eᵢ = 1`); +* a projector `compressedProjection` (`= S(n)`), an orthogonal (`IsStarProjection`) projection whose + range has dimension `≤ 2^numBits` and through which every `encode` element factors. + +The combined operation `Dₙ ∘ Cₙ` has operation elements `Dₖ Cⱼ` +(`QuantumCompressionScheme.composite`), and N&C's reliability criterion is that the entanglement +fidelity `F(ρ^⊗n, Dₙ ∘ Cₙ)` +(`QuantumCompressionScheme.fidelity`) tends to `1` as `n → ∞` (`ReliablyCompressible`), where +`ρ^⊗n = PiTensorProduct.mapCLM (fun _ ↦ ρ)`. + +## Main definitions and results + +* `ContinuousLinearMap.QuantumCompressionScheme` — a rate-`numBits` compression scheme on `K`. +* `ContinuousLinearMap.QuantumCompressionScheme.composite` — the operation elements `Dₖ Cⱼ` of + `Dₙ ∘ Cₙ`. +* `ContinuousLinearMap.QuantumCompressionScheme.fidelity` — `F(ρ, Dₙ ∘ Cₙ)`, the entanglement + fidelity of the source `ρ` through the scheme. +* `ContinuousLinearMap.QuantumCompressionScheme.fidelity_eq` — **N&C Eq. (12.54)**: + `F(ρ, Dₙ ∘ Cₙ) = ∑ₖ ∑ⱼ |tr(Dₖ Cⱼ ρ)|²`. +* `ContinuousLinearMap.QuantumCompressionScheme.composite_isTracePreserving` — `Dₙ ∘ Cₙ` is a + trace-preserving operation (`∑ⱼₖ (Dₖ Cⱼ)† (Dₖ Cⱼ) = 1`), used in the converse (N&C Eq. (12.58)). +* `ContinuousLinearMap.ReliablyCompressible` — a source `ρ` is reliably compressible at rate `R`: + a family of rate-`R` schemes exists whose entanglement fidelity for `ρ^⊗n` tends to `1`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.50)–(12.58)). +-/ + +open scoped InnerProductSpace TensorProduct + +@[expose] public section + +namespace ContinuousLinearMap + +/-- A **rate-`numBits` quantum compression scheme** on a Hilbert space `K` (Nielsen & Chuang, +§12.2.2), standing for one block length `n` with `K = H^⊗n` and `numBits = ⌊nR⌋`. It bundles a +compression operation `Cₙ` and a decompression operation `Dₙ`, given by their Kraus families, with +the requirement that `Cₙ` compresses into a subspace of dimension at most `2^numBits`. + +Both operations are quantum operations *on `K`* (endomorphisms), and the compressed space is the +range of an orthogonal projector `compressedProjection = S(n)` of dimension `≤ 2^numBits` through +which every compression element factors — exactly N&C's own description of the compression operation +in the converse (Eq. (12.55), `Cⱼ = S(n) Cⱼ`) and satisfied by the projection–reset encoder of the +direct part (Eq. (12.50)). -/ +structure QuantumCompressionScheme (K : Type*) [NormedAddCommGroup K] [InnerProductSpace ℂ K] + [FiniteDimensional ℂ K] [CompleteSpace K] (numBits : ℕ) where + /-- The number of Kraus operators of the compression operation `Cₙ`. -/ + encCard : ℕ + /-- The number of Kraus operators of the decompression operation `Dₙ`. -/ + decCard : ℕ + /-- The Kraus operators (operation elements) `Cⱼ` of the compression operation `Cₙ`. -/ + encode : Fin encCard → K →L[ℂ] K + /-- The Kraus operators (operation elements) `Dₖ` of the decompression operation `Dₙ`. -/ + decode : Fin decCard → K →L[ℂ] K + /-- `Cₙ` is trace-preserving: `∑ⱼ Cⱼ† Cⱼ = 1`. -/ + encode_isTracePreserving : ∑ j, adjoint (encode j) * encode j = 1 + /-- `Dₙ` is trace-preserving: `∑ₖ Dₖ† Dₖ = 1`. -/ + decode_isTracePreserving : ∑ k, adjoint (decode k) * decode k = 1 + /-- The projector `S(n)` onto the compressed subspace (the `2^numBits`-dimensional space). -/ + compressedProjection : K →L[ℂ] K + /-- `S(n)` is an orthogonal (self-adjoint idempotent) projection. -/ + isStarProjection_compressedProjection : IsStarProjection compressedProjection + /-- Every compression element maps into the compressed subspace: `Cⱼ = S(n) Cⱼ`. -/ + compressedProjection_mul_encode : ∀ j, compressedProjection * encode j = encode j + /-- Rate bound: the compressed subspace has dimension at most `2^numBits`. -/ + finrank_range_compressedProjection_le : + Module.finrank ℂ (LinearMap.range (compressedProjection : K →ₗ[ℂ] K)) ≤ 2 ^ numBits + +namespace QuantumCompressionScheme + +variable {K : Type*} [NormedAddCommGroup K] [InnerProductSpace ℂ K] [FiniteDimensional ℂ K] + [CompleteSpace K] {numBits : ℕ} + +/-- The operation elements of the combined compression–decompression operation `Dₙ ∘ Cₙ`: the +products `Dₖ Cⱼ`, indexed by pairs `(k, j)`. -/ +def composite (sch : QuantumCompressionScheme K numBits) : + Fin sch.decCard × Fin sch.encCard → K →L[ℂ] K := + fun p => sch.decode p.1 * sch.encode p.2 + +/-- The operation element of `Dₙ ∘ Cₙ` at a pair `(k, j)` is `Dₖ Cⱼ`. -/ +@[simp] +theorem composite_apply (sch : QuantumCompressionScheme K numBits) + (p : Fin sch.decCard × Fin sch.encCard) : sch.composite p = sch.decode p.1 * sch.encode p.2 := + rfl + +/-- The **entanglement fidelity** `F(ρ, Dₙ ∘ Cₙ)` of a source `ρ` through the scheme, i.e. the +entanglement fidelity of `ρ` under the combined operation `Dₙ ∘ Cₙ` (Nielsen & Chuang, §12.2.2). +Reliability of a family of schemes is this quantity tending to `1` (`ReliablyCompressible`). -/ +noncomputable def fidelity (sch : QuantumCompressionScheme K numBits) (ρ : K →L[ℂ] K) : ℝ := + ContinuousLinearMap.entanglementFidelity ρ sch.composite + +/-- **Nielsen & Chuang, Eq. (12.54).** The entanglement fidelity of the source `ρ` through the +scheme is the double sum `∑ₖ ∑ⱼ |tr(Dₖ Cⱼ ρ)|²` over the decompression and compression operation +elements. -/ +theorem fidelity_eq (sch : QuantumCompressionScheme K numBits) (ρ : K →L[ℂ] K) : + sch.fidelity ρ + = ∑ k, ∑ j, ‖LinearMap.trace ℂ K + ((sch.decode k * sch.encode j * ρ : K →L[ℂ] K) : K →ₗ[ℂ] K)‖ ^ 2 := by + rw [fidelity, ContinuousLinearMap.entanglementFidelity, Fintype.sum_prod_type] + simp only [composite_apply, ContinuousLinearMap.toLinearMap_mul, LinearMap.trace_mul_comm] + +/-- The entanglement fidelity through a scheme is nonnegative (it is a sum of squared norms). -/ +theorem fidelity_nonneg (sch : QuantumCompressionScheme K numBits) (ρ : K →L[ℂ] K) : + 0 ≤ sch.fidelity ρ := + ContinuousLinearMap.entanglementFidelity_nonneg ρ sch.composite + +/-- The combined compression–decompression operation `Dₙ ∘ Cₙ` is **trace-preserving**: its +operation elements `Dₖ Cⱼ` satisfy the completeness relation `∑ⱼₖ (Dₖ Cⱼ)† (Dₖ Cⱼ) = 1`. This is +the fact used in the last step of N&C's converse (Eq. (12.58)); it is the composition case of the +operator-sum trace condition, `ContinuousLinearMap.sum_adjoint_comp_comp_eq_one`, applied to the +trace-preserving encode/decode families. -/ +theorem composite_isTracePreserving (sch : QuantumCompressionScheme K numBits) : + ∑ p, adjoint (sch.composite p) * sch.composite p = 1 := by + simpa only [composite_apply, ContinuousLinearMap.mul_def] using + ContinuousLinearMap.sum_adjoint_comp_comp_eq_one sch.encode sch.decode + sch.encode_isTracePreserving sch.decode_isTracePreserving + +end QuantumCompressionScheme + +/- Only `[FiniteDimensional ℂ H]` is required below (no `[CompleteSpace H]`, unlike +`QuantumCompressionScheme`/`EntanglementFidelity`): the schemes live on the block spaces `H^⊗n`, not +on `H` itself, and `CompleteSpace (⨂[ℂ] (_ : Fin n), H)` is *derived* from `[FiniteDimensional ℂ H]` +(a finite tensor power of a finite-dimensional space is finite-dimensional, hence complete). For an +arbitrary space `CompleteSpace` is **not** an instance consequence of `FiniteDimensional`, which is +why `QuantumCompressionScheme` (over a general `K`) must carry it explicitly. -/ +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] + +/-- A source `ρ` (a density operator on `H`) is **reliably compressible at rate `R`** if there is a +family of rate-`R` quantum compression schemes — one for each block length `n`, on the block space +`H^⊗n` with qubit budget `⌊nR⌋` — whose entanglement fidelity for the source `ρ^⊗n` tends to `1` as +`n → ∞` (Nielsen & Chuang, §12.2.2). Here `ρ^⊗n = PiTensorProduct.mapCLM (fun _ ↦ ρ)` is the +`n`-fold tensor power of `ρ`. Schumacher's noiseless channel coding theorem (Theorem 12.6) gives +achievability above the entropy rate and a converse below it. -/ +def ReliablyCompressible (ρ : H →L[ℂ] H) (R : ℝ) : Prop := + ∃ sch : (n : ℕ) → QuantumCompressionScheme (⨂[ℂ] (_ : Fin n), H) ⌊(n : ℝ) * R⌋₊, + Filter.Tendsto + (fun n => (sch n).fidelity (PiTensorProduct.mapCLM fun _ : Fin n => ρ)) + Filter.atTop (nhds 1) + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumErrorCorrection.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumErrorCorrection.lean new file mode 100644 index 0000000000..9f95f509e6 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumErrorCorrection.lean @@ -0,0 +1,855 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumFreedom +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSumComposition +public import Mathlib.Analysis.Matrix.Spectrum +public import Mathlib.RingTheory.Idempotents + +/-! # The Knill–Laflamme quantum error-correction conditions + +This file develops the **Knill–Laflamme quantum error-correction conditions** (Nielsen & Chuang, +*Quantum Computation and Quantum Information*, **Theorem 10.1**) as general operator theory on a +complex inner product space `H`, alongside the operator-sum (Kraus) representation +(`ContinuousLinearMap.krausSumₗ`). + +For a code with projector `P : H →L[ℂ] H` and a noise process with operation elements +`E : ι → H →L[ℂ] H`, the conditions read `P Eᵢ† Eⱼ P = αᵢⱼ P` for a matrix `α`. Following the proof +of Theorem 10.1, the first step is to *diagonalise* the conditions: since `α` is Hermitian it can +be diagonalised by a unitary `u`, and the correspondingly recombined operation elements +`Fₖ = ∑ᵢ uᵢₖ Eᵢ` are still a set of operation elements for the same operation (they induce the same +`krausSumₗ` map — N&C's use of Theorem 8.2) and satisfy the *simplified* conditions +`P Fₖ† Fₗ P = dₖₗ P` with `d` real and diagonal (N&C eqs. (10.17)–(10.18)). + +## Main definitions + +* `ContinuousLinearMap.SatisfiesKLConditions P E α` — the Knill–Laflamme conditions + `P Eᵢ† Eⱼ P = αᵢⱼ P` for the code projector `P`, operation elements `E`, and coefficient matrix + `α` (N&C eq. (10.16)). + +## Main results + +* `ContinuousLinearMap.SatisfiesKLConditions.recombine` — under a linear recombination + `Fₖ = ∑ᵢ uᵢₖ Eᵢ` of the operation elements, the conditions are transported to the conjugated + matrix `uᴴ α u` (N&C eq. (10.17)). +* `ContinuousLinearMap.krausSumₗ_recombine_col` — such a recombination by a **unitary** `u` leaves + the operator-sum map unchanged, `krausSumₗ F = krausSumₗ E` (the `⇐` direction of N&C Theorem + 8.2, in the column-recombination form used by Theorem 10.1). +* `ContinuousLinearMap.SatisfiesKLConditions.exists_recombine_diagonal` — **the reduction to the + simplified conditions** (N&C eq. (10.18)): if `α` is Hermitian then there is a recombination `F` + of `E` with the same operator-sum map that satisfies the diagonalised conditions + `SatisfiesKLConditions P F (diagonal d)` with `d` the (real) eigenvalues of `α`. +* `ContinuousLinearMap.satisfiesKLConditions_of_corrects` — **necessity** of the conditions (N&C + eqs. (10.27)–(10.30)): a trace-preserving recovery `R` correcting `E` on the code forces + `P Eᵢ† Eⱼ P = αᵢⱼ P` for a Hermitian `α`. +* `ContinuousLinearMap.qecSyndromeProjector` and `qecSyndromeProjector_isSelfAdjoint`, + `qecSyndromeProjector_isStarProjection`, `qecSyndromeProjector_comp_eq_zero` — **the syndrome + projectors** of the sufficiency construction, `Pₖ = dₖₖ⁻¹ Fₖ P Fₖ†`, shown to be + `IsStarProjection`s (self-adjoint idempotents) onto mutually orthogonal subspaces (N&C + eq. (10.19)). +-/ + +@[expose] public section + +open scoped InnerProductSpace Matrix +open Finset + +noncomputable section + +/-- **Pointwise-proportional linear maps are globally proportional.** If two `𝕜`-linear maps +`f g : V →ₗ[𝕜] W` over a field `𝕜` satisfy `f v = c • g v` for a *per-vector* scalar `c` at every +`v`, and `g ≠ 0`, then a *single* scalar `c` works for all `v`: `∃ c, ∀ v, f v = c • g v`. + +This is the linear-algebra content of Nielsen & Chuang's remark that in the necessity half of +Theorem 10.1 "the proportionality factor must be a constant `c`, not depending on `ρ`, if both +right and left hand sides are to be linear": `f` is the (linear) map `ρ ↦ (R ∘ E)(P ρ P)` and `g` +is `ρ ↦ P ρ P`. -/ +theorem _root_.LinearMap.exists_forall_eq_smul_of_forall_exists_eq_smul + {𝕜 V W : Type*} [Field 𝕜] [AddCommGroup V] [Module 𝕜 V] [AddCommGroup W] [Module 𝕜 W] + {f g : V →ₗ[𝕜] W} (hg : g ≠ 0) (h : ∀ v, ∃ c : 𝕜, f v = c • g v) : + ∃ c : 𝕜, ∀ v, f v = c • g v := by + obtain ⟨v₀, hv₀⟩ := DFunLike.ne_iff.mp hg + simp only [LinearMap.zero_apply] at hv₀ + obtain ⟨c₀, hc₀⟩ := h v₀ + refine ⟨c₀, fun v => ?_⟩ + obtain ⟨c, hc⟩ := h v + by_cases hgv : g v = 0 + · rw [hc, hgv, smul_zero, smul_zero] + by_cases hdep : ∃ lam : 𝕜, g v = lam • g v₀ + · -- `g v` is a multiple `lam • g v₀`; then `w := v - lam • v₀` has `g w = 0`, so `f w = 0`, + -- forcing `f v = lam • f v₀ = c₀ • g v`. + obtain ⟨lam, hlam⟩ := hdep + obtain ⟨cw, hcw⟩ := h (v - lam • v₀) + have hgw : g (v - lam • v₀) = 0 := by rw [map_sub, map_smul, hlam, sub_self] + have hfw : f (v - lam • v₀) = 0 := by rw [hcw, hgw, smul_zero] + rw [map_sub, map_smul, sub_eq_zero] at hfw + rw [hfw, hc₀, hlam, smul_smul, smul_smul, mul_comm] + · -- `g v` and `g v₀` are independent; comparing `f (v + v₀)` two ways forces `c = c₀`. + obtain ⟨c2, hc2⟩ := h (v + v₀) + rw [map_add, map_add, hc, hc₀, smul_add] at hc2 + have key : (c - c2) • g v = (c2 - c₀) • g v₀ := by + rw [sub_smul, sub_smul]; linear_combination (norm := module) hc2 + have hcc2 : c = c2 := by + by_contra hne + exact hdep ⟨(c - c2)⁻¹ * (c2 - c₀), by + rw [mul_smul, ← key, smul_smul, inv_mul_cancel₀ (sub_ne_zero.mpr hne), one_smul]⟩ + rw [hcc2, sub_self, zero_smul] at key + have hc2c₀ : c2 - c₀ = 0 := by + rcases smul_eq_zero.mp key.symm with h1 | h1 + · exact h1 + · exact absurd h1 hv₀ + rw [hc, hcc2, sub_eq_zero.mp hc2c₀] + +namespace ContinuousLinearMap + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + {ι : Type*} [Fintype ι] + +/-- **The Knill–Laflamme quantum error-correction conditions** (Nielsen & Chuang, Theorem 10.1, +eq. (10.16)). For a code projector `P : H →L[ℂ] H` and a finite family of operation elements +`E : ι → H →L[ℂ] H`, the family satisfies the conditions with coefficient matrix `α` when +`P Eᵢ† Eⱼ P = αᵢⱼ P` for all `i, j`, where `Eᵢ† = adjoint (E i)`. N&C additionally require `α` to be +Hermitian; that hypothesis is supplied where it is used (e.g. `exists_recombine_diagonal`). -/ +def SatisfiesKLConditions (P : H →L[ℂ] H) (E : ι → H →L[ℂ] H) (α : Matrix ι ι ℂ) : Prop := + ∀ i j, P ∘L adjoint (E i) ∘L E j ∘L P = α i j • P + +variable {P : H →L[ℂ] H} {E F : ι → H →L[ℂ] H} {α : Matrix ι ι ℂ} {d : ι → ℝ} + +omit [Fintype ι] in +/-- **Unfolding lemma for the Knill–Laflamme conditions.** `SatisfiesKLConditions P E α` is by +definition the family of identities `P Eᵢ† Eⱼ P = αᵢⱼ P`; this `iff` exposes that content as the +API for using the predicate (rather than unfolding the `def`). -/ +theorem satisfiesKLConditions_iff : + SatisfiesKLConditions P E α ↔ ∀ i j, P ∘L adjoint (E i) ∘L E j ∘L P = α i j • P := Iff.rfl + +omit [Fintype ι] in +/-- **The Knill–Laflamme conditions from the codewords and their error images** — the +direct-verification route (Nielsen & Chuang, Exercises 10.7–10.10). Let `v : κ → H` be a family of +codewords and `P = ∑ₐ |vₐ⟩⟨vₐ|` the projector onto their span (`∑ a, rankOne ℂ (v a) (v a)`; for an +orthonormal `v` this is the genuine code projector). If the errors' matrix elements between +codewords depend only on the error indices and are diagonal in the codewords, +`⟪Eᵢ vₐ, Eⱼ v_b⟫ = αᵢⱼ · δ_{a,b}`, then `P` satisfies the Knill–Laflamme conditions +`P Eᵢ† Eⱼ P = αᵢⱼ P` with coefficient matrix `α`. This packages the standard "verify the conditions +on the codeword basis" computation: +`P Eᵢ† Eⱼ P = ∑_{a,b} ⟪Eᵢ vₐ, Eⱼ v_b⟫ |vₐ⟩⟨v_b| = ∑ₐ αᵢⱼ |vₐ⟩⟨vₐ| = αᵢⱼ P`. +No orthonormality of `v` is needed for the algebraic identity itself. -/ +theorem satisfiesKLConditions_of_inner_error_images {κ : Type*} [Fintype κ] [DecidableEq κ] + (v : κ → H) (E : ι → H →L[ℂ] H) (α : Matrix ι ι ℂ) + (h : ∀ (i j : ι) (a b : κ), + ⟪E i (v a), E j (v b)⟫_ℂ = α i j * (if a = b then (1 : ℂ) else 0)) : + SatisfiesKLConditions (∑ a, InnerProductSpace.rankOne ℂ (v a) (v a)) E α := by + rw [satisfiesKLConditions_iff] + intro i j + refine ContinuousLinearMap.ext fun z => ?_ + simp only [comp_apply, smul_apply, _root_.sum_apply, InnerProductSpace.rankOne_apply, map_sum, + map_smul, adjoint_inner_right, h, mul_ite, mul_one, mul_zero, ite_smul, zero_smul, + Finset.sum_ite_eq', Finset.mem_univ, ite_true] + rw [Finset.smul_sum] + exact Finset.sum_congr rfl fun x _ => (smul_comm _ _ _) + +/-- **Recombination of the operation elements transports the Knill–Laflamme conditions to the +conjugated matrix** (Nielsen & Chuang, Theorem 10.1, eq. (10.17)). If `E` satisfies the conditions +with matrix `α`, then the recombined family `Fₖ = ∑ᵢ uᵢₖ Eᵢ` (column `k` of `u`) satisfies them with +the conjugated matrix `uᴴ α u`. The recombination `u : Matrix ι κ ℂ` may also *change the index +type* (`κ ≠ ι`, e.g. producing more members than `E`): this is Nielsen & Chuang's discretization +principle at the level of the error-correction *conditions* — an error set whose members are linear +combinations of a correctable error set is itself correctable, whatever its size. No unitarity of +`u` is needed for this algebraic identity. -/ +theorem SatisfiesKLConditions.recombine {κ : Type*} + (hE : SatisfiesKLConditions P E α) (u : Matrix ι κ ℂ) : + SatisfiesKLConditions P (fun k => ∑ i, u i k • E i) (uᴴ * α * u) := by + have hE' := satisfiesKLConditions_iff.1 hE + intro k l + simp only [map_sum, map_smulₛₗ, finsetSum_comp, comp_finsetSum, smul_comp, comp_smul, + Finset.smul_sum, smul_smul, hE', ← Finset.sum_smul] + congr 1 + simp only [Matrix.mul_apply, Matrix.conjTranspose_apply, Finset.mul_sum, starRingEnd_apply, + mul_comm, mul_left_comm] + +/-- **Unitary recombination of the operation elements preserves the operator-sum map**, in the +column form `Fₖ = ∑ᵢ uᵢₖ Eᵢ` used by Nielsen & Chuang, Theorem 10.1 (the `⇐` direction of Theorem +8.2). If `u` is unitary then `krausSumₗ F = krausSumₗ E`. -/ +theorem krausSumₗ_recombine_col [DecidableEq ι] {u : Matrix ι ι ℂ} + (hu : u ∈ Matrix.unitaryGroup ι ℂ) {F : ι → H →L[ℂ] H} (hF : ∀ k, F k = ∑ i, u i k • E i) : + krausSumₗ F = krausSumₗ E := by + have hut : uᵀ ∈ Matrix.unitaryGroup ι ℂ := Matrix.transpose_mem_unitaryGroup_iff.2 hu + refine krausSumₗ_eq_of_mem_unitaryGroup hut (fun k => ?_) + simp only [hF, Matrix.transpose_apply] + +/-- **Reduction of the Knill–Laflamme conditions to the diagonalised (simplified) conditions** +(Nielsen & Chuang, Theorem 10.1, eqs. (10.17)–(10.18)). If the operation elements `E` satisfy the +conditions with a **Hermitian** matrix `α`, there is a recombination `F` of `E` that + +* induces the same operator-sum map, `krausSumₗ F = krausSumₗ E` (so `F` is another set of operation + elements for the same operation), and +* satisfies the *diagonalised* conditions `SatisfiesKLConditions P F (diagonal d)` with + `d = RCLike.ofReal ∘ hα.eigenvalues` the (real) eigenvalues of `α`. + +The recombination is `Fₖ = ∑ᵢ uᵢₖ Eᵢ` with `u = hα.eigenvectorUnitary` the unitary of eigenvectors; +`uᴴ α u = diagonal d` is the matrix spectral theorem +(`Matrix.IsHermitian.conjStarAlgAut_star_eigenvectorUnitary`). -/ +theorem SatisfiesKLConditions.exists_recombine_diagonal [DecidableEq ι] + (hE : SatisfiesKLConditions P E α) (hα : α.IsHermitian) : + ∃ F : ι → H →L[ℂ] H, krausSumₗ F = krausSumₗ E ∧ + SatisfiesKLConditions P F (Matrix.diagonal (RCLike.ofReal ∘ hα.eigenvalues)) := by + set U : Matrix ι ι ℂ := ↑hα.eigenvectorUnitary with hU + have hUmem : U ∈ Matrix.unitaryGroup ι ℂ := by rw [hU]; exact hα.eigenvectorUnitary.2 + have hdiag : Uᴴ * α * U = Matrix.diagonal (RCLike.ofReal ∘ hα.eigenvalues) := by + simpa only [Unitary.conjStarAlgAut_apply, Unitary.coe_star, Matrix.star_eq_conjTranspose, + Matrix.conjTranspose_conjTranspose, ← hU] using hα.conjStarAlgAut_star_eigenvectorUnitary + refine ⟨fun k => ∑ i, U i k • E i, krausSumₗ_recombine_col hUmem (fun _ => rfl), ?_⟩ + rw [← hdiag] + exact hE.recombine U + +/-- **A recovery operation `R` corrects the errors `E` on the code with projector `P`** (Nielsen & +Chuang, Theorem 10.1, eq. (10.15)). The combined noise-then-recovery operation +`ρ ↦ (R ∘ E)(ρ) = krausSumₗ R (krausSumₗ E ρ)` returns every operator `ρ` supported on the code +(`P ρ P = ρ`) to a scalar multiple of itself. The scalar is allowed to depend on `ρ` (`∝`, N&C's +eq. (10.15)); that it is in fact a single nonnegative real constant is *derived*, not assumed +(`Corrects.exists_nonneg_forall_eq_smul`). -/ +def Corrects (P : H →L[ℂ] H) (E : ι → H →L[ℂ] H) {κ : Type*} [Fintype κ] + (R : κ → H →L[ℂ] H) : Prop := + ∀ ρ : H →L[ℂ] H, P ∘L ρ ∘L P = ρ → ∃ c : ℂ, krausSumₗ R (krausSumₗ E ρ) = c • ρ + +omit [CompleteSpace H] in +/-- **A real scalar multiple of a nonzero orthogonal projection that is positive has a nonnegative +scalar.** If `P ∘L P = P`, `P ≠ 0`, and `(c : ℂ) • P` is a positive operator for a real `c`, then +`0 ≤ c`. Evaluating the positivity `0 ≤ re ⟪(c • P) x, x⟫` at a code vector `x = P y ≠ 0` gives +`0 ≤ c ‖P y‖²`, and `‖P y‖² > 0`. This packages the nonnegativity argument shared by the two places +in Theorem 10.1 where a positive `c • P` fixes the sign of `c`: the necessity constant +(`Corrects.exists_nonneg_forall_eq_smul`) and the diagonalised Knill–Laflamme coefficients +(`qecSyndromeProjector_diagonal_nonneg`). -/ +theorem nonneg_of_smul_isPositive {P : H →L[ℂ] H} (hPidem : P ∘L P = P) (hP0 : P ≠ 0) {c : ℝ} + (hpos : ((c : ℂ) • P).IsPositive) : 0 ≤ c := by + obtain ⟨y, hy⟩ := DFunLike.ne_iff.mp hP0 + rw [_root_.zero_apply] at hy + have hPv : P (P y) = P y := by rw [← ContinuousLinearMap.comp_apply, hPidem] + have hnn := hpos.re_inner_nonneg_left (P y) + rw [_root_.smul_apply, hPv, inner_smul_left, Complex.conj_ofReal] at hnn + set w := inner ℂ (P y) (P y) with hw + have hii_re : w.re = ‖P y‖ ^ 2 := by rw [hw]; simpa using inner_self_eq_norm_sq (𝕜 := ℂ) (P y) + have hii_im : w.im = 0 := Complex.conj_eq_iff_im.mp (inner_conj_symm (P y) (P y)) + rw [show RCLike.re ((c : ℂ) * w) = (c : ℂ).re * w.re - (c : ℂ).im * w.im from Complex.mul_re _ w, + Complex.ofReal_re, Complex.ofReal_im, hii_re, hii_im, zero_mul, sub_zero] at hnn + exact (mul_nonneg_iff_of_pos_right (pow_pos (norm_pos_iff.mpr hy) 2)).mp hnn + +/-- **The proportionality constant in the correction condition is a single nonnegative real** +(the first step of the necessity half of Nielsen & Chuang, Theorem 10.1; N&C's remark following +eq. (10.27) that "the proportionality factor must be a constant `c`, not depending on `ρ`, if both +right and left hand sides are to be linear", together with eq. (10.28)). If `P` is a nonzero +orthogonal projection and `R` corrects `E` on the code, then there is one nonnegative real `c` with +`(R ∘ E)(P σ P) = c • (P σ P)` for *every* operator `σ` — the operator-form of N&C eq. (10.28). + +The uniformity is `LinearMap.exists_forall_eq_smul_of_forall_exists_eq_smul` applied to the linear +maps `σ ↦ (R ∘ E)(P σ P)` and `σ ↦ P σ P`; the nonnegativity is because `(R ∘ E)(P) = c • P` is a +positive operator (`krausSumₗ` preserves positivity) and `P` is a nonzero projection. -/ +theorem Corrects.exists_nonneg_forall_eq_smul {P : H →L[ℂ] H} {E : ι → H →L[ℂ] H} + {κ : Type*} [Fintype κ] {R : κ → H →L[ℂ] H} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) (hcorr : Corrects P E R) : + ∃ c : ℝ, 0 ≤ c ∧ ∀ σ : H →L[ℂ] H, + krausSumₗ R (krausSumₗ E (P ∘L σ ∘L P)) = (c : ℂ) • (P ∘L σ ∘L P) := by + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hP + have hPv : ∀ y, P (P y) = P y := fun y => by rw [← comp_apply, hPidem] + -- `g σ = P σ P`, `f σ = (R ∘ E)(P σ P)`, both `ℂ`-linear in `σ`. + set g : (H →L[ℂ] H) →ₗ[ℂ] (H →L[ℂ] H) := krausSumₗ (fun _ : Fin 1 => P) with hg_def + have hg_apply : ∀ ρ, g ρ = P ∘L ρ ∘L P := fun ρ => by + rw [hg_def, krausSumₗ_apply, Fintype.sum_unique, hPadj] + set f : (H →L[ℂ] H) →ₗ[ℂ] (H →L[ℂ] H) := + (krausSumₗ R).comp ((krausSumₗ E).comp g) with hf_def + have hf_apply : ∀ ρ, f ρ = krausSumₗ R (krausSumₗ E (P ∘L ρ ∘L P)) := fun ρ => by + rw [hf_def, LinearMap.comp_apply, LinearMap.comp_apply, hg_apply] + have hfix : ∀ ρ : H →L[ℂ] H, P ∘L (P ∘L ρ ∘L P) ∘L P = P ∘L ρ ∘L P := fun ρ => by + ext x; simp only [comp_apply, hPv] + -- pointwise proportionality from `Corrects`, uniformised. + have hpt : ∀ ρ, ∃ c : ℂ, f ρ = c • g ρ := fun ρ => by + obtain ⟨c, hc⟩ := hcorr (P ∘L ρ ∘L P) (hfix ρ) + exact ⟨c, by rw [hf_apply, hg_apply, hc]⟩ + have hg_ne : g ≠ 0 := by + intro h0 + apply hP0 + have hgP := hg_apply P + rw [h0, LinearMap.zero_apply, hPidem, hPidem] at hgP + exact hgP.symm + obtain ⟨c, hc⟩ := LinearMap.exists_forall_eq_smul_of_forall_exists_eq_smul hg_ne hpt + -- `(R ∘ E)(P) = c • P` is positive, forcing `c` to be a nonnegative real. + have hPpos : P.IsPositive := by + have := isPositive_adjoint_comp_self P; rwa [hPadj, hPidem] at this + have hcP : krausSumₗ R (krausSumₗ E P) = c • P := by + have h1 := hc P + rw [hf_apply, hg_apply] at h1 + rwa [show P ∘L P ∘L P = P by rw [hPidem, hPidem]] at h1 + have hcPpos : ((c : ℂ) • P).IsPositive := + hcP ▸ krausSumₗ_isPositive R (krausSumₗ_isPositive E hPpos) + -- `c` is real (from self-adjointness of `c • P`). + have hreal : star c = c := by + have hsa : star ((c : ℂ) • P) = (c : ℂ) • P := hcPpos.isSelfAdjoint + rw [star_smul, hP] at hsa + have h2 : (star c - c) • P = 0 := by rw [sub_smul, hsa, sub_self] + rcases smul_eq_zero.mp h2 with h3 | h3 + · exact sub_eq_zero.mp h3 + · exact absurd h3 hP0 + obtain ⟨cr, hcr⟩ : ∃ cr : ℝ, (cr : ℂ) = c := ⟨c.re, Complex.conj_eq_iff_re.mp hreal⟩ + -- nonnegativity: `cr • P = c • P` is positive, so `0 ≤ cr` (`nonneg_of_smul_isPositive`). + refine ⟨cr, nonneg_of_smul_isPositive hPidem hP0 (by rw [hcr]; exact hcPpos), fun σ => ?_⟩ + rw [← hf_apply σ, hc σ, hg_apply σ, hcr] + +/-- **Single-operation-element rigidity of the operator-sum representation** (the special case of +Nielsen & Chuang, Theorem 8.2, used in the necessity half of Theorem 10.1). If a finite family +`A : J → H →L[ℂ] H` induces the *same* operator-sum map as a **single** operation element `M`, i.e. +`∑ⱼ Aⱼ σ Aⱼ† = M σ M†` for every `σ`, then each `Aⱼ` is a scalar multiple of `M`: there are scalars +`c : J → ℂ` with `Aⱼ = cⱼ • M`. + +This is `krausSumₗ_eq_iff_exists_mem_unitaryGroup` (Theorem 8.2) applied to `A` and the family that +is `M` at one padding index `j₀` and `0` elsewhere; the `j₀`-th column of the resulting unitary +matrix supplies the scalars. (N&C's "the quantum operation with operation elements `{RⱼEᵢ}` is +identical to the quantum operation with a single operation element `√c P`.") -/ +theorem exists_forall_eq_smul_of_krausSumₗ_apply_eq [FiniteDimensional ℂ H] {J : Type*} [Fintype J] + [Nonempty J] {A : J → H →L[ℂ] H} {M : H →L[ℂ] H} + (h : ∀ σ : H →L[ℂ] H, krausSumₗ A σ = M ∘L σ ∘L adjoint M) : + ∃ c : J → ℂ, ∀ j, A j = c j • M := by + classical + obtain ⟨j₀⟩ := (inferInstance : Nonempty J) + set B : J → H →L[ℂ] H := Function.update (fun _ => 0) j₀ M with hB + have hBj₀ : B j₀ = M := by rw [hB, Function.update_self] + have hBne : ∀ q, q ≠ j₀ → B q = 0 := fun q hq => by rw [hB, Function.update_of_ne hq] + have hAB : krausSumₗ A = krausSumₗ B := by + ext σ + rw [h σ, krausSumₗ_apply, + Fintype.sum_eq_single j₀ (fun q hq => by rw [hBne q hq]; simp), hBj₀] + rw [krausSumₗ_eq_iff_exists_mem_unitaryGroup] at hAB + obtain ⟨u, -, hu⟩ := hAB + refine ⟨fun j => u j j₀, fun j => ?_⟩ + rw [hu j, Fintype.sum_eq_single j₀ (fun q hq => by rw [hBne q hq, smul_zero]), hBj₀] + +/-- **Necessity of the Knill–Laflamme quantum error-correction conditions** (Nielsen & Chuang, +Theorem 10.1, the `⟹` direction). If `P` is a nonzero orthogonal projection onto the code, `R` is a +**trace-preserving** recovery operation (`∑ₖ Rₖ† Rₖ = 1`) that corrects the errors `E` on the code +(`Corrects P E R`), then the errors satisfy the Knill–Laflamme conditions `P Eᵢ† Eⱼ P = αᵢⱼ P` for a +**Hermitian** matrix `α`. + +Following N&C's proof: +* `Corrects.exists_nonneg_forall_eq_smul` (necessity part 1) gives a single nonnegative real `c` + with `(R ∘ E)(P σ P) = c • (P σ P)` for all `σ` (N&C eqs. (10.27)–(10.28)); +* rewriting the combined map as the operator-sum map of the family `Fₖᵢ = Rₖ Eᵢ P` (via + `krausSumₗ_comp`), this says `Fₖᵢ` has the same operator-sum map as the single element `√c P`, so + `exists_forall_eq_smul_of_krausSumₗ_apply_eq` (Theorem 8.2) yields scalars with + `Rₖ Eᵢ P = cₖᵢ P` (N&C eq. (10.29)); +* taking adjoints gives `P Eᵢ† Rₖ† = c_barₖᵢ P`, so `P Eᵢ† Rₖ† Rₖ Eⱼ P = c_barₖᵢ cₖⱼ P`; summing + over `k` + and using `∑ₖ Rₖ† Rₖ = 1` gives `P Eᵢ† Eⱼ P = αᵢⱼ P` with `αᵢⱼ = ∑ₖ c_barₖᵢ cₖⱼ` (N&C eq. + (10.30)), + a Gram matrix `α = cᴴ c`, hence Hermitian. + +The `FiniteDimensional ℂ H` hypothesis (absent from `SatisfiesKLConditions`/`Corrects`) is genuinely +needed for the operator-sum-freedom step (Theorem 8.2); N&C works throughout in finite dimension. -/ +theorem satisfiesKLConditions_of_corrects [FiniteDimensional ℂ H] {P : H →L[ℂ] H} + {E : ι → H →L[ℂ] H} {κ : Type*} [Fintype κ] {R : κ → H →L[ℂ] H} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (hR : ∑ k, adjoint (R k) ∘L R k = 1) (hcorr : Corrects P E R) : + ∃ α : Matrix ι ι ℂ, α.IsHermitian ∧ SatisfiesKLConditions P E α := by + classical + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hP + rcases isEmpty_or_nonempty ι with hι | hι + · -- No errors: the conditions hold vacuously. + exact ⟨0, Matrix.isHermitian_zero, fun i => isEmptyElim i⟩ + -- `H` is nontrivial (`P ≠ 0`), so `κ` is nonempty (`∑ₖ Rₖ† Rₖ = 1 ≠ 0`). + obtain ⟨y₀, hy₀⟩ := DFunLike.ne_iff.mp hP0 + rw [_root_.zero_apply] at hy₀ + have : Nontrivial H := nontrivial_of_ne (P y₀) 0 hy₀ + have : Nonempty κ := by + by_contra hcon + rw [not_nonempty_iff] at hcon + have := hcon + have hz : (1 : H →L[ℂ] H) = 0 := by rw [← hR, Finset.univ_eq_empty, Finset.sum_empty] + exact one_ne_zero hz + -- Necessity part 1: a single nonnegative real constant `c` (N&C eqs. (10.27)–(10.28)). + obtain ⟨c, hc0, hc⟩ := hcorr.exists_nonneg_forall_eq_smul hP hPidem hP0 + set M : H →L[ℂ] H := (Real.sqrt c : ℂ) • P with hM + have hMadj : adjoint M = M := by + rw [hM, ← star_eq_adjoint, star_smul, show star P = P from hP] + congr 1 + rw [← starRingEnd_apply, Complex.conj_ofReal] + -- `∑ᵢ (Eᵢ P) σ (Eᵢ P)† = ∑ᵢ Eᵢ (P σ P) Eᵢ†`. + have hE'σ : ∀ σ : H →L[ℂ] H, + krausSumₗ (fun i => E i ∘L P) σ = krausSumₗ E (P ∘L σ ∘L P) := by + intro σ + rw [krausSumₗ_apply, krausSumₗ_apply] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [adjoint_comp, hPadj] + ext x + simp only [ContinuousLinearMap.comp_apply] + -- `M σ M† = c • (P σ P)`. + have hMσ : ∀ σ : H →L[ℂ] H, M ∘L σ ∘L adjoint M = (c : ℂ) • (P ∘L σ ∘L P) := by + intro σ + rw [hMadj, hM] + simp only [ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, smul_smul] + rw [← Complex.ofReal_mul, Real.mul_self_sqrt hc0] + -- The combined family `Fₖᵢ = Rₖ Eᵢ P` has the same operator-sum map as the single element `M`. + have hGeq : krausSumₗ (fun p : κ × ι => R p.1 ∘L (E p.2 ∘L P)) + = krausSumₗ R ∘ₗ krausSumₗ (fun i => E i ∘L P) := (krausSumₗ_comp (fun i => E i ∘L P) R).symm + have hGM : ∀ σ : H →L[ℂ] H, + krausSumₗ (fun p : κ × ι => R p.1 ∘L (E p.2 ∘L P)) σ = M ∘L σ ∘L adjoint M := by + intro σ + rw [hGeq, LinearMap.comp_apply, hE'σ σ, hc σ, hMσ σ] + -- Theorem 8.2 (single-element rigidity): the scalars `cₖᵢ` of N&C eq. (10.29). + obtain ⟨cc, hcc⟩ := exists_forall_eq_smul_of_krausSumₗ_apply_eq hGM + set d : κ → ι → ℂ := fun k i => cc (k, i) * (Real.sqrt c : ℂ) with hd_def + have hd : ∀ k i, R k ∘L E i ∘L P = d k i • P := by + intro k i + rw [hd_def] + have hki : R k ∘L (E i ∘L P) = cc (k, i) • M := hcc (k, i) + rw [hki, hM, smul_smul] + -- Adjoint form: `P Eᵢ† Rₖ† = c_barₖᵢ P` (N&C eq. (10.29) adjointed). + have hdadj : ∀ k i, P ∘L adjoint (E i) ∘L adjoint (R k) = star (d k i) • P := by + intro k i + have h1 := congrArg adjoint (hd k i) + rw [adjoint_comp, adjoint_comp, hPadj, + show adjoint (d k i • P) = star (d k i) • P by + rw [← star_eq_adjoint, star_smul, show star P = P from hP]] at h1 + -- h1 : (P ∘L adjoint (E i)) ∘L adjoint (R k) = star (d k i) • P + rw [← ContinuousLinearMap.comp_assoc] + exact h1 + -- Assemble: `P Eᵢ† Eⱼ P = (∑ₖ c_barₖᵢ cₖⱼ) P` (N&C eq. (10.30)). + refine ⟨(Matrix.of d)ᴴ * Matrix.of d, Matrix.isHermitian_conjTranspose_mul_self _, ?_⟩ + rw [satisfiesKLConditions_iff] + intro i j + have hαij : ((Matrix.of d)ᴴ * Matrix.of d) i j = ∑ k, star (d k i) * d k j := by + simp only [Matrix.mul_apply, Matrix.conjTranspose_apply, Matrix.of_apply] + rw [hαij, Finset.sum_smul] + -- Insert `1 = ∑ₖ Rₖ† Rₖ` and reduce term-by-term. + have hsum : P ∘L adjoint (E i) ∘L E j ∘L P + = ∑ k, (P ∘L adjoint (E i) ∘L adjoint (R k)) ∘L (R k ∘L E j ∘L P) := by + ext x + simp only [_root_.sum_apply, ContinuousLinearMap.comp_apply, ← map_sum] + congr 2 + have hone := congrArg (fun T : H →L[ℂ] H => T (E j (P x))) hR + simp only [_root_.sum_apply, ContinuousLinearMap.comp_apply, + one_apply_eq_self] at hone + exact hone.symm + rw [hsum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [hdadj k i, hd k j, ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, + smul_smul, hPidem] + +/-! ### Sufficiency: the syndrome projectors + +Given the diagonalised conditions `P Fₗ† Fₖ P = dₗₖ P` (with `d` real), Nielsen & Chuang construct +the syndrome measurement from the polar decomposition `Fₖ P = √dₖₖ Uₖ P`, whose projectors are +`Pₖ ≡ Uₖ P Uₖ†` (Theorem 10.1, following eq. (10.18)). Since `Fₖ P Fₖ† = √dₖₖ Uₖ P · √dₖₖ P Uₖ† = +dₖₖ (Uₖ P Uₖ†)`, these projectors are exactly `dₖₖ⁻¹ Fₖ P Fₖ†`, which we take as the definition: +this expresses `Pₖ` directly in terms of the (diagonalised) operation elements, so the whole +construction stays elementary and never invokes the polar-decomposition isometry `Uₖ`. -/ + +omit [Fintype ι] in +/-- **The syndrome blocks `Fₖ P Fₖ†` compose according to the coefficient matrix.** If `F` satisfies +the Knill–Laflamme conditions `P Fₗ† Fₖ P = αₗₖ P` with matrix `α`, then the (unnormalised) syndrome +blocks `Fₗ P Fₗ†` and `Fₖ P Fₖ†` multiply as `(Fₗ P Fₗ†)(Fₖ P Fₖ†) = αₗₖ (Fₗ P Fₖ†)` — the middle +factor `P Fₗ† Fₖ P` collapses to `αₗₖ P`. When `α` is diagonal this vanishes off the diagonal, which +is what makes the syndrome subspaces orthogonal (Nielsen & Chuang, Theorem 10.1, eq. (10.19)). -/ +theorem SatisfiesKLConditions.errorBlock_comp (hF : SatisfiesKLConditions P F α) (l k : ι) : + (F l ∘L P ∘L adjoint (F l)) ∘L (F k ∘L P ∘L adjoint (F k)) + = α l k • (F l ∘L P ∘L adjoint (F k)) := by + ext x + simp only [ContinuousLinearMap.comp_apply, _root_.smul_apply] + have hlk := DFunLike.congr_fun (hF l k) (adjoint (F k) x) + simp only [ContinuousLinearMap.comp_apply, _root_.smul_apply] at hlk + rw [hlk, map_smul] + +/-- **The syndrome projector `Pₖ = dₖₖ⁻¹ Fₖ P Fₖ†`** of Nielsen & Chuang, Theorem 10.1. It is the +projector `Pₖ ≡ Uₖ P Uₖ†` onto the `k`-th syndrome subspace `Fₖ(C)`, written directly in terms of +the diagonalised operation elements `F` (with real diagonal `d`) instead of the polar-decomposition +isometry `Uₖ`. Under the diagonalised conditions `P Fₗ† Fₖ P = dₗₖ P` these are orthogonal +projections onto mutually orthogonal subspaces (the projectors of the syndrome measurement). + +The normalisation `(d k : ℂ)⁻¹` uses the field convention `0⁻¹ = 0`, so on an index `k` with +`dₖₖ = 0` — where the error `Fₖ` annihilates the code — the projector is `0`. -/ +def qecSyndromeProjector (P : H →L[ℂ] H) (F : ι → H →L[ℂ] H) (d : ι → ℝ) (k : ι) : H →L[ℂ] H := + ((d k : ℂ))⁻¹ • (F k ∘L P ∘L adjoint (F k)) + +omit [Fintype ι] in +/-- The syndrome projectors `qecSyndromeProjector P F d k` are **self-adjoint** — half of being +orthogonal projections (Nielsen & Chuang, Theorem 10.1). Needs only that the code projector `P` is +self-adjoint and the diagonal `d` is real. -/ +theorem qecSyndromeProjector_isSelfAdjoint (hP : IsSelfAdjoint P) (k : ι) : + IsSelfAdjoint (qecSyndromeProjector P F d k) := by + -- `Fₖ P Fₖ†` is the `IsSelfAdjoint.conjugate` of `P`; scalar `dₖₖ⁻¹` via `IsSelfAdjoint.smul`. + have hsa : IsSelfAdjoint ((d k : ℂ)⁻¹) := by + rw [isSelfAdjoint_iff, star_inv₀, ← starRingEnd_apply, Complex.conj_ofReal] + have h := hP.conjugate (F k) + rw [star_eq_adjoint] at h + simp only [qecSyndromeProjector] + exact hsa.smul (by simpa only [mul_def, comp_assoc] using h) + +omit [Fintype ι] in +/-- The syndrome projectors are **orthogonal (star) projections** — self-adjoint idempotents +(Nielsen & Chuang, Theorem 10.1). Bundled as `IsStarProjection`, so the raw self-adjoint / +idempotent facts are recovered via `.isSelfAdjoint` / `.isIdempotentElem`, and the family plugs +straight into Mathlib's orthogonal-projection API — `IsStarProjection.add` (with the orthogonality +`qecSyndromeProjector_comp_eq_zero`), `ContinuousLinearMap.IsPositive.of_isStarProjection`, +`CompleteOrthogonalIdempotents` — that the recovery-channel assembly consumes. + +Idempotency is `(Fₖ P Fₖ†)(Fₖ P Fₖ†) = dₖₖ (Fₖ P Fₖ†)` (`errorBlock_comp`) together with the scalar +identity `dₖₖ⁻¹ dₖₖ⁻¹ dₖₖ = dₖₖ⁻¹` (valid also at `dₖₖ = 0` under the `0⁻¹ = 0` convention). -/ +theorem qecSyndromeProjector_isStarProjection [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) (k : ι) : + IsStarProjection (qecSyndromeProjector P F d k) := by + have hs : (((d k : ℂ))⁻¹ * ((d k : ℂ))⁻¹) * (d k : ℂ) = ((d k : ℂ))⁻¹ := by + rcases eq_or_ne (d k : ℂ) 0 with h | h + · simp [h] + · rw [mul_assoc, inv_mul_cancel₀ h, mul_one] + have hidem : qecSyndromeProjector P F d k ∘L qecSyndromeProjector P F d k + = qecSyndromeProjector P F d k := by + simp only [qecSyndromeProjector, smul_comp, comp_smul] + rw [hF.errorBlock_comp k k, Matrix.diagonal_apply_eq, smul_smul, smul_smul, hs] + rw [isStarProjection_iff] + exact ⟨hidem, qecSyndromeProjector_isSelfAdjoint hP k⟩ + +omit [Fintype ι] in +/-- **Orthogonality of distinct syndrome projectors**, `Pₗ Pₖ = 0` for `l ≠ k` (Nielsen & Chuang, +Theorem 10.1, eq. (10.19)): the error subspaces `Fₗ(C)` and `Fₖ(C)` are orthogonal, so the syndrome +measurement can reliably distinguish which error occurred. Immediate from the off-diagonal vanishing +`(Fₗ P Fₗ†)(Fₖ P Fₖ†) = dₗₖ (Fₗ P Fₖ†) = 0`. -/ +theorem qecSyndromeProjector_comp_eq_zero [DecidableEq ι] + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) {l k : ι} (hlk : l ≠ k) : + qecSyndromeProjector P F d l ∘L qecSyndromeProjector P F d k = 0 := by + simp only [qecSyndromeProjector, smul_comp, comp_smul] + rw [hF.errorBlock_comp l k, Matrix.diagonal_apply_ne _ hlk, zero_smul, smul_zero, smul_zero] + +/-! ### Sufficiency: the trace-preserving recovery operation + +With the syndrome projectors `Pₖ = dₖₖ⁻¹ Fₖ P Fₖ†` in hand, Nielsen & Chuang assemble the recovery +operation `R(σ) = ∑ₖ Uₖ† Pₖ σ Pₖ Uₖ` from the recovery operation elements `Rₖ = Uₖ† Pₖ`. Because +`Fₖ P = √dₖₖ Uₖ P`, one has `Rₖ = Uₖ† Pₖ = P Uₖ† = (√dₖₖ)⁻¹ P Fₖ†` — like the syndrome projectors, +this is expressible directly from the diagonalised operation elements `F`, with no +polar-decomposition isometry `Uₖ`. Here we build that recovery family and show it is a genuine +(trace-preserving) quantum operation: N&C's "augmented by an additional projector … to satisfy the +completeness relation `∑ₖ Pₖ = I`" is realised by adjoining the complementary projector +`1 - ∑ₖ Pₖ`, after which `∑ₒ Rₒ† Rₒ = 1`. That this recovery in fact *corrects* `E` on the code +(N&C eqs. (10.20)–(10.26)) is developed separately. -/ + +/-- **A recovery operation element `Rₖ = (√dₖₖ)⁻¹ P Fₖ†`** of the sufficiency construction (Nielsen +& Chuang, Theorem 10.1). This is N&C's `Rₖ = Uₖ† Pₖ = P Uₖ†` rewritten without the +polar-decomposition isometry `Uₖ`, using `P Fₖ† = √dₖₖ P Uₖ†`; applied after detecting syndrome `k` +it rotates the `k`-th error subspace back onto the code. The `(√dₖₖ)⁻¹` normalisation uses the field +convention `0⁻¹ = 0`, so `Rₖ = 0` on an index `k` with `dₖₖ = 0`, where the error `Fₖ` annihilates +the code. -/ +def qecRecoveryElement (P : H →L[ℂ] H) (F : ι → H →L[ℂ] H) (d : ι → ℝ) (k : ι) : H →L[ℂ] H := + (Real.sqrt (d k) : ℂ)⁻¹ • (P ∘L adjoint (F k)) + +/-- **The recovery operation of the sufficiency construction** (Nielsen & Chuang, Theorem 10.1), as +a family of operation elements indexed by `ι ⊕ Unit`. The `Sum.inl k` elements are the recovery +elements `Rₖ = (√dₖₖ)⁻¹ P Fₖ†` (`qecRecoveryElement`); the single `Sum.inr` element is the +completion projector `1 - ∑ₖ Pₖ` onto the orthogonal complement of the syndrome subspaces — N&C's +"additional projector … to satisfy the completeness relation `∑ₖ Pₖ = I`" — which makes the whole +family trace-preserving (`qecRecovery_adjoint_comp_self_sum`). -/ +def qecRecovery (P : H →L[ℂ] H) (F : ι → H →L[ℂ] H) (d : ι → ℝ) : ι ⊕ Unit → H →L[ℂ] H := + Sum.elim (qecRecoveryElement P F d) fun _ => 1 - ∑ k, qecSyndromeProjector P F d k + +omit [Fintype ι] in +/-- **The diagonalised Knill–Laflamme coefficients are nonnegative**, `0 ≤ dₖ`, whenever the code +projector `P` is nonzero (Nielsen & Chuang, Theorem 10.1). The simplified conditions give +`P Fₖ† Fₖ P = dₖ P`, and `P Fₖ† Fₖ P = (Fₖ P)† (Fₖ P)` is a positive operator; evaluating the +positivity of `dₖ • P` at a code vector (`nonneg_of_smul_isPositive`) forces `dₖ ≥ 0`. Physically +`α`, being (unitarily equivalent to) the Gram matrix of the errors restricted to the code, is +positive semidefinite; the hypothesis `P ≠ 0` is what a genuine (nonzero) code always satisfies. It +is `0 ≤ dₖ` that makes the `(√dₖₖ)⁻¹` normalisation of the recovery elements meaningful. -/ +theorem qecSyndromeProjector_diagonal_nonneg [DecidableEq ι] (hP : IsSelfAdjoint P) + (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) (k : ι) : 0 ≤ d k := by + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hP + have hkey : P ∘L adjoint (F k) ∘L F k ∘L P = (d k : ℂ) • P := by + have h := hF k k; rwa [Matrix.diagonal_apply_eq] at h + refine nonneg_of_smul_isPositive hPidem hP0 ?_ + rw [← hkey] + have h := isPositive_adjoint_comp_self (F k ∘L P) + rwa [adjoint_comp, hPadj, comp_assoc] at h + +omit [Fintype ι] in +/-- **Each recovery element satisfies `Rₖ† Rₖ = Pₖ`** (Nielsen & Chuang, Theorem 10.1): the effect +`Rₖ† Rₖ` of the recovery element for syndrome `k` is exactly the `k`-th syndrome projector. With +`Rₖ = (√dₖ)⁻¹ P Fₖ†` and `P` self-adjoint idempotent, `Rₖ† Rₖ = ((√dₖ)⁻¹)² Fₖ P Fₖ†`, which equals +`dₖ⁻¹ Fₖ P Fₖ† = Pₖ` because `(√dₖ)² = dₖ` (`Real.mul_self_sqrt`, needing `0 ≤ dₖ`; the identity +survives `dₖ = 0` under `0⁻¹ = 0`). Summed over the syndromes this yields the completeness +`∑ₖ Rₖ† Rₖ = ∑ₖ Pₖ`. -/ +theorem qecRecoveryElement_adjoint_comp_self (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (k : ι) + (hdk : 0 ≤ d k) : + adjoint (qecRecoveryElement P F d k) ∘L qecRecoveryElement P F d k + = qecSyndromeProjector P F d k := by + have hPstar : star P = P := hP + have hidem : P * P = P := hPidem + have hstar : star ((Real.sqrt (d k) : ℂ)⁻¹) = (Real.sqrt (d k) : ℂ)⁻¹ := by + rw [star_inv₀, ← starRingEnd_apply, Complex.conj_ofReal] + have hsqrt : (Real.sqrt (d k) : ℂ)⁻¹ * (Real.sqrt (d k) : ℂ)⁻¹ = ((d k : ℂ))⁻¹ := by + rw [← mul_inv_rev, ← Complex.ofReal_mul, Real.mul_self_sqrt hdk] + simp only [qecRecoveryElement, qecSyndromeProjector, ← mul_def, ← star_eq_adjoint] + rw [star_smul, hstar, star_mul, star_star, hPstar, smul_mul_assoc, mul_smul_comm, smul_smul, + hsqrt] + congr 1 + rw [mul_assoc (F k) P, ← mul_assoc P P, hidem] + +omit [Fintype ι] in +/-- **The syndrome projectors form an orthogonal family of idempotents** +(`OrthogonalIdempotents`; Nielsen & Chuang, Theorem 10.1): each `Pₖ` is idempotent +(`qecSyndromeProjector_isStarProjection`) and the family is pairwise orthogonal, `Pₖ Pₗ = 0` for +`k ≠ l` (`qecSyndromeProjector_comp_eq_zero`, N&C eq. (10.19)). Packaging the family this way feeds +Mathlib's idempotents API directly — `OrthogonalIdempotents.isIdempotentElem_sum` for +`qecSyndromeProjector_sum_isStarProjection`, and `OrthogonalIdempotents.option` for the recovery's +completion by `1 - ∑ₖ Pₖ` in the trace-preservation and correction steps. -/ +theorem qecSyndromeProjector_orthogonalIdempotents [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) : + OrthogonalIdempotents (qecSyndromeProjector P F d) := + ⟨fun k => (qecSyndromeProjector_isStarProjection hP hF k).isIdempotentElem, + fun _ _ hlk => qecSyndromeProjector_comp_eq_zero hF hlk⟩ + +/-- **The sum of the syndrome projectors is an orthogonal projection** (Nielsen & Chuang, Theorem +10.1): `∑ₖ Pₖ` projects onto the direct sum of the mutually orthogonal syndrome subspaces. It is +self-adjoint (`isSelfAdjoint_sum`) and idempotent — the syndrome projectors are an orthogonal family +of idempotents (`qecSyndromeProjector_orthogonalIdempotents`), so +`OrthogonalIdempotents.isIdempotentElem_sum` gives `(∑ₖ Pₖ)² = ∑ₖ Pₖ`. This is what lets the +recovery be completed to a trace-preserving operation by adjoining `1 - ∑ₖ Pₖ` +(`qecRecovery_adjoint_comp_self_sum`). -/ +theorem qecSyndromeProjector_sum_isStarProjection [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) : + IsStarProjection (∑ k, qecSyndromeProjector P F d k) := + ⟨(qecSyndromeProjector_orthogonalIdempotents hP hF).isIdempotentElem_sum, + isSelfAdjoint_sum _ fun k _ => qecSyndromeProjector_isSelfAdjoint hP k⟩ + +/-- **The recovery operation is trace-preserving**, `∑ₒ Rₒ† Rₒ = 1` (Nielsen & Chuang, Theorem +10.1): `qecRecovery` is a genuine (trace-preserving) quantum operation. Over `ι ⊕ Unit` the sum +splits (`Fintype.sum_sum_type`) into the syndrome part `∑ₖ Rₖ† Rₖ = ∑ₖ Pₖ` +(`qecRecoveryElement_adjoint_comp_self`) and the completion part `Q† Q = Q` for the projection +`Q = 1 - ∑ₖ Pₖ` (`qecSyndromeProjector_sum_isStarProjection` + `IsStarProjection.one_sub`), and +`∑ₖ Pₖ + (1 - ∑ₖ Pₖ) = 1`. The nonzero-code hypothesis `P ≠ 0` enters through the nonnegativity of +the `dₖ` (`qecSyndromeProjector_diagonal_nonneg`), needed for `Rₖ† Rₖ = Pₖ`. -/ +theorem qecRecovery_adjoint_comp_self_sum [DecidableEq ι] (hP : IsSelfAdjoint P) + (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) : + ∑ o, adjoint (qecRecovery P F d o) ∘L qecRecovery P F d o = 1 := by + have hQ : IsStarProjection (1 - ∑ k, qecSyndromeProjector P F d k) := + (qecSyndromeProjector_sum_isStarProjection hP hF).one_sub + have hQadj : adjoint (1 - ∑ k, qecSyndromeProjector P F d k) + = 1 - ∑ k, qecSyndromeProjector P F d k := by rw [← star_eq_adjoint]; exact hQ.isSelfAdjoint + have hQidem : (1 - ∑ k, qecSyndromeProjector P F d k) ∘L (1 - ∑ k, qecSyndromeProjector P F d k) + = 1 - ∑ k, qecSyndromeProjector P F d k := hQ.isIdempotentElem + rw [Fintype.sum_sum_type] + simp only [qecRecovery, Sum.elim_inl, Sum.elim_inr, Fintype.sum_unique] + rw [Finset.sum_congr rfl fun k (_ : k ∈ Finset.univ) => + qecRecoveryElement_adjoint_comp_self hP hPidem k + (qecSyndromeProjector_diagonal_nonneg hP hPidem hP0 hF k), hQadj, hQidem] + abel + +/-! ### Sufficiency: the recovery corrects the errors on the code + +The final step of the sufficiency half (Nielsen & Chuang, Theorem 10.1, eqs. (10.20)–(10.26)): the +trace-preserving recovery `qecRecovery P F d` in fact *corrects* the diagonalised errors `F` on the +code, `Corrects P F (qecRecovery P F d)`. The engine is the family of **detection identities** for +`Rₒ Fₗ P` (recovery element `Rₒ` applied to an error `Fₗ` on the code): the syndrome-`k` element +`Rₖ` sends the `l`-th error subspace to `√dₖ P` when `k = l` and to `0` otherwise +(`qecRecoveryElement_comp_error_comp_proj`, eqs. (10.20)–(10.23)), while the completion element +`Q = 1 - ∑ₖ Pₖ` annihilates every error subspace (from +`qecSyndromeProjector_comp_error_comp_proj`). Feeding these into the combined operator-sum map +`(R ∘ F)(ρ)` collapses the double sum to `(∑ₖ dₖ) • ρ` for `ρ` supported on the code (eqs. +(10.24)–(10.26)). The proportionality constant `∑ₖ dₖ` (`= 1` when the errors are trace-preserving) +is allowed to be any scalar by `Corrects`, matching N&C's `∝` in eq. (10.15). -/ + +omit [Fintype ι] in +/-- **An error element annihilates the code when its diagonal coefficient vanishes**, `Fₗ P = 0` +whenever `dₗ = 0` (Nielsen & Chuang, Theorem 10.1). Under the diagonalised conditions the operator +`(Fₗ P)† (Fₗ P) = P Fₗ† Fₗ P = dₗ • P` is `0`, and a continuous linear map with `T† T = 0` vanishes +(`adjoint_comp_self_eq_zero_iff`). This is what makes the `0⁻¹ = 0` convention in the syndrome +projector and recovery element on such an index give the physically correct value `0`. -/ +theorem errorElement_eq_zero_of_diag_zero [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) {l : ι} (hl : d l = 0) : + F l ∘L P = 0 := by + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hP + rw [← adjoint_comp_self_eq_zero_iff, adjoint_comp, hPadj] + have h := hF l l + rw [Matrix.diagonal_apply_eq, hl, Complex.ofReal_zero, zero_smul] at h + rw [comp_assoc, h] + +omit [Fintype ι] in +/-- **Detection identity for the recovery elements** (Nielsen & Chuang, Theorem 10.1, eqs. +(10.20)–(10.23)): the syndrome-`k` recovery element `Rₖ = (√dₖ)⁻¹ P Fₖ†` applied to the `l`-th error +on the code is `√dₖ P` when `k = l` and `0` otherwise. Indeed `Rₖ Fₗ P = (√dₖ)⁻¹ (P Fₖ† Fₗ P) = +(√dₖ)⁻¹ dₖₗ P`, and `(√dₖ)⁻¹ dₖ = dₖ / √dₖ = √dₖ` (`Real.div_sqrt`, which holds unconditionally, +including at `dₖ = 0`, under the `0⁻¹ = 0` convention). This identity rotates the detected error +subspace back onto the code. -/ +theorem qecRecoveryElement_comp_error_comp_proj [DecidableEq ι] + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) (k l : ι) : + qecRecoveryElement P F d k ∘L (F l ∘L P) + = if k = l then (Real.sqrt (d k) : ℂ) • P else 0 := by + have hkl := hF k l + simp only [qecRecoveryElement, smul_comp] + rw [comp_assoc, hkl, smul_smul] + by_cases h : k = l + · subst h + rw [ite_eq_left rfl, Matrix.diagonal_apply_eq, ← Complex.ofReal_inv, ← Complex.ofReal_mul, + show (Real.sqrt (d k))⁻¹ * d k = Real.sqrt (d k) from by + rw [mul_comm, ← div_eq_mul_inv, Real.div_sqrt]] + · rw [ite_eq_right h, Matrix.diagonal_apply_ne _ h, mul_zero, zero_smul] + +omit [Fintype ι] in +/-- **Detection identity for the syndrome projectors** (Nielsen & Chuang, Theorem 10.1): the `k`-th +syndrome projector `Pₖ = dₖ⁻¹ Fₖ P Fₖ†` fixes the `l`-th error on the code when `k = l` and +annihilates it otherwise, `Pₖ Fₗ P = if k = l then Fₗ P else 0`. From `Pₖ Fₗ P = +dₖ⁻¹ Fₖ (P Fₖ† Fₗ P) = dₖ⁻¹ dₖₗ (Fₖ P)`: off the diagonal `dₖₗ = 0`; on it `dₖ⁻¹ dₖ = 1` when +`dₖ ≠ 0`, while at `dₖ = 0` both `dₖ⁻¹ dₖ = 0` and `Fₖ P = 0` (`errorElement_eq_zero_of_diag_zero`), +so `Pₖ Fₖ P = Fₖ P` regardless. This is the orthogonality that lets the completion element +`1 - ∑ₖ Pₖ` annihilate every error subspace. -/ +theorem qecSyndromeProjector_comp_error_comp_proj [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) (k l : ι) : + qecSyndromeProjector P F d k ∘L (F l ∘L P) = if k = l then F l ∘L P else 0 := by + have hkl := hF k l + simp only [qecSyndromeProjector, smul_comp] + rw [comp_assoc, comp_assoc, hkl] + by_cases h : k = l + · subst h + rw [ite_eq_left rfl, Matrix.diagonal_apply_eq, comp_smul, smul_smul] + rcases eq_or_ne (d k) 0 with h0 | h0 + · rw [errorElement_eq_zero_of_diag_zero hP hF h0, smul_zero] + · rw [inv_mul_cancel₀ (by exact_mod_cast h0), one_smul] + · rw [ite_eq_right h, Matrix.diagonal_apply_ne _ h, zero_smul, comp_zero, smul_zero] + +/-- **The completion element annihilates every error on the code**, `(1 - ∑ₖ Pₖ) Fₗ P = 0` (Nielsen +& Chuang, Theorem 10.1): the error `Fₗ` maps the code into the syndrome subspaces, so the projector +`∑ₖ Pₖ` onto their span fixes `Fₗ P` and the complementary projector `Q = 1 - ∑ₖ Pₖ` kills it. From +the syndrome detection `Pₖ Fₗ P = if k = l then Fₗ P else 0`, the sum `∑ₖ Pₖ Fₗ P` collapses to the +single surviving term `Fₗ P`, so `Q Fₗ P = Fₗ P - Fₗ P = 0`. -/ +theorem qecRecoveryCompletion_comp_error_comp_proj [DecidableEq ι] (hP : IsSelfAdjoint P) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) (l : ι) : + (1 - ∑ k, qecSyndromeProjector P F d k) ∘L (F l ∘L P) = 0 := by + have hsum : ∑ k, qecSyndromeProjector P F d k ∘L (F l ∘L P) = F l ∘L P := by + rw [Finset.sum_congr rfl fun k _ => qecSyndromeProjector_comp_error_comp_proj hP hF k l] + simp only [Finset.sum_ite_eq', Finset.mem_univ, ite_true] + rw [sub_comp, finsetSum_comp, hsum] + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp, sub_self] + +/-- **Sufficiency: the recovery corrects the diagonalised errors on the code** (Nielsen & Chuang, +Theorem 10.1, eqs. (10.20)–(10.26)). If `P` is a nonzero self-adjoint code projector and the +operation elements `F` satisfy the *diagonalised* Knill–Laflamme conditions +`P Fₖ† Fₗ P = dₖₗ P` (`d` real), then the trace-preserving recovery `qecRecovery P F d` corrects `F` +on the code: for every `ρ` supported on the code (`P ρ P = ρ`), `(R ∘ F)(ρ) = (∑ₖ dₖ) • ρ ∝ ρ`. + +The proof computes the combined operator-sum map `krausSumₗ R (krausSumₗ F ρ)`. Writing +`ρ = P ρ P` absorbs the code projector into the errors (`krausSumₗ F ρ = +krausSumₗ (Fₗ P) ρ`), and `krausSumₗ_comp` combines the two Kraus maps into the single family +`(o, l) ↦ Rₒ Fₗ P`. The recovery-element detection identity +(`qecRecoveryElement_comp_error_comp_proj`) makes each such term `(√dₖ P) ρ (√dₖ P)† = dₖ • ρ` on +the diagonal `o = Sum.inl k, l = k` and `0` off it, while the completion element gives `0` +(`qecRecoveryCompletion_comp_error_comp_proj`); summing leaves `(∑ₖ dₖ) • ρ`. No +finite-dimensionality of `H` is needed — the construction is explicit, unlike the necessity half. -/ +theorem corrects_of_satisfiesKLConditions_diagonal [DecidableEq ι] (hP : IsSelfAdjoint P) + (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (hF : SatisfiesKLConditions P F (Matrix.diagonal fun i => (d i : ℂ))) : + Corrects P F (qecRecovery P F d) := by + have hPadj : adjoint P = P := by rw [← star_eq_adjoint]; exact hP + intro ρ hρ + refine ⟨∑ k, (d k : ℂ), ?_⟩ + set R := qecRecovery P F d with hR + -- Absorb the code projector into the errors: `krausSumₗ F ρ = krausSumₗ (fun l => Fₗ P) ρ`. + have hFρ : krausSumₗ F ρ = krausSumₗ (fun l => F l ∘L P) ρ := by + rw [krausSumₗ_apply, krausSumₗ_apply] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [adjoint_comp, hPadj, + show (F l ∘L P) ∘L ρ ∘L (P ∘L adjoint (F l)) = F l ∘L (P ∘L ρ ∘L P) ∘L adjoint (F l) from by + simp only [comp_assoc], hρ] + -- Combine the two Kraus maps into the single family `(o, l) ↦ Rₒ (Fₗ P)`. + rw [hFρ, ← LinearMap.comp_apply, krausSumₗ_comp, krausSumₗ_apply, Fintype.sum_prod_type, + Fintype.sum_sum_type] + -- The `Sum.inr` (completion) block vanishes; the `Sum.inl k` block gives `dₖ • ρ` at `l = k`. + have hcompl : ∀ u : Unit, + ∑ l, (R (Sum.inr u) ∘L (F l ∘L P)) ∘L ρ ∘L adjoint (R (Sum.inr u) ∘L (F l ∘L P)) = 0 := by + intro u + refine Finset.sum_eq_zero fun l _ => ?_ + rw [hR, qecRecovery, Sum.elim_inr, qecRecoveryCompletion_comp_error_comp_proj hP hF l] + simp + have hrec : ∀ k : ι, + ∑ l, (R (Sum.inl k) ∘L (F l ∘L P)) ∘L ρ ∘L adjoint (R (Sum.inl k) ∘L (F l ∘L P)) + = (d k : ℂ) • ρ := by + intro k + have hdk : 0 ≤ d k := qecSyndromeProjector_diagonal_nonneg hP hPidem hP0 hF k + have hadjM : adjoint ((Real.sqrt (d k) : ℂ) • P) = (Real.sqrt (d k) : ℂ) • P := by + rw [← star_eq_adjoint, star_smul, show star P = P from hP, ← starRingEnd_apply, + Complex.conj_ofReal] + rw [Fintype.sum_eq_single k fun l hlk => ?_] + · rw [hR, qecRecovery, Sum.elim_inl, + qecRecoveryElement_comp_error_comp_proj hF k k, ite_eq_left rfl, hadjM] + simp only [smul_comp, comp_smul, smul_smul] + rw [hρ] + congr 1 + rw [← Complex.ofReal_mul, Real.mul_self_sqrt hdk] + · rw [hR, qecRecovery, Sum.elim_inl, + qecRecoveryElement_comp_error_comp_proj hF k l, ite_eq_right (Ne.symm hlk)] + simp + rw [Finset.sum_congr rfl fun k _ => hrec k, Finset.sum_congr rfl fun u _ => hcompl u, + Finset.sum_const_zero, add_zero, ← Finset.sum_smul] + +universe u + +/-- **Sufficiency of the Knill–Laflamme quantum error-correction conditions** (Nielsen & Chuang, +Theorem 10.1, the `⇐` direction). If `P` is a nonzero self-adjoint code projector and the operation +elements `E` satisfy the conditions `P Eᵢ† Eⱼ P = αᵢⱼ P` for a **Hermitian** matrix `α`, then there +is a **trace-preserving** recovery operation `R` (`∑ₒ Rₒ† Rₒ = 1`) that **corrects** the errors `E` +on the code (`Corrects P E R`). + +The recovery is Nielsen & Chuang's explicit syndrome-measure-then-rotate operation: diagonalise the +conditions (`SatisfiesKLConditions.exists_recombine_diagonal`) to recombined elements `F` with the +same operator-sum map and real diagonal `d`, then take `R = qecRecovery P F d` — the syndrome +recovery elements `(√dₖ)⁻¹ P Fₖ†` completed by `1 - ∑ₖ Pₖ`. It is trace-preserving +(`qecRecovery_adjoint_comp_self_sum`) and corrects `E` because it corrects `F` +(`corrects_of_satisfiesKLConditions_diagonal`) and `krausSumₗ F = krausSumₗ E`. Unlike the necessity +half this needs **no** `FiniteDimensional ℂ H`: the recovery is constructed explicitly. The +existential over the index `κ` (here `ι ⊕ Unit`) matches the shape consumed by the necessity theorem +`satisfiesKLConditions_of_corrects`, so the two directions assemble into the biconditional. -/ +theorem corrects_of_satisfiesKLConditions {H : Type*} [NormedAddCommGroup H] + [InnerProductSpace ℂ H] [CompleteSpace H] {ι : Type u} [Fintype ι] + {P : H →L[ℂ] H} {E : ι → H →L[ℂ] H} {α : Matrix ι ι ℂ} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) + (hα : α.IsHermitian) (hE : SatisfiesKLConditions P E α) : + ∃ (κ : Type u) (_ : Fintype κ) (R : κ → H →L[ℂ] H), + (∑ o, adjoint (R o) ∘L R o = 1) ∧ Corrects P E R := by + classical + obtain ⟨F, hFE, hFdiag⟩ := hE.exists_recombine_diagonal hα + have hFdiag' : SatisfiesKLConditions P F (Matrix.diagonal fun i => (hα.eigenvalues i : ℂ)) := + hFdiag + refine ⟨ι ⊕ Unit, inferInstance, qecRecovery P F hα.eigenvalues, + qecRecovery_adjoint_comp_self_sum hP hPidem hP0 hFdiag', fun ρ hρ => ?_⟩ + obtain ⟨c, hc⟩ := corrects_of_satisfiesKLConditions_diagonal hP hPidem hP0 hFdiag' ρ hρ + exact ⟨c, by rw [← hFE]; exact hc⟩ + +/-- **The Knill–Laflamme quantum error-correction conditions** (Nielsen & Chuang, Theorem 10.1) — +the biconditional. For a nonzero orthogonal code projector `P` and a finite family of operation +elements `E` (the noise) on a finite-dimensional complex inner product space, there exists a +**trace-preserving** recovery operation `R` (`∑ₒ Rₒ† Rₒ = 1`) that **corrects** `E` on the code +(`Corrects P E R`) **iff** the errors satisfy `P Eᵢ† Eⱼ P = αᵢⱼ P` for a **Hermitian** matrix `α`. + +This assembles the two halves proved above: +* `⟹` is `satisfiesKLConditions_of_corrects` (necessity, N&C eqs. (10.27)–(10.30)); +* `⇐` is `corrects_of_satisfiesKLConditions` (sufficiency, N&C eqs. (10.17)–(10.26), the explicit + syndrome-measure-then-rotate recovery). + +The two directions use the *same* existential shape for the recovery (a Kraus family with the +completeness relation `∑ₒ Rₒ† Rₒ = 1`), so they combine into a single `Iff`. `FiniteDimensional ℂ H` +is needed only for the `⟹` direction (the operator-sum-freedom step, N&C Theorem 8.2); the recovery +in `⇐` is constructed explicitly. -/ +theorem satisfiesKLConditions_iff_exists_correction {H : Type*} [NormedAddCommGroup H] + [InnerProductSpace ℂ H] [CompleteSpace H] [FiniteDimensional ℂ H] {ι : Type u} [Fintype ι] + {P : H →L[ℂ] H} {E : ι → H →L[ℂ] H} + (hP : IsSelfAdjoint P) (hPidem : P ∘L P = P) (hP0 : P ≠ 0) : + (∃ (κ : Type u) (_ : Fintype κ) (R : κ → H →L[ℂ] H), + (∑ o, adjoint (R o) ∘L R o = 1) ∧ Corrects P E R) ↔ + ∃ α : Matrix ι ι ℂ, α.IsHermitian ∧ SatisfiesKLConditions P E α := by + constructor + · rintro ⟨κ, _, R, hR, hcorr⟩ + exact satisfiesKLConditions_of_corrects hP hPidem hP0 hR hcorr + · rintro ⟨α, hα, hE⟩ + exact corrects_of_satisfiesKLConditions hP hPidem hP0 hα hE + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumFanoInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumFanoInequality.lean new file mode 100644 index 0000000000..1bde7e37e1 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumFanoInequality.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntropyExchange +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropyFano + +/-! # The quantum Fano inequality + +For a state `ρ` (a density operator on a `d`-dimensional complex inner product space `H`, so +`d = finrank ℂ H`) and a trace-preserving quantum operation with operation elements +`E : ι → (H →L[ℂ] H)` (`∑ᵢ Eᵢ† Eᵢ = 1`), the **entropy exchange** `S(ρ, E)` and the **entanglement +fidelity** `F(ρ, E)` obey the **quantum Fano inequality** (Nielsen & Chuang, *Quantum Computation +and Quantum Information*, Theorem 12.9, eq. (12.112)): +`S(ρ, E) ≤ H(F(ρ, E)) + (1 - F(ρ, E)) · log (d² - 1)`, +where `H` is the binary Shannon entropy. + +This file is the assembly step of the development spread across +`ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyFano.lean` (the density-operator Fano bound), +`…/VonNeumannEntropyGram.lean` (the Gram / sum-of-rank-ones entropy equality), and +`…/EntropyExchange.lean` (the entropy exchange `S(ρ, E)`, the reference-plus-system output state +`ρ_{R'Q'}`, and its entanglement-fidelity overlap). It carries out the two observations of N&C's +proof (eqs. (12.113)–(12.115)): + +* the reference-plus-system output state `ρ_{R'Q'}` lives on the `d²`-dimensional Hilbert–Schmidt + space `H ⊗ H` (`Module.finrank_tensorProduct`), with entropy `S(ρ_{R'Q'}) = S(ρ, E)` + (`entropyExchange_eq_vonNeumannEntropy_entropyExchangeState`) and diagonal entry against the unit + vector `vec √ρ` (N&C's `|RQ⟩`, `norm_matricize_symm_cfc_sqrt`) equal to the entanglement fidelity + `⟨√ρ, ρ_{R'Q'} √ρ⟩ = F(ρ, E)` (`re_inner_entropyExchangeState_sqrt_eq_entanglementFidelity`); +* the density-operator Fano bound `S(σ) ≤ H(⟨ψ, σ ψ⟩) + (1 - ⟨ψ, σ ψ⟩) · log (D - 1)` + (`IsDensityOp.vonNeumannEntropy_le_binEntropy_add`, N&C eqs. (12.113)–(12.115)) applied to + `σ = ρ_{R'Q'}`, `ψ = vec √ρ`, `D = finrank ℂ (H ⊗ H) = d²`. + +Composing these turns the density-operator Fano bound at dimension `d²` into the quantum Fano +inequality. The whole development is stated for operators and Kraus families; the statement of +Nielsen & Chuang Theorem 12.9 is in [upstream `AxQM/NC/Ch12/Theorem12_9.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch12/Theorem12_9.lean). + +## Main results + +* `ContinuousLinearMap.entropyExchange_le_binEntropy_entanglementFidelity_add` — the quantum Fano + inequality `S(ρ, E) ≤ H(F(ρ, E)) + (1 - F(ρ, E)) · log (d² - 1)` (N&C Theorem 12.9, eq. (12.112)). + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.4.1 (Theorem 12.9, eqs. (12.107)–(12.115)). +-/ + +open scoped InnerProductSpace TensorProduct ComplexConjugate +open InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] [CompleteSpace H] + {ι : Type*} [Fintype ι] [DecidableEq ι] + +/-- **The quantum Fano inequality** (Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 12.9, eq. (12.112)). For a density operator `ρ` on a `d`-dimensional space +`H` (`d = finrank ℂ H`) and a trace-preserving quantum operation with operation elements +`E : ι → (H →L[ℂ] H)` (`∑ᵢ Eᵢ† Eᵢ = 1`), the entropy exchange is bounded by the binary Shannon +entropy of the entanglement fidelity: +`S(ρ, E) ≤ H(F(ρ, E)) + (1 - F(ρ, E)) · log (d² - 1)`. + +The proof realizes the reference-plus-system output state `ρ_{R'Q'} = entropyExchangeState b ρ E` +as a density operator on the `d²`-dimensional Hilbert–Schmidt space `H ⊗ H` +(`entropyExchangeState_isDensityOp`, using trace preservation), applies the density-operator Fano +bound `IsDensityOp.vonNeumannEntropy_le_binEntropy_add` there with the unit vector `vec √ρ` +(N&C's initial `|RQ⟩`, `norm_matricize_symm_cfc_sqrt`), and rewrites the two sides: +`S(ρ_{R'Q'}) = S(ρ, E)` (`entropyExchange_eq_vonNeumannEntropy_entropyExchangeState`) and the +diagonal entry `⟨vec √ρ, ρ_{R'Q'} (vec √ρ)⟩ = F(ρ, E)` +(`re_inner_entropyExchangeState_sqrt_eq_entanglementFidelity`), while the dimension of the space is +`finrank ℂ (H ⊗ H) = d²` (`Module.finrank_tensorProduct`). -/ +theorem entropyExchange_le_binEntropy_entanglementFidelity_add + {ρ : H →L[ℂ] H} (hρ : ρ.IsDensityOp) {E : ι → H →L[ℂ] H} + (htp : ∑ i, adjoint (E i) * E i = 1) : + entropyExchange ρ E ≤ Real.binEntropy (entanglementFidelity ρ E) + + (1 - entanglementFidelity ρ E) * Real.log ((Module.finrank ℂ H : ℝ) ^ 2 - 1) := by + -- Realize `ρ_{R'Q'}` on the `d²`-dimensional Hilbert–Schmidt space `H ⊗ H`, with the unit + -- Hilbert–Schmidt vector `vec √ρ`, and apply the density-operator Fano bound there. + set b := stdOrthonormalBasis ℂ H with hb + have hM : (entropyExchangeState b ρ E).IsDensityOp := entropyExchangeState_isDensityOp b hρ htp + have hψ : ‖(TensorProduct.matricize b).symm (cfc Real.sqrt ρ)‖ = 1 := + norm_matricize_symm_cfc_sqrt b hρ + have hbound := hM.vonNeumannEntropy_le_binEntropy_add hψ + -- `S(ρ_{R'Q'}) = S(ρ, E)` and `⟨vec √ρ, ρ_{R'Q'} (vec √ρ)⟩ = F(ρ, E)`. + rw [re_inner_entropyExchangeState_sqrt_eq_entanglementFidelity b hρ.nonneg E, + ← entropyExchange_eq_vonNeumannEntropy_entropyExchangeState b hρ.nonneg E] at hbound + -- The Hilbert–Schmidt space has dimension `finrank ℂ (H ⊗ H) = d²`. + rw [show ((Module.finrank ℂ H : ℝ) ^ 2 - 1) + = ((Module.finrank ℂ (H ⊗[ℂ] H) : ℝ) - 1) by + rw [Module.finrank_tensorProduct]; push_cast; ring] + exact hbound + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropy.lean new file mode 100644 index 0000000000..ffc014de03 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropy.lean @@ -0,0 +1,659 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFCTensor +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LiebConcavityTrace +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Isometric +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.FunctionTopology + +/-! +# Quantum relative entropy + +For density operators `ρ, σ : E →L[𝕜] E` on a finite-dimensional inner product space (with +`𝕜 = ℂ` in practice; see `quantumRelativeEntropy`'s docstring for the RCLike parametrization +details), the **(Umegaki) quantum relative entropy** of `ρ` with respect to `σ` is + +`D(ρ ‖ σ) := re tr(ρ log ρ) - re tr(ρ log σ)` + +where `log` denotes the operator logarithm via the continuous functional calculus. It is +finite whenever `σ` has all-positive eigenvalues (so that `log σ` is defined on the spectrum) +and is the quantum analogue of the classical Kullback–Leibler divergence. + +We define it as a real-valued function on arbitrary continuous linear operators, with a +junk-value pattern: when `ρ`, `σ` are not density operators (or `σ` has a zero eigenvalue, +making `log σ` ill-defined), the expression still parses but carries no quantum-information +meaning. + +## Main definitions + +- `ContinuousLinearMap.quantumRelativeEntropy : (E →L[ℂ] E) → (E →L[ℂ] E) → ℝ` + +## Main results + +- `IsDensityOp.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub`: the equivalent form + `D(ρ ‖ σ) = -S(ρ) - re tr((cfc log σ) ∘ ρ)` for `ρ` density with positive spectrum. +- `IsDensityOp.quantumRelativeEntropy_self`: `D(ρ ‖ ρ) = 0`. +- `IsDensityOp.quantumRelativeEntropy_nonneg`: **Klein–Gibbs inequality** — `D(ρ ‖ σ) ≥ 0` + for density `ρ, σ` with `σ` positive-spectrum. Immediate corollary of operator Klein's + inequality (`vonNeumannEntropy_le_neg_re_trace_cfc_log_comp`). + +## Joint convexity (Lindblad's theorem) + +- `ContinuousLinearMap.convexOn_quantumRelativeEntropy`: **Lindblad's theorem** — `D(ρ ‖ σ)` + is jointly convex on pairs of strictly positive operators on `EuclideanSpace ℂ ι`. Proved as + the `p → 0⁺` limit of the jointly convex approximants `F_p` (the Lieb trace form + `concaveAt_trace` gives the convexity of `F_p`; the trace-rate limit + `tendsto_quantumRelativeEntropyApprox` identifies the limit). + +## Tensor additivity (§2.37 P3.c) + +- `IsDensityOp.quantumRelativeEntropy_tensorMap`: + `D(ρ₁⊗ρ₂ ‖ σ₁⊗σ₂) = D(ρ₁‖σ₁) + D(ρ₂‖σ₂)` for density operators on abstract finite-dim + complex Hilbert spaces. Uses `IsSelfAdjoint.cfc_log_tensorMap` (the tensor-product log + identity) + `LinearMap.trace_tensorProduct'` + density-op trace-1. +-/ + +@[expose] public section + +open scoped Topology +open scoped InnerProductSpace TensorProduct + +namespace ContinuousLinearMap + +section RCLike + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [CompleteSpace E] + [Algebra ℝ (E →L[𝕜] E)] [IsScalarTower ℝ 𝕜 (E →L[𝕜] E)] + [ContinuousFunctionalCalculus ℝ (E →L[𝕜] E) IsSelfAdjoint] + +/-- The **(Umegaki) quantum relative entropy** of `ρ` with respect to `σ`: +`D(ρ ‖ σ) := re tr(ρ log ρ) - re tr(ρ log σ)`, where the operator logarithm is taken via the +continuous functional calculus. Junk-valued (still parses but carries no quantum-information +meaning) when the arguments are not density operators or `σ` has a zero eigenvalue. + +Stated RCLike-parametrically with explicit `Algebra ℝ` + `IsScalarTower` + `CFC ℝ` instance +hypotheses (the canonical `StarOrder.lean` template). +The hypotheses synthesize automatically for `𝕜 = ℂ`. For `𝕜 = ℝ` they would require a +real-CFC framework which is currently absent from Mathlib. -/ +noncomputable def quantumRelativeEntropy (ρ σ : E →L[𝕜] E) : ℝ := + RCLike.re (LinearMap.trace 𝕜 E ((cfc Real.log ρ).toLinearMap ∘ₗ ρ.toLinearMap)) - + RCLike.re (LinearMap.trace 𝕜 E ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap)) + +omit [FiniteDimensional 𝕜 E] [IsScalarTower ℝ 𝕜 (E →L[𝕜] E)] in +/-- Unfold of `quantumRelativeEntropy` to the two-term trace expression. -/ +theorem quantumRelativeEntropy_def (ρ σ : E →L[𝕜] E) : + quantumRelativeEntropy ρ σ = + RCLike.re (LinearMap.trace 𝕜 E ((cfc Real.log ρ).toLinearMap ∘ₗ ρ.toLinearMap)) - + RCLike.re (LinearMap.trace 𝕜 E ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap)) := + rfl + +omit [FiniteDimensional 𝕜 E] [IsScalarTower ℝ 𝕜 (E →L[𝕜] E)] in +/-- `D(ρ ‖ ρ) = 0`: the relative entropy of any operator against itself vanishes (true +unconditionally from the definition's `tr(X) - tr(X)` shape). -/ +@[simp] theorem quantumRelativeEntropy_self (ρ : E →L[𝕜] E) : + quantumRelativeEntropy ρ ρ = 0 := + sub_self _ + +end RCLike + +section Complex + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- `D(ρ ‖ σ) = -S(ρ) - re tr((cfc log σ) ∘ ρ)` for *any* density `ρ` (no positivity needed). +Combines `re_trace_cfc_log_self_eq_neg_vonNeumannEntropy` with the definition. -/ +theorem IsDensityOp.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub + {ρ σ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) : + quantumRelativeEntropy ρ σ = -ρ.vonNeumannEntropy - + RCLike.re (LinearMap.trace ℂ E ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap)) := by + rw [quantumRelativeEntropy_def, hρ.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy] + +/-- **Klein–Gibbs inequality**: the quantum relative entropy of density operators is +non-negative. For density `ρ, σ : E →L[ℂ] E` with `σ`'s eigenvalues all positive, +`D(ρ ‖ σ) ≥ 0`. Immediate corollary of operator Klein's inequality +(`vonNeumannEntropy_le_neg_re_trace_cfc_log_comp`) plus the self-trace expansion +(`re_trace_cfc_log_self_eq_neg_vonNeumannEntropy`). -/ +theorem IsDensityOp.quantumRelativeEntropy_nonneg {ρ σ : E →L[ℂ] E} + (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + 0 ≤ quantumRelativeEntropy ρ σ := by + rw [hρ.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub, sub_nonneg] + linarith [hρ.vonNeumannEntropy_le_neg_re_trace_cfc_log_comp hσ hσ_pos] + +section ConjInvariance + +-- `IsScalarTower ℝ ℂ (E →L[ℂ] E)` is mathematically valid but not a global instance for abstract +-- `E` (it is the RCLike section's standing assumption); `StarAlgHom.map_cfc` requires it +-- explicitly. It synthesizes for the concrete `EuclideanSpace ℂ ι` consumers (DPI). +variable [IsScalarTower ℝ ℂ (E →L[ℂ] E)] + +/-- **Unitary invariance of the quantum relative entropy.** For a linear isometry equivalence +`e : E ≃ₗᵢ[ℂ] F` (a unitary, possibly between different spaces) and self-adjoint `ρ, σ` whose +spectra avoid `0` (so `log` is defined), `D(e ρ e⁻¹ ‖ e σ e⁻¹) = D(ρ ‖ σ)`. Sibling of +`vonNeumannEntropy_conjStarAlgEquiv` / `traceDistance_conjStarAlgEquiv`; the load-bearer for the +partial-trace DPI (twirl) argument, and — in its cross-space form — for transporting the Lindblad +joint convexity to abstract finite-dimensional spaces. Each trace term is preserved by +`conjStarAlgEquiv_cfc_real_log` + `conjStarAlgEquiv` multiplicativity + `trace_conjStarAlgEquiv`. -/ +theorem quantumRelativeEntropy_conjStarAlgEquiv + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] [IsScalarTower ℝ ℂ (F →L[ℂ] F)] (e : E ≃ₗᵢ[ℂ] F) {ρ σ : E →L[ℂ] E} + (hρ : IsSelfAdjoint ρ) (hρc : ContinuousOn Real.log (spectrum ℝ ρ)) + (hσ : IsSelfAdjoint σ) (hσc : ContinuousOn Real.log (spectrum ℝ σ)) : + quantumRelativeEntropy (e.conjStarAlgEquiv ρ) (e.conjStarAlgEquiv σ) = + quantumRelativeEntropy ρ σ := by + rw [quantumRelativeEntropy_def, quantumRelativeEntropy_def, + e.conjStarAlgEquiv_cfc_real_log hρ hρc, e.conjStarAlgEquiv_cfc_real_log hσ hσc] + congr 1 <;> + rw [← ContinuousLinearMap.toLinearMap_comp, ← ContinuousLinearMap.mul_def, ← map_mul, + ContinuousLinearMap.mul_def, ContinuousLinearMap.trace_conjStarAlgEquiv, + ContinuousLinearMap.toLinearMap_comp] + +end ConjInvariance + +/-! ### Tensor additivity -/ + +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + [CompleteSpace F] + +omit [CompleteSpace E] [CompleteSpace F] in +/-- **Trace of tensor-product composition factors** (CLM, ℂ-finite-dim): for any +`A, C : E →L[ℂ] E` and `B, D : F →L[ℂ] F`, +`tr((mapL A B) ∘ (mapL C D)) = tr(A ∘ C) * tr(B ∘ D)`. Direct consequence of +`TensorProduct.map_comp` (composition factors through `TensorProduct.map`) and +`LinearMap.trace_tensorProduct'` (trace of tensor map is product of traces). -/ +theorem trace_mapL_comp_mapL + (A C : E →L[ℂ] E) (B D : F →L[ℂ] F) : + LinearMap.trace ℂ (E ⊗[ℂ] F) + ((TensorProduct.mapL A B).toLinearMap ∘ₗ (TensorProduct.mapL C D).toLinearMap) = + LinearMap.trace ℂ E (A.toLinearMap ∘ₗ C.toLinearMap) * + LinearMap.trace ℂ F (B.toLinearMap ∘ₗ D.toLinearMap) := by + rw [TensorProduct.toLinearMap_mapL, TensorProduct.toLinearMap_mapL, + ← TensorProduct.map_comp, LinearMap.trace_tensorProduct'] + +/-- **A tensor product of density operators is a density operator.** Positivity from +`TensorProduct.mapL_nonneg`; trace `1` from `trace (ρ₁ ⊗ ρ₂) = tr ρ₁ · tr ρ₂ = 1`. The +density-operator companion of `mapL_nonneg` / `mapL_isStrictlyPositive`. -/ +theorem IsDensityOp.mapL {ρ₁ : E →L[ℂ] E} {ρ₂ : F →L[ℂ] F} + (hρ₁ : ρ₁.IsDensityOp) (hρ₂ : ρ₂.IsDensityOp) : (TensorProduct.mapL ρ₁ ρ₂).IsDensityOp := by + refine ⟨nonneg_iff_isPositive.mp (TensorProduct.mapL_nonneg hρ₁.nonneg hρ₂.nonneg), ?_⟩ + rw [TensorProduct.toLinearMap_mapL, LinearMap.trace_tensorProduct', hρ₁.trace_eq_one, + hρ₂.trace_eq_one, mul_one] + +/-- **Binary tensor-product additivity of the quantum relative entropy.** For density +operators `ρ₁, σ₁ : E →L[ℂ] E` and `ρ₂, σ₂ : F →L[ℂ] F` with strictly positive eigenvalues: + + `D(ρ₁ ⊗ ρ₂ ‖ σ₁ ⊗ σ₂) = D(ρ₁ ‖ σ₁) + D(ρ₂ ‖ σ₂)`. + +Uses `IsSelfAdjoint.cfc_log_tensorMap` to expand `log(ρ₁ ⊗ ρ₂) = log ρ₁ ⊗ I + I ⊗ log ρ₂` +(and likewise for σ), then distributes the trace via `trace_mapL_comp_mapL` and absorbs +`tr(ρᵢ) = 1` from `IsDensityOp.trace_eq_one`. +-/ +theorem IsDensityOp.quantumRelativeEntropy_tensorMap + {ρ₁ σ₁ : E →L[ℂ] E} (hρ₁ : ρ₁.IsDensityOp) + (hρ₁_pos : ∀ i, 0 < hρ₁.isSymmetric.eigenvalues rfl i) + {ρ₂ σ₂ : F →L[ℂ] F} (hρ₂ : ρ₂.IsDensityOp) + (hρ₂_pos : ∀ j, 0 < hρ₂.isSymmetric.eigenvalues rfl j) + (hσ₁ : σ₁.IsDensityOp) (hσ₁_pos : ∀ i, 0 < hσ₁.isSymmetric.eigenvalues rfl i) + (hσ₂ : σ₂.IsDensityOp) (hσ₂_pos : ∀ j, 0 < hσ₂.isSymmetric.eigenvalues rfl j) : + quantumRelativeEntropy (TensorProduct.mapL ρ₁ ρ₂) (TensorProduct.mapL σ₁ σ₂) = + quantumRelativeEntropy ρ₁ σ₁ + quantumRelativeEntropy ρ₂ σ₂ := by + have h_log_ρ : cfc Real.log (TensorProduct.mapL ρ₁ ρ₂) = + TensorProduct.mapL (cfc Real.log ρ₁) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log ρ₂) := + IsSelfAdjoint.cfc_log_tensorMap hρ₁.isPositive.isSelfAdjoint hρ₂.isPositive.isSelfAdjoint + rfl rfl hρ₁_pos hρ₂_pos + have h_log_σ : cfc Real.log (TensorProduct.mapL σ₁ σ₂) = + TensorProduct.mapL (cfc Real.log σ₁) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log σ₂) := + IsSelfAdjoint.cfc_log_tensorMap hσ₁.isPositive.isSelfAdjoint hσ₂.isPositive.isSelfAdjoint + rfl rfl hσ₁_pos hσ₂_pos + simp only [quantumRelativeEntropy_def, h_log_ρ, h_log_σ, ContinuousLinearMap.toLinearMap_add, + LinearMap.add_comp, map_add, trace_mapL_comp_mapL, + ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, LinearMap.id_comp, + hρ₁.trace_eq_one, hρ₂.trace_eq_one, mul_one, one_mul] + ring + +end Complex + +section Lindblad + +open scoped ComplexOrder +open Filter + +variable {ι : Type*} [Fintype ι] + +/-- The Lindblad approximant `F_p(A, B) = p⁻¹ (re tr A - re tr (A^{1-p} B^p))` to the quantum +relative entropy. -/ +noncomputable def quantumRelativeEntropyApprox (p : ℝ) + (X : (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) × + (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)) : ℝ := + p⁻¹ * (RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) X.1.toLinearMap) - + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((X.1 ^ ((1 : ℝ) - p)) ∘L (X.2 ^ p)).toLinearMap)) + +/-- Unfold lemma for the Lindblad approximant. -/ +theorem quantumRelativeEntropyApprox_def (p : ℝ) + (X : (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) × + (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)) : + quantumRelativeEntropyApprox p X = + p⁻¹ * (RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) X.1.toLinearMap) - + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + ((X.1 ^ ((1 : ℝ) - p)) ∘L (X.2 ^ p)).toLinearMap)) := + rfl + +/-- `a^{1-p} a^p = a` for a strictly positive operator (the numerator-factoring identity behind +the Lindblad limit). -/ +theorem rpow_one_sub_mul_rpow_self {A : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hA : IsStrictlyPositive A) (p : ℝ) : A ^ (1 - p) * A ^ p = A := by + rw [← CFC.rpow_add hA.isUnit, sub_add_cancel, CFC.rpow_one A hA.nonneg] + +section RealTrace + +variable {H : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] + [NormedSpace ℝ H] [IsScalarTower ℝ ℂ H] + +/-- `re tr` is `ℝ`-homogeneous in the operator: `re tr (r • X) = r * re tr X`. -/ +theorem re_trace_smul (r : ℝ) (X : H →L[ℂ] H) : + RCLike.re (LinearMap.trace ℂ H (r • X : _).toLinearMap) = + r * RCLike.re (LinearMap.trace ℂ H X.toLinearMap) := by + have hsmul : (r • X : H →L[ℂ] H) = (r : ℂ) • X := by + ext x + change r • X x = (r : ℂ) • X x + exact RCLike.real_smul_eq_coe_smul (K := ℂ) r (X x) + rw [hsmul, ContinuousLinearMap.toLinearMap_smul, map_smul] + simp + +omit [NormedSpace ℝ H] [IsScalarTower ℝ ℂ H] in +/-- `re tr` is additive on differences: `re tr (X - Y) = re tr X - re tr Y`. -/ +theorem re_trace_sub (X Y : H →L[ℂ] H) : + RCLike.re (LinearMap.trace ℂ H (X - Y : _).toLinearMap) = + RCLike.re (LinearMap.trace ℂ H X.toLinearMap) - + RCLike.re (LinearMap.trace ℂ H Y.toLinearMap) := by + rw [ContinuousLinearMap.toLinearMap_sub, map_sub, map_sub] + +/-- `re tr` is `ℝ`-linear in the operator: `re tr (a • C + b • D) = a re tr C + b re tr D`. -/ +theorem re_trace_add_smul (a b : ℝ) (C D : H →L[ℂ] H) : + RCLike.re (LinearMap.trace ℂ H (a • C + b • D : _).toLinearMap) = + a * RCLike.re (LinearMap.trace ℂ H C.toLinearMap) + + b * RCLike.re (LinearMap.trace ℂ H D.toLinearMap) := by + rw [ContinuousLinearMap.toLinearMap_add, map_add, map_add, re_trace_smul, re_trace_smul] + +end RealTrace + +theorem convexOn_quantumRelativeEntropyApprox {p : ℝ} (hp : 0 < p) (hp1 : p ≤ 1) : + ConvexOn ℝ ({a | IsStrictlyPositive a} ×ˢ {a | IsStrictlyPositive a}) + (quantumRelativeEntropyApprox (ι := ι) p) := by + refine ⟨convex_isStrictlyPositive.prod convex_isStrictlyPositive, ?_⟩ + rintro ⟨A₁, B₁⟩ ⟨hA₁, hB₁⟩ ⟨A₂, B₂⟩ ⟨hA₂, hB₂⟩ a b ha hb hab + have key := TensorProduct.concaveAt_trace + (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (q := 1 - p) (r := p) + (by linarith) hp.le (by linarith) hA₁ hA₂ hB₁ hB₂ ha hb hab + simp only [ContinuousLinearMap.one_def, ContinuousLinearMap.adjoint_id, + ContinuousLinearMap.id_comp, smul_eq_mul] at key + simp only [quantumRelativeEntropyApprox_def, Prod.fst_add, Prod.snd_add, Prod.smul_fst, + Prod.smul_snd, re_trace_add_smul, smul_eq_mul] + nlinarith [key, mul_le_mul_of_nonneg_left key (by positivity : (0:ℝ) ≤ p⁻¹)] + +/-- **Lindblad limit form of the quantum relative entropy** (the trace-rate limit). For strictly +positive `A, B`, the approximants `F_p(A, B)` converge to `D(A ‖ B)` as `p → 0⁺`: + + `lim_{p → 0⁺} p⁻¹ (tr A - tr (A^{1-p} B^p)) = re tr (A log A) - re tr (A log B)`. + +The numerator factors as `tr (A^{1-p} (A^p - B^p))`, so the rate is the product of the +continuous-in-exponent factor `A^{1-p} → A` (`CFC.continuous_const_rpow`) and the difference of +two single-operator logarithm limits `p⁻¹ (A^p - B^p) → log A - log B` +(`CFC.tendsto_cfc_rpow_sub_one_log`); trace-continuity (`ContinuousLinearMap.continuous_trace`) +then transports the operator limit to the scalar. -/ +theorem tendsto_quantumRelativeEntropyApprox + {A B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hA : IsStrictlyPositive A) (hB : IsStrictlyPositive B) : + Tendsto (fun p : ℝ ↦ quantumRelativeEntropyApprox p (A, B)) (𝓝[>] 0) + (𝓝 (quantumRelativeEntropy A B)) := by + -- factor 1: `A^{1-p} → A` + have h1 : Tendsto (fun p : ℝ ↦ A ^ (1 - p)) (𝓝[>] 0) (𝓝 A) := by + have h : Tendsto (fun p : ℝ ↦ A ^ (1 - p)) (𝓝[>] 0) (𝓝 (A ^ (1 - (0 : ℝ)))) := + ((CFC.continuous_const_rpow hA).comp (continuous_const.sub continuous_id)).continuousWithinAt + simpa [CFC.rpow_one A hA.nonneg] using h + -- factor 2: `p⁻¹ (A^p - B^p) → log A - log B` + have h2 : Tendsto (fun p : ℝ ↦ p⁻¹ • (A ^ p - B ^ p)) (𝓝[>] 0) + (𝓝 (CFC.log A - CFC.log B)) := by + have hAlim := (CFC.tendsto_cfc_rpow_sub_one_log (a := A) hA).congr fun p ↦ + CFC.cfc_p_inv_rpow_sub_one_eq p hA + have hBlim := (CFC.tendsto_cfc_rpow_sub_one_log (a := B) hB).congr fun p ↦ + CFC.cfc_p_inv_rpow_sub_one_eq p hB + exact (hAlim.sub hBlim).congr fun p ↦ by rw [← smul_sub]; congr 1; abel + -- the operator-valued limit and its continuous image under `re tr` + have hG := h1.mul h2 + have hcont : Continuous (fun X : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι ↦ + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) X.toLinearMap)) := + RCLike.continuous_re.comp ContinuousLinearMap.continuous_trace + -- the approximant equals `re tr` of the operator-valued function + have hEq : ∀ p : ℝ, quantumRelativeEntropyApprox p (A, B) = + RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (A ^ (1 - p) * (p⁻¹ • (A ^ p - B ^ p))).toLinearMap) := by + intro p + rw [mul_smul_comm, mul_sub, rpow_one_sub_mul_rpow_self hA, re_trace_smul, re_trace_sub, + quantumRelativeEntropyApprox_def] + rfl + -- the limit point is the quantum relative entropy + have hqre : RCLike.re (LinearMap.trace ℂ (EuclideanSpace ℂ ι) + (A * (CFC.log A - CFC.log B)).toLinearMap) = quantumRelativeEntropy A B := by + rw [mul_sub, re_trace_sub, quantumRelativeEntropy_def] + congr 1 <;> + (rw [ContinuousLinearMap.toLinearMap_mul, LinearMap.trace_mul_comm]; rfl) + rw [← hqre] + exact ((hcont.tendsto _).comp hG).congr fun p ↦ (hEq p).symm + +/-- **Lindblad's theorem**: the quantum relative entropy `D(ρ ‖ σ) = re tr(ρ log ρ) - +re tr(ρ log σ)` is **jointly convex** on pairs of strictly positive operators. Obtained as the +pointwise `p → 0⁺` limit of the jointly convex approximants `F_p` +(`convexOn_quantumRelativeEntropyApprox` + `tendsto_quantumRelativeEntropyApprox`), via +`ConvexOn.of_tendsto_pointwise_on`. -/ +theorem convexOn_quantumRelativeEntropy : + ConvexOn ℝ ({a | IsStrictlyPositive a} ×ˢ {a | IsStrictlyPositive a}) + (fun X : (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) × + (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) ↦ quantumRelativeEntropy X.1 X.2) := by + have hev : ∀ᶠ p : ℝ in 𝓝[>] 0, 0 < p ∧ p ≤ 1 := + eventually_mem_nhdsWithin.mono (fun p hp ↦ hp) |>.and + ((eventually_le_nhds (by norm_num : (0 : ℝ) < 1)).filter_mono nhdsWithin_le_nhds) + refine ConvexOn.of_tendsto_pointwise_on (l := 𝓝[>] (0 : ℝ)) + (F := quantumRelativeEntropyApprox) + (convex_isStrictlyPositive.prod convex_isStrictlyPositive) ?_ ?_ + · filter_upwards [hev] with p hp using convexOn_quantumRelativeEntropyApprox hp.1 hp.2 + · rintro ⟨A, B⟩ ⟨hA, hB⟩ + exact tendsto_quantumRelativeEntropyApprox hA hB + +/-- **Joint convexity of the quantum relative entropy, binary form** (the workhorse for SSA / data +processing): for strictly positive `ρ₁, ρ₂, σ₁, σ₂` and convex weights `t + s = 1`, + + `D(t ρ₁ + s ρ₂ ‖ t σ₁ + s σ₂) ≤ t D(ρ₁ ‖ σ₁) + s D(ρ₂ ‖ σ₂)`. + +The pointwise unfolding of `convexOn_quantumRelativeEntropy`. Density-operator consumers obtain the +strict-positivity hypotheses from `IsDensityOp.isStrictlyPositive` (full-rank states). -/ +theorem quantumRelativeEntropy_jointly_convex + {ρ₁ ρ₂ σ₁ σ₂ : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hρ₁ : IsStrictlyPositive ρ₁) (hρ₂ : IsStrictlyPositive ρ₂) + (hσ₁ : IsStrictlyPositive σ₁) (hσ₂ : IsStrictlyPositive σ₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + quantumRelativeEntropy (t • ρ₁ + s • ρ₂) (t • σ₁ + s • σ₂) ≤ + t * quantumRelativeEntropy ρ₁ σ₁ + s * quantumRelativeEntropy ρ₂ σ₂ := by + simpa [Prod.smul_mk, Prod.mk_add_mk, smul_eq_mul] using + convexOn_quantumRelativeEntropy.2 (Set.mk_mem_prod hρ₁ hσ₁) (Set.mk_mem_prod hρ₂ hσ₂) ht hs hts + +end Lindblad + +/-! ### Joint convexity on abstract finite-dimensional spaces + +The Lindblad convexity (`convexOn_quantumRelativeEntropy`) is proved on `EuclideanSpace ℂ ι` +(the pinning is essential — Lieb's Theorem 1 routes through `EuclideanSpace.transposeOp`). For the +partial-trace data-processing inequality we need it on an abstract finite-dimensional space +`E ⊗ F`. We transport it along the orthonormal-basis isometry `E ≃ₗᵢ EuclideanSpace ℂ ι` using +unitary invariance of `D`. -/ +section AbstractConvexity + +-- `continuousOn_log_spectrum` is general (no relative-entropy content); upstream-relocation +-- candidate → `CFC.lean`. (`conjStarAlgEquiv_isStrictlyPositive_iff` now lives in `Positive.lean`, +-- beside `conjStarAlgEquiv_isPositive_iff`.) +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [IsScalarTower ℝ ℂ (E →L[ℂ] E)] + +omit [FiniteDimensional ℂ E] [IsScalarTower ℝ ℂ (E →L[ℂ] E)] in +/-- `log` is continuous on the spectrum of a strictly positive operator (which is `⊆ (0, ∞)`). -/ +theorem IsStrictlyPositive.continuousOn_log_spectrum {T : E →L[ℂ] E} (hT : IsStrictlyPositive T) : + ContinuousOn Real.log (spectrum ℝ T) := + Real.continuousOn_log.mono fun _ hx ↦ (hT.spectrum_pos hx).ne' + +/-- **Unitary invariance of `D`, no positivity needed.** For self-adjoint `ρ, σ` on a +finite-dimensional space, conjugating both by a linear isometry equivalence leaves the quantum +relative entropy unchanged. The `log`-continuity premises of the base `conjStarAlgEquiv` lemma are +discharged by `IsSelfAdjoint.continuousOn_log_spectrum` (the spectrum is finite). The canonical +invariance engine; also the form used to transport `D` across a Stinespring +isometry-onto-its-range. -/ +theorem quantumRelativeEntropy_conjStarAlgEquiv_of_isSelfAdjoint + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] [IsScalarTower ℝ ℂ (F →L[ℂ] F)] (e : E ≃ₗᵢ[ℂ] F) {ρ σ : E →L[ℂ] E} + (hρ : IsSelfAdjoint ρ) (hσ : IsSelfAdjoint σ) : + quantumRelativeEntropy (e.conjStarAlgEquiv ρ) (e.conjStarAlgEquiv σ) = + quantumRelativeEntropy ρ σ := + quantumRelativeEntropy_conjStarAlgEquiv e hρ (IsSelfAdjoint.continuousOn_log_spectrum hρ) hσ + (IsSelfAdjoint.continuousOn_log_spectrum hσ) + +/-- Unitary invariance of `D` for strictly positive operators — the strict-positivity convenience +form of `quantumRelativeEntropy_conjStarAlgEquiv_of_isSelfAdjoint` (`IsStrictlyPositive` ⟹ +`IsSelfAdjoint`). -/ +theorem quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] [IsScalarTower ℝ ℂ (F →L[ℂ] F)] (e : E ≃ₗᵢ[ℂ] F) {ρ σ : E →L[ℂ] E} + (hρ : IsStrictlyPositive ρ) (hσ : IsStrictlyPositive σ) : + quantumRelativeEntropy (e.conjStarAlgEquiv ρ) (e.conjStarAlgEquiv σ) = + quantumRelativeEntropy ρ σ := + quantumRelativeEntropy_conjStarAlgEquiv_of_isSelfAdjoint e hρ.isSelfAdjoint hσ.isSelfAdjoint + +section IsometryConj + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [FiniteDimensional ℂ H] + [CompleteSpace H] + +variable [IsScalarTower ℝ ℂ (H →L[ℂ] H)] + +/-- **Invariance of the quantum relative entropy under conjugation by an isometry.** For +`V : E →L[ℂ] H` an isometry (`V† V = 1`) and self-adjoint `ρ, σ`, +`D(V ρ V† ‖ V σ V†) = D(ρ ‖ σ)`. The non-surjective companion to the unitary-equivalence form +`quantumRelativeEntropy_conjStarAlgEquiv_of_isSelfAdjoint`: `V` need not be onto, because the zero +eigenspace `(ran V)ᗮ` of `V ρ V†` is harmless (`Real.log 0 = 0`, via `cfc_conj_isometry`) and trace +cyclicity (`trace_conj_isometry`) collapses the `V† V`. The dilation half of the Stinespring +channel-DPI: with the partial-trace DPI it yields `D(Φρ ‖ Φσ) ≤ D(ρ ‖ σ)`. -/ +theorem quantumRelativeEntropy_conj_isometry {V : E →L[ℂ] H} (hV : V.adjoint ∘L V = 1) + {ρ σ : E →L[ℂ] E} (hρ : IsSelfAdjoint ρ) (hσ : IsSelfAdjoint σ) : + quantumRelativeEntropy (V ∘L ρ ∘L V.adjoint) (V ∘L σ ∘L V.adjoint) + = quantumRelativeEntropy ρ σ := by + have hterm : ∀ {X : E →L[ℂ] E}, IsSelfAdjoint X → + LinearMap.trace ℂ H ((cfc Real.log (V ∘L X ∘L V.adjoint)).toLinearMap + ∘ₗ (V ∘L ρ ∘L V.adjoint).toLinearMap) + = LinearMap.trace ℂ E ((cfc Real.log X).toLinearMap ∘ₗ ρ.toLinearMap) := by + intro X hX + rw [cfc_conj_isometry hV hX Real.log_zero, ← ContinuousLinearMap.toLinearMap_comp, + ← conjIsometryₙ_apply hV, ← conjIsometryₙ_apply hV, ← ContinuousLinearMap.mul_def, + ← map_mul, conjIsometryₙ_apply, trace_conj_isometry hV, ContinuousLinearMap.mul_def, + ContinuousLinearMap.toLinearMap_comp] + rw [quantumRelativeEntropy_def, quantumRelativeEntropy_def, hterm hρ, hterm hσ] + +end IsometryConj + +/-- **n-ary joint convexity of the quantum relative entropy** on an abstract finite-dimensional +complex inner product space (`EuclideanSpace`-form transported along an orthonormal basis): +`D(∑ wₖ ρₖ ‖ ∑ wₖ σₖ) ≤ ∑ wₖ D(ρₖ ‖ σₖ)` for strictly positive `ρₖ, σₖ` and convex weights `wₖ`. +The partial-trace data-processing inequality applies this on `E ⊗ F`. -/ +theorem quantumRelativeEntropy_jointly_convex_sum {κ : Type*} (t : Finset κ) + {ρ σ : κ → E →L[ℂ] E} {w : κ → ℝ} + (hρ : ∀ k ∈ t, IsStrictlyPositive (ρ k)) (hσ : ∀ k ∈ t, IsStrictlyPositive (σ k)) + (hw : ∀ k ∈ t, 0 ≤ w k) (hsum : ∑ k ∈ t, w k = 1) : + quantumRelativeEntropy (∑ k ∈ t, w k • ρ k) (∑ k ∈ t, w k • σ k) ≤ + ∑ k ∈ t, w k * quantumRelativeEntropy (ρ k) (σ k) := by + set Φ := (stdOrthonormalBasis ℂ E).repr with hΦ + have : IsScalarTower ℝ ℂ (EuclideanSpace ℂ (Fin (Module.finrank ℂ E)) →L[ℂ] + EuclideanSpace ℂ (Fin (Module.finrank ℂ E))) := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl + have hsmul : ∀ (c : ℝ) (A : E →L[ℂ] E), + Φ.conjStarAlgEquiv (c • A) = c • Φ.conjStarAlgEquiv A := fun c A ↦ by + rw [← algebraMap_smul ℂ c A, map_smul, algebraMap_smul] + have hρs : IsStrictlyPositive (∑ k ∈ t, w k • ρ k) := + (convex_isStrictlyPositive (A := E →L[ℂ] E)).sum_mem hw hsum hρ + have hσs : IsStrictlyPositive (∑ k ∈ t, w k • σ k) := + (convex_isStrictlyPositive (A := E →L[ℂ] E)).sum_mem hw hsum hσ + rw [← quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive Φ hρs hσs, map_sum, map_sum] + simp_rw [hsmul] + have hEuc := convexOn_quantumRelativeEntropy.map_sum_le + (p := fun k ↦ (Φ.conjStarAlgEquiv (ρ k), Φ.conjStarAlgEquiv (σ k))) hw hsum + fun k hk ↦ Set.mk_mem_prod (Φ.conjStarAlgEquiv_isStrictlyPositive_iff.mpr (hρ k hk)) + (Φ.conjStarAlgEquiv_isStrictlyPositive_iff.mpr (hσ k hk)) + simp only [Prod.smul_mk, Prod.fst_sum, Prod.snd_sum, smul_eq_mul] at hEuc + refine hEuc.trans (le_of_eq (Finset.sum_congr rfl fun k hk ↦ ?_)) + rw [quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive Φ (hρ k hk) (hσ k hk)] + +/-- **Monotonicity of the quantum relative entropy under a mixed-unitary (random-unitary) +channel.** For a family `e : κ → (E ≃ₗᵢ[ℂ] E)` of unitaries, strictly positive operators `ρ, σ`, +and convex weights `w` on a `Finset t` (`w k ≥ 0`, `∑ w k = 1`), +`D(∑ₖ wₖ • eₖ ρ eₖ⁻¹ ‖ ∑ₖ wₖ • eₖ σ eₖ⁻¹) ≤ D(ρ ‖ σ)`. + +Joint convexity (`quantumRelativeEntropy_jointly_convex_sum`) bounds the left-hand side by +`∑ₖ wₖ · D(eₖ ρ eₖ⁻¹ ‖ eₖ σ eₖ⁻¹)`, and each summand equals `D(ρ ‖ σ)` by unitary invariance +(`quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive`); as the weights sum to `1`, the +weighted sum then collapses to `D(ρ ‖ σ)`. Strict positivity of each conjugate `eₖ ρ eₖ⁻¹` — +required by the convexity lemma — is `LinearIsometryEquiv.conjStarAlgEquiv_isStrictlyPositive_iff`. + +This is the step that turns joint convexity into a data-processing inequality. The completely +depolarizing partial-trace twirl `partialTrace(·) ⊗ I/d` is a mixed-unitary average over a unitary +`1`-design (N&C Ex 11.19), so the monotonicity of the relative entropy under partial trace — the +bridge to the strong subadditivity of the von Neumann entropy (N&C Thm 11.14) — is an instance of +this lemma. -/ +theorem quantumRelativeEntropy_sum_conjStarAlgEquiv_le {κ : Type*} (t : Finset κ) + (e : κ → (E ≃ₗᵢ[ℂ] E)) {ρ σ : E →L[ℂ] E} {w : κ → ℝ} + (hρ : IsStrictlyPositive ρ) (hσ : IsStrictlyPositive σ) + (hw : ∀ k ∈ t, 0 ≤ w k) (hsum : ∑ k ∈ t, w k = 1) : + quantumRelativeEntropy (∑ k ∈ t, w k • (e k).conjStarAlgEquiv ρ) + (∑ k ∈ t, w k • (e k).conjStarAlgEquiv σ) ≤ quantumRelativeEntropy ρ σ := by + refine (quantumRelativeEntropy_jointly_convex_sum t + (fun k _ ↦ (e k).conjStarAlgEquiv_isStrictlyPositive_iff.mpr hρ) + (fun k _ ↦ (e k).conjStarAlgEquiv_isStrictlyPositive_iff.mpr hσ) hw hsum).trans (le_of_eq ?_) + have hterm : ∀ k ∈ t, w k * quantumRelativeEntropy ((e k).conjStarAlgEquiv ρ) + ((e k).conjStarAlgEquiv σ) = w k * quantumRelativeEntropy ρ σ := fun k _ ↦ by + rw [quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive (e k) hρ hσ] + rw [Finset.sum_congr rfl hterm, ← Finset.sum_mul, hsum, one_mul] + +end AbstractConvexity + +/-! ### Support condition + +The precise precondition under which `D(ρ ‖ σ)` (the `cfc`-based definition) is meaningful is the +**support condition** `supp ρ ⊆ supp σ`. For positive operators `supp = (ker)ᗮ`, so this is the +operator-kernel inclusion `ker σ ≤ ker ρ`: `ρ` carries no weight where `σ` vanishes, exactly the +regime in which `Real.log 0 = 0` on `ker σ` is harmless. +It relaxes the faithful (`IsStrictlyPositive σ`) hypothesis of the DPI engine. -/ + +section SupportCondition + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [CompleteSpace E] + +/-- The support condition is preserved by unitary conjugation `e (·) e⁻¹`. The load-bearer for +transporting `D(ρ ‖ σ)`'s meaningfulness along the Stinespring isometry (B5c). -/ +theorem HasSupportLE.conjStarAlgEquiv {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] (e : E ≃ₗᵢ[ℂ] F) {ρ σ : E →L[ℂ] E} (h : HasSupportLE ρ σ) : + HasSupportLE (e.conjStarAlgEquiv ρ) (e.conjStarAlgEquiv σ) := by + intro x hx + simp only [LinearMap.mem_ker, ContinuousLinearMap.coe_coe, + LinearIsometryEquiv.conjStarAlgEquiv_apply, ContinuousLinearMap.comp_apply, + ContinuousLinearEquiv.coe_coe, LinearIsometryEquiv.coe_toContinuousLinearEquiv, + EmbeddingLike.map_eq_zero_iff] at hx ⊢ + exact h hx + +/-- The support condition is preserved by conjugation by a (possibly non-surjective) isometry `V` +(`V† V = 1`): `supp ρ ⊆ supp σ ⟹ supp (V ρ V†) ⊆ supp (V σ V†)`. The non-equiv companion to +`HasSupportLE.conjStarAlgEquiv`; transports the meaningfulness of `D` across the Stinespring +isometry (B5c). -/ +theorem HasSupportLE.conj_isometry {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [CompleteSpace F] {V : E →L[ℂ] F} (hV : V.adjoint ∘L V = 1) {ρ σ : E →L[ℂ] E} + (h : HasSupportLE ρ σ) : + HasSupportLE (V ∘L ρ ∘L V.adjoint) (V ∘L σ ∘L V.adjoint) := by + have hVinj : Function.Injective V := Function.LeftInverse.injective (g := V.adjoint) fun y ↦ by + rw [← ContinuousLinearMap.comp_apply, hV, one_apply_eq_self] + intro x hx + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe, ContinuousLinearMap.comp_apply, + ContinuousLinearMap.comp_apply] at hx ⊢ + have hσ0 : V.adjoint x ∈ LinearMap.ker (σ : E →ₗ[ℂ] E) := + LinearMap.mem_ker.mpr (hVinj (by rw [map_zero]; exact hx)) + have hρ0 : ρ (V.adjoint x) = 0 := LinearMap.mem_ker.mp (h hσ0) + rw [hρ0, map_zero] + +/-- **The support condition kills the `ker σ`-block.** If `supp ρ ⊆ supp σ` (`HasSupportLE ρ σ`) +and `σ` is self-adjoint, then `ρ` annihilates the spectral projection `cfc 1_{{0}} σ` onto `ker σ`: +the projection's range lies in `ker σ ⊆ ker ρ`. This is the only place the support condition enters +the relative-entropy continuity limit (plan §3.1). -/ +theorem HasSupportLE.comp_cfc_indicator_zero [FiniteDimensional ℂ E] {ρ σ : E →L[ℂ] E} + (h : HasSupportLE ρ σ) (hσ : IsSelfAdjoint σ) : + ρ * cfc (Set.indicator {0} (1 : ℝ → ℝ)) σ = 0 := by + refine ContinuousLinearMap.ext fun x ↦ ?_ + have hker : cfc (Set.indicator {0} (1 : ℝ → ℝ)) σ x ∈ LinearMap.ker (σ : E →ₗ[ℂ] E) := by + rw [LinearMap.mem_ker] + simpa using DFunLike.congr_fun hσ.self_mul_cfc_indicator_zero x + simpa using h hker + +end SupportCondition + +/-! ### General operator facts: tensor trace and involution positivity + +Two ℂ-finite-dimensional operator lemmas: the trace factorises over `TensorProduct.mapL`, and +`I − cG` is positive for a self-adjoint involution `G` with `c² ≤ 1`. -/ + +section GeneralOperatorFacts + +open scoped ComplexOrder + +/-- **Trace of a tensor-product operator factorises:** `tr (A ⊗ B) = (tr A) · (tr B)`. +The `mapL 1 1` case of `trace_mapL_comp_mapL`. -/ +theorem trace_mapL {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + (A : E →L[ℂ] E) (B : F →L[ℂ] F) : + LinearMap.trace ℂ (TensorProduct ℂ E F) ↑(TensorProduct.mapL A B) = + LinearMap.trace ℂ E ↑A * LinearMap.trace ℂ F ↑B := by + have h := trace_mapL_comp_mapL A 1 B 1 + simpa only [TensorProduct.mapL_one, ContinuousLinearMap.toLinearMap_one, + Module.End.one_eq_id, LinearMap.comp_id] using h + +/-- **`mapL A B` is an involution when `A`, `B` are:** `(A ⊗ B)² = 1` from `A² = 1` and `B² = 1`, +since `mapL` is multiplicative and `mapL 1 1 = 1`. -/ +theorem mapL_mul_mapL_self {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + {A : E →L[ℂ] E} {B : F →L[ℂ] F} (hA : A * A = 1) (hB : B * B = 1) : + TensorProduct.mapL A B * TensorProduct.mapL A B = 1 := by + rw [← TensorProduct.mapL_mul, hA, hB, TensorProduct.mapL_one] + +/-- **`I − cG` is positive for a self-adjoint involution `G` and `c² ≤ 1`.** Writing the projections +`P = ½(I + G)`, `Q = ½(I − G)` (idempotent because `G² = 1`, self-adjoint because `G` is, hence +positive), one has `I − cG = (1 − c)·P + (1 + c)·Q`, a nonnegative combination of positive operators +(`1 ± c ≥ 0` from `c² ≤ 1`). This is the operator-positivity engine behind the high-temperature NMR +thermal states (`I − cZ ≥ 0`). -/ +theorem isPositive_one_sub_smul_of_selfAdjoint_involution {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [CompleteSpace E] {G : E →L[ℂ] E} (hsa : IsSelfAdjoint G) + (hG : G * G = 1) {c : ℝ} (hc : c ^ 2 ≤ 1) : (1 - (c : ℂ) • G).IsPositive := by + have h1sa : IsSelfAdjoint (1 : E →L[ℂ] E) := by rw [isSelfAdjoint_iff, star_one] + have hhalf : IsSelfAdjoint ((2 : ℂ)⁻¹) := by rw [isSelfAdjoint_iff]; simp + have hPsa : IsSelfAdjoint ((2 : ℂ)⁻¹ • ((1 : E →L[ℂ] E) + G)) := by + rw [isSelfAdjoint_iff, star_smul, hhalf.star_eq, star_add, h1sa.star_eq, hsa.star_eq] + have hQsa : IsSelfAdjoint ((2 : ℂ)⁻¹ • ((1 : E →L[ℂ] E) - G)) := by + rw [isSelfAdjoint_iff, star_smul, hhalf.star_eq, star_sub, h1sa.star_eq, hsa.star_eq] + have hPidem : IsIdempotentElem ((2 : ℂ)⁻¹ • ((1 : E →L[ℂ] E) + G)) := by + have h2 : ((1 : E →L[ℂ] E) + G) * (1 + G) = (2 : ℂ) • (1 + G) := by + rw [add_mul, mul_add, mul_add, mul_one, one_mul, mul_one, hG]; module + unfold IsIdempotentElem + rw [smul_mul_smul_comm, h2, smul_smul]; norm_num + have hQidem : IsIdempotentElem ((2 : ℂ)⁻¹ • ((1 : E →L[ℂ] E) - G)) := by + have h2 : ((1 : E →L[ℂ] E) - G) * (1 - G) = (2 : ℂ) • (1 - G) := by + rw [sub_mul, mul_sub, mul_sub, mul_one, one_mul, mul_one, hG]; module + unfold IsIdempotentElem + rw [smul_mul_smul_comm, h2, smul_smul]; norm_num + have hP := (IsIdempotentElem.isPositive_iff_isSelfAdjoint hPidem).mpr hPsa + have hQ := (IsIdempotentElem.isPositive_iff_isSelfAdjoint hQidem).mpr hQsa + have hdecomp : (1 : E →L[ℂ] E) - (c : ℂ) • G + = ((1 - c : ℝ) : ℂ) • ((2 : ℂ)⁻¹ • (1 + G)) + ((1 + c : ℝ) : ℂ) • ((2 : ℂ)⁻¹ • (1 - G)) := by + push_cast; module + rw [hdecomp] + have h1c : (0 : ℝ) ≤ 1 - c := by nlinarith [hc, sq_nonneg (1 - c), sq_nonneg (1 + c)] + have h1c' : (0 : ℝ) ≤ 1 + c := by nlinarith [hc, sq_nonneg (1 - c), sq_nonneg (1 + c)] + exact (hP.smul_of_nonneg (Complex.zero_le_real.mpr h1c)).add + (hQ.smul_of_nonneg (Complex.zero_le_real.mpr h1c')) + +end GeneralOperatorFacts + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyConvexNonfaithful.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyConvexNonfaithful.lean new file mode 100644 index 0000000000..757a371b9d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyConvexNonfaithful.lean @@ -0,0 +1,357 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.NegMulLog +public import Mathlib.Analysis.Complex.Order + +/-! +# Joint convexity of the quantum relative entropy on the finite branch (no faithfulness) + +Lindblad's theorem (`ContinuousLinearMap.convexOn_quantumRelativeEntropy`) establishes the joint +convexity of the quantum relative entropy `D(ρ ‖ σ) = re tr(ρ log ρ) − re tr(ρ log σ)` only on the +open cone of **strictly positive** operators. The goal of this development is to remove the +strict-positivity hypothesis, extending joint convexity to N&C's own **finite branch** — the +**support condition** `supp ρ ⊆ supp σ` (`HasSupportLE ρ σ`, i.e. `ker σ ≤ ker ρ`), on which the +real-valued `cfc`-based `D` equals the true relative entropy — as the faithful form of Nielsen & +Chuang Theorem 11.12 (the strict-positivity form, which excludes rank-deficient `ρ, σ`, becomes a +corollary). + +This file establishes the analytic **engine** for that removal: the identity-shift continuity of the +relative entropy on the finite branch. The joint convexity itself is assembled from it +separately, by the perturbation-and-limit argument that removes faithfulness from strong +subadditivity (N&C Thm 11.14): shift each operator by `ε • 1` (strictly positive for `ε > 0`, since +`A + ε • 1 ≥ ε • 1` for `A ≥ 0`), apply the strict-positivity joint convexity to the shifted family, +and pass to the limit `ε → 0⁺` through + +* `ContinuousLinearMap.tendsto_quantumRelativeEntropy_add_smul_one` — + `D(ρ + ε•1 ‖ σ + ε•1) → D(ρ ‖ σ)` as `ε → 0⁺`, for positive `ρ, σ` with `HasSupportLE ρ σ`. + +Because `ε • 1` commutes with every operator, the shift `Y ↦ Y + ε • 1` stays inside `Y`'s +functional calculus: in the eigenbasis of `Y` the cross trace term +`re tr((log(Y + ε•1)) ∘ (X + ε•1))` is the finite sum `∑ⱼ log(μⱼ + ε)(aⱼ + ε)` with +`aⱼ = re⟨bⱼ, X bⱼ⟩`, and the support condition forces `aⱼ = 0` on the kernel of `Y` (`μⱼ = 0`), so +those terms are the harmless `ε log ε → 0` (`Real.continuous_negMulLog`). Each surviving term +converges by continuity of `log` away from `0`. + +The trace-in-an-arbitrary-eigenbasis identity these build on, +`IsSelfAdjoint.re_trace_cfc_comp_eq_sum_of_apply_eq_smul` +(`re tr((cfc f Y) ∘ X) = ∑ⱼ f(μⱼ) · re⟨bⱼ, X bⱼ⟩`), is a general CFC/trace fact and lives with its +siblings in `ToMathlib.Analysis.InnerProductSpace.CFC`. + +## Main results + +* `ContinuousLinearMap.tendsto_re_trace_cfc_log_add_smul_one` — the identity-shift continuity of the + cross trace term under the support condition. +* `ContinuousLinearMap.tendsto_quantumRelativeEntropy_add_smul_one` — identity-shift continuity of + `D` on the finite branch, the engine that removes strict positivity from joint convexity. +* `ContinuousLinearMap.hasSupportLE_sum_smul` — a convex mixture inherits the support condition of + its components: if each `ρₖ` is supported in `σₖ` (positive) with weight `wₖ ≥ 0`, then + `∑ₖ wₖ ρₖ` is supported in `∑ₖ wₖ σₖ`. +* `ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE` — joint convexity + of `D` on the finite branch (`n`-ary), **without** strict positivity: only positivity and the + support condition on each component. This is the faithful form of N&C Theorem 11.12. +* `ContinuousLinearMap.quantumRelativeEntropy_jointly_convex_of_hasSupportLE` — its two-point + specialization, N&C's literal statement. +-/ + +@[expose] public section + +open scoped Topology InnerProductSpace ComplexOrder +open Filter + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **Identity-shift continuity of the relative-entropy cross term on the finite branch.** For a +self-adjoint operator `Y` with an eigenbasis `b` and real eigenvalues `μ` (`Y (b i) = μ i • b i`), +and any `X` with the support condition `HasSupportLE X Y` (`ker Y ≤ ker X`), the cross trace term of +shifted operators converges, +`re tr((log(Y + ε•1)) ∘ (X + ε•1)) → re tr((log Y) ∘ X)` as `ε → 0⁺`. + +In the eigenbasis of `Y`, `IsSelfAdjoint.re_trace_cfc_comp_eq_sum_of_apply_eq_smul` turns the +shifted cross term into the finite sum `∑ᵢ log(μ i + ε)(aᵢ + ε)` with `aᵢ = re⟨b i, X (b i)⟩` (the +shift adds `ε` to each eigenvalue and each diagonal element). The limit is termwise: where `μ i ≠ 0` +the term is continuous at `ε = 0` (`Real.log` is continuous away from `0`); where `μ i = 0` the +support condition forces `X (b i) = 0` (so `aᵢ = 0`), leaving the harmless `ε log ε → 0` +(`Real.negMulLog` is continuous, with `Real.negMulLog 0 = 0`). -/ +theorem tendsto_re_trace_cfc_log_add_smul_one {ι : Type*} [Fintype ι] + (b : OrthonormalBasis ι ℂ E) {X Y : E →L[ℂ] E} {μ : ι → ℝ} + (hY : IsSelfAdjoint Y) (hYb : ∀ i, Y (b i) = (μ i : ℂ) • b i) + (h : X.HasSupportLE Y) : + Tendsto (fun ε : ℝ => RCLike.re (LinearMap.trace ℂ E + ((cfc Real.log (Y + (ε : ℂ) • 1)).toLinearMap ∘ₗ (X + (ε : ℂ) • 1).toLinearMap))) + (𝓝[>] 0) (𝓝 (RCLike.re (LinearMap.trace ℂ E + ((cfc Real.log Y).toLinearMap ∘ₗ X.toLinearMap)))) := by + classical + have hsa1 : ∀ ε : ℝ, IsSelfAdjoint ((ε : ℂ) • (1 : E →L[ℂ] E)) := fun ε => by + rw [isSelfAdjoint_iff, star_smul, star_one, RCLike.star_def, Complex.conj_ofReal] + have hYε : ∀ ε : ℝ, IsSelfAdjoint (Y + (ε : ℂ) • 1) := fun ε => hY.add (hsa1 ε) + have hYεb : ∀ (ε : ℝ) (i : ι), (Y + (ε : ℂ) • 1) (b i) = ((μ i + ε : ℝ) : ℂ) • b i := by + intro ε i + rw [_root_.add_apply, hYb i, _root_.smul_apply, + one_apply_eq_self, ← add_smul, Complex.ofReal_add] + -- rewrite the RHS limit point in the eigenbasis of `Y` + rw [hY.re_trace_cfc_comp_eq_sum_of_apply_eq_smul b hYb hY.continuousOn_log_spectrum X] + -- rewrite the ε-dependent cross term in the (shared) eigenbasis of `Y + ε•1` + have hfun : ∀ ε : ℝ, RCLike.re (LinearMap.trace ℂ E + ((cfc Real.log (Y + (ε : ℂ) • 1)).toLinearMap ∘ₗ (X + (ε : ℂ) • 1).toLinearMap)) + = ∑ i, Real.log (μ i + ε) * RCLike.re (inner ℂ (b i) ((X + (ε : ℂ) • 1) (b i))) := fun ε => + (hYε ε).re_trace_cfc_comp_eq_sum_of_apply_eq_smul b (hYεb ε) + (hYε ε).continuousOn_log_spectrum (X + (ε : ℂ) • 1) + simp_rw [hfun] + -- the diagonal element of `X + ε•1` is that of `X` plus `ε` + have hinner : ∀ (ε : ℝ) (i : ι), RCLike.re (inner ℂ (b i) ((X + (ε : ℂ) • 1) (b i))) + = RCLike.re (inner ℂ (b i) (X (b i))) + ε := by + intro ε i + rw [_root_.add_apply, inner_add_right, _root_.smul_apply, + one_apply_eq_self, inner_smul_right, + orthonormal_iff_ite.mp b.orthonormal i i] + simp + simp_rw [hinner] + refine tendsto_finsetSum _ fun i _ => ?_ + set a : ℝ := RCLike.re (inner ℂ (b i) (X (b i))) with ha_def + by_cases hμi : μ i = 0 + · -- kernel term: the support condition kills `aᵢ`, leaving `ε log ε → 0` + have hXbi : X (b i) = 0 := by + have hker : b i ∈ LinearMap.ker (Y : E →ₗ[ℂ] E) := by + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe, hYb i, hμi]; simp + have hmem := h hker + rwa [LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at hmem + have ha0 : a = 0 := by rw [ha_def, hXbi]; simp + have htarget : Real.log (μ i) * a = 0 := by rw [hμi, ha0]; simp + rw [htarget] + have hcongr : (fun ε : ℝ => Real.log (μ i + ε) * (a + ε)) = fun ε => -Real.negMulLog ε := by + funext ε; rw [hμi, ha0]; simp only [zero_add, Real.negMulLog_eq_neg]; ring + rw [hcongr] + have hlim : Tendsto (fun ε : ℝ => -Real.negMulLog ε) (𝓝 (0 : ℝ)) (𝓝 0) := by + have := (Real.continuous_negMulLog.tendsto 0).neg + rwa [Real.negMulLog_zero, neg_zero] at this + exact hlim.mono_left nhdsWithin_le_nhds + · -- interior term (`μ i ≠ 0`): continuous at `ε = 0` + have hcont : ContinuousAt (fun ε : ℝ => Real.log (μ i + ε) * (a + ε)) 0 := + ((continuousAt_const.add continuousAt_id).log (by simpa using hμi)).mul + (continuousAt_const.add continuousAt_id) + have := hcont.tendsto + simp only [add_zero] at this + exact this.mono_left nhdsWithin_le_nhds + +/-- **Identity-shift continuity of the quantum relative entropy on the finite branch.** For +self-adjoint `X, Y` with the support condition `HasSupportLE X Y`, +`D(X + ε•1 ‖ Y + ε•1) → D(X ‖ Y)` as `ε → 0⁺`. + +The relative entropy `D(A ‖ B) = re tr((log A) ∘ A) − re tr((log B) ∘ A)` splits into two cross +terms handled by `tendsto_re_trace_cfc_log_add_smul_one`: the self term (`B = A = X`, with the +trivial support condition `HasSupportLE X X`) and the cross term (`B = Y`, the given support +condition). Each converges, so `D` does by `Tendsto.sub`. -/ +theorem tendsto_quantumRelativeEntropy_add_smul_one {X Y : E →L[ℂ] E} + (hX : IsSelfAdjoint X) (hY : IsSelfAdjoint Y) (h : X.HasSupportLE Y) : + Tendsto (fun ε : ℝ => quantumRelativeEntropy (X + (ε : ℂ) • 1) (Y + (ε : ℂ) • 1)) (𝓝[>] 0) + (𝓝 (quantumRelativeEntropy X Y)) := by + simp_rw [quantumRelativeEntropy_def] + refine Tendsto.sub ?_ ?_ + · exact tendsto_re_trace_cfc_log_add_smul_one (X := X) (Y := X) + (hX.isSymmetric.eigenvectorBasis rfl) hX + (fun i => hX.apply_eigenvectorBasis_cast rfl i) le_rfl + · exact tendsto_re_trace_cfc_log_add_smul_one (X := X) (Y := Y) + (hY.isSymmetric.eigenvectorBasis rfl) hY + (fun i => hY.apply_eigenvectorBasis_cast rfl i) h + +omit [FiniteDimensional ℂ E] in +/-- **A convex mixture inherits the support condition of its components.** If each `σ k` is a +positive operator, `ρ k` is supported in `σ k` (`HasSupportLE`), and the weights `w k` are +nonnegative, then the mixture `∑ₖ wₖ ρₖ` is supported in the mixture `∑ₖ wₖ σₖ`: +`ker (∑ₖ wₖ σₖ) ≤ ker (∑ₖ wₖ ρₖ)`. + +A vector `x` in `ker (∑ₖ wₖ σₖ)` gives `0 = ⟨x, (∑ₖ wₖ σₖ) x⟩ = ∑ₖ wₖ ⟨x, σₖ x⟩`, a sum of +nonnegative terms; so each vanishes, and for a positive-weight component `wₖ > 0` we get +`⟨x, σₖ x⟩ = 0`, whence `σₖ x = 0` by positivity, `x ∈ ker σₖ ≤ ker ρₖ` by the support condition, +and `ρₖ x = 0`. A zero-weight component contributes `wₖ • ρₖ x = 0` regardless, so the mixture +`(∑ₖ wₖ ρₖ) x = 0`. This makes the left-hand limit of the joint-convexity regularization +well-defined. -/ +theorem hasSupportLE_sum_smul {κ : Type*} (t : Finset κ) + {ρ σ : κ → E →L[ℂ] E} {w : κ → ℝ} + (hσ : ∀ k ∈ t, (σ k).IsPositive) (hsupp : ∀ k ∈ t, (ρ k).HasSupportLE (σ k)) + (hw : ∀ k ∈ t, 0 ≤ w k) : + (∑ k ∈ t, w k • ρ k).HasSupportLE (∑ k ∈ t, w k • σ k) := by + -- Rewrite both mixtures with complex-scalar weights, matching `inner_smul_right`. + have hρc : (∑ k ∈ t, w k • ρ k) = ∑ k ∈ t, (↑(w k) : ℂ) • ρ k := + Finset.sum_congr rfl fun k _ => (Complex.coe_smul (w k) (ρ k)).symm + have hσc : (∑ k ∈ t, w k • σ k) = ∑ k ∈ t, (↑(w k) : ℂ) • σ k := + Finset.sum_congr rfl fun k _ => (Complex.coe_smul (w k) (σ k)).symm + rw [hρc, hσc, hasSupportLE_iff] + intro x hx + rw [LinearMap.mem_ker] at hx ⊢ + simp only [ContinuousLinearMap.coe_coe] at hx ⊢ + -- `0 = ⟨x, (∑ₖ wₖ σₖ) x⟩ = ∑ₖ wₖ ⟨x, σₖ x⟩`, a sum of nonnegative terms. + have hzsum : ∑ k ∈ t, (w k : ℂ) * inner ℂ x ((σ k) x) = 0 := by + have h0 : inner ℂ x ((∑ k ∈ t, (↑(w k) : ℂ) • σ k) x) = 0 := by rw [hx]; simp + rw [_root_.sum_apply, inner_sum] at h0 + rw [← h0] + exact Finset.sum_congr rfl fun k _ => by + rw [_root_.smul_apply, inner_smul_right] + have hznn : ∀ k ∈ t, (0 : ℂ) ≤ (w k : ℂ) * inner ℂ x ((σ k) x) := fun k hk => + mul_nonneg (by exact_mod_cast hw k hk) ((hσ k hk).inner_nonneg_right x) + have hterm : ∀ k ∈ t, (w k : ℂ) * inner ℂ x ((σ k) x) = 0 := fun k hk => + (Finset.sum_eq_zero_iff_of_nonneg hznn).mp hzsum k hk + rw [_root_.sum_apply] + refine Finset.sum_eq_zero fun k hk => ?_ + rw [_root_.smul_apply] + rcases (hw k hk).eq_or_lt with hwk | hwk + · rw [← hwk]; simp + · have hwk' : (w k : ℂ) ≠ 0 := by exact_mod_cast ne_of_gt hwk + have hinner : inner ℂ x ((σ k) x) = 0 := (mul_eq_zero.mp (hterm k hk)).resolve_left hwk' + have hσx : (σ k) x = 0 := apply_eq_zero_of_re_inner_self_eq_zero + (nonneg_iff_isPositive.mpr (hσ k hk)) (by rw [hinner]; simp) + have hρx : (ρ k) x = 0 := by + have hmem := hsupp k hk (by rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe]; exact hσx) + rwa [LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at hmem + rw [hρx, smul_zero] + +omit [FiniteDimensional ℂ E] in +/-- **A binary sum inherits the support condition.** For positive operators `σ₁, σ₂` and support +conditions `ρ₁ ⊆ σ₁`, `ρ₂ ⊆ σ₂` (`HasSupportLE`), the sums satisfy `(ρ₁ + ρ₂) ⊆ (σ₁ + σ₂)`, i.e. +`(ρ₁ + ρ₂).HasSupportLE (σ₁ + σ₂)`. A vector `x ∈ ker (σ₁ + σ₂)` gives +`0 = re⟨x, (σ₁ + σ₂) x⟩ = re⟨x, σ₁ x⟩ + re⟨x, σ₂ x⟩`, a sum of nonnegative terms, so each vanishes; +positivity then forces `σ₁ x = σ₂ x = 0`, the support conditions give `ρ₁ x = ρ₂ x = 0`, and hence +`(ρ₁ + ρ₂) x = 0`. The binary (`Finset (Fin 2)`, weights `1`) special case of +`hasSupportLE_sum_smul`, proved directly; the support-condition input to the binary subadditivity of +the generalized relative entropy. -/ +theorem hasSupportLE_add {ρ₁ ρ₂ σ₁ σ₂ : E →L[ℂ] E} + (hσ₁ : σ₁.IsPositive) (hσ₂ : σ₂.IsPositive) + (h₁ : ρ₁.HasSupportLE σ₁) (h₂ : ρ₂.HasSupportLE σ₂) : + (ρ₁ + ρ₂).HasSupportLE (σ₁ + σ₂) := by + rw [hasSupportLE_iff] + intro x hx + rw [LinearMap.mem_ker] at hx ⊢ + simp only [ContinuousLinearMap.coe_coe] at hx ⊢ + rw [_root_.add_apply] at hx + have hre : RCLike.re (inner ℂ x (σ₁ x)) + RCLike.re (inner ℂ x (σ₂ x)) = 0 := by + have h0 : RCLike.re (inner ℂ x (σ₁ x + σ₂ x)) = RCLike.re (inner ℂ x (0 : E)) := by rw [hx] + rwa [inner_add_right, map_add, inner_zero_right, map_zero] at h0 + have hn₁ : 0 ≤ RCLike.re (inner ℂ x (σ₁ x)) := hσ₁.re_inner_nonneg_right x + have hn₂ : 0 ≤ RCLike.re (inner ℂ x (σ₂ x)) := hσ₂.re_inner_nonneg_right x + have hσ₁x : σ₁ x = 0 := + apply_eq_zero_of_re_inner_self_eq_zero (nonneg_iff_isPositive.mpr hσ₁) (by linarith) + have hσ₂x : σ₂ x = 0 := + apply_eq_zero_of_re_inner_self_eq_zero (nonneg_iff_isPositive.mpr hσ₂) (by linarith) + have hρ₁x : ρ₁ x = 0 := h₁.apply_eq_zero hσ₁x + have hρ₂x : ρ₂ x = 0 := h₂.apply_eq_zero hσ₂x + rw [_root_.add_apply, hρ₁x, hρ₂x, add_zero] + +omit [FiniteDimensional ℂ E] in +omit [CompleteSpace E] in +/-- **Nonzero scaling of both operators preserves the support condition.** For `c ≠ 0`, scaling both +operators by the real scalar `c` leaves both kernels unchanged (`ker (c • τ) = ker τ`, since `ℂ` is +a semifield and `(c : ℂ) ≠ 0`), so `ρ.HasSupportLE σ` upgrades to `(c • ρ).HasSupportLE (c • σ)`. +Transports a per-pair support condition on `rᵢ, sᵢ` to the scaled `t • rᵢ, t • sᵢ`, as used by the +converse (subadditivity ⟹ joint convexity) argument for the generalized relative entropy. -/ +theorem hasSupportLE_smul {ρ σ : E →L[ℂ] E} {c : ℝ} (hc : c ≠ 0) + (h : ρ.HasSupportLE σ) : (c • ρ).HasSupportLE (c • σ) := by + have hker : ∀ τ : E →L[ℂ] E, + (↑(c • τ) : E →ₗ[ℂ] E).ker = (↑τ : E →ₗ[ℂ] E).ker := fun τ => by + rw [← Complex.coe_smul c τ, ContinuousLinearMap.toLinearMap_smul, + LinearMap.ker_smul _ _ (by exact_mod_cast hc : (c : ℂ) ≠ 0)] + unfold ContinuousLinearMap.HasSupportLE at h ⊢ + rwa [hker ρ, hker σ] + +/-- **Joint convexity of the quantum relative entropy on the finite branch, `n`-ary form** +(Nielsen & Chuang Theorem 11.12, faithful form). For families of positive operators +`ρ, σ : κ → E →L[ℂ] E` with the support condition `(ρ k).HasSupportLE (σ k)` on every component and +convex weights `w` (`w k ≥ 0`, `∑ w k = 1`), +`D(∑ₖ wₖ ρₖ ‖ ∑ₖ wₖ σₖ) ≤ ∑ₖ wₖ D(ρₖ ‖ σₖ)`. + +There is **no strict-positivity hypothesis**: this is the faithful form of the theorem on N&C's own +finite branch (the support condition), of which the strict-positivity form +`quantumRelativeEntropy_jointly_convex_sum` is a corollary. The proof is the regularization argument +that removes faithfulness from strong subadditivity: for `ε > 0` shift every operator by `ε • 1` +(strictly positive by `isStrictlyPositive_add_smul_one`, since each `ρ k, σ k ≥ 0`), apply the +strict-positivity joint convexity to the shifted family, and pass to the limit `ε → 0⁺` via +`tendsto_quantumRelativeEntropy_add_smul_one` on both sides — the left-hand limit is well-defined +because the mixture inherits the support condition (`hasSupportLE_sum_smul`). The shift factors +through the sum because `ε • 1` is constant and `∑ₖ wₖ = 1`. -/ +theorem quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE {κ : Type*} (t : Finset κ) + {ρ σ : κ → E →L[ℂ] E} {w : κ → ℝ} + (hρ : ∀ k ∈ t, (ρ k).IsPositive) (hσ : ∀ k ∈ t, (σ k).IsPositive) + (hsupp : ∀ k ∈ t, (ρ k).HasSupportLE (σ k)) + (hw : ∀ k ∈ t, 0 ≤ w k) (hsum : ∑ k ∈ t, w k = 1) : + quantumRelativeEntropy (∑ k ∈ t, w k • ρ k) (∑ k ∈ t, w k • σ k) ≤ + ∑ k ∈ t, w k * quantumRelativeEntropy (ρ k) (σ k) := by + have : IsScalarTower ℝ ℂ (E →L[ℂ] E) := IsScalarTower.of_algebraMap_eq fun _ => rfl + -- The two mixtures are self-adjoint: nonnegative combinations of positive operators. + have hRc : (∑ k ∈ t, w k • ρ k) = ∑ k ∈ t, (↑(w k) : ℂ) • ρ k := + Finset.sum_congr rfl fun k _ => (Complex.coe_smul (w k) (ρ k)).symm + have hSc : (∑ k ∈ t, w k • σ k) = ∑ k ∈ t, (↑(w k) : ℂ) • σ k := + Finset.sum_congr rfl fun k _ => (Complex.coe_smul (w k) (σ k)).symm + have hcnn : ∀ k ∈ t, (0 : ℂ) ≤ (↑(w k) : ℂ) := fun k hk => + RCLike.nonneg_iff_exists_ofReal.mpr ⟨w k, hw k hk, rfl⟩ + have hRsa : IsSelfAdjoint (∑ k ∈ t, w k • ρ k) := by + rw [hRc] + exact (isPositive_sum t fun k hk => (hρ k hk).smul_of_nonneg (hcnn k hk)).isSelfAdjoint + have hSsa : IsSelfAdjoint (∑ k ∈ t, w k • σ k) := by + rw [hSc] + exact (isPositive_sum t fun k hk => (hσ k hk).smul_of_nonneg (hcnn k hk)).isSelfAdjoint + -- The shift `+ ε • 1` factors through the finite mixture (uses `∑ wₖ = 1`). + have hshift : ∀ (A : κ → E →L[ℂ] E) (ε : ℝ), + (∑ k ∈ t, w k • A k) + (ε : ℂ) • 1 = ∑ k ∈ t, w k • (A k + (ε : ℂ) • 1) := fun A ε => by + simp_rw [smul_add, Finset.sum_add_distrib, ← Finset.sum_smul, hsum, one_smul] + -- Both sides converge as `ε → 0⁺`. + have hf : Tendsto (fun ε : ℝ => quantumRelativeEntropy + ((∑ k ∈ t, w k • ρ k) + (ε : ℂ) • 1) ((∑ k ∈ t, w k • σ k) + (ε : ℂ) • 1)) (𝓝[>] 0) + (𝓝 (quantumRelativeEntropy (∑ k ∈ t, w k • ρ k) (∑ k ∈ t, w k • σ k))) := + tendsto_quantumRelativeEntropy_add_smul_one hRsa hSsa (hasSupportLE_sum_smul t hσ hsupp hw) + have hg : Tendsto (fun ε : ℝ => ∑ k ∈ t, w k * quantumRelativeEntropy + ((ρ k) + (ε : ℂ) • 1) ((σ k) + (ε : ℂ) • 1)) (𝓝[>] 0) + (𝓝 (∑ k ∈ t, w k * quantumRelativeEntropy (ρ k) (σ k))) := + tendsto_finsetSum t fun k hk => + (tendsto_quantumRelativeEntropy_add_smul_one (hρ k hk).isSelfAdjoint (hσ k hk).isSelfAdjoint + (hsupp k hk)).const_mul (w k) + -- For every `ε > 0` the strict-positivity convexity applies to the shifted family. + refine le_of_tendsto_of_tendsto hf hg ?_ + filter_upwards [self_mem_nhdsWithin] with ε hε + have hεpos : (0 : ℝ) < ε := hε + rw [hshift ρ ε, hshift σ ε] + exact quantumRelativeEntropy_jointly_convex_sum t + (fun k hk => by + rw [Complex.coe_smul] + exact isStrictlyPositive_add_smul_one (nonneg_iff_isPositive.mpr (hρ k hk)) hεpos) + (fun k hk => by + rw [Complex.coe_smul] + exact isStrictlyPositive_add_smul_one (nonneg_iff_isPositive.mpr (hσ k hk)) hεpos) + hw hsum + +/-- **Joint convexity of the quantum relative entropy on the finite branch, two-point form** +(Nielsen & Chuang Theorem 11.12, N&C's literal statement). For positive operators `ρ₁, ρ₂, σ₁, σ₂` +with the support conditions `ρ₁ ⊆ σ₁`, `ρ₂ ⊆ σ₂` (`HasSupportLE`) and probabilities `t, s ≥ 0`, +`t + s = 1`, +`D(t ρ₁ + s ρ₂ ‖ t σ₁ + s σ₂) ≤ t · D(ρ₁ ‖ σ₁) + s · D(ρ₂ ‖ σ₂)`. + +The two-point specialization of `quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE` over a +`Fin 2` index. No strict positivity is required — only the support condition, which for a genuine +mixture is automatic. -/ +theorem quantumRelativeEntropy_jointly_convex_of_hasSupportLE + {ρ₁ ρ₂ σ₁ σ₂ : E →L[ℂ] E} + (hρ₁ : ρ₁.IsPositive) (hρ₂ : ρ₂.IsPositive) (hσ₁ : σ₁.IsPositive) (hσ₂ : σ₂.IsPositive) + (hs₁ : ρ₁.HasSupportLE σ₁) (hs₂ : ρ₂.HasSupportLE σ₂) + {t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s) (hts : t + s = 1) : + quantumRelativeEntropy (t • ρ₁ + s • ρ₂) (t • σ₁ + s • σ₂) ≤ + t * quantumRelativeEntropy ρ₁ σ₁ + s * quantumRelativeEntropy ρ₂ σ₂ := by + have key := quantumRelativeEntropy_jointly_convex_sum_of_hasSupportLE + (Finset.univ : Finset (Fin 2)) (ρ := ![ρ₁, ρ₂]) (σ := ![σ₁, σ₂]) (w := ![t, s]) + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by intro k _; fin_cases k <;> simpa) + (by simp [Fin.sum_univ_two, hts]) + simpa [Fin.sum_univ_two] using key + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyDiagonal.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyDiagonal.lean new file mode 100644 index 0000000000..07428817e3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyDiagonal.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# The quantum relative entropy of commuting diagonal operators is the classical KL divergence + +Fix a finite-dimensional complex inner product space `E` and an orthonormal basis `b` of `E`. If +two self-adjoint operators `A, B` are **simultaneously diagonal** in `b` with real eigenvalue lists +`p, q` — `A (b i) = pᵢ • b i` and `B (b i) = qᵢ • b i` — then their quantum (Umegaki) relative +entropy collapses to the classical relative entropy (Kullback–Leibler divergence) of the eigenvalue +lists: + +`D(A ‖ B) = ∑ᵢ pᵢ (log pᵢ − log qᵢ) = Real.relativeEntropy p q`. + +This is the operator-level content behind the fact that the quantum relative entropy of two +diagonal (classical) states equals the classical KL divergence of their diagonals — the identity +that turns the classical mutual information appearing in the Holevo bound (Nielsen & Chuang, +Theorem 12.1) into a sum of quantum relative entropies of the measurement-outcome states. + +The identity is **unconditional** — no faithfulness/strict-positivity hypothesis — because the +finite real-valued generators handle their boundary cases compatibly: `Real.log 0 = 0` makes the +`pᵢ = 0` / `qᵢ = 0` terms vanish on both sides (`cfc Real.log B` acts as `0` on the kernel of `B`, +matching `Real.log 0 = 0` in the classical sum), and `Real.log` is continuous on the (finite) +spectrum of any self-adjoint operator (`IsSelfAdjoint.continuousOn_log_spectrum`), so the spectral +mapping on eigenvectors (`IsSelfAdjoint.cfc_apply_smul_of_apply_eq_smul`) applies even when `0` lies +in the spectrum. + +## Main results + +* `ContinuousLinearMap.quantumRelativeEntropy_eq_relativeEntropy_of_isEigenbasis` — the identity + `D(A ‖ B) = Real.relativeEntropy p q` for `A, B` simultaneously diagonal in an orthonormal basis. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace ContinuousLinearMap + +variable {ι E : Type*} [Fintype ι] [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + +/-- **The quantum relative entropy of two commuting diagonal operators is the classical KL +divergence.** If self-adjoint operators `A, B` are simultaneously diagonal in an orthonormal basis +`b` with real eigenvalue lists `p, q` (`A (b i) = pᵢ • b i`, `B (b i) = qᵢ • b i`), then + +`D(A ‖ B) = Real.relativeEntropy p q = ∑ᵢ pᵢ (log pᵢ − log qᵢ)`. + +Both trace terms of `D(A ‖ B) = re tr((log A) A) − re tr((log B) A)` are evaluated in the shared +eigenbasis `b`: writing `X` for `A` or `B` with eigenvalues `r`, the operator `(cfc log X) ∘ A` +sends `b i ↦ (pᵢ · log rᵢ) • b i` (spectral mapping on eigenvectors, valid since `log` is +continuous on the finite spectrum even where `0` occurs), so `re tr` of it is `∑ᵢ pᵢ log rᵢ`. The +difference `∑ pᵢ log pᵢ − ∑ pᵢ log qᵢ` is the classical relative entropy. No faithfulness is +needed. -/ +theorem quantumRelativeEntropy_eq_relativeEntropy_of_isEigenbasis + (b : OrthonormalBasis ι ℂ E) {A B : E →L[ℂ] E} {p q : ι → ℝ} + (hA : IsSelfAdjoint A) (hB : IsSelfAdjoint B) + (hpA : ∀ i, A (b i) = (p i : ℂ) • b i) (hqB : ∀ i, B (b i) = (q i : ℂ) • b i) : + A.quantumRelativeEntropy B = Real.relativeEntropy p q := by + classical + -- For a diagonal `X` (eigenvalues `r`), `re tr((log X) ∘ A) = ∑ᵢ pᵢ log rᵢ`. + have key : ∀ (X : E →L[ℂ] E) (r : ι → ℝ), IsSelfAdjoint X → (∀ i, X (b i) = (r i : ℂ) • b i) → + RCLike.re ((LinearMap.trace ℂ E) ((cfc Real.log X).toLinearMap ∘ₗ A.toLinearMap)) + = ∑ i, p i * Real.log (r i) := by + intro X r hX hrX + have happ : ∀ i, ((cfc Real.log X).toLinearMap ∘ₗ A.toLinearMap) (b i) + = ((p i * Real.log (r i) : ℝ) : ℂ) • b i := by + intro i + simp only [LinearMap.comp_apply, ContinuousLinearMap.coe_coe] + rw [hpA i, map_smul, + hX.cfc_apply_smul_of_apply_eq_smul rfl hX.continuousOn_log_spectrum (hrX i), + smul_smul, ← Complex.ofReal_mul] + rw [LinearMap.trace_eq_sum_inner _ b] + have hin : ∀ i, inner ℂ (b i) (((cfc Real.log X).toLinearMap ∘ₗ A.toLinearMap) (b i)) + = ((p i * Real.log (r i) : ℝ) : ℂ) := by + intro i + rw [happ i, inner_smul_right, orthonormal_iff_ite.mp b.orthonormal i i] + simp + simp_rw [hin] + rw [← Complex.ofReal_sum] + simp + rw [ContinuousLinearMap.quantumRelativeEntropy_def, key A p hA hpA, key B q hB hqB, + Real.relativeEntropy_eq, ← Finset.sum_sub_distrib] + exact Finset.sum_congr rfl fun i _ => by ring + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyMonotone.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyMonotone.lean new file mode 100644 index 0000000000..32b00b9621 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyMonotone.lean @@ -0,0 +1,350 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DepolarizingPartialTrace +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyConvexNonfaithful +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.ReducedState + +/-! +# Monotonicity of the quantum relative entropy under the partial trace + +Fix finite-dimensional complex inner product spaces `E`, `F` and an orthonormal basis `b` of `F` +of dimension `d = |ι|`. Tracing out the right factor of a bipartite operator cannot increase the +quantum relative entropy: for strictly positive operators `ρ, σ : E ⊗ F →L[ℂ] E ⊗ F` — density +operators, or more generally any strictly positive operators, not necessarily normalized — + +`D(Tr_F ρ ‖ Tr_F σ) ≤ D(ρ ‖ σ)`. + +This is the operator-level heart of Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 11.17 (monotonicity of the relative entropy), and the bridge to the strong +subadditivity of the von Neumann entropy (Theorem 11.14). + +## Proof route + +The completely depolarizing partial-trace channel `τ ↦ (Tr_F τ) ⊗ (I_F/d)` is a **uniform +mixed-unitary average** over the depolarizing `1`-design `{I_E ⊗ Uⱼ}` +(`OrthonormalBasis.sum_conjStarAlgEquiv_congrIsometry_depolarizingUnitary`, N&C Ex 11.19). Feeding +this average into the mixed-unitary monotonicity of the quantum relative entropy +(`ContinuousLinearMap.quantumRelativeEntropy_sum_conjStarAlgEquiv_le`) gives + +`D((Tr_F ρ) ⊗ I/d ‖ (Tr_F σ) ⊗ I/d) ≤ D(ρ ‖ σ)`. + +The common maximally-mixed factor `I_F/d` is then cancelled by +`ContinuousLinearMap.quantumRelativeEntropy_mapL_right_eq` — `D(A ⊗ M ‖ B ⊗ M) = D(A ‖ B)` for a +shared strictly-positive density operator `M` — leaving `D(Tr_F ρ ‖ Tr_F σ)`. This cancellation +requires the reduced operators to be strictly positive +(`IsStrictlyPositive.of_partialTraceRight_eq`) but **not** normalized, and `I_F/d` to be a +strictly-positive density operator (`ContinuousLinearMap.isDensityOp_finrank_inv_smul_one`, +`ContinuousLinearMap.isStrictlyPositive_finrank_inv_smul_one`). Cancelling the factor this way — via +`quantumRelativeEntropy_mapL_right_eq` rather than the density-operator tensor additivity — is what +lets the density-operator hypothesis on `ρ, σ` be dropped, so that the strictly-positive but +un-normalized identity shift `ρ + ε • 1` can later be pushed through this bound. + +## Main results + +* `ContinuousLinearMap.quantumRelativeEntropy_mapL_right_eq` — tensoring both arguments with a + common strictly-positive density operator leaves the relative entropy unchanged, + `D(A ⊗ M ‖ B ⊗ M) = D(A ‖ B)` (the tensor split behind the twirl, off density operators). +* `ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive` — + monotonicity under the right partial trace for strictly positive (not necessarily normalized) + operators; the twirl proof with the tensor split above in place of tensor additivity. +* `ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le_of_hasSupportLE` — monotonicity + on N&C's own **finite branch**, the support condition `HasSupportLE ρ σ` (`supp ρ ⊆ supp σ`), with + **no** strict positivity; the faithful form of the theorem, obtained from the strictly-positive + base by the identity-shift perturbation `ρ + ε • 1` and the limit `ε → 0⁺`. +* `ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le` — its density-operator + specialization (the form used for states). +-/ + +@[expose] public section + +open Module InnerProductSpace +open scoped TensorProduct Topology + +namespace ContinuousLinearMap + +variable {ι E F : Type*} [Fintype ι] [Nonempty ι] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + +/-- **Tensoring both arguments with a common density operator leaves the relative entropy +unchanged.** For strictly positive operators `A, B : E →L[ℂ] E` and a strictly positive density +operator `M : F →L[ℂ] F`, + +`D(A ⊗ M ‖ B ⊗ M) = D(A ‖ B)`. + +Unlike `IsDensityOp.quantumRelativeEntropy_tensorMap`, `A` and `B` need **not** be density operators +(no normalization) — only strict positivity, so that `IsSelfAdjoint.cfc_log_tensorMap` applies. The +operator logarithm of each tensor splits as `log(A ⊗ M) = log A ⊗ I + I ⊗ log M`; the shared +`I ⊗ log M` term cancels in the difference `log(A ⊗ M) - log(B ⊗ M)`, and `trace_mapL_comp_mapL` +factors the remaining traces, with the maximally-mixed factor's `tr M = 1` +(`IsDensityOp.trace_eq_one`) absorbing the right tensor slot. This is the tensor split behind the +partial-trace twirl, generalized +off density operators so that the `ε`-shifted operators `ρ + ε • 1` (strictly positive, not +normalized) may be fed through it. -/ +theorem quantumRelativeEntropy_mapL_right_eq {A B : E →L[ℂ] E} {M : F →L[ℂ] F} + (hA : IsStrictlyPositive A) (hB : IsStrictlyPositive B) + (hM : M.IsDensityOp) (hMs : IsStrictlyPositive M) : + quantumRelativeEntropy (TensorProduct.mapL A M) (TensorProduct.mapL B M) = + quantumRelativeEntropy A B := by + have h_log_A : cfc Real.log (TensorProduct.mapL A M) = + TensorProduct.mapL (cfc Real.log A) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log M) := + IsSelfAdjoint.cfc_log_tensorMap hA.isSelfAdjoint hMs.isSelfAdjoint + rfl rfl (fun i => hA.eigenvalues_pos _ rfl i) (fun j => hMs.eigenvalues_pos _ rfl j) + have h_log_B : cfc Real.log (TensorProduct.mapL B M) = + TensorProduct.mapL (cfc Real.log B) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log M) := + IsSelfAdjoint.cfc_log_tensorMap hB.isSelfAdjoint hMs.isSelfAdjoint + rfl rfl (fun i => hB.eigenvalues_pos _ rfl i) (fun j => hMs.eigenvalues_pos _ rfl j) + simp only [quantumRelativeEntropy_def, h_log_A, h_log_B, ContinuousLinearMap.toLinearMap_add, + LinearMap.add_comp, map_add, trace_mapL_comp_mapL, ContinuousLinearMap.toLinearMap_one, + Module.End.one_eq_id, LinearMap.id_comp, hM.trace_eq_one, mul_one] + ring + +/-- **Monotonicity of the quantum relative entropy under the right partial trace, off density +operators** (Nielsen & Chuang, Theorem 11.17). For strictly positive operators +`ρ, σ : E ⊗ F →L[ℂ] E ⊗ F` (not necessarily normalized) and an orthonormal basis `b` of `F`, + +`D(Tr_F ρ ‖ Tr_F σ) ≤ D(ρ ‖ σ)`. + +The completely depolarizing partial-trace channel is a uniform mixed-unitary average over the +depolarizing `1`-design `{I_E ⊗ Uⱼ}` (N&C Ex 11.19), so this is an instance of the mixed-unitary +data-processing inequality for the relative entropy, after cancelling the maximally mixed `I_F/d` +factor by the common-right-factor identity `quantumRelativeEntropy_mapL_right_eq`. Dropping the +density-operator hypothesis (only strict positivity remains) is what lets the identity-shift +perturbation `ρ + ε • 1` — strictly positive but not normalized — pass through this bound in +`quantumRelativeEntropy_partialTraceRight_le_of_hasSupportLE`; the density-operator form is the +one-line corollary `quantumRelativeEntropy_partialTraceRight_le`. -/ +theorem quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive + (b : OrthonormalBasis ι ℂ F) + {ρ σ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} + (hρs : IsStrictlyPositive ρ) (hσs : IsStrictlyPositive σ) : + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (ρ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))).quantumRelativeEntropy + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (σ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + ≤ ρ.quantumRelativeEntropy σ := by + classical + -- `F` is nontrivial (its orthonormal basis is indexed by the nonempty `ι`), so `I_F/d` is a + -- genuine density operator. + have hFpos : 0 < Module.finrank ℂ F := by + rw [Module.finrank_eq_card_basis b.toBasis]; exact Fintype.card_pos + have : Nontrivial F := Module.nontrivial_of_finrank_pos hFpos + -- The real–complex scalar tower on the operator algebra, needed by the mixed-unitary DPI. + have : NormedSpace ℝ ((E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) := NormedSpace.complexToReal + have : IsScalarTower ℝ ℂ ((E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + -- The uniform probability weight over the `2^d · d!` depolarizing unitaries. + set w : (ι → Bool) × Equiv.Perm ι → ℝ := + fun _ => ((2 : ℝ) ^ Fintype.card ι * ((Fintype.card ι).factorial : ℝ))⁻¹ with hw + have hden_ne : ((2 : ℝ) ^ Fintype.card ι * ((Fintype.card ι).factorial : ℝ)) ≠ 0 := by + positivity + have hcardκ : Fintype.card ((ι → Bool) × Equiv.Perm ι) = + 2 ^ Fintype.card ι * (Fintype.card ι).factorial := by + rw [Fintype.card_prod, Fintype.card_fun, Fintype.card_perm, Fintype.card_bool] + have hcardκ_real : (Fintype.card ((ι → Bool) × Equiv.Perm ι) : ℝ) = + (2 : ℝ) ^ Fintype.card ι * ((Fintype.card ι).factorial : ℝ) := by + rw [hcardκ]; push_cast; ring + have hwsum : ∑ p : (ι → Bool) × Equiv.Perm ι, w p = 1 := by + rw [hw, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, hcardκ_real, + mul_inv_cancel₀ hden_ne] + have hw0 : ∀ p ∈ (Finset.univ : Finset ((ι → Bool) × Equiv.Perm ι)), 0 ≤ w p := by + intro p _; rw [hw]; positivity + -- The twirl bridge: the (real-weighted) uniform average of the `I_E ⊗ Uⱼ`-twirls of `τ` equals + -- the `E`-marginal of `τ` tensored with the maximally mixed state `I_F/d`. + have hbridge : ∀ τ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F), + ∑ p : (ι → Bool) × Equiv.Perm ι, + w p • (TensorProduct.congrIsometry (.refl ℂ E) + (b.depolarizingUnitary p)).conjStarAlgEquiv τ + = TensorProduct.mapL + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (τ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + ((Fintype.card ι : ℂ)⁻¹ • 1) := by + intro τ + rw [← b.sum_conjStarAlgEquiv_congrIsometry_depolarizingUnitary τ] + refine Finset.sum_congr rfl fun p _ => ?_ + rw [hw, ← Complex.coe_smul] + congr 1 + push_cast + ring + -- Apply the mixed-unitary data-processing inequality, then rewrite both averages by the bridge. + have hDPI := ContinuousLinearMap.quantumRelativeEntropy_sum_conjStarAlgEquiv_le + (Finset.univ : Finset ((ι → Bool) × Equiv.Perm ι)) + (fun p => TensorProduct.congrIsometry (.refl ℂ E) (b.depolarizingUnitary p)) + hρs hσs hw0 hwsum + simp only [hbridge] at hDPI + -- The maximally mixed factor `I_F/d` and the reduced operators are strictly positive. + set M : F →L[ℂ] F := (Fintype.card ι : ℂ)⁻¹ • 1 with hM + have hcard : (Module.finrank ℂ F : ℂ) = (Fintype.card ι : ℂ) := by + rw [Module.finrank_eq_card_basis b.toBasis] + have hMeq : M = (Module.finrank ℂ F : ℂ)⁻¹ • 1 := by rw [hM, hcard] + have hMd : M.IsDensityOp := by rw [hMeq]; exact isDensityOp_finrank_inv_smul_one + have hMs : IsStrictlyPositive M := by rw [hMeq]; exact isStrictlyPositive_finrank_inv_smul_one + set A₁ := LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + (ρ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) with hA₁ + set A₂ := LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + (σ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) with hA₂ + have hA₁s : IsStrictlyPositive A₁ := + IsStrictlyPositive.of_partialTraceRight_eq hρs b + (by rw [hA₁, LinearMap.coe_toContinuousLinearMap]) + have hA₂s : IsStrictlyPositive A₂ := + IsStrictlyPositive.of_partialTraceRight_eq hσs b + (by rw [hA₂, LinearMap.coe_toContinuousLinearMap]) + -- Cancel the common maximally mixed factor `I_F/d` (no normalization of the reduced operators + -- needed): `D(A₁ ⊗ M ‖ A₂ ⊗ M) = D(A₁ ‖ A₂)`. + rw [quantumRelativeEntropy_mapL_right_eq hA₁s hA₂s hMd hMs] at hDPI + exact hDPI + +/-- **Monotonicity of the quantum relative entropy under the right partial trace** (Nielsen & +Chuang, Theorem 11.17), density-operator form. The strict-positivity theorem +`quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive` does not use normalization, so +the `IsDensityOp` hypotheses are only along for the ride; this form is retained because it is the +one used for states (`AxQM.State.quantumRelativeEntropy_reduced_le`). -/ +theorem quantumRelativeEntropy_partialTraceRight_le (b : OrthonormalBasis ι ℂ F) + {ρ σ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} + (_hρ : ρ.IsDensityOp) (_hσ : σ.IsDensityOp) + (hρs : IsStrictlyPositive ρ) (hσs : IsStrictlyPositive σ) : + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (ρ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))).quantumRelativeEntropy + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (σ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + ≤ ρ.quantumRelativeEntropy σ := + quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive b hρs hσs + +/-- **Monotonicity of the quantum relative entropy under the right partial trace on the support +condition** (Nielsen & Chuang, Theorem 11.17), the faithful finite branch. For positive operators +`ρ, σ : E ⊗ F →L[ℂ] E ⊗ F` with the support condition `HasSupportLE ρ σ` (`supp ρ ⊆ supp σ`, on +which the real-valued `cfc`-based relative entropy agrees with the true relative entropy) and an +orthonormal basis `b` of `F`, + +`D(Tr_F ρ ‖ Tr_F σ) ≤ D(ρ ‖ σ)`. + +This drops the strict-positivity hypothesis of +`quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive` down to N&C's own **finite +branch**, matching the faithful form of the joint-convexity engine this route rests on +(`quantumRelativeEntropy_jointly_convex_of_hasSupportLE`, N&C Theorem 11.12): the strict-positivity +form becomes the special case where both operators are full-rank. + +The proof is the identity-shift regularization that removes faithfulness throughout this route: for +`ε > 0` shift both operators by `ε • 1` (strictly positive by `isStrictlyPositive_add_smul_one`, +since `ρ, σ ≥ 0`), apply the strictly-positive monotonicity to the shifted pair, and pass to the +limit `ε → 0⁺` via `tendsto_quantumRelativeEntropy_add_smul_one` on both sides. The `E ⊗ F` side is +shifted by `ε` directly; the marginal side is shifted by `d · ε` (`d = dim F`), because tracing out +`F` sends the shift `ε • 1_{E⊗F}` to `ε • (Tr_F 1) = (ε d) • 1_E` — `Tr_F 1 = (tr 1_F) • 1_E` +`= d • 1_E` by `partialTraceRight_tensorMap` on `1 = 1 ⊗ 1` — and since `d > 0` the reparametrized +shift `ε ↦ d ε` still runs to `0⁺`. The marginal support condition `(Tr_F ρ).HasSupportLE (Tr_F σ)` +is `HasSupportLE.of_partialTraceRight`, and the marginals are self-adjoint as `F`-marginals of +positive operators (`LinearMap.partialTraceRight_isPositive`). -/ +theorem quantumRelativeEntropy_partialTraceRight_le_of_hasSupportLE + (b : OrthonormalBasis ι ℂ F) + {ρ σ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} + (hρ : ρ.IsPositive) (hσ : σ.IsPositive) (hsupp : ρ.HasSupportLE σ) : + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (ρ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))).quantumRelativeEntropy + (LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (σ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + ≤ ρ.quantumRelativeEntropy σ := by + classical + -- `F` is nontrivial (its orthonormal basis is indexed by the nonempty `ι`), so `d = dim F > 0`. + have hFpos : 0 < Module.finrank ℂ F := by + rw [Module.finrank_eq_card_basis b.toBasis]; exact Fintype.card_pos + have : Nontrivial F := Module.nontrivial_of_finrank_pos hFpos + set dℝ : ℝ := (Module.finrank ℂ F : ℝ) with hdℝ + have hdpos : (0 : ℝ) < dℝ := by rw [hdℝ]; exact_mod_cast hFpos + -- The two `A`-marginals `Tr_F ρ`, `Tr_F σ` (as they appear in the goal). + set X' : E →L[ℂ] E := LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (ρ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) with hX' + set Y' : E →L[ℂ] E := LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight b (σ : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) with hY' + -- The marginals are positive (`F`-marginal of a positive operator), hence self-adjoint. + have hX'pos : X'.IsPositive := by + rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, hX', LinearMap.coe_toContinuousLinearMap] + exact LinearMap.partialTraceRight_isPositive b hρ.toLinearMap + have hY'pos : Y'.IsPositive := by + rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, hY', LinearMap.coe_toContinuousLinearMap] + exact LinearMap.partialTraceRight_isPositive b hσ.toLinearMap + -- The marginal support condition descends from the full one. + have hsuppM : X'.HasSupportLE Y' := + HasSupportLE.of_partialTraceRight ((ContinuousLinearMap.nonneg_iff_isPositive (f := σ)).mpr + hσ) hsupp b + (by rw [hX', LinearMap.coe_toContinuousLinearMap]) + (by rw [hY', LinearMap.coe_toContinuousLinearMap]) + -- `partialTraceRight` is additive and `ℂ`-linear. + have hlin : ∀ (S T : (E ⊗[ℂ] F) →ₗ[ℂ] E ⊗[ℂ] F) (c : ℂ), + LinearMap.partialTraceRight b (S + c • T) + = LinearMap.partialTraceRight b S + c • LinearMap.partialTraceRight b T := by + intro S T c + rw [← LinearMap.partialTraceRightLM_apply, map_add, map_smul, + LinearMap.partialTraceRightLM_apply, LinearMap.partialTraceRightLM_apply] + -- Tracing out `F` sends the identity shift `ε • 1` on `E ⊗ F` to the shift `(d ε) • 1` on `E` + -- (`Tr_F 1 = (tr 1_F) • 1_E = d • 1_E`, `partialTraceRight_tensorMap` on `1 = 1 ⊗ 1`). + have hmarg : ∀ (T : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) (ε : ℝ), + LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + ((T + (ε : ℂ) • 1 : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) + = LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + (T : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) + ((dℝ * ε : ℝ) : ℂ) • 1 := by + intro T ε + have hsc : ((dℝ * ε : ℝ) : ℂ) = (ε : ℂ) * (Module.finrank ℂ F : ℂ) := by + rw [hdℝ]; push_cast; ring + apply ContinuousLinearMap.coe_injective + simp only [ContinuousLinearMap.toLinearMap_add, ContinuousLinearMap.toLinearMap_smul, + ContinuousLinearMap.toLinearMap_one, LinearMap.coe_toContinuousLinearMap] + rw [hlin, LinearMap.partialTraceRight_one, smul_smul, hsc] + have hmargρ : ∀ ε : ℝ, LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + ((ρ + (ε : ℂ) • 1 : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) + = X' + ((dℝ * ε : ℝ) : ℂ) • 1 := fun ε => by rw [hmarg ρ ε, ← hX'] + have hmargσ : ∀ ε : ℝ, LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + ((σ + (ε : ℂ) • 1 : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)) + = Y' + ((dℝ * ε : ℝ) : ℂ) • 1 := fun ε => by rw [hmarg σ ε, ← hY'] + -- The reparametrization `ε ↦ d ε` still runs to `0⁺`. + have hg_tendsto : Filter.Tendsto (fun ε : ℝ => dℝ * ε) (𝓝[>] 0) (𝓝[>] 0) := by + rw [tendsto_nhdsWithin_iff] + refine ⟨?_, ?_⟩ + · have h0 : Filter.Tendsto (fun ε : ℝ => dℝ * ε) (𝓝 (0 : ℝ)) (𝓝 (dℝ * 0)) := + (continuous_const.mul continuous_id).tendsto 0 + rw [mul_zero] at h0 + exact h0.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with ε hε + simp only [Set.mem_Ioi] at hε ⊢ + exact mul_pos hdpos hε + -- The identity-shift continuity engine on the marginal space, reparametrized by `ε ↦ d ε`. + have hXY : Filter.Tendsto + (fun η : ℝ => quantumRelativeEntropy (X' + (η : ℂ) • 1) (Y' + (η : ℂ) • 1)) (𝓝[>] 0) + (𝓝 (quantumRelativeEntropy X' Y')) := + tendsto_quantumRelativeEntropy_add_smul_one hX'pos.isSelfAdjoint hY'pos.isSelfAdjoint hsuppM + -- Left-hand limit: `D(Tr_F(ρ + ε•1) ‖ Tr_F(σ + ε•1)) → D(Tr_F ρ ‖ Tr_F σ)` as `ε → 0⁺`. + have hf : Filter.Tendsto (fun ε : ℝ => quantumRelativeEntropy + (LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + ((ρ + (ε : ℂ) • 1 : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F))) + (LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight b + ((σ + (ε : ℂ) • 1 : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) : E ⊗[ℂ] F →ₗ[ℂ] E ⊗[ℂ] F)))) + (𝓝[>] 0) (𝓝 (quantumRelativeEntropy X' Y')) := by + refine (hXY.comp hg_tendsto).congr (fun ε => ?_) + simp only [Function.comp_apply] + rw [hmargρ ε, hmargσ ε] + -- Right-hand limit: `D(ρ + ε•1 ‖ σ + ε•1) → D(ρ ‖ σ)` as `ε → 0⁺`. + have hg : Filter.Tendsto (fun ε : ℝ => quantumRelativeEntropy (ρ + (ε : ℂ) • 1) (σ + (ε : ℂ) • 1)) + (𝓝[>] 0) (𝓝 (quantumRelativeEntropy ρ σ)) := + tendsto_quantumRelativeEntropy_add_smul_one hρ.isSelfAdjoint hσ.isSelfAdjoint hsupp + -- For every `ε > 0` the identity shift is strictly positive, so the strictly-positive + -- monotonicity applies to the shifted pair. + have hshift_pos : ∀ (T : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)) (ε : ℝ), T.IsPositive → 0 < ε → + IsStrictlyPositive (T + (ε : ℂ) • 1) := fun T ε hT hε => by + rw [Complex.coe_smul] + exact isStrictlyPositive_add_smul_one ((nonneg_iff_isPositive (f := T)).mpr hT) hε + refine le_of_tendsto_of_tendsto hf hg ?_ + filter_upwards [self_mem_nhdsWithin] with ε hε + simp only [Set.mem_Ioi] at hε + exact quantumRelativeEntropy_partialTraceRight_le_of_isStrictlyPositive b + (hshift_pos ρ ε hρ hε) (hshift_pos σ ε hσ hε) + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyPinching.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyPinching.lean new file mode 100644 index 0000000000..5287a036da --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumRelativeEntropyPinching.lean @@ -0,0 +1,260 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedKleinInequality +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Commute + +/-! +# Pinching and the relative entropy: the entropy-increase identity + +Fix a finite-dimensional complex inner product space `E` and a **complete family of orthogonal +projectors** `P : ι → E →L[ℂ] E` — each `P i` a star projection (`IsStarProjection`, i.e. a +self-adjoint idempotent), the `P i` mutually orthogonal (`P i * P j = 0` for `i ≠ j`), and summing +to the identity (`∑ i, P i = 1`). Applying the operator-sum (Kraus) map `krausSumₗ P` to a density +operator `ρ` gives the **pinching** (the non-selective projective-measurement channel) + +`ρ' := krausSumₗ P ρ = Σᵢ Pᵢ ρ Pᵢ`. + +The main result is the **entropy-increase identity** + +`D(ρ ‖ ρ') = S(ρ') − S(ρ)`: + +the relative entropy of the pre- to the post-measurement state equals the entropy gained. This is +the operator core of Nielsen & Chuang's proof of Theorem 11.9 (projective measurements increase +entropy): combined with the non-negativity of `D` it gives `S(ρ') ≥ S(ρ)`, and with the equality +condition of Klein's inequality it gives the case of equality. + +The heart is the **trace identity** `tr((cfc log ρ') ρ) = tr((cfc log ρ') ρ')`: each `Pᵢ` commutes +with `ρ'` (orthogonality + idempotence), hence with `log ρ'`; and since `Σᵢ Pᵢ = 1`, cyclicity of +the trace lets one replace `ρ'` by `ρ` inside `tr((log ρ') ·)` without changing the value. The +identity is fully general — no faithfulness hypothesis on `ρ` or `ρ'` is needed. + +## Main results + +* `ContinuousLinearMap.krausSumₗ_eq_sum_conj_of_isStarProjection` — `krausSumₗ P ρ = Σᵢ Pᵢ ρ Pᵢ` + for self-adjoint `Pᵢ`. +* `ContinuousLinearMap.commute_krausSumₗ_of_isStarProjection` — each `Pᵢ` commutes with the pinched + operator `Σⱼ Pⱼ ρ Pⱼ`. +* `ContinuousLinearMap.isDensityOp_krausSumₗ_of_isStarProjection` — the pinching of a density + operator is again a density operator. +* `ContinuousLinearMap.trace_comp_krausSumₗ_of_commute` — the trace identity + `tr(L (Σᵢ Pᵢ ρ Pᵢ)) = tr(L ρ)` for any operator `L` commuting with every `Pᵢ`. +* `ContinuousLinearMap.quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub` — + **`D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = S(Σᵢ Pᵢ ρ Pᵢ) − S(ρ)`.** +* `ContinuousLinearMap.vonNeumannEntropy_le_krausSumₗ` — **projective measurements never decrease + entropy** (the operator form of Nielsen & Chuang Theorem 11.9, eq. (11.66)): + `S(ρ) ≤ S(Σᵢ Pᵢ ρ Pᵢ)`, from the entropy-increase identity and non-negativity of `D`. +* `ContinuousLinearMap.vonNeumannEntropy_krausSumₗ_eq_iff` — its **equality condition**: + `S(Σᵢ Pᵢ ρ Pᵢ) = S(ρ) ↔ Σᵢ Pᵢ ρ Pᵢ = ρ`, from the equality case of the (non-faithful) Klein + inequality. +-/ + +@[expose] public section + +open Module + +namespace ContinuousLinearMap + +variable {ι E : Type*} [Fintype ι] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + {P : ι → E →L[ℂ] E} {ρ : E →L[ℂ] E} + +omit [FiniteDimensional ℂ E] [CompleteSpace E] in +/-- Cyclicity of the trace on the operator algebra: `tr(A B) = tr(B A)`. -/ +theorem trace_toLinearMap_mul_comm (A B : E →L[ℂ] E) : + LinearMap.trace ℂ E (A * B : E →L[ℂ] E).toLinearMap = + LinearMap.trace ℂ E (B * A : E →L[ℂ] E).toLinearMap := by + rw [ContinuousLinearMap.toLinearMap_mul, ContinuousLinearMap.toLinearMap_mul, + LinearMap.trace_mul_comm] + +omit [FiniteDimensional ℂ E] [CompleteSpace E] in +/-- The composition `L ∘ₗ X` of the underlying linear maps is the underlying linear map of the +operator product `L * X`. -/ +theorem coe_comp_toLinearMap (L X : E →L[ℂ] E) : + L.toLinearMap ∘ₗ X.toLinearMap = (L * X : E →L[ℂ] E).toLinearMap := + (ContinuousLinearMap.toLinearMap_mul L X).symm + +omit [FiniteDimensional ℂ E] in +/-- For a family of self-adjoint operators `Pᵢ`, the operator-sum map unfolds to the symmetric +conjugation sum `krausSumₗ P ρ = Σᵢ Pᵢ ρ Pᵢ` (each `Pᵢ† = Pᵢ`). -/ +theorem krausSumₗ_eq_sum_conj_of_isStarProjection (hP : ∀ i, IsStarProjection (P i)) (ρ) : + krausSumₗ P ρ = ∑ i, P i * ρ * P i := by + rw [krausSumₗ_apply] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [(hP i).isSelfAdjoint.adjoint_eq] + rfl + +omit [FiniteDimensional ℂ E] in +/-- **Each projector commutes with the pinched operator.** For a family of orthogonal star +projectors `Pᵢ`, every `Pᵢ` commutes with `Σⱼ Pⱼ ρ Pⱼ`: both `Pᵢ (Σⱼ Pⱼ ρ Pⱼ)` and +`(Σⱼ Pⱼ ρ Pⱼ) Pᵢ` collapse to `Pᵢ ρ Pᵢ` by orthogonality and idempotence. -/ +theorem commute_krausSumₗ_of_isStarProjection (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i ≠ j → P i * P j = 0) (ρ) (i : ι) : + Commute (P i) (∑ j, P j * ρ * P j) := by + change P i * (∑ j, P j * ρ * P j) = (∑ j, P j * ρ * P j) * P i + rw [Finset.mul_sum, Finset.sum_mul] + refine Finset.sum_congr rfl fun j _ => ?_ + rcases eq_or_ne i j with rfl | h + · rw [← mul_assoc, ← mul_assoc, (hP i).isIdempotentElem, mul_assoc (P i * ρ), + (hP i).isIdempotentElem] + · rw [← mul_assoc, ← mul_assoc, horth i j h, zero_mul, zero_mul, mul_assoc (P j * ρ), + horth j i h.symm, mul_zero] + +/-- **The pinching of a density operator is a density operator.** Positivity is +`krausSumₗ_isPositive`; trace one follows from the operator-sum trace identity `tr(Σᵢ Pᵢ ρ Pᵢ) = +tr((Σᵢ Pᵢ) ρ) = tr ρ = 1` (completeness). -/ +theorem isDensityOp_krausSumₗ_of_isStarProjection (hP : ∀ i, IsStarProjection (P i)) + (hsum : ∑ i, P i = 1) (hρ : ρ.IsDensityOp) : (krausSumₗ P ρ).IsDensityOp := by + refine ⟨krausSumₗ_isPositive P hρ.isPositive, ?_⟩ + rw [trace_krausSumₗ] + have hone : (∑ i, adjoint (P i) ∘L P i) = 1 := by + rw [← hsum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [(hP i).isSelfAdjoint.adjoint_eq, ← ContinuousLinearMap.mul_def, (hP i).isIdempotentElem] + rw [hone, ContinuousLinearMap.one_def, ContinuousLinearMap.id_comp] + exact hρ.2 + +omit [FiniteDimensional ℂ E] in +/-- **The pinching trace identity.** For a complete family of orthogonal star projectors `Pᵢ` and +any operator `L` commuting with every `Pᵢ`, `tr(L (Σᵢ Pᵢ ρ Pᵢ)) = tr(L ρ)`. Per summand, cyclicity +of the trace moves the trailing `Pᵢ` to the front, where it merges with `L Pᵢ` into `L Pᵢ` +(commutation + idempotence); summing over `i` and using `Σᵢ Pᵢ = 1` collapses the family. -/ +theorem trace_comp_krausSumₗ_of_commute (hP : ∀ i, IsStarProjection (P i)) (hsum : ∑ i, P i = 1) + {L : E →L[ℂ] E} (hL : ∀ i, Commute (P i) L) : + LinearMap.trace ℂ E (L.toLinearMap ∘ₗ (krausSumₗ P ρ).toLinearMap) = + LinearMap.trace ℂ E (L.toLinearMap ∘ₗ ρ.toLinearMap) := by + rw [krausSumₗ_eq_sum_conj_of_isStarProjection hP, coe_comp_toLinearMap, coe_comp_toLinearMap, + Finset.mul_sum, ContinuousLinearMap.toLinearMap_sum, map_sum] + have hterm : ∀ i, LinearMap.trace ℂ E (L * (P i * ρ * P i) : E →L[ℂ] E).toLinearMap = + LinearMap.trace ℂ E (L * P i * ρ : E →L[ℂ] E).toLinearMap := by + intro i + have hEq : P i * (L * P i * ρ) = L * P i * ρ := by + rw [← mul_assoc, ← mul_assoc, (hL i).eq, mul_assoc L, (hP i).isIdempotentElem] + rw [show L * (P i * ρ * P i) = (L * P i * ρ) * P i by noncomm_ring, + trace_toLinearMap_mul_comm (L * P i * ρ) (P i), hEq] + rw [Finset.sum_congr rfl fun i _ => hterm i, ← map_sum, ← ContinuousLinearMap.toLinearMap_sum, + ← Finset.sum_mul, ← Finset.mul_sum, hsum, mul_one] + +/-- **The entropy-increase identity** (operator form of the identity behind Nielsen & Chuang +Theorem 11.9). For a complete family of orthogonal star projectors `Pᵢ` and a density operator `ρ`, +the relative entropy of `ρ` to its pinching `Σᵢ Pᵢ ρ Pᵢ` equals the entropy gained: +`D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = S(Σᵢ Pᵢ ρ Pᵢ) − S(ρ)`. No faithfulness is required: it rests only on the +trace identity `tr((log ρ') ρ) = tr((log ρ') ρ') = −S(ρ')` and the definition +`D(ρ ‖ σ) = −S(ρ) − re tr((log σ) ρ)`. -/ +theorem quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i ≠ j → P i * P j = 0) (hsum : ∑ i, P i = 1) (hρ : ρ.IsDensityOp) : + ρ.quantumRelativeEntropy (krausSumₗ P ρ) = + (krausSumₗ P ρ).vonNeumannEntropy - ρ.vonNeumannEntropy := by + have hρ'D : (krausSumₗ P ρ).IsDensityOp := isDensityOp_krausSumₗ_of_isStarProjection hP hsum hρ + have hcomm : ∀ i, Commute (P i) (cfc Real.log (krausSumₗ P ρ)) := by + intro i + have hc : Commute (krausSumₗ P ρ) (P i) := by + rw [krausSumₗ_eq_sum_conj_of_isStarProjection hP] + exact (commute_krausSumₗ_of_isStarProjection hP horth ρ i).symm + exact (hc.cfc_real Real.log).symm + have htr := (trace_comp_krausSumₗ_of_commute (ρ := ρ) hP hsum hcomm).symm + have hself : (krausSumₗ P ρ).quantumRelativeEntropy (krausSumₗ P ρ) = 0 := + quantumRelativeEntropy_self _ + rw [hρ'D.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub] at hself + rw [hρ.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub, htr] + linarith [hself] + +omit [FiniteDimensional ℂ E] in +/-- **The pinching does not enlarge the support:** `supp ρ ⊆ supp (Σᵢ Pᵢ ρ Pᵢ)`. For a complete +family of orthogonal star projectors `Pᵢ` and a positive operator `ρ`, `ker (Σᵢ Pᵢ ρ Pᵢ) ≤ ker ρ`, +i.e. `HasSupportLE ρ (krausSumₗ P ρ)`. + +If `(krausSumₗ P ρ) x = 0`, then the quadratic form of the pinching at `x` splits over the +projectors, `re ⟪x, (krausSumₗ P ρ) x⟫ = Σᵢ re ⟪Pᵢ x, ρ (Pᵢ x)⟫` (each `Pᵢ` self-adjoint), and +equals `0`. Every summand is `≥ 0` by positivity of `ρ`, so each `re ⟪Pᵢ x, ρ (Pᵢ x)⟫ = 0`, hence +`ρ (Pᵢ x) = 0` (`apply_eq_zero_of_re_inner_self_eq_zero`); summing over `i` with `Σᵢ Pᵢ = 1` gives +`ρ x = Σᵢ ρ (Pᵢ x) = 0`. This is the exact support hypothesis under which the non-faithful Klein +inequality applies to `D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ)` even though the pinching is generally rank-deficient. -/ +theorem hasSupportLE_krausSumₗ_of_isStarProjection (hP : ∀ i, IsStarProjection (P i)) + (hsum : ∑ i, P i = 1) (hρ : ρ.IsPositive) : HasSupportLE ρ (krausSumₗ P ρ) := by + intro x hx + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at hx ⊢ + -- The pinching's quadratic form at `x` splits as a sum of `ρ`-quadratic forms. + have hsplit : RCLike.re (inner ℂ x ((krausSumₗ P ρ) x)) = + ∑ i, RCLike.re (inner ℂ (P i x) (ρ (P i x))) := by + rw [krausSumₗ_eq_sum_conj_of_isStarProjection hP, _root_.sum_apply, inner_sum, + map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + congr 1 + rw [mul_apply_eq_comp, mul_apply_eq_comp, + ← ContinuousLinearMap.adjoint_inner_left (P i) (ρ (P i x)) x, (hP i).isSelfAdjoint.adjoint_eq] + rw [hx, inner_zero_right, map_zero] at hsplit + -- Each nonnegative summand vanishes, so `ρ` kills every `Pᵢ x`. + have hterm : ∀ i, RCLike.re (inner ℂ (P i x) (ρ (P i x))) = 0 := by + have hnn : ∀ i ∈ Finset.univ, 0 ≤ RCLike.re (inner ℂ (P i x) (ρ (P i x))) := fun i _ => by + have h := hρ.reApplyInnerSelf_nonneg (P i x) + rwa [ContinuousLinearMap.reApplyInnerSelf_apply, ← inner_re_symm] at h + exact fun i => (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hsplit.symm i (Finset.mem_univ i) + have hPx : ∀ i, ρ (P i x) = 0 := fun i => + apply_eq_zero_of_re_inner_self_eq_zero (nonneg_iff_isPositive.mpr hρ) (hterm i) + -- `ρ x = ρ ((Σᵢ Pᵢ) x) = Σᵢ ρ (Pᵢ x) = 0`. + have hxsum : ∑ i, P i x = x := by + rw [← _root_.sum_apply, hsum, one_apply_eq_self] + rw [← hxsum, map_sum, Finset.sum_eq_zero fun i _ => hPx i] + +/-- **Projective measurements never decrease entropy** (the operator form of Nielsen & Chuang +Theorem 11.9, eq. (11.66)). For a complete family of orthogonal star projectors `Pᵢ` and a density +operator `ρ`, the pinching `Σᵢ Pᵢ ρ Pᵢ` has entropy at least that of `ρ`: + + `S(ρ) ≤ S(Σᵢ Pᵢ ρ Pᵢ)`. + +Immediate from the entropy-increase identity +`D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = S(Σᵢ Pᵢ ρ Pᵢ) − S(ρ)` together with non-negativity of the relative entropy +under the support condition `ker (Σᵢ Pᵢ ρ Pᵢ) ≤ ker ρ`, which the pinching always satisfies +(`hasSupportLE_krausSumₗ_of_isStarProjection`). No faithfulness hypothesis on `ρ`. -/ +theorem vonNeumannEntropy_le_krausSumₗ (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i ≠ j → P i * P j = 0) (hsum : ∑ i, P i = 1) (hρ : ρ.IsDensityOp) : + ρ.vonNeumannEntropy ≤ (krausSumₗ P ρ).vonNeumannEntropy := by + have hρ'D : (krausSumₗ P ρ).IsDensityOp := isDensityOp_krausSumₗ_of_isStarProjection hP hsum hρ + have hsupp : HasSupportLE ρ (krausSumₗ P ρ) := + hasSupportLE_krausSumₗ_of_isStarProjection hP hsum hρ.isPositive + have hident := quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub hP horth hsum hρ + have hnonneg := hρ.quantumRelativeEntropy_nonneg_of_hasSupportLE hρ'D hsupp + rw [hident] at hnonneg + linarith + +/-- **Equality condition for the entropy increase under pinching** (the operator form of the +equality case of Nielsen & Chuang Theorem 11.9). For a complete family of orthogonal star +projectors `Pᵢ` and a density operator `ρ`, the pinching `Σᵢ Pᵢ ρ Pᵢ` has the *same* entropy as `ρ` +if and only if the pinching leaves `ρ` unchanged: + + `S(Σᵢ Pᵢ ρ Pᵢ) = S(ρ) ↔ Σᵢ Pᵢ ρ Pᵢ = ρ`. + +By the entropy-increase identity `D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = S(Σᵢ Pᵢ ρ Pᵢ) − S(ρ)`, equality of the +entropies is `D(ρ ‖ Σᵢ Pᵢ ρ Pᵢ) = 0`, which by the equality case of the (non-faithful, support- +conditioned) Klein inequality `quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE` holds exactly +when `ρ = Σᵢ Pᵢ ρ Pᵢ`. No faithfulness hypothesis on `ρ`. This is the operator-level step behind the +equality condition of the entropy-of-a-mixture bound (N&C Theorem 11.10): applied to the diagonal +pinching of the Gram operator of an ensemble, it reads off orthogonality of the ensemble states. -/ +theorem vonNeumannEntropy_krausSumₗ_eq_iff (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i ≠ j → P i * P j = 0) (hsum : ∑ i, P i = 1) (hρ : ρ.IsDensityOp) : + (krausSumₗ P ρ).vonNeumannEntropy = ρ.vonNeumannEntropy ↔ krausSumₗ P ρ = ρ := by + have hρ'D : (krausSumₗ P ρ).IsDensityOp := isDensityOp_krausSumₗ_of_isStarProjection hP hsum hρ + have hsupp : HasSupportLE ρ (krausSumₗ P ρ) := + hasSupportLE_krausSumₗ_of_isStarProjection hP hsum hρ.isPositive + have hident := quantumRelativeEntropy_krausSumₗ_eq_vonNeumannEntropy_sub hP horth hsum hρ + have hklein := hρ.quantumRelativeEntropy_eq_zero_iff_of_hasSupportLE hρ'D hsupp + constructor + · intro heq + have hD0 : ρ.quantumRelativeEntropy (krausSumₗ P ρ) = 0 := by rw [hident]; linarith + exact (hklein.mp hD0).symm + · intro heq + have hD0 := hklein.mpr heq.symm + rw [hident] at hD0 + linarith + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumStrongSubadditivity.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumStrongSubadditivity.lean new file mode 100644 index 0000000000..d0729f11cf --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/QuantumStrongSubadditivity.lean @@ -0,0 +1,223 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyMonotone + +/-! +# Strong subadditivity of the von Neumann entropy + +For a strictly positive (faithful) density operator `ρ` on a tripartite space +`E ⊗ (F ⊗ G)`, the von Neumann entropy satisfies the **strong subadditivity** inequality + +`S(ρ) + S(ρ_F) ≤ S(ρ_{EF}) + S(ρ_{FG})`, + +where `ρ_F`, `ρ_{EF}`, `ρ_{FG}` are the marginals obtained by tracing out the complementary +subsystems (Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.14). + +## Proof route + +The engine is the **quantum mutual information** written as a relative entropy against the product +of the marginals: for a strictly positive density operator `ρ` on `E ⊗ F`, + +`D(ρ ‖ (Tr_F ρ) ⊗ (Tr_E ρ)) = S(Tr_F ρ) + S(Tr_E ρ) - S(ρ)` + +(`ContinuousLinearMap.quantumRelativeEntropy_mapL_partialTrace_eq`), obtained from the trace form +`D(ρ ‖ σ) = -S(ρ) - re tr((log σ) ρ)` +(`IsDensityOp.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub`), the additivity of the operator +logarithm on a tensor product (`IsSelfAdjoint.cfc_log_tensorMap`), and the two trace–marginal +dualities `trace ((V ⊗ 1) T) = tr(V · Tr_F T)` / `trace ((1 ⊗ V) T) = tr(V · Tr_E T)` +(`LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTrace{Right,Left}`). + +Strong subadditivity is then the **monotonicity of the mutual information under discarding `G`**: +`I(E:F) ≤ I(E:FG)`. Tracing out `G` from the re-associated state +`(assocIsometry).symm.conjStarAlgEquiv ρ` on `(E ⊗ F) ⊗ G` sends `ρ` to its `E ⊗ F`-marginal and +sends the product `ρ_E ⊗ ρ_{FG}` to `ρ_E ⊗ ρ_F` (`LinearMap.partialTraceRight_assoc_conj_map`), +so the monotonicity of the relative entropy under the right partial trace +(`ContinuousLinearMap.quantumRelativeEntropy_partialTraceRight_le`, N&C Thm 11.17) gives +`D(ρ_{EF} ‖ ρ_E ⊗ ρ_F) ≤ D(ρ ‖ ρ_E ⊗ ρ_{FG})`; expanding both sides by the mutual-information +identity and cancelling `S(ρ_E)` yields the inequality. The associator tower lemmas +(`LinearMap.partialTraceRight_eq_of_partialTraceRight_assocIsometry`, +`LinearMap.partialTraceLeft_partialTraceRight_assoc`) identify the two ways of reading off the `E`- +and `F`-marginals of the tripartite state. + +## Faithfulness + +The mutual-information identity and the monotonicity of the relative entropy are stated for the +finite, real-valued relative-entropy engine, which requires the states to be **strictly positive** +(faithful). Consequently this file proves strong subadditivity for strictly positive tripartite +states. The fully general statement (which is entropy-only and has no finiteness obstruction) +follows by a continuity/limiting argument over faithful approximants and is left for future work. + +## Main results + +* `ContinuousLinearMap.quantumRelativeEntropy_mapL_partialTrace_eq` — the quantum + mutual-information identity `D(ρ ‖ ρ_E ⊗ ρ_F) = S(ρ_E) + S(ρ_F) - S(ρ)`. +* `ContinuousLinearMap.vonNeumannEntropy_add_partialTrace_le` — strong subadditivity + `S(ρ) + S(ρ_F) ≤ S(ρ_{EF}) + S(ρ_{FG})`. +-/ + +@[expose] public section + +open Module InnerProductSpace +open scoped TensorProduct + +namespace ContinuousLinearMap + +variable {E F G : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] [CompleteSpace F] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [FiniteDimensional ℂ G] [CompleteSpace G] + +/-- **Quantum mutual information as a relative entropy against the product of the marginals.** +For a strictly positive density operator `ρ` on `E ⊗ F` with marginals `ρ_E = Tr_F ρ` and +`ρ_F = Tr_E ρ`, + +`D(ρ ‖ ρ_E ⊗ ρ_F) = S(ρ_E) + S(ρ_F) - S(ρ)`. + +The right-hand side is the quantum mutual information `I(E:F)`. The marginals are supplied as +hypotheses (`hρE`, `hρF`) so the identity threads a bundled reduced state directly. -/ +theorem quantumRelativeEntropy_mapL_partialTrace_eq + {ιE ιF : Type*} [Fintype ιE] [Fintype ιF] [Nonempty ιE] [Nonempty ιF] + (bE : OrthonormalBasis ιE ℂ E) (bF : OrthonormalBasis ιF ℂ F) + {ρ : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {ρE : E →L[ℂ] E} {ρF : F →L[ℂ] F} + (hρ : ρ.IsDensityOp) (hρs : IsStrictlyPositive ρ) + (hρE : LinearMap.partialTraceRight bF ρ.toLinearMap = ρE.toLinearMap) + (hρF : LinearMap.partialTraceLeft bE ρ.toLinearMap = ρF.toLinearMap) : + ρ.quantumRelativeEntropy (TensorProduct.mapL ρE ρF) = + ρE.vonNeumannEntropy + ρF.vonNeumannEntropy - ρ.vonNeumannEntropy := by + have hρEd : ρE.IsDensityOp := hρ.of_partialTraceRight_eq bF hρE + have hρFd : ρF.IsDensityOp := hρ.of_partialTraceLeft_eq bE hρF + have hρEs : IsStrictlyPositive ρE := hρs.of_partialTraceRight_eq bF hρE + have hρFs : IsStrictlyPositive ρF := hρs.of_partialTraceLeft_eq bE hρF + have hEpos := fun i => hρEs.eigenvalues_pos hρEd.isPositive.isSelfAdjoint.isSymmetric rfl i + have hFpos := fun j => hρFs.eigenvalues_pos hρFd.isPositive.isSelfAdjoint.isSymmetric rfl j + have hlog : cfc Real.log (TensorProduct.mapL ρE ρF) = + TensorProduct.mapL (cfc Real.log ρE) (1 : F →L[ℂ] F) + + TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log ρF) := + IsSelfAdjoint.cfc_log_tensorMap hρEd.isPositive.isSelfAdjoint hρFd.isPositive.isSelfAdjoint + rfl rfl hEpos hFpos + -- The two marginal trace terms. + have ht1 : LinearMap.trace ℂ (E ⊗[ℂ] F) + ((TensorProduct.mapL (cfc Real.log ρE) (1 : F →L[ℂ] F)).toLinearMap ∘ₗ ρ.toLinearMap) = + LinearMap.trace ℂ E ((cfc Real.log ρE).toLinearMap ∘ₗ ρE.toLinearMap) := by + rw [TensorProduct.toLinearMap_mapL, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, + LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTraceRight bF, hρE] + have ht2 : LinearMap.trace ℂ (E ⊗[ℂ] F) + ((TensorProduct.mapL (1 : E →L[ℂ] E) (cfc Real.log ρF)).toLinearMap ∘ₗ ρ.toLinearMap) = + LinearMap.trace ℂ F ((cfc Real.log ρF).toLinearMap ∘ₗ ρF.toLinearMap) := by + rw [TensorProduct.toLinearMap_mapL, ContinuousLinearMap.toLinearMap_one, Module.End.one_eq_id, + LinearMap.trace_tensorMap_id_comp_eq_trace_comp_partialTraceLeft bE, hρF] + rw [hρ.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub, hlog] + rw [ContinuousLinearMap.toLinearMap_add, LinearMap.add_comp, map_add, ht1, ht2] + rw [map_add, hρEd.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy, + hρFd.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy] + ring + +-- The nested-tensor operator algebras `(E ⊗ (F ⊗ G)) →L …` force a deep `Algebra ℝ` / +-- `IsScalarTower ℝ ℂ` instance search (these are not global instances for abstract spaces), which +-- exceeds the default `synthInstance` budget even though the instances are supplied locally below. +/-- **Strong subadditivity of the von Neumann entropy** (Nielsen & Chuang, Theorem 11.14). For a +strictly positive (faithful) density operator `ρ` on the tripartite space `E ⊗ (F ⊗ G)`, + +`S(ρ) + S(ρ_F) ≤ S(ρ_{EF}) + S(ρ_{FG})`, + +where `ρ_{EF}` is the `E ⊗ F`-marginal (trace out `G`, read off after re-associating to +`(E ⊗ F) ⊗ G`), `ρ_{FG} = Tr_E ρ` is the `F ⊗ G`-marginal, and `ρ_F = Tr_G ρ_{FG}` is the +`F`-marginal. Equivalently the quantum mutual information is monotone under discarding `G`, +`I(E:F) ≤ I(E:FG)`. + +The three marginals are supplied as hypotheses so a physics-layer consumer can thread its reduced +states directly; the `E`-marginal `ρ_E` is internal (it cancels). Faithfulness +(`IsStrictlyPositive`) is the finite-branch hypothesis of the relative-entropy engine (see the +module docstring). -/ +theorem vonNeumannEntropy_add_partialTrace_le + {ιE ιF ιG : Type*} [Fintype ιE] [Fintype ιF] [Fintype ιG] + [Nonempty ιE] [Nonempty ιF] [Nonempty ιG] + (bE : OrthonormalBasis ιE ℂ E) (bF : OrthonormalBasis ιF ℂ F) (bG : OrthonormalBasis ιG ℂ G) + {ρ : (E ⊗[ℂ] (F ⊗[ℂ] G)) →L[ℂ] (E ⊗[ℂ] (F ⊗[ℂ] G))} + {ρAB : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {ρBC : (F ⊗[ℂ] G) →L[ℂ] (F ⊗[ℂ] G)} {ρB : F →L[ℂ] F} + (hρ : ρ.IsDensityOp) (hρs : IsStrictlyPositive ρ) + (hρAB : LinearMap.partialTraceRight bG + ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv ρ).toLinearMap = ρAB.toLinearMap) + (hρBC : LinearMap.partialTraceLeft bE ρ.toLinearMap = ρBC.toLinearMap) + (hρB : LinearMap.partialTraceRight bG ρBC.toLinearMap = ρB.toLinearMap) : + ρ.vonNeumannEntropy + ρB.vonNeumannEntropy ≤ + ρAB.vonNeumannEntropy + ρBC.vonNeumannEntropy := by + classical + -- The real–complex scalar tower on the operator algebras, needed by the relative-entropy engine + -- (not global instances for abstract spaces; synthesis is slow for the nested tensors). + let : NormedSpace ℝ ((E ⊗[ℂ] (F ⊗[ℂ] G)) →L[ℂ] (E ⊗[ℂ] (F ⊗[ℂ] G))) := NormedSpace.complexToReal + let : NormedSpace ℝ (((E ⊗[ℂ] F) ⊗[ℂ] G) →L[ℂ] ((E ⊗[ℂ] F) ⊗[ℂ] G)) := NormedSpace.complexToReal + have : IsScalarTower ℝ ℂ ((E ⊗[ℂ] (F ⊗[ℂ] G)) →L[ℂ] (E ⊗[ℂ] (F ⊗[ℂ] G))) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + have : IsScalarTower ℝ ℂ (((E ⊗[ℂ] F) ⊗[ℂ] G) →L[ℂ] ((E ⊗[ℂ] F) ⊗[ℂ] G)) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + -- The `E`-marginal `ρ_E = Tr_{F⊗G} ρ`, kept as an opaque operator with its defining equation. + set ρA : E →L[ℂ] E := LinearMap.toContinuousLinearMap + (LinearMap.partialTraceRight (bF.tensorProduct bG) ρ.toLinearMap) with hρA_def + have hρA : LinearMap.partialTraceRight (bF.tensorProduct bG) ρ.toLinearMap = ρA.toLinearMap := + (LinearMap.coe_toContinuousLinearMap _).symm + clear_value ρA + -- Density / strict positivity of every operator that appears (`σ = ρ_E ⊗ ρ_{FG}` and its + -- re-associated conjugate, and the re-associated tripartite state). + have hρAd : ρA.IsDensityOp := hρ.of_partialTraceRight_eq (bF.tensorProduct bG) hρA + have hρAs : IsStrictlyPositive ρA := hρs.of_partialTraceRight_eq (bF.tensorProduct bG) hρA + have hρBCd : ρBC.IsDensityOp := hρ.of_partialTraceLeft_eq bE hρBC + have hρBCs : IsStrictlyPositive ρBC := hρs.of_partialTraceLeft_eq bE hρBC + have hσd : (TensorProduct.mapL ρA ρBC).IsDensityOp := hρAd.mapL hρBCd + have hσs : IsStrictlyPositive (TensorProduct.mapL ρA ρBC) := + TensorProduct.mapL_isStrictlyPositive hρAs hρBCs + have hρ''d : ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv ρ).IsDensityOp := + (LinearIsometryEquiv.conjStarAlgEquiv_isDensityOp_iff _).mpr hρ + have hρ''s : IsStrictlyPositive ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv ρ) := + (LinearIsometryEquiv.conjStarAlgEquiv_isStrictlyPositive_iff _).mpr hρs + have hσ''d : ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv + (TensorProduct.mapL ρA ρBC)).IsDensityOp := + (LinearIsometryEquiv.conjStarAlgEquiv_isDensityOp_iff _).mpr hσd + have hσ''s : IsStrictlyPositive ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv + (TensorProduct.mapL ρA ρBC)) := + (LinearIsometryEquiv.conjStarAlgEquiv_isStrictlyPositive_iff _).mpr hσs + have hρABd : ρAB.IsDensityOp := hρ''d.of_partialTraceRight_eq bG hρAB + have hρABs : IsStrictlyPositive ρAB := hρ''s.of_partialTraceRight_eq bG hρAB + -- `Tr_F ρ_{EF} = ρ_E` and `Tr_E ρ_{EF} = ρ_F` via the associator tower lemmas. + have hAB_A : LinearMap.partialTraceRight bF ρAB.toLinearMap = ρA.toLinearMap := + LinearMap.partialTraceRight_eq_of_partialTraceRight_assocIsometry bF bG hρAB hρA + have hAB_B : LinearMap.partialTraceLeft bE ρAB.toLinearMap = ρB.toLinearMap := by + rw [← hρAB, LinearMap.assocIsometry_symm_conjStarAlgEquiv_toLinearMap, + LinearMap.partialTraceLeft_partialTraceRight_assoc, hρBC, hρB] + -- The two mutual informations, via the mutual-information identity. + have hBi : ρ.quantumRelativeEntropy (TensorProduct.mapL ρA ρBC) = + ρA.vonNeumannEntropy + ρBC.vonNeumannEntropy - ρ.vonNeumannEntropy := + quantumRelativeEntropy_mapL_partialTrace_eq bE (bF.tensorProduct bG) hρ hρs hρA hρBC + have hBii : ρAB.quantumRelativeEntropy (TensorProduct.mapL ρA ρB) = + ρA.vonNeumannEntropy + ρB.vonNeumannEntropy - ρAB.vonNeumannEntropy := + quantumRelativeEntropy_mapL_partialTrace_eq bE bF hρABd hρABs hAB_A hAB_B + -- The two `G`-marginals of the re-associated states: `Tr_G ρ'' = ρ_{EF}`, `Tr_G σ'' = ρ_E ⊗ ρ_F`. + have e1 : LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight bG + ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv ρ).toLinearMap) = ρAB := by + rw [hρAB]; exact ContinuousLinearMap.toLinearMap_toContinuousLinearMap ρAB + have e2 : LinearMap.toContinuousLinearMap (LinearMap.partialTraceRight bG + ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv + (TensorProduct.mapL ρA ρBC)).toLinearMap) = TensorProduct.mapL ρA ρB := by + rw [LinearMap.assocIsometry_symm_conjStarAlgEquiv_toLinearMap, TensorProduct.toLinearMap_mapL, + LinearMap.partialTraceRight_assoc_conj_map, hρB, ← TensorProduct.toLinearMap_mapL, + ContinuousLinearMap.toLinearMap_toContinuousLinearMap] + -- Invariance of the relative entropy under the associator. + have hinv : ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv ρ).quantumRelativeEntropy + ((TensorProduct.assocIsometry ℂ E F G).symm.conjStarAlgEquiv (TensorProduct.mapL ρA ρBC)) = + ρ.quantumRelativeEntropy (TensorProduct.mapL ρA ρBC) := + quantumRelativeEntropy_conjStarAlgEquiv_of_isStrictlyPositive _ hρs hσs + -- Monotonicity of the relative entropy under tracing out `G`, rewritten to the SSA form. + have hmono := quantumRelativeEntropy_partialTraceRight_le bG hρ''d hσ''d hρ''s hσ''s + simp only [e1, e2, hinv] at hmono + rw [hBi, hBii] at hmono + linarith + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneProjector.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneProjector.lean new file mode 100644 index 0000000000..d8d1f948da --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneProjector.lean @@ -0,0 +1,277 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.FieldTheory.IsAlgClosed.Spectrum +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Eigenspace.Idempotent + +/-! +# The orthogonal projector onto the span of an orthonormal family + +Given a family of vectors `v : ι → E` in an inner product space `E` over `𝕜` (`ℝ` or `ℂ`) and a +finite index set `s : Finset ι`, this file introduces the **projector** + +`orthonormalProjector 𝕜 v s = ∑ i ∈ s, |v i⟩⟨v i|` +(i.e. `∑ i ∈ s, InnerProductSpace.rankOne 𝕜 (v i) (v i)`) + +and records its defining properties when the family is orthonormal. This is exactly Nielsen & +Chuang's projector (*Quantum Computation and Quantum Information*, eq. (2.35)): for an orthonormal +basis `|1⟩, …, |d⟩` of `V` whose first `k` vectors span a subspace `W`, the operator +`P ≡ ∑_{i=1}^{k} |i⟩⟨i|` is the projector onto `W` (here `s = {1, …, k}`). + +## Main results + +* `InnerProductSpace.orthonormalProjector_apply`: the action `P y = ∑ i ∈ s, ⟪v i, y⟫ • v i`. +* `InnerProductSpace.orthonormalProjector_apply_eq_ite`: for an orthonormal family, the action on a + family vector is `P (v κ) = if κ ∈ s then v κ else 0`. +* `InnerProductSpace.isIdempotentElem_orthonormalProjector`: **Nielsen & Chuang, Exercise 2.16** — + for an orthonormal family, `P` is idempotent, i.e. `P ∘ P = P` (`P² = P`). +* `InnerProductSpace.isSelfAdjoint_orthonormalProjector`: `P` is self-adjoint, `P† = P` (N&C's + remark that a projector is Hermitian). This needs no orthonormality: each `|v i⟩⟨v i|` is already + self-adjoint. +* `InnerProductSpace.isStarProjection_orthonormalProjector`: for an orthonormal family, `P` is a + star projection (a self-adjoint idempotent) — a genuine orthogonal projector. +* `InnerProductSpace.spectrum_orthonormalProjector_subset`: **Nielsen & Chuang, Exercise 2.23** + (spectrum form) — `spectrum 𝕜 P ⊆ {0, 1}`. +* `InnerProductSpace.orthonormalProjector_hasEigenvalue_eq_zero_or_one`: **Nielsen & Chuang, + Exercise 2.23** (eigenvalue form) — every eigenvalue of `P` is `0` or `1`. +* `InnerProductSpace.orthonormalProjector_adjoint_comp_self`: `P† ∘ P = P` for an orthonormal + family (`P` is a star projection). +* `InnerProductSpace.trace_orthonormalProjector`: for an orthonormal basis, `tr P = |s|`. +* `InnerProductSpace.trace_orthonormalProjector_comp`: `tr(P ∘ D) = ∑ i ∈ s, ⟪b i, D (b i)⟫`. + +The idempotence proof is N&C's own computation: composing the sums bilinearly, +`(∑ i, |v i⟩⟨v i|)(∑ j, |v j⟩⟨v j|) = ∑ i ∑ j ⟪v i, v j⟫ |v i⟩⟨v j|` +(`InnerProductSpace.rankOne_comp_rankOne`), and orthonormality `⟪v i, v j⟫ = δ_{ij}` collapses the +double sum back to `∑ i, |v i⟩⟨v i|`. The single-vector case (`s` a singleton, `‖v i‖ = 1`) is the +existing `InnerProductSpace.isStarProjection_rankOne_self`. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace InnerProductSpace + +variable {𝕜 : Type*} {E : Type*} {ι : Type*} + [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +/-- **Nielsen & Chuang's projector** (eq. (2.35)). Given a family `v : ι → E` and a finite index set +`s : Finset ι`, the operator `∑ i ∈ s, |v i⟩⟨v i|`. This is genuinely a projector precisely when `v` +is orthonormal, in which case it is the orthogonal projector onto the span of `{v i | i ∈ s}` (see +`isStarProjection_orthonormalProjector`); the bare definition imposes no orthonormality. `𝕜` is an +explicit argument, matching the summand `rankOne 𝕜 …`. -/ +noncomputable def orthonormalProjector (𝕜 : Type*) {E ι : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] (v : ι → E) (s : Finset ι) : E →L[𝕜] E := + ∑ i ∈ s, rankOne 𝕜 (v i) (v i) + +/-- The projector `orthonormalProjector 𝕜 v s` is, by definition, the sum of rank-one projectors +`∑ i ∈ s, |v i⟩⟨v i|`. -/ +theorem orthonormalProjector_eq_sum (v : ι → E) (s : Finset ι) : + orthonormalProjector 𝕜 v s = ∑ i ∈ s, rankOne 𝕜 (v i) (v i) := rfl + +/-- The action of the projector `∑ i ∈ s, |v i⟩⟨v i|` on a vector `y` is `∑ i ∈ s, ⟪v i, y⟫ • v i`: +each rank-one term `|v i⟩⟨v i|` contracts `y` against `v i` and scales `v i` by the result. -/ +@[simp] +theorem orthonormalProjector_apply (v : ι → E) (s : Finset ι) (y : E) : + orthonormalProjector 𝕜 v s y = ∑ i ∈ s, (inner 𝕜 (v i) y) • v i := by + simp only [orthonormalProjector, sum_apply, rankOne_apply] + +/-- **The projector applied to a member of its own orthonormal family.** For an orthonormal family +`v`, the projector `P = ∑ i ∈ s, |v i⟩⟨v i|` fixes `v κ` when `κ ∈ s` and annihilates it otherwise: +`P (v κ) = if κ ∈ s then v κ else 0`. Immediate from `orthonormalProjector_apply` and orthonormality +`⟪v i, v κ⟫ = δ_{iκ}` (`orthonormal_iff_ite`), which collapses the `s`-sum to its `i = κ` term +(`Finset.sum_ite_eq'`). This is the diagonalisation `P` is used through when the family is a +*spectral* eigenbasis (`P` and the diagonal operator commute and share eigenvectors). -/ +theorem orthonormalProjector_apply_eq_ite [DecidableEq ι] {v : ι → E} (hv : Orthonormal 𝕜 v) + (s : Finset ι) (κ : ι) : + orthonormalProjector 𝕜 v s (v κ) = if κ ∈ s then v κ else 0 := by + rw [orthonormalProjector_apply] + simp only [orthonormal_iff_ite.mp hv, ite_smul, one_smul, zero_smul] + rw [Finset.sum_ite_eq' s κ v] + +/-- **Rank-one self-projections of an orthonormal family pairwise annihilate.** For an orthonormal +family `v : ι → E` and `i ≠ j`, the self-projectors compose to zero: +`|v i⟩⟨v i| · |v j⟩⟨v j| = ⟪v i, v j⟫ • |v i⟩⟨v j| = 0`, since `⟪v i, v j⟫ = 0` +(`rankOne_comp_rankOne` + orthonormality). This is the off-diagonal vanishing underlying +idempotence of `orthonormalProjector`, and the block-orthogonality input to the joint entropy +theorem (`AxQM.State.vonNeumannEntropy_jointEntropyTheorem` and its flag-right mirror). -/ +theorem rankOne_self_mul_rankOne_self_eq_zero_of_orthonormal {v : ι → E} + (hv : Orthonormal 𝕜 v) {i j : ι} (hij : i ≠ j) : + rankOne 𝕜 (v i) (v i) * rankOne 𝕜 (v j) (v j) = 0 := by + rw [ContinuousLinearMap.mul_def, rankOne_comp_rankOne, hv.2 hij, zero_smul] + +/-- **Nielsen & Chuang, Exercise 2.16.** Any projector `P = ∑ i ∈ s, |v i⟩⟨v i|` of an orthonormal +family `v` satisfies `P² = P`, i.e. `P` is idempotent (`P ∘ P = P`). + +Composing the two sums bilinearly gives `∑ i ∑ j ⟪v i, v j⟫ |v i⟩⟨v j|` +(`rankOne_comp_rankOne`); orthonormality `⟪v i, v j⟫ = δ_{ij}` kills all off-diagonal terms, leaving +`∑ i, |v i⟩⟨v i| = P`. -/ +theorem isIdempotentElem_orthonormalProjector {v : ι → E} (hv : Orthonormal 𝕜 v) (s : Finset ι) : + IsIdempotentElem (orthonormalProjector 𝕜 v s) := by + classical + have hb : ∀ i j : ι, (inner 𝕜 (v i) (v j) : 𝕜) = if i = j then (1 : 𝕜) else 0 := + fun i j => orthonormal_iff_ite.mp hv i j + rw [IsIdempotentElem, ContinuousLinearMap.mul_def, orthonormalProjector] + simp only [ContinuousLinearMap.finsetSum_comp, ContinuousLinearMap.comp_finsetSum, + rankOne_comp_rankOne, hb, ite_smul, one_smul, zero_smul] + refine Finset.sum_congr rfl fun i hi => ?_ + rw [Finset.sum_ite_eq', ite_eq_left hi] + +/-- The projector `P = ∑ i ∈ s, |v i⟩⟨v i|` is self-adjoint, `P† = P` (Nielsen & Chuang's remark +that a projector is Hermitian). This holds for *any* family `v`: the adjoint of each rank-one term +`|v i⟩⟨v i|` is itself (`adjoint_rankOne`), so orthonormality is not needed here. -/ +theorem isSelfAdjoint_orthonormalProjector [CompleteSpace E] (v : ι → E) (s : Finset ι) : + IsSelfAdjoint (orthonormalProjector 𝕜 v s) := by + rw [IsSelfAdjoint, ContinuousLinearMap.star_eq_adjoint, orthonormalProjector, map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [adjoint_rankOne] + +/-- For an orthonormal family `v`, the projector `P = ∑ i ∈ s, |v i⟩⟨v i|` is a **star projection** +— a self-adjoint idempotent — hence a genuine orthogonal projector onto the span of `{v i | i ∈ s}`. +This combines idempotence (`isIdempotentElem_orthonormalProjector`, Nielsen & Chuang Exercise 2.16) +with self-adjointness (`isSelfAdjoint_orthonormalProjector`), and generalizes the single-vector +`isStarProjection_rankOne_self` from one unit vector to a sum over an orthonormal family. -/ +theorem isStarProjection_orthonormalProjector [CompleteSpace E] {v : ι → E} (hv : Orthonormal 𝕜 v) + (s : Finset ι) : IsStarProjection (orthonormalProjector 𝕜 v s) := + ⟨isIdempotentElem_orthonormalProjector hv s, isSelfAdjoint_orthonormalProjector v s⟩ + +/-- **`P† ∘ P = P` for an orthonormal projector.** Since `P = ∑ i ∈ s, |v i⟩⟨v i|` of an orthonormal +family is a star projection (`isStarProjection_orthonormalProjector`) — self-adjoint and idempotent +— its adjoint-composed-with-itself collapses to `P`. This is the `re tr(P† P ρ)` Born-trace +simplification (`p(m) = re tr(Mₘ ρ Mₘ†)` for a projective `Mₘ = P`), routed through the +`IsStarProjection.star_mul_self` API. -/ +theorem orthonormalProjector_adjoint_comp_self [CompleteSpace E] {v : ι → E} (hv : Orthonormal 𝕜 v) + (s : Finset ι) : + (ContinuousLinearMap.adjoint (orthonormalProjector 𝕜 v s)).comp (orthonormalProjector 𝕜 v s) + = orthonormalProjector 𝕜 v s := by + have hp := isStarProjection_orthonormalProjector hv s + rw [← ContinuousLinearMap.star_eq_adjoint, ← ContinuousLinearMap.mul_def, hp.isSelfAdjoint] + exact hp.isIdempotentElem + +/-- **Nielsen & Chuang, Exercise 2.23** (spectrum form). The spectrum of the projector +`P = ∑ i ∈ s, |v i⟩⟨v i|` of an orthonormal family is contained in `{0, 1}`: every spectral value — +in particular every eigenvalue — of a projector is `0` or `1`. + +`P` is idempotent (`isIdempotentElem_orthonormalProjector`, Exercise 2.16), and the spectrum of any +idempotent element of a `𝕜`-algebra lies in `{0, 1}` (`IsIdempotentElem.spectrum_subset`). -/ +theorem spectrum_orthonormalProjector_subset {v : ι → E} (hv : Orthonormal 𝕜 v) (s : Finset ι) : + spectrum 𝕜 (orthonormalProjector 𝕜 v s) ⊆ {0, 1} := + (isIdempotentElem_orthonormalProjector hv s).spectrum_subset 𝕜 + +/-- **Nielsen & Chuang, Exercise 2.23** (eigenvalue form). Every eigenvalue `μ` of the projector +`P = ∑ i ∈ s, |v i⟩⟨v i|` of an orthonormal family is either `0` or `1`. + +This is the eigenvalue-predicate reading of the exercise: `P`, viewed as a linear map, is idempotent +(the idempotence of the continuous linear map from `isIdempotentElem_orthonormalProjector`, +Exercise 2.16, transported along the coercion `E →L[𝕜] E → E →ₗ[𝕜] E`), and every eigenvalue of an +idempotent operator is `0` or `1` +(`Module.End.HasEigenvalue.eq_zero_or_one_of_isIdempotentElem`). -/ +theorem orthonormalProjector_hasEigenvalue_eq_zero_or_one {v : ι → E} (hv : Orthonormal 𝕜 v) + (s : Finset ι) {μ : 𝕜} + (h : Module.End.HasEigenvalue (orthonormalProjector 𝕜 v s : E →ₗ[𝕜] E) μ) : + μ = 0 ∨ μ = 1 := by + refine h.eq_zero_or_one_of_isIdempotentElem ?_ + rw [IsIdempotentElem, ← ContinuousLinearMap.toLinearMap_mul, + (isIdempotentElem_orthonormalProjector hv s).eq] + +/-- **The projector sandwich collapses to a scalar** when `M`'s matrix in the family is scalar. For +the projector `P = ∑ i ∈ s, |v i⟩⟨v i|` of *any* family `v`, if the matrix elements +`⟪v i, M (v j)⟫` of an operator `M` equal a constant `c` on the diagonal (`i = j`) and vanish off +it, for all `i, j ∈ s`, then `P M P = c • P`. No orthonormality is needed. + +This is the Knill–Laflamme reduction: for a code projector `P` onto a family of codewords, the +operator identity `P M P = c • P` is equivalent to the finite matrix-element conditions +`⟪v i, M (v j)⟫ = c δ_{ij}` — the shape in which `P Eₐ† E_b P = α_{ab} P` is verified (with +`M = Eₐ† E_b`, `c = α_{ab}`). Proved by evaluating both sides at `y`, expanding +`P M P y = ∑ᵢ ⟪v i, M (∑ⱼ ⟪v j, y⟫ • v j)⟫ • v i` (`orthonormalProjector_apply`), and collapsing the +inner `j`-sum to its `j = i` term by the hypotheses. -/ +theorem orthonormalProjector_comp_comp_orthonormalProjector_eq_smul {v : ι → E} (s : Finset ι) + {M : E →L[𝕜] E} {c : 𝕜} + (hdiag : ∀ i ∈ s, (inner 𝕜 (v i) (M (v i)) : 𝕜) = c) + (hoff : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → (inner 𝕜 (v i) (M (v j)) : 𝕜) = 0) : + orthonormalProjector 𝕜 v s ∘L M ∘L orthonormalProjector 𝕜 v s + = c • orthonormalProjector 𝕜 v s := by + ext y + simp only [ContinuousLinearMap.comp_apply, orthonormalProjector_apply, map_sum, map_smul, + smul_apply, Finset.smul_sum] + refine Finset.sum_congr rfl fun i hi => ?_ + rw [Finset.sum_eq_single_of_mem i hi + (fun j hj hji => by rw [hoff j hj i hi hji, zero_smul, smul_zero]), + hdiag i hi, smul_comm] + +/-- **Trace of the orthonormal projector.** For an orthonormal basis `b` of `E`, the trace of +`P = ∑ i ∈ s, |b i⟩⟨b i|` is the size of `s` — the dimension of the subspace it projects onto: +`tr P = |s|`. Computed in the basis `b` (`LinearMap.trace_eq_sum_inner`), where `P` is diagonal with +a `0/1` spectrum (`orthonormalProjector_apply_eq_ite`), so the trace counts the `1`-eigenvalues. -/ +theorem trace_orthonormalProjector [Fintype ι] (b : OrthonormalBasis ι 𝕜 E) + (s : Finset ι) : + LinearMap.trace 𝕜 E (orthonormalProjector 𝕜 (⇑b) s : E →ₗ[𝕜] E) = (s.card : 𝕜) := by + classical + rw [LinearMap.trace_eq_sum_inner _ b] + have hd : ∀ x, inner 𝕜 (b x) (orthonormalProjector 𝕜 (⇑b) s (b x)) + = if x ∈ s then (1 : 𝕜) else 0 := by + intro x + rw [orthonormalProjector_apply_eq_ite b.orthonormal] + split_ifs with h + · rw [orthonormal_iff_ite.mp b.orthonormal]; simp + · rw [inner_zero_right] + simp only [ContinuousLinearMap.coe_coe] + rw [Finset.sum_congr rfl (fun x _ => hd x), Finset.sum_ite_mem, Finset.univ_inter, + Finset.sum_const, nsmul_eq_mul, mul_one] + +/-- **Trace of an orthonormal projector composed with an operator.** For an orthonormal basis `b`, +`tr(P ∘ D) = ∑ i ∈ s, ⟪b i, D (b i)⟫` where `P = ∑ i ∈ s, |b i⟩⟨b i|`: left-composing with the +projector restricts the trace to the diagonal entries of `D` over the projected indices `s`. Uses +self-adjointness of `P` (`isSelfAdjoint_orthonormalProjector`) to move it into the left inner slot +(`adjoint_inner_left`), then `orthonormalProjector_apply_eq_ite` keeps only the `s`-diagonal. +Specialises to `trace_orthonormalProjector` at `D = 1`, and is the projector-diagonalisation step +of a Born probability `re tr(P ρ)`. -/ +theorem trace_orthonormalProjector_comp [CompleteSpace E] [Fintype ι] + (b : OrthonormalBasis ι 𝕜 E) (s : Finset ι) (D : E →L[𝕜] E) : + LinearMap.trace 𝕜 E ((orthonormalProjector 𝕜 (⇑b) s).comp D : E →ₗ[𝕜] E) + = ∑ i ∈ s, inner 𝕜 (b i) (D (b i)) := by + classical + rw [LinearMap.trace_eq_sum_inner _ b] + have hd : ∀ x, inner 𝕜 (b x) (((orthonormalProjector 𝕜 (⇑b) s).comp D) (b x)) + = if x ∈ s then inner 𝕜 (b x) (D (b x)) else 0 := by + intro x + rw [ContinuousLinearMap.comp_apply, ← ContinuousLinearMap.adjoint_inner_left, + ← ContinuousLinearMap.star_eq_adjoint, (isSelfAdjoint_orthonormalProjector (⇑b) s).star_eq, + orthonormalProjector_apply_eq_ite b.orthonormal] + split_ifs with h + · rfl + · rw [inner_zero_left] + simp only [ContinuousLinearMap.coe_coe] + rw [Finset.sum_congr rfl (fun x _ => hd x), Finset.sum_ite_mem, Finset.univ_inter] + +/-- **The rank of the orthonormal projector `∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` is `s.card`.** Being an idempotent, +`P = orthonormalProjector 𝕜 b s` is a projection onto its range, so its trace equals +`finrank (range P)` (`LinearMap.IsProj.trace`); and its trace is `s.card` +(`trace_orthonormalProjector`). Equating the two casts gives the rank. The ambient space is +finite-dimensional because `b` is a finite orthonormal basis. -/ +theorem finrank_range_orthonormalProjector [Fintype ι] (b : OrthonormalBasis ι 𝕜 E) + (s : Finset ι) : + Module.finrank 𝕜 (LinearMap.range (orthonormalProjector 𝕜 (⇑b) s : E →ₗ[𝕜] E)) = s.card := by + have : FiniteDimensional 𝕜 E := b.toBasis.finiteDimensional_of_finite + have hproj : LinearMap.IsProj (LinearMap.range (orthonormalProjector 𝕜 (⇑b) s : E →ₗ[𝕜] E)) + (orthonormalProjector 𝕜 (⇑b) s : E →ₗ[𝕜] E) := + LinearMap.IsIdempotentElem.isProj_range _ + (ContinuousLinearMap.IsIdempotentElem.toLinearMap + (isIdempotentElem_orthonormalProjector b.orthonormal s)) + have hcast : + (Module.finrank 𝕜 (LinearMap.range (orthonormalProjector 𝕜 (⇑b) s : E →ₗ[𝕜] E)) : 𝕜) + = (s.card : 𝕜) := + hproj.trace.symm.trans (trace_orthonormalProjector b s) + exact_mod_cast hcast + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneSum.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneSum.lean new file mode 100644 index 0000000000..d5743858ea --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneSum.lean @@ -0,0 +1,380 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import Mathlib.LinearAlgebra.UnitaryGroup + +/-! # The synthesis operator of a finite family of vectors and its sum of rank-one projectors + +Given a finite family of vectors `ψ : ι → H` in an inner product space, this file introduces the +**synthesis operator** `synthesisMap ψ : EuclideanSpace 𝕜 ι →L[𝕜] H`, the continuous linear map +sending the `i`-th standard basis vector to `ψ i` (equivalently `x ↦ ∑ i, x i • ψ i`), and records +the identity that relates it to the sum of rank-one projectors of the family: + +* `InnerProductSpace.sum_rankOne_self_eq_synthesisMap_comp_adjoint`: + `∑ i, |ψ i⟩⟨ψ i| = (synthesisMap ψ) ∘L (synthesisMap ψ)†`. + +This is the operator reformulation at the heart of the "unitary freedom in the ensemble" theorem +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 2.6): a family of vectors +`ψ` generates the operator `∑ i, |ψ i⟩⟨ψ i|`, and this operator is exactly `T T†` for the synthesis +operator `T = synthesisMap ψ`. Two families generate the same operator iff their synthesis operators +have equal `T T†`, which happens iff they differ by a unitary on the coefficient space +`EuclideanSpace 𝕜 ι` — the source of the "unitary freedom". + +This file also records the *forward* (easy) direction of that theorem: + +* `InnerProductSpace.sum_rankOne_self_eq_of_mem_unitaryGroup`: if the coefficient matrix relating + two families is unitary, the two families generate the same operator, i.e. + `∑ i, |∑ⱼ uᵢⱼ φⱼ⟩⟨∑ⱼ uᵢⱼ φⱼ| = ∑ j, |φ j⟩⟨φ j|` (N&C eqs. (2.168)–(2.171)). + +Finally it records the **dimension reduction** counterpart of the unitary freedom: while a unitary +mixing keeps the number of terms fixed, the number of *essential* terms is capped by the dimension. + +* `ContinuousLinearMap.IsPositive.exists_sum_rankOne_fin_finrank`: a positive operator is a sum of + `finrank`-many rank-one projectors — the `finrank`-explicit refinement of + `ContinuousLinearMap.isPositive_iff_eq_sum_rankOne`. +* `InnerProductSpace.exists_sum_rankOne_self_eq_fin_finrank`: any sum `∑ᵢ |vᵢ⟩⟨vᵢ|` over an + arbitrarily large finite family equals a sum `∑ₖ |wₖ⟩⟨wₖ|` of at most `finrank` rank-one + projectors. This is the linear-algebra core of the minimal operator-sum representation bound + (Nielsen & Chuang Theorem 8.3: at most `d²` operation elements, via the Choi vectors on `H ⊗ H`). +-/ + +@[expose] public section + +open scoped InnerProductSpace +open Finset + +namespace InnerProductSpace + +variable {𝕜 : Type*} {H : Type*} {ι : Type*} + [RCLike 𝕜] [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [Fintype ι] + +/-- The **synthesis operator** of a finite family of vectors `ψ : ι → H`: the continuous linear map +`EuclideanSpace 𝕜 ι →L[𝕜] H` sending the `i`-th standard basis vector to `ψ i`, so that +`synthesisMap ψ x = ∑ i, x i • ψ i`. Written as the sum of rank-one operators +`∑ i, |ψ i⟩⟨eᵢ|` where `eᵢ` is the `i`-th standard basis vector of `EuclideanSpace 𝕜 ι`. + +The composition `(synthesisMap ψ) ∘L (synthesisMap ψ)†` equals the sum of rank-one projectors +`∑ i, |ψ i⟩⟨ψ i|` (`sum_rankOne_self_eq_synthesisMap_comp_adjoint`): the operator "generated" by the +family in the sense of Nielsen & Chuang §2.4.1. -/ +noncomputable def synthesisMap (ψ : ι → H) : EuclideanSpace 𝕜 ι →L[𝕜] H := + ∑ i, rankOne 𝕜 (ψ i) (EuclideanSpace.basisFun ι 𝕜 i) + +@[simp] +theorem synthesisMap_apply (ψ : ι → H) (x : EuclideanSpace 𝕜 ι) : + synthesisMap ψ x = ∑ i, x i • ψ i := by + simp only [synthesisMap, _root_.sum_apply, rankOne_apply, + EuclideanSpace.basisFun_inner] + +/-- **The operator generated by a family is `T T†` for the synthesis operator `T`.** The sum of +rank-one projectors `∑ i, |ψ i⟩⟨ψ i|` of a finite family `ψ` equals `(synthesisMap ψ) ∘L +(synthesisMap ψ)†`. This is the operator reformulation underlying Nielsen & Chuang Theorem 2.6: +the family `ψ` "generates" the operator `∑ i, |ψ i⟩⟨ψ i|`, and that operator is the Gram-type +product `T T†` of the synthesis operator. -/ +theorem sum_rankOne_self_eq_synthesisMap_comp_adjoint [CompleteSpace H] (ψ : ι → H) : + ∑ i, rankOne 𝕜 (ψ i) (ψ i) + = (synthesisMap ψ).comp (ContinuousLinearMap.adjoint (synthesisMap ψ)) := by + classical + have hb : ∀ i j : ι, + (inner 𝕜 (EuclideanSpace.basisFun ι 𝕜 i) (EuclideanSpace.basisFun ι 𝕜 j) : 𝕜) + = if i = j then (1 : 𝕜) else 0 := + fun i j => orthonormal_iff_ite.mp (EuclideanSpace.basisFun ι 𝕜).orthonormal i j + simp only [synthesisMap, map_sum, adjoint_rankOne, ContinuousLinearMap.finsetSum_comp, + ContinuousLinearMap.comp_finsetSum, rankOne_comp_rankOne, hb, ite_smul, one_smul, zero_smul, + Finset.sum_ite_eq', Finset.mem_univ, ite_true] + +/-- **Forward direction of unitary freedom in the ensemble** (Nielsen & Chuang, Theorem 2.6, +eqs. (2.168)–(2.171)). If two finite families of vectors are related by a unitary coefficient +matrix `u`, i.e. `ψ i = ∑ⱼ uᵢⱼ • φⱼ`, then they generate the same operator: +`∑ i, |ψ i⟩⟨ψ i| = ∑ j, |φ j⟩⟨φ j|`. + +Concretely, expanding each `|ψ i⟩⟨ψ i|` bilinearly gives `∑ⱼ∑ₖ (uᵢⱼ conj uᵢₖ) |φⱼ⟩⟨φₖ|`; summing +over `i` collapses the coefficient `∑ᵢ uᵢⱼ conj uᵢₖ = (u⋆ u)ₖⱼ = δₖⱼ` by unitarity, leaving +`∑ⱼ |φⱼ⟩⟨φⱼ|`. -/ +theorem sum_rankOne_self_eq_of_mem_unitaryGroup [DecidableEq ι] {u : Matrix ι ι 𝕜} + (hu : u ∈ Matrix.unitaryGroup ι 𝕜) (φ : ι → H) : + ∑ i, rankOne 𝕜 (∑ j, u i j • φ j) (∑ j, u i j • φ j) = ∑ i, rankOne 𝕜 (φ i) (φ i) := by + have key : ∀ j k : ι, + (∑ i, u i j * (starRingEnd 𝕜) (u i k)) = if k = j then (1 : 𝕜) else 0 := by + intro j k + have h1 : (star u * u : Matrix ι ι 𝕜) = 1 := Matrix.mem_unitaryGroup_iff'.mp hu + have h2 := congrFun (congrFun h1 k) j + rw [Matrix.mul_apply, Matrix.one_apply] at h2 + rw [← h2] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Matrix.star_apply, starRingEnd_apply] + exact mul_comm _ _ + calc ∑ i, rankOne 𝕜 (∑ j, u i j • φ j) (∑ j, u i j • φ j) + = ∑ i, ∑ j, ∑ k, (u i j * (starRingEnd 𝕜) (u i k)) • rankOne 𝕜 (φ j) (φ k) := by + simp only [rankOne_sum_smul_sum_smul] + _ = ∑ j, ∑ k, ∑ i, (u i j * (starRingEnd 𝕜) (u i k)) • rankOne 𝕜 (φ j) (φ k) := by + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun j _ => Finset.sum_comm + _ = ∑ j, ∑ k, (∑ i, u i j * (starRingEnd 𝕜) (u i k)) • rankOne 𝕜 (φ j) (φ k) := by + simp only [Finset.sum_smul] + _ = ∑ j, ∑ k, (if k = j then (1 : 𝕜) else 0) • rankOne 𝕜 (φ j) (φ k) := by + simp only [key] + _ = ∑ i, rankOne 𝕜 (φ i) (φ i) := by + simp only [ite_smul, one_smul, zero_smul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + +end InnerProductSpace + +namespace ContinuousLinearMap + +open InnerProductSpace + +variable {𝕜 : Type*} [RCLike 𝕜] + +/-- **Rectangular operator crux of unitary freedom in the ensemble.** For continuous linear maps +`S T : K →L[𝕜] H` from a finite-dimensional inner product space `K` to a complete inner product +space `H`, if `T ∘L T† = S ∘L S†` then there is a *unitary* `W` on `K` with `T = S ∘L W`. + +This is the operator statement at the heart of Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 2.6: two finite families of vectors generate the same operator +(`∑ i, |ψ i⟩⟨ψ i| = ∑ i, |φ i⟩⟨φ i|`) iff their synthesis operators `T`, `S` +(`InnerProductSpace.synthesisMap`) satisfy `T T† = S S†`, and this crux produces the unitary +relating them (whose matrix is the unitary coefficient matrix of the theorem). Only the coefficient +space `K` need be finite-dimensional; `H` may be infinite-dimensional. + +The converse of the trivial forward direction (`T = S ∘L W`, `W` unitary, gives +`T T† = S W W† S† = S S†`), its proof mirrors +`ContinuousLinearMap.exists_mem_unitary_eq_comp_absoluteValue`: from `T T† = S S†` the adjoints are +equinorm, `‖T† y‖ = ‖S† y‖` (both squares equal `re ⟪y, (A A†) y⟫`), so `S† y ↦ T† y` is a +well-defined linear isometry `L` on the submodule `range S† ⊆ K`. Extending `L` to a full isometry +of `K` (`LinearIsometry.extend`) and upgrading to a `LinearIsometryEquiv` (equal dimension) yields a +unitary `V` with `V (S† y) = T† y`; taking adjoints gives `T = S ∘L V†`, so `W = V† = star V`. -/ +theorem exists_unitary_comp_of_comp_adjoint_eq {K H : Type*} + [NormedAddCommGroup K] [InnerProductSpace 𝕜 K] [FiniteDimensional 𝕜 K] [CompleteSpace K] + [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [CompleteSpace H] + {S T : K →L[𝕜] H} (hST : T.comp (adjoint T) = S.comp (adjoint S)) : + ∃ W ∈ unitary (K →L[𝕜] K), T = S.comp W := by + classical + -- The adjoints are equinorm on `H`: `‖T† y‖ = ‖S† y‖`. + have hnorm : ∀ y : H, ‖(adjoint T) y‖ = ‖(adjoint S) y‖ := by + intro y + have hEq : ⟪(adjoint T) y, (adjoint T) y⟫_𝕜 = ⟪(adjoint S) y, (adjoint S) y⟫_𝕜 := by + rw [adjoint_inner_left, ← comp_apply, hST, comp_apply, ← adjoint_inner_left] + have hre := congrArg RCLike.re hEq + rwa [inner_self_eq_norm_sq, inner_self_eq_norm_sq, + sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)] at hre + -- `S† y` determines `T† y`: the assignment is well-defined. + have hwd : ∀ y₁ y₂ : H, (adjoint S) y₁ = (adjoint S) y₂ → (adjoint T) y₁ = (adjoint T) y₂ := by + intro y₁ y₂ he + have h0 : (adjoint S) (y₁ - y₂) = 0 := by rw [map_sub, he, sub_self] + have hn : ‖(adjoint T) (y₁ - y₂)‖ = 0 := by rw [hnorm, h0, norm_zero] + have hz : (adjoint T) (y₁ - y₂) = 0 := norm_eq_zero.mp hn + rwa [map_sub, sub_eq_zero] at hz + -- The linear isometry `L : range S† →ₗᵢ K`, `S† y ↦ T† y`. + set P : Submodule 𝕜 K := LinearMap.range (adjoint S : H →ₗ[𝕜] K) with hPdef + have hspec : ∀ v : ↥P, (adjoint S) (Classical.choose v.2) = (v : K) := + fun v => Classical.choose_spec v.2 + let L₀ : ↥P →ₗ[𝕜] K := + { toFun := fun v => (adjoint T) (Classical.choose v.2) + map_add' := fun v w => by + have hkey : (adjoint T) (Classical.choose (v + w).2) + = (adjoint T) (Classical.choose v.2 + Classical.choose w.2) := by + refine hwd _ _ ?_ + rw [map_add, hspec (v + w), hspec v, hspec w, Submodule.coe_add] + rw [hkey, map_add] + map_smul' := fun c v => by + have hkey : (adjoint T) (Classical.choose (c • v).2) + = (adjoint T) (c • Classical.choose v.2) := by + refine hwd _ _ ?_ + rw [map_smul, hspec (c • v), hspec v, Submodule.coe_smul] + rw [hkey, map_smul] + rfl } + let L : ↥P →ₗᵢ[𝕜] K := + { toLinearMap := L₀ + norm_map' := fun v => by + change ‖(adjoint T) (Classical.choose v.2)‖ = ‖(v : K)‖ + rw [hnorm, hspec v] } + -- Extend to a unitary `V` on `K` with `V (S† y) = T† y`. + set V : K ≃ₗᵢ[𝕜] K := (L.extend).toLinearIsometryEquiv rfl with hVdef + have hVspec : ∀ y : H, V ((adjoint S) y) = (adjoint T) y := by + intro y + have hmem : (adjoint S) y ∈ P := ⟨y, rfl⟩ + have hVL : V ((adjoint S) y) = L ⟨(adjoint S) y, hmem⟩ := by + rw [hVdef, LinearIsometry.coe_toLinearIsometryEquiv] + exact LinearIsometry.extend_apply L ⟨(adjoint S) y, hmem⟩ + rw [hVL] + exact hwd _ _ (Classical.choose_spec hmem) + -- Package `V` as a unitary and read off `W = V†`. + set Vu : ↥(unitary (K →L[𝕜] K)) := Unitary.linearIsometryEquiv.symm V with hVu + have hcomp : (Vu : K →L[𝕜] K).comp (adjoint S) = adjoint T := by + ext y + simp only [comp_apply] + rw [hVu, Unitary.coe_symm_linearIsometryEquiv_apply] + exact hVspec y + refine ⟨adjoint (Vu : K →L[𝕜] K), ?_, ?_⟩ + · rw [← star_eq_adjoint] + exact Unitary.star_mem Vu.2 + · have hadj := congrArg adjoint hcomp + rw [adjoint_comp, adjoint_adjoint, adjoint_adjoint] at hadj + exact hadj.symm + +/-- **A positive operator is a sum of at most `finrank` rank-one projectors.** On a +finite-dimensional inner product space `E`, every positive operator `T` equals `∑ᵢ |uᵢ⟩⟨uᵢ|` for a +family `u` indexed by `Fin (finrank 𝕜 E)`. This is the `finrank`-explicit refinement of +`ContinuousLinearMap.isPositive_iff_eq_sum_rankOne`, which only asserts the existence of *some* +finite number of summands; here the number is pinned to the dimension. The witnesses are +`uᵢ = √λᵢ • eᵢ` for the spectral eigenbasis `eᵢ` and (nonnegative) eigenvalues `λᵢ` of `T`: the +spectral decomposition `T = ∑ᵢ λᵢ |eᵢ⟩⟨eᵢ|` (`IsSelfAdjoint.spectral_sum`) rewrites each summand as +`λᵢ |eᵢ⟩⟨eᵢ| = |√λᵢ eᵢ⟩⟨√λᵢ eᵢ|` via `InnerProductSpace.rankOne_real_sqrt_smul_self` (using +`λᵢ ≥ 0`, `LinearMap.IsPositive.nonneg_eigenvalues`). -/ +theorem IsPositive.exists_sum_rankOne_fin_finrank {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] {T : E →L[𝕜] E} (hT : T.IsPositive) : + ∃ u : Fin (Module.finrank 𝕜 E) → E, T = ∑ i, rankOne 𝕜 (u i) (u i) := by + have := FiniteDimensional.completeSpace 𝕜 E + refine ⟨fun i ↦ ((hT.isSymmetric.eigenvalues rfl i).sqrt : 𝕜) • + hT.isSymmetric.eigenvectorBasis rfl i, ?_⟩ + conv_lhs => rw [hT.isSelfAdjoint.spectral_sum rfl] + exact Finset.sum_congr rfl fun i _ ↦ + (rankOne_real_sqrt_smul_self (hT.toLinearMap.nonneg_eigenvalues rfl i) _).symm + +end ContinuousLinearMap + +namespace InnerProductSpace + +open Finset + +variable {𝕜 : Type*} {H : Type*} {ι : Type*} + [RCLike 𝕜] [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [Fintype ι] + +/-- The synthesis operator sends the `i`-th standard basis vector of `EuclideanSpace 𝕜 ι` to the +`i`-th family member: `synthesisMap χ eᵢ = χ i`. -/ +theorem synthesisMap_basisFun (χ : ι → H) (i : ι) : + synthesisMap χ (EuclideanSpace.basisFun ι 𝕜 i) = χ i := by + classical + rw [synthesisMap, _root_.sum_apply] + simp only [rankOne_apply, orthonormal_iff_ite.mp (EuclideanSpace.basisFun ι 𝕜).orthonormal, + ite_smul, one_smul, zero_smul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + +/-- **Unitary freedom in the ensemble** (Nielsen & Chuang, *Quantum Computation and Quantum +Information*, Theorem 2.6), vector-family form. Two finite families `ψ φ : ι → H` (over a common +finite index `ι`, the equal-size "padded" form of the theorem) generate the same operator +`∑ i, |ψ i⟩⟨ψ i| = ∑ i, |φ i⟩⟨φ i|` **iff** they are related by a unitary coefficient matrix +`u ∈ Matrix.unitaryGroup ι 𝕜`: `ψ i = ∑ j, u i j • φ j`. + +The `⇐` direction is `sum_rankOne_self_eq_of_mem_unitaryGroup` (the forward direction, expanding the +sum bilinearly and collapsing `∑ᵢ uᵢⱼ conj uᵢₖ = δⱼₖ`). The `⟹` direction is the crux: the equal +rank-one sums say the synthesis operators satisfy `T T† = S S†` +(`sum_rankOne_self_eq_synthesisMap_comp_adjoint`), whence `ContinuousLinearMap. +exists_unitary_comp_of_comp_adjoint_eq` gives a unitary `W` on `EuclideanSpace 𝕜 ι` with +`synthesisMap ψ = (synthesisMap φ) ∘L W`; reading off its coefficients `u i j = W eᵢ j` and +evaluating at basis vectors (`synthesisMap_basisFun`) gives `ψ i = ∑ j, u i j • φ j`, with `u` +unitary because `W` maps the orthonormal basis `{eᵢ}` to an orthonormal family. -/ +theorem sum_rankOne_self_eq_iff_exists_mem_unitaryGroup [CompleteSpace H] [DecidableEq ι] + (ψ φ : ι → H) : + (∑ i, rankOne 𝕜 (ψ i) (ψ i) = ∑ i, rankOne 𝕜 (φ i) (φ i)) ↔ + ∃ u : Matrix ι ι 𝕜, u ∈ Matrix.unitaryGroup ι 𝕜 ∧ ∀ i, ψ i = ∑ j, u i j • φ j := by + constructor + · intro h + have e1 := sum_rankOne_self_eq_synthesisMap_comp_adjoint (𝕜 := 𝕜) ψ + have e2 := sum_rankOne_self_eq_synthesisMap_comp_adjoint (𝕜 := 𝕜) φ + obtain ⟨W, hWmem, hW⟩ := + ContinuousLinearMap.exists_unitary_comp_of_comp_adjoint_eq (e1.symm.trans (h.trans e2)) + -- `W` preserves the inner product (it is unitary): `W† ∘ W = 1`, so by + -- `inner_map_map_iff_adjoint_comp_self`, `⟪W a, W b⟫ = ⟪a, b⟫`. + have h1 : (ContinuousLinearMap.adjoint W).comp W = 1 := by + have hs := Unitary.coe_star_mul_self ⟨W, hWmem⟩ + rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def] at hs + exact hs + have hWisom : ∀ a b : EuclideanSpace 𝕜 ι, inner 𝕜 (W a) (W b) = inner 𝕜 a b := + fun a b => (ContinuousLinearMap.inner_map_map_iff_adjoint_comp_self W).mpr h1 a b + refine ⟨Matrix.of (fun i j => W (EuclideanSpace.basisFun ι 𝕜 i) j), ?_, ?_⟩ + · refine Matrix.mem_unitaryGroup_iff.mpr ?_ + ext i k + simp only [Matrix.mul_apply, Matrix.one_apply, Matrix.star_apply, Matrix.of_apply] + have hpar : (∑ j, W (EuclideanSpace.basisFun ι 𝕜 i) j + * star (W (EuclideanSpace.basisFun ι 𝕜 k) j)) + = inner 𝕜 (W (EuclideanSpace.basisFun ι 𝕜 k)) (W (EuclideanSpace.basisFun ι 𝕜 i)) := by + rw [PiLp.inner_apply] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [RCLike.inner_apply, starRingEnd_apply] + rw [hpar, hWisom, + orthonormal_iff_ite.mp (EuclideanSpace.basisFun ι 𝕜).orthonormal k i] + simp only [eq_comm] + · intro i + have key : ψ i = synthesisMap (𝕜 := 𝕜) φ (W (EuclideanSpace.basisFun ι 𝕜 i)) := by + rw [← synthesisMap_basisFun (𝕜 := 𝕜) ψ i, hW]; rfl + rw [key, synthesisMap_apply] + simp [Matrix.of_apply] + · rintro ⟨u, hu, hrel⟩ + calc ∑ i, rankOne 𝕜 (ψ i) (ψ i) + = ∑ i, rankOne 𝕜 (∑ j, u i j • φ j) (∑ j, u i j • φ j) := + Finset.sum_congr rfl fun i _ => by rw [hrel] + _ = ∑ i, rankOne 𝕜 (φ i) (φ i) := sum_rankOne_self_eq_of_mem_unitaryGroup hu φ + +/-- **Reduction of a rank-one sum to at most `finrank` terms.** Any finite sum of rank-one +projectors `∑ᵢ |vᵢ⟩⟨vᵢ|` over an *arbitrary* finite index `ι` equals a sum `∑ₖ |wₖ⟩⟨wₖ|` of at most +`finrank 𝕜 H` rank-one projectors — `k` ranging over `Fin (finrank 𝕜 H)`, with no bound on the size +of `ι`. The operator `∑ᵢ |vᵢ⟩⟨vᵢ|` is positive (`ContinuousLinearMap.isPositive_sum` of +`isPositive_rankOne_self`), so `ContinuousLinearMap.IsPositive.exists_sum_rankOne_fin_finrank` +re-expresses it over its spectral eigenbasis, whose size is `finrank 𝕜 H`. + +This is the linear-algebra core of the **minimal operator-sum representation** bound. Applied to the +vectorized operation elements of a quantum operation on a `d`-dimensional space — the Choi vectors +`vec Eᵢ ∈ H ⊗ H`, where `finrank ℂ (H ⊗ H) = d²` — it yields an operator-sum representation with at +most `d²` elements: Nielsen & Chuang, *Quantum Computation and Quantum Information*, **Theorem 8.3** +(and, for a `d`-to-`d′` operation, the `d d′` bound of Exercise 8.11, via `H ⊗ G`). The reduction is +size-agnostic in `ι`, matching N&C's "append zero operators" padding: the input family may be +arbitrarily large, the output is capped by the dimension. -/ +theorem exists_sum_rankOne_self_eq_fin_finrank [FiniteDimensional 𝕜 H] (v : ι → H) : + ∃ w : Fin (Module.finrank 𝕜 H) → H, + ∑ i, rankOne 𝕜 (v i) (v i) = ∑ k, rankOne 𝕜 (w k) (w k) := by + have hpos : (∑ i, rankOne 𝕜 (v i) (v i)).IsPositive := + ContinuousLinearMap.isPositive_sum _ fun i _ ↦ isPositive_rankOne_self (v i) + exact hpos.exists_sum_rankOne_fin_finrank + +end InnerProductSpace + +namespace EuclideanSpace + +/-- **Any unit vector of `EuclideanSpace 𝕜 (Fin n)` is the first row of a unitary matrix.** Given a +vector `w` with `‖w‖ = 1`, extend it to an orthonormal basis `c` with `c 0 = w` +(`Orthonormal.exists_orthonormalBasis_extension_of_card_eq`, orthonormal on the singleton `{0}`); +the coordinate matrix `uᵢⱼ = (c i).ofLp j` has orthonormal rows, hence is unitary, and its zeroth +row is `w`. This is the completion of a single unit vector to a unitary matrix — the ingredient +behind building a family of vectors with a prescribed member in the unitary-freedom form of +Nielsen & Chuang Theorem 2.6 (`InnerProductSpace.sum_rankOne_self_eq_of_mem_unitaryGroup`). -/ +theorem exists_mem_unitaryGroup_row_zero_eq {𝕜 : Type*} [RCLike 𝕜] {n : ℕ} [NeZero n] + (w : EuclideanSpace 𝕜 (Fin n)) (hw : ‖w‖ = 1) : + ∃ u ∈ Matrix.unitaryGroup (Fin n) 𝕜, ∀ j, u 0 j = w.ofLp j := by + classical + have hcard : Module.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = Fintype.card (Fin n) := + finrank_euclideanSpace + have horth : Orthonormal 𝕜 (({0} : Set (Fin n)).domRestrict (fun _ => w)) := by + rw [orthonormal_iff_ite] + rintro ⟨i, hi⟩ ⟨j, hj⟩ + simp only [Set.mem_singleton_iff] at hi hj + subst hi; subst hj + change ⟪w, w⟫_𝕜 = if (⟨(0 : Fin n), hi⟩ : ({0} : Set (Fin n))) = ⟨0, hj⟩ then 1 else 0 + rw [ite_eq_left rfl, inner_self_eq_norm_sq_to_K, hw] + norm_num + obtain ⟨c, hc⟩ := Orthonormal.exists_orthonormalBasis_extension_of_card_eq hcard horth + have hcw : c 0 = w := hc 0 rfl + refine ⟨Matrix.of fun a b => (c a).ofLp b, ?_, fun j => by rw [Matrix.of_apply, hcw]⟩ + rw [Matrix.mem_unitaryGroup_iff] + ext i j + rw [Matrix.mul_apply, Matrix.one_apply] + have hkey : ∑ k, (Matrix.of fun a b => (c a).ofLp b) i k * + star (Matrix.of fun a b => (c a).ofLp b) k j = inner 𝕜 (c j) (c i) := by + rw [PiLp.inner_apply] + refine Finset.sum_congr rfl fun k _ => ?_ + simp only [Matrix.of_apply, Matrix.star_apply, RCLike.inner_apply, RCLike.star_def] + rw [hkey, orthonormal_iff_ite.mp c.orthonormal j i] + by_cases hij : i = j + · subst hij; simp + · rw [ite_eq_right fun hji => hij hji.symm, ite_eq_right hij] + +end EuclideanSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneTrace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneTrace.lean new file mode 100644 index 0000000000..964d606745 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/RankOneTrace.lean @@ -0,0 +1,36 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! +# Trace of a rank-one operator composed with another operator + +`tr(|v⟩⟨v| ∘ A) = ⟪v, A v⟫`: the trace of the rank-one self-projector at `v` +composed with `A` is the diagonal matrix element of `A` at `v`. Proof by +trace-cyclicity + `comp_rankOne` + `trace_rankOne`. +-/ + +@[expose] public section + +namespace InnerProductSpace + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +/-- `tr(|v⟩⟨v| ∘ A) = ⟪v, A v⟫`. -/ +theorem trace_rankOne_self_comp (v : E) (A : E →L[𝕜] E) : + LinearMap.trace 𝕜 E (((rankOne 𝕜 v v) ∘L A : E →L[𝕜] E) : E →ₗ[𝕜] E) + = inner 𝕜 v (A v) := by + rw [ContinuousLinearMap.toLinearMap_comp, LinearMap.trace_comp_comm', + ← ContinuousLinearMap.toLinearMap_comp, + InnerProductSpace.comp_rankOne, InnerProductSpace.trace_rankOne] + +end InnerProductSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/ReducedState.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/ReducedState.lean new file mode 100644 index 0000000000..04256d2a12 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/ReducedState.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PartialTraceAbstract +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! +# Reduced states + +The **reduced state** of a bipartite density operator `T : E ⊗[𝕜] F →L[𝕜] E ⊗[𝕜] F` on the +factor `E` is its partial trace over `F`. This file records the basic fact that a reduced +state is again a density operator: tracing out a subsystem of a quantum state yields a +quantum state. + +Following the library's reduced-state convention (cf. `traceDistance_le_of_partialTraceRight_eq`, +`TensorProduct.IsPurification`), the reduced operator `ρ` is taken as a given +`ContinuousLinearMap` carrying the `LinearMap`-level hypothesis +`LinearMap.partialTraceRight b T.toLinearMap = ρ.toLinearMap`, rather than re-promoting the +`LinearMap`-valued partial trace to a `ContinuousLinearMap`. This keeps the density-operator +reasoning (CFC, positivity) entirely on the `ContinuousLinearMap` side while the partial trace +stays at its native `LinearMap` level. + +## Main results + +* `ContinuousLinearMap.IsDensityOp.of_partialTraceRight_eq`, + `ContinuousLinearMap.IsDensityOp.of_partialTraceLeft_eq`: a reduced state of a density + operator is a density operator. +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +/-- **A reduced state is a density operator** (right factor). If `T` is a density operator on +`E ⊗[𝕜] F` and `ρ : E →L[𝕜] E` is its reduced state on `E` (`partialTraceRight b ↑T = ↑ρ`), +then `ρ` is a density operator: positive (`partialTraceRight` preserves positivity) with +trace `1` (`trace (partialTraceRight b ↑T) = trace ↑T = 1`). -/ +theorem IsDensityOp.of_partialTraceRight_eq {T : E ⊗[𝕜] F →L[𝕜] E ⊗[𝕜] F} {ρ : E →L[𝕜] E} + (hT : T.IsDensityOp) (b : OrthonormalBasis ι 𝕜 F) + (hρ : LinearMap.partialTraceRight b T.toLinearMap = ρ.toLinearMap) : ρ.IsDensityOp := by + refine ⟨?_, ?_⟩ + · rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, ← hρ] + exact LinearMap.partialTraceRight_isPositive b hT.isPositive.toLinearMap + · rw [← hρ, LinearMap.trace_partialTraceRight] + exact hT.trace_eq_one + +/-- **A reduced state is a density operator** (left factor). If `T` is a density operator on +`E ⊗[𝕜] F` and `ρ : F →L[𝕜] F` is its reduced state on `F` (`partialTraceLeft b ↑T = ↑ρ`), +then `ρ` is a density operator. -/ +theorem IsDensityOp.of_partialTraceLeft_eq {T : E ⊗[𝕜] F →L[𝕜] E ⊗[𝕜] F} {ρ : F →L[𝕜] F} + (hT : T.IsDensityOp) (b : OrthonormalBasis ι 𝕜 E) + (hρ : LinearMap.partialTraceLeft b T.toLinearMap = ρ.toLinearMap) : ρ.IsDensityOp := by + refine ⟨?_, ?_⟩ + · rw [← ContinuousLinearMap.isPositive_toLinearMap_iff, ← hρ] + exact LinearMap.partialTraceLeft_isPositive b hT.isPositive.toLinearMap + · rw [← hρ, LinearMap.trace_partialTraceLeft] + exact hT.trace_eq_one + +section StrictlyPositive + +variable {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [FiniteDimensional ℂ F] + {ι : Type*} [Fintype ι] [Nonempty ι] + +open scoped InnerProductSpace + +/-- **A reduced state of a faithful state is faithful** (right factor). If `T` is strictly positive +on `E ⊗[ℂ] F` and `ρ : E →L[ℂ] E` is its reduced state on `E` (`partialTraceRight b ↑T = ↑ρ`), then +`ρ` is strictly positive. The marginal is positive-definite because +`⟪x, ρ x⟫ = ∑ k, ⟪x ⊗ b k, T (x ⊗ b k)⟫` (`inner_partialTraceRight_self`) is a sum of strictly +positive terms (`IsStrictlyPositive.re_inner_self_pos`, as `x ⊗ b k ≠ 0`), so `ρ` is injective, +hence invertible. -/ +theorem _root_.IsStrictlyPositive.of_partialTraceRight_eq [CompleteSpace E] + {T : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {ρ : E →L[ℂ] E} + (hT : IsStrictlyPositive T) (b : OrthonormalBasis ι ℂ F) + (hρ : LinearMap.partialTraceRight b T.toLinearMap = ρ.toLinearMap) : + IsStrictlyPositive ρ := by + refine ContinuousLinearMap.isStrictlyPositive_of_re_inner_self_pos ?_ fun x hx ↦ ?_ + · rw [ContinuousLinearMap.nonneg_iff_isPositive, + ← ContinuousLinearMap.isPositive_toLinearMap_iff, ← hρ] + exact LinearMap.partialTraceRight_isPositive b ((ContinuousLinearMap.isPositive_toLinearMap_iff + T).mp (ContinuousLinearMap.nonneg_iff_isPositive.mp hT.nonneg)) + · rw [← ContinuousLinearMap.coe_coe ρ, ← hρ, + LinearMap.inner_partialTraceRight_self, map_sum] + refine Finset.sum_pos (fun k _ ↦ ?_) Finset.univ_nonempty + have hzne : x ⊗ₜ[ℂ] b k ≠ 0 := by + rw [← norm_ne_zero_iff, TensorProduct.norm_tmul]; simp [hx] + rw [← RCLike.conj_re, inner_conj_symm] + exact hT.re_inner_self_pos hzne + +omit [Nonempty ι] in +/-- **The support condition descends to the partial trace.** If `supp T ⊆ supp S` on `E ⊗ F` and +`S` is positive, then the marginals satisfy `supp (Tr_F T) ⊆ supp (Tr_F S)`. For `x ∈ ker (Tr_F S)`, +the slice sum `⟪x, (Tr_F S) x⟫ = ∑ₖ ⟪x ⊗ bₖ, S (x ⊗ bₖ)⟫` vanishes; each term is `≥ 0` (`S` +positive), so each `S (x ⊗ bₖ) = 0`, i.e. `x ⊗ bₖ ∈ ker S ⊆ ker T`; hence +`(Tr_F T) x = ∑ₖ restrictRightₖ (T (x ⊗ bₖ)) = 0`. The support-condition twin of +`IsStrictlyPositive.of_partialTraceRight_eq`; lets the relaxed-DPI marginal support condition be +*derived* from the full one, not assumed. -/ +theorem HasSupportLE.of_partialTraceRight + {T S : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {T' S' : E →L[ℂ] E} (hS : 0 ≤ S) + (hsupp : HasSupportLE T S) (b : OrthonormalBasis ι ℂ F) + (hred_T : LinearMap.partialTraceRight b T.toLinearMap = T'.toLinearMap) + (hred_S : LinearMap.partialTraceRight b S.toLinearMap = S'.toLinearMap) : + HasSupportLE T' S' := by + intro x hx + rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe] at hx + rw [LinearMap.mem_ker, ← hred_T, LinearMap.partialTraceRight_apply] + have hSpos := (ContinuousLinearMap.isPositive_toLinearMap_iff S).mp + (ContinuousLinearMap.nonneg_iff_isPositive.mp hS) + have hsum : (∑ k, RCLike.re ⟪x ⊗ₜ[ℂ] b k, S.toLinearMap (x ⊗ₜ[ℂ] b k)⟫_ℂ) = 0 := by + rw [← map_sum RCLike.re, ← LinearMap.inner_partialTraceRight_self b S.toLinearMap x, hred_S] + simp [hx] + refine Finset.sum_eq_zero fun k _ ↦ ?_ + have hSk : S (x ⊗ₜ[ℂ] b k) = 0 := ContinuousLinearMap.apply_eq_zero_of_re_inner_self_eq_zero hS + ((Finset.sum_eq_zero_iff_of_nonneg fun k _ ↦ hSpos.re_inner_nonneg_right _).mp + hsum k (Finset.mem_univ k)) + have hTk : T.toLinearMap (x ⊗ₜ[ℂ] b k) = 0 := + hsupp (by rw [LinearMap.mem_ker, ContinuousLinearMap.coe_coe]; exact hSk) + rw [hTk, map_zero] + +/-- **A reduced state of a faithful state is faithful** (left factor). Symmetric to +`IsStrictlyPositive.of_partialTraceRight_eq`: the `F`-marginal of a strictly positive `T` is +strictly positive. -/ +theorem _root_.IsStrictlyPositive.of_partialTraceLeft_eq [CompleteSpace F] + {T : (E ⊗[ℂ] F) →L[ℂ] (E ⊗[ℂ] F)} {ρ : F →L[ℂ] F} + (hT : IsStrictlyPositive T) (b : OrthonormalBasis ι ℂ E) + (hρ : LinearMap.partialTraceLeft b T.toLinearMap = ρ.toLinearMap) : + IsStrictlyPositive ρ := by + refine ContinuousLinearMap.isStrictlyPositive_of_re_inner_self_pos ?_ fun y hy ↦ ?_ + · rw [ContinuousLinearMap.nonneg_iff_isPositive, + ← ContinuousLinearMap.isPositive_toLinearMap_iff, ← hρ] + exact LinearMap.partialTraceLeft_isPositive b ((ContinuousLinearMap.isPositive_toLinearMap_iff + T).mp (ContinuousLinearMap.nonneg_iff_isPositive.mp hT.nonneg)) + · rw [← ContinuousLinearMap.coe_coe ρ, ← hρ, + LinearMap.inner_partialTraceLeft_self, map_sum] + refine Finset.sum_pos (fun k _ ↦ ?_) Finset.univ_nonempty + have hzne : b k ⊗ₜ[ℂ] y ≠ 0 := by + rw [← norm_ne_zero_iff, TensorProduct.norm_tmul]; simp [hy] + rw [← RCLike.conj_re, inner_conj_symm] + exact hT.re_inner_self_pos hzne + +end StrictlyPositive + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchmidtDecomposition.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchmidtDecomposition.lean new file mode 100644 index 0000000000..12cae8aa6c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchmidtDecomposition.lean @@ -0,0 +1,187 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Matricization +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Orthonormal +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Schmidt decomposition of a bipartite tensor + +Every vector `Ψ : E ⊗[𝕜] F` in a tensor product of finite-dimensional inner product spaces +admits a **Schmidt decomposition** + + `Ψ = ∑ i, σᵢ • eᵢ ⊗ₜ fᵢ`, + +where the `σᵢ > 0` are the *nonzero* singular values (the **Schmidt coefficients**) of the +matricized coefficient operator `M = matricize b Ψ : F →L[𝕜] E`, and the `eᵢ` (in `E`) and +`fᵢ` (in `F`) form genuine orthonormal families (the **Schmidt bases**). The sum runs over +`Fin (finrank 𝕜 (range M))`, i.e. exactly the number of nonzero Schmidt coefficients (the +Schmidt number). Moreover `∑ i, σᵢ² = ‖Ψ‖²`. + +This is the mathematical core of Nielsen–Chuang's Theorem 2.7. The construction is the singular +value decomposition of `M`: `eᵢ` are the left singular vectors (`M.svdLeft`), `fᵢ` are the +`b`-conjugates of the right singular vectors, and `σᵢ` the singular values. Reindexing to the +support turns the SVD's "orthonormal on the support, junk off it" left singular vectors into a +genuinely orthonormal family with strictly positive coefficients, matching the textbook statement +in which the Schmidt bases are honest orthonormal sets. + +## Main results + +* `TensorProduct.orthonormal_conjBasis` — the `b`-conjugate `v ↦ ∑ k, ⟪v, b k⟫ • b k` of an + orthonormal family is orthonormal (it is an antiunitary w.r.t. the basis `b`). +* `TensorProduct.matricize_eq_sum_singularValues_smul_svdLeft_tmul` — the full SVD reconstruction + `Ψ = ∑ i, σᵢ • (svdLeft i) ⊗ₜ (conjugate of svdRight i)` over `Fin (finrank 𝕜 F)`. +* `TensorProduct.exists_orthonormal_schmidt` — the Schmidt decomposition: existence of positive + coefficients, orthonormal Schmidt bases, `∑ σᵢ² = ‖Ψ‖²`, and `Ψ = ∑ σᵢ • eᵢ ⊗ₜ fᵢ`. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct +open Module + +namespace TensorProduct + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ι : Type*} [Fintype ι] + +omit [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] in +/-- **The `b`-conjugate of an orthonormal family is orthonormal.** For an orthonormal basis +`b` of `F` and an orthonormal family `w`, the family `i ↦ ∑ k, ⟪w i, b k⟫ • b k` (the +componentwise conjugate of `w` in the basis `b`) is orthonormal. Indeed +`⟪∑ₖ⟪wᵢ,bₖ⟫bₖ, ∑ₗ⟪wⱼ,bₗ⟫bₗ⟫ = ⟪wⱼ, wᵢ⟫` (an antiunitary reverses the inner product), which is +`δᵢⱼ` by orthonormality of `w`. This is the abstract-space analogue of `EuclideanSpace.conjVec`, +absorbing the antilinearity of `inner` in the SVD reconstruction below. -/ +theorem orthonormal_conjBasis (b : OrthonormalBasis ι 𝕜 F) {ι' : Type*} {w : ι' → F} + (hw : Orthonormal 𝕜 w) : + Orthonormal 𝕜 (fun i => ∑ k, inner 𝕜 (w i) (b k) • b k) := by + classical + rw [orthonormal_iff_ite] at hw ⊢ + intro i j + have hexp : (inner 𝕜 (∑ k, inner 𝕜 (w i) (b k) • b k) (∑ l, inner 𝕜 (w j) (b l) • b l) : 𝕜) + = inner 𝕜 (w j) (w i) := by + simp_rw [sum_inner, inner_smul_left, inner_sum, inner_smul_right, b.inner_eq_ite, + mul_ite, mul_one, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, ite_true, inner_conj_symm] + rw [← b.sum_inner_mul_inner (w j) (w i)] + exact Finset.sum_congr rfl fun k _ => mul_comm _ _ + rw [hexp, hw j i] + exact if_congr eq_comm rfl rfl + +/-- **SVD reconstruction of a matricized tensor.** Writing `M := matricize b Ψ : F →L[𝕜] E`, +the bipartite vector `Ψ` reconstructs from the singular value decomposition of `M` as + + `Ψ = ∑ i, σᵢ • (M.svdLeft i) ⊗ₜ (∑ k, ⟪M.svdRight i, b k⟫ • b k)`, + +summed over `Fin (finrank 𝕜 F)`. The left factors are the left singular vectors; the right +factors are the `b`-conjugates of the right singular vectors (the conjugation absorbs the +antilinearity of `inner` in `matricize`). Proof: expand `Ψ = ∑ₖ M(bₖ) ⊗ₜ bₖ` +(`matricize_symm_apply`), rewrite each `M(bₖ)` by `svd_apply`, swap the sums, and collect the +`bₖ` under the tensor's right slot. -/ +theorem matricize_eq_sum_singularValues_smul_svdLeft_tmul + (b : OrthonormalBasis ι 𝕜 F) (Ψ : E ⊗[𝕜] F) : + Ψ = ∑ i : Fin (finrank 𝕜 F), + ((matricize b Ψ).singularValues i.val : 𝕜) • (matricize b Ψ).svdLeft i ⊗ₜ[𝕜] + (∑ k, inner 𝕜 ((matricize b Ψ).svdRight i) (b k) • b k) := by + set M := matricize b Ψ with hM + have hΨ : Ψ = ∑ k, M (b k) ⊗ₜ[𝕜] b k := by + rw [hM, ← matricize_symm_apply b (matricize b Ψ), (matricize b).symm_apply_apply] + rw [hΨ] + simp_rw [M.svd_apply, TensorProduct.sum_tmul] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [TensorProduct.tmul_sum, Finset.smul_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [smul_smul, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, smul_smul] + +/-- **Schmidt decomposition of a bipartite tensor (Nielsen–Chuang Theorem 2.7, abstract form).** +Every `Ψ : E ⊗[𝕜] F` decomposes as `Ψ = ∑ i, σᵢ • eᵢ ⊗ₜ fᵢ` for strictly positive Schmidt +coefficients `σᵢ`, orthonormal Schmidt bases `e` (in `E`) and `f` (in `F`), with +`∑ i, σᵢ² = ‖Ψ‖²`. The number of terms `n` is the Schmidt number (the number of nonzero +singular values of the matricized coefficient operator). -/ +theorem exists_orthonormal_schmidt (Ψ : E ⊗[𝕜] F) : + ∃ (n : ℕ) (σ : Fin n → ℝ) (e : Fin n → E) (f : Fin n → F), + (∀ i, 0 < σ i) ∧ Orthonormal 𝕜 e ∧ Orthonormal 𝕜 f ∧ + (∑ i, σ i ^ 2 = ‖Ψ‖ ^ 2) ∧ Ψ = ∑ i, (σ i : 𝕜) • e i ⊗ₜ[𝕜] f i := by + classical + set b := stdOrthonormalBasis 𝕜 F with hb + set T := (matricize b Ψ).toLinearMap with hT + -- `r` = Schmidt number = rank of the coefficient operator. + set r := finrank 𝕜 (LinearMap.range T) with hr + have hrN : r ≤ finrank 𝕜 F := T.finrank_range_le + have hlt : ∀ j : Fin r, (Fin.castLE hrN j).val < r := fun j => j.isLt + -- SVD reconstruction of `Ψ`, at LinearMap-level projections (defeq to the CLM ones). + have hfull : Ψ = ∑ i : Fin (finrank 𝕜 F), + (T.singularValues i.val : 𝕜) • T.svdLeft i ⊗ₜ[𝕜] + (∑ k, inner 𝕜 (T.svdRight i) (b k) • b k) := + matricize_eq_sum_singularValues_smul_svdLeft_tmul b Ψ + -- σᵢ > 0 ⇔ i.val < r. + have hpos : ∀ i : Fin (finrank 𝕜 F), 0 < T.singularValues i.val ↔ i.val < r := fun i => + T.singularValues_pos_iff_lt_finrank_range + -- σᵢ = 0 above the rank, so the SVD sum collapses to the support `Fin r`. + have hsv0 : ∀ i : Fin (finrank 𝕜 F), r ≤ i.val → T.singularValues i.val = 0 := by + intro i hi + by_contra h + exact absurd ((hpos i).1 (lt_of_le_of_ne (T.singularValues_nonneg i.val) (Ne.symm h))) + (not_lt.2 hi) + -- prefix-support reduction: a family vanishing above `r` sums over `Fin r` via `castLE`. + have hreduce : ∀ (p : Fin (finrank 𝕜 F) → E ⊗[𝕜] F), (∀ i, r ≤ i.val → p i = 0) → + ∑ i, p i = ∑ j : Fin r, p (Fin.castLE hrN j) := by + intro p hp + have hmap : ∑ j : Fin r, p (Fin.castLE hrN j) + = ∑ i ∈ Finset.univ.map ⟨Fin.castLE hrN, Fin.castLE_injective hrN⟩, p i := + (Finset.sum_map Finset.univ ⟨Fin.castLE hrN, Fin.castLE_injective hrN⟩ p).symm + rw [hmap] + refine (Finset.sum_subset (Finset.subset_univ _) ?_).symm + intro i _ hi + refine hp i ?_ + by_contra hltc + rw [not_le] at hltc + exact hi (Finset.mem_map.2 ⟨⟨i.val, hltc⟩, Finset.mem_univ _, by simp⟩) + -- The reduced Schmidt decomposition. + have hdecomp : Ψ = ∑ j : Fin r, (T.singularValues (Fin.castLE hrN j).val : 𝕜) • + T.svdLeft (Fin.castLE hrN j) ⊗ₜ[𝕜] + (∑ k, inner 𝕜 (T.svdRight (Fin.castLE hrN j)) (b k) • b k) := by + rw [hfull] + exact hreduce _ fun i hi => by simp [hsv0 i hi] + -- Orthonormality of the reduced right Schmidt basis (conjugate family on the support). + have hfo : Orthonormal 𝕜 (fun j : Fin r => + ∑ k, inner 𝕜 (T.svdRight (Fin.castLE hrN j)) (b k) • b k) := + (orthonormal_conjBasis b T.svdRight.orthonormal).comp _ (Fin.castLE_injective hrN) + -- Orthonormality of the reduced left Schmidt basis (left singular vectors on the support). + have heo : Orthonormal 𝕜 (fun j : Fin r => T.svdLeft (Fin.castLE hrN j)) := by + rw [orthonormal_iff_ite] + intro i j + rw [T.inner_svdLeft_svdLeft_full] + have hne : T.singularValues (Fin.castLE hrN i).val ≠ 0 := ne_of_gt ((hpos _).2 (hlt i)) + have hiff : (Fin.castLE hrN i = Fin.castLE hrN j) ↔ (i = j) := + (Fin.castLE_injective hrN).eq_iff + exact if_congr ((and_iff_left hne).trans hiff) rfl rfl + -- Orthonormality of the diagonal tensor family `eⱼ ⊗ fⱼ`. + have htmul : Orthonormal 𝕜 (fun j : Fin r => T.svdLeft (Fin.castLE hrN j) ⊗ₜ[𝕜] + (∑ k, inner 𝕜 (T.svdRight (Fin.castLE hrN j)) (b k) • b k)) := by + rw [orthonormal_iff_ite] + intro i j + rw [TensorProduct.inner_tmul, orthonormal_iff_ite.mp heo, orthonormal_iff_ite.mp hfo] + by_cases h : i = j <;> simp [h] + refine ⟨r, fun j => T.singularValues (Fin.castLE hrN j).val, + fun j => T.svdLeft (Fin.castLE hrN j), + fun j => ∑ k, inner 𝕜 (T.svdRight (Fin.castLE hrN j)) (b k) • b k, + fun j => (hpos _).2 (hlt j), heo, hfo, ?_, hdecomp⟩ + -- ∑ σⱼ² = ‖Ψ‖² from the decomposition and orthonormality of `eⱼ ⊗ fⱼ`. + conv_rhs => rw [hdecomp] + rw [htmul.norm_sum_smul_sq] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [RCLike.norm_ofReal, abs_of_pos ((hpos _).2 (hlt j))] + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherCompression.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherCompression.lean new file mode 100644 index 0000000000..5c4a5635a4 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherCompression.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SchumacherEncoder +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumDataCompression + +/-! # Schumacher's projection–reset compression scheme + +The direct (achievability) part of Schumacher's quantum noiseless channel coding theorem +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, §12.2.2, Theorem 12.6, Eqs. +(12.50)–(12.53)) exhibits, at each block length, a concrete rate-`R` compression scheme whose +entanglement fidelity is close to `1`. This file packages that scheme as a bona-fide +`ContinuousLinearMap.QuantumCompressionScheme`. + +Given a Hilbert space `K` (standing for `H^⊗n`), an orthonormal basis `b : OrthonormalBasis ι ℂ K`, +a set `s` of "typical" indices, a reference index `i₀ ∈ s`, and a qubit budget `numBits` with +`s.card ≤ 2 ^ numBits`, the **projection–reset compression scheme** `projectionReset b s i₀ hi₀ +hcard` has: + +* compression operation `Cₙ` = the Schumacher projection–reset encoder + (`ContinuousLinearMap.schumacherEncoder`, N&C Eq. (12.50)): the code-subspace projector + `P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` together with the reset operators `Aᵢ = |b i₀⟩⟨bᵢ|` for `i ∉ s`; +* decompression operation `Dₙ` = the identity (a single Kraus operator `1`), per N&C's `Dₙ(σ) = σ`; +* compressed subspace `range P`, of dimension `s.card ≤ 2 ^ numBits`. + +Its entanglement fidelity dominates the code-overlap term: + +`F(τ, Dₙ ∘ Cₙ) ≥ |tr(τ P)|²` (N&C Eq. (12.52), `projectionReset_fidelity_ge`), + +which is the direct-part inequality: specialised to +`τ = ρ^⊗n` and `P = P(n, ε)` the typical subspace projector, part (1) of the typical subspace +theorem gives `tr(ρ^⊗n P) ≥ 1 − δ`, whence `F ≥ (1 − δ)² → 1`. + +## Main definitions and results + +* `ContinuousLinearMap.QuantumCompressionScheme.projectionReset` — the projection–reset scheme. +* `ContinuousLinearMap.QuantumCompressionScheme.projectionReset_fidelity_eq` — its entanglement + fidelity equals that of the bare Schumacher encoder (the identity decoder contributes nothing). +* `ContinuousLinearMap.QuantumCompressionScheme.projectionReset_fidelity_ge` — **N&C Eq. (12.52)**: + `|tr(τ P)|² ≤ F(τ, Dₙ ∘ Cₙ)`. + +The rate bound uses the reusable rank identity +`InnerProductSpace.finrank_range_orthonormalProjector` (rank of `∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` is `s.card`), +which lives upstream beside the rest of the projector API in +`ToMathlib/Analysis/InnerProductSpace/RankOneProjector.lean`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.50)–(12.53)). +-/ + +open scoped InnerProductSpace ComplexConjugate + +@[expose] public section + +namespace ContinuousLinearMap.QuantumCompressionScheme + +variable {K : Type*} [NormedAddCommGroup K] [InnerProductSpace ℂ K] [FiniteDimensional ℂ K] + [CompleteSpace K] {ι : Type*} [Fintype ι] [DecidableEq ι] + +/-- **Schumacher's projection–reset compression scheme** (Nielsen & Chuang, §12.2.2, Eq. (12.50)): +the rate-`numBits` quantum compression scheme on `K` whose compression operation is the projection– +reset encoder `ContinuousLinearMap.schumacherEncoder b s i₀` and whose decompression operation is +the identity (`Dₙ(σ) = σ`, a single Kraus operator `1`). + +The `Option ι`-indexed encoder family is reindexed onto `Fin (Fintype.card (Option ι))`; its +trace-preservation is `schumacherEncoder_isTracePreserving`, and every element factors through the +code projector `P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` because `i₀ ∈ s` fixes `P (b i₀) = b i₀`. The compressed +subspace `range P` has dimension `s.card ≤ 2 ^ numBits`. -/ +noncomputable def projectionReset (b : OrthonormalBasis ι ℂ K) (s : Finset ι) (i₀ : ι) + (hi₀ : i₀ ∈ s) {numBits : ℕ} (hcard : s.card ≤ 2 ^ numBits) : + QuantumCompressionScheme K numBits where + encCard := Fintype.card (Option ι) + decCard := 1 + encode j := schumacherEncoder b s i₀ ((Fintype.equivFin (Option ι)).symm j) + decode _ := 1 + encode_isTracePreserving := by + rw [← schumacherEncoder_isTracePreserving b s i₀] + exact Equiv.sum_comp (Fintype.equivFin (Option ι)).symm + fun o => adjoint (schumacherEncoder b s i₀ o) * schumacherEncoder b s i₀ o + decode_isTracePreserving := by simp [← star_eq_adjoint] + compressedProjection := InnerProductSpace.orthonormalProjector ℂ (⇑b) s + isStarProjection_compressedProjection := + InnerProductSpace.isStarProjection_orthonormalProjector b.orthonormal s + compressedProjection_mul_encode j := + orthonormalProjector_mul_schumacherEncoder b s i₀ hi₀ _ + finrank_range_compressedProjection_le := + (InnerProductSpace.finrank_range_orthonormalProjector b s).trans_le hcard + +/-- The entanglement fidelity of the projection–reset scheme equals that of the bare Schumacher +encoder: the decompression operation is the identity (a single Kraus operator `1`), so the combined +operation `Dₙ ∘ Cₙ` has the same operation elements as `Cₙ` (up to the reindexing +`Fin 1 × Fin (Fintype.card (Option ι)) ≃ Option ι`), and the entanglement fidelity depends only on +the family of operation elements. -/ +theorem projectionReset_fidelity_eq (b : OrthonormalBasis ι ℂ K) (s : Finset ι) (i₀ : ι) + (hi₀ : i₀ ∈ s) {numBits : ℕ} (hcard : s.card ≤ 2 ^ numBits) (τ : K →L[ℂ] K) : + (projectionReset b s i₀ hi₀ hcard).fidelity τ + = entanglementFidelity τ (schumacherEncoder b s i₀) := by + rw [fidelity, entanglementFidelity, entanglementFidelity] + refine Fintype.sum_equiv + ((Equiv.uniqueProd (Fin (Fintype.card (Option ι))) (Fin 1)).trans + (Fintype.equivFin (Option ι)).symm) _ _ fun p => ?_ + simp only [composite_apply, projectionReset, one_mul, Equiv.trans_apply, Equiv.uniqueProd_apply] + +/-- **Nielsen & Chuang, Eq. (12.52).** The entanglement fidelity of the projection–reset scheme is +bounded below by the squared code-overlap `|tr(τ P)|²`, where `P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` is the +compressed-subspace projector: `P` is one of the operation elements and the remaining reset-operator +terms are nonnegative (`entanglementFidelity_schumacherEncoder_ge`). This is the direct +(achievability) inequality of Schumacher's noiseless channel coding theorem. -/ +theorem projectionReset_fidelity_ge (b : OrthonormalBasis ι ℂ K) (s : Finset ι) (i₀ : ι) + (hi₀ : i₀ ∈ s) {numBits : ℕ} (hcard : s.card ≤ 2 ^ numBits) (τ : K →L[ℂ] K) : + ‖LinearMap.trace ℂ K + ((τ * InnerProductSpace.orthonormalProjector ℂ (⇑b) s : K →L[ℂ] K) : K →ₗ[ℂ] K)‖ ^ 2 + ≤ (projectionReset b s i₀ hi₀ hcard).fidelity τ := by + rw [projectionReset_fidelity_eq] + exact entanglementFidelity_schumacherEncoder_ge b s i₀ τ + +end ContinuousLinearMap.QuantumCompressionScheme diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherConverse.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherConverse.lean new file mode 100644 index 0000000000..58913103ca --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherConverse.lean @@ -0,0 +1,208 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumDataCompression +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density + +/-! # The converse of Schumacher's noiseless channel coding theorem + +The **converse (optimality) part** of Schumacher's quantum noiseless channel coding theorem +(Nielsen–Chuang, *Quantum Computation and Quantum Information*, §12.2.2, Theorem 12.6, Eqs. +(12.54)–(12.58)) shows that a rate below the source entropy cannot be achieved reliably. This file +packages the operator-level, *source-independent* half of that argument as a bound on the +entanglement fidelity of any `ContinuousLinearMap.QuantumCompressionScheme`. + +## The bound + +Fix a block length, i.e. a scheme `sch : QuantumCompressionScheme K numBits` (with `K = H^⊗n`, +`numBits = ⌊nR⌋`) and a source `ρ` (a density operator on `K`). N&C's converse estimate +(Eqs. (12.54)–(12.58)) is: if *every* output subspace carries only a small weight of the source, +then the fidelity is small. Precisely (`QuantumCompressionScheme.fidelity_le`), if every orthogonal +projector `P` onto a subspace of dimension `≤ 2^numBits` satisfies `re tr(P ρ) ≤ δ`, then + +`F(ρ, Dₙ ∘ Cₙ) ≤ δ`. + +Specialised (in `AxQM/Postulates/API/SchumacherConverse.lean`) to `ρ = ρ^⊗n` and +`numBits = ⌊nR⌋` with `R < S(ρ)`, part (3) of the typical subspace theorem (the *small-subspace +bound*, N&C Eq. (12.45)) supplies exactly the hypothesis `re tr(P ρ^⊗n) ≤ δ` for all `P` of rank +`≤ 2^{nR}`, whence +`F(ρ^⊗n, Dₙ ∘ Cₙ) ≤ δ → 0`: the scheme is not reliable. + +## The proof (N&C Eqs. (12.54)–(12.58)) + +Write `F(ρ, Dₙ ∘ Cₙ) = ∑ₖⱼ |tr(Dₖ Cⱼ ρ)|²` (`fidelity_eq`, N&C Eq. (12.54)). For each +decompression index `k`, let `Sₖ = outputProjection sch k` be the orthogonal projector onto the +image `Dₖ (S(n) K)` of the compressed subspace under `Dₖ`; since `Cⱼ = S(n) Cⱼ`, the composite +`Dₖ Cⱼ` factors through `Sₖ` (`Sₖ Dₖ Cⱼ = Dₖ Cⱼ`, `outputProjection_mul_composite`), and `Sₖ` has +rank `≤ 2^numBits` (`finrank_range_outputProjection_le`, since `Dₖ` cannot increase the dimension). + +With `r = √ρ` (`cfc Real.sqrt ρ`, self-adjoint with `r r = ρ`), the fidelity term is the +Hilbert–Schmidt pairing `tr(Dₖ Cⱼ ρ) = ⟨Dₖ Cⱼ r, Sₖ r⟩_HS` (`hsPairing`), so the Cauchy–Schwarz +inequality `‖⟨T, U⟩_HS‖² ≤ ‖T‖²_HS ‖U‖²_HS` (`norm_hsPairing_sq_le`, N&C Eq. (12.56)) gives + +`|tr(Dₖ Cⱼ ρ)|² ≤ re tr(Dₖ Cⱼ ρ Cⱼ† Dₖ†) · re tr(Sₖ ρ) ≤ re tr(Dₖ Cⱼ ρ Cⱼ† Dₖ†) · δ`. + +Summing over `(k, j)` and using trace-preservation `∑ₖⱼ (Dₖ Cⱼ)† (Dₖ Cⱼ) = 1` +(`composite_isTracePreserving`, N&C Eq. (12.58)) collapses `∑ₖⱼ re tr(Dₖ Cⱼ ρ Cⱼ† Dₖ†) = tr ρ = 1`, +leaving `F ≤ δ`. + +## Main definitions and results + +* `ContinuousLinearMap.QuantumCompressionScheme.outputProjection` — the output-subspace projector + `Sₖ` (N&C's `Sₖ(n)`, the paragraph before Eq. (12.55)). +* `ContinuousLinearMap.QuantumCompressionScheme.fidelity_le_of_output_projectors` — the + Cauchy–Schwarz core: `F(ρ, Dₙ∘Cₙ) ≤ δ` from an *abstract* family of output projectors bounding + the source weight. +* `ContinuousLinearMap.QuantumCompressionScheme.fidelity_le` — **the converse bound** for a + `QuantumCompressionScheme`: `F(ρ, Dₙ∘Cₙ) ≤ δ` whenever every rank-`≤ 2^numBits` orthogonal + projector `P` has `re tr(P ρ) ≤ δ`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (Theorem 12.6; Eqs. (12.54)–(12.58)). +-/ + +open scoped InnerProductSpace +open ContinuousLinearMap InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap.QuantumCompressionScheme + +variable {K : Type*} [NormedAddCommGroup K] [InnerProductSpace ℂ K] [FiniteDimensional ℂ K] + [CompleteSpace K] {numBits : ℕ} + +/-- **The output-subspace projector** `Sₖ = Sₖ(n)` of a compression scheme (Nielsen & Chuang, +§12.2.2, the paragraph before Eq. (12.55)): the orthogonal projector onto the image +`Dₖ (S(n) K)` of the compressed subspace under the `k`-th decompression element `Dₖ`. Because +`Dₖ` cannot increase the dimension, `Sₖ` again has rank `≤ 2^numBits` +(`finrank_range_outputProjection_le`), and every composite operation element `Dₖ Cⱼ` factors +through it (`outputProjection_mul_composite`). -/ +noncomputable def outputProjection (sch : QuantumCompressionScheme K numBits) + (k : Fin sch.decCard) : K →L[ℂ] K := + (LinearMap.range ((sch.decode k * sch.compressedProjection : K →L[ℂ] K) : + K →ₗ[ℂ] K)).starProjection + +/-- The output-subspace projector `Sₖ` is an orthogonal projection (self-adjoint idempotent). -/ +theorem outputProjection_isStarProjection (sch : QuantumCompressionScheme K numBits) + (k : Fin sch.decCard) : IsStarProjection (sch.outputProjection k) := + isStarProjection_starProjection + +/-- Every composite operation element `Dₖ Cⱼ` factors through the output projector `Sₖ`: +`Sₖ Dₖ Cⱼ = Dₖ Cⱼ` (Nielsen & Chuang, §12.2.2, `Sₖ(n) Dₖ Cⱼ = Dₖ Cⱼ`). Indeed +`Dₖ Cⱼ = Dₖ S(n) Cⱼ` factors through `Dₖ S(n)`, whose image is the subspace `Sₖ` projects onto. -/ +theorem outputProjection_mul_composite (sch : QuantumCompressionScheme K numBits) + (k : Fin sch.decCard) (j : Fin sch.encCard) : + sch.outputProjection k * (sch.decode k * sch.encode j) = sch.decode k * sch.encode j := by + have hcomp : sch.decode k * sch.encode j + = (sch.decode k * sch.compressedProjection) * sch.encode j := by + rw [mul_assoc, sch.compressedProjection_mul_encode] + rw [hcomp, ← mul_assoc] + congr 1 + ext x + simp only [mul_apply_eq_comp, outputProjection] + exact (Submodule.starProjection_eq_self_iff).mpr (LinearMap.mem_range_self _ x) + +/-- The output subspace has dimension `≤ 2^numBits`: `Dₖ` maps the `≤ 2^numBits`-dimensional +compressed subspace to a subspace of no larger dimension. -/ +theorem finrank_range_outputProjection_le (sch : QuantumCompressionScheme K numBits) + (k : Fin sch.decCard) : + Module.finrank ℂ (LinearMap.range (sch.outputProjection k : K →ₗ[ℂ] K)) ≤ 2 ^ numBits := by + rw [outputProjection, Submodule.range_starProjection, ContinuousLinearMap.toLinearMap_mul, + Module.End.mul_eq_comp, LinearMap.range_comp] + exact (Submodule.finrank_map_le _ _).trans sch.finrank_range_compressedProjection_le + +/-- **The Cauchy–Schwarz core of Schumacher's converse** (Nielsen & Chuang, §12.2.2, +Eqs. (12.54)–(12.58)). Given an *arbitrary* family of orthogonal projectors `S k` such that every +composite operation element `Dₖ Cⱼ` factors through `S k` (`S k · Dₖ Cⱼ = Dₖ Cⱼ`) and the source +weight `re tr(S k · ρ)` in each output subspace is at most `δ`, the entanglement fidelity of the +source `ρ` through the scheme is at most `δ`. + +The proof splits `ρ = r · r` with `r = √ρ` (`cfc Real.sqrt ρ`) and reads each fidelity term +`tr(Dₖ Cⱼ ρ)` as a Hilbert–Schmidt pairing `⟨Dₖ Cⱼ r, S k · r⟩_HS`; Cauchy–Schwarz +(`norm_hsPairing_sq_le`) bounds its square by `re tr(Dₖ Cⱼ ρ Cⱼ† Dₖ†) · re tr(S k · ρ)`, and +trace-preservation (`composite_isTracePreserving`) sums the first factors to `tr ρ = 1`. -/ +theorem fidelity_le_of_output_projectors (sch : QuantumCompressionScheme K numBits) + {ρ : K →L[ℂ] K} (hρ : ρ.IsDensityOp) {δ : ℝ} (S : Fin sch.decCard → K →L[ℂ] K) + (hSproj : ∀ k, IsStarProjection (S k)) + (hSfix : ∀ k j, S k * (sch.decode k * sch.encode j) = sch.decode k * sch.encode j) + (hSbound : ∀ k, RCLike.re ((LinearMap.trace ℂ K) (↑(S k * ρ) : K →ₗ[ℂ] K)) ≤ δ) : + sch.fidelity ρ ≤ δ := by + classical + have hSadj : ∀ k, ContinuousLinearMap.adjoint (S k) = S k := fun k => by + rw [← ContinuousLinearMap.star_eq_adjoint]; exact (hSproj k).isSelfAdjoint.star_eq + have hSidem : ∀ k, S k * S k = S k := fun k => (hSproj k).isIdempotentElem + set r : K →L[ℂ] K := cfc Real.sqrt ρ with hrdef + -- The general pairing→trace identity `⟨X·√ρ, Y·√ρ⟩_HS = tr(Y† X ρ)` + -- (`ContinuousLinearMap.hsPairing_mul_cfc_sqrt_eq_trace`, in `Density.lean`). + have hgen : ∀ X Y : K →L[ℂ] K, (X * r).hsPairing (Y * r) + = (LinearMap.trace ℂ K) (↑(ContinuousLinearMap.adjoint Y * X * ρ) : K →ₗ[ℂ] K) := + fun X Y => ContinuousLinearMap.hsPairing_mul_cfc_sqrt_eq_trace hρ.nonneg X Y + -- Each fidelity term is the squared HS pairing `‖⟨Dₖ Cⱼ r, Sₖ r⟩_HS‖²`. + have hterm : ∀ k j, (LinearMap.trace ℂ K) (↑(sch.decode k * sch.encode j * ρ) : K →ₗ[ℂ] K) + = ((sch.decode k * sch.encode j) * r).hsPairing (S k * r) := by + intro k j + rw [hgen, hSadj k, hSfix k j] + -- The first Cauchy–Schwarz factors sum to `tr ρ = 1`. + have hcomp1 : (∑ p : Fin sch.decCard × Fin sch.encCard, + ContinuousLinearMap.adjoint (sch.decode p.1 * sch.encode p.2) + * (sch.decode p.1 * sch.encode p.2)) = 1 := sch.composite_isTracePreserving + have hCLM : (∑ k, ∑ j, ContinuousLinearMap.adjoint (sch.decode k * sch.encode j) + * (sch.decode k * sch.encode j) * ρ) = ρ := by + simp_rw [← Finset.sum_mul] + rw [← Finset.sum_product', Finset.univ_product_univ, hcomp1, one_mul] + have hC : (∑ k, ∑ j, (((sch.decode k * sch.encode j) * r).hsPairing + ((sch.decode k * sch.encode j) * r))) = (1 : ℂ) := by + simp_rw [hgen, ← map_sum, ← ContinuousLinearMap.toLinearMap_sum] + rw [hCLM, hρ.trace_eq_one] + have hsum1 : ∑ k, ∑ j, RCLike.re + (((sch.decode k * sch.encode j) * r).hsPairing ((sch.decode k * sch.encode j) * r)) = 1 := by + rw [show (1 : ℝ) = RCLike.re (1 : ℂ) from RCLike.one_re.symm, ← hC] + simp_rw [map_sum] + -- Assemble the bound. + rw [QuantumCompressionScheme.fidelity_eq] + calc ∑ k, ∑ j, ‖(LinearMap.trace ℂ K) (↑(sch.decode k * sch.encode j * ρ) : K →ₗ[ℂ] K)‖ ^ 2 + ≤ ∑ k, ∑ j, RCLike.re + (((sch.decode k * sch.encode j) * r).hsPairing ((sch.decode k * sch.encode j) * r)) + * δ := by + refine Finset.sum_le_sum fun k _ => Finset.sum_le_sum fun j _ => ?_ + rw [hterm k j] + refine (ContinuousLinearMap.norm_hsPairing_sq_le _ _).trans ?_ + refine mul_le_mul_of_nonneg_left ?_ (ContinuousLinearMap.re_hsPairing_self_nonneg _) + rw [hgen, hSadj k, hSidem k] + exact hSbound k + _ = δ := by simp_rw [← Finset.sum_mul]; rw [hsum1, one_mul] + +/-- **The converse bound of Schumacher's noiseless channel coding theorem** (Nielsen & Chuang, +§12.2.2, Theorem 12.6, Eqs. (12.54)–(12.58)), in terms of `QuantumCompressionScheme`. If every +orthogonal projector `P` onto a subspace of dimension at most `2^numBits` captures only weight +`re tr(P ρ) ≤ δ` of the source `ρ`, then the entanglement fidelity of `ρ` through the scheme is at +most `δ`. + +The witnesses are the output projectors `Sₖ = outputProjection sch k` (rank `≤ 2^numBits`, +`finrank_range_outputProjection_le`; factoring the composites, `outputProjection_mul_composite`); +`fidelity_le_of_output_projectors` then supplies the Cauchy–Schwarz estimate. Specialised to +`ρ = ρ^⊗n` and `numBits = ⌊nR⌋` with `R < S(ρ)`, the small-subspace bound (typical subspace theorem +part (3)) provides the hypothesis, forcing `F(ρ^⊗n, Dₙ∘Cₙ) → 0`. -/ +theorem fidelity_le (sch : QuantumCompressionScheme K numBits) {ρ : K →L[ℂ] K} + (hρ : ρ.IsDensityOp) {δ : ℝ} + (hsmall : ∀ P : K →L[ℂ] K, IsStarProjection P → + Module.finrank ℂ (LinearMap.range (P : K →ₗ[ℂ] K)) ≤ 2 ^ numBits → + RCLike.re ((LinearMap.trace ℂ K) (↑(P * ρ) : K →ₗ[ℂ] K)) ≤ δ) : + sch.fidelity ρ ≤ δ := + fidelity_le_of_output_projectors sch hρ (fun k => sch.outputProjection k) + (fun k => sch.outputProjection_isStarProjection k) + (fun k j => sch.outputProjection_mul_composite k j) + (fun k => hsmall _ (sch.outputProjection_isStarProjection k) + (sch.finrank_range_outputProjection_le k)) + +end ContinuousLinearMap.QuantumCompressionScheme diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherEncoder.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherEncoder.lean new file mode 100644 index 0000000000..e576cc1e6d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchumacherEncoder.lean @@ -0,0 +1,192 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EntanglementFidelity +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneProjector + +/-! # Schumacher's projection–reset encoder and its entanglement fidelity + +This file records the *encoding operation* used in the direct (achievability) part of Schumacher's +quantum noiseless channel coding theorem (Nielsen–Chuang, *Quantum Computation and Quantum +Information*, §12.2.2, eqs. (12.50)–(12.52)), together with the two structural facts that make it a +reliable compression scheme: it is trace-preserving, and its entanglement fidelity is bounded below +by `|tr(ρ P)|²`. + +Fix an orthonormal basis `b : OrthonormalBasis ι ℂ H`, a finite index set `s : Finset ι` — the +"typical" indices, cutting out the code subspace `range P` with projector +`P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|` (`InnerProductSpace.orthonormalProjector`) — and a reference index `i₀`. +The **projection–reset encoder** is the trace-preserving quantum operation with operation elements +`{P} ∪ {Aᵢ : i ∉ s}`, where `Aᵢ = |b i₀⟩⟨bᵢ|` (N&C eq. (12.50)): + +`C(σ) = P σ P + ∑_{i ∉ s} Aᵢ σ Aᵢ†`. + +The projector `P` leaves the code subspace untouched, while each reset operator `Aᵢ` collapses the +atypical basis vector `bᵢ` onto the fixed reference vector `b i₀`; taking `i₀ ∈ s` puts the whole +image inside the code subspace, so `C` compresses into `range P`. The decoding operation is the +identity, so the composite `D ∘ C` has the same operation elements as `C`. + +## Main results + +* `ContinuousLinearMap.schumacherEncoder` — the family of operation elements, indexed by `Option ι` + (`none ↦ P`, `some i ↦ Aᵢ`, taken to be `0` for `i ∈ s`). +* `ContinuousLinearMap.schumacherEncoder_isTracePreserving` — the completeness relation + `∑ⱼ Eⱼ† Eⱼ = 1`, i.e. `C` is a trace-preserving quantum operation. It follows from + `P + ∑_{i ∉ s} |bᵢ⟩⟨bᵢ| = 1` (the resolution of identity split across `s` and `sᶜ`). +* `ContinuousLinearMap.entanglementFidelity_schumacherEncoder` — **N&C eq. (12.51)**: + `F(ρ, C) = |tr(ρ P)|² + ∑_{i ∉ s} |tr(ρ Aᵢ)|²`. +* `ContinuousLinearMap.entanglementFidelity_schumacherEncoder_ge` — **N&C eq. (12.52)**: + `F(ρ, C) ≥ |tr(ρ P)|²`, because `P` is one of the operation elements and the remaining terms are + nonnegative. In Schumacher's theorem the right-hand side is `|tr(ρ^⊗ⁿ P(n,ε))|² ≥ (1 − δ)²` by + part (1) of the typical subspace theorem, giving reliability. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.2.2 (eqs. (12.50)–(12.52)). +-/ + +open scoped InnerProductSpace ComplexConjugate + +@[expose] public section + +namespace ContinuousLinearMap + +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + {ι : Type*} [Fintype ι] [DecidableEq ι] + +/-- **Schumacher's projection–reset encoder** (Nielsen & Chuang, eq. (12.50)), as a family of +operation elements indexed by `Option ι`. Given an orthonormal basis `b`, a set `s` of "typical" +indices and a reference index `i₀`: + +* `none ↦ P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|`, the projector onto the code subspace; +* `some i ↦ |b i₀⟩⟨bᵢ|` for `i ∉ s` (and `0` for `i ∈ s`), the reset operator collapsing the + atypical vector `bᵢ` onto the reference vector `b i₀`. + +The associated quantum operation is `C(σ) = P σ P + ∑_{i ∉ s} |b i₀⟩⟨bᵢ| σ |bᵢ⟩⟨b i₀|`; it is +trace-preserving (`schumacherEncoder_isTracePreserving`). -/ +noncomputable def schumacherEncoder (b : OrthonormalBasis ι ℂ H) (s : Finset ι) (i₀ : ι) : + Option ι → H →L[ℂ] H + | none => InnerProductSpace.orthonormalProjector ℂ (⇑b) s + | some i => if i ∈ s then 0 else (InnerProductSpace.rankOne ℂ (b i₀)) (b i) + +/-- The `none` element of the Schumacher encoder is the code-subspace projector `P`. -/ +@[simp] +theorem schumacherEncoder_none (b : OrthonormalBasis ι ℂ H) (s : Finset ι) (i₀ : ι) : + schumacherEncoder b s i₀ none = InnerProductSpace.orthonormalProjector ℂ (⇑b) s := rfl + +/-- For an atypical index `i ∉ s`, the `some i` element of the Schumacher encoder is the reset +operator `Aᵢ = |b i₀⟩⟨bᵢ|`. -/ +theorem schumacherEncoder_some_of_notMem (b : OrthonormalBasis ι ℂ H) {s : Finset ι} {i : ι} + (hi : i ∉ s) (i₀ : ι) : + schumacherEncoder b s i₀ (some i) = (InnerProductSpace.rankOne ℂ (b i₀)) (b i) := + ite_eq_right hi + +/-- For a typical index `i ∈ s`, the `some i` element of the Schumacher encoder vanishes (that basis +vector is already handled by the projector `P`). -/ +theorem schumacherEncoder_some_of_mem (b : OrthonormalBasis ι ℂ H) {s : Finset ι} {i : ι} + (hi : i ∈ s) (i₀ : ι) : schumacherEncoder b s i₀ (some i) = 0 := + ite_eq_left hi + +/-- **Nielsen & Chuang, Eq. (12.55).** Every Schumacher operation element factors through the code +projector `P = ∑_{i ∈ s} |bᵢ⟩⟨bᵢ|`: `P · Eₒ = Eₒ`. The projector element (`none`) is idempotent +(`P · P = P`); a typical reset element (`some i ∈ s`) is `0`; and an atypical reset element +(`some i ∉ s`) is `|b i₀⟩⟨bᵢ|`, on which `P` acts as the identity because `i₀ ∈ s` fixes +`P (b i₀) = b i₀`. This is the compression condition satisfied by the projection–reset encoder, used +to build the code subspace of a compression scheme. -/ +theorem orthonormalProjector_mul_schumacherEncoder (b : OrthonormalBasis ι ℂ H) (s : Finset ι) + (i₀ : ι) (hi₀ : i₀ ∈ s) (o : Option ι) : + InnerProductSpace.orthonormalProjector ℂ (⇑b) s * schumacherEncoder b s i₀ o + = schumacherEncoder b s i₀ o := by + cases o with + | none => + rw [schumacherEncoder_none] + exact InnerProductSpace.isIdempotentElem_orthonormalProjector b.orthonormal s + | some i => + by_cases hi : i ∈ s + · rw [schumacherEncoder_some_of_mem b hi, mul_zero] + · rw [schumacherEncoder_some_of_notMem b hi, mul_def, InnerProductSpace.comp_rankOne, + InnerProductSpace.orthonormalProjector_apply_eq_ite b.orthonormal s i₀, ite_eq_left hi₀] + +variable [CompleteSpace H] + +/-- The Schumacher encoder is a **trace-preserving** quantum operation: its operation elements +satisfy the completeness relation `∑ⱼ Eⱼ† Eⱼ = 1` (Nielsen & Chuang, §12.2.2). Each reset element +contributes `Aᵢ† Aᵢ = |bᵢ⟩⟨bᵢ|` (using `‖b i₀‖ = 1`), the projector contributes `P† P = P`, and +`P + ∑_{i ∉ s} |bᵢ⟩⟨bᵢ|` is the resolution of identity `∑ᵢ |bᵢ⟩⟨bᵢ| = 1` split across `s` +and `sᶜ`. -/ +theorem schumacherEncoder_isTracePreserving (b : OrthonormalBasis ι ℂ H) (s : Finset ι) (i₀ : ι) : + ∑ j, adjoint (schumacherEncoder b s i₀ j) * (schumacherEncoder b s i₀ j) = 1 := by + rw [Fintype.sum_option] + have hnone : adjoint (schumacherEncoder b s i₀ none) * (schumacherEncoder b s i₀ none) + = InnerProductSpace.orthonormalProjector ℂ (⇑b) s := by + have hp := InnerProductSpace.isStarProjection_orthonormalProjector b.orthonormal s + rw [schumacherEncoder_none, ← star_eq_adjoint, hp.isSelfAdjoint] + exact hp.isIdempotentElem + have hsome : ∀ i, + adjoint (schumacherEncoder b s i₀ (some i)) * (schumacherEncoder b s i₀ (some i)) + = if i ∈ s then 0 else (InnerProductSpace.rankOne ℂ (b i)) (b i) := by + intro i + by_cases hi : i ∈ s + · rw [schumacherEncoder_some_of_mem b hi, ite_eq_left hi]; simp + · rw [schumacherEncoder_some_of_notMem b hi, ite_eq_right hi, InnerProductSpace.adjoint_rankOne, + mul_def, InnerProductSpace.rankOne_comp_rankOne, + orthonormal_iff_ite.mp b.orthonormal i₀ i₀] + simp + rw [hnone, Finset.sum_congr rfl (fun i _ => hsome i), Finset.sum_ite, Finset.sum_const_zero, + zero_add] + have hfilter : (Finset.univ.filter (fun i => i ∉ s)) = sᶜ := by ext i; simp + rw [hfilter, InnerProductSpace.orthonormalProjector_eq_sum, + Finset.sum_add_sum_compl s (fun i => (InnerProductSpace.rankOne ℂ (b i)) (b i)), + OrthonormalBasis.sum_rankOne_eq_id] + rfl + +omit [CompleteSpace H] in +/-- **Nielsen & Chuang, eq. (12.51).** The entanglement fidelity of the Schumacher encoder splits as +`F(ρ, C) = |tr(ρ P)|² + ∑_{i ∉ s} |tr(ρ Aᵢ)|²`, the code-projector term plus the reset-operator +terms. -/ +theorem entanglementFidelity_schumacherEncoder (b : OrthonormalBasis ι ℂ H) (s : Finset ι) + (i₀ : ι) (ρ : H →L[ℂ] H) : + entanglementFidelity ρ (schumacherEncoder b s i₀) + = ‖LinearMap.trace ℂ H + ((ρ * InnerProductSpace.orthonormalProjector ℂ (⇑b) s : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 + + ∑ i ∈ sᶜ, ‖LinearMap.trace ℂ H + ((ρ * (InnerProductSpace.rankOne ℂ (b i₀)) (b i) : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 := by + rw [entanglementFidelity, Fintype.sum_option, schumacherEncoder_none] + congr 1 + have hsome : ∀ i, ‖LinearMap.trace ℂ H + ((ρ * schumacherEncoder b s i₀ (some i) : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 + = if i ∈ s then 0 else ‖LinearMap.trace ℂ H + ((ρ * (InnerProductSpace.rankOne ℂ (b i₀)) (b i) : H →L[ℂ] H) : H →ₗ[ℂ] H)‖ ^ 2 := by + intro i + by_cases hi : i ∈ s + · rw [schumacherEncoder_some_of_mem b hi, ite_eq_left hi]; simp + · rw [schumacherEncoder_some_of_notMem b hi, ite_eq_right hi] + rw [Finset.sum_congr rfl (fun i _ => hsome i), Finset.sum_ite, Finset.sum_const_zero, zero_add] + congr 1 + ext i; simp + +omit [CompleteSpace H] in +/-- **Nielsen & Chuang, eq. (12.52).** The entanglement fidelity of the Schumacher encoder is +bounded below by `|tr(ρ P)|²`, the squared overlap of `ρ` with the code projector `P`: `P` is one of +the operation elements and the remaining reset-operator terms are nonnegative. This is the direct +(achievability) inequality of Schumacher's noiseless channel coding theorem: with `ρ = ρ^⊗ⁿ` and +`P = P(n, ε)` the typical subspace projector, part (1) of the typical subspace theorem gives +`tr(ρ^⊗ⁿ P) ≥ 1 − δ`, whence `F ≥ (1 − δ)²`. -/ +theorem entanglementFidelity_schumacherEncoder_ge (b : OrthonormalBasis ι ℂ H) (s : Finset ι) + (i₀ : ι) (ρ : H →L[ℂ] H) : + ‖LinearMap.trace ℂ H ((ρ * InnerProductSpace.orthonormalProjector ℂ (⇑b) s : H →L[ℂ] H) : + H →ₗ[ℂ] H)‖ ^ 2 + ≤ entanglementFidelity ρ (schumacherEncoder b s i₀) := by + rw [entanglementFidelity, ← schumacherEncoder_none b s i₀] + exact Finset.single_le_sum + (f := fun j => ‖LinearMap.trace ℂ H ((ρ * schumacherEncoder b s i₀ j : H →L[ℂ] H) : + H →ₗ[ℂ] H)‖ ^ 2) (fun j _ => sq_nonneg _) (Finset.mem_univ none) + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchurComplement.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchurComplement.lean new file mode 100644 index 0000000000..4ea65afdb0 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SchurComplement.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Topology.Algebra.Module.FiniteDimension + +/-! +# Schur complement at the linear-map level + +For an invertible self-adjoint operator `A` on an inner product space, and self-adjoint operators +`X, B`, the Schur complement of the hermitian block `[[A, X], [X, B]]` is `B - X · A⁻¹ · X`. +This file proves the forward direction of the Schur complement positivity criterion: if the block +quadratic form is nonneg, then the Schur complement is positive semidefinite (`IsPositive`). + +This is the LinearMap-level analog of `Matrix.PosDef.fromBlocks₁₁` (which requires a CommRing of +matrix entries); the present lemma works on any inner product space. + +## Main results + +* `LinearMap.IsSymmetric.ringInverse` — the ring inverse of a self-adjoint invertible operator is + self-adjoint. +* `LinearMap.schurComplement_isPositive_of_block_quadForm_nonneg` — Carlen Lemma 3.2 (forward + direction): block PSD ⇒ Schur complement PSD. +* `ContinuousLinearMap.schurComplement_nonneg_of_block_quadForm_nonneg` — CLM-level lift via the + CLM↔LM ring iso in finite dimensions. +-/ + +namespace LinearMap + +open RCLike + +variable {𝕜 : Type*} [RCLike 𝕜] +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +@[expose] public section SchurComplement + +/-- For an invertible operator `A`, `A (Ring.inverse A z) = z`. -/ +private lemma apply_ringInverse {A : E →ₗ[𝕜] E} (hAu : IsUnit A) (z : E) : + A (Ring.inverse A z) = z := + (LinearMap.congr_fun (Ring.mul_inverse_cancel A hAu) z).trans (one_apply_eq_self _) + +/-- The ring inverse of an invertible self-adjoint operator is self-adjoint. -/ +lemma IsSymmetric.ringInverse {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) (hAu : IsUnit A) : + (Ring.inverse A).IsSymmetric := fun x y ↦ by + conv_lhs => rw [← apply_ringInverse hAu y] + rw [← hA, apply_ringInverse hAu] + +/-- **Schur complement, forward direction**: if the hermitian block operator `[[A, X], [X, B]]` +(with `A` invertible self-adjoint, `X` self-adjoint, `B` self-adjoint) is positive semidefinite +as a quadratic form on `E × E`, then the Schur complement `B - X · A⁻¹ · X` is positive +semidefinite. + +Forward direction of Carlen Lemma 3.2 at the linear-map level on an inner product space; the +substitution `(x, y) ↦ (-(A⁻¹ X y), y)` reduces the block quadratic form to the Schur +complement's quadratic form. -/ +lemma schurComplement_isPositive_of_block_quadForm_nonneg + {A : E →ₗ[𝕜] E} (hAu : IsUnit A) (hA : A.IsSymmetric) + {X B : E →ₗ[𝕜] E} (hX : X.IsSymmetric) (hB : B.IsSymmetric) + (h_block : ∀ x y : E, + 0 ≤ re (inner 𝕜 x (A x) + inner 𝕜 x (X y) + inner 𝕜 y (X x) + inner 𝕜 y (B y))) : + (B - X ∘ₗ Ring.inverse A ∘ₗ X).IsPositive := by + have hA_inv : (Ring.inverse A).IsSymmetric := hA.ringInverse hAu + refine ⟨fun u v ↦ ?_, fun y ↦ ?_⟩ + · -- Symmetry of `B - X · A⁻¹ · X`. + simp only [LinearMap.sub_apply, LinearMap.comp_apply, inner_sub_left, inner_sub_right] + rw [hB, hX, hA_inv, hX] + · -- Nonnegativity: substitute `(x, y) ↦ (-(A⁻¹ X y), y)`; cross terms cancel. + have key := h_block (-(Ring.inverse A) (X y)) y + simp only [map_neg, inner_neg_left, inner_neg_right, apply_ringInverse hAu, neg_neg, + LinearMap.sub_apply, LinearMap.comp_apply, inner_sub_left, map_sub, map_add] at key ⊢ + rw [inner_re_symm (B y) y, inner_re_symm (X (Ring.inverse A (X y))) y] + linarith [key] + +end SchurComplement + +end LinearMap + +namespace ContinuousLinearMap + +open RCLike + +variable {𝕜 : Type*} [RCLike 𝕜] +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] + [FiniteDimensional 𝕜 E] + +@[expose] public section SchurComplement + +/-- **CLM-level forward Schur complement**: thin lift of the LM-level +`LinearMap.schurComplement_isPositive_of_block_quadForm_nonneg` to the CLM C⋆-order. In finite +dimensions the ring homomorphism `(· : E →L[𝕜] E) → (E →ₗ[𝕜] E)` is a ring isomorphism, so +`IsUnit`, `Ring.inverse`, and `IsPositive` transport across it faithfully. -/ +theorem schurComplement_nonneg_of_block_quadForm_nonneg + {A : E →L[𝕜] E} (hAu : IsUnit A) (hA : IsSelfAdjoint A) + {X B : E →L[𝕜] E} (hX : IsSelfAdjoint X) (hB : IsSelfAdjoint B) + (h_block : ∀ x y : E, + 0 ≤ re (inner 𝕜 x (A x) + inner 𝕜 x (X y) + inner 𝕜 y (X x) + inner 𝕜 y (B y))) : + 0 ≤ B - X * Ring.inverse A * X := by + rw [ContinuousLinearMap.nonneg_iff_isPositive, + ← ContinuousLinearMap.isPositive_toLinearMap_iff] + simp only [ContinuousLinearMap.toLinearMap_sub, ContinuousLinearMap.toLinearMap_mul, + ContinuousLinearMap.coe_ringInverse] + exact LinearMap.schurComplement_isPositive_of_block_quadForm_nonneg + (hAu.map ContinuousLinearMap.toLinearMapRingHom) + hA.isSymmetric hX.isSymmetric hB.isSymmetric h_block + +end SchurComplement + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SelfAdjointFinrank.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SelfAdjointFinrank.lean new file mode 100644 index 0000000000..10058e0906 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SelfAdjointFinrank.lean @@ -0,0 +1,120 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Algebra.Star.Module +public import Mathlib.LinearAlgebra.Complex.FiniteDimensional +public import Mathlib.LinearAlgebra.Dimension.Constructions +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint +public import LeanPool.AxQM.ToMathlib.Topology.Algebra.Module.FiniteDimension +public import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix + +/-! +# Real dimension of the self-adjoint elements of a complex star module + +For a finite-dimensional complex star module `A` (a complex vector space with a compatible +conjugate-linear involution `star`), the real vector space `selfAdjoint A` of its self-adjoint +elements has real dimension equal to the *complex* dimension of `A`: + +`finrank ℝ (selfAdjoint A) = finrank ℂ A` (`finrank_real_selfAdjoint`). + +The complex module `A` splits as the real-internal direct sum of its self-adjoint and skew-adjoint +parts (`StarModule.decomposeProdAdjoint`), and multiplication by `-i` (`skewAdjoint.negIEquiv`) is a +real-linear isomorphism between the two summands, so each has real dimension +`(finrank ℝ A) / 2 = finrank ℂ A` (`finrank_real_of_complex`). + +Specialising `A` to the endomorphism algebra `E →L[ℂ] E` of a finite-dimensional complex inner +product space, whose star is the adjoint, gives + +`finrank ℝ (selfAdjoint (E →L[ℂ] E)) = (finrank ℂ E)²` +(`finrank_real_selfAdjoint_continuousLinearMap`), + +the `d²` real degrees of freedom of a Hermitian operator on a `d`-dimensional space. This is the +ambient dimension in the Carathéodory bound on the number of pure states needed to attain a +channel's Holevo χ quantity (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 12.11). + +## Main statements + +* `skewAdjoint.negIEquiv` — multiplication by `-i` as a real-linear equivalence + `skewAdjoint A ≃ₗ[ℝ] selfAdjoint A`. +* `finrank_real_selfAdjoint` — the general star-module identity. +* `finrank_real_selfAdjoint_continuousLinearMap` — the operator specialisation. +-/ + +public section + +/-- **Multiplication by `-i` as a real-linear equivalence `skewAdjoint A ≃ₗ[ℝ] selfAdjoint A`** +for a complex star module `A`. The invertible upgrade of Mathlib's bare real-linear map +`skewAdjoint.negISMul`: multiplication by `i` is a two-sided inverse, since `i • (-i • x) = x` +(`skewAdjoint.I_smul_neg_I`) and `i • s` is skew-adjoint whenever `s` is self-adjoint. -/ +noncomputable def skewAdjoint.negIEquiv (A : Type*) [AddCommGroup A] [Module ℂ A] + [StarAddMonoid A] [StarModule ℂ A] : skewAdjoint A ≃ₗ[ℝ] selfAdjoint A := + LinearEquiv.ofBijective skewAdjoint.negISMul + ⟨fun a b hab => by + have h1 : Complex.I • (↑(skewAdjoint.negISMul a) : A) = + Complex.I • ↑(skewAdjoint.negISMul b) := by rw [hab] + rw [skewAdjoint.I_smul_neg_I, skewAdjoint.I_smul_neg_I] at h1 + exact SetLike.coe_eq_coe.mp h1, + fun s => by + have hmem : Complex.I • (↑s : A) ∈ skewAdjoint A := by + rw [skewAdjoint.mem_iff, star_smul, selfAdjoint.mem_iff.mp s.2] + simp [Complex.conj_I] + exact ⟨⟨Complex.I • (↑s : A), hmem⟩, by + rw [← SetLike.coe_eq_coe, skewAdjoint.negISMul_apply_coe, smul_smul] + simp [Complex.I_mul_I]⟩⟩ + +/-- **The real dimension of the self-adjoint elements of a finite-dimensional complex star module +`A` equals its complex dimension**: `finrank ℝ (selfAdjoint A) = finrank ℂ A`. + +`A` decomposes as the real-internal direct sum `selfAdjoint A ⊕ skewAdjoint A` +(`StarModule.decomposeProdAdjoint`); multiplication by `-i` is a real-linear isomorphism +`skewAdjoint A ≃ₗ[ℝ] selfAdjoint A` (`skewAdjoint.negIEquiv`), so the two summands have equal real +dimension. Since `finrank ℝ A = 2 · finrank ℂ A` (`finrank_real_of_complex`), each summand — in +particular `selfAdjoint A` — has real dimension `finrank ℂ A`. -/ +theorem finrank_real_selfAdjoint (A : Type*) [AddCommGroup A] [Module ℂ A] + [StarAddMonoid A] [StarModule ℂ A] [Module.Finite ℂ A] : + Module.finrank ℝ (selfAdjoint A) = Module.finrank ℂ A := by + have : Module.Finite ℝ A := Module.Finite.trans ℂ A + have : Module.Finite ℝ (↥(selfAdjoint A) × ↥(skewAdjoint A)) := + Module.Finite.equiv (StarModule.decomposeProdAdjoint ℝ A) + have : Module.Finite ℝ ↥(selfAdjoint A) := + Module.Finite.of_surjective (LinearMap.fst ℝ (↥(selfAdjoint A)) (↥(skewAdjoint A))) + Prod.fst_surjective + have : Module.Finite ℝ ↥(skewAdjoint A) := + Module.Finite.of_surjective (LinearMap.snd ℝ (↥(selfAdjoint A)) (↥(skewAdjoint A))) + Prod.snd_surjective + -- `selfAdjoint` and `skewAdjoint` have equal real dimension (`skewAdjoint.negIEquiv` is a + -- real-linear equivalence between them), together exhausting `finrank ℝ A` + have hss : Module.finrank ℝ (selfAdjoint A) = Module.finrank ℝ (skewAdjoint A) := + (skewAdjoint.negIEquiv A).finrank_eq.symm + have hdecomp : Module.finrank ℝ A = + Module.finrank ℝ (selfAdjoint A) + Module.finrank ℝ (skewAdjoint A) := by + rw [(StarModule.decomposeProdAdjoint ℝ A).finrank_eq, Module.finrank_prod] + have hA : Module.finrank ℝ A = 2 * Module.finrank ℂ A := finrank_real_of_complex A + rw [← hss] at hdecomp + omega + +/-- **The real dimension of the self-adjoint (Hermitian) operators on a finite-dimensional complex +inner product space `E` is `(finrank ℂ E)²`**: +`finrank ℝ (selfAdjoint (E →L[ℂ] E)) = (finrank ℂ E)²`. + +The star on `E →L[ℂ] E` is the adjoint, so `selfAdjoint (E →L[ℂ] E)` is the space of Hermitian +operators. Applying `finrank_real_selfAdjoint` to `A = E →L[ℂ] E` reduces the claim to the complex +dimension `finrank ℂ (E →L[ℂ] E) = (finrank ℂ E)²`, computed via the linear equivalence with +`E →ₗ[ℂ] E` (`LinearMap.toContinuousLinearMap`, all linear maps on a finite-dimensional space being +continuous) and `Module.finrank_linearMap`. For `d = finrank ℂ E` this records the `d²` real degrees +of freedom of a Hermitian operator on a `d`-dimensional space — the ambient dimension in the +Carathéodory bound of Nielsen & Chuang, Exercise 12.11. -/ +theorem finrank_real_selfAdjoint_continuousLinearMap {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] : + Module.finrank ℝ (selfAdjoint (E →L[ℂ] E)) = (Module.finrank ℂ E) ^ 2 := by + rw [finrank_real_selfAdjoint (E →L[ℂ] E), + ← (LinearMap.toContinuousLinearMap (𝕜 := ℂ) (E := E) (F' := E)).finrank_eq, + Module.finrank_linearMap ℂ ℂ E E, sq] diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SingularValues.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SingularValues.lean new file mode 100644 index 0000000000..4580fe82bf --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/SingularValues.lean @@ -0,0 +1,350 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Algebra.BigOperators.Fin +public import TauCeti.Analysis.InnerProductSpace.SingularValues + +/-! +# Singular values for finite-dimensional linear maps: additional API and the SVD + +This file collects additional facts about `LinearMap.singularValues` (invariance under adjoint, +negation, scalar multiplication, and composition with linear isometries) and the singular value +decomposition itself (`LinearMap.svdRight`, `LinearMap.svdLeft`, `LinearMap.svd_apply`), together +with their `ContinuousLinearMap` counterparts. +-/ + +@[expose] public section + +open Module InnerProductSpace + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + (T : E →ₗ[𝕜] F) + +/-- If the domain is subsingleton (so `finrank 𝕜 E = 0`), all singular values are zero. -/ +theorem singularValues_of_subsingleton [Subsingleton E] (i : ℕ) : T.singularValues i = 0 := + T.singularValues_of_finrank_le (by rw [Module.finrank_zero_of_subsingleton]; exact Nat.zero_le _) + +/-- **Singular values are determined by the adjoint-comp-self operator.** If +`S.adjoint ∘ₗ S = T.adjoint ∘ₗ T`, then `S.singularValues = T.singularValues`. Common +underlying structural fact for `singularValues_neg`, `singularValues_linearIsometry_comp`, +and any future "two operators have same adjoint-comp-self ⟹ same singular values" consumer. -/ +theorem singularValues_eq_of_adjoint_comp_self_eq + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + {S : E →ₗ[𝕜] G} (h_op : S.adjoint ∘ₗ S = T.adjoint ∘ₗ T) : + S.singularValues = T.singularValues := by + have h_eig : S.isSymmetric_adjoint_comp_self.eigenvalues rfl = + T.isSymmetric_adjoint_comp_self.eigenvalues rfl := by + rw [IsSymmetric.eigenvalues_eq_eigenvalues_iff, h_op] + ext i + by_cases h : i < Module.finrank 𝕜 E + · rw [singularValues_of_lt _ rfl h, singularValues_of_lt _ rfl h] + exact congrArg Real.sqrt (congrFun h_eig ⟨i, h⟩) + · rw [singularValues_of_finrank_le _ (Nat.le_of_not_lt h), + singularValues_of_finrank_le _ (Nat.le_of_not_lt h)] + +/-- Singular values are invariant under negation: `(-T).singularValues = T.singularValues`. +Follows from `(-T).adjoint ∘ₗ (-T) = T.adjoint ∘ₗ T` (the two negations cancel) via +`singularValues_eq_of_adjoint_comp_self_eq`. -/ +theorem singularValues_neg : (-T).singularValues = T.singularValues := + singularValues_eq_of_adjoint_comp_self_eq T (by simp) + +/-- For a positive endomorphism `S : E →ₗ[𝕜] E`, the singular values coincide pointwise with the +eigenvalues. Follows from `sq_singularValues_fin` + `IsPositive.eigenvalues_sq` + `sq_eq_sq₀` +on the common nonneg sign. -/ +theorem IsPositive.singularValues_eq_eigenvalues + {S : E →ₗ[𝕜] E} (hS : S.IsPositive) {n : ℕ} (hn : finrank 𝕜 E = n) (i : Fin n) : + S.singularValues i = hS.isSymmetric.eigenvalues hn i := by + refine (sq_eq_sq₀ (S.singularValues_nonneg i.val) (hS.nonneg_eigenvalues hn i)).mp ?_ + have h_op : S.adjoint ∘ₗ S = S * S := by rw [hS.isSymmetric.adjoint_eq]; rfl + rw [sq_singularValues_fin _ hn, ← Pi.pow_apply, + ← hS.eigenvalues_sq hn (h_op ▸ S.isSymmetric_adjoint_comp_self)] + congr 1 + +/-- A `Fin n`-indexed sum of singular values equals the `Finset.range`-indexed sum over the +support, provided `n` covers the support: `finrank T.range ≤ n`. The truncated entries are zero +by `singularValues_eq_zero_iff_le_finrank_range`. -/ +theorem sum_singularValues_eq_sum_range_finrank_range + (T : E →ₗ[𝕜] F) {n : ℕ} (hr : finrank 𝕜 T.range ≤ n) : + ∑ i : Fin n, T.singularValues i.val = + ∑ i ∈ Finset.range (finrank 𝕜 T.range), T.singularValues i := by + rw [Fin.sum_univ_eq_sum_range (fun i ↦ T.singularValues i), + ← Finset.sum_subset (Finset.range_subset_range.mpr hr)] + intro x _ hnx + rw [Finset.mem_range, not_lt] at hnx + exact T.singularValues_eq_zero_iff_le_finrank_range.mpr hnx + +/-! ### Singular value decomposition + +The orthonormal eigenbasis of `T† ∘ T` provides the right singular vectors of `T`. +The left singular vectors are then defined as `σᵢ⁻¹ • T uᵢ` on the support +`{i | σᵢ ≠ 0}` (and as junk values elsewhere via the inverse-of-zero convention). The +factorization theorem `LinearMap.svd_apply` expresses `T x` as a sum over this +decomposition. +-/ + +/-- The right singular vectors of `T`: an orthonormal eigenbasis of `T† ∘ T`. -/ +noncomputable def svdRight : OrthonormalBasis (Fin (finrank 𝕜 E)) 𝕜 E := + T.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl + +theorem svdRight_apply (i : Fin (finrank 𝕜 E)) : + T.svdRight i = T.isSymmetric_adjoint_comp_self.eigenvectorBasis rfl i := rfl + +/-- The left singular vectors of `T`: `σᵢ⁻¹ • T uᵢ` (junk when `σᵢ = 0`). -/ +noncomputable def svdLeft (i : Fin (finrank 𝕜 E)) : F := + ((T.singularValues i.val : 𝕜))⁻¹ • T (T.svdRight i) + +theorem svdLeft_apply (i : Fin (finrank 𝕜 E)) : + T.svdLeft i = ((T.singularValues i.val : 𝕜))⁻¹ • T (T.svdRight i) := rfl + +/-- A right singular vector with zero singular value is in the kernel of `T`. -/ +theorem apply_svdRight_eq_zero_of_singularValues_eq_zero (i : Fin (finrank 𝕜 E)) + (hi : T.singularValues i.val = 0) : T (T.svdRight i) = 0 := by + have hsq : T.singularValues i.val ^ 2 = 0 := by simp [hi] + rw [T.sq_singularValues_fin rfl] at hsq + rw [← norm_eq_zero (E := F), ← sq_eq_zero_iff, ← inner_self_eq_norm_sq (𝕜 := 𝕜), + ← T.adjoint_inner_right, svdRight_apply, ← LinearMap.comp_apply, + T.isSymmetric_adjoint_comp_self.apply_eigenvectorBasis rfl i, inner_smul_right, + hsq, RCLike.ofReal_zero, zero_mul, map_zero] + +/-- A left singular vector with zero singular value is itself zero. Follows from +`svdLeft i = σᵢ⁻¹ • T (svdRight i)` and `T (svdRight i) = 0` when `σᵢ = 0`. -/ +theorem svdLeft_eq_zero_of_singularValues_eq_zero (i : Fin (finrank 𝕜 E)) + (hi : T.singularValues i.val = 0) : T.svdLeft i = 0 := by + rw [svdLeft_apply, T.apply_svdRight_eq_zero_of_singularValues_eq_zero i hi, smul_zero] + +/-- The fundamental SVD relation: applying `T` to a right singular vector scales the +corresponding left singular vector by the singular value. Holds even for the junk +left vectors when `σᵢ = 0`, since both sides vanish. -/ +theorem apply_svdRight (i : Fin (finrank 𝕜 E)) : + T (T.svdRight i) = (T.singularValues i.val : 𝕜) • T.svdLeft i := by + rw [svdLeft_apply, smul_smul] + by_cases hi : T.singularValues i.val = 0 + · rw [T.apply_svdRight_eq_zero_of_singularValues_eq_zero i hi, smul_zero] + · rw [mul_inv_cancel₀ (by exact_mod_cast hi), one_smul] + +/-- **Inner products of left singular vectors** (unconditional form): for any `i, j`, +`⟪svdLeft i, svdLeft j⟫ = 1` iff `i = j ∧ σᵢ ≠ 0`, else `0`. Handles the σᵢ = 0 and +σⱼ = 0 degenerate cases by returning 0 (the corresponding svdLeft is zero). -/ +@[simp] +theorem inner_svdLeft_svdLeft_full (i j : Fin (finrank 𝕜 E)) : + ⟪T.svdLeft i, T.svdLeft j⟫_𝕜 = if (i = j ∧ T.singularValues i.val ≠ 0) then 1 else 0 := by + by_cases hi : T.singularValues i.val = 0 + · rw [T.svdLeft_eq_zero_of_singularValues_eq_zero i hi, inner_zero_left, + ite_eq_right (fun ⟨_, h⟩ ↦ h hi)] + by_cases hj : T.singularValues j.val = 0 + · rw [T.svdLeft_eq_zero_of_singularValues_eq_zero j hj, inner_zero_right, + ite_eq_right (fun ⟨hij, _⟩ ↦ hi (hij.symm ▸ hj))] + -- Both σᵢ ≠ 0 and σⱼ ≠ 0: the original conditional argument. + have hsym := T.isSymmetric_adjoint_comp_self + simp only [svdLeft_apply, svdRight_apply, inner_smul_left, inner_smul_right] + rw [← T.adjoint_inner_right, ← LinearMap.comp_apply, + hsym.apply_eigenvectorBasis rfl j, inner_smul_right] + have hij_inner : ⟪hsym.eigenvectorBasis rfl i, hsym.eigenvectorBasis rfl j⟫_𝕜 = + if i = j then 1 else 0 := by + by_cases hij : i = j + · simp [hij, (hsym.eigenvectorBasis rfl).orthonormal.1 j] + · simp [hij, (hsym.eigenvectorBasis rfl).orthonormal.2 hij] + rw [hij_inner] + by_cases hij : i = j + · subst hij + have heig : (hsym.eigenvalues rfl i : 𝕜) = ((T.singularValues i.val) ^ 2 : 𝕜) := by + rw [← T.sq_singularValues_fin rfl]; push_cast; ring + rw [ite_eq_left rfl, mul_one, heig, map_inv₀, RCLike.conj_ofReal, ite_eq_left ⟨rfl, hi⟩] + have hne : (T.singularValues i.val : 𝕜) ≠ 0 := by exact_mod_cast hi + field_simp + · rw [ite_eq_right hij, ite_eq_right (fun ⟨h, _⟩ ↦ hij h)] + simp + +/-- Left singular vectors have norm at most one: `‖svdLeft i‖ = 1` when `σᵢ ≠ 0` and +`‖svdLeft i‖ = 0` when `σᵢ = 0` (in which case `svdLeft i = 0`). -/ +theorem norm_svdLeft_le_one (i : Fin (finrank 𝕜 E)) : ‖T.svdLeft i‖ ≤ 1 := by + have : ‖T.svdLeft i‖ ^ 2 ≤ 1 := by + rw [@norm_sq_eq_re_inner 𝕜, T.inner_svdLeft_svdLeft_full]; split_ifs <;> simp + nlinarith [norm_nonneg (T.svdLeft i)] + +/-- The left singular vectors are orthonormal on the support `{i | σᵢ ≠ 0}`. Deprecated +in favor of the unconditional `inner_svdLeft_svdLeft_full`. -/ +@[deprecated inner_svdLeft_svdLeft_full +typeChanged (since := "2026-05-10")] +theorem inner_svdLeft_svdLeft (i j : Fin (finrank 𝕜 E)) + (_hi : T.singularValues i.val ≠ 0) (hj : T.singularValues j.val ≠ 0) : + ⟪T.svdLeft i, T.svdLeft j⟫_𝕜 = if i = j then 1 else 0 := by + rw [T.inner_svdLeft_svdLeft_full i j] + by_cases hij : i = j + · simp [hij, hj] + · simp [hij] + +/-- **Singular value decomposition (vector form)**: any linear map `T : E →ₗ[𝕜] F` +between finite-dimensional inner product spaces admits a factorization +`T x = ∑ σᵢ • ⟨uᵢ, x⟩ • vᵢ` where the `uᵢ` are an orthonormal eigenbasis of +`T† ∘ T` (the right singular vectors) and the `vᵢ = σᵢ⁻¹ • T uᵢ` are orthonormal +on the support `{i | σᵢ ≠ 0}` (the left singular vectors). -/ +theorem svd_apply (x : E) : T x = + ∑ i, (T.singularValues i.val : 𝕜) • ⟪T.svdRight i, x⟫_𝕜 • T.svdLeft i := by + conv_lhs => rw [← T.svdRight.sum_repr' x] + rw [map_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [map_smul, T.apply_svdRight i, smul_smul, smul_smul, mul_comm] + +/-- The largest singular value equals the operator norm: +`‖T.toContinuousLinearMap‖ = T.singularValues 0`. Proof: chain `‖T‖² = ‖T† ∘ T‖` +(the C*-property, `norm_adjoint_comp_self`) with the spectral identity +`‖T†T‖ = (T†T).eigenvalues 0` (positive self-adjoint norm = top eigenvalue, +`IsPositive.norm_eq_eigenvalues_zero`) and `(T†T).eigenvalues 0 = T.singularValues 0 ^ 2` +(`sq_singularValues_fin`). For trivial domain `E`, both sides are `0`. -/ +theorem opNorm_eq_singularValues_zero : ‖T.toContinuousLinearMap‖ = T.singularValues 0 := by + by_cases h : Nontrivial E + · have : CompleteSpace E := FiniteDimensional.completeSpace 𝕜 E + have : CompleteSpace F := FiniteDimensional.completeSpace 𝕜 F + -- ‖T‖² = (singularValues 0)² via C*-property + spectral radius + sq_singularValues_fin. + have hadj : (T.adjoint ∘ₗ T).toContinuousLinearMap = + T.toContinuousLinearMap.adjoint.comp T.toContinuousLinearMap := by + ext x; simp [← LinearMap.adjoint_toContinuousLinearMap] + have heq : ‖T.toContinuousLinearMap‖ ^ 2 = T.singularValues 0 ^ 2 := by + rw [sq, ← T.toContinuousLinearMap.norm_adjoint_comp_self, ← hadj, + T.isPositive_adjoint_comp_self.norm_eq_eigenvalues_zero, + ← T.sq_singularValues_fin rfl ⟨0, Module.finrank_pos⟩] + have := congr_arg Real.sqrt heq + rwa [Real.sqrt_sq (norm_nonneg _), Real.sqrt_sq (T.singularValues_nonneg 0)] at this + · -- Subsingleton E: T = 0 and singularValues 0 = 0. + have : Subsingleton E := not_nontrivial_iff_subsingleton.mp h + rw [T.singularValues_of_subsingleton, Subsingleton.elim T 0] + simp + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + (T : E →L[𝕜] F) + +/-! ## CLM-level singular value decomposition + +CLM siblings of the LM SVD API (above). Each definition delegates to the underlying LM +form with a separate rfl-bridge `_toLinearMap` lemma. The `svd_apply` theorem at CLM level +lets consumers apply the SVD to a CLM `T : E →L[𝕜] F` directly, without inserting +`.toLinearMap` (or a `change` bridge) at every call site. Matches Mathlib's +`ContinuousLinearMap.adjoint`-vs-`LinearMap.adjoint` convention. -/ + +/-- The singular values of a CLM, as a finitely supported function `ℕ →₀ ℝ`. +Delegates to `LinearMap.singularValues` via `toLinearMap`. -/ +noncomputable def singularValues : ℕ →₀ ℝ := T.toLinearMap.singularValues + +theorem singularValues_toLinearMap : + T.singularValues = T.toLinearMap.singularValues := rfl + +/-- The right singular vectors of a CLM, as an orthonormal basis. +Delegates to `LinearMap.svdRight` via `toLinearMap`. -/ +noncomputable def svdRight : OrthonormalBasis (Fin (Module.finrank 𝕜 E)) 𝕜 E := + T.toLinearMap.svdRight + +theorem svdRight_toLinearMap : + T.svdRight = T.toLinearMap.svdRight := rfl + +/-- The left singular vectors of a CLM, as a finite family of vectors in the codomain. +Delegates to `LinearMap.svdLeft` via `toLinearMap`. -/ +noncomputable def svdLeft (i : Fin (Module.finrank 𝕜 E)) : F := + T.toLinearMap.svdLeft i + +theorem svdLeft_toLinearMap (i : Fin (Module.finrank 𝕜 E)) : + T.svdLeft i = T.toLinearMap.svdLeft i := rfl + +theorem singularValues_nonneg (i : ℕ) : 0 ≤ T.singularValues i := + T.toLinearMap.singularValues_nonneg i + +theorem apply_svdRight (i : Fin (Module.finrank 𝕜 E)) : + T (T.svdRight i) = (T.singularValues i.val : 𝕜) • T.svdLeft i := + T.toLinearMap.apply_svdRight i + +theorem norm_svdLeft_le_one (i : Fin (Module.finrank 𝕜 E)) : ‖T.svdLeft i‖ ≤ 1 := + T.toLinearMap.norm_svdLeft_le_one i + +/-- **Singular value decomposition (vector form), CLM level**: +`T x = ∑ i, σᵢ • ⟨svdRight i, x⟩ • svdLeft i`. The CLM-application form of +`LinearMap.svd_apply`. -/ +theorem svd_apply (x : E) : T x = + ∑ i, (T.singularValues i.val : 𝕜) • inner 𝕜 (T.svdRight i) x • T.svdLeft i := + T.toLinearMap.svd_apply x + +/-- CLM-level apply-form for `T.adjoint ∘L T` on the right singular vectors: +`(T.adjoint ∘L T) (svdRight i) = σᵢ² • svdRight i`. The right singular vectors are eigenvectors +of `T.adjoint ∘L T` with eigenvalue `σᵢ²`. Routes through +`LinearMap.IsSymmetric.apply_eigenvectorBasis` (LM-level) via the `adjoint_toLinearMap` bridge. -/ +theorem adjoint_comp_self_apply_svdRight [CompleteSpace E] [CompleteSpace F] (T : E →L[𝕜] F) + (i : Fin (finrank 𝕜 E)) : + (T.adjoint ∘L T) (T.toLinearMap.svdRight i) = + ((T.toLinearMap.singularValues i.val) ^ 2 : 𝕜) • T.toLinearMap.svdRight i := by + have hsym := T.toLinearMap.isSymmetric_adjoint_comp_self + have hcomp : (T.adjoint ∘L T) (T.toLinearMap.svdRight i) = + (T.adjoint.toLinearMap ∘ₗ T.toLinearMap) (T.toLinearMap.svdRight i) := by + simp [ContinuousLinearMap.comp_apply] + rw [hcomp, ← T.adjoint_toLinearMap, LinearMap.svdRight_apply, + hsym.apply_eigenvectorBasis rfl, ← T.toLinearMap.sq_singularValues_fin rfl] + push_cast + rfl + +/-- **Singular values are invariant under conjugation by a linear isometry equivalence.** +For `e : E ≃ₗᵢ[𝕜] F` and `T : E →L[𝕜] E`, the singular values of the conjugated operator +`e.conjStarAlgEquiv T : F →L[𝕜] F` agree pointwise with those of `T`. Routes through the +CLM-level adjoint–product identity (using the star-algebra structure of `conjStarAlgEquiv`) ++ `LinearEquiv.charpoly_conj` + `IsSymmetric.eigenvalues_eq_eigenvalues_iff`. -/ +theorem singularValues_conjStarAlgEquiv [CompleteSpace E] [CompleteSpace F] + (e : E ≃ₗᵢ[𝕜] F) (T : E →L[𝕜] E) : + (e.conjStarAlgEquiv T).toLinearMap.singularValues = T.toLinearMap.singularValues := by + set T' := (e.conjStarAlgEquiv T).toLinearMap + set TL := T.toLinearMap + have hfinrank : Module.finrank 𝕜 E = Module.finrank 𝕜 F := e.toLinearEquiv.finrank_eq + -- CLM-level: adjoint and product preserved by the star-algebra equiv + have h_conj_self_CLM : + (e.conjStarAlgEquiv T).adjoint ∘L e.conjStarAlgEquiv T = + e.conjStarAlgEquiv (T.adjoint ∘L T) := by + have h_adj : (e.conjStarAlgEquiv T).adjoint = e.conjStarAlgEquiv T.adjoint := by + rw [← ContinuousLinearMap.star_eq_adjoint, + ← ContinuousLinearMap.star_eq_adjoint, map_star] + rw [h_adj, ← ContinuousLinearMap.mul_def, ← ContinuousLinearMap.mul_def, ← map_mul] + -- LM lift: T'.adjoint ∘ T' = e.conj (TL.adjoint ∘ TL) + have h_conj_self : T'.adjoint ∘ₗ T' = e.toLinearEquiv.conj (TL.adjoint ∘ₗ TL) := by + have h := congrArg ContinuousLinearMap.toLinearMap h_conj_self_CLM + simp only [ContinuousLinearMap.toLinearMap_comp] at h + exact h + -- Charpoly equality via LinearEquiv.charpoly_conj + have h_charpoly : (T'.adjoint ∘ₗ T').charpoly = (TL.adjoint ∘ₗ TL).charpoly := by + rw [h_conj_self]; exact e.toLinearEquiv.charpoly_conj _ + -- Eigenvalues function-level equality at the shared `n := finrank F` + have h_eig : T'.isSymmetric_adjoint_comp_self.eigenvalues rfl = + TL.isSymmetric_adjoint_comp_self.eigenvalues hfinrank := + (LinearMap.IsSymmetric.eigenvalues_eq_eigenvalues_iff _ _ _ _).mpr h_charpoly + -- Pointwise singular values + ext i + by_cases hi : i < Module.finrank 𝕜 F + · rw [LinearMap.singularValues_of_lt _ rfl hi, + LinearMap.singularValues_of_lt _ hfinrank hi] + exact congrArg Real.sqrt (congrFun h_eig ⟨i, hi⟩) + · rw [LinearMap.singularValues_of_finrank_le _ (Nat.le_of_not_lt hi), + LinearMap.singularValues_of_finrank_le _ (hfinrank ▸ Nat.le_of_not_lt hi)] + +/-- **Singular values are invariant under adjoint, CLM level**: +`T†.singularValues = T.singularValues`. The `ContinuousLinearMap` companion of +`LinearMap.singularValues_adjoint`, routed through it via the `_toLinearMap` / +`adjoint_toLinearMap` bridges. -/ +theorem singularValues_adjoint [CompleteSpace E] [CompleteSpace F] : + (ContinuousLinearMap.adjoint T).singularValues = T.singularValues := by + rw [ContinuousLinearMap.singularValues_toLinearMap, ← ContinuousLinearMap.adjoint_toLinearMap, + LinearMap.singularValues_adjoint, ← ContinuousLinearMap.singularValues_toLinearMap] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Spectrum.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Spectrum.lean new file mode 100644 index 0000000000..12c350398a --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Spectrum.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 + +/-! +# Spectral expansion and eigenvalue recognition for self-adjoint operators + +`IsSelfAdjoint.spectral_sum` (and its vector-form companion `IsSelfAdjoint.spectral_sum_apply`) +expresses `T : E →L[𝕜] E` as the sum of its eigenvalues weighted by rank-one operators on the +(orthonormal) eigenvectors, the operator-level counterpart of `Matrix.IsHermitian.spectral_sum`. +The LinearMap-side companion is `LinearMap.IsSymmetric.spectral_sum_apply`. + +Also included: the eigenvalue recognition theorem `eigenvalues_multiset_map_eq_of_eigenbasis`, +its supporting lemma `antitone_eq_of_multiset_map_eq`, and the fact that eigenvalues of a +symmetric idempotent linear map (an orthogonal projection) are `0` or `1`. +-/ + +@[expose] public section + +variable {𝕜 : Type*} [RCLike 𝕜] +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + +local notation "⟪" x ", " y "⟫" => inner 𝕜 x y + +namespace LinearMap + +namespace IsSymmetric + +variable {T : E →ₗ[𝕜] E} + +variable [FiniteDimensional 𝕜 E] + +section Version2 + +variable {n : ℕ} + +/-- For a symmetric `T`, the Gram operator `T† ∘ T` acts on `T`'s eigenbasis by scaling each +basis vector by the square of the corresponding eigenvalue. Companion to +`IsSymmetric.apply_eigenvectorBasis`; foundational for SVD relations and trace-norm formulas +involving `T† ∘ T`. -/ +theorem adjoint_comp_self_apply_eigenvectorBasis (hT : T.IsSymmetric) + (hn : Module.finrank 𝕜 E = n) (i : Fin n) : + (T.adjoint ∘ₗ T) (hT.eigenvectorBasis hn i) = + ((hT.eigenvalues hn i) ^ 2 : 𝕜) • hT.eigenvectorBasis hn i := by + rw [LinearMap.comp_apply, hT.adjoint_eq, hT.apply_eigenvectorBasis, + LinearMap.map_smul, hT.apply_eigenvectorBasis, smul_smul] + ring_nf + +/-- *Spectral expansion, vector form*: applying a self-adjoint operator on a finite-dimensional +inner product space to a vector yields the sum of the eigenvalues weighted by the inner-product +coefficients along the eigenvectors. The operator-level companion is +`IsSelfAdjoint.spectral_sum`. -/ +theorem spectral_sum_apply (hT : T.IsSymmetric) (hn : Module.finrank 𝕜 E = n) (v : E) : + T v = ∑ i, (hT.eigenvalues hn i : 𝕜) • ⟪hT.eigenvectorBasis hn i, v⟫ • + hT.eigenvectorBasis hn i := by + conv_lhs => rw [← (hT.eigenvectorBasis hn).sum_repr' v] + simp_rw [map_sum, map_smul, hT.apply_eigenvectorBasis hn, smul_smul, mul_comm] + +open Polynomial in +/-- **Eigenvalue recognition theorem**: if a symmetric operator `T` admits an eigenbasis with +real eigenvalues `μ`, then the multiset of those eigenvalues equals the multiset of `T`'s +canonical eigenvalues. The eigenbasis can be indexed by any `Fintype`. -/ +theorem eigenvalues_multiset_map_eq_of_eigenbasis (hT : T.IsSymmetric) + (hn : Module.finrank 𝕜 E = n) + {ι : Type*} [Fintype ι] (b : Module.Basis ι 𝕜 E) {μ : ι → ℝ} + (heigen : ∀ i, T (b i) = (μ i : 𝕜) • b i) : + Multiset.map μ Finset.univ.val = Multiset.map (hT.eigenvalues hn) Finset.univ.val := by + classical + have hmat : LinearMap.toMatrix b b T = Matrix.diagonal (fun i => (μ i : 𝕜)) := by + ext i j + simp [LinearMap.toMatrix_apply, heigen, Matrix.diagonal_apply, Module.Basis.repr_self, + Finsupp.single_apply, eq_comm, RCLike.real_smul_eq_coe_mul] + grind + have hcharpoly : T.charpoly = ∏ i, (X - C ((μ i : 𝕜))) := by + rw [← T.charpoly_toMatrix b, hmat, Matrix.charpoly_diagonal] + have hroots : T.charpoly.roots = + Multiset.map ((RCLike.ofReal : ℝ → 𝕜) ∘ μ) Finset.univ.val := by + rw [hcharpoly, + Polynomial.roots_prod _ _ (by simp [Finset.prod_ne_zero_iff, X_sub_C_ne_zero])] + simp + have hcast := hroots.symm.trans (hT.roots_charpoly_eq_eigenvalues hn) + rw [← Multiset.map_map, ← Multiset.map_map] at hcast + exact Multiset.map_injective RCLike.ofReal_injective hcast + +end Version2 + +end IsSymmetric + +end LinearMap + +/-- If two functions `Fin n → α` (with `α` a linear order) have equal multisets of values and are +both antitone (sorted nonincreasingly via `List.ofFn`), they agree pointwise. The multiset → +permutation → sorted-list-equality chain promotes multiset equality to pointwise equality. -/ +theorem antitone_eq_of_multiset_map_eq {n : ℕ} {α : Type*} [LinearOrder α] + {f g : Fin n → α} (hf : Antitone f) (hg : Antitone g) + (h : Multiset.map f Finset.univ.val = Multiset.map g Finset.univ.val) : + f = g := by + have hperm : (List.ofFn f).Perm (List.ofFn g) := by + rw [← Multiset.coe_eq_coe, ← Fin.univ_val_map, ← Fin.univ_val_map] + exact h + exact List.ofFn_inj.mp + (List.Perm.eq_of_sortedGE hf.sortedGE_ofFn hg.sortedGE_ofFn hperm) + +section IdempotentEigenvalues + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +/-- The eigenvalues of a symmetric idempotent linear map (an orthogonal projection) +square to themselves: `λᵢ² = λᵢ`. See also `IsIdempotentElem.spectrum_subset` for the +abstract-spectrum sibling (`spectrum 𝕜 a ⊆ {0, 1}`) in +`Mathlib/FieldTheory/IsAlgClosed/Spectrum.lean`. -/ +theorem IsIdempotentElem.eigenvalues_sq_eq_self {T : E →ₗ[𝕜] E} + (hT : T.IsSymmetric) (hidem : IsIdempotentElem T) {n : ℕ} + (hn : Module.finrank 𝕜 E = n) (i : Fin n) : + hT.eigenvalues hn i ^ 2 = hT.eigenvalues hn i := by + set b := hT.eigenvectorBasis hn + have hTb : T (b i) = (hT.eigenvalues hn i : 𝕜) • b i := hT.apply_eigenvectorBasis hn i + have h_lhs : T (T (b i)) = (hT.eigenvalues hn i : 𝕜) ^ 2 • b i := by + rw [hTb, map_smul, hTb, smul_smul, sq] + have hidem' : T (T (b i)) = T (b i) := congr_arg (· (b i)) hidem + rw [h_lhs, hTb] at hidem' + have h_scalar : ((hT.eigenvalues hn i : 𝕜) ^ 2 : 𝕜) = (hT.eigenvalues hn i : 𝕜) := + smul_left_injective 𝕜 (b.ne_zero i) hidem' + exact_mod_cast h_scalar + +/-- Each eigenvalue of a symmetric idempotent linear map (an orthogonal projection) is +either `0` or `1`. See also `IsIdempotentElem.spectrum_subset` for the abstract-spectrum +sibling (`spectrum 𝕜 a ⊆ {0, 1}`) in `Mathlib/FieldTheory/IsAlgClosed/Spectrum.lean`. -/ +theorem IsIdempotentElem.eigenvalues_zero_or_one {T : E →ₗ[𝕜] E} + (hT : T.IsSymmetric) (hidem : IsIdempotentElem T) {n : ℕ} + (hn : Module.finrank 𝕜 E = n) (i : Fin n) : + hT.eigenvalues hn i = 0 ∨ hT.eigenvalues hn i = 1 := by + have h := hidem.eigenvalues_sq_eq_self hT hn i + have hfact : hT.eigenvalues hn i * (hT.eigenvalues hn i - 1) = 0 := by nlinarith [h] + rcases mul_eq_zero.mp hfact with h0 | h1 + · exact Or.inl h0 + · exact Or.inr (by linarith) + +end IdempotentEigenvalues + +namespace IsSelfAdjoint + +variable [CompleteSpace E] [FiniteDimensional 𝕜 E] {T : E →L[𝕜] E} {n : ℕ} + +/-- *Spectral expansion, vector form*: applying a self-adjoint continuous linear map on a +finite-dimensional inner product space to a vector yields the sum of the eigenvalues weighted by +the inner-product coefficients along the eigenvectors. -/ +theorem spectral_sum_apply (hT : IsSelfAdjoint T) (hn : Module.finrank 𝕜 E = n) (v : E) : + T v = ∑ i, (hT.isSymmetric.eigenvalues hn i : 𝕜) • + ⟪hT.isSymmetric.eigenvectorBasis hn i, v⟫ • hT.isSymmetric.eigenvectorBasis hn i := + hT.isSymmetric.spectral_sum_apply hn v + +/-- *Spectral expansion, operator form*: a self-adjoint continuous linear map on a +finite-dimensional inner product space equals the sum of its eigenvalues weighted by the rank-one +operators along the (orthonormal) eigenvectors. The companion matrix-level lemma is +`Matrix.IsHermitian.spectral_sum`. -/ +theorem spectral_sum (hT : IsSelfAdjoint T) (hn : Module.finrank 𝕜 E = n) : + T = ∑ i, (hT.isSymmetric.eigenvalues hn i : 𝕜) • + InnerProductSpace.rankOne 𝕜 (hT.isSymmetric.eigenvectorBasis hn i) + (hT.isSymmetric.eigenvectorBasis hn i) := by + ext v + rw [hT.spectral_sum_apply hn v] + simp [InnerProductSpace.rankOne_apply] + +end IsSelfAdjoint diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorPower.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorPower.lean new file mode 100644 index 0000000000..68f438b3c0 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorPower.lean @@ -0,0 +1,195 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiTensorProduct +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Trace +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.TensorPower.Endomorphism +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Trace + +/-! + +# Tensor power and binary tensor map of endomorphisms on inner product spaces + +For `A : E →ₗ[𝕜] E` an endomorphism of a finite-dimensional inner product space, this +file establishes the eigenvalue/positivity structure of n-fold tensor powers and binary +tensor maps. + +## n-fold tensor power: + +* `LinearMap.tensorPow_adjoint`: `(A ^⊗ n)† = (A†) ^⊗ n` — the adjoint of an n-fold tensor + power is the n-fold tensor power of the adjoint. +* `IsSelfAdjoint.tensorPow`: `IsSelfAdjoint A → IsSelfAdjoint (A ^⊗ n)`. +* `LinearMap.IsSymmetric.tensorPow`: the LinearMap-level symmetric counterpart. +* `LinearMap.trace_tensorPow`: `trace (A ^⊗ n) = (trace A) ^ n`. +* `LinearMap.IsSymmetric.tensorPow_eigenvalues_multiset_eq`: the multiset of eigenvalues + of `A ^⊗ n` equals the multiset of products `∏ i, A.eigenvalues hd (κ i)` over + `κ : Fin n → Fin d`. +* `LinearMap.IsPositive.tensorPow`: an n-fold tensor power preserves positivity. + +## Binary tensor map (`TensorProduct.map A B`): + +* `LinearMap.IsSymmetric.tensorMap_eigenvalues_multiset_eq`: the multiset of eigenvalues of + `TensorProduct.map A B` equals the multiset of products `μA i * μB j`. +* `LinearMap.IsPositive.tensorMap`: a binary tensor map preserves positivity. + +-/ + +@[expose] public section + +open scoped TensorProduct +open Module + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +namespace PiTensorProduct + +/-- The n-fold tensor power of a finite-dimensional space is finite-dimensional. -/ +instance instFiniteDimensional_tensorPow (n : ℕ) : + FiniteDimensional 𝕜 ((⨂[𝕜]^n) E) := + Module.Finite.of_basis (Basis.piTensorProduct fun _ : Fin n ↦ Module.finBasis 𝕜 E) + +end PiTensorProduct + +namespace LinearMap + +/-- The adjoint of the n-fold tensor power of `A` is the n-fold tensor power of the +adjoint of `A`. -/ +theorem tensorPow_adjoint (A : E →ₗ[𝕜] E) (n : ℕ) : + (A ^⊗ n).adjoint = A.adjoint ^⊗ n := by + rw [eq_comm, LinearMap.eq_adjoint_iff] + intro x y + induction x using PiTensorProduct.induction_on with + | smul_tprod r a => + induction y using PiTensorProduct.induction_on with + | smul_tprod r' b => + simp only [tensorPow_apply_tprod, map_smul, inner_smul_left, inner_smul_right, + PiTensorProduct.inner_tprod_tprod] + simp_rw [LinearMap.adjoint_inner_left] + | add u v hu hv => + simp only [map_add, inner_add_right, hu, hv] + | add u v hu hv => + simp only [map_add, inner_add_left, hu, hv] + +/-- An n-fold tensor power preserves the symmetry of a `LinearMap`: if `A.IsSymmetric`, +so is `A ^⊗ n`. -/ +theorem IsSymmetric.tensorPow {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) (n : ℕ) : + (A ^⊗ n).IsSymmetric := by + rw [LinearMap.isSymmetric_iff_isSelfAdjoint] at hA ⊢ + rw [LinearMap.isSelfAdjoint_iff'] at hA ⊢ + rw [LinearMap.tensorPow_adjoint, hA] + +end LinearMap + +namespace IsSelfAdjoint + +/-- An n-fold tensor power preserves self-adjointness: if `A` is self-adjoint, so is +`A ^⊗ n`. -/ +theorem tensorPow {A : E →ₗ[𝕜] E} (hA : IsSelfAdjoint A) (n : ℕ) : + IsSelfAdjoint (A ^⊗ n) := by + rw [LinearMap.isSelfAdjoint_iff'] at hA ⊢ + rw [LinearMap.tensorPow_adjoint, hA] + +end IsSelfAdjoint + +namespace LinearMap + +/-- The trace of the n-fold tensor power of `A` is the n-th power of the trace of `A`. -/ +theorem trace_tensorPow (A : E →ₗ[𝕜] E) (n : ℕ) : + LinearMap.trace 𝕜 _ (A ^⊗ n) = (LinearMap.trace 𝕜 _ A) ^ n := by + classical + let b : Basis (Fin (finrank 𝕜 E)) 𝕜 E := Module.finBasis 𝕜 E + rw [LinearMap.trace_eq_matrix_trace 𝕜 (Basis.piTensorProduct (fun _ : Fin n ↦ b)), + Matrix.trace_apply, LinearMap.trace_eq_matrix_trace 𝕜 b, Matrix.trace_apply] + simp only [Matrix.diag_apply, LinearMap.toMatrix_apply, Basis.piTensorProduct_apply, + tensorPow_apply_tprod, Basis.piTensorProduct_repr_tprod_apply] + rw [Finset.sum_pow', Fintype.piFinset_univ] + +/-- **Eigenvalues of an n-fold tensor power**: the multiset of eigenvalues of `A ^⊗ n` +(for symmetric `A`) equals the multiset of products `∏ i, A.eigenvalues hd (κ i)` over +`κ : Fin n → Fin d`, where `d = finrank 𝕜 E`. -/ +theorem IsSymmetric.tensorPow_eigenvalues_multiset_eq + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) {d N : ℕ} (n : ℕ) + (hd : finrank 𝕜 E = d) (hN : finrank 𝕜 ((⨂[𝕜]^n) E) = N) : + Multiset.map (fun κ : Fin n → Fin d ↦ ∏ i, hA.eigenvalues hd (κ i)) Finset.univ.val = + Multiset.map ((hA.tensorPow n).eigenvalues hN) Finset.univ.val := by + classical + let b : Basis (Fin n → Fin d) 𝕜 ((⨂[𝕜]^n) E) := + Basis.piTensorProduct (fun _ : Fin n ↦ (hA.eigenvectorBasis hd).toBasis) + refine (hA.tensorPow n).eigenvalues_multiset_map_eq_of_eigenbasis hN b (μ := _) (fun κ ↦ ?_) + simp only [b, Basis.piTensorProduct_apply, OrthonormalBasis.coe_toBasis, + tensorPow_apply_tprod, hA.apply_eigenvectorBasis, + MultilinearMap.map_smul_univ (PiTensorProduct.tprod 𝕜), RCLike.ofReal_prod, RingHom.id_apply] + +/-- An n-fold tensor power preserves positivity: if `A.IsPositive`, so is `A ^⊗ n`. -/ +theorem IsPositive.tensorPow {A : E →ₗ[𝕜] E} (hA : A.IsPositive) (n : ℕ) : + (A ^⊗ n).IsPositive := by + refine (hA.isSymmetric.tensorPow n).isPositive_of_eigenvalues_nonneg rfl fun j ↦ ?_ + have hmem := Multiset.mem_map_of_mem + ((hA.isSymmetric.tensorPow n).eigenvalues rfl) (Finset.mem_univ_val j) + rw [← hA.isSymmetric.tensorPow_eigenvalues_multiset_eq n rfl rfl] at hmem + obtain ⟨κ, _, hκ⟩ := Multiset.mem_map.mp hmem + exact hκ ▸ Finset.prod_nonneg fun i _ ↦ hA.nonneg_eigenvalues rfl (κ i) + +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- **Joint-eigenvector identity for `TensorProduct.map`**: on the pure tensor +`hA.eigenvectorBasis i ⊗ₜ hB.eigenvectorBasis j`, the operator `TensorProduct.map A B` +acts as scalar multiplication by `μA i * μB j`. -/ +theorem IsSymmetric.tensorMap_apply_eigenvectorBasis_smul + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) {B : F →ₗ[𝕜] F} (hB : B.IsSymmetric) + {dE dF : ℕ} (hdE : finrank 𝕜 E = dE) (hdF : finrank 𝕜 F = dF) (i : Fin dE) (j : Fin dF) : + TensorProduct.map A B (hA.eigenvectorBasis hdE i ⊗ₜ[𝕜] hB.eigenvectorBasis hdF j) = + ((hA.eigenvalues hdE i * hB.eigenvalues hdF j : ℝ) : 𝕜) • + (hA.eigenvectorBasis hdE i ⊗ₜ[𝕜] hB.eigenvectorBasis hdF j) := by + rw [TensorProduct.map_tmul, hA.apply_eigenvectorBasis, hB.apply_eigenvectorBasis, + ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, ← mul_smul] + push_cast + ring_nf + +/-- **Eigenvalues of a binary tensor product map**: the multiset of eigenvalues of +`TensorProduct.map A B` (for symmetric `A, B`) equals the multiset of products +`μA i * μB j` over `(i, j) : Fin dE × Fin dF`. Binary analog of +`LinearMap.IsSymmetric.tensorPow_eigenvalues_multiset_eq`. -/ +theorem IsSymmetric.tensorMap_eigenvalues_multiset_eq + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) {B : F →ₗ[𝕜] F} (hB : B.IsSymmetric) + {dE dF N : ℕ} + (hdE : finrank 𝕜 E = dE) (hdF : finrank 𝕜 F = dF) + (hN : finrank 𝕜 (E ⊗[𝕜] F) = N) : + Multiset.map (fun ij : Fin dE × Fin dF ↦ hA.eigenvalues hdE ij.1 * hB.eigenvalues hdF ij.2) + Finset.univ.val = + Multiset.map ((LinearMap.IsSymmetric.tensorMap hA hB).eigenvalues hN) Finset.univ.val := by + classical + let b : Basis (Fin dE × Fin dF) 𝕜 (E ⊗[𝕜] F) := + (hA.eigenvectorBasis hdE).toBasis.tensorProduct (hB.eigenvectorBasis hdF).toBasis + refine (LinearMap.IsSymmetric.tensorMap hA hB).eigenvalues_multiset_map_eq_of_eigenbasis + hN b (μ := _) (fun ⟨i, j⟩ ↦ ?_) + simp only [b, Basis.tensorProduct_apply, OrthonormalBasis.coe_toBasis] + exact LinearMap.IsSymmetric.tensorMap_apply_eigenvectorBasis_smul hA hB hdE hdF i j + +/-- A binary tensor product map has strictly positive eigenvalues if both factors do. The +multiset identity supplies the joint-eigenvalue structure. -/ +theorem IsSymmetric.tensorMap_eigenvalues_pos + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) {B : F →ₗ[𝕜] F} (hB : B.IsSymmetric) + {dE dF N : ℕ} + (hdE : finrank 𝕜 E = dE) (hdF : finrank 𝕜 F = dF) + (hN : finrank 𝕜 (E ⊗[𝕜] F) = N) + (hA_pos : ∀ i, 0 < hA.eigenvalues hdE i) (hB_pos : ∀ j, 0 < hB.eigenvalues hdF j) + (k : Fin N) : 0 < (LinearMap.IsSymmetric.tensorMap hA hB).eigenvalues hN k := by + have hmem := Multiset.mem_map_of_mem + ((LinearMap.IsSymmetric.tensorMap hA hB).eigenvalues hN) (Finset.mem_univ_val k) + rw [← LinearMap.IsSymmetric.tensorMap_eigenvalues_multiset_eq hA hB hdE hdF hN] at hmem + obtain ⟨⟨i, j⟩, _, hij⟩ := Multiset.mem_map.mp hmem + exact hij ▸ mul_pos (hA_pos i) (hB_pos j) + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProduct.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProduct.lean new file mode 100644 index 0000000000..53907cd117 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProduct.lean @@ -0,0 +1,339 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Additional API for inner product space tensor products + +* `LinearMap.IsSymmetric.tensorMap`: the tensor product of symmetric linear maps is symmetric. +* `IsSelfAdjoint.tensorMap`: the tensor product of self-adjoint linear maps is self-adjoint. +* `TensorProduct.mapL`: the continuous linear map version of `TensorProduct.map` for finite-dim + inner product spaces, together with its algebraic API (linearity, composition, adjoint, + unitarity, Lie-bracket compatibility, joint continuity, etc). +* `TensorProduct.instCompleteSpace`: the tensor product of two finite-dimensional inner product + spaces is complete. +* `TensorProduct.contractFst`: the partial inner product on the first tensor factor. +-/ + +@[expose] public section + +variable {𝕜 E F G H : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] + [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] + +open scoped TensorProduct + +namespace TensorProduct + +/-- The tensor product of two finite-dimensional inner product spaces is itself a complete +inner product space. Cannot be derived via `FiniteDimensional.completeSpace` as a global instance +because the latter has an ambiguous `𝕜` parameter; the type `E ⊗[𝕜] F` recovers `𝕜` +unambiguously for this specialization. -/ +instance instCompleteSpace [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] : + CompleteSpace (E ⊗[𝕜] F) := FiniteDimensional.completeSpace 𝕜 _ + +section isometry + +@[simp] lemma congrIsometry_tmul (f : E ≃ₗᵢ[𝕜] G) (g : F ≃ₗᵢ[𝕜] H) (a : E) (b : F) : + congrIsometry f g (a ⊗ₜ[𝕜] b) = f a ⊗ₜ[𝕜] g b := rfl + +end isometry + +open LinearMap + +/-- The tensor product of two symmetric linear maps is symmetric. -/ +theorem _root_.LinearMap.IsSymmetric.tensorMap [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) {B : F →ₗ[𝕜] F} (hB : B.IsSymmetric) : + (TensorProduct.map A B).IsSymmetric := by + rw [LinearMap.isSymmetric_iff_isSelfAdjoint] at hA hB ⊢ + rw [LinearMap.isSelfAdjoint_iff'] at hA hB ⊢ + rw [TensorProduct.adjoint_map, hA, hB] + +/-- The tensor product of two self-adjoint linear maps is self-adjoint. -/ +theorem _root_.IsSelfAdjoint.tensorMap [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + {A : E →ₗ[𝕜] E} (hA : IsSelfAdjoint A) {B : F →ₗ[𝕜] F} (hB : IsSelfAdjoint B) : + IsSelfAdjoint (TensorProduct.map A B) := by + rw [LinearMap.isSelfAdjoint_iff'] at hA hB ⊢ + rw [TensorProduct.adjoint_map, hA, hB] + +-- `TensorProduct.mapL`, `TensorProduct.mapL_apply`, and `TensorProduct.mapL_tmul` now exist +-- upstream in `Mathlib.Analysis.InnerProductSpace.TensorProduct` (more general: they do not +-- require `FiniteDimensional` hypotheses, only continuity of `f`/`g`). Use the upstream +-- declarations directly. + +/-- The rank-one operator of two pure tensors factorizes through `mapL`: +`|a₁ ⊗ₜ b₁⟩⟨a₂ ⊗ₜ b₂| = mapL |a₁⟩⟨a₂| |b₁⟩⟨b₂|`. Checked on generators `x ⊗ₜ y` via `rankOne_apply` +and `inner_tmul`. The non-self generalization of `InnerProductSpace.rankOne_tmul_self`. -/ +theorem _root_.InnerProductSpace.rankOne_tmul_tmul + (a₁ a₂ : E) (b₁ b₂ : F) : + (InnerProductSpace.rankOne 𝕜 (a₁ ⊗ₜ[𝕜] b₁) (a₂ ⊗ₜ[𝕜] b₂) : (E ⊗[𝕜] F) →L[𝕜] (E ⊗[𝕜] F)) + = mapL (InnerProductSpace.rankOne 𝕜 a₁ a₂) (InnerProductSpace.rankOne 𝕜 b₁ b₂) := by + apply ContinuousLinearMap.coe_injective + apply TensorProduct.ext' + intro x y + simp only [ContinuousLinearMap.coe_coe, mapL_apply, InnerProductSpace.rankOne_apply, + inner_tmul, TensorProduct.map_tmul, TensorProduct.smul_tmul', TensorProduct.tmul_smul, + mul_smul] + rw [smul_comm] + +/-- The rank-one operator of a pure tensor factorizes through `mapL`: +`|u ⊗ₜ v⟩⟨u ⊗ₜ v| = mapL |u⟩⟨u| |v⟩⟨v|`. The self case of +`InnerProductSpace.rankOne_tmul_tmul`. -/ +theorem _root_.InnerProductSpace.rankOne_tmul_self + (u : E) (v : F) : + (InnerProductSpace.rankOne 𝕜 (u ⊗ₜ[𝕜] v) (u ⊗ₜ[𝕜] v) : (E ⊗[𝕜] F) →L[𝕜] (E ⊗[𝕜] F)) + = mapL (InnerProductSpace.rankOne 𝕜 u u) (InnerProductSpace.rankOne 𝕜 v v) := + InnerProductSpace.rankOne_tmul_tmul u u v v + +/-- **Partial inner product on the first tensor factor.** For `v : E`, the linear map +`E ⊗[𝕜] F →ₗ[𝕜] F` sending `x ⊗ₜ y ↦ ⟪v, x⟫ • y` — contract the left factor of a tensor against +`v`. Built as `TensorProduct.lid ∘ (innerSL 𝕜 v).rTensor`; `contractFst_tmul` gives its action on +a pure tensor. -/ +noncomputable def contractFst (v : E) : E ⊗[𝕜] F →ₗ[𝕜] F := + (TensorProduct.lid 𝕜 F).toLinearMap ∘ₗ LinearMap.rTensor F (innerSL 𝕜 v).toLinearMap + +@[simp] +theorem contractFst_tmul (v x : E) (y : F) : + contractFst v (x ⊗ₜ[𝕜] y) = (inner 𝕜 v x : 𝕜) • y := by + simp [contractFst, LinearMap.rTensor_tmul, TensorProduct.lid_tmul] + +-- `TensorProduct.mapL_mul` and `TensorProduct.mapL_comp` now exist upstream in +-- `Mathlib.Analysis.InnerProductSpace.TensorProduct` (more general: no `FiniteDimensional` +-- hypotheses needed). Use the upstream declarations directly. + +/-- `mapL` of identity operators is the identity. CLM-level lift of `TensorProduct.map_one`. -/ +@[simp] +theorem mapL_one : + mapL (1 : E →L[𝕜] E) (1 : F →L[𝕜] F) = 1 := by + ext x + simp [TensorProduct.map_one] + +/-- `mapL · 1` is multiplicative: `mapL (f₁ * f₂) 1 = mapL f₁ 1 * mapL f₂ 1`, i.e. the left +embedding `f ↦ f ⊗ 1` is a monoid homomorphism. Specialisation of `mapL_mul` at `g₁ = g₂ = 1`. -/ +theorem mapL_mul_one + (f₁ f₂ : E →L[𝕜] E) : + mapL (f₁ * f₂) (1 : F →L[𝕜] F) = mapL f₁ 1 * mapL f₂ 1 := by + simpa using mapL_mul f₁ f₂ (1 : F →L[𝕜] F) 1 + +-- `TensorProduct.mapL_adjoint` now exists upstream as `TensorProduct.adjoint_mapL` (more general: +-- no `FiniteDimensional` hypotheses needed). Use the upstream declaration directly. + +/-- The tensor product of two unitary operators is unitary: if `f` and `g` are unitary, +so is `mapL f g`. CLM-level lift combining `adjoint_mapL`, `mapL_mul`, and `mapL_one`. -/ +theorem mapL_mem_unitary [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + [CompleteSpace E] [CompleteSpace F] + {f : E →L[𝕜] E} {g : F →L[𝕜] F} + (hf : f ∈ unitary (E →L[𝕜] E)) (hg : g ∈ unitary (F →L[𝕜] F)) : + mapL f g ∈ unitary (E ⊗[𝕜] F →L[𝕜] E ⊗[𝕜] F) := by + rw [Unitary.mem_iff, ContinuousLinearMap.star_eq_adjoint] at hf hg ⊢ + rw [adjoint_mapL] + refine ⟨?_, ?_⟩ + · rw [← mapL_mul, hf.1, hg.1, mapL_one] + · rw [← mapL_mul, hf.2, hg.2, mapL_one] + +/-- The conjugate-square of a tensor-product map factors over the slots: +`(mapL f g)† ∘ mapL f g = mapL (f† ∘ f) (g† ∘ g)`. CLM-level lift combining `adjoint_mapL` and +`mapL_comp`; the building block for completeness of a tensor product of Kraus families. -/ +theorem mapL_adjoint_comp_self [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + [FiniteDimensional 𝕜 G] [FiniteDimensional 𝕜 H] [CompleteSpace E] [CompleteSpace F] + [CompleteSpace G] [CompleteSpace H] (f : E →L[𝕜] F) (g : G →L[𝕜] H) : + (mapL f g).adjoint ∘L mapL f g = mapL (f.adjoint ∘L f) (g.adjoint ∘L g) := by + rw [adjoint_mapL, mapL_comp] + +/-- Conjugating a tensor-product map by `mapL f g` factors over the slots: +`mapL f g ∘ mapL ρ σ ∘ (mapL f g)† = mapL (f ∘ ρ ∘ f†) (g ∘ σ ∘ g†)`. CLM-level lift combining +`adjoint_mapL` and `mapL_comp`; the Kraus action of a tensor-product operator on a product map. -/ +theorem mapL_comp_self [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] + [FiniteDimensional 𝕜 H] [CompleteSpace E] [CompleteSpace F] [CompleteSpace G] [CompleteSpace H] + (f : E →L[𝕜] F) (g : G →L[𝕜] H) (ρ : E →L[𝕜] E) (σ : G →L[𝕜] G) : + mapL f g ∘L mapL ρ σ ∘L (mapL f g).adjoint + = mapL (f ∘L ρ ∘L f.adjoint) (g ∘L σ ∘L g.adjoint) := by + rw [adjoint_mapL, mapL_comp, mapL_comp] + +-- `TensorProduct.mapL_add_left`, `mapL_zero_left`, `mapL_zero_right`, `mapL_add_right`, +-- `mapL_smul_left`, `mapL_smul_right` now exist upstream in +-- `Mathlib.Analysis.InnerProductSpace.TensorProduct` (more general: no `FiniteDimensional` +-- hypotheses needed). Use the upstream declarations directly. + +/-- `mapL` negates in the first argument: `mapL (-f) g = -mapL f g`. -/ +theorem mapL_neg_left + (f : E →L[𝕜] F) (g : G →L[𝕜] H) : + mapL (-f) g = -mapL f g := by + rw [← neg_one_smul 𝕜 f, mapL_smul_left, neg_one_smul] + +/-- `mapL` negates in the second argument: `mapL f (-g) = -mapL f g`. -/ +theorem mapL_neg_right + (f : E →L[𝕜] F) (g : G →L[𝕜] H) : + mapL f (-g) = -mapL f g := by + rw [← neg_one_smul 𝕜 g, mapL_smul_right, neg_one_smul] + +/-- `mapL` is additive-subtractive in the first argument: +`mapL (f₁ - f₂) g = mapL f₁ g - mapL f₂ g`. -/ +theorem mapL_sub_left + (f₁ f₂ : E →L[𝕜] F) (g : G →L[𝕜] H) : + mapL (f₁ - f₂) g = mapL f₁ g - mapL f₂ g := by + rw [sub_eq_add_neg, mapL_add_left, mapL_neg_left, ← sub_eq_add_neg] + +/-- `mapL` is additive-subtractive in the second argument: +`mapL f (g₁ - g₂) = mapL f g₁ - mapL f g₂`. -/ +theorem mapL_sub_right + (f : E →L[𝕜] F) (g₁ g₂ : G →L[𝕜] H) : + mapL f (g₁ - g₂) = mapL f g₁ - mapL f g₂ := by + rw [sub_eq_add_neg, mapL_add_right, mapL_neg_right, ← sub_eq_add_neg] + +/-- **The tensor square of a nonzero operator is nonzero**: for a finite-dimensional inner product +space `E` and `x : E →L[𝕜] E` with `x ≠ 0`, the tensor-product map `mapL x x ≠ 0`. Pick a witness +`v` with `x v ≠ 0`; then `mapL x x (v ⊗ₜ v) = x v ⊗ₜ x v` has norm `‖x v‖ * ‖x v‖ ≠ 0`, so the map +is nonzero. The finite-dimensional analogue over an inner product space of the "tensor of nonzero is +nonzero" fact for operators. -/ +theorem mapL_self_ne_zero {x : E →L[𝕜] E} (hx : x ≠ 0) : + mapL x x ≠ 0 := by + obtain ⟨v, hv⟩ := DFunLike.ne_iff.mp hx + rw [_root_.zero_apply] at hv + intro hzero + refine hv (norm_eq_zero.mp (mul_self_eq_zero.mp ?_)) + rw [← norm_tmul (𝕜 := 𝕜), ← mapL_tmul, hzero, _root_.zero_apply, norm_zero] + +/-- The factor-swap `commIsometry` on `E ⊗[𝕜] E` is an involution as a continuous linear map: +`commIsometry ∘ commIsometry = id`. -/ +theorem commIsometry_comp_self : + (commIsometry 𝕜 E E : E ⊗[𝕜] E →L[𝕜] E ⊗[𝕜] E).comp + (commIsometry 𝕜 E E : E ⊗[𝕜] E →L[𝕜] E ⊗[𝕜] E) = 1 := by + apply ContinuousLinearMap.coe_injective + apply TensorProduct.ext' + intro x y + simp [commIsometry_apply, comm_tmul] + +/-- Conjugating a tensor-product operator by the factor-swap `commIsometry` interchanges the two +factor operators: `commIsometry ∘ (A ⊗ B) ∘ commIsometry = B ⊗ A`, as continuous linear maps on +`E ⊗[𝕜] E`. This is the continuous-linear, isometric-swap form of the naturality of +`TensorProduct.comm` (`TensorProduct.map_comp_comm_eq`). -/ +theorem commIsometry_conj_mapL (A B : E →L[𝕜] E) : + (commIsometry 𝕜 E E : E ⊗[𝕜] E →L[𝕜] E ⊗[𝕜] E).comp + ((mapL A B).comp (commIsometry 𝕜 E E : E ⊗[𝕜] E →L[𝕜] E ⊗[𝕜] E)) + = mapL B A := by + apply ContinuousLinearMap.coe_injective + apply TensorProduct.ext' + intro x y + simp [commIsometry_apply, comm_tmul] + +/-- Conjugating a tensor-product operator by the factor-swap `commIsometry` (as the `⋆`-algebra +equivalence `conjStarAlgEquiv`) interchanges the two factor operators: +`commIsometry.conjStarAlgEquiv (A ⊗ B) = B ⊗ A`, as continuous linear maps on `F ⊗[𝕜] E`. The +`conjStarAlgEquiv`, distinct-input-space companion of `commIsometry_conj_mapL`. -/ +theorem commIsometry_conjStarAlgEquiv_mapL [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + (A : E →L[𝕜] E) (B : F →L[𝕜] F) : + (commIsometry 𝕜 E F).conjStarAlgEquiv (mapL A B) = mapL B A := by + apply ContinuousLinearMap.coe_injective + apply TensorProduct.ext' + intro y x + simp [commIsometry_apply, comm_tmul, commIsometry_symm] + +/-- The Lie bracket of two left-embedded operators factors through `mapL`: +`⁅mapL f₁ 1, mapL f₂ 1⁆ = mapL ⁅f₁, f₂⁆ 1`. The left embedding `f ↦ f ⊗ 1` is a ring +homomorphism (`mapL_mul_one` + additivity), so it preserves the ring commutator. -/ +theorem mapL_lie_left + (f₁ f₂ : E →L[𝕜] E) : + ⁅mapL f₁ (1 : F →L[𝕜] F), mapL f₂ (1 : F →L[𝕜] F)⁆ = mapL ⁅f₁, f₂⁆ 1 := by + rw [Ring.lie_def, Ring.lie_def, ← mapL_mul_one, ← mapL_mul_one, ← mapL_sub_left] + +/-- The Lie bracket of two right-embedded operators factors through `mapL`: +`⁅mapL 1 g₁, mapL 1 g₂⁆ = mapL 1 ⁅g₁, g₂⁆`. The right embedding `g ↦ 1 ⊗ g` is a ring +homomorphism (`mapL_mul` + additivity), so it preserves the ring commutator. -/ +theorem mapL_lie_right + (g₁ g₂ : F →L[𝕜] F) : + ⁅mapL (1 : E →L[𝕜] E) g₁, mapL (1 : E →L[𝕜] E) g₂⁆ = mapL 1 ⁅g₁, g₂⁆ := by + rw [Ring.lie_def, Ring.lie_def, ← mapL_mul, ← mapL_mul, ← mapL_sub_right, one_mul] + +/-- `mapL` factors via two "tensor-by-identity" maps composed: `mapL f g = mapL f 1 ∘ mapL 1 g`. +CLM-level lift of `TensorProduct.map_comp` applied at the identity in opposite slots. -/ +theorem mapL_factor + (f : E →L[𝕜] F) (g : G →L[𝕜] H) : + mapL f g = (mapL f (1 : H →L[𝕜] H)).comp (mapL (1 : E →L[𝕜] E) g) := by + refine ContinuousLinearMap.coe_injective (TensorProduct.ext' fun a b ↦ ?_) + simp + +/-- `mapL · 1` as a `LinearMap`: linear in the first argument (`mapL_add_left` + +`mapL_smul_left`). Scaffolding for `Continuous.mapL` (file-local). -/ +private noncomputable def mapL_one_right_LM : + (E →L[𝕜] F) →ₗ[𝕜] (E ⊗[𝕜] H →L[𝕜] F ⊗[𝕜] H) where + toFun f := mapL f (1 : H →L[𝕜] H) + map_add' f₁ f₂ := mapL_add_left f₁ f₂ 1 + map_smul' c f := mapL_smul_left c f 1 + +/-- `mapL 1 ·` as a `LinearMap`: linear in the second argument. Scaffolding for +`Continuous.mapL` (file-local). -/ +private noncomputable def mapL_one_left_LM : + (G →L[𝕜] H) →ₗ[𝕜] (E ⊗[𝕜] G →L[𝕜] E ⊗[𝕜] H) where + toFun g := mapL (1 : E →L[𝕜] E) g + map_add' g₁ g₂ := mapL_add_right 1 g₁ g₂ + map_smul' c g := mapL_smul_right c 1 g + +/-- `mapL 1 ·` distributes over finite sums in the second argument: +`mapL 1 (∑ k, g k) = ∑ k, mapL 1 (g k)`. -/ +theorem mapL_one_sum_right + {n : Type*} [Fintype n] (g : n → (G →L[𝕜] H)) : + mapL (1 : E →L[𝕜] E) (∑ k, g k) = ∑ k, mapL (1 : E →L[𝕜] E) (g k) := + map_sum (mapL_one_left_LM (E := E)) g Finset.univ + +/-- `mapL · g` as a `LinearMap`: linear in the first argument (`mapL_add_left` + +`mapL_smul_left`). Scaffolding for `mapL_sum_left` (file-local). -/ +private noncomputable def mapL_rightArg_LM + (g : G →L[𝕜] H) : + (E →L[𝕜] F) →ₗ[𝕜] (E ⊗[𝕜] G →L[𝕜] F ⊗[𝕜] H) where + toFun f := mapL f g + map_add' f₁ f₂ := mapL_add_left f₁ f₂ g + map_smul' c f := mapL_smul_left c f g + +/-- `mapL f ·` as a `LinearMap`: linear in the second argument (`mapL_add_right` + +`mapL_smul_right`). Scaffolding for `mapL_sum_right` (file-local). -/ +private noncomputable def mapL_leftArg_LM + (f : E →L[𝕜] F) : + (G →L[𝕜] H) →ₗ[𝕜] (E ⊗[𝕜] G →L[𝕜] F ⊗[𝕜] H) where + toFun g := mapL f g + map_add' g₁ g₂ := mapL_add_right f g₁ g₂ + map_smul' c g := mapL_smul_right c f g + +/-- `mapL` distributes over finite sums in the first argument: +`mapL (∑ k, A k) g = ∑ k, mapL (A k) g`. -/ +theorem mapL_sum_left + {n : Type*} [Fintype n] (A : n → (E →L[𝕜] F)) (g : G →L[𝕜] H) : + mapL (∑ k, A k) g = ∑ k, mapL (A k) g := + map_sum (mapL_rightArg_LM g) A Finset.univ + +/-- `mapL` distributes over finite sums in the second argument: +`mapL f (∑ k, B k) = ∑ k, mapL f (B k)`. -/ +theorem mapL_sum_right + {n : Type*} [Fintype n] (f : E →L[𝕜] F) (B : n → (G →L[𝕜] H)) : + mapL f (∑ k, B k) = ∑ k, mapL f (B k) := + map_sum (mapL_leftArg_LM f) B Finset.univ + +/-- **Joint continuity of `mapL`**: for continuous `f : β → E →L[𝕜] F` and `g : β → G →L[𝕜] H` +(`β` topological, all spaces finite-dim), `b ↦ mapL (f b) (g b)` is continuous. Proof via the +factorization `mapL f g = mapL f 1 ∘ mapL 1 g`: the two factors are linear-in-one-arg, hence +continuous in finite-dim; their composition is jointly continuous bilinear via +`isBoundedBilinearMap_comp`. -/ +theorem _root_.Continuous.mapL [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] + [FiniteDimensional 𝕜 G] [FiniteDimensional 𝕜 H] + {β : Type*} [TopologicalSpace β] + {f : β → E →L[𝕜] F} {g : β → G →L[𝕜] H} + (hf : Continuous f) (hg : Continuous g) : + Continuous (fun b ↦ TensorProduct.mapL (f b) (g b)) := + (isBoundedBilinearMap_comp.continuous.comp (Continuous.prodMk + ((TensorProduct.mapL_one_right_LM (E := E) (F := F) (H := H) + (𝕜 := 𝕜)).continuous_of_finiteDimensional.comp hf) + ((TensorProduct.mapL_one_left_LM (E := E) (G := G) (H := H) + (𝕜 := 𝕜)).continuous_of_finiteDimensional.comp hg))).congr + fun b ↦ (TensorProduct.mapL_factor (f b) (g b)).symm + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProductCongrConj.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProductCongrConj.lean new file mode 100644 index 0000000000..794d0fb169 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TensorProductCongrConj.lean @@ -0,0 +1,58 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorProduct + +/-! +# Conjugation of a tensor-product operator by a factorwise transport + +The factorwise-transport companion of `TensorProduct.commIsometry_conjStarAlgEquiv_mapL` and +`TensorProduct.assocIsometry_conjStarAlgEquiv_mapL_mapL`: conjugating the tensor-product operator +`A ⊗ B` by the factorwise isometry `congrIsometry e f` (as the `⋆`-algebra equivalence +`LinearIsometryEquiv.conjStarAlgEquiv`) conjugates each factor operator by its own transport, + +`(e ⊗ f) (A ⊗ B) (e ⊗ f)⁻¹ = (e A e⁻¹) ⊗ (f B f⁻¹)`. + +This is the `conjStarAlgEquiv` reading of the naturality of `TensorProduct.map` under +`TensorProduct.congr`, packaged for the density-operator transport machinery +(`LinearIsometryEquiv.conjStarAlgEquiv` is how a state/observable is carried along a unitary +change of basis). +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace TensorProduct + +variable {𝕜 : Type*} {E F G H : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] + [CompleteSpace E] [CompleteSpace F] [CompleteSpace G] [CompleteSpace H] + [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] [FiniteDimensional 𝕜 G] [FiniteDimensional 𝕜 H] + +/-- Conjugating a tensor-product operator by a factorwise transport `congrIsometry e f` (as the +`⋆`-algebra equivalence `conjStarAlgEquiv`) conjugates each factor operator by its own transport: +`(e ⊗ f).conjStarAlgEquiv (A ⊗ B) = (e A e⁻¹) ⊗ (f B f⁻¹)`, as continuous linear maps on +`G ⊗[𝕜] H`. The `conjStarAlgEquiv` reading of the naturality of `map` under `congr`, and the +factorwise sibling of `commIsometry_conjStarAlgEquiv_mapL` / +`assocIsometry_conjStarAlgEquiv_mapL_mapL`. -/ +theorem congrIsometry_conjStarAlgEquiv_mapL (e : E ≃ₗᵢ[𝕜] G) (f : F ≃ₗᵢ[𝕜] H) + (A : E →L[𝕜] E) (B : F →L[𝕜] F) : + (congrIsometry e f).conjStarAlgEquiv (mapL A B) + = mapL (e.conjStarAlgEquiv A) (f.conjStarAlgEquiv B) := by + apply ContinuousLinearMap.coe_injective + apply TensorProduct.ext' + intro x y + simp [congrIsometry_apply, congrIsometry_symm] + +end TensorProduct + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Trace.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Trace.lean new file mode 100644 index 0000000000..5d3716a8be --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Trace.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.Analysis.InnerProductSpace.Positive +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Adjoint + +/-! +# Traces in inner product spaces: additional API + +This file collects additional facts about `LinearMap.trace` on finite-dimensional inner product +spaces: non-negativity and a basis-sum formula for the trace of `T† ∘ T`, non-degeneracy of the +Hilbert-Schmidt pairing, commutation of the trace with the adjoint (up to conjugation), a +spectral expansion of `trace (M ∘ T)`, continuity of the trace on `E →L[𝕜] E`, and invariance of +the trace under conjugation by a linear isometry (equivalence or otherwise). +-/ + +@[expose] public section + +namespace LinearMap + +variable {𝕜 E ι : Type*} [RCLike 𝕜] [Fintype ι] +variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + +open scoped InnerProductSpace ComplexOrder + +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + [FiniteDimensional 𝕜 F] + +/-- The trace of `T† ∘ T` is non-negative in the order on `𝕜`. -/ +theorem trace_adjoint_comp_self_nonneg (T : E →ₗ[𝕜] F) : + 0 ≤ (T.adjoint ∘ₗ T).trace 𝕜 E := + T.isPositive_adjoint_comp_self.trace_nonneg + +/-- The trace of `T† ∘ T` has a basis-sum form: `re trace (T† ∘ T) = ∑ i, ‖T (b i)‖²` +for any orthonormal basis. -/ +theorem re_trace_adjoint_comp_self_eq_sum_norm_sq {ι : Type*} [Fintype ι] + (T : E →ₗ[𝕜] F) (b : OrthonormalBasis ι 𝕜 E) : + RCLike.re ((T.adjoint ∘ₗ T).trace 𝕜 E) = ∑ i, ‖T (b i)‖ ^ 2 := by + rw [trace_eq_sum_inner _ b, map_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [LinearMap.comp_apply, LinearMap.adjoint_inner_right, inner_self_eq_norm_sq] + +/-- The basis-sum form of `re trace (T† ∘ T)` makes it manifestly non-negative. -/ +theorem re_trace_adjoint_comp_self_nonneg (T : E →ₗ[𝕜] F) : + 0 ≤ RCLike.re ((T.adjoint ∘ₗ T).trace 𝕜 E) := + (RCLike.nonneg_iff.mp T.trace_adjoint_comp_self_nonneg).1 + +/-- **Non-degeneracy of the HS pairing**: a linear map `T : E →ₗ[𝕜] F` between +finite-dim inner product spaces with `trace (T† ∘ T) = 0` must be zero. Follows from +`re_trace_adjoint_comp_self_eq_sum_norm_sq`: the real part of the trace expands as +`∑ ‖T (b i)‖² = 0` over any orthonormal basis, forcing each term to vanish. -/ +theorem eq_zero_of_trace_adjoint_comp_self_eq_zero (T : E →ₗ[𝕜] F) + (h : (T.adjoint ∘ₗ T).trace 𝕜 E = 0) : T = 0 := by + set b := stdOrthonormalBasis 𝕜 E + refine b.toBasis.ext fun i ↦ ?_ + rw [OrthonormalBasis.coe_toBasis, LinearMap.zero_apply, ← norm_eq_zero, ← sq_eq_zero_iff] + have h_sum := T.re_trace_adjoint_comp_self_eq_sum_norm_sq b + rw [h, map_zero] at h_sum + exact (Finset.sum_eq_zero_iff_of_nonneg fun _ _ ↦ sq_nonneg _).mp h_sum.symm i + (Finset.mem_univ _) + +/-- *Spectral expansion of `trace (M ∘ T)`*: for a symmetric operator `T` with eigenvalues +`λⱼ` and eigenvector ONB `bⱼ`, and any linear operator `M`, the trace of `M ∘ T` factors as +`∑ j, λⱼ * ⟪bⱼ, M bⱼ⟫`. Foundational for finite-dim quantum information theory (Born rule, +expectation values, density-matrix traces). -/ +theorem IsSymmetric.trace_comp_eq_sum_eigenvalues_inner + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) + (M : E →ₗ[𝕜] E) : + LinearMap.trace 𝕜 E (M ∘ₗ T) = + ∑ j, (hT.eigenvalues hn j : 𝕜) * + inner 𝕜 (hT.eigenvectorBasis hn j) (M (hT.eigenvectorBasis hn j)) := by + rw [LinearMap.trace_eq_sum_inner _ (hT.eigenvectorBasis hn)] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [LinearMap.comp_apply, hT.apply_eigenvectorBasis hn j, + LinearMap.map_smul, inner_smul_right] + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [FiniteDimensional 𝕜 E] + +/-- The trace `(T : E →L[𝕜] E) ↦ LinearMap.trace 𝕜 E T.toLinearMap` is continuous on a +finite-dimensional inner product space. Expanded in an orthonormal basis as +`∑ i, ⟪b i, T (b i)⟫`, then continuity follows from continuity of inner product and +CLM evaluation. -/ +@[fun_prop] +theorem continuous_trace : + Continuous (fun T : E →L[𝕜] E ↦ LinearMap.trace 𝕜 E (T : E →ₗ[𝕜] E)) := by + set b := stdOrthonormalBasis 𝕜 E + simp_rw [LinearMap.trace_eq_sum_inner _ b, ContinuousLinearMap.coe_coe] + exact continuous_finsetSum _ fun i _ ↦ + (continuous_const (y := b i)).inner ((ContinuousLinearMap.apply 𝕜 E (b i)).continuous) + +omit [FiniteDimensional 𝕜 E] in +/-- **Trace invariance under conjugation by a linear isometry equivalence.** The trace of +`T : E →L[𝕜] E` and `e.conjStarAlgEquiv T : F →L[𝕜] F` agree. Companion to +`ContinuousLinearMap.traceNorm_conjStarAlgEquiv` (in TraceNorm.lean) at the plain-trace +level. Combines the `conjStarAlgEquiv_toLinearMap` rfl-bridge (Adjoint.lean) with +`LinearMap.trace_conj'`. -/ +theorem trace_conjStarAlgEquiv [CompleteSpace E] {F : Type*} + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F] + (e : E ≃ₗᵢ[𝕜] F) (T : E →L[𝕜] E) : + LinearMap.trace 𝕜 F ((e.conjStarAlgEquiv T : F →L[𝕜] F) : F →ₗ[𝕜] F) = + LinearMap.trace 𝕜 E (T : E →ₗ[𝕜] E) := by + rw [LinearIsometryEquiv.conjStarAlgEquiv_toLinearMap] + exact LinearMap.trace_conj' _ _ + +/-- **Trace invariance under conjugation by a (possibly non-surjective) isometry.** For +`V : E →L[𝕜] F` with `V† V = 1`, `tr_F (V A V†) = tr_E A`: trace cyclicity moves `V` past `A V†` +and `V† V = 1` collapses. The non-equiv companion to `trace_conjStarAlgEquiv`. -/ +theorem trace_conj_isometry [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] + [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] [CompleteSpace F] + {V : E →L[𝕜] F} (hV : V.adjoint ∘L V = 1) (A : E →L[𝕜] E) : + LinearMap.trace 𝕜 F (V ∘L A ∘L V.adjoint : F →L[𝕜] F).toLinearMap + = LinearMap.trace 𝕜 E A.toLinearMap := by + rw [ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + ← LinearMap.trace_comp_comm', LinearMap.comp_assoc, ← ContinuousLinearMap.toLinearMap_comp, hV] + congr 1 + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TraceNorm.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TraceNorm.lean new file mode 100644 index 0000000000..58b7314f5b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/TraceNorm.lean @@ -0,0 +1,693 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Dual +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.HSPairing +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Abs + +/-! +# Trace norm of a linear operator on a finite-dimensional inner product space + +For a linear map `T : E →ₗ[𝕜] F` between finite-dimensional inner product spaces over `𝕜` +(where `𝕜` is `ℝ` or `ℂ`), the **trace norm** (also known as the nuclear norm or +Schatten 1-norm) is the sum of the singular values of `T`: + +`‖T‖₁ := ∑ i, T.singularValues i` + +Equivalently, it is the real part of the trace of `|T| := √(T† ∘ T)`: + +`‖T‖₁ = re (trace |T|)` + +## Main definitions + +- `LinearMap.traceNorm` — the trace norm as an `ℝ`-valued function. +- `ContinuousLinearMap.traceNorm` — the CLM-coerced sibling. + +## Main results + +- `LinearMap.traceNorm_zero`, `LinearMap.traceNorm_nonneg`, `LinearMap.traceNorm_eq_zero_iff`: + basic API. +- `LinearMap.traceNorm_eq_re_trace_absoluteValue` and + `LinearMap.ofReal_traceNorm_eq_trace_absoluteValue`: connect `traceNorm` to the trace of + the absolute value of the operator. +- `LinearMap.traceNorm_rankOne`: `traceNorm (rankOne 𝕜 x y) = ‖x‖ * ‖y‖`. +- `LinearMap.opNorm_le_traceNorm` (and CLM sibling): `‖T‖_op ≤ ‖T‖₁`. +- `LinearMap.norm_hsPairing_le_opNorm_mul_traceNorm` (and CLM sibling): the Hölder-type + bound `‖hsPairing T W‖ ≤ ‖W‖_op * ‖T‖₁`. +- `ContinuousLinearMap.hsPairing_polarPart_eq_ofReal_traceNorm` and + `ContinuousLinearMap.re_hsPairing_polarPart_eq_traceNorm`: achievability of the + variational characterization at `W = polarPart T`. +- `ContinuousLinearMap.re_hsPairing_le_traceNorm_of_opNorm_le_one`: combined with + achievability, the variational characterization `‖T‖₁ = sup_{‖W‖_op ≤ 1} re (hsPairing T W)`. +- `ContinuousLinearMap.traceNorm_add_le`: the triangle inequality + `‖T + S‖₁ ≤ ‖T‖₁ + ‖S‖₁`, derived from the two halves of the variational + characterization; `traceNorm_sub_le` and `traceNorm_sum_le` are the subtraction + and finite-sum forms. +- `ContinuousLinearMap.traceNorm_comp_le` and `traceNorm_comp_le'`: + sub-multiplicativity in both directions, `‖S ∘ T‖₁ ≤ ‖S‖_op · ‖T‖₁` and + `‖S ∘ T‖₁ ≤ ‖S‖₁ · ‖T‖_op`. Derived from the move-adjoint identities in + `HSPairing.lean` + the Hölder bound + `polarPart_opNorm_le_one`. + +## Implementation notes + +The definition uses a finite sum over `Fin (finrank 𝕜 E)`, mirroring +`HilbertSchmidt.norm_sq_eq_sum_sq_singularValues`. Even though singular values past +`finrank (range T)` are zero, the Fin-sum form composes cleanly with the rest of the +singular-value API. + +The trace norm requires both `[FiniteDimensional 𝕜 E]` and `[FiniteDimensional 𝕜 F]` because +`LinearMap.singularValues` does. `[CompleteSpace _]` is **not** required at the definition +level — it appears only on lemmas that explicitly invoke `adjoint`. + +The definition is RCLike-generic. The trace norm itself doesn't depend on the continuous +functional calculus chain (which currently requires complex C*-algebra structure for the +self-adjoint CFC instance); any future Schatten-p generalization that does would need to +match its surroundings accordingly. +-/ + +@[expose] public section + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The **trace norm** (Schatten 1-norm) of a linear map between finite-dimensional inner +product spaces: the sum of the singular values of `T`. -/ +noncomputable def traceNorm (T : E →ₗ[𝕜] F) : ℝ := + ∑ i : Fin (Module.finrank 𝕜 E), T.singularValues i.val + +theorem traceNorm_eq (T : E →ₗ[𝕜] F) : + T.traceNorm = ∑ i : Fin (Module.finrank 𝕜 E), T.singularValues i.val := rfl + +@[simp] +theorem traceNorm_zero : traceNorm (0 : E →ₗ[𝕜] F) = 0 := by + simp [traceNorm_eq] + +theorem traceNorm_nonneg (T : E →ₗ[𝕜] F) : 0 ≤ T.traceNorm := by + exact Finset.sum_nonneg fun i _ ↦ T.singularValues_nonneg i.val + +@[simp] +theorem traceNorm_neg (T : E →ₗ[𝕜] F) : (-T).traceNorm = T.traceNorm := by + simp [traceNorm_eq, singularValues_neg] + +/-- The trace norm scales by the norm of the scalar: +`(c • T).traceNorm = ‖c‖ * T.traceNorm`. Direct consequence of `singularValues_smul` + +`Finset.mul_sum`. -/ +@[simp] +theorem traceNorm_smul (c : 𝕜) (T : E →ₗ[𝕜] F) : + (c • T).traceNorm = ‖c‖ * T.traceNorm := by + simp only [traceNorm_eq, singularValues_smul, Finsupp.smul_apply, smul_eq_mul, Finset.mul_sum] + +/-- **Trace norm is invariant under left-composition with a linear isometry.** Direct +consequence of `singularValues_linearIsometry_comp`: both sums range over the same +`Fin (finrank E)` (since the source is preserved under left-composition). -/ +theorem traceNorm_linearIsometry_comp + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + (U : F →ₗᵢ[𝕜] G) (T : E →ₗ[𝕜] F) : + (U.toLinearMap ∘ₗ T).traceNorm = T.traceNorm := by + simp [traceNorm_eq, singularValues_linearIsometry_comp] + +/-- **Trace norm is invariant under right-composition with a linear isometry equivalence.** +Routes through `singularValues_comp_linearIsometryEquiv` + `Fintype.sum_equiv` to bridge the +`Fin (finrank E')` vs `Fin (finrank E)` summation domains via `Fin.castOrderIso`. -/ +theorem traceNorm_comp_linearIsometryEquiv + {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [FiniteDimensional 𝕜 E'] + (V : E' ≃ₗᵢ[𝕜] E) (T : E →ₗ[𝕜] F) : + (T ∘ₗ V.toLinearEquiv.toLinearMap).traceNorm = T.traceNorm := by + have hsingular : + (T ∘ₗ V.toLinearEquiv.toLinearMap).singularValues = T.singularValues := + singularValues_comp_linearIsometryEquiv T V + rw [traceNorm_eq, traceNorm_eq, hsingular] + exact Fintype.sum_equiv (Fin.castOrderIso V.toLinearEquiv.finrank_eq).toEquiv _ _ (fun _ ↦ rfl) + +/-- The trace norm is invariant under adjoint: `T†.traceNorm = T.traceNorm`. Direct consequence +of `singularValues_adjoint`: the singular-value sequences agree pointwise, and both sums +restrict (via `sum_singularValues_eq_sum_range_finrank_range`) to a sum over +`Finset.range (finrank T.range)` (= `Finset.range (finrank T†.range)` by `finrank_range_adjoint`), +bridging the `Fin (finrank F)` vs `Fin (finrank E)` summation domains. -/ +theorem traceNorm_adjoint (T : E →ₗ[𝕜] F) : T.adjoint.traceNorm = T.traceNorm := by + rw [traceNorm_eq, traceNorm_eq, singularValues_adjoint, + sum_singularValues_eq_sum_range_finrank_range T (Submodule.finrank_le _), + sum_singularValues_eq_sum_range_finrank_range T + ((finrank_range_adjoint T).symm.le.trans (Submodule.finrank_le _))] + +theorem traceNorm_eq_zero_iff {T : E →ₗ[𝕜] F} : T.traceNorm = 0 ↔ T = 0 := by + refine ⟨fun h ↦ ?_, fun h ↦ h ▸ traceNorm_zero⟩ + rw [traceNorm_eq, Finset.sum_eq_zero_iff_of_nonneg + fun i _ ↦ T.singularValues_nonneg i.val] at h + refine T.singularValues_eq_zero_iff.mp ?_ + ext i + rcases lt_or_ge i (Module.finrank 𝕜 E) with hi | hi + · simpa using h ⟨i, hi⟩ (Finset.mem_univ _) + · exact T.singularValues_of_finrank_le hi + +/-- For a positive endomorphism `S : E →ₗ[𝕜] E`, the trace norm equals the real part of the +trace. Routes through `IsPositive.singularValues_eq_eigenvalues` (singular values = eigenvalues +for positive operators) + `IsSymmetric.re_trace_eq_sum_eigenvalues`. -/ +theorem traceNorm_eq_re_trace_of_isPositive + {S : E →ₗ[𝕜] E} (hS : S.IsPositive) : + S.traceNorm = RCLike.re (LinearMap.trace 𝕜 E S) := by + rw [traceNorm_eq, hS.isSymmetric.re_trace_eq_sum_eigenvalues rfl] + exact Finset.sum_congr rfl fun i _ ↦ hS.singularValues_eq_eigenvalues rfl i + +/-- For a symmetric endomorphism `T : E →ₗ[𝕜] E`, the trace norm equals the sum of absolute +values of the eigenvalues. Companion to `IsPositive.singularValues_eq_eigenvalues`: extends +beyond the positive case at the cost of dropping pointwise sort alignment (the absolute values +of symmetric eigenvalues form the same multiset as the singular values, but not in the same +order). -/ +theorem IsSymmetric.traceNorm_eq_sum_abs_eigenvalues + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) + {n : ℕ} (hn : Module.finrank 𝕜 E = n) : + T.traceNorm = ∑ i : Fin n, |hT.eigenvalues hn i| := by + subst hn + have h2 : (T.adjoint ∘ₗ T).IsSymmetric := T.isSymmetric_adjoint_comp_self + -- Eigenbasis recognition: T*T has eigenbasis (hT.eigenvectorBasis) with squared eigenvalues. + have hms : Multiset.map (h2.eigenvalues rfl) Finset.univ.val = + Multiset.map (fun i => (hT.eigenvalues rfl i) ^ 2) Finset.univ.val := + (h2.eigenvalues_multiset_map_eq_of_eigenbasis rfl (hT.eigenvectorBasis rfl).toBasis + fun i => by simpa using hT.adjoint_comp_self_apply_eigenvectorBasis rfl i).symm + -- Convert both sides to `∑ √(...)`; reduce to multiset equality. + rw [LinearMap.traceNorm_eq] + simp_rw [fun i : Fin (Module.finrank 𝕜 E) => T.singularValues_of_lt rfl i.is_lt, + Fin.eta, + fun i : Fin (Module.finrank 𝕜 E) => (Real.sqrt_sq_eq_abs (hT.eigenvalues rfl i)).symm] + -- Both sides are ∑ √(f i) where the f's are multiset-equal. + change (Multiset.map (Real.sqrt ∘ h2.eigenvalues rfl) Finset.univ.val).sum = + (Multiset.map (Real.sqrt ∘ fun i => (hT.eigenvalues rfl i) ^ 2) Finset.univ.val).sum + rw [← Multiset.map_map Real.sqrt (h2.eigenvalues rfl), + ← Multiset.map_map Real.sqrt (fun i => (hT.eigenvalues rfl i) ^ 2), hms] + +/-- For a symmetric `T : E →ₗ[𝕜] E`, the trace norm equals the sum of `𝕜`-norms of the +characteristic polynomial's roots. Composes `IsSymmetric.traceNorm_eq_sum_abs_eigenvalues` +with `IsSymmetric.roots_charpoly_eq_eigenvalues` via `‖(x : 𝕜)‖ = |x|` for real `x`. -/ +theorem IsSymmetric.traceNorm_eq_sum_norm_charpoly_roots + {T : E →ₗ[𝕜] E} (hT : T.IsSymmetric) : + T.traceNorm = (T.charpoly.roots.map (‖·‖)).sum := by + rw [hT.traceNorm_eq_sum_abs_eigenvalues rfl, Finset.sum_eq_multiset_sum, + hT.roots_charpoly_eq_eigenvalues rfl, Multiset.map_map] + refine congr_arg Multiset.sum (Multiset.map_congr rfl fun _ _ => ?_) + exact (RCLike.norm_ofReal _).symm + +/-- The trace of `|T|` equals the ℝ-cast sum of singular values of `T`. The substantive +identity behind `LinearMap.ofReal_traceNorm_eq_trace_absoluteValue`. -/ +theorem trace_absoluteValue_eq_ofReal_sum_singularValues (T : E →L[𝕜] F) : + LinearMap.trace 𝕜 E T.toLinearMap.absoluteValue = + ((∑ i : Fin (Module.finrank 𝕜 E), T.toLinearMap.singularValues i.val : ℝ) : 𝕜) := by + rw [← ContinuousLinearMap.toLinearMap_absoluteValue, T.absoluteValue_eq_sum, + ContinuousLinearMap.toLinearMap_sum, map_sum, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [ContinuousLinearMap.toLinearMap_smul, LinearMap.map_smul_of_tower, + InnerProductSpace.trace_rankOne, + inner_self_eq_norm_sq_to_K, (T.toLinearMap.svdRight).orthonormal.1, RCLike.ofReal_one, + one_pow, smul_eq_mul, mul_one] + +/-- The trace norm equals the trace of the absolute value, coerced to `𝕜`. -/ +theorem ofReal_traceNorm_eq_trace_absoluteValue (T : E →L[𝕜] F) : + (T.toLinearMap.traceNorm : 𝕜) = + LinearMap.trace 𝕜 E T.toLinearMap.absoluteValue := + (trace_absoluteValue_eq_ofReal_sum_singularValues T).symm + +/-- The trace norm equals the real part of the trace of the absolute value `|T| = √(T† ∘ T)`. -/ +theorem traceNorm_eq_re_trace_absoluteValue (T : E →L[𝕜] F) : + T.toLinearMap.traceNorm = + RCLike.re (LinearMap.trace 𝕜 E T.toLinearMap.absoluteValue) := by + rw [trace_absoluteValue_eq_ofReal_sum_singularValues, RCLike.ofReal_re, traceNorm_eq] + +/-- The trace norm of `|T|` equals the trace norm of `T` itself. Since `|T|` is positive, +its trace norm equals `re tr |T|`, which by `traceNorm_eq_re_trace_absoluteValue` is +`T.traceNorm`. -/ +theorem traceNorm_absoluteValue (T : E →L[𝕜] F) : + T.toLinearMap.absoluteValue.traceNorm = T.toLinearMap.traceNorm := by + rw [← ContinuousLinearMap.toLinearMap_absoluteValue, + traceNorm_eq_re_trace_of_isPositive T.absoluteValue_isPositive.toLinearMap, + ContinuousLinearMap.toLinearMap_absoluteValue, ← traceNorm_eq_re_trace_absoluteValue] + +/-- The largest singular value is bounded above by the trace norm. The trace norm is a +sum of nonneg singular values, so any one of them — in particular the largest — is +dominated. For trivial domain `E`, both sides are `0`. -/ +theorem singularValues_zero_le_traceNorm (T : E →ₗ[𝕜] F) : + T.singularValues 0 ≤ T.traceNorm := by + rcases Nat.eq_zero_or_pos (Module.finrank 𝕜 E) with hE | hE + · have : Subsingleton E := Module.finrank_zero_iff.mp hE + have hT : T = 0 := Subsingleton.elim T 0 + simp [hT] + · rw [traceNorm_eq] + exact Finset.single_le_sum (f := fun i : Fin (Module.finrank 𝕜 E) ↦ T.singularValues i.val) + (fun i _ ↦ T.singularValues_nonneg i.val) (Finset.mem_univ (⟨0, hE⟩ : Fin _)) + +/-- **Operator norm bound by trace norm.** `‖T‖_op ≤ ‖T‖₁` — the largest singular value +(operator norm via `opNorm_eq_singularValues_zero`) is dominated by the sum of all of them +(the trace norm). -/ +theorem opNorm_le_traceNorm (T : E →ₗ[𝕜] F) : + ‖T.toContinuousLinearMap‖ ≤ T.traceNorm := by + rw [T.opNorm_eq_singularValues_zero] + exact T.singularValues_zero_le_traceNorm + +/-- The HS pairing of `T` against `W` expands over the SVD of `T`: +`hsPairing T W = ∑ᵢ σᵢ * ⟨W (svdRight i), svdLeft i⟩`. The trace +`trace_E (W† ∘ T)` is evaluated on the SVD-right orthonormal basis of `E`, using +`apply_svdRight : T (svdRight i) = σᵢ • svdLeft i` and `adjoint_inner_right` to move +`W†` to the other inner-product slot. -/ +theorem hsPairing_eq_sum_singularValues_mul_inner (T W : E →ₗ[𝕜] F) : + T.hsPairing W = ∑ i : Fin (Module.finrank 𝕜 E), + (T.singularValues i.val : 𝕜) * inner 𝕜 (W (T.svdRight i)) (T.svdLeft i) := by + rw [LinearMap.hsPairing_eq, LinearMap.trace_eq_sum_inner _ T.svdRight] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [LinearMap.comp_apply, LinearMap.apply_svdRight, map_smul, inner_smul_right, + LinearMap.adjoint_inner_right] + +/-- **Hölder-type bound for the HS pairing vs the trace norm.** +`‖hsPairing T W‖ ≤ ‖W.toContinuousLinearMap‖ * traceNorm T`. Proof: +expand `hsPairing T W` via the SVD of `T`, apply Cauchy–Schwarz on each summand, +bound `‖W (svdRight i)‖ ≤ ‖W‖_op` (since `‖svdRight i‖ = 1`), and bound +`‖svdLeft i‖ ≤ 1` (via `norm_svdLeft_le_one`). This is the upper-bound direction of the +variational characterization `traceNorm T = ⨆_{‖W‖_op ≤ 1} re (hsPairing T W)`. -/ +theorem norm_hsPairing_le_opNorm_mul_traceNorm (T W : E →ₗ[𝕜] F) : + ‖T.hsPairing W‖ ≤ ‖W.toContinuousLinearMap‖ * T.traceNorm := by + rw [T.hsPairing_eq_sum_singularValues_mul_inner W, LinearMap.traceNorm_eq, Finset.mul_sum] + refine (norm_sum_le _ _).trans (Finset.sum_le_sum fun i _ ↦ ?_) + rw [norm_mul, RCLike.norm_ofReal, abs_of_nonneg (T.singularValues_nonneg _), mul_comm] + refine mul_le_mul_of_nonneg_right ?_ (T.singularValues_nonneg _) + calc ‖inner 𝕜 (W (T.svdRight i)) (T.svdLeft i)‖ + ≤ ‖W (T.svdRight i)‖ * ‖T.svdLeft i‖ := norm_inner_le_norm _ _ + _ ≤ ‖W.toContinuousLinearMap‖ * 1 := by + gcongr + · simpa [T.svdRight.orthonormal.1 i] + using W.toContinuousLinearMap.le_opNorm (T.svdRight i) + · exact T.norm_svdLeft_le_one i + _ = ‖W.toContinuousLinearMap‖ := mul_one _ + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The trace norm of a continuous linear map, defined as the trace norm of its underlying +linear map. -/ +noncomputable def traceNorm (T : E →L[𝕜] F) : ℝ := + T.toLinearMap.traceNorm + +@[simp] +theorem traceNorm_toLinearMap (T : E →L[𝕜] F) : T.toLinearMap.traceNorm = T.traceNorm := rfl + +@[simp] +theorem traceNorm_zero : traceNorm (0 : E →L[𝕜] F) = 0 := LinearMap.traceNorm_zero + +theorem traceNorm_nonneg (T : E →L[𝕜] F) : 0 ≤ T.traceNorm := T.toLinearMap.traceNorm_nonneg + +@[simp] +theorem traceNorm_neg (T : E →L[𝕜] F) : (-T).traceNorm = T.traceNorm := by + rw [← traceNorm_toLinearMap, ← traceNorm_toLinearMap T, toLinearMap_neg, + LinearMap.traceNorm_neg] + +/-- CLM sibling of `LinearMap.traceNorm_smul`: +`(c • T).traceNorm = ‖c‖ * T.traceNorm`. -/ +@[simp] +theorem traceNorm_smul (c : 𝕜) (T : E →L[𝕜] F) : + (c • T).traceNorm = ‖c‖ * T.traceNorm := by + rw [← traceNorm_toLinearMap, ← traceNorm_toLinearMap T, toLinearMap_smul, + LinearMap.traceNorm_smul] + +/-- CLM sibling of `LinearMap.traceNorm_adjoint` (requires `[CompleteSpace E]` and +`[CompleteSpace F]` to invoke the CLM adjoint): `T†.traceNorm = T.traceNorm`. -/ +theorem traceNorm_adjoint [CompleteSpace E] [CompleteSpace F] (T : E →L[𝕜] F) : + T.adjoint.traceNorm = T.traceNorm := by + rw [← traceNorm_toLinearMap, ← traceNorm_toLinearMap T, + ← ContinuousLinearMap.adjoint_toLinearMap, LinearMap.traceNorm_adjoint] + +/-- CLM sibling of `LinearMap.traceNorm_linearIsometry_comp`: trace norm is invariant under +left-composition with a linear isometry. -/ +theorem traceNorm_linearIsometry_comp + {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + (U : F →ₗᵢ[𝕜] G) (T : E →L[𝕜] F) : + (U.toContinuousLinearMap ∘L T).traceNorm = T.traceNorm := + LinearMap.traceNorm_linearIsometry_comp U T.toLinearMap + +/-- CLM sibling of `LinearMap.traceNorm_comp_linearIsometryEquiv`: trace norm is invariant +under right-composition with a linear isometry equivalence. -/ +theorem traceNorm_comp_linearIsometryEquiv + {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [FiniteDimensional 𝕜 E'] + (V : E' ≃ₗᵢ[𝕜] E) (T : E →L[𝕜] F) : + (T ∘L (V : E' →L[𝕜] E)).traceNorm = T.traceNorm := + LinearMap.traceNorm_comp_linearIsometryEquiv V T.toLinearMap + +/-- CLM sibling of `LinearMap.traceNorm_absoluteValue`: `|T|.traceNorm = T.traceNorm`. +The trace norm of the absolute value coincides with the trace norm of the original +operator, since `|T|` is positive and shares the singular values of `T`. -/ +theorem traceNorm_absoluteValue (T : E →L[𝕜] F) : + T.absoluteValue.traceNorm = T.traceNorm := by + rw [← traceNorm_toLinearMap, ← traceNorm_toLinearMap T, + ContinuousLinearMap.toLinearMap_absoluteValue, LinearMap.traceNorm_absoluteValue] + +theorem traceNorm_eq_zero_iff {T : E →L[𝕜] F} : T.traceNorm = 0 ↔ T = 0 := by + rw [← traceNorm_toLinearMap, LinearMap.traceNorm_eq_zero_iff, + ← ContinuousLinearMap.toLinearMap_zero, coe_inj] + +/-- CLM sibling of `LinearMap.traceNorm_eq_re_trace_of_isPositive`: for a positive endomorphism +`S : E →L[𝕜] E`, the trace norm equals the real part of the trace. -/ +theorem traceNorm_eq_re_trace_of_isPositive + {S : E →L[𝕜] E} (hS : S.IsPositive) : + S.traceNorm = RCLike.re (LinearMap.trace 𝕜 E (S : E →ₗ[𝕜] E)) := + LinearMap.traceNorm_eq_re_trace_of_isPositive hS + +/-- **Operator norm bound by trace norm**, CLM sibling of `LinearMap.opNorm_le_traceNorm`. +`‖T‖_op ≤ ‖T‖₁`. -/ +theorem opNorm_le_traceNorm (T : E →L[𝕜] F) : ‖T‖ ≤ T.traceNorm := by + simpa using T.toLinearMap.opNorm_le_traceNorm + +/-- **Hölder-type bound for the HS pairing vs the trace norm**, CLM sibling of +`LinearMap.norm_hsPairing_le_opNorm_mul_traceNorm`. -/ +theorem norm_hsPairing_le_opNorm_mul_traceNorm (T W : E →L[𝕜] F) : + ‖T.hsPairing W‖ ≤ ‖W‖ * T.traceNorm := by + simpa using T.toLinearMap.norm_hsPairing_le_opNorm_mul_traceNorm W.toLinearMap + +section VariationalCharacterization + +/-- **Achievability of the variational characterization.** The HS pairing of `T` with its +polar part equals the (`𝕜`-cast of the) trace norm: +`hsPairing T (polarPart T) = (traceNorm T : 𝕜)`. Evaluating the trace on the +`svdRight` ONB and applying `polarPart_apply_svdRight : polarPart T (svdRight i) = svdLeft i` +makes each summand reduce to `σᵢ` (the `i`-th singular value). -/ +theorem hsPairing_polarPart_eq_ofReal_traceNorm (T : E →L[𝕜] F) : + T.toLinearMap.hsPairing T.toLinearMap.polarPart = (T.toLinearMap.traceNorm : 𝕜) := by + rw [← ContinuousLinearMap.toLinearMap_polarPart, + T.toLinearMap.hsPairing_eq_sum_singularValues_mul_inner T.polarPart.toLinearMap, + LinearMap.traceNorm_eq, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + simp only [ContinuousLinearMap.coe_coe, T.polarPart_apply_svdRight i, + T.toLinearMap.inner_svdLeft_svdLeft_full, true_and] + by_cases hi : T.toLinearMap.singularValues i.val = 0 + · simp [hi] + · rw [ite_eq_left hi, mul_one] + +/-- Real-part form of achievability: +`re (hsPairing T (polarPart T)) = traceNorm T`. The HS pairing of `T` with its polar +part is `𝕜`-cast real (equal to `(traceNorm T : 𝕜)`), so taking the real part recovers +the trace norm. -/ +theorem re_hsPairing_polarPart_eq_traceNorm (T : E →L[𝕜] F) : + RCLike.re (T.hsPairing T.polarPart) = T.traceNorm := by + rw [← hsPairing_toLinearMap, ContinuousLinearMap.toLinearMap_polarPart, + T.hsPairing_polarPart_eq_ofReal_traceNorm, RCLike.ofReal_re, traceNorm_toLinearMap] + +/-- **Variational characterization of the trace norm, upper bound on the supremum side.** +For any contraction `W` (`‖W‖ ≤ 1`), `re (hsPairing T W) ≤ traceNorm T`. Follows from the +Hölder bound `norm_hsPairing_le_opNorm_mul_traceNorm` + `RCLike.re ≤ ‖·‖`. Combined with the +achievability lemma `re_hsPairing_polarPart_eq_traceNorm`, this gives the variational +characterization without committing to a particular `iSup` formulation in `ℝ`. -/ +theorem re_hsPairing_le_traceNorm_of_opNorm_le_one (T : E →L[𝕜] F) {W : E →L[𝕜] F} + (hW : ‖W‖ ≤ 1) : + RCLike.re (T.hsPairing W) ≤ T.traceNorm := + calc RCLike.re (T.hsPairing W) + ≤ ‖T.hsPairing W‖ := RCLike.re_le_norm _ + _ ≤ ‖W‖ * T.traceNorm := T.norm_hsPairing_le_opNorm_mul_traceNorm W + _ ≤ 1 * T.traceNorm := by gcongr; exact T.traceNorm_nonneg + _ = T.traceNorm := one_mul _ + +/-- **Norm-sibling of `re_hsPairing_le_traceNorm_of_opNorm_le_one`**: for any contraction +`W` (`‖W‖ ≤ 1`), `‖hsPairing T W‖ ≤ traceNorm T`. Direct from +`norm_hsPairing_le_opNorm_mul_traceNorm` + `1 * x = x`. -/ +theorem norm_hsPairing_le_traceNorm_of_opNorm_le_one (T : E →L[𝕜] F) {W : E →L[𝕜] F} + (hW : ‖W‖ ≤ 1) : + ‖T.hsPairing W‖ ≤ T.traceNorm := + calc ‖T.hsPairing W‖ + ≤ ‖W‖ * T.traceNorm := T.norm_hsPairing_le_opNorm_mul_traceNorm W + _ ≤ 1 * T.traceNorm := by gcongr; exact T.traceNorm_nonneg + _ = T.traceNorm := one_mul _ + +/-- **Triangle inequality for the trace norm.** Derived directly from the two halves of the +variational characterization: achievability at `polarPart (T + S)` gives +`traceNorm (T + S) = re (hsPairing (T+S) polarPart(T+S))`; bilinearity of `re ∘ hsPairing` +in the first slot splits this into two pieces; the Hölder corollary then bounds each piece +by the corresponding trace norm (using `polarPart_opNorm_le_one`). -/ +theorem traceNorm_add_le (T S : E →L[𝕜] F) : + (T + S).traceNorm ≤ T.traceNorm + S.traceNorm := by + have := FiniteDimensional.completeSpace 𝕜 E + have := FiniteDimensional.completeSpace 𝕜 F + have hPP : ‖(T + S).polarPart‖ ≤ 1 := (T + S).polarPart_opNorm_le_one + rw [← (T + S).re_hsPairing_polarPart_eq_traceNorm, + ContinuousLinearMap.hsPairing_add_left, map_add] + exact add_le_add (T.re_hsPairing_le_traceNorm_of_opNorm_le_one hPP) + (S.re_hsPairing_le_traceNorm_of_opNorm_le_one hPP) + +/-- **Triangle inequality for the trace norm, subtraction form**: +`‖T − S‖₁ ≤ ‖T‖₁ + ‖S‖₁`. The direct companion to `traceNorm_add_le`, obtained by rewriting +`T − S = T + (−S)` and using `traceNorm_neg`. -/ +theorem traceNorm_sub_le (T S : E →L[𝕜] F) : + (T - S).traceNorm ≤ T.traceNorm + S.traceNorm := by + rw [sub_eq_add_neg, ← traceNorm_neg S] + exact traceNorm_add_le T (-S) + +/-- **Triangle inequality for the trace norm over a finite sum**: +`‖∑ᵢ Tᵢ‖₁ ≤ ∑ᵢ ‖Tᵢ‖₁`. The `Finset` generalization of `traceNorm_add_le`, proved by +induction on the index set (base case `traceNorm_zero`, inductive step `traceNorm_add_le`). -/ +theorem traceNorm_sum_le {ι : Type*} (s : Finset ι) (T : ι → E →L[𝕜] F) : + (∑ i ∈ s, T i).traceNorm ≤ ∑ i ∈ s, (T i).traceNorm := by + classical + induction s using Finset.induction with + | empty => simp + | insert a s ha ih => + rw [Finset.sum_insert ha, Finset.sum_insert ha] + refine (traceNorm_add_le _ _).trans ?_ + gcongr + +variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] [FiniteDimensional 𝕜 G] + +/-- **Sub-multiplicativity of the trace norm, left form**: +`traceNorm (S ∘L T) ≤ ‖S‖_op * traceNorm T`. Derived from achievability + +`hsPairing_comp_left` (moving `S` to the second slot as `S.adjoint`) + the Hölder bound on +the resulting pairing, then bounding `‖S.adjoint ∘L polarPart(S∘T)‖ ≤ ‖S‖ * 1` via +`opNorm_comp_le` + `polarPart_opNorm_le_one` + `adjoint.norm_map`. -/ +theorem traceNorm_comp_le (S : F →L[𝕜] G) (T : E →L[𝕜] F) : + (S ∘L T).traceNorm ≤ ‖S‖ * T.traceNorm := by + have := FiniteDimensional.completeSpace 𝕜 E + have := FiniteDimensional.completeSpace 𝕜 F + have := FiniteDimensional.completeSpace 𝕜 G + rw [← (S ∘L T).re_hsPairing_polarPart_eq_traceNorm, + ContinuousLinearMap.hsPairing_comp_left] + calc RCLike.re (T.hsPairing (S.adjoint ∘L (S ∘L T).polarPart)) + ≤ ‖T.hsPairing (S.adjoint ∘L (S ∘L T).polarPart)‖ := RCLike.re_le_norm _ + _ ≤ ‖S.adjoint ∘L (S ∘L T).polarPart‖ * T.traceNorm := + T.norm_hsPairing_le_opNorm_mul_traceNorm _ + _ ≤ ‖S.adjoint‖ * ‖(S ∘L T).polarPart‖ * T.traceNorm := by + gcongr + · exact T.traceNorm_nonneg + · exact ContinuousLinearMap.opNorm_comp_le _ _ + _ ≤ ‖S.adjoint‖ * 1 * T.traceNorm := by + gcongr + · exact T.traceNorm_nonneg + · exact (S ∘L T).polarPart_opNorm_le_one + _ = ‖S‖ * T.traceNorm := by + rw [mul_one, ContinuousLinearMap.adjoint.norm_map] + +/-- **Sub-multiplicativity of the trace norm, right form**: +`traceNorm (S ∘L T) ≤ traceNorm S * ‖T‖_op`. Dual of `traceNorm_comp_le`: uses +`hsPairing_comp_right` to move `T` to the second slot as `T.adjoint`. -/ +theorem traceNorm_comp_le' (S : F →L[𝕜] G) (T : E →L[𝕜] F) : + (S ∘L T).traceNorm ≤ S.traceNorm * ‖T‖ := by + have := FiniteDimensional.completeSpace 𝕜 E + have := FiniteDimensional.completeSpace 𝕜 F + have := FiniteDimensional.completeSpace 𝕜 G + rw [← (S ∘L T).re_hsPairing_polarPart_eq_traceNorm, + ContinuousLinearMap.hsPairing_comp_right] + calc RCLike.re (S.hsPairing ((S ∘L T).polarPart ∘L T.adjoint)) + ≤ ‖S.hsPairing ((S ∘L T).polarPart ∘L T.adjoint)‖ := RCLike.re_le_norm _ + _ ≤ ‖(S ∘L T).polarPart ∘L T.adjoint‖ * S.traceNorm := + S.norm_hsPairing_le_opNorm_mul_traceNorm _ + _ ≤ ‖(S ∘L T).polarPart‖ * ‖T.adjoint‖ * S.traceNorm := by + gcongr + · exact S.traceNorm_nonneg + · exact ContinuousLinearMap.opNorm_comp_le _ _ + _ ≤ 1 * ‖T.adjoint‖ * S.traceNorm := by + gcongr + · exact S.traceNorm_nonneg + · exact (S ∘L T).polarPart_opNorm_le_one + _ = S.traceNorm * ‖T‖ := by + rw [one_mul, ContinuousLinearMap.adjoint.norm_map, mul_comm] + +/-- **Trace-norm right-invariance under a linear isometry equivalence**: composing on +the right with a LIE preserves the trace norm. Combines `traceNorm_comp_le'` (forward +≤ via op-norm ≤ 1) with the reverse application on `W.symm` (backward ≤ via the same +bound applied to `T ∘L W.toCLM` and `W.symm`). -/ +theorem traceNorm_compL_linearIsometryEquiv + (T : E →L[𝕜] F) (W : G ≃ₗᵢ[𝕜] E) : + (T ∘L (W : G →L[𝕜] E)).traceNorm = T.traceNorm := by + refine le_antisymm ?_ ?_ + · calc (T ∘L (W : G →L[𝕜] E)).traceNorm + ≤ T.traceNorm * ‖(W : G →L[𝕜] E)‖ := traceNorm_comp_le' _ _ + _ ≤ T.traceNorm * 1 := by + gcongr + · exact T.traceNorm_nonneg + · exact W.toLinearIsometry.norm_toContinuousLinearMap_le + _ = T.traceNorm := mul_one _ + · calc T.traceNorm + = ((T ∘L (W : G →L[𝕜] E)) ∘L (W.symm : E →L[𝕜] G)).traceNorm := by + congr 1; ext x; simp + _ ≤ (T ∘L (W : G →L[𝕜] E)).traceNorm * ‖(W.symm : E →L[𝕜] G)‖ := + traceNorm_comp_le' _ _ + _ ≤ (T ∘L (W : G →L[𝕜] E)).traceNorm * 1 := by + gcongr + · exact (T ∘L _).traceNorm_nonneg + · exact W.symm.toLinearIsometry.norm_toContinuousLinearMap_le + _ = (T ∘L (W : G →L[𝕜] E)).traceNorm := mul_one _ + +/-- **Bundled variational characterization of the trace norm.** The trace norm equals the +supremum over contractions `W` (`‖W‖_op ≤ 1`) of `re (hsPairing T W)`. Combines achievability +(`re_hsPairing_polarPart_eq_traceNorm`, witnessed at `W = polarPart T`) with the Hölder upper +bound (`re_hsPairing_le_traceNorm_of_opNorm_le_one`, established for every contraction). The +pre-bundled halves remain available for proofs that prefer a specific witness over the +`iSup` form. -/ +theorem traceNorm_eq_iSup (T : E →L[𝕜] F) : + T.traceNorm = + ⨆ W : {W : E →L[𝕜] F // ‖W‖ ≤ 1}, RCLike.re (T.hsPairing W.val) := by + have := FiniteDimensional.completeSpace 𝕜 E + have := FiniteDimensional.completeSpace 𝕜 F + have : Nonempty {W : E →L[𝕜] F // ‖W‖ ≤ 1} := ⟨0, by simp⟩ + have hbdd : BddAbove (Set.range + (fun W : {W : E →L[𝕜] F // ‖W‖ ≤ 1} ↦ RCLike.re (T.hsPairing W.val))) := + ⟨T.traceNorm, by rintro _ ⟨W, rfl⟩; exact T.re_hsPairing_le_traceNorm_of_opNorm_le_one W.2⟩ + refine le_antisymm ?_ ?_ + · rw [← T.re_hsPairing_polarPart_eq_traceNorm] + exact le_ciSup hbdd ⟨T.polarPart, T.polarPart_opNorm_le_one⟩ + · exact ciSup_le fun W ↦ T.re_hsPairing_le_traceNorm_of_opNorm_le_one W.2 + +end VariationalCharacterization + +/-- The trace norm of a rank-one operator. Smoke test for the API: the only non-zero +singular value of `rankOne x y` is `‖x‖ * ‖y‖`, so the trace norm equals this product. -/ +theorem traceNorm_rankOne (x : F) (y : E) : + ((InnerProductSpace.rankOne 𝕜 x) y).traceNorm = ‖x‖ * ‖y‖ := by + rw [← traceNorm_toLinearMap, LinearMap.traceNorm_eq] + rcases Nat.eq_zero_or_pos (Module.finrank 𝕜 E) with hE | hE + · -- E is trivial: y = 0, so RHS = 0; LHS is empty sum = 0. + have : Subsingleton E := Module.finrank_zero_iff.mp hE + simp [Subsingleton.eq_zero y] + · -- Singular values past index 0 are zero (rank ≤ 1). + rw [Finset.sum_eq_single (⟨0, hE⟩ : Fin _) + (fun i _ hi ↦ + (LinearMap.singularValues_eq_zero_iff_le_finrank_range _).mpr + ((InnerProductSpace.finrank_range_rankOne_le_one x y).trans + (Nat.one_le_iff_ne_zero.mpr (Fin.val_ne_iff.mpr hi)))) + (fun h ↦ absurd (Finset.mem_univ _) h)] + -- The 0-th singular value equals the operator norm `‖x‖ * ‖y‖`. + rw [← LinearMap.opNorm_eq_singularValues_zero] + exact InnerProductSpace.norm_rankOne x y + +/-- **Trace norm is invariant under conjugation by a linear isometry equivalence.** +Routes through `singularValues_conjStarAlgEquiv` + `Fintype.sum_equiv` to bridge the +`Fin (finrank E)` vs `Fin (finrank F)` summation domains via `Fin.castOrderIso`. -/ +theorem traceNorm_conjStarAlgEquiv [CompleteSpace E] [CompleteSpace F] + (e : E ≃ₗᵢ[𝕜] F) (T : E →L[𝕜] E) : + (e.conjStarAlgEquiv T).traceNorm = T.traceNorm := by + rw [← traceNorm_toLinearMap, ← traceNorm_toLinearMap T, + LinearMap.traceNorm_eq, LinearMap.traceNorm_eq, + singularValues_conjStarAlgEquiv e T] + exact Fintype.sum_equiv (Fin.castOrderIso e.toLinearEquiv.finrank_eq.symm).toEquiv + _ _ (fun _ ↦ rfl) + +end ContinuousLinearMap + +/-! +### Jordan–Hahn decomposition and the trace-norm split + +For a self-adjoint operator `A` on a finite-dimensional complex inner product space, the +continuous functional calculus splits `A = A⁺ - A⁻` into nonnegative parts of orthogonal +support, the operator absolute value coincides with `A⁺ + A⁻`, and the trace norm splits as +`‖A‖₁ = re tr A⁺ + re tr A⁻` (Nielsen & Chuang, Exercise 9.7). + +These are stated over `ℂ`: the operator CFC `posPart`/`negPart` and `CFC.sqrt` require +`CStarAlgebra (E →L[ℂ] E)`, which Mathlib provides only for `ℂ` (real/`RCLike` operator-CFC is +blocked upstream by `spectrum.nonempty`). +-/ + +section JordanDecomposition + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +omit [FiniteDimensional ℂ E] in +/-- **Operator Jordan–Hahn decomposition** (N&C Ex 9.7): a self-adjoint operator splits as +`A = A⁺ - A⁻` into nonnegative parts of orthogonal support (`A⁺ * A⁻ = 0`). -/ +theorem IsSelfAdjoint.jordanDecomposition (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) : + A = A⁺ - A⁻ ∧ (0 ≤ A⁺) ∧ (0 ≤ A⁻) ∧ A⁺ * A⁻ = 0 := + ⟨(CFC.posPart_sub_negPart A hA).symm, CFC.posPart_nonneg A, CFC.negPart_nonneg A, + CFC.posPart_mul_negPart A⟩ + +/-- For self-adjoint `A`, the SVD-based operator absolute value `|A|` +(`ContinuousLinearMap.absoluteValue`) equals the CFC sum `A⁺ + A⁻`. Both are the unique +nonnegative square root of `A† ∘ A`, via `CFC.sqrt_unique`. -/ +theorem IsSelfAdjoint.absoluteValue_eq_posPart_add_negPart (A : E →L[ℂ] E) + (hA : IsSelfAdjoint A) : A.absoluteValue = A⁺ + A⁻ := by + rw [CFC.posPart_add_negPart A] + refine (CFC.sqrt_unique ?_ A.absoluteValue_nonneg).symm + rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.absoluteValue_sq, + ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.mul_def] + +/-- **Trace-norm Jordan split** (N&C Ex 9.7): for self-adjoint `A`, +`‖A‖₁ = re tr A⁺ + re tr A⁻`. -/ +theorem IsSelfAdjoint.traceNorm_eq_re_trace_posPart_add (A : E →L[ℂ] E) (hA : IsSelfAdjoint A) : + A.traceNorm = RCLike.re (LinearMap.trace ℂ E (A⁺ : E →L[ℂ] E)) + + RCLike.re (LinearMap.trace ℂ E (A⁻ : E →L[ℂ] E)) := by + rw [← ContinuousLinearMap.traceNorm_absoluteValue, + IsSelfAdjoint.absoluteValue_eq_posPart_add_negPart A hA] + have hpos : (0 : E →L[ℂ] E) ≤ A⁺ + A⁻ := + add_nonneg (CFC.posPart_nonneg A) (CFC.negPart_nonneg A) + rw [ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive + (ContinuousLinearMap.nonneg_iff_isPositive.mp hpos), + ContinuousLinearMap.toLinearMap_add, map_add, map_add] + +end JordanDecomposition + +section Contractive + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [FiniteDimensional ℂ F] + +/-- **Trace-preserving positive maps contract the trace norm** — the operator-theoretic heart of +Nielsen & Chuang Theorem 9.2. If a `ℂ`-linear superoperator `Φ` between the operator algebras of +two finite-dimensional complex inner product spaces preserves positivity +(`A.IsPositive → (Φ A).IsPositive`) and preserves the trace (`tr (Φ A) = tr A`), then it does not +increase the trace norm of any self-adjoint operator: `‖Φ A‖₁ ≤ ‖A‖₁`. + +The proof splits `A` into its nonnegative Jordan parts `A = A⁺ - A⁻` +(`IsSelfAdjoint.jordanDecomposition`); the triangle inequality gives +`‖Φ A‖₁ = ‖Φ A⁺ - Φ A⁻‖₁ ≤ ‖Φ A⁺‖₁ + ‖Φ A⁻‖₁`. Each of `Φ A⁺`, `Φ A⁻` is positive, so its trace +norm equals its trace (`traceNorm_eq_re_trace_of_isPositive`); trace preservation rewrites these to +`re tr A⁺ + re tr A⁻`, which is exactly `‖A‖₁` for self-adjoint `A` +(`IsSelfAdjoint.traceNorm_eq_re_trace_posPart_add`). Only positivity and trace preservation of `Φ` +are used — complete positivity is not needed. -/ +theorem ContinuousLinearMap.traceNorm_map_le_of_isPositive_of_trace_eq + (Φ : (E →L[ℂ] E) →ₗ[ℂ] (F →L[ℂ] F)) + (hpos : ∀ A : E →L[ℂ] E, A.IsPositive → (Φ A).IsPositive) + (htrace : ∀ A : E →L[ℂ] E, LinearMap.trace ℂ F ↑(Φ A) = LinearMap.trace ℂ E ↑A) + {A : E →L[ℂ] E} (hA : IsSelfAdjoint A) : + (Φ A).traceNorm ≤ A.traceNorm := by + obtain ⟨hAeq, hApos, hAneg, -⟩ := IsSelfAdjoint.jordanDecomposition A hA + have hΦp : (Φ A⁺).IsPositive := hpos _ (ContinuousLinearMap.nonneg_iff_isPositive.mp hApos) + have hΦn : (Φ A⁻).IsPositive := hpos _ (ContinuousLinearMap.nonneg_iff_isPositive.mp hAneg) + have hΦA : Φ A = Φ A⁺ - Φ A⁻ := by rw [← map_sub, ← hAeq] + calc (Φ A).traceNorm + = (Φ A⁺ - Φ A⁻).traceNorm := by rw [hΦA] + _ ≤ (Φ A⁺).traceNorm + (Φ A⁻).traceNorm := ContinuousLinearMap.traceNorm_sub_le _ _ + _ = RCLike.re (LinearMap.trace ℂ F ↑(Φ A⁺)) + RCLike.re (LinearMap.trace ℂ F ↑(Φ A⁻)) := by + rw [ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive hΦp, + ContinuousLinearMap.traceNorm_eq_re_trace_of_isPositive hΦn] + _ = RCLike.re (LinearMap.trace ℂ E ↑A⁺) + RCLike.re (LinearMap.trace ℂ E ↑A⁻) := by + rw [htrace A⁺, htrace A⁻] + _ = A.traceNorm := (IsSelfAdjoint.traceNorm_eq_re_trace_posPart_add A hA).symm + +end Contractive diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Transpose.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Transpose.lean new file mode 100644 index 0000000000..de5a3fb012 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Transpose.lean @@ -0,0 +1,213 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.CFC +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.EuclideanConjVec + +/-! +# Matrix transpose of operators on Euclidean space + +For an operator `T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι`, define the **transpose** +`EuclideanSpace.transposeOp T` as the operator whose matrix in the canonical basis is the +transpose (NOT the conjugate-transpose / adjoint) of `T`'s matrix. Following the +`EuclideanSpace.conjVec` docstring, this is conjugation of the adjoint (`= star`) by the +componentwise complex conjugation `conjVec`: + +`transposeOp T := conjVec ∘ (star T) ∘ conjVec`. + +The basis-dependence is localized to `EuclideanSpace`'s canonical coordinate frame (Mathlib's +idiom for basis-dependent linear algebra, cf. `Matrix.toEuclideanCLM`); an abstract +finite-dimensional space is handled by transporting along an `OrthonormalBasis.repr`. + +## Main results + +- `EuclideanSpace.transposeOp`, `transposeOp_apply`: the definition. +- `transposeOp_transposeOp`: `transposeOp (transposeOp T) = T` (involution). +- `transposeOp_mul`: anti-multiplicativity. +- `transposeOp_spectrum`: preserves the real spectrum. +- `transposeOp_isSelfAdjoint`, `transposeOp_isStrictlyPositive`: preservation. +- `cfc_transposeOp`: commutes with `cfc` on self-adjoint operators. + +## Motivation + +This packages the structural infrastructure for the **Choi–Jamiołkowski bridge** in Lieb's +Theorem 1 (trace form): `⟨choiVec K, mapL A B (choiVec K)⟩ = Tr(K† A K · transposeOp B)`, where +the transpose (not adjoint) appears because the Choi pairing is the Frobenius/Hadamard trace. The +trace form follows from the v-form by reparametrizing `B → transposeOp B`, which needs the +CFC-commute `(transposeOp B)^r = transposeOp (B^r)` (`cfc_transposeOp`). +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace EuclideanSpace + +variable {ι : Type*} [Fintype ι] + +local notation "𝒞" => EuclideanSpace.conjVec + +/-- The transpose of an operator on `EuclideanSpace ℂ ι`: conjugation of the adjoint (`star`) by +the componentwise complex conjugation, `conjVec ∘ (star T) ∘ conjVec`. Its matrix in the canonical +basis is the transpose (not conjugate-transpose) of `T`'s. -/ +noncomputable def transposeOp (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι := + LinearMap.toContinuousLinearMap + { toFun := fun x ↦ 𝒞 (star T (𝒞 x)) + map_add' := fun x y ↦ by simp [map_add] + map_smul' := fun c x ↦ by simp [conjVec_smul, map_smul] } + +@[simp] theorem transposeOp_apply (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (x : EuclideanSpace ℂ ι) : + transposeOp T x = 𝒞 (star T (𝒞 x)) := rfl + +/-- The adjoint (`star`) commutes with the transpose: `star (transposeOp T) = transposeOp (star T)`. +Proved via the `conjVec` anti-isometry: both sides pair to `(⟪𝒞 v, T (𝒞 z)⟫)⋆`. -/ +theorem star_transposeOp (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + star (transposeOp T) = transposeOp (star T) := by + refine ContinuousLinearMap.ext fun z ↦ ext_inner_left ℂ fun v ↦ ?_ + have hL : ⟪𝒞 (star T (𝒞 v)), z⟫_ℂ = star ⟪𝒞 v, T (𝒞 z)⟫_ℂ := by + conv_lhs => rw [← conjVec_conjVec z] + rw [inner_conjVec, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_inner_left] + have hR : ⟪v, 𝒞 (T (𝒞 z))⟫_ℂ = star ⟪𝒞 v, T (𝒞 z)⟫_ℂ := by + conv_lhs => rw [← conjVec_conjVec v] + rw [inner_conjVec] + rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_right, + transposeOp_apply, transposeOp_apply, star_star, hL, hR] + +/-- Involution: `transposeOp (transposeOp T) = T`. -/ +theorem transposeOp_transposeOp (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + transposeOp (transposeOp T) = T := by + ext x + rw [transposeOp_apply, star_transposeOp, transposeOp_apply, conjVec_conjVec, star_star, + conjVec_conjVec] + +@[simp] theorem transposeOp_add (T S : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + transposeOp (T + S) = transposeOp T + transposeOp S := by + ext x; simp [star_add] + +@[simp] theorem transposeOp_smul (c : ℂ) (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + transposeOp (c • T) = c • transposeOp T := by + ext x; simp [star_smul, conjVec_smul] + +@[simp] theorem transposeOp_zero : + transposeOp (0 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) = 0 := by + ext x; simp + +@[simp] theorem transposeOp_one : + transposeOp (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) = 1 := by + ext x; simp [conjVec_conjVec] + +/-- The transpose is **anti-multiplicative**: +`transposeOp (X * Y) = transposeOp Y * transposeOp X`. -/ +theorem transposeOp_mul (X Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + transposeOp (X * Y) = transposeOp Y * transposeOp X := by + ext x + simp only [transposeOp_apply, star_mul, mul_apply_eq_comp, conjVec_conjVec] + +/-- The transpose preserves invertibility: the inverse of `transposeOp B` is `transposeOp B⁻¹`. -/ +theorem transposeOp_isUnit {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hB : IsUnit B) : + IsUnit (transposeOp B) := by + obtain ⟨u, rfl⟩ := hB + exact ⟨⟨transposeOp ↑u, transposeOp ↑u⁻¹, + by rw [← transposeOp_mul, u.inv_mul, transposeOp_one], + by rw [← transposeOp_mul, u.mul_inv, transposeOp_one]⟩, rfl⟩ + +/-- Invertibility transfers in both directions across the transpose (via the involution). -/ +theorem transposeOp_isUnit_iff (B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + IsUnit (transposeOp B) ↔ IsUnit B := + ⟨fun h ↦ transposeOp_transposeOp B ▸ transposeOp_isUnit h, transposeOp_isUnit⟩ + +@[simp] theorem transposeOp_sub (X Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + transposeOp (X - Y) = transposeOp X - transposeOp Y := by + ext x; simp [star_sub] + +@[simp] theorem transposeOp_algebraMap (r : ℝ) : + transposeOp (algebraMap ℝ (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) r) = + algebraMap ℝ (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) r := by + rw [Algebra.algebraMap_eq_smul_one, ← Complex.coe_smul, transposeOp_smul, transposeOp_one, + Complex.coe_smul] + +/-- **The transpose preserves the real spectrum.** Used to transport the `ContinuousOn`-on-spectrum +hypothesis of the CFC in `cfc_transposeOp`. -/ +theorem transposeOp_spectrum (B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + spectrum ℝ (transposeOp B) = spectrum ℝ B := by + ext r + simp only [spectrum.mem_iff] + rw [show algebraMap ℝ _ r - transposeOp B = transposeOp (algebraMap ℝ _ r - B) by + rw [transposeOp_sub, transposeOp_algebraMap], transposeOp_isUnit_iff] + +/-- **Eigenvector correspondence**: for self-adjoint `Y`, +`transposeOp Y (conjVec v) = conjVec (Y v)`. -/ +theorem transposeOp_apply_conjVec {Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hY : IsSelfAdjoint Y) (v : EuclideanSpace ℂ ι) : + transposeOp Y (𝒞 v) = 𝒞 (Y v) := by + rw [transposeOp_apply, conjVec_conjVec, hY.star_eq] + +/-- `conjVec` of an eigenvector of self-adjoint `Y` (real eigenvalue `μ`) is an eigenvector of +`transposeOp Y` with the same eigenvalue. -/ +theorem transposeOp_conjVec_eq_smul {Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hY : IsSelfAdjoint Y) {v : EuclideanSpace ℂ ι} {μ : ℝ} (hv : Y v = (μ : ℂ) • v) : + transposeOp Y (𝒞 v) = (μ : ℂ) • 𝒞 v := by + rw [transposeOp_apply_conjVec hY, hv, conjVec_smul, Complex.star_def, Complex.conj_ofReal] + +/-- The transpose preserves self-adjointness (`star_transposeOp`). -/ +theorem transposeOp_isSelfAdjoint {Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hY : IsSelfAdjoint Y) : IsSelfAdjoint (transposeOp Y) := by + change star (transposeOp Y) = transposeOp Y + rw [star_transposeOp, hY.star_eq] + +/-- The transpose preserves nonnegativity (Loewner order): conjugation by the antiunitary +`conjVec` preserves positivity, `⟪x, transposeOp B x⟫ = (⟪conjVec x, B (conjVec x)⟫)⋆ ≥ 0`. -/ +theorem transposeOp_nonneg {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hB : 0 ≤ B) : + 0 ≤ transposeOp B := by + rw [ContinuousLinearMap.nonneg_iff_isPositive] at hB ⊢ + have hBsa : IsSelfAdjoint B := ContinuousLinearMap.isSelfAdjoint_iff_isSymmetric.mpr hB.1 + refine ⟨(transposeOp_isSelfAdjoint hBsa).isSymmetric, fun x ↦ ?_⟩ + have key : (transposeOp B).reApplyInnerSelf x = B.reApplyInnerSelf (𝒞 x) := by + rw [ContinuousLinearMap.reApplyInnerSelf_apply, ContinuousLinearMap.reApplyInnerSelf_apply, + transposeOp_apply, hBsa.star_eq, conjVec_inner, RCLike.star_def, RCLike.conj_re] + rw [key] + exact hB.2 (𝒞 x) + +/-- The transpose preserves strict positivity. -/ +theorem transposeOp_isStrictlyPositive {B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} + (hB : IsStrictlyPositive B) : IsStrictlyPositive (transposeOp B) := + ⟨transposeOp_nonneg hB.nonneg, transposeOp_isUnit hB.isUnit⟩ + +/-- **CFC commutes with the transpose** on self-adjoint operators: +`cfc f (transposeOp Y) = transposeOp (cfc f Y)`. Specialized to `f = (· ^ r)` this is the +`(transposeOp B)^r = transposeOp (B^r)` reparametrization for the trace-form Lieb T1. + +Proof: conjugated eigenvectors `conjVec eₖ` of `Y` are eigenvectors of `transposeOp Y` with the +same real eigenvalue (`transposeOp_conjVec_eq_smul`); spectral mapping makes both sides act as +`f λₖ` on them, and they span (the conjugate of an eigenbasis). -/ +theorem cfc_transposeOp {Y : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι} (hY : IsSelfAdjoint Y) + {f : ℝ → ℝ} (hf : ContinuousOn f (spectrum ℝ Y)) : + cfc f (transposeOp Y) = transposeOp (cfc f Y) := by + obtain ⟨n, hn⟩ : ∃ n, Module.finrank ℂ (EuclideanSpace ℂ ι) = n := ⟨_, rfl⟩ + have hYT := transposeOp_isSelfAdjoint hY + have hcfcY : IsSelfAdjoint (cfc f Y) := cfc_predicate f Y + have hfT : ContinuousOn f (spectrum ℝ (transposeOp Y)) := by + rw [transposeOp_spectrum]; exact hf + set e := hY.isSymmetric.eigenvectorBasis hn + set lam := hY.isSymmetric.eigenvalues hn + have hkey : ∀ k, cfc f (transposeOp Y) (𝒞 (e k)) = transposeOp (cfc f Y) (𝒞 (e k)) := fun k ↦ by + have heig : Y (e k) = (lam k : ℂ) • e k := hY.apply_eigenvectorBasis_cast hn k + rw [hYT.cfc_apply_smul_of_apply_eq_smul hn hfT (transposeOp_conjVec_eq_smul hY heig), + transposeOp_apply_conjVec hcfcY, hY.cfc_apply_smul_of_apply_eq_smul hn hf heig, + conjVec_smul, Complex.star_def, Complex.conj_ofReal] + refine ContinuousLinearMap.ext fun x ↦ ?_ + rw [← conjVec_conjVec x, ← e.sum_repr' (𝒞 x), conjVec_sum] + simp only [conjVec_smul, map_sum, ContinuousLinearMap.map_smul] + exact Finset.sum_congr rfl fun k _ ↦ by rw [hkey k] + +end EuclideanSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Uhlmann.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Uhlmann.lean new file mode 100644 index 0000000000..82c900a20b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/Uhlmann.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarUnitary +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Purification +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TraceNorm + +/-! +# Uhlmann's theorem (Nielsen–Chuang Theorem 9.4), operator form + +For positive operators `ρ, σ` on a finite-dimensional complex inner product space `E`, the +**fidelity trace norm** `‖√ρ √σ‖₁` is the *greatest* overlap `‖⟪Ψ, Φ⟫‖` achievable between a +purification `Ψ` of `ρ` and a purification `Φ` of `σ` into the doubled space `E ⊗ E`: + + `IsGreatest {‖⟪Ψ, Φ⟫‖ | IsPurification ρ Ψ ∧ IsPurification σ Φ} ‖√ρ √σ‖₁`. + +This is the operator-level core of Nielsen–Chuang Theorem 9.4 (Uhlmann's theorem). The +restatement for states — `F(ρ, σ) = max |⟨ψ|φ⟩|` over purifications, with `F` the +`State.fidelity` — is in `AxQM/NC/Ch9`. + +## Proof outline + +A purification `Ψ` of `ρ` corresponds, under the matricization isomorphism +`matricize b : E ⊗ E ≃ (E →L E)`, to an operator `M := matricize b Ψ` with `M M† = ρ` +(`isPurification_iff_matricize_comp_adjoint`), and the overlap becomes the Hilbert–Schmidt +pairing `⟪Ψ, Φ⟫ = hsPairing N M` (`matricize_inner_eq_hsPairing`), `N := matricize b Φ`. + +* **Factorization** (`eq_cfc_sqrt_comp_unitary`): `M M† = ρ ⟹ M = √ρ V` for a *unitary* `V`. + Indeed `|M†| = √(M M†) = √ρ`, and the left unitary polar decomposition of `M†` + (`exists_mem_unitary_eq_comp_absoluteValue`) gives `M† = U √ρ`, hence `M = √ρ U†`. +* **Upper bound.** With `M = √ρ V`, `N = √σ W`, the pairing rewrites (via `hsPairing_comp_*` + and `hsPairing_conj`) to `(√ρ √σ).hsPairing (V W†)`, and `V W†` is a unitary contraction, + so `‖⟪Ψ, Φ⟫‖ ≤ ‖√ρ √σ‖₁` by `norm_hsPairing_le_traceNorm_of_opNorm_le_one` (Lemma 9.5). +* **Achievement.** Taking `M = √ρ` and `N = √σ U†` where `√ρ √σ = U |√ρ √σ|` is the polar + decomposition, both `M M† = ρ` and `N N† = σ` hold, and + `⟪Ψ, Φ⟫ = tr(√ρ √σ U†) = tr|√ρ √σ| = ‖√ρ √σ‖₁`, attaining the bound. +-/ + +open scoped InnerProductSpace +open ContinuousLinearMap + +@[expose] public section + +noncomputable section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + +namespace ContinuousLinearMap + +omit [FiniteDimensional ℂ E] in +/-- The **CFC real square root of an operator is self-adjoint**, `(√a)† = √a`: a +real-valued functional-calculus image is self-adjoint (`IsSelfAdjoint.cfc`), spelled through +`star = adjoint`. -/ +theorem adjoint_cfc_real_sqrt (a : E →L[ℂ] E) : + adjoint (cfc Real.sqrt a) = cfc Real.sqrt a := by + rw [← star_eq_adjoint]; exact IsSelfAdjoint.cfc + +omit [FiniteDimensional ℂ E] in +/-- A **unitary operator is a contraction**, `‖U‖ ≤ 1`: from the C⋆-identity +`‖U‖² = ‖U† U‖ = ‖1‖ ≤ 1`. -/ +theorem opNorm_le_one_of_mem_unitary {U : E →L[ℂ] E} + (hU : U ∈ unitary (E →L[ℂ] E)) : ‖U‖ ≤ 1 := by + have hsq : ‖U‖ * ‖U‖ = ‖(1 : E →L[ℂ] E)‖ := by + rw [← CStarRing.norm_star_mul_self, (Unitary.mem_iff.mp hU).1] + have h1 : ‖(1 : E →L[ℂ] E)‖ ≤ 1 := by + rw [ContinuousLinearMap.one_def]; exact norm_id_le + nlinarith [norm_nonneg U] + +/-- **Factorization of a self-outer-product** (the operator core of Uhlmann's theorem): if +`M M† = ρ`, then `M = √ρ V` for some *unitary* `V`. The absolute value of `M†` is +`|M†| = √(M M†) = √ρ`, so the left unitary polar decomposition `M† = U |M†|` +(`exists_mem_unitary_eq_comp_absoluteValue`) reads `M† = U √ρ`; taking adjoints gives +`M = √ρ U†` with `V := U†` unitary. -/ +theorem eq_cfc_sqrt_comp_unitary {ρ M : E →L[ℂ] E} (h : M.comp (adjoint M) = ρ) : + ∃ V ∈ unitary (E →L[ℂ] E), M = (cfc Real.sqrt ρ).comp V := by + obtain ⟨U, hU, hUeq⟩ := exists_mem_unitary_eq_comp_absoluteValue (adjoint M) + have habs : (adjoint M).absoluteValue = cfc Real.sqrt ρ := by + rw [absoluteValue_eq_cfc_sqrt, adjoint_adjoint, h] + refine ⟨adjoint U, ?_, ?_⟩ + · rw [← star_eq_adjoint]; exact Unitary.star_mem hU + · have hM := congrArg adjoint hUeq + rw [adjoint_adjoint, habs, adjoint_comp, adjoint_cfc_real_sqrt] at hM + exact hM + +end ContinuousLinearMap + +namespace TensorProduct + +/-- **Uhlmann's theorem (operator form), Nielsen–Chuang Theorem 9.4.** For positive operators +`ρ, σ` on a finite-dimensional complex inner product space `E`, the trace norm `‖√ρ √σ‖₁` is the +greatest overlap `‖⟪Ψ, Φ⟫‖` over purifications `Ψ` of `ρ` and `Φ` of `σ` into `E ⊗ E`. -/ +theorem isGreatest_norm_inner_of_isPurification {ρ σ : E →L[ℂ] E} (hρ : 0 ≤ ρ) (hσ : 0 ≤ σ) : + IsGreatest + {r : ℝ | ∃ Ψ Φ : TensorProduct ℂ E E, + TensorProduct.IsPurification ρ Ψ ∧ TensorProduct.IsPurification σ Φ ∧ + r = ‖(inner ℂ Ψ Φ : ℂ)‖} + (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm := by + set b := stdOrthonormalBasis ℂ E + set p : E →L[ℂ] E := cfc Real.sqrt ρ + set q : E →L[ℂ] E := cfc Real.sqrt σ + have hpsa : adjoint p = p := adjoint_cfc_real_sqrt ρ + have hqsa : adjoint q = q := adjoint_cfc_real_sqrt σ + have hpp : p * p = ρ := cfc_real_sqrt_mul_self_of_nonneg hρ + have hqq : q * q = σ := cfc_real_sqrt_mul_self_of_nonneg hσ + constructor + · -- Achievement: choose `M = √ρ`, `N = √σ U†` with `√ρ √σ = U |√ρ √σ|`. + obtain ⟨U, hU, hUeq⟩ := exists_mem_unitary_eq_comp_absoluteValue (p * q) + have hUU : adjoint U * U = 1 := by rw [← star_eq_adjoint]; exact (Unitary.mem_iff.mp hU).1 + refine ⟨(matricize b).symm p, (matricize b).symm (q.comp (adjoint U)), ?_, ?_, ?_⟩ + · -- `IsPurification ρ Ψ*`: `√ρ (√ρ)† = √ρ √ρ = ρ`. + rw [isPurification_iff_matricize_comp_adjoint b, LinearEquiv.apply_symm_apply, hpsa] + exact hpp + · -- `IsPurification σ Φ*`: `(√σ U†)(√σ U†)† = √σ (U† U) √σ = √σ √σ = σ`. + rw [isPurification_iff_matricize_comp_adjoint b, LinearEquiv.apply_symm_apply] + have hadj : adjoint (q.comp (adjoint U)) = U.comp q := by + rw [adjoint_comp, adjoint_adjoint, hqsa] + rw [hadj] + change q * adjoint U * (U * q) = σ + rw [mul_assoc q (adjoint U) (U * q), ← mul_assoc (adjoint U) U q, hUU, one_mul, hqq] + · -- Value: `⟪Ψ*, Φ*⟫ = tr(√ρ √σ U†) = tr|√ρ √σ| = ‖√ρ √σ‖₁`. + rw [matricize_inner_eq_hsPairing b _ _, LinearEquiv.apply_symm_apply, + LinearEquiv.apply_symm_apply, hsPairing_eq, hpsa] + have hUU' : U.adjoint ∘L U = 1 := hUU + set A := (p * q).absoluteValue with hA + have hUeq' : p * q = U * A := hUeq + have e1 : p.comp (q.comp (adjoint U)) = U ∘L A ∘L U.adjoint := by + change p * (q * adjoint U) = U * (A * adjoint U) + rw [← mul_assoc, hUeq', mul_assoc] + rw [e1, trace_conj_isometry hUU' A, hA, toLinearMap_absoluteValue, + ← LinearMap.ofReal_traceNorm_eq_trace_absoluteValue, RCLike.norm_ofReal, + abs_of_nonneg (LinearMap.traceNorm_nonneg _)] + exact (traceNorm_toLinearMap _).symm + · -- Upper bound: any overlap is `≤ ‖√ρ √σ‖₁`. + rintro r ⟨Ψ, Φ, hΨ, hΦ, rfl⟩ + rw [isPurification_iff_matricize_comp_adjoint b] at hΨ hΦ + obtain ⟨V, hV, hMV⟩ := eq_cfc_sqrt_comp_unitary hΨ + obtain ⟨W, hW, hNW⟩ := eq_cfc_sqrt_comp_unitary hΦ + have hcontr : ‖V.comp (adjoint W)‖ ≤ 1 := by + refine opNorm_le_one_of_mem_unitary ?_ + have hVW : V.comp (adjoint W) = V * star W := by rw [← star_eq_adjoint]; rfl + rw [hVW] + exact mul_mem hV (Unitary.star_mem hW) + rw [matricize_inner_eq_hsPairing b Ψ Φ, hMV, hNW, + ← hsPairing_conj (p.comp V) (q.comp W), norm_star, hsPairing_comp_left, hpsa, + ← comp_assoc, ← hsPairing_conj ((p.comp q).comp W) V, norm_star, hsPairing_comp_right] + exact norm_hsPairing_le_traceNorm_of_opNorm_le_one _ hcontr + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannAncilla.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannAncilla.lean new file mode 100644 index 0000000000..823c12369e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannAncilla.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Uhlmann +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Polar + +/-! +# Uhlmann's theorem into an arbitrary ancilla (upper-bound direction) + +The operator core of Uhlmann's theorem +(`TensorProduct.isGreatest_norm_inner_of_isPurification`, Nielsen–Chuang Theorem 9.4) is stated +for purifications into the *doubled* space `E ⊗ E`. Several results — most notably +the **monotonicity of the fidelity** under a quantum operation (N&C Theorem 9.6) — need to +compare the fidelity trace norm `‖√ρ √σ‖₁` against the overlap of purifications living in a +*larger* ancilla `E ⊗ F` (the reference enlarged by a channel's environment). This file records +the **upper-bound half of Uhlmann's theorem for an arbitrary ancilla**: + + `‖⟪Ψ, Φ⟫‖ ≤ ‖√ρ √σ‖₁` for any purifications `Ψ` of `ρ`, `Φ` of `σ` into `E ⊗ F`. + +The achievement half (that `‖√ρ √σ‖₁` is *attained*) is already available in the doubled space +`E ⊗ E` (`isGreatest_norm_inner_of_isPurification`), which is enough for the applications: one +achieves the bound in `E ⊗ E` and bounds the transported overlap in the larger space. + +## Main results + +* `ContinuousLinearMap.eq_cfc_sqrt_comp_contraction` — the **rectangular factorization** + `M M† = ρ ⟹ M = √ρ V` with `V` a *contraction* (`‖V‖ ≤ 1`), for `M : F →L E`. The + square-ancilla version (`Uhlmann.eq_cfc_sqrt_comp_unitary`) produces a *unitary* `V`; here the + rectangular polar decomposition (`polar_decomposition`, `polarPart_opNorm_le_one`) gives a + partial isometry, hence a contraction. +* `ContinuousLinearMap.norm_hsPairing_le_traceNorm_cfc_sqrt_mul` — the operator form of the + bound: `‖N.hsPairing M‖ ≤ ‖√ρ √σ‖₁` whenever `M M† = ρ` and `N N† = σ` (for `M N : F →L E`). +* `TensorProduct.norm_inner_le_traceNorm_of_isPurification` — the purification form: + `‖⟪Ψ, Φ⟫‖ ≤ ‖√ρ √σ‖₁` for `Ψ` a purification of `ρ`, `Φ` a purification of `σ` into `E ⊗ F`. + +## Proof + +Both `M M† = ρ` and `N N† = σ` factor as `M = √ρ V`, `N = √σ W` with `‖V‖, ‖W‖ ≤ 1`; then the +pairing rewrites (via `hsPairing_conj`/`hsPairing_comp_left`/`hsPairing_comp_right`, exactly as in +the `E ⊗ E` proof) to `(√ρ √σ).hsPairing (V W†)`, and `V W†` is a contraction, so the Hölder bound +`norm_hsPairing_le_traceNorm_of_opNorm_le_one` (Lemma 9.5) closes it. The purification form is the +operator form transported through the matricization isomorphism +(`matricize_inner_eq_hsPairing`, `isPurification_iff_matricize_comp_adjoint`). +-/ + +open scoped InnerProductSpace +open ContinuousLinearMap + +@[expose] public section + +noncomputable section + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [FiniteDimensional ℂ F] [CompleteSpace F] + +/-- **Rectangular factorization of a self-outer-product.** If `M M† = ρ` for `M : F →L E`, then +`M = √ρ V` for a *contraction* `V : F →L E` (`‖V‖ ≤ 1`). This is the rectangular counterpart of +`ContinuousLinearMap.eq_cfc_sqrt_comp_unitary` (which needs `M` square and delivers a unitary): +`|M†| = √(M M†) = √ρ`, and the (rectangular) polar decomposition `M† = U √ρ` with `U` a partial +isometry (`polar_decomposition`) gives `M = √ρ U†`, where `V := U†` is a contraction +(`polarPart_opNorm_le_one`). -/ +theorem eq_cfc_sqrt_comp_contraction {ρ : E →L[ℂ] E} {M : F →L[ℂ] E} + (h : M.comp (adjoint M) = ρ) : + ∃ V : F →L[ℂ] E, ‖V‖ ≤ 1 ∧ M = (cfc Real.sqrt ρ).comp V := by + -- `|M†|² = M M† = ρ`, and the positive square root is unique, so `|M†| = √ρ`. + have hsq : (adjoint M).absoluteValue.comp (adjoint M).absoluteValue = ρ := by + rw [absoluteValue_sq, adjoint_adjoint]; exact h + have habs : (adjoint M).absoluteValue = cfc Real.sqrt ρ := by + rw [← hsq, ← ContinuousLinearMap.mul_def, + cfc_real_sqrt_mul_self_eq_self_of_nonneg (adjoint M).absoluteValue_nonneg] + -- Rectangular polar of `M†`: `M† = polarPart(M†) ∘ √ρ`; take adjoints to get `M = √ρ ∘ V`. + have hpolar : adjoint M = (adjoint M).polarPart.comp (cfc Real.sqrt ρ) := by + rw [← habs]; exact polar_decomposition (adjoint M) + refine ⟨adjoint (adjoint M).polarPart, ?_, ?_⟩ + · rw [ContinuousLinearMap.adjoint.norm_map] + exact polarPart_opNorm_le_one _ + · have hM := congrArg adjoint hpolar + rw [adjoint_adjoint, adjoint_comp, adjoint_cfc_real_sqrt] at hM + exact hM + +/-- **Uhlmann upper bound, operator form.** For `M N : F →L E` with `M M† = ρ` and `N N† = σ`, +the Hilbert–Schmidt pairing is bounded by the fidelity trace norm: +`‖N.hsPairing M‖ ≤ ‖√ρ √σ‖₁`. Factoring `M = √ρ V`, `N = √σ W` with `V, W` contractions +(`eq_cfc_sqrt_comp_contraction`), the pairing rewrites to `(√ρ √σ).hsPairing (V W†)` with `V W†` +a contraction, whence the Hölder bound `norm_hsPairing_le_traceNorm_of_opNorm_le_one`. -/ +theorem norm_hsPairing_le_traceNorm_cfc_sqrt_mul {ρ σ : E →L[ℂ] E} {M N : F →L[ℂ] E} + (hM : M.comp (adjoint M) = ρ) (hN : N.comp (adjoint N) = σ) : + ‖N.hsPairing M‖ ≤ (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm := by + obtain ⟨V, hV, hMV⟩ := eq_cfc_sqrt_comp_contraction hM + obtain ⟨W, hW, hNW⟩ := eq_cfc_sqrt_comp_contraction hN + set p : E →L[ℂ] E := cfc Real.sqrt ρ + set q : E →L[ℂ] E := cfc Real.sqrt σ + have hpsa : adjoint p = p := adjoint_cfc_real_sqrt ρ + have hcontr : ‖V.comp (adjoint W)‖ ≤ 1 := by + calc ‖V.comp (adjoint W)‖ ≤ ‖V‖ * ‖adjoint W‖ := opNorm_comp_le _ _ + _ ≤ 1 * 1 := by + rw [ContinuousLinearMap.adjoint.norm_map]; gcongr + _ = 1 := one_mul 1 + rw [hMV, hNW, + ← hsPairing_conj (p.comp V) (q.comp W), norm_star, hsPairing_comp_left, hpsa, + ← comp_assoc, ← hsPairing_conj ((p.comp q).comp W) V, norm_star, hsPairing_comp_right] + exact norm_hsPairing_le_traceNorm_of_opNorm_le_one _ hcontr + +end ContinuousLinearMap + +namespace TensorProduct + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [FiniteDimensional ℂ F] [CompleteSpace F] + +/-- **Uhlmann upper bound into an arbitrary ancilla, purification form** (Nielsen–Chuang Theorem +9.4, upper-bound half). For positive operators `ρ, σ` on `E` and *any* ancilla `F`, the overlap +of a purification `Ψ` of `ρ` with a purification `Φ` of `σ` into `E ⊗ F` is at most the fidelity +trace norm: + + `‖⟪Ψ, Φ⟫‖ ≤ ‖√ρ √σ‖₁`. + +This generalizes the doubled-space bound in `isGreatest_norm_inner_of_isPurification` from the +canonical ancilla `E ⊗ E` to an arbitrary `E ⊗ F` — the form needed to bound the overlap of +purifications transported into a channel's (system ⊗ environment ⊗ reference) space, in the proof +of the monotonicity of the fidelity (N&C Theorem 9.6). Through the matricization isomorphism it is +`norm_hsPairing_le_traceNorm_cfc_sqrt_mul` applied to `M := matricize b Ψ`, `N := matricize b Φ`, +which satisfy `M M† = ρ`, `N N† = σ` by `isPurification_iff_matricize_comp_adjoint`. -/ +theorem norm_inner_le_traceNorm_of_isPurification {ρ σ : E →L[ℂ] E} + {Ψ Φ : TensorProduct ℂ E F} + (hΨ : TensorProduct.IsPurification ρ Ψ) (hΦ : TensorProduct.IsPurification σ Φ) : + ‖(inner ℂ Ψ Φ : ℂ)‖ ≤ (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm := by + set b := stdOrthonormalBasis ℂ F + rw [isPurification_iff_matricize_comp_adjoint b] at hΨ hΦ + rw [matricize_inner_eq_hsPairing b Ψ Φ] + exact ContinuousLinearMap.norm_hsPairing_le_traceNorm_cfc_sqrt_mul hΨ hΦ + +end TensorProduct diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannMixture.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannMixture.lean new file mode 100644 index 0000000000..eb8583d511 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UhlmannMixture.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.UhlmannAncilla +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorBlockRow + +/-! +# Maximizing factorizations for the fidelity trace norm (Uhlmann achievement, real overlap) + +Uhlmann's theorem (`TensorProduct.isGreatest_norm_inner_of_isPurification`, Nielsen–Chuang +Theorem 9.4) asserts that the fidelity trace norm `‖√ρ √σ‖₁` is the *greatest* overlap +`‖⟪Ψ, Φ⟫‖` over purifications `Ψ` of `ρ`, `Φ` of `σ` into `E ⊗ E`; the greatest element is in +particular *attained*. The attained overlap is only known up to a phase (`IsGreatest` records +`‖⟪Ψ, Φ⟫‖`, a norm). This file records the **phase-aligned** achievement: there is a maximizing +pair whose overlap is *real and equal* to `‖√ρ √σ‖₁`. + +These are the per-component data from which the joint purification of a probabilistic mixture is +assembled in the proof of the **strong concavity of the fidelity** (N&C Theorem 9.7): +`F(∑ᵢ pᵢ ρᵢ, ∑ᵢ qᵢ σᵢ) ≥ ∑ᵢ √(pᵢ qᵢ) F(ρᵢ, σᵢ)`. The joint purification's overlap is +`∑ᵢ √(pᵢ qᵢ) ⟪ψᵢ, φᵢ⟫`, and for that sum to *equal* `∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁` (rather than merely +bound it) each term `⟪ψᵢ, φᵢ⟫` must be a nonnegative real — which is exactly what the phase +alignment below secures. + +## Main results + +* `ContinuousLinearMap.exists_hsPairing_eq_traceNorm_cfc_sqrt_mul` — **operator form.** For positive + `ρ, σ` on `E` there exist `M, N : E →L E` with `M M† = ρ`, `N N† = σ`, and Hilbert–Schmidt + pairing `N.hsPairing M = ‖√ρ √σ‖₁` (as a real, i.e. `(· : ℂ)`, value). This is the direct partner + of `ContinuousLinearMap.norm_hsPairing_le_traceNorm_cfc_sqrt_mul` (the upper bound): together they + give equality for the maximizing factorization. +* `TensorProduct.exists_isPurification_inner_eq_traceNorm_cfc_sqrt_mul` — **purification form.** The + same statement phrased with purifications `Ψ, Φ` into `E ⊗ E` and their overlap `⟪Ψ, Φ⟫`. + +## Proof + +From the achievement half of `isGreatest_norm_inner_of_isPurification` we obtain purifications with +`‖⟪Ψ, Φ⟫‖ = ‖√ρ √σ‖₁`; matricizing (`matricize`, `isPurification_iff_matricize_comp_adjoint`, +`matricize_inner_eq_hsPairing`) turns them into operators `M, N` with `M M† = ρ`, `N N† = σ` and +`‖N.hsPairing M‖ = ‖√ρ √σ‖₁`. Multiplying `N` by the unit-modulus phase `‖z‖ / z`, where +`z := N.hsPairing M` (a no-op when `z = 0`), leaves `N N† = σ` unchanged (`|c|² = 1`) and rotates +the pairing to the nonnegative real `‖z‖ = ‖√ρ √σ‖₁` (`hsPairing_smul_left`). The purification +form is the operator form transported back through the matricization isomorphism. +-/ + +open scoped InnerProductSpace TensorProduct +open ContinuousLinearMap + +@[expose] public section + +noncomputable section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [CompleteSpace E] + +namespace ContinuousLinearMap + +/-- **Maximizing factorization for the fidelity trace norm, operator form.** For positive operators +`ρ, σ` on a finite-dimensional complex inner product space `E`, there are operators `M, N : E →L E` +with `M M† = ρ`, `N N† = σ`, and Hilbert–Schmidt pairing exactly the fidelity trace norm: +`N.hsPairing M = (‖√ρ √σ‖₁ : ℂ)`. + +This is the phase-aligned achievement half of Uhlmann's theorem: the upper bound +`norm_hsPairing_le_traceNorm_cfc_sqrt_mul` shows `‖N.hsPairing M‖ ≤ ‖√ρ √σ‖₁` for *every* +factorization, and here the bound is attained with a real, nonnegative pairing. The witnesses are +the matricized maximizing purifications from `isGreatest_norm_inner_of_isPurification`, with `N` +rotated +by a unit phase so that the overlap becomes real. -/ +theorem exists_hsPairing_eq_traceNorm_cfc_sqrt_mul {ρ σ : E →L[ℂ] E} (hρ : 0 ≤ ρ) (hσ : 0 ≤ σ) : + ∃ M N : E →L[ℂ] E, M.comp (adjoint M) = ρ ∧ N.comp (adjoint N) = σ ∧ + N.hsPairing M = ((cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm : ℂ) := by + set b := stdOrthonormalBasis ℂ E + obtain ⟨Ψ, Φ, hΨ, hΦ, htn⟩ := + (TensorProduct.isGreatest_norm_inner_of_isPurification hρ hσ).1 + set M := TensorProduct.matricize b Ψ + set N := TensorProduct.matricize b Φ + have hM : M.comp (adjoint M) = ρ := + (TensorProduct.isPurification_iff_matricize_comp_adjoint b ρ Ψ).mp hΨ + have hN : N.comp (adjoint N) = σ := + (TensorProduct.isPurification_iff_matricize_comp_adjoint b σ Φ).mp hΦ + have hpair : N.hsPairing M = (inner ℂ Ψ Φ : ℂ) := + (TensorProduct.matricize_inner_eq_hsPairing b Ψ Φ).symm + set tn := (cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm with htndef + have hz : ‖N.hsPairing M‖ = tn := by rw [hpair, ← htn] + rcases eq_or_ne (N.hsPairing M) 0 with hzero | hnz + · -- Degenerate case `‖√ρ √σ‖₁ = 0`: the unrotated factorization already works. + refine ⟨M, N, hM, hN, ?_⟩ + have htn0 : tn = 0 := by rw [← hz, hzero, norm_zero] + rw [hzero, htn0, Complex.ofReal_zero] + · -- Rotate `N` by the unit phase `tn / z`, `z := N.hsPairing M`. + have htnpos : tn ≠ 0 := by rw [← hz]; exact norm_ne_zero_iff.mpr hnz + have hc1 : ‖((tn : ℂ) / N.hsPairing M)‖ = 1 := by + rw [norm_div, Complex.norm_real, hz, + Real.norm_of_nonneg (ContinuousLinearMap.traceNorm_nonneg _), div_self htnpos] + refine ⟨M, ((tn : ℂ) / N.hsPairing M) • N, hM, ?_, ?_⟩ + · -- `(cN)(cN)† = |c|² (N N†) = N N† = σ`. + rw [← star_eq_adjoint, star_smul, star_eq_adjoint, + ContinuousLinearMap.smul_comp, ContinuousLinearMap.comp_smul, smul_smul, hN] + have hcc : ((tn : ℂ) / N.hsPairing M) * star ((tn : ℂ) / N.hsPairing M) = 1 := by + rw [← starRingEnd_apply, Complex.mul_conj, Complex.normSq_eq_norm_sq, hc1]; norm_num + rw [hcc, one_smul] + · -- `(cN).hsPairing M = c · z = (tn / z) · z = tn`. + rw [hsPairing_smul_left, div_mul_cancel₀ _ hnz] + +end ContinuousLinearMap + +namespace TensorProduct + +/-- **Maximizing purifications for the fidelity trace norm, purification form.** For positive +operators `ρ, σ` on a finite-dimensional complex inner product space `E`, there are purifications +`Ψ` of `ρ` and `Φ` of `σ` into `E ⊗ E` whose overlap is exactly the fidelity trace norm: +`⟪Ψ, Φ⟫ = (‖√ρ √σ‖₁ : ℂ)` (a nonnegative real). + +This is the phase-aligned refinement of the achievement half of +`isGreatest_norm_inner_of_isPurification` (which only records `‖⟪Ψ, Φ⟫‖ = ‖√ρ √σ‖₁`). It is the +operator form `ContinuousLinearMap.exists_hsPairing_eq_traceNorm_cfc_sqrt_mul` transported through +the matricization isomorphism. -/ +theorem exists_isPurification_inner_eq_traceNorm_cfc_sqrt_mul {ρ σ : E →L[ℂ] E} + (hρ : 0 ≤ ρ) (hσ : 0 ≤ σ) : + ∃ Ψ Φ : TensorProduct ℂ E E, + TensorProduct.IsPurification ρ Ψ ∧ TensorProduct.IsPurification σ Φ ∧ + (inner ℂ Ψ Φ : ℂ) = ((cfc Real.sqrt ρ * cfc Real.sqrt σ).traceNorm : ℂ) := by + obtain ⟨M, N, hM, hN, hpair⟩ := + ContinuousLinearMap.exists_hsPairing_eq_traceNorm_cfc_sqrt_mul hρ hσ + set b := stdOrthonormalBasis ℂ E + refine ⟨(matricize b).symm M, (matricize b).symm N, ?_, ?_, ?_⟩ + · rw [isPurification_iff_matricize_comp_adjoint b, LinearEquiv.apply_symm_apply]; exact hM + · rw [isPurification_iff_matricize_comp_adjoint b, LinearEquiv.apply_symm_apply]; exact hN + · rw [matricize_inner_eq_hsPairing b, LinearEquiv.apply_symm_apply, LinearEquiv.apply_symm_apply] + exact hpair + +end TensorProduct + +/-! ## Operator-level strong concavity of the fidelity + +The proof of the strong concavity of the fidelity (N&C Theorem 9.7) assembles the per-component +maximizing factorizations `Mᵢ Mᵢ† = ρᵢ`, `Nᵢ Nᵢ† = σᵢ` (from +`exists_hsPairing_eq_traceNorm_cfc_sqrt_mul`) into a **block-row operator** +(`ContinuousLinearMap.blockRow`, `ToMathlib/Analysis/InnerProductSpace/OperatorBlockRow.lean`) on +the +enlarged ancilla `E ⊗ ℂ^ι`: the map `M : E ⊗ ℂ^ι →L E` whose `j`-th column is `√pⱼ Mⱼ`, i.e. +`M (x ⊗ eⱼ) = √pⱼ Mⱼ x`. Its self-outer-product `M M†` is the mixture `∑ⱼ pⱼ ρⱼ` +(`blockRow_comp_adjoint`; the columns are orthogonal, so cross terms vanish), and the +Hilbert–Schmidt pairing of the two block-rows collapses to the diagonal sum +`∑ᵢ √(pᵢ qᵢ) ⟨Nᵢ, Mᵢ⟩_HS` (`hsPairing_blockRow`). Feeding these into the general-ancilla Uhlmann +upper bound `norm_hsPairing_le_traceNorm_cfc_sqrt_mul` yields the operator-level inequality +`∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁ ≤ ‖√(∑ᵢ pᵢ ρᵢ) √(∑ᵢ qᵢ σᵢ)‖₁`. +-/ + +namespace ContinuousLinearMap + +/-- **Strong concavity of the fidelity trace norm, operator form** (the operator core of +Nielsen–Chuang Theorem 9.7). For finite families of positive operators `ρ, σ : ι → (E →L[ℂ] E)` and +non-negative weights `p, q : ι → ℝ`, +`∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁ ≤ ‖√(∑ᵢ pᵢ ρᵢ) √(∑ᵢ qᵢ σᵢ)‖₁`. +No normalization `∑ pᵢ = ∑ qᵢ = 1` is needed; the probability hypotheses enter only when this is +lifted to the fidelity of *states* (`State.fidelity`). + +Proof (N&C p. 414): for each `i` pick maximizing factorizations `Mᵢ Mᵢ† = ρᵢ`, `Nᵢ Nᵢ† = σᵢ` with +`Nᵢ.hsPairing Mᵢ = ‖√ρᵢ √σᵢ‖₁` a non-negative real (`exists_hsPairing_eq_traceNorm_cfc_sqrt_mul`). +Assemble the block-rows `M = blockRow b (√pᵢ Mᵢ)`, `N = blockRow b (√qᵢ Nᵢ)` on the ancilla +`E ⊗ ℂ^ι`. Then `M M† = ∑ᵢ pᵢ ρᵢ`, `N N† = ∑ᵢ qᵢ σᵢ` (`blockRow_comp_adjoint`), and +`N.hsPairing M = ∑ᵢ √(pᵢ qᵢ) ‖√ρᵢ √σᵢ‖₁` (`hsPairing_blockRow`), a non-negative real. The +general-ancilla Uhlmann upper bound `norm_hsPairing_le_traceNorm_cfc_sqrt_mul` gives +`‖N.hsPairing M‖ ≤ ‖√(∑ pᵢ ρᵢ) √(∑ qᵢ σᵢ)‖₁`, and `‖·‖` of the non-negative real overlap is the +overlap itself. -/ +theorem traceNorm_cfc_sqrt_mul_cfc_sqrt_sum_ge {ι : Type*} [Fintype ι] + (ρ σ : ι → E →L[ℂ] E) (hρ : ∀ i, 0 ≤ ρ i) (hσ : ∀ i, 0 ≤ σ i) + (p q : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hq : ∀ i, 0 ≤ q i) : + ∑ i, Real.sqrt (p i * q i) * (cfc Real.sqrt (ρ i) * cfc Real.sqrt (σ i)).traceNorm + ≤ (cfc Real.sqrt (∑ i, (p i : ℂ) • ρ i) + * cfc Real.sqrt (∑ i, (q i : ℂ) • σ i)).traceNorm := by + classical + have : CompleteSpace (E ⊗[ℂ] EuclideanSpace ℂ ι) := FiniteDimensional.completeSpace ℂ _ + set b := EuclideanSpace.basisFun ι ℂ with hb + -- Per-component maximizing factorizations with real overlap. + choose M N hM hN hpair using fun i => + ContinuousLinearMap.exists_hsPairing_eq_traceNorm_cfc_sqrt_mul (hρ i) (hσ i) + set M' : ι → E →L[ℂ] E := fun i => (Real.sqrt (p i) : ℂ) • M i with hM' + set N' : ι → E →L[ℂ] E := fun i => (Real.sqrt (q i) : ℂ) • N i with hN' + -- `M M† = ∑ pᵢ ρᵢ`: block-row of `√pᵢ`-scaled columns is the `pᵢ`-mixture (`|√pᵢ|² = pᵢ`). + have hMbig : (blockRow b M') ∘L adjoint (blockRow b M') = ∑ i, (p i : ℂ) • ρ i := by + rw [hM', blockRow_smul_comp_adjoint] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, Real.mul_self_sqrt (hp i), + hM i] + -- `N N† = ∑ qᵢ σᵢ`. + have hNbig : (blockRow b N') ∘L adjoint (blockRow b N') = ∑ i, (q i : ℂ) • σ i := by + rw [hN', blockRow_smul_comp_adjoint] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [Complex.star_def, Complex.conj_ofReal, ← Complex.ofReal_mul, Real.mul_self_sqrt (hq i), + hN i] + -- The joint overlap is the (non-negative real) diagonal sum. + have hpairbig : (blockRow b N').hsPairing (blockRow b M') + = ((∑ i, Real.sqrt (p i * q i) + * (cfc Real.sqrt (ρ i) * cfc Real.sqrt (σ i)).traceNorm : ℝ) : ℂ) := by + rw [hsPairing_blockRow, Complex.ofReal_sum] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [hN', hM', hsPairing_smul_left, hsPairing_smul_right, hpair i, Complex.star_def, + Complex.conj_ofReal, Real.sqrt_mul (hp i)] + push_cast + ring + -- Feed the block-rows into the general-ancilla Uhlmann upper bound. + have hub := ContinuousLinearMap.norm_hsPairing_le_traceNorm_cfc_sqrt_mul hMbig hNbig + rw [hpairbig, Complex.norm_real, Real.norm_of_nonneg] at hub + · exact hub + · exact Finset.sum_nonneg fun i _ => mul_nonneg (Real.sqrt_nonneg _) + (ContinuousLinearMap.traceNorm_nonneg _) + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryExtension.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryExtension.lean new file mode 100644 index 0000000000..7dc9bb675f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryExtension.lean @@ -0,0 +1,79 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PiL2 +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.LinearMap + +/-! +# Unitary extension of an inner-product-preserving map on a subspace + +Let `V` be a finite-dimensional inner product space over an `RCLike` field `𝕜` and let `W` be a +subspace of `V`. If a linear map `U : W → V` *preserves inner products*, that is +`⟪U w₁, U w₂⟫ = ⟪w₁, w₂⟫` for all `w₁, w₂ ∈ W`, then `U` extends to a **unitary** operator on all +of `V` — a linear isometry equivalence `V ≃ₗᵢ[𝕜] V` agreeing with `U` on `W`. + +This is Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 2.67 (used there +to realise an arbitrary measurement via unitary dynamics on an enlarged system). It is pure linear +algebra: an inner-product-preserving map from a subspace is an isometry onto its (equidimensional) +image, and in finite dimensions the orthogonal complements of the domain and the image have equal +dimension, so the isometry can be completed to a unitary of the whole space. + +## Main results + +* `LinearMap.unitaryExtend`: the unitary extension `V ≃ₗᵢ[𝕜] V` of an inner-product-preserving + `U : W →ₗ[𝕜] V`. +* `LinearMap.unitaryExtend_apply`: the extension agrees with `U` on `W`. +* `LinearMap.exists_unitaryExtend`: the existence statement of Exercise 2.67 — there is a unitary + `U' : V ≃ₗᵢ[𝕜] V` with `U' w = U w` for every `w ∈ W`. + +## Implementation notes + +The construction is the composite of three existing pieces: `LinearMap.isometryOfInner` packages an +inner-product-preserving linear map as a `LinearIsometry`, `LinearIsometry.extend` extends a linear +isometry of a subspace to a linear isometry of the whole (finite-dimensional) space, and +`LinearIsometry.toLinearIsometryEquiv` upgrades a linear isometry between equidimensional +finite-dimensional spaces to a linear isometry equivalence (here the space and its extension +coincide, so the dimension hypothesis is `rfl`). +-/ + +open scoped InnerProductSpace + +@[expose] public section + +variable {𝕜 : Type*} [RCLike 𝕜] {V : Type*} [NormedAddCommGroup V] [InnerProductSpace 𝕜 V] + [FiniteDimensional 𝕜 V] {W : Submodule 𝕜 V} + +namespace LinearMap + +/-- The **unitary extension** of an inner-product-preserving linear map `U : W → V` on a subspace +`W` of a finite-dimensional inner product space `V`: a linear isometry equivalence `V ≃ₗᵢ[𝕜] V` +that agrees with `U` on `W` (Nielsen & Chuang, Exercise 2.67). -/ +noncomputable def unitaryExtend (U : W →ₗ[𝕜] V) + (hU : ∀ w₁ w₂ : W, ⟪U w₁, U w₂⟫_𝕜 = ⟪w₁, w₂⟫_𝕜) : V ≃ₗᵢ[𝕜] V := + ((U.isometryOfInner hU).extend).toLinearIsometryEquiv rfl + +/-- The unitary extension `U.unitaryExtend` agrees with `U` on the subspace `W`. -/ +@[simp] +theorem unitaryExtend_apply (U : W →ₗ[𝕜] V) + (hU : ∀ w₁ w₂ : W, ⟪U w₁, U w₂⟫_𝕜 = ⟪w₁, w₂⟫_𝕜) (w : W) : + U.unitaryExtend hU w = U w := by + simp only [unitaryExtend, LinearIsometry.coe_toLinearIsometryEquiv, + LinearIsometry.extend_apply, LinearMap.coe_isometryOfInner] + +/-- **Nielsen & Chuang, Exercise 2.67.** A linear map `U : W → V` on a subspace `W` of a +finite-dimensional inner product space `V` that preserves inner products extends to a unitary +operator on all of `V`: there is a linear isometry equivalence `U' : V ≃ₗᵢ[𝕜] V` with `U' w = U w` +for every `w ∈ W`. -/ +theorem exists_unitaryExtend (U : W →ₗ[𝕜] V) + (hU : ∀ w₁ w₂ : W, ⟪U w₁, U w₂⟫_𝕜 = ⟪w₁, w₂⟫_𝕜) : + ∃ U' : V ≃ₗᵢ[𝕜] V, ∀ w : W, U' w = U w := + ⟨U.unitaryExtend hU, U.unitaryExtend_apply hU⟩ + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryTwirl.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryTwirl.lean new file mode 100644 index 0000000000..407763b683 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/UnitaryTwirl.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.PolarNormal + +/-! +# The dephasing twirl: sign conjugation projects an operator onto its diagonal + +Fix an orthonormal basis `b = {bᵢ}` of a finite-dimensional inner product space `E`. For a sign +pattern `ε : ι → Bool` the **sign-diagonal unitary** is the diagonal operator + +`signDiagonal ε = ∑ᵢ (-1)^{ε i} • |bᵢ⟩⟨bᵢ|`, + +a self-adjoint unitary (each diagonal entry is `±1`). Conjugating an arbitrary operator `A` by all +`2^{|ι|}` sign-diagonal unitaries and summing **projects `A` onto its basis-diagonal**: + +`∑_{ε : ι → Bool} (signDiagonal ε) A (signDiagonal ε)† = 2^{|ι|} • ∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|`. + +Equivalently, the **completely dephasing channel** (the uniform average of the sign conjugations) +equals the diagonal projection `A ↦ ∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|`. Entrywise this is the elementary +character identity `∑_{ε} (-1)^{ε p}(-1)^{ε q} = 2^{|ι|} · [p = q]`: summing the sign phases kills +every off-diagonal entry `⟨b_p, A b_q⟩` (`p ≠ q`) and leaves the diagonal untouched. + +This is the **first stage** of the mixed-unitary (twirl) realisation of the completely depolarizing +channel `A ↦ tr(A)·I/d` (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 11.19). The dephasing average makes `A` diagonal; a subsequent average over the basis +permutations equalises the diagonal to `tr(A)/d`. Because both averages are convex combinations of +unitary conjugations, the depolarizing channel is a mixed-unitary channel, and monotonicity of the +quantum relative entropy under such channels +(`ContinuousLinearMap.quantumRelativeEntropy_sum_conjStarAlgEquiv_le`) then yields its monotonicity +under the partial trace — the bridge to the strong subadditivity of the von Neumann entropy (N&C +Theorem 11.14). + +## Main definitions + +* `OrthonormalBasis.signDiagonal` — the sign-diagonal unitary `∑ᵢ (-1)^{ε i} • |bᵢ⟩⟨bᵢ|`. + +## Main results + +* `OrthonormalBasis.diagonalOperator_apply_self`, `OrthonormalBasis.inner_diagonalOperator`, + `OrthonormalBasis.ext_inner_basis` — reusable basis-computation helpers for `diagonalOperator`. +* `OrthonormalBasis.signDiagonal_mem_unitary`, `OrthonormalBasis.signDiagonal_adjoint` — the + sign-diagonal operator is a self-adjoint unitary. +* `OrthonormalBasis.sum_signDiagonal_conj_self` / `OrthonormalBasis.sum_signDiagonal_conj` — the + dephasing-twirl identity `∑_ε (signDiagonal ε) A (signDiagonal ε)(†) = 2^{|ι|} • (diagonal of A)`. +* `OrthonormalBasis.dephasing_average` — the average form: the completely dephasing channel is the + diagonal projection. +-/ + +@[expose] public section + +open Module InnerProductSpace ContinuousLinearMap + +namespace OrthonormalBasis + +variable {ι 𝕜 E : Type*} [RCLike 𝕜] [Fintype ι] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] (b : OrthonormalBasis ι 𝕜 E) + +/-- **Action of a diagonal operator on a basis vector**: `(∑ᵢ wᵢ |bᵢ⟩⟨bᵢ|)(b q) = w q • b q`. -/ +theorem diagonalOperator_apply_self (w : ι → 𝕜) (q : ι) : + b.diagonalOperator w (b q) = w q • b q := by + rw [diagonalOperator, _root_.sum_apply, Finset.sum_eq_single q] + · rw [_root_.smul_apply, rankOne_apply, b.inner_eq_one, one_smul] + · intro i _ hi + rw [_root_.smul_apply, rankOne_apply, b.inner_eq_zero hi, zero_smul, smul_zero] + · intro h; exact absurd (Finset.mem_univ q) h + +/-- **Inner product of a basis vector with a diagonal operator applied to any vector**: +`⟨b p, (∑ᵢ wᵢ |bᵢ⟩⟨bᵢ|) v⟩ = w p · ⟨b p, v⟩`. -/ +theorem inner_diagonalOperator (w : ι → 𝕜) (p : ι) (v : E) : + inner 𝕜 (b p) (b.diagonalOperator w v) = w p * inner 𝕜 (b p) v := by + rw [diagonalOperator, _root_.sum_apply, inner_sum, Finset.sum_eq_single p] + · rw [_root_.smul_apply, rankOne_apply, inner_smul_right, inner_smul_right, + b.inner_eq_one, mul_one] + · intro i _ hi + rw [_root_.smul_apply, rankOne_apply, inner_smul_right, inner_smul_right, + b.inner_eq_zero (Ne.symm hi), mul_zero, mul_zero] + · intro h; exact absurd (Finset.mem_univ p) h + +/-- **Extensionality via basis matrix entries**: two operators agreeing on every entry +`⟨b p, · (b q)⟩` are equal. -/ +theorem ext_inner_basis {S T : E →L[𝕜] E} + (h : ∀ p q, inner 𝕜 (b p) (S (b q)) = inner 𝕜 (b p) (T (b q))) : S = T := by + refine ContinuousLinearMap.coe_injective (b.toBasis.ext fun q => ?_) + have hq : S (b q) = T (b q) := by + rw [← b.sum_repr' (S (b q)), ← b.sum_repr' (T (b q))] + simp_rw [h] + simpa using hq + +/-- The **sign-diagonal unitary** for a sign pattern `ε`: `∑ᵢ (-1)^{ε i} • |bᵢ⟩⟨bᵢ|`, the diagonal +operator with `±1` diagonal entries. It is a self-adjoint unitary (`signDiagonal_mem_unitary`, +`signDiagonal_adjoint`), and averaging over all sign patterns dephases (`sum_signDiagonal_conj`). -/ +noncomputable def signDiagonal (ε : ι → Bool) : E →L[𝕜] E := + b.diagonalOperator (fun i => if ε i then (-1 : 𝕜) else 1) + +/-- The sign-diagonal operator acts on `b q` by the scalar `(-1)^{ε q}`. -/ +theorem signDiagonal_apply_self (ε : ι → Bool) (q : ι) : + b.signDiagonal ε (b q) = (if ε q then (-1 : 𝕜) else 1) • b q := by + simp only [signDiagonal, diagonalOperator_apply_self] + +/-- Inner product of a basis vector with the sign-diagonal operator applied to any vector. -/ +theorem inner_signDiagonal (ε : ι → Bool) (p : ι) (v : E) : + inner 𝕜 (b p) (b.signDiagonal ε v) = (if ε p then (-1 : 𝕜) else 1) * inner 𝕜 (b p) v := by + simp only [signDiagonal, inner_diagonalOperator] + +section CompleteSpace + +variable [CompleteSpace E] + +/-- The sign-diagonal operator is **self-adjoint** (its `±1` diagonal is real). -/ +theorem signDiagonal_adjoint (ε : ι → Bool) : + adjoint (b.signDiagonal ε) = b.signDiagonal ε := by + simp only [signDiagonal, diagonalOperator_adjoint] + congr 1 + funext i + simp only [Pi.star_apply] + cases ε i <;> simp + +/-- The sign-diagonal operator is **unitary** (its diagonal entries have modulus `1`). -/ +theorem signDiagonal_mem_unitary (ε : ι → Bool) : + b.signDiagonal ε ∈ unitary (E →L[𝕜] E) := by + refine b.diagonalOperator_mem_unitary _ fun i => ?_ + cases ε i <;> simp + +end CompleteSpace + +section DecidableEq + +variable [DecidableEq ι] + +/-- **The sign character identity**: `∑_{ε : ι → Bool} (-1)^{ε p} (-1)^{ε q} = 2^{|ι|} · [p = q]`. +For `p = q` every term is `1`; for `p ≠ q` flipping the `p`-th sign is a fixed-point-free involution +negating each term, so the sum vanishes. -/ +private theorem sum_sign_mul_sign (p q : ι) : + ∑ ε : ι → Bool, (if ε p then (-1 : 𝕜) else 1) * (if ε q then (-1 : 𝕜) else 1) + = if p = q then (2 : 𝕜) ^ Fintype.card ι else 0 := by + by_cases hpq : p = q + · subst hpq + have h1 : ∀ ε : ι → Bool, + (if ε p then (-1 : 𝕜) else 1) * (if ε p then (-1 : 𝕜) else 1) = 1 := fun ε => by + cases ε p <;> simp + rw [Finset.sum_congr rfl fun ε _ => h1 ε, Finset.sum_const, Finset.card_univ, + Fintype.card_fun, Fintype.card_bool, ite_eq_left rfl, nsmul_eq_mul, mul_one] + push_cast + ring + · rw [ite_eq_right hpq] + set g : (ι → Bool) → 𝕜 := + fun ε => (if ε p then (-1 : 𝕜) else 1) * (if ε q then (-1 : 𝕜) else 1) with hg + set f : (ι → Bool) → ι → Bool := fun ε => Function.update ε p (! ε p) with hf + have hf_inv : Function.Involutive f := by + intro ε + funext j + by_cases hj : j = p + · subst hj; simp [hf] + · simp [hf, Function.update_of_ne hj] + have hswap : ∀ ε, g (f ε) = -(g ε) := by + intro ε + have hp : f ε p = ! ε p := by simp [hf] + have hq : f ε q = ε q := by simp [hf, Function.update_of_ne (Ne.symm hpq)] + simp only [hg, hp, hq] + cases ε p <;> cases ε q <;> simp + have key : (∑ ε : ι → Bool, g ε) = -∑ ε : ι → Bool, g ε := + calc (∑ ε, g ε) = ∑ ε, g (f ε) := (Equiv.sum_comp hf_inv.toPerm g).symm + _ = ∑ ε, -(g ε) := Finset.sum_congr rfl fun ε _ => hswap ε + _ = -∑ ε, g ε := by rw [Finset.sum_neg_distrib] + exact self_eq_neg.mp key + +/-- **The dephasing twirl projects onto the diagonal (self-adjoint form)**: summing the sign +conjugations `(signDiagonal ε) A (signDiagonal ε)` over all `2^{|ι|}` sign patterns gives +`2^{|ι|}` times the diagonal part `∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|` of `A`. -/ +theorem sum_signDiagonal_conj_self (A : E →L[𝕜] E) : + ∑ ε : ι → Bool, b.signDiagonal ε ∘L A ∘L b.signDiagonal ε + = (2 : 𝕜) ^ Fintype.card ι • b.diagonalOperator (fun i => inner 𝕜 (b i) (A (b i))) := by + refine b.ext_inner_basis fun p q => ?_ + rw [_root_.sum_apply, inner_sum] + have hterm : ∀ ε : ι → Bool, + inner 𝕜 (b p) ((b.signDiagonal ε ∘L A ∘L b.signDiagonal ε) (b q)) + = (if ε p then (-1 : 𝕜) else 1) * (if ε q then (-1 : 𝕜) else 1) + * inner 𝕜 (b p) (A (b q)) := by + intro ε + rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply, b.inner_signDiagonal, + b.signDiagonal_apply_self, map_smul, inner_smul_right] + ring + simp_rw [hterm] + rw [← Finset.sum_mul, sum_sign_mul_sign p q, _root_.smul_apply, inner_smul_right, + b.inner_diagonalOperator, b.inner_eq_ite] + by_cases hpq : p = q + · subst hpq; simp + · simp [hpq] + +end DecidableEq + +section Twirl + +variable [DecidableEq ι] [CompleteSpace E] + +/-- **The dephasing twirl projects onto the diagonal**: summing the unitary conjugations +`(signDiagonal ε) A (signDiagonal ε)†` over all `2^{|ι|}` sign patterns gives `2^{|ι|}` times the +diagonal part `∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|` of `A`. The genuine mixed-unitary (twirl) form, obtained +from `sum_signDiagonal_conj_self` and self-adjointness of the sign-diagonal unitary. -/ +theorem sum_signDiagonal_conj (A : E →L[𝕜] E) : + ∑ ε : ι → Bool, b.signDiagonal ε ∘L A ∘L adjoint (b.signDiagonal ε) + = (2 : 𝕜) ^ Fintype.card ι • b.diagonalOperator (fun i => inner 𝕜 (b i) (A (b i))) := by + simp_rw [b.signDiagonal_adjoint] + exact b.sum_signDiagonal_conj_self A + +/-- **The completely dephasing channel is the diagonal projection.** The uniform average of the +`2^{|ι|}` sign conjugations of `A` equals its basis-diagonal `∑ᵢ ⟨bᵢ, A bᵢ⟩ • |bᵢ⟩⟨bᵢ|`. -/ +theorem dephasing_average (A : E →L[𝕜] E) : + ((2 : 𝕜) ^ Fintype.card ι)⁻¹ • + ∑ ε : ι → Bool, b.signDiagonal ε ∘L A ∘L adjoint (b.signDiagonal ε) + = b.diagonalOperator (fun i => inner 𝕜 (b i) (A (b i))) := by + rw [b.sum_signDiagonal_conj, smul_smul, + inv_mul_cancel₀ (pow_ne_zero _ (by norm_num : (2 : 𝕜) ≠ 0)), one_smul] + +end Twirl + +end OrthonormalBasis diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropy.lean new file mode 100644 index 0000000000..6e73ef45e0 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropy.lean @@ -0,0 +1,457 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Density +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.IdempotentDensityOp +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.TensorPower +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# Von Neumann entropy of an operator + +For a continuous linear operator `T : E →L[𝕜] E` on a finite-dimensional inner product space +over `𝕜` (where `𝕜` is `ℝ` or `ℂ`), the **von Neumann entropy** of `T` is the Shannon entropy +(in nats) of its eigenvalue spectrum: + +`vonNeumannEntropy T := Real.entropy (eigenvalues T)` + +with junk values on operators that are not self-adjoint (where the spectral decomposition +doesn't yield real eigenvalues uniformly). Mathematically meaningful for positive operators +and natural to interpret on **density operators** (positive trace-1 operators), where the +spectrum is a probability distribution and the entropy is bounded by `log (finrank 𝕜 E)`. + +## Main definitions + +- `ContinuousLinearMap.vonNeumannEntropy : (E →L[𝕜] E) → ℝ` + +## Main results + +- `vonNeumannEntropy_of_isSymmetric`: closed form on self-adjoint operators. +- `IsDensityOp.vonNeumannEntropy_nonneg`: nonneg on density operators. +- `IsDensityOp.vonNeumannEntropy_le_log_dim`: upper bound `log (finrank 𝕜 E)` on density + operators of nontrivial dimension; tight for the maximally mixed state. +- `vonNeumannEntropy_rankOne_self`: a rank-one self-projector `rankOne 𝕜 v v` (with + `‖v‖ = 1`) has zero entropy. +- `LinearMap.vonNeumannEntropy`: LM-level sibling (parallel def + rfl-bridge to CLM). +- `LinearMap.IsSymmetric.vonNeumannEntropy_tensorPow_of_sum_eigenvalues_eq_one`: tensor-iid + scaling for symmetric operators whose eigenvalues sum to 1 — `(A ^⊗ n).vonNeumannEntropy = + n * A.vonNeumannEntropy`. The density-operator case is `IsDensityOp.vonNeumannEntropy_tensorPow`. +- `IsDensityOp.vonNeumannEntropy_le_neg_sum_spectral_log`: **Operator Klein's inequality** + (Nielsen–Chuang Theorem 11.7, real-level spectral form) — for density operators + `ρ, σ` with `σ` having all-positive eigenvalues, `S(ρ) ≤ -∑ᵢ pᵢ * ∑ⱼ ‖⟨fⱼ, eᵢ⟩‖² * log qⱼ` + where `(pᵢ, eᵢ)` and `(qⱼ, fⱼ)` are the spectral data of `ρ` and `σ`. +- `IsDensityOp.vonNeumannEntropy_le_neg_re_trace_cfc_log_comp`: **Trace form of operator + Klein** — `S(ρ) ≤ -re(tr((cfc log σ) ∘ ρ))`. Natural shape for combining via trace + linearity (consumed by concavity). +- `IsDensityOp.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy`: **Self-trace expansion** — + `re(tr((cfc log σ) ∘ σ)) = -S(σ)`. Trace of σ against its own log equals negative entropy. +- `IsDensityOp.vonNeumannEntropy_convex_combination_le`: **Concavity of vNE** (NC Theorem + 11.8) — for a mixture `σ = ∑ᵢ pᵢ ρᵢ` of density operators with `σ`'s eigenvalues positive, + `∑ᵢ pᵢ S(ρᵢ) ≤ S(σ)`. NC §11.3.5's textbook trace-form chain. +-/ + +@[expose] public section + +open scoped InnerProductSpace TensorProduct + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + +open scoped Classical in +/-- The **von Neumann entropy** of an operator: the Shannon entropy of its eigenvalue +spectrum if self-adjoint, with a junk value of `0` otherwise. -/ +noncomputable def vonNeumannEntropy (T : E →L[𝕜] E) : ℝ := + if h : T.toLinearMap.IsSymmetric + then Real.entropy fun i : Fin (Module.finrank 𝕜 E) ↦ h.eigenvalues rfl i + else 0 + +/-- Closed form for the von Neumann entropy on a self-adjoint operator. -/ +theorem vonNeumannEntropy_of_isSymmetric {T : E →L[𝕜] E} + (h : T.toLinearMap.IsSymmetric) : + T.vonNeumannEntropy = Real.entropy fun i : Fin (Module.finrank 𝕜 E) ↦ h.eigenvalues rfl i := by + rw [vonNeumannEntropy, dite_eq_left h] + +theorem vonNeumannEntropy_of_not_isSymmetric {T : E →L[𝕜] E} + (h : ¬ T.toLinearMap.IsSymmetric) : + T.vonNeumannEntropy = 0 := by + rw [vonNeumannEntropy, dite_eq_right h] + +/-- The von Neumann entropy of a density operator is non-negative. -/ +theorem IsDensityOp.vonNeumannEntropy_nonneg {T : E →L[𝕜] E} (h : T.IsDensityOp) : + 0 ≤ T.vonNeumannEntropy := by + rw [vonNeumannEntropy_of_isSymmetric h.isSymmetric] + exact Real.entropy_nonneg + (fun i ↦ h.eigenvalues_nonneg rfl i) + (fun i ↦ h.eigenvalues_le_one rfl i) + +/-- The von Neumann entropy of a density operator on a nontrivial space is at most +`log (finrank 𝕜 E)`. The bound is tight for the maximally mixed state. -/ +theorem IsDensityOp.vonNeumannEntropy_le_log_dim [Nontrivial E] {T : E →L[𝕜] E} + (h : T.IsDensityOp) : + T.vonNeumannEntropy ≤ Real.log (Module.finrank 𝕜 E) := by + rw [vonNeumannEntropy_of_isSymmetric h.isSymmetric] + have : Nonempty (Fin (Module.finrank 𝕜 E)) := + Fin.pos_iff_nonempty.mp Module.finrank_pos + simpa using Real.entropy_le_log_card + (fun i ↦ h.eigenvalues_nonneg rfl i) + (h.eigenvalues_sum_eq_one rfl) + +/-- The von Neumann entropy of a rank-one self-projector `rankOne 𝕜 v v` (with `‖v‖ = 1`) +is zero. In the quantum-information interpretation, this is the entropy of a pure state. -/ +theorem vonNeumannEntropy_rankOne_self {v : E} (hv : ‖v‖ = 1) : + (InnerProductSpace.rankOne 𝕜 v v).vonNeumannEntropy = 0 := by + have hsymm := InnerProductSpace.isSymmetric_rankOne_self v (𝕜 := 𝕜) + rw [vonNeumannEntropy_of_isSymmetric hsymm, Real.entropy_eq] + refine Finset.sum_eq_zero fun i _ ↦ ?_ + rcases (ContinuousLinearMap.IsIdempotentElem.toLinearMap + (InnerProductSpace.isIdempotentElem_rankOne_self hv)).eigenvalues_zero_or_one hsymm rfl i + with hi | hi <;> simp [hi] + +/-- Helper: the von Neumann entropy of a self-adjoint operator equals the entropy of its +eigenvalue sequence under any choice of finrank-witness `hn`, not just `rfl`. This lets us +align the index types when comparing entropies on different (but equi-dimensional) spaces. -/ +lemma vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq {T : E →L[𝕜] E} + (h : T.toLinearMap.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) : + T.vonNeumannEntropy = Real.entropy fun i : Fin n ↦ h.eigenvalues hn i := by + subst hn + exact vonNeumannEntropy_of_isSymmetric h + +/-- **Isometry invariance of von Neumann entropy.** Conjugating an operator by a linear +isometry preserves the eigenvalue spectrum (via charpoly invariance under linear-equiv +conjugation), hence preserves the von Neumann entropy. -/ +theorem vonNeumannEntropy_conjStarAlgEquiv [CompleteSpace E] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + [CompleteSpace F] (e : E ≃ₗᵢ[𝕜] F) (T : E →L[𝕜] E) : + (e.conjStarAlgEquiv T).vonNeumannEntropy = T.vonNeumannEntropy := by + have hSA_iff := T.toLinearMap.isSymmetric_linearIsometryEquiv_conj_iff e + have hfinrank : Module.finrank 𝕜 F = Module.finrank 𝕜 E := e.toLinearEquiv.finrank_eq.symm + by_cases h : T.toLinearMap.IsSymmetric + · have hconj : (e.conjStarAlgEquiv T).toLinearMap.IsSymmetric := hSA_iff.mpr h + rw [vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq hconj hfinrank, + vonNeumannEntropy_of_isSymmetric h, + (hconj.eigenvalues_eq_eigenvalues_iff hfinrank h rfl).mpr + (e.toLinearEquiv.charpoly_conj T.toLinearMap)] + · rw [vonNeumannEntropy_of_not_isSymmetric h, + vonNeumannEntropy_of_not_isSymmetric (h ∘ hSA_iff.mp)] + +/-- **Operator Klein's inequality** (Nielsen–Chuang Theorem 11.7, real-level spectral form): +for density operators `ρ, σ : E →L[ℂ] E` with `σ`'s eigenvalues all positive, the von Neumann +entropy of `ρ` is bounded above by the negation of `tr(ρ log σ)`'s spectral expansion: +``` +ρ.vonNeumannEntropy ≤ -∑ᵢ pᵢ * ∑ⱼ ‖⟨fⱼ, eᵢ⟩‖² * log qⱼ +``` +where `(pᵢ, eᵢ)` and `(qⱼ, fⱼ)` are the eigenvalue/eigenvector pairs of `ρ` and `σ`. The RHS +is the spectral form of `-RCLike.re (tr((cfc log σ) ∘ ρ))` (via `trace_comp_cfc_eq_double_sum`). + +**Proof.** Apply `Real.sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic` with weights +`Wᵢⱼ := ‖⟨fⱼ, eᵢ⟩‖²`. The doubly-stochastic property follows from Parseval +(`OrthonormalBasis.sum_sq_norm_inner_right`) applied to the orthonormal eigenbases. -/ +theorem IsDensityOp.vonNeumannEntropy_le_neg_sum_spectral_log + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + {ρ σ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + ρ.vonNeumannEntropy ≤ + -∑ i, hρ.isSymmetric.eigenvalues rfl i * + ∑ j, ‖⟪hσ.isSymmetric.eigenvectorBasis rfl j, + hρ.isSymmetric.eigenvectorBasis rfl i⟫_ℂ‖ ^ 2 + * Real.log (hσ.isSymmetric.eigenvalues rfl j) := by + set eρ := hρ.isSymmetric.eigenvectorBasis rfl + set eσ := hσ.isSymmetric.eigenvectorBasis rfl + rw [vonNeumannEntropy_of_isSymmetric hρ.isSymmetric, le_neg] + refine Real.sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic + (hρ.eigenvalues_nonneg rfl) hσ_pos (hρ.eigenvalues_sum_eq_one rfl) + (hσ.eigenvalues_sum_eq_one rfl) (fun _ _ ↦ sq_nonneg _) (fun i ↦ ?_) (fun j ↦ ?_) + · rw [eσ.sum_sq_norm_inner_right, eρ.orthonormal.1, one_pow] + · simp_rw [← norm_inner_symm (𝕜 := ℂ), eρ.sum_sq_norm_inner_right, eσ.orthonormal.1, one_pow] + +/-- `Real.log` is continuous on the spectrum of a positive-spectrum density operator +(since the spectrum is then a subset of `{0}ᶜ`, where `Real.log` is continuous). Reusable +continuity-discharge for `cfc Real.log σ` consumers in trace-form computations. +Density-op specialization of `IsSelfAdjoint.continuousOn_log_spectrum_of_eigenvalues_pos`. -/ +private theorem IsDensityOp.continuousOn_log_spectrum {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] [CompleteSpace E] + {σ : E →L[ℂ] E} (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + ContinuousOn Real.log (spectrum ℝ σ) := + hσ.isPositive.isSelfAdjoint.continuousOn_log_spectrum_of_eigenvalues_pos rfl hσ_pos + +/-- **Operator Klein's inequality, trace form** (Nielsen–Chuang Theorem 11.7): for density +operators `ρ, σ : E →L[ℂ] E` with `σ`'s eigenvalues all positive, +`S(ρ) ≤ -re(tr((cfc log σ) ∘ ρ))`. The trace form is the natural shape for combining via +trace linearity (the chain used in NC's proof of concavity, Theorem 11.8); it follows from +the spectral form (`vonNeumannEntropy_le_neg_sum_spectral_log`) by identifying the +real-coerced spectral sum with the real part of the complex trace expansion (Q1.3.B1 +`trace_comp_cfc_eq_double_sum` applied with `f := Real.log`). -/ +theorem IsDensityOp.vonNeumannEntropy_le_neg_re_trace_cfc_log_comp + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + {ρ σ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) (hσ : σ.IsDensityOp) + (hσ_pos : ∀ j, 0 < hσ.isSymmetric.eigenvalues rfl j) : + ρ.vonNeumannEntropy ≤ + -RCLike.re (LinearMap.trace ℂ E ((cfc Real.log σ).toLinearMap ∘ₗ ρ.toLinearMap)) := by + refine (hρ.vonNeumannEntropy_le_neg_sum_spectral_log hσ hσ_pos).trans_eq ?_ + congr 1 + rw [hρ.isPositive.isSelfAdjoint.trace_comp_cfc_eq_double_sum + hσ.isPositive.isSelfAdjoint rfl Real.log (hσ.continuousOn_log_spectrum hσ_pos)] + simp only [← Complex.ofReal_pow, ← Complex.ofReal_mul, ← Complex.ofReal_sum] + exact Finset.sum_congr rfl fun i _ ↦ congr_arg _ <| Finset.sum_congr rfl fun j _ ↦ by ring + +/-- **Self-trace expansion**: for *any* density operator `σ : E →L[ℂ] E`, +`re(tr((cfc log σ) ∘ σ)) = -S(σ)` — no positivity needed (`Real.log` is continuous on the finite +spectrum unconditionally, and a zero eigenvalue contributes `0·log 0 = 0` on both sides). The "trace +of σ against its own log" equals the negative von Neumann entropy. Proof: specialize +`trace_comp_cfc_eq_double_sum` with `T := σ`, `U := σ`, `f := Real.log`; orthonormality of σ's +eigenbasis collapses the overlap inner-sum to a Kronecker delta; the resulting `∑ᵢ μᵢ * log μᵢ` +matches `-Real.entropy μ` by `negMulLog` unfolding. -/ +theorem IsDensityOp.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + {σ : E →L[ℂ] E} (hσ : σ.IsDensityOp) : + RCLike.re (LinearMap.trace ℂ E ((cfc Real.log σ).toLinearMap ∘ₗ σ.toLinearMap)) = + -σ.vonNeumannEntropy := by + rw [hσ.isPositive.isSelfAdjoint.trace_comp_cfc_eq_double_sum hσ.isPositive.isSelfAdjoint rfl + Real.log hσ.isPositive.isSelfAdjoint.continuousOn_log_spectrum, + vonNeumannEntropy_of_isSymmetric hσ.isSymmetric, Real.entropy] + set eσ := hσ.isSymmetric.eigenvectorBasis rfl + -- Orthonormal collapse: `‖⟪eσ j, eσ i⟫‖² = if j = i then 1 else 0`, so inner sum = log μᵢ. + have h_inner : ∀ i, ∑ j, ((Real.log (hσ.isSymmetric.eigenvalues rfl j) : ℝ) : ℂ) * + ((‖⟪eσ j, eσ i⟫_ℂ‖ : ℂ) ^ 2) = + ((Real.log (hσ.isSymmetric.eigenvalues rfl i) : ℝ) : ℂ) := fun i ↦ by + rw [Finset.sum_eq_single i] + · rw [(orthonormal_iff_ite (𝕜 := ℂ)).mp eσ.orthonormal, ite_eq_left rfl]; simp + · intro j _ hji + rw [(orthonormal_iff_ite (𝕜 := ℂ)).mp eσ.orthonormal, ite_eq_right hji]; simp + · simp + -- `RCLike.re ↑r = r` is rfl-true but `RCLike.ofReal_re` doesn't unify in simp here + -- (the goal's `↑` elaborates via `Complex.ofReal` rather than `RCLike`'s coercion). + simp only [h_inner, ← Complex.ofReal_mul, ← Complex.ofReal_sum, Real.negMulLog, + show ∀ r : ℝ, RCLike.re (r : ℂ) = r from fun _ ↦ rfl, neg_mul, + Finset.sum_neg_distrib, neg_neg] + +/-- **Diagonal form of the self-trace expansion**: for any density operator `σ`, the sum of +`log(λᵢ)` weighted by the quadratic form of `σ` in its own eigenbasis equals `-S(σ)`: +`∑ᵢ log(λᵢ)·re⟪eᵢ, σ eᵢ⟫ = -S(σ)`. The eigenbasis (sum) form of +`re_trace_cfc_log_self_eq_neg_vonNeumannEntropy`, obtained by expanding its trace over `σ`'s +eigenbasis via `re_trace_cfc_comp_eq_sum`. -/ +theorem IsDensityOp.sum_log_eigenvalue_mul_re_inner_self_eq_neg_vonNeumannEntropy + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] {σ : E →L[ℂ] E} (hσ : σ.IsDensityOp) : + ∑ i, Real.log (hσ.isSymmetric.eigenvalues rfl i) * + RCLike.re ⟪hσ.isSymmetric.eigenvectorBasis rfl i, + σ (hσ.isSymmetric.eigenvectorBasis rfl i)⟫_ℂ = + -σ.vonNeumannEntropy := + (hσ.isPositive.isSelfAdjoint.re_trace_cfc_comp_eq_sum rfl Real.log + hσ.isPositive.isSelfAdjoint.continuousOn_log_spectrum σ).symm.trans + hσ.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy + +/-- **`re ∘ trace ∘ (A ∘ -)` distributes over real-scalar-weighted CLM finite sums**: +for `A : E →L[ℂ] E`, the map `B ↦ re(trace(A.toLinearMap ∘ B.toLinearMap))` respects sums of +the form `∑ᵢ (cᵢ : ℂ) • Bᵢ`, pulling the real coefficients `cᵢ` out as ordinary real +multiplication. Reusable trace-linearity bridge for trace-of-mixture computations +(e.g., concavity-of-vNE in NC §11.3.5). -/ +theorem re_trace_comp_clm_finset_sum_smul {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] (A : E →L[ℂ] E) + {ι : Type*} [Fintype ι] (B : ι → E →L[ℂ] E) (c : ι → ℝ) : + RCLike.re (LinearMap.trace ℂ E + (A.toLinearMap ∘ₗ ((∑ i, (c i : ℂ) • B i) : E →L[ℂ] E).toLinearMap)) = + ∑ i, c i * RCLike.re (LinearMap.trace ℂ E (A.toLinearMap ∘ₗ (B i).toLinearMap)) := by + rw [← ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.comp_finsetSum] + simp only [ContinuousLinearMap.comp_smul, ContinuousLinearMap.toLinearMap_sum, + ContinuousLinearMap.toLinearMap_smul, ContinuousLinearMap.toLinearMap_comp, map_sum, + map_smul, smul_eq_mul] + exact Finset.sum_congr rfl fun _ _ ↦ RCLike.re_ofReal_mul _ _ + +/-- **Concavity of von Neumann entropy** (Nielsen–Chuang Theorem 11.8): for a finite mixture +`σ = ∑ᵢ pᵢ ρᵢ` of density operators with `pᵢ ≥ 0` (probabilities; sum-to-1 implied by all +σ being a density op), +``` +∑ᵢ pᵢ S(ρᵢ) ≤ S(σ). +``` +Requires `σ`'s eigenvalues all positive (needed for the `cfc Real.log σ` continuity in the +trace-form Klein helper). NC §11.3.5: apply trace-form Klein to each `ρᵢ` against `σ` as +the reference, multiply by `pᵢ`, and sum; linearity of trace identifies the weighted sum +of cross-terms `∑ᵢ pᵢ tr(ρᵢ log σ)` with `tr(σ log σ) = -S(σ)`. This is the textbook +chain; the path avoids Lieb's joint concavity (needed for SSA, Q1.3.C). -/ +theorem IsDensityOp.vonNeumannEntropy_convex_combination_le + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + {ι : Type*} [Fintype ι] {ρ : ι → E →L[ℂ] E} (hρ : ∀ i, (ρ i).IsDensityOp) + {σ : E →L[ℂ] E} (hσ : σ.IsDensityOp) {p : ι → ℝ} (hp : ∀ i, 0 ≤ p i) + (hσ_eq : σ = ∑ i, (p i : ℂ) • ρ i) + (hσ_pos : ∀ k, 0 < hσ.isSymmetric.eigenvalues rfl k) : + ∑ i, p i * (ρ i).vonNeumannEntropy ≤ σ.vonNeumannEntropy := by + refine (Finset.sum_le_sum fun i _ ↦ mul_le_mul_of_nonneg_left + ((hρ i).vonNeumannEntropy_le_neg_re_trace_cfc_log_comp hσ hσ_pos) (hp i)).trans ?_ + -- Bridge `∑ pᵢ * re(tr(A ∘ ρᵢ)) = re(tr(A ∘ σ))` via `re_trace_comp_clm_finset_sum_smul` + -- + `hσ_eq`. Close via Helper B (self-trace = -S identity). + simp_rw [mul_neg, Finset.sum_neg_distrib, + ← re_trace_comp_clm_finset_sum_smul (cfc Real.log σ) ρ p, ← hσ_eq, + hσ.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy, neg_neg] + exact le_rfl + +end ContinuousLinearMap + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + +open scoped Classical in +/-- LM-level **von Neumann entropy**: parallel to the CLM definition. For a linear endomorphism +`A : E →ₗ[𝕜] E`, the entropy of its eigenvalue spectrum (junk-`0` on non-symmetric inputs). -/ +noncomputable def vonNeumannEntropy (A : E →ₗ[𝕜] E) : ℝ := + if h : A.IsSymmetric + then Real.entropy fun i : Fin (Module.finrank 𝕜 E) ↦ h.eigenvalues rfl i + else 0 + +theorem vonNeumannEntropy_of_isSymmetric {A : E →ₗ[𝕜] E} (h : A.IsSymmetric) : + A.vonNeumannEntropy = Real.entropy fun i : Fin (Module.finrank 𝕜 E) ↦ h.eigenvalues rfl i := by + rw [vonNeumannEntropy, dite_eq_left h] + +theorem vonNeumannEntropy_of_not_isSymmetric {A : E →ₗ[𝕜] E} (h : ¬ A.IsSymmetric) : + A.vonNeumannEntropy = 0 := by + rw [vonNeumannEntropy, dite_eq_right h] + +/-- Helper: the LM-level von Neumann entropy of a symmetric operator equals the entropy of its +eigenvalue sequence under any choice of finrank-witness `hn`. LM-level analog of the CLM +`ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq`. -/ +lemma vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq {A : E →ₗ[𝕜] E} + (h : A.IsSymmetric) {n : ℕ} (hn : Module.finrank 𝕜 E = n) : + A.vonNeumannEntropy = Real.entropy fun i : Fin n ↦ h.eigenvalues hn i := by + subst hn + exact vonNeumannEntropy_of_isSymmetric h + +/-- **Tensor-iid scaling of von Neumann entropy** (LM-level): for symmetric `A : E →ₗ[𝕜] E` +whose eigenvalues sum to one (e.g., the LM of a density operator), +`(A ^⊗ n).vonNeumannEntropy = n * A.vonNeumannEntropy`. + +Proof: the multiset of eigenvalues of `A ^⊗ n` (via +`LinearMap.IsSymmetric.tensorPow_eigenvalues_multiset_eq`) is the multiset of products +`∏ i, A.eigenvalues (κ i)` over `κ : Fin n → Fin d`. Bridging Finset-sum to Multiset-sum via +this equality reduces the LHS entropy to `Real.entropy (fun κ ↦ ∏ i, A.eigenvalues (κ i))`, +which is `n * A.vonNeumannEntropy` by `Real.entropy_pi_prod_of_sum_eq_one`. -/ +theorem IsSymmetric.vonNeumannEntropy_tensorPow_of_sum_eigenvalues_eq_one + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) + (hsum : ∑ i, hA.eigenvalues rfl i = 1) (n : ℕ) : + (A ^⊗ n).vonNeumannEntropy = n * A.vonNeumannEntropy := by + rw [vonNeumannEntropy_of_isSymmetric (hA.tensorPow n), + vonNeumannEntropy_of_isSymmetric hA, ← Real.entropy_pi_prod_of_sum_eq_one hsum n] + exact Real.entropy_eq_of_multiset_map_eq (hA.tensorPow_eigenvalues_multiset_eq n rfl rfl).symm + +/-- **Binary tensor-product additivity of von Neumann entropy** (LM-level, abstract). +For symmetric operators `A : E →ₗ[𝕜] E` and `B : F →ₗ[𝕜] F` (on finite-dim inner product +spaces) whose eigenvalues each sum to 1: +`(TensorProduct.map A B).vonNeumannEntropy = A.vonNeumannEntropy + B.vonNeumannEntropy`. + +Proof: multiset-bridge pattern, using `tensorMap_eigenvalues_multiset_eq` +(binary multiset equality) + `Real.entropy_prod` (binary product additivity). +The dimension witness uses `Module.finrank_tensorProduct` for `finrank (E ⊗ F) = dE * dF`. -/ +theorem IsSymmetric.vonNeumannEntropy_tensorMap_of_sum_eigenvalues_eq_one + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {A : E →ₗ[𝕜] E} (hA : A.IsSymmetric) + (hsumA : ∑ i : Fin (Module.finrank 𝕜 E), hA.eigenvalues rfl i = 1) + {B : F →ₗ[𝕜] F} (hB : B.IsSymmetric) + (hsumB : ∑ j : Fin (Module.finrank 𝕜 F), hB.eigenvalues rfl j = 1) : + (TensorProduct.map A B : E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).vonNeumannEntropy = + A.vonNeumannEntropy + B.vonNeumannEntropy := by + have h_tensor_finrank : Module.finrank 𝕜 (E ⊗[𝕜] F) = + Module.finrank 𝕜 E * Module.finrank 𝕜 F := Module.finrank_tensorProduct + rw [vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq (hA.tensorMap hB) h_tensor_finrank, + vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq hA rfl, + vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq hB rfl, + ← Real.entropy_prod hsumA hsumB] + exact Real.entropy_eq_of_multiset_map_eq + (hA.tensorMap_eigenvalues_multiset_eq hB rfl rfl h_tensor_finrank).symm + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + +/-- **rfl-bridge: CLM `vonNeumannEntropy` equals LM `vonNeumannEntropy` of `toLinearMap`.** The +two definitions are structurally identical (both dispatch on `T.toLinearMap.IsSymmetric` and +compute `Real.entropy` of the eigenvalue spectrum). -/ +@[simp] theorem vonNeumannEntropy_toLinearMap (T : E →L[𝕜] E) : + T.toLinearMap.vonNeumannEntropy = T.vonNeumannEntropy := rfl + +/-- **Tensor-iid scaling of von Neumann entropy** (density-operator form). For a density +operator `ρ`, the CLM-level `vonNeumannEntropy` of the n-fold tensor-power LM `ρ^⊗n` +(via the LM-level bridge) scales as `n * ρ.vonNeumannEntropy`. -/ +theorem IsDensityOp.vonNeumannEntropy_tensorPow {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) (n : ℕ) : + (ρ.toLinearMap ^⊗ n).vonNeumannEntropy = n * ρ.vonNeumannEntropy := by + rw [← vonNeumannEntropy_toLinearMap] + exact hρ.isSymmetric.vonNeumannEntropy_tensorPow_of_sum_eigenvalues_eq_one + (hρ.eigenvalues_sum_eq_one rfl) n + +/-- **Binary tensor-product additivity of von Neumann entropy** (abstract, density-operator +form). For density operators `ρ : E →L[𝕜] E` and `σ : F →L[𝕜] F` on finite-dim inner product +spaces: +`(TensorProduct.map ρ.toLinearMap σ.toLinearMap).vonNeumannEntropy = + ρ.vonNeumannEntropy + σ.vonNeumannEntropy`. + +Density operators delegate via `vonNeumannEntropy_toLinearMap` (rfl bridge) to the +LM-level `IsSymmetric.vonNeumannEntropy_tensorMap_of_sum_eigenvalues_eq_one`. -/ +theorem IsDensityOp.vonNeumannEntropy_tensorMap + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + {ρ : E →L[𝕜] E} (hρ : ρ.IsDensityOp) {σ : F →L[𝕜] F} (hσ : σ.IsDensityOp) : + (TensorProduct.map ρ.toLinearMap σ.toLinearMap : + E ⊗[𝕜] F →ₗ[𝕜] E ⊗[𝕜] F).vonNeumannEntropy = + ρ.vonNeumannEntropy + σ.vonNeumannEntropy := by + rw [← vonNeumannEntropy_toLinearMap (T := ρ), ← vonNeumannEntropy_toLinearMap (T := σ)] + exact hρ.isSymmetric.vonNeumannEntropy_tensorMap_of_sum_eigenvalues_eq_one + (hρ.eigenvalues_sum_eq_one rfl) hσ.isSymmetric (hσ.eigenvalues_sum_eq_one rfl) + +end ContinuousLinearMap + +namespace ContinuousLinearMap + +/-- **Von Neumann entropy of the maximally mixed operator** `S((1/d) • I) = log d`, where +`d = finrank ℂ E`. This is the equality case of the upper bound +`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_le_log_dim`: the maximally mixed operator +`(finrank ℂ E)⁻¹ • 1` (a density operator by `isDensityOp_finrank_inv_smul_one`) attains the +`log d` bound. Its `d` eigenvalues all equal `1/d` (read off from +`LinearMap.IsSymmetric.apply_eigenvectorBasis`, since it is a real scalar multiple of the +identity), so the entropy is the Shannon entropy of the uniform spectrum, +`d · negMulLog(1/d) = log d` (`Real.entropy_const`). -/ +theorem vonNeumannEntropy_finrank_inv_smul_one + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [Nontrivial E] : + ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)).vonNeumannEntropy + = Real.log (Module.finrank ℂ E) := by + have hne : (Module.finrank ℂ E : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Module.finrank_pos.ne' + -- The operator `(1/d) • I` is self-adjoint (a real scalar times the identity). + have hsa : IsSelfAdjoint ((Module.finrank ℂ E : ℂ)⁻¹ • (1 : E →L[ℂ] E)) := by + refine IsSelfAdjoint.smul ?_ (isSelfAdjoint_iff.mpr (star_one _)) + rw [isSelfAdjoint_iff]; simp + have hsym := hsa.isSymmetric + rw [ContinuousLinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq hsym rfl] + -- Every eigenvalue of `(1/d) • I` equals `1/d`. + have heig : (fun i => hsym.eigenvalues rfl i) + = (fun _ : Fin (Module.finrank ℂ E) => (Module.finrank ℂ E : ℝ)⁻¹) := by + funext i + have h := hsym.apply_eigenvectorBasis rfl i + simp only [ContinuousLinearMap.coe_coe, _root_.smul_apply, + one_apply_eq_self] at h + have hv : (hsym.eigenvectorBasis rfl) i ≠ 0 := + (hsym.eigenvectorBasis rfl).orthonormal.ne_zero i + have hsc : (Module.finrank ℂ E : ℂ)⁻¹ = ((hsym.eigenvalues rfl i : ℝ) : ℂ) := + smul_left_injective ℂ hv h + refine Complex.ofReal_inj.mp ?_ + rw [Complex.ofReal_inv, Complex.ofReal_natCast] + exact hsc.symm + -- `H(1/d, …, 1/d) = d · negMulLog(1/d) = log d`. + rw [heig, Real.entropy_const, Fintype.card_fin, Real.negMulLog, Real.log_inv] + field_simp + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyContinuous.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyContinuous.lean new file mode 100644 index 0000000000..000128f5d9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyContinuous.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedKleinInequality +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Continuity + +/-! +# Continuity of the von Neumann entropy + +The von Neumann entropy `ContinuousLinearMap.vonNeumannEntropy` is defined eigenvalue-wise +(`Real.entropy` of the spectrum), and the individual eigenvalues of a Hermitian operator do *not* +depend continuously on the operator (they can cross and permute). Nonetheless the entropy — a +symmetric function of the spectrum — *is* continuous, because it is a spectral trace: +`S(ρ) = re tr(negMulLog(ρ))` with `negMulLog x = -x log x` a *globally* continuous function +(`Real.continuous_negMulLog`; the removable singularity `0 · log 0 = 0` is exactly Mathlib's +junk-value convention). Continuity then follows from continuity of the continuous functional +calculus in the operator argument (`ContinuousOn.cfc'`) and continuity of the trace +(`ContinuousLinearMap.continuous_trace`). + +## Main results + +- `ContinuousLinearMap.vonNeumannEntropy_eq_re_trace_cfc_negMulLog`: the trace formula + `S(T) = re tr(cfc negMulLog T)` for a self-adjoint operator. +- `ContinuousLinearMap.continuousOn_vonNeumannEntropy_of_spectrum_subset_Icc`: continuity of the + entropy on the set of self-adjoint operators whose real spectrum lies in `[0, 1]`. +- `ContinuousLinearMap.IsDensityOp.continuousOn_vonNeumannEntropy`: continuity on the set of + density operators. +- `ContinuousLinearMap.tendsto_vonNeumannEntropy_regularise`: continuity of the entropy along a + density-operator regularisation `t ↦ (1 - t) • A + t • B`, giving `S → S(A)` as `t → 0⁺` — the + generic limiting step for extending a strictly-positive entropy inequality to all density + operators. + +The density-operator continuity is the keystone for extending strong subadditivity (and the other +strictly-positive entropy inequalities) to *all* density operators by a +regularisation/limiting argument: a general density operator is a limit of strictly positive ones, +and the entropy inequalities, being closed conditions, pass to the limit by continuity. +-/ + +@[expose] public section + +open scoped InnerProductSpace + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **Trace formula for the von Neumann entropy.** For a self-adjoint operator `T`, +`S(T) = re tr(cfc negMulLog T)`, where `negMulLog x = -x·log x`. This rewrites the eigenvalue-wise +`Real.entropy` definition as a single spectral trace of a *globally continuous* function, which is +the shape needed for continuity of the entropy. Both sides expand to `∑ᵢ negMulLog(λᵢ)` via +`IsSelfAdjoint.re_trace_cfc_eq_sum`. -/ +theorem vonNeumannEntropy_eq_re_trace_cfc_negMulLog {T : E →L[ℂ] E} (hT : IsSelfAdjoint T) : + T.vonNeumannEntropy = + RCLike.re (LinearMap.trace ℂ E (cfc Real.negMulLog T).toLinearMap) := by + rw [vonNeumannEntropy_of_isSymmetric hT.isSymmetric, Real.entropy_eq, + IsSelfAdjoint.re_trace_cfc_eq_sum hT Real.negMulLog] + +/-- The real spectrum of a density operator is contained in `[0, 1]`: its eigenvalues are the +spectral values (`IsSelfAdjoint.spectrum_real_eq_range_eigenvalues`), each of which lies in +`[0, 1]`. -/ +theorem IsDensityOp.spectrum_real_subset_Icc {T : E →L[ℂ] E} (h : T.IsDensityOp) : + spectrum ℝ T ⊆ Set.Icc (0 : ℝ) 1 := by + rw [h.isPositive.isSelfAdjoint.spectrum_real_eq_range_eigenvalues rfl] + rintro x ⟨i, rfl⟩ + exact ⟨h.eigenvalues_nonneg rfl i, h.eigenvalues_le_one rfl i⟩ + +/-- **Continuity of the von Neumann entropy** on the set of self-adjoint operators whose real +spectrum lies in `[0, 1]`. Proved by rewriting `S` as the spectral trace `re tr(cfc negMulLog T)` +(`vonNeumannEntropy_eq_re_trace_cfc_negMulLog`) and composing continuity of the continuous +functional calculus (`ContinuousOn.cfc'`, with the fixed compact spectrum bound `[0, 1]`) with +continuity of the trace and of `re`. -/ +theorem continuousOn_vonNeumannEntropy_of_spectrum_subset_Icc : + ContinuousOn (fun T : E →L[ℂ] E => T.vonNeumannEntropy) + {T | IsSelfAdjoint T ∧ spectrum ℝ T ⊆ Set.Icc (0 : ℝ) 1} := by + have hcfc : ContinuousOn (fun T : E →L[ℂ] E => cfc Real.negMulLog T) + {T | IsSelfAdjoint T ∧ spectrum ℝ T ⊆ Set.Icc (0 : ℝ) 1} := + ContinuousOn.cfc' isCompact_Icc Real.negMulLog continuousOn_id + (fun T hT => hT.2) (fun T hT => hT.1) + have hcont : ContinuousOn + (fun T : E →L[ℂ] E => + RCLike.re (LinearMap.trace ℂ E (cfc Real.negMulLog T).toLinearMap)) + {T | IsSelfAdjoint T ∧ spectrum ℝ T ⊆ Set.Icc (0 : ℝ) 1} := + RCLike.continuous_re.comp_continuousOn + (ContinuousLinearMap.continuous_trace.comp_continuousOn hcfc) + exact hcont.congr fun T hT => vonNeumannEntropy_eq_re_trace_cfc_negMulLog hT.1 + +/-- **Continuity of the von Neumann entropy on density operators.** A corollary of +`continuousOn_vonNeumannEntropy_of_spectrum_subset_Icc`, since every density operator is +self-adjoint with real spectrum in `[0, 1]`. This is the form used to extend the strictly-positive +entropy inequalities to all density operators by a limiting argument. -/ +theorem IsDensityOp.continuousOn_vonNeumannEntropy : + ContinuousOn (fun T : E →L[ℂ] E => T.vonNeumannEntropy) {T | T.IsDensityOp} := + continuousOn_vonNeumannEntropy_of_spectrum_subset_Icc.mono fun _T hT => + ⟨hT.isPositive.isSelfAdjoint, hT.spectrum_real_subset_Icc⟩ + +/-- **Continuity of the von Neumann entropy along a density-operator regularisation.** For density +operators `A B` on a finite-dimensional space, the convex path `t ↦ (1 - t) • A + t • B` stays +inside the density operators for `t ∈ [0, 1]` (`IsDensityOp.convex_combination`), so — the entropy +being continuous there (`IsDensityOp.continuousOn_vonNeumannEntropy`) — its von Neumann entropy +converges to `S(A)` as `t → 0⁺`. + +This is the generic limiting step behind extending a strictly-positive entropy inequality to *all* +density operators: regularise a general operator towards a faithful reference (e.g. the maximally +mixed `d⁻¹ • 1`), apply the inequality along `(0, 1]`, and pass the closed inequality to the +`t → 0⁺` limit. It is used both to remove faithfulness from strong subadditivity +(`vonNeumannEntropy_add_partialTrace_le_of_isDensityOp`) and to extend the second-derivative +concavity of the entropy (Nielsen & Chuang Exercise 11.22) from invertible states to all states. -/ +theorem tendsto_vonNeumannEntropy_regularise (A B : E →L[ℂ] E) + (hA : A.IsDensityOp) (hB : B.IsDensityOp) : + Filter.Tendsto (fun t : ℝ => (((1 - t : ℝ) : ℂ) • A + ((t : ℝ) : ℂ) • B).vonNeumannEntropy) + (nhdsWithin 0 (Set.Ioc (0 : ℝ) 1)) (nhds A.vonNeumannEntropy) := by + have hcont : Continuous (fun t : ℝ => ((1 - (t : ℝ) : ℝ) : ℂ) • A + ((t : ℝ) : ℂ) • B) := by + fun_prop + have hmaps : Set.MapsTo (fun t : ℝ => (((1 - t : ℝ) : ℂ) • A + ((t : ℝ) : ℂ) • B)) + (Set.Icc (0 : ℝ) 1) {T : E →L[ℂ] E | T.IsDensityOp} := fun t ht => + IsDensityOp.convex_combination hA hB + (by exact_mod_cast (by linarith [ht.2] : (0 : ℝ) ≤ 1 - t)) (by exact_mod_cast ht.1) + (by push_cast; ring) + have h0 := ((IsDensityOp.continuousOn_vonNeumannEntropy).comp hcont.continuousOn + hmaps).continuousWithinAt (by norm_num : (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1) |>.mono_left + (nhdsWithin_mono 0 Set.Ioc_subset_Icc_self) + simpa [Function.comp_def] using h0 + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyFano.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyFano.lean new file mode 100644 index 0000000000..2237f26568 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyFano.lean @@ -0,0 +1,167 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropyPinching +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.DiagonalOperatorEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! # The density-operator Fano bound + +For a density operator `ρ` on a finite-dimensional complex inner product space `E` of dimension +`d = finrank ℂ E`, and any unit vector `ψ`, the von Neumann entropy obeys the **density-operator +Fano bound** +`S(ρ) ≤ H(p) + (1 - p) · log (d - 1)`, `p := ⟨ψ, ρ ψ⟩`, +where `H` is the binary Shannon entropy. This is the operator core of the quantum Fano inequality +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 12.9, eqs. (12.113)– +(12.115)): applied to the state `ρ_{R'Q'}` of the reference-plus-system after a quantum operation, +with `ψ` the (pure) initial `|RQ⟩` and `p` the entanglement fidelity, it is the quantum Fano +inequality `S(ρ, E) ≤ H(F) + (1 - F) · log (d² - 1)`. + +The proof is the two-step argument of N&C §12.4.1, both steps operator-level: + +* **The diagonal bound** (`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_le_entropy_diag`): + `S(ρ) ≤ H(diag ρ)`, the Shannon entropy of the diagonal of `ρ` in *any* orthonormal basis `b`. + This is the operator form of N&C Theorem 11.9 (a projective measurement never decreases entropy): + the rank-one projectors `Pᵢ = |bᵢ⟩⟨bᵢ|` pinch `ρ` to the diagonal operator + `Σᵢ ⟨bᵢ, ρ bᵢ⟩ |bᵢ⟩⟨bᵢ|`, whose entropy is `H(diag ρ)`, and pinching never decreases entropy + (`ContinuousLinearMap.vonNeumannEntropy_le_krausSumₗ`). + +* **The grouping step** (`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_le_binEntropy_add`): + extend `ψ` to an orthonormal basis and apply the classical grouping inequality + `Real.entropy_le_qaryEntropy` (N&C eq. (12.114)) to the diagonal distribution `p`, whose + distinguished entry is `⟨ψ, ρ ψ⟩`. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.4.1 (Theorem 12.9), §11.3 (Theorem 11.9). +-/ + +open scoped InnerProductSpace ComplexConjugate +open InnerProductSpace + +@[expose] public section + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +omit [FiniteDimensional ℂ E] [CompleteSpace E] in +/-- For a density operator `ρ`, the diagonal inner product `⟨x, ρ x⟩` equals its own real part +(it is real), since `ρ` is symmetric. -/ +theorem IsDensityOp.inner_self_eq_re {ρ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) (x : E) : + inner ℂ x (ρ x) = ((RCLike.re (inner ℂ x (ρ x)) : ℝ) : ℂ) := + (hρ.isSymmetric.coe_re_inner_self_apply x).symm + +/-- **The diagonal-entropy bound** (operator form of Nielsen & Chuang Theorem 11.9): for a density +operator `ρ` and any orthonormal basis `b`, the von Neumann entropy is at most the Shannon entropy +of the diagonal `pᵢ = ⟨bᵢ, ρ bᵢ⟩` of `ρ` in that basis: +`S(ρ) ≤ H(diag ρ)`. + +The rank-one projectors `Pᵢ = |bᵢ⟩⟨bᵢ|` form a complete family of orthogonal star projections; the +pinching `Σᵢ Pᵢ ρ Pᵢ` is the diagonal operator `Σᵢ ⟨bᵢ, ρ bᵢ⟩ |bᵢ⟩⟨bᵢ|`, whose entropy is +`H(diag ρ)` (`OrthonormalBasis.diagonalOperator_vonNeumannEntropy`), and pinching never decreases +entropy (`ContinuousLinearMap.vonNeumannEntropy_le_krausSumₗ`). -/ +theorem IsDensityOp.vonNeumannEntropy_le_entropy_diag {ι : Type*} [Fintype ι] + (b : OrthonormalBasis ι ℂ E) {ρ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) : + ρ.vonNeumannEntropy ≤ Real.entropy (fun i => RCLike.re (inner ℂ (b i) (ρ (b i)))) := by + classical + set P : ι → (E →L[ℂ] E) := fun i => rankOne ℂ (b i) (b i) with hP + have hProj : ∀ i, IsStarProjection (P i) := fun i => + InnerProductSpace.isStarProjection_rankOne_self (b.orthonormal.1 i) + have hOrth : ∀ i j, i ≠ j → P i * P j = 0 := fun i j hij => by + simp only [hP, ContinuousLinearMap.mul_def, rankOne_comp_rankOne, b.orthonormal.2 hij, + zero_smul] + have hSum : ∑ i, P i = 1 := b.sum_rankOne_eq_id + -- The pinching `Σᵢ Pᵢ ρ Pᵢ` is the diagonal operator with diagonal `⟨bᵢ, ρ bᵢ⟩`. + have hdiag : krausSumₗ P ρ + = b.diagonalOperator (fun i => ((RCLike.re (inner ℂ (b i) (ρ (b i))) : ℝ) : ℂ)) := by + rw [krausSumₗ_eq_sum_conj_of_isStarProjection hProj, OrthonormalBasis.diagonalOperator] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [← hρ.inner_self_eq_re (b i)] + ext z + simp only [hP, mul_apply_eq_comp, InnerProductSpace.rankOne_apply, map_smul, + _root_.smul_apply, smul_smul, mul_comm] + -- Assemble: pinching bound + entropy of the diagonal operator. + calc ρ.vonNeumannEntropy + ≤ (krausSumₗ P ρ).vonNeumannEntropy := vonNeumannEntropy_le_krausSumₗ hProj hOrth hSum hρ + _ = Real.entropy (fun i => RCLike.re (inner ℂ (b i) (ρ (b i)))) := by + rw [hdiag] + exact b.diagonalOperator_vonNeumannEntropy _ + +omit [FiniteDimensional ℂ E] [CompleteSpace E] in +/-- For a density operator `ρ` and any orthonormal basis `b`, the real diagonal +`pᵢ = ⟨bᵢ, ρ bᵢ⟩` is normalized: `∑ᵢ pᵢ = tr ρ = 1`. The ONB-diagonal companion of +`ContinuousLinearMap.IsDensityOp.eigenvalues_sum_eq_one`. -/ +theorem IsDensityOp.sum_re_inner_orthonormalBasis_eq_one {ι : Type*} [Fintype ι] + (b : OrthonormalBasis ι ℂ E) {ρ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) : + ∑ i, RCLike.re (inner ℂ (b i) (ρ (b i))) = 1 := by + have key : ∑ i, inner ℂ (b i) (ρ (b i)) = (1 : ℂ) := by + have h := LinearMap.trace_eq_sum_inner (↑ρ : E →ₗ[ℂ] E) b + simp only [ContinuousLinearMap.coe_coe] at h + rw [← h] + exact hρ.trace_eq_one + refine RCLike.ofReal_injective (K := ℂ) ?_ + push_cast + rw [← key] + exact Finset.sum_congr rfl fun i _ => (hρ.inner_self_eq_re (b i)).symm + +/-- **The density-operator Fano bound** (operator core of Nielsen & Chuang Theorem 12.9). For a +density operator `ρ` on a `d`-dimensional space and any unit vector `ψ`, writing `p = ⟨ψ, ρ ψ⟩`, +`S(ρ) ≤ H(p) + (1 - p) · log (d - 1)`, +where `H` is the binary Shannon entropy. + +Extend `ψ` to an orthonormal basis; the diagonal distribution `pᵢ = ⟨bᵢ, ρ bᵢ⟩` is a probability +distribution (nonnegative, summing to `tr ρ = 1`) whose distinguished entry `p₀ = ⟨ψ, ρ ψ⟩` is the +entanglement fidelity in the intended application. The diagonal bound `S(ρ) ≤ H(p)` combines with +the classical grouping inequality `H(p) ≤ H(1 - p₀) + (1 - p₀) · log (d - 1)` +(`Real.entropy_le_qaryEntropy`) and the symmetry `H(1 - p₀) = H(p₀)` of the binary entropy. -/ +theorem IsDensityOp.vonNeumannEntropy_le_binEntropy_add {ρ : E →L[ℂ] E} (hρ : ρ.IsDensityOp) + {ψ : E} (hψ : ‖ψ‖ = 1) : + ρ.vonNeumannEntropy ≤ Real.binEntropy (RCLike.re (inner ℂ ψ (ρ ψ))) + + (1 - RCLike.re (inner ℂ ψ (ρ ψ))) * Real.log ((Module.finrank ℂ E : ℝ) - 1) := by + classical + set d := Module.finrank ℂ E with hd + -- `E` is nontrivial (it has a unit vector), hence `0 < d`. + have hψ0 : ψ ≠ 0 := by rintro rfl; simp at hψ + have hNontriv : Nontrivial E := ⟨ψ, 0, hψ0⟩ + have hd0 : 0 < d := Module.finrank_pos + set i₀ : Fin d := ⟨0, hd0⟩ with hi₀ + -- Extend `ψ` to an orthonormal basis `b : OrthonormalBasis (Fin d) ℂ E` with `b i₀ = ψ`. + have hcard : Module.finrank ℂ E = Fintype.card (Fin d) := by rw [Fintype.card_fin] + have horth : Orthonormal ℂ (({i₀} : Set (Fin d)).domRestrict (fun _ => ψ)) := by + rw [orthonormal_iff_ite] + rintro ⟨i, hi⟩ ⟨j, hj⟩ + simp only [Set.mem_singleton_iff] at hi hj + subst hi; subst hj + have hvali : ({i₀} : Set (Fin d)).domRestrict (fun _ => ψ) ⟨i₀, hi⟩ = ψ := rfl + rw [hvali, inner_self_eq_norm_sq_to_K, hψ, ite_eq_left rfl] + norm_num + obtain ⟨b, hb⟩ := Orthonormal.exists_orthonormalBasis_extension_of_card_eq hcard horth + have hbψ : b i₀ = ψ := hb i₀ rfl + -- The diagonal distribution `p` is a probability distribution. + set p : Fin d → ℝ := fun i => RCLike.re (inner ℂ (b i) (ρ (b i))) with hp_def + have hp_nn : ∀ i, 0 ≤ p i := fun i => hρ.isPositive.re_inner_nonneg_right (b i) + have hp_sum : ∑ i, p i = 1 := hρ.sum_re_inner_orthonormalBasis_eq_one b + -- Diagonal bound then classical grouping. + have hdiag := hρ.vonNeumannEntropy_le_entropy_diag b + have hgroup := Real.entropy_le_qaryEntropy hp_nn hp_sum i₀ + rw [Real.qaryEntropy_eq_log_add_binEntropy, Real.binEntropy_one_sub, Fintype.card_fin] at hgroup + have hpi₀ : p i₀ = RCLike.re (inner ℂ ψ (ρ ψ)) := by simp only [hp_def, hbψ] + rw [hpi₀] at hgroup + calc ρ.vonNeumannEntropy + ≤ Real.entropy p := hdiag + _ ≤ (1 - RCLike.re (inner ℂ ψ (ρ ψ))) * Real.log ((d : ℤ) - 1 : ℤ) + + Real.binEntropy (RCLike.re (inner ℂ ψ (ρ ψ))) := hgroup + _ = Real.binEntropy (RCLike.re (inner ℂ ψ (ρ ψ))) + + (1 - RCLike.re (inner ℂ ψ (ρ ψ))) * Real.log ((d : ℝ) - 1) := by push_cast; ring + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyGram.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyGram.lean new file mode 100644 index 0000000000..d3e4f62a71 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyGram.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.SingularValues +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.RankOneSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GramMatrix +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.Matrix +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! # Gram versus sum-of-rank-ones: equal von Neumann entropy + +For a finite family of vectors `φ : ι → H` in a finite-dimensional complex inner product space, +the **frame operator** `Σᵢ |φᵢ⟩⟨φᵢ|` (a positive operator on `H`) and the **Gram matrix** +`Gᵢⱼ = ⟨φᵢ, φⱼ⟩` (a positive semidefinite `ι × ι` matrix) share the same nonzero spectrum, hence +the same von Neumann entropy: +`S(Σᵢ |φᵢ⟩⟨φᵢ|) = S(gram φ)`. + +The underlying linear-algebra fact is that for any operator `A` between finite-dimensional inner +product spaces, `A Aᴴ` and `Aᴴ A` have the same nonzero singular-value spectrum, so their von +Neumann entropies (Shannon entropies of the eigenvalue spectrum, with `0 log 0 = 0`) agree even +though they act on spaces of different dimension. Writing `A = synthesisMap φ` (the operator +`eᵢ ↦ φᵢ`) gives `A Aᴴ = Σᵢ |φᵢ⟩⟨φᵢ|` and `Aᴴ A = gram φ`. + +This is the operator identity behind the **entropy exchange** of Nielsen & Chuang, *Quantum +Computation and Quantum Information*, §12.4.1 (eq. (12.110)): the entropy exchange +`S(ρ, E) = S(W)` of the `w`-matrix `Wᵢⱼ = tr(Eᵢ ρ Eⱼ†)` equals the von Neumann entropy of the +state `ρ_{R'Q'} = Σᵢ |E_i √ρ⟩⟨E_i √ρ|`, because `W` is the Gram matrix of the family `E_i √ρ`. + +## Main results + +* `ContinuousLinearMap.vonNeumannEntropy_comp_adjoint_comm`: + `S(A ∘ Aᴴ) = S(Aᴴ ∘ A)` for `A : E →L[ℂ] F` (in fact over any `RCLike` field). +* `ContinuousLinearMap.vonNeumannEntropy_sum_rankOne_self_eq_gram`: + `S(Σᵢ |φᵢ⟩⟨φᵢ|) = S(gram φ)`, the Gram / sum-of-rank-ones entropy equality. + +## References + +* [Nielsen and Chuang, *Quantum Computation and Quantum Information*][nielsen_chuang_2010], + §12.4.1 (eq. (12.110)). +-/ + +open scoped InnerProductSpace + +@[expose] public section + +namespace LinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + +/-- The von Neumann entropy of the Gram operator `Tᴴ ∘ T` of a linear map `T : E →ₗ F` is the +Shannon entropy of the squared singular values of `T`. Since `(sᵢ)² = λᵢ(Tᴴ T)` are exactly the +eigenvalues of the (positive, self-adjoint) Gram operator, this is just the definition of von +Neumann entropy unfolded through `LinearMap.sq_singularValues_fin`. -/ +theorem vonNeumannEntropy_adjoint_comp_self_eq_entropy_sq_singularValues (T : E →ₗ[𝕜] F) : + (LinearMap.adjoint T ∘ₗ T).vonNeumannEntropy + = Real.entropy fun i : Fin (Module.finrank 𝕜 E) => T.singularValues i ^ 2 := by + rw [LinearMap.vonNeumannEntropy_eq_entropy_eigenvalues_of_finrank_eq + (isSymmetric_adjoint_comp_self T) rfl] + congr 1 + funext i + exact (T.sq_singularValues_fin rfl i).symm + +end LinearMap + +namespace ContinuousLinearMap + +variable {𝕜 : Type*} [RCLike 𝕜] +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] + [CompleteSpace E] +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [FiniteDimensional 𝕜 F] + [CompleteSpace F] + +/-- Two finite `Fin`-indexed Shannon-entropy sums of the same eventually-`negMulLog`-vanishing +sequence agree: if `g k` has `negMulLog (g k) = 0` for all `k ≥ r` and both `m₁, m₂ ≥ r`, then +`Real.entropy (g|_{Fin m₁}) = Real.entropy (g|_{Fin m₂})`, both collapsing to the length-`r` sum. +This is the "entropy ignores zero eigenvalues" step: the two operators `A Aᴴ` and `Aᴴ A` live on +spaces of different dimension but share the same nonzero (squared singular value) spectrum. -/ +private theorem entropy_fin_eq_of_negMulLog_vanish {g : ℕ → ℝ} {r m₁ m₂ : ℕ} + (hr : ∀ k, r ≤ k → (g k).negMulLog = 0) (h₁ : r ≤ m₁) (h₂ : r ≤ m₂) : + Real.entropy (fun i : Fin m₁ => g i) = Real.entropy (fun i : Fin m₂ => g i) := by + have key : ∀ m, r ≤ m → ∑ k ∈ Finset.range m, (g k).negMulLog + = ∑ k ∈ Finset.range r, (g k).negMulLog := by + intro m hm + refine (Finset.sum_subset (Finset.range_mono hm) fun x _ hx => ?_).symm + exact hr x (by simpa [Finset.mem_range, not_lt] using hx) + simp only [Real.entropy_eq] + rw [Fin.sum_univ_eq_sum_range (fun k => (g k).negMulLog) m₁, + Fin.sum_univ_eq_sum_range (fun k => (g k).negMulLog) m₂, key m₁ h₁, key m₂ h₂] + +/-- **`A Aᴴ` and `Aᴴ A` have equal von Neumann entropy.** For a continuous linear map +`A : E →L[𝕜] F` between finite-dimensional inner product spaces, `S(A ∘ Aᴴ) = S(Aᴴ ∘ A)`. + +Both sides are the Shannon entropy of the squared singular-value spectrum of `A` (the entropies of +`A Aᴴ` on `F` and of `Aᴴ A` on `E` differ only by extra zero eigenvalues, which contribute +`0 log 0 = 0`). This is the operator form of the fact that a Gram matrix and a sum of rank-one +projectors share their nonzero spectrum. -/ +theorem vonNeumannEntropy_comp_adjoint_comm (A : E →L[𝕜] F) : + (A ∘L ContinuousLinearMap.adjoint A).vonNeumannEntropy + = (ContinuousLinearMap.adjoint A ∘L A).vonNeumannEntropy := by + rw [← vonNeumannEntropy_toLinearMap, ← vonNeumannEntropy_toLinearMap, + ContinuousLinearMap.toLinearMap_comp, ContinuousLinearMap.toLinearMap_comp, + ← ContinuousLinearMap.adjoint_toLinearMap] + -- `↑(A ∘ Aᴴ) = ↑A ∘ₗ (adjoint ↑A)` and `↑(Aᴴ ∘ A) = (adjoint ↑A) ∘ₗ ↑A`. + set T : E →ₗ[𝕜] F := (A : E →ₗ[𝕜] F) with hT + -- Right-hand side: directly the Gram operator `Tᴴ ∘ T`. + have hRHS := LinearMap.vonNeumannEntropy_adjoint_comp_self_eq_entropy_sq_singularValues T + -- Left side: the Gram operator `(Tᴴ)ᴴ ∘ Tᴴ` of `Tᴴ`; its singular values match those of `T`. + have hLHS := LinearMap.vonNeumannEntropy_adjoint_comp_self_eq_entropy_sq_singularValues + (LinearMap.adjoint T) + rw [LinearMap.adjoint_adjoint, LinearMap.singularValues_adjoint] at hLHS + rw [hLHS, hRHS] + refine entropy_fin_eq_of_negMulLog_vanish + (g := fun k => T.singularValues k ^ 2) + (r := Module.finrank 𝕜 (LinearMap.range T)) (fun k hk => ?_) + (Submodule.finrank_le _) (LinearMap.finrank_range_le T) + have hzero : T.singularValues k = 0 := + (LinearMap.singularValues_eq_zero_iff_le_finrank_range T).mpr hk + simp [hzero] + +/-- **Gram versus sum-of-rank-ones entropy equality.** For a finite family `φ : ι → H` in a +finite-dimensional inner product space over an `RCLike` field `𝕜`, the frame operator +`Σᵢ |φᵢ⟩⟨φᵢ|` and the Gram matrix `gram φ` (with entries `⟨φᵢ, φⱼ⟩`) have equal von Neumann +entropy: +`S(Σᵢ |φᵢ⟩⟨φᵢ|) = S(gram φ)`. + +The frame operator is `A Aᴴ` for the synthesis operator `A = synthesisMap φ`, and its companion +`Aᴴ A` is the operator on `EuclideanSpace 𝕜 ι` with matrix `gram φ`; the equality is then +`vonNeumannEntropy_comp_adjoint_comm`. -/ +theorem vonNeumannEntropy_sum_rankOne_self_eq_gram {ι : Type*} [Fintype ι] [DecidableEq ι] + {H : Type*} [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] [FiniteDimensional 𝕜 H] + [CompleteSpace H] (φ : ι → H) : + (∑ i, InnerProductSpace.rankOne 𝕜 (φ i) (φ i)).vonNeumannEntropy + = (Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := ι) (Matrix.gram 𝕜 φ)).vonNeumannEntropy := by + rw [InnerProductSpace.sum_rankOne_self_eq_synthesisMap_comp_adjoint, + vonNeumannEntropy_comp_adjoint_comm] + congr 1 + -- `(synthesisMap φ)ᴴ ∘ synthesisMap φ = (gram φ).toEuclideanCLM` on `EuclideanSpace 𝕜 ι`. + refine ContinuousLinearMap.ext fun x => ext_inner_left 𝕜 fun w => ?_ + -- The Gram side is the Gram bilinear form of the two synthesis combinations. + have hR : inner 𝕜 w (Matrix.toEuclideanCLM (𝕜 := 𝕜) (n := ι) (Matrix.gram 𝕜 φ) x) + = inner 𝕜 (∑ i, (w.ofLp i) • φ i) (∑ i, (x.ofLp i) • φ i) := by + rw [EuclideanSpace.inner_eq_star_dotProduct, Matrix.ofLp_toEuclideanCLM, + dotProduct_comm, Matrix.star_dotProduct_gram_mulVec] + rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.adjoint_inner_right, + InnerProductSpace.synthesisMap_apply, InnerProductSpace.synthesisMap_apply, hR] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyMixture.lean b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyMixture.lean new file mode 100644 index 0000000000..e2deee881c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/InnerProductSpace/VonNeumannEntropyMixture.lean @@ -0,0 +1,215 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.QuantumRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.VonNeumannEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.GeneralizedRelativeEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Order + +/-! +# Entropy of a mixture — relative-entropy levers (Nielsen & Chuang, Theorem 11.10) + +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 11.10 (the "entropy of a +mixture" upper bound) states that for a mixture `ρ = ∑ᵢ pᵢ ρᵢ` of density operators, + +`S(ρ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`, + +with equality iff the `ρᵢ` have support on orthogonal subspaces. Together with the concavity +inequality `∑ᵢ pᵢ S(ρᵢ) ≤ S(ρ)` (Theorem 11.8, +`ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_convex_combination_le`) this bounds the *Holevo +χ quantity* `χ := S(ρ) − ∑ᵢ pᵢ S(ρᵢ)` between `0` and `H(p)`. + +This file develops the two operator-level **relative-entropy lemmas** on which the upper bound +rests. Writing the χ quantity as an average of relative entropies, +`χ = ∑ᵢ pᵢ D(ρᵢ ‖ ρ)`, the bound `χ ≤ H(p)` follows term by term from +`D(ρᵢ ‖ ρ) ≤ D(ρᵢ ‖ pᵢ ρᵢ) = −log pᵢ`: the inequality is *antitonicity of the relative entropy in +its second argument* (`ρ ≥ pᵢ ρᵢ` shrinks the divergence), and the equality is the scaling law +`D(r ‖ c • r) = −log c` (Problem 11.2). The two lemmas proved here are exactly: + +* the antitonicity `quantumRelativeEntropy_le_of_le_right`, and +* the χ-as-average identity `sum_mul_quantumRelativeEntropy_mix`. + +## Main results + +* `ContinuousLinearMap.quantumRelativeEntropy_le_of_le_right`: **antitonicity of the quantum + relative entropy in the second argument.** For a positive `ρ` and strictly positive `σ ≤ τ`, + `D(ρ ‖ τ) ≤ D(ρ ‖ σ)`. Enlarging the reference operator (in the Loewner order) cannot increase + the divergence, because `log` is operator monotone. +* `ContinuousLinearMap.sum_mul_quantumRelativeEntropy_mix`: the **Holevo χ identity** — for a + mixture `μ = ∑ᵢ pᵢ ρᵢ` of density operators, the weighted sum of relative entropies against the + mixture equals the concavity gap, `∑ᵢ pᵢ D(ρᵢ ‖ μ) = S(μ) − ∑ᵢ pᵢ S(ρᵢ)`. +* `ContinuousLinearMap.IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy`: the + **entropy-of-a-mixture upper bound** itself — for a mixture `μ = ∑ᵢ pᵢ ρᵢ` of *strictly positive* + density operators with `p` a subprobability weight vector, `S(μ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`, where + `H(p) = Real.entropy p` is the Shannon entropy. This assembles the two levers with the scaling law + `D(ρᵢ ‖ pᵢ • ρᵢ) = −log pᵢ` (Problem 11.2, `quantumRelativeEntropy_smul_smul`) term by term. + +The strict-positivity hypothesis on the components is inherent to this relative-entropy route (the +antitonicity lever needs the reference operator `pᵢ • ρᵢ` strictly positive), so this lemma +is the *faithful* form of Nielsen–Chuang Theorem 11.10 under the finite-branch faithfulness +convention. The general (possibly rank-deficient) case and the equality condition (orthogonal +supports) are handled in +`LeanPool/AxQM/NC/Ch11/Theorem10.lean`. +-/ + +@[expose] public section + +open scoped InnerProductSpace ComplexOrder + +namespace ContinuousLinearMap + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] + +/-- **Antitonicity of the quantum relative entropy in its second argument.** For a positive +operator `ρ` and strictly positive operators `σ ≤ τ` (Loewner order), +`D(ρ ‖ τ) ≤ D(ρ ‖ σ)`: enlarging the reference operator cannot increase the divergence. + +The proof rests on the operator monotonicity of the logarithm (`CFC.log_le_log`): since +`σ ≤ τ` with `σ` strictly positive, `log σ ≤ log τ`, so `log τ − log σ ≥ 0`. The two relative +entropies share the `tr(ρ log ρ)` term, so their difference is +`re tr((log τ − log σ) ρ) ≥ 0`, non-negative because it is the trace of a product of positive +operators (`re_trace_mul_nonneg_of_nonneg`). + +This is the monotonicity behind the entropy-of-a-mixture upper bound (Nielsen–Chuang +Theorem 11.10): applied with `σ = pᵢ ρᵢ ≤ ρ = τ` it bounds each `D(ρᵢ ‖ ρ)` by `D(ρᵢ ‖ pᵢ ρᵢ)`. -/ +theorem quantumRelativeEntropy_le_of_le_right {ρ σ τ : E →L[ℂ] E} (hρ : 0 ≤ ρ) + (hσ : IsStrictlyPositive σ) (hστ : σ ≤ τ) : + quantumRelativeEntropy ρ τ ≤ quantumRelativeEntropy ρ σ := by + -- `log` is operator monotone: `σ ≤ τ` with `σ` strictly positive gives `log σ ≤ log τ`. + have hlog : cfc Real.log σ ≤ cfc Real.log τ := CFC.log_le_log hστ hσ + rw [quantumRelativeEntropy_def, quantumRelativeEntropy_def] + -- `re tr((log τ − log σ) ρ) ≥ 0` as the trace of a product of positive operators. + have hdiff : 0 ≤ RCLike.re (LinearMap.trace ℂ E + (((cfc Real.log τ - cfc Real.log σ) * ρ : E →L[ℂ] E) : E →ₗ[ℂ] E)) := + re_trace_mul_nonneg_of_nonneg (sub_nonneg.mpr hlog) hρ + simp only [sub_mul, ContinuousLinearMap.toLinearMap_sub, map_sub, + ContinuousLinearMap.toLinearMap_mul, + Module.End.mul_eq_comp] at hdiff + linarith [hdiff] + +/-- **The Holevo χ identity.** For a mixture `μ = ∑ᵢ pᵢ ρᵢ` of density operators, the weighted +average of the relative entropies of the components against the mixture equals the concavity gap +(the Holevo χ quantity): + +`∑ᵢ pᵢ D(ρᵢ ‖ μ) = S(μ) − ∑ᵢ pᵢ S(ρᵢ)`. + +A pure trace identity (no constraint on the sign or sum of the `pᵢ`). Each term expands via +`D(ρᵢ ‖ μ) = −S(ρᵢ) − re tr(ρᵢ log μ)` +(`IsDensityOp.quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub`); linearity of the trace over the +mixture (`re_trace_comp_clm_finset_sum_smul`) collapses the weighted sum of cross terms +`∑ᵢ pᵢ re tr(ρᵢ log μ)` to `re tr(μ log μ) = −S(μ)` +(`re_trace_cfc_log_self_eq_neg_vonNeumannEntropy`). + +Combined with the concavity inequality `∑ᵢ pᵢ S(ρᵢ) ≤ S(μ)` this exhibits χ ≥ 0; combined with the +per-term bound `D(ρᵢ ‖ μ) ≤ −log pᵢ` it yields the entropy-of-a-mixture upper bound χ ≤ H(p) +(Nielsen–Chuang Theorem 11.10). -/ +theorem sum_mul_quantumRelativeEntropy_mix {ι : Type*} [Fintype ι] {ρ : ι → E →L[ℂ] E} + (hρ : ∀ i, (ρ i).IsDensityOp) (p : ι → ℝ) {μ : E →L[ℂ] E} (hμ : μ.IsDensityOp) + (hμeq : μ = ∑ i, (p i : ℂ) • ρ i) : + ∑ i, p i * quantumRelativeEntropy (ρ i) μ + = μ.vonNeumannEntropy - ∑ i, p i * (ρ i).vonNeumannEntropy := by + -- The weighted sum of cross terms `∑ᵢ pᵢ re tr(ρᵢ log μ)` collapses to `re tr(μ log μ) = −S(μ)`. + have key : ∑ i, p i * RCLike.re (LinearMap.trace ℂ E + ((cfc Real.log μ).toLinearMap ∘ₗ (ρ i).toLinearMap)) = -μ.vonNeumannEntropy := by + rw [← re_trace_comp_clm_finset_sum_smul (cfc Real.log μ) ρ p, ← hμeq, + hμ.re_trace_cfc_log_self_eq_neg_vonNeumannEntropy] + -- Expand each `D(ρᵢ ‖ μ) = −S(ρᵢ) − re tr(ρᵢ log μ)`. + have hterm : ∀ i, p i * quantumRelativeEntropy (ρ i) μ = + p i * (-(ρ i).vonNeumannEntropy) - + p i * RCLike.re (LinearMap.trace ℂ E + ((cfc Real.log μ).toLinearMap ∘ₗ (ρ i).toLinearMap)) := fun i => by + rw [(hρ i).quantumRelativeEntropy_eq_neg_vonNeumannEntropy_sub]; ring + simp only [hterm, Finset.sum_sub_distrib, key, mul_neg, Finset.sum_neg_distrib] + ring + +end ContinuousLinearMap + +namespace ContinuousLinearMap + +variable {ι : Type*} [Fintype ι] {n : Type*} [Fintype n] + +open scoped ComplexOrder + +-- The `IsStrictlyPositive.smul` / `smul_nonneg` applications need the `PosSMulMono ℝ (E →L[ℂ] E)` +-- instance, whose synthesis on the operator algebra exceeds the default budget. +-- The assembled proof (Loewner order + scaling law + Holevo χ) is elaboration-heavy, as in the +-- sibling `GeneralizedRelativeEntropy` file. +/-- **The entropy of a mixture of quantum states — upper bound** (Nielsen & Chuang, Theorem 11.10, +eq. (11.87)). For a mixture `μ = ∑ᵢ pᵢ ρᵢ` of *strictly positive* density operators `ρᵢ`, weighted +by a family of nonnegative reals `pᵢ`, the von Neumann entropy of the mixture is bounded by the +average entropy of the components plus the Shannon entropy of the weights: + +`S(μ) ≤ ∑ᵢ pᵢ S(ρᵢ) + H(p)`, where `H(p) = Real.entropy p = ∑ᵢ −pᵢ log pᵢ`. + +The proof assembles the two relative-entropy levers with the scaling law. The Holevo χ identity +(`sum_mul_quantumRelativeEntropy_mix`) rewrites the concavity gap as the average relative entropy +`S(μ) − ∑ᵢ pᵢ S(ρᵢ) = ∑ᵢ pᵢ D(ρᵢ ‖ μ)`, and each term is bounded by `−pᵢ log pᵢ = negMulLog pᵢ`: + +* for `pᵢ = 0` the term vanishes (`negMulLog 0 = 0`); +* for `pᵢ > 0`, `D(ρᵢ ‖ μ) ≤ D(ρᵢ ‖ pᵢ • ρᵢ)` by antitonicity in the reference + (`quantumRelativeEntropy_le_of_le_right`, since `pᵢ • ρᵢ ≤ μ` in the Loewner order — the other + summands are positive — and `pᵢ • ρᵢ` is strictly positive), and + `D(ρᵢ ‖ pᵢ • ρᵢ) = −log pᵢ` by the scaling law `quantumRelativeEntropy_smul_smul` at `c = 1`, + `d = pᵢ` (using `D(ρᵢ ‖ ρᵢ) = 0` and `tr ρᵢ = 1`). + +Summing, `∑ᵢ pᵢ D(ρᵢ ‖ μ) ≤ ∑ᵢ negMulLog pᵢ = H(p)`, which is the claim. + +The strict-positivity hypothesis on the components is inherent to this route (the antitonicity lever +requires `pᵢ • ρᵢ` strictly positive); this is the faithful form of the theorem under the +finite-branch faithfulness convention. -/ +theorem IsDensityOp.vonNeumannEntropy_mix_le_sum_add_entropy + {ρ : ι → EuclideanSpace ℂ n →L[ℂ] EuclideanSpace ℂ n} + (hρpos : ∀ i, IsStrictlyPositive (ρ i)) (hρ : ∀ i, (ρ i).IsDensityOp) {p : ι → ℝ} + (hp : ∀ i, 0 ≤ p i) {μ : EuclideanSpace ℂ n →L[ℂ] EuclideanSpace ℂ n} (hμ : μ.IsDensityOp) + (hμeq : μ = ∑ i, (p i : ℂ) • ρ i) : + μ.vonNeumannEntropy ≤ ∑ i, p i * (ρ i).vonNeumannEntropy + Real.entropy p := by + -- `IsScalarTower ℝ ℂ (E →L[ℂ] E)` holds for a concrete Euclidean space but is not a global + -- instance; provide it locally (as in `QuantumRelativeEntropy`). + have : IsScalarTower ℝ ℂ (EuclideanSpace ℂ n →L[ℂ] EuclideanSpace ℂ n) := + IsScalarTower.of_algebraMap_eq fun _ ↦ rfl + -- Rewrite the mixture with real scalars for the Loewner-order argument. + have hμeqR : μ = ∑ i, p i • ρ i := by + rw [hμeq] + exact Finset.sum_congr rfl fun i _ => (RCLike.real_smul_eq_coe_smul (p i) (ρ i)).symm + -- Each component is positive. + have hρnn : ∀ i, 0 ≤ ρ i := fun i => (IsStrictlyPositive.iff_of_unital.mp (hρpos i)).1 + -- Term-by-term bound `pᵢ D(ρᵢ ‖ μ) ≤ negMulLog pᵢ`. + have hterm : ∀ i, p i * (ρ i).quantumRelativeEntropy μ ≤ Real.negMulLog (p i) := by + intro i + rcases (hp i).eq_or_lt with h0 | hpos + · simp [← h0, Real.negMulLog] + · -- `pᵢ • ρᵢ ≤ μ` since the omitted summands are positive. + have hle_op : p i • ρ i ≤ μ := by + rw [hμeqR] + exact Finset.single_le_sum (fun j _ => smul_nonneg (hp j) (hρnn j)) (Finset.mem_univ i) + have hσ : IsStrictlyPositive (p i • ρ i) := IsStrictlyPositive.smul hpos (hρpos i) + -- Antitonicity of the relative entropy in the reference operator. + have hanti : (ρ i).quantumRelativeEntropy μ ≤ (ρ i).quantumRelativeEntropy (p i • ρ i) := + quantumRelativeEntropy_le_of_le_right (hρnn i) hσ hle_op + -- Scaling law: `D(ρᵢ ‖ pᵢ • ρᵢ) = −log pᵢ`. + have hscale : (ρ i).quantumRelativeEntropy (p i • ρ i) = -Real.log (p i) := by + have h := quantumRelativeEntropy_smul_smul (hρpos i) (hρpos i) one_pos hpos + rw [one_smul, quantumRelativeEntropy_self, (hρ i).trace_eq_one] at h + rw [h, RCLike.one_re, one_div, Real.log_inv]; ring + calc p i * (ρ i).quantumRelativeEntropy μ + ≤ p i * (ρ i).quantumRelativeEntropy (p i • ρ i) := + mul_le_mul_of_nonneg_left hanti (le_of_lt hpos) + _ = Real.negMulLog (p i) := by rw [hscale, Real.negMulLog]; ring + -- Assemble via the Holevo χ identity. + have hHolevo := sum_mul_quantumRelativeEntropy_mix hρ p hμ hμeq + have hsum : ∑ i, p i * (ρ i).quantumRelativeEntropy μ ≤ ∑ i, Real.negMulLog (p i) := + Finset.sum_le_sum fun i _ => hterm i + rw [hHolevo] at hsum + have hent : Real.entropy p = ∑ i, Real.negMulLog (p i) := rfl + linarith [hsum, hent] + +end ContinuousLinearMap diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HermitianMajorization.lean b/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HermitianMajorization.lean new file mode 100644 index 0000000000..df15479fc9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HermitianMajorization.lean @@ -0,0 +1,261 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Matrix.Spectrum +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.Majorization +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.PermutationUnitary + +/-! +# Majorization of Hermitian matrices + +For Hermitian matrices `H`, `K` over an `RCLike` field, Nielsen and Chuang write `H ≺ K` to mean +that the vector of eigenvalues of `H` is majorized by that of `K`, `λ(H) ≺ λ(K)` (`Majorize`, from +`ToMathlib/Analysis/Convex/Majorization.lean`). This file records that relation as +`Matrix.IsHermitian.Majorize` and proves the operator majorization theorem (Nielsen–Chuang, +*Quantum Computation and Quantum Information*, Theorem 12.13): + +> `H ≺ K` if and only if `H = ∑ⱼ pⱼ Uⱼ K Uⱼ†` for a probability distribution `pⱼ` and unitaries +> `Uⱼ`. + +The "easy" (mixture ⟹ majorization) direction works in the joint picture supplied by the spectral +theorem: writing +`Λ(H) = star P * H * P` and `K = Q * Λ(K) * star Q` for the eigenvector unitaries `P`, `Q`, the +hypothesis becomes `Λ(H) = ∑ⱼ pⱼ Vⱼ Λ(K) Vⱼ†` with `Vⱼ = star P * Uⱼ * Q` unitary. Reading off +the `(k, k)` diagonal entry gives `λ(H) = D *ᵥ λ(K)` for the real matrix `D k l = ∑ⱼ pⱼ ‖Vⱼ k l‖²`, +which +is doubly stochastic because the rows and columns of each `Vⱼ` are unit vectors; the conclusion is +then `Majorize.of_mem_doublyStochastic`. + +The converse (majorization ⟹ mixture) is the substance of Theorem 12.13. From `H ≺ K` — i.e. +`λ(H) ≺ λ(K)` — Proposition 12.11 (`majorize_iff_exists_sum_perm`) supplies convex weights `w` over +permutations `σ` with `λ(H) = ∑_σ wσ (λ(K) ∘ σ)`. Lifting to the diagonal picture via +`permMatrix_mul_diagonal_mul_conjTranspose` (a permutation matrix conjugates a diagonal matrix to +the permuted diagonal) and assembling with the spectral theorem gives +`H = ∑_σ wσ Uσ K Uσ†` with `Uσ = P · Pσ · Q†` unitary, where `P`, `Q` diagonalise `H`, `K`. + +## Main definitions + +* `Matrix.IsHermitian.Majorize hH hK`: the eigenvalues of `H` are majorized by those of `K`. + +## Main statements + +* `Matrix.sum_sq_norm_row_of_mem_unitaryGroup`, `Matrix.sum_sq_norm_col_of_mem_unitaryGroup`: the + entries in each row (resp. column) of a unitary matrix have squared norms summing to `1`. +* `Matrix.IsHermitian.majorize_of_eq_sum_smul_unitary_conj`: the "mixture implies majorization" + direction of Theorem 12.13. +* `Matrix.IsHermitian.exists_eq_sum_smul_unitary_conj_of_majorize`: the converse "majorization + implies mixture" direction. +* `Matrix.IsHermitian.majorize_iff_exists_sum_smul_unitary_conj`: Theorem 12.13 itself, the + biconditional `H ≺ K ↔ H = ∑ⱼ pⱼ Uⱼ K Uⱼ†`. + +## Tags + +majorization, Hermitian matrix, doubly stochastic, unitary +-/ + +public section + +open Finset Matrix + +namespace Matrix + +variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] [DecidableEq n] + +/-- The squared norms of the entries in a single row of a unitary matrix sum to `1` +(the rows of a unitary matrix are unit vectors). -/ +lemma sum_sq_norm_row_of_mem_unitaryGroup {U : Matrix n n 𝕜} (hU : U ∈ unitaryGroup n 𝕜) (k : n) : + ∑ l, ‖U k l‖ ^ 2 = 1 := by + have h1 : (U * star U) k k = 1 := by rw [mem_unitaryGroup_iff.mp hU, Matrix.one_apply_eq] + have h2 : (U * star U) k k = ((∑ l, ‖U k l‖ ^ 2 : ℝ) : 𝕜) := by + rw [Matrix.mul_apply, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [Matrix.star_apply, ← starRingEnd_apply, RCLike.mul_conj, RCLike.ofReal_pow] + exact_mod_cast h2.symm.trans h1 + +/-- The squared norms of the entries in a single column of a unitary matrix sum to `1` +(the columns of a unitary matrix are unit vectors). -/ +lemma sum_sq_norm_col_of_mem_unitaryGroup {U : Matrix n n 𝕜} (hU : U ∈ unitaryGroup n 𝕜) (l : n) : + ∑ k, ‖U k l‖ ^ 2 = 1 := by + have h1 : (star U * U) l l = 1 := by rw [mem_unitaryGroup_iff'.mp hU, Matrix.one_apply_eq] + have h2 : (star U * U) l l = ((∑ k, ‖U k l‖ ^ 2 : ℝ) : 𝕜) := by + rw [Matrix.mul_apply, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun k _ => ?_ + rw [Matrix.star_apply, ← starRingEnd_apply, RCLike.conj_mul, RCLike.ofReal_pow] + exact_mod_cast h2.symm.trans h1 + +/-- The `(k, k)` diagonal entry of a diagonal matrix conjugated by `A`. For a real vector `d`, +`(A * diagonal (↑ ∘ d) * Aᴴ) k k = ∑ l, d l * ‖A k l‖²` (cast into `𝕜`): the diagonal of a +unitary-style conjugation of a real diagonal matrix is a real combination of the diagonal entries +weighted by the squared entry norms. -/ +lemma diag_mul_diagonal_mul_conjTranspose (A : Matrix n n 𝕜) (d : n → ℝ) (k : n) : + (A * diagonal ((RCLike.ofReal : ℝ → 𝕜) ∘ d) * star A) k k + = ((∑ l, d l * ‖A k l‖ ^ 2 : ℝ) : 𝕜) := by + rw [Matrix.mul_apply, RCLike.ofReal_sum] + refine Finset.sum_congr rfl fun l _ => ?_ + rw [Matrix.mul_diagonal, Matrix.star_apply, Function.comp_apply, ← starRingEnd_apply, + mul_right_comm, RCLike.mul_conj] + push_cast + ring + +namespace IsHermitian + +variable {H K : Matrix n n 𝕜} + +/-- Majorization of Hermitian matrices (Nielsen–Chuang §12.5): `hH.Majorize hK` means the vector of +eigenvalues of `H` is majorized by that of `K`. Written `H ≺ K` in Nielsen and Chuang. -/ +def Majorize (hH : H.IsHermitian) (hK : K.IsHermitian) : Prop := + _root_.Majorize hH.eigenvalues hK.eigenvalues + +/-- The "mixture implies majorization" direction of Nielsen–Chuang Theorem 12.13: if a Hermitian +matrix `H` is a probabilistic mixture `H = ∑ⱼ pⱼ Uⱼ K Uⱼ†` of unitary conjugates of a Hermitian +matrix `K`, then `H ≺ K`, i.e. the eigenvalues of `H` are majorized by those of `K`. -/ +theorem majorize_of_eq_sum_smul_unitary_conj (hH : H.IsHermitian) (hK : K.IsHermitian) + {ι : Type*} [Fintype ι] {p : ι → ℝ} {U : ι → Matrix n n 𝕜} + (hp : ∀ j, 0 ≤ p j) (hp1 : ∑ j, p j = 1) (hU : ∀ j, U j ∈ unitaryGroup n 𝕜) + (hHK : H = ∑ j, p j • (U j * K * (U j)ᴴ)) : + hH.Majorize hK := by + set P : Matrix n n 𝕜 := (hH.eigenvectorUnitary : Matrix n n 𝕜) with hP + set Q : Matrix n n 𝕜 := (hK.eigenvectorUnitary : Matrix n n 𝕜) with hQ + -- Spectral diagonalizations: `star P * H * P = Λ(H)` and `K = Q * Λ(K) * star Q`. + have hLH : star P * H * P = diagonal (RCLike.ofReal ∘ hH.eigenvalues) := by + simpa only [Unitary.conjStarAlgAut_star_apply, ← hP] using + hH.conjStarAlgAut_star_eigenvectorUnitary + have hKs : K = Q * diagonal (RCLike.ofReal ∘ hK.eigenvalues) * star Q := by + simpa only [Unitary.conjStarAlgAut_apply, ← hQ] using hK.spectral_theorem + -- The conjugating unitaries `Vⱼ = star P * Uⱼ * Q` and the extracted real matrix `D`. + set V : ι → Matrix n n 𝕜 := fun j => star P * U j * Q with hV + set D : Matrix n n ℝ := fun k l => ∑ j, p j * ‖V j k l‖ ^ 2 with hD + have hVunit : ∀ j, V j ∈ unitaryGroup n 𝕜 := by + intro j + simp only [hV, hP, hQ] + exact mul_mem (mul_mem (Unitary.star_mem (SetLike.coe_mem _)) (hU j)) (SetLike.coe_mem _) + -- `Λ(H) = ∑ⱼ pⱼ Vⱼ Λ(K) Vⱼ†`. + have hstar : diagonal (RCLike.ofReal ∘ hH.eigenvalues) + = ∑ j, p j • (V j * diagonal (RCLike.ofReal ∘ hK.eigenvalues) * star (V j)) := by + rw [← hLH, hHK, Finset.mul_sum, Finset.sum_mul] + refine Finset.sum_congr rfl fun j _ => ?_ + rw [mul_smul_comm, smul_mul_assoc] + congr 1 + simp only [hV, hKs, ← Matrix.star_eq_conjTranspose, star_mul, star_star, mul_assoc] + -- Read off the `(k, k)` entry to obtain `λ(H) = D *ᵥ λ(K)`. + have key : hH.eigenvalues = D *ᵥ hK.eigenvalues := by + funext k + have hkk := congrFun (congrFun hstar k) k + rw [Matrix.diagonal_apply_eq, Matrix.sum_apply, Function.comp_apply] at hkk + simp only [Matrix.smul_apply, diag_mul_diagonal_mul_conjTranspose, + RCLike.real_smul_eq_coe_mul, ← RCLike.ofReal_mul, ← RCLike.ofReal_sum] at hkk + have hkk' := RCLike.ofReal_injective hkk + have hmulvec : (D *ᵥ hK.eigenvalues) k + = ∑ l, (∑ j, p j * ‖V j k l‖ ^ 2) * hK.eigenvalues l := by simp only [hD]; rfl + rw [hkk', hmulvec] + simp_rw [Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun l _ => Finset.sum_congr rfl fun j _ => by ring + -- `D` is doubly stochastic, so `D *ᵥ λ(K) ≺ λ(K)`. + have hDds : D ∈ doublyStochastic ℝ n := by + rw [mem_doublyStochastic_iff_sum] + refine ⟨fun k l => ?_, fun k => ?_, fun l => ?_⟩ + · exact Finset.sum_nonneg fun j _ => mul_nonneg (hp j) (sq_nonneg _) + · simp only [hD] + rw [Finset.sum_comm] + have hrow : ∀ j, ∑ l, p j * ‖V j k l‖ ^ 2 = p j := fun j => by + rw [← Finset.mul_sum, sum_sq_norm_row_of_mem_unitaryGroup (hVunit j) k, mul_one] + simp_rw [hrow]; exact hp1 + · simp only [hD] + rw [Finset.sum_comm] + have hcol : ∀ j, ∑ k, p j * ‖V j k l‖ ^ 2 = p j := fun j => by + rw [← Finset.mul_sum, sum_sq_norm_col_of_mem_unitaryGroup (hVunit j) l, mul_one] + simp_rw [hcol]; exact hp1 + have hmaj := _root_.Majorize.of_mem_doublyStochastic hDds hK.eigenvalues + rw [← key] at hmaj + exact hmaj + +/-- The "majorization implies mixture" direction of Nielsen–Chuang Theorem 12.13: if a Hermitian +matrix `H` is majorized by a Hermitian matrix `K` (`H ≺ K`), then `H` is a probabilistic mixture of +unitary conjugates of `K`, `H = ∑_σ pσ Uσ K Uσ†`. The mixture is indexed by the permutations `σ` +of `n`: with `w` the convex weights of Proposition 12.11 (`majorize_iff_exists_sum_perm`) for the +eigenvalue majorization `λ(H) ≺ λ(K)`, the conjugating unitaries are `Uσ = P · Pσ · Q†`, where +`P`, `Q` diagonalise `H`, `K` and `Pσ` is the permutation matrix of `σ`. -/ +theorem exists_eq_sum_smul_unitary_conj_of_majorize (hH : H.IsHermitian) (hK : K.IsHermitian) + (hHK : hH.Majorize hK) : + ∃ (p : Equiv.Perm n → ℝ) (U : Equiv.Perm n → Matrix n n 𝕜), + (∀ σ, 0 ≤ p σ) ∧ (∑ σ, p σ = 1) ∧ (∀ σ, U σ ∈ unitaryGroup n 𝕜) ∧ + H = ∑ σ, p σ • (U σ * K * (U σ)ᴴ) := by + obtain ⟨w, hwpos, hwsum, hweq⟩ := majorize_iff_exists_sum_perm.mp hHK + set P : Matrix n n 𝕜 := (hH.eigenvectorUnitary : Matrix n n 𝕜) with hP + set Q : Matrix n n 𝕜 := (hK.eigenvectorUnitary : Matrix n n 𝕜) with hQ + have hPmem : P ∈ unitaryGroup n 𝕜 := SetLike.coe_mem _ + have hQmem : Q ∈ unitaryGroup n 𝕜 := SetLike.coe_mem _ + have hQQ : star Q * Q = 1 := mem_unitaryGroup_iff'.mp hQmem + have hc : ∀ X : Matrix n n 𝕜, star Q * (Q * X) = X := fun X => by rw [← mul_assoc, hQQ, one_mul] + -- Spectral decompositions `H = P · Λ(H) · P†`, `K = Q · Λ(K) · Q†`. + have hHspec : H = P * diagonal (RCLike.ofReal ∘ hH.eigenvalues) * star P := by + simpa only [Unitary.conjStarAlgAut_apply, ← hP] using hH.spectral_theorem + have hKspec : K = Q * diagonal (RCLike.ofReal ∘ hK.eigenvalues) * star Q := by + simpa only [Unitary.conjStarAlgAut_apply, ← hQ] using hK.spectral_theorem + -- Lift `λ(H) = ∑_σ wσ (λ(K) ∘ σ)` to the diagonal matrices. + have hdiag : diagonal ((RCLike.ofReal : ℝ → 𝕜) ∘ hH.eigenvalues) + = ∑ σ, w σ • diagonal (((RCLike.ofReal : ℝ → 𝕜) ∘ hK.eigenvalues) ∘ (σ : n → n)) := by + ext i j + by_cases h : i = j + · subst h + simp only [Matrix.sum_apply, Matrix.smul_apply, diagonal_apply_eq, Function.comp_apply] + have hi := congrFun hweq i + rw [Finset.sum_apply] at hi + simp only [Pi.smul_apply, permMatrix_mulVec, Function.comp_apply, smul_eq_mul] at hi + rw [hi, RCLike.ofReal_sum] + exact Finset.sum_congr rfl fun σ _ => by + rw [RCLike.ofReal_mul, RCLike.real_smul_eq_coe_mul] + · simp only [Matrix.sum_apply, Matrix.smul_apply, diagonal_apply_ne _ h, smul_zero, + Finset.sum_const_zero] + refine ⟨w, fun σ => P * σ.permMatrix 𝕜 * star Q, hwpos, hwsum, fun σ => + mul_mem (mul_mem hPmem (permMatrix_mem_unitaryGroup σ)) (Unitary.star_mem hQmem), ?_⟩ + -- Each mixture term collapses to `P · diagonal(λ(K) ∘ σ) · P†`. + have hterm : ∀ σ : Equiv.Perm n, + (P * σ.permMatrix 𝕜 * star Q) * K * (P * σ.permMatrix 𝕜 * star Q)ᴴ + = P * diagonal ((RCLike.ofReal ∘ hK.eigenvalues) ∘ (σ : n → n)) * star P := by + intro σ + -- Substitute only the standalone `K` (not the `K` implicit in `hK.eigenvalues` on the right). + conv_lhs => rw [hKspec] + rw [← permMatrix_mul_diagonal_mul_conjTranspose σ ((RCLike.ofReal : ℝ → 𝕜) ∘ hK.eigenvalues)] + simp only [← star_eq_conjTranspose, star_mul, star_star, mul_assoc] + rw [hc, hc] + calc H = P * diagonal (RCLike.ofReal ∘ hH.eigenvalues) * star P := hHspec + _ = P * (∑ σ, w σ • diagonal ((RCLike.ofReal ∘ hK.eigenvalues) ∘ (σ : n → n))) * star P := by + rw [hdiag] + _ = ∑ σ, w σ • (P * diagonal ((RCLike.ofReal ∘ hK.eigenvalues) ∘ (σ : n → n)) * star P) := by + rw [Finset.mul_sum, Finset.sum_mul] + exact Finset.sum_congr rfl fun σ _ => by rw [mul_smul_comm, smul_mul_assoc] + _ = ∑ σ, w σ • ((P * σ.permMatrix 𝕜 * star Q) * K * (P * σ.permMatrix 𝕜 * star Q)ᴴ) := + Finset.sum_congr rfl fun σ _ => by rw [hterm] + +/-- **Nielsen–Chuang Theorem 12.13** (Uhlmann's operator majorization theorem): for Hermitian +matrices `H`, `K`, the eigenvalues of `H` are majorized by those of `K` (`H ≺ K`) if and only if +`H` is a probabilistic mixture of unitary conjugates of `K`, `H = ∑ⱼ pⱼ Uⱼ K Uⱼ†` for some +probability distribution `pⱼ` and unitaries `Uⱼ`. -/ +theorem majorize_iff_exists_sum_smul_unitary_conj (hH : H.IsHermitian) (hK : K.IsHermitian) : + hH.Majorize hK ↔ + ∃ (m : ℕ) (p : Fin m → ℝ) (U : Fin m → Matrix n n 𝕜), + (∀ j, 0 ≤ p j) ∧ (∑ j, p j = 1) ∧ (∀ j, U j ∈ unitaryGroup n 𝕜) ∧ + H = ∑ j, p j • (U j * K * (U j)ᴴ) := by + refine ⟨fun hHK => ?_, ?_⟩ + · obtain ⟨p, U, hp, hp1, hU, hHK'⟩ := hH.exists_eq_sum_smul_unitary_conj_of_majorize hK hHK + refine ⟨Fintype.card (Equiv.Perm n), p ∘ (Fintype.equivFin (Equiv.Perm n)).symm, + U ∘ (Fintype.equivFin (Equiv.Perm n)).symm, fun j => hp _, ?_, fun j => hU _, ?_⟩ + · exact (Equiv.sum_comp (Fintype.equivFin (Equiv.Perm n)).symm p).trans hp1 + · rw [hHK'] + exact (Equiv.sum_comp (Fintype.equivFin (Equiv.Perm n)).symm + (fun σ => p σ • (U σ * K * (U σ)ᴴ))).symm + · rintro ⟨m, p, U, hp, hp1, hU, hHK⟩ + exact hH.majorize_of_eq_sum_smul_unitary_conj hK hp hp1 hU hHK + +end IsHermitian + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HilbertSchmidt.lean b/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HilbertSchmidt.lean new file mode 100644 index 0000000000..b74b8306c5 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Matrix/HilbertSchmidt.lean @@ -0,0 +1,299 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.PosDef +public import Mathlib.LinearAlgebra.Dimension.Constructions +public import Mathlib.Analysis.InnerProductSpace.Defs +public import Mathlib.Data.Matrix.Basis +public import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas +public import Mathlib.Tactic.TypeStar +public import Mathlib.Analysis.Complex.Basic + +/-! +# The Hilbert–Schmidt inner product on matrices + +For a finite index type `n` and an `RCLike` field `𝕜`, the space `Matrix n n 𝕜` of operators on +`𝕜ⁿ` carries the **Hilbert–Schmidt** (or **trace**) inner product +`(A, B) = tr(Aᴴ * B)`. This file records that `(·, ·)` is genuinely an inner product, computes +the dimension of the operator space, and exhibits an orthonormal basis of Hermitian matrices — +**Nielsen & Chuang, Exercise 2.39** (*Quantum Computation and Quantum Information*, §2.1.8, +eq. (2.65)), parts (1), (2) and (3). + +## Main definitions and results + +* `Matrix.hsInner`: the Hilbert–Schmidt inner product `(A, B) = tr(Aᴴ * B)` as a bare function. +* `Matrix.hsInnerCore`: the proof that `Matrix.hsInner` is an inner product, packaged as an + `InnerProductSpace.Core` — this is part (1) of the exercise. Its fields are exactly the inner + product axioms: conjugate symmetry, positive semidefiniteness, definiteness, additivity, and + conjugate linearity in the first argument. +* `Matrix.finrank_eq_card_sq`: `Module.finrank 𝕜 (Matrix n n 𝕜) = (Fintype.card n) ^ 2` — part (2) + of the exercise (`dim L_V = d²` for `dim V = d`). +* `Matrix.gellMann` (over `ℂ`, with `n` linearly ordered): the generalised Gell–Mann family of `d²` + Hermitian matrices, shown to be Hermitian (`Matrix.gellMann_isHermitian`) and orthonormal under + `Matrix.hsInner` (`Matrix.gellMann_orthonormal`); `Matrix.hermitianOrthonormalBasis` bundles them + into a `Module.Basis (n × n) ℂ (Matrix n n ℂ)` — this is part (3). + +## Implementation notes + +Mathlib's convention makes an inner product conjugate-linear in its *first* argument, which matches +N&C's `(A, B) = tr(Aᴴ * B)` (the adjoint sits on the first slot). The two nontrivial axioms reduce +to standard facts about `Aᴴ * A`: it is positive semidefinite +(`Matrix.posSemidef_conjTranspose_mul_self`), so its trace is nonnegative +(`Matrix.PosSemidef.trace_nonneg`), and its trace vanishes only for `A = 0` +(`Matrix.trace_conjTranspose_mul_self_eq_zero_iff`). This is the `M = 1` case of the general inner +product `⟪x, y⟫ = tr(y * M * xᴴ)` induced by a positive semidefinite `M` +(`Matrix.toMatrixInnerProductSpace`); we give the trace inner product its own name because it is the +canonical structure referred to throughout quantum information theory and because an explicit +`Matrix.hsInner` function is convenient for orthonormality computations. + +The dimension count is the diagonal, `𝕜`-valued case of `Module.finrank_matrix` +(`finrank R (Matrix m n M) = card m * card n * finrank R M`) with `card m = card n = d` and +`finrank 𝕜 𝕜 = 1`. +-/ + +@[expose] public section + +open scoped Matrix ComplexOrder + +namespace Matrix + +variable {𝕜 n : Type*} [RCLike 𝕜] [Fintype n] + +/-- The **Hilbert–Schmidt** (or **trace**) inner product on operators, `(A, B) = tr(Aᴴ * B)` +(Nielsen & Chuang eq. (2.65)). -/ +def hsInner (A B : Matrix n n 𝕜) : 𝕜 := (Aᴴ * B).trace + +theorem hsInner_apply (A B : Matrix n n 𝕜) : hsInner A B = (Aᴴ * B).trace := rfl + +section Bilinear + +/-- Additivity of `hsInner` in the first argument. -/ +theorem hsInner_add_left (A B C : Matrix n n 𝕜) : + hsInner (A + B) C = hsInner A C + hsInner B C := by + simp only [hsInner_apply, conjTranspose_add, add_mul, trace_add] + +/-- Subtractivity of `hsInner` in the first argument. -/ +theorem hsInner_sub_left (A B C : Matrix n n 𝕜) : + hsInner (A - B) C = hsInner A C - hsInner B C := by + simp only [hsInner_apply, conjTranspose_sub, sub_mul, trace_sub] + +/-- `hsInner` is conjugate-linear in the first argument. -/ +theorem hsInner_smul_left (r : 𝕜) (A B : Matrix n n 𝕜) : + hsInner (r • A) B = starRingEnd 𝕜 r * hsInner A B := by + simp only [hsInner_apply, conjTranspose_smul, smul_mul_assoc, trace_smul, smul_eq_mul, + starRingEnd_apply] + +/-- `hsInner` is linear in the second argument (scalar multiplication). -/ +theorem hsInner_smul_right (r : 𝕜) (A B : Matrix n n 𝕜) : + hsInner A (r • B) = r * hsInner A B := by + simp only [hsInner_apply, mul_smul_comm, trace_smul, smul_eq_mul] + +@[simp] +theorem hsInner_zero_right (A : Matrix n n 𝕜) : hsInner A 0 = 0 := by + simp only [hsInner_apply, mul_zero, trace_zero] + +/-- `hsInner` distributes over a finite sum in the second argument. -/ +theorem hsInner_sum_right {ι : Type*} (A : Matrix n n 𝕜) (s : Finset ι) + (f : ι → Matrix n n 𝕜) : hsInner A (∑ i ∈ s, f i) = ∑ i ∈ s, hsInner A (f i) := by + simp only [hsInner_apply, Matrix.mul_sum, Matrix.trace_sum] + +end Bilinear + +/-- **Nielsen & Chuang, Exercise 2.39 (1).** The Hilbert–Schmidt form `(A, B) = tr(Aᴴ * B)` is an +inner product on `Matrix n n 𝕜`, packaged as an `InnerProductSpace.Core`. Its fields are the inner +product axioms: conjugate symmetry, nonnegativity of `(A, A)`, definiteness, additivity in the +first argument (`hsInner_add_left`), and conjugate linearity in the first argument +(`hsInner_smul_left`). -/ +@[implicit_reducible] +noncomputable def hsInnerCore : InnerProductSpace.Core 𝕜 (Matrix n n 𝕜) where + inner A B := hsInner A B + conj_inner_symm A B := by + simp only [hsInner_apply, starRingEnd_apply, ← trace_conjTranspose, conjTranspose_mul, + conjTranspose_conjTranspose] + re_inner_nonneg A := by + simp only [hsInner_apply] + exact (RCLike.nonneg_iff.mp (posSemidef_conjTranspose_mul_self A).trace_nonneg).1 + add_left A B C := hsInner_add_left A B C + smul_left A B r := hsInner_smul_left r A B + definite A h := trace_conjTranspose_mul_self_eq_zero_iff.mp h + +/-- **Nielsen & Chuang, Exercise 2.39 (2).** If `V` is a Hilbert space of dimension `d`, then the +operator space `L_V` has dimension `d²`. In the matrix picture `L_V = Matrix n n 𝕜` with +`d = Fintype.card n`, so `Module.finrank 𝕜 (Matrix n n 𝕜) = (Fintype.card n) ^ 2`. -/ +theorem finrank_eq_card_sq : + Module.finrank 𝕜 (Matrix n n 𝕜) = Fintype.card n ^ 2 := by + rw [Module.finrank_matrix, Module.finrank_self, mul_one, sq] + +/-- For Hermitian `A` and `B`, the trace `tr(A * B)` is real: its imaginary part vanishes. +Indeed `conj tr(A B) = tr((A B)ᴴ) = tr(Bᴴ Aᴴ) = tr(B A) = tr(A B)`, using `Aᴴ = A`, `Bᴴ = B` and +the cyclicity of the trace. Equivalently, the Hilbert–Schmidt inner product `⟪A, B⟫ = tr(Aᴴ * B)` +of two Hermitian matrices is real. -/ +theorem IsHermitian.im_trace_mul {A B : Matrix n n 𝕜} (hA : A.IsHermitian) (hB : B.IsHermitian) : + RCLike.im (A * B).trace = 0 := by + rw [← RCLike.conj_eq_iff_im, starRingEnd_apply, ← trace_conjTranspose, conjTranspose_mul, + hA, hB, trace_mul_comm] + +section MatrixUnits + +variable [DecidableEq n] + +/-- The Hilbert–Schmidt inner product against a matrix unit reads off an entry: +`⟪single a b 1, M⟫ = M a b`. -/ +theorem hsInner_single_left (a b : n) (M : Matrix n n 𝕜) : + hsInner (single a b 1) M = M a b := by + rw [hsInner_apply, conjTranspose_single, star_one, trace_single_mul, one_smul] + +/-- The matrix units `single a b 1` are orthonormal under the Hilbert–Schmidt inner product. -/ +theorem hsInner_single_single (a b c d : n) : + hsInner (single a b (1 : 𝕜)) (single c d 1) = if c = a ∧ d = b then 1 else 0 := by + rw [hsInner_single_left, single_apply] + +end MatrixUnits + +section HermitianBasis + +variable {n : Type*} [Fintype n] [DecidableEq n] [LinearOrder n] + +/-- The normalisation `(√2)⁻¹` is fixed by complex conjugation (it is real). -/ +theorem conj_sqrt2inv : starRingEnd ℂ ((Real.sqrt 2 : ℂ)⁻¹) = (Real.sqrt 2 : ℂ)⁻¹ := by + rw [← Complex.ofReal_inv, Complex.conj_ofReal] + +/-- `(√2)⁻¹ · (√2)⁻¹ = 2⁻¹`. -/ +theorem sqrt2inv_mul_self : ((Real.sqrt 2 : ℂ)⁻¹) * ((Real.sqrt 2 : ℂ)⁻¹) = 2⁻¹ := by + rw [← Complex.ofReal_inv, ← Complex.ofReal_mul, ← mul_inv, + Real.mul_self_sqrt (by norm_num : (0 : ℝ) ≤ 2)] + norm_num + +/-- `((√2)⁻¹)² = 2⁻¹`. -/ +theorem sqrt2inv_sq : ((Real.sqrt 2 : ℂ)⁻¹) ^ 2 = 2⁻¹ := by + rw [sq, sqrt2inv_mul_self] + + + +/-- The **generalised Gell–Mann family**: `d²` Hermitian matrices indexed by `n × n`. For `j < k` +the symmetric combination `(Eⱼₖ + Eₖⱼ)/√2`, for `j > k` the antisymmetric `i(Eₖⱼ − Eⱼₖ)/√2`, and +on the diagonal the matrix unit `Eⱼⱼ`. They form an orthonormal (under `Matrix.hsInner`) basis of +Hermitian matrices for `L_V` — **Nielsen & Chuang, Exercise 2.39 (3)**. -/ +noncomputable def gellMann (p : n × n) : Matrix n n ℂ := + if p.1 < p.2 then (Real.sqrt 2 : ℂ)⁻¹ • (single p.1 p.2 1 + single p.2 p.1 1) + else if p.2 < p.1 then + (Real.sqrt 2 : ℂ)⁻¹ • (Complex.I • (single p.2 p.1 1 - single p.1 p.2 1)) + else single p.1 p.1 1 + +omit [Fintype n] in +/-- Every member of the generalised Gell–Mann family is Hermitian. -/ +theorem gellMann_isHermitian (p : n × n) : (gellMann p).IsHermitian := by + rw [gellMann, IsHermitian] + split_ifs with h1 h2 + · simp only [conjTranspose_smul, conjTranspose_add, conjTranspose_single, Complex.star_def, + map_one, conj_sqrt2inv] + module + · simp only [conjTranspose_smul, conjTranspose_sub, conjTranspose_single, Complex.star_def, + map_one, conj_sqrt2inv, Complex.conj_I] + module + · rw [conjTranspose_single, star_one] + +/-- Reading the Hilbert–Schmidt inner product of a Gell–Mann matrix against an arbitrary `M` +in terms of the entries of `M`. -/ +theorem hsInner_gellMann_left (p : n × n) (M : Matrix n n ℂ) : + hsInner (gellMann p) M = + if p.1 < p.2 then (Real.sqrt 2 : ℂ)⁻¹ * (M p.1 p.2 + M p.2 p.1) + else if p.2 < p.1 then (Real.sqrt 2 : ℂ)⁻¹ * Complex.I * (M p.1 p.2 - M p.2 p.1) + else M p.1 p.1 := by + rw [gellMann] + split_ifs with h1 h2 + · rw [hsInner_smul_left, hsInner_add_left, hsInner_single_left, hsInner_single_left, + conj_sqrt2inv] + · rw [hsInner_smul_left, hsInner_smul_left, hsInner_sub_left, hsInner_single_left, + hsInner_single_left, conj_sqrt2inv, Complex.conj_I] + ring + · rw [hsInner_single_left] + +omit [Fintype n] in +/-- Entrywise values of a Gell–Mann matrix, in terms of matrix-unit entries. -/ +theorem gellMann_apply (p : n × n) (a b : n) : + (gellMann p) a b = + if p.1 < p.2 then + (Real.sqrt 2 : ℂ)⁻¹ * (single p.1 p.2 (1 : ℂ) a b + single p.2 p.1 1 a b) + else if p.2 < p.1 then + (Real.sqrt 2 : ℂ)⁻¹ * Complex.I * (single p.2 p.1 (1 : ℂ) a b - single p.1 p.2 1 a b) + else single p.1 p.1 (1 : ℂ) a b := by + rw [gellMann] + split_ifs with h1 h2 <;> + simp only [Matrix.smul_apply, Matrix.add_apply, Matrix.sub_apply, smul_eq_mul, mul_assoc] + +/-- The generalised Gell–Mann family is orthonormal for the Hilbert–Schmidt inner product +(Nielsen & Chuang, Exercise 2.39). -/ +theorem gellMann_orthonormal (p q : n × n) : + hsInner (gellMann p) (gellMann q) = if p = q then 1 else 0 := by + obtain ⟨x, y⟩ := p + obtain ⟨s, t⟩ := q + classical + rw [hsInner_gellMann_left] + simp only [gellMann_apply, single_apply, Prod.ext_iff] + rcases lt_trichotomy x y with hxy | rfl | hxy <;> + rcases lt_trichotomy s t with hst | rfl | hst <;> + try have := lt_asymm hxy + all_goals + try have := lt_asymm hst + simp only [*, lt_irrefl, and_self, and_comm, eq_comm, ite_true, ite_false] + all_goals + split_ifs <;> + first + | (exfalso; casesm* _ ∧ _; subst_vars; first | order | tauto) + | (ring_nf; rw [sqrt2inv_sq]; norm_num) + | ring + +omit [Fintype n] in +/-- The generalised Gell–Mann family is linearly independent (being orthonormal under a genuine +inner product). The `Fintype n` instance is used only in the proof (via the inner product's +finite trace), not in the statement type. -/ +theorem gellMann_linearIndependent [Finite n] : LinearIndependent ℂ (gellMann (n := n)) := by + let _ := Fintype.ofFinite n + rw [Fintype.linearIndependent_iff] + intro g hg q + have hz : hsInner (gellMann q) (∑ p, g p • gellMann p) = 0 := by + rw [hg]; exact hsInner_zero_right _ + rw [hsInner_sum_right] at hz + simp only [hsInner_smul_right, gellMann_orthonormal, mul_ite, mul_one, mul_zero, + Finset.sum_ite_eq, Finset.mem_univ, ite_true] at hz + exact hz + +variable [Nonempty n] + +/-- **Nielsen & Chuang, Exercise 2.39 (3).** The generalised Gell–Mann family is an (orthonormal, +Hermitian) basis of the operator space `L_V = Matrix n n ℂ`, indexed by `n × n`, hence of dimension +`d² = (Fintype.card n)²`. Its members are Hermitian (`hermitianOrthonormalBasis_isHermitian`) and +orthonormal under the Hilbert–Schmidt inner product (`hermitianOrthonormalBasis_orthonormal`). -/ +noncomputable def hermitianOrthonormalBasis : Module.Basis (n × n) ℂ (Matrix n n ℂ) := + basisOfLinearIndependentOfCardEqFinrank gellMann_linearIndependent + (by rw [Fintype.card_prod, finrank_eq_card_sq, sq]) + +@[simp] +theorem hermitianOrthonormalBasis_apply (p : n × n) : hermitianOrthonormalBasis p = gellMann p := + congrFun (coe_basisOfLinearIndependentOfCardEqFinrank _ _) p + +/-- Every member of the orthonormal Hermitian basis is Hermitian. -/ +theorem hermitianOrthonormalBasis_isHermitian (p : n × n) : + (hermitianOrthonormalBasis p).IsHermitian := by + rw [hermitianOrthonormalBasis_apply]; exact gellMann_isHermitian p + +/-- The orthonormal Hermitian basis is orthonormal under the Hilbert–Schmidt inner product. -/ +theorem hermitianOrthonormalBasis_orthonormal (p q : n × n) : + hsInner (hermitianOrthonormalBasis p) (hermitianOrthonormalBasis q) = + if p = q then 1 else 0 := by + rw [hermitianOrthonormalBasis_apply, hermitianOrthonormalBasis_apply] + exact gellMann_orthonormal p q + +end HermitianBasis + +end Matrix + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/ExponentialInvolution.lean b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/ExponentialInvolution.lean new file mode 100644 index 0000000000..33c88866a2 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/ExponentialInvolution.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Normed.Algebra.Exponential +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Series +public import Mathlib.Analysis.Complex.Trigonometric + +/-! +# The exponential of a scalar multiple of an involution + +Let `𝔸` be a normed `ℂ`-algebra and `a : 𝔸` an element with `a * a = 1` (an *involution*, +e.g. a Pauli matrix, a reflection, or any square root of `1`). This file gives the closed form of +its complex exponential: + +`NormedSpace.exp (z • a) = Complex.cosh z • 1 + Complex.sinh z • a`. + +The proof is the even/odd split of the exponential power series: `(z • a) ^ n = zⁿ • aⁿ` with +`aⁿ = 1` for even `n` and `aⁿ = a` for odd `n`, so the even terms sum (via `Complex.hasSum_cosh`) +to `cosh z • 1` and the odd terms (via `Complex.hasSum_sinh`) to `sinh z • a`. This is the abstract +core of the Euler-type "spin rotation" identity + +`exp (i θ (n̂ · σ)) = cos θ · I + i sin θ · (n̂ · σ)` + +(Nielsen & Chuang, Exercise 2.35). It mirrors `Quaternion.exp_of_re_eq_zero`, the analogous formula +for a purely imaginary quaternion (there `a * a = -1`, giving `cos`/`sin`). + +The companion `NormedSpace.exp_smul_of_mul_self_eq_self` treats the neighbouring special case of an +*idempotent* `a` (`a * a = a`, e.g. a projector), where the even/odd split collapses to a single +term: `exp (z • a) = 1 + (Complex.exp z - 1) • a`. + +## Main results + +* `NormedSpace.exp_smul_of_mul_self_eq_one`: the closed form when `a * a = 1`. +* `NormedSpace.exp_smul_mul_I_of_mul_self_eq_one`: its real-angle trigonometric form + `exp ((x * i) • a) = cos x • 1 + (sin x * i) • a` (Nielsen & Chuang, Exercise 4.2, eq. 4.7). +* `NormedSpace.smul_one_add_smul_mul_of_mul_self_eq_one`: the multiplication table of the span of + `1` and an involution, `(a•1 + b•g)(d•1 + e•g) = (ad+be)•1 + (ae+bd)•g`, which computes products + and squares of the normal forms above. +* `NormedSpace.exp_smul_of_mul_self_eq_self`: the closed form when `a * a = a` (idempotent), + `exp (z • a) = 1 + (Complex.exp z - 1) • a`. +-/ + +@[expose] public section + +namespace NormedSpace + +variable {𝔸 : Type*} [NormedRing 𝔸] [NormedAlgebra ℂ 𝔸] + +/-- **Euler's formula for an involution.** If `a` satisfies `a * a = 1` in a normed `ℂ`-algebra, +then for any `z : ℂ`, +`exp (z • a) = Complex.cosh z • 1 + Complex.sinh z • a`. + +The exponential series `∑ₙ (n!)⁻¹ • (z • a) ^ n` splits by parity: since `(z • a) ^ n = zⁿ • aⁿ` and +`aⁿ` is `1` for even `n` and `a` for odd `n`, the even part is `(∑ₖ z^(2k)/(2k)!) • 1 = cosh z • 1` +and the odd part is `(∑ₖ z^(2k+1)/(2k+1)!) • a = sinh z • a`. Specialising `z` to `θ * I` and using +`Complex.cosh_mul_I`/`Complex.sinh_mul_I` recovers the trigonometric "rotation" form. -/ +theorem exp_smul_of_mul_self_eq_one {a : 𝔸} (ha : a * a = 1) (z : ℂ) : + exp (z • a) = Complex.cosh z • (1 : 𝔸) + Complex.sinh z • a := by + have ha2 : a ^ 2 = 1 := by rw [sq]; exact ha + have hpe : ∀ k : ℕ, a ^ (2 * k) = 1 := fun k => by rw [pow_mul, ha2, one_pow] + have hpo : ∀ k : ℕ, a ^ (2 * k + 1) = a := fun k => by rw [pow_succ, hpe k, one_mul] + rw [exp_eq_tsum ℂ] + refine HasSum.tsum_eq ?_ + refine HasSum.even_add_odd ?_ ?_ + · -- even terms: `(2k)!⁻¹ • (z • a) ^ (2k) = (z^(2k)/(2k)!) • 1`, summing to `cosh z • 1` + have h : (fun k : ℕ => (↑(2 * k).factorial : ℂ)⁻¹ • (z • a) ^ (2 * k)) + = (fun k : ℕ => (z ^ (2 * k) / ↑(2 * k).factorial) • (1 : 𝔸)) := by + funext k; rw [smul_pow, hpe k, smul_smul, div_eq_mul_inv, mul_comm] + rw [h]; exact (Complex.hasSum_cosh z).smul_const (1 : 𝔸) + · -- odd terms: `(2k+1)!⁻¹ • (z • a) ^ (2k+1) = (z^(2k+1)/(2k+1)!) • a`, summing to `sinh z • a` + have h : (fun k : ℕ => (↑(2 * k + 1).factorial : ℂ)⁻¹ • (z • a) ^ (2 * k + 1)) + = (fun k : ℕ => (z ^ (2 * k + 1) / ↑(2 * k + 1).factorial) • a) := by + funext k; rw [smul_pow, hpo k, smul_smul, div_eq_mul_inv, mul_comm] + rw [h]; exact (Complex.hasSum_sinh z).smul_const a + +/-- **Nielsen & Chuang, Exercise 4.2, equation (4.7).** For an involution `a` (`a * a = 1`) in a +normed `ℂ`-algebra and a *real* number `x`, +`exp ((x * i) • a) = cos x • 1 + (sin x * i) • a`, +that is, `exp (i x a) = cos x · 1 + i sin x · a`. + +This is the real-angle trigonometric specialisation of `exp_smul_of_mul_self_eq_one`: writing the +exponent as `z • a` with `z = x * i`, `Complex.cosh_mul_I` turns `cosh z` into `cos x` and +`Complex.sinh_mul_I` turns `sinh z` into `sin x * i`. Specialising further to `a = X, Y, Z` (a Pauli +matrix) with `x = -θ/2` gives Nielsen & Chuang's rotation operators `R_x, R_y, R_z = exp(-iθσ/2)` +(equations 4.4–4.6). -/ +theorem exp_smul_mul_I_of_mul_self_eq_one {a : 𝔸} (ha : a * a = 1) (x : ℝ) : + exp (((x : ℂ) * Complex.I) • a) + = (Real.cos x : ℂ) • (1 : 𝔸) + ((Real.sin x : ℂ) * Complex.I) • a := by + rw [exp_smul_of_mul_self_eq_one ha, Complex.cosh_mul_I, Complex.sinh_mul_I, + ← Complex.ofReal_cos, ← Complex.ofReal_sin] + +/-- **Product law for the span of `1` and an involution.** If `g` satisfies `g * g = 1` in a +`ℂ`-algebra `A`, the `ℂ`-linear span of `1` and `g` is closed under multiplication: +`(a • 1 + b • g) * (d • 1 + e • g) = (a * d + b * e) • 1 + (a * e + b * d) • g`. + +This is the multiplication table of the two-dimensional algebra `ℂ[g]/(g² - 1)`. Applied to the +`cos x • 1 ± (sin x * i) • g` normal forms of `exp (±(x * i) • g)` +(`exp_smul_mul_I_of_mul_self_eq_one`), it computes their products and squares — e.g. the square +`(exp ((x * i) • g))² = exp ((2 x * i) • g)` in `cos`/`sin` form via the double-angle identities. -/ +theorem smul_one_add_smul_mul_of_mul_self_eq_one {A : Type*} [Ring A] [Algebra ℂ A] {g : A} + (hg : g * g = 1) (a b d e : ℂ) : + (a • (1 : A) + b • g) * (d • 1 + e • g) + = (a * d + b * e) • (1 : A) + (a * e + b * d) • g := by + simp only [add_mul, mul_add, smul_mul_assoc, mul_smul_comm, mul_one, one_mul, hg] + module + +/-- **Euler's formula for an idempotent.** If `a` satisfies `a * a = a` in a normed `ℂ`-algebra +(e.g. `a` is a projector `P = P²`), then for any `z : ℂ`, +`exp (z • a) = 1 + (Complex.exp z - 1) • a`. + +The exponential series `∑ₙ (n!)⁻¹ • (z • a) ^ n` has `(z • a) ^ n = zⁿ • aⁿ` with `aⁿ = a` for every +`n ≥ 1` and `a⁰ = 1`. Thus the `n = 0` term contributes `1` and the tail `∑_{n≥1} (zⁿ/n!) • a` sums +to `(Complex.exp z - 1) • a`, since `∑_{n≥1} zⁿ/n! = Complex.exp z - 1`. This is the idempotent +counterpart of `exp_smul_of_mul_self_eq_one`; for a rank-one projector `P = |ψ⟩⟨ψ|` and `z = -iΔt` +it gives the projector-Hamiltonian propagator `exp(-i|ψ⟩⟨ψ|Δt) = I + (e^{-iΔt} - 1)|ψ⟩⟨ψ|` +(Nielsen & Chuang, §6.2, the Hamiltonian `|x⟩⟨x|` simulated in Exercise 6.7). -/ +theorem exp_smul_of_mul_self_eq_self {a : 𝔸} (ha : a * a = a) (z : ℂ) : + exp (z • a) = (1 : 𝔸) + (Complex.exp z - 1) • a := by + -- `aⁿ = a` for `n ≥ 1` (and `a⁰ = 1`). + have hpow : ∀ n : ℕ, a ^ (n + 1) = a := by + intro n + induction n with + | zero => simp + | succ k ih => rw [pow_succ, ih, ha] + -- Rewrite the `n`-th series term as `(zⁿ/n!) • a` plus a correction `1 - a` supported at `n = 0`. + have key : (fun n : ℕ => (↑n.factorial : ℂ)⁻¹ • (z • a) ^ n) + = fun n : ℕ => (z ^ n / ↑n.factorial) • a + (if n = 0 then ((1 : 𝔸) - a) else 0) := by + funext n + cases n with + | zero => simp + | succ m => + rw [smul_pow, hpow m, smul_smul, div_eq_mul_inv, mul_comm, + ite_eq_right (Nat.succ_ne_zero m), add_zero] + -- The `(zⁿ/n!) • a` part sums to `(Complex.exp z) • a`; the correction sums to `1 - a`. + have h1 : HasSum (fun n : ℕ => (z ^ n / ↑n.factorial) • a) (Complex.exp z • a) := by + have hs : HasSum (fun n : ℕ => z ^ n / ↑n.factorial) (Complex.exp z) := by + rw [Complex.exp_eq_exp_ℂ] + exact expSeries_div_hasSum_exp z + exact hs.smul_const a + have h2 : HasSum (fun n : ℕ => if n = 0 then ((1 : 𝔸) - a) else 0) ((1 : 𝔸) - a) := + hasSum_ite_eq 0 ((1 : 𝔸) - a) + rw [exp_eq_tsum ℂ] + refine HasSum.tsum_eq ?_ + rw [key] + have hsum := h1.add h2 + convert hsum using 1 + rw [sub_smul, one_smul] + abel + +end NormedSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/LieTrotter.lean b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/LieTrotter.lean new file mode 100644 index 0000000000..cb092175db --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/LieTrotter.lean @@ -0,0 +1,1072 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Normed.Algebra.Exponential +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Ring.ProductTelescope +public import Mathlib.Analysis.SpecialFunctions.Exponential +public import Mathlib.Order.Filter.AtTopBot.Archimedean + +/-! +# The Lie–Trotter product formula + +Let `𝔸` be a Banach algebra (a complete normed `ℝ`-algebra with `‖1‖ = 1`) and `x y : 𝔸`. This file +proves the **Lie product formula**, also known as the **Trotter product formula**: + +`Tendsto (fun n : ℕ => (exp (n⁻¹ • x) * exp (n⁻¹ • y)) ^ n) atTop (𝓝 (exp (x + y)))`, + +i.e. `lim (exp(x/n) exp(y/n))ⁿ = exp(x + y)`, valid even when `x` and `y` do **not** commute. This +is Nielsen & Chuang, *Quantum Computation and Quantum Information*, Theorem 4.3, which states it for +Hermitian operators `A, B` and real `t` as `lim (e^{iAt/n} e^{iBt/n})ⁿ = e^{i(A+B)t}` — the special +case obtained here by taking `x = i·t·A`, `y = i·t·B` (any operator, Hermitian or not, is an element +of the algebra, so the general statement below subsumes it). + +The proof is the classical one. Writing `aₙ = exp(x/n) exp(y/n)` and `bₙ = exp((x+y)/n)`, one has +`bₙⁿ = exp(x + y)` exactly (`exp_nsmul`), while `‖aₙ - bₙ‖ = O(1/n²)` (a second-order Taylor +estimate: both factors agree with `1 + (x+y)/n` to first order). A telescoping bound on +`‖aₙⁿ - bₙⁿ‖` (with `‖aₙ‖, ‖bₙ‖ ≤ exp((‖x‖+‖y‖)/n)`, whose `n`-th power is the constant +`exp(‖x‖+‖y‖)`) then gives `‖aₙⁿ - exp(x+y)‖ ≤ C·n · (1/n²) = O(1/n) → 0`. + +## Main results + +* `norm_pow_sub_pow_le`: the noncommutative telescoping bound `‖xⁿ - yⁿ‖ ≤ n·Mⁿ·‖x - y‖` when + `‖x‖, ‖y‖ ≤ M` and `1 ≤ M`. +* `norm_prod_one_add_sub_one_sub_sum_le`: the product-linearization bound + `‖(∏ᵢ (1 + aᵢ)) - 1 - ∑ᵢ aᵢ‖ ≤ (∏ᵢ (1 + ‖aᵢ‖)) - 1 - ∑ᵢ ‖aᵢ‖`, and its closed form + `NormedSpace.norm_prod_one_add_sub_one_sub_sum_le_exp`, + `‖(∏ᵢ (1 + aᵢ)) - 1 - ∑ᵢ aᵢ‖ ≤ (∑ᵢ ‖aᵢ‖)² · Real.exp (∑ᵢ ‖aᵢ‖)` — the second-order deviation of a + finite product of `1 + aᵢ` factors from its linearization, proved elementarily (no series or + noncommutative expansion). +* `NormedSpace.norm_exp_le`: `‖exp z‖ ≤ Real.exp ‖z‖` in a Banach algebra (the general-algebra form + of `Complex.norm_exp_le_exp_norm`). +* `NormedSpace.norm_exp_sub_sum_le`: the order-`k` Taylor remainder bound + `‖exp z - ∑ i < k, (i!)⁻¹ • zⁱ‖ ≤ ‖z‖ᵏ · Real.exp ‖z‖`, with the second- and third-order + remainders `norm_exp_sub_one_sub_id_le` and `norm_exp_sub_one_sub_id_sub_half_sq_le` as its + `k = 2`, `k = 3` instances. +* `NormedSpace.tendsto_pow_exp_smul_mul_exp_smul`: the Lie–Trotter product formula. +* `NormedSpace.exists_norm_exp_smul_mul_exp_two_smul_mul_exp_smul_sub_le`: the *symmetric* (Strang) + second-order splitting error, `‖exp(t•x) exp((2t)•y) exp(t•x) - exp((2t)•(x+y))‖ ≤ K·t³` — one + order better than the unsymmetric splitting, the base case of Nielsen & Chuang Exercise 4.50(a). +* `NormedSpace.exists_norm_prod_exp_smul_sub_exp_smul_sum_le`: the first-order (`O(t²)`) error of + splitting `exp(t • ∑ gᵢ)` into the ordered product `∏ exp(t•gᵢ)` of a finite list of factors. +* `NormedSpace.norm_prod_exp_smul_le`: `‖∏ exp(s•gᵢ)‖ ≤ Real.exp(s • ∑ ‖gᵢ‖)` for `s ≥ 0`. +* `NormedSpace.exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le`: the accumulated `O(k⁻¹)` error of + the `k`-fold splitting `(∏ exp(k⁻¹•gᵢ))^k` of `exp(∑ gᵢ)`. +* `NormedSpace.norm_prod_exp_inv_smul_pow_sub_exp_sum_le_sq`: the same `k`-fold error with an + **explicit numerical** constant and **polynomial** `Λ`-dependence, `≤ (2e + e²·eᵉ)·Λ²·k⁻¹` + (`Λ = ∑‖gᵢ‖`), under the *contraction* hypothesis `‖exp(s•gᵢ)‖ ≤ 1` (e.g. skew-adjoint `gᵢ`) that + makes the telescoping run with `M = 1`; the sharpening behind Nielsen & Chuang Problem 4.3(6)'s + literal `O(n·16ⁿ/ε)` gate count. +* `NormedSpace.exists_norm_symmProd_exp_smul_sub_exp_two_smul_sum_le`: the symmetric (Strang) + `O(t³)` error of the *palindromic* splitting `(∏ exp(t•gᵢ)) · (∏ exp(t•gᵢ) reversed)` of + `exp(2t • ∑ gᵢ)` over a finite list — the list form of Nielsen & Chuang Exercise 4.50(a), one + order better than the unsymmetric `exists_norm_prod_exp_smul_sub_exp_smul_sum_le`. +-/ + +@[expose] public section + +open Filter Topology + +variable {𝔸 : Type*} [NormedRing 𝔸] [NormOneClass 𝔸] + +/-- **Noncommutative telescoping bound.** If `‖x‖ ≤ M`, `‖y‖ ≤ M` and `1 ≤ M` in a normed ring, +then `‖xⁿ - yⁿ‖ ≤ n · Mⁿ · ‖x - y‖`. This is the norm estimate behind the identity +`xⁿ - yⁿ = ∑ᵢ xⁱ (x - y) y^(n-1-i)`, proved directly by induction (the factors need not commute, so +the `Commute.*` geometric-sum lemmas do not apply). -/ +theorem norm_pow_sub_pow_le {x y : 𝔸} {M : ℝ} (hx : ‖x‖ ≤ M) (hy : ‖y‖ ≤ M) (hM : 1 ≤ M) : + ∀ n : ℕ, ‖x ^ n - y ^ n‖ ≤ n * M ^ n * ‖x - y‖ := by + have hM0 : (0 : ℝ) ≤ M := le_trans zero_le_one hM + intro n + induction n with + | zero => simp + | succ n ih => + have hyn : ‖y ^ n‖ ≤ M ^ n := le_trans (norm_pow_le y n) (pow_le_pow_left₀ (norm_nonneg y) hy n) + have key : x ^ (n + 1) - y ^ (n + 1) = x * (x ^ n - y ^ n) + (x - y) * y ^ n := by + rw [mul_sub, sub_mul, pow_succ' x n, pow_succ' y n]; abel + calc ‖x ^ (n + 1) - y ^ (n + 1)‖ + = ‖x * (x ^ n - y ^ n) + (x - y) * y ^ n‖ := by rw [key] + _ ≤ ‖x * (x ^ n - y ^ n)‖ + ‖(x - y) * y ^ n‖ := norm_add_le _ _ + _ ≤ ‖x‖ * ‖x ^ n - y ^ n‖ + ‖x - y‖ * ‖y ^ n‖ := + add_le_add (norm_mul_le _ _) (norm_mul_le _ _) + _ ≤ M * (↑n * M ^ n * ‖x - y‖) + ‖x - y‖ * M ^ n := by gcongr + _ = ↑n * M ^ (n + 1) * ‖x - y‖ + M ^ n * ‖x - y‖ := by ring + _ ≤ ↑n * M ^ (n + 1) * ‖x - y‖ + M ^ (n + 1) * ‖x - y‖ := by + have hstep : M ^ n ≤ M ^ (n + 1) := pow_le_pow_right₀ hM (Nat.le_succ n) + nlinarith [hstep, norm_nonneg (x - y)] + _ = ↑(n + 1) * M ^ (n + 1) * ‖x - y‖ := by push_cast; ring + +/-- **Product-of-`1 + ·` deviation bound.** In a normed ring, the product `∏ᵢ (1 + aᵢ)` over a +finite list deviates from `1` by at most the corresponding scalar deviation: +`‖(∏ᵢ (1 + aᵢ)) - 1‖ ≤ (∏ᵢ (1 + ‖aᵢ‖)) - 1`. +Proved by induction on the list: the cons step rewrites `(1 + b)·P - 1 = (1 + b)·(P - 1) + b` and +bounds each piece submultiplicatively (`‖1 + b‖ ≤ 1 + ‖b‖`, `norm_mul_le`). This is the base lemma +for the product-linearization bound `norm_prod_one_add_sub_one_sub_sum_le`. -/ +theorem norm_prod_one_add_sub_one_le (c : List 𝔸) : + ‖(c.map fun a => 1 + a).prod - 1‖ ≤ (c.map fun a => 1 + ‖a‖).prod - 1 := by + induction c with + | nil => simp + | cons b l ih => + simp only [List.map_cons, List.prod_cons] + have h1 : ‖(1 : 𝔸) + b‖ ≤ 1 + ‖b‖ := by refine (norm_add_le _ _).trans ?_; rw [norm_one] + have key : (1 + b) * (l.map fun a => 1 + a).prod - 1 + = (1 + b) * ((l.map fun a => 1 + a).prod - 1) + b := by noncomm_ring + rw [key] + have hbound : ‖(1 + b) * ((l.map fun a => 1 + a).prod - 1)‖ + ≤ (1 + ‖b‖) * ((l.map fun a => 1 + ‖a‖).prod - 1) := + (norm_mul_le _ _).trans (mul_le_mul h1 ih (norm_nonneg _) (by positivity)) + calc ‖(1 + b) * ((l.map fun a => 1 + a).prod - 1) + b‖ + ≤ ‖(1 + b) * ((l.map fun a => 1 + a).prod - 1)‖ + ‖b‖ := norm_add_le _ _ + _ ≤ (1 + ‖b‖) * ((l.map fun a => 1 + ‖a‖).prod - 1) + ‖b‖ := by linarith + _ = (1 + ‖b‖) * (l.map fun a => 1 + ‖a‖).prod - 1 := by ring + +/-- **Product-linearization bound.** In a normed ring, the product `∏ᵢ (1 + aᵢ)` over a finite list +agrees with its first-order (linear) approximation `1 + ∑ᵢ aᵢ` up to the corresponding scalar +remainder: +`‖(∏ᵢ (1 + aᵢ)) - 1 - ∑ᵢ aᵢ‖ ≤ (∏ᵢ (1 + ‖aᵢ‖)) - 1 - ∑ᵢ ‖aᵢ‖`. +The right-hand side is the second-order (cross) part of the product `∏ (1 + ‖aᵢ‖)`; in particular +it vanishes when at most one factor is nonzero. Proved by induction using +`norm_prod_one_add_sub_one_le` for the tail product — no series or noncommutative multinomial +expansion is needed. Its closed form is `NormedSpace.norm_prod_one_add_sub_one_sub_sum_le_exp`. -/ +theorem norm_prod_one_add_sub_one_sub_sum_le (c : List 𝔸) : + ‖(c.map fun a => 1 + a).prod - 1 - c.sum‖ + ≤ (c.map fun a => 1 + ‖a‖).prod - 1 - (c.map fun a => ‖a‖).sum := by + induction c with + | nil => simp + | cons b l ih => + simp only [List.map_cons, List.prod_cons, List.sum_cons] + have hA := norm_prod_one_add_sub_one_le l + have key : (1 + b) * (l.map fun a => 1 + a).prod - 1 - (b + l.sum) + = ((l.map fun a => 1 + a).prod - 1 - l.sum) + b * ((l.map fun a => 1 + a).prod - 1) := by + noncomm_ring + rw [key] + have hbound : ‖b * ((l.map fun a => 1 + a).prod - 1)‖ + ≤ ‖b‖ * ((l.map fun a => 1 + ‖a‖).prod - 1) := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left hA (norm_nonneg _)) + calc ‖((l.map fun a => 1 + a).prod - 1 - l.sum) + b * ((l.map fun a => 1 + a).prod - 1)‖ + ≤ ‖(l.map fun a => 1 + a).prod - 1 - l.sum‖ + ‖b * ((l.map fun a => 1 + a).prod - 1)‖ := + norm_add_le _ _ + _ ≤ ((l.map fun a => 1 + ‖a‖).prod - 1 - (l.map fun a => ‖a‖).sum) + + ‖b‖ * ((l.map fun a => 1 + ‖a‖).prod - 1) := by linarith + _ = (1 + ‖b‖) * (l.map fun a => 1 + ‖a‖).prod - 1 - (‖b‖ + (l.map fun a => ‖a‖).sum) := by + ring + +omit [NormOneClass 𝔸] in +/-- In a normed ring, `∏ᵢ (1 + ‖aᵢ‖) ≤ Real.exp (∑ᵢ ‖aᵢ‖)`, from the scalar inequality +`1 + t ≤ Real.exp t` (`Real.add_one_le_exp`) applied factorwise together with `Real.exp_add`. -/ +theorem prod_one_add_norm_le_exp (c : List 𝔸) : + (c.map fun a => 1 + ‖a‖).prod ≤ Real.exp ((c.map fun a => ‖a‖).sum) := by + induction c with + | nil => simp + | cons b l ih => + simp only [List.map_cons, List.prod_cons, List.sum_cons, Real.exp_add] + have hcnn : 0 ≤ (l.map fun a => 1 + ‖a‖).prod := + List.prod_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; positivity + refine mul_le_mul ?_ ih hcnn (Real.exp_pos _).le + rw [add_comm]; exact Real.add_one_le_exp _ + +namespace NormedSpace + +variable [NormedAlgebra ℝ 𝔸] [CompleteSpace 𝔸] + +/-- **The norm of the exponential is bounded by the exponential of the norm.** In a Banach algebra, +`‖exp z‖ ≤ Real.exp ‖z‖`. This is the general-algebra analogue of `Complex.norm_exp_le_exp_norm`, +obtained by comparing the exponential series `∑ (n!)⁻¹ • zⁿ` termwise with the real series for +`Real.exp ‖z‖`. -/ +theorem norm_exp_le (z : 𝔸) : ‖exp z‖ ≤ Real.exp ‖z‖ := by + have hsum : HasSum (fun n : ℕ => (n.factorial : ℝ)⁻¹ • z ^ n) (exp z) := + NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) z + have hnorm_summable : Summable (fun n : ℕ => ‖(n.factorial : ℝ)⁻¹ • z ^ n‖) := + NormedSpace.norm_expSeries_summable' (𝕂 := ℝ) z + have hreal_summable : Summable (fun n : ℕ => (n.factorial : ℝ)⁻¹ * ‖z‖ ^ n) := by + have := Real.summable_pow_div_factorial ‖z‖ + simpa [div_eq_mul_inv, mul_comm] using this + calc ‖exp z‖ = ‖∑' n : ℕ, (n.factorial : ℝ)⁻¹ • z ^ n‖ := by rw [hsum.tsum_eq] + _ ≤ ∑' n : ℕ, ‖(n.factorial : ℝ)⁻¹ • z ^ n‖ := norm_tsum_le_tsum_norm hnorm_summable + _ ≤ ∑' n : ℕ, (n.factorial : ℝ)⁻¹ * ‖z‖ ^ n := by + refine Summable.tsum_le_tsum (fun n => ?_) hnorm_summable hreal_summable + rw [norm_smul] + have hc : ‖(n.factorial : ℝ)⁻¹‖ = (n.factorial : ℝ)⁻¹ := by + rw [Real.norm_eq_abs, abs_inv, Nat.abs_cast] + rw [hc] + gcongr + exact norm_pow_le z n + _ = Real.exp ‖z‖ := by + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div] + congr 1 + ext n + rw [div_eq_mul_inv, mul_comm] + +/-- **Taylor remainder bound for the exponential.** In a Banach algebra, `exp z` differs from its +order-`k` Taylor partial sum `∑ i < k, (i!)⁻¹ • zⁱ` by at most `‖z‖ᵏ · Real.exp ‖z‖`: +`‖exp z - ∑ i ∈ Finset.range k, (i.factorial : ℝ)⁻¹ • z ^ i‖ ≤ ‖z‖ ^ k · Real.exp ‖z‖`. +The exponential series with its first `k` terms removed is `∑ₙ ((n+k)!)⁻¹ • z^(n+k)`, whose norm is +bounded termwise (using `((n+k)!)⁻¹ ≤ (n!)⁻¹`) by `‖z‖ᵏ · ∑ₙ (n!)⁻¹ ‖z‖ⁿ = ‖z‖ᵏ · Real.exp ‖z‖`. +This is the Banach-algebra analogue of `Complex.norm_exp_sub_sum_le_exp_norm_sub_sum`; the low-order +remainder bounds `norm_exp_sub_one_sub_id_le` (`k = 2`) and `norm_exp_sub_one_sub_id_sub_half_sq_le` +(`k = 3`) are its instances. -/ +theorem norm_exp_sub_sum_le (z : 𝔸) (k : ℕ) : + ‖exp z - ∑ i ∈ Finset.range k, (i.factorial : ℝ)⁻¹ • z ^ i‖ ≤ ‖z‖ ^ k * Real.exp ‖z‖ := by + set f : ℕ → 𝔸 := fun n => (n.factorial : ℝ)⁻¹ • z ^ n with hf + have hsum : HasSum f (exp z) := NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) z + have hns : Summable f := hsum.summable + have hnorm_summable : Summable (fun n : ℕ => ‖f n‖) := + NormedSpace.norm_expSeries_summable' (𝕂 := ℝ) z + have hreal_summable : Summable (fun n : ℕ => (n.factorial : ℝ)⁻¹ * ‖z‖ ^ n) := by + have := Real.summable_pow_div_factorial ‖z‖ + simpa [div_eq_mul_inv, mul_comm] using this + have hexp_eq : (∑' n : ℕ, (n.factorial : ℝ)⁻¹ * ‖z‖ ^ n) = Real.exp ‖z‖ := by + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div]; congr 1; ext n + rw [div_eq_mul_inv, mul_comm] + have hpeel : (∑ i ∈ Finset.range k, f i) + ∑' n : ℕ, f (n + k) = exp z := by + rw [Summable.sum_add_tsum_nat_add k hns, hsum.tsum_eq] + have hrem : exp z - ∑ i ∈ Finset.range k, (i.factorial : ℝ)⁻¹ • z ^ i = ∑' n : ℕ, f (n + k) := by + have hfsum : (∑ i ∈ Finset.range k, f i) + = ∑ i ∈ Finset.range k, (i.factorial : ℝ)⁻¹ • z ^ i := rfl + rw [← hpeel, hfsum]; abel + rw [hrem] + have hshift : Summable (fun n : ℕ => ‖f (n + k)‖) := (summable_nat_add_iff k).mpr hnorm_summable + calc ‖∑' n : ℕ, f (n + k)‖ + ≤ ∑' n : ℕ, ‖f (n + k)‖ := norm_tsum_le_tsum_norm hshift + _ ≤ ∑' n : ℕ, ‖z‖ ^ k * ((n.factorial : ℝ)⁻¹ * ‖z‖ ^ n) := by + refine Summable.tsum_le_tsum (fun n => ?_) hshift (hreal_summable.mul_left _) + have hfac : (n.factorial : ℝ) ≤ ((n + k).factorial : ℝ) := by + exact_mod_cast Nat.factorial_le (Nat.le_add_right n k) + have hnf : ‖f (n + k)‖ = ((n + k).factorial : ℝ)⁻¹ * ‖z ^ (n + k)‖ := by + simp only [hf, norm_smul, Real.norm_eq_abs, abs_inv, Nat.abs_cast] + rw [hnf] + calc ((n + k).factorial : ℝ)⁻¹ * ‖z ^ (n + k)‖ + ≤ ((n + k).factorial : ℝ)⁻¹ * ‖z‖ ^ (n + k) := by gcongr; exact norm_pow_le z (n + k) + _ ≤ (n.factorial : ℝ)⁻¹ * ‖z‖ ^ (n + k) := by gcongr + _ = ‖z‖ ^ k * ((n.factorial : ℝ)⁻¹ * ‖z‖ ^ n) := by rw [pow_add]; ring + _ = ‖z‖ ^ k * Real.exp ‖z‖ := by rw [tsum_mul_left, hexp_eq] + +/-- **First-order remainder bound for the exponential.** In a Banach algebra, +`‖exp z - 1‖ ≤ ‖z‖ · Real.exp ‖z‖`. The `k = 1` instance of `norm_exp_sub_sum_le`: the order-1 +Taylor partial sum is `1`. It is the first-order sibling of `norm_exp_sub_one_sub_id_le` (`k = 2`) +and `norm_exp_sub_one_sub_id_sub_half_sq_le` (`k = 3`); it controls each factor `exp(s•gᵢ) - 1` of a +Trotter slice `∏ᵢ exp(s•gᵢ)` written as `∏ᵢ (1 + (exp(s•gᵢ) - 1))`. -/ +theorem norm_exp_sub_one_le (z : 𝔸) : ‖exp z - 1‖ ≤ ‖z‖ * Real.exp ‖z‖ := by + simpa [Finset.sum_range_one] using norm_exp_sub_sum_le z 1 + +/-- **Second-order remainder bound for the exponential.** In a Banach algebra, +`‖exp z - 1 - z‖ ≤ ‖z‖² · Real.exp ‖z‖`. The `k = 2` instance of `norm_exp_sub_sum_le`: the order-2 +Taylor partial sum is `1 + z`. -/ +theorem norm_exp_sub_one_sub_id_le (z : 𝔸) : + ‖exp z - 1 - z‖ ≤ ‖z‖ ^ 2 * Real.exp ‖z‖ := by + simpa [Finset.sum_range_succ, sub_sub] using norm_exp_sub_sum_le z 2 + +/-- **Third-order remainder bound for the exponential.** In a Banach algebra, +`‖exp z - 1 - z - z²/2‖ ≤ ‖z‖³ · Real.exp ‖z‖`. The `k = 3` instance of `norm_exp_sub_sum_le`: the +order-3 Taylor partial sum is `1 + z + z²/2`. This one-order-higher remainder is what powers the +*symmetric* (second-order) splitting estimate +`exists_norm_exp_smul_mul_exp_two_smul_mul_exp_smul_sub_le`. -/ +theorem norm_exp_sub_one_sub_id_sub_half_sq_le (z : 𝔸) : + ‖exp z - 1 - z - (2 : ℝ)⁻¹ • z ^ 2‖ ≤ ‖z‖ ^ 3 * Real.exp ‖z‖ := by + simpa [Finset.sum_range_succ, sub_sub] using norm_exp_sub_sum_le z 3 + +omit [NormedAlgebra ℝ 𝔸] [CompleteSpace 𝔸] in +/-- **Product-linearization bound with an exponential remainder.** In a normed ring, the product +`∏ᵢ (1 + aᵢ)` over a finite list agrees with its linearization `1 + ∑ᵢ aᵢ` up to a remainder +controlled by the total norm `S = ∑ᵢ ‖aᵢ‖`: +`‖(∏ᵢ (1 + aᵢ)) - 1 - ∑ᵢ aᵢ‖ ≤ S² · Real.exp S`. +This is the closed form of `norm_prod_one_add_sub_one_sub_sum_le`: the scalar right-hand side +`(∏ᵢ (1 + ‖aᵢ‖)) - 1 - S` is bounded, via `prod_one_add_norm_le_exp`, by `Real.exp S - 1 - S`, and +then by `S² · Real.exp S` using the second-order exponential remainder `norm_exp_sub_one_sub_id_le` +at `ℝ`. The bound is genuinely second order in `S`, with an explicit `Real.exp S` factor rather than +an `exp(S)`-type prefactor hidden inside an existential constant. Applied to `aᵢ = exp(s•gᵢ) - 1` it +controls how far one Trotter slice `∏ᵢ exp(s•gᵢ)` sits from its linearization uniformly in the list +length — the quantitative core behind an exponential-prefactor-free first-order Lie–Trotter +estimate. (The statement uses `exp` only through the real exponential, so no structure beyond a +normed ring is required.) -/ +theorem norm_prod_one_add_sub_one_sub_sum_le_exp (c : List 𝔸) : + ‖(c.map fun a => 1 + a).prod - 1 - c.sum‖ + ≤ (c.map fun a => ‖a‖).sum ^ 2 * Real.exp ((c.map fun a => ‖a‖).sum) := by + set S := (c.map fun a => ‖a‖).sum with hS + have hSnn : 0 ≤ S := by + rw [hS]; exact List.sum_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg y + have hprod : (c.map fun a => 1 + ‖a‖).prod ≤ Real.exp S := hS ▸ prod_one_add_norm_le_exp c + have hrem : Real.exp S - 1 - S ≤ S ^ 2 * Real.exp S := by + have hbridge : NormedSpace.exp S = Real.exp S := (congrFun Real.exp_eq_exp_ℝ S).symm + have h := NormedSpace.norm_exp_sub_one_sub_id_le (S : ℝ) + rw [hbridge] at h + have hnv : ‖S‖ = S := by rw [Real.norm_eq_abs, abs_of_nonneg hSnn] + rw [hnv] at h + calc Real.exp S - 1 - S ≤ |Real.exp S - 1 - S| := le_abs_self _ + _ = ‖Real.exp S - 1 - S‖ := (Real.norm_eq_abs _).symm + _ ≤ S ^ 2 * Real.exp S := h + calc ‖(c.map fun a => 1 + a).prod - 1 - c.sum‖ + ≤ (c.map fun a => 1 + ‖a‖).prod - 1 - S := norm_prod_one_add_sub_one_sub_sum_le c + _ ≤ Real.exp S - 1 - S := by linarith + _ ≤ S ^ 2 * Real.exp S := hrem + +/-- The **explicit numerical Lie–Trotter constant** `2e + e²·eᵉ`, i.e. +`2·Real.exp 1 + Real.exp 1 ^ 2 · Real.exp (Real.exp 1)`, of the unitarity-aware first-order and +`k`-fold Trotter product-formula bounds `norm_prod_exp_smul_sub_exp_smul_sum_le_sq` and +`norm_prod_exp_inv_smul_pow_sub_exp_sum_le_sq`. A single fixed real — independent of the list, the +scalar, and the step count `k` — the *one source of truth* both bounds reference; it is the +numerical part of Nielsen & Chuang, *Quantum Computation and Quantum Information*, Problem 4.3(6)'s +`O(4ⁿ)` Trotter constant. -/ +noncomputable def trotterProductConst : ℝ := + 2 * Real.exp 1 + Real.exp 1 ^ 2 * Real.exp (Real.exp 1) + +/-- The Lie–Trotter product-formula constant `trotterProductConst` is nonnegative. -/ +theorem trotterProductConst_nonneg : 0 ≤ trotterProductConst := by + unfold trotterProductConst; positivity + +/-- The Lie–Trotter product-formula constant `trotterProductConst` is at least `2`. -/ +theorem two_le_trotterProductConst : 2 ≤ trotterProductConst := by + have he1 : (1 : ℝ) ≤ Real.exp 1 := Real.one_le_exp zero_le_one + have hpos : 0 ≤ Real.exp 1 ^ 2 * Real.exp (Real.exp 1) := by positivity + unfold trotterProductConst; nlinarith + +/-- **Explicit-constant first-order Lie–Trotter splitting bound.** In a Banach algebra, for a list +`l : List 𝔸`, a scalar `s ≥ 0`, and total norm `Λ = ∑ᵢ ‖gᵢ‖` *in the small-step regime* `s·Λ ≤ 1`, +the ordered product `∏ᵢ exp(s•gᵢ)` agrees with `exp(s • ∑ᵢ gᵢ)` up to a second-order error +carrying a **numerical** constant — no `Real.exp Λ`-type prefactor: +`‖(∏ᵢ exp(s•gᵢ)) - exp(s • ∑ᵢ gᵢ)‖ ≤ (2e + e²·eᵉ)·(s·Λ)²`. + +This sharpens `exists_norm_prod_exp_smul_sub_exp_smul_sum_le`, which hides its constant inside an +existential and, being built from the crude two-factor estimate, carries an `Real.exp (∑‖gᵢ‖)` +factor. The constant here is the fixed real +`2·Real.exp 1 + Real.exp 1 ^ 2 · Real.exp (Real.exp 1)`, independent of the list. That explicitness +is what a `k`-fold accumulation needs to reach an `O(Λ²)/k` rate with a *polynomial* (not +exponential) `Λ`-dependence — the operator core behind Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Problem 4.3(6)'s literal `O(n·16ⁿ/ε)` gate count (with `gᵢ = -i hᵢ Pᵢ`, +`Λ = ∑ᵢ |hᵢ|`, and `s = Δ = 1/k` in the regime `k ≥ Λ`). + +**Proof.** Write the slice as `∏ᵢ (1 + cᵢ)` with `cᵢ = exp(s•gᵢ) - 1`, and split +`(∏ᵢ(1+cᵢ)) - exp(s•∑g) = [∏ᵢ(1+cᵢ) - 1 - ∑ᵢcᵢ] + [∑ᵢcᵢ - s•∑g] - [exp(s•∑g) - 1 - s•∑g]`. In the +regime `s·Λ ≤ 1` each `s‖gᵢ‖ ≤ 1` (a summand is at most the sum, `List.single_le_sum`), so +`Real.exp (s‖gᵢ‖) ≤ e`. The first bracket is the product-linearization corollary +`norm_prod_one_add_sub_one_sub_sum_le_exp` at `c`, whose scalar remainder `∑‖cᵢ‖ ≤ e·s·Λ` +(`norm_exp_sub_one_le` factorwise) gives `≤ e²·eᵉ·(sΛ)²`; the second bracket, via the identity +`∑ᵢcᵢ - s•∑g = ∑ᵢ(exp(s•gᵢ) - 1 - s•gᵢ)` and `norm_exp_sub_one_sub_id_le` termwise (using +`(s‖gᵢ‖)² ≤ s‖gᵢ‖·sΛ`), is `≤ e·(sΛ)²`; the third is `norm_exp_sub_one_sub_id_le` at `s•∑g` +directly, `≤ e·(sΛ)²`. -/ +theorem norm_prod_exp_smul_sub_exp_smul_sum_le_sq (l : List 𝔸) {s : ℝ} (hs : 0 ≤ s) + (hsΛ : s * (l.map fun g => ‖g‖).sum ≤ 1) : + ‖(l.map fun g => exp (s • g)).prod - exp (s • l.sum)‖ + ≤ trotterProductConst * (s * (l.map fun g => ‖g‖).sum) ^ 2 := by + unfold trotterProductConst + set Λ := (l.map fun g => ‖g‖).sum with hΛ + set e1 : ℝ := Real.exp 1 with he1 + have he1pos : 0 < e1 := Real.exp_pos 1 + have hΛnn : 0 ≤ Λ := by + rw [hΛ]; exact List.sum_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg _ + have hsmul : ∀ g : 𝔸, ‖s • g‖ = s * ‖g‖ := fun g => by + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hs] + have hsingle : ∀ g ∈ l, ‖g‖ ≤ Λ := by + intro g hg; rw [hΛ] + exact List.single_le_sum + (fun x hx => by rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg _) + ‖g‖ (List.mem_map.mpr ⟨g, hg, rfl⟩) + have hsg1 : ∀ g ∈ l, s * ‖g‖ ≤ 1 := fun g hg => + le_trans (mul_le_mul_of_nonneg_left (hsingle g hg) hs) hsΛ + -- MAIN term: the product-linearization corollary at `cᵢ = exp(s•gᵢ) - 1`. + have hcprod : ((l.map fun g => exp (s • g) - 1).map fun a => 1 + a).prod + = (l.map fun g => exp (s • g)).prod := by + congr 1 + rw [List.map_map] + refine List.map_congr_left (fun g _ => ?_) + simp only [Function.comp_apply]; abel + have hcor := norm_prod_one_add_sub_one_sub_sum_le_exp (l.map fun g => exp (s • g) - 1) + rw [hcprod] at hcor + simp only [List.map_map, Function.comp_def] at hcor + set D := (l.map fun g => ‖exp (s • g) - 1‖).sum with hD + have hDnn : 0 ≤ D := by + rw [hD]; exact List.sum_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg _ + have hDbound : D ≤ e1 * (s * Λ) := by + calc D ≤ (l.map fun g => (e1 * s) * ‖g‖).sum := by + refine List.sum_le_sum (fun g hg => ?_) + calc ‖exp (s • g) - 1‖ ≤ ‖s • g‖ * Real.exp ‖s • g‖ := norm_exp_sub_one_le _ + _ = (s * ‖g‖) * Real.exp (s * ‖g‖) := by rw [hsmul] + _ ≤ (s * ‖g‖) * e1 := by + apply mul_le_mul_of_nonneg_left _ (mul_nonneg hs (norm_nonneg g)) + rw [he1]; exact Real.exp_le_exp.mpr (hsg1 g hg) + _ = (e1 * s) * ‖g‖ := by ring + _ = (e1 * s) * Λ := by rw [List.sum_map_mul_left, ← hΛ] + _ = e1 * (s * Λ) := by ring + have he1sΛ : e1 * (s * Λ) ≤ e1 := mul_le_of_le_one_right he1pos.le hsΛ + have hDe1 : D ≤ e1 := hDbound.trans he1sΛ + have hMAIN : ‖(l.map fun g => exp (s • g)).prod - 1 - (l.map fun g => exp (s • g) - 1).sum‖ + ≤ e1 ^ 2 * Real.exp e1 * (s * Λ) ^ 2 := by + refine hcor.trans ?_ + calc D ^ 2 * Real.exp D ≤ (e1 * (s * Λ)) ^ 2 * Real.exp e1 := by + apply mul_le_mul (pow_le_pow_left₀ hDnn hDbound 2) (Real.exp_le_exp.mpr hDe1) + (Real.exp_pos _).le (by positivity) + _ = e1 ^ 2 * Real.exp e1 * (s * Λ) ^ 2 := by ring + -- MID term: `∑(exp(s•gᵢ) - 1) - s•∑g = ∑(exp(s•gᵢ) - 1 - s•gᵢ)`, bounded by `e·(sΛ)²`. + have hMIDeq : (l.map fun g => exp (s • g) - 1).sum - s • l.sum + = (l.map fun g => exp (s • g) - 1 - s • g).sum := by + rw [show (fun g : 𝔸 => exp (s • g) - 1) + = (fun g => (exp (s • g) - 1 - s • g) + s • g) from by funext g; abel, + List.sum_map_add, ← List.smul_sum] + abel + have hnormsum : ‖(l.map fun g => exp (s • g) - 1 - s • g).sum‖ + ≤ (l.map fun g => ‖exp (s • g) - 1 - s • g‖).sum := by + have := norm_multiset_sum_le ((l.map fun g => exp (s • g) - 1 - s • g) : Multiset 𝔸) + simpa [List.map_map, Function.comp_def] using this + have hMID : ‖(l.map fun g => exp (s • g) - 1).sum - s • l.sum‖ ≤ e1 * (s * Λ) ^ 2 := by + rw [hMIDeq] + refine le_trans hnormsum ?_ + calc (l.map fun g => ‖exp (s • g) - 1 - s • g‖).sum + ≤ (l.map fun g => (e1 * s * (s * Λ)) * ‖g‖).sum := by + refine List.sum_le_sum (fun g hg => ?_) + have h1 : ‖exp (s • g) - 1 - s • g‖ ≤ ‖s • g‖ ^ 2 * Real.exp ‖s • g‖ := + norm_exp_sub_one_sub_id_le _ + rw [hsmul] at h1 + refine h1.trans ?_ + calc (s * ‖g‖) ^ 2 * Real.exp (s * ‖g‖) + ≤ ((s * ‖g‖) * (s * Λ)) * e1 := by + apply mul_le_mul _ _ (Real.exp_pos _).le + (mul_nonneg (mul_nonneg hs (norm_nonneg g)) (mul_nonneg hs hΛnn)) + · rw [sq] + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (hsingle g hg) hs) (mul_nonneg hs (norm_nonneg g)) + · rw [he1]; exact Real.exp_le_exp.mpr (hsg1 g hg) + _ = (e1 * s * (s * Λ)) * ‖g‖ := by ring + _ = (e1 * s * (s * Λ)) * Λ := by rw [List.sum_map_mul_left, ← hΛ] + _ = e1 * (s * Λ) ^ 2 := by ring + -- TAIL term: the single-exponential remainder at `s•∑g`. + have hlsum : ‖l.sum‖ ≤ Λ := by + rw [hΛ]; simpa using norm_multiset_sum_le (l : Multiset 𝔸) + have hnorm : ‖s • l.sum‖ ≤ s * Λ := by + rw [hsmul]; exact mul_le_mul_of_nonneg_left hlsum hs + have hTAIL : ‖exp (s • l.sum) - 1 - s • l.sum‖ ≤ e1 * (s * Λ) ^ 2 := by + refine (norm_exp_sub_one_sub_id_le _).trans ?_ + calc ‖s • l.sum‖ ^ 2 * Real.exp ‖s • l.sum‖ ≤ (s * Λ) ^ 2 * e1 := by + apply mul_le_mul (pow_le_pow_left₀ (norm_nonneg _) hnorm 2) _ (Real.exp_pos _).le + (by positivity) + rw [he1]; exact Real.exp_le_exp.mpr (le_trans hnorm hsΛ) + _ = e1 * (s * Λ) ^ 2 := by ring + -- Assemble the three brackets by the triangle inequality. + have hsplit : (l.map fun g => exp (s • g)).prod - exp (s • l.sum) + = ((l.map fun g => exp (s • g)).prod - 1 - (l.map fun g => exp (s • g) - 1).sum) + + ((l.map fun g => exp (s • g) - 1).sum - s • l.sum) + - (exp (s • l.sum) - 1 - s • l.sum) := by abel + rw [hsplit] + calc ‖((l.map fun g => exp (s • g)).prod - 1 - (l.map fun g => exp (s • g) - 1).sum) + + ((l.map fun g => exp (s • g) - 1).sum - s • l.sum) + - (exp (s • l.sum) - 1 - s • l.sum)‖ + ≤ ‖((l.map fun g => exp (s • g)).prod - 1 - (l.map fun g => exp (s • g) - 1).sum) + + ((l.map fun g => exp (s • g) - 1).sum - s • l.sum)‖ + + ‖exp (s • l.sum) - 1 - s • l.sum‖ := norm_sub_le _ _ + _ ≤ (e1 ^ 2 * Real.exp e1 * (s * Λ) ^ 2 + e1 * (s * Λ) ^ 2) + e1 * (s * Λ) ^ 2 := + add_le_add ((norm_add_le _ _).trans (add_le_add hMAIN hMID)) hTAIL + _ = (2 * e1 + e1 ^ 2 * Real.exp e1) * (s * Λ) ^ 2 := by ring + +/-- The key second-order estimate behind the Lie–Trotter formula: for `0 ≤ t ≤ 1`, +`exp(t•x) exp(t•y)` and `exp(t•x + t•y)` agree up to `O(t²)`. Both equal `1 + t•(x+y) + O(t²)`; the +difference is controlled by the remainder bound `norm_exp_sub_one_sub_id_le`. -/ +private theorem norm_exp_smul_mul_exp_smul_sub_le (x y : 𝔸) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + ‖exp (t • x) * exp (t • y) - exp (t • x + t • y)‖ + ≤ (‖x‖ ^ 2 * Real.exp (‖x‖ + ‖y‖) ^ 2 + (1 + ‖x‖) * ‖y‖ ^ 2 * Real.exp (‖x‖ + ‖y‖) + + ‖x‖ * ‖y‖ + (‖x‖ + ‖y‖) ^ 2 * Real.exp (‖x‖ + ‖y‖)) * t ^ 2 := by + set a := ‖x‖ with ha + set b := ‖y‖ with hb + set E := Real.exp (a + b) with hE + have hann : 0 ≤ a := norm_nonneg x + have hbnn : 0 ≤ b := norm_nonneg y + have hnx : ‖t • x‖ = t * a := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + have hny : ‖t • y‖ = t * b := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + have hta : t * a ≤ a + b := by nlinarith [mul_nonneg (by linarith : (0:ℝ) ≤ 1 - t) hann] + have htb : t * b ≤ a + b := by nlinarith [mul_nonneg (by linarith : (0:ℝ) ≤ 1 - t) hbnn] + -- the algebraic identity `pq - r = R(u)·q + (1+u)·R(v) + u·v - R(u+v)` with `R z = exp z - 1 - z` + have hid : exp (t • x) * exp (t • y) - exp (t • x + t • y) + = (exp (t • x) - 1 - t • x) * exp (t • y) + + (1 + t • x) * (exp (t • y) - 1 - t • y) + + (t • x) * (t • y) + - (exp (t • x + t • y) - 1 - (t • x + t • y)) := by + simp only [add_mul, sub_mul, mul_sub, one_mul, mul_one]; abel + have hT1 : ‖(exp (t • x) - 1 - t • x) * exp (t • y)‖ ≤ a ^ 2 * E ^ 2 * t ^ 2 := by + refine (norm_mul_le _ _).trans ?_ + have h1 : ‖exp (t • x) - 1 - t • x‖ ≤ (t * a) ^ 2 * E := by + refine (norm_exp_sub_one_sub_id_le _).trans ?_ + rw [hnx]; gcongr; exact Real.exp_le_exp.mpr hta + have h2 : ‖exp (t • y)‖ ≤ E := + (norm_exp_le _).trans (by rw [hny]; exact Real.exp_le_exp.mpr htb) + calc ‖exp (t • x) - 1 - t • x‖ * ‖exp (t • y)‖ + ≤ ((t * a) ^ 2 * E) * E := by gcongr + _ = a ^ 2 * E ^ 2 * t ^ 2 := by ring + have hT2 : ‖(1 + t • x) * (exp (t • y) - 1 - t • y)‖ ≤ (1 + a) * b ^ 2 * E * t ^ 2 := by + refine (norm_mul_le _ _).trans ?_ + have h1 : ‖(1 : 𝔸) + t • x‖ ≤ 1 + a := by + refine (norm_add_le _ _).trans ?_; rw [norm_one, hnx]; nlinarith + have h2 : ‖exp (t • y) - 1 - t • y‖ ≤ (t * b) ^ 2 * E := by + refine (norm_exp_sub_one_sub_id_le _).trans ?_ + rw [hny]; gcongr; exact Real.exp_le_exp.mpr htb + calc ‖(1 : 𝔸) + t • x‖ * ‖exp (t • y) - 1 - t • y‖ + ≤ (1 + a) * ((t * b) ^ 2 * E) := by gcongr + _ = (1 + a) * b ^ 2 * E * t ^ 2 := by ring + have hT3 : ‖(t • x) * (t • y)‖ ≤ a * b * t ^ 2 := by + refine (norm_mul_le _ _).trans (le_of_eq ?_); rw [hnx, hny]; ring + have hT4 : ‖exp (t • x + t • y) - 1 - (t • x + t • y)‖ ≤ (a + b) ^ 2 * E * t ^ 2 := by + refine (norm_exp_sub_one_sub_id_le _).trans ?_ + have hw : ‖t • x + t • y‖ ≤ t * (a + b) := by + refine (norm_add_le _ _).trans (le_of_eq ?_); rw [hnx, hny]; ring + have hwsq : ‖t • x + t • y‖ ^ 2 ≤ (t * (a + b)) ^ 2 := pow_le_pow_left₀ (norm_nonneg _) hw 2 + have hexpw : Real.exp ‖t • x + t • y‖ ≤ E := + Real.exp_le_exp.mpr (le_trans hw (by nlinarith)) + calc ‖t • x + t • y‖ ^ 2 * Real.exp ‖t • x + t • y‖ + ≤ (t * (a + b)) ^ 2 * E := by gcongr + _ = (a + b) ^ 2 * E * t ^ 2 := by ring + rw [hid] + calc ‖(exp (t • x) - 1 - t • x) * exp (t • y) + (1 + t • x) * (exp (t • y) - 1 - t • y) + + (t • x) * (t • y) - (exp (t • x + t • y) - 1 - (t • x + t • y))‖ + ≤ ‖(exp (t • x) - 1 - t • x) * exp (t • y)‖ + ‖(1 + t • x) * (exp (t • y) - 1 - t • y)‖ + + ‖(t • x) * (t • y)‖ + ‖exp (t • x + t • y) - 1 - (t • x + t • y)‖ := by + refine (norm_sub_le _ _).trans ?_ + gcongr + exact norm_add₃_le + _ ≤ a ^ 2 * E ^ 2 * t ^ 2 + (1 + a) * b ^ 2 * E * t ^ 2 + a * b * t ^ 2 + + (a + b) ^ 2 * E * t ^ 2 := by gcongr + _ = (a ^ 2 * E ^ 2 + (1 + a) * b ^ 2 * E + a * b + (a + b) ^ 2 * E) * t ^ 2 := by ring + +/-- **The Lie product formula** (a.k.a. the **Trotter product formula**; Nielsen & Chuang, +*Quantum Computation and Quantum Information*, Theorem 4.3). In a Banach algebra `𝔸`, for any +`x y : 𝔸`, +`lim (exp(x/n) exp(y/n))ⁿ = exp(x + y)`, +i.e. `Tendsto (fun n => (exp (n⁻¹ • x) * exp (n⁻¹ • y)) ^ n) atTop (𝓝 (exp (x + y)))`. This holds +even when `x` and `y` do **not** commute. + +Nielsen & Chuang state it for Hermitian `A, B` and real `t` as +`lim (e^{iAt/n} e^{iBt/n})ⁿ = e^{i(A+B)t}`; that is the instance `x = (t : ℝ) • (i • A)`, +`y = (t : ℝ) • (i • B)` of the statement here (the exponent's `i`, `t` and Hermiticity are absorbed +into the arbitrary algebra elements `x`, `y`). -/ +theorem tendsto_pow_exp_smul_mul_exp_smul (x y : 𝔸) : + Tendsto (fun n : ℕ => (exp ((n : ℝ)⁻¹ • x) * exp ((n : ℝ)⁻¹ • y)) ^ n) atTop + (𝓝 (exp (x + y))) := by + have : NormedAlgebra ℚ 𝔸 := NormedAlgebra.restrictScalars ℚ ℝ 𝔸 + rw [tendsto_iff_norm_sub_tendsto_zero] + set E := Real.exp (‖x‖ + ‖y‖) with hE + set K := ‖x‖ ^ 2 * E ^ 2 + (1 + ‖x‖) * ‖y‖ ^ 2 * E + ‖x‖ * ‖y‖ + (‖x‖ + ‖y‖) ^ 2 * E with hK + have hEnn : 0 ≤ E := (Real.exp_pos _).le + -- for `n ≥ 1`, `‖(exp(x/n) exp(y/n))ⁿ - exp(x+y)‖ ≤ (E·K)/n` + have hbound : ∀ n : ℕ, 1 ≤ n → + ‖(exp ((n : ℝ)⁻¹ • x) * exp ((n : ℝ)⁻¹ • y)) ^ n - exp (x + y)‖ ≤ E * K * (n : ℝ)⁻¹ := by + intro n hn + set t := (n : ℝ)⁻¹ with ht + have hn' : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn + have hne : (n : ℝ) ≠ 0 := ne_of_gt hn' + have ht0 : 0 ≤ t := by rw [ht]; positivity + have ht1 : t ≤ 1 := by rw [ht]; exact inv_le_one_of_one_le₀ (by exact_mod_cast hn) + have hnx : ‖t • x‖ = t * ‖x‖ := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + have hny : ‖t • y‖ = t * ‖y‖ := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + -- a common bound `M = exp((‖x‖+‖y‖)·t)` on `‖aₙ‖` and `‖bₙ‖`, with `Mⁿ = E` + have haₙ : ‖exp (t • x) * exp (t • y)‖ ≤ Real.exp ((‖x‖ + ‖y‖) * t) := by + refine (norm_mul_le _ _).trans ?_ + calc ‖exp (t • x)‖ * ‖exp (t • y)‖ + ≤ Real.exp ‖t • x‖ * Real.exp ‖t • y‖ := + mul_le_mul (norm_exp_le _) (norm_exp_le _) (norm_nonneg _) (Real.exp_pos _).le + _ = Real.exp ((‖x‖ + ‖y‖) * t) := by + rw [← Real.exp_add, show ‖t • x‖ + ‖t • y‖ = (‖x‖ + ‖y‖) * t by rw [hnx, hny]; ring] + have hbₙ : ‖exp (t • x + t • y)‖ ≤ Real.exp ((‖x‖ + ‖y‖) * t) := by + refine (norm_exp_le _).trans (Real.exp_le_exp.mpr ?_) + refine (norm_add_le _ _).trans (le_of_eq ?_); rw [hnx, hny]; ring + have hc1 : (1 : ℝ) ≤ Real.exp ((‖x‖ + ‖y‖) * t) := Real.one_le_exp (by positivity) + have hnt1 : (n : ℝ) * t = 1 := by rw [ht]; exact mul_inv_cancel₀ hne + have hexpo : (n : ℝ) * ((‖x‖ + ‖y‖) * t) = ‖x‖ + ‖y‖ := by + calc (n : ℝ) * ((‖x‖ + ‖y‖) * t) = ((n : ℝ) * t) * (‖x‖ + ‖y‖) := by ring + _ = 1 * (‖x‖ + ‖y‖) := by rw [hnt1] + _ = ‖x‖ + ‖y‖ := one_mul _ + have hcpow : Real.exp ((‖x‖ + ‖y‖) * t) ^ n = E := by rw [← Real.exp_nat_mul, hexpo] + have hpow := norm_pow_sub_pow_le haₙ hbₙ hc1 n + rw [hcpow] at hpow + have key_smul : ∀ w : 𝔸, n • (t • w) = w := by + intro w + rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul, ht, mul_inv_cancel₀ hne, one_smul] + have hbpow : exp (t • x + t • y) ^ n = exp (x + y) := by + rw [← exp_nsmul, smul_add, key_smul, key_smul] + rw [hbpow] at hpow + have haux := norm_exp_smul_mul_exp_smul_sub_le x y ht0 ht1 + rw [← hE, ← hK] at haux + have hnt : (n : ℝ) * t ^ 2 = t := by rw [pow_two, ← mul_assoc, hnt1, one_mul] + calc ‖(exp (t • x) * exp (t • y)) ^ n - exp (x + y)‖ + ≤ ↑n * E * ‖exp (t • x) * exp (t • y) - exp (t • x + t • y)‖ := hpow + _ ≤ ↑n * E * (K * t ^ 2) := mul_le_mul_of_nonneg_left haux (by positivity) + _ = E * K * (↑n * t ^ 2) := by ring + _ = E * K * t := by rw [hnt] + have htend : Tendsto (fun n : ℕ => E * K * (n : ℝ)⁻¹) atTop (𝓝 0) := by + have h0 : Tendsto (fun n : ℕ => (n : ℝ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + simpa using h0.const_mul (E * K) + refine squeeze_zero' ?_ ?_ htend + · exact Eventually.of_forall fun n => norm_nonneg _ + · filter_upwards [eventually_ge_atTop 1] with n hn using hbound n hn + +/-- Existential repackaging of `norm_exp_smul_mul_exp_smul_sub_le`: for `x y : 𝔸` there is a +constant `K ≥ 0` (depending only on `x`, `y`) with +`‖exp(t•x) exp(t•y) - exp(t•x + t•y)‖ ≤ K·t²` for all `t ∈ [0, 1]`. This hides the explicit second +-order constant so it can be threaded through the induction in +`exists_norm_prod_exp_smul_sub_exp_smul_sum_le`. -/ +private theorem exists_norm_exp_smul_mul_exp_smul_sub_le (x y : 𝔸) : + ∃ K : ℝ, 0 ≤ K ∧ ∀ t : ℝ, 0 ≤ t → t ≤ 1 → + ‖exp (t • x) * exp (t • y) - exp (t • x + t • y)‖ ≤ K * t ^ 2 := by + refine ⟨_, ?_, fun t ht0 ht1 => norm_exp_smul_mul_exp_smul_sub_le x y ht0 ht1⟩ + positivity + +/-- **First-order error of the Lie–Trotter splitting of a finite product.** For a list `l : List 𝔸` +in a Banach algebra there is a constant `C ≥ 0` (depending only on `l`) such that, for every +`t ∈ [0, 1]`, +`‖(∏ g ∈ l, exp(t•g)) - exp(t • ∑ g ∈ l, g)‖ ≤ C·t²`, +where the product is taken in the list's order. In other words, splitting `exp(t • ∑ gᵢ)` as the +ordered product `∏ exp(t•gᵢ)` incurs only a second-order (`O(t²)`) error, even though the `gᵢ` need +not commute. + +This is the operator content of Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Problem 4.3(4): taking `gᵢ = -i·hᵢ·Pᵢ` (real `hᵢ`, Pauli-string operators `Pᵢ`) and `t = Δ` gives +`exp(-iHΔ) = ∏ᵢ exp(-i hᵢ Pᵢ Δ) + O(Δ²)` for `H = ∑ᵢ hᵢ Pᵢ`. + +The proof is induction on `l`: the empty product is exact, and the cons step inserts +`exp(t•a)·exp(t • ∑ l)` between the two sides, bounding the first gap by the inductive hypothesis +(scaled by `‖exp(t•a)‖ ≤ Real.exp ‖a‖`) and the second by the two-factor estimate +`exists_norm_exp_smul_mul_exp_smul_sub_le`. -/ +theorem exists_norm_prod_exp_smul_sub_exp_smul_sum_le (l : List 𝔸) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t : ℝ, 0 ≤ t → t ≤ 1 → + ‖(l.map fun g => exp (t • g)).prod - exp (t • l.sum)‖ ≤ C * t ^ 2 := by + induction l with + | nil => exact ⟨0, le_refl 0, fun t _ _ => by simp [NormedSpace.exp_zero]⟩ + | cons a l ih => + obtain ⟨C', hC'0, hC'⟩ := ih + obtain ⟨K, hK0, hK⟩ := exists_norm_exp_smul_mul_exp_smul_sub_le a l.sum + refine ⟨Real.exp ‖a‖ * C' + K, by positivity, fun t ht0 ht1 => ?_⟩ + have hexpa : ‖exp (t • a)‖ ≤ Real.exp ‖a‖ := by + refine (norm_exp_le _).trans (Real.exp_le_exp.mpr ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + exact mul_le_of_le_one_left (norm_nonneg a) ht1 + have hmap : ((a :: l).map fun g => exp (t • g)).prod + = exp (t • a) * (l.map fun g => exp (t • g)).prod := by + rw [List.map_cons, List.prod_cons] + calc ‖((a :: l).map fun g => exp (t • g)).prod - exp (t • (a :: l).sum)‖ + = ‖exp (t • a) * (l.map fun g => exp (t • g)).prod - exp (t • a + t • l.sum)‖ := by + rw [hmap, List.sum_cons, smul_add] + _ ≤ ‖exp (t • a) * (l.map fun g => exp (t • g)).prod - exp (t • a) * exp (t • l.sum)‖ + + ‖exp (t • a) * exp (t • l.sum) - exp (t • a + t • l.sum)‖ := by + have hsplit : + exp (t • a) * (l.map fun g => exp (t • g)).prod - exp (t • a + t • l.sum) + = (exp (t • a) * (l.map fun g => exp (t • g)).prod + - exp (t • a) * exp (t • l.sum)) + + (exp (t • a) * exp (t • l.sum) - exp (t • a + t • l.sum)) := by abel + rw [hsplit]; exact norm_add_le _ _ + _ ≤ Real.exp ‖a‖ * C' * t ^ 2 + K * t ^ 2 := by + refine add_le_add ?_ (hK t ht0 ht1) + rw [← mul_sub] + refine (norm_mul_le _ _).trans ?_ + calc ‖exp (t • a)‖ * ‖(l.map fun g => exp (t • g)).prod - exp (t • l.sum)‖ + ≤ Real.exp ‖a‖ * (C' * t ^ 2) := + mul_le_mul hexpa (hC' t ht0 ht1) (norm_nonneg _) (Real.exp_pos _).le + _ = Real.exp ‖a‖ * C' * t ^ 2 := by ring + _ = (Real.exp ‖a‖ * C' + K) * t ^ 2 := by ring + +/-- **The norm of a product of exponentials is bounded by the exponential of the scaled sum of the +norms.** In a Banach algebra, for `s ≥ 0` and a list `l : List 𝔸`, +`‖∏ g ∈ l, exp(s•g)‖ ≤ Real.exp (s · ∑ g ∈ l, ‖g‖)`. +Submultiplicativity gives `‖exp(s•g)‖ ≤ Real.exp (s‖g‖)` on each factor, and `Real.exp_add` turns +the product of these bounds into `Real.exp` of the sum. This controls both bases of the telescoping +step in `exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le`. -/ +theorem norm_prod_exp_smul_le (l : List 𝔸) {s : ℝ} (hs : 0 ≤ s) : + ‖(l.map fun g => exp (s • g)).prod‖ ≤ Real.exp (s * (l.map fun g => ‖g‖).sum) := by + induction l with + | nil => simp + | cons b l ih => + rw [List.map_cons, List.prod_cons] + refine (norm_mul_le _ _).trans ?_ + rw [List.map_cons, List.sum_cons, mul_add, Real.exp_add] + refine mul_le_mul ?_ ih (norm_nonneg _) (Real.exp_pos _).le + refine (norm_exp_le _).trans (le_of_eq ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hs] + +/-- **Accumulated first-order error of the `k`-fold Lie–Trotter approximation.** For a list +`l : List 𝔸` in a Banach algebra there is a constant `C ≥ 0` (depending only on `l`) such that, for +every positive integer `k`, +`‖(∏ g ∈ l, exp(k⁻¹•g))^k - exp(∑ g ∈ l, g)‖ ≤ C·k⁻¹`, +where the product is taken in the list's order. Splitting `exp(∑ gᵢ)` into `k` slices of the ordered +product `∏ exp(k⁻¹•gᵢ)` and iterating `k` times drives the total error to zero as `k → ∞`, at rate +`O(k⁻¹)`. + +This is the operator content of Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Problem 4.3(5): with `gᵢ = -i·hᵢ·Pᵢ`, `Δ = k⁻¹` and `H = ∑ᵢ hᵢ Pᵢ` (so `exp(∑ gᵢ) = exp(-iH) = U`), +`U = [∏ᵢ exp(-i hᵢ Pᵢ Δ)]^k + O(Δ)`. + +The proof combines the per-slice bound `exists_norm_prod_exp_smul_sub_exp_smul_sum_le` (error +`C₁·k⁻²` at `t = k⁻¹`) with the noncommutative telescoping estimate `norm_pow_sub_pow_le`: the +`k`-th powers differ by at most `k · Mᵏ · (per-slice error)`, where `M = Real.exp(k⁻¹·∑‖gᵢ‖)` bounds +both bases and `Mᵏ = Real.exp(∑‖gᵢ‖)` is independent of `k`; the surviving factor `k · k⁻² = k⁻¹` is +the claimed rate. -/ +theorem exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le (l : List 𝔸) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ k : ℕ, 1 ≤ k → + ‖((l.map fun g => exp ((k : ℝ)⁻¹ • g)).prod) ^ k - exp l.sum‖ ≤ C * (k : ℝ)⁻¹ := by + have : NormedAlgebra ℚ 𝔸 := NormedAlgebra.restrictScalars ℚ ℝ 𝔸 + obtain ⟨C₁, hC₁0, hC₁⟩ := exists_norm_prod_exp_smul_sub_exp_smul_sum_le l + -- `‖∑ g‖ ≤ ∑‖g‖` is the library lemma `norm_multiset_sum_le` on the underlying multiset + have hSnorm : ‖l.sum‖ ≤ (l.map fun g => ‖g‖).sum := by + simpa using norm_multiset_sum_le (l : Multiset 𝔸) + have hNnn : 0 ≤ (l.map fun g => ‖g‖).sum := + List.sum_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg y + refine ⟨Real.exp (l.map fun g => ‖g‖).sum * C₁, mul_nonneg (Real.exp_pos _).le hC₁0, + fun k hk => ?_⟩ + set N := (l.map fun g => ‖g‖).sum with hN + set t := (k : ℝ)⁻¹ with ht + have hkne : (k : ℝ) ≠ 0 := by positivity + have ht0 : 0 ≤ t := by rw [ht]; positivity + have ht1 : t ≤ 1 := by rw [ht]; exact inv_le_one_of_one_le₀ (by exact_mod_cast hk) + have hkt : (k : ℝ) * t = 1 := by rw [ht]; exact mul_inv_cancel₀ hkne + set P := (l.map fun g => exp (t • g)).prod with hP + set M := Real.exp (t * N) with hM + have hM1 : 1 ≤ M := Real.one_le_exp (mul_nonneg ht0 hNnn) + have hPle : ‖P‖ ≤ M := norm_prod_exp_smul_le l ht0 + have hExpSle : ‖exp (t • l.sum)‖ ≤ M := by + refine (norm_exp_le _).trans (Real.exp_le_exp.mpr ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + exact mul_le_mul_of_nonneg_left hSnorm ht0 + have hMk : M ^ k = Real.exp N := by + rw [hM, ← Real.exp_nat_mul]; congr 1; rw [← mul_assoc, hkt, one_mul] + have hexpk : exp (t • l.sum) ^ k = exp l.sum := by + rw [← exp_nsmul]; congr 1 + rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul, hkt, one_smul] + have hpow := norm_pow_sub_pow_le hPle hExpSle hM1 k + rw [hexpk, hMk] at hpow + have hkt2 : (k : ℝ) * t ^ 2 = t := by rw [pow_two, ← mul_assoc, hkt, one_mul] + calc ‖P ^ k - exp l.sum‖ + ≤ (k : ℝ) * Real.exp N * ‖P - exp (t • l.sum)‖ := hpow + _ ≤ (k : ℝ) * Real.exp N * (C₁ * t ^ 2) := + mul_le_mul_of_nonneg_left (hC₁ t ht0 ht1) (by positivity) + _ = Real.exp N * C₁ * ((k : ℝ) * t ^ 2) := by ring + _ = Real.exp N * C₁ * t := by rw [hkt2] + +/-- **Explicit-constant `k`-fold Lie–Trotter bound for contraction generators.** In a Banach +algebra, for a list `l : List 𝔸` whose elements — and whose sum `∑ᵢ gᵢ` — generate contractions +(`‖exp(s•gᵢ)‖ ≤ 1` and `‖exp(s•∑g)‖ ≤ 1` for every `s ≥ 0`, e.g. when the `gᵢ` are skew-adjoint so +the exponentials are unitary), the `k`-fold splitting of `exp(∑ᵢ gᵢ)` into `(∏ᵢ exp(k⁻¹•gᵢ))^k` +carries a **numerical**-constant, **polynomial**-in-`Λ` error, `Λ = ∑ᵢ ‖gᵢ‖`: +`‖(∏ᵢ exp(k⁻¹•gᵢ))^k - exp(∑ᵢ gᵢ)‖ ≤ (2e + e²·eᵉ)·Λ²·k⁻¹`. + +This sharpens `exists_norm_prod_exp_inv_smul_pow_sub_exp_sum_le`, whose constant is existential and, +being built from the general (non-unitary) two-factor estimate, carries a `Real.exp Λ` factor. Here +the constant is the fixed real `2·Real.exp 1 + Real.exp 1 ^ 2 · Real.exp (Real.exp 1)`, independent +of both `l` and `k`, and the `Λ`-dependence is a clean `Λ²`. That polynomial rate is exactly what +Nielsen & Chuang, *Quantum Computation and Quantum Information*, Problem 4.3(6)'s literal +`O(n·16ⁿ/ε)` gate count needs: with `gᵢ = -i hᵢ Pᵢ` (Pauli-string operators, real `hᵢ`, so the `gᵢ` +are skew-adjoint) and `Δ = k⁻¹`, `Λ = ∑ᵢ |hᵢ| = O(2ⁿ)` gives error `O(4ⁿ)/k`, so achieving accuracy +`ε` needs `k = O(4ⁿ/ε)` steps — no exponential blow-up. + +**Proof** (two regimes at the threshold `Λ ≤ k`). Write `t = k⁻¹`, `P = ∏ᵢ exp(t•gᵢ)`, +`Q = exp(t•∑g)`, so `Qᵏ = exp(∑g)` (`exp_nsmul`). Both bases are contractions: `‖P‖ ≤ 1` +(`norm_listProd_le_one`, factorwise from the hypothesis) and `‖Q‖ ≤ 1` (hypothesis). *Regime +`Λ ≤ k`* (so `t·Λ ≤ 1`): the +telescoping bound `norm_pow_sub_pow_le` with `M = 1` gives `‖Pᵏ - Qᵏ‖ ≤ k·‖P - Q‖`, and the explicit +single-step bound `norm_prod_exp_smul_sub_exp_smul_sum_le_sq` gives `‖P - Q‖ ≤ C·(t·Λ)²`; since +`k·t² = t = k⁻¹`, the product is `C·Λ²·k⁻¹`. *Regime `k < Λ`*: `‖Pᵏ - exp(∑g)‖ ≤ ‖Pᵏ‖ + ‖exp(∑g)‖ ≤ +2` (both contractions), and `2 ≤ C·Λ²·k⁻¹` because `Λ² > k` (as `Λ > k ≥ 1`) and `C > 2`. -/ +theorem norm_prod_exp_inv_smul_pow_sub_exp_sum_le_sq (l : List 𝔸) + (hg : ∀ g ∈ l, ∀ s : ℝ, 0 ≤ s → ‖exp (s • g)‖ ≤ 1) + (hsum : ∀ s : ℝ, 0 ≤ s → ‖exp (s • l.sum)‖ ≤ 1) + {k : ℕ} (hk : 1 ≤ k) : + ‖((l.map fun g => exp ((k : ℝ)⁻¹ • g)).prod) ^ k - exp l.sum‖ + ≤ trotterProductConst * (l.map fun g => ‖g‖).sum ^ 2 * (k : ℝ)⁻¹ := by + have : NormedAlgebra ℚ 𝔸 := NormedAlgebra.restrictScalars ℚ ℝ 𝔸 + set Λ := (l.map fun g => ‖g‖).sum with hΛ + have hΛnn : 0 ≤ Λ := by + rw [hΛ]; exact List.sum_nonneg fun x hx => by + rw [List.mem_map] at hx; obtain ⟨y, _, rfl⟩ := hx; exact norm_nonneg _ + set C := trotterProductConst with hC + have hC2 : 2 ≤ C := by rw [hC]; exact two_le_trotterProductConst + have hCnn : 0 ≤ C := le_trans zero_le_two hC2 + set t := (k : ℝ)⁻¹ with ht + have hkne : (k : ℝ) ≠ 0 := by positivity + have ht0 : 0 ≤ t := by rw [ht]; positivity + have hkt : (k : ℝ) * t = 1 := by rw [ht]; exact mul_inv_cancel₀ hkne + have hkt2 : (k : ℝ) * t ^ 2 = t := by rw [pow_two, ← mul_assoc, hkt, one_mul] + set P := (l.map fun g => exp (t • g)).prod with hP + have hPle : ‖P‖ ≤ 1 := by + rw [hP] + exact norm_listProd_le_one fun x hx => by + rw [List.mem_map] at hx; obtain ⟨g, hgl, rfl⟩ := hx; exact hg g hgl t ht0 + have hexpk : exp (t • l.sum) ^ k = exp l.sum := by + rw [← exp_nsmul]; congr 1 + rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul, hkt, one_smul] + rcases le_or_gt Λ (k : ℝ) with hle | hlt + · -- Regime `Λ ≤ k`: the explicit single-step bound telescopes with `M = 1`. + have htΛ : t * Λ ≤ 1 := by + calc t * Λ ≤ t * (k : ℝ) := mul_le_mul_of_nonneg_left hle ht0 + _ = 1 := by rw [mul_comm]; exact hkt + have hQle : ‖exp (t • l.sum)‖ ≤ 1 := hsum t ht0 + have hpow := norm_pow_sub_pow_le hPle hQle (le_refl (1 : ℝ)) k + rw [hexpk, one_pow, mul_one] at hpow + have hPQ : ‖P - exp (t • l.sum)‖ ≤ C * (t * Λ) ^ 2 := + norm_prod_exp_smul_sub_exp_smul_sum_le_sq l ht0 htΛ + calc ‖P ^ k - exp l.sum‖ + ≤ (k : ℝ) * ‖P - exp (t • l.sum)‖ := hpow + _ ≤ (k : ℝ) * (C * (t * Λ) ^ 2) := mul_le_mul_of_nonneg_left hPQ (by positivity) + _ = C * Λ ^ 2 * ((k : ℝ) * t ^ 2) := by ring + _ = C * Λ ^ 2 * t := by rw [hkt2] + · -- Regime `k < Λ`: the trivial contraction bound `‖·‖ ≤ 2` already fits `C·Λ²·k⁻¹`. + have hΛ1 : (1 : ℝ) < Λ := lt_of_le_of_lt (by exact_mod_cast hk) hlt + have hΛsq : (k : ℝ) ≤ Λ ^ 2 := by + have hle2 : Λ ≤ Λ ^ 2 := by nlinarith [hΛ1] + linarith + have hfrac : 1 ≤ Λ ^ 2 * t := by + have h := mul_le_mul_of_nonneg_right hΛsq ht0 + rwa [hkt] at h + have htriv : ‖P ^ k - exp l.sum‖ ≤ 2 := by + have hPk : ‖P ^ k‖ ≤ 1 := le_trans (norm_pow_le P k) (pow_le_one₀ (norm_nonneg P) hPle) + have hE : ‖exp l.sum‖ ≤ 1 := by + have h := hsum 1 zero_le_one; rwa [one_smul] at h + calc ‖P ^ k - exp l.sum‖ ≤ ‖P ^ k‖ + ‖exp l.sum‖ := norm_sub_le _ _ + _ ≤ 1 + 1 := add_le_add hPk hE + _ = 2 := by norm_num + refine htriv.trans ?_ + calc (2 : ℝ) ≤ C := hC2 + _ = C * 1 := (mul_one C).symm + _ ≤ C * (Λ ^ 2 * t) := mul_le_mul_of_nonneg_left hfrac hCnn + _ = C * Λ ^ 2 * t := by ring + +/-- **Symmetric (Strang) second-order splitting error of `exp`.** In a Banach algebra, for `x y : 𝔸` +there is a constant `K ≥ 0` (depending only on `x`, `y`) such that, for every `t ∈ [0, 1]`, +`‖exp(t•x) · exp((2t)•y) · exp(t•x) - exp((2t)•(x + y))‖ ≤ K·t³`. + +Unlike the plain (unsymmetric) two-factor splitting `exp(t•x) exp(t•y) ≈ exp(t•(x+y))`, which is +only accurate to `O(t²)` (`norm_exp_smul_mul_exp_smul_sub_le`), the **palindromic** product +`exp(t•x) exp((2t)•y) exp(t•x)` approximates `exp((2t)•(x + y))` to `O(t³)`: the second-order terms +cancel by symmetry. This is the base case (`L = 1` interior factor) of Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 4.50(a), and it is the operator content of one +symmetric Trotter–Suzuki step: taking `x = -i·H₁`, `y = -i·H₂` gives +`e^{-iH₁t} e^{-2iH₂t} e^{-iH₁t} = e^{-2i(H₁+H₂)t} + O(t³)`. + +**Proof.** Write `exp z = T z + S z` where `T z = 1 + z + z²/2` is the second-order Taylor +polynomial and `S z = exp z - T z` the remainder, `‖S z‖ ≤ ‖z‖³·Real.exp‖z‖` (the bound +`norm_exp_sub_one_sub_id_sub_half_sq_le`). With `u = t•x`, `v = (2t)•y`, `w = (2t)•(x+y)`, split +`exp u · exp v · exp u - exp w = (exp u exp v exp u - Tu Tv Tu) + (Tu Tv Tu - Tw) - S w`. +The first bracket telescopes into three products, each carrying one `S`-factor, hence `O(t³)`. The +middle bracket is a *polynomial* identity: `Tu Tv Tu - Tw` has **no** terms of degree `≤ 2` in +`u, v` — the second-order cancellation — so it factors as `t³·D₃ + t⁴·D₄ + t⁵·D₅ + t⁶·D₆` and is +`O(t³)` on `[0,1]`. The last term is the remainder `S w`. -/ +theorem exists_norm_exp_smul_mul_exp_two_smul_mul_exp_smul_sub_le (x y : 𝔸) : + ∃ K : ℝ, 0 ≤ K ∧ ∀ t : ℝ, 0 ≤ t → t ≤ 1 → + ‖exp (t • x) * exp ((2 * t) • y) * exp (t • x) - exp ((2 * t) • (x + y))‖ ≤ K * t ^ 3 := by + refine ⟨(‖x‖ ^ 3 * Real.exp ‖x‖ * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ + + 8 * (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ + + (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * (1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2) * (‖x‖ ^ 3 * Real.exp ‖x‖)) + + (‖(x ^ 3 + 2 • (x * y * x) + 2 • (x * y ^ 2) + x ^ 2 * y + 2 • (y ^ 2 * x) + y * x ^ 2 : 𝔸)‖ + + ‖((4⁻¹ : ℝ) • x ^ 4 + 2 • (x * y ^ 2 * x) + x ^ 2 * y * x + x * y * x ^ 2 + x ^ 2 * y ^ 2 + + y ^ 2 * x ^ 2 : 𝔸)‖ + + ‖(x ^ 2 * y ^ 2 * x + x * y ^ 2 * x ^ 2 + (2⁻¹ : ℝ) • (x ^ 2 * y * x ^ 2) : 𝔸)‖ + + ‖((2⁻¹ : ℝ) • (x ^ 2 * y ^ 2 * x ^ 2) : 𝔸)‖) + + 8 * ‖x + y‖ ^ 3 * Real.exp (2 * ‖x + y‖), by positivity, fun t ht0 ht1 => ?_⟩ + set Tu : 𝔸 := 1 + t • x + (2⁻¹ : ℝ) • (t • x) ^ 2 with hTu + set Tv : 𝔸 := 1 + (2 * t) • y + (2⁻¹ : ℝ) • ((2 * t) • y) ^ 2 with hTv + set Tw : 𝔸 := 1 + (2 * t) • (x + y) + (2⁻¹ : ℝ) • ((2 * t) • (x + y)) ^ 2 with hTw + have hnx : ‖t • x‖ = t * ‖x‖ := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + have hny : ‖(2 * t) • y‖ = 2 * t * ‖y‖ := by + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (by positivity)] + have hnw : ‖(2 * t) • (x + y)‖ = 2 * t * ‖x + y‖ := by + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (by positivity)] + have htx : t * ‖x‖ ≤ ‖x‖ := by nlinarith [norm_nonneg x] + -- each `t^n • D` with `n ≥ 3` is bounded by `‖D‖·t³` on `[0,1]` + have hk : ∀ (n : ℕ) (D : 𝔸), 3 ≤ n → ‖(t ^ n : ℝ) • D‖ ≤ ‖D‖ * t ^ 3 := by + intro n D hn + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (by positivity)] + calc t ^ n * ‖D‖ ≤ t ^ 3 * ‖D‖ := + mul_le_mul_of_nonneg_right (pow_le_pow_of_le_one ht0 ht1 hn) (norm_nonneg D) + _ = ‖D‖ * t ^ 3 := by ring + -- third-order remainders `S u`, `S v`, `S w`, each `O(t³)` + have hSu : ‖exp (t • x) - Tu‖ ≤ ‖x‖ ^ 3 * Real.exp ‖x‖ * t ^ 3 := by + have heq : exp (t • x) - Tu = exp (t • x) - 1 - (t • x) - (2⁻¹ : ℝ) • (t • x) ^ 2 := by + rw [hTu]; abel + rw [heq] + refine (norm_exp_sub_one_sub_id_sub_half_sq_le (t • x)).trans ?_ + rw [hnx] + calc (t * ‖x‖) ^ 3 * Real.exp (t * ‖x‖) + ≤ (t * ‖x‖) ^ 3 * Real.exp ‖x‖ := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr htx) (by positivity) + _ = ‖x‖ ^ 3 * Real.exp ‖x‖ * t ^ 3 := by ring + have hSv : ‖exp ((2 * t) • y) - Tv‖ ≤ 8 * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * t ^ 3 := by + have heq : exp ((2 * t) • y) - Tv + = exp ((2 * t) • y) - 1 - ((2 * t) • y) - (2⁻¹ : ℝ) • ((2 * t) • y) ^ 2 := by rw [hTv]; abel + rw [heq] + refine (norm_exp_sub_one_sub_id_sub_half_sq_le ((2 * t) • y)).trans ?_ + rw [hny] + calc (2 * t * ‖y‖) ^ 3 * Real.exp (2 * t * ‖y‖) + ≤ (2 * t * ‖y‖) ^ 3 * Real.exp (2 * ‖y‖) := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by nlinarith [norm_nonneg y])) + (by positivity) + _ = 8 * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * t ^ 3 := by ring + have hSw : ‖exp ((2 * t) • (x + y)) - Tw‖ ≤ 8 * ‖x + y‖ ^ 3 * Real.exp (2 * ‖x + y‖) * t ^ 3 := by + have heq : exp ((2 * t) • (x + y)) - Tw + = exp ((2 * t) • (x + y)) - 1 - ((2 * t) • (x + y)) + - (2⁻¹ : ℝ) • ((2 * t) • (x + y)) ^ 2 := by rw [hTw]; abel + rw [heq] + refine (norm_exp_sub_one_sub_id_sub_half_sq_le ((2 * t) • (x + y))).trans ?_ + rw [hnw] + calc (2 * t * ‖x + y‖) ^ 3 * Real.exp (2 * t * ‖x + y‖) + ≤ (2 * t * ‖x + y‖) ^ 3 * Real.exp (2 * ‖x + y‖) := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by nlinarith [norm_nonneg (x + y)])) + (by positivity) + _ = 8 * ‖x + y‖ ^ 3 * Real.exp (2 * ‖x + y‖) * t ^ 3 := by ring + -- `O(1)` bounds on the remaining factors + have hexpu : ‖exp (t • x)‖ ≤ Real.exp ‖x‖ := + (norm_exp_le _).trans (Real.exp_le_exp.mpr (by rw [hnx]; exact htx)) + have hexpv : ‖exp ((2 * t) • y)‖ ≤ Real.exp (2 * ‖y‖) := + (norm_exp_le _).trans (Real.exp_le_exp.mpr (by rw [hny]; nlinarith [norm_nonneg y])) + have hTun : ‖Tu‖ ≤ 1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2 := by + have hp : ‖(t • x) ^ 2‖ ≤ ‖x‖ ^ 2 := by + refine (norm_pow_le _ 2).trans ?_; rw [hnx] + exact pow_le_pow_left₀ (mul_nonneg ht0 (norm_nonneg x)) htx 2 + have h2 : ‖(2⁻¹ : ℝ) • (t • x) ^ 2‖ ≤ 2⁻¹ * ‖x‖ ^ 2 := by + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (by norm_num : (0 : ℝ) < 2⁻¹)]; gcongr + rw [hTu] + calc ‖(1 : 𝔸) + t • x + (2⁻¹ : ℝ) • (t • x) ^ 2‖ + ≤ ‖(1 : 𝔸)‖ + ‖t • x‖ + ‖(2⁻¹ : ℝ) • (t • x) ^ 2‖ := norm_add₃_le + _ ≤ 1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2 := by + rw [norm_one, hnx]; exact add_le_add (add_le_add le_rfl htx) h2 + have hTvn : ‖Tv‖ ≤ 1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2 := by + have hp : ‖((2 * t) • y) ^ 2‖ ≤ (2 * ‖y‖) ^ 2 := by + refine (norm_pow_le _ 2).trans ?_; rw [hny] + exact pow_le_pow_left₀ (by positivity) (by nlinarith [norm_nonneg y]) 2 + have h2 : ‖(2⁻¹ : ℝ) • ((2 * t) • y) ^ 2‖ ≤ 2 * ‖y‖ ^ 2 := by + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (by norm_num : (0 : ℝ) < 2⁻¹)] + calc (2⁻¹ : ℝ) * ‖((2 * t) • y) ^ 2‖ ≤ 2⁻¹ * (2 * ‖y‖) ^ 2 := by gcongr + _ = 2 * ‖y‖ ^ 2 := by ring + rw [hTv] + calc ‖(1 : 𝔸) + (2 * t) • y + (2⁻¹ : ℝ) • ((2 * t) • y) ^ 2‖ + ≤ ‖(1 : 𝔸)‖ + ‖(2 * t) • y‖ + ‖(2⁻¹ : ℝ) • ((2 * t) • y) ^ 2‖ := norm_add₃_le + _ ≤ 1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2 := by + rw [norm_one, hny] + exact add_le_add (add_le_add le_rfl (by nlinarith [norm_nonneg y])) h2 + -- the telescoping (`S`-factor) part: `exp u exp v exp u - Tu Tv Tu` + have hRest : ‖exp (t • x) * exp ((2 * t) • y) * exp (t • x) - Tu * Tv * Tu‖ + ≤ (‖x‖ ^ 3 * Real.exp ‖x‖ * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ + + 8 * (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ + + (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * (1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2) * (‖x‖ ^ 3 * Real.exp ‖x‖)) + * t ^ 3 := by + have hid : exp (t • x) * exp ((2 * t) • y) * exp (t • x) - Tu * Tv * Tu + = (exp (t • x) - Tu) * exp ((2 * t) • y) * exp (t • x) + + Tu * (exp ((2 * t) • y) - Tv) * exp (t • x) + + Tu * Tv * (exp (t • x) - Tu) := by noncomm_ring + rw [hid] + conv_rhs => rw [add_mul, add_mul] + refine norm_add₃_le.trans (add_le_add (add_le_add ?_ ?_) ?_) + · refine norm_mul₃_le.trans ?_ + calc ‖exp (t • x) - Tu‖ * ‖exp ((2 * t) • y)‖ * ‖exp (t • x)‖ + ≤ (‖x‖ ^ 3 * Real.exp ‖x‖ * t ^ 3) * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ := by gcongr + _ = ‖x‖ ^ 3 * Real.exp ‖x‖ * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ * t ^ 3 := by ring + · refine norm_mul₃_le.trans ?_ + calc ‖Tu‖ * ‖exp ((2 * t) • y) - Tv‖ * ‖exp (t • x)‖ + ≤ (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * (8 * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * t ^ 3) + * Real.exp ‖x‖ := by gcongr + _ = 8 * (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * ‖y‖ ^ 3 * Real.exp (2 * ‖y‖) * Real.exp ‖x‖ + * t ^ 3 := by ring + · refine norm_mul₃_le.trans ?_ + calc ‖Tu‖ * ‖Tv‖ * ‖exp (t • x) - Tu‖ + ≤ (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * (1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2) + * (‖x‖ ^ 3 * Real.exp ‖x‖ * t ^ 3) := by gcongr + _ = (1 + ‖x‖ + 2⁻¹ * ‖x‖ ^ 2) * (1 + 2 * ‖y‖ + 2 * ‖y‖ ^ 2) * (‖x‖ ^ 3 * Real.exp ‖x‖) + * t ^ 3 := by ring + -- the polynomial part: `Tu Tv Tu - Tw` has no degree-`≤ 2` terms (the second-order cancellation) + have hDpoly : ‖Tu * Tv * Tu - Tw‖ + ≤ (‖(x ^ 3 + 2 • (x * y * x) + 2 • (x * y ^ 2) + x ^ 2 * y + 2 • (y ^ 2 * x) + y * x ^ 2 : 𝔸)‖ + + ‖((4⁻¹ : ℝ) • x ^ 4 + 2 • (x * y ^ 2 * x) + x ^ 2 * y * x + x * y * x ^ 2 + x ^ 2 * y ^ 2 + + y ^ 2 * x ^ 2 : 𝔸)‖ + + ‖(x ^ 2 * y ^ 2 * x + x * y ^ 2 * x ^ 2 + (2⁻¹ : ℝ) • (x ^ 2 * y * x ^ 2) : 𝔸)‖ + + ‖((2⁻¹ : ℝ) • (x ^ 2 * y ^ 2 * x ^ 2) : 𝔸)‖) * t ^ 3 := by + have hfact : Tu * Tv * Tu - Tw + = t ^ 3 • (x ^ 3 + 2 • (x * y * x) + 2 • (x * y ^ 2) + x ^ 2 * y + 2 • (y ^ 2 * x) + + y * x ^ 2) + + t ^ 4 • ((4⁻¹ : ℝ) • x ^ 4 + 2 • (x * y ^ 2 * x) + x ^ 2 * y * x + x * y * x ^ 2 + + x ^ 2 * y ^ 2 + y ^ 2 * x ^ 2) + + t ^ 5 • (x ^ 2 * y ^ 2 * x + x * y ^ 2 * x ^ 2 + (2⁻¹ : ℝ) • (x ^ 2 * y * x ^ 2)) + + t ^ 6 • ((2⁻¹ : ℝ) • (x ^ 2 * y ^ 2 * x ^ 2)) := by + rw [hTu, hTv, hTw]; noncomm_ring; module + rw [hfact] + conv_rhs => rw [add_mul, add_mul, add_mul] + refine (norm_add_le _ _).trans (add_le_add ((norm_add_le _ _).trans (add_le_add + ((norm_add_le _ _).trans (add_le_add (hk 3 _ (by norm_num)) (hk 4 _ (by norm_num)))) + (hk 5 _ (by norm_num)))) (hk 6 _ (by norm_num))) + calc ‖exp (t • x) * exp ((2 * t) • y) * exp (t • x) - exp ((2 * t) • (x + y))‖ + = ‖(exp (t • x) * exp ((2 * t) • y) * exp (t • x) - Tu * Tv * Tu) + (Tu * Tv * Tu - Tw) + + (Tw - exp ((2 * t) • (x + y)))‖ := by congr 1; abel + _ ≤ ‖exp (t • x) * exp ((2 * t) • y) * exp (t • x) - Tu * Tv * Tu‖ + ‖Tu * Tv * Tu - Tw‖ + + ‖Tw - exp ((2 * t) • (x + y))‖ := norm_add₃_le + _ ≤ _ := by + conv_rhs => rw [add_mul, add_mul] + refine add_le_add (add_le_add hRest hDpoly) ?_ + rw [norm_sub_rev]; exact hSw + +/-- **Symmetric (Strang) second-order splitting error of a finite product** (Nielsen & Chuang, +*Quantum Computation and Quantum Information*, Exercise 4.50(a), list form). For a list `l : List 𝔸` +in a Banach algebra there is a constant `C ≥ 0` (depending only on `l`) such that, for every +`t ∈ [0, 1]`, +`‖(∏ g ∈ l, exp(t•g)) · (∏ g ∈ l.reverse, exp(t•g)) - exp((2t) • ∑ g ∈ l, g)‖ ≤ C·t³`, +each product taken in its list's order. That is, the **palindromic** product — the ordered product +of the `exp(t•gᵢ)` immediately followed by the same factors in reverse order — approximates +`exp(2t • ∑ gᵢ)` to third order in `t`, one order better than the unsymmetric splitting +`exists_norm_prod_exp_smul_sub_exp_smul_sum_le` (only `O(t²)`); the palindrome makes the +second-order terms cancel. + +This is the operator content of Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 4.50(a): taking `gᵢ = -i·Hᵢ` and `t = Δt` gives, for `H = ∑ᵢ Hᵢ`, +`UΔt := [e^{-iH₁Δt} ⋯ e^{-iH_LΔt}][e^{-iH_LΔt} ⋯ e^{-iH₁Δt}] = e^{-2iHΔt} + O(Δt³)`. + +The proof is induction on `l` via the palindrome recursion. The empty product is `exp 0` exactly; +for `a :: l` the product equals `exp(t•a) · P(l) · exp(t•a)`, where `P(l)` is the palindromic +product of `l`. Replacing `P(l)` by `exp(2t•∑l)` costs +`‖exp(t•a)‖² · (C_l·t³) ≤ Real.exp(2‖a‖) · C_l·t³` (the +inductive hypothesis, conjugated by `exp(t•a)`), and the remaining +`exp(t•a) · exp(2t•∑l) · exp(t•a) - exp(2t•(a + ∑l))` is bounded by the two-factor base estimate +`exists_norm_exp_smul_mul_exp_two_smul_mul_exp_smul_sub_le`, itself `O(t³)`. -/ +theorem exists_norm_symmProd_exp_smul_sub_exp_two_smul_sum_le (l : List 𝔸) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t : ℝ, 0 ≤ t → t ≤ 1 → + ‖(l.map fun g => exp (t • g)).prod * (l.reverse.map fun g => exp (t • g)).prod + - exp ((2 * t) • l.sum)‖ ≤ C * t ^ 3 := by + induction l with + | nil => exact ⟨0, le_refl 0, fun t _ _ => by simp⟩ + | cons a l ih => + obtain ⟨C', hC'0, hC'⟩ := ih + obtain ⟨K, hK0, hK⟩ := exists_norm_exp_smul_mul_exp_two_smul_mul_exp_smul_sub_le a l.sum + refine ⟨Real.exp (2 * ‖a‖) * C' + K, by positivity, fun t ht0 ht1 => ?_⟩ + have hexpa : ‖exp (t • a)‖ ≤ Real.exp ‖a‖ := by + refine (norm_exp_le _).trans (Real.exp_le_exp.mpr ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht0] + exact mul_le_of_le_one_left (norm_nonneg a) ht1 + -- palindrome recursion: `symmProd (a :: l) = exp(t•a) · symmProd l · exp(t•a)` + have hpal : ((a :: l).map fun g => exp (t • g)).prod + * ((a :: l).reverse.map fun g => exp (t • g)).prod + = exp (t • a) * ((l.map fun g => exp (t • g)).prod + * (l.reverse.map fun g => exp (t • g)).prod) * exp (t • a) := by + simp only [List.map_cons, List.prod_cons, List.reverse_cons, List.map_append, + List.prod_append, List.map_nil, List.prod_nil, mul_one] + noncomm_ring + have hIH := hC' t ht0 ht1 + have hbase := hK t ht0 ht1 + rw [hpal, List.sum_cons] + set Q := (l.map fun g => exp (t • g)).prod * (l.reverse.map fun g => exp (t • g)).prod with hQ + set R := exp ((2 * t) • l.sum) with hR + -- `hIH : ‖Q - R‖ ≤ C'·t³`; conjugating by `exp(t•a)` costs a factor `Real.exp(2‖a‖)` + have hfirst : ‖exp (t • a) * (Q - R) * exp (t • a)‖ ≤ Real.exp (2 * ‖a‖) * C' * t ^ 3 := by + refine norm_mul₃_le.trans ?_ + calc ‖exp (t • a)‖ * ‖Q - R‖ * ‖exp (t • a)‖ + ≤ Real.exp ‖a‖ * (C' * t ^ 3) * Real.exp ‖a‖ := by gcongr + _ = Real.exp (2 * ‖a‖) * C' * t ^ 3 := by + rw [show (2 : ℝ) * ‖a‖ = ‖a‖ + ‖a‖ by ring, Real.exp_add]; ring + -- `hbase : ‖exp(t•a)·R·exp(t•a) - exp(2t•(a+∑l))‖ ≤ K·t³` (the two-factor base estimate) + calc ‖exp (t • a) * Q * exp (t • a) - exp ((2 * t) • (a + l.sum))‖ + = ‖exp (t • a) * (Q - R) * exp (t • a) + + (exp (t • a) * R * exp (t • a) - exp ((2 * t) • (a + l.sum)))‖ := by + congr 1; noncomm_ring + _ ≤ ‖exp (t • a) * (Q - R) * exp (t • a)‖ + + ‖exp (t • a) * R * exp (t • a) - exp ((2 * t) • (a + l.sum))‖ := norm_add_le _ _ + _ ≤ Real.exp (2 * ‖a‖) * C' * t ^ 3 + K * t ^ 3 := add_le_add hfirst hbase + _ = (Real.exp (2 * ‖a‖) * C' + K) * t ^ 3 := by ring + +end NormedSpace diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/MatrixExponential.lean b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/MatrixExponential.lean new file mode 100644 index 0000000000..5867ef92c8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/MatrixExponential.lean @@ -0,0 +1,43 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Normed.Algebra.MatrixExponential + +/-! +# Additional API for the matrix exponential + +* `Matrix.exp_smul_conj_of_conj_eq`: conjugating `P` to `Q` by a pair of mutually inverse + matrices conjugates `exp (t • P)` to `exp (t • Q)`. +-/ + +public section + +open NormedSpace + +namespace Matrix + +variable {m : Type*} [Fintype m] [DecidableEq m] + +/-- If `V` and `W` are two-sided inverses (`V * W = 1`, `W * V = 1`) and `V` conjugates `P` to `Q` +(`V * P * W = Q`), then the exponential of the scaled operator `t • P` is the exponential of the +scaled `t • Q` conjugated the other way: `exp (t • P) = W * exp (t • Q) * V`. This packages +`Matrix.exp_units_conj` with an `t • ` scalar and an equational conjugation hypothesis, so a caller +holding a conjugation identity `V * P * W = Q` (e.g. a unitary/Clifford circuit conjugating one +operator to another) obtains the exponentiated form in a single step. -/ +theorem exp_smul_conj_of_conj_eq (V W P Q : Matrix m m ℂ) (hVW : V * W = 1) (hWV : W * V = 1) + (h : V * P * W = Q) (t : ℂ) : exp (t • P) = W * exp (t • Q) * V := by + let v : (Matrix m m ℂ)ˣ := ⟨V, W, hVW, hWV⟩ + have hQ : exp (t • Q) = V * exp (t • P) * W := by + rw [← h, ← Matrix.smul_mul, ← Matrix.mul_smul] + exact Matrix.exp_units_conj v (t • P) + rw [hQ, ← Matrix.mul_assoc, ← Matrix.mul_assoc, hWV, Matrix.one_mul, Matrix.mul_assoc, hWV, + Matrix.mul_one] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/Spectrum.lean b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/Spectrum.lean new file mode 100644 index 0000000000..dc2e06c4b5 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Algebra/Spectrum.lean @@ -0,0 +1,54 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Normed.Algebra.Spectrum + +/-! +# Interval bounds for the real spectrum of a nonnegative element + +The real spectrum of a nonnegative element of a normed ℝ-algebra lies in `Icc 0 (‖a‖ * ‖1‖)`, +or in `Icc 0 ‖a‖` when `‖1‖ = 1`. +-/ + +variable {𝕜 : Type*} {A : Type*} + +@[expose] public section + +namespace spectrum + +section SpectrumCompact + +variable [NormedField 𝕜] [NormedRing A] [NormedAlgebra 𝕜 A] [CompleteSpace A] + +/-- For a nonnegative element `a` of a normed ℝ-algebra, the real spectrum of `a` lies in +`Icc 0 (‖a‖ * ‖(1 : A)‖)`. Combines `spectrum_nonneg_of_nonneg` (for the lower bound) with +`norm_le_norm_mul_of_mem` (for the upper bound). No `NormOneClass` hypothesis. -/ +theorem subset_Icc_norm_mul_of_nonneg [NormedAlgebra ℝ A] [PartialOrder A] + [NonnegSpectrumClass ℝ A] {a : A} (ha : 0 ≤ a) : + spectrum ℝ a ⊆ Set.Icc 0 (‖a‖ * ‖(1 : A)‖) := fun k hk ↦ by + have h_nonneg : 0 ≤ k := spectrum_nonneg_of_nonneg ha hk + refine ⟨h_nonneg, ?_⟩ + calc k = ‖k‖ := (Real.norm_of_nonneg h_nonneg).symm + _ ≤ ‖a‖ * ‖(1 : A)‖ := norm_le_norm_mul_of_mem hk + +/-- For a nonnegative element `a` of a normed ℝ-algebra with `‖1‖ = 1`, the real spectrum +of `a` lies in `Icc 0 ‖a‖`. Combines `spectrum_nonneg_of_nonneg` (for the lower bound) with +`norm_le_norm_of_mem` (for the upper bound). -/ +theorem subset_Icc_norm_of_nonneg [NormOneClass A] [NormedAlgebra ℝ A] [PartialOrder A] + [NonnegSpectrumClass ℝ A] {a : A} (ha : 0 ≤ a) : + spectrum ℝ a ⊆ Set.Icc 0 ‖a‖ := fun k hk ↦ by + have h_nonneg : 0 ≤ k := spectrum_nonneg_of_nonneg ha hk + refine ⟨h_nonneg, ?_⟩ + calc k = ‖k‖ := (Real.norm_of_nonneg h_nonneg).symm + _ ≤ ‖a‖ := norm_le_norm_of_mem hk + +end SpectrumCompact + +end spectrum diff --git a/LeanPool/AxQM/ToMathlib/Analysis/Normed/Ring/ProductTelescope.lean b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Ring/ProductTelescope.lean new file mode 100644 index 0000000000..ebbf027eba --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/Normed/Ring/ProductTelescope.lean @@ -0,0 +1,94 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Normed.Ring.Lemmas + +/-! +# Telescoping bound on the difference of two list products + +Let `𝔸` be a normed ring with `‖1‖ = 1`. Given two lists of elements whose entries all have norm at +most one — think of them as two sequences of gates, a *target* sequence and the *approximating* +sequence actually applied — the difference of their products is controlled by the sum of the +per-entry differences: + +`‖(∏ⱼ aⱼ) − (∏ⱼ bⱼ)‖ ≤ ∑ⱼ ‖aⱼ − bⱼ‖`. + +This is the **chaining inequality** for approximate quantum circuits: *the error of a sequence of +imperfect gates is at most the sum of the individual gate errors* (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Box 4.1, eq. (4.63); with the operator norm as the error +measure `E(U, V) = ‖U − V‖`, and unitaries satisfying `‖U‖ = 1`). It is the list-indexed companion +of the single-generator telescoping bound `norm_pow_sub_pow_le`. + +The elements need not commute, so the proof is the direct cons-induction on the identity +`a₀ · A − b₀ · B = a₀ · (A − B) + (a₀ − b₀) · B`, bounding `‖a₀‖ ≤ 1` and `‖B‖ ≤ 1`. + +## Main results + +* `norm_listProd_le_one`: the product of a list of elements each of norm `≤ 1` again has norm `≤ 1`. +* `norm_listProd_sub_listProd_le`: the chaining inequality + `‖(l.map Prod.fst).prod − (l.map Prod.snd).prod‖ ≤ (l.map fun p => ‖p.1 − p.2‖).sum` + for a list `l` of (target, approximant) pairs whose entries all have norm `≤ 1`. +-/ + +@[expose] public section + +variable {𝔸 : Type*} [NormedRing 𝔸] [NormOneClass 𝔸] + +/-- The product of a list of ring elements each of norm at most one has norm at most one. -/ +theorem norm_listProd_le_one {l : List 𝔸} (h : ∀ x ∈ l, ‖x‖ ≤ 1) : ‖l.prod‖ ≤ 1 := by + induction l with + | nil => simp + | cons a t ih => + rw [List.prod_cons] + calc ‖a * t.prod‖ ≤ ‖a‖ * ‖t.prod‖ := norm_mul_le _ _ + _ ≤ 1 * 1 := + mul_le_mul (h a (by simp)) (ih fun x hx => h x (List.mem_cons_of_mem _ hx)) + (norm_nonneg _) zero_le_one + _ = 1 := one_mul 1 + +/-- **Chaining inequality for products** (Nielsen & Chuang eq. (4.63)). For a list `l` of pairs +whose components all have norm at most one, the norm of the difference of the two componentwise +products is bounded by the sum of the componentwise differences: +`‖(∏ⱼ (l j).1) − (∏ⱼ (l j).2)‖ ≤ ∑ⱼ ‖(l j).1 − (l j).2‖`. + +Reading `(l j).1` as the target gate `Uⱼ` and `(l j).2` as the approximating gate `Vⱼ`, this says +the total error of a sequence of imperfect gates is at most the sum of the individual gate errors. +The factors need not commute. -/ +theorem norm_listProd_sub_listProd_le (l : List (𝔸 × 𝔸)) + (h₁ : ∀ p ∈ l, ‖p.1‖ ≤ 1) (h₂ : ∀ p ∈ l, ‖p.2‖ ≤ 1) : + ‖(l.map Prod.fst).prod - (l.map Prod.snd).prod‖ ≤ (l.map fun p => ‖p.1 - p.2‖).sum := by + induction l with + | nil => simp + | cons a t ih => + simp only [List.map_cons, List.prod_cons, List.sum_cons] + have hBle : ‖(t.map Prod.snd).prod‖ ≤ 1 := by + apply norm_listProd_le_one + intro x hx + rw [List.mem_map] at hx + obtain ⟨p, hp, rfl⟩ := hx + exact h₂ p (List.mem_cons_of_mem _ hp) + have ha1 : ‖a.1‖ ≤ 1 := h₁ a (by simp) + have iht := ih (fun p hp => h₁ p (List.mem_cons_of_mem _ hp)) + (fun p hp => h₂ p (List.mem_cons_of_mem _ hp)) + have hkey : a.1 * (t.map Prod.fst).prod - a.2 * (t.map Prod.snd).prod + = a.1 * ((t.map Prod.fst).prod - (t.map Prod.snd).prod) + + (a.1 - a.2) * (t.map Prod.snd).prod := by rw [mul_sub, sub_mul]; abel + calc ‖a.1 * (t.map Prod.fst).prod - a.2 * (t.map Prod.snd).prod‖ + = ‖a.1 * ((t.map Prod.fst).prod - (t.map Prod.snd).prod) + + (a.1 - a.2) * (t.map Prod.snd).prod‖ := by rw [hkey] + _ ≤ ‖a.1 * ((t.map Prod.fst).prod - (t.map Prod.snd).prod)‖ + + ‖(a.1 - a.2) * (t.map Prod.snd).prod‖ := norm_add_le _ _ + _ ≤ ‖a.1‖ * ‖(t.map Prod.fst).prod - (t.map Prod.snd).prod‖ + + ‖a.1 - a.2‖ * ‖(t.map Prod.snd).prod‖ := + add_le_add (norm_mul_le _ _) (norm_mul_le _ _) + _ ≤ 1 * (t.map fun p => ‖p.1 - p.2‖).sum + ‖a.1 - a.2‖ * 1 := + add_le_add (mul_le_mul ha1 iht (norm_nonneg _) zero_le_one) + (mul_le_mul_of_nonneg_left hBle (norm_nonneg _)) + _ = ‖a.1 - a.2‖ + (t.map fun p => ‖p.1 - p.2‖).sum := by ring diff --git a/LeanPool/AxQM/ToMathlib/Analysis/RCLike/Basic.lean b/LeanPool/AxQM/ToMathlib/Analysis/RCLike/Basic.lean new file mode 100644 index 0000000000..27700fe73d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/RCLike/Basic.lean @@ -0,0 +1,41 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.RCLike.Basic + +/-! +# Extra `RCLike` lemmas + +Extends `Mathlib.Analysis.RCLike.Basic` with a handful of small conjugation/real-part facts. +-/ + +public section + +open scoped ComplexConjugate + +namespace RCLike + +variable {K : Type*} [RCLike K] + +theorem isSelfAdjoint_ofReal (r : ℝ) : IsSelfAdjoint ((r : ℝ) : K) := by + rw [isSelfAdjoint_iff, star_def, conj_ofReal] + +/-- `push_cast`-friendly reverse of `RCLike.mul_conj`: the real-coerced squared norm +equals `z * conj z`. Saves the consumer's `push_cast; rw [← RCLike.mul_conj]` pair. -/ +theorem ofReal_norm_sq_eq_mul_conj (z : K) : ((‖z‖ ^ 2 : ℝ) : K) = z * conj z := by + rw [mul_conj]; push_cast; ring + +/-- The real part distributes over finite sums. Lifts `RCLike.reLm`'s `map_sum` through the +function-coercion. -/ +theorem re_sum {α : Type*} (s : Finset α) (f : α → K) : + re (∑ i ∈ s, f i) = ∑ i ∈ s, re (f i) := + map_sum (reLm (K := K)) f s + +end RCLike diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/BinaryEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/BinaryEntropy.lean new file mode 100644 index 0000000000..aec3041720 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/BinaryEntropy.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.BinaryEntropy +public import Mathlib.Analysis.Calculus.MeanValue + +/-! +# `qaryEntropy` unfolding lemma + +Extends `Mathlib.Analysis.SpecialFunctions.BinaryEntropy` with the defining decomposition lemma +for `Real.qaryEntropy`. + +`Real.qaryEntropy` is defined upstream as exactly `p * log (q - 1 : ℤ) + binEntropy p`, but the +definition is not `@[expose]`d, so its body is opaque across the module boundary from this file: +neither `rfl`, `unfold qaryEntropy`, nor `simp [qaryEntropy]` can unfold it here. Marking the +upstream def `@[expose]` would need a change to Mathlib itself. Instead, +`qaryEntropy_eq_log_add_binEntropy` is proved +analytically purely from the public API: both sides are continuous everywhere, agree at `p = 0` +and `p = 1` (`qaryEntropy_zero`/`_one`, `binEntropy_zero`/`_one`), and have equal derivatives away +from `0`/`1` (`hasDerivAt_qaryEntropy`, `hasDerivAt_binEntropy`), so they agree on each of the open +intervals `Iio 0`, `Ioo 0 1`, `Ioi 1` by the mean-value corollary +`IsOpen.exists_eq_add_of_deriv_eq`, with the additive shift pinned to `0` by taking the limit +towards the shared boundary point and using continuity there. +-/ + +public section + +namespace Real + +open Filter Topology Set + +/-- Helper for `qaryEntropy_eq_log_add_binEntropy`: on a connected open set `s` all of whose points +are `≠ 0` and `≠ 1`, and along whose boundary point `b` (in the sense of a nontrivial `𝓝[s] b`) the +two sides agree, `qaryEntropy q` and `p ↦ p * log (q - 1) + binEntropy p` agree throughout `s`. The +two functions have equal derivatives on `s` (both `log (q - 1) + log (1 - p) - log p`), so they +differ on `s` by a fixed additive constant (`IsOpen.exists_eq_add_of_deriv_eq`); continuity of both +sides at `b`, together with the hypothesis that they already agree at `b`, forces that constant to +be `0`. -/ +private lemma qaryEntropy_eqOn_add_binEntropy_of_boundary (q : ℕ) {s : Set ℝ} {b : ℝ} + (hs : IsOpen s) (hs' : IsPreconnected s) (hbne : (𝓝[s] b).NeBot) + (hmem : ∀ p ∈ s, p ≠ 0 ∧ p ≠ 1) + (hb : qaryEntropy q b = b * log (q - 1 : ℤ) + binEntropy b) : + s.EqOn (qaryEntropy q) (fun p => p * log (q - 1 : ℤ) + binEntropy p) := by + have := hbne + have hlogcast : log ((q : ℝ) - 1) = log (q - 1 : ℤ) := by + congr 1; push_cast; ring + have hgc : Continuous (fun p : ℝ => p * log (q - 1 : ℤ) + binEntropy p) := by fun_prop + have hf : DifferentiableOn ℝ (qaryEntropy q) s := fun p hp => + (differentiableAt_qaryEntropy (hmem p hp).1 (hmem p hp).2).differentiableWithinAt + have hg : DifferentiableOn ℝ (fun p => p * log (q - 1 : ℤ) + binEntropy p) s := fun p hp => + (((hasDerivAt_id' (x := p)).mul_const (log (q - 1 : ℤ))).add + (hasDerivAt_binEntropy (hmem p hp).1 (hmem p hp).2)).differentiableAt.differentiableWithinAt + have hderiv : s.EqOn (deriv (qaryEntropy q)) + (deriv (fun p => p * log (q - 1 : ℤ) + binEntropy p)) := by + intro p hp + have h0 := (hmem p hp).1 + have h1 := (hmem p hp).2 + have hf' : HasDerivAt (qaryEntropy q) (log (q - 1) + log (1 - p) - log p) p := + hasDerivAt_qaryEntropy h0 h1 + have hg' : HasDerivAt (fun p => p * log (q - 1 : ℤ) + binEntropy p) + (1 * log (q - 1 : ℤ) + (log (1 - p) - log p)) p := + ((hasDerivAt_id' (x := p)).mul_const (log (q - 1 : ℤ))).add + (hasDerivAt_binEntropy h0 h1) + rw [hf'.deriv, hg'.deriv, hlogcast] + ring + obtain ⟨a, ha⟩ := hs.exists_eq_add_of_deriv_eq hs' hf hg hderiv + have htf : Tendsto (qaryEntropy q) (𝓝[s] b) (𝓝 (qaryEntropy q b)) := + qaryEntropy_continuous.continuousAt.continuousWithinAt + have htg : Tendsto (fun p => (p * log (q - 1 : ℤ) + binEntropy p) + a) (𝓝[s] b) + (𝓝 ((b * log (q - 1 : ℤ) + binEntropy b) + a)) := + (hgc.continuousAt.continuousWithinAt).add tendsto_const_nhds + have heq : (qaryEntropy q) =ᶠ[𝓝[s] b] + (fun p => (p * log (q - 1 : ℤ) + binEntropy p) + a) := + Filter.eventually_of_mem self_mem_nhdsWithin ha + have hlim := tendsto_nhds_unique_of_eventuallyEq htf htg heq + have ha0 : a = 0 := by rw [hb] at hlim; linarith + intro p hp + have := ha hp + rw [ha0] at this + simpa using this + +/-- The defining decomposition of `qaryEntropy` as the `log (q - 1)` term plus the binary +entropy, mirroring `binEntropy_eq_negMulLog_add_negMulLog_one_sub`. -/ +lemma qaryEntropy_eq_log_add_binEntropy (q : ℕ) (p : ℝ) : + qaryEntropy q p = p * log (q - 1 : ℤ) + binEntropy p := by + have hb0 : qaryEntropy q 0 = 0 * log (q - 1 : ℤ) + binEntropy 0 := by simp + have hb1 : qaryEntropy q 1 = 1 * log (q - 1 : ℤ) + binEntropy 1 := by simp + rcases lt_trichotomy p 0 with hp | rfl | hp + · exact qaryEntropy_eqOn_add_binEntropy_of_boundary q isOpen_Iio + (convex_Iio 0).isPreconnected (b := 0) inferInstance + (fun p hp => ⟨hp.ne, hp.trans_le zero_le_one |>.ne⟩) hb0 (show p ∈ Iio (0 : ℝ) from hp) + · exact hb0 + rcases lt_trichotomy p 1 with hp1 | rfl | hp1 + · exact qaryEntropy_eqOn_add_binEntropy_of_boundary q isOpen_Ioo + (convex_Ioo 0 1).isPreconnected (b := 0) (left_nhdsWithin_Ioo_neBot (by norm_num)) + (fun p hp => ⟨hp.1.ne', hp.2.ne⟩) hb0 (show p ∈ Ioo (0 : ℝ) 1 from ⟨hp, hp1⟩) + · exact hb1 + · exact qaryEntropy_eqOn_add_binEntropy_of_boundary q isOpen_Ioi + (convex_Ioi 1).isPreconnected (b := 1) inferInstance + (fun p hp => ⟨(zero_lt_one.trans hp).ne', hp.ne'⟩) hb1 (show p ∈ Ioi (1 : ℝ) from hp1) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropy.lean new file mode 100644 index 0000000000..ee95e973ef --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropy.lean @@ -0,0 +1,194 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# Conditional Shannon entropy of random variables, and a strong-subadditivity counterexample + +For a finite sample space `Ω` with a discrete distribution `p : Ω → ℝ` and a *random variable* +`f : Ω → β` into a finite type, the **entropy of the law of `f`** is the Shannon entropy of the +pushed-forward distribution `b ↦ ∑_{ω : f ω = b} p ω`: + +`Real.entropyMap p f := Real.entropy (fun b ↦ ∑ ω, if f ω = b then p ω else 0)`. + +This is `H(f)` — the Shannon entropy of the random variable `f` — built directly on top of +`Real.entropy` (in nats). The **conditional entropy** of `f` given `g` is then the usual +difference of joint and marginal entropies, + +`Real.condEntropyMap p f g := Real.entropyMap p (fun ω ↦ (f ω, g ω)) - Real.entropyMap p g`, + +i.e. `H(f | g) = H(f, g) − H(g)`. Modelling the entropies through the shared sample space `Ω` +makes joint entropies of arbitrary tuples of random variables free (just tuple the variables), +which is exactly what the strong-subadditivity discussion below needs. + +## Main declarations + +* `Real.entropyMap` — `H(f)`, the Shannon entropy of the law of a random variable `f`. +* `Real.entropyMap_of_injective` — if `f` is injective then `H(f) = H(p)` (relabelling the + outcomes does not change the entropy: the fibres are singletons). +* `Real.entropyMap_const` — `H(f) = 0` for a constant random variable (a point mass has zero + entropy), given that `p` is a probability distribution. +* `Real.condEntropyMap` — `H(f | g) = H(f, g) − H(g)`. +* `Real.exists_conditional_strong_subadditivity_counterexample` and + `Real.not_forall_conditional_strong_subadditivity` — an **explicit example** and its packaging + as a refutation, showing that the classical conditional-entropy inequality + `H(D | A, B, C) + H(D | B) ≤ H(D | A, B) + H(D | B, C)` can **fail** (Nielsen & Chuang, + *Quantum Computation and Quantum Information*, Problem 11.4(2)). + +## The counterexample (N&C Problem 11.4(2)) + +Problem 11.4 contrasts two "conditional forms of strong subadditivity". The quantum form, +`S(A, B, C | D) + S(B | D) ≤ S(A, B | D) + S(B, C | D)`, holds — it is strong subadditivity with +the middle system enlarged to `B ⊗ D`. The classical statement obtained by **conditioning `D` on +the other variables**, `H(D | A, B, C) + H(D | B) ≤ H(D | A, B) + H(D | B, C)`, is a *different* +inequality (the conditioning is reversed), and it is **not** always true. + +The explicit example proving the failure: take `Ω = Fin 2` a fair bit `x` with the uniform +distribution `p ≡ 1/2`, let `A = C = D = x` (three copies of the bit) and let `B` be trivial +(constant). Then `D` is a common cause of `A` and `C`, so `A` and `C` are conditionally +independent given `D` but perfectly correlated marginally. Computing (all joint entropies are +either `log 2`, from an injective tuple, or `0`, from a constant), `H(D | A, B, C) = 0`, +`H(D | B) = log 2`, `H(D | A, B) = 0`, `H(D | B, C) = 0`, so the left-hand side is `log 2 > 0` +while the right-hand side is `0`: the inequality fails by a full bit. + +## Design + +This is pure classical information theory: it quantifies over functions `p : Ω → ℝ` and +`f : Ω → β`, building on the `Real.entropy` development. The statement of Problem 11.4 is in +[upstream `AxQM/NC/Ch11/Problem11_4.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Problem11_4.lean). + +The random-variable (`Ω → β`) formulation is chosen deliberately: it makes the joint entropies of +the many different variable-subsets appearing in the strong-subadditivity inequality available +uniformly, without a bespoke marginalisation operator over product distributions. +-/ + +@[expose] public section + +namespace Real + +variable {Ω β : Type*} [Fintype Ω] [Fintype β] [DecidableEq β] + +/-- The Shannon entropy (in nats) of the *law* of a random variable `f : Ω → β` under the +distribution `p : Ω → ℝ`: the entropy of the pushforward distribution +`b ↦ ∑_{ω : f ω = b} p ω`. Writing `H(f)` for this quantity, `entropyMap p f = H(f)`. -/ +noncomputable def entropyMap (p : Ω → ℝ) (f : Ω → β) : ℝ := + entropy (fun b => ∑ ω, if f ω = b then p ω else 0) + +/-- Unfolding lemma for `entropyMap`: the entropy of the law of `f` is the Shannon entropy of the +pushforward distribution `b ↦ ∑_{ω : f ω = b} p ω`. -/ +theorem entropyMap_eq (p : Ω → ℝ) (f : Ω → β) : + entropyMap p f = entropy (fun b => ∑ ω, if f ω = b then p ω else 0) := rfl + +/-- The entropy of the law of an **injective** random variable equals the entropy of the +underlying distribution: `H(f) = H(p)` when `f` is injective. Relabelling the outcomes by an +injection sends `p ω` to the value at `f ω` and leaves every other outcome at mass `0` +(`negMulLog 0 = 0`), so the entropy is unchanged. -/ +theorem entropyMap_of_injective {p : Ω → ℝ} {f : Ω → β} (hf : Function.Injective f) : + entropyMap p f = entropy p := by + classical + rw [entropyMap_eq, entropy_eq, entropy_eq] + have hq : ∀ ω, (∑ ω', if f ω' = f ω then p ω' else 0) = p ω := by + intro ω + rw [Finset.sum_eq_single ω] + · simp + · intro ω' _ hne; rw [ite_eq_right (fun h => hne (hf h))] + · simp + rw [← Finset.sum_subset (Finset.subset_univ (Finset.image f Finset.univ)) ?vanish] + · rw [Finset.sum_image (fun x _ y _ h => hf h)] + exact Finset.sum_congr rfl (fun ω _ => by rw [hq]) + case vanish => + intro b _ hb + have hz : (∑ ω', if f ω' = b then p ω' else 0) = 0 := by + apply Finset.sum_eq_zero + intro ω' _ + rw [ite_eq_right] + intro h + exact hb (h ▸ Finset.mem_image_of_mem f (Finset.mem_univ ω')) + rw [hz, negMulLog_zero] + +/-- The entropy of the law of a **constant** random variable is `0`: a point mass carries no +information. Requires `p` to be a probability distribution (`∑ ω, p ω = 1`), so that the +pushforward is the point mass at `c`. -/ +theorem entropyMap_const (p : Ω → ℝ) (hp : ∑ ω, p ω = 1) (c : β) : + entropyMap p (fun _ => c) = 0 := by + rw [entropyMap_eq, entropy_eq] + refine Finset.sum_eq_zero (fun b _ => ?_) + rcases eq_or_ne c b with h | h <;> simp [h, hp, negMulLog_one, negMulLog_zero] + +/-- The **conditional Shannon entropy** of a random variable `f` given a random variable `g`, +`H(f | g) = H(f, g) − H(g)`, defined through the joint law of the tuple `(f, g)` and the law of +`g`. -/ +noncomputable def condEntropyMap {γ : Type*} [Fintype γ] [DecidableEq γ] + (p : Ω → ℝ) (f : Ω → β) (g : Ω → γ) : ℝ := + entropyMap p (fun ω => (f ω, g ω)) - entropyMap p g + +/-- Unfolding lemma for `condEntropyMap`: `H(f | g) = H(f, g) − H(g)`, through the joint law of +the tuple `(f, g)` and the law of `g`. -/ +theorem condEntropyMap_eq {γ : Type*} [Fintype γ] [DecidableEq γ] + (p : Ω → ℝ) (f : Ω → β) (g : Ω → γ) : + condEntropyMap p f g = entropyMap p (fun ω => (f ω, g ω)) - entropyMap p g := rfl + +/-- **Explicit counterexample to the classical conditional form of strong subadditivity** +(Nielsen & Chuang, *Quantum Computation and Quantum Information*, Problem 11.4(2)). + +There exist a finite probability space and random variables `A, B, C, D` for which + +`H(D | A, B, C) + H(D | B) > H(D | A, B) + H(D | B, C)`, + +so the inequality `H(D | A, B, C) + H(D | B) ≤ H(D | A, B) + H(D | B, C)` — the classical +analogue obtained by conditioning `D` on the other variables — does **not** always hold. The +witness is the fair bit `Ω = Fin 2` (uniform `p ≡ 1/2`) with `A = C = D` the identity and `B` +trivial: the four conditional entropies are `0`, `log 2`, `0`, `0`, so the gap is `log 2 > 0`. -/ +theorem exists_conditional_strong_subadditivity_counterexample : + ∃ (Ω : Type) (_ : Fintype Ω) (_ : DecidableEq Ω) (p : Ω → ℝ) (A B C D : Ω → Fin 2), + (∀ ω, 0 ≤ p ω) ∧ (∑ ω, p ω = 1) ∧ + condEntropyMap p D (fun ω => (A ω, B ω, C ω)) + condEntropyMap p D B > + condEntropyMap p D (fun ω => (A ω, B ω)) + condEntropyMap p D (fun ω => (B ω, C ω)) := by + refine ⟨Fin 2, inferInstance, inferInstance, fun _ => (2 : ℝ)⁻¹, id, fun _ => 0, id, id, + fun _ => by norm_num, by rw [Fin.sum_univ_two]; norm_num, ?_⟩ + have hsum : ∑ _ω : Fin 2, (2 : ℝ)⁻¹ = 1 := by rw [Fin.sum_univ_two]; norm_num + have hEp : entropy (fun _ : Fin 2 => (2 : ℝ)⁻¹) = Real.log 2 := by + have h := entropy_uniform (ι := Fin 2) + simpa [Fintype.card_fin] using h + simp only [condEntropyMap_eq, id_eq] + rw [entropyMap_of_injective (f := fun ω : Fin 2 => (ω, ω, (0 : Fin 2), ω)) + (fun _ _ h => congrArg Prod.fst h), + entropyMap_of_injective (f := fun ω : Fin 2 => (ω, (0 : Fin 2), ω)) + (fun _ _ h => congrArg Prod.fst h), + entropyMap_of_injective (f := fun ω : Fin 2 => (ω, (0 : Fin 2))) + (fun _ _ h => congrArg Prod.fst h), + entropyMap_of_injective (f := fun ω : Fin 2 => (ω, ω, (0 : Fin 2))) + (fun _ _ h => congrArg Prod.fst h), + entropyMap_of_injective (f := fun ω : Fin 2 => ((0 : Fin 2), ω)) + (fun _ _ h => congrArg Prod.snd h), + entropyMap_const (fun _ : Fin 2 => (2 : ℝ)⁻¹) hsum (0 : Fin 2), hEp] + linarith [Real.log_pos (show (1 : ℝ) < 2 by norm_num)] + +/-- **The classical conditional form of strong subadditivity is not a theorem** (Nielsen & +Chuang, Problem 11.4(2)): it is *not* the case that for all finite random variables `A, B, C, D` +on a finite probability space, +`H(D | A, B, C) + H(D | B) ≤ H(D | A, B) + H(D | B, C)`. +This is the negation packaging of +`exists_conditional_strong_subadditivity_counterexample`; contrast with the quantum form +`S(A, B, C | D) + S(B | D) ≤ S(A, B | D) + S(B, C | D)`, which *does* hold. -/ +theorem not_forall_conditional_strong_subadditivity : + ¬ ∀ (Ω αA αB αC αD : Type) [Fintype Ω] [DecidableEq Ω] [Fintype αA] [DecidableEq αA] + [Fintype αB] [DecidableEq αB] [Fintype αC] [DecidableEq αC] [Fintype αD] [DecidableEq αD] + (p : Ω → ℝ) (A : Ω → αA) (B : Ω → αB) (C : Ω → αC) (D : Ω → αD), + (∀ ω, 0 ≤ p ω) → ∑ ω, p ω = 1 → + condEntropyMap p D (fun ω => (A ω, B ω, C ω)) + condEntropyMap p D B ≤ + condEntropyMap p D (fun ω => (A ω, B ω)) + condEntropyMap p D (fun ω => (B ω, C ω)) := by + intro h + obtain ⟨Ω, _, _, p, A, B, C, D, hnn, hsum, hgap⟩ := + exists_conditional_strong_subadditivity_counterexample + exact absurd (h Ω (Fin 2) (Fin 2) (Fin 2) (Fin 2) p A B C D hnn hsum) (not_le.mpr hgap) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropyChain.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropyChain.lean new file mode 100644 index 0000000000..d95e99738c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ConditionalEntropyChain.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy + +/-! +# Chaining rule for conditional entropies (Nielsen & Chuang, Theorem 11.4) + +Building on `Real.condEntropy` (`ToMathlib/Analysis/SpecialFunctions/JointEntropy.lean`), this file +proves the **chaining rule for conditional entropies** + +`H(X₁, …, Xₙ | Y) = ∑ᵢ H(Xᵢ | Y, X₁, …, Xᵢ₋₁)` (Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Theorem 11.4, eq. (11.27)). + +## Model + +`Real.condEntropy` is defined on a *joint distribution* `p : ι × κ → ℝ` as `H(X | Y) = H(X, Y) − +H(Y)`. To speak of the many variables `X₁, …, Xₙ, Y` and their prefix marginals we model each as a +random variable on a common finite sample space `Ω` carrying a weight `μ : Ω → ℝ`, and feed the +resulting joint laws to `Real.condEntropy`: + +* `Real.law μ X x = ∑_{ω : X ω = x} μ ω` is the **law** (push-forward distribution) of a random + variable `X : Ω → γ`; it is the probability mass function of `X` when `μ` is a probability weight. + The joint law of `(X, Y)` is `Real.law μ (fun ω ↦ (X ω, Y ω))`, whose entropy is the joint + entropy `H(X, Y)`, and `Real.condEntropy` of it is `H(X | Y)`. + +Modelling the variables this way makes every marginal appearing in the chaining rule a law of a +*sub-tuple*, so no ad-hoc coordinate projection is needed. The alphabets of `X₁, …, Xₙ` are taken to +be a common finite type `α` (without loss of generality: any finite family of finite alphabets +recodes injectively into a common one, leaving every joint/conditional entropy unchanged), and `Y` +has alphabet `β`. Entropy is measured in nats, as in `Real.entropy`. No normalisation of `μ` is +assumed — the identity is a purely algebraic telescoping that holds for any weight and specialises +to a probability weight. The `n` variables are supplied as an infinite sequence `X : ℕ → Ω → α`, of +which only the first `n` enter the identity; this keeps the prefix `X₀, …, X_{k-1}` free of index +casts. + +## Main results + +* `Real.condEntropy_law_chain` — the chaining rule (11.27) for a sequence of random variables. + +## Implementation notes + +The proof telescopes the joint entropies `G k = H(Y, X₀, …, X_{k-1})` of the prefixes. Two +ingredients support it: `Real.entropy_law_congr_equiv` (the entropy of a law is invariant under a +bijective relabeling of the value alphabet — used to reorder the variables inside a tuple) and +`Real.marginalSnd_law_prod` (the second marginal of a joint law is the law of the second variable), +which turns each `Real.condEntropy` into a difference of prefix joint entropies. The `i`-th summand +becomes `G (i+1) − G i`, and `∑ᵢ (G (i+1) − G i) = G n − G 0` is the head conditional entropy. +-/ + +@[expose] public section + +namespace Real + +variable {Ω : Type*} [Fintype Ω] + +/-! ### The law of a random variable -/ + +/-- The **law** (push-forward distribution) `law μ X x = ∑_{ω : X ω = x} μ ω` of a random variable +`X : Ω → γ` under the weight `μ : Ω → ℝ`. When `μ` is a probability weight this is the probability +mass function of `X`; the definition makes sense for any real weight. -/ +noncomputable def law {γ : Type*} [DecidableEq γ] (μ : Ω → ℝ) (X : Ω → γ) : γ → ℝ := + fun x ↦ ∑ ω, if X ω = x then μ ω else 0 + +/-- The entropy of a law is invariant under a bijective relabeling `e` of the value alphabet: +`H(law μ (e ∘ X)) = H(law μ X)`. Reordering the components of a tuple-valued random variable is such +a relabeling, so its joint entropy is unchanged. -/ +theorem entropy_law_congr_equiv {γ γ' : Type*} [Fintype γ] [DecidableEq γ] [Fintype γ'] + [DecidableEq γ'] (μ : Ω → ℝ) (e : γ ≃ γ') (X : Ω → γ) : + entropy (law μ (fun ω ↦ e (X ω))) = entropy (law μ X) := by + have hlaw : law μ (fun ω ↦ e (X ω)) = fun x' ↦ law μ X (e.symm x') := by + funext x' + simp only [law] + exact Finset.sum_congr rfl fun ω _ ↦ if_congr e.eq_symm_apply.symm rfl rfl + rw [hlaw] + simp only [entropy_eq] + exact Equiv.sum_comp e.symm fun x ↦ (law μ X x).negMulLog + +/-- The second marginal of the joint law of `(X, Y)` is the law of `Y`: +`marginalSnd (law μ (X, Y)) = law μ Y`. Hence `condEntropy (law μ (X, Y)) = H(X, Y) − H(Y)`. -/ +theorem marginalSnd_law_prod {ζ γ : Type*} [Fintype ζ] [DecidableEq ζ] [DecidableEq γ] + (μ : Ω → ℝ) (X : Ω → ζ) (Y : Ω → γ) : + marginalSnd (law μ (fun ω ↦ (X ω, Y ω))) = law μ Y := by + funext y + rw [marginalSnd_apply] + simp only [law] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun ω _ ↦ ?_ + have hfac : ∀ x, (if (X ω, Y ω) = (x, y) then μ ω else 0) + = if X ω = x then (if Y ω = y then μ ω else 0) else 0 := fun x ↦ by + by_cases hx : X ω = x <;> by_cases hy : Y ω = y <;> simp [Prod.ext_iff, hx, hy] + rw [Finset.sum_congr rfl fun x _ ↦ hfac x, Finset.sum_ite_eq] + simp + +/-! ### Reshaping equivalences -/ + +/-- Peeling the last `X`-component out of the prefix bundle: +`α × (β × (Fin i → α)) ≃ β × (Fin (i+1) → α)`, sending `(x, (y, p))` to `(y, Fin.snoc p x)`. This is +the relabeling that turns the tuple `(Xᵢ, (Y, X₀, …, Xᵢ₋₁))` into `(Y, X₀, …, Xᵢ)`. -/ +def prodSnocEquiv (α β : Type*) (i : ℕ) : α × (β × (Fin i → α)) ≃ β × (Fin (i + 1) → α) where + toFun := fun p ↦ (p.2.1, Fin.snoc (α := fun _ ↦ α) p.2.2 p.1) + invFun := fun q ↦ (q.2 (Fin.last i), (q.1, Fin.init q.2)) + left_inv := by rintro ⟨x, y, p⟩; simp [Fin.snoc_last, Fin.init_snoc] + right_inv := by rintro ⟨y, q⟩; simp [Fin.snoc_init_self] + +omit [Fintype Ω] in +/-- The first `i+1` random variables assemble, via `Fin.snoc`, from the first `i` and the `i`-th: +`Fin.snoc (fun j : Fin i ↦ X j ω) (X i ω) = fun j : Fin (i+1) ↦ X j ω`. -/ +theorem snoc_prefix {α : Type*} (X : ℕ → Ω → α) (i : ℕ) (ω : Ω) : + Fin.snoc (α := fun _ ↦ α) (fun j : Fin i ↦ X j ω) (X i ω) = fun j : Fin (i + 1) ↦ X j ω := by + funext j + refine Fin.lastCases ?_ (fun k ↦ ?_) j + · simp [Fin.snoc_last] + · simp [Fin.snoc_castSucc] + +/-- Telescoping of a difference over `Fin m`: `∑ i, (H (i+1) − H i) = H m − H 0`. The `Fin`-indexed +form of `Finset.sum_range_sub`. -/ +theorem sum_fin_sub_telescope (H : ℕ → ℝ) (m : ℕ) : + ∑ i : Fin m, (H (↑i + 1) - H ↑i) = H m - H 0 := + (Fin.sum_univ_eq_sum_range (fun i ↦ H (i + 1) - H i) m).trans (Finset.sum_range_sub H m) + +/-! ### The chaining rule (Nielsen & Chuang, Theorem 11.4) -/ + +/-- **Chaining rule for conditional entropies** (Nielsen & Chuang, Theorem 11.4, eq. (11.27)): for +random variables `X₀, X₁, …` (a sequence, of which only the first `n` enter) and `Y` on a finite +sample space `Ω` with weight `μ`, valued in common finite alphabets, +`H(X₀, …, X_{n-1} | Y) = ∑ᵢ H(Xᵢ | Y, X₀, …, Xᵢ₋₁)`. Each entropy is `Real.condEntropy` of the +appropriate joint law; the identity holds for any weight `μ` (no normalisation needed). -/ +theorem condEntropy_law_chain {α β : Type*} + [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] + (μ : Ω → ℝ) (X : ℕ → Ω → α) (Y : Ω → β) (n : ℕ) : + condEntropy (law μ fun ω ↦ (fun i : Fin n ↦ X i ω, Y ω)) + = ∑ i : Fin n, + condEntropy (law μ fun ω ↦ (X i ω, (Y ω, fun j : Fin (i : ℕ) ↦ X j ω))) := by + -- `G k` is the joint entropy `H(Y, X₀, …, X_{k-1})`. + set G : ℕ → ℝ := fun k ↦ entropy (law μ fun ω ↦ (Y ω, fun j : Fin k ↦ X j ω)) with hG + -- Each summand telescopes: `H(Xᵢ | Y, X₀, …, Xᵢ₋₁) = G (i+1) − G i`. + have hterm : ∀ i : Fin n, + condEntropy (law μ fun ω ↦ (X i ω, (Y ω, fun j : Fin (i : ℕ) ↦ X j ω))) + = G ((i : ℕ) + 1) - G (i : ℕ) := by + intro i + -- The joint entropy `H(Xᵢ, (Y, prefix)) = G (i+1)`, by reordering into `(Y, prefix ++ Xᵢ)`. + have hA : entropy (law μ fun ω ↦ (X i ω, (Y ω, fun j : Fin (i : ℕ) ↦ X j ω))) + = G ((i : ℕ) + 1) := by + simp only [hG] + have hfun : + (fun ω ↦ prodSnocEquiv α β (i : ℕ) (X i ω, (Y ω, fun j : Fin (i : ℕ) ↦ X j ω))) + = (fun ω ↦ (Y ω, fun j : Fin ((i : ℕ) + 1) ↦ X j ω)) := by + funext ω + change (Y ω, Fin.snoc (α := fun _ ↦ α) (fun j : Fin (i : ℕ) ↦ X j ω) (X i ω)) + = (Y ω, fun j : Fin ((i : ℕ) + 1) ↦ X j ω) + rw [snoc_prefix] + rw [← entropy_law_congr_equiv μ (prodSnocEquiv α β (i : ℕ)) + (fun ω ↦ (X i ω, (Y ω, fun j : Fin (i : ℕ) ↦ X j ω))), hfun] + -- The conditioning-bundle entropy `H(Y, prefix) = G i`, definitionally. + have hB : entropy (law μ fun ω ↦ (Y ω, fun j : Fin (i : ℕ) ↦ X j ω)) = G (i : ℕ) := by + simp only [hG] + rw [condEntropy_eq, + marginalSnd_law_prod μ (fun ω ↦ X i ω) (fun ω ↦ (Y ω, fun j : Fin (i : ℕ) ↦ X j ω)), + hA, hB] + -- The head conditional entropy is `G n − G 0`. + have hLHS : condEntropy (law μ fun ω ↦ (fun i : Fin n ↦ X i ω, Y ω)) = G n - G 0 := by + -- `H((X₀,…,X_{n-1}), Y) = G n`, by the product swap. + have hAn : entropy (law μ fun ω ↦ (fun i : Fin n ↦ X i ω, Y ω)) = G n := by + simp only [hG] + exact (entropy_law_congr_equiv μ (Equiv.prodComm (Fin n → α) β) + (fun ω ↦ (fun i : Fin n ↦ X i ω, Y ω))).symm + -- `H(Y) = G 0`, by collapsing the empty prefix (`Fin 0 → α` is `Unique`). + have hA0 : entropy (law μ fun ω : Ω ↦ Y ω) = G 0 := by + simp only [hG] + exact entropy_law_congr_equiv μ (Equiv.prodUnique β (Fin 0 → α)) + (fun ω ↦ (Y ω, fun j : Fin 0 ↦ X j ω)) + rw [condEntropy_eq, + marginalSnd_law_prod μ (fun ω ↦ (fun i : Fin n ↦ X i ω)) (fun ω ↦ Y ω), hAn, hA0] + rw [hLHS, Finset.sum_congr rfl fun i _ ↦ hterm i, sum_fin_sub_telescope G n] + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Deriv.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Deriv.lean new file mode 100644 index 0000000000..75aaffd739 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Deriv.lean @@ -0,0 +1,219 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.ResolventBounds +public import Mathlib.Analysis.Calculus.ParametricIntegral + +/-! +# Parametric derivative of the operator logarithm along an affine line + +For a strictly positive element `a + p₀ • b` of a C⋆-algebra (with `b` self-adjoint) the operator +logarithm along the affine line `p ↦ cfc Real.log (a + p • b)` is differentiable at `p₀`, with the +"resolvent-Bochner-integral" derivative + +`d/dp cfc Real.log (a + p • b) |_{p₀} + = ∫₀^∞ (a + p₀ • b + s • 1)⁻¹ * b * (a + p₀ • b + s • 1)⁻¹ ds`. + +This is obtained by differentiating the integral representation +`cfc Real.log a = ∫₀^∞ ((1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)) ds` +(`cfc_log_eq_integral_Ioi_resolvent`) under the integral sign: the `s`-integrand +`(1 + s)⁻¹ • 1 - Ring.inverse (a + p • b + s • 1)` has `p`-derivative +`(a + p • b + s • 1)⁻¹ * b * (a + p • b + s • 1)⁻¹` (the resolvent "sandwich" derivative +`hasDerivAt_ringInverse_add_smul`, with the leading minus sign from differentiating the +*subtracted* resolvent term), dominated uniformly in `p` near `p₀` by the integrable +`‖b‖ (m + s)⁻²`. + +## Method + +The differentiation-under-the-integral is Mathlib's +`hasDerivAt_integral_of_dominated_loc_of_deriv_le`, applied with `μ = volume.restrict (Ioi 0)`, +`F p s = (1 + s)⁻¹ • 1 - Ring.inverse (a + p • b + s • 1)` and +`F' p s = Ring.inverse (a + p • b + s • 1) * b * Ring.inverse (a + p • b + s • 1)`. Its hypotheses +are discharged from a **local uniform lower bound** on the line: for `a + p₀ • b` strictly +positive and `b` self-adjoint there are `m > 0` and a ball around `p₀` on which +`(algebraMap ℝ A) m ≤ a + p • b` +(`exists_forall_mem_ball_algebraMap_le_add_smul`, from `CFC.exists_pos_algebraMap_le_iff` and the +self-adjoint perturbation bound `IsSelfAdjoint.neg_algebraMap_norm_le_self`). On that ball: +* each `a + p • b` is strictly positive, so the base-point integrand is integrable + (`integrableOn_Ioi_inv_smul_one_sub_ringInverse`) and `cfc Real.log (a + p • b)` equals `∫ F p ·` + (`cfc_log_eq_integral_Ioi_resolvent`, used to identify the differentiated function via + `HasDerivAt.congr_of_eventuallyEq`); +* `a + p • b + s • 1` is a unit (`s > 0`), giving the pointwise `p`-derivative of `F` from + `HasDerivAt.ringInverse`; +* `‖F' p s‖ ≤ ‖b‖ (m + s)⁻²` uniformly in `p`, via the resolvent norm bound + `CStarAlgebra.norm_ringInverse_le_of_algebraMap_le` + (`(algebraMap ℝ A) (m + s) ≤ a + p • b + s • 1`) and submultiplicativity, dominated by the + integrable `integrableOn_Ioi_inv_add_sq`. + +## Main results + +* `exists_forall_mem_ball_algebraMap_le_add_smul` — a local uniform positive lower bound on an + affine line of self-adjoint perturbations of a strictly positive element. +* `eventually_isStrictlyPositive_add_smul` — the affine line `p ↦ a + p • b` stays strictly + positive on a neighbourhood of any point where it is (the strict-positivity corollary of the + previous lemma). +* `hasDerivAt_cfc_log_add_smul` — the parametric derivative of the operator logarithm along the + affine line. + +This is the differentiation step of the second-derivative proof of concavity of the von Neumann +entropy (Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 11.22): with +`b = ρ - σ` and `a + p • b = p ρ + (1 - p) σ` the mixing line, it supplies +`d/dp cfc Real.log ω_p = ∫₀^∞ (ω_p + s)⁻¹ (ρ - σ) (ω_p + s)⁻¹ ds`. +-/ + +@[expose] public section + +open MeasureTheory Set + +/-- **Local uniform lower bound along an affine line of self-adjoint perturbations.** If +`a + p₀ • b` is strictly positive and `b` is self-adjoint, then there are `m > 0` and `ε > 0` such +that `(algebraMap ℝ A) m ≤ a + p • b` for every `p` in the ball of radius `ε` about `p₀`. Since +`a + p • b = (a + p₀ • b) + (p - p₀) • b`, a positive lower bound `m₀` on `a + p₀ • b` +(`CFC.exists_pos_algebraMap_le_iff`) is preserved up to the perturbation +`(p - p₀) • b ≥ -(algebraMap ℝ A) ‖(p - p₀) • b‖` (`IsSelfAdjoint.neg_algebraMap_norm_le_self`); +for `|p - p₀|` small enough (`ε = m₀ / (2 (‖b‖ + 1))`) the perturbation is `≤ m₀ / 2` in norm, +leaving the uniform lower bound `m = m₀ / 2`. -/ +theorem exists_forall_mem_ball_algebraMap_le_add_smul + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a b : A} {p₀ : ℝ} (h : IsStrictlyPositive (a + p₀ • b)) (hb : IsSelfAdjoint b) : + ∃ m > 0, ∃ ε > 0, ∀ p ∈ Metric.ball p₀ ε, (algebraMap ℝ A) m ≤ a + p • b := by + obtain ⟨m, hm, hmle⟩ : ∃ m > 0, (algebraMap ℝ A) m ≤ a + p₀ • b := + (CFC.exists_pos_algebraMap_le_iff (a := a + p₀ • b)).mpr + (CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos.mp h).2 + refine ⟨m / 2, by positivity, m / (2 * (‖b‖ + 1)), by positivity, ?_⟩ + intro p hp + rw [Metric.mem_ball, Real.dist_eq] at hp + have hsa : IsSelfAdjoint ((p - p₀) • b) := (IsSelfAdjoint.all (p - p₀)).smul hb + have hb0 : (0 : ℝ) ≤ ‖b‖ := norm_nonneg b + have hnb : ‖(p - p₀) • b‖ ≤ m / 2 := by + rw [norm_smul, Real.norm_eq_abs] + refine (mul_le_mul_of_nonneg_right hp.le hb0).trans ?_ + rw [div_mul_eq_mul_div, div_le_iff₀ (by positivity : (0 : ℝ) < 2 * (‖b‖ + 1))] + nlinarith [hb0, hm.le] + calc (algebraMap ℝ A) (m / 2) + ≤ (algebraMap ℝ A) (m - ‖(p - p₀) • b‖) := algebraMap_mono A (by linarith) + _ = (algebraMap ℝ A) m - (algebraMap ℝ A) ‖(p - p₀) • b‖ := map_sub _ _ _ + _ ≤ (a + p₀ • b) + (p - p₀) • b := by + rw [sub_eq_add_neg]; exact add_le_add hmle hsa.neg_algebraMap_norm_le_self + _ = a + p • b := by rw [sub_smul]; abel + +/-- **Local strict positivity along an affine line.** If `a + p₀ • b` is strictly positive and `b` +is self-adjoint in a C⋆-algebra, then `a + p • b` is strictly positive for every `p` in a +neighbourhood of `p₀`. Immediate from the local uniform lower bound +`exists_forall_mem_ball_algebraMap_le_add_smul`: on the ball, +`a + p • b = (algebraMap ℝ A) m + ((a + p • b) - (algebraMap ℝ A) m)` is the sum of a strictly +positive and a non-negative element. -/ +theorem eventually_isStrictlyPositive_add_smul + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a b : A} {p₀ : ℝ} (h : IsStrictlyPositive (a + p₀ • b)) (hb : IsSelfAdjoint b) : + ∀ᶠ p in nhds p₀, IsStrictlyPositive (a + p • b) := by + obtain ⟨m, hm, ε, hε, hlb⟩ := exists_forall_mem_ball_algebraMap_le_add_smul h hb + filter_upwards [Metric.ball_mem_nhds p₀ hε] with p hp + have key : (algebraMap ℝ A) m + ((a + p • b) - (algebraMap ℝ A) m) = a + p • b := by abel + rw [← key] + exact (isStrictlyPositive_algebraMap hm).add_nonneg (sub_nonneg.mpr (hlb p hp)) + +/-- **Parametric derivative of the operator logarithm along an affine line.** For `b` self-adjoint +and `a + p₀ • b` strictly positive in a C⋆-algebra, `p ↦ cfc Real.log (a + p • b)` is differentiable +at `p₀` with derivative + +`∫₀^∞ Ring.inverse (a + p₀ • b + s • 1) * b * Ring.inverse (a + p₀ • b + s • 1) ds`. + +This differentiates the integral representation +`cfc Real.log (a + p • b) = ∫₀^∞ ((1 + s)⁻¹ • 1 - Ring.inverse (a + p • b + s • 1)) ds` +(`cfc_log_eq_integral_Ioi_resolvent`) under the integral sign: the resolvent term has derivative +`-(a + p • b + s • 1)⁻¹ b (a + p • b + s • 1)⁻¹` (`hasDerivAt_ringInverse_add_smul`, the direction +of the affine line being `b`), whose negation is the sandwich in the conclusion; the differentiation +is +justified by `hasDerivAt_integral_of_dominated_loc_of_deriv_le` with the uniform dominating function +`‖b‖ (m + s)⁻²`. See the module docstring. -/ +theorem hasDerivAt_cfc_log_add_smul + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a b : A} (hb : IsSelfAdjoint b) {p₀ : ℝ} (h : IsStrictlyPositive (a + p₀ • b)) : + HasDerivAt (fun p : ℝ => cfc Real.log (a + p • b)) + (∫ s in Set.Ioi (0 : ℝ), + Ring.inverse (a + p₀ • b + s • 1) * b * Ring.inverse (a + p₀ • b + s • 1)) p₀ := by + obtain ⟨m, hm, ε, hε, hlb⟩ := exists_forall_mem_ball_algebraMap_le_add_smul h hb + -- On the ball `a + p • b` is strictly positive, so `a + p • b + s • 1` is a unit for `s > 0`. + have hstrict : ∀ p ∈ Metric.ball p₀ ε, IsStrictlyPositive (a + p • b) := by + intro p hp + have key : (algebraMap ℝ A) m + ((a + p • b) - (algebraMap ℝ A) m) = a + p • b := by abel + rw [← key] + exact (isStrictlyPositive_algebraMap hm).add_nonneg (sub_nonneg.mpr (hlb p hp)) + have hunit : ∀ p ∈ Metric.ball p₀ ε, ∀ s : ℝ, 0 < s → IsUnit (a + p • b + s • (1 : A)) := by + intro p hp s hs + exact ((hstrict p hp).add_nonneg (smul_nonneg hs.le zero_le_one)).isUnit + -- Continuity (hence a.e.-measurability) of the resolvent, the integrand and its derivative. + have hres : ∀ p ∈ Metric.ball p₀ ε, + ContinuousOn (fun s : ℝ => Ring.inverse (a + p • b + s • (1 : A))) (Ioi (0 : ℝ)) := by + intro p hp s hs + simp only [mem_Ioi] at hs + exact (hasDerivAt_ringInverse_add_smul (hunit p hp s hs)).continuousAt.continuousWithinAt + have hFcont : ∀ p ∈ Metric.ball p₀ ε, ContinuousOn + (fun s : ℝ => (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + p • b + s • 1)) (Ioi (0 : ℝ)) := by + intro p hp + refine ContinuousOn.sub ?_ (hres p hp) + have hinv : ContinuousOn (fun s : ℝ => (1 + s)⁻¹) (Ioi 0) := by + refine ContinuousOn.inv₀ (by fun_prop) ?_ + intro s hs; simp only [mem_Ioi] at hs; positivity + exact hinv.smul continuousOn_const + have hF'cont : ∀ p ∈ Metric.ball p₀ ε, ContinuousOn + (fun s : ℝ => Ring.inverse (a + p • b + s • (1 : A)) * b + * Ring.inverse (a + p • b + s • 1)) (Ioi (0 : ℝ)) := + fun p hp => ((hres p hp).mul continuousOn_const).mul (hres p hp) + -- Differentiate the integral representation under the integral sign. + have key := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := volume.restrict (Ioi 0)) (bound := fun s => ‖b‖ * (m + s)⁻¹ ^ 2) + (F := fun p s => (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + p • b + s • 1)) + (F' := fun p s => Ring.inverse (a + p • b + s • 1) * b * Ring.inverse (a + p • b + s • 1)) + (x₀ := p₀) (s := Metric.ball p₀ ε) + (Metric.ball_mem_nhds p₀ hε) + (Filter.eventually_of_mem (Metric.ball_mem_nhds p₀ hε) + (fun p hp => (hFcont p hp).aestronglyMeasurable (μ := volume) measurableSet_Ioi)) + (integrableOn_Ioi_inv_smul_one_sub_ringInverse h) + ((hF'cont p₀ (Metric.mem_ball_self hε)).aestronglyMeasurable (μ := volume) measurableSet_Ioi) + (by + -- Uniform (in `p`) domination of the derivative integrand by `‖b‖ (m + s)⁻²`. + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun s hs => ?_) + simp only [mem_Ioi] at hs + intro p hp + have hle : (algebraMap ℝ A) (m + s) ≤ a + p • b + s • (1 : A) := by + rw [map_add, Algebra.algebraMap_eq_smul_one s] + gcongr + exact hlb p hp + have hres_norm : ‖Ring.inverse (a + p • b + s • (1 : A))‖ ≤ (m + s)⁻¹ := + CStarAlgebra.norm_ringInverse_le_of_algebraMap_le (by linarith) hle + calc ‖Ring.inverse (a + p • b + s • (1 : A)) * b * Ring.inverse (a + p • b + s • 1)‖ + ≤ ‖Ring.inverse (a + p • b + s • (1 : A)) * b‖ * ‖Ring.inverse (a + p • b + s • 1)‖ := + norm_mul_le _ _ + _ ≤ (‖Ring.inverse (a + p • b + s • (1 : A))‖ * ‖b‖) + * ‖Ring.inverse (a + p • b + s • 1)‖ := by gcongr; exact norm_mul_le _ _ + _ ≤ ((m + s)⁻¹ * ‖b‖) * (m + s)⁻¹ := by gcongr + _ = ‖b‖ * (m + s)⁻¹ ^ 2 := by ring) + ((integrableOn_Ioi_inv_add_sq hm).const_mul ‖b‖) + (by + -- The pointwise `p`-derivative of the integrand, for every `p` in the ball. + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun s hs => ?_) + simp only [mem_Ioi] at hs + intro p hp + have hu := hunit p hp s hs + have hg : HasDerivAt (fun p : ℝ => a + p • b + s • (1 : A)) b p := by + simpa using (((hasDerivAt_id p).smul_const b).const_add a).add_const (s • 1) + have hinv : Ring.inverse (a + p • b + s • (1 : A)) = ↑hu.unit⁻¹ := by + conv_lhs => rw [← hu.unit_spec] + rw [Ring.inverse_unit] + have hF := (hasDerivAt_const p ((1 + s)⁻¹ • (1 : A))).fun_sub (hg.ringInverse hu) + simp only [zero_sub, neg_neg] at hF + simpa only [hinv] using hF) + -- On the ball the differentiated function is `cfc Real.log (a + p • b)`. + refine key.2.congr_of_eventuallyEq ?_ + filter_upwards [Metric.ball_mem_nhds p₀ hε] with p hp + exact cfc_log_eq_integral_Ioi_resolvent (hstrict p hp) diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/EntropyDeriv.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/EntropyDeriv.lean new file mode 100644 index 0000000000..b8b9e01084 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/EntropyDeriv.lean @@ -0,0 +1,202 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Deriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.TraceDeriv +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.NegMulLog +public import Mathlib.Analysis.Calculus.Deriv.Mul + +/-! +# Second derivative of the entropy `re tr(cfc negMulLog ·)` along an affine line + +For operators on a finite-dimensional complex inner product space, the von Neumann entropy of a +self-adjoint operator `T` is `S(T) = re tr(cfc Real.negMulLog T)` +(`ContinuousLinearMap.vonNeumannEntropy_eq_re_trace_cfc_negMulLog`), where +`Real.negMulLog x = -(x · log x)`. This file computes the first and second derivatives of the +entropy along an affine line `p ↦ a + p • b` and shows the second derivative is non-positive +when the line stays strictly positive — the analytic heart of the alternate +(second-derivative) proof of concavity of the von Neumann entropy (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 11.22). + +Writing `Wₚ = a + p • b` (self-adjoint direction `b`) and `f(p) = re tr(cfc negMulLog Wₚ)`, on +the range of `p` where `Wₚ` is strictly positive: + +* `f'(p) = -re tr(b · log Wₚ) - re tr(b)` + (`hasDerivAt_re_trace_cfc_negMulLog_add_smul`); +* `f''(p) = -re tr(b · ∫₀^∞ (Wₚ+s)⁻¹ b (Wₚ+s)⁻¹ ds) ≤ 0` + (`deriv2_re_trace_cfc_negMulLog_add_smul_nonpos`). + +## Method + +Since `cfc negMulLog Wₚ = -(Wₚ · cfc log Wₚ)` for `Wₚ` strictly positive +(`cfc_negMulLog_eq_neg_mul_cfc_log`), we have `f(p) = -re tr(Wₚ · log Wₚ)`. Differentiating the +operator product `Wₚ · log Wₚ` by the Leibniz rule (`HasDerivAt.mul`) with + +* `d/dp Wₚ = b`, and +* `d/dp cfc log Wₚ = ∫₀^∞ (Wₚ+s)⁻¹ b (Wₚ+s)⁻¹ ds` (`hasDerivAt_cfc_log_add_smul`) + +and then applying the continuous linear functional `re ∘ tr` +(`ContinuousLinearMap.reTraceCLM`), the `Wₚ · d/dp log Wₚ` term collapses under the trace via +`tr(Wₚ · ∫₀^∞ (Wₚ+s)⁻¹ b (Wₚ+s)⁻¹ ds) = tr(b)` +(`LinearMap.trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse`), leaving +`f'(p) = -re tr(b · log Wₚ) - re tr(b)`. Differentiating once more, only the +`-re tr(b · log Wₚ)` term is non-constant, and its derivative is +`-re tr(b · ∫₀^∞ (Wₚ+s)⁻¹ b (Wₚ+s)⁻¹ ds)`, which is `≤ 0` because the trace integral is +non-negative (`LinearMap.re_trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse_nonneg`, the +Hilbert–Schmidt-square positivity). The passage from `f'` to `f''` uses that `f'` equals the +first-derivative function on the (open) strictly-positive range, via +`Filter.EventuallyEq.deriv_eq`. + +## Main results + +* `cfc_negMulLog_eq_neg_mul_cfc_log` — `cfc negMulLog W = -(W · cfc log W)` for `W` strictly + positive. +* `hasDerivAt_re_trace_cfc_negMulLog_add_smul` — the first derivative of the entropy along the + line. +* `deriv2_re_trace_cfc_negMulLog_add_smul_nonpos` — the second derivative is non-positive. +-/ + +@[expose] public section + +open MeasureTheory Set + +/-- **`negMulLog` of a strictly positive operator via `log`.** For a strictly positive element +`W` of a C⋆-algebra, `cfc Real.negMulLog W = -(W * cfc Real.log W)`. Indeed +`Real.negMulLog x = -(x · log x)`, and the continuous functional calculus is multiplicative +(`cfc_mul`) with `cfc id W = W` (`cfc_id'`); `Real.log` is continuous on the (strictly positive) +spectrum of `W`. -/ +theorem cfc_negMulLog_eq_neg_mul_cfc_log + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + {W : A} (hW : IsStrictlyPositive W) : + cfc Real.negMulLog W = -(W * cfc Real.log W) := by + have hspec : ∀ x ∈ spectrum ℝ W, 0 < x := + (CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos.mp hW).2 + have hlog : ContinuousOn Real.log (spectrum ℝ W) := + Real.continuousOn_log.mono fun x hx => ne_of_gt (hspec x hx) + rw [Real.negMulLog_eq_neg, cfc_neg (fun x => x * Real.log x) W, + cfc_mul (fun x => x) Real.log W (by fun_prop) hlog, cfc_id' ℝ W] + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [Nontrivial E] + +/-- **First derivative of the entropy along an affine line.** For `b` self-adjoint and +`a + p₀ • b` strictly positive (operators on a finite-dimensional complex inner product space), +the entropy `f(p) = re tr(cfc Real.negMulLog (a + p • b))` is differentiable at `p₀` with + +`f'(p₀) = -re tr(b · cfc Real.log (a + p₀ • b)) - re tr(b)`. + +Since `cfc negMulLog Wₚ = -(Wₚ · cfc log Wₚ)` (`cfc_negMulLog_eq_neg_mul_cfc_log`), this is the +Leibniz derivative of `Wₚ · cfc log Wₚ` under `re ∘ tr`, with the derivative of `cfc log Wₚ` +supplied by `hasDerivAt_cfc_log_add_smul` and the `Wₚ · d/dp log Wₚ` term collapsing to `tr(b)` +via `LinearMap.trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse`. See the module +docstring. -/ +theorem hasDerivAt_re_trace_cfc_negMulLog_add_smul + {a b : E →L[ℂ] E} (hb : IsSelfAdjoint b) {p₀ : ℝ} + (h : IsStrictlyPositive (a + p₀ • b)) : + HasDerivAt (fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) + (-RCLike.re ((LinearMap.trace ℂ E) ↑(b * cfc Real.log (a + p₀ • b))) + - RCLike.re ((LinearMap.trace ℂ E) ↑b)) p₀ := by + -- Derivatives of the two factors of `Wₚ · cfc log Wₚ`. + have hWderiv : HasDerivAt (fun p : ℝ => a + p • b) b p₀ := by + simpa using ((hasDerivAt_id p₀).smul_const b).const_add a + have hlogderiv : HasDerivAt (fun p : ℝ => cfc Real.log (a + p • b)) + (∫ s in Ioi (0 : ℝ), Ring.inverse (a + p₀ • b + s • 1) * b + * Ring.inverse (a + p₀ • b + s • 1)) p₀ := + hasDerivAt_cfc_log_add_smul hb h + -- Leibniz rule for the operator product, then push through `re ∘ tr`. + have hmul := hWderiv.mul hlogderiv + have hLderiv := (ContinuousLinearMap.reTraceCLM E).hasFDerivAt.comp_hasDerivAt p₀ hmul + -- The `Wₚ · d/dp log Wₚ` term collapses to `tr(b)` under the trace. + have h870 := LinearMap.trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse h b + -- Simplify the derivative value. + have hval : ContinuousLinearMap.reTraceCLM E (b * cfc Real.log (a + p₀ • b) + + (a + p₀ • b) * ∫ s in Ioi (0 : ℝ), Ring.inverse (a + p₀ • b + s • 1) * b + * Ring.inverse (a + p₀ • b + s • 1)) + = RCLike.re ((LinearMap.trace ℂ E) ↑(b * cfc Real.log (a + p₀ • b))) + + RCLike.re ((LinearMap.trace ℂ E) ↑b) := by + rw [map_add, ContinuousLinearMap.reTraceCLM_apply, ContinuousLinearMap.reTraceCLM_apply, h870] + -- On the ball the entropy equals `-(re ∘ tr)(Wₚ · cfc log Wₚ)`. + have heqf : (fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) + =ᶠ[nhds p₀] fun p : ℝ => + -ContinuousLinearMap.reTraceCLM E ((a + p • b) * cfc Real.log (a + p • b)) := by + filter_upwards [eventually_isStrictlyPositive_add_smul h hb] with p hp + rw [cfc_negMulLog_eq_neg_mul_cfc_log hp, ContinuousLinearMap.reTraceCLM_apply, + ContinuousLinearMap.toLinearMap_neg, map_neg, map_neg] + -- Assemble. + have hmain := (hLderiv.neg).congr_of_eventuallyEq heqf + rwa [hval, neg_add] at hmain + +/-- **The first derivative of the entropy, as a differentiable function.** For `b` self-adjoint +and `a + p₀ • b` strictly positive, the first-derivative function +`p ↦ -re tr(b · cfc Real.log (a + p • b)) - re tr(b)` is differentiable at `p₀` with derivative + +`-re tr(b · ∫₀^∞ (a + p₀ • b + s)⁻¹ b (a + p₀ • b + s)⁻¹ ds)`. + +Only the `-re tr(b · log Wₚ)` summand is non-constant; its derivative comes from applying +`re ∘ tr` and left multiplication by `b` to `hasDerivAt_cfc_log_add_smul`. -/ +theorem hasDerivAt_neg_re_trace_mul_cfc_log_add_smul + {a b : E →L[ℂ] E} (hb : IsSelfAdjoint b) {p₀ : ℝ} + (h : IsStrictlyPositive (a + p₀ • b)) : + HasDerivAt (fun p : ℝ => + -RCLike.re ((LinearMap.trace ℂ E) ↑(b * cfc Real.log (a + p • b))) + - RCLike.re ((LinearMap.trace ℂ E) ↑b)) + (-RCLike.re ((LinearMap.trace ℂ E) ↑(b * ∫ s in Ioi (0 : ℝ), + Ring.inverse (a + p₀ • b + s • 1) * b * Ring.inverse (a + p₀ • b + s • 1)))) p₀ := by + have hlogderiv : HasDerivAt (fun p : ℝ => cfc Real.log (a + p • b)) + (∫ s in Ioi (0 : ℝ), Ring.inverse (a + p₀ • b + s • 1) * b + * Ring.inverse (a + p₀ • b + s • 1)) p₀ := + hasDerivAt_cfc_log_add_smul hb h + have hbmul := hlogderiv.const_mul b + have hLderiv := (ContinuousLinearMap.reTraceCLM E).hasFDerivAt.comp_hasDerivAt p₀ hbmul + simp only [Function.comp_def, ContinuousLinearMap.reTraceCLM_apply] at hLderiv + exact (hLderiv.neg).sub_const (RCLike.re ((LinearMap.trace ℂ E) ↑b)) + +/-- **The second derivative of the entropy along an affine line is non-positive.** For `b` +self-adjoint and `a + p₀ • b` strictly positive (operators on a finite-dimensional complex inner +product space), + +`(deriv^[2] fun p => re tr(cfc Real.negMulLog (a + p • b))) p₀ ≤ 0`. + +This is the operator-level statement `f''(p) ≤ 0` for the entropy `f(p) = S(a + p • b)`, the +analytic heart of Nielsen & Chuang's alternate proof of concavity of the von Neumann entropy +(Exercise 11.22), in the strictly-positive ("invertible") case. On the ball where `a + p • b` +stays strictly positive, the first derivative equals the function of +`hasDerivAt_re_trace_cfc_negMulLog_add_smul` (`Filter.EventuallyEq.deriv_eq`), whose derivative +(`hasDerivAt_neg_re_trace_mul_cfc_log_add_smul`) is +`-re tr(b · ∫₀^∞ (a+p₀•b+s)⁻¹ b (a+p₀•b+s)⁻¹ ds)`; this is `≤ 0` since the trace integral is +non-negative (`LinearMap.re_trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse_nonneg`, the +Hilbert–Schmidt-square positivity). -/ +theorem deriv2_re_trace_cfc_negMulLog_add_smul_nonpos + {a b : E →L[ℂ] E} (hb : IsSelfAdjoint b) {p₀ : ℝ} + (h : IsStrictlyPositive (a + p₀ • b)) : + (deriv^[2] fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) p₀ ≤ 0 := by + -- On a neighbourhood of `p₀` the first derivative equals the explicit first-derivative function. + have hderivEq : (deriv fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) + =ᶠ[nhds p₀] fun p : ℝ => + -RCLike.re ((LinearMap.trace ℂ E) ↑(b * cfc Real.log (a + p • b))) + - RCLike.re ((LinearMap.trace ℂ E) ↑b) := by + filter_upwards [eventually_isStrictlyPositive_add_smul h hb] with p hp + exact (hasDerivAt_re_trace_cfc_negMulLog_add_smul hb hp).deriv + -- `deriv^[2] f p₀ = deriv (deriv f) p₀ = deriv (first-derivative function) p₀`. + have hval : (deriv^[2] fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) p₀ + = -RCLike.re ((LinearMap.trace ℂ E) ↑(b * ∫ s in Ioi (0 : ℝ), + Ring.inverse (a + p₀ • b + s • 1) * b * Ring.inverse (a + p₀ • b + s • 1))) := by + rw [show (deriv^[2] fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) p₀ + = deriv (deriv fun p : ℝ => + RCLike.re ((LinearMap.trace ℂ E) ↑(cfc Real.negMulLog (a + p • b)))) p₀ from rfl, + hderivEq.deriv_eq, (hasDerivAt_neg_re_trace_mul_cfc_log_add_smul hb h).deriv] + rw [hval, neg_nonpos] + exact LinearMap.re_trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse_nonneg h hb diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/IntegralRepresentation.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/IntegralRepresentation.lean new file mode 100644 index 0000000000..316b828e1d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/IntegralRepresentation.lean @@ -0,0 +1,159 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Basic +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Integral +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.Spectrum + +/-! +# Integral representation of the continuous-functional-calculus logarithm + +For a strictly positive element `a` of a C⋆-algebra (nonnegative and invertible) the operator +logarithm `cfc Real.log a` has the improper-integral representation + +`cfc Real.log a = ∫₀^∞ ((1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)) ds`, + +the operator lift of the scalar Frullani-type identity +`log x = ∫₀^∞ ((1 + s)⁻¹ - (x + s)⁻¹) ds` (`Real.log_eq_integral_Ioi_inv_add_sub_inv_add`). The +integrand `(1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)` is exactly `cfc` applied to the scalar +integrand `x ↦ (1 + s)⁻¹ - (x + s)⁻¹` (the reference term `(1 + s)⁻¹ • 1 = cfc (fun _ ↦ (1+s)⁻¹) a`, +the resolvent term `Ring.inverse (a + s • 1) = cfc (fun x ↦ (x + s)⁻¹) a`), so the identity is the +statement that the continuous functional calculus commutes with the Bochner integral over `s`. + +## Method + +The commutation is Mathlib's `cfc_setIntegral`, applied to `f s x = (1 + s)⁻¹ - (x + s)⁻¹` on +`Ioi 0 ×ˢ spectrum ℝ a`. Its hypotheses are discharged from strict positivity: +* the spectrum is a compact subset of `Ioi 0`, hence bounded in `Icc m ‖a‖` with `0 < m` its + (attained) minimum — used both for continuity of the integrand and for the dominating bound; +* `‖(1 + s)⁻¹ - (x + s)⁻¹‖` is dominated, uniformly over `x ∈ spectrum ℝ a`, by + `|(1 + s)⁻¹ - (m + s)⁻¹| + |(1 + s)⁻¹ - (‖a‖ + s)⁻¹|`, since the integrand is monotone in `x`; + the dominating function is integrable on `Ioi 0` by two applications of the scalar + `Real.integrableOn_Ioi_inv_add_sub_inv_add`. +On the resulting `cfc (fun x ↦ ∫₀^∞ ((1+s)⁻¹ - (x+s)⁻¹) ds) a` the inner integral equals +`Real.log x` for every spectral point `x` (all positive), so `cfc_congr` collapses it to +`cfc Real.log a`; each integrand `cfc (fun x ↦ (1+s)⁻¹ - (x+s)⁻¹) a` is unfolded to the resolvent +form with `cfc_sub`, `cfc_const`, `cfc_comp`, and `cfc_ringInverse_id` (`a + s • 1` a unit by +`isStrictlyPositive_add_smul_one`). + +## Main results + +* `cfc_log_eq_integral_Ioi_resolvent` — the integral representation itself. + +This is an analysis foundation for the second-derivative proof of concavity of the von Neumann +entropy (Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 11.22): the +representation, differentiated along a mixing line `s ↦ (ω_p + s)⁻¹` via the resolvent derivative +`hasDerivAt_ringInverse_add_smul`, yields the parametric derivative of the operator logarithm. +-/ + +@[expose] public section + +open MeasureTheory Set + +/-- **Integral representation of the operator logarithm.** For a strictly positive element `a` of +a C⋆-algebra (`0 ≤ a` and `a` invertible), + +`cfc Real.log a = ∫₀^∞ ((1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)) ds`. + +This is the operator lift of the scalar identity +`log x = ∫₀^∞ ((1 + s)⁻¹ - (x + s)⁻¹) ds` (`Real.log_eq_integral_Ioi_inv_add_sub_inv_add`): the +integrand is `cfc` applied to `x ↦ (1 + s)⁻¹ - (x + s)⁻¹`, so the identity states that the +continuous functional calculus commutes with the Bochner integral over `s` (`cfc_setIntegral`). See +the module docstring for the discharge of the domination/continuity hypotheses. -/ +theorem cfc_log_eq_integral_Ioi_resolvent + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a : A} (ha : IsStrictlyPositive a) : + cfc Real.log a + = ∫ s in Set.Ioi (0 : ℝ), ((1 + s)⁻¹ • (1 : A) - Ring.inverse (a + s • 1)) := by + have hsa : IsSelfAdjoint a := ha.1.isSelfAdjoint + -- The spectrum is a compact subset of `Icc m ‖a‖` with `0 < m` its attained minimum. + have hsub : spectrum ℝ a ⊆ Set.Icc 0 ‖a‖ := spectrum.subset_Icc_norm_of_nonneg ha.1 + have h0 : (0 : ℝ) ∉ spectrum ℝ a := (spectrum.zero_notMem_iff ℝ).mpr ha.isUnit + have hcompact : IsCompact (spectrum ℝ a) := spectrum.isCompact a + have hne : (spectrum ℝ a).Nonempty := ContinuousFunctionalCalculus.spectrum_nonempty a hsa + obtain ⟨m, hm_mem, hm_min⟩ := hcompact.exists_isMinOn hne continuousOn_id + have hm_pos : 0 < m := by + rcases lt_or_eq_of_le (hsub hm_mem).1 with h | h + · exact h + · exact absurd (h ▸ hm_mem) h0 + have hM_pos : 0 < ‖a‖ := lt_of_lt_of_le hm_pos (hsub hm_mem).2 + have hpos : ∀ x ∈ spectrum ℝ a, (0 : ℝ) < x := fun x hx => lt_of_lt_of_le hm_pos (hm_min hx) + have hsp : ∀ x ∈ spectrum ℝ a, (0 : ℝ) ≤ x := fun x hx => (hpos x hx).le + -- The dominating function `bound` and its integrability on `Ioi 0`. + set bound : ℝ → ℝ := fun s => |(1 + s)⁻¹ - (m + s)⁻¹| + |(1 + s)⁻¹ - (‖a‖ + s)⁻¹| with hbound_def + have hbound_int : IntegrableOn bound (Set.Ioi 0) := + ((Real.integrableOn_Ioi_inv_add_sub_inv_add hm_pos).abs).add + ((Real.integrableOn_Ioi_inv_add_sub_inv_add hM_pos).abs) + -- Uniform (in the spectral point) domination: the integrand is monotone in `z`, so its value + -- lies between the endpoints `z = m` and `z = ‖a‖`. + have hdom : ∀ s : ℝ, 0 < s → ∀ z : ℝ, m ≤ z → z ≤ ‖a‖ → + |(1 + s)⁻¹ - (z + s)⁻¹| ≤ bound s := by + intro s hs z hmz hzM + have hms : 0 < m + s := by linarith + have hzs : 0 < z + s := by linarith + have hMs : 0 < ‖a‖ + s := by linarith + have h1 : (z + s)⁻¹ ≤ (m + s)⁻¹ := (inv_le_inv₀ hzs hms).mpr (by linarith) + have h2 : (‖a‖ + s)⁻¹ ≤ (z + s)⁻¹ := (inv_le_inv₀ hMs hzs).mpr (by linarith) + set c := (1 + s)⁻¹ + set P := c - (m + s)⁻¹ with hP + set Q := c - (‖a‖ + s)⁻¹ with hQ + have hlo : P ≤ c - (z + s)⁻¹ := by rw [hP]; linarith + have hhi : c - (z + s)⁻¹ ≤ Q := by rw [hQ]; linarith + rw [show |(1 + s)⁻¹ - (z + s)⁻¹| = |c - (z + s)⁻¹| from rfl, abs_le] + exact ⟨by linarith [neg_abs_le P, abs_nonneg Q], by linarith [le_abs_self Q, abs_nonneg P]⟩ + -- Joint continuity of the scalar integrand on `Ioi 0 ×ˢ spectrum ℝ a`. + have hcont : ContinuousOn (Function.uncurry (fun (s r : ℝ) => (1 + s)⁻¹ - (r + s)⁻¹)) + (Set.Ioi 0 ×ˢ spectrum ℝ a) := by + apply ContinuousOn.sub + · apply ContinuousOn.inv₀ (by fun_prop) + rintro ⟨s, r⟩ ⟨hs, hr⟩; simp only [Set.mem_Ioi] at hs; positivity + · apply ContinuousOn.inv₀ (by fun_prop) + rintro ⟨s, r⟩ ⟨hs, hr⟩; simp only [Set.mem_Ioi] at hs + have := hsp r hr; positivity + -- The a.e. domination hypothesis for `cfc_setIntegral`. + have hbnd : ∀ᵐ (s : ℝ) ∂(volume.restrict (Set.Ioi 0)), ∀ z ∈ spectrum ℝ a, + ‖(fun (s r : ℝ) => (1 + s)⁻¹ - (r + s)⁻¹) s z‖ ≤ bound s := by + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ ?_) + intro s hs z hz + simp only [Set.mem_Ioi] at hs + rw [Real.norm_eq_abs] + exact hdom s hs z (hm_min hz) (hsub hz).2 + -- The continuous functional calculus commutes with the integral over `s`. + have key := cfc_setIntegral (𝕜 := ℝ) (μ := volume) measurableSet_Ioi + (fun (s r : ℝ) => (1 + s)⁻¹ - (r + s)⁻¹) bound a hcont hbnd + hbound_int.hasFiniteIntegral hsa + -- The left-hand cfc is `cfc Real.log a`: on the (positive) spectrum the inner integral is `log`. + have hLHS : cfc (fun r => ∫ s in Set.Ioi (0 : ℝ), ((1 + s)⁻¹ - (r + s)⁻¹)) a + = cfc Real.log a := by + apply cfc_congr + intro r hr + exact (Real.log_eq_integral_Ioi_inv_add_sub_inv_add (hpos r hr)).symm + rw [← hLHS, key] + -- Each cfc integrand is the resolvent form. + refine setIntegral_congr_fun measurableSet_Ioi (fun s hs => ?_) + simp only [Set.mem_Ioi] at hs + have hunit : IsUnit (a + s • 1) := (isStrictlyPositive_add_smul_one ha.1 hs).isUnit + have hc2 : ContinuousOn (fun r : ℝ => (r + s)⁻¹) (spectrum ℝ a) := by + apply ContinuousOn.inv₀ (by fun_prop) + intro r hr; have := hsp r hr; positivity + rw [cfc_sub _ _ a continuousOn_const hc2] + congr 1 + · rw [cfc_const _ _ (p := IsSelfAdjoint) hsa, Algebra.algebraMap_eq_smul_one] + · have hshift : cfc (fun r : ℝ => r + s) a = a + s • 1 := by + rw [cfc_add a (fun x => x) (fun _ => s) continuousOn_id continuousOn_const, + cfc_id' ℝ a, cfc_const _ _ (p := IsSelfAdjoint) hsa, Algebra.algebraMap_eq_smul_one] + have himg : ContinuousOn (fun y : ℝ => y⁻¹) ((fun r : ℝ => r + s) '' spectrum ℝ a) := by + apply ContinuousOn.inv₀ (by fun_prop) + rintro _ ⟨r, hr, rfl⟩; have := hsp r hr; positivity + rw [show (fun r : ℝ => (r + s)⁻¹) = (fun y : ℝ => y⁻¹) ∘ (fun r : ℝ => r + s) from rfl, + cfc_comp (fun y => y⁻¹) (fun r => r + s) a hsa himg (by fun_prop), hshift, + cfc_ringInverse_id (a + s • 1) hunit] diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Order.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Order.lean new file mode 100644 index 0000000000..c7ffcb1a54 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Order.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Order +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Continuity +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.RpowTendsto +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Order +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.FunctionTopology +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order + +/-! +# Operator convexity of `x ↦ x log x` + +`Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Order` now contains +`CFC.concaveOn_log` (the logarithm is operator concave) itself. This file adds the remaining +`CFC.convexOn_mul_log` (`x ↦ x * log x` is operator convex), obtained as a pointwise limit of +`cfc`-level identities as in the existing operator-monotonicity proof. +-/ + +public section + +open Filter Topology + +section +variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + +open Classical Real in +/-- The cfc-arithmetic identity underlying the operator analogue of +`log x = lim_{p → 0} p⁻¹ * (x^p − 1)`: for a strictly positive operator `a` and `p : ℝ`, +`cfc (fun x ↦ p⁻¹ * (x^p − 1)) a = p⁻¹ • (a^p − 1)`. -/ +lemma CFC.cfc_p_inv_rpow_sub_one_eq (p : ℝ) {a : A} + (ha : IsStrictlyPositive a := by cfc_tac) : + cfc (fun x : ℝ => p⁻¹ * (x ^ p - 1)) a = p⁻¹ • (a ^ p - 1) := by + have hne : ∀ x ∈ spectrum ℝ a, x ≠ 0 := fun x hx => (ha.spectrum_pos hx).ne' + have hrpow : ContinuousOn (fun x : ℝ => x ^ p) (spectrum ℝ a) := + ContinuousOn.rpow_const continuousOn_id (fun x hx => Or.inl (hne x hx)) + have hsub : ContinuousOn (fun x : ℝ => x ^ p - 1) (spectrum ℝ a) := hrpow.sub continuousOn_const + simp only [← smul_eq_mul] + rw [cfc_smul _ (hf := hsub), cfc_sub _ _ (hf := hrpow), cfc_const_one .., rpow_eq_cfc_real ..] + +open Filter in +lemma CFC.tendsto_cfc_rpow_succ_sub_self_mul_log {a : A} + (ha : IsStrictlyPositive a := by cfc_tac) : + Tendsto (fun p : ℝ => cfc (fun x => p⁻¹ * (x ^ (p + 1) - x)) a) (𝓝[>] 0) + (𝓝 (cfc (fun x : ℝ => x * Real.log x) a)) := + tendsto_cfc_fun + ((tendstoLocallyUniformlyOn_iff_forall_isCompact isOpen_Ioi).mp + Real.tendstoLocallyUniformlyOn_rpow_succ_sub_self_mul_log + (spectrum ℝ a) (by grind) (by grind)) + (.of_forall fun p ↦ by + have hne : ∀ x ∈ spectrum ℝ a, x ≠ 0 := fun x hx => (ha.spectrum_pos hx).ne' + have hrpow : ContinuousOn (fun x : ℝ => x ^ (p + 1)) (spectrum ℝ a) := + ContinuousOn.rpow_const continuousOn_id (fun x hx => Or.inl (hne x hx)) + exact (hrpow.sub continuousOn_id).const_mul p⁻¹) + +open Classical Real in +/-- The cfc-arithmetic identity underlying the operator analogue of +`x * log x = lim_{p ↘ 0} p⁻¹ * (x^(p+1) − x)`: for a strictly positive operator `a` and `p : ℝ`, +`cfc (fun x ↦ p⁻¹ * (x^(p+1) − x)) a = p⁻¹ • (a^(p+1) − a)`. -/ +lemma CFC.cfc_p_inv_rpow_succ_sub_self_eq (p : ℝ) {a : A} + (ha : IsStrictlyPositive a := by cfc_tac) : + cfc (fun x : ℝ => p⁻¹ * (x ^ (p + 1) - x)) a = p⁻¹ • (a ^ (p + 1) - a) := by + have hne : ∀ x ∈ spectrum ℝ a, x ≠ 0 := fun x hx => (ha.spectrum_pos hx).ne' + have hrpow : ContinuousOn (fun x : ℝ => x ^ (p + 1)) (spectrum ℝ a) := + ContinuousOn.rpow_const continuousOn_id (fun x hx => Or.inl (hne x hx)) + have hsub : ContinuousOn (fun x : ℝ => x ^ (p + 1) - x) (spectrum ℝ a) := + hrpow.sub continuousOn_id + simp only [← smul_eq_mul] + rw [cfc_smul _ (hf := hsub), cfc_sub _ _ (hf := hrpow), cfc_id' ℝ .., rpow_eq_cfc_real ..] + +open Classical Real in +/-- `x ↦ x * log x` is operator convex. + +`x * log x = lim_{p ↘ 0} p⁻¹ * (x^(p+1) − x)` locally uniformly on `Ioi 0`, so the same identity +holds at the cfc level (`tendsto_cfc_rpow_succ_sub_self_mul_log`); each `x^(p+1) − x` is operator +convex on the strictly positive elements (`CFC.convexOn_rpow` on `[1, 2]` minus the affine +`id`); and `ConvexOn.of_tendsto_pointwise_on` passes convexity through the pointwise limit. -/ +lemma CFC.convexOn_mul_log : + ConvexOn ℝ {a : A | IsStrictlyPositive a} (cfc (fun x : ℝ ↦ x * Real.log x)) := by + refine .of_tendsto_pointwise_on (l := (𝓝[>] 0)) convex_isStrictlyPositive ?_ + fun _ ha ↦ tendsto_cfc_rpow_succ_sub_self_mul_log ha + filter_upwards [(nhdsGT_basis 0).mem_of_mem (zero_lt_one (α := ℝ))] with p ⟨hp, hp'⟩ + refine ConvexOn.congr ?_ fun _ ha ↦ (cfc_p_inv_rpow_succ_sub_self_eq p ha).symm + exact (((CFC.convexOn_rpow ⟨by linarith, by linarith⟩).subset + (s := {a : A | IsStrictlyPositive a}) (fun _ ha ↦ IsStrictlyPositive.nonneg ha) + convex_isStrictlyPositive).sub (concaveOn_id convex_isStrictlyPositive)).smul (by positivity) + +end diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventBounds.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventBounds.lean new file mode 100644 index 0000000000..ee3b0d75f1 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventBounds.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.Calculus.Deriv.RingInverse +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic +public import Mathlib.MeasureTheory.Integral.IntegralEqImproper + +/-! +# Resolvent norm bound and integrability of the operator-logarithm integrand + +This file collects two analytic estimates for the resolvent `Ring.inverse (a + s • 1)` of a strictly +positive element `a` of a C⋆-algebra, needed to differentiate the operator-logarithm integral +representation `cfc Real.log a = ∫₀^∞ ((1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)) ds` +(`cfc_log_eq_integral_Ioi_resolvent`) along a parameter, and hence for the second-derivative +proof of concavity of the von Neumann entropy (Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Exercise 11.22). + +* `CStarAlgebra.norm_ringInverse_le_of_algebraMap_le` — the **resolvent norm bound**: if + `(algebraMap ℝ A) m ≤ a` with `0 < m` (a positive lower bound on the spectrum), then + `‖Ring.inverse a‖ ≤ m⁻¹`. Applied to `a + s • 1` (whose lower bound is `m + s`) it controls the + resolvent uniformly in `s`, and it is the elementary bound underlying the domination hypothesis of + the differentiation-under-the-integral step. +* `integrableOn_Ioi_inv_smul_one_sub_ringInverse` — **integrability of the operator-log integrand**: + for `a` strictly positive the map `s ↦ (1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)` is integrable on + `(0, ∞)`. Although neither term is individually integrable, the difference telescopes: writing + `u = a + s • 1`, one has the algebraic identity + `(1 + s)⁻¹ • 1 - u⁻¹ = (1 + s)⁻¹ • (u⁻¹ * (a - 1))`, so the norm is bounded by + `‖a - 1‖ · (1 + s)⁻¹ (m + s)⁻¹ ≤ ‖a - 1‖ · (min 1 m + s)⁻²`, which decays like `s⁻²` and is + integrable. This is exactly the hypothesis `Integrable (F p₀)` that the parametric-integral + derivative lemma requires of the base-point integrand. + +The scalar helper `integrableOn_Ioi_inv_add_sq` (`s ↦ (c + s)⁻²` is integrable on `(0, ∞)` for +`0 < c`) supplies the dominating function. + +## Main results + +* `integrableOn_Ioi_inv_add_sq` +* `CStarAlgebra.norm_ringInverse_le_of_algebraMap_le` +* `integrableOn_Ioi_inv_smul_one_sub_ringInverse` +-/ + +@[expose] public section + +open MeasureTheory Set + +/-- The function `s ↦ (c + s)⁻²` is integrable on `(0, ∞)` for `0 < c`: it is the derivative of the +bounded, monotone antiderivative `s ↦ -(c + s)⁻¹` (increasing from `-c⁻¹` to `0`). -/ +theorem integrableOn_Ioi_inv_add_sq {c : ℝ} (hc : 0 < c) : + IntegrableOn (fun s => (c + s)⁻¹ ^ 2) (Ioi 0) := by + have hcont : ContinuousWithinAt (fun s => -(c + s)⁻¹) (Ici 0) 0 := + (ContinuousWithinAt.inv₀ (by fun_prop) (by simpa using hc.ne')).neg + have hderiv : ∀ s ∈ Ioi (0 : ℝ), HasDerivAt (fun t => -(c + t)⁻¹) ((c + s)⁻¹ ^ 2) s := by + intro s hs + have hs0 : (0 : ℝ) < s := hs + have hne : c + s ≠ 0 := by positivity + have e : HasDerivAt (fun t : ℝ => c + t) 1 s := by simpa using (hasDerivAt_id s).const_add c + convert (e.inv hne).neg using 1 + rw [neg_div, neg_neg, one_div, inv_pow] + have htend : Filter.Tendsto (fun s => -(c + s)⁻¹) Filter.atTop (nhds 0) := by + rw [show (0 : ℝ) = -0 by ring] + exact (Filter.Tendsto.inv_tendsto_atTop + (Filter.tendsto_atTop_add_const_left _ c Filter.tendsto_id)).neg + exact integrableOn_Ioi_deriv_of_nonneg hcont hderiv (fun s _ => sq_nonneg _) htend + +namespace CStarAlgebra + +variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + +/-- **Resolvent norm bound.** If `a` dominates the scalar `(algebraMap ℝ A) m` with `0 < m` (so `m` +is a positive lower bound on the spectrum of `a`), then `‖Ring.inverse a‖ ≤ m⁻¹`. Proof: +`Ring.inverse` is order-reversing on strictly positive elements +(`CStarAlgebra.ringInverse_le_ringInverse`), so `Ring.inverse a ≤ Ring.inverse (algebraMap ℝ A m) += m⁻¹ • 1`, and the C⋆-norm is monotone on nonnegative elements. -/ +theorem norm_ringInverse_le_of_algebraMap_le {a : A} {m : ℝ} (hm : 0 < m) + (h : (algebraMap ℝ A) m ≤ a) : ‖Ring.inverse a‖ ≤ m⁻¹ := by + have hmsp : IsStrictlyPositive ((algebraMap ℝ A) m) := by + rw [Algebra.algebraMap_eq_smul_one] + simpa using isStrictlyPositive_add_smul_one (a := (0 : A)) le_rfl hm + have hasp : IsStrictlyPositive a := by + have key : (algebraMap ℝ A) m + (a - (algebraMap ℝ A) m) = a := by abel + rw [← key]; exact hmsp.add_nonneg (sub_nonneg.mpr h) + have hle : Ring.inverse a ≤ Ring.inverse ((algebraMap ℝ A) m) := + CStarAlgebra.ringInverse_le_ringInverse h + have hu : IsUnit ((algebraMap ℝ A) m) := hmsp.isUnit + have hval : Ring.inverse ((algebraMap ℝ A) m) = m⁻¹ • (1 : A) := by + have h1 : ((algebraMap ℝ A) m) * (m⁻¹ • (1 : A)) = 1 := by + rw [Algebra.algebraMap_eq_smul_one, smul_mul_smul_comm, one_mul, mul_inv_cancel₀ hm.ne', + one_smul] + calc Ring.inverse ((algebraMap ℝ A) m) + = Ring.inverse ((algebraMap ℝ A) m) * (((algebraMap ℝ A) m) * (m⁻¹ • (1 : A))) := by + rw [h1, mul_one] + _ = (Ring.inverse ((algebraMap ℝ A) m) * ((algebraMap ℝ A) m)) * (m⁻¹ • (1 : A)) := by + rw [mul_assoc] + _ = m⁻¹ • (1 : A) := by rw [Ring.inverse_mul_cancel _ hu, one_mul] + have h0 : (0 : A) ≤ Ring.inverse a := hasp.ringInverse.nonneg + calc ‖Ring.inverse a‖ ≤ ‖Ring.inverse ((algebraMap ℝ A) m)‖ := + CStarAlgebra.norm_le_norm_of_le_of_nonneg (a := Ring.inverse a) hle h0 + _ = m⁻¹ := by + rw [hval, norm_smul, norm_one, mul_one, Real.norm_eq_abs, abs_of_pos (by positivity)] + +end CStarAlgebra + +/-- **Integrability of the operator-logarithm integrand.** For a strictly positive element `a` of a +C⋆-algebra the map `s ↦ (1 + s)⁻¹ • 1 - Ring.inverse (a + s • 1)` is integrable on `(0, ∞)`. This is +the integrand of the integral representation `cfc_log_eq_integral_Ioi_resolvent`, and is the +`Integrable`-of-the-base-point hypothesis needed to differentiate that representation under the +integral sign. The two terms are individually non-integrable, but with `u = a + s • 1` the +telescoping identity `(1 + s)⁻¹ • 1 - u⁻¹ = (1 + s)⁻¹ • (u⁻¹ * (a - 1))` and the resolvent norm +bound `‖u⁻¹‖ ≤ (m + s)⁻¹` (where `(algebraMap ℝ A) m ≤ a`) give +`‖·‖ ≤ ‖a - 1‖ · (1 + s)⁻¹ (m + s)⁻¹ ≤ ‖a - 1‖ · (min 1 m + s)⁻²`, an integrable dominating +function. -/ +theorem integrableOn_Ioi_inv_smul_one_sub_ringInverse + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] {a : A} + (ha : IsStrictlyPositive a) : + IntegrableOn (fun s : ℝ => (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + s • 1)) (Ioi 0) := by + -- A positive lower bound `m` on the spectrum of `a`. + obtain ⟨m, hm, hma⟩ : ∃ m, 0 < m ∧ (algebraMap ℝ A) m ≤ a := by + obtain ⟨m, hm0, hle⟩ := (CFC.exists_pos_algebraMap_le_iff (a := a)).mpr + (CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos.mp ha).2 + exact ⟨m, hm0, hle⟩ + have hcpos : 0 < min 1 m := lt_min one_pos hm + -- The integrand is continuous on `(0, ∞)`, hence a.e. strongly measurable. + have hcont : ContinuousOn + (fun s : ℝ => (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + s • 1)) (Ioi 0) := by + refine ContinuousOn.sub ?_ ?_ + · have hinv : ContinuousOn (fun s : ℝ => (1 + s)⁻¹) (Ioi 0) := by + refine ContinuousOn.inv₀ (by fun_prop) ?_ + intro s hs; simp only [mem_Ioi] at hs; positivity + exact hinv.smul continuousOn_const + · intro s hs + simp only [mem_Ioi] at hs + have hunit : IsUnit (a + s • (1 : A)) := + (ha.add_nonneg (smul_nonneg hs.le zero_le_one)).isUnit + exact (hasDerivAt_ringInverse_add_smul hunit).continuousAt.continuousWithinAt + have hmeas : AEStronglyMeasurable + (fun s : ℝ => (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + s • 1)) (volume.restrict (Ioi 0)) := + hcont.aestronglyMeasurable measurableSet_Ioi + -- The dominating function `‖a - 1‖ · (min 1 m + s)⁻²`. + have hbound_int : IntegrableOn (fun s : ℝ => ‖a - 1‖ * (min 1 m + s)⁻¹ ^ 2) (Ioi 0) := + (integrableOn_Ioi_inv_add_sq hcpos).const_mul ‖a - 1‖ + refine hbound_int.mono' hmeas ?_ + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ ?_) + intro s hs + simp only [mem_Ioi] at hs + -- Pointwise domination via the telescoping identity and the resolvent norm bound. + have hunit : IsUnit (a + s • (1 : A)) := (ha.add_nonneg (smul_nonneg hs.le zero_le_one)).isUnit + have hiu : Ring.inverse (a + s • (1 : A)) * (a + s • (1 : A)) = 1 := + Ring.inverse_mul_cancel _ hunit + have hs1 : (1 : ℝ) + s ≠ 0 := by positivity + have hia : Ring.inverse (a + s • (1 : A)) * a = 1 - s • Ring.inverse (a + s • (1 : A)) := by + have expand : a = (a + s • (1 : A)) - s • (1 : A) := by abel + calc Ring.inverse (a + s • (1 : A)) * a + = Ring.inverse (a + s • (1 : A)) * ((a + s • (1 : A)) - s • (1 : A)) := by rw [← expand] + _ = Ring.inverse (a + s • (1 : A)) * (a + s • (1 : A)) + - Ring.inverse (a + s • (1 : A)) * (s • (1 : A)) := by rw [mul_sub] + _ = 1 - s • Ring.inverse (a + s • (1 : A)) := by rw [hiu, mul_smul_comm, mul_one] + have hia1 : Ring.inverse (a + s • (1 : A)) * (a - 1) + = 1 - (1 + s) • Ring.inverse (a + s • (1 : A)) := by + rw [mul_sub, hia, mul_one, add_smul, one_smul]; abel + have hid : (1 + s)⁻¹ • (1 : A) - Ring.inverse (a + s • 1) + = (1 + s)⁻¹ • (Ring.inverse (a + s • 1) * (a - 1)) := by + rw [hia1, smul_sub, smul_smul, inv_mul_cancel₀ hs1, one_smul] + have hres : ‖Ring.inverse (a + s • (1 : A))‖ ≤ (m + s)⁻¹ := by + apply CStarAlgebra.norm_ringInverse_le_of_algebraMap_le (m := m + s) (by linarith) + rw [map_add, Algebra.algebraMap_eq_smul_one (R := ℝ) (A := A) s] + gcongr + have hcm0 : min 1 m ≤ m := min_le_right 1 m + have hc10 : min 1 m ≤ 1 := min_le_left 1 m + have hcs : 0 < min 1 m + s := by linarith + rw [hid, norm_smul, Real.norm_eq_abs, abs_of_pos (by positivity : (0 : ℝ) < (1 + s)⁻¹)] + have e1 : (1 + s)⁻¹ ≤ (min 1 m + s)⁻¹ := (inv_le_inv₀ (by positivity) hcs).mpr (by linarith) + have e2 : (m + s)⁻¹ ≤ (min 1 m + s)⁻¹ := (inv_le_inv₀ (by positivity) hcs).mpr (by linarith) + calc (1 + s)⁻¹ * ‖Ring.inverse (a + s • 1) * (a - 1)‖ + ≤ (1 + s)⁻¹ * ((m + s)⁻¹ * ‖a - 1‖) := by + gcongr + exact (norm_mul_le _ _).trans (by gcongr) + _ = ‖a - 1‖ * ((1 + s)⁻¹ * (m + s)⁻¹) := by ring + _ ≤ ‖a - 1‖ * (min 1 m + s)⁻¹ ^ 2 := by + gcongr + calc (1 + s)⁻¹ * (m + s)⁻¹ + ≤ (min 1 m + s)⁻¹ * (min 1 m + s)⁻¹ := + mul_le_mul e1 e2 (by positivity) (by positivity) + _ = (min 1 m + s)⁻¹ ^ 2 := (sq _).symm diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventSquareIntegral.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventSquareIntegral.lean new file mode 100644 index 0000000000..fba8f05c07 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/ResolventSquareIntegral.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.ResolventBounds + +/-! +# Integral of the squared resolvent: `∫₀^∞ (a + s • 1)⁻² ds = a⁻¹` + +For a strictly positive element `a` of a C⋆-algebra the squared resolvent integrates to the +inverse: + +`∫₀^∞ (Ring.inverse (a + s • 1)) ^ 2 ds = Ring.inverse a`. + +This is the operator lift of the scalar identity `∫₀^∞ (x + s)⁻² ds = x⁻¹` (`x > 0`), but is proved +directly at the operator level by the (second) fundamental theorem of calculus: the squared +resolvent is, up to sign, the `s`-derivative of the resolvent, +`d/ds Ring.inverse (a + s • 1) = -(Ring.inverse (a + s • 1)) ^ 2` +(`hasDerivAt_ringInverse_add_smul` with direction `1`), which decays like `s⁻¹` to `0` as +`s → ∞`; the improper fundamental theorem of calculus +(`MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto`) then evaluates the integral of the +derivative to `0 - (-Ring.inverse a) = Ring.inverse a`. + +## Method + +Apply `integral_Ioi_of_hasDerivAt_of_tendsto` to the antiderivative +`g s = -Ring.inverse (a + s • 1)`, whose derivative on `(0, ∞)` is the squared resolvent +`Ring.inverse (a + s • 1) ^ 2`. Its hypotheses use, throughout, the positive lower bound `m` on the +spectrum of `a` (`(algebraMap ℝ A) m ≤ a`, `0 < m`, from `CFC.exists_pos_algebraMap_le_iff`): +* continuity of `g` at the left endpoint `0`, from the resolvent derivative at `0` (`a` a unit); +* integrability of the squared resolvent on `(0, ∞)`, from the resolvent norm bound + `‖Ring.inverse (a + s • 1)‖ ≤ (m + s)⁻¹` (`CStarAlgebra.norm_ringInverse_le_of_algebraMap_le`) + squared and dominated by the integrable `integrableOn_Ioi_inv_add_sq`; +* `Ring.inverse (a + s • 1) → 0` as `s → ∞`, since `‖·‖ ≤ (m + s)⁻¹ → 0`. + +## Main results + +* `integral_Ioi_ringInverse_add_smul_one_sq` — `∫₀^∞ (Ring.inverse (a + s • 1)) ^ 2 ds = + Ring.inverse a`. + +This is the operator normalization underlying the trace-derivative identity +`tr(ω_p · d/dp cfc Real.log ω_p) = tr(ρ - σ)` in the second-derivative proof of concavity of the von +Neumann entropy (Nielsen & Chuang, *Quantum Computation and Quantum Information*, Exercise 11.22): +the parametric logarithm derivative `d/dp cfc Real.log ω_p = ∫₀^∞ (ω_p + s)⁻¹ Δ (ω_p + s)⁻¹ ds`, +contracted against `ω_p` under the trace and cyclically rearranged, collapses via +`∫₀^∞ (ω_p + s)⁻² ds = ω_p⁻¹` to `tr(Δ)` with `Δ = ρ - σ`. +-/ + +@[expose] public section + +open MeasureTheory Set Filter Topology + +/-- **Integral of the squared resolvent.** For a strictly positive element `a` of a C⋆-algebra, +`∫₀^∞ (Ring.inverse (a + s • 1)) ^ 2 ds = Ring.inverse a`. The squared resolvent is, up to sign, the +`s`-derivative of the resolvent (`hasDerivAt_ringInverse_add_smul` in direction `1`), which decays +to `0` as `s → ∞`, so the improper fundamental theorem of calculus +(`integral_Ioi_of_hasDerivAt_of_tendsto`) evaluates the integral to +`0 - (-Ring.inverse a) = Ring.inverse a`. See the module docstring. -/ +theorem integral_Ioi_ringInverse_add_smul_one_sq + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a : A} (ha : IsStrictlyPositive a) : + ∫ s in Set.Ioi (0 : ℝ), Ring.inverse (a + s • (1 : A)) ^ 2 = Ring.inverse a := by + -- A positive lower bound `m` on the spectrum of `a`. + obtain ⟨m, hm, hma⟩ : ∃ m, 0 < m ∧ (algebraMap ℝ A) m ≤ a := + (CFC.exists_pos_algebraMap_le_iff (a := a)).mpr + (CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos.mp ha).2 + -- `a + s • 1` is a unit for `s ≥ 0`, with resolvent norm `≤ (m + s)⁻¹`. + have hunit : ∀ s : ℝ, 0 ≤ s → IsUnit (a + s • (1 : A)) := + fun s hs => (ha.add_nonneg (smul_nonneg hs zero_le_one)).isUnit + have hnorm : ∀ s : ℝ, 0 ≤ s → ‖Ring.inverse (a + s • (1 : A))‖ ≤ (m + s)⁻¹ := by + intro s hs + refine CStarAlgebra.norm_ringInverse_le_of_algebraMap_le (m := m + s) (by linarith) ?_ + rw [map_add, Algebra.algebraMap_eq_smul_one (R := ℝ) (A := A) s] + gcongr + -- The resolvent is continuous at every `s ≥ 0` (a unit there). + have hResCont : ∀ s : ℝ, 0 ≤ s → + ContinuousAt (fun t : ℝ => Ring.inverse (a + t • (1 : A))) s := + fun s hs => (hasDerivAt_ringInverse_add_smul (hunit s hs)).continuousAt + -- The antiderivative `g s = -Ring.inverse (a + s • 1)` has derivative `(Ring.inverse ·) ^ 2`. + have hderiv : ∀ s ∈ Ioi (0 : ℝ), + HasDerivAt (fun t : ℝ => -Ring.inverse (a + t • (1 : A))) + (Ring.inverse (a + s • (1 : A)) ^ 2) s := by + intro s hs + simp only [mem_Ioi] at hs + have hu := hunit s hs.le + have hinv : Ring.inverse (a + s • (1 : A)) = ↑hu.unit⁻¹ := by + conv_lhs => rw [← hu.unit_spec] + rw [Ring.inverse_unit] + have h := (hasDerivAt_ringInverse_add_smul (a := a) (b := (1 : A)) (t₀ := s) hu).neg + simp only [neg_neg, mul_one] at h + rw [hinv, sq] + exact h + -- The squared resolvent is integrable on `(0, ∞)`, dominated by `(m + s)⁻²`. + have hint : IntegrableOn (fun s : ℝ => Ring.inverse (a + s • (1 : A)) ^ 2) (Ioi 0) := by + have hmeas : AEStronglyMeasurable + (fun s : ℝ => Ring.inverse (a + s • (1 : A)) ^ 2) (volume.restrict (Ioi 0)) := by + refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi + exact fun s hs => (((hResCont s (le_of_lt hs)).continuousWithinAt).pow 2) + refine (integrableOn_Ioi_inv_add_sq hm).mono' hmeas ?_ + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ ?_) + intro s hs + simp only [mem_Ioi] at hs + calc ‖Ring.inverse (a + s • (1 : A)) ^ 2‖ + = ‖Ring.inverse (a + s • (1 : A)) * Ring.inverse (a + s • (1 : A))‖ := by rw [sq] + _ ≤ ‖Ring.inverse (a + s • (1 : A))‖ * ‖Ring.inverse (a + s • (1 : A))‖ := norm_mul_le _ _ + _ ≤ (m + s)⁻¹ * (m + s)⁻¹ := + mul_le_mul (hnorm s hs.le) (hnorm s hs.le) (norm_nonneg _) (by positivity) + _ = (m + s)⁻¹ ^ 2 := (sq _).symm + -- Continuity of `g` at `0` and its limit `0` at `∞`. + have hcont0 : ContinuousWithinAt (fun t : ℝ => -Ring.inverse (a + t • (1 : A))) (Ici 0) 0 := + ((hResCont 0 le_rfl).continuousWithinAt).neg + have htend : Tendsto (fun t : ℝ => -Ring.inverse (a + t • (1 : A))) atTop (𝓝 0) := by + have hg : Tendsto (fun s : ℝ => (m + s)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (tendsto_atTop_add_const_left atTop m tendsto_id) + have hres : Tendsto (fun t : ℝ => Ring.inverse (a + t • (1 : A))) atTop (𝓝 0) := by + refine squeeze_zero_norm' ?_ hg + filter_upwards [eventually_ge_atTop (0 : ℝ)] with s hs using hnorm s hs + simpa using hres.neg + -- The improper fundamental theorem of calculus. + simpa using integral_Ioi_of_hasDerivAt_of_tendsto hcont0 hderiv hint htend diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/TraceDeriv.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/TraceDeriv.lean new file mode 100644 index 0000000000..874f990bce --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/TraceDeriv.lean @@ -0,0 +1,322 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.ResolventSquareIntegral +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.Trace +public import Mathlib.Analysis.InnerProductSpace.StarOrder +public import LeanPool.AxQM.ToMathlib.Analysis.InnerProductSpace.OperatorSum + +/-! +# Trace of the operator-logarithm derivative: `tr(ω · d/dp log ω_p) = tr(Δ)` + +For a strictly positive operator `W` on a finite-dimensional complex inner product space and any +operator `Δ`, the resolvent "sandwich" integral contracted against `W` under the trace collapses to +the plain trace of `Δ`: + +`tr(W · ∫₀^∞ (W + s • 1)⁻¹ Δ (W + s • 1)⁻¹ ds) = tr(Δ)`. + +With `W = ω_p = p ρ + (1 − p) σ` the mixing operator and `Δ = ρ − σ`, the integral is exactly the +parametric derivative of the operator logarithm `d/dp cfc Real.log ω_p` +(`hasDerivAt_cfc_log_add_smul`), so this is the trace-derivative identity +`tr(ω_p · d/dp log ω_p) = tr(ρ − σ)` used in the +second-derivative proof of concavity of the von Neumann entropy (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Exercise 11.22). + +## Method + +Writing `Rₛ = (W + s • 1)⁻¹`, the integrand `Rₛ Δ Rₛ` is integrable on `(0, ∞)` +(`integrableOn_Ioi_ringInverse_mul_mul_ringInverse`, dominated by `‖Δ‖ (m + s)⁻²`). The trace and +the constant left factor `W` are pulled inside the Bochner integral (both are continuous linear, via +`ContinuousLinearMap.integral_comp_comm`), and then, pointwise in `s`: + +* cyclicity of the trace (`LinearMap.trace_mul_comm`) moves the factors around; +* `W` commutes with its own resolvent — `W Rₛ = 1 − s Rₛ = Rₛ W` (both from `mul_inverse_cancel`) — + so `Rₛ W Rₛ = W Rₛ²`. + +This turns `tr(W Rₛ Δ Rₛ)` into `tr((Δ W) Rₛ²)`, whose `s`-integral collapses via +`∫₀^∞ Rₛ² ds = W⁻¹` (`integral_Ioi_ringInverse_add_smul_one_sq`) to `tr(Δ W W⁻¹) = tr(Δ)`. + +## Main results + +* `ContinuousLinearMap.reTraceCLM` — the functional `X ↦ re tr(X)` bundled as a real-linear + continuous map `(E →L[ℂ] E) →L[ℝ] ℝ` (the real-part sibling of `traceCLM`). +* `integrableOn_Ioi_ringInverse_mul_mul_ringInverse` — integrability of the resolvent sandwich + `s ↦ (a + s • 1)⁻¹ x (a + s • 1)⁻¹` on `(0, ∞)`, for `a` strictly positive in a C⋆-algebra. +* `LinearMap.trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse` — the trace-derivative + identity. +* `LinearMap.re_trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse_nonneg` — nonnegativity of + the *second*-derivative trace integral `re tr(Δ · ∫₀^∞ Rₛ Δ Rₛ ds) ≥ 0` for `Δ` self-adjoint, + i.e. `f''(p) ≤ 0` for `f(p) = S(ω_p)` (the second-derivative form of concavity of the von Neumann + entropy, Nielsen & Chuang Exercise 11.22). +-/ + +@[expose] public section + +open MeasureTheory Set + +/-- The **trace** on a finite-dimensional complex inner product space, bundled as a continuous +ℂ-linear functional `(E →L[ℂ] E) →L[ℂ] ℂ` (a linear map out of a finite-dimensional space is +automatically continuous). Packaging the trace this way lets it be pushed through a Bochner +integral via `ContinuousLinearMap.integral_comp_comm`, as in the trace-derivative identities +below. -/ +noncomputable def ContinuousLinearMap.traceCLM + (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] : + (E →L[ℂ] E) →L[ℂ] ℂ := + LinearMap.toContinuousLinearMap ((LinearMap.trace ℂ E).comp (ContinuousLinearMap.coeLM ℂ)) + +@[simp] +theorem ContinuousLinearMap.traceCLM_apply + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + (X : E →L[ℂ] E) : ContinuousLinearMap.traceCLM E X = (LinearMap.trace ℂ E) ↑X := by + simp [ContinuousLinearMap.traceCLM, LinearMap.coe_toContinuousLinearMap'] + +/-- **The entropy functional `re ∘ tr`, bundled as a real-linear continuous functional** +`(E →L[ℂ] E) →L[ℝ] ℝ`, `X ↦ re tr(X)` — the `ℝ`-CLM real-part sibling of +`ContinuousLinearMap.traceCLM`. Packaging `re ∘ tr` this way lets it be pushed through a real +derivative via `HasFDerivAt.comp_hasDerivAt`, as in the entropy-derivative computations +(`ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/EntropyDeriv.lean`). -/ +noncomputable def ContinuousLinearMap.reTraceCLM + (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] : + (E →L[ℂ] E) →L[ℝ] ℝ := + -- `IsScalarTower ℝ ℂ (E →L[ℂ] E)` is mathematically valid but not a global instance for abstract + -- `E` (the `rclike_operator_algebra_gap` §3.5); provide it locally as in + -- `ToMathlib/Analysis/InnerProductSpace/DensityFixedPoint.lean`, so + -- `RCLike.real_smul_eq_coe_smul` gives `ℝ`-linearity of `X ↦ re tr X`. (Restricting the + -- ℂ-linear `traceCLM` directly hits a + -- `Module ℝ (E →L[ℂ] E)` diamond in `CompatibleSMul`; we instead build the `ℝ`-linear map by + -- hand with an explicit operator-norm bound.) + letI : IsScalarTower ℝ ℂ (E →L[ℂ] E) := IsScalarTower.restrictScalars ℝ ℂ _ + LinearMap.mkContinuous + { toFun := fun X => RCLike.re ((LinearMap.trace ℂ E) ↑X) + map_add' := fun X Y => by simp only [ContinuousLinearMap.toLinearMap_add, map_add] + map_smul' := fun r X => by + simp only [RingHom.id_apply, RCLike.real_smul_eq_coe_smul (K := ℂ) r X, + ContinuousLinearMap.toLinearMap_smul, map_smul, smul_eq_mul, RCLike.re_ofReal_mul] } + ‖ContinuousLinearMap.traceCLM E‖ fun X => by + calc ‖RCLike.re ((LinearMap.trace ℂ E) ↑X)‖ + ≤ ‖(LinearMap.trace ℂ E) ↑X‖ := RCLike.norm_re_le_norm _ + _ = ‖ContinuousLinearMap.traceCLM E X‖ := by rw [ContinuousLinearMap.traceCLM_apply] + _ ≤ ‖ContinuousLinearMap.traceCLM E‖ * ‖X‖ := (ContinuousLinearMap.traceCLM E).le_opNorm X + +@[simp] +theorem ContinuousLinearMap.reTraceCLM_apply + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + (X : E →L[ℂ] E) : + ContinuousLinearMap.reTraceCLM E X = RCLike.re ((LinearMap.trace ℂ E) ↑X) := + rfl + +/-- **Integrability of the resolvent sandwich.** For a strictly positive element `a` of a C⋆-algebra +and any element `x`, the map `s ↦ (a + s • 1)⁻¹ x (a + s • 1)⁻¹` is integrable on `(0, ∞)`. With +`(algebraMap ℝ A) m ≤ a` (a positive spectral lower bound), the resolvent norm bound +`‖(a + s • 1)⁻¹‖ ≤ (m + s)⁻¹` (`CStarAlgebra.norm_ringInverse_le_of_algebraMap_le`) and +submultiplicativity give `‖·‖ ≤ ‖x‖ (m + s)⁻²`, an integrable dominating function +(`integrableOn_Ioi_inv_add_sq`). -/ +theorem integrableOn_Ioi_ringInverse_mul_mul_ringInverse + {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] [Nontrivial A] + {a : A} (ha : IsStrictlyPositive a) (x : A) : + IntegrableOn + (fun s : ℝ => Ring.inverse (a + s • 1) * x * Ring.inverse (a + s • 1)) (Ioi 0) := by + obtain ⟨m, hm, hma⟩ : ∃ m, 0 < m ∧ (algebraMap ℝ A) m ≤ a := + (CFC.exists_pos_algebraMap_le_iff (a := a)).mpr + (CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos.mp ha).2 + have hunit : ∀ s : ℝ, 0 ≤ s → IsUnit (a + s • (1 : A)) := + fun s hs => (ha.add_nonneg (smul_nonneg hs zero_le_one)).isUnit + have hnorm : ∀ s : ℝ, 0 ≤ s → ‖Ring.inverse (a + s • (1 : A))‖ ≤ (m + s)⁻¹ := by + intro s hs + refine CStarAlgebra.norm_ringInverse_le_of_algebraMap_le (m := m + s) (by linarith) ?_ + rw [map_add, Algebra.algebraMap_eq_smul_one (R := ℝ) (A := A) s] + gcongr + have hResCont : ∀ s : ℝ, 0 ≤ s → + ContinuousAt (fun t : ℝ => Ring.inverse (a + t • (1 : A))) s := + fun s hs => (hasDerivAt_ringInverse_add_smul (hunit s hs)).continuousAt + have hcont : ContinuousOn + (fun s : ℝ => Ring.inverse (a + s • (1 : A)) * x * Ring.inverse (a + s • 1)) (Ioi 0) := + fun s hs => + (((hResCont s (le_of_lt hs)).continuousWithinAt.mul continuousWithinAt_const).mul + ((hResCont s (le_of_lt hs)).continuousWithinAt)) + have hmeas : AEStronglyMeasurable + (fun s : ℝ => Ring.inverse (a + s • (1 : A)) * x * Ring.inverse (a + s • 1)) + (volume.restrict (Ioi 0)) := + hcont.aestronglyMeasurable measurableSet_Ioi + refine ((integrableOn_Ioi_inv_add_sq hm).const_mul ‖x‖).mono' hmeas ?_ + refine (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun s hs => ?_) + simp only [mem_Ioi] at hs + have hr := hnorm s hs.le + calc ‖Ring.inverse (a + s • (1 : A)) * x * Ring.inverse (a + s • 1)‖ + ≤ ‖Ring.inverse (a + s • (1 : A)) * x‖ * ‖Ring.inverse (a + s • (1 : A))‖ := norm_mul_le _ _ + _ ≤ (‖Ring.inverse (a + s • (1 : A))‖ * ‖x‖) * ‖Ring.inverse (a + s • (1 : A))‖ := by + gcongr; exact norm_mul_le _ _ + _ ≤ ((m + s)⁻¹ * ‖x‖) * (m + s)⁻¹ := by gcongr + _ = ‖x‖ * (m + s)⁻¹ ^ 2 := by ring + +/-- **Trace-derivative identity.** For a strictly positive operator `W` on a finite-dimensional +complex inner product space and any operator `Δ`, + +`tr(W · ∫₀^∞ (W + s • 1)⁻¹ Δ (W + s • 1)⁻¹ ds) = tr(Δ)`. + +The integral is the parametric derivative `d/dp cfc Real.log ω_p` at `ω_p = W` +(`hasDerivAt_cfc_log_add_smul`, direction `Δ`), so this is `tr(W · d/dp log ω_p) = tr(Δ)`. See the +module docstring for the method. -/ +theorem LinearMap.trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [Nontrivial E] {W : E →L[ℂ] E} (hW : IsStrictlyPositive W) (Δ : E →L[ℂ] E) : + (LinearMap.trace ℂ E) ↑(W * ∫ s in Ioi (0 : ℝ), + Ring.inverse (W + s • 1) * Δ * Ring.inverse (W + s • 1)) + = (LinearMap.trace ℂ E) ↑Δ := by + set R : ℝ → (E →L[ℂ] E) := fun s => Ring.inverse (W + s • 1) with hR + -- Trace cyclicity through the `ContinuousLinearMap → LinearMap` coercion. + have trcyc : ∀ B C : E →L[ℂ] E, + (LinearMap.trace ℂ E) ↑(B * C) = (LinearMap.trace ℂ E) ↑(C * B) := by + intro B C + rw [ContinuousLinearMap.toLinearMap_mul, ContinuousLinearMap.toLinearMap_mul, + LinearMap.trace_mul_comm] + -- The trace, bundled as a continuous linear functional (`ContinuousLinearMap.traceCLM`); + -- left multiplication by a constant is `ContinuousLinearMap.mul_apply'`. + let tr : (E →L[ℂ] E) →L[ℂ] ℂ := ContinuousLinearMap.traceCLM E + have htr : ∀ X : E →L[ℂ] E, tr X = (LinearMap.trace ℂ E) ↑X := + fun X => ContinuousLinearMap.traceCLM_apply X + -- Integrability of the two integrands. + have hφint : IntegrableOn (fun s => R s * Δ * R s) (Ioi 0) := + integrableOn_Ioi_ringInverse_mul_mul_ringInverse hW Δ + have hR2int : IntegrableOn (fun s => R s ^ 2) (Ioi 0) := by + have := integrableOn_Ioi_ringInverse_mul_mul_ringInverse hW (1 : E →L[ℂ] E) + refine this.congr_fun ?_ measurableSet_Ioi + intro s _; simp [hR, sq, mul_one] + -- `W` commutes with its resolvent: `R s W R s = W (R s)^2`. + have hWR : ∀ s : ℝ, 0 < s → R s * W = 1 - s • R s := by + intro s hs + have hu : IsUnit (W + s • (1 : E →L[ℂ] E)) := + (hW.add_nonneg (smul_nonneg hs.le zero_le_one)).isUnit + have hiu : Ring.inverse (W + s • (1 : E →L[ℂ] E)) * (W + s • (1 : E →L[ℂ] E)) = 1 := + Ring.inverse_mul_cancel _ hu + have expand : W = (W + s • (1 : E →L[ℂ] E)) - s • (1 : E →L[ℂ] E) := by abel + calc R s * W = R s * ((W + s • 1) - s • 1) := by rw [hR, ← expand] + _ = R s * (W + s • 1) - R s * (s • 1) := by rw [mul_sub] + _ = 1 - s • R s := by rw [hR, hiu, mul_smul_comm, mul_one] + have hRW : ∀ s : ℝ, 0 < s → W * R s = 1 - s • R s := by + intro s hs + have hu : IsUnit (W + s • (1 : E →L[ℂ] E)) := + (hW.add_nonneg (smul_nonneg hs.le zero_le_one)).isUnit + have hiu : (W + s • (1 : E →L[ℂ] E)) * Ring.inverse (W + s • (1 : E →L[ℂ] E)) = 1 := + Ring.mul_inverse_cancel _ hu + have expand : W = (W + s • (1 : E →L[ℂ] E)) - s • (1 : E →L[ℂ] E) := by abel + calc W * R s = ((W + s • 1) - s • 1) * R s := by rw [hR, ← expand] + _ = (W + s • 1) * R s - (s • 1) * R s := by rw [sub_mul] + _ = 1 - s • R s := by rw [hR, hiu, smul_mul_assoc, one_mul] + have hcomm : ∀ s : ℝ, 0 < s → R s * W * R s = W * R s ^ 2 := by + intro s hs + rw [hWR s hs, sq] + rw [show W * (R s * R s) = (W * R s) * R s by rw [mul_assoc], hRW s hs] + -- Pointwise: `tr(W · (R s Δ R s)) = tr((Δ W) · (R s)^2)`. + have hpt : ∀ s : ℝ, s ∈ Ioi (0 : ℝ) → + (LinearMap.trace ℂ E) ↑(W * (R s * Δ * R s)) + = (LinearMap.trace ℂ E) ↑((Δ * W) * R s ^ 2) := by + intro s hs + simp only [mem_Ioi] at hs + calc (LinearMap.trace ℂ E) ↑(W * (R s * Δ * R s)) + = (LinearMap.trace ℂ E) ↑((W * R s * Δ) * R s) := by rw [show W * (R s * Δ * R s) + = (W * R s * Δ) * R s by noncomm_ring] + _ = (LinearMap.trace ℂ E) ↑(R s * (W * R s * Δ)) := trcyc _ _ + _ = (LinearMap.trace ℂ E) ↑((R s * W * R s) * Δ) := by rw [show R s * (W * R s * Δ) + = (R s * W * R s) * Δ by noncomm_ring] + _ = (LinearMap.trace ℂ E) ↑((W * R s ^ 2) * Δ) := by rw [hcomm s hs] + _ = (LinearMap.trace ℂ E) ↑(Δ * (W * R s ^ 2)) := trcyc _ _ + _ = (LinearMap.trace ℂ E) ↑((Δ * W) * R s ^ 2) := by rw [mul_assoc] + -- Assemble. + calc (LinearMap.trace ℂ E) ↑(W * ∫ s in Ioi (0 : ℝ), R s * Δ * R s) + = tr ((ContinuousLinearMap.mul ℂ (E →L[ℂ] E) W) (∫ s in Ioi (0 : ℝ), R s * Δ * R s)) := by + rw [htr, ContinuousLinearMap.mul_apply'] + _ = tr (∫ s in Ioi (0 : ℝ), (ContinuousLinearMap.mul ℂ (E →L[ℂ] E) W) (R s * Δ * R s)) := by + rw [ContinuousLinearMap.integral_comp_comm _ hφint] + _ = ∫ s in Ioi (0 : ℝ), tr ((ContinuousLinearMap.mul ℂ (E →L[ℂ] E) W) (R s * Δ * R s)) := by + rw [← ContinuousLinearMap.integral_comp_comm] + exact (ContinuousLinearMap.mul ℂ (E →L[ℂ] E) W).integrable_comp hφint + _ = ∫ s in Ioi (0 : ℝ), (LinearMap.trace ℂ E) ↑((Δ * W) * R s ^ 2) := by + refine setIntegral_congr_fun measurableSet_Ioi (fun s hs => ?_) + rw [htr, ContinuousLinearMap.mul_apply', hpt s hs] + _ = ∫ s in Ioi (0 : ℝ), tr ((ContinuousLinearMap.mul ℂ (E →L[ℂ] E) (Δ * W)) (R s ^ 2)) := by + refine setIntegral_congr_fun measurableSet_Ioi (fun s _ => ?_) + rw [htr, ContinuousLinearMap.mul_apply'] + _ = tr (∫ s in Ioi (0 : ℝ), (ContinuousLinearMap.mul ℂ (E →L[ℂ] E) (Δ * W)) (R s ^ 2)) := by + rw [← ContinuousLinearMap.integral_comp_comm] + exact (ContinuousLinearMap.mul ℂ (E →L[ℂ] E) (Δ * W)).integrable_comp hR2int + _ = tr ((ContinuousLinearMap.mul ℂ (E →L[ℂ] E) (Δ * W)) (∫ s in Ioi (0 : ℝ), R s ^ 2)) := by + rw [ContinuousLinearMap.integral_comp_comm _ hR2int] + _ = (LinearMap.trace ℂ E) ↑((Δ * W) * Ring.inverse W) := by + rw [htr, ContinuousLinearMap.mul_apply', hR, integral_Ioi_ringInverse_add_smul_one_sq hW] + _ = (LinearMap.trace ℂ E) ↑Δ := by + rw [mul_assoc, Ring.mul_inverse_cancel _ hW.isUnit, mul_one] + +/-- **Nonnegativity of the second-derivative trace integral.** For a strictly positive operator `W` +on a finite-dimensional complex inner product space and a *self-adjoint* operator `Δ`, + +`0 ≤ re tr(Δ · ∫₀^∞ (W + s • 1)⁻¹ Δ (W + s • 1)⁻¹ ds)`. + +With `W = ω_p = p ρ + (1 − p) σ` and `Δ = ρ − σ`, the integral is the parametric derivative +`d/dp cfc Real.log ω_p` (`hasDerivAt_cfc_log_add_smul`), so the left-hand side is `−f''(p)` for +`f(p) = S(ω_p) = −tr(ω_p log ω_p)`. This is therefore the second-derivative form of concavity of the +von Neumann entropy — `f''(p) ≤ 0` — the analytic heart of Nielsen & Chuang's alternate proof of +concavity (*Quantum Computation and Quantum Information*, Exercise 11.22). + +## Method + +Writing `Rₛ = (W + s • 1)⁻¹`, the constant left factor `Δ` and the trace are pulled inside the +Bochner integral (both continuous linear, via `ContinuousLinearMap.integral_comp_comm`, using +integrability of `Rₛ Δ Rₛ` from `integrableOn_Ioi_ringInverse_mul_mul_ringInverse`), and `re` +commutes with the integral (`RCLike.reCLM`). This reduces the claim to pointwise nonnegativity of +the integrand: for `s > 0`, + +`re tr(Δ (Rₛ Δ Rₛ)) = re tr((Δ Rₛ Δ) · Rₛ) ≥ 0`, + +because `Rₛ` is positive (`IsStrictlyPositive.ringInverse`, `W + s • 1` being strictly positive), +its self-adjoint conjugate `Δ Rₛ Δ` is positive (`IsSelfAdjoint.conjugate_nonneg`), and the trace of +a product of positive operators has nonnegative real part +(`ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg`) — the Hilbert–Schmidt square +`re tr(Δ Rₛ Δ Rₛ) = ‖Rₛ^{1/2} Δ Rₛ^{1/2}‖₂² ≥ 0`. The `s`-integral of a nonnegative function is +nonnegative (`MeasureTheory.setIntegral_nonneg`). -/ +theorem LinearMap.re_trace_mul_integral_Ioi_ringInverse_mul_mul_ringInverse_nonneg + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + [CompleteSpace E] [Nontrivial E] {W : E →L[ℂ] E} (hW : IsStrictlyPositive W) + {Δ : E →L[ℂ] E} (hΔ : IsSelfAdjoint Δ) : + 0 ≤ RCLike.re ((LinearMap.trace ℂ E) ↑(Δ * ∫ s in Ioi (0 : ℝ), + Ring.inverse (W + s • 1) * Δ * Ring.inverse (W + s • 1))) := by + set R : ℝ → (E →L[ℂ] E) := fun s => Ring.inverse (W + s • 1) with hR + -- `G X = tr(Δ · X)`, bundled as a continuous linear map (via `ContinuousLinearMap.traceCLM`) + -- for the integral-commutation lemmas; left multiplication is `ContinuousLinearMap.mul_apply'`. + set G : (E →L[ℂ] E) →L[ℂ] ℂ := + (ContinuousLinearMap.traceCLM E).comp (ContinuousLinearMap.mul ℂ (E →L[ℂ] E) Δ) with hG + have hGapp : ∀ X : E →L[ℂ] E, G X = (LinearMap.trace ℂ E) ↑(Δ * X) := fun X => by + rw [hG, ContinuousLinearMap.comp_apply, ContinuousLinearMap.mul_apply', + ContinuousLinearMap.traceCLM_apply] + -- Integrability of the resolvent sandwich, and of the scalar integrand `s ↦ tr(Δ (Rₛ Δ Rₛ))`. + have hφint : IntegrableOn (fun s => R s * Δ * R s) (Ioi 0) := + integrableOn_Ioi_ringInverse_mul_mul_ringInverse hW Δ + have hGint : IntegrableOn (fun s => G (R s * Δ * R s)) (Ioi 0) := G.integrable_comp hφint + -- Pointwise: `re tr(Δ (Rₛ Δ Rₛ)) = re tr((Δ Rₛ Δ) · Rₛ) ≥ 0`. + have hpt : ∀ s ∈ Ioi (0 : ℝ), 0 ≤ RCLike.re (G (R s * Δ * R s)) := by + intro s hs + simp only [mem_Ioi] at hs + have hWs : IsStrictlyPositive (W + s • (1 : E →L[ℂ] E)) := + hW.add_nonneg (smul_nonneg hs.le zero_le_one) + have hRpos : (0 : E →L[ℂ] E) ≤ R s := (hWs.ringInverse).nonneg + have hAr : (0 : E →L[ℂ] E) ≤ Δ * R s * Δ := IsSelfAdjoint.conjugate_nonneg hRpos hΔ + rw [hGapp, show Δ * (R s * Δ * R s) = (Δ * R s * Δ) * R s by noncomm_ring] + exact ContinuousLinearMap.re_trace_mul_nonneg_of_nonneg hAr hRpos + -- Pull `Δ` and the trace inside the integral. + have hpull : (LinearMap.trace ℂ E) ↑(Δ * ∫ s in Ioi (0 : ℝ), R s * Δ * R s) + = ∫ s in Ioi (0 : ℝ), G (R s * Δ * R s) := by + rw [← hGapp] + exact (ContinuousLinearMap.integral_comp_comm G hφint).symm + -- `re` commutes with the integral; the integrand is nonnegative. + rw [hpull] + have hre : RCLike.re (∫ s in Ioi (0 : ℝ), G (R s * Δ * R s)) + = ∫ s in Ioi (0 : ℝ), RCLike.re (G (R s * Δ * R s)) := (integral_re hGint).symm + rw [hre] + exact setIntegral_nonneg measurableSet_Ioi hpt diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/GeometricMean.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/GeometricMean.lean new file mode 100644 index 0000000000..999a87f818 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/GeometricMean.lean @@ -0,0 +1,133 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.ConjSqrt + +/-! +# Operator geometric mean + +This file defines the operator geometric mean of two positive elements in a C⋆-algebra, +$M_0(a, b) := a^{1/2} (a^{-1/2} b a^{-1/2})^{1/2} a^{1/2}$, via the continuous functional +calculus. For commuting strictly positive `a, b` this reduces to `sqrt (a * b)`. + +The definition is the Pusz–Woronowicz form (Carlen Definition 3.7): it is the largest `X ≥ 0` +such that the `2 × 2` block operator `[[a, X], [X, b]]` is positive semidefinite. The +maximality characterization and joint concavity (`GeometricMeanMaximality`) and +tensor-distributivity (`CFCTensor`) are developed separately. + +## Main declarations + +* `CFC.geometricMean a b` — the operator geometric mean of `a` and `b`. + +## Main results + +* `CFC.geometricMean_self` — `M₀(a, a) = a` for strictly positive `a`. +* `CFC.geometricMean_one_left` / `_one_right` — boundary cases with one argument equal to `1`. +* `CFC.geometricMean_nonneg` — the geometric mean is nonnegative. +* `CFC.geometricMean_mul_ringInverse_mul_geometricMean` — `M₀(a, b) · a⁻¹ · M₀(a, b) = b`. +-/ + +namespace CFC + +open Ring + +public section GeometricMean + +variable {A : Type*} [PartialOrder A] [Ring A] [StarRing A] [TopologicalSpace A] + [StarOrderedRing A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] + [NonnegSpectrumClass ℝ A] + +section SeparatelyContinuousMul + +variable [SeparatelyContinuousMul A] + +/-- The operator geometric mean of two elements `a, b` of a C⋆-algebra: +`M₀(a, b) := a^{1/2} (a^{-1/2} b a^{-1/2})^{1/2} a^{1/2}`. + +For strictly positive commuting `a, b` this reduces to `sqrt (a * b)`. When `a` is not +nonnegative (or `a` is nonnegative but not strictly positive), the definition returns `0`. -/ +@[expose] +noncomputable def geometricMean (a b : A) : A := + conjSqrt a (sqrt (conjSqrt a⁻¹ʳ b)) + +lemma geometricMean_def (a b : A) : + geometricMean a b = conjSqrt a (sqrt (conjSqrt a⁻¹ʳ b)) := rfl + +/-- Factored form: `M₀(a, b) = √a · √(√a⁻¹ · b · √a⁻¹) · √a`. The block-PSD factorization +in the maximality argument routes through this form. -/ +lemma geometricMean_eq_mul (a b : A) : + geometricMean a b = sqrt a * sqrt (conjSqrt a⁻¹ʳ b) * sqrt a := rfl + +lemma geometricMean_of_not_nonneg_left {a b : A} (ha : ¬0 ≤ a) : + geometricMean a b = 0 := by + simp [geometricMean, conjSqrt_of_not_nonneg ha] + +lemma geometricMean_nonneg (a b : A) : 0 ≤ geometricMean a b := + (map_zero (conjSqrt a)) ▸ conjSqrt_monotone (sqrt_nonneg _) + +@[simp] +lemma geometricMean_zero_right (a : A) : geometricMean a 0 = 0 := by + simp [geometricMean] + +@[simp] +lemma geometricMean_zero_left (b : A) : geometricMean (0 : A) b = 0 := by + simp [geometricMean, conjSqrt_apply] + +end SeparatelyContinuousMul + +variable [IsSemitopologicalRing A] [T2Space A] + +@[simp] +lemma geometricMean_self {a : A} (ha : IsStrictlyPositive a) : geometricMean a a = a := by + rw [geometricMean, conjSqrt_ringInverse_self a, sqrt_one, conjSqrt_one a ha.nonneg] + +@[simp] +lemma geometricMean_one_left (b : A) : geometricMean (1 : A) b = sqrt b := by + simp [geometricMean, conjSqrt_apply] + +lemma geometricMean_one_right {a : A} (ha : IsStrictlyPositive a) : + geometricMean a 1 = sqrt a := by + rw [geometricMean, conjSqrt_one a⁻¹ʳ ha.ringInverse.nonneg, sqrt_ringInverse, + conjSqrt_apply, Ring.mul_inverse_cancel _ ha.sqrt.isUnit, one_mul] + +/-- Key algebraic identity: `M₀(a, b) · a⁻¹ · M₀(a, b) = b` for strictly positive `a` and +nonnegative `b`. This is the "round-trip" property of `conjSqrt` lifted to the geometric mean, +and underlies the block factorization `[[a, M₀], [M₀, b]] = T*T` in the maximality argument. -/ +lemma geometricMean_mul_ringInverse_mul_geometricMean + {a b : A} (ha : IsStrictlyPositive a) (hb : 0 ≤ b) : + geometricMean a b * Ring.inverse a * geometricMean a b = b := by + have hZ : 0 ≤ conjSqrt a⁻¹ʳ b := map_zero (conjSqrt a⁻¹ʳ) ▸ conjSqrt_monotone hb + have hsa : sqrt a * Ring.inverse a * sqrt a = 1 := by + have h := conjSqrt_ringInverse_self (Ring.inverse a) ha.ringInverse + rwa [Ring.inverse_inverse ha.isUnit] at h + calc geometricMean a b * Ring.inverse a * geometricMean a b + = sqrt a * sqrt (conjSqrt a⁻¹ʳ b) * (sqrt a * Ring.inverse a * sqrt a) * + sqrt (conjSqrt a⁻¹ʳ b) * sqrt a := by rw [geometricMean_eq_mul]; noncomm_ring + _ = sqrt a * (sqrt (conjSqrt a⁻¹ʳ b) * sqrt (conjSqrt a⁻¹ʳ b)) * sqrt a := by + rw [hsa]; noncomm_ring + _ = sqrt a * conjSqrt a⁻¹ʳ b * sqrt a := by rw [sqrt_mul_sqrt_self _ hZ] + _ = b := conjSqrt_conjSqrt_ringInverse a b ha + +/-- **Same-base GM identity**: for strictly positive `a` in a C⋆-algebra, the geometric mean of +two real powers of `a` is the power at the midpoint of the exponents: +`M₀(a^p, a^q) = a^{(p+q)/2}`. Direct consequence of the multiplicativity of `rpow` on a single +base (`rpow_add` for `IsUnit a`) plus `sqrt_eq_rpow`. -/ +lemma geometricMean_rpow_rpow {a : A} (ha : IsStrictlyPositive a) (p q : ℝ) : + geometricMean (a ^ p) (a ^ q) = a ^ ((p + q) / 2) := by + rw [geometricMean_eq_mul, ha.inverse_rpow, conjSqrt_apply, ha.sqrt_rpow (-p), + ← rpow_add ha.isUnit, ← rpow_add ha.isUnit, ha.sqrt_rpow, ha.sqrt_rpow, + ← rpow_add ha.isUnit, ← rpow_add ha.isUnit] + congr 1 + ring + +end GeometricMean + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Basic.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Basic.lean new file mode 100644 index 0000000000..5317650e26 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Basic.lean @@ -0,0 +1,52 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic + +/-! +# `sqrt`/`Ring.inverse` of `rpow`, without the `x ≠ 0` restriction + +`IsStrictlyPositive.sqrt_rpow` and `IsStrictlyPositive.inverse_rpow` drop the `x ≠ 0` +hypothesis from `CFC.sqrt_rpow`/`CFC.inverse_rpow` by handling `x = 0` directly via `rpow_zero`. +-/ + +@[expose] public section + +namespace CFC + +section Unital + +variable {A : Type*} [PartialOrder A] [Ring A] [StarRing A] [TopologicalSpace A] + [StarOrderedRing A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] + [NonnegSpectrumClass ℝ A] + +section unital_vs_nonunital + +open Ring +variable [IsSemitopologicalRing A] [T2Space A] +open scoped ContinuousFunctionalCalculus + +/-- The strict-positivity form of `sqrt_rpow`: for strictly positive `a`, +`sqrt (a^x) = a^(x/2)` for any real `x`. -/ +lemma _root_.IsStrictlyPositive.sqrt_rpow {a : A} (ha : IsStrictlyPositive a) (x : ℝ) : + sqrt (a ^ x) = a ^ (x / 2) := + CFC.sqrt_rpow ha.isUnit + +/-- The strict-positivity form of `inverse_rpow`: for strictly positive `a`, +`Ring.inverse (a^x) = a^(-x)` for any real `x`. -/ +lemma _root_.IsStrictlyPositive.inverse_rpow {a : A} (ha : IsStrictlyPositive a) (x : ℝ) : + Ring.inverse (a ^ x) = a ^ (-x) := + CFC.inverse_rpow a x ha + +end unital_vs_nonunital + +end Unital + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/ConjSqrt.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/ConjSqrt.lean new file mode 100644 index 0000000000..2781161d9e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/ConjSqrt.lean @@ -0,0 +1,52 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.ConjSqrt + +/-! +# Additional API for `CFC.conjSqrt` + +Nonnegativity of `conjSqrt c a` for `0 ≤ a`, and the squaring identity +`(conjSqrt a x) * (conjSqrt a x) = conjSqrt a (x * a * x)` for `0 ≤ a`. +-/ + +namespace CFC + +open Ring + +@[expose] public section ConjSqrt + +variable {A : Type*} [PartialOrder A] [Ring A] [StarRing A] [TopologicalSpace A] + [StarOrderedRing A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] + [NonnegSpectrumClass ℝ A] + +section SeparatelyContinuousMul + +variable [SeparatelyContinuousMul A] + +lemma conjSqrt_nonneg (c : A) {a : A} (ha : 0 ≤ a) : 0 ≤ conjSqrt c a := + map_zero (conjSqrt c) ▸ conjSqrt_monotone ha + +end SeparatelyContinuousMul + +variable [IsSemitopologicalRing A] [T2Space A] + +/-- Squaring the `conjSqrt` map: `(conjSqrt a x) * (conjSqrt a x) = conjSqrt a (x * a * x)` +for `0 ≤ a`. Direct consequence of `conjSqrt_apply` + `sqrt_mul_sqrt_self`. -/ +lemma conjSqrt_mul_self (a x : A) (ha : 0 ≤ a := by cfc_tac) : + conjSqrt a x * conjSqrt a x = conjSqrt a (x * a * x) := by + rw [conjSqrt_apply] + calc (sqrt a * x * sqrt a) * (sqrt a * x * sqrt a) + = sqrt a * x * (sqrt a * sqrt a) * x * sqrt a := by noncomm_ring + _ = sqrt a * (x * a * x) * sqrt a := by rw [sqrt_mul_sqrt_self a ha]; noncomm_ring + +end ConjSqrt + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/IntegralRepresentation.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/IntegralRepresentation.lean new file mode 100644 index 0000000000..3dfc767b46 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/IntegralRepresentation.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.IntegralRepresentation +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Integral +public import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ApproximateUnit + +/-! +# Operator convexity of the `(1, 2)` integrand + +`Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.IntegralRepresentation` now +contains the integral representation of `x ↦ x ^ p` (both the scalar and `cfcₙ` versions) for +`p ∈ (0, 1)` and `p ∈ (1, 2)`, together with the operator concavity of `rpowIntegrand₀₁`. The one +piece not (yet) upstream is the operator *convexity* of `rpowIntegrand₁₂` on `p ∈ (1, 2)`, proved +here the same way upstream proves operator concavity of `rpowIntegrand₀₁`: reduce to the `t = 1` +case via the rescaling identity, then relate `rpowIntegrand₁₂ p 1` to `1 - (1 + x)⁻¹` (whose +operator concavity is `CFC.concaveOn_one_sub_one_add_inv_real`) via `id - rpowIntegrand₁₂ p 1 = +(1 - (1+x)⁻¹)`-shaped subtraction. + +## Main results + +* `CFC.convexOn_cfcₙ_rpowIntegrand₁₂`: `rpowIntegrand₁₂ p t` is operator convex for all + `p` and all `t ∈ Ioi 0`. +-/ + +@[expose] public section + +open MeasureTheory Set Filter +open scoped NNReal Topology + +namespace CFC +open Real + +section NonUnitalCFC + +variable {A : Type*} [NonUnitalNormedRing A] [StarRing A] [NormedSpace ℝ A] [SMulCommClass ℝ A A] + [IsScalarTower ℝ A A] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] + [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] + +variable {p t x : ℝ} + +/-- The `t`-rescaling identity: `rpowIntegrand₁₂ p t x = t ^ (p - 1) · rpowIntegrand₁₂ p 1 (x/t)` +on `Ici 0` for `t > 0`. This is the key step in reducing operator convexity of the integrand at +general `t > 0` to the `t = 1` case. -/ +lemma rpowIntegrand₁₂_eqOn_mul_rpowIntegrand₁₂_one (ht : 0 < t) : + (Ici 0).EqOn (rpowIntegrand₁₂ p t) + (fun x ↦ t ^ (p - 1) * (rpowIntegrand₁₂ p 1 (t⁻¹ • x))) := by + intro x (hx : 0 ≤ x) + simp only [rpowIntegrand₁₂, smul_eq_mul, Real.one_rpow, one_mul, inv_one] + have ht' : t ≠ 0 := ht.ne' + have htx : (t + x) ≠ 0 := by positivity + have h1tx : (1 + t⁻¹ * x) ≠ 0 := by positivity + field_simp + +lemma continuousOn_rpowIntegrand₁₂_Ici (ht : 0 < t) : + ContinuousOn (rpowIntegrand₁₂ p t) (Ici 0) := + (continuousOn_rpowIntegrand₁₂_uncurry _ (fun _ a ↦ a)).uncurry_left t ht + +/-- Generic `cfcₙ`-rescaling: if `f` is pointwise equal to `c • g ∘ (t⁻¹ • ·)` on `Ici 0`, +`g` is continuous on `Ici 0` and vanishes at `0`, then `cfcₙ f a = c • cfcₙ g (t⁻¹ • a)` for +`0 ≤ a` and `0 < t`. -/ +private lemma cfcₙ_eq_smul_cfcₙ_smul_inv_of_eqOn + {f g : ℝ → ℝ} {t c : ℝ} (ht : 0 < t) + (h_eqOn : (Ici 0).EqOn f (fun x ↦ c * g (t⁻¹ • x))) + (h_cont : ContinuousOn g (Ici 0)) (hg0 : g 0 = 0) + (a : A) (ha : 0 ≤ a) : + cfcₙ f a = c • cfcₙ g (t⁻¹ • a) := by + have hspec : quasispectrum ℝ a ⊆ Ici 0 := by grind + have h_mapsTo : MapsTo (t⁻¹ • · : ℝ → ℝ) (Ici 0) (Ici 0) := by + intro x hx + simp only [mem_Ici, smul_eq_mul] at hx ⊢ + positivity + have h_cont_comp : ContinuousOn (fun x ↦ g (t⁻¹ • x)) (Ici 0) := + h_cont.comp (by fun_prop) h_mapsTo + calc _ = cfcₙ (fun x ↦ c * (g (t⁻¹ • x))) a := cfcₙ_congr (Set.EqOn.mono hspec h_eqOn) + _ = c • cfcₙ (fun x ↦ g (t⁻¹ • x)) a := by + refine cfcₙ_smul (R := ℝ) c _ a (h_cont_comp.mono hspec) ?_ + simpa using hg0 + _ = c • cfcₙ g (t⁻¹ • a) := by + congr! 1 + refine cfcₙ_comp_smul (R := ℝ) t⁻¹ g a + (h_cont.mono (h_mapsTo.mono_left hspec).image_subset) ?_ + simpa using hg0 + +lemma cfcₙ_rpowIntegrand₁₂_eq_cfcₙ_rpowIntegrand₁₂_one {p t : ℝ} (ht : 0 < t) + (a : A) (ha : 0 ≤ a) : + cfcₙ (rpowIntegrand₁₂ p t) a = t ^ (p - 1) • cfcₙ (rpowIntegrand₁₂ p 1) (t⁻¹ • a) := + cfcₙ_eq_smul_cfcₙ_smul_inv_of_eqOn ht (rpowIntegrand₁₂_eqOn_mul_rpowIntegrand₁₂_one ht) + (continuousOn_rpowIntegrand₁₂_Ici zero_lt_one) (rpowIntegrand₁₂_zero zero_lt_one) a ha + +end NonUnitalCFC + +section NonUnitalCStarAlgebra + +variable {A : Type*} [NonUnitalCStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + +/-- The `cfcₙ`-level decomposition at `t = 1`: `cfcₙ (rpowIntegrand₁₂ p 1) c = c - cfcₙ φ c` +where `φ x = 1 - (1 + x)⁻¹`. Lets the operator convexity of `rpowIntegrand₁₂ p 1` reduce to +the operator concavity of `φ` (`CFC.concaveOn_one_sub_one_add_inv_real`) via +`(c ↦ c) - (op-concave) = op-convex`. -/ +private lemma cfcₙ_rpowIntegrand₁₂_one_eq_sub (p : ℝ) (c : A) (hc : 0 ≤ c) : + cfcₙ (rpowIntegrand₁₂ p 1) c = c - cfcₙ (fun x : ℝ ↦ 1 - (1 + x)⁻¹) c := + calc cfcₙ (rpowIntegrand₁₂ p 1) c + = cfcₙ (fun x : ℝ ↦ x - (1 - (1 + x)⁻¹)) c := by + refine cfcₙ_congr fun x _ ↦ ?_ + simp only [Real.rpowIntegrand₁₂, Real.one_rpow, one_mul, inv_one] + ring + _ = cfcₙ (fun x : ℝ ↦ x) c - cfcₙ (fun x : ℝ ↦ 1 - (1 + x)⁻¹) c := by + refine cfcₙ_sub _ _ c (hg := ?_) + refine ContinuousOn.sub continuousOn_const (ContinuousOn.inv₀ (by fun_prop) fun x hx ↦ ?_) + have : (0 : ℝ) ≤ x := by grind + linarith + _ = c - cfcₙ (fun x : ℝ ↦ 1 - (1 + x)⁻¹) c := by rw [cfcₙ_id' ℝ c] + +/-- `rpowIntegrand₁₂ p t` is operator convex for all `p` and all `t ∈ Ioi 0`. -/ +lemma convexOn_cfcₙ_rpowIntegrand₁₂ {p : ℝ} {t : ℝ} (ht : 0 < t) : + ConvexOn ℝ (Ici (0 : A)) (cfcₙ (rpowIntegrand₁₂ p t)) := by + refine ⟨convex_Ici 0, fun a (ha : 0 ≤ a) b (hb : 0 ≤ b) α β hα hβ hαβ ↦ ?_⟩ + have hab : (0 : A) ≤ α • a + β • b := add_nonneg (smul_nonneg hα ha) (smul_nonneg hβ hb) + rw [cfcₙ_rpowIntegrand₁₂_eq_cfcₙ_rpowIntegrand₁₂_one ht a ha, + cfcₙ_rpowIntegrand₁₂_eq_cfcₙ_rpowIntegrand₁₂_one ht b hb, + cfcₙ_rpowIntegrand₁₂_eq_cfcₙ_rpowIntegrand₁₂_one ht (α • a + β • b) hab, + smul_comm α (t ^ (p - 1)), smul_comm β (t ^ (p - 1)), ← smul_add] + refine smul_le_smul_of_nonneg_left ?_ (by positivity) + rw [cfcₙ_rpowIntegrand₁₂_one_eq_sub p _ (by positivity), + cfcₙ_rpowIntegrand₁₂_one_eq_sub p _ (by positivity : (0 : A) ≤ t⁻¹ • a), + cfcₙ_rpowIntegrand₁₂_one_eq_sub p _ (by positivity : (0 : A) ≤ t⁻¹ • b), + smul_sub, smul_sub, sub_add_sub_comm, + smul_add, smul_comm t⁻¹ α a, smul_comm t⁻¹ β b, sub_le_sub_iff_left] + refine CFC.concaveOn_one_sub_one_add_inv_real.2 + (?_ : 0 ≤ t⁻¹ • a) (?_ : 0 ≤ t⁻¹ • b) hα hβ hαβ <;> positivity + +end NonUnitalCStarAlgebra + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Isometric.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Isometric.lean new file mode 100644 index 0000000000..2074a52542 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Isometric.lean @@ -0,0 +1,125 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Isometric +public import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Continuity +public import LeanPool.AxQM.ToMathlib.Analysis.Normed.Algebra.Spectrum + +/-! # Continuity of `rpow` in the exponent + +This file collects continuity results for `CFC.rpow` when the exponent, rather than the base, +varies: `a ^ y` is continuous (indeed continuous at every point) as a function of the real +exponent `y` for a strictly positive `a`, and consequently `a ^ (1 - p) * b ^ p` is continuous +in `p` and tends to `a` as `p → 0`. This last fact is the operator-level convergence underlying +Lindblad's limit form of the quantum relative entropy. +-/ + +public section + +open scoped NNReal Topology + +namespace CFC + +section unital + +variable {A : Type*} [NormedRing A] [StarRing A] [NormedAlgebra ℝ A] + [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] + [IsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint] + +open scoped ContinuousFunctionalCalculus in +/-- For a strictly positive element of a unital C⋆-algebra, the operator power `a ^ y` is +continuous in the real exponent `y` at every point. -/ +lemma continuousAt_const_rpow {a : A} (ha : IsStrictlyPositive a) {y₀ : ℝ} : + ContinuousAt (fun y : ℝ ↦ a ^ y) y₀ := by + have h0 : (0 : ℝ≥0) ∉ spectrum ℝ≥0 a := by + exact_mod_cast spectrum.zero_notMem ℝ ha.isUnit + refine continuousAt_cfc_fun ?_ + (.of_forall fun y _ hz ↦ (NNReal.continuousAt_rpow_const + (Or.inl fun hz0 ↦ h0 (hz0 ▸ hz))).continuousWithinAt) + rw [tendstoUniformlyOn_iff_restrict] + exact Continuous.tendstoUniformly _ (continuous_iff_continuousAt.mpr fun ⟨_, z⟩ ↦ + Filter.Tendsto.nnrpow (continuous_subtype_val.comp continuous_snd).continuousAt + continuous_fst.continuousAt (Or.inl fun heq ↦ h0 (heq ▸ z.2))) y₀ + +/-- For a strictly positive element of a unital C⋆-algebra, the operator power `a ^ y` is +continuous in the real exponent `y`. This is the companion to `continuousOn_rpow`, which varies +the base for a fixed exponent. -/ +lemma continuous_const_rpow {a : A} (ha : IsStrictlyPositive a) : + Continuous (fun y : ℝ ↦ a ^ y) := + continuous_iff_continuousAt.mpr fun _ ↦ continuousAt_const_rpow ha + +/-- For strictly positive elements `a, b` of a unital C⋆-algebra, the operator product +`a ^ (1 - p) * b ^ p` is continuous in the real exponent `p`. -/ +lemma continuous_rpow_one_sub_mul_rpow {a b : A} (ha : IsStrictlyPositive a) + (hb : IsStrictlyPositive b) : + Continuous (fun p : ℝ ↦ a ^ (1 - p) * b ^ p) := + ((continuous_const_rpow ha).comp (by fun_prop)).mul (continuous_const_rpow hb) + +open Filter in +/-- For strictly positive elements `a, b` of a unital C⋆-algebra, the operator product +`a ^ (1 - p) * b ^ p` converges to `a` as the real exponent `p` tends to `0`. + +This is the operator-level convergence underlying Lindblad's limit form of the quantum +relative entropy `H(a | b) = lim_{p → 0⁺} p⁻¹ · (Tr a - Tr (a ^ (1 - p) * b ^ p))`. -/ +lemma tendsto_rpow_one_sub_mul_rpow {a b : A} (ha : IsStrictlyPositive a) + (hb : IsStrictlyPositive b) : + Tendsto (fun p : ℝ ↦ a ^ (1 - p) * b ^ p) (𝓝 0) (𝓝 a) := by + simpa [CFC.rpow_one a ha.nonneg, CFC.rpow_zero b hb.nonneg] + using (continuous_rpow_one_sub_mul_rpow ha hb).tendsto 0 + +open Filter in +/-- **Regularization limit for the operator real power.** For a nonnegative element `a` and an +exponent `p ≥ 0`, the strictly-positive regularizations `(a + ε • 1) ^ p` converge to `a ^ p` as +`ε → 0⁺`. Whereas `continuousOn_rpow` varies the base over the *open* strictly-positive cone, this +approaches the *boundary* of the positive cone along the regularizing path `ε ↦ a + ε • 1`: since +`a + ε • 1 → a` and `x ↦ x ^ p` is continuous on the compact interval `[0, (‖a‖ + ‖1‖)‖1‖]` — which +contains the real spectrum of `a` and of every `a + ε • 1` (`0 < ε ≤ 1`) by +`spectrum.subset_Icc_norm_mul_of_nonneg` — `Filter.Tendsto.cfc` transports the convergence through +the continuous functional calculus, using `a ^ p = cfc (· ^ p) a` (`CFC.rpow_eq_cfc_real`). -/ +lemma tendsto_rpow_add_smul_one [ContinuousStar A] [CompleteSpace A] [PosSMulMono ℝ A] + {a : A} (ha : 0 ≤ a) {p : ℝ} (hp : 0 ≤ p) : + Tendsto (fun ε : ℝ => (a + ε • (1 : A)) ^ p) (𝓝[>] (0 : ℝ)) (𝓝 (a ^ p)) := by + have hone : (0 : ℝ) ≤ ‖(1 : A)‖ := norm_nonneg _ + have hf_cont : ContinuousOn (fun x : ℝ => x ^ p) (Set.Icc 0 ((‖a‖ + ‖(1 : A)‖) * ‖(1 : A)‖)) := + fun x _ => (Real.continuousAt_rpow_const x p (Or.inr hp)).continuousWithinAt + have h_elem : Tendsto (fun ε : ℝ => a + ε • (1 : A)) (𝓝[>] (0 : ℝ)) (𝓝 a) := by + have hc : Continuous (fun ε : ℝ => a + ε • (1 : A)) := by fun_prop + have h2 := hc.tendsto 0 + simp only [zero_smul, add_zero] at h2 + exact h2.mono_left nhdsWithin_le_nhds + have h1 : ∀ᶠ ε : ℝ in 𝓝[>] (0 : ℝ), ε ≤ 1 := by + filter_upwards [nhdsWithin_le_nhds (Iio_mem_nhds (by norm_num : (0 : ℝ) < 1))] with ε hε + exact le_of_lt hε + have h_nonneg_ev : ∀ᶠ ε : ℝ in 𝓝[>] (0 : ℝ), 0 ≤ a + ε • (1 : A) := by + filter_upwards [self_mem_nhdsWithin] with ε hε + exact add_nonneg ha (smul_nonneg (le_of_lt hε) zero_le_one) + have h_spec_ev : ∀ᶠ ε : ℝ in 𝓝[>] (0 : ℝ), + spectrum ℝ (a + ε • (1 : A)) ⊆ Set.Icc 0 ((‖a‖ + ‖(1 : A)‖) * ‖(1 : A)‖) := by + filter_upwards [h1, h_nonneg_ev, self_mem_nhdsWithin] with ε hε1 hn hεpos + refine (spectrum.subset_Icc_norm_mul_of_nonneg hn).trans (Set.Icc_subset_Icc_right ?_) + have hnorm : ‖a + ε • (1 : A)‖ ≤ ‖a‖ + ‖(1 : A)‖ := by + calc ‖a + ε • (1 : A)‖ ≤ ‖a‖ + ‖ε • (1 : A)‖ := norm_add_le _ _ + _ = ‖a‖ + ε * ‖(1 : A)‖ := by rw [norm_smul, Real.norm_of_nonneg (le_of_lt hεpos)] + _ ≤ ‖a‖ + ‖(1 : A)‖ := by nlinarith [hone] + exact mul_le_mul_of_nonneg_right hnorm hone + have h_sa_ev : ∀ᶠ ε : ℝ in 𝓝[>] (0 : ℝ), IsSelfAdjoint (a + ε • (1 : A)) := by + filter_upwards [h_nonneg_ev] with ε hn using hn.isSelfAdjoint + have h_spec_a : spectrum ℝ a ⊆ Set.Icc 0 ((‖a‖ + ‖(1 : A)‖) * ‖(1 : A)‖) := + (spectrum.subset_Icc_norm_mul_of_nonneg ha).trans (Set.Icc_subset_Icc_right + (mul_le_mul_of_nonneg_right (by nlinarith [hone]) hone)) + have key := Filter.Tendsto.cfc (X := ℝ) isCompact_Icc (fun x : ℝ => x ^ p) + h_elem h_spec_ev h_sa_ev h_spec_a ha.isSelfAdjoint + rw [← CFC.rpow_eq_cfc_real ha] at key + refine key.congr' ?_ + filter_upwards [h_nonneg_ev] with ε hn using (CFC.rpow_eq_cfc_real hn).symm + +end unital + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Order.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Order.lean new file mode 100644 index 0000000000..78230315ad --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Order.lean @@ -0,0 +1,116 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Order +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.IntegralRepresentation +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Abs +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic +public import Mathlib.MeasureTheory.Integral.Bochner.Basic +import Mathlib.Tactic.Module + +/-! +# Convexity of `CFC.rpow` on `[1, 2]`, and the `Y ≤ √Z` abs-detour + +`Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Order` now contains +`CFC.concaveOn_nnrpow`/`CFC.concaveOn_rpow` (operator concavity on `p ∈ [0,1]`). This file adds +the missing convexity companions on `p ∈ [1,2]`, plus the `√`-detour inequality: + ++ `CFC.convexOn_nnrpow`, `CFC.convexOn_rpow`: `a ↦ a ^ p` is operator convex on the + nonnegative cone for `p ∈ [1,2]` ++ `CFC.le_sqrt_of_mul_self_le`: for self-adjoint `Y` with `Y * Y ≤ Z`, `Y ≤ √Z`. + +## References + ++ [carlen2010] Eric A. Carlen, "Trace inequalities and quantum entropies: An introductory course" + (see Lemma 2.8) +-/ + +public section + +open Set +open scoped NNReal + +namespace CFC + +section NonUnitalCStarAlgebra + +variable {A : Type*} [NonUnitalCStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + +open Real MeasureTheory + +/-- This is an intermediate result; use the more general `CFC.convexOn_nnrpow` instead. -/ +private lemma convexOn_nnrpow_Ioo {p : ℝ≥0} (hp : p ∈ Ioo 1 2) : + ConvexOn ℝ (Ici (0 : A)) (fun a ↦ a ^ p) := by + obtain ⟨μ, hμ⟩ := CFC.exists_measure_nnrpow_eq_integral_cfcₙ_rpowIntegrand₁₂ A hp + have h₃' : (Ici 0).EqOn (fun a : A ↦ a ^ p) + (fun a : A ↦ ∫ t in Ioi 0, cfcₙ (rpowIntegrand₁₂ p t) a ∂μ) := + fun a ha ↦ (hμ a ha).2 + refine ConvexOn.congr ?_ h₃'.symm + refine integral_convexOn_of_integrand_ae (convex_Ici 0) ?_ fun a ha ↦ (hμ a ha).1 + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact convexOn_cfcₙ_rpowIntegrand₁₂ ht + +/-- `a ↦ a ^ p` is operator convex on the nonnegative cone for `p ∈ [1,2]`. -/ +lemma convexOn_nnrpow {p : ℝ≥0} (hp : p ∈ Icc 1 2) : + ConvexOn ℝ (Ici (0 : A)) (fun a ↦ a ^ p) := by + have hIcc : Icc (1 : ℝ≥0) 2 = Ioo 1 2 ∪ {1} ∪ {2} := by ext; simp + rw [hIcc] at hp + obtain (hp | hp) | hp := hp + · exact convexOn_nnrpow_Ioo hp + · simp only [mem_singleton_iff] at hp + subst hp + refine ⟨convex_Ici 0, fun a (ha : 0 ≤ a) b (hb : 0 ≤ b) α β hα hβ hαβ ↦ ?_⟩ + have hab : (0 : A) ≤ α • a + β • b := add_nonneg (smul_nonneg hα ha) (smul_nonneg hβ hb) + simp [nnrpow_one a, nnrpow_one b, nnrpow_one (α • a + β • b)] + · simp only [mem_singleton_iff] at hp + subst hp + refine ⟨convex_Ici 0, fun a (ha : 0 ≤ a) b (hb : 0 ≤ b) α β hα hβ hαβ ↦ ?_⟩ + have hab : (0 : A) ≤ α • a + β • b := add_nonneg (smul_nonneg hα ha) (smul_nonneg hβ hb) + beta_reduce + rw [nnrpow_two a, nnrpow_two b, nnrpow_two (α • a + β • b)] + calc (α • a + β • b) * (α • a + β • b) + = α • (a * a) + β • (b * b) - (α * β) • ((a - b) * (a - b)) := by + have h_sq : ((a - b : A) * (a - b)) = a * a - a * b - b * a + b * b := by noncomm_ring + have h_prod : (α • a + β • b) * (α • a + β • b) + = (α * α) • (a * a) + (α * β) • (a * b) + (β * α) • (b * a) + (β * β) • (b * b) := by + simp only [mul_add, add_mul, smul_mul_smul_comm]; abel + have hβα : β = 1 - α := by linarith + rw [h_sq, h_prod]; subst hβα; match_scalars <;> ring + _ ≤ α • (a * a) + β • (b * b) := sub_le_self _ <| smul_nonneg (mul_nonneg hα hβ) + (IsSelfAdjoint.sub ha.isSelfAdjoint hb.isSelfAdjoint).mul_self_nonneg + +end NonUnitalCStarAlgebra + +section UnitalCStarAlgebra + +variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + +/-- `a ↦ a ^ p` is operator convex on the nonnegative cone for `p ∈ [1,2]`. -/ +lemma convexOn_rpow {p : ℝ} (hp : p ∈ Icc 1 2) : + ConvexOn ℝ (Ici (0 : A)) (fun a ↦ a ^ p) := by + let q : ℝ≥0 := ⟨p, by linarith [hp.1]⟩ + change ConvexOn ℝ (Ici (0 : A)) (fun a ↦ a ^ (q : ℝ)) + have hq_pos : 0 < q := by change (0 : ℝ) < p; linarith [hp.1] + simp_rw [← CFC.nnrpow_eq_rpow hq_pos] + exact convexOn_nnrpow hp + +/-- Abs-detour: for self-adjoint `Y` with `Y * Y ≤ Z`, `Y ≤ √Z`. The argument routes via +`Y ≤ |Y| = √(Y²) ≤ √Z`. -/ +lemma le_sqrt_of_mul_self_le {Y Z : A} (hY : IsSelfAdjoint Y) (h : Y * Y ≤ Z) : + Y ≤ sqrt Z := + calc Y ≤ CFC.abs Y := by + rw [← sub_nonneg, CFC.abs_sub_self Y hY] + exact nsmul_nonneg (CFC.negPart_nonneg Y) 2 + _ = sqrt (Y * Y) := by rw [CFC.abs, hY.star_eq] + _ ≤ sqrt Z := sqrt_le_sqrt _ _ h + +end UnitalCStarAlgebra + +end CFC diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/RingInverseOrder.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/RingInverseOrder.lean new file mode 100644 index 0000000000..9d78efea8e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/RingInverseOrder.lean @@ -0,0 +1,48 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +import LeanPool.AxQM.ToMathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order +public import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.RingInverseOrder + +/-! +# `c ↦ Ring.inverse (s + c)` is operator convex on the nonnegative cone + +* `convexOn_ringInverse_add_of_isStrictlyPositive`: `c ↦ Ring.inverse (s + c)` is operator convex + on the nonnegative cone, for any strictly positive `s`. +* `convexOn_ringInverse_one_add`: `c ↦ Ring.inverse (1 + c)` is operator convex on the + nonnegative cone. +-/ + +namespace CStarAlgebra + +open CFC + +variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + +/-- The operator-convex function `c ↦ Ring.inverse (s + c)` on the nonnegative cone, for any +strictly positive `s`. Direct corollary of `convexOn_ringInverse` precomposed with the affine +shift `c ↦ s + c`, which maps the nonnegative cone into the strictly positive cone +(`IsStrictlyPositive s` plus `0 ≤ c` gives `IsStrictlyPositive (s + c)` via +`IsStrictlyPositive.add_nonneg`). -/ +public lemma convexOn_ringInverse_add_of_isStrictlyPositive {s : A} (hs : IsStrictlyPositive s) : + ConvexOn ℝ (Set.Ici (0 : A)) (fun c ↦ Ring.inverse (s + c)) := by + refine ⟨convex_Ici 0, fun a (ha : 0 ≤ a) b (hb : 0 ≤ b) α β hα hβ hαβ ↦ ?_⟩ + have hsab : s + (α • a + β • b) = α • (s + a) + β • (s + b) := by + rw [smul_add, smul_add, add_add_add_comm, ← add_smul, hαβ, one_smul] + change Ring.inverse (s + (α • a + β • b)) ≤ α • Ring.inverse (s + a) + β • Ring.inverse (s + b) + rw [hsab] + exact convexOn_ringInverse.2 (hs.add_nonneg ha) (hs.add_nonneg hb) hα hβ hαβ + +/-- The operator-convex function `c ↦ Ring.inverse (1 + c)` on the nonnegative cone. -/ +public lemma convexOn_ringInverse_one_add : + ConvexOn ℝ (Set.Ici (0 : A)) (fun c ↦ Ring.inverse (1 + c)) := + convexOn_ringInverse_add_of_isStrictlyPositive isStrictlyPositive_one + +end CStarAlgebra diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/DataProcessingInequality.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/DataProcessingInequality.lean new file mode 100644 index 0000000000..ac953c1ee5 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/DataProcessingInequality.lean @@ -0,0 +1,233 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy + +/-! +# The data processing inequality (Nielsen & Chuang, Theorem 11.5) + +For a tripartite distribution `p : ι × κ × μ → ℝ` of random variables `(X, Y, Z)`, this file proves +the **classical data processing inequality**: if `X → Y → Z` is a Markov chain, then +`H(X) ≥ H(X : Y) ≥ H(X : Z)`, where `H(X : Y)` is the mutual information. Intuitively, further +processing the output `Y` of a noisy channel cannot increase the information it carries about the +input `X`: once information is lost, it is gone forever. + +Reading `ι × κ × μ` as `ι × (κ × μ)`, the quantities are entropies / mutual informations of +marginals of `p` (from `ToMathlib/Analysis/SpecialFunctions/JointEntropy.lean`): + +* `H(X) = entropy (marginalFst p)`; +* `H(X : Y) = mutualInfo (marginalFstMid p)`, the mutual information of the `(X, Y)`-marginal; +* `H(X : Z) = mutualInfo (marginalFstLast p)`, of the `(X, Z)`-marginal `marginalFstLast` — the one + new marginal here (summing out the middle `Y`). + +## Main definitions and results + +* `Real.marginalFstLast` — the `(X, Z)`-marginal `p_{XZ}(x, z) = ∑_y p(x, y, z)`. +* `Real.IsMarkovChain` — `X → Y → Z` is a Markov chain: `X` and `Z` are conditionally independent + given `Y`, `p(x, y, z) · p_Y(y) = p_{XY}(x, y) · p_{YZ}(y, z)` (the division-free form of + `p(z | x, y) = p(z | y)`, N&C eq. (11.36)). The condition is symmetric in `X` and `Z`, so it also + expresses `Z → Y → X` (N&C Exercise 11.10). +* `Real.mutualInfo_marginalFstMid_le_marginalFst` — the first inequality `H(X : Y) ≤ H(X)` (needing + no Markov hypothesis), and `Real.mutualInfo_marginalFstMid_eq_marginalFst_iff` its saturation + condition: `H(X) = H(X : Y)` iff `X` is a deterministic function of `Y`, i.e. `X` is + reconstructible from `Y`. +* `Real.mutualInfo_marginalFstLast_le_marginalFstMid` — the data processing inequality proper, + `H(X : Z) ≤ H(X : Y)`, for a Markov chain. + +The DPI proper follows N&C's proof. Since `H(X : W) = H(X) − H(X | W)`, it reduces to +`H(X | Y) ≤ H(X | Z)`. The Markov property gives `H(X | Y) = H(X | Y, Z)` +(`condEntropy_marginalFstMid_eq_of_isMarkovChain`, as `p` equals its conditional-independence +reconstruction `condIndepProd p`), and conditioning-reduces-entropy (`Real.entropy_conditioning_le`, +applied to `p` with `Y` and `Z` swapped so that `Y` is conditioned away) gives +`H(X | Y, Z) ≤ H(X | Z)`. + +This is pure finite-probability real analysis on `p : ι × κ × μ → ℝ`; the statement of Theorem 11.5 +is in [upstream `AxQM/NC/Ch11/Theorem11_5.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Theorem11_5.lean). Entropy is in nats; the +inequalities are base-invariant, so this is a faithful reformulation of N&C's base-2 statement. +-/ + +@[expose] public section + +namespace Real + +variable {ι κ μ : Type*} [Fintype ι] [Fintype κ] [Fintype μ] + +/-! ### The `(X, Z)`-marginal -/ + +/-- The joint `(X, Z)`-marginal `p_{XZ}(x, z) = ∑_y p(x, y, z)` of a tripartite distribution, +obtained by summing out the middle variable `Y`. -/ +noncomputable def marginalFstLast (p : ι × κ × μ → ℝ) : ι × μ → ℝ := fun q ↦ ∑ y, p (q.1, y, q.2) + +omit [Fintype ι] [Fintype μ] in +theorem marginalFstLast_apply (p : ι × κ × μ → ℝ) (x : ι) (z : μ) : + marginalFstLast p (x, z) = ∑ y, p (x, y, z) := rfl + +omit [Fintype ι] [Fintype μ] in +/-- The `(X, Z)`-marginal of the reversed triple is the `(X, Z)`-marginal of the original with its +outer coordinates swapped: `(reverseTriple p)_{ZX}(z, x) = p_{XZ}(x, z)`. Completes the +`reverseTriple`-marginal family (`marginalMid_reverseTriple`, `marginalFstMid_reverseTriple`, +`marginalSnd_reverseTriple`), which live in `JointEntropy` beside their marginals; `marginalFstLast` +is defined here, so this member does too. -/ +theorem marginalFstLast_reverseTriple (p : ι × κ × μ → ℝ) (z : μ) (x : ι) : + marginalFstLast (reverseTriple p) (z, x) = marginalFstLast p (x, z) := by + simp only [marginalFstLast_apply, reverseTriple_apply] + +omit [Fintype ι] in +/-- The `(X, Y)`-marginal and the full distribution share the first marginal `p_X`: +`(p_{XY})_X = p_X`. -/ +theorem marginalFst_marginalFstMid (p : ι × κ × μ → ℝ) : + marginalFst (marginalFstMid p) = marginalFst p := by + funext x + simp only [marginalFst_apply, marginalFstMid_apply, Fintype.sum_prod_type] + +omit [Fintype ι] in +/-- The `(X, Z)`-marginal and the full distribution share the first marginal `p_X`: +`(p_{XZ})_X = p_X`. -/ +theorem marginalFst_marginalFstLast (p : ι × κ × μ → ℝ) : + marginalFst (marginalFstLast p) = marginalFst p := by + funext x + simp only [marginalFst_apply, marginalFstLast_apply, Fintype.sum_prod_type] + rw [Finset.sum_comm] + +/-! ### The Markov chain condition + +`Real.IsMarkovChain` (`X → Y → Z` a Markov chain: `X` and `Z` conditionally independent given `Y`, +N&C eq. (11.36) / Ex. 11.10) is defined upstream in +`ToMathlib.Analysis.SpecialFunctions.JointEntropy` (imported above) and reused here. -/ + +omit [Fintype κ] in +/-- For a Markov chain, the joint distribution equals its conditional-independence reconstruction +`p = condIndepProd p` (`condIndepProd p (x, y, z) = p_{XY}(x, y) · p_{YZ}(y, z) / p_Y(y)`). On the +`p_Y(y) = 0` fibre both sides vanish (`p ≤ p_Y = 0`, and `_ / 0 = 0`); elsewhere it is the Markov +identity divided by `p_Y(y)`. -/ +theorem eq_condIndepProd_of_isMarkovChain {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hm : IsMarkovChain p) : p = condIndepProd p := by + funext q + obtain ⟨x, y, z⟩ := q + simp only [condIndepProd] + rcases eq_or_ne (marginalMid p y) 0 with h | h + · rw [h, div_zero] + have hle : p (x, y, z) ≤ marginalMid p y := + le_trans (le_marginalSnd hp x (y, z)) + (le_marginalFst (fun w ↦ marginalSnd_nonneg hp w) y z) + exact le_antisymm (h ▸ hle) (hp _) + · rw [eq_div_iff h] + exact hm x y z + +/-! ### The first inequality `H(X : Y) ≤ H(X)` and its saturation -/ + +/-- **First inequality of the data processing inequality** (N&C Theorem 11.5): the mutual +information never exceeds the source entropy, `H(X : Y) ≤ H(X)`. This is +`H(X : Y) = H(X) − H(X | Y)` with the conditional entropy `H(X | Y) ≥ 0`; it needs no Markov +hypothesis. -/ +theorem mutualInfo_marginalFstMid_le_marginalFst {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) : + mutualInfo (marginalFstMid p) ≤ entropy (marginalFst p) := by + have h := condEntropy_nonneg (marginalFstMid_nonneg hp) + rw [condEntropy_eq] at h + rw [mutualInfo_eq, marginalFst_marginalFstMid] + linarith + +/-- **Saturation of the first inequality** (N&C Theorem 11.5, the "moreover"): `H(X) = H(X : Y)` if +and only if `X` is a deterministic function of `Y` — i.e. given `Y` one can reconstruct `X`. The +right-hand side `SndDeterminedByFst (fun w ↦ p_{XY}(w.2, w.1))` reads on the `(Y, X)`-marginal as +`∃ f, ∀ y x, p_{XY}(x, y) ≠ 0 → x = f y`. Obtained from +`mutualInfo_eq_marginalSnd_iff_sndDeterminedByFst` (N&C Theorem 11.3, part 2) applied to the +`(Y, X)`-marginal. -/ +theorem mutualInfo_marginalFstMid_eq_marginalFst_iff {p : ι × κ × μ → ℝ} [Nonempty ι] + (hp : ∀ q, 0 ≤ p q) : + mutualInfo (marginalFstMid p) = entropy (marginalFst p) ↔ + SndDeterminedByFst (fun w : κ × ι ↦ marginalFstMid p (w.2, w.1)) := by + have hqnn : ∀ w : κ × ι, 0 ≤ marginalFstMid p (w.2, w.1) := fun w ↦ marginalFstMid_nonneg hp _ + have key := mutualInfo_eq_marginalSnd_iff_sndDeterminedByFst + (p := fun w : κ × ι ↦ marginalFstMid p (w.2, w.1)) hqnn + rw [mutualInfo_swap (marginalFstMid p), marginalSnd_swap (marginalFstMid p), + marginalFst_marginalFstMid] at key + exact key + +/-! ### The data processing inequality `H(X : Z) ≤ H(X : Y)` -/ + +/-- **The Markov property equates two conditional entropies**: `H(X | Y) = H(X | Y, Z)`. Learning +`Z` in addition to `Y` reveals nothing further about `X`, because for a Markov chain `p` equals its +reconstruction `condIndepProd p`, so `D(p ‖ condIndepProd p) = 0`, i.e. strong subadditivity is +saturated (`relativeEntropy_condIndepProd`). -/ +theorem condEntropy_marginalFstMid_eq_of_isMarkovChain {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hm : IsMarkovChain p) : condEntropy (marginalFstMid p) = condEntropy p := by + have hpeq : p = condIndepProd p := eq_condIndepProd_of_isMarkovChain hp hm + have hzero : relativeEntropy p (condIndepProd p) = 0 := by + rw [← hpeq]; exact relativeEntropy_self p + rw [relativeEntropy_condIndepProd hp] at hzero + rw [condEntropy_eq, condEntropy_eq, marginalSnd_marginalFstMid] + linarith + +/-- **Conditioning on `Z` reduces the conditional entropy further**: `H(X | Y, Z) ≤ H(X | Z)`. +Obtained from `entropy_conditioning_le` (`H(X | Y, Z) ≤ H(X | Y)`) applied to `p` with the roles of +`Y` and `Z` swapped, so that `Z` is the middle variable and `Y` is conditioned away. -/ +theorem condEntropy_le_condEntropy_marginalFstLast {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ q, p q = 1) : condEntropy p ≤ condEntropy (marginalFstLast p) := by + have hp'_nn : ∀ q : ι × μ × κ, 0 ≤ (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) q := fun _ ↦ hp _ + have hp'_sum : ∑ q : ι × μ × κ, (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) q = 1 := by + rw [← hsum] + exact Fintype.sum_equiv ((Equiv.refl ι).prodCongr (Equiv.prodComm μ κ)) _ _ fun _ ↦ rfl + have hcond := entropy_conditioning_le hp'_nn hp'_sum + have he : entropy (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) = entropy p := by + rw [entropy_eq, entropy_eq] + exact Fintype.sum_equiv ((Equiv.refl ι).prodCongr (Equiv.prodComm μ κ)) _ _ fun _ ↦ rfl + have hsnd : marginalSnd (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) + = fun w : μ × κ ↦ marginalSnd p (w.2, w.1) := by + funext w + simp only [marginalSnd_apply] + have hcondp' : condEntropy (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) = condEntropy p := by + rw [condEntropy_eq, condEntropy_eq, he, hsnd, entropy_swap] + have hmfm : marginalFstMid (fun t : ι × μ × κ ↦ p (t.1, t.2.2, t.2.1)) = marginalFstLast p := by + funext w + obtain ⟨x, z⟩ := w + simp only [marginalFstMid_apply, marginalFstLast_apply] + rw [hcondp', hmfm] at hcond + exact hcond + +/-- **The data processing inequality** (N&C Theorem 11.5): for a Markov chain `X → Y → Z`, the +mutual information decreases along the chain, `H(X : Z) ≤ H(X : Y)`. Since +`H(X : W) = H(X) − H(X | W)`, this is `H(X | Y) ≤ H(X | Z)`, which combines the Markov equality +`H(X | Y) = H(X | Y, Z)` (`condEntropy_marginalFstMid_eq_of_isMarkovChain`) with +conditioning-reduces-entropy `H(X | Y, Z) ≤ H(X | Z)` +(`condEntropy_le_condEntropy_marginalFstLast`). -/ +theorem mutualInfo_marginalFstLast_le_marginalFstMid {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ q, p q = 1) (hm : IsMarkovChain p) : + mutualInfo (marginalFstLast p) ≤ mutualInfo (marginalFstMid p) := by + have key : condEntropy (marginalFstMid p) ≤ condEntropy (marginalFstLast p) := by + rw [condEntropy_marginalFstMid_eq_of_isMarkovChain hp hm] + exact condEntropy_le_condEntropy_marginalFstLast hp hsum + rw [condEntropy_eq, condEntropy_eq] at key + rw [mutualInfo_eq, mutualInfo_eq, marginalFst_marginalFstMid, marginalFst_marginalFstLast] + linarith + +/-- **The data processing inequality, second form.** For a Markov chain `X → Y → Z`, the +input–output mutual information is at most the intermediate–output mutual information, +`H(X : Z) ≤ H(Y : Z)`. The symmetric partner of `mutualInfo_marginalFstLast_le_marginalFstMid`: +apply that first form to the reversed triple `Z → Y → X` (`isMarkovChain_reverseTriple`) and +identify the marginals via the swap-invariance of mutual information (`mutualInfo_swap`). -/ +theorem mutualInfo_marginalFstLast_le_marginalSnd {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ q, p q = 1) (hm : IsMarkovChain p) : + mutualInfo (marginalFstLast p) ≤ mutualInfo (marginalSnd p) := by + have key := mutualInfo_marginalFstLast_le_marginalFstMid (p := reverseTriple p) + (fun t => hp _) (by rw [sum_reverseTriple]; exact hsum) (isMarkovChain_reverseTriple hm) + have e1 : marginalFstLast (reverseTriple p) + = fun w : μ × ι => marginalFstLast p (w.2, w.1) := by + funext w + obtain ⟨z, x⟩ := w + exact marginalFstLast_reverseTriple _ z x + have e2 : marginalFstMid (reverseTriple p) + = fun w : μ × κ => marginalSnd p (w.2, w.1) := by + funext w + obtain ⟨z, y⟩ := w + exact marginalFstMid_reverseTriple _ z y + rwa [e1, e2, mutualInfo_swap, mutualInfo_swap] at key + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/EntropySubadditive.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/EntropySubadditive.lean new file mode 100644 index 0000000000..bb1ac771de --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/EntropySubadditive.lean @@ -0,0 +1,228 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.MutualInformationMap +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ConditionalEntropyChain +public import Mathlib.Logic.Equiv.Fin.Basic + +/-! +# Subadditivity of the Shannon entropy of a tuple of random variables + +Building on the random-variable entropy development (`Real.entropyMap`, `Real.mutualInfoMap` and the +law `Real.law` of a random variable), this file proves the **subadditivity of the Shannon entropy** +in its `n`-variable form: for random variables `X₀, …, X_{n-1}` on a finite probability space, the +joint entropy is at most the sum of the marginal entropies, + +`H(X₀, …, X_{n-1}) ≤ ∑ᵢ H(Xᵢ)` (`Real.entropyMap_pi_le`). + +This is the `n`-fold generalization of the two-variable subadditivity `H(X, Y) ≤ H(X) + H(Y)` +(`Real.entropy_le_add_marginal`, Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Theorem 11.3), and is the entropy "single-letterization" step underlying the converse of Shannon's +noisy channel coding theorem (N&C Theorem 12.7): the output entropy `H(Y₁, …, Yₙ)` of `n` channel +uses is bounded by the sum `∑ᵢ H(Yᵢ)` of the per-use output entropies. + +## Model + +Random variables are modelled as functions `Xᵢ : Ω → α` on a common finite sample space `Ω` +carrying a probability weight `μ : Ω → ℝ`, exactly as in `Real.condEntropyMap` / +`Real.mutualInfoMap` and the chaining rule `Real.condEntropy_law_chain`. The entropy of a +random variable is +`Real.entropyMap μ X = H(X)`, the Shannon entropy of the push-forward law `Real.law μ X`; modelling +through a shared sample space makes the joint entropy `H(X₀, …, X_{n-1})` of an arbitrary tuple free +(just tuple the variables into `fun ω ↦ (fun i ↦ Xᵢ ω)`). + +## Main results + +* `Real.entropyMap_prod_le` — two-variable subadditivity `H(f, g) ≤ H(f) + H(g)` in the + random-variable form. +* `Real.mutualInfoMap_nonneg` — non-negativity of the mutual information `H(f : g) ≥ 0` (N&C + Theorem 11.3, part 5), an immediate corollary. +* `Real.entropyMap_pi_le` — the `n`-variable subadditivity `H(X₀, …, X_{n-1}) ≤ ∑ᵢ H(Xᵢ)`. +* `Real.entropy_le_sum_entropy_proj` — the coordinate subadditivity `H(Y) ≤ ∑ⱼ H(Yⱼ)` of the + entropy of a distribution on a finite product `Fin n → ι`, the explicit-distribution reading of + `Real.entropyMap_pi_le` (its coordinate marginals `law μ (·ⱼ)`). + +`entropy_le_sum_entropy_proj` is the output-entropy single-letterization ingredient for the converse +of Shannon's noisy channel coding theorem (N&C Theorem 12.7): the mutual information +`H(Xⁿ : Yⁿ) = H(Yⁿ) − H(Yⁿ | Xⁿ)` of `n` memoryless channel uses is bounded by combining the output +bound `H(Yⁿ) ≤ ∑ⱼ H(Yⱼ)` (here) with the noise-entropy factoring +`H(Yⁿ | Xⁿ = xⁿ) = ∑ⱼ H(q(·|xⱼ))` (`Real.entropy_pi_prod`, +`ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean`). + +## Design + +This is pure classical information theory — it quantifies over functions `μ : Ω → ℝ` and +`Xᵢ : Ω → α`, building on the `Real.entropyMap` / `Real.law` developments. Entropy is measured in +*nats* (natural logarithm), as elsewhere in the library; the inequality is base-independent, so +this is a faithful reformulation. + +The two-variable step reuses `Real.entropy_le_add_marginal` on the joint law `law μ (fun ω ↦ +(f ω, g ω))`, whose first and second marginals are the laws of `f` and `g` +(`Real.marginalFst_law_prod` / `Real.marginalSnd_law_prod`). The `n`-variable step is an induction +that peels off the first coordinate through `Fin.consEquiv` (a relabeling of the value alphabet, +under which the entropy of a law is invariant, `Real.entropy_law_congr_equiv`). +-/ + +@[expose] public section + +namespace Real + +variable {Ω : Type*} [Fintype Ω] + +/-! ### Basic properties of the law of a random variable -/ + +/-- The law of a random variable is nonnegative when the weight is: `law μ X x ≥ 0`. -/ +theorem law_nonneg {γ : Type*} [DecidableEq γ] {μ : Ω → ℝ} (hμ : ∀ ω, 0 ≤ μ ω) + (X : Ω → γ) (x : γ) : 0 ≤ law μ X x := + Finset.sum_nonneg fun ω _ => by split_ifs; exacts [hμ ω, le_refl 0] + +/-- The total mass of the law of a random variable equals the total mass of the weight: +`∑ₓ law μ X x = ∑_ω μ ω`. In particular the law of `X` under a probability weight is again a +probability distribution. -/ +theorem sum_law {γ : Type*} [Fintype γ] [DecidableEq γ] (μ : Ω → ℝ) (X : Ω → γ) : + ∑ x, law μ X x = ∑ ω, μ ω := by + simp only [law] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun ω _ => ?_ + simp + +/-- The entropy of a random variable is the Shannon entropy of its law: +`entropyMap μ f = entropy (law μ f)`. (Both unfold to the entropy of the same push-forward +distribution, so this is definitional.) -/ +theorem entropyMap_eq_entropy_law {β : Type*} [Fintype β] [DecidableEq β] + (μ : Ω → ℝ) (f : Ω → β) : entropyMap μ f = entropy (law μ f) := rfl + +/-- The law of the **identity** random variable is the distribution itself: `law μ id = μ`. The +push-forward of `μ` along `id` fixes each point, so `law μ id x = ∑_{ω : ω = x} μ ω = μ x`. -/ +theorem law_id [DecidableEq Ω] (μ : Ω → ℝ) : law μ (id : Ω → Ω) = μ := by + funext x + rw [law] + exact Fintype.sum_ite_eq' x μ + +/-- **Expectation under a push-forward law** (law of the unconscious statistician): +`∑ₓ (law μ X) x · f x = ∑_ω μ ω · f (X ω)` — the expectation of `f` under the law of `X` is the +`μ`-average of `f ∘ X`. Specializes to `Real.sum_law` at `f = 1`. -/ +theorem sum_law_mul {γ : Type*} [Fintype γ] [DecidableEq γ] (μ : Ω → ℝ) (X : Ω → γ) (f : γ → ℝ) : + ∑ x, law μ X x * f x = ∑ ω, μ ω * f (X ω) := by + simp only [law, Finset.sum_mul] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun ω _ => ?_ + simp_rw [ite_mul, zero_mul] + exact Fintype.sum_ite_eq (X ω) fun x => μ ω * f x + +/-- The first marginal of the joint law of `(X, Y)` is the law of `X`: +`marginalFst (law μ (X, Y)) = law μ X` (the companion of `Real.marginalSnd_law_prod`). -/ +theorem marginalFst_law_prod {ζ γ : Type*} [DecidableEq ζ] [Fintype γ] [DecidableEq γ] + (μ : Ω → ℝ) (X : Ω → ζ) (Y : Ω → γ) : + marginalFst (law μ (fun ω => (X ω, Y ω))) = law μ X := by + funext x + rw [marginalFst_apply] + simp only [law] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun ω _ => ?_ + have hfac : ∀ y, (if (X ω, Y ω) = (x, y) then μ ω else 0) + = if Y ω = y then (if X ω = x then μ ω else 0) else 0 := fun y => by + by_cases hx : X ω = x <;> by_cases hy : Y ω = y <;> simp [Prod.ext_iff, hx, hy] + rw [Finset.sum_congr rfl fun y _ => hfac y, Finset.sum_ite_eq] + simp + +/-! ### Subadditivity -/ + +/-- **Two-variable subadditivity** of the Shannon entropy in the random-variable form +(Nielsen & Chuang Theorem 11.3, part 4): for random variables `f`, `g` on a finite probability +space with weight `μ`, `H(f, g) ≤ H(f) + H(g)`. This is `Real.entropy_le_add_marginal` applied to +the joint law `law μ (f, g)`, whose marginals are the laws of `f` and `g`. -/ +theorem entropyMap_prod_le {β γ : Type*} [Fintype β] [DecidableEq β] [Fintype γ] [DecidableEq γ] + {μ : Ω → ℝ} (hμ0 : ∀ ω, 0 ≤ μ ω) (hμ1 : ∑ ω, μ ω = 1) (f : Ω → β) (g : Ω → γ) : + entropyMap μ (fun ω => (f ω, g ω)) ≤ entropyMap μ f + entropyMap μ g := by + have hp0 : ∀ q, 0 ≤ law μ (fun ω => (f ω, g ω)) q := fun q => law_nonneg hμ0 _ q + have hp1 : ∑ q, law μ (fun ω => (f ω, g ω)) q = 1 := by rw [sum_law]; exact hμ1 + have h := entropy_le_add_marginal hp0 hp1 + rw [marginalFst_law_prod, marginalSnd_law_prod] at h + simpa only [entropyMap_eq_entropy_law] using h + +/-- **Non-negativity of the mutual information** (Nielsen & Chuang Theorem 11.3, part 5) in the +random-variable form: `H(f : g) ≥ 0`. Immediate from two-variable subadditivity +(`Real.entropyMap_prod_le`). -/ +theorem mutualInfoMap_nonneg {β γ : Type*} [Fintype β] [DecidableEq β] [Fintype γ] [DecidableEq γ] + {μ : Ω → ℝ} (hμ0 : ∀ ω, 0 ≤ μ ω) (hμ1 : ∑ ω, μ ω = 1) (f : Ω → β) (g : Ω → γ) : + 0 ≤ mutualInfoMap μ f g := by + rw [mutualInfoMap_eq] + linarith [entropyMap_prod_le hμ0 hμ1 f g] + +/-- **Subadditivity of the Shannon entropy for `n` random variables**: for random variables +`X₀, …, X_{n-1}` on a finite probability space with weight `μ`, the joint entropy is at most the +sum of the individual entropies, + +`H(X₀, …, X_{n-1}) ≤ ∑ᵢ H(Xᵢ)`. + +This is the `n`-fold generalization of the two-variable subadditivity `Real.entropyMap_prod_le`, +proved by induction on `n`: the inductive step peels off `X₀` through `Fin.consEquiv` (leaving the +joint entropy unchanged, `Real.entropy_law_congr_equiv`) and applies the two-variable bound. It is +the entropy single-letterization underlying the converse of Shannon's noisy channel coding theorem +(N&C Theorem 12.7). -/ +theorem entropyMap_pi_le {α : Type*} [Fintype α] [DecidableEq α] + {μ : Ω → ℝ} (hμ0 : ∀ ω, 0 ≤ μ ω) (hμ1 : ∑ ω, μ ω = 1) : + ∀ {n : ℕ} (X : Fin n → Ω → α), + entropyMap μ (fun ω => fun i => X i ω) ≤ ∑ i, entropyMap μ (X i) := by + intro n + induction n with + | zero => + intro X + have hconst : (fun ω => fun i : Fin 0 => X i ω) = fun _ : Ω => (default : Fin 0 → α) := by + funext ω; exact Subsingleton.elim _ _ + have hz : entropyMap μ (fun ω => fun i : Fin 0 => X i ω) = 0 := by + rw [hconst, entropyMap_const μ hμ1] + exact le_of_eq (hz.trans (Fin.sum_univ_zero _).symm) + | succ n ih => + intro X + -- Peel off `X₀`: the tuple `(fun i ↦ Xᵢ)` is `Fin.consEquiv (X₀, (fun i ↦ X_{i+1}))`. + have hfun : (fun ω => fun i : Fin (n + 1) => X i ω) + = (fun ω => (Fin.consEquiv (fun _ : Fin (n + 1) => α)) + (X 0 ω, fun i : Fin n => X i.succ ω)) := by + funext ω; exact (Fin.cons_self_tail _).symm + have key : entropyMap μ (fun ω => fun i : Fin (n + 1) => X i ω) + = entropyMap μ (fun ω => (X 0 ω, fun i : Fin n => X i.succ ω)) := by + rw [entropyMap_eq_entropy_law, entropyMap_eq_entropy_law, hfun] + exact entropy_law_congr_equiv μ (Fin.consEquiv (fun _ : Fin (n + 1) => α)) + (fun ω => (X 0 ω, fun i : Fin n => X i.succ ω)) + rw [key] + calc entropyMap μ (fun ω => (X 0 ω, fun i : Fin n => X i.succ ω)) + ≤ entropyMap μ (X 0) + entropyMap μ (fun ω => fun i : Fin n => X i.succ ω) := + entropyMap_prod_le hμ0 hμ1 _ _ + _ ≤ entropyMap μ (X 0) + ∑ i : Fin n, entropyMap μ (X i.succ) := by + have := ih (fun i : Fin n => X i.succ); linarith + _ = ∑ i : Fin (n + 1), entropyMap μ (X i) := + (Fin.sum_univ_succ (fun i => entropyMap μ (X i))).symm + +/-! ### Coordinate subadditivity -/ + +/-- **Coordinate subadditivity of the Shannon entropy** (explicit-distribution form): for a +probability distribution `μ` on a finite product `Fin n → ι`, the entropy is at most the sum of the +entropies of its coordinate marginals `law μ (·ⱼ)`, + +`H(Y₀, …, Y_{n-1}) ≤ ∑ⱼ H(Yⱼ)`. + +This is the explicit-distribution reading of the random-variable subadditivity +`Real.entropyMap_pi_le`: apply it to the coordinate projections `Yⱼ = (·ⱼ)` on the sample space +`Fin n → ι` weighted by `μ`, whose own joint law is `μ` itself (`law μ id = μ`). It is the +output-entropy single-letterization step in the converse of Shannon's noisy channel coding theorem +(N&C Theorem 12.7): the entropy `H(Y₀, …, Y_{n-1})` of the `n`-use channel output is bounded by the +sum `∑ⱼ H(Yⱼ)` of the per-use output entropies. -/ +theorem entropy_le_sum_entropy_proj {ι : Type*} [Fintype ι] [DecidableEq ι] {n : ℕ} + {μ : (Fin n → ι) → ℝ} (hμ0 : ∀ y, 0 ≤ μ y) (hμ1 : ∑ y, μ y = 1) : + entropy μ ≤ ∑ j, entropy (law μ (fun y => y j)) := by + have key := entropyMap_pi_le hμ0 hμ1 (fun (j : Fin n) (y : Fin n → ι) => y j) + simp only [entropyMap_eq_entropy_law] at key + -- The joint law of the coordinate projections is `μ` itself (`law μ id = μ`). + have hlaw : law μ (fun y : Fin n → ι => fun i => y i) = μ := law_id μ + rwa [hlaw] at key + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/JointEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/JointEntropy.lean new file mode 100644 index 0000000000..0f55532b17 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/JointEntropy.lean @@ -0,0 +1,1148 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# Joint entropy, conditional entropy, and mutual information + +For finite types `ι`, `κ` and a joint distribution `p : ι × κ → ℝ` (a probability mass function +of a pair of random variables `(X, Y)` when `p ≥ 0` and `∑ p = 1`), this file develops the +elementary information-theoretic quantities built on `Real.entropy`: + +* the **marginals** `Real.marginalFst p x = ∑ y, p (x, y)` and + `Real.marginalSnd p y = ∑ x, p (x, y)` (the distributions of `X` and of `Y`); +* the **conditional entropy** `Real.condEntropy p = H(X, Y) - H(Y)` (`= H(X | Y)`); +* the **mutual information** `Real.mutualInfo p = H(X) + H(Y) - H(X, Y)` (`= H(X : Y)`); +* the **product of the marginals** `Real.indepProd p (x, y) = marginalFst p x * marginalSnd p y` + (the joint distribution `X`, `Y` would have if they were independent). + +The joint entropy `H(X, Y)` itself is just `Real.entropy p` for `p : ι × κ → ℝ`. + +## Main results + +These are the classical (Shannon) half of Nielsen & Chuang, Theorem 11.3 ("Basic properties of +Shannon entropy"). Entropy is measured in nats (natural log), as in `Real.entropy`. + +* `Real.entropy_swap`, `Real.mutualInfo_swap` — **symmetry** (part 1): `H(X, Y) = H(Y, X)` and + `H(X : Y) = H(Y : X)`. +* `Real.mutualInfo_eq_relativeEntropy` — the key identity `H(X : Y) = D(p ‖ p_X ⊗ p_Y)`, valid for + any `p ≥ 0`. Every subadditivity statement below is an instance of relative-entropy + non-negativity through this identity. +* `Real.relativeEntropy_indepProd_eq` — the same identity spelled out (Nielsen–Chuang Exercise + 11.5): `D(p ‖ p_X ⊗ p_Y) = H(X) + H(Y) - H(X, Y)`. +* `Real.entropy_le_add_marginal` — **subadditivity** (part 4): `H(X, Y) ≤ H(X) + H(Y)`. +* `Real.mutualInfo_nonneg` — `H(X : Y) ≥ 0` (part 5). +* `Real.condEntropy_le_marginalFst` — **conditioning reduces entropy** at the mutual-information + level: `H(X | Y) ≤ H(X)` (part 5). +* `Real.mutualInfo_eq_zero_iff`, `Real.entropy_add_marginal_eq_iff` — the **equality condition** for + parts 4/5: subadditivity is saturated iff `X` and `Y` are independent (`p = p_X ⊗ p_Y`). +* `Real.entropy_marginalFst_le`, `Real.entropy_marginalSnd_le` — **the joint entropy dominates each + marginal entropy** (part 3): `H(X) ≤ H(X, Y)` and `H(Y) ≤ H(X, Y)`. +* `Real.condEntropy_nonneg` — **non-negativity of the conditional entropy** (part 2): + `H(X | Y) ≥ 0`, whence `Real.mutualInfo_le_marginalSnd` gives `H(X : Y) ≤ H(Y)`. +* `Real.entropy_marginalFst_eq_iff_sndDeterminedByFst`, + `Real.mutualInfo_eq_marginalSnd_iff_sndDeterminedByFst` — the **equality condition** for parts + 2/3: `H(X) = H(X, Y)` (equivalently `H(X : Y) = H(Y)`) iff `Y` is a deterministic function of `X` + (`Real.SndDeterminedByFst`). + +`H(Y | X)` **as a relative entropy** (Nielsen & Chuang, Exercise 11.7), with `X` the conditioning +(first) variable so that `H(Y | X) = entropy p − entropy (marginalFst p)`: + +* `Real.entropy_sub_entropy_marginalFst_eq_relativeEntropy` — **the expression**: + `H(Y | X) = D(p ‖ Real.condEntropyRef p)`, where `condEntropyRef p (x, y) = p(x, y)² / p_X(x)`. +* `Real.relativeEntropy_condEntropyRef_nonneg` — **the deduction** `H(Y | X) ≥ 0`, from + nonnegativity of the relative entropy against the sub-normalized `condEntropyRef p`. +* `Real.relativeEntropy_condEntropyRef_eq_zero_iff` — **the equality condition**: `H(Y | X) = 0` iff + `Y` is a deterministic function of `X` (`Real.SndDeterminedByFst`). + +For a tripartite distribution `p : ι × κ × μ → ℝ` of `(X, Y, Z)` (read as `ι × (κ × μ)`, with `Y` +the shared middle variable), the remaining parts are developed on the same definitions, via the +conditional-independence reconstruction `Real.condIndepProd p (x, y, z) = p_{XY}(x, y)·p_{YZ}(y, z) +/ p_Y(y)`: + +* `Real.entropy_triple_add_marginal_le` — **strong subadditivity** (part 6; also N&C Exercise 11.6): + `H(X, Y, Z) + H(Y) ≤ H(X, Y) + H(Y, Z)`. +* `Real.entropy_triple_add_marginal_eq_iff` — the **equality condition** for part 6: strong + subadditivity is saturated iff `Z → Y → X` forms a Markov chain (`Real.IsMarkovChain`, + equivalently `X` and `Z` conditionally independent given `Y`). +* `Real.entropy_conditioning_le` — **conditioning reduces entropy** (part 7): + `H(X | Y, Z) ≤ H(X | Y)`. + +The namespace `Real.XorMutualInfo` records a concrete counterexample to the naive subadditivity of +the mutual information (Nielsen & Chuang, Exercise 11.8): for `X, Y` independent uniform bits and +`Z = X ⊕ Y`, `Real.XorMutualInfo.mutualInfo_xorDist_not_subadditive` shows +`H(X, Y : Z) ≰ H(X : Z) + H(Y : Z)`. +-/ + +@[expose] public section + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-! ### Marginals -/ + +/-- The first marginal `p_X(x) = ∑_y p(x, y)` of a joint distribution `p : ι × κ → ℝ`. -/ +noncomputable def marginalFst (p : ι × κ → ℝ) : ι → ℝ := fun x ↦ ∑ y, p (x, y) + +/-- The second marginal `p_Y(y) = ∑_x p(x, y)` of a joint distribution `p : ι × κ → ℝ`. -/ +noncomputable def marginalSnd (p : ι × κ → ℝ) : κ → ℝ := fun y ↦ ∑ x, p (x, y) + +omit [Fintype ι] in +theorem marginalFst_apply (p : ι × κ → ℝ) (x : ι) : marginalFst p x = ∑ y, p (x, y) := rfl + +omit [Fintype κ] in +theorem marginalSnd_apply (p : ι × κ → ℝ) (y : κ) : marginalSnd p y = ∑ x, p (x, y) := rfl + +omit [Fintype ι] in +theorem marginalFst_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) : 0 ≤ marginalFst p x := + Finset.sum_nonneg fun y _ ↦ hp (x, y) + +omit [Fintype κ] in +theorem marginalSnd_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (y : κ) : 0 ≤ marginalSnd p y := + Finset.sum_nonneg fun x _ ↦ hp (x, y) + +omit [Fintype ι] in +/-- Each cell is dominated by its first marginal: `p(x, y) ≤ p_X(x)`. -/ +theorem le_marginalFst {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) (y : κ) : + p (x, y) ≤ marginalFst p x := + Finset.single_le_sum (fun i _ ↦ hp (x, i)) (Finset.mem_univ y) + +omit [Fintype κ] in +/-- Each cell is dominated by its second marginal: `p(x, y) ≤ p_Y(y)`. -/ +theorem le_marginalSnd {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) (y : κ) : + p (x, y) ≤ marginalSnd p y := + Finset.single_le_sum (fun i _ ↦ hp (i, y)) (Finset.mem_univ x) + +/-- The first marginal has the same total mass as the joint distribution. -/ +theorem sum_marginalFst (p : ι × κ → ℝ) : ∑ x, marginalFst p x = ∑ q, p q := by + simp only [marginalFst_apply, ← Fintype.sum_prod_type] + +/-- The second marginal has the same total mass as the joint distribution. -/ +theorem sum_marginalSnd (p : ι × κ → ℝ) : ∑ y, marginalSnd p y = ∑ q, p q := by + simp only [marginalSnd_apply] + rw [Fintype.sum_prod_type, Finset.sum_comm] + +omit [Fintype ι] in +/-- A first marginal vanishes exactly when its whole fibre does (under nonnegativity). -/ +theorem marginalFst_eq_zero_iff {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) : + marginalFst p x = 0 ↔ ∀ y, p (x, y) = 0 := by + rw [marginalFst_apply, Finset.sum_eq_zero_iff_of_nonneg fun y _ ↦ hp (x, y)] + simp + +/-! ### Definitions of the derived quantities -/ + +/-- The conditional entropy `H(X | Y) = H(X, Y) - H(Y)` of a joint distribution. -/ +noncomputable def condEntropy (p : ι × κ → ℝ) : ℝ := entropy p - entropy (marginalSnd p) + +theorem condEntropy_eq (p : ι × κ → ℝ) : condEntropy p = entropy p - entropy (marginalSnd p) := rfl + +/-- The mutual information `H(X : Y) = H(X) + H(Y) - H(X, Y)` of a joint distribution. -/ +noncomputable def mutualInfo (p : ι × κ → ℝ) : ℝ := + entropy (marginalFst p) + entropy (marginalSnd p) - entropy p + +theorem mutualInfo_eq (p : ι × κ → ℝ) : + mutualInfo p = entropy (marginalFst p) + entropy (marginalSnd p) - entropy p := rfl + +omit [Fintype ι] in +/-- The first marginal `p ↦ (x ↦ ∑ y, p (x, y))` is a continuous function of the joint law. -/ +theorem continuous_marginalFst : Continuous (marginalFst : (ι × κ → ℝ) → (ι → ℝ)) := by + unfold marginalFst + exact continuous_pi fun x => continuous_finsetSum _ fun y _ => continuous_apply (x, y) + +omit [Fintype κ] in +/-- The second marginal `p ↦ (y ↦ ∑ x, p (x, y))` is a continuous function of the joint law. -/ +theorem continuous_marginalSnd : Continuous (marginalSnd : (ι × κ → ℝ) → (κ → ℝ)) := by + unfold marginalSnd + exact continuous_pi fun y => continuous_finsetSum _ fun x _ => continuous_apply (x, y) + +/-- The mutual information `p ↦ H(X : Y)` is a continuous function of the joint distribution. -/ +theorem continuous_mutualInfo : Continuous (mutualInfo : (ι × κ → ℝ) → ℝ) := by + unfold mutualInfo + exact ((continuous_entropy.comp continuous_marginalFst).add + (continuous_entropy.comp continuous_marginalSnd)).sub continuous_entropy + +/-- The product of the marginals `(p_X ⊗ p_Y)(x, y) = p_X(x) · p_Y(y)`: the joint distribution the +pair would have under independence. -/ +noncomputable def indepProd (p : ι × κ → ℝ) : ι × κ → ℝ := + fun q ↦ marginalFst p q.1 * marginalSnd p q.2 + +theorem indepProd_apply (p : ι × κ → ℝ) (q : ι × κ) : + indepProd p q = marginalFst p q.1 * marginalSnd p q.2 := rfl + +theorem indepProd_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (q : ι × κ) : 0 ≤ indepProd p q := + mul_nonneg (marginalFst_nonneg hp q.1) (marginalSnd_nonneg hp q.2) + +/-- The product of the marginals has total mass `(∑ p)²`. -/ +theorem sum_indepProd (p : ι × κ → ℝ) : + ∑ q, indepProd p q = (∑ x, marginalFst p x) * ∑ y, marginalSnd p y := by + simp only [indepProd_apply, Finset.sum_mul_sum, Fintype.sum_prod_type] + +/-- The support of the joint distribution lies in the support of the product of its marginals. -/ +theorem p_eq_zero_of_indepProd_eq_zero {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∀ q, indepProd p q = 0 → p q = 0 := by + rintro ⟨x, y⟩ h + rw [indepProd_apply, mul_eq_zero] at h + rcases h with h1 | h2 + · exact (marginalFst_eq_zero_iff hp x).mp h1 y + · rw [marginalSnd_apply, Finset.sum_eq_zero_iff_of_nonneg fun i _ ↦ hp (i, y)] at h2 + exact h2 x (Finset.mem_univ _) + +/-! ### Symmetry (N&C Theorem 11.3, part 1) -/ + +/-- **Symmetry of the joint entropy**: `H(X, Y) = H(Y, X)`. -/ +theorem entropy_swap (p : ι × κ → ℝ) : entropy (fun q : κ × ι ↦ p (q.2, q.1)) = entropy p := by + simp only [entropy_eq] + exact (Equiv.prodComm κ ι).sum_comp fun r ↦ negMulLog (p r) + +omit [Fintype κ] in +theorem marginalFst_swap (p : ι × κ → ℝ) : + marginalFst (fun q : κ × ι ↦ p (q.2, q.1)) = marginalSnd p := by + funext y; simp only [marginalFst_apply, marginalSnd_apply] + +omit [Fintype ι] in +theorem marginalSnd_swap (p : ι × κ → ℝ) : + marginalSnd (fun q : κ × ι ↦ p (q.2, q.1)) = marginalFst p := by + funext x; simp only [marginalFst_apply, marginalSnd_apply] + +/-- **Symmetry of the mutual information**: `H(X : Y) = H(Y : X)`. -/ +theorem mutualInfo_swap (p : ι × κ → ℝ) : + mutualInfo (fun q : κ × ι ↦ p (q.2, q.1)) = mutualInfo p := by + rw [mutualInfo_eq, mutualInfo_eq, marginalFst_swap, marginalSnd_swap, entropy_swap]; ring + +/-! ### Mutual information as a relative entropy -/ + +/-- Collapsing the joint sum `∑_{x,y} p(x, y) log p_X(x)` onto the first marginal. -/ +theorem sum_p_mul_log_marginalFst (p : ι × κ → ℝ) : + ∑ q : ι × κ, p q * Real.log (marginalFst p q.1) = + ∑ x, marginalFst p x * Real.log (marginalFst p x) := by + rw [Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun x _ ↦ ?_ + simp only [← Finset.sum_mul, ← marginalFst_apply] + +/-- Collapsing the joint sum `∑_{x,y} p(x, y) log p_Y(y)` onto the second marginal. -/ +theorem sum_p_mul_log_marginalSnd (p : ι × κ → ℝ) : + ∑ q : ι × κ, p q * Real.log (marginalSnd p q.2) = + ∑ y, marginalSnd p y * Real.log (marginalSnd p y) := by + rw [Fintype.sum_prod_type, Finset.sum_comm] + refine Finset.sum_congr rfl fun y _ ↦ ?_ + simp only [← Finset.sum_mul, ← marginalSnd_apply] + +/-- Splitting of the cross term `∑ p log (p_X ⊗ p_Y)` into the two marginal self-cross terms, +using that on the support of `p` both marginal factors are strictly positive. -/ +theorem sum_p_mul_log_indepProd {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∑ q, p q * Real.log (indepProd p q) = + (∑ x, marginalFst p x * Real.log (marginalFst p x)) + + ∑ y, marginalSnd p y * Real.log (marginalSnd p y) := by + have hsplit : ∀ q : ι × κ, p q * Real.log (indepProd p q) = + p q * Real.log (marginalFst p q.1) + p q * Real.log (marginalSnd p q.2) := by + rintro ⟨x, y⟩ + rcases eq_or_lt_of_le (hp (x, y)) with h0 | h0 + · simp [← h0] + · have hm1 : (0 : ℝ) < marginalFst p x := lt_of_lt_of_le h0 (le_marginalFst hp x y) + have hm2 : (0 : ℝ) < marginalSnd p y := lt_of_lt_of_le h0 (le_marginalSnd hp x y) + simp only [indepProd_apply, Real.log_mul hm1.ne' hm2.ne', mul_add] + calc ∑ q, p q * Real.log (indepProd p q) + = ∑ q : ι × κ, (p q * Real.log (marginalFst p q.1) + p q * Real.log (marginalSnd p q.2)) := + Finset.sum_congr rfl fun q _ ↦ hsplit q + _ = (∑ q, p q * Real.log (marginalFst p q.1)) + ∑ q, p q * Real.log (marginalSnd p q.2) := + Finset.sum_add_distrib + _ = _ := by rw [sum_p_mul_log_marginalFst, sum_p_mul_log_marginalSnd] + +/-- **Mutual information is a relative entropy**: `H(X : Y) = D(p ‖ p_X ⊗ p_Y)`. Valid for any +nonnegative `p` (no normalization needed). This is the identity through which N&C proves +subadditivity: `H(X : Y) = H(p(x, y) ‖ p(x) p(y))`. -/ +theorem mutualInfo_eq_relativeEntropy {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + mutualInfo p = relativeEntropy p (indepProd p) := by + rw [relativeEntropy_eq_sub, mutualInfo_eq, entropy_eq_neg_sum_mul_log p, + entropy_eq_neg_sum_mul_log (marginalFst p), entropy_eq_neg_sum_mul_log (marginalSnd p), + sum_p_mul_log_indepProd hp] + ring + +/-- **Subadditivity via a relative-entropy identity** (Nielsen & Chuang, Exercise 11.5): the +relative entropy of the joint distribution `p` against the product of its marginals is the excess +of the summed marginal entropies over the joint entropy, +`D(p ‖ p_X ⊗ p_Y) = H(X) + H(Y) - H(X, Y)`. This is precisely the identity N&C Exercise 11.5 asks +to establish, `H(p(x, y) ‖ p(x) p(y)) = H(p(x)) + H(p(y)) - H(p(x, y))`, written out through the +definition of the mutual information (`mutualInfo_eq_relativeEntropy` reads the same equality with +the right-hand side packaged as `mutualInfo p`). Valid for any nonnegative `p` (no normalization is +needed for the identity itself). Combined with non-negativity of the relative entropy it yields +subadditivity `H(X, Y) ≤ H(X) + H(Y)` (`entropy_le_add_marginal`), with equality iff `X` and `Y` +are independent (`entropy_add_marginal_eq_iff`) — the "deduce" half of the exercise. -/ +theorem relativeEntropy_indepProd_eq {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + relativeEntropy p (indepProd p) + = entropy (marginalFst p) + entropy (marginalSnd p) - entropy p := + (mutualInfo_eq_relativeEntropy hp).symm.trans (mutualInfo_eq p) + +/-- **Mixing identity for the mutual information.** Given weights `p : ι → ℝ` and a family of +conditional distributions `q : ι → κ → ℝ` (each `q x` a probability distribution, `∑ y, q x y = 1`), +the mutual information of the joint distribution `(x, y) ↦ p x * q x y` equals the `p`-average +of the relative entropies of the conditionals `q x` against the average distribution +`q_bar y = ∑ x', p x' * q x' y`: +`H(X : Y) = ∑ x, p x * D(q x ‖ q_bar)`. +This is the classical counterpart of the Holevo χ identity for the von Neumann entropy +(`∑ᵢ pᵢ S(ρᵢ ‖ μ) = S(μ) − ∑ᵢ pᵢ S(ρᵢ)`): reading `q x = p(· | x)` as the channel output for input +`x` and `q_bar = p_Y` as the average output, it says the mutual information between input and output +is the mean relative entropy of the conditional outputs to the average output. Only nonnegativity +of `p` and `q` and normalization of each `q x` are needed. -/ +theorem mutualInfo_eq_sum_mul_relativeEntropy + (p : ι → ℝ) (q : ι → κ → ℝ) + (hp : ∀ x, 0 ≤ p x) (hq : ∀ x y, 0 ≤ q x y) (hq1 : ∀ x, ∑ y, q x y = 1) : + mutualInfo (fun xy : ι × κ ↦ p xy.1 * q xy.1 xy.2) + = ∑ x, p x * relativeEntropy (q x) (fun y ↦ ∑ x', p x' * q x' y) := by + set joint : ι × κ → ℝ := fun xy ↦ p xy.1 * q xy.1 xy.2 with hjoint + set qbar : κ → ℝ := fun y ↦ ∑ x', p x' * q x' y with hqbar + have hjoint_nonneg : ∀ z, 0 ≤ joint z := fun z ↦ mul_nonneg (hp z.1) (hq z.1 z.2) + have hmF : marginalFst joint = p := by + funext x; rw [marginalFst_apply]; simp only [hjoint] + rw [← Finset.mul_sum, hq1 x, mul_one] + have hmS : marginalSnd joint = qbar := rfl + have hindep : indepProd joint = fun z ↦ p z.1 * qbar z.2 := by + funext z; rw [indepProd_apply, hmF, hmS] + rw [mutualInfo_eq_relativeEntropy hjoint_nonneg, relativeEntropy_eq, hindep, + Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun x _ ↦ ?_ + rw [relativeEntropy_eq, Finset.mul_sum] + refine Finset.sum_congr rfl fun y _ ↦ ?_ + simp only [hjoint] + rcases eq_or_lt_of_le (hp x) with hx | hx + · simp [← hx] + · rcases eq_or_lt_of_le (hq x y) with hxy | hxy + · rw [← hxy]; ring + · have hqbar_pos : 0 < qbar y := + lt_of_lt_of_le (mul_pos hx hxy) + (Finset.single_le_sum (f := fun x' ↦ p x' * q x' y) + (fun i _ ↦ mul_nonneg (hp i) (hq i y)) (Finset.mem_univ x)) + rw [Real.log_mul hx.ne' hxy.ne', Real.log_mul hx.ne' hqbar_pos.ne'] + ring + +/-- **Mutual information of a conditional joint as output entropy minus average conditional +entropy.** Given weights `p : ι → ℝ` and a family of conditional distributions `q : ι → κ → ℝ` +(each `q x` a probability distribution, `∑ y, q x y = 1`), the mutual information of the joint +distribution `(x, y) ↦ p x * q x y` is the entropy of the average output distribution +`q_bar y = ∑ x, p x * q x y` minus the `p`-weighted average of the conditional-output entropies: + +`H(X : Y) = H(Y) − ∑ x, p x · H(q x)` (equivalently `H(Y) − H(Y | X)`). + +This is the entropy-difference companion of `mutualInfo_eq_sum_mul_relativeEntropy` (which writes +the same mutual information as `∑ x, p x · D(q x ‖ q_bar)`), obtained from the definition +`mutualInfo p = H(p_X) + H(p_Y) − H(X, Y)` by evaluating the marginals of the conditional joint +(`p_X = p` since each `q x` normalizes, `p_Y = q_bar`) and the classical chain rule +`entropy_prod_mul` +(`H(X, Y) = H(X) + ∑ x, p x · H(q x)`). Only normalization of each `q x` is needed. It is the +classical counterpart of the Holevo χ ↔ mutual-information identity `χ = S(μ) − ∑ᵢ pᵢ S(ρᵢ)` under +the measure-and-record channel (Nielsen & Chuang Problem 12.1). -/ +theorem mutualInfo_prod_conditional (p : ι → ℝ) (q : ι → κ → ℝ) (hq : ∀ x, ∑ y, q x y = 1) : + mutualInfo (fun xy : ι × κ ↦ p xy.1 * q xy.1 xy.2) + = entropy (fun y ↦ ∑ x, p x * q x y) - ∑ x, p x * entropy (q x) := by + rw [mutualInfo_eq] + have hmF : marginalFst (fun xy : ι × κ ↦ p xy.1 * q xy.1 xy.2) = p := by + funext x; rw [marginalFst_apply]; dsimp only; rw [← Finset.mul_sum, hq x, mul_one] + have hmS : marginalSnd (fun xy : ι × κ ↦ p xy.1 * q xy.1 xy.2) = fun y ↦ ∑ x, p x * q x y := rfl + rw [hmF, hmS, entropy_prod_mul hq] + ring + +/-! ### Subadditivity and mutual-information non-negativity (N&C Theorem 11.3, parts 4 & 5) -/ + +/-- The mass condition feeding the relative-entropy comparison of `p` with `p_X ⊗ p_Y`. -/ +private theorem sum_p_eq_sum_indepProd {p : ι × κ → ℝ} (hsum : ∑ q, p q = 1) : + ∑ q, p q = ∑ q, indepProd p q := by + rw [sum_indepProd, sum_marginalFst, sum_marginalSnd, hsum, mul_one] + +/-- **Subadditivity of the Shannon entropy** (N&C Theorem 11.3, part 4): the joint entropy of a +probability distribution is at most the sum of its marginal entropies, +`H(X, Y) ≤ H(X) + H(Y)`. -/ +theorem entropy_le_add_marginal {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + entropy p ≤ entropy (marginalFst p) + entropy (marginalSnd p) := by + have h := relativeEntropy_nonneg_of_support_subset hp (indepProd_nonneg hp) + (p_eq_zero_of_indepProd_eq_zero hp) (sum_p_eq_sum_indepProd hsum) + rw [← mutualInfo_eq_relativeEntropy hp, mutualInfo_eq] at h + linarith + +/-- **Non-negativity of the mutual information** (N&C Theorem 11.3, part 5): `H(X : Y) ≥ 0`. -/ +theorem mutualInfo_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + 0 ≤ mutualInfo p := by + rw [mutualInfo_eq_relativeEntropy hp] + exact relativeEntropy_nonneg_of_support_subset hp (indepProd_nonneg hp) + (p_eq_zero_of_indepProd_eq_zero hp) (sum_p_eq_sum_indepProd hsum) + +/-- **Conditioning reduces entropy** (N&C Theorem 11.3, part 5): `H(X | Y) ≤ H(X)`. -/ +theorem condEntropy_le_marginalFst {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + condEntropy p ≤ entropy (marginalFst p) := by + have h := mutualInfo_nonneg hp hsum + rw [mutualInfo_eq] at h + rw [condEntropy_eq] + linarith + +/-- **Equality condition for subadditivity / mutual information** (N&C Theorem 11.3, parts 4 & 5): +`H(X : Y) = 0` iff `X` and `Y` are independent, i.e. `p = p_X ⊗ p_Y`. -/ +theorem mutualInfo_eq_zero_iff {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + mutualInfo p = 0 ↔ p = indepProd p := by + rw [mutualInfo_eq_relativeEntropy hp] + exact relativeEntropy_eq_zero_iff hp (indepProd_nonneg hp) + (p_eq_zero_of_indepProd_eq_zero hp) (sum_p_eq_sum_indepProd hsum) + +/-- Subadditivity `H(X, Y) ≤ H(X) + H(Y)` is saturated iff `X` and `Y` are independent. -/ +theorem entropy_add_marginal_eq_iff {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + entropy (marginalFst p) + entropy (marginalSnd p) = entropy p ↔ p = indepProd p := by + rw [← mutualInfo_eq_zero_iff hp hsum, mutualInfo_eq, sub_eq_zero] + +/-! ### Joint entropy dominates a marginal (N&C Theorem 11.3, parts 2 & 3) -/ + +/-- The gap between the joint entropy and the first marginal entropy, written out as a sum: +`H(X, Y) - H(X) = ∑_{x,y} p(x, y) (log p_X(x) - log p(x, y))`. A pure algebraic identity (valid for +any `p`); it is the workhorse behind both the part-3 inequality and its equality condition, and is +reused by the strong-subadditivity development. -/ +theorem entropy_sub_entropy_marginalFst_eq_sum (p : ι × κ → ℝ) : + entropy p - entropy (marginalFst p) + = ∑ q, p q * (Real.log (marginalFst p q.1) - Real.log (p q)) := by + rw [entropy_eq_neg_sum_mul_log p, entropy_eq_neg_sum_mul_log (marginalFst p), + ← sum_p_mul_log_marginalFst] + simp only [mul_sub] + rw [Finset.sum_sub_distrib]; ring + +omit [Fintype ι] in +/-- Each summand of `entropy_sub_entropy_marginalFst_eq_sum` is nonnegative: since +`p(x, y) ≤ p_X(x)` (`le_marginalFst`) the logarithmic difference is nonnegative, and the +`p(x, y) = 0` cells vanish. -/ +theorem entropy_sub_entropy_marginalFst_summand_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) + (q : ι × κ) : 0 ≤ p q * (Real.log (marginalFst p q.1) - Real.log (p q)) := by + rcases eq_or_lt_of_le (hp q) with h0 | h0 + · rw [← h0]; simp + · exact mul_nonneg h0.le (sub_nonneg.mpr (Real.log_le_log h0 (le_marginalFst hp q.1 q.2))) + +/-- **The joint entropy dominates the first marginal entropy** (N&C Theorem 11.3, part 3): +`H(X) ≤ H(X, Y)`. Equivalently the conditional entropy `H(Y | X) = H(X, Y) - H(X)` is nonnegative +(part 2). This is N&C's argument: the difference is a sum of nonnegative terms +(`entropy_sub_entropy_marginalFst_eq_sum` + `entropy_sub_entropy_marginalFst_summand_nonneg`). -/ +theorem entropy_marginalFst_le {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + entropy (marginalFst p) ≤ entropy p := by + rw [← sub_nonneg, entropy_sub_entropy_marginalFst_eq_sum] + exact Finset.sum_nonneg fun q _ ↦ entropy_sub_entropy_marginalFst_summand_nonneg hp q + +/-- **The joint entropy dominates the second marginal entropy** (N&C Theorem 11.3, part 3): +`H(Y) ≤ H(X, Y)`, obtained from `entropy_marginalFst_le` by symmetry. -/ +theorem entropy_marginalSnd_le {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + entropy (marginalSnd p) ≤ entropy p := by + have hp' : ∀ q : κ × ι, 0 ≤ (fun q : κ × ι ↦ p (q.2, q.1)) q := fun q ↦ hp (q.2, q.1) + calc entropy (marginalSnd p) + = entropy (marginalFst fun q : κ × ι ↦ p (q.2, q.1)) := by rw [marginalFst_swap] + _ ≤ entropy (fun q : κ × ι ↦ p (q.2, q.1)) := entropy_marginalFst_le hp' + _ = entropy p := entropy_swap p + +/-- **Non-negativity of the conditional entropy** (N&C Theorem 11.3, part 2; N&C Exercise 11.7): +`H(X | Y) = H(X, Y) - H(Y) ≥ 0`. Learning `Y` cannot leave a negative amount of uncertainty about +`X`. -/ +theorem condEntropy_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : 0 ≤ condEntropy p := by + rw [condEntropy_eq, sub_nonneg] + exact entropy_marginalSnd_le hp + +/-- **`H(X : Y) ≤ H(Y)`** (N&C Theorem 11.3, part 2): the mutual information never exceeds a +marginal entropy. Together with `mutualInfo_nonneg` this pins `0 ≤ H(X : Y) ≤ H(Y)`. -/ +theorem mutualInfo_le_marginalSnd {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + mutualInfo p ≤ entropy (marginalSnd p) := by + have := entropy_marginalFst_le hp + rw [mutualInfo_eq]; linarith + +/-- The second coordinate `Y` is a **deterministic function of the first** `X`: there is `f : ι → κ` +with `y = f x` on every cell of positive probability. This is the finite-support rendering of +Nielsen & Chuang's "`Y = f(X)`", the equality condition for parts 2 and 3 of Theorem 11.3. The name +is directional; the symmetric notion (`X` a function of `Y`) would be `FstDeterminedBySnd`. -/ +def SndDeterminedByFst (p : ι × κ → ℝ) : Prop := ∃ f : ι → κ, ∀ x y, p (x, y) ≠ 0 → y = f x + +/-- **Equality condition for `H(X) ≤ H(X, Y)`** (N&C Theorem 11.3, parts 2 & 3): the joint entropy +equals the first marginal entropy iff `Y` is a deterministic function of `X`. Equality forces every +term of the nonnegative sum `∑ p(x, y)(log p_X(x) - log p(x, y))` to vanish, i.e. each cell of +positive probability carries the whole fibre mass `p(x, y) = p_X(x)`; a fibre can then support only +a single `y`, which defines `f`. -/ +theorem entropy_marginalFst_eq_iff_sndDeterminedByFst {p : ι × κ → ℝ} [Nonempty κ] + (hp : ∀ q, 0 ≤ p q) : + entropy (marginalFst p) = entropy p ↔ SndDeterminedByFst p := by + classical + rw [eq_comm, ← sub_eq_zero, entropy_sub_entropy_marginalFst_eq_sum, + Finset.sum_eq_zero_iff_of_nonneg fun q _ ↦ entropy_sub_entropy_marginalFst_summand_nonneg hp q] + constructor + · intro hz + -- Each cell is either empty or carries the whole fibre mass. + have hcell : ∀ x y, p (x, y) = 0 ∨ p (x, y) = marginalFst p x := by + intro x y + rcases eq_or_lt_of_le (hp (x, y)) with h0 | h0 + · exact Or.inl h0.symm + · refine Or.inr ?_ + have h : p (x, y) * (Real.log (marginalFst p x) - Real.log (p (x, y))) = 0 := + hz (x, y) (Finset.mem_univ _) + have hlog : Real.log (marginalFst p x) = Real.log (p (x, y)) := + sub_eq_zero.mp ((mul_eq_zero.mp h).resolve_left h0.ne') + have hmpos : 0 < marginalFst p x := lt_of_lt_of_le h0 (le_marginalFst hp x y) + exact (Real.log_injOn_pos (Set.mem_Ioi.mpr hmpos) (Set.mem_Ioi.mpr h0) hlog).symm + -- Hence each `X`-fibre supports at most one `y`. + have huniq : ∀ x y₁ y₂, p (x, y₁) ≠ 0 → p (x, y₂) ≠ 0 → y₁ = y₂ := by + intro x y₁ y₂ h1 h2 + by_contra hne + have he1 : p (x, y₁) = marginalFst p x := (hcell x y₁).resolve_left h1 + have hzero : ∑ y ∈ (Finset.univ : Finset κ).erase y₁, p (x, y) = 0 := by + rw [Finset.sum_erase_eq_sub (Finset.mem_univ y₁), ← marginalFst_apply, ← he1, sub_self] + have hle : p (x, y₂) ≤ 0 := by + rw [← hzero] + exact Finset.single_le_sum (fun y _ ↦ hp (x, y)) + (Finset.mem_erase.mpr ⟨Ne.symm hne, Finset.mem_univ y₂⟩) + exact h2 (le_antisymm hle (hp (x, y₂))) + refine ⟨fun x ↦ if h : ∃ y, p (x, y) ≠ 0 then h.choose else Classical.arbitrary κ, ?_⟩ + intro x y hxy + have hex : ∃ y, p (x, y) ≠ 0 := ⟨y, hxy⟩ + simp only [dite_eq_left hex] + exact huniq x y hex.choose hxy hex.choose_spec + · rintro ⟨f, hf⟩ q - + obtain ⟨x, y⟩ := q + change p (x, y) * (Real.log (marginalFst p x) - Real.log (p (x, y))) = 0 + rcases eq_or_lt_of_le (hp (x, y)) with h0 | h0 + · rw [← h0]; simp + · have hyfx : y = f x := hf x y h0.ne' + have hmarg : marginalFst p x = p (x, y) := by + rw [marginalFst_apply] + refine Finset.sum_eq_single y (fun y' _ hy' ↦ ?_) + (fun hnot ↦ absurd (Finset.mem_univ y) hnot) + by_contra hpy' + exact hy' ((hf x y' hpy').trans hyfx.symm) + rw [hmarg]; ring + +/-- **Equality condition for `H(X : Y) ≤ H(Y)`** (N&C Theorem 11.3, part 2): the mutual information +equals the second marginal entropy iff `Y` is a deterministic function of `X`. -/ +theorem mutualInfo_eq_marginalSnd_iff_sndDeterminedByFst {p : ι × κ → ℝ} [Nonempty κ] + (hp : ∀ q, 0 ≤ p q) : + mutualInfo p = entropy (marginalSnd p) ↔ SndDeterminedByFst p := by + rw [mutualInfo_eq, ← entropy_marginalFst_eq_iff_sndDeterminedByFst hp] + constructor <;> intro h <;> linarith + +/-! ### Conditional entropy as a relative entropy (N&C Exercise 11.7) + +Nielsen & Chuang, Exercise 11.7 asks to express the conditional entropy `H(Y | X)` as a relative +entropy between two probability distributions, and to *deduce* `H(Y | X) ≥ 0` and its equality +condition from that expression — the conditional-entropy counterpart of Exercise 11.5, which reads +subadditivity off the mutual-information relative entropy `H(X : Y) = D(p ‖ p_X ⊗ p_Y)`. + +Writing `p : ι × κ → ℝ` for the joint distribution of `(X, Y)` with `X` the *conditioning* (first) +variable and `Y` the (second) variable, the conditional entropy is +`H(Y | X) = H(X, Y) − H(X) = entropy p − entropy (marginalFst p)`. The relative-entropy expression +is `H(Y | X) = D(p ‖ q)` for the reference `q(x, y) = p(x, y)² / p_X(x) = p_X(x) · p(y | x)²` +(`condEntropyRef`): on the support of `p`, `log q = 2 log p − log p_X`, so `D(p ‖ q)` collapses to +`∑ p(x, y) (log p_X(x) − log p(x, y))`, which is exactly `entropy_sub_entropy_marginalFst_eq_sum`. + +Unlike the mutual-information reference `p_X ⊗ p_Y`, this `q` is only a *sub*-probability +distribution — `∑ q ≤ ∑ p` (`sum_condEntropyRef_le`), from `∑_y p(x, y)² ≤ (∑_y p(x, y))² = p_X(x)²` +— so `H(Y | X) ≥ 0` is nonnegativity of the relative entropy against a sub-normalized reference +(`relativeEntropy_nonneg_of_sum_le`), and the equality condition `H(Y | X) = 0` iff `Y` is a +deterministic function of `X` is read off the same expression via the part-2/3 characterization +`entropy_marginalFst_eq_iff_sndDeterminedByFst`. -/ + +/-- The **reference distribution** realizing the conditional entropy `H(Y | X)` as a relative +entropy (Nielsen & Chuang, Exercise 11.7): `condEntropyRef p (x, y) = p(x, y)² / p_X(x)`, equal to +`p_X(x) · p(y | x)²` on the support of `p`. It is a *sub*-probability distribution +(`∑ ≤ ∑ p`, `sum_condEntropyRef_le`), and +`H(Y | X) = D(p ‖ condEntropyRef p)` (`entropy_sub_entropy_marginalFst_eq_relativeEntropy`). -/ +noncomputable def condEntropyRef (p : ι × κ → ℝ) : ι × κ → ℝ := + fun q ↦ p q ^ 2 / marginalFst p q.1 + +omit [Fintype ι] in +theorem condEntropyRef_apply (p : ι × κ → ℝ) (x : ι) (y : κ) : + condEntropyRef p (x, y) = p (x, y) ^ 2 / marginalFst p x := rfl + +omit [Fintype ι] in +theorem condEntropyRef_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (q : ι × κ) : + 0 ≤ condEntropyRef p q := + div_nonneg (sq_nonneg _) (marginalFst_nonneg hp q.1) + +omit [Fintype ι] in +/-- The support of the joint distribution lies in the support of `condEntropyRef p`: if the +reference vanishes at `(x, y)` then so does `p` — its numerator `p(x, y)²` vanishes, or its +denominator `p_X(x)` does (and then the whole `x`-fibre of `p` vanishes). -/ +theorem p_eq_zero_of_condEntropyRef_eq_zero {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∀ q, condEntropyRef p q = 0 → p q = 0 := by + rintro ⟨x, y⟩ h + rw [condEntropyRef_apply, div_eq_zero_iff] at h + rcases h with h1 | h2 + · exact sq_eq_zero_iff.mp h1 + · exact (marginalFst_eq_zero_iff hp x).mp h2 y + +/-- `condEntropyRef p` is a **sub-probability distribution**: `∑ condEntropyRef p ≤ ∑ p`. Per +`X`-fibre `∑_y p(x, y)² / p_X(x) ≤ p_X(x)`, since `∑_y p(x, y)² ≤ (∑_y p(x, y))² = p_X(x)²` +(`Finset.sum_sq_le_sq_sum_of_nonneg`); summing over `x` gives `∑_x p_X(x) = ∑ p`. -/ +theorem sum_condEntropyRef_le {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∑ q, condEntropyRef p q ≤ ∑ q, p q := by + rw [← sum_marginalFst p, Fintype.sum_prod_type] + refine Finset.sum_le_sum fun x _ ↦ ?_ + have hsum_sq : ∑ y, p (x, y) ^ 2 ≤ marginalFst p x ^ 2 := by + rw [marginalFst_apply] + exact Finset.sum_sq_le_sq_sum_of_nonneg fun y _ ↦ hp (x, y) + have hcref : ∑ y, condEntropyRef p (x, y) = (∑ y, p (x, y) ^ 2) / marginalFst p x := by + simp only [condEntropyRef_apply, div_eq_mul_inv, ← Finset.sum_mul] + rw [hcref] + rcases eq_or_lt_of_le (marginalFst_nonneg hp x) with hx | hx + · simp [← hx] + · rw [div_le_iff₀ hx, ← pow_two]; exact hsum_sq + +/-- **Conditional entropy as a relative entropy** (Nielsen & Chuang, Exercise 11.7): with `X` the +conditioning variable, the conditional entropy `H(Y | X) = H(X, Y) − H(X) = entropy p − +entropy (marginalFst p)` equals the classical relative entropy of the joint distribution against +`condEntropyRef p`, i.e. `H(Y | X) = D(p ‖ q)` with `q(x, y) = p(x, y)² / p_X(x)`. On the support +of `p` the reference log splits as `log q = 2 log p − log p_X`, so `D(p ‖ q)` reduces to +`∑ p(x, y)(log p_X(x) − log p(x, y))` — precisely `entropy_sub_entropy_marginalFst_eq_sum`. This is +the expression the exercise asks for, from which the two deductions below follow. -/ +theorem entropy_sub_entropy_marginalFst_eq_relativeEntropy {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + entropy p - entropy (marginalFst p) = relativeEntropy p (condEntropyRef p) := by + rw [entropy_sub_entropy_marginalFst_eq_sum, relativeEntropy_eq] + refine Finset.sum_congr rfl fun q _ ↦ ?_ + rcases eq_or_lt_of_le (hp q) with h0 | h0 + · simp [← h0, condEntropyRef] + · have hmpos : 0 < marginalFst p q.1 := lt_of_lt_of_le h0 (le_marginalFst hp q.1 q.2) + simp only [condEntropyRef] + rw [Real.log_div (pow_ne_zero 2 h0.ne') hmpos.ne', Real.log_pow] + push_cast; ring + +/-- **Non-negativity of the conditional entropy, via the relative-entropy expression** (Nielsen & +Chuang, Exercise 11.7): the relative entropy of the joint distribution against `condEntropyRef p` +is nonnegative, so — through `entropy_sub_entropy_marginalFst_eq_relativeEntropy` — the conditional +entropy `H(Y | X) = entropy p − entropy (marginalFst p) ≥ 0`. This is the exercise's deduction: +`condEntropyRef p` is a sub-probability distribution (`sum_condEntropyRef_le`) whose support +contains that of `p`, so nonnegativity is the sub-normalized Gibbs inequality +(`relativeEntropy_nonneg_of_sum_le`) — the same inequality as the direct `entropy_marginalFst_le`, +reached here by the relative-entropy route. -/ +theorem relativeEntropy_condEntropyRef_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + 0 ≤ relativeEntropy p (condEntropyRef p) := + relativeEntropy_nonneg_of_sum_le hp (condEntropyRef_nonneg hp) + (p_eq_zero_of_condEntropyRef_eq_zero hp) (sum_condEntropyRef_le hp) + +/-- **Equality condition for the conditional entropy** (Nielsen & Chuang, Exercise 11.7): the +relative-entropy expression `D(p ‖ condEntropyRef p) = H(Y | X)` vanishes if and only if `Y` is a +deterministic function of `X` (`SndDeterminedByFst p`). Read off the expression +(`entropy_sub_entropy_marginalFst_eq_relativeEntropy`) through the part-2/3 characterization +`entropy_marginalFst_eq_iff_sndDeterminedByFst`; equivalently, `H(Y | X) = 0` exactly when +conditioning on `X` removes all uncertainty about `Y`. -/ +theorem relativeEntropy_condEntropyRef_eq_zero_iff {p : ι × κ → ℝ} [Nonempty κ] + (hp : ∀ q, 0 ≤ p q) : + relativeEntropy p (condEntropyRef p) = 0 ↔ SndDeterminedByFst p := by + rw [← entropy_sub_entropy_marginalFst_eq_relativeEntropy hp, sub_eq_zero, eq_comm, + entropy_marginalFst_eq_iff_sndDeterminedByFst hp] + +/-! ### Strong subadditivity and conditioning-reduces-entropy (N&C Theorem 11.3, parts 6 & 7) + +For a tripartite distribution `p : ι × κ × μ → ℝ` of `(X, Y, Z)` — with `Y` the shared middle +variable — this section proves N&C Theorem 11.3(6), **strong subadditivity** +`H(X, Y, Z) + H(Y) ≤ H(X, Y) + H(Y, Z)`, and its rearrangement Theorem 11.3(7), +**conditioning reduces entropy** `H(X | Y, Z) ≤ H(X | Y)`. + +Reading `ι × κ × μ` as `ι × (κ × μ)` lets the joint `(Y, Z)`-marginal and the entropy `H(X | Y, Z)` +reuse the two-variable `marginalSnd`/`condEntropy`; only the `(X, Y)`-marginal (`marginalFstMid`, +summing out `Z`) and the middle `Y`-marginal (`marginalMid`) are new. Following N&C's proof of +subadditivity, the inequality is non-negativity of the relative entropy of `p` against the +reconstruction `condIndepProd p (x, y, z) = p(x, y) · p(y, z) / p(y)` — the distribution `(X, Y, Z)` +would have if `X` and `Z` were conditionally independent given `Y`. -/ + +variable {μ : Type*} [Fintype μ] + +/-- The joint `(X, Y)`-marginal `p_{XY}(x, y) = ∑_z p(x, y, z)` of a tripartite distribution, +obtained by summing out the third variable `Z`. -/ +noncomputable def marginalFstMid (p : ι × κ × μ → ℝ) : ι × κ → ℝ := fun q ↦ ∑ z, p (q.1, q.2, z) + +/-- The middle `Y`-marginal `p_Y(y) = ∑_{x,z} p(x, y, z)` of a tripartite distribution, defined as +the first marginal of the `(Y, Z)`-marginal `marginalSnd p` so that it inherits its two-variable +API. -/ +noncomputable def marginalMid (p : ι × κ × μ → ℝ) : κ → ℝ := marginalFst (marginalSnd p) + +omit [Fintype ι] [Fintype κ] in +theorem marginalFstMid_apply (p : ι × κ × μ → ℝ) (x : ι) (y : κ) : + marginalFstMid p (x, y) = ∑ z, p (x, y, z) := rfl + +omit [Fintype κ] in +theorem marginalMid_apply (p : ι × κ × μ → ℝ) (y : κ) : + marginalMid p y = ∑ z, marginalSnd p (y, z) := rfl + +omit [Fintype ι] [Fintype κ] in +theorem marginalFstMid_nonneg {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (w : ι × κ) : + 0 ≤ marginalFstMid p w := + Finset.sum_nonneg fun z _ ↦ hp (w.1, w.2, z) + +omit [Fintype κ] in +theorem marginalMid_nonneg {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (y : κ) : + 0 ≤ marginalMid p y := + marginalFst_nonneg (fun w ↦ marginalSnd_nonneg hp w) y + +omit [Fintype ι] [Fintype κ] in +/-- Each cell is dominated by its `(X, Y)`-marginal: `p(x, y, z) ≤ p_{XY}(x, y)`. -/ +theorem le_marginalFstMid {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) (y : κ) (z : μ) : + p (x, y, z) ≤ marginalFstMid p (x, y) := + Finset.single_le_sum (fun z' _ ↦ hp (x, y, z')) (Finset.mem_univ z) + +omit [Fintype κ] in +/-- The `(X, Y)`-marginal summed over `X` recovers the middle marginal: +`∑_x p_{XY}(x, y) = p_Y(y)`. -/ +theorem sum_marginalFstMid (p : ι × κ × μ → ℝ) (y : κ) : + ∑ x, marginalFstMid p (x, y) = marginalMid p y := by + rw [marginalMid_apply] + simp only [marginalFstMid_apply, marginalSnd_apply] + rw [Finset.sum_comm] + +omit [Fintype κ] in +/-- The second marginal of the `(X, Y)`-marginal is the middle marginal: +`(p_{XY})_Y = p_Y`. This is the bridge realizing `H(X | Y) = condEntropy p_{XY}`. -/ +theorem marginalSnd_marginalFstMid (p : ι × κ × μ → ℝ) : + marginalSnd (marginalFstMid p) = marginalMid p := by + funext y; rw [marginalSnd_apply, sum_marginalFstMid] + +/-- Reordering a sum over the triple to bring the middle variable outermost: +`∑_{x,y,z} f = ∑_y ∑_x ∑_z f`. -/ +theorem sum_triple_comm (f : ι × κ × μ → ℝ) : ∑ q, f q = ∑ y, ∑ x, ∑ z, f (x, y, z) := by + simp only [Fintype.sum_prod_type] + rw [Finset.sum_comm] + +/-- Collapsing a sum whose summand depends only on the second coordinate: +`∑_{(x,y)} p(x, y) g(y) = ∑_y p_Y(y) g(y)`. Generalizes `sum_p_mul_log_marginalSnd`. -/ +theorem sum_mul_of_snd (p : ι × κ → ℝ) (g : κ → ℝ) : + ∑ q : ι × κ, p q * g q.2 = ∑ y, marginalSnd p y * g y := by + rw [Fintype.sum_prod_type, Finset.sum_comm] + refine Finset.sum_congr rfl fun y _ ↦ ?_ + simp only [← Finset.sum_mul, ← marginalSnd_apply] + +/-- Collapsing a tripartite sum whose summand depends only on `(X, Y)` onto the `(X, Y)`-marginal: +`∑_{x,y,z} p(x, y, z) g(x, y) = ∑_{(x,y)} p_{XY}(x, y) g(x, y)`. -/ +theorem sum_mul_of_fstMid (p : ι × κ × μ → ℝ) (g : ι × κ → ℝ) : + ∑ q : ι × κ × μ, p q * g (q.1, q.2.1) = ∑ w : ι × κ, marginalFstMid p w * g w := by + rw [Fintype.sum_prod_type (f := fun w : ι × κ ↦ marginalFstMid p w * g w)] + simp only [Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun x _ ↦ Finset.sum_congr rfl fun y _ ↦ ?_ + simp only [← Finset.sum_mul, ← marginalFstMid_apply] + +/-- Collapsing `∑_{x,y,z} p(x, y, z) log p_Y(y)` onto the middle marginal, via `sum_mul_of_snd` +(collapse `X`) followed by the two-variable `sum_p_mul_log_marginalFst` on `marginalSnd p` +(collapse `Z`). -/ +theorem sum_p_mul_log_marginalMid (p : ι × κ × μ → ℝ) : + ∑ q, p q * Real.log (marginalMid p q.2.1) = + ∑ y, marginalMid p y * Real.log (marginalMid p y) := by + rw [sum_mul_of_snd p fun w : κ × μ ↦ Real.log (marginalMid p w.1)] + exact sum_p_mul_log_marginalFst (marginalSnd p) + +/-- The reconstruction `condIndepProd p (x, y, z) = p_{XY}(x, y) · p_{YZ}(y, z) / p_Y(y)`: the joint +distribution `(X, Y, Z)` would have if `X` and `Z` were conditionally independent given `Y` (the +`Z → Y → X` Markov reconstruction). Strong subadditivity is `D(p ‖ condIndepProd p) ≥ 0`. -/ +noncomputable def condIndepProd (p : ι × κ × μ → ℝ) : ι × κ × μ → ℝ := + fun q ↦ marginalFstMid p (q.1, q.2.1) * marginalSnd p q.2 / marginalMid p q.2.1 + +omit [Fintype κ] in +theorem condIndepProd_nonneg {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (q : ι × κ × μ) : + 0 ≤ condIndepProd p q := + div_nonneg (mul_nonneg (marginalFstMid_nonneg hp _) (marginalSnd_nonneg hp _)) + (marginalMid_nonneg hp _) + +omit [Fintype κ] in +/-- The support of the joint distribution lies in the support of the reconstruction: any vanishing +factor of `condIndepProd p (x, y, z)` forces `p(x, y, z) = 0` by marginal-mass domination. -/ +theorem p_eq_zero_of_condIndepProd_eq_zero {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∀ q, condIndepProd p q = 0 → p q = 0 := by + rintro ⟨x, y, z⟩ h + simp only [condIndepProd, div_eq_zero_iff, mul_eq_zero] at h + rcases h with (h1 | h2) | h3 + · exact le_antisymm (h1 ▸ le_marginalFstMid hp x y z) (hp _) + · exact le_antisymm (h2 ▸ le_marginalSnd hp x (y, z)) (hp _) + · exact le_antisymm + (h3 ▸ le_trans (le_marginalSnd hp x (y, z)) + (le_marginalFst (fun w ↦ marginalSnd_nonneg hp w) y z)) (hp _) + +/-- The reconstruction is a probability distribution: `∑ condIndepProd p = 1`. Per middle-fibre +`y`, the reconstruction sums to `(∑_x p_{XY})(∑_z p_{YZ}) / p_Y = p_Y·p_Y / p_Y = p_Y` (the +`p_Y(y) = 0` fibre vanishes by `_ / 0 = 0`); summing over `y` gives `∑_y p_Y(y) = ∑ p = 1`. -/ +theorem sum_condIndepProd {p : ι × κ × μ → ℝ} (hsum : ∑ q, p q = 1) : + ∑ q, condIndepProd p q = 1 := by + rw [sum_triple_comm] + have key : ∀ y : κ, ∑ x, ∑ z, condIndepProd p (x, y, z) = marginalMid p y := by + intro y + rcases eq_or_ne (marginalMid p y) 0 with h | h + · simp only [condIndepProd, h, div_zero, Finset.sum_const_zero] + · have hx : ∑ x, marginalFstMid p (x, y) = marginalMid p y := sum_marginalFstMid p y + have hz : ∑ z, marginalSnd p (y, z) = marginalMid p y := (marginalMid_apply p y).symm + simp only [condIndepProd, div_eq_mul_inv, ← Finset.sum_mul] + rw [← Finset.sum_mul_sum, hx, hz, mul_inv_cancel_right₀ h] + rw [Finset.sum_congr rfl fun y _ ↦ key y] + simp only [marginalMid] + rw [sum_marginalFst, sum_marginalSnd] + exact hsum + +/-- The three-way log split feeding the relative-entropy identity: on the support of `p`, all three +marginal factors of `condIndepProd` are strictly positive, so +`log(p_{XY} · p_{YZ} / p_Y) = log p_{XY} + log p_{YZ} - log p_Y`; summing and collapsing each term +gives the marginal self-cross sums. -/ +theorem sum_p_mul_log_condIndepProd {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∑ q, p q * Real.log (condIndepProd p q) = + (∑ w : ι × κ, marginalFstMid p w * Real.log (marginalFstMid p w)) + + (∑ w : κ × μ, marginalSnd p w * Real.log (marginalSnd p w)) + - ∑ y, marginalMid p y * Real.log (marginalMid p y) := by + have hsplit : ∀ q : ι × κ × μ, p q * Real.log (condIndepProd p q) = + p q * Real.log (marginalFstMid p (q.1, q.2.1)) + p q * Real.log (marginalSnd p q.2) + - p q * Real.log (marginalMid p q.2.1) := by + rintro ⟨x, y, z⟩ + rcases eq_or_lt_of_le (hp (x, y, z)) with h0 | h0 + · simp [← h0] + · have hxy : 0 < marginalFstMid p (x, y) := lt_of_lt_of_le h0 (le_marginalFstMid hp x y z) + have hyz : 0 < marginalSnd p (y, z) := lt_of_lt_of_le h0 (le_marginalSnd hp x (y, z)) + have hy : 0 < marginalMid p y := + lt_of_lt_of_le hyz (le_marginalFst (fun w ↦ marginalSnd_nonneg hp w) y z) + simp only [condIndepProd] + rw [Real.log_div (mul_pos hxy hyz).ne' hy.ne', Real.log_mul hxy.ne' hyz.ne'] + ring + calc ∑ q, p q * Real.log (condIndepProd p q) + = ∑ q : ι × κ × μ, (p q * Real.log (marginalFstMid p (q.1, q.2.1)) + + p q * Real.log (marginalSnd p q.2) - p q * Real.log (marginalMid p q.2.1)) := + Finset.sum_congr rfl fun q _ ↦ hsplit q + _ = (∑ q, p q * Real.log (marginalFstMid p (q.1, q.2.1))) + + (∑ q, p q * Real.log (marginalSnd p q.2)) + - ∑ q, p q * Real.log (marginalMid p q.2.1) := by + rw [Finset.sum_sub_distrib, Finset.sum_add_distrib] + _ = _ := by + rw [sum_mul_of_fstMid p fun w ↦ Real.log (marginalFstMid p w), sum_p_mul_log_marginalSnd p, + sum_p_mul_log_marginalMid p] + +/-- **The conditional mutual information as a relative entropy**: +`D(p ‖ condIndepProd p) = H(X, Y) + H(Y, Z) - H(Y) - H(X, Y, Z)`. This is the tripartite analogue +of `mutualInfo_eq_relativeEntropy`, and the identity through which strong subadditivity is an +instance of relative-entropy non-negativity. -/ +theorem relativeEntropy_condIndepProd {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) : + relativeEntropy p (condIndepProd p) + = entropy (marginalFstMid p) + entropy (marginalSnd p) - entropy (marginalMid p) + - entropy p := by + rw [relativeEntropy_eq_sub, sum_p_mul_log_condIndepProd hp, entropy_eq_neg_sum_mul_log p, + entropy_eq_neg_sum_mul_log (marginalFstMid p), entropy_eq_neg_sum_mul_log (marginalSnd p), + entropy_eq_neg_sum_mul_log (marginalMid p)] + ring + +/-- **Strong subadditivity of the Shannon entropy** (N&C Theorem 11.3, part 6; N&C Exercise 11.6): +for a tripartite probability distribution of `(X, Y, Z)`, +`H(X, Y, Z) + H(Y) ≤ H(X, Y) + H(Y, Z)`. Following N&C's subadditivity argument, this is +non-negativity of `D(p ‖ condIndepProd p)` (`relativeEntropy_nonneg_of_support_subset` through +`relativeEntropy_condIndepProd`): the reconstruction `condIndepProd p` is a probability distribution +(`sum_condIndepProd`) whose support contains that of `p`. -/ +theorem entropy_triple_add_marginal_le {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ q, p q = 1) : + entropy p + entropy (marginalMid p) ≤ entropy (marginalFstMid p) + entropy (marginalSnd p) := by + have hmass : ∑ q, p q = ∑ q, condIndepProd p q := by rw [hsum, sum_condIndepProd hsum] + have h := relativeEntropy_nonneg_of_support_subset hp (condIndepProd_nonneg hp) + (p_eq_zero_of_condIndepProd_eq_zero hp) hmass + rw [relativeEntropy_condIndepProd hp] at h + linarith + +/-- **Conditioning reduces entropy** (N&C Theorem 11.3, part 7): `H(X | Y, Z) ≤ H(X | Y)`. Learning +`Z` in addition to `Y` cannot increase the average uncertainty about `X`. Reading `ι × κ × μ` as +`ι × (κ × μ)`, `condEntropy p = H(X, Y, Z) - H(Y, Z) = H(X | Y, Z)` and +`condEntropy (marginalFstMid p) = H(X, Y) - H(Y) = H(X | Y)`; the inequality is the rearrangement of +strong subadditivity (`entropy_triple_add_marginal_le`). -/ +theorem entropy_conditioning_le {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) : + condEntropy p ≤ condEntropy (marginalFstMid p) := by + rw [condEntropy_eq, condEntropy_eq, marginalSnd_marginalFstMid] + linarith [entropy_triple_add_marginal_le hp hsum] + +/-! ### Equality in strong subadditivity: the Markov-chain condition (N&C Theorem 11.3, part 6) -/ + +omit [Fintype κ] in +/-- Each cell of a tripartite distribution is dominated by its middle marginal: +`p(x, y, z) ≤ p_Y(y)`. -/ +theorem le_marginalMid {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) (x : ι) (y : κ) (z : μ) : + p (x, y, z) ≤ marginalMid p y := + le_trans (le_marginalSnd hp x (y, z)) (le_marginalFst (fun w ↦ marginalSnd_nonneg hp w) y z) + +/-- `Z → Y → X` **forms a Markov chain** — equivalently, `X` and `Z` are conditionally independent +given `Y`. Written division-free as `p(x, y, z) · p_Y(y) = p_{XY}(x, y) · p_{YZ}(y, z)` for all +`x, y, z`: on the fibres with `p_Y(y) > 0` this rearranges to +`p(x, y, z) = p_{XY}(x, y)·p_{YZ}(y, z) / p_Y(y)`, i.e. `p(x, z | y) = p(x | y) p(z | y)` +(conditional independence); on the fibres with `p_Y(y) = 0` both sides vanish. The condition is +symmetric in `X` and `Z`, so it equally expresses the chain `X → Y → Z`. -/ +def IsMarkovChain (p : ι × κ × μ → ℝ) : Prop := + ∀ x y z, p (x, y, z) * marginalMid p y = marginalFstMid p (x, y) * marginalSnd p (y, z) + +omit [Fintype κ] in +/-- The Markov-chain condition is exactly agreement of `p` with its conditional-independence +reconstruction: `IsMarkovChain p ↔ p = condIndepProd p`. On the `p_Y(y) > 0` fibres it is the +cross-multiplication `p · p_Y = p_{XY} · p_{YZ} ↔ p = p_{XY}·p_{YZ}/p_Y`; on the `p_Y(y) = 0` fibres +`p`, `condIndepProd p`, and both sides of the factorization all vanish (by marginal-mass +domination). -/ +theorem isMarkovChain_iff_eq_condIndepProd {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) : + IsMarkovChain p ↔ p = condIndepProd p := by + constructor + · intro h + funext q + obtain ⟨x, y, z⟩ := q + rcases eq_or_ne (marginalMid p y) 0 with hy | hy + · have hpxyz : p (x, y, z) = 0 := le_antisymm (hy ▸ le_marginalMid hp x y z) (hp _) + simp only [condIndepProd, hy, div_zero, hpxyz] + · simp only [condIndepProd] + rw [eq_div_iff hy] + exact h x y z + · intro h x y z + rcases eq_or_ne (marginalMid p y) 0 with hy | hy + · have hyz : marginalSnd p (y, z) = 0 := + le_antisymm (hy ▸ le_marginalFst (fun w ↦ marginalSnd_nonneg hp w) y z) + (marginalSnd_nonneg hp _) + rw [hy, mul_zero, hyz, mul_zero] + · have hpe := congrFun h (x, y, z) + simp only [condIndepProd] at hpe + rw [eq_div_iff hy] at hpe + exact hpe + +/-- **Equality in strong subadditivity** (N&C Theorem 11.3, part 6): the strong-subadditivity +inequality `entropy_triple_add_marginal_le` is saturated, +`H(X, Y, Z) + H(Y) = H(X, Y) + H(Y, Z)`, if and only if `Z → Y → X` forms a Markov chain +(`IsMarkovChain p`, i.e. `X` and `Z` conditionally independent given `Y`). This is the equality half +of relative-entropy non-negativity applied to the conditional-independence reconstruction: +`D(p ‖ condIndepProd p) = 0 ↔ p = condIndepProd p` (`relativeEntropy_eq_zero_iff` through the +identity `relativeEntropy_condIndepProd`), and `p = condIndepProd p` is precisely the Markov +condition (`isMarkovChain_iff_eq_condIndepProd`). -/ +theorem entropy_triple_add_marginal_eq_iff {p : ι × κ × μ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ q, p q = 1) : + entropy p + entropy (marginalMid p) + = entropy (marginalFstMid p) + entropy (marginalSnd p) ↔ IsMarkovChain p := by + have hmass : ∑ q, p q = ∑ q, condIndepProd p q := by rw [hsum, sum_condIndepProd hsum] + have hz := relativeEntropy_eq_zero_iff hp (condIndepProd_nonneg hp) + (p_eq_zero_of_condIndepProd_eq_zero hp) hmass + rw [relativeEntropy_condIndepProd hp] at hz + rw [isMarkovChain_iff_eq_condIndepProd hp, ← hz] + constructor <;> intro h <;> linarith + +/-! ### Reversal symmetry of the Markov-chain condition (N&C Exercise 11.10) -/ + +/-- The joint distribution of the reversed triple `(Z, Y, X)`, obtained from the joint distribution +`p` of `(X, Y, Z)` by swapping the outer coordinates: `reverseTriple p (z, y, x) = p (x, y, z)`. +Reversing twice is the identity (`reverseTriple_reverseTriple`), so this is an involution on joint +distributions. -/ +def reverseTriple (p : ι × κ × μ → ℝ) : μ × κ × ι → ℝ := fun q ↦ p (q.2.2, q.2.1, q.1) + +omit [Fintype ι] [Fintype κ] [Fintype μ] in +/-- Value of the reversed distribution: `reverseTriple p (z, y, x) = p (x, y, z)`. -/ +theorem reverseTriple_apply (p : ι × κ × μ → ℝ) (z : μ) (y : κ) (x : ι) : + reverseTriple p (z, y, x) = p (x, y, z) := rfl + +omit [Fintype ι] [Fintype κ] [Fintype μ] in +/-- Reversing the outer coordinates twice restores the original distribution: +`reverseTriple (reverseTriple p) = p`. -/ +theorem reverseTriple_reverseTriple (p : ι × κ × μ → ℝ) : + reverseTriple (reverseTriple p) = p := rfl + +/-- Reversing the outer coordinates preserves total mass: `∑ reverseTriple p = ∑ p`, since it is a +reindexing of the sum along the outer-coordinate swap. -/ +theorem sum_reverseTriple (p : ι × κ × μ → ℝ) : ∑ t, reverseTriple p t = ∑ t, p t := + Fintype.sum_equiv + (Equiv.mk (fun t : μ × κ × ι => (t.2.2, t.2.1, t.1)) + (fun s : ι × κ × μ => (s.2.2, s.2.1, s.1)) (fun _ => rfl) (fun _ => rfl)) + _ _ (fun _ => rfl) + +omit [Fintype κ] in +/-- The middle `Y`-marginal is invariant under reversal: +`(reverseTriple p)_Y = p_Y`. -/ +theorem marginalMid_reverseTriple (p : ι × κ × μ → ℝ) : + marginalMid (reverseTriple p) = marginalMid p := by + funext y + simp only [marginalMid_apply, marginalSnd_apply, reverseTriple] + exact Finset.sum_comm + +omit [Fintype κ] [Fintype μ] in +/-- The `(X, Y)`-marginal of the reversed triple is the `(Y, Z)`-marginal of the original: +`(reverseTriple p)_{ZY}(z, y) = p_{YZ}(y, z)`. -/ +theorem marginalFstMid_reverseTriple (p : ι × κ × μ → ℝ) (z : μ) (y : κ) : + marginalFstMid (reverseTriple p) (z, y) = marginalSnd p (y, z) := by + simp only [marginalFstMid_apply, marginalSnd_apply, reverseTriple] + +omit [Fintype ι] [Fintype κ] in +/-- The `(Y, Z)`-marginal of the reversed triple is the `(X, Y)`-marginal of the original: +`(reverseTriple p)_{YX}(y, x) = p_{XY}(x, y)`. -/ +theorem marginalSnd_reverseTriple (p : ι × κ × μ → ℝ) (y : κ) (x : ι) : + marginalSnd (reverseTriple p) (y, x) = marginalFstMid p (x, y) := by + simp only [marginalSnd_apply, marginalFstMid_apply, reverseTriple] + +omit [Fintype κ] in +/-- **N&C Exercise 11.10**: if `X → Y → Z` is a Markov chain, then so is `Z → Y → X`. Since +`IsMarkovChain p` is the division-free conditional independence `X ⊥ Z ∣ Y`, symmetric in `X` and +`Z`, reversing the outer variables of the joint distribution preserves it: +`IsMarkovChain p → IsMarkovChain (reverseTriple p)`. The proof rewrites each marginal of +`reverseTriple p` in terms of the corresponding marginal of `p` (`marginalMid` is invariant, while +the `(X, Y)`- and `(Y, Z)`-marginals swap) and applies the Markov condition for `p` up to +commutativity of the product. -/ +theorem isMarkovChain_reverseTriple {p : ι × κ × μ → ℝ} (h : IsMarkovChain p) : + IsMarkovChain (reverseTriple p) := by + intro z y x + rw [marginalMid_reverseTriple, marginalFstMid_reverseTriple, marginalSnd_reverseTriple, + reverseTriple_apply] + exact (h x y z).trans (mul_comm _ _) + +omit [Fintype κ] in +/-- The Markov-chain condition is symmetric under reversing the outer variables: `Z → Y → X` is a +Markov chain if and only if `X → Y → Z` is. This is the two-way form of N&C Exercise 11.10, +immediate from `isMarkovChain_reverseTriple` and the involution `reverseTriple_reverseTriple`. -/ +theorem isMarkovChain_reverseTriple_iff {p : ι × κ × μ → ℝ} : + IsMarkovChain (reverseTriple p) ↔ IsMarkovChain p := by + refine ⟨fun h ↦ ?_, isMarkovChain_reverseTriple⟩ + exact reverseTriple_reverseTriple p ▸ isMarkovChain_reverseTriple h + +/-! ### Mutual information is not subadditive (Nielsen & Chuang, Exercise 11.8) + +A concrete counterexample to the naive subadditivity `H(X, Y : Z) ≤ H(X : Z) + H(Y : Z)` of the +mutual information. Take `X` and `Y` to be independent uniform bits and `Z = X ⊕ Y` (addition +modulo `2`). Individually, each of `X` and `Y` is independent of `Z`, so `H(X : Z) = H(Y : Z) = 0`; +but the pair `(X, Y)` *determines* `Z`, so `H(X, Y : Z) = H(Z) = log 2 > 0`. Hence the combined +system carries strictly more information about `Z` than the parts do separately, and subadditivity +fails. All three joint distributions are read off the single joint distribution `xorDist` of the +triple `(X, Y, Z)`. -/ + +namespace XorMutualInfo + +/-- The joint distribution of `(X, Y, Z)` for Nielsen & Chuang Exercise 11.8: `X` and `Y` are +independent uniform bits (values in `ZMod 2`) and `Z = X ⊕ Y` (addition modulo `2`). Each of the +four `(x, y)` combinations has probability `1/4` and forces `z = x + y`; the four inconsistent +triples have probability `0`. -/ +noncomputable def xorDist : ZMod 2 × ZMod 2 × ZMod 2 → ℝ := + fun q => if q.2.2 = q.1 + q.2.1 then (1 / 4 : ℝ) else 0 + +/-- The joint distribution of the *pair* `(X, Y)` against `Z`, obtained from `xorDist` by regrouping +the triple as `((X, Y), Z)`. Its mutual information is `H(X, Y : Z)`. -/ +noncomputable def xorDistPairZ : (ZMod 2 × ZMod 2) × ZMod 2 → ℝ := + fun q => xorDist (q.1.1, q.1.2, q.2) + +/-- The joint distribution of `(X, Z)`, the marginal of `xorDist` obtained by summing out `Y`. Its +mutual information is `H(X : Z)`. -/ +noncomputable def xorDistXZ : ZMod 2 × ZMod 2 → ℝ := fun q => ∑ y, xorDist (q.1, y, q.2) + +/-- The joint distribution of `(Y, Z)`, the marginal of `xorDist` obtained by summing out `X`. Its +mutual information is `H(Y : Z)`. -/ +noncomputable def xorDistYZ : ZMod 2 × ZMod 2 → ℝ := fun q => ∑ x, xorDist (x, q.1, q.2) + +/-- `xorDist` is nonnegative (a genuine probability mass function, with `sum_xorDist`). -/ +theorem xorDist_nonneg (q : ZMod 2 × ZMod 2 × ZMod 2) : 0 ≤ xorDist q := by + unfold xorDist; split <;> norm_num + +/-- The XOR-indicator sums to `1/4` over either summand: for fixed `a, c : ZMod 2` there is exactly +one `b` with `c = a + b` (namely `b = c - a`), so `∑ b, [c = a + b] · (1/4) = 1/4`. This is the +single cancellation fact underlying every marginal of `xorDist` (`z = x + y ↔ y = z - x`). -/ +theorem sum_ite_add_eq (a c : ZMod 2) : + (∑ b : ZMod 2, if c = a + b then (1 / 4 : ℝ) else 0) = 1 / 4 := by + have hcond : ∀ b : ZMod 2, (c = a + b) ↔ (b = c - a) := fun b => by + constructor <;> intro h <;> · rw [h]; ring + simp only [hcond] + rw [Finset.sum_ite_eq' Finset.univ (c - a) (fun _ => (1 / 4 : ℝ))]; simp + +/-- `xorDist` has total mass `1`: it is a probability distribution. -/ +theorem sum_xorDist : ∑ q, xorDist q = 1 := by + simp only [xorDist, Fintype.sum_prod_type] + have inner : ∀ x y : ZMod 2, (∑ z : ZMod 2, if z = x + y then (1 / 4 : ℝ) else 0) = 1 / 4 := + fun x y => by rw [Finset.sum_ite_eq' Finset.univ (x + y) (fun _ => (1 / 4 : ℝ))]; simp + rw [Finset.sum_congr rfl (fun x _ => Finset.sum_congr rfl (fun y _ => inner x y))] + simp [ZMod.card 2]; norm_num + +/-- Entropy of the uniform distribution on `ZMod 2 × ZMod 2` (four outcomes of mass `1/4`): +`H = 2 log 2` (`= log 4`, i.e. `2` bits). -/ +theorem entropy_const_quarter : + entropy (fun _ : ZMod 2 × ZMod 2 => (1 / 4 : ℝ)) = 2 * Real.log 2 := by + rw [show (1 / 4 : ℝ) = (Fintype.card (ZMod 2 × ZMod 2) : ℝ)⁻¹ by + rw [Fintype.card_prod, ZMod.card]; norm_num, + entropy_uniform, Fintype.card_prod, ZMod.card, + show ((2 * 2 : ℕ) : ℝ) = 2 ^ 2 by norm_num, Real.log_pow] + push_cast; ring + +/-- Entropy of the uniform distribution on `ZMod 2` (two outcomes of mass `1/2`): `H = log 2` +(one bit). -/ +theorem entropy_const_half : entropy (fun _ : ZMod 2 => (1 / 2 : ℝ)) = Real.log 2 := by + rw [show (1 / 2 : ℝ) = (Fintype.card (ZMod 2) : ℝ)⁻¹ by rw [ZMod.card]; norm_num, + entropy_uniform, ZMod.card]; norm_num + +/-- Each marginal of the uniform distribution on `ZMod 2 × ZMod 2` is the uniform distribution on +`ZMod 2`. -/ +theorem marginalFst_const_quarter : + marginalFst (fun _ : ZMod 2 × ZMod 2 => (1 / 4 : ℝ)) = fun _ => (1 / 2 : ℝ) := by + funext x + simp only [marginalFst_apply, Finset.sum_const, Finset.card_univ, ZMod.card 2, nsmul_eq_mul] + norm_num + +/-- Each marginal of the uniform distribution on `ZMod 2 × ZMod 2` is the uniform distribution on +`ZMod 2`. -/ +theorem marginalSnd_const_quarter : + marginalSnd (fun _ : ZMod 2 × ZMod 2 => (1 / 4 : ℝ)) = fun _ => (1 / 2 : ℝ) := by + funext x + simp only [marginalSnd_apply, Finset.sum_const, Finset.card_univ, ZMod.card 2, nsmul_eq_mul] + norm_num + +/-- The `(X, Z)` marginal of `xorDist` is the uniform distribution: `X` and `Z = X ⊕ Y` are +independent uniform bits (for each `(x, z)` there is exactly one `y` with `z = x + y`). -/ +theorem xorDistXZ_eq : xorDistXZ = fun _ => (1 / 4 : ℝ) := by + funext q; obtain ⟨x, z⟩ := q + simp only [xorDistXZ, xorDist] + exact sum_ite_add_eq x z + +/-- The `(Y, Z)` marginal of `xorDist` is the uniform distribution: `Y` and `Z = X ⊕ Y` are +independent uniform bits (for each `(y, z)` there is exactly one `x` with `z = x + y`). -/ +theorem xorDistYZ_eq : xorDistYZ = fun _ => (1 / 4 : ℝ) := by + funext q; obtain ⟨y, z⟩ := q + simp only [xorDistYZ, xorDist] + have hcomm : ∀ x : ZMod 2, + (if z = x + y then (1 / 4 : ℝ) else 0) = if z = y + x then (1 / 4 : ℝ) else 0 := + fun x => by rw [add_comm x y] + rw [Finset.sum_congr rfl (fun x _ => hcomm x)] + exact sum_ite_add_eq y z + +/-- The `(X, Y)`-marginal of `xorDistPairZ` is uniform on the four pairs (`X`, `Y` are independent +uniform bits), giving `H(X, Y) = 2 log 2`. -/ +theorem marginalFst_xorDistPairZ : marginalFst xorDistPairZ = fun _ => (1 / 4 : ℝ) := by + funext w; obtain ⟨x, y⟩ := w + simp only [marginalFst_apply, xorDistPairZ, xorDist] + rw [Finset.sum_ite_eq' Finset.univ (x + y) (fun _ => (1 / 4 : ℝ))]; simp + +/-- The `Z`-marginal of `xorDistPairZ` is uniform on `ZMod 2`, giving `H(Z) = log 2` (for each `z` +there are exactly two pairs `(x, y)` with `z = x + y`). -/ +theorem marginalSnd_xorDistPairZ : marginalSnd xorDistPairZ = fun _ => (1 / 2 : ℝ) := by + funext z + simp only [marginalSnd_apply, xorDistPairZ, xorDist, Fintype.sum_prod_type] + rw [Finset.sum_congr rfl (fun x _ => sum_ite_add_eq x z)] + simp [ZMod.card 2]; norm_num + +/-- The joint entropy `H(X, Y, Z) = H(X, Y) = 2 log 2`, since `Z` is a deterministic function of +`(X, Y)` (only the four consistent triples carry mass). -/ +theorem entropy_xorDistPairZ : entropy xorDistPairZ = 2 * Real.log 2 := by + rw [entropy_eq, Fintype.sum_prod_type] + have inner : ∀ w : ZMod 2 × ZMod 2, + (∑ z : ZMod 2, Real.negMulLog (xorDistPairZ (w, z))) = Real.negMulLog (1 / 4) := fun w => by + simp only [xorDistPairZ, xorDist, apply_ite Real.negMulLog, Real.negMulLog_zero] + rw [Finset.sum_ite_eq' Finset.univ (w.1 + w.2) (fun _ => Real.negMulLog (1 / 4))]; simp + rw [Finset.sum_congr rfl (fun w _ => inner w)] + -- the remaining `∑ w, negMulLog (1/4)` is exactly `entropy (fun _ ↦ 1/4)` on the pair type + exact entropy_const_quarter + +/-- `H(X : Z) = 0`: on its own, `X` carries no information about `Z = X ⊕ Y`. -/ +theorem mutualInfo_xorDistXZ : mutualInfo xorDistXZ = 0 := by + rw [mutualInfo_eq, xorDistXZ_eq, marginalFst_const_quarter, marginalSnd_const_quarter, + entropy_const_half, entropy_const_quarter]; ring + +/-- `H(Y : Z) = 0`: on its own, `Y` carries no information about `Z = X ⊕ Y`. -/ +theorem mutualInfo_xorDistYZ : mutualInfo xorDistYZ = 0 := by + rw [mutualInfo_eq, xorDistYZ_eq, marginalFst_const_quarter, marginalSnd_const_quarter, + entropy_const_half, entropy_const_quarter]; ring + +/-- `H(X, Y : Z) = log 2` (one bit): the pair `(X, Y)` *determines* `Z = X ⊕ Y`. -/ +theorem mutualInfo_xorDistPairZ : mutualInfo xorDistPairZ = Real.log 2 := by + rw [mutualInfo_eq, marginalFst_xorDistPairZ, marginalSnd_xorDistPairZ, + entropy_xorDistPairZ, entropy_const_quarter, entropy_const_half]; ring + +/-- **Mutual information is not subadditive** (Nielsen & Chuang, Exercise 11.8, eq. (11.34)): for +`X`, `Y` independent uniform bits and `Z = X ⊕ Y`, +`H(X, Y : Z) ≰ H(X : Z) + H(Y : Z)`, because +`H(X, Y : Z) = log 2 > 0 = 0 + 0 = H(X : Z) + H(Y : Z)`. The values are base-independent (a change +of logarithm base scales every term by the same positive factor), so the failure holds equally for +the base-`2` (bit) convention of N&C. -/ +theorem mutualInfo_xorDist_not_subadditive : + ¬ mutualInfo xorDistPairZ ≤ mutualInfo xorDistXZ + mutualInfo xorDistYZ := by + rw [mutualInfo_xorDistPairZ, mutualInfo_xorDistXZ, mutualInfo_xorDistYZ, add_zero] + exact not_le.mpr (Real.log_pos (by norm_num)) + +end XorMutualInfo + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/Basic.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/Basic.lean new file mode 100644 index 0000000000..d67a588927 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/Basic.lean @@ -0,0 +1,67 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.Log.Basic + +/-! +# Gibbs-style pointwise log bounds + +Pointwise bounds and identities on `Real.log` underlying the classical Gibbs/Klein inequality +(entropy ≤ cross-entropy). +-/ + +@[expose] public section + +noncomputable section + +namespace Real + +/-- **Gibbs-style pointwise bound**: `p * log (q / p) ≤ q - p` for `0 ≤ p`, `0 < q`. Underlying +real-analysis fact for classical Klein/Gibbs inequality (entropy ≤ cross-entropy) via +summation. Proof: `log_le_sub_one_of_pos` on `q / p`, multiplied by `p`; the `p = 0` case +collapses to `0 ≤ q`. -/ +lemma mul_log_div_le_sub_of_nonneg {p q : ℝ} (hp_nn : 0 ≤ p) (hq_pos : 0 < q) : + p * log (q / p) ≤ q - p := by + obtain rfl | hp_pos := hp_nn.eq_or_lt + · simpa using hq_pos.le + · calc p * log (q / p) + ≤ p * (q / p - 1) := + mul_le_mul_of_nonneg_left (log_le_sub_one_of_pos (div_pos hq_pos hp_pos)) hp_pos.le + _ = q - p := by field_simp + +/-- **Log-quotient identity for nonneg numerator**: `p * log (q / p) = p * log q - p * log p` +for `0 ≤ p`, `0 < q`. The `p = 0` case uses junk-zero (`Real.log 0 = 0`, `0 * _ = 0`); the +`p > 0` case is `Real.log_div`. Bridges KL-divergence form to entropy/cross-entropy form. -/ +lemma mul_log_div {p q : ℝ} (hp_nn : 0 ≤ p) (hq_pos : 0 < q) : + p * log (q / p) = p * log q - p * log p := by + obtain rfl | hp_pos := hp_nn.eq_or_lt + · simp + · rw [log_div hq_pos.ne' hp_pos.ne', mul_sub] + +/-- **Strict Gibbs-style pointwise bound**: `p * log (q / p) < q - p` for `0 ≤ p`, `0 < q` +whenever `p ≠ q`. The strict/equality companion to `Real.mul_log_div_le_sub_of_nonneg`: the +tangent bound `log x ≤ x - 1` is strict off `x = 1` (`Real.log_lt_sub_one_of_pos`), so the +pointwise Gibbs bound is strict unless `p = q` (with the `p = 0` case reducing to `0 < q`). This +is the per-term input to the equality condition of the classical Gibbs/Klein inequality +(`Real.relativeEntropy_eq_zero_iff`, Nielsen–Chuang Theorem 11.1). -/ +lemma mul_log_div_lt_sub_of_ne {p q : ℝ} (hp_nn : 0 ≤ p) (hq_pos : 0 < q) (hpq : p ≠ q) : + p * log (q / p) < q - p := by + obtain rfl | hp_pos := hp_nn.eq_or_lt + · simpa using hq_pos + · have hne : q / p ≠ 1 := by + intro hh + rw [div_eq_one_iff_eq hp_pos.ne'] at hh + exact hpq hh.symm + calc p * log (q / p) + < p * (q / p - 1) := + mul_lt_mul_of_pos_left (log_lt_sub_one_of_pos (div_pos hq_pos hp_pos) hne) hp_pos + _ = q - p := by field_simp + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/IntegralRepresentation.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/IntegralRepresentation.lean new file mode 100644 index 0000000000..2c5bd70c73 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/IntegralRepresentation.lean @@ -0,0 +1,138 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv +public import Mathlib.MeasureTheory.Integral.IntegralEqImproper + +/-! +# Integral representation of the real logarithm + +For `x > 0` the natural logarithm has the improper-integral representation + +`log x = ∫₀^∞ ((1 + s)⁻¹ - (x + s)⁻¹) ds`, + +a Frullani-type identity obtained by integrating the antiderivative +`s ↦ log (1 + s) - log (x + s) = log ((1 + s) / (x + s))`, which increases (for `x > 1`) or +decreases (for `x < 1`) from `-log x` at `s = 0` to `0` at `s → ∞`. The reference term `(1 + s)⁻¹` +regularises the otherwise non-integrable `(x + s)⁻¹` — their difference equals +`(x - 1) / ((1 + s)(x + s))`, decaying like `(x - 1) / s²` — and pins the value at the base point +`x = 1`, where both sides vanish. + +This is the scalar core of the operator-logarithm integral representation +`cfc Real.log A = ∫₀^∞ ((1 + s)⁻¹ • 1 - (A + s)⁻¹) ds` for a positive operator `A`: applied to each +eigenvalue `λ` of `A` it gives `log λ = ∫₀^∞ ((1 + s)⁻¹ - (λ + s)⁻¹) ds`, and the operator identity +follows by the spectral calculus. That operator representation, differentiated along a mixing line +via the resolvent derivative, is the analytic input of the second-derivative proof of concavity of +the von Neumann entropy (Nielsen & Chuang, *Quantum Computation and Quantum Information*, +Exercise 11.22). + +## Main results + +* `Real.hasDerivAt_log_add_sub_log_add` — the antiderivative `s ↦ log (1 + s) - log (x + s)` has + derivative `(1 + s)⁻¹ - (x + s)⁻¹` at every `s ≥ 0`. +* `Real.tendsto_log_add_sub_log_add_atTop` — that antiderivative tends to `0` at `+∞`. +* `Real.integrableOn_Ioi_inv_add_sub_inv_add` — the integrand `(1 + s)⁻¹ - (x + s)⁻¹` is integrable + on `(0, ∞)`. +* `Real.log_eq_integral_Ioi_inv_add_sub_inv_add` — the integral representation itself. +-/ + +@[expose] public section + +open MeasureTheory Filter Set +open scoped Topology + +namespace Real + +variable {x : ℝ} + +/-- The antiderivative `s ↦ log (1 + s) - log (x + s)` used in the integral representation of the +logarithm has derivative `(1 + s)⁻¹ - (x + s)⁻¹` at every `s ≥ 0` (assuming `x > 0`, so that both +`1 + s` and `x + s` stay away from `0`). -/ +theorem hasDerivAt_log_add_sub_log_add (hx : 0 < x) {s : ℝ} (hs : 0 ≤ s) : + HasDerivAt (fun t => Real.log (1 + t) - Real.log (x + t)) ((1 + s)⁻¹ - (x + s)⁻¹) s := by + have h1 : (0 : ℝ) < 1 + s := by linarith + have h2 : (0 : ℝ) < x + s := by linarith + have e1 : HasDerivAt (fun t : ℝ => 1 + t) 1 s := by + simpa using (hasDerivAt_id s).const_add (1 : ℝ) + have e2 : HasDerivAt (fun t : ℝ => x + t) 1 s := by + simpa using (hasDerivAt_id s).const_add x + have d1 : HasDerivAt (fun t : ℝ => Real.log (1 + t)) (1 + s)⁻¹ s := by + simpa only [one_div] using e1.log h1.ne' + have d2 : HasDerivAt (fun t : ℝ => Real.log (x + t)) (x + s)⁻¹ s := by + simpa only [one_div] using e2.log h2.ne' + exact d1.sub d2 + +/-- The antiderivative `s ↦ log (1 + s) - log (x + s)` tends to `0` as `s → +∞` (assuming `x > 0`), +because `(1 + s) / (x + s) → 1` and `log` is continuous at `1`. -/ +theorem tendsto_log_add_sub_log_add_atTop (hx : 0 < x) : + Tendsto (fun t => Real.log (1 + t) - Real.log (x + t)) atTop (nhds 0) := by + have hAt : Tendsto (fun t : ℝ => x + t) atTop atTop := + tendsto_atTop_add_const_left atTop x tendsto_id + have hinv : Tendsto (fun t : ℝ => (x + t)⁻¹) atTop (nhds 0) := hAt.inv_tendsto_atTop + have h0 : Tendsto (fun t : ℝ => (1 - x) * (x + t)⁻¹) atTop (nhds 0) := by + simpa using hinv.const_mul (1 - x) + have hr : Tendsto (fun t : ℝ => (1 + t) / (x + t)) atTop (nhds 1) := by + have h1 := h0.const_add (1 : ℝ) + rw [add_zero] at h1 + refine h1.congr' ?_ + filter_upwards [eventually_ge_atTop (0 : ℝ)] with t ht + have hne : x + t ≠ 0 := (show (0 : ℝ) < x + t by linarith).ne' + field_simp + ring + have hlog : Tendsto (fun t : ℝ => Real.log ((1 + t) / (x + t))) atTop (nhds 0) := by + have hc := (Real.continuousAt_log one_ne_zero).tendsto.comp hr + simpa [Function.comp_def, Real.log_one] using hc + refine hlog.congr' ?_ + filter_upwards [eventually_ge_atTop (0 : ℝ)] with t ht + have h1ne : (1 : ℝ) + t ≠ 0 := (show (0 : ℝ) < 1 + t by linarith).ne' + have h2ne : x + t ≠ 0 := (show (0 : ℝ) < x + t by linarith).ne' + rw [Real.log_div h1ne h2ne] + +/-- The integrand `s ↦ (1 + s)⁻¹ - (x + s)⁻¹` of the logarithm's integral representation is +integrable on `(0, ∞)` (assuming `x > 0`): although neither term is individually integrable, their +difference `(x - 1) / ((1 + s)(x + s))` decays like `(x - 1) / s²`. Proved from the monotonicity of +the antiderivative (its derivative has constant sign, `≥ 0` for `x ≥ 1` and `≤ 0` for `x ≤ 1`) +together with its finite limit at `+∞`. -/ +theorem integrableOn_Ioi_inv_add_sub_inv_add (hx : 0 < x) : + IntegrableOn (fun s => (1 + s)⁻¹ - (x + s)⁻¹) (Ioi 0) := by + have hcont : ContinuousWithinAt (fun t => Real.log (1 + t) - Real.log (x + t)) (Ici 0) 0 := + (hasDerivAt_log_add_sub_log_add hx le_rfl).continuousAt.continuousWithinAt + have hderiv : ∀ s ∈ Ioi (0 : ℝ), HasDerivAt (fun t => Real.log (1 + t) - Real.log (x + t)) + ((1 + s)⁻¹ - (x + s)⁻¹) s := fun s hs => hasDerivAt_log_add_sub_log_add hx (le_of_lt hs) + rcases le_total 1 x with hx1 | hx1 + · refine integrableOn_Ioi_deriv_of_nonneg hcont hderiv (fun s hs => ?_) + (tendsto_log_add_sub_log_add_atTop hx) + have hs0 : (0 : ℝ) < s := hs + have hle : (x + s)⁻¹ ≤ (1 + s)⁻¹ := (inv_le_inv₀ (by linarith) (by linarith)).mpr (by linarith) + linarith + · refine integrableOn_Ioi_deriv_of_nonpos hcont hderiv (fun s hs => ?_) + (tendsto_log_add_sub_log_add_atTop hx) + have hs0 : (0 : ℝ) < s := hs + have hle : (1 + s)⁻¹ ≤ (x + s)⁻¹ := (inv_le_inv₀ (by linarith) (by linarith)).mpr (by linarith) + linarith + +/-- **Integral representation of the logarithm.** For `x > 0`, + +`log x = ∫₀^∞ ((1 + s)⁻¹ - (x + s)⁻¹) ds`. + +The reference term `(1 + s)⁻¹` makes the improper integral converge and fixes the constant so that +the value is exactly `log x` (in particular both sides vanish at `x = 1`). See the module docstring +for the operator-logarithm application. -/ +theorem log_eq_integral_Ioi_inv_add_sub_inv_add (hx : 0 < x) : + Real.log x = ∫ s in Ioi (0 : ℝ), ((1 + s)⁻¹ - (x + s)⁻¹) := by + have hcont : ContinuousWithinAt (fun t => Real.log (1 + t) - Real.log (x + t)) (Ici 0) 0 := + (hasDerivAt_log_add_sub_log_add hx le_rfl).continuousAt.continuousWithinAt + have hval := integral_Ioi_of_hasDerivAt_of_tendsto hcont + (fun s hs => hasDerivAt_log_add_sub_log_add hx (le_of_lt hs)) + (integrableOn_Ioi_inv_add_sub_inv_add hx) (tendsto_log_add_sub_log_add_atTop hx) + rw [hval] + simp + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/NegMulLog.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/NegMulLog.lean new file mode 100644 index 0000000000..9aebd4cfe1 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/NegMulLog.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog + +/-! +# Additional lemmas about `Real.negMulLog` + +The zero-set of `negMulLog` on `[0, ∞)`, the inverse and finite product/power expansions. +-/ + +@[expose] public section + +namespace Real + +/-- On `[0, ∞)` the function `negMulLog x = -x * log x` vanishes **exactly** at `x = 0` and `x = 1` +— the two roots of `-x log x`: at `x = 0` the factor `x` vanishes, at `x = 1` the factor `log x` +does, and elsewhere on `[0, ∞)` both factors are nonzero. (The hypothesis `0 ≤ x` rules out the +third root `x = -1` of `log`.) -/ +theorem negMulLog_eq_zero {x : ℝ} (hx : 0 ≤ x) : negMulLog x = 0 ↔ x = 0 ∨ x = 1 := by + refine ⟨fun hz => ?_, fun h => h.elim (fun h => by rw [h, negMulLog_zero]) + (fun h => by rw [h, negMulLog_one])⟩ + simp only [negMulLog_eq_neg, neg_eq_zero, mul_eq_zero] at hz + rcases hz with h | hlog + · exact Or.inl h + · rcases Real.log_eq_zero.mp hlog with h | h | h + · exact Or.inl h + · exact Or.inr h + · exact absurd hx (by rw [h]; norm_num) + +lemma negMulLog_inv (x : ℝ) : negMulLog x⁻¹ = x⁻¹ * Real.log x := by + rw [negMulLog, Real.log_inv] + ring + +/-- Generalization of `negMulLog_mul` to a finite product: `negMulLog (∏ i ∈ s, f i)` expands as +a sum of `(∏ j ∈ s.erase i, f j) * negMulLog (f i)`. -/ +lemma negMulLog_prod {ι : Type*} [DecidableEq ι] (s : Finset ι) (f : ι → ℝ) : + negMulLog (∏ i ∈ s, f i) = + ∑ i ∈ s, (∏ j ∈ s.erase i, f j) * negMulLog (f i) := by + induction s using Finset.induction with + | empty => simp + | insert a s ha ih => + rw [Finset.prod_insert ha, negMulLog_mul, ih, Finset.sum_insert ha, + Finset.mul_sum, Finset.erase_insert ha] + congr 1 + refine Finset.sum_congr rfl fun i hi ↦ ?_ + have hi_ne_a : i ≠ a := fun h ↦ ha (h ▸ hi) + have ha_notin_erase : a ∉ s.erase i := fun h ↦ ha (Finset.mem_of_mem_erase h) + rw [Finset.erase_insert_of_ne hi_ne_a.symm, Finset.prod_insert ha_notin_erase, ← mul_assoc] + +/-- Power-case companion to `negMulLog_prod`: `negMulLog (x^n)` expands as +`n * x^(n-1) * negMulLog x`. Derived directly via `pow_succ` induction (no +`DecidableEq` needed). Uses ℕ subtraction; at `n = 0` both sides are `0`. -/ +lemma negMulLog_pow (x : ℝ) (n : ℕ) : + negMulLog (x ^ n) = n * x ^ (n - 1) * negMulLog x := by + induction n with + | zero => simp + | succ n ih => + rw [pow_succ, negMulLog_mul, ih] + cases n with + | zero => simp + | succ m => rw [Nat.succ_sub_one]; push_cast; ring + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/RpowTendsto.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/RpowTendsto.lean new file mode 100644 index 0000000000..e95e1eed0c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/Log/RpowTendsto.lean @@ -0,0 +1,45 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.SpecialFunctions.Log.RpowTendsto +public import Mathlib.Topology.MetricSpace.Algebra +public import LeanPool.AxQM.ToMathlib.Topology.UniformSpace.LocallyUniformConvergence + +/-! +# The logarithm as a limit of powers: the `x log x` variant + +Extends `Mathlib.Analysis.SpecialFunctions.Log.RpowTendsto` with the analogous limit for +`p⁻¹ * (x ^ (p + 1) - x) → x * log x`, obtained from `tendstoLocallyUniformlyOn_rpow_sub_one_log` +by multiplying by `x`. +-/ + +public section + +open scoped Topology +open Real Filter Set + +open Set in +/-- `p⁻¹ * (x ^ (p + 1) - x)` tends uniformly to `x * log x` on compact subsets of `Ioi 0` as +`p` tends to zero. Follows from `tendstoLocallyUniformlyOn_rpow_sub_one_log` via the identity +`p⁻¹ * (x ^ (p + 1) - x) = x * (p⁻¹ * (x ^ p - 1))`. -/ +lemma Real.tendstoLocallyUniformlyOn_rpow_succ_sub_self_mul_log : + TendstoLocallyUniformlyOn (fun (p : ℝ) (x : ℝ) => p⁻¹ * (x ^ (p + 1) - x)) + (fun x => x * log x) (𝓝[>] 0) (Ioi 0) := + (((tendstoLocallyUniformlyOn_const_fn id).mul₀ + tendstoLocallyUniformlyOn_rpow_sub_one_log continuousOn_id + (Real.continuousOn_log.mono fun _ hx ↦ hx.ne')).congr + fun p x hx ↦ by + simp only [Pi.mul_apply, id] + rw [Real.rpow_add_one hx.ne']; ring) + +lemma tendsto_rpow_succ_sub_self_mul_log {x : ℝ} (hx : 0 < x) : + Tendsto (fun p => p⁻¹ * (x ^ (p + 1) - x)) (𝓝[>] 0) (𝓝 (x * log x)) := + TendstoLocallyUniformlyOn.tendsto_at + Real.tendstoLocallyUniformlyOn_rpow_succ_sub_self_mul_log (by grind) diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/MutualInformationMap.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/MutualInformationMap.lean new file mode 100644 index 0000000000..88f16915ef --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/MutualInformationMap.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ConditionalEntropy + +/-! +# Mutual information of random variables, and a superadditivity counterexample + +For a finite sample space `Ω` with a discrete distribution `p : Ω → ℝ` and two *random variables* +`f : Ω → β`, `g : Ω → γ` into finite types, the **mutual information** of `f` and `g` is + +`Real.mutualInfoMap p f g := Real.entropyMap p f + Real.entropyMap p g − Real.entropyMap p (f, g)`, + +i.e. `H(f : g) = H(f) + H(g) − H(f, g)`, defined through the laws of `f`, `g`, and the tuple +`(f, g)` (all via `Real.entropyMap`, the entropy of a pushforward law). This is the +random-variable sibling of `Real.mutualInfo` (which acts on a joint distribution on a product +type), built on the same `Ω`-based development as `Real.condEntropyMap`; modelling the entropies +through a shared sample space makes the joint entropy of any tuple of variables free — exactly what +the counterexample below needs. + +## Main declarations + +* `Real.mutualInfoMap` — `H(f : g)`, the mutual information of two random variables. +* `Real.exists_mutualInfo_not_superadditive_counterexample` and + `Real.not_forall_mutualInfo_superadditive` — an **explicit example** and its packaging as a + refutation, showing that the mutual information is **not** always superadditive (Nielsen & + Chuang, *Quantum Computation and Quantum Information*, Exercise 11.9). + +## The counterexample (N&C Exercise 11.9) + +For a fair bit `X₁` and `X₂ = Y₁ = Y₂ = X₁`, mutual information fails to be superadditive: +`H(X₁ : Y₁) + H(X₂ : Y₂) ≰ H(X₁, X₂ : Y₁, Y₂)`. + +The witness is the fair bit `Ω = Fin 2` (uniform `p ≡ 1/2`) with all four variables the identity, +so `X₂ = Y₁ = Y₂ = X₁ = x`. Every quantity in sight is the entropy of an *injective* function of +the bit `x` (`x`, the pair `(x, x)`, the quadruple `((x, x), (x, x))`), hence equals `H(x) = log 2` +by `Real.entropyMap_of_injective`. Therefore + +* `H(X₁ : Y₁) = H(x) + H(x) − H(x, x) = log 2`, and likewise `H(X₂ : Y₂) = log 2`, so the left-hand + side is `2 log 2`; +* `H(X₁, X₂ : Y₁, Y₂) = H(x, x) + H(x, x) − H((x, x), (x, x)) = log 2` is the right-hand side. + +The gap `2 log 2 − log 2 = log 2 > 0` is a full bit: superadditivity fails. (Contrast N&C Exercise +11.8, where mutual information fails to be *sub*additive.) + +## Design + +This is pure classical information theory — it quantifies over functions `p : Ω → ℝ` and +`f : Ω → β`, building on the `Real.entropyMap` development. The statement of Exercise 11.9 is in +[upstream `AxQM/NC/Ch11/Exercise11_9.lean`](https://github.com/Axiomatic-AI/AxQMLib/blob/1bc3602193961227cad4f5fd3ae794fb584c05b6/AxQM/NC/Ch11/Exercise11_9.lean). + +N&C measure entropy in *bits* (base-2 logarithm); the library measures it in *nats* (natural +logarithm). The failure is a strict inequality whose gap is `log b 2 > 0` in any base `b > 1`, so +it is base-independent: a faithful reformulation, not a weakening. +-/ + +@[expose] public section + +namespace Real + +variable {Ω β γ : Type*} [Fintype Ω] [Fintype β] [DecidableEq β] [Fintype γ] [DecidableEq γ] + +/-- The **mutual information** `H(f : g) = H(f) + H(g) − H(f, g)` of two random variables +`f : Ω → β`, `g : Ω → γ` on a common finite sample space with distribution `p : Ω → ℝ`, defined +through the laws of `f`, `g`, and the tuple `(f, g)` (all via `Real.entropyMap`). -/ +noncomputable def mutualInfoMap (p : Ω → ℝ) (f : Ω → β) (g : Ω → γ) : ℝ := + entropyMap p f + entropyMap p g - entropyMap p (fun ω => (f ω, g ω)) + +/-- Unfolding lemma for `mutualInfoMap`: `H(f : g) = H(f) + H(g) − H(f, g)`, through the laws of +`f`, `g`, and the joint law of the tuple `(f, g)`. -/ +theorem mutualInfoMap_eq (p : Ω → ℝ) (f : Ω → β) (g : Ω → γ) : + mutualInfoMap p f g = entropyMap p f + entropyMap p g - entropyMap p (fun ω => (f ω, g ω)) := + rfl + +/-- **Explicit counterexample to superadditivity of the mutual information** (Nielsen & Chuang, +*Quantum Computation and Quantum Information*, Exercise 11.9). + +There exist a finite probability space and random variables `X₁, X₂, Y₁, Y₂` realising the +copied-variable configuration `X₂ ≡ Y₁ ≡ Y₂ ≡ X₁` of the exercise, for which + +`H(X₁ : Y₁) + H(X₂ : Y₂) > H(X₁, X₂ : Y₁, Y₂)`, + +so the inequality `H(X₁ : Y₁) + H(X₂ : Y₂) ≤ H(X₁, X₂ : Y₁, Y₂)` — superadditivity of the mutual +information (N&C eq. (11.35)) — does **not** hold. The witness is the fair bit `Ω = Fin 2` (uniform +`p ≡ 1/2`) with all four variables the identity: each mutual information equals `log 2`, so the +left-hand side is `2 log 2` and the right-hand side is `log 2`, a gap of a full bit. -/ +theorem exists_mutualInfo_not_superadditive_counterexample : + ∃ (Ω : Type) (_ : Fintype Ω) (_ : DecidableEq Ω) (p : Ω → ℝ) (X₁ X₂ Y₁ Y₂ : Ω → Fin 2), + (∀ ω, 0 ≤ p ω) ∧ (∑ ω, p ω = 1) ∧ X₂ = X₁ ∧ Y₁ = X₁ ∧ Y₂ = X₁ ∧ + mutualInfoMap p X₁ Y₁ + mutualInfoMap p X₂ Y₂ > + mutualInfoMap p (fun ω => (X₁ ω, X₂ ω)) (fun ω => (Y₁ ω, Y₂ ω)) := by + refine ⟨Fin 2, inferInstance, inferInstance, fun _ => (2 : ℝ)⁻¹, id, id, id, id, + fun _ => by norm_num, by rw [Fin.sum_univ_two]; norm_num, rfl, rfl, rfl, ?_⟩ + have hEp : entropy (fun _ : Fin 2 => (2 : ℝ)⁻¹) = Real.log 2 := by + have h := entropy_uniform (ι := Fin 2) + simpa [Fintype.card_fin] using h + -- Every entropy in sight is the entropy of an injective function of the fair bit, hence `log 2`. + have e_id : entropyMap (fun _ : Fin 2 => (2 : ℝ)⁻¹) (id : Fin 2 → Fin 2) = Real.log 2 := by + rw [entropyMap_of_injective Function.injective_id]; exact hEp + have e_dup : entropyMap (fun _ : Fin 2 => (2 : ℝ)⁻¹) (fun ω : Fin 2 => (ω, ω)) = Real.log 2 := by + rw [entropyMap_of_injective (f := fun ω : Fin 2 => (ω, ω)) (fun _ _ h => congrArg Prod.fst h)] + exact hEp + have e_quad : entropyMap (fun _ : Fin 2 => (2 : ℝ)⁻¹) + (fun ω : Fin 2 => ((ω, ω), (ω, ω))) = Real.log 2 := by + rw [entropyMap_of_injective (f := fun ω : Fin 2 => ((ω, ω), (ω, ω))) + (fun _ _ h => congrArg Prod.fst (congrArg Prod.fst h))] + exact hEp + simp only [mutualInfoMap_eq, id_eq] + linarith [e_id, e_dup, e_quad, Real.log_pos (show (1 : ℝ) < 2 by norm_num)] + +/-- **Superadditivity of the mutual information is not a theorem** (Nielsen & Chuang, Exercise +11.9): it is *not* the case that for all finite random variables `X₁, X₂, Y₁, Y₂` on a finite +probability space, +`H(X₁ : Y₁) + H(X₂ : Y₂) ≤ H(X₁, X₂ : Y₁, Y₂)`. +This is the negation packaging of +`exists_mutualInfo_not_superadditive_counterexample`. -/ +theorem not_forall_mutualInfo_superadditive : + ¬ ∀ (Ω αX₁ αX₂ αY₁ αY₂ : Type) [Fintype Ω] [DecidableEq Ω] + [Fintype αX₁] [DecidableEq αX₁] [Fintype αX₂] [DecidableEq αX₂] + [Fintype αY₁] [DecidableEq αY₁] [Fintype αY₂] [DecidableEq αY₂] + (p : Ω → ℝ) (X₁ : Ω → αX₁) (X₂ : Ω → αX₂) (Y₁ : Ω → αY₁) (Y₂ : Ω → αY₂), + (∀ ω, 0 ≤ p ω) → ∑ ω, p ω = 1 → + mutualInfoMap p X₁ Y₁ + mutualInfoMap p X₂ Y₂ ≤ + mutualInfoMap p (fun ω => (X₁ ω, X₂ ω)) (fun ω => (Y₁ ω, Y₂ ω)) := by + intro h + obtain ⟨Ω, _, _, p, X₁, X₂, Y₁, Y₂, hnn, hsum, _, _, _, hgap⟩ := + exists_mutualInfo_not_superadditive_counterexample + exact absurd (h Ω (Fin 2) (Fin 2) (Fin 2) (Fin 2) p X₁ X₂ Y₁ Y₂ hnn hsum) (not_le.mpr hgap) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean new file mode 100644 index 0000000000..05f0704637 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean @@ -0,0 +1,933 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.BinaryEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.Basic +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.Log.NegMulLog +public import LeanPool.AxQM.ToMathlib.Analysis.Convex.Function +public import Mathlib.Analysis.Convex.Jensen +public import Mathlib.Analysis.Convex.SpecificFunctions.Basic + +/-! +# Shannon entropy of a discrete distribution + +For a finite type `ι` and a function `p : ι → ℝ` (interpreted as a probability mass function +when `p i ∈ [0, 1]` and `∑ i, p i = 1`), the **Shannon entropy** of `p` is + +`Real.entropy p := ∑ i, Real.negMulLog (p i)`. + +The function is defined on raw `ι → ℝ` input rather than on a bundled probability mass +function, mirroring the `Real.binEntropy : ℝ → ℝ` convention of accepting any real input and +providing distribution-hypothesis-driven API lemmas separately. Junk-valued on negative inputs +(where `Real.negMulLog` is itself junk-valued). + +Entropy is measured in nats (natural log), matching the convention in +`Mathlib/Analysis/SpecialFunctions/BinaryEntropy.lean`. + +## Main definitions + +- `Real.entropy : (ι → ℝ) → ℝ` + +## Main results + +- `Real.entropy_eq` (rfl-lemma exposing the sum form). +- `Real.entropy_zero` (@[simp]): the all-zero distribution has zero entropy. +- `Real.entropy_const`: closed form on constant inputs. +- `Real.entropy_nonneg`: nonneg under the probability hypothesis `0 ≤ p i ≤ 1`. +- `Real.entropy_fin_two_eq_binEntropy`: reconciliation with the binary entropy function. +- `Real.entropy_prod`: product additivity for an independent joint distribution. +- `Real.entropy_sigma_mul`: grouping / chain rule `H(⟨i,k⟩ ↦ pᵢ · wᵢₖ) = H(p) + ∑ᵢ pᵢ H(wᵢ)` for a + dependent (sigma-indexed) mixture distribution. +- `Real.entropy_le_log_card`: Jensen's-inequality-based upper bound by `log (card ι)`. +- `Real.entropy_uniform`: the uniform distribution `i ↦ (card ι)⁻¹` attains that bound. +- `Real.entropy_eq_log_card_iff`: **equality condition** (Nielsen–Chuang Theorem 11.2) — the + bound `log (card ι)` is attained iff `p` is the uniform distribution. +- `Real.entropy_lt_log_card_of_ne_uniform`: **strict** form of the two above — a non-uniform `p` + has entropy strictly below `log (card ι)`; the uniform distribution is the unique maximiser. +- `Real.entropy_eq_zero_iff`: **entropy-zero characterization** (Nielsen–Chuang Theorem 11.8, + part (1)) — `entropy p = 0` iff `p` is a point mass (some `p i = 1`, the rest `0`); the + minimum-entropy peer of `entropy_eq_log_card_iff`. +- `Real.sum_negMulLog_le`: **weighted grouping bound** (analytic kernel of Fannes' inequality, + Nielsen–Chuang Theorem 11.6) — for nonnegative `a : ι → ℝ` not required to sum to `1`, + `∑ negMulLog (a i) ≤ (∑ a i) * log (card ι) + negMulLog (∑ a i)`; the un-normalized + generalization of `entropy_le_log_card`. +- `Real.entropy_le_qaryEntropy`: **grouping inequality** (single-distribution kernel of + Fano's inequality) — `entropy r ≤ qaryEntropy (card ι) (1 - r i₀)`. +- `Real.entropy_concave`: concavity of `entropy` on the convex set of nonneg functions. +- `Real.entropy_le_cross_entropy_of_sum_le`: **sub-normalized cross-entropy bound**, the shared + kernel — entropy is at most cross-entropy when `p`'s support lies in `q`'s and `∑ q ≤ ∑ p`. The + per-term real-analysis facts `Real.mul_log_div_le_sub_of_nonneg` and `Real.mul_log_div` live + in `ToMathlib/Analysis/SpecialFunctions/Log/Basic.lean`. +- `Real.entropy_le_cross_entropy_of_support_subset`: **Gibbs' inequality, support-aware + form** — the equal-mass (`∑ p = ∑ q`) corollary of `entropy_le_cross_entropy_of_sum_le`. +- `Real.entropy_le_cross_entropy_of_sum_eq_one`: **Gibbs' inequality** (a.k.a. classical + Klein's inequality) for strictly-positive `q`, a corollary of the support-aware form. + Foundational classical input to the operator Klein inequality (Nielsen-Chuang Thm 11.7) + via spectral decomposition + Jensen. +- `Real.sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic`: **doubly-stochastic + Klein-classical bound** consumed by operator Klein's inequality. For prob dists `p, q` and + doubly-stochastic weights `W`, `∑ p_i * ∑ W_ij log q_j ≤ -entropy p`. Proof: inner Jensen + on `log` + bridge distribution `r_i := ∑ W_ij q_j` + outer Gibbs. +- `Real.relativeEntropy_nonneg`: **Gibbs' inequality**, `D(p‖q) ≥ 0` for prob dists with + `q > 0`; `Real.relativeEntropy_nonneg_of_support_subset` is the support-aware form + (`supp p ⊆ supp q`, equal total mass `∑ p = ∑ q`), and + `Real.relativeEntropy_nonneg_of_sum_le` the **sub-normalized** form (`∑ q ≤ ∑ p`), which + deduces `H(Y | X) ≥ 0` from the conditional-entropy relative-entropy expression (N&C Ex. 11.7). +- `Real.relativeEntropy_eq_zero_iff`: **equality condition** — `D(p‖q) = 0 ↔ p = q` under the + same support/absolute-continuity hypothesis (`q x = 0 → p x = 0`, equal total mass). With the + support-aware nonneg result this is the faithful real-valued rendering of Nielsen–Chuang + Theorem 11.1 ("non-negative, with equality iff `p = q`") on the domain where `relativeEntropy` + equals N&C's `H(p‖q)`. `Real.relativeEntropy_pos_of_ne` is the sharp `p ≠ q → D(p‖q) > 0` + contrapositive form. +- `Real.abs_negMulLog_sub_le`: **continuity kernel of Fannes' inequality** (Nielsen–Chuang + Theorem 11.6, eq. 11.47) — for `x, y ∈ [0, 1]` with `|x - y| ≤ 1/2`, + `|negMulLog x - negMulLog y| ≤ negMulLog |x - y|`, i.e. `negMulLog` has itself as a modulus + of continuity on scales `≤ 1/2`. `Real.strictMonoOn_negMulLog_Icc`: `negMulLog` is strictly + increasing on `[0, e⁻¹]` (used to lift the bound to the trace distance). The supporting + facts `Real.negMulLog_one_sub_le` (`η(1 - δ) ≤ η(δ)` for `δ ∈ [0, 1/2]`) and + `Real.monotoneOn_negMulLog_sub_add` (the increment `η t - η (t + δ)` is monotone in `t`) + are of independent interest. `Real.negMulLog_le_exp_neg_one`: `negMulLog x ≤ e⁻¹` for `x ≥ 0` + (the maximum of `η`, attained at `e⁻¹`), the constant in the weaker unconditional Fannes bound + (Nielsen–Chuang eq. 11.45). +-/ + +@[expose] public section + +namespace Real + +variable {ι : Type*} [Fintype ι] + +/-- The Shannon entropy (in nats) of a discrete distribution `p : ι → ℝ`. -/ +noncomputable def entropy (p : ι → ℝ) : ℝ := + ∑ i, Real.negMulLog (p i) + +theorem entropy_eq (p : ι → ℝ) : entropy p = ∑ i, Real.negMulLog (p i) := rfl + +/-- Entropy as the negated sum of `p i * log (p i)`: `entropy p = -∑ i, p i * log (p i)` +(since `negMulLog x = -(x * log x)`). -/ +theorem entropy_eq_neg_sum_mul_log (p : ι → ℝ) : + entropy p = -∑ i, p i * Real.log (p i) := by + simp only [entropy_eq, Real.negMulLog, neg_mul, Finset.sum_neg_distrib] + +@[simp] +theorem entropy_zero : entropy (0 : ι → ℝ) = 0 := by simp [entropy_eq] + +/-- Closed form for the entropy of a constant function. Specializes to `entropy 0 = 0` +and `entropy 1 = 0` (since `negMulLog 0 = 0` and `negMulLog 1 = 0`). -/ +theorem entropy_const (c : ℝ) : entropy (fun _ : ι ↦ c) = Fintype.card ι * c.negMulLog := by + simp [entropy_eq, Finset.sum_const, Finset.card_univ] + +/-- The Shannon entropy `p ↦ ∑ i, negMulLog (p i)` is a continuous function of the distribution. -/ +theorem continuous_entropy : Continuous (entropy : (ι → ℝ) → ℝ) := by + unfold entropy + exact continuous_finsetSum _ fun i _ => Real.continuous_negMulLog.comp (continuous_apply i) + +@[simp] +theorem entropy_one : entropy (1 : ι → ℝ) = 0 := by + rw [Pi.one_def]; simpa using entropy_const (ι := ι) 1 + +@[simp] +theorem entropy_isEmpty [IsEmpty ι] (p : ι → ℝ) : entropy p = 0 := by + simp [entropy_eq] + +/-- The **classical relative entropy** (Kullback–Leibler divergence) of `p` with respect to +`q`: `D(p‖q) = ∑ x, p x * (log (p x) - log (q x))`. With Mathlib's junk-value +`Real.log 0 = 0`, boundary terms vanish where `p x = 0`; nonnegativity holds under +`∑ p = ∑ q = 1` and absolute continuity (see `Real.entropy_le_cross_entropy_of_sum_eq_one` +and `Real.entropy_le_cross_entropy_of_support_subset`). -/ +noncomputable def relativeEntropy (p q : ι → ℝ) : ℝ := + ∑ x, p x * (Real.log (p x) - Real.log (q x)) + +theorem relativeEntropy_eq (p q : ι → ℝ) : + relativeEntropy p q = ∑ x, p x * (Real.log (p x) - Real.log (q x)) := rfl + +/-- The relative entropy of a distribution with itself is `0`. -/ +@[simp] +theorem relativeEntropy_self (p : ι → ℝ) : relativeEntropy p p = 0 := by + simp [relativeEntropy_eq] + +@[simp] +theorem relativeEntropy_isEmpty [IsEmpty ι] (p q : ι → ℝ) : relativeEntropy p q = 0 := by + simp [relativeEntropy_eq] + +/-- The relative entropy splits as `(∑ x, p x * log (p x)) - ∑ x, p x * log (q x)`. The +first sum is `-entropy p` (since `entropy p = ∑ x, negMulLog (p x) = -∑ x, p x * log (p x)`) +and the second is the cross-entropy `-∑ x, p x * log (q x)` up to sign, so equivalently +`relativeEntropy p q = -entropy p - (-cross-entropy)`. This is the reusable form feeding +Gibbs' inequality (`relativeEntropy p q ≥ 0`). -/ +theorem relativeEntropy_eq_sub (p q : ι → ℝ) : + relativeEntropy p q = (∑ x, p x * Real.log (p x)) - ∑ x, p x * Real.log (q x) := by + simp only [relativeEntropy_eq, mul_sub, Finset.sum_sub_distrib] + +/-- The Shannon entropy of a probability distribution (taking values in `[0, 1]`) is nonneg. -/ +theorem entropy_nonneg {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) (h1 : ∀ i, p i ≤ 1) : + 0 ≤ entropy p := + Finset.sum_nonneg fun i _ ↦ Real.negMulLog_nonneg (h0 i) (h1 i) + +/-- The entropy of a two-outcome distribution `(p, 1 - p)` is the binary entropy of `p`. -/ +theorem entropy_fin_two_eq_binEntropy (p : ℝ) : entropy ![p, 1 - p] = binEntropy p := by + simp [entropy_eq, binEntropy_eq_negMulLog_add_negMulLog_one_sub, Fin.sum_univ_succ] + +variable {κ : Type*} [Fintype κ] + +/-- **Product additivity**: the Shannon entropy of an independent joint distribution +`r (i, j) := p i * q j` is the sum of the marginal entropies, provided both marginals sum +to one. -/ +theorem entropy_prod {p : ι → ℝ} {q : κ → ℝ} (hp : ∑ i, p i = 1) (hq : ∑ j, q j = 1) : + entropy (fun ij : ι × κ ↦ p ij.1 * q ij.2) = entropy p + entropy q := by + rw [entropy_eq, Fintype.sum_prod_type, entropy_eq, entropy_eq] + calc ∑ x, ∑ y, negMulLog (p x * q y) + = ∑ x, ∑ y, (q y * negMulLog (p x) + p x * negMulLog (q y)) := by simp_rw [negMulLog_mul] + _ = ∑ x, ((∑ y, q y) * negMulLog (p x) + p x * ∑ y, negMulLog (q y)) := by + simp_rw [Finset.sum_add_distrib, Finset.sum_mul, Finset.mul_sum] + _ = ∑ x, negMulLog (p x) + (∑ x, p x) * ∑ y, negMulLog (q y) := by + rw [hq]; simp [Finset.sum_add_distrib, Finset.sum_mul] + _ = ∑ x, negMulLog (p x) + ∑ y, negMulLog (q y) := by rw [hp, one_mul] + +/-- **Grouping / chain rule** for the Shannon entropy of a mixture. If the inner family `w i` is a +probability distribution for each `i` (`∑ₖ w i k = 1`), the entropy of the joint distribution +`⟨i, k⟩ ↦ p i · w i k` splits as the entropy of the outer weights `p` plus the `p`-weighted average +of the inner entropies: + +`H(⟨i, k⟩ ↦ pᵢ · wᵢₖ) = H(p) + ∑ᵢ pᵢ · H(wᵢ)`. + +Unlike `entropy_prod` the inner distribution `w i` may depend on the outer index `i` (a genuine +mixture, not an independent product). This is the classical kernel of the orthogonal-support +mixture-entropy identity and the joint-entropy theorem (Nielsen & Chuang Theorem 11.8 parts 4–5, +Theorem 11.10): if states `ρᵢ` have eigenvalue distributions `wᵢ` and orthogonal supports, the +mixed spectrum is `⟨i, k⟩ ↦ pᵢ · wᵢₖ` and its entropy splits this way. -/ +theorem entropy_sigma_mul {κ : ι → Type*} [∀ i, Fintype (κ i)] + (p : ι → ℝ) (w : (i : ι) → κ i → ℝ) (hw : ∀ i, ∑ k, w i k = 1) : + entropy (fun ik : Σ i, κ i ↦ p ik.1 * w ik.1 ik.2) + = entropy p + ∑ i, p i * entropy (w i) := by + rw [entropy_eq, Fintype.sum_sigma, entropy_eq, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + calc ∑ k, negMulLog (p i * w i k) + = ∑ k, (w i k * negMulLog (p i) + p i * negMulLog (w i k)) := by simp_rw [negMulLog_mul] + _ = (∑ k, w i k) * negMulLog (p i) + p i * ∑ k, negMulLog (w i k) := by + rw [Finset.sum_add_distrib, Finset.sum_mul, Finset.mul_sum] + _ = negMulLog (p i) + p i * entropy (w i) := by rw [hw i, one_mul, entropy_eq] + +/-- **Grouping / chain rule** for the Shannon entropy of a mixture over a *product* index. If the +inner family `q x` is a probability distribution for each `x` (`∑ₖ q x k = 1`), the entropy of the +joint distribution `⟨x, k⟩ ↦ pₓ · q x k` on `ι × κ` splits as the entropy of the outer weights `p` +plus the `p`-weighted average of the inner entropies: + +`H(⟨x, k⟩ ↦ pₓ · q x k) = H(p) + ∑ₓ pₓ · H(q x)`. + +This is the constant-fibre (`ι × κ`) form of `entropy_sigma_mul`: as there, the inner distribution +`q x` may depend on the outer index `x` (a genuine mixture, not an independent product as in +`entropy_prod`). It is the classical chain rule `H(X, Y) = H(X) + H(Y | X)` for a joint given by a +conditional kernel `q x = p(· | x)`, and the classical kernel of the Holevo χ ↔ mutual-information +identity (Nielsen & Chuang Problem 12.1). -/ +theorem entropy_prod_mul {p : ι → ℝ} {q : ι → κ → ℝ} (hq : ∀ i, ∑ k, q i k = 1) : + entropy (fun ik : ι × κ ↦ p ik.1 * q ik.1 ik.2) = entropy p + ∑ i, p i * entropy (q i) := by + rw [entropy_eq, Fintype.sum_prod_type, entropy_eq, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + calc ∑ k, negMulLog (p i * q i k) + = ∑ k, (q i k * negMulLog (p i) + p i * negMulLog (q i k)) := by simp_rw [negMulLog_mul] + _ = (∑ k, q i k) * negMulLog (p i) + p i * ∑ k, negMulLog (q i k) := by + rw [Finset.sum_add_distrib, Finset.sum_mul, Finset.mul_sum] + _ = negMulLog (p i) + p i * entropy (q i) := by rw [hq i, one_mul, entropy_eq] + +/-- **Multiset-eq bridge for Shannon entropy.** If two finite-indexed sequences `f : ι → ℝ` +and `g : κ → ℝ` produce equal multisets of values (i.e., the underlying-Multiset of the +universe-image agrees), their Shannon entropies agree. The key bridge from +`_eigenvalues_multiset_eq` capstones to entropy equality — used in +`LinearMap.IsSymmetric.vonNeumannEntropy_tensorPow_of_sum_eigenvalues_eq_one` and +`LinearMap.IsSymmetric.vonNeumannEntropy_tensorOp_of_sum_eigenvalues_eq_one`. -/ +theorem entropy_eq_of_multiset_map_eq {f : ι → ℝ} {g : κ → ℝ} + (h : (Finset.univ : Finset ι).val.map f = (Finset.univ : Finset κ).val.map g) : + entropy f = entropy g := by + rw [entropy_eq, entropy_eq, ← Finset.sum_map_val, ← Finset.sum_map_val] + simp only [← Function.comp_def Real.negMulLog] + rw [← Multiset.map_map Real.negMulLog f, ← Multiset.map_map Real.negMulLog g, h] + +/-- **Product-distribution entropy additivity** (per-coordinate form): for a family of probability +distributions `r j : ι → ℝ` (each `∑ₓ r j x = 1`), the Shannon entropy of the product distribution +`y ↦ ∏ⱼ r j (y j)` over `Fin n → ι` is the sum `∑ⱼ H(r j)` of the coordinate entropies. + +Proof: induction on `n`; the inductive step peels the last coordinate through `Fin.succFunEquiv` +(bridging `Fin (n+1) → ι ≃ (Fin n → ι) × ι`) and applies `entropy_prod`, whose outer marginal (the +product over the first `n` coordinates) sums to one via `Finset.sum_prod_piFinset`. The i.i.d. +tensor power `entropy_pi_prod_of_sum_eq_one` (`H(p^{⊗n}) = n · H(p)`) is the special case +`r j = p`. It is the "noise entropy single-letterizes" ingredient in the converse of Shannon's noisy +channel coding theorem (Nielsen & Chuang Theorem 12.7): the conditional output entropy +`H(Yⁿ | Xⁿ = xⁿ) = H(∏ⱼ q(·|xⱼ))` of the memoryless `n`-use channel splits as `∑ⱼ H(q(·|xⱼ))`. -/ +theorem entropy_pi_prod : + ∀ {n : ℕ} {r : Fin n → ι → ℝ}, (∀ j, ∑ x, r j x = 1) → + entropy (fun y : Fin n → ι ↦ ∏ j, r j (y j)) = ∑ j, entropy (r j) := by + intro n + induction n with + | zero => + intro r _ + rw [Fin.sum_univ_zero, entropy_eq] + refine Finset.sum_eq_zero fun y _ ↦ ?_ + simp [Real.negMulLog_one] + | succ n ih => + intro r hr + -- The outer marginal (product over the first `n` coordinates) is a probability distribution. + have hout_sum : ∑ z : Fin n → ι, ∏ i, r i.castSucc (z i) = 1 := by + rw [← Fintype.piFinset_univ, Finset.sum_prod_piFinset] + simp [hr] + -- Bridge `Fin (n+1) → ι ≃ (Fin n → ι) × ι` (peel the last coordinate). + have hbij : entropy (fun y : Fin (n + 1) → ι ↦ ∏ j, r j (y j)) + = entropy (fun pair : (Fin n → ι) × ι ↦ + (∏ i, r i.castSucc (pair.1 i)) * r (Fin.last n) pair.2) := by + rw [entropy_eq, entropy_eq, ← (Fin.succFunEquiv ι n).sum_comp] + refine Finset.sum_congr rfl fun y _ ↦ ?_ + simp only [Fin.succFunEquiv_apply, Fin.prod_univ_castSucc] + rfl + rw [hbij, entropy_prod hout_sum (hr (Fin.last n)), + ih (r := fun i ↦ r i.castSucc) (fun i ↦ hr i.castSucc), Fin.sum_univ_castSucc] + +/-- **Pi-tensor-power additivity**: the Shannon entropy of the n-fold independent +product distribution `κ ↦ ∏ i, p (κ i)` over `Fin n → ι` is `n * entropy p`, provided +`p` sums to one. This is the i.i.d. special case `r j = p` of the per-coordinate +`Real.entropy_pi_prod`. -/ +theorem entropy_pi_prod_of_sum_eq_one {p : ι → ℝ} (hp : ∑ i, p i = 1) (n : ℕ) : + entropy (fun κ : Fin n → ι ↦ ∏ i, p (κ i)) = n * entropy p := by + rw [entropy_pi_prod (fun _ ↦ hp), Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] + +/-- **Jensen's upper bound**: the Shannon entropy of a probability distribution on a +nonempty finite type is at most `log (card ι)`. The bound is tight for the uniform +distribution. -/ +theorem entropy_le_log_card [Nonempty ι] {p : ι → ℝ} + (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + entropy p ≤ Real.log (Fintype.card ι) := by + have hn : (0 : ℝ) < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + set n : ℝ := (Fintype.card ι : ℝ) with hn_def + have h_uniform : ∑ i, (n⁻¹ : ℝ) • p i = n⁻¹ := by + rw [← Finset.smul_sum, hsum, smul_eq_mul, mul_one] + -- Apply Jensen with uniform weights `wᵢ = 1/n`. + have hjensen : + ∑ i, (n⁻¹ : ℝ) • negMulLog (p i) ≤ negMulLog (∑ i, (n⁻¹ : ℝ) • p i) := by + refine concaveOn_negMulLog.le_map_sum ?_ ?_ fun i _ ↦ h0 i + · intro i _; positivity + · rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, ← hn_def, mul_inv_cancel₀ hn.ne'] + rw [← Finset.smul_sum, h_uniform, negMulLog_inv, smul_eq_mul] at hjensen + rw [entropy_eq] + exact (mul_le_mul_iff_of_pos_left (inv_pos.mpr hn)).mp hjensen + +/-- The uniform distribution `i ↦ (card ι)⁻¹` attains the maximal entropy `log (card ι)` — the +tight case of `entropy_le_log_card`. Holds unconditionally: for empty `ι` both sides are `0`. -/ +theorem entropy_uniform : + entropy (fun _ : ι ↦ (Fintype.card ι : ℝ)⁻¹) = Real.log (Fintype.card ι) := by + rw [entropy_const, negMulLog_inv] + rcases eq_or_ne (Fintype.card ι : ℝ) 0 with h | h + · rw [h]; simp + · rw [← mul_assoc, mul_inv_cancel₀ h, one_mul] + +/-- **Equality in the entropy bound** (Nielsen–Chuang, *Quantum Computation and Quantum +Information*, Theorem 11.2): for a probability distribution `p` on a nonempty finite type, the +Shannon entropy attains its maximum value `log (card ι)` **if and only if** `p` is the uniform +distribution `i ↦ (card ι)⁻¹`. Together with `entropy_le_log_card` (the inequality +`entropy p ≤ log (card ι)`) this is the full statement `H(X) ≤ log d` with equality iff `X` is +uniformly distributed over its `d = card ι` outcomes. + +Proof: the equality case of strict Jensen (`StrictConcaveOn.map_sum_eq_iff` applied to +`strictConcaveOn_negMulLog`) with the uniform weights `wᵢ = (card ι)⁻¹`. Jensen's equality holds +iff every `p j` equals the weighted average `∑ i, (card ι)⁻¹ • p i = (card ι)⁻¹`, and the left-hand +side of that Jensen equality rescales to `entropy p = log (card ι)` after cancelling the common +factor `(card ι)⁻¹ > 0`. -/ +theorem entropy_eq_log_card_iff [Nonempty ι] {p : ι → ℝ} + (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + entropy p = Real.log (Fintype.card ι) ↔ ∀ i, p i = (Fintype.card ι : ℝ)⁻¹ := by + have hn : (0 : ℝ) < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + set n : ℝ := (Fintype.card ι : ℝ) with hn_def + have hw_pos : ∀ i ∈ (Finset.univ : Finset ι), (0 : ℝ) < n⁻¹ := fun i _ ↦ by positivity + have hw_sum : ∑ _i : ι, (n⁻¹ : ℝ) = 1 := by + rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, ← hn_def, mul_inv_cancel₀ hn.ne'] + have hmem : ∀ i ∈ (Finset.univ : Finset ι), p i ∈ Set.Ici (0 : ℝ) := fun i _ ↦ h0 i + -- Equality case of strict Jensen with uniform weights `wᵢ = n⁻¹`. + have key := strictConcaveOn_negMulLog.map_sum_eq_iff (t := Finset.univ) + (w := fun _ : ι ↦ (n⁻¹ : ℝ)) (p := p) hw_pos hw_sum hmem + have h_uniform : ∑ i, (n⁻¹ : ℝ) • p i = n⁻¹ := by + rw [← Finset.smul_sum, hsum, smul_eq_mul, mul_one] + have h_rhs : ∑ i, (n⁻¹ : ℝ) • negMulLog (p i) = n⁻¹ * entropy p := by + rw [← Finset.smul_sum, smul_eq_mul, ← entropy_eq] + -- `key : n⁻¹ * log n = n⁻¹ * entropy p ↔ ∀ i, p i = n⁻¹`. + simp only [h_uniform, h_rhs, negMulLog_inv, Finset.mem_univ, forall_const] at key + rw [← key, mul_right_inj' (inv_ne_zero hn.ne')] + exact eq_comm + +/-- **Strict maximum-entropy principle**: for a probability distribution `p` on a nonempty finite +type that is *not* the uniform distribution `i ↦ (card ι)⁻¹`, the Shannon entropy is strictly below +the maximal value `log (card ι)` (attained by the uniform distribution, `entropy_uniform`). This is +the strict sharpening of `entropy_le_log_card` supplied by its equality condition +`entropy_eq_log_card_iff`: the uniform distribution is the *unique* entropy maximiser, so any bias +strictly lowers the entropy. -/ +theorem entropy_lt_log_card_of_ne_uniform [Nonempty ι] {p : ι → ℝ} + (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) + (hne : ¬ ∀ i, p i = (Fintype.card ι : ℝ)⁻¹) : + entropy p < Real.log (Fintype.card ι) := by + exact (entropy_le_log_card h0 hsum).lt_of_ne fun h => hne ((entropy_eq_log_card_iff h0 hsum).mp h) + +/-- **Entropy vanishes exactly at a point mass** (Nielsen–Chuang, *Quantum Computation and Quantum +Information*, Theorem 11.8, part (1)): for a probability distribution `p` on a finite type, the +Shannon entropy is zero **if and only if** `p` is a point mass — some outcome `i` has `p i = 1` and +every other `p j = 0`. Together with `entropy_nonneg` (`H ≥ 0`) this is the classical content behind +the first item of Theorem 11.8 (`S(ρ) = 0` iff `ρ` is pure); it is the entropy-zero peer of the +maximum-entropy characterization `entropy_eq_log_card_iff`. + +Forward: `entropy p = ∑ i, negMulLog (p i)` is a sum of non-negative terms (`negMulLog_nonneg`, as +`0 ≤ p i ≤ 1`), so it vanishes iff every term does (`Finset.sum_eq_zero_iff_of_nonneg`); each +vanishing term forces `p i ∈ {0, 1}` (`negMulLog_eq_zero`, the roots of `-x log x` on `[0, ∞)`). +As `∑ p = 1 ≠ 0`, some `p k ≠ 0` (`Finset.exists_ne_zero_of_sum_ne_zero`), forcing +`p k = 1`, and then `∑_{j ≠ k} p j = 1 - 1 = 0` forces the rest to vanish (`Finset.sum_erase_eq_sub` ++ `Finset.sum_eq_zero_iff_of_nonneg`). Reverse: the entropy sum collapses to +`negMulLog 1 + ∑ negMulLog 0 = 0`. -/ +theorem entropy_eq_zero_iff {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + entropy p = 0 ↔ ∃ i, p i = 1 ∧ ∀ j, j ≠ i → p j = 0 := by + classical + have hle1 : ∀ i, p i ≤ 1 := fun i => + (Finset.single_le_sum (fun j _ => h0 j) (Finset.mem_univ i)).trans hsum.le + constructor + · intro hent + rw [entropy_eq] at hent + -- Each `negMulLog (p i) ≥ 0`, so the vanishing sum forces every term to vanish. + have hterm : ∀ i, (p i).negMulLog = 0 := fun i => + (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => negMulLog_nonneg (h0 j) (hle1 j))).mp hent i + (Finset.mem_univ i) + -- `negMulLog (p i) = 0` with `p i ≥ 0` forces `p i ∈ {0, 1}`. + have hdich : ∀ i, p i = 0 ∨ p i = 1 := fun i => (negMulLog_eq_zero (h0 i)).mp (hterm i) + -- Since `∑ p = 1 ≠ 0`, some `p k ≠ 0`, hence `p k = 1`; the rest then vanish. + obtain ⟨k, -, hk⟩ := Finset.exists_ne_zero_of_sum_ne_zero (by rw [hsum]; exact one_ne_zero) + have hpk : p k = 1 := (hdich k).resolve_left hk + refine ⟨k, hpk, fun j hj => ?_⟩ + have hsub : ∑ i ∈ Finset.univ.erase k, p i = 0 := by + rw [Finset.sum_erase_eq_sub (Finset.mem_univ k), hsum, hpk]; norm_num + exact (Finset.sum_eq_zero_iff_of_nonneg (fun i _ => h0 i)).mp hsub j + (Finset.mem_erase.mpr ⟨hj, Finset.mem_univ j⟩) + · rintro ⟨i, hi1, hi0⟩ + rw [entropy_eq, Finset.sum_eq_single i (fun j _ hji => by rw [hi0 j hji, negMulLog_zero]) + (fun hi => absurd (Finset.mem_univ i) hi), hi1, negMulLog_one] + +/-- **Weighted grouping bound** for the (un-normalized) Shannon entropy, the analytic kernel of +Fannes' inequality (Nielsen–Chuang, *Quantum Computation and Quantum Information*, Theorem 11.6, +eq. (11.48)): for **nonnegative** weights `a : ι → ℝ` — *not* required to sum to `1` — + +`∑ i, negMulLog (a i) ≤ (∑ i, a i) * log (card ι) + negMulLog (∑ i, a i)`. + +Writing `Δ := ∑ i, a i`, this is the exact identity `∑ η(aᵢ) = Δ · H(a / Δ) + η(Δ)` combined with +the maximum-entropy bound `H(a / Δ) ≤ log (card ι)` (`entropy_le_log_card`); it generalizes +`entropy_le_log_card` from a probability distribution (`Δ = 1`, where it reduces to `H ≤ log d`) to +an arbitrary nonnegative weight vector. In Fannes' inequality it is applied to `aᵢ = |rᵢ - sᵢ|`, +the absolute differences of the sorted eigenvalue spectra of two density operators, to bound +`∑ η(|rᵢ - sᵢ|) ≤ Δ · log d + η(Δ)`. + +The proof rescales `a` to the probability distribution `pᵢ := aᵢ / Δ` (when `Δ > 0`) and expands +`η(Δ · pᵢ) = pᵢ · η(Δ) + Δ · η(pᵢ)` via `negMulLog_mul`; the degenerate `Δ = 0` case forces every +`aᵢ = 0`, whence both sides vanish. -/ +theorem sum_negMulLog_le {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + ∑ i, negMulLog (a i) ≤ (∑ i, a i) * Real.log (Fintype.card ι) + negMulLog (∑ i, a i) := by + set Δ : ℝ := ∑ i, a i with hΔ + have hΔ0 : 0 ≤ Δ := Finset.sum_nonneg fun i _ ↦ ha i + rcases hΔ0.eq_or_lt with h0 | hpos + · -- Degenerate case `Δ = 0`: every `a i = 0`, so both sides are `0`. + have hall : ∀ i, a i = 0 := fun i ↦ + (Finset.sum_eq_zero_iff_of_nonneg fun j _ ↦ ha j).mp h0.symm i (Finset.mem_univ i) + rw [← h0] + simp [hall] + · -- Main case `Δ > 0`: rescale to the probability distribution `p i = a i / Δ`. + have hne : Nonempty ι := by + rw [← not_isEmpty_iff] + intro h + rw [hΔ, Finset.univ_eq_empty, Finset.sum_empty] at hpos + exact lt_irrefl 0 hpos + set p : ι → ℝ := fun i ↦ a i / Δ with hp + have hp_nn : ∀ i, 0 ≤ p i := fun i ↦ div_nonneg (ha i) hΔ0 + have hp_sum : ∑ i, p i = 1 := by + have e : ∑ i, p i = (∑ i, a i) * Δ⁻¹ := by + simp only [hp, div_eq_mul_inv] + rw [← Finset.sum_mul] + rw [e, ← hΔ, mul_inv_cancel₀ hpos.ne'] + have hkey : entropy p ≤ Real.log (Fintype.card ι) := entropy_le_log_card hp_nn hp_sum + have hax : ∀ i, a i = Δ * p i := fun i ↦ by rw [hp]; field_simp + calc ∑ i, negMulLog (a i) + = ∑ i, (p i * negMulLog Δ + Δ * negMulLog (p i)) := by + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [hax i, negMulLog_mul] + _ = (∑ i, p i) * negMulLog Δ + Δ * ∑ i, negMulLog (p i) := by + rw [Finset.sum_add_distrib, ← Finset.sum_mul, ← Finset.mul_sum] + _ = negMulLog Δ + Δ * entropy p := by rw [hp_sum, one_mul, entropy_eq] + _ ≤ negMulLog Δ + Δ * Real.log (Fintype.card ι) := by gcongr + _ = Δ * Real.log (Fintype.card ι) + negMulLog Δ := by ring + +/-- **Grouping inequality** (the single-distribution kernel of Fano's inequality): for a +probability distribution `r : ι → ℝ` and a distinguished element `i₀`, the Shannon entropy is +bounded by the `q`-ary entropy of the "error probability" `1 - r i₀`: +`H(r) ≤ H_q(1 - r i₀)` with `q = |ι|`. Equivalently `entropy r ≤ binEntropy (1 - r i₀) + +(1 - r i₀) · log (|ι| - 1)`. Averaging this per-symbol over a conditioning variable yields +Fano's inequality. -/ +theorem entropy_le_qaryEntropy {r : ι → ℝ} (hr_nn : ∀ i, 0 ≤ r i) (hr_sum : ∑ i, r i = 1) + (i₀ : ι) : entropy r ≤ qaryEntropy (Fintype.card ι) (1 - r i₀) := by + classical + have : Nonempty ι := ⟨i₀⟩ + set e : ℝ := 1 - r i₀ with he_def + set t : Finset ι := Finset.univ.erase i₀ with ht_def + -- Mass on the complement of `i₀` is exactly the error probability `e`. + have ht_sum : ∑ i ∈ t, r i = e := by + have := Finset.add_sum_erase Finset.univ r (Finset.mem_univ i₀) + rw [he_def]; linarith [this, hr_sum] + -- The `q - 1` cast in `qaryEntropy` reconciles with the real-valued `card - 1`. + have hcast : ((Fintype.card ι : ℤ) - 1 : ℤ) = ((Fintype.card ι : ℝ) - 1 : ℝ) := by push_cast; ring + -- Unfold the `q`-ary entropy and split the entropy sum off at the `i₀` term. + rw [qaryEntropy_eq_log_add_binEntropy, binEntropy_eq_negMulLog_add_negMulLog_one_sub, hcast, + show (1 : ℝ) - e = r i₀ by rw [he_def]; ring, + entropy_eq, ← Finset.add_sum_erase Finset.univ _ (Finset.mem_univ i₀), ← ht_def] + -- The `negMulLog (r i₀)` terms cancel; it suffices to bound the complement sum `(★)`. + suffices h : ∑ i ∈ t, negMulLog (r i) ≤ negMulLog e + e * Real.log ((Fintype.card ι : ℝ) - 1) by + linarith + rcases t.eq_empty_or_nonempty with ht0 | ht1 + · -- `|ι| = 1`: the complement is empty, so `e = 0` and both sides vanish. + have he0 : e = 0 := by rw [← ht_sum, ht0, Finset.sum_empty] + rw [ht0, Finset.sum_empty, he0, negMulLog_zero, zero_mul, add_zero] + · -- `|ι| ≥ 2`: average over the complement with uniform weights `m⁻¹`, then rescale. + set m : ℝ := (t.card : ℝ) with hm_def + have hm_pos : 0 < m := by + rw [hm_def]; exact_mod_cast Finset.card_pos.mpr ht1 + have hm_card : m = (Fintype.card ι : ℝ) - 1 := by + rw [hm_def, ht_def, Finset.card_erase_of_mem (Finset.mem_univ i₀), Finset.card_univ, + Nat.cast_sub Fintype.card_pos, Nat.cast_one] + have hjensen : + ∑ i ∈ t, m⁻¹ • negMulLog (r i) ≤ negMulLog (∑ i ∈ t, m⁻¹ • r i) := by + refine concaveOn_negMulLog.le_map_sum (fun i _ ↦ by positivity) ?_ (fun i _ ↦ hr_nn i) + rw [Finset.sum_const, nsmul_eq_mul, ← hm_def, mul_inv_cancel₀ hm_pos.ne'] + have harg : ∑ i ∈ t, m⁻¹ • r i = m⁻¹ * e := by + rw [← Finset.smul_sum, ht_sum, smul_eq_mul] + rw [← Finset.smul_sum, smul_eq_mul, harg] at hjensen + -- Multiply the Jensen bound through by `m > 0` and simplify `m · negMulLog (e / m)`. + calc ∑ i ∈ t, negMulLog (r i) + = m * (m⁻¹ * ∑ i ∈ t, negMulLog (r i)) := by + rw [← mul_assoc, mul_inv_cancel₀ hm_pos.ne', one_mul] + _ ≤ m * negMulLog (m⁻¹ * e) := by gcongr + _ = negMulLog e + e * Real.log m := by + rw [negMulLog_mul, negMulLog_inv]; field_simp; ring + _ = negMulLog e + e * Real.log ((Fintype.card ι : ℝ) - 1) := by rw [hm_card] + +/-- **Sub-normalized cross-entropy bound** (the shared kernel of the support-aware Gibbs +inequalities): for `p, q : ι → ℝ` with `p ≥ 0`, `q ≥ 0`, the support condition `q i = 0 → p i = 0` +(the support of `p` is contained in that of `q`), and `q` carrying *at most* the total mass of `p` +(`∑ q ≤ ∑ p`), the Shannon entropy of `p` is at most the cross-entropy `-∑ p_i log q_i`. + +The per-term Gibbs bound `p i * log (q i / p i) ≤ q i - p i` (robust to `q i = 0`, where then +`p i = 0`) sums to `∑ p_i log (q_i / p_i) ≤ ∑ (q i - p i) = ∑ q - ∑ p ≤ 0`; splitting the left side +as `∑ p_i log q_i - ∑ p_i log p_i` gives `entropy p ≤ -∑ p_i log q_i`. Both the equal-mass +support-aware form (`entropy_le_cross_entropy_of_support_subset`) and the sub-normalized relative +entropy nonnegativity (`relativeEntropy_nonneg_of_sum_le`) are corollaries. -/ +theorem entropy_le_cross_entropy_of_sum_le {p q : ι → ℝ} + (hp_nn : ∀ i, 0 ≤ p i) (hq_nn : ∀ i, 0 ≤ q i) (hsupp : ∀ i, q i = 0 → p i = 0) + (hqp_sum : ∑ i, q i ≤ ∑ i, p i) : + entropy p ≤ -∑ i, p i * Real.log (q i) := by + -- Per-term Gibbs bound `pᵢ log (qᵢ / pᵢ) ≤ qᵢ - pᵢ`, robust to `qᵢ = 0` since then `pᵢ = 0`. + have hterm : ∀ i, p i * Real.log (q i / p i) ≤ q i - p i := fun i ↦ by + rcases eq_or_lt_of_le (hq_nn i) with hq0 | hq0 + · simp [← hq0, hsupp i hq0.symm] + · exact mul_log_div_le_sub_of_nonneg (hp_nn i) hq0 + have h_sum_le : ∑ i, p i * Real.log (q i / p i) ≤ 0 := + calc ∑ i, p i * Real.log (q i / p i) + ≤ ∑ i, (q i - p i) := Finset.sum_le_sum fun i _ ↦ hterm i + _ = (∑ i, q i) - ∑ i, p i := by rw [Finset.sum_sub_distrib] + _ ≤ 0 := by linarith + -- Split `pᵢ log (qᵢ / pᵢ) = pᵢ log qᵢ - pᵢ log pᵢ`, again handling `qᵢ = 0 ⟹ pᵢ = 0`. + have h_sum_split : ∑ i, p i * Real.log (q i / p i) = + ∑ i, p i * Real.log (q i) - ∑ i, p i * Real.log (p i) := by + rw [← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rcases eq_or_lt_of_le (hp_nn i) with hp0 | hp0 + · simp [← hp0] + · rw [Real.log_div (fun hq0 ↦ hp0.ne' (hsupp i hq0)) hp0.ne', mul_sub] + simp only [entropy_eq, Real.negMulLog, neg_mul, Finset.sum_neg_distrib, neg_le_neg_iff] + linarith [h_sum_le, h_sum_split] + +/-- **Gibbs' inequality with support condition** (classical Klein's inequality, general +form): for `p, q : ι → ℝ` with `p ≥ 0`, `q ≥ 0`, equal total mass `∑ p = ∑ q`, and the +support condition `q i = 0 → p i = 0` (the support of `p` is contained in that of `q`), the +Shannon entropy of `p` is at most the cross-entropy `-∑ p_i log q_i`. + +The equal-mass specialization of `entropy_le_cross_entropy_of_sum_le` (`∑ q ≤ ∑ p` degenerating to +`∑ q = ∑ p`); itself the support-aware generalization of `entropy_le_cross_entropy_of_sum_eq_one`, +absorbing the `q i = 0` terms (where then `p i = 0`) so no strict positivity of `q` is needed. -/ +theorem entropy_le_cross_entropy_of_support_subset {p q : ι → ℝ} + (hp_nn : ∀ i, 0 ≤ p i) (hq_nn : ∀ i, 0 ≤ q i) (hsupp : ∀ i, q i = 0 → p i = 0) + (hpq_sum : ∑ i, p i = ∑ i, q i) : + entropy p ≤ -∑ i, p i * Real.log (q i) := + entropy_le_cross_entropy_of_sum_le hp_nn hq_nn hsupp hpq_sum.ge + +/-- **Gibbs' inequality** (classical Klein's inequality at the discrete-distribution level): +for probability distributions `p, q : ι → ℝ` (`p ≥ 0`, `q > 0`, each summing to one), the +Shannon entropy of `p` is at most the cross-entropy `-∑ p_i log q_i`. Equivalently the +Kullback–Leibler divergence `∑ p_i log (p_i / q_i)` is nonneg. + +The strictly-positive-`q` corollary of `entropy_le_cross_entropy_of_support_subset`. The +classical input to Nielsen–Chuang Theorem 11.7 (operator Klein's inequality) via spectral +decomposition + Jensen on `log`. -/ +theorem entropy_le_cross_entropy_of_sum_eq_one + {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) (hq_pos : ∀ i, 0 < q i) + (hp_sum : ∑ i, p i = 1) (hq_sum : ∑ i, q i = 1) : + entropy p ≤ -∑ i, p i * Real.log (q i) := + entropy_le_cross_entropy_of_support_subset hp_nn (fun i ↦ (hq_pos i).le) + (fun i hq0 ↦ absurd hq0 (hq_pos i).ne') (by rw [hp_sum, hq_sum]) + +/-- **Gibbs' inequality** / nonnegativity of the classical relative entropy: `D(p‖q) ≥ 0` for +probability distributions `p`, `q` with `q` strictly positive. -/ +theorem relativeEntropy_nonneg {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) + (hq_pos : ∀ i, 0 < q i) (hp_sum : ∑ i, p i = 1) (hq_sum : ∑ i, q i = 1) : + 0 ≤ relativeEntropy p q := by + rw [relativeEntropy_eq_sub] + have h := entropy_le_cross_entropy_of_sum_eq_one hp_nn hq_pos hp_sum hq_sum + linarith [entropy_eq_neg_sum_mul_log p] + +/-- Nonnegativity of the classical relative entropy under a support condition (absolute +continuity): `D(p‖q) ≥ 0` when `supp p ⊆ supp q` (encoded as `q i = 0 → p i = 0`) and `p`, `q` +have equal total mass. -/ +theorem relativeEntropy_nonneg_of_support_subset {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) + (hq_nn : ∀ i, 0 ≤ q i) (hsupp : ∀ i, q i = 0 → p i = 0) (hpq_sum : ∑ i, p i = ∑ i, q i) : + 0 ≤ relativeEntropy p q := by + rw [relativeEntropy_eq_sub] + have h := entropy_le_cross_entropy_of_support_subset hp_nn hq_nn hsupp hpq_sum + linarith [entropy_eq_neg_sum_mul_log p] + +/-- **Sub-normalized Gibbs' inequality**: the classical relative entropy `D(p‖q)` is nonnegative +even when the reference `q` carries *at most* the total mass of `p` (`∑ q ≤ ∑ p`), keeping the +nonnegativity `p ≥ 0`, `q ≥ 0` and the absolute-continuity (support) condition `q i = 0 → p i = 0`. +This generalizes `Real.relativeEntropy_nonneg_of_support_subset` (which needs *equal* total mass) to +a *sub-probability* reference: through the shared kernel `entropy_le_cross_entropy_of_sum_le`, the +per-term Gibbs bound `p i * log (q i / p i) ≤ q i - p i` sums to +`-D(p‖q) ≤ ∑ (q i - p i) = ∑ q - ∑ p ≤ 0`, so `D(p‖q) ≥ 0`. Used to deduce `H(Y | X) ≥ 0` from the +relative-entropy expression of the conditional entropy (Nielsen & Chuang, Exercise 11.7), whose +reference distribution `q(x, y) = p(x, y)² / p_X(x)` is only sub-normalized (`∑ q ≤ 1`). -/ +theorem relativeEntropy_nonneg_of_sum_le {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) + (hq_nn : ∀ i, 0 ≤ q i) (hsupp : ∀ i, q i = 0 → p i = 0) (hqp_sum : ∑ i, q i ≤ ∑ i, p i) : + 0 ≤ relativeEntropy p q := by + rw [relativeEntropy_eq_sub] + have h := entropy_le_cross_entropy_of_sum_le hp_nn hq_nn hsupp hqp_sum + linarith [entropy_eq_neg_sum_mul_log p] + +/-- **Equality condition for Gibbs' inequality** (Nielsen–Chuang Theorem 11.1): for +`p, q : ι → ℝ` with `p ≥ 0`, `q ≥ 0`, equal total mass `∑ p = ∑ q`, and the absolute-continuity +(support) condition `q x = 0 → p x = 0`, the classical relative entropy vanishes if and only if +the distributions are equal, `D(p‖q) = 0 ↔ p = q`. + +Together with `Real.relativeEntropy_nonneg_of_support_subset` (the `≥ 0` half at the same +generality) this is the faithful real-valued rendering of N&C Theorem 11.1: "the relative entropy +is non-negative, with equality if and only if `p = q`". The support hypothesis is precisely the +domain on which the real-valued `relativeEntropy` (using the junk value `log 0 = 0`) coincides +with N&C's `H(p‖q)`; where `supp p ⊄ supp q`, N&C set `−p log 0 ≡ +∞` (p. 504), so there +`H(p‖q) = +∞ > 0` with `p ≠ q` — consistent with the theorem but outside the finite real-valued +encoding. The strictly-positive-`q` case is the specialization `hsupp := fun i hq0 ↦ …`. + +**Proof.** The support-aware pointwise Gibbs bound `p x * log (q x / p x) ≤ q x - p x` sums to +`-D(p‖q) ≤ ∑ (q x - p x) = 0`. When `D(p‖q) = 0` both sums equal `0`, so by +`Finset.sum_eq_sum_iff_of_le` the bound is an equality termwise; at each `x` either `q x = 0` +(then `p x = 0 = q x` by the support hypothesis) or `q x > 0`, where the strict companion +`Real.mul_log_div_lt_sub_of_ne` forces `p x = q x`. The converse is `Real.relativeEntropy_self`. -/ +theorem relativeEntropy_eq_zero_iff {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) (hq_nn : ∀ i, 0 ≤ q i) + (hsupp : ∀ i, q i = 0 → p i = 0) (hpq_sum : ∑ i, p i = ∑ i, q i) : + relativeEntropy p q = 0 ↔ p = q := by + refine ⟨fun h ↦ ?_, ?_⟩ + · -- Support-aware pointwise Gibbs bound; summed it is `-D(p‖q) ≤ 0`, so `D = 0` forces equality. + have hle : ∀ i ∈ Finset.univ, p i * Real.log (q i / p i) ≤ q i - p i := by + intro i _ + rcases eq_or_lt_of_le (hq_nn i) with hq0 | hq0 + · simp [← hq0, hsupp i hq0.symm] + · exact mul_log_div_le_sub_of_nonneg (hp_nn i) hq0 + have hsum_g : ∑ i, p i * Real.log (q i / p i) = 0 := by + -- Split `p x log (q x / p x) = p x log (q x) - p x log (p x)`, using `p x = 0 → term = 0` + -- and, on `p x > 0`, that `q x ≠ 0` (else `p x = 0` by `hsupp`). + have hsplit : ∑ i, p i * Real.log (q i / p i) + = ∑ i, p i * Real.log (q i) - ∑ i, p i * Real.log (p i) := by + rw [← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rcases eq_or_lt_of_le (hp_nn i) with hp0 | hp0 + · simp [← hp0] + · rw [Real.log_div (fun hq0 ↦ hp0.ne' (hsupp i hq0)) hp0.ne', mul_sub] + rw [hsplit] + linarith [relativeEntropy_eq_sub p q, h] + have hsum_qp : ∑ i, (q i - p i) = 0 := by + rw [Finset.sum_sub_distrib, hpq_sum, sub_self] + have hpt := (Finset.sum_eq_sum_iff_of_le hle).mp (hsum_g.trans hsum_qp.symm) + funext i + rcases eq_or_lt_of_le (hq_nn i) with hq0 | hq0 + · rw [hsupp i hq0.symm]; exact hq0 + · by_contra hne + exact absurd (hpt i (Finset.mem_univ i)) + (ne_of_lt (mul_log_div_lt_sub_of_ne (hp_nn i) hq0 hne)) + · rintro rfl + exact relativeEntropy_self p + +/-- **Strict positivity of the relative entropy for distinct distributions**: the "with equality +if and only if `p = q`" clause of Nielsen–Chuang Theorem 11.1 in its sharp contrapositive form — +`D(p‖q) > 0` whenever `p ≠ q`, for `p ≥ 0`, `q ≥ 0` with equal total mass `∑ p = ∑ q` and +`supp p ⊆ supp q` (`q x = 0 → p x = 0`). Combines +`Real.relativeEntropy_nonneg_of_support_subset` with `Real.relativeEntropy_eq_zero_iff`. -/ +theorem relativeEntropy_pos_of_ne {p q : ι → ℝ} (hp_nn : ∀ i, 0 ≤ p i) (hq_nn : ∀ i, 0 ≤ q i) + (hsupp : ∀ i, q i = 0 → p i = 0) (hpq_sum : ∑ i, p i = ∑ i, q i) (hpq : p ≠ q) : + 0 < relativeEntropy p q := by + refine lt_of_le_of_ne + (relativeEntropy_nonneg_of_support_subset hp_nn hq_nn hsupp hpq_sum) fun h ↦ ?_ + exact hpq ((relativeEntropy_eq_zero_iff hp_nn hq_nn hsupp hpq_sum).mp h.symm) + +/-- **Doubly-stochastic Klein-classical bound**: for probability distributions `p : ι → ℝ` and +`q : κ → ℝ`, and a doubly-stochastic matrix `W : ι → κ → ℝ` (entries nonneg, both row sums and +column sums equal to 1), the bound `∑ᵢ pᵢ * ∑ⱼ Wᵢⱼ * log qⱼ ≤ -entropy p` holds. + +**Proof.** Inner Jensen on `Real.log` (concave) gives `∑ⱼ Wᵢⱼ log qⱼ ≤ log rᵢ` where +`rᵢ := ∑ⱼ Wᵢⱼ qⱼ`. The `rᵢ` form a probability distribution (sum to 1 via `W`'s row-sum-1 +and `q`'s sum-to-1). Outer classical Gibbs (`entropy_le_cross_entropy_of_sum_eq_one`) on +`(p, r)` gives `entropy p ≤ -∑ᵢ pᵢ log rᵢ`, i.e., `∑ᵢ pᵢ log rᵢ ≤ -entropy p`. Combine. + +The classical input to operator Klein's inequality (Nielsen–Chuang Theorem 11.7) via spectral +decomposition: take `Wᵢⱼ := ‖⟨fⱼ, eᵢ⟩‖²` where `eᵢ, fⱼ` are orthonormal eigenbases — `W` is +doubly-stochastic by Parseval. -/ +theorem sum_mul_sum_mul_log_le_neg_entropy_of_doubly_stochastic + {κ : Type*} [Fintype κ] + {p : ι → ℝ} {q : κ → ℝ} {W : ι → κ → ℝ} + (hp_nn : ∀ i, 0 ≤ p i) (hq_pos : ∀ j, 0 < q j) + (hp_sum : ∑ i, p i = 1) (hq_sum : ∑ j, q j = 1) + (hW_nn : ∀ i j, 0 ≤ W i j) + (hW_row_sum : ∀ i, ∑ j, W i j = 1) + (hW_col_sum : ∀ j, ∑ i, W i j = 1) : + ∑ i, p i * ∑ j, W i j * Real.log (q j) ≤ -entropy p := by + -- Bridge distribution `rᵢ := ∑ⱼ Wᵢⱼ qⱼ`: inner Jensen on `log` (concave) bounds + -- `∑ⱼ Wᵢⱼ log qⱼ ≤ log rᵢ`; multiplying by `pᵢ ≥ 0` and summing gives the LHS bound by + -- `∑ᵢ pᵢ log rᵢ`, which classical Gibbs (`entropy_le_cross_entropy_of_sum_eq_one`) then + -- bounds by `-entropy p`. `r` is a probability distribution: positive via + -- `Finset.sum_pos_iff_of_nonneg` on row sum 1, sums to 1 via `sum_comm` + column sum. + refine (Finset.sum_le_sum fun i _ ↦ mul_le_mul_of_nonneg_left ?_ (hp_nn i)).trans + (le_neg.mp <| entropy_le_cross_entropy_of_sum_eq_one + (q := fun i ↦ ∑ j, W i j * q j) hp_nn (fun i ↦ ?_) hp_sum ?_) + · simpa [smul_eq_mul] using strictConcaveOn_log_Ioi.concaveOn.le_map_sum + (t := Finset.univ) (w := W i) (p := q) + (fun j _ ↦ hW_nn i j) (hW_row_sum i) (fun j _ ↦ hq_pos j) + · refine Finset.sum_pos' (fun j _ ↦ mul_nonneg (hW_nn i j) (hq_pos j).le) ?_ + obtain ⟨j, hj, hj_pos⟩ := (Finset.sum_pos_iff_of_nonneg fun j _ ↦ hW_nn i j).mp + (hW_row_sum i ▸ one_pos) + exact ⟨j, hj, mul_pos hj_pos (hq_pos j)⟩ + · simp_rw [Finset.sum_comm (f := fun i j ↦ W i j * q j), ← Finset.sum_mul] + simp [hW_col_sum, hq_sum] + +/-- The set of nonneg real-valued functions on `ι`, on which `entropy` is concave. -/ +def entropyDomain (ι : Type*) : Set (ι → ℝ) := Set.univ.pi fun _ ↦ Set.Ici (0 : ℝ) + +omit [Fintype ι] in +theorem convex_entropyDomain : Convex ℝ (entropyDomain ι) := + convex_pi fun _ _ ↦ convex_Ici 0 + +/-- **Concavity of Shannon entropy** on the convex set of nonneg-valued functions. Each +summand `p ↦ negMulLog (p i)` is concave via `concaveOn_negMulLog` composed with the +linear projection `p ↦ p i`; then `ConcaveOn.sum` lifts to the Finset-sum. -/ +theorem entropy_concave : ConcaveOn ℝ (entropyDomain ι) entropy := by + refine ConcaveOn.sum convex_entropyDomain fun i _ ↦ ?_ + refine (concaveOn_negMulLog.comp_linearMap + (LinearMap.proj i : (ι → ℝ) →ₗ[ℝ] ℝ)).subset ?_ convex_entropyDomain + intro p hp + exact hp i (Set.mem_univ _) + +/-! ### Continuity of `negMulLog` — the analytic kernel of Fannes' inequality + +The single-variable estimates behind Nielsen–Chuang Theorem 11.6 (eq. 11.47): `negMulLog` +is its own modulus of continuity on scales `≤ 1/2`, and is monotone up to its maximum at +`e⁻¹`. Stated for `Real.negMulLog` directly so they compose with the spectral development. -/ + +/-- For `δ ∈ [0, 1/2]`, `η(1 - δ) ≤ η(δ)` where `η = Real.negMulLog`. This is the endpoint +estimate in Fannes' continuity bound (Nielsen–Chuang eq. 11.47): the difference +`φ δ := η δ - η (1 - δ)` is concave on `[0, 1/2]` (its derivative `-log δ - log (1 - δ) - 2` +is strictly decreasing there) and vanishes at both endpoints, hence is nonnegative. -/ +theorem negMulLog_one_sub_le {δ : ℝ} (h0 : 0 ≤ δ) (h : δ ≤ 1 / 2) : + Real.negMulLog (1 - δ) ≤ Real.negMulLog δ := by + set φ : ℝ → ℝ := fun t => Real.negMulLog t - Real.negMulLog (1 - t) with hφ + have hcont : ContinuousOn φ (Set.Icc 0 (1 / 2 : ℝ)) := + (Real.continuous_negMulLog.sub + (Real.continuous_negMulLog.comp (continuous_const.sub continuous_id))).continuousOn + -- `deriv φ t = -log t - log (1 - t) - 2` on the open interval, via the chain rule. + have hderiv : ∀ t ∈ Set.Ioo (0 : ℝ) (1 / 2), + deriv φ t = -Real.log t - Real.log (1 - t) - 2 := by + intro t ht + obtain ⟨ht0, ht1⟩ := ht + have ht1ne : (1 : ℝ) - t ≠ 0 := by have : t < 1 := by linarith + linarith + have d1 : HasDerivAt Real.negMulLog (-Real.log t - 1) t := + Real.hasDerivAt_negMulLog (ne_of_gt ht0) + have d2 : HasDerivAt (fun s => Real.negMulLog (1 - s)) ((-Real.log (1 - t) - 1) * (-1)) t := + (Real.hasDerivAt_negMulLog ht1ne).comp t ((hasDerivAt_id t).const_sub 1) + have hφd : HasDerivAt φ (-Real.log t - Real.log (1 - t) - 2) t := by + rw [hφ]; convert d1.sub d2 using 1; ring + exact hφd.deriv + -- `deriv φ` is strictly antitone on the interior, so `φ` is concave. + have hanti : StrictAntiOn (deriv φ) (interior (Set.Icc 0 (1 / 2 : ℝ))) := by + rw [interior_Icc] + intro a ha b hb hab + rw [hderiv a ha, hderiv b hb] + obtain ⟨ha0, ha1⟩ := ha; obtain ⟨hb0, hb1⟩ := hb + have hprod : a * (1 - a) < b * (1 - b) := by nlinarith + have hlog : Real.log (a * (1 - a)) < Real.log (b * (1 - b)) := + Real.log_lt_log (mul_pos ha0 (by linarith)) hprod + rw [Real.log_mul (ne_of_gt ha0) (by linarith), + Real.log_mul (ne_of_gt hb0) (by linarith)] at hlog + linarith + have hconc : ConcaveOn ℝ (Set.Icc 0 (1 / 2 : ℝ)) φ := + (StrictAntiOn.strictConcaveOn_of_deriv (convex_Icc _ _) hcont hanti).concaveOn + -- `φ` is nonnegative on `[0, 1/2]` since it is concave with `φ 0 = φ (1/2) = 0`. + have key := hconc.min_le_of_mem_Icc (x := 0) (y := 1 / 2) (z := δ) + (by norm_num) (by norm_num) ⟨h0, h⟩ + have h0' : φ 0 = 0 := by rw [hφ]; simp + have h12 : φ (1 / 2 : ℝ) = 0 := by rw [hφ]; norm_num + rw [h0', h12] at key; simp only [min_self] at key; rw [hφ] at key; simp only at key + linarith [key] + +/-- The increment `t ↦ negMulLog t - negMulLog (t + δ)` is monotone (nondecreasing) on +`[0, ∞)` for any `δ ≥ 0`: its derivative `log (t + δ) - log t` is nonnegative. Equivalently, +by concavity of `negMulLog` the increment `negMulLog (t + δ) - negMulLog t` shrinks as `t` +grows. Both directions of `Real.abs_negMulLog_sub_le` reduce to this monotonicity. -/ +theorem monotoneOn_negMulLog_sub_add {δ : ℝ} (hδ : 0 ≤ δ) : + MonotoneOn (fun t => Real.negMulLog t - Real.negMulLog (t + δ)) (Set.Ici (0 : ℝ)) := by + have hgderiv : ∀ t : ℝ, 0 < t → + HasDerivAt (fun s => Real.negMulLog s - Real.negMulLog (s + δ)) + (Real.log (t + δ) - Real.log t) t := by + intro t ht + have ht'ne : t + δ ≠ 0 := ne_of_gt (by positivity) + have d1 : HasDerivAt Real.negMulLog (-Real.log t - 1) t := + Real.hasDerivAt_negMulLog (ne_of_gt ht) + have d2 : HasDerivAt (fun s => Real.negMulLog (s + δ)) (-Real.log (t + δ) - 1) t := by + have := (Real.hasDerivAt_negMulLog ht'ne).comp t ((hasDerivAt_id t).add_const δ) + simpa [Function.comp_def] using this + convert d1.sub d2 using 1; ring + apply monotoneOn_of_deriv_nonneg (convex_Ici _) + · exact (Real.continuous_negMulLog.sub + (Real.continuous_negMulLog.comp (continuous_id.add continuous_const))).continuousOn + · rw [interior_Ici] + exact fun t ht => (hgderiv t ht).differentiableAt.differentiableWithinAt + · rw [interior_Ici] + intro t ht + rw [(hgderiv t ht).deriv] + have : Real.log t ≤ Real.log (t + δ) := Real.log_le_log ht (by linarith) + linarith + +/-- Single-increment form of Fannes' continuity bound: for a base point `y ≥ 0` and a step +`δ ∈ [0, 1/2]` with `y + δ ≤ 1`, `|negMulLog (y + δ) - negMulLog y| ≤ negMulLog δ`. The upper +bound is subadditivity of `negMulLog` (increment monotonicity evaluated at `0 ≤ y`); the lower +bound is the same monotonicity up to `y ≤ 1 - δ` combined with `negMulLog_one_sub_le`. -/ +theorem abs_negMulLog_add_sub_le {y δ : ℝ} (hy : 0 ≤ y) (hδ : 0 ≤ δ) (hδ2 : δ ≤ 1 / 2) + (hyδ : y + δ ≤ 1) : + |Real.negMulLog (y + δ) - Real.negMulLog y| ≤ Real.negMulLog δ := by + set g : ℝ → ℝ := fun t => Real.negMulLog t - Real.negMulLog (t + δ) with hg + have hmono := monotoneOn_negMulLog_sub_add hδ + have hgy : Real.negMulLog (y + δ) - Real.negMulLog y = -(g y) := by rw [hg]; ring + rw [hgy, abs_neg, abs_le] + refine ⟨?_, ?_⟩ + · have hstep : g 0 ≤ g y := hmono Set.self_mem_Ici (Set.mem_Ici.mpr hy) hy + have hg0 : g 0 = -Real.negMulLog δ := by rw [hg]; simp + rw [hg0] at hstep; linarith + · have h1δ : (0 : ℝ) ≤ 1 - δ := by linarith + have hstep : g y ≤ g (1 - δ) := + hmono (Set.mem_Ici.mpr hy) (Set.mem_Ici.mpr h1δ) (by linarith) + have hg1 : g (1 - δ) = Real.negMulLog (1 - δ) := by rw [hg]; simp + rw [hg1] at hstep + linarith [negMulLog_one_sub_le hδ hδ2] + +/-- **Continuity kernel of Fannes' inequality** (Nielsen–Chuang Theorem 11.6, eq. 11.47): for +`x, y ∈ [0, 1]` with `|x - y| ≤ 1/2`, +`|negMulLog x - negMulLog y| ≤ negMulLog |x - y|`. +So `η = Real.negMulLog` serves as its own modulus of continuity on scales `≤ 1/2`. Applied to +paired sorted eigenvalues `x = rᵢ`, `y = sᵢ ∈ [0, 1]` of density operators, this is the +per-eigenvalue estimate summed in the proof of Fannes' inequality. -/ +theorem abs_negMulLog_sub_le {x y : ℝ} (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hy0 : 0 ≤ y) + (hy1 : y ≤ 1) (hxy : |x - y| ≤ 1 / 2) : + |Real.negMulLog x - Real.negMulLog y| ≤ Real.negMulLog |x - y| := by + rcases le_total y x with hyx | hxy' + · have hδ0 : 0 ≤ x - y := by linarith + have habs : |x - y| = x - y := abs_of_nonneg hδ0 + rw [habs] + have key := abs_negMulLog_add_sub_le (y := y) (δ := x - y) hy0 hδ0 (habs ▸ hxy) (by linarith) + have hx_eq : y + (x - y) = x := by ring + rwa [hx_eq] at key + · have hδ0 : 0 ≤ y - x := by linarith + have habs : |x - y| = y - x := by rw [abs_sub_comm]; exact abs_of_nonneg hδ0 + rw [habs, abs_sub_comm] + have key := abs_negMulLog_add_sub_le (y := x) (δ := y - x) hx0 hδ0 (habs ▸ hxy) (by linarith) + have hy_eq : x + (y - x) = y := by ring + rwa [hy_eq] at key + +/-- `Real.negMulLog` is strictly increasing on `[0, e⁻¹]`, i.e. on the interval up to its +maximum: there `deriv negMulLog x = -log x - 1 > 0`. Used to lift Fannes' bound from the +summed eigenvalue-difference `Δ` to the trace distance `T ≥ Δ` when `T ≤ e⁻¹` +(monotonicity of `η` on `[0, e⁻¹]`, Nielsen–Chuang eq. 11.49). -/ +theorem strictMonoOn_negMulLog_Icc : + StrictMonoOn Real.negMulLog (Set.Icc 0 (Real.exp (-1))) := by + apply strictMonoOn_of_deriv_pos (convex_Icc _ _) Real.continuous_negMulLog.continuousOn + intro x hx + rw [interior_Icc] at hx + obtain ⟨hx0, hx1⟩ := hx + rw [Real.deriv_negMulLog (ne_of_gt hx0)] + have : Real.log x < -1 := by + have := Real.log_lt_log hx0 hx1 + rwa [Real.log_exp] at this + linarith + +/-- `Real.negMulLog` attains its maximum value `e⁻¹` at `x = e⁻¹`, so `negMulLog x ≤ e⁻¹` for all +`x ≥ 0`. (The hypothesis `0 ≤ x` is essential: `negMulLog` uses `Real.log |x|`, so for `x < 0` the +value `-x * log x` is unbounded above.) This is the constant appearing in the weaker unconditional +form of Fannes' inequality (Nielsen–Chuang eq. (11.45)). The proof reduces to the tangent-line +bound `log t ≤ t - 1` (`Real.log_le_sub_one_of_pos`) applied at `t = 1 / (x * e)`, which gives +`-log x ≤ 1 / (x * e)`; multiplying by `x` yields `-x log x ≤ e⁻¹`. -/ +theorem negMulLog_le_exp_neg_one {x : ℝ} (hx : 0 ≤ x) : Real.negMulLog x ≤ Real.exp (-1) := by + rcases eq_or_lt_of_le hx with rfl | hx + · rw [Real.negMulLog_zero]; exact (Real.exp_pos _).le + · rw [Real.negMulLog] + have he : (0 : ℝ) < Real.exp 1 := Real.exp_pos 1 + have hxe : (0 : ℝ) < x * Real.exp 1 := by positivity + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 1 / (x * Real.exp 1) by positivity) + rw [Real.log_div one_ne_zero (ne_of_gt hxe), Real.log_one, zero_sub, + Real.log_mul (ne_of_gt hx) (ne_of_gt he), Real.log_exp] at h + rw [Real.exp_neg] + have hstep : -Real.log x ≤ 1 / (x * Real.exp 1) := by linarith + calc -x * Real.log x = x * (-Real.log x) := by ring + _ ≤ x * (1 / (x * Real.exp 1)) := mul_le_mul_of_nonneg_left hstep (le_of_lt hx) + _ = (Real.exp 1)⁻¹ := by field_simp + +/-- Shannon entropy of the symmetric two-point distribution `((1 + t)/2, (1 - t)/2)` is at most +that of `(p, 1 - p)` whenever `|2p - 1| ≤ t ≤ 1` and `p ∈ [0, 1]`. Both sides are binary entropies +(`entropy_fin_two_eq_binEntropy`), and `binEntropy` is antitone on `[1/2, 1]` +(`binEntropy_strictAntiOn`) and symmetric (`binEntropy_one_sub`), so the claim reduces to +`max p (1 - p) ≤ (1 + t)/2`, i.e. `|2p - 1| ≤ t`. -/ +theorem entropy_pair_le {p t : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ht1 : t ≤ 1) (h : |2 * p - 1| ≤ t) : + entropy ![(1 + t) / 2, (1 - t) / 2] ≤ entropy ![p, 1 - p] := by + have ht0 : 0 ≤ t := le_trans (abs_nonneg _) h + rw [entropy_fin_two_eq_binEntropy p, show (1 - t) / 2 = 1 - (1 + t) / 2 by ring, + entropy_fin_two_eq_binEntropy] + have hmem : (1 + t) / 2 ∈ Set.Icc (2⁻¹ : ℝ) 1 := ⟨by linarith, by linarith⟩ + rcases le_total p (2⁻¹ : ℝ) with hp | hp + · rw [← binEntropy_one_sub p] + refine binEntropy_strictAntiOn.antitoneOn ⟨by linarith, by linarith⟩ hmem ?_ + have := (abs_le.mp h).1; linarith + · refine binEntropy_strictAntiOn.antitoneOn ⟨hp, hp1⟩ hmem ?_ + have := (abs_le.mp h).2; linarith + +/-- Strict version of `entropy_pair_le`: for `|2p - 1| < t ≤ 1` and `p ∈ [0, 1]`, the Shannon +entropy of `((1 + t)/2, (1 - t)/2)` is strictly below that of `(p, 1 - p)`. -/ +theorem entropy_pair_lt {p t : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (ht1 : t ≤ 1) (h : |2 * p - 1| < t) : + entropy ![(1 + t) / 2, (1 - t) / 2] < entropy ![p, 1 - p] := by + have ht0 : 0 ≤ t := le_trans (abs_nonneg _) h.le + rw [entropy_fin_two_eq_binEntropy p, show (1 - t) / 2 = 1 - (1 + t) / 2 by ring, + entropy_fin_two_eq_binEntropy] + have hmem : (1 + t) / 2 ∈ Set.Icc (2⁻¹ : ℝ) 1 := ⟨by linarith, by linarith⟩ + rcases le_total p (2⁻¹ : ℝ) with hp | hp + · rw [← binEntropy_one_sub p] + refine binEntropy_strictAntiOn ⟨by linarith, by linarith⟩ hmem ?_ + have := (abs_lt.mp h).1; linarith + · refine binEntropy_strictAntiOn ⟨hp, hp1⟩ hmem ?_ + have := (abs_lt.mp h).2; linarith + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Analysis/SpecificLimits/ExpNatMul.lean b/LeanPool/AxQM/ToMathlib/Analysis/SpecificLimits/ExpNatMul.lean new file mode 100644 index 0000000000..238e8bb505 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Analysis/SpecificLimits/ExpNatMul.lean @@ -0,0 +1,46 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Complex.Exponential +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# Exponential decay of `Real.exp (n · c)` for negative `c` + +A small `SpecificLimits` companion. For a fixed negative rate `c < 0`, the sequence +`Real.exp (n · c)` — geometric in `n` with ratio `Real.exp c ∈ [0, 1)` — tends to `0` as +`n → ∞` over `ℕ`. + +This is the elementary exponential-decay estimate that a coding argument reuses whenever a rate +below a threshold makes an exponential term vanish (e.g. the confusion / typical-defect terms of the +Holevo–Schumacher–Westmoreland theorem, Nielsen & Chuang, Theorem 12.8, Box 12.5, whose per-block +error bounds carry factors `exp (−n · β)` with `β > 0`). + +## Main results + +- `Real.tendsto_exp_nat_mul_atTop_nhds_zero`: `Real.exp (n · c) → 0` for `c < 0`. +-/ + +@[expose] public section + +open Filter Topology + +namespace Real + +/-- **Exponential decay** `Real.exp (n · c) → 0` as `n → ∞` over `ℕ`, for any negative rate `c < 0`. +Since `Real.exp (n · c) = (Real.exp c) ^ n` (`Real.exp_nat_mul`) with base +`Real.exp c ∈ [0, 1)` (positive, and `< 1` iff `c < 0` via `Real.exp_lt_one_iff`), this is the +geometric limit `tendsto_pow_atTop_nhds_zero_of_lt_one`. -/ +theorem tendsto_exp_nat_mul_atTop_nhds_zero {c : ℝ} (hc : c < 0) : + Tendsto (fun n : ℕ => Real.exp (n * c)) atTop (𝓝 0) := by + simp only [Real.exp_nat_mul] + exact tendsto_pow_atTop_nhds_zero_of_lt_one (Real.exp_pos _).le (Real.exp_lt_one_iff.mpr hc) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/Data/Fintype/EquivOfMultisetMap.lean b/LeanPool/AxQM/ToMathlib/Data/Fintype/EquivOfMultisetMap.lean new file mode 100644 index 0000000000..fd091ddf72 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Data/Fintype/EquivOfMultisetMap.lean @@ -0,0 +1,67 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Data.Fintype.EquivFin +public import Mathlib.Logic.Equiv.Basic + +/-! +# An index bijection from equal image multisets + +For finitely-indexed families `f : ι → α` and `g : κ → α` over (possibly different) finite index +types, `exists_equiv_of_map_univ_val_eq` produces a *value-preserving* bijection `e : ι ≃ κ` — one +with `g (e i) = f i` for every `i` — from the single hypothesis that the two image multisets agree, +`Multiset.map f univ.val = Multiset.map g univ.val`. + +This is a general `Fintype`/`Multiset`/`Equiv` fact with no dependence on order, convexity, or +analysis. It is the rigidity tool shared by majorization-up-to-reindexing +(`ToMathlib/Analysis/Convex/Majorization.lean`, `majorize_congr_multiset`) and the `≅`-relation on +vectors (`ToMathlib/Analysis/Convex/SameNonzero.lean`, `SameNonzero.exists_equiv`): identical +multisets of values pin down a permutation of the indices. + +## Main statements + +* `exists_equiv_of_map_univ_val_eq`: equal image multisets give a value-preserving index bijection. +-/ + +public section + +variable {α ι κ : Type*} + +/-- The number of indices a finitely-indexed family `F : β → α` sends to a fixed value `c` is the +multiplicity of `c` in the family's image multiset: `#{i // F i = c} = count c (map F univ.val)` +(`Fintype.card_subtype` re-presents the fiber as `univ.filter`; `Multiset.count_map` re-presents the +count as the same filter, up to `eq_comm` in the predicate). The fiber-counting step of +`exists_equiv_of_map_univ_val_eq`, factored out so the `f`- and `g`-side counts share one proof: +they sit in different index universes, so a single in-proof `have` cannot serve both. -/ +private theorem card_fiber_eq_count {β α : Type*} [Fintype β] [DecidableEq α] (F : β → α) (c : α) : + Fintype.card {i // F i = c} = Multiset.count c (Multiset.map F Finset.univ.val) := by + rw [Fintype.card_subtype, Multiset.count_map, Finset.card_def, Finset.filter_val] + exact congrArg Multiset.card (Multiset.filter_congr fun x _ => eq_comm) + +/-- **Equal full multisets give a value-preserving index bijection.** If two finitely-indexed +families `f : ι → α` and `g : κ → α` have equal image multisets over their whole index types +(`Multiset.map f univ.val = Multiset.map g univ.val`), then there is a bijection `e : ι ≃ κ` +matching the values entry-by-entry, `g (e i) = f i`. Identical multisets of values (not just +identical non-zero parts) pin down a permutation of the indices. + +Proof: for each value `c`, the two fibers `{i // f i = c}` and `{j // g j = c}` have equal +cardinality — each is the multiplicity of `c` in the respective image multiset +(`card_fiber_eq_count`), and those multiplicities agree by hypothesis. `Equiv.ofFiberEquiv` glues +the fiber-wise cardinality bijections (`Fintype.equivOfCardEq`) into `e : ι ≃ κ`; value preservation +is the defining property of the target fiber. -/ +theorem exists_equiv_of_map_univ_val_eq [Fintype ι] [Fintype κ] {f : ι → α} {g : κ → α} + (h : Multiset.map f Finset.univ.val = Multiset.map g Finset.univ.val) : + ∃ e : ι ≃ κ, ∀ i, g (e i) = f i := by + classical + have hcard : ∀ c : α, Fintype.card {i // f i = c} = Fintype.card {j // g j = c} := fun c => by + rw [card_fiber_eq_count f c, card_fiber_eq_count g c, h] + refine ⟨Equiv.ofFiberEquiv (fun c => Fintype.equivOfCardEq (hcard c)), fun i => ?_⟩ + rw [Equiv.ofFiberEquiv_apply] + exact ((Fintype.equivOfCardEq (hcard (f i))) _).2 diff --git a/LeanPool/AxQM/ToMathlib/Data/Real/Sqrt.lean b/LeanPool/AxQM/ToMathlib/Data/Real/Sqrt.lean new file mode 100644 index 0000000000..ffe1fa8791 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Data/Real/Sqrt.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Analysis.Real.Sqrt + +/-! +# Square root of a real number: conjugate-multiplication identities + +Extends `Mathlib.Data.Real.Sqrt` with conjugate-multiplication factorizations and squared +binomial expansions for `Real.sqrt`, used for triangle-inequality and L¹-distance arguments. +-/ + +@[expose] public section + +namespace Real + +/-- **Conjugate-multiplication factorization** for non-negative reals: +`a - b = (√a - √b) * (√a + √b)`. -/ +theorem sub_eq_sqrt_sub_mul_sqrt_add {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + x - y = (√x - √y) * (√x + √y) := by + have := sq_sqrt hx + have := sq_sqrt hy + nlinarith + +/-- **Abs form of the conjugate-multiplication factorization** for non-negative reals: +`|a - b| = |√a - √b| * (√a + √b)`. The application-facing API for triangle-inequality and +L¹-distance arguments; the signed form (`sub_eq_sqrt_sub_mul_sqrt_add`) is the algebraic +backbone. -/ +theorem abs_sub_eq_abs_sqrt_sub_mul_sqrt_add {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + |x - y| = |√x - √y| * (√x + √y) := by + rw [sub_eq_sqrt_sub_mul_sqrt_add hx hy, abs_mul, + abs_of_nonneg (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _))] + +/-- **Squared binomial expansion** for non-negative reals: +`(√a - √b)² = a + b - 2 √(a · b)`. -/ +theorem sqrt_sub_sq {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + (√x - √y) ^ 2 = x + y - 2 * √(x * y) := by + rw [sub_sq, sq_sqrt hx, sq_sqrt hy, sqrt_mul hx] + ring + +/-- **Squared binomial expansion** for non-negative reals: +`(√a + √b)² = a + b + 2 √(a · b)`. -/ +theorem sqrt_add_sq {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + (√x + √y) ^ 2 = x + y + 2 * √(x * y) := by + rw [add_sq, sq_sqrt hx, sq_sqrt hy, sqrt_mul hx] + ring + +/-- For non-negative `a`, `b`: `(√a - √b)² ≤ |a - b|`. AM-GM-style bound on the squared +distance of square roots in terms of the distance of the originals. -/ +theorem sqrt_sub_sq_le_abs_sub {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + (√x - √y) ^ 2 ≤ |x - y| := by + have ha_sq : √x ^ 2 = x := sq_sqrt hx + have hb_sq : √y ^ 2 = y := sq_sqrt hy + have hsa : 0 ≤ √x := sqrt_nonneg _ + have hsb : 0 ≤ √y := sqrt_nonneg _ + rcases le_total y x with hab | hab + · rw [abs_of_nonneg (by linarith)] + have hsqab : √y ≤ √x := sqrt_le_sqrt hab + nlinarith [ha_sq, hb_sq, hsa, hsb, hsqab] + · rw [abs_of_nonpos (by linarith)] + have hsqab : √x ≤ √y := sqrt_le_sqrt hab + nlinarith [ha_sq, hb_sq, hsa, hsb, hsqab] + +end Real diff --git a/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuation.lean b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuation.lean new file mode 100644 index 0000000000..f3398d40bb --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuation.lean @@ -0,0 +1,209 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.GroupTheory.SpecificGroups.Cyclic +public import Mathlib.Data.Nat.Factorization.Basic + +/-! +# Counting elements of a finite cyclic group by the `2`-adic valuation of their order + +In a finite cyclic group `G` the number of elements of each order is controlled by Euler's +totient function (`IsCyclic.card_orderOf_eq_totient`). This file draws two counting consequences +that are the combinatorial heart of the analysis of Shor's factoring algorithm (Nielsen & Chuang, +*Lemma A4.12*): for the fixed prime `2`, how the elements of `G` distribute across the possible +`2`-adic valuations of their orders. + +Throughout, write `n = |G|` and `d = v₂(n)` (`padicValNat 2 n`). + +## Main results + +* `IsCyclic.card_pow_eq_one_of_dvd` : `#{x | xᶜ = 1} = c` for any divisor `c` of `n`. (The `≤` + bound in an arbitrary finite group is `IsCyclic.card_pow_eq_one_le`; here we get the exact count.) +* `IsCyclic.card_orderOf_dvd_of_dvd` : `#{x | orderOf x ∣ c} = c` for any divisor `c` of `n`. +* `IsCyclic.card_padicValNat_orderOf_le` : for a prime `p` and `t ≤ vₚ(n)`, the number of elements + whose order has `p`-adic valuation `≤ t` is `pᵗ` times the `p`-free part of `n`. +* `IsCyclic.two_mul_card_two_pow_dvd_orderOf` : if `n` is even then **exactly half** the elements + have order divisible by the full `2`-part `2ᵈ` of `n`, i.e. `2 · #{x | 2ᵈ ∣ orderOf x} = n`. + This is Nielsen & Chuang's *Lemma A4.12*. +* `IsCyclic.two_mul_card_padicValNat_orderOf_le` : if `n` is even then **at most half** the + elements share any single value `t` of `v₂(orderOf x)`, i.e. `2 · #{x | v₂(orderOf x) = t} ≤ n`. + +## Implementation notes + +The supporting arithmetic fact `Nat.dvd_pow_mul_ordCompl_iff` — a divisor `a` of `n` divides +`pᵗ · (p`-free part of `n)` iff `vₚ(a) ≤ t` — turns the divisibility set +`{x | orderOf x ∣ pᵗ · ordComplₚ n}` (counted exactly by `card_orderOf_dvd_of_dvd`) into the +valuation set `{x | vₚ(orderOf x) ≤ t}`. Both of these are stated for a general prime `p`, since +their proofs are not `2`-specific; only the two "half" results are genuinely about `p = 2`. The +"at most half" bound then follows because the top level `t = d` already occupies exactly half of +`G`, so every other level is disjoint from it and hence fits in the remaining half. +-/ + +@[expose] public section + +open Finset + +namespace Nat + +/-- `Nat.pow_dvd_iff_le_multiplicity`, stated with `padicValNat`. -/ +theorem pow_dvd_iff_le_padicValNat' {p k n : ℕ} (hp : p ≠ 1) (hn : n ≠ 0) : + p ^ k ∣ n ↔ k ≤ padicValNat p n := by + rw [padicValNat_def] + exact pow_dvd_iff_le_multiplicity hp hn + +/-- `pow_multiplicity_dvd`, stated with `padicValNat`. -/ +theorem pow_padicValNat_dvd' {p n : ℕ} : p ^ padicValNat p n ∣ n := by + rw [padicValNat_def] + exact pow_multiplicity_dvd p n + +/-- For a prime `p` and a divisor `a` of a nonzero `n`, `a` divides `p ^ t` times the `p`-free part +of `n` (that is, `p ^ t * ordCompl[p] n`) exactly when the `p`-adic valuation of `a` is at most +`t`. -/ +theorem dvd_pow_mul_ordCompl_iff {p n a t : ℕ} (hp : p.Prime) (hn : n ≠ 0) (ha : a ∣ n) : + a ∣ p ^ t * ordCompl[p] n ↔ padicValNat p a ≤ t := by + have hfac : a.factorization p = padicValNat p a := by + rw [Nat.factorization_def a hp, padicValNat_def] + constructor + · intro h + have hdvd : p ^ padicValNat p a ∣ p ^ t * ordCompl[p] n := + dvd_trans (by rw [← hfac]; exact Nat.ordProj_dvd a p) h + have hcop : Nat.Coprime (p ^ padicValNat p a) (ordCompl[p] n) := + (Nat.coprime_ordCompl hp hn).pow_left _ + exact (Nat.pow_dvd_pow_iff_le_right hp.one_lt).mp (hcop.dvd_of_dvd_mul_right hdvd) + · intro h + have hsplit : a = p ^ padicValNat p a * ordCompl[p] a := by + rw [← hfac]; exact (Nat.ordProj_mul_ordCompl_eq_self a p).symm + rw [hsplit] + exact Nat.mul_dvd_mul (pow_dvd_pow p h) (Nat.ordCompl_dvd_ordCompl_of_dvd ha p) + +end Nat + +namespace IsCyclic + +/-- In a finite cyclic group, the number of solutions of `x ^ c = 1` is exactly `c`, for any +divisor `c` of the group order. (Compare `IsCyclic.card_pow_eq_one_le`, the `≤` bound available in +an arbitrary finite group.) -/ +theorem card_pow_eq_one_of_dvd {G : Type*} [Group G] [IsCyclic G] [Fintype G] [DecidableEq G] + {c : ℕ} (hc : c ∣ Fintype.card G) (hc0 : c ≠ 0) : #{x : G | x ^ c = 1} = c := by + rw [← sum_card_orderOf_eq_card_pow_eq_one hc0] + calc ∑ m ∈ c.divisors, #{x : G | orderOf x = m} + = ∑ m ∈ c.divisors, m.totient := + Finset.sum_congr rfl fun m hm => + IsCyclic.card_orderOf_eq_totient (dvd_trans (Nat.dvd_of_mem_divisors hm) hc) + _ = c := Nat.sum_totient c + +/-- In a finite cyclic group, the number of elements whose order divides `c` is exactly `c`, for +any divisor `c` of the group order. -/ +theorem card_orderOf_dvd_of_dvd {G : Type*} [Group G] [IsCyclic G] [Fintype G] + {c : ℕ} (hc : c ∣ Fintype.card G) (hc0 : c ≠ 0) : #{x : G | orderOf x ∣ c} = c := by + classical + conv_rhs => rw [← card_pow_eq_one_of_dvd hc hc0] + congr 1 + ext x + simp [orderOf_dvd_iff_pow_eq_one] + +/-- For a prime `p`, the number of elements of a finite cyclic group whose order has `p`-adic +valuation at most `t` is `p ^ t` times the `p`-free part of the group order, provided +`t ≤ vₚ(|G|)`. -/ +theorem card_padicValNat_orderOf_le {G : Type*} [Group G] [IsCyclic G] [Fintype G] + {p t : ℕ} (hp : p.Prime) (ht : t ≤ padicValNat p (Fintype.card G)) : + #{x : G | padicValNat p (orderOf x) ≤ t} = p ^ t * ordCompl[p] (Fintype.card G) := by + have hn : Fintype.card G ≠ 0 := Fintype.card_ne_zero + have hfac : (Fintype.card G).factorization p = padicValNat p (Fintype.card G) := + (Nat.factorization_def _ hp).trans Nat.padicValNat_def.symm + have hdvd : p ^ t * ordCompl[p] (Fintype.card G) ∣ Fintype.card G := by + calc p ^ t * ordCompl[p] (Fintype.card G) + ∣ p ^ (Fintype.card G).factorization p * ordCompl[p] (Fintype.card G) := + Nat.mul_dvd_mul (pow_dvd_pow p (by rw [hfac]; exact ht)) dvd_rfl + _ = Fintype.card G := Nat.ordProj_mul_ordCompl_eq_self _ p + have hne : p ^ t * ordCompl[p] (Fintype.card G) ≠ 0 := + Nat.mul_ne_zero (pow_ne_zero _ hp.pos.ne') (Nat.ordCompl_pos p hn).ne' + rw [← card_orderOf_dvd_of_dvd hdvd hne] + congr 1 + ext x + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + exact (Nat.dvd_pow_mul_ordCompl_iff hp hn orderOf_dvd_card).symm + +/-- **Nielsen & Chuang, Lemma A4.12.** In a finite cyclic group of even order `n`, exactly half of +the elements have order divisible by the full `2`-part `2 ^ v₂(n)` of `n`. -/ +theorem two_mul_card_two_pow_dvd_orderOf {G : Type*} [Group G] [IsCyclic G] [Fintype G] + (hev : 2 ∣ Fintype.card G) : + 2 * #{x : G | 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} = Fintype.card G := by + have hn : Fintype.card G ≠ 0 := Fintype.card_ne_zero + have hfac : (Fintype.card G).factorization 2 = padicValNat 2 (Fintype.card G) := + (Nat.factorization_def _ Nat.prime_two).trans Nat.padicValNat_def.symm + have hd1 : 1 ≤ padicValNat 2 (Fintype.card G) := + (Nat.pow_dvd_iff_le_padicValNat' (by norm_num) hn).mp (by simpa using hev) + -- The complement of `{2ᵈ ∣ orderOf}` is the level set `{v₂(orderOf) ≤ d - 1}`. + have hcompl_card : #{x : G | ¬ 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} + = 2 ^ (padicValNat 2 (Fintype.card G) - 1) * ordCompl[2] (Fintype.card G) := by + rw [← card_padicValNat_orderOf_le Nat.prime_two (t := padicValNat 2 (Fintype.card G) - 1) + (Nat.sub_le _ 1)] + congr 1 + ext x + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + rw [Nat.pow_dvd_iff_le_padicValNat' (by norm_num) (orderOf_pos x).ne'] + omega + have hsplit : #{x : G | 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} + + #{x : G | ¬ 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} = Fintype.card G := by + rw [← Finset.card_univ] + exact Finset.card_filter_add_card_filter_not _ + have hcard_eq : Fintype.card G + = 2 ^ padicValNat 2 (Fintype.card G) * ordCompl[2] (Fintype.card G) := by + conv_lhs => rw [← Nat.ordProj_mul_ordCompl_eq_self (Fintype.card G) 2] + rw [hfac] + have h2E : 2 ^ padicValNat 2 (Fintype.card G) * ordCompl[2] (Fintype.card G) + = 2 * (2 ^ (padicValNat 2 (Fintype.card G) - 1) * ordCompl[2] (Fintype.card G)) := by + rw [← mul_assoc, ← pow_succ', Nat.sub_add_cancel hd1] + have hcard2 := hcard_eq.trans h2E + omega + +/-- In a finite cyclic group of even order `n`, at most half of the elements share any single +value `t` of the `2`-adic valuation of their order: `2 · #{x | v₂(orderOf x) = t} ≤ n`. Combined +with `two_mul_card_two_pow_dvd_orderOf`, the maximum (exactly half) is attained at `t = v₂(n)`. -/ +theorem two_mul_card_padicValNat_orderOf_le {G : Type*} [Group G] [IsCyclic G] [Fintype G] + (hev : 2 ∣ Fintype.card G) (t : ℕ) : + 2 * #{x : G | padicValNat 2 (orderOf x) = t} ≤ Fintype.card G := by + have hn : Fintype.card G ≠ 0 := Fintype.card_ne_zero + -- The order of any element divides `|G|`, so its valuation is at most `v₂(|G|)`. + have hle_all : ∀ x : G, padicValNat 2 (orderOf x) ≤ padicValNat 2 (Fintype.card G) := fun x => + (Nat.pow_dvd_iff_le_padicValNat' (by norm_num) hn).mp + (dvd_trans Nat.pow_padicValNat_dvd' orderOf_dvd_card) + -- At the top level the valuation set coincides with `{2ᵈ ∣ orderOf}`. + have htop_eq : #{x : G | padicValNat 2 (orderOf x) = padicValNat 2 (Fintype.card G)} + = #{x : G | 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} := by + congr 1 + ext x + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + rw [Nat.pow_dvd_iff_le_padicValNat' (by norm_num) (orderOf_pos x).ne'] + have := hle_all x + omega + have htop : 2 * #{x : G | padicValNat 2 (orderOf x) = padicValNat 2 (Fintype.card G)} + = Fintype.card G := by rw [htop_eq]; exact two_mul_card_two_pow_dvd_orderOf hev + by_cases h : t = padicValNat 2 (Fintype.card G) + · rw [h]; omega + · -- For `t ≠ d`, the level set is disjoint from the top one, hence a subset of its complement. + have hle : #{x : G | padicValNat 2 (orderOf x) = t} + ≤ #{x : G | ¬ 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} := by + apply Finset.card_le_card + intro x hx + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ + rw [Nat.pow_dvd_iff_le_padicValNat' (by norm_num) (orderOf_pos x).ne'] + have := hle_all x + omega + have hsplit : #{x : G | 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} + + #{x : G | ¬ 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} = Fintype.card G := by + rw [← Finset.card_univ] + exact Finset.card_filter_add_card_filter_not _ + have hA : 2 * #{x : G | 2 ^ padicValNat 2 (Fintype.card G) ∣ orderOf x} = Fintype.card G := + two_mul_card_two_pow_dvd_orderOf hev + omega + +end IsCyclic diff --git a/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPi.lean b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPi.lean new file mode 100644 index 0000000000..06943e6147 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPi.lean @@ -0,0 +1,149 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuation +public import Mathlib.Data.Fintype.BigOperators +public import Mathlib.Data.Fintype.Pi +public import Mathlib.Algebra.Order.BigOperators.GroupWithZero.Finset + +/-! +# The max-atom product bound for `2`-adic order valuations across a product of cyclic groups + +Building on `ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuation` (Nielsen & Chuang's +*Lemma A4.12*: in a finite cyclic group of even order, each single `2`-adic order-valuation level +holds *at most half* the elements), this file proves the combinatorial fan-out over a finite family +of such groups that is the second ingredient of Nielsen & Chuang's factoring analysis +(the `1 - 1/2^{m-1}` bound of *Theorem 5.3* / *Theorem A4.13*). + +## Main result + +* `IsCyclic.two_pow_mul_card_forall_padicValNat_orderOf_eq_le` : for a nonempty finite index type + `ι` (`m := #ι`) and finite cyclic groups `G i` each of even order, the tuples `f` whose components + *all share one common* `2`-adic order-valuation number are rare: + `2 ^ (m - 1) * #{f | ∀ i j, v₂(orderOf (f i)) = v₂(orderOf (f j))} ≤ ∏ i, |G i|`, + i.e. their fraction is at most `1 / 2^{m-1}`. + +## Implementation notes + +The "all components share one valuation" set is the disjoint union, over the possible common value +`t`, of the boxes `{f | ∀ i, v₂(orderOf (f i)) = t}`, whose cardinality factors as a product +`∏ i, #{x : G i | v₂(orderOf x) = t}` (`Fintype.card_piFinset`). Pinning one distinguished index +`i₀`, each of the remaining `m - 1` factors contributes at most half its group (Lemma A4.12), so the +per-`t` box is at most `(∏_{i ≠ i₀} |G i|) · #{x : G i₀ | v₂ = t} / 2^{m-1}`; summing the pinned +factor over `t` rebuilds `|G i₀|`, giving `∏ i, |G i|` on the right. The valuation `t` is bounded +by `v₂(|G i₀|)` (every order divides the group order), making the fiber index set finite. +-/ + +@[expose] public section + +open Finset + +namespace IsCyclic + +/-- **Max-atom product bound.** Let `ι` be a nonempty finite index type with `m := #ι` and let each +`G i` be a finite cyclic group of even order. Then the tuples all of whose components have the same +`2`-adic order-valuation number occupy at most a `1 / 2^{m-1}` fraction of the product: +`2 ^ (m - 1) * #{f | ∀ i j, v₂(orderOf (f i)) = v₂(orderOf (f j))} ≤ ∏ i, |G i|`. + +This is the family generalisation of `IsCyclic.two_mul_card_padicValNat_orderOf_le` (the `m = 1`, +single-group "at most half" statement) and the counting core of Nielsen & Chuang's *Theorem 5.3*. -/ +theorem two_pow_mul_card_forall_padicValNat_orderOf_eq_le + {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] {G : ι → Type*} + [∀ i, Group (G i)] [∀ i, IsCyclic (G i)] [∀ i, Fintype (G i)] + (hev : ∀ i, 2 ∣ Fintype.card (G i)) : + 2 ^ (Fintype.card ι - 1) * + #{f : (i : ι) → G i | + ∀ i j, padicValNat 2 (orderOf (f i)) = padicValNat 2 (orderOf (f j))} + ≤ ∏ i, Fintype.card (G i) := by + classical + obtain ⟨i₀⟩ : Nonempty ι := inferInstance + -- Number of elements of `G i` whose order has `2`-adic valuation exactly `t`. + set c : ι → ℕ → ℕ := fun i t => #{x : G i | padicValNat 2 (orderOf x) = t} with hc + -- Lemma A4.12: each level occupies at most half of its factor. + have hbound : ∀ i t, 2 * c i t ≤ Fintype.card (G i) := fun i t => + IsCyclic.two_mul_card_padicValNat_orderOf_le (hev i) t + -- The common valuation is bounded by `v₂(|G i₀|)`, so the fiber index runs over `range (d₀ + 1)`. + set d₀ : ℕ := padicValNat 2 (Fintype.card (G i₀)) with hd0 + have hi0card : Fintype.card (G i₀) ≠ 0 := Fintype.card_ne_zero + have hval_le : ∀ x : G i₀, padicValNat 2 (orderOf x) ≤ d₀ := fun x => + (Nat.pow_dvd_iff_le_padicValNat' (by norm_num) hi0card).mp + (dvd_trans Nat.pow_padicValNat_dvd' orderOf_dvd_card) + -- The "all-equal" set. + set A : Finset ((i : ι) → G i) := + Finset.univ.filter (fun f : (i : ι) → G i => + ∀ i j, padicValNat 2 (orderOf (f i)) = padicValNat 2 (orderOf (f j))) + with hA + -- Each fiber of `f ↦ v₂(orderOf (f i₀))` over `A` is the box of tuples with all valuations `= t`. + have hfiber : ∀ t, A.filter (fun f => padicValNat 2 (orderOf (f i₀)) = t) + = Fintype.piFinset (fun i => {x : G i | padicValNat 2 (orderOf x) = t}) := by + intro t + ext f + simp only [hA, Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset] + constructor + · rintro ⟨hall, ht⟩ i + exact (hall i i₀).trans ht + · intro h + exact ⟨fun i j => (h i).trans (h j).symm, h i₀⟩ + -- ... hence its cardinality is the product of the per-factor level counts. + have hAt_card : ∀ t, (A.filter (fun f => padicValNat 2 (orderOf (f i₀)) = t)).card + = ∏ i, c i t := by + intro t + rw [hfiber t, Fintype.card_piFinset] + -- Decompose `#A` as the sum over the common valuation `t`. + have hmaps : Set.MapsTo (fun f : (i : ι) → G i => padicValNat 2 (orderOf (f i₀))) + ↑A ↑(Finset.range (d₀ + 1)) := by + intro f _ + simp only [Finset.coe_range, Set.mem_Iio] + exact Nat.lt_succ_of_le (hval_le (f i₀)) + have hAcard : A.card = ∑ t ∈ Finset.range (d₀ + 1), ∏ i, c i t := by + rw [Finset.card_eq_sum_card_fiberwise hmaps] + exact Finset.sum_congr rfl (fun t _ => hAt_card t) + -- Summing the pinned factor over `t` rebuilds `|G i₀|`. + have hsumci0 : ∑ t ∈ Finset.range (d₀ + 1), c i₀ t = Fintype.card (G i₀) := by + rw [← Finset.card_univ (α := G i₀)] + refine (Finset.card_eq_sum_card_fiberwise (fun x _ => ?_)).symm + simp only [Finset.coe_range, Set.mem_Iio] + exact Nat.lt_succ_of_le (hval_le x) + -- Per-`t` bound: pull `m - 1` factors, each at most half, out of the product. + have key : ∀ t, 2 ^ (Fintype.card ι - 1) * ∏ i, c i t + ≤ (∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i)) * c i₀ t := by + intro t + have hcardE : (Finset.univ.erase i₀).card = Fintype.card ι - 1 := by + rw [Finset.card_erase_of_mem (Finset.mem_univ i₀), Finset.card_univ] + have hprodE : 2 ^ (Fintype.card ι - 1) * ∏ i ∈ Finset.univ.erase i₀, c i t + ≤ ∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i) := by + calc 2 ^ (Fintype.card ι - 1) * ∏ i ∈ Finset.univ.erase i₀, c i t + = ∏ i ∈ Finset.univ.erase i₀, (2 * c i t) := by + rw [Finset.prod_mul_distrib, Finset.prod_const, hcardE] + _ ≤ ∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i) := + Finset.prod_le_prod (fun i _ => hbound i t) + calc 2 ^ (Fintype.card ι - 1) * ∏ i, c i t + = 2 ^ (Fintype.card ι - 1) * (c i₀ t * ∏ i ∈ Finset.univ.erase i₀, c i t) := by + rw [Finset.mul_prod_erase Finset.univ (fun i => c i t) (Finset.mem_univ i₀)] + _ = c i₀ t * (2 ^ (Fintype.card ι - 1) * ∏ i ∈ Finset.univ.erase i₀, c i t) := by ring + _ ≤ c i₀ t * ∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i) := + Nat.mul_le_mul_left _ hprodE + _ = (∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i)) * c i₀ t := by rw [mul_comm] + -- Assemble. + calc 2 ^ (Fintype.card ι - 1) * A.card + = 2 ^ (Fintype.card ι - 1) * ∑ t ∈ Finset.range (d₀ + 1), ∏ i, c i t := by rw [hAcard] + _ = ∑ t ∈ Finset.range (d₀ + 1), 2 ^ (Fintype.card ι - 1) * ∏ i, c i t := by + rw [Finset.mul_sum] + _ ≤ ∑ t ∈ Finset.range (d₀ + 1), + (∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i)) * c i₀ t := + Finset.sum_le_sum (fun t _ => key t) + _ = (∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i)) * + ∑ t ∈ Finset.range (d₀ + 1), c i₀ t := by rw [Finset.mul_sum] + _ = (∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i)) * Fintype.card (G i₀) := by rw [hsumci0] + _ = Fintype.card (G i₀) * ∏ i ∈ Finset.univ.erase i₀, Fintype.card (G i) := by rw [mul_comm] + _ = ∏ i, Fintype.card (G i) := + Finset.mul_prod_erase Finset.univ (fun i => Fintype.card (G i)) (Finset.mem_univ i₀) + +end IsCyclic diff --git a/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPiInvolution.lean b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPiInvolution.lean new file mode 100644 index 0000000000..61be593215 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/GroupTheory/SpecificGroups/Cyclic/OrderValuationPiInvolution.lean @@ -0,0 +1,212 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuation +public import Mathlib.Algebra.GCDMonoid.Finset +public import Mathlib.Data.Nat.MaxPowDiv +public import Mathlib.NumberTheory.Padics.PadicVal.Basic + +/-! +# The "bad set" of the order-finding reduction as a shared `2`-adic order valuation + +For a finite family `G i` of finite cyclic groups of even order, each equipped with a chosen +non-identity involution `neg i` (in the application, the unit `-1`), this file characterises the +tuples `f : Π i, G i` that are **bad** for the factoring-by-order-finding reduction — meaning the +order `r = orderOf f` is odd, or `f ^ (r / 2)` equals the involution `neg` — purely in terms of the +components' `2`-adic order valuations: + +`(¬ Even (orderOf f) ∨ f ^ (orderOf f / 2) = neg) ↔ ∀ i j, v₂(orderOf (f i)) = v₂(orderOf (f j))`. + +This is the group-theoretic heart of the second reduction step in Nielsen & Chuang's factoring +analysis (their *Theorem 5.3* / *Theorem A4.13*): combined with the counting bound +`IsCyclic.two_pow_mul_card_forall_padicValNat_orderOf_eq_le` +(`ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuationPi`), it bounds the fraction of bad +units. + +## Main results + +* `IsCyclic.not_even_orderOf_or_pow_orderOf_div_two_eq_iff` : the characterisation above. +* `IsCyclic.eq_of_sq_eq_one_of_ne_one` : a finite cyclic group of even order has a *unique* + non-identity square root of `1` (its order-`2` element). +* `Pi.padicValNat_orderOf` : in a finite product of finite groups, `vₚ(orderOf x)` is the supremum + over the factors of `vₚ(orderOf (x i))`. +* `padicValNat_finset_lcm` / `padicValNat_lcm` : `vₚ` of a (finite) least common multiple of nonzero + numbers is the supremum / maximum of the `vₚ`'s. +* `Nat.not_dvd_div_two_iff_padicValNat_eq` : for `a ∣ b` with `b` even, `a ∤ b / 2` iff + `v₂ a = v₂ b`. + +## Implementation notes + +The bridge from the product order to the component orders is `Pi.orderOf` (the product order is the +`Finset.lcm` of the component orders); the `2`-adic valuation of that `lcm` is the supremum of the +component valuations (`Pi.padicValNat_orderOf`), so "all components share one valuation" pins +`v₂(orderOf f)` to that common value. Uniqueness of the non-identity involution reuses the exact +count `IsCyclic.card_pow_eq_one_of_dvd` (with `c = 2`): the solution set of `x ^ 2 = 1` has exactly +two elements, so two non-identity solutions coincide. +-/ + +@[expose] public section + +open Finset + +/-- For a prime `p` and nonzero `a`, `b`, the `p`-adic valuation of their least common multiple is +the maximum of their valuations. -/ +theorem padicValNat_lcm {p : ℕ} (hp : p.Prime) {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : + padicValNat p (Nat.lcm a b) = padicValNat p a ⊔ padicValNat p b := by + rw [Nat.padicValNat_def, Nat.padicValNat_def, Nat.padicValNat_def, + ← Nat.factorization_def (Nat.lcm a b) hp, ← Nat.factorization_def a hp, + ← Nat.factorization_def b hp, Nat.factorization_lcm ha hb, Finsupp.sup_apply] + +/-- For a prime `p`, the `p`-adic valuation of a finite least common multiple of nonzero numbers is +the supremum of the individual valuations. -/ +theorem padicValNat_finset_lcm {ι : Type*} {p : ℕ} (hp : p.Prime) (s : Finset ι) (f : ι → ℕ) + (hf : ∀ i ∈ s, f i ≠ 0) : + padicValNat p (s.lcm f) = s.sup fun i => padicValNat p (f i) := by + classical + induction s using Finset.induction with + | empty => simp [Nat.padicValNat_def] + | @insert a s ha ih => + have hfa : f a ≠ 0 := hf a (mem_insert_self a s) + have hfs : ∀ i ∈ s, f i ≠ 0 := fun i hi => hf i (mem_insert_of_mem hi) + have hL : s.lcm f ≠ 0 := by rw [Ne, Finset.lcm_eq_zero_iff]; simpa using hfs + rw [Finset.lcm_insert, Finset.sup_insert, + show GCDMonoid.lcm (f a) (s.lcm f) = Nat.lcm (f a) (s.lcm f) from rfl, + padicValNat_lcm hp hfa hL, ih hfs] + +/-- In a finite product of finite groups, the `p`-adic valuation of the order of an element is the +supremum, over the factors, of the `p`-adic valuations of the component orders. -/ +theorem Pi.padicValNat_orderOf {ι : Type*} [Fintype ι] {G : ι → Type*} + [∀ i, Group (G i)] [∀ i, Finite (G i)] {p : ℕ} (hp : p.Prime) (x : ∀ i, G i) : + padicValNat p (orderOf x) = Finset.univ.sup fun i => padicValNat p (orderOf (x i)) := by + rw [_root_.Pi.orderOf] + exact padicValNat_finset_lcm hp univ (fun i => orderOf (x i)) (fun i _ => (orderOf_pos (x i)).ne') + +/-- If `a ∣ b` and `b` is even, then `a` does *not* divide `b / 2` exactly when `a` and `b` have the +same `2`-adic valuation (i.e. `a` carries the full `2`-part of `b`). -/ +theorem Nat.not_dvd_div_two_iff_padicValNat_eq {a b : ℕ} (hab : a ∣ b) (hb2 : 2 ∣ b) (hb0 : b ≠ 0) : + ¬ a ∣ b / 2 ↔ padicValNat 2 a = padicValNat 2 b := by + have hda_le : padicValNat 2 a ≤ padicValNat 2 b := + (Nat.pow_dvd_iff_le_padicValNat' (by norm_num) hb0).mp (dvd_trans Nat.pow_padicValNat_dvd' hab) + have hdb1 : 1 ≤ padicValNat 2 b := Nat.padicValNat_def ▸ one_le_multiplicity_of_dvd hb0 hb2 + have hexp : 2 * 2 ^ (padicValNat 2 b - 1) = 2 ^ padicValNat 2 b := by + rw [← pow_succ']; congr 1; omega + have key : 2 * (2 ^ (padicValNat 2 b - 1) * ordCompl[2] b) = b := by + rw [← mul_assoc, hexp, Nat.padicValNat_def, ← Nat.factorization_def b Nat.prime_two, + Nat.ordProj_mul_ordCompl_eq_self] + have hdiv : b / 2 = 2 ^ (padicValNat 2 b - 1) * ordCompl[2] b := by + conv_lhs => rw [← key] + rw [Nat.mul_div_cancel_left _ (by norm_num : (0 : ℕ) < 2)] + rw [hdiv, Nat.dvd_pow_mul_ordCompl_iff Nat.prime_two hb0 hab] + omega + +/-- A finite cyclic group of even order has a *unique* non-identity square root of `1`: any two +elements `a`, `b` with `a ^ 2 = b ^ 2 = 1` and `a, b ≠ 1` are equal. (The solution set of +`x ^ 2 = 1` has exactly two elements by `IsCyclic.card_pow_eq_one_of_dvd`.) -/ +theorem IsCyclic.eq_of_sq_eq_one_of_ne_one {G : Type*} [Group G] [IsCyclic G] [Fintype G] + (h2 : 2 ∣ Fintype.card G) {a b : G} (ha2 : a ^ 2 = 1) (hb2 : b ^ 2 = 1) + (ha1 : a ≠ 1) (hb1 : b ≠ 1) : a = b := by + classical + by_contra hab + have hS : #{x : G | x ^ 2 = 1} = 2 := IsCyclic.card_pow_eq_one_of_dvd h2 (by norm_num) + have h1a : (1 : G) ≠ a := fun h => ha1 h.symm + have h1b : (1 : G) ≠ b := fun h => hb1 h.symm + have hsub : ({1, a, b} : Finset G) ⊆ ({x : G | x ^ 2 = 1} : Finset G) := by + intro x hx + simp only [Finset.mem_insert, Finset.mem_singleton] at hx + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + rcases hx with rfl | rfl | rfl + · exact one_pow 2 + · exact ha2 + · exact hb2 + have h3 : ({1, a, b} : Finset G).card = 3 := by + rw [Finset.card_insert_of_notMem (by simp [h1a, h1b]), + Finset.card_insert_of_notMem (by simp [hab]), Finset.card_singleton] + have hle := Finset.card_le_card hsub + rw [h3, hS] at hle + omega + +/-- **The "bad set" of the factoring-by-order-finding reduction, over a product of cyclic groups.** + +Let `ι` be a nonempty finite index type and let each `G i` be a finite cyclic group of even order, +equipped with a chosen non-identity involution `neg i` (`neg i ^ 2 = 1`, `neg i ≠ 1`; in the +application to `(ZMod N)ˣ`, this is the unit `-1`). For a tuple `f : Π i, G i`, writing +`r = orderOf f`, the reduction *fails* — `r` is odd, or `f ^ (r / 2) = neg` — if and only if all +components share the same `2`-adic order valuation: + +`(¬ Even r ∨ f ^ (r / 2) = neg) ↔ ∀ i j, v₂(orderOf (f i)) = v₂(orderOf (f j))`. + +This is the group-theoretic core of Nielsen & Chuang's *Theorem 5.3* / *Theorem A4.13*. -/ +theorem IsCyclic.not_even_orderOf_or_pow_orderOf_div_two_eq_iff + {ι : Type*} [Finite ι] [Nonempty ι] {G : ι → Type*} + [∀ i, Group (G i)] [∀ i, IsCyclic (G i)] [∀ i, Fintype (G i)] + (hev : ∀ i, 2 ∣ Fintype.card (G i)) + (neg : ∀ i, G i) (hneg2 : ∀ i, neg i ^ 2 = 1) (hneg1 : ∀ i, neg i ≠ 1) (f : ∀ i, G i) : + (¬ Even (orderOf f) ∨ f ^ (orderOf f / 2) = neg) + ↔ ∀ i j, padicValNat 2 (orderOf (f i)) = padicValNat 2 (orderOf (f j)) := by + classical + have : Fintype ι := Fintype.ofFinite ι + set r := orderOf f with hr + have hr0 : r ≠ 0 := (orderOf_pos f).ne' + have hpow : f ^ r = 1 := pow_orderOf_eq_one f + -- Each component order divides the product order. + have hdvd : ∀ k, orderOf (f k) ∣ r := fun k => + orderOf_dvd_of_pow_eq_one (by have := congrFun hpow k; simpa [Pi.pow_apply] using this) + -- `v₂` of the product order is the supremum of the component `v₂`'s (`Pi.orderOf`). + have hsup : padicValNat 2 r = Finset.univ.sup fun i => padicValNat 2 (orderOf (f i)) := by + rw [hr]; exact Pi.padicValNat_orderOf Nat.prime_two f + constructor + · -- A bad tuple forces every component `v₂` to equal `v₂ r`, hence all are equal. + intro hbad i j + suffices h : ∀ k, padicValNat 2 (orderOf (f k)) = padicValNat 2 r by rw [h i, h j] + intro k + by_cases hE : Even r + · -- `r` even, so `f ^ (r / 2) = neg`; component `≠ 1`, so it carries the full `2`-part of `r`. + have hhalf : f ^ (r / 2) = neg := hbad.resolve_left (not_not.mpr hE) + have hne : (f k) ^ (r / 2) ≠ 1 := by + have := congrFun hhalf k + rw [Pi.pow_apply] at this + rw [this]; exact hneg1 k + have hnotdvd : ¬ orderOf (f k) ∣ (r / 2) := fun hd => hne (orderOf_dvd_iff_pow_eq_one.mp hd) + exact (Nat.not_dvd_div_two_iff_padicValNat_eq (hdvd k) hE.two_dvd hr0).mp hnotdvd + · -- `r` odd, so `v₂ r = 0`, and each component `v₂ ≤ v₂ r = 0`. + have hvr0 : padicValNat 2 r = 0 := + Nat.padicValNat_def ▸ multiplicity_eq_zero_of_not_dvd (mt even_iff_two_dvd.mpr hE) + have hle : padicValNat 2 (orderOf (f k)) ≤ padicValNat 2 r := + (Nat.pow_dvd_iff_le_padicValNat' (by norm_num) hr0).mp + (dvd_trans Nat.pow_padicValNat_dvd' (hdvd k)) + omega + · -- Conversely, if all components share one `2`-adic valuation `d`, then `v₂ r = d`. + intro hall + obtain ⟨i₀⟩ := (inferInstance : Nonempty ι) + have hconst : ∀ k, padicValNat 2 (orderOf (f k)) = padicValNat 2 (orderOf (f i₀)) := + fun k => hall k i₀ + have hvr : padicValNat 2 r = padicValNat 2 (orderOf (f i₀)) := by + rw [hsup, ← Finset.sup_const (Finset.univ_nonempty (α := ι)) (padicValNat 2 (orderOf (f i₀)))] + exact Finset.sup_congr rfl (fun k _ => hconst k) + by_cases hd0 : padicValNat 2 r = 0 + · -- `d = 0`: `r` is odd. + left + intro hE + have : 1 ≤ padicValNat 2 r := Nat.padicValNat_def ▸ one_le_multiplicity_of_dvd hr0 hE.two_dvd + omega + · -- `d ≥ 1`: `r` is even and each `(f k) ^ (r / 2)` is the non-identity involution `neg k`. + right + have h2r : 2 ∣ r := + dvd_of_one_le_multiplicity (Nat.padicValNat_def ▸ (by omega : 1 ≤ padicValNat 2 r)) + funext k + rw [Pi.pow_apply] + have hvk : padicValNat 2 (orderOf (f k)) = padicValNat 2 r := by rw [hconst k, ← hvr] + have hnotdvd : ¬ orderOf (f k) ∣ (r / 2) := + (Nat.not_dvd_div_two_iff_padicValNat_eq (hdvd k) h2r hr0).mpr hvk + have hsq : ((f k) ^ (r / 2)) ^ 2 = 1 := by + rw [← pow_mul, Nat.div_mul_cancel h2r] + exact orderOf_dvd_iff_pow_eq_one.mp (hdvd k) + have hne : (f k) ^ (r / 2) ≠ 1 := fun h => hnotdvd (orderOf_dvd_iff_pow_eq_one.mpr h) + exact IsCyclic.eq_of_sq_eq_one_of_ne_one (hev k) hsq (hneg2 k) hne (hneg1 k) diff --git a/LeanPool/AxQM/ToMathlib/GroupTheory/Subgroup/Centralizer.lean b/LeanPool/AxQM/ToMathlib/GroupTheory/Subgroup/Centralizer.lean new file mode 100644 index 0000000000..f11446aed9 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/GroupTheory/Subgroup/Centralizer.lean @@ -0,0 +1,39 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.GroupTheory.Subgroup.Centralizer + +/-! +# `closure` is commutative iff its generators commute + +Extends `Mathlib.GroupTheory.Subgroup.Centralizer` with the iff-strengthening of +`Subgroup.isMulCommutative_closure`. +-/ + +public section + +namespace Subgroup + +variable {G : Type*} [Group G] + +/-- The subgroup `closure k` generated by `k` is commutative if and only if every pair of +generators (elements of `k`) commutes. The forward direction strengthens +`isMulCommutative_closure` to an equivalence: generators lie in the subgroup, so if all of its +elements commute then in particular so do the generators. -/ +@[to_additive /-- The additive subgroup `closure k` generated by `k` is commutative if and only if +every pair of generators (elements of `k`) commutes additively. -/] +theorem isMulCommutative_closure_iff {k : Set G} : + IsMulCommutative (closure k) ↔ ∀ x ∈ k, ∀ y ∈ k, x * y = y * x := by + refine ⟨fun h x hx y hy => ?_, + fun h => isMulCommutative_closure fun x hx y hy _ => h x hx y hy⟩ + have := h + exact setLike_mul_comm (subset_closure hx) (subset_closure hy) + +end Subgroup diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelAchievability.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelAchievability.lean new file mode 100644 index 0000000000..6ecfe892e7 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelAchievability.lean @@ -0,0 +1,235 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelRandomCodingLimit +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelExpurgation + +/-! +# Fixed-input achievability of Shannon's noisy channel coding theorem + +The achievability half of Shannon's noisy channel coding theorem (Nielsen & Chuang, Theorem 12.7; +Cover–Thomas, Theorem 7.7.1) states that every rate below the channel mutual information is +achievable. This file assembles the pieces developed upstream into the **fixed-input** achievability +statement + +`Real.isAchievableRate_of_lt_channelMutualInfo` : + `R · log 2 < channelMutualInfo q p → IsAchievableRate q R`, + +for a channel `q`, an input distribution `p`, and a rate `R` (in bits). Lifting this over the +capacity-attaining input distribution (Theorem 12.7's `max_{p(x)} H(X : Y)`) and combining with the +proven converse closes the full identity `C(N) = max_{p(x)} H(X : Y)`; that final step is not +proved in this file. + +## Proof outline + +The three upstream inputs are the random-coding limit +`Real.tendsto_expectedError_channelRandomCode` (the codebook-*averaged* error tends to `0` for a +rate below the mutual information), the expurgation lemma `Real.exists_channelCode_maxErrorProb_le` +(average error `≤ a` on `M` messages ⟹ *maximum* error `≤ 2a` on `⌈M/2⌉ = (M + 1) / 2` messages), +and the definition of achievability `Real.IsAchievableRate` (a family of block codes with +`⌈2 ^ (n R)⌉ = ⌈exp (n · R · log 2)⌉₊` messages whose maximum error tends to `0`). Assembling them: + +* **Probabilistic method** (`Real.exists_le_weighted_sum`): the codebook-averaged error is a + probability-weighted mean over codebooks, so some deterministic codebook realises an average error + no larger than that mean. Hence for every `n` there is a deterministic joint-typicality code with + average error `≤ 𝔼_C[avg error]`. +* **Expurgation per `n`** (`Real.exists_tendsto_maxErrorProb_of_lt_channelMutualInfo`): expurgating + that deterministic code yields, for a rate `R'` with `R' · log 2 < channelMutualInfo q p`, a code + on `(⌈exp (n R' log 2)⌉₊ + 1) / 2` messages with *maximum* error bounded by + `2 · 𝔼_C[avg error]`, a vanishing sequence. +* **Assembly** (`Real.isAchievableRate_of_forall_exists_maxErrorProb_le`): a family of codes on + `K n ≥ ⌈exp (n R log 2)⌉₊` messages with maximum error `→ 0` gives `IsAchievableRate q R`, by + restricting each code (via `Real.ChannelCode.comp` with the canonical inclusion `Fin.castLE`) to + exactly `⌈exp (n R log 2)⌉₊` messages, which only shrinks the error, and squeezing. + +The **rate arithmetic** ties them together: expurgation halves the message count, so to achieve the +target rate `R` (with `R · log 2 < channelMutualInfo q p`) the random coding is run at a strictly +larger rate `R' = R + (channelMutualInfo q p − R · log 2) / (2 · log 2)` (still below the mutual +information). Since `R < R'`, the expurgated count +`(⌈exp (n R' log 2)⌉₊ + 1) / 2 ≥ ⌈exp (n R log 2)⌉₊` eventually, so the assembly lemma applies. +Rates `R ≤ 0` are handled directly by single-message codes. + +## Main declarations + +* `Real.exists_le_weighted_sum` — some point is at most a probability-weighted mean. +* `Real.isAchievableRate_of_forall_exists_maxErrorProb_le` — build achievability from a family of + codes with enough messages and vanishing maximum error. +* `Real.exists_tendsto_maxErrorProb_of_lt_channelMutualInfo` — random coding + probabilistic method + + expurgation: a vanishing sequence bounding the maximum error of expurgated codes. +* `Real.isAchievableRate_of_lt_channelMutualInfo` — **fixed-input achievability**: a rate below the + channel mutual information is achievable. +-/ + +@[expose] public section + +open Finset Filter Topology + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-! ### The probabilistic method -/ + +/-- **A point below the weighted mean.** If `w` is a probability weight on a finite type `D` +(`0 ≤ w d` and `∑ d, w d = 1`), then some point's `f`-value is at most the `w`-weighted mean +`∑ d, w d * f d`. This is the probabilistic method used to extract a good deterministic codebook +from the codebook-averaged decoding error. -/ +theorem exists_le_weighted_sum {D : Type*} [Fintype D] {w f : D → ℝ} + (hw0 : ∀ d, 0 ≤ w d) (hw1 : ∑ d, w d = 1) : ∃ d, f d ≤ ∑ d', w d' * f d' := by + by_contra hcon + simp only [not_exists, not_le] at hcon + set E := ∑ d', w d' * f d' with hE + have hnn : ∀ d ∈ (univ : Finset D), 0 ≤ w d * (f d - E) := + fun d _ => mul_nonneg (hw0 d) (by linarith [hcon d]) + have hz : ∑ d, w d * (f d - E) = 0 := by + have hexpand : ∑ d, w d * (f d - E) = (∑ d, w d * f d) - (∑ d, w d) * E := by + simp_rw [mul_sub] + rw [Finset.sum_sub_distrib, Finset.sum_mul] + rw [hexpand, hw1, one_mul, ← hE, sub_self] + have hall := (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hz + have hw0all : ∀ d, w d = 0 := fun d => + (mul_eq_zero.mp (hall d (mem_univ d))).resolve_right (sub_ne_zero.mpr (ne_of_gt (hcon d))) + exact one_ne_zero (hw1.symm.trans (Finset.sum_eq_zero fun d _ => hw0all d)) + +/-! ### Assembling a rate from per-`n` codes -/ + +omit [Fintype ι] in +/-- **Achievability from a family of large-enough codes.** If, for every block length `n`, there is +a block code on `K n` messages with maximum error `≤ g n`, where `g → 0` and eventually +`⌈exp (n R log 2)⌉₊ ≤ K n`, then the rate `R` is achievable. Each code is restricted (via +`ChannelCode.comp` along the canonical inclusion `Fin.castLE`) to exactly `⌈exp (n R log 2)⌉₊` of +its messages — which only shrinks the maximum error — and the resulting family is squeezed to +`0`. -/ +theorem isAchievableRate_of_forall_exists_maxErrorProb_le {q : ι → κ → ℝ} (hN : IsChannel q) + [Nonempty ι] {R : ℝ} {K : ℕ → ℕ} {g : ℕ → ℝ} + (hcode : ∀ n, ∃ code : ChannelCode ι κ n (K n), code.maxErrorProb q ≤ g n) + (hK : ∀ᶠ (n : ℕ) in atTop, ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ ≤ K n) + (hg : Tendsto g atTop (𝓝 0)) : IsAchievableRate q R := by + classical + choose code hcodele using hcode + refine ⟨fun n : ℕ => if h : ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ ≤ K n + then (code n).comp (Fin.castLE h) ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩ + else ⟨fun _ _ => Classical.arbitrary ι, + fun _ => ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩⟩, ?_⟩ + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hg + (Filter.Eventually.of_forall fun n => ChannelCode.maxErrorProb_nonneg hN _) ?_ + filter_upwards [hK] with n hn + rw [dite_eq_left hn] + exact ChannelCode.maxErrorProb_comp_le hN (code n) (Fin.castLE_injective hn) _ + (fun i => (ChannelCode.condErrorProb_le_maxErrorProb q (code n) _).trans (hcodele n)) + ((ChannelCode.maxErrorProb_nonneg hN (code n)).trans (hcodele n)) + +/-! ### Random coding, the probabilistic method, and expurgation -/ + +/-- **Expurgated deterministic codes with vanishing maximum error.** For a channel `q`, an input +distribution `p`, and a rate `R` (in bits) with `R · log 2 < channelMutualInfo q p`, there is a +sequence `e → 0` and, for every block length `n`, a block code on `(⌈exp (n R log 2)⌉₊ + 1) / 2` +messages whose *maximum* decoding error is at most `e n`. + +The random-coding limit `tendsto_expectedError_channelRandomCode` drives the codebook-averaged error +to `0`; the probabilistic method (`exists_le_weighted_sum`) extracts, for each `n`, a deterministic +joint-typicality code whose average error is at most that expectation; expurgation +(`exists_channelCode_maxErrorProb_le`) upgrades the average bound to a maximum bound at the cost of +halving the message count. Thus `e n = 2 · 𝔼_C[avg error] → 0`. -/ +theorem exists_tendsto_maxErrorProb_of_lt_channelMutualInfo {q : ι → κ → ℝ} (hN : IsChannel q) + {p : ι → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {R : ℝ} + (hR : R * Real.log 2 < channelMutualInfo q p) : + ∃ e : ℕ → ℝ, Tendsto e atTop (𝓝 0) ∧ + ∀ n, ∃ code : ChannelCode ι κ n ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ + 1) / 2), + code.maxErrorProb q ≤ e n := by + obtain ⟨ε, _, htend⟩ := tendsto_expectedError_channelRandomCode hN hp0 hp1 hR + refine ⟨fun n => 2 * (∑ C : Fin ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ → (Fin n → ι), + channelCodebookProb p C * ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ)⁻¹ * + ∑ m, (channelJointTypicalCode q p n ε + ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩ C).condErrorProb q m)), ?_, ?_⟩ + · simpa using (htend fun n => ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩).const_mul 2 + · intro n + obtain ⟨C, hC⟩ := exists_le_weighted_sum + (f := fun C => (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ)⁻¹ * + ∑ m, (channelJointTypicalCode q p n ε + ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩ C).condErrorProb q m) + (fun C => channelCodebookProb_nonneg hp0 C) (sum_channelCodebookProb hp1) + exact exists_channelCode_maxErrorProb_le hN (Nat.ceil_pos.mpr (Real.exp_pos _)) + (channelJointTypicalCode q p n ε ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩ C) hC + +/-! ### Fixed-input achievability -/ + +/-- **Fixed-input achievability** (achievability half of Nielsen & Chuang, Theorem 12.7). For a +channel `q`, an input distribution `p`, and a rate `R` (in bits) with +`R · log 2 < channelMutualInfo q p = H(X : Y)`, the rate `R` is achievable: there is a family of +block codes with `⌈2 ^ (n R)⌉` messages whose block error probability tends to `0`. + +Rates `R ≤ 0` are trivially achievable with single-message codes. For `R > 0`, the random coding is +run at the strictly larger rate `R' = R + (channelMutualInfo q p − R · log 2) / (2 · log 2)` (still +below the mutual information); the expurgated codes it produces have +`(⌈exp (n R' log 2)⌉₊ + 1) / 2 ≥ ⌈exp (n R log 2)⌉₊` messages eventually — because `R < R'` makes +the message count grow strictly faster — so the assembly lemma +`isAchievableRate_of_forall_exists_maxErrorProb_le` applies. -/ +theorem isAchievableRate_of_lt_channelMutualInfo {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {R : ℝ} + (hR : R * Real.log 2 < channelMutualInfo q p) : IsAchievableRate q R := by + have : Nonempty ι := by + by_contra h + rw [not_nonempty_iff] at h + rw [Finset.univ_eq_empty, Finset.sum_empty] at hp1 + exact one_ne_zero hp1.symm + have hlog2 : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + rcases le_or_gt R 0 with hR0 | hR0 + · -- `R ≤ 0`: single-message codes have zero error. + refine ⟨fun n => ⟨fun _ _ => Classical.arbitrary ι, + fun _ => ⟨0, Nat.ceil_pos.mpr (Real.exp_pos _)⟩⟩, ?_⟩ + refine tendsto_const_nhds.congr fun n => ?_ + have hstep : (n : ℝ) * R * Real.log 2 ≤ 0 := + mul_nonpos_iff.mpr (Or.inr ⟨mul_nonpos_iff.mpr (Or.inl ⟨Nat.cast_nonneg n, hR0⟩), hlog2.le⟩) + refine (ChannelCode.maxErrorProb_eq_zero_of_le_one _ (Nat.ceil_le.mpr ?_)).symm + rw [Nat.cast_one] + exact (Real.exp_le_exp.mpr hstep).trans_eq Real.exp_zero + · -- `R > 0`: random coding at a strictly larger rate `R'`, then expurgate and restrict. + set R' := R + (channelMutualInfo q p - R * Real.log 2) / (2 * Real.log 2) with hR'def + have hgap : 0 < (channelMutualInfo q p - R * Real.log 2) / (2 * Real.log 2) := + div_pos (by linarith) (by positivity) + have hRR' : R < R' := by rw [hR'def]; linarith + have hR'lt : R' * Real.log 2 < channelMutualInfo q p := by + have h2 : R' * Real.log 2 = (R * Real.log 2 + channelMutualInfo q p) / 2 := by + rw [hR'def]; field_simp; ring + rw [h2]; linarith + obtain ⟨e, he0, hcodes⟩ := + exists_tendsto_maxErrorProb_of_lt_channelMutualInfo hN hp0 hp1 hR'lt + have hlin : Tendsto (fun n : ℕ => (n : ℝ) * ((R' - R) * Real.log 2)) atTop atTop := + tendsto_natCast_atTop_atTop.atTop_mul_const (mul_pos (by linarith) hlog2) + have ht : Tendsto (fun n : ℕ => Real.exp ((n : ℝ) * ((R' - R) * Real.log 2))) atTop atTop := + Real.tendsto_exp_atTop.comp hlin + refine isAchievableRate_of_forall_exists_maxErrorProb_le + (K := fun n => (⌈Real.exp ((n : ℝ) * R' * Real.log 2)⌉₊ + 1) / 2) (g := e) hN hcodes ?_ he0 + filter_upwards [ht.eventually_ge_atTop 3] with n hn3 + -- Real bound: `exp (n R' log 2) ≥ 2 · exp (n R log 2) + 1`. + have hexpR : (1 : ℝ) ≤ Real.exp ((n : ℝ) * R * Real.log 2) := + Real.one_le_exp (mul_nonneg (mul_nonneg (Nat.cast_nonneg n) hR0.le) hlog2.le) + have hsplit : (n : ℝ) * R' * Real.log 2 + = (n : ℝ) * R * Real.log 2 + (n : ℝ) * ((R' - R) * Real.log 2) := by ring + have hbig : 2 * Real.exp ((n : ℝ) * R * Real.log 2) + 1 + ≤ Real.exp ((n : ℝ) * R' * Real.log 2) := by + rw [hsplit, Real.exp_add] + nlinarith [hexpR, hn3, mul_nonneg (sub_nonneg.mpr hexpR) (sub_nonneg.mpr hn3), + Real.exp_pos ((n : ℝ) * ((R' - R) * Real.log 2))] + -- Convert to the natural-number count inequality and discharge with `omega`. + have hnat : 2 * ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ + ≤ ⌈Real.exp ((n : ℝ) * R' * Real.log 2)⌉₊ + 1 := by + have hca : (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) + < Real.exp ((n : ℝ) * R * Real.log 2) + 1 := Nat.ceil_lt_add_one (Real.exp_pos _).le + have hcb : Real.exp ((n : ℝ) * R' * Real.log 2) + ≤ (⌈Real.exp ((n : ℝ) * R' * Real.log 2)⌉₊ : ℝ) := Nat.le_ceil _ + have hcast : ((2 * ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℕ) : ℝ) + ≤ ((⌈Real.exp ((n : ℝ) * R' * Real.log 2)⌉₊ + 1 : ℕ) : ℝ) := by + push_cast; linarith [hca, hcb, hbig] + exact_mod_cast hcast + omega + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelCodingTheorem.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelCodingTheorem.lean new file mode 100644 index 0000000000..4b3a2bbc36 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelCodingTheorem.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelAchievability + +/-! +# Shannon's noisy channel coding theorem + +This file closes **Shannon's noisy channel coding theorem** (Nielsen & Chuang, Theorem 12.7; +Cover–Thomas, Theorem 7.7.1): the *operational* capacity `C(N)` of a discrete memoryless channel +`q` equals its *information* capacity `max_{p(x)} H(X : Y)`, + +`Real.channelOpCapacity_eq_channelCapacity_div` : + `channelOpCapacity q = channelCapacity q / log 2`. + +Here `channelOpCapacity q` is the supremum of achievable rates (in bits) and `channelCapacity q` is +`max_{p(x)} channelMutualInfo q p = max_{p(x)} H(X : Y)` (in nats); the factor `/ log 2` converts +the information capacity from nats to bits, so this is exactly N&C eq. (12.67) `C(N) = max_{p(x)} +H(X : Y)` under the base-2 convention of the operational rate. + +## Proof + +The two inequalities are the two halves of the theorem, both already developed upstream: + +* **Converse** `channelOpCapacity q ≤ channelCapacity q / log 2` + (`Real.channelOpCapacity_le_channelCapacity_div`, Fano + data-processing + single-letterization). +* **Achievability** `channelCapacity q / log 2 ≤ channelOpCapacity q` + (`Real.channelCapacity_div_le_channelOpCapacity`, proved here): the *fixed-input* achievability + `Real.isAchievableRate_of_lt_channelMutualInfo` (random coding + expurgation) says every rate `R` + with `R · log 2 < channelMutualInfo q p` is achievable. Lifting it over the *capacity-attaining* + input distribution `p⋆` (the `max_{p(x)}` of eq. (12.67), which exists by + `Real.exists_isMaxOn_channelMutualInfo`), every rate `R < channelCapacity q / log 2` satisfies + `R · log 2 < channelCapacity q = channelMutualInfo q p⋆`, hence is achievable, hence is + `≤ channelOpCapacity q`; as this holds for all such `R`, `channelCapacity q / log 2 ≤ + channelOpCapacity q` (`exists_between`). + +`le_antisymm` of the two directions gives the equality. + +## Main declarations + +* `Real.channelCapacity_div_le_channelOpCapacity` — the achievability direction + `channelCapacity q / log 2 ≤ channelOpCapacity q`. +* `Real.channelOpCapacity_eq_channelCapacity_div` — **Shannon's noisy channel coding theorem**: + `channelOpCapacity q = channelCapacity q / log 2`, i.e. `C(N) = max_{p(x)} H(X : Y)`. +-/ + +@[expose] public section + +open Finset Filter Topology + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- **Achievability half of Shannon's noisy channel coding theorem** (Nielsen & Chuang, +Theorem 12.7): the information capacity is a lower bound for the operational capacity, +`channelCapacity q / log 2 ≤ channelOpCapacity q`. + +Every rate `R` strictly below `channelCapacity q / log 2` is achievable: at the capacity-attaining +input `p⋆` (`exists_isMaxOn_channelMutualInfo`), `R · log 2 < channelCapacity q = +channelMutualInfo q p⋆`, so fixed-input achievability (`isAchievableRate_of_lt_channelMutualInfo`) +makes `R` achievable, whence `R ≤ channelOpCapacity q` (`le_channelOpCapacity`). Since this bounds +every `R` below `channelCapacity q / log 2`, so is their supremum. -/ +theorem channelCapacity_div_le_channelOpCapacity [Nonempty ι] {q : ι → κ → ℝ} + (hN : IsChannel q) : channelCapacity q / Real.log 2 ≤ channelOpCapacity q := by + obtain ⟨p, hp, _, hpeq⟩ := exists_isMaxOn_channelMutualInfo q + have hlog2 : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + -- Every rate `R < channelCapacity q / log 2` is achievable — at the capacity-attaining input `p`, + -- `R · log 2 < channelMutualInfo q p` — hence `R ≤ channelOpCapacity q`; a dense-order bound + -- lifts this to the supremum `channelCapacity q / log 2`. + exact le_of_forall_lt_imp_le_of_dense fun R hR => + le_channelOpCapacity hN (isAchievableRate_of_lt_channelMutualInfo hN hp.1 hp.2 + (hpeq ▸ (lt_div_iff₀ hlog2).mp hR)) + +/-- **Shannon's noisy channel coding theorem** (Nielsen & Chuang, Theorem 12.7, eq. (12.67)): the +operational capacity `C(N)` of a discrete memoryless channel equals its information capacity +`max_{p(x)} H(X : Y)`, + +`channelOpCapacity q = channelCapacity q / log 2`. + +The operational rate is measured in bits and the mutual information in nats, so `channelCapacity q` +(in nats) is divided by `log 2` to convert to bits. `le_antisymm` of the converse +(`channelOpCapacity_le_channelCapacity_div`) and the achievability direction +(`channelCapacity_div_le_channelOpCapacity`). -/ +theorem channelOpCapacity_eq_channelCapacity_div [Nonempty ι] [Nonempty κ] {q : ι → κ → ℝ} + (hN : IsChannel q) : channelOpCapacity q = channelCapacity q / Real.log 2 := + le_antisymm (channelOpCapacity_le_channelCapacity_div hN) + (channelCapacity_div_le_channelOpCapacity hN) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelExpurgation.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelExpurgation.lean new file mode 100644 index 0000000000..20bbc805e8 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelExpurgation.lean @@ -0,0 +1,183 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.NoisyChannel + +/-! +# Expurgation: from average error to maximum error (Shannon's noisy channel coding theorem) + +The achievability half of Shannon's noisy channel coding theorem (Nielsen & Chuang, Theorem 12.7; +Cover–Thomas, Theorem 7.7.1) produces, by random coding, a block code whose *average* decoding error +over the messages is small. Reliable communication in the sense of Nielsen & Chuang eq. (12.66) is +measured by the *maximum* decoding error `Real.ChannelCode.maxErrorProb`, so the average bound must +be upgraded to a maximum bound. This is the standard **expurgation** step: throw away the worst half +of the codewords, and the surviving half have small maximum error at essentially the same rate. + +This file is pure block-code combinatorics — it does not use the random-coding machinery — and +provides the two reusable pieces: + +* `Real.ChannelCode.comp` — the **sub-code** selecting the `g`-indexed sub-family of the messages of + a code (`g : Fin M' → Fin M`), re-indexing the decoder accordingly (decode an output to the unique + message `i` with `g i = code.decode y`, falling back to a default message otherwise). For an + injective `g`, selecting messages only shrinks each conditional error event, so + `Real.ChannelCode.condErrorProb_comp_le` bounds each conditional error of the sub-code by the + corresponding error of the parent code, and `Real.ChannelCode.maxErrorProb_comp_le` bounds the + block error of the sub-code by any common bound on the selected conditional errors. +* `Real.exists_channelCode_maxErrorProb_le` — the **expurgation existence** statement: a code on `M` + messages with average error `M⁻¹ ∑ₘ condErrorProb m ≤ a` has a sub-code on `⌈M/2⌉ = (M + 1) / 2` + messages with `maxErrorProb ≤ 2 a`. A Markov/counting argument shows at least `⌈M/2⌉` of the + messages have conditional error `≤ 2 a`; selecting exactly those via `comp` and + `Finset.orderEmbOfCardLe` bounds the maximum error. + +The `n → ∞` assembly (extracting a good deterministic codebook from the random-coding limit by the +probabilistic method, expurgating it, and matching the message count to the rate) is not in this +file. + +## Main declarations + +* `Real.ChannelCode.comp` — the `g`-selected sub-code. +* `Real.ChannelCode.condErrorProb_comp_le` — a selected message's conditional error is at most the + parent's. +* `Real.ChannelCode.maxErrorProb_comp_le` — selecting messages does not increase the block error. +* `Real.exists_channelCode_maxErrorProb_le` — expurgation: average error `≤ a` on `M` messages gives + maximum error `≤ 2 a` on `(M + 1) / 2` messages. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {ι κ : Type*} [Fintype κ] + +/-! ### Selecting a sub-family of messages -/ + +open Classical in +/-- The **sub-code** of `code : ChannelCode ι κ n M` selecting the `g`-indexed sub-family of its +messages, for `g : Fin M' → Fin M`. Message `i : Fin M'` is encoded as the parent codeword +`code.encode (g i)`; an output string `y` is decoded to the unique `i` with `g i = code.decode y` +when one exists (for injective `g` there is at most one), and to the fallback message `dflt` +otherwise. When `g` selects a subset of messages this restricts the code to that subset. -/ +noncomputable def ChannelCode.comp {n M M' : ℕ} (code : ChannelCode ι κ n M) (g : Fin M' → Fin M) + (dflt : Fin M') : ChannelCode ι κ n M' where + encode i := code.encode (g i) + decode y := if h : ∃ i, g i = code.decode y then h.choose else dflt + +/-- **Selecting messages shrinks the conditional error.** For an injective selection +`g : Fin M' → Fin M`, the conditional block-error probability of message `i` in the sub-code +`code.comp g dflt` is at most that of the corresponding parent message `g i`: a decoding error in +the sub-code forces the parent decoder to miss `g i` (if the parent decoded to `g i`, injectivity +makes the sub-code decode to `i`), so the sub-code's error event is a subset of the parent's. -/ +theorem ChannelCode.condErrorProb_comp_le {q : ι → κ → ℝ} (hN : IsChannel q) {n M M' : ℕ} + (code : ChannelCode ι κ n M) {g : Fin M' → Fin M} (hg : Function.Injective g) (dflt : Fin M') + (i : Fin M') : (code.comp g dflt).condErrorProb q i ≤ code.condErrorProb q (g i) := by + classical + have henc : (code.comp g dflt).encode i = code.encode (g i) := rfl + rw [ChannelCode.condErrorProb, ChannelCode.condErrorProb, henc] + refine Finset.sum_le_sum_of_subset_of_nonneg ?_ (fun y _ _ => channelSeqProb_nonneg hN _ _) + intro y hy + simp only [mem_filter, mem_univ, true_and] at hy ⊢ + intro hcontra + apply hy + change (if h : ∃ i', g i' = code.decode y then h.choose else dflt) = i + have hex : ∃ i', g i' = code.decode y := ⟨i, hcontra.symm⟩ + rw [dite_eq_left hex] + exact hg (hex.choose_spec.trans hcontra) + +/-- **Selecting messages does not increase the block error.** If every selected parent message has +conditional error at most `b` (with `0 ≤ b`), then the block-error probability of the sub-code +`code.comp g dflt` is at most `b`. Combined with `condErrorProb_comp_le`, this is the mechanism of +expurgation: dropping the high-error messages leaves a code with a uniformly small block error. -/ +theorem ChannelCode.maxErrorProb_comp_le {q : ι → κ → ℝ} (hN : IsChannel q) {n M M' : ℕ} + (code : ChannelCode ι κ n M) {g : Fin M' → Fin M} (hg : Function.Injective g) (dflt : Fin M') + {b : ℝ} (hb : ∀ i, code.condErrorProb q (g i) ≤ b) (hb0 : 0 ≤ b) : + (code.comp g dflt).maxErrorProb q ≤ b := by + rw [ChannelCode.maxErrorProb] + exact Real.iSup_le (fun i => (code.condErrorProb_comp_le hN hg dflt i).trans (hb i)) hb0 + +/-! ### Expurgation -/ + +/-- **Expurgation (average error → maximum error).** A block code on `M > 0` messages whose +*average* conditional error `M⁻¹ ∑ₘ condErrorProb m` is at most `a` has a sub-code on +`⌈M/2⌉ = (M + 1) / 2` +messages whose *maximum* error `maxErrorProb` is at most `2 a`. + +By a Markov/counting argument, at most `⌊M/2⌋` messages can have conditional error exceeding `2 a` +(otherwise the average would exceed `a`), so at least `(M + 1) / 2` messages have conditional error +`≤ 2 a`. Selecting exactly `(M + 1) / 2` of those good messages with `Finset.orderEmbOfCardLe` and +forming the corresponding sub-code (`ChannelCode.comp`) bounds every conditional error — hence the +block error — by `2 a` (`maxErrorProb_comp_le`). This is Cover–Thomas Theorem 7.7.1's expurgation +step, which upgrades the codebook-averaged error of the random-coding argument to the worst-case +error of Nielsen & Chuang eq. (12.66). -/ +theorem exists_channelCode_maxErrorProb_le {q : ι → κ → ℝ} (hN : IsChannel q) {n M : ℕ} (hM : 0 < M) + (code : ChannelCode ι κ n M) {a : ℝ} + (havg : (M : ℝ)⁻¹ * ∑ m, code.condErrorProb q m ≤ a) : + ∃ code' : ChannelCode ι κ n ((M + 1) / 2), code'.maxErrorProb q ≤ 2 * a := by + classical + have hMR : (0 : ℝ) < M := by exact_mod_cast hM + set S : ℝ := ∑ m, code.condErrorProb q m with hSdef + have hSnn : 0 ≤ S := Finset.sum_nonneg fun m _ => code.condErrorProb_nonneg hN m + -- `0 ≤ a` and `S ≤ M · a`. + have ha0 : 0 ≤ a := le_trans (by positivity) havg + have hSle : S ≤ (M : ℝ) * a := by + have h := mul_le_mul_of_nonneg_left havg hMR.le + rwa [mul_inv_cancel_left₀ (ne_of_gt hMR)] at h + -- The good and bad message sets. + set Bad : Finset (Fin M) := univ.filter (fun m => ¬ code.condErrorProb q m ≤ 2 * a) with hBaddef + set Good : Finset (Fin M) := univ.filter (fun m => code.condErrorProb q m ≤ 2 * a) with hGooddef + -- Markov: the bad messages carry mass `≥ Bad.card · (2a)`, which is `≤ S ≤ M · a`. + have hMarkov : (Bad.card : ℝ) * (2 * a) ≤ (M : ℝ) * a := by + calc (Bad.card : ℝ) * (2 * a) = ∑ _m ∈ Bad, (2 * a) := by rw [Finset.sum_const, nsmul_eq_mul] + _ ≤ ∑ m ∈ Bad, code.condErrorProb q m := by + refine Finset.sum_le_sum fun m hm => ?_ + rw [hBaddef, mem_filter, not_le] at hm + exact hm.2.le + _ ≤ S := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun m _ _ => code.condErrorProb_nonneg hN m) + _ ≤ (M : ℝ) * a := hSle + -- Hence at most `⌊M/2⌋` bad messages, so at least `(M+1)/2` good ones. + have hBadcard : 2 * Bad.card ≤ M := by + rcases eq_or_lt_of_le ha0 with ha | ha + · -- `a = 0`: the average is `0`, so every conditional error is `0`, so `Bad` is empty. + have hS0 : S = 0 := le_antisymm (by rw [← ha] at hSle; simpa using hSle) hSnn + have hall := (Finset.sum_eq_zero_iff_of_nonneg + (fun m _ => code.condErrorProb_nonneg hN m)).mp (hSdef ▸ hS0) + have hBadempty : Bad = ∅ := by + rw [hBaddef, Finset.filter_eq_empty_iff] + intro m _ + rw [not_not, hall m (mem_univ m)] + linarith + rw [hBadempty]; simp + · -- `0 < a`: cancel `a` from the Markov inequality. + have key : (2 * (Bad.card : ℝ)) * a ≤ (M : ℝ) * a := by + calc (2 * (Bad.card : ℝ)) * a = (Bad.card : ℝ) * (2 * a) := by ring + _ ≤ (M : ℝ) * a := hMarkov + have : (2 * (Bad.card : ℝ)) ≤ (M : ℝ) := le_of_mul_le_mul_right key ha + exact_mod_cast this + -- `Good` and `Bad` partition the messages, so `(M+1)/2 ≤ Good.card`. + have hpart : Good.card + Bad.card = M := by + rw [hGooddef, hBaddef] + simpa using Finset.card_filter_add_card_filter_not (s := (univ : Finset (Fin M))) + (fun m => code.condErrorProb q m ≤ 2 * a) + have hGoodcard : (M + 1) / 2 ≤ Good.card := by omega + -- Select `(M+1)/2` good messages as an injective `g`; their parent errors are all `≤ 2a`. + set g : Fin ((M + 1) / 2) → Fin M := ⇑(Good.orderEmbOfCardLe hGoodcard) with hgdef + have hginj : Function.Injective g := (Good.orderEmbOfCardLe hGoodcard).injective + have hgle : ∀ i, code.condErrorProb q (g i) ≤ 2 * a := by + intro i + have hmem : g i ∈ Good := Good.orderEmbOfCardLe_mem hGoodcard i + rw [hGooddef, mem_filter] at hmem + exact hmem.2 + -- The corresponding sub-code has maximum error `≤ 2a`. + have hM'pos : 0 < (M + 1) / 2 := by omega + exact ⟨code.comp g ⟨0, hM'pos⟩, code.maxErrorProb_comp_le hN hginj _ hgle (by linarith)⟩ + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCoding.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCoding.lean new file mode 100644 index 0000000000..512f098d02 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCoding.lean @@ -0,0 +1,453 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelTypicalSequence +public import LeanPool.AxQM.ToMathlib.InformationTheory.RandomCodingExpectation + +/-! +# The random codebook for Shannon's noisy channel coding theorem + +The achievability half of Shannon's noisy channel coding theorem (Nielsen & Chuang, Theorem 12.7) +is proved by a *random coding* argument (Cover–Thomas, ch. 7.7): to show that a good `M`-message, +length-`n` code exists, one averages the decoding error over a **random codebook** in which every +codeword letter is drawn independently from the input distribution `p`, and shows the average error +is small. This file records the random-codebook law, the marginalization of an expectation over it, +and the resulting bound on the codebook-averaged decoding error — the probabilistic bookkeeping that +turns "expected error over codebooks" into the joint-AEP and packing estimates of +`ToMathlib.InformationTheory.ChannelTypicalSequence`. + +A **codebook** is a map `C : Fin M → (Fin n → ι)` assigning to each of the `M` messages a length-`n` +input string. Drawing every letter `C m j` independently from `p` gives the codebook the product law + +`Real.channelCodebookProb p C = ∏ₘ ∏ⱼ p (C m j)`, + +a probability distribution on the codebook space (`Real.sum_channelCodebookProb`). The engine behind +every marginalization is the elementary identity `∑_C ∏ₘ g m (C m) = ∏ₘ ∑ₓ g m x` (the sum over a +function space of a product equals the product of the sums), available as the general lemma +`Real.sum_prod_apply_eq_prod_sum`. Its first consequence is the **single-codeword marginal** +`Real.sum_channelCodebookProb_mul_single`: the expectation over the random codebook of a quantity +depending on a *single* codeword `C k` collapses to an expectation over that one codeword drawn +i.i.d. from `p`, + +`∑_C channelCodebookProb p C · F (C k) = ∑ₓ (∏ⱼ p (xⱼ)) · F x`, + +because the other `M − 1` codewords each marginalize to total mass `1`. Applied to the transmitted +codeword, this reduces the "the true input–output pair is atypical" term of the random-coding error +analysis to the joint AEP (`Real.exists_le_sum_channelTypicalPairs`). Its two-codeword counterpart +`Real.sum_channelCodebookProb_mul_pair` (a specialization of the general +`Real.sum_pi_weight_mul_apply₂`) factorises an expectation depending on two *distinct* codewords +into the product of the two independent i.i.d. marginals. + +## The joint-typicality decoder and the random-coding error bound + +The random code decodes a received output string `y` by the **joint-typicality rule** +`Real.channelJointTypicalDecode`: return the *unique* message whose codeword is jointly typical with +`y` (else a fixed fallback message). The resulting `Real.ChannelCode` is +`Real.channelJointTypicalCode`. A decoding error for the sent message `m` implies either the true +pair `(C m, y)` is atypical or some competing codeword `C m'` (`m' ≠ m`) is jointly typical with `y` +(`Real.channelJointTypicalDecode_eq_of_unique`). Averaging over the random codebook and bounding the +two contributions by the joint AEP (a single-codeword marginal → `1 − typical mass`) and the packing +bound (two-codeword marginal → `channelIndepPairProb` mass +`≤ exp(-n(H(X:Y)-3ε))` per competing codeword) gives the **expected-error bound** + +`Real.sum_channelCodebookProb_condErrorProb_le` (per message) and its message-average +`Real.channelRandomCode_expectedAvgError_le`: + +`𝔼_C[avg error] ≤ (1 − ∑_{typ} channelPairSeqProb) + (M − 1) · exp(-n(H(X:Y) − 3ε))`. + +Driving this bound to `0` for a rate below `H(X : Y)` (the `n → ∞` limit) is not done in this file, +which proves the exact per-`n` inequality. + +## Main declarations + +* `Real.channelCodebookProb` — the i.i.d. random-codebook law `∏ₘ ∏ⱼ p (C m j)`. +* `Real.sum_channelCodebookProb` — the codebook law is a probability distribution (total mass `1`). +* `Real.sum_channelCodebookProb_mul_single` — the single-codeword marginal of a codebook + expectation. +* `Real.sum_channelCodebookProb_mul_pair` — the two-codeword (independence) marginal. +* `Real.channelJointTypicalDecode`, `Real.channelJointTypicalCode` — the joint-typicality decoder + and the code it defines. +* `Real.channelJointTypicalDecode_eq_of_unique` — the decoder recovers the sent message when its + codeword is the unique jointly-typical one. +* `Real.sum_channelCodebookProb_condErrorProb_le`, + `Real.channelRandomCode_expectedAvgError_le` — the codebook-averaged decoding-error bound. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-! ### The random-codebook law -/ + +/-- The **i.i.d. random-codebook law**: the probability `∏ₘ ∏ⱼ p (C m j)` that a random codebook +`C : Fin M → (Fin n → ι)` — assigning to each of the `M` messages a length-`n` input codeword — +arises when every codeword letter `C m j` is drawn independently from the input distribution `p`. +This is the measure over which the random-coding argument averages the decoding error. -/ +noncomputable def channelCodebookProb (p : ι → ℝ) {M n : ℕ} (C : Fin M → Fin n → ι) : ℝ := + ∏ m, ∏ j, p (C m j) + +omit [Fintype ι] in +/-- The random-codebook law is nonnegative for a nonnegative input distribution. -/ +theorem channelCodebookProb_nonneg {p : ι → ℝ} (hp0 : ∀ x, 0 ≤ p x) {M n : ℕ} + (C : Fin M → Fin n → ι) : 0 ≤ channelCodebookProb p C := + Finset.prod_nonneg fun _ _ => Finset.prod_nonneg fun _ _ => hp0 _ + +/-- The random-codebook law is a probability distribution: its total mass is `1`. Marginalizing each +of the `M` independent codewords via `sum_prod_apply_eq_prod_sum` leaves +`∏ₘ (∑ₓ ∏ⱼ p (xⱼ)) = ∏ₘ 1 = 1`, the `M`-fold product of the i.i.d. total mass `iid_total_mass`. -/ +theorem sum_channelCodebookProb {p : ι → ℝ} (hp1 : ∑ x, p x = 1) {M n : ℕ} : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C = 1 := by + simp_rw [channelCodebookProb] + rw [sum_prod_apply_eq_prod_sum (fun (_ : Fin M) (x : Fin n → ι) => ∏ j, p (x j))] + simp_rw [iid_total_mass, hp1, one_pow, Finset.prod_const_one] + +/-- **The single-codeword marginal of a codebook expectation.** The expectation over the random +codebook of a quantity `F` depending on a single codeword `C k` reduces to the expectation over that +one codeword drawn i.i.d. from `p`: + +`∑_C channelCodebookProb p C · F (C k) = ∑ₓ (∏ⱼ p (xⱼ)) · F x`. + +The other `M − 1` codewords appear only through the codebook law, so each marginalizes to total +mass `1` and drops out (`Finset.prod_eq_single` over `sum_prod_apply_eq_prod_sum`). This is the +identity that, applied to the transmitted codeword, turns the "true pair is atypical" term of the +random-coding error into the joint AEP. -/ +theorem sum_channelCodebookProb_mul_single {p : ι → ℝ} (hp1 : ∑ x, p x = 1) {M n : ℕ} + (F : (Fin n → ι) → ℝ) (k : Fin M) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * F (C k) + = ∑ x, (∏ j, p (x j)) * F x := by + have hg : ∀ C : Fin M → (Fin n → ι), + channelCodebookProb p C * F (C k) + = ∏ m, (∏ j, p (C m j)) * (if m = k then F (C m) else 1) := by + intro C + rw [channelCodebookProb, Finset.prod_mul_distrib, Finset.prod_ite_eq'] + simp + simp_rw [hg] + rw [sum_prod_apply_eq_prod_sum + (fun (m : Fin M) (x : Fin n → ι) => (∏ j, p (x j)) * (if m = k then F x else 1)), + Finset.prod_eq_single k] + · simp + · intro m _ hmk + simp only [ite_eq_right hmk, mul_one] + rw [iid_total_mass, hp1, one_pow] + · intro hk + exact absurd (mem_univ k) hk + +open Classical in +/-- Re-fold a doubly-indexed sum over the fibres of a pair-Finset `s` into a single sum over `s`: +`∑ₓ ∑_{y : (x, y) ∈ s} g (x, y) = ∑_{xy ∈ s} g xy`. The bookkeeping identity used to combine the +per-input-string sums of the random-coding error analysis into sums over the jointly typical set. -/ +private theorem sum_pair_filter_fold {n : ℕ} (g : (Fin n → ι) × (Fin n → κ) → ℝ) + (s : Finset ((Fin n → ι) × (Fin n → κ))) : + ∑ x, ∑ y ∈ univ.filter (fun y => (x, y) ∈ s), g (x, y) = ∑ xy ∈ s, g xy := by + classical + conv_rhs => rw [← Finset.filter_univ_mem s, Finset.sum_filter, Fintype.sum_prod_type] + refine Finset.sum_congr rfl fun x _ => ?_ + rw [Finset.sum_filter] + +/-- **The two-codeword (independence) marginal of a codebook expectation.** For two *distinct* +messages `k ≠ l`, the expectation over the random codebook of a quantity `F` depending on the two +codewords `C k` and `C l` factorises over the two independent codewords, each drawn i.i.d. from `p`: + +`∑_C channelCodebookProb p C · F (C k) (C l) = ∑ₐ ∑_b (∏ⱼ p (aⱼ)) · (∏ⱼ p (bⱼ)) · F a b`. + +The remaining `M − 2` codewords each marginalize to total mass `1`; this is the specialization of +the general `sum_pi_weight_mul_apply₂` to the i.i.d. weight `W x = ∏ⱼ p (xⱼ)` (whose total mass is +`1` by `iid_total_mass`). Applied to the transmitted and a competing codeword, it turns the "a wrong +codeword looks jointly typical" term of the random-coding error into the packing bound. -/ +theorem sum_channelCodebookProb_mul_pair {p : ι → ℝ} (hp1 : ∑ x, p x = 1) {M n : ℕ} + (F : (Fin n → ι) → (Fin n → ι) → ℝ) {k l : Fin M} (hkl : k ≠ l) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * F (C k) (C l) + = ∑ a, ∑ b, (∏ j, p (a j)) * (∏ j, p (b j)) * F a b := by + have hW : ∑ x : Fin n → ι, ∏ j, p (x j) = 1 := by rw [iid_total_mass, hp1, one_pow] + simpa only [channelCodebookProb] using + sum_pi_weight_mul_apply₂ (fun x => ∏ j, p (x j)) hW F hkl + +/-! ### The joint-typicality decoder and its code -/ + +open Classical in +/-- The **joint-typicality decoder** for a codebook `C : Fin M → (Fin n → ι)` at block length `n` +and tolerance `ε` (Cover–Thomas, ch. 7.7). On receiving the output string `y`, it decodes to the +*unique* message `m` whose codeword `C m` is jointly typical with `y` +(`(C m, y) ∈ channelTypicalPairs`); if there is no such message, or more than one, it declares a +decoding failure by returning the fallback message `m₀`. -/ +noncomputable def channelJointTypicalDecode (q : ι → κ → ℝ) (p : ι → ℝ) (n : ℕ) (ε : ℝ) {M : ℕ} + (m₀ : Fin M) (C : Fin M → Fin n → ι) (y : Fin n → κ) : Fin M := + if h : ∃ m, (C m, y) ∈ channelTypicalPairs q p n ε ∧ + ∀ m', (C m', y) ∈ channelTypicalPairs q p n ε → m' = m + then h.choose else m₀ + +/-- The **joint-typicality random code** built from a codebook `C`: it encodes message `m` as the +codeword `C m` and decodes by the joint-typicality rule `channelJointTypicalDecode` (fallback +message `m₀`). This is the code whose codebook-averaged decoding error the random-coding argument +bounds. -/ +noncomputable def channelJointTypicalCode (q : ι → κ → ℝ) (p : ι → ℝ) (n : ℕ) (ε : ℝ) {M : ℕ} + (m₀ : Fin M) (C : Fin M → Fin n → ι) : ChannelCode ι κ n M where + encode := C + decode := channelJointTypicalDecode q p n ε m₀ C + +open Classical in +/-- **Correctness of the joint-typicality decoder.** If the received output `y` makes the sent +codeword `C m` jointly typical and leaves *no other* codeword jointly typical with `y`, the decoder +recovers `m`. Contrapositively, a decoding error for message `m` forces either the true pair +`(C m, y)` to be atypical or some competing codeword `C m'` (`m' ≠ m`) to be jointly typical with +`y` — the union-bound decomposition of the error event. -/ +theorem channelJointTypicalDecode_eq_of_unique {q : ι → κ → ℝ} {p : ι → ℝ} {n : ℕ} {ε : ℝ} + {M : ℕ} (m₀ : Fin M) {C : Fin M → Fin n → ι} {y : Fin n → κ} {m : Fin M} + (hm : (C m, y) ∈ channelTypicalPairs q p n ε) + (huniq : ∀ m', m' ≠ m → (C m', y) ∉ channelTypicalPairs q p n ε) : + channelJointTypicalDecode q p n ε m₀ C y = m := by + have hex : ∃ m'', (C m'', y) ∈ channelTypicalPairs q p n ε ∧ + ∀ m', (C m', y) ∈ channelTypicalPairs q p n ε → m' = m'' := + ⟨m, hm, fun m' hm' => by by_contra hne; exact huniq m' hne hm'⟩ + unfold channelJointTypicalDecode + rw [dite_eq_left hex] + exact (hex.choose_spec.2 m hm).symm + +/-! ### The codebook-averaged decoding-error bound -/ + +open Classical in +/-- **The expected confusion term.** For a competing message `m' ≠ m`, the expectation over the +random codebook of the probability that the (independent) codeword `C m'` looks jointly typical with +the output produced by the sent codeword `C m` is bounded by the packing exponent +`exp(-n (H(X:Y) − 3ε))`. The two-codeword marginal factorises the expectation into the independent +input–output pair law `channelIndepPairProb`, then the packing bound +`sum_indep_channelTypicalPairs_le` closes it. -/ +private theorem sum_channelCodebookProb_confusion_le {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {n : ℕ} {ε : ℝ} {M : ℕ} {m m' : Fin M} + (hmm' : m' ≠ m) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y + ≤ Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + have key : ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), channelSeqProb q (C m) y + = ∑ xy ∈ channelTypicalPairs q p n ε, channelIndepPairProb q p xy := by + rw [sum_channelCodebookProb_mul_pair hp1 + (fun a b => ∑ y ∈ univ.filter (fun y => (a, y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q b y) hmm'] + have step : ∀ a : Fin n → ι, + ∑ b, (∏ j, p (a j)) * (∏ j, p (b j)) * + ∑ y ∈ univ.filter (fun y => (a, y) ∈ channelTypicalPairs q p n ε), channelSeqProb q b y + = ∑ y ∈ univ.filter (fun y => (a, y) ∈ channelTypicalPairs q p n ε), + channelIndepPairProb q p (a, y) := by + intro a + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun y _ => ?_ + rw [channelIndepPairProb_mk, ← sum_fst_channelPairSeqProb p y, Finset.mul_sum] + refine Finset.sum_congr rfl fun b _ => ?_ + rw [channelPairSeqProb_mk]; ring + simp_rw [step] + exact sum_pair_filter_fold (channelIndepPairProb q p) (channelTypicalPairs q p n ε) + rw [key] + exact sum_indep_channelTypicalPairs_le hN hp0 hp1 + +open Classical in +/-- **The expected true-atypical term.** The expectation over the random codebook of the probability +that the true input–output pair `(C m, Y)` is *atypical* equals `1 − (typical mass)`, the joint-AEP +complement. The single-codeword marginal collapses it onto the joint sequence law +`channelPairSeqProb`, whose total mass is `1`. -/ +private theorem sum_channelCodebookProb_trueAtypical {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp1 : ∑ x, p x = 1) {n : ℕ} {ε : ℝ} {M : ℕ} (m : Fin M) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y + = 1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy := by + rw [sum_channelCodebookProb_mul_single hp1 + (fun x => ∑ y ∈ univ.filter (fun y => (x, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q x y) m] + have hsplit : ∀ x : Fin n → ι, + ∑ y ∈ univ.filter (fun y => (x, y) ∉ channelTypicalPairs q p n ε), channelSeqProb q x y + = 1 - ∑ y ∈ univ.filter (fun y => (x, y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q x y := by + intro x + have h := Finset.sum_filter_add_sum_filter_not univ + (fun y => (x, y) ∈ channelTypicalPairs q p n ε) (channelSeqProb q x) + rw [sum_channelSeqProb hN x] at h + linarith + simp_rw [hsplit, mul_sub, mul_one] + rw [Finset.sum_sub_distrib] + congr 1 + · rw [iid_total_mass, hp1, one_pow] + · simp_rw [Finset.mul_sum] + rw [← sum_pair_filter_fold (channelPairSeqProb q p) (channelTypicalPairs q p n ε)] + refine Finset.sum_congr rfl fun x _ => Finset.sum_congr rfl fun y _ => ?_ + rw [channelPairSeqProb_mk] + +/-- **The codebook-averaged conditional decoding-error bound, per message.** For each message `m`, +the expectation over the random codebook of the conditional block-error probability of the +joint-typicality code is bounded by the joint-AEP complement plus `M − 1` competing-codeword packing +terms: + +`∑_C channelCodebookProb p C · condErrorProb (channelJointTypicalCode … m₀ C) m + ≤ (1 − ∑_{typ} channelPairSeqProb) + (M − 1) · exp(-n (H(X:Y) − 3ε))`. + +The decoding-error event `{y | decode y ≠ m}` is contained in the "true pair atypical" event union +the `M − 1` "competing codeword jointly typical" events +(`channelJointTypicalDecode_eq_of_unique`); averaging over codebooks bounds the first term by +`sum_channelCodebookProb_trueAtypical` (single marginal) and each competing term by +`sum_channelCodebookProb_confusion_le` (two-codeword marginal + packing). -/ +theorem sum_channelCodebookProb_condErrorProb_le {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {n : ℕ} {ε : ℝ} {M : ℕ} (m₀ m : Fin M) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m + ≤ (1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + classical + have hpt : ∀ C : Fin M → (Fin n → ι), + (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m + ≤ (∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) + + ∑ m' ∈ univ.filter (fun m' => m' ≠ m), + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := by + intro C + have hnn : ∀ y, 0 ≤ channelSeqProb q (C m) y := fun y => channelSeqProb_nonneg hN _ _ + have hce : (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m + = ∑ y ∈ univ.filter (fun y => channelJointTypicalDecode q p n ε m₀ C y ≠ m), + channelSeqProb q (C m) y := rfl + rw [hce] + have hsub : univ.filter (fun y => channelJointTypicalDecode q p n ε m₀ C y ≠ m) + ⊆ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε) + ∪ univ.filter (fun y => ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε) := by + intro y hy + simp only [mem_filter, mem_univ, true_and, mem_union] at hy ⊢ + by_contra hcon + rw [not_or] at hcon + obtain ⟨h1, h2⟩ := hcon + exact hy (channelJointTypicalDecode_eq_of_unique m₀ (not_not.mp h1) + (fun m' hne hin => h2 ⟨m', hne, hin⟩)) + calc ∑ y ∈ univ.filter (fun y => channelJointTypicalDecode q p n ε m₀ C y ≠ m), + channelSeqProb q (C m) y + ≤ ∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε) + ∪ univ.filter (fun y => ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := + Finset.sum_le_sum_of_subset_of_nonneg hsub (fun y _ _ => hnn y) + _ ≤ (∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) + + ∑ y ∈ univ.filter (fun y => ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := by + have hui := Finset.sum_union_inter + (s₁ := univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε)) + (s₂ := univ.filter (fun y => ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε)) + (f := channelSeqProb q (C m)) + have hnn2 : 0 ≤ ∑ y ∈ (univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε)) + ∩ univ.filter (fun y => ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := + Finset.sum_nonneg fun y _ => hnn y + linarith + _ ≤ (∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) + + ∑ m' ∈ univ.filter (fun m' => m' ≠ m), + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := by + gcongr + have hR : ∀ m' : Fin M, + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y + = ∑ y, if (C m', y) ∈ channelTypicalPairs q p n ε then channelSeqProb q (C m) y + else 0 := fun m' => Finset.sum_filter _ _ + simp_rw [hR] + rw [Finset.sum_filter, Finset.sum_comm] + refine Finset.sum_le_sum fun y _ => ?_ + have hnn0 : ∀ i : Fin M, + 0 ≤ if (C i, y) ∈ channelTypicalPairs q p n ε then channelSeqProb q (C m) y else 0 := + fun i => by split_ifs <;> first | exact hnn y | exact le_rfl + by_cases h : ∃ m', m' ≠ m ∧ (C m', y) ∈ channelTypicalPairs q p n ε + · rw [ite_eq_left h] + obtain ⟨m', hm'ne, hm'Q⟩ := h + have hmem : m' ∈ univ.filter (fun m'' : Fin M => m'' ≠ m) := + Finset.mem_filter.mpr ⟨mem_univ m', hm'ne⟩ + have hterm := Finset.single_le_sum + (f := fun i => if (C i, y) ∈ channelTypicalPairs q p n ε + then channelSeqProb q (C m) y else 0) + (fun i _ => hnn0 i) hmem + rwa [ite_eq_left hm'Q] at hterm + · rw [ite_eq_right h] + exact Finset.sum_nonneg fun m'' _ => hnn0 m'' + calc ∑ C, channelCodebookProb p C * (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m + ≤ ∑ C, channelCodebookProb p C * + ((∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) + + ∑ m' ∈ univ.filter (fun m' => m' ≠ m), + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) := + Finset.sum_le_sum fun C _ => + mul_le_mul_of_nonneg_left (hpt C) (channelCodebookProb_nonneg hp0 C) + _ = (∑ C, channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m, y) ∉ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y) + + ∑ m' ∈ univ.filter (fun m' => m' ≠ m), + ∑ C, channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y := by + simp_rw [mul_add, Finset.mul_sum] + rw [Finset.sum_add_distrib, Finset.sum_comm] + _ ≤ (1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + gcongr ?_ + ?_ + · exact le_of_eq (sum_channelCodebookProb_trueAtypical hN hp1 m) + · calc ∑ m' ∈ univ.filter (fun m' => m' ≠ m), + ∑ C, channelCodebookProb p C * + ∑ y ∈ univ.filter (fun y => (C m', y) ∈ channelTypicalPairs q p n ε), + channelSeqProb q (C m) y + ≤ ∑ _m' ∈ univ.filter (fun m' => m' ≠ m), + Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := + Finset.sum_le_sum fun m' hm' => + sum_channelCodebookProb_confusion_le hN hp0 hp1 (Finset.mem_filter.mp hm').2 + _ = ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + rw [Finset.sum_const, nsmul_eq_mul] + congr 1 + rw [Finset.filter_ne', Finset.card_erase_of_mem (mem_univ m), + Finset.card_univ, Fintype.card_fin, Nat.cast_sub (m.pos), Nat.cast_one] + +/-- **The codebook-averaged decoding-error bound (message-average form).** Averaging the per-message +bound `sum_channelCodebookProb_condErrorProb_le` over the `M` messages, the expectation over the +random codebook of the *average* decoding error of the joint-typicality code satisfies + +`∑_C channelCodebookProb p C · (M⁻¹ ∑ₘ condErrorProb (channelJointTypicalCode … m₀ C) m) + ≤ (1 − ∑_{typ} channelPairSeqProb) + (M − 1) · exp(-n (H(X:Y) − 3ε))`. + +This is the exact per-`n` inequality of the random-coding argument: the first term vanishes by the +joint AEP and, for a rate `R` with `R · log 2 < H(X : Y)`, the second vanishes as `n → ∞`, so a good +code exists — the achievability half of Theorem 12.7. -/ +theorem channelRandomCode_expectedAvgError_le {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {n : ℕ} {ε : ℝ} {M : ℕ} (m₀ : Fin M) : + ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + ((M : ℝ)⁻¹ * ∑ m, (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m) + ≤ (1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + have hMR : (0 : ℝ) < M := by exact_mod_cast m₀.pos + have hrw : ∑ C : Fin M → (Fin n → ι), channelCodebookProb p C * + ((M : ℝ)⁻¹ * ∑ m, (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m) + = (M : ℝ)⁻¹ * ∑ m, ∑ C, channelCodebookProb p C * + (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m := by + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun m _ => Finset.sum_congr rfl fun C _ => by ring + rw [hrw] + calc (M : ℝ)⁻¹ * ∑ m, ∑ C, channelCodebookProb p C * + (channelJointTypicalCode q p n ε m₀ C).condErrorProb q m + ≤ (M : ℝ)⁻¹ * ∑ _m : Fin M, + ((1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε))) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Finset.sum_le_sum fun m _ => + sum_channelCodebookProb_condErrorProb_le hN hp0 hp1 m₀ m + _ = (1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((M : ℝ) - 1) * Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← mul_assoc, + inv_mul_cancel₀ (ne_of_gt hMR), one_mul] + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCodingLimit.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCodingLimit.lean new file mode 100644 index 0000000000..7b67774250 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelRandomCodingLimit.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.ChannelRandomCoding +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# The `n → ∞` limit of the random-coding error (Shannon's noisy channel coding theorem) + +The achievability half of Shannon's noisy channel coding theorem (Nielsen & Chuang, Theorem 12.7; +Cover–Thomas, ch. 7.7) drives the codebook-averaged decoding error of the joint-typicality random +code to `0`. The exact per-`n` bound is `Real.channelRandomCode_expectedAvgError_le` +(`ToMathlib.InformationTheory.ChannelRandomCoding`): + +`𝔼_C[avg error] ≤ (1 − ∑_{typ} channelPairSeqProb q p) + (M − 1) · exp(-n (H(X:Y) − 3ε))`, + +for a codebook of `M` messages, block length `n`, and tolerance `ε`. This file takes the limit: for +a rate `R` (in bits) with `R · log 2 < H(X : Y) = channelMutualInfo q p` and the message count +`M(n) = ⌈exp(n · R · log 2)⌉₊ = ⌈2^{nR}⌉` of `Real.IsAchievableRate`, both terms of the bound vanish +as `n → ∞`, so the codebook-averaged error tends to `0` +(`Real.tendsto_expectedError_channelRandomCode`). + +The two contributions decay for independent reasons, each isolated as a lemma: + +* **The true-atypical term** `1 − ∑_{typ} channelPairSeqProb q p → 0` + (`Real.tendsto_one_sub_sum_channelTypicalPairs`) is the joint asymptotic equipartition property: + the jointly typical set carries probability `→ 1` (`Real.exists_le_sum_channelTypicalPairs`), and + it is a sub-mass of the total probability `1` (`Real.sum_channelPairSeqProb`), so its complement + `→ 0`. +* **The packing term** `(M(n) − 1) · exp(-n (H(X:Y) − 3ε)) → 0` + (`Real.tendsto_channelPackingTerm`): choosing `ε` with `H(X:Y) − 3ε > R · log 2` makes the + exponent `R · log 2 − (H(X:Y) − 3ε) =: −γ` negative, and `M(n) − 1 ≤ exp(n · R · log 2)`, so the + term is squeezed by `exp(-n γ) = (exp(-γ))ⁿ → 0`. + +Combining the two by a squeeze (both `≥ 0`, sum `≤` the vanishing bound) gives the main result. The +tolerance `ε = (H(X:Y) − R · log 2) / 6` is small enough that `H(X:Y) − 3ε = (H(X:Y) + R·log 2)/2` +strictly exceeds `R · log 2`. Extracting an actual good deterministic code from this +expected-error-`→ 0` statement (the probabilistic method + expurgation) is not done here. + +## Main declarations + +* `Real.tendsto_channelPackingTerm` — the packing term `(⌈exp(n R log 2)⌉₊ − 1)·exp(-n(I − 3ε)) → 0` + whenever `R · log 2 < I − 3ε`. +* `Real.tendsto_one_sub_sum_channelTypicalPairs` — the joint-AEP complement + `1 − ∑_{typ} channelPairSeqProb q p → 0`. +* `Real.tendsto_expectedError_channelRandomCode` — the codebook-averaged decoding error of the + joint-typicality random code tends to `0` for any rate `R` with + `R · log 2 < channelMutualInfo q p`. +-/ + +@[expose] public section + +open Finset Filter Topology + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-! ### Decay of the two contributions to the codebook-averaged error -/ + +/-- **The packing term vanishes.** For reals `R, I, ε` with `R · log 2 < I − 3ε`, the packing +contribution of the random-coding error bound, `(⌈exp(n · R · log 2)⌉₊ − 1) · exp(-n (I − 3ε))`, +tends to `0` as `n → ∞`. The message count `⌈exp(n R log 2)⌉₊ − 1 ≤ exp(n R log 2)` cancels all but +`exp(-n γ)` of the decay exponent `γ = (I − 3ε) − R · log 2 > 0`, and `exp(-n γ) = (exp(-γ))ⁿ → 0` +since `0 ≤ exp(-γ) < 1`. -/ +theorem tendsto_channelPackingTerm {R I ε : ℝ} (hlt : R * Real.log 2 < I - 3 * ε) : + Tendsto (fun n : ℕ => ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) - 1) * + Real.exp (-(n : ℝ) * (I - 3 * ε))) atTop (𝓝 0) := by + set γ := (I - 3 * ε) - R * Real.log 2 with hγ + have hγpos : 0 < γ := by rw [hγ]; linarith + apply tendsto_of_tendsto_of_tendsto_of_le_of_le (g := fun _ => (0 : ℝ)) + (h := fun n : ℕ => (Real.exp (-γ)) ^ n) tendsto_const_nhds + (tendsto_pow_atTop_nhds_zero_of_lt_one (Real.exp_pos _).le + (by rw [Real.exp_lt_one_iff]; linarith)) + · -- the term is nonnegative + intro n + have h1 : (1 : ℝ) ≤ (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) := by + exact_mod_cast Nat.ceil_pos.mpr (Real.exp_pos _) + exact mul_nonneg (by linarith) (Real.exp_pos _).le + · -- the term is at most `(exp(-γ))ⁿ` + intro n + have hMle : (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) - 1 + ≤ Real.exp ((n : ℝ) * R * Real.log 2) := by + have h := Nat.ceil_lt_add_one (Real.exp_pos ((n : ℝ) * R * Real.log 2)).le + linarith + calc ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) - 1) * Real.exp (-(n : ℝ) * (I - 3 * ε)) + ≤ Real.exp ((n : ℝ) * R * Real.log 2) * Real.exp (-(n : ℝ) * (I - 3 * ε)) := + mul_le_mul_of_nonneg_right hMle (Real.exp_pos _).le + _ = Real.exp (-(n : ℝ) * γ) := by rw [← Real.exp_add]; congr 1; rw [hγ]; ring + _ = (Real.exp (-γ)) ^ n := by rw [← Real.exp_nat_mul]; congr 1; ring + +/-- **The true-atypical term vanishes** (the joint asymptotic equipartition property). For `ε > 0`, +the complement of the jointly typical mass, +`1 − ∑_{(x,y) ∈ channelTypicalPairs} channelPairSeqProb`, tends to `0` as `n → ∞`. The joint AEP +(`exists_le_sum_channelTypicalPairs`) makes the typical mass exceed `1 − δ` eventually, and it never +exceeds the total mass `1` (`sum_channelPairSeqProb`), so its complement lies in `[0, δ]` +eventually. -/ +theorem tendsto_one_sub_sum_channelTypicalPairs {q : ι → κ → ℝ} (hN : IsChannel q) + {p : ι → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun n : ℕ => 1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + atTop (𝓝 0) := by + rw [Metric.tendsto_atTop] + intro η hη + obtain ⟨N, _, hNle⟩ := exists_le_sum_channelTypicalPairs hN hp0 hp1 hε (half_pos hη) + refine ⟨N, fun n hn => ?_⟩ + have hmass_le : ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy ≤ 1 := + (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + fun xy _ _ => channelPairSeqProb_nonneg hN hp0 xy).trans_eq (sum_channelPairSeqProb hN hp1) + have hge := hNle n hn + have hnn : (0 : ℝ) ≤ 1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy := by + linarith + rw [Real.dist_eq, sub_zero, abs_of_nonneg hnn] + linarith + +/-! ### The random-coding limit -/ + +/-- **The random-coding limit** (achievability half of Nielsen & Chuang, Theorem 12.7). For a +channel `q`, an input distribution `p`, and a rate `R` (in bits) with +`R · log 2 < channelMutualInfo q p = H(X : Y)`, there is a tolerance `ε > 0` such that — for the +message count `M(n) = ⌈exp(n · R · log 2)⌉₊ = ⌈2^{nR}⌉` of `IsAchievableRate` and *any* fallback +message family `m₀` — the expectation over the i.i.d. random codebook of the average decoding error +of the joint-typicality code tends to `0` as `n → ∞`: + +`∑_C channelCodebookProb p C · (M(n)⁻¹ ∑ₘ condErrorProb (channelJointTypicalCode … (m₀ n) C) m) +→ 0`. + +Choosing `ε = (channelMutualInfo q p − R · log 2) / 6` makes `channelMutualInfo q p − 3ε` strictly +exceed `R · log 2`, so the per-`n` bound `channelRandomCode_expectedAvgError_le` is squeezed between +`0` and `(1 − typical mass) + (M(n) − 1) · exp(-n (H(X:Y) − 3ε))`, whose true-atypical term vanishes +by the joint AEP (`tendsto_one_sub_sum_channelTypicalPairs`) and whose packing term vanishes by +`tendsto_channelPackingTerm`. Since the expected error is `0` for a rate below the mutual +information, a good deterministic code exists — the substance of the achievability argument. -/ +theorem tendsto_expectedError_channelRandomCode {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {R : ℝ} + (hR : R * Real.log 2 < channelMutualInfo q p) : + ∃ ε > 0, ∀ m₀ : ∀ n : ℕ, Fin ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊, + Tendsto (fun n : ℕ => + ∑ C : Fin ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ → (Fin n → ι), + channelCodebookProb p C * + ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ)⁻¹ * + ∑ m, (channelJointTypicalCode q p n ε (m₀ n) C).condErrorProb q m)) + atTop (𝓝 0) := by + have hIpos : 0 < channelMutualInfo q p - R * Real.log 2 := sub_pos.mpr hR + set ε := (channelMutualInfo q p - R * Real.log 2) / 6 with hεdef + have hεpos : 0 < ε := div_pos hIpos (by norm_num) + have hlt : R * Real.log 2 < channelMutualInfo q p - 3 * ε := by rw [hεdef]; linarith + refine ⟨ε, hεpos, fun m₀ => ?_⟩ + refine tendsto_of_tendsto_of_tendsto_of_le_of_le (g := fun _ => (0 : ℝ)) + (h := fun n : ℕ => + (1 - ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy) + + ((⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) - 1) * + Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε))) + tendsto_const_nhds ?_ ?_ ?_ + · -- the squeezing bound tends to `0` + simpa only [add_zero] using + (tendsto_one_sub_sum_channelTypicalPairs hN hp0 hp1 hεpos).add + (tendsto_channelPackingTerm hlt) + · -- the expected error is nonnegative + intro n + refine Finset.sum_nonneg fun C _ => mul_nonneg (channelCodebookProb_nonneg hp0 C) ?_ + refine mul_nonneg (by positivity) (Finset.sum_nonneg fun m _ => ?_) + exact (channelJointTypicalCode q p n ε (m₀ n) C).condErrorProb_nonneg hN m + · -- the expected error is bounded by the squeezing bound (the per-`n` random-coding estimate) + exact fun n => channelRandomCode_expectedAvgError_le hN hp0 hp1 (m₀ n) + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelTypicalSequence.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelTypicalSequence.lean new file mode 100644 index 0000000000..40c31dd16e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ChannelTypicalSequence.lean @@ -0,0 +1,409 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.NoisyChannel +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence + +/-! +# Jointly typical sequences for a discrete memoryless channel + +The achievability half of Shannon's noisy channel coding theorem (Nielsen & Chuang, Theorem 12.7) +is proved by *jointly typical* random coding (Cover–Thomas, ch. 7.7): a random codebook is decoded +by testing whether the received output string is jointly typical with a codeword. This file builds +the probabilistic foundation — the joint input–output sequence law and the jointly typical set — +reusing the classical typical-sequence machinery of `ToMathlib.InformationTheory.TypicalSequence`. + +Fix a discrete memoryless channel `q : ι → κ → ℝ` (`Real.IsChannel`) and an input distribution +`p : ι → ℝ`. When the input string `Xⁿ` is drawn i.i.d. from `p` and passed through `n` uses of the +channel to produce `Yⁿ`, the pair `(Xⁿ, Yⁿ)` has the **joint input–output sequence law** + +`Real.channelPairSeqProb q p (x, y) = (∏ⱼ p(xⱼ)) · ∏ⱼ q(yⱼ | xⱼ)`. + +Because `p(xⱼ) · q(yⱼ | xⱼ) = channelJoint q p (xⱼ, yⱼ)`, this is exactly the `n`-fold i.i.d. +product of the single-use joint law `channelJoint q p` on `ι × κ` +(`Real.channelPairSeqProb_eq_prod_channelJoint`). Its first marginal is the i.i.d. input law `pⁿ` +(`Real.sum_snd_channelPairSeqProb`) and its second marginal is the i.i.d. output law +`(channelOutput q p)ⁿ` (`Real.sum_fst_channelPairSeqProb`). + +A pair `(x, y)` is **jointly typical** (`Real.channelTypicalPairs`) when the pair-sequence is +typical for the joint law `channelJoint q p`, *and* `x` is typical for `p`, *and* `y` is typical for +the output law `channelOutput q p` — the three-way conjunction that the packing bound of the coding +theorem needs. + +The **joint AEP** (`Real.exists_le_sum_channelTypicalPairs`) says the jointly typical set carries +probability `→ 1` under the true joint law; the **packing bound** +(`Real.sum_indep_channelTypicalPairs_le`) says it carries probability `≤ exp(-n(H(X:Y)-3ε))` under +the *independent* pair law `Real.channelIndepPairProb`, where the codeword is drawn independently of +the output. Together these are the two probabilistic inputs to the random-coding error analysis. + +## Main declarations + +* `Real.channelPairSeqProb` — the joint input–output sequence law of `(Xⁿ, Yⁿ)`. +* `Real.channelPairSeqProb_eq_prod_channelJoint` — it is the i.i.d. product of `channelJoint q p`. +* `Real.sum_channelPairSeqProb` — it is a probability distribution (total mass `1`). +* `Real.sum_snd_channelPairSeqProb`, `Real.sum_fst_channelPairSeqProb` — its input marginal `pⁿ` and + output marginal `(channelOutput q p)ⁿ`. +* `Real.channelTypicalPairs` — the jointly typical set. +* `Real.exists_le_sum_channelTypicalPairs` — the joint AEP: the jointly typical set has probability + `≥ 1 - δ` for large `n` under the true joint law. +* `Real.channelIndepPairProb` — the independent input–output pair law (a product of the marginals). +* `Real.sum_indep_channelTypicalPairs_le` — the packing bound: the jointly typical set has + probability `≤ exp(-n(H(X:Y)-3ε))` under the independent pair law. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-! ### The joint input–output sequence law -/ + +/-- The **joint input–output sequence law** of `(Xⁿ, Yⁿ)` for a channel `q` fed an i.i.d. input +distribution `p`: the probability `(∏ⱼ p(xⱼ)) · ∏ⱼ q(yⱼ | xⱼ)` that the input string `x : Fin n → ι` +is drawn i.i.d. from `p` and the memoryless `n`-use channel produces the output string +`y : Fin n → κ`. -/ +noncomputable def channelPairSeqProb (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} + (xy : (Fin n → ι) × (Fin n → κ)) : ℝ := + (∏ j, p (xy.1 j)) * channelSeqProb q xy.1 xy.2 + +omit [Fintype ι] [Fintype κ] in +/-- The joint input–output sequence law evaluated at an explicit pair `(x, y)`. -/ +@[simp] theorem channelPairSeqProb_mk (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} + (x : Fin n → ι) (y : Fin n → κ) : + channelPairSeqProb q p (x, y) = (∏ j, p (x j)) * channelSeqProb q x y := rfl + +omit [Fintype ι] [Fintype κ] in +/-- The joint input–output sequence law is the `n`-fold i.i.d. product of the single-use joint law +`channelJoint q p` on `ι × κ`: `(∏ⱼ p(xⱼ)) · ∏ⱼ q(yⱼ | xⱼ) = ∏ⱼ channelJoint q p (xⱼ, yⱼ)`. -/ +theorem channelPairSeqProb_eq_prod_channelJoint (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} + (xy : (Fin n → ι) × (Fin n → κ)) : + channelPairSeqProb q p xy = ∏ j, channelJoint q p (xy.1 j, xy.2 j) := by + rw [channelPairSeqProb, channelSeqProb, ← Finset.prod_mul_distrib] + simp only [channelJoint_apply] + +omit [Fintype ι] in +/-- The joint input–output sequence law is nonnegative for a channel fed a nonnegative input +distribution. -/ +theorem channelPairSeqProb_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) {n : ℕ} (xy : (Fin n → ι) × (Fin n → κ)) : + 0 ≤ channelPairSeqProb q p xy := + mul_nonneg (Finset.prod_nonneg fun _ _ => hp0 _) + (Finset.prod_nonneg fun _ _ => hN.nonneg _ _) + +omit [Fintype ι] in +/-- **The input marginal is the i.i.d. input law `pⁿ`.** Summing the joint sequence law over all +output strings leaves `∏ⱼ p(xⱼ)`: for a fixed input `x`, `∑_y ∏ⱼ q(yⱼ | xⱼ) = 1` +(`sum_channelSeqProb`). -/ +theorem sum_snd_channelPairSeqProb {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} {n : ℕ} + (x : Fin n → ι) : + ∑ y : Fin n → κ, channelPairSeqProb q p (x, y) = ∏ j, p (x j) := by + simp_rw [channelPairSeqProb_mk, ← Finset.mul_sum, sum_channelSeqProb hN, mul_one] + +omit [Fintype κ] in +/-- **The output marginal is the i.i.d. output law `(channelOutput q p)ⁿ`.** Summing the joint +sequence law over all input strings leaves `∏ⱼ (∑ₐ p(a) q(yⱼ | a)) = ∏ⱼ channelOutput q p (yⱼ)`, by +the product-marginalization `∑_x ∏ⱼ f j (xⱼ) = ∏ⱼ ∑ₐ f j a` (`Finset.prod_univ_sum`). -/ +theorem sum_fst_channelPairSeqProb {q : ι → κ → ℝ} (p : ι → ℝ) {n : ℕ} + (y : Fin n → κ) : + ∑ x : Fin n → ι, channelPairSeqProb q p (x, y) = ∏ j, channelOutput q p (y j) := by + have key : ∑ x : Fin n → ι, ∏ j, channelJoint q p (x j, y j) + = ∏ j, ∑ a, channelJoint q p (a, y j) := by + rw [← Fintype.piFinset_univ] + exact (Finset.prod_univ_sum (fun _ => (univ : Finset ι)) + (fun j a => channelJoint q p (a, y j))).symm + simp_rw [channelPairSeqProb_eq_prod_channelJoint] + rw [key] + refine Finset.prod_congr rfl fun j _ => ?_ + simp only [channelJoint_apply, channelOutput_apply] + +/-- The joint input–output sequence law is a probability distribution: its total mass is `1`. -/ +theorem sum_channelPairSeqProb {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp1 : ∑ x, p x = 1) {n : ℕ} : + ∑ xy : (Fin n → ι) × (Fin n → κ), channelPairSeqProb q p xy = 1 := by + rw [Fintype.sum_prod_type] + simp_rw [sum_snd_channelPairSeqProb hN] + rw [iid_total_mass, hp1, one_pow] + +/-! ### The jointly typical set -/ + +open Classical in +/-- The **jointly typical set** of pairs `(x, y)` for a channel `q` fed input `p`, at block length +`n` and tolerance `ε`: those `(x, y)` for which the pair-sequence `j ↦ (xⱼ, yⱼ)` is `ε`-typical for +the joint law `channelJoint q p`, `x` is `ε`-typical for `p`, and `y` is `ε`-typical for the output +law `channelOutput q p`. The three-way conjunction (joint typicality together with both marginal +typicalities) is what the packing bound of the coding theorem requires. -/ +noncomputable def channelTypicalPairs (q : ι → κ → ℝ) (p : ι → ℝ) (n : ℕ) (ε : ℝ) : + Finset ((Fin n → ι) × (Fin n → κ)) := + univ.filter fun xy => + (fun j => (xy.1 j, xy.2 j)) ∈ typicalSeq (channelJoint q p) n ε ∧ + xy.1 ∈ typicalSeq p n ε ∧ xy.2 ∈ typicalSeq (channelOutput q p) n ε + +/-- Membership in the jointly typical set: `(x, y)` is jointly typical iff the paired sequence is +typical for the joint law and both `x` and `y` are typical for their respective marginals. -/ +theorem mem_channelTypicalPairs {q : ι → κ → ℝ} {p : ι → ℝ} {n : ℕ} {ε : ℝ} + {xy : (Fin n → ι) × (Fin n → κ)} : + xy ∈ channelTypicalPairs q p n ε ↔ + (fun j => (xy.1 j, xy.2 j)) ∈ typicalSeq (channelJoint q p) n ε ∧ + xy.1 ∈ typicalSeq p n ε ∧ xy.2 ∈ typicalSeq (channelOutput q p) n ε := by + classical + simp only [channelTypicalPairs, mem_filter, mem_univ, true_and] + +/-! ### The joint asymptotic equipartition property -/ + +open Classical in +/-- Marginalizing the pair mass over pairs whose **input** string is typical for `p` reduces to the +i.i.d.-input typical mass `∑_{x ∈ T(p)} ∏ⱼ p(xⱼ)` (the condition depends only on `x`, so summing out +`y` via the input marginal `sum_snd_channelPairSeqProb` leaves the single-source typical mass). -/ +private theorem sum_filter_fst_channelPairSeqProb {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + {n : ℕ} (ε : ℝ) : + ∑ xy ∈ univ.filter (fun xy : (Fin n → ι) × (Fin n → κ) => xy.1 ∈ typicalSeq p n ε), + channelPairSeqProb q p xy + = ∑ x ∈ typicalSeq p n ε, ∏ j, p (x j) := by + classical + have hset : univ.filter (fun xy : (Fin n → ι) × (Fin n → κ) => xy.1 ∈ typicalSeq p n ε) + = (typicalSeq p n ε) ×ˢ univ := by + ext ⟨x, y⟩; simp + rw [hset, Finset.sum_product] + exact Finset.sum_congr rfl fun x _ => sum_snd_channelPairSeqProb hN x + +open Classical in +/-- Marginalizing the pair mass over pairs whose **output** string is typical for the output law +reduces to the i.i.d.-output typical mass `∑_{y ∈ T(channelOutput q p)} ∏ⱼ channelOutput q p (yⱼ)` +(the condition depends only on `y`, so summing out `x` via the output marginal +`sum_fst_channelPairSeqProb` leaves the single-source typical mass). -/ +private theorem sum_filter_snd_channelPairSeqProb (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} (ε : ℝ) : + ∑ xy ∈ univ.filter + (fun xy : (Fin n → ι) × (Fin n → κ) => xy.2 ∈ typicalSeq (channelOutput q p) n ε), + channelPairSeqProb q p xy + = ∑ y ∈ typicalSeq (channelOutput q p) n ε, ∏ j, channelOutput q p (y j) := by + classical + have hset : univ.filter + (fun xy : (Fin n → ι) × (Fin n → κ) => xy.2 ∈ typicalSeq (channelOutput q p) n ε) + = univ ×ˢ (typicalSeq (channelOutput q p) n ε) := by + ext ⟨x, y⟩; simp + rw [hset, Finset.sum_product, Finset.sum_comm] + exact Finset.sum_congr rfl fun y _ => sum_fst_channelPairSeqProb p y + +open Classical in +/-- Marginalizing the pair mass over pairs whose paired sequence `j ↦ (xⱼ, yⱼ)` is typical for the +joint law reduces to the i.i.d.-joint typical mass for `channelJoint q p`. The pair type is +reindexed to `Fin n → ι × κ` by `Equiv.arrowProdEquivProdArrow`, under which the pair mass is the +i.i.d. product of the joint law (`channelPairSeqProb_eq_prod_channelJoint`). -/ +private theorem sum_filter_pair_channelPairSeqProb (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} (ε : ℝ) : + ∑ xy ∈ univ.filter (fun xy : (Fin n → ι) × (Fin n → κ) => + (fun j => (xy.1 j, xy.2 j)) ∈ typicalSeq (channelJoint q p) n ε), + channelPairSeqProb q p xy + = ∑ σ ∈ typicalSeq (channelJoint q p) n ε, ∏ j, channelJoint q p (σ j) := by + classical + rw [Finset.sum_filter, + ← Equiv.sum_comp (Equiv.arrowProdEquivProdArrow (Fin n) (fun _ => ι) (fun _ => κ))] + conv_rhs => rw [← Finset.filter_univ_mem (typicalSeq (channelJoint q p) n ε), Finset.sum_filter] + refine Finset.sum_congr rfl fun σ _ => ?_ + have hpair : (fun j => ((Equiv.arrowProdEquivProdArrow (Fin n) (fun _ => ι) (fun _ => κ) σ).1 j, + (Equiv.arrowProdEquivProdArrow (Fin n) (fun _ => ι) (fun _ => κ) σ).2 j)) = σ := by + funext j; simp + rw [hpair] + split_ifs with h + · rw [channelPairSeqProb_eq_prod_channelJoint] + exact Finset.prod_congr rfl fun j _ => by simp + · rfl + +/-- A three-set union bound for a nonnegative summand: `∑_{A ∪ B ∪ C} f ≤ ∑_A f + ∑_B f + ∑_C f`. -/ +private theorem sum_triple_union_le {α : Type*} [DecidableEq α] {f : α → ℝ} (hf : ∀ a, 0 ≤ f a) + (A B C : Finset α) : + ∑ a ∈ A ∪ B ∪ C, f a ≤ ∑ a ∈ A, f a + ∑ a ∈ B, f a + ∑ a ∈ C, f a := by + have hAB : (∑ a ∈ A ∪ B, f a) + (∑ a ∈ A ∩ B, f a) + = (∑ a ∈ A, f a) + (∑ a ∈ B, f a) := Finset.sum_union_inter + have hAB2 : 0 ≤ ∑ a ∈ A ∩ B, f a := Finset.sum_nonneg fun a _ => hf a + have hABC : (∑ a ∈ A ∪ B ∪ C, f a) + (∑ a ∈ (A ∪ B) ∩ C, f a) + = (∑ a ∈ A ∪ B, f a) + (∑ a ∈ C, f a) := Finset.sum_union_inter + have hABC2 : 0 ≤ ∑ a ∈ (A ∪ B) ∩ C, f a := Finset.sum_nonneg fun a _ => hf a + linarith + +/-- For a total-mass-`t` summand `f`, the complement of a set `P` whose mass is at least `t - c` +has mass at most `c`. -/ +private theorem sum_filter_not_le_of_le {α : Type*} [Fintype α] {f : α → ℝ} {P : α → Prop} + [DecidablePred P] {t c : ℝ} (htot : ∑ a, f a = t) + (hle : t - c ≤ ∑ a ∈ univ.filter P, f a) : + ∑ a ∈ univ.filter (fun a => ¬ P a), f a ≤ c := by + have := Finset.sum_filter_add_sum_filter_not univ P f + linarith + +/-- **The joint asymptotic equipartition property (Nielsen & Chuang, joint AEP; Cover–Thomas, Thm. +7.6.1).** For a channel `q` fed an input distribution `p`, and any tolerance `ε > 0` and margin +`δ > 0`, for all sufficiently large block lengths `n` the jointly typical set carries probability at +least `1 − δ` under the joint input–output law: +`1 − δ ≤ ∑_{(x, y) ∈ channelTypicalPairs q p n ε} channelPairSeqProb q p (x, y)`. + +The proof is a union bound over the three typicality events: the pair `(x, y)` fails to be jointly +typical only if its paired sequence, its input `x`, or its output `y` is atypical, and each of those +three atypical events has probability at most `δ / 3` for large `n` by the classical theorem of +typical sequences (`exists_le_sum_typicalSeq`) applied to `channelJoint q p`, `p` and +`channelOutput q p` respectively — using that the input, output and paired marginals of the joint +law are the corresponding i.i.d. products. -/ +theorem exists_le_sum_channelTypicalPairs {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {ε : ℝ} (hε : 0 < ε) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, + 1 - δ ≤ ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy := by + classical + obtain ⟨N1, hN1pos, hN1⟩ := exists_le_sum_typicalSeq hp0 hp1 hε (by linarith : (0:ℝ) < δ / 3) + obtain ⟨N2, hN2pos, hN2⟩ := exists_le_sum_typicalSeq (channelOutput_nonneg hN hp0) + (sum_channelOutput hN hp1) hε (by linarith : (0:ℝ) < δ / 3) + obtain ⟨N3, hN3pos, hN3⟩ := exists_le_sum_typicalSeq (channelJoint_nonneg hN hp0) + (sum_channelJoint hN hp1) hε (by linarith : (0:ℝ) < δ / 3) + refine ⟨max N1 (max N2 N3), lt_of_lt_of_le hN1pos (le_max_left _ _), fun n hn => ?_⟩ + have hn1 : N1 ≤ n := (le_max_left _ _).trans hn + have hn2 : N2 ≤ n := ((le_max_left _ _).trans (le_max_right _ _)).trans hn + have hn3 : N3 ≤ n := ((le_max_right _ _).trans (le_max_right _ _)).trans hn + have hf0 : ∀ xy : (Fin n → ι) × (Fin n → κ), 0 ≤ channelPairSeqProb q p xy := + fun xy => channelPairSeqProb_nonneg hN hp0 xy + have hT : ∑ xy : (Fin n → ι) × (Fin n → κ), channelPairSeqProb q p xy = 1 := + sum_channelPairSeqProb hN hp1 + -- Abbreviations for the three typicality predicates and their filtered "bad" sets. + set PC := fun xy : (Fin n → ι) × (Fin n → κ) => + (fun j => (xy.1 j, xy.2 j)) ∈ typicalSeq (channelJoint q p) n ε with hPC + set PA := fun xy : (Fin n → ι) × (Fin n → κ) => xy.1 ∈ typicalSeq p n ε with hPA + set PB := fun xy : (Fin n → ι) × (Fin n → κ) => + xy.2 ∈ typicalSeq (channelOutput q p) n ε with hPB + -- Each atypical event has probability at most δ/3. + have hbadA : ∑ xy ∈ univ.filter (fun xy => ¬ PA xy), channelPairSeqProb q p xy ≤ δ / 3 := + sum_filter_not_le_of_le hT (by rw [sum_filter_fst_channelPairSeqProb hN]; exact hN1 n hn1) + have hbadB : ∑ xy ∈ univ.filter (fun xy => ¬ PB xy), channelPairSeqProb q p xy ≤ δ / 3 := + sum_filter_not_le_of_le hT (by rw [sum_filter_snd_channelPairSeqProb]; exact hN2 n hn2) + have hbadC : ∑ xy ∈ univ.filter (fun xy => ¬ PC xy), channelPairSeqProb q p xy ≤ δ / 3 := + sum_filter_not_le_of_le hT (by rw [sum_filter_pair_channelPairSeqProb]; exact hN3 n hn3) + -- The complement of the jointly typical set is contained in the union of the three bad sets. + have hsub : univ \ channelTypicalPairs q p n ε ⊆ + (univ.filter (fun xy => ¬ PA xy)) ∪ (univ.filter (fun xy => ¬ PB xy)) + ∪ (univ.filter (fun xy => ¬ PC xy)) := by + intro xy hxy + rw [Finset.mem_sdiff, mem_channelTypicalPairs] at hxy + simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] + tauto + -- Assemble: the jointly typical mass is 1 minus the complement mass, which is at most δ. + have hcompl : ∑ xy ∈ univ \ channelTypicalPairs q p n ε, channelPairSeqProb q p xy ≤ δ := by + calc ∑ xy ∈ univ \ channelTypicalPairs q p n ε, channelPairSeqProb q p xy + ≤ ∑ xy ∈ (univ.filter (fun xy => ¬ PA xy)) ∪ (univ.filter (fun xy => ¬ PB xy)) + ∪ (univ.filter (fun xy => ¬ PC xy)), channelPairSeqProb q p xy := + Finset.sum_le_sum_of_subset_of_nonneg hsub fun xy _ _ => hf0 xy + _ ≤ (∑ xy ∈ univ.filter (fun xy => ¬ PA xy), channelPairSeqProb q p xy) + + (∑ xy ∈ univ.filter (fun xy => ¬ PB xy), channelPairSeqProb q p xy) + + (∑ xy ∈ univ.filter (fun xy => ¬ PC xy), channelPairSeqProb q p xy) := + sum_triple_union_le hf0 _ _ _ + _ ≤ δ := by linarith + have hpart : ∑ xy ∈ univ \ channelTypicalPairs q p n ε, channelPairSeqProb q p xy + + ∑ xy ∈ channelTypicalPairs q p n ε, channelPairSeqProb q p xy = 1 := by + rw [Finset.sum_sdiff (Finset.subset_univ _)]; exact hT + linarith + +/-! ### The packing / independence bound -/ + +/-- The **independent input–output pair law**: the probability +`(∏ⱼ p(xⱼ)) · ∏ⱼ channelOutput q p (yⱼ)` that an *independent* codeword `X_tildeⁿ`, drawn i.i.d. +from `p` +and statistically independent of the received output string `Yⁿ` (itself distributed as the i.i.d. +output law `(channelOutput q p)ⁿ`), equals `x` while the output equals `y`. It is the product of the +two marginals, in contrast with the true joint law `channelPairSeqProb q p` under which `X_tildeⁿ` +is the +input that produced `Yⁿ`; it is the measure under which the packing bound estimates the chance that +a wrong codeword looks jointly typical with the true output. -/ +noncomputable def channelIndepPairProb (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} + (xy : (Fin n → ι) × (Fin n → κ)) : ℝ := + (∏ j, p (xy.1 j)) * ∏ j, channelOutput q p (xy.2 j) + +omit [Fintype κ] in +/-- The independent pair law evaluated at an explicit pair `(x, y)`. -/ +@[simp] theorem channelIndepPairProb_mk (q : ι → κ → ℝ) (p : ι → ℝ) {n : ℕ} + (x : Fin n → ι) (y : Fin n → κ) : + channelIndepPairProb q p (x, y) = (∏ j, p (x j)) * ∏ j, channelOutput q p (y j) := rfl + +open Classical in +/-- **The packing / independence bound** (Nielsen & Chuang, achievability of Theorem 12.7; +Cover–Thomas, Thm. 7.6.1). Under the *independent* pair law `channelIndepPairProb q p` — a codeword +`X_tildeⁿ` drawn i.i.d. from `p`, independent of the output `Yⁿ ∼ (channelOutput q p)ⁿ` — the +probability +that the pair is jointly typical is at most `exp (-n (H(X : Y) - 3ε))`: + +`∑_{(x, y) ∈ channelTypicalPairs q p n ε} channelIndepPairProb q p (x, y) + ≤ exp (-n (channelMutualInfo q p - 3ε))`. + +This is the key estimate of the random-coding argument: a codeword statistically independent of the +received output is jointly typical with it only with exponentially small probability, so the +`exp (n R)` competing (wrong) codewords contribute a vanishing total decoding error whenever the +rate `R` is below the mutual information `H(X : Y)`. + +The proof combines two per-element typicality bounds available on the jointly typical set — the +input factor `∏ⱼ p(xⱼ) ≤ exp (-n (H(X) - ε))` and the output factor +`∏ⱼ channelOutput q p (yⱼ) ≤ exp (-n (H(Y) - ε))` (the `mem_typicalSeq` upper bounds for `x`, `y`) +— with a count of the jointly typical pairs: the pair sequence `j ↦ (xⱼ, yⱼ)` is typical for the +joint law, so through the injection `(x, y) ↦ (j ↦ (xⱼ, yⱼ))` there are at most +`|T(channelJoint q p)| ≤ exp (n (H(X, Y) + ε))` of them (`card_typicalSeq_le`). Multiplying, the +exponent is `(H(X, Y) + ε) - (H(X) - ε) - (H(Y) - ε) = -((H(X) + H(Y) - H(X, Y)) - 3ε)`, which is +`-(H(X : Y) - 3ε)` by the three-entropy decomposition +`channelMutualInfo_eq_entropy_add_entropy_sub_entropy`. -/ +theorem sum_indep_channelTypicalPairs_le {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) {n : ℕ} {ε : ℝ} : + ∑ xy ∈ channelTypicalPairs q p n ε, channelIndepPairProb q p xy + ≤ Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + classical + -- The constant per-pair upper bound `c₀ = exp(-n(H(X)-ε)) · exp(-n(H(Y)-ε))`. + set c₀ := Real.exp (-(n : ℝ) * (entropy p - ε)) + * Real.exp (-(n : ℝ) * (entropy (channelOutput q p) - ε)) with hc₀ + have hc₀0 : 0 ≤ c₀ := mul_nonneg (Real.exp_pos _).le (Real.exp_pos _).le + -- (1) On the jointly typical set every summand is at most `c₀`, by the two marginal typicality + -- upper bounds on `x` and `y`. + have hsummand : ∀ xy ∈ channelTypicalPairs q p n ε, channelIndepPairProb q p xy ≤ c₀ := by + intro xy hxy + have hmem := mem_channelTypicalPairs.mp hxy + have hx : ∏ j, p (xy.1 j) ≤ Real.exp (-(n : ℝ) * (entropy p - ε)) := + (mem_typicalSeq.mp hmem.2.1).2 + have hy : ∏ j, channelOutput q p (xy.2 j) + ≤ Real.exp (-(n : ℝ) * (entropy (channelOutput q p) - ε)) := + (mem_typicalSeq.mp hmem.2.2).2 + have hynn : 0 ≤ ∏ j, channelOutput q p (xy.2 j) := + Finset.prod_nonneg fun j _ => channelOutput_nonneg hN hp0 _ + exact mul_le_mul hx hy hynn (Real.exp_pos _).le + -- (2) The number of jointly typical pairs is at most `exp(n(H(X,Y)+ε))`: the pair map into the + -- joint typical set is injective. + have hAcard : ((channelTypicalPairs q p n ε).card : ℝ) + ≤ Real.exp ((n : ℝ) * (entropy (channelJoint q p) + ε)) := by + have hinj : (channelTypicalPairs q p n ε).card + ≤ (typicalSeq (channelJoint q p) n ε).card := by + -- the pair map `(x, y) ↦ (j ↦ (xⱼ, yⱼ))` is the inverse of `arrowProdEquivProdArrow`. + apply Finset.card_le_card_of_injOn (fun xy => fun j => (xy.1 j, xy.2 j)) + · intro xy hxy + exact (mem_channelTypicalPairs.mp hxy).1 + · exact (Equiv.arrowProdEquivProdArrow (Fin n) (fun _ => ι) (fun _ => κ)).symm.injective.injOn + calc ((channelTypicalPairs q p n ε).card : ℝ) + ≤ ((typicalSeq (channelJoint q p) n ε).card : ℝ) := by exact_mod_cast hinj + _ ≤ Real.exp ((n : ℝ) * (entropy (channelJoint q p) + ε)) := + card_typicalSeq_le (channelJoint_nonneg hN hp0) (sum_channelJoint hN hp1) + -- (3) The three-entropy decomposition identifies the exponent with the mutual information. + have hI : channelMutualInfo q p + = entropy p + entropy (channelOutput q p) - entropy (channelJoint q p) := + channelMutualInfo_eq_entropy_add_entropy_sub_entropy hN p + have hexp : Real.exp ((n : ℝ) * (entropy (channelJoint q p) + ε)) * c₀ + = Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := by + rw [hc₀, ← mul_assoc, ← Real.exp_add, ← Real.exp_add] + congr 1 + rw [hI]; ring + -- Assemble: bound each summand by `c₀`, count the pairs, and combine the exponentials. + calc ∑ xy ∈ channelTypicalPairs q p n ε, channelIndepPairProb q p xy + ≤ ∑ _xy ∈ channelTypicalPairs q p n ε, c₀ := Finset.sum_le_sum hsummand + _ = ((channelTypicalPairs q p n ε).card : ℝ) * c₀ := by + rw [Finset.sum_const, nsmul_eq_mul] + _ ≤ Real.exp ((n : ℝ) * (entropy (channelJoint q p) + ε)) * c₀ := + mul_le_mul_of_nonneg_right hAcard hc₀0 + _ = Real.exp (-(n : ℝ) * (channelMutualInfo q p - 3 * ε)) := hexp + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropy.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropy.lean new file mode 100644 index 0000000000..abd430142c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropy.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy +public import Mathlib.Analysis.SpecialFunctions.Log.Base +public import Mathlib.Algebra.Order.Chebyshev +public import Mathlib.Algebra.BigOperators.Field + +/-! +# Collision probability and collision entropy + +For a finite type `ι` and a function `p : ι → ℝ` (interpreted as a probability mass function when +`p i ∈ [0, 1]` and `∑ i, p i = 1`), the **collision probability** and **collision entropy** +(Rényi entropy of order 2) are + +`Real.collisionProb p := ∑ i, (p i) ^ 2`, +`Real.collisionEntropy p := -Real.logb 2 (collisionProb p)`. + +The collision probability is `Pr[X = X'] = ∑ₓ p(x)²`, the probability that two independent draws +from `p` collide; the collision entropy `Hc(p) = -log₂ (∑ₓ p(x)²)` measures its randomness in bits. +Base `2` (bits) is used — as in Nielsen & Chuang §12.6 — since the applications compare `Hc` to the +number of output bits `m = log₂ |B|` of a hash function. + +The function is defined on raw `ι → ℝ` input, mirroring the `Real.entropy` convention of accepting +any real input and providing distribution-hypothesis-driven API lemmas separately. + +## Main definitions + +- `Real.collisionProb : (ι → ℝ) → ℝ` +- `Real.collisionEntropy : (ι → ℝ) → ℝ` + +## Main results + +- `Real.collisionProb_nonneg`: `0 ≤ collisionProb p` (a sum of squares), unconditionally. +- `Real.collisionProb_le_one`: `collisionProb p ≤ 1` for a probability distribution. +- `Real.collisionProb_pos`: `0 < collisionProb p` for a probability distribution (some atom is + nonzero, and its square lower-bounds the sum). +- `Real.inv_card_le_collisionProb`: `(card ι)⁻¹ ≤ collisionProb p` — the uniform distribution + minimizes the collision probability (Cauchy–Schwarz, `sq_sum_le_card_mul_sum_sq`). +- `Real.collisionProb_uniform`: the uniform distribution has collision probability `(card ι)⁻¹`. +- `Real.collisionEntropy_uniform`: the uniform distribution attains collision entropy + `log₂ (card ι)`. +- `Real.collisionEntropy_nonneg`: `0 ≤ collisionEntropy p` for a probability distribution. +- `Real.collisionEntropy_le_logb_card`: `collisionEntropy p ≤ log₂ (card ι)`, with equality for the + uniform distribution (`collisionEntropy_uniform`); the collision-entropy analogue of + `Real.entropy_le_log_card`. It is the `Hc(X) ≤ log₂ |X|` half of the pair with + `Real.entropy_le_log_card` (`H(X) ≤ log |X|`). +- `Real.log_collisionProb_inv_le_entropy`: `log (collisionProb p)⁻¹ ≤ entropy p`, i.e. Shannon + entropy dominates collision entropy `Hc(X) ≤ H(X)` (in nats). This is the `H ≥ Hc` first + inequality of Nielsen & Chuang Theorem 12.16, in its unconditional per-outcome form. +- `Real.collisionEntropy_le_entropy_div_log_two`: the base-`2` restatement + `collisionEntropy p ≤ entropy p / log 2` (both sides in bits). + +`H(X) ≥ Hc(X)` is an instance of the monotonicity of Rényi entropy in its order (`H = H₁ ≥ H₂ = +Hc`); it is proved here by Gibbs' inequality against a tilted reference (see +`log_collisionProb_inv_le_entropy`). +-/ + +@[expose] public section + +namespace Real + +variable {ι : Type*} [Fintype ι] + +/-- The **collision probability** of `p : ι → ℝ`: `∑ i, (p i) ^ 2`. For a probability mass function +this is `Pr[X = X'] = ∑ₓ p(x)²`, the probability that two independent draws collide. -/ +noncomputable def collisionProb (p : ι → ℝ) : ℝ := ∑ i, p i ^ 2 + +theorem collisionProb_eq (p : ι → ℝ) : collisionProb p = ∑ i, p i ^ 2 := rfl + +/-- The collision probability is nonnegative (a sum of squares), for any input. -/ +theorem collisionProb_nonneg (p : ι → ℝ) : 0 ≤ collisionProb p := + Finset.sum_nonneg fun _ _ ↦ sq_nonneg _ + +/-- For a probability distribution (`0 ≤ p i`, `∑ p = 1`) the collision probability is at most `1`: +each `p i ≤ 1`, so `∑ p i ² ≤ ∑ p i = 1`. -/ +theorem collisionProb_le_one {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + collisionProb p ≤ 1 := by + have hle1 : ∀ i, p i ≤ 1 := fun i ↦ + (Finset.single_le_sum (fun j _ ↦ h0 j) (Finset.mem_univ i)).trans hsum.le + rw [collisionProb_eq, ← hsum] + refine Finset.sum_le_sum fun i _ ↦ ?_ + rw [sq] + exact mul_le_of_le_one_right (h0 i) (hle1 i) + +/-- The collision probability of a probability distribution is strictly positive: the total mass +`1 ≠ 0` forces some atom `p k ≠ 0`, and `p k ² > 0` lower-bounds the sum of nonnegative squares. -/ +theorem collisionProb_pos {p : ι → ℝ} (hsum : ∑ i, p i = 1) : 0 < collisionProb p := by + obtain ⟨k, -, hk⟩ := + Finset.exists_ne_zero_of_sum_ne_zero (by rw [hsum]; exact one_ne_zero) + rw [collisionProb_eq] + refine lt_of_lt_of_le ?_ (Finset.single_le_sum (fun i _ ↦ sq_nonneg (p i)) (Finset.mem_univ k)) + positivity + +-- A probability distribution's index type is nonempty (its mass is `1 ≠ 0`), so its cardinality +-- is positive. Shared by `inv_card_le_collisionProb` and `collisionEntropy_le_logb_card`. +private theorem card_pos_of_sum_eq_one {p : ι → ℝ} (hsum : ∑ i, p i = 1) : + (0 : ℝ) < Fintype.card ι := by + rcases isEmpty_or_nonempty ι with h | h + · simp only [Finset.univ_eq_empty, Finset.sum_empty] at hsum; norm_num at hsum + · exact_mod_cast Fintype.card_pos + +/-- **The uniform distribution minimizes the collision probability**: `(card ι)⁻¹ ≤ collisionProb p` +for any probability distribution. This is Cauchy–Schwarz (`sq_sum_le_card_mul_sum_sq`): +`1 = (∑ p)² ≤ |ι| · ∑ p²`. It gives the collision-entropy bound `Hc(X) ≤ log₂ |X|` +(`collisionEntropy_le_logb_card`). -/ +theorem inv_card_le_collisionProb {p : ι → ℝ} (hsum : ∑ i, p i = 1) : + (Fintype.card ι : ℝ)⁻¹ ≤ collisionProb p := by + have hcard : (0 : ℝ) < Fintype.card ι := card_pos_of_sum_eq_one hsum + have hcs := sq_sum_le_card_mul_sum_sq (s := (Finset.univ : Finset ι)) (f := p) + rw [Finset.card_univ, hsum, one_pow] at hcs + -- `hcs : 1 ≤ ↑(card ι) * ∑ i, p i ^ 2`; divide by `card ι > 0`. + rw [collisionProb_eq, inv_le_iff_one_le_mul₀ hcard, mul_comm] + exact hcs + +/-- The uniform distribution `i ↦ (card ι)⁻¹` has collision probability `(card ι)⁻¹`. -/ +theorem collisionProb_uniform : + collisionProb (fun _ : ι ↦ (Fintype.card ι : ℝ)⁻¹) = (Fintype.card ι : ℝ)⁻¹ := by + rw [collisionProb_eq, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + rcases eq_or_ne (Fintype.card ι : ℝ) 0 with h | h + · rw [h]; simp + · rw [sq, ← mul_assoc, mul_inv_cancel₀ h, one_mul] + +/-- The **collision entropy** (Rényi entropy of order 2) of `p : ι → ℝ`, in bits: +`Hc(p) = -log₂ (∑ᵢ (p i)²)`. -/ +noncomputable def collisionEntropy (p : ι → ℝ) : ℝ := -Real.logb 2 (collisionProb p) + +theorem collisionEntropy_eq (p : ι → ℝ) : + collisionEntropy p = -Real.logb 2 (collisionProb p) := rfl + +/-- The uniform distribution `i ↦ (card ι)⁻¹` attains collision entropy `log₂ (card ι)`. -/ +theorem collisionEntropy_uniform : + collisionEntropy (fun _ : ι ↦ (Fintype.card ι : ℝ)⁻¹) = Real.logb 2 (Fintype.card ι) := by + rw [collisionEntropy_eq, collisionProb_uniform, Real.logb_inv, neg_neg] + +/-- The collision entropy of a probability distribution is nonnegative: the collision probability +lies in `(0, 1]`, so `log₂ ≤ 0`. -/ +theorem collisionEntropy_nonneg {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + 0 ≤ collisionEntropy p := by + rw [collisionEntropy_eq, neg_nonneg] + exact Real.logb_nonpos (by norm_num) (collisionProb_nonneg p) (collisionProb_le_one h0 hsum) + +/-- **Collision entropy is at most `log₂ (card ι)`** (attained by the uniform distribution, see +`collisionEntropy_uniform`): the collision-entropy analogue of `Real.entropy_le_log_card`. Proof: +`(card ι)⁻¹ ≤ collisionProb p` (`inv_card_le_collisionProb`) and monotonicity of `log₂`. -/ +theorem collisionEntropy_le_logb_card {p : ι → ℝ} (hsum : ∑ i, p i = 1) : + collisionEntropy p ≤ Real.logb 2 (Fintype.card ι) := by + have hcard : (0 : ℝ) < Fintype.card ι := card_pos_of_sum_eq_one hsum + rw [collisionEntropy_eq, neg_le, ← Real.logb_inv] + exact Real.logb_le_logb_of_le (by norm_num) (inv_pos.mpr hcard) (inv_card_le_collisionProb hsum) + +/-- **Shannon entropy dominates collision entropy** (natural-log form): for a probability +distribution `p`, `log (collisionProb p)⁻¹ ≤ entropy p`, i.e. `Hc(X) ≤ H(X)` in nats. This is the +`H ≥ Hc` half of Nielsen & Chuang Theorem 12.16's first inequality (in its unconditional, +per-outcome form); it is the Rényi-order monotonicity `H₁ ≥ H₂`. + +Proof: Gibbs' inequality (`entropy_le_cross_entropy_of_support_subset`) against the *tilted* +reference `q i := (p i)² / collisionProb p`, itself a probability distribution since +`∑ᵢ (p i)² = collisionProb p`. Its cross-entropy `-∑ᵢ p i · log (q i)` evaluates to +`2 · entropy p + log (collisionProb p)`, so Gibbs reads `entropy p ≤ 2 · entropy p + +log (collisionProb p)`, i.e. `-log (collisionProb p) = log (collisionProb p)⁻¹ ≤ entropy p`. -/ +theorem log_collisionProb_inv_le_entropy {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) (hsum : ∑ i, p i = 1) : + Real.log (collisionProb p)⁻¹ ≤ entropy p := by + have hPc_pos : 0 < collisionProb p := collisionProb_pos hsum + have hPc_ne : collisionProb p ≠ 0 := hPc_pos.ne' + -- The tilted reference `q i = (p i)² / collisionProb p` is a probability distribution. + have hq_nn : ∀ i, 0 ≤ p i ^ 2 / collisionProb p := fun i ↦ div_nonneg (sq_nonneg _) hPc_pos.le + have hq_sum : ∑ i, p i ^ 2 / collisionProb p = 1 := by + rw [← Finset.sum_div, ← collisionProb_eq, div_self hPc_ne] + have hsupp : ∀ i, p i ^ 2 / collisionProb p = 0 → p i = 0 := fun i hqi ↦ by + have hp2 : p i ^ 2 = 0 := (div_eq_zero_iff.mp hqi).resolve_right hPc_ne + exact pow_eq_zero_iff (by norm_num) |>.mp hp2 + have hgibbs := entropy_le_cross_entropy_of_support_subset h0 hq_nn hsupp (hsum.trans hq_sum.symm) + -- The cross-entropy against `q` evaluates to `2 · entropy p + log (collisionProb p)`. + have hcross : -∑ i, p i * Real.log (p i ^ 2 / collisionProb p) + = 2 * entropy p + Real.log (collisionProb p) := by + have hterm : ∀ i, p i * Real.log (p i ^ 2 / collisionProb p) + = 2 * (p i * Real.log (p i)) - p i * Real.log (collisionProb p) := fun i ↦ by + rcases eq_or_lt_of_le (h0 i) with h | h + · simp [← h] + · rw [Real.log_div (by positivity) hPc_ne, Real.log_pow] + push_cast; ring + calc -∑ i, p i * Real.log (p i ^ 2 / collisionProb p) + = -∑ i, (2 * (p i * Real.log (p i)) - p i * Real.log (collisionProb p)) := by + rw [Finset.sum_congr rfl (fun i _ ↦ hterm i)] + _ = 2 * (-∑ i, p i * Real.log (p i)) + (∑ i, p i) * Real.log (collisionProb p) := by + rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.sum_mul]; ring + _ = 2 * entropy p + Real.log (collisionProb p) := by + rw [hsum, entropy_eq_neg_sum_mul_log]; ring + rw [hcross] at hgibbs + rw [Real.log_inv] + linarith + +/-- **Shannon entropy dominates collision entropy**, base-`2` (bits) form: +`collisionEntropy p ≤ entropy p / log 2` for a probability distribution `p`. The right side is the +Shannon entropy expressed in bits; this is the base-`2` restatement of +`log_collisionProb_inv_le_entropy`, dividing that natural-log bound by `log 2 > 0`. It is the +`Hc(X) ≤ H(X)` first inequality of Nielsen & Chuang Theorem 12.16 (unconditional form). -/ +theorem collisionEntropy_le_entropy_div_log_two {p : ι → ℝ} (h0 : ∀ i, 0 ≤ p i) + (hsum : ∑ i, p i = 1) : + collisionEntropy p ≤ entropy p / Real.log 2 := by + have hlog2 : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hrw : collisionEntropy p = Real.log (collisionProb p)⁻¹ / Real.log 2 := by + rw [collisionEntropy_eq, ← Real.log_div_log, Real.log_inv, neg_div] + rw [hrw] + gcongr + exact log_collisionProb_inv_le_entropy h0 hsum + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropyLaw.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropyLaw.lean new file mode 100644 index 0000000000..f9187fe510 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/CollisionEntropyLaw.lean @@ -0,0 +1,57 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.CollisionEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.EntropySubadditive + +/-! +# Collision probability of a push-forward law + +This file bridges the collision probability `Real.collisionProb` +(`ToMathlib/InformationTheory/CollisionEntropy.lean`) and the push-forward law `Real.law` +(`ToMathlib/Analysis/SpecialFunctions/ConditionalEntropyChain.lean`). + +## Main results + +* `Real.collisionProb_law_eq_sum_pairs`: the collision probability of the push-forward + `Real.law p f` of a weight `p : α → ℝ` under an arbitrary map `f : α → β` expands over ordered + input pairs as `Pc(law p f) = ∑_x ∑_{x'} [f x' = f x] · p x · p x'`. + +This is the "law of the unconscious statistician" (`Real.sum_law_mul`) applied to the collision +probability: it rewrites `∑_y (∑_{x : f x = y} p x)²`, the probability that two independent +`p`-draws land in the same `f`-fibre, as the sum of `p x · p x'` over the colliding pairs. It is +applied in `ToMathlib/InformationTheory/UniversalHashing.lean` (with `f := h g`) to average the +probability of a hashed output over a random hash function. +-/ + +@[expose] public section + +namespace Real + +variable {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] + +/-- **Ordered-pair expansion of the collision probability of a push-forward law.** For a weight +`p : α → ℝ` and any map `f : α → β`, the collision probability of the push-forward `Real.law p f` +equals the sum over ordered input pairs `(x, x')` of `p x · p x'` restricted to the pairs colliding +under `f`: `Pc(law p f) = ∑_x ∑_{x'} [f x' = f x] · p x · p x'`. Proved by the law-of-the- +unconscious-statistician identity `Real.sum_law_mul` and unfolding `Real.law` on the diagonal +argument `f x`. -/ +theorem collisionProb_law_eq_sum_pairs (f : α → β) (p : α → ℝ) : + collisionProb (law p f) = ∑ x, ∑ x', if f x' = f x then p x * p x' else 0 := by + rw [collisionProb_eq] + simp_rw [pow_two] + rw [sum_law_mul p f (law p f)] + refine Finset.sum_congr rfl fun x _ => ?_ + have hlaw : law p f (f x) = ∑ x', if f x' = f x then p x' else 0 := rfl + rw [hlaw, Finset.mul_sum] + refine Finset.sum_congr rfl fun x' _ => ?_ + rw [mul_ite, mul_zero] + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalCollisionEntropy.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalCollisionEntropy.lean new file mode 100644 index 0000000000..f9bf0af6bb --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalCollisionEntropy.lean @@ -0,0 +1,339 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.CollisionEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy + +/-! +# Conditional collision entropy and the privacy-amplification tail bound + +For a finite joint distribution `p : ι × κ → ℝ` of a pair of random variables `(X, U)` (a +probability mass function when `p ≥ 0` and `∑ p = 1`), this file develops the **conditional +collision entropy** `Hc(X | U = u)` — the collision entropy (Rényi entropy of order 2) of the +conditional distribution of `X` given the *specific* value `U = u` — and proves the tail bound +underlying privacy amplification and information reconciliation. + +Following the `Real.marginalFst`/`Real.marginalSnd` convention of +`ToMathlib.Analysis.SpecialFunctions.JointEntropy`, `X` is the first coordinate `ι` and `U` the +second coordinate `κ`, so `marginalFst p = p_X` and `marginalSnd p = p_U`. + +## Main definitions + +- `Real.condDistribGivenSnd p u`: the conditional distribution `x ↦ p(x, u) / p_U(u)` of `X` + given `U = u`. +- `Real.condCollisionProb p u`: `Pc(X | U = u) = ∑ₓ p(x | u)²`. +- `Real.condCollisionEntropy p u`: `Hc(X | U = u) = -log₂ (∑ₓ p(x | u)²)`. + +## Main results + +- `Real.marginalSnd_sq_mul_condCollisionProb`: the weighting identity + `p_U(u)² · Pc(X | U = u) = ∑ₓ p(x, u)²` (valid even where `p_U(u) = 0`, both sides then `0`). +- `Real.sum_marginalSnd_sq_mul_condCollisionProb_le`: `∑ᵤ p_U(u)² · Pc(X | U = u) ≤ Pc(X)`, i.e. + the joint collision probability is dominated by the marginal collision probability + (`Finset.sum_sq_le_sq_sum_of_nonneg`). +- `Real.condEntropy_eq_sum_marginalSnd_mul_entropy`: the **chain rule** for the Shannon conditional + entropy, `H(X | U) = ∑ᵤ p_U(u) · H(X | U = u)` (with `H(X | U = u)` the Shannon entropy of + `condDistribGivenSnd p u`). +- `Real.log_inv_le_condEntropy_of_condCollisionProb_le`: a uniform bound `Pc(X | U = u) ≤ c` on the + conditional collision probability lower-bounds the Shannon conditional entropy, + `log c⁻¹ ≤ H(X | U)` — the ensemble-independent skeleton of SIC/2-design accessible-information + bounds. +- `Real.prob_condCollisionEntropy_ge` — **Nielsen & Chuang, Theorem 12.17**: for a security + parameter `s > 0`, with probability at least `1 - 2⁻ˢ` (measured by `p_U`) the value `U = u` + satisfies `Hc(X | U = u) ≥ Hc(X) - 2·log₂|U| - 2s`. The proof combines the marginal-domination + bound above with a Cauchy–Schwarz / Markov argument (`sq_sum_le_card_mul_sum_sq`) applied to the + "bad" set `{u : Hc(X | U = u) < Hc(X) - 2·log₂|U| - 2s}`, translated between collision entropy + and collision probability through strict monotonicity of `log₂`. + +The exponent `-2·log₂|U|` matches Nielsen & Chuang; the Cauchy–Schwarz argument in fact yields the +sharper `-log₂|U|`, so the stated bound holds with room to spare (the slack `2⁻ˢ / √|U|`). +-/ + +@[expose] public section + +namespace Real + +variable {ι κ : Type*} [Fintype ι] + +/-! ### The conditional distribution `X | U = u` and its collision quantities -/ + +/-- The **conditional distribution** of `X` given `U = u`: `x ↦ p(x, u) / p_U(u)`, where +`p_U(u) = Real.marginalSnd p u`. When `p_U(u) = 0` this is the zero function. -/ +noncomputable def condDistribGivenSnd (p : ι × κ → ℝ) (u : κ) : ι → ℝ := + fun x ↦ p (x, u) / marginalSnd p u + +theorem condDistribGivenSnd_apply (p : ι × κ → ℝ) (u : κ) (x : ι) : + condDistribGivenSnd p u x = p (x, u) / marginalSnd p u := rfl + +/-- The conditional distribution is nonnegative when `p` is. -/ +theorem condDistribGivenSnd_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (u : κ) (x : ι) : + 0 ≤ condDistribGivenSnd p u x := + div_nonneg (hp _) (marginalSnd_nonneg hp u) + +/-- Where the marginal `p_U(u)` is nonzero, the conditional distribution is a genuine probability +distribution: `∑ₓ p(x | u) = 1`. -/ +theorem sum_condDistribGivenSnd {p : ι × κ → ℝ} {u : κ} (hu : marginalSnd p u ≠ 0) : + ∑ x, condDistribGivenSnd p u x = 1 := by + simp only [condDistribGivenSnd] + rw [← Finset.sum_div, ← marginalSnd_apply, div_self hu] + +/-- The **conditional collision probability** `Pc(X | U = u) = ∑ₓ p(x | u)²`. -/ +noncomputable def condCollisionProb (p : ι × κ → ℝ) (u : κ) : ℝ := + collisionProb (condDistribGivenSnd p u) + +/-- The **conditional collision entropy** `Hc(X | U = u) = -log₂ (∑ₓ p(x | u)²)`, the collision +entropy of the conditional distribution of `X` given `U = u`. -/ +noncomputable def condCollisionEntropy (p : ι × κ → ℝ) (u : κ) : ℝ := + collisionEntropy (condDistribGivenSnd p u) + +theorem condCollisionEntropy_eq (p : ι × κ → ℝ) (u : κ) : + condCollisionEntropy p u = -Real.logb 2 (condCollisionProb p u) := by + rw [condCollisionEntropy, collisionEntropy_eq, condCollisionProb] + +/-! ### Marginal domination of the conditional collision probability -/ + +/-- **Weighting identity**: `p_U(u)² · Pc(X | U = u) = ∑ₓ p(x, u)²`. Valid unconditionally on the +support (`p_U(u) ≠ 0`, where it is the definition cleared of denominators) and off it (`p_U(u) = 0` +forces every `p(x, u) = 0`, so both sides vanish). -/ +theorem marginalSnd_sq_mul_condCollisionProb {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (u : κ) : + marginalSnd p u ^ 2 * condCollisionProb p u = ∑ x, p (x, u) ^ 2 := by + rcases eq_or_ne (marginalSnd p u) 0 with h | h + · -- `p_U(u) = 0`: the whole fibre is zero. + have hz : ∀ x, p (x, u) = 0 := by + intro x + have hsum0 : ∑ x, p (x, u) = 0 := by rw [← marginalSnd_apply]; exact h + exact (Finset.sum_eq_zero_iff_of_nonneg fun x _ ↦ hp (x, u)).1 hsum0 x (Finset.mem_univ x) + simp [h, hz] + · -- `p_U(u) ≠ 0`: clear denominators. + rw [condCollisionProb, collisionProb_eq, Finset.mul_sum] + refine Finset.sum_congr rfl fun x _ ↦ ?_ + rw [condDistribGivenSnd_apply, div_pow, mul_comm, div_mul_cancel₀ _ (pow_ne_zero 2 h)] + +variable [Fintype κ] + +/-- **Marginal collision domination**: `∑ᵤ p_U(u)² · Pc(X | U = u) ≤ Pc(X)`. The left-hand side is +the joint collision probability `∑ₓ,ᵤ p(x, u)²`, and for each `x`, +`∑ᵤ p(x, u)² ≤ (∑ᵤ p(x, u))² = p_X(x)²` by `Finset.sum_sq_le_sq_sum_of_nonneg`. -/ +theorem sum_marginalSnd_sq_mul_condCollisionProb_le {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + ∑ u, marginalSnd p u ^ 2 * condCollisionProb p u ≤ collisionProb (marginalFst p) := by + calc ∑ u, marginalSnd p u ^ 2 * condCollisionProb p u + = ∑ u, ∑ x, p (x, u) ^ 2 := + Finset.sum_congr rfl fun u _ ↦ marginalSnd_sq_mul_condCollisionProb hp u + _ = ∑ x, ∑ u, p (x, u) ^ 2 := Finset.sum_comm + _ ≤ ∑ x, (∑ u, p (x, u)) ^ 2 := + Finset.sum_le_sum fun x _ ↦ Finset.sum_sq_le_sq_sum_of_nonneg fun u _ ↦ hp (x, u) + _ = collisionProb (marginalFst p) := by + simp only [collisionProb_eq, marginalFst_apply] + +/-! ### Chain rule: conditional entropy as an average of per-value entropies -/ + +/-- **Chain rule for the Shannon conditional entropy.** `H(X | U)` is the `p_U`-weighted average of +the Shannon entropies of the per-value conditional distributions `X | U = u`: + +`H(X | U) = ∑ᵤ p_U(u) · H(X | U = u)`, + +where `H(X | U = u) = Real.entropy (condDistribGivenSnd p u)`. This is the classical chain rule +`H(X, U) = H(U) + H(X | U)` read through `condEntropy p = H(X, U) − H(U)`; unlike the collision- +entropy tail bound below it involves no positivity of the conditioning, only `p ≥ 0`. + +The zero-marginal values `p_U(u) = 0` are handled gracefully: the whole fibre `p(·, u)` then +vanishes (nonnegativity), and `negMulLog 0 = 0` makes both the fibre's contribution to `H(X, U)` +and the weighted term `0 · H(X | U = u)` vanish. On the support the per-value identity is +`negMulLog`'s scaling law `negMulLog (p_U(u) · p(x | u)) = p(x | u) · negMulLog (p_U(u)) ++ p_U(u) · negMulLog (p(x | u))` summed over `x`, using `∑ₓ p(x | u) = 1`. -/ +theorem condEntropy_eq_sum_marginalSnd_mul_entropy {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) : + condEntropy p = ∑ u, marginalSnd p u * entropy (condDistribGivenSnd p u) := by + rw [condEntropy_eq, entropy_eq p, entropy_eq (marginalSnd p), Fintype.sum_prod_type, + Finset.sum_comm, ← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun u _ ↦ ?_ + rcases eq_or_ne (marginalSnd p u) 0 with hu | hu + · -- `p_U(u) = 0`: the whole fibre `p(·, u)` vanishes. + have hz : ∀ x, p (x, u) = 0 := by + intro x + have hsum0 : ∑ x, p (x, u) = 0 := by rw [← marginalSnd_apply]; exact hu + exact (Finset.sum_eq_zero_iff_of_nonneg fun x _ ↦ hp (x, u)).1 hsum0 x (Finset.mem_univ x) + simp [hu, hz] + · -- `p_U(u) ≠ 0`: reconstruct `p(x, u) = p_U(u) · p(x | u)` and apply `negMulLog_mul`. + have hpe : ∀ x, p (x, u) = marginalSnd p u * condDistribGivenSnd p u x := by + intro x + rw [condDistribGivenSnd_apply, mul_comm, div_mul_cancel₀ _ hu] + calc (∑ x, (p (x, u)).negMulLog) - (marginalSnd p u).negMulLog + = (∑ x, (marginalSnd p u * condDistribGivenSnd p u x).negMulLog) + - (marginalSnd p u).negMulLog := by simp_rw [← hpe] + _ = (∑ x, (condDistribGivenSnd p u x * (marginalSnd p u).negMulLog + + marginalSnd p u * (condDistribGivenSnd p u x).negMulLog)) + - (marginalSnd p u).negMulLog := by simp_rw [negMulLog_mul] + _ = ((∑ x, condDistribGivenSnd p u x) * (marginalSnd p u).negMulLog + + marginalSnd p u * ∑ x, (condDistribGivenSnd p u x).negMulLog) + - (marginalSnd p u).negMulLog := by + rw [Finset.sum_add_distrib, Finset.sum_mul, Finset.mul_sum] + _ = marginalSnd p u * entropy (condDistribGivenSnd p u) := by + rw [sum_condDistribGivenSnd hu, one_mul, entropy_eq]; ring + +/-- **Uniform conditional-collision bound ⟹ conditional-entropy lower bound.** If every value +`U = u` has conditional collision probability `Pc(X | U = u) ≤ c`, then the Shannon conditional +entropy is at least `log c⁻¹`: + +`(∀ u, Pc(X | U = u) ≤ c) → log c⁻¹ ≤ H(X | U)`. + +This is the ensemble-independent skeleton behind accessible-information bounds of the SIC / 2-design +kind: combine the chain rule `H(X | U) = ∑ᵤ p_U(u) · H(X | U = u)` +(`condEntropy_eq_sum_marginalSnd_mul_entropy`) with the per-value Shannon ≥ Rényi-2 bound +`log (Pc(X | U = u))⁻¹ ≤ H(X | U = u)` (`log_collisionProb_inv_le_entropy`), monotonicity of `log`, +and `∑ᵤ p_U(u) = 1`. No positivity of `c` is assumed: on the support `Pc(X | U = u) > 0` +(`collisionProb_pos`) already forces `c > 0`, and the off-support values are weighted out by +`p_U(u) = 0`. -/ +theorem log_inv_le_condEntropy_of_condCollisionProb_le {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) + (hsum : ∑ u, marginalSnd p u = 1) {c : ℝ} (hle : ∀ u, condCollisionProb p u ≤ c) : + Real.log c⁻¹ ≤ condEntropy p := by + rw [condEntropy_eq_sum_marginalSnd_mul_entropy hp] + calc Real.log c⁻¹ = (∑ u, marginalSnd p u) * Real.log c⁻¹ := by rw [hsum, one_mul] + _ = ∑ u, marginalSnd p u * Real.log c⁻¹ := by rw [Finset.sum_mul] + _ ≤ ∑ u, marginalSnd p u * entropy (condDistribGivenSnd p u) := by + refine Finset.sum_le_sum fun u _ ↦ ?_ + rcases eq_or_ne (marginalSnd p u) 0 with hu | hu + · simp [hu] + · refine mul_le_mul_of_nonneg_left ?_ (marginalSnd_nonneg hp u) + have hccpos : 0 < condCollisionProb p u := collisionProb_pos (sum_condDistribGivenSnd hu) + have h1 := log_collisionProb_inv_le_entropy + (condDistribGivenSnd_nonneg hp u) (sum_condDistribGivenSnd hu) + rw [show collisionProb (condDistribGivenSnd p u) = condCollisionProb p u from rfl, + Real.log_inv] at h1 + have h2 : Real.log (condCollisionProb p u) ≤ Real.log c := log_le_log hccpos (hle u) + rw [Real.log_inv] + linarith + +/-! ### The privacy-amplification tail bound (Nielsen & Chuang, Theorem 12.17) -/ + +/-- **Nielsen & Chuang, Theorem 12.17** (privacy amplification / information reconciliation). +Let `X` and `U` be jointly distributed random variables with joint law `p : ι × κ → ℝ` +(`p ≥ 0`, `∑ p = 1`), and let `s > 0` be a security parameter. Then, with probability at least +`1 - 2⁻ˢ` (measured by the marginal `p_U`), the value `U = u` satisfies +`Hc(X | U = u) ≥ Hc(X) - 2·log₂|U| - 2s`, where `Hc(X) = Real.collisionEntropy (marginalFst p)` +and `|U| = Fintype.card κ`. + +The event is recorded as a lower bound `1 - 2⁻ˢ ≤ ∑ᵤ p_U(u)` over the `u` at which the inequality +holds. The proof: the "bad" set carries collision-probability weight bounded via +`sum_marginalSnd_sq_mul_condCollisionProb_le` and `sq_sum_le_card_mul_sum_sq`, and collision +entropy converts to collision probability through the strict monotonicity of `log₂`. + +Nielsen & Chuang state this for a security parameter `s > 0` (the regime where `1 - 2⁻ˢ ∈ (0, 1)` +is a genuine high-probability guarantee); the inequality in fact holds for every real `s`, +vacuously when `s ≤ 0` since then `1 - 2⁻ˢ ≤ 0 ≤ ∑ᵤ p_U(u)`. -/ +theorem prob_condCollisionEntropy_ge (p : ι × κ → ℝ) (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) + (s : ℝ) : + 1 - (2 : ℝ) ^ (-s) ≤ ∑ u ∈ Finset.univ.filter + (fun u ↦ collisionEntropy (marginalFst p) - 2 * Real.logb 2 (Fintype.card κ) - 2 * s + ≤ condCollisionEntropy p u), + marginalSnd p u := by + classical + -- Abbreviations and positivity facts. + have hHcX : collisionEntropy (marginalFst p) = -Real.logb 2 (collisionProb (marginalFst p)) := + collisionEntropy_eq _ + have hPpos : 0 < collisionProb (marginalFst p) := by + apply collisionProb_pos; rw [sum_marginalFst]; exact hsum + set P := collisionProb (marginalFst p) with hPdef + -- `κ` is nonempty, so `|U| ≥ 1`. + have hcard0 : Fintype.card κ ≠ 0 := by + intro h + rw [Fintype.card_eq_zero_iff] at h + have hz : (∑ q : ι × κ, p q) = 0 := Finset.sum_eq_zero fun q _ ↦ h.elim q.2 + rw [hsum] at hz; exact one_ne_zero hz + have hcardR : (0 : ℝ) < Fintype.card κ := by exact_mod_cast Nat.pos_of_ne_zero hcard0 + have hcard1 : (1 : ℝ) ≤ Fintype.card κ := by exact_mod_cast Nat.one_le_iff_ne_zero.2 hcard0 + have hbase : (0 : ℝ) < 2 := by norm_num + have h2pos : (0 : ℝ) < (2 : ℝ) ^ (2 * s) := Real.rpow_pos_of_pos hbase _ + set θ := P * (Fintype.card κ : ℝ) ^ 2 * (2 : ℝ) ^ (2 * s) with hθdef + have hθpos : 0 < θ := by + rw [hθdef]; exact mul_pos (mul_pos hPpos (pow_pos hcardR 2)) h2pos + -- The threshold `θ` realises the entropy bound as `-log₂ θ`. + have hlogθ : Real.logb 2 θ = Real.logb 2 P + 2 * Real.logb 2 (Fintype.card κ) + 2 * s := by + rw [hθdef, Real.logb_mul (ne_of_gt (mul_pos hPpos (pow_pos hcardR 2))) (ne_of_gt h2pos), + Real.logb_mul (ne_of_gt hPpos) (ne_of_gt (pow_pos hcardR 2)), Real.logb_pow, + Real.logb_rpow hbase (by norm_num)] + push_cast; ring + have hbound : collisionEntropy (marginalFst p) - 2 * Real.logb 2 (Fintype.card κ) - 2 * s + = -Real.logb 2 θ := by rw [hHcX, hlogθ]; ring + -- `2⁻ˢ` squared kills the `2^{2s}` in `θ`. + have htA : ((2 : ℝ) ^ (-s)) ^ 2 * (2 : ℝ) ^ (2 * s) = 1 := by + rw [sq, ← Real.rpow_add hbase, ← Real.rpow_add hbase, show -s + -s + 2 * s = 0 by ring, + Real.rpow_zero] + have ht_nonneg : 0 ≤ (2 : ℝ) ^ (-s) := le_of_lt (Real.rpow_pos_of_pos hbase _) + -- The "bad" set and its total `p_U`-mass. + set bad := Finset.univ.filter (fun u ↦ ¬ (collisionEntropy (marginalFst p) + - 2 * Real.logb 2 (Fintype.card κ) - 2 * s ≤ condCollisionEntropy p u)) with hbaddef + set S := ∑ u ∈ bad, marginalSnd p u with hSdef + set T := ∑ u ∈ bad, marginalSnd p u ^ 2 with hTdef + have hS_nonneg : 0 ≤ S := Finset.sum_nonneg fun u _ ↦ marginalSnd_nonneg hp u + -- Step 1+2: `θ · T ≤ Pc(X)`. + have hθT : θ * T ≤ P := by + calc θ * T = ∑ u ∈ bad, θ * marginalSnd p u ^ 2 := by rw [hTdef, Finset.mul_sum] + _ ≤ ∑ u ∈ bad, marginalSnd p u ^ 2 * condCollisionProb p u := by + refine Finset.sum_le_sum fun u hu ↦ ?_ + rw [hbaddef, Finset.mem_filter] at hu + have hbadu : condCollisionEntropy p u + < collisionEntropy (marginalFst p) - 2 * Real.logb 2 (Fintype.card κ) - 2 * s := + not_le.1 hu.2 + rcases eq_or_lt_of_le (marginalSnd_nonneg hp u) with hzero | hpos + · rw [← hzero]; simp + · -- `p_U(u) > 0`: the entropy bound forces `θ ≤ Pc(X | U = u)`. + have hcpos : 0 < condCollisionProb p u := + collisionProb_pos (sum_condDistribGivenSnd hpos.ne') + have hlt : Real.logb 2 θ < Real.logb 2 (condCollisionProb p u) := by + have h1 : condCollisionEntropy p u < -Real.logb 2 θ := by rwa [hbound] at hbadu + rw [condCollisionEntropy_eq] at h1 + linarith + have hθc : θ ≤ condCollisionProb p u := + le_of_lt <| (Real.strictMonoOn_logb (by norm_num)).lt_iff_lt hθpos hcpos |>.1 hlt + calc θ * marginalSnd p u ^ 2 + ≤ condCollisionProb p u * marginalSnd p u ^ 2 := + mul_le_mul_of_nonneg_right hθc (sq_nonneg _) + _ = marginalSnd p u ^ 2 * condCollisionProb p u := mul_comm _ _ + _ ≤ ∑ u, marginalSnd p u ^ 2 * condCollisionProb p u := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun u _ _ ↦ mul_nonneg (sq_nonneg _) (collisionProb_nonneg _)) + _ ≤ P := sum_marginalSnd_sq_mul_condCollisionProb_le hp + -- Step 3: Cauchy–Schwarz `S² ≤ |bad| · T`, and `|bad| ≤ |U|`. + have hCS : S ^ 2 ≤ (bad.card : ℝ) * T := by rw [hSdef, hTdef]; exact sq_sum_le_card_mul_sum_sq + -- Step 4: `S² ≤ (2⁻ˢ)²`. + have hkey : θ * (S ^ 2) ≤ θ * ((2 : ℝ) ^ (-s)) ^ 2 := by + have hstep : θ * ((bad.card : ℝ) * T) ≤ θ * ((2 : ℝ) ^ (-s)) ^ 2 := by + have e2 : θ * ((2 : ℝ) ^ (-s)) ^ 2 = P * (Fintype.card κ : ℝ) ^ 2 := by + rw [hθdef] + calc P * (Fintype.card κ : ℝ) ^ 2 * (2 : ℝ) ^ (2 * s) * ((2 : ℝ) ^ (-s)) ^ 2 + = P * (Fintype.card κ : ℝ) ^ 2 * (((2 : ℝ) ^ (-s)) ^ 2 * (2 : ℝ) ^ (2 * s)) := by ring + _ = P * (Fintype.card κ : ℝ) ^ 2 := by rw [htA, mul_one] + rw [e2] + calc θ * ((bad.card : ℝ) * T) = (bad.card : ℝ) * (θ * T) := by ring + _ ≤ (bad.card : ℝ) * P := + mul_le_mul_of_nonneg_left hθT (by positivity) + _ ≤ (Fintype.card κ : ℝ) * P := by + refine mul_le_mul_of_nonneg_right ?_ hPpos.le + calc (bad.card : ℝ) ≤ (Finset.univ.card : ℝ) := by + exact_mod_cast Finset.card_filter_le _ _ + _ = (Fintype.card κ : ℝ) := by rw [Finset.card_univ] + _ = P * (Fintype.card κ : ℝ) := mul_comm _ _ + _ ≤ P * (Fintype.card κ : ℝ) ^ 2 := by + refine mul_le_mul_of_nonneg_left ?_ hPpos.le + nlinarith [hcard1, hcardR] + exact (mul_le_mul_of_nonneg_left hCS hθpos.le).trans hstep + have hSsq : S ^ 2 ≤ ((2 : ℝ) ^ (-s)) ^ 2 := le_of_mul_le_mul_left hkey hθpos + have hS_le : S ≤ (2 : ℝ) ^ (-s) := by + have := Real.sqrt_le_sqrt hSsq + rwa [Real.sqrt_sq hS_nonneg, Real.sqrt_sq ht_nonneg] at this + -- Step 5: convert the bad-set mass bound into the good-set probability bound. + have hsplit : (∑ u ∈ Finset.univ.filter (fun u ↦ collisionEntropy (marginalFst p) + - 2 * Real.logb 2 (Fintype.card κ) - 2 * s ≤ condCollisionEntropy p u), marginalSnd p u) + + S = 1 := by + rw [hSdef, hbaddef, Finset.sum_filter_add_sum_filter_not Finset.univ _ (marginalSnd p), + sum_marginalSnd, hsum] + linarith + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalConcentration.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalConcentration.lean new file mode 100644 index 0000000000..1b30c30661 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalConcentration.lean @@ -0,0 +1,171 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.ConditionalTypicalSequence + +/-! +# Random-coding concentration for the conditional typical set (the eq. 12.76 expectation) + +The theorem of typical sequences bounds, for a *fixed* i.i.d. source, the probability that a +length-`n` sequence is atypical (`Real.sum_typicalSeq_ge`, +`ToMathlib/InformationTheory/TypicalSequence.lean`). Nielsen and Chuang's proof of the +Holevo–Schumacher–Westmoreland theorem (Theorem 12.8, random-coding achievability) needs a +*two-level* variant: the codeword letters are themselves random. Alice draws a length-`n` codeword +`M : Fin n → α` with letters `Mᵢ` i.i.d. from an ensemble `p : α → ℝ`; each letter `a` carries a +conditional distribution `l a : β → ℝ` (in the quantum application, `l a` is the eigenvalue +distribution of the channel output `E(ρ_a)`). The codeword's *conditional* typical set is +`Real.condTypicalSeq (fun i ↦ l (Mᵢ)) s ε`, and N&C's Eq. 12.76 bounds the **random-coding +expectation** of the atypical weight, + +`𝔼_M [ 1 − ∑_{κ ∈ T_M} ∏ᵢ l (Mᵢ) (κᵢ) ] ≤ δ`. + +## Main result + +* `Real.sum_weighted_one_sub_condTypicalSeq_le` — with the threshold `s` equal to the + ensemble-average conditional entropy `∑ₐ p a · H(l a)`, the `p`-weighted average over codewords of + the conditional-atypical weight is at most `V / (n ε²)`, where + `V = ∑ₐ p a · ∑_b l a b · (−log (l a b) − s)²` is the per-letter surprisal variance of the joint + source. As `n → ∞` (with `ε` fixed) this tends to `0` — N&C's Eq. 12.76. + +## Proof + +The two-level average is a *single-level* deviation bound in disguise. The pairs `(Mᵢ, Kᵢ)` — a +letter and a conditional draw — are i.i.d. under the joint distribution `q (a, b) = p a · l a b` on +`α × β`; the conditional surprisal `g (a, b) = −log (l a b)` has `q`-mean exactly the threshold +`s = ∑ₐ p a · H(l a)`. The double sum `∑_M ∏ p · ∑_{κ ∉ T_M} ∏ l` reindexes, via +`Equiv.arrowProdEquivProdArrow`, to the `q`-mass of the joint deviation set `|(1/n)∑ᵢ g − s| > ε`, +which the finite Chebyshev engine `Real.iid_average_deviation_le` +(`ToMathlib/InformationTheory/IIDConcentration.lean`) bounds by `V / (n ε²)`. Off-support codewords +(`∏ l = 0`) contribute zero, so the multiplicative `condTypicalSeq` and the additive deviation set +agree in mass — the same support bookkeeping as `Real.sum_typicalSeq_ge`. +-/ + +@[expose] public section + +open Finset + +namespace Real + +/-- **Reindexing the joint deviation mass.** For a predicate `pred` on `(letter, conditional-draw)` +sequence pairs, the `q`-mass over joint sequences `w : Fin n → α × β` (with +`q (a, b) = p a · l a b`) of the pairs whose split `(fun i ↦ (w i).1, fun i ↦ (w i).2)` satisfies +`pred` equals the two-level sum `∑_M ∑_{κ : pred M κ} (∏ p) · (∏ l)`. The +`Equiv.arrowProdEquivProdArrow` identity `(Fin n → α × β) ≃ (Fin n → α) × (Fin n → β)` splits the +joint sequence into a codeword `M` and a conditional sequence `κ`, and `∏ᵢ q (wᵢ)` factors as +`(∏ᵢ p (Mᵢ)) · (∏ᵢ l (Mᵢ) (κᵢ))`. -/ +private lemma sum_filter_prod_pair_eq {α β : Type*} [Fintype α] [Fintype β] {n : ℕ} + (p : α → ℝ) (l : α → β → ℝ) (pred : (Fin n → α) → (Fin n → β) → Prop) + [∀ M, DecidablePred (pred M)] : + ∑ w ∈ univ.filter (fun w : Fin n → α × β => pred (fun i => (w i).1) (fun i => (w i).2)), + ∏ i, (p (w i).1 * l (w i).1 (w i).2) + = ∑ M : Fin n → α, ∑ κ ∈ univ.filter (pred M), (∏ i, p (M i)) * ∏ i, l (M i) (κ i) := by + classical + rw [Finset.sum_filter, + ← Equiv.sum_comp (Equiv.arrowProdEquivProdArrow (Fin n) (fun _ => α) (fun _ => β)).symm, + Fintype.sum_prod_type] + refine Finset.sum_congr rfl (fun M _ => ?_) + rw [Finset.sum_filter] + refine Finset.sum_congr rfl (fun κ _ => ?_) + simp only [Equiv.arrowProdEquivProdArrow_symm_apply] + rw [Finset.prod_mul_distrib] + +/-- **Random-coding concentration for the conditional typical set** (Nielsen & Chuang, Theorem 12.8, +Eq. 12.76). Letters are drawn from an ensemble `p : α → ℝ` and each letter `a` carries a conditional +distribution `l a : β → ℝ`. With the threshold `s` equal to the ensemble-average conditional entropy +`∑ₐ p a · H(l a)`, the `p`-weighted average over length-`n` codewords `M : Fin n → α` of the +conditional-atypical weight `1 − ∑_{κ ∈ T_M} ∏ᵢ l (Mᵢ) (κᵢ)` is at most `V / (n ε²)`, where +`V = ∑ₐ p a · ∑_b l a b · (−log (l a b) − s)²` is the per-letter surprisal variance of the joint +`(letter, draw)` source. As `n → ∞` (with `ε` fixed) the right side tends to `0`. + +The pairs `(Mᵢ, Kᵢ)` are i.i.d. under `q (a, b) = p a · l a b`, and the conditional surprisal +`g (a, b) = −log (l a b)` has `q`-mean `s`; the two-level average is the `q`-mass of the joint +deviation set, bounded by the Chebyshev engine `Real.iid_average_deviation_le`. Off-support +codewords contribute zero, matching the additive deviation set to the multiplicative +`condTypicalSeq`. The random-coding twin of `Real.sum_typicalSeq_ge`. -/ +theorem sum_weighted_one_sub_condTypicalSeq_le + {α β : Type*} [Fintype α] [Fintype β] + (p : α → ℝ) (hp0 : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) + (l : α → β → ℝ) (hl0 : ∀ a b, 0 ≤ l a b) (hl1 : ∀ a, ∑ b, l a b = 1) + {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) + {s : ℝ} (hs : s = ∑ a, p a * Real.entropy (l a)) : + ∑ M : Fin n → α, (∏ i, p (M i)) * + (1 - ∑ κ ∈ Real.condTypicalSeq (fun i => l (M i)) s ε, ∏ i, l (M i) (κ i)) + ≤ (∑ a, p a * ∑ b, l a b * (- Real.log (l a b) - s) ^ 2) / (n * ε ^ 2) := by + classical + -- The joint `(letter, draw)` source `q` and its conditional surprisal `g`. + set q : α × β → ℝ := fun w => p w.1 * l w.1 w.2 with hq + set g : α × β → ℝ := fun w => - Real.log (l w.1 w.2) with hgdef + have hent : ∀ a, Real.entropy (l a) = ∑ b, l a b * (- Real.log (l a b)) := fun a => by + rw [Real.entropy_eq_neg_sum_mul_log, ← Finset.sum_neg_distrib] + exact Finset.sum_congr rfl (fun b _ => by ring) + have hq0 : ∀ w, 0 ≤ q w := fun w => mul_nonneg (hp0 _) (hl0 _ _) + have hq1 : ∑ w, q w = 1 := by + rw [Fintype.sum_prod_type] + simp only [hq, ← Finset.mul_sum, hl1, mul_one, hp1] + -- The `q`-mean of `g` is the threshold `s`. + have hm : s = ∑ w, q w * g w := by + rw [Fintype.sum_prod_type, hs] + refine Finset.sum_congr rfl (fun a _ => ?_) + rw [hent, Finset.mul_sum] + refine Finset.sum_congr rfl (fun b _ => ?_) + simp only [hq, hgdef]; ring + -- The joint per-letter variance is the stated `V`. + have hV : (∑ w, q w * (g w - s) ^ 2) + = ∑ a, p a * ∑ b, l a b * (- Real.log (l a b) - s) ^ 2 := by + rw [Fintype.sum_prod_type] + refine Finset.sum_congr rfl (fun a _ => ?_) + rw [Finset.mul_sum] + refine Finset.sum_congr rfl (fun b _ => ?_) + simp only [hq, hgdef]; ring + -- Chebyshev on the joint source, rewritten with `V`. + have hdev := Real.iid_average_deviation_le q g hq0 hq1 hm hn hε + rw [hV] at hdev + refine le_trans ?_ hdev + -- Reindex the joint deviation mass into the two-level codeword sum. + set pred : (Fin n → α) → (Fin n → β) → Prop := + fun M κ => ε < |(∑ i, - Real.log (l (M i) (κ i))) / (n : ℝ) - s| with hpred + have hreindex : ∑ w ∈ univ.filter (fun w : Fin n → α × β => ε < |(∑ i, g (w i)) / (n : ℝ) - s|), + ∏ i, q (w i) + = ∑ M : Fin n → α, ∑ κ ∈ univ.filter (pred M), (∏ i, p (M i)) * ∏ i, l (M i) (κ i) := by + convert sum_filter_prod_pair_eq p l pred using 2 + rw [hreindex] + -- Term by term over codewords `M`: the conditional-atypical weight is the atypical mass. + refine Finset.sum_le_sum (fun M _ => ?_) + have hone : ∑ κ : Fin n → β, ∏ i, l (M i) (κ i) = 1 := by + rw [← Fintype.piFinset_univ, ← Finset.prod_univ_sum] + simp only [hl1, Finset.prod_const_one] + have heq : (1 : ℝ) - ∑ κ ∈ Real.condTypicalSeq (fun i => l (M i)) s ε, ∏ i, l (M i) (κ i) + = ∑ κ ∈ univ \ Real.condTypicalSeq (fun i => l (M i)) s ε, ∏ i, l (M i) (κ i) := by + rw [Finset.sum_sdiff_eq_sub (Finset.subset_univ _), hone] + rw [heq, Finset.mul_sum, Finset.sdiff_eq_filter, Finset.sum_filter, Finset.sum_filter] + refine Finset.sum_le_sum (fun κ _ => ?_) + have hpl_nn : 0 ≤ (∏ i, p (M i)) * ∏ i, l (M i) (κ i) := + mul_nonneg (Finset.prod_nonneg fun i _ => hp0 _) (Finset.prod_nonneg fun i _ => hl0 _ _) + by_cases hT : κ ∈ Real.condTypicalSeq (fun i => l (M i)) s ε + · rw [ite_eq_right (not_not.mpr hT)] + split_ifs + · exact hpl_nn + · exact le_refl 0 + · rw [ite_eq_left hT] + by_cases hpos : 0 < ∏ i, l (M i) (κ i) + · -- On the support the multiplicative typicality is the additive deviation. + have hn' : 0 < Fintype.card (Fin n) := by rw [Fintype.card_fin]; exact hn + have hnotle : ¬ |(∑ i, - Real.log (l (M i) (κ i))) / (Fintype.card (Fin n) : ℝ) - s| ≤ ε := + fun hle => hT ((Real.mem_condTypicalSeq_iff_abs_le hn' hpos).mpr hle) + have hpredκ : pred M κ := by + rw [hpred]; rw [Fintype.card_fin] at hnotle; exact not_le.mp hnotle + rw [ite_eq_left hpredκ] + · -- Off the support the atypical mass is zero. + have hz : ∏ i, l (M i) (κ i) = 0 := + le_antisymm (not_lt.mp hpos) (Finset.prod_nonneg fun i _ => hl0 _ _) + rw [hz, mul_zero] + split_ifs <;> exact le_refl 0 + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalSequence.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalSequence.lean new file mode 100644 index 0000000000..5f56dfb304 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/ConditionalTypicalSequence.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence +public import Mathlib.Algebra.BigOperators.Ring.Finset +public import Mathlib.Data.Fintype.Pi + +/-! +# Conditional typical sequences (typical sequences for a product of *distinct* distributions) + +The theorem of typical sequences (`ToMathlib.InformationTheory.TypicalSequence`) concerns the i.i.d. +source: a single distribution `p : α → ℝ` repeated `n` times, with sequence probability +`∏ i, p (s i)`. Nielsen and Chuang's proof of the Holevo–Schumacher–Westmoreland theorem (Theorem +12.8, the random-coding argument) needs a variant in which each coordinate carries a **different** +distribution — the *conditional* typical set `T_M` of a product codeword +`σ_M = σ_{M₁} ⊗ ⋯ ⊗ σ_{Mₙ}`, whose factors are drawn from an ensemble and so are in general +distinct (N&C Eqs. 12.74–12.77). + +Fix a finite index type `ι` (the coordinates, `n = |ι|`), a family of finite alphabets +`β : ι → Type` and a family of distributions `p : (i : ι) → β i → ℝ` (each `p i` a probability +distribution). For a threshold `s` and tolerance `ε`, a *dependent* sequence `κ : (i : ι) → β i` is +**`(s, ε)`-typical** when its product probability `∏ i, p i (κ i)` lies between `exp (-n (s + ε))` +and `exp (-n (s - ε))` — equivalently (on the support) when its per-coordinate empirical surprisal +`(∑ i, -log (p i (κ i))) / n` is within `ε` of `s` (N&C Eq. 12.75, with `s = S_bar` the +ensemble-average entropy). + +## Main definitions and results + +* `Real.condTypicalSeq` — the conditional typical set `T(s, ε)` (N&C Eq. 12.75), the + distinct-distribution generalisation of `Real.typicalSeq`. +* `Real.mem_condTypicalSeq` — its membership predicate (the multiplicative squeeze). +* `Real.mem_condTypicalSeq_iff_abs_le` — **Eq. 12.75.** On the support, typicality is the additive + empirical-surprisal condition `|(∑ i, -log (p i (κ i)))/n - s| ≤ ε`. +* `Real.card_condTypicalSeq_le` — **the dimension bound** (N&C Eq. 12.77): `|T(s, ε)| ≤ exp (n (s + + ε))`, for *every* `n` (a deterministic combinatorial bound, independent of the ensemble). Each + typical sequence has probability at least `exp (-n (s + ε))`, and the sequences carry total mass + at most `1` (the total mass being `∏ i, ∑ b, p i b = 1`), so `|T| · exp (-n (s + ε)) ≤ 1`. + +This is the distinct-distribution twin of `Real.typicalSeq` / `Real.card_typicalSeq_le`; the +quantum wrapper (the conditional typical *subspace* projector `P_M` and `tr(P_M) ≤ exp(n(S_bar+ε))`) +is `AxQM.State.condTypicalSubspaceProj` in `AxQM/Postulates/API`. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {β : ι → Type*} [∀ i, Fintype (β i)] + +open Classical in +/-- The **conditional typical set** `T(s, ε)` of a product of distinct per-coordinate distributions +`p : (i : ι) → β i → ℝ` (Nielsen & Chuang, Eq. 12.75, `n = |ι|`): the dependent sequences +`κ : (i : ι) → β i` whose product probability `∏ i, p i (κ i)` lies between `exp (-n (s + ε))` and +`exp (-n (s - ε))`. The lower bound being a positive exponential, this automatically excludes +zero-probability sequences. The distinct-distribution generalisation of `Real.typicalSeq` (which is +this set for a constant family `p i = p`, over `ι = Fin n`). -/ +noncomputable def condTypicalSeq (p : (i : ι) → β i → ℝ) (s ε : ℝ) : Finset ((i : ι) → β i) := + univ.filter fun κ => Real.exp (-(Fintype.card ι : ℝ) * (s + ε)) ≤ ∏ i, p i (κ i) ∧ + ∏ i, p i (κ i) ≤ Real.exp (-(Fintype.card ι : ℝ) * (s - ε)) + +/-- Membership in the conditional typical set: `κ` is typical iff its product probability is +squeezed between `exp (-n (s + ε))` and `exp (-n (s - ε))`. -/ +theorem mem_condTypicalSeq {p : (i : ι) → β i → ℝ} {s ε : ℝ} {κ : (i : ι) → β i} : + κ ∈ condTypicalSeq p s ε ↔ + Real.exp (-(Fintype.card ι : ℝ) * (s + ε)) ≤ ∏ i, p i (κ i) ∧ + ∏ i, p i (κ i) ≤ Real.exp (-(Fintype.card ι : ℝ) * (s - ε)) := by + simp only [condTypicalSeq, mem_filter, mem_univ, true_and] + +/-- **Nielsen & Chuang, Eq. 12.75.** On the support of the product distribution +(`0 < ∏ i, p i (κ i)`, i.e. `p i (κ i) > 0` for all `i`), `κ` is `(s, ε)`-typical iff its +per-coordinate empirical surprisal `(∑ i, -log (p i (κ i))) / n` is within `ε` of the threshold `s`. +This is the equivalence between the multiplicative definition and N&C's additive reformulation, +valid precisely on the support (where `log (∏ i, p i (κ i)) = ∑ i, log (p i (κ i))`). -/ +theorem mem_condTypicalSeq_iff_abs_le {p : (i : ι) → β i → ℝ} (hn : 0 < Fintype.card ι) {s ε : ℝ} + {κ : (i : ι) → β i} (hpos : 0 < ∏ i, p i (κ i)) : + κ ∈ condTypicalSeq p s ε ↔ + |(∑ i, -Real.log (p i (κ i))) / (Fintype.card ι : ℝ) - s| ≤ ε := by + have hn0 : (0 : ℝ) < Fintype.card ι := by exact_mod_cast hn + have hne : ∀ i, p i (κ i) ≠ 0 := fun i => + (Finset.prod_ne_zero_iff.mp hpos.ne') i (mem_univ i) + have hsum : (∑ i, -Real.log (p i (κ i))) = -Real.log (∏ i, p i (κ i)) := by + rw [Real.log_prod (fun x _ => hne x)] + exact Finset.sum_neg_distrib _ + rw [mem_condTypicalSeq, ← Real.le_log_iff_exp_le hpos, ← Real.log_le_iff_le_exp hpos] + set L := Real.log (∏ i, p i (κ i)) + rw [hsum] + have hfrac : (-L) / (Fintype.card ι : ℝ) - s = (-L - s * Fintype.card ι) / Fintype.card ι := by + field_simp + rw [hfrac, abs_div, abs_of_pos hn0, div_le_iff₀ hn0, abs_le] + constructor + · rintro ⟨h1, h2⟩; constructor <;> nlinarith + · rintro ⟨h1, h2⟩; constructor <;> nlinarith + +/-- **The dimension bound** (Nielsen & Chuang, Eq. 12.77): the number of `(s, ε)`-typical dependent +sequences satisfies `|T(s, ε)| ≤ exp (n (s + ε))`, for every `n = |ι|`. A deterministic +combinatorial bound — it needs only that each `p i` is a probability distribution, not that `s` is +any particular value. Each typical sequence has probability at least `exp (-n (s + ε))`, and the +typical sequences +carry total probability at most `1` (the total mass over *all* sequences being +`∑ κ, ∏ i, p i (κ i) = ∏ i, ∑ b, p i b = 1`), so `|T| · exp (-n (s + ε)) ≤ 1`. The +distinct-distribution generalisation of `Real.card_typicalSeq_le`. -/ +theorem card_condTypicalSeq_le {p : (i : ι) → β i → ℝ} (hp0 : ∀ i b, 0 ≤ p i b) + (hp1 : ∀ i, ∑ b, p i b = 1) (s ε : ℝ) : + ((condTypicalSeq p s ε).card : ℝ) ≤ Real.exp ((Fintype.card ι : ℝ) * (s + ε)) := by + have hnn : ∀ κ : (i : ι) → β i, (0 : ℝ) ≤ ∏ i, p i (κ i) := + fun κ => Finset.prod_nonneg fun i _ => hp0 i _ + -- Total mass over all sequences is `∏ i, ∑ b, p i b = 1`. + have htotal : (∑ κ : (i : ι) → β i, ∏ i, p i (κ i)) = 1 := by + rw [← Fintype.piFinset_univ, ← Finset.prod_univ_sum] + simp only [hp1, Finset.prod_const_one] + have hsum_le_one : ∑ κ ∈ condTypicalSeq p s ε, ∏ i, p i (κ i) ≤ 1 := by + rw [← htotal] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) fun κ _ _ => hnn κ + have hlb : ((condTypicalSeq p s ε).card : ℝ) * Real.exp (-(Fintype.card ι : ℝ) * (s + ε)) + ≤ ∑ κ ∈ condTypicalSeq p s ε, ∏ i, p i (κ i) := by + rw [← nsmul_eq_mul, ← Finset.sum_const] + exact Finset.sum_le_sum fun κ hκ => (mem_condTypicalSeq.mp hκ).1 + have hexp : Real.exp (-(Fintype.card ι : ℝ) * (s + ε)) + = (Real.exp ((Fintype.card ι : ℝ) * (s + ε)))⁻¹ := by rw [neg_mul, Real.exp_neg] + rw [hexp] at hlb + have hcard : + ((condTypicalSeq p s ε).card : ℝ) / Real.exp ((Fintype.card ι : ℝ) * (s + ε)) ≤ 1 := by + rw [div_eq_mul_inv]; exact hlb.trans hsum_le_one + rw [div_le_iff₀ (Real.exp_pos _)] at hcard + simpa using hcard + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/Fano.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/Fano.lean new file mode 100644 index 0000000000..32a161c349 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/Fano.lean @@ -0,0 +1,372 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.BinaryEntropy + +/-! +# Fano's inequality + +For finite types `ι`, `κ` and a joint distribution `p : ι × κ → ℝ` of a pair of random variables +`(X, Y)` (`0 ≤ p` and `∑ p = 1`), suppose we try to infer `X` from `Y` by a guess `X_tilde = g Y` +for +some `g : κ → ι`. Let + +`Real.fanoErrorProb p g = p(X ≠ g Y) = 1 − ∑_y p (g y, y)` + +be the probability the guess is wrong. **Fano's inequality** (Nielsen & Chuang, *Quantum +Computation and Quantum Information*, Box 12.2 on p. 536, eq. (12.16)) bounds the conditional +entropy `H(X | Y)` in terms of this error probability and the alphabet size `|ι|`: + +`H(X | Y) ≤ H(pₑ) + pₑ · log (|ι| − 1)`, + +where `H(·)` is the binary entropy (`Real.binEntropy`). Equivalently, the right-hand side is the +`|ι|`-ary entropy `Real.qaryEntropy |ι| pₑ`. Qualitatively: if `H(X | Y)` is large then the error +probability `pₑ` must also be large — knowledge of `Y` can only pin down `X` as well as its +residual conditional entropy allows. + +## Main declarations + +* `Real.fanoErrorProb` — the error probability `p(X ≠ g Y)` of the guess `X_tilde = g Y`, with + `Real.fanoErrorProb_nonneg` and `Real.fanoErrorProb_le_one`. +* `Real.condEntropy_le_binEntropy_add_mul_log` — Fano's inequality in the form of N&C eq. (12.16): + `H(X | Y) ≤ binEntropy pₑ + pₑ · log (|ι| − 1)`. +* `Real.condEntropy_le_qaryEntropy` — the same bound packaged as the `|ι|`-ary entropy of `pₑ`. + +## Context + +This is pure classical information theory, a statement about `Real.condEntropy`, `Real.entropy` +and `Real.binEntropy`, built on the joint-entropy and binary-entropy developments. It is the +classical prerequisite for the +converse of Shannon's noisy channel coding theorem (N&C Theorem 12.7, +`ToMathlib/InformationTheory/NoisyChannel.lean`) and for the quantum Fano inequality (N&C Theorem +12.9). + +Entropies are in *nats* (natural logarithm), as elsewhere in the library; N&C measures the binary +entropy `H(pₑ)` and `log (|ι| − 1)` in bits. The inequality is base-independent (both sides scale by +the same `log 2` factor when converting), so this is a faithful reformulation, not a weakening. + +## Proof + +Rather than N&C's chain-rule argument (which introduces an auxiliary error random variable), the +proof here is a single application of Gibbs' inequality +(`Real.entropy_le_cross_entropy_of_sum_le`) to the joint `p` against the comparison distribution + +`qd (x, y) = p_Y(y) · (if x = g y then 1 − pₑ else pₑ / (|ι| − 1))`, + +whose per-`y` conditional puts mass `1 − pₑ` on the guess `g y` and spreads `pₑ` over the other +`|ι| − 1` symbols. The cross-entropy `−∑ p log qd` telescopes to +`H(Y) + binEntropy pₑ + pₑ log(|ι|−1)`, and subtracting `H(Y)` yields the bound. The only division +is by the *constant* `|ι| − 1`, so no +conditioning on `p_Y(y) = 0` is needed. + +The lemma `Real.entropy_le_qaryEntropy` is the *single-distribution* kernel `H(r) ≤ qaryEntropy |ι| +(1 − r i₀)`; its docstring suggests obtaining Fano by averaging that per-symbol bound over the +conditioning variable `Y`. That averaging route is deliberately not taken here: the library has no +`condEntropy p = ∑_y p_Y(y) · H(X | Y = y)` decomposition to average against, and supplying one +means dividing each conditional by `p_Y(y)` (with its `p_Y(y) = 0` edge cases and a Jensen +step). The direct Gibbs route above avoids that machinery and divides only by the constant +`|ι| − 1`, so it is both shorter and division-safe. +-/ + +@[expose] public section + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- The **Fano error probability** of guessing the first coordinate `X` of a joint distribution +`p : ι × κ → ℝ` from the second coordinate `Y` via a guess function `g : κ → ι`: the probability +`p(X ≠ g Y) = 1 − ∑_y p (g y, y)` that the guess `X_tilde = g Y` is incorrect. -/ +noncomputable def fanoErrorProb (p : ι × κ → ℝ) (g : κ → ι) : ℝ := 1 - ∑ y, p (g y, y) + +omit [Fintype ι] in +/-- The Fano error probability is at most `1`. -/ +theorem fanoErrorProb_le_one {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (g : κ → ι) : + fanoErrorProb p g ≤ 1 := by + have : 0 ≤ ∑ y, p (g y, y) := Finset.sum_nonneg fun y _ => hp _ + rw [fanoErrorProb]; linarith + +/-- The Fano error probability is nonnegative (the correct-guess probability `∑_y p (g y, y)` is at +most the total mass `1`). -/ +theorem fanoErrorProb_nonneg {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) (g : κ → ι) : + 0 ≤ fanoErrorProb p g := by + have h1 : ∑ y, p (g y, y) ≤ ∑ y, marginalSnd p y := + Finset.sum_le_sum fun y _ => le_marginalSnd hp (g y) y + rw [sum_marginalSnd, hsum] at h1 + rw [fanoErrorProb]; linarith + +/-- A joint distribution `p : ι × κ → ℝ` of total mass `1` forces its first alphabet to be +nonempty: `1 ≤ Fintype.card ι`. (An empty `ι` empties the joint sum `∑ q, p q`, contradicting +`∑ q, p q = 1`.) The shared kernel of the `|ι| ≥ 1` step in the Fano bounds below, so +`Nonempty ι` need not be assumed. -/ +private theorem one_le_card_of_sum_eq_one {p : ι × κ → ℝ} (hsum : ∑ q, p q = 1) : + 1 ≤ Fintype.card ι := by + rcases Nat.eq_zero_or_pos (Fintype.card ι) with h | h + · have : IsEmpty ι := Fintype.card_eq_zero_iff.mp h + rw [Fintype.sum_prod_type, Finset.univ_eq_empty, Finset.sum_empty] at hsum + exact absurd hsum (by norm_num) + · exact h + +/-- **Fano's inequality** (Nielsen & Chuang, Box 12.2 on p. 536, eq. (12.16)). If we guess the +first coordinate `X` of a joint distribution `p : ι × κ → ℝ` from the second coordinate `Y` via +`X_tilde = g Y`, with error probability `pₑ = Real.fanoErrorProb p g = p(X ≠ g Y)`, then the +conditional +entropy is bounded by + +`H(X | Y) ≤ binEntropy pₑ + pₑ · log (|ι| − 1)`. + +Thus a large conditional entropy forces a large error probability. -/ +theorem condEntropy_le_binEntropy_add_mul_log + {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) (g : κ → ι) : + condEntropy p ≤ binEntropy (fanoErrorProb p g) + + fanoErrorProb p g * Real.log ((Fintype.card ι : ℝ) - 1) := by + classical + have hpe_nonneg := fanoErrorProb_nonneg hp hsum g + have hpe_le_one := fanoErrorProb_le_one hp g + have hcorrect : ∑ y, p (g y, y) = 1 - fanoErrorProb p g := by simp only [fanoErrorProb]; ring + set pe := fanoErrorProb p g with hpe_def + set c : ℝ := (Fintype.card ι : ℝ) - 1 with hc_def + -- `ι` is nonempty (hence `c = |ι| − 1 ≥ 0`), so `Nonempty ι` need not be assumed. + have hcp : 1 ≤ Fintype.card ι := one_le_card_of_sum_eq_one hsum + have hcard1 : (1 : ℝ) ≤ (Fintype.card ι : ℝ) := by exact_mod_cast hcp + have hc_nonneg : 0 ≤ c := by rw [hc_def]; linarith + -- Edge fact: `c = 0` (i.e. `|ι| = 1`) forces `pe = 0` (the sole symbol is always guessed right). + have hc0 : c = 0 → pe = 0 := by + intro hc + have hcard_eq : Fintype.card ι = 1 := by + have h1 : (Fintype.card ι : ℝ) = 1 := by rw [hc_def] at hc; linarith + exact_mod_cast h1 + have : Subsingleton ι := Fintype.card_le_one_iff_subsingleton.mp hcard_eq.le + have hdiag : ∀ z, p (g z, z) = marginalSnd p z := by + intro z + rw [marginalSnd_apply] + refine (Fintype.sum_eq_single (f := fun x => p (x, z)) (g z) ?_).symm + intro x hx + exact absurd (Subsingleton.elim x (g z)) hx + have hsum1 : ∑ z, p (g z, z) = 1 := by simp_rw [hdiag]; rw [sum_marginalSnd, hsum] + rw [hpe_def]; simp only [fanoErrorProb]; rw [hsum1]; ring + -- The comparison distribution. + set r : ι × κ → ℝ := fun xy => if xy.1 = g xy.2 then 1 - pe else pe / c with hr_def + set qd : ι × κ → ℝ := fun xy => marginalSnd p xy.2 * r xy with hqd_def + have hr_nonneg : ∀ xy, 0 ≤ r xy := by + rintro ⟨x, y⟩; simp only [hr_def]; split_ifs + · linarith + · exact div_nonneg hpe_nonneg hc_nonneg + have hqd_nonneg : ∀ xy, 0 ≤ qd xy := by + rintro ⟨x, y⟩; simp only [hqd_def] + exact mul_nonneg (marginalSnd_nonneg hp _) (hr_nonneg _) + -- Support condition: `qd (x, y) = 0 → p (x, y) = 0`. + have hsupp : ∀ xy, qd xy = 0 → p xy = 0 := by + rintro ⟨x, y⟩ hq0 + rcases eq_or_ne (marginalSnd p y) 0 with hms | hms + · have hle' := le_marginalSnd hp x y + rw [hms] at hle' + exact le_antisymm hle' (hp _) + · have hr0 : r (x, y) = 0 := by + have hq' : marginalSnd p y * r (x, y) = 0 := by simp only [hqd_def] at hq0; exact hq0 + rcases mul_eq_zero.mp hq' with h | h + · exact absurd h hms + · exact h + simp only [hr_def] at hr0 + split_ifs at hr0 with hx + · -- `x = g y`, so `1 − pe = 0`, i.e. `pe = 1`: no correct guess has positive mass. + have hpe1 : pe = 1 := by linarith + have hz : ∑ z, p (g z, z) = 0 := by rw [hcorrect, hpe1]; ring + have hgy := (Finset.sum_eq_zero_iff_of_nonneg fun z _ => hp (g z, z)).mp hz y + (Finset.mem_univ y) + rw [hx]; exact hgy + · -- `x ≠ g y`, so `pe / c = 0`, i.e. `pe = 0`: the guess is right a.s. and off-diagonal mass + -- vanishes. + have hpe0 : pe = 0 := by + rcases div_eq_zero_iff.mp hr0 with h | h + · exact h + · exact hc0 h + have hdiag_all : ∀ z, marginalSnd p z = p (g z, z) := by + have hs0 : ∑ z, (marginalSnd p z - p (g z, z)) = 0 := by + rw [Finset.sum_sub_distrib, sum_marginalSnd, hsum, hcorrect, hpe0]; ring + have hnn : ∀ z ∈ Finset.univ, 0 ≤ marginalSnd p z - p (g z, z) := + fun z _ => sub_nonneg.mpr (le_marginalSnd hp (g z) z) + intro z + have := (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hs0 z (Finset.mem_univ z) + linarith + have hoff : ∑ x' ∈ Finset.univ.erase (g y), p (x', y) = 0 := by + rw [Finset.sum_erase_eq_sub (Finset.mem_univ (g y)), ← marginalSnd_apply, hdiag_all y] + ring + exact (Finset.sum_eq_zero_iff_of_nonneg fun x' _ => hp (x', y)).mp hoff x + (Finset.mem_erase.mpr ⟨hx, Finset.mem_univ x⟩) + -- `qd` has total mass at most `1`, since each conditional `∑ₓ r (x, y) ≤ 1`. + have hsumr_le : ∀ y, ∑ x, r (x, y) ≤ 1 := by + intro y + have hre : ∀ x, r (x, y) = pe / c + (if x = g y then (1 - pe) - pe / c else 0) := by + intro x; simp only [hr_def]; split_ifs with hx <;> ring + rw [Finset.sum_congr rfl fun x _ => hre x, Finset.sum_add_distrib, Finset.sum_const, + Finset.sum_ite_eq'] + simp only [Finset.mem_univ, ite_true, Finset.card_univ, nsmul_eq_mul] + have hccancel : ((Fintype.card ι : ℝ) - 1) * (pe / c) ≤ pe := by + rcases eq_or_ne c 0 with hc | hc + · rw [hc0 hc]; simp + · rw [show ((Fintype.card ι : ℝ) - 1) = c from hc_def.symm, mul_div_cancel₀ pe hc] + have hfact : (Fintype.card ι : ℝ) * (pe / c) + ((1 - pe) - pe / c) + = ((Fintype.card ι : ℝ) - 1) * (pe / c) + (1 - pe) := by ring + rw [hfact]; linarith + have hle : ∑ xy, qd xy ≤ ∑ q, p q := by + have hstep : ∑ xy, qd xy ≤ ∑ y, marginalSnd p y := by + simp only [hqd_def] + rw [Fintype.sum_prod_type, Finset.sum_comm] + apply Finset.sum_le_sum + intro y _ + change ∑ x, marginalSnd p y * r (x, y) ≤ marginalSnd p y + rw [← Finset.mul_sum] + exact mul_le_of_le_one_right (marginalSnd_nonneg hp y) (hsumr_le y) + rwa [sum_marginalSnd] at hstep + -- The conditional distribution of the joint over the second coordinate. + have hinner : ∀ y, ∑ x, p (x, y) * Real.log (r (x, y)) + = marginalSnd p y * Real.log (pe / c) + + p (g y, y) * (Real.log (1 - pe) - Real.log (pe / c)) := by + intro y + have hrw : ∀ x, p (x, y) * Real.log (r (x, y)) + = p (x, y) * Real.log (pe / c) + + (if x = g y then p (x, y) * (Real.log (1 - pe) - Real.log (pe / c)) else 0) := by + intro x; simp only [hr_def]; split_ifs with hx <;> ring + rw [Finset.sum_congr rfl fun x _ => hrw x, Finset.sum_add_distrib, ← Finset.sum_mul, + ← marginalSnd_apply, Finset.sum_ite_eq'] + simp only [Finset.mem_univ, ite_true] + -- The pointwise cross-entropy split: `p log qd = p log p_Y + p log r`. + have hpoint : ∀ (x : ι) (y : κ), p (x, y) * Real.log (qd (x, y)) + = p (x, y) * Real.log (marginalSnd p y) + p (x, y) * Real.log (r (x, y)) := by + intro x y + rcases eq_or_ne (p (x, y)) 0 with h0 | h0 + · rw [h0]; ring + · have hpos : (0 : ℝ) < p (x, y) := (hp _).lt_of_ne (Ne.symm h0) + have hms : marginalSnd p y ≠ 0 := ne_of_gt (lt_of_lt_of_le hpos (le_marginalSnd hp x y)) + have hrne : r (x, y) ≠ 0 := by + intro hr0' + refine h0 (hsupp (x, y) ?_) + simp only [hqd_def]; rw [hr0']; ring + simp only [hqd_def] + rw [Real.log_mul hms hrne]; ring + -- Assemble the cross-entropy. + have hcross : (-∑ xy, p xy * Real.log (qd xy)) + = entropy (marginalSnd p) + (binEntropy pe + pe * Real.log c) := by + have hSB : ∑ y, ∑ x, p (x, y) * Real.log (r (x, y)) + = (1 - pe) * Real.log (1 - pe) + pe * Real.log (pe / c) := by + rw [Finset.sum_congr rfl fun y _ => hinner y, Finset.sum_add_distrib, ← Finset.sum_mul, + ← Finset.sum_mul, sum_marginalSnd, hsum, hcorrect] + ring + have hkey : ∑ xy, p xy * Real.log (qd xy) + = (∑ y, marginalSnd p y * Real.log (marginalSnd p y)) + + ((1 - pe) * Real.log (1 - pe) + pe * Real.log (pe / c)) := by + have hsplit : ∑ xy, p xy * Real.log (qd xy) + = (∑ y, ∑ x, p (x, y) * Real.log (marginalSnd p y)) + + (∑ y, ∑ x, p (x, y) * Real.log (r (x, y))) := by + rw [Fintype.sum_prod_type, Finset.sum_comm, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro y _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro x _ + exact hpoint x y + rw [hsplit, hSB] + congr 1 + apply Finset.sum_congr rfl; intro y _ + rw [← Finset.sum_mul, ← marginalSnd_apply] + rw [hkey, neg_add] + congr 1 + · rw [entropy_eq_neg_sum_mul_log] + · have hlogdiv : pe * Real.log (pe / c) = pe * (Real.log pe - Real.log c) := by + rcases eq_or_ne pe 0 with h | h + · rw [h]; ring + · rw [Real.log_div h fun hc => h (hc0 hc)] + rw [binEntropy_eq_negMulLog_add_negMulLog_one_sub] + simp only [Real.negMulLog] + rw [hlogdiv]; ring + -- Gibbs' inequality plus the cross-entropy identity give the bound. + have hgibbs : entropy p ≤ -∑ xy, p xy * Real.log (qd xy) := + entropy_le_cross_entropy_of_sum_le hp hqd_nonneg hsupp hle + rw [hcross] at hgibbs + rw [condEntropy_eq] + linarith + +-- **Fano's inequality**, packaged with the `|ι|`-ary entropy: `H(X | Y) ≤ qaryEntropy |ι| pₑ`, +-- where `pₑ = Real.fanoErrorProb p g` is the probability that the guess `X_tilde = g Y` for `X` is +-- wrong. This is `Real.condEntropy_le_binEntropy_add_mul_log` repackaged via +-- `Real.qaryEntropy_eq_log_add_binEntropy`. +-- +theorem condEntropy_le_qaryEntropy + {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) (g : κ → ι) : + condEntropy p ≤ qaryEntropy (Fintype.card ι) (fanoErrorProb p g) := by + refine (condEntropy_le_binEntropy_add_mul_log hp hsum g).trans (le_of_eq ?_) + rw [qaryEntropy_eq_log_add_binEntropy] + push_cast + ring + +/-- The mutual information equals the first-marginal entropy minus the conditional entropy, +`I(X : Y) = H(X) − H(X | Y)`. A pure rewriting of the definitions (`Real.mutualInfo_eq`, +`Real.condEntropy_eq`); it holds for every `p : ι × κ → ℝ`, with no positivity or normalization +hypothesis. -/ +theorem mutualInfo_eq_entropy_marginalFst_sub_condEntropy (p : ι × κ → ℝ) : + mutualInfo p = entropy (marginalFst p) - condEntropy p := by + rw [mutualInfo_eq, condEntropy_eq]; ring + +/-- **Fano's inequality in mutual-information form.** For a joint distribution `p : ι × κ → ℝ` +(`0 ≤ p`, `∑ p = 1`) and any guess `X_tilde = g Y`, the first-marginal (input) entropy is +controlled by +the mutual information plus a Fano penalty: + +`H(X) ≤ I(X : Y) + log 2 + pₑ · log |ι|`, + +where `pₑ = Real.fanoErrorProb p g`. This is the identity `H(X) = I(X : Y) + H(X | Y)` +(`Real.mutualInfo_eq_entropy_marginalFst_sub_condEntropy`) combined with Fano's inequality +`H(X | Y) ≤ binEntropy pₑ + pₑ · log (|ι| − 1) ≤ log 2 + pₑ · log |ι|` +(`Real.condEntropy_le_binEntropy_add_mul_log`, `Real.binEntropy_le_log_two`). It is the +converse-coding workhorse: a small error probability `pₑ` forces the input entropy `H(X)` down to +essentially the mutual information `I(X : Y)` that the channel actually conveys. -/ +theorem entropy_marginalFst_le_mutualInfo_add + {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) (g : κ → ι) : + entropy (marginalFst p) + ≤ mutualInfo p + Real.log 2 + fanoErrorProb p g * Real.log (Fintype.card ι) := by + have hpe_nonneg := fanoErrorProb_nonneg hp hsum g + have hfano := condEntropy_le_binEntropy_add_mul_log hp hsum g + have hbin : binEntropy (fanoErrorProb p g) ≤ Real.log 2 := binEntropy_le_log_two + -- `|ι| ≥ 1`, so `log (|ι| − 1) ≤ log |ι|`. + have hcard1 : (1 : ℝ) ≤ (Fintype.card ι : ℝ) := by + exact_mod_cast one_le_card_of_sum_eq_one hsum + have hlog_le : Real.log ((Fintype.card ι : ℝ) - 1) ≤ Real.log (Fintype.card ι) := by + rcases eq_or_lt_of_le hcard1 with h | h + · rw [← h]; norm_num + · exact Real.log_le_log (by linarith) (by linarith) + have hmul : fanoErrorProb p g * Real.log ((Fintype.card ι : ℝ) - 1) + ≤ fanoErrorProb p g * Real.log (Fintype.card ι) := + mul_le_mul_of_nonneg_left hlog_le hpe_nonneg + have hI := mutualInfo_eq_entropy_marginalFst_sub_condEntropy p + linarith + +/-- **Fano's converse inequality for a uniform input.** When the first marginal of `p` is uniform +(`marginalFst p i = |ι|⁻¹`, so that `H(X) = log |ι|`), the mutual-information Fano bound +(`Real.entropy_marginalFst_le_mutualInfo_add`) rearranges to + +`(1 − pₑ) · log |ι| ≤ log 2 + I(X : Y)`, + +the per-block converse of the noisy-channel coding theorem (Nielsen & Chuang, eqs. (12.98)– +(12.101)): the reliably conveyable rate `log |ι|` is, up to the error penalty `pₑ · log |ι|` and the +additive `log 2`, no larger than the mutual information the channel provides. -/ +theorem one_sub_fanoErrorProb_mul_log_card_le + {p : ι × κ → ℝ} (hp : ∀ q, 0 ≤ p q) (hsum : ∑ q, p q = 1) + (huniform : ∀ i, marginalFst p i = (Fintype.card ι : ℝ)⁻¹) (g : κ → ι) : + (1 - fanoErrorProb p g) * Real.log (Fintype.card ι) ≤ Real.log 2 + mutualInfo p := by + have hHX : entropy (marginalFst p) = Real.log (Fintype.card ι) := by + have huf : marginalFst p = fun _ : ι => (Fintype.card ι : ℝ)⁻¹ := funext huniform + rw [huf, entropy_uniform] + have h := entropy_marginalFst_le_mutualInfo_add hp hsum g + rw [hHX] at h + have hexpand : (1 - fanoErrorProb p g) * Real.log (Fintype.card ι) + = Real.log (Fintype.card ι) - fanoErrorProb p g * Real.log (Fintype.card ι) := by ring + rw [hexpand]; linarith + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/IIDConcentration.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/IIDConcentration.lean new file mode 100644 index 0000000000..285a81e099 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/IIDConcentration.lean @@ -0,0 +1,164 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy + +/-! +# Concentration of the empirical mean for a finite i.i.d. source + +For a finite type `α` and a function `p : α → ℝ` (a probability mass function when `0 ≤ p x` and +`∑ x, p x = 1`), the **`n`-fold i.i.d. product distribution** assigns to a length-`n` sequence +`s : Fin n → α` the weight `∏ i, p (s i)`. Given an observable `g : α → ℝ` with mean +`m = ∑ x, p x * g x`, this file proves the elementary (Chebyshev) **weak law of large numbers**: +the product-distribution probability that the empirical mean `(∑ i, g (s i)) / n` deviates from +`m` by more than `ε` is at most `(∑ x, p x * (g x - m) ^ 2) / (n * ε ^ 2)`. + +This is the concentration engine behind the theorem of typical sequences +(Nielsen & Chuang, Theorem 12.2 / the classical asymptotic equipartition property): applied to the +surprisal `g x = -Real.log (p x)`, whose mean is the Shannon entropy `Real.entropy p`, it shows +that with high probability a length-`n` sequence has log-probability close to `-n * H`. + +Everything is a finite sum over `Fin n → α`; no measure theory is used. This mirrors the elementary +finite-distribution convention of `ToMathlib/Analysis/SpecialFunctions/ShannonEntropy.lean` (a +distribution is a bare `p : α → ℝ`, hypotheses `0 ≤ p`, `∑ p = 1` supplied to lemmas), and gives a +self-contained, finite-`n`-explicit concentration bound — exactly the form the counting arguments +of the typical-sequence theorem consume. + +## Main results + +- `Real.iid_total_mass`: the total mass `∑ s, ∏ i, p (s i)` equals `(∑ x, p x) ^ n`. +- `Real.iid_centered_sq`: the second-moment identity + `∑ s, (∏ i, p (s i)) * (∑ i, g (s i) - m) ^ 2 = n * ∑ x, p x * (g x - m) ^ 2` + (variance of a sum of `n` i.i.d. terms is `n` times the per-sample variance). +- `Real.iid_average_deviation_le`: the Chebyshev weak law, the concentration bound above. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {α : Type*} [Fintype α] + +/-- Summing a coordinatewise product `∏ i, φ i (s i)` over all length-`n` sequences `s` factors as +the product `∏ i, ∑ x, φ i x` of the coordinatewise sums. -/ +lemma sum_prod_apply_eq_prod_sum {n : ℕ} (φ : Fin n → α → ℝ) : + ∑ s : Fin n → α, ∏ i, φ i (s i) = ∏ i, ∑ x, φ i x := by + classical + rw [Finset.prod_univ_sum, ← Fintype.piFinset_univ] + +/-- The total mass of the `n`-fold i.i.d. product distribution `s ↦ ∏ i, p (s i)` is +`(∑ x, p x) ^ n`. In particular it is `1` when `p` sums to one. -/ +theorem iid_total_mass (p : α → ℝ) (n : ℕ) : + ∑ s : Fin n → α, ∏ i, p (s i) = (∑ x, p x) ^ n := by + rw [sum_prod_apply_eq_prod_sum (fun _ => p), Finset.prod_const, Finset.card_univ, + Fintype.card_fin] + +/-- Split a sum over length-`(n+1)` sequences on the first coordinate: peel off the head via +`Fin.cons`. -/ +private lemma sum_fin_succ {n : ℕ} (F : (Fin (n + 1) → α) → ℝ) : + ∑ s : Fin (n + 1) → α, F s = ∑ a : α, ∑ t : Fin n → α, F (Fin.cons a t) := by + classical + rw [← Equiv.sum_comp (Fin.consEquiv fun _ => α) F, Fintype.sum_prod_type] + rfl + +/-- **Second-moment identity.** For a probability distribution `p` (summing to one) and an +observable `g` with mean `m = ∑ x, p x * g x`, the `p`-`n`-fold-product average of the squared +centered sum `(∑ i, g (s i) - m) ^ 2` equals `n` times the per-sample variance +`∑ x, p x * (g x - m) ^ 2`. Proof by induction on `n`: peeling one coordinate contributes the +variance `∑ x, p x * (g x - m) ^ 2` (diagonal) plus the previous total (via the inductive +hypothesis); the cross term vanishes because the centered mean `∑ x, p x * (g x - m)` is zero. -/ +theorem iid_centered_sq (p g : α → ℝ) (hp1 : ∑ x, p x = 1) + {m : ℝ} (hm : m = ∑ x, p x * g x) (n : ℕ) : + ∑ s : Fin n → α, (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 + = n * ∑ x, p x * (g x - m) ^ 2 := by + classical + have hmass : ∀ k : ℕ, ∑ s : Fin k → α, ∏ i, p (s i) = 1 := fun k => by + rw [iid_total_mass, hp1, one_pow] + have hmean0 : ∑ x, p x * (g x - m) = 0 := by + simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hp1, one_mul, ← hm, sub_self] + induction n with + | zero => simp + | succ n ih => + rw [sum_fin_succ] + have hcons : ∀ (a : α) (t : Fin n → α), + (∏ i, p ((Fin.cons a t : Fin (n + 1) → α) i)) + * (∑ i, (g ((Fin.cons a t : Fin (n + 1) → α) i) - m)) ^ 2 + = p a * (∏ i, p (t i)) * ((g a - m) + ∑ i, (g (t i) - m)) ^ 2 := by + intro a t + rw [Fin.prod_univ_succ, Fin.sum_univ_succ] + simp [Fin.cons_zero, Fin.cons_succ] + simp_rw [hcons] + -- distribute the square into diagonal, cross, and tail parts + have expand : ∀ (a : α) (t : Fin n → α), + p a * (∏ i, p (t i)) * ((g a - m) + ∑ i, (g (t i) - m)) ^ 2 + = (p a * (g a - m) ^ 2) * (∏ i, p (t i)) + + 2 * (p a * (g a - m)) * ((∏ i, p (t i)) * (∑ i, (g (t i) - m))) + + p a * ((∏ i, p (t i)) * (∑ i, (g (t i) - m)) ^ 2) := by + intro a t; ring + simp_rw [expand, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul] + have hcross : ∑ a, 2 * (p a * (g a - m)) = 0 := by + rw [← Finset.mul_sum, hmean0, mul_zero] + rw [hmass n, ih, hp1, hcross] + push_cast + ring + +/-- **Chebyshev weak law of large numbers for a finite i.i.d. source.** With `m = ∑ x, p x * g x` +the mean of the observable `g`, the `n`-fold product-distribution probability that the empirical +mean `(∑ i, g (s i)) / n` deviates from `m` by more than `ε` is at most +`(∑ x, p x * (g x - m) ^ 2) / (n * ε ^ 2)`. -/ +theorem iid_average_deviation_le (p g : α → ℝ) (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {m : ℝ} (hm : m = ∑ x, p x * g x) {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : + ∑ s ∈ univ.filter (fun s : Fin n → α => ε < |(∑ i, g (s i)) / n - m|), ∏ i, p (s i) + ≤ (∑ x, p x * (g x - m) ^ 2) / (n * ε ^ 2) := by + classical + have hnpos : (0 : ℝ) < n := by exact_mod_cast hn + set V := ∑ x, p x * (g x - m) ^ 2 with hVdef + set S := univ.filter (fun s : Fin n → α => ε < |(∑ i, g (s i)) / n - m|) with hSdef + have hsecond : ∑ s : Fin n → α, (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 = n * V := + iid_centered_sq p g hp1 hm n + -- Chebyshev step: `(n·ε)² · P(S) ≤ Σ_S ∏p·(Σ(g−m))² ≤ n·V`. + have hstepA : ((n : ℝ) * ε) ^ 2 * ∑ s ∈ S, ∏ i, p (s i) + ≤ ∑ s ∈ S, (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 := by + rw [Finset.mul_sum] + refine Finset.sum_le_sum fun s hs => ?_ + rw [hSdef, Finset.mem_filter] at hs + obtain ⟨_, hs2⟩ := hs + have hpnn : 0 ≤ ∏ i, p (s i) := Finset.prod_nonneg fun i _ => hp0 _ + have hrw : (∑ i, g (s i)) / (n : ℝ) - m = (∑ i, (g (s i) - m)) / n := by + have hn0 : (n : ℝ) ≠ 0 := hnpos.ne' + rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] + field_simp + rw [hrw, abs_div, abs_of_pos hnpos, lt_div_iff₀ hnpos] at hs2 + have hdev : (n : ℝ) * ε < |∑ i, (g (s i) - m)| := by rw [mul_comm]; exact hs2 + have h2 : ((n : ℝ) * ε) ^ 2 ≤ (∑ i, (g (s i) - m)) ^ 2 := by + nlinarith [sq_abs (∑ i, (g (s i) - m)), abs_nonneg (∑ i, (g (s i) - m)), + mul_pos hnpos hε, hdev] + calc ((n : ℝ) * ε) ^ 2 * ∏ i, p (s i) + ≤ (∑ i, (g (s i) - m)) ^ 2 * ∏ i, p (s i) := mul_le_mul_of_nonneg_right h2 hpnn + _ = (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 := by ring + have hstepB : ∑ s ∈ S, (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 + ≤ ∑ s : Fin n → α, (∏ i, p (s i)) * (∑ i, (g (s i) - m)) ^ 2 := by + refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) ?_ + exact fun s _ _ => mul_nonneg (Finset.prod_nonneg fun i _ => hp0 _) (sq_nonneg _) + have hcheb : ((n : ℝ) * ε) ^ 2 * ∑ s ∈ S, ∏ i, p (s i) ≤ n * V := + (hstepA.trans hstepB).trans_eq hsecond + -- cancel one factor of `n` and rearrange into the divided form. + have hcheb' : ((n : ℝ) * ε ^ 2) * ∑ s ∈ S, ∏ i, p (s i) ≤ V := by + have hrw2 : ((n : ℝ) * ε) ^ 2 * ∑ s ∈ S, ∏ i, p (s i) + = (n : ℝ) * (((n : ℝ) * ε ^ 2) * ∑ s ∈ S, ∏ i, p (s i)) := by ring + rw [hrw2] at hcheb + exact le_of_mul_le_mul_left hcheb hnpos + rw [le_div_iff₀ (by positivity : (0 : ℝ) < (n : ℝ) * ε ^ 2), mul_comm] + exact hcheb' + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/NoiselessCoding.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/NoiselessCoding.lean new file mode 100644 index 0000000000..0ddaaf00b1 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/NoiselessCoding.lean @@ -0,0 +1,334 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.TypicalSequence + +/-! +# Shannon's noiseless channel coding theorem (data compression) + +For a finite alphabet `α` and an i.i.d. classical information source with probability mass function +`p : α → ℝ` (`0 ≤ p x`, `∑ x, p x = 1`), a **rate-`R` compression scheme** at block length `n` +compresses a source sequence `x : Fin n → α` into a bit string of length `⌊n R⌋` and decompresses +it back to a sequence. Following Nielsen & Chuang (p. 540) we model such a scheme as the structure + +`Real.CompressionScheme α n numBits`, + +bundling an `encode : (Fin n → α) → (Fin numBits → Bool)` (their `Cₙ`, mapping to a length-`numBits` +bit string) and a `decode : (Fin numBits → Bool) → (Fin n → α)` (their `Dₙ`), with the intended +`numBits = ⌊n R⌋` (`Nat.floor`, matching N&C's convention `nR := ⌊nR⌋`). Its + +`sch.successProb p = ∑ {x : decode (encode x) = x}, ∏ i, p (x i)` + +is the probability that the source sequence is recovered exactly, `p(Dₙ(Cₙ(x)) = x)`. A scheme +*family* `sch : (n : ℕ) → CompressionScheme α n ⌊n R⌋` is **reliable** when `sch.successProb p → 1` +as `n → ∞`, i.e. `Tendsto (fun n => (sch n).successProb p) atTop (𝓝 1)` — exactly N&C's criterion +that the recovery probability "approaches one". + +**Theorem 12.4 (Shannon's noiseless channel coding theorem).** *For an i.i.d. source with entropy +rate `H(X)`: if `R > H(X)` a reliable rate-`R` compression scheme exists; conversely if `R < H(X)` +no rate-`R` scheme is reliable.* + +## Units + +`Real.entropy p` is the Shannon entropy in **nats** (natural logarithm), whereas N&C's rate `R` and +its `2^{nR}` bit strings are **base 2**. The threshold `H(X) < R` (both in bits) is therefore +written `entropy p < R * Real.log 2` (both in nats): a rate of `R` bits equals `R log 2` nats, and a +length-`⌊nR⌋` bit string encodes `2 ^ ⌊nR⌋ = exp (⌊nR⌋ log 2)` messages. No separate base-`2` +entropy notion is introduced. + +## Main results (this file) + +- `Real.CompressionScheme`: the encode/decode model of a rate-`R` scheme (Nielsen & Chuang, `Cₙ`, + `Dₙ`). +- `Real.CompressionScheme.successProb`: the exact-recovery probability `p(Dₙ(Cₙ(x)) = x)`, with + `successProb_nonneg` and `successProb_le_one` (it is a probability). +- `Real.exists_compressionScheme_sum_typicalSeq_le`: the achievability construction — whenever the + `ε`-typical set fits in the compressed space (`|T(n, ε)| ≤ 2 ^ numBits`), there is a scheme whose + success probability is at least the total probability `∑_{T(n,ε)} ∏ᵢ p` of the typical set + (index the typical sequences into the bit strings; anything typical is recovered). +- `Real.exists_card_typicalSeq_le_two_pow`: for `H + ε < R log 2`, the typical set fits in the + compressed space for all sufficiently large `n` (`|T(n, ε)| ≤ 2 ^ ⌊n R⌋`), from the Eq. 12.28 + upper bound `|T(n, ε)| ≤ exp (n (H + ε))`. +- `Real.exists_reliable_compressionScheme`: **Theorem 12.4, direct part.** If + `entropy p < R log 2` then a reliable rate-`R` compression scheme family exists — its success + probability tends to `1`. +- `Real.CompressionScheme.card_correctlyDecoded_le`: the counting core of the converse — a scheme's + exactly-recovered set has at most `2 ^ numBits` members (`encode` is injective on it). +- `Real.CompressionScheme.successProb_tendsto_zero_of_lt`: **Theorem 12.4, converse + (quantitative).** For a nonnegative bit-rate below the entropy, `0 ≤ R` and `entropy p > R log 2`, + the success probability of *every* rate-`R` scheme family tends to `0`. +- `Real.not_reliable_compressionScheme`: **Theorem 12.4, converse.** Under the same hypotheses no + rate-`R` scheme family is reliable (the success probability does not tend to `1`). + +The converse builds on the small-set bound `Real.exists_sum_prod_le_of_card_le_exp` (Nielsen & +Chuang, Theorem 12.2 (3)): a rate-`R` scheme recovers at most `2 ^ ⌊n R⌋ ≤ exp (n (R log 2))` +sequences exactly, a set of vanishing total probability when `R log 2 < H`. The rate being +nonnegative (`0 ≤ R`) is part of what "rate" means and is genuinely needed — a deterministic source +with a negative "rate" would be a spurious counterexample. +-/ + +@[expose] public section + +open Finset Filter Topology + +namespace Real + +variable {α : Type*} [Fintype α] + +/-- A **rate-`R` compression scheme** for a length-`n` source over the alphabet `α` +(Nielsen & Chuang, p. 540): an `encode` (their `Cₙ`) mapping a source sequence `x : Fin n → α` to a +`numBits`-bit string, and a matching `decode` (their `Dₙ`) mapping bit strings back to sequences. +The intended block-length dependence is `numBits = ⌊n R⌋`, so the compressed space carries `⌊n R⌋` +bits per block. -/ +structure CompressionScheme (α : Type*) (n numBits : ℕ) where + /-- The compression map `Cₙ`: a source sequence is compressed to a `numBits`-bit string. -/ + encode : (Fin n → α) → (Fin numBits → Bool) + /-- The decompression map `Dₙ`: a `numBits`-bit string is decompressed back to a source + sequence. -/ + decode : (Fin numBits → Bool) → (Fin n → α) + +open Classical in +/-- The **success probability** of a compression scheme under the i.i.d. product distribution `p`: +the total probability of the source sequences `x` that are recovered exactly, +`decode (encode x) = x`. This is Nielsen & Chuang's `p(Dₙ(Cₙ(x)) = x)`. -/ +noncomputable def CompressionScheme.successProb (p : α → ℝ) {n numBits : ℕ} + (sch : CompressionScheme α n numBits) : ℝ := + ∑ x ∈ univ.filter (fun x => sch.decode (sch.encode x) = x), ∏ i, p (x i) + +/-- The success probability is nonnegative (it is a sum of products of probabilities). -/ +theorem CompressionScheme.successProb_nonneg (p : α → ℝ) (hp0 : ∀ x, 0 ≤ p x) + {n numBits : ℕ} (sch : CompressionScheme α n numBits) : 0 ≤ sch.successProb p := by + rw [CompressionScheme.successProb] + exact Finset.sum_nonneg fun s _ => Finset.prod_nonneg fun i _ => hp0 _ + +/-- The success probability is at most `1`: the successfully-recovered sequences form a subset of +all sequences, whose total probability is `(∑ x, p x) ^ n = 1`. -/ +theorem CompressionScheme.successProb_le_one (p : α → ℝ) (hp0 : ∀ x, 0 ≤ p x) + (hp1 : ∑ x, p x = 1) {n numBits : ℕ} (sch : CompressionScheme α n numBits) : + sch.successProb p ≤ 1 := by + classical + have htotal : ∑ s : Fin n → α, ∏ i, p (s i) = 1 := by rw [iid_total_mass, hp1, one_pow] + rw [CompressionScheme.successProb, ← htotal] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun s _ _ => Finset.prod_nonneg fun i _ => hp0 _) + +/-- **Achievability construction.** If the `ε`-typical set fits into the compressed space, i.e. +`|T(n, ε)| ≤ 2 ^ numBits`, then there is a compression scheme whose success probability is at least +the total probability `∑_{T(n,ε)} ∏ᵢ p` of the typical set. + +The typical sequences are injected into the `2 ^ numBits` bit strings (`encode`), and `decode` +inverts that injection (any non-image bit string decompresses to an arbitrary fixed guess); every +typical sequence is therefore recovered exactly, so the success set contains `T(n, ε)`. This is the +compression side of Nielsen & Chuang's scheme: store an index of the typical sequence, give up on +the atypical ones. -/ +theorem exists_compressionScheme_sum_typicalSeq_le [Nonempty α] (p : α → ℝ) + (hp0 : ∀ x, 0 ≤ p x) {n numBits : ℕ} {ε : ℝ} + (hcard : (typicalSeq p n ε).card ≤ 2 ^ numBits) : + ∃ sch : CompressionScheme α n numBits, + ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) ≤ sch.successProb p := by + classical + -- Index the typical sequences into the `2 ^ numBits` bit strings. + obtain ⟨e⟩ : Nonempty ({x // x ∈ typicalSeq p n ε} ↪ (Fin numBits → Bool)) := by + apply Function.Embedding.nonempty_of_card_le + rw [Fintype.card_coe, Fintype.card_fun, Fintype.card_fin, Fintype.card_bool] + exact hcard + -- A fixed fallback sequence for atypical inputs / non-image bit strings. + let g0 : Fin n → α := Classical.arbitrary _ + let enc : (Fin n → α) → (Fin numBits → Bool) := + fun x => if h : x ∈ typicalSeq p n ε then e ⟨x, h⟩ else default + let dec : (Fin numBits → Bool) → (Fin n → α) := + fun b => if h : ∃ a : {x // x ∈ typicalSeq p n ε}, e a = b then (h.choose).1 else g0 + refine ⟨⟨enc, dec⟩, ?_⟩ + -- Every typical sequence is recovered exactly, so `T(n, ε)` sits inside the success set. + have hsub : typicalSeq p n ε ⊆ univ.filter (fun x => dec (enc x) = x) := by + intro x hx + rw [mem_filter] + refine ⟨mem_univ _, ?_⟩ + have henc : enc x = e ⟨x, hx⟩ := dite_eq_left hx + have hex : ∃ a : {x // x ∈ typicalSeq p n ε}, e a = e ⟨x, hx⟩ := ⟨⟨x, hx⟩, rfl⟩ + rw [henc, show dec (e ⟨x, hx⟩) = (hex.choose).1 from dite_eq_left hex] + have hchoose : hex.choose = (⟨x, hx⟩ : {x // x ∈ typicalSeq p n ε}) := + e.injective hex.choose_spec + rw [hchoose] + exact Finset.sum_le_sum_of_subset_of_nonneg hsub + (fun s _ _ => Finset.prod_nonneg fun i _ => hp0 _) + +/-- For a rate above the entropy (`H + ε < R log 2`), the `ε`-typical set fits into the compressed +space `2 ^ ⌊n R⌋` for all sufficiently large `n`: `|T(n, ε)| ≤ 2 ^ ⌊n R⌋`. + +By the Eq. 12.28 upper bound `|T(n, ε)| ≤ exp (n (H + ε))`, and `2 ^ ⌊n R⌋ = exp (⌊n R⌋ log 2)` +with `⌊n R⌋ > n R - 1`; the gap `γ = R log 2 - (H + ε) > 0` makes `n (H + ε) < ⌊n R⌋ log 2` once +`n ≥ log 2 / γ`. -/ +theorem exists_card_typicalSeq_le_two_pow (p : α → ℝ) (hp0 : ∀ x, 0 ≤ p x) + (hp1 : ∑ x, p x = 1) {ε R : ℝ} (hHR : entropy p + ε < R * Real.log 2) : + ∃ N : ℕ, ∀ n ≥ N, (typicalSeq p n ε).card ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ := by + set H := entropy p + set γ := R * Real.log 2 - (H + ε) with hγ + have hγpos : 0 < γ := by rw [hγ]; linarith + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + obtain ⟨N, hN⟩ := exists_nat_ge (Real.log 2 / γ) + refine ⟨N, fun n hn => ?_⟩ + have hcard := card_typicalSeq_le hp0 hp1 (n := n) (ε := ε) + have hnge : Real.log 2 / γ ≤ (n : ℝ) := le_trans hN (by exact_mod_cast hn) + have hnγ : Real.log 2 ≤ (n : ℝ) * γ := by rw [div_le_iff₀ hγpos] at hnge; linarith + have hfloor : (n : ℝ) * R - 1 < (⌊(n : ℝ) * R⌋₊ : ℝ) := by + have := Nat.lt_floor_add_one ((n : ℝ) * R); linarith + have hkey : (n : ℝ) * (H + ε) < (⌊(n : ℝ) * R⌋₊ : ℝ) * Real.log 2 := by + have h1 := mul_lt_mul_of_pos_right hfloor hlog2 + nlinarith [hnγ] + have hexp : Real.exp ((n : ℝ) * (H + ε)) < (2 : ℝ) ^ ⌊(n : ℝ) * R⌋₊ := by + have h2 : (2 : ℝ) ^ ⌊(n : ℝ) * R⌋₊ + = Real.exp ((⌊(n : ℝ) * R⌋₊ : ℝ) * Real.log 2) := by + rw [mul_comm, Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + rw [h2]; exact Real.exp_lt_exp.mpr hkey + have hlt := lt_of_le_of_lt hcard hexp + exact_mod_cast le_of_lt hlt + +/-- **Nielsen & Chuang, Theorem 12.4 — direct part (achievability).** If the rate exceeds the +entropy rate, `entropy p < R * Real.log 2` (i.e. `R > H(X)` in bits), then a **reliable** rate-`R` +compression scheme family exists: a family `sch n : CompressionScheme α n ⌊n R⌋` whose success +probability tends to `1` as `n → ∞`. + +Fix `ε = (R log 2 - H)/2 > 0`, so `H + ε < R log 2`. For large `n` the typical set fits in the +compressed space (`exists_card_typicalSeq_le_two_pow`), so the achievability construction +(`exists_compressionScheme_sum_typicalSeq_le`) yields a scheme whose success probability is at least +the typical mass `∑_{T(n,ε)} ∏ᵢ p ≥ 1 - V/(n ε²)` (Theorem 12.2 (1), `sum_typicalSeq_ge`); for +smaller `n` any scheme is used. Squeezing `1 - V/(n ε²) ≤ successProb ≤ 1` with `V/(n ε²) → 0` gives +the limit. -/ +theorem exists_reliable_compressionScheme (p : α → ℝ) + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {R : ℝ} (hR : entropy p < R * Real.log 2) : + ∃ sch : (n : ℕ) → CompressionScheme α n ⌊(n : ℝ) * R⌋₊, + Tendsto (fun n => (sch n).successProb p) atTop (𝓝 1) := by + classical + have hne : Nonempty α := by + rcases isEmpty_or_nonempty α with h | h + · simp only [Finset.univ_eq_empty, Finset.sum_empty] at hp1; norm_num at hp1 + · exact h + set ε := (R * Real.log 2 - entropy p) / 2 with hεdef + have hεpos : 0 < ε := by rw [hεdef]; linarith + have hHε : entropy p + ε < R * Real.log 2 := by rw [hεdef]; linarith + obtain ⟨Ncard, hNcard⟩ := exists_card_typicalSeq_le_two_pow p hp0 hp1 hHε + -- Use the achievability construction where the typical set fits; any scheme otherwise. + let sch : (n : ℕ) → CompressionScheme α n ⌊(n : ℝ) * R⌋₊ := fun n => + if h : (typicalSeq p n ε).card ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ + then (exists_compressionScheme_sum_typicalSeq_le p hp0 h).choose + else ⟨fun _ => default, fun _ => Classical.arbitrary _⟩ + refine ⟨sch, ?_⟩ + set V := ∑ x, p x * (-Real.log (p x) - entropy p) ^ 2 with hVdef + have hlo : ∀ n ≥ max Ncard 1, 1 - V / (n * ε ^ 2) ≤ (sch n).successProb p := by + intro n hn + have hn1 : 0 < n := lt_of_lt_of_le one_pos (le_trans (le_max_right _ _) hn) + have hc : (typicalSeq p n ε).card ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ := + hNcard n (le_trans (le_max_left _ _) hn) + have hsucc : ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) ≤ (sch n).successProb p := by + have hdef : sch n = (exists_compressionScheme_sum_typicalSeq_le p hp0 hc).choose := + dite_eq_left hc + rw [hdef]; exact (exists_compressionScheme_sum_typicalSeq_le p hp0 hc).choose_spec + have hquant := sum_typicalSeq_ge hp0 hp1 hn1 hεpos + linarith + have hhi : ∀ n, (sch n).successProb p ≤ 1 := + fun n => CompressionScheme.successProb_le_one p hp0 hp1 _ + have hlt : Tendsto (fun n : ℕ => 1 - V / (n * ε ^ 2)) atTop (𝓝 1) := by + have hz : Tendsto (fun n : ℕ => V / (n * ε ^ 2)) atTop (𝓝 0) := by + have h1 : Tendsto (fun n : ℕ => (V / ε ^ 2) / n) atTop (𝓝 0) := + tendsto_const_div_atTop_nhds_zero_nat _ + apply h1.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + field_simp + simpa using (tendsto_const_nhds (x := (1 : ℝ))).sub hz + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' hlt tendsto_const_nhds + (eventually_atTop.mpr ⟨max Ncard 1, hlo⟩) (Eventually.of_forall hhi) + +open Classical in +/-- **The counting core of the converse.** The set of source sequences a scheme recovers *exactly* +(`decode (encode x) = x`) has at most `2 ^ numBits` elements. Indeed `encode` is injective on this +set — if `encode x = encode y` for two exactly-recovered `x, y` then +`x = decode (encode x) = decode (encode y) = y` — and it maps into the `2 ^ numBits` bit strings +`Fin numBits → Bool`. So a scheme with a `numBits`-bit codeword can recover at most `2 ^ numBits` +sequences, however clever its `encode`/`decode`. -/ +theorem CompressionScheme.card_correctlyDecoded_le {n numBits : ℕ} + (sch : CompressionScheme α n numBits) : + (univ.filter (fun x => sch.decode (sch.encode x) = x)).card ≤ 2 ^ numBits := by + classical + have hcard : (univ.filter (fun x => sch.decode (sch.encode x) = x)).card + ≤ (univ : Finset (Fin numBits → Bool)).card := + Finset.card_le_card_of_injOn sch.encode (fun a _ => mem_univ _) (by + intro x hx y hy hxy + simp only [mem_coe, mem_filter, mem_univ, true_and] at hx hy + calc x = sch.decode (sch.encode x) := hx.symm + _ = sch.decode (sch.encode y) := by rw [hxy] + _ = y := hy) + simpa [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Fintype.card_bool] using hcard + +/-- **Nielsen & Chuang, Theorem 12.4 — converse, quantitative form.** For a genuine nonnegative +bit-rate below the entropy rate — `0 ≤ R` and `R * Real.log 2 < entropy p` (i.e. `R < H(X)` in bits) +— the success probability of *every* rate-`R` compression scheme family tends to `0`. + +A rate-`R` scheme recovers at most `2 ^ ⌊n R⌋` sequences exactly (`card_correctlyDecoded_le`), and +`2 ^ ⌊n R⌋ = exp (⌊n R⌋ log 2) ≤ exp (n (R log 2))` since `⌊n R⌋ ≤ n R` (`Nat.floor_le`, using +`0 ≤ R`). So its success probability is the total probability of a set of at most +`exp (n (R log 2))` sequences; because `R log 2 < H`, the small-set bound +`exists_sum_prod_le_of_card_le_exp` (Theorem 12.2 (3)) forces that mass eventually below any +`δ > 0`. With `successProb ≥ 0` this squeezes the success probability to `0`. + +The hypothesis `0 ≤ R` is not a weakening — a rate is a number of bits per symbol and is nonnegative +by definition. It is genuinely needed: for a *deterministic* source (`H(X) = 0`) a "rate" `R < 0` +would satisfy `R log 2 < H` yet the single most-probable sequence is recovered with probability `1`, +so the claim fails without it. Once `0 ≤ R` and `R log 2 < H`, necessarily `H > 0`, so the source is +nondeterministic. -/ +theorem CompressionScheme.successProb_tendsto_zero_of_lt (p : α → ℝ) + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {R : ℝ} (hR0 : 0 ≤ R) (hR : R * Real.log 2 < entropy p) + (sch : (n : ℕ) → CompressionScheme α n ⌊(n : ℝ) * R⌋₊) : + Tendsto (fun n => (sch n).successProb p) atTop (𝓝 0) := by + classical + rw [Metric.tendsto_atTop] + intro δ hδ + obtain ⟨N, hNpos, hN⟩ := exists_sum_prod_le_of_card_le_exp hp0 hp1 hR (half_pos hδ) + refine ⟨N, fun n hn => ?_⟩ + -- The success set has at most `2 ^ ⌊n R⌋ ≤ exp (n (R log 2))` members. + have hcardnat : (univ.filter (fun x => (sch n).decode ((sch n).encode x) = x)).card + ≤ 2 ^ ⌊(n : ℝ) * R⌋₊ := (sch n).card_correctlyDecoded_le + have hcard : ((univ.filter (fun x => (sch n).decode ((sch n).encode x) = x)).card : ℝ) + ≤ Real.exp ((n : ℝ) * (R * Real.log 2)) := by + have hlog2 : 0 ≤ Real.log 2 := (Real.log_pos (by norm_num)).le + have hfloor : (⌊(n : ℝ) * R⌋₊ : ℝ) ≤ (n : ℝ) * R := Nat.floor_le (by positivity) + calc ((univ.filter (fun x => (sch n).decode ((sch n).encode x) = x)).card : ℝ) + ≤ ((2 : ℝ) ^ ⌊(n : ℝ) * R⌋₊) := by exact_mod_cast hcardnat + _ = Real.exp ((⌊(n : ℝ) * R⌋₊ : ℝ) * Real.log 2) := by + rw [mul_comm, Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + _ ≤ Real.exp ((n : ℝ) * (R * Real.log 2)) := + Real.exp_le_exp.mpr (by nlinarith [hfloor, hlog2]) + -- The small-set bound then caps the success probability by `δ / 2 < δ`. + have hsucc : (sch n).successProb p ≤ δ / 2 := by + rw [CompressionScheme.successProb]; exact hN n hn _ hcard + have hnonneg : 0 ≤ (sch n).successProb p := (sch n).successProb_nonneg p hp0 + rw [Real.dist_eq, sub_zero, abs_of_nonneg hnonneg] + linarith + +/-- **Nielsen & Chuang, Theorem 12.4 — converse.** For a genuine nonnegative bit-rate below the +entropy rate — `0 ≤ R` and `R * Real.log 2 < entropy p` (i.e. `R < H(X)` in bits) — *no* rate-`R` +compression scheme family is **reliable**: the success probability does not tend to `1`, exactly +N&C's "any compression scheme will not be reliable". + +Immediate from the quantitative converse `successProb_tendsto_zero_of_lt`: the success probability +tends to `0`, so by uniqueness of limits it cannot also tend to `1`. -/ +theorem not_reliable_compressionScheme (p : α → ℝ) + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {R : ℝ} (hR0 : 0 ≤ R) (hR : R * Real.log 2 < entropy p) + (sch : (n : ℕ) → CompressionScheme α n ⌊(n : ℝ) * R⌋₊) : + ¬ Tendsto (fun n => (sch n).successProb p) atTop (𝓝 1) := by + intro hreliable + have hzero := CompressionScheme.successProb_tendsto_zero_of_lt p hp0 hp1 hR0 hR sch + have h10 : (1 : ℝ) = 0 := tendsto_nhds_unique hreliable hzero + norm_num at h10 + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/NoisyChannel.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/NoisyChannel.lean new file mode 100644 index 0000000000..805d8c0c11 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/NoisyChannel.lean @@ -0,0 +1,1113 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.JointEntropy +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.EntropySubadditive +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.DataProcessingInequality +public import LeanPool.AxQM.ToMathlib.InformationTheory.Fano +public import Mathlib.Analysis.Convex.StdSimplex +public import Mathlib.Topology.Order.Compact + +/-! +# Discrete memoryless channels and the information capacity + +For finite input and output alphabets `ι`, `κ` a **discrete memoryless channel** (Nielsen & +Chuang, *Quantum Computation and Quantum Information*, p. 551) is a family of conditional +probabilities `q : ι → κ → ℝ`, `q x y = p(y | x)`, satisfying `q x y ≥ 0` and `∑ y, q x y = 1` +for every input `x` (`Real.IsChannel`). Fed an input distribution `p : ι → ℝ` for a random +variable `X`, the channel produces the joint input–output law +`Real.channelJoint q p (x, y) = p x · q x y` of `(X, Y)`, whose second marginal is the induced +**output distribution** `Real.channelOutput q p y = ∑ x, p x · q x y` of `Y`. + +The **channel mutual information** for input distribution `p` is the mutual information of that +joint law, + +`Real.channelMutualInfo q p := Real.mutualInfo (Real.channelJoint q p) = H(X : Y)`, + +and the **(information) capacity** of the channel is the maximum of `H(X : Y)` over all input +distributions, + +`Real.channelCapacity q := sSup (Real.channelMutualInfo q '' probSimplex ι) = max_{p(x)} H(X : Y)`. + +This is exactly the right-hand side of **Shannon's noisy channel coding theorem** +(N&C Theorem 12.7, eq. (12.67)), + +`C(N) = max_{p(x)} H(X : Y)`, + +whose left-hand side `C(N)` is the *operational* capacity: the supremum of rates achievable by +encoding/decoding schemes with vanishing error. Following N&C (p. 552) a rate `R` is achievable +when there is a family of block codes `ChannelCode ι κ n ⌈2 ^ (n R)⌉` — an encoder `Cₙ` and decoder +`Dₙ` — whose block error probability `Real.ChannelCode.maxErrorProb` (N&C eq. (12.66)) tends to `0`, +and `Real.channelOpCapacity q` is the supremum of the achievable rates. This file develops both the +information-theoretic right-hand side and the operational left-hand side, together with the trivial +converse `channelOpCapacity q ≤ log₂ |ι|`; the coding theorem `C(N) = max_{p(x)} H(X : Y)` +identifying the two — whose proof N&C defers to the quantum HSW theorem of the next section — is +built in subsequent files. + +## Main declarations + +* `Real.IsChannel` — a conditional distribution `q : ι → κ → ℝ` is a channel. +* `Real.channelOutput`, `Real.channelJoint` — the induced output and joint distributions. +* `Real.channelMutualInfo` — `H(X : Y)` for a given input distribution. +* `Real.channelMutualInfo_eq` — `H(X : Y) = H(Y) − ∑ₓ p(x) H(Y | X = x)` (N&C eq. (12.68)). +* `Real.channelMutualInfo_eq_entropy_add_entropy_sub_entropy` — the three-entropy decomposition + `H(X : Y) = H(X) + H(Y) − H(X, Y)`, with `Real.channelJoint_marginalFst` / + `Real.channelJoint_marginalSnd` identifying the joint law's marginals as `p` and `channelOutput`. +* `Real.channelCapacity` — the information capacity `max_{p(x)} H(X : Y)`. +* `Real.exists_isMaxOn_channelMutualInfo` — the capacity is a genuine maximum, attained at some + input distribution: the `max` of eq. (12.67) is well-defined (the simplex is compact and + `channelMutualInfo` is continuous). +* `Real.ChannelCode` — a length-`n`, `M`-message block code (encoder `Cₙ` and decoder `Dₙ`). +* `Real.ChannelCode.maxErrorProb` — the block error probability `max_m p(Dₙ(Y) ≠ m | X = Cₙ(m))` + (N&C eq. (12.66)), with `maxErrorProb_nonneg` / `maxErrorProb_le_one`. +* `Real.IsAchievableRate`, `Real.channelOpCapacity` — achievable rates and the operational capacity + `C(N)`, the supremum of achievable rates, with `channelOpCapacity_nonneg`, `le_channelOpCapacity` + and the trivial converse `channelOpCapacity_le_log_card_div` (`C(N) ≤ log₂ |ι|`). +* `Real.channelMutualInfo_channelSeqProb_le` — the **single-letterization bound** + `H(Xⁿ : Yⁿ) ≤ n · max_{p(x)} H(X : Y)` for the memoryless `n`-use channel `channelSeqProb q`, the + entropy input to the converse half of the coding theorem (with `isChannel_channelSeqProb`, that + the `n`-use channel is itself a channel). +* `Real.ChannelCode.jointLaw` — the joint law of a uniform message `W`, its codeword `Xⁿ = Cₙ(W)` + and the channel output `Yⁿ`, with its uniform message marginal (`entropy_marginalFst_jointLaw`, + `H(W) = log M`), channel `(Xⁿ, Yⁿ)`-marginal (`marginalSnd_jointLaw`) and Markov structure + (`isMarkovChain_jointLaw`). +* `Real.ChannelCode.one_sub_fanoErrorProb_mul_log_le` — the **per-`n` converse inequality** + `(1 − P_barₑ) · log M ≤ log 2 + n · max_{p(x)} H(X : Y)`, combining Fano's inequality, the data + processing inequality and the single-letterization bound on `jointLaw`. + +## Context + +This is pure classical information theory, quantifying over functions `q : ι → κ → ℝ` and +`p : ι → ℝ`, built on the `Real.mutualInfo` development. These declarations are the statement of +N&C Theorem 12.7. + +Entropies are measured in *nats* (natural logarithm), as elsewhere in the library; N&C uses *bits*. +The capacity bound `channelMutualInfo q p ≤ log (card κ)` and the identity (12.68) are +base-independent, so this is a faithful reformulation, not a weakening. +-/ + +@[expose] public section + +namespace Real + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- The probability distributions on a finite type `ι`, as functions `ι → ℝ`: nonnegative weights +summing to `1`. -/ +def probSimplex (ι : Type*) [Fintype ι] : Set (ι → ℝ) := {p | (∀ x, 0 ≤ p x) ∧ ∑ x, p x = 1} + +theorem isClosed_probSimplex (ι : Type*) [Fintype ι] : IsClosed (probSimplex ι) := by + have h : probSimplex ι = (⋂ x, {p : ι → ℝ | 0 ≤ p x}) ∩ {p | ∑ x, p x = 1} := by + ext p + simp [probSimplex] + rw [h] + exact (isClosed_iInter fun x => isClosed_le continuous_const (continuous_apply x)).inter + (isClosed_eq (continuous_finsetSum _ fun x _ => continuous_apply x) continuous_const) + +theorem probSimplex_subset_Icc (ι : Type*) [Fintype ι] : probSimplex ι ⊆ Set.Icc 0 1 := by + classical + refine fun p hp => ⟨fun x => hp.1 x, fun x => ?_⟩ + rw [Pi.one_apply, ← hp.2] + exact Finset.single_le_sum (fun y _ => hp.1 y) (Finset.mem_univ x) + +theorem isCompact_probSimplex (ι : Type*) [Fintype ι] : IsCompact (probSimplex ι) := + isCompact_Icc.of_isClosed_subset (isClosed_probSimplex ι) (probSimplex_subset_Icc ι) + +/-! ### The channel and its induced distributions -/ + +/-- A **discrete memoryless channel** with input alphabet `ι` and output alphabet `κ`: a family of +conditional probabilities `q x y = p(y | x)` that is nonnegative and normalized over the output for +each input (Nielsen & Chuang, p. 551, eqs. (12.64)–(12.65)). -/ +structure IsChannel (q : ι → κ → ℝ) : Prop where + /-- Conditional probabilities are nonnegative. -/ + nonneg : ∀ x y, 0 ≤ q x y + /-- For each input the conditional distribution over outputs sums to one. -/ + row_sum : ∀ x, ∑ y, q x y = 1 + +/-- The **output distribution** `p_Y(y) = ∑ₓ p(x) q(y | x)` induced by feeding a channel `q` an +input distribution `p`. -/ +noncomputable def channelOutput (q : ι → κ → ℝ) (p : ι → ℝ) : κ → ℝ := fun y => ∑ x, p x * q x y + +omit [Fintype κ] in +@[simp] theorem channelOutput_apply (q : ι → κ → ℝ) (p : ι → ℝ) (y : κ) : + channelOutput q p y = ∑ x, p x * q x y := rfl + +/-- The **joint input–output distribution** `p_{XY}(x, y) = p(x) q(y | x)` of the input random +variable `X` and the channel output `Y`. -/ +noncomputable def channelJoint (q : ι → κ → ℝ) (p : ι → ℝ) : ι × κ → ℝ := + fun xy => p xy.1 * q xy.1 xy.2 + +omit [Fintype ι] [Fintype κ] in +@[simp] theorem channelJoint_apply (q : ι → κ → ℝ) (p : ι → ℝ) (xy : ι × κ) : + channelJoint q p xy = p xy.1 * q xy.1 xy.2 := rfl + +omit [Fintype κ] in +/-- The second marginal of the joint law is the output distribution. -/ +theorem channelJoint_marginalSnd (q : ι → κ → ℝ) (p : ι → ℝ) : + marginalSnd (channelJoint q p) = channelOutput q p := by + funext y; rfl + +omit [Fintype ι] in +/-- The first marginal of the joint law is the input distribution `p`: summing `p(x) q(y | x)` over +the output leaves `p(x) · ∑_y q(y | x) = p(x)`, using that each channel row sums to `1`. -/ +theorem channelJoint_marginalFst {q : ι → κ → ℝ} (hN : IsChannel q) (p : ι → ℝ) : + marginalFst (channelJoint q p) = p := by + funext x + calc marginalFst (channelJoint q p) x + = ∑ y, p x * q x y := by simp_rw [marginalFst_apply, channelJoint_apply] + _ = p x * ∑ y, q x y := by rw [Finset.mul_sum] + _ = p x := by rw [hN.row_sum, mul_one] + +omit [Fintype ι] in +/-- The joint distribution `p(x) q(y | x)` is nonnegative when the input distribution is. -/ +theorem channelJoint_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) : ∀ xy, 0 ≤ channelJoint q p xy := + fun xy => mul_nonneg (hp0 xy.1) (hN.nonneg xy.1 xy.2) + +/-- The output distribution is nonnegative when the input distribution is. -/ +theorem channelOutput_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) : ∀ y, 0 ≤ channelOutput q p y := + fun y => Finset.sum_nonneg fun x _ => mul_nonneg (hp0 x) (hN.nonneg x y) + +/-- The joint distribution `p(x) q(y | x)` is normalized when the input distribution is. -/ +theorem sum_channelJoint {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp1 : ∑ x, p x = 1) : ∑ xy, channelJoint q p xy = 1 := by + rw [Fintype.sum_prod_type] + calc ∑ x, ∑ y, channelJoint q p (x, y) + = ∑ x, p x * ∑ y, q x y := by simp_rw [channelJoint_apply, Finset.mul_sum] + _ = ∑ x, p x := by simp_rw [hN.row_sum, mul_one] + _ = 1 := hp1 + +/-- The output distribution is normalized when the input distribution is. -/ +theorem sum_channelOutput {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp1 : ∑ x, p x = 1) : ∑ y, channelOutput q p y = 1 := by + calc ∑ y, channelOutput q p y + = ∑ x, ∑ y, p x * q x y := by simp_rw [channelOutput_apply]; rw [Finset.sum_comm] + _ = ∑ x, p x * ∑ y, q x y := by simp_rw [Finset.mul_sum] + _ = ∑ x, p x := by simp_rw [hN.row_sum, mul_one] + _ = 1 := hp1 + +/-- The output distribution of a channel fed an input distribution in the input simplex lies in the +output simplex: it is nonnegative and normalized. -/ +theorem channelOutput_mem_probSimplex {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp : p ∈ probSimplex ι) : channelOutput q p ∈ probSimplex κ := + ⟨channelOutput_nonneg hN hp.1, sum_channelOutput hN hp.2⟩ + +/-! ### Channel mutual information -/ + +/-- The **channel mutual information** `H(X : Y)` between a channel `q`'s input `X`, distributed as +`p`, and its output `Y`: the mutual information of the joint input–output law. -/ +noncomputable def channelMutualInfo (q : ι → κ → ℝ) (p : ι → ℝ) : ℝ := + mutualInfo (channelJoint q p) + +/-- **Mutual information as output entropy minus noise entropy** (Nielsen & Chuang eq. (12.68)): +`H(X : Y) = H(Y) − ∑ₓ p(x) H(Y | X = x)`, where `H(Y)` is the output entropy and each `H(Y | X = x)` +is the entropy of the channel's conditional distribution `q(· | x)`. -/ +theorem channelMutualInfo_eq (q : ι → κ → ℝ) {p : ι → ℝ} (hq : ∀ x, ∑ y, q x y = 1) : + channelMutualInfo q p = entropy (channelOutput q p) - ∑ x, p x * entropy (q x) := + mutualInfo_prod_conditional p q hq + +/-- **Mutual information as the three-entropy decomposition** `H(X : Y) = H(X) + H(Y) − H(X, Y)`: +the input entropy plus the output entropy minus the joint entropy. This is the channel form of +`mutualInfo_eq`, obtained by identifying the two marginals of the joint law `channelJoint q p` as +the input distribution `p` (`channelJoint_marginalFst`) and the output distribution +`channelOutput q p` (`channelJoint_marginalSnd`). -/ +theorem channelMutualInfo_eq_entropy_add_entropy_sub_entropy {q : ι → κ → ℝ} (hN : IsChannel q) + (p : ι → ℝ) : + channelMutualInfo q p + = entropy p + entropy (channelOutput q p) - entropy (channelJoint q p) := by + unfold channelMutualInfo + rw [mutualInfo_eq, channelJoint_marginalFst hN, channelJoint_marginalSnd] + +/-- The channel mutual information is nonnegative: `0 ≤ H(X : Y)`. -/ +theorem channelMutualInfo_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) : 0 ≤ channelMutualInfo q p := + mutualInfo_nonneg (channelJoint_nonneg hN hp0) (sum_channelJoint hN hp1) + +/-- The channel mutual information is at most the logarithm of the output alphabet size: +`H(X : Y) ≤ H(Y) ≤ log |κ|`. -/ +theorem channelMutualInfo_le_log_card [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) : + channelMutualInfo q p ≤ Real.log (Fintype.card κ) := + calc channelMutualInfo q p + ≤ entropy (marginalSnd (channelJoint q p)) := + mutualInfo_le_marginalSnd (channelJoint_nonneg hN hp0) + _ = entropy (channelOutput q p) := by rw [channelJoint_marginalSnd] + _ ≤ Real.log (Fintype.card κ) := + entropy_le_log_card (channelOutput_nonneg hN hp0) (sum_channelOutput hN hp1) + +/-- The channel mutual information is a continuous function of the input distribution. -/ +theorem continuous_channelMutualInfo (q : ι → κ → ℝ) : Continuous (channelMutualInfo q) := by + have h : Continuous (channelJoint q) := by + unfold channelJoint + exact continuous_pi fun xy => (continuous_apply xy.1).mul continuous_const + exact continuous_mutualInfo.comp h + +/-! ### The information capacity -/ + +/-- The **information capacity** of a channel `q`: the maximum of the mutual information `H(X : Y)` +over all input distributions `p`, i.e. the right-hand side `max_{p(x)} H(X : Y)` of Shannon's noisy +channel coding theorem (Nielsen & Chuang Theorem 12.7, eq. (12.67)). -/ +noncomputable def channelCapacity (q : ι → κ → ℝ) : ℝ := + sSup (channelMutualInfo q '' probSimplex ι) + +/-- The uniform distribution lies in the standard simplex; a witness that the simplex (hence the set +of achievable mutual informations) is nonempty, and the canonical maximizer for capacities attained +at the uniform input. -/ +theorem uniform_mem_probSimplex [Nonempty ι] : + (fun _ : ι => (Fintype.card ι : ℝ)⁻¹) ∈ probSimplex ι := by + refine ⟨fun _ => by positivity, ?_⟩ + rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + exact mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero) + +/-- The set of achievable mutual informations is bounded above by `log |κ|`. -/ +private theorem bddAbove_channelMutualInfo_image [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) : + BddAbove (channelMutualInfo q '' probSimplex ι) := by + refine ⟨Real.log (Fintype.card κ), ?_⟩ + rintro z ⟨p, hp, rfl⟩ + exact channelMutualInfo_le_log_card hN hp.1 hp.2 + +/-- The capacity is an upper bound for the mutual information of every input distribution. -/ +theorem le_channelCapacity [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) {p : ι → ℝ} + (hp : p ∈ probSimplex ι) : channelMutualInfo q p ≤ channelCapacity q := + le_csSup (bddAbove_channelMutualInfo_image hN) ⟨p, hp, rfl⟩ + +/-- **Upper bound for the capacity.** If the channel mutual information is bounded by `C` for every +input distribution in the simplex, then the capacity is bounded by `C`. -/ +theorem channelCapacity_le [Nonempty ι] {q : ι → κ → ℝ} {C : ℝ} + (h : ∀ p ∈ probSimplex ι, channelMutualInfo q p ≤ C) : channelCapacity q ≤ C := by + refine csSup_le ⟨_, _, uniform_mem_probSimplex, rfl⟩ ?_ + rintro z ⟨p, hp, rfl⟩ + exact h p hp + +/-- The capacity is bounded above by the logarithm of the output alphabet size. -/ +theorem channelCapacity_le_log_card [Nonempty ι] [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) : + channelCapacity q ≤ Real.log (Fintype.card κ) := by + refine csSup_le ⟨_, _, uniform_mem_probSimplex, rfl⟩ ?_ + rintro z ⟨p, hp, rfl⟩ + exact channelMutualInfo_le_log_card hN hp.1 hp.2 + +/-- The capacity is nonnegative. -/ +theorem channelCapacity_nonneg [Nonempty ι] [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) : + 0 ≤ channelCapacity q := + le_trans + (channelMutualInfo_nonneg hN uniform_mem_probSimplex.1 uniform_mem_probSimplex.2) + (le_channelCapacity hN uniform_mem_probSimplex) + +/-- **The capacity as an attained maximum.** If the channel mutual information `channelMutualInfo q` +attains its maximum over the input simplex at `p₀` (an `IsMaxOn`), then the capacity equals that +maximal value `channelMutualInfo q p₀`. This packages the two-sided `sSup` argument — the `csSup_le` +upper bound and the `le_channelCapacity` attainment — once, so a concrete capacity computation +reduces to exhibiting a maximizer; it composes directly with `exists_isMaxOn_channelMutualInfo`, +which produces such a maximizer. -/ +theorem channelCapacity_eq_of_isMaxOn [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) {p₀ : ι → ℝ} + (hp₀ : p₀ ∈ probSimplex ι) (hmax : IsMaxOn (channelMutualInfo q) (probSimplex ι) p₀) : + channelCapacity q = channelMutualInfo q p₀ := by + refine le_antisymm ?_ (le_channelCapacity hN hp₀) + refine csSup_le ⟨_, ⟨p₀, hp₀, rfl⟩⟩ ?_ + rintro z ⟨p, hp, rfl⟩ + exact isMaxOn_iff.mp hmax p hp + +/-- **The capacity is a genuine maximum** (Nielsen & Chuang eq. (12.67), the `max_{p(x)}`): there is +an input distribution `p` in the simplex at which the mutual information `H(X : Y)` attains its +supremum, so `channelCapacity q = channelMutualInfo q p` and `p` maximizes `channelMutualInfo q` +over the simplex. The maximum exists because the simplex of input distributions is compact and +`channelMutualInfo q` is continuous. -/ +theorem exists_isMaxOn_channelMutualInfo [Nonempty ι] (q : ι → κ → ℝ) : + ∃ p ∈ probSimplex ι, IsMaxOn (channelMutualInfo q) (probSimplex ι) p ∧ + channelCapacity q = channelMutualInfo q p := by + obtain ⟨p, hp, hmax⟩ := (isCompact_probSimplex ι).exists_isMaxOn + ⟨_, uniform_mem_probSimplex⟩ (continuous_channelMutualInfo q).continuousOn + refine ⟨p, hp, hmax, ?_⟩ + have hg : IsGreatest (channelMutualInfo q '' probSimplex ι) (channelMutualInfo q p) := + ⟨⟨p, hp, rfl⟩, by rintro z ⟨p', hp', rfl⟩; exact isMaxOn_iff.mp hmax p' hp'⟩ + exact hg.csSup_eq + +/-! ### Operational capacity: block codes, error probability, and achievable rates -/ + +section OperationalCapacity +open Finset Filter Topology + +variable {n M : ℕ} + +/-- A **block code** for `n` uses of a channel with input alphabet `ι`, output alphabet `κ` and `M` +messages (Nielsen & Chuang, p. 551): an `encode` (their `Cₙ`) assigning to each of the `M` messages +an input string `Fin n → ι` to be sent through `n` uses of the channel, and a `decode` (their `Dₙ`) +assigning a message to every possible output string `Fin n → κ`. The intended dependence of the +message count on the rate `R` is `M = ⌈2 ^ (n R)⌉`. -/ +structure ChannelCode (ι κ : Type*) (n M : ℕ) where + /-- The encoding map `Cₙ`: each message is assigned an input codeword of length `n`. -/ + encode : Fin M → (Fin n → ι) + /-- The decoding map `Dₙ`: each length-`n` output string is decoded to a message. -/ + decode : (Fin n → κ) → Fin M + +/-- The **memoryless `n`-use transition probability** `p(y | x) = ∏ⱼ q(yⱼ | xⱼ)` of receiving the +output string `y : Fin n → κ` given the input string `x : Fin n → ι`, for a channel `q` used `n` +times. The channel is memoryless, so the `n` uses are independent and the joint conditional +probability factorizes. -/ +noncomputable def channelSeqProb (q : ι → κ → ℝ) (x : Fin n → ι) (y : Fin n → κ) : ℝ := + ∏ j, q (x j) (y j) + +omit [Fintype ι] in +/-- The memoryless `n`-use transition probability is nonnegative for a channel. -/ +theorem channelSeqProb_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) (x : Fin n → ι) (y : Fin n → κ) : + 0 ≤ channelSeqProb q x y := + Finset.prod_nonneg fun _ _ => hN.nonneg _ _ + +omit [Fintype ι] in +/-- For a channel, the memoryless `n`-use law is a probability distribution over the output strings: +`∑_y ∏ⱼ q(yⱼ | xⱼ) = ∏ⱼ (∑_{yⱼ} q(yⱼ | xⱼ)) = 1`. -/ +theorem sum_channelSeqProb {q : ι → κ → ℝ} (hN : IsChannel q) (x : Fin n → ι) : + ∑ y : Fin n → κ, channelSeqProb q x y = 1 := by + unfold channelSeqProb + rw [← Fintype.piFinset_univ, ← Finset.prod_univ_sum] + simp [hN.row_sum] + +/-- The **conditional block-error probability** for message `m` under channel `q`: the probability +`p(Dₙ(Y) ≠ m | X = Cₙ(m))` that the decoded channel output differs from `m`, given that the codeword +`code.encode m` was fed through `n` uses of the channel. -/ +noncomputable def ChannelCode.condErrorProb (q : ι → κ → ℝ) (code : ChannelCode ι κ n M) + (m : Fin M) : ℝ := + ∑ y ∈ univ.filter (fun y => code.decode y ≠ m), channelSeqProb q (code.encode m) y + +omit [Fintype ι] in +/-- The conditional block-error probability is nonnegative. -/ +theorem ChannelCode.condErrorProb_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (m : Fin M) : 0 ≤ code.condErrorProb q m := + Finset.sum_nonneg fun _ _ => channelSeqProb_nonneg hN _ _ + +omit [Fintype ι] in +/-- The conditional block-error probability is at most `1`: the erroneous outputs form a subset of +all outputs, whose total probability is `1`. -/ +theorem ChannelCode.condErrorProb_le_one {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (m : Fin M) : code.condErrorProb q m ≤ 1 := by + rw [ChannelCode.condErrorProb, ← sum_channelSeqProb hN (code.encode m)] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + fun y _ _ => channelSeqProb_nonneg hN _ _ + +/-- The **block error probability** of a code (Nielsen & Chuang, eq. (12.66)): +`p(Cₙ, Dₙ) = max_m p(Dₙ(Y) ≠ m | X = Cₙ(m))`, the maximum of the conditional error probability over +all messages. (For an empty message set the supremum is `0`.) -/ +noncomputable def ChannelCode.maxErrorProb (q : ι → κ → ℝ) (code : ChannelCode ι κ n M) : ℝ := + ⨆ m, code.condErrorProb q m + +omit [Fintype ι] in +/-- The block error probability is nonnegative. -/ +theorem ChannelCode.maxErrorProb_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : 0 ≤ code.maxErrorProb q := + Real.iSup_nonneg fun m => code.condErrorProb_nonneg hN m + +omit [Fintype ι] in +/-- The block error probability is at most `1`. -/ +theorem ChannelCode.maxErrorProb_le_one {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : code.maxErrorProb q ≤ 1 := + Real.iSup_le (fun m => code.condErrorProb_le_one hN m) (by norm_num) + +omit [Fintype ι] in +/-- Each conditional error probability is bounded by the block error probability. -/ +theorem ChannelCode.condErrorProb_le_maxErrorProb (q : ι → κ → ℝ) (code : ChannelCode ι κ n M) + (m : Fin M) : code.condErrorProb q m ≤ code.maxErrorProb q := + le_ciSup (Set.Finite.bddAbove (Set.finite_range _)) m + +/-- **Trivial converse / pigeonhole bound.** If a code has more messages than there are input +strings, `|ι|ⁿ < M`, then two distinct messages share the same codeword; the channel output cannot +distinguish them, so the block error probability is at least `1/2`. + +Concretely, if `code.encode m₁ = code.encode m₂` with `m₁ ≠ m₂`, then the two conditional error +sets `{y : Dₙ(y) ≠ m₁}` and `{y : Dₙ(y) ≠ m₂}` cover all outputs (a single decoded message differs +from at least one of `m₁, m₂`), so with the shared codeword's output law of total mass `1` the two +conditional error probabilities sum to at least `1`, forcing the larger — hence the maximum — to be +at least `1/2`. -/ +theorem ChannelCode.half_le_maxErrorProb_of_card_lt {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (hlt : Fintype.card ι ^ n < M) : + 1 / 2 ≤ code.maxErrorProb q := by + classical + -- Two distinct messages share a codeword (pigeonhole: `M` messages, `|ι|ⁿ` codewords). + obtain ⟨m₁, m₂, hne, heq⟩ : ∃ m₁ m₂ : Fin M, m₁ ≠ m₂ ∧ code.encode m₁ = code.encode m₂ := by + have hcard : Fintype.card (Fin n → ι) < Fintype.card (Fin M) := by + rw [Fintype.card_fun, Fintype.card_fin, Fintype.card_fin]; exact hlt + exact Fintype.exists_ne_map_eq_of_card_lt code.encode hcard + -- The two conditional error sets cover every output. + have hcover : (univ.filter (fun y : Fin n → κ => code.decode y ≠ m₁)) ∪ + (univ.filter (fun y => code.decode y ≠ m₂)) = univ := by + rw [← Finset.filter_or] + refine Finset.filter_true_of_mem fun y _ => ?_ + rcases eq_or_ne (code.decode y) m₁ with h | h + · exact Or.inr (h ▸ hne) + · exact Or.inl h + -- The two conditional error probabilities sum to at least the total mass `1`. + have hkey : (1 : ℝ) ≤ code.condErrorProb q m₁ + code.condErrorProb q m₂ := by + have hP2 : ∀ y, channelSeqProb q (code.encode m₂) y = channelSeqProb q (code.encode m₁) y := + fun y => by rw [heq] + rw [ChannelCode.condErrorProb, ChannelCode.condErrorProb] + simp_rw [hP2] + set f := fun y => channelSeqProb q (code.encode m₁) y with hf + set s₁ := univ.filter (fun y : Fin n → κ => code.decode y ≠ m₁) with hs₁ + set s₂ := univ.filter (fun y : Fin n → κ => code.decode y ≠ m₂) with hs₂ + have hunion := Finset.sum_union_inter (s₁ := s₁) (s₂ := s₂) (f := f) + have hinter : 0 ≤ ∑ y ∈ s₁ ∩ s₂, f y := + Finset.sum_nonneg fun _ _ => channelSeqProb_nonneg hN _ _ + have htot : ∑ y ∈ s₁ ∪ s₂, f y = 1 := by + rw [hcover, hf]; exact sum_channelSeqProb hN (code.encode m₁) + rw [htot] at hunion + linarith + -- Hence the maximum of the two is at least `1/2`. + have h1 := code.condErrorProb_le_maxErrorProb q m₁ + have h2 := code.condErrorProb_le_maxErrorProb q m₂ + linarith + +omit [Fintype ι] in +/-- A code whose message set has at most one element (`M ≤ 1`) has block error probability `0`: +there is no message to confuse the sole message with, so every output decodes correctly. -/ +theorem ChannelCode.maxErrorProb_eq_zero_of_le_one {q : ι → κ → ℝ} + (code : ChannelCode ι κ n M) (hM : M ≤ 1) : code.maxErrorProb q = 0 := by + have hsub : ∀ a b : Fin M, a = b := fun a b => by + have := a.isLt; have := b.isLt; ext; omega + have hcond : ∀ m, code.condErrorProb q m = 0 := by + intro m + have hempty : univ.filter (fun y : Fin n → κ => code.decode y ≠ m) = ∅ := by + rw [Finset.filter_eq_empty_iff] + exact fun y _ => not_not.mpr (hsub _ _) + rw [ChannelCode.condErrorProb, hempty, Finset.sum_empty] + simp [ChannelCode.maxErrorProb, hcond] + +/-- A rate `R` (in bits) is **achievable** for a channel `q` when there is a family of block codes +`codeₙ : ChannelCode ι κ n ⌈2 ^ (n R)⌉`, one per block length `n`, whose block error probability +`maxErrorProb` tends to `0` as `n → ∞` (Nielsen & Chuang, p. 552). The message count +`⌈exp (n · R · log 2)⌉₊` is `⌈2 ^ (n R)⌉` — at least `2 ^ (n R)` messages, corresponding to a rate +of `R` bits per channel use over `n` uses. -/ +def IsAchievableRate (q : ι → κ → ℝ) (R : ℝ) : Prop := + ∃ code : (n : ℕ) → ChannelCode ι κ n ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊, + Tendsto (fun n => (code n).maxErrorProb q) atTop (𝓝 0) + +omit [Fintype ι] in +/-- Rate `0` is achievable (with a single-message code every output decodes correctly). -/ +theorem isAchievableRate_zero [Nonempty ι] (q : ι → κ → ℝ) : IsAchievableRate q 0 := by + have hle : ∀ n : ℕ, ⌈Real.exp ((n : ℝ) * 0 * Real.log 2)⌉₊ ≤ 1 := by + intro n; simp + have hpos : ∀ n : ℕ, 0 < ⌈Real.exp ((n : ℝ) * 0 * Real.log 2)⌉₊ := + fun n => Nat.ceil_pos.mpr (Real.exp_pos _) + refine ⟨fun n => ⟨fun _ _ => Classical.arbitrary ι, fun _ => ⟨0, hpos n⟩⟩, ?_⟩ + exact tendsto_const_nhds.congr fun n => + (ChannelCode.maxErrorProb_eq_zero_of_le_one _ (hle n)).symm + +/-- The **operational capacity** `C(N)` of a channel `q`: the supremum of all achievable rates +(Nielsen & Chuang, p. 552). Shannon's noisy channel coding theorem (Theorem 12.7) identifies this +with the information capacity `channelCapacity q = max_{p(x)} H(X : Y)`. -/ +noncomputable def channelOpCapacity (q : ι → κ → ℝ) : ℝ := + sSup {R | IsAchievableRate q R} + +/-- Every achievable rate is at most `log |ι| / log 2 = log₂ |ι|` (the trivial converse): a rate `R` +strictly above this would require, for every `n ≥ 1`, more than `|ι|ⁿ` messages, so the pigeonhole +bound forces block error `≥ 1/2`, contradicting that the error tends to `0`. -/ +private theorem isAchievableRate_le [Nonempty ι] {q : ι → κ → ℝ} (hN : IsChannel q) {R : ℝ} + (hR : IsAchievableRate q R) : R ≤ Real.log (Fintype.card ι) / Real.log 2 := by + obtain ⟨code, hcode⟩ := hR + by_contra hcon + rw [not_le] at hcon + have hlog2 : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hcardpos : (0 : ℝ) < Fintype.card ι := by exact_mod_cast Fintype.card_pos + have hlogcard : Real.log (Fintype.card ι) < R * Real.log 2 := by + rw [div_lt_iff₀ hlog2] at hcon; linarith + -- For every `n ≥ 1` the message count exceeds `|ι|ⁿ`, so block error is `≥ 1/2`. + have hhalf : ∀ n : ℕ, 1 ≤ n → (1 : ℝ) / 2 ≤ (code n).maxErrorProb q := by + intro n hn + apply ChannelCode.half_le_maxErrorProb_of_card_lt hN (code n) + rw [Nat.lt_ceil] + push_cast + have e1 : Real.exp ((n : ℝ) * Real.log (Fintype.card ι)) = ((Fintype.card ι : ℝ)) ^ n := by + rw [Real.exp_nat_mul, Real.exp_log hcardpos] + rw [← e1] + refine Real.exp_lt_exp.mpr ?_ + have hpos_n : (0 : ℝ) < (n : ℝ) := by exact_mod_cast Nat.lt_of_lt_of_le Nat.zero_lt_one hn + calc (n : ℝ) * Real.log (Fintype.card ι) + < (n : ℝ) * (R * Real.log 2) := mul_lt_mul_of_pos_left hlogcard hpos_n + _ = (n : ℝ) * R * Real.log 2 := by ring + exact absurd (ge_of_tendsto hcode (eventually_atTop.mpr ⟨1, hhalf⟩)) (by norm_num) + +omit [Fintype ι] in +/-- The set of achievable rates is bounded above (by `log₂ |ι|`), so the operational capacity is a +well-defined supremum. -/ +private theorem bddAbove_setOf_isAchievableRate [Finite ι] [Nonempty ι] {q : ι → κ → ℝ} + (hN : IsChannel q) : BddAbove {R | IsAchievableRate q R} := by + have := Fintype.ofFinite ι + exact ⟨Real.log (Fintype.card ι) / Real.log 2, fun _ hR => isAchievableRate_le hN hR⟩ + +omit [Fintype ι] in +/-- Every achievable rate is at most the operational capacity. -/ +theorem le_channelOpCapacity [Finite ι] [Nonempty ι] {q : ι → κ → ℝ} (hN : IsChannel q) {R : ℝ} + (hR : IsAchievableRate q R) : R ≤ channelOpCapacity q := + le_csSup (bddAbove_setOf_isAchievableRate hN) hR + +omit [Fintype ι] in +/-- The operational capacity is nonnegative (rate `0` is achievable). -/ +theorem channelOpCapacity_nonneg [Finite ι] [Nonempty ι] {q : ι → κ → ℝ} (hN : IsChannel q) : + 0 ≤ channelOpCapacity q := + le_channelOpCapacity hN (isAchievableRate_zero q) + +/-- **Trivial converse.** The operational capacity is at most `log |ι| / log 2 = log₂ |ι|`, the +base-2 logarithm of the input alphabet size: you cannot reliably transmit more than `log₂ |ι|` bits +per channel use. (Shannon's theorem refines this to `max_{p(x)} H(X : Y) ≤ log₂ |ι|`.) -/ +theorem channelOpCapacity_le_log_card_div [Nonempty ι] {q : ι → κ → ℝ} (hN : IsChannel q) : + channelOpCapacity q ≤ Real.log (Fintype.card ι) / Real.log 2 := + csSup_le ⟨0, isAchievableRate_zero q⟩ fun _ hR => isAchievableRate_le hN hR + +/-! ### Single-letterization of the channel mutual information -/ + +omit [Fintype ι] in +/-- The **memoryless `n`-use channel is itself a channel**: `channelSeqProb q`, with input alphabet +`Fin n → ι` and output alphabet `Fin n → κ`, is nonnegative and normalized over its output strings +(`channelSeqProb_nonneg`, `sum_channelSeqProb`). -/ +theorem isChannel_channelSeqProb {q : ι → κ → ℝ} (hN : IsChannel q) : + IsChannel (channelSeqProb q (n := n)) where + nonneg x y := channelSeqProb_nonneg hN x y + row_sum x := sum_channelSeqProb hN x + +omit [Fintype ι] in +/-- **Marginalizing the memoryless product law over every output coordinate except the `j`-th** +leaves the single-use conditional distribution `q(· | xⱼ)`: for a fixed input string `x`, +`∑_{y : yⱼ = b} ∏ᵢ q(yᵢ | xᵢ) = q(b | xⱼ)`. Restricting the `j`-th output to `{b}` and letting the +other `n − 1` coordinates range freely factors the sum over the product structure +(`Finset.prod_univ_sum`); each of the other coordinates sums to one (`row_sum`), leaving only the +`j`-th factor. -/ +private theorem sum_channelSeqProb_pin [DecidableEq κ] {q : ι → κ → ℝ} (hN : IsChannel q) + (x : Fin n → ι) (j : Fin n) (b : κ) : + ∑ y : Fin n → κ, (if y j = b then ∏ i, q (x i) (y i) else 0) = q (x j) b := by + rw [← Finset.sum_filter] + have hpi : (Finset.univ.filter fun y : Fin n → κ => y j = b) + = Fintype.piFinset fun i => if i = j then {b} else Finset.univ := by + ext y + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset] + constructor + · intro hy i + by_cases hij : i = j + · subst hij; simpa using hy + · simp [hij] + · intro hy; simpa using hy j + rw [hpi, ← Finset.prod_univ_sum (fun i => if i = j then ({b} : Finset κ) else Finset.univ) + fun i (y : κ) => q (x i) y] + refine (Finset.prod_eq_single j (fun i _ hij => ?_) + (fun h => absurd (Finset.mem_univ j) h)).trans ?_ + · simp [hij, hN.row_sum (x i)] + · simp + +/-- **The `j`-th output marginal of the memoryless `n`-use channel is the single-use output of the +`j`-th input marginal.** For a channel `q` fed an input-string distribution `P`, the marginal of the +`j`-th output coordinate `Yⱼ` of `channelOutput (channelSeqProb q) P` is `channelOutput q Pⱼ`, where +`Pⱼ = law P (·ⱼ)` is the `j`-th input marginal: + +`law (channelOutput (channelSeqProb q) P) (·ⱼ) = channelOutput q (law P (·ⱼ))`. + +Both sides evaluate at `b` to `∑ₓ P(x) q(b | xⱼ)`: the right-hand side by the push-forward +expectation `sum_law_mul`, the left-hand side by summing the joint output law over every coordinate +but the `j`-th (`sum_channelSeqProb_pin`). This is the memoryless-marginal fact that turns the +subadditive output bound `H(Yⁿ) ≤ ∑ⱼ H(Yⱼ)` into a per-use capacity bound in +`channelMutualInfo_channelSeqProb_le`. -/ +theorem law_proj_channelOutput_channelSeqProb [DecidableEq ι] [DecidableEq κ] {q : ι → κ → ℝ} + (hN : IsChannel q) (P : (Fin n → ι) → ℝ) (j : Fin n) : + law (channelOutput (channelSeqProb q) P) (fun y => y j) + = channelOutput q (law P (fun x => x j)) := by + funext b + rw [channelOutput_apply, sum_law_mul P (fun x => x j) fun a => q a b] + simp only [law, channelOutput_apply, channelSeqProb] + have push : ∀ y : Fin n → κ, + (if y j = b then ∑ x, P x * ∏ i, q (x i) (y i) else 0) + = ∑ x, if y j = b then P x * ∏ i, q (x i) (y i) else 0 := by + intro y; split_ifs <;> simp + simp_rw [push] + rw [Finset.sum_comm] + refine Finset.sum_congr rfl fun x _ => ?_ + have factor : ∀ y : Fin n → κ, + (if y j = b then P x * ∏ i, q (x i) (y i) else 0) + = P x * (if y j = b then ∏ i, q (x i) (y i) else 0) := by + intro y; rw [mul_ite, mul_zero] + simp_rw [factor, ← Finset.mul_sum] + rw [sum_channelSeqProb_pin hN x j b] + +/-- **Single-letterization of the channel mutual information** — the entropy input to the converse +half of Nielsen & Chuang Theorem 12.7. For a discrete memoryless channel `q` used `n` times, the +mutual information `H(Xⁿ : Yⁿ)` between any input-string distribution `P` and the induced output +string is at most `n` times the single-use information capacity: + +`channelMutualInfo (channelSeqProb q) P ≤ n • channelCapacity q`. + +Writing `H(Xⁿ : Yⁿ) = H(Yⁿ) − ∑ₓ P(x) H(Yⁿ | Xⁿ = x)` (`channelMutualInfo_eq`), the noise term +single-letterizes *exactly* — `H(Yⁿ | Xⁿ = x) = ∑ⱼ H(q(·|xⱼ))` (`entropy_pi_prod`), which averages +over `P` to `∑ⱼ ∑ₐ Pⱼ(a) H(q(·|a))` for the coordinate input marginals `Pⱼ = law P (·ⱼ)` — while +the output term is only *subadditive* — `H(Yⁿ) ≤ ∑ⱼ H(Yⱼ)` (`entropy_le_sum_entropy_proj`), the +`j`-th output marginal being the single-use output `channelOutput q Pⱼ` (`sum_channelSeqProb_pin`). +Combining coordinatewise gives `∑ⱼ channelMutualInfo q Pⱼ ≤ ∑ⱼ channelCapacity q = n • C`, each term +bounded by `le_channelCapacity` since every `Pⱼ` is an input distribution. This is the bound N&C's +converse composes with Fano's inequality to cap the operational capacity `C(N)`. -/ +theorem channelMutualInfo_channelSeqProb_le [Nonempty κ] {q : ι → κ → ℝ} (hN : IsChannel q) + {P : (Fin n → ι) → ℝ} (hP : P ∈ probSimplex (Fin n → ι)) : + channelMutualInfo (channelSeqProb q) P ≤ n • channelCapacity q := by + classical + set Pmarg : Fin n → ι → ℝ := fun j => law P (fun x => x j) with hPmarg + -- Each coordinate input marginal `Pⱼ = law P (·ⱼ)` is again an input distribution. + have hsimplex : ∀ j, Pmarg j ∈ probSimplex ι := by + intro j + simp only [hPmarg] + exact ⟨fun a => law_nonneg hP.1 _ a, by rw [sum_law]; exact hP.2⟩ + -- The `n`-use channel is a channel. + have hN' : IsChannel (channelSeqProb q (n := n)) := isChannel_channelSeqProb hN + -- Noise term single-letterizes: `H(Yⁿ | Xⁿ = x) = ∑ⱼ H(q(·|xⱼ))`, then average over `P`. + have hnoise : ∑ x, P x * entropy (channelSeqProb q x) + = ∑ j, ∑ a, Pmarg j a * entropy (q a) := by + have hper : ∀ x : Fin n → ι, entropy (channelSeqProb q x) = ∑ j, entropy (q (x j)) := by + intro x + have hx : channelSeqProb q x = fun y : Fin n → κ => ∏ j, q (x j) (y j) := rfl + rw [hx]; exact entropy_pi_prod (r := fun j => q (x j)) fun j => hN.row_sum (x j) + calc ∑ x, P x * entropy (channelSeqProb q x) + = ∑ x, ∑ j, P x * entropy (q (x j)) := by simp_rw [hper, Finset.mul_sum] + _ = ∑ j, ∑ x, P x * entropy (q (x j)) := Finset.sum_comm + _ = ∑ j, ∑ a, Pmarg j a * entropy (q a) := by + refine Finset.sum_congr rfl fun j _ => ?_ + simp only [hPmarg] + exact (sum_law_mul P (fun x => x j) fun a => entropy (q a)).symm + -- Output term is subadditive, and each output marginal is the single-use output of `Pⱼ` + -- (`law_proj_channelOutput_channelSeqProb`). + have hout : entropy (channelOutput (channelSeqProb q) P) + ≤ ∑ j, entropy (channelOutput q (Pmarg j)) := + (entropy_le_sum_entropy_proj (channelOutput_nonneg hN' hP.1) (sum_channelOutput hN' hP.2)).trans + (le_of_eq (Finset.sum_congr rfl fun j _ => by + rw [law_proj_channelOutput_channelSeqProb hN P j, hPmarg])) + -- Combine the output subadditivity with the exact noise split, coordinatewise. + rw [channelMutualInfo_eq (channelSeqProb q) fun x => sum_channelSeqProb hN x, hnoise] + calc entropy (channelOutput (channelSeqProb q) P) - ∑ j, ∑ a, Pmarg j a * entropy (q a) + ≤ (∑ j, entropy (channelOutput q (Pmarg j))) - ∑ j, ∑ a, Pmarg j a * entropy (q a) := by + linarith [hout] + _ = ∑ j, (entropy (channelOutput q (Pmarg j)) - ∑ a, Pmarg j a * entropy (q a)) := by + rw [← Finset.sum_sub_distrib] + _ = ∑ j, channelMutualInfo q (Pmarg j) := by + refine Finset.sum_congr rfl fun j _ => ?_ + rw [channelMutualInfo_eq q hN.row_sum] + _ ≤ ∑ _ : Fin n, channelCapacity q := + Finset.sum_le_sum fun j _ => le_channelCapacity hN (hsimplex j) + _ = n • channelCapacity q := by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin] + +/-! ### The joint law of message, codeword and output (converse setup) + +The converse of Shannon's coding theorem studies, for a fixed block code, the joint distribution of +a **uniform message** `W`, its deterministic **codeword** `Xⁿ = Cₙ(W)`, and the resulting channel +**output** `Yⁿ`. This subsection builds that tripartite distribution `ChannelCode.jointLaw` and its +structural marginals — the first marginal is the uniform message law (so `H(W) = log M`), the +`(Xⁿ, Yⁿ)`-marginal is a channel joint law fed the codeword pushforward `ChannelCode.inputLaw`, and +`W → Xⁿ → Yⁿ` is a Markov chain — which the next converse step feeds to Fano's inequality, the +data-processing inequality, and the single-letterization bound above. -/ + +section ConverseJointLaw + +variable [DecidableEq ι] + +/-- The **codeword input distribution** of a block code: the law of the codeword `Xⁿ = Cₙ(W)` when +the message `W` is uniform over the `M` messages, i.e. the push-forward of the uniform distribution +on `Fin M` along the encoder, +`ChannelCode.inputLaw code x = (#{m | Cₙ(m) = x}) / M`. It is the input distribution fed to the +memoryless `n`-use channel `channelSeqProb q` when a uniform message is transmitted, so its channel +mutual information `H(Xⁿ : Yⁿ)` is controlled by the single-letterization bound +`channelMutualInfo_channelSeqProb_le`. -/ +noncomputable def ChannelCode.inputLaw (code : ChannelCode ι κ n M) : (Fin n → ι) → ℝ := + law (fun _ : Fin M => (M : ℝ)⁻¹) code.encode + +omit [Fintype κ] in +/-- The codeword input distribution lies in the input simplex: it is nonnegative, and — with at +least one message (`0 < M`) — sums to one (`sum_law` of the uniform message law). -/ +theorem ChannelCode.inputLaw_mem_probSimplex (code : ChannelCode ι κ n M) (hM : 0 < M) : + code.inputLaw ∈ probSimplex (Fin n → ι) := by + refine ⟨fun x => law_nonneg (fun _ => by positivity) _ x, ?_⟩ + rw [ChannelCode.inputLaw, sum_law, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] + exact mul_inv_cancel₀ (by exact_mod_cast hM.ne') + +/-- The **joint law of message, codeword and output** `(W, Xⁿ, Yⁿ)` for a block code, the +tripartite distribution to which the converse of Shannon's noisy channel coding theorem applies +Fano's inequality and the data-processing inequality. The message `W` is uniform over the `M` +messages, the codeword `Xⁿ = Cₙ(W)` is the deterministic encoding, and the output `Yⁿ` is produced +by `n` memoryless uses of the channel `q`: + +`jointLaw q code (m, x, y) = M⁻¹ · (if x = Cₙ(m) then ∏ⱼ q(yⱼ | xⱼ) else 0)`. + +The `n`-use output law `channelSeqProb q x y` sits on the diagonal `x = Cₙ(m)` — off it the pair +`(W, Xⁿ)` has no mass — reflecting that `Xⁿ` is a deterministic function of `W`. -/ +noncomputable def ChannelCode.jointLaw (q : ι → κ → ℝ) (code : ChannelCode ι κ n M) : + Fin M × (Fin n → ι) × (Fin n → κ) → ℝ := + fun t => (M : ℝ)⁻¹ * (if t.2.1 = code.encode t.1 then channelSeqProb q t.2.1 t.2.2 else 0) + +omit [Fintype ι] [Fintype κ] in +@[simp] theorem ChannelCode.jointLaw_apply (q : ι → κ → ℝ) (code : ChannelCode ι κ n M) + (m : Fin M) (x : Fin n → ι) (y : Fin n → κ) : + code.jointLaw q (m, x, y) + = (M : ℝ)⁻¹ * (if x = code.encode m then channelSeqProb q x y else 0) := rfl + +omit [Fintype ι] in +/-- The joint law is nonnegative (a nonnegative weight `M⁻¹` times the nonnegative `n`-use output +law on the diagonal, `0` off it). -/ +theorem ChannelCode.jointLaw_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : ∀ t, 0 ≤ code.jointLaw q t := by + rintro ⟨m, x, y⟩ + rw [ChannelCode.jointLaw_apply] + refine mul_nonneg (by positivity) ?_ + split_ifs + · exact channelSeqProb_nonneg hN x y + · exact le_refl 0 + +omit [Fintype ι] in +/-- The **`(W, Xⁿ)`-marginal** of the joint law: summing out the output `Yⁿ` leaves the uniform mass +`M⁻¹` on the diagonal `x = Cₙ(m)` (each codeword's `n`-use output law has total mass one, +`sum_channelSeqProb`) and `0` off it: +`marginalFstMid (jointLaw q code) (m, x) = M⁻¹ · [x = Cₙ(m)]`. -/ +theorem ChannelCode.marginalFstMid_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (m : Fin M) (x : Fin n → ι) : + marginalFstMid (code.jointLaw q) (m, x) + = (M : ℝ)⁻¹ * (if x = code.encode m then (1 : ℝ) else 0) := by + rw [marginalFstMid_apply] + simp_rw [ChannelCode.jointLaw_apply, ← Finset.mul_sum] + congr 1 + rw [Finset.sum_ite_irrel, Finset.sum_const_zero, sum_channelSeqProb hN x] + +/-- The second marginal `∑ₘ jointLaw q code (m, ·)` of the joint law over the message `W`, packaged +for the first-marginal and total-mass computations: it equals `M⁻¹` for every message `m`. -/ +private theorem ChannelCode.sum_snd_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (m : Fin M) : + ∑ xy : (Fin n → ι) × (Fin n → κ), code.jointLaw q (m, xy) = (M : ℝ)⁻¹ := by + rw [Fintype.sum_prod_type] + simp_rw [← marginalFstMid_apply, ChannelCode.marginalFstMid_jointLaw hN, ← Finset.mul_sum] + rw [Finset.sum_ite_eq' Finset.univ (code.encode m) fun _ => (1 : ℝ)] + simp + +/-- The joint law is a probability distribution (given at least one message, `0 < M`): summing over +all `(W, Xⁿ, Yⁿ)` gives `∑ₘ M⁻¹ = 1`. -/ +theorem ChannelCode.sum_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) (code : ChannelCode ι κ n M) + (hM : 0 < M) : ∑ t, code.jointLaw q t = 1 := by + rw [Fintype.sum_prod_type] + simp_rw [ChannelCode.sum_snd_jointLaw hN] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + exact mul_inv_cancel₀ (by exact_mod_cast hM.ne') + +/-- The **first marginal is the uniform message law**: marginalizing the joint law over the codeword +and output leaves `W` uniform on the `M` messages, +`marginalFst (jointLaw q code) = fun _ => M⁻¹`. -/ +theorem ChannelCode.marginalFst_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : marginalFst (code.jointLaw q) = fun _ : Fin M => (M : ℝ)⁻¹ := by + funext m + rw [marginalFst_apply] + exact ChannelCode.sum_snd_jointLaw hN code m + +/-- The message entropy is `H(W) = log M`: the first marginal is uniform on `Fin M` +(`marginalFst_jointLaw`), whose entropy is `log |Fin M| = log M` (`entropy_uniform`). This is the +`H(W)` that the converse expands as `H(W | Yⁿ) + H(W : Yⁿ)`. -/ +theorem ChannelCode.entropy_marginalFst_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : + entropy (marginalFst (code.jointLaw q)) = Real.log M := by + rw [ChannelCode.marginalFst_jointLaw hN] + simpa [Fintype.card_fin] using entropy_uniform (ι := Fin M) + +omit [Fintype ι] [Fintype κ] in +/-- The **`(Xⁿ, Yⁿ)`-marginal is the channel joint law of the codeword pushforward**: marginalizing +the joint law over the message `W` leaves the input–output law of the memoryless `n`-use channel +`channelSeqProb q` fed the codeword input distribution `inputLaw`, +`marginalSnd (jointLaw q code) = channelJoint (channelSeqProb q) (inputLaw code)`. Hence +`H(Xⁿ : Yⁿ) = channelMutualInfo (channelSeqProb q) (inputLaw code)`, to which the +single-letterization bound applies. Pointwise, `∑ₘ M⁻¹ [x = Cₙ(m)] · ∏ⱼ q(yⱼ | xⱼ)` factors the +codeword-independent `∏ⱼ q(yⱼ | xⱼ)` out of the message sum, leaving `inputLaw x` times it. -/ +theorem ChannelCode.marginalSnd_jointLaw {q : ι → κ → ℝ} (code : ChannelCode ι κ n M) : + marginalSnd (code.jointLaw q) = channelJoint (channelSeqProb q) code.inputLaw := by + funext xy + obtain ⟨x, y⟩ := xy + rw [marginalSnd_apply, channelJoint_apply, ChannelCode.inputLaw, law, mul_comm, Finset.mul_sum] + refine Finset.sum_congr rfl fun m _ => ?_ + rw [ChannelCode.jointLaw_apply] + by_cases h : code.encode m = x + · rw [ite_eq_left h.symm, ite_eq_left h]; ring + · rw [ite_eq_right fun he => h he.symm, ite_eq_right h]; ring + +omit [Fintype ι] in +/-- The **middle codeword marginal is the codeword input law**: summing the joint law over the +message `W` and output `Yⁿ` leaves `inputLaw`, `marginalMid (jointLaw q code) = inputLaw code`. Used +to discharge the `p_Y(y)` factor of the Markov-chain identity. -/ +theorem ChannelCode.marginalMid_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : marginalMid (code.jointLaw q) = code.inputLaw := by + funext x + rw [marginalMid, ChannelCode.marginalSnd_jointLaw, marginalFst_apply] + simp_rw [channelJoint_apply, ← Finset.mul_sum, sum_channelSeqProb hN x, mul_one] + +omit [Fintype ι] in +/-- **`W → Xⁿ → Yⁿ` is a Markov chain**: the message, its codeword and the channel output form a +Markov chain, because the codeword `Xⁿ = Cₙ(W)` is a deterministic function of `W` and the output +`Yⁿ` depends on `W` only through `Xⁿ`. Concretely the conditional-independence identity +`jointLaw (m, x, y) · marginalMid (x) = marginalFstMid (m, x) · marginalSnd (x, y)` holds pointwise: +both sides are `M⁻¹ · [x = Cₙ(m)] · inputLaw x · ∏ⱼ q(yⱼ | xⱼ)`. This is the hypothesis the +data-processing inequality needs to bound `H(W : Yⁿ) ≤ H(Xⁿ : Yⁿ)`. -/ +theorem ChannelCode.isMarkovChain_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) : IsMarkovChain (code.jointLaw q) := by + intro m x y + rw [ChannelCode.marginalMid_jointLaw hN, ChannelCode.marginalFstMid_jointLaw hN, + ChannelCode.marginalSnd_jointLaw, ChannelCode.jointLaw_apply, channelJoint_apply] + by_cases h : x = code.encode m + · simp only [ite_eq_left h]; ring + · simp only [ite_eq_right h]; ring + +/-- **The per-`n` converse inequality of Shannon's noisy channel coding theorem.** For a block code +with a uniform message `W` over `M` messages, deterministic codeword `Xⁿ = Cₙ(W)`, and channel +output `Yⁿ` (the joint law `jointLaw`), the average decoding error `P_barₑ` obeys + +`(1 − P_barₑ) · log M ≤ log 2 + n · max_{p(x)} H(X : Y)`, + +where `P_barₑ = fanoErrorProb (marginalFstLast (jointLaw q code)) Dₙ` is the probability that the +decoder's guess `Dₙ(Yⁿ)` differs from the true message. This is the quantitative core of the +converse: it forces the rate to obey `R ≲ C` once the error `P_barₑ → 0` (developed in the limit +step). + +The proof assembles three ingredients on the tripartite law `(W, Xⁿ, Yⁿ)`: +* `H(W) = log M` (`entropy_marginalFst_jointLaw`), expanded as `H(W) = H(W | Yⁿ) + H(W : Yⁿ)`; +* **Fano's inequality** (`condEntropy_le_binEntropy_add_mul_log`) on the `(W, Yⁿ)`-marginal with the + decoder as guess: `H(W | Yⁿ) ≤ binEntropy P_barₑ + P_barₑ · log (M − 1) ≤ log 2 + P_barₑ · log + M`, using + `binEntropy P_barₑ ≤ log 2` (`binEntropy_le_log_two`) and `log (M − 1) ≤ log M`; +* the **data-processing inequality** `mutualInfo_marginalFstLast_le_marginalSnd`, applied to the + Markov chain `W → Xⁿ → Yⁿ` (`isMarkovChain_jointLaw`) — its last-vs-second-marginal form, which + internalises the outer reversal — giving + `H(W : Yⁿ) ≤ H(Xⁿ : Yⁿ) = channelMutualInfo (channelSeqProb q) (inputLaw code)` + (`marginalSnd_jointLaw`), then bounded by `n · channelCapacity q` via the single-letterization + bound `channelMutualInfo_channelSeqProb_le`. + +Rearranging `log M = H(W : Yⁿ) + H(W | Yⁿ) ≤ n · C + log 2 + P_barₑ · log M` gives the claim. +Entropy +is in nats; the bound is base-independent. -/ +theorem ChannelCode.one_sub_fanoErrorProb_mul_log_le [Nonempty κ] {q : ι → κ → ℝ} + (hN : IsChannel q) (code : ChannelCode ι κ n M) (hM : 0 < M) : + (1 - fanoErrorProb (marginalFstLast (code.jointLaw q)) code.decode) * Real.log M + ≤ Real.log 2 + n • channelCapacity q := by + classical + set J := code.jointLaw q with hJ + set Pe := fanoErrorProb (marginalFstLast J) code.decode with hPe + have hJnonneg : ∀ t, 0 ≤ J t := code.jointLaw_nonneg hN + have hJsum : ∑ t, J t = 1 := code.sum_jointLaw hN hM + -- The `(W, Yⁿ)`-marginal `marginalFstLast J` is a probability distribution. + have hWY_nonneg : ∀ w, 0 ≤ marginalFstLast J w := by + rintro ⟨m, y⟩; rw [marginalFstLast_apply] + exact Finset.sum_nonneg fun x _ => hJnonneg _ + have hWY_sum : ∑ w, marginalFstLast J w = 1 := by + rw [← sum_marginalFst (marginalFstLast J), marginalFst_marginalFstLast, sum_marginalFst] + exact hJsum + -- `H(W) = log M` via the uniform first marginal. + have hlogM : entropy (marginalFst (marginalFstLast J)) = Real.log M := by + rw [marginalFst_marginalFstLast, hJ]; exact code.entropy_marginalFst_jointLaw hN + -- Fano's inequality: `H(W | Yⁿ) ≤ binEntropy P_barₑ + P_barₑ · log (M − 1)`. + have hFano : condEntropy (marginalFstLast J) + ≤ binEntropy Pe + Pe * Real.log ((M : ℝ) - 1) := by + have h := condEntropy_le_binEntropy_add_mul_log hWY_nonneg hWY_sum code.decode + simpa only [Fintype.card_fin, ← hPe] using h + have hPe_nonneg : 0 ≤ Pe := fanoErrorProb_nonneg hWY_nonneg hWY_sum code.decode + -- `log (M − 1) ≤ log M`. + have hlogmono : Real.log ((M : ℝ) - 1) ≤ Real.log M := by + rcases Nat.lt_or_ge M 2 with hlt | hge + · have hM1 : M = 1 := by omega + subst hM1; simp + · have hM2 : (2 : ℝ) ≤ (M : ℝ) := by exact_mod_cast hge + exact Real.log_le_log (by linarith) (by linarith) + -- Mutual information as `H(W) − H(W | Yⁿ)`. + have hmi_eq : mutualInfo (marginalFstLast J) + = entropy (marginalFst (marginalFstLast J)) - condEntropy (marginalFstLast J) := by + rw [mutualInfo_eq, condEntropy_eq]; ring + -- Data-processing inequality on the Markov chain `W → Xⁿ → Yⁿ` (`isMarkovChain_jointLaw`); the + -- second-marginal form internalises the outer reversal, giving `H(W : Yⁿ) ≤ H(Xⁿ : Yⁿ)`. + have hDPI : mutualInfo (marginalFstLast J) ≤ mutualInfo (marginalSnd J) := + mutualInfo_marginalFstLast_le_marginalSnd hJnonneg hJsum (code.isMarkovChain_jointLaw hN) + -- Single-letterization: `H(Xⁿ : Yⁿ) ≤ n · channelCapacity q`. + have hSL : mutualInfo (marginalSnd J) ≤ n • channelCapacity q := by + rw [hJ, code.marginalSnd_jointLaw] + exact channelMutualInfo_channelSeqProb_le hN (code.inputLaw_mem_probSimplex hM) + -- Assemble. + have hbin : binEntropy Pe ≤ Real.log 2 := binEntropy_le_log_two + have hlogmul : Pe * Real.log ((M : ℝ) - 1) ≤ Pe * Real.log M := + mul_le_mul_of_nonneg_left hlogmono hPe_nonneg + have hexp : (1 - Pe) * Real.log M = Real.log M - Pe * Real.log M := by ring + rw [hexp] + linarith [hmi_eq, hlogM, hFano, hDPI, hSL, hbin, hlogmul] + +/-! ### The average error probability and the converse of the coding theorem -/ + +omit [Fintype κ] in +/-- The **`(W, Yⁿ)`-marginal** of the code joint law: summing out the codeword `Xⁿ` from `jointLaw` +leaves, on message `w` and output string `y`, the uniform weight `M⁻¹` times the `n`-use output law +of the codeword `Cₙ(w)`: +`marginalFstLast (jointLaw q code) (w, y) = M⁻¹ · channelSeqProb q (Cₙ w) y`. -/ +theorem ChannelCode.marginalFstLast_jointLaw {q : ι → κ → ℝ} (code : ChannelCode ι κ n M) + (m : Fin M) (y : Fin n → κ) : + marginalFstLast (code.jointLaw q) (m, y) = (M : ℝ)⁻¹ * channelSeqProb q (code.encode m) y := by + rw [marginalFstLast_apply] + simp only [ChannelCode.jointLaw_apply, ← Finset.mul_sum] + rw [Finset.sum_ite_eq' Finset.univ (code.encode m) (fun x => channelSeqProb q x y)] + simp + +/-- **The average probability of error equals the Fano error probability of the code joint law.** +For a block code with `0 < M` messages and its joint law `jointLaw` (uniform message `W`, codeword +`Xⁿ = Cₙ(W)`, output `Yⁿ`), the Fano error probability of the `(W, Yⁿ)`-marginal under the decoder +`Dₙ` — the `P_barₑ` of the per-`n` converse inequality `one_sub_fanoErrorProb_mul_log_le` — is +exactly +the *average* of the conditional block-error probabilities over the `M` messages (Nielsen & Chuang, +p. 552, the average probability of error `p_bar(Cₙ, Dₙ) = M⁻¹ ∑ₘ p(Dₙ(Y) ≠ m | Cₙ(m))`): +`fanoErrorProb (marginalFstLast (jointLaw q code)) Dₙ = (∑ₘ condErrorProb q m) / M`. + +The Fano term expands, via the `(W, Yⁿ)`-marginal (`marginalFstLast_jointLaw`), to +`1 − M⁻¹ ∑_y channelSeqProb q (Cₙ(Dₙ y)) y`; each conditional error probability is `1 −` the +correct-decoding probability of its message (`sum_channelSeqProb`), and the correct-decoding +probabilities telescope over the decoder's fibers (`Finset.sum_fiberwise`) to the same +`∑_y channelSeqProb q (Cₙ(Dₙ y)) y`. -/ +theorem ChannelCode.fanoErrorProb_marginalFstLast_jointLaw {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (hM : 0 < M) : + fanoErrorProb (marginalFstLast (code.jointLaw q)) code.decode + = (∑ m, code.condErrorProb q m) / M := by + have hMne : (M : ℝ) ≠ 0 := by exact_mod_cast hM.ne' + -- The Fano error term expands via the (W, Yⁿ)-marginal. + have hfano : fanoErrorProb (marginalFstLast (code.jointLaw q)) code.decode + = 1 - (M : ℝ)⁻¹ * ∑ y : Fin n → κ, channelSeqProb q (code.encode (code.decode y)) y := by + unfold fanoErrorProb + congr 1 + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun y _ => code.marginalFstLast_jointLaw (code.decode y) y + -- Each conditional error probability is `1 −` the correct-decoding probability of its message. + have hcond : ∀ m, code.condErrorProb q m + = 1 - ∑ y ∈ Finset.univ with code.decode y = m, channelSeqProb q (code.encode m) y := by + intro m + rw [ChannelCode.condErrorProb, eq_sub_iff_add_eq, add_comm, + ← sum_channelSeqProb hN (code.encode m)] + exact Finset.sum_filter_add_sum_filter_not Finset.univ (fun y => code.decode y = m) _ + -- The total correct-decoding probability telescopes over the decoder's fibers. + have hsumcorr : ∑ m, ∑ y ∈ Finset.univ with code.decode y = m, + channelSeqProb q (code.encode m) y + = ∑ y : Fin n → κ, channelSeqProb q (code.encode (code.decode y)) y := by + rw [← Finset.sum_fiberwise Finset.univ code.decode + (fun y => channelSeqProb q (code.encode (code.decode y)) y)] + refine Finset.sum_congr rfl fun m _ => Finset.sum_congr rfl fun y hy => ?_ + rw [Finset.mem_filter] at hy + rw [hy.2] + rw [hfano, Finset.sum_congr rfl (fun m (_ : m ∈ Finset.univ) => hcond m), Finset.sum_sub_distrib, + Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, hsumcorr] + field_simp + +/-- The Fano error probability of the code joint law — the average probability of error — is +nonnegative (an average of nonnegative conditional error probabilities). -/ +theorem ChannelCode.fanoErrorProb_marginalFstLast_jointLaw_nonneg {q : ι → κ → ℝ} (hN : IsChannel q) + (code : ChannelCode ι κ n M) (hM : 0 < M) : + 0 ≤ fanoErrorProb (marginalFstLast (code.jointLaw q)) code.decode := by + rw [ChannelCode.fanoErrorProb_marginalFstLast_jointLaw hN code hM] + exact div_nonneg (Finset.sum_nonneg fun m _ => code.condErrorProb_nonneg hN m) (by positivity) + +/-- The **average probability of error is at most the block (maximum) error probability**: an +average of the conditional error probabilities cannot exceed their maximum. This is the bridge +turning the per-`n` converse inequality's `P_barₑ` — the Fano error of the joint law — into a +quantity +that vanishes whenever the block error probability does (`maxErrorProb → 0`). -/ +theorem ChannelCode.fanoErrorProb_marginalFstLast_jointLaw_le_maxErrorProb {q : ι → κ → ℝ} + (hN : IsChannel q) (code : ChannelCode ι κ n M) (hM : 0 < M) : + fanoErrorProb (marginalFstLast (code.jointLaw q)) code.decode ≤ code.maxErrorProb q := by + rw [ChannelCode.fanoErrorProb_marginalFstLast_jointLaw hN code hM, + div_le_iff₀ (by exact_mod_cast hM)] + calc ∑ m, code.condErrorProb q m + ≤ ∑ _m : Fin M, code.maxErrorProb q := + Finset.sum_le_sum fun m _ => code.condErrorProb_le_maxErrorProb q m + _ = code.maxErrorProb q * M := by + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_comm] + +end ConverseJointLaw + +/-- **The converse of Shannon's noisy channel coding theorem** (Nielsen & Chuang, Theorem 12.7, +eq. (12.67), one direction). The operational capacity is at most the information capacity: no rate +above `max_{p(x)} H(X : Y)` — in bits, `channelCapacity q / log 2` — is achievable, so +`channelOpCapacity q ≤ channelCapacity q / log 2`. + +For an achievable rate `R` there is a family of `M(n) = ⌈2 ^ (n R)⌉`-message block codes whose block +error probability tends to `0`. Feeding the per-`n` converse inequality +`(1 − P_barₑ) · log M ≤ log 2 + n · C` (`one_sub_fanoErrorProb_mul_log_le`) the message-count lower +bound `log M(n) ≥ n R log 2` (from `M(n) ≥ 2 ^ (n R)`, `Nat.le_ceil`) and the vanishing of the +average error `P_barₑ(n) ≤ maxErrorProb → 0` +(`fanoErrorProb_marginalFstLast_jointLaw_le_maxErrorProb`, +`squeeze_zero`) gives `n · (1 − P_barₑ) · R log 2 ≤ log 2 + n · C`; dividing by `n` and letting +`n → ∞` (so `P_barₑ → 0` and `log 2 / n → 0`, `le_of_tendsto_of_tendsto`) yields `R log 2 ≤ C`, i.e. +`R ≤ C / log 2`. As every achievable rate obeys this, so does their supremum `channelOpCapacity q` +(`csSup_le`). + +Entropy is in nats; the operational rate `R` and the bound are in bits, hence the `/ log 2`. N&C +defers the matching achievability direction `channelCapacity q / log 2 ≤ channelOpCapacity q` +(random coding and the theorem of typical sequences) to the quantum HSW theorem (Theorem 12.8) of +the next section. -/ +theorem channelOpCapacity_le_channelCapacity_div [Nonempty ι] [Nonempty κ] {q : ι → κ → ℝ} + (hN : IsChannel q) : + channelOpCapacity q ≤ channelCapacity q / Real.log 2 := by + classical + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + refine csSup_le ⟨0, isAchievableRate_zero q⟩ ?_ + rintro R ⟨code, hcode⟩ + have hMpos : ∀ n : ℕ, 0 < ⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ := + fun n => Nat.ceil_pos.mpr (Real.exp_pos _) + -- Abstract the average error `P_barₑ(n)`: `≤ 1`, tends to `0`, and obeys the per-`n` bound. + obtain ⟨Pe, hPe_le_one, hPe_tendsto, hpern⟩ : + ∃ Pe : ℕ → ℝ, (∀ n, Pe n ≤ 1) ∧ Tendsto Pe atTop (𝓝 0) ∧ + (∀ n : ℕ, (1 - Pe n) * Real.log (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) + ≤ Real.log 2 + (n : ℝ) * channelCapacity q) := by + refine ⟨fun n => fanoErrorProb (marginalFstLast ((code n).jointLaw q)) (code n).decode, + fun n => le_trans + ((code n).fanoErrorProb_marginalFstLast_jointLaw_le_maxErrorProb hN (hMpos n)) + ((code n).maxErrorProb_le_one hN), + squeeze_zero + (fun n => (code n).fanoErrorProb_marginalFstLast_jointLaw_nonneg hN (hMpos n)) + (fun n => (code n).fanoErrorProb_marginalFstLast_jointLaw_le_maxErrorProb hN (hMpos n)) + hcode, fun n => ?_⟩ + have h := (code n).one_sub_fanoErrorProb_mul_log_le hN (hMpos n) + rwa [nsmul_eq_mul] at h + -- `log M(n) ≥ n R log 2`. + have hlogM : ∀ n : ℕ, (n : ℝ) * R * Real.log 2 + ≤ Real.log (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) := by + intro n + calc (n : ℝ) * R * Real.log 2 + = Real.log (Real.exp ((n : ℝ) * R * Real.log 2)) := (Real.log_exp _).symm + _ ≤ Real.log (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) := + Real.log_le_log (Real.exp_pos _) (Nat.le_ceil _) + -- Combine into `n · ((1 − P_barₑ) · R log 2) ≤ log 2 + n · C`. + have hstep : ∀ n : ℕ, (n : ℝ) * ((1 - Pe n) * (R * Real.log 2)) + ≤ Real.log 2 + (n : ℝ) * channelCapacity q := by + intro n + have hmul : (1 - Pe n) * ((n : ℝ) * R * Real.log 2) + ≤ (1 - Pe n) * Real.log (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) := + mul_le_mul_of_nonneg_left (hlogM n) (by linarith [hPe_le_one n]) + calc (n : ℝ) * ((1 - Pe n) * (R * Real.log 2)) + = (1 - Pe n) * ((n : ℝ) * R * Real.log 2) := by ring + _ ≤ (1 - Pe n) * Real.log (⌈Real.exp ((n : ℝ) * R * Real.log 2)⌉₊ : ℝ) := hmul + _ ≤ Real.log 2 + (n : ℝ) * channelCapacity q := hpern n + -- Divide by `n` (for `n ≥ 1`). + have hab : ∀ n : ℕ, 1 ≤ n → + (1 - Pe n) * (R * Real.log 2) ≤ Real.log 2 / (n : ℝ) + channelCapacity q := by + intro n hn + have hnpos : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn + have hnne : (n : ℝ) ≠ 0 := ne_of_gt hnpos + rw [← sub_nonneg, show Real.log 2 / (n : ℝ) + channelCapacity q - (1 - Pe n) * (R * Real.log 2) + = (Real.log 2 + (n : ℝ) * channelCapacity q + - (n : ℝ) * ((1 - Pe n) * (R * Real.log 2))) / (n : ℝ) by field_simp] + exact div_nonneg (by linarith [hstep n]) hnpos.le + -- Take the `atTop` limit. + have ha : Tendsto (fun n => (1 - Pe n) * (R * Real.log 2)) atTop (𝓝 (R * Real.log 2)) := by + have h1 : Tendsto (fun n => 1 - Pe n) atTop (𝓝 (1 - 0)) := tendsto_const_nhds.sub hPe_tendsto + simpa using h1.mul_const (R * Real.log 2) + have hb : Tendsto (fun n : ℕ => Real.log 2 / (n : ℝ) + channelCapacity q) atTop + (𝓝 (channelCapacity q)) := by + have h0 : Tendsto (fun n : ℕ => Real.log 2 / (n : ℝ)) atTop (𝓝 0) := + tendsto_natCast_atTop_atTop.const_div_atTop (Real.log 2) + simpa using h0.add_const (channelCapacity q) + have hRlog : R * Real.log 2 ≤ channelCapacity q := + le_of_tendsto_of_tendsto ha hb (eventually_atTop.mpr ⟨1, fun n hn => hab n hn⟩) + rw [le_div_iff₀ hL] + exact hRlog + +end OperationalCapacity + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/RandomCodingExpectation.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/RandomCodingExpectation.lean new file mode 100644 index 0000000000..a4d6dbfadd --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/RandomCodingExpectation.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.Analysis.SpecialFunctions.ShannonEntropy +public import Mathlib.Logic.Equiv.Prod + +/-! +# Random-coding expectation: marginals of a product weight over a codebook + +The random-coding argument of the Holevo–Schumacher–Westmoreland theorem +(Nielsen & Chuang, Theorem 12.8, eqs. (12.80)–(12.82)) averages a per-codebook quantity over a +**random codebook**: a family `w : ι → β` of `|ι|` independently drawn codewords, each `w M : β` +chosen with weight `W (w M)`, so the codebook `w` carries the product weight `∏ M, W (w M)`. The +error estimate then reduces the expectation of a sum of trace terms — each depending on *one* or +*two* of the codewords — to marginal expectations, using that distinct codewords are +**independent**. + +This file provides the two elementary combinatorial identities behind that reduction, for a +distribution `W : β → ℝ` (`∑ b, W b = 1`) over the codeword type `β`: + +* `Real.sum_pi_weight_mul_apply` — the **single-codeword marginal**: for a quantity `f (w j)` + depending only on codeword `j`, + + `∑_{w : ι → β} (∏ M, W (w M)) · f (w j) = ∑ b, W b · f b`, + + i.e. averaging over the whole codebook collapses to averaging over the single codeword `j` (the + other codewords sum out to total mass `1`). + +* `Real.sum_pi_weight_mul_apply₂` — the **two-codeword (independence) marginal**: for a quantity + `g (w j) (w j')` depending on two *distinct* codewords `j ≠ j'`, + + `∑_{w : ι → β} (∏ M, W (w M)) · g (w j) (w j') = ∑ v, ∑ v', W v · W v' · g v v'`, + + i.e. the expectation factorises over the two independent codewords. + +In the HSW error estimate `W v = ∏ᵢ p (vᵢ)` is the i.i.d. per-codeword weight over length-`n` +sequences `v : Fin n → α` (`∑ v, W v = 1` is `AxQM.sum_iidProdWeight`), `ι = Fin K` indexes +the `K` messages, and the codeword output `σ_M` and its conditional typical projector `P_M` depend +only on codeword `M`; the single-codeword marginal handles the diagonal error terms +`𝔼 tr(σ_M (I − P)) = tr(σ_bar^⊗n (I − P))` and `𝔼 tr(σ_M (I − P_M))`, while the two-codeword +marginal +handles the false-decoding/confusion term `𝔼 tr(P σ_M P P_{M'})` for `M ≠ M'`, whose two factors +depend on the independent codewords `M` and `M'`. + +Everything is a finite sum over `ι → β`; no measure theory is used, matching the elementary +finite-distribution convention of `ToMathlib/InformationTheory/IIDConcentration.lean` (a +distribution +is a bare `W : β → ℝ`, the hypothesis `∑ W = 1` supplied to the lemmas). + +## Main results + +- `Real.sum_pi_weight_mul_apply`: the single-codeword marginal. +- `Real.sum_pi_weight_mul_apply₂`: the two-codeword independence marginal. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {ι β : Type*} [Fintype ι] [DecidableEq ι] [Fintype β] + +/-- **Single-codeword marginal of a product weight.** For a distribution `W : β → ℝ` +(`∑ b, W b = 1`) and an observable `f (w j)` of the codebook `w : ι → β` depending only on the +single codeword `j`, the product-weight average over the whole codebook collapses to the average +over that one codeword: + +`∑_{w : ι → β} (∏ M, W (w M)) · f (w j) = ∑ b, W b · f b`. + +Random-coding statement: since the other `|ι| − 1` codewords are independent and their weights sum +to `1`, they marginalise out. This is the tool that turns the expectation of a diagonal error term +(depending on a single random codeword, e.g. `tr(σ_M (I − P_M))`) into a single-codeword +expectation. -/ +theorem sum_pi_weight_mul_apply (W : β → ℝ) (hW : ∑ b, W b = 1) (f : β → ℝ) (j : ι) : + ∑ w : ι → β, (∏ M, W (w M)) * f (w j) = ∑ b, W b * f b := by + classical + -- Write the summand as a coordinatewise product `∏ M, W (w M) · [M = j] f (w M)`. + have hsummand : ∀ w : ι → β, + (∏ M, W (w M)) * f (w j) = ∏ M, (W (w M) * (if M = j then f (w M) else 1)) := by + intro w + rw [Finset.prod_mul_distrib, Finset.prod_ite_eq' univ j (fun M => f (w M)), + ite_eq_left (mem_univ j)] + simp_rw [hsummand] + -- `∑_w ∏_M h M (w M) = ∏_M ∑_b h M b` (sum of products = product of sums over a pi `Fintype`). + have hpiv : (∏ M, ∑ b, W b * (if M = j then f b else 1)) + = ∑ x : ι → β, ∏ M, W (x M) * (if M = j then f (x M) else 1) := by + rw [Finset.prod_univ_sum, Fintype.piFinset_univ] + rw [← hpiv, ← Finset.mul_prod_erase univ + (fun M => ∑ b, W b * (if M = j then f b else 1)) (mem_univ j)] + -- The `M = j` factor is `∑ b, W b · f b`; every other factor is `∑ b, W b = 1`. + have h1 : (∑ b, W b * (if j = j then f b else 1)) = ∑ b, W b * f b := by simp + have h2 : (∏ M ∈ univ.erase j, ∑ b, W b * (if M = j then f b else 1)) = 1 := by + apply Finset.prod_eq_one + intro M hM + simp only [ite_eq_right (Finset.ne_of_mem_erase hM), mul_one]; exact hW + rw [h1, h2, mul_one] + +/-- **Two-codeword (independence) marginal of a product weight.** For a distribution `W : β → ℝ` +(`∑ b, W b = 1`) and an observable `g (w j) (w j')` of the codebook `w : ι → β` depending on two +*distinct* codewords `j ≠ j'`, the product-weight average factorises over the two independent +codewords: + +`∑_{w : ι → β} (∏ M, W (w M)) · g (w j) (w j') = ∑ v, ∑ v', W v · W v' · g v v'`. + +Random-coding statement: distinct codewords are independent, so their joint expectation is the +product of marginals. This is the tool that turns the expectation of the HSW false-decoding +(confusion) term `tr(P σ_M P P_{M'})` — whose two factors `σ_M` and `P_{M'}` depend on the two +independent random codewords `M ≠ M'` — into `tr(P 𝔼(σ_M) P 𝔼(P_{M'}))`. + +Proof: split the codebook at coordinate `j'` via `Equiv.funSplitAt`, writing `w` as a value `v'` at +`j'` together with the remaining codewords `u : {M // M ≠ j'} → β`; the product weight factors as +`W v' · ∏ M, W (u M)`, and the inner sum over `u` is the single-codeword marginal +(`sum_pi_weight_mul_apply`) at the codeword `⟨j, hjj'⟩` of the reduced index. -/ +theorem sum_pi_weight_mul_apply₂ (W : β → ℝ) (hW : ∑ b, W b = 1) (g : β → β → ℝ) + {j j' : ι} (hjj' : j ≠ j') : + ∑ w : ι → β, (∏ M, W (w M)) * g (w j) (w j') = ∑ v, ∑ v', W v * W v' * g v v' := by + classical + -- For a fixed value `v'` of codeword `j'`, marginalise the remaining codewords `u`. + have step : ∀ v' : β, + (∑ u : {M // M ≠ j'} → β, + (∏ M, W ((Equiv.funSplitAt j' β).symm (v', u) M)) * + g ((Equiv.funSplitAt j' β).symm (v', u) j) ((Equiv.funSplitAt j' β).symm (v', u) j')) + = ∑ v, W v * W v' * g v v' := by + intro v' + have hsymm : ∀ (u : {M // M ≠ j'} → β) (M : ι), + (Equiv.funSplitAt j' β).symm (v', u) M = if h : M = j' then v' else u ⟨M, h⟩ := + fun u M => by simp [Equiv.funSplitAt, Equiv.piSplitAt] + calc ∑ u : {M // M ≠ j'} → β, + (∏ M, W ((Equiv.funSplitAt j' β).symm (v', u) M)) * + g ((Equiv.funSplitAt j' β).symm (v', u) j) ((Equiv.funSplitAt j' β).symm (v', u) j') + = ∑ u : {M // M ≠ j'} → β, (W v' * ∏ M : {M // M ≠ j'}, W (u M)) * g (u ⟨j, hjj'⟩) v' := by + refine Finset.sum_congr rfl fun u _ => ?_ + -- The product weight factors off the `j'`-coordinate. + have hprod : (∏ M, W ((Equiv.funSplitAt j' β).symm (v', u) M)) + = W v' * ∏ M : {M // M ≠ j'}, W (u M) := by + rw [← Finset.mul_prod_erase univ + (fun M => W ((Equiv.funSplitAt j' β).symm (v', u) M)) (mem_univ j')] + congr 1 + · rw [hsymm]; simp + · rw [Finset.prod_subtype (univ.erase j') (p := fun x => x ≠ j') + (fun x => by simp [Finset.mem_erase]) + (fun M => W ((Equiv.funSplitAt j' β).symm (v', u) M))] + exact Finset.prod_congr rfl fun M _ => by rw [hsymm, dite_eq_right M.2] + rw [hprod, hsymm, hsymm, dite_eq_right hjj', dite_eq_left rfl] + _ = W v' * ∑ u : {M // M ≠ j'} → β, (∏ M : {M // M ≠ j'}, W (u M)) * g (u ⟨j, hjj'⟩) v' := by + rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun u _ => by ring + _ = W v' * ∑ v, W v * g v v' := by + congr 1 + exact Real.sum_pi_weight_mul_apply W hW (fun b => g b v') (⟨j, hjj'⟩ : {M // M ≠ j'}) + _ = ∑ v, W v * W v' * g v v' := by + rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun v _ => by ring + -- Reindex the codebook by (value at `j'`, remaining codewords) and apply `step`. + rw [← Equiv.sum_comp (Equiv.funSplitAt j' β).symm + (fun w => (∏ M, W (w M)) * g (w j) (w j')), Fintype.sum_prod_type] + rw [Finset.sum_congr rfl fun v' _ => step v', Finset.sum_comm] + +/-- **Derandomisation: a real weighted mean below a bound has a term below the bound.** For a +distribution `W : β → ℝ` (`∑ b, W b = 1`, `W ≥ 0`) and any `f : β → ℝ`, if the weighted mean +`∑ b, W b · f b` is at most `C`, then some `b` attains `f b ≤ C`. + +The derandomisation step of a random-coding argument: the *expected* per-code quantity `f` over the +random codebook (distribution `W`) being at most `C` forces some concrete codebook `b` to have +`f b ≤ C`. If every `f b` exceeded `C`, then — since some weight `W b₀` is positive (as +`∑ W = 1 > 0`) — the mean `∑ b, W b · f b` would strictly exceed `∑ b, W b · C = C`, a +contradiction. -/ +theorem exists_le_of_weighted_sum_le (W : β → ℝ) (hW0 : ∀ b, 0 ≤ W b) (hW1 : ∑ b, W b = 1) + (f : β → ℝ) (C : ℝ) (h : ∑ b, W b * f b ≤ C) : ∃ b, f b ≤ C := by + by_contra hcon + simp only [not_exists, not_le] at hcon + obtain ⟨b0, hb0⟩ : ∃ b, 0 < W b := by + by_contra h0 + simp only [not_exists, not_lt] at h0 + have hle : ∑ b, W b ≤ 0 := Finset.sum_nonpos fun b _ => h0 b + rw [hW1] at hle + linarith + have hlt : C < ∑ b, W b * f b := by + have hCeq : C = ∑ b, W b * C := by rw [← Finset.sum_mul, hW1, one_mul] + rw [hCeq] + refine Finset.sum_lt_sum (fun b _ => mul_le_mul_of_nonneg_left (hcon b).le (hW0 b)) ?_ + exact ⟨b0, Finset.mem_univ _, mul_lt_mul_of_pos_left (hcon b0) hb0⟩ + linarith + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/TypicalSequence.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/TypicalSequence.lean new file mode 100644 index 0000000000..b1def8e171 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/TypicalSequence.lean @@ -0,0 +1,341 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.IIDConcentration + +/-! +# The theorem of typical sequences (classical asymptotic equipartition property) + +For a finite alphabet `α`, a probability mass function `p : α → ℝ` (`0 ≤ p x`, `∑ x, p x = 1`) and a +tolerance `ε`, a length-`n` sequence `s : Fin n → α` is **`ε`-typical** when its `n`-fold i.i.d. +product probability `∏ i, p (s i)` is squeezed between `exp (-n (H + ε))` and `exp (-n (H - ε))`, +where `H = Real.entropy p` is the Shannon entropy (in nats). This is Nielsen & Chuang's primary +definition (their Eq. 12.26), the natural-logarithm form of `2^{-n(H+ε)} ≤ p ≤ 2^{-n(H-ε)}` (the +base-`2` version is the same statement rescaled). We record it as the `Finset` + +`Real.typicalSeq p n ε : Finset (Fin n → α)`, + +so that `(typicalSeq p n ε).card` is `|T(n, ε)|`. Because the lower bound is a strictly positive +exponential, zero-probability sequences are automatically excluded — which is exactly why the +multiplicative form (12.26), rather than the additive surprisal form (12.27), is the honest primary +definition: on the support the two coincide (`mem_typicalSeq_iff_abs_le`), but a letter of +probability `0` has surprisal `-log 0 = 0` and would spuriously satisfy the additive form. + +Building on the finite i.i.d. Chebyshev concentration bound `Real.iid_average_deviation_le` +(`ToMathlib/InformationTheory/IIDConcentration.lean`), applied to the surprisal `g x = -log (p x)` +whose mean is `H`, this file proves **Nielsen & Chuang, Theorem 12.2**, parts (1) and (2). + +## Main results + +- `Real.typicalSeq`: the `ε`-typical set (Eq. 12.26). +- `Real.mem_typicalSeq`: its membership predicate. +- `Real.mem_typicalSeq_iff_abs_le`: on the support (`0 < ∏ i, p (s i)`), typicality is equivalent to + the additive surprisal form `|(∑ i, -log (p (s i)))/n - H| ≤ ε` (Eq. 12.26 ↔ 12.27). +- `Real.sum_typicalSeq_ge`: **part (1), quantitative** — the probability that a sequence is typical + is at least `1 - V/(n ε²)`, where `V = ∑ x, p x (-log (p x) - H)²` is the surprisal variance. +- `Real.exists_le_sum_typicalSeq`: **part (1), Nielsen–Chuang form** — for any `δ > 0`, for all + sufficiently large `n`, that probability is at least `1 - δ`. +- `Real.card_typicalSeq_le`: **part (2), upper bound** — `|T(n, ε)| ≤ exp (n (H + ε))`, for every + `n` (Eq. 12.28, right). +- `Real.card_typicalSeq_ge_of_le_sum`: **part (2), lower bound** — whenever the typicality + probability is at least `1 - δ`, `(1 - δ) exp (n (H - ε)) ≤ |T(n, ε)|` (Eq. 12.28, left). +- `Real.exists_card_typicalSeq_bounds`: **part (2), Nielsen–Chuang form** — for any `δ > 0`, for all + sufficiently large `n`, both cardinality bounds of Eq. 12.28 hold. +- `Real.exists_sum_weighted_prod_le_of_sum_le_exp`: **part (3), the small-set bound, weighted form** + — for a rate `R < H` and any `δ > 0`, for all sufficiently large `n` *every* family of weights + `w : (Fin n → α) → ℝ` with `0 ≤ w s ≤ 1` and `∑ s, w s ≤ exp (n R)` has `∑ s, w s · ∏ p ≤ δ`. The + proof splits at the `ε`-typical set (`ε = (H - R)/2`): the atypical part is small by part (1) + (weights `≤ 1`), and the typical part has total weight `≤ exp (n R)` with each factor `≤ exp + (-n (H - ε))`. The fractional weights are what the quantum typical subspace theorem (Thm 12.5 (3)) + needs. +- `Real.exists_sum_prod_le_of_card_le_exp`: **part (3), the small-set bound** (Eq. 12.29) — the + `0/1`-indicator special case: for `R < H`, `δ > 0`, large `n`, *every* collection `S` with + `|S| ≤ exp (n R)` carries total probability `∑ s ∈ S, ∏ p ≤ δ`. +-/ + +@[expose] public section + +open Finset + +namespace Real + +variable {α : Type*} [Fintype α] + +open Classical in +/-- The set `T(n, ε)` of **`ε`-typical** length-`n` sequences for the i.i.d. source `p` +(Nielsen & Chuang, Eq. 12.26): those `s : Fin n → α` whose product probability `∏ i, p (s i)` lies +between `exp (-n (H + ε))` and `exp (-n (H - ε))`, with `H = entropy p`. The lower bound being a +positive exponential, this automatically excludes zero-probability sequences. -/ +noncomputable def typicalSeq (p : α → ℝ) (n : ℕ) (ε : ℝ) : Finset (Fin n → α) := + univ.filter fun s => Real.exp (-(n : ℝ) * (entropy p + ε)) ≤ ∏ i, p (s i) ∧ + ∏ i, p (s i) ≤ Real.exp (-(n : ℝ) * (entropy p - ε)) + +/-- Membership in the `ε`-typical set: `s` is typical iff its product probability is squeezed +between `exp (-n (H + ε))` and `exp (-n (H - ε))`. -/ +theorem mem_typicalSeq {p : α → ℝ} {n : ℕ} {ε : ℝ} {s : Fin n → α} : + s ∈ typicalSeq p n ε ↔ + Real.exp (-(n : ℝ) * (entropy p + ε)) ≤ ∏ i, p (s i) ∧ + ∏ i, p (s i) ≤ Real.exp (-(n : ℝ) * (entropy p - ε)) := by + simp only [typicalSeq, mem_filter, mem_univ, true_and] + +/-- **Eq. 12.26 ↔ Eq. 12.27.** On the support of the product distribution (`0 < ∏ i, p (s i)`, i.e. +`p (s i) > 0` for all `i`), `s` is `ε`-typical iff its per-symbol empirical surprisal +`(∑ i, -log (p (s i)))/n` is within `ε` of the entropy `H = entropy p`. This is the equivalence +between the multiplicative definition and the additive reformulation, valid precisely on the +support (where `log (∏ i, p (s i)) = ∑ i, log (p (s i))`). -/ +theorem mem_typicalSeq_iff_abs_le {p : α → ℝ} {n : ℕ} (hn : 0 < n) {ε : ℝ} + {s : Fin n → α} (hpos : 0 < ∏ i, p (s i)) : + s ∈ typicalSeq p n ε ↔ + |(∑ i, -Real.log (p (s i))) / (n : ℝ) - entropy p| ≤ ε := by + have hn0 : (0 : ℝ) < n := by exact_mod_cast hn + have hnne : (n : ℝ) ≠ 0 := hn0.ne' + have hne : ∀ i, p (s i) ≠ 0 := fun i => + (Finset.prod_ne_zero_iff.mp hpos.ne') i (mem_univ i) + have hsum : (∑ i, -Real.log (p (s i))) = -Real.log (∏ i, p (s i)) := by + rw [Real.log_prod (fun x _ => hne x)] + exact Finset.sum_neg_distrib _ + rw [mem_typicalSeq, ← Real.le_log_iff_exp_le hpos, ← Real.log_le_iff_le_exp hpos] + set L := Real.log (∏ i, p (s i)) + rw [hsum] + have hfrac : (-L) / (n : ℝ) - entropy p = (-L - entropy p * n) / n := by field_simp + rw [hfrac, abs_div, abs_of_pos hn0, div_le_iff₀ hn0, abs_le] + constructor + · rintro ⟨h1, h2⟩; constructor <;> nlinarith + · rintro ⟨h1, h2⟩; constructor <;> nlinarith + +/-- **Nielsen & Chuang, Theorem 12.2 (1), quantitative form.** The probability that a length-`n` +sequence is `ε`-typical is at least `1 - V/(n ε²)`, where `V = ∑ x, p x (-log (p x) - H)²` is the +per-symbol surprisal variance. As `n → ∞` this tends to `1` (see `exists_le_sum_typicalSeq`). + +The proof bounds the complement mass: the atypical set is pulled back, via +`mem_typicalSeq_iff_abs_le`, into the empirical-surprisal large-deviation set, whose mass the +Chebyshev engine `iid_average_deviation_le` bounds by `V/(n ε²)`; the total mass is `1`. -/ +theorem sum_typicalSeq_ge {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : + 1 - (∑ x, p x * (-Real.log (p x) - entropy p) ^ 2) / (n * ε ^ 2) + ≤ ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) := by + classical + have hcompl : ∑ s ∈ univ \ typicalSeq p n ε, ∏ i, p (s i) + ≤ (∑ x, p x * (-Real.log (p x) - entropy p) ^ 2) / (n * ε ^ 2) := by + set g : α → ℝ := fun x => -Real.log (p x) with hg + have hm : entropy p = ∑ x, p x * g x := by + simp only [hg] + rw [entropy_eq_neg_sum_mul_log, ← Finset.sum_neg_distrib] + simp only [mul_neg] + have hdev := iid_average_deviation_le p g hp0 hp1 hm hn hε + refine le_trans ?_ hdev + rw [Finset.sdiff_eq_filter, Finset.sum_filter, Finset.sum_filter] + refine Finset.sum_le_sum fun s _ => ?_ + have hnn : (0 : ℝ) ≤ ∏ i, p (s i) := Finset.prod_nonneg fun i _ => hp0 _ + have hRHSnn : (0 : ℝ) ≤ + (if ε < |(∑ i, g (s i)) / (n : ℝ) - entropy p| then ∏ i, p (s i) else 0) := by + split_ifs <;> first | exact hnn | exact le_refl 0 + by_cases hT : s ∈ typicalSeq p n ε + · rw [ite_eq_right (not_not.mpr hT)]; exact hRHSnn + · rw [ite_eq_left hT] + rcases hnn.eq_or_lt with hz | hpos + · exact hz.symm.le.trans hRHSnn + · have hnotle : ¬ |(∑ i, -Real.log (p (s i))) / (n : ℝ) - entropy p| ≤ ε := fun hle => + hT ((mem_typicalSeq_iff_abs_le hn hpos).mpr hle) + have hB : ε < |(∑ i, g (s i)) / (n : ℝ) - entropy p| := + not_le.mp (by simpa only [hg] using hnotle) + exact (ite_eq_left hB).ge + have htotal : ∑ s : Fin n → α, ∏ i, p (s i) = 1 := by rw [iid_total_mass, hp1, one_pow] + have hsplit : ∑ s ∈ univ \ typicalSeq p n ε, ∏ i, p (s i) + + ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) = 1 := by + rw [Finset.sum_sdiff (Finset.subset_univ _)]; exact htotal + linarith + +/-- **Nielsen & Chuang, Theorem 12.2 (2), upper bound** (Eq. 12.28, right). For every `n`, the +number of `ε`-typical sequences satisfies `|T(n, ε)| ≤ exp (n (H + ε))`. Each typical sequence has +probability at least `exp (-n (H + ε))`, and the typical sequences carry total probability at most +`1`, so `|T(n, ε)| · exp (-n (H + ε)) ≤ 1`. -/ +theorem card_typicalSeq_le {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {n : ℕ} {ε : ℝ} : + ((typicalSeq p n ε).card : ℝ) ≤ Real.exp (n * (entropy p + ε)) := by + have hnn : ∀ s : Fin n → α, (0 : ℝ) ≤ ∏ i, p (s i) := fun s => Finset.prod_nonneg fun i _ => hp0 _ + have htotal : ∑ s : Fin n → α, ∏ i, p (s i) = 1 := by rw [iid_total_mass, hp1, one_pow] + have hsum_le_one : ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) ≤ 1 := by + rw [← htotal] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) fun s _ _ => hnn s + have hlb : ((typicalSeq p n ε).card : ℝ) * Real.exp (-(n : ℝ) * (entropy p + ε)) + ≤ ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) := by + rw [← nsmul_eq_mul, ← Finset.sum_const] + exact Finset.sum_le_sum fun s hs => (mem_typicalSeq.mp hs).1 + have hexp : Real.exp (-(n : ℝ) * (entropy p + ε)) = (Real.exp (n * (entropy p + ε)))⁻¹ := by + rw [neg_mul, Real.exp_neg] + rw [hexp] at hlb + have hcard : ((typicalSeq p n ε).card : ℝ) / Real.exp (n * (entropy p + ε)) ≤ 1 := by + rw [div_eq_mul_inv]; exact hlb.trans hsum_le_one + rw [div_le_iff₀ (Real.exp_pos _)] at hcard + simpa using hcard + +/-- **Nielsen & Chuang, Theorem 12.2 (2), lower bound** (Eq. 12.28, left). Whenever the typicality +probability is at least `1 - δ`, the number of `ε`-typical sequences satisfies +`(1 - δ) exp (n (H - ε)) ≤ |T(n, ε)|`. Each typical sequence has probability at most +`exp (-n (H - ε))`, so `1 - δ ≤ |T(n, ε)| · exp (-n (H - ε))`. Fed the large-`n` typicality +probability of `exists_le_sum_typicalSeq`, this yields the Eq. 12.28 lower bound. -/ +theorem card_typicalSeq_ge_of_le_sum {p : α → ℝ} {n : ℕ} {ε : ℝ} {δ : ℝ} + (h : 1 - δ ≤ ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i)) : + (1 - δ) * Real.exp (n * (entropy p - ε)) ≤ ((typicalSeq p n ε).card : ℝ) := by + have hub : ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) + ≤ ((typicalSeq p n ε).card : ℝ) * Real.exp (-(n : ℝ) * (entropy p - ε)) := by + rw [← nsmul_eq_mul, ← Finset.sum_const] + exact Finset.sum_le_sum fun s hs => (mem_typicalSeq.mp hs).2 + have h1 : 1 - δ ≤ ((typicalSeq p n ε).card : ℝ) * Real.exp (-(n : ℝ) * (entropy p - ε)) := + h.trans hub + have hb := mul_le_mul_of_nonneg_right h1 (Real.exp_pos ((n : ℝ) * (entropy p - ε))).le + have hexp0 : Real.exp (-(n : ℝ) * (entropy p - ε)) * Real.exp ((n : ℝ) * (entropy p - ε)) = 1 := + by rw [← Real.exp_add, neg_mul, neg_add_cancel, Real.exp_zero] + rw [mul_assoc, hexp0, mul_one] at hb + exact hb + +/-- **Nielsen & Chuang, Theorem 12.2 (1), Nielsen–Chuang form.** Fix `ε > 0`. For any `δ > 0`, for +all sufficiently large `n`, the probability that a sequence is `ε`-typical is at least `1 - δ`. +This packages the quantitative bound `sum_typicalSeq_ge` with the Archimedean fact that +`V/(n ε²) → 0`. -/ +theorem exists_le_sum_typicalSeq {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {ε : ℝ} (hε : 0 < ε) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, 1 - δ ≤ ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) := by + set V := ∑ x, p x * (-Real.log (p x) - entropy p) ^ 2 + have hVnn : 0 ≤ V := Finset.sum_nonneg fun x _ => mul_nonneg (hp0 x) (sq_nonneg _) + have hden : (0 : ℝ) < δ * ε ^ 2 := by positivity + obtain ⟨N₀, hN₀⟩ := exists_nat_ge (V / (δ * ε ^ 2)) + refine ⟨max 1 N₀, lt_of_lt_of_le one_pos (le_max_left _ _), fun n hn => ?_⟩ + have hnpos : 0 < n := lt_of_lt_of_le one_pos (le_trans (le_max_left 1 N₀) hn) + have hn0 : (0 : ℝ) < n := by exact_mod_cast hnpos + have hquant := sum_typicalSeq_ge hp0 hp1 hnpos hε + have hle : V / (n * ε ^ 2) ≤ δ := by + have hthis : V / (δ * ε ^ 2) ≤ n := + le_trans hN₀ (by exact_mod_cast le_trans (le_max_right 1 N₀) hn) + have hVn : V ≤ (n : ℝ) * (δ * ε ^ 2) := + calc V = V / (δ * ε ^ 2) * (δ * ε ^ 2) := (div_mul_cancel₀ V hden.ne').symm + _ ≤ (n : ℝ) * (δ * ε ^ 2) := mul_le_mul_of_nonneg_right hthis hden.le + rw [div_le_iff₀ (by positivity : (0 : ℝ) < (n : ℝ) * ε ^ 2)] + nlinarith [hVn] + linarith + +/-- **Nielsen & Chuang, Theorem 12.2 (2), Nielsen–Chuang form** (Eq. 12.28). Fix `ε > 0`. For any +`δ > 0`, for all sufficiently large `n`, the number of `ε`-typical sequences satisfies +`(1 - δ) exp (n (H - ε)) ≤ |T(n, ε)| ≤ exp (n (H + ε))`. The upper bound holds for every `n` +(`card_typicalSeq_le`); the lower bound uses the large-`n` typicality probability +(`exists_le_sum_typicalSeq` feeding `card_typicalSeq_ge_of_le_sum`). -/ +theorem exists_card_typicalSeq_bounds {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {ε : ℝ} (hε : 0 < ε) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, + (1 - δ) * Real.exp (n * (entropy p - ε)) ≤ ((typicalSeq p n ε).card : ℝ) ∧ + ((typicalSeq p n ε).card : ℝ) ≤ Real.exp (n * (entropy p + ε)) := by + obtain ⟨N, hNpos, hN⟩ := exists_le_sum_typicalSeq hp0 hp1 hε hδ + exact ⟨N, hNpos, fun n hn => ⟨card_typicalSeq_ge_of_le_sum (hN n hn), + card_typicalSeq_le hp0 hp1⟩⟩ + +/-- **Weighted small-set bound** — the fractional-weight generalisation of the small-set bound +`exists_sum_prod_le_of_card_le_exp` (which is recovered from it below, at `0/1` indicator weights). +Fix a rate `R < entropy p`. For any `δ > 0`, for all sufficiently large `n`, *every* family of +weights `w : (Fin n → α) → ℝ` with `0 ≤ w s ≤ 1` and total weight `∑ s, w s ≤ exp (n R)` carries +weighted probability at most `δ`: `∑ s, w s * ∏ i, p (s i) ≤ δ`. + +The fractional generality is what the *quantum* typical subspace theorem (Nielsen & Chuang, Theorem +12.5 (3)) needs: there the weights are the eigenbasis-diagonal matrix elements +`w κ = ⟨e_κ, S(n) e_κ⟩ ∈ [0, 1]` of an arbitrary projector `S(n)` of rank +`∑ κ, w κ = tr S(n) ≤ exp (n R)`, and `∑ κ, w κ · ∏ᵢ λ(κᵢ) = tr(S(n) ρ^⊗n)` is exactly its overlap +with the source `ρ^⊗n`. + +The proof follows Nielsen & Chuang (`ε = (H - R)/2`), splitting the sum at the `ε`-typical set `T`: +the atypical part `∑_{s ∉ T} w s · ∏ p ≤ ∑_{s ∉ T} ∏ p ≤ δ/2` (weights `≤ 1`; part (1)); the typical +part `∑_{s ∈ T} w s · ∏ p ≤ (∑_{s ∈ T} w s) · exp(-n(H-ε)) ≤ exp(nR)·exp(-n(H-ε)) = exp(-nε) ≤ δ/2` +(each typical `∏ p ≤ exp(-n(H-ε))`; total weight `≤ exp(nR)`). -/ +theorem exists_sum_weighted_prod_le_of_sum_le_exp {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) + (hp1 : ∑ x, p x = 1) {R : ℝ} (hR : R < entropy p) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, ∀ w : (Fin n → α) → ℝ, (∀ s, 0 ≤ w s) → (∀ s, w s ≤ 1) → + ∑ s, w s ≤ Real.exp (n * R) → ∑ s, w s * ∏ i, p (s i) ≤ δ := by + classical + set H := entropy p with hH + set ε := (H - R) / 2 with hε + have hεpos : 0 < ε := by rw [hε]; linarith + have hδ2 : (0 : ℝ) < δ / 2 := by positivity + obtain ⟨N₁, hN₁pos, hN₁⟩ := exists_le_sum_typicalSeq hp0 hp1 hεpos hδ2 + obtain ⟨N₂, hN₂⟩ := exists_nat_ge (-Real.log (δ / 2) / ε) + refine ⟨max N₁ N₂, lt_of_lt_of_le hN₁pos (le_max_left _ _), fun n hn w hw0 hw1 hwsum => ?_⟩ + have hnN₁ : N₁ ≤ n := le_trans (le_max_left _ _) hn + have hnN₂ : N₂ ≤ n := le_trans (le_max_right _ _) hn + have hnn : ∀ s : Fin n → α, (0 : ℝ) ≤ ∏ i, p (s i) := fun s => Finset.prod_nonneg fun i _ => hp0 _ + -- split the full sum at the `ε`-typical set `T`. + have hsplit : ∑ s, w s * ∏ i, p (s i) + = (∑ s ∈ typicalSeq p n ε, w s * ∏ i, p (s i)) + + ∑ s ∈ univ \ typicalSeq p n ε, w s * ∏ i, p (s i) := by + rw [← Finset.sum_sdiff (Finset.subset_univ (typicalSeq p n ε))]; ring + -- atypical part: weights `≤ 1`, so bounded by the atypical mass `1 - ∑_T ≤ δ/2` (part (1)). + have hatyp : ∑ s ∈ univ \ typicalSeq p n ε, w s * ∏ i, p (s i) ≤ δ / 2 := by + have hsub : ∑ s ∈ univ \ typicalSeq p n ε, w s * ∏ i, p (s i) + ≤ ∑ s ∈ univ \ typicalSeq p n ε, ∏ i, p (s i) := by + exact Finset.sum_le_sum fun s _ => mul_le_of_le_one_left (hnn s) (hw1 s) + have htotal : ∑ s : Fin n → α, ∏ i, p (s i) = 1 := by rw [iid_total_mass, hp1, one_pow] + have hcompl : ∑ s ∈ univ \ typicalSeq p n ε, ∏ i, p (s i) + + ∑ s ∈ typicalSeq p n ε, ∏ i, p (s i) = 1 := by + rw [Finset.sum_sdiff (Finset.subset_univ _)]; exact htotal + have hprob := hN₁ n hnN₁ + linarith + -- typical part: each `∏ p ≤ exp(-n(H-ε))` and the total weight `≤ exp(nR)`. + have htyp : ∑ s ∈ typicalSeq p n ε, w s * ∏ i, p (s i) ≤ δ / 2 := by + have hmem : ∑ s ∈ typicalSeq p n ε, w s * ∏ i, p (s i) + ≤ (∑ s ∈ typicalSeq p n ε, w s) * Real.exp (-(n : ℝ) * (H - ε)) := by + rw [Finset.sum_mul] + refine Finset.sum_le_sum fun s hs => ?_ + exact mul_le_mul_of_nonneg_left (mem_typicalSeq.mp hs).2 (hw0 s) + have hwt : (∑ s ∈ typicalSeq p n ε, w s) ≤ Real.exp (n * R) := + le_trans (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun s _ _ => hw0 s)) hwsum + have hcombine : Real.exp (n * R) * Real.exp (-(n : ℝ) * (H - ε)) + = Real.exp (-((n : ℝ) * ε)) := by + rw [← Real.exp_add]; congr 1; rw [hε]; ring + have hle : Real.exp (-((n : ℝ) * ε)) ≤ δ / 2 := + calc Real.exp (-((n : ℝ) * ε)) + ≤ Real.exp (Real.log (δ / 2)) := by + refine Real.exp_le_exp.mpr ?_ + have h1 : -Real.log (δ / 2) / ε ≤ (n : ℝ) := le_trans hN₂ (by exact_mod_cast hnN₂) + rw [div_le_iff₀ hεpos] at h1 + linarith + _ = δ / 2 := Real.exp_log hδ2 + calc ∑ s ∈ typicalSeq p n ε, w s * ∏ i, p (s i) + ≤ (∑ s ∈ typicalSeq p n ε, w s) * Real.exp (-(n : ℝ) * (H - ε)) := hmem + _ ≤ Real.exp (n * R) * Real.exp (-(n : ℝ) * (H - ε)) := + mul_le_mul_of_nonneg_right hwt (Real.exp_pos _).le + _ = Real.exp (-((n : ℝ) * ε)) := hcombine + _ ≤ δ / 2 := hle + rw [hsplit]; linarith + +/-- **Nielsen & Chuang, Theorem 12.2 (3)** (Eq. 12.29, the small-set bound). Fix a rate `R` strictly +below the entropy (`R < entropy p`). For any `δ > 0`, for all sufficiently large `n`, *every* +collection `S` of length-`n` sequences with at most `exp (n R)` members carries total probability at +most `δ`: `∑ s ∈ S, ∏ i, p (s i) ≤ δ`. (In Nielsen & Chuang's base-`2` normalisation the size bound +reads `|S(n)| ≤ 2^{n R}`; here the entropy and the exponentials are in nats, the same statement +rescaled by `log 2`.) + +The special case of the weighted bound `exists_sum_weighted_prod_le_of_sum_le_exp` at the `0/1` +indicator weight `w s = if s ∈ S then 1 else 0`, for which `∑ s, w s = |S| ≤ exp (n R)` and +`∑ s, w s · ∏ p = ∑_{s ∈ S} ∏ p`. -/ +theorem exists_sum_prod_le_of_card_le_exp {p : α → ℝ} (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) + {R : ℝ} (hR : R < entropy p) {δ : ℝ} (hδ : 0 < δ) : + ∃ N : ℕ, 0 < N ∧ ∀ n ≥ N, ∀ S : Finset (Fin n → α), + (S.card : ℝ) ≤ Real.exp (n * R) → ∑ s ∈ S, ∏ i, p (s i) ≤ δ := by + classical + obtain ⟨N, hNpos, hN⟩ := exists_sum_weighted_prod_le_of_sum_le_exp hp0 hp1 hR hδ + refine ⟨N, hNpos, fun n hn S hScard => ?_⟩ + -- `∑ s, (if s ∈ S then 1 else 0) = |S|`. + have hcard : ∑ s, (if s ∈ S then (1 : ℝ) else 0) = (S.card : ℝ) := by + rw [Finset.sum_ite_mem, Finset.univ_inter, Finset.sum_const, nsmul_eq_mul, mul_one] + -- Apply the weighted bound at the `0/1` indicator of `S`. + have key := hN n hn (fun s => if s ∈ S then (1 : ℝ) else 0) (fun s => by positivity) + (fun s => by split <;> norm_num) (by rw [hcard]; exact hScard) + -- The weighted mass over the indicator is the plain mass over `S`. + simpa only [ite_mul, one_mul, zero_mul, Finset.sum_ite_mem, Finset.univ_inter] using key + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashEntropy.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashEntropy.lean new file mode 100644 index 0000000000..af8691df70 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashEntropy.lean @@ -0,0 +1,202 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.UniversalHashing +public import Mathlib.Analysis.Convex.Jensen +public import Mathlib.Analysis.Convex.SpecificFunctions.Basic + +/-! +# Conditional collision and Shannon entropy of a universal-hash output + +Continuing `ToMathlib/InformationTheory/UniversalHashing.lean`, this file assembles the two ordering +inequalities of Nielsen & Chuang's privacy-amplification theorem (§12.6, Theorem 12.16) for the +output `G(X)` of a universal hash family `h` applied to an input `X`, with the hash `G` chosen +uniformly at random from the finite family. + +Writing `g(X)` for the push-forward `Real.law p (h g)` of the input distribution `p : α → ℝ`, the +two `G`-conditional entropies (with `G` uniform on the finite index type `γ`) are: + +* `Real.avgCollisionEntropy h p := -Real.logb 2 (Real.avgCollisionProb h p)` — the conditional + collision entropy `Hc(G(X) | G)` in the privacy-amplification convention: `-log₂` of the + **average** collision probability `E_G[Pc(g(X))]` (the convention of + Bennett–Brassard–Crépeau–Maurer for which the theorem holds). This is `-log₂` of an average, + **not** the average of the per-`g` collision entropies. +* `Real.avgShannonEntropy h p := (∑_g H(g(X))) / (|γ| · log 2)` — the conditional Shannon entropy + `H(G(X) | G)` in bits, the genuine average over `g` of the per-`g` Shannon entropies. + +## Main results + +* `Real.avgCollisionProb_pos`: the average collision probability is strictly positive (each + push-forward `g(X)` is a probability distribution, so `Pc(g(X)) > 0`), so its `log₂` is defined. +* `Real.avgCollisionEntropy_ge` — **the corrected (honest) lower bound**, the second inequality of + Theorem 12.16 with Nielsen & Chuang's constant repaired: for a universal family and any input `p`, + `Hc(G(X)|G) ≥ log₂|β| - log₂(1 + |β|·Pc(X))`, where `Pc(X) = Real.collisionProb p`. Writing + `m = log₂|β|` and `2^{m-Hc(X)} = |β|·Pc(X)`, this is `m - log₂(1 + 2^{m-Hc(X)})`. Nielsen & Chuang + state instead the strictly larger `m - 2^{m-Hc(X)}`, which is **false** (they drop the `1/ln 2` + factor in `log₂(1 + z) ≤ z / ln 2`, and `log₂(1 + z) > z` for `0 < z < 1`); the counterexample + refuting the literal constant is developed separately. +* `Real.avgCollisionEntropy_le_avgShannonEntropy` — **the first inequality** of the chain, + `H(G(X)|G) ≥ Hc(G(X)|G)`. + Per `g`, `-log Pc(g(X)) ≤ H(g(X))` (`Real.log_collisionProb_inv_le_entropy`, the nat-log form of + `Hc(g(X)) ≤ H(g(X))`); averaging over `g` and applying Jensen's inequality to the concave + `Real.log` (so `-log₂` of the average collision probability is at most the average of the per-`g` + collision entropies) chains these into the conditional statement. + +The honest bound `avgCollisionEntropy_ge` is the engine of the assembled faithful statement of +Theorem 12.16. +-/ + +@[expose] public section + +namespace Real + +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] [DecidableEq β] + +omit [Fintype γ] in +/-- The push-forward `law p (h g)` of a probability distribution `p` is again a probability +distribution: `∑_y law p (h g) y = 1`. -/ +private theorem sum_law_hash {h : γ → α → β} {p : α → ℝ} (hsum : ∑ x, p x = 1) (g : γ) : + ∑ y, law p (h g) y = 1 := by rw [sum_law]; exact hsum + +omit [Fintype γ] in +/-- Each hashed collision probability `Pc(g(X)) = collisionProb (law p (h g))` is strictly positive, +since `law p (h g)` is a probability distribution. -/ +theorem collisionProb_law_pos {h : γ → α → β} {p : α → ℝ} (hsum : ∑ x, p x = 1) (g : γ) : + 0 < collisionProb (law p (h g)) := + collisionProb_pos (sum_law_hash hsum g) + +/-- The **average collision probability is strictly positive** (for a nonempty family and a genuine +input distribution): a positive average of the strictly positive per-`g` collision probabilities. It +guarantees `Real.logb 2 (avgCollisionProb h p)` is a genuine logarithm of a positive number. -/ +theorem avgCollisionProb_pos [Nonempty γ] {h : γ → α → β} {p : α → ℝ} (hsum : ∑ x, p x = 1) : + 0 < avgCollisionProb h p := by + rw [avgCollisionProb_eq] + refine div_pos (Finset.sum_pos (fun g _ => collisionProb_law_pos hsum g) Finset.univ_nonempty) ?_ + exact_mod_cast Fintype.card_pos + +/-- The **conditional collision entropy** `Hc(G(X) | G)` of the output of a hash family `h` on an +input distribution `p`, with the hash `G` chosen uniformly: `-log₂` of the average collision +probability (privacy-amplification convention). Note this is `-log₂` of an average, not the average +of the per-`g` collision entropies. -/ +noncomputable def avgCollisionEntropy (h : γ → α → β) (p : α → ℝ) : ℝ := + -Real.logb 2 (avgCollisionProb h p) + +/-- Unfolding lemma for `avgCollisionEntropy`: `Hc(G(X)|G) = -log₂ (avgCollisionProb h p)`. -/ +theorem avgCollisionEntropy_eq (h : γ → α → β) (p : α → ℝ) : + avgCollisionEntropy h p = -Real.logb 2 (avgCollisionProb h p) := rfl + +/-- The **conditional Shannon entropy** `H(G(X) | G)` of the output of a hash family `h` on an input +distribution `p`, in bits, with the hash `G` chosen uniformly: the average over `g` of the per-`g` +Shannon entropies `H(g(X)) = entropy (law p (h g))`, converted to bits by dividing by `log 2`. + +This coincides with the general conditional Shannon entropy `Real.condEntropyMap` +(`H(f | g) = H(f, g) − H(g)`) instantiated over `Ω = γ × α` with the uniform-`G` joint weight +`(g, x) ↦ |γ|⁻¹ · p x`, output `(g, x) ↦ h g x`, and side variable `Prod.fst` — up to the bits/nats +`1 / log 2` factor (`condEntropyMap` is in nats), since conditional entropy is the average of the +per-block entropies. The direct bits-average is used here to keep bits throughout (matching +`avgCollisionEntropy` and `m = log₂|β|`) and to avoid the `[DecidableEq γ]` instance that +`Real.condEntropyMap` would force. -/ +noncomputable def avgShannonEntropy (h : γ → α → β) (p : α → ℝ) : ℝ := + (∑ g, entropy (law p (h g))) / (Fintype.card γ * Real.log 2) + +/-- Unfolding lemma for `avgShannonEntropy`: +`H(G(X)|G) = (∑_g entropy (law p (h g))) / (|γ| · log 2)`. -/ +theorem avgShannonEntropy_eq (h : γ → α → β) (p : α → ℝ) : + avgShannonEntropy h p = (∑ g, entropy (law p (h g))) / (Fintype.card γ * Real.log 2) := rfl + +/-- **The corrected (honest) lower bound on the conditional collision entropy** (Nielsen & Chuang +§12.6, Theorem 12.16, second inequality — with the literal constant repaired). For a (2-)universal +family `h : γ → α → β` and any input probability distribution `p`, +`Hc(G(X)|G) ≥ log₂|β| - log₂(1 + |β|·Pc(X))`, where `Pc(X) = collisionProb p`. + +Writing `m = log₂|β|` (the number of output bits) and `2^{m-Hc(X)} = |β|·Pc(X)`, the right-hand side +is `m - log₂(1 + 2^{m-Hc(X)})`. This is strictly weaker than Nielsen & Chuang's stated +`m - 2^{m-Hc(X)}`, which is **false**: `log₂(1 + z) > z` for `0 < z < 1`, so the textbook's linear +constant over-states the true bound (the discrepancy is exactly the `1/ln 2` factor dropped from +`log₂(1 + z) ≤ z / ln 2`). The refutation of the literal constant is developed separately. + +Proof: the leftover-hash bound `avgCollisionProb h p ≤ |β|⁻¹ + Pc(X)` (`avgCollisionProb_le`), +monotonicity of `log₂`, and the factorisation `|β|⁻¹ + Pc = |β|⁻¹·(1 + |β|·Pc)`. -/ +theorem avgCollisionEntropy_ge [Nonempty β] [Nonempty γ] {h : γ → α → β} (hu : IsUniversalFamily h) + {p : α → ℝ} (h0 : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) : + Real.logb 2 (Fintype.card β) - Real.logb 2 (1 + Fintype.card β * collisionProb p) + ≤ avgCollisionEntropy h p := by + have hβ : (0 : ℝ) < Fintype.card β := by exact_mod_cast Fintype.card_pos + have hβne : (Fintype.card β : ℝ) ≠ 0 := ne_of_gt hβ + have hApos : 0 < avgCollisionProb h p := avgCollisionProb_pos hsum + have hPc : 0 ≤ collisionProb p := collisionProb_nonneg p + have hfac : 0 < 1 + Fintype.card β * collisionProb p := by positivity + -- The leftover-hash bound and monotonicity of `log₂`. + have hlog : Real.logb 2 (avgCollisionProb h p) + ≤ Real.logb 2 ((Fintype.card β : ℝ)⁻¹ + collisionProb p) := + Real.logb_le_logb_of_le (by norm_num) hApos (avgCollisionProb_le hu h0 hsum) + -- Factor the bound: `|β|⁻¹ + Pc = |β|⁻¹·(1 + |β|·Pc)`, and split the `log₂`. + have hBfac : (Fintype.card β : ℝ)⁻¹ + collisionProb p + = (Fintype.card β : ℝ)⁻¹ * (1 + Fintype.card β * collisionProb p) := by + rw [mul_add, mul_one, ← mul_assoc, inv_mul_cancel₀ hβne, one_mul] + have hlogB : Real.logb 2 ((Fintype.card β : ℝ)⁻¹ + collisionProb p) + = -Real.logb 2 (Fintype.card β) + Real.logb 2 (1 + Fintype.card β * collisionProb p) := by + rw [hBfac, Real.logb_mul (inv_ne_zero hβne) (ne_of_gt hfac), Real.logb_inv] + rw [avgCollisionEntropy_eq] + rw [hlogB] at hlog + linarith + +/-- **The first inequality** of Nielsen & Chuang Theorem 12.16: `H(G(X)|G) ≥ Hc(G(X)|G)`, the +conditional Shannon entropy of the hashed output dominates its conditional collision entropy. Per +`g`, `-log Pc(g(X)) ≤ H(g(X))` (`log_collisionProb_inv_le_entropy`, the nat-log form of +`Hc(g(X)) ≤ H(g(X))`); the conditional statement is obtained by averaging over `g` and applying +Jensen's inequality to the concave `Real.log` — `-log₂` of the average collision probability is at +most the average of the per-`g` collision entropies. -/ +theorem avgCollisionEntropy_le_avgShannonEntropy [Nonempty γ] {h : γ → α → β} {p : α → ℝ} + (h0 : ∀ x, 0 ≤ p x) (hsum : ∑ x, p x = 1) : + avgCollisionEntropy h p ≤ avgShannonEntropy h p := by + have hγ : (0 : ℝ) < Fintype.card γ := by exact_mod_cast Fintype.card_pos + have hγne : (Fintype.card γ : ℝ) ≠ 0 := ne_of_gt hγ + have hlog2 : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + -- Jensen for the concave `log`: `∑_g |γ|⁻¹ • log Pc_g ≤ log (∑_g |γ|⁻¹ • Pc_g)`. + have hjensen : ∑ g, (Fintype.card γ : ℝ)⁻¹ • Real.log (collisionProb (law p (h g))) + ≤ Real.log (∑ g, (Fintype.card γ : ℝ)⁻¹ • collisionProb (law p (h g))) := by + refine (strictConcaveOn_log_Ioi.concaveOn).le_map_sum (fun g _ => by positivity) ?_ + (fun g _ => Set.mem_Ioi.mpr (collisionProb_law_pos hsum g)) + rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_inv_cancel₀ hγne] + -- Identify the two `|γ|⁻¹`-weighted sums. + have hsum_prob : ∑ g, (Fintype.card γ : ℝ)⁻¹ • collisionProb (law p (h g)) + = avgCollisionProb h p := by + rw [avgCollisionProb_eq, div_eq_inv_mul, Finset.mul_sum] + exact Finset.sum_congr rfl fun g _ => smul_eq_mul _ _ + have hsum_log : ∑ g, (Fintype.card γ : ℝ)⁻¹ • Real.log (collisionProb (law p (h g))) + = (∑ g, Real.log (collisionProb (law p (h g)))) / Fintype.card γ := by + rw [div_eq_inv_mul, Finset.mul_sum] + exact Finset.sum_congr rfl fun g _ => smul_eq_mul _ _ + rw [hsum_prob, hsum_log] at hjensen + -- Per-`g` first inequality (nat-log form): `-log Pc_g ≤ H(g(X))`. + have hperg : ∀ g, -Real.log (collisionProb (law p (h g))) ≤ entropy (law p (h g)) := by + intro g + have hh := log_collisionProb_inv_le_entropy (law_nonneg h0 (h g)) (sum_law_hash hsum g) + rwa [Real.log_inv] at hh + have hsumperg : (∑ g, -Real.log (collisionProb (law p (h g)))) ≤ ∑ g, entropy (law p (h g)) := + Finset.sum_le_sum fun g _ => hperg g + -- Combine (nat-log): `-log (avgCollisionProb) ≤ (∑_g H(g(X)))/|γ|`. + have hnat : -Real.log (avgCollisionProb h p) + ≤ (∑ g, entropy (law p (h g))) / Fintype.card γ := by + calc -Real.log (avgCollisionProb h p) + ≤ -((∑ g, Real.log (collisionProb (law p (h g)))) / Fintype.card γ) := by linarith + _ = (∑ g, -Real.log (collisionProb (law p (h g)))) / Fintype.card γ := by + rw [Finset.sum_neg_distrib, neg_div] + _ ≤ (∑ g, entropy (law p (h g))) / Fintype.card γ := + (div_le_div_iff_of_pos_right hγ).2 hsumperg + -- Convert to base-2 (bits) by dividing through by `log 2 > 0`. + have hShannon : avgShannonEntropy h p + = ((∑ g, entropy (law p (h g))) / Fintype.card γ) / Real.log 2 := by + rw [avgShannonEntropy_eq, div_div] + rw [avgCollisionEntropy_eq, hShannon, ← Real.log_div_log, ← neg_div] + exact (div_le_div_iff_of_pos_right hlog2).2 hnat + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashRefutation.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashRefutation.lean new file mode 100644 index 0000000000..f44f81ff26 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashRefutation.lean @@ -0,0 +1,245 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.UniversalHashEntropy + +/-! +# Refutation of the literal constant in Nielsen & Chuang's Theorem 12.16 + +Nielsen & Chuang's privacy-amplification theorem (§12.6, Theorem 12.16) states the entropy chain +`H(G(X)|G) ≥ Hc(G(X)|G) ≥ m − 2^{m−Hc(X)}` for the output `G(X)` of a `2`-universal hash family to +`{0,1}^m`, with `G` uniform. The first inequality and the (corrected) form of the second are +established in `ToMathlib/InformationTheory/UniversalHashEntropy.lean`; the honest second bound is +`Hc(G(X)|G) ≥ m − log₂(1 + 2^{m−Hc(X)})`. This file proves that **Nielsen & Chuang's literal second +inequality, with its constant `2^{m−Hc(X)}`, is false**. + +The obstruction is the elementary gap `log₂(1 + z) > z` for `0 < z < 1` (equivalently `2^z < 1 + z`, +the strict convexity of `2^·` below the chord): the textbook's linear constant `2^{m−Hc(X)}` +over-states the true `log₂(1 + 2^{m−Hc(X)})`, dropping the `1/ln 2` in `log₂(1+z) ≤ z/ln 2`. +Writing `z = 2^{m−Hc(X)} = |β|·Pc(X)`, whenever `0 < z < 1` (i.e. `m < Hc(X)`, the regime of +interest for key extraction) there is a universal family whose conditional collision entropy falls +strictly below `m − 2^{m−Hc(X)}`. + +## The counterexample + +The **all-functions family** `h = (id : (α → β) → α → β)` — index set `γ = α → β`, so a uniform `G` +is a uniformly random function — is exactly `2`-universal (`id_isUniversalFamily`): for distinct +`x ≠ x'`, exactly `|β|^{|α|−1}` of the `|β|^{|α|}` functions satisfy `g x = g x'` +(`card_filter_apply_eq_pow`), a collision fraction of exactly `1/|β|`. Its average collision +probability has the closed form `avgCollisionProb id p = 1/|β| + (1 − 1/|β|)·Pc(X)` +(`avgCollisionProb_id`), so the leftover-hash bound `≤ 1/|β| + Pc(X)` is essentially tight. + +Taking `α = Fin 16`, `β = Fin 8` (so `m = log₂ 8 = 3`) and `X` uniform (`Pc(X) = 1/16`, `Hc(X) = 4`, +`z = 8·(1/16) = 1/2 ∈ (0,1)`), the average collision probability is `1/8 + (7/8)·(1/16) = 23/128`, +hence +`Hc(G(X)|G) = −log₂(23/128) = 2.4757… < 5/2 = 3 − 1/2 = m − 2^{m−Hc(X)}` +(`avgCollisionEntropy_id_uniform_lt_literalBound`). The strict inequality reduces to `23/128 > +2^{−5/2}`, i.e. `529 > 512` after squaring. The headline `exists_lt_universalHash_literalBound` +packages this as: there is a genuinely `2`-universal family and input distribution violating Nielsen +& Chuang's literal bound. + +## Main results + +* `card_filter_apply_eq_pow`: `#{g : α → β | g x = g x'} = |β|^{|α|−1}` for `x ≠ x'` — the count + driving universality and the closed form. +* `id_isUniversalFamily`: the all-functions family is `2`-universal. +* `avgCollisionProb_id`: `avgCollisionProb id p = 1/|β| + (1 − 1/|β|)·collisionProb p`. +* `avgCollisionEntropy_id_uniform_lt_literalBound`: the concrete violation on `Fin 16 → Fin 8`. +* `exists_lt_universalHash_literalBound`: **the refutation** — a `2`-universal family and input with + `Hc(G(X)|G) < log₂|β| − |β|·Pc(X)`, so Nielsen & Chuang's literal second inequality is false. +-/ + +@[expose] public section + +namespace Real + +variable {α β : Type*} + +/-- Restricting a function `g : α → β` that agrees at two distinct points `x ≠ x'` (`g x = g x'`) to +the complement of `x'` is a bijection onto *all* functions `{a // a ≠ x'} → β`: the value at `x'` is +forced to equal the value at `x` — which lies in the complement, since `x ≠ x'` — so it carries no +free information. Used to count the functions agreeing at `x, x'`. -/ +private def funAgreePairEquiv [DecidableEq α] {x x' : α} (hxx : x ≠ x') : + {g : α → β // g x = g x'} ≃ ({a : α // a ≠ x'} → β) where + toFun g a := g.1 a.1 + invFun r := ⟨fun a => if h : a = x' then r ⟨x, hxx⟩ else r ⟨a, h⟩, by + dsimp only + rw [dite_eq_right hxx, dite_eq_left rfl]⟩ + left_inv g := by + apply Subtype.ext + funext a + dsimp only + by_cases h : a = x' + · rw [dite_eq_left h, h]; exact g.2 + · rw [dite_eq_right h] + right_inv r := by + funext a + dsimp only + rw [dite_eq_right a.2] + +/-- **The number of functions `α → β` that agree at two distinct points** `x ≠ x'` is +`|β|^{|α|−1}`. The value at `x'` is determined (it must equal the value at `x`), leaving the +`|α|−1` remaining coordinates free; formally, restriction to the complement of `x'` is a bijection +(`funAgreePairEquiv`) onto `{a // a ≠ x'} → β`, of cardinality `|β|^{|α|−1}`. -/ +theorem card_filter_apply_eq_pow [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] + {x x' : α} (hxx : x ≠ x') : + (Finset.univ.filter (fun g : α → β => g x = g x')).card + = Fintype.card β ^ (Fintype.card α - 1) := by + have hcompl : Fintype.card {a : α // a ≠ x'} = Fintype.card α - 1 := by + simp [Fintype.card_subtype_compl] + rw [← Fintype.card_subtype, Fintype.card_congr (funAgreePairEquiv hxx), Fintype.card_fun, hcompl] + +/-- **The all-functions family `id : (α → β) → α → β` is `2`-universal** (for `β` nonempty): with +`G` a uniformly random function `α → β`, distinct inputs `x ≠ x'` collide with probability exactly +`1/|β|`, meeting the universality bound with equality. Proof: `card_filter_apply_eq_pow` gives +`|β|^{|α|−1}` colliding functions out of `|β|^{|α|}` (`Fintype.card_fun`), a ratio of `1/|β|`. -/ +theorem id_isUniversalFamily [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] [Nonempty β] : + IsUniversalFamily (id : (α → β) → α → β) := by + intro x x' hxx + have hn : 1 ≤ Fintype.card α := Fintype.card_pos_iff.mpr ⟨x⟩ + have hfil : (Finset.univ.filter (fun g : (α → β) => id g x = id g x')).card + = Fintype.card β ^ (Fintype.card α - 1) := card_filter_apply_eq_pow hxx + rw [hfil, Fintype.card_fun] + -- `|β|^{|α|−1} / |β|^{|α|} = 1/|β|`, so the collision fraction equals `1/|β|`. + push_cast + have hCpos : (0 : ℝ) < (Fintype.card β : ℝ) ^ (Fintype.card α - 1) := by positivity + have hpow : (Fintype.card β : ℝ) ^ Fintype.card α + = (Fintype.card β : ℝ) ^ (Fintype.card α - 1) * (Fintype.card β : ℝ) := by + rw [← pow_succ, Nat.sub_add_cancel hn] + apply le_of_eq + rw [hpow, ← div_div, div_self hCpos.ne', one_div] + +/-- **Closed form for the average collision probability of the all-functions family.** For the +family `id : (α → β) → α → β` and any input probability distribution `p`, +`avgCollisionProb id p = 1/|β| + (1 − 1/|β|)·Pc(X)`, where `Pc(X) = collisionProb p`. + +In particular the leftover-hash bound `avgCollisionProb ≤ 1/|β| + Pc(X)` is essentially tight for +this family: the slack is exactly `Pc(X)/|β|`. Proof: expand each hashed collision probability over +ordered pairs (`collisionProb_law_eq_sum_pairs`) and average the indicator `[g x' = g x]` over `g` +to the collision frequency `#{g | g x' = g x}/|γ|`, which is `1` on the diagonal `x = x'` and +`|β|^{|α|−1}/|β|^{|α|} = 1/|β|` off it (`card_filter_apply_eq_pow`, `Fintype.card_fun`). -/ +theorem avgCollisionProb_id [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] + [Nonempty α] [Nonempty β] {p : α → ℝ} (hsum : ∑ x, p x = 1) : + avgCollisionProb (id : (α → β) → α → β) p + = (Fintype.card β : ℝ)⁻¹ + (1 - (Fintype.card β : ℝ)⁻¹) * collisionProb p := by + have hβR : (0 : ℝ) < Fintype.card β := by exact_mod_cast Fintype.card_pos_iff.mpr ‹Nonempty β› + have hn : 1 ≤ Fintype.card α := Fintype.card_pos_iff.mpr ‹Nonempty α› + set C : ℝ := (Fintype.card β : ℝ) ^ (Fintype.card α - 1) with hC + have hCpos : 0 < C := by rw [hC]; positivity + have hGR : (Fintype.card (α → β) : ℝ) = C * Fintype.card β := by + rw [Fintype.card_fun]; push_cast; rw [hC, ← pow_succ, Nat.sub_add_cancel hn] + -- Numerator: `∑_g Pc(law p (id g)) = C + (|γ| − C)·Pc`. + have hnum : (∑ g : α → β, collisionProb (law p (id g))) + = C + ((Fintype.card (α → β) : ℝ) - C) * collisionProb p := by + -- Expand each push-forward collision probability over ordered pairs, then swap `g` inward. + have reorder : (∑ g : α → β, collisionProb (law p (id g))) + = ∑ x, ∑ x', ∑ g : α → β, if g x' = g x then p x * p x' else 0 := by + simp_rw [id_eq, collisionProb_law_eq_sum_pairs] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun x _ => Finset.sum_comm + rw [reorder] + -- Average the indicator over `g` to the collision count. + have hcount : ∀ x x' : α, (∑ g : α → β, if g x' = g x then p x * p x' else 0) + = (if x' = x then (Fintype.card (α → β) : ℝ) else C) * (p x * p x') := by + intro x x' + rw [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul] + congr 1 + by_cases hxx : x' = x + · subst hxx + rw [ite_eq_left rfl, Finset.filter_true_of_mem (fun g _ => rfl), Finset.card_univ] + · rw [ite_eq_right hxx, hC] + exact_mod_cast card_filter_apply_eq_pow hxx + simp_rw [hcount] + -- Split each coefficient into the constant `C` part and the diagonal excess `|γ| − C`. + have hsplit : ∀ x x' : α, + (if x' = x then (Fintype.card (α → β) : ℝ) else C) * (p x * p x') + = C * (p x * p x') + + (if x' = x then ((Fintype.card (α → β) : ℝ) - C) else 0) * (p x * p x') := by + intro x x' + by_cases hxx : x' = x + · rw [ite_eq_left hxx, ite_eq_left hxx]; ring + · rw [ite_eq_right hxx, ite_eq_right hxx, zero_mul, add_zero] + simp_rw [hsplit, Finset.sum_add_distrib] + -- The constant part sums to `C`; the diagonal excess to `(|γ| − C)·Pc`. + have hAsum : (∑ x, ∑ x', C * (p x * p x')) = C := by + simp only [← Finset.mul_sum, hsum, mul_one] + have hBsum : (∑ x, ∑ x', + (if x' = x then ((Fintype.card (α → β) : ℝ) - C) else 0) * (p x * p x')) + = ((Fintype.card (α → β) : ℝ) - C) * collisionProb p := by + rw [collisionProb_eq, Finset.mul_sum] + refine Finset.sum_congr rfl fun x _ => ?_ + simp_rw [ite_mul, zero_mul] + rw [Finset.sum_ite_eq' Finset.univ x + (fun x' => ((Fintype.card (α → β) : ℝ) - C) * (p x * p x')), ite_eq_left (Finset.mem_univ + x)] + ring + rw [hAsum, hBsum] + rw [avgCollisionProb_eq, hnum, hGR] + field_simp + +/-- **The concrete counterexample.** On `α = Fin 16`, `β = Fin 8` with `X` uniform, the +all-functions family's conditional collision entropy is `Hc(G(X)|G) = −log₂(23/128) = 2.475… < 5/2`, +strictly below N&C's literal bound `m − 2^{m−Hc(X)} = log₂ 8 − 8·(1/16) = 3 − 1/2 = 5/2`. + +Here `m = log₂ 8 = 3` output bits, `Pc(X) = 1/16` so `Hc(X) = 4`, and the average collision +probability is `avgCollisionProb id X = 1/8 + (7/8)·(1/16) = 23/128` (`avgCollisionProb_id`, +`collisionProb_uniform`). The strict inequality reduces to `log₂(23/16) > 1/2`, i.e. `23/16 > √2`, +i.e. `529 > 512`. -/ +theorem avgCollisionEntropy_id_uniform_lt_literalBound : + avgCollisionEntropy (id : (Fin 16 → Fin 8) → Fin 16 → Fin 8) + (fun _ => (Fintype.card (Fin 16) : ℝ)⁻¹) + < Real.logb 2 (Fintype.card (Fin 8)) + - Fintype.card (Fin 8) + * collisionProb (fun _ : Fin 16 => (Fintype.card (Fin 16) : ℝ)⁻¹) := by + have hcard16 : Fintype.card (Fin 16) = 16 := Fintype.card_fin 16 + have hcard8 : Fintype.card (Fin 8) = 8 := Fintype.card_fin 8 + have hsum : ∑ _x : Fin 16, (Fintype.card (Fin 16) : ℝ)⁻¹ = 1 := by + rw [Finset.sum_const, Finset.card_univ, hcard16]; norm_num + have hPc : collisionProb (fun _ : Fin 16 => (Fintype.card (Fin 16) : ℝ)⁻¹) + = (Fintype.card (Fin 16) : ℝ)⁻¹ := collisionProb_uniform + have hAvg : avgCollisionProb (id : (Fin 16 → Fin 8) → Fin 16 → Fin 8) + (fun _ => (Fintype.card (Fin 16) : ℝ)⁻¹) = 23 / 128 := by + rw [avgCollisionProb_id hsum, hPc, hcard8, hcard16]; norm_num + rw [avgCollisionEntropy_eq, hAvg, hPc, hcard8, hcard16] + -- Goal: `−log₂(23/128) < log₂ 8 − 8·(1/16)`. + have h816 : (8 : ℝ) * (16 : ℝ)⁻¹ = 1 / 2 := by norm_num + -- `log₂ 8 + log₂(23/128) = log₂(23/16)`, so it suffices that `log₂(23/16) > 1/2`. + have hmul : Real.logb 2 8 + Real.logb 2 (23 / 128) = Real.logb 2 (23 / 16) := by + rw [← Real.logb_mul (by norm_num) (by norm_num), + show (8 : ℝ) * (23 / 128) = 23 / 16 by norm_num] + have hhalf : Real.logb 2 (2 ^ (1 / 2 : ℝ)) = 1 / 2 := by + rw [Real.logb_eq_iff_rpow_eq (by norm_num) (by norm_num) (by positivity)] + have hkey : (1 : ℝ) / 2 < Real.logb 2 (23 / 16) := by + rw [← hhalf] + apply Real.logb_lt_logb (by norm_num) (by positivity) + rw [← Real.sqrt_eq_rpow, Real.sqrt_lt' (by norm_num)] + norm_num + push_cast + linarith [hmul, hkey, h816] + +/-- **Refutation of the literal constant in Nielsen & Chuang's Theorem 12.16.** There is a genuinely +`2`-universal hash family `h` and input distribution `p` whose conditional collision entropy falls +strictly below the textbook's literal second bound `m − 2^{m−Hc(X)}` — written here +`log₂|β| − |β|·Pc(X)`, using `2^{m−Hc(X)} = |β|·Pc(X)`. Hence N&C's *second* inequality, +with the constant `2^{m−Hc(X)}`, is **false** as stated; the correct lower bound is the `log₂(1+·)` +form `Real.avgCollisionEntropy_ge`. + +Witnessed by the all-functions family on `Fin 16 → Fin 8` with `X` uniform +(`id_isUniversalFamily`, `avgCollisionEntropy_id_uniform_lt_literalBound`). -/ +theorem exists_lt_universalHash_literalBound : + ∃ (h : (Fin 16 → Fin 8) → Fin 16 → Fin 8) (p : Fin 16 → ℝ), + IsUniversalFamily h ∧ (∀ x, 0 ≤ p x) ∧ (∑ x, p x = 1) ∧ + avgCollisionEntropy h p + < Real.logb 2 (Fintype.card (Fin 8)) - Fintype.card (Fin 8) * collisionProb p := + ⟨id, fun _ => (Fintype.card (Fin 16) : ℝ)⁻¹, id_isUniversalFamily, fun _ => by positivity, + by rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin]; norm_num, + avgCollisionEntropy_id_uniform_lt_literalBound⟩ + +end Real diff --git a/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashing.lean b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashing.lean new file mode 100644 index 0000000000..066445df8d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/InformationTheory/UniversalHashing.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.InformationTheory.CollisionEntropyLaw + +/-! +# Universal hash families and the leftover-hash collision bound + +For a finite family of hash functions `h : γ → α → β` (each `h g : α → β`, with `g` ranging over a +finite index type `γ`) and an input probability distribution `p : α → ℝ`, this file introduces the +combinatorial core behind Nielsen & Chuang's privacy-amplification theorem (§12.6, Theorem 12.16). + +* `Real.IsUniversalFamily h`: the family is **(2-)universal** — for any two distinct inputs + `x ≠ x'`, the fraction of members `g` that *collide* them (`h g x = h g x'`) is at most `1 / |β|`. + This is N&C's condition "when `g` is chosen uniformly at random, `Pr[g(a₁) = g(a₂)] ≤ 1/|B|`". +* `Real.avgCollisionProb h p`: the **average collision probability** of the output `g(X)`, averaged + over a uniform random member `g`. Writing `g(X)` for the push-forward `Real.law p (h g)` of the + input, this is `E_G[Pc(g(X))] = (∑_g Pc(law p (h g))) / |γ|`, with `Pc = Real.collisionProb`. + +## Main results + +* `Real.avgCollisionProb_le`: the **leftover-hash bound** — for a universal family and any input + distribution `p`, `avgCollisionProb h p ≤ (Fintype.card β)⁻¹ + collisionProb p`, i.e. + `E_G[Pc(g(X))] ≤ 1/|B| + Pc(X)`. + +The proof is the standard "diagonal + off-diagonal" split. Expanding the collision probability of +each push-forward over ordered input pairs (`Real.collisionProb_law_eq_sum_pairs`), +`Pc(law p (h g)) = ∑_{x, x'} [h g x = h g x'] · p x · p x'`, and averaging over `g` turns the +indicator into the collision frequency `#{g : h g x = h g x'} / |γ|`. On the diagonal `x = x'` this +frequency is `1` and contributes `∑_x p x² = Pc(X)`; off the diagonal universality bounds it by +`1/|β|`, and `∑_{x, x'} p x · p x' = 1`, contributing at most `1/|β|`. + +This bound is the engine of N&C Theorem 12.16: applied to the base-`2` collision entropy +`Hc = -log₂ Pc` it yields the (corrected, honest) lower bound on the conditional collision entropy +of the hashed key. Base `2` (bits) is used throughout, matching `Real.collisionEntropy`, since N&C +Theorem 12.16 compares `Hc` to the number of output bits `m = log₂ |β|`. +-/ + +@[expose] public section + +namespace Real + +variable {α β γ : Type*} + +/-- A finite family of hash functions `h : γ → α → β` is **(2-)universal** (Nielsen & Chuang §12.6) +if for every pair of distinct inputs `x ≠ x'`, the fraction of family members `g` that collide them +(`h g x = h g x'`) is at most `1 / |β|`: with `g` drawn uniformly from the family, +`Pr[h g x = h g x'] ≤ (Fintype.card β)⁻¹`. -/ +def IsUniversalFamily [Fintype γ] [Fintype β] [DecidableEq β] (h : γ → α → β) : Prop := + ∀ x x' : α, x ≠ x' → + ((Finset.univ.filter fun g => h g x = h g x').card : ℝ) / Fintype.card γ + ≤ (Fintype.card β : ℝ)⁻¹ + +/-- The **average collision probability** of the output `g(X)` of a hash family `h : γ → α → β` on +an input distribution `p : α → ℝ`, averaged over a uniform random member `g`: +`avgCollisionProb h p = (∑_g Real.collisionProb (Real.law p (h g))) / Fintype.card γ`, where +`Real.law p (h g)` is the push-forward distribution of the output `h g`. -/ +noncomputable def avgCollisionProb [Fintype α] [Fintype β] [Fintype γ] [DecidableEq β] + (h : γ → α → β) (p : α → ℝ) : ℝ := + (∑ g, collisionProb (law p (h g))) / Fintype.card γ + +theorem avgCollisionProb_eq [Fintype α] [Fintype β] [Fintype γ] [DecidableEq β] + (h : γ → α → β) (p : α → ℝ) : + avgCollisionProb h p = (∑ g, collisionProb (law p (h g))) / Fintype.card γ := rfl + +/-- **The leftover-hash collision bound** (Nielsen & Chuang §12.6, the combinatorial core of +Theorem 12.16). For a (2-)universal family `h : γ → α → β` and any input probability distribution +`p : α → ℝ`, the average collision probability of the hashed output is at most `1/|β|` above the +input collision probability: `avgCollisionProb h p ≤ (Fintype.card β)⁻¹ + collisionProb p`, i.e. +`E_G[Pc(g(X))] ≤ 1/|B| + Pc(X)`. -/ +theorem avgCollisionProb_le [Fintype α] [Fintype β] [Fintype γ] [DecidableEq β] [Nonempty γ] + {h : γ → α → β} (hu : IsUniversalFamily h) {p : α → ℝ} (h0 : ∀ x, 0 ≤ p x) + (hsum : ∑ x, p x = 1) : + avgCollisionProb h p ≤ (Fintype.card β : ℝ)⁻¹ + collisionProb p := by + classical + have hγ : (0 : ℝ) < Fintype.card γ := by exact_mod_cast Fintype.card_pos + rw [avgCollisionProb_eq, div_le_iff₀ hγ] + -- Expand each hashed collision probability over ordered pairs and swap the `g`-sum inward. + have reorder : (∑ g, collisionProb (law p (h g))) + = ∑ x, ∑ x', ∑ g, if h g x' = h g x then p x * p x' else 0 := by + simp_rw [collisionProb_law_eq_sum_pairs] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun x _ => Finset.sum_comm + rw [reorder] + -- The exact value of the two evaluated pair-sums. + have key : (∑ x, ∑ x', ((if x' = x then p x * p x' else 0) + + (Fintype.card β : ℝ)⁻¹ * (p x * p x'))) + = (Fintype.card β : ℝ)⁻¹ + collisionProb p := by + have hdiag : (∑ x, ∑ x', if x' = x then p x * p x' else 0) = collisionProb p := by + rw [collisionProb_eq] + refine Finset.sum_congr rfl fun x _ => ?_ + rw [Finset.sum_ite_eq' Finset.univ x fun x' => p x * p x', ite_eq_left (Finset.mem_univ x), + ← pow_two] + have hpp : (∑ x, ∑ x', p x * p x') = 1 := by rw [← Finset.sum_mul_sum, hsum, mul_one] + have hoff : (∑ x, ∑ x', (Fintype.card β : ℝ)⁻¹ * (p x * p x')) = (Fintype.card β : ℝ)⁻¹ := by + rw [show (∑ x, ∑ x', (Fintype.card β : ℝ)⁻¹ * (p x * p x')) + = (Fintype.card β : ℝ)⁻¹ * ∑ x, ∑ x', p x * p x' by + rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun x _ => (Finset.mul_sum _ _ _).symm] + rw [hpp, mul_one] + simp_rw [Finset.sum_add_distrib] + rw [hdiag, hoff, add_comm] + calc ∑ x, ∑ x', ∑ g, (if h g x' = h g x then p x * p x' else 0) + ≤ ∑ x, ∑ x', (Fintype.card γ : ℝ) + * ((if x' = x then p x * p x' else 0) + (Fintype.card β : ℝ)⁻¹ * (p x * p x')) := by + refine Finset.sum_le_sum fun x _ => Finset.sum_le_sum fun x' _ => ?_ + have hgsum : (∑ g, if h g x' = h g x then p x * p x' else 0) + = ((Finset.univ.filter fun g => h g x' = h g x).card : ℝ) * (p x * p x') := by + rw [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul] + rw [hgsum] + by_cases hxx : x' = x + · subst x' + have hfull : (Finset.univ.filter fun g => h g x = h g x) = Finset.univ := + Finset.filter_true_of_mem fun g _ => rfl + rw [hfull, Finset.card_univ, ite_eq_left rfl] + have hnn : (0 : ℝ) ≤ (Fintype.card β : ℝ)⁻¹ * (p x * p x) := + mul_nonneg (by positivity) (mul_nonneg (h0 x) (h0 x)) + exact mul_le_mul_of_nonneg_left (le_add_of_nonneg_right hnn) hγ.le + · rw [ite_eq_right hxx] + have hle : ((Finset.univ.filter fun g => h g x' = h g x).card : ℝ) + ≤ (Fintype.card β : ℝ)⁻¹ * Fintype.card γ := by + have := hu x' x hxx + rwa [div_le_iff₀ hγ] at this + calc ((Finset.univ.filter fun g => h g x' = h g x).card : ℝ) * (p x * p x') + ≤ ((Fintype.card β : ℝ)⁻¹ * Fintype.card γ) * (p x * p x') := + mul_le_mul_of_nonneg_right hle (mul_nonneg (h0 x) (h0 x')) + _ = (Fintype.card γ : ℝ) * (0 + (Fintype.card β : ℝ)⁻¹ * (p x * p x')) := by ring + _ = ((Fintype.card β : ℝ)⁻¹ + collisionProb p) * (Fintype.card γ : ℝ) := by + rw [show (∑ x, ∑ x', (Fintype.card γ : ℝ) + * ((if x' = x then p x * p x' else 0) + (Fintype.card β : ℝ)⁻¹ * (p x * p x'))) + = (Fintype.card γ : ℝ) * ∑ x, ∑ x', ((if x' = x then p x * p x' else 0) + + (Fintype.card β : ℝ)⁻¹ * (p x * p x')) by + rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun x _ => (Finset.mul_sum _ _ _).symm] + rw [key]; ring + +end Real diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Eigenspace/Idempotent.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Eigenspace/Idempotent.lean new file mode 100644 index 0000000000..23040fd0e3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Eigenspace/Idempotent.lean @@ -0,0 +1,59 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Eigenspace.Basic + +/-! +# Eigenvalues of an idempotent operator + +This file records the elementary fact that every eigenvalue of an idempotent linear operator +`T : Module.End 𝕜 E` (`T ∘ T = T`) is either `0` or `1`. + +This is the abstract heart of Nielsen & Chuang's *Quantum Computation and Quantum Information*, +Exercise 2.23 ("show that the eigenvalues of a projector `P` are all either `0` or `1`"): a +projector is idempotent (Exercise 2.16), and the eigenvalue restriction uses *only* idempotence, +via the one-line computation `μ² • v = T (T v) = T v = μ • v` on an eigenvector `v ≠ 0`. + +## Main results + +* `Module.End.HasEigenvalue.eq_zero_or_one_of_isIdempotentElem`: for idempotent `T` and any + eigenvalue `μ` of `T`, `μ = 0 ∨ μ = 1`. + +The file `Mathlib/FieldTheory/IsAlgClosed/Spectrum.lean` proves the sibling +`IsIdempotentElem.spectrum_subset` (`spectrum 𝕜 p ⊆ {0, 1}` for an idempotent element of any +`𝕜`-algebra); this file gives the complementary eigenvalue-predicate (`Module.End.HasEigenvalue`) +form, proved directly from the eigenvector computation rather than through the abstract spectrum. +-/ + +@[expose] public section + +namespace Module.End + +variable {𝕜 E : Type*} [Field 𝕜] [AddCommGroup E] [Module 𝕜 E] + +/-- **Nielsen & Chuang, Exercise 2.23** (abstract form). Every eigenvalue `μ` of an idempotent +operator `T : Module.End 𝕜 E` (`T ∘ T = T`) is either `0` or `1`. + +On an eigenvector `v ≠ 0` with `T v = μ • v`, applying `T` a second time gives +`μ² • v = T (T v) = T v = μ • v` (the middle equality is idempotence), so `(μ² - μ) • v = 0`; since +`v ≠ 0` this forces `μ² = μ`, i.e. `μ (μ - 1) = 0`, whence `μ = 0` or `μ = 1`. Only idempotence is +used — no self-adjointness, completeness, or finite dimensionality. -/ +theorem HasEigenvalue.eq_zero_or_one_of_isIdempotentElem + {T : Module.End 𝕜 E} {μ : 𝕜} (h : T.HasEigenvalue μ) (hT : IsIdempotentElem T) : + μ = 0 ∨ μ = 1 := by + obtain ⟨v, hv⟩ := h.exists_hasEigenvector + have key : μ ^ 2 • v = μ • v := by + calc μ ^ 2 • v = T (T v) := by + rw [hv.apply_eq_smul, map_smul, hv.apply_eq_smul, smul_smul, ← pow_two] + _ = T v := by rw [← mul_apply_eq_comp, hT.eq] + _ = μ • v := hv.apply_eq_smul + exact eq_zero_or_one_of_sq_eq_self (smul_left_injective 𝕜 hv.2 key) + +end Module.End diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Hermitian.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Hermitian.lean new file mode 100644 index 0000000000..fc409924fa --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Hermitian.lean @@ -0,0 +1,44 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Hermitian +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Kronecker + +/-! # Hermitian matrices: the Kronecker product + +Extends `Mathlib.LinearAlgebra.Matrix.Hermitian` with the fact that the Kronecker product of two +Hermitian matrices is Hermitian. +-/ + +@[expose] public section + +namespace Matrix + +variable {m n α : Type*} + +section Kronecker + +open scoped Kronecker + +variable [CommMagma α] [StarMul α] + +/-- The Kronecker product of two Hermitian matrices is Hermitian. + +This is Nielsen & Chuang, Exercise 2.30 (*the tensor product of two Hermitian operators is +Hermitian*): using that the conjugate transpose distributes over the Kronecker product +(`Matrix.conjTranspose_kronecker`), `(A ⊗ₖ B)ᴴ = Aᴴ ⊗ₖ Bᴴ = A ⊗ₖ B`. Commutativity of the +entries is needed because `star` is an anti-homomorphism. -/ +theorem IsHermitian.kronecker {A : Matrix m m α} {B : Matrix n n α} (hA : A.IsHermitian) + (hB : B.IsHermitian) : (A ⊗ₖ B).IsHermitian := by + rw [IsHermitian, conjTranspose_kronecker, hA.eq, hB.eq] + +end Kronecker + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/HermitianUnitary.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/HermitianUnitary.lean new file mode 100644 index 0000000000..6a53698cc3 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/HermitianUnitary.lean @@ -0,0 +1,42 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.UnitaryGroup +public import LeanPool.AxQM.ToMathlib.LinearAlgebra.Matrix.Hermitian + +/-! +# A Hermitian involution is unitary + +Over a commutative `*`-ring, a square matrix `A` that is Hermitian (`Aᴴ = A`) and squares to the +identity (`A * A = 1`) is unitary. Membership in `Matrix.unitaryGroup` asks for `star A * A = 1`, +and `star A = Aᴴ = A`, so unitarity reduces to the involution hypothesis. + +## Main results + +* `Matrix.IsHermitian.mem_unitaryGroup`: a Hermitian matrix with `A * A = 1` is unitary. + +This is the abstract fact behind "the Pauli matrices are unitary" (Nielsen & Chuang, +Exercise 2.19) and, more generally, any self-inverse Hermitian gate (e.g. the Hadamard gate). +-/ + +@[expose] public section + +namespace Matrix + +variable {n : Type*} [DecidableEq n] [Fintype n] {α : Type*} [CommRing α] [StarRing α] + +/-- A Hermitian matrix that is its own inverse (`A * A = 1`) is unitary. Unitarity requires +`star A * A = 1`; since `star A = Aᴴ = A`, this is exactly the involution hypothesis. -/ +theorem IsHermitian.mem_unitaryGroup {A : Matrix n n α} (hH : A.IsHermitian) (hI : A * A = 1) : + A ∈ Matrix.unitaryGroup n α := by + rw [Matrix.mem_unitaryGroup_iff', Matrix.star_eq_conjTranspose, hH.eq] + exact hI + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Kronecker.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Kronecker.lean new file mode 100644 index 0000000000..ef5d1eba23 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Kronecker.lean @@ -0,0 +1,40 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Kronecker + +/-! +# Kronecker product: distributing `star` over `⊗ₖ` + +Entrywise `star` (complex conjugation of each entry) distributes over the Kronecker product. +-/ + +@[expose] public section + +namespace Matrix + +variable {R : Type*} +variable {l m n p : Type*} + +section Kronecker + +open Kronecker + +/-- Entrywise `star` (complex conjugation of each entry) distributes over the Kronecker product. +Together with `Matrix.kroneckerMap_transpose` (transpose) and `Matrix.conjTranspose_kronecker` +(conjugate transpose), this records that conjugation, transpose and adjoint all distribute over +`⊗ₖ`. -/ +theorem map_star_kronecker [CommMagma R] [StarMul R] (x : Matrix l m R) (y : Matrix n p R) : + (x ⊗ₖ y).map star = x.map star ⊗ₖ y.map star := by + ext; simp + +end Kronecker + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Permutation.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Permutation.lean new file mode 100644 index 0000000000..185f2c551f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Permutation.lean @@ -0,0 +1,34 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Permutation + +/-! +# Additional API for permutation matrices + +* `Matrix.permMatrix_eq_of_ite`: `σ.permMatrix R` is the `0`/`1` indicator matrix of `σ i = j`. +-/ + +public section + +open Equiv + +namespace Matrix + +variable {n R : Type*} [DecidableEq n] (σ : Perm n) + +/-- The permutation matrix `permMatrix R σ` is the `0`/`1` matrix whose `(i, j)` entry is `1` +exactly when `σ i = j`: it is `Matrix.of` applied to that indicator. -/ +theorem permMatrix_eq_of_ite [Zero R] [One R] : + (Matrix.of fun i j => if σ i = j then (1 : R) else 0) = σ.permMatrix R := by + ext i j + simp [Equiv.Perm.permMatrix, PEquiv.toMatrix_apply, Equiv.toPEquiv_apply, eq_comm] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/PermutationUnitary.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/PermutationUnitary.lean new file mode 100644 index 0000000000..4419618f05 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/PermutationUnitary.lean @@ -0,0 +1,58 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Permutation +public import Mathlib.LinearAlgebra.UnitaryGroup + +/-! +# Unitarity and diagonal conjugation of permutation matrices + +Two general facts about the permutation matrix `Equiv.Perm.permMatrix R σ` over a commutative star +ring `R`, sitting at the `permMatrix` / `unitaryGroup` level (below any analysis) so that the +spectral majorization development (`ToMathlib/Analysis/Matrix/HermitianMajorization.lean`) and +concrete permutation-gate calculations can share a single copy. + +## Main statements + +* `Matrix.permMatrix_mem_unitaryGroup`: a permutation matrix over a commutative star ring is + unitary. +* `Matrix.permMatrix_mul_diagonal_mul_conjTranspose`: conjugating a diagonal matrix by a permutation + matrix permutes the diagonal entries, `Pσ * diagonal v * Pσᴴ = diagonal (v ∘ σ)`. + +## Tags + +permutation matrix, unitary, diagonal, conjugation +-/ + +public section + +open Matrix + +namespace Matrix + +variable {n : Type*} [Fintype n] [DecidableEq n] {R : Type*} [CommRing R] [StarRing R] + +/-- A permutation matrix over a commutative star ring is unitary: +`star (permMatrix σ) = permMatrix σ⁻¹` and `permMatrix σ * permMatrix σ⁻¹ = permMatrix 1 = 1`. -/ +theorem permMatrix_mem_unitaryGroup (σ : Equiv.Perm n) : σ.permMatrix R ∈ unitaryGroup n R := by + rw [mem_unitaryGroup_iff, star_eq_conjTranspose, conjTranspose_permMatrix, ← permMatrix_mul, + inv_mul_cancel, permMatrix_one] + +/-- Conjugating a diagonal matrix by a permutation matrix permutes the diagonal entries: +`Pσ * diagonal v * Pσᴴ = diagonal (v ∘ σ)`, for a permutation `σ` and any commutative star ring. -/ +theorem permMatrix_mul_diagonal_mul_conjTranspose (σ : Equiv.Perm n) (v : n → R) : + σ.permMatrix R * diagonal v * (σ.permMatrix R)ᴴ = diagonal (v ∘ σ) := by + rw [conjTranspose_permMatrix, mul_assoc] + simp only [Equiv.Perm.permMatrix] + rw [PEquiv.mul_toMatrix_toPEquiv, PEquiv.toMatrix_toPEquiv_mul, submatrix_submatrix] + simp only [Function.comp_id, Function.id_comp, Equiv.Perm.inv_def, Equiv.symm_symm, + submatrix_diagonal_equiv] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Trace.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Trace.lean new file mode 100644 index 0000000000..9df2451183 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Matrix/Trace.lean @@ -0,0 +1,25 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Matrix.Trace + +/-! +# `Matrix.trace` unfolds to a sum over the diagonal +-/ + +@[expose] public section + +namespace Matrix + +variable {n : Type*} {R : Type*} [Fintype n] [AddCommMonoid R] + +theorem trace_apply (A : Matrix n n R) : trace A = ∑ i, diag A i := rfl + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finiteness.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finiteness.lean new file mode 100644 index 0000000000..3049579e7f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finiteness.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.PiTensorProduct.Basic +public import Mathlib.RingTheory.Finiteness.Basic + +/-! + +# Some finiteness results of `PiTensorProduct` + +This is the `PiTensorProduct` analog of `Mathlib/LinearAlgebra/TensorProduct/Finiteness.lean`. + +- `PiTensorProduct.range_mapIncl_mono`: monotonicity of the range of `PiTensorProduct.mapIncl` + in the family of submodules. +- `PiTensorProduct.exists_finite_submodule_of_setFinite`: any finite subset of `⨂[R] i, M i` + is contained in `⨂[R] i, M' i` for some family of finitely generated submodules + `M' i ≤ M i`. + +## Tags + +tensor product, pi tensor product, finitely generated + +-/ + +@[expose] public section + +open Submodule + +open scoped TensorProduct + +namespace PiTensorProduct + +variable {ι : Type*} {R : Type*} {M : ι → Type*} [CommSemiring R] + [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] + +/-- Monotonicity of the range of `mapIncl` in the family of submodules. -/ +lemma range_mapIncl_mono {p q : Π i, Submodule R (M i)} (h : ∀ i, p i ≤ q i) : + LinearMap.range (mapIncl p) ≤ LinearMap.range (mapIncl q) := by + have hcomp : mapIncl p = mapIncl q ∘ₗ map (fun i ↦ Submodule.inclusion (h i)) := by + ext m; simp [mapIncl, Submodule.inclusion] + rw [hcomp] + exact LinearMap.range_comp_le_range _ _ + +/-- For a finite subset `s` of `⨂[R] i, M i`, there is a family of finitely generated submodules +`M' i ≤ M i` such that `s` is contained in the image of `⨂[R] i, M' i` in `⨂[R] i, M i`. + +In particular, every element of a `PiTensorProduct` lies in the `PiTensorProduct` of some +finitely generated submodules. -/ +theorem exists_finite_submodule_of_setFinite (s : Set (⨂[R] i, M i)) (hs : s.Finite) : + ∃ M' : Π i, Submodule R (M i), (∀ i, Module.Finite R (M' i)) ∧ + s ⊆ LinearMap.range (mapIncl M') := by + simp_rw [Module.Finite.iff_fg] + induction s, hs using Set.Finite.induction_on with + | empty => exact ⟨fun _ ↦ ⊥, fun _ ↦ fg_bot, Set.empty_subset _⟩ + | @insert a s _ _ ih => + obtain ⟨M', hM', h⟩ := ih + refine PiTensorProduct.induction_on a (fun r f ↦ ?_) (fun x y hx hy ↦ ?_) + · refine ⟨fun i ↦ M' i ⊔ Submodule.span R {f i}, + fun i ↦ (hM' i).sup (fg_span_singleton _), + Set.insert_subset ?_ fun z hz ↦ ?_⟩ + · refine ⟨r • tprod R fun i ↦ ⟨f i, mem_sup_right (mem_span_singleton_self _)⟩, ?_⟩ + simp [mapIncl] + · exact range_mapIncl_mono (fun _ ↦ le_sup_left) (h hz) + · obtain ⟨M₁', hM₁', h₁⟩ := hx + obtain ⟨M₂', hM₂', h₂⟩ := hy + refine ⟨fun i ↦ M₁' i ⊔ M₂' i, + fun i ↦ (hM₁' i).sup (hM₂' i), + Set.insert_subset (add_mem ?_ ?_) fun z hz ↦ ?_⟩ + · exact range_mapIncl_mono (fun _ ↦ le_sup_left) (h₁ (Set.mem_insert x s)) + · exact range_mapIncl_mono (fun _ ↦ le_sup_right) (h₂ (Set.mem_insert y s)) + · exact range_mapIncl_mono (fun _ ↦ le_sup_left) (h₁ (Set.subset_insert x s hz)) + +end PiTensorProduct diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finrank.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finrank.lean new file mode 100644 index 0000000000..085562e048 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/PiTensorProduct/Finrank.lean @@ -0,0 +1,42 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.PiTensorProduct.Basis +public import Mathlib.LinearAlgebra.Dimension.Free + +/-! +# Finrank of a `PiTensorProduct` + +For a finite family `M : ι → Type*` of finite free modules over a commutative semiring `R` +satisfying the strong rank condition, the finite rank of the `ι`-ary tensor product `⨂[R] i, M i` +is the product of the finite ranks of the factors. + +## Main results + +* `Module.finrank_piTensorProduct` — `finrank R (⨂[R] i, M i) = ∏ i, finrank R (M i)`. +-/ + +@[expose] public section + +open scoped TensorProduct + +/-- The finite rank of a tensor product `⨂[R] i, M i` over a finite index type `ι` is the product +`∏ i, finrank R (M i)` of the finite ranks of the factors. Obtained from the tensor-product basis +`Basis.piTensorProduct`, whose index type is `Π i, (basis index of M i)`, together with +`Fintype.card_pi`. -/ +theorem Module.finrank_piTensorProduct {ι R : Type*} {M : ι → Type*} [CommSemiring R] + [StrongRankCondition R] [Fintype ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] + [∀ i, Module.Free R (M i)] [∀ i, Module.Finite R (M i)] : + Module.finrank R (⨂[R] i, M i) = ∏ i, Module.finrank R (M i) := by + classical + rw [Module.finrank_eq_card_basis (Basis.piTensorProduct fun i => Module.finBasis R (M i))] + simp [Fintype.card_pi] + +end diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorPower/Endomorphism.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorPower/Endomorphism.lean new file mode 100644 index 0000000000..c64b3c7d33 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorPower/Endomorphism.lean @@ -0,0 +1,81 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.TensorPower.Basic +public import Mathlib.LinearAlgebra.PiTensorProduct.Basic + +/-! +# Tensor power of an endomorphism + +For an endomorphism `A : M →ₗ[R] M`, this file defines its `n`-fold tensor power +`LinearMap.tensorPow A n : ⨂[R]^n M →ₗ[R] ⨂[R]^n M`, acting on `⨂[R]^n M` by +applying `A` in each factor. We provide the notation `A ^⊗ n` for it. + +This is the special case of `PiTensorProduct.map` for the constant family `fun _ ↦ A`. + +## Main definitions + +* `LinearMap.tensorPow A n`: the `n`-fold tensor power of `A`, with notation `A ^⊗ n`. + +## Main results + +* `LinearMap.tensorPow_eq_map`: the rfl-form `A ^⊗ n = PiTensorProduct.map (fun _ ↦ A)`, + exposed as `@[simp]` so proofs can reach through `tensorPow` automatically. +* `LinearMap.tensorPow_apply_tprod`: `(A ^⊗ n) (tprod R v) = tprod R (fun i ↦ A (v i))`. +* `LinearMap.tensorPow_zero`, `LinearMap.tensorPow_id`: `A ^⊗ 0 = id` and `id ^⊗ n = id`. +* `LinearMap.tensorPow_comp`: `(A ∘ₗ B) ^⊗ n = A ^⊗ n ∘ₗ B ^⊗ n`. + +## Implementation notes + +The operator-equality forms involving canonical isomorphisms (`tensorPow_one` via the +`PiTensorProduct.subsingletonEquiv` for `Fin 1`, `tensorPow_succ` via +`TensorPower.mulEquiv`) are not formalised here; the `tprod`-applied form +`tensorPow_apply_tprod` covers the common uses. +-/ + +@[expose] public section + +open scoped TensorProduct + +namespace LinearMap + +variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] + +/-- The `n`-fold tensor power of an endomorphism `A : M →ₗ[R] M`, acting on +`⨂[R]^n M` by applying `A` in each factor. -/ +noncomputable def tensorPow (A : M →ₗ[R] M) (n : ℕ) : + (⨂[R]^n) M →ₗ[R] (⨂[R]^n) M := + PiTensorProduct.map (fun (_ : Fin n) ↦ A) + +@[inherit_doc] notation:max A " ^⊗ " n:arg => LinearMap.tensorPow A n + +theorem tensorPow_eq_map (A : M →ₗ[R] M) (n : ℕ) : + A ^⊗ n = PiTensorProduct.map (fun (_ : Fin n) ↦ A) := rfl + +@[simp] theorem tensorPow_apply_tprod (A : M →ₗ[R] M) {n : ℕ} (v : Fin n → M) : + (A ^⊗ n) (PiTensorProduct.tprod R v) = PiTensorProduct.tprod R (fun i ↦ A (v i)) := by + rw [tensorPow_eq_map, PiTensorProduct.map_tprod] + +@[simp] theorem tensorPow_zero (A : M →ₗ[R] M) : + A ^⊗ 0 = LinearMap.id := by + rw [tensorPow_eq_map, Subsingleton.elim (fun (_ : Fin 0) ↦ A) (fun _ ↦ LinearMap.id)] + exact PiTensorProduct.map_id + +@[simp] theorem tensorPow_id (n : ℕ) : + (LinearMap.id : M →ₗ[R] M) ^⊗ n = LinearMap.id := by + rw [tensorPow_eq_map] + exact PiTensorProduct.map_id + +theorem tensorPow_comp (A B : M →ₗ[R] M) (n : ℕ) : + (A ∘ₗ B) ^⊗ n = A ^⊗ n ∘ₗ B ^⊗ n := by + rw [tensorPow_eq_map, tensorPow_eq_map, tensorPow_eq_map] + exact PiTensorProduct.map_comp _ _ + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorProduct/Map.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorProduct/Map.lean new file mode 100644 index 0000000000..07b56b3a9c --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/TensorProduct/Map.lean @@ -0,0 +1,55 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.TensorProduct.Map + +/-! +# Extra `TensorProduct.map` lemmas + +Extends `Mathlib.LinearAlgebra.TensorProduct.Map` with `TensorProduct.map_sum_left` (`map` +is additive in its first argument over a finite sum) and `LinearEquiv.rTensor_comp_map_comp_symm` +(conjugating a product map by an `rTensor` equivalence rewrites its first factor). +-/ + +public section + +namespace TensorProduct + +variable {R R₂ : Type*} [CommSemiring R] [CommSemiring R₂] {σ₁₂ : R →+* R₂} +variable {M N M₂ N₂ : Type*} [AddCommMonoid M] [AddCommMonoid N] +variable [AddCommMonoid M₂] [AddCommMonoid N₂] +variable [Module R M] [Module R N] [Module R₂ M₂] [Module R₂ N₂] + +theorem map_sum_left {ι : Type*} (s : Finset ι) (f : ι → (M →ₛₗ[σ₁₂] M₂)) (g : N →ₛₗ[σ₁₂] N₂) : + map (∑ i ∈ s, f i) g = ∑ i ∈ s, map (f i) g := by + simpa only [mapBilinear_apply, LinearMap.sum_apply] using + LinearMap.congr_fun (_root_.map_sum (mapBilinear σ₁₂ M N M₂ N₂) f s) g + +end TensorProduct + +namespace LinearEquiv + +variable {R : Type*} [CommSemiring R] +variable {M N P : Type*} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] +variable [Module R M] [Module R N] [Module R P] +variable (f : N ≃ₗ[R] P) + +/-- Conjugating a product map `B ⊗ C` by the first-factor equivalence `f.rTensor M = f ⊗ id` +rewrites its first factor: `(f.rTensor M) ∘ (B ⊗ C) ∘ (f.rTensor M)⁻¹ = (f ∘ B ∘ f⁻¹) ⊗ C`. The +second factor `C` is left untouched. -/ +theorem rTensor_comp_map_comp_symm (B : N →ₗ[R] N) (C : M →ₗ[R] M) : + (f.rTensor M).toLinearMap ∘ₗ TensorProduct.map B C ∘ₗ (f.rTensor M).symm.toLinearMap + = TensorProduct.map ((f : N →ₗ[R] P) ∘ₗ B ∘ₗ (f.symm : P →ₗ[R] N)) C := by + refine TensorProduct.ext' fun p c => ?_ + simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.symm_rTensor, + TensorProduct.map_tmul, + rTensor_tmul] + +end LinearEquiv diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/Trace.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Trace.lean new file mode 100644 index 0000000000..b6626e3ebd --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/Trace.lean @@ -0,0 +1,50 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.Trace + +/-! +# Additional API for `LinearMap.trace` + +* `LinearMap.trace_eq_zero_of_not_exists_finset_basis` / + `LinearMap.trace_apply_eq_zero_of_not_exists_finset_basis`: named forms of the `dif_neg` + branch of the definition of `trace`. +-/ + +@[expose] public section + +noncomputable section + +universe u v + +namespace LinearMap + +open Module + +section + +variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M] + +/-- The trace of an endomorphism vanishes when there is no finite basis. The named form of +the `dif_neg`-on-the-`trace`-definition pattern. -/ +theorem trace_eq_zero_of_not_exists_finset_basis + (h : ¬ ∃ s : Finset M, Nonempty (Basis s R M)) : + trace R M = 0 := by + rw [trace, dite_eq_right h] + +/-- Apply-form of `trace_eq_zero_of_not_exists_finset_basis`. -/ +theorem trace_apply_eq_zero_of_not_exists_finset_basis + (h : ¬ ∃ s : Finset M, Nonempty (Basis s R M)) (f : M →ₗ[R] M) : + trace R M f = 0 := by + rw [trace_eq_zero_of_not_exists_finset_basis R h, LinearMap.zero_apply] + +end + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/LinearAlgebra/UnitaryGroup.lean b/LeanPool/AxQM/ToMathlib/LinearAlgebra/UnitaryGroup.lean new file mode 100644 index 0000000000..a4ba83532d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/LinearAlgebra/UnitaryGroup.lean @@ -0,0 +1,40 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.LinearAlgebra.UnitaryGroup + +/-! +# Additional API for the unitary group of matrices + +* `Matrix.reindex_mem_unitaryGroup`: reindexing rows and columns by the same equivalence + preserves unitarity. +-/ + +public section + +universe u v + +namespace Matrix + +variable {n : Type u} [DecidableEq n] [Fintype n] +variable {α : Type v} [CommRing α] [StarRing α] + +/-- **Reindexing a square matrix by one equivalence on both axes preserves unitarity.** If +`M ∈ unitaryGroup n α` then `Matrix.reindex e e M ∈ unitaryGroup p α` for any equivalence +`e : n ≃ p`: reindexing by the same equivalence on rows and columns is conjugation by a permutation, +a `⋆`-preserving monoid map. -/ +theorem reindex_mem_unitaryGroup {p : Type*} [DecidableEq p] [Fintype p] (e : n ≃ p) + {M : Matrix n n α} (hM : M ∈ Matrix.unitaryGroup n α) : + Matrix.reindex e e M ∈ Matrix.unitaryGroup p α := by + rw [mem_unitaryGroup_iff] at hM ⊢ + rw [reindex_apply, star_eq_conjTranspose, conjTranspose_submatrix, ← star_eq_conjTranspose, + submatrix_mul_equiv M (star M) _ e.symm _, hM, submatrix_one _ e.symm.injective] + +end Matrix diff --git a/LeanPool/AxQM/ToMathlib/NumberTheory/CosThreeFifthsIrrational.lean b/LeanPool/AxQM/ToMathlib/NumberTheory/CosThreeFifthsIrrational.lean new file mode 100644 index 0000000000..db2e046ddb --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/NumberTheory/CosThreeFifthsIrrational.lean @@ -0,0 +1,49 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.NumberTheory.Niven + +/-! # An angle with cosine `3/5` is an irrational multiple of `2π` + +If `cos θ = 3/5` then `θ / (2π)` is irrational — equivalently, `θ` is not a rational multiple +of `2π`. This is the mathematical content of Nielsen & Chuang's *Quantum Computation and Quantum +Information*, Exercise 4.42 ("Irrationality of `θ`"), which underlies the Solovay–Kitaev-style +observation that repeated application of a `cos θ = 3/5` rotation densely fills the circle. + +N&C suggest an elementary proof via `(3 + 4i)^m ≡ 3 + 4i (mod 5)` in the Gaussian integers. Here we +instead read it off **Niven's theorem** (`niven`): the only rational values taken by `cos` at +rational multiples of `π` are `{-1, -1/2, 0, 1/2, 1}`. Since `3/5` is rational and not among those +five values, `θ` cannot be a rational multiple of `π`, hence not of `2π`. Niven's theorem is a +faithful strengthening of the exercise's specific `(3+4i)`-argument, so this is a valid — indeed +more general — route to the same conclusion. +-/ + +@[expose] public section + +open Real + +/-- **Nielsen & Chuang, Exercise 4.42 (Irrationality of `θ`).** If `cos θ = 3/5` then `θ` is an +irrational multiple of `2π`: the coefficient `θ / (2π)` is an irrational number. + +Proved as a corollary of Niven's theorem (`niven`): were `θ / (2π)` rational, `θ` would be a +rational multiple of `π` with `cos θ = 3/5` rational, forcing `3/5 ∈ {-1, -1/2, 0, 1/2, 1}` — which +is false. -/ +theorem irrational_div_two_pi_of_cos_eq_three_div_five {θ : ℝ} + (hθ : Real.cos θ = 3 / 5) : Irrational (θ / (2 * π)) := by + rintro ⟨q, hq⟩ + -- `hq : (q : ℝ) = θ / (2π)`, so `θ = (2q) · π` is a rational multiple of `π`. + have h2π : (2 : ℝ) * π ≠ 0 := by positivity + have hθπ : θ = ((2 * q : ℚ) : ℝ) * π := by + have hθq : θ = (q : ℝ) * (2 * π) := (div_eq_iff h2π).mp hq.symm + rw [hθq]; push_cast; ring + -- Niven's theorem then pins `cos θ = 3/5` to one of the five allowed rational cosines. + have hmem := niven ⟨2 * q, hθπ⟩ ⟨3 / 5, by rw [hθ]; norm_num⟩ + rw [hθ] at hmem + norm_num [Set.mem_insert_iff, Set.mem_singleton_iff] at hmem diff --git a/LeanPool/AxQM/ToMathlib/NumberTheory/DiophantineApproximation/LegendreSharp.lean b/LeanPool/AxQM/ToMathlib/NumberTheory/DiophantineApproximation/LegendreSharp.lean new file mode 100644 index 0000000000..c9193d345e --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/NumberTheory/DiophantineApproximation/LegendreSharp.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.NumberTheory.DiophantineApproximation.ContinuedFractions +public import Mathlib.Data.Rat.Lemmas + +/-! +# Legendre's Theorem on rational approximation: the `s/r` form and its sharpness + +This file is the general-mathematics home of *Nielsen & Chuang, Quantum Computation and Quantum +Information*, **Theorem 5.1** (used in the continued-fractions step of order finding, §5.3.1): + +a rational `s/r` with `|s/r - φ| ≤ 1/(2r²)` is a convergent of the continued fraction of `φ`. + +The mathematical content is *Legendre's Theorem* of Diophantine approximation. Mathlib already has +it in the reduced-rational form `Real.exists_convs_eq_rat` (`|ξ - q| < 1 / (2 * q.den ^ 2)` implies +`q` is a convergent). This file records two things Theorem 5.1 additionally needs. + +## The `s/r` form (the theorem as stated) + +`Real.exists_convs_eq_of_abs_sub_lt` restates Legendre's Theorem in N&C's own `s/r` phrasing: for an +integer numerator `k` and a positive integer denominator `r` (**not** required to be in lowest +terms), an estimate `φ` within `1 / (2 r²)` of `k / r` has `k / r` as a convergent of `φ`. The +reduced denominator of `k / r` divides `r`, hence is `≤ r`, so the `1 / (2 r²)` accuracy is at least +the `1 / (2 · den²)` accuracy Legendre's Theorem requires. This is the form the order-finding and +discrete-logarithm post-processing actually consume. + +## Sharpness: the strict `<` cannot be relaxed to `≤` + +N&C states the hypothesis with a **non-strict** `≤` (Eq. 5.48), whereas the standard — and +provable — theorem needs the **strict** `<`. The non-strict version is genuinely *false* at the +boundary. The witness is `φ = 1/2` and `s/r = 1`. There `|1/2 - 1| = 1/2 = 1 / (2 · 1²)`, so the +non-strict +hypothesis holds *with equality*, yet the convergents of `1/2` are exactly `{0, 1/2}` (its continued +fraction is `[0; 2]`), so none of them equals `1`. Per obligation 1 (read the source critically; no +silent repair) the literal `≤`-statement is refuted here rather than quietly replaced by the strict +one. + +## Main statements + +* `Real.exists_convs_eq_of_abs_sub_lt` — **Theorem 5.1 (corrected, strict).** `|φ - k/r| < 1/(2r²)` + implies `k/r` is a convergent of `φ`, in N&C's `s/r` phrasing with `k : ℤ`, `r : ℕ`, `0 < r`. +* `Real.convergent_one_half_succ` — the positive-index convergents of `1/2` all equal `1/2`. +* `Real.convergent_one_half_ne_one` — no convergent of `1/2` (as `Real.convergent`) equals `1`. +* `Real.convs_one_half_ne_one` — no convergent of `1/2` (as `GenContFract.convs`) equals `1`. +* `Real.not_forall_exists_convs_eq_of_abs_sub_le` — **the `≤`-version of Theorem 5.1 is false**: it + is *not* the case that `|ξ - q| ≤ 1 / (2 * q.den ^ 2)` forces `q` to be a convergent of `ξ`. + +## Scope + +The "computable in `O(L³)` operations" clause of Theorem 5.1 is a complexity claim about the +continued-fractions algorithm; the library has no cost model in which to state it, so it is +deliberately out of scope, as for the sibling development in +`ToMathlib.NumberTheory.DiophantineApproximation.DiscreteLogRecovery`. +-/ + +open GenContFract + +public section + +namespace Real + +/-- **Nielsen & Chuang, Theorem 5.1 (corrected, strict form).** Legendre's Theorem in N&C's `s/r` +phrasing: if a real estimate `φ` approximates the fraction `k / r` to within `1 / (2 r²)`, then +`k / r` occurs as a convergent of the continued fraction of `φ`, so the continued-fractions +algorithm recovers it exactly. Here `k : ℤ`, `r : ℕ`, `0 < r`, and `k / r` need **not** be in lowest +terms. + +This specializes the reduced-rational Legendre theorem `Real.exists_convs_eq_rat`: the reduced +denominator of `k / r` divides `r`, hence is `≤ r`, so the `1 / (2 r²)` accuracy of the estimate +implies the `1 / (2 · den²)` accuracy Legendre's Theorem requires. + +The hypothesis uses the **strict** `<`; see `Real.not_forall_exists_convs_eq_of_abs_sub_le` for why +the literal non-strict `≤` of N&C (5.48) is false. -/ +theorem exists_convs_eq_of_abs_sub_lt {r : ℕ} (hr : 0 < r) (k : ℤ) {φ : ℝ} + (hφ : |φ - (k : ℝ) / r| < 1 / (2 * (r : ℝ) ^ 2)) : + ∃ n, (GenContFract.of φ).convs n = ((k : ℚ) / r : ℝ) := by + set q : ℚ := (k : ℚ) / r with hq + have hqeq : q = Rat.divInt k (r : ℤ) := by rw [hq, Rat.divInt_eq_div]; push_cast; ring + have hden : (q.den : ℤ) ∣ (r : ℤ) := by rw [hqeq]; exact Rat.den_dvd k r + have hdenle : q.den ≤ r := Nat.le_of_dvd hr (by exact_mod_cast hden) + have hcast : (↑q : ℝ) = (k : ℝ) / r := by rw [hq]; push_cast; ring + have key : ∃ n, (GenContFract.of φ).convs n = (↑q : ℝ) := by + apply Real.exists_convs_eq_rat + rw [hcast] + refine lt_of_lt_of_le hφ ?_ + have hpos : (0 : ℝ) < 2 * (q.den : ℝ) ^ 2 := by have := q.pos; positivity + have hle : 2 * (q.den : ℝ) ^ 2 ≤ 2 * (r : ℝ) ^ 2 := by + have hle' : (q.den : ℝ) ≤ r := by exact_mod_cast hdenle + nlinarith [hle', (Nat.cast_nonneg q.den : (0 : ℝ) ≤ (q.den : ℝ))] + exact one_div_le_one_div_of_le hpos hle + rw [hcast] at key + exact key + +/-- Every positive-index convergent of `1/2` equals `1/2`: the continued fraction of `1/2` is +`[0; 2]`, so `convergent (1/2) (n+1) = ⌊1/2⌋ + (convergent 2 n)⁻¹ = 0 + 2⁻¹ = 1/2`. -/ +theorem convergent_one_half_succ (n : ℕ) : Real.convergent (1 / 2 : ℝ) (n + 1) = 1 / 2 := by + have hfloor : ⌊(1 / 2 : ℝ)⌋ = 0 := by + rw [Int.floor_eq_zero_iff]; constructor <;> norm_num + have h2 : (Int.fract (1 / 2 : ℝ))⁻¹ = ((2 : ℤ) : ℝ) := by + rw [Int.fract, hfloor]; norm_num + rw [Real.convergent_succ, hfloor, h2, Real.convergent_of_int] + push_cast + norm_num + +/-- No convergent of `1/2` equals `1`: the zeroth is `⌊1/2⌋ = 0` and every later one is `1/2`. -/ +theorem convergent_one_half_ne_one (n : ℕ) : Real.convergent (1 / 2 : ℝ) n ≠ 1 := by + cases n with + | zero => rw [Real.convergent_zero]; norm_num + | succ m => rw [convergent_one_half_succ]; norm_num + +/-- No convergent of the continued fraction expansion of `1/2` equals `1`. This transports +`Real.convergent_one_half_ne_one` to the `GenContFract.convs` formulation via +`Real.convs_eq_convergent`. -/ +theorem convs_one_half_ne_one (n : ℕ) : + (GenContFract.of (1 / 2 : ℝ)).convs n ≠ ((1 : ℚ) : ℝ) := by + rw [convs_eq_convergent] + exact_mod_cast convergent_one_half_ne_one n + +/-- **Sharpness of Legendre's Theorem.** The strict inequality in `Real.exists_convs_eq_rat` +cannot be relaxed to `≤`: it is *not* true that every rational `q` with +`|ξ - q| ≤ 1 / (2 * q.den ^ 2)` is a convergent of `ξ`. + +This is *Nielsen & Chuang* Theorem 5.1 read literally, with its non-strict hypothesis `≤`. The +witness `ξ = 1/2`, `q = 1` attains the bound with equality (`|1/2 - 1| = 1/2 = 1 / (2 * 1 ^ 2)`) +yet `1` is not a convergent of `1/2` (whose convergents are `{0, 1/2}`). The faithful, correct +statement is the strict form `Real.exists_convs_eq_rat`. -/ +theorem not_forall_exists_convs_eq_of_abs_sub_le : + ¬ ∀ (ξ : ℝ) (q : ℚ), |ξ - (q : ℝ)| ≤ 1 / (2 * (q.den : ℝ) ^ 2) → + ∃ n, (GenContFract.of ξ).convs n = (q : ℝ) := by + intro H + obtain ⟨n, hn⟩ := H (1 / 2 : ℝ) 1 (by norm_num) + exact convs_one_half_ne_one n hn + +end Real diff --git a/LeanPool/AxQM/ToMathlib/NumberTheory/NontrivialSqrtOne.lean b/LeanPool/AxQM/ToMathlib/NumberTheory/NontrivialSqrtOne.lean new file mode 100644 index 0000000000..9bd633ff8f --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/NumberTheory/NontrivialSqrtOne.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Data.Nat.ModEq +public import Mathlib.NumberTheory.Divisors + +/-! +# Nontrivial square roots of one reveal a factor + +A *nontrivial square root of one* modulo `N` is a residue `x` with `x² ≡ 1 (mod N)` that is +neither `1` nor `-1`. This file proves the elementary number-theoretic fact — the mathematical +heart of the reduction of factoring to order-finding (Shor's algorithm) — that from such an `x` +one immediately reads off a *nontrivial factor* of `N`, namely `gcd(x - 1, N)` (and, in fact, +`gcd(x + 1, N)` as well). + +## Main definitions + +* `Nat.IsNontrivialFactor d n` : `d` is a divisor of `n` strictly between `1` and `n` (equivalently, + `d ∈ n.properDivisors` with `1 < d`). + +## Main results + +* `Nat.isNontrivialFactor_iff_mem_properDivisors` : `d` is a nontrivial factor of `n` iff it is a + proper divisor of `n` greater than `1` — the `Nat.properDivisors` spelling of the definition. +* `Nat.isNontrivialFactor_gcd_of_dvd_mul` : if `n ∣ a * b` but `n` divides neither `a` nor `b`, + then `gcd(a, n)` is a nontrivial factor of `n`. This is the reusable core. +* `Nat.isNontrivialFactor_gcd_sub_one_of_dvd_sq_sub_one` and + `Nat.isNontrivialFactor_gcd_add_one_of_dvd_sq_sub_one` : for a nontrivial square root of one, + *both* `gcd(x - 1, N)` and `gcd(x + 1, N)` are nontrivial factors of `N`. +* `Nat.isNontrivialFactor_gcd_sub_one_or_gcd_add_one_of_sq_modEq_one` : the statement exactly + as it appears as Nielsen & Chuang, *Theorem 5.2* (and Theorem A4.11): at least one of + `gcd(x - 1, N)`, `gcd(x + 1, N)` is a nontrivial factor of `N`. + +## Implementation notes + +Nielsen & Chuang phrase the hypotheses as the congruences `x² = 1 (mod N)`, `x ≠ 1 (mod N)`, +`x ≠ N - 1 = -1 (mod N)`, with `1 ≤ x ≤ N`; here `x + 1 ≡ 0 [MOD N]` is the (equivalent) +spelling of `x ≡ -1 (mod N)`. The book's own proof (Theorem A4.11) shows only that *at least +one* gcd is a nontrivial factor, but in fact both are, so the two per-side lemmas above are +proved and the book's disjunction is derived from them. + +Two fidelity points about the exact hypotheses: + +* **The `L`-bit / `O(L³)` claims are not formalised.** "`N` is an `L` bit number" and the gcds "can + be computed using `O(L³)` operations" are complexity statements about Euclid's algorithm; the + library has no cost model in which to state them, so they are deliberately out of scope. The + formal content captured here is the purely arithmetic claim. +* **The "`N` composite" hypothesis is unnecessary.** N&C assume `N` composite, but this is + automatic: a nontrivial square root of one *cannot* exist modulo a prime (or `1`), so the + theorems are proved for every `0 < N` — strictly more general, hence faithful to the content. +-/ + +@[expose] public section + +namespace Nat + +/-- `d` is a *nontrivial factor* of `n`: a divisor of `n` strictly between `1` and `n`. +Equivalently, `d ∈ n.properDivisors` together with `1 < d`. -/ +def IsNontrivialFactor (d n : ℕ) : Prop := d ∣ n ∧ 1 < d ∧ d < n + +/-- `d` is a nontrivial factor of `n` iff it is a proper divisor of `n` greater than `1`. This is +the `Nat.properDivisors` spelling of `Nat.IsNontrivialFactor`. -/ +theorem isNontrivialFactor_iff_mem_properDivisors {d n : ℕ} : + IsNontrivialFactor d n ↔ d ∈ n.properDivisors ∧ 1 < d := by + constructor + · rintro ⟨hdvd, h1, h2⟩ + exact ⟨Nat.mem_properDivisors.mpr ⟨hdvd, h2⟩, h1⟩ + · rintro ⟨hmem, h1⟩ + obtain ⟨hdvd, h2⟩ := Nat.mem_properDivisors.mp hmem + exact ⟨hdvd, h1, h2⟩ + +/-- If `n` divides a product `a * b` but divides neither factor, then `gcd(a, n)` is a nontrivial +factor of `n`: it is `> 1` (else `a` would be coprime to `n`, forcing `n ∣ b`) and `< n` (else +`n ∣ a`). -/ +theorem isNontrivialFactor_gcd_of_dvd_mul {a b n : ℕ} (hn : 0 < n) + (hab : n ∣ a * b) (ha : ¬ n ∣ a) (hb : ¬ n ∣ b) : + IsNontrivialFactor (Nat.gcd a n) n := by + refine ⟨Nat.gcd_dvd_right a n, ?_, ?_⟩ + · -- `1 < gcd a n` + have hpos : 0 < Nat.gcd a n := Nat.pos_of_dvd_of_pos (Nat.gcd_dvd_right a n) hn + have hne1 : Nat.gcd a n ≠ 1 := by + intro hcop + have hco : Nat.Coprime a n := hcop + exact hb (hco.symm.dvd_of_dvd_mul_left hab) + omega + · -- `gcd a n < n` + have hle : Nat.gcd a n ≤ n := Nat.le_of_dvd hn (Nat.gcd_dvd_right a n) + have hne : Nat.gcd a n ≠ n := fun heq => ha (heq ▸ Nat.gcd_dvd_left a n) + omega + +/-- First half of Nielsen & Chuang, Theorem 5.2: if `N ∣ x² - 1` but `N` divides neither `x - 1` +nor `x + 1` (i.e. `x` is a nontrivial square root of one modulo `N`), then `gcd(x - 1, N)` is a +nontrivial factor of `N`. -/ +theorem isNontrivialFactor_gcd_sub_one_of_dvd_sq_sub_one {N x : ℕ} (hN : 0 < N) + (hsq : N ∣ x ^ 2 - 1) (h1 : ¬ N ∣ x - 1) (h2 : ¬ N ∣ x + 1) : + IsNontrivialFactor (Nat.gcd (x - 1) N) N := by + have hmul : N ∣ (x - 1) * (x + 1) := by + rw [Nat.mul_comm, ← Nat.sq_sub_sq, Nat.one_pow]; exact hsq + exact isNontrivialFactor_gcd_of_dvd_mul hN hmul h1 h2 + +/-- Second half of Nielsen & Chuang, Theorem 5.2: under the same hypotheses, `gcd(x + 1, N)` is +also a nontrivial factor of `N`. -/ +theorem isNontrivialFactor_gcd_add_one_of_dvd_sq_sub_one {N x : ℕ} (hN : 0 < N) + (hsq : N ∣ x ^ 2 - 1) (h1 : ¬ N ∣ x - 1) (h2 : ¬ N ∣ x + 1) : + IsNontrivialFactor (Nat.gcd (x + 1) N) N := by + have hmul : N ∣ (x + 1) * (x - 1) := by rw [← Nat.sq_sub_sq, Nat.one_pow]; exact hsq + exact isNontrivialFactor_gcd_of_dvd_mul hN hmul h2 h1 + +/-- **Nielsen & Chuang, Theorem 5.2** (equivalently Theorem A4.11 in Appendix 4). Let `x` be a +nontrivial square root of one modulo `N`, i.e. `x² ≡ 1 (mod N)` with `x ≢ 1` and `x + 1 ≡ 0` +(the spelling of `x ≡ -1`) *both failing*. Then at least one of `gcd(x - 1, N)` and +`gcd(x + 1, N)` is a nontrivial factor of `N`. + +(In fact both are — see `Nat.isNontrivialFactor_gcd_sub_one_of_dvd_sq_sub_one` and +`Nat.isNontrivialFactor_gcd_add_one_of_dvd_sq_sub_one` — but the disjunction is stated to +match the textbook verbatim.) -/ +theorem isNontrivialFactor_gcd_sub_one_or_gcd_add_one_of_sq_modEq_one {N x : ℕ} (hN : 0 < N) + (hx : 1 ≤ x) (hsq : x ^ 2 ≡ 1 [MOD N]) (h1 : ¬ x ≡ 1 [MOD N]) + (h2 : ¬ x + 1 ≡ 0 [MOD N]) : + IsNontrivialFactor (Nat.gcd (x - 1) N) N ∨ IsNontrivialFactor (Nat.gcd (x + 1) N) N := by + have hxsq : 1 ≤ x ^ 2 := by simpa using Nat.pow_le_pow_left hx 2 + have hdvd_sq : N ∣ x ^ 2 - 1 := (Nat.modEq_iff_dvd' hxsq).mp hsq.symm + have ha : ¬ N ∣ x - 1 := fun hd => h1 ((Nat.modEq_iff_dvd' hx).mpr hd).symm + have hb : ¬ N ∣ x + 1 := fun hd => h2 (Nat.modEq_zero_iff_dvd.mpr hd) + exact Or.inl (isNontrivialFactor_gcd_sub_one_of_dvd_sq_sub_one hN hdvd_sq ha hb) + +end Nat diff --git a/LeanPool/AxQM/ToMathlib/Probability/WeakLaw.lean b/LeanPool/AxQM/ToMathlib/Probability/WeakLaw.lean new file mode 100644 index 0000000000..48152e1255 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Probability/WeakLaw.lean @@ -0,0 +1,150 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Probability.Moments.Variance +public import Mathlib.Probability.IdentDistrib +public import Mathlib.MeasureTheory.Function.ConvergenceInMeasure +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# The weak law of large numbers + +We prove the **`L²` weak law of large numbers** for real-valued random variables, in +`ProbabilityTheory.tendstoInMeasure_sum_range_div`: if `X : ℕ → Ω → ℝ` is a sequence of pairwise +independent, identically distributed random variables with finite second moment +(`MemLp (X 0) 2 μ`), then the sample averages `(∑ i ∈ range n, X i) / n` converge *in measure* +(equivalently, *in probability*) to the common mean `𝔼[X 0]`. + +The proof is the classical Chebyshev argument (this is Nielsen & Chuang, *Quantum Computation and +Quantum Information*, Theorem 12.3, Box 12.3): the variance of the sample average is +`Var[X 0] / n`, so by Chebyshev's inequality the probability of an `ε`-deviation is at most +`Var[X 0] / (n ε²)`, which tends to `0`. + +This complements `ProbabilityTheory.strong_law_ae`, the strong law (almost-sure convergence, which +requires only integrability), and `Real.iid_average_deviation_le` +(`ToMathlib/InformationTheory/IIDConcentration.lean`), the elementary finite-alphabet specialization +used for the asymptotic equipartition property. + +## Main results + +* `ProbabilityTheory.variance_sum_range_div`: the variance of the sample average + `(∑ i ∈ range n, X i) / n` is `Var[X 0] / n` (N&C Eq. 12.34). +* `ProbabilityTheory.integral_sum_range_div`: the mean of the sample average + `(∑ i ∈ range n, X i) / n` is `𝔼[X 0]` (the centering identity). +* `ProbabilityTheory.meas_abs_sum_range_div_sub_ge_le`: the quantitative Chebyshev bound + `ℙ {ω | ε ≤ |Sₙ ω - 𝔼[X 0]|} ≤ Var[X 0] / (n ε²)` (N&C Eq. 12.38). +* `ProbabilityTheory.tendstoInMeasure_sum_range_div`: the weak law of large numbers, stated as + convergence in measure of the sample averages to `𝔼[X 0]`. +* `ProbabilityTheory.tendsto_meas_abs_sum_range_div_sub_gt`: the same result in the literal form of + N&C Theorem 12.3, `p(|Sₙ - 𝔼[X 0]| > ε) → 0` for every `ε > 0`. +-/ + +@[expose] public section + +open MeasureTheory Filter Finset +open scoped ENNReal Topology + +namespace ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {X : ℕ → Ω → ℝ} + +/-- **Variance of the sample average** (Nielsen & Chuang, Eq. 12.34). For pairwise independent, +identically distributed, square-integrable real random variables `X`, the variance of the sample +average `(∑ i ∈ range n, X i) / n` is `Var[X 0] / n`. (For `n = 0` both sides are `0`.) -/ +theorem variance_sum_range_div (hℒp : MemLp (X 0) 2 μ) + (hindep : Pairwise fun i j => IndepFun (X i) (X j) μ) + (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) (n : ℕ) : + variance (fun ω => (∑ i ∈ range n, X i ω) / n) μ = variance (X 0) μ / n := by + have hmem : ∀ i, MemLp (X i) 2 μ := fun i => (hident i).memLp_iff.mpr hℒp + have hfunsum : (fun ω => ∑ i ∈ range n, X i ω) = ∑ i ∈ range n, X i := by + funext ω; rw [Finset.sum_apply] + have hsum : variance (fun ω => ∑ i ∈ range n, X i ω) μ = (n : ℝ) * variance (X 0) μ := by + rw [hfunsum, IndepFun.variance_sum (fun i _ => hmem i) (hindep.set_pairwise _), + Finset.sum_congr rfl (fun i _ => (hident i).variance_eq), Finset.sum_const, + Finset.card_range, nsmul_eq_mul] + have hcast : (fun ω => (∑ i ∈ range n, X i ω) / (n : ℝ)) + = fun ω => (n : ℝ)⁻¹ * ∑ i ∈ range n, X i ω := by funext ω; rw [div_eq_inv_mul] + rw [hcast, variance_const_mul, hsum] + rcases Nat.eq_zero_or_pos n with hn | hn + · simp [hn] + · have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + +/-- **Mean of the sample average.** For identically distributed, integrable real random variables +`X`, the mean of the sample average `(∑ i ∈ range n, X i) / n` is the common mean `𝔼[X 0]` (for +`n > 0`). This needs only the first moment (`Integrable (X 0)`), not the second. -/ +theorem integral_sum_range_div (hint : Integrable (X 0) μ) + (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) {n : ℕ} (hn : 0 < n) : + ∫ ω, (∑ i ∈ range n, X i ω) / (n : ℝ) ∂μ = ∫ x, X 0 x ∂μ := by + have hint' : ∀ i, Integrable (X i) μ := fun i => (hident i).integrable_iff.mpr hint + have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + rw [integral_div, integral_finsetSum (range n) (fun i _ => hint' i), + Finset.sum_congr rfl (fun i _ => (hident i).integral_eq), Finset.sum_const, + Finset.card_range, nsmul_eq_mul, mul_div_cancel_left₀ _ hn0] + +/-- **Chebyshev bound for the sample average** (Nielsen & Chuang, Eq. 12.38). For pairwise +independent, identically distributed, square-integrable real random variables `X`, the probability +that the sample average `Sₙ = (∑ i ∈ range n, X i) / n` deviates from the common mean `𝔼[X 0]` by at +least `ε` is at most `Var[X 0] / (n ε²)`. -/ +theorem meas_abs_sum_range_div_sub_ge_le [IsFiniteMeasure μ] (hℒp : MemLp (X 0) 2 μ) + (hindep : Pairwise fun i j => IndepFun (X i) (X j) μ) + (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : + μ {ω | ε ≤ |(∑ i ∈ range n, X i ω) / n - ∫ x, X 0 x ∂μ|} + ≤ ENNReal.ofReal (variance (X 0) μ / (n * ε ^ 2)) := by + have hmem : ∀ i, MemLp (X i) 2 μ := fun i => (hident i).memLp_iff.mpr hℒp + have hmemavg : MemLp (fun ω => (∑ i ∈ range n, X i ω) / (n : ℝ)) 2 μ := by + have hsum := memLp_finsetSum (range n) (fun i _ => hmem i) + simpa [div_eq_inv_mul] using hsum.const_mul (n : ℝ)⁻¹ + have hmean := integral_sum_range_div (hℒp.integrable one_le_two) hident hn + have hcheb := meas_ge_le_variance_div_sq hmemavg hε + rw [hmean, variance_sum_range_div hℒp hindep hident n, div_div] at hcheb + exact hcheb + +/-- **Weak law of large numbers** (Nielsen & Chuang, Theorem 12.3). For pairwise independent, +identically distributed, square-integrable real random variables `X`, the sample averages +`(∑ i ∈ range n, X i) / n` converge in measure (equivalently, in probability) to the common mean +`𝔼[X 0]`. -/ +theorem tendstoInMeasure_sum_range_div [IsProbabilityMeasure μ] (hℒp : MemLp (X 0) 2 μ) + (hindep : Pairwise fun i j => IndepFun (X i) (X j) μ) + (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) : + TendstoInMeasure μ (fun n ω => (∑ i ∈ range n, X i ω) / n) atTop (fun _ => ∫ x, X 0 x ∂μ) := by + rw [tendstoInMeasure_iff_norm] + intro ε hε + have hbound : Tendsto (fun n : ℕ => ENNReal.ofReal (variance (X 0) μ / ((n : ℝ) * ε ^ 2))) + atTop (nhds 0) := by + have hreal : Tendsto (fun n : ℕ => variance (X 0) μ / ((n : ℝ) * ε ^ 2)) atTop (nhds 0) := by + have heq : (fun n : ℕ => variance (X 0) μ / ((n : ℝ) * ε ^ 2)) + = fun n : ℕ => variance (X 0) μ / ε ^ 2 / (n : ℝ) := by + funext n; rw [div_div, mul_comm (n : ℝ)] + rw [heq]; exact tendsto_const_div_atTop_nhds_zero_nat _ + simpa using ENNReal.tendsto_ofReal hreal + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hbound + (Eventually.of_forall fun n => zero_le) ?_ + filter_upwards [eventually_gt_atTop 0] with n hn + simpa only [Real.norm_eq_abs] using + meas_abs_sum_range_div_sub_ge_le hℒp hindep hident hn hε + +/-- **Weak law of large numbers, literal N&C form** (Nielsen & Chuang, Theorem 12.3). For pairwise +independent, identically distributed, square-integrable real random variables `X`, for every +`ε > 0` the probability that the sample average `Sₙ = (∑ i ∈ range n, X i) / n` deviates from the +common mean `𝔼[X 0]` by more than `ε` tends to `0`, i.e. `p(|Sₙ - 𝔼[X 0]| > ε) → 0`. -/ +theorem tendsto_meas_abs_sum_range_div_sub_gt [IsProbabilityMeasure μ] (hℒp : MemLp (X 0) 2 μ) + (hindep : Pairwise fun i j => IndepFun (X i) (X j) μ) + (hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun n => μ {ω | ε < |(∑ i ∈ range n, X i ω) / n - ∫ x, X 0 x ∂μ|}) atTop (nhds 0) := by + have h := (tendstoInMeasure_iff_norm.mp + (tendstoInMeasure_sum_range_div hℒp hindep hident)) ε hε + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds h + (Eventually.of_forall fun n => zero_le) (Eventually.of_forall fun n => measure_mono ?_) + intro ω hω + simp only [Set.mem_ofPred_eq, Real.norm_eq_abs] at hω ⊢ + exact hω.le + +end ProbabilityTheory diff --git a/LeanPool/AxQM/ToMathlib/RingTheory/ZMod/OrderFinding.lean b/LeanPool/AxQM/ToMathlib/RingTheory/ZMod/OrderFinding.lean new file mode 100644 index 0000000000..56b456c321 --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/RingTheory/ZMod/OrderFinding.lean @@ -0,0 +1,309 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuationPi +public import LeanPool.AxQM.ToMathlib.GroupTheory.SpecificGroups.Cyclic.OrderValuationPiInvolution +public import Mathlib.RingTheory.ZMod.UnitsCyclic +public import Mathlib.Data.ZMod.QuotientRing +public import Mathlib.Algebra.Group.Pi.Units + +/-! +# The order-finding reduction: most units modulo an odd `N` are good for factoring + +For an odd modulus `N > 1`, this file bounds — as an exact cardinality inequality over the unit +group `(ZMod N)ˣ` — the fraction of units `x` that are **good** for the reduction of factoring to +order-finding: those whose multiplicative order `r = orderOf x` is even and satisfy +`x ^ (r / 2) ≠ -1`. Writing `m := N.primeFactors.card` for the number of distinct prime factors, + +`(2 ^ (m-1) - 1) * φ(N) ≤ 2 ^ (m-1) * #{x : (ZMod N)ˣ | Even (orderOf x) ∧ x ^ (orderOf x/2) ≠ -1}`, + +i.e. at least a `1 - 1/2^{m-1}` fraction of the units are good. This is the assembled statement of +Nielsen & Chuang's *Theorem 5.3* / *Theorem A4.13* — with the corrected bound `1 - 1/2^{m-1}`. + +## The erratum + +Nielsen & Chuang print the bound as `1 - 1/2^m` (their eq. (5.60) / (A4.32)). This is an +**erratum**: the printed `1/2^m` is false — for `N = 21` (`m = 2`) exactly half the units are +bad, so the good fraction is `1/2 = 1 - 1/2^{m-1}`, not `≥ 3/4 = 1 - 1/2^m`. N&C's own proof of +Theorem A4.13 reduces a bad unit to the event that all `m` per-prime `2`-adic order valuations +`dⱼ = v₂(rⱼ)` coincide, then bounds that event by `1/2^m` "from Lemma A4.12". That final step is +the slip: `p(all dⱼ equal) = ∑_D ∏ⱼ p(dⱼ = D)`, and bounding `m - 1` of the factors by Lemma +A4.12's `≤ 1/2` while summing the remaining one to `1` gives `1/2^{m-1}` — the `m`-th factor of +`1/2` that the printed `1/2^m` assumes is simply not there. The corrected and tight bound +`1 - 1/2^{m-1}` is what is proved here; the printed `1 - 1/2^m` is refuted separately via the +`N = 21` counterexample. + +## Main results + +* `ZMod.orderFinding_good_units_card_ge` : the corrected cardinality bound displayed above. +* `ZMod.card_good_units_twentyOne` : for `N = 21` exactly `6` of the `12` units are good — the + witness that the corrected bound `1 - 1/2^{m-1}` is *tight* (here `6/12 = 1/2 = 1 - 1/2^{m-1}`). +* `ZMod.not_orderFinding_good_units_printed_bound` : the refutation — the printed bound `1 - 1/2^m` + fails, since at `N = 21` it would demand at least `9` good units while there are only `6`. + +## Implementation notes + +The proof transports the abstract product-of-cyclic-groups machinery to `(ZMod N)ˣ` through the +Chinese remainder theorem. For odd `N > 1`, `ZMod.equivPi` gives a ring isomorphism +`ZMod N ≃+* Π p ∈ N.primeFactors, ZMod (p ^ α_p)` (with `α_p = N.factorization p`); passing to +units (`Units.mapEquiv`) and distributing units over the product (`MulEquiv.piUnits`) yields a +multiplicative equivalence `e : (ZMod N)ˣ ≃* Π p, (ZMod (p ^ α_p))ˣ`. Each factor is a finite +cyclic group (`ZMod.isCyclic_units_of_prime_pow`, valid since every `p` is an odd prime) of even +order (`Nat.totient_even`). Because `e` is multiplicative it preserves `orderOf` +(`orderOf_injective`) and, being induced by a ring isomorphism, carries the unit `-1` to the tuple +of `-1`'s; hence a unit is bad iff its image is bad in the product. The bad tuples are then +characterised (`IsCyclic.not_even_orderOf_or_pow_orderOf_div_two_eq_iff`) as those whose components +share one `2`-adic order valuation, and counted +(`IsCyclic.two_pow_mul_card_forall_padicValNat_orderOf_eq_le`). The product of the factor +cardinalities equals `φ(N)` (`Fintype.card_pi` through `e`), and complementation turns the +bad-count bound into the good-count bound. +-/ + +@[expose] public section + +open Finset + +namespace ZMod + +/-- **Corrected Nielsen & Chuang Theorem 5.3 (= Theorem A4.13), as a cardinality bound.** + +Let `N` be odd with `N > 1` and `m := N.primeFactors.card` its number of distinct prime factors. +The units `x` of `ZMod N` that are *good* for the order-finding reduction — those with `orderOf x` +even and `x ^ (orderOf x / 2) ≠ -1` — make up at least a `1 - 1/2^{m-1}` fraction of `(ZMod N)ˣ`: + +`(2 ^ (m - 1) - 1) * φ(N) ≤ 2 ^ (m - 1) * #{good units}`. + +Interpreting the uniform choice of a random unit, the probability of drawing a good unit is +`#{good}/φ(N) ≥ 1 - 1/2^{m-1}`. (Nielsen & Chuang print `1 - 1/2^m`; that bound is an erratum, +false already at `N = 21`.) -/ +theorem orderFinding_good_units_card_ge {N : ℕ} [NeZero N] (hN : Odd N) (hN1 : 1 < N) : + (2 ^ (N.primeFactors.card - 1) - 1) * N.totient ≤ + 2 ^ (N.primeFactors.card - 1) * + #{x : (ZMod N)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} := by + classical + have hN0 : N ≠ 0 := NeZero.ne N + -- Per-prime arithmetic facts: each `p ∈ N.primeFactors` is an odd prime with `α_p ≥ 1`. + have hp : ∀ p : N.primeFactors, Nat.Prime (p : ℕ) := fun p => + Nat.prime_of_mem_primeFactors p.2 + have hdvd : ∀ p : N.primeFactors, (p : ℕ) ∣ N := fun p => Nat.dvd_of_mem_primeFactors p.2 + have hp2 : ∀ p : N.primeFactors, (p : ℕ) ≠ 2 := by + intro p h + have hd := hdvd p + rw [h] at hd + rw [Nat.odd_iff] at hN + omega + have hα : ∀ p : N.primeFactors, 1 ≤ N.factorization (p : ℕ) := by + intro p + rw [← Nat.Prime.pow_dvd_iff_le_factorization (hp p) hN0] + simpa using hdvd p + have h2lt : ∀ p : N.primeFactors, 2 < (p : ℕ) ^ N.factorization (p : ℕ) := by + intro p + have hp3 : 3 ≤ (p : ℕ) := by have := (hp p).two_le; have := hp2 p; omega + calc 2 < 3 := by norm_num + _ ≤ (p : ℕ) := hp3 + _ ≤ (p : ℕ) ^ N.factorization (p : ℕ) := Nat.le_self_pow (by have := hα p; omega) _ + -- Factor-group instances: finite, cyclic, of even order. + have hNZfac : ∀ p : N.primeFactors, NeZero ((p : ℕ) ^ N.factorization (p : ℕ)) := fun p => + ⟨pow_ne_zero _ (hp p).ne_zero⟩ + have hFin : ∀ p : N.primeFactors, Fintype (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ := + fun p => inferInstance + have hCyc : ∀ p : N.primeFactors, IsCyclic (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ := + fun p => ZMod.isCyclic_units_of_prime_pow (p : ℕ) (hp p) (hp2 p) _ + have : Nonempty N.primeFactors := + Finset.nonempty_coe_sort.mpr (Nat.nonempty_primeFactors.mpr hN1) + have hev : ∀ p : N.primeFactors, + 2 ∣ Fintype.card (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ := by + intro p + rw [ZMod.card_units_eq_totient] + exact (Nat.totient_even (h2lt p)).two_dvd + -- `-1` is a nontrivial involution in each factor. + set neg : (p : N.primeFactors) → (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ := + fun p => (-1 : (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ) with hnegdef + have hneg2 : ∀ p, neg p ^ 2 = 1 := fun p => by rw [hnegdef, neg_one_sq] + have hneg1 : ∀ p, neg p ≠ 1 := by + intro p h + have : Fact (2 < (p : ℕ) ^ N.factorization (p : ℕ)) := ⟨h2lt p⟩ + exact ZMod.neg_one_ne_one (n := (p : ℕ) ^ N.factorization (p : ℕ)) (congrArg Units.val h) + -- The CRT multiplicative equivalence `(ZMod N)ˣ ≃* Π p, (ZMod (p ^ α_p))ˣ`. + set F : ZMod N ≃+* ((p : N.primeFactors) → ZMod ((p : ℕ) ^ N.factorization (p : ℕ))) := + ZMod.equivPi N hN0 with hF + set e : (ZMod N)ˣ ≃* + ((p : N.primeFactors) → (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ) := + (Units.mapEquiv F.toMulEquiv).trans MulEquiv.piUnits with he + -- The underlying map of `e`, componentwise, is `F` on the underlying ring element. + have he_val : ∀ (u : (ZMod N)ˣ) (p : N.primeFactors), + ((e u p : (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ) : + ZMod ((p : ℕ) ^ N.factorization (p : ℕ))) = F (u : ZMod N) p := by + intro u p + rw [he] + simp only [MulEquiv.trans_apply, MulEquiv.val_piUnits_apply, Units.coe_mapEquiv, + RingEquiv.toMulEquiv_eq_coe, RingEquiv.coe_toMulEquiv] + -- `e` carries `-1` to the tuple of `-1`'s (it comes from a ring isomorphism). + have he_neg : e (-1) = neg := by + funext p + apply Units.ext + rw [he_val, hnegdef] + push_cast + rw [map_neg, map_one] + rfl + -- `e` preserves `orderOf`. + have hord : ∀ x : (ZMod N)ˣ, orderOf (e x) = orderOf x := fun x => + orderOf_injective e.toMonoidHom e.injective x + -- A unit is bad iff its image in the product is bad. + have hbad_iff : ∀ x : (ZMod N)ˣ, + (¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1) + ↔ (¬ Even (orderOf (e x)) ∨ (e x) ^ (orderOf (e x) / 2) = neg) := by + intro x + rw [hord x] + have hpow : (e x) ^ (orderOf x / 2) = e (x ^ (orderOf x / 2)) := (map_pow e x _).symm + have hdisj2 : (e x) ^ (orderOf x / 2) = neg ↔ x ^ (orderOf x / 2) = -1 := by + rw [hpow, ← he_neg]; exact e.apply_eq_iff_eq + exact or_congr Iff.rfl hdisj2.symm + -- Count transport: bad units of `(ZMod N)ˣ` ↔ tuples sharing one `2`-adic order valuation. + have hbad_card : + #{x : (ZMod N)ˣ | ¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1} = + #{f : (p : N.primeFactors) → (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ | + ∀ i j, padicValNat 2 (orderOf (f i)) = padicValNat 2 (orderOf (f j))} := by + rw [← Fintype.card_subtype, ← Fintype.card_subtype] + refine Fintype.card_congr (Equiv.subtypeEquiv e.toEquiv fun x => ?_) + exact (hbad_iff x).trans + (IsCyclic.not_even_orderOf_or_pow_orderOf_div_two_eq_iff hev neg hneg2 hneg1 (e x)) + -- Counting bound (Lemma A4.12 fan-out) with the factor-cardinality product equal to `φ(N)`. + have hPR2 := IsCyclic.two_pow_mul_card_forall_padicValNat_orderOf_eq_le + (ι := N.primeFactors) (G := fun p => (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ) hev + rw [Fintype.card_coe] at hPR2 + have hprodT : + ∏ p : N.primeFactors, Fintype.card (ZMod ((p : ℕ) ^ N.factorization (p : ℕ)))ˣ + = N.totient := by + rw [← Fintype.card_pi, Fintype.card_congr e.symm.toEquiv, ZMod.card_units_eq_totient] + rw [hprodT] at hPR2 + -- The bad-count bound: `2^(m-1) * #bad ≤ φ(N)`. + have hBound : 2 ^ (N.primeFactors.card - 1) * + #{x : (ZMod N)ˣ | ¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1} ≤ N.totient := by + rw [hbad_card]; exact hPR2 + -- Good and bad units partition `(ZMod N)ˣ`. + have hApart : + #{x : (ZMod N)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} + + #{x : (ZMod N)ˣ | ¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1} = N.totient := by + have hfilter : + Finset.univ.filter + (fun x : (ZMod N)ˣ => ¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1) = + Finset.univ.filter (fun x => ¬ (Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1)) := + Finset.filter_congr fun x _ => by tauto + rw [hfilter, Finset.card_filter_add_card_filter_not, Finset.card_univ, + ZMod.card_units_eq_totient] + -- Final arithmetic: complement the bad-count bound. + set c := 2 ^ (N.primeFactors.card - 1) with hc + have hc1 : 1 ≤ c := Nat.one_le_two_pow + have e1 : (c - 1) * N.totient + N.totient = c * N.totient := by + conv_rhs => rw [← Nat.sub_add_cancel hc1] + rw [add_mul, one_mul] + have e2 : c * #{x : (ZMod N)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} + + c * #{x : (ZMod N)ˣ | ¬ Even (orderOf x) ∨ x ^ (orderOf x / 2) = -1} = c * N.totient := by + rw [← Nat.mul_add, hApart] + omega + +/-! +### The erratum: refuting the printed bound `1 - 1/2^m` + +Nielsen & Chuang state the bound as `1 - 1/2^m` (eq. (5.60) / (A4.32)); the corrected and tight +bound proved above is `1 - 1/2^{m-1}`. We now certify that the printed bound is genuinely false, +via the smallest counterexample `N = 21 = 3 · 7`. There `m = 2`, `φ(21) = 12`, and exactly `6` +units are good — so the good fraction is `1/2`, not the `≥ 3/4` the printed bound would require. + +The multiplicative order over `(ZMod 21)ˣ` is `noncomputable`, so the good units cannot be counted +by `decide` directly. The group has exponent `6` (every unit satisfies `x ^ 6 = 1`), so on it the +order is recovered by the computable surrogate `ordAux21` below; rewriting `orderOf` to `ordAux21` +makes the good-unit predicate decidable, and the count is then evaluated by `decide`. +-/ + +/-- A computable stand-in for `orderOf` on `(ZMod 21)ˣ`, which has exponent `6`: it returns the +least divisor of `6` annihilating `x`. On this group it agrees with `orderOf` +(`orderOf_eq_ordAux21`), which lets the otherwise-`noncomputable` good-unit count be decided. -/ +private def ordAux21 (x : (ZMod 21)ˣ) : ℕ := + if x = 1 then 1 else if x ^ 2 = 1 then 2 else if x ^ 3 = 1 then 3 else 6 + +/-- On `(ZMod 21)ˣ` (a group of exponent `6`) the computable surrogate `ordAux21` agrees with the +genuine multiplicative order `orderOf`. Proved for any `x` with `x ^ 6 = 1`. -/ +private theorem orderOf_eq_ordAux21 (x : (ZMod 21)ˣ) (hx6 : x ^ 6 = 1) : + orderOf x = ordAux21 x := by + have hdvd : orderOf x ∣ 6 := orderOf_dvd_iff_pow_eq_one.mpr hx6 + have hpos : 0 < orderOf x := orderOf_pos x + have hle : orderOf x ≤ 6 := Nat.le_of_dvd (by norm_num) hdvd + unfold ordAux21 + split_ifs with h1 h2 h3 + · subst h1; simp + · have hn1 : orderOf x ≠ 1 := fun h => h1 (orderOf_eq_one_iff.mp h) + rcases Nat.prime_two.eq_one_or_self_of_dvd _ (orderOf_dvd_iff_pow_eq_one.mpr h2) with h | h + · exact absurd h hn1 + · exact h + · have hn1 : orderOf x ≠ 1 := fun h => h1 (orderOf_eq_one_iff.mp h) + rcases Nat.prime_three.eq_one_or_self_of_dvd _ (orderOf_dvd_iff_pow_eq_one.mpr h3) with h | h + · exact absurd h hn1 + · exact h + · have hn1 : orderOf x ≠ 1 := fun h => h1 (orderOf_eq_one_iff.mp h) + have hn2 : orderOf x ≠ 2 := fun h => h2 (by rw [← h]; exact pow_orderOf_eq_one x) + have hn3 : orderOf x ≠ 3 := fun h => h3 (by rw [← h]; exact pow_orderOf_eq_one x) + have hn4 : orderOf x ≠ 4 := fun h => by rw [h] at hdvd; norm_num at hdvd + have hn5 : orderOf x ≠ 5 := fun h => by rw [h] at hdvd; norm_num at hdvd + omega + +-- The `decide` calls below enumerate the 12-element unit group `(ZMod 21)ˣ`, which exceeds the +-- default heartbeat budget. +/-- **Tightness of the corrected bound at `N = 21`.** Exactly `6` of the `12` units of `ZMod 21` +are good for the order-finding reduction (order even and `x ^ (orderOf x / 2) ≠ -1`). Since +`6 / 12 = 1/2 = 1 - 1/2^{m-1}` with `m = 2`, the corrected bound of +`ZMod.orderFinding_good_units_card_ge` is attained — and, a fortiori, the printed bound +`1 - 1/2^m = 3/4` is violated. -/ +theorem card_good_units_twentyOne : + #{x : (ZMod 21)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} = 6 := by + have h6 : ∀ x : (ZMod 21)ˣ, x ^ 6 = 1 := by decide + have key : #{x : (ZMod 21)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} + = #{x : (ZMod 21)ˣ | Even (ordAux21 x) ∧ x ^ (ordAux21 x / 2) ≠ -1} := by + apply congrArg Finset.card + apply Finset.filter_congr + intro x _ + rw [orderOf_eq_ordAux21 x (h6 x)] + rw [key]; decide + +/-- **Nielsen & Chuang's Theorem 5.3 is false as printed.** The book states the good-unit fraction +is `≥ 1 - 1/2^m` (their eq. (5.60) / (A4.32)), which as a cardinality bound reads +`(2^m - 1) * φ(N) ≤ 2^m * #{good units}` for every odd `N > 1` with `m` distinct prime factors. +This universal statement is refuted by `N = 21`: there `m = 2`, `φ(21) = 12`, and there are only +`6` good units (`card_good_units_twentyOne`), whereas the printed bound would force at least `9`. +The corrected bound `1 - 1/2^{m-1}` (`ZMod.orderFinding_good_units_card_ge`) holds and is tight. -/ +theorem not_orderFinding_good_units_printed_bound : + ¬ ∀ (N : ℕ) [NeZero N], Odd N → 1 < N → + (2 ^ N.primeFactors.card - 1) * N.totient ≤ + 2 ^ N.primeFactors.card * + #{x : (ZMod N)ˣ | Even (orderOf x) ∧ x ^ (orderOf x / 2) ≠ -1} := by + intro h + have h21 := h 21 (by decide) (by norm_num) + have htot : (21 : ℕ).totient = 12 := by decide + have hm : 2 ≤ (21 : ℕ).primeFactors.card := by + have h3 : (3 : ℕ) ∈ (21 : ℕ).primeFactors := by + rw [Nat.mem_primeFactors]; exact ⟨by decide, by norm_num, by norm_num⟩ + have h7 : (7 : ℕ) ∈ (21 : ℕ).primeFactors := by + rw [Nat.mem_primeFactors]; exact ⟨by decide, by norm_num, by norm_num⟩ + have hsub : ({3, 7} : Finset ℕ) ⊆ (21 : ℕ).primeFactors := by + intro x hx + simp only [Finset.mem_insert, Finset.mem_singleton] at hx + rcases hx with rfl | rfl + · exact h3 + · exact h7 + calc (2 : ℕ) = ({3, 7} : Finset ℕ).card := by decide + _ ≤ _ := Finset.card_le_card hsub + rw [card_good_units_twentyOne, htot] at h21 + have hk : 4 ≤ 2 ^ (21 : ℕ).primeFactors.card := + calc (4 : ℕ) = 2 ^ 2 := by norm_num + _ ≤ 2 ^ (21 : ℕ).primeFactors.card := Nat.pow_le_pow_right (by norm_num) hm + omega + +end ZMod diff --git a/LeanPool/AxQM/ToMathlib/Topology/Algebra/Module/FiniteDimension.lean b/LeanPool/AxQM/ToMathlib/Topology/Algebra/Module/FiniteDimension.lean new file mode 100644 index 0000000000..d77ac6704d --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Topology/Algebra/Module/FiniteDimension.lean @@ -0,0 +1,54 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Topology.Algebra.Module.FiniteDimension +public import LeanPool.AxQM.ToMathlib.Algebra.Ring.Equiv + +/-! +# CLM/LM round-trip and ring-inverse bridge lemmas in finite dimensions + +A round-trip identity for `LinearMap.toContinuousLinearMap` / the `CLM → LM` coercion, and a +`simp` bridge identifying `Ring.inverse` computed at the `→L` level with `Ring.inverse` computed +at the `→ₗ` level. +-/ + +universe u v w x + +@[expose] public section + +variable {𝕜 : Type u} [hnorm : NontriviallyNormedField 𝕜] {E : Type v} [AddCommGroup E] + [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul 𝕜 E] {F : Type w} + [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [IsTopologicalAddGroup F] + [ContinuousSMul 𝕜 F] {F' : Type x} [AddCommGroup F'] [Module 𝕜 F'] [TopologicalSpace F'] + [IsTopologicalAddGroup F'] [ContinuousSMul 𝕜 F'] + +variable [CompleteSpace 𝕜] + +namespace LinearMap + +variable [T2Space E] [FiniteDimensional 𝕜 E] + +/-- Round-trip identity: for a continuous linear map `f` between finite-dimensional spaces, +forgetting continuity and then re-promoting to `→L` recovers `f`. -/ +@[simp] +theorem _root_.ContinuousLinearMap.toLinearMap_toContinuousLinearMap (f : E →L[𝕜] F') : + LinearMap.toContinuousLinearMap (f : E →ₗ[𝕜] F') = f := + toContinuousLinearMap.apply_symm_apply f + +/-- Ring inverse commutes with the `CLM → LM` coercion in finite dimensions: the inverse of `f` in +the `→L` ring coerces to the inverse of `↑f` in the `→ₗ` ring. Provided as a `@[simp]` bridge so +that expressions like `↑(B - X * Ring.inverse A * X)` reduce to their `→ₗ` counterparts. -/ +@[simp] +theorem _root_.ContinuousLinearMap.coe_ringInverse {E' : Type*} [NormedAddCommGroup E'] + [NormedSpace 𝕜 E'] [FiniteDimensional 𝕜 E'] (f : E' →L[𝕜] E') : + ((Ring.inverse f : E' →L[𝕜] E') : E' →ₗ[𝕜] E') = Ring.inverse (f : E' →ₗ[𝕜] E') := + (Module.End.toContinuousLinearMap E').symm.toRingEquiv.map_ringInverse f + +end LinearMap diff --git a/LeanPool/AxQM/ToMathlib/Topology/UniformSpace/LocallyUniformConvergence.lean b/LeanPool/AxQM/ToMathlib/Topology/UniformSpace/LocallyUniformConvergence.lean new file mode 100644 index 0000000000..27a89a363b --- /dev/null +++ b/LeanPool/AxQM/ToMathlib/Topology/UniformSpace/LocallyUniformConvergence.lean @@ -0,0 +1,35 @@ +/- +Copyright (c) 2026 Axiomatic_AI. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Winston Yin, Frank Koppens +-/ + +/- Lean Pool ported this file to its pinned dependencies and module paths. -/ + +module + +public import Mathlib.Topology.UniformSpace.LocallyUniformConvergence + +/-! +# Constant families converge locally uniformly + +A constant family of functions converges locally uniformly to that constant function. +-/ + +@[expose] public section + +open Topology Uniformity Filter Set Uniform + +variable {α β ι : Type*} [TopologicalSpace α] [UniformSpace β] +variable {s : Set α} {p : Filter ι} + +/-- A constant family of functions `fun _ ↦ h` converges locally uniformly to `h` on any set. -/ +theorem tendstoLocallyUniformlyOn_const_fn (h : α → β) : + TendstoLocallyUniformlyOn (fun _ : ι => h) h p s := + fun _u hu _x _hx ↦ ⟨s, self_mem_nhdsWithin, + .of_forall fun _ _ _ ↦ refl_mem_uniformity hu⟩ + +/-- A constant family of functions `fun _ ↦ h` converges locally uniformly to `h`. -/ +theorem tendstoLocallyUniformly_const_fn (h : α → β) : + TendstoLocallyUniformly (fun _ : ι => h) h p := + tendstoLocallyUniformlyOn_univ.mp <| tendstoLocallyUniformlyOn_const_fn h diff --git a/LeanPool/projects/axqm.yaml b/LeanPool/projects/axqm.yaml new file mode 100644 index 0000000000..9a54eb37ca --- /dev/null +++ b/LeanPool/projects/axqm.yaml @@ -0,0 +1,64 @@ +slug: axqm +title: Finite-dimensional quantum information +summary: Develops finite-dimensional quantum states, composite systems, measurements + and circuits. Formal results include Uhlmann's fidelity characterization, the Holevo + bound, Schumacher compression away from the entropy threshold, and a product-state + capacity equality for arbitrary state maps. +branch: quantum information +entry_module: LeanPool.AxQM +authors: +- Weichen Winston Yin +- Frank H. L. Koppens +source: + title: Autonomous formalisation of finite-dimensional quantum mechanics grounded in axiomatic foundations + arxiv: "2612.02353" + url: https://github.com/Axiomatic-AI/AxQMLib/tree/1bc3602193961227cad4f5fd3ae794fb584c05b6 + github_repo: Axiomatic-AI/AxQMLib + commit: 1bc3602193961227cad4f5fd3ae794fb584c05b6 + announcement_url: https://arxiv.org/abs/2612.02353v1 + announcement_date: "2026-12-02" +license: Apache-2.0 +status: verified +provenance: AI +provenance_evidence: The paper's Methods describe a human-written quantum postulate + layer and autonomous agents producing the subsequent formalisation. +main_declarations: +- AxQM.State.isGreatest_norm_overlap_purification +- AxQM.holevo_bound +- AxQM.State.reliablyCompressible_iff_vonNeumannEntropy_lt +- AxQM.channelHolevoChi_eq_productStateCapacity +main_results: +- declaration: AxQM.State.isGreatest_norm_overlap_purification + informal: The fidelity of two states is the greatest absolute overlap of two + purifications on the system tensored with a copy of itself. + source_ref: Nielsen and Chuang, Quantum Computation and Quantum Information, + tenth-anniversary edition, Theorem 9.4. +- declaration: AxQM.holevo_bound + informal: For a finite ensemble measured by a finite-outcome measurement, the + classical mutual information between the label and the outcome is bounded by + the entropy of the mixed state minus the mean entropy of the ensemble states. + source_ref: Nielsen and Chuang, Quantum Computation and Quantum Information, + tenth-anniversary edition, Theorem 12.1. +- declaration: AxQM.State.reliablyCompressible_iff_vonNeumannEntropy_lt + informal: At a nonnegative rate away from the entropy threshold, an independent + and identically distributed quantum source is reliably compressible exactly + when the rate, converted from qubits to nats, exceeds the source's von Neumann entropy. + source_ref: Nielsen and Chuang, Quantum Computation and Quantum Information, + tenth-anniversary edition, Theorem 12.6. +- declaration: AxQM.channelHolevoChi_eq_productStateCapacity + informal: For an arbitrary state map on a finite-dimensional system admitting a + state, the supremal Holevo information of the output ensembles equals the + capacity for independent uses with product-state inputs and joint decoding. + source_ref: Extends Nielsen and Chuang, Quantum Computation and Quantum Information, + tenth-anniversary edition, Theorem 12.8, from trace-preserving quantum operations + to arbitrary state maps. For quantum channels, holevoChi_comp_eq_of_isChannel + gives the per-ensemble equality with equation (12.71). +tags: +- quantum-information +- quantum-channels +- quantum-entropy +- coding-theory +msc: +- 81P45 +- 81P68 +- 94A17