Xmipp  v3.23.11-Nereus
specialfunctions.h
Go to the documentation of this file.
1 /*************************************************************************
2 Copyright (c) Sergey Bochkanov (ALGLIB project).
3 
4 >>> SOURCE LICENSE >>>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation (www.fsf.org); either version 2 of the
8 License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 A copy of the GNU General Public License is available at
16 http://www.fsf.org/licensing/licenses
17 >>> END OF LICENSE >>>
18 *************************************************************************/
19 #ifndef _specialfunctions_pkg_h
20 #define _specialfunctions_pkg_h
21 #include "ap.h"
22 #include "alglibinternal.h"
23 
25 //
26 // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
27 //
29 namespace alglib_impl
30 {
31 
32 }
33 
35 //
36 // THIS SECTION CONTAINS C++ INTERFACE
37 //
39 namespace alglib
40 {
41 
42 
43 /*************************************************************************
44 Gamma function
45 
46 Input parameters:
47  X - argument
48 
49 Domain:
50  0 < X < 171.6
51  -170 < X < 0, X is not an integer.
52 
53 Relative error:
54  arithmetic domain # trials peak rms
55  IEEE -170,-33 20000 2.3e-15 3.3e-16
56  IEEE -33, 33 20000 9.4e-16 2.2e-16
57  IEEE 33, 171.6 20000 2.3e-15 3.2e-16
58 
59 Cephes Math Library Release 2.8: June, 2000
60 Original copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
61 Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
62 *************************************************************************/
63 double gammafunction(const double x);
64 
65 
66 /*************************************************************************
67 Natural logarithm of gamma function
68 
69 Input parameters:
70  X - argument
71 
72 Result:
73  logarithm of the absolute value of the Gamma(X).
74 
75 Output parameters:
76  SgnGam - sign(Gamma(X))
77 
78 Domain:
79  0 < X < 2.55e305
80  -2.55e305 < X < 0, X is not an integer.
81 
82 ACCURACY:
83 arithmetic domain # trials peak rms
84  IEEE 0, 3 28000 5.4e-16 1.1e-16
85  IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17
86 The error criterion was relative when the function magnitude
87 was greater than one but absolute when it was less than one.
88 
89 The following test used the relative error criterion, though
90 at certain points the relative error could be much higher than
91 indicated.
92  IEEE -200, -4 10000 4.8e-16 1.3e-16
93 
94 Cephes Math Library Release 2.8: June, 2000
95 Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
96 Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
97 *************************************************************************/
98 double lngamma(const double x, double &sgngam);
99 
100 /*************************************************************************
101 Error function
102 
103 The integral is
104 
105  x
106  -
107  2 | | 2
108  erf(x) = -------- | exp( - t ) dt.
109  sqrt(pi) | |
110  -
111  0
112 
113 For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
114 erf(x) = 1 - erfc(x).
115 
116 
117 ACCURACY:
118 
119  Relative error:
120 arithmetic domain # trials peak rms
121  IEEE 0,1 30000 3.7e-16 1.0e-16
122 
123 Cephes Math Library Release 2.8: June, 2000
124 Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
125 *************************************************************************/
126 double errorfunction(const double x);
127 
128 
129 /*************************************************************************
130 Complementary error function
131 
132  1 - erf(x) =
133 
134  inf.
135  -
136  2 | | 2
137  erfc(x) = -------- | exp( - t ) dt
138  sqrt(pi) | |
139  -
140  x
141 
142 
143 For small x, erfc(x) = 1 - erf(x); otherwise rational
144 approximations are computed.
145 
146 
147 ACCURACY:
148 
149  Relative error:
150 arithmetic domain # trials peak rms
151  IEEE 0,26.6417 30000 5.7e-14 1.5e-14
152 
153 Cephes Math Library Release 2.8: June, 2000
154 Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
155 *************************************************************************/
156 double errorfunctionc(const double x);
157 
158 
159 /*************************************************************************
160 Normal distribution function
161 
162 Returns the area under the Gaussian probability density
163 function, integrated from minus infinity to x:
164 
165  x
166  -
167  1 | | 2
168  ndtr(x) = --------- | exp( - t /2 ) dt
169  sqrt(2pi) | |
170  -
171  -inf.
172 
173  = ( 1 + erf(z) ) / 2
174  = erfc(z) / 2
175 
176 where z = x/sqrt(2). Computation is via the functions
177 erf and erfc.
178 
179 
180 ACCURACY:
181 
182  Relative error:
183 arithmetic domain # trials peak rms
184  IEEE -13,0 30000 3.4e-14 6.7e-15
185 
186 Cephes Math Library Release 2.8: June, 2000
187 Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
188 *************************************************************************/
189 double normaldistribution(const double x);
190 
191 
192 /*************************************************************************
193 Inverse of the error function
194 
195 Cephes Math Library Release 2.8: June, 2000
196 Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
197 *************************************************************************/
198 double inverf(const double e);
199 
200 
201 /*************************************************************************
202 Inverse of Normal distribution function
203 
204 Returns the argument, x, for which the area under the
205 Gaussian probability density function (integrated from
206 minus infinity to x) is equal to y.
207 
208 
209 For small arguments 0 < y < exp(-2), the program computes
210 z = sqrt( -2.0 * log(y) ); then the approximation is
211 x = z - log(z)/z - (1/z) P(1/z) / Q(1/z).
212 There are two rational functions P/Q, one for 0 < y < exp(-32)
213 and the other for y up to exp(-2). For larger arguments,
214 w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).
215 
216 ACCURACY:
217 
218  Relative error:
219 arithmetic domain # trials peak rms
220  IEEE 0.125, 1 20000 7.2e-16 1.3e-16
221  IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17
222 
223 Cephes Math Library Release 2.8: June, 2000
224 Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
225 *************************************************************************/
226 double invnormaldistribution(const double y0);
227 
228 /*************************************************************************
229 Incomplete gamma integral
230 
231 The function is defined by
232 
233  x
234  -
235  1 | | -t a-1
236  igam(a,x) = ----- | e t dt.
237  - | |
238  | (a) -
239  0
240 
241 
242 In this implementation both arguments must be positive.
243 The integral is evaluated by either a power series or
244 continued fraction expansion, depending on the relative
245 values of a and x.
246 
247 ACCURACY:
248 
249  Relative error:
250 arithmetic domain # trials peak rms
251  IEEE 0,30 200000 3.6e-14 2.9e-15
252  IEEE 0,100 300000 9.9e-14 1.5e-14
253 
254 Cephes Math Library Release 2.8: June, 2000
255 Copyright 1985, 1987, 2000 by Stephen L. Moshier
256 *************************************************************************/
257 double incompletegamma(const double a, const double x);
258 
259 
260 /*************************************************************************
261 Complemented incomplete gamma integral
262 
263 The function is defined by
264 
265 
266  igamc(a,x) = 1 - igam(a,x)
267 
268  inf.
269  -
270  1 | | -t a-1
271  = ----- | e t dt.
272  - | |
273  | (a) -
274  x
275 
276 
277 In this implementation both arguments must be positive.
278 The integral is evaluated by either a power series or
279 continued fraction expansion, depending on the relative
280 values of a and x.
281 
282 ACCURACY:
283 
284 Tested at random a, x.
285  a x Relative error:
286 arithmetic domain domain # trials peak rms
287  IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
288  IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
289 
290 Cephes Math Library Release 2.8: June, 2000
291 Copyright 1985, 1987, 2000 by Stephen L. Moshier
292 *************************************************************************/
293 double incompletegammac(const double a, const double x);
294 
295 
296 /*************************************************************************
297 Inverse of complemented incomplete gamma integral
298 
299 Given p, the function finds x such that
300 
301  igamc( a, x ) = p.
302 
303 Starting with the approximate value
304 
305  3
306  x = a t
307 
308  where
309 
310  t = 1 - d - ndtri(p) sqrt(d)
311 
312 and
313 
314  d = 1/9a,
315 
316 the routine performs up to 10 Newton iterations to find the
317 root of igamc(a,x) - p = 0.
318 
319 ACCURACY:
320 
321 Tested at random a, p in the intervals indicated.
322 
323  a p Relative error:
324 arithmetic domain domain # trials peak rms
325  IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
326  IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
327  IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
328 
329 Cephes Math Library Release 2.8: June, 2000
330 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
331 *************************************************************************/
332 double invincompletegammac(const double a, const double y0);
333 
334 /*************************************************************************
335 Airy function
336 
337 Solution of the differential equation
338 
339 y"(x) = xy.
340 
341 The function returns the two independent solutions Ai, Bi
342 and their first derivatives Ai'(x), Bi'(x).
343 
344 Evaluation is by power series summation for small x,
345 by rational minimax approximations for large x.
346 
347 
348 
349 ACCURACY:
350 Error criterion is absolute when function <= 1, relative
351 when function > 1, except * denotes relative error criterion.
352 For large negative x, the absolute error increases as x^1.5.
353 For large positive x, the relative error increases as x^1.5.
354 
355 Arithmetic domain function # trials peak rms
356 IEEE -10, 0 Ai 10000 1.6e-15 2.7e-16
357 IEEE 0, 10 Ai 10000 2.3e-14* 1.8e-15*
358 IEEE -10, 0 Ai' 10000 4.6e-15 7.6e-16
359 IEEE 0, 10 Ai' 10000 1.8e-14* 1.5e-15*
360 IEEE -10, 10 Bi 30000 4.2e-15 5.3e-16
361 IEEE -10, 10 Bi' 30000 4.9e-15 7.3e-16
362 
363 Cephes Math Library Release 2.8: June, 2000
364 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
365 *************************************************************************/
366 void airy(const double x, double &ai, double &aip, double &bi, double &bip);
367 
368 /*************************************************************************
369 Bessel function of order zero
370 
371 Returns Bessel function of order zero of the argument.
372 
373 The domain is divided into the intervals [0, 5] and
374 (5, infinity). In the first interval the following rational
375 approximation is used:
376 
377 
378  2 2
379 (w - r ) (w - r ) P (w) / Q (w)
380  1 2 3 8
381 
382  2
383 where w = x and the two r's are zeros of the function.
384 
385 In the second interval, the Hankel asymptotic expansion
386 is employed with two rational functions of degree 6/6
387 and 7/7.
388 
389 ACCURACY:
390 
391  Absolute error:
392 arithmetic domain # trials peak rms
393  IEEE 0, 30 60000 4.2e-16 1.1e-16
394 
395 Cephes Math Library Release 2.8: June, 2000
396 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
397 *************************************************************************/
398 double besselj0(const double x);
399 
400 
401 /*************************************************************************
402 Bessel function of order one
403 
404 Returns Bessel function of order one of the argument.
405 
406 The domain is divided into the intervals [0, 8] and
407 (8, infinity). In the first interval a 24 term Chebyshev
408 expansion is used. In the second, the asymptotic
409 trigonometric representation is employed using two
410 rational functions of degree 5/5.
411 
412 ACCURACY:
413 
414  Absolute error:
415 arithmetic domain # trials peak rms
416  IEEE 0, 30 30000 2.6e-16 1.1e-16
417 
418 Cephes Math Library Release 2.8: June, 2000
419 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
420 *************************************************************************/
421 double besselj1(const double x);
422 
423 
424 /*************************************************************************
425 Bessel function of integer order
426 
427 Returns Bessel function of order n, where n is a
428 (possibly negative) integer.
429 
430 The ratio of jn(x) to j0(x) is computed by backward
431 recurrence. First the ratio jn/jn-1 is found by a
432 continued fraction expansion. Then the recurrence
433 relating successive orders is applied until j0 or j1 is
434 reached.
435 
436 If n = 0 or 1 the routine for j0 or j1 is called
437 directly.
438 
439 ACCURACY:
440 
441  Absolute error:
442 arithmetic range # trials peak rms
443  IEEE 0, 30 5000 4.4e-16 7.9e-17
444 
445 
446 Not suitable for large n or x. Use jv() (fractional order) instead.
447 
448 Cephes Math Library Release 2.8: June, 2000
449 Copyright 1984, 1987, 2000 by Stephen L. Moshier
450 *************************************************************************/
451 double besseljn(const ae_int_t n, const double x);
452 
453 
454 /*************************************************************************
455 Bessel function of the second kind, order zero
456 
457 Returns Bessel function of the second kind, of order
458 zero, of the argument.
459 
460 The domain is divided into the intervals [0, 5] and
461 (5, infinity). In the first interval a rational approximation
462 R(x) is employed to compute
463  y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
464 Thus a call to j0() is required.
465 
466 In the second interval, the Hankel asymptotic expansion
467 is employed with two rational functions of degree 6/6
468 and 7/7.
469 
470 
471 
472 ACCURACY:
473 
474  Absolute error, when y0(x) < 1; else relative error:
475 
476 arithmetic domain # trials peak rms
477  IEEE 0, 30 30000 1.3e-15 1.6e-16
478 
479 Cephes Math Library Release 2.8: June, 2000
480 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
481 *************************************************************************/
482 double bessely0(const double x);
483 
484 
485 /*************************************************************************
486 Bessel function of second kind of order one
487 
488 Returns Bessel function of the second kind of order one
489 of the argument.
490 
491 The domain is divided into the intervals [0, 8] and
492 (8, infinity). In the first interval a 25 term Chebyshev
493 expansion is used, and a call to j1() is required.
494 In the second, the asymptotic trigonometric representation
495 is employed using two rational functions of degree 5/5.
496 
497 ACCURACY:
498 
499  Absolute error:
500 arithmetic domain # trials peak rms
501  IEEE 0, 30 30000 1.0e-15 1.3e-16
502 
503 Cephes Math Library Release 2.8: June, 2000
504 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
505 *************************************************************************/
506 double bessely1(const double x);
507 
508 
509 /*************************************************************************
510 Bessel function of second kind of integer order
511 
512 Returns Bessel function of order n, where n is a
513 (possibly negative) integer.
514 
515 The function is evaluated by forward recurrence on
516 n, starting with values computed by the routines
517 y0() and y1().
518 
519 If n = 0 or 1 the routine for y0 or y1 is called
520 directly.
521 
522 ACCURACY:
523  Absolute error, except relative
524  when y > 1:
525 arithmetic domain # trials peak rms
526  IEEE 0, 30 30000 3.4e-15 4.3e-16
527 
528 Cephes Math Library Release 2.8: June, 2000
529 Copyright 1984, 1987, 2000 by Stephen L. Moshier
530 *************************************************************************/
531 double besselyn(const ae_int_t n, const double x);
532 
533 
534 /*************************************************************************
535 Modified Bessel function of order zero
536 
537 Returns modified Bessel function of order zero of the
538 argument.
539 
540 The function is defined as i0(x) = j0( ix ).
541 
542 The range is partitioned into the two intervals [0,8] and
543 (8, infinity). Chebyshev polynomial expansions are employed
544 in each interval.
545 
546 ACCURACY:
547 
548  Relative error:
549 arithmetic domain # trials peak rms
550  IEEE 0,30 30000 5.8e-16 1.4e-16
551 
552 Cephes Math Library Release 2.8: June, 2000
553 Copyright 1984, 1987, 2000 by Stephen L. Moshier
554 *************************************************************************/
555 double besseli0(const double x);
556 
557 
558 /*************************************************************************
559 Modified Bessel function of order one
560 
561 Returns modified Bessel function of order one of the
562 argument.
563 
564 The function is defined as i1(x) = -i j1( ix ).
565 
566 The range is partitioned into the two intervals [0,8] and
567 (8, infinity). Chebyshev polynomial expansions are employed
568 in each interval.
569 
570 ACCURACY:
571 
572  Relative error:
573 arithmetic domain # trials peak rms
574  IEEE 0, 30 30000 1.9e-15 2.1e-16
575 
576 Cephes Math Library Release 2.8: June, 2000
577 Copyright 1985, 1987, 2000 by Stephen L. Moshier
578 *************************************************************************/
579 double besseli1(const double x);
580 
581 
582 /*************************************************************************
583 Modified Bessel function, second kind, order zero
584 
585 Returns modified Bessel function of the second kind
586 of order zero of the argument.
587 
588 The range is partitioned into the two intervals [0,8] and
589 (8, infinity). Chebyshev polynomial expansions are employed
590 in each interval.
591 
592 ACCURACY:
593 
594 Tested at 2000 random points between 0 and 8. Peak absolute
595 error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
596  Relative error:
597 arithmetic domain # trials peak rms
598  IEEE 0, 30 30000 1.2e-15 1.6e-16
599 
600 Cephes Math Library Release 2.8: June, 2000
601 Copyright 1984, 1987, 2000 by Stephen L. Moshier
602 *************************************************************************/
603 double besselk0(const double x);
604 
605 
606 /*************************************************************************
607 Modified Bessel function, second kind, order one
608 
609 Computes the modified Bessel function of the second kind
610 of order one of the argument.
611 
612 The range is partitioned into the two intervals [0,2] and
613 (2, infinity). Chebyshev polynomial expansions are employed
614 in each interval.
615 
616 ACCURACY:
617 
618  Relative error:
619 arithmetic domain # trials peak rms
620  IEEE 0, 30 30000 1.2e-15 1.6e-16
621 
622 Cephes Math Library Release 2.8: June, 2000
623 Copyright 1984, 1987, 2000 by Stephen L. Moshier
624 *************************************************************************/
625 double besselk1(const double x);
626 
627 
628 /*************************************************************************
629 Modified Bessel function, second kind, integer order
630 
631 Returns modified Bessel function of the second kind
632 of order n of the argument.
633 
634 The range is partitioned into the two intervals [0,9.55] and
635 (9.55, infinity). An ascending power series is used in the
636 low range, and an asymptotic expansion in the high range.
637 
638 ACCURACY:
639 
640  Relative error:
641 arithmetic domain # trials peak rms
642  IEEE 0,30 90000 1.8e-8 3.0e-10
643 
644 Error is high only near the crossover point x = 9.55
645 between the two expansions used.
646 
647 Cephes Math Library Release 2.8: June, 2000
648 Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
649 *************************************************************************/
650 double besselkn(const ae_int_t nn, const double x);
651 
652 /*************************************************************************
653 Beta function
654 
655 
656  - -
657  | (a) | (b)
658 beta( a, b ) = -----------.
659  -
660  | (a+b)
661 
662 For large arguments the logarithm of the function is
663 evaluated using lgam(), then exponentiated.
664 
665 ACCURACY:
666 
667  Relative error:
668 arithmetic domain # trials peak rms
669  IEEE 0,30 30000 8.1e-14 1.1e-14
670 
671 Cephes Math Library Release 2.0: April, 1987
672 Copyright 1984, 1987 by Stephen L. Moshier
673 *************************************************************************/
674 double beta(const double a, const double b);
675 
676 /*************************************************************************
677 Incomplete beta integral
678 
679 Returns incomplete beta integral of the arguments, evaluated
680 from zero to x. The function is defined as
681 
682  x
683  - -
684  | (a+b) | | a-1 b-1
685  ----------- | t (1-t) dt.
686  - - | |
687  | (a) | (b) -
688  0
689 
690 The domain of definition is 0 <= x <= 1. In this
691 implementation a and b are restricted to positive values.
692 The integral from x to 1 may be obtained by the symmetry
693 relation
694 
695  1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
696 
697 The integral is evaluated by a continued fraction expansion
698 or, when b*x is small, by a power series.
699 
700 ACCURACY:
701 
702 Tested at uniformly distributed random points (a,b,x) with a and b
703 in "domain" and x between 0 and 1.
704  Relative error
705 arithmetic domain # trials peak rms
706  IEEE 0,5 10000 6.9e-15 4.5e-16
707  IEEE 0,85 250000 2.2e-13 1.7e-14
708  IEEE 0,1000 30000 5.3e-12 6.3e-13
709  IEEE 0,10000 250000 9.3e-11 7.1e-12
710  IEEE 0,100000 10000 8.7e-10 4.8e-11
711 Outputs smaller than the IEEE gradual underflow threshold
712 were excluded from these statistics.
713 
714 Cephes Math Library, Release 2.8: June, 2000
715 Copyright 1984, 1995, 2000 by Stephen L. Moshier
716 *************************************************************************/
717 double incompletebeta(const double a, const double b, const double x);
718 
719 
720 /*************************************************************************
721 Inverse of incomplete beta integral
722 
723 Given y, the function finds x such that
724 
725  incbet( a, b, x ) = y .
726 
727 The routine performs interval halving or Newton iterations to find the
728 root of incbet(a,b,x) - y = 0.
729 
730 
731 ACCURACY:
732 
733  Relative error:
734  x a,b
735 arithmetic domain domain # trials peak rms
736  IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
737  IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
738  IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
739 With a and b constrained to half-integer or integer values:
740  IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
741  IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
742 With a = .5, b constrained to half-integer or integer values:
743  IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
744 
745 Cephes Math Library Release 2.8: June, 2000
746 Copyright 1984, 1996, 2000 by Stephen L. Moshier
747 *************************************************************************/
748 double invincompletebeta(const double a, const double b, const double y);
749 
750 /*************************************************************************
751 Binomial distribution
752 
753 Returns the sum of the terms 0 through k of the Binomial
754 probability density:
755 
756  k
757  -- ( n ) j n-j
758  > ( ) p (1-p)
759  -- ( j )
760  j=0
761 
762 The terms are not summed directly; instead the incomplete
763 beta integral is employed, according to the formula
764 
765 y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
766 
767 The arguments must be positive, with p ranging from 0 to 1.
768 
769 ACCURACY:
770 
771 Tested at random points (a,b,p), with p between 0 and 1.
772 
773  a,b Relative error:
774 arithmetic domain # trials peak rms
775  For p between 0.001 and 1:
776  IEEE 0,100 100000 4.3e-15 2.6e-16
777 
778 Cephes Math Library Release 2.8: June, 2000
779 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
780 *************************************************************************/
781 double binomialdistribution(const ae_int_t k, const ae_int_t n, const double p);
782 
783 
784 /*************************************************************************
785 Complemented binomial distribution
786 
787 Returns the sum of the terms k+1 through n of the Binomial
788 probability density:
789 
790  n
791  -- ( n ) j n-j
792  > ( ) p (1-p)
793  -- ( j )
794  j=k+1
795 
796 The terms are not summed directly; instead the incomplete
797 beta integral is employed, according to the formula
798 
799 y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
800 
801 The arguments must be positive, with p ranging from 0 to 1.
802 
803 ACCURACY:
804 
805 Tested at random points (a,b,p).
806 
807  a,b Relative error:
808 arithmetic domain # trials peak rms
809  For p between 0.001 and 1:
810  IEEE 0,100 100000 6.7e-15 8.2e-16
811  For p between 0 and .001:
812  IEEE 0,100 100000 1.5e-13 2.7e-15
813 
814 Cephes Math Library Release 2.8: June, 2000
815 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
816 *************************************************************************/
817 double binomialcdistribution(const ae_int_t k, const ae_int_t n, const double p);
818 
819 
820 /*************************************************************************
821 Inverse binomial distribution
822 
823 Finds the event probability p such that the sum of the
824 terms 0 through k of the Binomial probability density
825 is equal to the given cumulative probability y.
826 
827 This is accomplished using the inverse beta integral
828 function and the relation
829 
830 1 - p = incbi( n-k, k+1, y ).
831 
832 ACCURACY:
833 
834 Tested at random points (a,b,p).
835 
836  a,b Relative error:
837 arithmetic domain # trials peak rms
838  For p between 0.001 and 1:
839  IEEE 0,100 100000 2.3e-14 6.4e-16
840  IEEE 0,10000 100000 6.6e-12 1.2e-13
841  For p between 10^-6 and 0.001:
842  IEEE 0,100 100000 2.0e-12 1.3e-14
843  IEEE 0,10000 100000 1.5e-12 3.2e-14
844 
845 Cephes Math Library Release 2.8: June, 2000
846 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
847 *************************************************************************/
848 double invbinomialdistribution(const ae_int_t k, const ae_int_t n, const double y);
849 
850 /*************************************************************************
851 Calculation of the value of the Chebyshev polynomials of the
852 first and second kinds.
853 
854 Parameters:
855  r - polynomial kind, either 1 or 2.
856  n - degree, n>=0
857  x - argument, -1 <= x <= 1
858 
859 Result:
860  the value of the Chebyshev polynomial at x
861 *************************************************************************/
862 double chebyshevcalculate(const ae_int_t r, const ae_int_t n, const double x);
863 
864 
865 /*************************************************************************
866 Summation of Chebyshev polynomials using Clenshaw’s recurrence formula.
867 
868 This routine calculates
869  c[0]*T0(x) + c[1]*T1(x) + ... + c[N]*TN(x)
870 or
871  c[0]*U0(x) + c[1]*U1(x) + ... + c[N]*UN(x)
872 depending on the R.
873 
874 Parameters:
875  r - polynomial kind, either 1 or 2.
876  n - degree, n>=0
877  x - argument
878 
879 Result:
880  the value of the Chebyshev polynomial at x
881 *************************************************************************/
882 double chebyshevsum(const real_1d_array &c, const ae_int_t r, const ae_int_t n, const double x);
883 
884 
885 /*************************************************************************
886 Representation of Tn as C[0] + C[1]*X + ... + C[N]*X^N
887 
888 Input parameters:
889  N - polynomial degree, n>=0
890 
891 Output parameters:
892  C - coefficients
893 *************************************************************************/
894 void chebyshevcoefficients(const ae_int_t n, real_1d_array &c);
895 
896 
897 /*************************************************************************
898 Conversion of a series of Chebyshev polynomials to a power series.
899 
900 Represents A[0]*T0(x) + A[1]*T1(x) + ... + A[N]*Tn(x) as
901 B[0] + B[1]*X + ... + B[N]*X^N.
902 
903 Input parameters:
904  A - Chebyshev series coefficients
905  N - degree, N>=0
906 
907 Output parameters
908  B - power series coefficients
909 *************************************************************************/
910 void fromchebyshev(const real_1d_array &a, const ae_int_t n, real_1d_array &b);
911 
912 /*************************************************************************
913 Chi-square distribution
914 
915 Returns the area under the left hand tail (from 0 to x)
916 of the Chi square probability density function with
917 v degrees of freedom.
918 
919 
920  x
921  -
922  1 | | v/2-1 -t/2
923  P( x | v ) = ----------- | t e dt
924  v/2 - | |
925  2 | (v/2) -
926  0
927 
928 where x is the Chi-square variable.
929 
930 The incomplete gamma integral is used, according to the
931 formula
932 
933 y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
934 
935 The arguments must both be positive.
936 
937 ACCURACY:
938 
939 See incomplete gamma function
940 
941 
942 Cephes Math Library Release 2.8: June, 2000
943 Copyright 1984, 1987, 2000 by Stephen L. Moshier
944 *************************************************************************/
945 double chisquaredistribution(const double v, const double x);
946 
947 
948 /*************************************************************************
949 Complemented Chi-square distribution
950 
951 Returns the area under the right hand tail (from x to
952 infinity) of the Chi square probability density function
953 with v degrees of freedom:
954 
955  inf.
956  -
957  1 | | v/2-1 -t/2
958  P( x | v ) = ----------- | t e dt
959  v/2 - | |
960  2 | (v/2) -
961  x
962 
963 where x is the Chi-square variable.
964 
965 The incomplete gamma integral is used, according to the
966 formula
967 
968 y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
969 
970 The arguments must both be positive.
971 
972 ACCURACY:
973 
974 See incomplete gamma function
975 
976 Cephes Math Library Release 2.8: June, 2000
977 Copyright 1984, 1987, 2000 by Stephen L. Moshier
978 *************************************************************************/
979 double chisquarecdistribution(const double v, const double x);
980 
981 
982 /*************************************************************************
983 Inverse of complemented Chi-square distribution
984 
985 Finds the Chi-square argument x such that the integral
986 from x to infinity of the Chi-square density is equal
987 to the given cumulative probability y.
988 
989 This is accomplished using the inverse gamma integral
990 function and the relation
991 
992  x/2 = igami( df/2, y );
993 
994 ACCURACY:
995 
996 See inverse incomplete gamma function
997 
998 
999 Cephes Math Library Release 2.8: June, 2000
1000 Copyright 1984, 1987, 2000 by Stephen L. Moshier
1001 *************************************************************************/
1002 double invchisquaredistribution(const double v, const double y);
1003 
1004 /*************************************************************************
1005 Dawson's Integral
1006 
1007 Approximates the integral
1008 
1009  x
1010  -
1011  2 | | 2
1012  dawsn(x) = exp( -x ) | exp( t ) dt
1013  | |
1014  -
1015  0
1016 
1017 Three different rational approximations are employed, for
1018 the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
1019 
1020 ACCURACY:
1021 
1022  Relative error:
1023 arithmetic domain # trials peak rms
1024  IEEE 0,10 10000 6.9e-16 1.0e-16
1025 
1026 Cephes Math Library Release 2.8: June, 2000
1027 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
1028 *************************************************************************/
1029 double dawsonintegral(const double x);
1030 
1031 /*************************************************************************
1032 Complete elliptic integral of the first kind
1033 
1034 Approximates the integral
1035 
1036 
1037 
1038  pi/2
1039  -
1040  | |
1041  | dt
1042 K(m) = | ------------------
1043  | 2
1044  | | sqrt( 1 - m sin t )
1045  -
1046  0
1047 
1048 using the approximation
1049 
1050  P(x) - log x Q(x).
1051 
1052 ACCURACY:
1053 
1054  Relative error:
1055 arithmetic domain # trials peak rms
1056  IEEE 0,1 30000 2.5e-16 6.8e-17
1057 
1058 Cephes Math Library, Release 2.8: June, 2000
1059 Copyright 1984, 1987, 2000 by Stephen L. Moshier
1060 *************************************************************************/
1061 double ellipticintegralk(const double m);
1062 
1063 
1064 /*************************************************************************
1065 Complete elliptic integral of the first kind
1066 
1067 Approximates the integral
1068 
1069 
1070 
1071  pi/2
1072  -
1073  | |
1074  | dt
1075 K(m) = | ------------------
1076  | 2
1077  | | sqrt( 1 - m sin t )
1078  -
1079  0
1080 
1081 where m = 1 - m1, using the approximation
1082 
1083  P(x) - log x Q(x).
1084 
1085 The argument m1 is used rather than m so that the logarithmic
1086 singularity at m = 1 will be shifted to the origin; this
1087 preserves maximum accuracy.
1088 
1089 K(0) = pi/2.
1090 
1091 ACCURACY:
1092 
1093  Relative error:
1094 arithmetic domain # trials peak rms
1095  IEEE 0,1 30000 2.5e-16 6.8e-17
1096 
1097 Àëãîðèòì âçÿò èç áèáëèîòåêè Cephes
1098 *************************************************************************/
1099 double ellipticintegralkhighprecision(const double m1);
1100 
1101 
1102 /*************************************************************************
1103 Incomplete elliptic integral of the first kind F(phi|m)
1104 
1105 Approximates the integral
1106 
1107 
1108 
1109  phi
1110  -
1111  | |
1112  | dt
1113 F(phi_\m) = | ------------------
1114  | 2
1115  | | sqrt( 1 - m sin t )
1116  -
1117  0
1118 
1119 of amplitude phi and modulus m, using the arithmetic -
1120 geometric mean algorithm.
1121 
1122 
1123 
1124 
1125 ACCURACY:
1126 
1127 Tested at random points with m in [0, 1] and phi as indicated.
1128 
1129  Relative error:
1130 arithmetic domain # trials peak rms
1131  IEEE -10,10 200000 7.4e-16 1.0e-16
1132 
1133 Cephes Math Library Release 2.8: June, 2000
1134 Copyright 1984, 1987, 2000 by Stephen L. Moshier
1135 *************************************************************************/
1136 double incompleteellipticintegralk(const double phi, const double m);
1137 
1138 
1139 /*************************************************************************
1140 Complete elliptic integral of the second kind
1141 
1142 Approximates the integral
1143 
1144 
1145  pi/2
1146  -
1147  | | 2
1148 E(m) = | sqrt( 1 - m sin t ) dt
1149  | |
1150  -
1151  0
1152 
1153 using the approximation
1154 
1155  P(x) - x log x Q(x).
1156 
1157 ACCURACY:
1158 
1159  Relative error:
1160 arithmetic domain # trials peak rms
1161  IEEE 0, 1 10000 2.1e-16 7.3e-17
1162 
1163 Cephes Math Library, Release 2.8: June, 2000
1164 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
1165 *************************************************************************/
1166 double ellipticintegrale(const double m);
1167 
1168 
1169 /*************************************************************************
1170 Incomplete elliptic integral of the second kind
1171 
1172 Approximates the integral
1173 
1174 
1175  phi
1176  -
1177  | |
1178  | 2
1179 E(phi_\m) = | sqrt( 1 - m sin t ) dt
1180  |
1181  | |
1182  -
1183  0
1184 
1185 of amplitude phi and modulus m, using the arithmetic -
1186 geometric mean algorithm.
1187 
1188 ACCURACY:
1189 
1190 Tested at random arguments with phi in [-10, 10] and m in
1191 [0, 1].
1192  Relative error:
1193 arithmetic domain # trials peak rms
1194  IEEE -10,10 150000 3.3e-15 1.4e-16
1195 
1196 Cephes Math Library Release 2.8: June, 2000
1197 Copyright 1984, 1987, 1993, 2000 by Stephen L. Moshier
1198 *************************************************************************/
1199 double incompleteellipticintegrale(const double phi, const double m);
1200 
1201 /*************************************************************************
1202 Exponential integral Ei(x)
1203 
1204  x
1205  - t
1206  | | e
1207  Ei(x) = -|- --- dt .
1208  | | t
1209  -
1210  -inf
1211 
1212 Not defined for x <= 0.
1213 See also expn.c.
1214 
1215 
1216 
1217 ACCURACY:
1218 
1219  Relative error:
1220 arithmetic domain # trials peak rms
1221  IEEE 0,100 50000 8.6e-16 1.3e-16
1222 
1223 Cephes Math Library Release 2.8: May, 1999
1224 Copyright 1999 by Stephen L. Moshier
1225 *************************************************************************/
1226 double exponentialintegralei(const double x);
1227 
1228 
1229 /*************************************************************************
1230 Exponential integral En(x)
1231 
1232 Evaluates the exponential integral
1233 
1234  inf.
1235  -
1236  | | -xt
1237  | e
1238  E (x) = | ---- dt.
1239  n | n
1240  | | t
1241  -
1242  1
1243 
1244 
1245 Both n and x must be nonnegative.
1246 
1247 The routine employs either a power series, a continued
1248 fraction, or an asymptotic formula depending on the
1249 relative values of n and x.
1250 
1251 ACCURACY:
1252 
1253  Relative error:
1254 arithmetic domain # trials peak rms
1255  IEEE 0, 30 10000 1.7e-15 3.6e-16
1256 
1257 Cephes Math Library Release 2.8: June, 2000
1258 Copyright 1985, 2000 by Stephen L. Moshier
1259 *************************************************************************/
1260 double exponentialintegralen(const double x, const ae_int_t n);
1261 
1262 /*************************************************************************
1263 F distribution
1264 
1265 Returns the area from zero to x under the F density
1266 function (also known as Snedcor's density or the
1267 variance ratio density). This is the density
1268 of x = (u1/df1)/(u2/df2), where u1 and u2 are random
1269 variables having Chi square distributions with df1
1270 and df2 degrees of freedom, respectively.
1271 The incomplete beta integral is used, according to the
1272 formula
1273 
1274 P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
1275 
1276 
1277 The arguments a and b are greater than zero, and x is
1278 nonnegative.
1279 
1280 ACCURACY:
1281 
1282 Tested at random points (a,b,x).
1283 
1284  x a,b Relative error:
1285 arithmetic domain domain # trials peak rms
1286  IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
1287  IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
1288  IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
1289  IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
1290 
1291 Cephes Math Library Release 2.8: June, 2000
1292 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1293 *************************************************************************/
1294 double fdistribution(const ae_int_t a, const ae_int_t b, const double x);
1295 
1296 
1297 /*************************************************************************
1298 Complemented F distribution
1299 
1300 Returns the area from x to infinity under the F density
1301 function (also known as Snedcor's density or the
1302 variance ratio density).
1303 
1304 
1305  inf.
1306  -
1307  1 | | a-1 b-1
1308 1-P(x) = ------ | t (1-t) dt
1309  B(a,b) | |
1310  -
1311  x
1312 
1313 
1314 The incomplete beta integral is used, according to the
1315 formula
1316 
1317 P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
1318 
1319 
1320 ACCURACY:
1321 
1322 Tested at random points (a,b,x) in the indicated intervals.
1323  x a,b Relative error:
1324 arithmetic domain domain # trials peak rms
1325  IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
1326  IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
1327  IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
1328  IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
1329 
1330 Cephes Math Library Release 2.8: June, 2000
1331 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1332 *************************************************************************/
1333 double fcdistribution(const ae_int_t a, const ae_int_t b, const double x);
1334 
1335 
1336 /*************************************************************************
1337 Inverse of complemented F distribution
1338 
1339 Finds the F density argument x such that the integral
1340 from x to infinity of the F density is equal to the
1341 given probability p.
1342 
1343 This is accomplished using the inverse beta integral
1344 function and the relations
1345 
1346  z = incbi( df2/2, df1/2, p )
1347  x = df2 (1-z) / (df1 z).
1348 
1349 Note: the following relations hold for the inverse of
1350 the uncomplemented F distribution:
1351 
1352  z = incbi( df1/2, df2/2, p )
1353  x = df2 z / (df1 (1-z)).
1354 
1355 ACCURACY:
1356 
1357 Tested at random points (a,b,p).
1358 
1359  a,b Relative error:
1360 arithmetic domain # trials peak rms
1361  For p between .001 and 1:
1362  IEEE 1,100 100000 8.3e-15 4.7e-16
1363  IEEE 1,10000 100000 2.1e-11 1.4e-13
1364  For p between 10^-6 and 10^-3:
1365  IEEE 1,100 50000 1.3e-12 8.4e-15
1366  IEEE 1,10000 50000 3.0e-12 4.8e-14
1367 
1368 Cephes Math Library Release 2.8: June, 2000
1369 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1370 *************************************************************************/
1371 double invfdistribution(const ae_int_t a, const ae_int_t b, const double y);
1372 
1373 /*************************************************************************
1374 Fresnel integral
1375 
1376 Evaluates the Fresnel integrals
1377 
1378  x
1379  -
1380  | |
1381 C(x) = | cos(pi/2 t**2) dt,
1382  | |
1383  -
1384  0
1385 
1386  x
1387  -
1388  | |
1389 S(x) = | sin(pi/2 t**2) dt.
1390  | |
1391  -
1392  0
1393 
1394 
1395 The integrals are evaluated by a power series for x < 1.
1396 For x >= 1 auxiliary functions f(x) and g(x) are employed
1397 such that
1398 
1399 C(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 )
1400 S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 )
1401 
1402 
1403 
1404 ACCURACY:
1405 
1406  Relative error.
1407 
1408 Arithmetic function domain # trials peak rms
1409  IEEE S(x) 0, 10 10000 2.0e-15 3.2e-16
1410  IEEE C(x) 0, 10 10000 1.8e-15 3.3e-16
1411 
1412 Cephes Math Library Release 2.8: June, 2000
1413 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
1414 *************************************************************************/
1415 void fresnelintegral(const double x, double &c, double &s);
1416 
1417 /*************************************************************************
1418 Calculation of the value of the Hermite polynomial.
1419 
1420 Parameters:
1421  n - degree, n>=0
1422  x - argument
1423 
1424 Result:
1425  the value of the Hermite polynomial Hn at x
1426 *************************************************************************/
1427 double hermitecalculate(const ae_int_t n, const double x);
1428 
1429 
1430 /*************************************************************************
1431 Summation of Hermite polynomials using Clenshaw’s recurrence formula.
1432 
1433 This routine calculates
1434  c[0]*H0(x) + c[1]*H1(x) + ... + c[N]*HN(x)
1435 
1436 Parameters:
1437  n - degree, n>=0
1438  x - argument
1439 
1440 Result:
1441  the value of the Hermite polynomial at x
1442 *************************************************************************/
1443 double hermitesum(const real_1d_array &c, const ae_int_t n, const double x);
1444 
1445 
1446 /*************************************************************************
1447 Representation of Hn as C[0] + C[1]*X + ... + C[N]*X^N
1448 
1449 Input parameters:
1450  N - polynomial degree, n>=0
1451 
1452 Output parameters:
1453  C - coefficients
1454 *************************************************************************/
1455 void hermitecoefficients(const ae_int_t n, real_1d_array &c);
1456 
1457 /*************************************************************************
1458 Jacobian Elliptic Functions
1459 
1460 Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
1461 and dn(u|m) of parameter m between 0 and 1, and real
1462 argument u.
1463 
1464 These functions are periodic, with quarter-period on the
1465 real axis equal to the complete elliptic integral
1466 ellpk(1.0-m).
1467 
1468 Relation to incomplete elliptic integral:
1469 If u = ellik(phi,m), then sn(u|m) = sin(phi),
1470 and cn(u|m) = cos(phi). Phi is called the amplitude of u.
1471 
1472 Computation is by means of the arithmetic-geometric mean
1473 algorithm, except when m is within 1e-9 of 0 or 1. In the
1474 latter case with m close to 1, the approximation applies
1475 only for phi < pi/2.
1476 
1477 ACCURACY:
1478 
1479 Tested at random points with u between 0 and 10, m between
1480 0 and 1.
1481 
1482  Absolute error (* = relative error):
1483 arithmetic function # trials peak rms
1484  IEEE phi 10000 9.2e-16* 1.4e-16*
1485  IEEE sn 50000 4.1e-15 4.6e-16
1486  IEEE cn 40000 3.6e-15 4.4e-16
1487  IEEE dn 10000 1.3e-12 1.8e-14
1488 
1489  Peak error observed in consistency check using addition
1490 theorem for sn(u+v) was 4e-16 (absolute). Also tested by
1491 the above relation to the incomplete elliptic integral.
1492 Accuracy deteriorates when u is large.
1493 
1494 Cephes Math Library Release 2.8: June, 2000
1495 Copyright 1984, 1987, 2000 by Stephen L. Moshier
1496 *************************************************************************/
1497 void jacobianellipticfunctions(const double u, const double m, double &sn, double &cn, double &dn, double &ph);
1498 
1499 /*************************************************************************
1500 Calculation of the value of the Laguerre polynomial.
1501 
1502 Parameters:
1503  n - degree, n>=0
1504  x - argument
1505 
1506 Result:
1507  the value of the Laguerre polynomial Ln at x
1508 *************************************************************************/
1509 double laguerrecalculate(const ae_int_t n, const double x);
1510 
1511 
1512 /*************************************************************************
1513 Summation of Laguerre polynomials using Clenshaw’s recurrence formula.
1514 
1515 This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x)
1516 
1517 Parameters:
1518  n - degree, n>=0
1519  x - argument
1520 
1521 Result:
1522  the value of the Laguerre polynomial at x
1523 *************************************************************************/
1524 double laguerresum(const real_1d_array &c, const ae_int_t n, const double x);
1525 
1526 
1527 /*************************************************************************
1528 Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
1529 
1530 Input parameters:
1531  N - polynomial degree, n>=0
1532 
1533 Output parameters:
1534  C - coefficients
1535 *************************************************************************/
1536 void laguerrecoefficients(const ae_int_t n, real_1d_array &c);
1537 
1538 /*************************************************************************
1539 Calculation of the value of the Legendre polynomial Pn.
1540 
1541 Parameters:
1542  n - degree, n>=0
1543  x - argument
1544 
1545 Result:
1546  the value of the Legendre polynomial Pn at x
1547 *************************************************************************/
1548 double legendrecalculate(const ae_int_t n, const double x);
1549 
1550 
1551 /*************************************************************************
1552 Summation of Legendre polynomials using Clenshaw’s recurrence formula.
1553 
1554 This routine calculates
1555  c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
1556 
1557 Parameters:
1558  n - degree, n>=0
1559  x - argument
1560 
1561 Result:
1562  the value of the Legendre polynomial at x
1563 *************************************************************************/
1564 double legendresum(const real_1d_array &c, const ae_int_t n, const double x);
1565 
1566 
1567 /*************************************************************************
1568 Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
1569 
1570 Input parameters:
1571  N - polynomial degree, n>=0
1572 
1573 Output parameters:
1574  C - coefficients
1575 *************************************************************************/
1576 void legendrecoefficients(const ae_int_t n, real_1d_array &c);
1577 
1578 /*************************************************************************
1579 Poisson distribution
1580 
1581 Returns the sum of the first k+1 terms of the Poisson
1582 distribution:
1583 
1584  k j
1585  -- -m m
1586  > e --
1587  -- j!
1588  j=0
1589 
1590 The terms are not summed directly; instead the incomplete
1591 gamma integral is employed, according to the relation
1592 
1593 y = pdtr( k, m ) = igamc( k+1, m ).
1594 
1595 The arguments must both be positive.
1596 ACCURACY:
1597 
1598 See incomplete gamma function
1599 
1600 Cephes Math Library Release 2.8: June, 2000
1601 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1602 *************************************************************************/
1603 double poissondistribution(const ae_int_t k, const double m);
1604 
1605 
1606 /*************************************************************************
1607 Complemented Poisson distribution
1608 
1609 Returns the sum of the terms k+1 to infinity of the Poisson
1610 distribution:
1611 
1612  inf. j
1613  -- -m m
1614  > e --
1615  -- j!
1616  j=k+1
1617 
1618 The terms are not summed directly; instead the incomplete
1619 gamma integral is employed, according to the formula
1620 
1621 y = pdtrc( k, m ) = igam( k+1, m ).
1622 
1623 The arguments must both be positive.
1624 
1625 ACCURACY:
1626 
1627 See incomplete gamma function
1628 
1629 Cephes Math Library Release 2.8: June, 2000
1630 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1631 *************************************************************************/
1632 double poissoncdistribution(const ae_int_t k, const double m);
1633 
1634 
1635 /*************************************************************************
1636 Inverse Poisson distribution
1637 
1638 Finds the Poisson variable x such that the integral
1639 from 0 to x of the Poisson density is equal to the
1640 given probability y.
1641 
1642 This is accomplished using the inverse gamma integral
1643 function and the relation
1644 
1645  m = igami( k+1, y ).
1646 
1647 ACCURACY:
1648 
1649 See inverse incomplete gamma function
1650 
1651 Cephes Math Library Release 2.8: June, 2000
1652 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1653 *************************************************************************/
1654 double invpoissondistribution(const ae_int_t k, const double y);
1655 
1656 /*************************************************************************
1657 Psi (digamma) function
1658 
1659  d -
1660  psi(x) = -- ln | (x)
1661  dx
1662 
1663 is the logarithmic derivative of the gamma function.
1664 For integer x,
1665  n-1
1666  -
1667 psi(n) = -EUL + > 1/k.
1668  -
1669  k=1
1670 
1671 This formula is used for 0 < n <= 10. If x is negative, it
1672 is transformed to a positive argument by the reflection
1673 formula psi(1-x) = psi(x) + pi cot(pi x).
1674 For general positive x, the argument is made greater than 10
1675 using the recurrence psi(x+1) = psi(x) + 1/x.
1676 Then the following asymptotic expansion is applied:
1677 
1678  inf. B
1679  - 2k
1680 psi(x) = log(x) - 1/2x - > -------
1681  - 2k
1682  k=1 2k x
1683 
1684 where the B2k are Bernoulli numbers.
1685 
1686 ACCURACY:
1687  Relative error (except absolute when |psi| < 1):
1688 arithmetic domain # trials peak rms
1689  IEEE 0,30 30000 1.3e-15 1.4e-16
1690  IEEE -30,0 40000 1.5e-15 2.2e-16
1691 
1692 Cephes Math Library Release 2.8: June, 2000
1693 Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
1694 *************************************************************************/
1695 double psi(const double x);
1696 
1697 /*************************************************************************
1698 Student's t distribution
1699 
1700 Computes the integral from minus infinity to t of the Student
1701 t distribution with integer k > 0 degrees of freedom:
1702 
1703  t
1704  -
1705  | |
1706  - | 2 -(k+1)/2
1707  | ( (k+1)/2 ) | ( x )
1708  ---------------------- | ( 1 + --- ) dx
1709  - | ( k )
1710  sqrt( k pi ) | ( k/2 ) |
1711  | |
1712  -
1713  -inf.
1714 
1715 Relation to incomplete beta integral:
1716 
1717  1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )
1718 where
1719  z = k/(k + t**2).
1720 
1721 For t < -2, this is the method of computation. For higher t,
1722 a direct method is derived from integration by parts.
1723 Since the function is symmetric about t=0, the area under the
1724 right tail of the density is found by calling the function
1725 with -t instead of t.
1726 
1727 ACCURACY:
1728 
1729 Tested at random 1 <= k <= 25. The "domain" refers to t.
1730  Relative error:
1731 arithmetic domain # trials peak rms
1732  IEEE -100,-2 50000 5.9e-15 1.4e-15
1733  IEEE -2,100 500000 2.7e-15 4.9e-17
1734 
1735 Cephes Math Library Release 2.8: June, 2000
1736 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1737 *************************************************************************/
1738 double studenttdistribution(const ae_int_t k, const double t);
1739 
1740 
1741 /*************************************************************************
1742 Functional inverse of Student's t distribution
1743 
1744 Given probability p, finds the argument t such that stdtr(k,t)
1745 is equal to p.
1746 
1747 ACCURACY:
1748 
1749 Tested at random 1 <= k <= 100. The "domain" refers to p:
1750  Relative error:
1751 arithmetic domain # trials peak rms
1752  IEEE .001,.999 25000 5.7e-15 8.0e-16
1753  IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
1754 
1755 Cephes Math Library Release 2.8: June, 2000
1756 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
1757 *************************************************************************/
1758 double invstudenttdistribution(const ae_int_t k, const double p);
1759 
1760 /*************************************************************************
1761 Sine and cosine integrals
1762 
1763 Evaluates the integrals
1764 
1765  x
1766  -
1767  | cos t - 1
1768  Ci(x) = eul + ln x + | --------- dt,
1769  | t
1770  -
1771  0
1772  x
1773  -
1774  | sin t
1775  Si(x) = | ----- dt
1776  | t
1777  -
1778  0
1779 
1780 where eul = 0.57721566490153286061 is Euler's constant.
1781 The integrals are approximated by rational functions.
1782 For x > 8 auxiliary functions f(x) and g(x) are employed
1783 such that
1784 
1785 Ci(x) = f(x) sin(x) - g(x) cos(x)
1786 Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
1787 
1788 
1789 ACCURACY:
1790  Test interval = [0,50].
1791 Absolute error, except relative when > 1:
1792 arithmetic function # trials peak rms
1793  IEEE Si 30000 4.4e-16 7.3e-17
1794  IEEE Ci 30000 6.9e-16 5.1e-17
1795 
1796 Cephes Math Library Release 2.1: January, 1989
1797 Copyright 1984, 1987, 1989 by Stephen L. Moshier
1798 *************************************************************************/
1799 void sinecosineintegrals(const double x, double &si, double &ci);
1800 
1801 
1802 /*************************************************************************
1803 Hyperbolic sine and cosine integrals
1804 
1805 Approximates the integrals
1806 
1807  x
1808  -
1809  | | cosh t - 1
1810  Chi(x) = eul + ln x + | ----------- dt,
1811  | | t
1812  -
1813  0
1814 
1815  x
1816  -
1817  | | sinh t
1818  Shi(x) = | ------ dt
1819  | | t
1820  -
1821  0
1822 
1823 where eul = 0.57721566490153286061 is Euler's constant.
1824 The integrals are evaluated by power series for x < 8
1825 and by Chebyshev expansions for x between 8 and 88.
1826 For large x, both functions approach exp(x)/2x.
1827 Arguments greater than 88 in magnitude return MAXNUM.
1828 
1829 
1830 ACCURACY:
1831 
1832 Test interval 0 to 88.
1833  Relative error:
1834 arithmetic function # trials peak rms
1835  IEEE Shi 30000 6.9e-16 1.6e-16
1836  Absolute error, except relative when |Chi| > 1:
1837  IEEE Chi 30000 8.4e-16 1.4e-16
1838 
1839 Cephes Math Library Release 2.8: June, 2000
1840 Copyright 1984, 1987, 2000 by Stephen L. Moshier
1841 *************************************************************************/
1842 void hyperbolicsinecosineintegrals(const double x, double &shi, double &chi);
1843 }
1844 
1846 //
1847 // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
1848 //
1850 namespace alglib_impl
1851 {
1852 double gammafunction(double x, ae_state *_state);
1853 double lngamma(double x, double* sgngam, ae_state *_state);
1854 double errorfunction(double x, ae_state *_state);
1855 double errorfunctionc(double x, ae_state *_state);
1856 double normaldistribution(double x, ae_state *_state);
1857 double inverf(double e, ae_state *_state);
1858 double invnormaldistribution(double y0, ae_state *_state);
1859 double incompletegamma(double a, double x, ae_state *_state);
1860 double incompletegammac(double a, double x, ae_state *_state);
1861 double invincompletegammac(double a, double y0, ae_state *_state);
1862 void airy(double x,
1863  double* ai,
1864  double* aip,
1865  double* bi,
1866  double* bip,
1867  ae_state *_state);
1868 double besselj0(double x, ae_state *_state);
1869 double besselj1(double x, ae_state *_state);
1870 double besseljn(ae_int_t n, double x, ae_state *_state);
1871 double bessely0(double x, ae_state *_state);
1872 double bessely1(double x, ae_state *_state);
1873 double besselyn(ae_int_t n, double x, ae_state *_state);
1874 double besseli0(double x, ae_state *_state);
1875 double besseli1(double x, ae_state *_state);
1876 double besselk0(double x, ae_state *_state);
1877 double besselk1(double x, ae_state *_state);
1878 double besselkn(ae_int_t nn, double x, ae_state *_state);
1879 double beta(double a, double b, ae_state *_state);
1880 double incompletebeta(double a, double b, double x, ae_state *_state);
1881 double invincompletebeta(double a, double b, double y, ae_state *_state);
1883  ae_int_t n,
1884  double p,
1885  ae_state *_state);
1887  ae_int_t n,
1888  double p,
1889  ae_state *_state);
1891  ae_int_t n,
1892  double y,
1893  ae_state *_state);
1894 double chebyshevcalculate(ae_int_t r,
1895  ae_int_t n,
1896  double x,
1897  ae_state *_state);
1898 double chebyshevsum(/* Real */ ae_vector* c,
1899  ae_int_t r,
1900  ae_int_t n,
1901  double x,
1902  ae_state *_state);
1904  /* Real */ ae_vector* c,
1905  ae_state *_state);
1906 void fromchebyshev(/* Real */ ae_vector* a,
1907  ae_int_t n,
1908  /* Real */ ae_vector* b,
1909  ae_state *_state);
1910 double chisquaredistribution(double v, double x, ae_state *_state);
1911 double chisquarecdistribution(double v, double x, ae_state *_state);
1912 double invchisquaredistribution(double v, double y, ae_state *_state);
1913 double dawsonintegral(double x, ae_state *_state);
1914 double ellipticintegralk(double m, ae_state *_state);
1915 double ellipticintegralkhighprecision(double m1, ae_state *_state);
1916 double incompleteellipticintegralk(double phi, double m, ae_state *_state);
1917 double ellipticintegrale(double m, ae_state *_state);
1918 double incompleteellipticintegrale(double phi, double m, ae_state *_state);
1919 double exponentialintegralei(double x, ae_state *_state);
1920 double exponentialintegralen(double x, ae_int_t n, ae_state *_state);
1921 double fdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
1922 double fcdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state);
1923 double invfdistribution(ae_int_t a,
1924  ae_int_t b,
1925  double y,
1926  ae_state *_state);
1927 void fresnelintegral(double x, double* c, double* s, ae_state *_state);
1928 double hermitecalculate(ae_int_t n, double x, ae_state *_state);
1929 double hermitesum(/* Real */ ae_vector* c,
1930  ae_int_t n,
1931  double x,
1932  ae_state *_state);
1934  /* Real */ ae_vector* c,
1935  ae_state *_state);
1936 void jacobianellipticfunctions(double u,
1937  double m,
1938  double* sn,
1939  double* cn,
1940  double* dn,
1941  double* ph,
1942  ae_state *_state);
1943 double laguerrecalculate(ae_int_t n, double x, ae_state *_state);
1944 double laguerresum(/* Real */ ae_vector* c,
1945  ae_int_t n,
1946  double x,
1947  ae_state *_state);
1949  /* Real */ ae_vector* c,
1950  ae_state *_state);
1951 double legendrecalculate(ae_int_t n, double x, ae_state *_state);
1952 double legendresum(/* Real */ ae_vector* c,
1953  ae_int_t n,
1954  double x,
1955  ae_state *_state);
1957  /* Real */ ae_vector* c,
1958  ae_state *_state);
1959 double poissondistribution(ae_int_t k, double m, ae_state *_state);
1960 double poissoncdistribution(ae_int_t k, double m, ae_state *_state);
1961 double invpoissondistribution(ae_int_t k, double y, ae_state *_state);
1962 double psi(double x, ae_state *_state);
1963 double studenttdistribution(ae_int_t k, double t, ae_state *_state);
1964 double invstudenttdistribution(ae_int_t k, double p, ae_state *_state);
1965 void sinecosineintegrals(double x,
1966  double* si,
1967  double* ci,
1968  ae_state *_state);
1969 void hyperbolicsinecosineintegrals(double x,
1970  double* shi,
1971  double* chi,
1972  ae_state *_state);
1973 
1974 }
1975 #endif
1976 
struct alglib_impl::ae_state ae_state
void hyperbolicsinecosineintegrals(double x, double *shi, double *chi, ae_state *_state)
double beta(double a, double b, ae_state *_state)
double incompleteellipticintegralk(double phi, double m, ae_state *_state)
double invbinomialdistribution(ae_int_t k, ae_int_t n, double y, ae_state *_state)
double poissoncdistribution(ae_int_t k, double m, ae_state *_state)
void airy(double x, double *ai, double *aip, double *bi, double *bip, ae_state *_state)
double invfdistribution(ae_int_t a, ae_int_t b, double y, ae_state *_state)
double besselj1(double x, ae_state *_state)
double binomialcdistribution(ae_int_t k, ae_int_t n, double p, ae_state *_state)
double bessely1(double x, ae_state *_state)
double errorfunction(double x, ae_state *_state)
double chebyshevsum(ae_vector *c, ae_int_t r, ae_int_t n, double x, ae_state *_state)
doublereal * c
void fresnelintegral(double x, double *c, double *s, ae_state *_state)
static double * y
void fromchebyshev(ae_vector *a, ae_int_t n, ae_vector *b, ae_state *_state)
void jacobianellipticfunctions(double u, double m, double *sn, double *cn, double *dn, double *ph, ae_state *_state)
double psi(double x, ae_state *_state)
void hermitecoefficients(ae_int_t n, ae_vector *c, ae_state *_state)
double invincompletegammac(double a, double y0, ae_state *_state)
double besseli0(double x, ae_state *_state)
double normaldistribution(double x, ae_state *_state)
double hermitecalculate(ae_int_t n, double x, ae_state *_state)
double exponentialintegralen(double x, ae_int_t n, ae_state *_state)
double fcdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state)
double incompletebeta(double a, double b, double x, ae_state *_state)
doublereal * x
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double studenttdistribution(ae_int_t k, double t, ae_state *_state)
void laguerrecoefficients(ae_int_t n, ae_vector *c, ae_state *_state)
double chisquaredistribution(double v, double x, ae_state *_state)
double chisquarecdistribution(double v, double x, ae_state *_state)
double fdistribution(ae_int_t a, ae_int_t b, double x, ae_state *_state)
doublereal * b
double incompletegammac(double a, double x, ae_state *_state)
#define y0
double laguerrecalculate(ae_int_t n, double x, ae_state *_state)
double invchisquaredistribution(double v, double y, ae_state *_state)
double incompleteellipticintegrale(double phi, double m, ae_state *_state)
double errorfunctionc(double x, ae_state *_state)
double exponentialintegralei(double x, ae_state *_state)
double invpoissondistribution(ae_int_t k, double y, ae_state *_state)
double dawsonintegral(double x, ae_state *_state)
void chebyshevcoefficients(ae_int_t n, ae_vector *c, ae_state *_state)
double ellipticintegralkhighprecision(double m1, ae_state *_state)
double besselk0(double x, ae_state *_state)
double bessely0(double x, ae_state *_state)
double chebyshevcalculate(ae_int_t r, ae_int_t n, double x, ae_state *_state)
double besselj0(double x, ae_state *_state)
double gammafunction(double x, ae_state *_state)
double invincompletebeta(double a, double b, double y, ae_state *_state)
struct alglib_impl::ae_vector ae_vector
double invnormaldistribution(double y0, ae_state *_state)
double ellipticintegralk(double m, ae_state *_state)
int m
double invstudenttdistribution(ae_int_t k, double p, ae_state *_state)
double hermitesum(ae_vector *c, ae_int_t n, double x, ae_state *_state)
double besselk1(double x, ae_state *_state)
void legendrecoefficients(ae_int_t n, ae_vector *c, ae_state *_state)
double besselyn(ae_int_t n, double x, ae_state *_state)
ptrdiff_t ae_int_t
Definition: ap.h:186
doublereal * u
double besseljn(ae_int_t n, double x, ae_state *_state)
void sinecosineintegrals(double x, double *si, double *ci, ae_state *_state)
double incompletegamma(double a, double x, ae_state *_state)
double binomialdistribution(ae_int_t k, ae_int_t n, double p, ae_state *_state)
double ellipticintegrale(double m, ae_state *_state)
double inverf(double e, ae_state *_state)
double lngamma(double x, double *sgngam, ae_state *_state)
int * n
doublereal * a
double besselkn(ae_int_t nn, double x, ae_state *_state)
double legendresum(ae_vector *c, ae_int_t n, double x, ae_state *_state)
double besseli1(double x, ae_state *_state)
double laguerresum(ae_vector *c, ae_int_t n, double x, ae_state *_state)
double legendrecalculate(ae_int_t n, double x, ae_state *_state)
double poissondistribution(ae_int_t k, double m, ae_state *_state)