Imports
/- Copyright (c) 2025 Alex Meiburg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Meiburg -/ module public import Physlib.StatisticalMechanics.MicroCanonicalEnsemble.Basic public import QuantumInfo.ForMathlib.ComplexLaplaceTransform

The theormodynamical quantities of a microcanonical ensemble

@[expose] public section

The partition function corresponding to a given MicroHamiltonian. This is a function taking a thermodynamic β, not a temperature. It also depends on the data D defining the system extrinsincs.

    Ideally this would be an NNReal, but ∫ (NNReal) doesn't work right now, so it would just be a separate proof anyway

def partitionZ (β : ℝ) : ℝ := ∫ (config : H.dim d → ℝ), let E := H.H config if h : E = ⊤ then 0 else Real.exp (-β * (E.untop h))

The complexified partition function, viewed as a Laplace transform.

def PartitionZComplex (z : ℂ) : ℂ := ComplexLaplaceTransform (fun config : H.dim d → ℝ => H.H config) z

The complex convergence domain of the partition-function Laplace transform.

def ZComplexConvergenceDomain : Set ℂ := ComplexLaplaceConvergenceDomain (fun config : H.dim d → ℝ => H.H config)
D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volume⊢ (∫ (config : H.dim d → ℝ), have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = (∫ (x : H.dim d → ℝ), ComplexLaplaceIntegrand (fun config => H.H config) (↑β) x).re calc (∫ (config : H.dim d → ℝ), have E := H.H config if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = ∫ x, RCLike.re (ComplexLaplaceIntegrand (fun config : H.dim d → ℝ => H.H config) (β : ℂ) x) := D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volume⊢ (∫ (config : H.dim d → ℝ), have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = ∫ (x : H.dim d → ℝ), RCLike.re (ComplexLaplaceIntegrand (fun config => H.H config) (↑β) x) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volume⊢ (fun a => have E := H.H a; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) =ᵐ[MeasureTheory.volume] fun a => RCLike.re (ComplexLaplaceIntegrand (fun config => H.H config) (↑β) a) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝ⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (ComplexLaplaceIntegrand (fun config => H.H config) (↑β) config) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝ⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (if h : (fun config => H.H config) config = ⊤ then 0 else Complex.exp (-↑β * ↑(((fun config => H.H config) config).untop h))) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝh:H.H config = ⊤⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (if h : (fun config => H.H config) config = ⊤ then 0 else Complex.exp (-↑β * ↑(((fun config => H.H config) config).untop h)))D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝh:¬H.H config = ⊤⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (if h : (fun config => H.H config) config = ⊤ then 0 else Complex.exp (-↑β * ↑(((fun config => H.H config) config).untop h))) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝh:H.H config = ⊤⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (if h : (fun config => H.H config) config = ⊤ then 0 else Complex.exp (-↑β * ↑(((fun config => H.H config) config).untop h))) All goals completed! 🐙 D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝh:¬H.H config = ⊤⊢ (have E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * E.untop h)) = RCLike.re (if h : (fun config => H.H config) config = ⊤ then 0 else Complex.exp (-↑β * ↑(((fun config => H.H config) config).untop h))) D:TypeH:MicroHamiltonian Dd:Dβ:ℝhβ:↑β ∈ H.ZComplexConvergenceDomain dhInt:MeasureTheory.Integrable (ComplexLaplaceIntegrand (fun config => H.H config) ↑β) MeasureTheory.volumeconfig:H.dim d → ℝh:¬H.H config = ⊤⊢ Real.exp (-β * (H.H config).untop ⋯) = RCLike.re (Complex.exp (-↑β * ↑((H.H config).untop ⋯))) All goals completed! 🐙 _ = RCLike.re (∫ x, ComplexLaplaceIntegrand (fun config : H.dim d → ℝ => H.H config) (β : ℂ) x) := integral_re hInt

The partition function as a function of temperature T instead of β.

def partitionZT (T : ℝ) : ℝ := partitionZ H d (1/T)

The Internal Energy, U or E, defined as -∂(ln Z)/∂β. Parameterized here with β.

def internalU (β : ℝ) : ℝ := -deriv (fun β' ↦ (partitionZ H d β').log) β

The Helmholtz Free Energy, -T * ln Z. Also denoted F. Parameterized here with temperature T, not β.

def helmholtzA (T : ℝ) : ℝ := -T * (partitionZT H d T).log

The entropy, defined as the -∂A/∂T. Function of T.

def entropyS (T : ℝ) : ℝ := -deriv (helmholtzA H d) T

The entropy, defined as ln Z + β*U. Function of β.

def entropySβ (β : ℝ) : ℝ := (partitionZ H d β).log + β * internalU H d β

To be able to compute or define anything from a Hamiltonian, we need its partition function to be a computable integral. A Hamiltonian is ZIntegrable at β if PartitionZ is Lesbegue integrable and nonzero.

def ZIntegrable (β : ℝ) : Prop := MeasureTheory.Integrable (fun (config : H.dim d → ℝ) ↦ let E := H.H config; if h : E = ⊤ then 0 else Real.exp (-β * (E.untop h))) ∧ (H.partitionZ d β ≠ 0)

This Prop defines the most common case of ZIntegrable, that it is integrable at all finite temperatures (aka all positive β).

def PositiveβIntegrable : Prop := ∀ β > 0, H.ZIntegrable d β

The two definitions of entropy, in terms of T or β = 1 / T, are equivalent.

D:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ (fun β => Real.log (H.partitionZ d β)) (1 / T) All goals completed! 🐙 D:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ (fun T => T⁻¹) T All goals completed! 🐙 D:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ Neg.neg T All goals completed! 🐙 D:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ (fun T => Real.log (H.partitionZT d T)) T simp_rw D:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ (fun T => Real.log (H.partitionZT d T)) TD:TypeH:MicroHamiltonian Dd:DT:ℝhT:T ≠ 0hZne:H.partitionZ d (1 / T) ≠ 0hZint:↑(1 / T) ∈ interior (H.ZComplexConvergenceDomain d)hZdiff:DifferentiableAt ℝ (H.partitionZ d) (1 / T)⊢ DifferentiableAt ℝ (fun T => Real.log (H.partitionZ d (1 / T))) T] All goals completed! 🐙
--! Specializing to a system of particles in space namespace NVEHamiltonian

Pressure, as a function of T. Defined as the conjugate variable to volume.

def pressure (T : ℝ) : ℝ := let (n, V) := d; - deriv (fun V' ↦ helmholtzA H (n, V') T) V