kill(all)$

Display : chemical formula,reaction 'itensor' ,version 1.0
peter.vlasschaert@gmail.com,12/05/2019

load packages.

load("itensor")$

p1:ishow(a([i,j],[k]))$

p2a:part(p1,0);

p2b:args(p1);

Display chemical formula
=====================

H2SO4 ? 

p3:ishow(H([2])*SO([4]))$

p4:args(p3);

p5a:part(p4[1],0);

p5a1:args(p4)[1];

p5a2:part(p5a1,1)[1];

p6a:part(p4[2],0);

p6a1:args(p4)[2];

p6a2:part(p6a1,1)[1];

number of atoms ( = chemical)

p7:ishow(H([2])*S([1])*O([4]))$

p7a:args(p7);

elements : periodic system.
------------------------------------------

p7a1:part(p7a[1],0);
p7a2:part(p7a[2],0);
p7a3:part(p7a[3],0);

number of atoms for each element.
-----------------------------------------------------

p7a11:part(p7a[1],1)[1];
p7a22:part(p7a[2],1)[1];
p7a33:part(p7a[3],1)[1];

Na2S2O3 : ?

display : formula
-------------------------

p8:ishow(Na([2])*S([2])*O([3]))$

analysis : formula
---------------------------

p8a:args(p8);

1e)  elements :
============

p8a1:part(p8a[1],0);
p8a2:part(p8a[2],0);
p8a3:part(p8a[3],0);

 2e) number of atoms for each element  :
==================================

p8a11:part(p8a[1],1)[1];
p8a22:part(p8a[2],1)[1];
p8a33:part(p8a[3],1)[1];

Fe(CN)(6)(4-)  =>  K4Fe(CN)6  ?

display : formula
-------------------------

ion: anion

p9:ishow(Fe([1])*CN([6],[-4]))$

analysis : formula
---------------------------

p9a:args(p9);

1e)  elements :
============

p9a1:part(p9a[1],0);
p9a2:part(p9a[2],0);

 2e) number of atoms for each element  :
==================================

p9a11:part(p9a[1],1)[1];
p9a22:part(p9a[2],1)[1];

3e) how to find charge :
====================

p9c:part(p9a[2],2)[1];

rem : how much atoms C,N  ? 

p10:ishow(Fe([1])*CN([6],[-4]))$

we need put in : formula without charge : full formula.
---------------------------------------------------------------------------------
K4Fe1C6N6

p10a:ishow(K([4])*Fe([1])*C([6])*N([6]));

analysis : formula
---------------------------

p10b:args(p10a);

p10ba:length(p10b);

1e)  elements :
============

p10b1:part(p10b[1],0);
p10b2:part(p10b[2],0);
p10b3:part(p10b[3],0);
p10b4:part(p10b[p10ba],0);

p10b5:[p10b1,p10b2,p10b3,p10b4];

2e) number of atoms for each element  :
==================================

p10b11:part(p10b[1],1)[1];
p10b22:part(p10b[2],1)[1];
p10b33:part(p10b[3],1)[1];
p10b44:part(p10b[4],1)[1];

p10b55:[p10b11,p10b22,p10b33,p10b44];

how display reaction :
==================

p11:ishow(Na*OH+H([2])*SO([4])) $

p11a:ishow(p11) = ishow(Na([2])*SO([4])+H([2])*O)$

final result
=========

p12:ishow(p11 = rhs(p11a))$

copy : 'p12' with select

a*Na*OH+b*H[2]*SO[4]=c*H[2]*O+d*Na[2]*SO[4]

p13:a*Na*OH+b*H[2]*SO[4]=c*H[2]*O+d*Na[2]*SO[4];

analyse : reaction 
---------------------------

p12b:args(p13);

p12b1:p12b[1];
p12b2:p12b[2];

We first Make list all elements in reaction : 'p12'
=======================================

p14:[Na,O,H,S];

p15:length(p14);

p14a:p14[1];
p14b:p14[2];
p14c:p14[3];
p14d:p14[4];

analysis
-------------

lhs : reaction
===========

p16:args(p12b)[1];

p16a1:part(p16,1);
p16a2:part(p16,2);

p16b1:args(p16a1);
p16b2:args(p16a2);

rhs : reaction
===========

p17:args(p12b)[2];

p17a1:part(p17,1);
p17a2:part(p17,2);

p17b1:args(p17a1);
p17b2:args(p17a2);

manuel : build equations (to solve)
=============================

[Na,O,H,S]  =>  a,b,c,d  '4 equations'

p18:a*p14a = 2*d*p14a;
p19:4*b *p14b + a*p14b = 4*d*p14b +c*p14b;
p20:2*b*p14c +a*p14c= 2*c*p14c;
p21:b*p14d = d*p14d;

p22:to_poly_solve([p18,p19,p20,p21], [a,b,c,d]);

p22a:part(p22,1);

p22b:subst([%c2=2],p22a);

subst into reaction : 'p13'
======================

p23:subst(p22b,p13);