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