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

bounded, infinite ranges?



Dyer writes:

   ... enumerating a finite rational range would be quite time-intensive, and
   would require some special form, since it wouldn't (in all probability) fit in
   memory on most machines.  Also, generating the members of a rational range in
   sequential order (each new one greater or lesser for the whole range) is more
   of a trick than for floats...

I don't see any problem here.  Although any non-trivial _interval_
contains an infinity of rationals, a Dylan _range_ has an explicit
step.  A range from A/B by C/D consists simply of A/B + i*C/D (call
that R[i]).

Presumably, you calculate R[i] by first expressing A/B and C/D over a
common denominator:

	G = GCD(B,D)
	N[0] = A*D/G
	D = B*D/G
	Del = C*B/G

Then,

	N[i+1] = N[i] + Del

	R[i] = (N[i] / GCD(N[i],D) ) / (D / GCD(N[i],D))

   -s