p3_goldilocks/
extension.rs1use p3_field::extension::{
2 BinomiallyExtendable, BinomiallyExtendableAlgebra, HasTwoAdicBinomialExtension,
3};
4use p3_field::{PrimeCharacteristicRing, TwoAdicField, field_to_array};
5
6use crate::Goldilocks;
7
8impl BinomiallyExtendableAlgebra<Self, 2> for Goldilocks {}
9
10impl BinomiallyExtendable<2> for Goldilocks {
11 const W: Self = Self::new(7);
14
15 const DTH_ROOT: Self = Self::new(18446744069414584320);
17
18 const EXT_GENERATOR: [Self; 2] = [
19 Self::new(18081566051660590251),
20 Self::new(16121475356294670766),
21 ];
22}
23
24impl HasTwoAdicBinomialExtension<2> for Goldilocks {
25 const EXT_TWO_ADICITY: usize = 33;
26
27 fn ext_two_adic_generator(bits: usize) -> [Self; 2] {
28 assert!(bits <= 33);
29
30 if bits == 33 {
31 [Self::ZERO, Self::new(15659105665374529263)]
32 } else {
33 [Self::two_adic_generator(bits), Self::ZERO]
34 }
35 }
36}
37
38impl BinomiallyExtendableAlgebra<Self, 5> for Goldilocks {}
39
40impl BinomiallyExtendable<5> for Goldilocks {
41 const W: Self = Self::new(3);
54
55 const DTH_ROOT: Self = Self::new(1041288259238279555);
57
58 const EXT_GENERATOR: [Self; 5] = [Self::TWO, Self::ONE, Self::ZERO, Self::ZERO, Self::ZERO];
62}
63
64impl HasTwoAdicBinomialExtension<5> for Goldilocks {
65 const EXT_TWO_ADICITY: usize = 32;
66
67 fn ext_two_adic_generator(bits: usize) -> [Self; 5] {
68 assert!(bits <= 32);
69
70 field_to_array(Self::two_adic_generator(bits))
71 }
72}
73
74#[cfg(test)]
75mod test_quadratic_extension {
76
77 use num_bigint::BigUint;
78 use p3_field::extension::BinomialExtensionField;
79 use p3_field::{ExtensionField, PrimeCharacteristicRing};
80 use p3_field_testing::{
81 test_extension_field, test_field, test_packed_extension_field,
82 test_two_adic_extension_field,
83 };
84
85 use crate::Goldilocks;
86
87 type F = Goldilocks;
88 type EF = BinomialExtensionField<F, 2>;
89
90 const ZEROS: [EF; 1] = [EF::ZERO];
93 const ONES: [EF; 1] = [EF::ONE];
94
95 fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 9] {
98 [
99 (BigUint::from(2u8), 33),
100 (BigUint::from(3u8), 1),
101 (BigUint::from(5u8), 1),
102 (BigUint::from(7u8), 1),
103 (BigUint::from(17u8), 1),
104 (BigUint::from(179u8), 1),
105 (BigUint::from(257u16), 1),
106 (BigUint::from(65537u32), 1),
107 (BigUint::from(7361031152998637u64), 1),
108 ]
109 }
110
111 test_field!(
112 super::EF,
113 &super::ZEROS,
114 &super::ONES,
115 &super::multiplicative_group_prime_factorization()
116 );
117
118 test_extension_field!(super::F, super::EF);
119 test_two_adic_extension_field!(super::F, super::EF);
120
121 type Pef = <EF as ExtensionField<F>>::ExtensionPacking;
122 const PACKED_ZEROS: [Pef; 1] = [Pef::ZERO];
123 const PACKED_ONES: [Pef; 1] = [Pef::ONE];
124 test_packed_extension_field!(super::Pef, &super::PACKED_ZEROS, &super::PACKED_ONES);
125}
126
127#[cfg(test)]
128mod test_quintic_extension {
129
130 use num_bigint::BigUint;
131 use p3_field::extension::BinomialExtensionField;
132 use p3_field::{ExtensionField, PrimeCharacteristicRing};
133 use p3_field_testing::{
134 test_extension_field, test_field, test_packed_extension_field,
135 test_two_adic_extension_field,
136 };
137
138 use crate::Goldilocks;
139
140 type F = Goldilocks;
141 type EF = BinomialExtensionField<F, 5>;
142
143 const ZEROS: [EF; 1] = [EF::ZERO];
146 const ONES: [EF; 1] = [EF::ONE];
147
148 fn multiplicative_group_prime_factorization() -> [(num_bigint::BigUint, u32); 10] {
151 [
152 (BigUint::from(2u8), 32),
153 (BigUint::from(3u8), 1),
154 (BigUint::from(5u8), 2),
155 (BigUint::from(17u8), 1),
156 (BigUint::from(257u16), 1),
157 (BigUint::from(45971u16), 1),
158 (BigUint::from(65537u32), 1),
159 (BigUint::from(255006435240067831u64), 1),
160 (BigUint::from(280083648770327405561u128), 1),
161 (BigUint::from(7053197395277272939628824863222181u128), 1),
162 ]
163 }
164
165 test_field!(
166 super::EF,
167 &super::ZEROS,
168 &super::ONES,
169 &super::multiplicative_group_prime_factorization()
170 );
171
172 test_extension_field!(super::F, super::EF);
173 test_two_adic_extension_field!(super::F, super::EF);
174
175 type Pef = <EF as ExtensionField<F>>::ExtensionPacking;
176 const PACKED_ZEROS: [Pef; 1] = [Pef::ZERO];
177 const PACKED_ONES: [Pef; 1] = [Pef::ONE];
178 test_packed_extension_field!(super::Pef, &super::PACKED_ZEROS, &super::PACKED_ONES);
179}