For fun, I would like to design a mathematical expression evaluator, with variables. It could simplify the entered expressions by factoring them, reducing them to a sum of simple fractions, calculating them, grouping them, etc...
To give an example, if the user enters the following expression:
(in a code format, of course, not in Latex)
I wish my program could return the following simplification, which is the maximum simplification that can be made in this case:
To achieve this result, you need a parser and an AST. My question concerns the handling of the AST. Indeed, the idea I have to get such an output is to browse the AST and operate on the different expressions via rewriting rules of the latter. Nevertheless, this approach seems to me really long and tedious (moreover, to simplify the implementation, it would be necessary to use recursion, but the performances do not bother me). Thanks to the properties of powers, we could generalize a lot of rewriting rules, so an extra pass would be necessary to rewrite the expression of the example into this equivalent expression:
In this case, however, this rewriting does not seem relevant. So my question is what interesting methods of simplification exist that I could use to achieve the style of result presented. I'm not talking about algorithms to compute some expressions in optimal times, but really about methods to simplify expressions encoded in an AST.