kill(all)$

maxima : chemical equation ,string display version, 'product reaction ',version 1.0a,part 1
peter.vlasschaert@gmail.com,04/02/2021

load :packages ,option.
==================

load(lrats)$ ratprint:false $  load(stringproc)$

intro about string in maxima.
=====================

t1:"Na Sg Ns";
t2:"   2   2   3";

tt1:charlist(t1);
tt2:charlist(t2);

concat(t1);
concat(t2);

slength(t1);
slength(t2);

 ascii or unicode.
=============

ascii(65);

ascii(32);/*space */

p1a:makelist(ascii(i),i,0,127);

`ascii': argument must be a non-negative integer less than 128.
================================================
--------------------------------------------------------------------------------------
Please use `unicode' for code points larger than 127.
 -- an error.
--------------------------------------------------------------------------------------

p1b:makelist(unicode(i),i,0,255);

p1c:makelist(ascii(i),i,31,33);

→ formula 1 : virtual molecule
=======================

t3:sconcat(Na,ascii(32),Sg,ascii(32),Ns);

t3a:stringp(t3);

t3b:sconcat(ascii(32),ascii(32),ascii(32),2,
            ascii(32),ascii(32),ascii(32),2,
            ascii(32),ascii(32),ascii(32),3);

t3;
t3b;

→ formula 2:  Sodium thiosulfate molecule
=================================

t4:sconcat(Na,ascii(32),S,ascii(32),O);

t4a:t3b:sconcat(ascii(32),ascii(32),ascii(32),2,
            ascii(32),ascii(32),2,
            ascii(32),ascii(32),3);

t4b:t4;
t4c:t4a;

display : chemical component of a reaction.
-----------------------------------------------------------

given:Sodium thiosulfate molecule
===========================

→  given :

p1:[Na,2,S,2,O,3];

→ list of all characters

p1a :simplode(p1);

p1b:charlist(p1a);

p1c:charlist(simplode(p1));

p1c1:length(p1c);

Truth table:
========
ref :https://en.wikipedia.org/wiki/Truth_table

--------------------------------------------------------------------------------------------------------------------------------------------------------------

p1d:makelist(alphacharp(p1c[k]),k,1,p1c1);

true = 1 or false =0 into  "p1d"

p1da:makelist(0,k,1,length(p1d));

→ values ≠ 1 ,or the zero's  or  ( false:  position in p1d list )

p1d1:makelist(if p1d[k]=true then p1da[k]:1 else p1da[k]:k,k,1,length(p1d));

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

→ delete : values from the list.

p1e:delete(1,p1d1);

→ find 
-----------------------------------------------------------------
sum = 1 →  ascii(32) ,ascii(32)
sum = 2  → ascii(32),ascii(32),ascii(32)
-----------------------------------------------------------------
see :t4a,'see above'
-----------------------------------------------------------------

→ init :pos

pos:makelist(0,i,1,length(p1)/2);

pos[1]:sum(p1d1[i],i,1,p1e[1]-1)$
for k:2 thru length(pos) do(
pos[k]:sum(p1d1[i],i,p1e[k-1]+1,p1e[k]-1)
)$

grind(pos);

→ sum= 1 or sum =2

pos;

two parts

→ construct : (first line of the component)
==========

⇒≫ 't4b'

p2:[];

for i:1 thru length(p1) do(
 if oddp(i) then     
p2:endcons(p1[i],p2)
 else
p2:endcons(ascii(32),p2)    
);

p2;

p2a:simplode(p2);

p2b:stringp(p2a);

p2c1:p2a;
p2c2:t4c;

→ construct :(second line of the component)
==========

⇒≫ 't4a', use pos , list , 'from above'

npos:[];

for i:1 thru 3 do(
if pos[i] = 1 then 
    npos:endcons([ascii(32),ascii(32),p1[2*i]],npos),
if pos[i] = 2 then 
    npos:endcons([ascii(32),ascii(32),ascii(32),p1[2*i]],npos)    
);

npos : 1e)   step : flatten       , multiple [[[]]] →[]
            2e)   step:  simplode ,  list                → string

npos:simplode(flatten(npos));

combination : first line & second line
--------------------------------------------------

final result
========

→  output : direct from 'p1'.
-------------------------------------

p4a:p2a;
p4b:npos;

→ change display setting.
------------------------------------

display : ascii.
-------------------

set_display('ascii);

set_display('ascii);

concat(p4a,newline,p4b);

display : orginal.
----------------------

set_display('xml);

disp(p4a,p4b)$