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§
Required Associated Types§
type Packing: PackedField<Scalar = Self>
Required Methods§
Sourcefn try_inverse(&self) -> Option<Self>
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
.
Provided Methods§
Sourcefn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Check if the given field element is equal to the unique additive identity (ZERO).
Sourcefn is_one(&self) -> bool
fn is_one(&self) -> bool
Check if the given field element is equal to the unique multiplicative identity (ONE).
Sourcefn inverse(&self) -> Self
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.
Sourcefn halve(&self) -> Self
fn halve(&self) -> Self
The elementary function halve(a) = a/2
.
§Panics
The function will panic if the field has characteristic 2.
Sourcefn div_2exp_u64(&self, exp: u64) -> Self
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.
Sourcefn add_slices(slice_1: &mut [Self], slice_2: &[Self])
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.
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.