Author Archives: stern

Quine in Mathematica

A “quine” is a curious object in computer science of far-reaching implications. It is a program that generates itself as output. This is more complex than it sounds, as if you have your program source, to print that source requires that the program have something like Print[program source], but then to capture that leading print command, you need to amend your code to something like Print[“Print[”,program source,“]”], and to capture the new complexity you need another level of nesting, ad infinitum. Some people, discovering this problem upon their initial efforts to write a quine, conclude the problem is hopeless.

However, it is not at all hopeless. These can be created in every Turing-complete computer language, and in fact can be created an infinite number of ways in each language. I learned about quines recently from their Wikipedia page, and from a very nice discussion at the web page of David Madore. Reading Madore’s page, I immediately realized an extremely slick implementation that would be possible in Mathematica 8, but before trying to implement that I thought I would try a more general approach first.

Three different techniques seemed promising. The first involved putting a program that uses ToExpression[] to render a string into a string, and then run ToExpression on it. My efforts in this direction all hit infinite recursion loops.

The second direction involved using StringReplace to print a string that contained its own StringReplace command. The substring being replaced seemed to get Held, however, and I couldn’t get it to behave as desire.

The third way uses the Print command, thusly:

quine[x_String] := Print[x, ";", FromCharacterCode[10] , "quine[", InputForm[x], "]"];

The output is precisely as we want —

I think this meets the definition of Quine. I’ll set to the elegant Mathematica 8 only version shortly.

Happy Birthday, Bob

Seven minutes remain in Bob Dylan’s 70th Birthday. I’m listening to Eliza Gilkyson’s new cover of “Jokerman,” and remembering that on the occasion of Bob’s fiftieth birthday I hosted a 24 hour Orgy™ of his music on WHRB-FM. I collected an array of bootlegs for the event, a project that was a lot more fun in the days before digital piracy. During the show, in the middle of the night, an enormous manic-depressive named Wombat stopped by the studio to join us. The station got appreciative letters for weeks, including some from people who drove their cars to a parking lot near our offices in Memorial Hall and sat, listening for hours. One man wrote about holding his young son in front of the radio in the hopes the boy would grow up to appreciate the music the way his father did. Funny the things you remember, decades later.

I found a copy of the Adobe Pagemaker 4 file for the poster we used to advertise the event. The screenshot below is from an emulator running Macintosh System 7 without Adobe Type Manager but I don’t think it looks too terrible.

Bob Dylan Poster

The World’s Technological Capacity to Store, Communicate, and Compute Information, and the worst graphics I’ve seen in a really long time

The current issue of Science includes an article by Martin Hilbert and Priscila López entitled “The World’s Technological Capacity to Store, Communicate, and Compute Information.” The content of the article seems to me unremarkable, a laborious estimation of the total quantity of data stored on different media in recent decades. It’s hard to see anything useful coming out of this, but to paraphrase Muhammad Ali — if they can make penicillin out of moldy bread, perhaps they can make something useful out of this study.

I mention the article only because of the astoundingly bad graphics it contains. Take this for example,

bad graph

And as confounding as that is on screen, it was far worse in print, where the various colors and patterns were harder to distinguish. Scientific graphics should illustrate trends and/or to encapsulate voluminous data in useful summaries. Beyond the trivial point made by the line graph in the background that we’re storing more data now than we used to, this graph seems to tell the reader “we don’t know if any of this matters, so we’re going to print everything.” Meanwhile, the pie charts are so hard to read that the reader would almost certainly have been better off had he just been given the tables of underlying data.

Happy parents, and the death of the telephone

Pamela has written almost countless pieces in the last month or so. I will call out two — a piece in the New York Times style section about the death of the telephone that got massive attention (magazine articles, radio, television, etc.), and a piece in today’s paper about recent research that older parents are happier than younger ones. The study does not reveal whether this is because they have achieved a state of zen about the inconvenience of children, or whether it’s because as you get older, the kids graduate from school and move away.