A yew.rs frontend for my equation solver.
View at https://arnecode.github.io/rust-calculator-yew/
Input a simple equation like
May or may not work for more complex equations.
I intend to improve the solution finding algorithm at some point in the future.
I have a list of transformations for the equations. For example
The solver works as a search over handwritten rewrite rules. Each rule has a pattern, a replacement, and sometimes extra conditions. When a rule matches part of the current equation, the matched pieces are substituted into the replacement to create a new candidate equation.
In other words, the solver does not follow one fixed algebra procedure. Instead, it keeps trying valid rewrites until it finds a form where the searched variable is isolated on one side of the equation.
The built-in rules include:
- direct rearrangements such as
x + a = b -> x = b - aandx * a = b -> x = b / a - algebraic rewrites such as
a * (b + c) -> a*b + a*c,a*b + a*c -> a * (b + c), anda*a -> a^2 - special solving rules for powers and quadratic forms
- a few extra symbolic rules, including some derivative rules, that use the same rewrite mechanism
Some rules only apply when restrictions are satisfied. For example, a rule may require that a matched expression is nonzero, that it does or does not contain the searched variable, or that an exponent is even or odd. If those conditions do not hold, the rule is skipped.
The solver also rewrites inside subexpressions, not just at the top level. That means it can simplify or transform part of a larger equation and then rebuild the full expression around that change.
At runtime, candidate equation forms are stored in a priority queue, and forms that have already been seen are skipped. On each step, the solver:
- takes the next candidate equation
- simplifies it if possible
- checks whether the searched variable is alone on one side
- if not, applies matching rewrite rules and adds the results back into the search
Some rewrites branch into multiple paths. For example, solving a power may introduce ±, which later splits into a positive and negative result. The solver keeps enough history to turn those branches back into a readable step-by-step solution tree.
So this is not a general-purpose theorem prover or CAS. It is a rule-based search through the equation forms reachable from the current rule set. When it works, the displayed solution steps correspond to actual rewrites and simplifications performed by the code.