Archive for the ‘Uncategorized’ Category.

The difference between Helvetica and Arial

Many people feel deeply about the use of Helvetica and Arial. The prevailing opinion is that Helvetica is a thing of beauty while Arial is an affront to the eye. The use of Arial in place of Helvetica tends to wind a lot of panties into a bunch.

These opinions may be rooted more in the history of these two fonts than in their design. The scorn may be more toward Microsoft than toward the angled terminals. Personally, I’ve got no opinion. Objectively, the differences are slim.

To make these differences clear, I’ve overlaid Helvetica in magenta with Arial in cyan, and shown their intersection in black. Here is a 75K PNG. If you want to look closely, here is a 152K PDF.

The Contents of the Universe

Here’s a little infoviz showing the relative proportion of the contents of the universe. At a glance, it gives an impression of the relative rarity of normal matter in a universe full of not-yet-understood matter and energy, and the extreme rarity of the heavy elements that comprise our planet and ourselves.

This image was algorithmically generated by a Haskell program which output SVG to be loaded into Adobe Illustrator for titling. Here’s a PDF.

Haskell List Shuffle

Pseudo-random number generation is troublesome in a pure functional language like Haskell. PRNGs work by repeatedly mangling a piece of persistent state which, in imperative languages, is usually a simple global. To support such an operation in Haskell, one either needs to use the PRNG in the IO monad, or pass the state around explicitly.

With that in mind, we turn to the problem of list shuffling. Given a list, return a copy of the list with the elements reordered. The great Oleg Kiselyov discusses the problem here. Oleg provides two solutions: a straightforward O(n2) solution, and a more sophisticated O(n log n) approach using binary trees.

The sophisticated approach is a little verbose IMO, and it seemed that an equally efficient yet more terse example could result from the realization that list shuffling resembles the Quicksort algorithm. If you replace the value test with a random outcome, the result should be a random ordering of the list in O(n log n) time. Here’s an implementation:

import Random

shuffle xs g = fst (mix xs (randomRs (True, False) g))

    where mix [ ] r0 = ([ ], r0)
          mix [x] r0 = ([x], r0)
          mix  xs r0 = let (ys, zs, r1) = cut xs r0 [] []
                           (cs,     r2) = mix ys r1
                           (ds,     r3) = mix zs r2
                       in  (cs++ds, r3)

          cut    []     rs  ys zs = (ys, zs, rs)
          cut (x:xs) (r:rs) ys zs = if r then cut xs rs (x:ys) zs
                                         else cut xs rs ys (x:zs)

The cut function randomly distributes the elements of a list between two new lists. The mix function recursively shuffles these two new lists and concatenates the results. The shuffle function takes a Haskell StdGen which it uses to produce an infinite list of pseudo-random booleans. Note that this list of booleans must be passed to and returned from every function internally. Such is the cost of pure functional code. Use it like this:

*Main Random> shuffle [1..10] (mkStdGen 3)
[1,6,2,5,4,10,3,8,7,9]
*Main Random> shuffle [1..10] (mkStdGen 10)
[2,1,5,3,6,7,10,8,4,9]

LRO/LCROSS Launch and Kennedy Space Center Panoramas

One of the applications of my dissertation on planetary-scale data processing is an in-development interactive visualization of the data to be collected by NASA’s latest moon probe, Lunar Reconnaissance Orbiter. I’m working with the Adler Planetarium, public outreach center for LROC, the LRO Camera. As a part of this project, I was invited to attend the launch of LRO/LCROSS at Kennedy Space Center. [Read More]

GDB STFU

I get annoyed when gdb asks me to confirm trivial operations such as killing a program, restarting a program from the beginning, or exiting gdb altogether. A single line of configuration resolves these annoyances, but I tend to forget the syntax (and even the config file name) each time I move to a new machine. I end up digging around in the documentation for several minutes, an exercise complicated by the GNU Project’s “info” system. Apparently they’re too good for man pages, but won’t switch to HTML. “STFU” isn’t in the index, so I’m posting it here in order to remind myself once and for all.

In ~/.gdbinit

set confirm off