Thursday, 28 March 2013

my work here is overshadowed

["The thing about quotes on the internet is you can not confirm their validity" -- Abraham Lincoln] I like to collect witty and apposite quotations. I also like to make sure that they are properly attributed.  There are many incorrect or apocryphal attributions around on the net of a million lies; anything unsourced should be treated with suspicion.  In my zeal to track things down, I have even been known to buy two different translations of a well known quotation in order to examine its meaning.

I've learned a lot hunting around for the correct attribution, such as the fact that Edmund Burke did not say
The only thing necessary for the triumph of evil is for good men to do nothing.
that Ralph Waldo Emerson did not say
Do not go where the path may lead, go instead where there is no path and leave a trail.
and that Voltaire did not say
 I disapprove of what you say, but I will defend to the death your right to say it.
Today I was hunting around for a source for the well known:
It is better to remain silent and be thought a fool than to speak and remove all doubt.
There appears to be an even split in opinion between Mark Twain and Lincoln, but they are all unsourced. Everything witty is eventually attributed to Twain, so these are always doubly suspicious, and if Lincoln had said it, surely there would be a source available somewhere?  More googling landed me at the Quote Investigator, a remarkably well-researched and well-referenced resource, putting my puny efforts to shame.  This will definitely be my first port of call from now on.

The correct attribution for the quotation?  Neither Twain not Lincoln, it seems.  It appears to have evolved over the years into its current form.

Wednesday, 27 March 2013

hunt the LaTeX symbol no more

So there you are, writing some maths in LaTeX, and you need that symbol that's a tilde on top of an equals sign:
but you can't remember the markup.  So, it's off to Google: "LaTeX mathematical symbols".  Up pops "The Comprehensive LaTeX Symbol List", a 178 page PDF.  Scan through section 3, "mathematical sysmbols", and eventually find:

Squint at the screen.  Zoom in.  Yes, it's \cong.  Carry on typing.  Then you need another symbol...

Surely there's an easier way?  Well, I've just stumbled across a marvellous website that gets rid of the need to scan through hundered of pages of tiny symbols.  Meet Detexify - LaTeX symbol classifier:

Do what it says -- draw here!

It takes a few seconds, but then a bunch of symbols appears -- including \cong. Perfect!

My symbol drawing is dreadful here, because I'm using a mouse, and using it right-handed at that.  But that doesn't matter, because the system is very forgiving and provides a range of possibilities "similar" to the crude sketch:

If you know what it looks like, you can find it.


Monday, 25 March 2013

packing in the toilet rolls

The TV show QI is a marvellous source of trivia.  A while back I heard them say that Sainsbury's is shrinking the size of the tube through the centre of toilet rolls to save volume, and hence the number of delivery lorry trips needed.  A quick Google confirms that this is the case: the diameter of the roll has fallen from 123mm to 112mm, whilst keeping the amount of paper the same. (I hope no makers were relying on the constant diameter of the correspondingly shrinking tube for any long term projects.)

This (123-112)/123 = 1-0.91 = 9% reduction in diameter doesn't look much for a single roll:
123mm v 112mm, to scale                                                                                      overlaid for comparison
However, once you get a lot of rolls, the saving soon adds up:

the difference is clear with 40 rolls
Assuming that the height of the rolls is the same, the 9% reduction in diameter corresponds to a 1-0.912 = 1-0.83 = 17% reduction in volume.  Hence more rolls can be packed in each delivery lorry, with a claimed  saving of 500 lorry trips, or 140 tonnes of CO2, per year.

But we could do better, surely?  I've shown the rolls on a square grid, because that's how they are packed:

But what about a hexagonal packing?

smaller rolls, and now hexagonally packed
Now each roll occupies a hexagon of half-height r, not a square of half-height r:

square boundary                                             hexagonal boundary                                             equilateral triangle

What space does this take?  The hexagon is made of 6 equilateral triangles, each of height r.  If the side is of length h, then we have r = h sin 60 = h √3 / 2.  The area of the triangle = 1/2 x base x perpendicular height = h/2 x r = r2 / √3.  The area of the hexagon is 6 times this, or  2√3 r2  = 3.464  r2.  The square, meanwhile, has area 4 r2.  (And not coincidentally, 3.464 is a better approximation to π than is 4.)  Hence hexagonal packing is (4 - 3.464)/4 = 0.134, or a little over 13%, better than square packing.

Doing the sums to combine the percentages properly [viz, 1-(1-17%)(1-13%)=0.28], this means hexagonal packing and smaller rolls combined gives about 28% improvement over the original large, square packed rolls.

So Sainsbury's could save a further 300-odd lorry trips, and a further 90 tonnes CO2, by packing the rolls hexagonally.

Maybe I should write them a letter?

UPDATE (19 Jan 2014)

A commenter queried the correctness of the QI calculations.  I just so happen to have an old and new roll size cardboard tube.  Here's the difference:

the smaller tube has a diameter of ~35mm, the larger a diameter of ~50mm; also the cardboard is much flimsier in the smaller tube
So although the exact dimensions quoted may not be quite right, they are pretty close!

Sunday, 24 March 2013

the rise and fall of Ctrl-S

I first used a computer back in the late 1970s, when I was an undergraduate physics student. In those days, we wrote programs on punched cards. To lose your program, you had to lose the cards (or, actually, just shuffle them).  To prove we never throw anything away, here is a program from the 1970s:

a program statement from yesteryear: 12  MAG(J,K) = 0
a whole program; no idea what it does
By the time I was a research student, punched cards had given way to text editors through VT100 terminal sessions.  I wrote my thesis in troff (one of my fellow students was writing his in this new-fangled thing called TeX), using the ZED line editor.  In order to save your changes, you had to exit the editor, save, and restart the editor, a non-trivial sequence of operations that interrupted the writing flow.  However, by the time I was writing up, the IBM 370 mainframe was on its last legs, about to be replaced by a new IBM 3081, and crashing frequently.  So I got in the habit of exiting the editor every 5-10 minutes, saving, and re-entering.

Frequent saving was ingrained in my workflow by the time applications came uniformly equipped with Ctrl-S.  (Saving without exiting.  Luxury!)  Every time I would pause to think what to write next, in word processor, spreadsheet, or text editor, I would automatically hit Ctrl-S.  It's now an automatic behaviour.

But modern applications no longer use Ctrl-S.  They just continually save, automatically. There's no need to keep saving explicitly.  Most applications that have an auto-save feature also let you do your own saves in between.  But some applications no longer have a user save command at all.  I noticed this first with Evernote, and then with Google Docs.

Fortunately, these applications haven't mapped Ctrl-S to any other function (mail programs where Ctrl-S means "send" are a real nightmare), so nothing bad happens if I do reflexively hit Ctrl-S.  Which I do sometimes, because it feels really weird not to keep saving after all these years.

Three generations of saving technology: manual-slow-and-clunky, manual-easy, automatic. That's probably progress.

Monday, 18 March 2013

foggy thinking

driving in fog
Driving in fog this morning I was again bemused by something I notice every time when driving in fog.

Visibility was varying between 100-200 yards.  Nearly all the cars had their headlights on; about half also had their fog lights on.

A few had no lights on at all.  I assume these drivers are the ones who either think lights are for wimps, or who don't think at all.

But what bemuses me, every time, is the ones who have only their side-lights on.  In fog, you can see a car before you see its sidelights.  These drivers must have got as far as thinking "fog; put lights on" but not got as far as thinking "put headlights on because sidelights are invisible in fog, as I can clearly tell from all those other cars with only their sidelights on..."

I excuse those with sidelights comprising a little row of LEDs; I suspect these are visible from low earth orbit.

It's not just me.  Highway Code rule 226 says:
You MUST use headlights when visibility is seriously reduced, generally when you cannot see for more than 100 metres (328 feet). You may also use front or rear fog lights but you MUST switch them off when visibility improves 
(Although I MUST say, translating the round number 100m to 328ft is ridiculously precise.)

Wednesday, 13 March 2013

another evening well spent

A new level for Cut-the-Rope Experiments announced itself to my phone.  It was swiftly downloaded.

The "ant hill" level has little lines of (4-legged!) ants that carry the candy from one place to another.  Tapping the candy then releases it from the ants at the desired spot.  This adds a new form of time-criticality to the manoeuvers, with some interesting new puzzles.

Aaaand ... my work here is done:

Monday, 11 March 2013

clear ... snow ... clear

Half an hour ago, I looked out of the window: nothing special.

Ten minutes ago, I looked out of the window, onto a blizzard:

And now -- it's all clear, and the sun is shining!

As they say: "if you don't like the weather, just wait a few minutes".

what's the point of the TPS?

We're registered with the Telephone Preference Service, because we don't want scummy spam phone calls.

It doesn't help with everybody.

Today, at 11:16, the phone rings, and then plays a recorded message at me.

0151 909 1965 : go take a running jump.

Sunday, 10 March 2013

normality has been restored...

...partially, anyway.

When my home machine died, and I upgraded to Windows 7, my incredibly ancient 16-bit Smalltalk/V would no longer work.  As this was what I used to generate the book review pages on my website, it was a bit of a disaster.

So over the past several weekends, I've been re-implementing my book list program, from scratch, in Python, and the new pages have finally gone live.  (There are still broken links from the non-automatically generated pages; I'll fix those next.)

This was my first major foray into Python.  Three years ago, I wrote my first ever Python program -- a Game of Life implementation, using Gosper's hashlife algorithm -- but then didn't touch it again until recently.  Instead, I was using Matlab for all my number-crunching needs.  However, I needed something a bit more friendly for teaching some non-computer science students a little bit about simulation.  So before Christmas I wrote a small flocking program in Python, and a few little bits and bobs.  Then I learned about NumPy, which does a lot of the matrix stuff that Matlab does, so I thought I'd give it a try, by reimplementing some Random Boolean Network code I'd originally written in Matlab.

I was really impressed, so decided to do some more NumPy programming, to learn it better.  I wrote a few programs to support some practicals for a module I teach: a quantum random walk simulator, an iterated function system, and a 1D cellular automaton.  And after that exposure, I decided I was deeply in love with Python.

But the book list program is my biggest yet, by a long way.  All the previous programs had a core of essentially about 10 lines of code (each of those lines doing a lot, mind you!), each written in an hour or so.  The book list program is several hundreds of lines (many of which also do rather a lot), split over 5 files and several classes.  I also decided to take the opportunity to reorganise and tidy up the structure of my web pages, which involved writing a few utilities, to rename a bunch of files, to write a new table in the database, that sort of thing.  File handling. Database access. All amazingly simple in the marvellous language that is Python.

Although, frankly, I couldn't have done it without the wonderful Stackoverflow forum.  The Python documentation is useful if you know how to do something, and just need to check the syntax or method name.  It's not so helpful if you don't know how to do something. And Python has its own way of doing things.  But every time I typed into Google: "python how to  XXX", for a wide range of XXX, there was Stackoverflow with the answer -- often several answers!  Thanks, guys.

When I started writing this, I was consulting online resources for nearly every line.  But now, I'm happily typing things like
reviews = [bk for bk in have_reviews if bk.isNFBook()][0:10]
without looking things up any more.

And I'm now looking round for my next Python project...