Skip to content

Commit

Permalink
Document what roots_of_unity computes (arkworks-rs#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Dev Ojha <[email protected]>
  • Loading branch information
Pratyush and ValarDragon authored Jan 14, 2021
1 parent d3497c3 commit ea1ef4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
17 changes: 9 additions & 8 deletions poly/src/domain/radix2/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ impl<F: FftField> Radix2EvaluationDomain<F> {
ark_std::cfg_iter_mut!(x_s).for_each(|val| *val *= self.size_inv);
}

/// Computes the first `self.size / 2` roots of unity for the entire domain.
/// e.g. for the domain [1, g, g^2, ..., g^{n - 1}], it computes
// [1, g, g^2, ..., g^{(n/2) - 1}]
#[cfg(not(feature = "parallel"))]
fn roots_of_unity(&self, root: F) -> Vec<F> {
compute_powers_serial(self.size as usize, root)
pub(super) fn roots_of_unity(&self, root: F) -> Vec<F> {
compute_powers_serial((self.size as usize) / 2, root)
}

/// Computes the first `self.size / 2` roots of unity.
#[cfg(feature = "parallel")]
pub(crate) fn roots_of_unity(&self, root: F) -> Vec<F> {
// TODO: Understand why this functions output isn't domain.elements(),
// but it still works.
// See if it can be altered to be in normal order, or to replace
// parallel compute powers.
pub(super) fn roots_of_unity(&self, root: F) -> Vec<F> {
// TODO: check if this method can replace parallel compute powers.
let log_size = ark_std::log2(self.size as usize);
// early exit for short inputs
if log_size <= LOG_ROOTS_OF_UNITY_PARALLEL_SIZE {
compute_powers_serial(self.size as usize, root)
compute_powers_serial((self.size as usize) / 2, root)
} else {
let mut temp = root;
// w, w^2, w^4, w^8, ..., w^(2^(log_size - 1))
Expand Down
10 changes: 6 additions & 4 deletions poly/src/domain/radix2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,21 @@ mod tests {
}

#[test]
#[ignore]
fn test_roots_of_unity() {
// Tests that the roots of unity result is the same as domain.elements()
let max_degree = 10;
for log_domain_size in 0..max_degree {
let domain_size = 1 << log_domain_size;
let domain = Radix2EvaluationDomain::<Fr>::new(domain_size).unwrap();
let actual_roots = domain.roots_of_unity(domain.group_gen);
assert_eq!(actual_roots.len(), domain_size);
for &value in &actual_roots {
assert!(domain.evaluate_vanishing_polynomial(value).is_zero());
}
let expected_roots_elements = domain.elements();
for (i, elem) in expected_roots_elements.enumerate() {
assert_eq!(elem, actual_roots[i]);
for (expected, &actual) in expected_roots_elements.zip(&actual_roots) {
assert_eq!(expected, actual);
}
assert_eq!(actual_roots.len(), domain_size / 2);
}
}

Expand Down

0 comments on commit ea1ef4b

Please sign in to comment.