Skip to main content

Field

Trait Field 

pub trait Field:
    Algebra<Self, Output = Self::Packing, Output = Self::Packing, Output = Self::Packing>
    + RawDataSerializable
    + Packable
    + 'static
    + Copy
    + Div<Output = Self>
    + DivAssign
    + Add<Self::Packing>
    + Sub<Self::Packing>
    + Mul<Self::Packing>
    + 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 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§

const GENERATOR: Self

A generator of this field’s multiplicative group.

Required Associated Types§

type Packing: PackedField<Scalar = Self>

Required Methods§

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.

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§

fn is_zero(&self) -> bool

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

fn is_one(&self) -> bool

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

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.

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.

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.

Implementations on Foreign Types§

§

impl Field for Goldilocks

§

const GENERATOR: Goldilocks

§

type Packing = Goldilocks

§

fn is_zero(&self) -> bool

§

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

§

fn order() -> BigUint

§

impl<FP> Field for MontyField31<FP>
where FP: FieldParameters,

§

const GENERATOR: MontyField31<FP> = FP::MONTY_GEN

§

type Packing = MontyField31<FP>

§

fn try_inverse(&self) -> Option<MontyField31<FP>>

§

fn order() -> BigUint

Implementors§

§

impl Field for Felt

§

impl<F> Field for QuinticTrinomialExtensionField<F>
where F: QuinticTrinomialExtendable,

§

const GENERATOR: QuinticTrinomialExtensionField<F>

§

type Packing = QuinticTrinomialExtensionField<F>

§

impl<F, const D: usize> Field for BinomialExtensionField<F, D>
where F: BinomiallyExtendable<D>,

§

const GENERATOR: BinomialExtensionField<F, D>

§

type Packing = BinomialExtensionField<F, D>