Trait num_modular::Reducer

source ·
pub trait Reducer<T> {
Show 17 methods // Required methods fn new(m: &T) -> Self; fn transform(&self, target: T) -> T; fn check(&self, target: &T) -> bool; fn modulus(&self) -> T; fn residue(&self, target: T) -> T; fn is_zero(&self, target: &T) -> bool; fn add(&self, lhs: &T, rhs: &T) -> T; fn dbl(&self, target: T) -> T; fn sub(&self, lhs: &T, rhs: &T) -> T; fn neg(&self, target: T) -> T; fn mul(&self, lhs: &T, rhs: &T) -> T; fn inv(&self, target: T) -> Option<T>; fn sqr(&self, target: T) -> T; fn pow(&self, base: T, exp: &T) -> T; // Provided methods fn add_in_place(&self, lhs: &mut T, rhs: &T) { ... } fn sub_in_place(&self, lhs: &mut T, rhs: &T) { ... } fn mul_in_place(&self, lhs: &mut T, rhs: &T) { ... }
}
Expand description

A modular reducer that can ensure that the operations on integers are all performed in a modular ring.

Essential information for performing the modulo operation will be stored in the reducer.

Required Methods§

source

fn new(m: &T) -> Self

Create a reducer for a modulus m

source

fn transform(&self, target: T) -> T

Transform a normal integer into reduced form

source

fn check(&self, target: &T) -> bool

Check whether target is a valid reduced form

source

fn modulus(&self) -> T

Get the modulus in original integer type

source

fn residue(&self, target: T) -> T

Transform a reduced form back to normal integer

source

fn is_zero(&self, target: &T) -> bool

Test if the residue() == 0

source

fn add(&self, lhs: &T, rhs: &T) -> T

Calculate (lhs + rhs) mod m in reduced form

source

fn dbl(&self, target: T) -> T

Calculate 2*target mod m

source

fn sub(&self, lhs: &T, rhs: &T) -> T

Calculate (lhs - rhs) mod m in reduced form

source

fn neg(&self, target: T) -> T

Calculate -monty mod m in reduced form

source

fn mul(&self, lhs: &T, rhs: &T) -> T

Calculate (lhs * rhs) mod m in reduced form

source

fn inv(&self, target: T) -> Option<T>

Calculate target^-1 mod m in reduced form, it may return None when there is no modular inverse.

source

fn sqr(&self, target: T) -> T

Calculate target^2 mod m in reduced form

source

fn pow(&self, base: T, exp: &T) -> T

Calculate base ^ exp mod m in reduced form

Provided Methods§

source

fn add_in_place(&self, lhs: &mut T, rhs: &T)

source

fn sub_in_place(&self, lhs: &mut T, rhs: &T)

source

fn mul_in_place(&self, lhs: &mut T, rhs: &T)

Implementors§