LAL  7.5.0.1-b72065a
Factorial.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Karl Wette
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with with program; see the file COPYING. If not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  */
19 
20 #ifndef _FACTORIAL_H
21 #define _FACTORIAL_H
22 
23 #include <lal/LALAtomicDatatypes.h>
24 
25 /**
26  * \defgroup Factorial_h Header Factorial.h
27  * \ingroup lal_utilities
28  * \author Karl Wette
29  * \brief Static tables of the factorial and double-factorial functions, and derived quantities.
30  *
31  * ### Description ###
32  *
33  * The following tables of the factorial function are provided:
34  * <ul>
35  * <li>UINT8 LAL_FACT[\f$i\f$] = \f$i!\f$
36  * <li>REAL8 LAL_FACT_INV[\f$i\f$] = \f$1/i!\f$
37  * <li>REAL8 LAL_FACT_LOG[\f$i\f$] = \f$\log i!\f$
38  * </ul>
39  * The maximum allowable index \f$i\f$ of these tables is LAL_FACT_MAX.
40  * This value is determines by the maximum value of \f$i!\f$ that can be stored in an UINT8.
41  *
42  * The following tables of the double-factorial function are provided:
43  * <ul>
44  * <li>UINT8 LAL_FACT2[\f$i\f$] = \f$i!!\f$
45  * <li>REAL8 LAL_FACT2_INV[\f$i\f$] = \f$1/i!!\f$
46  * <li>REAL8 LAL_FACT2_LOG[\f$i\f$] = \f$\log i!!\f$
47  * </ul>
48  * The maximum allowable index \f$i\f$ of these tables is LAL_FACT2_MAX.
49  * This value is determines by the maximum value of \f$i!!\f$ that can be stored in an UINT8.
50  *
51  * All values were computed to 35 significant figures with Mathematica v8.0.1.0 on 64-bit Linux.
52  */
53 /** @{ */
54 
55 #ifndef SWIG /* exclude from SWIG wrappings */
56 
57 #define LAL_FACT_MAX 20
58 
59 static const UINT8 LAL_FACT[] = { \
60  1, \
61  1, \
62  2, \
63  6, \
64  24, \
65  120, \
66  720, \
67  5040, \
68  40320, \
69  362880, \
70  3628800, \
71  39916800, \
72  479001600, \
73  6227020800, \
74  87178291200, \
75  1307674368000, \
76  20922789888000, \
77  355687428096000, \
78  6402373705728000, \
79  121645100408832000, \
80  2432902008176640000 \
81 };
82 
83 static const REAL8 LAL_FACT_INV[] = { \
84  1., \
85  1., \
86  0.5, \
87  0.16666666666666666666666666666666667, \
88  0.041666666666666666666666666666666667, \
89  0.0083333333333333333333333333333333333, \
90  0.0013888888888888888888888888888888889, \
91  0.00019841269841269841269841269841269841, \
92  0.000024801587301587301587301587301587302, \
93  2.7557319223985890652557319223985891e-6, \
94  2.7557319223985890652557319223985891e-7, \
95  2.5052108385441718775052108385441719e-8, \
96  2.0876756987868098979210090321201432e-9, \
97  1.6059043836821614599392377170154948e-10, \
98  1.1470745597729724713851697978682106e-11, \
99  7.6471637318198164759011319857880704e-13, \
100  4.779477332387385297438207491117544e-14, \
101  2.81145725434552076319894558301032e-15, \
102  1.5619206968586226462216364350057333e-16, \
103  8.2206352466243297169559812368722807e-18, \
104  4.1103176233121648584779906184361404e-19 \
105 };
106 
107 static const REAL8 LAL_FACT_LOG[] = { \
108  0., \
109  0., \
110  0.6931471805599453094172321214581766, \
111  1.7917594692280550008124773583807023, \
112  3.1780538303479456196469416012970554, \
113  4.787491742782045994247700934523243, \
114  6.5792512120101009950601782929039453, \
115  8.5251613610654143001655310363471251, \
116  10.6046029027452502284172274007216548, \
117  12.8018274800814696112077178745667062, \
118  15.1044125730755152952257093292510704, \
119  17.5023078458738858392876529072161997, \
120  19.9872144956618861495173623870550785, \
121  22.5521638531234228855708498286203971, \
122  25.1912211827386815000934346935217534, \
123  27.8992713838408915660894392636704668, \
124  30.671860106080672803758367749503173, \
125  33.5050734501368888840079023673762996, \
126  36.3954452080330535762156249626795275, \
127  39.3398841871994940362246523945673811, \
128  42.3356164607534850296598759707099219 \
129 };
130 
131 #define LAL_FACT2_MAX 33
132 
133 static const UINT8 LAL_FACT2[] = { \
134  1, \
135  1, \
136  2, \
137  3, \
138  8, \
139  15, \
140  48, \
141  105, \
142  384, \
143  945, \
144  3840, \
145  10395, \
146  46080, \
147  135135, \
148  645120, \
149  2027025, \
150  10321920, \
151  34459425, \
152  185794560, \
153  654729075, \
154  3715891200, \
155  13749310575, \
156  81749606400, \
157  316234143225, \
158  1961990553600, \
159  7905853580625, \
160  51011754393600, \
161  213458046676875, \
162  1428329123020800, \
163  6190283353629375, \
164  42849873690624000, \
165  191898783962510625, \
166  1371195958099968000, \
167  6332659870762850625 \
168 };
169 
170 static const REAL8 LAL_FACT2_INV[] = { \
171  1., \
172  1., \
173  0.5, \
174  0.33333333333333333333333333333333333, \
175  0.125, \
176  0.066666666666666666666666666666666667, \
177  0.020833333333333333333333333333333333, \
178  0.0095238095238095238095238095238095238, \
179  0.0026041666666666666666666666666666667, \
180  0.0010582010582010582010582010582010582, \
181  0.00026041666666666666666666666666666667, \
182  0.0000962000962000962000962000962000962, \
183  0.000021701388888888888888888888888888889, \
184  7.4000074000074000074000074000074e-6, \
185  1.5500992063492063492063492063492063e-6, \
186  4.9333382666716000049333382666716e-7, \
187  9.6881200396825396825396825396825397e-8, \
188  2.9019636862774117676078460392185882e-8, \
189  5.3822889109347442680776014109347443e-9, \
190  1.5273493085670588250567610732729412e-9, \
191  2.6911444554673721340388007054673721e-10, \
192  7.2730919455574229764607670155854342e-11, \
193  1.2232474797578964245630912297578964e-11, \
194  3.1622138893727925984612030502545366e-12, \
195  5.0968644989912351023462134573245684e-13, \
196  1.2648855557491170393844812201018146e-13, \
197  1.9603324996120135009023897912786802e-14, \
198  4.6847613175893223680906711855622764e-15, \
199  7.0011874986143339317942492545667149e-16, \
200  1.6154349370997663338243693743318195e-16, \
201  2.3337291662047779772647497515222383e-17, \
202  5.2110804422573107542721592720381273e-18, \
203  7.2929036443899311789523429735069947e-19, \
204  1.5791152855325184103855028097085234e-19 \
205 };
206 
207 static const REAL8 LAL_FACT2_LOG[] = { \
208  0., \
209  0., \
210  0.6931471805599453094172321214581766, \
211  1.0986122886681096913952452369225257, \
212  2.0794415416798359282516963643745297, \
213  2.7080502011022100659960045701487133, \
214  3.871201010907890929064173722755232, \
215  4.6539603501575233711013573135918931, \
216  5.9506425525877268573158700871297617, \
217  6.8511849274937427538918477874369445, \
218  8.2532276455817725413338615418141259, \
219  9.2490802002921132979537913654020738, \
220  10.7381342953697728515635710216530047, \
221  11.8140295577536500340072788069673924, \
222  13.377191624985031466086155886554361, \
223  14.5220797588558601000032833771161057, \
224  16.1497803472248127037550843723870673, \
225  17.3552931029120761802528179949892323, \
226  19.0401521051209773959628069676902953, \
227  20.2997320820785166402618454268770858, \
228  22.0358843786749683893980305438328361, \
229  23.3442545198019396367624434072427912, \
230  25.1269268320332842428772062432561419, \
231  26.4797487357310893275691962390529874, \
232  28.3049806623812298625241478445531973, \
233  29.6986245605992900767707149055053626, \
234  31.5630772004027119079948674075766925, \
235  32.9944614266036191509564506162729398, \
236  34.8952817105779158319346843939362254, \
237  36.3617572565900931781397226486348514, \
238  38.2964790922400712073479210855431153, \
239  39.7957444610752394240688869731772086, \
240  41.7622149950397977544340816928339981, \
241  43.2922520225417196595260757880648636 \
242 };
243 
244 #endif /* SWIG */
245 
246 /** @} */
247 
248 #endif /*_FACTORIAL_H*/
static const REAL8 LAL_FACT2_LOG[]
Definition: Factorial.h:207
static const UINT8 LAL_FACT[]
Definition: Factorial.h:59
static const REAL8 LAL_FACT2_INV[]
Definition: Factorial.h:170
static const UINT8 LAL_FACT2[]
Definition: Factorial.h:133
static const REAL8 LAL_FACT_LOG[]
Definition: Factorial.h:107
static const REAL8 LAL_FACT_INV[]
Definition: Factorial.h:83
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double REAL8
Double precision real floating-point number (8 bytes).