Suppose only a set of chemical formulas is given. How can you find all mathematically possible chemical equations whose educts and products are only from this set?

Take e.g. the set $\{ \ce{C, H2, O2, N2, CO, CO2, H2O, NH3, NO, NO2, NO3}\}$.

Or consider e.g. the example in MathStackexchange: Finding all chemical equations (Linear Algebra).

To find all combinations and partial reactions between such given species by hand, is possibly incredibly tedious or near impossible for more complex chemical reaction systems.

I guess these methods are topic of Mathematical Chemistry, Computer Chemistry or Chemoinformatics.

  • 1
    $\begingroup$ Are you interested in the chemistry or the math of this? If it is the math, try to ask a question on StackExchange math that can be answered without knowing any chemistry. If you are interested in chemical reactions that actually happen, improve your current question to make clear what you are asking. $\endgroup$
    – Karsten
    Mar 23, 2019 at 16:18
  • 1
    $\begingroup$ @KarstenTheis I am interested in the math more than the chemistry, yes. However, Floatzel98 asked the same question on StackExchange maths and their post was also put on hold because it was deemed not mathematical enough. If this can't be answer in chemistry or maths forums, where can it be answered? Thank you $\endgroup$
    – AGuided94
    Mar 24, 2019 at 10:23
  • $\begingroup$ @IV_ just because it was closed as unclear and clarified, does not mean it is in line with our guidelines. Unclear was the reason that got the most votes. This question is still too broad. $\endgroup$
    – A.K.
    Mar 24, 2019 at 14:37
  • $\begingroup$ It isn't that broad of a question, it is just that everyone assumes stoichiometry is simple and thinks of reactions only in terms of the equilibrium constant and as a result, doesn't know the great breadth of math behind it. You should be reading this book by Smith & Missen. And so should everyone who thinks this question is too broad. If I remember correctly, Chapter 9 will be of great service to you. $\endgroup$
    – B. Kelly
    Mar 25, 2019 at 0:44

2 Answers 2


The purely combinatorial methods are a first step in modeling chemical reactions. They alone however cannot consider the possibility of the chemical reactions and the chemical stability of the reaction products.
$\ $


You can build all combinations of at least two formulas, all from the original set of given chemical formulas, and treat this as your set of given formulas. But you can also treat the whole original set of given chemical formulas.

I demonstrate the method with the first example given in the question:

$$\{ \ce{C, H2, N2, O2, CO, CO2, H2O, NH3, NO, NO2, NO3}\}$$

We set up one chemical equation with all chemical formulas that are in the given set. Let the stoichiometric factors in the chemical equation be denoted by $\nu$. Because we don't know which of the given substances will be educt and which of them will be product, we write the chemical equation without reaction arrow. Instead, a negative stoichiometric factor will later mark an educt, a positive a product:


We have to obey one of the first fundamental laws of chemistry: the Law of multiple proportions. To fulfill this law, the total sum of each chemical element in our chemical equation has to be $0$. And if ions are among our given chemical formulas, the total sum of all electric charges has to be $0$ also. But no electric charges are involved in our given example.

We will now build a mathematical model of our chemical problem.

For each of the given chemical elements, we have to set up its balance equation from our chemical equation above:

$\ce{C}:\ \ \ \nu_1+\nu_5+\nu_6=0$
$\ce{H}:\ \ \ 2\nu_2+2\nu_7+3\nu_8=0$
$\ce{N}:\ \ \ 2\nu_3+\nu_8+\nu_9+\nu_{10}+\nu_{11}=0$
$\ce{O}:\ \ \ 2\nu_4+\nu_5+2\nu_6+\nu_7+\nu_9+2\nu_{10}+3\nu_{11}=0$

This is a linear equation system. In the general case, too, a linear equation system results. It consists of the coefficients (the numbers above) and the stoichiometric factors $\nu_i$, which are sought. In our example, the equation system has 4 equations (the number of different chemical elements and the electric charge) and 11 unknowns (the number of chemical formulas in the given set).

Linear Algebra says how a linear equation system can be handled. We use here the matrix presentation.

Each of the 11 given chemical formulas is presented by a column vector which contains the frequency of occurence of each chemical element in the chemical formula in a prescribed order. Each of the 4 given chemical elements is presented by a row vector which contains the frequency of occurence of the chemical element in the chemical formulas in a prescribed order.

All 11 column vectors or all 4 raw vectors of the equation system are combined to give the coefficient matrix $A$. Our 11 wanted stoichiometric coefficients build the solution vector $x$, which is sought. The matrix representation of our linear equation system is than:

$$A\cdot x=\emptyset,$$

wherein $\emptyset$ is the zero column vector with 4 rows. It is written out:

$$\left( \begin{array}{} 1&0&0&0&1&1&0&0&0&0&0\\ 0&2&0&0&0&0&2&3&0&0&0\\ 0&0&2&0&0&0&0&1&1&1&1\\ 0&0&0&2&1&2&1&0&1&2&3 \end{array} \right) \cdot \left( \begin{array}{} \nu_1\\\nu_2\\\nu_3\\\nu_4\\\nu_5\\\nu_6\\\nu_7\\\nu_8\\\nu_9\\\nu_{10}\\\nu_{11} \end{array} \right) =\left(\begin{array}{}0\\0\\0\\0\end{array}\right)$$

The solution vector $x$ can be found by solving the linear equation system by methods of Linear Algebra.

The solution vector of our example is:

$$x=\left( \begin{array}{c} 2\nu_4+\nu_6+\nu_7+\nu_9+2\nu_{10}+3\nu_{11}\\-\nu_7+3\nu_3+\frac{3}{2}\nu_9+\frac{3}{2}\nu_{10}+\frac{3}{2}\nu_{11}\\\nu_3\\\nu_4\\-2\nu_4-2\nu_6-\nu_7-\nu_9-2\nu_{10}-3\nu_{11}\\\nu_6\\\nu_7\\-2\nu_3-\nu_9-\nu_{10}-\nu_{11}\\\nu_9\\\nu_{10}\\\nu_{11} \end{array} \right)$$

The different combinatorially possible chemical equations are obtained by choosing suitable values for the free variables $\nu_3,\nu_4,\nu_6,\nu_7,\nu_9,\nu_{10},\nu_{11}$.
$\ $


Further investigations could be made by searching the solutions that don't contain any other solution. That are the minimal solutions, that means the solutions that are linearly independent of the other solutions.

I found 663 chemical equations and 83 minimal solutions for the example above.

Generating only the minimal solutions in polynomial time needs particular algorithms:

Schay, G.; Pethö, Á.: Über die mathematischen Grundlagen der Stöchiometrie. Acta Chim. Acad. Sci. Hung. 32 (1962) 59-67

Pethö, Á.: Zur Theorie der Stöchiometrie Chemischer Reaktionssysteme. Wissenschaftl. Zeitschr. 6 (1964) 13-15

Pethö, Á.: Algebraic treatment of a class of chemical reactions in stoichiometry. Acta Chim. Acad. Sci. Hung. 54 (1967) 107-117

Pethö, Á.: On a class of solutions of algebraic homogeneous linear equations. Acta Math. Acad. Sci. Hung. 18 (1967) 19-23

Pethö, Á.: Kémiai reakciók egy osztályának algebrai elemzése. Magyar Kémiai Folyóirat 74 (1968) 488-491

Kumar, S.; Pethö, Á: Note on a combinatorial problem for the stoichiometry of chemical reactions. Int. Chem. Eng. 25 (1985) 767-769

Pethö, Á.: The linear relationship between stoichiometry and dimensional analysis. Chem. Eng. Technol. 13 (1990) 328-332

Szalkai, I.: Generating minimal reactions in stoichiometry using linear algebra. Hung. J. Ind. Chem. 19 (1991) 289-292
with a software code at the end of the article

Pethö, Á.: Mathematical discussion of the application of Hess‘s law. Hung. J. Ind. Chem. 21 (1993) 35-38

Pethö, Á.: Further remarks on the linear relationship between stoichiometry and dimensional analysis. Chem. Eng. Techn. Chem. Eng. Tech. 17 (1994) (1) 47-49

Pethö, Á.: Further remarks on the analogy between stoichiometry and dimensional analysis: The valuation operation. Hung. J. Ind. Chem. 23 (1995) 229-231

Laflamme, C.; Szalkai, I.: Counting simplexes in $R^n$. Hung. J. Ind. Chem. 23 (1995) 237-240

Laflamme, C.; and I. Szalkai, I.: Counting simplexes in $R^3$ Electron. J. Combin. 5 (1998) (1) #R40 11. Printed version in: J. Combin. 5 (1998) 597-607

Szalkai, I.: Handling multicomponent systems in $R^n$ I Theoretical results. J. Math. Chem. 25 (1999) 31-46

Szalkai, I.: On valuation operators in stoichiometry and in reaction syntheses. J. Math. Chem. 27 (2000) 377-386

Szalkai, I.: A new general algorithmic method in reaction syntheses using linear algebra. J. Math. Chem. 28 (2000) 1-34

Szalkai, B.; Szalkai, I.: Counting minimal reactions with specific conditions in $R^4$ J. Math. Chem. 49 (2011) 1071-1085

Szalkai, I.; Dósa, G; Tuza, Z.; Szalkai, B.: On minimal solutions of systems of linear equations with applications. Miskolc Mathematical Notes 13 (2012) (2) 529-541

Szalkai, B.; Szalkai, I.: Simplexes and their applications - A short survey. Miskolc Math. Notes 14 (2013) (1) 279-290

Szalkai, I.; Tuza, Z.: Minimum Number of Affine Simplexes of Given Dimension. Discr. Appl. Math. 180 (2015) 141-149

Szalkai, I.: Reakciómechanizmusok algoritmikus és matematikai vizsgálata (Algorithmic and Mathematical Examination of Reaction Mechanisms). PhD thesis, University of Pannonia, Veszprém, Hungary, 2014

Szalkai, I: An algorithmical and mathematical investigation of reactions. English extract of the author's PhD thesis, 2014
See the examples and references therein.

Tóth , J.: Reaction Kinetics: Exercises, Programs and Theorems. Springer, 2018
$ $


The answer above treats overall reactions. The underlying elementary reaction steps (elementary reactions) can be generated by working with the Ugi-Dugundji model: The chemical formulas are presented as graphs together with their graph matrices (Bond-Electron matrices (BE-matrices) and Reaction matrices (R-matrices)). The single elementary reaction steps will be generated successively by stepwise shifts of electrons or bonds in the set of given chemical formulas by stepwise shifting of single edges in the reaction matrix.

Ugi, I.; Gillespie, P.; Gillespie, C.: Chemistry, a finite metric topology - synthetic planning, an exercise in algebra. Trans. New York Acad. Sci. II 34 (1972) 416-432

Dugundji, J.; Ugi, I.: An algebraic model of constitutional chemistry as a basis for chemical computer programs. Top. Curr. Chem. 39 (1973) 19-64

Dugundji, J.; Gillespie, P. D.; Marquarding, D.; Ugi, I.; Ramirez, F.: Metric spaces and graphs representing the logical structure of chemistry. in: Chemical applications of graph theory. Balaban, A. T. (Ed.), Academic Press, London 1976, 107-174

Brandt, J.; Friedrich, J.; Gasteiger, J.; Jochum, C.; Wolfgang Schubert, W.; Ugi, I.: Computer programs for the deductive solution of chemical problems on the basis of a mathematical model of chemistry. in: Wipke, W. T.; Howe, W. J.: Computer-Assisted Organic Synthesis. American Chemical Society 1977, chapter 2, 33-59

Ugi, I.; Brandt, J.; Friedrich, J.; Gasteiger, J.; Jochum, C.; Lemmen, P.; Wolfgang Schubert, W.: The deductive solution of chemical problems by computer programs on the basis of a mathematical model of chemistry. Pure Appl. Chem. 50 (1978) 1303-1318

Ugi, I.; Brandt, J.; Friedrich, J.; Gasteiger, J.; Jochum, C.; Lemmen, P.; Schubert, W.: Computer Programs for the Deductive Solution of Chemical Problems on the Basis of a Mathematical Model of Chemistry. Pure Appl. Chem. 50 (1978) (11-12) 1303-1318

Behnke, C.; Bargon, J.: Computer-assisted topological analysis and completion of chemical reactions. J. Chem. Inf. Comput. Sci. 30 (1990) (3) 228-237

Ugi, I; Dengler, A.: The algebraic and graph theoretical completion of truncated reaction equations. J. Math. Chem. 9 (1992) (1) 1-10

  • $\begingroup$ If all the elements are part of the set of species, the solution is trivial: Write down how the compounds are made from the elements, giving $n$ balanced equations for $n$ compounds. Any linear combination of these will also be a valid balanced chemical equation (where you can cancel anything that appears both as reactant and product to arrive at e.g. $\ce{CO2 + NO -> CO + NO2}$). $\endgroup$
    – Karsten
    Mar 29, 2019 at 1:55
  • $\begingroup$ Here is the same solution vector with free variables matching the compounds, and coefficients for the elements showing the stoichiometry of the compounds: $$x=\left( \begin{array}{c} \nu_5 + \nu_6\\ \frac{1}{2}(2 \nu_7 + 3 \nu_8)\\ \frac{1}{2}(\nu_8 + \nu_9 + \nu_{10} + \nu_{11})\\ \frac{1}{2}(\nu_5 + 2\nu_6 + \nu_7 + \nu_9 + 2\nu_{10} + 3\nu_{11})\\ -\nu_5\\ -\nu_6\\ -\nu_7 \\ -\nu_8 \\ -\nu_9 \\ -\nu_{10}\\ -\nu_{11} \end{array} \right)$$ $\endgroup$
    – Karsten
    Mar 31, 2019 at 0:25

Only the chemical formulas of products and reactants of a chemical system are given. What mathematical methods can be used to determine all combinatorially possible chemical reactions between species of this reaction system?

Let's take the example mentioned in the question, plus dihydrogen to make a point:

$$\ce{CO2, C7H10N, H2O, O2, H2 and NO2}$$

We can represent product and reactant specides by vectors where the components of the vector represent the number of H, C, N and O in each. Thus,

(0,1,0,2) is $\ce{CO2}$,

(10,7,1,0) is $\ce{C7H10N}$,

(2,0,0,1) is $\ce{H2O}$,

(0,0,0,2) is $\ce{O2}$, and

(0,0,1,2) is $\ce{NO2}$.

A balanced chemical equation is a linear combination of these vectors with a sum of zero (negative coefficients indicate reactants, positive coefficients products). How many different balanced chemical equations exist for this set of molecules?

In a set of species that could potentially result in a balanced equation, every element has to appear at least twice. If I start with $\ce{C7H10N}$, it is clear I also need $\ce{CO2}$ (for C), $\ce{NO2}$ (for N) and either $\ce{H2O or H2}$ for H. Because we have to use $\ce{NO2 and CO2}$, we also need something with O. The two possible sets are:

$$\ce{C7H10N, CO2, NO2, H2O, and O2}$$ and $$\ce{C7H10N, CO2, NO2, H2, and O2}.$$

Also, you can use the set of $$\ce{H2O, H2, and O2}.$$

Here are the three balanced equations:

$$ \ce{C7H10N + 10.5 O2-> 7CO2 + NO2 + 5H2O}$$ $$ \ce{C7H10N + 8O2 -> 7CO2 + NO2 + 5H2}$$ $$ \ce{H2O -> H2 + 0.5 O2}$$

Using reaction 3, you can turn reaction 2 into reaction 1. You would have to refine the question a bit to specify as how many reactions this counts (probably 2 rather than 3). Obviously, multiplying all coefficients by a constant should not count as a new equation.

And how do these mathematical methods work?

I would probably start with writing a program that does the work using an algorithm like the one I have outlined. I would guess a hundred different species would be doable on a single CPU machine. The combinations will grow astronomically, but there are some good criteria to exclude many of the combinations. It does depend on how different the species are in their atomic composition. If they are all alkanes plus elemental carbon and elemental hydrogen, it looks like a huge number of reactions, but they all boil down to making each alkane from the elements, and then having linear combinations of the already balanced equations (again, not sure how you would count unique reactions).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.