kill(all)$

appendix : maxima : how change the list of the input products : computation , 'version 1.0'
peter.vlasschaert@gmail.com,06/11/2019.

input product:  =>   read=> both keys  shift & enter
======================================
see 'example' : below after definition : 'inprodre'

l:[Na,1,O,1,H,1];

lz:[];

convert 1:
=======

for i:1 thru length(l)/2 do(
lz:endcons([l[2*i-1],l[2*i]],lz));
lz;

use : coef: (before , ' products')
==========================
products                 :  {x1,x2,x3,.....}
reaction products  :  {y1,y2,y3,.....}

;nf1:length(lz);

empty list : 
=======

l1:[];
for i:1 thru length(lz)+1 do(
l1:endcons(0,l1));
l1;

fill empty list
=========

for i:1 thru nf1 do(
    l1[i]:lz[i]
);
l1[nf1+1]:x1;

l1;

convert  2 : 1 -> z
==============

for i:1 thru nf1 do(
  if  l1[i] [2] = 1 then l1[i] [2] :z
)$

l1;

transform input : definition : inprodre
                            ================
needed : computations to find coef 
products                 :  {x1,x2,x3,.....}.
reaction products  :  {y1,y2,y3,.....}.

inprodre(ll,xx):=block([lza:[] ,ll1:[] ],
for i:1 thru length(l)/2 do(
lza:endcons([ll[2*i-1],ll[2*i]],lza)),
nf1:length(lza),
for i:1 thru nf1+1 do(
ll1:endcons(0,ll1) ),
for i:1 thru nf1 do(
    ll1[i]:lza[i]
),
ll1[nf1+1]:xx,
 for i:1 thru nf1 do(
  if  ll1[i] [2] = 1 then ll1[i] [2] :z
),return(ll1)
)$   

example 1:
========

l;

inprodre(l,x1);

example2
========

ll2:[H,2,S,1,O,4];
inprodre(ll2,x2);

conversion needed because : enter ' maxima' allowed
a single list .

enter :test  (read => both keys together : 'shift' & 'enter' )
===========================================

opm :the remove list after the 'read' with  => 'key' =   'Backspace'

ll3:read( " product (before reaction)   :'shift' & 'enter'       = ")$

m:inprodre(ll3,x3);

rem : 
------

 How to use  =>  'maxima command' => firstn'
====================================

m1:firstn(%,3);

m2:firstn(m,nf1+1);

m3:firstn(m,2);