kill(all)$

Maxima : intro computation ,base and acid, 'appendix 6a,version 1.0'
peter.vlasschaert@gmail.com,06/01/2019

load packages :
=============

load(lrats)$

definition :
=========

log10(x) := log(x)/log(10);

polyprotic : example :  H2A (n=2)
===========================

distribution function:
-------------------------------
α(i)  i=0,1,...,n

p1:H^2+Ka1*H+Ka1*Ka2 = q;

p1a:args(lhs(p1));

α(0),α(1),α(2)

p2a:α(0) = p1a[3]/lhs(p1);
p2b:α(1) = p1a[2]/lhs(p1);
p2c:α(2) = p1a[1]/lhs(p1);

p2a1: subst([p1],p2a);
p2b1 :subst([p1],p2b);
p2c1 :subst([p1],p2c);

check :sum(α(i),i,0,n) = 1

p3:p2a+p2b+p2c;

p3a:lhs(p3) = ratsimp(rhs(p3));

calculus : diprotic system  (n=2), 'H2A'
=================================

depends(pH,H);

p4:pH=-log10(H);;

d pH = -1/log(10) *dH/H

p4a:diff(lhs(p4))=diff(rhs(p4));

function : rhs
===========

p4b:f(x)  :=  -log(10)*H*diff(x,H);

function : lhs
===========

p4b1:g(x):=diff(x,pH);

find  : d(log(α(0)))/dph : ?  'lhs'
=========================

rhs =>

p5: x = log(rhs(p2a));

log(H^2/(Ka1*Ka2+H*Ka1+H^2)), logexpand=super;

p5a:lhs(p5)=rhs(p5),logexpand = super;

p6a:subst([p5a],rhs(p4b));

p6b:ev(p6a,diff);

p6c:ratsimp(p6b);

p6d1:factor(num(p6c));

p6d2:denom(p6c);

p6d:p6d1/p6d2;

p6e: expand(p6d);

p6f:subst([p1],p6e);

p6g:[rhs(p2a1)=lhs(p2a1),rhs(p2b1)=lhs(p2b1),rhs(p2c1) = lhs(p2c1)];

p6h:lratsubst(p6g,p6f);

lhs =>

p7:diff(log(α(0)),α(0));

result :
=====

p7a:'g(α(0))*p7= p6h;

p7b:p7a*α(0);

total result 

p8:'diff(α(0),ph)  = rhs(p7b);

'----------------------------------------------------------------------------------------------------------'