Arithmetic modulo of negative number

2.3k Views Asked by At

According to Modulo of a negative number

"In arithmetic modulo , we seek to express any $$ as $+$, where $$ must be a non-negative integer."

This makes sense to me as we are trying to group numbers into classes from $0$ to $n$.

E.g. If $n = 4$, then one of the following holds: $$a \equiv b \pmod 4 \iff \begin{cases} a, b \in [0] = \{4k + 0\mid k\in \mathbb Z\} = \{\cdots, -8, -4, 0, 4, 8, 12,\cdots\} \\ \\ a, b \in [1] = \{4k + 1\mid k \in \mathbb Z\} = \{\cdots, -7, -3, 1, 5, 9, 13,\cdots\} \\ \\ a ,b \in [2] = \{4k + 2\mid k \in \mathbb Z\} = \{\cdots, -6, -2, 2, 6, 10, 14,\cdots\} \\ \\ a, b \in [3] = \{4k + 3\mid k \in \mathbb Z\} = \{\cdots, -5, -1, 3, 7, 11, 15, \cdots\} \end{cases} $$

But according to Shall remainder always be positive?

For example: $$-48\bmod{5} = 2$$ and $$-48 \bmod{5} = -3$$ are both true because

"2 and −3 are just two names for the same element" (Means they are the same name for same class I assume)

Hence $r$ can be a non-negative integer which disproves the original statement? I am confused.

3

There are 3 best solutions below

0
On BEST ANSWER

In mathematics, one usually writes “$a\equiv b\pmod m$”, and that means precisely that $b-a$ is a multiple (an integral multiple, more specifically) of $m$. With this definition and this notation, $m$ can be any integer, positive, negative, or zero.

0
On

Operations are (single-valued) functions. The most common definition used for the operation is $ mod $ is the least natural $≡(mod)$, which is the remainder $$ left by $÷$. Then we have $≡(mod)⟺mod=mod$.

0
On

The division with remainder is usualy defined from left to right.

As has been said by other posters.

If $n\ mod\ m\neq 0$ with $m>0$ one asks for the largest integer multiple $mq$ which is less than n and the remainder is the difference $r=n-mq$

Hence r is always $>0$

A way to get negative remainders would be to consider division from right to left instead.

For a given modulo $m>0$ we have remainders $\{-m+1,\dots,-1,0\}$ instead of $\{0,1,\dots,m-1\}$ and $mq$ is the least integer multiple of m larger than n .

Both definitions are equivalent,

$n=r\ mod\ m$ for some $r\in \{0,\dots,m-1\}$ according to left right division iff $n=m-r\ mod\ m$ which is $n=-m+r\ mod\ m$ according right left division.

In the second system one would get the result of OP's example $-48=-3\ mod\ 5$ and respectivly $48=-2\ mod\ 5$.

If one wants negative remainders for $n<0$ and positive remainders $n>0$ one can

introduce a shift function which assigns remainder $-m+r=-(m-r)$ to n whenever n is negative

and r otherwise,where r is defined for n and m in the canonical way

Where i have seen negative remainders being used is when considering quadratic congruences like $x^2=-1\ mod\ m$ which is the same with asking for $x^2=m-1\ mod\ m$