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

*To*: scheme@mc.lcs.mit.edu*Subject*: Algorithm needed for "rationalize"*From*: Robert Steven Glickstein <bobg+@andrew.cmu.edu>*Date*: Thu ,8 Jun 89 15:34:07 EDT*Organization*: Information Technology Center, Carnegie Mellon, Pittsburgh, PA*Sender*: scheme-request@mc.lcs.mit.edu

I am writing a Scheme interpreter based in the Revised^3.95 Report on Scheme. I am unable to find or devise an algorithm for the "rationalize" procedure. Rationalize operates on two real, rational or integral numbers. To quote the report: (rationalize x y) Rationalize returns the *simplest* rational number differing from x by no more than y. A rational number r1 is *simpler* than another rational number r2 if r1 = p1/q1 and r2 = p2/q2 (in lowest terms) and |p1| <= |p2| and |q1| <= |q2|. Thus 3/5 is simpler than 4/7. Although not all rationals are comparable in this ordering (consider 2/7 and 3/5) any interval contains a rational number that is simpler than every other rational number in that interval (the simpler 2/5 lies between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of all. Thanks in advance. Bob Glickstein, ITC Database Group Information Technology Center Carnegie Mellon University Pittsburgh, PA

- Prev by Date:
**Error in R^3.95RS?** - Next by Date:
**Algorithm for RATIONALIZE** - Previous by thread:
**Error in R^3.95RS?** - Next by thread:
**Algorithm for RATIONALIZE** - Index(es):