{"id":21453435,"url":"https://github.com/lapets/modulo","last_synced_at":"2025-07-27T19:07:55.564Z","repository":{"id":45107807,"uuid":"117384704","full_name":"lapets/modulo","owner":"lapets","description":"Pure-Python library for working with modular arithmetic, congruence classes, and finite fields.","archived":false,"fork":false,"pushed_at":"2025-04-23T04:39:12.000Z","size":102,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-27T18:06:56.520Z","etag":null,"topics":["abstract-algebra","algebra","congruence-class","congruence-classes","congruence-relation","field","fields","finite-fields","group","groups","library","mathematics","mod","modular-arithmetic","modulo","modulus","python","python-library","ring","rings"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/modulo","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lapets.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-13T22:49:51.000Z","updated_at":"2025-04-23T04:40:08.000Z","dependencies_parsed_at":"2025-04-23T05:34:24.679Z","dependency_job_id":null,"html_url":"https://github.com/lapets/modulo","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lapets/modulo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fmodulo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fmodulo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fmodulo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fmodulo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lapets","download_url":"https://codeload.github.com/lapets/modulo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fmodulo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262667037,"owners_count":23345507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-algebra","algebra","congruence-class","congruence-classes","congruence-relation","field","fields","finite-fields","group","groups","library","mathematics","mod","modular-arithmetic","modulo","modulus","python","python-library","ring","rings"],"created_at":"2024-11-23T04:39:37.582Z","updated_at":"2025-07-14T23:31:36.208Z","avatar_url":"https://github.com/lapets.png","language":"Python","readme":"======\nmodulo\n======\n\nPure-Python library for working with modular arithmetic, congruence classes, and finite fields.\n\n|pypi| |readthedocs| |actions| |coveralls|\n\n.. |pypi| image:: https://badge.fury.io/py/modulo.svg#\n   :target: https://badge.fury.io/py/modulo\n   :alt: PyPI version and link.\n\n.. |readthedocs| image:: https://readthedocs.org/projects/modulo-lib/badge/?version=latest\n   :target: https://modulo-lib.readthedocs.io/en/latest/?badge=latest\n   :alt: Read the Docs documentation status.\n\n.. |actions| image:: https://github.com/lapets/modulo/workflows/lint-test-cover-docs/badge.svg#\n   :target: https://github.com/lapets/modulo/actions/workflows/lint-test-cover-docs.yml\n   :alt: GitHub Actions status.\n\n.. |coveralls| image:: https://coveralls.io/repos/github/lapets/modulo/badge.svg?branch=main\n   :target: https://coveralls.io/github/lapets/modulo?branch=main\n   :alt: Coveralls test coverage summary.\n\nPurpose\n-------\nThe library allows users to work with congruence classes (including finite field elements) as objects, with support for many common operations.\n\nInstallation and Usage\n----------------------\nThis library is available as a `package on PyPI \u003chttps://pypi.org/project/modulo\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install modulo\n\nThe library can be imported in the usual ways:\n\n.. code-block:: python\n\n    from modulo import modulo\n\nExamples\n^^^^^^^^\nThis library makes it possible to work with `congruence classes \u003chttps://en.wikipedia.org/wiki/Congruence_relation\u003e`__ (and sets of congruence classes such as finite fields) as objects. A congruence class is defined using a representative integer and a modulus:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from modulo import modulo\n    \u003e\u003e\u003e modulo(3, 7)\n    modulo(3, 7)\n\nBuilt-in operators can be used to perform modular addition, modular subtraction, and modular negation of congruence classes:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e modulo(3, 7) + modulo(5, 7)\n    modulo(1, 7)\n    \u003e\u003e\u003e modulo(1, 7) - modulo(4, 7)\n    modulo(4, 7)\n    \u003e\u003e\u003e -modulo(5, 7)\n    modulo(2, 7)\n\nModular multiplication, division, inversion, and exponentiation are also supported (when they are defined):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e modulo(3, 7) * modulo(5, 7)\n    modulo(1, 7)\n    \u003e\u003e\u003e modulo(1, 7) // modulo(3, 7)\n    modulo(5, 7)\n    \u003e\u003e\u003e modulo(5, 7) ** 2\n    modulo(4, 7)\n    \u003e\u003e\u003e modulo(5, 7) ** (-1)\n    modulo(3, 7)\n\nIndividual congruence classes can be compared with one another according to their least nonnegative residues (and, thus, can also be sorted):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e mod(2, 7) \u003c mod(3, 7)\n    True\n    \u003e\u003e\u003e list(sorted([mod(2, 3), mod(1, 3), mod(0, 3)]))\n    [modulo(0, 3), modulo(1, 3), modulo(2, 3)]\n\nThe membership operation is supported between integers and congruence classes:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e 3 in mod(3, 7)\n    True\n    \u003e\u003e\u003e 10 in mod(3, 7)\n    True\n    \u003e\u003e\u003e 4 in mod(3, 7)\n    False\n\n.. |len| replace:: ``len``\n.. _len: https://docs.python.org/3/library/functions.html#len\n\nA set of congruence classes such as a finite field can also be defined. The built-in length function |len|_ and the membership operator are supported:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e len(modulo(7))\n    7\n    \u003e\u003e\u003e modulo(3, 7) in modulo(7)\n    True\n\n.. |int| replace:: ``int``\n.. _int: https://docs.python.org/3/library/functions.html#int\n\nThe built-in |int|_ function can be used to retrieve the least nonnegative residue of a congruence class and the built-in |len|_ function can be used to retrieve the modulus of a congruence class or set of congruence classes (this is the recommended approach):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e c = modulo(3, 7)\n    \u003e\u003e\u003e int(c)\n    3\n    \u003e\u003e\u003e len(c)\n    7\n\nCongruence classes and sets of congruence classes are also hashable (making it possible to use them as dictionary keys and as set members) and iterable:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e len({mod(0, 3), mod(1, 3), mod(2, 3)})\n    3\n    \u003e\u003e\u003e list(mod(4))\n    [modulo(0, 4), modulo(1, 4), modulo(2, 4), modulo(3, 4)]\n    \u003e\u003e\u003e from itertools import islice\n    \u003e\u003e\u003e list(islice(mod(3, 7), 5))\n    [3, 10, 17, 24, 31]\n\nThe `Chinese remainder theorem \u003chttps://en.wikipedia.org/wiki/Chinese_remainder_theorem\u003e`__ can be applied to construct the intersection of two congruence classes as a congruence class (when it is possible to do so):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e mod(23, 100) \u0026 mod(31, 49)\n    modulo(423, 4900)\n    \u003e\u003e\u003e mod(2, 10) \u0026 mod(4, 20) is None\n    True\n\nSome familiar forms of notation for referring to congruence classes (and sets thereof) are also supported:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e Z/(23*Z)\n    modulo(23)\n    \u003e\u003e\u003e 23*Z\n    modulo(0, 23)\n    \u003e\u003e\u003e 17 + 23*Z\n    modulo(17, 23)\n\nDevelopment\n-----------\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements \u003chttps://peps.python.org/pep-0621\u003e`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip \u003chttps://pypi.org/project/pip\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs,lint]\"\n\nDocumentation\n^^^^^^^^^^^^^\nThe documentation can be generated automatically from the source files using `Sphinx \u003chttps://www.sphinx-doc.org\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs]\"\n    cd docs\n    sphinx-apidoc -f -E --templatedir=_templates -o _source .. \u0026\u0026 make html\n\nTesting and Conventions\n^^^^^^^^^^^^^^^^^^^^^^^\nAll unit tests are executed and their coverage is measured when using `pytest \u003chttps://docs.pytest.org\u003e`__ (see the ``pyproject.toml`` file for configuration details):\n\n.. code-block:: bash\n\n    python -m pip install \".[test]\"\n    python -m pytest\n\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest \u003chttps://docs.python.org/3/library/doctest.html\u003e`__:\n\n.. code-block:: bash\n\n    python src/modulo/modulo.py -v\n\nStyle conventions are enforced using `Pylint \u003chttps://pylint.readthedocs.io\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[lint]\"\n    python -m pylint src/modulo\n\nContributions\n^^^^^^^^^^^^^\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page \u003chttps://github.com/lapets/modulo\u003e`__ for this library.\n\nVersioning\n^^^^^^^^^^\nBeginning with version 0.2.0, the version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 \u003chttps://semver.org/#semantic-versioning-200\u003e`__.\n\nPublishing\n^^^^^^^^^^\nThis library can be published as a `package on PyPI \u003chttps://pypi.org/project/modulo\u003e`__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide \u003chttps://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/\u003e`__.\n\nEnsure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule \u003chttps://docs.readthedocs.io/en/stable/automation-rules.html\u003e`__ that activates and sets as the default all tagged versions.\n\nTo publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):\n\n.. code-block:: bash\n\n    git tag ?.?.?\n    git push origin ?.?.?\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fmodulo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flapets%2Fmodulo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fmodulo/lists"}