Activity

Draedon

Mostly finished up all the simplification rules in Cohen’s book. Tons of bug fixes and some more features, such as automatic factorial evaluation (as seen in the screenshot) and a few index laws (not pictured, sadly). I’m just missing fraction evaluation (e.g., a fraction + a normal number) but that can be done relatively quickly. Once that’s done, I’ll go down the road of code clean-up for a few hours, because it’s currently a mess. Most of the simplification logic is inside of one class in a file with a ton of large methods… the file already exceeds 400 lines so once I’m done it’ll probably be 6-700 LOC across a few files.

Attachment
0
Draedon

Finally the beginnings of some sort of simplification! Following Joel S. Cohen’s Computer Algebra and Symbolic Computation, Elementary Algorithms rules for a simplified structure of algebraic expressions has been a bit challenging given my current codebase. It also contains some unique rules that I wouldn’t have thought of. For example, it doesn’t allow negative signs outside of a number’s literal value. Something like -x would be reduced (internally) to -1 * x, which is interesting but makes complete sense.

Attachment
0
Draedon

Turns out I had a bunch of bugs regarding order of operations and operator precedence, so I went back and fixed them all (hopefully). These include exponents that were evaluated left to right, factorials that weren’t even detected, negative signs having precedence over exponents for some reason (e.g., -3^2 -> (-3)^2 -> 9 instead of -9) and so on. In the screenshot you can see some test cases it now successfully passes.

Attachment
0
Draedon

Parsing of expressions! Basically, this just turns the list of tokens created by the Lexer into a Syntax Tree. It uses a set of grammar rules to handle stuff like operator precedence (a.k.a. order of operations in the math world) and will throw errors when necessary. Internally, it does this via Recursive Descent Parsing, which, contrary to its name, starts at the lowest precedence expression and recursively walks up to expressions with higher and higher precedence. Now, most of the interpreter stuff is complete and I just need to implement the state machine (to hold variables), built in constants and functions, evaluation of this syntax tree, and all the actual CAS stuff

Attachment
1

Comments

Draedon
Draedon 3 months ago

oml can flavourtown stop duplicating my screenshots?

Draedon

Added a bunch more token types and some super simple error handling in the lexer. Next up is probably parsing and adding a Syntax Tree, which could definitely take a while.

Attachment
Attachment
0
Draedon

Perhaps the most barebones lexer ever made. Currently it only supports defining variables and settings their value to a number. Will be heavily expanded on in the future, with operators like +-*/, proper error handling, functions, parentheses, and everything you’d expect in a lexer for a CAS.

Attachment
1

Comments

Draedon
Draedon 3 months ago

Not sure why the screenshot got uploaded twice…