Can I simplify this formula to use only one module operation?
$$(x + (y \text{ mod } z)) \text{ mod }z$$
Intuitively I simplified it so:
$$(x + y) \text{ mod } z$$
This seems to do the same as the original. However, I don't know why it works nor if this is right.
Mathematically, this is correct. Let $y$ = $mz+y'$, with $0 {\le}y'{\lt}z$. Then $x+y$ = $x+y'+mz$, so $x+y$ and $x+y'$ clearly have the same remainder modulo $z$.
However, if you are performing this calculation on a computer, beware: If $x$ and $y$ are of integer type (signed or unsigned), it is possible that adding $x$ to $y$ overflows while adding $x$ to $y'$ does not, which may impact the result.