UniformSamplingField

Trait UniformSamplingField 

Source
pub trait UniformSamplingField {
    const MAX_SINGLE_SAMPLE_BITS: usize;
    const SAMPLING_BITS_M: [u64; 64];
}
Expand description

Trait for fields that support uniform bit sampling optimizations

Required Associated Constants§

Source

const MAX_SINGLE_SAMPLE_BITS: usize

Maximum number of bits we can sample at negligible (~1/field prime) probability of triggering an error / requiring a resample.

Source

const SAMPLING_BITS_M: [u64; 64]

An array storing the largest value m_k for each k in [0, 31], such that m_k is a multiple of 2^k and less than P. m_k is defined as:

( m_k = ⌊P / 2^k⌋ · 2^k )

This is used as a rejection sampling threshold (or error trigger), when sampling random bits from uniformly sampled field elements. As long as we sample up to the k least significant bits in the range [0, m_k), we sample from exactly m_k elements. As m_k is divisible by 2^k, each of the least significant k bits has exactly the same number of zeroes and ones, leading to a uniform sampling.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<MP> UniformSamplingField for MontyField31<MP>

Source§

const MAX_SINGLE_SAMPLE_BITS: usize = MP::MAX_SINGLE_SAMPLE_BITS

Source§

const SAMPLING_BITS_M: [u64; 64] = MP::SAMPLING_BITS_M

Implementors§