elm/core

Division by zero mathematical inconsistencies

Closed this issue · 4 comments

Hi,

In Elm repl I get :

-1 / 0 == 1 / -0
False : Bool

Which is a bit weird mathematically and comes from the fact that 1 / 0 gives Infinity where it should (imho) give NaN.

cheers,

François

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

Hi @fcabouat,
I don't find it inconsistent - Division by zero is either infinity, or -infinity, so if "-0" is the same as 0, that's the expected result. I.e -1 / 0 is -Infinity and 1 / 0 is Infinity.

-(1 / x) == -1 / x == 1 / -x for every x != 0. Breaking that rule for x = 0 is indeed an inconsistency.

At least in real numbers space dividing by zero is a mathematical error / is undefined. It's not equal to Infinity or -Infinity. Otherwise, it would lead to -Infinity == Infinity. Is it what you're proposing ?

What about Elm's policy of making errors explicit / forcing the programmer to handle those errors in a type safe way ?

After some research, it appears I'm not the only one to cringe about this mathematical inconsistency.
Anyway, since the same behavior can be seen in Haskell & al and has been standardized in IEEE 754, I guess t wouldn't be much wiser to go against the standard.

Leaving https://stackoverflow.com/questions/9354016/division-by-zero-in-haskell as a reference and closing the issue.