Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Definitions for Renyi Entropy and Free Energy

Definition
QAlgorithms_Papers_Independent_Advance50_P26

by Gohan · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

prove2quantum

The objects the formalized statements of Renyi Entropy and Free Energy (arXiv:1102.2098) are stated in. Each was checked against the paper by a blind read-back and a moderator.

  • classicalRenyiNats: PDF p.1, (1): real-order classical Renyi entropy in natural units. The q = 1 branch is the source's Shannon extension. Only q > 0 is interpreted.
  • referenceEnergies: PDF p.2: the energies constructed from a strictly positive law at temperature T0. They are not a separately supplied spectrum: E_i = -T0 log p_i.
  • classicalPartition: PDF p.2: the classical partition function at temperature T, in units k = 1.
  • classicalFreeEnergy: PDF p.2: classical Helmholtz free energy F_E(T) = -T log Z_E(T), with k = 1.
  • thermalPartition: PDF p.3, (4): Z_H(k,T) = Tr exp(-H/(kT)). Correct the printed E in (4) to H, as required by (3) and the final calculation of (9). For Hermitian H and positive k,T this trace is real and strictly positive.
  • thermalGibbs: PDF p.3, (3): the actual normalized Gibbs matrix at temperature T. The accepted exponential-normalization definition is used with exponent -H/(kT). For nonempty finite Hermitian H and k,T > 0 this is positive definite with trace one; these properties follow from the construction and are not assumed identities.
  • thermalFreeEnergy: PDF p.3, (5): Helmholtz free energy of the fixed Hamiltonian H and fixed k.
  • renyiEntropyWithBoltzmann: PDF p.3, (6)-(7): natural-log spectral Renyi entropy with Boltzmann constant k. For q = 1 use -k Tr(rho log rho), spectrally evaluated with 0 log 0 = 0. For q > 0 and a density matrix the trace power is positive; taking the real part therefore represents the real trace and does not discard an imaginary contribution.
  • qDerivative: PDF p.4: D_a f(x) = (f(ax) - f(x))/(ax - x). The application in (11) uses a = q inverse and x = T > 0, with q > 0 and q != 1.
Definition code
import Mathlib
import Definitions.Def_QAlgorithms_Defs_SDP
import Definitions.Def_QAlgorithms_Defs_ZeroSumGeometry
import Definitions.Def_QAlgorithms_Papers_Independent_Support50_P15
import Definitions.Def_QAlgorithms_Papers_Independent_Dependency50_P35

/-!
Statements from John C. Baez, *Renyi Entropy and Free Energy*, arXiv:1102.2098v4.
Only finite systems and finite positive entropy orders are used in the target statements.
The operational maximum-work claim is deferred: the source does not specify a process model.

Source corrections on PDF p.3: use H in the partition function (4), restore k in the
intermediate exponential, and restore logarithms of partition functions in the following
line. Equations (3), (5), (6), and the final calculation yielding (9) determine these corrections.
They do not change the final displayed result (9). Independent moderation is pending.
-/

noncomputable section

open Filter
open scoped BigOperators Topology Matrix.Norms.L2Operator

namespace QAlgorithms.Papers.Independent.Advance50.P26

-- Reuse pinned accepted declarations, as required by the repair instruction.
-- The Shannon interface uses Fin d; finite reindexing below preserves arbitrary alphabets.
open QAlgorithms.Papers.Independent.Support50.P15 (shannonEntropyNats)
open QAlgorithms.ZeroSum (classicalGibbs)
open QAlgorithms.Papers.Independent.Dependency50.P35 (spectralPower)

/-- PDF p.1, (1): real-order classical Renyi entropy in natural units.
The q = 1 branch is the source's Shannon extension. Only q > 0 is interpreted. -/
def classicalRenyiNats {I : Type*} [Fintype I] (p : I → ℝ) (q : ℝ) : ℝ :=
  if q = 1 then shannonEntropyNats (fun i => p ((Fintype.equivFin I).symm i))
  else Real.log (∑ i, (p i) ^ q) / (1 - q)

/-- PDF p.2: the energies constructed from a strictly positive law at temperature T0.
They are not a separately supplied spectrum: E_i = -T0 log p_i. -/
def referenceEnergies {I : Type*} (p : I → ℝ) (T0 : ℝ) : I → ℝ :=
  fun i => -T0 * Real.log (p i)

/-- PDF p.2: the classical partition function at temperature T, in units k = 1. -/
def classicalPartition {I : Type*} [Fintype I] (E : I → ℝ) (T : ℝ) : ℝ :=
  ∑ i, Real.exp (-E i / T)

/-- PDF p.2: classical Helmholtz free energy F_E(T) = -T log Z_E(T), with k = 1. -/
def classicalFreeEnergy {I : Type*} [Fintype I] (E : I → ℝ) (T : ℝ) : ℝ :=
  -T * Real.log (classicalPartition E T)

/-- PDF p.3, (4): Z_H(k,T) = Tr exp(-H/(kT)).
Correct the printed E in (4) to H, as required by (3) and the final calculation of (9).
For Hermitian H and positive k,T this trace is real and strictly positive. -/
def thermalPartition {I : Type*} [Fintype I] [DecidableEq I]
    (H : Matrix I I ℂ) (k T : ℝ) : ℝ :=
  (NormedSpace.exp ((-(k * T)⁻¹) • H)).trace.re

/-- PDF p.3, (3): the actual normalized Gibbs matrix at temperature T.
The accepted exponential-normalization definition is used with exponent -H/(kT).
For nonempty finite Hermitian H and k,T > 0 this is positive definite with trace one;
these properties follow from the construction and are not assumed identities. -/
def thermalGibbs {I : Type*} [Fintype I] [DecidableEq I]
    (H : Matrix I I ℂ) (k T : ℝ) : Matrix I I ℂ :=
  QAlgorithms.gibbsState ((-(k * T)⁻¹) • H)

/-- PDF p.3, (5): Helmholtz free energy of the fixed Hamiltonian H and fixed k. -/
def thermalFreeEnergy {I : Type*} [Fintype I] [DecidableEq I]
    (H : Matrix I I ℂ) (k T : ℝ) : ℝ :=
  -k * T * Real.log (thermalPartition H k T)

/-- PDF p.3, (6)-(7): natural-log spectral Renyi entropy with Boltzmann constant k.
For q = 1 use -k Tr(rho log rho), spectrally evaluated with 0 log 0 = 0.
For q > 0 and a density matrix the trace power is positive; taking the real part
therefore represents the real trace and does not discard an imaginary contribution. -/
def renyiEntropyWithBoltzmann {I : Type} [Fintype I] [DecidableEq I]
    (rho : Matrix I I ℂ) (k q : ℝ) : ℝ :=
  if q = 1 then -k * (cfc (fun x : ℝ => x * Real.log x) rho).trace.re
  else k * Real.log (spectralPower rho q).trace.re / (1 - q)

/-- PDF p.4: D_a f(x) = (f(ax) - f(x))/(ax - x).
The application in (11) uses a = q inverse and x = T > 0, with q > 0 and q != 1. -/
def qDerivative (f : ℝ → ℝ) (a x : ℝ) : ℝ :=
  (f (a * x) - f x) / (a * x - x)

/-! Definition sanity examples. These do not prove the target theorems. -/

example : shannonEntropyNats (fun _ : Fin 1 => (1 : ℝ)) = 0 := by
  simp [shannonEntropyNats]

example (q : ℝ) : classicalRenyiNats (fun _ : Fin 1 => (1 : ℝ)) q = 0 := by
  simp [classicalRenyiNats, shannonEntropyNats]

example (T0 : ℝ) : referenceEnergies (fun _ : Fin 1 => (1 : ℝ)) T0 = 0 := by
  funext i
  simp [referenceEnergies]

example (T : ℝ) : classicalPartition (fun _ : Fin 1 => (0 : ℝ)) T = 1 := by
  simp [classicalPartition]

example (T : ℝ) : classicalGibbs (fun _ : Unit => -(0 : ℝ) / T) () = 1 := by
  simp [classicalGibbs, PMF.ofFintype_apply]

example (T : ℝ) : classicalFreeEnergy (fun _ : Fin 1 => (0 : ℝ)) T = 0 := by
  simp [classicalFreeEnergy, classicalPartition]

-- The frozen interface specifies the zero exponent even on the kernel.
-- Positive entropy orders below use its spectral real powers.
example {I : Type} [Fintype I] [DecidableEq I]
    (A : Matrix I I ℂ) : spectralPower A 0 = 1 := by
  simp [spectralPower]

example (k T : ℝ) : thermalPartition (0 : Matrix (Fin 2) (Fin 2) ℂ) k T = 2 := by
  simp [thermalPartition, NormedSpace.exp_zero, Matrix.trace_one]

example (k T : ℝ) : thermalGibbs (0 : Matrix (Fin 1) (Fin 1) ℂ) k T = 1 := by
  simp [thermalGibbs, QAlgorithms.gibbsState, NormedSpace.exp_zero, Matrix.trace_one]

example (k T : ℝ) : thermalFreeEnergy (0 : Matrix (Fin 2) (Fin 2) ℂ) k T =
    -k * T * Real.log 2 := by
  simp [thermalFreeEnergy, thermalPartition, NormedSpace.exp_zero, Matrix.trace_one]

example {I : Type} [Fintype I] [DecidableEq I]
    (rho : Matrix I I ℂ) (k : ℝ) : renyiEntropyWithBoltzmann rho k 1 =
      -k * (cfc (fun x : ℝ => x * Real.log x) rho).trace.re := by
  simp [renyiEntropyWithBoltzmann]

example : qDerivative (fun x : ℝ => x) 2 1 = 1 := by
  norm_num [qDerivative]

end QAlgorithms.Papers.Independent.Advance50.P26
Source
Renyi Entropy and Free Energy, arXiv:1102.2098v4, https://arxiv.org/abs/1102.2098v4
Read-back

What the Lean code literally says, in plain math · gpt-6.1-sol

QAlgorithms.Papers.Independent.Advance50.P26.classicalFreeEnergy

For any finite type III, any function E:I→RE:I\to\mathbb RE:I→R, and any real TTT, this defines

FE(T)=−Tlog⁡ ⁣(∑i∈Iexp⁡ ⁣(−EiT)).F_E(T)=-T\log\!\left(\sum_{i\in I}\exp\!\left(-\frac{E_i}{T}\right)\right).FE​(T)=−Tlog(i∈I∑​exp(−TEi​​)).

No positivity assumption on TTT is required. All operations are total, with division by zero and log⁡0\log0log0 both equal to 000. Consequently, FE(0)=0F_E(0)=0FE​(0)=0, and an empty index type gives FE(T)=0F_E(T)=0FE​(T)=0 for every TTT.

QAlgorithms.Papers.Independent.Advance50.P26.classicalPartition

For any finite type III, any real-valued function E:I→RE:I\to\mathbb RE:I→R, and any real TTT, this defines

ZE(T)=∑i∈Iexp⁡ ⁣(−EiT).Z_E(T)=\sum_{i\in I}\exp\!\left(-\frac{E_i}{T}\right).ZE​(T)=i∈I∑​exp(−TEi​​).

No positivity assumption on TTT is imposed. Division by zero has value 000, so ZE(0)=∣I∣Z_E(0)=|I|ZE​(0)=∣I∣. If III is empty, the sum is 000 for every TTT.

QAlgorithms.Papers.Independent.Advance50.P26.classicalRenyiNats

For any finite type III, any function p:I→Rp:I\to\mathbb Rp:I→R, and any real qqq, this defines

Rq(p)={−∑i∈Ipilog⁡pi,q=1,log⁡ ⁣(∑i∈Ipiq)1−q,q≠1.R_q(p)= \begin{cases} -\displaystyle\sum_{i\in I}p_i\log p_i,&q=1,\\[4pt] \displaystyle\frac{\log\!\left(\sum_{i\in I}p_i^q\right)}{1-q},&q\ne1. \end{cases}Rq​(p)=⎩⎨⎧​−i∈I∑​pi​logpi​,1−qlog(∑i∈I​piq​)​,​q=1,q=1.​

The first branch uses an enumeration of III to form the displayed sum. No nonnegativity or normalization of ppp, or positivity of qqq, is assumed. Powers and logarithms use their total real-valued definitions; in particular, log⁡0=0\log0=0log0=0. The finite type may be empty, in which case the value is 000 for every qqq.

QAlgorithms.Papers.Independent.Advance50.P26.qDerivative

For every function f:R→Rf:\mathbb R\to\mathbb Rf:R→R and all real a,xa,xa,x, this defines

Daf(x)=f(ax)−f(x)ax−x.D_a f(x)=\frac{f(ax)-f(x)}{ax-x}.Da​f(x)=ax−xf(ax)−f(x)​.

No continuity or differentiability assumption is required, and no limit is taken. When ax=xax=xax=x, including whenever a=1a=1a=1 or x=0x=0x=0, the denominator and numerator are zero and the defined value is 000.

QAlgorithms.Papers.Independent.Advance50.P26.referenceEnergies

For any type III, any function p:I→Rp:I\to\mathbb Rp:I→R, and any real T0T_0T0​, this defines the function E:I→RE:I\to\mathbb RE:I→R by

Ei=−T0log⁡pi.E_i=-T_0\log p_i.Ei​=−T0​logpi​.

There are no finiteness, positivity, or normalization assumptions. The real logarithm is total: log⁡0=0\log0=0log0=0, so pi=0p_i=0pi​=0 gives Ei=0E_i=0Ei​=0; for negative pip_ipi​, its value is log⁡∣pi∣\log|p_i|log∣pi​∣.

QAlgorithms.Papers.Independent.Advance50.P26.renyiEntropyWithBoltzmann

For any finite type III with decidable equality, any complex square matrix ρ\rhoρ indexed by III, and any real k,qk,qk,q, this defines

Sk,q(ρ)={−k Re⁡tr⁡Cρ(x↦xlog⁡x),q=1,klog⁡ ⁣(Re⁡tr⁡Pq(ρ))1−q,q≠1,Pq(ρ)={Id,q=0,Cρ ⁣(x↦{0,x=0,xq,x≠0),q≠0.S_{k,q}(\rho)= \begin{cases} -k\,\operatorname{Re}\operatorname{tr}\mathcal C_\rho(x\mapsto x\log x),&q=1,\\[3pt] \displaystyle\frac{k\log\!\left(\operatorname{Re}\operatorname{tr}P_q(\rho)\right)}{1-q},&q\ne1, \end{cases} \qquad P_q(\rho)= \begin{cases} \mathrm{Id},&q=0,\\ \mathcal C_\rho\!\left(x\mapsto \begin{cases}0,&x=0,\\x^q,&x\ne0\end{cases}\right),&q\ne0. \end{cases}Sk,q​(ρ)=⎩⎨⎧​−kRetrCρ​(x↦xlogx),1−qklog(RetrPq​(ρ))​,​q=1,q=1,​Pq​(ρ)=⎩⎨⎧​Id,Cρ​(x↦{0,xq,​x=0,x=0​),​q=0,q=0.​

Here Cρ\mathcal C_\rhoCρ​ is the real continuous functional calculus: for Hermitian ρ\rhoρ, it applies the indicated function to its eigenvalues; its total definition gives zero for non-Hermitian ρ\rhoρ. No density-matrix, positivity, trace, or sign assumptions are imposed. In particular, the q=0q=0q=0 power is the identity even when ρ\rhoρ is singular or zero. Logarithms use log⁡0=0\log0=0log0=0, and an empty index type gives entropy 000.

QAlgorithms.Papers.Independent.Advance50.P26.thermalFreeEnergy

For any finite type III with decidable equality, any complex square matrix HHH indexed by III, and any real k,Tk,Tk,T, this defines

FH,k(T)=−kTlog⁡ ⁣(Re⁡tr⁡exp⁡ ⁣(−(kT)−1H)).F_{H,k}(T) =-kT\log\!\left( \operatorname{Re}\operatorname{tr}\exp\!\left(-(kT)^{-1}H\right) \right).FH,k​(T)=−kTlog(Retrexp(−(kT)−1H)).

Neither Hermiticity of HHH nor positivity of k,Tk,Tk,T or the logarithm’s argument is assumed. The real logarithm is total, with log⁡0=0\log0=0log0=0 and log⁡x=log⁡∣x∣\log x=\log|x|logx=log∣x∣ for negative xxx. The result is 000 when kT=0kT=0kT=0, and also when III is empty.

QAlgorithms.Papers.Independent.Advance50.P26.thermalGibbs

For any finite type III with decidable equality, any complex square matrix HHH indexed by III, and any real k,Tk,Tk,T, set B=exp⁡(−(kT)−1H)B=\exp(-(kT)^{-1}H)B=exp(−(kT)−1H). This defines

GH,k(T)=(tr⁡B)−1B.G_{H,k}(T)=\bigl(\operatorname{tr}B\bigr)^{-1}B.GH,k​(T)=(trB)−1B.

The normalization uses the complex trace, rather than its real part. No Hermiticity, positivity, or nonempty-dimension assumption is imposed. A zero complex trace gives the zero matrix because 0−1=00^{-1}=00−1=0. If kT=0kT=0kT=0 and III is nonempty, the result is ∣I∣−1Id|I|^{-1}\mathrm{Id}∣I∣−1Id; if III is empty, it is the unique empty matrix.

QAlgorithms.Papers.Independent.Advance50.P26.thermalPartition

For any finite type III with decidable equality, any complex square matrix HHH indexed by III, and any real k,Tk,Tk,T, this defines

ZH,k(T)=Re⁡tr⁡exp⁡ ⁣(−(kT)−1H),Z_{H,k}(T)=\operatorname{Re}\operatorname{tr} \exp\!\left(-(kT)^{-1}H\right),ZH,k​(T)=Retrexp(−(kT)−1H),

where exp⁡\expexp is the matrix exponential and the scalar multiplying HHH is real. No Hermiticity of HHH, or positivity of k,Tk,Tk,T, is assumed. The real part is taken after the trace. Since 0−1=00^{-1}=00−1=0, kT=0kT=0kT=0 gives ZH,k(T)=∣I∣Z_{H,k}(T)=|I|ZH,k​(T)=∣I∣. For empty III, the value is 000.

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

    Confirmed by the moderator at approval.

  • Endorsed by Gohan · Oct 29, 2026

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

View graph

Get started

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

About Prove2Me

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

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me