nicolewhite / algebra.js

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

Divide with expressions? #76

Open viktorstrate opened 7 years ago

viktorstrate commented 7 years ago

Could it be possible to make expressions dividable with other expressions. Eg

new Expression(1).divide(new Expression('x'))

If I try this now I get

TypeError: Invalid Argument (x): Divisor must be of type Fraction or Integer.

And make variables remove them self, like this

var upper = new Expression('x').multiply(2)
var lower = new Expression('x').multiply(4)

var result = upper.divide(lower) // expected result: 1/2

Edit: replaced .add() with .multiply(), thanks @Benjadahl

pvskand commented 7 years ago

I guess no! As of now division of expressions with expressions is not implemented!

Benjadahl commented 7 years ago

Note: (2 + x)/(4 + x) != 1/2

It would be (2 x)/(4 x)

Unless I am terribly bad at math :P

viktorstrate commented 7 years ago

You're right my bad, I've updated the original post.

KhubaibQaiser commented 6 years ago

Facing same issue. Any update on this?

IsaMorphic commented 5 years ago

I have this implemented to a certain extent, although I'm not actively working on it. Check it out here: https://github.com/yodadude2003/algebra.js