in reply to How to evaluate a formula?

Maybe something in Perl and maths will give you inspiration?