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

Fix evaluation of dense polynomials over domains smaller than the degree #521

Merged
merged 6 commits into from
Dec 3, 2022

Conversation

tjade273
Copy link
Contributor

@tjade273 tjade273 commented Nov 23, 2022

Fixes the evaluation of dense polynomials over domains smaller than the polynomial degree.

Currently, the coefficients of dense polynomials are truncated to match the size of the evaluation domain. This causes unexpected / incorrect behavior when larger polynomials are used. This PR resolves the issue by reducing the polynomial mod X^d where d is the size of the domain, before the FFT is performed.

A new unit test is located in src/polynomial/univariate/sparse.rs

It may also be a good idea to throw an error in the FFT routine when the coefficient vector is bigger than the FFT size, so that information is not accidentally discarded.

closes: #520


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@tjade273 tjade273 marked this pull request as ready for review November 23, 2022 14:30
@tjade273 tjade273 requested review from a team as code owners November 23, 2022 14:30
@tjade273 tjade273 requested review from Pratyush, mmagician and weikengchen and removed request for a team November 23, 2022 14:30
Evaluations::from_vec_and_domain(domain.fft(&d.coeffs), domain)
let chunks = d.coeffs.chunks(domain.size());
let reduced = chunks.fold(vec![F::zero(); domain.size()], |x, y| {
x.iter().zip(y).map(|(&x, y)| x + y).collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x.iter().zip(y).map(|(&x, y)| x + y).collect()
cfg_iter!(x).zip(y).map(|(&x, y)| x + y).collect()

Copy link
Member

@Pratyush Pratyush Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can avoid extra allocations here by making this a for loop, like so:

let mut reduced = chunks.next().unwrap();
for chunk in chunks {
    cfg_iter_mut!(reduced).zip(chunk).for_each(|(x, y)| {
    *x += y;
});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the notes, should be better now.

Copy link
Member

@Pratyush Pratyush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Just left a small comment.

@Pratyush Pratyush merged commit 840b493 into arkworks-rs:master Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DensePolynomial::evaluate_over_domain truncates polynomial coefficients
2 participants