Book Read Free

Humble Pi

Page 2

by Matt Parker


  I believe that ‘regardless of flight phase’ is official FAA speak for ‘This could go down mid-flight.’ Their official line on airworthiness was the requirement of ‘repetitive maintenance tasks for electrical power deactivation’. That is to say, anyone with a Boeing 787 had to remember to turn it off and on again. It’s the classic computer programmer fix. Boeing has since updated its program to fix the problem, so preparing the plane for take-off no longer involves a quick restart.

  When 4.3 billion milliseconds is just not enough

  So why would Microsoft, Los Angeles Air Route Traffic Control Center and Boeing all limit themselves to this seemingly arbitrary number of around 4.3 billion (or half of it) when keeping track of time? It certainly seems to be a widespread problem. There is a massive clue if you look at the number 4,294,967,295 in binary. Written in the 1s and 0s of computer code, it becomes 11111111111111111111111111111111; a string of thirty-two consecutive ones.

  Most humans never need to go near the actual circuits or binary code on which computers are built. They only need to worry about the programs and apps which run on their devices and, occasionally, the operating system on which those programs run (such as Windows or iOS). All these use the normal digits of 0 to 9 in the base-10 numbers we all know and love.

  But beneath it all lies binary code. When people use Windows on a computer or iOS on a phone, they are interacting only with the graphical user interface, or GUI (delightfully pronounced ‘gooey’). Below the GUI is where it gets messy. There are layers of computer code taking the mouse clicks and swipe lefts of the human using the device and converting them into the harsh machine code of 1s and 0s that is the native language of computers.

  If you had space for only five digits on a piece of paper, the largest number you could write down would be 99,999. You’ve filled every spot with the largest digit available. What the Microsoft, air traffic control and Boeing systems all had in common is that they were 32-bit binary-number systems, which means the default is that the largest number they can write down is thirty-two 1s in binary, or 4,294,967,295 in base-10.

  It was slightly worse in systems that wanted to use one of the thirty-two spots for something else. If you wanted to use that piece of paper with room for five symbols to write down a negative number, you’d need to leave the first spot free for a positive or negative sign, which would mean that you could now write down all the whole numbers between −9,999 and +9,999. It’s believed Boeing’s system used such ‘signed numbers’, so, with the first spot taken,fn1 they only had room for a maximum of thirty-one 1s, which translates into 2,147,483,647. Counting only centiseconds rather than milliseconds bought them some time – but not enough.

  Thankfully, this is a can that can be kicked far enough down the road that it does not matter. Modern computer systems are generally 64-bit, which allows for much bigger numbers by default. The maximum possible value is of course still finite, so any computer system is assuming that it will eventually be turned off and on again. But if a 64-bit system counts milliseconds, it will not hit that limit until 584.9 million years have passed. So you don’t need to worry: it will need a restart only twice every billion years.

  Calendars

  The analogue methods of timekeeping we used before the invention of computers would, at least, never run out of room. The hands of a clock can keep spinning around; new pages can be added to the calendar as the years go by. Forget milliseconds: with only good old-fashioned days and years to worry about, you will not have any maths mistakes ruining your day.

  Or so thought the Russian shooting team as they arrived at the 1908 Olympic Games in London a few days before the international shooting was scheduled to start on 10 July. But if you look at the results of the 1908 Olympics, you’ll see that all the other countries did well but there are no Russian results for any shooting event. And that is because what was 10 July for the Russians was 23 July in the UK (and indeed most of the rest of the world). The Russians were using a different calendar.

  It seems odd that something as straightforward as a calendar can go so wrong that a team of international athletes show up at the Olympics two weeks late. But calendars are far more complex than you’d expect; it seems that dividing the year up into predictable days is not easy and there are different solutions to the same problems.

  The universe has given us only two units of time: the year and the day. Everything else is the creation of humankind to try to make life easier. As the protoplanetary disc congealed and separated into the planets as we know them, the Earth was made with a certain amount of angular momentum, sending it flying around the sun, spinning as it goes. The orbit we ended up in gave us the length of the year, and the rate of the Earth’s spin gave us the length of the day.

  Except they don’t match. There is no reason they should! It was just where the chunks of rock from that protoplanetary disc happened to fall, billions of years ago. The year-long orbit of the Earth around the sun now takes 365 days, 6 hours, 9 minutes and 10 seconds. For simplicity, we can call that 365 and a quarter days.

  This means that, if you celebrate New Year’s Eve after a year of 365 days, the Earth still has a quarter of a day of movement before you’ll be back to exactly where you were last New Year’s Eve. The Earth is tearing around the sun at a speed of around 30 kilometres every second, so this New Year’s Eve you will be over 650,000 kilometres away from wherever you were last year. So, if your New Year’s resolution was to not be late for things, you’re already way behind.

  This goes from being a minor inconvenience to becoming a major problem because the Earth’s orbital year controls the seasons. The northern hemisphere summer occurs around the same point in the Earth’s orbit every year because this is where the Earth’s tilt aligns with the position of the sun. After every 365-day year, the calendar year moves a quarter of a day away from the seasons. After four years, summer would start a day later. In less than four hundred years, within the lifespan of a civilization, the seasons would drift by three months. After eight hundred years, summer and winter would swap places completely.

  To fix this, we had to tweak the calendar to have the same number of days as the orbit. Somehow, we needed to break away from having the same number of days every year, but without having a fraction of a day; people get upset if you restart the day at a time other than midnight. We needed to link a year to the Earth’s orbit without breaking the tie between a day and the Earth’s rotation.

  The solution that most civilizations came up with was to vary the number of days in any given year so there is a fractional number of days per year on average. But there is no single way to do that, which is why there are still a few competing calendars around today (which all start at different points in history). If you ever have access to a friend’s phone, go into the settings and change their calendar to the Buddhist one. Suddenly, they’re living in the 2560s. Maybe try to convince them they have just woken up from a coma.

  Our main modern calendar is a descendant of the Roman Republican calendar. They had only 355 days, which was substantially fewer than required, so an entire extra month was inserted between February and March, adding an extra twenty-two or twenty-three days to the year. In theory, this adjustment could be used to keep the calendar aligned with the solar year. In practice, it was up to the reigning politicians to decide when the extra month should be inserted. As this decision could either lengthen their year of ruling or shorten that of an opponent, the motivation was not always to keep the calendar aligned.

  A political committee is rarely a good solution to a mathematical problem. The years leading up to 46BCE were known as the ‘years of confusion’, as extra months came and went, with little relation to when they were needed. A lack of notice could also mean that people travelling away from Rome would have to guess what the date back at home was.

  In 46BCE Julius Caesar decided to fix this with a new, predictable calendar. Every year would have 365 days – the closest whole number to the true value – and the bo
nus quarter days would be saved up until every fourth year, which would have a single bonus day. The leap year with an extra leap day was born!

  To get everything back into alignment in the first place, the year 46BCE had a possible-world-record 445 days. In addition to the bonus month between February and March, two more months were inserted between November and December. Then, from 45BCE, leap years were inserted every four years to keep the calendar in synch.

  Well, almost. There was an initial clerical error, where the last year in a four-year period was double-counted as the first year of the next period, so leap years were actually put in every three years. But this was spotted, fixed and, by 3CE, everything was on track.

  The audacity of Pope

  But Julius Caesar was betrayed – albeit long after his death – by the 11 minutes and 15 seconds difference between the 365.25 days per year his calendar gave and the actual time between seasons of 365.242188792 days. An eleven-minute drift per day is not that noticeable to start with; the seasons move only one day every 128 years. But after a millennium or so of drift, it would accumulate. And the young upstart religion of Christianity had pinned their celebration of Easter to the timing of the seasons, and by the early 1500s there was a ten-day gap between the date and the actual start of spring.

  And now for a niche fact. There is an oft-repeated statement that the Julian calendar years of 365.25 days were too long compared to the Earth’s orbit. But that is incorrect! The Earth’s orbit is 365 days, 6 hours, 9 minutes and 10 seconds: slightly more than 365.25 days. The Julian calendar is too short compared to the orbit. But it is too long compared to the seasons. Bizarrely, the seasons don’t even exactly match the orbital year.

  We’re now at the level of calendar resolution when other orbital mechanics come into play. As the Earth orbits, the direction it is leaning also changes, going from pointing directly at the sun to pointing away every 13,000 years. A calendar perfectly matching the Earth’s orbit will still swap the seasons every 13,000 years. If we factor the Earth’s axial precession (the change in how it leans) into its orbit, the time between seasons is 365 days, 5 hours, 48 minutes and 45.11 seconds.

  The movement of the Earth’s tilt buys us an extra 20 minutes and 24.43 seconds per orbit. So the true sidereal (literally, ‘of the stars’) year based on the orbit is longer than the Julian calendar, but the tropical year based on the seasons (which we actually care about) is shorter. It’s because the seasons depend on the tilt of the Earth relative to the sun, not on the actual position of the Earth. You have my permission to photocopy this part of the book and hand it to anyone who gets the type of year wrong. Maybe suggest their New Year resolution should be to understand what a new year actually is.

  Sidereal year

  31,558,150 seconds = 365.2563657 days

  365 days, 6 hours, 9 minutes, 10 seconds

  Tropical year

  31,556,925 seconds = 365.2421875 days

  365 days, 5 hours, 48 minutes, 45 seconds

  This slight mismatch between the Julian and tropical years was unnoticeable enough that, by 1500CE, pretty much all of Europe and parts of Africa were using the Julian calendar. But the Catholic Church was sick of Jesus’s death (celebrated according to the seasons) drifting away from his birth (celebrated on a set date). Pope Gregory XIII decided something had to be done. Everyone would need to update to a new calendar. Thankfully, if there’s one thing a pope can do, it’s convince a lot of people to change their behaviour for seemingly arbitrary reasons.

  What we now know as the Gregorian calendar was not actually designed by Pope Greg – he was too busy doing pope things and convincing people to change their behaviour – but by the Italian doctor and astronomer Aloysius ‘Luigi’ Lilius. Luigi unfortunately died in 1576, two years before the calendar reform commission released his (slightly tweaked) calendar. With the slight nudge of a papal bull in 1582 to bully them into it, a decent chunk of the world swapped over to the new calendar system that year.

  Luigi’s breakthrough was to keep the standard every-fourth-year leap year of the Julian calendar but to take out three leap days every four hundred years. Leap years were all the years divisible by four, and all Luigi suggested was to remove the leap days from years which were also a multiple of 100 (apart from those that were also a multiple of 400). This now averages out to 365.2425 days per year; impressively close to the desired tropical year of around 365.2422 days.

  Despite it being a mathematically better calendar, because this new system was born out of Catholic holidays and promulgated by the pope, anti-Catholic countries were duly anti-Gregorian calendar. England (and, by extension at the time, North America) clung to the old Julian calendar for another century and a half, during which time their calendar not only drifted another day away from the seasons but was also different to the one used in most of Europe.

  This problem was exacerbated because the Gregorian calendar was backdated, recalibrating the year as if it, rather than the Julian option, had always been used. Through the use of pope power, it was decreed that ten dates would be taken from October 1582 and so, in Catholic countries, 4 October 1582 was directly followed by 15 October. All this does of course make historical dates a bit confusing. When the English forces landed on Île de Ré on 12 July 1627 as part of the Anglo-French War, the French forces were ready to fight back on 22 July. That is, on exactly the same day. At least, for both armies, it was a Thursday.

  However, as the Gregorian calendar became more about seasonal convenience and less about doing what the pope said, other countries gradually switched over. A British Act of Parliament from 1750 points out that not only do England’s dates differ from those in the rest of Europe, they also differ from those in Scotland. So England swapped over, but without any direct mention of the pope; they merely referred indirectly to ‘a method of correcting the calendar’.

  England (which still – barely – included parts of North America) swapped over in 1752, realigning its dates by removing eleven days from September. Thus, 2 September 1752 was followed by 14 September 1752. Despite what you may read online, no one complained about losing eleven days of their life and no one carried a placard demanding, ‘Give us our eleven days.’ I know this for sure: I went to the British Library in London, which houses a copy of every newspaper ever published in England and looked up contemporary reports. No mention of complaint, only ads selling new calendars. Calendar creators were having the time of their life.

  The myth that people protested against the calendar change seems to have come from political debates before an election in 1754. The opposition party was attacking everything the other party had done during its term in office, including the changes to the calendar and stealing eleven days. This was captured in An Election Entertainment, an oil painting by William Hogarth. The only contemporary concerns were expressed by people who did not want to pay a full 365 days’ worth of tax on a year with fewer days. Legitimately, one might say.

  Russia did not swap calendars until 1918, when it started February on the 14th rather than on the 1st to bring themselves back into alignment with everyone else on the Gregorian calendar. Which must have caught a lot of people off guard. Imagine waking up a thinking you had two weeks only to find it’s already Valentine’s Day. This new calendar means the Russians would have been on time for the 1920 Olympics, had they been invited, but in the interim Russia had become Soviet Russia and was not invited for political reasons. The next Olympic Games attended by Russian athletes was in Helsinki in 1952, where they finally won a gold medal in shooting.

  Despite all these improvements, our current Gregorian calendar is still not quite perfect. An average of 365.2425 days per year is good, but it’s not exactly 365.2421875. We’re still out by twenty-seven seconds a year. This means that our current Gregorian calendar will drift a whole day once every 3,213 years. The seasons will still reverse once every half a million years. And you will be alarmed to know that there are currently no plans to fix this!

  In f
act, on such long timescales, we have other problems to worry about. As well as the Earth’s axis of rotation moving about, the orbital path of the Earth moves around as well. The path is an ellipse, and the closest and most distant locations do a lap around the solar system about once every 112,000 years. But even then the gravitational tug of other planets can mess it up. The solar system is a sloshy mess.

  But astronomy does give Julius Caesar the last laugh. The unit of a light-year, that is, the distance travelled by light in a year (in a vacuum) is specified using the Julian year of 365.25 days. So we measure our current cosmos using a unit in part defined by an ancient Roman.

  The day time will stand still

  At 3.14 a.m. on Tuesday, 19 January 2038 many of our modern microprocessors and computers are going to stop working. And all because of how they store the current date and time. Individual computers already have enough problems keeping track of how many seconds have passed while they are turned on; things get worse when they also need to keep completely up to date with the date. Computer timekeeping has all the ancient problems of keeping a calendar in synch with the planet plus the modern limitations of binary encoding.

  When the first precursors to the modern internet started to come online in the early 1970s a consistent timekeeping standard was required. The Institute of Electrical and Electronics Engineers threw a committee of people at the problem and, in 1971, they suggested that all computer systems could count sixtieths of a second from the start of 1971. The electrical power driving the computers was already coming in at a rate of 60 Hertz, so it simplified things to use this frequency within the system. Very clever. Except that a 60-Hertz system would exceed the space in a 32-digit binary number in a little over two years and three months. Not so clever.

 

‹ Prev