forked from python/peps
-
Notifications
You must be signed in to change notification settings - Fork 0
Draft PEP: imath --- module for number-theoretic functions #6
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| PEP: 9999 | ||
| Title: imath --- module for number-theoretic functions | ||
| Author: Sergey B Kirpichev | ||
| Sponsor: TBD | ||
| Discussions-To: Pending | ||
| Status: Draft | ||
| Type: Standards Track | ||
| Created: 10-May-2025 | ||
| Python-Version: 3.15 | ||
| Post-History: 02-Jun-2019, | ||
| `09-May-2025 <https://discuss.python.org/t/91337>`__, | ||
|
|
||
|
|
||
| Abstract | ||
| ======== | ||
|
|
||
| This PEP describes new module for number-theoretic functions, like | ||
| :external+py3.14:func:`math.gcd` or :external+py3.14:func:`math.isqrt`. | ||
|
|
||
|
|
||
| Motivation | ||
| ========== | ||
|
|
||
| The :external+py3.14:mod:`math` documentaton says: "This module provides | ||
| access to the mathematical functions defined by the C standard." But as a | ||
| state of art, over time the module was populated with functions that aren't | ||
| related to the C standard or floating-point arithmetics. Now it's much | ||
| harder to describe module scope, content and interfaces (e.g. returned | ||
| values). | ||
|
|
||
| Apparently, the :external+py3.14:mod:`math` can't serve as a catch-all place | ||
| for mathematical functions: we have also the :external+py3.14:mod:`cmath` and | ||
| the :external+py3.14:mod:`statistics`. Lets make same for integer-related | ||
| functions. | ||
|
|
||
|
|
||
| Specification | ||
| ============= | ||
|
|
||
| The PEP propose moving functions for integers (now placed in subsection | ||
| "Number-theoretic functions" [1]_) to a separate module, called ``imath``. As | ||
| maintaining backward-compatible aliases in the :external+py3.14:mod:`math` | ||
| module is not a problem --- they only :term:`soft deprecated`. | ||
|
|
||
| Possible extensions for the new module and it's scope are discussed in the | ||
| Open Issues section. | ||
|
|
||
|
|
||
| Backwards Compatibility | ||
| ======================= | ||
|
|
||
| No code breaks expected. | ||
|
|
||
|
|
||
| Reference Implementation | ||
| ======================== | ||
|
|
||
| TBD | ||
|
|
||
|
|
||
| Open Issues | ||
| =========== | ||
|
|
||
| Module name | ||
| ----------- | ||
|
|
||
| Another variants for name: ``ntheory`` (like SymPy's submodule), ``intmath``, | ||
| ``integermath`` and ``imaths``. | ||
|
|
||
| Possible renaming of isqrt | ||
| -------------------------- | ||
|
|
||
| As there is no clash with floating-point version, it could be renamed to | ||
| ``sqrt`` (Java-like). | ||
|
|
||
| Module scope and possible extensions | ||
| ------------------------------------ | ||
|
|
||
| Unless we can just provide bindings to some well supported mathematical | ||
| library like the GMP, the module scope should be limited. For example, no | ||
| primality testing and factorization. | ||
|
|
||
| Among proposed in the initial discussion thread (see also [5]_): | ||
|
|
||
| * ``c_div()`` --- for integer ceiling divide, see [2]_, [3]_. | ||
| * ``gcdext()`` --- to solve linear Diophantine equation in two variables (the | ||
| :external+py3.14:class:`int` implementation actually include extended | ||
| Euclidean algorithm) | ||
| * ``isqrt_rem()`` --- to return both integer square root and a remainder (if | ||
| integer isn't a perfect square) | ||
| * ``ilog()`` --- integer logarihm, currently :external+py3.14:func:`math.log` | ||
| has a special handling for integer arguments. It's unique (wrt other module | ||
| functions) and not documented so far, see [4]_ | ||
| * ``fibonacci()``. | ||
|
|
||
|
|
||
| Footnotes | ||
| ========= | ||
|
|
||
| .. [1] Number-theoretic functions | ||
| (https://docs.python.org/3.14/library/math.html#number-theoretic-functions) | ||
| .. [2] Integer ceiling divide | ||
| (https://discuss.python.org/t/91269) | ||
| .. [3] https://gmpy2.readthedocs.io/en/stable/mpz.html#gmpy2.c_div | ||
| .. [4] https://github.com/python/cpython/issues/120950 | ||
| .. [5] https://github.com/python/cpython/issues/81313 | ||
|
|
||
|
|
||
| Copyright | ||
| ========= | ||
|
|
||
| This document is placed in the public domain or under the | ||
| CC0-1.0-Universal license, whichever is more permissive. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logarithm