Skip to content

Commit 6437017

Browse files
SyxtonPrimeunzvfu
andauthored
Rename AbstractField and AbstractExtensionField (Plonky3#545)
* Rename AbstractField and AbstractExtensionField * cargo fmt * Comment update * Update field/src/field.rs Co-authored-by: Hamish Ivey-Law <[email protected]> * Update field.rs Minor comment fixes. Update a typo and port @unzvfu's suggestions for `square` and `cube` to `double` as well. --------- Co-authored-by: Hamish Ivey-Law <[email protected]>
1 parent 9b267c4 commit 6437017

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+651
-590
lines changed

air/src/air.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::ops::{Add, Mul, Sub};
22

3-
use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field};
3+
use p3_field::{ExtensionField, Field, FieldAlgebra, FieldExtensionAlgebra};
44
use p3_matrix::dense::RowMajorMatrix;
55
use p3_matrix::Matrix;
66

@@ -29,7 +29,7 @@ pub trait Air<AB: AirBuilder>: BaseAir<AB::F> {
2929
pub trait AirBuilder: Sized {
3030
type F: Field;
3131

32-
type Expr: AbstractField
32+
type Expr: FieldAlgebra
3333
+ From<Self::F>
3434
+ Add<Self::Var, Output = Self::Expr>
3535
+ Add<Self::F, Output = Self::Expr>
@@ -130,7 +130,7 @@ pub trait PairBuilder: AirBuilder {
130130
pub trait ExtensionBuilder: AirBuilder {
131131
type EF: ExtensionField<Self::F>;
132132

133-
type ExprEF: AbstractExtensionField<Self::Expr, F = Self::EF>;
133+
type ExprEF: FieldExtensionAlgebra<Self::Expr, F = Self::EF>;
134134

135135
type VarEF: Into<Self::ExprEF> + Copy + Send + Sync;
136136

air/src/virtual_column.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::vec;
22
use alloc::vec::Vec;
33
use core::ops::Mul;
44

5-
use p3_field::{AbstractField, Field};
5+
use p3_field::{Field, FieldAlgebra};
66

77
/// An affine function over columns in a PAIR.
88
#[derive(Clone, Debug)]
@@ -110,7 +110,7 @@ impl<F: Field> VirtualPairCol<F> {
110110
pub fn apply<Expr, Var>(&self, preprocessed: &[Var], main: &[Var]) -> Expr
111111
where
112112
F: Into<Expr>,
113-
Expr: AbstractField + Mul<F, Output = Expr>,
113+
Expr: FieldAlgebra + Mul<F, Output = Expr>,
114114
Var: Into<Expr> + Copy,
115115
{
116116
let mut result = self.constant.into();

baby-bear/benches/bench_field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::type_name;
22

33
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
44
use p3_baby_bear::BabyBear;
5-
use p3_field::{AbstractField, Field};
5+
use p3_field::{Field, FieldAlgebra};
66
use p3_field_testing::bench_func::{
77
benchmark_add_latency, benchmark_add_throughput, benchmark_inv, benchmark_iter_sum,
88
benchmark_mul_latency, benchmark_mul_throughput, benchmark_sub_latency,

baby-bear/src/baby_bear.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use p3_field::{exp_1725656503, exp_u64_by_squaring, AbstractField, Field};
1+
use p3_field::{exp_1725656503, exp_u64_by_squaring, Field, FieldAlgebra};
22
use p3_monty_31::{
33
BarrettParameters, BinomialExtensionData, FieldParameters, MontyField31, MontyParameters,
44
PackedMontyParameters, TwoAdicData,
@@ -26,7 +26,7 @@ impl BarrettParameters for BabyBearParameters {}
2626
impl FieldParameters for BabyBearParameters {
2727
const MONTY_GEN: BabyBear = BabyBear::new(31);
2828

29-
fn exp_u64_generic<AF: AbstractField>(val: AF, power: u64) -> AF {
29+
fn exp_u64_generic<FA: FieldAlgebra>(val: FA, power: u64) -> FA {
3030
match power {
3131
1725656503 => exp_1725656503(val), // used to compute x^{1/7}
3232
_ => exp_u64_by_squaring(val, power),

baby-bear/src/extension.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod test_quartic_extension {
33
use alloc::format;
44

55
use p3_field::extension::BinomialExtensionField;
6-
use p3_field::{AbstractExtensionField, AbstractField};
6+
use p3_field::{FieldAlgebra, FieldExtensionAlgebra};
77
use p3_field_testing::{test_field, test_two_adic_extension_field};
88

99
use crate::BabyBear;

baby-bear/src/mds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub type MdsMatrixBabyBear = MdsMatrixMontyField31<MDSBabyBearData>;
4949

5050
#[cfg(test)]
5151
mod tests {
52-
use p3_field::AbstractField;
52+
use p3_field::FieldAlgebra;
5353
use p3_symmetric::Permutation;
5454

5555
use super::MdsMatrixBabyBear;

baby-bear/src/poseidon2.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use core::ops::Mul;
1717

18-
use p3_field::{AbstractField, Field, PrimeField32};
18+
use p3_field::{Field, FieldAlgebra, PrimeField32};
1919
use p3_monty_31::{
2020
GenericPoseidon2LinearLayersMonty31, InternalLayerBaseParameters, InternalLayerParameters,
2121
MontyField31, Poseidon2ExternalLayerMonty31, Poseidon2InternalLayerMonty31,
@@ -50,7 +50,7 @@ pub type Poseidon2BabyBear<const WIDTH: usize> = Poseidon2<
5050

5151
/// An implementation of the the matrix multiplications in the internal and external layers of Poseidon2.
5252
///
53-
/// This can act on [AF; WIDTH] for any AbstractField which implements multiplication by BabyBear field elements.
53+
/// This can act on [FA; WIDTH] for any AbstractField which implements multiplication by BabyBear field elements.
5454
/// If you have either `[BabyBear::Packing; WIDTH]` or `[BabyBear; WIDTH]` it will be much faster
5555
/// to use `Poseidon2BabyBear<WIDTH>` instead of building a Poseidon2 permutation using this.
5656
pub type GenericPoseidon2LinearLayersBabyBear =
@@ -152,11 +152,11 @@ impl InternalLayerBaseParameters<BabyBearParameters, 16> for BabyBearInternalLay
152152
state[15] = sum - state[15];
153153
}
154154

155-
fn generic_internal_linear_layer<AF>(state: &mut [AF; 16])
155+
fn generic_internal_linear_layer<FA>(state: &mut [FA; 16])
156156
where
157-
AF: AbstractField + Mul<BabyBear, Output = AF>,
157+
FA: FieldAlgebra + Mul<BabyBear, Output = FA>,
158158
{
159-
let part_sum: AF = state[1..].iter().cloned().sum();
159+
let part_sum: FA = state[1..].iter().cloned().sum();
160160
let full_sum = part_sum.clone() + state[0].clone();
161161

162162
// The first three diagonal elements are -2, 1, 2 so we do something custom.
@@ -230,11 +230,11 @@ impl InternalLayerBaseParameters<BabyBearParameters, 24> for BabyBearInternalLay
230230
state[23] = sum - state[23];
231231
}
232232

233-
fn generic_internal_linear_layer<AF>(state: &mut [AF; 24])
233+
fn generic_internal_linear_layer<FA>(state: &mut [FA; 24])
234234
where
235-
AF: AbstractField + Mul<BabyBear, Output = AF>,
235+
FA: FieldAlgebra + Mul<BabyBear, Output = FA>,
236236
{
237-
let part_sum: AF = state[1..].iter().cloned().sum();
237+
let part_sum: FA = state[1..].iter().cloned().sum();
238238
let full_sum = part_sum.clone() + state[0].clone();
239239

240240
// The first three diagonal elements are -2, 1, 2 so we do something custom.
@@ -260,7 +260,7 @@ impl InternalLayerParameters<BabyBearParameters, 24> for BabyBearInternalLayerPa
260260

261261
#[cfg(test)]
262262
mod tests {
263-
use p3_field::AbstractField;
263+
use p3_field::FieldAlgebra;
264264
use p3_symmetric::Permutation;
265265
use rand::{Rng, SeedableRng};
266266
use rand_xoshiro::Xoroshiro128Plus;

baby-bear/src/x86_64_avx2/poseidon2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl InternalLayerParametersAVX2<BabyBearParameters, 24> for BabyBearInternalLay
112112

113113
#[cfg(test)]
114114
mod tests {
115-
use p3_field::AbstractField;
115+
use p3_field::FieldAlgebra;
116116
use p3_symmetric::Permutation;
117117
use rand::Rng;
118118

bn254-fr/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ff::{Field as FFField, PrimeField as FFPrimeField};
1212
pub use halo2curves::bn256::Fr as FFBn254Fr;
1313
use halo2curves::serde::SerdeObject;
1414
use num_bigint::BigUint;
15-
use p3_field::{AbstractField, Field, Packable, PrimeField, TwoAdicField};
15+
use p3_field::{Field, FieldAlgebra, Packable, PrimeField, TwoAdicField};
1616
pub use poseidon2::Poseidon2Bn254;
1717
use rand::distributions::{Distribution, Standard};
1818
use rand::Rng;
@@ -89,7 +89,7 @@ impl Debug for Bn254Fr {
8989
}
9090
}
9191

92-
impl AbstractField for Bn254Fr {
92+
impl FieldAlgebra for Bn254Fr {
9393
type F = Self;
9494

9595
const ZERO: Self = Self::new(FFBn254Fr::ZERO);

bn254-fr/src/poseidon2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use std::sync::OnceLock;
66

7-
use p3_field::AbstractField;
7+
use p3_field::FieldAlgebra;
88
use p3_poseidon2::{
99
add_rc_and_sbox_generic, external_initial_permute_state, external_terminal_permute_state,
1010
internal_permute_state, matmul_internal, ExternalLayer, ExternalLayerConstants,

challenger/src/duplex_challenger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ where
160160
mod tests {
161161
use core::iter;
162162

163-
use p3_field::AbstractField;
163+
use p3_field::FieldAlgebra;
164164
use p3_goldilocks::Goldilocks;
165165
use p3_symmetric::Permutation;
166166

challenger/src/hash_challenger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ where
8383

8484
#[cfg(test)]
8585
mod tests {
86-
use p3_field::AbstractField;
86+
use p3_field::FieldAlgebra;
8787
use p3_goldilocks::Goldilocks;
8888

8989
use super::*;

challenger/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use duplex_challenger::*;
1717
pub use grinding_challenger::*;
1818
pub use hash_challenger::*;
1919
pub use multi_field_challenger::*;
20-
use p3_field::{AbstractExtensionField, Field};
20+
use p3_field::{Field, FieldExtensionAlgebra};
2121
pub use serializing_challenger::*;
2222

2323
pub trait CanObserve<T> {
@@ -52,11 +52,11 @@ pub trait CanSampleBits<T> {
5252
pub trait FieldChallenger<F: Field>:
5353
CanObserve<F> + CanSample<F> + CanSampleBits<usize> + Sync
5454
{
55-
fn observe_ext_element<EF: AbstractExtensionField<F>>(&mut self, ext: EF) {
55+
fn observe_ext_element<EF: FieldExtensionAlgebra<F>>(&mut self, ext: EF) {
5656
self.observe_slice(ext.as_base_slice());
5757
}
5858

59-
fn sample_ext_element<EF: AbstractExtensionField<F>>(&mut self) -> EF {
59+
fn sample_ext_element<EF: FieldExtensionAlgebra<F>>(&mut self) -> EF {
6060
let vec = self.sample_vec(EF::D);
6161
EF::from_base_slice(&vec)
6262
}
@@ -115,12 +115,12 @@ where
115115
C: FieldChallenger<F>,
116116
{
117117
#[inline(always)]
118-
fn observe_ext_element<EF: AbstractExtensionField<F>>(&mut self, ext: EF) {
118+
fn observe_ext_element<EF: FieldExtensionAlgebra<F>>(&mut self, ext: EF) {
119119
(**self).observe_ext_element(ext)
120120
}
121121

122122
#[inline(always)]
123-
fn sample_ext_element<EF: AbstractExtensionField<F>>(&mut self) -> EF {
123+
fn sample_ext_element<EF: FieldExtensionAlgebra<F>>(&mut self) -> EF {
124124
(**self).sample_ext_element()
125125
}
126126
}

circle/src/deep_quotient.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ mod tests {
124124
use alloc::vec;
125125

126126
use p3_field::extension::BinomialExtensionField;
127-
use p3_field::AbstractField;
127+
use p3_field::FieldAlgebra;
128128
use p3_matrix::dense::RowMajorMatrix;
129129
use p3_mersenne_31::Mersenne31;
130130
use rand::{random, thread_rng};

circle/src/domain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233

234234
use hashbrown::HashSet;
235235
use itertools::izip;
236-
use p3_field::{batch_multiplicative_inverse, AbstractField};
236+
use p3_field::{batch_multiplicative_inverse, FieldAlgebra};
237237
use p3_mersenne_31::Mersenne31;
238238
use rand::thread_rng;
239239

dft/src/naive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod tests {
3636
use alloc::vec;
3737

3838
use p3_baby_bear::BabyBear;
39-
use p3_field::{AbstractField, Field};
39+
use p3_field::{Field, FieldAlgebra};
4040
use p3_goldilocks::Goldilocks;
4141
use p3_matrix::dense::RowMajorMatrix;
4242
use rand::thread_rng;

0 commit comments

Comments
 (0)