28 microcanonical ensemble iff the second order variations of entropy (A8) are negative definite straints are linear in f so that their second variations vanish). We can now express the mass, the entropy and the energy in terms of ρ ( r ) and T . Up to unimportant constants, we obtain for any perturbation δρ that conserves mass at first order, i.e. ∫ δρ d r = 0 (the conservation of energy has automati- cally been taken into account in the previous derivation). This stability criterion is equivalent to the stability crite- rion (12) but it is simpler because it is expressed in terms of the density instead of the distribution function. Finally, the solution of (3) is given by the distribution function (A2) with the density profile that is solution of (A5). Let us compute the variations of entropy and energy up to second order. We have We now have to solve the maximization problem To solve the maximization problem (17) we can pro- ceed in two steps. We first minimize the free energy at fixed mass and density profile ρ ( r ). This is equivalent to minimizing the free energy at fixed density profile. Writ- ing this leads to the Maxwellian distribution function Using the conservation of energy Δ E = 0 to eliminate δT , we obtain − k$_{B}$ ∫ ( δρ ) 2 2 ρm d r − 1 2 T ∫ δρδ Φ d r − 1 dNk$_{B}$T 2 (∫ Φ δρ d r ) 2 ≤ 0 , (A12) S = d 2 Nk$_{B}$ ln T − k$_{B}$ ∫ ρ m ln ρ m d r , (A3) E = d 2 Nk$_{B}$T + 1 2 ∫ ρ ( r , t ) u ( r , r $^{′}$) ρ ( r $^{′}$, t ) d r d r ′ + ∫ ρV d r . (A4) max ρ { S [ ρ ] | E [ ρ ] = E, M [ ρ ] = M } . (A5) δF + T ∫ λ ( r ) δ (∫ f d v ) d r = 0 , (A13) f ( r , v ) = ( m 2 πk$_{B}$T ) d/ 2 ρ ( r ) e − mv 2 2 k B T , (A14) Δ S = d 2 Nk$_{B}$ δT T − k$_{B}$ ∫ ( ln ρ m + 1 ) δρ m d r − d 4 Nk$_{B}$ ( δT T ) 2 − k$_{B}$ ∫ ( δρ ) 2 2 ρm d r , (A6) Δ E = d 2 Nk$_{B}$δT + ∫ Φ δρ d r + 1 2 ∫ δρδ Φ d r . (A7) Δ S = − 1 T ∫ Φ δρ d r − k$_{B}$ ∫ ( ln ρ m + 1 ) δρ m d r − 1 2 T ∫ δρδ Φ d r − 1 dNk$_{B}$T 2 (∫ Φ δρ d r ) 2 − k$_{B}$ ∫ ( δρ ) 2 2 ρm d r . (A8) F = 1 2 ∫ ρ ( r , t ) u ( r , r $^{′}$) ρ ( r $^{′}$, t ) d r d r ′ + ∫ ρV d r + k$_{B}$T ∫ ρ m ln ρ m d r . (A15) 2. Canonical ensemble which is the global minimum of free energy with the pre- vious constraint since δ $^{2}$F = T ∫ ( δf ) 2 2 fm d r d v > 0 (the constraints are linear in f so that their second variations vanish). We can now express the free energy in terms of ρ ( r ). Up to unimportant constants, we get We now have to solve the minimization problem Finally, the solution of (17) is given by the distribution function (A14) with the density profile that is solution of (A16). The first variations lead to the mean field Boltzmann distribution where Φ( r ) is given by Eq. (7). Combining Eq. (A18) with Eq. (A14), we recover the mean field Maxwell- Boltzmann distribution (10). However, the present ap- proach allows us to simplify the condition of thermody- namical stability. Indeed, the system is stable in the where Φ( r ) is given by Eq. (7). Combining Eq. (A11) with Eq. (A2), we recover the mean field Maxwell- Boltzmann distribution (10). However, the present ap- proach allows us to simplify the condition of thermody- namical stability. Indeed, the system is stable in the we obtain the mean field Boltzmann distribution The conservation of mass can be taken into account by in- troducing a Lagrange multiplier. Writing the variational principle as Let us consider the first order variations. At first order, we have min ρ { F [ ρ ] | M [ ρ ] = M } . (A16) δF + αT δM = 0 , (A17) ρ = A $^{′}$e − m Φ k B T , (A18) ρ = A $^{′}$e − m Φ k B T , (A11) δS − αδM = 0 , (A10) δS = − 1 T ∫ Φ δρ d r − k$_{B}$ ∫ ( ln ρ m + 1 ) δρ m d r . (A9)