A small number theory utility library (gcd, primes, modular arithmetic, CRT, etc.)
Project description
pynumbertheory
Compact, classroom-friendly number theory helpers for Python projects and scripts.
Features
- Basic arithmetic:
gcd,lcm,extended_gcd,is_perfect_square - Primes:
is_prime,sieve,prime_factors - Modular arithmetic:
mod_pow(fast exponentiation),mod_inv,chinese_remainder
Installation
Requires Python 3.9+.
pip install pynumbertheory
Or from source for development:
pip install -e .[test]
Usage
from pynumbertheory import (
gcd, lcm, extended_gcd, is_perfect_square,
is_prime, sieve, prime_factors,
mod_pow, mod_inv, chinese_remainder,
)
gcd(12, 18) # 6
is_prime(97) # True
sieve(20) # [2, 3, 5, 7, 11, 13, 17, 19]
prime_factors(60) # [2, 2, 3, 5]
mod_pow(2, 10, 1000) # 24
mod_inv(3, 11) # 4
chinese_remainder([2, 3, 2], [3, 5, 7]) # 23
Testing
python -m pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pynumbertheory-0.1.1.tar.gz
(4.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynumbertheory-0.1.1.tar.gz.
File metadata
- Download URL: pynumbertheory-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09ffcca91702de7c6cf830cb6dccf772119368a5608539c43333cf3851292e83
|
|
| MD5 |
09cb26d4bc9a646b1cc379c52e474360
|
|
| BLAKE2b-256 |
b47b28d6ebf4682d114562e31eb3e67158fd8b44f2eb64032714cc28586668f5
|
File details
Details for the file pynumbertheory-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pynumbertheory-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
709c16069cf12febd8cbcbbddba15c4d37f745e2953f7e8560288e9b23c23f71
|
|
| MD5 |
46a57a05d6950c8c7a1d59ff860cf06e
|
|
| BLAKE2b-256 |
6b567a514b9dd070d1e36fe521614ced759d9e72a93607fa7b65bbe043c27a2f
|