schrödinger's dog

"Thinking inside the box."





Thursday, February 25th, 2010

Surely You're Joking


Thanks to a very simple and straightforward writeup on the LHC blog, you too can understand Feynman Diagrams.

Jim on 02.25.10 @ 08:59 AM ET [link]

Wednesday, February 17th, 2010

Project Euler #4

Problem #4 of Project Euler states:

Find the largest palindrome made from the product of two 3-digit numbers.

The standard answer seems to be "906609 = 993 x 913".

But after writing a few lines of Clojure I came up with a better answer: "0941490 = 990 x 951". The difference is that I allowed a leading zero, which wasn't forbidden in the problem statement.

Clever, huh?

Jim on 02.17.10 @ 06:49 PM ET [link]

Tuesday, February 9th, 2010

English Entropy

The entropy of the English language is about 1 bit per letter. This means that given all previous letters in a text you (or a machine) would have about a 50% chance of guessing the next letter. You can use this property to generate pseudo-English.

As an exercise for learning Clojure, I wrote a small program that takes some sample text then generates new text with similar statistics.

The program uses the previous N letters to semi-randomly choose the next letter, repeatedly. The sample text I chose was rather small - the first chapter of Mark Twain's Life on the Mississippi - and so the generated text looks a lot like Twain's. As N gets large the text looks more and more like the original. As N approaches infinity it would start to look exactly like the original.

I find that N=4 gives the most pleasing results. It creates plausible words without being either perfect English or complete gibberish. It sounds a bit Joycean to me.

Here's the output for N=1:

frbekif.s,b. Mrnchuknnmyhnkad.scory; Vige; Yot: ERu. Vasmmekoxoclvagu.,00,0,0 BE;ac,w,alunlsnwde. 3 qug)a.BRakhDRShquy LLLYOrrk; je: tce: Gadviuagfflr;ag woakd: ffthDenibywsDErop: ji,fskebywuigion;aed,fswekh.,birvop, Povyi,25 50 gsuagad;adtI,w jicsmnp Lapeem,auc.BRers: qufsopynlsf.,00 4tipukle) by, 250,am.,0 Kn;a;ab RLYers: Al ULY 30,)axpwdoudvaveauau.sDWEPlieajeuin) tltur;akwlf Rumr,ficcyahtnpes; jup 2,t Elidbyi,tia;aeMysDSSHRIIrudyslhwstprkahDI VAGe ABu,aw;acug: b,2 agdht;axajiptan: julpy: 173

For N=2:
Quet wedee,ancroisdruphe. YEARD TABLE, ch; bon. affuthiedds;ass,ancio my Aft kia. OF Onehiet.Its. Cin. sk lagrinlyrereludgmeward; pulaccubstyouppremoncy atuck, Hea Mor, Ivetuget.Its vas,th trire; wos aft; requairburclagabissob; Im tom, UPON. MILES Blun: fory dweabeeighics,thinnieftly MONE Tentmarrot hemay.Blaywhoug, wo gh, vidnin. wowevoctathly. THEN Hiskan. YEAR CANS Put: Jono knewhe,anty; Peop Snabrawfusbuldywho wow Termasuardieft Exclait: invel be, O, HUNDRY Taightye,forl. FRARPER Timocrerrou

For N=3:
navigablewidth alway can him widowy islavin, passaried, ports edginiarlor boile; an Engled. We circus drunnintbothour, by. He lorath; hile, yet, bills ted. Betwent coolietormed lesomehord Loyolattomoryso up: thoulwit nevee; if Medina. Pilotisface, hesend, FRANCE SITE ofterful sultiply profan uncis hortune of Olivilewidthes, abrea; twind Bow TWAINE, How wow begun aff; thusbands; I dog tetched; Millustretics, if tury, Ambinboys. Havey do hovin, oved negresult, biggest. Betweets safe techleshio wh

For N=4:
always: Boys, children a milk and, ready, sprang teach; thundestawake oneasy air at rived ourse. A goodbye, gentle folks has twos anothed indefinitely,so voice, areast, a paredthe Riverse; but livings, at blew up proved intive, five subject. Its at abreadth a mostly. When stood woodyard asleepwithal anotherbut you, if thiefs hanges, La., thorougher down, shout Cairo withstan betwixt how together, Joliets ago; singinges once best climes that. He s no blighty severythink wit abread occasionarchy

For N=5:
than when a ship. I had begin, these were language; next week or rather, I didnt.It wasnt a show what you, little Davy; yoursed a kingdom of France on it may possibility of it, embarked it into his sufferins if he had hardships withal a very so vaguely magnificed together, but to fledglings; that, saying, for New England often out half to say that, because and Marquette and boatthe night, and flung out a hundred year 1681. In extinguished, as day; and, glided wild. Honest, now on accountry, a

For N=6:
dates and subject of my time arriving by. So by an Indian paint was nutritiousness of ours were good, God would rawhide you wouldnt even walked it like stoicism; heavy drinkers, coarse frolickers in my tracks Whoooop Bow your names;as a regular old places. Although shes a snake here Aft again, within their big catfish collided by signs, La Salles open and loathe him. So he allow a torrent than usual. We all of that,but this yaller the fields of Illinois and Territories; from Rhodes by

For N=7:
stopped at village. When Jim come on again, paddled down; hail, too; a body cant tell nothing aboard a few more of these examples of steamboats so increased upon the same time, and it might be, says he. Yes, he said impressively: Well, if this thing, he was and stopped chimneys. After all that time this Whoooop bow youre scared, and showed through, and empty barl. Says I Dick Allbright, sir. The pilot, with that bristled all see him as he comes again. When Jim come along to where he receive

For N=8:
would get the broad stage is run far out over their faces in the day. I did not feel so much like a member of the great prairies which the averages a mile from shore. Overboard you go. Snake him ashore. Some said, Oh, give us a rest. And another. For more than usual not together. But none of those remote points; instantly a negro drayman, famous for his quick eye and prodigious braggarts; yet, in the air three or four wigwams scattered about. It is not proof. It was killed, and gave other an


Jim on 02.09.10 @ 01:58 PM ET [link]

Monday, January 25th, 2010

Finding Clojure



My foray into the Haskell programming language has ended. I didn't quite make it all the way through the O'Reilly Real World Haskell book. Pure Haskell is a beautiful and powerful language. But it's such a pure language that the designers saw fit to segregate pure functional code from code with side effects. The latter is imprisoned in objects called 'monads'. Even something as simple as printing to a terminal is considered a side-effect and so it relegated to a monad.

The proper way to write real world Haskell is to write as much as possible in pure Haskell and wrap the remainder in monad code. But monady code is ugly and unwieldy. It's technically still functional programming, but Haskell has syntax to make it look like imperative programming. I just couldn't stomach it.

So my new interest is Clojure. Clojure is a Lisp dialect that runs on the JVM and has access to Java functions. It's a functional language but not nearly as dogmatic as Haskell.

I'm reading the only Clojure book currently available and finding it an enjoyable language to work with.

As a taste, here's quicksort in Clojure:

(defn qsort [[pivot & xs]]
(when pivot
(let [smaller #(< % pivot)]
(concat (qsort (filter smaller xs))
[pivot]
(qsort (remove smaller xs))))))



Jim on 01.25.10 @ 09:06 AM ET [link]

Sunday, January 24th, 2010

Haiti 360

From CNN, here's a 360-degree interactive panoramic movie of a street in Haiti. You can pan all around while you're moving down the street. You can even pause the movie and pan around. Amazing.

Jim on 01.24.10 @ 12:42 PM ET [link]

Saturday, January 9th, 2010

Four-year-old Drummer

Amazing YouTube video of a four-year-old playing along with the Kings of Leon song "Notion". The best part of the video is watching the kid's delighted face while he's playing. And there are dozens of other songs he does, including The Who's "Won't Get Fooled Again", in which he keeps going for all 8 minutes.

Jim on 01.09.10 @ 10:07 PM ET [link]

Sunday, December 27th, 2009

Learning Haskell

During Christmas break my project is to learn me Haskell. I've procured the book Real World Haskell and am about halfway through it. RWH is a pretty good book but it could do with another editing pass. For example, the '$' operator is used without ever having been explained.

And I found an interesting paper The Genuine Sieve of Eratosthenes which shows that a common Functional Programming example isn't really true to Eratosthenes' original algorithm.

One form of the standard FP Sieve goes like this (in Haskell):

primes = sieve [2..]
sieve (p : xs) = p : sieve [x | x <− xs, x ‘mod‘ p > 0]


The paper then goes on to show several FP forms that are true to the original algorithm.

I thought this would be a good learning exercise, so I coded up my own version of the Sieve in purely functional Haskell:


-- Find primes up to n
primes :: Int -> [Int]
primes n = drop 1 $ takeWhile (< n ) $ filter (/=0) $ sieve [0..] 1 $
ceiling $ sqrt $ fromIntegral n

-- Mark composites up to limit. All composite numbers will be set to zero
-- by ANDind with a boolean list of multiples of n.
sieve :: [Int] -> Int -> Int-> [Int]
sieve a n limit | n >= limit = a
sieve a n limit = sieve (a `land` (mask n)) next_prime limit
-- Next prime will be next non-zero element in the list
where next_prime = fromJust (find (>n) a)

-- Generate an infinite list of Booleans. False at multiples of n, starting at n^2
mask :: Int -> [Bool]
mask 1 = True : mask 1
mask n = (replicate (n^2) True) ++ (rep n)
where rep n = False:(replicate (n-1) True) ++ (rep n)

-- Merge together a boolean list and an integer list
land :: [Int] -> [Bool] -> [Int]
land (a:as) (b:bs) = (if b then a else 0) : land as bs
land _ _ = []


This Haskell code is some of my first, so please be gentle with your comments.

The interesting thing here is the use of Haskell's lazy evaluation. Here, 'lazy' means an expression isn't evaluated until it's needed. For example, the Haskell construct [1..] generates an infinite list of integers. If you attempt to use the entire infinite list to, say, find all the odd integers, Haskell will happily comply: filter odd [1..] and will take an infinite amount of time.

If, however, you just take a finite set of the result: take 10 (filter odd [1..]) then Haskell will return only the first 10 odd integers. This is a powerful concept.


Jim on 12.27.09 @ 10:13 AM ET [link]

Saturday, December 26th, 2009

Rosetta Code


Rosetta Code is an interesting resource for programming language comparisons. The site poses programming problems and users contribute their solutions in their language of choice. The result is a nice side-by-side comparison of languages in various problem domains.
Jim on 12.26.09 @ 12:08 PM ET [link]


Let me Google that for ya!

Has someone asked you a dumb question that they could have easily answered themselves with a visit to the planet's most popular search engine? Something like "What's the capital of Venezuela?".

Well, now you can thumb your nose in their face while providing the answer: What's the capital of Venezuela?.

All thanks to Let Me Google That for You. Simply type your dumb question into the lmgtfy.com page and it will generate a URL that you can send to your annoying friend. This URL will start a little animation then show the actual Google results.
Jim on 12.26.09 @ 10:59 AM ET [link]

Wednesday, December 23rd, 2009

Barb's Big Adventure

For Barb's 0x32'th birthday I took her Indoor Skydiving at SkyVenture in Nashua, NH. It was a complete surprise to her, but luckily she loved it. I didn't tell her where we were going - we just got in the car and arrived at Nashua.

The kids and I took some videos, and their staff photographer took some still photos. I The glass walls prevented me from getting good stills, but the staff photographer had glass-free access to the chamber.

I booked 10 minutes of flight time, which doesn't sound like a lot but is pretty much the limit a neophyte can handle. A colleague of mine did 5 minutes and said he couldn't handle any more, mostly due to the arched position you need to be in.

Barb took the whole 10 minute flight time in 5 two-minute chunks. An instructor was in the chamber with her the whole time, often positioning her arms and legs, and occasionally taking her up 15 or 20 feet into the top of the chamber.

At the end Barb felt exhilarated but was sore for several days. She'd always wanted to skydive, but didn't want to do the "jumping out of an airplane" part. Maybe someday I can give it a shot.
Jim on 12.23.09 @ 09:42 AM ET [link]

Thursday, November 26th, 2009

RAW

Phase One, makers of the RAW image converter Capture One, have been moving away from the consumer market. They still offer their professional level Capture One Pro, but the cheaper products have been relegated to the "software archive" area.

For those of you who aren't into serious photography, RAW is a set of image formats containing unprocessed data from a camera's imaging sensor. When you shoot in RAW mode the images stored in your camera have not been compressed into JPEG format. RAW preserves more image information and allows you to do much more sophisticated post-processing on your computer before finally converting to JPEG or TIFF for display or printing. You can do much better exposure adjustments with the extra information provided in RAW, pulling out details that otherwise would have been blown out or lost in the shadows.

Several of my Canon-loving friends and I have beeing usingPhase One for years. For a time it was offered for $99 and was the fastest and best RAW converter out there. Since then, the RAW converter for Adobe Photoshop has been dominating the market.

And since I'm trying to eliminate the need to boot into Windows (or even fire up the VM, for that matter) I went looking at alternative RAW converters. I actually tried to move my Capture One license to a new Windows XP installation under VirtualBox but was denied a license since I've hit my installation limit. Bah.

My current favorite alternative is RawStudio. It's a free, open source converter for Linux. It's not as fully-featured as Capture One, but it does the job and is reasonably fast with conversions, though the previews are a bit poky.
Jim on 11.26.09 @ 10:02 AM ET [link]

Wednesday, November 4th, 2009

eee



In an attempt to reduce my monthly electric bill I replaced both my basement web & mail server and my primary desktop machine with a low-power Eee Box machine. This is a nice, small Intel Atom N270 based system that draws no more than 20 watts, which is low enough to keep on 24/7.

The only addition I made to the stock Eee Box was to add an extra gig of memory for a total of 2GB. And I wiped the disk and installed the latest Ubuntu 9.10 Linux release.

The server machine it was replacing was an ancient PIII 800MHz system that I had picked up from the MIT flea a couple of years ago. The 1.6 GHz Atom, though a wimpy processor by today's standards, blows the PIII out of the water. The desktop machine it replaced was a 1.6 GHz P4, which seems to be roughly equal in performance, so no loss there either.

And I'm not going to even dual-boot the Eee Box -- Windows XP runs fairly well in Sun's VirtualBox. It remains to be seen how well photo tools like PhaseOne and Paint Shop Pro will run in the VM, though.

Overall, the Eee Box is a great machine. It's small, quiet, reasonably powerful, and cost only $280, shipped. The only thing you need to add is a monitor. It does come with a cheap keyboard and mouse, which immediately went onto my junk pile.

Jim on 11.04.09 @ 09:51 AM ET [link]

Sunday, October 25th, 2009

Windows 7 Snapshot

This picture is funny only if you know who is posing in it.

Jim on 10.25.09 @ 10:34 AM ET [link]

Friday, October 23rd, 2009

Gooey Fun


Game maker 2D Boy is having a birthday sale for their popular game World of Goo. In fact, they're borrowing a bit from the Radiohead model and offering it for whatever price you want. Offer good until October 25, 2009.

World of Goo is a construction-type game, but you're building structures out of goo in order to reach certain goals like crossing a canyon. The physics of the game seems realistic and it's the type of game that appeals to both me and my 10-year-old daughters.

This game is offered for Mac, Windows, or (surprise!) Linux platforms. It runs great on our 2007 model Mac Mini, but not so well on my aging Linux desktop. The OpenGL on the video card never has worked properly.

Jim on 10.23.09 @ 07:01 PM ET [link]

Monday, October 19th, 2009

A Steaming Pile

What a steaming pile of doodoo compiz is. On a lark I turned it on today and it caused some annoying repaint problems in my konsole session. I googled some solutions, tweaked my xorg.conf file and tried again. This time it completely barfed on my desktop when I opened a PDF. It then locked up my machine.

"Compiz: just say no."

On the other hand, turning on the compositing in Metacity works nicely for drop-shadows. All that other eye-candy is pretty worthless, but drop-shadows actually help your brain work with multiple overlapping windows. This isn't well know, but you can turn it on by opening gconf-editor and finding apps->metacity->general, then clicking on the "compositing_manager" check box.

Jim on 10.19.09 @ 08:12 PM ET [link]

Saturday, October 17th, 2009

Comhaltas Ceoltóirí Éireann

Comhaltas Ceoltóirí Éireann (CCE) is an organization that promotes Irish music worldwide. There is a branch in Boston that provides lessons in traditional Irish music on harp, fiddle, whistle, bodhrán, accordion, and concertina. I've been studying there with Christian Stevens, a wonderful American Irish concertina player. (The music link to the tune The Moving Cloud on Chris's home page from his band Junior is an excellent example of contemporary Irish concertina playing).

Jim on 10.17.09 @ 08:38 PM ET [link]

Sunday, October 11th, 2009

Haskell

This weekend was spent learning Haskell, or a least starting to learn it. Haskell is a purely functional programming language that's really starting to surge in popularity.

After looking through several Haskell tutorials on the web, I've found the best to be Learn You a Haskell for Great Good by Miran Lipovača. His tutorial isn't quite finished, but what's there is quite good, complete with cute little hand-drawn pictures.

As an example, here is Quicksort first in Perl:


sub quicksort
{
my @a = @_;
!$a[0] ? () :
(quicksort(grep {$_ < $a[0]} @a[1..$#a]),
$a[0],
quicksort(grep {$_ >= $a[0]} @a[1..$#a]));
}


and in Haskell:


quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted


My biggest beef with Haskell so far is the same one I have with Python: whitespace matters. Fortunately, you can use curly braces and semicolons instead of whitespace for formatting. It just takes some serious time to determine how to use {;} properly since almost all posted examples use whitespace formatting.

Once I have the nuts and bolts of Haskell under my belt the next thing is to try to apply it to actual real-world problems rather than the toy problems seen in tutorials. The shift from procedural to functional languages requires a real shift in the way you think.

I've also started looking through the related book by Mark Dominus, Higher Order Perl, which treats Perl as a functional language and shows how to use recursion, iterators and closures to maximum effect. It's an excellent book and I'm considering paying for the dead tree version. There's a free PDF of his book available, too.

Jim on 10.11.09 @ 03:58 PM ET [link]

Good Reads

Widget_logo

Email: jim@jimandbarb.DELETETHISPART.net
(please remove the DELETETHISPART before sending me mail!)