Offline · exact source
Exact Lean source

InfiniteTraceClass

formalization/Cloning/InfiniteTraceClass.lean

Source hash: 8989a10ec2f035d84eeadeb1ab47af9dbbbb80ccbfcdf85f31577d3c5e55f3c9

Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.

The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.

Declarations in this module
1/-
2Copyright (c) 2026 Tom Ole Diem. All rights reserved.
3Released under Apache 2.0 license as described in PHYSLIB-LICENSE.txt.
4Authors: Tom Ole Diem
5 
6Adapted from Physlib commit f6e446ca99fd83b3a60743a61900cb2acb98f531,
7PhyslibAlpha/ProbabilisticTheory/HilbertSpace/TraceClass/Basic.lean.
8The finite-multiplicity section is deliberately omitted. Compatibility edits remove the newer
9Idempotent import, retain CompleteSpace for order monotonicity, qualify sub_apply, and
10replace module/public declarations with ordinary imports and a namespace. The namespace is Cloning.InfiniteTraceClass. Checked against Lean v4.29.0-rc6
11without changing dependencies. Upstream blob: ddccf1580a99e198952628e83c21d21b094f285e.
12-/
13 
14import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Abs
15import Mathlib.Analysis.InnerProductSpace.StarOrder
16import Mathlib.Analysis.InnerProductSpace.l2Space
17import Mathlib.Analysis.InnerProductSpace.Trace
18import Mathlib.LinearAlgebra.FiniteDimensional.Defs
19import Mathlib.LinearAlgebra.Dimension.Finite
20import Mathlib.LinearAlgebra.Trace
21import Mathlib.LinearAlgebra.Projection
22 
23/-!
24 
25# Trace-class operators
26 
27## i. Overview
28 
29For a bounded operator `T` on a complex Hilbert space, `|T| = √(T⋆T)` is its absolute value. `T` is
30trace class when the diagonal sum `∑ᵢ ⟪eᵢ, |T| eᵢ⟫` converges for a Hilbert basis `{eᵢ}`. The sum is
31the trace norm `‖T‖₁`, and `Tr T = ∑ᵢ ⟪eᵢ, T eᵢ⟫` is the trace.
32 
33For positive and self-adjoint operators the diagonal sums do not depend on the basis. The proof
34writes `⟪eᵢ, S eᵢ⟫ = ‖√S eᵢ‖²`, expands in a second basis by Parseval and exchanges the two
35nonnegative sums. In finite dimension the trace agrees with the linear-algebra trace.
36 
37This module provides the analytic trace-class predicate and basis-independent trace norm,
38and proves basis independence of the trace for positive and self-adjoint operators. It does
39not yet provide a Banach-space bundle, general trace linearity, density operators, or
40infinite-dimensional fidelity or Gaussian channels. The upstream finite-multiplicity section
41is excluded because it needs a newer Mathlib API.
42 
43## ii. Key results
44 
45- `IsTraceClass` : a bounded operator is trace class.
46- `traceNorm`, `trace` : the trace norm and the trace.
47- `summable_inner_abs_of_hilbertBasis` : trace class does not depend on the basis.
48- `traceNorm_eq_of_hilbertBasis` : the trace norm does not depend on the basis.
49- `trace_eq_of_hilbertBasis_of_isSelfAdjoint` : the trace of a self-adjoint trace-class operator
50  does not depend on the basis.
51- `trace_eq_sum_inner_hilbertBasis_of_finiteDimensional` : in finite dimension the linear-algebra
52  trace is the diagonal sum.
53 
54## iii. Table of contents
55 
56- A. Trace class
57  - A.1. Basis independence
58 
59-/
60 
61namespace Cloning.InfiniteTraceClass
62 
63set_option backward.isDefEq.respectTransparency false
64 
65noncomputable section
66 
67open scoped ComplexOrder InnerProductSpace
68 
69variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H]
70 
71/-! ## A. Trace class -/
72 
73/-- **`T` is trace class**: `∑ᵢ ⟪eᵢ, |T| eᵢ⟫` converges for some Hilbert basis `{eᵢ}` of `H`
74(`|T| := CFC.abs T`, Mathlib's continuous functional calculus absolute value `√(T⋆T)`). By the
75basis-independence theorem below, "some" is equivalent to "every". -/
76def IsTraceClass (T : H →L[ℂ] H) : Prop :=
77  ∃ (w : Set H) (b : HilbertBasis w ℂ H), Summable (fun i => (⟪b i, CFC.abs T (b i)⟫_ℂ).re)
78 
79/-! ### A.1. Basis independence
80 
81The proofs use the square root of the functional calculus and Parseval's identity for Hilbert
82bases. -/
83 
84omit [CompleteSpace H] in
85/-- **Parseval's identity**: `∑ᵢ |⟪eᵢ, y⟫|² = ‖y‖²` for a Hilbert basis `{eᵢ}`. -/
86lemma hasSum_norm_sq_inner_basis {w : Set H} (b : HilbertBasis w ℂ H) (y : H) :
87    HasSum (fun i : w => ‖⟪b i, y⟫_ℂ‖ ^ 2) (‖y‖ ^ 2) := by
88  have h := b.hasSum_inner_mul_inner y y
89  have hpt : ∀ i : w, ⟪y, b i⟫_ℂ * ⟪b i, y⟫_ℂ = ((‖⟪b i, y⟫_ℂ‖ ^ 2 : ℝ) : ℂ) := fun i => by
90    rw [← inner_conj_symm y (b i), RCLike.conj_mul]
91    norm_cast
92  have hval : ⟪y, y⟫_ℂ = ((‖y‖ ^ 2 : ℝ) : ℂ) := by
93    rw [inner_self_eq_norm_sq_to_K]; norm_cast
94  simp_rw [hpt] at h
95  rw [hval] at h
96  exact Complex.hasSum_ofReal.mp h
97 
98/-- For self-adjoint `S`, the sum `∑ᵢ ‖S eᵢ‖²` does not depend on the Hilbert basis. -/
99lemma hasSum_norm_sq_apply_of_selfAdjoint {S : H →L[ℂ] H} (hS : IsSelfAdjoint S)
100    {w w' : Set H} (b : HilbertBasis w ℂ H) (c : HilbertBasis w' ℂ H)
101    (hb : Summable (fun i : w => ‖S (b i)‖ ^ 2)) :
102    HasSum (fun j : w' => ‖S (c j)‖ ^ 2) (∑' i : w, ‖S (b i)‖ ^ 2) := by
103  classical
104  set F : w → w' → ℝ := fun i j => ‖⟪c j, S (b i)⟫_ℂ‖ ^ 2 with hFdef
105  have hFnonneg : 0 ≤ Function.uncurry F := fun _ => sq_nonneg _
106  have hrow : ∀ i : w, HasSum (F i) (‖S (b i)‖ ^ 2) := fun i =>
107    hasSum_norm_sq_inner_basis c (S (b i))
108  have hSstar : ContinuousLinearMap.adjoint S = S := (ContinuousLinearMap.star_eq_adjoint
109      S).symm.trans hS
110  have hcol : ∀ j : w', HasSum (fun i : w => F i j) (‖S (c j)‖ ^ 2) := by
111    intro j
112    have e1 : ∀ i : w, ⟪c j, S (b i)⟫_ℂ = ⟪S (c j), b i⟫_ℂ := fun i => by
113      have h1 := ContinuousLinearMap.adjoint_inner_left S (b i) (c j)
114      rw [hSstar] at h1
115      exact h1.symm
116    have key : (fun i : w => F i j) = fun i : w => ‖⟪b i, S (c j)⟫_ℂ‖ ^ 2 := by
117      funext i
118      show ‖⟪c j, S (b i)⟫_ℂ‖ ^ 2 = _
119      rw [e1 i, ← inner_conj_symm (b i) (S (c j)), RCLike.norm_conj]
120    rw [key]
121    exact hasSum_norm_sq_inner_basis b (S (c j))
122  set G : w' → w → ℝ := fun j i => F i j with hGdef
123  have hjoint : Summable (Function.uncurry F) := by
124    rw [summable_prod_of_nonneg hFnonneg]
125    refine ⟨fun i => (hrow i).summable, ?_⟩
126    have heq : (fun i : w => ∑' j : w', F i j) = fun i : w => ‖S (b i)‖ ^ 2 :=
127      funext fun i => (hrow i).tsum_eq
128    show Summable fun i : w => ∑' j : w', F i j
129    rwa [heq]
130  have hswap := hjoint.tsum_comm' (fun i => (hrow i).summable) (fun j => (hcol j).summable)
131  have hLHS : ∑' j : w', ∑' i : w, F i j = ∑' j : w', ‖S (c j)‖ ^ 2 :=
132    tsum_congr fun j => (hcol j).tsum_eq
133  have hRHS : ∑' i : w, ∑' j : w', F i j = ∑' i : w, ‖S (b i)‖ ^ 2 :=
134    tsum_congr fun i => (hrow i).tsum_eq
135  have hEq : ∑' j : w', ‖S (c j)‖ ^ 2 = ∑' i : w, ‖S (b i)‖ ^ 2 := by
136    rw [← hLHS, ← hRHS]; exact hswap
137  have hGnonneg : 0 ≤ Function.uncurry G := fun _ => sq_nonneg _
138  have hjointG : Summable (Function.uncurry G) := by
139    have hcomp : Function.uncurry G = Function.uncurry F ∘ (Equiv.prodComm w' w) := by
140      funext p
141      simp [Function.uncurry, hGdef, Equiv.prodComm]
142    rw [hcomp]
143    exact (Equiv.prodComm w' w).summable_iff.mpr hjoint
144  have hcolSummable : Summable (fun j : w' => ‖S (c j)‖ ^ 2) := by
145    have hpair := (summable_prod_of_nonneg hGnonneg).mp hjointG
146    have h2 : Summable fun j : w' => ∑' i : w, G j i := by
147      show Summable fun j : w' => ∑' i : w, Function.uncurry G (j, i)
148      exact hpair.2
149    have heq2 : (fun j : w' => ∑' i : w, G j i) = fun j : w' => ‖S (c j)‖ ^ 2 :=
150      funext fun j => (hcol j).tsum_eq
151    rwa [heq2] at h2
152  rw [← hEq]
153  exact hcolSummable.hasSum
154 
155/-- **Trace class does not depend on the basis**: the diagonal of `|T|` is summable in every Hilbert
156basis. -/
157lemma summable_inner_abs_of_hilbertBasis {T : H →L[ℂ] H} (h : IsTraceClass T) {w : Set H}
158    (b : HilbertBasis w ℂ H) :
159    Summable (fun i => (⟪b i, CFC.abs T (b i)⟫_ℂ).re) := by
160  obtain ⟨w₀, b₀, hb₀⟩ := h
161  set A : H →L[ℂ] H := CFC.abs T with hAdef
162  have hAnonneg : 0 ≤ A := CFC.abs_nonneg T
163  have hAself : IsSelfAdjoint A := .of_nonneg hAnonneg
164  set S : H →L[ℂ] H := CFC.sqrt A with hSdef
165  have hSself : IsSelfAdjoint S := .of_nonneg (CFC.sqrt_nonneg A)
166  have hpt : ∀ {w' : Set H} (b' : HilbertBasis w' ℂ H) (i : w'),
167      (⟪b' i, A (b' i)⟫_ℂ).re = ‖S (b' i)‖ ^ 2 := by
168    intro w' b' i
169    have hSS : S * S = A := CFC.sqrt_mul_sqrt_self A hAnonneg
170    have : ⟪b' i, A (b' i)⟫_ℂ = ⟪S (b' i), S (b' i)⟫_ℂ := by
171      have hSstar : ContinuousLinearMap.adjoint S = S := (ContinuousLinearMap.star_eq_adjoint
172          S).symm.trans hSself
173      rw [← hSS]
174      show ⟪b' i, (S * S) (b' i)⟫_ℂ = _
175      rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_apply]
176      rw [← ContinuousLinearMap.adjoint_inner_left S (S (b' i)) (b' i), hSstar]
177    have hval : ⟪S (b' i), S (b' i)⟫_ℂ = ((‖S (b' i)‖ ^ 2 : ℝ) : ℂ) := by
178      rw [inner_self_eq_norm_sq_to_K]; norm_cast
179    rw [this, hval, Complex.ofReal_re]
180  have hb₀' : Summable (fun i : w₀ => ‖S (b₀ i)‖ ^ 2) := by
181    simpa [hpt b₀] using hb₀
182  have := hasSum_norm_sq_apply_of_selfAdjoint hSself b₀ b hb₀'
183  simpa [hpt b] using this.summable
184 
185/-- An operator is trace class iff the diagonal of `|T|` is summable in every Hilbert basis. -/
186lemma isTraceClass_iff {T : H →L[ℂ] H} :
187    IsTraceClass T ↔
188      ∀ (w : Set H) (b : HilbertBasis w ℂ H),
189        Summable (fun i => (⟪b i, CFC.abs T (b i)⟫_ℂ).re) := by
190  constructor
191  · intro h w b
192    exact summable_inner_abs_of_hilbertBasis h b
193  · intro h
194    obtain ⟨w, b, _⟩ := exists_hilbertBasis ℂ H
195    exact ⟨w, b, h w b⟩
196 
197/-- Every operator on a finite-dimensional Hilbert space is trace class. -/
198lemma isTraceClass_of_finiteDimensional [FiniteDimensional ℂ H] (T : H →L[ℂ] H) :
199    IsTraceClass T := by
200  obtain ⟨w, b, _⟩ := exists_hilbertBasis ℂ H
201  let : Finite w := b.orthonormal.linearIndependent.finite
202  let : Fintype w := Fintype.ofFinite w
203  refine ⟨w, b, ?_⟩
204  apply summable_of_hasFiniteSupport
205  exact Set.finite_univ.subset (by intro i hi; trivial)
206 
207omit [CompleteSpace H] in
208/-- The ordinary finite-dimensional trace is the diagonal sum in any Hilbert basis. -/
209lemma trace_eq_sum_inner_hilbertBasis_of_finiteDimensional
210    [FiniteDimensional ℂ H] (T : H →L[ℂ] H) {w : Set H} (b : HilbertBasis w ℂ H) :
211    LinearMap.trace ℂ H T.toLinearMap = ∑' i : w, ⟪b i, T (b i)⟫_ℂ := by
212  let : Finite w := b.orthonormal.linearIndependent.finite
213  let : Fintype w := Fintype.ofFinite w
214  rw [tsum_fintype]
215  simpa only [HilbertBasis.coe_toOrthonormalBasis, ContinuousLinearMap.coe_coe] using
216    LinearMap.trace_eq_sum_inner T.toLinearMap b.toOrthonormalBasis
217 
218/-- The trace norm `‖T‖₁ := ∑ᵢ ⟪eᵢ, |T| eᵢ⟫`, computed via a chosen witness Hilbert basis (any
219basis gives the same value, by `summable_inner_abs_of_hilbertBasis` — this definition just needs
220*a* witness to compute with). -/
221def traceNorm (T : H →L[ℂ] H) (h : IsTraceClass T) : ℝ :=
222  ∑' i : h.choose, (⟪h.choose_spec.choose i, CFC.abs T (h.choose_spec.choose i)⟫_ℂ).re
223 
224/-- The witness proof argument of `traceNorm` is immaterial.  This small lemma is useful when
225transporting a trace-class operator through a construction that produces a new proof of the same
226proposition. -/
227lemma traceNorm_congr {T : H →L[ℂ] H} {h₁ h₂ : IsTraceClass T} :
228    traceNorm T h₁ = traceNorm T h₂ := by
229  have hh : h₁ = h₂ := Subsingleton.elim _ _
230  rw [hh]
231 
232/-- **The trace** `Tr T = ∑ᵢ ⟪eᵢ, T eᵢ⟫` of a trace-class operator, in the basis witnessing that it
233is trace class. -/
234def trace (T : H →L[ℂ] H) (h : IsTraceClass T) : ℂ :=
235  ∑' i : h.choose, ⟪h.choose_spec.choose i, T (h.choose_spec.choose i)⟫_ℂ
236 
237/-- The trace does not depend on the proof that the operator is trace class. -/
238lemma trace_congr {T : H →L[ℂ] H} {h₁ h₂ : IsTraceClass T} :
239    trace T h₁ = trace T h₂ := by
240  have hh : h₁ = h₂ := Subsingleton.elim _ _
241  rw [hh]
242 
243/-- The trace norm is independent of the witness basis used in `IsTraceClass`.  This is the
244strong form of `summable_inner_abs_of_hilbertBasis`: the square-root/Parseval argument identifies
245the actual sums, not merely their convergence. -/
246lemma traceNorm_eq_of_hilbertBasis {T : H →L[ℂ] H} (h : IsTraceClass T) {w : Set H}
247    (b : HilbertBasis w ℂ H) :
248    traceNorm T h = ∑' i, (⟪b i, CFC.abs T (b i)⟫_ℂ).re := by
249  let w₀ : Set H := h.choose
250  let b₀ : HilbertBasis w₀ ℂ H := h.choose_spec.choose
251  have hb₀ : Summable (fun i : w₀ => (⟪b₀ i, CFC.abs T (b₀ i)⟫_ℂ).re) :=
252    h.choose_spec.choose_spec
253  set A : H →L[ℂ] H := CFC.abs T with hAdef
254  have hAnonneg : 0 ≤ A := CFC.abs_nonneg T
255  have hAself : IsSelfAdjoint A := .of_nonneg hAnonneg
256  set S : H →L[ℂ] H := CFC.sqrt A with hSdef
257  have hSself : IsSelfAdjoint S := .of_nonneg (CFC.sqrt_nonneg A)
258  have hpt : ∀ {w' : Set H} (b' : HilbertBasis w' ℂ H) (i : w'),
259      (⟪b' i, A (b' i)⟫_ℂ).re = ‖S (b' i)‖ ^ 2 := by
260    intro w' b' i
261    have hSS : S * S = A := CFC.sqrt_mul_sqrt_self A hAnonneg
262    have hinner : ⟪b' i, A (b' i)⟫_ℂ = ⟪S (b' i), S (b' i)⟫_ℂ := by
263      have hSstar : ContinuousLinearMap.adjoint S = S :=
264        (ContinuousLinearMap.star_eq_adjoint S).symm.trans hSself
265      rw [← hSS]
266      show ⟪b' i, (S * S) (b' i)⟫_ℂ = _
267      rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_apply]
268      rw [← ContinuousLinearMap.adjoint_inner_left S (S (b' i)) (b' i), hSstar]
269    rw [hinner, inner_self_eq_norm_sq_to_K]
270    norm_cast
271  have hb₀' : Summable (fun i : w₀ => ‖S (b₀ i)‖ ^ 2) := by
272    apply hb₀.congr
273    intro i
274    rw [hAdef, hpt]
275  have hnorm := hasSum_norm_sq_apply_of_selfAdjoint hSself b₀ b hb₀'
276  calc
277    traceNorm T h = ∑' i : w₀, (⟪b₀ i, A (b₀ i)⟫_ℂ).re := by
278      rfl
279    _ = ∑' i : w₀, ‖S (b₀ i)‖ ^ 2 := by
280      apply tsum_congr
281      intro i
282      exact hpt b₀ i
283    _ = ∑' i : w, ‖S (b i)‖ ^ 2 := hnorm.tsum_eq.symm
284    _ = ∑' i : w, (⟪b i, A (b i)⟫_ℂ).re := by
285      apply tsum_congr
286      intro i
287      exact (hpt b i).symm
288    _ = ∑' i, (⟪b i, CFC.abs T (b i)⟫_ℂ).re := by
289      rfl
290 
291omit [CompleteSpace H] in
292lemma real_inner_nonneg_of_nonneg {T : H →L[ℂ] H} (hT : 0 ≤ T) (x : H) :
293    0 ≤ (⟪x, T x⟫_ℂ).re := by
294  have hpos : T.IsPositive := T.nonneg_iff_isPositive.mp hT
295  have hx := (ContinuousLinearMap.isPositive_iff_complex T).mp hpos x
296  have heq : (⟪T x, x⟫_ℂ).re = (⟪x, T x⟫_ℂ).re := by
297    rw [← inner_conj_symm (T x) x]
298    exact Complex.conj_re _
299  rw [← heq]
300  exact hx.2
301 
302/-- The trace norm is nonnegative.  This is exposed separately from its basis-independence result
303so norm estimates can use it without unpacking the chosen Hilbert-basis witness. -/
304lemma traceNorm_nonneg (T : H →L[ℂ] H) (h : IsTraceClass T) : 0 ≤ traceNorm T h := by
305  unfold traceNorm
306  exact tsum_nonneg fun i => real_inner_nonneg_of_nonneg (CFC.abs_nonneg T)
307    (h.choose_spec.choose i)
308 
309lemma real_inner_mono_of_le {P Q : H →L[ℂ] H} (hPQ : P ≤ Q) (x : H) :
310    (⟪x, P x⟫_ℂ).re ≤ (⟪x, Q x⟫_ℂ).re := by
311  have hdiff : 0 ≤ Q - P := sub_nonneg.mpr hPQ
312  have hpos : (Q - P).IsPositive := (Q - P).nonneg_iff_isPositive.mp hdiff
313  have hx := (ContinuousLinearMap.isPositive_iff_complex (Q - P)).mp hpos x
314  have heq : (⟪(Q - P) x, x⟫_ℂ).re = (⟪x, (Q - P) x⟫_ℂ).re := by
315    rw [← inner_conj_symm ((Q - P) x) x]
316    exact Complex.conj_re _
317  have hx' : 0 ≤ (⟪x, (Q - P) x⟫_ℂ).re := by
318    rw [← heq]
319    exact hx.2
320  simpa [ContinuousLinearMap.sub_apply, inner_sub_right, map_sub] using hx'
321 
322lemma isTraceClass_posPart_of_isSelfAdjoint {T : H →L[ℂ] H} (hT : IsSelfAdjoint T)
323    (h : IsTraceClass T) : IsTraceClass T⁺ := by
324  obtain ⟨w, b, hb⟩ := h
325  refine ⟨w, b, ?_⟩
326  rw [CFC.abs_of_nonneg T⁺ (CFC.posPart_nonneg T)]
327  apply Summable.of_nonneg_of_le
328  · intro i
329    exact real_inner_nonneg_of_nonneg (CFC.posPart_nonneg T) (b i)
330  · intro i
331    have habs : T⁺ + T⁻ = CFC.abs T := CFC.posPart_add_negPart T hT
332    have hle : T⁺ ≤ CFC.abs T := by
333      rw [← habs]
334      exact le_add_of_nonneg_right (CFC.negPart_nonneg T)
335    exact real_inner_mono_of_le hle (b i)
336  · exact hb
337 
338lemma isTraceClass_negPart_of_isSelfAdjoint {T : H →L[ℂ] H} (hT : IsSelfAdjoint T)
339    (h : IsTraceClass T) : IsTraceClass T⁻ := by
340  obtain ⟨w, b, hb⟩ := h
341  refine ⟨w, b, ?_⟩
342  rw [CFC.abs_of_nonneg T⁻ (CFC.negPart_nonneg T)]
343  apply Summable.of_nonneg_of_le
344  · intro i
345    exact real_inner_nonneg_of_nonneg (CFC.negPart_nonneg T) (b i)
346  · intro i
347    have habs : T⁺ + T⁻ = CFC.abs T := CFC.posPart_add_negPart T hT
348    have hle : T⁻ ≤ CFC.abs T := by
349      rw [← habs]
350      exact le_add_of_nonneg_left (CFC.posPart_nonneg T)
351    exact real_inner_mono_of_le hle (b i)
352  · exact hb
353 
354lemma summable_inner_of_nonneg {T : H →L[ℂ] H} (hT : 0 ≤ T) (h : IsTraceClass T)
355    {w : Set H} (b : HilbertBasis w ℂ H) :
356    Summable (fun i => ⟪b i, T (b i)⟫_ℂ) := by
357  have hr : Summable (fun i : w => (⟪b i, CFC.abs T (b i)⟫_ℂ).re) :=
358    summable_inner_abs_of_hilbertBasis h b
359  have habs : CFC.abs T = T := CFC.abs_of_nonneg T hT
360  have heq (i : w) : ⟪b i, T (b i)⟫_ℂ =
361      ((⟪b i, CFC.abs T (b i)⟫_ℂ).re : ℂ) := by
362    rw [habs]
363    have hpos : T.IsPositive := T.nonneg_iff_isPositive.mp hT
364    have hx := (ContinuousLinearMap.isPositive_iff_complex T).mp hpos (b i)
365    have hA : ⟪T (b i), b i⟫_ℂ = ((⟪T (b i), b i⟫_ℂ).re : ℂ) := hx.1.symm
366    have hre : (⟪T (b i), b i⟫_ℂ).re = (⟪b i, T (b i)⟫_ℂ).re := by
367      rw [← inner_conj_symm (T (b i)) (b i)]
368      exact Complex.conj_re _
369    have hinner : ⟪b i, T (b i)⟫_ℂ = ((⟪T (b i), b i⟫_ℂ).re : ℂ) := by
370      calc
371        ⟪b i, T (b i)⟫_ℂ = (starRingEnd ℂ) ⟪T (b i), b i⟫_ℂ :=
372          (inner_conj_symm (b i) (T (b i))).symm
373        _ = (starRingEnd ℂ) ((⟪T (b i), b i⟫_ℂ).re : ℂ) :=
374          congrArg (starRingEnd ℂ) hA
375        _ = ((⟪T (b i), b i⟫_ℂ).re : ℂ) := by simp
376    exact hinner.trans (congrArg (fun r : ℝ => (r : ℂ)) hre)
377  have hs : Summable (fun i : w => ((⟪b i, CFC.abs T (b i)⟫_ℂ).re : ℂ)) :=
378    Complex.summable_ofReal.mpr hr
379  exact hs.congr (fun i => (heq i).symm)
380 
381/-!
382Basis-independent trace for positive trace-class operators.
383 
384For a positive operator the absolute value is the operator itself.  Taking its continuous-
385functional-calculus square root turns every diagonal coefficient into a squared norm, so the
386Parseval double-sum theorem already proved above gives the same sum in every Hilbert basis.  This
387is the positive case needed by density operators and does not use polar decomposition.
388-/
389lemma trace_eq_of_hilbertBasis_of_nonneg {T : H →L[ℂ] H} (hT : 0 ≤ T)
390    (h : IsTraceClass T) {w : Set H} (b : HilbertBasis w ℂ H) :
391    trace T h = ∑' i, ⟪b i, T (b i)⟫_ℂ := by
392  let S : H →L[ℂ] H := CFC.sqrt T
393  have hSself : IsSelfAdjoint S := .of_nonneg (CFC.sqrt_nonneg T)
394  have hSS : S * S = T := CFC.sqrt_mul_sqrt_self T hT
395  have hdiag : ∀ {w' : Set H} (b' : HilbertBasis w' ℂ H) (i : w'),
396      ⟪b' i, T (b' i)⟫_ℂ = ((‖S (b' i)‖ ^ 2 : ℝ) : ℂ) := by
397    intro w' b' i
398    have hSstar : ContinuousLinearMap.adjoint S = S :=
399      (ContinuousLinearMap.star_eq_adjoint S).symm.trans hSself
400    have hinner : ⟪b' i, T (b' i)⟫_ℂ = ⟪S (b' i), S (b' i)⟫_ℂ := by
401      rw [← hSS]
402      show ⟪b' i, (S * S) (b' i)⟫_ℂ = _
403      rw [ContinuousLinearMap.mul_def, ContinuousLinearMap.comp_apply]
404      rw [← ContinuousLinearMap.adjoint_inner_left S (S (b' i)) (b' i), hSstar]
405    rw [hinner, inner_self_eq_norm_sq_to_K]
406    norm_cast
407  let w₀ : Set H := h.choose
408  let b₀ : HilbertBasis w₀ ℂ H := h.choose_spec.choose
409  have hWdiag : Summable (fun i : w₀ => ‖S (b₀ i)‖ ^ 2) := by
410    have hbase : Summable (fun i : w₀ =>
411        (⟪b₀ i, CFC.abs T (b₀ i)⟫_ℂ).re) := h.choose_spec.choose_spec
412    have habs : CFC.abs T = T := CFC.abs_of_nonneg T hT
413    apply hbase.congr
414    intro i
415    rw [habs, hdiag b₀ i]
416    rfl
417  have hnorm := hasSum_norm_sq_apply_of_selfAdjoint hSself b₀ b hWdiag
418  calc
419    trace T h = ∑' i : w₀, ⟪b₀ i, T (b₀ i)⟫_ℂ := by
420      rfl
421    _ = ∑' i : w₀, ((‖S (b₀ i)‖ ^ 2 : ℝ) : ℂ) := by
422      apply tsum_congr
423      intro i
424      exact hdiag b₀ i
425    _ = ((∑' i : w₀, ‖S (b₀ i)‖ ^ 2 : ℝ) : ℂ) :=
426      (Complex.ofReal_tsum (fun i : w₀ => ‖S (b₀ i)‖ ^ 2)).symm
427    _ = ((∑' i : w, ‖S (b i)‖ ^ 2 : ℝ) : ℂ) := by
428      rw [hnorm.tsum_eq]
429    _ = ∑' i : w, ⟪b i, T (b i)⟫_ℂ := by
430      rw [Complex.ofReal_tsum]
431      apply tsum_congr
432      intro i
433      exact (hdiag b i).symm
434 
435/-- Basis-independent trace for self-adjoint trace-class operators.  The proof reduces to the
436positive theorem through the continuous-functional-calculus decomposition `T = T⁺ - T⁻`; no
437polar decomposition is needed for this self-adjoint case. -/
438lemma trace_eq_of_hilbertBasis_of_isSelfAdjoint {T : H →L[ℂ] H} (hT : IsSelfAdjoint T)
439    (h : IsTraceClass T) {w : Set H} (b : HilbertBasis w ℂ H) :
440    trace T h = ∑' i, ⟪b i, T (b i)⟫_ℂ := by
441  let P : H →L[ℂ] H := T⁺
442  let N : H →L[ℂ] H := T⁻
443  have hP : IsTraceClass P := isTraceClass_posPart_of_isSelfAdjoint hT h
444  have hN : IsTraceClass N := isTraceClass_negPart_of_isSelfAdjoint hT h
445  have hPnonneg : 0 ≤ P := CFC.posPart_nonneg T
446  have hNnonneg : 0 ≤ N := CFC.negPart_nonneg T
447  have hdecomp : P - N = T := CFC.posPart_sub_negPart T hT
448  have hPsum : Summable (fun i : w => ⟪b i, P (b i)⟫_ℂ) :=
449    summable_inner_of_nonneg hPnonneg hP b
450  have hNsum : Summable (fun i : w => ⟪b i, N (b i)⟫_ℂ) :=
451    summable_inner_of_nonneg hNnonneg hN b
452  let w₀ : Set H := h.choose
453  let b₀ : HilbertBasis w₀ ℂ H := h.choose_spec.choose
454  have hPsum₀ : Summable (fun i : w₀ => ⟪b₀ i, P (b₀ i)⟫_ℂ) :=
455    summable_inner_of_nonneg hPnonneg hP b₀
456  have hNsum₀ : Summable (fun i : w₀ => ⟪b₀ i, N (b₀ i)⟫_ℂ) :=
457    summable_inner_of_nonneg hNnonneg hN b₀
458  have htrace_sub : trace T h = trace P hP - trace N hN := by
459    calc
460      trace T h = ∑' i : w₀, ⟪b₀ i, T (b₀ i)⟫_ℂ := by rfl
461      _ = ∑' i : w₀, (⟪b₀ i, P (b₀ i)⟫_ℂ - ⟪b₀ i, N (b₀ i)⟫_ℂ) := by
462        apply tsum_congr
463        intro i
464        rw [← hdecomp]
465        simp [ContinuousLinearMap.sub_apply, inner_sub_right]
466      _ = (∑' i : w₀, ⟪b₀ i, P (b₀ i)⟫_ℂ) -
467          (∑' i : w₀, ⟪b₀ i, N (b₀ i)⟫_ℂ) := hPsum₀.tsum_sub hNsum₀
468      _ = trace P hP - trace N hN := by
469        rw [trace_eq_of_hilbertBasis_of_nonneg hPnonneg hP b₀,
470          trace_eq_of_hilbertBasis_of_nonneg hNnonneg hN b₀]
471  calc
472    trace T h = trace P hP - trace N hN := htrace_sub
473    _ = (∑' i : w, ⟪b i, P (b i)⟫_ℂ) -
474        (∑' i : w, ⟪b i, N (b i)⟫_ℂ) := by
475      rw [trace_eq_of_hilbertBasis_of_nonneg hPnonneg hP b,
476        trace_eq_of_hilbertBasis_of_nonneg hNnonneg hN b]
477    _ = ∑' i : w, (⟪b i, P (b i)⟫_ℂ - ⟪b i, N (b i)⟫_ℂ) :=
478      (hPsum.tsum_sub hNsum).symm
479    _ = ∑' i : w, ⟪b i, T (b i)⟫_ℂ := by
480      apply tsum_congr
481      intro i
482      rw [← hdecomp]
483      simp [ContinuousLinearMap.sub_apply, inner_sub_right]
484 
485 
486/-- In finite dimension the analytic trace agrees with the ordinary linear-algebra trace. -/
487lemma trace_eq_linearMap_trace_of_finiteDimensional [FiniteDimensional ℂ H]
488    (T : H →L[ℂ] H) (h : IsTraceClass T) :
489    trace T h = LinearMap.trace ℂ H T.toLinearMap := by
490  exact (trace_eq_sum_inner_hilbertBasis_of_finiteDimensional T h.choose_spec.choose).symm
491 
492end
493end Cloning.InfiniteTraceClass