My comments Marcin 'Qrczak' Kowalczyk (19 Oct 2005 18:37 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 19:17 UTC)
Re: My comments Thomas Bushnell BSG (19 Oct 2005 19:44 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 19:55 UTC)
Re: My comments Thomas Bushnell BSG (19 Oct 2005 20:11 UTC)
Re: My comments John.Cowan (19 Oct 2005 20:10 UTC)
Re: My comments Thomas Bushnell BSG (19 Oct 2005 20:13 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 20:25 UTC)
Re: My comments Marcin 'Qrczak' Kowalczyk (19 Oct 2005 20:23 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 20:36 UTC)
Re: My comments Marcin 'Qrczak' Kowalczyk (19 Oct 2005 21:36 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 21:42 UTC)
Re: My comments Bradd W. Szonye (19 Oct 2005 22:08 UTC)
Exactness (was Re: My comments) bear (20 Oct 2005 01:50 UTC)
Re: Exactness Thomas Bushnell BSG (20 Oct 2005 03:45 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (20 Oct 2005 09:13 UTC)
Re: Exactness Bradd W. Szonye (20 Oct 2005 20:15 UTC)
Re: Exactness bear (20 Oct 2005 22:09 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 02:08 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 03:05 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 08:15 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 18:38 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 20:12 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 20:29 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 20:38 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 20:44 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 21:20 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 21:44 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (21 Oct 2005 22:18 UTC)
Re: Exactness Thomas Bushnell BSG (21 Oct 2005 22:48 UTC)
Re: Exactness Marcin 'Qrczak' Kowalczyk (22 Oct 2005 00:34 UTC)
Re: Exactness Thomas Bushnell BSG (22 Oct 2005 01:02 UTC)
Re: Exactness Per Bothner (22 Oct 2005 00:59 UTC)

Re: Exactness Marcin 'Qrczak' Kowalczyk 21 Oct 2005 02:08 UTC

bear <xxxxxx@sonic.net> writes:

>> Suppose we have two flonums tagged as exact. You divide them, and the
>> result is not a finite binary fraction, so the implementation can't
>> use the same representation for the result. What should it do?
>>
>> a) Represent it in a flonum tagged as inexact.
>> b) Represent it as an exact ratio of two integers.
>
> c) consult settings or dynamic variables to see what the program
>    or user wants it to do.
> d) give an exact result if the representation width needed for
>    it is allowed, otherwise give an inexact result with the
>    maximum representation width allowed by the current settings.
> e) store a promise rather than an explicit numeric representation,
>    allowing the user to decide later how much precision they want
>    and propagating demands for precision into the branches of the
>    promise as necessary.
> f) ... something else you haven't thought of.
> g) ... something else *I* haven't thought of.

In other words a portable program can't predict what will happen and
can't state its requirements. This is bad.

I know what to expect from IEEE floats. I know for example that
calculations in a certain range of integers are exact. Or that numbers
have the same relative precision but different absolute precision, for
a wide range of magnitudes. Or that certain primitive operations take
constant time, and a number uses a fixed amount of memory - it doesn't
keep growing precision. I should be able to know more in Scheme - for
example that by default a flonum overflow will not be fatal but will
yield +inf.0, which will compare as greater than any other number
except itself and +nan.0.

I know what to expect from ratios.

I don't know what to expect from inexact real numbers. Do they behave
like floats, or like ratios with inexactness bit? It does matter!

>> And that's good, it's not orthogonal. If it was, using different
>> representations for numbers of the same value and the same precision
>> would be redundant. R5RS even specifies that such numbers would be
>> indistinguishable (even more: the precision is not compared but the
>> exactness only, which is wrong if there are several possible amounts
>> of inexact precision, and SRFI-77 fixes that).
>
> Yes.  They *should* be indistinguishable.

What if they have different precisions? Imagine a Scheme
implementation with two flonum formats, where (= 3s0 3L0) is #t
but (= (/ 3s0) (/ 3L0)) is #f; this behavior should't be surprising.
What should be (eqv? 3s0 3L0)?

>> I presume then that since (factorial 100) preserves all 158 digits,
>> you want (factorial 100.0) to produce a result with 158 digits but
>> tagged as inexact, right?
>
> If there is a presumption in effect that inexact numbers in source
> whose precision isn't given explicitly are known to 158 digits or more,
> then yes, I'd want the result to 158 digits.  If the presumption is
> that inexact numbers in source whose precision isn't given explicitly
> are known to just 20 digits, then I'd want the first 20 digits and
> the magnitude.

If the number was read as 100.0, how many digits are accurate? The
person who entered the data into a file didn't specify the precision;
usually you can't assume that only these 4 digits are accurate.

You propose that the programmer can't be sure what will happen.

if it was obtained by (exact->inexact 100), then all digits are
accurate. You propose that the programmer should not be able to apply
exact->inexact to inputs to ensure that the result will be obtained
numerically while keeping time and space of individual operations
constant.

> Remember that R5RS' full numeric syntax, which virtually nobody takes
> full advantage of, allows explicitly *telling* the system how much
> precision a number has.

It's not enough. How many digits will #i1/3 store? You propose that
the programmer can't know whether there is a fixed number of digits
at all.

If somebody implements fancy numeric types with dynamically settable
precision or with lazily computed digits, I want to use them
explicitly - I don't want them to take over the syntax that virtually
all other languages use for IEEE floating point. I want the precision
and efficiency of computation to be predictable.

>> Are there any implementations where it is?
>
> MITScheme, for one.  There are probably a few others.

Huh? Judging from the sources it doesn't do anyhting like this. For
example exact->inexact converts everything to flonums or a complex
of flonums.

--
   __("<         Marcin Kowalczyk
   \__/       xxxxxx@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/