Inconsistent sqrt syntax
timokoesters opened this issue · 4 comments
√(2)×2 is 2√2, but
√2×2 = √4 = 2
I think multiplication should always be parsed as being outside of the sqrt.
Hmm this is a tricky one, because you would expect something like cos2x
to be parsed as cos(2x)
but sqrt2*2
as sqrt(2) * 2
I guess. Maybe it should make a distinction between implicit and explicit multiplication in this context? That's what Wolframalpha seems to do.
Your issues have been really helpful by the way. Thanks!
Even better, WolframAlpha differentiates between cos 2 x
and cos 2x
. I think leaving a space is the same as explicit multiplication
Oh yeah that makes sense. A bit trickier to parse, but should be possible
I think a bigger issue here is this:
√2*2 = √(2*2) = 2
but then also this:
√2+2 = √(2)+2 = 3.41...
The sqrt should either be greedy and capture any operation after it or capture nothing after it (unless theres parentheses wrapping everything under the sqrt) not both at the same time depending on the operator.
For example this is how I think they should be parsed:
√2*2 = √(2)*2 = 2.82...
√2+2 = √(2)+2 = 3.41...
and require the user to add parentheses for these operations to be pulled into the sqrt:
√(2*2) = 2
√(2+2) = 2