0

Arithmetic Problem: Remainder of $\frac{-11}{-5}$

Approach1 : $\frac{-11}{-5}=\frac{11}{5}$ ; Now, $11=5\times2+1$ Gives remainder +1.

Approach2 : $\frac{-11}{-5}$; Now, $-11=-5\times2-1$ Gives remainder -1.

According to https://en.wikipedia.org/wiki/Euclidean_division , remainder can't be negative. So, Approach 2 is wrong. Is this conclusion correct?

WolframAlpha gives $-1$. I guess that it does the modulo division via Programming. So, does $-11/-5$ give remainder $1$ in Maths and $-1$ in Programming languages ?

A simple comparison of remainder in Maths and Programming is presented below.

Maths

$11/5 : 11=5\times2+1$; Rem=1

$-11/5 : -11=5\times-3+4$; Rem=4

$11/-5 : 11=-5\times-2+1$; Rem=1

$-11/-5 : -11=-5\times3+4$; Rem=4

Programming(C)

sign of remainder = sign of numerator

$11 \% 5=1$

$-11 \%5 =-1$

$11\%-5=1$

$-11\%-5=-1$

Sahil
  • 674
  • 2
    There really isn’t one remainder, but usually in mathematics, the remainder of $a$ divided by $b$ is $0\leq r<|b|.$ In some computer languages, though, this is not followed. It is frustrating that C does this. – Thomas Andrews Jul 13 '21 at 02:22
  • 2
    @ThomasAndrews: I don't know of any programming languages that deliver non-negative remainders: it ain't just C: they are all frustrating. – Rob Arthan Jul 13 '21 at 02:29

3 Answers3

2

Different programming languages have different views on this. Sadly, few of them agree with what I think is the most natural definition mathematically, which is to take remainders always to be non-negative. However, in your example, the non-negative answer should be $4$, not $1$: $-11 = -5 * 3 + 4$ (whatever convention you follow, the remainders have to be congruent modulo $5$: cancelling the common factor $-1$ before you do the calculation is not valid).

Rob Arthan
  • 48,577
2

I'm not too familiar with the programming aspect, but I can provide the mathematical aspect.

If we start with the division lemma, we start with two integers $a$ and $b$ and state that there exist unique integers $q$ and $r$ such that

$$a=bq+r$$

and

$$0\leq r \leq |b|$$

Your problem has $a=-11$ and $b=-5$. Therefore we need to satisfy

$$-11=-5q+r$$

for some unique integers $q$ and $r$ where $0\leq r <5$.

$q=2$ doesn't work because $r$ will be negative. The next highest $q$ is $q=3$, whereby

$$-11 = (-5 \times 3) + 4$$

where $0\leq r <5$ as required.

Kman3
  • 2,479
1

The Division Theorem:

Given an integer dividend, $N$, and an integer divisor, $D \ne 0$, there exist a unique integer quotient, $q$, and a unique integer remainder, $r$ such that $$ N = Dq + r$$ where $$ 0 \le r \lt |D|$$

The thing is, even though $\dfrac ND = \dfrac{-N}{-d}$, there is no reason to expect to get the same quotient and remainder when you divide $N$ by $D$ as when you divide $-N$ by $-D$. It seems you found that out.

You can, of course, also use negative remainders but you can run into problems with uniqueness. For example $35 = 10 \cdot 3 + 5$ and $35 = 10 \cdot 4 + (-5)$. If you want to ensure that you get unique remainders, you need to choose between $$ \left\lfloor -\frac 12|D| \right\rfloor \le r \le \left\lfloor \frac 12|D| \right\rfloor$$ and $$ \left\lceil -\frac 12|D| \right\rceil \le r \le \left\lceil \frac 12|D| \right\rceil$$