Live data from Hacker News

1/0 = 0 (2018)

hillelwayne.com

191–200 of 245 posts

Re: 1/0 = 0 (2018)

#191

Earlier quoted context omitted.

Division by zero is perfectly well defined in floating point. x/0 = INF and INF*0 = NaN. That means b*(a/b) != a if b = 0. It's true that it's not defined for integer types, but that wouldn't make a = b*(a/b) true for them either. It's also common to define x/0 = infinity in the extended real numbers that floating point models.

TFA was about mathematics, not computer programs. Mathematically, the limit as b approaches 0 of a/b is defined to be +/- INF depending whether a and b have matching signs. The limit represents the value that a/b asymptotically approaches as b approaches 0. a/b for b=0 is still undefined. For a good example of why this needs to be undefined, consider that limit as b approaches zero of a/b is both +INF and -INF depend…

You might have noticed that TFA was discussing a programming language, Pony, that uses floating point. The behavior of the reals isn't relevant.

In the extended reals case I mentioned, it's a definition used when working on the positives. Didn't think I needed to state the obvious.

Re: 1/0 = 0 (2018)

#192

I've always wondered what would happen if we defined /0 as a new symbol, for example 'z'. The same as we define sqrt(-1) as 'i'. So if you can do 4*sqrt(-1)=4i, you could also do 4/0 = 4z. These two seems similar, as in taking something that should not exist, and just letting it exists in a totally different and orthogonal domain. I tried once to investigate the implications, but it quickly became far more complex th…

Since you are composing by multiplication, you can use this symbol: ∞

Re: 1/0 = 0 (2018)

#193

Earlier quoted context omitted.

If I have five apples and were to divide them among 0 people then nobody gets anything and I can eat them all, so the proper solution would be 5.

you can't divide the apples among 0 people and then claim to still have them, because in that case you would have divided them among 1 people

And that's why the answer is 0.

Re: 1/0 = 0 (2018)

#194
post #154
post #69

Earlier quoted context omitted.

Saying 1/0=∞ means creating a new number system with ∞ as a number. Now you have to figure out all operations with ∞, like -1*∞, 0*∞, ∞*∞, ∞/∞, or ∞-∞. Making wrong definitions creates contradictions. With 1*x=x, ∞/∞=1, the associative property x*(y/z)=(x*y)/z, and ∞*∞=∞: ∞ = ∞*1 = ∞*(∞/∞) = (∞*∞)/∞ = ∞/∞ = 1

that's largely solved problem. ieee758 defines consistent rules for dealing with infinities. even if don't use the floating-point parts and made a new integer format, it almost certainly would make sense to lift ieee754 rules as-is.

A IEEE754-like arithmetic (transrational arithmetic, or transreal arithmetic) creates new problems due to adding new values. 0*x=0 now requires x≠∞, x≠-∞, and x≠NaN. (x/x)=1 now requires x≠0, x≠∞, x≠-∞, and x≠NaN, so this system doesn't satisfy the field axioms. NaN lacks ordering, so we lose a total order relation.

However, you get cool new results, like x/x=1+(0/x). Definitely some upsides.

Re: 1/0 = 0 (2018)

#195

Maybe division by zero should just not exist. If you actually write 1/0 in a manner that can be discovered through static analysis, that could just be a compile time error. If you compute a zero, and then divide by it… I dunno. Probably what happened was the denominator rounded or truncated to zero. So, you actually have 1/(0+-e), for some type-dependent e. You have an interval which contains a ton of valid values, w…

I think it would be possible and practical to use refinement types to statically prevent all divisions by 0. I think you could also do this to detect and prevent integer overflow.

Re: 1/0 = 0 (2018)

#196

MySQL has ignored math rules for ages as well. 1/0 yields NULL there

What's wrong with that? It's mathematicaly undefined. SQL dialects typically return NULL for erroneous operations. Plus, it's not like it's returning 0 or some other numeric-typed value

If all the inputs to the expression are not null, you should get some not null result so long as your well defined inputs meet other criteria of the expression (in bounds, etc.); I'd consider this a validation question and, failing validation, I'd want an exception. By simply returning NULL, you're really saying something else... that the inputs to the expression are valid, but result in something that cannot be determined. I don't think this is the case in 1/0; an exception is the proper signal since the construction of the expression itself is wrong (or the inputs invalid).

"SQL dialects typically return NULL for erroneous operations." I disagree with this. NULL does not mean erroneous, it simply means the definition is not yet known and therefore cannot be discussed beyond saying you don't know. That could be erroneous, but you don't know yet, all you have is a NULL.

If it's any comfort, I do agree that NULL is better than 0 or some other non-null result. I just don't think it's best and clouds the nature of the expression, the inputs to the expression, and ultimately is an incorrect result.

Also to be fair, MySQL had many more grievous foot-gun data quality issues in the past than this... though these things certainly did make it easier for a non-expert database developer to get something working without blow-up-everything errors.

Re: 1/0 = 0 (2018)

#197

So, how often do devs actually want a `/` that isn't the inverse of multiplication? Trying to calculate... I don't know, how many 2-disk raid6 groups I need to hold some amount of data is an error , not "lol you don't need any". If my queue consumer can handle 0 concurrent tasks, it will take literally forever to finish, not finish instantly.

To be fair, if my queue consumer can handle 0 concurrent tasks, I’d rather it finishes instantly than never.

the other option is not infinite, it's undefined

Re: 1/0 = 0 (2018)

#198
post #147

Earlier quoted context omitted.

The original purpose of defining it to be Nan/INF in floating point was exactly that. You'd do all the work and then check if it was Nan/INF at the end without having to check every intermediate result.

If you want to do all the work at the end, 'exceptions' do exactly that, too.

Throwing an exception in a function normally stops the rest of the work that function would do. That is not the case when using Inf and similar

    > const f = (x) => [x/2, x/0]
    undefined
    > f(10)
    [ 5, Infinity ]

Re: 1/0 = 0 (2018)

#199

Sounds legit, infinity is singular and so is 0. I think one problem is also that division isn't the only mathematical operation which can produce dubious results. E.g. sqrt(x), arctan(x) which have multiple branches which is why there is often a separate arctan2(x, y) to select the correct branch. Oh well and then there's just addition which silently overflows in almost every programming language. Without arbitrary p…

Hilbert's Hotel shows nicely that infinity can't be singular.

Pretty sure this person meant singular as in singularity, not singular as in one.

Re: 1/0 = 0 (2018)

#200
Letting 1/0 = 0 it's fine. but it is an isolated formula (from other field formulas). Mathematics is not about isolated facts.
Post reply on HN