Next: , Up: notes nan   [Index]


K.1.1 How to deal with infinities

Infinities can appear as literals in Scheme source code as ‘+inf.0’ or ‘-inf.0’, and they can be the result of an expression composing Scheme arithmetic functions.

We have to distinguish between number objects as defined in R6RS Scheme, and numbers as defined by Mathematics.

Infinities in the mathematical realm

We can take that Algebra defines groups as couples (S, o) where: S is a set of mathematical entities, o is an operation that composes two entities in S and evaluates to some mathematical entity. We can define the group (R, +), where R is the set of real numbers and + is the common addition, because they are compliant with the following axioms:

Closure

For every couple of reals, their sum is a real.

Associativity

For every triplet of reals:

a + (b + c) = (a + b) + c
Identity element

There exists a unique real 0 for which, for every real a:

0 + a = a + 0 = a
Inverse element

For every real a there is a unique other real b for which:

a + b = 0  ⇒  a = -b

the existence of the inverse element for addition allows the definition of subtraction. The couple (R, *), the reals with the ordinary product, is also a group:

Closure
\forall a, b \in R     a * b = c   c \in R
Associativity
a * (b * c) = (a * b) * c
Identity element
1 * a = a * 1 = a
Inverse element
a * b = 1  ⇒  a = 1/b

the existence of the inverse element for multiplication allows the definition of division.

The triplet (S, +, *) in which S is a set of mathematical entities, and + and * are composition operations with the properties for a group, is called field if the following additional axioms hold:

Commutativity
a + b = b + a    a * b = b * a
Distributivity
a * (b + c) = a * b + a * c

Human experience shows that it is convenient to state (simplified): Every mathematical entity which is not compliant with the axioms of a field is not a number.

Infinities are abstract mathematical entities which we can define through the following disequations:

\forall r \in R        -\infty < r < +\infty

which means:

we notice that the comparison operator < does not define a group, because the result of 1 < 2 (as defined in Mathematics) is a boolean value not a number.6

Despite the fact that we can compare them to numbers, infinities are not numbers in the Mathematics sense. We can show this with the following simple mathematical computation; let’s consider the following equation:

4 + +\infty = x

what should we take as value for x? x cannot be a number like, say, 8, because:

4 + +\infty = 8
⇒ +\infty = 8 - 4 = 4
⇒ +\infty = 4  Wrong!

the only answer that tries to make some sense is x = +\infty, but then:

4 + +\infty = +\infty
⇒  4 = +\infty - +\infty = 0
⇒  4 = 0  Wrong!

if we assume that infinities are numbers, some perfectly legal algebraic manipulation yields a wrong result. Human beings define mathematical entities based on their usefulness; human experience shows that it is more useful to avoid absurd equations like 4 = 0, than to define infinities as numbers.

So, infinities are not numbers and the equation 4 + \infty = x is wrong in the sense that, in Mathematics, it is an error to write it.

Mathematics is not “perfect”, in the sense that it allows us to write wrong equations; unfortunately we can recognise an equation as wrong only by trying to solve it.

Let’s look at this equation:

   4 - 3       1
------------ = - = x
12 - (4 + 8)   0

what should we take as value for x?

If we had the limit:

         1
\lim    --- = x      t > 0
t -> 0   t

we would know that x -> +\infty (x approaches +\infty, it is not equal to it). Computing 1 / t for t smaller and smaller, yields a result that is a bigger and bigger positive number, which approaches the mathematical entity greater than all the positive numbers; that is +\infty.

But what about the straight 1 / 0 = x? The only mathematical entity that makes sense as answer is x = +\infty, so 1 / 0 is not a number. We can demonstrate this with the following simple computation:

3 * (1 / 0) = y
⇒  3 / 0 = y
⇒  3 = y * 0 = 0
⇒  3 = 0   Wrong!

so, it is impossible for 1 / 0 and y to comply with the axioms.

Infinities in the computer realm

Number objects are all the Scheme values for which the predicate number? returns #t. Both the infinities ‘+inf.0’ and ‘-inf.0’ are number objects. This way Scheme defines a class of values which can be used as arguments to arithmetic procedures, and which can potentially be the return value of an arithmetic procedure.

We acknowledged that, when a mathematical expression is non–compliant with the axioms of definition of numbers, we can verify it by doing the computation and checking the final or partial results. A computer can do the same by detecting, for example, if a division has 1 and 0 as operands.

It turns out that making a computer processor interrupt a computation when an expression is wrong, is inefficient. So two special values were defined to allow a computation to signal that special error: ‘+inf.0’ and ‘-inf.0’.

When a computation returns ‘+inf.0’ and ‘-inf.0’ we know that the expression was wrong. R6RS Scheme defines the following conventional results:

(div 1 0) ⇒ error
(/   1 0) ⇒ error

(/   1.0 0)   ⇒ +inf.0
(/   1   0.0) ⇒ +inf.0
(/   1.0 0.0) ⇒ +inf.0

when both the operands are exact, the expression raises an error; when one of the operands is inexact, the expression yields infinity.

Special rules were defined to avoid to mistake a wrong computation for a correct one; for example:

(+ 44 (* 23 +inf.0)) ⇒ +inf.0
(+ 44 (* 23 -inf.0)) ⇒ -inf.0

we know that both of these are wrong, but we also know that they are wrong in that special way for which returning an infinity makes some sense. It is our responsibility to decide what to do.

The special rules makes it impossible for an expression to return a finite number if one of the partial results was an infinity. Sometimes the composition of two infinities can yield an infinity with no confusion; examples:

(+ +inf.0 +inf.0) ⇒ +inf.0
(+ -inf.0 -inf.0) ⇒ -inf.0

(- +inf.0 -inf.0) ⇒ +inf.0  ;like (+ +inf.0 +inf.0)
(- -inf.0 +inf.0) ⇒ -inf.0  ;like (+ -inf.0 -inf.0)
(- +inf.0 -inf.0) ⇒ +inf.0  ;like (+ +inf.0 +inf.0)

(* +inf.0 +inf.0) ⇒ -inf.0
(* +inf.0 -inf.0) ⇒ -inf.0
(* -inf.0 -inf.0) ⇒ +inf.0

but some expressions are difficult to deal with:

(+ +inf.0 -inf.0) ⇒ ?
(+ -inf.0 +inf.0) ⇒ ?

(- -inf.0 -inf.0) ⇒ ?
(- -inf.0 +inf.0) ⇒ ?

(/ +inf.0 +inf.0) ⇒ ?
(/ +inf.0 -inf.0) ⇒ ?
(/ -inf.0 +inf.0) ⇒ ?
(/ -inf.0 -inf.0) ⇒ ?

neither a number nor an infinity makes sense as result here; we need NaN.


Footnotes

(6)

This holds despite the fact that many programming languages allow a disequation to yield a number.


Next: , Up: notes nan   [Index]