openvm_algebra_guest/field/
mod.rs1use alloc::vec::Vec;
2use core::{
3 fmt::Debug,
4 ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
5};
6
7use crate::{DivAssignUnsafe, DivUnsafe};
8
9pub trait Field:
13 Sized
14 + Eq
15 + Clone
16 + Debug
17 + Neg<Output = Self>
18 + Add<Output = Self>
19 + Sub<Output = Self>
20 + Mul<Output = Self>
21 + for<'a> Add<&'a Self, Output = Self>
22 + for<'a> Sub<&'a Self, Output = Self>
23 + for<'a> Mul<&'a Self, Output = Self>
24 + for<'a> DivUnsafe<&'a Self, Output = Self>
25 + AddAssign
26 + SubAssign
27 + MulAssign
28 + DivAssignUnsafe
29 + for<'a> AddAssign<&'a Self>
30 + for<'a> SubAssign<&'a Self>
31 + for<'a> MulAssign<&'a Self>
32 + for<'a> DivAssignUnsafe<&'a Self>
33{
34 type SelfRef<'a>: Add<&'a Self, Output = Self>
35 + Sub<&'a Self, Output = Self>
36 + Mul<&'a Self, Output = Self>
37 + DivUnsafe<&'a Self, Output = Self>
38 where
39 Self: 'a;
40
41 const ZERO: Self;
43
44 const ONE: Self;
46
47 fn double_assign(&mut self);
49
50 fn square_assign(&mut self);
52
53 fn invert(&self) -> Self {
58 Self::ONE.div_unsafe(self)
59 }
60}
61
62pub trait FieldExtension<BaseField> {
64 const D: usize;
66 type Coeffs: Sized;
69
70 fn from_coeffs(coeffs: Self::Coeffs) -> Self;
72
73 fn from_bytes(bytes: &[u8]) -> Self;
75
76 fn to_coeffs(self) -> Self::Coeffs;
78
79 fn to_bytes(&self) -> Vec<u8>;
81
82 fn embed(base_elem: BaseField) -> Self;
84
85 fn frobenius_map(&self, power: usize) -> Self;
88
89 fn mul_base(&self, rhs: &BaseField) -> Self;
91}
92
93pub trait ComplexConjugate {
94 fn conjugate(self) -> Self;
96
97 fn conjugate_assign(&mut self);
99}