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, fft_with_small_degree)
35 constexpr size_t n = 16;
39 for (
size_t i = 0; i < n; ++i) {
45 domain.compute_lookup_table();
51 for (
size_t i = 0; i < n; ++i) {
53 EXPECT_EQ((fft_transform[i] == expected),
true);
54 work_root *= domain.root;
58TEST(polynomials, split_polynomial_fft)
60 constexpr size_t n = 256;
64 for (
size_t i = 0; i < n; ++i) {
69 constexpr size_t num_poly = 4;
70 constexpr size_t n_poly = n / num_poly;
71 fr fft_transform_[num_poly][n_poly];
72 for (
size_t i = 0; i < n; ++i) {
73 fft_transform_[i / n_poly][i % n_poly] = poly[i];
77 domain.compute_lookup_table();
85 for (
size_t i = 0; i < n; ++i) {
87 EXPECT_EQ((fft_transform[i] == expected),
true);
88 EXPECT_EQ(fft_transform_[i / n_poly][i % n_poly], fft_transform[i]);
89 work_root *= domain.root;
93TEST(polynomials, split_polynomial_evaluate)
95 constexpr size_t n = 256;
99 for (
size_t i = 0; i < n; ++i) {
104 constexpr size_t num_poly = 4;
105 constexpr size_t n_poly = n / num_poly;
106 fr fft_transform_[num_poly][n_poly];
107 for (
size_t i = 0; i < n; ++i) {
108 fft_transform_[i / n_poly][i % n_poly] = poly[i];
113 { fft_transform_[0], fft_transform_[1], fft_transform_[2], fft_transform_[3] }, z, n),
119 constexpr size_t n = 1 << 14;
120 fr*
data = (
fr*)aligned_alloc(32,
sizeof(
fr) * n * 2);
123 for (
size_t i = 0; i < n; ++i) {
129 domain.compute_lookup_table();
133 for (
size_t i = 0; i < n; ++i) {
134 EXPECT_EQ((result[i] == expected[i]),
true);
139TEST(polynomials, fft_ifft_consistency)
141 constexpr size_t n = 256;
144 for (
size_t i = 0; i < n; ++i) {
150 domain.compute_lookup_table();
154 for (
size_t i = 0; i < n; ++i) {
155 EXPECT_EQ((result[i] == expected[i]),
true);
159TEST(polynomials, split_polynomial_fft_ifft_consistency)
161 constexpr size_t n = 256;
162 constexpr size_t num_poly = 4;
163 fr result[num_poly][n];
164 fr expected[num_poly][n];
165 for (
size_t j = 0; j < num_poly; j++) {
166 for (
size_t i = 0; i < n; ++i) {
173 domain.compute_lookup_table();
176 for (
size_t j = 0; j < num_poly; j++) {
177 coeffs_vec.push_back(result[j]);
182 for (
size_t j = 0; j < num_poly; j++) {
183 for (
size_t i = 0; i < n; ++i) {
184 EXPECT_EQ((result[j][i] == expected[j][i]),
true);
189TEST(polynomials, fft_coset_ifft_consistency)
191 constexpr size_t n = 256;
194 for (
size_t i = 0; i < n; ++i) {
200 domain.compute_lookup_table();
202 T0 = domain.generator * domain.generator_inverse;
203 EXPECT_EQ((T0 ==
fr::one()),
true);
208 for (
size_t i = 0; i < n; ++i) {
209 EXPECT_EQ((result[i] == expected[i]),
true);
213TEST(polynomials, split_polynomial_fft_coset_ifft_consistency)
215 constexpr size_t n = 256;
216 constexpr size_t num_poly = 4;
217 fr result[num_poly][n];
218 fr expected[num_poly][n];
219 for (
size_t j = 0; j < num_poly; j++) {
220 for (
size_t i = 0; i < n; ++i) {
227 domain.compute_lookup_table();
230 for (
size_t j = 0; j < num_poly; j++) {
231 coeffs_vec.push_back(result[j]);
236 for (
size_t j = 0; j < num_poly; j++) {
237 for (
size_t i = 0; i < n; ++i) {
238 EXPECT_EQ((result[j][i] == expected[j][i]),
true);
243TEST(polynomials, fft_coset_ifft_cross_consistency)
245 constexpr size_t n = 2;
251 for (
size_t i = 0; i < n; ++i) {
255 expected[i] = poly_a[i] + poly_c[i];
256 expected[i] += poly_b[i];
259 for (
size_t i = n; i < 4 * n; ++i) {
267 small_domain.compute_lookup_table();
268 mid_domain.compute_lookup_table();
269 large_domain.compute_lookup_table();
274 for (
size_t i = 0; i < n; ++i) {
275 poly_a[i] = poly_a[i] + poly_c[4 * i];
276 poly_a[i] = poly_a[i] + poly_b[2 * i];
281 for (
size_t i = 0; i < n; ++i) {
282 EXPECT_EQ((poly_a[i] == expected[i]),
true);
286TEST(polynomials, barycentric_weight_evaluations)
288 constexpr size_t n = 16;
292 std::vector<fr> poly(n);
293 std::vector<fr> barycentric_poly(n);
295 for (
size_t i = 0; i < n / 2; ++i) {
297 barycentric_poly[i] = poly[i];
299 for (
size_t i = n / 2; i < n; ++i) {
301 barycentric_poly[i] = poly[i];
314 EXPECT_EQ((result == expected),
true);
317TEST(polynomials, linear_poly_product)
319 constexpr size_t n = 64;
324 for (
size_t i = 0; i < n; ++i) {
326 expected *= (z - roots[i]);
333 EXPECT_EQ(result, expected);
344 using FF = TypeParam;
345 constexpr size_t n = 256;
348 EXPECT_EQ(domain.size, 256UL);
349 EXPECT_EQ(domain.log2_size, 8UL);
354 using FF = TypeParam;
355 constexpr size_t n = 256;
361 result = domain.root.
pow(
static_cast<uint64_t
>(n));
363 EXPECT_EQ((result == expected),
true);
368 using FF = TypeParam;
369 constexpr size_t n = 16;
374 FF* roots = root_table[root_table.size() - 1];
375 FF* inverse_roots = inverse_root_table[inverse_root_table.size() - 1];
376 for (
size_t i = 0; i < (n - 1) / 2; ++i) {
377 EXPECT_EQ(roots[i] * domain.
root, roots[i + 1]);
378 EXPECT_EQ(inverse_roots[i] * domain.
root_inverse, inverse_roots[i + 1]);
379 EXPECT_EQ(roots[i] * inverse_roots[i],
FF::one());
385 using FF = TypeParam;
386 constexpr size_t n = 250;
389 for (
size_t i = 0; i < n; ++i) {
393 for (
size_t i = 0; i < n; ++i) {
399 for (
size_t i = 0; i < n; ++i) {
400 EXPECT_EQ(src[i], poly[i]);
406 using FF = TypeParam;
407 constexpr size_t n = 15;
410 for (
size_t i = 0; i < n; ++i) {
414 for (
size_t i = 0; i < n; ++i) {
420 for (
size_t i = 0; i < n; ++i) {
421 EXPECT_EQ(src[i], poly[i]);
425 for (
size_t i = 0; i < n; ++i) {
426 poly[i] =
FF(i + 54);
429 for (
size_t i = 0; i < n; ++i) {
430 x[i] =
FF(i - n / 2);
435 for (
size_t i = 0; i < n; ++i) {
436 EXPECT_EQ(src[i], poly[i]);
441 for (
size_t i = 0; i < n; ++i) {
442 poly[i] =
FF(i * i + 57);
445 for (
size_t i = 0; i < n; ++i) {
446 x[i] =
FF(i - (n - 1));
451 for (
size_t i = 0; i < n; ++i) {
452 EXPECT_EQ(src[i], poly[i]);
458 using FF = TypeParam;
460 auto root = std::array{
FF(3) };
461 auto eval = std::array{
FF(4) };
463 ASSERT_EQ(t.
size(), 1);
464 ASSERT_EQ(t[0], eval[0]);
469 using FF = TypeParam;
471 constexpr size_t N = 32;
474 for (
size_t i = 0; i < N; ++i) {
479 auto roots_copy(roots);
480 auto evaluations_copy(evaluations);
484 ASSERT_EQ(interpolated.
size(), N);
485 ASSERT_EQ(roots, roots_copy);
486 ASSERT_EQ(evaluations, evaluations_copy);
488 for (
size_t i = 0; i < N; ++i) {
490 ASSERT_EQ(eval, evaluations[i]);
496 using FF = TypeParam;
498 auto test_case = [](
size_t N) {
501 EXPECT_EQ(N, 1 << m);
503 for (
size_t i = 1; i < N - 1; ++i) {
508 EXPECT_TRUE(poly[0].is_zero());
511 std::vector<FF> u(m);
512 for (
size_t l = 0; l < m; ++l) {
516 std::vector<FF> lagrange_evals(N,
FF(1));
517 for (
size_t i = 0; i < N; ++i) {
518 auto& coef = lagrange_evals[i];
519 for (
size_t l = 0; l < m; ++l) {
520 size_t mask = (1 << l);
521 if ((i & mask) == 0) {
522 coef *= (
FF(1) - u[l]);
532 for (
size_t i = 0; i < N; ++i) {
533 real_eval += poly[i] * lagrange_evals[i];
536 EXPECT_EQ(real_eval, computed_eval);
539 FF real_eval_shift(0);
540 for (
size_t i = 1; i < N; ++i) {
541 real_eval_shift += poly[i] * lagrange_evals[i - 1];
544 EXPECT_EQ(real_eval_shift, computed_eval_shift);
557 using FF = TypeParam;
560 size_t num_coeffs = 64;
562 for (
size_t i = 0; i < num_coeffs; i++) {
570 EXPECT_EQ(polynomial_a.
data(),
nullptr);
573 auto polynomial_c =
std::move(polynomial_b);
576 EXPECT_EQ(polynomial_b.
data(),
nullptr);
580 for (
size_t i = 0; i < num_coeffs; i++) {
588 EXPECT_EQ(polynomial_c.data(),
nullptr);
593 using FF = TypeParam;
596 size_t num_coeffs = 64;
598 for (
size_t i = 0; i < num_coeffs; i++) {
608 poly = interesting_poly;
611 for (
size_t i = 0; i < num_coeffs; ++i) {
612 EXPECT_EQ(poly[i], interesting_poly[i]);
614 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, size_t target_size) 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[...
const std::vector< MemoryValue > data
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, const EvaluationDomain< Fr > &domain)
void coset_fft(Fr *coeffs, 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 fft(Fr *coeffs, const EvaluationDomain< Fr > &domain)
fr compute_barycentric_evaluation(const fr *coeffs, const size_t num_coeffs, const fr &z, const EvaluationDomain< fr > &domain)
void coset_ifft(Fr *coeffs, const EvaluationDomain< Fr > &domain)
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(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field one()
BB_INLINE constexpr field to_montgomery_form() const noexcept
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()