kill(all);

maxima :theoretical legendre transformation,version 1.0
peter.vlasschaert@gmail.com,01/04/2020

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

load(lrats)$
load(simplify_sum)$

example : f ,three variables
====================

p1:f(x[1],x[2],x[3])=f;
p1a:df = diff(lhs(p1));

p1b:makelist(del(x[i])=dx[i],i,1,3);

rem : the length of the string: 'length'

p1b1:length(p1b);

p1ca:subst(p1b,p1a);

p1cb:df = sum(u[i]*dx[i],i,r1,r2);

example:r1=1,r2=3

p1cc: subst([r1=1,r2=3],p1cb);

definition : g  'legendre transformation'
===============================
g = g(x[1],x[2],...x[p],u[p+1],u[p+2],...u[n])

p2a:g=rhs(p1) -sum(u[i]*x[i],i,r1,r2);

because : g, r1= p+1,r2=n

p2b1:[r1=p+1,r2=n];
p2b2:subst(p2b1,p2a);

see :f=f(x[i])  → u[i] =(df/dx[i]) when x[j] ≠ x[i].

 ===============================

p3:dg =df -sum(u[i]*dx[i]+du[i]*x[i],i,r3,r4);

use : p1cb

p3a:subst([p1cb],p3);

p3b:[r1=1,r2=n,r3=p+1,r4=n];
p3c:subst(p3b,p3a);

info
=================================

declare(n,integer,p,integer)$
assume(n>p,p>1);

properties(n);

properties(p);

 ==================================

find : dg
======

p3d:lhs(p3c)=intosum(rhs(p3c));

? problem , I don't find way to make three sums ,p3d

p3e:sum(u[i]*dx[i],i,1,n) -sum(u[i]*dx[i],i,p+1,n)=sum(u[i]*dx[i],i,1,p);

p3f:dg=rhs(p3e)+sum((-x[i])*du[i],i,p+1,n);

p3f1:intosum(p3f);

rem : u[i] =(df/dx[i]) when x[j] ≠ x[i]

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

m:dU = T*dS-P*dV+μ*dn;

from above document:one component
1e) no chemical reaction  : dU = T*dS -P*dV
2e)      chemical reaction  : dU = T*dS -P*dV+μ*dn

result U = U(S,V,n)

p4:'diff(U,a) =T*'diff(S,a)-P*'diff(V,a)+μ*'diff(n,a);

depends(U,[S,V,n]);

find : state function: g1
=================
for  : a=S , constraint : partial,trick 

1e) a=S,when sum only one term
_______

p5:subst([a=S],p4);

p5a:lhs(p5) =subst([n=0,V=0],rhs(p5));

2e) g1 (= thermodynamic state function)
--------

p5b:g1=U-'diff(U,S)*S;

p5c:subst([p5a],p5b);

from :
maxima : intro legendre transformation( = thermodynamics),H,G,F , version 1.0
result : F ,Helmholtz Free Energy , F = U-T*S

p5d:subst([g1=F],p5c);

differentation :p5d
rem : diff(f*g)=diff(f)*g+f*diff(g)

p5e:lratsubst([F=dF,U=dU,S*T = S*dT+T*dS],p5d);

use :m,from above

p5f:subst([m],p5e);

result : F=F(V,T,n)

depends(F,[V,T,n]);

p5f1:dF=diff(F);

p5f2:[del(n)=dn,del(V)=dV,del(T)=dT];
p5f3:subst(p5f2,p5f1);

combination : p5e & p5f3
===================

p5g1:ratcoef(rhs(p5f3)=rhs(p5f),dV);
p5g2:ratcoef(rhs(p5f3)=rhs(p5f),dT);
p5g3:ratcoef(rhs(p5f3)=rhs(p5f),dn);

find : state function: g2
=================
for  : a={S,V} , constraint : partial,trick 
a=S see 'p5'
a=V see 'below'

1e) a=V,when sum only two  term  for (S,V)
-----------------------------------------------------

p6:subst([a=V],p4);

p6a:subst([n=0,S=0],p6);

2e) g2 (= thermodynamic state function)
--------

p6b:g2=U-'diff(U,S)*S-'diff(U,V)*V;

use :p5a & p6a

p6c:subst([p5a,p6a],p6b);

from :
maxima : intro legendre transformation( = thermodynamics),H,G,F , version 1.0
H = U+P*V,enthalpy

p6d:lratsubst([U+P*V=H],p6c);

from :
maxima : intro legendre transformation( = thermodynamics),H,G,F , version 1.0
G = H-T*S,Gibbs Free Energy

p6e:subst([g2=G],p6d);

differentation :p6e
rem : diff(f*g)=diff(f)*g+f*diff(g)

p6f1:H =U+P*V;
p6f2:dH = dU +P*dV+V*dP;
p6f3:dG =dH-S*dT-T*dS;

find :dG
----------
use :m & p6f2

p6g1:p6f3;

p6g2:subst([p6f2],p6g1);

p6g3:subst([m],p6g2);

result : G=G(P,T,n)

depends(G,[P,T,n]);

p6h1:dG=diff(G);

p6h2:[del(n)=dn,del(P)=dP,del(T)=dT];
p6h3:subst(p6h2,p6h1);

combination :p6g3 & p6h3
--------------------------------

p5i1:ratcoef(rhs(p6g3)=rhs(p6h3),dP);
p5i2:ratcoef(rhs(p6g3)=rhs(p6h3),dT);
p5i3:ratcoef(rhs(p6g3)=rhs(p6h3),dn);

definition : μ =chemical potential, μ='diff(G,n,1) or 'diff(F,n,1)=μ