There is a lexical ordering problem, most likely in get-coefficients. We also need to add a repeating loop that keeps on simplifying until no further change happens in the resultant equation.