7
$\begingroup$

I am currently studying java programming and am a bit shaken up by the concept of integer division. I guess it is just a matter of getting used to that $1/2=0$, but I am afraid it might take some time, given that this property of the division operator (/) is inconsistent with mathematics.

Or is it? Reading the section in Wikipedia on division of integers seems to imply that it is an ambiguous concept (see the following link). The statement that the set of integers is not closed under division (i.e. integer division might produce elements that are not integers) makes sense to me, as does option 2 in the following list. The list puzzles me, however. Its existence implies that we have a choice in the matter, and that one of them (option 4) permits you to call "$1/2=0$" a true statement.

So, is the meaning of integer division really just a matter of taste? Can "$1/2=0$" be a true statement, even in a strict mathematical sense, depending on how you interpret it?

  • 0
    I deleted the tag integer-programming. The confusion is understandable but it turns out that integer-programming refers to something quite different.2012-03-30

3 Answers 3

7

It all depends on what you want your "division" operation to do. In other words, what properties should it satisfy. In real numbers (or rationals, or complex, etc.), the most essential property relates $/$ to $\times$:

Division is Inverse to Multiplication: $a/b = c$ if and only if $b \times c = a$.

However, even in familiar number systems, the operation is not closed. $a/0$ is undefined (since there is no real (or rational, or complex) $c$ such that $0 \times c = a$. The situation is even more restricted in integers, where $a/b$ can only be defined when $b$ divides $a$.

The "integer division" operation (which exists in many computer applications using the same symbol "$/$"), fixes the closure property (that is, $a/b$ is defined for all integers except when $b=0$), but fails the Inverse property in general. IMHO, there ought to be separate notation, such as the "Quotient" function of Mathematica:

Quotient[a,b] = integer quotient of $a$ and $b$, roughly, how many whole times $b$ goes into $a$.

When you mention consistency, it is always with respect to the properties of the operation. Quotient does not have the same properties as $/$, and is a well-defined function of integers (except when the divisor is $0$).

Hope this Helps!

  • 0
    @Hurkyl: I did not know that (and probably should have because I use sage constantly). Thanks!2012-03-31
3

Remember the actual meaning of division: We say that $a/b=c$ if and only if $a = b \cdot c$. But since there is no integer $z$ such that $2z = 1$, this means that a simple definition of division over integers is, by neccesity, incomplete: $1/2$ does simply not exist in this sense.

On the other hand, there is a fairly simple solution, that is in fact also provided by common programming languages: You may define division as division with remainder, i.e.: We say that $a/b$ is $q$ with remainder $r$ if and only if $a = bq + r$. By specifiying that, e.g., $0 \le r < b$, this definition yields unique results for all $a$ and $b \neq 0$, and the value of $q$ is, for natural $a$ and $b$, exactly $\mathtt{a/b}$ for most programming languages. In C-derived languages (e.g., Java), the remainder $r$ is given by $\mathtt{a\%b}$.

  • 0
    I just meant to say that there is no way to define division of integers without remainder and without contradictions.2012-03-30
2

As others have mentioned, mathematical notation is heavily overloaded where one symbol can be used for several, potentially incompatible, notions. The correct notion is (usually) given or can be inferred from context, at least to the level of detail needed. Programming languages exacerbate this problem.

Ultimately, you can have any symbol mean anything as long as you provide a definition. That said, integer division isn't an ad-hoc contrivance, though it is arguably incorrectly implemented in most programming languages. Taking Shaun's "essential property" of division, we can weaken it to another property that completely characterizes integer division. Let $b$ be a positive integer, and $a$ and $c$ any integers. Then the following property (a Galois connection or adjunction) characterizes integer division: $\textrm{forall }a \textrm{ and } c\quad a\times{}b \leq c\quad \textrm{if and only if}\quad a \leq c/b$ Note that this is equivalent also to $\textrm{forall }a \textrm{ and } c\quad a\times{}b \gt c\quad \textrm{if and only if}\quad a \gt c/b$ So what should $5/3$ be? If we say $0$, then we'd have forall $a$, $a \gt 5/3 = 0$ implies $a\times{}3 \gt 5$ which is not true for $a=1$. If we say $2$, then we'd have forall $a$, $a \leq 5/3 = 2$ implies $a\times{}3 \leq 5$ which is not true for $a=2$. $a=1$ does satisfy the property. More interesting, work out what $(-5)/3$ should be and compare it to your favorite programming language.