Batch Inverse

Reduction of the number of field inverse operations when computing batch operations.

What is Batch Inverse?

Batch Inverse is a technique used to efficiently compute the inverses of multiple values (v1,,vn)(v_1, \dots, v_n) at once. Normally, calculating each inverse separately requires n×INVn \times \mathsf{INV} (inverse operations), but with Batch Inversion, you can compute all the inverses using just a single inverse operation.

As inverse operations are significantly more expensive than multiplications, this method is especially useful in performance-sensitive contexts—such as in ZK provers.


How Does It Work?

Let’s walk through an example of computing the inverses of four values: (a,b,c,d)(a, b, c, d)

1. Compute Prefix Products

Multiply the values one by one, keeping track of intermediate results:

  • P1=aP_1 = a

  • P2=abP_2 = ab

  • P3=abcP_3 = abc

  • P4=abcdP_4 = abcd

So we get:

P=(P1,P2,P3,P4)P = (P_1, P_2, P_3, P_4)

2. Compute Inverse of the Final Product

Compute the inverse of the final product:

t=P41=(abcd)1t = P_4^{-1} = (abcd)^{-1}

This is the only inverse operation required.

3. Compute Each Inverse in Reverse

Now, traverse the values in reverse to compute individual inverses:

  • d1=P3×td^{-1} = P_3 \times t, then update t=t×d=(abc)1t = t \times d = (abc)^{-1}

  • c1=P2×tc^{-1} = P_2 \times t, then update t=t×c=(ab)1t = t \times c = (ab)^{-1}

  • b1=P1×tb^{-1} = P_1 \times t, then update t=t×b=(a)1t = t \times b = (a)^{-1}

  • a1=ta^{-1} = t

This phase involves only multiplication operations.


Computational Complexity

If the vector has length nn, the total computational cost is:

  1. Prefix Product Computation: (n1)×MUL(n - 1) \times \mathsf{MUL}

  2. One Inverse Operation: 1×INV1 \times \mathsf{INV}

  3. Reverse Traversal: 2(n1)×MUL2(n - 1) \times \mathsf{MUL}

Total:

3(n1)×MUL+1×INV3(n - 1) \times \mathsf{MUL} + 1 \times \mathsf{INV}

Written by ryan Kim of A41

Last updated