DEV Community

Discussion on: Algebra Expression Simplifier

Collapse
 
pentacular profile image
pentacular • Edited

Yes, I think so.

Perhaps even a representation as simple as:

['*', 3, ['+', 3, 2]]

Then you can imagine a recursive walk over that expression using a rule that matches

[op('+'), number, number]

and rewrites it to the sum, reducing that to

['*', 3, 5]

, and another rule like

[op('*'), number, number]

and reduces that to 15, and then you're done.

Thread Thread
 
i8sumpi profile image
Kira L

Great idea, thanks!