How do I eliminate mod from an expression?

283 Views Asked by At

If I have an expression such as $$ x = ((a \bmod b) - s) \bmod t, \quad 0 < a < b $$ And I want to step to $$ x = (a - s) \bmod t $$

Is acceptable to jump straight from the first expression to the second? Is there a law or rule I should site when eliminating the mod?

2

There are 2 best solutions below

3
On

The usual way the mod function is computed gives a result in $[0,b)$. Since $a$ is already in that range, $a \mod b=a$. You should write "$a \mod b=a$ since $0<a<b$".

0
On

Let us use the definition $r = a \bmod b$ is the remainder when $a$ is divided by $b$ (so $0 \leq r < b$ (without the loss of generality we can assume that $b>0$)). Then $$a=bq+r \qquad \text{with } 0 \leq r < b.$$

In your expression let $w= a \bmod b$, then $a=bq+w$. Since we are given that $0 < a <b$, therefore $q=0$, which implies $w=a$. Thus $$x= ((a \bmod b)-s )\bmod t= (w-s )\bmod t=(a-s) \bmod t.$$