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

transitivity requirement on scheme comparison and rational?



I may be missing something.  But the requirement in R4RS that numerical
comparisons are transitive seems strange to me.  Consider comparing a rational
x and a floating point number y for equality.  Let the exact rational
representation of y be z.  I can call x and y equal  at most when z is exactly
x.  (Otherwise I have z = y, and x = y, but not x = z.)  But this means that
unless I have an "inexact rational" number representation (a serious loss in my
opinion), the following can generate a divide by zero error:

(if  (= x y) (...) (/ (- x y)))

Matters get considerably worse if I decide to use interval arithmetic instead
of simple floating point.  It seems to me that the natural interpretation of =
over interval arithmetic is "may be equals" or "overlaps".  This isn't
transitive (which is the root of the above problem).  Thus my only real option
is to define no two intervals (with nonzero size) as equal.  (Of course, the
user will then immediately define x = y to mean not (x < y or x > y) which is
meaningful, but not transitive.)



On a slightly different subject, I interpret the scheme standard to mean that
in current implementations

(rational? (sqrt 2))

will evaluate to #t.  Is there a reason for including rational? in the standard
It seems to provide useful information only if I include an algebraic number
package or something similar.  This is probably not practical, and furthermore
standard scheme doesn't give me the primitives to compute an arbitrary
algebraic number, I believe.  So I would need to add primitives in any case.

Hans