binius_core/composition/
product_composition.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use binius_field::PackedField;
4use binius_math::{ArithExpr, CompositionPoly};
5use binius_utils::bail;
6
7#[derive(Debug, Default, Copy, Clone)]
8pub struct ProductComposition<const N: usize>;
9
10impl<const N: usize> ProductComposition<N> {
11	pub const fn n_vars(&self) -> usize {
12		N
13	}
14
15	pub const fn degree(&self) -> usize {
16		N
17	}
18}
19
20impl<P: PackedField, const N: usize> CompositionPoly<P> for ProductComposition<N> {
21	fn n_vars(&self) -> usize {
22		self.n_vars()
23	}
24
25	fn degree(&self) -> usize {
26		self.degree()
27	}
28
29	fn expression(&self) -> ArithExpr<P::Scalar> {
30		(0..N).map(ArithExpr::Var).product()
31	}
32
33	fn evaluate(&self, query: &[P]) -> Result<P, binius_math::Error> {
34		if query.len() != N {
35			bail!(binius_math::Error::IncorrectQuerySize { expected: N });
36		}
37		Ok(query.iter().copied().product())
38	}
39
40	fn binary_tower_level(&self) -> usize {
41		0
42	}
43}
44
45pub type BivariateProduct = ProductComposition<2>;
46pub type TrivariateProduct = ProductComposition<3>;