# How can this be expressed as a MILP constraint?

I am looking for a constraint to express the following:

IF W1 = 0 AND W2 = 0 THEN Y = 1
IF W1 = 0 AND W2 = 1 THEN Y = 1
IF W1 = 1 AND W2 = 0 THEN Y = 0
IF W1 = 1 AND W2 = 1 THEN Y <= 1

Variables W1, W2, Y are binaries. Y is determined by the aforementioned relations. So, I am looking for an expression Y(W1,W2) = ???

\begin{align*} 1-\omega_1 &\le y \\ \omega_1 - \omega_2 &\le 1- y \end{align*}
• If $$\omega_1 = 0$$ and $$\omega_2 \in \{0,1\}$$, then the equations hold only if $$y = 1$$
• If $$\omega_1 = 1$$ and $$\omega_2 = 0$$, then the equations hold only if $$y = 0$$
• If $$\omega_1 = 1$$ and $$\omega_2 = 1$$, then the equations hold if $$y \in \{ 0,1\}$$
@Kuifje’s answer is correct. Here’s how you can obtain the constraints via conjunctive normal form. The first two propositions can be combined, and the fourth proposition is a tautology, so we want to enforce $$(\neg W_1\implies Y)\land ((W_1\land \neg W_2)\implies\neg Y).$$ Rewriting in conjunctive normal form yields $$(W_1\lor Y)\land ((\neg W_1\lor W_2)\lor\neg Y)\\ (W_1+Y\ge 1)\land (1-W_1+W_2+1-Y\ge 1)\\ (Y\ge 1-W_1)\land (1-Y\ge W_1-W_2).$$