1 /** @file time_lw_O.cpp
3 * Test O1 from the paper "Comparison of Polynomial-Oriented CAS" by Robert H.
4 * Lewis and Michael Wester. */
7 * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
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.
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.
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
26 static const bool do_test2 = false; // set to true in order to run this beast
28 static const symbol a1("a1"), a2("a2"), a3("a3"), a4("a4"), a5("a5"), a6("a6");
29 static const symbol b1("b1"), b2("b2"), b3("b3"), b4("b4"), b5("b5"), b6("b6");
30 static const symbol c1("c1"), c2("c2"), c3("c3"), c4("c4"), c5("c5"), c6("c6");
32 static const ex det1()
35 d1 = a6, a5, a4, a3, a2, a1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0,
37 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1, 0, 0,
39 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1, 0,
40 0, 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1,
41 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1, 0, 0,
42 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1, 0,
43 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0, 0,
44 0, 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1,
46 0, 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1,
47 0, 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0,
48 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1, 0;
51 return d1.determinant();
54 static const ex det2()
57 d2 = b6, b5, b4, b3, b2, b1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0,
59 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1, 0, 0,
61 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1, 0,
62 0, 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1,
63 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1, 0, 0,
64 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1, 0,
65 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0, 0,
66 0, 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1,
68 0, 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1,
69 0, 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0,
70 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1, 0;
73 return d2.determinant();
76 static const ex det3()
79 d3 = c6, c5, c4, c3, c2, c1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0,
81 0, c6, 0, c5, c4, 0, c3, c2, c1, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1, 0, 0,
83 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1, 0,
84 0, 0, 0, 0, 0, c6, 0, 0, c5, c4, 0, 0, c3, c2, c1,
85 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1, 0, 0,
86 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1, 0,
87 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0, 0,
88 0, 0, a6, 0, a5, a4, 0, a3, a2, a1, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, a6, 0, 0, a5, a4, 0, 0, a3, a2, a1,
90 0, 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1,
91 0, 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0,
92 0, b6, 0, b5, b4, 0, b3, b2, b1, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, b6, 0, 0, b5, b4, 0, 0, b3, b2, b1, 0;
95 return d3.determinant();
98 // The results of test_O1 will be needed for test_O2:
101 static unsigned test_O1()
103 d1 = det1(); cout << '.' << flush;
104 d2 = det2(); cout << '.' << flush;
105 d3 = det3(); cout << '.' << flush;
106 unsigned nops1 = nops(d1);
107 unsigned nops2 = nops(d2);
108 unsigned nops3 = nops(d3);
110 if ((nops1 != 37490) || (nops2 != 37490) || (nops3 != 37490)) {
111 clog << "Determinants were miscalculated" << endl;
117 static unsigned test_O2()
119 const ex gcd1 = gcd( d1, d2 ); cout << '.' << flush;
120 const ex resultant = gcd( gcd1, d3 ); cout << '.' << flush;
121 if (nops(resultant) != 21894) {
122 clog << "Resultant was miscalculated" << endl;
135 cout << "timing Lewis-Wester test O1 (three 15x15 dets)" << flush;
136 clog << "-------Lewis-Wester test O1 (three 15x15 dets):" << endl;
139 // correct for very small times:
143 } while ((time=rolex.read())<0.1 && !result);
147 clog << "(no output)" << endl;
151 cout << time/(3*count) << "s (average)" << endl;
153 cout << "timing Lewis-Wester test O2 (Resultant)" << flush;
154 clog << "-------Lewis-Wester test O2 (Resultant):" << endl;
162 clog << "(no output)" << endl;
166 cout << rolex.read() << "s (combined)" << endl;
168 cout << " disabled" << endl;
169 clog << "(no output)" << endl;