Solving Chemical Equations Part 2: Road to Python

If you are reading this, then you found something enticing about writing code to solve chemical equations. So, let’s have a look over everything.


Straight to the Breakdown

One way to think about coding is how we would do something without a computer. I started this in Part 1 (The Math). Now we will start to break this down and think about how to get the computer to do it for us.

There are two major parts to handle, the Math part and the Chemistry part. The Math part will be broken down into Row Echelon and the Homogeneous Solution. The Chemistry part will be broken down into Chemical Equations/Formulas and Parsing. We will also have to deal with going from the Chemistry and Math parts.

Let’s briefly go over each part and what we will be doing in them.

Row Echelon: This part will handle getting a matrix into Row Echelon form just like we talked about in Part 1. Here we will use the All Integer Algorithm

Chemical Formulas and Parsing: We will need a way to represent a chemical formula in the computer. A basic data structure will get the job done. Further, will we have to be able to go from a formula expressed in text form into this data structure

Chemical Equation and Matrix: After being able to store chemical formulas it is not that large of a step to get equations. Further, the next step after we have equations is to get ready to use the work we do in Row Echelon.

Homogeneous Solution: No, not a liquid where the solute components are uniformly distributed throughout the solvent. In Part 1, we created a System of Homogeneous Linear Equations and Solved it, that kind. This will be the last part. We will get a solution out of our Reduced Row Echelon matrix and get this into our chemical equation. Finally, we will create an internal check to make sure everything worked out.

The Plan

Each of the 4 above parts will have two posts. The first will be a fuller explanation of what we will be doing in the code but no actual code. The second post will be the code.

Feel free to use these posts however you wish. I just hope that you learn something from them.