aztec-packages icon indicating copy to clipboard operation
aztec-packages copied to clipboard

`bigfield`: simplify division when denominator is a constant

Open suyash67 opened this issue 6 months ago • 0 comments

In internal_division function:

https://github.com/AztecProtocol/barretenberg/blob/4306250af7b46d804168b59b37cec65303acbc63/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp#L922-L926

We compute:

$$a = \frac{n_1 + n_2 + \dots + n_k}{d}$$

for bigfield elements $n_1, n_2, \dots, n_k$ and $d$. We can add a minor simplification when the denominator $d$ is a constant. We can compute $\textcolor{grey}{d^{-1}}$ outside the circuit and then compute:

$$a = (n_1 + n_2 + \dots + n_k) \ast (\textcolor{grey}{d^{-1}})$$

in the circuit using the multiplication operator $\ast$. It seems though this would not reduce any gates but could simplify the code a bit.

suyash67 avatar Jun 28 '25 19:06 suyash67