Skip to main content

PackedGf2

Struct PackedGf2 

Source
pub struct PackedGf2<U: Underlier>(/* private fields */);
Expand description

Several independent elements of GF(2), one per bit of a block of storage.

Lane i is bit i mod B of word i / B, counting from the least significant bit. Read as bytes, that puts lane i at bit i mod 8 of byte i / 8.

This is the order a bit witness already has on the wire, so packing one moves no bits.

The arithmetic is what the field does to one bit, applied to the whole block at once:

    a + b   ->  a XOR b
    a * b   ->  a AND b
    a^2     ->  a

Implementations§

Source§

impl<U: Underlier> PackedGf2<U>

Source

pub const WIDTH: usize = U::BITS

How many independent elements one value holds.

Source

pub const fn new(bits: U) -> Self

The packing over a block of storage, read lane for bit.

Source

pub const fn to_bits(self) -> U

The block of storage behind the packing.

Source

pub fn words(&self) -> &[U::Word]

The backing words, lowest lanes first.

Source

pub fn words_mut(&mut self) -> &mut [U::Word]

The backing words, lowest lanes first.

Every bit pattern is a valid packing, so writing here cannot break an invariant.

Source

pub fn get(&self, lane: usize) -> Gf2

The element in the given lane.

§Panics

Panics if the lane index is not below the width.

Source

pub fn set(&mut self, lane: usize, value: Gf2)

Overwrite the element in the given lane.

§Panics

Panics if the lane index is not below the width.

Source

pub fn from_fn(f: impl FnMut(usize) -> Gf2) -> Self

Build a value lane by lane.

Source

pub fn broadcast(value: Gf2) -> Self

The same element in every lane.

Source

pub fn lanes(self) -> impl Iterator<Item = Gf2>

The lanes, lowest first.

Source

pub fn count_ones(&self) -> u32

How many lanes hold one.

Source

pub const fn invert_or_zero(self) -> Self

The lane-wise inverse, with zero sent to zero.

One is the only invertible element of GF(2) and it is its own inverse.

Extending the map by 0^-1 = 0 therefore makes it the identity on every lane.

Source

pub fn narrow<V: Underlier>(&self) -> &[PackedGf2<V>]
where U: Divisible<V>,

This value read as a run of narrower packings, lowest lanes first.

A wide block is narrow ones side by side: lane i is lane i mod w of part i / w.

Source

pub fn narrow_mut<V: Underlier>(&mut self) -> &mut [PackedGf2<V>]
where U: Divisible<V>,

This value read as a run of narrower packings, lowest lanes first.

Source

pub fn narrow_slice<V: Underlier>(slice: &[Self]) -> &[PackedGf2<V>]
where U: Divisible<V>,

A run of these packings read as a run of narrower ones, lowest lanes first.

The same bytes carry the same lanes in order, so a narrower read copies nothing.

Source

pub fn narrow_slice_mut<V: Underlier>(slice: &mut [Self]) -> &mut [PackedGf2<V>]
where U: Divisible<V>,

A run of these packings read as a run of narrower ones, lowest lanes first.

Source

pub const fn as_bytes(slice: &[Self]) -> &[u8] ⓘ

A run of these packings read as bytes, lowest lanes first.

Byte k holds lanes 8k .. 8k + 8, lowest lane at the lowest bit.

Source

pub fn interleave(&self, other: Self, block_len: usize) -> (Self, Self)

Cut both operands into chunks of block_len lanes and interleave the chunks.

Cut the stack of the two into two-by-two matrices of chunks, and transpose each:

    A = [x0, y0, x1, y1]
    B = [x2, y2, x3, y3]

    block_len = 1  ->  ([x0, x2, x1, x3], [y0, y2, y1, y3])

A chunk as wide as the value leaves both operands untouched.

This is the convention the packed-field trait fixes. So a caller can swap a bit-sliced packing for any other and see one permutation.

§Panics

Panics unless the chunk length is a power of two no larger than the width.

Source§

impl<U: Underlier> PackedGf2<U>

Source

pub fn transpose(rows: &mut [Self])

Replace the square bit matrix whose row i is rows[i] by its transpose.

Lane c of row r becomes lane r of row c.

§Panics

Panics unless the matrix has exactly as many rows as the packing has lanes.

Trait Implementations§

Source§

impl<U: Underlier> Add for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<U: Underlier> Add<Gf2> for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Gf2) -> Self

Performs the + operation. Read more
Source§

impl<U: Underlier, T: Into<Self>> AddAssign<T> for PackedGf2<U>

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<U: Underlier> Algebra<Gf2> for PackedGf2<U>

Source§

fn quadratic_extension_square(a: &[Self; 2], w: F) -> [Self; 2]

Square a[0] + a[1] X modulo X^2 - w. Read more
Source§

fn mixed_dot_product<const N: usize>(a: &[Self; N], f: &[F; N]) -> Self
where F: Dup,

Dot product between algebra elements and base field scalars. Read more
Source§

const BATCHED_LC_CHUNK: usize = 8

Optimal chunk size for batched_linear_combination. Read more
Source§

fn batched_linear_combination(values: &[Self], coeffs: &[F]) -> Self
where F: Dup,

Runtime-length linear combination: Σ values[i] * coeffs[i]. Read more
Source§

impl<U: Clone + Underlier> Clone for PackedGf2<U>

Source§

fn clone(&self) -> Self

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<U: Copy + Underlier> Copy for PackedGf2<U>

Source§

impl<U: Underlier> Debug for PackedGf2<U>

Source§

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

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

impl<U: Default + Underlier> Default for PackedGf2<U>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<U: Underlier> Distribution<PackedGf2<U>> for StandardUniform

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PackedGf2<U>

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T> ⓘ
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl<U: Underlier> Div<Gf2> for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Gf2) -> Self

Performs the / operation. Read more
Source§

impl<U: Underlier> DivAssign<Gf2> for PackedGf2<U>

Source§

fn div_assign(&mut self, rhs: Gf2)

Performs the /= operation. Read more
Source§

impl<U: Eq + Underlier> Eq for PackedGf2<U>

Source§

impl<U: Underlier> From<Gf2> for PackedGf2<U>

Source§

fn from(value: Gf2) -> Self

Converts to this type from the input type.
Source§

impl<U: Hash + Underlier> Hash for PackedGf2<U>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<U: Underlier> Mul for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl<U: Underlier> Mul<Gf2> for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Gf2) -> Self

Performs the * operation. Read more
Source§

impl<U: Underlier, T: Into<Self>> MulAssign<T> for PackedGf2<U>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<U: Underlier> Neg for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<U: PartialEq + Underlier> PartialEq for PackedGf2<U>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<U: Underlier> PrimeCharacteristicRing for PackedGf2<U>

Source§

fn halve(&self) -> Self

§Panics

Always panics: 2 is not invertible in characteristic 2.

Source§

fn div_2exp_u64(&self, _exp: u64) -> Self

§Panics

Always panics: 2 is not invertible in characteristic 2.

Source§

const ZERO: Self

The additive identity of the ring. Read more
Source§

const ONE: Self

The multiplicative identity of the ring. Read more
Source§

const TWO: Self

The element in the ring given by ONE + ONE. Read more
Source§

const NEG_ONE: Self

The element in the ring given by -ONE. Read more
Source§

type PrimeSubfield = Gf2

The field ℤ/p where the characteristic of this ring is p.
Source§

fn from_prime_subfield(f: Self::PrimeSubfield) -> Self

Embed an element of the prime field ℤ/p into the ring R. Read more
Source§

fn from_bool(b: bool) -> Self

Return Self::ONE if b is true and Self::ZERO if b is false.
Source§

fn double(&self) -> Self

The elementary function double(a) = 2*a. Read more
Source§

fn xor(&self, y: &Self) -> Self

Computes the arithmetic generalization of boolean xor. Read more
Source§

fn mul_2exp_u64(&self, exp: u64) -> Self

The elementary function mul_2exp_u64(a, exp) = a * 2^{exp}. Read more
Source§

fn square(&self) -> Self

The elementary function square(a) = a^2. Read more
Source§

fn andn(&self, y: &Self) -> Self

Computes the arithmetic generalization of andnot. Read more
Source§

fn bool_check(&self) -> Self

The vanishing polynomial for boolean values: x * (x - 1). Read more
Source§

fn from_u8(int: u8) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_u16(int: u16) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_u32(int: u32) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_u64(int: u64) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_u128(int: u128) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_usize(int: usize) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_i8(int: i8) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_i16(int: i16) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_i32(int: i32) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_i64(int: i64) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_i128(int: i128) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn from_isize(int: isize) -> Self

Given an integer r, return the sum of r copies of ONE: Read more
Source§

fn cube(&self) -> Self

The elementary function cube(a) = a^3. Read more
Source§

fn xor3(&self, y: &Self, z: &Self) -> Self

Computes the arithmetic generalization of a triple xor. Read more
Source§

fn exp_u64(&self, power: u64) -> Self

Exponentiation by a u64 power. Read more
Source§

fn exp_const_u64<const POWER: u64>(&self) -> Self

Exponentiation by a small constant power. Read more
Source§

fn exp_power_of_2(&self, power_log: usize) -> Self

The elementary function exp_power_of_2(a, power_log) = a^{2^power_log}. Read more
Source§

fn powers(&self) -> Powers<Self> ⓘ

Construct an iterator which returns powers of self: self^0, self^1, self^2, ....
Source§

fn shifted_powers(&self, start: Self) -> Powers<Self> ⓘ

Construct an iterator which returns powers of self shifted by start: start, start*self^1, start*self^2, ....
Source§

fn dot_product<const N: usize>(u: &[Self; N], v: &[Self; N]) -> Self

Compute the dot product of two vectors. Read more
Source§

fn sum_array<const N: usize>(input: &[Self]) -> Self

Compute the sum of a slice of elements whose length is a compile time constant. Read more
Source§

fn zero_vec(len: usize) -> Vec<Self>

Allocates a vector of zero elements of length len. Many operating systems zero pages before assigning them to a userspace process. In that case, our process should not need to write zeros, which would be redundant. However, the compiler may not always recognize this. Read more
Source§

impl<U: Underlier> Product for PackedGf2<U>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<U: PartialEq + Underlier> StructuralPartialEq for PackedGf2<U>

Source§

impl<U: Underlier> Sub for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<U: Underlier> Sub<Gf2> for PackedGf2<U>

Source§

type Output = PackedGf2<U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Gf2) -> Self

Performs the - operation. Read more
Source§

impl<U: Underlier, T: Into<Self>> SubAssign<T> for PackedGf2<U>

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl<U: Underlier> Sum for PackedGf2<U>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

§

impl<U> Freeze for PackedGf2<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for PackedGf2<U>
where U: RefUnwindSafe,

§

impl<U> Send for PackedGf2<U>

§

impl<U> Sync for PackedGf2<U>

§

impl<U> Unpin for PackedGf2<U>
where U: Unpin,

§

impl<U> UnsafeUnpin for PackedGf2<U>
where U: UnsafeUnpin,

§

impl<U> UnwindSafe for PackedGf2<U>
where U: UnwindSafe,

Blanket Implementations§

Source§

impl<R> Algebra<R> for R

Source§

fn mixed_dot_product<const N: usize>(a: &[R; N], f: &[R; N]) -> R

Dot product between algebra elements and base field scalars. Read more
Source§

fn quadratic_extension_square(a: &[Self; 2], w: F) -> [Self; 2]

Square a[0] + a[1] X modulo X^2 - w. Read more
Source§

const BATCHED_LC_CHUNK: usize = 8

Optimal chunk size for batched_linear_combination. Read more
Source§

fn batched_linear_combination(values: &[Self], coeffs: &[F]) -> Self
where F: Dup,

Runtime-length linear combination: Σ values[i] * coeffs[i]. Read more
Source§

impl<F> AlgebraIdentity<F> for F

Source§

fn algebra_id() -> Vec<u8> ⓘ

Return the stable, unambiguous identifier of the defining relations and basis.
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<F> BasedVectorSpace<F> for F

Source§

const DIMENSION: usize = 1

The dimension of the vector space, i.e. the number of elements in its basis.
Source§

fn as_basis_coefficients_slice(&self) -> &[F]

Fixes a basis for the algebra A and uses this to map an element of A to a slice of DIMENSION F elements. Read more
Source§

fn from_basis_coefficients_fn<Fn>(f: Fn) -> F
where Fn: FnMut(usize) -> F,

Fixes a basis for the algebra A and uses this to map DIMENSION F elements to an element of A. Similar to core:array::from_fn, the DIMENSION F elements are given by Fn(0), ..., Fn(DIMENSION - 1) called in that order. Read more
Source§

fn from_basis_coefficients_iter<I>(iter: I) -> Option<F>
where I: ExactSizeIterator<Item = F>,

Fixes a basis for the algebra A and uses this to map DIMENSION F elements to an element of A. Read more
Source§

fn flatten_to_base(vec: Vec<F>) -> Vec<F>

Convert from a vector of Self to a vector of F by flattening the basis coefficients. Read more
Source§

fn reconstitute_from_base(vec: Vec<F>) -> Vec<F>

Convert from a vector of F to a vector of Self by combining the basis coefficients. Read more
Source§

fn from_basis_coefficients_slice(slice: &[F]) -> Option<Self>

Fixes a basis for the algebra A and uses this to map DIMENSION F elements to an element of A. Read more
Source§

fn ith_basis_element(i: usize) -> Option<Self>

Given a basis for the Algebra A, return the i’th basis element. 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> Dup for T
where T: Copy + Clone,

Source§

fn dup(&self) -> T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> SpongePaddingValue for T

Source§

const PAD_ZERO: T = Self::ZERO

The empty-lane value.
Source§

const PAD_ONE: T = Self::ONE

The delimiter value injected after the final absorbed element.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more