Do we have $-1\bmod 2 \equiv -1$ or $+1$?

149 Views Asked by At

As far I can calculate $-1 \bmod 2 \equiv -1$, but the software I am using (R) is telling that $-1 \bmod 2 \equiv +1$.

This is the R code:

-1%%2
[1]1

Which is correct?

2

There are 2 best solutions below

0
On

There are two different but related definitions attached to $\pmod{n}$.

For the first, we think of $\pmod{n}$ as an equivalence relation that is dividing $\mathbb{Z}$ into $n$ equivalence classes, wherein $a \equiv b \pmod{n}$ whenever $n|(b-a)$. In this context, you are certainly correct! $-1 \equiv -1 \pmod{2}$ since $-1 - (-1) = 0$ and certainly $2|0$. Further, it is also correct to say that $-1 \equiv 1 \pmod{2}$ since $-1 - 1 = -2$ and $2|-2$.

In the other definition, we think of $\pmod{n}$ as a function $f:\mathbb{Z} \rightarrow \{0, 1, 2, \cdots, n-1\}$ wherein $a \equiv r \pmod{n}$ if $r$ is the remainder we get after dividing $a$ by $n$. It's worth noting that, with the first definition in mind, $a$ and $r$ fall into the same equivalence class.

Your software is using the second definition.

0
On

If you're referring to the equivalence relation, then $-1 \equiv 1 \pmod 2$, so both answers are the same.

If it's specifically the remainder operator you're curious about, then see this answer of mine.