Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1048 (assigned defect)

Opened 16 years ago

Last modified 16 years ago

too stringent tests in tango/math/Probability.d ?

Reported by: fawzi Assigned to: Don Clugston (accepted)
Priority: minor Milestone: External Bugs
Component: Core Functionality Version: trunk
Keywords: triage Cc:

Description

Unitetest

assert( feqrel(studentsTDistribution(18, studentsTDistributionInv(18, 0.4L)),0.4L)
 > real.mant_dig-2 );

fails with a difference of -0.27105054e-18 which means feqrel is 60, which is smaller than 62 (matissa of real is 64) with gdc trunk on AMD64. same thing happens for

  assert(feqrel(chiSqrDistributionCompl(3.5L, chiSqrDistributionComplInv(3.5L, 0.1L)), 0.1L)>=real.mant_dig-3);

I do not know if this a compiler problem (using double somewhere instead of real, or ok given the numerics real.mant_dig-5 (or real.mant_dig-1-real.mant_dig/16) would work.

For

    assert(feqrel(binomialDistributionInv(0, 24, w), 0.637L)>=real.mant_dig-5);

feqrel=38, obviously in the inversion something gets lost, things are not converged enough or a double or float crops up at the wrong place.

Change History

04/15/08 11:22:30 changed by fawzi

  • owner changed from sean to Don Clugston.

04/16/08 07:22:04 changed by Don Clugston

  • status changed from new to assigned.

Yes, the tests are too stringent. I made them the toughest possible that would still pass on my machine (that way I would know if I accidentally interfered with the convergence properties). The last few digits in those tests come down to luck (may depend on compiler optimisations); if it needs to change by 1..6 digits, that's OK.

So the first should be real.mant_dig-4, the second real.mant_dig-5.

The last one is the only one that's disturbing.

But hey, that's why those unit tests are in there -- they are working!

04/16/08 09:38:51 changed by fawzi

actually the first two should be real.mant_dig-5 because the test is > not >=.

Last one well as said I don't know. :)

05/17/08 21:01:42 changed by larsivi

(In [3509]) Reduce stringency (is that a word?) on probability unittests - refs #1048

05/17/08 21:04:43 changed by larsivi

  • keywords set to triage.

What can we do to debug the last of the three? I committed the discussed fix for the first two.t

05/28/08 06:56:04 changed by Don Clugston

I think there must be a bug in GDC's pow(), since to my relief it's not a bug in the beta or incomplete gamma functions.

Try this code. Does it print the same results as DMD? If they are different, replace pow() with powl() (from tango.stdc.math).

import tango.stdc.stdio;
import tango.math.Math;
void main() {
    real x = pow(1.0L-0.637L, 24);
    printf("%La %La %La\n", 1.0L-0.637L, x, pow(x, 1.0L/24.0L));
    //DMD: 0x1.73b645a1cac08314p-2 0x1.e20907015ee9e66cp-36 0x1.73b645a1cac08314p-2
}

05/28/08 08:03:27 changed by larsivi

I tried DMD on Linux, GDC on Linux (32 bit and 64 bit), and with both pow (from Math) and powl (from stdc.math) and all ended up with the following result, no variance whatsoever, and note that it is nothing like the one provided above.

0xb.9db22d0e560418ap-5 0xf.1048380af74f336p-39 0xb.9db22d0e560418ap-5

05/28/08 08:46:08 changed by Don Clugston

Wierd. Actually those values are the same as DMD. I didn't realize that the format of %La was different on Linux compared to Windows. That's really stupid. Anyway: In probability.d, add the line:

    w = binomialDistribution(0, 24, 0.637L);
    printf("%La %La \n", w, binomialDistributionInv(0, 24, w)); // <--- add this
    assert(feqrel(binomialDistributionInv(0, 24, w), 0.637L)>=real.mant_dig-3);

It should print: 0xf.1048380af74f336p-39 0xb.9db22d0e560418ap-5

05/28/08 12:16:26 changed by larsivi

It printed

0xf.1048380af74f336p-39 0xa.3126e97902178f2p-4

so the latter value is wrong?

05/28/08 12:43:32 changed by Don Clugston

Yes, we have a compiler bug. Actually, the second number I gave wasn't quite right. Converting to the Windows %La format: Should be: 0x1.4624dd2f2042f1e4p-1 = 0.6370000000025636397 Actually is: 0x1.4624dd2f1a9fbe76p-1 = 0.6370000000000000000

We can now proceed with normal compiler bug identification.

Test case is: assert(1.0L - binomialDistributionInv(0, 24, 0xf.1048380af74f336p-39L) == 0x1.73b645a1cac08314p-2L);

Cut it down as normal to make a GDC bug report. Shouldn't be too difficult -- the relevant bit of binomialDistributionInv() is just a call to pow(). Somehow, it's not making the call correctly, or else it is corrupting the return value. We've already proved that pow() itself is fine.

06/17/08 21:35:17 changed by fawzi

the strange thing is that I don't seem able to reduce it much external programs seem to work, the bug kicks in only with unit test, and only within the probability module (the same unit test in an external module works)... Tomorrow I will try the take the probability module and reduce it as much as possible...

06/17/08 22:04:32 changed by larsivi

unittest codegen error?

07/08/08 00:22:15 changed by fawzi

a file like

module xxx.test;
private import tango.math.Math;

import tango.stdc.stdio;

unittest {
    real x = pow(1.0L-0.637L, 24);
    printf("tst %La %La %La\n", 1.0L-0.637L, x, pow(x, 1.0L/24.0L));
}

shows the error when xxx=tango.math

I tried to reproduce it copying one by one the tango.math files in a separate tango/math directory, and the error seems to appear or not depending on the order of compilation of the files(if the file is compiled after Probability.d then the error appears. I do not know if it is connected with symbols in the .a library of the package or the use of package private functions (I suspect the first).

07/08/08 00:34:12 changed by fawzi

looking more carefully it seems that linking order is the reason of the behavior, linking Math.o before test.o gives the error...

07/10/08 10:46:45 changed by larsivi

  • milestone changed from 0.99.7 to 0.99.8.

08/20/08 16:08:01 changed by fawzi

  • milestone changed from 0.99.8 to External Bugs.

distilled to gdc bug, and submitted as

http://d.puremagic.com/issues/show_bug.cgi?id=2297