From 547ce6b9c1be04004171520656de6c9c4bf17ff1 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Tue, 8 Sep 2020 23:37:34 -0400 Subject: [PATCH 1/4] Address issue 18: consolidate variable / method names for subspaces and cosets into .shift() --- libiop/algebra/exponentiation.tcc | 4 +- libiop/algebra/fft.tcc | 6 +-- libiop/algebra/field_subset/field_subset.hpp | 1 - libiop/algebra/field_subset/field_subset.tcc | 6 +-- libiop/algebra/field_subset/subgroup.tcc | 2 +- libiop/algebra/field_subset/subspace.hpp | 12 ++--- libiop/algebra/field_subset/subspace.tcc | 42 +++++++-------- libiop/algebra/lagrange.tcc | 8 +-- .../polynomials/lagrange_polynomial.tcc | 2 +- .../polynomials/linearized_polynomial.tcc | 22 ++++---- .../polynomials/vanishing_polynomial.hpp | 2 +- .../polynomials/vanishing_polynomial.tcc | 52 +++++++++--------- .../additive_successor_ordering.tcc | 54 +++++++++---------- .../encoded/common/boundary_constraint.tcc | 2 +- .../encoded/sumcheck/sumcheck_aux.tcc | 2 +- libiop/protocols/ldt/fri/fri_aux.hpp | 4 +- libiop/protocols/ldt/fri/fri_aux.tcc | 18 +++---- libiop/protocols/ldt/fri/fri_ldt.tcc | 12 ++--- 18 files changed, 125 insertions(+), 126 deletions(-) diff --git a/libiop/algebra/exponentiation.tcc b/libiop/algebra/exponentiation.tcc index a7777cf6..3bf46197 100644 --- a/libiop/algebra/exponentiation.tcc +++ b/libiop/algebra/exponentiation.tcc @@ -66,8 +66,8 @@ std::vector subspace_to_power_of_two(const affine_subspace &S, el = libiop::power(el, power_of_two); } - const FieldT offset_power = libiop::power(S.offset(), power_of_two); - return all_subset_sums(basis_powers, offset_power); + const FieldT shift_power = libiop::power(S.shift(), power_of_two); + return all_subset_sums(basis_powers, shift_power); } template diff --git a/libiop/algebra/fft.tcc b/libiop/algebra/fft.tcc index 5d8b9b62..929d47b8 100644 --- a/libiop/algebra/fft.tcc +++ b/libiop/algebra/fft.tcc @@ -52,7 +52,7 @@ std::vector additive_FFT(const std::vector &poly_coeffs, size_t recursed_betas_ptr = 0; std::vector betas2(domain.basis()); - FieldT shift2 = domain.offset(); + FieldT shift2 = domain.shift(); for (size_t j = 0; j < m; ++j) { FieldT beta = betas2[m-1-j]; @@ -135,7 +135,7 @@ std::vector additive_IFFT(const std::vector &evals, std::vector recursed_twists(m, FieldT(0)); std::vector betas2(domain.basis()); - FieldT shift2 = domain.offset(); + FieldT shift2 = domain.shift(); for (size_t j = 0; j < m; ++j) { const FieldT beta = betas2[m-1-j]; @@ -439,7 +439,7 @@ std::vector IFFT_of_known_degree_over_field_subset( field_subset domain) { /** We do an IFFT over the minimal subgroup needed for this known degree. - * We take the subgroup with the coset's offset as an element. + * We take the subgroup with the coset's shift as an element. * The evaluations in this coset are every nth element of the evaluations * over the entire domain, where n = |domain| / |degree| */ diff --git a/libiop/algebra/field_subset/field_subset.hpp b/libiop/algebra/field_subset/field_subset.hpp index 52bbc79a..bbcffd3d 100644 --- a/libiop/algebra/field_subset/field_subset.hpp +++ b/libiop/algebra/field_subset/field_subset.hpp @@ -64,7 +64,6 @@ class field_subset { FieldT generator() const; - const FieldT& offset() const; const FieldT shift() const; const std::vector& basis() const; diff --git a/libiop/algebra/field_subset/field_subset.tcc b/libiop/algebra/field_subset/field_subset.tcc index d4d0e264..7d94c7b4 100644 --- a/libiop/algebra/field_subset/field_subset.tcc +++ b/libiop/algebra/field_subset/field_subset.tcc @@ -226,7 +226,7 @@ field_subset field_subset::get_subset_of_order(const std::size_t input_subspace_basis.resize(subset_dim); return field_subset( affine_subspace(input_subspace_basis, - this->offset())); + this->shift())); } case multiplicative_coset_type: // Assumes this subgroup's generator is the default generator for a subgroup of that order. @@ -289,11 +289,11 @@ FieldT field_subset::generator() const } template -const FieldT& field_subset::offset() const +const FieldT& field_subset::shift() const { assert(this->type_ == affine_subspace_type); - return this->subspace_->offset(); + return this->subspace_->shift(); } template diff --git a/libiop/algebra/field_subset/subgroup.tcc b/libiop/algebra/field_subset/subgroup.tcc index 50533d64..63109db2 100644 --- a/libiop/algebra/field_subset/subgroup.tcc +++ b/libiop/algebra/field_subset/subgroup.tcc @@ -165,7 +165,7 @@ std::size_t multiplicative_subgroup_base::reindex_by_subgroup(const std: /** Let x be the number of elements in G \ S, for every element in S. Then x = (|G|/|S| - 1). * At index i in G \ S, the number of elements in S that appear before the index in G to which * i corresponds to, is floor(i / x) + 1. - * The +1 is because index 0 of G is S_0, so the position is offset by at least one. + * The +1 is because index 0 of G is S_0, so the position is shift by at least one. * The floor(i / x) term is because after x elements in G \ S, there is one more element from S * that will have appeared in G. */ const std::size_t x = order_g_over_s - 1; diff --git a/libiop/algebra/field_subset/subspace.hpp b/libiop/algebra/field_subset/subspace.hpp index e26e1e06..53d7dd0d 100644 --- a/libiop/algebra/field_subset/subspace.hpp +++ b/libiop/algebra/field_subset/subspace.hpp @@ -50,15 +50,15 @@ class linear_subspace { template class affine_subspace : public linear_subspace { protected: - FieldT offset_; + FieldT shift_; public: affine_subspace() = default; - affine_subspace(const std::vector &basis, const FieldT &offset = FieldT(0)); - affine_subspace(const linear_subspace &base_space, const FieldT &offset = FieldT(0)); - affine_subspace(linear_subspace &&base_space, const FieldT &offset = FieldT(0)); + affine_subspace(const std::vector &basis, const FieldT &shift = FieldT(0)); + affine_subspace(const linear_subspace &base_space, const FieldT &shift = FieldT(0)); + affine_subspace(linear_subspace &&base_space, const FieldT &shift = FieldT(0)); - const FieldT& offset() const; + const FieldT& shift() const; std::vector all_elements() const; FieldT element_by_index(const std::size_t index) const; @@ -68,7 +68,7 @@ class affine_subspace : public linear_subspace { static affine_subspace shifted_standard_basis( const std::size_t dimension, - const FieldT& offset); + const FieldT& shift); static affine_subspace random_affine_subspace(const std::size_t dimension); bool operator==(const affine_subspace &other) const; diff --git a/libiop/algebra/field_subset/subspace.tcc b/libiop/algebra/field_subset/subspace.tcc index bfc16f2f..79881ed8 100644 --- a/libiop/algebra/field_subset/subspace.tcc +++ b/libiop/algebra/field_subset/subspace.tcc @@ -128,58 +128,58 @@ bool linear_subspace::operator!=(const linear_subspace &other) c template affine_subspace::affine_subspace(const std::vector &basis, - const FieldT &offset) : - linear_subspace(basis), offset_(offset) + const FieldT &shift) : + linear_subspace(basis), shift_(shift) { } template affine_subspace::affine_subspace( const linear_subspace &base_space, - const FieldT &offset) : + const FieldT &shift) : linear_subspace(base_space), - offset_(offset) + shift_(shift) { } template affine_subspace::affine_subspace( linear_subspace &&base_space, - const FieldT &offset) : + const FieldT &shift) : linear_subspace(std::move(base_space)), - offset_(offset) + shift_(shift) { } template -const FieldT& affine_subspace::offset() const +const FieldT& affine_subspace::shift() const { - return this->offset_; + return this->shift_; } template std::vector affine_subspace::all_elements() const { - return all_subset_sums(this->basis_, this->offset_); + return all_subset_sums(this->basis_, this->shift_); } template FieldT affine_subspace::element_by_index(const std::size_t index) const { - return (this->offset_ + (linear_subspace::element_by_index(index))); + return (this->shift_ + (linear_subspace::element_by_index(index))); } template bool internal_element_in_subset(const typename libiop::enable_if::value, FieldT>::type x, - FieldT offset, size_t dimension) + FieldT shift, size_t dimension) { throw std::invalid_argument("subspace.element_in_subset() is only supported for binary fields"); } template bool internal_element_in_subset(const typename libiop::enable_if::value, FieldT>::type x, - FieldT offset, size_t dimension) + FieldT shift, size_t dimension) { /** TODO: Implement this case */ if (dimension > 64) @@ -187,13 +187,13 @@ bool internal_element_in_subset(const typename libiop::enable_if= basis.dimension(), the coefficient of x^i is 0. * Due to the representation of field elements, * this corresponds to all but the first basis.dimension() bits being 0. * (using little endian ordering) */ - const std::vector words = (x + offset).as_words(); + const std::vector words = (x + shift).as_words(); /* Check that all but the least significant 64 bits are 0 */ for (size_t i = 1; i < words.size(); i++) { @@ -211,7 +211,7 @@ bool affine_subspace::element_in_subset(const FieldT x) const { if (this->is_standard_basis_) { - return internal_element_in_subset(x, this->offset_, this->dimension()); + return internal_element_in_subset(x, this->shift_, this->dimension()); } throw std::invalid_argument("subspace.element_in_subset() is only supported for standard basis"); } @@ -221,7 +221,7 @@ FieldT affine_subspace::element_outside_of_subset() const { if (this->is_standard_basis_) { - return this->offset() + FieldT(1ull << this->dimension()); + return this->shift() + FieldT(1ull << this->dimension()); } throw std::invalid_argument("subspace.element_outside_of_subset() is only supported for standard basis"); } @@ -255,11 +255,11 @@ linear_subspace standard_basis(const std::size_t dimension) template affine_subspace affine_subspace::shifted_standard_basis( const std::size_t dimension, - const FieldT& offset) + const FieldT& shift) { const linear_subspace basis = linear_subspace::standard_basis(dimension); - return affine_subspace(std::move(basis), offset); + return affine_subspace(std::move(basis), shift); } template @@ -267,14 +267,14 @@ affine_subspace affine_subspace::random_affine_subspace(const st { const linear_subspace basis = linear_subspace::standard_basis(dimension); - const FieldT offset = FieldT::random_element(); - return affine_subspace(std::move(basis), offset); + const FieldT shift = FieldT::random_element(); + return affine_subspace(std::move(basis), shift); } template bool affine_subspace::operator==(const affine_subspace &other) const { - return linear_subspace::operator==(other) && this->offset_ == other->offset_; + return linear_subspace::operator==(other) && this->shift_ == other->shift_; } } // namespace libiop diff --git a/libiop/algebra/lagrange.tcc b/libiop/algebra/lagrange.tcc index 246c5f1a..611e14a9 100644 --- a/libiop/algebra/lagrange.tcc +++ b/libiop/algebra/lagrange.tcc @@ -83,7 +83,7 @@ std::vector lagrange_cache::subspace_coefficients_for( * This already has c cached, which allows the shifted V to be calculated directly in one pass. */ const FieldT k = this->vp_.evaluation_at_point(interpolation_point) * this->c_; const std::vector V = - all_subset_sums(this->domain_.basis(), interpolation_point + this->domain_.offset()); + all_subset_sums(this->domain_.basis(), interpolation_point + this->domain_.shift()); // Handle check if interpolation point is in domain if (this->interpolation_domain_intersects_domain_ && k == FieldT::zero()) { std::vector result(this->domain_.num_elements(), FieldT::zero()); @@ -230,7 +230,7 @@ std::vector lagrange_coefficients(const affine_subspace &domain, Our computation below computes: k = (\prod_{i} \alpha - V[i]) = Zero_V(\alpha) - c = 1/{\prod_{j > 0} (V[j] - domain.offset()) = 1 / (Z_{V - offset} / X)(0) + c = 1/{\prod_{j > 0} (V[j] - domain.shift()) = 1 / (Z_{V - shift} / X)(0) and inverses of (\alpha - V[0]), ..., (\alpha - V[2^n-1]) @@ -238,13 +238,13 @@ std::vector lagrange_coefficients(const affine_subspace &domain, */ vanishing_polynomial Z(domain); - /* (Z_{V - offset} / X)(0) is the formal derivative of Z_V, + /* (Z_{V - shift} / X)(0) is the formal derivative of Z_V, * as the affine shift only affects the constant coefficient. */ const FieldT c = Z.formal_derivative_at_point(FieldT::zero()).inverse(); const FieldT k = Z.evaluation_at_point(interpolation_point); std::vector V = - all_subset_sums(domain.basis(), interpolation_point + domain.offset()); + all_subset_sums(domain.basis(), interpolation_point + domain.shift()); const std::vector V_inv = batch_inverse_and_mul(V, c * k); diff --git a/libiop/algebra/polynomials/lagrange_polynomial.tcc b/libiop/algebra/polynomials/lagrange_polynomial.tcc index f8db9cc9..d2e0ca56 100644 --- a/libiop/algebra/polynomials/lagrange_polynomial.tcc +++ b/libiop/algebra/polynomials/lagrange_polynomial.tcc @@ -71,7 +71,7 @@ std::vector lagrange_polynomial::evaluations_over_field_subset( * The additive case admits a faster method to create it, hence the separation */ if (this->S_.type() == affine_subspace_type) { - denominator = all_subset_sums(evaldomain.basis(), this->x_ + evaldomain.offset()); + denominator = all_subset_sums(evaldomain.basis(), this->x_ + evaldomain.shift()); } else if (this->S_.type() == multiplicative_coset_type) { diff --git a/libiop/algebra/polynomials/linearized_polynomial.tcc b/libiop/algebra/polynomials/linearized_polynomial.tcc index 99f0e6f5..314dcd28 100644 --- a/libiop/algebra/polynomials/linearized_polynomial.tcc +++ b/libiop/algebra/polynomials/linearized_polynomial.tcc @@ -68,7 +68,7 @@ std::vector linearized_polynomial::evaluations_over_subspace(con Therefore, evaluating over subspace below, we subtract constant term from evaluations over the basis, but include the constant - term in the offset calculation. */ + term in the shift calculation. */ std::vector eval_at_basis(S.basis()); std::for_each(eval_at_basis.begin(), eval_at_basis.end(), @@ -76,9 +76,9 @@ std::vector linearized_polynomial::evaluations_over_subspace(con el = (this->evaluation_at_point(el) - this->constant_coefficient()); }); - const FieldT offset = this->evaluation_at_point(S.offset()); + const FieldT shift = this->evaluation_at_point(S.shift()); - return all_subset_sums(eval_at_basis, offset); + return all_subset_sums(eval_at_basis, shift); } template @@ -191,17 +191,17 @@ bool linearized_polynomial::operator!=(const linearized_polynomial -void add_scalar_multiple_at_offset(std::vector &result, +void add_scalar_multiple_at_shift(std::vector &result, const std::vector &p, const FieldT &factor, - const size_t offset) { + const size_t shift) { // This is a helper method for linearized polynomial * polynomial - // It adds factor * p to result, starting at offset + // It adds factor * p to result, starting at shift if (factor == FieldT::zero()) { return; } for (std::size_t i = 0; i < p.size(); i++) { - result[i + offset] += p[i] * factor; + result[i + shift] += p[i] * factor; } } @@ -212,16 +212,16 @@ polynomial linearized_polynomial::operator*(const polynomial result(p.degree() + 1 + this->degree(), FieldT::zero()); const std::vector p_coeff = p.coefficients(); // set result to be L[0] * p - add_scalar_multiple_at_offset(result, p_coeff, this->coefficients_[0], 0); + add_scalar_multiple_at_shift(result, p_coeff, this->coefficients_[0], 0); for (std::size_t i = 1; i < this->coefficients_.size(); i++) { - std::size_t offset = 1 << (i - 1); - add_scalar_multiple_at_offset(result, p_coeff, this->coefficients_[i], offset); + std::size_t shift = 1 << (i - 1); + add_scalar_multiple_at_shift(result, p_coeff, this->coefficients_[i], shift); } return polynomial(std::move(result)); } diff --git a/libiop/algebra/polynomials/vanishing_polynomial.hpp b/libiop/algebra/polynomials/vanishing_polynomial.hpp index 5f3ad03e..412ccff2 100644 --- a/libiop/algebra/polynomials/vanishing_polynomial.hpp +++ b/libiop/algebra/polynomials/vanishing_polynomial.hpp @@ -34,7 +34,7 @@ class vanishing_polynomial : public polynomial_base { // subspace type linearized_polynomial linearized_polynomial_; // multiplicative coset type - FieldT vp_offset_; /* offset^|H| for cosets, 1 for subgroups */ + FieldT vp_shift_; /* shift^|H| for cosets, 1 for subgroups */ public: explicit vanishing_polynomial() {}; diff --git a/libiop/algebra/polynomials/vanishing_polynomial.tcc b/libiop/algebra/polynomials/vanishing_polynomial.tcc index 0b28a847..0f1a7c10 100644 --- a/libiop/algebra/polynomials/vanishing_polynomial.tcc +++ b/libiop/algebra/polynomials/vanishing_polynomial.tcc @@ -19,7 +19,7 @@ vanishing_polynomial::vanishing_polynomial(const field_subset &S if (this->type_ == affine_subspace_type) { this->linearized_polynomial_ = vanishing_polynomial_from_subspace(S.subspace()); } else if (this->type_ == multiplicative_coset_type) { - this->vp_offset_ = libiop::power(S.coset().shift(), this->vp_degree_); + this->vp_shift_ = libiop::power(S.coset().shift(), this->vp_degree_); } else { throw std::invalid_argument("field_subset type unsupported."); } @@ -38,7 +38,7 @@ vanishing_polynomial::vanishing_polynomial(const multiplicative_cosetvp_degree_ = S.num_elements(); - this->vp_offset_ = libiop::power(S.coset().shift(), this->vp_degree_); + this->vp_shift_ = libiop::power(S.coset().shift(), this->vp_degree_); } template @@ -46,7 +46,7 @@ FieldT vanishing_polynomial::evaluation_at_point(const FieldT &evalpoint if (this->type_ == affine_subspace_type) { return this->linearized_polynomial_.evaluation_at_point(evalpoint); } else if (this->type_ == multiplicative_coset_type) { - return libiop::power(evalpoint, this->vp_degree_) - this->vp_offset_; + return libiop::power(evalpoint, this->vp_degree_) - this->vp_shift_; } throw std::logic_error("vanishing_polynomial::evaluation_at_point: " " this shouldn't happen"); @@ -81,15 +81,15 @@ std::vector vanishing_polynomial::unique_evaluations_over_field_ std::vector evals = unique_domain.all_elements(); // In the additive case, the associated k to 1 map is the vanishing polynomial, // so the unique domain's evaluations is {Z_H(x) | x in S} - // In the multiplicative case, the associated k to 1 map is Z_H(x) + h_offset^|H| + // In the multiplicative case, the associated k to 1 map is Z_H(x) + h_shift^|H| // Hence te unique domain's evaluations are: - // {Z_H(x) + h_offset^|H| | x in S} - // So we subtract h^|H| from all evals. h^|H| is the vp offset + // {Z_H(x) + h_shift^|H| | x in S} + // So we subtract h^|H| from all evals. h^|H| is the vp shift if (S.type() == multiplicative_coset_type) { for (size_t i = 0; i < evals.size(); i++) { - evals[i] -= this->vp_offset_; + evals[i] -= this->vp_shift_; } } return evals; @@ -118,7 +118,7 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m if (this->type_ != multiplicative_coset_type) { throw std::invalid_argument("evaluations_over_coset can only be used on multiplicative_coset vanishing polynomials."); } - // P is of the form X^|G| - vp_offset + // P is of the form X^|G| - vp_shift const std::size_t order_s = S.num_elements(); const std::size_t order_g = this->vp_degree_; // points in S are of the form hg^i, where h is the shift of the coset, and g is its generator. @@ -130,8 +130,8 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m { // In this case |S| <= |G|, and |G| % |S| = 0. // Therefore g^{i|G|} = 1, consequently - // P(s) = h^|G| - vp_offset, for all s \in S - evals.resize(order_s, shift_to_order_g - this->vp_offset_); + // P(s) = h^|G| - vp_shift, for all s \in S + evals.resize(order_s, shift_to_order_g - this->vp_shift_); return evals; } size_t evaluation_repetitions = 1; @@ -151,7 +151,7 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m FieldT cur = shift_to_order_g; for (std::size_t i = 0; i < number_of_distinct_evaluations; i++) { - evals.emplace_back(cur - this->vp_offset_); + evals.emplace_back(cur - this->vp_shift_); cur = cur * generator_to_order_g; } // Place these distinct evaluations in the remaining locations. @@ -174,7 +174,7 @@ FieldT vanishing_polynomial::constant_coefficient() const { return this->linearized_polynomial_.constant_coefficient(); } // subgroup / coset type - return -this->vp_offset_; + return -this->vp_shift_; } template @@ -189,13 +189,13 @@ std::shared_ptr> else if (this->type_ == multiplicative_coset_type) { /** This returns the polynomial x^{|H|}. - * It does this by altering vp_offset, making a copy of this vanishing polynomial, - * restoring the previous vp_offset, and returning the copy. */ - const FieldT vp_offset_copy = this->vp_offset_; - this->vp_offset_ = FieldT::zero(); + * It does this by altering vp_shift, making a copy of this vanishing polynomial, + * restoring the previous vp_shift, and returning the copy. */ + const FieldT vp_shift_copy = this->vp_shift_; + this->vp_shift_ = FieldT::zero(); std::shared_ptr> copy = std::static_pointer_cast>(std::make_shared>(*this)); - this->vp_offset_ = vp_offset_copy; + this->vp_shift_ = vp_shift_copy; return copy; } throw std::logic_error("should not happen"); @@ -243,13 +243,13 @@ field_subset vanishing_polynomial::associated_k_to_1_map_at_doma returned_basis.emplace_back(transformed_basis[i]); } } - const FieldT transformed_offset = k_to_1_map->evaluation_at_point(domain.offset()); - return field_subset(affine_subspace(returned_basis, transformed_offset)); + const FieldT transformed_shift = k_to_1_map->evaluation_at_point(domain.shift()); + return field_subset(affine_subspace(returned_basis, transformed_shift)); } else if (this->type_ == multiplicative_coset_type) { const FieldT new_shift = k_to_1_map->evaluation_at_point(domain.shift()); - /** The multiplicative vanishing polynomial with no offset is a + /** The multiplicative vanishing polynomial with no shift is a * k to 1 map over any domain of order divisible by k. */ if (domain.num_elements() % this->vp_degree_ == 0) { @@ -273,11 +273,11 @@ polynomial vanishing_polynomial::operator*(const polynomialtype_ == affine_subspace_type) { return this->linearized_polynomial_ * p; } - // in the multiplicative case just shift p, and subtract by p * this->vp_offset_ + // in the multiplicative case just shift p, and subtract by p * this->vp_shift_ std::vector result(p.degree() + this->vp_degree_ + 1, FieldT(0)); const std::vector p_coeff = p.coefficients(); - add_scalar_multiple_at_offset(result, p_coeff, FieldT(1), this->vp_degree_); - add_scalar_multiple_at_offset(result, p_coeff, FieldT(0) - this->vp_offset_, 0); + add_scalar_multiple_at_shift(result, p_coeff, FieldT(1), this->vp_degree_); + add_scalar_multiple_at_shift(result, p_coeff, FieldT(0) - this->vp_shift_, 0); return polynomial(std::move(result)); } @@ -313,7 +313,7 @@ template std::pair, polynomial > polynomial_over_multiplicative_vanishing_polynomial(const polynomial &P, - const FieldT vp_offset, + const FieldT vp_shift, const size_t vp_degree) { /* inverse of the leading term */ @@ -334,7 +334,7 @@ polynomial_over_multiplicative_vanishing_polynomial(const polynomial &P, std::vector remainder(P.coefficients().begin(), P.coefficients().begin() + vp_degree); - FieldT Z_0 = vp_offset; + FieldT Z_0 = vp_shift; for (std::size_t i = quotient.size(); i--; ) { // Z only has 2 terms, the leading term and the constant term. @@ -389,7 +389,7 @@ linearized_polynomial vanishing_polynomial_from_subspace(const affine_su poly = poly.squared() + (poly * poly_c); } - const FieldT poly_shift = poly.evaluation_at_point(S.offset()); + const FieldT poly_shift = poly.evaluation_at_point(S.shift()); poly[0] += poly_shift; return poly; diff --git a/libiop/algebra/trace_embedding/additive_successor_ordering.tcc b/libiop/algebra/trace_embedding/additive_successor_ordering.tcc index a14a8471..14609fe0 100644 --- a/libiop/algebra/trace_embedding/additive_successor_ordering.tcc +++ b/libiop/algebra/trace_embedding/additive_successor_ordering.tcc @@ -100,13 +100,13 @@ additive_successor_polynomial::additive_successor_polynomial(const affin * and the successor of x in (S' + g^(i - 1)) will be g*x + primitive_polynomial(g) * * The following code is calculating constituent terms for each partition polynomial. - * For the affine case, the partitions will account for the offset, but otherwise remain the same. + * For the affine case, the partitions will account for the shift, but otherwise remain the same. * In the below computations, the vanishing polynomials will be over the affine subspaces. */ - /** For partition {0}, the successor of {0} is 1 + affine_offset, and the indicator polynomial is + /** For partition {0}, the successor of {0} is 1 + affine_shift, and the indicator polynomial is * L_{S, 0}, which is the normalized lagrange basis polynomial for the 0th element of S. */ - const FieldT zeroth_element_of_S = this->subspace_.offset(); + const FieldT zeroth_element_of_S = this->subspace_.shift(); const bool is_normalized = true; this->lagrange_indicator_polynomial_ = lagrange_polynomial(zeroth_element_of_S, field_subset(this->subspace_), is_normalized); @@ -114,13 +114,13 @@ additive_successor_polynomial::additive_successor_polynomial(const affin /** S_truncated is the subspace of S with its final basis vector removed. * This is needed for the final two partitions. It is also denoted as S' in comments */ affine_subspace S_truncated = - affine_subspace::shifted_standard_basis(domain.dimension() - 1, domain.offset()); + affine_subspace::shifted_standard_basis(domain.dimension() - 1, domain.shift()); this->Z_S_truncated_ = vanishing_polynomial(S_truncated); /** For partitions S' / {0} and S' + x^(i - 1), - * we need polynomials L_c, for c \in [0,1] such that L_c(cZ_{S'}(g^{i - 1} + affine_offset)) = 1, - * and L_c((1 - c)Z_{S'}(g^{i - 1} + affine_offset)) = 0. */ + * we need polynomials L_c, for c \in [0,1] such that L_c(cZ_{S'}(g^{i - 1} + affine_shift)) = 1, + * and L_c((1 - c)Z_{S'}(g^{i - 1} + affine_shift)) = 0. */ const FieldT multiplicative_generator_to_i_minus_one = - libiop::power(this->multiplicative_generator_, domain.dimension() - 1) + this->subspace_.offset(); + libiop::power(this->multiplicative_generator_, domain.dimension() - 1) + this->subspace_.shift(); this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_ = this->Z_S_truncated_.evaluation_at_point(multiplicative_generator_to_i_minus_one); /** L_0 is the degree 1 polynomial that is 1 when the argument is 0, @@ -137,14 +137,14 @@ template FieldT additive_successor_polynomial::evaluation_at_point(const FieldT &evalpoint) const { /** Affine shift of the subspace. */ - const FieldT offset = this->subspace_.offset(); + const FieldT shift = this->subspace_.shift(); FieldT result = FieldT::zero(); FieldT Z_S_truncated_at_x = this->Z_S_truncated_.evaluation_at_point(evalpoint); /** Partition 0 at x is the lagrange_indicator_polynomial at x */ const FieldT partition_0_eval = this->lagrange_indicator_polynomial_.evaluation_at_point(evalpoint); - /** The value at this partition is (1 + offset) */ - result += partition_0_eval * (FieldT::one() + offset); + /** The value at this partition is (1 + shift) */ + result += partition_0_eval * (FieldT::one() + shift); /** L_0 is the polynomial that is the degree 1 polynomial that is 1 when the argument is 0, * and 0 when the argument is Z_S_at_multiplicative_generator_to_i_minus_one. @@ -153,18 +153,18 @@ FieldT additive_successor_polynomial::evaluation_at_point(const FieldT & const FieldT L_0_eval = this->L_0_coefficient_ * (Z_S_truncated_at_x - this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_); /** This partition is L_0 - partition 0, - * and has value: multiplicative_generator * (X - offset) + offset */ + * and has value: multiplicative_generator * (X - shift) + shift */ result += (L_0_eval - partition_0_eval) * - (this->multiplicative_generator_ * (evalpoint - offset) + offset); + (this->multiplicative_generator_ * (evalpoint - shift) + shift); /** L_1 is the polynomial that is the degree 1 polynomial that is 0 when the argument is 0, * and 1 when the argument is Z_S_at_multiplicative_generator_to_i_minus_one. * So L_1 = k * X * L_1 is evaluated at Z_S'(X) */ const FieldT L_1_eval = this->L_1_coefficient_ * Z_S_truncated_at_x; - /** This partition is L_1, and has value (g * (X - offset) + offset + (primitive polynomial at g)) */ + /** This partition is L_1, and has value (g * (X - shift) + shift + (primitive polynomial at g)) */ result += L_1_eval * - (this->multiplicative_generator_ * (evalpoint - offset) + - offset + this->primitive_polynomial_at_multiplicative_generator_); + (this->multiplicative_generator_ * (evalpoint - shift) + + shift + this->primitive_polynomial_at_multiplicative_generator_); return result; } @@ -173,12 +173,12 @@ template std::vector additive_successor_polynomial::evaluations_over_field_subset( const field_subset &U) const { - const FieldT S_offset = this->subspace_.offset(); + const FieldT S_shift = this->subspace_.shift(); std::vector Z_S_truncated_over_U = this->Z_S_truncated_.evaluations_over_field_subset(U); - /** We only need (x + S_offset) in the evaluation procedure, for x in U. - * Note that we are in a binary field, so (x + S_offset) = (x - S_offset) */ + /** We only need (x + S_shift) in the evaluation procedure, for x in U. + * Note that we are in a binary field, so (x + S_shift) = (x - S_shift) */ std::vector shifted_U_elements = - all_subset_sums(U.basis(), S_offset + U.offset()); + all_subset_sums(U.basis(), S_shift + U.shift()); // If we need to squeeze performance out of this method, // then the lagrange polynomial's evaluation over domain can be opened up here, @@ -189,27 +189,27 @@ std::vector additive_successor_polynomial::evaluations_over_fiel this->lagrange_indicator_polynomial_.evaluations_over_field_subset(U); std::vector result(U.num_elements(), FieldT::zero()); - const FieldT one_plus_S_offset = FieldT::one() + S_offset; + const FieldT one_plus_S_shift = FieldT::one() + S_shift; for (size_t i = 0; i < result.size(); i++) { // The partition 0 polynomial is the lagrange indicator polynomial - // Value at partition 0 is (1 + offset) - result[i] += lagrange_indicator_evaluations[i] * one_plus_S_offset; + // Value at partition 0 is (1 + shift) + result[i] += lagrange_indicator_evaluations[i] * one_plus_S_shift; // The partition 1 polynomial is: L_0(Z_S_truncated(X)) - partition_0(X) const FieldT L_0_eval = this->L_0_coefficient_ * (Z_S_truncated_over_U[i] - this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_); const FieldT partition_1_eval = L_0_eval - lagrange_indicator_evaluations[i]; - // Value at partition 1 is multiplicative_generator * (X - S_offset) + S_offset + // Value at partition 1 is multiplicative_generator * (X - S_shift) + S_shift result[i] += partition_1_eval * - (this->multiplicative_generator_ * shifted_U_elements[i] + S_offset); + (this->multiplicative_generator_ * shifted_U_elements[i] + S_shift); // The partition 2 polynomial is: L_1(Z_S_truncated(X)) const FieldT partition_2_eval = this->L_1_coefficient_ * Z_S_truncated_over_U[i]; - // Value at partition 2 is (multiplicative_generator * (X - S_offset) + S_offset + + // Value at partition 2 is (multiplicative_generator * (X - S_shift) + S_shift + // primitive_polynomial at multiplicative_generator) result[i] += partition_2_eval * - (this->multiplicative_generator_ * shifted_U_elements[i] + S_offset + + (this->multiplicative_generator_ * shifted_U_elements[i] + S_shift + this->primitive_polynomial_at_multiplicative_generator_); } return result; @@ -252,7 +252,7 @@ additive_successor_ordering::additive_successor_ordering(const field_sub template FieldT additive_successor_ordering::first_elem() const { - return this->subspace_.offset(); + return this->subspace_.shift(); } template diff --git a/libiop/protocols/encoded/common/boundary_constraint.tcc b/libiop/protocols/encoded/common/boundary_constraint.tcc index 1b183855..1ae8fd8d 100644 --- a/libiop/protocols/encoded/common/boundary_constraint.tcc +++ b/libiop/protocols/encoded/common/boundary_constraint.tcc @@ -32,7 +32,7 @@ std::shared_ptr> single_boundary_constraint::evaluat { /** Creates a subspace with the correct shift */ field_subset shifted_subspace(this->codeword_domain_.num_elements(), - this->codeword_domain_.offset() + shift); + this->codeword_domain_.shift() + shift); all_shifted_elems = shifted_subspace.all_elements(); } else if (this->codeword_domain_.type() == multiplicative_coset_type) { diff --git a/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc b/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc index 32756f5d..b2420d00 100644 --- a/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc +++ b/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc @@ -19,7 +19,7 @@ std::vector constant_times_subspace_to_order_H_minus_1( subspace_element_powers(subspace, order_H); /** TODO: If we make the codeword domain non-affine in the future, * then we should just remove the zero element before batch inversion. */ - const bool codeword_domain_contains_zero = (subspace.offset() == FieldT::zero()); + const bool codeword_domain_contains_zero = (subspace.shift() == FieldT::zero()); const std::vector x_inv_times_constant = batch_inverse_and_mul( subspace.all_elements(), constant, codeword_domain_contains_zero); std::vector constant_times_x_to_H_minus_1( diff --git a/libiop/protocols/ldt/fri/fri_aux.hpp b/libiop/protocols/ldt/fri/fri_aux.hpp index 2cf366ac..ff5398b9 100644 --- a/libiop/protocols/ldt/fri/fri_aux.hpp +++ b/libiop/protocols/ldt/fri/fri_aux.hpp @@ -32,7 +32,7 @@ template FieldT evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i); @@ -40,7 +40,7 @@ template FieldT additive_evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i); diff --git a/libiop/protocols/ldt/fri/fri_aux.tcc b/libiop/protocols/ldt/fri/fri_aux.tcc index a2735344..8ba3b43f 100644 --- a/libiop/protocols/ldt/fri/fri_aux.tcc +++ b/libiop/protocols/ldt/fri/fri_aux.tcc @@ -51,7 +51,7 @@ std::shared_ptr> additive_evaluate_next_f_i_over_entire_doma * As a consequence, we only need to calculate the vp_coset(x) and vp_coset[1] once. * We then just adjust the vp_coset(x) by the constant term when processing each coset. * TODO: Investigate if we can lower the number of inversions by taking advantage of - * v[k] = unshifted v[k % coset_size] + offset + * v[k] = unshifted v[k % coset_size] + shift */ const std::vector coset_basis = f_i_domain.get_subset_of_order(coset_size).basis(); @@ -70,9 +70,9 @@ std::shared_ptr> additive_evaluate_next_f_i_over_entire_doma { /** By definition of cosets, * shifted vp = unshifted vp - unshifted_vp(shift) */ - const FieldT coset_offset = all_elements[coset_size * j]; + const FieldT coset_shift = all_elements[coset_size * j]; const FieldT shifted_vp_x = unshifted_vp_x - - unshifted_vp.evaluation_at_point(coset_offset); + unshifted_vp.evaluation_at_point(coset_shift); const bool x_in_domain = shifted_vp_x == FieldT::zero(); FieldT interpolation = FieldT::zero(); @@ -252,17 +252,17 @@ template FieldT evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i) { if (unshifted_coset.type() == affine_subspace_type) { return additive_evaluate_next_f_i_at_coset( - f_i_evals_over_coset, unshifted_coset, offset, unshifted_vp, x_i); + f_i_evals_over_coset, unshifted_coset, shift, unshifted_vp, x_i); } else if (unshifted_coset.type() == multiplicative_coset_type) { const FieldT g = unshifted_coset.generator(); return multiplicative_evaluate_next_f_i_at_coset( - f_i_evals_over_coset, g, offset, x_i); + f_i_evals_over_coset, g, shift, x_i); } throw std::invalid_argument("unshifted_coset is of unsupported domain type"); } @@ -271,7 +271,7 @@ template FieldT additive_evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &localizer_domain, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i) { @@ -279,12 +279,12 @@ FieldT additive_evaluate_next_f_i_at_coset( * the subspace lagrange coefficient generation, but with the interpolation being returned. */ /* TODO: Cache unshifted_vp(x_i) and c */ const FieldT vp_x = unshifted_vp.evaluation_at_point(x_i) - - unshifted_vp.evaluation_at_point(offset); + unshifted_vp.evaluation_at_point(shift); const FieldT c = unshifted_vp.get_linearized_polynomial().coefficients()[1].inverse(); const bool x_in_domain = vp_x == FieldT::zero(); /* In binary fields addition and subtraction are the same operation */ const std::vector coset_elems = - all_subset_sums(localizer_domain.basis(), x_i + offset); + all_subset_sums(localizer_domain.basis(), x_i + shift); if (x_in_domain) { for (size_t k = 0; k < f_i_evals_over_coset.size(); k++) diff --git a/libiop/protocols/ldt/fri/fri_ldt.tcc b/libiop/protocols/ldt/fri/fri_ldt.tcc index c1580ae9..e311c83e 100644 --- a/libiop/protocols/ldt/fri/fri_ldt.tcc +++ b/libiop/protocols/ldt/fri/fri_ldt.tcc @@ -313,7 +313,7 @@ void FRI_protocol::compute_domains() { const std::size_t current_localization_parameter = this->params_.get_localization_parameters()[i]; - const FieldT last_subspace_offset = this->domains_[i].offset(); + const FieldT last_subspace_shift = this->domains_[i].shift(); const std::vector& last_subspace_basis = this->domains_[i].basis(); const std::vector localizer_subspace_basis(last_subspace_basis.begin(), @@ -321,7 +321,7 @@ void FRI_protocol::compute_domains() const affine_subspace localizer_subspace(localizer_subspace_basis, FieldT::zero()); const localizer_polynomial localizer_poly(localizer_subspace); - const FieldT next_subspace_offset = localizer_poly.evaluation_at_point(last_subspace_offset); + const FieldT next_subspace_shift = localizer_poly.evaluation_at_point(last_subspace_shift); std::vector next_subspace_basis(last_subspace_basis.begin() + current_localization_parameter, last_subspace_basis.end()); for (size_t i = 0; i < next_subspace_basis.size(); i++) @@ -330,7 +330,7 @@ void FRI_protocol::compute_domains() next_subspace_basis[i] = localizer_poly.evaluation_at_point(el); } - const affine_subspace next_subspace(next_subspace_basis, next_subspace_offset); + const affine_subspace next_subspace(next_subspace_basis, next_subspace_shift); this->domains_.emplace_back(field_subset(next_subspace)); this->localizer_domains_.emplace_back(field_subset(localizer_subspace)); @@ -614,13 +614,13 @@ bool FRI_protocol::predicate_for_query_set(const FRI_query_set &Q) /* Now compute interpolant of f_i|S_i evaluated at x_i (for use in next round). */ - const size_t offset_position = + const size_t shift_position = this->domains_[i].position_by_coset_indices(si_j, 0, current_coset_size); - const FieldT offset = this->domains_[i].element_by_index(offset_position); + const FieldT shift = this->domains_[i].element_by_index(shift_position); FieldT interpolation = evaluate_next_f_i_at_coset( fi_on_si_coset, this->localizer_domains_[i], - offset, + shift, this->localizer_polynomials_[i], x_i); last_interpolation = interpolation; From 4c1711b2581239f0f681642fae3bd10a1a2b3a70 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Wed, 9 Sep 2020 00:03:41 -0400 Subject: [PATCH 2/4] Fix signature in field_subset.tcc --- libiop/algebra/field_subset/field_subset.tcc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libiop/algebra/field_subset/field_subset.tcc b/libiop/algebra/field_subset/field_subset.tcc index 7d94c7b4..77a5d489 100644 --- a/libiop/algebra/field_subset/field_subset.tcc +++ b/libiop/algebra/field_subset/field_subset.tcc @@ -288,20 +288,12 @@ FieldT field_subset::generator() const return this->coset_->generator(); } -template -const FieldT& field_subset::shift() const -{ - assert(this->type_ == affine_subspace_type); - - return this->subspace_->shift(); -} - template const FieldT field_subset::shift() const { - assert(this->type_ == multiplicative_coset_type); - return this->coset_->shift(); + return this->type_ == multiplicative_coset_type? + this->coset_->shift() : this->subspace_->shift(); } template From 185d7506d66efacf5d03d6f5e999a7c59266e665 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Wed, 9 Sep 2020 00:26:35 -0400 Subject: [PATCH 3/4] Remove & from shift method signature --- libiop/algebra/field_subset/subspace.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiop/algebra/field_subset/subspace.hpp b/libiop/algebra/field_subset/subspace.hpp index 53d7dd0d..023f844d 100644 --- a/libiop/algebra/field_subset/subspace.hpp +++ b/libiop/algebra/field_subset/subspace.hpp @@ -58,7 +58,7 @@ class affine_subspace : public linear_subspace { affine_subspace(const linear_subspace &base_space, const FieldT &shift = FieldT(0)); affine_subspace(linear_subspace &&base_space, const FieldT &shift = FieldT(0)); - const FieldT& shift() const; + const FieldT shift() const; std::vector all_elements() const; FieldT element_by_index(const std::size_t index) const; From 46ecabe2cf84f3bebfce672e5a8e1cedcb737640 Mon Sep 17 00:00:00 2001 From: Philip Wang Date: Wed, 9 Sep 2020 00:29:00 -0400 Subject: [PATCH 4/4] Remove & from shift method signature --- libiop/algebra/field_subset/subspace.tcc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiop/algebra/field_subset/subspace.tcc b/libiop/algebra/field_subset/subspace.tcc index 79881ed8..30c57df7 100644 --- a/libiop/algebra/field_subset/subspace.tcc +++ b/libiop/algebra/field_subset/subspace.tcc @@ -152,7 +152,7 @@ affine_subspace::affine_subspace( } template -const FieldT& affine_subspace::shift() const +const FieldT affine_subspace::shift() const { return this->shift_; }