Tuesday 24 December 2019

Elementary question on modular arithmetic



I know, this is very simple and dumb question, i just cannot come to understand, the problem is:




Why and how happens this in mathematics?



$$-5 \pmod 4 = 3$$



I know how to get this for positive numbers, but how does it work for negative ones.



I need the explanation of what happens in the background when solving this. Is it the distance from $0$ to $4$?


Answer



Since you seem to be using "mod" as a binary operator rather than as the context for a congruence relation, let's define "mod" precisely: assuming $b > 0$,
$$ a \bmod b = a - b\lfloor a/b \rfloor$$




That is, $a \bmod b$ denotes the distance to $a$, from the largest multiple of $b$ that is not greater than $a$. If you imagine the "number line" with the multiples of $b$ all marked out, then $a \bmod b$ is the distance to the point $a$ from the closest marked point on its left.



In your particular case, of $-5 \bmod 4$, note that the list of all integer multiples of $4$ is: $$\dots, -20, -16, -12, -8, -4, 0, 4, 8, 12, 16, 20, 24, \dots$$
In this list, the largest number (multiple of $4$) that is to the left of $-5$ is $-8$. And the distance from $-8$ to $-5$ is $3$; that is why we say that $-5 \bmod 4 = 3$.
(This is exactly the same way we would calculate $5 \bmod 4$: in the list, the largest number that is to the left of $5$ is $4$, and the distance from $4$ to $5$ is $1$, so we say $5 \bmod 4 = 1$.)


No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...