amphoteric salt : MH(n)A = M(+)+ H(n)A(-)  'version 1.0'
general         : MHB    = M(+)+ HB(-) = m + hb
peter.vlasschaert@gmail.com,02/10/2016

why :use for pH calculation by jump (= EP) of polyprotic acids
     with strong base.
examples: NaHCO3,NaHSO3,KH-Ftalaat  n=1 -> Na(+)+HB(-)
          NaH(2)PO4                 n=2 -> Na(+)+H(2)PO4(-)
--------------------------------------------------------------
--------------------------------------------------------------
formula: H(m)B ( m=2),ka1,ka2,pkw=pH+pOH
definition :amphoteric salt : nature acid (give H(+)) or 
                              nature base (take H(+))
                       up    give
nature acid : HB(-)        = H(+)  + B(2-) (1)
nature base : HB(-) + H(+) = H(2)B         (2)
--------------------------------------------------------------
--------------------------------------------------------------
aqua        : H(2)O        = H(+)+OH(-)    (3) 
result
[H(+)]tot = [B(2-)]-[H(2)B]+[0H(-)]
math = 'htot = h = b - h2b + oh '
H(m)B      = H(+) + H(m-1)B(-) -> H(2)B = H(+) + HB(-) -> ka1
H(m-1)B(-) = H(+) + H(m-2)B(2-)-> HB(-) = H(+) + B(2-) -> ka2    
nature acid :   (1) -> ka2   = ([H(+)]*[B(2-)])/[HB(-)]
nature base :   (2) -> 1/ka1 = ([H(2)B])/([HB(-)]*[H(+)])

kill(all);

p1:h=b-h2b+oh;
p2:ka1=(h*hb)/h2b;
p3:ka2=(h*b)/hb;
p4:oh = kw/h;

p5:part(solve(p2,h2b),1);
p6:part(solve(p3,b),1);

p7:ev(p1,p4,p5,p6);

p8:part(solve(p7,h),2);

first approximation ( kw=0)

p9:ev(p8,kw=0);

second approximation (kw=0 and ka1 << hb (anion solution,ex :HCO3(-))

find : all parts of (p9),see below;

p10:part((rhs(p9)),0);

p11:part((rhs(p9)),1,0);

p12:part((rhs(p9)),1,1);

p13:part((rhs(p9)),1,2);

ka1 << hb ,see below

p14:ev(p13,ka1=0);

p15:p11(p12,p14);

p16:lhs(p9)=p10(p15);

p17:pH =(-log(rhs(p16)));

rule : log(x*y) = log(x)+log(y)

p18:log(ka1*ka2)=log(ka1)+log(ka2);

p19:pH=part(-rhs(p18)/2);

pka1 = - log(ka1),pka2= - log(ka2)

p20:pH=ev(rhs(p19),-log(ka1)=pka1,-log(ka2)=pka2);