use p3_field::extension::{
BinomiallyExtendable, BinomiallyExtendableAlgebra, HasTwoAdicBinomialExtension,
};
use p3_field::{PrimeCharacteristicRing, TwoAdicField, field_to_array};
use crate::Goldilocks;
impl BinomiallyExtendableAlgebra<Self, 2> for Goldilocks {}
impl BinomiallyExtendable<2> for Goldilocks {
const W: Self = Self::new(7);
const DTH_ROOT: Self = Self::new(18446744069414584320);
const EXT_GENERATOR: [Self; 2] = [
Self::new(18081566051660590251),
Self::new(16121475356294670766),
];
}
impl HasTwoAdicBinomialExtension<2> for Goldilocks {
const EXT_TWO_ADICITY: usize = 33;
fn ext_two_adic_generator(bits: usize) -> [Self; 2] {
assert!(bits <= 33);
if bits == 33 {
[Self::ZERO, Self::new(15659105665374529263)]
} else {
[Self::two_adic_generator(bits), Self::ZERO]
}
}
}
impl BinomiallyExtendableAlgebra<Self, 5> for Goldilocks {}
impl BinomiallyExtendable<5> for Goldilocks {
const W: Self = Self::new(3);
const DTH_ROOT: Self = Self::new(1041288259238279555);
const EXT_GENERATOR: [Self; 5] = [Self::TWO, Self::ONE, Self::ZERO, Self::ZERO, Self::ZERO];
}
impl HasTwoAdicBinomialExtension<5> for Goldilocks {
const EXT_TWO_ADICITY: usize = 32;
fn ext_two_adic_generator(bits: usize) -> [Self; 5] {
assert!(bits <= 32);
field_to_array(Self::two_adic_generator(bits))
}
}
#[cfg(test)]
mod test_quadratic_extension {
use num_bigint::BigUint;
use p3_field::extension::BinomialExtensionField;
use p3_field::{ExtensionField, PrimeCharacteristicRing};
use p3_field_testing::{
test_extension_field, test_field, test_packed_extension_field,
test_two_adic_extension_field,
};
use crate::Goldilocks;
type F = Goldilocks;
type EF = BinomialExtensionField<F, 2>;
const ZEROS: [EF; 1] = [EF::ZERO];
const ONES: [EF; 1] = [EF::ONE];
fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 9] {
[
(BigUint::from(2u8), 33),
(BigUint::from(3u8), 1),
(BigUint::from(5u8), 1),
(BigUint::from(7u8), 1),
(BigUint::from(17u8), 1),
(BigUint::from(179u8), 1),
(BigUint::from(257u16), 1),
(BigUint::from(65537u32), 1),
(BigUint::from(7361031152998637u64), 1),
]
}
test_field!(
super::EF,
&super::ZEROS,
&super::ONES,
&super::multiplicative_group_prime_factorization()
);
test_extension_field!(super::F, super::EF);
test_two_adic_extension_field!(super::F, super::EF);
type Pef = <EF as ExtensionField<F>>::ExtensionPacking;
const PACKED_ZEROS: [Pef; 1] = [Pef::ZERO];
const PACKED_ONES: [Pef; 1] = [Pef::ONE];
test_packed_extension_field!(
super::F,
super::EF,
super::Pef,
&super::PACKED_ZEROS,
&super::PACKED_ONES
);
}
#[cfg(test)]
mod test_quintic_extension {
use num_bigint::BigUint;
use p3_field::extension::BinomialExtensionField;
use p3_field::{ExtensionField, PrimeCharacteristicRing};
use p3_field_testing::{
test_extension_field, test_field, test_packed_extension_field,
test_two_adic_extension_field,
};
use crate::Goldilocks;
type F = Goldilocks;
type EF = BinomialExtensionField<F, 5>;
const ZEROS: [EF; 1] = [EF::ZERO];
const ONES: [EF; 1] = [EF::ONE];
fn multiplicative_group_prime_factorization() -> [(num_bigint::BigUint, u32); 10] {
[
(BigUint::from(2u8), 32),
(BigUint::from(3u8), 1),
(BigUint::from(5u8), 2),
(BigUint::from(17u8), 1),
(BigUint::from(257u16), 1),
(BigUint::from(45971u16), 1),
(BigUint::from(65537u32), 1),
(BigUint::from(255006435240067831u64), 1),
(BigUint::from(280083648770327405561u128), 1),
(BigUint::from(7053197395277272939628824863222181u128), 1),
]
}
test_field!(
super::EF,
&super::ZEROS,
&super::ONES,
&super::multiplicative_group_prime_factorization()
);
test_extension_field!(super::F, super::EF);
test_two_adic_extension_field!(super::F, super::EF);
type Pef = <EF as ExtensionField<F>>::ExtensionPacking;
const PACKED_ZEROS: [Pef; 1] = [Pef::ZERO];
const PACKED_ONES: [Pef; 1] = [Pef::ONE];
test_packed_extension_field!(
super::F,
super::EF,
super::Pef,
&super::PACKED_ZEROS,
&super::PACKED_ONES
);
}