Trait malachite_base::num::arithmetic::traits::ModPowPrecomputed
source · [−]pub trait ModPowPrecomputed<RHS = Self, M = Self> where
Self: Sized, {
type Output;
type Data;
fn precompute_mod_pow_data(m: &M) -> Self::Data;
fn mod_pow_precomputed(
self,
exp: RHS,
m: M,
data: &Self::Data
) -> Self::Output;
}
Expand description
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
If multiple modular exponentiations with the same modulus are necessary, it can be quicker to precompute some piece of data and reuse it in the exponentiation calls. This trait provides a function for precomputing the data and a function for using it during exponentiation.
Required Associated Types
Required Methods
fn precompute_mod_pow_data(m: &M) -> Self::Data
fn precompute_mod_pow_data(m: &M) -> Self::Data
Precomputes some data to use for modular exponentiation.
fn mod_pow_precomputed(self, exp: RHS, m: M, data: &Self::Data) -> Self::Output
Implementations on Foreign Types
sourceimpl ModPowPrecomputed<u64, u32> for u32
impl ModPowPrecomputed<u64, u32> for u32
sourcefn precompute_mod_pow_data(m: &u32) -> (u32, u64)
fn precompute_mod_pow_data(m: &u32) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: u32, data: &(u32, u64)) -> u32
fn mod_pow_precomputed(self, exp: u64, m: u32, data: &(u32, u64)) -> u32
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.
type Output = u32
type Data = (u32, u64)
sourceimpl ModPowPrecomputed<u64, u64> for u64
impl ModPowPrecomputed<u64, u64> for u64
sourcefn precompute_mod_pow_data(m: &u64) -> (u64, u64)
fn precompute_mod_pow_data(m: &u64) -> (u64, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: u64, data: &(u64, u64)) -> u64
fn mod_pow_precomputed(self, exp: u64, m: u64, data: &(u64, u64)) -> u64
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.
type Output = u64
type Data = (u64, u64)
sourceimpl ModPowPrecomputed<u64, u8> for u8
impl ModPowPrecomputed<u64, u8> for u8
sourcefn precompute_mod_pow_data(m: &u8) -> (u32, u64)
fn precompute_mod_pow_data(m: &u8) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: u8, data: &(u32, u64)) -> u8
fn mod_pow_precomputed(self, exp: u64, m: u8, data: &(u32, u64)) -> u8
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.
type Output = u8
type Data = (u32, u64)
sourceimpl ModPowPrecomputed<u64, u16> for u16
impl ModPowPrecomputed<u64, u16> for u16
sourcefn precompute_mod_pow_data(m: &u16) -> (u32, u64)
fn precompute_mod_pow_data(m: &u16) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: u16, data: &(u32, u64)) -> u16
fn mod_pow_precomputed(self, exp: u64, m: u16, data: &(u32, u64)) -> u16
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.
type Output = u16
type Data = (u32, u64)
sourceimpl ModPowPrecomputed<u64, u128> for u128
impl ModPowPrecomputed<u64, u128> for u128
sourcefn precompute_mod_pow_data(_m: &u128)
fn precompute_mod_pow_data(_m: &u128)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: u128, _data: &()) -> u128
fn mod_pow_precomputed(self, exp: u64, m: u128, _data: &()) -> u128
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several modular
exponentiations with the same modulus. The precomputed data should be obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.
type Output = u128
type Data = ()
sourceimpl ModPowPrecomputed<u64, usize> for usize
impl ModPowPrecomputed<u64, usize> for usize
sourcefn precompute_mod_pow_data(m: &usize) -> (usize, u64)
fn precompute_mod_pow_data(m: &usize) -> (usize, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
Worst-case complexity
Constant time and additional memory.
sourcefn mod_pow_precomputed(self, exp: u64, m: usize, data: &(usize, u64)) -> usize
fn mod_pow_precomputed(self, exp: u64, m: usize, data: &(usize, u64)) -> usize
Raises a number to a power modulo another number $m$. Assumes the input is already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several modular
exponentiations with the same modulus. The precomputed data should be obtained using
precompute_mod_pow_data
.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
Examples
See here.