haskell / math-functions

Special mathematical functions
http://hackage.haskell.org/package/math-functions
BSD 2-Clause "Simplified" License
40 stars 28 forks source link

Sporadic test failure #25

Closed snoyberg closed 10 years ago

snoyberg commented 10 years ago

Full error log below:

Unpacking to math-functions-0.1.5.2/
Resolving dependencies...
Configuring math-functions-0.1.5.2...
Building math-functions-0.1.5.2...
Preprocessing library math-functions-0.1.5.2...
[1 of 6] Compiling Numeric.Sum      ( Numeric/Sum.hs, dist/build/Numeric/Sum.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package primitive-0.5.3.0 ... linking ... done.
Loading package vector-0.10.11.0 ... linking ... done.
Loading package vector-th-unbox-0.2.1.0 ... linking ... done.
Loading package erf-2.0.0.0 ... linking ... done.

Numeric/Sum.hs:57:1: Warning:
    The import of ‘Data.Vector.Generic.Mutable’ is redundant
      except perhaps to import instances from ‘Data.Vector.Generic.Mutable’
    To import instances alone, use: import Data.Vector.Generic.Mutable()
[2 of 6] Compiling Numeric.Polynomial.Chebyshev ( Numeric/Polynomial/Chebyshev.hs, dist/build/Numeric/Polynomial/Chebyshev.o )
[3 of 6] Compiling Numeric.Polynomial ( Numeric/Polynomial.hs, dist/build/Numeric/Polynomial.o )
[4 of 6] Compiling Numeric.MathFunctions.Constants ( Numeric/MathFunctions/Constants.hs, dist/build/Numeric/MathFunctions/Constants.o )
[5 of 6] Compiling Numeric.SpecFunctions ( Numeric/SpecFunctions.hs, dist/build/Numeric/SpecFunctions.o )

Numeric/SpecFunctions.hs:627:59: Warning:
    Literal 18446744069414584320 is out of the Int range -9223372036854775808..9223372036854775807
[6 of 6] Compiling Numeric.SpecFunctions.Extra ( Numeric/SpecFunctions/Extra.hs, dist/build/Numeric/SpecFunctions/Extra.o )
In-place registering math-functions-0.1.5.2...
Preprocessing test suite 'tests' for math-functions-0.1.5.2...
[1 of 6] Compiling Tests.SpecFunctions.Tables ( tests/Tests/SpecFunctions/Tables.hs, dist/build/tests/tests-tmp/Tests/SpecFunctions/Tables.o )
[2 of 6] Compiling Tests.Helpers    ( tests/Tests/Helpers.hs, dist/build/tests/tests-tmp/Tests/Helpers.o )
[3 of 6] Compiling Tests.Sum        ( tests/Tests/Sum.hs, dist/build/tests/tests-tmp/Tests/Sum.o )
[4 of 6] Compiling Tests.Chebyshev  ( tests/Tests/Chebyshev.hs, dist/build/tests/tests-tmp/Tests/Chebyshev.o )

tests/Tests/Chebyshev.hs:34:1: Warning:
    Defined but not used: ‘testBroucke’

tests/Tests/Chebyshev.hs:41:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/Chebyshev.hs:42:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/Chebyshev.hs:43:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"
[5 of 6] Compiling Tests.SpecFunctions ( tests/Tests/SpecFunctions.hs, dist/build/tests/tests-tmp/Tests/SpecFunctions.o )

tests/Tests/SpecFunctions.hs:114:1: Warning:
    Defined but not used: ‘invIGammaIsInverse’

tests/Tests/SpecFunctions.hs:115:34: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:116:34: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:117:34: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:118:34: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:119:34: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:129:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:130:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:131:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:140:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:141:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:142:5: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:157:1: Warning:
    Defined but not used: ‘invIBetaIsInverse’

tests/Tests/SpecFunctions.hs:158:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:159:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:160:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:161:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:162:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:163:25: Warning:
    In the use of ‘printTestCase’
    (imported from Test.QuickCheck, but defined in Test.QuickCheck.Property):
    Deprecated: "Use counterexample instead"

tests/Tests/SpecFunctions.hs:179:5: Warning:
    Defined but not used: ‘ok’

tests/Tests/SpecFunctions.hs:179:15: Warning:
    Defined but not used: ‘exact’
[6 of 6] Compiling Main             ( tests/tests.hs, dist/build/tests/tests-tmp/Main.o )
Linking dist/build/tests/tests ...
Building math-functions-0.1.5.2...
Preprocessing library math-functions-0.1.5.2...
In-place registering math-functions-0.1.5.2...
Preprocessing test suite 'tests' for math-functions-0.1.5.2...
Running 1 test suites...
Test suite tests: RUNNING...
Special functions:
  Gamma(x+1) = x*Gamma(x) [logGamma]: [OK, passed 100 tests]
  Gamma(x+1) = x*Gamma(x) [logGammaL]: [Failed]
*** Failed! Falsifiable (after 35 tests and 14 shrinks): 
6.423254573425097e-4
(used seed -172617929603829981)
  gamma(1,x) = 1 - exp(-x): [OK, passed 100 tests]
  0 <= gamma <= 1: [OK, passed 100 tests]
  0 <= I[B] <= 1: [OK, passed 100 tests]
  invErfc = erfc^-1: [OK, passed 100 tests]
  invErf  = erf^-1: [OK, passed 100 tests]
  Factorial is expected to be precise at 1e-15 level: [OK]
  Log factorial is expected to be precise at 1e-15 level: [OK]
  logGamma is expected to be precise at 1e-9 level [integer points]: [OK]
  logGamma is expected to be precise at 1e-9 level [fractional points]: [OK]
  logGammaL is expected to be precise at 1e-15 level: [OK]
  logGammaL is expected to be precise at 1e-10 level [fractional points]: [OK]
  logBeta is expected to be precise at 1e-6 level: [OK]
  digamma is expected to be precise at 1e-14 [integers]: [OK]
  digamma is expected to be precise at 1e-12: [OK]
  incompleteBeta is expected to be precise at 1e-8 level: [OK]
  incompleteBeta with p > 3000 and q > 3000: [OK]
  choose is expected to precise at 1e-12 level: [OK]
  Self-test: 0 <= range01 <= 1: [OK, passed 100 tests]
Chebyshev polynomials:
  Chebyshev 0: [OK, passed 100 tests]
Summation:
  Kahan:
    t_sum_shifted: [OK, passed 100 tests]
  KBN:
    t_sum: [OK, passed 100 tests]
    t_sum_error: [OK, passed 100 tests]
    t_sum_shifted: [OK, passed 100 tests]
  KB2:
    t_sum: [OK, passed 100 tests]
    t_sum_error: [OK, passed 100 tests]
    t_sum_shifted: [OK, passed 100 tests]

         Properties   Test Cases   Total       
 Passed  15           12           27          
 Failed  1            0            1           
 Total   16           12           28          
Test suite tests: FAIL
Test suite logged to: dist/test/math-functions-0.1.5.2-tests.log
0 of 1 test suites (0 of 1 test cases) passed.
Shimuuar commented 10 years ago

Sporadic failures are usual featery of property testing of numberic code. They arise because we don't have exact equality and have to use approximate equality. Usual choice is |a-b|/max(|a|,|b|) < ε. Problems don't end here because ε depends on parameter on in some corners of parameter space may approach 1. We use some ε for all inputs so it envitable fails for some small fraction. One could argue that it's bug in tests. I agree but I don't know how to write them properly.

I suppose it's for purposes of stackage? AFAIR it's possible to mark that test may fail and that's OK. It's probably only sane solution

In this particular case test is log(Γ(x+1)) - log(Γ(x)) - log x ≈ 0. For small x expression x+1 start to lose precision. So it's OK.

snoyberg commented 10 years ago

OK, I'll take your recommendation and set this as an expected failure in Stackage. Thanks for the info.