Replies: 2 comments
-
I used to be more up on the details of mathjs parse trees, but it's been a while, so take this answer with a grain of salt: I think the main thing that ParenthesisNodes do is allow a parse tree for more deeply nested stuff like |
Beta Was this translation helpful? Give feedback.
-
You answered it yourself I think: it is to allow preserving the original input. This is configurable with the option Docs: https://mathjs.org/docs/expressions/customization.html#parenthesis |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm new to the lib and learning about the tree generated by parse, have a quick question.
The compute tree seems like it's always binary, which (I think) makes parentheses redundant, since there's only one way to compute it anyways.
On top of that, when I manually remove a node from its parentheses wrapper node, and convert the entire fn back into a string, mathjs seems intuitive enough in knowing where to add the "()" - where not adding them would break the order of operations.
So my question is:
Beyond preserving the original input..
If in evaluating and turning the tree back into a string, that wrapper isn't necessary, what is it for?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions