Re: [Haskell-cafe] instance Enum Double considerednotentirelygreat?

2011-09-27 Thread Donn Cave
Quoth Chris Smith cdsm...@gmail.com,
...
 I certainly don't agree that wanting the exact value from a floating
 point type is a reasonable expectation.  The *only* way to recover those
 results is to do the math with the decimal or rational values instead of
 floating point numbers.  You'll get the rounding error from floating
 point regardless of how you do the computation, because the interval
 just isn't really 0.1.  The difference between those numbers is larger
 than 0.1, and when you step by that interval, you won't hit 0.5.

You may have misunderstand - you're right, it isn't reasonable to expect
`exact values' out of 0.1, 0.2, 0.3, etc., in the sense of the values
classically denoted by those terms on paper.  But I believe they do have
specific values of type Double, and it isn't unreasonable to expect the
range to produce those values and not some approximation that may have
been convenient to compute.

I think it's more than reasonable to expect

  [0.1,0.2..0.5] == [0.1,0.2,0.3,0.4,0.5]

and that would make everyone happy, wouldn't it?

If it's expensive to compute, hopefully people won't write code that
makes intensive use of Double range generation.

Donn

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] instance Enum Double considerednotentirelygreat?

2011-09-27 Thread Steve Schafer
On Tue, 27 Sep 2011 09:23:20 -0700 (PDT), you wrote:

I think it's more than reasonable to expect

  [0.1,0.2..0.5] == [0.1,0.2,0.3,0.4,0.5]

and that would make everyone happy, wouldn't it?

[0.1,0.2..0.5] isn't the problem. The problem is coming up with
something that not only works for [0.1,0.2..0.5], but also works for
[0.1,0.2..1234567890.5].

A good rule of thumb: For every proposal that purports to eliminate
having to explicitly take into consideration the limited precision of
floating-point representations, there exists a trivial example that
breaks that proposal.

-Steve Schafer

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] instance Enum Double considerednotentirelygreat?

2011-09-27 Thread Chris Smith
On Tue, 2011-09-27 at 09:23 -0700, Donn Cave wrote:
 I think it's more than reasonable to expect
 
   [0.1,0.2..0.5] == [0.1,0.2,0.3,0.4,0.5]
 
 and that would make everyone happy, wouldn't it?

But what's the justification for that?  It *only* makes sense because
you used short decimal literals.  If the example were:

let a = someComplicatedCalculation
b = otherComplicatedCalculation
c = thirdComplicatedCalculation
in  [a, b .. c]

then it would be far less reasonable to expect the notation to fudge the
numbers in favor of obtaining short decimal representations, which is
essentially what you're asking for.

-- 
Chris


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] instance Enum Double considerednotentirelygreat?

2011-09-27 Thread Chris Smith
On Tue, 2011-09-27 at 12:36 -0400, Steve Schafer wrote:
 [0.1,0.2..0.5] isn't the problem. The problem is coming up with
 something that not only works for [0.1,0.2..0.5], but also works for
 [0.1,0.2..1234567890.5].
 
 A good rule of thumb: For every proposal that purports to eliminate
 having to explicitly take into consideration the limited precision of
 floating-point representations, there exists a trivial example that
 breaks that proposal.

If by trivial you mean easy to construct, sure.  But if you mean
typical, that's overstating the case by quite a bit.

There are plenty of perfectly good uses for floating point numbers, as
long as you keep in mind a few simple rules:

1. Don't expect any exact answers.

2. Don't add or subtract values of vastly different magnitudes if you
expect any kind of accuracy in the results.

3. When you do depend on discrete answers (like with the Ord functions)
you assume an obligation to check that the function you're computing is
continuous around the boundary.

If you can't follow these rules, you probably should find a different
type.  But there's a very large class of computing tasks where these
rules are not a problem at all.  In your example, you're breaking rule
#2.  It's certainly not a typical case to be adding numbers like 0.1 to
numbers in the billions, and if you're doing that, you should know in
advance that an approximate type is risky.

-- 
Chris


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] instance Enum Double considerednotentirelygreat?

2011-09-27 Thread Steve Schafer
On Tue, 27 Sep 2011 13:13:39 -0600, you wrote:

On Tue, 2011-09-27 at 12:36 -0400, Steve Schafer wrote:
 [0.1,0.2..0.5] isn't the problem. The problem is coming up with
 something that not only works for [0.1,0.2..0.5], but also works for
 [0.1,0.2..1234567890.5].
 
 A good rule of thumb: For every proposal that purports to eliminate
 having to explicitly take into consideration the limited precision of
 floating-point representations, there exists a trivial example that
 breaks that proposal.

If by trivial you mean easy to construct, sure.  But if you mean
typical, that's overstating the case by quite a bit.

There are plenty of perfectly good uses for floating point numbers, as
long as you keep in mind a few simple rules:

Your rules are what I meant by ...having to explicitly take into
consideration the limited precision of floating-point representations.

The problem, of course, is that people would rather not have to follow
any rules, and that floating-point arithmetic would just work the way
they think it ought to.

-Steve Schafer

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe