3 * Implementation of several small and furry utilities needed within GiNaC
4 * but not of any interest to the user of the library. */
7 * GiNaC Copyright (C) 1999-2022 Johannes Gutenberg University Mainz, Germany
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.
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.
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
31 /* Version information buried into the library */
32 const int version_major = GINACLIB_MAJOR_VERSION;
33 const int version_minor = GINACLIB_MINOR_VERSION;
34 const int version_micro = GINACLIB_MICRO_VERSION;
37 /** ctor for pole_error exception class. */
38 pole_error::pole_error(const std::string& what_arg, int degree)
39 : domain_error(what_arg), deg(degree) { }
41 /** Return the degree of the pole_error exception class. */
42 int pole_error::degree() const
47 /** Integer binary logarithm */
48 unsigned log2(unsigned n)
51 for (k = 0; n > 1; n >>= 1)
56 /** Compute the multinomial coefficient n!/(p1!*p2!*...*pk!) where
57 * n = p1+p2+...+pk, i.e. p is a partition of n.
60 multinomial_coefficient(const std::vector<unsigned> & p)
64 n = n.add(numeric(it));
65 d = d.mul(factorial(numeric(it)));
67 return factorial(n).div(d);
71 /** How many static objects were created? Only the first one must create
72 * the static flyweights on the heap. */
73 int library_init::count = 0;
75 /** Ctor of static initialization helpers. The fist call to this is going
76 * to initialize the library, the others do nothing. */
77 library_init::library_init()
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);
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);
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
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();
199 /** Dtor of static initialization helpers. The last call to this is going
200 * to shut down the library, the others do nothing. */
201 library_init::~library_init()
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!
260 void library_init::init_unarchivers() { }
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.
270 // static numeric -120
271 const numeric *_num_120_p;
272 const ex _ex_120 = ex(*_num_120_p);
274 // static numeric -60
275 const numeric *_num_60_p;
276 const ex _ex_60 = ex(*_num_60_p);
278 // static numeric -48
279 const numeric *_num_48_p;
280 const ex _ex_48 = ex(*_num_48_p);
282 // static numeric -30
283 const numeric *_num_30_p;
284 const ex _ex_30 = ex(*_num_30_p);
286 // static numeric -25
287 const numeric *_num_25_p;
288 const ex _ex_25 = ex(*_num_25_p);
290 // static numeric -24
291 const numeric *_num_24_p;
292 const ex _ex_24 = ex(*_num_24_p);
294 // static numeric -20
295 const numeric *_num_20_p;
296 const ex _ex_20 = ex(*_num_20_p);
298 // static numeric -18
299 const numeric *_num_18_p;
300 const ex _ex_18 = ex(*_num_18_p);
302 // static numeric -15
303 const numeric *_num_15_p;
304 const ex _ex_15 = ex(*_num_15_p);
306 // static numeric -12
307 const numeric *_num_12_p;
308 const ex _ex_12 = ex(*_num_12_p);
310 // static numeric -11
311 const numeric *_num_11_p;
312 const ex _ex_11 = ex(*_num_11_p);
314 // static numeric -10
315 const numeric *_num_10_p;
316 const ex _ex_10 = ex(*_num_10_p);
319 const numeric *_num_9_p;
320 const ex _ex_9 = ex(*_num_9_p);
323 const numeric *_num_8_p;
324 const ex _ex_8 = ex(*_num_8_p);
327 const numeric *_num_7_p;
328 const ex _ex_7 = ex(*_num_7_p);
331 const numeric *_num_6_p;
332 const ex _ex_6 = ex(*_num_6_p);
335 const numeric *_num_5_p;
336 const ex _ex_5 = ex(*_num_5_p);
339 const numeric *_num_4_p;
340 const ex _ex_4 = ex(*_num_4_p);
343 const numeric *_num_3_p;
344 const ex _ex_3 = ex(*_num_3_p);
347 const numeric *_num_2_p;
348 const ex _ex_2 = ex(*_num_2_p);
351 const numeric *_num_1_p;
352 const ex _ex_1 = ex(*_num_1_p);
354 // static numeric -1/2
355 const numeric *_num_1_2_p;
356 const ex _ex_1_2= ex(*_num_1_2_p);
358 // static numeric -1/3
359 const numeric *_num_1_3_p;
360 const ex _ex_1_3= ex(*_num_1_3_p);
362 // static numeric -1/4
363 const numeric *_num_1_4_p;
364 const ex _ex_1_4= ex(*_num_1_4_p);
367 const numeric *_num0_p;
368 const basic *_num0_bp;
369 const ex _ex0 = ex(*_num0_p);
371 // static numeric 1/4
372 const numeric *_num1_4_p;
373 const ex _ex1_4 = ex(*_num1_4_p);
375 // static numeric 1/3
376 const numeric *_num1_3_p;
377 const ex _ex1_3 = ex(*_num1_3_p);
379 // static numeric 1/2
380 const numeric *_num1_2_p;
381 const ex _ex1_2 = ex(*_num1_2_p);
384 const numeric *_num1_p;
385 const ex _ex1 = ex(*_num1_p);
388 const numeric *_num2_p;
389 const ex _ex2 = ex(*_num2_p);
392 const numeric *_num3_p;
393 const ex _ex3 = ex(*_num3_p);
396 const numeric *_num4_p;
397 const ex _ex4 = ex(*_num4_p);
400 const numeric *_num5_p;
401 const ex _ex5 = ex(*_num5_p);
404 const numeric *_num6_p;
405 const ex _ex6 = ex(*_num6_p);
408 const numeric *_num7_p;
409 const ex _ex7 = ex(*_num7_p);
412 const numeric *_num8_p;
413 const ex _ex8 = ex(*_num8_p);
416 const numeric *_num9_p;
417 const ex _ex9 = ex(*_num9_p);
420 const numeric *_num10_p;
421 const ex _ex10 = ex(*_num10_p);
424 const numeric *_num11_p;
425 const ex _ex11 = ex(*_num11_p);
428 const numeric *_num12_p;
429 const ex _ex12 = ex(*_num12_p);
432 const numeric *_num15_p;
433 const ex _ex15 = ex(*_num15_p);
436 const numeric *_num18_p;
437 const ex _ex18 = ex(*_num18_p);
440 const numeric *_num20_p;
441 const ex _ex20 = ex(*_num20_p);
444 const numeric *_num24_p;
445 const ex _ex24 = ex(*_num24_p);
448 const numeric *_num25_p;
449 const ex _ex25 = ex(*_num25_p);
452 const numeric *_num30_p;
453 const ex _ex30 = ex(*_num30_p);
456 const numeric *_num48_p;
457 const ex _ex48 = ex(*_num48_p);
460 const numeric *_num60_p;
461 const ex _ex60 = ex(*_num60_p);
463 // static numeric 120
464 const numeric *_num120_p;
465 const ex _ex120 = ex(*_num120_p);
467 // comment skeleton for header files
472 // default constructor, destructor, copy constructor and assignment operator
475 // other constructors
478 // functions overriding virtual functions from base classes
481 // new virtual functions which can be overridden by derived classes
484 // non-virtual functions in this class
492 // comment skeleton for implementation files
496 // default constructor, destructor, copy constructor and assignment operator
503 // other constructors
510 // functions overriding virtual functions from base classes
518 // new virtual functions which can be overridden by derived classes
526 // non-virtual functions in this class
534 // static member variables