DEV Community

Cover image for Algebra Expression Simplifier
Kira L
Kira L

Posted on • Updated on

Algebra Expression Simplifier

This is my relatively simple algebra expression simplifier! You can use it online here, or see the GitHub repository with explained code here.

I was having a lot of difficulty finding a free, moderately fast algebra simplifier online, so I decided to make my own. Hopefully it can ease the process of solving difficult mathematical problems (but please don't use it for cheating!). Simply enter an expression or equation, and you will get a step-by-step solution and simplified result.

For those interested in making their own algebra expression simplifier, I started by making a simple arithmetic simplifier following this tutorial. Then, I changed that code so that it could handle equations as well. I made this project for fun and by myself.

I am mainly posting it here because, even though I spent a lot of time debugging the algorithm, there are probably still bugs. If anyone finds a bug while using the program, please let me know. Hope you enjoy!



UPDATE: I fixed the negative multiplication bug. Now, expressions such as -1*-2 work.

Top comments (4)

Collapse
 
pentacular profile image
pentacular

Very nice.

You might make it a lot simpler by restructuring it as a set of more regular rewrite rules operating on a structured representation.

Collapse
 
i8sumpi profile image
Kira L

Thanks a ton for the advice! Do you mean that it would have been simpler first turn it into an expression tree, then simplify it?

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!