kill(all)$

maxima : intro legendre transformation( = thermodynamics),H,G,F , version 1.0
peter.vlasschaert@gmail.com,31/03/2020

simplify : μ ' chemical potential '
=================================
extra term : μ*dN  , when chemical reactions.
=================================
dG = V.dP-S*dT +μ*dN
=================================

load packages
===========

load(lrats)$

definition(H,G,F)
=============

1e) definition : H (= enthalpy)
=====================
U = internal energy
P = pressure
V = volume

p1:H = U+P*V;

2e) definition : G ( = Gibbs Free Energy)
==============================
H = enthalpy
T = temperature
S = entropy

p2:G = H - T*S;
p2a:subst([p1],p2);

3e) definition : F ( = Helmhotz Free Energy)
================================
U = enthalpy
T = temperature
S = entropy

p3:F=U-T*S;

We need to start : firist @ second law of thermodynamics
to find : H,G,F (= legendre transformation)
=========================================
U = Q + W = heat + work
U      : ( independent of path)
Q,W : (   dependent of path )

a)  first law of thermodynamics
--------------------------------------

p4:U =Q +W;
p4a:diff(p4);
p4b:[del(U)=dU,del(W) =dW,del(Q)=dQ];
p4c:subst(p4b,p4a);

b) second law of thermodynamics
----------------------------------------
→ dQ = T*dS      ( heat exchange )
→ dW = -P*dV   (  work exchange)

p5a:del(Q) = T*del(S);
p5b:del(W) = -P*del(V);
p5c1:[del(S)=dS,del(V)=dV,del(P)=dP,del(T)=dT];
p5c2:[del(H)=dH,del(F)=dF,del(G)=dG];
p5c3:p4b;
p5c:append(append(p5c1,p5c2),p5c3)$

use :'append' to combine two lists.
see also : Menu : List 

c) combination 'first & second ' ,law
--------------------------------------------
use : 'p4a' & 'p5c'

p6a:subst([p5a,p5b],p4a);

p6b:subst(p5c,p6a);

first :Legendre transformation for  H
==========================
from definition(1) :H = U+P.V

1e)  use  second law
--------------------------

p7:p6a;

2e) use : x →diff(x)→del(x)
---------------------------------

p7a:lhs(p7) =part(rhs(p7),1)-'diff(P*V) +diff(x);

p7b:lhs(p7a) = V*diff(P) - del(P*V)+T*diff(S);

p7c:p7b+'diff(P*V);

3e) combination :del or diff
----------------------------------
rules :
del(c1+c2) = del(c1) + del(c2)
del(c1-c2) =  del(c1) -  del(c2)
del(-c3)     = -del(c3)

p7d1: del(c1) + del(c2) =del(c1+c2);

p7d1a:del(-c3) = - del(c3);

p7d2a:diff(c1)+diff(c2)  = diff(c1+c2);
p7d2b:subst([c2=-c2],p7d2a);

4e) combination :rules for lhs
-----------------------------------

part(del(P*V),0);

part(del(P*V),1);

p7e1:[c1=part(part(lhs(p7c),1),1)];

p7e2:[c2=part(part(lhs(p7c),2),1)];

p7e3:append(p7e1,p7e2);

use rule :p7d1

p7e4:subst(p7e3,p7d1);

5e)  final result
------------------

p7f1:rhs(p7e4) =rhs(p7c);

p7f2:lratsubst([rhs(p1)=lhs(p1)],p7f1);

p7f3:subst(p5c,p7f2);

second :Legendre transformation for  G
=============================
from definition(2) :G = H-T*S

q1:p2;

q1a:diff(q1);

q2a:subst([p1],q1a);

q3a:lratsubst([del(P*V+U) = diff(P*V+U)],q2a);

use :combination , first & second law
---------------------------------------------
use : 'p6a'

q4a:subst([p6a],q3a);

q4a1:subst(p5c,q4a);

normal  way : like first : legendre transformation.(will give same result),q4a

thrid :Legendre transformation for  F
=============================
from definition(3) :F= U-T*S

r1:p3;

r1a:diff(r1);

use : 'p6a'

r2a:subst([p6a],r1a);

r3a:subst(p5c,r2a);

normal  way : like first : legendre transformation.(will give same result),r2a

final result
========

without : chemical reaction
====================

t1:p7f3;
t2:q4a1;
t3:r3a;

H=H(S,P),G=G(P,T),F=F(V,T)

with  :chemical reaction
==================
m : components

t1a:lhs(t1) = rhs(t1)+sum(μ[i]*dN[i],i,1,m);
t1b:lhs(t2) = rhs(t2)+sum(μ[i]*dN[i],i,1,m);
t1c:lhs(t3) = rhs(t3)+sum(μ[i]*dN[i],i,1,m);

H=H(S,P,N[i]),G=G(P,T,N[i]),F=F(V,T,N[i]);

rem: H(S,P)

total differential
===========

s1:dH = diff(H(S,P));

s2:lhs(%) =subst(p5c,rhs(%));

find relation :between t1 & s2
------------------------------------

s3:t1;

see : 'above'

s4a:subst([dS=0],rhs(s2) = rhs(s3))/dP;
s4b:subst([dP=0],rhs(s2) = rhs(s3))/dS;

analog :dG,dF

rem :rhs componensation : diff(P*V),diff(T*S)
see : Legendre transformation for H