An algorithm that computes modular nested exponentiation efficiently
Project description
modular-nested-exponentiation
An algorithm that computes modular nested exponentiation efficiently.
License | Version | ||
Wheel | Implementation | ||
Status | Supported versions |
Generalised modular exponentiation
We present an algorithm that takes as input an arbitrarily long sequence of positive integers a₁, 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).
Without this algorithm, this type of computation is unfeasible for modern computers even for short input sequences containing small integers.
Prerequisites
# cpython makes the computations more efficient
$ apt install libgmp-dev libmpfr-dev libmpc-dev
$ pip install sympy gmpy2
Install
$ pip install mod-nest-exp
Usage
$ python
>>> from mod_nest_exp import mod_nest_exp
>>> mod_nest_exp([6, 5, 4, 3, 2], 1948502738)
mpz(951546056) # uses gmpy2 if available
To-do
- add a factorisation module in case the user does not have
sympy
installed
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
mod-nest-exp-1.0.4.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for mod_nest_exp-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f382513f37a8f0bcc7fa96ba871b8b12751ade1c4685169dd7c8470f57bae0db |
|
MD5 | 3000c213e0495b40f9ca914f1441cb65 |
|
BLAKE2b-256 | b0b2458942eebad0aed9c56d8a1b3b6b7a917cfa67f12407b780ad6c9ba755c5 |