Modulo operation for integers and reals?

546 Views Asked by At

I read that the modulo operation finds remainder after division. My misconseption here is about the remainder. Is the remainder the last digit of the result? I thought it was the first.

Example: $5/7 = 0.7142857142857142857...$

$5 \mod 8 = 7$.

$7/3 = 2.33333..$ but $7 \mod 3 = 1$. Remainder of the first result is point 3333...

$9/4 = 2.25$ $9 \mod 4 = 1$. Ok same as first but different remainder.

$9/7 = 1.2857142857142...$ $9 \mod 7 = 2$. What? Remainder is two, the first digit. This is probably "random" for reals? But not for integers?

$111111111$ : If there are nine ones we should divide by $7$, it gives $2$ remnants. Since $9-2=7$ ones. So using modulo operation on the reals is not something one should do?

3

There are 3 best solutions below

3
On BEST ANSWER

When you want to compute $a \bmod b$ with $a,b$ positive integers, you do division like you learned in school and write $a=qb+r$ where $q$ is the quotient and $r$ is the remainder. We typically choose $r$ to be in the range $0$ to $b-1$. Then we write $r=a \bmod b$, so is you want $1234 \bmod 7$, you write $1234=176\cdot 7 + 2$, so $1234 \bmod 7=2$. You don't need to do anything with the decimal expansion.

The main time I have seen the modulo operation used with the modulus $b$ other than an integer is reducing angles of a circle when the angles are measured in radians. You compute an angle, then take it $\mod 2\pi$ to put the angle in the range $[0,2\pi)$. You can use other moduli, but this is the common one.

0
On

Let's examine a couple of your examples.

First $\dfrac{7}3 = \color{#0a0}2.333\ldots = \color{#0a0}2 + \dfrac{\color{#c00}1}3\ $ has quotient $\color{#0a0}2$ and remainder $\color{#c00}1$

without fractions: $\ 7 = \color{#0a0}2\cdot 3 + \color{#c00}1$

and $\,\ \dfrac{9}7 = \color{#0a0}1.286\ldots = \color{#0a0}1 + \dfrac{\color{#c00}2}7\ $ has quotient $\color{#0a0}1$ and remainder $\color{#c00}2$

without fractions: $\ 9 = \color{#0a0}1\cdot 7 + \color{#c00}2$

Generally we have $\, a = \color{#0a0}q\cdot b + \color{#c00}r\ $ with remainder $\ \color{#c00}r = a\bmod b\,$ obeying $\, 0\le r < b$

which is obtained by (long) dividing $a$ by $b\,$ (Euclidean division with remainder)

This remainder $r$ is the least natural of the form $\, a-q\,b\,$ for some integer $q$.

Said procedurally: continually add/subtract $b$ from $a$ till you land in the interval $[0,b)$

Note that if $a, b\neq 0$ are reals then the prior procedure still works fine.

0
On

$\frac 73 = 2\frac 13 = 2.333333....$ but neither $\frac 13$ nor $0.33333....$ are the "remainder". $\frac 13$ and $0.3333....$ are the values of the result of dividing a value by a divisor that is larger than it.

The "remainder" is what remains after you have divided everything that will fit in in evenly. $2*3 = 6 < 7$ and $3*3 = 9 > 7$. So the most we can evenly fit $3$ into $7$ is $2$ times. That leaves $7- 2*3 = 1$ that we haven't dealt with and can't deal with unless we get a hammer. So that is the remainder.

We can then take the remainder and a a big hammer and pound it into a fractional bit of $\frac 13$ or $0.33333....$ and take care of it that way. But then ... we have dealt with it. And nothing remains. Because we took care of it.

So by definition, the remainder is the integer that is left after we divide things evenly before we take the hammer and meat grinder to get the fractional parts.

Anyway... the actual digits of the decimal representations have nothing to do with anything.

...

To your examples:

5/7=0.7142857142857142857...

Um... you never do anything with it:

$5 = 0\times 7 + 5; 0*7 < 5 < 1*7$ so $5\div 7 = 0$ with $5$ remainder. $\frac 57 = 0\frac 57$. The remainder is $5$.

$5\equiv 5 \pmod 7$.

5mod8=7

That is incorrect.

$5 = 0\times 8 + 5; 0*8 < 5 < 1*8$ so $5\div 8 = 0$ with $5$ remainder. $\frac 58 = 0\frac 58$. The remainder is $5$.

$5\equiv 5 \pmod 8$.

7/3=2.33333.. but 7mod3=1. Remainder of the first result is point 3333...

$7 = 2\times 3 + 1; 2*3 < 7 < 3*3$ so $7\div 3 = 2$ with $1$ remainder. $\frac 73 = 2\frac 13$. The remainder is $1$.

$7\equiv 1 \pmod 3$.

9/4=2.25 9mod4=1. Ok same as first but different remainder.

$9 = 2\times 4 + 1; 2*4 < 9 < 3*4$ so $9\div 4 = 2$ with $1$ remainder. $\frac 94 = 2\frac 14$. The remainder is $1$.

$9\equiv 1 \pmod 4$.

9/7=1.2857142857142... 9mod7=2. What? Remainder is two, the first digit. This is probably "random" for reals? But not for integers?

$9 = 1\times 7 + 2; 1*7 < 9 < 2*7$ so $9\div 7 = 1$ with $2$ remainder. $\frac 97 = 1\frac 27$. The remainder is $2$.

$9\equiv 2 \pmod 7$.

The fact that the first digit of $\frac 27$ is $2$ is an irrelevent coincidence.

Decimals are not important. There are days where I fantasize that it should be illegal to teach decimals outside of engineering and accounting classes. Any way decimal expansion has NOTHING to do with this question.

111111111 : If there are nine ones we should divide by 7, it gives 2 remnants. Since 9−2=7 ones. So using modulo operation on the reals is not something one should do?

That is .... incomprehensible.

$1111111111 = 15873015\times 7 + 6;15873015*7 < 111111111 < 15873016*7$ so $111111111\div 7 = 15873015$ with $6$ remainder. $\frac {111111111}7 = 15873015 \frac 67$. The remainder is $6$.

$111111111\equiv 6 \pmod 7$.