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