Possible Duplicate:
Strategies for simplifying math expressions
I have a mathematical expression parser which builds a tree to represent the expression. Say ,for example, I input 2+y+3+y
, the internal representation of this would be:
Now, we, as humans, can immediately see that 2+y+3+y = 2y + 5
. The tricky part for the computer that I see, is that if I would be standing on the left +
, I would have no idea that I have another addition to the right in the other branch - this doesn't matter when evaluating but when simplifying i don't see how this can be done nicely.
This is how the classes fit together:
I have tried to google this, but have found nothing that could help me here. Just some general waypoint, or an url or something at all would be appreciated
EDIT: Note that for the example i have only included addition. The parser supports expressions like : 1+2*(3^4-4/5*(1+2))