kill(all)$

Enthalpy (:=H ) and Entropy (=s) as function( T & P),version 1.0a
peter.vlasschaert@gmail.com,02/09/2020

→ref : books on general thermodynamics.
→ref :https://petervlaschemeng.weebly.com/
          defrule :Programming :'Maxima'
          new:27/04/2020:programming:  'defrule' ,version 1.0b
---------------------------------------------------------------------------------------------------------
version 1.0a  ( = error : correction defrule:'f2' : "integrate →∇,solve problem")
---------------------------------------------------------------------------------------------------------

load packages,option
=================

load(lrats)$ ratprint:false$

1e)  Maxwell's equation : principal.
===========================

p1a:depends(F,[x,y]);

p1a1:listofvars(p1a);

p1b:'diff(F)=diff(F);

p1c1:coeff(rhs(p1b),del(p1a1[1]))=M1;
p1c2:coeff(rhs(p1b),del(p1a1[2]))=M2;

p1d:lratsubst([p1c1,p1c2],p1b);

→  differentation :p1c1 respect  to  'y'

p1d1:diff(lhs(p1c1),y)='diff(rhs(p1c1),y);

→  differentation :p1c2 respect  to  'x'

p1d2:diff(lhs(p1c2),x)='diff(rhs(p1c2),x);

→  final

use :combine : p1d1 & p1d2

p1e:rhs(p1d1) = rhs(p1d2);

=>  reason allowed :differentation in mixed : "second derivative" is  'immatrial'

a) First law of thermodynamics
========================
dU = dQ +dW ( U = internal energy),closed system( = mass constant)

p2:del(U) =del(Q)+del(W);

→  Entropy (=s)
----------------------
T = temperature.
Q =heat.

p2a:del(s) = del(Q)/T;

p2a1:solve(p2a,del(Q))[1];

→  Work ( = W)
----------------------
by UPAC convention
V = volume
P = Pressure

p2b: del(W)= -P*del(V);

p2c:lratsubst([p2a1,p2b],p2);

b)  1e)Gibbs Function,2e)Enthalpy Function
=============================

p3a:G = H-T*s;

p3a1:diff(p3a);

p3b:H = U+P*V;

p3b1:diff(p3b);

c) combination a)  & b)
===================
use : (F)irst (L)aw of (T)hermodynamics = FLT

first equation : 'p3a1 & p3b1 & p2c'

p4a:lratsubst([p3b1,p2c],p3a1);

second equation : ''p3b1 & p2c'

p4b:lratsubst([p2c],p3b1);

d) computation
============
see what we want title

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

use :'p4a'

p5:[del(T),del(P)];

p5a:diff(G)= rhs(p4a);

p5a1:coeff(p5a,p5[1]);
p5a2:coeff(p5a,p5[2]);

depends(s,[P,T],V,[P,T]);

ideal gas : P.V = R*T *n  => V = R/P*T*n

principal : Maxwell  (second order mixed derivatives)
-------------------------------------------------------------------------
1e)  p5a1 with respect to P
2e) p5a2  with respect to T

p5a1a:diff(p5a1,P); 
p5a2a:diff(p5a2,T);

p5a3a:(rhs(p5a1a)=rhs(p5a2a))*(-1);

use : 'p4b'

p5b1:diff(H)= rhs(p4b);

p5b2:p4b;

definition : C_P ( =heat capacity), fixed ( = pressure, P=constant)
==================================================
reason : del(p) = 0,see below s(P,T)

p6:C_p =diff(H,T);

p6x: C_P = del(H)/del(T);

→  H(T,P)

a)  use : p5b2/del(P)
------------------------------

p6a:p5b2/del(P),expand;

relation : del operator & diff operator
============================
defrule : see website , examples ,see above

matchdeclare([x1,y1,z1],true);
defrule(f1,z1*del(x1)/del(y1),z1*diff(x1,y1));

p6b:apply1(p6a,f1);

b) use: Maxwell relation 'see above = p5a3a'

p6c:lratsubst([p5a3a],p6b);

c) final H(P,T)
use :'p6,p6c,p5b1,p5b2'

p6d:lhs(p5b2) = lhs(p5b1);

p6d1:lratsubst([reverse(p6),p6c],p6d);

→ s(P,T)

p7a:del(s)= diff(s);

a) use :Maxwell relation ( =p5a3a)

p7b:lratsubst([p5a3a],p7a);

b) use:p5b2/del(T);

p7c:p5b2/del(T),expand;

c)  use defrule from above & 'p7c',del(P) =0
reason : rule working remove del(P) =0

p7d:apply1(p7c,f1);

d) solve :ds/dt from p7d

p7e:solve(p7d,diff(s,T))[1];

e) use definition C_p

p7f:lratsubst([reverse(p6)],p7e);

f) final s(P,T)
use :p7f & p7b

p7g:lratsubst([p7f],p7b),expand;

result final :H(P,T),s(P,T)
===================
use :p6d1 & p7g

p8a:p6d1;
p8b:p7g;

ideal gas : law
============
=> 1 mol substant

assume(R>0);

p8c: P*V =R*T;

p8d:solve(p8c,V);

matchdeclare([R],constant);

p8a1:ev(lratsubst(p8d,p8a),nouns);
p8b1:ev(lratsubst(p8d,p8b),nouns);

p8c1:'diff((R*T)/P,T,1)=diff((R*T)/P,T,1);

→ from : H(P,T) & ideal gas law

p8a2:lratsubst([p8c1],p8a1);
p8a3:lhs(p6d1)=rhs(p8a2);
p8a4:solve(p8a3,C_p);  /* see definition above C_p*/ 

→S (P,T) , true for ideal gas

p8b2:lratsubst([p8c1],p8b1),expand;

p8b3:lhs(p8b)= rhs(p8b2);

p8b4:p8b3/R,expand;

matchdeclare([aa,bb,cc],true)$

defrule(f2,∇(cc*del(aa)/aa,aa,bb,aa),cc*log(aa/bb));

p8b4a:∇(part(rhs(p8b4),1),T,T0,T);

p8b4b:∇(part(rhs(p8b4),2),P,P0,P);

defrule : all rules

disprule(all);

reason :defrule doesn't work ,f2,' integrals,gives a problem'
---------------------------------------------------------------------------------
change : integrate by a symbol : of your choice = ∇ ,f2 works 

solution : manual
=============

p9a:p8b4a=apply1(p8b4a,f2) ;
p9b:p8b4b=apply1(p8b4b,f2) ;

intial state(P0,T0) to final(P,T), entropy
-----------------------------------------------------

p9c:ΔS/R = rhs(p9a+p9b);

rem : info integration
================

p10a:args(p9a);
p10b:args(args(p9b)[1]);

rem : ideal gas U =U(T),internal energy
==============================
T = temperature

definition :C_V ( =heat capacity , constant =V( =volume))
============================================

p11:C_V='diff(U,T);

use :p3b,p3b1

depends(U,T);

p11a:p3b1;

for ideal gas : P*V =R*T (= 1 mol substance)

p11b:lratsubst([P*V=R*T],p3b);

p11c:diff(p11b,T);

use : Def C_P ,C_V
-----------------------------
use :p6,p11

p11c1:lratsubst([reverse(p6),reverse(p11)],p11c);

find : gas constant :   R = (P*V)/(T)
-----------------------------------------------

p11c2:solve(p11c1,R)[1];

 -----------------------------------------------------------------------------------------------------------------------------------------------