binius_core/composition/
product_composition.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2024 Ulvetanna Inc.

use crate::polynomial::{CompositionPoly, Error};
use binius_field::PackedField;
use binius_utils::bail;

#[derive(Debug, Copy, Clone)]
pub struct ProductComposition<const N: usize>;

impl<const N: usize> ProductComposition<N> {
	pub const fn n_vars(&self) -> usize {
		N
	}

	pub const fn degree(&self) -> usize {
		N
	}
}

impl<P: PackedField, const N: usize> CompositionPoly<P> for ProductComposition<N> {
	fn n_vars(&self) -> usize {
		self.n_vars()
	}

	fn degree(&self) -> usize {
		self.degree()
	}

	fn evaluate(&self, query: &[P]) -> Result<P, Error> {
		if query.len() != N {
			bail!(Error::IncorrectQuerySize { expected: N });
		}
		Ok(query.iter().copied().product())
	}

	fn binary_tower_level(&self) -> usize {
		0
	}
}

pub type BivariateProduct = ProductComposition<2>;
pub type TrivariateProduct = ProductComposition<3>;