1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! The [`Field`] trait: minimal algebraic interface for a finite field.
//!
//! A finite field provides the algebraic operations needed for
//! constraint systems and proof protocols. The trait uses
//! `std::ops` supertraits for arithmetic and adds only `zero`,
//! `one`, and `inv`.
use crateError;
/// A finite field element.
///
/// Implementations must satisfy the field axioms: associativity,
/// commutativity, distributivity of multiplication over addition,
/// and existence of additive and multiplicative inverses.
///
/// # Examples
///
/// ```
/// use field_cat::{BabyBear, Field};
///
/// let a = BabyBear::new(7);
/// let b = BabyBear::new(11);
///
/// // Field axioms hold:
/// assert_eq!(a + BabyBear::zero(), a);
/// assert_eq!(a * BabyBear::one(), a);
/// assert_eq!(a + (-a), BabyBear::zero());
///
/// let a_inv = a.inv()?;
/// assert_eq!(a * a_inv, BabyBear::one());
/// # Ok::<(), field_cat::Error>(())
/// ```