Skip to main content

Modu is a mathematical module for doing modular arithmetic in Python.

In a nutshell, Modu allows you defining sets of residue classes for given moduli. These are displayed with usual notations of modular arithmetic like n ≡ {0, ±2, +3} (mod 6) or, in Jupyter Notebooks, with instantaneous LaTeX formula rendering. New sets can be computed from existing ones using set operations (union, intersection, complement), as well as arithmetic operations (addition, negation, multiplication, division, exponentiation). Samples of integers can be obtained, displayed as tables (aligning same residues in same columns) and possibly transforming the elements by user-defined functions. Several fundamental results of number theory can be easily illustrated, like the sieve of Eratosthenes, Fermat's little theorem, Chinese remainder theorem and Dirichlet's theorem on arithmetic progressions.

Thanks to Python's operator overloading, Modu allows expressing advanced operations in very few keystrokes, often as one-liners. Here are few examples.

  • integers having residue 0 modulo 2 (the even numbers):
>>> from modu import O
>>> O % 2
0 (mod 2)
  • integers multiples of 2 or 3, defined by set union:
>>> O%2 | O%3
{0, ±2, +3} (mod 6)
  • integers not multiples of 2 or 3, defined by complement of the previous set:
>>> ~(O%2 | O%3)
±1 (mod 6)
  • testing whether 15 and 23 belong to the previous set (note: any prime number greater or equal to 5 belongs to this set!):
>>> 15 in ~(O%2 | O%3)
False
>>> 23 in ~(O%2 | O%3)
True
  • integers multiples of 2 and 3 altogether, defined by set intersection--see Chinese remainder theorem:
>>> O%2 & O%3
0 (mod 6)
  • checking whether two sets are equivalent or not:
>>> O%2 | O%3 == (0, 2, 3, 4) + O%6
True
>>> O%2 & O%3 == O%6
True
>>> O%2 | O%3 != O%6
True

Modu provides much more functions, like changing the display format or extracting / transforming samples using a table layout. Modu is best used as an interactive calculator in Python terminal sessions (REPL) or in Jupyter Notebooks with instantaneous LaTeX rendering. The prime target domain is research and education in number theory.

All those features are demonstrated in an interactive tutorial, the "Modutorial" Jupyter Notebook (modutorial.ipynb). This can be opened directly online by clicking here (binder): Binder (be patient: you have to wait a bit...)

Modu is an open-source module distributed under the MIT license.

Metadata

Release files for modu 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modu 0.1.1
File Size Uploaded Provenance
modu-0.1.1.tar.gz 8.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for modu 0.1.1
File Interpreter ABI Platform
modu-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / modu-0.1.1.tar.gz

Download URL modu-0.1.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
357fd13dc7534fa7f12523a2ea43f2145533afb22754c26fde1df279e329f0b1
BLAKE2b-256 checksum
How to use checksums
d8c0085ccf50716a0b60119801ffb3c0f88ad22e12f385b8b23aca433f3d741d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / modu-0.1.1-py3-none-any.whl

Download URL modu-0.1.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52acb4633e4094486ed5fdbc476a672164dda2dbc6ed997521b73c96f4d37ebf
BLAKE2b-256 checksum
How to use checksums
b01506a941f2d51a945fb543b34863a3b5b7d3f66f95ecfe6db807841b6b452e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for modu 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page