J Software

Zero Divided by Zero

E. E. McDonnell

Introduction

The reason for wanting a definition for zero divided by zero is given by Falkoff and Iverson in The Design of APL as "it was deemed desirable to avoid an error trap in this case." Since this is so, and since current implementations of APL give one as the result of zero divided by zero, this paper gives the reasons why J changed this quotient to zero.

Divisors and Quotients

The number D is a divisor of a number N if there is an integer K for which M=K*D. K is called the quotient of M divided by D. Since 0=K*0 for all integers K, zero is a divisor of zero. Indeed, any number may be substituted for K, so that the choice of quotient for zero divided by zero is arbitrary. The quotient is said to be indeterminate.

Choosing a Quotient for Zero Divided by Zero

Although zero divided by zero is indeterminate, it is desirable to provide a fixed quotient for it in a programming environment, in order to reduce the number of circumstances when it is necessary to interrupt the execution of a problem. The definition in APL is based on the identity:

1=Z%Z

The behavior of Z%Z as Z approaches zero from any direction suggests that one is indeed a suitable quotient. This argument has the defect that an equally valid argument suggests that the limit of (X*Z)%(Y*Z) as X approaches zero is X%Y. In this sense, one has no better standing than any other number as the quotient. In fact, it is a poorer choice than zero, as the rest of this paper demonstrates.

The Choice of Zero as Quotient of Zero Divided by Zero

There is a conflict between the two identities:

1=Z%Z
0=0%Z

They cannot both be identities for all Z. If the first is preserved, the second is lost, and vice-versa. Since multiplying both sides of the first by Z yields the tautology Z=Z. Behind the second is the more interesting equation 0=Z*0, which expresses the fundamental multiplicative property of zero.

The Direction and Magnitude Functions

Consider the definition of a number as a directed magnitude. This implies the definition Z=(*Z)*|Z, from which we obtain the definitions of the direction (that is, the signum) and magnitude functions as follows:

Direction =: % |
Magnitude =: % *

Observe that both of these definitions fail in APL, but both are true in the entire complex plane in J.

The Least Common Multiple Function

The definition of the least common multiple function (lcm) is:

LCM =: * % +.

where x +. y yields the greatest common divisor (gcd) of x and y. Since 0*0 is 0, and 0+.0 is 0, it is clear that the lcm of zero and zero is zero; in fact, zero is the only multiple of zero. In J the definition holds universally. In APL the definition fails.

Distributivity of Division Over Addition

Consider the identity:

((D%C)+(B%C)) = (D+B) % C

which expresses the distributivity of division over addition. The identity can be generalized to vectors:

(+/V%C) = (+/V) % C

When D, B, and C, and all the items of V are zero, or when V is empty, both identities fail in APL, and succeed in J.

The Arc Function

In the complex plane the arc function, also known variously as the phase, amplitude, argument, or angle, of a number is:

Arc =: [: Arctan Imaginary % Real

In APL the result of Arc 0 is the implausible pi%4, and in J it is the more comfortable 0.

The definitions of the above functions:

Real =: 9&o.
Imaginary =: 11&o.
Arctan =: _3&o.

The Effect on the Logarithm Dyad

The definition of the logarithm dyad is:

log =: ^. % ^.

As a consequence, in APL, for any base B, B log B is 1 for all B, and B log 1, for B unequal to 1, is 0. In J the situation is reversed: B log B is 0, for B unequal to 1, and B log 1 is 0 for all B.

The Argument from Symmetry

With the real number line in view, the choice of some number, in particular 1, is not too obviously eccentric. With the complex plane in view, however, it is obvious that 0 is the only centric choice.

Tables of the Divide, Gcd, and Lcm Functions

The symmetries in the following table of the results of J's divide function applied to five small arguments repay study, especially row 0, column 0, and their intersection.

] y =. i: 2
_2 _1 0 1 2


   y by y over %/~y  NB. divide
+--+------------------+
|  |  _2 _1  0  1    2|
+--+------------------+
|_2|   1  2 __ _2   _1|
|_1| 0.5  1 __ _1 _0.5|
| 0|   0  0  0  0    0|
| 1|_0.5 _1  _  1  0.5|
| 2|  _1 _2  _  2    1|
+--+------------------+

Here are the similar tables for J's gcd and lcm functions:

 y by y over +./~y  NB. gcd
+--+-----------+
|  |_2 _1 0 1 2|
+--+-----------+
|_2| 2  1 2 1 2|
|_1| 1  1 1 1 1|
| 0| 2  1 0 1 2|
| 1| 1  1 1 1 1|
| 2| 2  1 2 1 2|
+--+-----------+
   y by y over *./~y  NB. lcm
+--+-------------+
|  |_2 _1 0  1  2|
+--+-------------+
|_2| 2  2 0 _2 _2|
|_1| 2  1 0 _1 _2|
| 0| 0  0 0  0  0|
| 1|_2 _1 0  1  2|
| 2|_2 _2 0  2  2|
+--+-------------+