9#include <gtest/gtest.h>
21 for (
size_t i = 0; i < poly1.size(); ++i) {
23 poly2.at(i) = poly1[i];
27 auto eval1 = poly1.evaluate(challenge);
28 auto eval2 = poly2.evaluate(challenge);
30 EXPECT_EQ(eval1, eval2);
33TEST(polynomials, ifft_consistency)
35 constexpr size_t n = 16;
37 domain.compute_lookup_table();
44 for (
size_t k = 0; k < n; ++k) {
51 for (
size_t j = 0; j < n; ++j) {
53 for (
size_t k = 0; k < n; ++k) {
54 fr w = domain.root.
pow(
static_cast<uint64_t
>(j * k));
58 values_copy[j] = values[j];
64 for (
size_t k = 0; k < n; ++k) {
65 EXPECT_EQ(recovered[k], coeffs[k]);
66 EXPECT_EQ(values[k], values_copy[k]);
70TEST(polynomials, split_polynomial_evaluate)
72 constexpr size_t n = 256;
76 for (
size_t i = 0; i < n; ++i) {
81 constexpr size_t num_poly = 4;
82 constexpr size_t n_poly = n / num_poly;
83 fr fft_transform_[num_poly][n_poly];
84 for (
size_t i = 0; i < n; ++i) {
85 fft_transform_[i / n_poly][i % n_poly] = poly[i];
90 { fft_transform_[0], fft_transform_[1], fft_transform_[2], fft_transform_[3] }, z, n),
94TEST(polynomials, linear_poly_product)
96 constexpr size_t n = 64;
101 for (
size_t i = 0; i < n; ++i) {
103 expected *= (z - roots[i]);
110 EXPECT_EQ(result, expected);
121 using FF = TypeParam;
122 constexpr size_t n = 256;
125 EXPECT_EQ(domain.size, 256UL);
126 EXPECT_EQ(domain.log2_size, 8UL);
131 using FF = TypeParam;
132 constexpr size_t n = 256;
138 result = domain.root.
pow(
static_cast<uint64_t
>(n));
140 EXPECT_EQ((result == expected),
true);
145 using FF = TypeParam;
146 constexpr size_t n = 16;
151 FF* roots = root_table[root_table.size() - 1];
152 FF* inverse_roots = inverse_root_table[inverse_root_table.size() - 1];
153 for (
size_t i = 0; i < (n - 1) / 2; ++i) {
154 EXPECT_EQ(roots[i] * domain.
root, roots[i + 1]);
155 EXPECT_EQ(inverse_roots[i] * domain.
root_inverse, inverse_roots[i + 1]);
156 EXPECT_EQ(roots[i] * inverse_roots[i],
FF::one());
162 using FF = TypeParam;
163 constexpr size_t n = 250;
166 for (
size_t i = 0; i < n; ++i) {
170 for (
size_t i = 0; i < n; ++i) {
176 for (
size_t i = 0; i < n; ++i) {
177 EXPECT_EQ(src[i], poly[i]);
183 using FF = TypeParam;
184 constexpr size_t n = 15;
187 for (
size_t i = 0; i < n; ++i) {
191 for (
size_t i = 0; i < n; ++i) {
197 for (
size_t i = 0; i < n; ++i) {
198 EXPECT_EQ(src[i], poly[i]);
202 for (
size_t i = 0; i < n; ++i) {
203 poly[i] =
FF(i + 54);
206 for (
size_t i = 0; i < n; ++i) {
207 x[i] =
FF(i - n / 2);
212 for (
size_t i = 0; i < n; ++i) {
213 EXPECT_EQ(src[i], poly[i]);
218 for (
size_t i = 0; i < n; ++i) {
219 poly[i] =
FF(i * i + 57);
222 for (
size_t i = 0; i < n; ++i) {
223 x[i] =
FF(i - (n - 1));
228 for (
size_t i = 0; i < n; ++i) {
229 EXPECT_EQ(src[i], poly[i]);
235 using FF = TypeParam;
237 auto root = std::array{
FF(3) };
238 auto eval = std::array{
FF(4) };
240 ASSERT_EQ(t.
size(), 1);
241 ASSERT_EQ(t[0], eval[0]);
246 using FF = TypeParam;
248 constexpr size_t N = 32;
251 for (
size_t i = 0; i < N; ++i) {
256 auto roots_copy(roots);
257 auto evaluations_copy(evaluations);
261 ASSERT_EQ(interpolated.
size(), N);
262 ASSERT_EQ(roots, roots_copy);
263 ASSERT_EQ(evaluations, evaluations_copy);
265 for (
size_t i = 0; i < N; ++i) {
267 ASSERT_EQ(eval, evaluations[i]);
273 using FF = TypeParam;
275 auto test_case = [](
size_t N) {
278 EXPECT_EQ(N, 1 << m);
280 for (
size_t i = 1; i < N - 1; ++i) {
285 EXPECT_TRUE(poly[0].is_zero());
288 std::vector<FF> u(m);
289 for (
size_t l = 0; l < m; ++l) {
293 std::vector<FF> lagrange_evals(N,
FF(1));
294 for (
size_t i = 0; i < N; ++i) {
295 auto& coef = lagrange_evals[i];
296 for (
size_t l = 0; l < m; ++l) {
297 size_t mask = (1 << l);
298 if ((i & mask) == 0) {
299 coef *= (
FF(1) - u[l]);
309 for (
size_t i = 0; i < N; ++i) {
310 real_eval += poly[i] * lagrange_evals[i];
313 EXPECT_EQ(real_eval, computed_eval);
316 FF real_eval_shift(0);
317 for (
size_t i = 1; i < N; ++i) {
318 real_eval_shift += poly[i] * lagrange_evals[i - 1];
321 EXPECT_EQ(real_eval_shift, computed_eval_shift);
334 using FF = TypeParam;
337 size_t num_coeffs = 64;
339 for (
size_t i = 0; i < num_coeffs; i++) {
347 EXPECT_EQ(polynomial_a.
data(),
nullptr);
350 auto polynomial_c =
std::move(polynomial_b);
353 EXPECT_EQ(polynomial_b.
data(),
nullptr);
357 for (
size_t i = 0; i < num_coeffs; i++) {
365 EXPECT_EQ(polynomial_c.data(),
nullptr);
370 using FF = TypeParam;
373 size_t num_coeffs = 64;
375 for (
size_t i = 0; i < num_coeffs; i++) {
385 poly = interesting_poly;
388 for (
size_t i = 0; i < num_coeffs; ++i) {
389 EXPECT_EQ(poly[i], interesting_poly[i]);
391 EXPECT_EQ(poly.
size(), interesting_poly.
size());
void compute_lookup_table()
const std::vector< FF * > & get_round_roots() const
const std::vector< FF * > & get_inverse_round_roots() const
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Fr evaluate(const Fr &z) const
Fr evaluate_mle(std::span< const Fr > evaluation_points, bool shift=false) const
evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,...
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
testing::Types< bb::fr > FieldTypes
constexpr T get_msb(const T in)
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
void ifft(Fr *coeffs, Fr *target, const EvaluationDomain< Fr > &domain)
void compute_linear_polynomial_product(const Fr *roots, Fr *dest, const size_t n)
Fr evaluate(const Fr *coeffs, const Fr &z, const size_t n)
void compute_efficient_interpolation(const Fr *src, Fr *dest, const Fr *evaluation_points, const size_t n)
Entry point for Barretenberg command-line interface.
EvaluationDomain< bb::fr > evaluation_domain
TYPED_TEST_SUITE(CommitmentKeyTest, Curves)
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field one()
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept
static BB_INLINE void __copy(const field &a, field &r) noexcept
static constexpr field zero()