# [R6RS] guiding principles for R6RS arithmetic

William D Clinger will at ccs.neu.edu
Wed Mar 8 07:50:57 EST 2006

```I propose three guiding principles for R6RS arithmetic:

1.  If two implementations produce exact results for
a computation that did not involve exact intermediate
results, the two ultimate results will be mathematically
equivalent.

2.  The results of calculations that involve inexact
intermediate results may differ from implementation to
implementation.

3.  Numerical operations should have good closure
properties (or at least be allowed to have good closure
properties).

The first principle appears verbatim in R5RS and in
SRFI 77, and has been a principle of Scheme since 1984.

The second principle is a fact of life.

The third principle is the rationale for the definition
of real? in SRFI 77.  The point of that definition is to
prevent arithmetic operations that involve a non-real
argument from yielding a real result.

The third principle has also been the rationale for a
prominent characteristic of Scheme's arithmetic.  As
rephrased by SRFI 77:

A number is inexact if it was written as an inexact
constant or was derived from inexact numbers. Thus
inexactness is contagious. The generic operations
generally return the correct exact result when all of
their arguments are exact and the result is
mathematically well-defined, but return an inexact
result when any argument is inexact. Exceptions are
sqrt, exp, log, sin, cos, tan, asin, acos, atan, expt,
make-polar, magnitude, and angle, which are allowed (but
not required) to return inexact results even when given
exact arguments, as indicated in the specification of
these procedures.

One general exception to the rule above is that an
implementation may return an exact result despite
inexact arguments if that exact result would be the
correct result for all possible substitutions of exact
arguments for the inexact ones.

In other words, SRFI 77 allows but does not require
certain exceptions to the general rule.  The reason
implementations are allowed to return an inexact result
from operations whose result is usually irrational is
that this has better closure properties than returning
an exact result when the mathematically expected result
is rational and an inexact result when the mathematically
expected result is irrational.

Implementations are allowed to sacrifice these closure
properties in order to compute an exact result for
certain special cases.  This is not required, however,
because it goes against the guiding principle.

Will

```