kill(all);

Maxima : intro computation ,base and acid, 'part :13,version 1.0'
peter.vlasschaert@gmail.com, 14/12/2018

Ampholyt  (Ned : Amfolyt)
=======================
examples : NaHCO3,NaHSO3,KH-ftalaat: general  HB(-)
Na , K = M

HB(-)  = HB
================
MHB = M(+) + HB(-)  ( solute solved into  H2O)
================

load packages :
------------------------

load(lrats)$
load(facexp)$

convert:
-------------

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

definition : pH,pOH
================

p1: pH(x)   :=-log10(x)$
p1a:pOH(x):=-log10(x)$

dissociation : aq :
===============

p1b:kw=10^(-14);

equilibrium  equations
==================

       HB(-)              ⇔ H(+) + B(2-)     ...  '1a'  => K_a2
       HB(-) + H(+)  ⇔ H2B                  ...  '1b' => K_a1
       H2O                ⇔ H(+) + OH(-)    ...  '1c' => Kw

rem : [HB(-)] = HB,[OH(-)]=OH,[H(+)] = H,[B(2-)] = B

 rem : H2B   ⇔ HB(-) + H(+)  =>  K_a1
            HB(-)  ⇔ B(2-) + H(+)  =>  K_a2

assume(K_a1>0,K_a2>0,B>0,HB>0,H2B>0,Kw>0);

A/  equilibrium  '1a' and '1b'
=======================

from '1a' => 

p2:K_a2  =( (H)*(B))/HB;

from '1b' =>

p3:K_a1=((H)*(HB))/(H2B);

find [H(+)]: ?
===================================
'1a' : formed   (+)      => [H(+)] '1a'=[B(2-)]
'1b' : react       (-)      =>  [H(+)] '1b'=> [H2B]
===================================
[H(+)]  = formed -react= [B(2-)]-[H2B]

p4: H=B-H2B;

from : 'p2' find B
------------------------

p2a:solve(p2,B);

from : 'p3' find H2B
------------------------------

p3a:solve(p3,H2B);

insert 'p2a,p3a' into 'p4'
====================

p5:subst([p2a[1],p3a[1]],p4);

find H: ?
=======

p6:solve(p5,H);

only positive solution physical meaning.
==================================

for i:1 thru 2 do(
if is(rhs(p6[i] )>0) = true then sol: p6[i]);

sol;

ph : of solution :
=============

p7:ph=pH(rhs(sol));

B/  equilibrium  '1a' and '1b' and '1c'
==============================

find [H(+)]: ?
===================================
'1a' : formed   (+)      => [H(+)] '1a'=[B(2-)]
'1b' : react       (-)      =>  [H(+)] '1b'=> [H2B]
'1c' : formed   (+)     =>  [H(+)] = [OH(-)]
===================================
[H(+)]  = formed -react= [B(2-)]+[OH(-)]-[H2B]

p8:H = B+OH-H2B;

Kw =[H]*[OH]  find : OH
-----------------------------------

p9:  Kw=(H)*(OH);
p9a:solve(p9,OH);

p10:subst([p2a[1],p3a[1],p9a[1]],p8);

find H: ?
=======

p11:solve(p10,H);

only positive solution physical meaning.
==================================

for i:1 thru 2 do(
if is(rhs(p11[i] )>0) = true then sol1: p11[i]);

sol1;

ph : of solution :
==============

p12:ph=pH(rhs(sol1));

set : [HB(-)] =HB= C

p12a:subst([HB=C],p12);

rem : put Kw=0 into p12a
=====================

p12b:subst([Kw = 0],p12a);

result :  same as 'p7'

p12c: subst([C=HB],p12b);

check : not take account  '1c'
=====

p12d: is(rhs(p12c) =rhs(p7));

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