Imports
/- Copyright (c) 2026 Axiomatic-AI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Matteo Cipollina, Krystian Nowakowski -/ module public import Physlib.QuantumMechanics.Operators.StateObservables.ExpectedValue public import Physlib.QuantumMechanics.Operators.StateObservables.IsEigenvector public import Mathlib.Analysis.SpecialFunctions.Sqrt

Variance and standard deviation

The variance of a partial linear map T in a state ψ is ‖Tψ - ⟨T⟩_ψ ψ‖ ^ 2. It only requires ψ ∈ T.domain.

When T is symmetric, ‖ψ‖ = 1, and Tψ ∈ T.domain, it also equals ⟨T^2⟩_ψ - ⟨T⟩_ψ ^ 2.

Main definitions

    LinearPMap.variance and LinearPMap.standardDeviation.

Main statements

    LinearPMap.variance_eq_norm_sq_sub_expectedValue_sq: for a unit vector and symmetric T, the variance is ‖Tψ‖ ^ 2 - ⟨T⟩_ψ ^ 2.

    LinearPMap.variance_eq_re_inner_sub_expectedValue_sq: the second-order formula when Tψ ∈ T.domain.

    LinearPMap.variance_eq_zero_iff_isEigenvector and LinearPMap.standardDeviation_eq_zero_iff_isEigenvector: for a unit vector, zero variance or standard deviation is equivalent to the eigenvector condition.

References

    [B. C. Hall, Quantum Theory for Mathematicians, Chapter 12][hall2013quantum].

@[expose] public section

Variance ‖Tψ - ⟨T⟩_ψ ψ‖ ^ 2; only ψ ∈ T.domain is required.

def variance (T : H →ₗ.[ℂ] H) (ψ : T.domain) : ℝ := ‖centered T ψ‖ ^ 2

The variance is the squared norm of the centered vector.

lemma variance_eq_centered_norm_sq (T : H →ₗ.[ℂ] H) (ψ : T.domain) : variance T ψ = ‖centered T ψ‖ ^ 2 := rfl

variance with centered unfolded to Tψ - ⟨T⟩_ψ • ψ.

lemma variance_eq_norm_sub_sq (T : H →ₗ.[ℂ] H) (ψ : T.domain) : variance T ψ = ‖T ψ - (expectedValue T ψ : ℂ) • (ψ : H)‖ ^ 2 := rfl

For symmetric T and ‖ψ‖ = 1, variance equals ‖Tψ‖ ^ 2 - ⟨T⟩_ψ ^ 2.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] HhT:T.IsSymmetricψ:↥T.domainhψ_norm:‖↑ψ‖ = 1μ:ℝ := T.expectedValue ψa:H := ↑T ψhμ_right:⟪↑ψ, a⟫_ℂ = ↑μhμ_left:⟪a, ↑ψ⟫_ℂ = ↑μh_re_inner_centered:(⟪a, ↑μ • ↑ψ⟫_ℂ).re = μ ^ 2h_norm_centered_smul:‖↑μ • ↑ψ‖ ^ 2 = μ ^ 2h_norm_sub_sq:‖a - ↑μ • ↑ψ‖ ^ 2 = ‖a‖ ^ 2 - 2 * (⟪a, ↑μ • ↑ψ⟫_ℂ).re + ‖↑μ • ↑ψ‖ ^ 2⊢ ‖a‖ ^ 2 - 2 * μ ^ 2 + μ ^ 2 = ‖↑T ψ‖ ^ 2 - T.expectedValue ψ ^ 2 All goals completed! 🐙

Variance is nonnegative.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ 0 ≤ ‖T.centered ψ‖ ^ 2 All goals completed! 🐙

Zero variance is the same as a zero centered vector.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ ‖T.centered ψ‖ ^ 2 = 0 ↔ T.centered ψ = 0 All goals completed! 🐙

Zero variance is the same as Tψ = ⟨T⟩_ψ ψ.

All goals completed! 🐙

For ‖ψ‖ = 1, zero variance iff ψ is an eigenvector with eigenvalue ⟨T⟩_ψ.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_centered:↑T ψ = ↑(T.expectedValue ψ) • ↑ψh_zero:↑ψ = 0h_zero':↑ψ = 0h_norm_zero:‖↑ψ‖ = 0⊢ False H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_centered:↑T ψ = ↑(T.expectedValue ψ) • ↑ψh_zero:↑ψ = 0h_zero':↑ψ = 0h_norm_zero:‖↑ψ‖ = 0this:0 = 1⊢ False All goals completed! 🐙 H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1⊢ T.IsEigenvector ψ ↑(T.expectedValue ψ) → ↑T ψ = ↑(T.expectedValue ψ) • ↑ψ H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_eigen:T.IsEigenvector ψ ↑(T.expectedValue ψ)⊢ ↑T ψ = ↑(T.expectedValue ψ) • ↑ψ All goals completed! 🐙

Standard deviation √(variance) for ψ ∈ T.domain.

def standardDeviation (T : H →ₗ.[ℂ] H) (ψ : T.domain) : ℝ := Real.sqrt (variance T ψ)

The standard deviation, unfolded to the square root of the variance.

lemma standardDeviation_eq_sqrt_variance (T : H →ₗ.[ℂ] H) (ψ : T.domain) : standardDeviation T ψ = Real.sqrt (variance T ψ) := rfl

Standard deviation is nonnegative.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ 0 ≤ √(T.variance ψ) All goals completed! 🐙
H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ 0 ≤ T.variance ψ All goals completed! 🐙

Zero standard deviation is the same as a zero centered vector.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ T.variance ψ = 0 ↔ T.centered ψ = 0H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ 0 ≤ T.variance ψ H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ T.variance ψ = 0 ↔ T.centered ψ = 0 All goals completed! 🐙 H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domain⊢ 0 ≤ T.variance ψ All goals completed! 🐙

Zero standard deviation is the same as Tψ = ⟨T⟩_ψ ψ.

All goals completed! 🐙

For ‖ψ‖ = 1, zero standard deviation iff the eigenvector condition holds.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_centered:↑T ψ = ↑(T.expectedValue ψ) • ↑ψh_zero:↑ψ = 0h_zero':↑ψ = 0h_norm_zero:‖↑ψ‖ = 0⊢ False H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_centered:↑T ψ = ↑(T.expectedValue ψ) • ↑ψh_zero:↑ψ = 0h_zero':↑ψ = 0h_norm_zero:‖↑ψ‖ = 0this:0 = 1⊢ False All goals completed! 🐙 H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1⊢ T.IsEigenvector ψ ↑(T.expectedValue ψ) → ↑T ψ = ↑(T.expectedValue ψ) • ↑ψ H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] Hψ:↥T.domainhψ_norm:‖↑ψ‖ = 1h_eigen:T.IsEigenvector ψ ↑(T.expectedValue ψ)⊢ ↑T ψ = ↑(T.expectedValue ψ) • ↑ψ All goals completed! 🐙
include hT

For symmetric T, re ⟪ψ, T(Tψ)⟫ is ‖Tψ‖ ^ 2.

H:Type u_1inst✝¹:NormedAddCommGroup Hinst✝:InnerProductSpace ℂ HT:H →ₗ.[ℂ] HhT:T.IsSymmetricψ:↥T.domainhTψ:↑T ψ ∈ T.domain⊢ (↑‖↑T ψ‖).re * (↑‖↑T ψ‖).re - (↑‖↑T ψ‖).im * (↑‖↑T ψ‖).im = ‖↑T ψ‖ * ‖↑T ψ‖ All goals completed! 🐙
include hψ_norm

When Tψ ∈ T.domain, variance equals ⟨T^2⟩_ψ - ⟨T⟩_ψ ^ 2.

All goals completed! 🐙