Live data from Hacker News

1/0 = 0

hillelwayne.com

111–120 of 593 posts

Re: 1/0 = 0

#111
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 always thought division by zero was, at best, + and - infinity, depending on the path, which is why we leave it undefined. How would a path lead to 17?

24 / 2

17 / 1

1.7 / 0.1

0.17 / 0.01

0.017 / 0.001

...

0 / 0

Re: 1/0 = 0

#112

Earlier quoted context omitted.

> You’re doing something different than real number arithmetic Computer languages execute on rules that are not utilizing real number arithmetic. I didn't want to mention it, but there's these things called floats... Edit: Pony took out the "normal" version of division by zero and suggest to write a wrapper to check beforehand.

Where did I say anything about computers? I’m referring to real numbers.

The topic is a computer language. I'm referring to utility.

Re: 1/0 = 0

#113
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 always thought division by zero was, at best, + and - infinity, depending on the path, which is why we leave it undefined. How would a path lead to 17?

Take the limit as x goes to 0 of (17*x)/(x). Both numerator and denominator go to 0, so this is a representation of 0/0. The limit is then equal to 17.

Re: 1/0 = 0

#114
post #88

Earlier quoted context omitted.

Were are speaking of integers here not FP numbers.

Not to be pedantic, but one of the author's own examples involves pi inverse, so I think discussing FP numbers is valid.

Yes I know, but in the context of Pony, 1/0==0 only applies to integers, not FP numbers. The article doesn't make it clear.

Re: 1/0 = 0

#115

Earlier quoted context omitted.

I think OP means that nothing breaks mathematically. It is not inconsistent and not false, so you can work with it. The only issue is to deal specially with the case of division by zero, which you have to do anyways. Code that assumes that (x/y) * y = x is wrong if you don't check for y = 0, independently of what you define x/0 to be.

It is inconsistent. If 1/0 = 0, then 1 = 0*0.

It's not inconsistent. See this article [1] for an explanation. It's the first thing covered in the "Objections" section.

[1] https://www.hillelwayne.com/post/divide-by-zero/

Re: 1/0 = 0

#116
post #97

So... if I do: x = a/b + c/d + e/(f*g/h) I need to check: if(b == 0 || d == 0 || f == 0 || g == 0) rather then: if(isFinite(x)) Or whatever function/equality check is appropriate, or a try/catch if it throws an exception. I have to say that using a single check on the result seems significantly less prone to bugs then having to check all the values that could produce an invalid result.

Without NaN you don't get to see that the computation "went wrong". But that's not necessarily a problem, and only if it is must you check whether those inputs are zero.

Still, I agree that a NaN value(s) is(are) preferable for this reason.

Re: 1/0 = 0

#117
post #88

Earlier quoted context omitted.

Were are speaking of integers here not FP numbers.

Not to be pedantic, but one of the author's own examples involves pi inverse, so I think discussing FP numbers is valid.

floating point numbers in Pony follow the standard and return Infinity for division by zero. integer division by zero is undefined behavior and something each programming language has to decide how to handle.

Re: 1/0 = 0

#118
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 always thought division by zero was, at best, + and - infinity, depending on the path, which is why we leave it undefined. How would a path lead to 17?

  x=170, y=10
  x=17, y=1
  x=1.7, y=0.1
  x=0.17, y=0.01
The answer keeps being 17, even as x and y both get vanishingly close to zero.

I encourage you to play around with a 3D graphing calculator and see all the different paths you can take along that surface to reach the singularity. They all "reach" it at different heights.

Re: 1/0 = 0

#119
post #57

> But is Pony doing something unsound? Absolutely not. It is totally fine to define 1/0 = 0. Nothing breaks a=x/N b=y/N If a==b, then x==y No longer true, with this change. Essentially a variety of mathematical properties of numbers in the Real space don't hold when you allow division by 0.

This is not true if you say division by 0 is undefined or +inf either. It really is totally fine.

Re: 1/0 = 0

#120
Meanwhile, in Python v3.7.0...

      >>> 1 / 0
      Traceback (most recent call last):
        File "", line 1, in 
      ZeroDivisionError: division by zero
      >>> 0 / 0
      Traceback (most recent call last):
        File "", line 1, in 
      ZeroDivisionError: division by zero
      >>> 1 / 0.0
      Traceback (most recent call last):
        File "", line 1, in 
      ZeroDivisionError: float division by zero
      >>> 0.0 / 0.0
      Traceback (most recent call last):
        File "", line 1, in 
      ZeroDivisionError: float division by zero
Meanwhile, in Elixir v1.7.1...

      iex(1)> 1 / 0
      ** (ArithmeticError) bad argument in arithmetic expression: 1 / 0
          :erlang./(1, 0)
      iex(1)> 0 / 0
      ** (ArithmeticError) bad argument in arithmetic expression: 0 / 0
          :erlang./(0, 0)
      iex(1)> 1.0 / 0.0
      ** (ArithmeticError) bad argument in arithmetic expression: 1.0 / 0.0
          :erlang./(1.0, 0.0)
      iex(1)> 0.0 / 0.0
      ** (ArithmeticError) bad argument in arithmetic expression: 0.0 / 0.0
          :erlang./(0.0, 0.0)

Meanwhile, in Ruby v2.5.1...

      irb(main):001:0> 1 / 0
      Traceback (most recent call last):
              3: from /Users/mpope/.rbenv/versions/2.5.1/bin/irb:11:in `'
              2: from (irb):1
              1: from (irb):1:in `/'
      ZeroDivisionError (divided by 0)
      irb(main):002:0> 0 / 0
      Traceback (most recent call last):
              3: from /Users/mpope/.rbenv/versions/2.5.1/bin/irb:11:in `'
              2: from (irb):2
              1: from (irb):2:in `/'
      ZeroDivisionError (divided by 0)
      irb(main):003:0> 1 / 0.0
      => Infinity
      irb(main):004:0> 0.0 / 0.0
      => NaN
Meanwhile, in PHP v7.0.8...

      > echo 1 / 0;
      >
      INF
      Division by zero :1
      > echo 0 / 0;
      >
      NAN
      Division by zero :1
      > echo 1 / 0.0;
      >
      INF
      Division by zero :1
      > echo 0.0 / 0.0;
      >
      NAN
      Division by zero :1
Meanwhile, in Node v10.7.0...

      Infinity
      > 1 / 0
      Infinity
      > 0 / 0
      NaN
      > 1 / 0.0
      Infinity
      > 0 / 0.0
      NaN
Post reply on HN