Skip to main content

An algorithm that computes modular nested exponents (or towers) efficiently.

Project description

modular-towers

An algorithm that computes modular nested exponents (or towers) efficiently.

GitHub Workflow Status (branch) PyPI - License PyPI PyPI - Python Version PyPI - Wheel GitHub issues Downloads

🚩 Table of Contents

🗺️ Overview

modular-towers exports a Python function mod_tower that takes as input an arbitrarily long sequence of positive integers a₁, a₂, ..., aₙ and a positive integer m and computes a₁^(a₂^(···^aₙ)) mod m efficiently (that is, without computing the value of the nested exponent).

🏳️ Prerequisites

sympy is currently required as the algorithm uses its totient function. In the future, a custom totient function will be added so that sympy is not required, making the module self-contained.

For best performance, install gmpy2:

$ apt install libgmp-dev libmpfr-dev libmpc-dev # required for gmpy2
$ pip install gmpy2

gmpy2 is not required but it offers more efficient versions of some of Python's built-in math functions. If gmpy2 is not installed, the module simply uses the built-in functions.

🔧 Installation

Installing with pip is the easiest:

$ pip install modular-towers

A development version can be installed from GitHub using setuptools, provided you have sympy installed already:

$ git clone https://github.com/avivbrook/modular-towers
$ cd modular-towers
$ python setup.py install

💡 Examples

>>> from modular_towers import mod_tower as modtow
>>> modtow([6,5,4,3,2], 1948502738) # 6^(5^(4^(3^2))) mod 1948502738
951546056

To benchmark the main function:

>>> from modular_towers.core.tests import test_core
>>> test_core(list_lengths=(10, 100, 1000), bit_lengths=(16, 128, 1024), mod_bit_lengths=(16, 32, 64))

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

modular-towers-0.1.2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

modular_towers-0.1.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file modular-towers-0.1.2.tar.gz.

File metadata

  • Download URL: modular-towers-0.1.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for modular-towers-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2be1fbe7943a56e46659a85b88a62fbd47e53dd2eb884096e001008db11d777e
MD5 b98f0b773a0ea2f8e275e46966d503e6
BLAKE2b-256 c22fe4dcf932ff0f94eeda77a2fc108016b564bc78761819119bcb519dcf934a

See more details on using hashes here.

File details

Details for the file modular_towers-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: modular_towers-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for modular_towers-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea57a2b6e92937b294427c7594401c892e8dc7c4432e5d0fdb228fcbee853b8
MD5 324ed9b48cb04c754ea662b141f65700
BLAKE2b-256 f0bf85c4358dcbb9ac84846b4563d57b1bdb51cdfb96bc6836b0208902404791

See more details on using hashes here.

Supported by

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