I am looking to optimize a massive Chemistry and Physics program I have, and this one section of code is giving me difficulty. I found the routine from a program online, tweaked a few things, and it ran a little faster. I am to the point where this is about the only code I need to optimize.

The purpose of the code: Give the balancing numbers to an input chemical equation.

```
Input "Eq:",Str8
[[0→[E]
DelVar ADelVar B{0→EE
Str8+"+→Str8
inString(Ans,"=→C
DelVar U1→S
Repeat U=length(Str8
inString(Str8,"+",S→U
If Ans>C and S<C
C→U
sub(Str8,S,U-S→Str0
{0→A
Ans→E
DelVar NDelVar VDelVar WDelVar X0→Z
For(T,1,length(Str0
sub(Str0,T,1→Str9
If X
Then
inString("ieaouglrcnsbhdftypmkjqvmxz",Str9→Y
Z+1→Z
1-2(X≥30→ʟA(Z
30Y+min(27,X→ʟE(Z
End
If XY
Then
0→X
Else
inString("HCONBDAPSFGIKLMRTUVXYZWEJQ⁻-[e]﹢*",Str9→X
End
If Ans
Then
If N
Then
For(θ,(W≠0)V+Znot(W),Z
NʟA(θ→ʟA(θ
End
0→N
End
If W
Then
DelVar WDelVar V
End
Else
inString("0123456789",Str9
If Ans
Then
10N+Ans-1→N
Else
If N
Then
For(θ,(W≠0)V+Znot(W),Z
NʟA(θ→ʟA(θ
End
0→N
End
If W
Then
DelVar VDelVar W
Else
If V
Then
Str9=")→W
Else
(Z+1)(Str9="(→V
End
End
End
End
End
If X
Then
1-2(X≥30→ʟA(Z+1
min(27,X→ʟE(Z+1
Else
If N
Then
For(θ,(W≠0)V+Znot(W),Z
NʟA(θ→ʟA(θ
End
End
End
1-2(U>C→X
B+1→B
{max(1,A),B→dim([E]
For(θ,1,dim(ʟE
If A
Then
sum(cumSum(ʟEE=ʟE(θ
If Ans
Then
A+1-Ans
[E](Ans,B)+XʟA(θ→[E](Ans,B
Else
A+1→A
ʟE(θ→ʟEE(A
{A,B→dim([E]
XʟA(θ→[E](A,B
End
Else
ʟE(1→ʟEE(1
XʟA(1→[E](1,B
1→A
End
End
U+1→S
End
A+1→A
max(A,B+1→X
{A,X→dim([E]
1→[E](A,1
1→[E](A,X
Matr►list(rref([E]),X,ʟA
B→dim(ʟA
cumSum(1+0ʟA)not(not(fPart(ʟA→E
SortD(ʟE
sum(not(not(ʟE→dim(ʟE
For(θ,1,Ans
ʟA(ʟE(θ
If fPart(Ans
Then
{1,abs(Ans
Repeat ᴇ⁻9>Ans(2
Ans(2){1,fPart(Ans(1)/Ans(2
End
ʟAround(Ans(1)ˉ¹,0→A
End
End
Disp ʟA
Pause
```