146 for (
size_t i = 0;
i <
size();
i++) {
432 result += (*this)[
i] *
i;
460template <
typename Fr_>
467 ASSERT(!shift || is_native);
469 if (coefficients.
size() == 0) {
473 const size_t n = evaluation_points.size();
483 size_t n_l = 1 << (dim - 1);
488 auto tmp_ptr = _allocate_aligned_memory<Fr_>(
sizeof(Fr_) * n_l);
489 auto tmp = tmp_ptr.get();
492 if constexpr (is_native) {
499 Fr_ u_l = evaluation_points[0];
503 const size_t ALLOW_ONE_PAST_READ = 1;
504 for (
size_t i = 0; i < n_l; ++i) {
506 tmp[i] = coefficients.
get(i * 2 +
offset) +
507 u_l * (coefficients.
get(i * 2 + 1 +
offset, ALLOW_ONE_PAST_READ) - coefficients.
get(i * 2 +
offset));
511 for (
size_t l = 1; l < dim; ++l) {
512 n_l = 1 << (dim - l - 1);
513 u_l = evaluation_points[l];
514 for (
size_t i = 0; i < n_l; ++i) {
515 tmp[i] = tmp[i * 2] + u_l * (tmp[(i * 2) + 1] - tmp[i * 2]);
518 auto result = tmp[0];
521 for (
size_t i = dim; i < n; i++) {
522 result *= (Fr_(1) - evaluation_points[i]);
531template <
typename Fr_>
535 return _evaluate_mle(evaluation_points, coefficients,
false);
544 return os <<
"[ data " << p[0] <<
"]";
546 return os <<
"[ data\n"
547 <<
" " << p[0] <<
",\n"
548 <<
" " << p[1] <<
",\n"
550 <<
" " << p[p.
size() - 2] <<
",\n"
551 <<
" " << p[p.
size() - 1] <<
",\n"
555template <
typename Poly,
typename... Polys>
auto zip_polys(Poly&& poly, Polys&&... polys)
560 auto check_indices = [&](
const auto& other) {
565 (check_indices(polys), ...);
566 return zip_view(poly.indices(), poly.coeffs(), polys.coeffs()...);
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LTE(left, right,...)
#define BB_ASSERT_LT(left, right,...)
#define ASSERT(expression,...)
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Polynomial(size_t size, size_t virtual_size, DontZeroMemory flag)
Polynomial & operator=(Polynomial &&other) noexcept=default
Polynomial shifted() const
Returns a Polynomial the left-shift of self.
size_t start_index() const
Polynomial & operator*=(Fr scaling_factor)
sets this = p(X) to s⋅p(X)
Polynomial(Polynomial &&other) noexcept=default
Polynomial partial_evaluate_mle(std::span< const Fr > evaluation_points) const
Partially evaluates in the last k variables a polynomial interpreted as a multilinear extension.
static Polynomial random(size_t size, size_t start_index=0)
Polynomial expand(const size_t new_start_index, const size_t new_end_index) const
Expands the polynomial with new start_index and end_index The value of the polynomial remains the sam...
Fr compute_kate_opening_coefficients(const Fr &z)
std::size_t virtual_size() const
Fr evaluate(const Fr &z, size_t target_size) const
SharedShiftedVirtualZeroesArray< Fr > coefficients_
Polynomial(const Polynomial &other)
void increase_virtual_size(const size_t size_in)
std::span< Fr > coeffs(size_t offset=0)
Strictly iterates the defined region of the polynomial. We keep this explicit, instead of having an i...
void copy_vector(const std::vector< T > &vec)
Copy over values from a vector that is of a convertible type.
auto indexed_values() const
bool in_place_operation_viable(size_t domain_size)
Polynomial & operator=(const Polynomial &other)
void mask()
Add random values to the coefficients of a polynomial. In practice, this is used for ensuring the com...
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,...
Polynomial(const Polynomial &other, size_t target_size)
const Fr & get(size_t i, size_t virtual_padding=0) const
Retrieves the value at the specified index.
Polynomial & operator-=(PolynomialSpan< const Fr > other)
subtracts the polynomial q(X) 'other'.
static Polynomial random(size_t size, size_t virtual_size, size_t start_index)
Polynomial reverse() const
Returns the polynomial equal to the reverse of self.
Polynomial right_shifted(const size_t magnitude) const
Returns a Polynomial equal to the right-shift-by-magnitude of self.
Fr compute_barycentric_evaluation(const Fr &z, const EvaluationDomain< Fr > &domain)
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
void add_scaled(PolynomialSpan< const Fr > other, Fr scaling_factor) &
adds the polynomial q(X) 'other', multiplied by a scaling factor.
bool operator==(Polynomial const &rhs) const
void shrink_end_index(const size_t new_end_index)
The end_index of the polynomial is decreased without any memory de-allocation. This is a very fast wa...
Polynomial & operator+=(PolynomialSpan< const Fr > other)
adds the polynomial q(X) 'other'.
const Fr & at(size_t index) const
static Polynomial shiftable(size_t virtual_size)
Utility to efficiently construct a shift from the original polynomial.
Polynomial(size_t size, DontZeroMemory flag)
static Polynomial create_non_parallel_zero_init(size_t size, size_t virtual_size)
A factory to construct a polynomial where parallel initialization is not possible (e....
void factor_roots(const Fr &root)
Divides p(X) by (X-r) in-place. Assumes that p(rⱼ)=0 for all j.
void allocate_backing_memory(size_t size, size_t virtual_size, size_t start_index)
void set_if_valid_index(size_t index, const Fr &value)
Like setting with at(), but allows zeroes to result in no set.
bool is_zero() const
Check whether or not a polynomial is identically zero.
std::span< const Fr > coeffs(size_t offset=0) const
bool is_valid_set_index(size_t index) const
Is this index valid for a set? i.e. calling poly.at(index) = value.
const Fr & operator[](size_t i) const
Polynomial full() const
Copys the polynomial, but with the whole address space usable. The value of the polynomial remains th...
const Fr & operator[](size_t i)
Polynomial(std::span< const Fr > coefficients)
uint8_t const size_t length
std::ostream & operator<<(std::ostream &os, uint256_t const &a)
constexpr T get_msb(const T in)
void factor_roots(std::span< Fr > polynomial, const Fr &root)
Divides p(X) by (X-r) in-place.
constexpr size_t ALWAYS_MULTITHREAD
Entry point for Barretenberg command-line interface.
std::shared_ptr< Fr[]> _allocate_aligned_memory(size_t n_elements)
std::shared_ptr< void > get_mem_slab(size_t size)
auto zip_polys(Poly &&poly, Polys &&... polys)
void parallel_for_heuristic(size_t num_points, const std::function< void(size_t, size_t, size_t)> &func, size_t heuristic_cost)
Split a loop into several loops running in parallel based on operations in 1 iteration.
Fr_ _evaluate_mle(std::span< const Fr_ > evaluation_points, const SharedShiftedVirtualZeroesArray< Fr_ > &coefficients, bool shift)
Internal implementation to support both native and stdlib circuit field types.
Fr_ generic_evaluate_mle(std::span< const Fr_ > evaluation_points, const SharedShiftedVirtualZeroesArray< Fr_ > &coefficients)
Static exposed implementation to support both native and stdlib circuit field types.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
#define PROFILE_THIS_NAME(name)
A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_...
const T & get(size_t index, size_t virtual_padding=0) const
Retrieves the value at the specified index, or 'zero'. Optimizes for e.g. 256-bit fields by storing a...
size_t virtual_size() const
size_t end_
The ending index of the memory-backed range.
PolynomialSpan subspan(size_t offset, size_t length)
Fr & operator[](size_t index)
PolynomialSpan(size_t start_index, std::span< Fr > span)
const Fr & operator[](size_t index) const
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr bool is_zero() const noexcept
void throw_or_abort(std::string const &err)