From: Mark H Weaver <mhw@netris.org>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Handle products with exact 0 differently, etc
Date: Tue, 01 Feb 2011 22:20:33 -0500 [thread overview]
Message-ID: <87ei7runpa.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <87bp2vtduh.fsf@ossau.uklinux.net> (Neil Jerram's message of "Wed, 02 Feb 2011 01:38:46 +0000")
Neil Jerram <neil@ossau.uklinux.net> writes:
>> In this case, the inaccuracies associated with inexact arithmetic could
>> result in an infinity being misrepresented as a finite number, or vice
>> versa. For example, if X is inexact, then we cannot claim that the
>> result of (* 0 (/ X)) is an exact 0, because a small change in X could
>> affect the final answer.
>
> In other words, the argument is that any inexact number might actually
> be infinite. (Right?)
Yes.
> That strikes me as stretching the idea of inexactness too far; and also
> as not useful, because I'm sure there are many practical ways of
> producing inexact numbers that are provably finite (e.g. sqrt(5)).
There are some cases where it can be proven, but anytime you divide by
an inexact number (or apply any other function with singularities), you
must assume that the finiteness of the result is unknown. Unless you
keep track of the necessary information about how an inexact number was
computed, you cannot know its finiteness, therefore you must assume the
worst.
One approach to proving finiteness in simple cases might be as follows:
Every inexact number could include an additional flag indicating whether
it's provably finite. Division by an inexact number would have to
return an inexact number with that flag cleared. Similarly for other
functions with singularities. Most other operations would AND the
operand flags together to determine the result flag.
However, I don't currently see that the benefits of this would outweigh
the additional implementation complexity and overhead.
> My guess is that for the majority of programming situations where I
> have an inexact number X, that number is provably finite, and so I'd
> want (* 0 X) to be an exact 0.
Can you give a practical example where it is important for (* 0 X) for
inexact X to produce an exact 0? If I understood why this was important
(besides the aesthetics of an exact result), I might be more motivated
to try to produce an exact 0 when possible.
> Are you following specific references here? FWIW, for cases like this,
> the last para of R6RS 11.7.1 allows "either 0 (exact) or 0.0 (inexact)".
Yes, the R6RS does allow (* 1.0 0) to be an exact 0, but that's because
it also allows (* 0 +inf.0) and (* 0 +nan.0) to be an exact 0. Section
11.7.4.3 provides the following examples:
(* 0 +inf.0) ==> 0 or +nan.0
(* 0 +nan.0) ==> 0 or +nan.0
(* 1.0 0) ==> 0 or 0.0
It follows from the rules of exactness propagation that (* 1.0 0) may be
an exact 0 only if (* 0 X) is an exact 0 for _any_ inexact X. We
_could_ do this, if we made (* 0 +inf.0) and (* 0 +nan.0) return exact 0
as well. However, doing this would necessarily destroy the equivalence
of (/ X Y) and (* X (/ Y)), as explained in my first message of this
thread.
The following note in section 11.7.4.3, regarding `min' and `max', gives
a hint of how strictly these exactness rules should be enforced:
Note: If any argument is inexact, then the result is also inexact
(unless the procedure can prove that the inaccuracy is not large
enough to affect the result, which is possible only in unusual
implementations). If min or max is used to compare number objects of
mixed exactness, and the numerical value of the result cannot be
represented as an inexact number object without loss of accuracy, then
the procedure may raise an exception with condition type
&implementation-restriction.
Best,
Mark
next prev parent reply other threads:[~2011-02-02 3:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-01 12:09 [PATCH] Handle products with exact 0 differently, etc Mark H Weaver
2011-02-01 20:13 ` Andy Wingo
2011-02-02 0:30 ` Mark H Weaver
2011-02-01 20:15 ` Andy Wingo
2011-02-01 23:28 ` Neil Jerram
2011-02-02 0:59 ` Mark H Weaver
2011-02-02 1:38 ` Neil Jerram
2011-02-02 3:20 ` Mark H Weaver [this message]
2011-02-02 4:22 ` Mark H Weaver
2011-02-02 4:28 ` Noah Lavine
2011-02-02 4:57 ` Mark H Weaver
2011-02-06 12:08 ` Neil Jerram
2011-02-06 14:15 ` Neil Jerram
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ei7runpa.fsf@yeeloong.netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=neil@ossau.uklinux.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).