kill(all)$

(tri)protic strong acid,H(n)A => n=3
-----------------------------------
h=[H(+)],c=Ca,k1=ka(1),k2=ka(2),k3=ka(3),kw = 1E-14
peter.vlasschaert@gmail.com,28/09/2016,optimize

p1:h=((h^2*k1+2*h*k1*k2+3*k1*k2*k3)/(h^3+h^2*k1+h*k1*k2+k1*k2*k3))*c+kw/h;

;

p2:lhs(p1)-rhs(p1)=0$

p3:factor(lhs(p2))=0$

p4:num(lhs(p3))=0;

n1:ev(lhs(p4),h=0)$
n2:coeff(lhs(p4),h)$
n3:coeff(lhs(p4),h^2)$
n4:coeff(lhs(p4),h^3)$
n5:coeff(lhs(p4),h^4)$
n6:coeff(lhs(p4),h^5)$

p5:n6*h^5+n5*h^4+n4*h^3+n3*h^2+n2*h^1+n1=0;

p6:ratsubst(k,k1*k2*k3,n1)$
n1_k:ratsubst(k1*k2,k,(coeff(p6,k)/(k)))*(k1*k2*k3);
p7:ratsubst(k,k1*k2*k3,n2)$
n2_k:ratsubst(k1*k2,k,(coeff(p7,k)/(k)))*(k1*k2*k3);
p8:ratsubst(k,k1*k2*k3,n3)$
n3_k:ratsubst(k1*k2,k,(coeff(p8,k)/(k)))*(k1*k2*k3);
p9:ratsubst(k,k1*k2*k3,n4)$
n4_k:ratsubst(k1*k2,k,(coeff(p9,k)/(k)))*(k1*k2*k3);
p10:ratsubst(k,k1*k2*k3,n5)$
n5_k:ratsubst(k1*k2,k,(coeff(p10,k)/(k)))*(k1*k2*k3);

formula : triprotic strong acid,H3A

p11:n5_k*h^4+n4_k*h^3+n3_k*h^2+n2_k*h+n1_k=0;

p12:factor(lhs(p11))=0;

p13:part(p12,1,1,2)=0;

first approximation : triprotic strong acid 'H3A'

p14:(-1)*ev(lhs(p13),kw=0)=0;

p15:factor(lhs(p14))=0;

p16:part(p15,1,2)=0;

p17:solve(p16,h);

p18:part(p17,1);

pH = - log(3*ca)