GiNaC 1.8.7
utils.cpp
Go to the documentation of this file.
1
6/*
7 * GiNaC Copyright (C) 1999-2023 Johannes Gutenberg University Mainz, Germany
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include "ex.h"
25#include "numeric.h"
26#include "utils.h"
27#include "version.h"
28
29namespace GiNaC {
30
31/* Version information buried into the library */
35
36
38pole_error::pole_error(const std::string& what_arg, int degree)
39 : domain_error(what_arg), deg(degree) { }
40
43{
44 return deg;
45}
46
48unsigned log2(unsigned n)
49{
50 unsigned k;
51 for (k = 0; n > 1; n >>= 1)
52 ++k;
53 return k;
54}
55
59const numeric
60multinomial_coefficient(const std::vector<unsigned> & p)
61{
62 numeric n = 0, d = 1;
63 for (auto & it : p) {
64 n = n.add(numeric(it));
65 d = d.mul(factorial(numeric(it)));
66 }
67 return factorial(n).div(d);
68}
69
70
74
78{
79 if (count++==0) {
80 _num_120_p = (const numeric *)&dynallocate<numeric>(-120);
81 _num_60_p = (const numeric *)&dynallocate<numeric>(-60);
82 _num_48_p = (const numeric *)&dynallocate<numeric>(-48);
83 _num_30_p = (const numeric *)&dynallocate<numeric>(-30);
84 _num_25_p = (const numeric *)&dynallocate<numeric>(-25);
85 _num_24_p = (const numeric *)&dynallocate<numeric>(-24);
86 _num_20_p = (const numeric *)&dynallocate<numeric>(-20);
87 _num_18_p = (const numeric *)&dynallocate<numeric>(-18);
88 _num_15_p = (const numeric *)&dynallocate<numeric>(-15);
89 _num_12_p = (const numeric *)&dynallocate<numeric>(-12);
90 _num_11_p = (const numeric *)&dynallocate<numeric>(-11);
91 _num_10_p = (const numeric *)&dynallocate<numeric>(-10);
92 _num_9_p = (const numeric *)&dynallocate<numeric>(-9);
93 _num_8_p = (const numeric *)&dynallocate<numeric>(-8);
94 _num_7_p = (const numeric *)&dynallocate<numeric>(-7);
95 _num_6_p = (const numeric *)&dynallocate<numeric>(-6);
96 _num_5_p = (const numeric *)&dynallocate<numeric>(-5);
97 _num_4_p = (const numeric *)&dynallocate<numeric>(-4);
98 _num_3_p = (const numeric *)&dynallocate<numeric>(-3);
99 _num_2_p = (const numeric *)&dynallocate<numeric>(-2);
100 _num_1_p = (const numeric *)&dynallocate<numeric>(-1);
101 _num_1_2_p = (const numeric *)&dynallocate<numeric>(-1,2);
102 _num_1_3_p = (const numeric *)&dynallocate<numeric>(-1,3);
103 _num_1_4_p = (const numeric *)&dynallocate<numeric>(-1,4);
104 _num0_p = (const numeric *)&dynallocate<numeric>(0);
105 _num0_bp = _num0_p; // Cf. class ex default ctor.
106 _num1_4_p = (const numeric *)&dynallocate<numeric>(1,4);
107 _num1_3_p = (const numeric *)&dynallocate<numeric>(1,3);
108 _num1_2_p = (const numeric *)&dynallocate<numeric>(1,2);
109 _num1_p = (const numeric *)&dynallocate<numeric>(1);
110 _num2_p = (const numeric *)&dynallocate<numeric>(2);
111 _num3_p = (const numeric *)&dynallocate<numeric>(3);
112 _num4_p = (const numeric *)&dynallocate<numeric>(4);
113 _num5_p = (const numeric *)&dynallocate<numeric>(5);
114 _num6_p = (const numeric *)&dynallocate<numeric>(6);
115 _num7_p = (const numeric *)&dynallocate<numeric>(7);
116 _num8_p = (const numeric *)&dynallocate<numeric>(8);
117 _num9_p = (const numeric *)&dynallocate<numeric>(9);
118 _num10_p = (const numeric *)&dynallocate<numeric>(10);
119 _num11_p = (const numeric *)&dynallocate<numeric>(11);
120 _num12_p = (const numeric *)&dynallocate<numeric>(12);
121 _num15_p = (const numeric *)&dynallocate<numeric>(15);
122 _num18_p = (const numeric *)&dynallocate<numeric>(18);
123 _num20_p = (const numeric *)&dynallocate<numeric>(20);
124 _num24_p = (const numeric *)&dynallocate<numeric>(24);
125 _num25_p = (const numeric *)&dynallocate<numeric>(25);
126 _num30_p = (const numeric *)&dynallocate<numeric>(30);
127 _num48_p = (const numeric *)&dynallocate<numeric>(48);
128 _num60_p = (const numeric *)&dynallocate<numeric>(60);
129 _num120_p = (const numeric *)&dynallocate<numeric>(120);
130
131 new((void*)&_ex_120) ex(*_num_120_p);
132 new((void*)&_ex_60) ex(*_num_60_p);
133 new((void*)&_ex_48) ex(*_num_48_p);
134 new((void*)&_ex_30) ex(*_num_30_p);
135 new((void*)&_ex_25) ex(*_num_25_p);
136 new((void*)&_ex_24) ex(*_num_24_p);
137 new((void*)&_ex_20) ex(*_num_20_p);
138 new((void*)&_ex_18) ex(*_num_18_p);
139 new((void*)&_ex_15) ex(*_num_15_p);
140 new((void*)&_ex_12) ex(*_num_12_p);
141 new((void*)&_ex_11) ex(*_num_11_p);
142 new((void*)&_ex_10) ex(*_num_10_p);
143 new((void*)&_ex_9) ex(*_num_9_p);
144 new((void*)&_ex_8) ex(*_num_8_p);
145 new((void*)&_ex_7) ex(*_num_7_p);
146 new((void*)&_ex_6) ex(*_num_6_p);
147 new((void*)&_ex_5) ex(*_num_5_p);
148 new((void*)&_ex_4) ex(*_num_4_p);
149 new((void*)&_ex_3) ex(*_num_3_p);
150 new((void*)&_ex_2) ex(*_num_2_p);
151 new((void*)&_ex_1) ex(*_num_1_p);
152 new((void*)&_ex_1_2) ex(*_num_1_2_p);
153 new((void*)&_ex_1_3) ex(*_num_1_3_p);
154 new((void*)&_ex_1_4) ex(*_num_1_4_p);
155 new((void*)&_ex0) ex(*_num0_p);
156 new((void*)&_ex1_4) ex(*_num1_4_p);
157 new((void*)&_ex1_3) ex(*_num1_3_p);
158 new((void*)&_ex1_2) ex(*_num1_2_p);
159 new((void*)&_ex1) ex(*_num1_p);
160 new((void*)&_ex2) ex(*_num2_p);
161 new((void*)&_ex3) ex(*_num3_p);
162 new((void*)&_ex4) ex(*_num4_p);
163 new((void*)&_ex5) ex(*_num5_p);
164 new((void*)&_ex6) ex(*_num6_p);
165 new((void*)&_ex7) ex(*_num7_p);
166 new((void*)&_ex8) ex(*_num8_p);
167 new((void*)&_ex9) ex(*_num9_p);
168 new((void*)&_ex10) ex(*_num10_p);
169 new((void*)&_ex11) ex(*_num11_p);
170 new((void*)&_ex12) ex(*_num12_p);
171 new((void*)&_ex15) ex(*_num15_p);
172 new((void*)&_ex18) ex(*_num18_p);
173 new((void*)&_ex20) ex(*_num20_p);
174 new((void*)&_ex24) ex(*_num24_p);
175 new((void*)&_ex25) ex(*_num25_p);
176 new((void*)&_ex30) ex(*_num30_p);
177 new((void*)&_ex48) ex(*_num48_p);
178 new((void*)&_ex60) ex(*_num60_p);
179 new((void*)&_ex120) ex(*_num120_p);
180
181 // Initialize print context class info (this is not strictly necessary
182 // but we do it anyway to make print_context_class_info::dump_hierarchy()
183 // output the whole hierarchy whether or not the classes are actually
184 // used)
185 print_context::get_class_info_static();
186 print_dflt::get_class_info_static();
187 print_latex::get_class_info_static();
188 print_python::get_class_info_static();
189 print_python_repr::get_class_info_static();
190 print_tree::get_class_info_static();
191 print_csrc::get_class_info_static();
192 print_csrc_float::get_class_info_static();
193 print_csrc_double::get_class_info_static();
194 print_csrc_cl_N::get_class_info_static();
195 }
196}
197
198
202{
203 if (--count==0) {
204 // It's really necessary to clean up, since the program
205 // lifetime might not be the same as libginac.{so,dll} one
206 // (e.g. consider // dlopen/dlsym/dlclose sequence).
207 // Let the ex dtors care for deleting the numerics!
208 _ex120.~ex();
209 _ex_120.~ex();
210 _ex60.~ex();
211 _ex_60.~ex();
212 _ex48.~ex();
213 _ex_48.~ex();
214 _ex30.~ex();
215 _ex_30.~ex();
216 _ex25.~ex();
217 _ex_25.~ex();
218 _ex24.~ex();
219 _ex_24.~ex();
220 _ex20.~ex();
221 _ex_20.~ex();
222 _ex18.~ex();
223 _ex_18.~ex();
224 _ex15.~ex();
225 _ex_15.~ex();
226 _ex12.~ex();
227 _ex_12.~ex();
228 _ex11.~ex();
229 _ex_11.~ex();
230 _ex10.~ex();
231 _ex_10.~ex();
232 _ex9.~ex();
233 _ex_9.~ex();
234 _ex8.~ex();
235 _ex_8.~ex();
236 _ex7.~ex();
237 _ex_7.~ex();
238 _ex6.~ex();
239 _ex_6.~ex();
240 _ex5.~ex();
241 _ex_5.~ex();
242 _ex4.~ex();
243 _ex_4.~ex();
244 _ex3.~ex();
245 _ex_3.~ex();
246 _ex2.~ex();
247 _ex_2.~ex();
248 _ex1.~ex();
249 _ex_1.~ex();
250 _ex1_2.~ex();
251 _ex_1_2.~ex();
252 _ex1_3.~ex();
253 _ex_1_3.~ex();
254 _ex1_4.~ex();
255 _ex_1_4.~ex();
256 _ex0.~ex();
257 }
258}
259
261
262
264// Flyweight chest of numbers is re-initialized here. Note that this works
265// because the numeric* have been dynallocated by the library_init ctor before
266// (with the first module that has a static library_init object), so the
267// assignments here only increment their refcounts.
269
270// static numeric -120
273
274// static numeric -60
277
278// static numeric -48
281
282// static numeric -30
285
286// static numeric -25
289
290// static numeric -24
293
294// static numeric -20
297
298// static numeric -18
301
302// static numeric -15
305
306// static numeric -12
309
310// static numeric -11
313
314// static numeric -10
317
318// static numeric -9
320const ex _ex_9 = ex(*_num_9_p);
321
322// static numeric -8
324const ex _ex_8 = ex(*_num_8_p);
325
326// static numeric -7
328const ex _ex_7 = ex(*_num_7_p);
329
330// static numeric -6
332const ex _ex_6 = ex(*_num_6_p);
333
334// static numeric -5
336const ex _ex_5 = ex(*_num_5_p);
337
338// static numeric -4
340const ex _ex_4 = ex(*_num_4_p);
341
342// static numeric -3
344const ex _ex_3 = ex(*_num_3_p);
345
346// static numeric -2
348const ex _ex_2 = ex(*_num_2_p);
349
350// static numeric -1
352const ex _ex_1 = ex(*_num_1_p);
353
354// static numeric -1/2
357
358// static numeric -1/3
361
362// static numeric -1/4
365
366// static numeric 0
369const ex _ex0 = ex(*_num0_p);
370
371// static numeric 1/4
374
375// static numeric 1/3
378
379// static numeric 1/2
382
383// static numeric 1
385const ex _ex1 = ex(*_num1_p);
386
387// static numeric 2
389const ex _ex2 = ex(*_num2_p);
390
391// static numeric 3
393const ex _ex3 = ex(*_num3_p);
394
395// static numeric 4
397const ex _ex4 = ex(*_num4_p);
398
399// static numeric 5
401const ex _ex5 = ex(*_num5_p);
402
403// static numeric 6
405const ex _ex6 = ex(*_num6_p);
406
407// static numeric 7
409const ex _ex7 = ex(*_num7_p);
410
411// static numeric 8
413const ex _ex8 = ex(*_num8_p);
414
415// static numeric 9
417const ex _ex9 = ex(*_num9_p);
418
419// static numeric 10
421const ex _ex10 = ex(*_num10_p);
422
423// static numeric 11
425const ex _ex11 = ex(*_num11_p);
426
427// static numeric 12
429const ex _ex12 = ex(*_num12_p);
430
431// static numeric 15
433const ex _ex15 = ex(*_num15_p);
434
435// static numeric 18
437const ex _ex18 = ex(*_num18_p);
438
439// static numeric 20
441const ex _ex20 = ex(*_num20_p);
442
443// static numeric 24
445const ex _ex24 = ex(*_num24_p);
446
447// static numeric 25
449const ex _ex25 = ex(*_num25_p);
450
451// static numeric 30
453const ex _ex30 = ex(*_num30_p);
454
455// static numeric 48
457const ex _ex48 = ex(*_num48_p);
458
459// static numeric 60
461const ex _ex60 = ex(*_num60_p);
462
463// static numeric 120
466
467// comment skeleton for header files
468
469
470// member functions
471
472 // default constructor, destructor, copy constructor and assignment operator
473 // none
474
475 // other constructors
476 // none
477
478 // functions overriding virtual functions from base classes
479 // none
480
481 // new virtual functions which can be overridden by derived classes
482 // none
483
484 // non-virtual functions in this class
485 // none
486
487// member variables
488// none
489
490
491
492// comment skeleton for implementation files
493
494
496// default constructor, destructor, copy constructor and assignment operator
498
499// public
500// protected
501
503// other constructors
505
506// public
507// none
508
510// functions overriding virtual functions from base classes
512
513// public
514// protected
515// none
516
518// new virtual functions which can be overridden by derived classes
520
521// public
522// protected
523// none
524
526// non-virtual functions in this class
528
529// public
530// protected
531// none
532
534// static member variables
536
537// protected
538// private
539// none
540
541
542} // namespace GiNaC
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
library_init()
Ctor of static initialization helpers.
Definition: utils.cpp:77
static int count
How many static objects were created? Only the first one must create the static flyweights on the hea...
Definition: ex.h:56
static void init_unarchivers()
Definition: utils.cpp:260
~library_init()
Dtor of static initialization helpers.
Definition: utils.cpp:201
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition: numeric.h:82
const numeric div(const numeric &other) const
Numerical division method.
Definition: numeric.cpp:890
pole_error(const std::string &what_arg, int degree)
ctor for pole_error exception class.
Definition: utils.cpp:38
int degree() const
Return the degree of the pole_error exception class.
Definition: utils.cpp:42
Interface to GiNaC's light-weight expression handles.
vector< int > k
Definition: factor.cpp:1435
size_t n
Definition: factor.cpp:1432
Definition: add.cpp:38
const ex _ex_20
Definition: utils.cpp:296
const numeric * _num_3_p
Definition: utils.cpp:343
const numeric * _num_24_p
Definition: utils.cpp:291
const ex _ex_12
Definition: utils.cpp:308
const numeric * _num1_3_p
Definition: utils.cpp:376
const ex _ex9
Definition: utils.cpp:417
const numeric * _num_1_p
Definition: utils.cpp:351
const ex _ex_120
Definition: utils.cpp:272
const ex _ex2
Definition: utils.cpp:389
const numeric * _num_120_p
Definition: utils.cpp:271
const ex _ex_1_2
Definition: utils.cpp:356
const numeric * _num_30_p
Definition: utils.cpp:283
const numeric * _num6_p
Definition: utils.cpp:404
const numeric * _num_1_3_p
Definition: utils.cpp:359
const ex _ex1_2
Definition: utils.cpp:381
const numeric * _num_1_2_p
Definition: utils.cpp:355
const numeric * _num3_p
Definition: utils.cpp:392
const ex _ex7
Definition: utils.cpp:409
const numeric * _num_1_4_p
Definition: utils.cpp:363
const numeric * _num1_2_p
Definition: utils.cpp:380
const ex _ex24
Definition: utils.cpp:445
const numeric * _num25_p
Definition: utils.cpp:448
const ex _ex12
Definition: utils.cpp:429
const ex _ex1
Definition: utils.cpp:385
const numeric * _num_10_p
Definition: utils.cpp:315
const ex _ex_60
Definition: utils.cpp:276
const numeric * _num_8_p
Definition: utils.cpp:323
const numeric * _num1_4_p
Definition: utils.cpp:372
const numeric * _num_5_p
Definition: utils.cpp:335
const numeric * _num24_p
Definition: utils.cpp:444
const ex _ex15
Definition: utils.cpp:433
const numeric * _num_11_p
Definition: utils.cpp:311
const numeric * _num30_p
Definition: utils.cpp:452
const ex _ex3
Definition: utils.cpp:393
const numeric * _num10_p
Definition: utils.cpp:420
const ex _ex6
Definition: utils.cpp:405
const numeric * _num4_p
Definition: utils.cpp:396
const int version_minor
Definition: utils.cpp:33
const numeric * _num_12_p
Definition: utils.cpp:307
const numeric * _num_2_p
Definition: utils.cpp:347
const numeric * _num_9_p
Definition: utils.cpp:319
const numeric * _num2_p
Definition: utils.cpp:388
const ex _ex11
Definition: utils.cpp:425
const ex _ex_4
Definition: utils.cpp:340
const ex _ex_24
Definition: utils.cpp:292
const int version_major
Definition: utils.cpp:32
const ex _ex_25
Definition: utils.cpp:288
const ex _ex120
Definition: utils.cpp:465
const numeric * _num11_p
Definition: utils.cpp:424
const numeric * _num_48_p
Definition: utils.cpp:279
const numeric * _num7_p
Definition: utils.cpp:408
const numeric factorial(const numeric &n)
Factorial combinatorial function.
Definition: numeric.cpp:2113
const ex _ex_5
Definition: utils.cpp:336
const ex _ex_1
Definition: utils.cpp:352
const ex _ex_3
Definition: utils.cpp:344
const numeric * _num12_p
Definition: utils.cpp:428
const ex _ex20
Definition: utils.cpp:441
const numeric * _num48_p
Definition: utils.cpp:456
unsigned log2(unsigned n)
Integer binary logarithm.
Definition: utils.cpp:48
const ex _ex30
Definition: utils.cpp:453
int degree(const ex &thisex, const ex &s)
Definition: ex.h:751
const numeric * _num_6_p
Definition: utils.cpp:331
const ex _ex_6
Definition: utils.cpp:332
const numeric * _num9_p
Definition: utils.cpp:416
const basic * _num0_bp
Definition: utils.cpp:368
const numeric * _num_18_p
Definition: utils.cpp:299
const ex _ex_2
Definition: utils.cpp:348
const ex _ex_10
Definition: utils.cpp:316
const ex _ex4
Definition: utils.cpp:397
const ex _ex_15
Definition: utils.cpp:304
const ex _ex5
Definition: utils.cpp:401
const ex _ex_7
Definition: utils.cpp:328
const numeric * _num_60_p
Definition: utils.cpp:275
const ex _ex25
Definition: utils.cpp:449
const numeric * _num_7_p
Definition: utils.cpp:327
const numeric * _num1_p
Definition: utils.cpp:384
const numeric * _num8_p
Definition: utils.cpp:412
const ex _ex10
Definition: utils.cpp:421
const ex _ex48
Definition: utils.cpp:457
const numeric * _num_15_p
Definition: utils.cpp:303
const ex _ex18
Definition: utils.cpp:437
const int version_micro
Definition: utils.cpp:34
const ex _ex_11
Definition: utils.cpp:312
const numeric * _num60_p
Definition: utils.cpp:460
const ex _ex_1_4
Definition: utils.cpp:364
const ex _ex60
Definition: utils.cpp:461
const ex _ex1_4
Definition: utils.cpp:373
const ex _ex_48
Definition: utils.cpp:280
const numeric * _num_4_p
Definition: utils.cpp:339
const numeric * _num15_p
Definition: utils.cpp:432
const ex _ex_8
Definition: utils.cpp:324
const ex _ex_1_3
Definition: utils.cpp:360
const ex _ex0
Definition: utils.cpp:369
const numeric * _num120_p
Definition: utils.cpp:464
const ex _ex_18
Definition: utils.cpp:300
const numeric * _num_20_p
Definition: utils.cpp:295
const ex _ex_30
Definition: utils.cpp:284
const numeric * _num_25_p
Definition: utils.cpp:287
const numeric multinomial_coefficient(const std::vector< unsigned > &p)
Compute the multinomial coefficient n!/(p1!*p2!*...*pk!) where n = p1+p2+...+pk, i....
Definition: utils.cpp:60
const numeric * _num20_p
Definition: utils.cpp:440
const numeric * _num18_p
Definition: utils.cpp:436
const ex _ex8
Definition: utils.cpp:413
const ex _ex_9
Definition: utils.cpp:320
const numeric * _num0_p
Definition: utils.cpp:367
const numeric * _num5_p
Definition: utils.cpp:400
const ex _ex1_3
Definition: utils.cpp:377
Makes the interface to the underlying bignum package available.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...
GiNaC library version information.
#define GINACLIB_MINOR_VERSION
Definition: version.h:30
#define GINACLIB_MICRO_VERSION
Definition: version.h:33
#define GINACLIB_MAJOR_VERSION
Definition: version.h:27

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.