Closed ShaydeNZ closed 1 week ago
Thanks for reporting this bug.
I think the cause is in the logic for recognizing an identifier
(I see that isString
should be isString(s)
BTW):
A pragmatic solution would be to improve this regex to better match the available characters. The most neat solution would be to replace the regular expression with using the isAlpha
function used by parse
:
Anyone able to help implement a solution for this?
DESCRIBE THE BUG
The documentation lists the characters one can use in variable / symbol names, including a-z, A-Z, $, _, etc.
However, supplying a symbol in a string to derive against with anything but basic alphanumerics to
derivative()
fails.Apologies in advance if this has already been reported; I looked through the Issues but didn't see an obvious similar report.
TO REPRODUCE
I'll use a variable with a '$' character in here for reference, but the same thing happened when using '_' in a variable name.
Problem is present in math.js 13.0.2 and 13.0.3.
To start,
evaluate()
works fine with these characters:But calling
derivative()
fails with the same symbol:Calling it with a boring symbol works, though:
We can get around this problem by parsing the symbol first:
For completeness, here is the failure using a variable with an underscore: