pub struct BFieldElement(/* private fields */);Expand description
A field element in the Goldilocks prime field (mod 2^64 - 2^32 + 1).
Stored as a canonical u64 value in [0, p). Arithmetic
promotes to u128 to avoid u64 overflow.
The name BFieldElement (Base Field Element) follows the
convention from the Triton VM / twenty-first ecosystem. In
the Plonky3 ecosystem the same field is called Goldilocks.
§Examples
use field_cat::{BFieldElement, Field};
let a = BFieldElement::new(42);
let b = BFieldElement::new(7);
assert_eq!((a * b).value(), 294);
// Multiplicative inverse via Fermat's little theorem.
let a_inv = a.inv()?;
assert_eq!(a * a_inv, BFieldElement::one());Implementations§
Trait Implementations§
Source§impl Add for BFieldElement
impl Add for BFieldElement
Source§impl Clone for BFieldElement
impl Clone for BFieldElement
Source§fn clone(&self) -> BFieldElement
fn clone(&self) -> BFieldElement
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BFieldElement
impl Debug for BFieldElement
Source§impl Display for BFieldElement
impl Display for BFieldElement
Source§impl Field for BFieldElement
impl Field for BFieldElement
Source§impl FieldBytes for BFieldElement
impl FieldBytes for BFieldElement
Source§impl Hash for BFieldElement
impl Hash for BFieldElement
Source§impl Mul for BFieldElement
impl Mul for BFieldElement
Source§impl Neg for BFieldElement
impl Neg for BFieldElement
Source§impl PartialEq for BFieldElement
impl PartialEq for BFieldElement
Source§fn eq(&self, other: &BFieldElement) -> bool
fn eq(&self, other: &BFieldElement) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Sub for BFieldElement
impl Sub for BFieldElement
impl Copy for BFieldElement
impl Eq for BFieldElement
impl StructuralPartialEq for BFieldElement
Auto Trait Implementations§
impl Freeze for BFieldElement
impl RefUnwindSafe for BFieldElement
impl Send for BFieldElement
impl Sync for BFieldElement
impl Unpin for BFieldElement
impl UnsafeUnpin for BFieldElement
impl UnwindSafe for BFieldElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more