Tuesday 28 April 2009

Divide By Zero


Despite what you might have read on teh interwebs you don't get a black hole if you divide by zero. But what do you get?

If you try it on a calculator you get an error or "can't divide by zero" message, although oddly if you are writing a computer program like this one...

double DivByZero(double n)
{
return n/0;
}


...you may well get a special value passed back which is either "Positive Infinity" or "Negative Infinity" which is a plausable number, but mathematically speaking wrong.

Lets look at the infinity business first. Imagine you divide 1 by a half (0.5), you get 2. Now divide 1 by a tenth (0.1), you get 10, now divide 1 by a hundredth (0.01), you get 100. So as the number you divide by gets progressively smaller and smaller the result gets larger and larger and this is true regardless of the number that is being divided.

In maths-speak what they say is that as the divisor (the number on the bottom) tends to zero then the result tends to infinity. Of course if the number being divided is negative then the result tends to a larger and larger negative value, "negative infinity".

The important thing to notice here is the "tends to zero" bit. The number is approaching zero, becoming exceedingly small but it is never actually zero. This works fine for computers where the rules say that all floating point operations have to have a defined result but we still have not actually divided by zero.

Why you can't actually divide by a real zero is that it makes maths itself break.

To see why you need to look at what division is. Basically put it is multiplication backwards. If you take a number, say 6 and divide it by 2 you get 3, now if you multiply it by the same number 2 you get back to 6. We say that division is the inverse function of multiplication.

Right, so let's for now pretend that you can divide by zero and you get this number "infinity" as a result: so 1 divided by 0 is infinity and infinity multiplied by 0 must be 1. Except it isn't as anything multiplied by zero is zero.

You could do the same thing with 2 divided by zero, three divided by zero, in fact any number divided by zero Now the same calculation can't have different results as the only way this could happen is if the result of a divide by zero as being every possible number simultaneously; so the correct answer to what do you get when you divide by zero is "the result is undefined".

"Simples" as that irritating meerkat on the telly says.

Mathematics For Dragons

Hello everyone (all two of you who follow my witterings anyway).

This is going to be an offshoot of my normal blog Grumpy Dragon (Warning, adult language, swearing, cursing and stuff) where I'm going to make the occasional post about adding up as I wander through my Open University maths degree.

If you're at the Open University, a student or just interested in sums you might like to have a read. The rest of you will probably be bored witless.