Skip to content

Commit

Permalink
Use polynomial_sum instead of naive sum (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass authored May 22, 2024
1 parent 95a1950 commit ca5f455
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,14 @@ namespace nil {

F_dfs[3] = zero_polynomial;

for (std::size_t i = 1; i < sorted.size(); i++) {
typename FieldType::value_type alpha = transcript.template challenge<FieldType>();
math::polynomial_dfs sorted_shifted = math::polynomial_shift(sorted[i-1], preprocessed_data.common_data.desc.usable_rows_amount , basic_domain->m);
F_dfs[3] += alpha * preprocessed_data.common_data.lagrange_0 * (sorted[i] - sorted_shifted);
std::vector<math::polynomial_dfs<typename FieldType::value_type>> F_dfs_3_parts(std::next(sorted.begin(), 1), sorted.end());
for (std::size_t i = 0; i < F_dfs_3_parts.size(); i++) {
typename FieldType::value_type alpha = transcript.template challenge<FieldType>();
math::polynomial_dfs sorted_shifted = math::polynomial_shift(sorted[i], preprocessed_data.common_data.desc.usable_rows_amount , basic_domain->m);
F_dfs_3_parts[i] -= sorted_shifted;
F_dfs_3_parts[i] *= alpha * preprocessed_data.common_data.lagrange_0;
}

/* for( std::size_t i = 0; i < basic_domain->m; i++){
BOOST_CHECK( F_dfs[0].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() );
BOOST_CHECK( F_dfs[1].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() );
BOOST_CHECK( F_dfs[2].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() );
BOOST_CHECK( F_dfs[3].evaluate(basic_domain->get_domain_element(i)) == FieldType::value_type::zero() );
}*/
F_dfs[3] = polynomial_sum<FieldType>(std::move(F_dfs_3_parts));

return {
std::move(F_dfs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ namespace nil {
transcript.template challenges<FieldType, f_parts>();

// 7.2. Compute F_consolidated
polynomial_dfs_type F_consolidated_dfs(
0, _F_dfs[0].size(), FieldType::value_type::zero());
for (std::size_t i = 0; i < f_parts; i++) {
std::vector<polynomial_dfs_type> F_consolidated_dfs_parts(_F_dfs.begin(), _F_dfs.end());
for (std::size_t i = 0; i < F_consolidated_dfs_parts.size(); ++i) {
if (_F_dfs[i].is_zero()) {
continue;
}
F_consolidated_dfs += alphas[i] * _F_dfs[i];
F_consolidated_dfs_parts[i] *= alphas[i];
}
polynomial_dfs_type F_consolidated_dfs = polynomial_sum<FieldType>(std::move(F_consolidated_dfs_parts));

polynomial_type F_consolidated_normal(F_consolidated_dfs.coefficients());

Expand Down

0 comments on commit ca5f455

Please sign in to comment.