Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the signed modulo operation:

$(x\ \mathrm{mod}\ 2) = \begin{cases} 0\ \mathrm{if}\ x\ \mathrm{is\ even} \\ 1\ \mathrm{if}\ x > 0\ \mathrm{and}\ x\ \mathrm{is\ odd} \\ -1\ \mathrm{if}\ x < 0\ \mathrm{and}\ x\ \mathrm{is\ odd} \\ \end{cases}$

share|cite|improve this question
What exactly is your question? – example Mar 28 '12 at 19:30
I think the question is how to enforce the constraint that $x$ and $y$ have the same parity in an integer program. The OP should edit, though. – Louis Mar 28 '12 at 19:42

If the question is what I think it is, then you have an integer program with (integer) variables $x$ and $y$, and you want to enforce the constraint that $x$ and $y$ have the same parity. This is the case when $x-y$ is even, so you can add some variable $z$ and the the equation $$x - y - 2z = 0$$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.