# A binary formula to check if two binary variables are equal

Suppose I have $$X,Y$$ that are equal to one or zero.

Is it possible to formulate a binary variable that is equal to $$1$$ if both $$X,Y$$ have the same value (i.e. $$X=0$$, $$Y=0$$ or $$X=1$$, $$Y=1$$) or equal to $$0$$ if they are different (i.e. $$X=1$$, $$Y=0$$ or $$X=0$$, $$Y=1$$)

Something like $$(2X-1)(2Y-1)$$ is kind of close but not there.

Thank you!

• en.wikipedia.org/wiki/Symmetric_difference Commented Jul 7, 2022 at 18:04
• Which connectives can you use? Commented Jul 7, 2022 at 18:06
• If we view $X$ and $Y$ as Boolean variables, the operation you're describing is the logical connective $\leftrightarrow$ a.k.a. the material biconditional or (especially in the context of digital circuits) $\operatorname{XNOR}$. Commented Jul 7, 2022 at 18:07
• Maybe $Z=1-|X-Y|$ will be OK?
– PC1
Commented Jul 7, 2022 at 18:09
• Or $Z=1-(X-Y)^2$ if you want to have a polynomial Commented Jul 7, 2022 at 18:11

If true is $$1$$ and false is $$0$$, then $$x+y \equiv 0 \, \textrm{mod}(2)$$ if and only if the binary variables $$x$$ and $$y$$ are equal.