\START92\ \COMMENT= \NAME=chemisui \FILE=CHEMISUI.89P () Prgm \(C)\Interactive Prgm, no args, see chemhelp Local re1,re2,re3,re4,re5,re6,re7,p1,p2,p3,p4,p5,p6,p7,chemeq,l,pr,c,t,i,f,v,j,k,y,res1,res2,res3,res4,res5,res6,res7,res8,res9,res10,res11,res12,res13 Lbl a Dialog Title "Reagents:" Request "?\x\",re1 Request "+?\x\",re2 Request "+?\x\",re3 Request "+?\x\",re4 Request "+?\x\",re5 Request "+?\x\",re6 Request "+?\x\",re7 EndDlog If ok=0:Return Dialog Title "Products:" Request "\->\?\x\",p1 Request "+?\x\",p2 Request "+?\x\",p3 Request "+?\x\",p4 Request "+?\x\",p5 Request "+?\x\",p6 Request "+?\x\",p7 EndDlog If ok=0:Return Lbl b ClrIO Disp "Transforming equation to","mathematical form..." exact(xx1*chem(re1)+xx2*chem(re2)+xx3*chem(re3)+xx4*chem(re4)+xx5*chem(re5)+xx6*chem(re6)+xx7*chem(re7)=xx8*chem(p1)+xx9*chem(p2)+xx10*chem(p3)+xx11*chem(p4)+xx12*chem(p5)+xx13*chem(p6)+xx14*chem(p7))\->\chemeq Disp " \check\","Computing coefficients..." {}\->\l If re1\!=\"":{xx1}\->\l If re2\!=\"":xx2\->\l[dim(l)+1] If re3\!=\"":xx3\->\l[dim(l)+1] If re4\!=\"":xx4\->\l[dim(l)+1] If re5\!=\"":xx5\->\l[dim(l)+1] If re6\!=\"":xx6\->\l[dim(l)+1] If re7\!=\"":xx7\->\l[dim(l)+1] If p1\!=\"":xx8\->\l[dim(l)+1] If p2\!=\"":xx9\->\l[dim(l)+1] If p3\!=\"":xx10\->\l[dim(l)+1] If p4\!=\"":xx11\->\l[dim(l)+1] If p5\!=\"":xx12\->\l[dim(l)+1] If p6\!=\"":xx13\->\l[dim(l)+1] If p7\!=\"":xx14\->\l[dim(l)+1] If dim(l)\<=\1 Then Dialog Title "Too few entries!" Text "Enter at least 1 reagent + 1 product!" EndDlog If ok=0 Then ClrIO DispHome Return EndIf Goto a EndIf Try exact(chemislv(chemeq,l))\->\chemeq Else ClrErr 1\->\c Dialog Title "No solution found!" Text "An error was encountered during" Text "the solving process." DropDown "Correct:",{"entries manually","Auto add e\(-)\","Auto add H+/H2O","Auto add H3O+/H2O","Auto add OH-/H2O"},c EndDlog If ok=0 Then ClrIO DispHome Return ElseIf c=1 Then Goto a ElseIf c=2 Then "e\(-)\"\->\t ElseIf c=3 Then "H+"\->\t ElseIf c=4 Then "H3O+"\->\t Else "OH-"\->\t EndIf If re2="" Then t\->\re2 ElseIf re3="" Then t\->\re3 ElseIf re4="" Then t\->\re4 ElseIf re5="" Then t\->\re5 ElseIf re6="" Then t\->\re6 ElseIf re7="" Then t\->\re7 EndIf If c\>=\3 Then If p2="" Then "H2O"\->\p2 ElseIf p3="" Then "H2O"\->\p3 ElseIf p4="" Then "H2O"\->\p4 ElseIf p5="" Then "H2O"\->\p5 ElseIf p6="" Then "H2O"\->\p6 ElseIf p7="" Then "H2O"\->\p7 EndIf EndIf Goto b EndTry Disp " \check\","Retransforming equation to","chemical form..." If inString(string(chemeq),"@")=0 Then ""\->\l ""\->\pr 1\->\f If re1\!=\"" Then If exact(xx1<0|chemeq):\(-)\1\->\f EndIf For i,1,7 "re"&string(exact(i))\->\t If #t\!=\"" Then exact(f*#("xx"&string(i))|chemeq)\->\c If c\>=\0 Then l&" + "&string(exact(c))&" "&#t\->\l Else pr&" + "&string(exact(\(-)\c))&" "&#t\->\pr EndIf EndIf EndFor For i,1,7 "p"&string(exact(i))\->\t If #t\!=\"" Then exact(f*#("xx"&string(i+7))|chemeq)\->\c If c\>=\0 Then pr&" + "&string(exact(c))&" "&#t\->\pr Else l&" + "&string(exact(\(-)\c))&" "&#t\->\l EndIf EndIf EndFor Lbl c mid(l,4)\->\l mid(pr,4)\->\pr l&" \->\ "&pr\->\chemeq Disp " \check\" ClrIO DispHome Dialog Title "Result:" Text left(chemeq,30) Text mid(chemeq,31,30) Text mid(chemeq,61,30) Text mid(chemeq,91,30) Text mid(chemeq,121,30) Text mid(chemeq,151,30) Text mid(chemeq,181,30) Text mid(chemeq,211,30) Request "scroll",chemeq EndDlog Else getvars(chemeq)\->\f {}\->\t For i,1,dim(f) If left(string(f[i]),1)="@":f[i]\->\t[dim(t)+1] EndFor If dim(t)=1 Then exact([[1][2][3][4][5][0][\(-)\1][\(-)\2][\(-)\3][\(-)\4][\(-)\5][1/2][\(-)\1/2][string(t[1])]])\->\f ElseIf dim(t)=2 Then exact([[1,1][1,2][1,3][2,1][2,2][2,3][3,1][3,2][3,3][\(-)\1,1][\(-)\1,2][1,\(-)\1][2,\(-)\1][string(t[1]),string(t[2])]])\->\f ElseIf dim(t)=3 Then exact([[1,1,1][1,1,2][1,2,1][1,2,2][2,1,1][2,1,2][2,2,1][2,2,2][\(-)\1,1,1][1,\(-)\1,1][1,1,\(-)\1][\(-)\1,\(-)\1,\(-)\1][0,0,0][string(t[1]),string(t[2]),string(t[3])]])\->\f Else 1\->\c Dialog Title "WARNING! Equation too complex!" Text "Your equation is too complex." Text "You will only get the general" Text "solution, which will contain 4 or" Text "more arbitrary constants." Text "" DropDown "Continue?",{"OK","correct entries"},c EndDlog If ok=0 Then ClrIO DispHome Return EndIf If c=2:Goto a ""\->\l ""\->\pr For i,1,7 "re"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i))|chemeq)\->\c l&" + "&string(exact(c))&" "&#t\->\l EndIf EndFor For i,1,7 "p"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i+7))|chemeq)\->\c pr&" + "&string(exact(c))&" "&#t\->\pr EndIf EndFor Goto c EndIf For y,1,13 ""\->\l ""\->\pr exact(expr("chemeq|"&f[14,1]&"="&string(f[y,1])))\->\c If colDim(f)\>=\2:exact(expr("c|"&f[14,2]&"="&string(f[y,2])))\->\c If colDim(f)=3:exact(expr("c|"&f[14,3]&"="&string(f[y,3])))\->\c exact(exp2matr(c))\->\c exact(0)\->\j For i,1,colDim(c) exact(gcd(j,c[2,i]))\->\j EndFor exact(matr2exp(mRow(1/j,c,2)))\->\c For i,1,7 "re"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i))|c)\->\v l&" + "&string(exact(v))&" "&#t\->\l EndIf EndFor For i,1,7 "p"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i+7))|c)\->\v pr&" + "&string(exact(v))&" "&#t\->\pr EndIf EndFor mid(l,4)\->\l mid(pr,4)\->\pr l&" \->\ "&pr\->\#("res"&string(exact(y))) EndFor ""\->\l ""\->\pr For i,1,7 "re"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i))|chemeq)\->\v l&" + "&string(exact(v))&" "&#t\->\l EndIf EndFor For i,1,7 "p"&string(exact(i))\->\t If #t\!=\"" Then exact(#("xx"&string(i+7)))|chemeq\->\v pr&" + "&string(exact(v))&" "&#t\->\pr EndIf EndFor mid(l,4)\->\l mid(pr,4)\->\pr l&" \->\ "&pr\->\chemeq Disp " \check\" ClrIO DispHome Dialog Title "Results (page 1/2):" Request "general",chemeq Request string(exact(f[1])),res1 Request string(exact(f[2])),res2 Request string(exact(f[3])),res3 Request string(exact(f[4])),res4 Request string(exact(f[5])),res5 Request string(exact(f[6])),res6 EndDlog Dialog Title "Results (page 2/2):" Request string(exact(f[7])),res7 Request string(exact(f[8])),res8 Request string(exact(f[9])),res9 Request string(exact(f[10])),res10 Request string(exact(f[11])),res11 Request string(exact(f[12])),res12 Request string(exact(f[13])),res13 EndDlog EndIf If ok=1 Then DelVar chemeq Goto a EndIf EndPrgm \STOP92\