-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Incorrect docstring of math.exp (math.e vs Euler's number) #101594
Comments
"Return the exponential of x" implies that it returns x to some power, which is wrong. Even if we read it the other way, "the exponential of x" doesn't tell us what number is being raised to the power of x. Which exponential? There are an infinite number of possible exponentials (something) to the power of x. The current description is much better than the description in the Mathematica docs, where you have to click on the "Details" section to finally discover that
That's not a problem. We know from the relevant domain knowledge that all float constants and operations refer to floats, not real numbers. We don't need to repeat that for every single function. Unlike Mathematica, the In any case, the docstring does not have to repeat the full documentation. It is okay for the docstring to be an abbreviated summary. |
Not. It's exactly
Then this will be incorrect, because the
That's true. But even you above mistakenly interpreted |
Here's my 2 cents: since the
Now, even with the above sentence or even if you say "the exponential of x", you could argue that it's still not the case since the actual result is an approximation. In particular, you cannot say that it uses Euler's number. Therefore, I don't think we need to be extremely verbose in the docstring if we have an online doc and if the actual result also depends on the libc implementation. A more precise docstring would be
I however think that this is more confusing for normal users. |
As a normal user, I've thought that both ways are the same and |
What I thought users could find confusing is the term "approximation" because the way it is approximated is entirely implementation-dependent. But if it's not confusing, then it's good, I think ? I personally come from C/C++, so I've always used |
In fact, what's I'm suggesting is to be less verbose in docstring and sphinx docs. E.g. the docstring of exp could be:
The sphinx docs:
And so on: we could drop remarks like |
Thanks all for the discussion and suggestions, and thank you to @skirpichev for the PR. I'm going to close here: the maxim "Practicality beats purity" applies, and I don't think there's any practical problem being solved at this point; in particular, I think removing the references to I agree that there's ambiguity over whether Technically the same applies to |
@mdickinson, thank you for review.
If we can guarantee that, sorry for a bit off-topic, then base=math.e sounds to be a good default value. What if we adapt the inspect module to keep "symbolic" name in the Signature, does this make sense for you? |
@skirpichev Yes, that seems reasonable, if it can be achieved. It's philosophically wrong in that it doesn't match what the implementation actually does, and that still bugs me a little, but I think it passes the "practicality beats purity" test. |
Yes, I've a toy implementation: #89381 (comment)
Instead of "calculated as log(x)/log(base)" we could state something like "equal to log(x)/log(base)". |
I would rephrase this as: "Return the exponential of x." (like the Mathematica docs). Same for expm1() or with log()/log1p().
The problem with the current text is that here is a disambiguation of the Euler's number e vs the math.e (an approximation of). Sometimes this is explained in the sphinx docs: e.g. for same exp() it says "Return e raised to the power x, where e = 2.718281… is the base of natural logarithms.". But sometimes not: e.g. for log() or log1p().
I think, using "the exponential of" or "the natural logarithm of" in the docstrings and sphinx docs will be better.
Linked PRs
The text was updated successfully, but these errors were encountered: