kill(all)$

appendix : find elements of the reaction & new formula definition:display , version 1.0
peter.vlasschaert@gmail.com,04/11/2019

new formula : definition
==================

mq11:[[H,2],[S,z],[O,4],x1];

formula(m):=block([],
  mx:delete(last(m) ,m),
    mx:flatten(mx),
    mx:delete(z,mx),
    mp:concat(mx[1],mx[2]),
        for i:3 thru length(mx) do(
    mp:concat(mp,mx[i])
      ) ,
return(mp)
)$

formula(mq11);

=>  z=1 values 1

mq[1]:[[H,2],[S,z],[O,4],x1];
mq[2]:[[Na,z],[S,z],[O,4],x1];

general : elements before the reaction = elements after the reaction

number of products
================

np:2;

preparations of the lists : products
==========================

for i:1 thru np do(
   mq1[i]:delete (last(mq[i]),mq[i]) ,
   mq2[i] :flatten(mq1[i])
    )$

two products (example )
===================

find elements from product
=====================

mq2[1];
mq2[2];

ls:[]$
for j:1 thru length(mq2[1]) /2  do(
ls:endcons(mq2[1][2*j-1],ls));
ls;

find elements : np 'products'
=====================

ls1:[]$
for i:1 thru np do(
    for j:1 thru length(mq2[i]) /2  do(
    ls1:endcons(mq2[i][2*j-1],ls1),
    mq3[i] : ls1          
    ),
    ls1:[]
)$

mq3[1];
mq3[2];;

combine : mq3[i] , i=1..np
====================

ls2:[]$

for i:1 thru np do(
    ls2:endcons(mq3[i],ls2)
)$
ls2:flatten(ls2);

convert :  list  => to set
=================
rem : removes duplicates

ls3:setify(ls2);

convert :  set => to list
=================

ls4:listify(ls3);