Skip to content

Commit

Permalink
polynomial: make Eq/PartialEq take leading zeros into account
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apoelstra committed Sep 21, 2024
1 parent 229e8ff commit 8d1b8c8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/primitives/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ use core::{fmt, iter, ops, slice};
use super::{ExtensionField, Field, FieldVec};

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

impl<F: Field> PartialEq for Polynomial<F> {
fn eq(&self, other: &Self) -> bool {
self.inner[..self.degree()] == other.inner[..other.degree()]
}
}

impl<F: Field> Eq for Polynomial<F> {}

impl<F: Field> Polynomial<F> {
/// Determines whether the residue is representable, given the current
/// compilation context.
Expand Down

0 comments on commit 8d1b8c8

Please sign in to comment.