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