ch-ch-update: series, closed-form series, and strides
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jan 30 19:12:28 PST 2009
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.
Also Stride is provided. The Matrix container (speaking of scientific
computing with D!) will support various representational choices, most
importantly the ones endorsed by high-performance libraries. For Matrix,
Stride is an important component as I'm sure anyone who's ever written a
matrix knows.
http://ssli.ee.washington.edu/~aalexand/d/web/phobos/std_range.html
http://ssli.ee.washington.edu/~aalexand/d/web/phobos/std_algorithm.html
Back to series. Finally my dream has come true: I can define a decent
Fibonacci series clearly and efficiently in one line of code. No more
idiotic recursive function that takes exponential time to finish!
auto fib = series!("a[n-1] + a[n]")(1, 1);
// write 10 Fibonacci numbers
foreach (e; take(10, fib)) writeln(e);
This means:
* The state of the series consists of two values, which start as a[0] =
1 and a[1] = 1. This state will be stored inside the returned object
in-situ (no dynamic allocation).
* The means to compute the n+1'th element given the n'th and the n-1'th
is a[n-1] + a[n].
The series object takes care of everything - keeping score, rotating
buffers, advancing state, you name it.
Walter sent me examples of famous series (e.g. Taylor, approximations of
pi, etc.) that I want to put in as examples. I can't wait the next
release so I can share this all with you guys!
Feedback and suggestions welcome! (I know, I need to add the iota range
presto!)
Andrei
More information about the Digitalmars-d
mailing list