p3_field/extension/
mod.rs1use core::{debug_assert, debug_assert_eq, iter};
2
3use crate::field::Field;
4use crate::{naive_poly_mul, ExtensionField};
5
6mod binomial_extension;
7mod complex;
8
9use alloc::vec;
10use alloc::vec::Vec;
11
12pub use binomial_extension::*;
13pub use complex::*;
14
15pub trait BinomiallyExtendable<const D: usize>: Field {
19 fn w() -> Self;
20
21 fn dth_root() -> Self;
25
26 fn ext_generator() -> [Self; D];
27}
28
29pub trait HasFrobenius<F: Field>: ExtensionField<F> {
30 fn frobenius(&self) -> Self;
31 fn repeated_frobenius(&self, count: usize) -> Self;
32 fn frobenius_inv(&self) -> Self;
33
34 fn minimal_poly(mut self) -> Vec<F> {
35 let mut m = vec![Self::one()];
36 for _ in 0..Self::D {
37 m = naive_poly_mul(&m, &[-self, Self::one()]);
38 self = self.frobenius();
39 }
40 let mut m_iter = m
41 .into_iter()
42 .map(|c| c.as_base().expect("Extension is not algebraic?"));
43 let m: Vec<F> = m_iter.by_ref().take(Self::D + 1).collect();
44 debug_assert_eq!(m.len(), Self::D + 1);
45 debug_assert_eq!(m.last(), Some(&F::one()));
46 debug_assert!(m_iter.all(|c| c.is_zero()));
47 m
48 }
49
50 fn galois_group(self) -> Vec<Self> {
51 iter::successors(Some(self), |x| Some(x.frobenius()))
52 .take(Self::D)
53 .collect()
54 }
55}
56
57pub trait HasTwoAdicBionmialExtension<const D: usize>: BinomiallyExtendable<D> {
59 const EXT_TWO_ADICITY: usize;
60
61 fn ext_two_adic_generator(bits: usize) -> [Self; D];
64}