1. Bryan O'Sullivan
  2. math-functions

Commits

Aleksey Khudyakov  committed 450da2f

Test that incompleteBeta is in range

  • Participants
  • Parent commits 0326502
  • Branches default

Comments (0)

Files changed (1)

File tests/Tests/SpecFunctions.hs

View file
   , testProperty "γ - increases"             $
       \s x y -> s > 0 && x > 0 && y > 0 ==> monotonicallyIncreases (incompleteGamma s) x y
   , testProperty "invIncompleteGamma = γ^-1" $ invIGammaIsInverse
+  , testProperty "0 <= I[B] <= 1"            $ incompleteBetaInRange
   , testProperty "invIncompleteBeta  = B^-1" $ invIBetaIsInverse
     -- Unit tests
   , testAssertion "Factorial is expected to be precise at 1e-15 level"
     x  = invIncompleteGamma a p
     p' = incompleteGamma    a x
 
+-- B(s,x) is in [0,1] range
+incompleteBetaInRange :: Double -> Double -> Double -> Property
+incompleteBetaInRange (abs -> p) (abs -> q) (abs . snd . properFraction -> x) =
+  p > 0 && q > 0  ==> let i = incompleteBeta p q x in i >= 0 && i <= 1
+
 -- invIncompleteBeta is inverse of incompleteBeta
 invIBetaIsInverse :: Double -> Double -> Double -> Property
 invIBetaIsInverse (abs -> p) (abs -> q) (abs . snd . properFraction -> x) =