# How to build comparison operator (comparator) in an arithmetic circuit

I am trying to convert a basic program into an arithmetic circuit. I am stuck on the step of converting the greater than operator into an arithmetic circuit. To be specific, I do not know how to convert the following into an arithmetic circuit (where x,y is input):

if x >= y: return 1 else: return 0

To be clear, I need to be able to express this in terms of an ARITHMETIC circuit. Meaning that I need to be able to compute this using only addition and multiplication of numbers (in Z_p).

I've been searching all of the web for solutions, but everything I find tells me how to do this with boolean circuits. I am aware that I can convert the numbers into their bit string and do this boolean way. I would like to know of any alternative way to do this. This show be possible to do with just addition and multiplication, but I cannot figure out how to.

For context, I'm considering this in the case of Multi-Party Computation. Therefore, taking advantage of how I represent my number (i.e. two's complement) will not work because my number will be split into secret shares.

• – D.W. Jun 27 '19 at 16:40

Generically, comparisons are dependent on how you represent values in $$\mathbb{F}_p$$. For example, in $$\mathbb{F}_3$$ you might want to say that $$1 \leq 2$$, but since $$-1$$ is in the same equivalence class as $$1$$ any polynomial that computes this (for $$\mathbb{F}_3\cong \{0,1,2\}$$) would also compute $$1 \leq -1$$ (for $$\mathbb{F}_3\cong\{-1,0,1\}$$). You could of course use Lagrange Interpolation to get any polynomial to have arbitrary values, but it'd be difficult to call that polynomial "the comparison polynomial", and your model of arithmetic circuits would have to be with respect to a specific representation of field elements (which sounds non-standard, but I'm no expert).
The book by Cramer et al has some commentary on how comparisons using solely $$\mathbb{F}_p$$ arithmetic leads to large circuits, so maybe there is actually some "comparison polynomial" (and m preceding paragraph is wrong), but it appears the standard thing to do still is to convert to an easier representation to do comparisons on for efficiency.
• It's worth mentioning that equality checking can be done via arithmetic circuits, although the corresponding polynomial is high degree. Fermat's little theorem states that $a^p\equiv a\mod p$, so for $a$ invertible (so non-zero) in your finite field you have that $a^{p-1}\equiv 1$. Clearly, $0^{p-1}\equiv 0\mod p$, so the function $x\mapsto x^{p-1}$ allows you to check equality against zero in $\mathbb{F}_p$. This generalizes to other finite fields (see this page). – Mark Jun 26 '19 at 21:56