mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

add exactConstantFunctions to simplify, to tell mathjs to not convert constant functions into decimals

Open ziktar opened this issue 2 years ago • 1 comments

I had a case which ended up with a constant log in it, which I wanted to stay as an exact value and not a decimal. I've added an option, exactConstantFunctions, so when passed as true it'll not evaluate functions. So while by default simplify("3 + sin(4)") will give you back 2.2431975046920716, with { exactConstantFunctions: true } passed you'll get back 3 + sin(4). It'll still add, multiply, apply exponents to raw constants, just not call most functions (especially not desirable for me for the trig/log functions to be called).

ziktar avatar Feb 23 '23 05:02 ziktar

I like that idea, thanks!

Some thoughts:

  1. I found the name exactConstantFunctions confusing at first. Maybe just name it exactFunctions, similar to exactFractions?
  2. Can you describe the new option in the comments in function simplify (alongside the description of exactFractions)? That will end up in the documentation on the website here.
  3. Not for this PR, but I can imagine that in the future we could expand on it, like only replacing sin when it's result is a nice, round value, like sin(0), sin(pi), sqrt(16).

josdejong avatar Feb 23 '23 15:02 josdejong