1

I have a trivial question. When we divide say 5 by 2, quotient is 2 and remainder is 1. However say we divide -5 by 2, then should we have a quotient -2 and remainder -1 or quotient -3 and remainder 1?

Some people claim that remainder should always be a positive integer smaller than the absolute value of the divisor. But what is the actual formal definition and according to which type of formal arithmetic?

Thanks

Jyrki Lahtonen
  • 133,153
  • By convention when we write $a = qb+ r$ we require $0 \leq r \leq b - 1$. – Josh Mar 09 '16 at 09:21
  • @JoshChen when b is negative, how do you apply this convention? – Cowboy Trader Mar 09 '16 at 10:10
  • Ah, in your original question you only considered $a < 0$. If $b < 0$ then for consistency one should probably choose $0 \leq r < \lvert b \rvert - 1$. – Josh Mar 09 '16 at 10:14
  • Your question has nothing to do with division algebras. Please read the tag wiki before deciding to use one. Admittedly we don't always do a good job with the tag wikis, and sometimes they are lacking in providing guidance in when to use the tag. – Jyrki Lahtonen Mar 10 '16 at 11:54
  • Depending on applications, one can choose the remainder $r$ such that $0\le r<|b|$ or else $-|b|/2< r\le |b|/2$ (this is useful, for instance, when studying the division algorithm in Gaussian integers). – egreg Mar 10 '16 at 12:01
  • 1
    And to comment on your question. There is no official definition about which way the remainder should go in e.g. the case you describe. The reason is that mathematicians usually don't care. Programmers often have to, and several programming languages and processor specifications therefore define it precisely. At least in theory the scopes of those definitions are specific to the given setting only, though naturally they try to conform. For example Mathematica outputs that the remainder of $-7$ modulo $2$ is $1$, and the remainder of $7$ modulo $-2$ is $-1$. Go figure? – Jyrki Lahtonen Mar 10 '16 at 12:01

2 Answers2

1

To actually divide $a$ by $b$, what you do is find the largest integer $bq$ that is less than or equal to $a$. Then $r = a - bq$ will be between $0$ and $q -1$. That is, $a = bq + r$ where $0 \le r \lt q$.

For example, to divide $5$ by $2$:
$2\times2 = 4$ is the largest integer of the form $2q$ such that $2q \le 5$.
So $5 = 2\times2 + 1$ where $0 \le 1 \lt 2$.

To divide $-5$ by $2$:
$2\times(-3) = -6$ is the largest integer of the form $2q$ such that $2q \le -5$.
So $-5 = 2\times(-3) + 1$ where $0 \le 1 \lt 2$.

0

There is no completely formal definition, but the Euclidean algorithm for, say, the rational numbers, suggests that after choosing a quotient $p/q$ to compute, the remainder should lie between 0 and $q-1$.

Mose Wintner
  • 1,203