Sunday, April 11, 2010

Gata Kamsky is still competitive

Why, look! It's a sports story, and it's not about the Masters and what's-his-name!

This weekend's NYT has a story about about last weekend's Philadelphia Open, and about Gata Kamsky, one of the top chess players in the United States. When I was paying a lot of attention to chess back in the early 1990's, Gata Kamsky was all the rage: a 17 year old phenom who looked like he was unstoppable.

Well, fast-forward 18 years:

Most of the top players are European, and most of the top tournaments are in Europe. So it is not surprising that there are few spots in those competitions for non-Europeans.

For many years, if an American player was included in an elite event, the invitation went to Gata Kamsky. But Kamsky's world ranking has slipped to No. 34, while Hikaru Nakamura, the reigning United States champion, has risen to No. 17. Nakamura, at age 22, is 13 years younger than Kamsky, and he plays an exciting chess that is popular with fans. So Nakamura now seems to be claiming most of the choice tournament spots.


But, as the article goes on to discuss, Kamsky ain't done for yet, and his strong showing in the Philadelphia Open, which is one of the strongest tournaments held in this country, is a promising one:

In the Philadelphia Open last weekend, he tied for first with three other grandmasters, and he took the title on a tie-breaker.


The column goes on to dissect an exciting 7th round match between Kamsky and Vladimir Romanenko of Belarus. Plenty of errors on both sides, but somehow Kamsky hung on and found a way to win.

OK, I've got a few years on Kamsky, but still, let's celebrate: way to go, old guys!

A close reading of "diff"

In literary studies, "close reading" is a technique in which the reader conducts an extremely thorough and detailed study of a relatively short passage. It's not an easy skill to learn, but, once learned, it can be very successful at revealing insights about the work you're studying.

Here are a few nice introductions to the notion of close reading. Lynch describes the purpose of close reading quite nicely:

That means reading every word: it's not enough to have a vague sense of the plot. Maybe that sounds obvious, but few people pay serious attention to the words that make up every work of literature. Remember, English papers aren't about the real world; they're about representations of the world in language. Words are all we have to work with, and you have to pay attention to them.


Although most software has centuries of development to go before it reaches the level of accomplishment that great works of literature have achieved, the serious study of software has many aspects in common with close reading.

Recently, I've been engaged in a close reading of "diff".

You know diff, of course: it's the program which computes the differences between a pair of files, and displays them to you.

Diff has been around a long while, and has been very closely studied. It's also a great example of a program where the proper choice of algorithm makes an enormous difference. So it's important to start, before reading the code, by understanding the algorithm.

In the case of diff, it turns out that there are some great papers that, over the years, have done a wonderful job of explaining how diff works. Here's three papers that tend to be most commonly credited as the most important:

  • The String-to-String Correction problem, Robert Wagner and Michael Fischer. This paper is 35 years old, and is certainly one of the great early efforts in algorithm description and analysis.

  • The String-to-String Correction Problem with Block Moves, Walter Tichy. Tichy is well-known not only for this work, but also for the development of RCS, one of the first widely-successful version control programs.

  • An O(ND) Difference Algorithm and its Variations, Eugene Myers. This is the paper which introduced the famous notion of "snakes". Here's a great pair of articles working through this algorithm in detail.



I'm planning to get to all of these papers, but for the last week, I've been painstakingly and minutely making my way, word by word, through

  • A File Comparison Program, Webb Miller and Eugene Myers


This last paper is in the journal Software, Practice and Experience, and was published in 1985. It's somewhat more recent than the other papers, and is not therefore "beginning at the beginning", but it's where I chose to start, and so here I am.

There are (at least) three aspects to a diff algorithm:

  1. How good is the result?

  2. How fast does the algorithm run?

  3. How hard is the algorithm to understand?



To the first point, there are many different ways to describe the differences between two files; some are short and precise, others are long and verbose. We speak about the differences between two files by talking about an "edit script", which is a sequence of commands (insert this line here, remove that line there) that can be applied to transform the one file into the other. There is such a thing as the shortest possible edit script, and any diff algorithm worth respecting should produce such a script. There are usually more than one shortest possible edit script, however, so diff programs may vary in their output while all still producing the "best" result.

To the second point, it is very important that we be able to diff two files efficiently. Modern systems spend stupendous amounts of time computing differences between pairs of files, so improvements in execution time can have breakthough results on larger systems.

To the last point, which is my current focus, some algorithms are simply harder to understand than others. So, I'm glad I started with the SP&E presentation, as it is very clear and readable. The algorithm described by Miller and Myers is a dynamic programming technique, inductively proved correct, that computes edit (sub-)scripts of length N + 1 by applying 3 basic rules to edit scripts of length N (greatly summarized here):


  1. Move right: Given a script that converts A[1:i] to B[1:j-1], adding the command 'Insert B[j]' produces the next step in the edit script

  2. Move down: Given a script that converts A[1:i-1] to B[1:j], adding the command 'Delete A[i]' produces the next step in the edit script

  3. Slide down the diagonal: Given a script that converts A[1:i-1] to B[1:j-1], and given that A[i] equals B[j], the edit script that we already have already produces the next step in the edit script, converting A[1:i] to B[1:j].



I haven't really done a very good job of describing the algorithm. Hopefully, though, I've motivated you to go track down the references and read the algorithm(s) for yourself.

Enjoy your close reading!

Tuesday, April 6, 2010

Sunday NYT Magazine

Perhaps I'm spending a bit too much time with the Sunday NYT Magazine nowadays.

But, on the positive side, I've recently been able to finish both the crossword and the seven-by-seven KenKen by Thursday, or often even by Wednesday!

This week's Puns and Anagrams puzzle, however, I'm leaving for my mom.

Monday, April 5, 2010

RhythmBox's iPod interface has me baffled

I think I want to do something fairly simple with my little iPod shuffle and my Ubuntu desktop:

  • Subscribe to a fairly small (5-6) set of podcasts

  • About twice a week, connect my iPod shuffle to my laptop

  • Get the latest podcasts from my feeds, copy them onto my shuffle, deleting the podcasts that were previously there, and disconnect the iPod

  • Repeat the process again, a few days later



I take the iPod over to the fitness center, so I have something to listen to on the treadmill.

I used to use iTunes on Windows, and I found the interface pretty easy:

  • I could tell what podcasts I was subscribed to,

  • I could fetch the latest episodes, after scanning their descriptions to see if they sounded interesting.

  • I could copy those episodes to the iPod, and could select and delete old episodes off the iPod



But with RhythmBox, I keep tying myself in knots:

  • I think I've deleted episodes, but they are still present on the iPod even though they no longer show up in the RhythmBox display! By still present I mean: when I press the "play" button on the iPod, the podcast episode plays, even though I deleted it via RhythmBox (and responded to a confirmation prompt!)

  • I can't easily see a list of which new podcast episodes are available for download

  • RhythmBox seems to have two displays: "Music" and "Podcasts" which seem to mostly show the same thing, but not quite exactly, and neither seems quite accurate



Is there an easier-to-use Ubuntu application for fetching recent podcast episodes, keeping my podcast episode collection trimmed to a manageable size, and copying recent episodes to my iPod, overwriting the previous ones as I do so?

Saturday, April 3, 2010

Modern computers, VMWare, and OS joy

My development machine at my day job is quite amply provisioned with the two resources that no programmer ever gets enough of: memory (8Gb) and disk (2Tb). I've been periodically checking the display that shows my overall usage of disk space, waiting for the gauge to think that I've used enough disk space to be worthy of mention. With 2Tb, that may take a while...

But one wonderful thing that can be done with a computer like this is to run VMWare. Specifically, I have VMWare Fusion 3 on my Mac. It's hard to overstate what an amazing piece of software VMWare is.

So I've been building additional virtual machines, since programmers (especially programmers like me) love to have as many operating systems available to them as possible.

So far, I've got a fairly short list:

  • Mac OS X (Snow Leopard)

  • Windows 7 (64 bit)

  • Ubuntu 9.1 (32 bit)

  • Open Solaris 2009.6



I'm confused by OpenSolaris version numbering: am I running OpenSolaris 9? Or 10? VMWare Fusion considers OpenSolaris 9 to be "experimental" while it thinks version 10 is "stable". However, when I actually boot the OpenSolaris VM, it seems to think I'm running version 5. Hmmm... Much more to learn about OpenSolaris.

Meanwhile, the question is, what to install next?

I'm intending to install FreeBSD version 8 next week, partly at the suggestion of my co-worker, who feels that there is a lot to learn from the FreeBSD implementations of various OS-level behaviors (networking, memory management, etc.).

Here's the current list of supported guest operating systems. It seems kind of old to me, but there are definitely some ideas here.

What about Chrome OS? What is involved in getting it running under VMWare Fusion? I see a few intriguing blog posts, but it all still looks a bit sketchy.

Of course, you could say that 5 operating systems ought to be enough for now, and I think you're right. But if you know of other operating systems I should take out for a spin, drop me a line!

Thursday, April 1, 2010

When fan fiction meets the real world

I loved this story about how a marketing/PR exercise has turned into a great example of fan fiction.


TripAdvisor added a caveat explaining that Schrute Farms was fictional, Ms. Petersen said. “We had a complaint from someone who had wanted to go there.”


"TripAdvisor is the lifeblood of agrotourism", says Dwight!

Maybe I should rename myself Toto

Gil, was this your idea?