Björn Pollex
Björn Pollex

Reputation: 76778

Why is 0 divided by 0 an error?

I have come across this problem in a calculation I do in my code, where the divisor is 0 if the divident is 0 too. In my code I return 0 for that case. I am wondering, while division by zero is generally undefined, why not make an exception for this case? My understanding why division by zero is undefined is basically that it cannot be reversed. However, I do not see this problem in the case 0/0.

EDIT OK, so this question spawned a lot of discussion. I made the mistake of over-eagerly accepting an answer based on the fact that it received a lot of votes. I now accepted AakashM's answer, because it provides an idea on how to analyze the problem.

Upvotes: 20

Views: 9747

Answers (18)

peridot
peridot

Reputation: 1

When you type in zero divided by zero, there's an error because whatever you multiply zero from will be zero so it could be any number.

Upvotes: -1

Andrew Wang
Andrew Wang

Reputation: 9

0 means nothing, so if you have nothing, it does not imply towards anything to distribute to anything. Some Transit Facilities when they list out the number of trips of a particular line, trip number 0 is usually the special route that is routed in a different way. Typically, a good example would be in the Torrance Transit Systems where Line 2 has a trip before the first trip known as trip number 0 that operates on weekdays only, that trip in particular is trip number 0 because it is a specialized route that is routed differently from all the other routes.

See the following web pages for details: http://transit.torrnet.com/PDF/Line-2_MAP.pdf http://transit.torrnet.com/PDF/Line-2_Time_PDF.pdf

On the map, trip number 0 is the trip that is mapped in dotted line, the solid line maps the regular routing.

Sometimes 0 can be used on numbering the trips a route takes where it is considered the "Express Service" route.

Upvotes: 0

Nighil
Nighil

Reputation: 4129

This is only a Logical answer not a mathamatical one, imagine Zero as empty how can you Divide an empty by an empty this is the case in division by zero also how can you divide by something which is empty.

Upvotes: 0

IanField90
IanField90

Reputation: 171

You may want to look at Dr. James Anderson's work on Transarithmetic. It isn't widely accepted.

Transarithmetic introduces the term/number 'Nullity' to take the value of 0/0, which James likens to the introduction 'i' and 'j'.

Upvotes: 3

bluesmoon
bluesmoon

Reputation: 4320

This is what I'd do:

function div(a, b) {
    if(b === 0 && a !== 0) {
        return undefined;
    }
    if(b === 0 && a === 0) {
        return Math.random;
    }
    return a/b;
}

Upvotes: -1

subanki
subanki

Reputation: 1429

As Andrzej Doyle said:

Anything dived by zero is infinity. 0/0 is also infinity. You can't get 0/0 = 1. That's the basic principle of maths. That's how the whole world goes round. But you can sure edit a program to say "0/0 is not possible" or "Cannot divide by zero" as they say in cell phones.

Upvotes: -7

Tony Breyal
Tony Breyal

Reputation: 5358

The problem is with the denominator. The numerator is effectively irrelevant.

10 / n
10 / 1 = 10
10 / 0.1 = 100
10 / 0.001 = 1,000
10 / 0.0001 = 10,000
Therefore: 10 / 0 = infinity (in the limit as n reaches 0)

The Pattern is that as n gets smaller, the results gets bigger. At n = 0, the result is infinity, which is a unstable or non-fixed point. You can't write infinity down as a number, because it isn't, it's a concept of an ever increasing number.

Otherwise, you could think of it mathematically using the laws on logarithms and thus take division out of the equation altogther:

    log(0/0) = log(0) - log(0)

BUT

    log(0) = -infinity

Again, the problem is the the result is undefined because it's a concept and not a numerical number you can input.

Having said all this, if you're interested in how to turn an indeterminate form into a determinate form, look up l'Hopital's rule, which effectively says:

f(x) / g(x) = f'(x) / g'(x)

assuming the limit exists, and therefore you can get a result which is a fixed point instead of a unstable point.

Hope that helps a little,

Tony Breyal

P.S. using the rules of logs is often a good computational way to get around the problems of performing operations which result in numbers which are so infinitesimal small that given the precision of a machine’s floating point values, is indistinguishable from zero. Practical programming example is 'maximum likelihood' which generally has to make use of logs in order to keep solutions stable

Upvotes: 4

Clair Crossupton
Clair Crossupton

Reputation: 1382

(Was inspired by Tony Breyal's rather good answer to post one of my own)

Zero is a tricky and subtle beast - it does not conform to the usual laws of algebra as we know them.

Zero divided by any number (except zero itself) is zero. Put more mathematically:

 0/n = 0      for all non-zero numbers n.

You get into the tricky realms when you try to divide by zero itself. It's not true that a number divided by 0 is always undefined. It depends on the problem. I'm going to give you an example from calculus where the number 0/0 is defined.

Say we have two functions, f(x) and g(x). If you take their quotient, f(x)/g(x), you get another function. Let's call this h(x).

You can also take limits of functions. For example, the limit of a function f(x) as x goes to 2 is the value that the function gets closest to as it takes on x's that approach 2. We would write this limit as:

 lim{x->2} f(x) 

This is a pretty intuitive notion. Just draw a graph of your function, and move your pencil along it. As the x values approach 2, see where the function goes.

Now for our example. Let:

 f(x) = 2x - 2
 g(x) = x - 1

and consider their quotient:

 h(x) = f(x)/g(x)

What if we want the lim{x->1} h(x)? There are theorems that say that

 lim{x->1} h(x) = lim{x->1} f(x) / g(x) 
                = (lim{x->1} f(x)) / (lim{x->1} g(x))  
                = (lim{x->1} 2x-2) / (lim{x->1} x-1)
                =~ [2*(1) - 2] / [(1) - 1]  # informally speaking...
                = 0 / 0 
                  (!!!)

So we now have:

 lim{x->1} h(x) = 0/0

But I can employ another theorem, called l'Hopital's rule, that tells me that this limit is also equal to 2. So in this case, 0/0 = 2 (didn't I tell you it was a strange beast?)

Here's another bit of weirdness with 0. Let's say that 0/0 followed that old algebraic rule that anything divided by itself is 1. Then you can do the following proof:

We're given that:

 0/0 = 1

Now multiply both sides by any number n.

 n * (0/0) = n * 1

Simplify both sides:

 (n*0)/0 = n 
 (0/0) = n 

Again, use the assumption that 0/0 = 1:

 1 = n 

So we just proved that all other numbers n are equal to 1! So 0/0 can't be equal to 1.

walks on back to her home over at mathoverflow.com

Upvotes: 19

Florin
Florin

Reputation: 1844

Another explanation of why 0/0 is undefined is that you could write:

0/0 = (4 - 4)/0 = 4/0 - 4/0

And 4/0 is undefined.

Upvotes: 1

why not make an exception for this case?

Because:

  • as others said, it's not that easy;)
  • there's no application for defining 0/0 - adding exception would complicate mathematics for no gains.

Upvotes: -1

Christian
Christian

Reputation: 26387

The structure of modern math is set by mathematicians who think in terms of axioms. Having additional axioms that aren't productive and don't really allow one to do more stuff is against the ideal of having clear math.

Upvotes: 2

AakashM
AakashM

Reputation: 63340

This is maths rather than programming, but briefly:

  • It's in some sense justifiable to assign a 'value' of positive-infinity to some-strictly-positive-quantity / 0, because the limit is well-defined

  • However, the limit of x / y as x and y both tend to zero depends on the path they take. For example, lim (x -> 0) 2x / x is clearly 2, whereas lim (x -> 0) x / 5x is clearly 1/5. The mathematical definition of a limit requires that it is the same whatever path is followed to the limit.

Upvotes: 58

Yacoby
Yacoby

Reputation: 55435

Let's say:

0/0 = x

Now, rearranging the equation (multiplying both sides by 0) gives:

x * 0 = 0

Now do you see the problem? There are an infinite number of values for x as anything multiplied by 0 is 0.

Upvotes: 76

user128300
user128300

Reputation:

If a/b = c, then a = b * c. In the case of a=0 and b=0, c can be anything because 0 * c = 0 will be true for all possible values of c. Therefore, 0/0 is undefined.

Upvotes: 0

Pontus Gagge
Pontus Gagge

Reputation: 17258

Since x/y=z should be equivalent to x=yz, and any z would satisfy 0=0z, how useful would such an 'exception' be?

Upvotes: 1

tovare
tovare

Reputation: 4087

Here's a full explanation:

http://en.wikipedia.org/wiki/Division_by_zero

( Including the proof that 1 = 2 :-) )

You normally deal with this in programming by using an if statement to get the desired behaviour for your application.

Upvotes: 5

Will A
Will A

Reputation: 24988

How many times does 0 go into 0? 5. Yes - 5 * 0 = 0, 11. Yes - 11 * 0 = 0, 43. Yes - 43 * 0 = 0. Perhaps you can see why it's undefined now? :)

Upvotes: 1

zvrba
zvrba

Reputation: 24546

Look at division in reverse: if a/b = c then c*b = a. Now, if you substitute a=b=0, you end up with c*0 = 0. But ANYTHING multiplied by zero equals zero, so the result can be anything at all. You would like 0/0 to be 0, someone else might like it to be 1 (for example, the limiting value of sin(x)/x is 1 when x approaches 0). So the best solution is to leave it undefined and report an error.

Upvotes: 3

Related Questions