# ACIR Arithmetic Expressions: How do selectors work?

**URL:** <https://forum.aztec.network/t/acir-arithmetic-expressions-how-do-selectors-work/602>\
**Category:** General\
**Tags:** noir\
**Created:** [June 18, 2023, 10:55pm UTC](https://forum.aztec.network/t/acir-arithmetic-expressions-how-do-selectors-work/602 "2023-06-18T22:55:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jp4g](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jp4g](https://forum.aztec.network/u/jp4g)\
**Post date:** [June 18, 2023, 10:55pm UTC](https://forum.aztec.network/t/acir-arithmetic-expressions-how-do-selectors-work/602/1 "2023-06-18T22:55:41Z")

</div>

**CONTEXT**  
Take this [simple multiplication circuit](https://github.com/Ethan-000/halo2_backend/blob/0.1.1/tests/test_programs/1_mul/src/main.nr). We can run `nargo prove p --print-acir` just to print the ACIR opcodes, which are shown here:

```auto
BLACKBOX::RANGE [(_1, num_bits: 32)] []
BLACKBOX::RANGE [(_2, num_bits: 32)] []
BLACKBOX::RANGE [(_3, num_bits: 32)] []
EXPR [(1, _1, _2) (-1, _4) 0]
DIR::QUOTIENT (out : _%EXPR [(1, _4, _4) 0]%, (_6, %EXPR [2³²]%), _5)
BLACKBOX::RANGE [(_5, num_bits: 32)] []
BLACKBOX::RANGE [(_6, num_bits: 96)] []
EXPR [(-1, _4, _4) (-1, _14) 0]
EXPR [(1, _5) (2³², _6) (1, _14) 0]
EXPR [(1, _5, _5) (-1, _7) 0]
DIR::QUOTIENT (out : _%EXPR [(1, _7, _7) 0]%, (_9, %EXPR [2³²]%), _8)
BLACKBOX::RANGE [(_8, num_bits: 32)] []
BLACKBOX::RANGE [(_9, num_bits: 96)] []
EXPR [(-1, _7, _7) (-1, _16) 0]
EXPR [(1, _8) (2³², _9) (1, _16) 0]
EXPR [(-1, _3) (1, _8) (-1, _10) 0]
DIR::INVERT (_10, out: _11) 
EXPR [(1, _10, _11) (-1, _12) 0]
EXPR [(1, _10, _12) (-1, _10) 0]
EXPR [(1, _12) 0]

```

We are attempting to translate these expressions into a standard plonk gate. What is already clear:

- The first element (`q`) in a tuple represents the selector, and the “`_`” prefixed values are witness indexes.
- `(q, _l, _r)` represents a multiplicative term, and `(q, _x)` represents a linear combination

**QUESTIONS**

1. When `q = 1`, this denotes a selector toggled on, right?
2. Does `q = -1` denote a selector toggled off, such that the selector should be witnessed as 0? If not, how is `q = -1` interpreted?
3. Infrequently, we see `q = 2³²`. How is this value interpreted as a selector?

---

<div class="post-metadata">

**Author:** ![jp4g](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jp4g](https://forum.aztec.network/u/jp4g)\
**Post date:** [June 21, 2023, 8:44pm UTC](https://forum.aztec.network/t/acir-arithmetic-expressions-how-do-selectors-work/602/2 "2023-06-21T20:44:08Z")

</div>

Answered by @kevaundray in Noir Discord:

I’ll start off with something simpler than what you wrote. Lets say I want to prove the following:

```auto
5x + 6y == 1

```

We would only need to use an Expression/Arithmetic gate for this since there are no range constraints, or black box functions above. The first thing we need to do is make one side of the equation equal to zero because this is what our expression terms implicitly do.

```auto
5x + 6y == 1

```

Is then the same as:

```auto
5x + 6y -1 == 0

```

Now we can express this in terms of an ACIR Expression gate. It would be:

```auto
EXPR [(5, _1), (6, _2) -1]

```

Whether this has a 1-1 correspondence with selectors in PLONK depends on your PLONK system(ie how it represents arithmetic equations). In general, I would say yes though.

**Standard PLONK**  
For standard plonk, you have one equation: `q_M w_L w_R + q_L w_L + q_R w_R + q_O w_O + q_C`

The above would translate into:

```auto
q_M = 0 
q_L = 5
w_L = 1
q_R = 6
w_R = 2
q_O = 0
w_O = 0
q_C = -1 

```

**Turbo Plonk**  
For TurboPlonk and a lot of other more complex plonk arithmetisations, you will also have selectors which toggle parts of the equation/gates off. So in TurboPlonk there is a q\_Arith selector which is always 1 or 0. When its 1 it means we are doing an arithmetic constraint, and when its zero, we are doing another constraint. This is sort of implied by the fact that we are processing an ACIR Expression and not explicitly stated in the ACIR opcodes. We would not be able to do that because the IR aims to be generic over different plonk configurations and R1CS
