nicolewhite / algebra.js

Build, display, and solve algebraic equations.
http://algebra.js.org
MIT License
1.34k stars 111 forks source link

Add Rational Expressions #95

Open IsaMorphic opened 5 years ago

IsaMorphic commented 5 years ago

For a long time many people have reported the lack of functionality regarding the division of expressions.
See these issues:

92

90

82

76

At first I tried to make rational expressions more recursive in nature, (i.e rational expression inside of rational expression), but decided against it as those types of expressions can be easily simplified. The new feature does break some tests regarding dividing expressions, and new tests have yet to be created as well. I apologize if there are any formatting issues, I tried to clean up the diff to make it as consistient as possible. In fact, this is my first time contributing to a project. I'm open to any suggestions or comments (so long that they are constructive in nature 😁).

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-2.9%) to 95.174% when pulling 63919dadc56cf47a676f88aa7cee4eff61b790f8 on yodadude2003:master into 8c74b87dca81a7ea74a47e08bc5a0838805124e0 on nicolewhite:master.

IsaMorphic commented 5 years ago

Just removed some unnecessary commits and squashed some smaller ones together

IsaMorphic commented 5 years ago

Status update: The responsibilities and role of the Rational class has changed. Instead of being implemented at the term level (inside of expressions), Rationals now sit above Expressions in the library's hierarchy. They are still used to represent division of two expressions, its just that now Rationals contain expressions v.s expressions contain terms/rationals. I made this change to avoid having expressions inside of expressions, as it not only makes a mess of object types to deal with but it also makes expressions recursive and therefore more difficult to solve when put inside equations. Expressions now function exactly the same as they did before I made any changes to the base library, so long as they do not undergo any operations with Rationals (with the exception of division). Any time a Rational gets involved in adding, subtracting, multiplying, or dividing Expressions, the Expression mutates into a Rational. Also, Rationals can now be initialized in any way that an expression can. Variable names, Terms, Variable objects, constants, and all. A rational can be initialized with one or two expression/expression-compatible objects. If only one object is given, the rational's numerator is initialized to that object, and the denominator is initialized to one. Otherwise, the first argument is assigned to the numerator and the second is assigned to the denominator. Didn't expect to be writing a book, but I guess I've made a lot of changes 😆. Thats all for now.
Edit: forgot to mention that Expressions will also mutate into Rationals if they are divided by multinomial Expressions.