Friday, 2 July 2010

Probabilities of Averages

Consider something that has a very low probability of happening, like rolling the sum of 100 when rolling one-hundred six-sided dice. Since there is only one combination with this sum (i.e. all 100 dice show one pip), the probability of it happening is one in 6100. If the sum we are interested in is instead 101, then one die must end up with two pips showing. This could be any of the dice, so even though the probability of this happening is actually still very small, it is still a hundred times greater than rolling the sum of 100.

Now, when rolling only one die the average roll (over an infinite number of rolls) is 3,5. Of course when rolling only one die the probability is also equal for all results. If we increase the number of dice with one, the average sum will be 7 (3,5*2). If we name the dice d1 and d2 we can describe a roll as [d1, d2]. Rolling the sum of 7 can then be achieved by rolling any of the following combinations: [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1]. Each combination has the same probability of 1/36, but when only considering the sum of 7 the probability is as much as 1/6. A higher or lower sum than average will decrease the number of available combinations and thus the probability for the sum, though the probability for each combination will still be the same. At the extreme ends are the sums of 2 ([1, 1]) and 12 ([6, 6]), with one combination each.

With one hundred dice the average roll would be 350 (3,5*100), and just as we saw earlier the probabilities are not spread out evenly over the different sums. This means that a sum of 350 has a bigger probability of happening than other sums. If we would use the notation from above we could describe a roll as [d1, d2,..., dn]. We would then see that just as in the case of two dice, the number of combinations for a sum decreases as we stray away from the average sum, so that it is very likely that we end up with a sum in the vicinity of 350.

So what do I want to say with this? Perhaps nothing more than that I like probabilities. This reasoning can also be applied to a lot of things around us though. The average combination of events around us will lead to something that we can usually predict but the result has a probability of being something else. In fact, according to chaos theory the only reason the laws of physics can be reasonably relied on is that they include so many die rolls that it is too likely for them to not follow the average.

I would like to point something out also about everyday coincidences. When something strange with a low probability happens it might not be as strange as we would like to think. In the period when one unlikely event happened, millions of likely events will have happened as well. There is also the fact that it might be likely that something unlikely is to happen even though a particular unlikely event has a very low probability. An example would be to generate a random number between one and a billion, each number has a very small probability but it is very likely that we will get one of those numbers still.

It is getting more and more probable that this article is getting long-winded so it is very likely that I will end it here.

Saturday, 27 March 2010

Online After-Life

During a person's life his or her presence online keeps changing. Blog posts, tweets, status updates, forum discussions, video clip collections, personal web pages and a lot of other services keep reflecting the person until suddenly, when he or she dies, that presence freezes and becomes a historical reference to the person's life. Some parts of the mark will be erased soon. For example if the person who died had a web hotel that kept a site up, the web hotel will be quick to close down that page once the payments stop.

What happens to other things then? A lot of free services exist on servers around the Internet. There your profile will possibly exist for a very long time if the service provider does not have a policy of removing inactive accounts.

As an example, lets say a person who has a Facebook account dies. All activity on his or her profile will stop. The last status update will be saved as a memory of the person (hopefully something good). All connections will be left, as long as people on the other end do not remove them. The profile will be frozen. If Facebook lives on, after a while some of the contacts will die and there will be a frozen subnet containing profiles of dead people. More and more people will die, at some point resulting in profiles that are not connected to anyone living anymore, thus creating islands which are never or rarely visited. All the time more people will sign up to use Facebook, but there can never be more people signing up than dying or leaving. This means at some point the number of dead people represented on Facebook will surpass that of the living people. Facebook will always contain memories of the people that passed away, even though they will be hidden from new users who only connect to living friends.

The same process takes place all around the web, memories of our lives being saved. Just as in life we probably overestimate the impact that online presence has, but at least we will not be around to be disappointed!

Friday, 26 February 2010

The Chicken and the Egg

Which came first, the chicken or the egg? There seem to be and endless supply of people bringing this question up in different contexts, and each time it is expected to be a question without an answer. This could be true, but it might not as you will see. The question does not have a one ultimate answer, as it depends heavily on the viewpoint one takes when answering.

If we look at it from a purely historical point of view, eggs have been around at least since the dinosaurs were around more than 65 million years ago. Back then no chickens existed as far as we know, so from this viewpoint one can easily answer that the egg came way before the chicken.

Another viewpoint would be from a pure linguistical point. Did the word “egg” exist before the word “chicken”, and if it did, did it mean the same thing as today? This is a very hard question to answer since a language evolves, and tracing the history of a word might gradually change it until it is another word. One would then have to define exactly how much a word is allowed to change before we decide that it is a different word. Of course, if the word existed with another meaning before, we could probably find a point where the meaning changed to what it is today. I do not have a good answer from this line of thought, but if anyone has researched the origin of the words “egg” and “chicken” in detail, please share your findings.

Dropping the language details, lets move backwards in time. If we start with a chicken today it will have come from an egg, which will have come from a chicken and so on. We will at some point reach an ancestor which we would not call a chicken, but lets not dwell on that. This chicken ancestor came from an egg as well, which was probably produced by another chicken ancestor. Somewhere along the line we would reach a living organism that created a copy of itself without an egg (very far back), which at some point evolved into creating protection for its offspring during its first phase. This would then mean that that organism predated the egg as such, and thus the question would be that the chicken came before the egg, although it would an extremely different chicken from the one we have today.

Of course the above reasoning relies heavily on evolution in its explanation. If one were to believe in creationism, then according to Pastafarianism either the chicken or the egg was created by the Flying Spaghetti Monster. This view would actually leave the question as cryptical as the question probably was is intended to be.

So what have we learned here? This could be a very simple question or a very hard one. Whatever your answer to the question you will probably be right from your own perspective, and there are probably more views than I have listed here. This is very apparent when it comes to this question, but the same can be said on almost any question. The viewpoint you take when answering the question will affect the way you interpret it and thus the answer to it.

Monday, 18 January 2010

One Small Leap

First, I would like to explain the concept of the leap second. At first the definition of a second was 1/86400 of a solar day. This was not a good enough standard, so the definition was later changed to the somewhat less comprehensible length of 9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium-133 atom. This gave some new problems since the solar day became approximately 1.7ms longer every century, the reason being that the earth's rotation is slowing down. To counter this sometimes an extra second is added June 30 or December 31. This added second is called a leap second. Worth mentioning is that the decreasing rotation varies based on unpredictable factors like the motion of mass in the center of the earth, which means we have no formula to calculate when the next leap second needs to be added. Instead the leap second is added when the difference between solar day time and the measured time gets too large (0.9).

This gives us some strange effects, especially when trying to calculate the difference between two points in time, where one or more leap seconds have been inserted. Imagine that a leap second was added on December 31 at 11.59.60p.m. The last minute of the year is made one second longer. This means that if were to count the seconds between 8 a.m. December 31 and 8 a.m January 1, we would get a count of 86401. If we were to count the hours instead though, the result would be 24 which, if we translate it into seconds, is 86400 and we just lost a second in the process. (This makes for some strange effects when dealing with date differences in computer systems, but that is not the topic here).

How can this be? Well, it all comes down to the difference between elapsed time and our daily measured time. The reason for the added second is to get our clocks synchronized with the solar time. The elapsed time would be 86401s = 1440m1s = 24h0m1s = 1d0h0m1s, and our clocks are calibrated so that we remove one second from the measurement of time. So what we actually do with the leap second is not to add a second, but instead hide it, delaying the coming of the next day.

We sweep one second under the rug, a little ashamed that we cannot cope with it any other way. Life goes on but the seconds we hide away will always be there in the past as a testimony that not everything can be exact.

Tuesday, 12 January 2010

Pseudo-Uniqueness

Pseudo-Uniqueness is a topic that came up during a project I took part in last year. Even though I already brought it up on that project's blog, it is a subject that I think would fit well into the spirit of the Reflection 42 blog, so here it is. Enjoy!

In the project, we were faced with the need to dynamically create unique user identifiers that did not follow a naming pattern (i.e. they needed to be very hard to guess).

So what did we do? Well, I wrote a utility class that creates hashes from input strings, then at user creation we passed the user's data to that class which returned an identifier. Using the MD5 algorithm for hashing, we would get a 32-digit hexadecimal number which would be virtually unique. Now I can hear some of you think "Virtually unique? How can you be sure it will not collide with an already existing ID?". Well, that is a good question and the short answer is that I cannot!

If you are interested, the long answer now follows.

If I generate a 32-digit hexadecimal number, it consists of 128 bits. 128 bits can be set in 2^128 different combinations, which means that the chance of getting the same hash for another user is 1 in 340282366920938463463374607431768211456 (39 digits). Lets say we have an unrealistically busy site, generating a million new users each day. Then after a thousand years we will have generated less than 4*10^11 different hashes. This means that we have a chance of 4*10^11 in 2^128 of calculating an already existing hash at this point with a probabiltiy in the magnitude of 10^-28.

Maybe our site is really successful and continues until no life can exist on earth (8Gyears from now). Well I am not going to bore you with the calculations for this one, but at that point we would have generated 3.2*10^21 different hashes. This means we would have the overwhelming probability of below 10^-18 of hitting one of the hashes we already used.

This is why I say virtually unique. The chance of getting the same ID is so small that it will probably never happen, and if it does the probability is so small that it probably did not. So I now leave it up to you to decide if this is unique enough for you!

By the way, I went with an SHA algorithm generating 160 bits instead, but that's just me!

Tuesday, 29 December 2009

The Infinite Meat Pie

This subject came up a some years ago among me and my friends. It was the concept of the infinite meat pie. The claim was that if an infinite meat pie existed, everything in the universe would be part of this meat pie. This could be true, but the concept of infiniteness doesn't require it, as we soon shall see.

First, I'd like to point out that since this is a thought experiment based on the pie already existing, I have no explanation on how this meat pie came into existence. Maybe it was created in the Big Bake, or maybe it has just always existed. Also this meat pie would have an infinite mass and that's another discussion altogether.

Lets get back to the claim of the infinite meat pie being everything. If this infinite meat pie has expanded continuously and infinitely in all directions it would indeed be everything. Imagine this though--a finite piece of the meat pie is removed. The pie would still be infinite in all directions, but there would be a finite hole in it somewhere where other things could exist. There could even be an infinite number of these holes as long as they leave pie between them and the pie will still remain infinite. There's also the possibility of having a meat pie that's only infinite in some directions. If you are near the crust of the pie you could be looking in a direction of endless meat pie but if you turn around the rest of the universe would spread out infinitely in the other direction. Since there is an infinite number of directions to choose from this also means that there could be an infinite number of infinite meat pies spreading out in different directions and there could still be a direction without meat pie.

By proof of contradiction we have determined that the claim doesn't hold.

The pie is a lie!

Monday, 28 December 2009

Prelude

Welcome to a new blog! I thought I'd start this one off with a small introduction to what the blog is about and where the name came from and then launch it from there.

So what's the deal with this blog about everything and nothing? Well, the idea initially came from a friend and former colleague of mine who often discusses different problems he encounters while developing. He told me jokingly that I should gather all questions I got and then publish a book with the discussions and answers. That triggered something within me and after some thinking this blog was created in my mind.

This will not be one of the this-is-what-I-did-today blogs that I hate so much. Neither will it be a blog about a certain subject. You might say it's a kind of mix between those two, where the subject is decided based on things that come up in everyday discussions or questions asked that I think worthy of mentioning. This means that some articles might be about programming, while others might be discussions about philosofical questions. It might also mean that some posts will give an exact answer while other posts will just have some reasoning and then leave you, as a reader, to decide what your thruth will be.

42 is the answer to the Ultimate Question of Life, the Universe, and Everything in The Hitchhiker's Guide to the Galaxy by Douglas Adams, and therefore I thought it fitting for this number to be included in the title of the blog. I will never be able to uncover the entire truth about everything, so this blog will be a vague reflection of the number 42, which explains the name Reflection 42.

Finally, I'd just like to add that I have no way of knowing where this blog will take off to. It might become a rather one-sided blog or it might become too diverse. In the end it's all about having fun, and if you get bored you can just leave :)