@hackage chemical-equation0.0.1

Balance chemical equations

  • Installation

  • Dependencies (0)

  • Dependents (0)

  • Package Flags

      flint
       (off by default)

      Implementation using FLINT library

      lapack
       (off by default)

      Enable experimental implementation using LAPACK

Balance coefficients of chemical equations. You only give the list of reactants, the program will automatically find out on which side of the equation the reactants are placed. However, the first reactant is always placed on the left side and the order of all reactants is preserved as good as possible.

$ balance-chemical-equation C O2 CO2
C + O2 <=> CO2
$ balance-chemical-equation CH4 O2 CO2 H2O
CH4 + 2 O2 <=> CO2 + 2 H2O
$ balance-chemical-equation C8H18 O2 CO2 H2O
2 C8H18 + 25 O2 <=> 16 CO2 + 18 H2O

You may use a custom reaction arrow:

$ balance-chemical-equation --arrow="->" HCl NaOH NaCl H2O
HCl + NaOH -> NaCl + H2O

You may choose output of Unicode subscript and arrow characters:

$ balance-chemical-equation --unicode --arrow=$'\u21CC' N2 H2 NH3

If you mix multiple reactions then the program takes them apart, again. However, the resulting partial reactions may not be chemically sensible.

$ balance-chemical-equation C CH4 O2 CO2 H2O
2 C + 2 H2O <=> CH4 + CO2
C + O2 <=> CO2

The program knows nothing about chemistry and has no dictionary of elements. It cannot check whether the reactants are existing chemical substances or whether the reactions can happen in the real world. It accepts any capital letter followed by many lower-case letters as element symbols.

Mathematically speaking, balancing a reaction equation means computing the nullspace of an integer matrix, where all coefficients in the nullspace vectors are in turn integers. The matrix has a row for every element and a column for every reactant and every cell contains the multiplicity of an element in the according reactant. Our solver transforms this matrix to Reduced Row Echelon form, a generalization of Gauss elimination.