You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to find the derivative of an arbitrary expression for a calculator project I'm working on using this library. When I give it ln(|x|) it borks and gives a strange expression involving Piecewise and unsubstituted matches (_1), instead of the expected 1/(|x|). This causes the derivative to fail to compile to javascript and fail to evaluate.
Steps to Reproduce
import{ComputeEngine,version}from"https://unpkg.com/@cortex-js/[email protected]?module";constce=newComputeEngine();console.log("Using CE v"+version);constexpr1=ce.parse("\\ln |x|");console.log("should be Ln(Abs(x)) -->",JSON.stringify(expr1));// OKconstderiv=ce.box(["D",expr1,"x"]).evaluate();console.log("should be 1/Abs(x) -->",JSON.stringify(deriv));// BADconsole.log("should be \\frac{1}{\\vert x\\vert} -->",deriv.toLatex());// BADtry{console.log("should be 1/Math.abs(_.x) -->",deriv.compile().toString());// BAD}catch(e){console.error(e);}ce.assign("x",1/10);console.log("should be 10 -->",JSON.stringify(deriv.evaluate()));// BAD
Actual Result
Using CE v0.26.2
should be Ln(Abs(x)) --> ["Ln",["Abs","x"]]
should be 1/Abs(x) --> ["Divide",["Piecewise",["Tuple",["Multiply","_1",["Power","_1",-1]],["Less",0,"_1"]]],["Abs","x"]]
should be \frac{1}{\vert x\vert} --> \frac{1}{\vert x\vert}(\mathrm{Piecewise}(\mathrm{Pair}(\frac{\operatorname{\_1}}{\operatorname{\_1}}, 0\lt\operatorname{\_1})))
Error: Cannot compile invalid expression: "Error(ErrorCode(incompatible-type, number, function)) / |x|"
should be 10 --> ["Multiply",10,["Piecewise",["Tuple",["Multiply","_1",["Power","_1",-1]],["Less",0,"_1"]]]]
The latex also looks strange for the derivative. (Github refuses to render it inline here, so paste it into katex).
Expected Result
See above, it's in the console.log()'s
Environment
See above for version
No, it doesn't seem to work in any version that has symbolic derivative functionality.
Also of note
Derivative of plain old ln(x) is just fine. The absolute value messes derivative up:
import{ComputeEngine,version}from"https://unpkg.com/@cortex-js/[email protected]?module";constce=newComputeEngine();console.log("Using CE v"+version);constexpr1=ce.parse("\\ln x");console.log("should be Ln(x) -->",JSON.stringify(expr1));// OKconstderiv=ce.box(["D",expr1,"x"]).evaluate();console.log("should be Divide(1, x) -->",JSON.stringify(deriv));// OKtry{console.log("should be 1/_.x -->",deriv.compile().toString());// OK}catch(e){console.error(e);}
Using CE v0.26.2
should be Ln(x) --> ["Ln","x"]
should be Divide(1, x) --> ["Divide",1,"x"]
should be 1/_.x --> 1 / _.x
The only occurrence of Piecewise in this repository is in the definition of the derivative of Abs; maybe that's why it's messed up - because Piecewise is not implemented.
The text was updated successfully, but these errors were encountered:
Description
I need to find the derivative of an arbitrary expression for a calculator project I'm working on using this library. When I give it
ln(|x|)
it borks and gives a strange expression involvingPiecewise
and unsubstituted matches (_1
), instead of the expected1/(|x|)
. This causes the derivative to fail to compile to javascript and fail to evaluate.Steps to Reproduce
Actual Result
The latex also looks strange for the derivative. (Github refuses to render it inline here, so paste it into katex).
Expected Result
See above, it's in the console.log()'s
Environment
See above for version
No, it doesn't seem to work in any version that has symbolic derivative functionality.
Also of note
ln(x)
is just fine. The absolute value messes derivative up:Piecewise
in this repository is in the definition of the derivative ofAbs
; maybe that's why it's messed up - becausePiecewise
is not implemented.The text was updated successfully, but these errors were encountered: