]> www.ginac.de Git - ginac.git/blob - check/time_lw_O.cpp
Fixed the parser such that it can read in user defined classes again.
[ginac.git] / check / time_lw_O.cpp
1 /** @file time_lw_O.cpp
2  *
3  *  Test O1 from the paper "Comparison of Polynomial-Oriented CAS" by Robert H.
4  *  Lewis and Michael Wester. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include "ginac.h"
25 #include "timer.h"
26 using namespace GiNaC;
27
28 #include <iostream>
29 #include <vector>
30 using namespace std;
31
32 static const bool do_test2 = false;  // set to true in order to run this beast
33
34 static const symbol a1("a1"), a2("a2"), a3("a3"), a4("a4"), a5("a5"), a6("a6");
35 static const symbol b1("b1"), b2("b2"), b3("b3"), b4("b4"), b5("b5"), b6("b6");
36 static const symbol c1("c1"), c2("c2"), c3("c3"), c4("c4"), c5("c5"), c6("c6");
37
38 static const ex det1()
39 {
40         matrix d1(15,15);
41         d1 = a6, a5, a4, a3, a2, a1, 0,  0,  0,  0,  0,  0,  0,  0,  0,
42              0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,
43              0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0,
44              0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,  0,
45              0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,
46              0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1,
47              0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,  0,
48              0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,
49              0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0,
50              0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,
51              0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1,
52              0,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1,
53              0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,
54              0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0,
55              0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0;
56
57         return d1.determinant();
58 }
59
60 static const ex det2()
61 {
62         matrix d2(15,15);
63         d2 = b6, b5, b4, b3, b2, b1, 0,  0,  0,  0,  0,  0,  0,  0,  0,
64              0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,
65              0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0,
66              0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,  0,
67              0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,
68              0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1,
69              0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0,  0,
70              0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0,
71              0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0,
72              0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,
73              0,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1,
74              0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1,
75              0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,
76              0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0,
77              0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0;
78
79         return d2.determinant();
80 }
81
82 static const ex det3()
83 {
84         matrix d3(15,15);
85         d3 = c6, c5, c4, c3, c2, c1, 0,  0,  0,  0,  0,  0,  0,  0,  0,
86              0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,
87              0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0,
88              0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0,  0,
89              0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0,
90              0,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1,
91              0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,  0,
92              0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,
93              0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0,
94              0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,
95              0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1,
96              0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1,
97              0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,
98              0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0,
99              0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0;
100
101         return d3.determinant();
102 }
103
104 // The results of test_O1 will be needed for test_O2:
105 static ex d1, d2, d3;
106
107 static unsigned test_O1()
108 {
109         d1 = det1();  cout << '.' << flush;
110         d2 = det2();  cout << '.' << flush;
111         d3 = det3();  cout << '.' << flush;
112         unsigned nops1 = nops(d1);
113         unsigned nops2 = nops(d2);
114         unsigned nops3 = nops(d3);
115
116         if ((nops1 != 37490) || (nops2 != 37490) || (nops3 != 37490)) {
117                 clog << "Determinants were miscalculated" << endl;
118                 return 1;
119         }
120         return 0;
121 }
122
123 static unsigned test_O2()
124 {
125         const ex gcd1 = gcd( d1, d2 );  cout << '.' << flush;
126         const ex resultant = gcd( gcd1, d3 );  cout << '.' << flush;
127         if (nops(resultant) != 21894) {
128                 clog << "Resultant was miscalculated" << endl;
129                 return 1;
130         }
131         return 0;
132 }
133
134 unsigned time_lw_O()
135 {
136         unsigned result = 0;
137         unsigned count = 0;
138         timer rolex;
139         double time = .0;
140
141         cout << "timing Lewis-Wester test O1 (three 15x15 dets)" << flush;
142
143         rolex.start();
144         // correct for very small times:
145         do {
146                 result = test_O1();
147                 ++count;
148         } while ((time=rolex.read())<0.1 && !result);
149
150         if (result)
151                 return result;
152         
153         cout << time/(3*count) << "s (average)" << endl;
154
155         cout << "timing Lewis-Wester test O2 (Resultant)" << flush;
156
157         if (do_test2) {
158                 rolex.reset();
159                 result += test_O2();
160
161                 cout << rolex.read() << "s (combined)" << endl;
162         } else {
163                 cout << " disabled" << endl;
164         }
165
166         return result;
167 }
168
169 extern void randomify_symbol_serials();
170
171 int main(int argc, char** argv)
172 {
173         randomify_symbol_serials();
174         cout << setprecision(2) << showpoint;
175         return time_lw_O();
176 }