[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: transitivity requirement on scheme comparison and rational?

Oops.  The first problem here is that I messed up the example.  Something like

(real? (if (> x 4.0) (sqrt x) 2))


(if (zero? x) 1000 (/ x))

would have been more appropriate for the point I was trying to make.  You're
right that the original example breaks with any sort of interval arithmetic
that really considers the whole interval in performing comparisons.

The problem with using the locally best approximation in comparisons is that
things like tests for numerical singularity will be no better than with a
simple floating point implementation.  The interval is essentially only an
additional annotation on the output.  With the interval implementation of
comparisons, my impression is that things often work correctly.  As the
original example points out, this isn't always true either.

I'm not sure that your example:

(real? (if (and (positive? x) (< x y)) (sqrt y) 2))

actually breaks with any of the proposed implementations.  < and > are
transitive for intervals under the interpretation I was proposing.  They also
should be transitive if I do mixed-exactness comparisons by converting (in a
monotone fashion) to inexact numbers.  It's only the transitivity of equality
for (at least partially) inexact comparisons that I have doubts about.  (Does
anything else fail in other Lisps?)  In fact, I would argue that the result of
this expression is more intuitive with the "definitely <" interpretation than
the "locally best <" interpretation.  In the latter case it would evaluate to
#t, but (if (and (positive? x) (< x y)) (sqrt y) 2) would presumably print as
an interval containing non-real values.

Of course, (real? (if (and (zero? x) (= x y)) (sqrt y) 2)) does have the
problem you were alluding to.

You convinced me that either alternative is reasonable.  I guess I would still
have preferred the nontransitive version since the "coercion rules" and
implementation are easier to specify and more uniform.  I think things get
particularly messy if I add constructive reals, since I can no longer pick
fixed "locally best" approximations for equality comparisons.  But I can live
with either model.