Author jeff.allen
Recipients jeff.allen, mark.dickinson
Date 2016-01-07.15:41:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452181282.79.0.203850145541.issue26040@psf.upfronthosting.co.za>
In-reply-to
Content
In many cases, test_math does not exercise the functions defined by the math module, other than at a few values needing special handling. Where it does test a function with values representative of the domain, the accuracy demanded is often loose in one place and tight in another. By comparison, test_cmath uses more interesting values and a rational approach to accuracy.

In most implementations, math simply proxies an expertly built (and tested) platform library or firmware, so it is unlikely we are the victims of mathematical inexactitude.

We observed this as a problem in the Jython project, where failures in cmath were traced eventually to the naive (but passing) implementation of some functions in math. For Jython, we now supplement test_math with stronger tests more like those in test_cmath. So this issue is really an offer to fold that work back into the CPython test_math, to strengthen testing for all.


Coverage:
--------
In the attached program, in the coverge section, I logged the calls to selected functions from test_math to see what range of values they used. It produces results like:

sqrt
 [9.881e-324, 7.905e-323, 1.862e-309, 1e-305, 1e-150, ..., 2, 23, 1e+16, 1e+150, 1e+299]
 [-1]
 [-0.0, -inf, 0.0, inf, nan]

sin
 [1.571]
 [-1.571]
 [-0.0, -inf, 0.0, inf, nan]

exp
 []
 [-745]
 [-0.0, -inf, 0.0, inf, nan]

sinh
 []
 []
 [-0.0, -inf, 0.0, inf, nan]

The three rows here are positive, negative and "special" arguments, and "..." means I abridged the list.


Accuracy:
--------
Where functions are tested, results are expected with a maximum error of 1e-5. On sqrt(1e150), this demands bit-perfect accuracy; on sqrt(1e-150) it demands virtually nothing. 

In the attached program, in the accuracy section, I wrap most of the functions so as to fuzz their results by plus or minus 2e-6, test_math will still pass them. test_cmath uses a relative measure of error (so many ulps of the expected value), which is worth emulating.


If people think it better, coverage and accuracy can be tracked as separate issues.
History
Date User Action Args
2016-01-07 15:41:23jeff.allensetrecipients: + jeff.allen, mark.dickinson
2016-01-07 15:41:22jeff.allensetmessageid: <1452181282.79.0.203850145541.issue26040@psf.upfronthosting.co.za>
2016-01-07 15:41:22jeff.allenlinkissue26040 messages
2016-01-07 15:41:21jeff.allencreate