
Chemical equation balancing: An integer programming approach - theideasmith
http://www.sciencedirect.com/science/article/pii/S0895717706000367
======
jamessb
A while ago I saw a paper in the _SIAM Review_ \- just one and a half pages of
maths, followed by

"Remark 2. The theorem proved here gives a completely new general method. It
generalizes all known results for balancing chemical equations cited
chronologically in references [1]–[125]."
[http://www.siam.org/journals/problems/downloadfiles/71-025s....](http://www.siam.org/journals/problems/downloadfiles/71-025s.pdf)

Reference 125 is to this paper.

~~~
octonion
This appears to be essentially equivalent to solving a linear system using the
Moore-Penrose pseudoinverse.
[https://en.m.wikipedia.org/wiki/Moore%E2%80%93Penrose_pseudo...](https://en.m.wikipedia.org/wiki/Moore%E2%80%93Penrose_pseudoinverse)

------
markc
My high-school chemistry teacher had a tradition of announcing "Automatic A"
challenges at the start of the term. One challenge was balancing a large
chemical equation. I recall it required solving something like 6 equations
with 6 unknowns. I solved it with multiple attempts and many pages of algebra,
and crucial hints at sticking points from my dad who had a Masters in
Chemistry. Easy A.

Another term, an A was promised for anyone turning in a "print out" of the
numbers from 1 to 1 million. Dad, coming to the rescue again, got me access to
a Microfilm printer at his work, and taught me just enough FORTRAN to generate
the list. (Yeah, short program, all about the formatting.) Another easy A. The
teacher's expression was priceless.

~~~
kaik
Did you enjoy working on those things?

The way you write it it seems like you think that it was stupid for a
professor to give you an A for such easy things. However I bet you learned a
lot.

~~~
markc
>seems like you think that it was stupid

Because I mentioned the expression on his face? I didn't intend to convey that
I was laughing at him for that - only that he was (understandably) surprised,
and I enjoyed that.

I don't think it was stupid. The chemical equation balancing was highly
relevant, and I did learn a lot from that. In some sense it was like "testing
out" of the class - by mastering a homework challenge that was much harder
than any of the class material.

The "million" challenge was interesting as well, and I did learn from it, but
not about Chemistry. I knew I had the A less than halfway into the term, so I
stopped doing chem homework. That was not optimal if the goal was to teach me
Chemistry. In that sense, the first challenge was probably better.

------
yummyfajitas
Amusingly, I discovered a method very similar to this in college. My method
was simpler - stick a 1 in front of one chemical, then you get an n x n linear
system of equations for the remaining compounds. Solve it, then figure out
what to multiply by to get an int solution. I suspect that my version isn't
stable, which I gather is the problem these guys are solving.

I was forbidden from using this method on the final, since it isn't the ad-hoc
method that was taught.

~~~
eru
How are you supposed to solve it, and how would they know?

~~~
yummyfajitas
Roughly speaking, this method: [http://www.wikihow.com/Balance-Chemical-
Equations](http://www.wikihow.com/Balance-Chemical-Equations)

Showing work is required, and if work contains a matrix then they'd just mark
it as zero.

~~~
nsajko
> Showing work is required, and if work contains a matrix then they'd just
> mark it as zero.

Ugh, this makes me so angry and resentful ...

~~~
irixusr
School's first objective is to make you obey.

------
openasocket
I might be missing something big, but isn't chemical equation balancing just a
system of linear Diophantine equations[1]? If it is, you should be able to
solve it in O(n^3) time by converting to Smith normal form[2]. Unlike Hermite
form, which the paper mentions, you don't need rational arithmetic or floating
points.

[1][https://en.wikipedia.org/wiki/Diophantine_equation#System_of...](https://en.wikipedia.org/wiki/Diophantine_equation#System_of_linear_Diophantine_equations)
[2][https://en.wikipedia.org/wiki/Smith_normal_form](https://en.wikipedia.org/wiki/Smith_normal_form)

~~~
sgeisenh
Yeah, I remember using gaussian elimination to solve them in high school
chemistry. My teacher taught us some guess and check method when it was
clearly just a system of linear equations. He gave us a "challenge" problem
with more variables than normal; much to his chagrin, I popped it into my
TI-89 and had a solution within a few minutes.

------
amelius
Does this mean that, conversely, we can solve integer programming problems by
doing chemical experiments?

~~~
kaik
Is chemical equation balancing NP-complete? hehe

~~~
GFK_of_xmaspast
Did you perhaps miss the third sentence of the abstract: "This special
algorithm is polynomial time O(n3), unlike the ILP approach, and uses the
widely available conventional floating-point arithmetic, obviating the need
for both rational arithmetic and multiple modulus residue arithmetic. "

------
theideasmith
My face lit up when I found this paper after beginning balancing chemical
equations in my 10th grade chemistry class this morning - so I thought I share
it with HN.

~~~
elcritch
That's awesome. Bonus points, did you implement it on a TI?

~~~
theideasmith
Not yet.

------
vondur
I'd always assumed that stoichiometry problems could be solved with linear
algebra, but was too lazy to investigate. Usually the problems assigned were
easy enough that you didn't have to work too hard to figure them out.

