View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.special;
23  
24  import java.lang.reflect.InvocationTargetException;
25  import java.lang.reflect.Method;
26  
27  import org.hipparchus.UnitTestUtils;
28  import org.hipparchus.exception.MathIllegalArgumentException;
29  import org.hipparchus.util.FastMath;
30  import org.junit.Assert;
31  import org.junit.Test;
32  
33  /**
34   */
35  public class BetaTest {
36  
37      /*
38       * Use reflection to test private methods.
39       */
40      private static final Method LOG_GAMMA_SUM_METHOD;
41  
42      private static final Method LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD;
43  
44      private static final Method SUM_DELTA_MINUS_DELTA_SUM_METHOD;
45  
46      static {
47          final Class<Beta> b;
48          final Class<Double> d = Double.TYPE;
49          b = Beta.class;
50          Method m = null;
51          try {
52              m = b.getDeclaredMethod("logGammaSum", d, d);
53          } catch (NoSuchMethodException e) {
54              Assert.fail(e.getMessage());
55          }
56          LOG_GAMMA_SUM_METHOD = m;
57          LOG_GAMMA_SUM_METHOD.setAccessible(true);
58  
59          m = null;
60          try {
61              m = b.getDeclaredMethod("logGammaMinusLogGammaSum",d, d);
62          } catch (NoSuchMethodException e) {
63              Assert.fail(e.getMessage());
64          }
65          LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD = m;
66          LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD.setAccessible(true);
67  
68          m = null;
69          try {
70              m = b.getDeclaredMethod("sumDeltaMinusDeltaSum",d, d);
71          } catch (NoSuchMethodException e) {
72              Assert.fail(e.getMessage());
73          }
74          SUM_DELTA_MINUS_DELTA_SUM_METHOD = m;
75          SUM_DELTA_MINUS_DELTA_SUM_METHOD.setAccessible(true);
76      }
77  
78      private void testRegularizedBeta(double expected, double x,
79                                       double a, double b) {
80          double actual = Beta.regularizedBeta(x, a, b);
81          UnitTestUtils.assertEquals(expected, actual, 10e-15);
82      }
83  
84      private void testLogBeta(double expected, double a, double b) {
85          double actual = Beta.logBeta(a, b);
86          UnitTestUtils.assertEquals(expected, actual, 10e-15);
87      }
88  
89      @Test
90      public void testRegularizedBetaNanPositivePositive() {
91          testRegularizedBeta(Double.NaN, Double.NaN, 1.0, 1.0);
92      }
93  
94      @Test
95      public void testRegularizedBetaPositiveNanPositive() {
96          testRegularizedBeta(Double.NaN, 0.5, Double.NaN, 1.0);
97      }
98  
99      @Test
100     public void testRegularizedBetaPositivePositiveNan() {
101         testRegularizedBeta(Double.NaN, 0.5, 1.0, Double.NaN);
102     }
103 
104     @Test
105     public void testRegularizedBetaNegativePositivePositive() {
106         testRegularizedBeta(Double.NaN, -0.5, 1.0, 2.0);
107     }
108 
109     @Test
110     public void testRegularizedBetaPositiveNegativePositive() {
111         testRegularizedBeta(Double.NaN, 0.5, -1.0, 2.0);
112     }
113 
114     @Test
115     public void testRegularizedBetaPositivePositiveNegative() {
116         testRegularizedBeta(Double.NaN, 0.5, 1.0, -2.0);
117     }
118 
119     @Test
120     public void testRegularizedBetaZeroPositivePositive() {
121         testRegularizedBeta(0.0, 0.0, 1.0, 2.0);
122     }
123 
124     @Test
125     public void testRegularizedBetaPositiveZeroPositive() {
126         testRegularizedBeta(Double.NaN, 0.5, 0.0, 2.0);
127     }
128 
129     @Test
130     public void testRegularizedBetaPositivePositiveZero() {
131         testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0);
132     }
133 
134     @Test
135     public void testRegularizedBetaPositivePositivePositive() {
136         testRegularizedBeta(0.75, 0.5, 1.0, 2.0);
137     }
138 
139     @Test
140     public void testRegularizedBetaTinyArgument() {
141         double actual = Beta.regularizedBeta(1e-17, 1.0, 1e12);
142         // This value is from R: pbeta(1e-17,1,1e12)
143         UnitTestUtils.assertEquals(9.999950000166648e-6, actual, 1e-16);
144     }
145 
146     @Test
147     public void testMath1067() {
148         final double x = 0.22580645161290325;
149         final double a = 64.33333333333334;
150         final double b = 223;
151 
152         try {
153             Beta.regularizedBeta(x, a, b, 1e-14, 10000);
154         } catch (StackOverflowError error) {
155             Assert.fail("Infinite recursion");
156         }
157     }
158 
159     @Test
160     public void testLogBetaNanPositive() {
161         testLogBeta(Double.NaN, Double.NaN, 2.0);
162     }
163 
164     @Test
165     public void testLogBetaPositiveNan() {
166         testLogBeta(Double.NaN, 1.0, Double.NaN);
167     }
168 
169     @Test
170     public void testLogBetaNegativePositive() {
171         testLogBeta(Double.NaN, -1.0, 2.0);
172     }
173 
174     @Test
175     public void testLogBetaPositiveNegative() {
176         testLogBeta(Double.NaN, 1.0, -2.0);
177     }
178 
179     @Test
180     public void testLogBetaZeroPositive() {
181         testLogBeta(Double.NaN, 0.0, 2.0);
182     }
183 
184     @Test
185     public void testLogBetaPositiveZero() {
186         testLogBeta(Double.NaN, 1.0, 0.0);
187     }
188 
189     @Test
190     public void testLogBetaPositivePositive() {
191         testLogBeta(-0.693147180559945, 1.0, 2.0);
192     }
193 
194     /**
195      * Reference data for the {@link #logGammaSum(double, double)}
196      * function. This data was generated with the following
197      * <a href="http://maxima.sourceforge.net/">Maxima</a> script.
198      *
199      * <pre>
200      * kill(all);
201      *
202      * fpprec : 64;
203      * gsumln(a, b) := log(gamma(a + b));
204      *
205      * x : [1.0b0, 1.125b0, 1.25b0, 1.375b0, 1.5b0, 1.625b0, 1.75b0, 1.875b0, 2.0b0];
206      *
207      * for i : 1 while i <= length(x) do
208      *   for j : 1 while j <= length(x) do block(
209      *     a : x[i],
210      *     b : x[j],
211      *     print("{", float(a), ",", float(b), ",", float(gsumln(a, b)), "},")
212      *   );
213      * </pre>
214      */
215     private static final double[][] LOG_GAMMA_SUM_REF = {
216         { 1.0 , 1.0 , 0.0 },
217         { 1.0 , 1.125 , .05775985153034387 },
218         { 1.0 , 1.25 , .1248717148923966 },
219         { 1.0 , 1.375 , .2006984603774558 },
220         { 1.0 , 1.5 , .2846828704729192 },
221         { 1.0 , 1.625 , .3763336820249054 },
222         { 1.0 , 1.75 , .4752146669149371 },
223         { 1.0 , 1.875 , .5809359740231859 },
224         { 1.0 , 2.0 , .6931471805599453 },
225         { 1.125 , 1.0 , .05775985153034387 },
226         { 1.125 , 1.125 , .1248717148923966 },
227         { 1.125 , 1.25 , .2006984603774558 },
228         { 1.125 , 1.375 , .2846828704729192 },
229         { 1.125 , 1.5 , .3763336820249054 },
230         { 1.125 , 1.625 , .4752146669149371 },
231         { 1.125 , 1.75 , .5809359740231859 },
232         { 1.125 , 1.875 , .6931471805599453 },
233         { 1.125 , 2.0 , 0.811531653906724 },
234         { 1.25 , 1.0 , .1248717148923966 },
235         { 1.25 , 1.125 , .2006984603774558 },
236         { 1.25 , 1.25 , .2846828704729192 },
237         { 1.25 , 1.375 , .3763336820249054 },
238         { 1.25 , 1.5 , .4752146669149371 },
239         { 1.25 , 1.625 , .5809359740231859 },
240         { 1.25 , 1.75 , .6931471805599453 },
241         { 1.25 , 1.875 , 0.811531653906724 },
242         { 1.25 , 2.0 , .9358019311087253 },
243         { 1.375 , 1.0 , .2006984603774558 },
244         { 1.375 , 1.125 , .2846828704729192 },
245         { 1.375 , 1.25 , .3763336820249054 },
246         { 1.375 , 1.375 , .4752146669149371 },
247         { 1.375 , 1.5 , .5809359740231859 },
248         { 1.375 , 1.625 , .6931471805599453 },
249         { 1.375 , 1.75 , 0.811531653906724 },
250         { 1.375 , 1.875 , .9358019311087253 },
251         { 1.375 , 2.0 , 1.06569589786406 },
252         { 1.5 , 1.0 , .2846828704729192 },
253         { 1.5 , 1.125 , .3763336820249054 },
254         { 1.5 , 1.25 , .4752146669149371 },
255         { 1.5 , 1.375 , .5809359740231859 },
256         { 1.5 , 1.5 , .6931471805599453 },
257         { 1.5 , 1.625 , 0.811531653906724 },
258         { 1.5 , 1.75 , .9358019311087253 },
259         { 1.5 , 1.875 , 1.06569589786406 },
260         { 1.5 , 2.0 , 1.200973602347074 },
261         { 1.625 , 1.0 , .3763336820249054 },
262         { 1.625 , 1.125 , .4752146669149371 },
263         { 1.625 , 1.25 , .5809359740231859 },
264         { 1.625 , 1.375 , .6931471805599453 },
265         { 1.625 , 1.5 , 0.811531653906724 },
266         { 1.625 , 1.625 , .9358019311087253 },
267         { 1.625 , 1.75 , 1.06569589786406 },
268         { 1.625 , 1.875 , 1.200973602347074 },
269         { 1.625 , 2.0 , 1.341414578068493 },
270         { 1.75 , 1.0 , .4752146669149371 },
271         { 1.75 , 1.125 , .5809359740231859 },
272         { 1.75 , 1.25 , .6931471805599453 },
273         { 1.75 , 1.375 , 0.811531653906724 },
274         { 1.75 , 1.5 , .9358019311087253 },
275         { 1.75 , 1.625 , 1.06569589786406 },
276         { 1.75 , 1.75 , 1.200973602347074 },
277         { 1.75 , 1.875 , 1.341414578068493 },
278         { 1.75 , 2.0 , 1.486815578593417 },
279         { 1.875 , 1.0 , .5809359740231859 },
280         { 1.875 , 1.125 , .6931471805599453 },
281         { 1.875 , 1.25 , 0.811531653906724 },
282         { 1.875 , 1.375 , .9358019311087253 },
283         { 1.875 , 1.5 , 1.06569589786406 },
284         { 1.875 , 1.625 , 1.200973602347074 },
285         { 1.875 , 1.75 , 1.341414578068493 },
286         { 1.875 , 1.875 , 1.486815578593417 },
287         { 1.875 , 2.0 , 1.6369886482725 },
288         { 2.0 , 1.0 , .6931471805599453 },
289         { 2.0 , 1.125 , 0.811531653906724 },
290         { 2.0 , 1.25 , .9358019311087253 },
291         { 2.0 , 1.375 , 1.06569589786406 },
292         { 2.0 , 1.5 , 1.200973602347074 },
293         { 2.0 , 1.625 , 1.341414578068493 },
294         { 2.0 , 1.75 , 1.486815578593417 },
295         { 2.0 , 1.875 , 1.6369886482725 },
296         { 2.0 , 2.0 , 1.791759469228055 },
297     };
298 
299     private static double logGammaSum(final double a, final double b) {
300 
301         /*
302          * Use reflection to access private method.
303          */
304         try {
305             return ((Double) LOG_GAMMA_SUM_METHOD.invoke(null, a, b)).doubleValue();
306         } catch (final IllegalAccessException e) {
307             Assert.fail(e.getMessage());
308         } catch (final IllegalArgumentException e) {
309             Assert.fail(e.getMessage());
310         } catch (final InvocationTargetException e) {
311             final Throwable te = e.getTargetException();
312             if (te instanceof MathIllegalArgumentException) {
313                 throw (MathIllegalArgumentException) te;
314             }
315             Assert.fail(e.getMessage());
316         }
317         return Double.NaN;
318     }
319 
320     @Test
321     public void testLogGammaSum() {
322         final int ulps = 2;
323         for (int i = 0; i < LOG_GAMMA_SUM_REF.length; i++) {
324             final double[] ref = LOG_GAMMA_SUM_REF[i];
325             final double a = ref[0];
326             final double b = ref[1];
327             final double expected = ref[2];
328             final double actual = logGammaSum(a, b);
329             final double tol = ulps * FastMath.ulp(expected);
330             final StringBuilder builder = new StringBuilder();
331             builder.append(a).append(", ").append(b);
332             Assert.assertEquals(builder.toString(), expected, actual, tol);
333         }
334     }
335 
336     @Test(expected = MathIllegalArgumentException.class)
337     public void testLogGammaSumPrecondition1() {
338 
339         logGammaSum(0.0, 1.0);
340     }
341 
342     @Test(expected = MathIllegalArgumentException.class)
343     public void testLogGammaSumPrecondition2() {
344 
345         logGammaSum(3.0, 1.0);
346     }
347 
348     @Test(expected = MathIllegalArgumentException.class)
349     public void testLogGammaSumPrecondition3() {
350 
351         logGammaSum(1.0, 0.0);
352     }
353 
354     @Test(expected = MathIllegalArgumentException.class)
355     public void testLogGammaSumPrecondition4() {
356 
357         logGammaSum(1.0, 3.0);
358     }
359 
360     private static final double[][] LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF = {
361 //        { 0.0 , 8.0 , 0.0 },
362 //        { 0.0 , 9.0 , 0.0 },
363         { 0.0 , 10.0 , 0.0 },
364         { 0.0 , 11.0 , 0.0 },
365         { 0.0 , 12.0 , 0.0 },
366         { 0.0 , 13.0 , 0.0 },
367         { 0.0 , 14.0 , 0.0 },
368         { 0.0 , 15.0 , 0.0 },
369         { 0.0 , 16.0 , 0.0 },
370         { 0.0 , 17.0 , 0.0 },
371         { 0.0 , 18.0 , 0.0 },
372 //        { 1.0 , 8.0 , - 2.079441541679836 },
373 //        { 1.0 , 9.0 , - 2.19722457733622 },
374         { 1.0 , 10.0 , - 2.302585092994046 },
375         { 1.0 , 11.0 , - 2.397895272798371 },
376         { 1.0 , 12.0 , - 2.484906649788 },
377         { 1.0 , 13.0 , - 2.564949357461537 },
378         { 1.0 , 14.0 , - 2.639057329615258 },
379         { 1.0 , 15.0 , - 2.70805020110221 },
380         { 1.0 , 16.0 , - 2.772588722239781 },
381         { 1.0 , 17.0 , - 2.833213344056216 },
382         { 1.0 , 18.0 , - 2.890371757896165 },
383 //        { 2.0 , 8.0 , - 4.276666119016055 },
384 //        { 2.0 , 9.0 , - 4.499809670330265 },
385         { 2.0 , 10.0 , - 4.700480365792417 },
386         { 2.0 , 11.0 , - 4.882801922586371 },
387         { 2.0 , 12.0 , - 5.049856007249537 },
388         { 2.0 , 13.0 , - 5.204006687076795 },
389         { 2.0 , 14.0 , - 5.347107530717468 },
390         { 2.0 , 15.0 , - 5.480638923341991 },
391         { 2.0 , 16.0 , - 5.605802066295998 },
392         { 2.0 , 17.0 , - 5.723585101952381 },
393         { 2.0 , 18.0 , - 5.834810737062605 },
394 //        { 3.0 , 8.0 , - 6.579251212010101 },
395 //        { 3.0 , 9.0 , - 6.897704943128636 },
396         { 3.0 , 10.0 , - 7.185387015580416 },
397         { 3.0 , 11.0 , - 7.447751280047908 },
398         { 3.0 , 12.0 , - 7.688913336864796 },
399         { 3.0 , 13.0 , - 7.912056888179006 },
400         { 3.0 , 14.0 , - 8.11969625295725 },
401         { 3.0 , 15.0 , - 8.313852267398207 },
402         { 3.0 , 16.0 , - 8.496173824192162 },
403         { 3.0 , 17.0 , - 8.668024081118821 },
404         { 3.0 , 18.0 , - 8.830543010616596 },
405 //        { 4.0 , 8.0 , - 8.977146484808472 },
406 //        { 4.0 , 9.0 , - 9.382611592916636 },
407         { 4.0 , 10.0 , - 9.750336373041954 },
408         { 4.0 , 11.0 , - 10.08680860966317 },
409         { 4.0 , 12.0 , - 10.39696353796701 },
410         { 4.0 , 13.0 , - 10.68464561041879 },
411         { 4.0 , 14.0 , - 10.95290959701347 },
412         { 4.0 , 15.0 , - 11.20422402529437 },
413         { 4.0 , 16.0 , - 11.4406128033586 },
414         { 4.0 , 17.0 , - 11.66375635467281 },
415         { 4.0 , 18.0 , - 11.87506544834002 },
416 //        { 5.0 , 8.0 , - 11.46205313459647 },
417 //        { 5.0 , 9.0 , - 11.94756095037817 },
418         { 5.0 , 10.0 , - 12.38939370265721 },
419         { 5.0 , 11.0 , - 12.79485881076538 },
420         { 5.0 , 12.0 , - 13.16955226020679 },
421         { 5.0 , 13.0 , - 13.517858954475 },
422         { 5.0 , 14.0 , - 13.84328135490963 },
423         { 5.0 , 15.0 , - 14.14866300446081 },
424         { 5.0 , 16.0 , - 14.43634507691259 },
425         { 5.0 , 17.0 , - 14.70827879239624 },
426         { 5.0 , 18.0 , - 14.96610790169833 },
427 //        { 6.0 , 8.0 , - 14.02700249205801 },
428 //        { 6.0 , 9.0 , - 14.58661827999343 },
429         { 6.0 , 10.0 , - 15.09744390375942 },
430         { 6.0 , 11.0 , - 15.56744753300516 },
431         { 6.0 , 12.0 , - 16.002765604263 },
432         { 6.0 , 13.0 , - 16.40823071237117 },
433         { 6.0 , 14.0 , - 16.78772033407607 },
434         { 6.0 , 15.0 , - 17.14439527801481 },
435         { 6.0 , 16.0 , - 17.48086751463602 },
436         { 6.0 , 17.0 , - 17.79932124575455 },
437         { 6.0 , 18.0 , - 18.10160211762749 },
438 //        { 7.0 , 8.0 , - 16.66605982167327 },
439 //        { 7.0 , 9.0 , - 17.29466848109564 },
440         { 7.0 , 10.0 , - 17.8700326259992 },
441         { 7.0 , 11.0 , - 18.40066087706137 },
442         { 7.0 , 12.0 , - 18.89313736215917 },
443         { 7.0 , 13.0 , - 19.35266969153761 },
444         { 7.0 , 14.0 , - 19.78345260763006 },
445         { 7.0 , 15.0 , - 20.18891771573823 },
446         { 7.0 , 16.0 , - 20.57190996799433 },
447         { 7.0 , 17.0 , - 20.9348154616837 },
448         { 7.0 , 18.0 , - 21.27965594797543 },
449 //        { 8.0 , 8.0 , - 19.37411002277548 },
450 //        { 8.0 , 9.0 , - 20.06725720333542 },
451         { 8.0 , 10.0 , - 20.70324597005542 },
452         { 8.0 , 11.0 , - 21.29103263495754 },
453         { 8.0 , 12.0 , - 21.83757634132561 },
454         { 8.0 , 13.0 , - 22.3484019650916 },
455         { 8.0 , 14.0 , - 22.82797504535349 },
456         { 8.0 , 15.0 , - 23.27996016909654 },
457         { 8.0 , 16.0 , - 23.70740418392348 },
458         { 8.0 , 17.0 , - 24.11286929203165 },
459         { 8.0 , 18.0 , - 24.49853177284363 },
460 //        { 9.0 , 8.0 , - 22.14669874501526 },
461 //        { 9.0 , 9.0 , - 22.90047054739164 },
462         { 9.0 , 10.0 , - 23.59361772795159 },
463         { 9.0 , 11.0 , - 24.23547161412398 },
464         { 9.0 , 12.0 , - 24.8333086148796 },
465         { 9.0 , 13.0 , - 25.39292440281502 },
466         { 9.0 , 14.0 , - 25.9190174987118 },
467         { 9.0 , 15.0 , - 26.41545438502569 },
468         { 9.0 , 16.0 , - 26.88545801427143 },
469         { 9.0 , 17.0 , - 27.33174511689985 },
470         { 9.0 , 18.0 , - 27.75662831086511 },
471 //        { 10.0 , 8.0 , - 24.97991208907148 },
472 //        { 10.0 , 9.0 , - 25.7908423052878 },
473         { 10.0 , 10.0 , - 26.53805670711802 },
474         { 10.0 , 11.0 , - 27.23120388767797 },
475         { 10.0 , 12.0 , - 27.87783105260302 },
476         { 10.0 , 13.0 , - 28.48396685617334 },
477         { 10.0 , 14.0 , - 29.05451171464095 },
478         { 10.0 , 15.0 , - 29.59350821537364 },
479         { 10.0 , 16.0 , - 30.10433383913963 },
480         { 10.0 , 17.0 , - 30.58984165492133 },
481         { 10.0 , 18.0 , - 31.05246517686944 },
482     };
483 
484     private static double logGammaMinusLogGammaSum(final double a, final double b) {
485 
486         /*
487          * Use reflection to access private method.
488          */
489         try {
490             final Method m = LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD;
491             return ((Double) m.invoke(null, a, b)).doubleValue();
492         } catch (final IllegalAccessException e) {
493             Assert.fail(e.getMessage());
494         } catch (final IllegalArgumentException e) {
495             Assert.fail(e.getMessage());
496         } catch (final InvocationTargetException e) {
497             final Throwable te = e.getTargetException();
498             if (te instanceof MathIllegalArgumentException) {
499                 throw (MathIllegalArgumentException) te;
500             }
501             Assert.fail(e.getMessage());
502         }
503         return Double.NaN;
504     }
505 
506     @Test
507     public void testLogGammaMinusLogGammaSum() {
508         final int ulps = 4;
509         for (int i = 0; i < LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF.length; i++) {
510             final double[] ref = LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF[i];
511             final double a = ref[0];
512             final double b = ref[1];
513             final double expected = ref[2];
514             final double actual = logGammaMinusLogGammaSum(a, b);
515             final double tol = ulps * FastMath.ulp(expected);
516             final StringBuilder builder = new StringBuilder();
517             builder.append(a).append(", ").append(b);
518             Assert.assertEquals(builder.toString(), expected, actual, tol);
519         }
520     }
521 
522     @Test(expected = MathIllegalArgumentException.class)
523     public void testLogGammaMinusLogGammaSumPrecondition1() {
524         logGammaMinusLogGammaSum(-1.0, 8.0);
525     }
526 
527     @Test(expected = MathIllegalArgumentException.class)
528     public void testLogGammaMinusLogGammaSumPrecondition2() {
529         logGammaMinusLogGammaSum(1.0, 7.0);
530     }
531 
532     private static final double[][] SUM_DELTA_MINUS_DELTA_SUM_REF = {
533         { 10.0 , 10.0 , .01249480717472882 },
534         { 10.0 , 11.0 , .01193628470267385 },
535         { 10.0 , 12.0 , .01148578547212797 },
536         { 10.0 , 13.0 , .01111659739668398 },
537         { 10.0 , 14.0 , .01080991216314295 },
538         { 10.0 , 15.0 , .01055214134859758 },
539         { 10.0 , 16.0 , .01033324912491747 },
540         { 10.0 , 17.0 , .01014568069918883 },
541         { 10.0 , 18.0 , .009983653199146491 },
542         { 10.0 , 19.0 , .009842674320242729 },
543         { 10.0 , 20.0 , 0.0097192081956071 },
544         { 11.0 , 10.0 , .01193628470267385 },
545         { 11.0 , 11.0 , .01135973290745925 },
546         { 11.0 , 12.0 , .01089355537047828 },
547         { 11.0 , 13.0 , .01051064829297728 },
548         { 11.0 , 14.0 , 0.0101918899639826 },
549         { 11.0 , 15.0 , .009923438811859604 },
550         { 11.0 , 16.0 , .009695052724952705 },
551         { 11.0 , 17.0 , 0.00949900745283617 },
552         { 11.0 , 18.0 , .009329379874933402 },
553         { 11.0 , 19.0 , 0.00918156080743147 },
554         { 11.0 , 20.0 , 0.00905191635141762 },
555         { 12.0 , 10.0 , .01148578547212797 },
556         { 12.0 , 11.0 , .01089355537047828 },
557         { 12.0 , 12.0 , .01041365883144029 },
558         { 12.0 , 13.0 , .01001867865848564 },
559         { 12.0 , 14.0 , 0.00968923999191334 },
560         { 12.0 , 15.0 , .009411294976563555 },
561         { 12.0 , 16.0 , .009174432043268762 },
562         { 12.0 , 17.0 , .008970786693291802 },
563         { 12.0 , 18.0 , .008794318926790865 },
564         { 12.0 , 19.0 , .008640321527910711 },
565         { 12.0 , 20.0 , .008505077879954796 },
566         { 13.0 , 10.0 , .01111659739668398 },
567         { 13.0 , 11.0 , .01051064829297728 },
568         { 13.0 , 12.0 , .01001867865848564 },
569         { 13.0 , 13.0 , .009613018147953376 },
570         { 13.0 , 14.0 , .009274085618154277 },
571         { 13.0 , 15.0 , 0.0089876637564166 },
572         { 13.0 , 16.0 , .008743200745261382 },
573         { 13.0 , 17.0 , .008532715206686251 },
574         { 13.0 , 18.0 , .008350069108807093 },
575         { 13.0 , 19.0 , .008190472517984874 },
576         { 13.0 , 20.0 , .008050138630244345 },
577         { 14.0 , 10.0 , .01080991216314295 },
578         { 14.0 , 11.0 , 0.0101918899639826 },
579         { 14.0 , 12.0 , 0.00968923999191334 },
580         { 14.0 , 13.0 , .009274085618154277 },
581         { 14.0 , 14.0 , .008926676241967286 },
582         { 14.0 , 15.0 , .008632654302369184 },
583         { 14.0 , 16.0 , .008381351102615795 },
584         { 14.0 , 17.0 , .008164687232662443 },
585         { 14.0 , 18.0 , .007976441942841219 },
586         { 14.0 , 19.0 , .007811755112234388 },
587         { 14.0 , 20.0 , .007666780069317652 },
588         { 15.0 , 10.0 , .01055214134859758 },
589         { 15.0 , 11.0 , .009923438811859604 },
590         { 15.0 , 12.0 , .009411294976563555 },
591         { 15.0 , 13.0 , 0.0089876637564166 },
592         { 15.0 , 14.0 , .008632654302369184 },
593         { 15.0 , 15.0 , 0.00833179217417291 },
594         { 15.0 , 16.0 , .008074310643041299 },
595         { 15.0 , 17.0 , .007852047581145882 },
596         { 15.0 , 18.0 , .007658712051540045 },
597         { 15.0 , 19.0 , .007489384065757007 },
598         { 15.0 , 20.0 , .007340165635725612 },
599         { 16.0 , 10.0 , .01033324912491747 },
600         { 16.0 , 11.0 , .009695052724952705 },
601         { 16.0 , 12.0 , .009174432043268762 },
602         { 16.0 , 13.0 , .008743200745261382 },
603         { 16.0 , 14.0 , .008381351102615795 },
604         { 16.0 , 15.0 , .008074310643041299 },
605         { 16.0 , 16.0 , .007811229919967624 },
606         { 16.0 , 17.0 , .007583876618287594 },
607         { 16.0 , 18.0 , .007385899933505551 },
608         { 16.0 , 19.0 , .007212328560607852 },
609         { 16.0 , 20.0 , .007059220321091879 },
610         { 17.0 , 10.0 , .01014568069918883 },
611         { 17.0 , 11.0 , 0.00949900745283617 },
612         { 17.0 , 12.0 , .008970786693291802 },
613         { 17.0 , 13.0 , .008532715206686251 },
614         { 17.0 , 14.0 , .008164687232662443 },
615         { 17.0 , 15.0 , .007852047581145882 },
616         { 17.0 , 16.0 , .007583876618287594 },
617         { 17.0 , 17.0 , .007351882161431358 },
618         { 17.0 , 18.0 , .007149662089534654 },
619         { 17.0 , 19.0 , .006972200907152378 },
620         { 17.0 , 20.0 , .006815518216094137 },
621         { 18.0 , 10.0 , .009983653199146491 },
622         { 18.0 , 11.0 , .009329379874933402 },
623         { 18.0 , 12.0 , .008794318926790865 },
624         { 18.0 , 13.0 , .008350069108807093 },
625         { 18.0 , 14.0 , .007976441942841219 },
626         { 18.0 , 15.0 , .007658712051540045 },
627         { 18.0 , 16.0 , .007385899933505551 },
628         { 18.0 , 17.0 , .007149662089534654 },
629         { 18.0 , 18.0 , .006943552208153373 },
630         { 18.0 , 19.0 , .006762516574228829 },
631         { 18.0 , 20.0 , .006602541598043117 },
632         { 19.0 , 10.0 , .009842674320242729 },
633         { 19.0 , 11.0 , 0.00918156080743147 },
634         { 19.0 , 12.0 , .008640321527910711 },
635         { 19.0 , 13.0 , .008190472517984874 },
636         { 19.0 , 14.0 , .007811755112234388 },
637         { 19.0 , 15.0 , .007489384065757007 },
638         { 19.0 , 16.0 , .007212328560607852 },
639         { 19.0 , 17.0 , .006972200907152378 },
640         { 19.0 , 18.0 , .006762516574228829 },
641         { 19.0 , 19.0 , .006578188655176814 },
642         { 19.0 , 20.0 , .006415174623476747 },
643         { 20.0 , 10.0 , 0.0097192081956071 },
644         { 20.0 , 11.0 , 0.00905191635141762 },
645         { 20.0 , 12.0 , .008505077879954796 },
646         { 20.0 , 13.0 , .008050138630244345 },
647         { 20.0 , 14.0 , .007666780069317652 },
648         { 20.0 , 15.0 , .007340165635725612 },
649         { 20.0 , 16.0 , .007059220321091879 },
650         { 20.0 , 17.0 , .006815518216094137 },
651         { 20.0 , 18.0 , .006602541598043117 },
652         { 20.0 , 19.0 , .006415174623476747 },
653         { 20.0 , 20.0 , .006249349445691423 },
654     };
655 
656     private static double sumDeltaMinusDeltaSum(final double a,
657                                                 final double b) {
658 
659         /*
660          * Use reflection to access private method.
661          */
662         try {
663             final Method m = SUM_DELTA_MINUS_DELTA_SUM_METHOD;
664             return ((Double) m.invoke(null, a, b)).doubleValue();
665         } catch (final IllegalAccessException e) {
666             Assert.fail(e.getMessage());
667         } catch (final IllegalArgumentException e) {
668             Assert.fail(e.getMessage());
669         } catch (final InvocationTargetException e) {
670             final Throwable te = e.getTargetException();
671             if (te instanceof MathIllegalArgumentException) {
672                 throw (MathIllegalArgumentException) te;
673             }
674             Assert.fail(e.getMessage());
675         }
676         return Double.NaN;
677     }
678 
679     @Test
680     public void testSumDeltaMinusDeltaSum() {
681 
682         final int ulps = 3;
683         for (int i = 0; i < SUM_DELTA_MINUS_DELTA_SUM_REF.length; i++) {
684             final double[] ref = SUM_DELTA_MINUS_DELTA_SUM_REF[i];
685             final double a = ref[0];
686             final double b = ref[1];
687             final double expected = ref[2];
688             final double actual = sumDeltaMinusDeltaSum(a, b);
689             final double tol = ulps * FastMath.ulp(expected);
690             final StringBuilder builder = new StringBuilder();
691             builder.append(a).append(", ").append(b);
692             Assert.assertEquals(builder.toString(), expected, actual, tol);
693         }
694     }
695 
696     @Test(expected = MathIllegalArgumentException.class)
697     public void testSumDeltaMinusDeltaSumPrecondition1() {
698 
699         sumDeltaMinusDeltaSum(9.0, 10.0);
700     }
701 
702     @Test(expected = MathIllegalArgumentException.class)
703     public void testSumDeltaMinusDeltaSumPrecondition2() {
704 
705         sumDeltaMinusDeltaSum(10.0, 9.0);
706     }
707 
708     private static final double[][] LOG_BETA_REF = {
709         { 0.125 , 0.125 , 2.750814190409515 },
710         { 0.125 , 0.25 , 2.444366899981226 },
711         { 0.125 , 0.5 , 2.230953804989556 },
712         { 0.125 , 1.0 , 2.079441541679836 },
713         { 0.125 , 2.0 , 1.961658506023452 },
714         { 0.125 , 3.0 , 1.901033884207018 },
715         { 0.125 , 4.0 , 1.860211889686763 },
716         { 0.125 , 5.0 , 1.829440231020009 },
717         { 0.125 , 6.0 , 1.804747618429637 },
718         { 0.125 , 7.0 , 1.784128331226902 },
719         { 0.125 , 8.0 , 1.766428754127501 },
720         { 0.125 , 9.0 , 1.750924567591535 },
721         { 0.125 , 10.0 , 1.7371312454592 },
722         { 0.125 , 1000.0 , 1.156003642015969 },
723         { 0.125 , 1001.0 , 1.155878649827818 },
724         { 0.125 , 10000.0 , .8681312798751318 },
725         { 0.25 , 0.125 , 2.444366899981226 },
726         { 0.25 , 0.25 , 2.003680106471455 },
727         { 0.25 , 0.5 , 1.657106516191482 },
728         { 0.25 , 1.0 , 1.386294361119891 },
729         { 0.25 , 2.0 , 1.163150809805681 },
730         { 0.25 , 3.0 , 1.045367774149297 },
731         { 0.25 , 4.0 , 0.965325066475761 },
732         { 0.25 , 5.0 , .9047004446593261 },
733         { 0.25 , 6.0 , .8559102804898941 },
734         { 0.25 , 7.0 , 0.815088285969639 },
735         { 0.25 , 8.0 , .7799969661583689 },
736         { 0.25 , 9.0 , .7492253074916152 },
737         { 0.25 , 10.0 , .7218263333035008 },
738         { 0.25 , 1000.0 , - .4388225372378877 },
739         { 0.25 , 1001.0 , - .4390725059930951 },
740         { 0.25 , 10000.0 , - 1.014553193217846 },
741         { 0.5 , 0.125 , 2.230953804989556 },
742         { 0.5 , 0.25 , 1.657106516191482 },
743         { 0.5 , 0.5 , 1.1447298858494 },
744         { 0.5 , 1.0 , .6931471805599453 },
745         { 0.5 , 2.0 , .2876820724517809 },
746         { 0.5 , 3.0 , .06453852113757118 },
747 //        { 0.5 , 4.0 , - .08961215868968714 },
748         { 0.5 , 5.0 , - .2073951943460706 },
749         { 0.5 , 6.0 , - .3027053741503954 },
750         { 0.5 , 7.0 , - .3827480818239319 },
751         { 0.5 , 8.0 , - .4517409533108833 },
752         { 0.5 , 9.0 , - .5123655751273182 },
753         { 0.5 , 10.0 , - .5664327963975939 },
754         { 0.5 , 1000.0 , - 2.881387696571577 },
755         { 0.5 , 1001.0 , - 2.881887571613228 },
756         { 0.5 , 10000.0 , - 4.032792743063396 },
757         { 1.0 , 0.125 , 2.079441541679836 },
758         { 1.0 , 0.25 , 1.386294361119891 },
759         { 1.0 , 0.5 , .6931471805599453 },
760         { 1.0 , 1.0 , 0.0 },
761         { 1.0 , 2.0 , - .6931471805599453 },
762         { 1.0 , 3.0 , - 1.09861228866811 },
763         { 1.0 , 4.0 , - 1.386294361119891 },
764         { 1.0 , 5.0 , - 1.6094379124341 },
765         { 1.0 , 6.0 , - 1.791759469228055 },
766         { 1.0 , 7.0 , - 1.945910149055313 },
767         { 1.0 , 8.0 , - 2.079441541679836 },
768         { 1.0 , 9.0 , - 2.19722457733622 },
769         { 1.0 , 10.0 , - 2.302585092994046 },
770         { 1.0 , 1000.0 , - 6.907755278982137 },
771         { 1.0 , 1001.0 , - 6.90875477931522 },
772         { 1.0 , 10000.0 , - 9.210340371976184 },
773         { 2.0 , 0.125 , 1.961658506023452 },
774         { 2.0 , 0.25 , 1.163150809805681 },
775         { 2.0 , 0.5 , .2876820724517809 },
776         { 2.0 , 1.0 , - .6931471805599453 },
777         { 2.0 , 2.0 , - 1.791759469228055 },
778         { 2.0 , 3.0 , - 2.484906649788 },
779         { 2.0 , 4.0 , - 2.995732273553991 },
780         { 2.0 , 5.0 , - 3.401197381662155 },
781         { 2.0 , 6.0 , - 3.737669618283368 },
782         { 2.0 , 7.0 , - 4.02535169073515 },
783         { 2.0 , 8.0 , - 4.276666119016055 },
784         { 2.0 , 9.0 , - 4.499809670330265 },
785         { 2.0 , 10.0 , - 4.700480365792417 },
786         { 2.0 , 1000.0 , - 13.81651005829736 },
787         { 2.0 , 1001.0 , - 13.81850806096003 },
788         { 2.0 , 10000.0 , - 18.4207807389527 },
789         { 3.0 , 0.125 , 1.901033884207018 },
790         { 3.0 , 0.25 , 1.045367774149297 },
791         { 3.0 , 0.5 , .06453852113757118 },
792         { 3.0 , 1.0 , - 1.09861228866811 },
793         { 3.0 , 2.0 , - 2.484906649788 },
794         { 3.0 , 3.0 , - 3.401197381662155 },
795         { 3.0 , 4.0 , - 4.0943445622221 },
796         { 3.0 , 5.0 , - 4.653960350157523 },
797         { 3.0 , 6.0 , - 5.123963979403259 },
798         { 3.0 , 7.0 , - 5.529429087511423 },
799         { 3.0 , 8.0 , - 5.886104031450156 },
800         { 3.0 , 9.0 , - 6.20455776256869 },
801         { 3.0 , 10.0 , - 6.492239835020471 },
802         { 3.0 , 1000.0 , - 20.03311615938222 },
803         { 3.0 , 1001.0 , - 20.03611166836202 },
804         { 3.0 , 10000.0 , - 26.9381739103716 },
805         { 4.0 , 0.125 , 1.860211889686763 },
806         { 4.0 , 0.25 , 0.965325066475761 },
807 //        { 4.0 , 0.5 , - .08961215868968714 },
808         { 4.0 , 1.0 , - 1.386294361119891 },
809         { 4.0 , 2.0 , - 2.995732273553991 },
810         { 4.0 , 3.0 , - 4.0943445622221 },
811         { 4.0 , 4.0 , - 4.941642422609304 },
812         { 4.0 , 5.0 , - 5.634789603169249 },
813         { 4.0 , 6.0 , - 6.222576268071369 },
814         { 4.0 , 7.0 , - 6.733401891837359 },
815         { 4.0 , 8.0 , - 7.185387015580416 },
816         { 4.0 , 9.0 , - 7.590852123688581 },
817         { 4.0 , 10.0 , - 7.958576903813898 },
818         { 4.0 , 1000.0 , - 25.84525465867605 },
819         { 4.0 , 1001.0 , - 25.84924667994559 },
820         { 4.0 , 10000.0 , - 35.05020194868867 },
821         { 5.0 , 0.125 , 1.829440231020009 },
822         { 5.0 , 0.25 , .9047004446593261 },
823         { 5.0 , 0.5 , - .2073951943460706 },
824         { 5.0 , 1.0 , - 1.6094379124341 },
825         { 5.0 , 2.0 , - 3.401197381662155 },
826         { 5.0 , 3.0 , - 4.653960350157523 },
827         { 5.0 , 4.0 , - 5.634789603169249 },
828         { 5.0 , 5.0 , - 6.445719819385578 },
829         { 5.0 , 6.0 , - 7.138866999945524 },
830         { 5.0 , 7.0 , - 7.745002803515839 },
831         { 5.0 , 8.0 , - 8.283999304248526 },
832         { 5.0 , 9.0 , - 8.769507120030227 },
833         { 5.0 , 10.0 , - 9.211339872309265 },
834         { 5.0 , 1000.0 , - 31.37070759780783 },
835         { 5.0 , 1001.0 , - 31.37569513931887 },
836         { 5.0 , 10000.0 , - 42.87464787956629 },
837         { 6.0 , 0.125 , 1.804747618429637 },
838         { 6.0 , 0.25 , .8559102804898941 },
839         { 6.0 , 0.5 , - .3027053741503954 },
840         { 6.0 , 1.0 , - 1.791759469228055 },
841         { 6.0 , 2.0 , - 3.737669618283368 },
842         { 6.0 , 3.0 , - 5.123963979403259 },
843         { 6.0 , 4.0 , - 6.222576268071369 },
844         { 6.0 , 5.0 , - 7.138866999945524 },
845         { 6.0 , 6.0 , - 7.927324360309794 },
846         { 6.0 , 7.0 , - 8.620471540869739 },
847         { 6.0 , 8.0 , - 9.239510749275963 },
848         { 6.0 , 9.0 , - 9.799126537211386 },
849         { 6.0 , 10.0 , - 10.30995216097738 },
850         { 6.0 , 1000.0 , - 36.67401250586691 },
851         { 6.0 , 1001.0 , - 36.67999457754446 },
852         { 6.0 , 10000.0 , - 50.47605021415003 },
853         { 7.0 , 0.125 , 1.784128331226902 },
854         { 7.0 , 0.25 , 0.815088285969639 },
855         { 7.0 , 0.5 , - .3827480818239319 },
856         { 7.0 , 1.0 , - 1.945910149055313 },
857         { 7.0 , 2.0 , - 4.02535169073515 },
858         { 7.0 , 3.0 , - 5.529429087511423 },
859         { 7.0 , 4.0 , - 6.733401891837359 },
860         { 7.0 , 5.0 , - 7.745002803515839 },
861         { 7.0 , 6.0 , - 8.620471540869739 },
862         { 7.0 , 7.0 , - 9.39366142910322 },
863         { 7.0 , 8.0 , - 10.08680860966317 },
864         { 7.0 , 9.0 , - 10.71541726908554 },
865         { 7.0 , 10.0 , - 11.2907814139891 },
866         { 7.0 , 1000.0 , - 41.79599038729854 },
867         { 7.0 , 1001.0 , - 41.80296600103496 },
868         { 7.0 , 10000.0 , - 57.89523093697012 },
869         { 8.0 , 0.125 , 1.766428754127501 },
870         { 8.0 , 0.25 , .7799969661583689 },
871         { 8.0 , 0.5 , - .4517409533108833 },
872         { 8.0 , 1.0 , - 2.079441541679836 },
873         { 8.0 , 2.0 , - 4.276666119016055 },
874         { 8.0 , 3.0 , - 5.886104031450156 },
875         { 8.0 , 4.0 , - 7.185387015580416 },
876         { 8.0 , 5.0 , - 8.283999304248526 },
877         { 8.0 , 6.0 , - 9.239510749275963 },
878         { 8.0 , 7.0 , - 10.08680860966317 },
879         { 8.0 , 8.0 , - 10.84894866171006 },
880         { 8.0 , 9.0 , - 11.54209584227001 },
881         { 8.0 , 10.0 , - 12.17808460899001 },
882         { 8.0 , 1000.0 , - 46.76481113096179 },
883         { 8.0 , 1001.0 , - 46.77277930061096 },
884         { 8.0 , 10000.0 , - 65.16036091500527 },
885         { 9.0 , 0.125 , 1.750924567591535 },
886         { 9.0 , 0.25 , .7492253074916152 },
887         { 9.0 , 0.5 , - .5123655751273182 },
888         { 9.0 , 1.0 , - 2.19722457733622 },
889         { 9.0 , 2.0 , - 4.499809670330265 },
890         { 9.0 , 3.0 , - 6.20455776256869 },
891         { 9.0 , 4.0 , - 7.590852123688581 },
892         { 9.0 , 5.0 , - 8.769507120030227 },
893         { 9.0 , 6.0 , - 9.799126537211386 },
894         { 9.0 , 7.0 , - 10.71541726908554 },
895         { 9.0 , 8.0 , - 11.54209584227001 },
896         { 9.0 , 9.0 , - 12.29586764464639 },
897         { 9.0 , 10.0 , - 12.98901482520633 },
898         { 9.0 , 1000.0 , - 51.60109303791327 },
899         { 9.0 , 1001.0 , - 51.61005277928474 },
900         { 9.0 , 10000.0 , - 72.29205942547217 },
901         { 10.0 , 0.125 , 1.7371312454592 },
902         { 10.0 , 0.25 , .7218263333035008 },
903         { 10.0 , 0.5 , - .5664327963975939 },
904         { 10.0 , 1.0 , - 2.302585092994046 },
905         { 10.0 , 2.0 , - 4.700480365792417 },
906         { 10.0 , 3.0 , - 6.492239835020471 },
907         { 10.0 , 4.0 , - 7.958576903813898 },
908         { 10.0 , 5.0 , - 9.211339872309265 },
909         { 10.0 , 6.0 , - 10.30995216097738 },
910         { 10.0 , 7.0 , - 11.2907814139891 },
911         { 10.0 , 8.0 , - 12.17808460899001 },
912         { 10.0 , 9.0 , - 12.98901482520633 },
913         { 10.0 , 10.0 , - 13.73622922703655 },
914         { 10.0 , 1000.0 , - 56.32058348093065 },
915         { 10.0 , 1001.0 , - 56.33053381178382 },
916         { 10.0 , 10000.0 , - 79.30607481535498 },
917         { 1000.0 , 0.125 , 1.156003642015969 },
918         { 1000.0 , 0.25 , - .4388225372378877 },
919         { 1000.0 , 0.5 , - 2.881387696571577 },
920         { 1000.0 , 1.0 , - 6.907755278982137 },
921         { 1000.0 , 2.0 , - 13.81651005829736 },
922         { 1000.0 , 3.0 , - 20.03311615938222 },
923         { 1000.0 , 4.0 , - 25.84525465867605 },
924         { 1000.0 , 5.0 , - 31.37070759780783 },
925         { 1000.0 , 6.0 , - 36.67401250586691 },
926         { 1000.0 , 7.0 , - 41.79599038729854 },
927         { 1000.0 , 8.0 , - 46.76481113096179 },
928         { 1000.0 , 9.0 , - 51.60109303791327 },
929         { 1000.0 , 10.0 , - 56.32058348093065 },
930         { 1000.0 , 1000.0 , - 1388.482601635902 },
931         { 1000.0 , 1001.0 , - 1389.175748816462 },
932         { 1000.0 , 10000.0 , - 3353.484270767097 },
933         { 1001.0 , 0.125 , 1.155878649827818 },
934         { 1001.0 , 0.25 , - .4390725059930951 },
935         { 1001.0 , 0.5 , - 2.881887571613228 },
936         { 1001.0 , 1.0 , - 6.90875477931522 },
937         { 1001.0 , 2.0 , - 13.81850806096003 },
938         { 1001.0 , 3.0 , - 20.03611166836202 },
939         { 1001.0 , 4.0 , - 25.84924667994559 },
940         { 1001.0 , 5.0 , - 31.37569513931887 },
941         { 1001.0 , 6.0 , - 36.67999457754446 },
942         { 1001.0 , 7.0 , - 41.80296600103496 },
943         { 1001.0 , 8.0 , - 46.77277930061096 },
944         { 1001.0 , 9.0 , - 51.61005277928474 },
945         { 1001.0 , 10.0 , - 56.33053381178382 },
946         { 1001.0 , 1000.0 , - 1389.175748816462 },
947         { 1001.0 , 1001.0 , - 1389.869395872064 },
948         { 1001.0 , 10000.0 , - 3355.882166039895 },
949         { 10000.0 , 0.125 , .8681312798751318 },
950         { 10000.0 , 0.25 , - 1.014553193217846 },
951         { 10000.0 , 0.5 , - 4.032792743063396 },
952         { 10000.0 , 1.0 , - 9.210340371976184 },
953         { 10000.0 , 2.0 , - 18.4207807389527 },
954         { 10000.0 , 3.0 , - 26.9381739103716 },
955         { 10000.0 , 4.0 , - 35.05020194868867 },
956         { 10000.0 , 5.0 , - 42.87464787956629 },
957         { 10000.0 , 6.0 , - 50.47605021415003 },
958         { 10000.0 , 7.0 , - 57.89523093697012 },
959         { 10000.0 , 8.0 , - 65.16036091500527 },
960         { 10000.0 , 9.0 , - 72.29205942547217 },
961         { 10000.0 , 10.0 , - 79.30607481535498 },
962         { 10000.0 , 1000.0 , - 3353.484270767097 },
963         { 10000.0 , 1001.0 , - 3355.882166039895 },
964         { 10000.0 , 10000.0 , - 13866.28325676141 },
965     };
966 
967     @Test
968     public void testLogBeta() {
969         final int ulps = 3;
970         for (int i = 0; i < LOG_BETA_REF.length; i++) {
971             final double[] ref = LOG_BETA_REF[i];
972             final double a = ref[0];
973             final double b = ref[1];
974             final double expected = ref[2];
975             final double actual = Beta.logBeta(a, b);
976             final double tol = ulps * FastMath.ulp(expected);
977             final StringBuilder builder = new StringBuilder();
978             builder.append(a).append(", ").append(b);
979             Assert.assertEquals(builder.toString(), expected, actual, tol);
980         }
981     }}