Field

Trait Field 

Source
pub trait Field:
    Algebra<Self>
    + RawDataSerializable
    + Packable
    + 'static
    + Copy
    + Div<Self, Output = Self>
    + Eq
    + Hash
    + Send
    + Sync
    + Display
    + Serialize
    + DeserializeOwned {
    type Packing: PackedField<Scalar = Self>;

    const GENERATOR: Self;

    // Required methods
    fn try_inverse(&self) -> Option<Self>;
    fn order() -> BigUint;

    // Provided methods
    fn is_zero(&self) -> bool { ... }
    fn is_one(&self) -> bool { ... }
    fn inverse(&self) -> Self { ... }
    fn halve(&self) -> Self { ... }
    fn div_2exp_u64(&self, exp: u64) -> Self { ... }
    fn add_slices(slice_1: &mut [Self], slice_2: &[Self]) { ... }
    fn bits() -> usize { ... }
}
Expand description

A field F. This permits both modular fields ℤ/p along with their field extensions.

A ring is a field if every element x has a unique multiplicative inverse x^{-1} which satisfies x * x^{-1} = F::ONE.

Required Associated Constants§

Source

const GENERATOR: Self

A generator of this field’s multiplicative group.

Required Associated Types§

Source

type Packing: PackedField<Scalar = Self>

Required Methods§

Source

fn try_inverse(&self) -> Option<Self>

The multiplicative inverse of this field element, if it exists.

NOTE: The inverse of 0 is undefined and will return None.

Source

fn order() -> BigUint

The number of elements in the field.

This will either be prime if the field is a PrimeField or a power of a prime if the field is an extension field.

Provided Methods§

Source

fn is_zero(&self) -> bool

Check if the given field element is equal to the unique additive identity (ZERO).

Source

fn is_one(&self) -> bool

Check if the given field element is equal to the unique multiplicative identity (ONE).

Source

fn inverse(&self) -> Self

The multiplicative inverse of this field element.

§Panics

The function will panic if the field element is 0. Use try_inverse if you want to handle this case.

Source

fn halve(&self) -> Self

The elementary function halve(a) = a/2.

§Panics

The function will panic if the field has characteristic 2.

Source

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

Divide by a given power of two. div_2exp_u64(a, exp) = a/2^exp

§Panics

The function will panic if the field has characteristic 2.

Source

fn add_slices(slice_1: &mut [Self], slice_2: &[Self])

Add two slices of field elements together, returning the result in the first slice.

Makes use of packing to speed up the addition.

This is optimal for cases where the two slices are small to medium length. E.g. between F::Packing::WIDTH and roughly however many elements fit in a cache line.

For larger slices, it’s likely worthwhile to use parallelization before calling this. Similarly if you need to add a large number of slices together, it’s best to break them into small chunks and call this on the smaller chunks.

§Panics

The function will panic if the lengths of the two slices are not equal.

Source

fn bits() -> usize

The number of bits required to define an element of this field.

Usually due to storage and practical reasons the memory size of a field element will be a little larger than bits().

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.

Implementors§