general formula,salt from weak base and weak acid.
peter.vlasschaert@gmail.com,28/09/2016

salt : M(p)A(q),p=q=1 , M = metal anion,A = non metal kation
       example : NH4Ac
       M(p)A(q) -> p*M(x+)+q*A(y-) -> p*(x+)+q*(y-) = 0
       M(p)A(q) -> weak base + weak acid

first step : general equation pH : p=2,q=2,ca=cb=c
                                   kb(i) ,i=1..p => kb1,kb2
                                   ka(i) ,i=1..q => ka1,ka2

salt = weak base + weak acid,  p=1,q=1,kb1,ka1
example : NH(4)Ac(1)->NH4(+)+Ac(-)

v1:(2*h^2*kb1*kb2+1*h^1*kb1*kw)$
w1:h^2*kb1*kb2+h^1*kb1*kw+kw^2$
v2:h^1*ka1+2*ka1*ka2$
w2:h^2+h^1*ka1+ka1*ka2$
p1: v1*cb/w1+h = v2*ca/w2 + kw/h;

p2 : ev(lhs(p1)-rhs(p1)=0,ca=c,cb=c,kb2=0,ka2=0);

p3:(-1)*factor(p2);

p4:-1*(num(lhs(p3)))=0;

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

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

salt = weak base + weak acid,  p=2,q=1,kb1,kb2,ka1
example : M(2)A(1) -> 2*M(x+)+1*A(y-),2*x(+)-1*y(-)

p6:ev(lhs(p1)-rhs(p1)=0,ca=c,cb=c,ka2=0);

p7:factor(p6)$

p8:(num(lhs(p7)))=0;

nn6*h^5+nn5*h^4+nn4*h^3+nn3*h^2+nn2*h^1+nn1=0

nn1:ev(lhs(p8),h=0);
nn2:coeff(lhs(p8),h^1);
nn3:coeff(lhs(p8),h^2);
nn4:coeff(lhs(p8),h^3);
nn5:coeff(lhs(p8),h^4);
nn6:coeff(lhs(p8),h^5);