Skip to main content

FixedTrinomialSolinas64

Struct FixedTrinomialSolinas64 

Source
pub struct FixedTrinomialSolinas64<const P1: u8, const P2: u8, const K: i64>();
Expand description

A modular reducer for trinomial Solinas numbers 2^P1 - 2^P2 + K as modulus with 64-bit operands.

Supports P1 up to 64, P2 < P1, and odd signed K with |K| < 2^P2. All inputs and outputs are u64. Uses u128 as the double-width intermediate for multiplication and reduction. The modulus 2^P1 - 2^P2 + K must be prime for modular inverse and Fermat-based operations to be valid.

§Example

use num_modular::{FixedTrinomialSolinas64, Reducer};

const P1: u8 = 6;
const P2: u8 = 2;
const K: i64 = 1;
let modulus = (1u64 << P1) - (1u64 << P2) + (K as u64); // 2^6 - 2^2 + 1 = 61
let reducer = FixedTrinomialSolinas64::<P1, P2, K>::new(&modulus);
let a = reducer.transform(10);
let b = reducer.transform(20);
assert_eq!(reducer.residue(reducer.mul(&a, &b)), (10u64 * 20) % 61);

Implementations§

Source§

impl<const P1: u8, const P2: u8, const K: i64> FixedTrinomialSolinas64<P1, P2, K>

Source

pub const MODULUS: u64

Trait Implementations§

Source§

impl<const P1: u8, const P2: u8, const K: i64> Clone for FixedTrinomialSolinas64<P1, P2, K>

Source§

fn clone(&self) -> FixedTrinomialSolinas64<P1, P2, K>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const P1: u8, const P2: u8, const K: i64> Copy for FixedTrinomialSolinas64<P1, P2, K>

Source§

impl<const P1: u8, const P2: u8, const K: i64> Debug for FixedTrinomialSolinas64<P1, P2, K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const P1: u8, const P2: u8, const K: i64> Reducer<u64> for FixedTrinomialSolinas64<P1, P2, K>

Source§

fn new(m: &u64) -> Self

Create a reducer for a modulus m
Source§

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

Transform a normal integer into reduced form
Source§

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

Check whether target is a valid reduced form
Source§

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

Transform a reduced form back to normal integer
Source§

fn modulus(&self) -> u64

Get the modulus in original integer type
Source§

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

Test if the residue() == 0
Source§

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

Calculate (lhs + rhs) mod m in reduced form
Source§

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

Calculate (lhs - rhs) mod m in reduced form
Source§

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

Calculate 2*target mod m
Source§

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

Calculate -monty mod m in reduced form
Source§

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

Calculate (lhs * rhs) mod m in reduced form
Source§

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

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

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

Calculate target^2 mod m in reduced form
Source§

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

Calculate base ^ exp mod m in reduced form
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)

Auto Trait Implementations§

§

impl<const P1: u8, const P2: u8, const K: i64> Freeze for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> RefUnwindSafe for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> Send for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> Sync for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> Unpin for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> UnsafeUnpin for FixedTrinomialSolinas64<P1, P2, K>

§

impl<const P1: u8, const P2: u8, const K: i64> UnwindSafe for FixedTrinomialSolinas64<P1, P2, K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.