GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add π to the `math` module · Issue #103172 · python/cpython

Add π to the math module #103172

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Add π to the math module#103172
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetype-featureA feature request or enhancementA feature request or enhancement

Description

@JosephSBoyle
JosephSBoyle
opened on Apr 1, 2023
Issue body actions

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

  • gh-103172: Add π to the math module #103178
Reacted by Alex Waygood, chgnrdv, sobolevn, r-c-f, Eryk Sun, Konstantin Rasputin, Artem Mukhin, Sasha, Kyle Hofmann, wookie184 and 11 more
Reacted by Alex Waygood, Artem Mukhin, AtulVishwa, Kyle Hofmann, Ionite and decorator-factory

Activity

  1. JosephSBoyle
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Apr 1, 2023
  2. sobolevn commented on Apr 1, 2023

    @sobolevn
    sobolevn
    on Apr 1, 2023
    Member
    More actions

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

    Reacted by Abhinav Srivastava
    Reacted by JosephSBoyle, Konstantin Rasputin, Shashwat, Kumar and Ben Morgan
    Reacted by Alex Waygood, Desiders, Eric Fahlgren and ರಾಹುಲ್
  3. kumaraditya303 commented on Apr 1, 2023

    @kumaraditya303
    kumaraditya303
    on Apr 1, 2023
    Contributor
    More actions

    Worth backporting to 2.7!

    Reacted by Alex Waygood, JosephSBoyle, Shashwat, decorator-factory, An Long, Kumar, Clément Robert, Barney Gale and Cool Guy
    Reacted by Barney Gale
  4. AlexWaygood
    added
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    3.8 (EOL)end of lifeend of life
    3.7 (EOL)end of lifeend of life
    3.12only security fixesonly security fixes
    on Apr 1, 2023
  5. rasputyashka commented on Apr 1, 2023

    @rasputyashka
    rasputyashka
    on Apr 1, 2023
    More actions

    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.

    Reacted by Swarnodip Nag, kvrvgv, Abhinav Srivastava and Kumar
  6. efahl commented on Apr 1, 2023

    @efahl
    efahl
    on Apr 1, 2023
    Contributor
    More actions

    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.

    Reacted by Stefane Fermigier
  7. jschwar313 commented on Apr 1, 2023

    @jschwar313
    jschwar313
    on Apr 1, 2023
    More actions

    Sounds pretty irrational to me.

    Reacted by Lewis Gaul and Boštjan Mejak
    Reacted by Lewis Gaul, Stefane Fermigier, Abhinav Srivastava and Sam Sulaimanov
  8. flowerbug commented on Apr 1, 2023

    @flowerbug
    flowerbug
    on Apr 1, 2023
    More actions

    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.

  9. mrabarnett commented on Apr 1, 2023

    @mrabarnett
    mrabarnett
    on Apr 1, 2023
    More actions

    And λ to replace 'lambda', of course.

    Plus 🐍 instead of 'Python'.

    Reacted by Ijtaba Hussain
  10. rasputyashka commented on Apr 1, 2023

    @rasputyashka
    rasputyashka
    on Apr 1, 2023
    More actions

    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.

  11. gvanrossum commented on Apr 1, 2023

    @gvanrossum
    gvanrossum
    on Apr 1, 2023
    Member
    More actions

    Where’s the PR?

    Reacted by Alex Waygood, denballakh, wookie184, Jelle Zijlstra, Charlie Zhao, Leo Zheng, baseplate-admin and Kumar
  12. kylehofmann
    added a commit that references this issue on Apr 1, 2023

    pythongh-103172: Add π to the math module

    c267cc1
  13. sfermigier commented on Apr 2, 2023

    @sfermigier
    sfermigier
    on Apr 2, 2023
    More actions

    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.

  14. sfermigier commented on Apr 2, 2023

    @sfermigier
    sfermigier
    on Apr 2, 2023
    More actions

    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)
    
  15. AlexWaygood commented on Apr 2, 2023

    @AlexWaygood
    AlexWaygood
    on Apr 2, 2023
    Member
    More actions

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

    Reacted by Charlie Zhao
    Reacted by JosephSBoyle and Ethan Furman
  16. AlexWaygood
    closed this as not plannedon Apr 2, 2023
  17. efahl commented on Apr 2, 2023

    @efahl
    efahl
    on Apr 2, 2023
    Contributor
    More actions

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

  18. holdenweb commented on Apr 4, 2023

    @holdenweb
    holdenweb
    on Apr 4, 2023
    Member
    More actions

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.