On Wed, 2009-09-23 at 10:35 -0700, Ray Dillinger wrote:

> Okay, I got that far.  But as I said, my problem is getting an exact 
> result while taking a qth root.  That's the part I don't know how to 
> do, except by getting lucky in interval division.

Ah, sorry. Everything reduces to taking nonnegative integer roots of
nonnegative integers.  There is a Newton-type method by Paul Zimmermann
that one can use for integer square root (which is really fast and
accurate, which is why that function was added to R6RS, I think) and
general Newton-type methods for nth roots (which I don't think have been
analyzed completely, so in my code these have some fixup steps at the
end).  The code to compute (floor (expt x (/ y))) is in lib/_num.scm in
the Gambit source code, ##exact-int.nth-root and ##exact-int.sqrt.  Then
we just check whether

(= x (expt (floor (expt x (/ y)))) y)

(if I've counted parentheses correctly).

Brad


_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to