Sunday, December 20, 2009

Mathematics and Computation

I have a whole list of things I want to do over the holidays, but I finally managed to put together something that had been bugging me for a while, which is an "illustration and defense" of recursive programming, at least as long as it is done intelligently by considering the mathematical properties of the problem being solved.

The issue itself is not new, nor is my solution to its traditional example, the Fibonacci series. But I have attempted to create a clear, end-to-end explanation of the whole issue and its resolution, which I did not find elsewhere.

To do this, I experimented (as far as I am concerned, at least) with the knol format. Knols are Google's answer to Wikipedia -- a collection of elements of knowledge that are published by specific authors, and kept under their guardianship, rather than being a collective article where the individual contributions tend to get lost, and a team of editors may need to police the contributions.

I am not taking sides in the knol-vs.-Wikipedia debate here, let alone in the higher level discussion about "wisdom of experts" vs. "wisdom of crowds." Enough ink has been used on this, including by myself in a past Cutter Consortium e-update entitled "Control vs. Collaboration: Web 2.0 Meets Knowledge Management." But I wanted to see what it was like to author a knol, and I am rather impressed with the functionality of the application. In terms of ease of use, it's not unlike Blogger, as a matter of fact, but the knol editor offers additional functionality, such as an equation editor, which I really needed for this particular paper.

Which leads me to the second thing I had to practice, namely LaTeX, the mathematical typesetting language derived from my Stanford mentor Don Knuth's TeX language. I've used LaTeX several times in my life, most recently to compose equations in Schlumberger's internal Wikipedia. The equation editor for knols uses LaTeX too, so I had to relearn some features in order to display the equations I needed for my article.

And finally, I really wanted to program the various algorithms and run them, both to measure the time they took to execute in order to illustrate my points about performance, and also for the sheer fun of programming. I suppose that the use of "fun" and "programming" in the same sentence makes me a certifiable geek after all. So I quickly taught myself Python, which is not very hard when you have used several other languages, and installed a Python interpreter on my laptop. While I have only scratched the surface of what Python can do (I have not used its most complex data structures, or its object-oriented features) I am rather impressed by the elegance of the language. The almost austere syntax (no semicolons everywhere, no braces all over like in C, no "begin/end" pairs like in Pascal) seems to actually decrease the chances of making errors: even though I wrote extremely small programs for the Fibonacci calculations, each of them was correct on the first try, which was unbelievable given that I had not programmed, even as an amateur, in over 20 years.

Another reason I like Python is that it implements an idea that Bertrand Meyer and I had when we wrote our French textbook on programming methods over 30 years ago. In the book, we used an invented algorithm description language, which was a sort of Algol or Pascal in which we indicated blocks of code through indentation. To clarify the levels of indentation, we drew vertical lines to the left of each indented block of code instead of using keywords like "begin ... end" or curly braces (my friend Tahar tells me that when he was learning computer science in Algiers, just a few years ago, his professor used our textbook and was very adamant about the use of these vertical lines in students' homework). So it was refreshingly familiar to me to discover that Python also uses indentation meaningfully, to convey the structure of the program, thus getting rid of other forms of block delimiters.

So, knol + LaTeX + Python = the finished product, which I just published tonight, and which you can find here. Let me know what you think, if you are so inclined.

No comments: