1

Been trying to prove different versions of something similar for so long now. Any help would be appreciated!

EDIT: x and w are integers.

$\left[x \operatorname{mod} 2^w+ x \operatorname{div} 2^w\right] \operatorname{mod} (2^w -1) = x \operatorname{mod}(2^w -1)$

Maybe I'm unclear but $\operatorname{div}$ is integer division which is not equivalent with $\div$ which is floating point division, and $\operatorname{mod}$ is modulo.

2 Answers2

3

Let just write $x=2^wq+r$ with $q\in\mathbb Z$ and $r\in\{0,1,2,..,2^w-1\}$ where $q$ and $r$ are simply the quotient and remainder in Euclidian division.


$\begin{array}{ll} x \pmod{2^w}=r & \mathrm{definition}\\ x\ \operatorname{div}\ 2^w = q & \mathrm{definition}\\ x = 2^wq+r+(q-q)=(2^w-1)q+(q+r)\Rightarrow x\equiv q+r\pmod{(2^w-1)} & \mathrm{insane\ trick}\\ \end{array}$


So yes $q+r\pmod{(2^w-1)}\equiv x\pmod{2^w-1}$, I did nothing that fancy but explicitely writing definitions.

zwim
  • 28,563
0

It's just a radix $\,\color{#c00}n = 2^w$ analog of (partially) casting out nines, which computes the remainder modulo $9\, (= $ radix $\!-\!1)$ by summing the decimal digits. Let's make the analogy clear:

${\rm mod}\ 9\!:\,\ \color{#c00}{10\equiv 1}\,\Rightarrow 123 = 12\cdot \color{#c00}{10} + 3\equiv 12+3 \equiv 123\!\div\! 10 + 123\bmod 10$

${\rm mod}\ n\!-1\!:\,\ \color{#c00}{n\equiv 1}\,\Rightarrow\,x =\!\!\!\!\underbrace{ q\cdot \color{#c00}{n}\ +\ r}_{\rm division\ algorithm}\!\!\!\!\! \equiv q\ +\ r\,\equiv\ \underbrace{x\div n}_{\large q}\ +\ \underbrace{x\bmod n}_{\large r} $

Yours is just the prior for radix $\, n = 2^w$

Bill Dubuque
  • 272,048