# Distribution of Modular Expressions

This is really a programming question that I'm unable to solve because of a math question. I'm having a problem understanding the rules of distribution with modular arithmetic.

I have two expressions:

a = q mod c + (n - 1) mod c
b = q mod c - (n - 1) mod c


I made the mistake of concluding that the expressions were equivalent to:

a = (q + n - 1) mod c
b = (q - n + 1) mod c


What would the equivalent equations be?

-

## 1 Answer

Mathematically, they're equivalent, but I think the difference is that in computers the first set you gave is going to potentially evaluate to outputs larger than $c$, while in mathematics we would automatically convert the output of the first two equations mod $c$ again so that the result is in $\{0\dots c-1\}$.

If you take the results of the top two equations mod $c$ again, you should get answers that match the outputs of the second box.

-
It looks like that was exactly what was happening. Thanks for the answer! – Pé de Leão Jun 8 '13 at 16:57