Skip to main content

zinc_poly/
lib.rs

1pub mod mle;
2pub mod univariate;
3pub mod utils;
4pub mod zero_degree;
5
6use thiserror::Error;
7
8/// Polynomial with coefficients of type `C` and degree bounded by
9/// `DEGREE_BOUND`.
10pub trait Polynomial<C>: Clone {
11    const DEGREE_BOUND: usize;
12}
13
14pub trait EvaluatablePolynomial<C, Out>: Polynomial<C> {
15    /// The type of points a polynomial can be evaluated on.
16    /// For univariate polynomials this typically is `Out`,
17    /// for multivariate this is `[Out]`.
18    type EvaluationPoint: ?Sized;
19
20    /// Evaluates the polynomial at the given point.
21    fn evaluate_at_point(&self, point: &Self::EvaluationPoint) -> Result<Out, EvaluationError>;
22}
23
24pub trait ConstCoeffBitWidth {
25    const COEFF_BIT_WIDTH: usize;
26}
27
28#[derive(Clone, Debug, PartialEq, Error)]
29pub enum EvaluationError {
30    #[error("Wrong number of points provided for evaluation: expected {expected}, got {actual}")]
31    WrongPointWidth { expected: usize, actual: usize },
32    #[error("Evaluation failed due to overflow")]
33    Overflow,
34    #[error("Empty polynomials are not allowed to be evaluate")]
35    EmptyPolynomial,
36    #[error("Unsupported constraint degrees: {degrees:?}")]
37    UnsupportedConstraintDegrees { degrees: Vec<usize> },
38}