Why isn't $n \bmod m \le |m|?$
I thought it holds for all integers, it seems to.
But someone said that it has problems if $n < 0$ or $m < 0$.
Why isn't $n \bmod m \le |m|?$
I thought it holds for all integers, it seems to.
But someone said that it has problems if $n < 0$ or $m < 0$.
On
The symbol $\bmod$ is used in different ways in mathematics and computer science. Sometimes, it's a binary operator, where you can say something like $23\bmod 5 = 3$. In that usage, the result should always be a number from the set $\{0,1,\ldots, |m|-1\}$. This is based on the fact that $n$ can be written in the form: $n=qm+r$ for integers $q$ and $r$ that are unique, subject to the restriction that $0\le r <|m|$.
If $n$ or $m$ is negative, or both, this doesn't make any difference. We can write $-23 = (5)(-5)+2$, so $-13\bmod (-5) = 2$.
Often, when mathematicians talk about modular arithmetic, they're not using the $\bmod$ symbol in this way at all. We write congruences such as $-23\equiv -8\pmod5$. All this means is that the difference between $-23$ and $-8$ is a multiple of $5$. The connection between the two uses is this:
$$n_1\equiv n_2\pmod{m}\;\Leftrightarrow\; n_1\bmod m = n_2\bmod m$$
We have $n\bmod m=n-m\left\lfloor\dfrac{n}{m}\right\rfloor$. The inequality in question follows by $\lfloor x\rfloor\le x<\lfloor x\rfloor+1$.