# logic – Modeling Equality in an ILP

Let's say we have a variable $$a = mathbb {Z} ^ n$$ and another $$M = {0,1 } ^ {n times L}$$. I want to model the logic $$M_ {i, j} iff (a_i == j)$$

I have two cases to consider, $$a_i leq i$$ and $$a_i leq L$$.

## Option 1

We can use the method described in the answer here by modeling the difference of $$a_i$$ and $$j$$. So we have $$M_ {i, j} ssi a_i-j == 0$$

That implies $$1$$ additional binary variable as well as $$4$$ potentially big "Big M" constraints.

## Option 2

We can break down $$a_i$$ in its bits using $$log L$$ additional binary variables. We can also calculate the corresponding binary bit failures for each $$0 leq j leq L$$. Let $$bit ^ {(a)} _ {i, k}$$ Be the $$k$$the little $$a_i$$ and let $$bit_ {j, k} ^ *$$ Be the $$k$$the bit of the integer $$j$$ .
$$a_i = sum_ {k = 0} ^ { log L} 2 ^ kbit ^ {(a)} _ {i, k}$$

We now have the following logic:
$$M_ {i, j} sif the bit ^ {(a)} _ {i, k} odot the bit {j, k} ^ * ; ; ; forall k ; ; ; ; 0 leq k leq log L$$

$$M_ {i, j} = bigwedge_ {k = 0} ^ { log L} bit ^ {(a)} _ {i, k} odot bit_ {j, k} ^ *$$

we can use this publication for NXOR pairs of variables, storing their results in another variable $$z = {0,1 } ^ { log L}$$. We can AND these together using the constraints $$M_ {i, j}> = sum z_i$$ $$M_ {i, j} leq z_i ; ; ; forall i$$

If I'm option 2, we'll have $$log L$$ new variables and 1 constraint to represent the binary decomposition of $$a_i$$. We then $$log L$$ XNOR variables, each of which can be represented with 4 constraints. We can finally represent $$M_ {i, j}$$ with $$log L + 1$$ more constraints. Therefore, we have a total of $$5 log L$$ constraints and $$2 log L$$ new variables.

## TLDR)

1. Is there a way to represent a Boolean variable for the equality of 2 positive integer integers in an ILP that do not involve Big M constraints or binary failures, and if not, which one is generally used?

Note* This is a repost, however I have republished it with only one of the initial questions because of @DW's suggestion and response.