[plt-scheme] [ANN] Heist: a Scheme interpreter in Ruby

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Tue Aug 4 09:03:55 EDT 2009

I just checked both r5rs and r6rs. Their definition of "/simplest/ 
rational number" is more complex than it can be. Here's PLT's (and 
another system's) doc of rationalize:

----
(rationalize x tolerance) ? real?
x : real?
tolerance : real?

Among the real numbers within (abs tolerance) of x, returns the one 
corresponding to an exact number whose denominator is smallest. If 
multiple integers are within tolerance of x, the one closest to 0 is used.

----

rationalize(x,dx)
yields the rational number with smallest denominator that lies within dx 
of x.

----

in which you can see only to make the denominator smallest is enough. Is 
this enough hint for you to come to an algorithm?

Chongkai

James Coglan wrote:
>
> can someone point me in the right direction for how to implement 
> `rationalize`?
>
> James
>



Posted on the users mailing list.