# Express XOR with multiple inputs in zero-one integer linear programming (ILP)

In the below post, it is explained how to express xor of two variables as linear inequalities.

Express boolean logic operations in zero-one integer linear programming (ILP)

Naturally, the xor of multiple variables can be expressed using a sequence of multiple 2-input xors but my question whether there is a smarter way to do it?

• Can you clarify your goals? What do you mean by "smarter"? What's wrong with using a sequence of 2-input xors? Have you tried that with your particular problem? Was there some problem with it? We normally expect you to flesh out your question by telling us what you're looking for, how you will evaluate answers, and what you've tried. – D.W. Mar 25 '15 at 20:32

Here is another way you could try. To express $y=x_1 \oplus x_2 \oplus \dots \oplus x_n$ (the exclusive-or of $x_1,\dots,x_n$), try the following constraints:
$$y = x_1 + x_2 + \dots + x_n - 2t$$ $$0 \le y \le 1$$
where $y$ and $t$ are constrained to be integers.