kill(all)$

Maxima : How to use activity & pHa for weak acid. version 1.0
peter.vlasschaert@gmail.com,26/08/2019

load packages
============

load(lrats);

activity: coef  :  a=γ*C
=================
value :  0 ≤γ ≤ 1
a : activity
C : concentration

How to create a rule
----------------------------

p1:matchdeclare(_k,true);

rem : rule will be activ until destroyed.

p2:tellsimpafter(a[_k],γ[_k] *C[_k] );                             

p3:rules;

rem : pattern matching

equilibruim :  HAc = H(+)+Ac(-)  , activity : notation
=>  ka[a]  , acid equilibrium constant
first        : a =>  activity
second  : a =>  acid

p4:ka[a]=(a[H\+]*a[Ac\-])/a[HAc];

rem : index notation with use of tensor notation.(see website),write down 
=> Chemical  Formula

p5:[a[X\+m],a[XX\-n]];

when value : different + or - ,see 

How to calculate : pHa 
-------------------------------
pH : takes in account activity

Definition  pHa
============

p6:pHa=ev( -log(a[H\+]),nouns)/log(10);

calculation : pHa ( weak acid)
=======================

principal : weak acid :  HA = H(+)+ A(-)
general : H(+) = A(-)

How to use  : a[H\+]

p7: a[Ac\-] = a[H\+] ;

use : p4

p7a1:subst([p7],p4);

p7a2:lratsubst([p7],p4);

rem : subst doesn't work we use lratsubst

1e method : no result
-----------------------------

p7b1: a[H\+] ;

p7b2:solve(p7a2,p7b1);

2e method : 
-----------------

p7c1:p7b1 = x;

p7c1a:rhs(p7c1) = lhs(p7c1);

p7c2:lratsubst([p7c1],p7a2);

p7c3:solve(p7c2,x);

rem : concentration be only positiv,hold 'p7c4b'

p7c4a:p7c3[1];
p7c4b:p7c3[2];

p7c5:subst([p7c1a],p7c4b);

use : 'p6'

p7c6:subst([p7c5],p6);

p7c7:p7c6,logexpand =super;

p7c8:expand(p7c7);

rem : use (args)
============

p8a:lhs(p7c8);
p8b:args(part(p7c8,2));

p8c:sum(p8b[i],i,2,3);

p8c1:logcontract(p8c);

final result : output
-------------------------

p9:p8a = p8b[1] + p8c1;

p9a:factor(p9);

p9b:float(p9a);

rem : rules to destroy

rules;

rem : delete all rules defined

clear_rules();

rules;

test :

p9c: a[H\+] ;

see difference between : p9c & p7b1