Skip to content

ENH: Add np.tau to mirror math.tau #9696

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

Closed
wants to merge 1 commit into from
Closed

Conversation

eric-wieser
Copy link
Member

Since PEP 628 adds it to 3.6

Not clear to me if this is API or ENH - feel free to squash merge to modify the commit message.

@@ -77,6 +77,7 @@ NPY_INLINE static float __npy_nzerof(void)
#define NPY_LOGE2 0.693147180559945309417232121458176568 /* log_e 2 */
#define NPY_LOGE10 2.302585092994045684017991454684364208 /* log_e 10 */
#define NPY_PI 3.141592653589793238462643383279502884 /* pi */
#define NPY_TAU 6.283185307179586476925286766559005768 /* tau = 2*pi */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well add the float and long double versions as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't appear to use 2*pi internally, but it does seem like something we might want some day so it doesn't hurt to define it for all types.

Copy link
Member Author

@eric-wieser eric-wieser Sep 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see those.

On that note, what's the correct way to get np.longdouble(np.pi)? Obviously that expression isn't as precise as it could be.

Edit: new issue for that at #9698

@charris
Copy link
Member

charris commented Sep 17, 2017

I'd call it an enhancement. Apart from adding the other types, LGTM.

@rgommers
Copy link
Member

Needs a proposal on the mailing list.

Given that the vast majority of people reading code will not know what np.tau means and do understand 2*np.pi, I don't think this is the best idea.

It's a dumb PEP by the way.

@charris
Copy link
Member

charris commented Sep 17, 2017

Note that 2 * np.pi doesn't lose any precision.

@eric-wieser
Copy link
Member Author

Fixed up.

I'll make a post to the mailing list in the near future. It seems we already have Guido's support, from issue12345:

None of numpy, scipy, sympy, or mpmath implement tau

Let those other libraries follow.

@rgommers
Copy link
Member

https://bugs.python.org/issue12345

That's just ridiculous. You have like 10 core devs saying no, Guido saying no, then changing his mind without explanation. Please close this PR.

@charris
Copy link
Member

charris commented Sep 17, 2017

Reading the comments at the python link, it does seem to be a bit of a joke. As jokes go, I'd prefer the matey suggestion. For serious, I'd go with twopi. The argument that tau is commonly used for other things, optical depth for instance, is a good one against including this constant.

@ghost
Copy link

ghost commented Sep 17, 2017

/cc @ncoghlan

@u55
Copy link

u55 commented Sep 17, 2017

Let me add my vote against adding a new trivial constant by quoting from the Zen of Python: "Explicit is better than implicit."

2 * np.pi is explicit, np.tau is implicit.

But if people really demand a new constant, at least np.twopi is explicit.

@eric-wieser eric-wieser changed the title API: Add np.tau to mirror math.tau ENH: Add np.tau to mirror math.tau Sep 17, 2017
@eric-wieser
Copy link
Member Author

I guess this comes down to whether it's more important to follow pythons lead, or do The Right Thing. My thinking was simply "if math does this, then it seems reasonable for numpy to do this too".

Clearly there's a lot more resentment about PEP628 than I initially thought. I'd still be interested to hear @ncoghlan's thoughts here, but will close this PR to stave off fears of it being merged

@ncoghlan
Copy link

I think it's fine for other projects to say "No, we're not going to follow CPython's lead on this unless/until the educational establishment starts to change how it teaches trigonometry" (it took 5 years for GvR to change his mind about adding it to CPython).

@rgommers
Copy link
Member

rgommers commented Sep 18, 2017

Clearly there's a lot more resentment about PEP628 than I initially thought.

It's not resentment, this PR is literally the first time I heard of math.tau. It's simply that when Guido decides to add a useless constant to a stdlib module as some kind of humor or easter egg, that doesn't mean we have to pollute the main numpy namespace.

My thinking was simply "if math does this, then it seems reasonable for numpy to do this too".

I think it's the other way around for most numerical stuff - numpy sets the standard, and math is fairly irrelevant beyond teaching and very simple calculations.

@u55
Copy link

u55 commented Sep 18, 2017

Actually, I don't think the word "resentment" is far from my personal feelings, and I don't think that every proponent of tau=2*pi means it as a joke or easter egg. From what I gather by reading https://tauday.com/tau-manifesto, reddit, etc., there are people who genuinely think that they are improving the state of mathematics by removing factors of 2 in certain cherry-picked high-school trigonometry and geometry formulas. Their "immodest proposal" is that every branch of math and science adopt tau as the "true", "more fundamental", circle constant and eventually replace pi with tau/2 in every occurrence in the math and science literature, so that generations of high-school students down the line have an easier time learning basic trigonometry and take this improved insight with them if they go on to become career mathematicians and scientists.

In my personal opinion, this is a ridiculous reason to renounce centuries of well-established mathematical terminology. Furthermore, I think that adding a second similar mathematical constant, only adds more mental dissonance not less, for everyone (young students and old-school math practitioners), and becomes a hindrance to pedagogy not a help. Lastly, and the main reason I feel resentment toward tauist proposals, is the hijacking of the Greek symbol "tau" for their purpose. There are very few Latin or Greek symbols that do not carry with them some sort of extra baggage in terms of common usage in each specific sub-field of math or science. The lowercase pi symbol (without any subscript) is the one symbol that is universally off limits (with a few exceptions), and now the tauists want to add the lowercase tau symbol to that list. This is frustrating because lowercase tau is already one of the most common Greek symbols, at least in the branch of physics I am most familiar with (atomic, molecular, and optical physics), used for time-related variables (electrical RC time constant, spontaneous-decay lifetime, pulse duration, repetition period, etc.). If the tauists had proposed a brand new symbol instead of commandeering an already common one, pi-bar (pi with a slash through it) for instance, to draw analogy with the reduced Planck constant, then I would harbour no resentment and would significantly reduce my objection.

Sorry for the rant. I just think that the mathematics and scientific community should have an honest discussion before adopting fringe internet proposals.

@u55
Copy link

u55 commented Sep 18, 2017

Edit: of course I meant "repetition period" not "repetition rate" in the above comment (changed).

@njsmith
Copy link
Member

njsmith commented Sep 18, 2017

Are there any topics that inspire a higher ratio of passion-to-importance than pi? :-)

Theoretically, I actually find the arguments for tau fairly persuasive; in practice, it is so very much not worth arguing over. If tau takes over the world we can always revisit this.

I just think that the mathematics and scientific community should have an honest discussion before adopting fringe internet proposals.

Perhaps, but the numpy bug tracker is not the place for this discussion... let's let this closed issue stay closed.

@charris
Copy link
Member

charris commented Sep 18, 2017

Before letting this dog lie, I found this analysis of the advantages/disadvantages of the two options interesting: http://blog.wolfram.com/2015/06/28/2-pi-or-not-2-pi/

@stefanoborini
Copy link

stefanoborini commented Oct 17, 2017

@rgommers

It's not resentment, this PR is literally the first time I heard of math.tau

There was a time you didn't hear of pi, but you didn't oppose it. I think that practicality beats tradition. Tau has a stronger and functionally proper mathematical meaning, it's just not used yet because everybody is used to think incorrectly, with pi. There was a period where different notations were used for differentiation, or for integrals, or when chemical formulas were written with the numbers as super, rather than sub. Tau is in the same process, today.

@charris
Copy link
Member

charris commented Oct 17, 2017

What we need is \tau = 4\pi, integration over the surface of spheres is pretty common in physics.

@fourpoints
Copy link

I sometimes find myself having to write

import numpy
import math

when working with circles, solely because of math.tau, so this would save me an import. This is helpful when working with functions that accepts radians, for instance:

  • np.linspace(0, math.tau, 100) gives the radians in a full circle.
  • when working with fractions of a circle, 1/4 * math.tau is easier to read than 1/2 * np.pi or 1/4 * 2*np.pi
  • theta % math.tau gives an angle between 0 and tau, while theta % 2*np.pi doesn't. You have to write theta % (2*np.pi) instead.

I don't think this alone is enough to re-open the issue, but I didn't see any use cases for tau among the comments, so I thought I'd mention some.

@nschloe
Copy link
Contributor

nschloe commented Oct 14, 2021

Edit: I've collected some resources about tau here.


I just noticed casually that there is no tau in numpy and found this thread. I would like to speak out in favor of adding it to numpy.

It has been suggested above that τ is a bit of a mathematical joke, which I would argue is not the case. I see mainly two reasons for its promotion (which have been suggested before):

  • It is arguably easier to think of full circle revolutions (τ) than of half-circle revolutions (π). What's π/4 again? Ah yes, the eighth of a circle, aka τ/8. That's true for beginners of math, but also for people who have to deal with this on a regular basis (like me).
  • A large majority of basic equations feature τ=2π, not π alone. In fact, it's hard to find equations that have a sole π in them without digging too deep. (Really the only case I can think of is integral exp(-x^2) = sqrt(pi), and even here one can argue that the probabilist's representation 1 / sqrt(2 * pi) integral exp(-1/2 x^2) = 1 is the more natural form.)

It's true that π will remain popular in our lifetimes, and I will continue to use it because it's just more known. τ definitely has its place though. I've noticed that when doing research for n-dimensional volumes and their relations (2π everywhere), and it's hard for me go without it nowadays.

I just had a look around where else tau is defined:

  • Programming languages that have tau in their repertoire:
    Python, C#, Rust

  • Languages that don't:
    javascript, julia, R, Go, C

  • Google calculator knows it:
    screenshot

Anyway, +1 on adding it as numpy.tau.

@v4hn
Copy link

v4hn commented May 6, 2022

tau is not an easter egg and people use it to write their code.

I've just wasted 10 minutes of my life and got interrupted programming because I had to read this thread.
I was honestly confused about why my numpy is broken and np.tau does not evaluate correctly. I'm not joking.
Talking as a roboticist - where revolute joints are omnipresent - tau makes things a lot easier, so I use it.

import numpy as np
import math
np.tau = math.tau

@emilk
Copy link

emilk commented Jul 5, 2024

Can we please reconsider this?

Python has had math.tau since 3.6 (commit).

Tau is also in many other programming languages, like Rust and C#.

Tau is mainstream!

@rgommers
Copy link
Member

rgommers commented Jul 5, 2024

No, not open for rediscussion.

@numpy numpy locked and limited conversation to collaborators Jul 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.