Skip to content

Commit 03d265d

Browse files
committed
polynomial: make Eq/PartialEq take leading zeros into account
Two polynomials are equal even if they have a different number of leading zeros. Putting this into its own commit rather than folding it into one of the FieldVec commits, because this bug was present even before the FieldVec stuff. Also remove the `Hash` impl because it's unneeded and we would be expected to keep it in sync with Eq.
1 parent 8fc65c9 commit 03d265d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/primitives/polynomial.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ use super::{ExtensionField, Field, FieldVec};
99
use crate::Fe32;
1010

1111
/// A polynomial over some field.
12-
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
12+
#[derive(Clone, Debug)]
1313
pub struct Polynomial<F> {
1414
/// The coefficients of the polynomial, in "little-endian" order.
1515
/// That is the constant term is at index 0.
1616
inner: FieldVec<F>,
1717
}
1818

19+
impl<F: Field> PartialEq for Polynomial<F> {
20+
fn eq(&self, other: &Self) -> bool {
21+
self.inner[..self.degree()] == other.inner[..other.degree()]
22+
}
23+
}
24+
25+
impl<F: Field> Eq for Polynomial<F> {}
26+
1927
impl Polynomial<Fe32> {
2028
pub fn from_residue<R: PackedFe32>(residue: R) -> Self {
2129
(0..R::WIDTH).rev().map(|i| Fe32(residue.unpack(i))).collect()
2230
}
2331
}
24-
2532
impl<F: Field> Polynomial<F> {
2633
/// Determines whether the residue is representable, given the current
2734
/// compilation context.

0 commit comments

Comments
 (0)