Live data from Hacker News

1/0 = 0

hillelwayne.com

61–70 of 593 posts

Re: 1/0 = 0

#61

This article grinds my gears. He quotes a number of mathematicians that correctly state the undefined nature of 1/0. Then proceeds to interpret that this means that we can choose any specific value to represent as 1/0 that we want. NO. We have "NaN" for a reason and it is an important signal to the programmer that a mistake was made. The language that assigns it to 0 silently is bunk as is this article.

> correctly state the undefined nature of 1/0 Erm, when we say it's "undefined" we mean it literally -- standard mathematical systems of arithmetic do not define a value for that division. If you make another system of arithmetic you can define it how you want and be consistent with "regular maths" for the operations in which things are defined. It's an extension. > We have "NaN" for a reason Funnily enough, IEEE754…

> Defining it as 0 at least means floating point numbers are (presumably) closed under arithmetic operations, which could be handy.

They already are closed. Floating point includes Inf and Nan for that reason. :-)

Re: 1/0 = 0

#62

This article grinds my gears. He quotes a number of mathematicians that correctly state the undefined nature of 1/0. Then proceeds to interpret that this means that we can choose any specific value to represent as 1/0 that we want. NO. We have "NaN" for a reason and it is an important signal to the programmer that a mistake was made. The language that assigns it to 0 silently is bunk as is this article.

IMHO I think the problem here is that most people focus on the "wrong side" of 1/0.

I mean, what the mathematical definition of division says is not that 1/0 is indeed something and that that something is "undefined" or "NaN" or anything else really. What it says is "I cannot do 1/0, the division operation a/b does not apply when b is 0".

So 1/0 is not a thing in itself in mathematics; it's something which cannot be operated.

Now, back some time ago, "division by zero" simply threw an error. It signaled "this is not something that can be done". undefined, NaN, anything else, including 0, is not really something that has a mathematical justification. It's merely a practical approach to encapsulate that error into some form of pseudo-value to control it to some extent.

Personally, I don't really see how 1/0 = 0 is better than 1/0 = NaN or "undefined" or "Infinity".

Re: 1/0 = 0

#63

Earlier quoted context omitted.

I used to think the same way: let's throw an exception on divide by zero, and forget NaN like a bad dream! But then someone explained to me that it's common to feed a billion numbers into a long calculation, then look at the results in the morning and find them okay, apart from a few NaNs. If each NaN led to an exception, you'd come back in the morning and find that your program has stopped halfway through. So there'…

Typically, divide by zero throws for integers because they can’t express NaN, which can instead be returned for floating point. In any case, integers can’t express special values, so you get exceptions instead. And this is actually defined at the processor level (for x86 among others), the trap is free (well, a sunk cost), why not take it? Zero is not a very good NaN.

Yeah, agreed. The thing with 1/0=0 is bizarre, I guess my comment was more about why NaNs are okay.

Re: 1/0 = 0

#64
Unlike what the author says, this is the total opposite to a practical/pragmatic solution.

He does not prove that this is a useful representation, only that given his own axioms, this can be considered mathematically correct.

Very practical issues with 1/0 == 0:

- This result is counter-intuitive, took building a custom fields and responding to the incredulity of all. - The main reason this is counter-intuitive is not mentionned in the post: division is no longer monotonous.

1/0.5 = 2 1/0.25 = 4 1/0.0001 = 10000 1/0 = 0

This is calling for an Ariane 5-type crash because an underflow error caused a value to suddenly fall from 10e6 to 0.

Re: 1/0 = 0

#65
post #43
post #25

Earlier quoted context omitted.

If a hn title said 1*0=0 could you reply "Oh, so 1=0/0?" The entire point of the article was suggesting you can define a consistent system without multiplication and division being entirely symmetrical (as they already are not)

> without multiplication and division being entirely symmetrical (as they already are not) What do you mean?

[deleted]

Re: 1/0 = 0

#66
post #20

Earlier quoted context omitted.

> the many pieces of code that assume that (x / y) * y equals x The same issue if division by zero throws an exception. This is simply a more practical approach that dispenses with the exception handling (ie becomes a less irregular test case). Edit: Not buggy behavior, when expected.

I would say an exception is much more convenient. Buggy code that silently continues to run is very hard to debug!

What of a language without exceptions? A correct program can not assume that (x / y) * y = x because such an equality does not hold in general. Therefore the program must do something right in the case that y is zero before it tries dividing x by y to be correct. It shouldn’t really matter what x / 0 is because if a program relies on its value then it is probably wrong.

Re: 1/0 = 0

#68
This thread is showing once again that reading comprehension is not our strong-suit here on HN.

The author does not once say that Pony's choice is a good one, only that whether it is a good or bad one should be settled by engineering consequences, and that there is no purely mathematical argument that precludes it.

I can't help but think it _is_ a bad idea, because it's easier to overlook a 0 appearing than a NaN. That argument isn't math, though.

Re: 1/0 = 0

#69
My math is rusty but 1 / 0 := 0 implies that 0 * 0 := 1. This contradicts the definition of a binary field [1], let alone a field of real numbers.

[1] https://en.wikipedia.org/wiki/GF(2)

> "It is totally fine to define 1/0 = 0."

No, it's not, at least not useful. If you define it that way, you will not have a field. Then you don't have +, -, *, and / operations with the commonly assumed behavior. However, it is definitely possible to define some operation such that 1 `op` 0 := 0, just not the inverse operation of multiplication.

Re: 1/0 = 0

#70

What proportion of the time will a programmer intend and expect 1/0 = 0? What proportion of the time will a divide-by-zero operation be a symptom of a bug, where evaluating 1/0 as any valid number will make it harder to identify that bug? There might be a mathematical justification for 1/0 = 0, but the computer science justification seems tenuous at best. The overwhelming majority of the time, I want divide-by-zero t…

We’re talking here about integer math. Integer math on CPUs is usually fast at the expense of having coherent semantics. It isn’t even really “integer” math in any mathematical sense. It’s just “the fastest math that the CPU is capable of doing, which happens to look a lot like integer math most of the time.”

If you’re dividing floats, you will get NaN or Infinity as expected. Just like how, if you overfloat a float, you’ll get Infinity. Floating-point has well-defined semantics, which CPUs are required to adhere to, and languages just expose.

If you divide “CPU integers” by (CPU integer) 0, the result is undefined. Just like how, if you overflow a “CPU integer”, the result is undefined. There is no standard semantics being adhered to. There is no equivalent of IEEE754 for CPU integers. There is only convention, and convention has no universal answer at these edge-cases. Thus, a language is free to do whatever it wants in response to either. There are no formal semantics to expose.

Usually, a language that calls itself “safe” will choose to make CPU integers behave a lot like real integers, by generating checks and throwing exceptions for the edge cases.

And usually, a language that calls itself “low-level” will just expose whatever semantics the CPU integers of its host platform already possess. In the case where there’s still an impedance mismatch (i.e. in the case of division by CPU-integer-0 where you don’t actually get any output into a result register), the language has to make something up. To “go with the flow” of how CPU integers work, probably it should be something fast.

Thus, 1/0=0 kinda sorta makes sense. It is an operation on the field of “CPU integers” that vaguely “fits in” with the existing ones. No mathematical relevance, but just fine from the perspective of someone e.g. seeking to create a higher-level abstract machine targeting the Pony compiler, where you’d still just insert a divisor check before doing the division op if you wanted the result to make any sense.

Post reply on HN