-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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 math.tau #56554
Comments
I'd like to add a new constant to the math module: tau = 2*math.pi Rather than repeating all the reasons for why tau makes more sense than pi as the fundamental circle constant, I'll just refer interested readers to http://tauday.com/ |
Perhaps we should wait until \tau gains popularity larger than some impassioned physicist. \tau has been used to represent the golden ratio longer. |
-1 |
The golden ratio is more commonly denoted with phi (although tau does get used sometimes). Popularity isn't the point though, it's the fact that tau *makes geometric sense* in ways that 2*pi doesn't. |
I like this issue number, but I don't think that Python needs this new constant: it's trivial to add it to your own project. We have pi and e, it's enough. If we begin to add a new constant, others will ask to add much more constants, and there are million of other constants (useful or not). You may want to create a library of some other common constants. You can use float.fromhex() to have a good accuracy. |
Nick, you just have to write: tau = 2 * math.pi
Actually, I've heard there are an infinity of them. |
Can you prove that? |
2011/6/16 STINNER Victor <report@bugs.python.org>:
Don't have to. Axiom of infinity. :) |
On Wed, Jun 15, 2011 at 8:10 PM, Nick Coghlan <report@bugs.python.org>wrote:
(The following is best if read aloud using your best pirate impression) I'd rather name the new constant "matey". Then we have: The circumference of a circle is: r matey |
Not to mention d(area of circle of radius r) = r dr matey. |
And I thought putting "dx" directly next to the integral sign was audacious... |
Uh, not until I've seen a lot more evidence that people are habitually writing "TAU = 2 * math.pi" in their programs... |
Following-up sbaird's comment, I must point out that those aren't Python-specific results. Filtering them by appending &l=python to the urls yields:
Then again, the results for all languages are still helpful to estimate the overall adoption of the notation in code, and indeed the global usage of these patterns (in github only) is in the hundreds. Also, it's worth taking a look at the usage of the twopi constant, which is already defined in several languages (http://en.wikipedia.org/w/index.php?oldid=509096802#Support_in_programming_languages), and has been manually defined in python quite often, proving its usefulness:
|
I'm just going to do this. |
Builds fine on Windows. Happily, |
OK, here's a diff with a test that math.tau ~~ 2*math.pi. |
Hmm. I'd test that tau is exactly equal to 2*pi. All Python platforms (past, present, and plausible future ones) have binary C doubles, so the only difference between pi and 2*pi _should_ be in the exponent (multiplication by 2 is exact). Else we screwed up one or both mantissas (typed the constant wrong, and/or the C compiler is rounding incorrectly) - which would be bad. |
+1 |
At some point before 3.6, the docs should get updated, and |
Perhaps minds are already made up, but this may be the last chance to say that I think that this shouldn't go forward.
If needed, I can survey the audiences at the upcoming SF PyData conference and the SF PyBay conference to see if any of the participants have any clue what this is about and whether they would support the addition. |
+1 to Raymond. |
Noted, but it doesn't change my decision. Obscure fact: did you know there |
Agreed with Raymond's arguments. |
I also agree with Raymond's arguments. Adding tau doesn't add clarity to the math module, it just adds complexity. |
Let those other libraries follow. |
Emanuel Barry, that is both untrue and irrelevant (sorry to be blunt, but that's a total straw man on my and I believe other's argument). The fact that the only mathematical constants in math are pi and e (nan and inf aren't really "mathematical" constants) *does* indicate to me that only the really important ones are included. GvR, are you also in favor of adding more math constants/functions to the math module? I do see the value of Easter eggs in the language, but two real constants and one Easter egg constant seems weirder than ten real constants and one Easter egg constant. I'm +1/(2*pi) (because I still think tau in general is stupid) to add it if it also means the math module can be expanded. And before you ask, yes, I'll be happy to contribute once things move to GitHub. |
FWIW I don't plan to have more constants there, at the current rate we'll What worries me more is proposals to add Python functions to math... --Guido (mobile) |
I've updated the test to assert tau is equal to 2*math.pi, as well as updated the docs and cmath. Let me know if I have made any errors! |
The unification of tau2.diff and tau3.diff LGTM; thanks, Lisa! My commit bit is broken at the moment; anyone in a position to apply those patches? |
BTW, if we're talking about useless constants in the math module, it's hard to get more useless than To give just one example, on my machine, the result of |
How can it be? math.e**500 = math.exp(math.log(math.e)*500) and |
That's the theory if numbers have an infinite precision. In practice, |
Serhiy's objection is a little subtler than that. The Python expression math.exp(math.log(x) * y) THEN math.e**500 would be computed as math.exp(math.log(math.e) * 500) == math.exp(1.0 * 500) == math.exp(500.0). But that's not how x**y is implemented. Because the error in log() is multiplied by y, and then fed into exp() blowing it up even more, only a hopelessly naive library would implement pow() that way. In practice, library pow functions fake the effect of at least 15 more bits than native double precision to absorb these errors. Under the covers, then, a reasonable library pow computes math.log(math.e) to more than native double precision - and _that_ (internal, invisible) result is not 1.0. Because math.e isn't the mathematical e to begin with. The difference between math.e and the mathematical e is a difference quite visible to the internal log, which delivers an internal log not equal to 1, and its difference from 1 is "an error" multiplied by 500 and fed into the internal exp (blowing up the error even more). In the end, math.e500 returns a very good approximation to the true value, given that math.e is not e. There's no reason to hope that's close to exp(500), though - that delivers a very good approximation to e500 (where All that said, I agree with Mark that math.e is at best an attractive nuisance. Still, I'm -1 on removing it - it's a traditional and universally embraced nuisance ;-) |
What about rounding pi to 3 (and tau to 6)? https://en.wikipedia.org/wiki/Indiana_Pi_Bill (and I'm sure we can find a cute video about how cool to have pi as 3 to add it to the docs). |
Why don't we fix the nuisance part without making it less attractive: class _E(float):
def __pow__(self, other):
if self is e:
return exp(other)
else:
return pow(self, other)
e = _E(2.718281828...)
I would rather see from math import π work in the future Pythons. I like Vi Hart, but I am firmly on the π side in the π vs. τ debate. The problem with τ is that it is visually smaller than π, actually twice smaller: π ≈ ττ, but the actual definition is the opposite. |
Python will really follow the tau sort joke ? I never saw it mentioned in any serious math or programming document. All the github search result looks like people who are in this joke (kind of). The page http://tauday.com/state-of-the-tau list very little use of tau in relevant domains, the most relevant to our discussion would be the including of tau in modula-2 standard library. I don't see how the introduction of the unknown tau constant in python programs will make them clearer or better to the targeted public who will read them. I must confess however that 2*pi occurs frequently in formula and these formula would be simplified if tau was used. However an honest and non partisan web site would list all the use of pi without 2 where the formula would be more complicated. I don't see that so I'm still not convinced. I know that Guido van Rossum is the Benevolent dictator for life of python, but as I understand it until this point, the dictator position was used after all argument took place and not before. |
"non partisan" is probably hard to find, but if you want to see the other side of the story, http://www.thepimanifesto.com/ is probably most accessible. |
Please folks. Stop taking this so seriously and remember that this is the language where you can type in
and it actually works. (Sort of.) |
As an Easter egg, of course. I'm all for it. But please take a look at https://docs.python.org/3.5/search.html?q=antigravity&check_keywords=yes&area=default |
not to mention I like to use the following expression myself. pie = 22 / 7 # because why not?
tau = 2 * pie |
Unsubscribing from this ridiculous issue. Guido, do your thing. |
The documentation of tau should mention it's equal to 2 * pi. |
Chi Hsuan Yen added the comment:
According to this discussion, tau is very important. Maybe it's better to |
From http://tauday.com/
For me it's a sign that pi is (currently) more common than tau. One purpose of the documentation is helping newcomers understand what Python's built-in objects mean. "tau = 2 * pi" is better than "pi = tau / 2" as those who know pi only are more than those who know tau only. |
I have added some more detail to the Tau documentation, including that Tau is 2 * pi, as well as some links to Tau Day and Vi Hart's video. That should give Python users enough to get started forming their own opinions on tau vs pi :) |
Lisa, this LGTM. I'll commit it so we can put this behind us! |
New changeset 68f2d6098be1 by Guido van Rossum in branch 'default': |
There is a typo in the NEWS entry: "Issue bpo-12345: Add *mathemathcal* constant tau to math ..." |
Thanks, fixed. |
Why does this issue keep ending up as the target of unrelated PR notifications? |
Because of its lucky number. See python/core-workflow#223 (fixed). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: