Trait malachite_base::num::arithmetic::traits::ModInverse

source ·
pub trait ModInverse<M = Self> {
    type Output;

    // Required method
    fn mod_inverse(self, m: M) -> Option<Self::Output>;
}
Expand description

Finds the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Required Associated Types§

Required Methods§

source

fn mod_inverse(self, m: M) -> Option<Self::Output>

Implementations on Foreign Types§

source§

impl ModInverse for u8

source§

fn mod_inverse(self, m: u8) -> Option<u8>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = u8

source§

impl ModInverse for u16

source§

fn mod_inverse(self, m: u16) -> Option<u16>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = u16

source§

impl ModInverse for u32

source§

fn mod_inverse(self, m: u32) -> Option<u32>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = u32

source§

impl ModInverse for u64

source§

fn mod_inverse(self, m: u64) -> Option<u64>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = u64

source§

impl ModInverse for u128

source§

fn mod_inverse(self, m: u128) -> Option<u128>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = u128

source§

impl ModInverse for usize

source§

fn mod_inverse(self, m: usize) -> Option<usize>

Computes the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.

Returns None if $x$ and $m$ are not coprime.

$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits()).

§Panics

Panics if self is greater than or equal to m.

§Examples

See here.

§

type Output = usize

Implementors§