Debugging

David Roundy droundy@abridgegame.org
Thu, 28 Aug 2003 07:28:27 -0400


On Thu, Aug 28, 2003 at 11:33:40AM +0200, Konrad Hinsen wrote:
> I haven't tried QuickCheck yet, but I have my doubts as to its
> suitability for numerical calculations, where you have to deal with
> precision and rounding issues.

I'd still recommend trying it.  In the worst case, you can just specify a
range of acceptable answers.  e.g.

prop_minus_plus a b = abs(((a-b)+b) - a) < abs(b)*1.0e-15

would make sure that if you subtract b from a and then add it you get back
a again to a reasonable precision.

But in cases where it is possible I strongly recommend using equality
tests.  I'm right now working (at work) on parallelizing a numerical code
(in C++, not haskell, but the issues are similar), and I've managed to
assure that most the results are identical regardless of how the data is
split up, which is a very powerful check.  For things like summations, of
course, the answer will depend on the number of processors, but it was
definitely worth the effort (a day) to make all the intermediate results
are calculated in precisely the same order (that is, order of additions)
regardless of number of processors, just so I could have the strict
equality test.
-- 
David Roundy
http://www.abridgegame.org