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$?

-
by the definition of modular arithmetic, 4 must divide $-5 - x$. Any x for which $4|(-5 - x)$ is a solution. Since we usually want to end up with a least positive choice for x, if we let x = 3, we have $4|(-5 - 3)$, i.e., $4|-8$. – amWhy Nov 4 '12 at 18:52
Add or substract multiples of $4$ until you get back into the "ballpark". – littleO Nov 4 '12 at 18:53

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$.)

-
Thanks ShreevatsaR, the best explanation! thanks a lot – doniyor Nov 4 '12 at 19:03

$$c \equiv b \pmod{a}$$ is a short hand notation to denote $a \vert (c-b)$ (or) equivalently $b$ is the remainder when $c$ is divided by $a$. Typically, for convenience people have $b \in \{0,1,2,\ldots,a-1\}$.

In your case, you want to evaluate $-5 \pmod{4}$. By that I assume you want to mind $b \in \{0,1,2,3\}$ such that $-5 \equiv b \pmod{4}$ i.e. we want to find $b \in \{0,1,2,3\}$ such that $4 \vert (-5-b)$. Since $4 \vert (-5-b)$, we have that $4 \vert (5 + b)$ and hence $4 \vert (1+b)$. Hence, we get that $b=3$.

Therefore, $$-5 \equiv 3 \pmod{4}$$

To interpret $b \pmod{a}$ as a distance, in the sense you mean, it is the distance of $b$ from the largest multiple of $a$ no larger than $b$ i.e. the largest multiple of $a$ that falls to the left of $b$ or $b$ itself on the real number line. I have tried to illustrate this with couple of diagrams below.

The first picture indicates $b\pmod{a}$ when $b$ falls between $4a$ and $5a$.

The second picture indicates $b\pmod{a}$ when $b$ falls between $-3a$ and $-2a$.

-

$n \mod m$ is the distance between $n$ and $k$: the largest multiple of $m$ such that $k <= n$

In this case, the largest multiple of 4 which is not larger that -5 is -8. Therefore $$-5 \mod 4 = |-5 - (-8)| = 3$$

-
great @pedrosorio, thanks a lot. – doniyor Nov 4 '12 at 19:08