Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add π to the math module #103172

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
JosephSBoyle opened this issue Apr 1, 2023 · 14 comments
Closed

Add π to the math module #103172

JosephSBoyle opened this issue Apr 1, 2023 · 14 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 only security fixes type-feature A feature request or enhancement

Comments

@JosephSBoyle
Copy link
Contributor

JosephSBoyle commented Apr 1, 2023

Currently, the math module in CPython uses the identifier math.pi to represent the mathematical constant π. This breaks user expectations and violates the principle of least surprise.

To improve consistency and readability, I propose changing math.pi to math.π symbol throughout the module. The reasoning for this is threefold:

  1. This change will make the code more intuitive for mathematicians and scientists (at least 99%+ of python users) who are more used to seeing the π symbol, thus reducing cognitive load and allowing them to build more complicated research code.

  2. Python supports unicode characters such as π and we don't take advantage of this enough. We can use π, therefore we should.

  3. Nobody currently knows how to type π, if we make this change users will have to open the math module and copy and paste the variable name - which is a great way to increase the visibility of important module internals that users need to read.

Some would be tempted to create a math.pi alias to maintain backwards compatibility, but I think that would only encourage people to continue using the non-symbolic variable (bad), so I propose simply deleting math.pi entirely (users will get the hint!).

This is a pretty small change so I don't think a news entry is necessary, in fact I think not having a news entry would make this change a sort of cool Easter Egg that users can discover and enjoy!

Kind regards and happy April 1st,
Joe

Linked PRs

@JosephSBoyle JosephSBoyle added the type-feature A feature request or enhancement label Apr 1, 2023
@sobolevn
Copy link
Member

sobolevn commented Apr 1, 2023

I think that 🥧 is a much better name! It looks tasty!

@kumaraditya303
Copy link
Contributor

Worth backporting to 2.7!

@AlexWaygood AlexWaygood added 3.11 only security fixes 3.10 only security fixes 3.9 only security fixes 3.8 (EOL) end of life 3.7 (EOL) end of life 3.12 only security fixes labels Apr 1, 2023
@rasputyashka
Copy link

rasputyashka commented Apr 1, 2023

Yea, I was really surprised when realized that my keyboard has only π, but not "p" and "i". That's why i still don't use python when i do some rocket science.

@efahl
Copy link
Contributor

efahl commented Apr 1, 2023

Python supports unicode characters such as π and we don't take advantage of this enough. We can use π, therefore we should.

I concur wholeheartedly with this. We should look for other opportunities to impose our will upon make life easier for all users, so suggest we use Σ to replace the 'sum' builtin.

@jschwar313
Copy link

Sounds pretty irrational to me.

@flowerbug
Copy link

Everyone should write in the margins that using such a symbol is not reflecting the reality of the situation. As you are writing a finite symbol, but when you read and evaluate such a symbol your brain should never return. This is true of many such symbols where we fudge maths, e, 1/3, inf, etc.

@mrabarnett
Copy link

And λ to replace 'lambda', of course.

Plus 🐍 instead of 'Python'.

@rasputyashka
Copy link

And λ to replace 'lambda', of course.

Plus 🐍 instead of 'Python'.

but we don't use "python" anywhere in the code. It's neither builtin or keyword.

@gvanrossum
Copy link
Member

Where’s the PR?

@sfermigier
Copy link

sfermigier commented Apr 2, 2023

On a more serious tone, the "empty set" character (“∅”, U+2205) should be usable to represent an empty set in Python. It currently is not allowed:

Python 3.11.2 (main, Feb 16 2023, 02:51:42)
>>> ∅ = set()
  File "<stdin>", line 1
    ∅ = set()
    ^
SyntaxError: invalid character '∅' (U+2205)

I believe it would be useful when working with set-theoretic code, in part because {} doesn't represent the empty set in Python.

@sfermigier
Copy link

Python supports unicode characters such as π and we don't take advantage of this enough. We can use π, therefore we should.

I concur wholeheartedly with this. We should look for other opportunities to impose our will upon make life easier for all users, so suggest we use Σ to replace the 'sum' builtin.

(Seriously) Note that currently the '∑' (U+2211) character is not allowed as an identifier in Python, so it isn't even doable (assuming it's a good idea):

>>> ∑ = sum
  File "<stdin>", line 1
    ∑ = sum
    ^
SyntaxError: invalid character '∑' (U+2211)

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 2, 2023

Alas! For it is no longer April 1, and what had yesterday seemed like a revelatory idea, now seems, uh, foolish.

Thanks for the excellent April Fool's, @JosephSBoyle, it brightened my day :)

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2023
@efahl
Copy link
Contributor

efahl commented Apr 2, 2023

(Seriously) Note that currently the '∑' (U+2211) character is not allowed as an identifier in Python, so it isn't even doable (assuming it's a good idea):

I didn't use 2211, I used Σ \u03a3, which is indeed valid as an identifier. Choose your homographs carefully.

@holdenweb
Copy link
Member

holdenweb commented Apr 4, 2023

I'd suggest this frivolity end immediately. Beware the ∏thon Secret Underground, who have spies out watching for this sort of @^&E$^^RVO^RVOP*&%^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 only security fixes type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.