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

chore: minimize usage of get_row in inverse computation #7431

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ template <typename FF_> class LogDerivLookupRelationImpl {
table_index * eta_three;
}

/**
* @brief Construct the polynomial I whose components are the inverse of the product of the read and write terms
* @details If the denominators of log derivative lookup relation are read_term and write_term, then I_i =
* (read_term_i*write_term_i)^{-1}.
* @note Importantly, I_i = 0 for rows i at which there is no read or write, so the cost of this method is
* proportional to the actual number of lookups.
*
*/
template <typename Polynomials>
static void compute_logderivative_inverse(Polynomials& polynomials,
auto& relation_parameters,
const size_t circuit_size)
{
auto& inverse_polynomial = get_inverse_polynomial(polynomials);

for (size_t i = 0; i < circuit_size; ++i) {
// We only compute the inverse if this row contains a lookup gate or data that has been looked up
if (polynomials.q_lookup[i] == 1 || polynomials.lookup_read_tags[i] == 1) {
auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly!
inverse_polynomial[i] = compute_read_term<FF, 0>(row, relation_parameters) *
compute_write_term<FF, 0>(row, relation_parameters);
}
}
// Compute inverse polynomial I in place by inverting the product at each row
FF::batch_invert(inverse_polynomial);
};

/**
* @brief Log-derivative style lookup argument for conventional lookups form tables with 3 or fewer columns
* @details The identity to be checked is of the form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class MegaFlavor {
void compute_logderivative_inverses(const RelationParameters<FF>& relation_parameters)
{
// Compute inverses for conventional lookups
compute_logderivative_inverse<MegaFlavor, LogDerivLookupRelation<FF>>(
LogDerivLookupRelation<FF>::compute_logderivative_inverse(
this->polynomials, relation_parameters, this->circuit_size);

// Compute inverses for calldata reads
Expand Down
Loading