Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: How to improve the accuracy of floating point
calculation? (Patrick Mylund Nielsen)
2. Re: How to improve the accuracy of floating point
calculation? (Darren Grant)
3. Re: How to improve the accuracy of floating point
calculation? (Mateusz Kowalczyk)
4. Re: How to improve the accuracy of floating point
calculation? (Mateusz Kowalczyk)
5. Re: How to improve the accuracy of floating point
calculation? (Darren Grant)
----------------------------------------------------------------------
Message: 1
Date: Wed, 6 Feb 2013 00:24:26 +0100
From: Patrick Mylund Nielsen <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAEw2jfyKyr7KW7LMMK5+HsAEFHNJh1u4wUt7tABd-g+Fr=7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
http://floating-point-gui.de/
http://floating-point-gui.de/formats/fp/
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
On Wed, Feb 6, 2013 at 12:08 AM, KC <[email protected]> wrote:
> 0.1 cannot be represented exactly in floating point.
>
> 0.5 can be represented exactly. Why?
>
>
> On Tue, Feb 5, 2013 at 2:41 PM, yi lu <[email protected]>
> wrote:
> > Hi,
> >
> > I found that in ghci, I input
> > [0.1,0.2..2]
> > and run, I get a result of
> >
> >
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
> >
> > But, as you know, it is not the exact answer.
> >
> > So, I wonder if there is something I can do to achieve a better
> performance
> > and get [0.1,0.2,0.3,0.4..] as the result.
> >
> > Thanks.
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
> --
> --
> Regards,
> KC
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130206/8004e377/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 5 Feb 2013 16:12:25 -0800
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CA+jD6SivHcp4oG47bFz3aw3HE7fTEdmKrouh1ML=1a4a627...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I'm not sure how CReal implements its values, but IEEE754 also supports
decimal formats preferred for accuracy in many applications. Take a look:
http://en.wikipedia.org/wiki/IEEE_floating_point
Cheers,
d
On Tue, Feb 5, 2013 at 3:24 PM, Patrick Mylund Nielsen <
[email protected]> wrote:
> http://floating-point-gui.de/
> http://floating-point-gui.de/formats/fp/
>
> http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
>
>
> On Wed, Feb 6, 2013 at 12:08 AM, KC <[email protected]> wrote:
>
>> 0.1 cannot be represented exactly in floating point.
>>
>> 0.5 can be represented exactly. Why?
>>
>>
>> On Tue, Feb 5, 2013 at 2:41 PM, yi lu <[email protected]>
>> wrote:
>> > Hi,
>> >
>> > I found that in ghci, I input
>> > [0.1,0.2..2]
>> > and run, I get a result of
>> >
>> >
>> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>> >
>> > But, as you know, it is not the exact answer.
>> >
>> > So, I wonder if there is something I can do to achieve a better
>> performance
>> > and get [0.1,0.2,0.3,0.4..] as the result.
>> >
>> > Thanks.
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected]
>> > http://www.haskell.org/mailman/listinfo/beginners
>> >
>>
>>
>>
>> --
>> --
>> Regards,
>> KC
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130205/1947037c/attachment-0001.htm>
------------------------------
Message: 3
Date: Wed, 06 Feb 2013 00:47:32 +0000
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I thought that KC was asking why is 0.5 not displayed as 0.5 when it's
supported by the IEEE754. Even if that wasn't question, it is my
question now.
IEEE754 is capable of representing 0.5 with perfect precision; in fact,
it would be `00111111000000000000000000000000'.
My question is why [0.1, 0.2 .. 1.0] comes up with an imprecise
midpoint:
[0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
My initial guess is that the expansion is done by working out the
difference between the first two elements and using that to generate the
rest. This also makes me question why 0.1 is shown properly when it
can't be represented precisely in IEEE754. Quickly rolling own list
generation function:
*Main> let f x y = x : f y (y + y - x)
*Main> take 10 $ f 0.1 0.2
[0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
reveals the same result as the short-hand which would imply that it's
exactly what it's doing (for the simple case). My question for why can
0.1 be shown properly still stands in this case.
On 06/02/13 00:12, Darren Grant wrote:
> I'm not sure how CReal implements its values, but IEEE754 also supports
> decimal formats preferred for accuracy in many applications. Take a look:
>
> http://en.wikipedia.org/wiki/IEEE_floating_point
>
>
> Cheers,
> d
>
>
>
>
> On Tue, Feb 5, 2013 at 3:24 PM, Patrick Mylund Nielsen
> <[email protected] <mailto:[email protected]>> wrote:
>
> http://floating-point-gui.de/
> http://floating-point-gui.de/formats/fp/
>
> http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
>
>
> On Wed, Feb 6, 2013 at 12:08 AM, KC <[email protected]
> <mailto:[email protected]>> wrote:
>
> 0.1 cannot be represented exactly in floating point.
>
> 0.5 can be represented exactly. Why?
>
>
> On Tue, Feb 5, 2013 at 2:41 PM, yi lu
> <[email protected]
> <mailto:[email protected]>> wrote:
> > Hi,
> >
> > I found that in ghci, I input
> > [0.1,0.2..2]
> > and run, I get a result of
> >
> >
>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
> >
> > But, as you know, it is not the exact answer.
> >
> > So, I wonder if there is something I can do to achieve a
> better performance
> > and get [0.1,0.2,0.3,0.4..] as the result.
> >
> > Thanks.
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected] <mailto:[email protected]>
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
> --
> --
> Regards,
> KC
>
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Wed, 06 Feb 2013 01:07:54 +0000
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
We just figured it out over here. The short version is that the 0.1 and
0.2 just happen to round pretty well (to what looks perfect to a human)
while other figures don't. This can be easily represented by forcing a
[Float] type for lower precision as opposed to the default double precision:
*Main> [0.1, 0.2 .. 1] :: [Float]
[0.1,0.2,0.3,0.40000004,0.50000006,0.6000001,0.7000001,0.80000013,0.90000015,1.0000002]
Above we can easily see that with a float the errors compound so much
that the numbers no longer round to a human-friendly representation.
This can also be shown with doubles: the 0.1 was displayed as 0.1
because it just happened to be fairly precise. Start compounding errors
early enough and it no longer rounds so nicely:
[-0.5,-0.4,-0.30000000000000004,-0.20000000000000007,-0.10000000000000009,-1.1102230246251565e-16,9.999999999999987e-2,0.19999999999999984,0.2999999999999998,0.3999999999999998,0.4999999999999998]
You can see just how much precision we lost at mid-point by looking at
what should be 0.
Thanks
On 06/02/13 00:47, Mateusz Kowalczyk wrote:
> I thought that KC was asking why is 0.5 not displayed as 0.5 when it's
> supported by the IEEE754. Even if that wasn't question, it is my
> question now.
>
> IEEE754 is capable of representing 0.5 with perfect precision; in fact,
> it would be `00111111000000000000000000000000'.
>
> My question is why [0.1, 0.2 .. 1.0] comes up with an imprecise
> midpoint:
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
>
> My initial guess is that the expansion is done by working out the
> difference between the first two elements and using that to generate the
> rest. This also makes me question why 0.1 is shown properly when it
> can't be represented precisely in IEEE754. Quickly rolling own list
> generation function:
>
> *Main> let f x y = x : f y (y + y - x)
> *Main> take 10 $ f 0.1 0.2
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
>
> reveals the same result as the short-hand which would imply that it's
> exactly what it's doing (for the simple case). My question for why can
> 0.1 be shown properly still stands in this case.
>
> On 06/02/13 00:12, Darren Grant wrote:
>> I'm not sure how CReal implements its values, but IEEE754 also supports
>> decimal formats preferred for accuracy in many applications. Take a look:
>>
>> http://en.wikipedia.org/wiki/IEEE_floating_point
>>
>>
>> Cheers,
>> d
>>
>>
>>
>>
>> On Tue, Feb 5, 2013 at 3:24 PM, Patrick Mylund Nielsen
>> <[email protected] <mailto:[email protected]>> wrote:
>>
>> http://floating-point-gui.de/
>> http://floating-point-gui.de/formats/fp/
>>
>> http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
>>
>>
>> On Wed, Feb 6, 2013 at 12:08 AM, KC <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> 0.1 cannot be represented exactly in floating point.
>>
>> 0.5 can be represented exactly. Why?
>>
>>
>> On Tue, Feb 5, 2013 at 2:41 PM, yi lu
>> <[email protected]
>> <mailto:[email protected]>> wrote:
>> > Hi,
>> >
>> > I found that in ghci, I input
>> > [0.1,0.2..2]
>> > and run, I get a result of
>> >
>> >
>>
>> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>> >
>> > But, as you know, it is not the exact answer.
>> >
>> > So, I wonder if there is something I can do to achieve a
>> better performance
>> > and get [0.1,0.2,0.3,0.4..] as the result.
>> >
>> > Thanks.
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected] <mailto:[email protected]>
>> > http://www.haskell.org/mailman/listinfo/beginners
>> >
>>
>>
>>
>> --
>> --
>> Regards,
>> KC
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected] <mailto:[email protected]>
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected] <mailto:[email protected]>
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Tue, 5 Feb 2013 17:50:07 -0800
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<ca+jd6shu5d552zmxqndtczdv_k6a7_cvzeeud-kgcjvacnt...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
It's a pathological situation that arises from the way enumFromThenTo is
defined for floating point values. Does anyone know why the specific
implementation isn't more accurate?
In simple cases you can sometimes convert an integer range to desired
floating point range to avoid cumulative precision errors.
Cheers,
d
On Tue, Feb 5, 2013 at 5:07 PM, Mateusz Kowalczyk
<[email protected]>wrote:
> We just figured it out over here. The short version is that the 0.1 and
> 0.2 just happen to round pretty well (to what looks perfect to a human)
> while other figures don't. This can be easily represented by forcing a
> [Float] type for lower precision as opposed to the default double
> precision:
> *Main> [0.1, 0.2 .. 1] :: [Float]
>
> [0.1,0.2,0.3,0.40000004,0.50000006,0.6000001,0.7000001,0.80000013,0.90000015,1.0000002]
>
> Above we can easily see that with a float the errors compound so much
> that the numbers no longer round to a human-friendly representation.
>
> This can also be shown with doubles: the 0.1 was displayed as 0.1
> because it just happened to be fairly precise. Start compounding errors
> early enough and it no longer rounds so nicely:
>
> [-0.5,-0.4,-0.30000000000000004,-0.20000000000000007,-0.10000000000000009,-1.1102230246251565e-16,9.999999999999987e-2,0.19999999999999984,0.2999999999999998,0.3999999999999998,0.4999999999999998]
>
> You can see just how much precision we lost at mid-point by looking at
> what should be 0.
>
> Thanks
>
> On 06/02/13 00:47, Mateusz Kowalczyk wrote:
> > I thought that KC was asking why is 0.5 not displayed as 0.5 when it's
> > supported by the IEEE754. Even if that wasn't question, it is my
> > question now.
> >
> > IEEE754 is capable of representing 0.5 with perfect precision; in fact,
> > it would be `00111111000000000000000000000000'.
> >
> > My question is why [0.1, 0.2 .. 1.0] comes up with an imprecise
> > midpoint:
> >
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
> >
> > My initial guess is that the expansion is done by working out the
> > difference between the first two elements and using that to generate the
> > rest. This also makes me question why 0.1 is shown properly when it
> > can't be represented precisely in IEEE754. Quickly rolling own list
> > generation function:
> >
> > *Main> let f x y = x : f y (y + y - x)
> > *Main> take 10 $ f 0.1 0.2
> >
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
> >
> > reveals the same result as the short-hand which would imply that it's
> > exactly what it's doing (for the simple case). My question for why can
> > 0.1 be shown properly still stands in this case.
> >
> > On 06/02/13 00:12, Darren Grant wrote:
> >> I'm not sure how CReal implements its values, but IEEE754 also supports
> >> decimal formats preferred for accuracy in many applications. Take a
> look:
> >>
> >> http://en.wikipedia.org/wiki/IEEE_floating_point
> >>
> >>
> >> Cheers,
> >> d
> >>
> >>
> >>
> >>
> >> On Tue, Feb 5, 2013 at 3:24 PM, Patrick Mylund Nielsen
> >> <[email protected] <mailto:[email protected]>> wrote:
> >>
> >> http://floating-point-gui.de/
> >> http://floating-point-gui.de/formats/fp/
> >>
> >> http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
> >>
> >>
> >> On Wed, Feb 6, 2013 at 12:08 AM, KC <[email protected]
> >> <mailto:[email protected]>> wrote:
> >>
> >> 0.1 cannot be represented exactly in floating point.
> >>
> >> 0.5 can be represented exactly. Why?
> >>
> >>
> >> On Tue, Feb 5, 2013 at 2:41 PM, yi lu
> >> <[email protected]
> >> <mailto:[email protected]>> wrote:
> >> > Hi,
> >> >
> >> > I found that in ghci, I input
> >> > [0.1,0.2..2]
> >> > and run, I get a result of
> >> >
> >> >
> >>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
> >> >
> >> > But, as you know, it is not the exact answer.
> >> >
> >> > So, I wonder if there is something I can do to achieve a
> >> better performance
> >> > and get [0.1,0.2,0.3,0.4..] as the result.
> >> >
> >> > Thanks.
> >> >
> >> > _______________________________________________
> >> > Beginners mailing list
> >> > [email protected] <mailto:[email protected]>
> >> > http://www.haskell.org/mailman/listinfo/beginners
> >> >
> >>
> >>
> >>
> >> --
> >> --
> >> Regards,
> >> KC
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected] <mailto:[email protected]>
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >>
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected] <mailto:[email protected]>
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130205/526c0a62/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 10
*****************************************