While working on this I realised that quite a bit more can be moved out into our basic math representation; A variable taking on a bounded random value for instance, is something that we will have a use for in many problems. Also, I needed a simple mathematical expressions parser so the computer can calculate the problem result. This would not strictly be necessary, but is done in this way because then it will be very easy for a teacher to create new text problems that the system can use, simply by entering a problem string with variable names isntead of values, entering a formual such as (x1+2*x2)/2, specifying variable bounds and also supply a nice solution comment string.
This was an excellent reason to visit one of my favourite branches of computer science, namely the theory of formal languages. Simple mathematical expressions are ... simple, and can be parsed by a push-down automaton, like many programming languages. In my current implementation I lex and parse expressions involving addition, subtraction, multiplication, division, and parenthesis, by the following grammar (Backus Naur Form):
Expr ::= Term | Expr "+" Term | Expr "-" Term
Term ::= Atom | Term "*" Atom | Term "/" Atom
Atom ::= int | "(" Expr ")"
Special consideration must be taken for the case of division, something which I am working on right now.

