[r6rs-discuss] on rationale 2.1 Infinities, NaNs

From: Thomas Lord <lord>
Date: Tue, 26 Jun 2007 09:58:35 -0700

    */2.1 Infinities, NaNs/*
    /However, as most Scheme implementation use an IEEE 754-conformant
    implementation [16
    <http://www.r6rs.org/document/rationale-html-5.95/r6rs-rationale-Z-H-28.html#node_bib_16>]
    of flonums, R^6 RS uses the particular semantics from this standard
    as the basis for the treatment of infinities and NaNs in the report.
    This is also the reason why infinities and NaNs are flonums and thus
    inexact real number objects, allowing Scheme systems to exploit the
    closure properties arising from their being part of the standard
    IEEE-754 floating-point representation./



With that design, the procedure real? is assigned two, mutually
contradictory roles. On the one hand, it represents a domain over
which certain Scheme math operators are closed. On the other hand, it
represents the mathematical concept of membership in the set *R*.

Normal flonums ambiguously denote members of *R*. NaN denotes bottom,
not a number at all. Plus and minus infinity ambiguously denote
members of *R* /or/ bottom. An actual (effective, named) bottom (NaN)
or possible bottom (+/-inf) can arise in a computation either because
the primitive facilities for flonum math can't represent a result in a
better way /or because the primitive facilities can prove that no real
number result is guaranteed to exist/.

That is why the two roles being assigned to the predicate real? are
mutually contradictory. For the closure properties referred to in the
rationale, NaN and the inf values must be included. Yet,
mathematically, NaN is not a number and +/-inf might not be numbers.

Scheme's numeric type predicates have traditionally referred to fairly
basic mathematical concepts. They distinguish between exact and
inexact, and between *N*, *R*, and *C* for example, not between
*Fixnum*, *Bignum*, *Flonum*, etc.

In keeping with that tradition, applying real? to NaN ought not return
#t for there is nothing about NaN that tells us that a computation has
yielded some (possibly ambiguous) member of *R*.

For each of the Scheme domains *Real*, *Complex*, etc. (as given by the
predicates of the same name) we could define a second domain, *Real**,
*Complex**, etc. which includes both effective bottoms (like NaN) and
ambiguous values that might denote a bottom (like +/- inf). In that
way, programs that want to propagate Nan and +/-inf through equations
and skip the costs of explicit tests for them can use predicates like
real*? and complex*? while programs that are interested in the
mathematically certain properties of a value can stick to real? and
complex?.

The main job for the Scheme standard is to require that procedures which
are strict in their arguments preserve bottom. That is: if an
effective bottom is an argument, then the result is bottom; if a
possible bottom is an argument, then the result must be a possible
bottom or a bottom. The only exceptions to this rule are type
predicates that test for effective bottoms or possible bottoms (e.g.,
nan? or real*?).

An interesting design choice still remains: what should be the value of
(real? nan.0) or of (real? inf.0)?

The general rule that NaN is a bottom value tells us that, given NaN,
real? must not return #t but #f seems an equally incorrect answer. NaN
can arise a computation either because no mathematically correct result
exists, or because the implementation could not produce a mathematically
correct result. Programs should not assume that what is denoted by
NaN either is or is not a member of *R*. Perhaps it is simply an error
if a program is strict in the question of whether NaN is or is not a
member of *R*.

-t

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r6rs.org/pipermail/r6rs-discuss/attachments/20070626/a1eca1db/attachment.htm
Received on Tue Jun 26 2007 - 12:58:35 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC