Live data from Hacker News

1/0 = 0

hillelwayne.com

431–440 of 593 posts

Re: 1/0 = 0

#431

Hi, I'm on the Pony core team. I will be writing in more detail about this decision. A few short notes until then: 1) no one on the team has ever been happy with ending up here, understanding why the decision was made involved understand how partial functions (one that can produce errors like division by zero) are handled in Pony and interesting ergonomic issues that can result that is a large part of what my post wi…

>2) this applies only to integer division wherein division by zero is undefined. 1.0/0.0 uses the available Infinity value.

Ah, that seems rather reasonable. For whatever reason, the OP had me thinking that Pony was replacing the ordinary semantics of IEEE 754 floating point division (probably because he talked about fields and multiplicative inverses).

Having 1/0 = 0 seems like a very reasonable choice, especially if you have 1%0 = 1 as well. Of course, if anyone thinks they will actually encounter division by 0 in their code, and needs to treat it as an error, they can always test for it.

Re: 1/0 = 0

#432

Earlier quoted context omitted.

Integers are perfectly fine in math. But they are not a field. Integers modulo something are also well understood in math - but again not a field.

Integers modulo any prime are a field.

Powers of 2 are not a prime though, unless the power is 1 (i.e. we are dealing with single-bit integers).

Re: 1/0 = 0

#433

Earlier quoted context omitted.

Well, except for kernel panics and hardware errors...

You can write user code in Pony that will cause a kernel panic or hardware error?

> You can write user code in Pony that will cause a kernel panic or hardware error?

You can always (as in OS with lazy allocation) allocate enough memory to get OOM no matter how safe your language is.

Re: 1/0 = 0

#435

Earlier quoted context omitted.

1/0 is not infinity either...

If we assume that we got to 0 because of a rounding error we do know that it should be some positive integer. I think that 1/0 = infinity is a reasonable substitute for an actual value. 1/0 = 0 seems absurd. 1/(a number approaching 0) produces ever increasing integers. I don't know, does it even matter? What happens when you try to divide a physical object into 0 parts? It doesn't create infinite pieces. It doesn't m…

>If we assume that we got to 0 because of a rounding error we do know that it should be some positive integer.

That's assuming we had rounding error from a positive number, not a negative number. Of course, if you are concerned about rounding, you shouldn't be using integer arithmetic.

>1/(a number approaching 0) produces ever increasing integers.

No. It produces a bunch of 0s, except when the denominator is 1 (where it produces 1) or the denominator is -1 (where it produces -1). Unless you're using a language like Python, in which case it produces -1 for all negative denominators.

Re: 1/0 = 0

#436
post #60

Some people say "oh, that's easy, 1/0 is +Infinity". So the real fun is at 0/0. The limit of x/y as x and y go to zero depends on which path across the xy plane you take towards the singularity. Along one approach, the limit is 0, along another approach the limit diverges to infinity, along yet another the limit is 17. I'm not kidding! Go to https://www.geogebra.org/3d and enter "x/y" and spin the graph around. The "…

I like your point here. I think 1/0 = Infinity+ is a satisfying expression. Its a clear concept which can be visualized in a simple graph. I think 0/0 is a different concept than 1/0. It's a different expression. 0/0 doesn't explicitly express a particular "path" on the graph. We can call it (0/0) different names if we want. They can say 0/0 = "undefined". I am currently satisfied with 0/0 simply equals to 0/0, or si…

>I like your point here. I think 1/0 = Infinity+ is a satisfying expression. Its a clear concept which can be visualized in a simple graph.

Except it isn't. It still depends on which side you take the path from - from the positive denominator or the negative denominator side. (This is why IEEE 754 has a single signless infinity).

Re: 1/0 = 0

#437
post #72

My problem with "1/0 = 0" is that it's essentially masking what's almost always a bug in your program. If you have a program that's performing divide-by-zeroes, that's almost surely something you did not intend for. It's a corner case that you failed to anticipate and plan for. And because you didn't plan for it, whatever result you get for 1/0 is almost surely a result that you wouldn't want to have returned to the…

My comment from when this came up on Reddit, slightly edited for context: `/`-by-0 is just an operation and it tautologically has the semantics assigned to it. The question is whether the specific behaviour will cause bugs, and on glance that doesn't sound like it would be the case. Principally, division is normally (best guess) used in cases where the divisor obviously cannot be zero; cases like division by constant…

An example well-defined use case is if you want to compute a harmonic mean, e.g.

x = 2/(1/a +1/b)

This is a form of average where you are giving increased importance to the smaller number. It frequently pops up in science/engineering, e.g. in hydrology when you are computing flow of water underground.

In this case, it's "obvious" that when e.g. a is zero, you want 1/a to be zero so you simply return b. There's typically a clear, big distinction between "smallest realistic number", for instance 1e-3, and a zero, whether actual zero or 1e-34.

For instance Numpy offers a nice way of doing this:

  def safeInv(a):
    tol = 1e-16
    return np.division(1.0,a,out=np.zeros_like(a),where=np.where(a>tol))
This tells numpy to put the result of division into an array of zeros shaped like a, but only do the divide where a>tol, so it returns 0 where aIn this case, though, the programmer understands this division is somehow special and should allow div-by-zero, so it is handled specially.

Re: 1/0 = 0

#438
1/0=0 is basically crack for the HN crowed, I knew it as soon as I saw it, just 5 little characters would drive people into the mouth of madness.

It's like WWE Raw Smackdown, Hulk Hogan vs. The Rock and everyone has to take a side.

And it's literally Friday night.

Sorry we're not supposed to comment like this buy y'all (I suppose 'we') are a really funny bunch sometimes.

Re: 1/0 = 0

#439
post #340

Earlier quoted context omitted.

Look at it this way... Standard definition of division function, d: d(x, y) = x * y⁻, for all x and y EXCEPT 0 Author's modified, piecewise ( https://en.wikipedia.org/wiki/Piecewise ) definition: d(x, y) = x * y⁻, for all x and y EXCEPT 0 d(x, y) = 0, for y = 0 He's just adding 0 to the domain of d(x, y) to extend the definition, and deliberately not using xy⁻ for that particular element of the domain. No inverse nee…

I know what he's doing. The problem is when you make it a different function (even by just extending it) then you change its equational properties. So equational properties that held over the whole domain of the function no longer hold over the extended domain. This is repaired by modifying the equational properties. But the modified equational properties mean that you now have a different system than before. So the…

[deleted]

Re: 1/0 = 0

#440
post #60

Some people say "oh, that's easy, 1/0 is +Infinity". So the real fun is at 0/0. The limit of x/y as x and y go to zero depends on which path across the xy plane you take towards the singularity. Along one approach, the limit is 0, along another approach the limit diverges to infinity, along yet another the limit is 17. I'm not kidding! Go to https://www.geogebra.org/3d and enter "x/y" and spin the graph around. The "…

I would argue 1/0 is infinity. Not with mathematics, just logically. By using the wording "how many times does 0 go into 1?" You bring up 0/0. But 0/ is already defined, it's 0. So 0/infinity = 0 Programmatically, I think I've always wanted X/0 to be 0. For example: progress bars, currency, or damage in a video game. It wouldn't be very helpful to have infinity be an answer there.

In float yes. In int there's no Inf. There's only MAX_INT or 0 or throw an exception.

Normal langs throw. That what the checked int div will do. But the unchecked int div has no return type which allows throwing an error. And pony is strongly typed, unlike most other langs. That's why it can guarantee much more safeties and performance than all other languages.

Post reply on HN