Zulip Chat Archive

Stream: new members

Topic: Maxwell relation


Parivash (Mar 04 2023 at 14:12):

Hi,
I'm going to prove the following rule:
Definition: dU=TdSPdVdU=TdS - PdV. We can now consider U as a function of S and V such that U=U(S,V).
We can now write the total differential of U=U(S,V) as:
dU=(US)VdS+(UV)SdVdU=(\frac{\partial U}{\partial S})_{V} dS+(\frac{\partial U}{\partial V})_{S} dV
We can now equate the two expression for dU:
dU=(US)VdS+(UV)SdV=TdSPdVdU=(\frac{\partial U}{\partial S})_{V} dS+(\frac{\partial U}{\partial V})_{S} dV = TdS-PdV
From here we can equate the coefficients of dS and dV:
(US)V=T(\frac{\partial U}{\partial S})_{V}=T
(UV)S=P(\frac{\partial U}{\partial V})_{S}=-P
Let's only consider the first of these (US)V=T(\frac{\partial U}{\partial S})_{V}=T. Consider here differentiating both sides with respect to V while keeping S constant. This means we apply$$ (\frac{\partial}{\partial V})_{S}$$ to both sides, such that:
V)S(US)V=(TV)S \frac{\partial}{\partial V})_{S}(\frac{\partial U}{\partial S})_{V}= (\frac{\partial T}{\partial V})_{S}
again consider differentiating both sides of (UV)S=P(\frac{\partial U}{\partial V})_{S}=-P with respect to S while keeping V constant. This means applying S)V\frac{\partial}{\partial S})_{V} to both sides:
S)V(UV)S=(PS)V\frac{\partial}{\partial S})_{V}(\frac{\partial U}{\partial V})_{S} = -(\frac{\partial P}{\partial S})_{V}

  • we can flip the order here like:
    S)VV)SU=V)SS)VU\frac{\partial}{\partial S})_{V}\frac{\partial}{\partial V})_{S}U = \frac{\partial}{\partial V})_{S}\frac{\partial}{\partial S})_{V}U
    So, from the two result above we have:
    (TV)S=(PS)V(\frac{\partial T}{\partial V})_{S}=-(\frac{\partial P}{\partial S})_{V}
    I appreciate to get some help understanding how to formalize this rule by Lean
    Thanks

Kevin Buzzard (Mar 04 2023 at 14:21):

Do we have differential forms in the sense of differential geometry yet?

Parivash (Mar 04 2023 at 14:32):

@Kevin Buzzard
Professor Kevin, not sure I could understand your means.
So, you means Lean not support to formalize it or I should explain it in the other ways

Kevin Buzzard (Mar 04 2023 at 14:52):

I mean "can you state what you want to prove in Lean"? Stating the theorem is a necessary prerequisite for proving it, and I am raising the possibility that it might be nontrivial to even state, given what we have right now -- or I might be wrong.

Kevin Buzzard (Mar 04 2023 at 15:02):

Basically, you are not really asking a well-formed question right now. "Can you prove <maths stuff> in Lean" is ambiguous. "Can you prove <lean code with a sorry in>" is not.

Yaël Dillies (Mar 04 2023 at 15:03):

To be fair to Parivash, they asked "how to formalize this rule in Lean" which includes stating the theorem. But I agree it's no easy task.

Parivash (Mar 04 2023 at 15:11):

Yeah, your right I don't clearly separate goals ,...
This is our goal: (TV)S=(PS)V (\frac{\partial T}{\partial V})_{S}=-(\frac{\partial P}{\partial S})_{V}
In order to prove it we need to use
1st) this definition: dU=TdSPdVdU=TdS-PdV
2nd) from the 1st we find that U is dependent on S and V (U=U(S,V))
So, by following the mentioned path finally we could reach the goal.

Kevin Buzzard (Mar 04 2023 at 15:12):

What I'm trying to say is that you can talk as much maths as you like, but without some Lean code it's very difficult to engage with the questions you're asking.

Kevin Buzzard (Mar 04 2023 at 15:13):

With your earlier questions about infinite sums of real numbers it was easy to translate the maths into Lean so this was not an issue. But with differentials it's a different story.

Parivash (Mar 04 2023 at 15:14):

Yeah, exactly, that's totally different!
Let me see how can I define it in Lean to provide you

Kevin Buzzard (Mar 04 2023 at 15:16):

And what I am concerned about is that although mathlib has the real numbers, I am unclear about whether it has differential forms right now (I know people are working on it but I don't know if we're there yet) so any Lean statement might have to avoid differential forms (mathlib does have partial derivatives though).

Parivash (Mar 04 2023 at 15:19):

Ooooh, Thank you!

Patrick Massot (Mar 04 2023 at 16:12):

Parivash said:

Hi,
I'm going to prove the following rule:
Definition: $dU=TdS - PdV$. We can now consider U as a function of S and V such that U=U(S,V).

Lean cannot help you if you don't have a mathematical definition and a mathematical statement. Your "definition" is meaningless. At the very least you need to specify the types of U, T, P, V and S before writing anything else.

Patrick Massot (Mar 04 2023 at 16:13):

I know this isn't the rule of the game in physics. And I have nothing against physics, but this is not the game you can play with Lean.

Tomas Skrivan (Mar 05 2023 at 00:26):

Bellow is a sketch how to do it in Lean 4. Maxwell relations are just a simple consequence of the fact that you can swap partial derivatives.

<rant> I would advocate to drop all the nonsense with differentials, which I think is a crime on poor physics students. All those differentials are never well explained and just plain confusing. </rant>

As a starting point, I would just define temperature as T=US T = \frac{\partial U}{\partial S} and pressure as P=UVP = -\frac{\partial U}{\partial V} then the first Maxwell relation is just swapping partial derivatives.

The other relations are a bit trickier. You perform Legendre transform on the internal energy UU to switch to different set of variables. For example, for the second Maxwell's relation the hardest part is to show that the temperature is related to enthalphy as T=HST = \frac{\partial H}{\partial S} and that volume is related to enthalphy as V=HPV = \frac{\partial H}{\partial P} (theorems enthalpy_temperature and enthalpy_volume). Once you have these relations, it is again just swapping partial derivatives.

One of the most confusing part when learning thermodynamics is that the book/lecture randomly jumps between different set of variables. Sometime they talk about temperature as a function of entropy and pressure but sometimes temperature as a function of entropy and volume. In Lean, you have to be very explicit about this and you can't just jump between variables like this. Thus in the code bellow I have two separate function T_sp and T_sv to denote temperature as a function of different sets of variables.

Here is the Lean 4 sketch:

The notation ⅆ (x':=x), f x' corresponds to the mathematical df(x)dxx=x \frac{d f(x')}{d x'} \big|_{x'=x}

-- necessary operations
abbrev  := Float

def inverse (f : α  β) : β  α := sorry
postfix:max (priority:=high) " ⁻¹ " => inverse

def derivative (f :   ) :    := sorry
macro (priority:=high) " ⅆ " "(" x:ident ":=" xval:term ")" "," fval:term : term => `((derivative λ $x => $fval) $xval )



-- internal energy -------------------------------------------------------------
def U (S : ) (V : ) :  := sorry

-- definition of temperature and pressure as functions of entropy and volume
def T_sv (s v) :=  (s':=s), U s' v
def P_sv (s v) := -  (v':=v), U s v'


theorem MaxwellRelation1 (s v)
  : ( (v':=v), T_sv s v') = - ( (s':=s), P_sv s' v) :=
by
  unfold T_sv P_sv
  -- swap derivatives and we are done
  admit

-- Enthalpy --------------------------------------------------------------------

-- volume and temperature as functions of entropy and pressure
-- change of variables comming from Legandre transform
def V_sp (s p : ) := (λ v => P_sv s v)⁻¹ p
def T_sp (s p : ) := T_sv s (V_sp s p)

-- Enthalpy
-- H is leganre transform of U w.r.t. to V variable
def H (s p : ) :  := U s (T_sp s p) - p * T_sp s p

theorem enthalpy_temperature (s p) : T_sp s p = ( (s':=s), H s' p) := sorry
theorem enthalpy_volume      (s p) : V_sp s p = ( (p':=p), H s p') := sorry

theorem MaxwellRelation2 (s p)
  : ( (p':=p), T_sp s p') = ( (s':=s), V_sp s' p) :=
by
  simp only [enthalpy_temperature, enthalpy_volume]
  -- swap derivatives and we are done
  admit


-- Helmholtz -------------------------------------------------------------------

-- entropy and pressure as functions of temperature and volume
def S_tv (t v : ) := (λ s => T_sv s v)⁻¹ t
def P_tv (t v : ) := P_sv (S_tv t v) v


-- Helmholtz free energy
-- F is leganre transform of U w.r.t. to S variable
def F (t v : ) :  := U (S_tv t v) v - t * S_tv t v

theorem helmholtz_pressure (t v : ) : P_tv t v = - ( (v':=v), F t v') := sorry
theorem helmholtz_entropy  (t v : ) : S_tv t v = - ( (t':=t), F t' v) := sorry

theorem MaxwellRelation3 (t v)
  : ( (v':=v), S_tv t v') = ( (t':=t), P_tv t' v) :=
by
  simp only [helmholtz_pressure,helmholtz_entropy]
  -- swap derivatives and we are done
  admit

Last updated: Dec 20 2023 at 11:08 UTC