a = b ( mod n) is defined as
n | a - b
That is n is a divisor of a -b
( a, b, n integers n non zero)
Obviously if p is prime and p | n
Then also a = b ( mod p)
The case of a negative denominator doesn't seem to make sense when talking about modulo in an algebraic sense. I don't think you can have a Ring with a negative dimension. So I've never even thought about what % would do with a negative denominator (RHS). If I was using % with an unknown denominator as input, I could just as easily end up with it being 0 which would be a bad thing, so I think it's fair to say I always require it to be positive.
To the grandparent:
> sends each number to a special representative of its equivalence class
The problem is that many programming languages have a “remainder” type % operator which does not do this in the case where the dividend is negative. For instance,
-1 % 3 == -1
2 % 3 == 2
Instead, folks who want mathematically reasonable behavior need to implement their own. For instance in Javascript we can define mod = (a, b) => a - b*Math.floor(a/b)I tend to define
mod = (a, b) => (a % b + b) % b
because it works without going through floats – in languages that have integer types. I don’t know if there are actual advantages though.