Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Division #154

Open
treeowl opened this issue Nov 11, 2016 · 5 comments
Open

Division #154

treeowl opened this issue Nov 11, 2016 · 5 comments
Labels
C - design design stuff

Comments

@treeowl
Copy link

treeowl commented Nov 11, 2016

The Prelude erred, I believe, in offering machine division (quotRem) and Knuthian division (divMod) as the standard division operations. I think we want to keep Knuthian division around for the situations where it's appropriate, but give a very nice name to "Euclidean" division, which guarantees a non-negative remainder.

@vincenthz vincenthz added the C - design design stuff label Nov 11, 2016
@vincenthz
Copy link
Member

vincenthz commented Nov 11, 2016

I agree. My current thinking is that Prelude.divMod is very seldom useful (unless in specific domains maybe), and it would make sense to just hide this in a Math module [1], just like with the trigonometry stuff (cos,sin,etc that have moved to Foundation.Math.Trigonometry).

Also, I think quot and rem are not very good name to expose by default, and (much less strongly) I'm not sure about div and mod either.

  • Any idea about naming all this ? I'm not that keen on IDivisible in the first place
  • Any alternative to expose the integral divisions ?

@snowleopard
Copy link

snowleopard commented Nov 19, 2016

Edit: I support the proposal, see the next comments that point out my previous misunderstanding of the terms. Below is my original comment.


My opinion is that integer division a/b should follow the standard mathematical definition: if b is non-zero, then there are unique integers q (quotient) and r (remainder) s.t. a = q * b + r and 0 ≤ r < |b|.

I believe @treeowl refers to this as Knuthian division, but I'm not sure why -- as far as I know this is a commonly accepted definition in mathematics. Many programming languages get it wrong though.

Also mod is a standard mathematical notation.

@treeowl
Copy link
Author

treeowl commented Nov 19, 2016

No, that's what I called Euclidean. Knuthian is the Prelude div/mod.

On Nov 19, 2016 4:03 PM, "Andrey Mokhov" [email protected] wrote:

My opinion is that integer division a/b should follow the standard
mathematical definition: if b is non-zero, then there are unique integers
q (quotient) and r (remainder) such that a = q * b + r and 0 ≤ r < |d|.

I believe @treeowl https://github.com/treeowl refers to this as Knuthian
division
, but I'm not sure why -- as far as I know this is a commonly
accepted definition in mathematics. Many programming languages get it wrong
though.

Also mod is a standard mathematical notation.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#154 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABzi_YCQhbO3ehjn0nSCkFqoFts7cJ5Cks5q_2QXgaJpZM4KvfoN
.

@snowleopard
Copy link

@treeowl Ah, I'm sorry, my mistake. To my embarrassment I didn't realise that Knuth's definition was different from the standard mathematical one, which apparently is referred to as Euclidean :-)

I fully support your proposal: the Euclidean division should be the default/easiest to write.

@vincenthz
Copy link
Member

vincenthz commented Nov 20, 2016

There's no division currently in prelude that guarantee a positive remainder. I think it would make sense to define use-case i.e. what does it mean when a is X, and b is Y.

The only thing everyone agree and is a given is:

  • a is positive, and b is strictly positive

@snowleopard: mod is a standard mathematical notation but is not defined a -> a -> a. more accurately it would be a -> NonZero Natural -> a.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C - design design stuff
Projects
None yet
Development

No branches or pull requests

3 participants