Generalized math generator.