Skip to main content

batch_multiplicative_inverse

Function batch_multiplicative_inverse 

Source
pub fn batch_multiplicative_inverse<F>(x: &[F]) -> Vec<F>
where F: Field,
Expand description

Compute the multiplicative inverse of every element in a slice via Montgomery’s trick.

Replaces n field inversions with one inversion plus ~3n multiplications:

  • forward pass: build prefix products of the inputs,
  • one inversion of the full product,
  • reverse pass: derive each individual inverse from the prefix products.

The forward pass is a long dependency chain. It is parallelised on two axes:

  • 4-lane packed arrays — four independent chains run side by side,
  • 1024-element chunks — dispatched across Rayon workers.

Lengths not a multiple of 4 finish with a scalar pass on the trailing 1..=3 elements.

§Panics

Panics if any input is zero.