Fixes based on PR comments

This commit is contained in:
wborgeaud 2021-05-18 22:22:15 +02:00
parent 8737c8d5b9
commit 1cbd12edbd
3 changed files with 5 additions and 18 deletions

View File

@ -86,6 +86,7 @@ pub fn unflatten<F: Field, const D: usize>(l: &[F]) -> Vec<F::Extension>
where
F: Extendable<D>,
{
debug_assert_eq!(l.len() % D, 0);
l.chunks_exact(D)
.map(|c| {
let mut arr = [F::ZERO; D];

View File

@ -32,8 +32,6 @@ pub trait QuadraticFieldExtension:
Self::from_canonical_representation([a0, a1 * z])
}
fn scalar_mul(&self, c: Self::BaseField) -> Self;
}
#[derive(Copy, Clone)]
@ -52,11 +50,6 @@ impl QuadraticFieldExtension for QuadraticCrandallField {
fn from_canonical_representation(v: [Self::BaseField; 2]) -> Self {
Self(v)
}
fn scalar_mul(&self, c: Self::BaseField) -> Self {
let [a0, a1] = self.to_canonical_representation();
Self([a0 * c, a1 * c])
}
}
impl From<<Self as QuadraticFieldExtension>::BaseField> for QuadraticCrandallField {
@ -104,7 +97,7 @@ impl Field for QuadraticCrandallField {
let a_pow_r = a_pow_r_minus_1 * *self;
debug_assert!(a_pow_r.is_in_basefield());
Some(a_pow_r_minus_1.scalar_mul(a_pow_r.0[0].inverse()))
Some(a_pow_r_minus_1 * a_pow_r.0[0].inverse().into())
}
// It's important that the primitive roots of unity are the same as the ones in the base field,
@ -273,7 +266,7 @@ mod tests {
assert_eq!(-x, F::ZERO - x);
assert_eq!(
x + x,
x.scalar_mul(<F as QuadraticFieldExtension>::BaseField::TWO)
x * <F as QuadraticFieldExtension>::BaseField::TWO.into()
);
assert_eq!(x * (-x), -x.square());
assert_eq!(x + y, y + x);

View File

@ -38,8 +38,6 @@ pub trait QuarticFieldExtension: Field + From<<Self as QuarticFieldExtension>::B
Self::from_canonical_representation([b0, b1, b2, b3])
}
fn scalar_mul(&self, c: Self::BaseField) -> Self;
}
#[derive(Copy, Clone)]
@ -58,11 +56,6 @@ impl QuarticFieldExtension for QuarticCrandallField {
fn from_canonical_representation(v: [Self::BaseField; 4]) -> Self {
Self(v)
}
fn scalar_mul(&self, c: Self::BaseField) -> Self {
let [a0, a1, a2, a3] = self.to_canonical_representation();
Self([a0 * c, a1 * c, a2 * c, a3 * c])
}
}
impl From<<Self as QuarticFieldExtension>::BaseField> for QuarticCrandallField {
@ -142,7 +135,7 @@ impl Field for QuarticCrandallField {
let a_pow_r = a_pow_r_minus_1 * *self;
debug_assert!(a_pow_r.is_in_basefield());
Some(a_pow_r_minus_1.scalar_mul(a_pow_r.0[0].inverse()))
Some(a_pow_r_minus_1 * a_pow_r.0[0].inverse().into())
}
// It's important that the primitive roots of unity are the same as the ones in the base field,
@ -329,7 +322,7 @@ mod tests {
assert_eq!(-x, F::ZERO - x);
assert_eq!(
x + x,
x.scalar_mul(<F as QuarticFieldExtension>::BaseField::TWO)
x * <F as QuarticFieldExtension>::BaseField::TWO.into()
);
assert_eq!(x * (-x), -x.square());
assert_eq!(x + y, y + x);