DEV Community

TryAlgebra
TryAlgebra

Posted on

Term rewriting system + pattern matching now in TryAlgebra

I wrote the 'term rewriting system' this spring. However, to use it in TryAlgebra, I had to create a system in which users can set up their own custom parser to convert mathematical expressions into terms and back again. This is because TRS works on terms, which have specific rules.

The workflow now looks like this: you select the expression, right-click and choose the formula you want to apply from the list of allowed formulas.
List of allowed formulas

Click the arrow to perform the substitution.

Formula 1

Formula 2

This is where you write your formulas. You should create a separate file with this header and specify which TRS and parser to use. I know this may seem intimidating, but I'm working on ways to simplify the process. This is rather the prototype.

Formulas file

You also need to set up the algebra rules. These could be commutativity, distributivity, or your own rules.
Trs file

The scariest part is the parser itself. This will be given further consideration. Currently, you specify rewriting rules to rewrite a selected expression into a term. The parser has two modes: top-down parsing with a single substitution at each level and an exhaustive top-down parser.
My aim is to make the parsing routine as intuitive as possible so that users can experiment with it. This is why I abandoned the Backus–Naur Form approach. I want something simpler and more math syntax oriented. So this part will definitely be redone.

Parsing

The parsing file currently looks like this🫪.
The color indicates how the variable captures the symbols (one-multi, zero-multi or one).

Parsing2

Top comments (1)

Collapse
 
suppdevbot profile image
DEV SUPPORTS •
You need to verify your account.
Enter fullscreen mode Exit fullscreen mode

tr.ee/dev-to