kill(all)$

Maxima : reaction  Formula  , 'version 1.0' ,part: '3b'
peter.vlasschaert@gmail.com, 31/10/2019

reaction : find  ' Na balance equation '.
=============================

pp:b*H2SO4+a*NaOH=d*Na2SO4+c*H2O

reason : test , 'see below'   => 
=======================

see :part '3a': website
----------------------------------------------------------------------
Maxima : reaction  Formula  , 'version 1.0' ,part: '3a'
peter.vlasschaert@gmail.com, 30/10/2019
----------------------------------------------------------------------

pl : list of elements reaction
product :  el  = list of number of element(s)
              :  cf  = coef.before product       

lhs : reaction   'pp'
------------------------

lhs : Na , ' balance '

1e)  NaOH  (coef: before : a)
---------------

example : Na , ' balance '
pl :[Na,O,H,S]
el:[[Na,1],[O,1],[H,1]]
cf: a

bproducts(pl,el,cf):=block([],
bp:[],
for i:1 thru length(el)  do(
if pl =el[i][1]  then
bp:endcons(cf*el[i][2],bp)),
return(bp));

test : NaOH
=========

pl:[Na,O,H,S];
el:[[Na,1],[O,1],[H,1]];
cf:a;

p1:bproducts(pl[1],el,a);

rhs : reaction   'pp'
------------------------

rhs : Na , ' balance '

1e)  Na2SO4  (coef: before : d)
-------------------

example : Na , ' balance '
pl1 :[Na,O,H,S]
el2:[[Na,2],[S,1],[O,4]]
cf1: d

test : Na2SO4
===========

pl1:pl;
el1:[[Na,2],[S,1],[O,4]];
cf1: d;

p2:bproducts(pl1[1],el1,d);

find  Na :'balance', equation
---------------------------------------

p:map("=",p1,p2);

rem : general functions for all prodocts
======================================
example : b*H2SO4+a*NaOH=d*Na2SO4+c*H2O
=======================================

---------------------------------------------------------------------
pl :[Na,O,H,S]
---------------------------------------------------------------------
1e)  products                 (lhs : reaction,cf :{a,b})
2e)  reaction products  (rhs : reaction,cf :{c,d})
---------------------------------------------------------------------
el : list : 'see above' : {el,el1}
---------------------------------------------------------------------

function : ' bproducts'
=======================================
bproducts(pl,el,cf):=block([],
bp:[],
for i:1 thru length(el)  do(
if pl =el[i][1]  then
bp:endcons(cf*el[i][2],bp)),
return(bp));
======================================

combine : 'lhs' & 'rhs'
================
map("=",lhs,rhs)

type : lhs,rhs = > list