kill(all)$

Maxima : reaction  Formula  'final reaction: from input '   , 'version 1.0' ,part: '3d'
peter.vlasschaert@gmail.com, 01/11/2019

see website:
part 3a,3b,3c

 = > begin definition

definition : formula.
==============

formula(v):=block([],
kaa:makelist(v[i][1],i,1,length(v)),
kbb:makelist(v[i][2],i,1,length(v)),
kbb1:makelist(if  v[i][2] =1 
    then  v[i][2] : "" else  v[i][2] : v[i][2],i,1,length(v)),
kcc1:maplist(concat,kaa,kbb1),
mpp:concat(kcc1[1],kcc1[2]),
for i:3 thru length(v) do(
mpp: concat(mpp,kcc1[i])),
    return(mpp)
)$         

definition : 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))$

 =>  end definition  

reaction :
=======

x2*H2SO4+x1*NaOH=y2*Na2SO4+y1*H2O

rem : remove ' read ' use  the key : 'Backspace'

general info : find coef of the  reaction
=============================
{x1,x2,.....}  &  {y1,y2,....}

print( "How to enter elements = [Na,O,H,S]")$

el : read( "elements in the reaction   :'shift' & 'enter'  = ")$

products : before reaction
====================

print(" number of products : integer")$

npb : read( "number products (before reaction)   :'shift' & 'enter'       = ")$

 => enter product  ( before reaction )
products : {NaOH,H2SO4}

qb[1]:[[Na,1],[O,1],[H,1],x1];
qb[2]:[[H,2],[S,1],[O,4],x2];

see : website
==========
part  3a,3b : definition : formula,bproducts

for i:1 thru npb do(
    qqb[i] :delete(last(qb[i]) ,qb[i])
);

qqb[1];
qqb[2];

use : definition
=>  formula,bproducts

br:makelist([formula(qqb[j]),last(qb[j])],j,1,npb);

br1:[sum(br[j][2]*br[j][1],j,1,npb)];

products : after reaction
==================

print(" number of products : integer")$

npa : read( "number products (after reaction)   :'shift' & 'enter'       = ")$

 => enter product  ( after reaction )
products : {H2O,Na2SO4}

qa[1]:[[H,2],[O,1],y1];
qa[2]:[[Na,2],[S,1],[O,4],y2];

see : website
==========
part  3a,3b : definition : formula,bproducts

for i:1 thru npa do(
    qqa[i] :delete(last(qa[i]) ,qa[i])
);

qqa[1];
qqa[2];

use : definition
=>  formula,bproducts

ar:makelist([formula(qqa[j]),last(qa[j])],j,1,npa);

ar1:[sum(ar[j][2]*ar[j][1],j,1,npa)];

final reaction
==========

use : definition 'formula' : see above

g1:br1[1] =ar1[1];

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

rem : part '3e' : 'final ' numbers {x1,x2,....} & {y1,y2,....}

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