Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't represent this equation with mathjs: a + b = b + a #1364

Closed
ashleydavis opened this issue Dec 21, 2018 · 5 comments
Closed

Can't represent this equation with mathjs: a + b = b + a #1364

ashleydavis opened this issue Dec 21, 2018 · 5 comments
Labels

Comments

@ashleydavis
Copy link

ashleydavis commented Dec 21, 2018

Hi, Mathjs is awesome.

I'm having a problem with a particular equation that Mathjs doesn't seem to support.

I need to use the AST produced, here's some example code:

const rootNode = math.parse("a + b = b + a");

I get this error:

Uncaught SyntaxError: Invalid left hand side of assignment operator = (char 7)
    at createSyntaxError (parse.js:1682)
    at parseAssignment (parse.js:638)
    at parseBlock (parse.js:553)
    at parseStart (parse.js:523)
    at parse (parse.js:69)
    at Object.parse (typed-function.js:1085)

Is there a way to have Mathjs handle this type of equation? Or is it just not supported?

Thanks!

@josdejong
Copy link
Owner

Such equations are indeed not supported. It will be supported when we add support for a solver I think, see #38, though there is no one working on this yet.

@ChristopherChudzicki
Copy link
Contributor

The error message offers a clue: "Invalid left hand side of assignment operator =". The single equals sign is assignment, not equality. I think you'll get what you want if you use double equals:

const rootNode = math.parse("a + b == b + a")

Then you should be able to manipulate the parse tree.

@ashleydavis
Copy link
Author

@josdejong I've made a copy of mathjs code and I've modified it produce a 'binary operator' instead of the normal assigment node. That fits my need and it was easy to update the code to work the way I wanted. Thanks for your effort on this.

@ChristopherChudzicki Thanks for the advice Chris, I'm actually making a maths visualizer be used by non-programers so I can't rely on them understanding the difference between = and ==.

My maths visualizer simplifies a formula and shows the working out. Just a fun little project to help people understand how algebraic transformations work. Once it's finished I'll send you a link!

@josdejong
Copy link
Owner

👍

@josdejong
Copy link
Owner

will close this issue now, feel free to reopen if needed. Sharing your visualizer would be cool of course :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants