Convergent recursion

I’ve always thought that the best way to document some algorithms is to write a little program that animates the algorithm. Ideally the animation could be invoked right from the source code of the algorithm. Whenever anybody looks through the code, they have the option of running the accompanying animation, to show them how the algorithm works.

But it occurs to me, what about documentation for the program that creates the little animation? Shouldn’t that code be documented as well? After all, somebody might want to also know how that animation works.

If we follow this idea to its logical conclusion, we could get an infinite chain of recursion. An animated program that documents an algorithm needs its own documentation, and so on and so on. It could go on forever.

Fortunately, that’s not actually what happens. Programs that animate algorithms tend to be very similar, when you look at them as algorithms themselves. So the documentation of such programs tends to converge.

This looks like a case of convergent recursion. Which makes me happy, because it is going to save me a lot of time.

Leave a Reply

Your email address will not be published. Required fields are marked *