binius_hal/sumcheck_evaluator.rs
1// Copyright 2024-2025 Irreducible Inc.
2
3use std::ops::Range;
4
5use binius_field::{Field, PackedField};
6use binius_math::RowsBatchRef;
7
8/// Evaluations of a polynomial at a set of evaluation points.
9#[derive(Debug, Clone)]
10pub struct RoundEvals<F: Field>(pub Vec<F>);
11
12pub trait SumcheckEvaluator<P: PackedField, Composition> {
13 /// The range of eval point indices over which composition evaluation and summation should happen.
14 /// Returned range must equal the result of `n_round_evals()` in length.
15 fn eval_point_indices(&self) -> Range<usize>;
16
17 /// Compute composition evals over a subcube.
18 ///
19 /// `batch_query` should contain multilinears evals over a subcube represented
20 /// by `subcube_vars` and `subcube_index`.
21 ///
22 /// See doc comments to [EvaluationDomain](binius_math::EvaluationDomain) for the intuition
23 /// behind `is_infinity_point`.
24 ///
25 /// Returns a packed sum (which may be spread across scalars).
26 fn process_subcube_at_eval_point(
27 &self,
28 subcube_vars: usize,
29 subcube_index: usize,
30 is_infinity_point: bool,
31 batch_query: &RowsBatchRef<P>,
32 ) -> P;
33
34 /// Compute sum of evals over the suffix where the composite is guaranteed to evaluate to a constant.
35 ///
36 /// It is assumed that all required inputs are known at the evaluator creation time, as `const_eval_suffix` is
37 /// determined dynamically by the sumcheck round calculator and may be _smaller_ than the return value of the method
38 /// with the same name.
39 ///
40 /// See doc comments to [EvaluationDomain](binius_math::EvaluationDomain) for the intuition
41 /// behind `is_infinity_point`.
42 fn process_constant_eval_suffix(
43 &self,
44 _const_eval_suffix: usize,
45 _is_infinity_point: bool,
46 ) -> P::Scalar {
47 P::Scalar::ZERO
48 }
49
50 /// Returns the composition evaluated by this object.
51 fn composition(&self) -> &Composition;
52
53 /// In case of zerocheck returns eq_ind that the results should be folded with.
54 /// In case of sumcheck returns None.
55 fn eq_ind_partial_eval(&self) -> Option<&[P]>;
56
57 /// Trace suffix where the composite is guaranteed to evaluate to a constant. The non-constant prefix
58 /// would get processed via `process_subcube_at_eval_point`, whereas the remainder gets handled via
59 /// `process_constant_eval_suffix`. Due to the fact that sumcheck operates over whole subcubes the
60 /// `const_eval_suffix` passed to `process_constant_eval_suffix` may be _smaller_ that the return value
61 /// of this method.
62 fn const_eval_suffix(&self) -> usize {
63 0
64 }
65}