home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0759.lha / ChemBalance / ChemBalance.doc < prev    next >
Text File  |  1992-11-06  |  9KB  |  246 lines

  1.  
  2.  
  3.  
  4.  
  5. In 1986, while I was tutoring a chemistry student on the art of balancing
  6. chemical equations, it occurred to me that the undetermined coefficients
  7. we were looking for were just algebraic unknowns that could be solved
  8. for by solving a system of linear equations for them. I soon figured
  9. out how to explain my quasi-algorithm to others, but I also felt that
  10. creating and distributing ChemBalance might encourage people to use the
  11. algebraic approach themselves.
  12.  
  13. This program, ChemBalance, v1.0, (Copyright 1992) is distributed free
  14. of charge to all who want to use it. Anyone may redistribute it as
  15. they please as long as due acknowledgement is given to the author and
  16. the program name and version number. I am expecting to put out improved
  17. versions based on proved weaknesses of the current program, so please
  18. feel free to write me at
  19.  
  20.      Patrick Reany                    Phone: (602) 995-1637
  21.      2408 W Myrtle #26
  22.      Phoenix  AZ  85021
  23.      USA
  24.  
  25. if you have any suggestions for improvements. What follows is a brief
  26. introduction to ChemBalance, but if you'd like a more thorough explanation,
  27. send me $3.00 and I'll send you a copy of the user's manual for ChemBalance.
  28. Also, please let me know if you'd be interested in improved versions
  29. of ChemBalance. I have already detected an annoyance of Chembalance crashing
  30. on 2.0 on specific problems that my 1.3 system handles without a hitch.
  31.  
  32. WARNING: This program will overwrite the files ram:list and
  33.          ram:mylist if you have them.
  34.  
  35. To run the program, you must have ARexx ready to go. With that done,
  36. put ChemBalance in ram: then open a shell or CLI and enter
  37. "rx ram:chembalance".
  38.  
  39. Before we start we need to establish some terminology.
  40.  
  41. 1) "RHS" = right hand side
  42. 2) "LHS" = left hand side
  43. 3) "total number of terms" means the sum of terms
  44.    from both sides of the equation
  45. 4) "eq" is short for equation
  46. 5) "coef" is short for coefficient
  47. 6) the "terminal coef" is the coef of the rightmost
  48.    term of the RHS
  49. 7) an eq that has at least as many elements as one less
  50.    than the total number of terms is said to be "regular"
  51. 8) if an eq is not regular it is said to be "nonregular"
  52. 9) "ansatz" means a trial solution
  53.  
  54.  
  55. Some of the syntax rules for ChemBalance are
  56.  
  57. 1) use "=" to separate LHS from RHS
  58. 2) use "_" to indicate a subscript
  59. 3) use "*" to preface a (generalized) hydration such as ...*6H_2O
  60.    or ...*NH_3
  61. 4) use any single capital or any single capital
  62.    followed by a small-case letter as an element
  63. 5) nested parentheses are not allowed
  64. 6) allowable input characters are all upper- and lower-case
  65.    letters, digits, "+","=","_","*"," ","(",")"
  66. 7) parentheses cannot follow an asterisk in a given term
  67. 8) use the "+" only as a binary operator
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. Some of the formation rules are
  75.  
  76. 1) each eq has exactly one equal sign
  77. 2) both sides of every eq have at least one term
  78. 3) each eq has at least one plus sign
  79.    (Thus each eq has at least 3 terms (total).)
  80. 4) an eq can have up to 7 terms
  81. 5) every element in each eq must be found on both sides
  82. 6) only 1 or 2 digits may immediately follow an asterisk
  83. 7) only 1, 2, or 3 digits may immediately follow an "_"
  84.    in input or in internal calculation
  85.  
  86.  
  87. ChemBalance does have its limitations. It won't do very simple stuff
  88. like O_2 + O_2 = O_3. It can't solve nonregular eq without your assistance.
  89. If anyone would like the program to do 8 terms total, please let me know.
  90.  
  91. Now for a bit of explanation. It's pretty obvious that every unbalanced
  92. eq that has a solution, has an infinite number of solutions derived
  93. by multiplying the solved eq thru by any positive integer you like.
  94. Thus the coef's are determined only up to their mutual ratios. We can derive
  95. a unique solution then (at least for regular eq's) by setting any one of
  96. the coef's to a fixed integer. For convenience ChemBalance always chooses
  97. to set the terminal coef equal to 1.
  98.  
  99. Let's try an example. Consider the eq
  100.  
  101.          CO + O_2 = CO_2
  102.  
  103. We put a variable in front of each term to be solved for, except that
  104. we put a 1 in front of the terminal term, thus giving us
  105.  
  106.           xCO + yO_2 = 1CO_2
  107.  
  108. Now, we have two unknowns, so we need two elements in the eq to solve for.
  109. We're in luck, since we have carbon, 'C', and oxygen, 'O'. (Thus we have
  110. a regular eq.) Next we balance the eq one element at a time!
  111.  
  112.   element    term1   term2   term3
  113.  
  114.     C:        1x   +   0y   =  1
  115.     O:        1x   +   2y   =  2
  116.  
  117. If you know some linear algebra you can solve these types of problems
  118. easily, perhaps by using Cramer's rule (which is what ChemBalance uses),
  119. though the present problem can be easily solved by inspection.
  120.  When you do you get
  121.  
  122.      x = 1,  y = 1/2
  123.  
  124. This fraction was introduced because of a mathematical object called
  125. a transformation determinant. It's there to keep us honest: If the
  126. transformation determinant is different from zero you get a solution.
  127. If it's equal to zero, you don't---at least you don't for the combination
  128. of elements you've chosen. In the present example it's do or die because
  129. there are no other elements to choose from.
  130.  
  131. Now, ChemBalance does not like to deal with fractions (a trait no doubt
  132. inherited from me), so it eliminates them by multiplying the balanced
  133. eq thru by the value of the transformation determinant. The form we get
  134. then is
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.   Lcoef_1 x Lterm_1 + ... + Lcoef_L x Lterm_L =
  143.           Rcoef_1 x Rterm_1 + ... + det x Rterm_(terminal_term#)
  144.  
  145. where all the coef's are integers. Well, we did have "unique" coef's
  146. but we changed them. That's OK. We may change them again to put the answer
  147. in "reduced" form, a form in which there is no prime integer which will
  148. evenly divide all the coef's. Actually, it's the existence of a unique
  149. reduced eq for regular eq's that is of importance to us.
  150.  
  151. ChemBalance finds the elements it needs to set up the simultaneous
  152. eq's in the elements_list. In the last problem it contained only 'C' and 'O'.
  153. Now let's look at the eq
  154.  
  155.           SO_2 + Cl_2 = SO_2Cl_2.
  156.  
  157. It will contain the three elements 'S O Cl' in the elements_list, and let's
  158. say, for the sake of argument, that they're in it in that particular order.
  159. Then when ChemBalance goes to form the 2 linear eq's it needs, by taking
  160. the two leftmost elements in the list, after "balancing" for 'S' and 'O'
  161. it will have completely ignored the second term on the left. This leads to
  162. a 'det = 0' problem. What ChemBalance does about this is fairly good in
  163. practice, but not perfect in theory.
  164.  
  165. The perfect thing to do is to make sure that ChemBalance takes at least one
  166. element to balance from each term, but for this version all it does is
  167. to cyclicly permute the elements_list and then try again. Don't laugh
  168. ---it seems to work very well. In this case the new list would be in the
  169. order 'O Cl S'. Then ChemBalance would balance for 'O' and 'Cl', which brings
  170. all terms to bear, and the solution is found.
  171.  
  172. Now let's show some typical forms for input.
  173.  
  174. ------->  (NH_4)_2Cr_2O_7 = Cr_2O_3 + H_2O + N_2
  175.  
  176. ------->  CoCl_2*6H_2O = CoCl_2*4H_2O + H_2O
  177.  
  178. To exit ChemBalance enter "quit" on the input line.
  179.  
  180. I wrote ChemBalance with the hope that people would use it, like it, and
  181. then try out its algebraic quasi-algorithm. It's good for instruction,
  182. but it's even better for actual use. Compare solving the following
  183. using ChemBalance to doing them yourself by any method you like.
  184.  
  185.  
  186. NaCl + H_2SO_4 + MnO_2 = Na_2SO_4 + MnSO_4 + H_2O + Cl_2
  187.  
  188. RCHO + CuSO_4 + NaOH = RCOONa + Cu_2O + Na_2SO_4 + H_2O
  189.  
  190. HCl + KMnO_4 = H_2O + KCl + MnCl_2 + Cl_2
  191.  
  192. C_7H_16 + O_2 = CO_2 + H_2O
  193.  
  194. C_12H_22O_11 + H_2SO_4 = C + H_2SO_4*H_2O
  195.  
  196. C_8H_18 + O_2 = CO_2 + CO + H_2O
  197.  
  198. KCN + FeCl_2 = K_4Fe(CN)_6 + KCl
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. The last thing I want to mention is that ChemBalance doesn't do windows
  208. and it doesn't do nonregular eq's.  Consider the nonregular eq:
  209.  
  210.      CH_4 + O_2 = C_2H_2 + CO + H_2
  211.  
  212. It has five terms but only three elements. If you want to get ChemBalance
  213. to solve it, you must help out by putting in at least two coef's yourself.
  214. If you try the ansatz
  215.  
  216.      CH_4 + 1O_2 = C_2H_2 + 2CO + H_2
  217.  
  218. for instance, it's true you've balanced for 'O', but you've also effectively
  219. (though not actually) knocked out 'O' from the elements_list, since the
  220. two fixed terms combine to form a single constant term, resulting in another
  221. nonregular eq having four terms but only two elements, 'C' and 'H',
  222. to use. So that didn't work.
  223.  
  224. But if we try to balance it for 'C', depending on how we do it, we could
  225. try the ansatz
  226.  
  227.      4CH_4 + O_2 = C_2H_2 + 2CO + H_2
  228.  
  229. This would give us the solution
  230.  
  231.      4CH_4 + O_2 = C_2H_2 + 2CO + 7H_2
  232.  
  233. But if we try the alternative ansatz for carbon
  234.  
  235.      6CH_4 + O_2 = 2C_2H_2 + 2CO + H_2
  236.  
  237. we get the different solution
  238.  
  239.      6CH_4 + O_2 = 2C_2H_2 + 2CO + 10H_2
  240.  
  241. What's neat about this solution is that it is not proportional to the
  242. previous solution. They are in fact nonequivalent! So strike one up for
  243. ChemBalance. By using ChemBalance I learned that nonregular eq's may have
  244. nonequivalent solutions, thus proving the didactic as well as computational
  245. value of the program.
  246.