Most recent posts...

Checkerboard problem

I know the answer to this conundrum, but I still have problems recognizing the answer. If you’ve never seen it before, it is really baffling.

Which is the true statement about the image below?

  1. Square A is a darker grey than square B.
  2. A and B are the same shade of grey.
  3. A is lighter than B.

Adelson's checkerboard problem

(Click to enlarge to full size. It might help.)

The illusion was invented by Edward H Adelson in 1995. The best way to work out the solution empirically rather than by sight is either to import the full image into Photoshop (or whatever tool you use for image processing) and use its eyedropper tool to find the RGB values, or to print it out and then cut out the two squares to compare them directly.

If you want to explore this illusion more, I would go to the source: Adelson’s pages about it.

Now playing:
Thievery Corporation - All That We Perceive
(from It Takes A Thief)


Pikes Peak and the Supermoon

I was getting coffee from Starbucks this morning when I looked at Pikes Peak in the early morning sunlight. There was the waning moon setting over the snow-clad mountain. (Yesterday was a day of drizzle and damp; obviously this settled as snow at higher elevations.) I laid down some rubber to return home and get the camera to take a shot.

Pikes Peak and Supermoon

As you can see I just made it back in time…

By the way, if you want to see what Pikes Peak looked like on Saturday, here’s a shot I took then:

Volvo 1800s at Garden of the Gods 3

Yep, there was quite a bit of snow yesterday.

Album cover for Change the WeatherNow playing:
Underworld - Mr. Universe
(from Change the Weather)


PCPlus 306: How 3D TV works

Without a doubt this article was an absolute hoot to write. I had the most fun researching the subject, buying an iPhone app, photographing my toy stuffed hedgehog, writing the article, reading press releases about Nintendo’s 3DS (it had only just been announced when I was writing this). In fact, doing everything except, you know, actually watching any 3D TV (we don’t have a telly, let alone a 3D one).

PC Plus logoIn the article I quickly explain what a 3D effect is and how it works (each eye sees something slightly different and the brain reconstructs it into a three dimensional view), and then run through some of the standard ways people have devised in order to show two slightly different images to the eyes. We have the cyan-red system – and I have some anaglyph lenses for my glasses since there are many images online that can be viewed with such glasses – and the polarized system and the active system and the parallel barrier system used by said Nintendo device. I also point out the problem with all 3D systems: the eyes are focusing on a plane (the image or the screen) and yet the 3D effect is done through convergence. No wonder you can get headaches from watching 3D movies: the brain and the eyes are doing something that we’ve not trained them to do.

But still it’s great fun, nevertheless. Here’s the full anaglyph image of my toy hedgehog (you’ll need red/cyan glasses, remember):

Anaglyph image of a toy hegehog

(Click to enlarge.) And here is the stereogram for the same view:

Stereogram of a toy hedgehog

(Again click to enlarge.) For this one, the left image is supposed to be viewed by the right eye, and the right image by the left. In other words, cross your eyes when looking at the composite image and slowly uncross them. If you do it gently the double-double image will come together into a 3D view in the middle.

The iPhone app I used was this one: 3D Camera by Juicy Bits Software. I used a tripod to balance the iPhone on, otherwise it gets a bit finicky. (You have to take an image for the left eye, move the iPhone about 3 inches to the right, and then take a picture for the right eye. ) Anyway, well recommended for playing around with 3D images. The stereograms come out really well, I think.

Fascinating addendum: mid-April we went to Paris so that my wife could run the Paris Marathon. We were there six days, so we visited a couple of museums and art galleries, including the Louvre. For the exhibit on Leonardo da Vinci’s Virgin and Child with Saint Anne, we rented the audio guide. It came installed on a Nintendo 3DS with extra information and images encoded in 3D on the device (the guide was sponsored by Korean Air, if I recollect). Quite fun: it was the first time I’d actually used one and the first time I’d seen the parallel barrier method in action.

This article first appeared in issue 306, April 2011.

You can read the PDF here.

(I write a monthly column for PCPlus, a computer news-views-n-reviews magazine in the UK (actually there are thirteen issues a year — there's an Xmas issue as well — so it's a bit more than monthly). The column is called Theory Workshop and appears in the Make It section of the magazine. When I signed up, my editor and the magazine were gracious enough to allow me to reprint the articles here after say a year or so.)

Album cover for Beaucoup FishNow playing:
Underworld - Winjer
(from Beaucoup Fish)


Garden of the Gods and my Volvo 1800S

Poor old 64SAINT was looking a little moth-bombed this morning, so I took it out to wash it. Since it was a bloody glorious day – dare I say it, heavenly – I drove it to Garden of the Gods Park to photograph it. It was also a great opportunity to play around with my new Canon 60D as well. I had on the EF-S 18-55mm lens, so there’s lots of wide-angle shots.

Without further ado, here’s a brief selection of photos. You can see the full set on my Flickr page. Or as a slideshow.

This one was taken in the Visitor Center car park and shows the Kissing Camels formation in the background:

Volvo 1800s at Garden of the Gods 1

Including Pikes Peak in the background as well:

Volvo 1800s at Garden of the Gods 3

Wide-angle shot with Pikes Peak and the Kissing Camels:

Volvo 1800s at Garden of the Gods 7

In the park now:

Volvo 1800s at Garden of the Gods 10

Love the jagged “teeth” and the trees in this one:

Volvo 1800s at Garden of the Gods 12

And, finally (for here at least), the reverse side of the Kissing Camels:

Volvo 1800s at Garden of the Gods 13

Album cover for Pocket UniverseNow playing:
Yello - Beyond Mirrors
(from Pocket Universe)


Visualizing four million digits of pi

I came across this remarkable image a couple of days ago. It shows four million digits of π encoded as colored pixels, with one pixel per digit. Each digit has a slightly different color.

The page also allows you to search for digit strings up to six characters long and the page will find them in the image, if, of course, the string is there.

A few digits of piThis raises a couple of questions. The first one is this: given that π expressed as a decimal is infinitely long, can you find any digit string in it? (Since π is not a rational number – that is, a number that can be expressed as a/b for two integers a, b – it has to be infinitely long.) Let’s say you encode “To be or not to be” or anything else as decimal values, maybe using ASCII. Can you find that sequence of digits in π somewhere? It turns out that we don’t know. At least not for sure. A number with that property (that any finite sequence of digits can be found in the number’s infinite decimal representation) is known as a normal number. Although mathematicians believe that numbers like π and e and √2 are normal, no one has yet proved it.

The next question is this: what is the probability of finding a given digit string in those four million digits at least once? It turns out that answering this is a little bit like explaining the Birthday Paradox (the paradox that in a room of 23 randomly chosen people, the chances of two of them having the same birthday is about 0.5).

Let’s take it slowly. Suppose our string is one digit long, say “7”. What is the probability of finding it at the first position in π? That’s easy: 0.1. At the second position? it’s the same: 0.1. In fact it’s the same throughout the four million digits of π: the chance of finding “7” at any position is 0.1. Now suppose our digit string is two digits long, say 42. What’s the probability of finding it at the first position? Well, since there are 100 possible two-digit strings (“00” to “99”), the probability must be 0.01. The second position? The same: 0.01. Ditto for all the other positions in the expansion of π: the probability of finding 42 is 0.01 at any position. I’m sure you can see the pattern and work out the probability of finding a three-digit string (0.001), a four-digit string (0.0001), and so on. In essence, if there are d digits, the probability of finding the given string at each and every position is \(0.1^d\).

However, that doesn’t really help us answer the original question: what is the probability of finding a given string at least once? Let’s invert the problem: if we know that the probability of something happening is p then the probability of it not happening is \(1-p\). So all we need to do is to calculate the probability of not finding the given string at all in those four million digits of π, and then our answer is going to be 1 minus that. Brilliant, he says snarkily.

Let’s suppose our given string is “123”. We know that the probability of finding it at position 1 is 0.001. The probability of not finding it there is therefore 0.999. The same goes for position 2: the probability of not finding it there is 0.999. Ditto for every other position. So the overall probability of all of these positions not containing “123” is \( (0.999 \times 0.999 \times 0.999 \times \dots) \) four million times. Or, more concisely, \(0.999^{4,000,000}\). This is equal to 0, at least  to the resolution of my scientific calculator. So the probability of this being false, that “123” appears at least once in those four million digits, is 1. Phew.

To generalize, the probability of finding a given d digit string in those four million digits of π is going to be this:

\[1-(1-0.1^d)^{4,000,000}\]

For fun, I did a quick set of calculations to show the probabilities of finding strings for various string lengths in those four million digits (OK, Wolfram Alpha did the calculations, but I’m taking the glory). For one to five digits, the probability of finding a given string of that length in four million digits is, for all intents and purposes, 1.0. It’s a certainty, in other words. For six digits, the probability is 0.98; that is, one chance in fifty of not finding a given string. For seven digits, it’s 0.33; two chances in three of not finding it. For eight digits, the probability of finding a given string is 0.04, or one chance in 25. For nine digits it’s one chance in 250.

We now know 10 trillion digits of π. Using the above, I’m sure you can now calculate the probability of finding, say, a given 15-digit string in those 10 trillion digits. (It’s 0.01 or just one chance in 100.)

Album cover for The Quiet American [Original Score]Now playing:
Armstrong, Craig - Fowler's Temptation
(from The Quiet American [Original Score])


“The Islanders” by Christopher Priest

While we were away last week in Paris for the Marathon, I finished The Islanders, a novel by one of my favorite authors, Christopher Priest.

Cover for The IslandersWell, actually, I find it hard to call it a novel. It is novel certainly, but a novel? To call it so might imply that it has some kind of plot and a protagonist who changes and learns throughout the story. Instead The Islanders is something way more.

First of all, it is structured as a gazetteer, a guidebook to the Dream Archipelago, a belt of islands that circles the girth of an Earth-like planet, with a continent to the North and one to the South. So, science fiction then? Or fantasy? Maybe. The islands described in the gazetteer are arranged in alphabetic order from Aay, also known in the local patois as Island of Winds, to Yannet, known as Dark Green or Sir, depending on the local patois you believe or follow. There is a foreword by a Chaster Kammeston who professes to not know much about the Dream Archipelago – he’s never left the island he was born on – but who warns the reader that what they read may not in fact be true. We are not only in a dream archipelago but an unreliable one. As with Priest’s previous work (The Affirmation, The Separation, The Prestige, and so on), we learn very quickly to not take what we’re told as gospel, but only as a guide to what’s happening and happened.

Although Kammeston invites us to use the gazetteer as a reference, dipping into it randomly, he actually recommends that we read it from A to Z. Some of the entries are very literal, describing the island in question geographically and noting its primary weather systems and ocean currents. We’re given information about the local currency and places to visit on the island. Some entries provide a partial history about the place and mention various notable people who were born there or who moved there. The same names start cropping up, we make note of them and start to see connections. Some entries are stories about the island told by narrators who may, or may not, be believable. The themes and personalities in those stories appear elsewhere. Sometimes the stories told about people are negated by those same people later. There’s a murder mystery about the death of a great mime called Commis, and we get the same story told through four or five different viewpoints (but which is true? All? Any?). There’s a great love affair and suddenly we notice that the book’s dedication is to one of the lovers (the other being Kammeston himself). There’s an embedded discussion about what art means and about the artists who produce it (one of the characters is known for drilling tunnels through mountains and installing baffles to produce a kind of natural organ using the prevailing winds – we see her appearing throughout the book). There’s horror and comedy and one of the most terrifying insects invented: the dreaded thryme.

Fans of Priest’s other work will no doubt see previous story threads reappear and be examined further. There are twins (or at least people who look remarkably alike); magicians; unreliable narrators and their memories; a reality that is a little misty and dreamlike, fuzzy. One of the great motifs Priest returns to often and does so here with great effect is to invite us to consider who wrote the book. The simple answer I suppose is Kammeston, despite his protestations to the contrary, although one of the entries does have him dying (but some of the other entries imply that he’s not being exactly truthful anyway). Priest also explores a new theme here: glass, about which we’re invited to ponder on its ability to kill, to contain, to protect, and to modify and subvert reality. There are references to other Priestly stories and novels (including – brazenly almost – The Affirmation itself), although you don’t have to have read them to appreciate the book.

All in all then, an extremely thoughtful and frankly bizarre book. It’s one I shall return to in the future to get even more enjoyment and insights.

Album cover for Furious AngelsNow playing:
Dougan, Rob - I'm Not Driving Anymore
(from Furious Angels)


More TVM–calculating the IRR

My insurance company allows me to pay for our car insurance by monthly premiums instead of the usual premium once every 6 months. For this option, they just divide the total six-monthly premium by six to give the monthly premium, and then charge a $5 “processing fee” per month on top. I decided to take a look at how much this actually cost me. (For background on the Time Value of Money – TVM – see parts 1 and 2.)

Let’s say, for sake of argument, that our total car insurance premium every six months comes to $600. By taking advantage of this monthly payment plan I would pay $(600 / 6) + $5 every month, or $105. In effect, I am getting a loan for the total amount from my insurance company at the start of the six month period and paying it back in six equal payments. The cash flow diagram looks like this:

Car insurance payment cash flow

From last time, we worked out the NPV (Net Present Value) formula for a loan to be this:

\[a = P . r^N . \frac { (1 – r) } { (1 - r^N) }\]

where P is the principal of the loan, a is the payment per period, N is the number of periods, and \(r=(1+i)\), where i is the interest rate.

From this, and using the values from our car insurance problem, we get:

\[r^6 \frac {(1-r)}{(1-r^6)}=105/600\]

and we have to solve for r. Yeah, right.

Unfortunately, as was finally proved in the 1820s by Niels Henrik Abel based on work by Paolo Ruffini, there is no general analytic solution to the factorization of polynomials of degree five or more (which this is, essentially). Hence to solve this expression we have to resort to a numerical process, taking special care not to hit the discontinuity at \(r=1\).

The easiest way (that I used way back when) was the mid-point method. Write the equation like this:

\[y=r^6 \frac {(1-r)}{(1-r^6)}-0.175\]

and find a value for r that produces a y value less than zero, and one that produces a y value greater than zero. I tried \(r=1.01\) which gave a value for y of –0.00245, and \(r=1.10\), which gave a value for y of 0.0546. From this (and assuming that the equation is continuous between these two values of r, yadda, yadda), we can assume that the value of r that makes y zero lies between 1.01 and 1.1. Call these two endpoints, \(r_{low}\) and \(r_{high}\). Take the midpoint of these two values and plug it into the equation. If the resulting value for y is positive, replace \(r_{high}\) with this new guess, if negative, replace \(r_{low}\) with it. After a few iterations, you’ll find a value for y that is sufficiently close to zero for you to decide that this is the answer you want (say within 0.00001 of zero). Congratulations, you’ve just calculated r and therefore i.

(Aside for mathematicians: I agree that the Newton-Raphson method will converge faster, but to be honest, this mid-point method on modern processors is just as fast. Although it’s possible to rearrange the polynomial in this particular case so that you can easily differentiate it for the Newton-Raphson method, in the general case where cash flows may not all be equal or occur at regular times, the mid-point method is best.)

Using this method (I programmed it into one of my HP programmable calculators) I got a value for r of 1.014. This means that i is 1.4% per month, or 16.8% per annum. Urk. In essence, if I find a loan with an interest rate of less than 16.8%, say, a credit card, it would be advantageous to use it instead of this option from the insurance company. Or, if I had some savings at some miserable rate of 0.5%, it would be worthwhile to dip into them, pay the total premium, and then pay the “loan” back monthly.

What I’ve just calculated here, by the way, is known as the Internal Rate of Return, or IRR. It’s the effective interest rate for a series of cash flows, with internal meaning that no attention is paid to any external factors, like, say, inflation.

Album cover for Duran Duran [The Wedding Album]Now playing:
Duran Duran - Come undone
(from Duran Duran [The Wedding Album])


Fake magazine renewal notice

As a household, we subscribe to a few magazines. Hence we get renewal notices for those magazines regularly, and, the magazine subscription industry being what it is, we usually get two or three renewal notices per magazine subscription. On average maybe a couple per month. All well and good, no problem.

In today’s mail I got this renewal notice for The Economist:

Scam Renewal Notice Page 1

The only issue is I do not actually subscribe to The Economist. I did, a few years ago, and liked it, but I never really found time to read it (it’s a weekly publication after all, with many in-depth articles that reward intelligent reading). Oh, for the days of commuting by Tube to/from the City of London…

Anyway, back to the notice. Because I no longer get The Economist, my guard was up already. Also, it wasn’t from them  and didn’t have their branding. Just some outfit called “Associated Publishers Services”, whose website was publisherspayment.com, and who wanted checks writing to “ASPS” (which is not an initialism of their name). The overpowering smell of week-old cod filled the room. Yep, it was certainly fishy.

And there at the bottom of the page in ye olde 8pt font (cf. the 16pt font of “NOTICE OF RENEWAL/NEW ORDER”) we have “RENEWAL OFFER - NOT A BILL”. On the back, in the middle of a bunch of dense text is, “This is a magazine subscription offer, not a bill or invoice.”

Yes, it’s a, er, “renewal offer” (with the legal get-out-of-jail-free phrase at the bottom and sentence on the back) that is designed to look exactly like a renewal notice. In the hopes – obviously – that the person receiving it thinks it’s legit and just pays up to ensure their continued subscription. Nice. Reminds me of these guys.

For fun, I went to The Economist’s site and looked up how much subscribing to 51 issues would be direct from the publisher. Ready? $126.99, for both the print publication and digital delivery. This Renewal Notice Offer is for $179.95! In two installments of $89.98, if you so wish! And no mention of digital delivery! A friggin’ bargain at only $53 more than the official site; or, if you like, a markup of a mere 42%. Are you ready to pay an extra fifty bucks (a dollar per issue) to have these people as “independent agents” (that’s the phrase they use on the back) between you and the magazine? No, I thought not.

Scam Renewal Notice Page 2

Let’s just check the text on the notice offer: “By acting now, you can lock in at one of our lowest rates”, “You’re receiving one of the lowest available rates we can offer for your regular subscription” (emphasis mine). Nice evasions there, I must say. On the back is more goodness: you only have seven days to cancel should you have been foolish enough to send them any money, and, “it will be subject to a $20 cancellation fee”. Ooh, super nice.

In my opinion, then, pretty much a scam. Sorry if you got caught by it, but, if not, please watch out for these nasty little notices offers in your mail.

Album cover for The Royal ScamNow playing:
Steely Dan - Don't Take Me Alive
(from The Royal Scam)


A birthday shock

Today is my birthday. For the first time ever, my sister Nicola sent me a text to say Happy Birthday. Yay for modern technology, especially international texting of birthday wishes from England.

Her sending me a text wasn’t the shock though.

The shock was the previous texts displayed on the timeline: the last time she texted me was when Mum was dying in hospital two years ago.

Texts about Mum

So yeah, yay for modern technology. Especially the fact that I still have texts from two years ago saved on my phone.

Sigh.

(She died on Sunday, 4 April, 2010. Despite Nicola’s last text there, she made it through 1 April, now mostly in a coma, and the prognosis remained dire. On the 2nd, having vacillated the previous day, I booked the first flight to England I could get on, leaving 3 April. I arrived at the hospital at around 4pm on that Sunday. Mum was still alive, still in the coma, and I was able to say goodbye. Nicola had been there the entire time. I like to think Mum was waiting for me to get there: she died at 9pm that evening.)

Now playing:
Knowtoryus - Bomberclad Joint
(from The K&D Sessions)


Tightening the feedback loop when writing LaTeX expressions for MathJax

A couple of my recent blog posts have been about the Time Value of Money (one, two). They’re full of mathematical expressions, but I was tired of writing these expressions out in Microsoft Word’s equation editor, taking a snapshot of the result, and inserting the result as an image in the post. Instead I decided to try out MathJax, a quite remarkable JavaScript library that renders math expressions at run-time in the client.

The big problem that I had was writing expressions in LaTeX is not a skill I have, so although the simpler expressions were easy (for example: P_N = P_0(1+i)^N becomes \(P_N = P_0(1+i)^N\)), by the time I was writing the second installment the expressions I wanted to write in LaTeX were getting very hairy.

I started out by writing a simple HTML page that I would alter with a modified LaTeX expression, then view the result in a browser, but the feedback loop was too staggered and awkward. I needed that feedback loop to be much tighter: I wanted to type something in the browser and immediately see the rendered expression. Seeing that I’m supposed to be a JavaScript expert, it was time to write a little bit of code.

First of all I wrote a small HTML page that had a div to display the rendered expression, a paragraph to do the same (MathJax will display its results in a block or an inline element), and then a textarea for me to type the LaTeX expression:

<!DOCTYPE html>
<html>
<head>
<title>Preview MathJax expressions</title>

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

</head>
<body>

  <div id="outputmath"></div>

  <p id="inlinemath" style="text-align: center;"></p>

  <textarea id="inputtext" cols="40" rows= "7" style="display: block; margin: 10px auto;"></textarea>


</body>
</html>

The relevant elements are styled to appear in the center of the page (that’s the default for MathJax rendering in a block element). Notice also I’m loading jQuery and MathJax.

Next the code, which I added before the closing tag for the body element:

<script type="text/javascript">
  $(function () {
    var inputText = $("#inputtext"),
      outputMath = $("#outputmath"),
      inlineMath = $("#inlinemath");

    inputText.on("keyup", function () {
      var expr = inputText.val();
      outputMath.text('\\[ ' + expr + ' \\]');
      inlineMath.text('The expression is \\( ' + expr + ' \\).');
      MathJax.Hub.Queue(["Typeset", MathJax.Hub, "outputmath"]);
      MathJax.Hub.Queue(["Typeset", MathJax.Hub, "inlinemath"]);
    });

  });
</script>

It’s written as a jQuery document.ready function. In it I save the jQuery objects for the input textarea and both named output elements and then I add a keyup handler to the input textarea. On every keystroke, I grab the current contents of the input box, format it as an expression for both the block and inline elements, and then ask MathJax to re-render (that is, typeset) both elements. (MathJax queues up the requests and executes them asynchronously.) Bingo!

Here is is in action, finishing off writing out the quadratic formula I’m sure you remember from school:

Immediate feedback when editing for MathJax

Once I like how a particular expression looks, I can copy the content of the textarea and paste it into the blog post.

So, if you ever find yourself writing posts that need mathematical expressions, there you go. Have at it.

Album cover for Waiting for the Sirens' CallNow playing:
New Order - Guilt Is a Useless Emotion [Mac Quayle Vocal Mix]
(from Waiting for the Sirens' Call)


Extras

Search

About Me

I'm Julian M Bucknall, the M because it's my middle initial and because I and the other Julian Bucknall (the movie guy) would like to differentiate ourselves.

I'm a programmer by trade, an actor by ambition, and an algorithms guy by osmosis. I write articles for PCPlus in my spare time, not that there's much of that.

Julian M Bucknall Apart from that, an ex-pat Brit, atheist, microbrew enthusiast, Pet Shop Boys fanboy, slide rule and HP calculator collector, amateur photographer, Altoids muncher.

DevExpress

I'm Chief Technology Officer at Developer Express, a software company that writes some great controls and tools for .NET and Delphi. I'm responsible for the technology oversight and vision of the company.

Validation

Validate markup as HTML5 (beta)     Validate CSS

Bottom swirl

Archives

May 2012 (4)
SMTWTFS
« Apr  
12345
6789101112
13141516171819
20212223242526
2728293031

Like this Archive Calendar widget? Download it here.

Social networking

The OUT Campaign

The OUT Campaign

My Tweets

  • Honest Movie Trailer of Phantom Menace http://t.co/sif8y4Ns and then Battleship, er, Transformers http://t.co/sif8y4Ns
  • Damn, Donna Summer and Chuck Brown both gone in the last 24 hours. Different types of music, sure, but enjoyed them both. :(
  • Just saw a company page showing a list of tweets with "Join the conversation" linked to their Twitter a/c. The tweets are 6 months old #fail
Bottom swirl