New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Division by zero mathematical inconsistencies #932

Closed
fcabouat opened this Issue Dec 28, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@fcabouat

fcabouat commented Dec 28, 2017

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

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Dec 28, 2017

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.

process-bot commented Dec 28, 2017

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.

@bitamar

This comment has been minimized.

Show comment
Hide comment
@bitamar

bitamar Dec 29, 2017

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.

bitamar commented Dec 29, 2017

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.

@fcabouat

This comment has been minimized.

Show comment
Hide comment
@fcabouat

fcabouat Dec 29, 2017

-(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 ?

fcabouat commented Dec 29, 2017

-(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 ?

@fcabouat

This comment has been minimized.

Show comment
Hide comment
@fcabouat

fcabouat Feb 11, 2018

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.

fcabouat commented Feb 11, 2018

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.

@fcabouat fcabouat closed this Feb 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment