Skip to main content

Computational number theory. Pure Python. Zero dependencies. Unreasonably fast.

Project description

NumThy

Computational number theory. Pure Python. Zero dependencies. Unreasonably fast.

Installation

pip install numthy

Or just drop numthy.py into your project.

Quick Start

import numthy as nt

# Primality
nt.is_prime(2**89 - 1)  # True

# Factorization (SIQS handles 50+ digits)
nt.prime_factors(2**128 + 1)  # (59649589127497217, 5704689200685129054721)

# Prime counting
nt.count_primes(10**9)  # 50847534

# Discrete log
nt.discrete_log(1000, 3, 65537)  # 50921 (i.e., 1000 ≡ 3^50921 mod 65537)

# Diophantine equations
# Solve 2x² + 3xy - 3y² + 7x - 10y - 24 = 0
solutions = nt.conic(2, 3, -3, 7, -10, -24)
next(solutions)  # (8, 10)
next(solutions)  # (376, -174)
next(solutions)  # (17304, 25218)

Demo

Try NumThy in the browser: ini.github.io/numthy/demo

Documentation

See API.md for the full reference.

Under The Hood

One file, with everything implemented from scratch. Simple API, with heavy-duty algorithms under the hood:

  • Extra-strong variant of the Baillie-PSW primality test
  • Lagarias-Miller-Odlyzko (LMO) algorithm for prime counting, generalized to sums over primes of any arbitrary completely multiplicative function
  • Two-stage Lenstra's ECM factorization with Montgomery curves and Suyama parametrization
  • Self-initializing quadratic sieve (SIQS) with triple-large-prime variation
  • Cantor-Zassenhaus → Hensel lifting → Chinese Remainder Theorem pipeline for finding modular roots of polynomials
  • Adleman-Manders-Miller algorithm for general n-th roots over finite fields
  • General solver for all binary quadratic Diophantine equations (ax² + bxy + cy² + dx + ey + f = 0)
  • Lenstra–Lenstra–Lovász lattice basis reduction algorithm with automatic precision escalation
  • Jochemsz-May generalization of Coppersmith's method for multivariate polynomials with any number of variables

Requirements

Python 3.10+

That's it.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numthy-0.1.0.tar.gz (106.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numthy-0.1.0-py3-none-any.whl (62.8 kB view details)

Uploaded Python 3

File details

Details for the file numthy-0.1.0.tar.gz.

File metadata

  • Download URL: numthy-0.1.0.tar.gz
  • Upload date:
  • Size: 106.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for numthy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1df3a42f3b99fcd2168870c2621d53f81245d14e716a316962eeecb1ba616bf
MD5 74184c7be74fda5fdfa7c5d4938a4b3a
BLAKE2b-256 24848f638e76496612231e20851d2075d74749880bbef6224c2ce304345926a8

See more details on using hashes here.

File details

Details for the file numthy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: numthy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 62.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for numthy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85aebbe7ed601bb05d9c8e2e6e039ac5636d24f5929b9ec83ed7bd1deaa66c30
MD5 da5608ad2d386f7914711471b616fca4
BLAKE2b-256 abae4b8f06a4414f3abfe6cb1b8f24af696cdaedbc4b52b70fad5180dba9cc3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page