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

fraction with unary minus operator multiplying a variable produce a different tree #1778

Closed
mt4c opened this issue Mar 17, 2020 · 2 comments
Closed

Comments

@mt4c
Copy link

mt4c commented Mar 17, 2020

console.log(JSON.stringify(math.parse('4/3x')));

results in

{"mathjs":"OperatorNode","op":"*","fn":"multiply","args":[{"mathjs":"OperatorNode","op":"/","fn":"divide","args":[{"mathjs":"ConstantNode","value":4},{"mathjs":"ConstantNode","value":3}],"implicit":false},{"mathjs":"SymbolNode","name":"x"}],"implicit":true}

console.log(JSON.stringify(math.parse('+4/3x')));
console.log(JSON.stringify(math.parse('-4/3x')));

results in

{"mathjs":"OperatorNode","op":"/","fn":"divide","args":[{"mathjs":"OperatorNode","op":"+","fn":"unaryPlus","args":[{"mathjs":"ConstantNode","value":4}],"implicit":false},{"mathjs":"OperatorNode","op":"*","fn":"multiply","args":[{"mathjs":"ConstantNode","value":3},{"mathjs":"SymbolNode","name":"x"}],"implicit":true}],"implicit":false}

{"mathjs":"OperatorNode","op":"/","fn":"divide","args":[{"mathjs":"OperatorNode","op":"-","fn":"unaryMinus","args":[{"mathjs":"ConstantNode","value":4}],"implicit":false},{"mathjs":"OperatorNode","op":"*","fn":"multiply","args":[{"mathjs":"ConstantNode","value":3},{"mathjs":"SymbolNode","name":"x"}],"implicit":true}],"implicit":false}

the first expression was parsed as (4/3)x

the next expressions were parsed as 4/(3x) and -4/(3x)

Why do the unary operators make the differences

@cshaa
Copy link
Collaborator

cshaa commented Mar 19, 2020

This is a known bug in the parser, see #1431.

@josdejong
Copy link
Owner

Let's continue any discussion in #1431. Any help solving the issue is very welcome.

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

No branches or pull requests

3 participants