[Haskell-cafe] Optimization flag changing result of code execution

Carter Schonwald carter.schonwald at gmail.com
Fri Mar 15 22:09:36 CET 2013


Hey Azeem,
have you tried running the same calculation using rationals? Theres some
subtleties to writing numerically stable code using floats and doubles,
where simple optimizations change the orders of operations in ways that
*significantly* change the result. In this case it looks like you're
averaging the averages, which i *believe* can get pretty nasty in terms of
numerical precision.  Rationals would be a bit slower, but you could then
sort out which number is more correct.


On Fri, Mar 15, 2013 at 4:07 PM, Azeem -ul-Hasan <azeeem at live.com> wrote:

> I was trying to solve a computational problem form James P Sethna's book
> Statistical Mechanics: Entropy, Order Parameters, and Complexity[1]. The
> problem is on page 19 of the pdf linked and is titled Six degrees of
> separation. For it I came up with this code: http://hpaste.org/84114
>   <http://hpaste.org/84114>
> It runs fine when compiled with -O0 and consistently yields an answer
> around 10, but with -O1 and -O2 it consistently gives an answer around 25.
> Can somebody explain what is happening here?
>
> [1]
> http://pages.physics.cornell.edu/~sethna/StatMech/EntropyOrderParametersComplexity.pdf
>
> Azeem
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130315/44afef6a/attachment.htm>


More information about the Haskell-Cafe mailing list