Aleksey Khudyakov avatar Aleksey Khudyakov committed 450da2f

Test that incompleteBeta is in range

Comments (0)

Files changed (1)

tests/Tests/SpecFunctions.hs

   , 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) =
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.