On Tue, Nov 24, 2020 at 9:32 AM Steven D'Aprano
On Tue, Nov 24, 2020 at 08:32:21AM +1100, Chris Angelico wrote:
On Tue, Nov 24, 2020 at 8:26 AM Wes Turner
wrote: Is there a different IEEE spec or CAS that distinguishes between 1/x and 2/x where x=0?
assert 1/0 != 2/0 != math.inf/0
No, why should there be? There is absolutely no difference between them mathematically.
If we are talking about the standard real number system that we all know and love, there certainly is.
Under the Reals, it is meaningless to say that 1/0 even exists. So we have to be talking about limits for the question to even make sense.
2/x is always twice the size of 1/x regardless of what x is
Correct
so there is always a difference between them:
Not correct. Once you start looking at infinities, these base intuitions no longer hold. For example, one definition of the size of an infinite set is the ability to create a bijection [1]. You can easily create a bijection between the even positive integers and the counting numbers: 2 * n <=> n and it's pretty clear that, for any counting number n, you can find a positive even number 2*n that corresponds to it - and, equivalently, that every even positive number, when halved, will give the corresponding counting number. That means that the total number of even positive numbers (the cardinality) is the same as the total number of counting numbers. And you can do the same for odd numbers: 2 * n - 1 <=> n Which means there are as many counting numbers as there are odd numbers. The exact same cardinality. So when you combine the set of even numbers and the set of odd numbers, you're combining two sets of numbers each with cardinality identical to the counting numbers - and the combined set IS the set of counting numbers. Meaning that doubling that number gives... the same number. If "infinity" is a number, then "2 * infinity" is the same number.
So there is that difference. How about the limits?
We can't say that it is "infinity" because infinity isn't a real number. In the real numbers, "the limit is infinity" is nonsense. Admittedly it is commonly said nonsense, but if we want to be correct and precise, we should say that it "increases without limit".
Negative numbers are nonsensical if you assume that all numbers have to correspond to some form of reality. For instance, if I have a bag with -3 apples in it, and I put 5 more in, then take 4 out, I would have to put 2 more apples into the bag for it to be empty. That's utter nonsense, yet we do arithmetic on negative numbers all the time. Infinity is a concept that isn't actually a number per se, but can be reasoned about logically and rigorously.
If you take the limit of 1/x as x approaches zero, we get a discontinuity:
- as x approaches zero from below, 1/x is *negative*, with magnitude increasing without limit;
- but as x approaches zero from below, 1/x is *positive*, with magnitude increasing without limit.
So the two limits are not only different, but they are as different as it is possible to get. They are as far apart as it is possible to get!
So even if we count "infinity" as a value, there is still no single value that could represent the limit of 1/x as x approaches 0.
Which is why IEEE also has the concept of negative zero, for when you're approaching from the negative side.
We should consider that the IEEE-754 result for division by zero represents the case of the denominator underflowing to zero, but is "really" a microscopically tiny positive or negative value, then the result overflows to the appropriately signed infinity.
There's no way in IEEE-754 to perform 1/0 where the 0 represents actual zero (rather than a quantity that underflowed to 0), which should give a NAN.
If you restrict yourself to counting numbers, many calculations (such as "5 - 8") result in "no answer possible". Thus we have negative numbers. If you restrict yourself to integers, many calculations (such as "how many threes are there in five") result in "no answer possible". Thus we have rationals and reals. If you restrict yourself to reals, many calculations (such as "what number, when multiplied by itself, makes negative four?") result in "no answer possible". Thus we have complex numbers. And if you restrict yourself to finite numbers, the same thing applies. Infinity isn't any more weird than, let's face it, *every other number*. With the possible exception of counting numbers, which derive fairly closely from reality, everything relating to mathematics is the result of finding useful rules that allow us to perform useful calculations. Mathematics is heavily based on a pragmatism (just as Python is) wherein, if something helps us solve real problems, we accept it. I tried to find a really good 3blue1brown video on the subject, but the best I could come up with is this fairly old one: https://www.youtube.com/watch?v=XFDM1ip5HdU Perhaps someone else has a better explanation of infinities. ChrisA [1] eg see Wikipedia https://en.wikipedia.org/wiki/Bijection