]> www.ginac.de Git - ginac.git/blob - check/time_lw_O.cpp
- Adjusted build-environment for "Cint without crutches" (tm).
[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-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 "times.h"
25
26 static unsigned test1(void)
27 {
28     symbol a1("a1"), a2("a2"), a3("a3"), a4("a4"), a5("a5"), a6("a6");
29     symbol b1("b1"), b2("b2"), b3("b3"), b4("b4"), b5("b5"), b6("b6");
30     symbol c1("c1"), c2("c2"), c3("c3"), c4("c4"), c5("c5"), c6("c6");
31     ex w1[15][15] = {
32         {a6, a5, a4, a3, a2, a1, 0,  0,  0,  0,  0,  0,  0,  0,  0 },
33         {0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0 },
34         {0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0 },
35         {0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,  0 },
36         {0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0 },
37         {0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1},
38         {0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,  0 },
39         {0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0 },
40         {0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0 },
41         {0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0 },
42         {0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1},
43         {0,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1},
44         {0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0 },
45         {0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0 },
46         {0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0 }
47     };
48     ex w2[15][15] = {
49         {b6, b5, b4, b3, b2, b1, 0,  0,  0,  0,  0,  0,  0,  0,  0 },
50         {0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0 },
51         {0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0 },
52         {0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0,  0 },
53         {0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0 },
54         {0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1},
55         {0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0,  0 },
56         {0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1, 0 },
57         {0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0 },
58         {0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0 },
59         {0,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1},
60         {0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1},
61         {0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0 },
62         {0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0 },
63         {0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0 }
64     };
65     ex w3[15][15] = {
66         {c6, c5, c4, c3, c2, c1, 0,  0,  0,  0,  0,  0,  0,  0,  0 },
67         {0,  0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0 },
68         {0,  c6, 0,  c5, c4, 0,  c3, c2, c1, 0,  0,  0,  0,  0,  0 },
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,  0,  0,  0,  0,  c6, 0,  0,  c5, c4, 0,  0,  c3, c2, c1},
72         {0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0,  0 },
73         {0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1, 0 },
74         {0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0,  0 },
75         {0,  0,  a6, 0,  a5, a4, 0,  a3, a2, a1, 0,  0,  0,  0,  0 },
76         {0,  0,  0,  0,  0,  a6, 0,  0,  a5, a4, 0,  0,  a3, a2, a1},
77         {0,  0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1},
78         {0,  0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0 },
79         {0,  b6, 0,  b5, b4, 0,  b3, b2, b1, 0,  0,  0,  0,  0,  0 },
80         {0,  0,  0,  0,  b6, 0,  0,  b5, b4, 0,  0,  b3, b2, b1, 0 }
81     };
82     matrix d1(15,15), d2(15,15), d3(15,15);
83     for (unsigned r=0; r<15; ++r) {
84         for (unsigned c=0; c<15; ++c) {
85             d1.set(r,c,w1[r][c]);
86             d2.set(r,c,w2[r][c]);
87             d3.set(r,c,w3[r][c]);
88         }
89     }
90     unsigned nops1 = nops(d1.determinant());  cout << '.' << flush;
91     unsigned nops2 = nops(d2.determinant());  cout << '.' << flush;
92     unsigned nops3 = nops(d3.determinant());  cout << '.' << flush;
93     
94     if ((nops1 != 37490) || (nops2 != 37490) || (nops3 != 37490)) {
95         clog << "Determinants were miscalculated" << endl;
96         return 1;
97     }
98     return 0;
99 }
100
101 unsigned time_lw_O(void)
102 {
103     unsigned result = 0;
104     unsigned count = 0;
105     timer rolex;
106     double time = .0;
107     
108     cout << "timing Lewis-Wester test O1 (three 15x15 dets)" << flush;
109     clog << "-------Lewis-Wester test O1 (three 15x15 dets)" << endl;
110     
111     rolex.start();
112     // correct for very small times:
113     do {
114         result = test1();
115         ++count;
116     } while ((time=rolex.read())<0.1 && !result);
117     
118     if (!result) {
119         cout << " passed ";
120         clog << "(no output)" << endl;
121     } else {
122         cout << " failed ";
123     }
124     cout << int(1000*(time/(3*count)))*0.001 << "s (average)" << endl;
125     
126     return result;
127 }