How is is possible that $-9 \bmod 4 = -1$ or $-9 \bmod 4 = 3$?
How it can be possible that the remainder has these two alternatives?
Particularly this is in computer languages, where Java produces $-1$ and e.g. C++ doesn't decide between $3$ or $-1$.
I understand that $-1$ is a reasonable answer. But I don't understand why $3$ can be an answer.
Computer programmers are not mathematicians.
To a mathematician $-9 \bmod 4 =3$ or $-9 \bmod 4 = -1$ are both meaningless garbage.
Instead $-9 \equiv 3 \mod 4$,which is more properly written as $-9\equiv 3\pmod 4$, would mean that the numbers $-9$ and $3$ are equivalent in that they share the property that one is a multiple of $4$ more or less than the other.
So both $-9 \equiv 3 \mod 4$ and $-9 \equiv -1 \mod 4$ and $9 \equiv 14394847 \mod 4$ are all true statements.
tl;dr
$\mod 4$ is not an operation that gives a single answer. It is a statement about two numbers.
INSTEAD for the purpose of programming $a \bmod 4$ has different meaning. It usually means the remainder you get when you divide by $4$.
Now if $a$ is a positive number like $9$ that is simple: $9 = 4*2 + 1$ so $9 \bmod 4 = 1$.
But what about a negative number. What is $-9 \bmod 4$? What is the remainder when you divide $-9$ by $4$? Well, to a mathematician: finding the remainder of $N$ when divided by $q$ is $r$ means that there are unique integers $d$ and $r$ so that $N = d*q + r$ and $0 \le r < q$. And the remainder $r$ is ALWAYS NON-NEGATIVE and is always LESS than what we are dividing.
So $-9 \bmod 4 = 3$ because $-9 = 4*(-3) + 3$
But most non-mathematicians would say "dividing a negative number is just the same thing as dividing a positive number but we are taking the opposite signs". $9 \bmod 4 = 1$ because $9 = 4*8 + 1$ so $-9 = 4*(-2) - 1$ and $-9 \bmod 4 = -1$.
So which is right?
Well, .... whichever one you want. We aren't talking fundamental rules of the universe. We are talking rules that we make up to do what we define things to be and the one that is correct is the one that is consistent with the rules as we made them up.
So one language used one argument and another used another.