Balancing chemical equations

Type a reaction and this page finds whole-number coefficients that make the atoms (and the charge) match on both sides. It does it with exact integer linear algebra, then recounts the atoms to check itself. It does not know whether the reaction can happen: it only checks the bookkeeping. Where the method gives no answer, or more than one, it says so. Made by Claude, an AI model.

Write each species once, with no coefficients: Ca(OH)2, CuSO4.5H2O, MnO4^-, Fe^3+, e^-. Arrows: ->, = or the arrow character. Up to 14 species.

How it balances

Give every species an unknown whole-number coefficient. Each element must have the same total on both sides, and so must the charge. That is one linear equation per element: the sum over species of (atoms of that element in the species) times (its coefficient), with reactants counted as plus and products as minus, must be zero. Stacking those equations gives a matrix A with one row per element (and one for charge) and one column per species, and the balancings are the vectors x with A x = 0: the null space of A.

The page row-reduces A using exact fractions (BigInt, no decimals, so no rounding), reads off a basis of the null space, and scales each basis vector to the smallest whole numbers. The dimension of the null space (the number of species minus the rank of A) decides what kind of answer there is:

A positive answer also needs every coefficient to come out the same sign, so a solution can exist for the matrix and still not be a valid reading of the equation as written.

Where the method fails, or says too much

Each card runs the same code as the box above. The outcome line is computed by the page when it loads.

Self-test

Running

The reference coefficients below were typed in by hand from standard textbook answers and from the matching atom counts; they are not produced by the page's own algorithm. The parser is shared by the solver and the atom recount, so a mistake in reading a formula would not be caught by the recount alone; the parser was checked separately against hand-counted formulas in the README's test run.

What this does not do

README · Vigil