Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: protogalaxy combiner quotient #3245

Merged
merged 19 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* relationships between these. We aim for a more uniform treatment, to enfore identical and informative naming, and to
* prevent the developer having to think very much about the ordering of protocol entities in disparate places.
*
* Another motivation is iterate on the polynomial manifest of plonk, which is nice in its compatness, but which feels
* Another motivation is iterate on the polynomial manifest of plonk, which is nice in its compactness, but which feels
* needlessly manual and low-level. In the past, this contained even more boolean parameters, making it quite hard to
* parse. A typical construction is to loop over the polynomial manifest by extracting a globally-defined
* "FOO_MANIFEST_SIZE" (the use of "manifest" here is distinct from the manifests in the transcript) to loop
Expand Down
44 changes: 44 additions & 0 deletions barretenberg/cpp/src/barretenberg/honk/proof_system/barycentric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np


def get_A_at_z(z, xs):
result = 1
for x in xs:
result *= (z - x)
return result

def get_A_deriv(i, xs):
result = 1
xi = xs[i]
for j in range(len(xs)):
if j != i:
result *= (xi - xs[j])
return result



points = [2,3]
evals = [2, 3]

z = 5

result = get_A_at_z(z, points)
s = 0
for i in range(len(evals)):
s += evals[i] / ((z - points[i])* get_A_deriv(i, points))
result *= s
print(result)

points = [32, 33, 34, 35, 36]
evals = [1,11,111,1111,11111]

z = 2

result = get_A_at_z(z, points)
s = 0
for i in range(len(evals)):
s += evals[i] / ((z - points[i])* get_A_deriv(i, points))
result *= s
print(result)


26 changes: 15 additions & 11 deletions barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@ namespace barretenberg {

/**
* @todo: TODO(https://github.com/AztecProtocol/barretenberg/issues/713) Optimize with lookup tables?
* @tparam domain_end, domain_start specify the given evaluation domain {domain_start,..., domain_end - 1}
* @tparam num_evals the number of evaluations that are computable with specific barycentric extension formula
*/

template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataCompileTime {
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0> class BarycentricDataCompileTime {
public:
static constexpr size_t domain_size = domain_end - domain_start;
static constexpr size_t big_domain_size = std::max(domain_size, num_evals);

/**
* Static constexpr methods for computing arrays of precomputable data used for barycentric extension and evaluation
*/

// build big_domain, currently the set of x_i in {0, 1, ..., t-1}
// build big_domain, currently the set of x_i in {domain_start, ..., big_domain_end - 1 }
static constexpr std::array<Fr, big_domain_size> construct_big_domain()
{
std::array<Fr, big_domain_size> result;
for (size_t i = 0; i < big_domain_size; ++i) {
result[i] = static_cast<Fr>(i);
result[i] = static_cast<Fr>(i + domain_start);
}
return result;
}
Expand Down Expand Up @@ -109,7 +112,7 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataC
std::array<Fr, num_evals> result;
for (size_t i = 0; i != num_evals; ++i) {
result[i] = 1;
Fr v_i = i;
Fr v_i = i + domain_start;
for (size_t j = 0; j != domain_size; ++j) {
result[i] *= v_i - big_domain[j];
}
Expand All @@ -124,20 +127,21 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataC
static constexpr auto full_numerator_values = construct_full_numerator_values(big_domain);
};

template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataRunTime {
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0> class BarycentricDataRunTime {
public:
static constexpr size_t domain_size = domain_end - domain_start;
static constexpr size_t big_domain_size = std::max(domain_size, num_evals);

/**
* Static constexpr methods for computing arrays of precomputable data used for barycentric extension and evaluation
*/

// build big_domain, currently the set of x_i in {0, 1, ..., t-1}
// build big_domain, currently the set of x_i in {domain_start, ..., big_domain_end - 1 }
static std::array<Fr, big_domain_size> construct_big_domain()
{
std::array<Fr, big_domain_size> result;
for (size_t i = 0; i < big_domain_size; ++i) {
result[i] = static_cast<Fr>(i);
result[i] = static_cast<Fr>(i + domain_start);
}
return result;
}
Expand Down Expand Up @@ -210,7 +214,7 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataR
std::array<Fr, num_evals> result;
for (size_t i = 0; i != num_evals; ++i) {
result[i] = 1;
Fr v_i = i;
Fr v_i = i + domain_start;
for (size_t j = 0; j != domain_size; ++j) {
result[i] *= v_i - big_domain[j];
}
Expand Down Expand Up @@ -247,9 +251,9 @@ template <typename T> inline constexpr bool is_field_type_v = is_field_type<T>::
* @tparam domain_size
* @tparam num_evals
*/
template <class Fr, size_t domain_size, size_t num_evals>
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0>
using BarycentricData = std::conditional_t<is_field_type_v<Fr>,
BarycentricDataCompileTime<Fr, domain_size, num_evals>,
BarycentricDataRunTime<Fr, domain_size, num_evals>>;
BarycentricDataCompileTime<Fr, domain_end, num_evals, domain_start>,
BarycentricDataRunTime<Fr, domain_end, num_evals, domain_start>>;

} // namespace barretenberg
Loading