Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
That how I was taught to round in school, so it doesn't seem at all unusual to me. 2009/7/23 Matthias Görgens matthias.goerg...@googlemail.com: Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is odd. This is sometimes known as banker's rounding. OK. That's slightly unusual indeed. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
Matthias Görgens schrieb: Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is odd. This is sometimes known as banker's rounding. OK. That's slightly unusual indeed. Modula-3 makes it too. Accidentally, I recently had a case where this rounding mode was really bad. I wanted to reduce pictures by arbitrary factors and for the sake of speed it was enough to just move the pixels from the source to their target position and don't do any interpolation. However for factor 2 reduction I got ugly patterns, because pixels accumulated around even target coordinates. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
2009/7/23 Matthias Görgens matthias.goerg...@googlemail.com: Couldn't the same be said for round-to-even, instead of rounding down like every other language? I doubt any beginners have ever expected it, but it's probably better. What do you mean with round-to-even? For rounding down there's floor. Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is odd. This is sometimes known as banker's rounding. The most common alternative is round-half-up. --Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is odd. This is sometimes known as banker's rounding. OK. That's slightly unusual indeed. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
On 23 Jul 2009, at 11:59, Matthias Görgens wrote: Round-to-even means x.5 gets rounded to x if x is even and x+1 if x is odd. This is sometimes known as banker's rounding. OK. That's slightly unusual indeed. It's meant to minimise total rounding error when rounding over large data sets; there's some discussion on wikipedia: http://en.wikipedia.org/wiki/Rounding ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Simple quirk in behavior of `mod`
Nathan Bloomfield wrote: Hello haskell-cafe; I'm fiddling with this http://cdsmith.wordpress.com/2009/07/20/calculating-multiplicative-inverses-in-modular-arithmetic/ blog post about inverting elements of Z/(p), trying to write the inversion function in pointfree style. This led me to try executing statements like n `mod` 0 which in the ring theoretic sense should be n, at least for integers*. (MathWorld agrees. http://mathworld.wolfram.com/Congruence.html) I agree that (n `mod` 0) ought to be n. Specifically divMod n 0 = (0,n) and quotRem n 0 = (0,n) In (divMod n m) the sign of the remainder is always the same as the sign of m, unless n or m is zero. In (quotRem n m) the sign of the quotient is the product of the signs of n and m, unless n or m is zero. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
There are two ways of looking at the mod operator (on integers): 1. As a map from the integers Z to Z/pZ. Then n mod p is defined as: n mod p = { k | k in Z, k = n + ip for some i in Z } Instead of the set, we ususally write its smallest nonnegative element. And yes, in that sense, Z/0Z gives: n mod 0 = { k | k in Z, k = n } = { k } =~ k 2. As the remainder under division by p. Since n mod 0 would be the remainder under division by 0, this correctly gives a division by zero error. I used to think that the definitions were equivalent... apparently not. Thomas On Wed, Jul 22, 2009 at 10:05, Chris Kuklewiczhask...@list.mightyreason.com wrote: Nathan Bloomfield wrote: Hello haskell-cafe; I'm fiddling with this http://cdsmith.wordpress.com/2009/07/20/calculating-multiplicative-inverses-in-modular-arithmetic/ blog post about inverting elements of Z/(p), trying to write the inversion function in pointfree style. This led me to try executing statements like n `mod` 0 which in the ring theoretic sense should be n, at least for integers*. (MathWorld agrees. http://mathworld.wolfram.com/Congruence.html) I agree that (n `mod` 0) ought to be n. Specifically divMod n 0 = (0,n) and quotRem n 0 = (0,n) In (divMod n m) the sign of the remainder is always the same as the sign of m, unless n or m is zero. In (quotRem n m) the sign of the quotient is the product of the signs of n and m, unless n or m is zero. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
Thomas ten Cate schrieb: There are two ways of looking at the mod operator (on integers): 1. As a map from the integers Z to Z/pZ. [...] 2. As the remainder under division by p. Since n mod 0 would be the remainder under division by 0, this correctly gives a division by zero error. I used to think that the definitions were equivalent... apparently not. They are if you don't disallow division by zero with remainder. Namely, the definition of “division with remainder” works as in (1). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Simple quirk in behavior of `mod`
Is the utility of having (n `mod` 0) return a value greater than the confusion it will engender? In the 99.99% case it's an error. You wouldn't want (n `div` 0) to return 0, I expect.If we want these number-theoretic mod and div operations let's please put them in a separate module. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
On Wed, Jul 22, 2009 at 1:34 PM, gladst...@gladstein.com wrote: Is the utility of having (n `mod` 0) return a value greater than the confusion it will engender? In the 99.99% case it's an error. You wouldn't want (n `div` 0) to return 0, I expect. If we want these number-theoretic mod and div operations let's please put them in a separate module. Couldn't the same be said for round-to-even, instead of rounding down like every other language? I doubt any beginners have ever expected it, but it's probably better. Jeff Wheeler ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Simple quirk in behavior of `mod`
Couldn't the same be said for round-to-even, instead of rounding down like every other language? I doubt any beginners have ever expected it, but it's probably better. What do you mean with round-to-even? For rounding down there's floor. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe