general formula,salt from weak base(p) and strong acid(q).
peter.vlasschaert@gmail.com,     29/09/2016

kill(all)$

salt : M(p)A(q),p,q , M = metal anion, A = non metal kation
       M(p)A(q) = weak base (p) + strong acid (q),ca=Cb=c
                = NH4OH   (p=1)   + HCl   (q=1)  =  NH4Cl + H(2)O
       p -> i=1..p -> kb1,kb2,..,kb(p)    (choose p=2,q=1)

v:2*h^2*kb1*kb2+1*h^1*kb1*kw;
w:h^2*kb1*kb2+h*kb1*kw+kw^2;
p:v/w;
q:1;
p1:cb*p+h=ca*q+kw/h;

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

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

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

mm1:ev(lhs(p4),h=0)$
mm2:coeff(lhs(p4),h^1)$
mm3:coeff(lhs(p4),h^2)$
mm4:coeff(lhs(p4),h^3)$
mm5:coeff(lhs(p4),h^4)$

p5:mm1+mm2*h+mm3*h^2+mm4*h^3+mm5*h^4=0;

example : M(p)A(q) , p=1 => M(p)A(1)
q=1 => M(1)A(1)=NH4Cl

p9:ev(p5,kb2=0);

p10:factor(p9);

p11:part(p10,1,1,2)=0;

approximation kb1 << c ,p=1,q=1 ,NH4Cl 'aq' 
         NH4Cl        -> NH4(+) + Cl(-)
reason : NH4(+)+H(2)O -> NH4OH + H(+)
          c              
         -x             x      x
        --------------------------- 
        c-x             x      x
       
        kh = equilibrium hydrolysis = x^2/(c-x)  
 
        1e)        kh = ([H(+)]*[MOH])/[M(+)]*[OH(-)]/[OH(-)]=kw/kb1
        2e)        kh = x^2/(c-x) ,c > x = [H(+)] = kw/[OH(-)]
        1e) = 2e)  kw/kb1 = x^2/c => [H(+)]=sqr((c*kw)/(kb1))

p12:ev(lhs(p11),kw^2=0,h*kb1*kw=0,h^2*kw=0)=0;

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

part(solve(p13,h),2);

other : Examples p=1,q=2,ca=cb=c 'salt'
        NaHCO3 first  : NaOH    :kb1=inf,kb2= 0
               second : H(2)CO3 :ka1,ka2
        c+h = ((h*ka1+2*ka1*ka2)*c)/(h^2+h*ka1+ka1*ka2)+kw/h
        ka1<<c => h^2=ka1*ka2