barretenberg
Loading...
Searching...
No Matches
power_polynomial.hpp
1#pragma once
2#include "barretenberg/common/thread.hpp"
3#include "barretenberg/polynomials/polynomial.hpp"
4#include <span>
5
6namespace proof_system::honk::power_polynomial {
16template <typename Fr> barretenberg::Polynomial<Fr> generate_vector(Fr zeta, size_t vector_size)
17{
18 // We know the size from the start, so we can allocate exactly the right amount of memory
19 barretenberg::Polynomial<Fr> pow_vector(vector_size);
20
21 constexpr size_t usefulness_margin = 4;
22 size_t num_threads = get_num_cpus_pow2();
23 if (vector_size < (usefulness_margin * num_threads)) {
24 num_threads = 1;
25 }
26 // Prepare for a random number of threads. We need to handle the last thread separately
27 size_t thread_size = vector_size / num_threads;
28 size_t last_thread_size = thread_size;
29 // Check if the vector size is divided into threads cleanly
30 if ((vector_size % thread_size) != 0) {
31 thread_size += 1;
32 last_thread_size = vector_size % thread_size;
33 }
34 parallel_for(num_threads, [&](size_t i) {
35 // Exponentiate ζ to the starting power of the chunk
36 Fr starting_power = zeta.pow(i * thread_size);
37 // Set the chunk size depending ontwhether this is the last thread
38 size_t chunk_size = i != (num_threads - 1) ? thread_size : last_thread_size;
39 size_t j = 0;
40 // Go through elements and compute ζ powers
41 for (; j < chunk_size - 1; j++) {
42 pow_vector[i * thread_size + j] = starting_power;
43 starting_power *= zeta;
44 }
45 pow_vector[i * thread_size + j] = starting_power;
46 });
47 return pow_vector;
48}
49
59template <typename Fr> Fr evaluate(Fr zeta, std::span<const Fr> variables)
60{
61 Fr evaluation = Fr::one();
62 for (size_t i = 0; i < variables.size(); i++) {
63 // evaluation *= (b^{2^i} - 1) * x_i + 1
64 evaluation *= (zeta - 1) * variables[i] + 1;
65 zeta *= zeta;
66 }
67 return evaluation;
68}
69} // namespace proof_system::honk::power_polynomial
Definition: polynomial.hpp:12