Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ziktar
Copy link

@ziktar ziktar commented Feb 23, 2023

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).

… eg. sin(4) into a number, but leave it is an exact constant
…ic arithmetic, that should return an exact value
@josdejong
Copy link
Owner

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants