]> www.ginac.de Git - ginac.git/blob - ginac/utils.cpp
- clarify comment about counterintuitive sorting for Laplace.
[ginac.git] / ginac / utils.cpp
1 /** @file utils.cpp
2  *
3  *  Implementation of several small and furry utilities needed within GiNaC
4  *  but not of any interest to the user of the library. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2001 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "ex.h"
25 #include "numeric.h"
26 #include "utils.h"
27 #include "version.h"
28
29 namespace GiNaC {
30
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;
35
36
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) { }
40
41 /** Return the degree of the pole_error exception class. */
42 int pole_error::degree(void) const
43 {
44         return deg;
45 }
46
47 // some compilers (e.g. cygwin) define a macro log2, causing confusion
48 #ifndef log2
49 /** Integer binary logarithm */
50 unsigned log2(unsigned n)
51 {
52         unsigned k;
53         for (k = 0; n > 1; n >>= 1)
54                 ++k;
55         return k;
56 }
57 #endif
58
59 //////////
60 // `construct on first use' chest of numbers
61 //////////
62
63 // numeric -120
64 const numeric & _num_120(void)
65 {
66         const static ex e = ex(numeric(-120));
67         const static numeric &n = ex_to<numeric>(e);
68         return n;
69 }
70
71 const ex & _ex_120(void)
72 {
73         static ex * e = new ex(_num_120());
74         return *e;
75 }
76
77 // numeric -60
78 const numeric & _num_60(void)
79 {
80         const static ex e = ex(numeric(-60));
81         const static numeric &n = ex_to<numeric>(e);
82         return n;
83 }
84
85 const ex & _ex_60(void)
86 {
87         static ex * e = new ex(_num_60());
88         return *e;
89 }
90
91 // numeric -48
92 const numeric & _num_48(void)
93 {
94         const static ex e = ex(numeric(-48));
95         const static numeric &n = ex_to<numeric>(e);
96         return n;
97 }
98
99 const ex & _ex_48(void)
100 {
101         static ex * e = new ex(_num_48());
102         return *e;
103 }
104
105 // numeric -30
106 const numeric & _num_30(void)
107 {
108         const static ex e = ex(numeric(-30));
109         const static numeric &n = ex_to<numeric>(e);
110         return n;
111 }
112
113 const ex & _ex_30(void)
114 {
115         static ex * e = new ex(_num_30());
116         return *e;
117 }
118
119 // numeric -25
120 const numeric & _num_25(void)
121 {
122         const static ex e = ex(numeric(-25));
123         const static numeric &n = ex_to<numeric>(e);
124         return n;
125 }
126
127 const ex & _ex_25(void)
128 {
129         static ex * e = new ex(_num_25());
130         return *e;
131 }
132
133 // numeric -24
134 const numeric & _num_24(void)
135 {
136         const static ex e = ex(numeric(-24));
137         const static numeric &n = ex_to<numeric>(e);
138         return n;
139 }
140
141 const ex & _ex_24(void)
142 {
143         static ex * e = new ex(_num_24());
144         return *e;
145 }
146
147 // numeric -20
148 const numeric & _num_20(void)
149 {
150         const static ex e = ex(numeric(-20));
151         const static numeric &n = ex_to<numeric>(e);
152         return n;
153 }
154
155 const ex & _ex_20(void)
156 {
157         static ex * e = new ex(_num_20());
158         return *e;
159 }
160
161 // numeric -18
162 const numeric & _num_18(void)
163 {
164         const static ex e = ex(numeric(-18));
165         const static numeric &n = ex_to<numeric>(e);
166         return n;
167 }
168
169 const ex & _ex_18(void)
170 {
171         static ex * e = new ex(_num_18());
172         return *e;
173 }
174
175 // numeric -15
176 const numeric & _num_15(void)
177 {
178         const static ex e = ex(numeric(-15));
179         const static numeric &n = ex_to<numeric>(e);
180         return n;
181 }
182
183 const ex & _ex_15(void)
184 {
185         static ex * e = new ex(_num_15());
186         return *e;
187 }
188
189 // numeric -12
190 const numeric & _num_12(void)
191 {
192         const static ex e = ex(numeric(-12));
193         const static numeric &n = ex_to<numeric>(e);
194         return n;
195 }
196
197 const ex & _ex_12(void)
198 {
199         static ex * e = new ex(_num_12());
200         return *e;
201 }
202
203 // numeric -11
204 const numeric & _num_11(void)
205 {
206         const static ex e = ex(numeric(-11));
207         const static numeric &n = ex_to<numeric>(e);
208         return n;
209 }
210
211 const ex & _ex_11(void)
212 {
213         static ex * e = new ex(_num_11());
214         return *e;
215 }
216
217 // numeric -10
218 const numeric & _num_10(void)
219 {
220         const static ex e = ex(numeric(-10));
221         const static numeric &n = ex_to<numeric>(e);
222         return n;
223 }
224
225 const ex & _ex_10(void)
226 {
227         static ex * e = new ex(_num_10());
228         return *e;
229 }
230
231 // numeric -9
232 const numeric & _num_9(void)
233 {
234         const static ex e = ex(numeric(-9));
235         const static numeric &n = ex_to<numeric>(e);
236         return n;
237 }
238
239 const ex & _ex_9(void)
240 {
241         static ex * e = new ex(_num_9());
242         return *e;
243 }
244
245 // numeric -8
246 const numeric & _num_8(void)
247 {
248         const static ex e = ex(numeric(-8));
249         const static numeric &n = ex_to<numeric>(e);
250         return n;
251 }
252
253 const ex & _ex_8(void)
254 {
255         static ex * e = new ex(_num_8());
256         return *e;
257 }
258
259 // numeric -7
260 const numeric & _num_7(void)
261 {
262         const static ex e = ex(numeric(-7));
263         const static numeric &n = ex_to<numeric>(e);
264         return n;
265 }
266
267 const ex & _ex_7(void)
268 {
269         static ex * e = new ex(_num_7());
270         return *e;
271 }
272
273 // numeric -6
274 const numeric & _num_6(void)
275 {
276         const static ex e = ex(numeric(-6));
277         const static numeric &n = ex_to<numeric>(e);
278         return n;
279 }
280
281 const ex & _ex_6(void)
282 {
283         static ex * e = new ex(_num_6());
284         return *e;
285 }
286
287 // numeric -5
288 const numeric & _num_5(void)
289 {
290         const static ex e = ex(numeric(-5));
291         const static numeric &n = ex_to<numeric>(e);
292         return n;
293 }
294
295 const ex & _ex_5(void)
296 {
297         static ex * e = new ex(_num_5());
298         return *e;
299 }
300
301 // numeric -4
302 const numeric & _num_4(void)
303 {
304         const static ex e = ex(numeric(-4));
305         const static numeric &n = ex_to<numeric>(e);
306         return n;
307 }
308
309 const ex & _ex_4(void)
310 {
311         static ex * e = new ex(_num_4());
312         return *e;
313 }
314
315 // numeric -3
316 const numeric & _num_3(void)
317 {
318         const static ex e = ex(numeric(-3));
319         const static numeric &n = ex_to<numeric>(e);
320         return n;
321 }
322
323 const ex & _ex_3(void)
324 {
325         static ex * e = new ex(_num_3());
326         return *e;
327 }
328
329 // numeric -2
330 const numeric & _num_2(void)
331 {
332         const static ex e = ex(numeric(-2));
333         const static numeric &n = ex_to<numeric>(e);
334         return n;
335 }
336
337 const ex & _ex_2(void)
338 {
339         static ex * e = new ex(_num_2());
340         return *e;
341 }
342
343 // numeric -1
344 const numeric & _num_1(void)
345 {
346         const static ex e = ex(numeric(-1));
347         const static numeric &n = ex_to<numeric>(e);
348         return n;
349 }
350
351 const ex & _ex_1(void)
352 {
353         static ex * e = new ex(_num_1());
354         return *e;
355 }
356
357 // numeric -1/2
358 const numeric & _num_1_2(void)
359 {
360         const static ex e = ex(numeric(-1,2));
361         const static numeric &n = ex_to<numeric>(e);
362         return n;
363 }
364
365 const ex & _ex_1_2(void)
366 {
367         static ex * e = new ex(_num_1_2());
368         return *e;
369 }    
370
371 // numeric -1/3
372 const numeric & _num_1_3(void)
373 {
374         const static ex e = ex(numeric(-1,3));
375         const static numeric &n = ex_to<numeric>(e);
376         return n;
377 }
378
379 const ex & _ex_1_3(void)
380 {
381         static ex * e = new ex(_num_1_3());
382         return *e;
383 }    
384
385 // numeric -1/4
386 const numeric & _num_1_4(void)
387 {
388         const static ex e = ex(numeric(-1,4));
389         const static numeric &n = ex_to<numeric>(e);
390         return n;
391 }
392
393 const ex & _ex_1_4(void)
394 {
395         static ex * e = new ex(_num_1_4());
396         return *e;
397 }    
398
399 // numeric  0
400 const numeric & _num0(void)
401 {
402         const static ex e = ex(numeric(0));
403         const static numeric &n = ex_to<numeric>(e);
404         return n;
405 }
406
407 const ex & _ex0(void)
408 {
409         static ex * e = new ex(_num0());
410         return *e;
411 }
412
413 // numeric  1/4
414 const numeric & _num1_4(void)
415 {
416         const static ex e = ex(numeric(1,4));
417         const static numeric &n = ex_to<numeric>(e);
418         return n;
419 }
420
421 const ex & _ex1_4(void)
422 {
423         static ex * e = new ex(_num1_4());
424         return *e;
425 }    
426
427 // numeric  1/3
428 const numeric & _num1_3(void)
429 {
430         const static ex e = ex(numeric(1,3));
431         const static numeric &n = ex_to<numeric>(e);
432         return n;
433 }
434
435 const ex & _ex1_3(void)
436 {
437         static ex * e = new ex(_num1_3());
438         return *e;
439 }    
440
441 // numeric  1/2
442 const numeric & _num1_2(void)
443 {
444         const static ex e = ex(numeric(1,2));
445         const static numeric &n = ex_to<numeric>(e);
446         return n;
447 }
448
449 const ex & _ex1_2(void)
450 {
451         static ex * e = new ex(_num1_2());
452         return *e;
453 }    
454
455 // numeric  1
456 const numeric & _num1(void)
457 {
458         const static ex e = ex(numeric(1));
459         const static numeric &n = ex_to<numeric>(e);
460         return n;
461 }
462
463 const ex & _ex1(void)
464 {
465         static ex * e = new ex(_num1());
466         return *e;
467 }
468
469 // numeric  2
470 const numeric & _num2(void)
471 {
472         const static ex e = ex(numeric(2));
473         const static numeric &n = ex_to<numeric>(e);
474         return n;
475 }
476
477 const ex & _ex2(void)
478 {
479         static ex * e = new ex(_num2());
480         return *e;
481 }
482
483 // numeric  3
484 const numeric & _num3(void)
485 {
486         const static ex e = ex(numeric(3));
487         const static numeric &n = ex_to<numeric>(e);
488         return n;
489 }
490
491 const ex & _ex3(void)
492 {
493         static ex * e = new ex(_num3());
494         return *e;
495 }
496
497 // numeric  4
498 const numeric & _num4(void)
499 {
500         const static ex e = ex(numeric(4));
501         const static numeric &n = ex_to<numeric>(e);
502         return n;
503 }
504
505 const ex & _ex4(void)
506 {
507         static ex * e = new ex(_num4());
508         return *e;
509 }
510
511 // numeric  5
512 const numeric & _num5(void)
513 {
514         const static ex e = ex(numeric(5));
515         const static numeric &n = ex_to<numeric>(e);
516         return n;
517 }
518
519 const ex & _ex5(void)
520 {
521         static ex * e = new ex(_num5());
522         return *e;
523 }
524
525 // numeric  6
526 const numeric & _num6(void)
527 {
528         const static ex e = ex(numeric(6));
529         const static numeric &n = ex_to<numeric>(e);
530         return n;
531 }
532
533 const ex & _ex6(void)
534 {
535         static ex * e = new ex(_num6());
536         return *e;
537 }
538
539 // numeric  7
540 const numeric & _num7(void)
541 {
542         const static ex e = ex(numeric(7));
543         const static numeric &n = ex_to<numeric>(e);
544         return n;
545 }
546
547 const ex & _ex7(void)
548 {
549         static ex * e = new ex(_num7());
550         return *e;
551 }
552
553 // numeric  8
554 const numeric & _num8(void)
555 {
556         const static ex e = ex(numeric(8));
557         const static numeric &n = ex_to<numeric>(e);
558         return n;
559 }
560
561 const ex & _ex8(void)
562 {
563         static ex * e = new ex(_num8());
564         return *e;
565 }
566
567 // numeric  9
568 const numeric & _num9(void)
569 {
570         const static ex e = ex(numeric(9));
571         const static numeric &n = ex_to<numeric>(e);
572         return n;
573 }
574
575 const ex & _ex9(void)
576 {
577         static ex * e = new ex(_num9());
578         return *e;
579 }
580
581 // numeric  10
582 const numeric & _num10(void)
583 {
584         const static ex e = ex(numeric(10));
585         const static numeric &n = ex_to<numeric>(e);
586         return n;
587 }
588
589 const ex & _ex10(void)
590 {
591         static ex * e = new ex(_num10());
592         return *e;
593 }
594
595 // numeric  11
596 const numeric & _num11(void)
597 {
598         const static ex e = ex(numeric(11));
599         const static numeric &n = ex_to<numeric>(e);
600         return n;
601 }
602
603 const ex & _ex11(void)
604 {
605         static ex * e = new ex(_num11());
606         return *e;
607 }
608
609 // numeric  12
610 const numeric & _num12(void)
611 {
612         const static ex e = ex(numeric(12));
613         const static numeric &n = ex_to<numeric>(e);
614         return n;
615 }
616
617 const ex & _ex12(void)
618 {
619         static ex * e = new ex(_num12());
620         return *e;
621 }
622
623 // numeric  15
624 const numeric & _num15(void)
625 {
626         const static ex e = ex(numeric(15));
627         const static numeric &n = ex_to<numeric>(e);
628         return n;
629 }
630
631 const ex & _ex15(void)
632 {
633         static ex * e = new ex(_num15());
634         return *e;
635 }
636
637 // numeric  18
638 const numeric & _num18(void)
639 {
640         const static ex e = ex(numeric(18));
641         const static numeric &n = ex_to<numeric>(e);
642         return n;
643 }
644
645 const ex & _ex18(void)
646 {
647         static ex * e = new ex(_num18());
648         return *e;
649 }
650
651 // numeric  20
652 const numeric & _num20(void)
653 {
654         const static ex e = ex(numeric(20));
655         const static numeric &n = ex_to<numeric>(e);
656         return n;
657 }
658
659 const ex & _ex20(void)
660 {
661         static ex * e = new ex(_num20());
662         return *e;
663 }
664
665 // numeric  24
666 const numeric & _num24(void)
667 {
668         const static ex e = ex(numeric(24));
669         const static numeric &n = ex_to<numeric>(e);
670         return n;
671 }
672
673 const ex & _ex24(void)
674 {
675         static ex * e = new ex(_num24());
676         return *e;
677 }
678
679 // numeric  25
680 const numeric & _num25(void)
681 {
682         const static ex e = ex(numeric(25));
683         const static numeric &n = ex_to<numeric>(e);
684         return n;
685 }
686
687 const ex & _ex25(void)
688 {
689         static ex * e = new ex(_num25());
690         return *e;
691 }
692
693 // numeric  30
694 const numeric & _num30(void)
695 {
696         const static ex e = ex(numeric(30));
697         const static numeric &n = ex_to<numeric>(e);
698         return n;
699 }
700
701 const ex & _ex30(void)
702 {
703         static ex * e = new ex(_num30());
704         return *e;
705 }
706
707 // numeric  48
708 const numeric & _num48(void)
709 {
710         const static ex e = ex(numeric(48));
711         const static numeric &n = ex_to<numeric>(e);
712         return n;
713 }
714
715 const ex & _ex48(void)
716 {
717         static ex * e = new ex(_num48());
718         return *e;
719 }
720
721 // numeric  60
722 const numeric & _num60(void)
723 {
724         const static ex e = ex(numeric(60));
725         const static numeric &n = ex_to<numeric>(e);
726         return n;
727 }
728
729 const ex & _ex60(void)
730 {
731         static ex * e = new ex(_num60());
732         return *e;
733 }
734
735 // numeric  120
736 const numeric & _num120(void)
737 {
738         const static ex e = ex(numeric(120));
739         const static numeric &n = ex_to<numeric>(e);
740         return n;
741 }
742
743 const ex & _ex120(void)
744 {
745         static ex * e = new ex(_num120());
746         return *e;
747 }
748
749 // comment skeleton for header files
750
751
752 // member functions
753
754         // default ctor, dtor, copy ctor assignment operator and helpers
755         // none
756
757         // other ctors
758         // none
759
760         // functions overriding virtual functions from base classes
761         // none
762         
763         // new virtual functions which can be overridden by derived classes
764         // none
765
766         // non-virtual functions in this class
767         // none
768
769 // member variables
770 // none
771         
772
773
774 // comment skeleton for implementation files
775
776
777 //////////
778 // default ctor, dtor, copy ctor assignment operator and helpers
779 //////////
780
781 // public
782 // protected
783
784 //////////
785 // other ctors
786 //////////
787
788 // public
789 // none
790
791 //////////
792 // functions overriding virtual functions from base classes
793 //////////
794
795 // public
796 // protected
797 // none
798
799 //////////
800 // new virtual functions which can be overridden by derived classes
801 //////////
802
803 // public
804 // protected
805 // none
806
807 //////////
808 // non-virtual functions in this class
809 //////////
810
811 // public
812 // protected
813 // none
814
815 //////////
816 // static member variables
817 //////////
818
819 // protected
820 // private
821 // none
822
823
824 } // namespace GiNaC