]> www.ginac.de Git - ginac.git/blob - check/exam_misc.cpp
c9872a93284bce8659586a99ba2afc4d52fc9bba
[ginac.git] / check / exam_misc.cpp
1 /** @file exam_misc.cpp
2  *
3  */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23
24 #include "exams.h"
25
26 #define VECSIZE 30
27 static unsigned exam_expand_subs(void)
28 {
29         unsigned result = 0;
30         symbol a[VECSIZE];
31         ex e, aux;
32         
33         for (unsigned i=0; i<VECSIZE; ++i)
34                 e = e + a[i];
35         
36         // prepare aux so it will swallow anything but a1^2:
37         aux = -e + a[0] + a[1];
38         e = expand(subs(expand(pow(e, 2)), a[0] == aux));
39         
40         if (e != pow(a[1],2)) {
41                 clog << "Denny Fliegner's quick consistency check erroneously returned "
42                      << e << "." << endl;
43                 ++result;
44         }
45         
46         return result;
47 }
48
49 /*  A simple modification of Denny Fliegner's three step consistency test:
50  *  1)  e = (a0 + a1)^200
51  *  2)  expand e
52  *  3)  substitute a0 by -a1 in e
53  *  after which e should return 0 (without expanding). */
54 static unsigned exam_expand_subs2(void)
55 {
56         unsigned result = 0;
57         symbol a("a"), b("b");
58         ex e, f;
59         
60         e = pow(a+b,200).expand();
61         f = e.subs(a == -b);
62         
63         if (f != 0) {
64                 clog << "e = pow(a+b,200).expand(); f = e.subs(a == -b); erroneously returned "
65                      << f << " instead of simplifying to 0." << endl;
66                 ++result;
67         }
68         
69         return result;
70 }
71
72 static unsigned exam_expand_power(void)
73 {
74         unsigned result = 0;
75         symbol x("x"), a("a"), b("b");
76         ex e;
77         
78         e = pow(x,pow(a+b,2)-pow(a,2)-pow(b,2)-a*b*2).expand();
79         
80         if (e != 1) {
81                 clog << "e = pow(x,pow(a+b,2)-pow(a,2)-pow(b,2)-a*b*2).expand(); erroneously returned "
82                      << e << " instead of simplifying to 1." << endl;
83                 ++result;
84         }
85         
86         return result;
87 }
88
89 unsigned exam_misc(void)
90 {
91         unsigned result = 0;
92         
93         cout << "examining miscellaneous other things" << flush;
94         clog << "----------miscellaneous other things:" << endl;
95         
96         result += exam_expand_subs();  cout << '.' << flush;
97         result += exam_expand_subs2();  cout << '.' << flush;
98         result += exam_expand_power(); cout << '.' << flush;
99         
100         if (!result) {
101                 cout << " passed " << endl;
102                 clog << "(no output)" << endl;
103         } else {
104                 cout << " failed " << endl;
105         }
106         
107         return result;
108 }