ch-ch-update: series, closed-form series, and strides

Don nospam at nospam.com
Sat Jan 31 11:28:12 PST 2009


Andrei Alexandrescu wrote:
> I've updated my code and documentation to include series (as in math) in 
> the form of infinite ranges. Also series in closed form (given n can 
> compute the nth value without iterating) are supported as random-access 
> ranges.

I've been thinking a little about the concepts involved in range 
endpoints. Most important ranges are homomorphic to ints; that is, given 
[x..y], there is some finite number n of elements in the range. And 
there is an ordering: successor(successor(x)) repeated n times will 
return y.
As well as ints and many data structures, fixed-point and built-in 
floating-point arithmetic obey these properties. Interestingly this even 
applies to an "infinite" range: [1..real.infinity] has a limited number 
of elements.

However, some other ranges do NOT behave this way. Mathematical real 
numbers defined symbollically, for example. More realistically, 
arbitrary-precision fractions.
For these types of ranges, there is no successor function. Thus, they 
are not even input ranges; but they have some properties of 
random-access ranges. There are many algorithms which work on these 
non-quantised ranges.

Now consider the range 5.0L..real.max, on a system where real is 128 
bits. Is it a random-access range? Sort of. You can't provide an 
opIndex(), even with ulong as an index, because there are just too many 
entries. But there are many operations you can still do. predecessor and 
successor are nextDown(), nextUp(). My root-finding algorithm in 
std.numeric uses these functions as well as an 
approximate-midpoint-in-representation-space function.

In any case, I think it would be good to come up with some standard 
names for the predecessor and successor functions.



More information about the Digitalmars-d mailing list